Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "map"

Index

Functions

Const mapV

  • Like mapVV, but for VecOpV type ops and hence only using single input.

    example
    // 4x 2D vectors in SOA layout
    // i.e. [x1, x2, x3, x4, y1, y2, y3, y4]
    buf = [1, 3, 5, 7, 2, 4, 6, 8];
    
    // use `swapXY` to swizzle each vector and use AOS for output
    res = mapV(swapXY, new Vec2(), new Vec2(buf, 0, 4), 4, 2, 1);
    // [ 2, 1, 4, 3, 6, 5, 8, 7 ]
    
    // unpack result for demonstration purposes
    [...Vec2.iterator(res, 4)].map(v => [...v]);
    // [ [ 2, 1 ], [ 4, 3 ], [ 6, 5 ], [ 8, 7 ] ]

    Parameters

    • op: VecOpV

      -

    • out: IVector<any>

      -

    • a: IVector<any>

      -

    • num: number

      -

    • Default value so: number = out.length * out.stride

      -

    • Default value sa: number = a.length * a.stride

      -

    Returns Vec

Const mapVN

Const mapVV

  • Vec2/3/4 view based buffer transformation for VecOpVV type ops and supporting arbitrary component and element layouts of all input and output buffers.

    remarks

    The given pre-initialized vectors MUST be separate instances, are used as sliding cursors / views of their respective backing buffers and will be modified as part of the transformation process (though the input buffers themselves are treated as immutable, unless out is configured to use one of the input buffers).

    In each iteration op is called via op(out, a, b), followed by cursor updates to process the next vector view. No bounds checking is performed.

    This function returns out's backing buffer.

    example
    // each input buffer contains 2 2D vectors, but using
    // different strided data layouts
    mapVV(
      // transformation function
      add,
      // init output buffer view
      new Vec2(),
      // wrap 1st input buffer & configure offset & component stride
      new Vec2([1,0,2,0,0,0,0,0,3,0,4,0,0,0,0,0], 0, 2),
      // wrap 2nd input buffer
      new Vec2([0,10,0,0,20,0,0,30,0,0,40], 1, 3),
      2, // num vectors
      2, // output element stride
      8, // input #1 element stride
      6  // input #2 element stride
    );
    // [ 11, 22, 33, 44 ]

    Alternatively, Vec2/3/4.iterator() combined with transducers can be used to achieve the same (and more flexible) transformations, but will incur more intermediate object allocations. mapV*() functions only use (and mutate) the provided vector instances and do not allocate any further objects.

    // output buffer
    const out = new Array(4);
    
    tx.run(
      tx.map(([o, a, b]) => add(o, a, b)),
      tx.zip(
         Vec2.iterator(out, 2),
         Vec2.iterator([1,0,2,0,0,0,0,0,3,0,4,0,0,0,0,0], 2, 0, 2, 8),
         Vec2.iterator([0,10,0,0,20,0,0,30,0,0,40], 2, 1, 3, 6),
      )
    );
    
    out
    // [ 11, 22, 33, 44 ]

    Parameters

    • op: VecOpVV

      -

    • out: IVector<any>

      -

    • a: IVector<any>

      -

    • b: IVector<any>

      -

    • num: number

      -

    • Default value so: number = out.length * out.stride

      -

    • Default value sa: number = a.length * a.stride

      -

    • Default value sb: number = b.length * b.stride

      -

    Returns Vec

Const mapVVN

  • Like mapVV, but for VecOpVVN type ops and hence using two vector input buffers a, b and a scalar n.

    Parameters

    • op: VecOpVVN

      -

    • out: IVector<any>

      -

    • a: IVector<any>

      -

    • b: IVector<any>

      -

    • n: number

      -

    • num: number

      -

    • Default value so: number = out.length * out.stride

      -

    • Default value sa: number = a.length * a.stride

      -

    • Default value sb: number = b.length * b.stride

      -

    Returns Vec

Const mapVVV

  • Like mapVV, but for VecOpVVV type ops and hence using three vector input buffers a, b, c.

    Parameters

    • op: VecOpVVV

      -

    • out: IVector<any>

      -

    • a: IVector<any>

      -

    • b: IVector<any>

      -

    • c: IVector<any>

      -

    • num: number

      -

    • Default value so: number = out.length * out.stride

      -

    • Default value sa: number = a.length * a.stride

      -

    • Default value sb: number = b.length * b.stride

      -

    • Default value sc: number = c.length * c.stride

      -

    Returns Vec

Generated using TypeDoc