Skip to content

Commit dbbdef1

Browse files
committed
Fixed list function not making a copy
1 parent 45b91bd commit dbbdef1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

torch/csrc/jit/register_prim_ops.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,12 +1507,12 @@ 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 = c10::make_list<T>();
1513+
pop(stack, a);
1514+
push(stack, a.copy());
1515+
return 0;
15161516
}
15171517

15181518
template <class T>
@@ -1920,7 +1920,8 @@ RegisterOperators reg2({
19201920
"[] l, int start, int end=9223372036854775807, int step=1) -> " decl_type \
19211921
"[]", \
19221922
listSlice<c_type::value_type>), \
1923-
Operator("aten::list(" decl_type "[] l) -> " decl_type "[]", listList), \
1923+
Operator("aten::list(" decl_type "[] l) -> " decl_type "[]", \
1924+
listList<c_type::value_type>), \
19241925
Operator( \
19251926
"aten::mul(" decl_type "[] l, int n) -> " decl_type "[]", \
19261927
listMulIntLeft<c_type::value_type>), \
@@ -2068,7 +2069,7 @@ RegisterOperators reg2({
20682069
"prim::min(int[] x) -> int",
20692070
[](Stack& stack) {
20702071
c10::List<int64_t> int_list = pop(stack).toIntList();
2071-
int64_t min_element = std::numeric_limits<int64_t>::max();
2072+
int64_t min_element = std::numeric_limits<int64_t>::max();
20722073

20732074
for(int64_t ele: int_list) {
20742075
if(ele < min_element) {

0 commit comments

Comments
 (0)