Skip to content

Commit 88a7c4d

Browse files
committed
refactor: add support for ancillary ndarray arguments having trailing dimensions
--- 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 status: passed - task: lint_package_json status: na - task: lint_repl_help status: skipped - 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 ---
1 parent 7559ce0 commit 88a7c4d

5 files changed

Lines changed: 39 additions & 15 deletions

File tree

lib/node_modules/@stdlib/ndarray/base/unary-strided1d/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ Each provided ndarray should be an object with the following properties:
138138

139139
## Notes
140140

141-
- Any additional ndarray arguments are expected to have the same dimensions as the loop dimensions of the input ndarray. When calling the strided array function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects.
141+
- Any additional ndarray arguments are expected to have the same leading dimensions as the loop dimensions of the input ndarray.
142+
143+
- 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 input ndarray. For example, if an input 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 input 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.
142144

143145
- The strided array function is expected to have the following signature:
144146

@@ -148,7 +150,7 @@ Each provided ndarray should be an object with the following properties:
148150
149151
where
150152
151-
- **arrays**: array containing a one-dimensional subarray of the input ndarray, a one-dimensional subarray of the output ndarray, and any additional ndarray arguments as zero-dimensional ndarrays.
153+
- **arrays**: array containing a one-dimensional subarray of the input ndarray, a one-dimensional subarray of the output ndarray, and any additional ndarray arguments as subarrays.
152154
- **options**: function options (_optional_).
153155
154156
- The function iterates over ndarray elements according to the memory layout of the input ndarray.

lib/node_modules/@stdlib/ndarray/base/unary-strided1d/docs/repl.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@
1414
- order: specifies whether an ndarray is row-major (C-style) or column-major
1515
(Fortran-style).
1616

17-
Any additional ndarray arguments are expected to have the same dimensions as
18-
the loop dimensions of the input ndarray. When calling the strided array
19-
function, any additional ndarray arguments are provided as zero-dimensional
20-
ndarray-like objects.
17+
Any additional ndarray arguments are expected to have the same leading
18+
dimensions as the loop dimensions of the input ndarray.
19+
20+
When calling the strided array function, any additional ndarray arguments
21+
are provided as k-dimensional subarrays, where `k = M - N` with `M` being
22+
the number of dimensions in an ndarray argument and `N` being the number of
23+
loop dimensions for the input ndarray. For example, if an input ndarray has
24+
three dimensions, the number of loop dimensions is one, and an additional
25+
ndarray argument has one dimension, thus matching the number of loop
26+
dimensions for the input ndarray, the strided array function is provided a
27+
zero-dimensional subarray as an additional ndarray argument. In the same
28+
scenario but where an additional ndarray argument has two dimensions, thus
29+
exceeding the number of loop dimensions, the strided array function is
30+
provided a one-dimensional subarray as an additional ndarray argument.
2131

2232
Parameters
2333
----------
@@ -32,7 +42,7 @@
3242

3343
- arrays: array containing a one-dimensional subarray of the input
3444
ndarray, a one-dimensional subarray of the output ndarray, and any
35-
additional ndarray arguments as zero-dimensional ndarrays.
45+
additional ndarray arguments as subarrays.
3646
- options: function options.
3747

3848
arrays: ArrayLikeObject<ndarray>

lib/node_modules/@stdlib/ndarray/base/unary-strided1d/lib/initialize_array_views.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@
1818

1919
'use strict';
2020

21+
// MODULES //
22+
23+
var slice = require( '@stdlib/array/base/slice' );
24+
25+
2126
// MAIN //
2227

2328
/**
24-
* Initialize ndarray-like objects for representing zero-dimensional sub-array views of ancillary ndarray arguments.
29+
* Initialize ndarray-like objects for representing sub-array views of ancillary ndarray arguments.
2530
*
2631
* ## Notes
2732
*
@@ -30,20 +35,25 @@
3035
*
3136
* @private
3237
* @param {ArrayLikeObject<Object>} arrays - list of ndarray-like objects
38+
* @param {NonNegativeInteger} k - number of non-reduced dimensions
3339
* @param {Array<Object>} out - output array
3440
* @returns {Array<Object>} output array
3541
*/
36-
function initializeViews( arrays, out ) {
42+
function initializeViews( arrays, k, out ) {
43+
var sh;
44+
var N;
3745
var v;
3846
var i;
3947

4048
for ( i = 2; i < arrays.length; i++ ) {
4149
v = arrays[ i ];
50+
sh = v.shape;
51+
N = sh.length;
4252
out.push({
4353
'dtype': v.dtype,
4454
'data': v.data,
45-
'shape': [],
46-
'strides': [ 0 ],
55+
'shape': slice( sh, k, N ),
56+
'strides': ( N === k ) ? [ 0 ] : slice( v.strides, k, N ),
4757
'offset': v.offset,
4858
'order': v.order
4959
});

lib/node_modules/@stdlib/ndarray/base/unary-strided1d/lib/main_factory.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,12 @@ function factory( options ) {
400400
if ( M > ndims ) {
401401
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, ',' ) ) );
402402
}
403-
// Verify that provided ancillary ndarrays have the expected number of dimensions...
403+
// Compute the number of non-reduced dimensions:
404404
K = ndims - M;
405+
406+
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
405407
for ( i = 2; i < N; i++ ) {
406-
if ( arr[ i ].shape.length !== K ) {
408+
if ( arr[ i ].shape.length < K ) {
407409
throw new Error( format( 'invalid argument. Array arguments after the first two arrays 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 ) );
408410
}
409411
}
@@ -472,7 +474,7 @@ function factory( options ) {
472474
'order': y.order
473475
}
474476
];
475-
initializeViews( arr, views );
477+
initializeViews( arr, K, views );
476478

477479
// Determine the strategy for marshaling data to and from sub-array views of the input and output arrays before and after performing an operation:
478480
strategyX = strategy( views[ 0 ] );

lib/node_modules/@stdlib/ndarray/base/unary-strided1d/lib/strategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function copyFromWorkspace( workspace ) {
209209
*
210210
* @private
211211
* @param {ndarrayLike} x - input ndarray
212-
* @param {string} x.dtype - input ndarray data type
212+
* @param {*} x.dtype - input ndarray data type
213213
* @param {Collection} x.data - input ndarray data buffer
214214
* @param {NonNegativeIntegerArray} x.shape - input ndarray shape
215215
* @param {IntegerArray} x.strides - input ndarray strides

0 commit comments

Comments
 (0)