Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_set_ops.py: 15%
193 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
23_DenseToDenseSetOperationOutput = collections.namedtuple(
24 "DenseToDenseSetOperation",
25 ["result_indices", "result_values", "result_shape"])
28def dense_to_dense_set_operation(set1, set2, set_operation, validate_indices=True, name=None):
29 r"""Applies set operation along last dimension of 2 `Tensor` inputs.
31 See SetOperationOp::SetOperationFromContext for values of `set_operation`.
33 Output `result` is a `SparseTensor` represented by `result_indices`,
34 `result_values`, and `result_shape`. For `set1` and `set2` ranked `n`, this
35 has rank `n` and the same 1st `n-1` dimensions as `set1` and `set2`. The `nth`
36 dimension contains the result of `set_operation` applied to the corresponding
37 `[0...n-1]` dimension of `set`.
39 Args:
40 set1: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
41 `Tensor` with rank `n`. 1st `n-1` dimensions must be the same as `set2`.
42 Dimension `n` contains values in a set, duplicates are allowed but ignored.
43 set2: A `Tensor`. Must have the same type as `set1`.
44 `Tensor` with rank `n`. 1st `n-1` dimensions must be the same as `set1`.
45 Dimension `n` contains values in a set, duplicates are allowed but ignored.
46 set_operation: A `string`.
47 validate_indices: An optional `bool`. Defaults to `True`.
48 name: A name for the operation (optional).
50 Returns:
51 A tuple of `Tensor` objects (result_indices, result_values, result_shape).
53 result_indices: A `Tensor` of type `int64`.
54 result_values: A `Tensor`. Has the same type as `set1`.
55 result_shape: A `Tensor` of type `int64`.
56 """
57 _ctx = _context._context or _context.context()
58 tld = _ctx._thread_local_data
59 if tld.is_eager:
60 try:
61 _result = pywrap_tfe.TFE_Py_FastPathExecute(
62 _ctx, "DenseToDenseSetOperation", name, set1, set2, "set_operation",
63 set_operation, "validate_indices", validate_indices)
64 _result = _DenseToDenseSetOperationOutput._make(_result)
65 return _result
66 except _core._NotOkStatusException as e:
67 _ops.raise_from_not_ok_status(e, name)
68 except _core._FallbackException:
69 pass
70 try:
71 return dense_to_dense_set_operation_eager_fallback(
72 set1, set2, set_operation=set_operation,
73 validate_indices=validate_indices, name=name, ctx=_ctx)
74 except _core._SymbolicException:
75 pass # Add nodes to the TensorFlow graph.
76 # Add nodes to the TensorFlow graph.
77 set_operation = _execute.make_str(set_operation, "set_operation")
78 if validate_indices is None:
79 validate_indices = True
80 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
81 _, _, _op, _outputs = _op_def_library._apply_op_helper(
82 "DenseToDenseSetOperation", set1=set1, set2=set2,
83 set_operation=set_operation,
84 validate_indices=validate_indices,
85 name=name)
86 _result = _outputs[:]
87 if _execute.must_record_gradient():
88 _attrs = ("set_operation", _op.get_attr("set_operation"),
89 "validate_indices", _op._get_attr_bool("validate_indices"), "T",
90 _op._get_attr_type("T"))
91 _inputs_flat = _op.inputs
92 _execute.record_gradient(
93 "DenseToDenseSetOperation", _inputs_flat, _attrs, _result)
94 _result = _DenseToDenseSetOperationOutput._make(_result)
95 return _result
97DenseToDenseSetOperation = tf_export("raw_ops.DenseToDenseSetOperation")(_ops.to_raw_op(dense_to_dense_set_operation))
100def dense_to_dense_set_operation_eager_fallback(set1, set2, set_operation, validate_indices, name, ctx):
101 set_operation = _execute.make_str(set_operation, "set_operation")
102 if validate_indices is None:
103 validate_indices = True
104 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
105 _attr_T, _inputs_T = _execute.args_to_matching_eager([set1, set2], ctx, [_dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.uint8, _dtypes.uint16, _dtypes.string, ])
106 (set1, set2) = _inputs_T
107 _inputs_flat = [set1, set2]
108 _attrs = ("set_operation", set_operation, "validate_indices",
109 validate_indices, "T", _attr_T)
110 _result = _execute.execute(b"DenseToDenseSetOperation", 3,
111 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
112 name=name)
113 if _execute.must_record_gradient():
114 _execute.record_gradient(
115 "DenseToDenseSetOperation", _inputs_flat, _attrs, _result)
116 _result = _DenseToDenseSetOperationOutput._make(_result)
117 return _result
119_DenseToSparseSetOperationOutput = collections.namedtuple(
120 "DenseToSparseSetOperation",
121 ["result_indices", "result_values", "result_shape"])
124def dense_to_sparse_set_operation(set1, set2_indices, set2_values, set2_shape, set_operation, validate_indices=True, name=None):
125 r"""Applies set operation along last dimension of `Tensor` and `SparseTensor`.
127 See SetOperationOp::SetOperationFromContext for values of `set_operation`.
129 Input `set2` is a `SparseTensor` represented by `set2_indices`, `set2_values`,
130 and `set2_shape`. For `set2` ranked `n`, 1st `n-1` dimensions must be the same
131 as `set1`. Dimension `n` contains values in a set, duplicates are allowed but
132 ignored.
134 If `validate_indices` is `True`, this op validates the order and range of `set2`
135 indices.
137 Output `result` is a `SparseTensor` represented by `result_indices`,
138 `result_values`, and `result_shape`. For `set1` and `set2` ranked `n`, this
139 has rank `n` and the same 1st `n-1` dimensions as `set1` and `set2`. The `nth`
140 dimension contains the result of `set_operation` applied to the corresponding
141 `[0...n-1]` dimension of `set`.
143 Args:
144 set1: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
145 `Tensor` with rank `n`. 1st `n-1` dimensions must be the same as `set2`.
146 Dimension `n` contains values in a set, duplicates are allowed but ignored.
147 set2_indices: A `Tensor` of type `int64`.
148 2D `Tensor`, indices of a `SparseTensor`. Must be in row-major
149 order.
150 set2_values: A `Tensor`. Must have the same type as `set1`.
151 1D `Tensor`, values of a `SparseTensor`. Must be in row-major
152 order.
153 set2_shape: A `Tensor` of type `int64`.
154 1D `Tensor`, shape of a `SparseTensor`. `set2_shape[0...n-1]` must
155 be the same as the 1st `n-1` dimensions of `set1`, `result_shape[n]` is the
156 max set size across `n-1` dimensions.
157 set_operation: A `string`.
158 validate_indices: An optional `bool`. Defaults to `True`.
159 name: A name for the operation (optional).
161 Returns:
162 A tuple of `Tensor` objects (result_indices, result_values, result_shape).
164 result_indices: A `Tensor` of type `int64`.
165 result_values: A `Tensor`. Has the same type as `set1`.
166 result_shape: A `Tensor` of type `int64`.
167 """
168 _ctx = _context._context or _context.context()
169 tld = _ctx._thread_local_data
170 if tld.is_eager:
171 try:
172 _result = pywrap_tfe.TFE_Py_FastPathExecute(
173 _ctx, "DenseToSparseSetOperation", name, set1, set2_indices,
174 set2_values, set2_shape, "set_operation", set_operation,
175 "validate_indices", validate_indices)
176 _result = _DenseToSparseSetOperationOutput._make(_result)
177 return _result
178 except _core._NotOkStatusException as e:
179 _ops.raise_from_not_ok_status(e, name)
180 except _core._FallbackException:
181 pass
182 try:
183 return dense_to_sparse_set_operation_eager_fallback(
184 set1, set2_indices, set2_values, set2_shape,
185 set_operation=set_operation, validate_indices=validate_indices,
186 name=name, ctx=_ctx)
187 except _core._SymbolicException:
188 pass # Add nodes to the TensorFlow graph.
189 # Add nodes to the TensorFlow graph.
190 set_operation = _execute.make_str(set_operation, "set_operation")
191 if validate_indices is None:
192 validate_indices = True
193 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
194 _, _, _op, _outputs = _op_def_library._apply_op_helper(
195 "DenseToSparseSetOperation", set1=set1, set2_indices=set2_indices,
196 set2_values=set2_values,
197 set2_shape=set2_shape,
198 set_operation=set_operation,
199 validate_indices=validate_indices,
200 name=name)
201 _result = _outputs[:]
202 if _execute.must_record_gradient():
203 _attrs = ("set_operation", _op.get_attr("set_operation"),
204 "validate_indices", _op._get_attr_bool("validate_indices"), "T",
205 _op._get_attr_type("T"))
206 _inputs_flat = _op.inputs
207 _execute.record_gradient(
208 "DenseToSparseSetOperation", _inputs_flat, _attrs, _result)
209 _result = _DenseToSparseSetOperationOutput._make(_result)
210 return _result
212DenseToSparseSetOperation = tf_export("raw_ops.DenseToSparseSetOperation")(_ops.to_raw_op(dense_to_sparse_set_operation))
215def dense_to_sparse_set_operation_eager_fallback(set1, set2_indices, set2_values, set2_shape, set_operation, validate_indices, name, ctx):
216 set_operation = _execute.make_str(set_operation, "set_operation")
217 if validate_indices is None:
218 validate_indices = True
219 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
220 _attr_T, _inputs_T = _execute.args_to_matching_eager([set1, set2_values], ctx, [_dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.uint8, _dtypes.uint16, _dtypes.string, ])
221 (set1, set2_values) = _inputs_T
222 set2_indices = _ops.convert_to_tensor(set2_indices, _dtypes.int64)
223 set2_shape = _ops.convert_to_tensor(set2_shape, _dtypes.int64)
224 _inputs_flat = [set1, set2_indices, set2_values, set2_shape]
225 _attrs = ("set_operation", set_operation, "validate_indices",
226 validate_indices, "T", _attr_T)
227 _result = _execute.execute(b"DenseToSparseSetOperation", 3,
228 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
229 name=name)
230 if _execute.must_record_gradient():
231 _execute.record_gradient(
232 "DenseToSparseSetOperation", _inputs_flat, _attrs, _result)
233 _result = _DenseToSparseSetOperationOutput._make(_result)
234 return _result
237def set_size(set_indices, set_values, set_shape, validate_indices=True, name=None):
238 r"""Number of unique elements along last dimension of input `set`.
240 Input `set` is a `SparseTensor` represented by `set_indices`, `set_values`,
241 and `set_shape`. The last dimension contains values in a set, duplicates are
242 allowed but ignored.
244 If `validate_indices` is `True`, this op validates the order and range of `set`
245 indices. Setting is to `False` while passing invalid arguments results in
246 undefined behavior.
248 Args:
249 set_indices: A `Tensor` of type `int64`.
250 2D `Tensor`, indices of a `SparseTensor`.
251 set_values: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
252 1D `Tensor`, values of a `SparseTensor`.
253 set_shape: A `Tensor` of type `int64`.
254 1D `Tensor`, shape of a `SparseTensor`.
255 validate_indices: An optional `bool`. Defaults to `True`.
256 name: A name for the operation (optional).
258 Returns:
259 A `Tensor` of type `int32`.
260 """
261 _ctx = _context._context or _context.context()
262 tld = _ctx._thread_local_data
263 if tld.is_eager:
264 try:
265 _result = pywrap_tfe.TFE_Py_FastPathExecute(
266 _ctx, "SetSize", name, set_indices, set_values, set_shape,
267 "validate_indices", validate_indices)
268 return _result
269 except _core._NotOkStatusException as e:
270 _ops.raise_from_not_ok_status(e, name)
271 except _core._FallbackException:
272 pass
273 try:
274 return set_size_eager_fallback(
275 set_indices, set_values, set_shape,
276 validate_indices=validate_indices, name=name, ctx=_ctx)
277 except _core._SymbolicException:
278 pass # Add nodes to the TensorFlow graph.
279 # Add nodes to the TensorFlow graph.
280 if validate_indices is None:
281 validate_indices = True
282 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
283 _, _, _op, _outputs = _op_def_library._apply_op_helper(
284 "SetSize", set_indices=set_indices, set_values=set_values,
285 set_shape=set_shape, validate_indices=validate_indices,
286 name=name)
287 _result = _outputs[:]
288 if _execute.must_record_gradient():
289 _attrs = ("validate_indices", _op._get_attr_bool("validate_indices"), "T",
290 _op._get_attr_type("T"))
291 _inputs_flat = _op.inputs
292 _execute.record_gradient(
293 "SetSize", _inputs_flat, _attrs, _result)
294 _result, = _result
295 return _result
297SetSize = tf_export("raw_ops.SetSize")(_ops.to_raw_op(set_size))
300def set_size_eager_fallback(set_indices, set_values, set_shape, validate_indices, name, ctx):
301 if validate_indices is None:
302 validate_indices = True
303 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
304 _attr_T, (set_values,) = _execute.args_to_matching_eager([set_values], ctx, [_dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.uint8, _dtypes.uint16, _dtypes.string, ])
305 set_indices = _ops.convert_to_tensor(set_indices, _dtypes.int64)
306 set_shape = _ops.convert_to_tensor(set_shape, _dtypes.int64)
307 _inputs_flat = [set_indices, set_values, set_shape]
308 _attrs = ("validate_indices", validate_indices, "T", _attr_T)
309 _result = _execute.execute(b"SetSize", 1, inputs=_inputs_flat, attrs=_attrs,
310 ctx=ctx, name=name)
311 if _execute.must_record_gradient():
312 _execute.record_gradient(
313 "SetSize", _inputs_flat, _attrs, _result)
314 _result, = _result
315 return _result
317_SparseToSparseSetOperationOutput = collections.namedtuple(
318 "SparseToSparseSetOperation",
319 ["result_indices", "result_values", "result_shape"])
322def sparse_to_sparse_set_operation(set1_indices, set1_values, set1_shape, set2_indices, set2_values, set2_shape, set_operation, validate_indices=True, name=None):
323 r"""Applies set operation along last dimension of 2 `SparseTensor` inputs.
325 See SetOperationOp::SetOperationFromContext for values of `set_operation`.
327 If `validate_indices` is `True`, `SparseToSparseSetOperation` validates the
328 order and range of `set1` and `set2` indices.
330 Input `set1` is a `SparseTensor` represented by `set1_indices`, `set1_values`,
331 and `set1_shape`. For `set1` ranked `n`, 1st `n-1` dimensions must be the same
332 as `set2`. Dimension `n` contains values in a set, duplicates are allowed but
333 ignored.
335 Input `set2` is a `SparseTensor` represented by `set2_indices`, `set2_values`,
336 and `set2_shape`. For `set2` ranked `n`, 1st `n-1` dimensions must be the same
337 as `set1`. Dimension `n` contains values in a set, duplicates are allowed but
338 ignored.
340 If `validate_indices` is `True`, this op validates the order and range of `set1`
341 and `set2` indices.
343 Output `result` is a `SparseTensor` represented by `result_indices`,
344 `result_values`, and `result_shape`. For `set1` and `set2` ranked `n`, this
345 has rank `n` and the same 1st `n-1` dimensions as `set1` and `set2`. The `nth`
346 dimension contains the result of `set_operation` applied to the corresponding
347 `[0...n-1]` dimension of `set`.
349 Args:
350 set1_indices: A `Tensor` of type `int64`.
351 2D `Tensor`, indices of a `SparseTensor`. Must be in row-major
352 order.
353 set1_values: A `Tensor`. Must be one of the following types: `int8`, `int16`, `int32`, `int64`, `uint8`, `uint16`, `string`.
354 1D `Tensor`, values of a `SparseTensor`. Must be in row-major
355 order.
356 set1_shape: A `Tensor` of type `int64`.
357 1D `Tensor`, shape of a `SparseTensor`. `set1_shape[0...n-1]` must
358 be the same as `set2_shape[0...n-1]`, `set1_shape[n]` is the
359 max set size across `0...n-1` dimensions.
360 set2_indices: A `Tensor` of type `int64`.
361 2D `Tensor`, indices of a `SparseTensor`. Must be in row-major
362 order.
363 set2_values: A `Tensor`. Must have the same type as `set1_values`.
364 1D `Tensor`, values of a `SparseTensor`. Must be in row-major
365 order.
366 set2_shape: A `Tensor` of type `int64`.
367 1D `Tensor`, shape of a `SparseTensor`. `set2_shape[0...n-1]` must
368 be the same as `set1_shape[0...n-1]`, `set2_shape[n]` is the
369 max set size across `0...n-1` dimensions.
370 set_operation: A `string`.
371 validate_indices: An optional `bool`. Defaults to `True`.
372 name: A name for the operation (optional).
374 Returns:
375 A tuple of `Tensor` objects (result_indices, result_values, result_shape).
377 result_indices: A `Tensor` of type `int64`.
378 result_values: A `Tensor`. Has the same type as `set1_values`.
379 result_shape: A `Tensor` of type `int64`.
380 """
381 _ctx = _context._context or _context.context()
382 tld = _ctx._thread_local_data
383 if tld.is_eager:
384 try:
385 _result = pywrap_tfe.TFE_Py_FastPathExecute(
386 _ctx, "SparseToSparseSetOperation", name, set1_indices, set1_values,
387 set1_shape, set2_indices, set2_values, set2_shape, "set_operation",
388 set_operation, "validate_indices", validate_indices)
389 _result = _SparseToSparseSetOperationOutput._make(_result)
390 return _result
391 except _core._NotOkStatusException as e:
392 _ops.raise_from_not_ok_status(e, name)
393 except _core._FallbackException:
394 pass
395 try:
396 return sparse_to_sparse_set_operation_eager_fallback(
397 set1_indices, set1_values, set1_shape, set2_indices, set2_values,
398 set2_shape, set_operation=set_operation,
399 validate_indices=validate_indices, name=name, ctx=_ctx)
400 except _core._SymbolicException:
401 pass # Add nodes to the TensorFlow graph.
402 # Add nodes to the TensorFlow graph.
403 set_operation = _execute.make_str(set_operation, "set_operation")
404 if validate_indices is None:
405 validate_indices = True
406 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
407 _, _, _op, _outputs = _op_def_library._apply_op_helper(
408 "SparseToSparseSetOperation", set1_indices=set1_indices,
409 set1_values=set1_values,
410 set1_shape=set1_shape,
411 set2_indices=set2_indices,
412 set2_values=set2_values,
413 set2_shape=set2_shape,
414 set_operation=set_operation,
415 validate_indices=validate_indices,
416 name=name)
417 _result = _outputs[:]
418 if _execute.must_record_gradient():
419 _attrs = ("set_operation", _op.get_attr("set_operation"),
420 "validate_indices", _op._get_attr_bool("validate_indices"), "T",
421 _op._get_attr_type("T"))
422 _inputs_flat = _op.inputs
423 _execute.record_gradient(
424 "SparseToSparseSetOperation", _inputs_flat, _attrs, _result)
425 _result = _SparseToSparseSetOperationOutput._make(_result)
426 return _result
428SparseToSparseSetOperation = tf_export("raw_ops.SparseToSparseSetOperation")(_ops.to_raw_op(sparse_to_sparse_set_operation))
431def sparse_to_sparse_set_operation_eager_fallback(set1_indices, set1_values, set1_shape, set2_indices, set2_values, set2_shape, set_operation, validate_indices, name, ctx):
432 set_operation = _execute.make_str(set_operation, "set_operation")
433 if validate_indices is None:
434 validate_indices = True
435 validate_indices = _execute.make_bool(validate_indices, "validate_indices")
436 _attr_T, _inputs_T = _execute.args_to_matching_eager([set1_values, set2_values], ctx, [_dtypes.int8, _dtypes.int16, _dtypes.int32, _dtypes.int64, _dtypes.uint8, _dtypes.uint16, _dtypes.string, ])
437 (set1_values, set2_values) = _inputs_T
438 set1_indices = _ops.convert_to_tensor(set1_indices, _dtypes.int64)
439 set1_shape = _ops.convert_to_tensor(set1_shape, _dtypes.int64)
440 set2_indices = _ops.convert_to_tensor(set2_indices, _dtypes.int64)
441 set2_shape = _ops.convert_to_tensor(set2_shape, _dtypes.int64)
442 _inputs_flat = [set1_indices, set1_values, set1_shape, set2_indices, set2_values, set2_shape]
443 _attrs = ("set_operation", set_operation, "validate_indices",
444 validate_indices, "T", _attr_T)
445 _result = _execute.execute(b"SparseToSparseSetOperation", 3,
446 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
447 name=name)
448 if _execute.must_record_gradient():
449 _execute.record_gradient(
450 "SparseToSparseSetOperation", _inputs_flat, _attrs, _result)
451 _result = _SparseToSparseSetOperationOutput._make(_result)
452 return _result