.. _op_ai_onnx_Range: Range ===== - **Domain**: ``ai.onnx`` - **Since version**: 27 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: .. code-block:: number_of_elements = max( ceil( (limit - start) / delta ) , 0 ) The pseudocode determining the contents of the output is shown below: .. code-block:: for(int i=0; i (output) .. code-block:: text Inputs: start: shape=(), dtype=bfloat16 1 limit: shape=(), dtype=bfloat16 5 delta: shape=(), dtype=bfloat16 2 Outputs: output: shape=(2,), dtype=bfloat16 [1, 3] **test_range_float16_type_positive_delta** .. code-block:: text Node: Range(start, limit, delta) -> (output) .. code-block:: text Inputs: start: shape=(), dtype=float16 1. limit: shape=(), dtype=float16 5. delta: shape=(), dtype=float16 2. Outputs: output: shape=(2,), dtype=float16 [1., 3.] Differences with previous version (11) -------------------------------------- **SchemaDiff**: ``Range`` (domain ``'ai.onnx'``) * old version: 11 * new version: 27 * breaking: no **Attributes:** * added 'stash_type': type=INT; required=False; default=1 **Type constraints:** * changed 'T': added types: ['tensor(bfloat16)', 'tensor(float16)'] **Documentation:** * line similarity: 0.91 (+6/-0 lines) .. code-block:: diff --- Range v11 +++ Range v27 @@ -29,3 +29,9 @@ 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`). Version History --------------- - :doc:`Version 11 `