Gradients for the SparseReorder op. Args: op: the SparseReorder op unused_output_indices_grad: the incoming gradients of the output indices output_values_grad: the incoming gradients of the output values Returns: Gradient for each of the 3 input tensors: (input_indices, i
(op, unused_output_indices_grad, output_values_grad)
| 35 | |
| 36 | @ops.RegisterGradient("SparseReorder") |
| 37 | def _SparseReorderGrad(op, unused_output_indices_grad, output_values_grad): |
| 38 | """Gradients for the SparseReorder op. |
| 39 | |
| 40 | Args: |
| 41 | op: the SparseReorder op |
| 42 | unused_output_indices_grad: the incoming gradients of the output indices |
| 43 | output_values_grad: the incoming gradients of the output values |
| 44 | |
| 45 | Returns: |
| 46 | Gradient for each of the 3 input tensors: |
| 47 | (input_indices, input_values, input_shape) |
| 48 | The gradients for input_indices and input_shape is None. |
| 49 | """ |
| 50 | input_indices = op.inputs[0] |
| 51 | input_shape = op.inputs[2] |
| 52 | |
| 53 | num_entries = array_ops.shape(input_indices)[0] |
| 54 | entry_indices = math_ops.range(num_entries) |
| 55 | sp_unordered = sparse_tensor.SparseTensor( |
| 56 | input_indices, entry_indices, input_shape) |
| 57 | sp_ordered = sparse_ops.sparse_reorder(sp_unordered) |
| 58 | inverted_permutation = array_ops.invert_permutation(sp_ordered.values) |
| 59 | |
| 60 | return (None, |
| 61 | array_ops.gather(output_values_grad, inverted_permutation), |
| 62 | None) |
| 63 | |
| 64 | |
| 65 | @ops.RegisterGradient("SparseAdd") |