Implementation:Tensorflow Tfjs CPU RaggedRange Impl
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, CPU_Backend |
| Last Updated | 2026-02-10 06:00 GMT |
Overview
The raggedRangeImpl function generates a ragged tensor from sequences defined by starts, limits, and deltas parameters. Each row of the output contains a range of values analogous to Python's range(start, limit, delta). The result is a ragged tensor represented by nested row splits and dense values.
Code Reference
Source Location
tfjs-backend-cpu/src/kernels/RaggedRange_impl.ts (GitHub)
Signature
export function raggedRangeImpl(
starts: TypedArray, startsShape: number[], startsDType: DataType,
limits: TypedArray, limitsShape: number[], deltas: TypedArray,
deltasShape: number[]): [TypedArray, TypedArray]
Imports
import {DataType, TypedArray, util} from '@tensorflow/tfjs-core';
I/O Contract
Inputs
| Name | Type | Description |
|---|---|---|
starts |
TypedArray |
Starting values for each range (scalar or 1D vector) |
startsShape |
number[] |
Shape of the starts tensor |
startsDType |
DataType |
Data type of the starts tensor (used for output dtype) |
limits |
TypedArray |
Limit values for each range (scalar or 1D vector) |
limitsShape |
number[] |
Shape of the limits tensor |
deltas |
TypedArray |
Step sizes for each range (scalar or 1D vector) |
deltasShape |
number[] |
Shape of the deltas tensor |
Output
Returns a tuple [rtNestedSplits, rtDenseValues]:
rtNestedSplits(TypedArray, int32): Row split indices of shape[nRows + 1]defining ragged row boundaries.rtDenseValues(TypedArray, same dtype as starts): Flat array of generated range values.
Algorithm
- Validates that
starts,limits, anddeltasare each scalars or 1D vectors. - Determines which inputs to broadcast (scalars are broadcast to all rows).
- Computes the number of output rows (
nRows) from the non-scalar inputs. - Builds the
rtNestedSplitsarray: for each row, computes the range size asceil(abs((limit - start) / delta)), clamped to zero for empty ranges. Enforces anINT32_MAXupper bound (2147483647). - Builds the
rtDenseValuesarray: iterates over each row, filling in values by incrementing bydeltafromstart.
Usage Example
import {raggedRangeImpl} from './RaggedRange_impl';
const starts = new Float32Array([0, 5, 8]);
const limits = new Float32Array([4, 7, 13]);
const deltas = new Float32Array([1, 1, 2]);
const [splits, values] = raggedRangeImpl(
starts, [3], 'float32',
limits, [3],
deltas, [3]);
// splits: [0, 4, 6, 9]
// values: [0, 1, 2, 3, 5, 6, 8, 10, 12]
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment