self.assertEqual(foo(), [1, 2, 3, 4])
+ def test_mutable_list_reverse_empty(self):
+ def test_reverse_empty():
+ a = []
+ a.reverse()
+
+ return a == []
+ self.checkScript(test_reverse_empty, ())
+
+ def test_mutable_list_reverse(self):
+ def test_reverse():
+ a = [1, 2, 3, 4]
+ a.reverse()
+
+ return a == [4, 3, 2, 1]
+ self.checkScript(test_reverse, ())
+
+ def test_mutable_tensor_list_reverse(self):
+ def test_tensor_reverse():
+ a = [torch.tensor(1), torch.tensor(2)]
+ a.reverse()
+
+ return a == [torch.tensor(2), torch.tensor(1)]
+ self.checkScript(test_tensor_reverse, ())
+
def test_mutable_list_pop_empty(self):
@torch.jit.script
def test_pop_empty():
}
template <typename TList>
+int listReverse(Stack& stack) {
+ TList a;
+ pop(stack, a);
+
+ auto& elements = a->elements();
+ std::reverse(elements.begin(), elements.end());
+
+ return 0;
+}
+
+template <typename TList>
int listPop(Stack& stack) {
TList list;
int64_t idx;
"(c) el) -> " decl_type "[](a!)", \
listAppend<Shared<c_type>, c_type::ElemType>), \
Operator( \
+ "aten::reverse( " decl_type "[](a!) self) -> ()", \
+ listReverse<Shared<c_type>>), \
+ Operator( \
"aten::extend(" decl_type "[](a!) self, " decl_type \
" [] other) -> ()", \
listExtend<Shared<c_type>>), \
" el) -> " decl_type "[](a!)", \
listAppend<Shared<c_type>, c_type::ElemType>), \
Operator( \
+ "aten::reverse(" decl_type "[](a!) self) -> ()", \
+ listReverse<Shared<c_type>>), \
+ Operator( \
"aten::extend(" decl_type "[](a!) self, " decl_type \
" [] other) -> ()", \
listExtend<Shared<c_type>>), \
#undef CREATE_MUTABLE_LIST_OPS
#define CREATE_LIST_OPS(decl_type, c_type) \
- Operator("aten::len(" decl_type "[] a) -> int", listLen<Shared<c_type>>), \
+ Operator("aten::len(" decl_type "[] a) -> int", listLen<Shared<c_type>>), \
Operator( \
"aten::add(" decl_type "[] a, " decl_type "[] b) -> " decl_type \
"[]", \