14

The docs say:

In addition, variants of these types with the _ref suffix are defined for reference-typed tensors.

What exactly does this mean? What are reference-typed tensors and how do they differ from standard ones?

dannygoldstein
  • 275
  • 2
  • 7

1 Answers1

16

A reference-typed tensor is mutable. The most common way to create a reference-typed tensor is to define a tf.Variable: defining a tf.Variable whose initial value has dtype tf.float32 will create a reference-typed tensor with dtype tf.float32_ref. You can mutate a reference-typed tensor by passing it as the first argument to tf.assign().

(Note that reference-typed tensors are something of an implementation detail in the present version of TensorFlow. We'd encourage you to use higher-level wrappers like tf.Variable, which may migrate to alternative representations for mutable state in the future.)

mrry
  • 125,488
  • 26
  • 399
  • 400
  • 2
    There isn't any documentation for `tf.assign()`, is it on purpose? – Olivier Moindrot Jun 22 '16 at 10:24
  • 1
    It's semi-on-purpose. We'd encourage using `tf.Variable.assign()` in preference to `tf.assign()`, but there are a few use cases (in particular, chained assignments) that only work with `tf.assign()`, so we haven't been able to remove it altogether. – mrry Jun 23 '16 at 05:32