1 #include <gtest/gtest.h> 4 #include <c10/core/UndefinedTensorImpl.h> 9 TEST(TestUndefined, UndefinedTest) {
14 Tensor ft = ones({1}, CPU(kFloat));
17 ss << und << std::endl;
18 ASSERT_FALSE(und.defined());
19 ASSERT_EQ(std::string(
"UndefinedType"), und.toString());
21 ASSERT_ANY_THROW(und.strides());
22 ASSERT_ANY_THROW(und.dim());
23 ASSERT_ANY_THROW([]() {
return Tensor(); }() =
Scalar(5));
24 ASSERT_ANY_THROW(und.add(und));
25 ASSERT_ANY_THROW(und.add(ft));
26 ASSERT_ANY_THROW(ft.add(und));
27 ASSERT_ANY_THROW(und.add(5));
28 ASSERT_ANY_THROW(und.mm(und));
30 und.toType(und.type());
31 ASSERT_ANY_THROW(und.toType(ft.type()));
32 ASSERT_ANY_THROW(ft.toType(und.type()));
33 und.toType(ScalarType::Undefined);
34 ASSERT_ANY_THROW(und.toType(ScalarType::Float));
35 ASSERT_ANY_THROW(ft.toType(ScalarType::Undefined));
38 ASSERT_ANY_THROW(und.copy_(und));
39 ASSERT_ANY_THROW(und.copy_(ft));
40 ASSERT_ANY_THROW(ft.copy_(und));
42 und.toBackend(Backend::Undefined);
43 ASSERT_ANY_THROW(und.toBackend(Backend::CPU));
44 ASSERT_ANY_THROW(ft.toBackend(Backend::Undefined));
46 Tensor to_move = ones({1}, CPU(kFloat));
47 Tensor m(std::move(to_move));
48 ASSERT_FALSE(to_move.defined());
49 ASSERT_EQ(to_move.unsafeGetTensorImpl(), UndefinedTensorImpl::singleton());
Scalar represents a 0-dimensional tensor which contains a single element.
Flush-To-Zero and Denormals-Are-Zero mode.