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

Function wrapped_body

tensorflow/python/ops/while_v2.py:155–188  ·  view source on GitHub ↗

Loop body augmented with counter update. Args: loop_counter: Loop counter which needs to be incremented in the body. maximum_iterations_arg: Maximum iterations of the loop. *args: List of args Returns: A list of tensors the same length as args.

(loop_counter, maximum_iterations_arg, *args)

Source from the content-addressed store, hash-verified

153 add_control_dependencies=add_control_dependencies)
154
155 def wrapped_body(loop_counter, maximum_iterations_arg, *args):
156 """Loop body augmented with counter update.
157
158 Args:
159 loop_counter: Loop counter which needs to be incremented in the body.
160 maximum_iterations_arg: Maximum iterations of the loop.
161 *args: List of args
162
163 Returns:
164 A list of tensors the same length as args.
165 """
166 # Capture the tensors already captured in cond_graph so that they appear
167 # in the same order in body_graph.external_captures.
168 for t in cond_graph.external_captures:
169 ops.get_default_graph().capture(t)
170
171 # Convert the flow variables in `args` to TensorArrays. `args` should
172 # already have the same structure as `orig_loop_vars` but currently there
173 # is no nest.zip so we call `_pack_sequence_as` which flattens both
174 # `orig_loop_vars` and `args`, converts flows in `args` to TensorArrays
175 # and packs it into the structure of `orig_loop_vars`.
176 outputs = body(*_pack_sequence_as(orig_loop_vars, args))
177 if not nest.is_sequence_or_composite(outputs):
178 outputs = [outputs]
179 # Compare the structure of input and output of body converting the
180 # top-level tuples to list to be compatible with legacy while_loop.
181 nest.assert_same_structure(list(outputs), list(orig_loop_vars),
182 expand_composites=True)
183
184 outputs = _tensor_array_to_flow(outputs)
185
186 # TODO(srbs): Update lowering code to create _Enter nodes with
187 # is_constant=True for inputs that are directly passed to outputs.
188 return [loop_counter + 1, maximum_iterations_arg] + list(outputs)
189
190 body_graph = func_graph_module.func_graph_from_py_func(
191 body_name,

Callers

nothing calls this directly

Calls 4

_pack_sequence_asFunction · 0.85
_tensor_array_to_flowFunction · 0.85
bodyFunction · 0.70
captureMethod · 0.45

Tested by

no test coverage detected