jlbun
    Preparing search index...

    Class JuliaSubArray

    Wrapper for Julia SubArray - a view into an existing array.

    SubArray provides zero-copy access to a portion of an array. Changes to a SubArray are reflected in the parent array and vice versa.

    • Zero-copy: SubArray shares memory with the parent array
    • Mutable: Changes propagate to the parent
    • Flexible indexing: Supports slices, stepped ranges, and scattered indices
    // Create a SubArray via view() on JuliaArray
    const arr = JuliaArray.from(new Float64Array([1, 2, 3, 4, 5]));
    const subArr = arr.view([1, 3]); // indices 1..3 (0-based)

    // SubArray reflects parent data
    console.log(subArr.value); // [2, 3, 4]

    // Modifications propagate to parent
    subArr.set(0, 100);
    console.log(arr.value[1]); // 100

    // Get parent array
    const parent = subArr.parent;
    // Multi-dimensional views
    const matrix = Julia.eval("reshape(Float64.(1:12), 3, 4)") as JuliaArray;
    const col1 = matrix.view(":", 0); // First column
    const row2 = matrix.view(1, ":"); // Second row
    // Nested views (view of view)
    const arr = JuliaArray.from(new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
    const sub1 = arr.view([2, 8]); // [3, 4, 5, 6, 7, 8, 9]
    const sub2 = sub1.view([1, 3]); // [4, 5, 6]

    Implements

    Index

    Constructors

    Properties

    ptr: Pointer

    Accessors

    • get fastValue(): any[]

      Get value directly from memory for contiguous numeric SubArrays.

      This is faster than value for contiguous SubArrays but only works for primitive numeric types.

      Returns any[]

    • get isContiguous(): boolean

      Check if the SubArray's memory layout is contiguous.

      Contiguous SubArrays can be more efficiently converted to TypedArrays.

      Returns boolean

    • get rawPtr(): Pointer

      Get pointer to SubArray data if contiguous.

      Warning: Only valid for contiguous SubArrays. The pointer becomes invalid if the parent array is garbage collected.

      Returns Pointer

    • get value(): any[] | BunArray

      Get the SubArray data as a JavaScript array or TypedArray.

      Note: For non-contiguous SubArrays, this collects the data first.

      Returns any[] | BunArray

    Methods

    • Fill the SubArray with a value.

      Parameters

      • value: any

        Value to fill with.

      Returns void

    • Get element at the given multi-dimensional indices (0-based).

      Parameters

      • ...indices: number[]

        Indices for each dimension.

      Returns JuliaValue

    • Set element at the given linear index (0-based).

      Changes propagate to the parent array.

      Parameters

      • index: number

        Linear index.

      • value: any

        Value to set.

      Returns void

    • Set element at the given multi-dimensional indices (0-based).

      Parameters

      • ...args: any[]

        Indices followed by the value.

      Returns void

    • Create a contiguous view (slice) of elements from start to stop (0-based, inclusive).

      Parameters

      • start: number

        Start index (0-based, inclusive).

      • stop: number

        Stop index (0-based, inclusive).

      Returns JuliaSubArray

      A new JuliaSubArray.

    • Create a view (SubArray) of this SubArray with specified indices.

      Views can be nested - a view of a view is still a valid SubArray.

      Parameters

      • ...indices: (number | [number, number] | [number, number, number] | ":")[]

        Index specifications (same as static view() method).

      Returns JuliaSubArray

      A new JuliaSubArray.

      const arr = JuliaArray.from(new Float64Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]));
      const sub1 = arr.view([2, 8]); // [3, 4, 5, 6, 7, 8, 9]
      const sub2 = sub1.view([1, 3]); // [4, 5, 6]
    • Create a contiguous view of elements from start to stop (0-based, inclusive).

      This is a convenience method for 1D array views.

      Parameters

      • array: JuliaValue

        The source 1D array.

      • start: number

        Start index (0-based, inclusive).

      • stop: number

        Stop index (0-based, inclusive).

      Returns JuliaSubArray

      A new JuliaSubArray.

    • Create a view (SubArray) of an array with specified indices.

      Parameters

      • array: JuliaValue

        The source array.

      • ...indices: (number | [number, number] | [number, number, number] | ":")[]

        Index specifications. Can be:

        • number: Single index (0-based, converted to 1-based for Julia)
        • ":": All elements in that dimension (equivalent to Julia's :)
        • [start, stop]: Range (0-based, inclusive)
        • [start, step, stop]: Stepped range (0-based)

      Returns JuliaSubArray

      A new JuliaSubArray.

      const arr = JuliaArray.from(new Float64Array([1, 2, 3, 4, 5]));

      // View elements 1..3 (0-based indices)
      const sub1 = JuliaSubArray.view(arr, [1, 3]);

      // View every other element
      const sub2 = JuliaSubArray.view(arr, [0, 2, 4]); // step=2

      // For multi-dimensional arrays
      const matrix = Julia.eval("reshape(1:12, 3, 4)");
      const sub3 = JuliaSubArray.view(matrix, ":", 0); // All rows, first column