Category: Generation
Short description: Range operation generates a sequence of numbers according input values [start, stop) with a step.
Attributes:
Inputs:
step
is equal to zero after casting to output_type
, behavior is undefined. Required.Outputs:
Types
Detailed description:
Range operation generates a sequence of numbers starting from the value in the first input (start
) up to but not including the value in the second input (stop
) with a step
equal to the value in the third input, according to the following formula:
For a positive step
:
\[ start<=val[i]<stop, \]
for a negative step
:
\[ start>=val[i]>stop, \]
the i-th element is calculated by the following formula:
\[ val[i+1]=val[i]+step. \]
The calculations are done after casting all values to accumulate_type(output_type)
. accumulate_type
is a type that have better or equal accuracy for accumulation than output_type
on current hardware, e.g. fp64
for fp16
. The number of elements is calculated in the floating point type according to the following formula:
\[ max(ceil((end − start) / step), 0) \]
This is aligned with PyTorch's operation torch.arange
, to align with tensorflow operation tf.range
all inputs must be casted to output_type
before calling Range. The rounding for casting values are done towards zero.
Examples
Example 1: positive step
Example 2: negative step
Example 3: floating point