diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/README.md new file mode 100644 index 000000000000..72c984d3e29f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/README.md @@ -0,0 +1,344 @@ + + +# kernel + +> Return a kernel for applying a quaternary callback to elements in four 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/quaternary/linear' ); +``` + +#### kernel( ndims ) + +Returns a kernel for applying a quaternary callback to elements in four 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 add4 = require( '@stdlib/number/float64/base/add4' ); + +// 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( 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 ]; + +// 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' +}; + +// Resolve a kernel: +var f = kernel( 13 ); + +// Apply the quaternary function: +f( x, y, z, w, u, add4 ); + +var arr = ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ); +// returns [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.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**: output ndarray descriptor. +- **fcn**: quaternary callback accepting four 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, fcn ) + +Applies a quaternary 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 add4 = require( '@stdlib/number/float64/base/add4' ); + +// 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( 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 ]; + +// 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' +}; + +// Apply the quaternary function: +kernel.nd( x, y, z, w, u, add4 ); + +var arr = ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ); +// returns [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.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**: output ndarray descriptor. +- **fcn**: quaternary callback accepting four scalar values and returning one scalar value. + +
+ + + +
+ +## Notes + +- The quaternary callback is expected to have the following signature: + + ```text + fcn( v1, v2, v3, v4 ) + ``` + + 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. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var add4 = require( '@stdlib/number/float64/base/add4' ); +var kernel = require( '@stdlib/ndarray/base/kernels/generic/quaternary/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( 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' +}; + +// Resolve a kernel: +var f = kernel( 13 ); + +// Apply the quaternary function: +f( x, y, z, w, u, add4 ); + +console.log( ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ) ); +// => [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/benchmark/benchmark.js new file mode 100644 index 000000000000..52d825421f8a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/benchmark/benchmark.js @@ -0,0 +1,162 @@ +/** +* @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 add4 = require( '@stdlib/number/float64/base/add4' ); +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} utype - output ndarray data type +* @param {string} order - memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, utype, order ) { + var opts; + var st; + var x; + var y; + var z; + var w; + var u; + 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 = filledarray( 0.0, len, utype ); + + 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( utype, u, 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, add4 ); + if ( isnan( u.data[ i%len ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( u.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,uorder=%s,xtype=%s,utype=%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,uorder=%s,xtype=%s,utype=%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,uorder=%s,xtype=%s,utype=%s', pkg, sh.length, len, sh.join(','), ord, ord, t1, t2 ), f ); + } + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/docs/repl.txt new file mode 100644 index 000000000000..b679b0ee2dce --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/docs/repl.txt @@ -0,0 +1,62 @@ + +{{alias}}( ndims ) + Returns a kernel for applying a quaternary callback to elements in four + 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: output ndarray descriptor. + - fcn: quaternary callback accepting four 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, fcn ) + Applies a quaternary 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 + Output ndarray descriptor. + + fcn: Function + Quaternary callback. + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/examples/index.js new file mode 100644 index 000000000000..dbe2df2f20f0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/examples/index.js @@ -0,0 +1,88 @@ +/** +* @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 add4 = require( '@stdlib/number/float64/base/add4' ); +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( 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' +}; + +// Resolve a kernel: +var f = kernel( 13 ); + +// Apply the quaternary function: +f( x, y, z, w, u, add4 ); + +console.log( ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ) ); +// => [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.0 ] ] ] ] ] ] ] ] ] ] ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/index.js new file mode 100644 index 000000000000..55d3d0c2efa3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/index.js @@ -0,0 +1,115 @@ +/** +* @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 quaternary callback to elements in four input ndarrays and assigning results to elements in an output ndarray using linear view iteration. +* +* @module @stdlib/ndarray/base/kernels/generic/quaternary/linear +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var add4 = require( '@stdlib/number/float64/base/add4' ); +* var kernel = require( '@stdlib/ndarray/base/kernels/generic/quaternary/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( 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 ]; +* +* // 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' +* }; +* +* // Resolve a kernel: +* var f = kernel( 13 ); +* +* // Apply the quaternary function: +* f( x, y, z, w, u, add4 ); +* +* var arr = ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.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/quaternary/linear/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/main.js new file mode 100644 index 000000000000..74c81c054afd --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/main.js @@ -0,0 +1,117 @@ +/** +* @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 quaternarynd = require( './nd.js' ); + + +// MAIN // + +/** +* Returns a kernel for applying a quaternary callback to elements in four 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 add4 = require( '@stdlib/number/float64/base/add4' ); +* +* // 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( 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 ]; +* +* // 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' +* }; +* +* // Resolve a kernel: +* var f = kernel( 13 ); +* +* // Apply the quaternary function: +* f( x, y, z, w, u, add4 ); +* +* var arr = ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +*/ +function kernel( ndims ) { + if ( ndims <= 0 ) { + return null; + } + return quaternarynd; +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/nd.js new file mode 100644 index 000000000000..f5eec476c299 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/nd.js @@ -0,0 +1,225 @@ +/** +* @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 quaternary 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 output 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 {Callback} fcn - quaternary callback +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var add4 = require( '@stdlib/number/float64/base/add4' ); +* +* // 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( 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 ]; +* +* // Define the index offsets: +* var ox = 0; +* var oy = 0; +* var oz = 0; +* var ow = 0; +* var ou = 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' +* }; +* +* // Apply the quaternary function: +* quaternarynd( x, y, z, w, u, add4 ); +* +* var arr = ndarray2array( u.data, u.shape, u.strides, u.offset, u.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.0 ] ] ] ] ] ] ] ] ] ] ] ] ] +*/ +function quaternarynd( x, y, z, w, u, fcn ) { + var xbuf; + var ybuf; + var zbuf; + var wbuf; + var ubuf; + var ordx; + var ordy; + var ordz; + var ordw; + var ordu; + var len; + var sh; + var sx; + var sy; + var sz; + var sw; + var su; + var ox; + var oy; + var oz; + var ow; + var ou; + var ix; + var iy; + var iz; + var iw; + var iu; + 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; + + // Cache references to the respective stride arrays: + sx = x.strides; + sy = y.strides; + sz = z.strides; + sw = w.strides; + su = u.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; + + // Cache the respective array orders: + ordx = x.order; + ordy = y.order; + ordz = z.order; + ordw = w.order; + ordu = u.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' ); + ubuf[ iu ] = fcn( xbuf[ ix ], ybuf[ iy ], zbuf[ iz ], wbuf[ iw ] ); + } +} + + +// EXPORTS // + +module.exports = quaternarynd; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/package.json new file mode 100644 index 000000000000..47ca84e8c400 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/kernels/generic/quaternary/linear", + "version": "0.0.0", + "description": "Return a kernel for applying a quaternary callback to elements in four 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", + "quaternary", + "apply", + "element-wise", + "elementwise", + "callback", + "kernel", + "linear" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/test/test.js new file mode 100644 index 000000000000..fd534146534c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/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 add4 = require( '@stdlib/number/float64/base/add4' ); +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 quaternary callback', function test( t ) { + var expected; + var shapes; + var sh; + var st; + var x; + var u; + 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( [ 4.0, 8.0, 12.0, 16.0, 20.0, 24.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' ); + u = descriptor( 'float64', zeros( numel( sh ), 'float64' ), sh, st, strides2offset( sh, st ), 'row-major' ); + + f = kernel( sh.length ); + f( x, x, x, x, u, add4 ); + t.strictEqual( isSameFloat64Array( u.data, expected ), true, 'returns expected value' ); + } + t.end(); +});