Skip to content

Commit ac39869

Browse files
Chilleefacebook-github-bot
authored andcommitted
Fixed list() not making a copy (#22093)
Summary: Fixes #22087 Pull Request resolved: #22093 Differential Revision: D16036814 Pulled By: Chillee fbshipit-source-id: 3c7106f907415ed0f600acaf45d2c61e1c60867a
1 parent b109699 commit ac39869

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

torch/csrc/jit/register_prim_ops.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,12 +1507,11 @@ int listNe<at::Tensor>(Stack& stack) {
15071507
return 0;
15081508
}
15091509

1510-
Operation listList(const Node* node) {
1511-
return [=](Stack& stack) {
1512-
// Intentional no-op, needed to match Python semantics for list(iterable),
1513-
// but in JIT these will already be lists
1514-
return 0;
1515-
};
1510+
template <typename T>
1511+
int listList(Stack& stack) {
1512+
c10::List<T> a = pop(stack).to<c10::List<T>>();
1513+
push(stack, a.copy());
1514+
return 0;
15161515
}
15171516

15181517
template <class T>
@@ -2011,7 +2010,8 @@ RegisterOperators reg2({
20112010
"[] l, int start, int end=9223372036854775807, int step=1) -> " decl_type \
20122011
"[]", \
20132012
listSlice<c_type::value_type>), \
2014-
Operator("aten::list(" decl_type "[] l) -> " decl_type "[]", listList), \
2013+
Operator("aten::list(" decl_type "[] l) -> " decl_type "[]", \
2014+
listList<c_type::value_type>), \
20152015
Operator( \
20162016
"aten::mul(" decl_type "[] l, int n) -> " decl_type "[]", \
20172017
listMulIntLeft<c_type::value_type>), \

0 commit comments

Comments
 (0)