Skip to content

Commit a59e6e0

Browse files
yuanbyutensorflower-gardener
authored andcommitted
Add a scan operator, similar to Theano's scan.
Change: 117756292
1 parent 59e04a0 commit a59e6e0

File tree

16 files changed

+610
-185
lines changed

16 files changed

+610
-185
lines changed

tensorflow/g3doc/api_docs/python/array_ops.md

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -561,43 +561,62 @@ dimension. For example, tiling `[a b c d]` by `[2]` produces
561561

562562
- - -
563563

564-
### `tf.pad(input, paddings, name=None)` {#pad}
564+
### `tf.pad(tensor, paddings, mode='CONSTANT', name=None)` {#pad}
565565

566-
Pads a tensor with zeros.
566+
Pads a tensor.
567567

568-
This operation pads a `input` with zeros according to the `paddings` you
569-
specify. `paddings` is an integer tensor with shape `[Dn, 2]`, where n is the
570-
rank of `input`. For each dimension D of `input`, `paddings[D, 0]` indicates
571-
how many zeros to add before the contents of `input` in that dimension, and
572-
`paddings[D, 1]` indicates how many zeros to add after the contents of `input`
573-
in that dimension.
568+
This operation pads a `tensor` according to the `paddings` you specify.
569+
`paddings` is an integer tensor with shape `[n, 2]`, where n is the rank of
570+
`tensor`. For each dimension D of `input`, `paddings[D, 0]` indicates how
571+
many values to add before the contents of `tensor` in that dimension, and
572+
`paddings[D, 1]` indicates how many values to add after the contents of
573+
`tensor` in that dimension. If `mode` is "REFLECT" then both `paddings[D, 0]`
574+
and `paddings[D, 1]` must be no greater than `tensor.dim_size(D) - 1`. If
575+
`mode` is "SYMMETRIC" then both `paddings[D, 0]` and `paddings[D, 1]` must be
576+
no greater than `tensor.dim_size(D)`.
574577

575578
The padded size of each dimension D of the output is:
576579

577-
`paddings(D, 0) + input.dim_size(D) + paddings(D, 1)`
580+
`paddings[D, 0] + tensor.dim_size(D) + paddings[D, 1]`
578581

579582
For example:
580583

581-
```prettyprint
582-
# 't' is [[1, 1], [2, 2]]
583-
# 'paddings' is [[1, 1], [2, 2]]
584-
# rank of 't' is 2
585-
pad(t, paddings) ==> [[0, 0, 0, 0, 0, 0]
586-
[0, 0, 1, 1, 0, 0]
587-
[0, 0, 2, 2, 0, 0]
588-
[0, 0, 0, 0, 0, 0]]
584+
```python
585+
# 't' is [[1, 2, 3], [4, 5, 6]].
586+
# 'paddings' is [[1, 1,], [2, 2]].
587+
# rank of 't' is 2.
588+
pad(t, paddings, "CONSTANT") ==> [[0, 0, 0, 0, 0, 0, 0],
589+
[0, 0, 1, 2, 3, 0, 0],
590+
[0, 0, 4, 5, 6, 0, 0],
591+
[0, 0, 0, 0, 0, 0, 0]]
592+
593+
pad(t, paddings, "REFLECT") ==> [[6, 5, 4, 5, 6, 5, 4],
594+
[3, 2, 1, 2, 3, 2, 1],
595+
[6, 5, 4, 5, 6, 5, 4],
596+
[3, 2, 1, 2, 3, 2, 1]]
597+
598+
pad(t, paddings, "SYMMETRIC") ==> [[2, 1, 1, 2, 3, 3, 2],
599+
[2, 1, 1, 2, 3, 3, 2],
600+
[5, 4, 4, 5, 6, 6, 5],
601+
[5, 4, 4, 5, 6, 6, 5]]
589602
```
590603

591604
##### Args:
592605

593606

594-
* <b>`input`</b>: A `Tensor`.
607+
* <b>`tensor`</b>: A `Tensor`.
595608
* <b>`paddings`</b>: A `Tensor` of type `int32`.
609+
* <b>`mode`</b>: One of "CONSTANT", "REFLECT", or "SYMMETRIC".
596610
* <b>`name`</b>: A name for the operation (optional).
597611

598612
##### Returns:
599613

600-
A `Tensor`. Has the same type as `input`.
614+
A `Tensor`. Has the same type as `tensor`.
615+
616+
##### Raises:
617+
618+
619+
* <b>`ValueError`</b>: When mode is not one of "CONSTANT", "REFLECT", or "SYMMETRIC".
601620

602621

603622
- - -
@@ -1277,6 +1296,7 @@ where `(i1,...,iK)` is the ith `True` entry of `mask` (row-major order).
12771296

12781297

12791298
* <b>`Examples`</b>:
1299+
12801300
```python
12811301
# 2-D example
12821302
a = [[1, 2], [3, 4], [5, 6]]
@@ -1420,8 +1440,8 @@ dimension be equal to sizeof(`type`)/sizeof(`T`). The shape then goes from
14201440
##### Args:
14211441

14221442

1423-
* <b>`input`</b>: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int64`, `int32`, `uint8`, `uint16`, `int16`, `int8`, `complex64`, `qint8`, `quint8`, `qint32`.
1424-
* <b>`type`</b>: A `tf.DType` from: `tf.float32, tf.float64, tf.int64, tf.int32, tf.uint8, tf.uint16, tf.int16, tf.int8, tf.complex64, tf.qint8, tf.quint8, tf.qint32`.
1443+
* <b>`input`</b>: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int64`, `int32`, `uint8`, `uint16`, `int16`, `int8`, `complex64`, `complex128`, `qint8`, `quint8`, `qint32`.
1444+
* <b>`type`</b>: A `tf.DType` from: `tf.float32, tf.float64, tf.int64, tf.int32, tf.uint8, tf.uint16, tf.int16, tf.int8, tf.complex64, tf.complex128, tf.qint8, tf.quint8, tf.qint32`.
14251445
* <b>`name`</b>: A name for the operation (optional).
14261446

14271447
##### Returns:

tensorflow/g3doc/api_docs/python/client.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ the session constructor.
9393

9494
- - -
9595

96-
#### `tf.Session.run(fetches, feed_dict=None)` {#Session.run}
96+
#### `tf.Session.run(fetches, feed_dict=None, options=None, run_outputs=None)` {#Session.run}
9797

9898
Runs the operations and evaluates the tensors in `fetches`.
9999

@@ -133,13 +133,24 @@ one of the following types:
133133
the value should be a
134134
[`SparseTensorValue`](../../api_docs/python/sparse_ops.md#SparseTensorValue).
135135

136+
The optional `options` argument expects a [`RunOptions`] proto. The options
137+
allow controlling the behavior of this particular step (e.g. turning tracing
138+
on).
139+
140+
The optional `run_outputs` argument expects a [`RunOutputs`] proto. When
141+
appropriate, the non-Tensor output of this step will be collected there. For
142+
example, when users turn on tracing in `options`, the profiled info will be
143+
collected into this argument and passed back.
144+
136145
##### Args:
137146

138147

139148
* <b>`fetches`</b>: A single graph element, or a list of graph elements
140149
(described above).
141150
* <b>`feed_dict`</b>: A dictionary that maps graph elements to values
142151
(described above).
152+
* <b>`options`</b>: A [`RunOptions`] protocol buffer
153+
* <b>`run_outputs`</b>: A [`RunOutputs`] protocol buffer
143154

144155
##### Returns:
145156

0 commit comments

Comments
 (0)