Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Oct 6, 2023
1 parent 857193b commit 2f9ba9f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 135 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

34 changes: 3 additions & 31 deletions iter/columns/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,11 @@ var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var numel = require( './../../../base/numel' );
var slice = require( './../../../base/slice' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
var MultiSlice = require( '@stdlib/slice/multi' );
var format = require( '@stdlib/string/format' );


// FUNCTIONS //

/**
* Increments stack indices.
*
* @private
* @param {NonNegativeInteger} ndims - number of dimensions
* @param {NonNegativeIntegerArray} shape - array shape
* @param {NonNegativeIntegerArray} idx - current indices
* @returns {NonNegativeIntegerArray} updated indices
*/
function incrementIndices( ndims, shape, idx ) {
var i;
var j;

// Search for the first dimension in which we don't have to "carry the one"...
for ( i = ndims-3; i >= 0; i-- ) {
j = ( idx[ i ] + 1 ) % shape[ i ];
idx[ i ] = j;

// If the current index value is greater than zero, we can continue iterating within the current sub-array...
if ( j > 0 ) {
break;
}
}
return idx;
}


// MAIN //

/**
Expand Down Expand Up @@ -136,7 +108,7 @@ function nditerColumns( x ) {
opts.writable = !options.readonly;
}
}
// Retrieve the input array shape:
// Retrieve input array meta data:
shape = x.shape;
ndims = shape.length;

Expand Down Expand Up @@ -197,7 +169,7 @@ function nditerColumns( x ) {
idx[ dim ] = j;
if ( j === 0 ) {
// If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:
incrementIndices( ndims, shape, idx );
idx = nextCartesianIndex( shape, 'row-major', idx, dim-2, idx );
}
// Return the next column slice:
return {
Expand Down
71 changes: 2 additions & 69 deletions iter/indices/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,10 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var numel = require( './../../../base/numel' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
var format = require( '@stdlib/string/format' );


// FUNCTIONS //

/**
* Increments indices in row-major order.
*
* @private
* @param {NonNegativeInteger} ndims - number of dimensions
* @param {NonNegativeIntegerArray} shape - array shape
* @param {NonNegativeIntegerArray} idx - current indices
* @returns {NonNegativeIntegerArray} updated indices
*/
function nextRowMajor( ndims, shape, idx ) {
var i;
var j;

// Search for the first dimension in which we don't have to "carry the one"...
for ( i = ndims-2; i >= 0; i-- ) {
j = ( idx[ i ] + 1 ) % shape[ i ];
idx[ i ] = j;

// If the current index value is greater than zero, we can continue iterating within the current sub-array...
if ( j > 0 ) {
break;
}
}
return idx;
}

/**
* Increments indices in column-major order.
*
* @private
* @param {NonNegativeInteger} ndims - number of dimensions
* @param {NonNegativeIntegerArray} shape - array shape
* @param {NonNegativeIntegerArray} idx - current indices
* @returns {NonNegativeIntegerArray} updated indices
*/
function nextColumnMajor( ndims, shape, idx ) {
var i;
var j;

// Search for the first dimension in which we don't have to "carry the one"...
for ( i = 1; i < ndims; i++ ) {
j = ( idx[ i ] + 1 ) % shape[ i ];
idx[ i ] = j;

// If the current index value is greater than zero, we can continue iterating within the current sub-array...
if ( j > 0 ) {
break;
}
}
return idx;
}


// MAIN //

/**
Expand Down Expand Up @@ -128,8 +74,6 @@ function nditerIndices( shape ) {
var idx;
var dim;
var sh;
var f;
var S;
var N;
var i;

Expand Down Expand Up @@ -170,13 +114,9 @@ function nditerIndices( shape ) {
// Resolve the dimension in which indices iterate fastest:
if ( opts.order === 'row-major' ) {
dim = ndims - 1;
f = nextRowMajor;
} else {
dim = 0;
f = nextColumnMajor;
}
S = sh[ dim ];

// Initialize a counter:
i = -1;

Expand All @@ -201,21 +141,14 @@ function nditerIndices( shape ) {
* @returns {Object} iterator protocol-compliant object
*/
function next() {
var j;
i += 1;
if ( FLG || i >= N ) {
return {
'done': true
};
}
if ( i > 0 ) {
// Update the index array:
j = ( idx[ dim ] + 1 ) % S;
idx[ dim ] = j;
if ( j === 0 ) {
// If we've iterated over all the elements in the current dimension, move on to the next sub-array:
f( ndims, sh, idx );
}
idx = nextCartesianIndex( shape, opts.order, idx, dim, idx );
}
// Return the next set of indices:
return {
Expand Down
34 changes: 3 additions & 31 deletions iter/rows/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,11 @@ var iteratorSymbol = require( '@stdlib/symbol/iterator' );
var zeros = require( '@stdlib/array/base/zeros' );
var numel = require( './../../../base/numel' );
var slice = require( './../../../base/slice' );
var nextCartesianIndex = require( './../../../base/next-cartesian-index' ).assign;
var MultiSlice = require( '@stdlib/slice/multi' );
var format = require( '@stdlib/string/format' );


// FUNCTIONS //

/**
* Increments stack indices.
*
* @private
* @param {NonNegativeInteger} ndims - number of dimensions
* @param {NonNegativeIntegerArray} shape - array shape
* @param {NonNegativeIntegerArray} idx - current indices
* @returns {NonNegativeIntegerArray} updated indices
*/
function incrementIndices( ndims, shape, idx ) {
var i;
var j;

// Search for the first dimension in which we don't have to "carry the one"...
for ( i = ndims-3; i >= 0; i-- ) {
j = ( idx[ i ] + 1 ) % shape[ i ];
idx[ i ] = j;

// If the current index value is greater than zero, we can continue iterating within the current sub-array...
if ( j > 0 ) {
break;
}
}
return idx;
}


// MAIN //

/**
Expand Down Expand Up @@ -136,7 +108,7 @@ function nditerRows( x ) {
opts.writable = !options.readonly;
}
}
// Retrieve the input array shape:
// Retrieve input array meta data:
shape = x.shape;
ndims = shape.length;

Expand Down Expand Up @@ -197,7 +169,7 @@ function nditerRows( x ) {
idx[ dim ] = j;
if ( j === 0 ) {
// If we've iterated over all the rows in the current matrix, move on to the next matrix in the stack:
incrementIndices( ndims, shape, idx );
idx = nextCartesianIndex( shape, 'row-major', idx, dim-1, idx );
}
// Return the next row slice:
return {
Expand Down

0 comments on commit 2f9ba9f

Please sign in to comment.