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

Function range

tensorflow/python/ops/ragged/ragged_math_ops.py:42–110  ·  view source on GitHub ↗

Returns a `RaggedTensor` containing the specified sequences of numbers. Each row of the returned `RaggedTensor` contains a single sequence: ```python ragged.range(starts, limits, deltas)[i] == tf.range(starts[i], limits[i], deltas[i]) ``` If `start[i] < limits[i] and deltas[i] > 0

(starts, limits=None, deltas=1, dtype=None,
          name=None, row_splits_dtype=dtypes.int64)

Source from the content-addressed store, hash-verified

40# pylint: disable=redefined-builtin
41@tf_export('ragged.range')
42def range(starts, limits=None, deltas=1, dtype=None,
43 name=None, row_splits_dtype=dtypes.int64):
44 """Returns a `RaggedTensor` containing the specified sequences of numbers.
45
46 Each row of the returned `RaggedTensor` contains a single sequence:
47
48 ```python
49 ragged.range(starts, limits, deltas)[i] ==
50 tf.range(starts[i], limits[i], deltas[i])
51 ```
52
53 If `start[i] < limits[i] and deltas[i] > 0`, then `output[i]` will be an
54 empty list. Similarly, if `start[i] > limits[i] and deltas[i] < 0`, then
55 `output[i]` will be an empty list. This behavior is consistent with the
56 Python `range` function, but differs from the `tf.range` op, which returns
57 an error for these cases.
58
59 Examples:
60
61 ```python
62 >>> ragged.range([3, 5, 2]).eval().tolist()
63 [[0, 1, 2], [0, 1, 2, 3, 4], [0, 1]]
64 >>> ragged.range([0, 5, 8], [3, 3, 12]).eval().tolist()
65 [[0, 1, 2], [], [8, 9, 10, 11]]
66 >>> ragged.range([0, 5, 8], [3, 3, 12], 2).eval().tolist()
67 [[0, 2], [], [8, 10]]
68 ```
69
70 The input tensors `starts`, `limits`, and `deltas` may be scalars or vectors.
71 The vector inputs must all have the same size. Scalar inputs are broadcast
72 to match the size of the vector inputs.
73
74 Args:
75 starts: Vector or scalar `Tensor`. Specifies the first entry for each range
76 if `limits` is not `None`; otherwise, specifies the range limits, and the
77 first entries default to `0`.
78 limits: Vector or scalar `Tensor`. Specifies the exclusive upper limits for
79 each range.
80 deltas: Vector or scalar `Tensor`. Specifies the increment for each range.
81 Defaults to `1`.
82 dtype: The type of the elements of the resulting tensor. If not specified,
83 then a value is chosen based on the other args.
84 name: A name for the operation.
85 row_splits_dtype: `dtype` for the returned `RaggedTensor`&#x27;s `row_splits`
86 tensor. One of `tf.int32` or `tf.int64`.
87
88 Returns:
89 A `RaggedTensor` of type `dtype` with `ragged_rank=1`.
90 """
91 row_splits_dtype = dtypes.as_dtype(row_splits_dtype)
92 if limits is None:
93 starts, limits = 0, starts
94
95 with ops.name_scope(name, 'RaggedRange', [starts, limits, deltas]) as name:
96 starts = ops.convert_to_tensor(starts, dtype=dtype, name='starts')
97 limits = ops.convert_to_tensor(limits, dtype=dtype, name='limits')
98 deltas = ops.convert_to_tensor(deltas, dtype=dtype, name='deltas')
99

Callers 15

expected_valueMethod · 0.70
testBasicRangesMethod · 0.70
testNegativeDeltasMethod · 0.70
testBroadcastMethod · 0.70
ragged_reduce_aggregateFunction · 0.70
_ragged_op_signatureFunction · 0.70
boolean_maskFunction · 0.70
_tile_ragged_valuesFunction · 0.70
_tile_ragged_splitsFunction · 0.70

Calls 3

_infer_matching_dtypeFunction · 0.85
from_row_splitsMethod · 0.80
name_scopeMethod · 0.45

Tested by 15

expected_valueMethod · 0.56
testBasicRangesMethod · 0.56
testNegativeDeltasMethod · 0.56
testBroadcastMethod · 0.56
testHighDimensionsMethod · 0.56
run_and_assert_equalMethod · 0.40
__init__Method · 0.40
lstm_model_fnFunction · 0.40
create_fc_per_eg_gradFunction · 0.40
create_lstm_per_eg_gradFunction · 0.40