Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:Tensorflow Tfjs CPU RaggedRange Impl

From Leeroopedia


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

  1. Validates that starts, limits, and deltas are each scalars or 1D vectors.
  2. Determines which inputs to broadcast (scalars are broadcast to all rows).
  3. Computes the number of output rows (nRows) from the non-scalar inputs.
  4. Builds the rtNestedSplits array: for each row, computes the range size as ceil(abs((limit - start) / delta)), clamped to zero for empty ranges. Enforces an INT32_MAX upper bound (2147483647).
  5. Builds the rtDenseValues array: iterates over each row, filling in values by incrementing by delta from start.

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