Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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<ndarray>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -35,17 +36,22 @@ var descriptor = require( '@stdlib/ndarray/base/descriptor' );
*
* @private
* @param {ArrayLikeObject<Object>} arrays - list of ndarray-like objects
* @param {NonNegativeInteger} k - number of non-reduced dimensions
* @param {Array<Object>} out - output array
* @returns {Array<Object>} 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Expand All @@ -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 ) );
}
Expand All @@ -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 ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down