MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST

Function TEST

tensorflow/core/util/tensor_slice_set_test.cc:40–145  ·  view source on GitHub ↗

A simple test: we have a 2-d tensor of shape 4 X 5 that looks like this: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 We assume this is a row-major matrix. Testing the meta version of the tensor slice set.

Source from the content-addressed store, hash-verified

38//
39// Testing the meta version of the tensor slice set.
40TEST(TensorSliceSetTest, QueryMetaTwoD) {
41 TensorShape shape({4, 5});
42
43 TensorSliceSet tss(shape, DT_INT32);
44 // We store a few slices.
45
46 // Slice #1 is the top two rows:
47 // 0 1 2 3 4
48 // 5 6 7 8 9
49 // . . . . .
50 // . . . . .
51 TensorSlice slice_1 = TensorSlice::ParseOrDie("0,2:-");
52 TF_CHECK_OK(tss.Register(slice_1, "slice_1"));
53
54 // Slice #2 is the bottom left corner
55 // . . . . .
56 // . . . . .
57 // 10 11 12 . .
58 // 15 16 17 . .
59 TensorSlice slice_2 = TensorSlice::ParseOrDie("2,2:0,3");
60 TF_CHECK_OK(tss.Register(slice_2, "slice_2"));
61
62 // Slice #3 is the bottom right corner
63 // . . . . .
64 // . . . . .
65 // . . . . .
66 // . . . 18 19
67 TensorSlice slice_3 = TensorSlice::ParseOrDie("3,1:3,2");
68 TF_CHECK_OK(tss.Register(slice_3, "slice_3"));
69
70 // Notice that we leave a hole in the tensor
71 // . . . . .
72 // . . . . .
73 // . . . (13) (14)
74 // . . . . .
75
76 // Now we query some of the slices
77
78 // Slice #1 is an exact match
79 // 0 1 2 3 4
80 // 5 6 7 8 9
81 // . . . . .
82 // . . . . .
83 // We just need slice_1 for this
84 {
85 TensorSlice s = TensorSlice::ParseOrDie("0,2:-");
86 std::vector<std::pair<TensorSlice, string>> results;
87 EXPECT_TRUE(tss.QueryMeta(s, &results));
88 EXPECT_EQ(1, results.size());
89 EXPECT_EQ("0,2:-", results[0].first.DebugString());
90 EXPECT_EQ("slice_1", results[0].second);
91 }
92
93 // Slice #2 is a subset match
94 // . . . . .
95 // 5 6 7 8 9
96 // . . . . .
97 // . . . . .

Callers

nothing calls this directly

Calls 4

QueryMetaMethod · 0.80
RegisterMethod · 0.45
sizeMethod · 0.45
DebugStringMethod · 0.45

Tested by

no test coverage detected