# tensorflow::ops::TensorArrayGrad Class Reference

# tensorflow::
ops::
TensorArrayGrad

`
#include <data_flow_ops.h>
`


Creates a
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
for storing the gradients of values in the given handle.

## Summary


If the given
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
gradient already exists, returns a reference to it.


Locks the size of the original
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
by disabling its dynamic size flag.


**A note about the input flow_in:**


The handle flow_in forces the execution of the gradient lookup to occur only after certain other operations have occurred. For example, when the forward
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
is dynamically sized, writes to this
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
may resize the object. The gradient
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
is statically sized based on the size of the forward
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
when this operation executes. Furthermore, the size of the forward
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
is frozen by this call. As a result, the flow is used to ensure that the call to generate the gradient
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
only happens after all writes are executed.


In the case of dynamically sized TensorArrays, gradient computation should only be performed on read operations that have themselves been chained via flow to occur only after all writes have executed. That way the final size of the forward
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
is known when this operation is called.


**A note about the source attribute:**


[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
gradient calls use an accumulator
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
object. If multiple gradients are calculated and run in the same session, the multiple gradient nodes may accidentally flow through the same accumulator
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
. This double counts and generally breaks the
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
gradient flow.


The solution is to identify which gradient call this particular
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
gradient is being called in. This is performed by identifying a unique string (e.g. "gradients", "gradients_1", ...) from the input gradient
[Tensor](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)
's name. This string is used as a suffix when creating the
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
gradient object here (the attribute
`
source
`
).


The attribute
`
source
`
is added as a suffix to the forward
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
's name when performing the creation / lookup, so that each separate gradient calculation gets its own
[TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array)
accumulator.


Args:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- handle: The handle to the forward [TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) .
- flow_in: A float scalar that enforces proper chaining of operations.
- source: The gradient source string, used to decide which gradient [TensorArray](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array#classtensorflow_1_1ops_1_1_tensor_array) to return.

<br />


Returns:

- `
  https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output
  ` grad_handle
- `
  https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output
  ` flow_out

<br />

| ### Constructors and Destructors ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array-grad#classtensorflow_1_1ops_1_1_tensor_array_grad_1a6240f50f9c7efdcf3bf8d48c4218d27b (const :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input handle, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input flow_in, StringPiece source) ` ||

| ### Public attributes ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array-grad#classtensorflow_1_1ops_1_1_tensor_array_grad_1a2499ef8bb9c633df24389a51f37654da ` | ` :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array-grad#classtensorflow_1_1ops_1_1_tensor_array_grad_1ab5be040d777eb52f767d58a83a3a345d ` | ` :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/tensor-array-grad#classtensorflow_1_1ops_1_1_tensor_array_grad_1ae7c0b0022fc4a44d321bf759c55413c2 ` | ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation ` |

## Public attributes

### flow_out

```
::tensorflow::Output flow_out
```

### grad_handle

```
::tensorflow::Output grad_handle
```

### operation

```
Operation operation
```

## Public functions

### TensorArrayGrad

```
 TensorArrayGrad(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input handle,
  ::tensorflow::Input flow_in,
  StringPiece source
)
```