self.assertEqual(foo(), [1, 2, 3, 4])
+ @unittest.skipIf(sys.version_info < (3, 3), "clear not supported in version < 3.3")
+ def test_mutable_list_clear_empty(self):
+ def test_clear_empty():
+ a = torch.jit.annotate(List[int], [])
+ a.clear()
+
+ return len(a) == 0
+ self.checkScript(test_clear_empty, ())
+
+ @unittest.skipIf(sys.version_info < (3, 3), "clear not supported in version < 3.3")
+ def test_mutable_list_clear(self):
+ def test_clear():
+ a = [1, 2, 3, 4]
+ a.clear()
+
+ return len(a) == 0
+ self.checkScript(test_clear, ())
+
def test_func_call(self):
script = '''
def add(a, b):
};
}
+template <typename TList>
+int listClear(Stack& stack) {
+ TList a;
+ pop(stack, a);
+
+ a->elements().clear();
+ push(stack, a);
+
+ return 0;
+}
+
template <typename T>
Operation listSelect(const Node* node) {
return [=](Stack& stack) {
Operator( \
"aten::_set_item(" decl_type "[](a!) l, int idx, " decl_type \
" el) -> " decl_type "[](a!)", \
- listSetItem<Shared<c_type>, c_type::ElemType>)
+ listSetItem<Shared<c_type>, c_type::ElemType>), \
+ Operator( \
+ "aten::clear( " decl_type "[](a!) self) -> ()", \
+ listClear<Shared<c_type>>)
CREATE_MUTABLE_LIST_OPS("Tensor", TensorList),
Operator( \
"aten::_set_item(" decl_type "[](a!) l, int idx, " decl_type \
" el) -> " decl_type "[](a!)", \
- listSetItem<Shared<c_type>, c_type::ElemType>)
+ listSetItem<Shared<c_type>, c_type::ElemType>), \
+ Operator( \
+ "aten::clear( " decl_type "[](a!) self) -> ()", \
+ listClear<Shared<c_type>>)
CREATE_IMMUTABLE_LIST_OPS("int", IntList),
CREATE_IMMUTABLE_LIST_OPS("float", DoubleList),