MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / scan

Function scan

tensorflow/python/ops/functional_ops.py:281–529  ·  view source on GitHub ↗

scan on the list of tensors unpacked from `elems` on dimension 0. The simplest version of `scan` repeatedly applies the callable `fn` to a sequence of elements from first to last. The elements are made of the tensors unpacked from `elems` on dimension 0. The callable fn takes two tensors as

(fn,
         elems,
         initializer=None,
         parallel_iterations=10,
         back_prop=True,
         swap_memory=False,
         infer_shape=True,
         reverse=False,
         name=None)

Source from the content-addressed store, hash-verified

279
280@tf_export("scan")
281def scan(fn,
282 elems,
283 initializer=None,
284 parallel_iterations=10,
285 back_prop=True,
286 swap_memory=False,
287 infer_shape=True,
288 reverse=False,
289 name=None):
290 """scan on the list of tensors unpacked from `elems` on dimension 0.
291
292 The simplest version of `scan` repeatedly applies the callable `fn` to a
293 sequence of elements from first to last. The elements are made of the tensors
294 unpacked from `elems` on dimension 0. The callable fn takes two tensors as
295 arguments. The first argument is the accumulated value computed from the
296 preceding invocation of fn, and the second is the value at the current
297 position of `elems`. If `initializer` is None, `elems` must contain at least
298 one element, and its first element is used as the initializer.
299
300 Suppose that `elems` is unpacked into `values`, a list of tensors. The shape
301 of the result tensor is `[len(values)] + fn(initializer, values[0]).shape`.
302 If reverse=True, it's fn(initializer, values[-1]).shape.
303
304 This method also allows multi-arity `elems` and accumulator. If `elems`
305 is a (possibly nested) list or tuple of tensors, then each of these tensors
306 must have a matching first (unpack) dimension. The second argument of
307 `fn` must match the structure of `elems`.
308
309 If no `initializer` is provided, the output structure and dtypes of `fn`
310 are assumed to be the same as its input; and in this case, the first
311 argument of `fn` must match the structure of `elems`.
312
313 If an `initializer` is provided, then the output of `fn` must have the same
314 structure as `initializer`; and the first argument of `fn` must match
315 this structure.
316
317 For example, if `elems` is `(t1, [t2, t3])` and `initializer` is
318 `[i1, i2]` then an appropriate signature for `fn` in `python2` is:
319 `fn = lambda (acc_p1, acc_p2), (t1, [t2, t3]):` and `fn` must return a list,
320 `[acc_n1, acc_n2]`. An alternative correct signature for `fn`, and the
321 one that works in `python3`, is:
322 `fn = lambda a, t:`, where `a` and `t` correspond to the input tuples.
323
324 Args:
325 fn: The callable to be performed. It accepts two arguments. The first will
326 have the same structure as `initializer` if one is provided, otherwise it
327 will have the same structure as `elems`. The second will have the same
328 (possibly nested) structure as `elems`. Its output must have the same
329 structure as `initializer` if one is provided, otherwise it must have the
330 same structure as `elems`.
331 elems: A tensor or (possibly nested) sequence of tensors, each of which will
332 be unpacked along their first dimension. The nested sequence of the
333 resulting slices will be the first argument to `fn`.
334 initializer: (optional) A tensor or (possibly nested) sequence of tensors,
335 initial value for the accumulator, and the expected output type of `fn`.
336 parallel_iterations: (optional) The number of iterations allowed to run in
337 parallel.
338 back_prop: (optional) True enables support for back propagation.

Callers

nothing calls this directly

Calls 15

merge_withMethod · 0.95
executing_eagerlyMethod · 0.80
set_caching_deviceMethod · 0.80
TensorArrayMethod · 0.80
with_rank_at_leastMethod · 0.80
output_packFunction · 0.70
flattenMethod · 0.45
name_scopeMethod · 0.45
shapeMethod · 0.45
unstackMethod · 0.45
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected