Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_script_ops.py: 16%
141 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 eager_py_func(input, token, Tout, is_async=False, name=None):
25 r"""Eagerly executes a python function to compute func(input)->output. The
27 semantics of the input, output, and attributes are the same as those for
28 PyFunc.
30 Args:
31 input: A list of `Tensor` objects.
32 token: A `string`.
33 Tout: A list of `tf.DTypes`.
34 is_async: An optional `bool`. Defaults to `False`.
35 name: A name for the operation (optional).
37 Returns:
38 A list of `Tensor` objects of type `Tout`.
39 """
40 _ctx = _context._context or _context.context()
41 tld = _ctx._thread_local_data
42 if tld.is_eager:
43 try:
44 _result = pywrap_tfe.TFE_Py_FastPathExecute(
45 _ctx, "EagerPyFunc", name, input, "token", token, "is_async",
46 is_async, "Tout", Tout)
47 return _result
48 except _core._NotOkStatusException as e:
49 _ops.raise_from_not_ok_status(e, name)
50 except _core._FallbackException:
51 pass
52 try:
53 return eager_py_func_eager_fallback(
54 input, token=token, is_async=is_async, Tout=Tout, name=name,
55 ctx=_ctx)
56 except _core._SymbolicException:
57 pass # Add nodes to the TensorFlow graph.
58 # Add nodes to the TensorFlow graph.
59 token = _execute.make_str(token, "token")
60 if not isinstance(Tout, (list, tuple)):
61 raise TypeError(
62 "Expected list for 'Tout' argument to "
63 "'eager_py_func' Op, not %r." % Tout)
64 Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
65 if is_async is None:
66 is_async = False
67 is_async = _execute.make_bool(is_async, "is_async")
68 _, _, _op, _outputs = _op_def_library._apply_op_helper(
69 "EagerPyFunc", input=input, token=token, Tout=Tout, is_async=is_async,
70 name=name)
71 _result = _outputs[:]
72 if not _result:
73 return _op
74 if _execute.must_record_gradient():
75 _attrs = ("token", _op.get_attr("token"), "is_async",
76 _op._get_attr_bool("is_async"), "Tin", _op.get_attr("Tin"),
77 "Tout", _op.get_attr("Tout"))
78 _inputs_flat = _op.inputs
79 _execute.record_gradient(
80 "EagerPyFunc", _inputs_flat, _attrs, _result)
81 return _result
83EagerPyFunc = tf_export("raw_ops.EagerPyFunc")(_ops.to_raw_op(eager_py_func))
86def eager_py_func_eager_fallback(input, token, Tout, is_async, name, ctx):
87 token = _execute.make_str(token, "token")
88 if not isinstance(Tout, (list, tuple)):
89 raise TypeError(
90 "Expected list for 'Tout' argument to "
91 "'eager_py_func' Op, not %r." % Tout)
92 Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
93 if is_async is None:
94 is_async = False
95 is_async = _execute.make_bool(is_async, "is_async")
96 _attr_Tin, input = _execute.convert_to_mixed_eager_tensors(input, ctx)
97 _inputs_flat = list(input)
98 _attrs = ("token", token, "is_async", is_async, "Tin", _attr_Tin, "Tout",
99 Tout)
100 _result = _execute.execute(b"EagerPyFunc", len(Tout), inputs=_inputs_flat,
101 attrs=_attrs, ctx=ctx, name=name)
102 if _execute.must_record_gradient():
103 _execute.record_gradient(
104 "EagerPyFunc", _inputs_flat, _attrs, _result)
105 return _result
108def py_func(input, token, Tout, name=None):
109 r"""Invokes a python function to compute func(input)->output.
111 This operation is considered stateful. For a stateless version, see
112 PyFuncStateless.
114 Args:
115 input: A list of `Tensor` objects.
116 List of Tensors that will provide input to the Op.
117 token: A `string`.
118 A token representing a registered python function in this address space.
119 Tout: A list of `tf.DTypes`. Data types of the outputs from the op.
120 The length of the list specifies the number of outputs.
121 name: A name for the operation (optional).
123 Returns:
124 A list of `Tensor` objects of type `Tout`.
125 """
126 _ctx = _context._context or _context.context()
127 tld = _ctx._thread_local_data
128 if tld.is_eager:
129 try:
130 _result = pywrap_tfe.TFE_Py_FastPathExecute(
131 _ctx, "PyFunc", name, input, "token", token, "Tout", Tout)
132 return _result
133 except _core._NotOkStatusException as e:
134 _ops.raise_from_not_ok_status(e, name)
135 except _core._FallbackException:
136 pass
137 try:
138 return py_func_eager_fallback(
139 input, token=token, Tout=Tout, name=name, ctx=_ctx)
140 except _core._SymbolicException:
141 pass # Add nodes to the TensorFlow graph.
142 # Add nodes to the TensorFlow graph.
143 token = _execute.make_str(token, "token")
144 if not isinstance(Tout, (list, tuple)):
145 raise TypeError(
146 "Expected list for 'Tout' argument to "
147 "'py_func' Op, not %r." % Tout)
148 Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
149 _, _, _op, _outputs = _op_def_library._apply_op_helper(
150 "PyFunc", input=input, token=token, Tout=Tout, name=name)
151 _result = _outputs[:]
152 if not _result:
153 return _op
154 if _execute.must_record_gradient():
155 _attrs = ("token", _op.get_attr("token"), "Tin", _op.get_attr("Tin"),
156 "Tout", _op.get_attr("Tout"))
157 _inputs_flat = _op.inputs
158 _execute.record_gradient(
159 "PyFunc", _inputs_flat, _attrs, _result)
160 return _result
162PyFunc = tf_export("raw_ops.PyFunc")(_ops.to_raw_op(py_func))
165def py_func_eager_fallback(input, token, Tout, name, ctx):
166 token = _execute.make_str(token, "token")
167 if not isinstance(Tout, (list, tuple)):
168 raise TypeError(
169 "Expected list for 'Tout' argument to "
170 "'py_func' Op, not %r." % Tout)
171 Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
172 _attr_Tin, input = _execute.convert_to_mixed_eager_tensors(input, ctx)
173 _inputs_flat = list(input)
174 _attrs = ("token", token, "Tin", _attr_Tin, "Tout", Tout)
175 _result = _execute.execute(b"PyFunc", len(Tout), inputs=_inputs_flat,
176 attrs=_attrs, ctx=ctx, name=name)
177 if _execute.must_record_gradient():
178 _execute.record_gradient(
179 "PyFunc", _inputs_flat, _attrs, _result)
180 return _result
183def py_func_stateless(input, token, Tout, name=None):
184 r"""A stateless version of PyFunc.
186 Args:
187 input: A list of `Tensor` objects.
188 token: A `string`.
189 Tout: A list of `tf.DTypes`.
190 name: A name for the operation (optional).
192 Returns:
193 A list of `Tensor` objects of type `Tout`.
194 """
195 _ctx = _context._context or _context.context()
196 tld = _ctx._thread_local_data
197 if tld.is_eager:
198 try:
199 _result = pywrap_tfe.TFE_Py_FastPathExecute(
200 _ctx, "PyFuncStateless", name, input, "token", token, "Tout", Tout)
201 return _result
202 except _core._NotOkStatusException as e:
203 _ops.raise_from_not_ok_status(e, name)
204 except _core._FallbackException:
205 pass
206 try:
207 return py_func_stateless_eager_fallback(
208 input, token=token, Tout=Tout, name=name, ctx=_ctx)
209 except _core._SymbolicException:
210 pass # Add nodes to the TensorFlow graph.
211 # Add nodes to the TensorFlow graph.
212 token = _execute.make_str(token, "token")
213 if not isinstance(Tout, (list, tuple)):
214 raise TypeError(
215 "Expected list for 'Tout' argument to "
216 "'py_func_stateless' Op, not %r." % Tout)
217 Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
218 _, _, _op, _outputs = _op_def_library._apply_op_helper(
219 "PyFuncStateless", input=input, token=token, Tout=Tout, name=name)
220 _result = _outputs[:]
221 if _execute.must_record_gradient():
222 _attrs = ("token", _op.get_attr("token"), "Tin", _op.get_attr("Tin"),
223 "Tout", _op.get_attr("Tout"))
224 _inputs_flat = _op.inputs
225 _execute.record_gradient(
226 "PyFuncStateless", _inputs_flat, _attrs, _result)
227 return _result
229PyFuncStateless = tf_export("raw_ops.PyFuncStateless")(_ops.to_raw_op(py_func_stateless))
232def py_func_stateless_eager_fallback(input, token, Tout, name, ctx):
233 token = _execute.make_str(token, "token")
234 if not isinstance(Tout, (list, tuple)):
235 raise TypeError(
236 "Expected list for 'Tout' argument to "
237 "'py_func_stateless' Op, not %r." % Tout)
238 Tout = [_execute.make_type(_t, "Tout") for _t in Tout]
239 _attr_Tin, input = _execute.convert_to_mixed_eager_tensors(input, ctx)
240 _inputs_flat = list(input)
241 _attrs = ("token", token, "Tin", _attr_Tin, "Tout", Tout)
242 _result = _execute.execute(b"PyFuncStateless", len(Tout),
243 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
244 name=name)
245 if _execute.must_record_gradient():
246 _execute.record_gradient(
247 "PyFuncStateless", _inputs_flat, _attrs, _result)
248 return _result