Range

Range - 27

Version

  • name: Range (GitHub)

  • domain: main

  • since_version: 27

  • function: True

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 27.

Summary

Generate a tensor containing a sequence of numbers that begin at start and extends by increments of delta up to limit (exclusive).

The number of elements in the output of range is computed as below:

number_of_elements = max( ceil( (limit - start) / delta ) , 0 )

The pseudocode determining the contents of the output is shown below:

for(int i=0; i<number_of_elements; ++i) {
  output[i] =  start + (i * delta);
}

Example 1:

Inputs: start = 3, limit = 9, delta = 3
Output: [3, 6]

Example 2:

Inputs: start = 10, limit = 4, delta = -2
Output: [10, 8, 6]

For float16 and bfloat16 inputs, the stash_type attribute controls the precision used for intermediate accumulation. Setting stash_type to 1 (float) causes start, limit, and delta to be cast to 32-bit float before the loop, with the output cast back to the original type. This avoids precision loss for large ranges where successive additions in float16 or bfloat16 would otherwise be inexact (e.g. x + 1 == x for large x).

Attributes

  • stash_type - INT (default is 1):

    The data type used for intermediate computation when T is float16 or bfloat16. Defaults to 1 (float). Has no effect for other types.

Inputs

  • start (heterogeneous) - T:

    Scalar. First entry for the range of output values.

  • limit (heterogeneous) - T:

    Scalar. Exclusive upper limit for the range of output values.

  • delta (heterogeneous) - T:

    Scalar. Value to step by.

Outputs

  • output (heterogeneous) - T:

    A 1-D tensor with same type as the inputs containing generated range of values.

Type Constraints

  • T in ( tensor(bfloat16), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64) ):

    Constrain input types to common numeric type tensors.

Range - 11

Version

  • name: Range (GitHub)

  • domain: main

  • since_version: 11

  • function: True

  • support_level: SupportType.COMMON

  • shape inference: True

This version of the operator has been available since version 11.

Summary

Generate a tensor containing a sequence of numbers that begin at start and extends by increments of delta up to limit (exclusive).

The number of elements in the output of range is computed as below:

number_of_elements = max( ceil( (limit - start) / delta ) , 0 )

The pseudocode determining the contents of the output is shown below:

for(int i=0; i<number_of_elements; ++i) {
  output[i] =  start + (i * delta);
}

Example 1:

Inputs: start = 3, limit = 9, delta = 3
Output: [3, 6]

Example 2:

Inputs: start = 10, limit = 4, delta = -2
Output: [10, 8, 6]

Function Body

The function definition for this operator.

<
  domain: "",
  opset_import: ["" : 11]
>
Range (start, limit, delta) => (output)
{
   sub_result = Sub (limit, start)
   sub_result_casted = Cast <to: int = 1> (sub_result)
   delta_casted = Cast <to: int = 1> (delta)
   div_result = Div (sub_result_casted, delta_casted)
   ceil_result = Ceil (div_result)
   ceil_result_relu = Relu (ceil_result)
   ceil_result_relu_int = Cast <to: int = 7> (ceil_result_relu)
   ceil_result_relu_bool = Cast <to: int = 9> (ceil_result_relu)
   variadic_output, output = Loop (ceil_result_relu_int, ceil_result_relu_bool, start) <body: graph = loop_body_attribute (int64 i, bool cond,  prev) => ( cond_out,  current,  range) {
      cond_out = Identity (cond)
      current = Add (prev, delta)
      range = Identity (prev)
   }>
}

Inputs

  • start (heterogeneous) - T:

    Scalar. First entry for the range of output values.

  • limit (heterogeneous) - T:

    Scalar. Exclusive upper limit for the range of output values.

  • delta (heterogeneous) - T:

    Scalar. Value to step by.

Outputs

  • output (heterogeneous) - T:

    A 1-D tensor with same type as the inputs containing generated range of values.

Type Constraints

  • T in ( tensor(double), tensor(float), tensor(int16), tensor(int32), tensor(int64) ):

    Constrain input types to common numeric type tensors.