tensorflow/core/util/tensor_slice_set_test.cc
// 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.


We assume this is a row-major matrix.

Testing the meta version of the tensor slice set.
We assume this is a row - major matrix . Testing the meta version of the tensor slice set .
TEST(TensorSliceSetTest, QueryMetaTwoD) {
  TensorShape shape({4, 5});
  TensorSliceSet tss(shape, DT_INT32);
  TensorSlice slice_1 = TensorSlice::ParseOrDie("0,2:-");
  TF_CHECK_OK(tss.Register(slice_1, "slice_1"));
  TensorSlice slice_2 = TensorSlice::ParseOrDie("2,2:0,3");
  TF_CHECK_OK(tss.Register(slice_2, "slice_2"));
  TensorSlice slice_3 = TensorSlice::ParseOrDie("3,1:3,2");
  TF_CHECK_OK(tss.Register(slice_3, "slice_3"));
  {
    TensorSlice s = TensorSlice::ParseOrDie("0,2:-");
    std::vector<std::pair<TensorSlice, string>> results;
    EXPECT_TRUE(tss.QueryMeta(s, &results));
    EXPECT_EQ(1, results.size());
    EXPECT_EQ("0,2:-", results[0].first.DebugString());
    EXPECT_EQ("slice_1", results[0].second);
  }
  {
    TensorSlice s = TensorSlice::ParseOrDie("1,1:-");
    std::vector<std::pair<TensorSlice, string>> results;
    EXPECT_TRUE(tss.QueryMeta(s, &results));
    EXPECT_EQ(1, results.size());
    EXPECT_EQ("0,2:-", results[0].first.DebugString());
    EXPECT_EQ("slice_1", results[0].second);
  }
  {
    TensorSlice s = TensorSlice::ParseOrDie("1,2:0,3");
    std::vector<std::pair<TensorSlice, string>> results;
    EXPECT_TRUE(tss.QueryMeta(s, &results));
    EXPECT_EQ(2, results.size());
    if (results[0].second == "slice_2") {
      EXPECT_EQ("2,2:0,3", results[0].first.DebugString());
      EXPECT_EQ("slice_2", results[0].second);
      EXPECT_EQ("0,2:-", results[1].first.DebugString());
      EXPECT_EQ("slice_1", results[1].second);
    } else {
      EXPECT_EQ("0,2:-", results[0].first.DebugString());
      EXPECT_EQ("slice_1", results[0].second);
      EXPECT_EQ("2,2:0,3", results[1].first.DebugString());
      EXPECT_EQ("slice_2", results[1].second);
    }
  }
  {
    TensorSlice s = TensorSlice::ParseOrDie("1,2:2,3");
    std::vector<std::pair<TensorSlice, string>> results;
    EXPECT_FALSE(tss.QueryMeta(s, &results));
    EXPECT_EQ(0, results.size());
  }
}
TEST ( TensorSliceSetTest , QueryMetaTwoD ) { TensorShape shape ( { 4 , 5 } ) ; TensorSliceSet tss ( shape , DT_INT32 ) ; TensorSlice slice_1 = TensorSlice :: ParseOrDie ( " " ) ; TF_CHECK_OK ( tss . Register ( slice_1 , " " ) ) ; TensorSlice slice_2 = TensorSlice :: ParseOrDie ( " " ) ; TF_CHECK_OK ( tss . Register ( slice_2 , " " ) ) ; TensorSlice slice_3 = TensorSlice :: ParseOrDie ( " " ) ; TF_CHECK_OK ( tss . Register ( slice_3 , " " ) ) ; { TensorSlice s = TensorSlice :: ParseOrDie ( " " ) ; std :: vector < std :: pair < TensorSlice , string > > results ; EXPECT_TRUE ( tss . QueryMeta ( s , & results ) ) ; EXPECT_EQ ( 1 , results . size ( ) ) ; EXPECT_EQ ( " " , results [ 0 ] . first . DebugString ( ) ) ; EXPECT_EQ ( " " , results [ 0 ] . second ) ; } { TensorSlice s = TensorSlice :: ParseOrDie ( " " ) ; std :: vector < std :: pair < TensorSlice , string > > results ; EXPECT_TRUE ( tss . QueryMeta ( s , & results ) ) ; EXPECT_EQ ( 1 , results . size ( ) ) ; EXPECT_EQ ( " " , results [ 0 ] . first . DebugString ( ) ) ; EXPECT_EQ ( " " , results [ 0 ] . second ) ; } { TensorSlice s = TensorSlice :: ParseOrDie ( " " ) ; std :: vector < std :: pair < TensorSlice , string > > results ; EXPECT_TRUE ( tss . QueryMeta ( s , & results ) ) ; EXPECT_EQ ( 2 , results . size ( ) ) ; if ( results [ 0 ] . second == " " ) { EXPECT_EQ ( " " , results [ 0 ] . first . DebugString ( ) ) ; EXPECT_EQ ( " " , results [ 0 ] . second ) ; EXPECT_EQ ( " " , results [ 1 ] . first . DebugString ( ) ) ; EXPECT_EQ ( " " , results [ 1 ] . second ) ; } else { EXPECT_EQ ( " " , results [ 0 ] . first . DebugString ( ) ) ; EXPECT_EQ ( " " , results [ 0 ] . second ) ; EXPECT_EQ ( " " , results [ 1 ] . first . DebugString ( ) ) ; EXPECT_EQ ( " " , results [ 1 ] . second ) ; } } { TensorSlice s = TensorSlice :: ParseOrDie ( " " ) ; std :: vector < std :: pair < TensorSlice , string > > results ; EXPECT_FALSE ( tss . QueryMeta ( s , & results ) ) ; EXPECT_EQ ( 0 , results . size ( ) ) ; } }
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
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 store a few slices. // Slice #1 is the top two rows: //   0   1   2   3   4 //   5   6   7   8   9 //   .   .   .   .   . //   .   .   .   .   . // Slice #2 is the bottom left corner //   .   .   .   .   . //   .   .   .   .   . //  10  11  12   .   . //  15  16  17   .   . // Slice #3 is the bottom right corner //   .   .   .   .   . //   .   .   .   .   . //   .   .   .   .   . //   .   .   .  18  19 // Notice that we leave a hole in the tensor //   .   .   .   .   . //   .   .   .   .   . //   .   .   . (13) (14) //   .   .   .   .   . // Now we query some of the slices // Slice #1 is an exact match //   0   1   2   3   4 //   5   6   7   8   9 //   .   .   .   .   . //   .   .   .   .   . // We just need slice_1 for this // Slice #2 is a subset match //   .   .   .   .   . //   5   6   7   8   9 //   .   .   .   .   . //   .   .   .   .   . // We just need slice_1 for this // Slice #3 is a more complicated match: it needs the combination of a couple // of slices //   .   .   .   .   . //   5   6   7   .   . //  10  11  12   .   . //   .   .   .   .   . // We need both slice_1 and slice_2 for this. // Allow results to be returned in either order // Slice #4 includes the hole and so there is no match //   .   .   .   .   . //   .   .   7   8   9 //   .   .  12  13  14 //   .   .   .   .   .