RAPIDS
    Preparing search index...

    Function clampRange

    • Parameters

      • len: number

        The total number of elements.

      • lhs: number = 0

        The beginning of the range to clamp.

      • rhs: number = len

        The end of the range to clamp (Default: len).

      Returns [begin: number, end: number]

      An Array of the normalized begin and end positions.

      Normalizes begin/end to between 0 and length, and wrap around on negative indices.

      import {clampRange} from '@rapidsai/cuda';

      clampRange(5) // [0, 5]
      clampRange(5, 0, -1) // [0, 4]
      clampRange(5, -1) // [4, 5]
      clampRange(5, -1, 0) // [4, 4]

      const ary = Array.from({length: 5}, (_, i) => i);

      assert(ary.slice() == ary.slice(...clampRange(ary.length)))
      // > [0, 1, 2, 3, 4]
      assert(ary.slice(0, -1) == ary.slice(...clampRange(ary.length, 0, -1)))
      // > [0, 1, 2, 3]
      assert(ary.slice(-1) == ary.slice(...clampRange(ary.length, -1)))
      // > [4]
      assert(ary.slice(-1, 0) == ary.slice(...clampRange(ary.length, -1, 0)))
      // > []