Add code-fences to doctest blocks.

Most >>> blocks already have ``` fences. Doctest runs them with or without the fences.
This change adds the ``` anywhere they're missing when api docs are generated from the docstrings. This will ensure that they look right when viewed as markdown.

+ fix docstring for `constant_initializer`: you can't have blank lines inside a doctest block. This prevents the rendering from getting corrupted.

PiperOrigin-RevId: 267009925
This commit is contained in:
Mark Daoust 2019-09-03 14:12:54 -07:00 committed by TensorFlower Gardener
parent fe6529d095
commit 76ca9f1060
2 changed files with 60 additions and 77 deletions

View File

@ -173,50 +173,42 @@ class Constant(Initializer):
of the `value` list, even reshaped, as shown in the two commented lines of the `value` list, even reshaped, as shown in the two commented lines
below the `value` list initialization. below the `value` list initialization.
```python ```
>>> import numpy as np
>>> import tensorflow as tf
>>> value = [0, 1, 2, 3, 4, 5, 6, 7] >>> value = [0, 1, 2, 3, 4, 5, 6, 7]
>>> # value = np.array(value) >>> # value = np.array(value)
>>> # value = value.reshape([2, 4]) >>> # value = value.reshape([2, 4])
>>> init = tf.compat.v1.constant_initializer(value) >>> init = tf.compat.v1.constant_initializer(value)
>>>
>>> print('fitting shape:') >>> # fitting shape
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[2, 4], initializer=init) ... x = tf.compat.v1.get_variable('x', shape=[2, 4], initializer=init)
>>> x.initializer.run() ... x.initializer.run()
>>> print(x.eval()) ... print(x.eval())
fitting shape:
[[0. 1. 2. 3.] [[0. 1. 2. 3.]
[4. 5. 6. 7.]] [4. 5. 6. 7.]]
>>>
>>> print('larger shape:') >>> # Larger shape
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[3, 4], initializer=init) ... x = tf.compat.v1.get_variable('x', shape=[3, 4], initializer=init)
>>> x.initializer.run() ... x.initializer.run()
>>> print(x.eval()) ... print(x.eval())
larger shape:
[[ 0. 1. 2. 3.] [[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.] [ 4. 5. 6. 7.]
[ 7. 7. 7. 7.]] [ 7. 7. 7. 7.]]
>>>
>>> print('smaller shape:') >>> # Smaller shape
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[2, 3], initializer=init) ... x = tf.compat.v1.get_variable('x', shape=[2, 3], initializer=init)
ValueError: Too many elements provided. Needed at most 6, but received 8 ValueError: Too many elements provided. Needed at most 6, but received 8
>>>
>>> print('shape verification:') >>> # Shape verification
>>> init_verify = tf.compat.v1.constant_initializer(value, >>> init_verify = tf.compat.v1.constant_initializer(value,
verify_shape=True) verify_shape=True)
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[3, 4], ... x = tf.compat.v1.get_variable('x', shape=[3, 4],
initializer=init_verify) ... initializer=init_verify)
TypeError: Expected Tensor's shape: (3, 4), got (8,). TypeError: Expected Tensor's shape: (3, 4), got (8,).
>>>
``` ```
""" """

View File

@ -150,40 +150,31 @@ class Constant(Initializer):
below the `value` list initialization. below the `value` list initialization.
```python ```python
>>> import numpy as np
>>> import tensorflow as tf
>>> value = [0, 1, 2, 3, 4, 5, 6, 7] >>> value = [0, 1, 2, 3, 4, 5, 6, 7]
>>> # value = np.array(value) >>> # value = np.array(value)
>>> # value = value.reshape([2, 4]) >>> # value = value.reshape([2, 4])
>>> init = tf.compat.v1.constant_initializer(value) >>> init = tf.compat.v1.constant_initializer(value)
>>>
>>> print('fitting shape:') >>> # Fitting shape
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[2, 4], initializer=init) ... x = tf.compat.v1.get_variable('x', shape=[2, 4], initializer=init)
>>> x.initializer.run() ... x.initializer.run()
>>> print(x.eval()) ... print(x.eval())
fitting shape:
[[0. 1. 2. 3.] [[0. 1. 2. 3.]
[4. 5. 6. 7.]] [4. 5. 6. 7.]]
>>> # Larger shape
>>> print('larger shape:')
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[3, 4], initializer=init) ... x = tf.compat.v1.get_variable('x', shape=[3, 4], initializer=init)
>>> x.initializer.run() ... x.initializer.run()
>>> print(x.eval()) ... print(x.eval())
larger shape:
[[ 0. 1. 2. 3.] [[ 0. 1. 2. 3.]
[ 4. 5. 6. 7.] [ 4. 5. 6. 7.]
[ 7. 7. 7. 7.]] [ 7. 7. 7. 7.]]
>>> # Smaller shape
>>> print('smaller shape:')
>>> with tf.compat.v1.Session(): >>> with tf.compat.v1.Session():
>>> x = tf.compat.v1.get_variable('x', shape=[2, 3], initializer=init) ... x = tf.compat.v1.get_variable('x', shape=[2, 3], initializer=init)
ValueError: Too many elements provided. Needed at most 6, but received 8 ValueError: Too many elements provided. Needed at most 6, but received 8
``` ```
""" """