4 #include "ATen/core/ivalue.h" 5 #include "test/cpp/jit/test_base.h" 6 #include "test/cpp/jit/test_utils.h" 12 using Var = SymbolicVariable;
17 Shared<IntList> foo = IntList::create({3, 4, 5});
18 ASSERT_EQ(foo.use_count(), 1);
20 ASSERT_EQ(foo.use_count(), 2);
22 ASSERT_EQ(foo.use_count(), 3);
23 auto foo2 = std::move(bar);
24 ASSERT_EQ(foo.use_count(), 3);
25 ASSERT_TRUE(foo2.isIntList());
26 ASSERT_TRUE(bar.isNone());
28 ASSERT_TRUE(foo2.isDouble());
29 ASSERT_EQ(foo2.toDouble(), 4.0);
30 ASSERT_EQ(foo.use_count(), 2);
31 ASSERT_TRUE(ArrayRef<int64_t>(baz.toIntList()->elements()).equals({3, 4, 5}));
33 auto move_it = std::move(baz).toIntList();
34 ASSERT_EQ(foo.use_count(), 2);
35 ASSERT_TRUE(baz.isNone());
37 ASSERT_TRUE(i.isInt());
38 ASSERT_EQ(i.toInt(), 4);
39 IValue dlist(DoubleList::create({3.5}));
40 ASSERT_TRUE(dlist.isDoubleList());
41 ASSERT_TRUE(ArrayRef<double>(std::move(dlist).toDoubleList()->elements())
43 ASSERT_TRUE(dlist.isNone());
44 dlist = IValue(DoubleList::create({3.4}));
45 ASSERT_TRUE(ArrayRef<double>(dlist.toDoubleList()->elements()).equals({3.4}));
46 IValue the_list(Tuple::create({IValue(3.4), IValue(4), IValue(foo)}));
47 ASSERT_EQ(foo.use_count(), 3);
48 ASSERT_TRUE(the_list.isTuple());
49 auto first = std::move(the_list).toTuple()->elements().at(1);
50 ASSERT_EQ(first.toInt(), 4);
53 ASSERT_EQ(tv.use_count(), 2);
55 ASSERT_EQ(tv.use_count(), 3);
56 ASSERT_TRUE(ten2.toTensor().equal(ten.toTensor()));
57 std::move(ten2).toTensor();
58 ASSERT_EQ(tv.use_count(), 2);