# tensorflow::ops::TemporaryVariable Class Reference

# tensorflow::ops::TemporaryVariable

`#include <state_ops.h>`

Returns a tensor that may be mutated, but only persists within a single step.

## Summary

This is an experimental op for internal use only and it is possible to use this op in unsafe ways. DO NOT USE unless you fully understand the risks.

It is the caller's responsibility to ensure that 'ref' is eventually passed to a matching '[DestroyTemporaryVariable](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/destroy-temporary-variable#classtensorflow_1_1ops_1_1_destroy_temporary_variable)' op after all other uses have completed.

Outputs a ref to the tensor state so it may be read or modified.

E.g. var = state_ops._temporary_variable(\[1, 2\], types.float_) var_name = var.op.name var = state_ops.assign(var, \[\[4.0, 5.0\]\]) var = state_ops.assign_add(var, \[\[6.0, 7.0\]\]) final = state_ops._destroy_temporary_variable(var, var_name=var_name)

Arguments:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- shape: The shape of the variable tensor.
- dtype: The type of elements in the variable tensor.

<br />

Optional attributes (see `https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/temporary-variable/attrs#structtensorflow_1_1ops_1_1_temporary_variable_1_1_attrs`):

- var_name: Overrides the name used for the temporary variable resource. Default value is the name of the '[TemporaryVariable](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable)' op (which is guaranteed unique).

<br />

Returns:

- `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output`: A reference to the variable tensor.

<br />

| ### Constructors and Destructors ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a694e6c48eaf39d57f59d52796a9a71d1(const ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, PartialTensorShape shape, DataType dtype)` ||
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a43909369fdad702faf95e5aab8346b1a(const ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, PartialTensorShape shape, DataType dtype, const https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/temporary-variable/attrs#structtensorflow_1_1ops_1_1_temporary_variable_1_1_attrs & attrs)` ||

| ### Public attributes ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1abf90e66f914f45a8e9c11f7409917423` | `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a62601e5fd1b28bd28a6f0db0c691fe61` | `::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` |

| ### Public functions ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a3dbe9a732d4ec4ab4f94240c0ba61210() const ` | `::tensorflow::Node *` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a8414b80274ac7ca395a565b59e90cd9e() const ` | ` `` ` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a62b24d2f958c91a5a1005127d7056dc9() const ` | ` `` ` |

| ### Public static functions ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable_1a6647c19d0e761d2c6c11ff667576cfb5(StringPiece x)` | `https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/temporary-variable/attrs#structtensorflow_1_1ops_1_1_temporary_variable_1_1_attrs` |

| ### Structs ||
|---|---|
| [tensorflow::ops::TemporaryVariable::Attrs](https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/temporary-variable/attrs) | Optional attribute setters for [TemporaryVariable](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/temporary-variable#classtensorflow_1_1ops_1_1_temporary_variable). |

## Public attributes

### operation

```
Operation operation
```

### ref

```
::tensorflow::Output ref
```

## Public functions

### TemporaryVariable

```
 TemporaryVariable(
  const ::tensorflow::Scope & scope,
  PartialTensorShape shape,
  DataType dtype
)
```

### TemporaryVariable

```
 TemporaryVariable(
  const ::tensorflow::Scope & scope,
  PartialTensorShape shape,
  DataType dtype,
  const TemporaryVariable::Attrs & attrs
)
```

### node

```
::tensorflow::Node * node() const 
```

### operator::tensorflow::Input

```
 operator::tensorflow::Input() const 
```

### operator::tensorflow::Output

```
 operator::tensorflow::Output() const 
```

## Public static functions

### VarName

```
Attrs VarName(
  StringPiece x
)
```