Skip to content

Commit

Permalink
refactor: duplicate shape iteration and fix annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Jul 31, 2024
1 parent e4c8807 commit f081548
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/node_modules/@stdlib/ndarray/base/map/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
*
* // Create the input and output ndarray-like objects:
* var x = {
* 'ref': null,
* 'dtype': 'float64',
* 'data': xbuf,
* 'shape': shape,
Expand Down
16 changes: 8 additions & 8 deletions lib/node_modules/@stdlib/ndarray/base/map/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
var iterationOrder = require( '@stdlib/ndarray/base/iteration-order' );
var minmaxViewBufferIndex = require( '@stdlib/ndarray/base/minmax-view-buffer-index' );
var ndarray2object = require( '@stdlib/ndarray/base/ndarraylike2object' );
var numel = require( '@stdlib/ndarray/base/numel' );
var blockedaccessormap2d = require( './2d_blocked_accessors.js' );
var blockedaccessormap3d = require( './3d_blocked_accessors.js' );
var blockedmap2d = require( './2d_blocked.js' );
Expand Down Expand Up @@ -81,7 +80,6 @@ var MAX_DIMS = MAP.length -1;
* - **offset**: index offset.
* - **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style).
*
* @private
* @param {ArrayLikeObject<Object>} arrays - array-like object containing one input array and one output array
* @param {Callback} fcn - callback function
* @param {*} [thisArg] - callback execution context
Expand Down Expand Up @@ -113,7 +111,6 @@ var MAX_DIMS = MAP.length -1;
*
* // Create the input and output ndarray-like objects:
* var x = {
* 'ref': null,
* 'dtype': 'float64',
* 'data': xbuf,
* 'shape': shape,
Expand Down Expand Up @@ -163,7 +160,6 @@ function map( arrays, fcn, thisArg ) {
shx = x.shape;
shy = y.shape;
ndims = shx.length;
len = numel( shx );
if ( ndims !== shy.length ) {
throw new Error( 'invalid arguments. Arrays must have the same number of dimensions (i.e., same rank). ndims(x) == '+ndims+'. ndims(y) == '+shy.length+'.' );
}
Expand All @@ -174,22 +170,26 @@ function map( arrays, fcn, thisArg ) {
}
return MAP[ ndims ]( x, y, fcn, thisArg );
}
// Check whether we were provided an empty ndarray...
if ( len === 0 ) {
return;
}
// Verify that the input and output arrays have the same dimensions...
len = 1; // number of elements
ns = 0; // number of singleton dimensions
for ( i = 0; i < ndims; i++ ) {
d = shx[ i ];
if ( d !== shy[ i ] ) {
throw new Error( 'invalid arguments. Array must have the same shape.' );
}
// Note that, if one of the dimensions is `0`, the length will be `0`...
len *= d;

// Check whether the current dimension is a singleton dimension...
if ( d === 1 ) {
ns += 1;
}
}
// Check whether we were provided empty ndarrays...
if ( len === 0 ) {
return;
}
// Determine whether the ndarrays are one-dimensional and thus readily translate to one-dimensional strided arrays...
if ( ndims === 1 ) {
if ( x.accessorProtocol || y.accessorProtocol ) {
Expand Down

0 comments on commit f081548

Please sign in to comment.