MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / TEST

Function TEST

dnn/test/common/named_tensor.cpp:11–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9using megdnn::test::MegDNNError;
10
11TEST(NAMED_TENSOR, NAMED_TENSOR_SHAPE_BASIC) {
12 ASSERT_EQ(Dimension::NR_NAMES, 10);
13 Dimension dim0 = {"C"}, dim1 = {"C//32"}, dim2 = {"C//4"}, dim3 = {"C%32"},
14 dim4 = {"C%4"}, dim5 = {"C//4%8"};
15 ASSERT_TRUE(dim0 == dim1 * dim3);
16 ASSERT_TRUE(dim2 == dim1 * dim5);
17 ASSERT_THROW(dim0 * dim0, MegDNNError);
18
19 ASSERT_TRUE(dim1 == dim0 / dim3);
20 ASSERT_TRUE(dim3 == dim0 / dim1);
21 ASSERT_TRUE(dim4 == dim3 / dim5);
22 ASSERT_TRUE(dim5 == dim3 / dim4);
23 ASSERT_TRUE(dim5 == dim2 / dim1);
24 ASSERT_THROW(dim5 / dim1, MegDNNError);
25
26 ASSERT_TRUE(dim1 < dim4);
27 ASSERT_TRUE(dim5 < dim4);
28 ASSERT_FALSE(dim4 < dim5);
29 ASSERT_TRUE(dim1 < dim2);
30 ASSERT_FALSE(dim2 < dim1);
31
32 auto shape0 =
33 NamedTensorShape::make_named_tensor_shape(NamedTensorShape::Format::NCHW);
34 SmallVector<Dimension> dims = {{"N"}, {"C"}, {"H"}, {"W"}};
35 NamedTensorShape shape1(dims);
36 NamedTensorShape shape2{{"N"}, {"C"}, {"H"}, {"W"}};
37 ASSERT_TRUE(shape0.eq_shape(shape1));
38 ASSERT_TRUE(shape0.eq_shape(shape2));
39 ASSERT_TRUE(shape1.eq_shape(shape2));
40 auto shape3 =
41 NamedTensorShape::make_named_tensor_shape(NamedTensorShape::Format::NCHW4);
42 ASSERT_FALSE(shape0.eq_shape(shape3));
43 auto shape4 = NamedTensorShape::make_named_tensor_shape(
44 NamedTensorShape::Format::NCHW44_DOT);
45 std::sort(shape4.dims.begin(), shape4.dims.begin() + shape4.ndim);
46 NamedTensorShape shape5{{"N"}, {"C//32"}, {"H"}, {"W"}, {"C//8%4"}, {"C%8"}};
47 std::sort(shape5.dims.begin(), shape5.dims.begin() + shape5.ndim);
48}
49// vim: syntax=cpp.doxygen

Callers

nothing calls this directly

Calls 3

sortFunction · 0.85
eq_shapeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected