From cf2edb4e2173b935b8d2e429602287f999a5dd04 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 1 Oct 2026 20:41:02 +0500 Subject: [PATCH 1/5] feat: add ndarray/base/kernels/generic/quaternary/linear --- .../generic/quaternary/linear/README.md | 325 ++++++++++++++++++ .../quaternary/linear/benchmark/benchmark.js | 162 +++++++++ .../generic/quaternary/linear/docs/repl.txt | 52 +++ .../quaternary/linear/examples/index.js | 91 +++++ .../generic/quaternary/linear/lib/index.js | 117 +++++++ .../generic/quaternary/linear/lib/main.js | 119 +++++++ .../generic/quaternary/linear/lib/nd.js | 227 ++++++++++++ .../generic/quaternary/linear/package.json | 64 ++++ .../generic/quaternary/linear/test/test.js | 85 +++++ 9 files changed, 1242 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/nd.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/test/test.js 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..840a292e387e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/README.md @@ -0,0 +1,325 @@ + + +# 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' ); + +function add4( a, b, c, d ) { + return a + b + c + d; +} + +// 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// 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 v = u.data; +// 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 +``` + +#### 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' ); + +function add4( a, b, c, d ) { + return a + b + c + d; +} + +// 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// 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 v = u.data; +// returns [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +``` + +
+ + + +
+ +## Notes + +- Each returned kernel expects 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. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var kernel = require( '@stdlib/ndarray/base/kernels/generic/quaternary/linear' ); + +function add4( a, b, c, d ) { + return a + b + c + d; +} + +// 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// 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..b7d0f9254214 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/docs/repl.txt @@ -0,0 +1,52 @@ + +{{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. + + 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..a04b3358a4a7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/examples/index.js @@ -0,0 +1,91 @@ +/** +* @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 kernel = require( './../lib' ); + +function add4( a, b, c, d ) { + return a + b + c + d; +} + +// 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + +// 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..2e1aea33f10a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/index.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'; + +/** +* 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 kernel = require( '@stdlib/ndarray/base/kernels/generic/quaternary/linear' ); +* +* function add4( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // 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 v = u.data; +* // 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..17137156c9ac --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/main.js @@ -0,0 +1,119 @@ +/** +* @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' ); +* +* function add4( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // 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 v = u.data; +* // 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..75383e5064b8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/quaternary/linear/lib/nd.js @@ -0,0 +1,227 @@ +/** +* @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' ); +* +* function fcn( a, b, c, d ) { +* return a + b + c + d; +* } +* +* // 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* // 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, fcn ); +* +* console.log( u.data ); +* // => [ 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(); +}); From b95f2a4f2dd8f1c938b136a126455154efda8b36 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 2 Oct 2026 23:06:26 +0500 Subject: [PATCH 2/5] fix: apply suggestions from code review --- .../generic/quaternary/linear/README.md | 81 ++++++++++++------- .../quaternary/linear/benchmark/benchmark.js | 2 +- .../generic/quaternary/linear/docs/repl.txt | 21 ++++- .../quaternary/linear/examples/index.js | 9 +-- .../generic/quaternary/linear/lib/index.js | 14 ++-- .../generic/quaternary/linear/lib/main.js | 14 ++-- .../generic/quaternary/linear/lib/nd.js | 21 ++--- .../generic/quaternary/linear/test/test.js | 2 +- 8 files changed, 100 insertions(+), 64 deletions(-) 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 index 840a292e387e..fbf33aeeffd6 100644 --- 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 @@ -40,19 +40,19 @@ var kernel = require( '@stdlib/ndarray/base/kernels/generic/quaternary/linear' ) 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' ); - -function add4( a, b, c, d ) { - return a + b + c + d; -} +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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -110,10 +110,10 @@ var u = { var f = kernel( 13 ); // Apply the quaternary function: -f( x, y, z, w, u, add4 ); +f( x, y, z, w, u, false, add4 ); -var v = u.data; -// returns [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +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: @@ -127,7 +127,19 @@ var f = kernel( -1 ); // returns null ``` -#### kernel.nd( x, y, z, w, u, fcn ) +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. +- **isRowMajor**: boolean indicating whether the arrays are in row-major order. +- **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, isRowMajor, 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. @@ -135,17 +147,15 @@ Applies a quaternary callback to elements in n-dimensional input ndarrays and as ```javascript var Float64Array = require( '@stdlib/array/float64' ); - -function add4( a, b, c, d ) { - return a + b + c + d; -} +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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -200,12 +210,22 @@ var u = { }; // Apply the quaternary function: -kernel.nd( x, y, z, w, u, add4 ); +kernel.nd( x, y, z, w, u, false, add4 ); -var v = u.data; -// returns [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +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. +- **isRowMajor**: boolean indicating whether the arrays are in row-major order. +- **fcn**: quaternary callback accepting four scalar values and returning one scalar value. + @@ -214,14 +234,18 @@ var v = u.data; ## Notes -- Each returned kernel expects the following arguments: +- The quaternary callback is expected to have the following signature: - - **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. + ```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. @@ -238,18 +262,15 @@ var v = u.data; ```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' ); -function add4( a, b, c, d ) { - return a + b + c + d; -} - // 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -300,7 +321,7 @@ var u = { var f = kernel( 13 ); // Apply the quaternary function: -f( x, y, z, w, u, add4 ); +f( x, y, z, w, u, false, 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 index 52d825421f8a..81c578634e76 100644 --- 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 @@ -95,7 +95,7 @@ function createBenchmark( len, shape, xtype, utype, order ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - f( x, y, z, w, u, add4 ); + f( x, y, z, w, u, false, add4 ); if ( isnan( u.data[ i%len ] ) ) { b.fail( 'should not return NaN' ); } 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 index b7d0f9254214..f019526cd126 100644 --- 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 @@ -4,6 +4,19 @@ 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. + - isRowMajor: boolean indicating whether the arrays are in row-major + order. + - fcn: quaternary callback accepting four scalar values and returning one + scalar value. + If `ndims` is less than `0`, the function returns `null`. Parameters @@ -22,11 +35,14 @@ -{{alias}}.nd( x, y, z, w, u, fcn ) +{{alias}}.nd( x, y, z, w, u, isRowMajor, 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. + The `isRowMajor` parameter is unused. Providing a placeholder for this + parameter is recommended in order to ensure a monomorphic API. + Parameters ---------- x: Object @@ -44,6 +60,9 @@ u: Object Output ndarray descriptor. + isRowMajor: boolean + Boolean indicating whether the arrays are in row-major order. + fcn: Function Quaternary callback. 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 index a04b3358a4a7..1aeb51f98b9d 100644 --- 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 @@ -20,18 +20,15 @@ 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' ); -function add4( a, b, c, d ) { - return a + b + c + d; -} - // 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -85,7 +82,7 @@ var u = { var f = kernel( 13 ); // Apply the quaternary function: -f( x, y, z, w, u, add4 ); +f( x, y, z, w, u, false, 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 index 2e1aea33f10a..34ec6668970d 100644 --- 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 @@ -25,18 +25,16 @@ * * @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' ); * -* function add4( a, b, c, d ) { -* return a + b + c + d; -* } -* * // 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -94,10 +92,10 @@ * var f = kernel( 13 ); * * // Apply the quaternary function: -* f( x, y, z, w, u, add4 ); +* f( x, y, z, w, u, false, add4 ); * -* var v = u.data; -* // returns [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +* 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 // 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 index 17137156c9ac..2d304e3a1411 100644 --- 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 @@ -33,17 +33,15 @@ var quaternarynd = require( './nd.js' ); * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* -* function add4( a, b, c, d ) { -* return a + b + c + d; -* } +* 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -101,10 +99,10 @@ var quaternarynd = require( './nd.js' ); * var f = kernel( 13 ); * * // Apply the quaternary function: -* f( x, y, z, w, u, add4 ); +* f( x, y, z, w, u, false, add4 ); * -* var v = u.data; -* // returns [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +* 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 ) { 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 index 75383e5064b8..6383dad3f98b 100644 --- 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 @@ -29,6 +29,10 @@ var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); /** * 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. * +* ## Notes +* +* - The `isRowMajor` parameter is unused. Providing a placeholder for this parameter is recommended in order to ensure a monomorphic API. +* * @private * @param {Object} x - object containing input ndarray meta data * @param {*} x.dtype - data type @@ -65,22 +69,21 @@ var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); * @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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order * @param {Callback} fcn - quaternary callback * @returns {void} * * @example * var Float64Array = require( '@stdlib/array/float64' ); -* -* function fcn( a, b, c, d ) { -* return a + b + c + d; -* } +* 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( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 ]; @@ -142,12 +145,12 @@ var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); * }; * * // Apply the quaternary function: -* quaternarynd( x, y, z, w, u, fcn ); +* quaternarynd( x, y, z, w, u, false, add4 ); * -* console.log( u.data ); -* // => [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] +* 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 ) { +function quaternarynd( x, y, z, w, u, isRowMajor, fcn ) { var xbuf; var ybuf; var zbuf; 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 index fd534146534c..7cb152b46157 100644 --- 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 @@ -78,7 +78,7 @@ tape( 'the function returns a kernel for applying a quaternary callback', functi 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 ); + f( x, x, x, x, u, false, add4 ); t.strictEqual( isSameFloat64Array( u.data, expected ), true, 'returns expected value' ); } t.end(); From ea971c1234145909004ae31861cc6b1e0998904b Mon Sep 17 00:00:00 2001 From: headlessNode Date: Fri, 2 Oct 2026 23:39:10 +0500 Subject: [PATCH 3/5] fix: apply suggestions from code review --- .../base/kernels/generic/quaternary/linear/README.md | 10 ++++------ .../generic/quaternary/linear/benchmark/benchmark.js | 2 +- .../kernels/generic/quaternary/linear/docs/repl.txt | 10 +--------- .../generic/quaternary/linear/examples/index.js | 2 +- .../kernels/generic/quaternary/linear/lib/index.js | 2 +- .../base/kernels/generic/quaternary/linear/lib/main.js | 2 +- .../base/kernels/generic/quaternary/linear/lib/nd.js | 9 ++------- .../kernels/generic/quaternary/linear/test/test.js | 2 +- 8 files changed, 12 insertions(+), 27 deletions(-) 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 index fbf33aeeffd6..72c984d3e29f 100644 --- 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 @@ -110,7 +110,7 @@ var u = { var f = kernel( 13 ); // Apply the quaternary function: -f( x, y, z, w, u, false, add4 ); +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 ] ] ] ] ] ] ] ] ] ] ] ] ] @@ -134,12 +134,11 @@ The returned function accepts the following arguments: - **z**: third input ndarray descriptor. - **w**: fourth input ndarray descriptor. - **u**: output ndarray descriptor. -- **isRowMajor**: boolean indicating whether the arrays are in row-major order. - **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, isRowMajor, fcn ) +#### 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. @@ -210,7 +209,7 @@ var u = { }; // Apply the quaternary function: -kernel.nd( x, y, z, w, u, false, add4 ); +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 ] ] ] ] ] ] ] ] ] ] ] ] ] @@ -223,7 +222,6 @@ The function has the following parameters: - **z**: third input ndarray descriptor. - **w**: fourth input ndarray descriptor. - **u**: output ndarray descriptor. -- **isRowMajor**: boolean indicating whether the arrays are in row-major order. - **fcn**: quaternary callback accepting four scalar values and returning one scalar value. @@ -321,7 +319,7 @@ var u = { var f = kernel( 13 ); // Apply the quaternary function: -f( x, y, z, w, u, false, add4 ); +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 index 81c578634e76..52d825421f8a 100644 --- 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 @@ -95,7 +95,7 @@ function createBenchmark( len, shape, xtype, utype, order ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - f( x, y, z, w, u, false, add4 ); + f( x, y, z, w, u, add4 ); if ( isnan( u.data[ i%len ] ) ) { b.fail( 'should not return NaN' ); } 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 index f019526cd126..db321f4dc378 100644 --- 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 @@ -12,8 +12,6 @@ - z: third input ndarray descriptor. - w: fourth input ndarray descriptor. - u: output ndarray descriptor. - - isRowMajor: boolean indicating whether the arrays are in row-major - order. - fcn: quaternary callback accepting four scalar values and returning one scalar value. @@ -35,14 +33,11 @@ -{{alias}}.nd( x, y, z, w, u, isRowMajor, fcn ) +{{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. - The `isRowMajor` parameter is unused. Providing a placeholder for this - parameter is recommended in order to ensure a monomorphic API. - Parameters ---------- x: Object @@ -60,9 +55,6 @@ u: Object Output ndarray descriptor. - isRowMajor: boolean - Boolean indicating whether the arrays are in row-major order. - fcn: Function Quaternary callback. 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 index 1aeb51f98b9d..dbe2df2f20f0 100644 --- 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 @@ -82,7 +82,7 @@ var u = { var f = kernel( 13 ); // Apply the quaternary function: -f( x, y, z, w, u, false, add4 ); +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 index 34ec6668970d..55d3d0c2efa3 100644 --- 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 @@ -92,7 +92,7 @@ * var f = kernel( 13 ); * * // Apply the quaternary function: -* f( x, y, z, w, u, false, add4 ); +* 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 ] ] ] ] ] ] ] ] ] ] ] ] ] 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 index 2d304e3a1411..2243c73ab418 100644 --- 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 @@ -99,7 +99,7 @@ var quaternarynd = require( './nd.js' ); * var f = kernel( 13 ); * * // Apply the quaternary function: -* f( x, y, z, w, u, false, add4 ); +* 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 ] ] ] ] ] ] ] ] ] ] ] ] ] 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 index 6383dad3f98b..f5eec476c299 100644 --- 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 @@ -29,10 +29,6 @@ var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); /** * 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. * -* ## Notes -* -* - The `isRowMajor` parameter is unused. Providing a placeholder for this parameter is recommended in order to ensure a monomorphic API. -* * @private * @param {Object} x - object containing input ndarray meta data * @param {*} x.dtype - data type @@ -69,7 +65,6 @@ var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); * @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 {boolean} isRowMajor - boolean indicating if provided arrays are in row-major order * @param {Callback} fcn - quaternary callback * @returns {void} * @@ -145,12 +140,12 @@ var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); * }; * * // Apply the quaternary function: -* quaternarynd( x, y, z, w, u, false, add4 ); +* 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, isRowMajor, fcn ) { +function quaternarynd( x, y, z, w, u, fcn ) { var xbuf; var ybuf; var zbuf; 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 index 7cb152b46157..fd534146534c 100644 --- 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 @@ -78,7 +78,7 @@ tape( 'the function returns a kernel for applying a quaternary callback', functi u = descriptor( 'float64', zeros( numel( sh ), 'float64' ), sh, st, strides2offset( sh, st ), 'row-major' ); f = kernel( sh.length ); - f( x, x, x, x, u, false, add4 ); + f( x, x, x, x, u, add4 ); t.strictEqual( isSameFloat64Array( u.data, expected ), true, 'returns expected value' ); } t.end(); From 6a2536b64649cc206552bd323cf6b4aa1e31ce8a Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:09:07 +0500 Subject: [PATCH 4/5] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- .../ndarray/base/kernels/generic/quaternary/linear/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 2243c73ab418..74c81c054afd 100644 --- 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 @@ -105,7 +105,7 @@ var quaternarynd = require( './nd.js' ); * // returns [ [ [ [ [ [ [ [ [ [ [ [ [ 7.0, 8.0 ], [ 9.0, 10.0 ], [ 11.0, 12.0 ] ] ] ] ] ] ] ] ] ] ] ] ] */ function kernel( ndims ) { - if ( ndims < 0 ) { + if ( ndims <= 0 ) { return null; } return quaternarynd; From dbad7c08da11e7bb7e810ade3023959dac7b0d2e Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 3 Oct 2026 13:31:53 +0500 Subject: [PATCH 5/5] fix: apply suggestions from code review --- .../base/kernels/generic/quaternary/linear/docs/repl.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 index db321f4dc378..b679b0ee2dce 100644 --- 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 @@ -1,13 +1,13 @@ {{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. + 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`). + - 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. @@ -60,4 +60,3 @@ See Also -------- -