From 3cf6f0738f3a3f9ffedea77501ee88326ebccb74 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 13 Aug 2026 10:50:35 +0500 Subject: [PATCH] refactor: add ancillary ndarray arguments support to ndarray/base/nullary-strided1d --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../ndarray/base/nullary-strided1d/README.md | 6 +++-- .../base/nullary-strided1d/docs/repl.txt | 22 ++++++++++++++----- .../ndarray/base/nullary-strided1d/lib/2d.js | 2 +- .../lib/initialize_array_views.js | 12 +++++++--- .../nullary-strided1d/lib/main_factory.js | 10 +++++---- .../base/nullary-strided1d/lib/strategy.js | 2 +- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/README.md b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/README.md index 5be951d57075..6519a2393f12 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/README.md @@ -122,7 +122,9 @@ Each provided ndarray should be an object with the following properties: ## Notes -- Any additional ndarray arguments are expected to have the same dimensions as the loop dimensions of the first provided ndarray. When calling the strided array function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects. +- Any additional ndarray arguments are expected to have the same leading dimensions as the loop dimensions of the first provided ndarray. + +- When calling the strided array function, any additional ndarray arguments are provided as k-dimensional subarrays, where `k = M - N` with `M` being the number of dimensions in an ndarray argument and `N` being the number of loop dimensions for the first provided ndarray. For example, if the first provided ndarray has three dimensions, the number of loop dimensions is one, and an additional ndarray argument has one dimension, thus matching the number of loop dimensions for the first provided ndarray, the strided array function is provided a zero-dimensional subarray as an additional ndarray argument. In the same scenario but where an additional ndarray argument has two dimensions, thus exceeding the number of loop dimensions, the strided array function is provided a one-dimensional subarray as an additional ndarray argument. - The strided array function is expected to have the following signature: @@ -132,7 +134,7 @@ Each provided ndarray should be an object with the following properties: where - - **arrays**: array containing a one-dimensional subarray of the first provided ndarray and any additional ndarray arguments as zero-dimensional ndarrays. + - **arrays**: array containing a one-dimensional subarray of the first provided ndarray and any additional ndarray arguments as subarrays. - **options**: function options (_optional_). - The function iterates over ndarray elements according to the memory layout of the first provided ndarray. diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/docs/repl.txt index 54127fcf8a6f..48556271f93d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/docs/repl.txt @@ -13,10 +13,21 @@ - order: specifies whether an ndarray is row-major (C-style) or column-major (Fortran-style). - Any additional ndarray arguments are expected to have the same dimensions as - the loop dimensions of the first provided ndarray. When calling the strided - array function, any additional ndarray arguments are provided as zero- - dimensional ndarray-like objects. + Any additional ndarray arguments are expected to have the same leading + dimensions as the loop dimensions of the first provided ndarray. + + When calling the strided array function, any additional ndarray arguments + are provided as k-dimensional subarrays, where `k = M - N` with `M` being + the number of dimensions in an ndarray argument and `N` being the number of + loop dimensions for the first provided ndarray. For example, if the first + provided ndarray has three dimensions, the number of loop dimensions is + one, and an additional ndarray argument has one dimension, thus matching + the number of loop dimensions for the first provided ndarray, the strided + array function is provided a zero-dimensional subarray as an additional + ndarray argument. In the same scenario but where an additional ndarray + argument has two dimensions, thus exceeding the number of loop dimensions, + the strided array function is provided a one-dimensional subarray as an + additional ndarray argument. Parameters ---------- @@ -29,8 +40,7 @@ where - arrays: array containing a one-dimensional subarray of the first - provided ndarray and any additional ndarray arguments as zero- - dimensional ndarrays. + provided ndarray and any additional ndarray arguments as subarrays. - options: function options. arrays: ArrayLikeObject diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/2d.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/2d.js index 5beec147b79d..57729ebc05f1 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/2d.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/2d.js @@ -195,7 +195,7 @@ function nullary2d( fcn, arrays, views, shape, stridesX, isRowMajor, strategyX, setViewOffsets( views, iv ); v[ 0 ] = strategyX.input( views[ 0 ] ); fcn( v, opts ); - strategyX.output( views[ 0 ]); + strategyX.output( views[ 0 ] ); incrementOffsets( iv, dv0 ); } incrementOffsets( iv, dv1 ); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/initialize_array_views.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/initialize_array_views.js index aebae736c6b7..5fda0b0f5319 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/initialize_array_views.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/initialize_array_views.js @@ -21,12 +21,13 @@ // MODULES // var descriptor = require( '@stdlib/ndarray/base/descriptor' ); +var slice = require( '@stdlib/array/base/slice' ); // MAIN // /** -* Initialize ndarray-like objects for representing zero-dimensional sub-array views of ancillary ndarray arguments. +* Initialize ndarray-like objects for representing sub-array views of ancillary ndarray arguments. * * ## Notes * @@ -35,17 +36,22 @@ var descriptor = require( '@stdlib/ndarray/base/descriptor' ); * * @private * @param {ArrayLikeObject} arrays - list of ndarray-like objects +* @param {NonNegativeInteger} k - number of non-reduced dimensions * @param {Array} out - output array * @returns {Array} output array */ -function initializeViews( arrays, out ) { +function initializeViews( arrays, k, out ) { + var sh; + var N; var v; var o; var i; for ( i = 1; i < arrays.length; i++ ) { v = arrays[ i ]; - o = descriptor( v.dtype, v.data, [], [ 0 ], v.offset, v.order ); + sh = v.shape; + N = sh.length; + o = descriptor( v.dtype, v.data, slice( sh, k, N ), ( N === k ) ? [ 0 ] : slice( v.strides, k, N ), v.offset, v.order ); // eslint-disable-line max-len out.push( o ); } return out; diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/main_factory.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/main_factory.js index 1f5dd733b280..9d8cffc78337 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/main_factory.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/main_factory.js @@ -292,10 +292,12 @@ function factory( options ) { if ( M > ndims ) { throw new RangeError( format( 'invalid argument. Number of specified dimensions cannot exceed the number of dimensions in the input array. Number of dimensions: %d. Value: [%s].', ndims, join( dims, ',' ) ) ); } - // Verify that provided ancillary ndarrays have the expected number of dimensions... + // Compute the number of loop dimensions: K = ndims - M; + + // Verify that any ancillary ndarrays have at least the number of loop dimensions... for ( i = 1; i < N; i++ ) { - if ( arr[ i ].shape.length !== K ) { + if ( arr[ i ].shape.length < K ) { throw new Error( format( 'invalid argument. Array arguments after the first array must have the same number of loop dimensions. Input array shape: [%s]. Number of loop dimensions: %d. Array shape: [%s] (index: %d).', join( shx, ',' ), K, join( arr[ i ].shape, ',' ), i ) ); } } @@ -315,7 +317,7 @@ function factory( options ) { ns = 0; // number of singleton dimensions for ( i = 0; i < K; i++ ) { s = shl[ i ]; - for ( j = 2; j < N; j++ ) { + for ( j = 1; j < N; j++ ) { if ( s !== arr[ j ].shape[ i ] ) { throw new Error( format( 'invalid argument. Loop dimensions must be consistent across all provided arrays. Input array shape: [%s]. Loop dimension indices: [%s]. Loop dimensions: [%s]. Array shape: [%s] (index: %d).', join( shx, ',' ), join( ldims, ',' ), join( shl, ',' ), join( arr[ j ].shape, ',' ), j ) ); } @@ -336,7 +338,7 @@ function factory( options ) { views = [ descriptor( x.dtype, x.data, shc, scx, x.offset, x.order ) ]; - initializeViews( arr, views ); + initializeViews( arr, K, views ); // Determine the strategy for marshaling data to and from sub-array views of the input array before and after performing an operation: strategyX = strategy( views[ 0 ] ); diff --git a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/strategy.js b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/strategy.js index c7c734da8906..c488c0507fb6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/strategy.js +++ b/lib/node_modules/@stdlib/ndarray/base/nullary-strided1d/lib/strategy.js @@ -179,7 +179,7 @@ function copyFromWorkspace( workspace ) { * * @private * @param {ndarrayLike} x - input ndarray -* @param {string} x.dtype - input ndarray data type +* @param {*} x.dtype - input ndarray data type * @param {Collection} x.data - input ndarray data buffer * @param {NonNegativeIntegerArray} x.shape - input ndarray shape * @param {IntegerArray} x.strides - input ndarray strides