dispatch
Dispatch to a native add-on applying a nullary function.
Usage
var dispatch = require( '@stdlib/strided/base/nullary-addon-dispatch' );
dispatch( addon, fallback )
Returns a function which dispatches to a native add-on applying a nullary function.
function addon( N, dtypeX, x, strideX ) {
    // Call into native add-on...
}
function fallback( N, dtypeX, x, strideX ) {
    // Fallback JavaScript implementation...
}
// Create a dispatch function:
var f = dispatch( addon, fallback );
// ...
// Invoke the dispatch function with strided array arguments:
f( 2, 'generic', [ 1, 2 ], 1 );
The returned function has the following signature:
f( N, dtypeX, x, strideX )
where
- N: number of indexed elements.
- dtypeX: xdata type.
- x: output array.
- strideX: xstride length.
The addon function should have the following signature:
f( N, dtypeX, x, strideX )
where
- N: number of indexed elements.
- dtypeX: xdata type (enumeration constant).
- x: output array.
- strideX: xstride length.
The fallback function should have the following signature:
f( N, dtypeX, x, strideX )
where
- N: number of indexed elements.
- dtypeX: xdata type.
- x: output array.
- strideX: xstride length.
dispatch.ndarray( addon, fallback )
Returns a function which dispatches to a native add-on applying a nullary function using alternative indexing semantics.
function addon( N, dtypeX, x, strideX ) {
    // Call into native add-on...
}
function fallback( N, dtypeX, x, strideX, offsetX ) {
    // Fallback JavaScript implementation...
}
// Create a dispatch function:
var f = dispatch.ndarray( addon, fallback );
// ...
// Invoke the dispatch function with strided array arguments:
f( 2, 'generic', [ 1, 2 ], 1, 0 );
The returned function has the following signature:
f( N, dtypeX, x, strideX, offsetX )
where
- N: number of indexed elements.
- dtypeX: xdata type.
- x: output array.
- strideX: xstride length.
- offsetX: starting xindex.
The addon function should have the following signature:
f( N, dtypeX, x, strideX )
where
- N: number of indexed elements.
- dtypeX: xdata type (enumeration constant).
- x: output array.
- strideX: xstride length.
The fallback function should have the following signature:
f( N, dtypeX, x, strideX, offsetX )
where
- N: number of indexed elements.
- dtypeX: xdata type.
- x: output array.
- strideX: xstride length.
- offsetX: starting xindex.
Notes
- To determine whether to dispatch to the addonfunction, the returned dispatch function checks whether the provided arrays are typed arrays. If the provided arrays are typed arrays, the dispatch function invokes theaddonfunction; otherwise, the dispatch function invokes thefallbackfunction.
Examples
var Float64Array = require( '@stdlib/array/float64' );
var dispatch = require( '@stdlib/strided/base/nullary-addon-dispatch' );
function addon( N, dtypeX, x, strideX ) {
    console.log( x );
    // => <Float64Array>[ 3, 4 ]
}
function fallback( N, dtypeX, x, strideX, offsetX ) {
    console.log( x );
    // => [ 1, 2, 3, 4 ]
}
// Create a dispatch function:
var f = dispatch.ndarray( addon, fallback );
// Create a strided array:
var x = new Float64Array( [ 1, 2, 3, 4 ] );
// Dispatch to the add-on function:
f( 2, 'float64', x, 1, 2 );
// Define a new strided array:
x = [ 1, 2, 3, 4 ];
// Dispatch to the fallback function:
f( 2, 'generic', x, 1, 2 );