| 582 | |
| 583 | template <typename T> |
| 584 | void TestMatMulGrad(const bool is_batch, const bool t_x, const bool t_y) { |
| 585 | TF_ASSERT_OK(root_.status()); |
| 586 | // Generate random (but compatible) shapes for matrix multiplication. |
| 587 | std::vector<TensorShape> shapes; |
| 588 | RandMatMulShapes(is_batch, t_x, t_y, &shapes); |
| 589 | TensorShape x_shape = shapes[0]; |
| 590 | TensorShape y_shape = shapes[1]; |
| 591 | TensorShape z_shape = shapes[2]; |
| 592 | auto x = |
| 593 | Placeholder(root_, DataTypeToEnum<T>::v(), Placeholder::Shape(x_shape)); |
| 594 | auto y = |
| 595 | Placeholder(root_, DataTypeToEnum<T>::v(), Placeholder::Shape(y_shape)); |
| 596 | Output z; |
| 597 | if (is_batch) { |
| 598 | z = BatchMatMul(root_, x, y, BatchMatMul::AdjX(t_x).AdjY(t_y)); |
| 599 | } else { |
| 600 | z = MatMul(root_, x, y, MatMul::TransposeA(t_x).TransposeB(t_y)); |
| 601 | } |
| 602 | |
| 603 | float max_error; |
| 604 | TF_ASSERT_OK((ComputeGradientError<T, T, float>( |
| 605 | root_, {x, y}, {x_shape, y_shape}, {z}, {z_shape}, &max_error))); |
| 606 | EXPECT_LT(max_error, 1e-3); |
| 607 | } |
| 608 | |
| 609 | void RandMatMulShapes(const bool is_batch, const bool tx, const bool ty, |
| 610 | std::vector<TensorShape>* shapes) { |
nothing calls this directly
no test coverage detected