UNPKG

@stdlib/strided

Version:
179 lines (141 loc) 5.1 kB
{{alias}}( addon, fallback ) Returns a function which dispatches to a native add-on applying a unary function to an input strided array according to a mask strided array. The returned function has the following signature: f( N, dx, x, sx, dm, m, sm, dy, y, sy ) where - N: number of indexed elements. - dx: `x` data type. - x: input array. - sx: `x` stride length. - dm: `m` data type. - m: mask array. - sm: `m` stride length. - dy: `y` data type. - y: output array. - sy: `y` stride length. To determine whether to dispatch to the `addon` function, the returned dispatch function checks whether the provided arrays are typed arrays. If the provided arrays are typed arrays, the dispatch function invokes the `addon` function; otherwise, the dispatch function invokes the `fallback` function. Parameters ---------- addon: Function Add-on interface. The function should have the following signature: f( N, dx, x, sx, dy, y, sy ) where - N: number of indexed elements. - dx: `x` data type (enumeration constant). - x: input array. - sx: `x` stride length. - dm: `m` data type (enumeration constant). - m: mask array. - sm: `m` stride length. - dy: `y` data type (enumeration constant). - y: output array. - sy: `y` stride length. fallback: Function Fallback function. The function should have the following signature: f( N, dx, x, sx, dy, y, sy ) where - N: number of indexed elements. - dx: `x` data type. - x: input array. - sx: `x` stride length. - dm: `m` data type. - m: mask array. - sm: `m` stride length. - dy: `y` data type. - y: output array. - sy: `y` stride length. Returns ------- fcn: Function Dispatch function. Examples -------- > function addon( N, dx, x, sx, dm, m, sm, dy, y, sy ) { ... // Call into native add-on... ... }; > function fallback( N, dx, x, sx, dm, m, sm, dy, y, sy ) { ... // Fallback JavaScript implementation... ... }; > var f = {{alias}}( addon, fallback ); > var dt = 'generic'; > f( 2, dt, [ 1, 2 ], 1, dt, [ 0, 0 ], 1, dt, [ 0, 0 ], 1 ); {{alias}}.ndarray( addon, fallback ) Returns a function which dispatches to a native add-on applying a unary function to an input strided array according to a mask strided array using alternative indexing semantics. The returned function has the following signature: f( N, dx, x, sx, ox, dm, m, sm, om, dy, y, sy, oy ) where - N: number of indexed elements. - dx: `x` data type. - x: input array. - sx: `x` stride length. - ox: starting `x` index. - dm: `mask` data type. - m: mask array. - sm: `m` stride length. - om: starting `m` index. - dy: `y` data type. - y: output array. - sy: `y` stride length. - oy: starting `y` index. To determine whether to dispatch to the `addon` function, the returned dispatch function checks whether the provided arrays are typed arrays. If the provided arrays are typed arrays, the dispatch function invokes the `addon` function; otherwise, the dispatch function invokes the `fallback` function. Parameters ---------- addon: Function Add-on interface. The function should have the following signature: f( N, dx, x, sx, dm, m, sm, dy, y, sy ) where - N: number of indexed elements. - dx: `x` data type (enumeration constant). - x: input array. - sx: `x` stride length. - dm: `mask` data type (enumeration constant). - m: mask array. - sm: `m` stride length. - dy: `y` data type (enumeration constant). - y: output array. - sy: `y` stride length. fallback: Function Fallback function. The function should have the following signature: f( N, dx, x, sx, ox, dm, m, sm, om, dy, y, sy, oy ) where - N: number of indexed elements. - dx: `x` data type. - x: input array. - sx: `x` stride length. - ox: starting `x` index. - dm: `mask` data type. - m: mask array. - sm: `m` stride length. - om: starting `m` index. - dy: `y` data type. - y: output array. - sy: `y` stride length. - oy: starting `y` index. Returns ------- fcn: Function Dispatch function. Examples -------- > function addon( N, dx, x, sx, dm, m, sm, dy, y, sy ) { ... // Call into native add-on... ... }; > function fallback( N, dx, x, sx, ox, dm, m, sm, om, dy, y, sy ) { ... // Fallback JavaScript implementation... ... }; > var f = {{alias}}.ndarray( addon, fallback ); > var dt = 'generic'; > f( 2, dt, [ 1, 2 ], 1, 0, dt, [ 0, 0 ], 1, 0, dt, [ 0, 0 ], 1, 0 ); See Also --------