tensorflow/compiler/xla/tests/broadcast_simple_test.cc
// r1 and r3's dim0 matches, and r1's dim1 and dim2 have size 1:
r1 and r3's dim0 matches, and r1's dim1 and dim2 have size 1.
r1 and r3 ' s dim0 matches and r1 ' s dim1 and dim2 have size 1 .
XLA_TEST_F(BroadcastSimpleTest, Add3DTo3DDegenerate_1_2) {
  XlaBuilder b(TestName());
  XlaOp r1h;
  XlaOp r3h;
  Array3D<float> r1d = {{{1}}, {{2}}};
  Array3D<float> r3d = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}};
  auto r1 = CreateR3Parameter(r1d, 1, "r1", &b, &r1h);
  auto r3 = CreateR3Parameter(r3d, 0, "r3", &b, &r3h);
  Add(r3h, r1h);
  auto expected =
      LiteralUtil::CreateR3<float>({{{2, 3}, {4, 5}}, {{7, 8}, {9, 10}}});
  ComputeAndCompareLiteral(&b, expected, {r3.get(), r1.get()},
                           ErrorSpec(0.0001));
}
XLA_TEST_F ( BroadcastSimpleTest , Add3DTo3DDegenerate_1_2 ) { XlaBuilder b ( TestName ( ) ) ; XlaOp r1h ; XlaOp r3h ; Array3D < float > r1d = { { { 1 } } , { { 2 } } } ; Array3D < float > r3d = { { { 1 , 2 } , { 3 , 4 } } , { { 5 , 6 } , { 7 , 8 } } } ; auto r1 = CreateR3Parameter ( r1d , 1 , " " , & b , & r1h ) ; auto r3 = CreateR3Parameter ( r3d , 0 , " " , & b , & r3h ) ; Add ( r3h , r1h ) ; auto expected = LiteralUtil :: CreateR3 < float > ( { { { 2 , 3 } , { 4 , 5 } } , { { 7 , 8 } , { 9 , 10 } } } ) ; ComputeAndCompareLiteral ( & b , expected , { r3 . get ( ) , r1 . get ( ) } , ErrorSpec ( 0.0001 ) ) ; }
r1 and r3's dim0 matches, and r1's dim1 and dim2 have size 1:
r1 and r3 ' s dim0 matches and r1 ' s dim1 and dim2 have size 1 :