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..13bcdbe022de --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/README.md @@ -0,0 +1,458 @@ + + +# kernel + +> Return a kernel for applying 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( ndims ) + +Returns a kernel for applying 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/unary-strided1d/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 less than or equal to `0`, the function returns `null`. + +```javascript +var f = kernel( -1 ); +// 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 linear **view** index, regardless as to how the data is stored in memory. + + + +#### kernel.nd( fcn, arrays, ref, views, shape, stridesX, strategyX, ibuf, ldims, cdims, options, hasOpts, clbk, thisArg ) + + + +Applies a one-dimensional strided array function to an n-dimensional 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/unary-strided1d/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.nd( 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. + +
+ + + +
+ +## 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/unary-strided1d/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 ]; + +// 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/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..f5d3b71d0c95 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/docs/repl.txt @@ -0,0 +1,101 @@ + +{{alias}}( ndims ) + Returns a kernel for applying a one-dimensional strided array function to an + input ndarray according to a callback function using linear view iteration. + + 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. + + The returned function iterates based on the linear view index, regardless as + to how the data is stored in memory. + + If `ndims` is less than or equal to `0`, the function returns `null`. + + Parameters + ---------- + ndims: integer + Number of loop dimensions. + + Returns + ------- + fcn: Function|null + Kernel function. + + Examples + -------- + > var f = {{alias}}( 2 ) + + + +{{alias}}.nd( fcn, arr, ref, v, sh, sx, st, ib, ld, cd, o, po, cb, ctx ) + Applies a one-dimensional strided array function to an n-dimensional 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. + + 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..dd301b39f5bf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/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/unary-strided1d/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/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..dcf6eac59626 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/index.js @@ -0,0 +1,142 @@ +/** +* @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 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/unary-strided1d/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 ]; +* +* // 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 nd = require( './nd.js' ); +var main = require( './main.js' ); + + +// MAIN // + +setReadOnly( main, 'nd', nd ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/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..9372484a4d03 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/main.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'; + +// MODULES // + +var nullarynd = require( './nd.js' ); + + +// MAIN // + +/** +* Returns a kernel for applying a one-dimensional strided array function to an input ndarray according to a callback function using linear view iteration. +* +* @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/unary-strided1d/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 ) { + return null; + } + return nullarynd; +} + + +// EXPORTS // + +module.exports = kernel; diff --git a/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/nd.js b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/nd.js new file mode 100644 index 000000000000..3c81167d2d62 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/kernels/generic/nullary-strided1d-by/linear/lib/nd.js @@ -0,0 +1,209 @@ +/** +* @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. +* +* @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[ 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: +* nullarynd( 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 nullarynd( 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 = nullarynd; 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..3ee29f1721d0 --- /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": "Return a kernel for applying 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