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

Function map_fn

tensorflow/python/ops/ragged/ragged_map_ops.py:38–331  ·  view source on GitHub ↗

map on the list of tensors unpacked from `elems` on dimension 0. The simplest version of `map_fn` repeatedly applies the callable `fn` to a sequence of elements from first to last. The elements are made of the tensors unpacked from `elems`. `dtype` is the data type of the return value of `f

(fn,
           elems,
           dtype=None,
           parallel_iterations=None,
           back_prop=True,
           swap_memory=False,
           infer_shape=True,
           name=None)

Source from the content-addressed store, hash-verified

36
37
38def map_fn(fn,
39 elems,
40 dtype=None,
41 parallel_iterations=None,
42 back_prop=True,
43 swap_memory=False,
44 infer_shape=True,
45 name=None):
46 """map on the list of tensors unpacked from `elems` on dimension 0.
47
48 The simplest version of `map_fn` repeatedly applies the callable `fn` to a
49 sequence of elements from first to last. The elements are made of the
50 tensors unpacked from `elems`. `dtype` is the data type of the return
51 value of `fn`. Users must provide `dtype` if it is different from
52 the data type of `elems`.
53
54 Suppose that `elems` is unpacked into `values`, a list of tensors. The shape
55 of the result tensor is `[values.shape[0]] + fn(values[0]).shape`.
56
57 This method also allows multi-arity `elems` and output of `fn`. If `elems`
58 is a (possibly nested) list or tuple of tensors, then each of these tensors
59 must have a matching first (unpack) dimension. The signature of `fn` may
60 match the structure of `elems`. That is, if `elems` is
61 `(t1, [t2, t3, [t4, t5]])`, then an appropriate signature for `fn` is:
62 `fn = lambda (t1, [t2, t3, [t4, t5]]):`.
63
64 Furthermore, `fn` may emit a different structure than its input. For example,
65 `fn` may look like: `fn = lambda t1: return (t1 + 1, t1 - 1)`. In this case,
66 the `dtype` parameter is not optional: `dtype` must be a type or (possibly
67 nested) tuple of types matching the output of `fn`.
68
69 To apply a functional operation to the nonzero elements of a SparseTensor
70 one of the following methods is recommended. First, if the function is
71 expressible as TensorFlow ops, use
72
73 ```python
74 result = SparseTensor(input.indices, fn(input.values), input.dense_shape)
75 ```
76
77 If, however, the function is not expressible as a TensorFlow op, then use
78
79 ```python
80 result = SparseTensor(
81 input.indices, map_fn(fn, input.values), input.dense_shape)
82 ```
83
84 instead.
85
86 When executing eagerly, map_fn does not execute in parallel even if
87 `parallel_iterations` is set to a value > 1. You can still get the
88 performance benefits of running a function in parallel by using the
89 `tf.contrib.eager.defun` decorator,
90
91 ```python
92 # Assume the function being used in map_fn is fn.
93 # To ensure map_fn calls fn in parallel, use the defun decorator.
94 @tf.contrib.eager.defun
95 def func(tensor):

Callers

nothing calls this directly

Calls 14

_maybe_decompose_dtypeFunction · 0.85
_stack_or_concatFunction · 0.85
_maybe_recompose_tensorFunction · 0.85
executing_eagerlyMethod · 0.80
set_caching_deviceMethod · 0.80
nrowsMethod · 0.80
TensorArrayMethod · 0.80
input_packFunction · 0.70
flattenMethod · 0.45
name_scopeMethod · 0.45
shapeMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected