Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/test_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12767,6 +12767,13 @@ def test_pickle_checkpoint(self):
self._test_pickle_checkpoint('cpu')
self._test_pickle_checkpoint_views('cpu')

def test_string_list(self):
def fn(string):
# type: (str) -> List[str]
return list(string)

self.checkScript(fn, ("abcdefgh",))

def test_split(self):
def split_two(tensor):
a, b, c = torch.split(tensor, 2, dim=1)
Expand Down
13 changes: 13 additions & 0 deletions torch/csrc/jit/register_prim_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,19 @@ RegisterOperators reg2({
push(stack, t.sizes()[0]);
return 0;
}),
Operator(
"aten::list(str t) -> str[]",
[](Stack& stack) {
auto str = pop(stack).toStringRef();
std::vector<IValue> chars;
chars.reserve(str.size());
for (auto c : str) {
chars.push_back(std::string(1, c));
}
push(stack, chars);
return 0;
}
),
// Mutable ops for lists containing mutable types.
#define CREATE_MUTABLE_LIST_OPS(decl_type, c_type) \
Operator( \
Expand Down