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

Function constant

tensorflow/python/ops/ragged/ragged_factory_ops.py:37–87  ·  view source on GitHub ↗

Constructs a constant RaggedTensor from a nested Python list. Example: ```python >>> ragged.constant([[1, 2], [3], [4, 5, 6]]).eval() RaggedTensorValue(values=[1, 2, 3, 4, 5, 6], splits=[0, 2, 3, 6]) ``` All scalar values in `pylist` must have the same nesting depth `K`, and the ret

(pylist, dtype=None, ragged_rank=None, inner_shape=None,
             name=None, row_splits_dtype=dtypes.int64)

Source from the content-addressed store, hash-verified

35#===============================================================================
36@tf_export("ragged.constant")
37def constant(pylist, dtype=None, ragged_rank=None, inner_shape=None,
38 name=None, row_splits_dtype=dtypes.int64):
39 """Constructs a constant RaggedTensor from a nested Python list.
40
41 Example:
42
43 ```python
44 >>> ragged.constant([[1, 2], [3], [4, 5, 6]]).eval()
45 RaggedTensorValue(values=[1, 2, 3, 4, 5, 6], splits=[0, 2, 3, 6])
46 ```
47
48 All scalar values in `pylist` must have the same nesting depth `K`, and the
49 returned `RaggedTensor` will have rank `K`. If `pylist` contains no scalar
50 values, then `K` is one greater than the maximum depth of empty lists in
51 `pylist`. All scalar values in `pylist` must be compatible with `dtype`.
52
53 Args:
54 pylist: A nested `list`, `tuple` or `np.ndarray`. Any nested element that
55 is not a `list`, `tuple` or `np.ndarray` must be a scalar value
56 compatible with `dtype`.
57 dtype: The type of elements for the returned `RaggedTensor`. If not
58 specified, then a default is chosen based on the scalar values in
59 `pylist`.
60 ragged_rank: An integer specifying the ragged rank of the returned
61 `RaggedTensor`. Must be nonnegative and less than `K`. Defaults to
62 `max(0, K - 1)` if `inner_shape` is not specified. Defaults to `max(0, K
63 - 1 - len(inner_shape))` if `inner_shape` is specified.
64 inner_shape: A tuple of integers specifying the shape for individual inner
65 values in the returned `RaggedTensor`. Defaults to `()` if `ragged_rank`
66 is not specified. If `ragged_rank` is specified, then a default is chosen
67 based on the contents of `pylist`.
68 name: A name prefix for the returned tensor (optional).
69 row_splits_dtype: data type for the constructed `RaggedTensor`'s row_splits.
70 One of `tf.int32` or `tf.int64`.
71
72 Returns:
73 A potentially ragged tensor with rank `K` and the specified `ragged_rank`,
74 containing the values from `pylist`.
75
76 Raises:
77 ValueError: If the scalar values in `pylist` have inconsistent nesting
78 depth; or if ragged_rank or inner_shape are incompatible with `pylist`.
79 """
80 def ragged_factory(values, row_splits):
81 row_splits = constant_op.constant(row_splits, dtype=row_splits_dtype)
82 return ragged_tensor.RaggedTensor.from_row_splits(values, row_splits,
83 validate=False)
84
85 with ops.name_scope(name, "RaggedConstant"):
86 return _constant_value(ragged_factory, constant_op.constant, pylist, dtype,
87 ragged_rank, inner_shape)
88
89
90@tf_export(v1=["ragged.constant_value"])

Callers

nothing calls this directly

Calls 2

_constant_valueFunction · 0.85
name_scopeMethod · 0.45

Tested by

no test coverage detected