@@ -29,39 +29,11 @@ var iteratorSymbol = require( '@stdlib/symbol/iterator' );
2929var zeros = require ( '@stdlib/array/base/zeros' ) ;
3030var numel = require ( '@stdlib/ndarray/base/numel' ) ;
3131var slice = require ( '@stdlib/ndarray/base/slice' ) ;
32+ var nextCartesianIndex = require ( '@stdlib/ndarray/base/next-cartesian-index' ) . assign ;
3233var MultiSlice = require ( '@stdlib/slice/multi' ) ;
3334var format = require ( '@stdlib/string/format' ) ;
3435
3536
36- // FUNCTIONS //
37-
38- /**
39- * Increments stack indices.
40- *
41- * @private
42- * @param {NonNegativeInteger } ndims - number of dimensions
43- * @param {NonNegativeIntegerArray } shape - array shape
44- * @param {NonNegativeIntegerArray } idx - current indices
45- * @returns {NonNegativeIntegerArray } updated indices
46- */
47- function incrementIndices ( ndims , shape , idx ) {
48- var i ;
49- var j ;
50-
51- // Search for the first dimension in which we don't have to "carry the one"...
52- for ( i = ndims - 3 ; i >= 0 ; i -- ) {
53- j = ( idx [ i ] + 1 ) % shape [ i ] ;
54- idx [ i ] = j ;
55-
56- // If the current index value is greater than zero, we can continue iterating within the current sub-array...
57- if ( j > 0 ) {
58- break ;
59- }
60- }
61- return idx ;
62- }
63-
64-
6537// MAIN //
6638
6739/**
@@ -136,7 +108,7 @@ function nditerColumns( x ) {
136108 opts . writable = ! options . readonly ;
137109 }
138110 }
139- // Retrieve the input array shape :
111+ // Retrieve input array meta data :
140112 shape = x . shape ;
141113 ndims = shape . length ;
142114
@@ -197,7 +169,7 @@ function nditerColumns( x ) {
197169 idx [ dim ] = j ;
198170 if ( j === 0 ) {
199171 // If we've iterated over all the columns in the current matrix, move on to the next matrix in the stack:
200- incrementIndices ( ndims , shape , idx ) ;
172+ idx = nextCartesianIndex ( shape , 'row-major' , idx , dim - 2 , idx ) ;
201173 }
202174 // Return the next column slice:
203175 return {
0 commit comments