diff options
-rw-r--r-- | tensorflow/g3doc/api_docs/python/index.md | 1 | ||||
-rw-r--r-- | tensorflow/g3doc/api_docs/python/io_ops.md | 50 |
2 files changed, 51 insertions, 0 deletions
diff --git a/tensorflow/g3doc/api_docs/python/index.md b/tensorflow/g3doc/api_docs/python/index.md index dcb79623c7..97726dc56a 100644 --- a/tensorflow/g3doc/api_docs/python/index.md +++ b/tensorflow/g3doc/api_docs/python/index.md @@ -376,6 +376,7 @@ * [`shuffle_batch_join`](../../api_docs/python/io_ops.md#shuffle_batch_join) * [`size`](../../api_docs/python/io_ops.md#size) * [`slice_input_producer`](../../api_docs/python/io_ops.md#slice_input_producer) + * [`sparse_placeholder`](../../api_docs/python/io_ops.md#sparse_placeholder) * [`string_input_producer`](../../api_docs/python/io_ops.md#string_input_producer) * [`TextLineReader`](../../api_docs/python/io_ops.md#TextLineReader) * [`TFRecordReader`](../../api_docs/python/io_ops.md#TFRecordReader) diff --git a/tensorflow/g3doc/api_docs/python/io_ops.md b/tensorflow/g3doc/api_docs/python/io_ops.md index 5eab6fece8..8d84aa4eba 100644 --- a/tensorflow/g3doc/api_docs/python/io_ops.md +++ b/tensorflow/g3doc/api_docs/python/io_ops.md @@ -71,6 +71,56 @@ A placeholder op that passes though `input` when its output is not fed. +For feeding `SparseTensor`s which are composite type, +there is a convenience function: + +- - - + +### `tf.sparse_placeholder(dtype, shape=None, name=None)` {#sparse_placeholder} + +Inserts a placeholder for a sparse tensor that will be always fed. + +**Important**: This sparse tensor will produce an error if evaluated. +Its value must be fed using the `feed_dict` optional argument to +`Session.run()`, `Tensor.eval()`, or `Operation.run()`. + +For example: + +```python +x = tf.sparse_placeholder(tf.float32) +y = tf.sparse_reduce_sum(x) + +with tf.Session() as sess: + print(sess.run(y)) # ERROR: will fail because x was not fed. + + indices = np.array([[3, 2, 0], [4, 5, 1]], dtype=np.int64) + values = np.array([1.0, 2.0], dtype=np.float32) + shape = np.array([7, 9, 2], dtype=np.int64) + print(sess.run(y, feed_dict={ + x: tf.SparseTensorValue(indices, values, shape)})) # Will succeed. + print(sess.run(y, feed_dict={ + x: (indices, values, shape)})) # Will succeed. + + sp = tf.SparseTensor(indices=indices, values=values, shape=shape) + sp_value = sp.eval(session) + print(sess.run(y, feed_dict={x: sp_value})) # Will succeed. +``` + +##### Args: + + +* <b>`dtype`</b>: The type of `values` elements in the tensor to be fed. +* <b>`shape`</b>: The shape of the tensor to be fed (optional). If the shape is not + specified, you can feed a sparse tensor of any shape. +* <b>`name`</b>: A name for prefixing the operations (optional). + +##### Returns: + + A `SparseTensor` that may be used as a handle for feeding a value, but not + evaluated directly. + + + ## Readers TensorFlow provides a set of Reader classes for reading data formats. |