@stdlib/strided
Version:
Strided.
171 lines (129 loc) • 5.43 kB
Plain Text
{{alias}}( N, x, sx, y, sy, z, sz, fcn, clbk[, thisArg] )
Applies a binary function to each pair of elements retrieved from strided
input arrays according to a callback function and assigns results to a
strided output array.
The `N` and stride parameters determine which elements in the strided arrays
are accessed at runtime.
Indexing is relative to the first index. To introduce an offset, use typed
array views.
The callback function is provided four arguments:
- values: input array elements.
- idx: iteration index.
- indices: strided array indices (offset + idx*stride).
- arrays: input and output arrays.
If the callback function does not return any value (or equivalently,
explicitly returns `undefined`), the value is ignored.
Parameters
----------
N: integer
Number of indexed elements.
x: Array|TypedArray|Object
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).
sx: integer
Index increment for `x`.
y: Array|TypedArray|Object
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).
sy: integer
Index increment for `y`.
z: Array|TypedArray|Object
Destination array/collection. If provided an object, the object must be
array-like (excluding strings and functions).
sz: integer
Index increment for `z`.
fcn: Function
Binary function to apply to callback return values.
clbk: Function
Callback function which returns an array-like object containing two
values.
thisArg: any (optional)
Callback execution context.
Returns
-------
z: Array|TypedArray|Object
Destination array/collection.
Examples
--------
// Standard usage:
> var x = [ 1.0, -2.0, 3.0, -4.0 ];
> var y = [ 1.0, 1.0, 2.0, 2.0 ];
> var z = [ 0.0, 0.0, 0.0, 0.0 ];
> function clbk( v ) { v[0] *= 2.0; v[1] *= 2.0; return v; };
> {{alias}}( x.length, x, 1, y, 1, z, 1, {{alias:/math/base/ops/add}}, clbk )
[ 4.0, -2.0, 10.0, -4.0 ]
// Using `N` and stride parameters:
> z = [ 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}( 2, x, 2, y, -1, z, -1, {{alias:/math/base/ops/add}}, clbk )
[ 8.0, 4.0, 0.0, 0.0 ]
// Using view offsets:
> var x0 = new {{alias:/array/float64}}( [ 1.0, -2.0, 3.0, -4.0 ] );
> var y0 = new {{alias:/array/float64}}( [ 1.0, 1.0, 2.0, 2.0 ] );
> var z0 = new {{alias:/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] );
> var x1 = new {{alias:/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:/array/float64}}( y0.buffer, y0.BYTES_PER_ELEMENT*2 );
> var z1 = new {{alias:/array/float64}}( z0.buffer, z0.BYTES_PER_ELEMENT*2 );
> {{alias}}( 2, x1, -2, y1, 1, z1, 1, {{alias:/math/base/ops/add}}, clbk )
<Float64Array>[ -4.0, 0.0 ]
> z0
<Float64Array>[ 0.0, 0.0, -4.0, 0.0 ]
{{alias}}.ndarray( N, x, sx, ox, y, sy, oy, z, sz, oz, fcn, clbk[, thisArg] )
Applies a binary function to each pair of elements retrieved from strided
input arrays according to a callback function and assigns results to a
strided output array using alternative indexing semantics.
While typed array views mandate a view offset based on the underlying
buffer, the offsest parameters support indexing semantics
based on starting indices.
Parameters
----------
N: integer
Number of indexed elements.
x: Array|TypedArray|Object
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).
sx: integer
Index increment for `x`.
ox: integer
Starting index for `x`.
y: Array|TypedArray|Object
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).
sy: integer
Index increment for `y`.
oy: integer
Starting index for `y`.
z: Array|TypedArray|Object
Destination array/collection. If provided an object, the object must be
array-like (excluding strings and functions).
sz: integer
Index increment for `z`.
oz: integer
Starting index for `z`.
fcn: Function
Binary function to apply to callback return values.
clbk: Function
Callback function which returns an array-like object containing two
values.
thisArg: any (optional)
Callback execution context.
Returns
-------
z: Array|TypedArray|Object
Destination array/collection.
Examples
--------
// Standard usage:
> var x = [ 1.0, -2.0, 3.0, -4.0 ];
> var y = [ 1.0, 1.0, 2.0, 2.0 ];
> var z = [ 0.0, 0.0, 0.0, 0.0 ];
> function clbk( v ) { v[0] *= 2.0; v[1] *= 2.0; return v; };
> {{alias}}.ndarray( 4, x, 1, 0, y, 1, 0, z, 1, 0, {{alias:/math/base/ops/add}}, clbk )
[ 4.0, -2.0, 10.0, -4.0 ]
// Advanced indexing:
> x = [ 1.0, -2.0, 3.0, -4.0 ];
> y = [ 1.0, 1.0, 2.0, 2.0 ];
> z = [ 0.0, 0.0, 0.0, 0.0 ];
> {{alias}}.ndarray( 2, x, 2, 1, y, -1, 3, z, 1, 0, {{alias:/math/base/ops/add}}, clbk )
[ 0.0, -4.0, 0.0, 0.0 ]
See Also
--------