tensorflow/compiler/xla/tests/reduce_test.cc
// Add-reduces a broadcasted scalar matrix among dimension 1 and 0.
Add-reduces a broadcasted scalar matrix among dimension 1 and 0.
Add - reduces a broadcasted scalar matrix among dimension 1 and 0 .
XLA_TEST_F(ReduceTest, AddReduce2DScalarToR0) {
  XlaBuilder builder(TestName());
  auto add = CreateScalarAddComputation(F32, &builder);
  auto scalar = ConstantR0<float>(&builder, 42.0);
  auto broadcasted = Broadcast(scalar, {500, 500});
  Reduce(broadcasted, ConstantR0<float>(&builder, 0.0f), add, {0, 1});
  float expected = 42.0f * static_cast<float>(500 * 500);
  ComputeAndCompareR0<float>(&builder, expected, {}, ErrorSpec(0.0001));
}
XLA_TEST_F ( ReduceTest , AddReduce2DScalarToR0 ) { XlaBuilder builder ( TestName ( ) ) ; auto add = CreateScalarAddComputation ( F32 , & builder ) ; auto scalar = ConstantR0 < float > ( & builder , 42.0 ) ; auto broadcasted = Broadcast ( scalar , { 500 , 500 } ) ; Reduce ( broadcasted , ConstantR0 < float > ( & builder , 0.0f ) , add , { 0 , 1 } ) ; float expected = 42.0f * static_cast < float > ( 500 * 500 ) ; ComputeAndCompareR0 < float > ( & builder , expected , { } , ErrorSpec ( 0.0001 ) ) ; }
Add-reduces a broadcasted scalar matrix among dimension 1 and 0.
Add - reduces a broadcasted scalar matrix among dimension 1 and 0 .