| 847 | } |
| 848 | |
| 849 | Status MatMulGradCommon(const string& opname, const string& attr_adj_x, |
| 850 | const string& attr_adj_y, const AttrSlice& attrs, |
| 851 | FunctionDef* g, bool enable_broadcasting) { |
| 852 | DataType T; |
| 853 | TF_RETURN_IF_ERROR(GetNodeAttr(attrs, "T", &T)); |
| 854 | if (T == DT_COMPLEX64 || T == DT_COMPLEX128) { |
| 855 | return errors::Unimplemented( |
| 856 | "MatMul gradient for complex is not supported yet."); |
| 857 | } |
| 858 | bool ta; |
| 859 | bool tb; |
| 860 | TF_RETURN_IF_ERROR(GetNodeAttr(attrs, attr_adj_x, &ta)); |
| 861 | TF_RETURN_IF_ERROR(GetNodeAttr(attrs, attr_adj_y, &tb)); |
| 862 | if (!ta && !tb) { |
| 863 | return MatMulGradHelper(g, opname, attr_adj_x, attr_adj_y, "dz", false, "y", |
| 864 | true, "x", true, "dz", false, enable_broadcasting); |
| 865 | } |
| 866 | if (!ta && tb) { |
| 867 | return MatMulGradHelper(g, opname, attr_adj_x, attr_adj_y, "dz", false, "y", |
| 868 | false, "dz", true, "x", false, enable_broadcasting); |
| 869 | } |
| 870 | if (ta && !tb) { |
| 871 | return MatMulGradHelper(g, opname, attr_adj_x, attr_adj_y, "y", false, "dz", |
| 872 | true, "x", false, "dz", false, enable_broadcasting); |
| 873 | } |
| 874 | CHECK(ta && tb); |
| 875 | return MatMulGradHelper(g, opname, attr_adj_x, attr_adj_y, "y", true, "dz", |
| 876 | true, "dz", true, "x", true, enable_broadcasting); |
| 877 | } |
| 878 | |
| 879 | Status MatMulGrad(const AttrSlice& attrs, FunctionDef* g) { |
| 880 | return MatMulGradCommon("MatMul", "transpose_a", "transpose_b", attrs, g, |