jlbun
    Preparing search index...

    Class JuliaArray

    Wrapper for Julia Array.

    Julia uses column-major order (like Fortran), meaning elements are stored column-by-column in memory. This is different from C/JavaScript which use row-major order.

    For a 2D array (matrix), elements are stored as:

    [a[0,0], a[1,0], a[2,0], ..., a[0,1], a[1,1], a[2,1], ...]
    

    Example: For a 2x3 matrix:

    Julia:  [ 1  3  5 ]    Memory layout: [1, 2, 3, 4, 5, 6]
    [ 2 4 6 ]

    C/JS: [ 1 2 3 ] Memory layout: [1, 2, 3, 4, 5, 6]
    [ 4 5 6 ]

    When using get(linearIndex) or set(linearIndex, value), the linear index follows column-major order. For multi-dimensional access, use getAt(...indices) and setAt(...indices, value) which handle the index conversion automatically.

    const matrix = JuliaArray.init(Julia.Float64, 3, 4); // 3 rows, 4 columns

    // Linear indexing (column-major)
    matrix.set(0, 1.0); // Sets element at row 0, col 0
    matrix.set(1, 2.0); // Sets element at row 1, col 0
    matrix.set(3, 4.0); // Sets element at row 0, col 1

    // Multi-dimensional indexing (more intuitive)
    matrix.setAt(0, 0, 1.0); // row 0, col 0
    matrix.setAt(1, 0, 2.0); // row 1, col 0
    matrix.setAt(0, 1, 4.0); // row 0, col 1

    // Get element at row 2, col 3
    const val = matrix.getAt(2, 3);

    Implements

    Index

    Constructors

    Properties

    ptr: Pointer

    Accessors

    • get ndims(): number

      Number of dimensions of the array.

      Returns number

    • get rawPtr(): Pointer

      Get the raw pointer of the array.

      Returns Pointer

    • get size(): number[]

      Size (equivalent to shape in numpy's terms) of the array.

      Returns number[]

    Methods

    • Create a copy of this array.

      The copy is independent - changes to the copy do not affect the original.

      Returns JuliaArray

      A new JuliaArray with the same data.

    • Fill the array with the given value.

      Parameters

      • value: any

        Value to be filled.

      Returns void

    • Get data at the given linear index (column-major order).

      For multi-dimensional arrays, consider using getAt(...indices) for more intuitive access.

      Parameters

      • index: number

        The linear index (starting from 0) to be fetched.

      Returns JuliaValue

      Julia data at the given index, wrapped in a JuliaValue object.

    • Get data at the given multi-dimensional indices.

      Indices are 0-based and follow Julia's column-major convention. For a 2D matrix, use getAt(row, col).

      Parameters

      • ...indices: number[]

        The indices for each dimension (all 0-based).

      Returns JuliaValue

      Julia data at the given position, wrapped in a JuliaValue object.

      const matrix = JuliaArray.init(Julia.Float64, 3, 4); // 3 rows, 4 cols
      const val = matrix.getAt(2, 3); // Get element at row 2, col 3

      const tensor = JuliaArray.init(Julia.Float64, 2, 3, 4);
      const val3d = tensor.getAt(1, 2, 3); // 3D indexing
    • Parameters

      • ...values: any[]

      Returns number

    • Reshape the array with the given shape and get a new array.

      Note that the new array shares the underlying memory with the original array. So if you have reshaped an array, you cannot perform pop() or push() operations on it since this will affect the arrays that share data with the current array.

      Parameters

      • ...shape: number[]

      Returns JuliaArray

    • Set data at the given linear index (column-major order).

      For multi-dimensional arrays, consider using setAt(...indices, value) for more intuitive access.

      Parameters

      • index: number

        The linear index (starting from 0).

      • value: any

        Data to be set at the given index.

      Returns void

    • Set data at the given multi-dimensional indices.

      Indices are 0-based and follow Julia's column-major convention. For a 2D matrix, use setAt(row, col, value).

      Parameters

      • ...args: any[]

        The indices for each dimension followed by the value to set. For an N-dimensional array, pass N indices then the value.

      Returns void

      const matrix = JuliaArray.init(Julia.Float64, 3, 4); // 3 rows, 4 cols
      matrix.setAt(2, 3, 42.0); // Set element at row 2, col 3 to 42.0

      const tensor = JuliaArray.init(Julia.Float64, 2, 3, 4);
      tensor.setAt(1, 2, 3, 99.0); // 3D indexing
    • Create a contiguous view (slice) of elements from start to stop (0-based, inclusive).

      This is a convenience method for 1D array views.

      Parameters

      • start: number

        Start index (0-based, inclusive).

      • stop: number

        Stop index (0-based, inclusive).

      Returns JuliaSubArray

      A new JuliaSubArray.

      const arr = JuliaArray.from(new Float64Array([10, 20, 30, 40, 50]));
      const sub = arr.slice(1, 3); // [20, 30, 40]

      sub.set(0, 100);
      console.log(arr.get(1).value); // 100 (modification propagates)
    • Create a view (SubArray) of this array with specified indices.

      Views share memory with the parent array - changes to the view are reflected in the parent and vice versa.

      Parameters

      • ...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 = arr.view([1, 3]);

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

      // For multi-dimensional arrays
      const matrix = Julia.eval("reshape(Float64.(1:12), 3, 4)") as JuliaArray;
      const col = matrix.view(":", 0); // All rows, first column
    • Create a JuliaArray with given element type and dimensions.

      Parameters

      • elType: JuliaDataType

        Element type of the array.

      • ...dims: number[]

        Dimensions of the array. For 1D array, pass a single number. For multi-dimensional arrays, pass multiple numbers.

      Returns JuliaArray

      // 1D array with 100 elements
      const arr1d = JuliaArray.init(Julia.Float64, 100);

      // 2D array (10x20 matrix)
      const arr2d = JuliaArray.init(Julia.Float64, 10, 20);

      // 3D array (10x20x30)
      const arr3d = JuliaArray.init(Julia.Float64, 10, 20, 30);

      // N-dimensional array
      const arrNd = JuliaArray.init(Julia.Float64, 2, 3, 4, 5);