tensorflow/compiler/xla/tests/tuple_test.cc
// Builds two new tuples from an existing tuple (by means of GetTupleElement),
// then adds up the components of the new tuples.
Builds two new tuples from an existing tuple (by means of GetTupleElement),
then adds up the components of the new tuples.
Builds two new tuples from an existing tuple ( by means of GetTupleElement ) then adds up the components of the new tuples .
XLA_TEST_F(TupleTest, TupleGTEToTupleToGTEAdd) {
   v------           --(GTE 0)--             --(GTE 0)----------
          \         /           \           /                   \
           (tuple)--             (tuple01)--                     \
          /   |     \           /           \                     \
   m------    |      --(GTE 1)--             --(GTE 1)------------ \
              |                                                   \ \
              |                                                    (add)
              |                                                   / /
              |--------(GTE 1)--             --(GTE 0)------------ /
               \                \           /                     /
                \                (tuple10)--                     /
                 \              /           \                   /
                  -----(GTE 0)--             --(GTE 1)----------
  XlaBuilder builder(TestName());
  std::initializer_list<float> constant_vector = {1.f, 2.f, 3.f};
  std::initializer_list<std::initializer_list<float>> constant_matrix = {
      {1.f, 2.f, 3.f},   row 0
      {4.f, 5.f, 6.f},   row 1
  };
  auto tuple_data =
      Tuple(&builder, {ConstantR1<float>(&builder, constant_vector),
                       ConstantR2<float>(&builder, constant_matrix)});
  auto new_tuple01 = Tuple(&builder, {GetTupleElement(tuple_data, 0),
                                      GetTupleElement(tuple_data, 1)});
  auto new_tuple10 = Tuple(&builder, {GetTupleElement(tuple_data, 1),
                                      GetTupleElement(tuple_data, 0)});
  auto vector_from_01 = GetTupleElement(new_tuple01, 0);
  auto vector_from_10 = GetTupleElement(new_tuple10, 1);
  auto matrix_from_01 = GetTupleElement(new_tuple01, 1);
  auto matrix_from_10 = GetTupleElement(new_tuple10, 0);
  auto addvectors = Add(vector_from_01, vector_from_10);
  auto addmatrices = Add(matrix_from_01, matrix_from_10);
  Add(addmatrices, addvectors,
      {1});
  Array2D<float> expected({
      {4.f, 8.f, 12.f},     row 0
      {10.f, 14.f, 18.f},   row 1
  });
  ComputeAndCompareR2<float>(&builder, expected, {}, error_spec_);
}
XLA_TEST_F ( TupleTest , TupleGTEToTupleToGTEAdd ) { XlaBuilder builder ( TestName ( ) ) ; std :: initializer_list < float > constant_vector = { 1.f , 2.f , 3.f } ; std :: initializer_list < std :: initializer_list < float > > constant_matrix = { { 1.f , 2.f , 3.f } , { 4.f , 5.f , 6.f } , } ; auto tuple_data = Tuple ( & builder , { ConstantR1 < float > ( & builder , constant_vector ) , ConstantR2 < float > ( & builder , constant_matrix ) } ) ; auto new_tuple01 = Tuple ( & builder , { GetTupleElement ( tuple_data , 0 ) , GetTupleElement ( tuple_data , 1 ) } ) ; auto new_tuple10 = Tuple ( & builder , { GetTupleElement ( tuple_data , 1 ) , GetTupleElement ( tuple_data , 0 ) } ) ; auto vector_from_01 = GetTupleElement ( new_tuple01 , 0 ) ; auto vector_from_10 = GetTupleElement ( new_tuple10 , 1 ) ; auto matrix_from_01 = GetTupleElement ( new_tuple01 , 1 ) ; auto matrix_from_10 = GetTupleElement ( new_tuple10 , 0 ) ; auto addvectors = Add ( vector_from_01 , vector_from_10 ) ; auto addmatrices = Add ( matrix_from_01 , matrix_from_10 ) ; Add ( addmatrices , addvectors , { 1 } ) ; Array2D < float > expected ( { { 4.f , 8.f , 12.f } , { 10.f , 14.f , 18.f } , } ) ; ComputeAndCompareR2 < float > ( & builder , expected , { } , error_spec_ ) ; }
Builds two new tuples from an existing tuple (by means of GetTupleElement),
then adds up the components of the new tuples.
Builds two new tuples from an existing tuple ( by means of GetTupleElement ) then adds up the components of the new tuples .
// // v------           --(GTE 0)--             --(GTE 0)---------- //        \         /           \           /                   \
  //         (tuple)--             (tuple01)--                     \
  //        /   |     \           /           \                     \
  // m------    |      --(GTE 1)--             --(GTE 1)------------ \
  //            |                                                   \ \
  //            |                                                    (add) //            |                                                   / / //            |--------(GTE 1)--             --(GTE 0)------------ / //             \                \           /                     / //              \                (tuple10)--                     / //               \              /           \                   / //                -----(GTE 0)--             --(GTE 1)---------- // row 0 // row 1 /*broadcast_dimensions=*/ // row 0 // row 1