fix docs formatting of tf.while_loop ()

This commit is contained in:
Yuxin Wu 2017-02-14 19:05:26 -06:00 committed by Vijay Vasudevan
parent e75c0fc925
commit 6c4fd8c6b1

View File

@ -2566,35 +2566,35 @@ def while_loop(cond, body, loop_vars, shape_invariants=None,
Example: Example:
```python ```python
i = tf.constant(0) i = tf.constant(0)
c = lambda i: tf.less(i, 10) c = lambda i: tf.less(i, 10)
b = lambda i: tf.add(i, 1) b = lambda i: tf.add(i, 1)
r = tf.while_loop(c, b, [i]) r = tf.while_loop(c, b, [i])
``` ```
Example with nesting and a namedtuple: Example with nesting and a namedtuple:
```python ```python
import collections import collections
Pair = collections.namedtuple('Pair', 'j, k') Pair = collections.namedtuple('Pair', 'j, k')
ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2))) ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2)))
c = lambda i, p: i < 10 c = lambda i, p: i < 10
b = lambda i, p: (i + 1, Pair((p.j + p.k), (p.j - p.k))) b = lambda i, p: (i + 1, Pair((p.j + p.k), (p.j - p.k)))
ijk_final = tf.while_loop(c, b, ijk_0) ijk_final = tf.while_loop(c, b, ijk_0)
``` ```
Example using shape_invariants: Example using shape_invariants:
```python ```python
i0 = tf.constant(0) i0 = tf.constant(0)
m0 = tf.ones([2, 2]) m0 = tf.ones([2, 2])
c = lambda i, m: i < 10 c = lambda i, m: i < 10
b = lambda i, m: [i+1, tf.concat([m, m], axis=0)] b = lambda i, m: [i+1, tf.concat([m, m], axis=0)]
tf.while_loop( tf.while_loop(
c, b, loop_vars=[i0, m0], c, b, loop_vars=[i0, m0],
shape_invariants=[i0.get_shape(), tf.TensorShape([None, 2])]) shape_invariants=[i0.get_shape(), tf.TensorShape([None, 2])])
``` ```
""" """
with ops.name_scope(name, "while", loop_vars) as name: with ops.name_scope(name, "while", loop_vars) as name: