Gradient for MatMul.
(op, grad)
| 1565 | |
| 1566 | @ops.RegisterGradient("MatMul") |
| 1567 | def _MatMulGrad(op, grad): |
| 1568 | """Gradient for MatMul.""" |
| 1569 | try: |
| 1570 | skip_input_indices = op.skip_input_indices |
| 1571 | if skip_input_indices is not None: |
| 1572 | if 1 in skip_input_indices: |
| 1573 | return _MatMulGradAgainstFirstOnly(op, grad) |
| 1574 | elif 0 in skip_input_indices: |
| 1575 | return _MatMulGradAgainstSecondOnly(op, grad) |
| 1576 | except AttributeError: |
| 1577 | # No gradient skipping, so do the full gradient computation |
| 1578 | pass |
| 1579 | |
| 1580 | t_a = op.get_attr("transpose_a") |
| 1581 | t_b = op.get_attr("transpose_b") |
| 1582 | a = math_ops.conj(op.inputs[0]) |
| 1583 | b = math_ops.conj(op.inputs[1]) |
| 1584 | if not t_a and not t_b: |
| 1585 | grad_a = gen_math_ops.mat_mul(grad, b, transpose_b=True) |
| 1586 | grad_b = gen_math_ops.mat_mul(a, grad, transpose_a=True) |
| 1587 | elif not t_a and t_b: |
| 1588 | grad_a = gen_math_ops.mat_mul(grad, b) |
| 1589 | grad_b = gen_math_ops.mat_mul(grad, a, transpose_a=True) |
| 1590 | elif t_a and not t_b: |
| 1591 | grad_a = gen_math_ops.mat_mul(b, grad, transpose_b=True) |
| 1592 | grad_b = gen_math_ops.mat_mul(a, grad) |
| 1593 | elif t_a and t_b: |
| 1594 | grad_a = gen_math_ops.mat_mul(b, grad, transpose_a=True, transpose_b=True) |
| 1595 | grad_b = gen_math_ops.mat_mul(grad, a, transpose_a=True, transpose_b=True) |
| 1596 | return grad_a, grad_b |
| 1597 | |
| 1598 | |
| 1599 | @ops.RegisterGradient("SparseMatMul") |
nothing calls this directly
no test coverage detected