mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Revert D15459166: [pytorch][PR] add batch of string ops
Differential Revision: D15459166 Original commit changeset: 0ed908022475 fbshipit-source-id: d0a04228605e3437a02961a525eed8f8b3b59c17
This commit is contained in:
committed by
Facebook Github Bot
parent
5952ca8d9f
commit
a21cf76575
@ -12079,29 +12079,14 @@ a")
|
|||||||
|
|
||||||
self.checkScript(fn, ("abcde",))
|
self.checkScript(fn, ("abcde",))
|
||||||
|
|
||||||
def test_str_ops(self):
|
def test_str_cmp(self):
|
||||||
def test_str_is(s):
|
def test(a, b):
|
||||||
# type: (str) -> Tuple[bool, bool, bool, bool, bool, bool]
|
|
||||||
return s.isupper(), s.islower(), s.isdigit(), s.isspace(), \
|
|
||||||
s.isalnum(), s.isalpha()
|
|
||||||
|
|
||||||
def test_str_to(s):
|
|
||||||
# type: (str) -> Tuple[str, str]
|
|
||||||
return s.upper(), s.lower()
|
|
||||||
|
|
||||||
inputs = ["", "12a", "!B", "12", "a", "B", "aB", "$12", "B12", "AB ",
|
|
||||||
" \t", " \n", "\na", "abc"]
|
|
||||||
|
|
||||||
for input in inputs:
|
|
||||||
self.checkScript(test_str_is, (input,))
|
|
||||||
self.checkScript(test_str_to, (input,))
|
|
||||||
|
|
||||||
def test_str_cmp(a, b):
|
|
||||||
# type: (str, str) -> Tuple[bool, bool, bool, bool, bool, bool]
|
# type: (str, str) -> Tuple[bool, bool, bool, bool, bool, bool]
|
||||||
return a != b, a == b, a < b, a > b, a <= b, a >= b
|
return a != b, a == b, a < b, a > b, a <= b, a >= b
|
||||||
|
|
||||||
for i in range(len(inputs) - 1):
|
self.checkScript(test, ("1", "2"))
|
||||||
self.checkScript(test_str_cmp, (inputs[i], inputs[i + 1]))
|
self.checkScript(test, ("2", "1"))
|
||||||
|
self.checkScript(test, ("1", "1"))
|
||||||
|
|
||||||
def test_ord(self):
|
def test_ord(self):
|
||||||
def fn(x):
|
def fn(x):
|
||||||
|
@ -1913,68 +1913,6 @@ RegisterOperators reg2({
|
|||||||
Operator(
|
Operator(
|
||||||
"aten::slice(str string, int start, int end=9223372036854775807, int step=1) -> str",
|
"aten::slice(str string, int start, int end=9223372036854775807, int step=1) -> str",
|
||||||
stringSlice),
|
stringSlice),
|
||||||
|
|
||||||
// python string is methods return false if empty
|
|
||||||
#define DEFINE_STRING_IS_OP(op_name, char_op) \
|
|
||||||
Operator(#op_name "(str self) -> bool", [](Stack& stack) { \
|
|
||||||
auto string = pop(stack).toStringRef(); \
|
|
||||||
push( \
|
|
||||||
stack, \
|
|
||||||
string.size() != 0 && \
|
|
||||||
std::all_of(string.begin(), string.end(), [](char c) { \
|
|
||||||
return char_op(c); \
|
|
||||||
})); \
|
|
||||||
return 0; \
|
|
||||||
})
|
|
||||||
|
|
||||||
// upper and lower require there to be at least one alpha character,
|
|
||||||
// and ignore all other characters
|
|
||||||
Operator(
|
|
||||||
"aten::isupper(str self) -> bool",
|
|
||||||
[](Stack& stack) {
|
|
||||||
auto string = pop(stack).toStringRef();
|
|
||||||
bool found_alpha = false;
|
|
||||||
bool is_upper = true;
|
|
||||||
for (char c : string) {
|
|
||||||
found_alpha |= std::isalpha(c);
|
|
||||||
is_upper &= (!std::isalpha(c) || std::isupper(c));
|
|
||||||
}
|
|
||||||
push(stack, found_alpha && is_upper);
|
|
||||||
return 0;
|
|
||||||
}),
|
|
||||||
Operator(
|
|
||||||
"aten::islower(str self) -> bool",
|
|
||||||
[](Stack& stack) {
|
|
||||||
auto string = pop(stack).toStringRef();
|
|
||||||
bool found_alpha = false;
|
|
||||||
bool is_lower = true;
|
|
||||||
for (char c : string) {
|
|
||||||
found_alpha |= std::isalpha(c);
|
|
||||||
is_lower &= (!std::isalpha(c) || std::islower(c));
|
|
||||||
}
|
|
||||||
push(stack, found_alpha && is_lower);
|
|
||||||
return 0;
|
|
||||||
}),
|
|
||||||
|
|
||||||
DEFINE_STRING_IS_OP(aten::isdigit, std::isdigit),
|
|
||||||
DEFINE_STRING_IS_OP(aten::isspace, std::isspace),
|
|
||||||
DEFINE_STRING_IS_OP(aten::isalnum, std::isalnum),
|
|
||||||
DEFINE_STRING_IS_OP(aten::isalpha, std::isalpha),
|
|
||||||
|
|
||||||
#define DEFINE_STRING_CHAR_MAP_OP(op_name, char_op) \
|
|
||||||
Operator(#op_name "(str self) -> str", [](Stack& stack) { \
|
|
||||||
auto string = pop(stack).toStringRef(); \
|
|
||||||
std::stringstream ss; \
|
|
||||||
for (char c : string) { \
|
|
||||||
ss << static_cast<char>(char_op(c)); \
|
|
||||||
} \
|
|
||||||
push(stack, ss.str()); \
|
|
||||||
return 0; \
|
|
||||||
})
|
|
||||||
|
|
||||||
DEFINE_STRING_CHAR_MAP_OP(aten::upper, std::toupper),
|
|
||||||
DEFINE_STRING_CHAR_MAP_OP(aten::lower, std::tolower),
|
|
||||||
|
|
||||||
Operator(
|
Operator(
|
||||||
"prim::StringIndex(str string, int index) -> str",
|
"prim::StringIndex(str string, int index) -> str",
|
||||||
[](Stack& stack) {
|
[](Stack& stack) {
|
||||||
|
Reference in New Issue
Block a user