Skip to content

Commit 03fa29e

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

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

torch/csrc/jit/register_prim_ops.cpp

Lines changed: 8 additions & 8 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>
@@ -1920,7 +1919,8 @@ RegisterOperators reg2({
19201919
"[] l, int start, int end=9223372036854775807, int step=1) -> " decl_type \
19211920
"[]", \
19221921
listSlice<c_type::value_type>), \
1923-
Operator("aten::list(" decl_type "[] l) -> " decl_type "[]", listList), \
1922+
Operator("aten::list(" decl_type "[] l) -> " decl_type "[]", \
1923+
listList<c_type::value_type>), \
19241924
Operator( \
19251925
"aten::mul(" decl_type "[] l, int n) -> " decl_type "[]", \
19261926
listMulIntLeft<c_type::value_type>), \
@@ -2068,7 +2068,7 @@ RegisterOperators reg2({
20682068
"prim::min(int[] x) -> int",
20692069
[](Stack& stack) {
20702070
c10::List<int64_t> int_list = pop(stack).toIntList();
2071-
int64_t min_element = std::numeric_limits<int64_t>::max();
2071+
int64_t min_element = std::numeric_limits<int64_t>::max();
20722072

20732073
for(int64_t ele: int_list) {
20742074
if(ele < min_element) {

0 commit comments

Comments
 (0)