Skip to content

Commit 18bd545

Browse files
author
Ailing Zhang
committed
update chr test
1 parent 4a2d4fb commit 18bd545

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

test/repro.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import torch
2+
3+
@torch.jit.script
4+
def func(x):
5+
# type: (int) -> int
6+
print(chr(x))
7+
return x
8+
print(func(255))
9+
print(chr(255))

test/test_jit.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11971,16 +11971,13 @@ def index_str_to_tensor(s):
1197111971
s = u'\u00a3'.encode('utf8')[:1]
1197211972
self.checkScript(index_str_to_tensor, (s,))
1197311973

11974-
@unittest.skipIf(not PY2, "We don't support returning wstring")
1197511974
def test_chr(self):
1197611975
def fn(x):
1197711976
# type: (int) -> str
1197811977
return chr(x)
1197911978

1198011979
self.checkScript(fn, (1,))
11981-
self.checkScript(fn, (255,))
11982-
11983-
self.checkScriptRaisesRegex(fn, (256,), Exception, 'not in range(256)')
11980+
self.checkScript(fn, (97,))
1198411981

1198511982
def test_round(self):
1198611983
def round_float(x):

torch/csrc/jit/register_prim_ops.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,12 +2165,14 @@ RegisterOperators reg2({
21652165
"aten::chr(int i) -> str",
21662166
[](Stack& stack) {
21672167
auto i = pop(stack).toInt();
2168+
std::stringstream ss;
21682169
TORCH_CHECK(
21692170
i >= 0 && i < 1114111,
2170-
"chr() arg not in range(256), found ",
2171+
"chr() arg not in range(0x110000), found ",
21712172
i);
21722173
char c = i;
2173-
push(stack, std::string(c, 1));
2174+
ss << c;
2175+
push(stack, ss.str());
21742176
return 0;
21752177
}),
21762178
#define CREATE_COPY_OP(other_type, c_type) \

0 commit comments

Comments
 (0)