Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_ragged_conversion_ops.py: 13%
232 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_RaggedTensorFromVariantOutput = collections.namedtuple(
24 "RaggedTensorFromVariant",
25 ["output_nested_splits", "output_dense_values"])
28def ragged_tensor_from_variant(encoded_ragged, input_ragged_rank, output_ragged_rank, Tvalues, Tsplits=_dtypes.int64, name=None):
29 r"""Decodes a `variant` Tensor into a `RaggedTensor`.
31 Decodes the given `variant` Tensor and returns a `RaggedTensor`. The input
32 could be a scalar, meaning it encodes a single `RaggedTensor` with ragged_rank
33 `output_ragged_rank`. It could also have an arbitrary rank, in which case each
34 element is decoded into a `RaggedTensor` with ragged_rank `input_ragged_rank`
35 and these are then stacked according to the input shape to output a single
36 `RaggedTensor` with ragged_rank `output_ragged_rank`. Each `variant` element in
37 the input Tensor is decoded by retrieving from the element a 1-D `variant`
38 Tensor with `input_ragged_rank + 1` Tensors, corresponding to the splits and
39 values of the decoded `RaggedTensor`. If `input_ragged_rank` is -1, then it is
40 inferred as `output_ragged_rank` - `rank(encoded_ragged)`. See
41 `RaggedTensorToVariant` for the corresponding encoding logic.
43 Args:
44 encoded_ragged: A `Tensor` of type `variant`.
45 A `variant` Tensor containing encoded `RaggedTensor`s.
46 input_ragged_rank: An `int` that is `>= -1`.
47 The ragged rank of each encoded `RaggedTensor` component in the input. If set to
48 -1, this is inferred as `output_ragged_rank` - `rank(encoded_ragged)`
49 output_ragged_rank: An `int` that is `>= 0`.
50 The expected ragged rank of the output `RaggedTensor`. The following must hold:
51 `output_ragged_rank = rank(encoded_ragged) + input_ragged_rank`.
52 Tvalues: A `tf.DType`.
53 Tsplits: An optional `tf.DType` from: `tf.int32, tf.int64`. Defaults to `tf.int64`.
54 name: A name for the operation (optional).
56 Returns:
57 A tuple of `Tensor` objects (output_nested_splits, output_dense_values).
59 output_nested_splits: A list of `output_ragged_rank` `Tensor` objects with type `Tsplits`.
60 output_dense_values: A `Tensor` of type `Tvalues`.
61 """
62 _ctx = _context._context or _context.context()
63 tld = _ctx._thread_local_data
64 if tld.is_eager:
65 try:
66 _result = pywrap_tfe.TFE_Py_FastPathExecute(
67 _ctx, "RaggedTensorFromVariant", name, encoded_ragged,
68 "input_ragged_rank", input_ragged_rank, "output_ragged_rank",
69 output_ragged_rank, "Tvalues", Tvalues, "Tsplits", Tsplits)
70 _result = _RaggedTensorFromVariantOutput._make(_result)
71 return _result
72 except _core._NotOkStatusException as e:
73 _ops.raise_from_not_ok_status(e, name)
74 except _core._FallbackException:
75 pass
76 try:
77 return ragged_tensor_from_variant_eager_fallback(
78 encoded_ragged, input_ragged_rank=input_ragged_rank,
79 output_ragged_rank=output_ragged_rank, Tvalues=Tvalues,
80 Tsplits=Tsplits, name=name, ctx=_ctx)
81 except _core._SymbolicException:
82 pass # Add nodes to the TensorFlow graph.
83 # Add nodes to the TensorFlow graph.
84 input_ragged_rank = _execute.make_int(input_ragged_rank, "input_ragged_rank")
85 output_ragged_rank = _execute.make_int(output_ragged_rank, "output_ragged_rank")
86 Tvalues = _execute.make_type(Tvalues, "Tvalues")
87 if Tsplits is None:
88 Tsplits = _dtypes.int64
89 Tsplits = _execute.make_type(Tsplits, "Tsplits")
90 _, _, _op, _outputs = _op_def_library._apply_op_helper(
91 "RaggedTensorFromVariant", encoded_ragged=encoded_ragged,
92 input_ragged_rank=input_ragged_rank,
93 output_ragged_rank=output_ragged_rank,
94 Tvalues=Tvalues, Tsplits=Tsplits,
95 name=name)
96 _result = _outputs[:]
97 if _execute.must_record_gradient():
98 _attrs = ("input_ragged_rank", _op._get_attr_int("input_ragged_rank"),
99 "output_ragged_rank", _op._get_attr_int("output_ragged_rank"),
100 "Tvalues", _op._get_attr_type("Tvalues"), "Tsplits",
101 _op._get_attr_type("Tsplits"))
102 _inputs_flat = _op.inputs
103 _execute.record_gradient(
104 "RaggedTensorFromVariant", _inputs_flat, _attrs, _result)
105 _result = [_result[:output_ragged_rank]] + _result[output_ragged_rank:]
106 _result = _RaggedTensorFromVariantOutput._make(_result)
107 return _result
109RaggedTensorFromVariant = tf_export("raw_ops.RaggedTensorFromVariant")(_ops.to_raw_op(ragged_tensor_from_variant))
112def ragged_tensor_from_variant_eager_fallback(encoded_ragged, input_ragged_rank, output_ragged_rank, Tvalues, Tsplits, name, ctx):
113 input_ragged_rank = _execute.make_int(input_ragged_rank, "input_ragged_rank")
114 output_ragged_rank = _execute.make_int(output_ragged_rank, "output_ragged_rank")
115 Tvalues = _execute.make_type(Tvalues, "Tvalues")
116 if Tsplits is None:
117 Tsplits = _dtypes.int64
118 Tsplits = _execute.make_type(Tsplits, "Tsplits")
119 encoded_ragged = _ops.convert_to_tensor(encoded_ragged, _dtypes.variant)
120 _inputs_flat = [encoded_ragged]
121 _attrs = ("input_ragged_rank", input_ragged_rank, "output_ragged_rank",
122 output_ragged_rank, "Tvalues", Tvalues, "Tsplits", Tsplits)
123 _result = _execute.execute(b"RaggedTensorFromVariant", output_ragged_rank +
124 1, inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
125 name=name)
126 if _execute.must_record_gradient():
127 _execute.record_gradient(
128 "RaggedTensorFromVariant", _inputs_flat, _attrs, _result)
129 _result = [_result[:output_ragged_rank]] + _result[output_ragged_rank:]
130 _result = _RaggedTensorFromVariantOutput._make(_result)
131 return _result
133_RaggedTensorToSparseOutput = collections.namedtuple(
134 "RaggedTensorToSparse",
135 ["sparse_indices", "sparse_values", "sparse_dense_shape"])
138def ragged_tensor_to_sparse(rt_nested_splits, rt_dense_values, name=None):
139 r"""Converts a `RaggedTensor` into a `SparseTensor` with the same values.
141 input=ragged.from_nested_row_splits(rt_dense_values, rt_nested_splits)
142 output=SparseTensor(indices=sparse_indices, values=sparse_values,
143 dense_shape=sparse_dense_shape)
145 Args:
146 rt_nested_splits: A list of at least 1 `Tensor` objects with the same type in: `int32`, `int64`.
147 The `row_splits` for the `RaggedTensor`.
148 rt_dense_values: A `Tensor`. The `flat_values` for the `RaggedTensor`.
149 name: A name for the operation (optional).
151 Returns:
152 A tuple of `Tensor` objects (sparse_indices, sparse_values, sparse_dense_shape).
154 sparse_indices: A `Tensor` of type `int64`.
155 sparse_values: A `Tensor`. Has the same type as `rt_dense_values`.
156 sparse_dense_shape: A `Tensor` of type `int64`.
157 """
158 _ctx = _context._context or _context.context()
159 tld = _ctx._thread_local_data
160 if tld.is_eager:
161 try:
162 _result = pywrap_tfe.TFE_Py_FastPathExecute(
163 _ctx, "RaggedTensorToSparse", name, rt_nested_splits, rt_dense_values)
164 _result = _RaggedTensorToSparseOutput._make(_result)
165 return _result
166 except _core._NotOkStatusException as e:
167 _ops.raise_from_not_ok_status(e, name)
168 except _core._FallbackException:
169 pass
170 try:
171 return ragged_tensor_to_sparse_eager_fallback(
172 rt_nested_splits, rt_dense_values, name=name, ctx=_ctx)
173 except _core._SymbolicException:
174 pass # Add nodes to the TensorFlow graph.
175 # Add nodes to the TensorFlow graph.
176 if not isinstance(rt_nested_splits, (list, tuple)):
177 raise TypeError(
178 "Expected list for 'rt_nested_splits' argument to "
179 "'ragged_tensor_to_sparse' Op, not %r." % rt_nested_splits)
180 _attr_RAGGED_RANK = len(rt_nested_splits)
181 _, _, _op, _outputs = _op_def_library._apply_op_helper(
182 "RaggedTensorToSparse", rt_nested_splits=rt_nested_splits,
183 rt_dense_values=rt_dense_values, name=name)
184 _result = _outputs[:]
185 if _execute.must_record_gradient():
186 _attrs = ("RAGGED_RANK", _op._get_attr_int("RAGGED_RANK"), "T",
187 _op._get_attr_type("T"), "Tsplits",
188 _op._get_attr_type("Tsplits"))
189 _inputs_flat = _op.inputs
190 _execute.record_gradient(
191 "RaggedTensorToSparse", _inputs_flat, _attrs, _result)
192 _result = _RaggedTensorToSparseOutput._make(_result)
193 return _result
195RaggedTensorToSparse = tf_export("raw_ops.RaggedTensorToSparse")(_ops.to_raw_op(ragged_tensor_to_sparse))
198def ragged_tensor_to_sparse_eager_fallback(rt_nested_splits, rt_dense_values, name, ctx):
199 if not isinstance(rt_nested_splits, (list, tuple)):
200 raise TypeError(
201 "Expected list for 'rt_nested_splits' argument to "
202 "'ragged_tensor_to_sparse' Op, not %r." % rt_nested_splits)
203 _attr_RAGGED_RANK = len(rt_nested_splits)
204 _attr_T, (rt_dense_values,) = _execute.args_to_matching_eager([rt_dense_values], ctx, [])
205 _attr_Tsplits, rt_nested_splits = _execute.args_to_matching_eager(list(rt_nested_splits), ctx, [_dtypes.int32, _dtypes.int64, ], _dtypes.int64)
206 _inputs_flat = list(rt_nested_splits) + [rt_dense_values]
207 _attrs = ("RAGGED_RANK", _attr_RAGGED_RANK, "T", _attr_T, "Tsplits",
208 _attr_Tsplits)
209 _result = _execute.execute(b"RaggedTensorToSparse", 3, inputs=_inputs_flat,
210 attrs=_attrs, ctx=ctx, name=name)
211 if _execute.must_record_gradient():
212 _execute.record_gradient(
213 "RaggedTensorToSparse", _inputs_flat, _attrs, _result)
214 _result = _RaggedTensorToSparseOutput._make(_result)
215 return _result
218def ragged_tensor_to_tensor(shape, values, default_value, row_partition_tensors, row_partition_types, name=None):
219 r"""Create a dense tensor from a ragged tensor, possibly altering its shape.
221 The `ragged_to_dense` op creates a dense tensor from a list of row partition
222 tensors, a value vector, and default values. If the shape is unspecified, the
223 minimal shape required to contain all the elements in the ragged tensor (the
224 natural shape) will be used. If some dimensions are left unspecified, then the
225 size of the natural shape is used in that dimension.
227 The default_value will be broadcast to the output shape. After that, the values
228 from the ragged tensor overwrite the default values. Note that the default_value
229 must have less dimensions than the value.
231 The row partition tensors are in the order of the dimensions.
232 At present, the types can be:
233 * "ROW_SPLITS": the row_splits tensor from the ragged tensor.
234 * "VALUE_ROWIDS": the value_rowids tensor from the ragged tensor.
235 * "FIRST_DIM_SIZE": if value_rowids is used for the first dimension, then it
236 is preceded by "FIRST_DIM_SIZE".
238 Args:
239 shape: A `Tensor`. Must be one of the following types: `int64`, `int32`.
240 The desired shape of the output tensor. If left unspecified (empty),
241 the minimal shape required to contain all the elements in the ragged tensor
242 (the natural shape) will be used. If some dimensions are left unspecified, then
243 the size of the natural shape is used in that dimension.
245 Note that dense dimensions cannot be modified by the shape argument. Trying to
246 change the size of a dense dimension will cause the op to fail.
247 Examples:
248 natural shape: [4, 5, 6]
249 shape: -1
250 output shape: [4, 5, 6]
252 natural shape: [4, 5, 6]
253 shape: [3, -1, 2]
254 output shape: [3, 5, 2]
256 natural shape: [4, 5, 6]
257 shape: [3, 7, 2]
258 output shape: [3, 7, 2]
259 values: A `Tensor`.
260 A 1D tensor representing the values of the ragged tensor.
261 default_value: A `Tensor`. Must have the same type as `values`.
262 The default_value when the shape is larger than the ragged tensor. The
263 default_value is broadcast until it is the shape of the output tensor, and
264 then overwritten by values in the ragged tensor. The default value must be
265 compatible with this broadcast operation, and must have fewer dimensions than
266 the value tensor.
267 row_partition_tensors: A list of at least 1 `Tensor` objects with the same type in: `int64`, `int32`.
268 row_partition_types: A list of `strings`.
269 The types of the row partition tensors. At present, these can be:
270 * "ROW_SPLITS": the row_splits tensor from the ragged tensor.
271 * "VALUE_ROWIDS": the value_rowids tensor from the ragged tensor.
272 * "FIRST_DIM_SIZE": if value_rowids is used for the first dimension, then it
273 is preceeded by "FIRST_DIM_SIZE".
274 The tensors are in the order of the dimensions.
275 name: A name for the operation (optional).
277 Returns:
278 A `Tensor`. Has the same type as `values`.
279 """
280 _ctx = _context._context or _context.context()
281 tld = _ctx._thread_local_data
282 if tld.is_eager:
283 try:
284 _result = pywrap_tfe.TFE_Py_FastPathExecute(
285 _ctx, "RaggedTensorToTensor", name, shape, values, default_value,
286 row_partition_tensors, "row_partition_types", row_partition_types)
287 return _result
288 except _core._NotOkStatusException as e:
289 _ops.raise_from_not_ok_status(e, name)
290 except _core._FallbackException:
291 pass
292 try:
293 return ragged_tensor_to_tensor_eager_fallback(
294 shape, values, default_value, row_partition_tensors,
295 row_partition_types=row_partition_types, name=name, ctx=_ctx)
296 except _core._SymbolicException:
297 pass # Add nodes to the TensorFlow graph.
298 # Add nodes to the TensorFlow graph.
299 if not isinstance(row_partition_tensors, (list, tuple)):
300 raise TypeError(
301 "Expected list for 'row_partition_tensors' argument to "
302 "'ragged_tensor_to_tensor' Op, not %r." % row_partition_tensors)
303 _attr_num_row_partition_tensors = len(row_partition_tensors)
304 if not isinstance(row_partition_types, (list, tuple)):
305 raise TypeError(
306 "Expected list for 'row_partition_types' argument to "
307 "'ragged_tensor_to_tensor' Op, not %r." % row_partition_types)
308 row_partition_types = [_execute.make_str(_s, "row_partition_types") for _s in row_partition_types]
309 _, _, _op, _outputs = _op_def_library._apply_op_helper(
310 "RaggedTensorToTensor", shape=shape, values=values,
311 default_value=default_value,
312 row_partition_tensors=row_partition_tensors,
313 row_partition_types=row_partition_types,
314 name=name)
315 _result = _outputs[:]
316 if _execute.must_record_gradient():
317 _attrs = ("T", _op._get_attr_type("T"), "Tindex",
318 _op._get_attr_type("Tindex"), "Tshape",
319 _op._get_attr_type("Tshape"), "num_row_partition_tensors",
320 _op._get_attr_int("num_row_partition_tensors"),
321 "row_partition_types", _op.get_attr("row_partition_types"))
322 _inputs_flat = _op.inputs
323 _execute.record_gradient(
324 "RaggedTensorToTensor", _inputs_flat, _attrs, _result)
325 _result, = _result
326 return _result
328RaggedTensorToTensor = tf_export("raw_ops.RaggedTensorToTensor")(_ops.to_raw_op(ragged_tensor_to_tensor))
331def ragged_tensor_to_tensor_eager_fallback(shape, values, default_value, row_partition_tensors, row_partition_types, name, ctx):
332 if not isinstance(row_partition_tensors, (list, tuple)):
333 raise TypeError(
334 "Expected list for 'row_partition_tensors' argument to "
335 "'ragged_tensor_to_tensor' Op, not %r." % row_partition_tensors)
336 _attr_num_row_partition_tensors = len(row_partition_tensors)
337 if not isinstance(row_partition_types, (list, tuple)):
338 raise TypeError(
339 "Expected list for 'row_partition_types' argument to "
340 "'ragged_tensor_to_tensor' Op, not %r." % row_partition_types)
341 row_partition_types = [_execute.make_str(_s, "row_partition_types") for _s in row_partition_types]
342 _attr_T, _inputs_T = _execute.args_to_matching_eager([values, default_value], ctx, [])
343 (values, default_value) = _inputs_T
344 _attr_Tindex, row_partition_tensors = _execute.args_to_matching_eager(list(row_partition_tensors), ctx, [_dtypes.int64, _dtypes.int32, ])
345 _attr_Tshape, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int64, _dtypes.int32, ])
346 _inputs_flat = [shape, values, default_value] + list(row_partition_tensors)
347 _attrs = ("T", _attr_T, "Tindex", _attr_Tindex, "Tshape", _attr_Tshape,
348 "num_row_partition_tensors", _attr_num_row_partition_tensors,
349 "row_partition_types", row_partition_types)
350 _result = _execute.execute(b"RaggedTensorToTensor", 1, inputs=_inputs_flat,
351 attrs=_attrs, ctx=ctx, name=name)
352 if _execute.must_record_gradient():
353 _execute.record_gradient(
354 "RaggedTensorToTensor", _inputs_flat, _attrs, _result)
355 _result, = _result
356 return _result
359def ragged_tensor_to_variant(rt_nested_splits, rt_dense_values, batched_input, name=None):
360 r"""Encodes a `RaggedTensor` into a `variant` Tensor.
363 Encodes the given `RaggedTensor` and returns a `variant` Tensor. If
364 `batched_input` is True, then input `RaggedTensor` is unbatched along the
365 zero-th dimension, each component `RaggedTensor` is encoded into a scalar
366 `variant` Tensor, and these are stacked to return a 1-D `variant` Tensor.
367 If `batched_input` is False, then the input `RaggedTensor` is encoded as is and
368 a scalar `variant` Tensor is returned. A `RaggedTensor` is encoded by first
369 creating a 1-D `variant` Tensor with `ragged_rank + 1` elements, containing the
370 splits and values Tensors of the `RaggedTensor`. Then the 1-D `variant` Tensor
371 is wrapped in a scalar `variant` Tensor. See `RaggedTensorFromVariant` for the
372 corresponding decoding logic.
374 Args:
375 rt_nested_splits: A list of `Tensor` objects with the same type in: `int32`, `int64`.
376 A list of one or more Tensors representing the splits of the input
377 `RaggedTensor`.
378 rt_dense_values: A `Tensor`.
379 A Tensor representing the values of the input `RaggedTensor`.
380 batched_input: A `bool`.
381 A `bool` denoting whether the input is a batched `RaggedTensor`.
382 name: A name for the operation (optional).
384 Returns:
385 A `Tensor` of type `variant`.
386 """
387 _ctx = _context._context or _context.context()
388 tld = _ctx._thread_local_data
389 if tld.is_eager:
390 try:
391 _result = pywrap_tfe.TFE_Py_FastPathExecute(
392 _ctx, "RaggedTensorToVariant", name, rt_nested_splits,
393 rt_dense_values, "batched_input", batched_input)
394 return _result
395 except _core._NotOkStatusException as e:
396 _ops.raise_from_not_ok_status(e, name)
397 except _core._FallbackException:
398 pass
399 try:
400 return ragged_tensor_to_variant_eager_fallback(
401 rt_nested_splits, rt_dense_values, batched_input=batched_input,
402 name=name, ctx=_ctx)
403 except _core._SymbolicException:
404 pass # Add nodes to the TensorFlow graph.
405 # Add nodes to the TensorFlow graph.
406 if not isinstance(rt_nested_splits, (list, tuple)):
407 raise TypeError(
408 "Expected list for 'rt_nested_splits' argument to "
409 "'ragged_tensor_to_variant' Op, not %r." % rt_nested_splits)
410 _attr_RAGGED_RANK = len(rt_nested_splits)
411 batched_input = _execute.make_bool(batched_input, "batched_input")
412 _, _, _op, _outputs = _op_def_library._apply_op_helper(
413 "RaggedTensorToVariant", rt_nested_splits=rt_nested_splits,
414 rt_dense_values=rt_dense_values,
415 batched_input=batched_input, name=name)
416 _result = _outputs[:]
417 if _execute.must_record_gradient():
418 _attrs = ("RAGGED_RANK", _op._get_attr_int("RAGGED_RANK"), "Tvalues",
419 _op._get_attr_type("Tvalues"), "Tsplits",
420 _op._get_attr_type("Tsplits"), "batched_input",
421 _op._get_attr_bool("batched_input"))
422 _inputs_flat = _op.inputs
423 _execute.record_gradient(
424 "RaggedTensorToVariant", _inputs_flat, _attrs, _result)
425 _result, = _result
426 return _result
428RaggedTensorToVariant = tf_export("raw_ops.RaggedTensorToVariant")(_ops.to_raw_op(ragged_tensor_to_variant))
431def ragged_tensor_to_variant_eager_fallback(rt_nested_splits, rt_dense_values, batched_input, name, ctx):
432 if not isinstance(rt_nested_splits, (list, tuple)):
433 raise TypeError(
434 "Expected list for 'rt_nested_splits' argument to "
435 "'ragged_tensor_to_variant' Op, not %r." % rt_nested_splits)
436 _attr_RAGGED_RANK = len(rt_nested_splits)
437 batched_input = _execute.make_bool(batched_input, "batched_input")
438 _attr_Tvalues, (rt_dense_values,) = _execute.args_to_matching_eager([rt_dense_values], ctx, [])
439 _attr_Tsplits, rt_nested_splits = _execute.args_to_matching_eager(list(rt_nested_splits), ctx, [_dtypes.int32, _dtypes.int64, ], _dtypes.int64)
440 _inputs_flat = list(rt_nested_splits) + [rt_dense_values]
441 _attrs = ("RAGGED_RANK", _attr_RAGGED_RANK, "Tvalues", _attr_Tvalues,
442 "Tsplits", _attr_Tsplits, "batched_input", batched_input)
443 _result = _execute.execute(b"RaggedTensorToVariant", 1, inputs=_inputs_flat,
444 attrs=_attrs, ctx=ctx, name=name)
445 if _execute.must_record_gradient():
446 _execute.record_gradient(
447 "RaggedTensorToVariant", _inputs_flat, _attrs, _result)
448 _result, = _result
449 return _result
452def ragged_tensor_to_variant_gradient(encoded_ragged_grad, row_splits, dense_values_shape, Tvalues, name=None):
453 r"""Helper used to compute the gradient for `RaggedTensorToVariant`.
455 Computes the gradient for the dense_values input to the RaggedTensorToVariant
456 op, given the variant-encoded ragged gradients of the outputs, along with
457 the outer row-splits and the shape of the dense-values that were provided as
458 inputs to the RaggedTensorToVariant op.
460 Args:
461 encoded_ragged_grad: A `Tensor` of type `variant`.
462 A `variant` Tensor containing encoded `RaggedTensor` gradients.
463 row_splits: A `Tensor`. Must be one of the following types: `int32`, `int64`.
464 Outermost row-splits that were used as input to the RaggedTensorToVariant op.
465 dense_values_shape: A `Tensor` of type `int32`.
466 Shape of the dense_values that was used as an input to the
467 RaggedTensorToVariant op.
468 Tvalues: A `tf.DType`.
469 name: A name for the operation (optional).
471 Returns:
472 A `Tensor` of type `Tvalues`.
473 """
474 _ctx = _context._context or _context.context()
475 tld = _ctx._thread_local_data
476 if tld.is_eager:
477 try:
478 _result = pywrap_tfe.TFE_Py_FastPathExecute(
479 _ctx, "RaggedTensorToVariantGradient", name, encoded_ragged_grad,
480 row_splits, dense_values_shape, "Tvalues", Tvalues)
481 return _result
482 except _core._NotOkStatusException as e:
483 _ops.raise_from_not_ok_status(e, name)
484 except _core._FallbackException:
485 pass
486 try:
487 return ragged_tensor_to_variant_gradient_eager_fallback(
488 encoded_ragged_grad, row_splits, dense_values_shape,
489 Tvalues=Tvalues, name=name, ctx=_ctx)
490 except _core._SymbolicException:
491 pass # Add nodes to the TensorFlow graph.
492 # Add nodes to the TensorFlow graph.
493 Tvalues = _execute.make_type(Tvalues, "Tvalues")
494 _, _, _op, _outputs = _op_def_library._apply_op_helper(
495 "RaggedTensorToVariantGradient", encoded_ragged_grad=encoded_ragged_grad,
496 row_splits=row_splits,
497 dense_values_shape=dense_values_shape,
498 Tvalues=Tvalues, name=name)
499 _result = _outputs[:]
500 if _execute.must_record_gradient():
501 _attrs = ("Tvalues", _op._get_attr_type("Tvalues"), "Tsplits",
502 _op._get_attr_type("Tsplits"))
503 _inputs_flat = _op.inputs
504 _execute.record_gradient(
505 "RaggedTensorToVariantGradient", _inputs_flat, _attrs, _result)
506 _result, = _result
507 return _result
509RaggedTensorToVariantGradient = tf_export("raw_ops.RaggedTensorToVariantGradient")(_ops.to_raw_op(ragged_tensor_to_variant_gradient))
512def ragged_tensor_to_variant_gradient_eager_fallback(encoded_ragged_grad, row_splits, dense_values_shape, Tvalues, name, ctx):
513 Tvalues = _execute.make_type(Tvalues, "Tvalues")
514 _attr_Tsplits, (row_splits,) = _execute.args_to_matching_eager([row_splits], ctx, [_dtypes.int32, _dtypes.int64, ], _dtypes.int64)
515 encoded_ragged_grad = _ops.convert_to_tensor(encoded_ragged_grad, _dtypes.variant)
516 dense_values_shape = _ops.convert_to_tensor(dense_values_shape, _dtypes.int32)
517 _inputs_flat = [encoded_ragged_grad, row_splits, dense_values_shape]
518 _attrs = ("Tvalues", Tvalues, "Tsplits", _attr_Tsplits)
519 _result = _execute.execute(b"RaggedTensorToVariantGradient", 1,
520 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
521 name=name)
522 if _execute.must_record_gradient():
523 _execute.record_gradient(
524 "RaggedTensorToVariantGradient", _inputs_flat, _attrs, _result)
525 _result, = _result
526 return _result