From 48f11f3b1fab506983cf286c2c24cd5cf1f5e840 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 27 Sep 2026 22:37:11 +0500 Subject: [PATCH 1/4] feat: add ndarray/base/kernels/generic/nullary-strided1d-by --- .../nullary-strided1d-by/blocked/README.md | 581 +++++++++++++ .../blocked/docs/repl.txt | 149 ++++ .../blocked/examples/index.js | 120 +++ .../nullary-strided1d-by/blocked/lib/2d.js | 256 ++++++ .../nullary-strided1d-by/blocked/lib/3d.js | 279 ++++++ .../blocked/lib/callback_wrapper.js | 72 ++ .../nullary-strided1d-by/blocked/lib/index.js | 144 ++++ .../nullary-strided1d-by/blocked/lib/main.js | 154 ++++ .../nullary-strided1d-by/blocked/package.json | 65 ++ .../nullary-strided1d-by/blocked/test/test.js | 35 + .../nullary-strided1d-by/linear/README.md | 320 +++++++ .../nullary-strided1d-by/linear/docs/repl.txt | 62 ++ .../linear/examples/index.js | 117 +++ .../linear/lib/callback_wrapper.js | 72 ++ .../nullary-strided1d-by/linear/lib/index.js | 132 +++ .../nullary-strided1d-by/linear/lib/main.js | 208 +++++ .../nullary-strided1d-by/linear/package.json | 65 ++ .../nullary-strided1d-by/linear/test/test.js | 35 + .../nullary-strided1d-by/strategy/README.md | 207 +++++ .../strategy/docs/repl.txt | 43 + .../strategy/examples/index.js | 120 +++ .../strategy/lib/index.js | 50 ++ .../nullary-strided1d-by/strategy/lib/main.js | 283 ++++++ .../strategy/package.json | 61 ++ .../strategy/test/test.js | 35 + .../nullary-strided1d-by/unblocked/README.md | 807 ++++++++++++++++++ .../unblocked/docs/repl.txt | 254 ++++++ .../unblocked/examples/index.js | 120 +++ .../nullary-strided1d-by/unblocked/lib/0d.js | 139 +++ .../nullary-strided1d-by/unblocked/lib/1d.js | 194 +++++ .../nullary-strided1d-by/unblocked/lib/2d.js | 226 +++++ .../nullary-strided1d-by/unblocked/lib/3d.js | 242 ++++++ .../unblocked/lib/callback_wrapper.js | 72 ++ .../unblocked/lib/index.js | 148 ++++ .../unblocked/lib/main.js | 158 ++++ .../unblocked/package.json | 64 ++ .../unblocked/test/test.js | 35 + 37 files changed, 6124 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/callback_wrapper.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md new file mode 100644 index 000000000000..b94588359475 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md @@ -0,0 +1,581 @@ + + +# kernel + +> Return a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. + +
+ +
+ + + +
+ +## Usage + +```javascript +var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); +``` + +#### kernel( ndims ) + +Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Resolve a kernel: +var f = kernel( 2 ); + +// Apply strided function: +f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +``` + +The function accepts the following arguments: + +- **ndims**: number of loop dimensions. + +If the function is provided `ndims < 2` or a value greater than the maximum number of supported loop dimensions, the function returns `null`. + +```javascript +var f = kernel( 100000 ); +// returns null +``` + +The returned function accepts the following arguments: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel2d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Apply strided function: +kernel.kernel2d( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have two elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel3d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Apply strided function: +kernel.kernel3d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have three elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + +
+ + + +
+ +## Notes + +- The strided array function is expected to have the following signature: + + ```text + fcn( arrays[, options], clbk ) + ``` + + where + + - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as subarrays. + - **options**: function options (_optional_). + - **clbk**: callback function. + +- The callback function is provided the following arguments: + + - **value**: current array element. + - **idx**: current array element indices. + - **arr**: the original input ndarray. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Resolve a kernel: +var f = kernel( 3 ); + +// Apply strided function: +f( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt new file mode 100644 index 000000000000..4c8057f0841f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt @@ -0,0 +1,149 @@ + +{{alias}}( ndims ) + Returns a kernel for applying a one-dimensional strided array function to + an input ndarray according to a callback function using loop blocking. + + The returned function has the following parameters: + + - fcn: function which will be applied to a one-dimensional input subarray + according to a callback function. + - arrays: array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + - ref: original input ndarray provided to a callback function. + - views: initialized ndarray descriptors representing subarray views. + - shape: loop dimensions. + - stridesX: loop dimension strides for the input ndarray. + - strategyX: strategy for marshaling data to and from an input ndarray + view. + - ibuf: workspace for storing iteration indices. + - ldims: list of loop dimensions. + - cdims: list of "core" dimensions. + - options: function options which are passed through to `fcn`. + - hasOpts: boolean indicating whether to pass an options argument to a + strided array function. + - clbk: callback function. + - thisArg: callback execution context. + + If `ndims < 2` or greater than the maximum supported number of loop + dimensions, the function returns `null`. + + Parameters + ---------- + ndims: integer + Number of loop dimensions. + + Returns + ------- + fcn: Function|null + Kernel function. + + Examples + -------- + > var f = {{alias}}( 2 ) + + + +{{alias}}.kernel2d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function via loop blocking. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have two elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel3d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function via loop blocking. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have three elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js new file mode 100644 index 000000000000..1c93f3555ca7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js @@ -0,0 +1,120 @@ +/** +* @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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var kernel = require( './../lib' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Resolve a kernel: +var f = kernel( 3 ); + +// Apply strided function: +f( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js new file mode 100644 index 000000000000..e9e05ffb1859 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js @@ -0,0 +1,256 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var bsize; + var dv0; + var dv1; + var ov1; + var sh; + var s0; + var s1; + var sv; + var ov; + var iv; + var i0; + var i1; + var j0; + var j1; + var N; + var x; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + + // Resolve the loop interchange order: + o = loopOrder( shape, stridesX ); + sh = o.sh; + sv = [ o.sx ]; + for ( k = 1; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + dv1 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov[k] + ( j1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the loop dimensions... + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + } + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js new file mode 100644 index 000000000000..d6509e37e361 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js @@ -0,0 +1,279 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params, max-depth */ + +'use strict'; + +// MODULES // + +var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); +var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); +var takeIndexed = require( '@stdlib/array/base/take-indexed' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 3 ], +* 'strides': [ 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 3 ], +* 'strides': [ 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2 ]; +* var cdims = [ 3, 4 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var bsize; + var dv0; + var dv1; + var dv2; + var ov1; + var ov2; + var sh; + var s0; + var s1; + var s2; + var sv; + var ov; + var iv; + var i0; + var i1; + var i2; + var j0; + var j1; + var j2; + var N; + var x; + var v; + var o; + var k; + var f; + + // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... + + N = arrays.length; + x = arrays[ 0 ]; + + // Resolve the loop interchange order: + o = loopOrder( shape, stridesX ); + sh = o.sh; + sv = [ o.sx ]; + for ( k = 1; k < N; k++ ) { + sv.push( takeIndexed( arrays[k].strides, o.idx ) ); + } + // Determine the block size: + bsize = blockSize( x.dtype ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + ov = offsets( arrays ); + + // Cache offset increments for the innermost loop... + dv0 = []; + for ( k = 0; k < N; k++ ) { + dv0.push( sv[k][0] ); + } + // Initialize loop variables... + ov1 = zeros( N ); + ov2 = zeros( N ); + dv1 = zeros( N ); + dv2 = zeros( N ); + iv = zeros( N ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over blocks... + for ( j2 = sh[2]; j2 > 0; ) { + if ( j2 < bsize ) { + s2 = j2; + j2 = 0; + } else { + s2 = bsize; + j2 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov2[ k ] = ov[k] + ( j2*sv[k][2] ); + } + for ( j1 = sh[1]; j1 > 0; ) { + if ( j1 < bsize ) { + s1 = j1; + j1 = 0; + } else { + s1 = bsize; + j1 -= bsize; + } + for ( k = 0; k < N; k++ ) { + ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); + dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); + } + for ( j0 = sh[0]; j0 > 0; ) { + if ( j0 < bsize ) { + s0 = j0; + j0 = 0; + } else { + s0 = bsize; + j0 -= bsize; + } + // Compute index offsets and loop offset increments for the first ndarray elements in the current block... + for ( k = 0; k < N; k++ ) { + iv[ k ] = ov1[k] + ( j0*sv[k][0] ); + dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); + } + // Iterate over the loop dimensions... + for ( i2 = 0; i2 < s2; i2++ ) { + for ( i1 = 0; i1 < s1; i1++ ) { + for ( i0 = 0; i0 < s0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + } + } + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js new file mode 100644 index 000000000000..ad25b5d7bbcf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js @@ -0,0 +1,72 @@ +/** +* @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 put = require( '@stdlib/array/base/put' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ).assign; +var zeros = require( '@stdlib/array/base/zeros' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Wraps a provided callback function. +* +* @private +* @param {ndarray} arr - input ndarray +* @param {ndarray} view - subarray view of the input ndarray +* @param {NonNegativeIntegerArray} idx - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - loop dimensions +* @param {NonNegativeIntegerArray} lidx - current loop iteration indices +* @param {NonNegativeIntegerArray} cdims - core dimensions +* @param {Function} clbk - callback function +* @param {thisArg} thisArg - callback execution context +* @returns {Function} callback wrapper +*/ +function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { + var cidx = zeros( cdims.length ); // workspace for storing core iteration indices + put( idx, ldims, lidx, MODE ); + return wrapper; + + /** + * Invokes a callback function. + * + * @private + * @param {*} v - value + * @param {NonNegativeInteger} aidx - current array element index + * @returns {*} result + */ + function wrapper( v, aidx ) { + ind2sub( view.shape, view.strides, view.offset, view.order, aidx, MODE, cidx ); // eslint-disable-line max-len + put( idx, cdims, cidx, MODE ); + return clbk.call( thisArg, v, idx.slice(), arr ); + } +} + + +// EXPORTS // + +module.exports = wrap; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js new file mode 100644 index 000000000000..dfdf4d55e482 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js @@ -0,0 +1,144 @@ +/** +* @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 one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. +* +* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve a kernel: +* var f = kernel( 2 ); +* +* // Apply strided function: +* f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var kernel2d = require( './2d.js' ); +var kernel3d = require( './3d.js' ); +var main = require( './main.js' ); + + +// MAIN // + +setReadOnly( main, 'kernel2d', kernel2d ); +setReadOnly( main, 'kernel3d', kernel3d ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js new file mode 100644 index 000000000000..074af133012f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js @@ -0,0 +1,154 @@ +/** +* @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 kernel2d = require( './2d.js' ); +var kernel3d = require( './3d.js' ); + + +// VARIABLES // + +var KERNELS = [ + kernel2d, + kernel3d +]; +var MAX_DIMS = KERNELS.length + 1; + + +// MAIN // + +/** +* Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. +* +* @param {integer} ndims - number of loop dimensions +* @returns {(Function|null)} kernel function or null +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve a kernel: +* var f = kernel( 2 ); +* +* // Apply strided function: +* f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ +function kernel( ndims ) { + if ( ndims < 2 || ndims > MAX_DIMS ) { + return null; + } + return KERNELS[ ndims-2 ]; +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json new file mode 100644 index 000000000000..5b9f3be3c9bc --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked", + "version": "0.0.0", + "description": "Return a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking.", + "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": { + "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", + "strided", + "array", + "ndarray", + "nullary", + "apply", + "fill", + "callback", + "vector", + "kernel", + "blocked" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js new file mode 100644 index 000000000000..053851cfb7f7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 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(); +}); + +// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md new file mode 100644 index 000000000000..538a115ff2ea --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md @@ -0,0 +1,320 @@ + + +# kernel + +> Apply a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. + +
+ +
+ + + +
+ +## Usage + +```javascript +var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear' ); +``` + + + +#### kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Apply strided function: +kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + +The function iterates based on the linear **view** index, regardless as to how the data is stored in memory. + +
+ + + +
+ +## Notes + +- The strided array function is expected to have the following signature: + + ```text + fcn( arrays[, options], clbk ) + ``` + + where + + - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as subarrays. + - **options**: function options (_optional_). + - **clbk**: callback function. + +- The callback function is provided the following arguments: + + - **value**: current array element. + - **idx**: current array element indices. + - **arr**: the original input ndarray. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Apply strided function: +kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt new file mode 100644 index 000000000000..98d364017b81 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt @@ -0,0 +1,62 @@ + +{{alias}}( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function using linear view iteration. + + The function iterates based on the linear view index, regardless as to how + the data is stored in memory. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + Examples + -------- + > var f = {{alias}} + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js new file mode 100644 index 000000000000..c56bd7b29f93 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var kernel = require( './../lib' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Apply strided function: +kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js new file mode 100644 index 000000000000..ad25b5d7bbcf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js @@ -0,0 +1,72 @@ +/** +* @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 put = require( '@stdlib/array/base/put' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ).assign; +var zeros = require( '@stdlib/array/base/zeros' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Wraps a provided callback function. +* +* @private +* @param {ndarray} arr - input ndarray +* @param {ndarray} view - subarray view of the input ndarray +* @param {NonNegativeIntegerArray} idx - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - loop dimensions +* @param {NonNegativeIntegerArray} lidx - current loop iteration indices +* @param {NonNegativeIntegerArray} cdims - core dimensions +* @param {Function} clbk - callback function +* @param {thisArg} thisArg - callback execution context +* @returns {Function} callback wrapper +*/ +function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { + var cidx = zeros( cdims.length ); // workspace for storing core iteration indices + put( idx, ldims, lidx, MODE ); + return wrapper; + + /** + * Invokes a callback function. + * + * @private + * @param {*} v - value + * @param {NonNegativeInteger} aidx - current array element index + * @returns {*} result + */ + function wrapper( v, aidx ) { + ind2sub( view.shape, view.strides, view.offset, view.order, aidx, MODE, cidx ); // eslint-disable-line max-len + put( idx, cdims, cidx, MODE ); + return clbk.call( thisArg, v, idx.slice(), arr ); + } +} + + +// EXPORTS // + +module.exports = wrap; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js new file mode 100644 index 000000000000..7d47221b96d7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js @@ -0,0 +1,132 @@ +/** +* @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'; + +/** +* Apply a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. +* +* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js new file mode 100644 index 000000000000..dee8637de4e2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js @@ -0,0 +1,208 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var numel = require( '@stdlib/ndarray/base/numel' ); +var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. +* +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var len; + var arr; + var sub; + var iv; + var io; + var N; + var x; + var v; + var i; + var j; + var f; + + N = arrays.length; + + // Cache a reference to the input ndarray: + x = arrays[ 0 ]; + + // Compute the total number of elements over which to iterate: + len = numel( shape ); + + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate based on the linear **view** index, regardless as to how the data is stored in memory... + io = zeros( N ); + for ( i = 0; i < len; i++ ) { + for ( j = 0; j < N; j++ ) { + arr = arrays[ j ]; + io[ j ] = vind2bind( shape, arr.strides, iv[ j ], arr.order, i, MODE ); + } + setViewOffsets( views, io ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + sub = ind2sub( shape, stridesX, 0, x.order, i, MODE ); + f = wrap( ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json new file mode 100644 index 000000000000..909513f56257 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear", + "version": "0.0.0", + "description": "Apply a one-dimensional strided array function to an input ndarray according to a callback function 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": { + "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", + "strided", + "array", + "ndarray", + "nullary", + "apply", + "fill", + "callback", + "vector", + "kernel", + "linear" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js new file mode 100644 index 000000000000..053851cfb7f7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 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(); +}); + +// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md new file mode 100644 index 000000000000..d16c35374a8e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md @@ -0,0 +1,207 @@ + + +# strategy + +> Return an object containing methods for reshaping an ndarray as a one-dimensional strided array view. + +
+ +
+ + + +
+ +## Usage + +```javascript +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +``` + +#### strategy( x ) + +Returns an object containing methods for reshaping an ndarray as a one-dimensional strided array view. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +var x = { + 'dtype': 'float64', + 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), + 'shape': [ 1 ], + 'strides': [ 1 ], + 'offset': 0, + 'order': 'row-major' +}; + +var out = strategy( x ); +// returns {...} +``` + +The function accepts the following arguments: + +- **x**: ndarray [descriptor][@stdlib/ndarray/base/descriptor]. + +
+ + + +
+ +## Notes + +- The function returns an object having the following properties: + + - **input**: function providing a strategy for reshaping an input ndarray to a one-dimensional input ndarray view **prior** to applying a one-dimensional strided array function. + - **output**: function providing a strategy for reshaping the results of a one-dimensional strided array function to the shape of an input ndarray **after** applying a one-dimensional strided array function. This function should only be invoked for input ndarrays which are written to by the one-dimensional strided array function. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var resolveKernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Resolve a kernel: +var kernel = resolveKernel( 2 ); + +// Apply strided function: +kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt new file mode 100644 index 000000000000..cda7cabbf51b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt @@ -0,0 +1,43 @@ + +{{alias}}( x ) + Returns an object containing methods for reshaping an ndarray as a one- + dimensional strided array view. + + Parameters + ---------- + x: Object + Descriptor. + + Returns + ------- + out: Object + Object containing an input and output strategy. + + out.input: Function + Function providing a strategy for reshaping an input ndarray to a one- + dimensional input ndarray view prior to applying a one-dimensional + strided array function. + + out.output: Function + Function providing a strategy for reshaping the results of a one- + dimensional strided array function to the shape of an input ndarray + after applying a one-dimensional strided array function. This function + should only be invoked for input ndarrays which are written to by the + one-dimensional strided array function. + + Examples + -------- + > var x = { + ... 'dtype': 'float64', + ... 'data': new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ), + ... 'shape': [ 1 ], + ... 'strides': [ 1 ], + ... 'offset': 0, + ... 'order': 'row-major' + ... }; + > var o = {{alias}}( x ) + {...} + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js new file mode 100644 index 000000000000..2a60cb1f1a45 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js @@ -0,0 +1,120 @@ +/** +* @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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var resolveKernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); +var strategy = require( './../lib' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Resolve a kernel: +var kernel = resolveKernel( 2 ); + +// Apply strided function: +kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js new file mode 100644 index 000000000000..d656140f45fa --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js @@ -0,0 +1,50 @@ +/** +* @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 an object containing methods for reshaping an ndarray as a one-dimensional strided array view. +* +* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* var x = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), +* 'shape': [ 1 ], +* 'strides': [ 1 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* var out = strategy( x ); +* // returns {...} +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js new file mode 100644 index 000000000000..45d344b42a93 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js @@ -0,0 +1,283 @@ +/** +* @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 iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); +var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ).assign; +var ndarraylike2descriptor = require( '@stdlib/ndarray/base/ndarraylike2descriptor' ); +var assign = require( '@stdlib/ndarray/base/assign' ); +var descriptor = require( '@stdlib/ndarray/base/descriptor' ); +var empty = require( '@stdlib/ndarray/base/empty' ); + + +// FUNCTIONS // + +/** +* Returns an input ndarray. +* +* @private +* @param {Object} x - input ndarray descriptor +* @returns {Object} input ndarray descriptor +*/ +function identity( x ) { + return x; +} + +/** +* Broadcasts a zero-dimensional ndarray to a one-dimensional ndarray view containing a single element. +* +* @private +* @param {Object} x - input ndarray descriptor +* @returns {Object} broadcasted ndarray view descriptor +*/ +function broadcast( x ) { + return descriptor( x.dtype, x.data, [ 1 ], [ 0 ], x.offset, x.order ); +} + +/** +* Returns a function which returns an ndarray view in which the singleton dimensions are removed from an input ndarray having only one non-singleton dimension. +* +* @private +* @param {Object} arr - original ndarray descriptor +* @param {integer} index - index of the non-singleton dimension +* @returns {Function} function for returning an ndarray view +*/ +function squeeze( arr, index ) { + var sh = [ arr.shape[ index ] ]; + var sx = [ arr.strides[ index ] ]; + return reshape; + + /** + * Returns an ndarray view in which the singleton dimensions are removed from an input ndarray having only one non-singleton dimension. + * + * @private + * @param {Object} x - input ndarray descriptor + * @returns {Object} a squeezed ndarray view descriptor + */ + function reshape( x ) { + return descriptor( x.dtype, x.data, sh, sx, x.offset, x.order ); + } +} + +/** +* Returns a function which returns a one-dimensional ndarray view of a contiguous input ndarray having more than one dimension. +* +* @private +* @param {integer} len - number of elements in an ndarray +* @param {integer} iox - iteration order +* @returns {Function} function for returning a one-dimensional ndarray view +*/ +function contiguous( len, iox ) { + var xmmv; + var ind; + var sh; + var sx; + + // Resolve the index of the min/max view buffer element which is the first indexed element... + if ( iox === 1 ) { + ind = 0; + } else { + ind = 1; + } + // Initialize an array for storing the min/max view buffer elements: + xmmv = [ 0, 0 ]; // [ min, max ] + + // Initialize the output one-dimensional view's shape and strides: + sh = [ len ]; + sx = [ iox ]; + + return reshape; + + /** + * Returns a one-dimensional ndarray view of a contiguous input ndarray having more than one dimension. + * + * @private + * @param {Object} x - input ndarray descriptor + * @returns {Object} a one-dimensional ndarray view descriptor + */ + function reshape( x ) { + // Resolve the minimum and maximum linear indices in the underlying data buffer which are accessible to the input ndarray view: + minmaxViewBufferIndex( x.shape, x.strides, x.offset, xmmv ); + + // Note: `xmmv[ ind ]` corresponds to the index of the first indexed element + return descriptor( x.dtype, x.data, sh, sx, xmmv[ ind ], x.order ); + } +} + +/** +* Returns a function which copies an input ndarray to a contiguous ndarray workspace. +* +* @private +* @param {integer} len - number of elements in an ndarray +* @param {Object} workspace - ndarray workspace descriptor +* @returns {Function} function which copies an input ndarray to a contiguous ndarray workspace +*/ +function copyToWorkspace( len, workspace ) { + var view = descriptor( workspace.dtype, workspace.data, [ len ], [ 1 ], workspace.offset, workspace.order ); // eslint-disable-line max-len + return reshape; + + /** + * Copies an input ndarray to a contiguous ndarray workspace and returns a one-dimensional workspace view. + * + * @private + * @param {Object} x - input ndarray descriptor + * @returns {Object} one-dimensional workspace view descriptor + */ + function reshape( x ) { + assign( [ x, workspace ] ); + return view; + } +} + +/** +* Returns a function which copies from a contiguous ndarray workspace to an input ndarray. +* +* @private +* @param {Object} workspace - ndarray workspace descriptor +* @returns {Function} function which copies from a contiguous ndarray workspace to an input ndarray +*/ +function copyFromWorkspace( workspace ) { + return copy; + + /** + * Copies from a contiguous ndarray workspace to an input ndarray. + * + * @private + * @param {Object} x - input ndarray descriptor + * @returns {Object} input ndarray descriptor + */ + function copy( x ) { + assign( [ workspace, x ] ); + return x; + } +} + + +// MAIN // + +/** +* Returns an object containing methods for reshaping an ndarray as a one-dimensional strided array view. +* +* @param {Object} x - ndarray descriptor +* @param {*} x.dtype - ndarray data type +* @param {Collection} x.data - ndarray data buffer +* @param {Array} x.shape - ndarray shape +* @param {Array} x.strides - ndarray strides +* @param {integer} x.offset - ndarray index offset +* @param {string} x.order - ndarray memory layout +* @returns {Object} object containing methods implementing a reshape strategy +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* +* var x = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), +* 'shape': [ 1 ], +* 'strides': [ 1 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* var out = strategy( x ); +* // returns {...} +*/ +function strategy( x ) { + var workspace; + var ndims; + var xmmv; + var len; + var iox; + var sh; + var ns; + var i; + + // Resolve the number of array dimensions: + sh = x.shape; + ndims = sh.length; + + // Check whether the ndarray is zero-dimensional... + if ( ndims === 0 ) { + return { + 'input': broadcast, + 'output': identity + }; + } + // Check whether the ndarray is already one-dimensional... + if ( ndims === 1 ) { + return { + 'input': identity, + 'output': identity + }; + } + // Determine the number of singleton dimensions... + len = 1; // number of elements + ns = 0; // number of singleton dimensions + for ( i = 0; i < ndims; i++ ) { + // Check whether the current dimension is a singleton dimension... + if ( sh[ i ] === 1 ) { + ns += 1; + } + len *= sh[ i ]; + } + // Determine whether the ndarray has only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can simply create an ndarray view without the singleton dimensions... + if ( ns === ndims-1 ) { + // Get the index of the non-singleton dimension... + for ( i = 0; i < ndims; i++ ) { + if ( sh[ i ] !== 1 ) { + break; + } + } + return { + 'input': squeeze( x, i ), + 'output': identity + }; + } + iox = iterationOrder( x.strides ); // +/-1 + + // Determine whether we can avoid copying data... + if ( iox !== 0 ) { + // Determine the minimum and maximum linear indices which are accessible by the ndarray view: + xmmv = minmaxViewBufferIndex( sh, x.strides, x.offset, [ 0, 0 ] ); + + // Determine whether we can ignore shape (and strides) and create a new one-dimensional ndarray view... + if ( len === ( xmmv[1]-xmmv[0]+1 ) ) { + return { + 'input': contiguous( len, iox ), + 'output': identity + }; + } + // The ndarray is non-contiguous, so we cannot directly interpret as a one-dimensional ndarray... + + // Fall-through to copying to a workspace ndarray... + } + // At this point, we're dealing with a non-contiguous multi-dimensional ndarray, so we need to copy to a contiguous workspace: + workspace = ndarraylike2descriptor( empty( x.dtype, x.shape, x.order ) ); + return { + 'input': copyToWorkspace( len, workspace ), + 'output': copyFromWorkspace( workspace ) + }; +} + + +// EXPORTS // + +module.exports = strategy; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json new file mode 100644 index 000000000000..4090e40f792e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json @@ -0,0 +1,61 @@ +{ + "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy", + "version": "0.0.0", + "description": "Return an object containing methods for reshaping an ndarray as a one-dimensional strided array view.", + "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": { + "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", + "strided", + "ndarray", + "nullary", + "workspace", + "strategy", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js new file mode 100644 index 000000000000..5424549718c9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 strategy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof strategy, 'function', 'main export is a function' ); + t.end(); +}); + +// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md new file mode 100644 index 000000000000..e284fd4c4265 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md @@ -0,0 +1,807 @@ + + +# kernel + +> Return a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked' ); +``` + +#### kernel( ndims ) + +Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Resolve a kernel: +var f = kernel( 2 ); + +// Apply strided function: +f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +``` + +The function accepts the following arguments: + +- **ndims**: number of loop dimensions. + +If the function is provided an `ndims` value greater than the maximum number of supported loop dimensions, the function returns `null`. + +```javascript +var f = kernel( 100000 ); +// returns null +``` + +The returned function accepts the following arguments: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + +The returned function iterates over ndarray elements according to the memory layout of the input ndarray. + + + +#### kernel.kernel0d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 0 ]*10 ) + idx[ 1 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 4 ); + +// Define the array shape: +var xsh = [ 2, 2 ]; + +// Define the array strides: +var sx = [ 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Resolve an input strategy for the input ndarray: +var strategyX = strategy( x ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = []; +var cdims = [ 0, 1 ]; + +// Apply strided function: +kernel.kernel0d( gfillBy, [ x, start, end ], x, [], [], [], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have zero elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + +The `views`, `shape`, and `stridesX` parameters are unused. Providing empty arrays for these parameters is recommended in order to ensure a monomorphic API. + + + +#### kernel.kernel1d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 0 ]*100 ) + ( idx[ 1 ]*10 ) + idx[ 2 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 3 ], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 3 ], + 'strides': [ 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0 ]; +var cdims = [ 1, 2 ]; + +// Apply strided function: +kernel.kernel1d( gfillBy, [ x, start, end ], x, views, [ 3 ], [ 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have one element. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel2d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 3 ], + 'strides': [ 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1 ]; +var cdims = [ 2, 3 ]; + +// Apply strided function: +kernel.kernel2d( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have two elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel3d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Apply strided function: +kernel.kernel3d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have three elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + +
+ + + +
+ +## Notes + +- The strided array function is expected to have the following signature: + + ```text + fcn( arrays[, options], clbk ) + ``` + + where + + - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as subarrays. + - **options**: function options (_optional_). + - **clbk**: callback function. + +- The callback function is provided the following arguments: + + - **value**: current array element. + - **idx**: current array element indices. + - **arr**: the original input ndarray. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Resolve a kernel: +var f = kernel( 3 ); + +// Apply strided function: +f( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); +``` + +
+ + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt new file mode 100644 index 000000000000..2ec8fc903871 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt @@ -0,0 +1,254 @@ + +{{alias}}( ndims ) + Returns a kernel for applying a one-dimensional strided array function to + an input ndarray according to a callback function. + + The returned function has the following parameters: + + - fcn: function which will be applied to a one-dimensional input subarray + according to a callback function. + - arrays: array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + - ref: original input ndarray provided to a callback function. + - views: initialized ndarray descriptors representing subarray views. + - shape: loop dimensions. + - stridesX: loop dimension strides for the input ndarray. + - strategyX: strategy for marshaling data to and from an input ndarray + view. + - ibuf: workspace for storing iteration indices. + - ldims: list of loop dimensions. + - cdims: list of "core" dimensions. + - options: function options which are passed through to `fcn`. + - hasOpts: boolean indicating whether to pass an options argument to a + strided array function. + - clbk: callback function. + - thisArg: callback execution context. + + If `ndims` is greater than the maximum supported number of loop dimensions, + the function returns `null`. + + Parameters + ---------- + ndims: integer + Number of loop dimensions. + + Returns + ------- + fcn: Function|null + Kernel function. + + Examples + -------- + > var f = {{alias}}( 2 ) + + + +{{alias}}.kernel0d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + The `v`, `sh`, and `sx` parameters are unused. Providing empty arrays for + these parameters is recommended in order to ensure a monomorphic API. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have zero elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel1d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have one element. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel2d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have two elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel3d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any + additional ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have three elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js new file mode 100644 index 000000000000..1c93f3555ca7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js @@ -0,0 +1,120 @@ +/** +* @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. +*/ + +/* eslint-disable max-len */ + +'use strict'; + +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var kernel = require( './../lib' ); + +function clbk( value, idx ) { + return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 3 ], + 'strides': [ 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2 ]; +var cdims = [ 3, 4 ]; + +// Resolve a kernel: +var f = kernel( 3 ); + +// Apply strided function: +f( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js new file mode 100644 index 000000000000..48fd931d3ed9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js @@ -0,0 +1,139 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* ## Notes +* +* - The `views`, `shape`, and `stridesX` parameters are unused. Providing empty arrays for these parameters is recommended in order to ensure a monomorphic API. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 0 ]*10 ) + idx[ 1 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 4 ); +* +* // Define the array shape: +* var xsh = [ 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Resolve an input strategy for the input ndarray: +* var strategyX = strategy( x ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = []; +* var cdims = [ 0, 1 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, [], [], [], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var f; + + f = wrap( ref, arrays[ 0 ], ibuf, ldims, [], cdims, clbk, thisArg ); + arrays[ 0 ] = strategyX.input( arrays[ 0 ] ); + if ( hasOpts ) { + fcn( arrays, opts, f ); + } else { + fcn( arrays, f ); + } + strategyX.output( arrays[ 0 ] ); +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js new file mode 100644 index 000000000000..4d8f5a636450 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js @@ -0,0 +1,194 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 0 ]*100 ) + ( idx[ 1 ]*10 ) + idx[ 2 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 3 ], +* 'strides': [ 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 3 ], +* 'strides': [ 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0 ]; +* var cdims = [ 1, 2 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 3 ], [ 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var S0; + var iv; + var i0; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + S0 = shape[ 0 ]; + dv0 = [ + stridesX[0] + ]; + for ( i = 1; i < arrays.length; i++ ) { + dv0.push( arrays[i].strides[0] ); + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js new file mode 100644 index 000000000000..537e991a6dee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js @@ -0,0 +1,226 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var S0; + var S1; + var sv; + var iv; + var i0; + var i1; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 1 ]; + S1 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[1] + ]; + dv1 = [ // offset increment for outermost loop + stridesX[0] - ( S0*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[1] ); + dv1.push( sv[0] - ( S0*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ // offset increment for outermost loop + stridesX[1] - ( S0*stridesX[0] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js new file mode 100644 index 000000000000..86a0b4ef53e7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js @@ -0,0 +1,242 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 3 ], +* 'strides': [ 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 3 ], +* 'strides': [ 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2 ]; +* var cdims = [ 3, 4 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var S0; + var S1; + var S2; + var sv; + var iv; + var i0; + var i1; + var i2; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 2 ]; + S1 = shape[ 1 ]; + S2 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[2] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[2] ) + ]; + dv2 = [ // offset increment for outermost loop + stridesX[0] - ( S1*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[2] ); + dv1.push( sv[1] - ( S0*sv[2] ) ); + dv2.push( sv[0] - ( S1*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ // offset increment for outermost loop + stridesX[2] - ( S1*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/callback_wrapper.js new file mode 100644 index 000000000000..ad25b5d7bbcf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/callback_wrapper.js @@ -0,0 +1,72 @@ +/** +* @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 put = require( '@stdlib/array/base/put' ); +var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ).assign; +var zeros = require( '@stdlib/array/base/zeros' ); + + +// VARIABLES // + +var MODE = 'throw'; + + +// MAIN // + +/** +* Wraps a provided callback function. +* +* @private +* @param {ndarray} arr - input ndarray +* @param {ndarray} view - subarray view of the input ndarray +* @param {NonNegativeIntegerArray} idx - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - loop dimensions +* @param {NonNegativeIntegerArray} lidx - current loop iteration indices +* @param {NonNegativeIntegerArray} cdims - core dimensions +* @param {Function} clbk - callback function +* @param {thisArg} thisArg - callback execution context +* @returns {Function} callback wrapper +*/ +function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { + var cidx = zeros( cdims.length ); // workspace for storing core iteration indices + put( idx, ldims, lidx, MODE ); + return wrapper; + + /** + * Invokes a callback function. + * + * @private + * @param {*} v - value + * @param {NonNegativeInteger} aidx - current array element index + * @returns {*} result + */ + function wrapper( v, aidx ) { + ind2sub( view.shape, view.strides, view.offset, view.order, aidx, MODE, cidx ); // eslint-disable-line max-len + put( idx, cdims, cidx, MODE ); + return clbk.call( thisArg, v, idx.slice(), arr ); + } +} + + +// EXPORTS // + +module.exports = wrap; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js new file mode 100644 index 000000000000..1caf1719d9ef --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js @@ -0,0 +1,148 @@ +/** +* @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 one-dimensional strided array function to an input ndarray according to a callback function. +* +* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve a kernel: +* var f = kernel( 2 ); +* +* // Apply strided function: +* f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var kernel0d = require( './0d.js' ); +var kernel1d = require( './1d.js' ); +var kernel2d = require( './2d.js' ); +var kernel3d = require( './3d.js' ); +var main = require( './main.js' ); + + +// MAIN // + +setReadOnly( main, 'kernel0d', kernel0d ); +setReadOnly( main, 'kernel1d', kernel1d ); +setReadOnly( main, 'kernel2d', kernel2d ); +setReadOnly( main, 'kernel3d', kernel3d ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js new file mode 100644 index 000000000000..dab7e5fac81e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js @@ -0,0 +1,158 @@ +/** +* @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 kernel0d = require( './0d.js' ); +var kernel1d = require( './1d.js' ); +var kernel2d = require( './2d.js' ); +var kernel3d = require( './3d.js' ); + + +// VARIABLES // + +var KERNELS = [ + kernel0d, + kernel1d, + kernel2d, + kernel3d +]; +var MAX_DIMS = KERNELS.length - 1; + + +// MAIN // + +/** +* Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @param {integer} ndims - number of loop dimensions +* @returns {(Function|null)} kernel function or null +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 3 ], +* 'strides': [ 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1 ]; +* var cdims = [ 2, 3 ]; +* +* // Resolve a kernel: +* var f = kernel( 2 ); +* +* // Apply strided function: +* f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] +*/ +function kernel( ndims ) { + if ( ndims < 0 || ndims > MAX_DIMS ) { + return null; + } + return KERNELS[ ndims ]; +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/package.json new file mode 100644 index 000000000000..f5ce07248e21 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked", + "version": "0.0.0", + "description": "Return a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function.", + "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": { + "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", + "strided", + "array", + "ndarray", + "nullary", + "apply", + "fill", + "callback", + "vector", + "kernel" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/test/test.js new file mode 100644 index 000000000000..053851cfb7f7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/test/test.js @@ -0,0 +1,35 @@ +/** +* @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 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(); +}); + +// FIXME: add tests From 6f8b7c8a292898d58c82d97def18026b9654e367 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sun, 27 Sep 2026 22:49:23 +0500 Subject: [PATCH 2/4] fix: repl wrapping --- .../blocked/docs/repl.txt | 15 ++++++------ .../nullary-strided1d-by/linear/docs/repl.txt | 4 ++-- .../unblocked/docs/repl.txt | 23 +++++++++---------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt index 4c8057f0841f..7cb907bbedb9 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( ndims ) - Returns a kernel for applying a one-dimensional strided array function to - an input ndarray according to a callback function using loop blocking. + Returns a kernel for applying a one-dimensional strided array function to an + input ndarray according to a callback function using loop blocking. The returned function has the following parameters: @@ -13,8 +13,7 @@ - views: initialized ndarray descriptors representing subarray views. - shape: loop dimensions. - stridesX: loop dimension strides for the input ndarray. - - strategyX: strategy for marshaling data to and from an input ndarray - view. + - strategyX: strategy for marshaling data to and from an input ndarray view. - ibuf: workspace for storing iteration indices. - ldims: list of loop dimensions. - cdims: list of "core" dimensions. @@ -53,8 +52,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. @@ -104,8 +103,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt index 98d364017b81..8ca3bda05cc0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt @@ -12,8 +12,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt index 2ec8fc903871..37172b23a6ca 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( ndims ) - Returns a kernel for applying a one-dimensional strided array function to - an input ndarray according to a callback function. + Returns a kernel for applying a one-dimensional strided array function to an + input ndarray according to a callback function. The returned function has the following parameters: @@ -13,8 +13,7 @@ - views: initialized ndarray descriptors representing subarray views. - shape: loop dimensions. - stridesX: loop dimension strides for the input ndarray. - - strategyX: strategy for marshaling data to and from an input ndarray - view. + - strategyX: strategy for marshaling data to and from an input ndarray view. - ibuf: workspace for storing iteration indices. - ldims: list of loop dimensions. - cdims: list of "core" dimensions. @@ -56,8 +55,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. @@ -107,8 +106,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. @@ -158,8 +157,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. @@ -209,8 +208,8 @@ Wrapper for a one-dimensional strided array function. arr: Array - Array containing an input ndarray descriptor, followed by any - additional ndarray arguments. + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. ref: ndarray Original input ndarray provided to a callback function. From 070f8dfcb052a1f8524adc2c84ec06dbe0d67785 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 29 Sep 2026 15:49:29 +0500 Subject: [PATCH 3/4] refactor: apply suggestions from code review --- .../nullary-strided1d-by/blocked/README.md | 581 ------------------ .../blocked/docs/repl.txt | 148 ----- .../blocked/examples/index.js | 120 ---- .../nullary-strided1d-by/blocked/lib/2d.js | 256 -------- .../nullary-strided1d-by/blocked/lib/3d.js | 279 --------- .../blocked/lib/callback_wrapper.js | 72 --- .../nullary-strided1d-by/blocked/lib/index.js | 144 ----- .../nullary-strided1d-by/blocked/lib/main.js | 154 ----- .../nullary-strided1d-by/blocked/package.json | 65 -- .../nullary-strided1d-by/blocked/test/test.js | 35 -- .../nullary-strided1d-by/linear/README.md | 320 ---------- .../nullary-strided1d-by/linear/docs/repl.txt | 62 -- .../linear/examples/index.js | 117 ---- .../linear/lib/callback_wrapper.js | 72 --- .../nullary-strided1d-by/linear/lib/index.js | 132 ---- .../nullary-strided1d-by/linear/lib/main.js | 208 ------- .../nullary-strided1d-by/linear/package.json | 65 -- .../nullary-strided1d-by/linear/test/test.js | 35 -- .../nullary-strided1d-by/strategy/README.md | 207 ------- .../strategy/docs/repl.txt | 43 -- .../strategy/examples/index.js | 120 ---- .../strategy/lib/index.js | 50 -- .../nullary-strided1d-by/strategy/lib/main.js | 283 --------- .../strategy/package.json | 61 -- .../strategy/test/test.js | 35 -- .../nullary-strided1d-by/unblocked/README.md | 12 +- .../unblocked/examples/index.js | 2 +- .../nullary-strided1d-by/unblocked/lib/0d.js | 2 +- .../nullary-strided1d-by/unblocked/lib/1d.js | 2 +- .../nullary-strided1d-by/unblocked/lib/2d.js | 2 +- .../nullary-strided1d-by/unblocked/lib/3d.js | 2 +- .../unblocked/lib/index.js | 2 +- .../unblocked/lib/main.js | 2 +- 33 files changed, 13 insertions(+), 3677 deletions(-) delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json delete mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md deleted file mode 100644 index b94588359475..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/README.md +++ /dev/null @@ -1,581 +0,0 @@ - - -# kernel - -> Return a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. - -
- -
- - - -
- -## Usage - -```javascript -var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); -``` - -#### kernel( ndims ) - -Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); - -function clbk( value, idx ) { - return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1 ]; -var cdims = [ 2, 3 ]; - -// Resolve a kernel: -var f = kernel( 2 ); - -// Apply strided function: -f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -``` - -The function accepts the following arguments: - -- **ndims**: number of loop dimensions. - -If the function is provided `ndims < 2` or a value greater than the maximum number of supported loop dimensions, the function returns `null`. - -```javascript -var f = kernel( 100000 ); -// returns null -``` - -The returned function accepts the following arguments: - -- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. -- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. -- **ref**: original input ndarray provided to a callback function. -- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. -- **shape**: loop dimensions. -- **stridesX**: loop dimension strides for the input ndarray. -- **strategyX**: strategy for marshaling data to and from an input ndarray view. -- **ibuf**: workspace for storing iteration indices. -- **ldims**: list of loop dimensions. -- **cdims**: list of "core" dimensions. -- **options**: function options which are passed through to `fcn`. -- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. -- **clbk**: callback function. -- **thisArg**: callback execution context. - - - -#### kernel.kernel2d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) - - - -Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); - -function clbk( value, idx ) { - return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1 ]; -var cdims = [ 2, 3 ]; - -// Apply strided function: -kernel.kernel2d( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -``` - -The function has the following parameters: - -- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. -- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. -- **ref**: original input ndarray provided to a callback function. -- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. -- **shape**: loop dimensions. Should have two elements. -- **stridesX**: loop dimension strides for the input ndarray. -- **strategyX**: strategy for marshaling data to and from an input ndarray view. -- **ibuf**: workspace for storing iteration indices. -- **ldims**: list of loop dimensions. -- **cdims**: list of "core" dimensions. -- **options**: function options which are passed through to `fcn`. -- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. -- **clbk**: callback function. -- **thisArg**: callback execution context. - - - -#### kernel.kernel3d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) - - - -Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); - -function clbk( value, idx ) { - return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1, 2 ]; -var cdims = [ 3, 4 ]; - -// Apply strided function: -kernel.kernel3d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -// returns [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] -``` - -The function has the following parameters: - -- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. -- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. -- **ref**: original input ndarray provided to a callback function. -- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. -- **shape**: loop dimensions. Should have three elements. -- **stridesX**: loop dimension strides for the input ndarray. -- **strategyX**: strategy for marshaling data to and from an input ndarray view. -- **ibuf**: workspace for storing iteration indices. -- **ldims**: list of loop dimensions. -- **cdims**: list of "core" dimensions. -- **options**: function options which are passed through to `fcn`. -- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. -- **clbk**: callback function. -- **thisArg**: callback execution context. - -
- - - -
- -## Notes - -- The strided array function is expected to have the following signature: - - ```text - fcn( arrays[, options], clbk ) - ``` - - where - - - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as subarrays. - - **options**: function options (_optional_). - - **clbk**: callback function. - -- The callback function is provided the following arguments: - - - **value**: current array element. - - **idx**: current array element indices. - - **arr**: the original input ndarray. - -
- - - -
- -## Examples - - - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); - -function clbk( value, idx ) { - return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1, 2 ]; -var cdims = [ 3, 4 ]; - -// Resolve a kernel: -var f = kernel( 3 ); - -// Apply strided function: -f( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); -``` - -
- - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt deleted file mode 100644 index 7cb907bbedb9..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/docs/repl.txt +++ /dev/null @@ -1,148 +0,0 @@ - -{{alias}}( ndims ) - Returns a kernel for applying a one-dimensional strided array function to an - input ndarray according to a callback function using loop blocking. - - The returned function has the following parameters: - - - fcn: function which will be applied to a one-dimensional input subarray - according to a callback function. - - arrays: array containing an input ndarray descriptor, followed by any - additional ndarray arguments. - - ref: original input ndarray provided to a callback function. - - views: initialized ndarray descriptors representing subarray views. - - shape: loop dimensions. - - stridesX: loop dimension strides for the input ndarray. - - strategyX: strategy for marshaling data to and from an input ndarray view. - - ibuf: workspace for storing iteration indices. - - ldims: list of loop dimensions. - - cdims: list of "core" dimensions. - - options: function options which are passed through to `fcn`. - - hasOpts: boolean indicating whether to pass an options argument to a - strided array function. - - clbk: callback function. - - thisArg: callback execution context. - - If `ndims < 2` or greater than the maximum supported number of loop - dimensions, the function returns `null`. - - Parameters - ---------- - ndims: integer - Number of loop dimensions. - - Returns - ------- - fcn: Function|null - Kernel function. - - Examples - -------- - > var f = {{alias}}( 2 ) - - - -{{alias}}.kernel2d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) - Applies a one-dimensional strided array function to an input ndarray - according to a callback function via loop blocking. - - Parameters - ---------- - fcn: Function - Wrapper for a one-dimensional strided array function. - - arr: Array - Array containing an input ndarray descriptor, followed by any additional - ndarray arguments. - - ref: ndarray - Original input ndarray provided to a callback function. - - v: Array - Initialized ndarray descriptors representing subarray views. - - sh: Array - Loop dimensions. Should have two elements. - - sx: Array - Loop dimension strides for the input ndarray. - - st: Object - Strategy for marshaling data to and from an input ndarray view. - - ib: Array - Workspace for storing iteration indices. - - ld: Array - List of loop dimensions. - - cd: Array - List of "core" dimensions. - - o: Object - Function options which are passed through to `fcn`. - - po: boolean - Boolean indicating whether to pass an options argument to a strided - array function. - - cb: Function - Callback function. - - ctx: any - Callback execution context. - - -{{alias}}.kernel3d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) - Applies a one-dimensional strided array function to an input ndarray - according to a callback function via loop blocking. - - Parameters - ---------- - fcn: Function - Wrapper for a one-dimensional strided array function. - - arr: Array - Array containing an input ndarray descriptor, followed by any additional - ndarray arguments. - - ref: ndarray - Original input ndarray provided to a callback function. - - v: Array - Initialized ndarray descriptors representing subarray views. - - sh: Array - Loop dimensions. Should have three elements. - - sx: Array - Loop dimension strides for the input ndarray. - - st: Object - Strategy for marshaling data to and from an input ndarray view. - - ib: Array - Workspace for storing iteration indices. - - ld: Array - List of loop dimensions. - - cd: Array - List of "core" dimensions. - - o: Object - Function options which are passed through to `fcn`. - - po: boolean - Boolean indicating whether to pass an options argument to a strided - array function. - - cb: Function - Callback function. - - ctx: any - Callback execution context. - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js deleted file mode 100644 index 1c93f3555ca7..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/examples/index.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @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. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -var kernel = require( './../lib' ); - -function clbk( value, idx ) { - return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1, 2 ]; -var cdims = [ 3, 4 ]; - -// Resolve a kernel: -var f = kernel( 3 ); - -// Apply strided function: -f( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js deleted file mode 100644 index e9e05ffb1859..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/2d.js +++ /dev/null @@ -1,256 +0,0 @@ -/** -* @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. -*/ - -/* eslint-disable max-len, max-params */ - -'use strict'; - -// MODULES // - -var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); -var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); -var takeIndexed = require( '@stdlib/array/base/take-indexed' ); -var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); -var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); -var offsets = require( '@stdlib/ndarray/base/offsets' ); -var wrap = require( './callback_wrapper.js' ); - - -// MAIN // - -/** -* Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. -* -* @private -* @param {Function} fcn - wrapper for a one-dimensional strided array function -* @param {Array} arrays - ndarray descriptors -* @param {ndarrayLike} ref - original input ndarray provided to a callback function -* @param {Array} views - initialized ndarray descriptors representing subarray views -* @param {Array} shape - loop dimensions -* @param {Array} stridesX - loop dimension strides for the input ndarray -* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view -* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices -* @param {NonNegativeIntegerArray} ldims - list of loop dimensions -* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions -* @param {Options} opts - function options -* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function -* @param {Function} clbk - callback function -* @param {*} thisArg - callback execution context -* @returns {void} -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -* var zeros = require( '@stdlib/array/base/zeros' ); -* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* -* function clbk( value, idx ) { -* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -* } -* -* // Create a data buffer: -* var xbuf = new Float64Array( 12 ); -* -* // Define the array shape: -* var xsh = [ 1, 3, 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 12, 4, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray descriptor: -* var x = { -* 'dtype': 'float64', -* 'data': xbuf, -* 'shape': xsh, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the starting index (inclusive): -* var start = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 0.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the ending index (exclusive): -* var end = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 4.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Initialize ndarray descriptors representing subarray views: -* var views = [ -* { -* 'dtype': x.dtype, -* 'data': x.data, -* 'shape': [ 2, 2 ], -* 'strides': [ 2, 1 ], -* 'offset': x.offset, -* 'order': x.order -* }, -* { -* 'dtype': start.dtype, -* 'data': start.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': start.offset, -* 'order': start.order -* }, -* { -* 'dtype': end.dtype, -* 'data': end.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': end.offset, -* 'order': end.order -* } -* ]; -* -* // Resolve an input strategy when iterating over subarray views: -* var strategyX = strategy( views[ 0 ] ); -* -* // Create a workspace array for storing iteration indices: -* var ibuf = zeros( xsh.length ); -* -* // Define the loop and core dimensions: -* var ldims = [ 0, 1 ]; -* var cdims = [ 2, 3 ]; -* -* // Apply strided function: -* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); -* -* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -*/ -function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { - var bsize; - var dv0; - var dv1; - var ov1; - var sh; - var s0; - var s1; - var sv; - var ov; - var iv; - var i0; - var i1; - var j0; - var j1; - var N; - var x; - var v; - var o; - var k; - var f; - - // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... - - N = arrays.length; - x = arrays[ 0 ]; - - // Resolve the loop interchange order: - o = loopOrder( shape, stridesX ); - sh = o.sh; - sv = [ o.sx ]; - for ( k = 1; k < N; k++ ) { - sv.push( takeIndexed( arrays[k].strides, o.idx ) ); - } - // Determine the block size: - bsize = blockSize( x.dtype ); - - // Resolve a list of pointers to the first indexed elements in the respective ndarrays: - ov = offsets( arrays ); - - // Cache offset increments for the innermost loop... - dv0 = []; - for ( k = 0; k < N; k++ ) { - dv0.push( sv[k][0] ); - } - // Initialize loop variables... - ov1 = zeros( N ); - dv1 = zeros( N ); - iv = zeros( N ); - - // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: - v = copyIndexed( views ); - - // Iterate over blocks... - for ( j1 = sh[1]; j1 > 0; ) { - if ( j1 < bsize ) { - s1 = j1; - j1 = 0; - } else { - s1 = bsize; - j1 -= bsize; - } - for ( k = 0; k < N; k++ ) { - ov1[ k ] = ov[k] + ( j1*sv[k][1] ); - } - for ( j0 = sh[0]; j0 > 0; ) { - if ( j0 < bsize ) { - s0 = j0; - j0 = 0; - } else { - s0 = bsize; - j0 -= bsize; - } - // Compute index offsets and loop offset increments for the first ndarray elements in the current block... - for ( k = 0; k < N; k++ ) { - iv[ k ] = ov1[k] + ( j0*sv[k][0] ); - dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); - } - // Iterate over the loop dimensions... - for ( i1 = 0; i1 < s1; i1++ ) { - for ( i0 = 0; i0 < s0; i0++ ) { - setViewOffsets( views, iv ); - v[ 0 ] = strategyX.input( views[ 0 ] ); - f = wrap( ref, views[ 0 ], ibuf, ldims, [ j1+i1, j0+i0 ], cdims, clbk, thisArg ); - if ( hasOpts ) { - fcn( v, opts, f ); - } else { - fcn( v, f ); - } - strategyX.output( views[ 0 ] ); - incrementOffsets( iv, dv0 ); - } - incrementOffsets( iv, dv1 ); - } - } - } -} - - -// EXPORTS // - -module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js deleted file mode 100644 index d6509e37e361..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/3d.js +++ /dev/null @@ -1,279 +0,0 @@ -/** -* @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. -*/ - -/* eslint-disable max-len, max-params, max-depth */ - -'use strict'; - -// MODULES // - -var loopOrder = require( '@stdlib/ndarray/base/nullary-loop-interchange-order' ); -var blockSize = require( '@stdlib/ndarray/base/nullary-tiling-block-size' ); -var takeIndexed = require( '@stdlib/array/base/take-indexed' ); -var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); -var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); -var offsets = require( '@stdlib/ndarray/base/offsets' ); -var wrap = require( './callback_wrapper.js' ); - - -// MAIN // - -/** -* Applies a one-dimensional strided array function to an input ndarray according to a callback function via loop blocking. -* -* @private -* @param {Function} fcn - wrapper for a one-dimensional strided array function -* @param {Array} arrays - ndarray descriptors -* @param {ndarrayLike} ref - original input ndarray provided to a callback function -* @param {Array} views - initialized ndarray descriptors representing subarray views -* @param {Array} shape - loop dimensions -* @param {Array} stridesX - loop dimension strides for the input ndarray -* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view -* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices -* @param {NonNegativeIntegerArray} ldims - list of loop dimensions -* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions -* @param {Options} opts - function options -* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function -* @param {Function} clbk - callback function -* @param {*} thisArg - callback execution context -* @returns {void} -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -* var zeros = require( '@stdlib/array/base/zeros' ); -* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* -* function clbk( value, idx ) { -* return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; -* } -* -* // Create a data buffer: -* var xbuf = new Float64Array( 12 ); -* -* // Define the array shape: -* var xsh = [ 1, 1, 3, 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 12, 12, 4, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray descriptor: -* var x = { -* 'dtype': 'float64', -* 'data': xbuf, -* 'shape': xsh, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the starting index (inclusive): -* var start = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 0.0 ] ), -* 'shape': [ 1, 1, 3 ], -* 'strides': [ 0, 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the ending index (exclusive): -* var end = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 4.0 ] ), -* 'shape': [ 1, 1, 3 ], -* 'strides': [ 0, 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Initialize ndarray descriptors representing subarray views: -* var views = [ -* { -* 'dtype': x.dtype, -* 'data': x.data, -* 'shape': [ 2, 2 ], -* 'strides': [ 2, 1 ], -* 'offset': x.offset, -* 'order': x.order -* }, -* { -* 'dtype': start.dtype, -* 'data': start.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': start.offset, -* 'order': start.order -* }, -* { -* 'dtype': end.dtype, -* 'data': end.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': end.offset, -* 'order': end.order -* } -* ]; -* -* // Resolve an input strategy when iterating over subarray views: -* var strategyX = strategy( views[ 0 ] ); -* -* // Create a workspace array for storing iteration indices: -* var ibuf = zeros( xsh.length ); -* -* // Define the loop and core dimensions: -* var ldims = [ 0, 1, 2 ]; -* var cdims = [ 3, 4 ]; -* -* // Apply strided function: -* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); -* -* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -* // returns [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] -*/ -function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { - var bsize; - var dv0; - var dv1; - var dv2; - var ov1; - var ov2; - var sh; - var s0; - var s1; - var s2; - var sv; - var ov; - var iv; - var i0; - var i1; - var i2; - var j0; - var j1; - var j2; - var N; - var x; - var v; - var o; - var k; - var f; - - // Note on variable naming convention: S#, dv#, i#, j# where # corresponds to the loop number, with `0` being the innermost loop... - - N = arrays.length; - x = arrays[ 0 ]; - - // Resolve the loop interchange order: - o = loopOrder( shape, stridesX ); - sh = o.sh; - sv = [ o.sx ]; - for ( k = 1; k < N; k++ ) { - sv.push( takeIndexed( arrays[k].strides, o.idx ) ); - } - // Determine the block size: - bsize = blockSize( x.dtype ); - - // Resolve a list of pointers to the first indexed elements in the respective ndarrays: - ov = offsets( arrays ); - - // Cache offset increments for the innermost loop... - dv0 = []; - for ( k = 0; k < N; k++ ) { - dv0.push( sv[k][0] ); - } - // Initialize loop variables... - ov1 = zeros( N ); - ov2 = zeros( N ); - dv1 = zeros( N ); - dv2 = zeros( N ); - iv = zeros( N ); - - // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: - v = copyIndexed( views ); - - // Iterate over blocks... - for ( j2 = sh[2]; j2 > 0; ) { - if ( j2 < bsize ) { - s2 = j2; - j2 = 0; - } else { - s2 = bsize; - j2 -= bsize; - } - for ( k = 0; k < N; k++ ) { - ov2[ k ] = ov[k] + ( j2*sv[k][2] ); - } - for ( j1 = sh[1]; j1 > 0; ) { - if ( j1 < bsize ) { - s1 = j1; - j1 = 0; - } else { - s1 = bsize; - j1 -= bsize; - } - for ( k = 0; k < N; k++ ) { - ov1[ k ] = ov2[k] + ( j1*sv[k][1] ); - dv2[ k ] = sv[k][2] - ( s1*sv[k][1] ); - } - for ( j0 = sh[0]; j0 > 0; ) { - if ( j0 < bsize ) { - s0 = j0; - j0 = 0; - } else { - s0 = bsize; - j0 -= bsize; - } - // Compute index offsets and loop offset increments for the first ndarray elements in the current block... - for ( k = 0; k < N; k++ ) { - iv[ k ] = ov1[k] + ( j0*sv[k][0] ); - dv1[ k ] = sv[k][1] - ( s0*sv[k][0] ); - } - // Iterate over the loop dimensions... - for ( i2 = 0; i2 < s2; i2++ ) { - for ( i1 = 0; i1 < s1; i1++ ) { - for ( i0 = 0; i0 < s0; i0++ ) { - setViewOffsets( views, iv ); - v[ 0 ] = strategyX.input( views[ 0 ] ); - f = wrap( ref, views[ 0 ], ibuf, ldims, [ j2+i2, j1+i1, j0+i0 ], cdims, clbk, thisArg ); - if ( hasOpts ) { - fcn( v, opts, f ); - } else { - fcn( v, f ); - } - strategyX.output( views[ 0 ] ); - incrementOffsets( iv, dv0 ); - } - incrementOffsets( iv, dv1 ); - } - incrementOffsets( iv, dv2 ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js deleted file mode 100644 index ad25b5d7bbcf..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/callback_wrapper.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @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 put = require( '@stdlib/array/base/put' ); -var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ).assign; -var zeros = require( '@stdlib/array/base/zeros' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Wraps a provided callback function. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {ndarray} view - subarray view of the input ndarray -* @param {NonNegativeIntegerArray} idx - workspace for storing iteration indices -* @param {NonNegativeIntegerArray} ldims - loop dimensions -* @param {NonNegativeIntegerArray} lidx - current loop iteration indices -* @param {NonNegativeIntegerArray} cdims - core dimensions -* @param {Function} clbk - callback function -* @param {thisArg} thisArg - callback execution context -* @returns {Function} callback wrapper -*/ -function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { - var cidx = zeros( cdims.length ); // workspace for storing core iteration indices - put( idx, ldims, lidx, MODE ); - return wrapper; - - /** - * Invokes a callback function. - * - * @private - * @param {*} v - value - * @param {NonNegativeInteger} aidx - current array element index - * @returns {*} result - */ - function wrapper( v, aidx ) { - ind2sub( view.shape, view.strides, view.offset, view.order, aidx, MODE, cidx ); // eslint-disable-line max-len - put( idx, cdims, cidx, MODE ); - return clbk.call( thisArg, v, idx.slice(), arr ); - } -} - - -// EXPORTS // - -module.exports = wrap; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js deleted file mode 100644 index dfdf4d55e482..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/index.js +++ /dev/null @@ -1,144 +0,0 @@ -/** -* @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 one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. -* -* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -* var zeros = require( '@stdlib/array/base/zeros' ); -* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); -* -* function clbk( value, idx ) { -* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -* } -* -* // Create a data buffer: -* var xbuf = new Float64Array( 12 ); -* -* // Define the array shape: -* var xsh = [ 1, 3, 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 12, 4, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray descriptor: -* var x = { -* 'dtype': 'float64', -* 'data': xbuf, -* 'shape': xsh, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the starting index (inclusive): -* var start = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 0.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the ending index (exclusive): -* var end = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 4.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Initialize ndarray descriptors representing subarray views: -* var views = [ -* { -* 'dtype': x.dtype, -* 'data': x.data, -* 'shape': [ 2, 2 ], -* 'strides': [ 2, 1 ], -* 'offset': x.offset, -* 'order': x.order -* }, -* { -* 'dtype': start.dtype, -* 'data': start.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': start.offset, -* 'order': start.order -* }, -* { -* 'dtype': end.dtype, -* 'data': end.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': end.offset, -* 'order': end.order -* } -* ]; -* -* // Resolve an input strategy when iterating over subarray views: -* var strategyX = strategy( views[ 0 ] ); -* -* // Create a workspace array for storing iteration indices: -* var ibuf = zeros( xsh.length ); -* -* // Define the loop and core dimensions: -* var ldims = [ 0, 1 ]; -* var cdims = [ 2, 3 ]; -* -* // Resolve a kernel: -* var f = kernel( 2 ); -* -* // Apply strided function: -* f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); -* -* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -*/ - -// MODULES // - -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var kernel2d = require( './2d.js' ); -var kernel3d = require( './3d.js' ); -var main = require( './main.js' ); - - -// MAIN // - -setReadOnly( main, 'kernel2d', kernel2d ); -setReadOnly( main, 'kernel3d', kernel3d ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js deleted file mode 100644 index 074af133012f..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/lib/main.js +++ /dev/null @@ -1,154 +0,0 @@ -/** -* @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 kernel2d = require( './2d.js' ); -var kernel3d = require( './3d.js' ); - - -// VARIABLES // - -var KERNELS = [ - kernel2d, - kernel3d -]; -var MAX_DIMS = KERNELS.length + 1; - - -// MAIN // - -/** -* Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking. -* -* @param {integer} ndims - number of loop dimensions -* @returns {(Function|null)} kernel function or null -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -* var zeros = require( '@stdlib/array/base/zeros' ); -* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* -* function clbk( value, idx ) { -* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -* } -* -* // Create a data buffer: -* var xbuf = new Float64Array( 12 ); -* -* // Define the array shape: -* var xsh = [ 1, 3, 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 12, 4, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray descriptor: -* var x = { -* 'dtype': 'float64', -* 'data': xbuf, -* 'shape': xsh, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the starting index (inclusive): -* var start = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 0.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the ending index (exclusive): -* var end = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 4.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Initialize ndarray descriptors representing subarray views: -* var views = [ -* { -* 'dtype': x.dtype, -* 'data': x.data, -* 'shape': [ 2, 2 ], -* 'strides': [ 2, 1 ], -* 'offset': x.offset, -* 'order': x.order -* }, -* { -* 'dtype': start.dtype, -* 'data': start.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': start.offset, -* 'order': start.order -* }, -* { -* 'dtype': end.dtype, -* 'data': end.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': end.offset, -* 'order': end.order -* } -* ]; -* -* // Resolve an input strategy when iterating over subarray views: -* var strategyX = strategy( views[ 0 ] ); -* -* // Create a workspace array for storing iteration indices: -* var ibuf = zeros( xsh.length ); -* -* // Define the loop and core dimensions: -* var ldims = [ 0, 1 ]; -* var cdims = [ 2, 3 ]; -* -* // Resolve a kernel: -* var f = kernel( 2 ); -* -* // Apply strided function: -* f( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); -* -* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -*/ -function kernel( ndims ) { - if ( ndims < 2 || ndims > MAX_DIMS ) { - return null; - } - return KERNELS[ ndims-2 ]; -} - - -// EXPORTS // - -module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json deleted file mode 100644 index 5b9f3be3c9bc..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/package.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked", - "version": "0.0.0", - "description": "Return a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using loop blocking.", - "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": { - "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", - "strided", - "array", - "ndarray", - "nullary", - "apply", - "fill", - "callback", - "vector", - "kernel", - "blocked" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js deleted file mode 100644 index 053851cfb7f7..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @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 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(); -}); - -// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md deleted file mode 100644 index 538a115ff2ea..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md +++ /dev/null @@ -1,320 +0,0 @@ - - -# kernel - -> Apply a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. - -
- -
- - - -
- -## Usage - -```javascript -var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear' ); -``` - - - -#### kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) - - - -Applies a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); - -function clbk( value, idx ) { - return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1 ]; -var cdims = [ 2, 3 ]; - -// Apply strided function: -kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -// returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -``` - -The function has the following parameters: - -- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. -- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. -- **ref**: original input ndarray provided to a callback function. -- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. -- **shape**: loop dimensions. -- **stridesX**: loop dimension strides for the input ndarray. -- **strategyX**: strategy for marshaling data to and from an input ndarray view. -- **ibuf**: workspace for storing iteration indices. -- **ldims**: list of loop dimensions. -- **cdims**: list of "core" dimensions. -- **options**: function options which are passed through to `fcn`. -- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. -- **clbk**: callback function. -- **thisArg**: callback execution context. - -The function iterates based on the linear **view** index, regardless as to how the data is stored in memory. - -
- - - -
- -## Notes - -- The strided array function is expected to have the following signature: - - ```text - fcn( arrays[, options], clbk ) - ``` - - where - - - **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as subarrays. - - **options**: function options (_optional_). - - **clbk**: callback function. - -- The callback function is provided the following arguments: - - - **value**: current array element. - - **idx**: current array element indices. - - **arr**: the original input ndarray. - -
- - - -
- -## Examples - - - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear' ); - -function clbk( value, idx ) { - return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1, 2 ]; -var cdims = [ 3, 4 ]; - -// Apply strided function: -kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); -``` - -
- - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt deleted file mode 100644 index 8ca3bda05cc0..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt +++ /dev/null @@ -1,62 +0,0 @@ - -{{alias}}( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) - Applies a one-dimensional strided array function to an input ndarray - according to a callback function using linear view iteration. - - The function iterates based on the linear view index, regardless as to how - the data is stored in memory. - - Parameters - ---------- - fcn: Function - Wrapper for a one-dimensional strided array function. - - arr: Array - Array containing an input ndarray descriptor, followed by any additional - ndarray arguments. - - ref: ndarray - Original input ndarray provided to a callback function. - - v: Array - Initialized ndarray descriptors representing subarray views. - - sh: Array - Loop dimensions. - - sx: Array - Loop dimension strides for the input ndarray. - - st: Object - Strategy for marshaling data to and from an input ndarray view. - - ib: Array - Workspace for storing iteration indices. - - ld: Array - List of loop dimensions. - - cd: Array - List of "core" dimensions. - - o: Object - Function options which are passed through to `fcn`. - - po: boolean - Boolean indicating whether to pass an options argument to a strided - array function. - - cb: Function - Callback function. - - ctx: any - Callback execution context. - - Examples - -------- - > var f = {{alias}} - - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js deleted file mode 100644 index c56bd7b29f93..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/examples/index.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @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. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -var kernel = require( './../lib' ); - -function clbk( value, idx ) { - return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 1, 3 ], - 'strides': [ 0, 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1, 2 ]; -var cdims = [ 3, 4 ]; - -// Apply strided function: -kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 3 ], [ 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js deleted file mode 100644 index ad25b5d7bbcf..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/callback_wrapper.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @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 put = require( '@stdlib/array/base/put' ); -var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ).assign; -var zeros = require( '@stdlib/array/base/zeros' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Wraps a provided callback function. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {ndarray} view - subarray view of the input ndarray -* @param {NonNegativeIntegerArray} idx - workspace for storing iteration indices -* @param {NonNegativeIntegerArray} ldims - loop dimensions -* @param {NonNegativeIntegerArray} lidx - current loop iteration indices -* @param {NonNegativeIntegerArray} cdims - core dimensions -* @param {Function} clbk - callback function -* @param {thisArg} thisArg - callback execution context -* @returns {Function} callback wrapper -*/ -function wrap( arr, view, idx, ldims, lidx, cdims, clbk, thisArg ) { - var cidx = zeros( cdims.length ); // workspace for storing core iteration indices - put( idx, ldims, lidx, MODE ); - return wrapper; - - /** - * Invokes a callback function. - * - * @private - * @param {*} v - value - * @param {NonNegativeInteger} aidx - current array element index - * @returns {*} result - */ - function wrapper( v, aidx ) { - ind2sub( view.shape, view.strides, view.offset, view.order, aidx, MODE, cidx ); // eslint-disable-line max-len - put( idx, cdims, cidx, MODE ); - return clbk.call( thisArg, v, idx.slice(), arr ); - } -} - - -// EXPORTS // - -module.exports = wrap; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js deleted file mode 100644 index 7d47221b96d7..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js +++ /dev/null @@ -1,132 +0,0 @@ -/** -* @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'; - -/** -* Apply a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. -* -* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -* var zeros = require( '@stdlib/array/base/zeros' ); -* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear' ); -* -* function clbk( value, idx ) { -* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -* } -* -* // Create a data buffer: -* var xbuf = new Float64Array( 12 ); -* -* // Define the array shape: -* var xsh = [ 1, 3, 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 12, 4, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray descriptor: -* var x = { -* 'dtype': 'float64', -* 'data': xbuf, -* 'shape': xsh, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the starting index (inclusive): -* var start = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 0.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the ending index (exclusive): -* var end = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 4.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Initialize ndarray descriptors representing subarray views: -* var views = [ -* { -* 'dtype': x.dtype, -* 'data': x.data, -* 'shape': [ 2, 2 ], -* 'strides': [ 2, 1 ], -* 'offset': x.offset, -* 'order': x.order -* }, -* { -* 'dtype': start.dtype, -* 'data': start.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': start.offset, -* 'order': start.order -* }, -* { -* 'dtype': end.dtype, -* 'data': end.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': end.offset, -* 'order': end.order -* } -* ]; -* -* // Resolve an input strategy when iterating over subarray views: -* var strategyX = strategy( views[ 0 ] ); -* -* // Create a workspace array for storing iteration indices: -* var ibuf = zeros( xsh.length ); -* -* // Define the loop and core dimensions: -* var ldims = [ 0, 1 ]; -* var cdims = [ 2, 3 ]; -* -* // Apply strided function: -* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); -* -* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js deleted file mode 100644 index dee8637de4e2..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.js +++ /dev/null @@ -1,208 +0,0 @@ -/** -* @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. -*/ - -/* eslint-disable max-len, max-params */ - -'use strict'; - -// MODULES // - -var numel = require( '@stdlib/ndarray/base/numel' ); -var vind2bind = require( '@stdlib/ndarray/base/vind2bind' ); -var ind2sub = require( '@stdlib/ndarray/base/ind2sub' ); -var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); -var offsets = require( '@stdlib/ndarray/base/offsets' ); -var wrap = require( './callback_wrapper.js' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Applies a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. -* -* @param {Function} fcn - wrapper for a one-dimensional strided array function -* @param {Array} arrays - ndarray descriptors -* @param {ndarrayLike} ref - original input ndarray provided to a callback function -* @param {Array} views - initialized ndarray descriptors representing subarray views -* @param {Array} shape - loop dimensions -* @param {Array} stridesX - loop dimension strides for the input ndarray -* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view -* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices -* @param {NonNegativeIntegerArray} ldims - list of loop dimensions -* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions -* @param {Options} opts - function options -* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function -* @param {Function} clbk - callback function -* @param {*} thisArg - callback execution context -* @returns {void} -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -* var zeros = require( '@stdlib/array/base/zeros' ); -* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* -* function clbk( value, idx ) { -* return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -* } -* -* // Create a data buffer: -* var xbuf = new Float64Array( 12 ); -* -* // Define the array shape: -* var xsh = [ 1, 3, 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 12, 4, 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Create an input ndarray descriptor: -* var x = { -* 'dtype': 'float64', -* 'data': xbuf, -* 'shape': xsh, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the starting index (inclusive): -* var start = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 0.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Create an ndarray descriptor for the ending index (exclusive): -* var end = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 4.0 ] ), -* 'shape': [ 1, 3 ], -* 'strides': [ 0, 0 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* // Initialize ndarray descriptors representing subarray views: -* var views = [ -* { -* 'dtype': x.dtype, -* 'data': x.data, -* 'shape': [ 2, 2 ], -* 'strides': [ 2, 1 ], -* 'offset': x.offset, -* 'order': x.order -* }, -* { -* 'dtype': start.dtype, -* 'data': start.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': start.offset, -* 'order': start.order -* }, -* { -* 'dtype': end.dtype, -* 'data': end.data, -* 'shape': [], -* 'strides': [ 0 ], -* 'offset': end.offset, -* 'order': end.order -* } -* ]; -* -* // Resolve an input strategy when iterating over subarray views: -* var strategyX = strategy( views[ 0 ] ); -* -* // Create a workspace array for storing iteration indices: -* var ibuf = zeros( xsh.length ); -* -* // Define the loop and core dimensions: -* var ldims = [ 0, 1 ]; -* var cdims = [ 2, 3 ]; -* -* // Apply strided function: -* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); -* -* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); -* // returns [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] -*/ -function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { - var len; - var arr; - var sub; - var iv; - var io; - var N; - var x; - var v; - var i; - var j; - var f; - - N = arrays.length; - - // Cache a reference to the input ndarray: - x = arrays[ 0 ]; - - // Compute the total number of elements over which to iterate: - len = numel( shape ); - - // Resolve a list of pointers to the first indexed elements in the respective ndarrays: - iv = offsets( arrays ); - - // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: - v = copyIndexed( views ); - - // Iterate based on the linear **view** index, regardless as to how the data is stored in memory... - io = zeros( N ); - for ( i = 0; i < len; i++ ) { - for ( j = 0; j < N; j++ ) { - arr = arrays[ j ]; - io[ j ] = vind2bind( shape, arr.strides, iv[ j ], arr.order, i, MODE ); - } - setViewOffsets( views, io ); - v[ 0 ] = strategyX.input( views[ 0 ] ); - sub = ind2sub( shape, stridesX, 0, x.order, i, MODE ); - f = wrap( ref, views[ 0 ], ibuf, ldims, sub, cdims, clbk, thisArg ); - if ( hasOpts ) { - fcn( v, opts, f ); - } else { - fcn( v, f ); - } - strategyX.output( views[ 0 ] ); - } -} - - -// EXPORTS // - -module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json deleted file mode 100644 index 909513f56257..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/package.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear", - "version": "0.0.0", - "description": "Apply a one-dimensional strided array function to an input ndarray according to a callback function 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": { - "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", - "strided", - "array", - "ndarray", - "nullary", - "apply", - "fill", - "callback", - "vector", - "kernel", - "linear" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js deleted file mode 100644 index 053851cfb7f7..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @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 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(); -}); - -// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md deleted file mode 100644 index d16c35374a8e..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/README.md +++ /dev/null @@ -1,207 +0,0 @@ - - -# strategy - -> Return an object containing methods for reshaping an ndarray as a one-dimensional strided array view. - -
- -
- - - -
- -## Usage - -```javascript -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -``` - -#### strategy( x ) - -Returns an object containing methods for reshaping an ndarray as a one-dimensional strided array view. - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); - -var x = { - 'dtype': 'float64', - 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), - 'shape': [ 1 ], - 'strides': [ 1 ], - 'offset': 0, - 'order': 'row-major' -}; - -var out = strategy( x ); -// returns {...} -``` - -The function accepts the following arguments: - -- **x**: ndarray [descriptor][@stdlib/ndarray/base/descriptor]. - -
- - - -
- -## Notes - -- The function returns an object having the following properties: - - - **input**: function providing a strategy for reshaping an input ndarray to a one-dimensional input ndarray view **prior** to applying a one-dimensional strided array function. - - **output**: function providing a strategy for reshaping the results of a one-dimensional strided array function to the shape of an input ndarray **after** applying a one-dimensional strided array function. This function should only be invoked for input ndarrays which are written to by the one-dimensional strided array function. - -
- - - -
- -## Examples - - - - - -```javascript -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var resolveKernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); - -function clbk( value, idx ) { - return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1 ]; -var cdims = [ 2, 3 ]; - -// Resolve a kernel: -var kernel = resolveKernel( 2 ); - -// Apply strided function: -kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); -``` - -
- - - - - - - - - - - - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt deleted file mode 100644 index cda7cabbf51b..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/docs/repl.txt +++ /dev/null @@ -1,43 +0,0 @@ - -{{alias}}( x ) - Returns an object containing methods for reshaping an ndarray as a one- - dimensional strided array view. - - Parameters - ---------- - x: Object - Descriptor. - - Returns - ------- - out: Object - Object containing an input and output strategy. - - out.input: Function - Function providing a strategy for reshaping an input ndarray to a one- - dimensional input ndarray view prior to applying a one-dimensional - strided array function. - - out.output: Function - Function providing a strategy for reshaping the results of a one- - dimensional strided array function to the shape of an input ndarray - after applying a one-dimensional strided array function. This function - should only be invoked for input ndarrays which are written to by the - one-dimensional strided array function. - - Examples - -------- - > var x = { - ... 'dtype': 'float64', - ... 'data': new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ), - ... 'shape': [ 1 ], - ... 'strides': [ 1 ], - ... 'offset': 0, - ... 'order': 'row-major' - ... }; - > var o = {{alias}}( x ) - {...} - - See Also - -------- - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js deleted file mode 100644 index 2a60cb1f1a45..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/examples/index.js +++ /dev/null @@ -1,120 +0,0 @@ -/** -* @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. -*/ - -/* eslint-disable max-len */ - -'use strict'; - -var Float64Array = require( '@stdlib/array/float64' ); -var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); -var zeros = require( '@stdlib/array/base/zeros' ); -var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var resolveKernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/blocked' ); -var strategy = require( './../lib' ); - -function clbk( value, idx ) { - return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; -} - -// Create a data buffer: -var xbuf = new Float64Array( 12 ); - -// Define the array shape: -var xsh = [ 1, 3, 2, 2 ]; - -// Define the array strides: -var sx = [ 12, 4, 2, 1 ]; - -// Define the index offset: -var ox = 0; - -// Create an input ndarray descriptor: -var x = { - 'dtype': 'float64', - 'data': xbuf, - 'shape': xsh, - 'strides': sx, - 'offset': ox, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the starting index (inclusive): -var start = { - 'dtype': 'float64', - 'data': new Float64Array( [ 0.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Create an ndarray descriptor for the ending index (exclusive): -var end = { - 'dtype': 'float64', - 'data': new Float64Array( [ 4.0 ] ), - 'shape': [ 1, 3 ], - 'strides': [ 0, 0 ], - 'offset': 0, - 'order': 'row-major' -}; - -// Initialize ndarray descriptors representing subarray views: -var views = [ - { - 'dtype': x.dtype, - 'data': x.data, - 'shape': [ 2, 2 ], - 'strides': [ 2, 1 ], - 'offset': x.offset, - 'order': x.order - }, - { - 'dtype': start.dtype, - 'data': start.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': start.offset, - 'order': start.order - }, - { - 'dtype': end.dtype, - 'data': end.data, - 'shape': [], - 'strides': [ 0 ], - 'offset': end.offset, - 'order': end.order - } -]; - -// Resolve an input strategy when iterating over subarray views: -var strategyX = strategy( views[ 0 ] ); - -// Create a workspace array for storing iteration indices: -var ibuf = zeros( xsh.length ); - -// Define the loop and core dimensions: -var ldims = [ 0, 1 ]; -var cdims = [ 2, 3 ]; - -// Resolve a kernel: -var kernel = resolveKernel( 2 ); - -// Apply strided function: -kernel( gfillBy, [ x, start, end ], x, views, [ 1, 3 ], [ 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); - -console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js deleted file mode 100644 index d656140f45fa..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/index.js +++ /dev/null @@ -1,50 +0,0 @@ -/** -* @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 an object containing methods for reshaping an ndarray as a one-dimensional strided array view. -* -* @module @stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); -* -* var x = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), -* 'shape': [ 1 ], -* 'strides': [ 1 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* var out = strategy( x ); -* // returns {...} -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js deleted file mode 100644 index 45d344b42a93..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/lib/main.js +++ /dev/null @@ -1,283 +0,0 @@ -/** -* @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 iterationOrder = require( '@stdlib/ndarray/base/iteration-order' ); -var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' ).assign; -var ndarraylike2descriptor = require( '@stdlib/ndarray/base/ndarraylike2descriptor' ); -var assign = require( '@stdlib/ndarray/base/assign' ); -var descriptor = require( '@stdlib/ndarray/base/descriptor' ); -var empty = require( '@stdlib/ndarray/base/empty' ); - - -// FUNCTIONS // - -/** -* Returns an input ndarray. -* -* @private -* @param {Object} x - input ndarray descriptor -* @returns {Object} input ndarray descriptor -*/ -function identity( x ) { - return x; -} - -/** -* Broadcasts a zero-dimensional ndarray to a one-dimensional ndarray view containing a single element. -* -* @private -* @param {Object} x - input ndarray descriptor -* @returns {Object} broadcasted ndarray view descriptor -*/ -function broadcast( x ) { - return descriptor( x.dtype, x.data, [ 1 ], [ 0 ], x.offset, x.order ); -} - -/** -* Returns a function which returns an ndarray view in which the singleton dimensions are removed from an input ndarray having only one non-singleton dimension. -* -* @private -* @param {Object} arr - original ndarray descriptor -* @param {integer} index - index of the non-singleton dimension -* @returns {Function} function for returning an ndarray view -*/ -function squeeze( arr, index ) { - var sh = [ arr.shape[ index ] ]; - var sx = [ arr.strides[ index ] ]; - return reshape; - - /** - * Returns an ndarray view in which the singleton dimensions are removed from an input ndarray having only one non-singleton dimension. - * - * @private - * @param {Object} x - input ndarray descriptor - * @returns {Object} a squeezed ndarray view descriptor - */ - function reshape( x ) { - return descriptor( x.dtype, x.data, sh, sx, x.offset, x.order ); - } -} - -/** -* Returns a function which returns a one-dimensional ndarray view of a contiguous input ndarray having more than one dimension. -* -* @private -* @param {integer} len - number of elements in an ndarray -* @param {integer} iox - iteration order -* @returns {Function} function for returning a one-dimensional ndarray view -*/ -function contiguous( len, iox ) { - var xmmv; - var ind; - var sh; - var sx; - - // Resolve the index of the min/max view buffer element which is the first indexed element... - if ( iox === 1 ) { - ind = 0; - } else { - ind = 1; - } - // Initialize an array for storing the min/max view buffer elements: - xmmv = [ 0, 0 ]; // [ min, max ] - - // Initialize the output one-dimensional view's shape and strides: - sh = [ len ]; - sx = [ iox ]; - - return reshape; - - /** - * Returns a one-dimensional ndarray view of a contiguous input ndarray having more than one dimension. - * - * @private - * @param {Object} x - input ndarray descriptor - * @returns {Object} a one-dimensional ndarray view descriptor - */ - function reshape( x ) { - // Resolve the minimum and maximum linear indices in the underlying data buffer which are accessible to the input ndarray view: - minmaxViewBufferIndex( x.shape, x.strides, x.offset, xmmv ); - - // Note: `xmmv[ ind ]` corresponds to the index of the first indexed element - return descriptor( x.dtype, x.data, sh, sx, xmmv[ ind ], x.order ); - } -} - -/** -* Returns a function which copies an input ndarray to a contiguous ndarray workspace. -* -* @private -* @param {integer} len - number of elements in an ndarray -* @param {Object} workspace - ndarray workspace descriptor -* @returns {Function} function which copies an input ndarray to a contiguous ndarray workspace -*/ -function copyToWorkspace( len, workspace ) { - var view = descriptor( workspace.dtype, workspace.data, [ len ], [ 1 ], workspace.offset, workspace.order ); // eslint-disable-line max-len - return reshape; - - /** - * Copies an input ndarray to a contiguous ndarray workspace and returns a one-dimensional workspace view. - * - * @private - * @param {Object} x - input ndarray descriptor - * @returns {Object} one-dimensional workspace view descriptor - */ - function reshape( x ) { - assign( [ x, workspace ] ); - return view; - } -} - -/** -* Returns a function which copies from a contiguous ndarray workspace to an input ndarray. -* -* @private -* @param {Object} workspace - ndarray workspace descriptor -* @returns {Function} function which copies from a contiguous ndarray workspace to an input ndarray -*/ -function copyFromWorkspace( workspace ) { - return copy; - - /** - * Copies from a contiguous ndarray workspace to an input ndarray. - * - * @private - * @param {Object} x - input ndarray descriptor - * @returns {Object} input ndarray descriptor - */ - function copy( x ) { - assign( [ workspace, x ] ); - return x; - } -} - - -// MAIN // - -/** -* Returns an object containing methods for reshaping an ndarray as a one-dimensional strided array view. -* -* @param {Object} x - ndarray descriptor -* @param {*} x.dtype - ndarray data type -* @param {Collection} x.data - ndarray data buffer -* @param {Array} x.shape - ndarray shape -* @param {Array} x.strides - ndarray strides -* @param {integer} x.offset - ndarray index offset -* @param {string} x.order - ndarray memory layout -* @returns {Object} object containing methods implementing a reshape strategy -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); -* -* var x = { -* 'dtype': 'float64', -* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), -* 'shape': [ 1 ], -* 'strides': [ 1 ], -* 'offset': 0, -* 'order': 'row-major' -* }; -* -* var out = strategy( x ); -* // returns {...} -*/ -function strategy( x ) { - var workspace; - var ndims; - var xmmv; - var len; - var iox; - var sh; - var ns; - var i; - - // Resolve the number of array dimensions: - sh = x.shape; - ndims = sh.length; - - // Check whether the ndarray is zero-dimensional... - if ( ndims === 0 ) { - return { - 'input': broadcast, - 'output': identity - }; - } - // Check whether the ndarray is already one-dimensional... - if ( ndims === 1 ) { - return { - 'input': identity, - 'output': identity - }; - } - // Determine the number of singleton dimensions... - len = 1; // number of elements - ns = 0; // number of singleton dimensions - for ( i = 0; i < ndims; i++ ) { - // Check whether the current dimension is a singleton dimension... - if ( sh[ i ] === 1 ) { - ns += 1; - } - len *= sh[ i ]; - } - // Determine whether the ndarray has only **one** non-singleton dimension (e.g., ndims=4, shape=[10,1,1,1]) so that we can simply create an ndarray view without the singleton dimensions... - if ( ns === ndims-1 ) { - // Get the index of the non-singleton dimension... - for ( i = 0; i < ndims; i++ ) { - if ( sh[ i ] !== 1 ) { - break; - } - } - return { - 'input': squeeze( x, i ), - 'output': identity - }; - } - iox = iterationOrder( x.strides ); // +/-1 - - // Determine whether we can avoid copying data... - if ( iox !== 0 ) { - // Determine the minimum and maximum linear indices which are accessible by the ndarray view: - xmmv = minmaxViewBufferIndex( sh, x.strides, x.offset, [ 0, 0 ] ); - - // Determine whether we can ignore shape (and strides) and create a new one-dimensional ndarray view... - if ( len === ( xmmv[1]-xmmv[0]+1 ) ) { - return { - 'input': contiguous( len, iox ), - 'output': identity - }; - } - // The ndarray is non-contiguous, so we cannot directly interpret as a one-dimensional ndarray... - - // Fall-through to copying to a workspace ndarray... - } - // At this point, we're dealing with a non-contiguous multi-dimensional ndarray, so we need to copy to a contiguous workspace: - workspace = ndarraylike2descriptor( empty( x.dtype, x.shape, x.order ) ); - return { - 'input': copyToWorkspace( len, workspace ), - 'output': copyFromWorkspace( workspace ) - }; -} - - -// EXPORTS // - -module.exports = strategy; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json deleted file mode 100644 index 4090e40f792e..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/package.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "name": "@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy", - "version": "0.0.0", - "description": "Return an object containing methods for reshaping an ndarray as a one-dimensional strided array view.", - "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": { - "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", - "strided", - "ndarray", - "nullary", - "workspace", - "strategy", - "util" - ], - "__stdlib__": {} -} diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js deleted file mode 100644 index 5424549718c9..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy/test/test.js +++ /dev/null @@ -1,35 +0,0 @@ -/** -* @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 strategy = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof strategy, 'function', 'main export is a function' ); - t.end(); -}); - -// FIXME: add tests diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md index e284fd4c4265..4565187f792e 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md @@ -47,7 +47,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); function clbk( value, idx ) { return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; @@ -188,7 +188,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); function clbk( value, idx ) { return ( idx[ 0 ]*10 ) + idx[ 1 ]; @@ -287,7 +287,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); function clbk( value, idx ) { return ( idx[ 0 ]*100 ) + ( idx[ 1 ]*10 ) + idx[ 2 ]; @@ -412,7 +412,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); function clbk( value, idx ) { return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; @@ -537,7 +537,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); function clbk( value, idx ) { return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; @@ -690,7 +690,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked' ); function clbk( value, idx ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js index 1c93f3555ca7..dd301b39f5bf 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/examples/index.js @@ -24,7 +24,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); var zeros = require( '@stdlib/array/base/zeros' ); var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); var kernel = require( './../lib' ); function clbk( value, idx ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js index 48fd931d3ed9..b0f1f2f87f81 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/0d.js @@ -56,7 +56,7 @@ var wrap = require( './callback_wrapper.js' ); * var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); * var zeros = require( '@stdlib/array/base/zeros' ); * var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); * * function clbk( value, idx ) { * return ( idx[ 0 ]*10 ) + idx[ 1 ]; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js index 4d8f5a636450..5b65676a4115 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/1d.js @@ -56,7 +56,7 @@ var wrap = require( './callback_wrapper.js' ); * var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); * var zeros = require( '@stdlib/array/base/zeros' ); * var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); * * function clbk( value, idx ) { * return ( idx[ 0 ]*100 ) + ( idx[ 1 ]*10 ) + idx[ 2 ]; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js index 537e991a6dee..5198601d83d2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/2d.js @@ -57,7 +57,7 @@ var wrap = require( './callback_wrapper.js' ); * var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); * var zeros = require( '@stdlib/array/base/zeros' ); * var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); * * function clbk( value, idx ) { * return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js index 86a0b4ef53e7..18b49d0da465 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/3d.js @@ -57,7 +57,7 @@ var wrap = require( './callback_wrapper.js' ); * var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); * var zeros = require( '@stdlib/array/base/zeros' ); * var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); * * function clbk( value, idx ) { * return ( idx[ 2 ]*100 ) + ( idx[ 3 ]*10 ) + idx[ 4 ]; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js index 1caf1719d9ef..28668abd1628 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js @@ -28,7 +28,7 @@ * var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); * var zeros = require( '@stdlib/array/base/zeros' ); * var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); * var kernel = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked' ); * * function clbk( value, idx ) { diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js index dab7e5fac81e..0dcb56d27458 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js @@ -50,7 +50,7 @@ var MAX_DIMS = KERNELS.length - 1; * var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); * var zeros = require( '@stdlib/array/base/zeros' ); * var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); -* var strategy = require( '@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/strategy' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); * * function clbk( value, idx ) { * return ( idx[ 1 ]*100 ) + ( idx[ 2 ]*10 ) + idx[ 3 ]; From 3359fcdbe75427472c5a702e5adf2eef59c0b879 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 3 Oct 2026 18:20:49 +0500 Subject: [PATCH 4/4] feat: add kernels --- .../nullary-strided1d-by/unblocked/README.md | 875 ++++++++++++++++++ .../unblocked/docs/repl.txt | 358 ++++++- .../nullary-strided1d-by/unblocked/lib/10d.js | 354 +++++++ .../nullary-strided1d-by/unblocked/lib/4d.js | 258 ++++++ .../nullary-strided1d-by/unblocked/lib/5d.js | 274 ++++++ .../nullary-strided1d-by/unblocked/lib/6d.js | 290 ++++++ .../nullary-strided1d-by/unblocked/lib/7d.js | 306 ++++++ .../nullary-strided1d-by/unblocked/lib/8d.js | 322 +++++++ .../nullary-strided1d-by/unblocked/lib/9d.js | 338 +++++++ .../unblocked/lib/index.js | 14 + .../unblocked/lib/main.js | 16 +- 11 files changed, 3403 insertions(+), 2 deletions(-) create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/10d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/4d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/5d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/6d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/7d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/8d.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/9d.js diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md index 4565187f792e..c7fdd0ecdb89 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/README.md @@ -647,6 +647,881 @@ The function has the following parameters: - **clbk**: callback function. - **thisArg**: callback execution context. + + +#### kernel.kernel4d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 3 ]*100 ) + ( idx[ 4 ]*10 ) + idx[ 5 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3 ]; +var cdims = [ 4, 5 ]; + +// Apply strided function: +kernel.kernel4d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 3 ], [ 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have four elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel5d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 4 ]*100 ) + ( idx[ 5 ]*10 ) + idx[ 6 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3, 4 ]; +var cdims = [ 5, 6 ]; + +// Apply strided function: +kernel.kernel5d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have five elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel6d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 5 ]*100 ) + ( idx[ 6 ]*10 ) + idx[ 7 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3, 4, 5 ]; +var cdims = [ 6, 7 ]; + +// Apply strided function: +kernel.kernel6d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have six elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel7d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 6 ]*100 ) + ( idx[ 7 ]*10 ) + idx[ 8 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3, 4, 5, 6 ]; +var cdims = [ 7, 8 ]; + +// Apply strided function: +kernel.kernel7d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have seven elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel8d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 7 ]*100 ) + ( idx[ 8 ]*10 ) + idx[ 9 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; +var cdims = [ 8, 9 ]; + +// Apply strided function: +kernel.kernel8d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have eight elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel9d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 8 ]*100 ) + ( idx[ 9 ]*10 ) + idx[ 10 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]; +var cdims = [ 9, 10 ]; + +// Apply strided function: +kernel.kernel9d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have nine elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + + + +#### kernel.kernel10d( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an input ndarray according to a callback function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); + +function clbk( value, idx ) { + return ( idx[ 9 ]*100 ) + ( idx[ 10 ]*10 ) + idx[ 11 ]; +} + +// Create a data buffer: +var xbuf = new Float64Array( 12 ); + +// Define the array shape: +var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; + +// Define the array strides: +var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; + +// Define the index offset: +var ox = 0; + +// Create an input ndarray descriptor: +var x = { + 'dtype': 'float64', + 'data': xbuf, + 'shape': xsh, + 'strides': sx, + 'offset': ox, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the starting index (inclusive): +var start = { + 'dtype': 'float64', + 'data': new Float64Array( [ 0.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Create an ndarray descriptor for the ending index (exclusive): +var end = { + 'dtype': 'float64', + 'data': new Float64Array( [ 4.0 ] ), + 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], + 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + 'offset': 0, + 'order': 'row-major' +}; + +// Initialize ndarray descriptors representing subarray views: +var views = [ + { + 'dtype': x.dtype, + 'data': x.data, + 'shape': [ 2, 2 ], + 'strides': [ 2, 1 ], + 'offset': x.offset, + 'order': x.order + }, + { + 'dtype': start.dtype, + 'data': start.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': start.offset, + 'order': start.order + }, + { + 'dtype': end.dtype, + 'data': end.data, + 'shape': [], + 'strides': [ 0 ], + 'offset': end.offset, + 'order': end.order + } +]; + +// Resolve an input strategy when iterating over subarray views: +var strategyX = strategy( views[ 0 ] ); + +// Create a workspace array for storing iteration indices: +var ibuf = zeros( xsh.length ); + +// Define the loop and core dimensions: +var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; +var cdims = [ 10, 11 ]; + +// Apply strided function: +kernel.kernel10d( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); + +var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +// returns [ [ [ [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] ] ] ] +``` + +The function has the following parameters: + +- **fcn**: function which will be applied to a one-dimensional input subarray according to a callback function. +- **arrays**: array containing an input ndarray [descriptor][@stdlib/ndarray/base/descriptor], followed by any additional ndarray arguments. +- **ref**: original input ndarray provided to a callback function. +- **views**: initialized ndarray [descriptors][@stdlib/ndarray/base/descriptor] representing subarray views. +- **shape**: loop dimensions. Should have ten elements. +- **stridesX**: loop dimension strides for the input ndarray. +- **strategyX**: strategy for marshaling data to and from an input ndarray view. +- **ibuf**: workspace for storing iteration indices. +- **ldims**: list of loop dimensions. +- **cdims**: list of "core" dimensions. +- **options**: function options which are passed through to `fcn`. +- **hasOpts**: boolean indicating whether to pass an options argument to a strided array function. +- **clbk**: callback function. +- **thisArg**: callback execution context. + diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt index 37172b23a6ca..c3a5a5658d58 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/docs/repl.txt @@ -248,6 +248,362 @@ ctx: any Callback execution context. + +{{alias}}.kernel4d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have four elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel5d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have five elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel6d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have six elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel7d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have seven elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel8d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have eight elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel9d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have nine elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + + +{{alias}}.kernel10d( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an input ndarray + according to a callback function. + + Parameters + ---------- + fcn: Function + Wrapper for a one-dimensional strided array function. + + arr: Array + Array containing an input ndarray descriptor, followed by any additional + ndarray arguments. + + ref: ndarray + Original input ndarray provided to a callback function. + + v: Array + Initialized ndarray descriptors representing subarray views. + + sh: Array + Loop dimensions. Should have ten elements. + + sx: Array + Loop dimension strides for the input ndarray. + + st: Object + Strategy for marshaling data to and from an input ndarray view. + + ib: Array + Workspace for storing iteration indices. + + ld: Array + List of loop dimensions. + + cd: Array + List of "core" dimensions. + + o: Object + Function options which are passed through to `fcn`. + + po: boolean + Boolean indicating whether to pass an options argument to a strided + array function. + + cb: Function + Callback function. + + ctx: any + Callback execution context. + See Also -------- - diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/10d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/10d.js new file mode 100644 index 000000000000..e99c00be9ae2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/10d.js @@ -0,0 +1,354 @@ +/** +* @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. +*/ + +/* eslint-disable max-depth, max-len, max-params, max-statements */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 9 ]*100 ) + ( idx[ 10 ]*10 ) + idx[ 11 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; +* var cdims = [ 10, 11 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var dv9; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var S9; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var i9; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 9 ]; + S1 = shape[ 8 ]; + S2 = shape[ 7 ]; + S3 = shape[ 6 ]; + S4 = shape[ 5 ]; + S5 = shape[ 4 ]; + S6 = shape[ 3 ]; + S7 = shape[ 2 ]; + S8 = shape[ 1 ]; + S9 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[9] + ]; + dv1 = [ + stridesX[8] - ( S0*stridesX[9] ) + ]; + dv2 = [ + stridesX[7] - ( S1*stridesX[8] ) + ]; + dv3 = [ + stridesX[6] - ( S2*stridesX[7] ) + ]; + dv4 = [ + stridesX[5] - ( S3*stridesX[6] ) + ]; + dv5 = [ + stridesX[4] - ( S4*stridesX[5] ) + ]; + dv6 = [ + stridesX[3] - ( S5*stridesX[4] ) + ]; + dv7 = [ + stridesX[2] - ( S6*stridesX[3] ) + ]; + dv8 = [ + stridesX[1] - ( S7*stridesX[2] ) + ]; + dv9 = [ // offset increment for outermost loop + stridesX[0] - ( S8*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[9] ); + dv1.push( sv[8] - ( S0*sv[9] ) ); + dv2.push( sv[7] - ( S1*sv[8] ) ); + dv3.push( sv[6] - ( S2*sv[7] ) ); + dv4.push( sv[5] - ( S3*sv[6] ) ); + dv5.push( sv[4] - ( S4*sv[5] ) ); + dv6.push( sv[3] - ( S5*sv[4] ) ); + dv7.push( sv[2] - ( S6*sv[3] ) ); + dv8.push( sv[1] - ( S7*sv[2] ) ); + dv9.push( sv[0] - ( S8*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + S4 = shape[ 4 ]; + S5 = shape[ 5 ]; + S6 = shape[ 6 ]; + S7 = shape[ 7 ]; + S8 = shape[ 8 ]; + S9 = shape[ 9 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[2] ) + ]; + dv4 = [ + stridesX[4] - ( S3*stridesX[3] ) + ]; + dv5 = [ + stridesX[5] - ( S4*stridesX[4] ) + ]; + dv6 = [ + stridesX[6] - ( S5*stridesX[5] ) + ]; + dv7 = [ + stridesX[7] - ( S6*stridesX[6] ) + ]; + dv8 = [ + stridesX[8] - ( S7*stridesX[7] ) + ]; + dv9 = [ // offset increment for outermost loop + stridesX[9] - ( S8*stridesX[8] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + dv8.push( sv[8] - ( S7*sv[7] ) ); + dv9.push( sv[9] - ( S8*sv[8] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i9 = 0; i9 < S9; i9++ ) { + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i9, i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } + incrementOffsets( iv, dv9 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/4d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/4d.js new file mode 100644 index 000000000000..8da54724780a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/4d.js @@ -0,0 +1,258 @@ +/** +* @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. +*/ + +/* eslint-disable max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 3 ]*100 ) + ( idx[ 4 ]*10 ) + idx[ 5 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3 ]; +* var cdims = [ 4, 5 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 3 ], [ 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var S0; + var S1; + var S2; + var S3; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 3 ]; + S1 = shape[ 2 ]; + S2 = shape[ 1 ]; + S3 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[3] + ]; + dv1 = [ + stridesX[2] - ( S0*stridesX[3] ) + ]; + dv2 = [ + stridesX[1] - ( S1*stridesX[2] ) + ]; + dv3 = [ // offset increment for outermost loop + stridesX[0] - ( S2*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[3] ); + dv1.push( sv[2] - ( S0*sv[3] ) ); + dv2.push( sv[1] - ( S1*sv[2] ) ); + dv3.push( sv[0] - ( S2*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ // offset increment for outermost loop + stridesX[3] - ( S2*stridesX[2] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/5d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/5d.js new file mode 100644 index 000000000000..2087385b745c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/5d.js @@ -0,0 +1,274 @@ +/** +* @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. +*/ + +/* eslint-disable max-depth, max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 4 ]*100 ) + ( idx[ 5 ]*10 ) + idx[ 6 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4 ]; +* var cdims = [ 5, 6 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var S0; + var S1; + var S2; + var S3; + var S4; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 4 ]; + S1 = shape[ 3 ]; + S2 = shape[ 2 ]; + S3 = shape[ 1 ]; + S4 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[4] + ]; + dv1 = [ + stridesX[3] - ( S0*stridesX[4] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[3] ) + ]; + dv3 = [ + stridesX[1] - ( S2*stridesX[2] ) + ]; + dv4 = [ // offset increment for outermost loop + stridesX[0] - ( S3*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[4] ); + dv1.push( sv[3] - ( S0*sv[4] ) ); + dv2.push( sv[2] - ( S1*sv[3] ) ); + dv3.push( sv[1] - ( S2*sv[2] ) ); + dv4.push( sv[0] - ( S3*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + S4 = shape[ 4 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[2] ) + ]; + dv4 = [ // offset increment for outermost loop + stridesX[4] - ( S3*stridesX[3] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/6d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/6d.js new file mode 100644 index 000000000000..d1a13622a5f5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/6d.js @@ -0,0 +1,290 @@ +/** +* @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. +*/ + +/* eslint-disable max-depth, max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 5 ]*100 ) + ( idx[ 6 ]*10 ) + idx[ 7 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5 ]; +* var cdims = [ 6, 7 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 5 ]; + S1 = shape[ 4 ]; + S2 = shape[ 3 ]; + S3 = shape[ 2 ]; + S4 = shape[ 1 ]; + S5 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[5] + ]; + dv1 = [ + stridesX[4] - ( S0*stridesX[5] ) + ]; + dv2 = [ + stridesX[3] - ( S1*stridesX[4] ) + ]; + dv3 = [ + stridesX[2] - ( S2*stridesX[3] ) + ]; + dv4 = [ + stridesX[1] - ( S3*stridesX[2] ) + ]; + dv5 = [ // offset increment for outermost loop + stridesX[0] - ( S4*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[5] ); + dv1.push( sv[4] - ( S0*sv[5] ) ); + dv2.push( sv[3] - ( S1*sv[4] ) ); + dv3.push( sv[2] - ( S2*sv[3] ) ); + dv4.push( sv[1] - ( S3*sv[2] ) ); + dv5.push( sv[0] - ( S4*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + S4 = shape[ 4 ]; + S5 = shape[ 5 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[2] ) + ]; + dv4 = [ + stridesX[4] - ( S3*stridesX[3] ) + ]; + dv5 = [ // offset increment for outermost loop + stridesX[5] - ( S4*stridesX[4] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/7d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/7d.js new file mode 100644 index 000000000000..0e64af280d9a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/7d.js @@ -0,0 +1,306 @@ +/** +* @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. +*/ + +/* eslint-disable max-depth, max-len, max-params */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 6 ]*100 ) + ( idx[ 7 ]*10 ) + idx[ 8 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6 ]; +* var cdims = [ 7, 8 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 6 ]; + S1 = shape[ 5 ]; + S2 = shape[ 4 ]; + S3 = shape[ 3 ]; + S4 = shape[ 2 ]; + S5 = shape[ 1 ]; + S6 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[6] + ]; + dv1 = [ + stridesX[5] - ( S0*stridesX[6] ) + ]; + dv2 = [ + stridesX[4] - ( S1*stridesX[5] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[4] ) + ]; + dv4 = [ + stridesX[2] - ( S3*stridesX[3] ) + ]; + dv5 = [ + stridesX[1] - ( S4*stridesX[2] ) + ]; + dv6 = [ // offset increment for outermost loop + stridesX[0] - ( S5*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[6] ); + dv1.push( sv[5] - ( S0*sv[6] ) ); + dv2.push( sv[4] - ( S1*sv[5] ) ); + dv3.push( sv[3] - ( S2*sv[4] ) ); + dv4.push( sv[2] - ( S3*sv[3] ) ); + dv5.push( sv[1] - ( S4*sv[2] ) ); + dv6.push( sv[0] - ( S5*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + S4 = shape[ 4 ]; + S5 = shape[ 5 ]; + S6 = shape[ 6 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[2] ) + ]; + dv4 = [ + stridesX[4] - ( S3*stridesX[3] ) + ]; + dv5 = [ + stridesX[5] - ( S4*stridesX[4] ) + ]; + dv6 = [ // offset increment for outermost loop + stridesX[6] - ( S5*stridesX[5] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/8d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/8d.js new file mode 100644 index 000000000000..86ccd0cec5c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/8d.js @@ -0,0 +1,322 @@ +/** +* @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. +*/ + +/* eslint-disable max-depth, max-len, max-params, max-statements */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 7 ]*100 ) + ( idx[ 8 ]*10 ) + idx[ 9 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7 ]; +* var cdims = [ 8, 9 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 7 ]; + S1 = shape[ 6 ]; + S2 = shape[ 5 ]; + S3 = shape[ 4 ]; + S4 = shape[ 3 ]; + S5 = shape[ 2 ]; + S6 = shape[ 1 ]; + S7 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[7] + ]; + dv1 = [ + stridesX[6] - ( S0*stridesX[7] ) + ]; + dv2 = [ + stridesX[5] - ( S1*stridesX[6] ) + ]; + dv3 = [ + stridesX[4] - ( S2*stridesX[5] ) + ]; + dv4 = [ + stridesX[3] - ( S3*stridesX[4] ) + ]; + dv5 = [ + stridesX[2] - ( S4*stridesX[3] ) + ]; + dv6 = [ + stridesX[1] - ( S5*stridesX[2] ) + ]; + dv7 = [ // offset increment for outermost loop + stridesX[0] - ( S6*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[7] ); + dv1.push( sv[6] - ( S0*sv[7] ) ); + dv2.push( sv[5] - ( S1*sv[6] ) ); + dv3.push( sv[4] - ( S2*sv[5] ) ); + dv4.push( sv[3] - ( S3*sv[4] ) ); + dv5.push( sv[2] - ( S4*sv[3] ) ); + dv6.push( sv[1] - ( S5*sv[2] ) ); + dv7.push( sv[0] - ( S6*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + S4 = shape[ 4 ]; + S5 = shape[ 5 ]; + S6 = shape[ 6 ]; + S7 = shape[ 7 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[2] ) + ]; + dv4 = [ + stridesX[4] - ( S3*stridesX[3] ) + ]; + dv5 = [ + stridesX[5] - ( S4*stridesX[4] ) + ]; + dv6 = [ + stridesX[6] - ( S5*stridesX[5] ) + ]; + dv7 = [ // offset increment for outermost loop + stridesX[7] - ( S6*stridesX[6] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/9d.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/9d.js new file mode 100644 index 000000000000..1a53c20603b2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/9d.js @@ -0,0 +1,338 @@ +/** +* @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. +*/ + +/* eslint-disable max-depth, max-len, max-params, max-statements */ + +'use strict'; + +// MODULES // + +var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' ); +var copyIndexed = require( '@stdlib/array/base/copy-indexed' ); +var incrementOffsets = require( '@stdlib/ndarray/base/kernels/utils/increment-offsets' ); +var setViewOffsets = require( '@stdlib/ndarray/base/set-descriptor-offsets' ); +var offsets = require( '@stdlib/ndarray/base/offsets' ); +var wrap = require( './callback_wrapper.js' ); + + +// MAIN // + +/** +* Applies a one-dimensional strided array function to an input ndarray according to a callback function. +* +* @private +* @param {Function} fcn - wrapper for a one-dimensional strided array function +* @param {Array} arrays - ndarray descriptors +* @param {ndarrayLike} ref - original input ndarray provided to a callback function +* @param {Array} views - initialized ndarray descriptors representing subarray views +* @param {Array} shape - loop dimensions +* @param {Array} stridesX - loop dimension strides for the input ndarray +* @param {Object} strategyX - strategy for marshaling data to and from an input ndarray view +* @param {NonNegativeIntegerArray} ibuf - workspace for storing iteration indices +* @param {NonNegativeIntegerArray} ldims - list of loop dimensions +* @param {NonNegativeIntegerArray} cdims - list of "core" dimensions +* @param {Options} opts - function options +* @param {boolean} hasOpts - boolean indicating whether to pass an options argument to a strided array function +* @param {Function} clbk - callback function +* @param {*} thisArg - callback execution context +* @returns {void} +* +* @example +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); +* var zeros = require( '@stdlib/array/base/zeros' ); +* var gfillBy = require( '@stdlib/blas/ext/base/ndarray/gfill-by' ); +* var strategy = require( '@stdlib/ndarray/base/kernels/generic/unary-strided1d/strategy' ); +* +* function clbk( value, idx ) { +* return ( idx[ 8 ]*100 ) + ( idx[ 9 ]*10 ) + idx[ 10 ]; +* } +* +* // Create a data buffer: +* var xbuf = new Float64Array( 12 ); +* +* // Define the array shape: +* var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ]; +* +* // Define the array strides: +* var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create an input ndarray descriptor: +* var x = { +* 'dtype': 'float64', +* 'data': xbuf, +* 'shape': xsh, +* 'strides': sx, +* 'offset': ox, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the starting index (inclusive): +* var start = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 0.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Create an ndarray descriptor for the ending index (exclusive): +* var end = { +* 'dtype': 'float64', +* 'data': new Float64Array( [ 4.0 ] ), +* 'shape': [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], +* 'strides': [ 0, 0, 0, 0, 0, 0, 0, 0, 0 ], +* 'offset': 0, +* 'order': 'row-major' +* }; +* +* // Initialize ndarray descriptors representing subarray views: +* var views = [ +* { +* 'dtype': x.dtype, +* 'data': x.data, +* 'shape': [ 2, 2 ], +* 'strides': [ 2, 1 ], +* 'offset': x.offset, +* 'order': x.order +* }, +* { +* 'dtype': start.dtype, +* 'data': start.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': start.offset, +* 'order': start.order +* }, +* { +* 'dtype': end.dtype, +* 'data': end.data, +* 'shape': [], +* 'strides': [ 0 ], +* 'offset': end.offset, +* 'order': end.order +* } +* ]; +* +* // Resolve an input strategy when iterating over subarray views: +* var strategyX = strategy( views[ 0 ] ); +* +* // Create a workspace array for storing iteration indices: +* var ibuf = zeros( xsh.length ); +* +* // Define the loop and core dimensions: +* var ldims = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ]; +* var cdims = [ 9, 10 ]; +* +* // Apply strided function: +* kernel( gfillBy, [ x, start, end ], x, views, [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ], strategyX, ibuf, ldims, cdims, {}, false, clbk, {} ); +* +* var arr = ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ); +* // returns [ [ [ [ [ [ [ [ [ [ [ 0.0, 1.0 ], [ 10.0, 11.0 ] ], [ [ 100.0, 101.0 ], [ 110.0, 111.0 ] ], [ [ 200.0, 201.0 ], [ 210.0, 211.0 ] ] ] ] ] ] ] ] ] ] ] +*/ +function kernel( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, opts, hasOpts, clbk, thisArg ) { + var dv0; + var dv1; + var dv2; + var dv3; + var dv4; + var dv5; + var dv6; + var dv7; + var dv8; + var S0; + var S1; + var S2; + var S3; + var S4; + var S5; + var S6; + var S7; + var S8; + var sv; + var iv; + var i0; + var i1; + var i2; + var i3; + var i4; + var i5; + var i6; + var i7; + var i8; + var v; + var i; + var f; + + // Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop... + + // Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments... + if ( isRowMajor( stridesX ) ) { + // For row-major ndarrays, the last dimensions have the fastest changing indices... + S0 = shape[ 8 ]; + S1 = shape[ 7 ]; + S2 = shape[ 6 ]; + S3 = shape[ 5 ]; + S4 = shape[ 4 ]; + S5 = shape[ 3 ]; + S6 = shape[ 2 ]; + S7 = shape[ 1 ]; + S8 = shape[ 0 ]; + dv0 = [ // offset increment for innermost loop + stridesX[8] + ]; + dv1 = [ + stridesX[7] - ( S0*stridesX[8] ) + ]; + dv2 = [ + stridesX[6] - ( S1*stridesX[7] ) + ]; + dv3 = [ + stridesX[5] - ( S2*stridesX[6] ) + ]; + dv4 = [ + stridesX[4] - ( S3*stridesX[5] ) + ]; + dv5 = [ + stridesX[3] - ( S4*stridesX[4] ) + ]; + dv6 = [ + stridesX[2] - ( S5*stridesX[3] ) + ]; + dv7 = [ + stridesX[1] - ( S6*stridesX[2] ) + ]; + dv8 = [ // offset increment for outermost loop + stridesX[0] - ( S7*stridesX[1] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[8] ); + dv1.push( sv[7] - ( S0*sv[8] ) ); + dv2.push( sv[6] - ( S1*sv[7] ) ); + dv3.push( sv[5] - ( S2*sv[6] ) ); + dv4.push( sv[4] - ( S3*sv[5] ) ); + dv5.push( sv[3] - ( S4*sv[4] ) ); + dv6.push( sv[2] - ( S5*sv[3] ) ); + dv7.push( sv[1] - ( S6*sv[2] ) ); + dv8.push( sv[0] - ( S7*sv[1] ) ); + } + } else { // order === 'column-major' + // For column-major ndarrays, the first dimensions have the fastest changing indices... + S0 = shape[ 0 ]; + S1 = shape[ 1 ]; + S2 = shape[ 2 ]; + S3 = shape[ 3 ]; + S4 = shape[ 4 ]; + S5 = shape[ 5 ]; + S6 = shape[ 6 ]; + S7 = shape[ 7 ]; + S8 = shape[ 8 ]; + dv0 = [ // offset increment for innermost loop + stridesX[0] + ]; + dv1 = [ + stridesX[1] - ( S0*stridesX[0] ) + ]; + dv2 = [ + stridesX[2] - ( S1*stridesX[1] ) + ]; + dv3 = [ + stridesX[3] - ( S2*stridesX[2] ) + ]; + dv4 = [ + stridesX[4] - ( S3*stridesX[3] ) + ]; + dv5 = [ + stridesX[5] - ( S4*stridesX[4] ) + ]; + dv6 = [ + stridesX[6] - ( S5*stridesX[5] ) + ]; + dv7 = [ + stridesX[7] - ( S6*stridesX[6] ) + ]; + dv8 = [ // offset increment for outermost loop + stridesX[8] - ( S7*stridesX[7] ) + ]; + for ( i = 1; i < arrays.length; i++ ) { + sv = arrays[ i ].strides; + dv0.push( sv[0] ); + dv1.push( sv[1] - ( S0*sv[0] ) ); + dv2.push( sv[2] - ( S1*sv[1] ) ); + dv3.push( sv[3] - ( S2*sv[2] ) ); + dv4.push( sv[4] - ( S3*sv[3] ) ); + dv5.push( sv[5] - ( S4*sv[4] ) ); + dv6.push( sv[6] - ( S5*sv[5] ) ); + dv7.push( sv[7] - ( S6*sv[6] ) ); + dv8.push( sv[8] - ( S7*sv[7] ) ); + } + } + // Resolve a list of pointers to the first indexed elements in the respective ndarrays: + iv = offsets( arrays ); + + // Shallow copy the list of views to an internal array so that we can update with reshaped views without impacting the original list of views: + v = copyIndexed( views ); + + // Iterate over the loop dimensions... + for ( i8 = 0; i8 < S8; i8++ ) { + for ( i7 = 0; i7 < S7; i7++ ) { + for ( i6 = 0; i6 < S6; i6++ ) { + for ( i5 = 0; i5 < S5; i5++ ) { + for ( i4 = 0; i4 < S4; i4++ ) { + for ( i3 = 0; i3 < S3; i3++ ) { + for ( i2 = 0; i2 < S2; i2++ ) { + for ( i1 = 0; i1 < S1; i1++ ) { + for ( i0 = 0; i0 < S0; i0++ ) { + setViewOffsets( views, iv ); + v[ 0 ] = strategyX.input( views[ 0 ] ); + f = wrap( ref, views[ 0 ], ibuf, ldims, [ i8, i7, i6, i5, i4, i3, i2, i1, i0 ], cdims, clbk, thisArg ); + if ( hasOpts ) { + fcn( v, opts, f ); + } else { + fcn( v, f ); + } + strategyX.output( views[ 0 ] ); + incrementOffsets( iv, dv0 ); + } + incrementOffsets( iv, dv1 ); + } + incrementOffsets( iv, dv2 ); + } + incrementOffsets( iv, dv3 ); + } + incrementOffsets( iv, dv4 ); + } + incrementOffsets( iv, dv5 ); + } + incrementOffsets( iv, dv6 ); + } + incrementOffsets( iv, dv7 ); + } + incrementOffsets( iv, dv8 ); + } +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js index 28668abd1628..aaa216c79c00 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/index.js @@ -132,6 +132,13 @@ var kernel0d = require( './0d.js' ); var kernel1d = require( './1d.js' ); var kernel2d = require( './2d.js' ); var kernel3d = require( './3d.js' ); +var kernel4d = require( './4d.js' ); +var kernel5d = require( './5d.js' ); +var kernel6d = require( './6d.js' ); +var kernel7d = require( './7d.js' ); +var kernel8d = require( './8d.js' ); +var kernel9d = require( './9d.js' ); +var kernel10d = require( './10d.js' ); var main = require( './main.js' ); @@ -141,6 +148,13 @@ setReadOnly( main, 'kernel0d', kernel0d ); setReadOnly( main, 'kernel1d', kernel1d ); setReadOnly( main, 'kernel2d', kernel2d ); setReadOnly( main, 'kernel3d', kernel3d ); +setReadOnly( main, 'kernel4d', kernel4d ); +setReadOnly( main, 'kernel5d', kernel5d ); +setReadOnly( main, 'kernel6d', kernel6d ); +setReadOnly( main, 'kernel7d', kernel7d ); +setReadOnly( main, 'kernel8d', kernel8d ); +setReadOnly( main, 'kernel9d', kernel9d ); +setReadOnly( main, 'kernel10d', kernel10d ); // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js index 0dcb56d27458..1d3a137e35b2 100644 --- a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/unblocked/lib/main.js @@ -24,6 +24,13 @@ var kernel0d = require( './0d.js' ); var kernel1d = require( './1d.js' ); var kernel2d = require( './2d.js' ); var kernel3d = require( './3d.js' ); +var kernel4d = require( './4d.js' ); +var kernel5d = require( './5d.js' ); +var kernel6d = require( './6d.js' ); +var kernel7d = require( './7d.js' ); +var kernel8d = require( './8d.js' ); +var kernel9d = require( './9d.js' ); +var kernel10d = require( './10d.js' ); // VARIABLES // @@ -32,7 +39,14 @@ var KERNELS = [ kernel0d, kernel1d, kernel2d, - kernel3d + kernel3d, + kernel4d, + kernel5d, + kernel6d, + kernel7d, + kernel8d, + kernel9d, + kernel10d ]; var MAX_DIMS = KERNELS.length - 1;