Gradient for TensorArrayGather. Args: op: Forward TensorArrayGather op. grad: Gradient `Tensor` to TensorArrayGather. Returns: A flow `Tensor`, which can be used in control dependencies to force the write of `grad` to the gradient `TensorArray`.
(op, grad)
| 141 | @ops.RegisterGradient("TensorArrayGatherV2") |
| 142 | @ops.RegisterGradient("TensorArrayGatherV3") |
| 143 | def _TensorArrayGatherGrad(op, grad): |
| 144 | """Gradient for TensorArrayGather. |
| 145 | |
| 146 | Args: |
| 147 | op: Forward TensorArrayGather op. |
| 148 | grad: Gradient `Tensor` to TensorArrayGather. |
| 149 | |
| 150 | Returns: |
| 151 | A flow `Tensor`, which can be used in control dependencies to |
| 152 | force the write of `grad` to the gradient `TensorArray`. |
| 153 | """ |
| 154 | # Note: the forward flow dependency in the call to grad() is necessary for |
| 155 | # the case of dynamic sized TensorArrays. When creating the gradient |
| 156 | # TensorArray, the final size of the forward array must be known. |
| 157 | # For this we need to wait until it has been created by depending on |
| 158 | # the input flow of the original op. |
| 159 | handle = op.inputs[0] |
| 160 | indices = op.inputs[1] |
| 161 | flow = op.inputs[2] |
| 162 | dtype = op.get_attr("dtype") |
| 163 | grad_source = _GetGradSource(grad) |
| 164 | g = (tensor_array_ops.TensorArray(dtype=dtype, handle=handle, flow=flow, |
| 165 | colocate_with_first_write_call=False) |
| 166 | .grad(source=grad_source, flow=flow)) |
| 167 | u_g = g.scatter(indices, grad) |
| 168 | return [None, None, u_g.flow] |
| 169 | |
| 170 | |
| 171 | @ops.RegisterGradient("TensorArrayScatter") |
nothing calls this directly
no test coverage detected