From 7ef824084570fb099679007247bd41017dffc249 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 3 Oct 2026 00:14:34 +0500 Subject: [PATCH] feat: add ndarray/base/kernels/generic/quinary/linear --- .../kernels/generic/quinary/linear/README.md | 376 ++++++++++++++++++ .../quinary/linear/benchmark/benchmark.js | 165 ++++++++ .../generic/quinary/linear/docs/repl.txt | 66 +++ .../generic/quinary/linear/examples/index.js | 97 +++++ .../generic/quinary/linear/lib/index.js | 125 ++++++ .../generic/quinary/linear/lib/main.js | 127 ++++++ .../kernels/generic/quinary/linear/lib/nd.js | 253 ++++++++++++ .../generic/quinary/linear/package.json | 64 +++ .../generic/quinary/linear/test/test.js | 85 ++++ 9 files changed, 1358 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/README.md new file mode 100644 index 000000000000..7e477f641859 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/README.md @@ -0,0 +1,376 @@ + + +# kernel + +> Return a kernel for applying a quinary callback to elements in five input ndarrays and assigning results to elements in an output ndarray using linear view iteration. + +
+ +
+ + + +
+ +## Usage + +```javascript +var kernel = require( '@stdlib/ndarray/base/kernels/generic/quinary/linear' ); +``` + +#### kernel( ndims ) + +Returns a kernel for applying a quinary callback to elements in five input ndarrays and assigning results to elements in an output ndarray using linear view iteration. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var add5 = require( '@stdlib/number/float64/base/add5' ); + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var vbuf = new Float64Array( 6 ); + +// Define the shape of the input and output arrays: +var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; + +// Define the array strides: +var sx = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sy = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sz = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sw = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var su = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sv = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; + +// Create the input and output ndarray-like objects: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': sx, + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': shape, + 'strides': sy, + 'offset': 0, + 'order': 'row-major' +}; +var z = { + 'dtype': 'float64', + 'data': zbuf, + 'shape': shape, + 'strides': sz, + 'offset': 0, + 'order': 'row-major' +}; +var w = { + 'dtype': 'float64', + 'data': wbuf, + 'shape': shape, + 'strides': sw, + 'offset': 0, + 'order': 'row-major' +}; +var u = { + 'dtype': 'float64', + 'data': ubuf, + 'shape': shape, + 'strides': su, + 'offset': 0, + 'order': 'row-major' +}; +var v = { + 'dtype': 'float64', + 'data': vbuf, + 'shape': shape, + 'strides': sv, + 'offset': 0, + 'order': 'row-major' +}; + +// Resolve a kernel: +var f = kernel( 13 ); + +// Apply the quinary function: +f( x, y, z, w, u, v, add5 ); + +var arr = ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ); +// returns [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +``` + +The function accepts the following arguments: + +- **ndims**: number of dimensions. + +If the function is provided an `ndims` value less than `0`, the function returns `null`. + +```javascript +var f = kernel( -1 ); +// returns null +``` + +The returned function accepts the following arguments: + +- **x**: first input ndarray descriptor (object with `dtype`, `data`, `shape`, `strides`, `offset`, `order`). +- **y**: second input ndarray descriptor. +- **z**: third input ndarray descriptor. +- **w**: fourth input ndarray descriptor. +- **u**: fifth input ndarray descriptor. +- **v**: output ndarray descriptor. +- **fcn**: quinary callback accepting five scalar values and returning one scalar value. + +The returned function iterates over ndarray elements according to the linear **view** index, regardless as to how the data is stored in memory. + +#### kernel.nd( x, y, z, w, u, v, fcn ) + +Applies a quinary callback to elements in n-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray using linear view iteration. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var add5 = require( '@stdlib/number/float64/base/add5' ); + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var vbuf = new Float64Array( 6 ); + +// Define the shape of the input and output arrays: +var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; + +// Define the array strides: +var sx = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sy = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sz = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sw = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var su = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +var sv = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; + +// Create the input and output ndarray-like objects: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': sx, + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': shape, + 'strides': sy, + 'offset': 0, + 'order': 'row-major' +}; +var z = { + 'dtype': 'float64', + 'data': zbuf, + 'shape': shape, + 'strides': sz, + 'offset': 0, + 'order': 'row-major' +}; +var w = { + 'dtype': 'float64', + 'data': wbuf, + 'shape': shape, + 'strides': sw, + 'offset': 0, + 'order': 'row-major' +}; +var u = { + 'dtype': 'float64', + 'data': ubuf, + 'shape': shape, + 'strides': su, + 'offset': 0, + 'order': 'row-major' +}; +var v = { + 'dtype': 'float64', + 'data': vbuf, + 'shape': shape, + 'strides': sv, + 'offset': 0, + 'order': 'row-major' +}; + +// Apply the quinary function: +kernel.nd( x, y, z, w, u, v, add5 ); + +var arr = ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ); +// returns [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **x**: first input ndarray descriptor (object with `dtype`, `data`, `shape`, `strides`, `offset`, `order`). +- **y**: second input ndarray descriptor. +- **z**: third input ndarray descriptor. +- **w**: fourth input ndarray descriptor. +- **u**: fifth input ndarray descriptor. +- **v**: output ndarray descriptor. +- **fcn**: quinary callback accepting five scalar values and returning one scalar value. + +
+ + + +
+ +## Notes + +- The quinary callback is expected to have the following signature: + + ```text + fcn( v1, v2, v3, v4, v5 ) + ``` + + where + + - **v1**: element from the first input ndarray. + - **v2**: element from the second input ndarray. + - **v3**: element from the third input ndarray. + - **v4**: element from the fourth input ndarray. + - **v5**: element from the fifth input ndarray. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var add5 = require( '@stdlib/number/float64/base/add5' ); +var kernel = require( '@stdlib/ndarray/base/kernels/generic/quinary/linear' ); + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var vbuf = new Float64Array( 6 ); + +// Define the array shapes: +var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; + +// Create the input and output ndarray-like objects: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': shape, + 'strides': [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var z = { + 'dtype': 'float64', + 'data': zbuf, + 'shape': shape, + 'strides': [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var w = { + 'dtype': 'float64', + 'data': wbuf, + 'shape': shape, + 'strides': [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var u = { + 'dtype': 'float64', + 'data': ubuf, + 'shape': shape, + 'strides': [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; +var v = { + 'dtype': 'float64', + 'data': vbuf, + 'shape': shape, + 'strides': [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Resolve a kernel: +var f = kernel( 13 ); + +// Apply the quinary function: +f( x, y, z, w, u, v, add5 ); + +console.log( ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ) ); +// => [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/benchmark/benchmark.js new file mode 100644 index 000000000000..dc7e8b83f0e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/benchmark/benchmark.js @@ -0,0 +1,165 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var cbrt = require( '@stdlib/math/base/special/cbrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var filledarray = require( '@stdlib/array/filled' ); +var add5 = require( '@stdlib/number/float64/base/add5' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var descriptor = require( '@stdlib/ndarray/base/descriptor' ); +var orders = require( '@stdlib/ndarray/orders' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var kernel = require( './../lib' ); + + +// VARIABLES // + +var TYPES = [ + 'float64' +]; +var ORDERS = orders(); + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} vtype - output ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, vtype, order ) { + var opts; + var st; + var x; + var y; + var z; + var w; + var u; + var v; + var f; + + st = shape2strides( shape, order ); + opts = { + 'dtype': xtype + }; + x = discreteUniform( len, -100, 100, opts ); + y = discreteUniform( len, -100, 100, opts ); + z = discreteUniform( len, -100, 100, opts ); + w = discreteUniform( len, -100, 100, opts ); + u = discreteUniform( len, -100, 100, opts ); + v = filledarray( 0.0, len, vtype ); + + x = descriptor( xtype, x, shape, st, strides2offset( shape, st ), order ); + y = descriptor( xtype, y, shape, st, strides2offset( shape, st ), order ); + z = descriptor( xtype, z, shape, st, strides2offset( shape, st ), order ); + w = descriptor( xtype, w, shape, st, strides2offset( shape, st ), order ); + u = descriptor( xtype, u, shape, st, strides2offset( shape, st ), order ); + v = descriptor( vtype, v, shape, st, strides2offset( shape, st ), order ); + + f = kernel( shape.length ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + f( x, y, z, w, u, v, add5 ); + if ( isnan( v.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( v.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var ord; + var sh; + var t1; + var t2; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < ORDERS.length; k++ ) { + ord = ORDERS[ k ]; + for ( j = 0; j < TYPES.length; j++ ) { + t1 = TYPES[ j ]; + t2 = TYPES[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, len/2, 2, 1 ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,vorder=%s,xtype=%s,vtype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,vorder=%s,xtype=%s,vtype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + + len = floor( cbrt( len ) ); + sh = [ 1, 1, 1, 1, 1, 1, 1, 1, len, len, len ]; + len *= len * len; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( format( '%s:ndims=%d,len=%d,shape=[%s],xorder=%s,vorder=%s,xtype=%s,vtype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/docs/repl.txt new file mode 100644 index 000000000000..17a1c25a6d7f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/docs/repl.txt @@ -0,0 +1,66 @@ + +{{alias}}( ndims ) + Returns a kernel for applying a quinary callback to elements in five input + ndarrays and assigning results to elements in an output ndarray using linear + view iteration. + + The returned function has the following parameters: + + - x: first input ndarray descriptor (object with `dtype`, `data`, `shape`, + `strides`, `offset`, `order`). + - y: second input ndarray descriptor. + - z: third input ndarray descriptor. + - w: fourth input ndarray descriptor. + - u: fifth input ndarray descriptor. + - v: output ndarray descriptor. + - fcn: quinary callback accepting five scalar values and returning one + scalar value. + + If `ndims` is less than `0`, the function returns `null`. + + Parameters + ---------- + ndims: integer + Number of dimensions. + + Returns + ------- + fcn: Function|null + Kernel function. + + Examples + -------- + > var f = {{alias}}( 13 ) + + + +{{alias}}.nd( x, y, z, w, u, v, fcn ) + Applies a quinary callback to elements in n-dimensional input ndarrays and + assigns results to elements in an equivalently shaped output ndarray using + linear view iteration. + + Parameters + ---------- + x: Object + First input ndarray descriptor. + + y: Object + Second input ndarray descriptor. + + z: Object + Third input ndarray descriptor. + + w: Object + Fourth input ndarray descriptor. + + u: Object + Fifth input ndarray descriptor. + + v: Object + Output ndarray descriptor. + + fcn: Function + Quinary callback. + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/examples/index.js new file mode 100644 index 000000000000..e32486ee702b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/examples/index.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var add5 = require( '@stdlib/number/float64/base/add5' ); +var kernel = require( './../lib' ); + +// Create data buffers: +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +var vbuf = new Float64Array( 6 ); + +// Define the array shapes: +var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; + +// Define the array strides: +var strides = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; + +// Create the input and output ndarray-like objects: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': shape, + 'strides': strides, + 'offset': 0, + 'order': 'row-major' +}; +var y = { + 'dtype': 'float64', + 'data': ybuf, + 'shape': shape, + 'strides': strides, + 'offset': 0, + 'order': 'row-major' +}; +var z = { + 'dtype': 'float64', + 'data': zbuf, + 'shape': shape, + 'strides': strides, + 'offset': 0, + 'order': 'row-major' +}; +var w = { + 'dtype': 'float64', + 'data': wbuf, + 'shape': shape, + 'strides': strides, + 'offset': 0, + 'order': 'row-major' +}; +var u = { + 'dtype': 'float64', + 'data': ubuf, + 'shape': shape, + 'strides': strides, + 'offset': 0, + 'order': 'row-major' +}; +var v = { + 'dtype': 'float64', + 'data': vbuf, + 'shape': shape, + 'strides': strides, + 'offset': 0, + 'order': 'row-major' +}; + +// Resolve a kernel: +var f = kernel( 13 ); + +// Apply the quinary function: +f( x, y, z, w, u, v, add5 ); + +console.log( ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ) ); +// => [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/index.js new file mode 100644 index 000000000000..58527b66742f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/index.js @@ -0,0 +1,125 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a kernel for applying a quinary callback to elements in five input ndarrays and assigning results to elements in an output ndarray using linear view iteration. +* +* @module @stdlib/ndarray/base/kernels/generic/quinary/linear +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var add5 = require( '@stdlib/number/float64/base/add5' ); +* var kernel = require( '@stdlib/ndarray/base/kernels/generic/quinary/linear' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var vbuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sy = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sz = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sw = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var su = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sv = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var v = { +* 'dtype': 'float64', +* 'data': vbuf, +* 'shape': shape, +* 'strides': sv, +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Resolve a kernel: +* var f = kernel( 13 ); +* +* // Apply the quinary function: +* f( x, y, z, w, u, v, add5 ); +* +* var arr = ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var nd = require( './nd.js' ); +var main = require( './main.js' ); + + +// MAIN // + +setReadOnly( main, 'nd', nd ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/main.js new file mode 100644 index 000000000000..fd905b9380a6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/main.js @@ -0,0 +1,127 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var quinarynd = require( './nd.js' ); + + +// MAIN // + +/** +* Returns a kernel for applying a quinary callback to elements in five input ndarrays and assigning results to elements in an output ndarray using linear view iteration. +* +* @param {integer} ndims - number of dimensions +* @returns {(Function|null)} kernel function or null +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var add5 = require( '@stdlib/number/float64/base/add5' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var vbuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sy = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sz = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sw = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var su = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sv = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': 0, +* 'order': 'row-major' +* }; +* var v = { +* 'dtype': 'float64', +* 'data': vbuf, +* 'shape': shape, +* 'strides': sv, +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Resolve a kernel: +* var f = kernel( 13 ); +* +* // Apply the quinary function: +* f( x, y, z, w, u, v, add5 ); +* +* var arr = ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +*/ +function kernel( ndims ) { + if ( ndims <= 0 ) { + return null; + } + return quinarynd; +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/nd.js new file mode 100644 index 000000000000..1a9afe52ddf0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/lib/nd.js @@ -0,0 +1,253 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); + + +// MAIN // + +/** +* Applies a quinary callback to elements in n-dimensional input ndarrays and assigns results to elements in an equivalently shaped output ndarray via linear view iteration. +* +* @private +* @param {Object} x - object containing input ndarray meta data +* @param {*} x.dtype - data type +* @param {Collection} x.data - data buffer +* @param {NonNegativeIntegerArray} x.shape - dimensions +* @param {IntegerArray} x.strides - stride lengths +* @param {NonNegativeInteger} x.offset - index offset +* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} y - object containing input ndarray meta data +* @param {*} y.dtype - data type +* @param {Collection} y.data - data buffer +* @param {NonNegativeIntegerArray} y.shape - dimensions +* @param {IntegerArray} y.strides - stride lengths +* @param {NonNegativeInteger} y.offset - index offset +* @param {string} y.order - specifies whether `y` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} z - object containing input ndarray meta data +* @param {*} z.dtype - data type +* @param {Collection} z.data - data buffer +* @param {NonNegativeIntegerArray} z.shape - dimensions +* @param {IntegerArray} z.strides - stride lengths +* @param {NonNegativeInteger} z.offset - index offset +* @param {string} z.order - specifies whether `z` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} w - object containing input ndarray meta data +* @param {*} w.dtype - data type +* @param {Collection} w.data - data buffer +* @param {NonNegativeIntegerArray} w.shape - dimensions +* @param {IntegerArray} w.strides - stride lengths +* @param {NonNegativeInteger} w.offset - index offset +* @param {string} w.order - specifies whether `w` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} u - object containing input ndarray meta data +* @param {*} u.dtype - data type +* @param {Collection} u.data - data buffer +* @param {NonNegativeIntegerArray} u.shape - dimensions +* @param {IntegerArray} u.strides - stride lengths +* @param {NonNegativeInteger} u.offset - index offset +* @param {string} u.order - specifies whether `u` is row-major (C-style) or column-major (Fortran-style) +* @param {Object} v - object containing output ndarray meta data +* @param {*} v.dtype - data type +* @param {Collection} v.data - data buffer +* @param {NonNegativeIntegerArray} v.shape - dimensions +* @param {IntegerArray} v.strides - stride lengths +* @param {NonNegativeInteger} v.offset - index offset +* @param {string} v.order - specifies whether `v` is row-major (C-style) or column-major (Fortran-style) +* @param {Callback} fcn - quinary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var add5 = require( '@stdlib/number/float64/base/add5' ); +* +* // Create data buffers: +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* var ybuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var zbuf = new Float64Array( [ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0 ] ); +* var wbuf = new Float64Array( [ 3.0, 3.0, 3.0, 3.0, 3.0, 3.0 ] ); +* var ubuf = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); +* var vbuf = new Float64Array( 6 ); +* +* // Define the shape of the input and output arrays: +* var shape = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sy = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sz = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sw = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var su = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* var sv = [ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 1 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 0; +* var ov = 0; +* +* // Create the input and output ndarray-like objects: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': shape, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* var y = { +* 'dtype': 'float64', +* 'data': ybuf, +* 'shape': shape, +* 'strides': sy, +* 'offset': oy, +* 'order': 'row-major' +* }; +* var z = { +* 'dtype': 'float64', +* 'data': zbuf, +* 'shape': shape, +* 'strides': sz, +* 'offset': oz, +* 'order': 'row-major' +* }; +* var w = { +* 'dtype': 'float64', +* 'data': wbuf, +* 'shape': shape, +* 'strides': sw, +* 'offset': ow, +* 'order': 'row-major' +* }; +* var u = { +* 'dtype': 'float64', +* 'data': ubuf, +* 'shape': shape, +* 'strides': su, +* 'offset': ou, +* 'order': 'row-major' +* }; +* var v = { +* 'dtype': 'float64', +* 'data': vbuf, +* 'shape': shape, +* 'strides': sv, +* 'offset': ov, +* 'order': 'row-major' +* }; +* +* // Apply the quinary function: +* quinarynd( x, y, z, w, u, v, add5 ); +* +* var arr = ndarray2array( v.data, v.shape, v.strides, v.offset, v.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 8.0, 9.0 ], [ 10.0, 11.0 ], [ 12.0, 13.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +*/ +function quinarynd( x, y, z, w, u, v, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var vbuf; + var ordx; + var ordy; + var ordz; + var ordw; + var ordu; + var ordv; + var len; + var sh; + var sx; + var sy; + var sz; + var sw; + var su; + var sv; + var ox; + var oy; + var oz; + var ow; + var ou; + var ov; + var ix; + var iy; + var iz; + var iw; + var iu; + var iv; + var i; + + sh = x.shape; + + // Compute the total number of elements over which to iterate: + len = numel( sh ); + + // Cache references to the input and output ndarray buffers: + xbuf = x.data; + ybuf = y.data; + zbuf = z.data; + wbuf = w.data; + ubuf = u.data; + vbuf = v.data; + + // Cache references to the respective stride arrays: + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.strides; + sv = v.strides; + + // Cache the indices of the first indexed elements in the respective ndarrays: + ox = x.offset; + oy = y.offset; + oz = z.offset; + ow = w.offset; + ou = u.offset; + ov = v.offset; + + // Cache the respective array orders: + ordx = x.order; + ordy = y.order; + ordz = z.order; + ordw = w.order; + ordu = u.order; + ordv = v.order; + + // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory... + for ( i = 0; i < len; i++ ) { + ix = vind2bind( sh, sx, ox, ordx, i, 'throw' ); + iy = vind2bind( sh, sy, oy, ordy, i, 'throw' ); + iz = vind2bind( sh, sz, oz, ordz, i, 'throw' ); + iw = vind2bind( sh, sw, ow, ordw, i, 'throw' ); + iu = vind2bind( sh, su, ou, ordu, i, 'throw' ); + iv = vind2bind( sh, sv, ov, ordv, i, 'throw' ); + vbuf[ iv ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ], ubuf[ iu ] ); + } +} + + +// EXPORTS // + +module.exports = quinarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/package.json new file mode 100644 index 000000000000..7bddc245c0d8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/kernels/generic/quinary/linear", + "version": "0.0.0", + "description": "Return a kernel for applying a quinary callback to elements in five input ndarrays and assigning results to elements in an output ndarray using linear view iteration.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "base", + "ndarray", + "quinary", + "apply", + "element-wise", + "elementwise", + "callback", + "kernel", + "linear" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/test/test.js new file mode 100644 index 000000000000..8b32ef36cc64 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quinary/linear/test/test.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var oneTo = require( '@stdlib/array/one-to' ); +var zeros = require( '@stdlib/array/zeros' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var descriptor = require( '@stdlib/ndarray/base/descriptor' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var add5 = require( '@stdlib/number/float64/base/add5' ); +var kernel = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof kernel, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns null if provided a negative number of dimensions', function test( t ) { + t.strictEqual( kernel( -1 ), null, 'returns expected value' ); + t.strictEqual( kernel( -10 ), null, 'returns expected value' ); + t.strictEqual( kernel( -100 ), null, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a kernel for applying a quinary callback', function test( t ) { + var expected; + var shapes; + var sh; + var st; + var x; + var v; + var f; + var i; + + shapes = [ + [ 6 ], + [ 2, 3 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 6 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3 ], + [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3 ] + ]; + expected = new Float64Array( [ 5.0, 10.0, 15.0, 20.0, 25.0, 30.0 ] ); + + for ( i = 0; i < shapes.length; i++ ) { + sh = shapes[ i ]; + st = shape2strides( sh, 'row-major' ); + + x = descriptor( 'float64', oneTo( numel( sh ), 'float64' ), sh, st, strides2offset( sh, st ), 'row-major' ); + v = descriptor( 'float64', zeros( numel( sh ), 'float64' ), sh, st, strides2offset( sh, st ), 'row-major' ); + + f = kernel( sh.length ); + f( x, x, x, x, x, v, add5 ); + t.strictEqual( isSameFloat64Array( v.data, expected ), true, 'returns expected value' ); + } + t.end(); +});