MatMulGrad common used to read and check node attr state, and determine proper MatMul products for gradients based on input matrix transposition combinations.
| 1087 | // proper MatMul products for gradients based on input matrix transposition |
| 1088 | // combinations. |
| 1089 | Status MatMulGradCommon(const Scope& scope, const Operation& op, |
| 1090 | const bool is_batch, |
| 1091 | const std::vector<Output>& grad_inputs, |
| 1092 | const string& attr_adj_x, const string& attr_adj_y, |
| 1093 | std::vector<Output>* grad_outputs) { |
| 1094 | auto a = op.input(0); |
| 1095 | auto b = op.input(1); |
| 1096 | // Use conjugate of the inputs for MatMul |
| 1097 | if (is_batch == false) { |
| 1098 | a = ConjugateHelper(scope, a); |
| 1099 | b = ConjugateHelper(scope, b); |
| 1100 | } |
| 1101 | auto product = op.output(0); |
| 1102 | |
| 1103 | bool ta; |
| 1104 | bool tb; |
| 1105 | TF_RETURN_IF_ERROR(GetNodeAttr(product.node()->attrs(), attr_adj_x, &ta)); |
| 1106 | TF_RETURN_IF_ERROR(GetNodeAttr(product.node()->attrs(), attr_adj_y, &tb)); |
| 1107 | |
| 1108 | if (!ta && !tb) { |
| 1109 | return MatMulGradHelper(scope, is_batch, grad_inputs[0], false, b, true, a, |
| 1110 | true, grad_inputs[0], false, grad_outputs); |
| 1111 | } else if (!ta && tb) { |
| 1112 | return MatMulGradHelper(scope, is_batch, grad_inputs[0], false, b, false, |
| 1113 | grad_inputs[0], true, a, false, grad_outputs); |
| 1114 | } else if (ta && !tb) { |
| 1115 | return MatMulGradHelper(scope, is_batch, b, false, grad_inputs[0], true, a, |
| 1116 | false, grad_inputs[0], false, grad_outputs); |
| 1117 | } |
| 1118 | return MatMulGradHelper(scope, is_batch, b, true, grad_inputs[0], true, |
| 1119 | grad_inputs[0], true, a, true, grad_outputs); |
| 1120 | } |
| 1121 | |
| 1122 | Status MatMulGrad(const Scope& scope, const Operation& op, |
| 1123 | const std::vector<Output>& grad_inputs, |
no test coverage detected