Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_control_flow_ops.py: 15%
453 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1"""Python wrappers around TensorFlow ops.
3This file is MACHINE GENERATED! Do not edit.
4"""
6import collections
8from tensorflow.python import pywrap_tfe as pywrap_tfe
9from tensorflow.python.eager import context as _context
10from tensorflow.python.eager import core as _core
11from tensorflow.python.eager import execute as _execute
12from tensorflow.python.framework import dtypes as _dtypes
13from tensorflow.security.fuzzing.py import annotation_types as _atypes
15from tensorflow.python.framework import op_def_registry as _op_def_registry
16from tensorflow.python.framework import ops as _ops
17from tensorflow.python.framework import op_def_library as _op_def_library
18from tensorflow.python.util.deprecation import deprecated_endpoints
19from tensorflow.python.util import dispatch as _dispatch
20from tensorflow.python.util.tf_export import tf_export
22from typing import TypeVar
24def abort(error_msg="", exit_without_error=False, name=None):
25 r"""Raise a exception to abort the process when called.
27 If exit_without_error is true, the process will exit normally,
28 otherwise it will exit with a SIGABORT signal.
30 Returns nothing but an exception.
32 Args:
33 error_msg: An optional `string`. Defaults to `""`.
34 A string which is the message associated with the exception.
35 exit_without_error: An optional `bool`. Defaults to `False`.
36 name: A name for the operation (optional).
38 Returns:
39 The created Operation.
40 """
41 _ctx = _context._context or _context.context()
42 tld = _ctx._thread_local_data
43 if tld.is_eager:
44 try:
45 _result = pywrap_tfe.TFE_Py_FastPathExecute(
46 _ctx, "Abort", name, "error_msg", error_msg, "exit_without_error",
47 exit_without_error)
48 return _result
49 except _core._NotOkStatusException as e:
50 _ops.raise_from_not_ok_status(e, name)
51 except _core._FallbackException:
52 pass
53 try:
54 return abort_eager_fallback(
55 error_msg=error_msg, exit_without_error=exit_without_error,
56 name=name, ctx=_ctx)
57 except _core._SymbolicException:
58 pass # Add nodes to the TensorFlow graph.
59 # Add nodes to the TensorFlow graph.
60 if error_msg is None:
61 error_msg = ""
62 error_msg = _execute.make_str(error_msg, "error_msg")
63 if exit_without_error is None:
64 exit_without_error = False
65 exit_without_error = _execute.make_bool(exit_without_error, "exit_without_error")
66 _, _, _op, _outputs = _op_def_library._apply_op_helper(
67 "Abort", error_msg=error_msg, exit_without_error=exit_without_error,
68 name=name)
69 return _op
70Abort = tf_export("raw_ops.Abort")(_ops.to_raw_op(abort))
73def abort_eager_fallback(error_msg, exit_without_error, name, ctx):
74 if error_msg is None:
75 error_msg = ""
76 error_msg = _execute.make_str(error_msg, "error_msg")
77 if exit_without_error is None:
78 exit_without_error = False
79 exit_without_error = _execute.make_bool(exit_without_error, "exit_without_error")
80 _inputs_flat = []
81 _attrs = ("error_msg", error_msg, "exit_without_error", exit_without_error)
82 _result = _execute.execute(b"Abort", 0, inputs=_inputs_flat, attrs=_attrs,
83 ctx=ctx, name=name)
84 _result = None
85 return _result
88def control_trigger(name=None):
89 r"""Does nothing. Serves as a control trigger for scheduling.
91 Only useful as a placeholder for control edges.
93 Args:
94 name: A name for the operation (optional).
96 Returns:
97 The created Operation.
98 """
99 _ctx = _context._context or _context.context()
100 tld = _ctx._thread_local_data
101 if tld.is_eager:
102 try:
103 _result = pywrap_tfe.TFE_Py_FastPathExecute(
104 _ctx, "ControlTrigger", name)
105 return _result
106 except _core._NotOkStatusException as e:
107 _ops.raise_from_not_ok_status(e, name)
108 except _core._FallbackException:
109 pass
110 try:
111 return control_trigger_eager_fallback(
112 name=name, ctx=_ctx)
113 except _core._SymbolicException:
114 pass # Add nodes to the TensorFlow graph.
115 # Add nodes to the TensorFlow graph.
116 _, _, _op, _outputs = _op_def_library._apply_op_helper(
117 "ControlTrigger", name=name)
118 return _op
119ControlTrigger = tf_export("raw_ops.ControlTrigger")(_ops.to_raw_op(control_trigger))
122def control_trigger_eager_fallback(name, ctx):
123 _inputs_flat = []
124 _attrs = None
125 _result = _execute.execute(b"ControlTrigger", 0, inputs=_inputs_flat,
126 attrs=_attrs, ctx=ctx, name=name)
127 _result = None
128 return _result
131def enter(data, frame_name, is_constant=False, parallel_iterations=10, name=None):
132 r"""Creates or finds a child frame, and makes `data` available to the child frame.
134 This op is used together with `Exit` to create loops in the graph.
135 The unique `frame_name` is used by the `Executor` to identify frames. If
136 `is_constant` is true, `output` is a constant in the child frame; otherwise
137 it may be changed in the child frame. At most `parallel_iterations` iterations
138 are run in parallel in the child frame.
140 Args:
141 data: A `Tensor`. The tensor to be made available to the child frame.
142 frame_name: A `string`. The name of the child frame.
143 is_constant: An optional `bool`. Defaults to `False`.
144 If true, the output is constant within the child frame.
145 parallel_iterations: An optional `int`. Defaults to `10`.
146 The number of iterations allowed to run in parallel.
147 name: A name for the operation (optional).
149 Returns:
150 A `Tensor`. Has the same type as `data`.
151 """
152 _ctx = _context._context or _context.context()
153 tld = _ctx._thread_local_data
154 if tld.is_eager:
155 try:
156 _result = pywrap_tfe.TFE_Py_FastPathExecute(
157 _ctx, "Enter", name, data, "frame_name", frame_name, "is_constant",
158 is_constant, "parallel_iterations", parallel_iterations)
159 return _result
160 except _core._NotOkStatusException as e:
161 _ops.raise_from_not_ok_status(e, name)
162 except _core._FallbackException:
163 pass
164 try:
165 return enter_eager_fallback(
166 data, frame_name=frame_name, is_constant=is_constant,
167 parallel_iterations=parallel_iterations, name=name, ctx=_ctx)
168 except _core._SymbolicException:
169 pass # Add nodes to the TensorFlow graph.
170 # Add nodes to the TensorFlow graph.
171 frame_name = _execute.make_str(frame_name, "frame_name")
172 if is_constant is None:
173 is_constant = False
174 is_constant = _execute.make_bool(is_constant, "is_constant")
175 if parallel_iterations is None:
176 parallel_iterations = 10
177 parallel_iterations = _execute.make_int(parallel_iterations, "parallel_iterations")
178 _, _, _op, _outputs = _op_def_library._apply_op_helper(
179 "Enter", data=data, frame_name=frame_name, is_constant=is_constant,
180 parallel_iterations=parallel_iterations, name=name)
181 _result = _outputs[:]
182 if _execute.must_record_gradient():
183 _attrs = ("T", _op._get_attr_type("T"), "frame_name",
184 _op.get_attr("frame_name"), "is_constant",
185 _op._get_attr_bool("is_constant"), "parallel_iterations",
186 _op._get_attr_int("parallel_iterations"))
187 _inputs_flat = _op.inputs
188 _execute.record_gradient(
189 "Enter", _inputs_flat, _attrs, _result)
190 _result, = _result
191 return _result
193Enter = tf_export("raw_ops.Enter")(_ops.to_raw_op(enter))
196def enter_eager_fallback(data, frame_name, is_constant, parallel_iterations, name, ctx):
197 frame_name = _execute.make_str(frame_name, "frame_name")
198 if is_constant is None:
199 is_constant = False
200 is_constant = _execute.make_bool(is_constant, "is_constant")
201 if parallel_iterations is None:
202 parallel_iterations = 10
203 parallel_iterations = _execute.make_int(parallel_iterations, "parallel_iterations")
204 _attr_T, (data,) = _execute.args_to_matching_eager([data], ctx, [])
205 _inputs_flat = [data]
206 _attrs = ("T", _attr_T, "frame_name", frame_name, "is_constant",
207 is_constant, "parallel_iterations", parallel_iterations)
208 _result = _execute.execute(b"Enter", 1, inputs=_inputs_flat, attrs=_attrs,
209 ctx=ctx, name=name)
210 if _execute.must_record_gradient():
211 _execute.record_gradient(
212 "Enter", _inputs_flat, _attrs, _result)
213 _result, = _result
214 return _result
217def _exit(data, name=None):
218 r"""Exits the current frame to its parent frame.
220 Exit makes its input `data` available to the parent frame.
222 Args:
223 data: A `Tensor`. The tensor to be made available to the parent frame.
224 name: A name for the operation (optional).
226 Returns:
227 A `Tensor`. Has the same type as `data`.
228 """
229 _ctx = _context._context or _context.context()
230 tld = _ctx._thread_local_data
231 if tld.is_eager:
232 try:
233 _result = pywrap_tfe.TFE_Py_FastPathExecute(
234 _ctx, "Exit", name, data)
235 return _result
236 except _core._NotOkStatusException as e:
237 _ops.raise_from_not_ok_status(e, name)
238 except _core._FallbackException:
239 pass
240 try:
241 return _exit_eager_fallback(
242 data, name=name, ctx=_ctx)
243 except _core._SymbolicException:
244 pass # Add nodes to the TensorFlow graph.
245 # Add nodes to the TensorFlow graph.
246 _, _, _op, _outputs = _op_def_library._apply_op_helper(
247 "Exit", data=data, name=name)
248 _result = _outputs[:]
249 if _execute.must_record_gradient():
250 _attrs = ("T", _op._get_attr_type("T"))
251 _inputs_flat = _op.inputs
252 _execute.record_gradient(
253 "Exit", _inputs_flat, _attrs, _result)
254 _result, = _result
255 return _result
257Exit = tf_export("raw_ops.Exit")(_ops.to_raw_op(_exit))
260def _exit_eager_fallback(data, name, ctx):
261 _attr_T, (data,) = _execute.args_to_matching_eager([data], ctx, [])
262 _inputs_flat = [data]
263 _attrs = ("T", _attr_T)
264 _result = _execute.execute(b"Exit", 1, inputs=_inputs_flat, attrs=_attrs,
265 ctx=ctx, name=name)
266 if _execute.must_record_gradient():
267 _execute.record_gradient(
268 "Exit", _inputs_flat, _attrs, _result)
269 _result, = _result
270 return _result
273def loop_cond(input, name=None):
274 r"""Forwards the input to the output.
276 This operator represents the loop termination condition used by the
277 "pivot" switches of a loop.
279 Args:
280 input: A `Tensor` of type `bool`.
281 A boolean scalar, representing the branch predicate of the Switch op.
282 name: A name for the operation (optional).
284 Returns:
285 A `Tensor` of type `bool`.
286 """
287 _ctx = _context._context or _context.context()
288 tld = _ctx._thread_local_data
289 if tld.is_eager:
290 try:
291 _result = pywrap_tfe.TFE_Py_FastPathExecute(
292 _ctx, "LoopCond", name, input)
293 return _result
294 except _core._NotOkStatusException as e:
295 _ops.raise_from_not_ok_status(e, name)
296 except _core._FallbackException:
297 pass
298 try:
299 return loop_cond_eager_fallback(
300 input, name=name, ctx=_ctx)
301 except _core._SymbolicException:
302 pass # Add nodes to the TensorFlow graph.
303 # Add nodes to the TensorFlow graph.
304 _, _, _op, _outputs = _op_def_library._apply_op_helper(
305 "LoopCond", input=input, name=name)
306 _result = _outputs[:]
307 if _execute.must_record_gradient():
308 _attrs = ()
309 _inputs_flat = _op.inputs
310 _execute.record_gradient(
311 "LoopCond", _inputs_flat, _attrs, _result)
312 _result, = _result
313 return _result
315LoopCond = tf_export("raw_ops.LoopCond")(_ops.to_raw_op(loop_cond))
318def loop_cond_eager_fallback(input, name, ctx):
319 input = _ops.convert_to_tensor(input, _dtypes.bool)
320 _inputs_flat = [input]
321 _attrs = None
322 _result = _execute.execute(b"LoopCond", 1, inputs=_inputs_flat,
323 attrs=_attrs, ctx=ctx, name=name)
324 if _execute.must_record_gradient():
325 _execute.record_gradient(
326 "LoopCond", _inputs_flat, _attrs, _result)
327 _result, = _result
328 return _result
330_MergeOutput = collections.namedtuple(
331 "Merge",
332 ["output", "value_index"])
335def merge(inputs, name=None):
336 r"""Forwards the value of an available tensor from `inputs` to `output`.
338 `Merge` waits for at least one of the tensors in `inputs` to become available.
339 It is usually combined with `Switch` to implement branching.
341 `Merge` forwards the first tensor to become available to `output`, and sets
342 `value_index` to its index in `inputs`.
344 Args:
345 inputs: A list of at least 1 `Tensor` objects with the same type.
346 The input tensors, exactly one of which will become available.
347 name: A name for the operation (optional).
349 Returns:
350 A tuple of `Tensor` objects (output, value_index).
352 output: A `Tensor`. Has the same type as `inputs`.
353 value_index: A `Tensor` of type `int32`.
354 """
355 _ctx = _context._context or _context.context()
356 tld = _ctx._thread_local_data
357 if tld.is_eager:
358 try:
359 _result = pywrap_tfe.TFE_Py_FastPathExecute(
360 _ctx, "Merge", name, inputs)
361 _result = _MergeOutput._make(_result)
362 return _result
363 except _core._NotOkStatusException as e:
364 _ops.raise_from_not_ok_status(e, name)
365 except _core._FallbackException:
366 pass
367 try:
368 return merge_eager_fallback(
369 inputs, name=name, ctx=_ctx)
370 except _core._SymbolicException:
371 pass # Add nodes to the TensorFlow graph.
372 # Add nodes to the TensorFlow graph.
373 if not isinstance(inputs, (list, tuple)):
374 raise TypeError(
375 "Expected list for 'inputs' argument to "
376 "'merge' Op, not %r." % inputs)
377 _attr_N = len(inputs)
378 _, _, _op, _outputs = _op_def_library._apply_op_helper(
379 "Merge", inputs=inputs, name=name)
380 _result = _outputs[:]
381 if _execute.must_record_gradient():
382 _attrs = ("T", _op._get_attr_type("T"), "N", _op._get_attr_int("N"))
383 _inputs_flat = _op.inputs
384 _execute.record_gradient(
385 "Merge", _inputs_flat, _attrs, _result)
386 _result = _MergeOutput._make(_result)
387 return _result
389Merge = tf_export("raw_ops.Merge")(_ops.to_raw_op(merge))
392def merge_eager_fallback(inputs, name, ctx):
393 if not isinstance(inputs, (list, tuple)):
394 raise TypeError(
395 "Expected list for 'inputs' argument to "
396 "'merge' Op, not %r." % inputs)
397 _attr_N = len(inputs)
398 _attr_T, inputs = _execute.args_to_matching_eager(list(inputs), ctx, [])
399 _inputs_flat = list(inputs)
400 _attrs = ("T", _attr_T, "N", _attr_N)
401 _result = _execute.execute(b"Merge", 2, inputs=_inputs_flat, attrs=_attrs,
402 ctx=ctx, name=name)
403 if _execute.must_record_gradient():
404 _execute.record_gradient(
405 "Merge", _inputs_flat, _attrs, _result)
406 _result = _MergeOutput._make(_result)
407 return _result
410def next_iteration(data, name=None):
411 r"""Makes its input available to the next iteration.
413 Args:
414 data: A `Tensor`. The tensor to be made available to the next iteration.
415 name: A name for the operation (optional).
417 Returns:
418 A `Tensor`. Has the same type as `data`.
419 """
420 _ctx = _context._context or _context.context()
421 tld = _ctx._thread_local_data
422 if tld.is_eager:
423 try:
424 _result = pywrap_tfe.TFE_Py_FastPathExecute(
425 _ctx, "NextIteration", name, data)
426 return _result
427 except _core._NotOkStatusException as e:
428 _ops.raise_from_not_ok_status(e, name)
429 except _core._FallbackException:
430 pass
431 try:
432 return next_iteration_eager_fallback(
433 data, name=name, ctx=_ctx)
434 except _core._SymbolicException:
435 pass # Add nodes to the TensorFlow graph.
436 # Add nodes to the TensorFlow graph.
437 _, _, _op, _outputs = _op_def_library._apply_op_helper(
438 "NextIteration", data=data, name=name)
439 _result = _outputs[:]
440 if _execute.must_record_gradient():
441 _attrs = ("T", _op._get_attr_type("T"))
442 _inputs_flat = _op.inputs
443 _execute.record_gradient(
444 "NextIteration", _inputs_flat, _attrs, _result)
445 _result, = _result
446 return _result
448NextIteration = tf_export("raw_ops.NextIteration")(_ops.to_raw_op(next_iteration))
451def next_iteration_eager_fallback(data, name, ctx):
452 _attr_T, (data,) = _execute.args_to_matching_eager([data], ctx, [])
453 _inputs_flat = [data]
454 _attrs = ("T", _attr_T)
455 _result = _execute.execute(b"NextIteration", 1, inputs=_inputs_flat,
456 attrs=_attrs, ctx=ctx, name=name)
457 if _execute.must_record_gradient():
458 _execute.record_gradient(
459 "NextIteration", _inputs_flat, _attrs, _result)
460 _result, = _result
461 return _result
464@_dispatch.add_fallback_dispatch_list
465@_dispatch.add_type_based_api_dispatcher
466@tf_export('no_op')
467def no_op(name=None):
468 r"""Does nothing. Only useful as a placeholder for control edges.
470 Args:
471 name: A name for the operation (optional).
473 Returns:
474 The created Operation.
475 """
476 _ctx = _context._context or _context.context()
477 tld = _ctx._thread_local_data
478 if tld.is_eager:
479 try:
480 _result = pywrap_tfe.TFE_Py_FastPathExecute(
481 _ctx, "NoOp", name)
482 return _result
483 except _core._NotOkStatusException as e:
484 _ops.raise_from_not_ok_status(e, name)
485 except _core._FallbackException:
486 pass
487 try:
488 _result = _dispatcher_for_no_op(
489 (name,), None)
490 if _result is not NotImplemented:
491 return _result
492 return no_op_eager_fallback(
493 name=name, ctx=_ctx)
494 except _core._SymbolicException:
495 pass # Add nodes to the TensorFlow graph.
496 except (TypeError, ValueError):
497 _result = _dispatch.dispatch(
498 no_op, (), dict(name=name)
499 )
500 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
501 return _result
502 raise
503 else:
504 _result = _dispatcher_for_no_op(
505 (name,), None)
506 if _result is not NotImplemented:
507 return _result
508 # Add nodes to the TensorFlow graph.
509 try:
510 _, _, _op, _outputs = _op_def_library._apply_op_helper(
511 "NoOp", name=name)
512 except (TypeError, ValueError):
513 _result = _dispatch.dispatch(
514 no_op, (), dict(name=name)
515 )
516 if _result is not _dispatch.OpDispatcher.NOT_SUPPORTED:
517 return _result
518 raise
519 return _op
520NoOp = tf_export("raw_ops.NoOp")(_ops.to_raw_op(no_op))
521_dispatcher_for_no_op = no_op._tf_type_based_dispatcher.Dispatch
524def no_op_eager_fallback(name, ctx):
525 _inputs_flat = []
526 _attrs = None
527 _result = _execute.execute(b"NoOp", 0, inputs=_inputs_flat, attrs=_attrs,
528 ctx=ctx, name=name)
529 _result = None
530 return _result
533def ref_enter(data, frame_name, is_constant=False, parallel_iterations=10, name=None):
534 r"""Creates or finds a child frame, and makes `data` available to the child frame.
536 The unique `frame_name` is used by the `Executor` to identify frames. If
537 `is_constant` is true, `output` is a constant in the child frame; otherwise
538 it may be changed in the child frame. At most `parallel_iterations` iterations
539 are run in parallel in the child frame.
541 Args:
542 data: A mutable `Tensor`.
543 The tensor to be made available to the child frame.
544 frame_name: A `string`. The name of the child frame.
545 is_constant: An optional `bool`. Defaults to `False`.
546 If true, the output is constant within the child frame.
547 parallel_iterations: An optional `int`. Defaults to `10`.
548 The number of iterations allowed to run in parallel.
549 name: A name for the operation (optional).
551 Returns:
552 A mutable `Tensor`. Has the same type as `data`.
553 """
554 _ctx = _context._context or _context.context()
555 tld = _ctx._thread_local_data
556 if tld.is_eager:
557 raise RuntimeError("ref_enter op does not support eager execution. Arg 'output' is a ref.")
558 # Add nodes to the TensorFlow graph.
559 frame_name = _execute.make_str(frame_name, "frame_name")
560 if is_constant is None:
561 is_constant = False
562 is_constant = _execute.make_bool(is_constant, "is_constant")
563 if parallel_iterations is None:
564 parallel_iterations = 10
565 parallel_iterations = _execute.make_int(parallel_iterations, "parallel_iterations")
566 _, _, _op, _outputs = _op_def_library._apply_op_helper(
567 "RefEnter", data=data, frame_name=frame_name, is_constant=is_constant,
568 parallel_iterations=parallel_iterations, name=name)
569 _result = _outputs[:]
570 if _execute.must_record_gradient():
571 _attrs = ("T", _op._get_attr_type("T"), "frame_name",
572 _op.get_attr("frame_name"), "is_constant",
573 _op._get_attr_bool("is_constant"), "parallel_iterations",
574 _op._get_attr_int("parallel_iterations"))
575 _inputs_flat = _op.inputs
576 _execute.record_gradient(
577 "RefEnter", _inputs_flat, _attrs, _result)
578 _result, = _result
579 return _result
581RefEnter = tf_export("raw_ops.RefEnter")(_ops.to_raw_op(ref_enter))
584def ref_enter_eager_fallback(data, frame_name, is_constant, parallel_iterations, name, ctx):
585 raise RuntimeError("ref_enter op does not support eager execution. Arg 'output' is a ref.")
587def ref_exit(data, name=None):
588 r"""Exits the current frame to its parent frame.
590 Exit makes its input `data` available to the parent frame.
592 Args:
593 data: A mutable `Tensor`.
594 The tensor to be made available to the parent frame.
595 name: A name for the operation (optional).
597 Returns:
598 A mutable `Tensor`. Has the same type as `data`.
599 """
600 _ctx = _context._context or _context.context()
601 tld = _ctx._thread_local_data
602 if tld.is_eager:
603 raise RuntimeError("ref_exit op does not support eager execution. Arg 'output' is a ref.")
604 # Add nodes to the TensorFlow graph.
605 _, _, _op, _outputs = _op_def_library._apply_op_helper(
606 "RefExit", data=data, name=name)
607 _result = _outputs[:]
608 if _execute.must_record_gradient():
609 _attrs = ("T", _op._get_attr_type("T"))
610 _inputs_flat = _op.inputs
611 _execute.record_gradient(
612 "RefExit", _inputs_flat, _attrs, _result)
613 _result, = _result
614 return _result
616RefExit = tf_export("raw_ops.RefExit")(_ops.to_raw_op(ref_exit))
619def ref_exit_eager_fallback(data, name, ctx):
620 raise RuntimeError("ref_exit op does not support eager execution. Arg 'output' is a ref.")
621_RefMergeOutput = collections.namedtuple(
622 "RefMerge",
623 ["output", "value_index"])
626def ref_merge(inputs, name=None):
627 r"""Forwards the value of an available tensor from `inputs` to `output`.
629 `Merge` waits for at least one of the tensors in `inputs` to become available.
630 It is usually combined with `Switch` to implement branching.
632 `Merge` forwards the first tensor for become available to `output`, and sets
633 `value_index` to its index in `inputs`.
635 Args:
636 inputs: A list of at least 1 mutable `Tensor` objects with the same type.
637 The input tensors, exactly one of which will become available.
638 name: A name for the operation (optional).
640 Returns:
641 A tuple of `Tensor` objects (output, value_index).
643 output: A mutable `Tensor`. Has the same type as `inputs`.
644 value_index: A `Tensor` of type `int32`.
645 """
646 _ctx = _context._context or _context.context()
647 tld = _ctx._thread_local_data
648 if tld.is_eager:
649 raise RuntimeError("ref_merge op does not support eager execution. Arg 'output' is a ref.")
650 # Add nodes to the TensorFlow graph.
651 if not isinstance(inputs, (list, tuple)):
652 raise TypeError(
653 "Expected list for 'inputs' argument to "
654 "'ref_merge' Op, not %r." % inputs)
655 _attr_N = len(inputs)
656 _, _, _op, _outputs = _op_def_library._apply_op_helper(
657 "RefMerge", inputs=inputs, name=name)
658 _result = _outputs[:]
659 if _execute.must_record_gradient():
660 _attrs = ("T", _op._get_attr_type("T"), "N", _op._get_attr_int("N"))
661 _inputs_flat = _op.inputs
662 _execute.record_gradient(
663 "RefMerge", _inputs_flat, _attrs, _result)
664 _result = _RefMergeOutput._make(_result)
665 return _result
667RefMerge = tf_export("raw_ops.RefMerge")(_ops.to_raw_op(ref_merge))
670def ref_merge_eager_fallback(inputs, name, ctx):
671 raise RuntimeError("ref_merge op does not support eager execution. Arg 'output' is a ref.")
673def ref_next_iteration(data, name=None):
674 r"""Makes its input available to the next iteration.
676 Args:
677 data: A mutable `Tensor`.
678 The tensor to be made available to the next iteration.
679 name: A name for the operation (optional).
681 Returns:
682 A mutable `Tensor`. Has the same type as `data`.
683 """
684 _ctx = _context._context or _context.context()
685 tld = _ctx._thread_local_data
686 if tld.is_eager:
687 raise RuntimeError("ref_next_iteration op does not support eager execution. Arg 'output' is a ref.")
688 # Add nodes to the TensorFlow graph.
689 _, _, _op, _outputs = _op_def_library._apply_op_helper(
690 "RefNextIteration", data=data, name=name)
691 _result = _outputs[:]
692 if _execute.must_record_gradient():
693 _attrs = ("T", _op._get_attr_type("T"))
694 _inputs_flat = _op.inputs
695 _execute.record_gradient(
696 "RefNextIteration", _inputs_flat, _attrs, _result)
697 _result, = _result
698 return _result
700RefNextIteration = tf_export("raw_ops.RefNextIteration")(_ops.to_raw_op(ref_next_iteration))
703def ref_next_iteration_eager_fallback(data, name, ctx):
704 raise RuntimeError("ref_next_iteration op does not support eager execution. Arg 'output' is a ref.")
706def ref_select(index, inputs, name=None):
707 r"""Forwards the `index`th element of `inputs` to `output`.
709 Args:
710 index: A `Tensor` of type `int32`.
711 A scalar that determines the input that gets selected.
712 inputs: A list of at least 1 mutable `Tensor` objects with the same type.
713 A list of ref tensors, one of which will be forwarded to `output`.
714 name: A name for the operation (optional).
716 Returns:
717 A mutable `Tensor`. Has the same type as `inputs`.
718 """
719 _ctx = _context._context or _context.context()
720 tld = _ctx._thread_local_data
721 if tld.is_eager:
722 raise RuntimeError("ref_select op does not support eager execution. Arg 'output' is a ref.")
723 # Add nodes to the TensorFlow graph.
724 if not isinstance(inputs, (list, tuple)):
725 raise TypeError(
726 "Expected list for 'inputs' argument to "
727 "'ref_select' Op, not %r." % inputs)
728 _attr_N = len(inputs)
729 _, _, _op, _outputs = _op_def_library._apply_op_helper(
730 "RefSelect", index=index, inputs=inputs, name=name)
731 _result = _outputs[:]
732 if _execute.must_record_gradient():
733 _attrs = ("T", _op._get_attr_type("T"), "N", _op._get_attr_int("N"))
734 _inputs_flat = _op.inputs
735 _execute.record_gradient(
736 "RefSelect", _inputs_flat, _attrs, _result)
737 _result, = _result
738 return _result
740RefSelect = tf_export("raw_ops.RefSelect")(_ops.to_raw_op(ref_select))
743def ref_select_eager_fallback(index, inputs, name, ctx):
744 raise RuntimeError("ref_select op does not support eager execution. Arg 'output' is a ref.")
745_RefSwitchOutput = collections.namedtuple(
746 "RefSwitch",
747 ["output_false", "output_true"])
750def ref_switch(data, pred, name=None):
751 r"""Forwards the ref tensor `data` to the output port determined by `pred`.
753 If `pred` is true, the `data` input is forwarded to `output_true`. Otherwise,
754 the data goes to `output_false`.
756 See also `Switch` and `Merge`.
758 Args:
759 data: A mutable `Tensor`.
760 The ref tensor to be forwarded to the appropriate output.
761 pred: A `Tensor` of type `bool`.
762 A scalar that specifies which output port will receive data.
763 name: A name for the operation (optional).
765 Returns:
766 A tuple of `Tensor` objects (output_false, output_true).
768 output_false: A mutable `Tensor`. Has the same type as `data`.
769 output_true: A mutable `Tensor`. Has the same type as `data`.
770 """
771 _ctx = _context._context or _context.context()
772 tld = _ctx._thread_local_data
773 if tld.is_eager:
774 raise RuntimeError("ref_switch op does not support eager execution. Arg 'output_true' is a ref.")
775 # Add nodes to the TensorFlow graph.
776 _, _, _op, _outputs = _op_def_library._apply_op_helper(
777 "RefSwitch", data=data, pred=pred, name=name)
778 _result = _outputs[:]
779 if _execute.must_record_gradient():
780 _attrs = ("T", _op._get_attr_type("T"))
781 _inputs_flat = _op.inputs
782 _execute.record_gradient(
783 "RefSwitch", _inputs_flat, _attrs, _result)
784 _result = _RefSwitchOutput._make(_result)
785 return _result
787RefSwitch = tf_export("raw_ops.RefSwitch")(_ops.to_raw_op(ref_switch))
790def ref_switch_eager_fallback(data, pred, name, ctx):
791 raise RuntimeError("ref_switch op does not support eager execution. Arg 'output_true' is a ref.")
792_SwitchOutput = collections.namedtuple(
793 "Switch",
794 ["output_false", "output_true"])
797def switch(data, pred, name=None):
798 r"""Forwards `data` to the output port determined by `pred`.
800 If `pred` is true, the `data` input is forwarded to `output_true`. Otherwise,
801 the data goes to `output_false`.
803 See also `RefSwitch` and `Merge`.
805 Args:
806 data: A `Tensor`. The tensor to be forwarded to the appropriate output.
807 pred: A `Tensor` of type `bool`.
808 A scalar that specifies which output port will receive data.
809 name: A name for the operation (optional).
811 Returns:
812 A tuple of `Tensor` objects (output_false, output_true).
814 output_false: A `Tensor`. Has the same type as `data`.
815 output_true: A `Tensor`. Has the same type as `data`.
816 """
817 _ctx = _context._context or _context.context()
818 tld = _ctx._thread_local_data
819 if tld.is_eager:
820 try:
821 _result = pywrap_tfe.TFE_Py_FastPathExecute(
822 _ctx, "Switch", name, data, pred)
823 _result = _SwitchOutput._make(_result)
824 return _result
825 except _core._NotOkStatusException as e:
826 _ops.raise_from_not_ok_status(e, name)
827 except _core._FallbackException:
828 pass
829 try:
830 return switch_eager_fallback(
831 data, pred, name=name, ctx=_ctx)
832 except _core._SymbolicException:
833 pass # Add nodes to the TensorFlow graph.
834 # Add nodes to the TensorFlow graph.
835 _, _, _op, _outputs = _op_def_library._apply_op_helper(
836 "Switch", data=data, pred=pred, name=name)
837 _result = _outputs[:]
838 if _execute.must_record_gradient():
839 _attrs = ("T", _op._get_attr_type("T"))
840 _inputs_flat = _op.inputs
841 _execute.record_gradient(
842 "Switch", _inputs_flat, _attrs, _result)
843 _result = _SwitchOutput._make(_result)
844 return _result
846Switch = tf_export("raw_ops.Switch")(_ops.to_raw_op(switch))
849def switch_eager_fallback(data, pred, name, ctx):
850 _attr_T, (data,) = _execute.args_to_matching_eager([data], ctx, [])
851 pred = _ops.convert_to_tensor(pred, _dtypes.bool)
852 _inputs_flat = [data, pred]
853 _attrs = ("T", _attr_T)
854 _result = _execute.execute(b"Switch", 2, inputs=_inputs_flat, attrs=_attrs,
855 ctx=ctx, name=name)
856 if _execute.must_record_gradient():
857 _execute.record_gradient(
858 "Switch", _inputs_flat, _attrs, _result)
859 _result = _SwitchOutput._make(_result)
860 return _result