Gradient for MatMul, only for the second input.
(op, grad)
| 1548 | |
| 1549 | |
| 1550 | def _MatMulGradAgainstSecondOnly(op, grad): |
| 1551 | """Gradient for MatMul, only for the second input.""" |
| 1552 | t_a = op.get_attr("transpose_a") |
| 1553 | t_b = op.get_attr("transpose_b") |
| 1554 | a = math_ops.conj(op.inputs[0]) |
| 1555 | if not t_a and not t_b: |
| 1556 | grad_b = gen_math_ops.mat_mul(a, grad, transpose_a=True) |
| 1557 | elif not t_a and t_b: |
| 1558 | grad_b = gen_math_ops.mat_mul(grad, a, transpose_a=True) |
| 1559 | elif t_a and not t_b: |
| 1560 | grad_b = gen_math_ops.mat_mul(a, grad) |
| 1561 | elif t_a and t_b: |
| 1562 | grad_b = gen_math_ops.mat_mul(grad, a, transpose_a=True, transpose_b=True) |
| 1563 | return None, grad_b |
| 1564 | |
| 1565 | |
| 1566 | @ops.RegisterGradient("MatMul") |