tensorflow/compiler/xla/tests/tuple_test.cc
// Extracts both elements from a tuple with GetTupleElement and then adds them
// together.
Extracts both elements from a tuple with GetTupleElement and then adds them
together.
Extracts both elements from a tuple with GetTupleElement and then adds them together .
XLA_TEST_F(TupleTest, AddTupleElements) {
  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 vector_element = GetTupleElement(tuple_data, 0);
  auto matrix_element = GetTupleElement(tuple_data, 1);
  auto vector_shape = builder.GetShape(vector_element).ConsumeValueOrDie();
  auto matrix_shape = builder.GetShape(matrix_element).ConsumeValueOrDie();
  Add(matrix_element, vector_element,
      {1});
  Array2D<float> expected({
      {2.f, 4.f, 6.f},  
      {5.f, 7.f, 9.f},  
  });
  ASSERT_TRUE(ShapeUtil::Equal(vector_shape, ShapeUtil::MakeShape(F32, {3})));
  ASSERT_TRUE(ShapeUtil::Equal(matrix_shape,
                               ShapeUtil::MakeShape(F32, {2, 3})));
  ComputeAndCompareR2<float>(&builder, expected, {}, error_spec_);
}
XLA_TEST_F ( TupleTest , AddTupleElements ) { 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 vector_element = GetTupleElement ( tuple_data , 0 ) ; auto matrix_element = GetTupleElement ( tuple_data , 1 ) ; auto vector_shape = builder . GetShape ( vector_element ) . ConsumeValueOrDie ( ) ; auto matrix_shape = builder . GetShape ( matrix_element ) . ConsumeValueOrDie ( ) ; Add ( matrix_element , vector_element , { 1 } ) ; Array2D < float > expected ( { { 2.f , 4.f , 6.f } , { 5.f , 7.f , 9.f } , } ) ; ASSERT_TRUE ( ShapeUtil :: Equal ( vector_shape , ShapeUtil :: MakeShape ( F32 , { 3 } ) ) ) ; ASSERT_TRUE ( ShapeUtil :: Equal ( matrix_shape , ShapeUtil :: MakeShape ( F32 , { 2 , 3 } ) ) ) ; ComputeAndCompareR2 < float > ( & builder , expected , { } , error_spec_ ) ; }
Extracts both elements from a tuple with GetTupleElement and then adds them
together.
Extracts both elements from a tuple with GetTupleElement and then adds them together .
// row 0 // row 1 /*broadcast_dimensions=*/ // row 0 // row 1 /*y=*/ /*x=*/