| 85 | // |
| 86 | |
| 87 | TEST_F(GradientsTest, OneMatMul) { |
| 88 | for (const bool expected : {false, true}) { |
| 89 | const Scope& scope = expected ? scope_expected_ : scope_test_; |
| 90 | // Construct forward graph. |
| 91 | auto x = Const(scope, {{1.0, 2.0}, {3.0, 4.0}}); |
| 92 | auto y = Const(scope, {{1.0, 0.0}, {0.0, 1.0}}); |
| 93 | auto z = MatMul(scope, x, y); |
| 94 | TF_ASSERT_OK(scope.status()); |
| 95 | CHECK_NOTNULL(z.node()); |
| 96 | |
| 97 | if (expected) { |
| 98 | // Construct backward graph. |
| 99 | auto dz = Const(scope, {{1.0, 1.0}, {1.0, 1.0}}); |
| 100 | auto dx = MatMul(scope, dz, y, MatMul::TransposeB(true)); |
| 101 | auto dy = MatMul(scope, x, dz, MatMul::TransposeA(true)); |
| 102 | } else { |
| 103 | // Call AddSymbolicGradients. |
| 104 | auto dz = Const(scope, {{1.0, 1.0}, {1.0, 1.0}}); |
| 105 | std::vector<Output> grad_outputs; |
| 106 | TF_ASSERT_OK( |
| 107 | AddSymbolicGradients(scope, {z}, {x, y}, {dz}, &grad_outputs)); |
| 108 | } |
| 109 | } |
| 110 | CompareTestAndExpectedGraphs(); |
| 111 | } |
| 112 | |
| 113 | TEST_F(GradientsTest, OneMatMul_InferGradInputs) { |
| 114 | for (const bool expected : {false, true}) { |
nothing calls this directly
no test coverage detected