tensorflow/compiler/xla/tests/reduce_test.cc
// Test the operational semantic that the init value is passed on the lhs for
// reduces. Can be tested by performing an "identity" reduce (that simply
// returns one of the parameters). In this case, we return the rhs, which for
// a 1D array with one element, should not be the init value.
Test the operational semantic that the init value is passed on the lhs for
reduces. Can be tested by performing an "identity" reduce (that simply
returns one of the parameters). In this case, we return the rhs, which for
a 1D array with one element, should not be the init value.
Test the operational semantic that the init value is passed on the lhs for reduces . Can be tested by performing an " identity " reduce ( that simply returns one of the parameters ) . In this case we return the rhs which for a 1D array with one element should not be the init value .
XLA_TEST_F(ReduceTest, ReduceIdentity) {
  XlaBuilder builder(TestName());
  Shape single_float = ShapeUtil::MakeShape(F32, {});
  Parameter(&builder, 0, single_float, "lhs-unused");
  Parameter(&builder, 1, single_float, "rhs-used");
  auto computation_status = builder.Build();
  TF_ASSERT_OK(computation_status.status());
  Shape operand_shape = ShapeUtil::MakeShape(F32, {1});
  Reduce(Parameter(&builder, 0, operand_shape, "operand"),
         Parameter(&builder, 1, single_float, "init"),
         computation_status.ValueOrDie(), {0});
  float operand[] = {42.0f};
  float init = 58.5f;
  float expected = 42.0f;
  Literal input_literal = LiteralUtil::CreateR1<float>(operand);
  std::unique_ptr<GlobalData> input_global_data =
      client_->TransferToServer(input_literal).ConsumeValueOrDie();
  Literal input_literal2 = LiteralUtil::CreateR0<float>(init);
  std::unique_ptr<GlobalData> input_global_data2 =
      client_->TransferToServer(input_literal2).ConsumeValueOrDie();
  ComputeAndCompareR0<float>(
      &builder, expected, {input_global_data.get(), input_global_data2.get()},
      ErrorSpec(0.0001));
}
XLA_TEST_F ( ReduceTest , ReduceIdentity ) { XlaBuilder builder ( TestName ( ) ) ; Shape single_float = ShapeUtil :: MakeShape ( F32 , { } ) ; Parameter ( & builder , 0 , single_float , " " ) ; Parameter ( & builder , 1 , single_float , " " ) ; auto computation_status = builder . Build ( ) ; TF_ASSERT_OK ( computation_status . status ( ) ) ; Shape operand_shape = ShapeUtil :: MakeShape ( F32 , { 1 } ) ; Reduce ( Parameter ( & builder , 0 , operand_shape , " " ) , Parameter ( & builder , 1 , single_float , " " ) , computation_status . ValueOrDie ( ) , { 0 } ) ; float operand [ ] = { 42.0f } ; float init = 58.5f ; float expected = 42.0f ; Literal input_literal = LiteralUtil :: CreateR1 < float > ( operand ) ; std :: unique_ptr < GlobalData > input_global_data = client_ -> TransferToServer ( input_literal ) . ConsumeValueOrDie ( ) ; Literal input_literal2 = LiteralUtil :: CreateR0 < float > ( init ) ; std :: unique_ptr < GlobalData > input_global_data2 = client_ -> TransferToServer ( input_literal2 ) . ConsumeValueOrDie ( ) ; ComputeAndCompareR0 < float > ( & builder , expected , { input_global_data . get ( ) , input_global_data2 . get ( ) } , ErrorSpec ( 0.0001 ) ) ; }
Test the operational semantic that the init value is passed on the lhs for
reduces.
Test the operational semantic that the init value is passed on the lhs for reduces .