Skip to content

Commit a1ad58d

Browse files
committed
Auto-generated commit
1 parent fa463e3 commit a1ad58d

File tree

32 files changed

+304
-141
lines changed

32 files changed

+304
-141
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@ A total of 45 issues were closed in this release:
820820

821821
<details>
822822

823+
- [`c13dd70`](https://github.com/stdlib-js/stdlib/commit/c13dd703daff4a5893dac860a78fe6e0631e68ec) - **refactor:** normalize dtypes to enums to reduce memory consumption and speed-up comparisons _(by Athan Reines)_
824+
- [`2041e12`](https://github.com/stdlib-js/stdlib/commit/2041e12c968c4bd6f4a4f051271aacaa65727a6d) - **docs:** ensure support for dtype instances and update examples _(by Athan Reines)_
825+
- [`88a7c4d`](https://github.com/stdlib-js/stdlib/commit/88a7c4de78c60740018a7038279248e48a2019cc) - **refactor:** add support for ancillary ndarray arguments having trailing dimensions _(by Athan Reines)_
826+
- [`9929838`](https://github.com/stdlib-js/stdlib/commit/99298389ec07331f424d4a8ed570d974d7ad3c44) - **refactor:** add support for ancillary ndarray arguments having trailing dimensions _(by Athan Reines)_
827+
- [`ed8da6f`](https://github.com/stdlib-js/stdlib/commit/ed8da6f296e6031ef298cbeeb03ee121fdf0d0a7) - **refactor:** add support for ancillary ndarray arguments having trailing dimensions _(by Athan Reines)_
828+
- [`94e56f0`](https://github.com/stdlib-js/stdlib/commit/94e56f0ce160c8d5409fd7750ff42c4249704e5c) - **refactor:** add support for ancillary ndarray arguments having trailing dimensions _(by Athan Reines)_
829+
- [`07462e4`](https://github.com/stdlib-js/stdlib/commit/07462e494d3442559bb88d713009f50f9130b33e) - **refactor:** support ancillary ndarray arguments with trailing dimensions _(by Athan Reines)_
830+
- [`686981c`](https://github.com/stdlib-js/stdlib/commit/686981c226ea4589c3fc53ef0b1c8c3ccfc70809) - **refactor:** move assignment expression _(by Athan Reines)_
823831
- [`16c408d`](https://github.com/stdlib-js/stdlib/commit/16c408d950173630d6d458987f0d4d0a5e0c9f3e) - **docs:** fix copy _(by Athan Reines)_
824832
- [`c8df03c`](https://github.com/stdlib-js/stdlib/commit/c8df03cfe4cb5362cfff5f981aff4c0abc6d0e5a) - **refactor:** add support for ancilliary ndarrays which decompose into subarrays _(by Athan Reines)_
825833
- [`da18a82`](https://github.com/stdlib-js/stdlib/commit/da18a821cb5b0e559658144a92a9fc1876d7345e) - **style:** reorder declarations _(by Athan Reines)_

base/unary-reduce-strided1d-assign-struct/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ Each provided ndarray should be an object with the following properties:
154154

155155
## Notes
156156

157-
- The output ndarray and any additional ndarray arguments are expected to have the same dimensions as the non-reduced dimensions of the input ndarray. When calling the reduction function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects.
157+
- The output ndarray is expected to have the same dimensions as the non-reduced dimensions of the input ndarray.
158+
159+
- Any additional ndarray arguments are expected to have the same leading dimensions as the non-reduced dimensions of the input ndarray.
160+
161+
- When calling the reduction 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 non-reduced dimensions in the input ndarray. For example, if an input ndarray has three dimensions, the number of reduced dimensions is two, and an additional ndarray argument has one dimension, thus matching the number of non-reduced dimensions in the input ndarray, the reduction 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 non-reduced dimensions in the input ndarray, the reduction function is provided a one-dimensional subarray as an additional ndarray argument.
158162

159163
- The reduction function is expected to have the following signature:
160164

@@ -164,7 +168,7 @@ Each provided ndarray should be an object with the following properties:
164168
165169
where
166170
167-
- **arrays**: array containing a one-dimensional subarray of the input ndarray, a zero-dimensional subarray of the output ndarray containing the output [`struct`][@stdlib/dstructs/struct] object, and any additional ndarray arguments as zero-dimensional ndarrays.
171+
- **arrays**: array containing a one-dimensional subarray of the input ndarray, a zero-dimensional subarray of the output ndarray containing the output [`struct`][@stdlib/dstructs/struct] object, and any additional ndarray arguments as subarrays.
168172
- **options**: function options (_optional_).
169173
170174
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing a reduction in order to achieve better performance.

base/unary-reduce-strided1d-assign-struct/docs/repl.txt

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

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

2236
Parameters
2337
----------
@@ -32,8 +46,8 @@
3246

3347
- arrays: array containing a one-dimensional subarray of the input
3448
ndarray, a zero-dimensional subarray of the output ndarray containing
35-
the output struct object, and any additional ndarray arguments as zero-
36-
dimensional ndarrays.
49+
the output struct object, and any additional ndarray arguments as
50+
subarrays.
3751
- options: function options.
3852

3953
arrays: ArrayLikeObject<ndarray>

base/unary-reduce-strided1d-assign-struct/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 the output and ancillary ndarray arguments.
29+
* Initialize ndarray-like objects for representing sub-array views of the output and 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 = 1; 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
});

base/unary-reduce-strided1d-assign-struct/lib/main.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,16 @@ function unaryReduceStrided1d( fcn, arrays, dims, options ) {
416416
if ( M > ndims ) {
417417
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, ',' ) ) );
418418
}
419-
// Verify that provided ndarrays have the expected number of dimensions...
419+
// Compute the number of non-reduced dimensions:
420420
K = ndims - M;
421-
for ( i = 1; i < N; i++ ) {
422-
if ( arr[ i ].shape.length !== K ) {
421+
422+
// Verify that the output ndarray has the expected number of dimensions...
423+
if ( arr[ 1 ].shape.length !== K ) {
424+
throw new Error( format( 'invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).', join( shx, ',' ), K, join( arr[ 1 ].shape, ',' ), 1 ) );
425+
}
426+
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
427+
for ( i = 2; i < N; i++ ) {
428+
if ( arr[ i ].shape.length < K ) {
423429
throw new Error( format( 'invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).', join( shx, ',' ), K, join( arr[ i ].shape, ',' ), i ) );
424430
}
425431
}
@@ -467,7 +473,7 @@ function unaryReduceStrided1d( fcn, arrays, dims, options ) {
467473
'order': x.order
468474
}
469475
];
470-
initializeViews( arr, views );
476+
initializeViews( arr, K, views );
471477

472478
// Determine the strategy for reshaping sub-array views of the input array prior to performing a reduction:
473479
strategy = reshapeStrategy( views[ 0 ] );
@@ -480,8 +486,6 @@ function unaryReduceStrided1d( fcn, arrays, dims, options ) {
480486
if ( K === 1 ) {
481487
return UNARY[ K ]( fcn, arr, views, sl, strategy, opts );
482488
}
483-
sy = y.strides;
484-
485489
// Determine whether the loop dimensions have only **one** non-singleton dimension (e.g., shape=[10,1,1,1]) so that we can treat loop iteration as being equivalent to one-dimensional iteration...
486490
if ( ns === K-1 ) {
487491
// Get the index of the non-singleton dimension...
@@ -497,6 +501,7 @@ function unaryReduceStrided1d( fcn, arrays, dims, options ) {
497501
sl = [ sl[i] ];
498502
return UNARY[ 1 ]( fcn, arr, views, sl, strategy, opts );
499503
}
504+
sy = y.strides;
500505
iox = iterationOrder( sl ); // +/-1
501506
ioy = iterationOrder( sy ); // +/-1
502507

base/unary-reduce-strided1d-assign-struct/lib/reshape_strategy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function copy( len, workspace ) {
186186
*
187187
* @private
188188
* @param {ndarrayLike} x - input ndarray
189-
* @param {string} x.dtype - input ndarray data type
189+
* @param {*} x.dtype - input ndarray data type
190190
* @param {Collection} x.data - input ndarray data buffer
191191
* @param {NonNegativeIntegerArray} x.shape - input ndarray shape
192192
* @param {IntegerArray} x.strides - input ndarray strides

base/unary-reduce-strided1d-by/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ var count = ctx.count;
195195

196196
## Notes
197197

198-
- The output ndarray and any additional ndarray arguments are expected to have the same dimensions as the non-reduced dimensions of the input ndarray. When calling the reduction function, any additional ndarray arguments are provided as zero-dimensional ndarray-like objects.
198+
- The output ndarray is expected to have the same dimensions as the non-reduced dimensions of the input ndarray.
199+
200+
- Any additional ndarray arguments are expected to have the same leading dimensions as the non-reduced dimensions of the input ndarray.
201+
202+
- When calling the reduction 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 non-reduced dimensions in the input ndarray. For example, if an input ndarray has three dimensions, the number of reduced dimensions is two, and an additional ndarray argument has one dimension, thus matching the number of non-reduced dimensions in the input ndarray, the reduction 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 non-reduced dimensions in the input ndarray, the reduction function is provided a one-dimensional subarray as an additional ndarray argument.
199203

200204
- The reduction function is expected to have the following signature:
201205

@@ -205,7 +209,7 @@ var count = ctx.count;
205209
206210
where
207211
208-
- **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as zero-dimensional ndarrays.
212+
- **arrays**: array containing a one-dimensional subarray of the input ndarray and any additional ndarray arguments as subarrays.
209213
- **options**: function options (_optional_).
210214
- **clbk**: callback function.
211215
- **thisArg**: callback execution context (_optional_).

base/unary-reduce-strided1d-by/docs/repl.txt

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

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

2236
Parameters
2337
----------
@@ -31,8 +45,7 @@
3145
where
3246

3347
- arrays: array containing a one-dimensional subarray of the input
34-
ndarray and any additional ndarray arguments as zero-dimensional
35-
ndarrays.
48+
ndarray and any additional ndarray arguments as subarrays.
3649
- options: function options.
3750
- clbk: callback function.
3851
- thisArg: callback execution context.

base/unary-reduce-strided1d-by/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
});

base/unary-reduce-strided1d-by/lib/main.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,16 @@ function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { /
391391
if ( M > ndims ) {
392392
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, ',' ) ) );
393393
}
394-
// Verify that provided ndarrays have the expected number of dimensions...
394+
// Compute the number of non-reduced dimensions:
395395
K = ndims - M;
396-
for ( i = 1; i < N; i++ ) {
397-
if ( arr[ i ].shape.length !== K ) {
396+
397+
// Verify that the output ndarray has the expected number of dimensions...
398+
if ( arr[ 1 ].shape.length !== K ) {
399+
throw new Error( format( 'invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).', join( shx, ',' ), K, join( arr[ 1 ].shape, ',' ), 1 ) );
400+
}
401+
// Verify that any ancillary ndarrays have at least the number of non-reduced dimensions...
402+
for ( i = 2; i < N; i++ ) {
403+
if ( arr[ i ].shape.length < K ) {
398404
throw new Error( format( 'invalid argument. Arrays which are not being reduced must have the same number of non-reduced dimensions. Input array shape: [%s]. Number of non-reduced dimensions: %d. Array shape: [%s] (index: %d).', join( shx, ',' ), K, join( arr[ i ].shape, ',' ), i ) );
399405
}
400406
}
@@ -439,7 +445,7 @@ function unaryReduceStrided1dBy( fcn, arrays, dims, options, clbk, thisArg ) { /
439445
'order': x.order
440446
}
441447
];
442-
initializeViews( arr, views );
448+
initializeViews( arr, K, views );
443449

444450
// Determine the strategy for reshaping sub-array views of the input array prior to performing a reduction:
445451
strategy = reshapeStrategy( views[ 0 ] );

0 commit comments

Comments
 (0)