diff --git a/base/lib/index.js b/base/lib/index.js
index 019a27e5..3d276602 100644
--- a/base/lib/index.js
+++ b/base/lib/index.js
@@ -364,6 +364,15 @@ setReadOnly( ns, 'minmaxViewBufferIndex', require( './../../base/minmax-view-buf
*/
setReadOnly( ns, 'ndarraylike2object', require( './../../base/ndarraylike2object' ) );
+/**
+* @name nextCartesianIndex
+* @memberof ns
+* @readonly
+* @type {Function}
+* @see {@link module:@stdlib/ndarray/base/next-cartesian-index}
+*/
+setReadOnly( ns, 'nextCartesianIndex', require( './../../base/next-cartesian-index' ) );
+
/**
* @name nonsingletonDimensions
* @memberof ns
diff --git a/base/next-cartesian-index/README.md b/base/next-cartesian-index/README.md
new file mode 100644
index 00000000..dfce526d
--- /dev/null
+++ b/base/next-cartesian-index/README.md
@@ -0,0 +1,173 @@
+
+
+# nextCartesianIndex
+
+> Return the next Cartesian index (i.e., set of subscripts/dimension indices).
+
+
+
+
+
+
+
+
+
+
+
+## Usage
+
+```javascript
+var nextCartesianIndex = require( '@stdlib/ndarray/base/next-cartesian-index' );
+```
+
+#### nextCartesianIndex( shape, order, idx, dim )
+
+Returns the next Cartesian index (i.e., set of subscripts/dimension indices).
+
+```javascript
+var idx = nextCartesianIndex( [ 2, 2, 2 ], 'row-major', [ 0, 0, 1 ], -1 );
+// returns [ 0, 1, 0 ]
+```
+
+The function accepts the following arguments:
+
+- **shape**: array shape.
+- **order**: index iteration order. Must be either `row-major` (C-style) or `column-major` (Fortran-style).
+- **idx**: current dimension indices.
+- **dim**: index of the dimension from which to start incrementing (inclusive).
+
+The `order` parameter specifies the index iteration order. When `order` is `row-major`, the last indices change fastest, and, when the `order` is `column-major`, the first indices change fastest.
+
+```javascript
+var idx = nextCartesianIndex( [ 2, 2, 2 ], 'column-major', [ 0, 1, 0 ], 0 );
+// returns [ 1, 1, 0 ]
+```
+
+The `dim` parameter controls which dimensions are incremented. When `order` is `row-major`, if `dim` equals `shape.length-1` (or equivalently `-1`), the function increments over all dimensions from right-to-left (last-to-first). Similarly, when `order` is `column-major`, if `dim` equals `0`, the function increments over all dimensions from left-to-right (first-to-last). To restrict which dimensions can be incremented, set `dim` to a value other than the respective end. For example,
+
+```javascript
+// Increment starting from the second-to-last dimension:
+var idx = nextCartesianIndex( [ 2, 2, 2 ], 'row-major', [ 0, 0, 0 ], -2 );
+// returns [ 0, 1, 0 ]
+
+idx = nextCartesianIndex( [ 2, 2, 2 ], 'row-major', idx, -2 );
+// returns [ 1, 0, 0 ]
+
+idx = nextCartesianIndex( [ 2, 2, 2 ], 'row-major', idx, -2 );
+// returns [ 1, 1, 0 ]
+```
+
+#### nextCartesianIndex.assign( shape, order, idx, dim, out )
+
+Returns the next Cartesian index (i.e., set of subscripts/dimension indices) and assigns results to a provided output array.
+
+```javascript
+var out = [ 0, 0, 0 ];
+var idx = nextCartesianIndex.assign( [ 2, 2, 2 ], 'row-major', [ 0, 0, 1 ], -1, out );
+// returns [ 0, 1, 0 ]
+
+var bool = ( out === idx );
+// returns true
+```
+
+The function accepts the following arguments:
+
+- **shape**: array shape.
+- **order**: index iteration order. Must be either `row-major` (C-style) or `column-major` (Fortran-style).
+- **idx**: current dimension indices.
+- **dim**: index of the dimension from which to start incrementing (inclusive).
+- **out**: output array.
+
+
+
+
+
+
+
+
+
+## Notes
+
+- The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
+- If provided an empty shape (i.e., a shape corresponding to a zero-dimensional ndarray) or a dimension index `dim` which is out-of-bounds, the function returns `null`.
+
+
+
+
+
+
+
+
+
+## Examples
+
+
+
+```javascript
+var array = require( '@stdlib/ndarray/array' );
+var zeroTo = require( '@stdlib/array/base/zero-to' );
+var nextCartesianIndex = require( '@stdlib/ndarray/base/next-cartesian-index' );
+
+// Create an ndarray:
+var x = array( zeroTo( 27 ), {
+ 'shape': [ 3, 3, 3 ]
+});
+
+// Initialize a set of indices:
+var idx = [ 0, 0, 0 ];
+
+// Iterate over each element in the array...
+var i;
+for ( i = 0; i < x.length; i++ ) {
+ console.log( 'x[%s] = %d', idx.join( ',' ), x.get.apply( x, idx ) );
+ idx = nextCartesianIndex.assign( x.shape, x.order, idx, -1, idx );
+}
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/base/next-cartesian-index/benchmark/benchmark.js b/base/next-cartesian-index/benchmark/benchmark.js
new file mode 100644
index 00000000..13064dbd
--- /dev/null
+++ b/base/next-cartesian-index/benchmark/benchmark.js
@@ -0,0 +1,120 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var bench = require( '@stdlib/bench' );
+var isArray = require( '@stdlib/assert/is-array' );
+var zeros = require( '@stdlib/array/base/zeros' );
+var pkg = require( './../package.json' ).name;
+var nextCartesianIndex = require( './../lib' );
+
+
+// MAIN //
+
+bench( pkg+':order=row-major,ndims=3', function benchmark( b ) {
+ var shape;
+ var out;
+ var i;
+
+ shape = [ 10, 10, 10 ];
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = nextCartesianIndex( shape, 'row-major', [ (i+2)%10, (i+1)%10, i%10 ], -1 );
+ if ( out.length !== shape.length ) {
+ b.fail( 'should have expected length' );
+ }
+ }
+ b.toc();
+ if ( !isArray( out ) ) {
+ b.fail( 'should return an array' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
+
+bench( pkg+':order=column-major,ndims=3', function benchmark( b ) {
+ var shape;
+ var out;
+ var i;
+
+ shape = [ 10, 10, 10 ];
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = nextCartesianIndex( shape, 'column-major', [ (i+2)%10, (i+1)%10, i%10 ], 0 );
+ if ( out.length !== shape.length ) {
+ b.fail( 'should have expected length' );
+ }
+ }
+ b.toc();
+ if ( !isArray( out ) ) {
+ b.fail( 'should return an array' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
+
+bench( pkg+':assign:order=row-major,ndims=3', function benchmark( b ) {
+ var shape;
+ var out;
+ var i;
+
+ shape = [ 10, 10, 10 ];
+ out = zeros( shape.length );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = nextCartesianIndex.assign( shape, 'row-major', [ (i+2)%10, (i+1)%10, i%10 ], -1, out );
+ if ( out.length !== shape.length ) {
+ b.fail( 'should have expected length' );
+ }
+ }
+ b.toc();
+ if ( !isArray( out ) ) {
+ b.fail( 'should return an array' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
+
+bench( pkg+':assign:order=column-major,ndims=3', function benchmark( b ) {
+ var shape;
+ var out;
+ var i;
+
+ shape = [ 10, 10, 10 ];
+ out = zeros( shape.length );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = nextCartesianIndex.assign( shape, 'column-major', [ (i+2)%10, (i+1)%10, i%10 ], 0, out );
+ if ( out.length !== shape.length ) {
+ b.fail( 'should have expected length' );
+ }
+ }
+ b.toc();
+ if ( !isArray( out ) ) {
+ b.fail( 'should return an array' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
diff --git a/base/next-cartesian-index/docs/repl.txt b/base/next-cartesian-index/docs/repl.txt
new file mode 100644
index 00000000..2e63b2a6
--- /dev/null
+++ b/base/next-cartesian-index/docs/repl.txt
@@ -0,0 +1,91 @@
+
+{{alias}}( shape, order, idx, dim )
+ Returns the next Cartesian index (i.e., set of subscripts/dimension
+ indices).
+
+ The function does not check whether the current index is the "last" index.
+ Instead, if the function is provided dimension indices corresponding to the
+ last element, the function will cycle back to the "first" index.
+
+ If provided an empty shape (i.e., a shape corresponding to a zero-
+ dimensional ndarray) or a dimension index which is out-of-bounds, the
+ function returns `null`.
+
+ Parameters
+ ----------
+ shape: ArrayLike
+ Array shape.
+
+ order: string
+ Index iteration order. Must be either row-major (C-style) or column-
+ major (Fortran-style).
+
+ idx: ArrayLike
+ Current dimension indices.
+
+ dim: integer
+ Index of the dimension from which to start incrementing (inclusive).
+
+ Returns
+ -------
+ out: Array|null
+ Updated dimension indices (or null).
+
+ Examples
+ --------
+ > var sh = [ 2, 2, 2 ];
+ > var ord = 'row-major';
+ > var idx = {{alias}}( sh, ord, [ 0, 0, 1 ], -1 )
+ [ 0, 1, 0 ]
+ > idx = {{alias}}( sh, ord, idx, -1 )
+ [ 0, 1, 1 ]
+
+
+{{alias}}.assign( shape, order, idx, dim, out )
+ Returns the next Cartesian index (i.e., set of subscripts/dimension
+ indices) and assigns results to a provided output array.
+
+ The function does not check whether the current index is the "last" index.
+ Instead, if the function is provided dimension indices corresponding to the
+ last element, the function will cycle back to the "first" index.
+
+ If provided an empty shape (i.e., a shape corresponding to a zero-
+ dimensional ndarray) or a dimension index which is out-of-bounds, the
+ function returns `null`.
+
+ Parameters
+ ----------
+ shape: ArrayLike
+ Array shape.
+
+ order: string
+ Index iteration order. Must be either row-major (C-style) or column-
+ major (Fortran-style).
+
+ idx: ArrayLike
+ Current dimension indices.
+
+ dim: integer
+ Index of the dimension from which to start incrementing (inclusive).
+
+ out: Array|TypedArray|Object
+ Output array.
+
+ Returns
+ -------
+ out: Array|TypedArray|Object
+ Output array.
+
+ Examples
+ --------
+ > var sh = [ 2, 2, 2 ];
+ > var ord = 'row-major';
+ > var out = [ 0, 0, 0 ];
+ > var idx = {{alias}}.assign( sh, ord, [ 0, 0, 1 ], -1, out )
+ [ 0, 1, 0 ]
+ > var bool = ( out === idx )
+ true
+
+ See Also
+ --------
+
diff --git a/base/next-cartesian-index/docs/types/index.d.ts b/base/next-cartesian-index/docs/types/index.d.ts
new file mode 100644
index 00000000..b5d0ee52
--- /dev/null
+++ b/base/next-cartesian-index/docs/types/index.d.ts
@@ -0,0 +1,207 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+// TypeScript Version: 4.1
+
+///
+
+import { Collection } from '@stdlib/types/array';
+import { Shape, Order } from '@stdlib/types/ndarray';
+
+/**
+* Interface describing `nextCartesianIndex`.
+*/
+interface Routine {
+ /**
+ * Returns the next Cartesian index (i.e., set of subscripts/dimension indices).
+ *
+ * ## Notes
+ *
+ * - The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
+ * - If provided an empty shape (i.e., a shape corresponding to a zero-dimensional ndarray) or a dimension index `dim` which is out-of-bounds, the function returns `null`.
+ *
+ * @param shape - array shape
+ * @param order - iteration order
+ * @param idx - current dimension indices
+ * @param dim - index of the dimension from which to start incrementing (inclusive)
+ * @returns updated dimension indices
+ *
+ * @example
+ * var shape = [ 12 ];
+ * var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], 0 );
+ * // returns [ 3 ]
+ *
+ * @example
+ * var shape = [ 2, 2, 2 ];
+ *
+ * var idx = nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1 );
+ * // returns [ 0, 1, 0 ]
+ *
+ * idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+ * // returns [ 0, 1, 1 ]
+ *
+ * idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+ * // returns [ 1, 0, 0 ]
+ *
+ * idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+ * // returns [ 1, 0, 1 ]
+ *
+ * idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+ * // returns [ 1, 1, 0 ]
+ *
+ * idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+ * // returns [ 1, 1, 1 ]
+ *
+ * @example
+ * var shape = [];
+ * var idx = nextCartesianIndex( shape, 'row-major', [], 0 );
+ * // returns null
+ *
+ * @example
+ * var shape = [ 12 ];
+ * var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], -10 );
+ * // returns null
+ *
+ * @example
+ * var shape = [ 12 ];
+ * var idx = nextCartesianIndex( shape, 'column-major', [ 2 ], 10 );
+ * // returns null
+ */
+ ( shape: Shape, order: Order, idx: Collection, dim: number ): Array | null;
+
+ /**
+ * Returns the next Cartesian index (i.e., set of subscripts/dimension indices) and assigns results to a provided output array.
+ *
+ * ## Notes
+ *
+ * - The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
+ * - If provided an empty shape (i.e., a shape corresponding to a zero-dimensional ndarray) or a dimension index `dim` which is out-of-bounds, the function returns `null`.
+ *
+ * @param shape - array shape
+ * @param order - iteration order
+ * @param idx - current dimension indices
+ * @param dim - index of the dimension from which to start incrementing (inclusive)
+ * @param out - output array
+ * @returns update dimension indices
+ *
+ * @example
+ * var shape = [ 12 ];
+ * var idx = nextCartesianIndex.assign( shape, 'row-major', [ 2 ], 0, [ 0 ] );
+ * // returns [ 3 ]
+ *
+ * @example
+ * var shape = [ 2, 2, 2 ];
+ *
+ * var out = [ 0, 0, 0 ];
+ * var idx = nextCartesianIndex.assign( shape, 'row-major', [ 0, 0, 1 ], -1, out );
+ * // returns [ 0, 1, 0 ]
+ *
+ * idx = nextCartesianIndex.assign( shape, 'row-major', idx, -1, out );
+ * // returns [ 0, 1, 1 ]
+ *
+ * idx = nextCartesianIndex.assign( shape, 'row-major', idx, -1, out );
+ * // returns [ 1, 0, 0 ]
+ *
+ * idx = nextCartesianIndex.assign( shape, 'row-major', idx, -1, out );
+ * // returns [ 1, 0, 1 ]
+ *
+ * idx = nextCartesianIndex.assign( shape, 'row-major', idx, -1, out );
+ * // returns [ 1, 1, 0 ]
+ *
+ * idx = nextCartesianIndex.assign( shape, 'row-major', idx, -1, out );
+ * // returns [ 1, 1, 1 ]
+ *
+ * @example
+ * var shape = [];
+ * var idx = nextCartesianIndex.assign( shape, 'row-major', [], 0, [] );
+ * // returns null
+ *
+ * @example
+ * var shape = [ 12 ];
+ * var idx = nextCartesianIndex.assign( shape, 'row-major', [ 2 ], -10, [ 0 ] );
+ * // returns null
+ *
+ * @example
+ * var shape = [ 12 ];
+ * var idx = nextCartesianIndex.assign( shape, 'column-major', [ 2 ], 10, [ 0 ] );
+ * // returns null
+ */
+ assign( shape: Shape, order: Order, idx: Collection, dim: number, out: Collection ): Collection | null;
+}
+
+/**
+* Returns the next Cartesian index (i.e., set of subscripts/dimension indices).
+*
+* ## Notes
+*
+* - The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
+* - If provided an empty shape (i.e., a shape corresponding to a zero-dimensional ndarray) or a dimension index `dim` which is out-of-bounds, the function returns `null`.
+*
+* @param shape - array shape
+* @param order - iteration order
+* @param idx - current dimension indices
+* @param dim - index of the dimension from which to start incrementing (inclusive)
+* @returns updated dimension indices
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], 0 );
+* // returns [ 3 ]
+*
+* @example
+* var shape = [ 2, 2, 2 ];
+*
+* var idx = nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1 );
+* // returns [ 0, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 0, 1, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 0, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 0, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 1, 1 ]
+*
+* @example
+* var shape = [];
+* var idx = nextCartesianIndex( shape, 'row-major', [], 0 );
+* // returns null
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], -10 );
+* // returns null
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'column-major', [ 2 ], 10 );
+* // returns null
+*/
+declare var nextCartesianIndex: Routine;
+
+
+// EXPORTS //
+
+export = nextCartesianIndex;
diff --git a/base/next-cartesian-index/docs/types/test.ts b/base/next-cartesian-index/docs/types/test.ts
new file mode 100644
index 00000000..e8a301a6
--- /dev/null
+++ b/base/next-cartesian-index/docs/types/test.ts
@@ -0,0 +1,157 @@
+/*
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import nextCartesianIndex = require( './index' );
+
+
+// TESTS //
+
+// The function returns an array of numbers (or null)...
+{
+ nextCartesianIndex( [ 3, 2, 1 ], 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectType number[] | null
+}
+
+// The compiler throws an error if the function is provided a first argument which is not an array-like object containing numbers...
+{
+ nextCartesianIndex( true, 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( false, 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( null, 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( undefined, 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( '5', 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ '1', '2' ], 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( {}, 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( ( x: number ): number => x, 'row-major', [ 0, 0, 0 ], -1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a second argument which is not a recognized order...
+{
+ nextCartesianIndex( [ 2, 3 ], true, [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], false, [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], null, [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], undefined, [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], '5', [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], [ '1', '2' ], [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], {}, [ 0, 0 ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], ( x: number ): number => x, [ 0, 0 ], -1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a third argument which is not an array of numbers...
+{
+ nextCartesianIndex( [ 2, 3 ], 'row-major', true, -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', false, -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', null, -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', undefined, -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', '5', -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ '1', '2' ], -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', {}, -1 ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', ( x: number ): number => x, -1 ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided a fourth argument which is not a number...
+{
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], true ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], false ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], null ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], undefined ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], '5' ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], [ '1', '2' ] ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], {} ); // $ExpectError
+ nextCartesianIndex( [ 2, 3 ], 'row-major', [ 0, 0 ], ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an unsupported number of arguments...
+{
+ nextCartesianIndex(); // $ExpectError
+ nextCartesianIndex( [ 3, 2 ] ); // $ExpectError
+ nextCartesianIndex( [ 3, 2 ], 'row-major' ); // $ExpectError
+ nextCartesianIndex( [ 3, 2 ], 'row-major', [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex( [ 3, 2 ], 'row-major', [ 0, 0 ], -1, {} ); // $ExpectError
+}
+
+// Attached to the main export is an `assign` method which returns a collection (or null)...
+{
+ nextCartesianIndex.assign( [ 3, 2, 1 ], 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectType Collection | null
+}
+
+// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object containing numbers...
+{
+ nextCartesianIndex.assign( true, 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( false, 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( null, 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( undefined, 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( '5', 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ '1', '2' ], 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( {}, 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( ( x: number ): number => x, 'row-major', [ 0, 0, 0 ], -1, [ 0, 0, 0 ] ); // $ExpectError
+}
+
+// The compiler throws an error if the `assign` method is provided a second argument which is not a recognized order...
+{
+ nextCartesianIndex.assign( [ 2, 3 ], true, [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], false, [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], null, [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], undefined, [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], '5', [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], [ '1', '2' ], [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], {}, [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], ( x: number ): number => x, [ 0, 0 ], -1, [ 0, 0 ] ); // $ExpectError
+}
+
+// The compiler throws an error if the `assign` method is provided a third argument which is not an array of numbers...
+{
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', true, -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', false, -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', null, -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', undefined, -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', '5', -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ '1', '2' ], -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', {}, -1, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', ( x: number ): number => x, -1, [ 0, 0 ] ); // $ExpectError
+}
+
+// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number...
+{
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], true, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], false, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], null, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], undefined, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], '5', [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], [ '1', '2' ], [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], {}, [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], ( x: number ): number => x, [ 0, 0 ] ); // $ExpectError
+}
+
+// The compiler throws an error if the `assign` method is provided a fifth argument which is not a collection...
+{
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, 1 ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, true ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, false ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, null ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, undefined ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, {} ); // $ExpectError
+ nextCartesianIndex.assign( [ 2, 3 ], 'row-major', [ 0, 0 ], -1, ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
+{
+ nextCartesianIndex.assign(); // $ExpectError
+ nextCartesianIndex.assign( [ 3, 2 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 3, 2 ], 'row-major' ); // $ExpectError
+ nextCartesianIndex.assign( [ 3, 2 ], 'row-major', [ 0, 0 ] ); // $ExpectError
+ nextCartesianIndex.assign( [ 3, 2 ], 'row-major', [ 0, 0 ], -1, [ 0, 0 ], {} ); // $ExpectError
+}
diff --git a/base/next-cartesian-index/examples/index.js b/base/next-cartesian-index/examples/index.js
new file mode 100644
index 00000000..d780499c
--- /dev/null
+++ b/base/next-cartesian-index/examples/index.js
@@ -0,0 +1,38 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var array = require( './../../../array' );
+var zeroTo = require( '@stdlib/array/base/zero-to' );
+var nextCartesianIndex = require( './../lib' );
+
+// Create an ndarray:
+var x = array( zeroTo( 27 ), {
+ 'shape': [ 3, 3, 3 ]
+});
+
+// Initialize a set of indices:
+var idx = [ 0, 0, 0 ];
+
+// Iterate over each element in the array...
+var i;
+for ( i = 0; i < x.length; i++ ) {
+ console.log( 'x[%s] = %d', idx.join( ',' ), x.get.apply( x, idx ) );
+ idx = nextCartesianIndex.assign( x.shape, x.order, idx, -1, idx );
+}
diff --git a/base/next-cartesian-index/lib/assign.js b/base/next-cartesian-index/lib/assign.js
new file mode 100644
index 00000000..9ee464e0
--- /dev/null
+++ b/base/next-cartesian-index/lib/assign.js
@@ -0,0 +1,184 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// VARIABLES //
+
+var ROW_MAJOR = 'row-major';
+
+
+// FUNCTIONS //
+
+/**
+* Returns the next Cartesian index (row-major).
+*
+* @private
+* @param {NonNegativeInteger} ndims - number of dimensions
+* @param {NonNegativeIntegerArray} shape - array shape
+* @param {NonNegativeIntegerArray} idx - current dimension indices
+* @param {NonNegativeInteger} dim - index of the dimension from which to start incrementing (inclusive)
+* @param {(Array|TypedArray|Object)} out - output array
+* @returns {(Array|TypedArray|Object)} output array
+*/
+function rowmajor( ndims, shape, idx, dim, out ) {
+ var i;
+ var j;
+
+ // Set dimension indices which are skipped...
+ for ( i = ndims-1; i > dim; i-- ) {
+ out[ i ] = idx[ i ];
+ }
+ // Search for the first dimension in which we don't have to "carry the one"...
+ for ( i = dim; i >= 0; i-- ) {
+ j = ( idx[ i ] + 1 ) % shape[ i ];
+ out[ i ] = j;
+
+ // If the current index value is greater than zero, we can continue iterating within the current sub-array...
+ if ( j > 0 ) {
+ break;
+ }
+ }
+ // Set dimension indices which did not get updated...
+ for ( i -= 1; i >= 0; i-- ) {
+ out[ i ] = idx[ i ];
+ }
+ return out;
+}
+
+/**
+* Returns the next Cartesian index (column-major).
+*
+* @private
+* @param {NonNegativeInteger} ndims - number of dimensions
+* @param {NonNegativeIntegerArray} shape - array shape
+* @param {NonNegativeIntegerArray} idx - current dimension indices
+* @param {NonNegativeInteger} dim - index of the dimension from which to start incrementing (inclusive)
+* @param {(Array|TypedArray|Object)} out - output array
+* @returns {(Array|TypedArray|Object)} output array
+*/
+function columnmajor( ndims, shape, idx, dim, out ) {
+ var i;
+ var j;
+
+ // Set dimension indices which are skipped...
+ for ( i = 0; i < dim; i++ ) {
+ out[ i ] = idx[ i ];
+ }
+ // Search for the first dimension in which we don't have to "carry the one"...
+ for ( i = dim; i < ndims; i++ ) {
+ j = ( idx[ i ] + 1 ) % shape[ i ];
+ out[ i ] = j;
+
+ // If the current index value is greater than zero, we can continue iterating within the current sub-array...
+ if ( j > 0 ) {
+ break;
+ }
+ }
+ // Set dimension indices which did not get updated...
+ for ( i += 1; i < ndims; i++ ) {
+ out[ i ] = idx[ i ];
+ }
+ return out;
+}
+
+
+// MAIN //
+
+/**
+* Returns the next Cartesian index (i.e., set of subscripts/dimension indices) and assigns results to a provided output array.
+*
+* ## Notes
+*
+* - The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
+*
+* @param {NonNegativeIntegerArray} shape - array shape
+* @param {string} order - index iteration order
+* @param {NonNegativeIntegerArray} idx - current dimension indices
+* @param {integer} dim - index of the dimension from which to start incrementing (inclusive)
+* @param {(Array|TypedArray|Object)} out - output array
+* @returns {(Array|TypedArray|Object|null)} output array (or null)
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], 0, [ 0 ] );
+* // returns [ 3 ]
+*
+* @example
+* var shape = [ 2, 2, 2 ];
+*
+* var out = [ 0, 0, 0 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1, out );
+* // returns [ 0, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
+* // returns [ 0, 1, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
+* // returns [ 1, 0, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
+* // returns [ 1, 0, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
+* // returns [ 1, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1, out );
+* // returns [ 1, 1, 1 ]
+*
+* @example
+* var shape = [];
+* var idx = nextCartesianIndex( shape, 'row-major', [], 0, [] );
+* // returns null
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], -10, [ 0 ] );
+* // returns null
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'column-major', [ 2 ], 10, [ 0 ] );
+* // returns null
+*/
+function nextCartesianIndex( shape, order, idx, dim, out ) {
+ var ndims = shape.length;
+ if ( ndims === 0 ) {
+ return null;
+ }
+ if ( dim < 0 ) {
+ dim += ndims;
+ if ( dim < 0 ) {
+ // Out-of-bounds:
+ return null;
+ }
+ } else if ( dim >= ndims ) {
+ // Out-of-bounds:
+ return null;
+ }
+ if ( order === ROW_MAJOR ) {
+ return rowmajor( ndims, shape, idx, dim, out );
+ }
+ // order === 'column-major'
+ return columnmajor( ndims, shape, idx, dim, out );
+}
+
+
+// EXPORTS //
+
+module.exports = nextCartesianIndex;
diff --git a/base/next-cartesian-index/lib/index.js b/base/next-cartesian-index/lib/index.js
new file mode 100644
index 00000000..b9492b40
--- /dev/null
+++ b/base/next-cartesian-index/lib/index.js
@@ -0,0 +1,64 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+/**
+* Return the next Cartesian index (i.e., set of subscripts/dimension indices).
+*
+* @module @stdlib/ndarray/base/next-cartesian-index
+*
+* @example
+* var nextCartesianIndex = require( '@stdlib/ndarray/base/next-cartesian-index' );
+*
+* var shape = [ 2, 2, 2 ];
+*
+* var idx = nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1 );
+* // returns [ 0, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 0, 1, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 0, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 0, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 1, 1 ]
+*/
+
+// MODULES //
+
+var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
+var main = require( './main.js' );
+var assign = require( './assign.js' );
+
+
+// MAIN //
+
+setReadOnly( main, 'assign', assign );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/base/next-cartesian-index/lib/main.js b/base/next-cartesian-index/lib/main.js
new file mode 100644
index 00000000..74c3c64f
--- /dev/null
+++ b/base/next-cartesian-index/lib/main.js
@@ -0,0 +1,90 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var zeros = require( '@stdlib/array/base/zeros' );
+var assign = require( './assign.js' );
+
+
+// MAIN //
+
+/**
+* Returns the next Cartesian index (i.e., set of subscripts/dimension indices).
+*
+* ## Notes
+*
+* - The function does not check whether the current index is the "last" index. Instead, if the function is provided dimension indices corresponding to the last element, the function will cycle back to the "first" index.
+*
+* @param {NonNegativeIntegerArray} shape - array shape
+* @param {string} order - index iteration order
+* @param {NonNegativeIntegerArray} idx - current dimension indices
+* @param {integer} dim - index of the dimension from which to start incrementing (inclusive)
+* @returns {(NonNegativeIntegerArray|null)} updated dimension indices
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], 0 );
+* // returns [ 3 ]
+*
+* @example
+* var shape = [ 2, 2, 2 ];
+*
+* var idx = nextCartesianIndex( shape, 'row-major', [ 0, 0, 1 ], -1 );
+* // returns [ 0, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 0, 1, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 0, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 0, 1 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 1, 0 ]
+*
+* idx = nextCartesianIndex( shape, 'row-major', idx, -1 );
+* // returns [ 1, 1, 1 ]
+*
+* @example
+* var shape = [];
+* var idx = nextCartesianIndex( shape, 'row-major', [], 0 );
+* // returns null
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'row-major', [ 2 ], -10 );
+* // returns null
+*
+* @example
+* var shape = [ 12 ];
+* var idx = nextCartesianIndex( shape, 'column-major', [ 2 ], 10 );
+* // returns null
+*/
+function nextCartesianIndex( shape, order, idx, dim ) {
+ return assign( shape, order, idx, dim, zeros( shape.length ) );
+}
+
+
+// EXPORTS //
+
+module.exports = nextCartesianIndex;
diff --git a/base/next-cartesian-index/package.json b/base/next-cartesian-index/package.json
new file mode 100644
index 00000000..e253d7fa
--- /dev/null
+++ b/base/next-cartesian-index/package.json
@@ -0,0 +1,72 @@
+{
+ "name": "@stdlib/ndarray/base/next-cartesian-index",
+ "version": "0.0.0",
+ "description": "Return the next Cartesian index (i.e., set of subscripts/dimension indices).",
+ "license": "Apache-2.0",
+ "author": {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ },
+ "contributors": [
+ {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ }
+ ],
+ "main": "./lib",
+ "directories": {
+ "benchmark": "./benchmark",
+ "doc": "./docs",
+ "example": "./examples",
+ "lib": "./lib",
+ "test": "./test"
+ },
+ "types": "./docs/types",
+ "scripts": {},
+ "homepage": "https://github.com/stdlib-js/stdlib",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/stdlib-js/stdlib.git"
+ },
+ "bugs": {
+ "url": "https://github.com/stdlib-js/stdlib/issues"
+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "engines": {
+ "node": ">=0.10.0",
+ "npm": ">2.7.0"
+ },
+ "os": [
+ "aix",
+ "darwin",
+ "freebsd",
+ "linux",
+ "macos",
+ "openbsd",
+ "sunos",
+ "win32",
+ "windows"
+ ],
+ "keywords": [
+ "stdlib",
+ "stdtypes",
+ "types",
+ "base",
+ "ndarray",
+ "multidimensional",
+ "array",
+ "utilities",
+ "utility",
+ "utils",
+ "util",
+ "cartesian",
+ "subscripts",
+ "dimension",
+ "index",
+ "indices",
+ "indexing",
+ "iteration"
+ ],
+ "__stdlib__": {}
+}
diff --git a/base/next-cartesian-index/test/test.js b/base/next-cartesian-index/test/test.js
new file mode 100644
index 00000000..9d590918
--- /dev/null
+++ b/base/next-cartesian-index/test/test.js
@@ -0,0 +1,884 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2023 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var tape = require( 'tape' );
+var numel = require( './../../../base/numel' );
+var nextCartesianIndex = require( './../lib' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof nextCartesianIndex, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=0, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+
+ shape = [];
+ actual = nextCartesianIndex( shape, 'row-major', [], -1 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=0, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+
+ shape = [];
+ actual = nextCartesianIndex( shape, 'column-major', [], 0 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=1, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 5 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, -1 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 1 ],
+ [ 2 ],
+ [ 3 ],
+ [ 4 ],
+ [ 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=1, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 5 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, 0 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 1 ],
+ [ 2 ],
+ [ 3 ],
+ [ 4 ],
+ [ 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=1, row-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+
+ shape = [ 5 ];
+ actual = nextCartesianIndex( shape, 'row-major', [ 0 ], -10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ shape = [ 5 ];
+ actual = nextCartesianIndex( shape, 'row-major', [ 0 ], 10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=1, column-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+
+ shape = [ 5 ];
+ actual = nextCartesianIndex( shape, 'column-major', [ 0 ], -10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ shape = [ 5 ];
+ actual = nextCartesianIndex( shape, 'column-major', [ 0 ], 10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=2, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 2, 2 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, -1 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 0, 1 ],
+ [ 1, 0 ],
+ [ 1, 1 ],
+ [ 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=2, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 2, 2 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, 0 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 1, 0 ],
+ [ 0, 1 ],
+ [ 1, 1 ],
+ [ 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=2, row-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+
+ shape = [ 2, 2 ];
+ actual = nextCartesianIndex( shape, 'row-major', [ 0, 0 ], -10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ shape = [ 2, 2 ];
+ actual = nextCartesianIndex( shape, 'row-major', [ 0, 0 ], 10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=2, column-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+
+ shape = [ 2, 2 ];
+ actual = nextCartesianIndex( shape, 'column-major', [ 0, 0 ], -10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+
+ shape = [ 2, 2 ];
+ actual = nextCartesianIndex( shape, 'column-major', [ 0, 0 ], 10 );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=3, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, -1 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 0, 0, 1 ],
+ [ 0, 1, 0 ],
+ [ 0, 1, 1 ],
+ [ 0, 2, 0 ],
+ [ 0, 2, 1 ],
+ [ 1, 0, 0 ],
+ [ 1, 0, 1 ],
+ [ 1, 1, 0 ],
+ [ 1, 1, 1 ],
+ [ 1, 2, 0 ],
+ [ 1, 2, 1 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns the next Cartesian index (ndims=3, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, 0 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 1, 0, 0 ],
+ [ 0, 1, 0 ],
+ [ 1, 1, 0 ],
+ [ 0, 2, 0 ],
+ [ 1, 2, 0 ],
+ [ 0, 0, 1 ],
+ [ 1, 0, 1 ],
+ [ 0, 1, 1 ],
+ [ 1, 1, 1 ],
+ [ 0, 2, 1 ],
+ [ 1, 2, 1 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying the starting dimension index (ndims=3, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape.slice( 0, 2 ) ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, -2 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 0, 1, 0 ],
+ [ 0, 2, 0 ],
+ [ 1, 0, 0 ],
+ [ 1, 1, 0 ],
+ [ 1, 2, 0 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape.slice( 0, 1 ) ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, 0 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 1, 0, 0 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying the starting dimension index (ndims=3, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape.slice( 1 ) ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, 1 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 0, 1, 0 ],
+ [ 0, 2, 0 ],
+ [ 0, 0, 1 ],
+ [ 0, 1, 1 ],
+ [ 0, 2, 1 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape.slice( 2 ) ); i++ ) {
+ out = nextCartesianIndex( shape, order, idx, 2 );
+ t.notEqual( out, idx, 'returns expected value' );
+ actual.push( out );
+ idx = out;
+ }
+ expected = [
+ [ 0, 0, 1 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=0, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var out;
+
+ shape = [];
+ out = [];
+ actual = nextCartesianIndex.assign( shape, 'row-major', [], -1, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [], 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=0, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var out;
+
+ shape = [];
+ out = [];
+ actual = nextCartesianIndex.assign( shape, 'column-major', [], -1, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [], 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=1, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 5 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = [ 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, -1, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1 ],
+ [ 2 ],
+ [ 3 ],
+ [ 4 ],
+ [ 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=1, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 5 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = [ 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, 0, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1 ],
+ [ 2 ],
+ [ 3 ],
+ [ 4 ],
+ [ 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=1, row-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var out;
+
+ shape = [ 5 ];
+ out = [ 0 ];
+ actual = nextCartesianIndex.assign( shape, 'row-major', [ 0 ], -10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0 ], 'returns expected value' );
+
+ shape = [ 5 ];
+ out = [ 0 ];
+ actual = nextCartesianIndex.assign( shape, 'row-major', [ 0 ], 10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0 ], 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=1, column-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var out;
+
+ shape = [ 5 ];
+ out = [ 0 ];
+ actual = nextCartesianIndex.assign( shape, 'column-major', [ 0 ], -10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0 ], 'returns expected value' );
+
+ shape = [ 5 ];
+ out = [ 0 ];
+ actual = nextCartesianIndex.assign( shape, 'column-major', [ 0 ], 10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0 ], 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=2, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 2, 2 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = [ 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, -1, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 0, 1 ],
+ [ 1, 0 ],
+ [ 1, 1 ],
+ [ 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=2, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 2, 2 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = [ 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, 0, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1, 0 ],
+ [ 0, 1 ],
+ [ 1, 1 ],
+ [ 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=2, row-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var out;
+
+ shape = [ 2, 2 ];
+ out = [ 0, 0 ];
+ actual = nextCartesianIndex.assign( shape, 'row-major', [ 0, 0 ], -10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0, 0 ], 'returns expected value' );
+
+ shape = [ 2, 2 ];
+ out = [ 0, 0 ];
+ actual = nextCartesianIndex.assign( shape, 'row-major', [ 0, 0 ], 10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0, 0 ], 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=2, column-major, out-of-bounds)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var out;
+
+ shape = [ 2, 2 ];
+ out = [ 0, 0 ];
+ actual = nextCartesianIndex.assign( shape, 'column-major', [ 0, 0 ], -10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0, 0 ], 'returns expected value' );
+
+ shape = [ 2, 2 ];
+ out = [ 0, 0 ];
+ actual = nextCartesianIndex.assign( shape, 'column-major', [ 0, 0 ], 10, out );
+ expected = null;
+
+ t.strictEqual( actual, expected, 'returns expected value' );
+ t.deepEqual( out, [ 0, 0 ], 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=3, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = [ 0, 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, -1, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 0, 0, 1 ],
+ [ 0, 1, 0 ],
+ [ 0, 1, 1 ],
+ [ 0, 2, 0 ],
+ [ 0, 2, 1 ],
+ [ 1, 0, 0 ],
+ [ 1, 0, 1 ],
+ [ 1, 1, 0 ],
+ [ 1, 1, 1 ],
+ [ 1, 2, 0 ],
+ [ 1, 2, 1 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'attached to the main function is an `assign` method which assigns results to an output array (ndims=3, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 0, 0, 0 ];
+ for ( i = 0; i < numel( shape ); i++ ) {
+ out = [ 0, 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, 0, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1, 0, 0 ],
+ [ 0, 1, 0 ],
+ [ 1, 1, 0 ],
+ [ 0, 2, 0 ],
+ [ 1, 2, 0 ],
+ [ 0, 0, 1 ],
+ [ 1, 0, 1 ],
+ [ 0, 1, 1 ],
+ [ 1, 1, 1 ],
+ [ 0, 2, 1 ],
+ [ 1, 2, 1 ],
+ [ 0, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying the starting dimension index (ndims=3, row-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'row-major';
+
+ actual = [];
+ idx = [ 0, 0, 1 ];
+ for ( i = 0; i < numel( shape.slice( 0, 2 ) ); i++ ) {
+ out = [ 0, 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, -2, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 0, 1, 1 ],
+ [ 0, 2, 1 ],
+ [ 1, 0, 1 ],
+ [ 1, 1, 1 ],
+ [ 1, 2, 1 ],
+ [ 0, 0, 1 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ actual = [];
+ idx = [ 0, 0, 1 ];
+ for ( i = 0; i < numel( shape.slice( 0, 1 ) ); i++ ) {
+ out = [ 0, 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, 0, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1, 0, 1 ],
+ [ 0, 0, 1 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports specifying the starting dimension index (ndims=3, column-major)', function test( t ) {
+ var expected;
+ var actual;
+ var shape;
+ var order;
+ var idx;
+ var out;
+ var tmp;
+ var i;
+
+ shape = [ 2, 3, 2 ];
+ order = 'column-major';
+
+ actual = [];
+ idx = [ 1, 0, 0 ];
+ for ( i = 0; i < numel( shape.slice( 1 ) ); i++ ) {
+ out = [ 0, 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, 1, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1, 1, 0 ],
+ [ 1, 2, 0 ],
+ [ 1, 0, 1 ],
+ [ 1, 1, 1 ],
+ [ 1, 2, 1 ],
+ [ 1, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+
+ actual = [];
+ idx = [ 1, 0, 0 ];
+ for ( i = 0; i < numel( shape.slice( 2 ) ); i++ ) {
+ out = [ 0, 0, 0 ];
+ tmp = nextCartesianIndex.assign( shape, order, idx, 2, out );
+ t.strictEqual( tmp, out, 'returns expected value' );
+ actual.push( out.slice() );
+ idx = tmp;
+ }
+ expected = [
+ [ 1, 0, 1 ],
+ [ 1, 0, 0 ] // cycles back to beginning
+ ];
+
+ t.deepEqual( actual, expected, 'returns expected value' );
+ t.end();
+});
diff --git a/dist/index.js b/dist/index.js
index cfd0a13c..00e00b7c 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1,4 +1,4 @@
-"use strict";var D=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var Wi=D(function(nC,Qi){"use strict";function n3(r){var e,a,i,v;for(e=r.length,a=[],v=0;v=0;v--)a[v]=i,i*=r[v];return a}function u3(r){var e,a,i;for(e=[],a=1,i=0;i=0;v--)e[v]=i,i*=r[v];return e}function l3(r,e){var a,i;for(a=1,i=0;iv&&(i=!1),i||e)v=t;else return 0;return i&&e?3:i?1:2}st.exports=h3});var Ne=D(function(yC,nt){"use strict";var q3=ot();nt.exports=q3});var ft=D(function(pC,ut){"use strict";function g3(r){var e,a,i;if(e=r.length,e===0)return 0;for(a=1,i=0;i0?t+=o*(r[s]-1):o<0&&(v+=o*(r[s]-1))}return[v,t]}Lt.exports=Y3});var Vt=D(function(AC,Pt){"use strict";function K3(r,e,a,i){var v,t,o,s,u;for(v=r.length,t=a,o=a,u=0;u0?o+=s*(r[u]-1):s<0&&(t+=s*(r[u]-1))}return i[0]=t,i[1]=o,i}Pt.exports=K3});var ne=D(function(RC,Bt){"use strict";var G3=require("@stdlib/utils/define-nonenumerable-read-only-property"),Mt=zt(),Z3=Vt();G3(Mt,"assign",Z3);Bt.exports=Mt});var Ft=D(function(NC,Ut){"use strict";var J3=ne();function X3(r,e,a,i){var v=J3(e,a,i);return v[0]>=0&&v[1]=0;o--)t=r%a[o],r-=t,r/=a[o],v+=t*e[o];return this._accessors?this._buffer.get(v):this._buffer[v]}sv.exports=nh});var uv=D(function(KC,nv){"use strict";function uh(r,e){var a,i,v,t,o,s;if(v=this._ndims,v===0)return this._accessors?this._buffer.set(r,this._offset):this._buffer[this._offset]=r,this;if(this._flags.ROW_MAJOR_CONTIGUOUS||this._flags.COLUMN_MAJOR_CONTIGUOUS){if(this._iterationOrder===1)return this._accessors?this._buffer.set(e,this._offset+r):this._buffer[this._offset+r]=e,this;if(this._iterationOrder===-1)return this._accessors?this._buffer.set(e,this._offset-r):this._buffer[this._offset-r]=e,this}if(i=this._shape,a=this._strides,t=this._offset,this._order==="column-major"){for(s=0;s=0;s--)o=r%i[s],r-=o,r/=i[s],t+=o*a[s];return this._accessors?this._buffer.set(e,t):this._buffer[t]=e,this}nv.exports=uh});var dv=D(function(GC,fv){"use strict";function fh(){var r,e;for(r=this._offset,e=0;e=0;o--)t=this.iget(this._length-1-o),r+=Fa(t)+", "+Ya(t),o>0&&(r+=", ");else for(o=2;o>=0;o--)r+=this.iget(this._length-1-o),o>0&&(r+=", ")}if(a=mh[this.dtype],i+=ph(a,"{{data}}",r),i+=", ",e===0?i+="[]":i+="[ "+this._shape.join(", ")+" ]",i+=", ",i+="[ ",e===0)i+="0";else for(o=0;oe?e:r}Vv.exports=dq});var Za=D(function(nL,Bv){"use strict";var lq=Mv();Bv.exports=lq});var Fv=D(function(uL,Uv){"use strict";function cq(r,e){var a=e+1;return r<0?(r+=a,r<0&&(r%=a,r!==0&&(r+=a)),r):(r>e&&(r-=a,r>e&&(r%=a)),r)}Uv.exports=cq});var Ja=D(function(fL,Yv){"use strict";var yq=Fv();Yv.exports=yq});var Gv=D(function(dL,Kv){"use strict";var pq=Za(),mq=Ja(),xq=require("@stdlib/string/format");function hq(r,e,a){if(a==="clamp")return pq(r,e);if(a==="wrap")return mq(r,e);if(r<0||r>e)throw new RangeError(xq("invalid argument. Index must be on the interval: [0, %d]. Value: `%d`.",e,r));return r}Kv.exports=hq});var Se=D(function(lL,Zv){"use strict";var qq=Gv();Zv.exports=qq});var Qv=D(function(cL,Xv){"use strict";var gq=require("@stdlib/assert/is-integer").isPrimitive,bq=Se(),Sq=$r(),wq=require("@stdlib/string/format"),Jv=Sq.prototype.iget;function jq(r){if(this._ndims>0){if(!gq(r))throw new TypeError(wq("invalid argument. Index must be an integer. Value: `%s`.",r));return r=bq(r,this._length-1,this._mode),Jv.call(this,r)}return Jv.call(this)}Xv.exports=jq});var $v=D(function(yL,Hv){"use strict";var _q=require("@stdlib/assert/is-integer").isPrimitive,Eq=Se(),Oq=$r(),Tq=require("@stdlib/string/format"),Wv=Oq.prototype.iset;function Iq(r,e){if(this._flags.READONLY)throw new Error("invalid invocation. Cannot write to a read-only array.");if(this._ndims>0){if(!_q(r))throw new TypeError(Tq("invalid argument. Index must be an integer. Value: `%s`.",r));r=Eq(r,this._length-1,this._mode),Wv.call(this,r,e)}else Wv.call(this,r);return this}Hv.exports=Iq});var as=D(function(pL,es){"use strict";var kq=require("@stdlib/assert/is-integer").isPrimitive,Aq=Se(),rs=require("@stdlib/string/format");function Rq(){var r,e,a,i;if(arguments.length!==this._ndims)throw new RangeError(rs("invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.",this._ndims,arguments.length));for(r=this._offset,a=this._submode.length,i=0;i0))throw new TypeError(re("invalid argument. Third argument must be an array-like object containing nonnegative integers. Value: `%s`.",a));if(s=a.length,s>hs)throw new RangeError(re("invalid argument. Number of dimensions must not exceed %u due to stack limits. Value: `%u`.",hs,s));if(!Zq(i))throw new TypeError(re("invalid argument. Fourth argument must be an array-like object containing integers. Value: `%s`.",i));if(s>0){if(i.length!==s)throw new RangeError(re("invalid argument. Fourth argument length must match the number of dimensions. Expected number of dimensions: `%u`. Strides length: `%u`.",s,i.length))}else{if(i.length!==1)throw new RangeError("invalid argument. Fourth argument length must be equal to 1 when creating a zero-dimensional ndarray.");if(i[0]!==0)throw new RangeError(re("invalid argument. Fourth argument must contain a single element equal to 0. Value: `%d`.",i[0]))}if(!Gq(v))throw new TypeError(re("invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.",v));if(!Jq(t))throw new TypeError(re("invalid argument. Sixth argument must be a supported order. Value: `%s`.",t));if(s>0&&!Qq(e.length,a,i,v)&&Wq(a)>0)throw new Error("invalid arguments. Input buffer is incompatible with the specified meta data. Ensure that the offset is valid with regard to the strides array and that the buffer has enough elements to satisfy the desired array shape.");if(u={},u.mode=vg,u.readonly=sg,arguments.length>6&&(f=tg(u,o),f))throw f;return this._mode=u.mode,u.submode===void 0&&(u.submode=[this._mode]),this._submode=u.submode,n=xs(a,s),d=xs(i,s||1),qs.call(this,r,e,n,d,v,t),this._flags.READONLY=u.readonly,this}$q(ee,qs);Pe(ee,"name","ndarray");Pe(ee.prototype,"get",ag);Pe(ee.prototype,"iget",rg);Pe(ee.prototype,"set",ig);Pe(ee.prototype,"iset",eg);gs.exports=ee});var ae=D(function(SL,Ss){"use strict";var og=bs();Ss.exports=og});var ws=D(function(wL,ng){ng.exports=["none","equiv","safe","same-kind","unsafe"]});var _s=D(function(jL,js){"use strict";var ug=ws();function fg(){return ug.slice()}js.exports=fg});var Os=D(function(_L,Es){"use strict";function dg(){return{none:0,equiv:1,safe:2,"same-kind":3,unsafe:4}}Es.exports=dg});var Qa=D(function(EL,Is){"use strict";var lg=require("@stdlib/utils/define-nonenumerable-read-only-property"),Ts=_s(),cg=Os();lg(Ts,"enum",cg);Is.exports=Ts});var Rs=D(function(OL,As){"use strict";var yg=Qa(),ks=yg(),pg=ks.length;function mg(r){var e;for(e=0;e0}Js.exports=Mg});var Me=D(function(VL,Qs){"use strict";var Bg=Xs();Qs.exports=Bg});var Ws=D(function(ML,Ug){Ug.exports={float64:{float64:1,float32:1,int32:0,int16:0,int8:0,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:0,binary:0,generic:1},float32:{float64:1,float32:1,int32:0,int16:0,int8:0,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:1,binary:0,generic:1},int32:{float64:1,float32:0,int32:1,int16:1,int8:1,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:0,binary:0,generic:1},int16:{float64:1,float32:1,int32:1,int16:1,int8:1,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:1,binary:0,generic:1},int8:{float64:1,float32:1,int32:1,int16:1,int8:1,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:1,binary:0,generic:1},uint32:{float64:1,float32:0,int32:0,int16:0,int8:0,uint32:1,uint16:1,uint8:1,uint8c:1,complex128:1,complex64:0,binary:0,generic:1},uint16:{float64:1,float32:1,int32:1,int16:0,int8:0,uint32:1,uint16:1,uint8:1,uint8c:1,complex128:1,complex64:1,binary:0,generic:1},uint8:{float64:1,float32:1,int32:1,int16:1,int8:0,uint32:1,uint16:1,uint8:1,uint8c:1,complex128:1,complex64:1,binary:0,generic:1},uint8c:{float64:1,float32:1,int32:1,int16:1,int8:0,uint32:1,uint16:1,uint8:1,uint8c:1,complex128:1,complex64:1,binary:0,generic:1},complex128:{float64:0,float32:0,int32:0,int16:0,int8:0,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:1,binary:0,generic:0},complex64:{float64:0,float32:0,int32:0,int16:0,int8:0,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:1,complex64:1,binary:0,generic:0},generic:{float64:0,float32:0,int32:0,int16:0,int8:0,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:0,complex64:0,binary:0,generic:1},binary:{float64:0,float32:0,int32:0,int16:0,int8:0,uint32:0,uint16:0,uint8:0,uint8c:0,complex128:0,complex64:0,binary:1,generic:0}}});var ro=D(function(BL,$s){"use strict";var Hs=require("@stdlib/utils/keys"),Fg=require("@stdlib/assert/has-own-property"),Yg=ie(),na=Ws(),oa;function Kg(){var r,e,a,i,v,t,o,s,u;for(a={},r=Hs(na),e=r.length,u=0;u0}ao.exports=Wg});var ua=D(function(YL,to){"use strict";var Hg=io();to.exports=Hg});var so=D(function(KL,vo){"use strict";var $g=Me(),r4=ua();function e4(r,e,a){return a==="unsafe"||r===e?!0:a==="none"||a==="equiv"?!1:a==="safe"?$g(r,e):r4(r,e)}vo.exports=e4});var ri=D(function(GL,oo){"use strict";var a4=so();oo.exports=a4});var uo=D(function(ZL,no){"use strict";var i4=require("@stdlib/buffer/ctor"),t4=require("@stdlib/array/float64"),v4=require("@stdlib/array/float32"),s4=require("@stdlib/array/int16"),o4=require("@stdlib/array/int32"),n4=require("@stdlib/array/int8"),u4=require("@stdlib/array/uint16"),f4=require("@stdlib/array/uint32"),d4=require("@stdlib/array/uint8"),l4=require("@stdlib/array/uint8c"),c4=require("@stdlib/array/complex64"),y4=require("@stdlib/array/complex128"),p4={binary:i4,float64:t4,float32:v4,generic:Array,int16:s4,int32:o4,int8:n4,uint16:u4,uint32:f4,uint8:d4,uint8c:l4,complex64:c4,complex128:y4};no.exports=p4});var lo=D(function(JL,fo){"use strict";var m4=uo();function x4(r){return m4[r]||null}fo.exports=x4});var Be=D(function(XL,co){"use strict";var h4=lo();co.exports=h4});var po=D(function(QL,yo){"use strict";function q4(r){var e;for(e=0;e=0&&r.length=Nb(e)}Xo.exports=Db});var Ho=D(function(cz,Wo){"use strict";var Cb=Qo();Wo.exports=Cb});var en=D(function(yz,rn){"use strict";var $o=require("@stdlib/math/base/special/abs");function Lb(r){var e,a,i,v;if(e=r.length,e===0)return!1;for(a=$o(r[0]),v=1;va)return!1;a=i}return!0}zn.exports=w6});var vi=D(function(zz,Vn){"use strict";var j6=Pn();Vn.exports=j6});var Bn=D(function(Pz,Mn){"use strict";var _6=Ue(),E6=te(),O6=vi();function T6(r,e,a){return E6(e)!==0&&O6(e)&&_6(r,e,a)}Mn.exports=T6});var Fn=D(function(Vz,Un){"use strict";var I6=Bn();Un.exports=I6});var Kn=D(function(Mz,Yn){"use strict";var k6=require("@stdlib/array/base/assert/contains").factory,A6=Fr(),R6=k6(A6("signed_integer"));Yn.exports=R6});var ya=D(function(Bz,Gn){"use strict";var N6=Kn();Gn.exports=N6});var Jn=D(function(Uz,Zn){"use strict";var D6=require("@stdlib/array/base/assert/contains").factory,C6=Fr(),L6=D6(C6("unsigned_integer"));Zn.exports=L6});var pa=D(function(Fz,Xn){"use strict";var z6=Jn();Xn.exports=z6});var Wn=D(function(Yz,Qn){"use strict";var Pr=require("@stdlib/utils/define-read-only-property"),zr={};Pr(zr,"isAllowedDataTypeCast",ri());Pr(zr,"isBufferLengthCompatible",Ua());Pr(zr,"isBufferLengthCompatibleShape",Ho());Pr(zr,"isCastingMode",Wa());Pr(zr,"isColumnMajor",ei());Pr(zr,"isColumnMajorContiguous",fn());Pr(zr,"isComplexFloatingPointDataType",Fe());Pr(zr,"isContiguous",xn());Pr(zr,"isDataType",De());Pr(zr,"isFloatingPointDataType",Ye());Pr(zr,"isIndexMode",ze());Pr(zr,"isIntegerDataType",ai());Pr(zr,"isNumericDataType",ii());Pr(zr,"isOrder",xe());Pr(zr,"isReadOnly",je());Pr(zr,"isRealDataType",ca());Pr(zr,"isRealFloatingPointDataType",ti());Pr(zr,"isRowMajor",vi());Pr(zr,"isRowMajorContiguous",Fn());Pr(zr,"isSafeDataTypeCast",Me());Pr(zr,"isSameKindDataTypeCast",ua());Pr(zr,"isSignedIntegerDataType",ya());Pr(zr,"isSingleSegmentCompatible",Ue());Pr(zr,"isUnsignedIntegerDataType",pa());Qn.exports=zr});var $n=D(function(Kz,Hn){"use strict";function P6(r,e){var a,i,v,t,o,s,u,f,n,d;for(v=1,t=1,d=1;d=0&&(n=r[o],i=n<0?-n:n,!(i<=a));)r[o+1]=n,e[s+1]=e[s],o-=1,s-=1;r[o+1]=u,e[s+1]=f,v+=1,t+=1}}Hn.exports=P6});var au=D(function(Gz,eu){"use strict";var V6=require("@stdlib/array/base/zero-to"),M6=require("@stdlib/array/base/copy-indexed"),ma=require("@stdlib/array/base/take"),B6=require("@stdlib/array/base/filled"),si=Ne(),U6=$n(),ru=3;function F6(r,e,a,i){var v,t,o,s,u,f,n,d,y,x;if(v=V6(r.length),f=si(e),n=si(a),d=si(i),t=B6([],4),t[f].push(e),t[n].push(a),t[d].push(i),o=t[0].length,o===ru)u=e;else if(o===ru-1){for(y=1;y<4;y++)if(t[y].length){u=t[y][0];break}}else{for(x=0,y=1;y<4;y++)s=t[y].length,s>=o&&(o=s,x=y);u=t[x][0]}return u=M6(u),U6(u,v),r=ma(r,v),e=e===u?u:ma(e,v),a=a===u?u:ma(a,v),i=i===u?u:ma(i,v),{sh:r,sx:e,sy:a,sz:i}}eu.exports=F6});var tu=D(function(Zz,iu){"use strict";var Y6=au();iu.exports=Y6});var su=D(function(Jz,vu){"use strict";var K6={BLOCK_SIZE_IN_BYTES:64,BLOCK_SIZE_IN_ELEMENTS:8};vu.exports=K6});var nu=D(function(Xz,ou){"use strict";var oi=ue(),xa=su();function G6(r,e,a){var i,v,t;return i=oi(r),v=oi(e),t=oi(a),i===null||v===null||t===null?xa.BLOCK_SIZE_IN_ELEMENTS:i>v&&i>t?xa.BLOCK_SIZE_IN_BYTES/i|0:v>t?xa.BLOCK_SIZE_IN_BYTES/v|0:xa.BLOCK_SIZE_IN_BYTES/t|0}ou.exports=G6});var fu=D(function(Qz,uu){"use strict";var Z6=nu();uu.exports=Z6});var cu=D(function(Wz,lu){"use strict";var J6=require("@stdlib/string/format"),ha=require("@stdlib/math/base/special/trunc"),du=require("@stdlib/math/base/special/abs");function X6(r,e,a,i,v,t){var o,s,u,f,n,d;for(o=r.length,s=1,d=0;d=s&&(v=s-1);else if(t==="wrap")v<0?(v+=s,v<0&&(v%=s,v!==0&&(v+=s))):v>=s&&(v-=s,v>=s&&(v%=s));else if(v<0||v>=s)throw new RangeError(J6("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,v));if(u=0,i==="column-major"){for(d=o-1;d>=0;d--)n=e[d],n<0?(f=ha(v/n),v-=f*n,f+=r[d]-1):(f=ha(v/n),v-=f*n),u+=f*du(n);return u}for(d=0;d=0;f--)if(n=s-o+f,!(n<0)){if(u=v[n],i=e[f],i!==0&&if&&(f=e[n]);for(n=0;n=0;){for(t=e[0]-f+n,t>=0?i=v[t]:i=1,d=1;d=0?s=r[d][o]:s=1,i===1){i=s;continue}if(!(s===1||i===s))return null}a[n]=i,n-=1}return a}ju.exports=u5});var Ou=D(function(t9,Eu){"use strict";var f5=_u();Eu.exports=f5});var Iu=D(function(v9,Tu){"use strict";var d5=Ve(),l5=fa();function c5(r){var e=l5(r);return e?d5(e):null}Tu.exports=c5});var Au=D(function(s9,ku){"use strict";var y5=Iu();ku.exports=y5});var Nu=D(function(o9,Ru){"use strict";function p5(){return{binary:"r",bool:"x",complex64:"c",complex128:"z",float16:"h",bfloat16:"e",float32:"f",float64:"d",float128:"g",generic:"o",int8:"s",int16:"k",int32:"i",int64:"l",int128:"m",int256:"n",uint8:"b",uint8c:"a",uint16:"t",uint32:"u",uint64:"v",uint128:"w",uint256:"y"}}Ru.exports=p5});var Lu=D(function(n9,Cu){"use strict";var m5=ie(),Du=Nu(),ni;function x5(r){return arguments.length===0?Du():(ni===void 0&&(ni=Du()),ni[m5(r)]||null)}Cu.exports=x5});var ui=D(function(u9,zu){"use strict";var h5=Lu();zu.exports=h5});var Bu=D(function(f9,Mu){"use strict";var Pu=require("@stdlib/utils/object-inverse"),Vu=ui(),fi;function q5(r){return arguments.length===0?Pu(Vu()):(fi===void 0&&(fi=Pu(Vu())),fi[r]||null)}Mu.exports=q5});var Fu=D(function(d9,Uu){"use strict";var g5=Bu();Uu.exports=g5});var Ku=D(function(l9,Yu){"use strict";function b5(){return{binary:"byte",bool:"boolean",complex64:"single-precision floating-point complex number",complex128:"double-precision floating-point complex number",float16:"half-precision floating-point number",bfloat16:"brain floating-point number",float32:"single-precision floating-point number",float64:"double-precision floating-point number",float128:"quadruple-precision floating-point number",generic:"generic array value",int8:"signed 8-bit integer",int16:"signed 16-bit integer",int32:"signed 32-bit integer",int64:"signed 64-bit integer",int128:"signed 128-bit integer",int256:"signed 256-bit integer",uint8:"unsigned 8-bit integer",uint8c:"unsigned 8-bit integer (clamped)",uint16:"unsigned 16-bit integer",uint32:"unsigned 32-bit integer",uint64:"unsigned 64-bit integer",uint128:"unsigned 128-bit integer",uint256:"unsigned 256-bit integer"}}Yu.exports=b5});var Ju=D(function(c9,Zu){"use strict";var S5=ie(),Gu=Ku(),di;function w5(r){return arguments.length===0?Gu():(di===void 0&&(di=Gu()),di[S5(r)]||null)}Zu.exports=w5});var Qu=D(function(y9,Xu){"use strict";var j5=Ju();Xu.exports=j5});var Hu=D(function(p9,Wu){"use strict";var _5=ta(),E5=Ve();function O5(r){var e=typeof r;return e==="number"?_5(r)?r:null:e==="string"?E5(r):null}Wu.exports=O5});var li=D(function(m9,$u){"use strict";var T5=Hu();$u.exports=T5});var rf=D(function(x9,I5){I5.exports={binary:null,bool:"bool",complex64:"stdlib_complex64_t",complex128:"stdlib_complex128_t",float16:null,bfloat16:null,float32:"float",float64:"double",float128:null,generic:null,int8:"int8_t",int16:"int16_t",int32:"int32_t",int64:"int64_t",int128:null,int256:null,uint8:"uint8_t",uint8c:null,uint16:"uint16_t",uint32:"uint32_t",uint64:"uint64_t",uint128:null,uint256:null}});var af=D(function(h9,ef){"use strict";var k5=ie(),A5=rf();function R5(r){return A5[k5(r)]||null}ef.exports=R5});var vf=D(function(q9,tf){"use strict";var N5=af();tf.exports=N5});var nf=D(function(g9,of){"use strict";var D5=require("@stdlib/assert/is-array-like-object"),sf=require("@stdlib/assert/is-nonnegative-integer").isPrimitive,C5=ie(),ci=require("@stdlib/string/format");function L5(r,e,a){var i,v,t,o,s,u,f,n;if(!D5(r))throw new TypeError(ci("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(!sf(e))throw new TypeError(ci("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",e));if(!sf(a))throw new TypeError(ci("invalid argument. Third argument must be a nonnegative integer. Value: `%s`.",a));if(i=r.length,i===0)throw new RangeError("invalid argument. First argument must contain at least one element.");if(s=e+a,i%s!==0)throw new RangeError("invalid arguments. Length of the first argument is incompatible with the second and third arguments.");for(v=[],t=[],u=2*s,n=2*e,f=0;f<=u;f++)f===0?f===n?t.push("() => ("):t.push("("):f===u?f===n?t.push(") => ()"):t.push(")"):f===n?t.push(") => ("):f%2===1?t.push(""):t.push(", ");for(f=0;f0?(t=B5(e),o=P5(e,a)):(t=1,o=[0]),r==="binary"?v=F5(t):v=U5(t,r),new M5(r,v,e,o,V5(e,o),a)}ff.exports=Y5});var cf=D(function(w9,lf){"use strict";var K5=df();lf.exports=K5});var pf=D(function(j9,yf){"use strict";var G5=Yr(),Z5=Gr(),J5=Lr(),X5=require("@stdlib/array/empty"),Q5=require("@stdlib/buffer/alloc-unsafe");function W5(r){var e,a,i,v,t,o,s;return s=r.dtype,t=r.shape,v=r.order,e=t.length,e>0?(a=J5(t),o=G5(t,v)):(a=1,o=[0]),s==="binary"?i=Q5(a):i=X5(a,s),new r.constructor(s,i,t,o,Z5(t,o),v)}yf.exports=W5});var xf=D(function(_9,mf){"use strict";var H5=pf();mf.exports=H5});var gf=D(function(E9,qf){"use strict";var $5=je(),hf=require("@stdlib/string/format");function r8(r,e){var a,i,v,t,o,s,u;if(t=r.shape,o=r.strides,v=r.order,s=t.length,a=[],i=[],e<0){if(e<-s-1)throw new RangeError(hf("invalid argument. Specified axis is out-of-bounds. Must be on the interval: [-%u-1, %u]. Value: `%d`.",s,s,e));e+=s+1}else if(e>s)throw new RangeError(hf("invalid argument. Specified axis is out-of-bounds. Must be on the interval: [-%u-1, %u]. Value: `%d`.",s,s,e));if(e===0)for(i.push(1),a.push(o[0]),u=0;u=u&&(v=u-1);else if(t==="wrap")v<0?(v+=u,v<0&&(v%=u,v!==0&&(v+=u))):v>=u&&(v-=u,v>=u&&(v%=u));else if(v<0||v>=u)throw new RangeError(f8("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",u,v));if(a===0){if(i==="column-major"){for(d=0;d=0;d--)n=v%r[d],v-=n,v/=r[d],o[d]=n;return o}if(i==="column-major"){for(d=s-1;d>=0;d--)n=e[d],n<0?(f=ga(v/n),v-=f*n,o[d]=r[d]-1+f):(f=ga(v/n),v-=f*n,o[d]=f);return o}for(d=0;d0&&(v+=e[t]*(r[t]-1))}return v}Rf.exports=m8});var Cf=D(function(D9,Df){"use strict";var x8=Nf();Df.exports=x8});var Pf=D(function(C9,zf){"use strict";var Lf=qa();function h8(r,e){var a,i,v;if(i=e.length,a=r.shape,a.length===i){for(v=0;v=0&&(n=r[o],i=n<0?-n:n,!(i<=a));)r[o+1]=n,e[s+1]=e[s],o-=1,s-=1;r[o+1]=u,e[s+1]=f,v+=1,t+=1}}ad.exports=L8});var vd=D(function(G9,td){"use strict";var z8=require("@stdlib/array/base/zero-to"),P8=require("@stdlib/array/base/copy-indexed"),V8=require("@stdlib/array/base/take"),M8=id();function B8(r,e){var a;return a=z8(r.length),e=P8(e),M8(e,a),r=V8(r,a),{sh:r,sx:e}}td.exports=B8});var Mr=D(function(Z9,sd){"use strict";var U8=vd();sd.exports=U8});var nd=D(function(J9,od){"use strict";var F8={BLOCK_SIZE_IN_BYTES:64,BLOCK_SIZE_IN_ELEMENTS:8};od.exports=F8});var dd=D(function(X9,fd){"use strict";var Y8=ue(),ud=nd();function K8(r){var e=Y8(r);return e===null?ud.BLOCK_SIZE_IN_ELEMENTS:ud.BLOCK_SIZE_IN_BYTES/e|0}fd.exports=K8});var Br=D(function(Q9,ld){"use strict";var G8=dd();ld.exports=G8});var yd=D(function(W9,cd){"use strict";var Z8=Mr(),J8=Br();function X8(r,e){var a,i,v,t,o,s,u,f,n,d,y,x,b,p,q,m,g;for(g=Z8(r.shape,r.strides),u=g.sh,d=g.sx,a=J8(r.dtype),y=r.offset,i=r.data,t=d[0],v=r.accessors[1],m=u[1];m>0;)for(m0;)for(q0;)for(E0;)for(h0;)for(S0;)for(w0;)for(O0;)for(l0;)for(_0;)for(I0;)for(R0;)for(A0;)for(T0;)for(k0;)for(V0;)for(z0;)for(N0;)for(L0;)for(C0;)for(I0;)for(F0;)for(U0;)for(B0;)for(M0;)for(P0;)for(V0;)for(z0;)for(G0;)for(J0;)for(K0;)for(Z0;)for(Y0;)for(F0;)for(U0;)for(B0;)for(H0;)for($0;)for(Q0;)for(W0;)for(X0;)for(G0;)for(J0;)for(K0;)for(Z0;)for(ar0;)for(vr0;)for(er0;)for(ir0;)for(rr0;)for(H0;)for($0;)for(Q0;)for(W0;)for(X0;)for(q0;)for(p0;)for(h0;)for(S0;)for(j0;)for(O0;)for(l0;)for(_0;)for(c0;)for(R0;)for(A0;)for(T0;)for(k0;)for(w0;)for(z0;)for(N0;)for(L0;)for(C0;)for(I0;)for(R0;)for(U0;)for(B0;)for(M0;)for(P0;)for(V0;)for(z0;)for(N0;)for(J0;)for(K0;)for(Z0;)for(Y0;)for(F0;)for(U0;)for(B0;)for(M0;)for($0;)for(Q0;)for(W0;)for(X0;)for(G0;)for(J0;)for(K0;)for(Z0;)for(Y0;)for(vr0;)for(er0;)for(ir0;)for(rr0;)for(H0;)for($0;)for(Q0;)for(W0;)for(X0;)for(G=s&&(v=s-1);else if(t==="wrap")v<0?(v+=s,v<0&&(v%=s,v!==0&&(v+=s))):v>=s&&(v-=s,v>=s&&(v%=s));else if(v<0||v>=s)throw new RangeError(tw("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,v));if(u=a,i==="column-major"){for(n=0;n=0;n--)f=v%r[n],v-=f,v/=r[n],u+=f*e[n];return u}x0.exports=vw});var le=D(function(OP,q0){"use strict";var sw=h0();q0.exports=sw});var b0=D(function(TP,g0){"use strict";var ow=Lr(),nw=le(),uw="throw";function fw(r,e){var a,i,v,t,o,s,u,f,n;for(o=r.shape,v=ow(o),a=r.data,s=r.strides,u=r.offset,i=r.order,t=r.accessors[1],n=0;n0&&(y=I_(y.length))}else y=Zl(x);return Jl(y)===0?R_(d,o,gi(y,f),u,!i):(t=k_(x,v,t),y=gi(y,f),y.length===0?new d(o,r.data,[],[0],t,u,{readonly:!i}):(v=A_(x,v,f),new d(o,r.data,y,v,t,u,{readonly:!i})))}Ql.exports=N_});var qe=D(function(pV,Hl){"use strict";var D_=Wl();Hl.exports=D_});var rc=D(function(mV,$l){"use strict";function C_(r,e){var a,i,v,t,o,s,u,f,n,d;for(v=1,t=1,d=1;d=0&&(n=r[o],i=n<0?-n:n,!(i<=a));)r[o+1]=n,e[s+1]=e[s],o-=1,s-=1;r[o+1]=u,e[s+1]=f,v+=1,t+=1}}$l.exports=C_});var ic=D(function(xV,ac){"use strict";var L_=require("@stdlib/array/base/zero-to"),z_=require("@stdlib/array/base/copy-indexed"),ec=require("@stdlib/array/base/take"),P_=rc();function V_(r,e,a){var i;return i=L_(r.length),e=z_(e),P_(e,i),r=ec(r,i),a=ec(a,i),{sh:r,sx:e,sy:a}}ac.exports=V_});var kr=D(function(hV,tc){"use strict";var M_=ic();tc.exports=M_});var sc=D(function(qV,vc){"use strict";var B_={BLOCK_SIZE_IN_BYTES:64,BLOCK_SIZE_IN_ELEMENTS:8};vc.exports=B_});var uc=D(function(gV,nc){"use strict";var oc=ue(),bi=sc();function U_(r,e){var a,i;return a=oc(r),i=oc(e),a===null||i===null?bi.BLOCK_SIZE_IN_ELEMENTS:a>i?bi.BLOCK_SIZE_IN_BYTES/a|0:bi.BLOCK_SIZE_IN_BYTES/i|0}nc.exports=U_});var Ar=D(function(bV,fc){"use strict";var F_=uc();fc.exports=F_});var lc=D(function(SV,dc){"use strict";var Y_=kr(),K_=Ar();function G_(r,e,a){var i,v,t,o,s,u,f,n,d,y,x,b,p,q,m,g,j,S,h,E,c,_,l,O,w;for(w=Y_(r.shape,r.strides,e.strides),b=w.sh,m=w.sx,g=w.sy,i=K_(r.dtype,e.dtype),j=r.offset,S=e.offset,v=r.data,t=e.data,u=m[0],n=g[0],o=r.accessors[0],s=e.accessors[1],O=b[1];O>0;)for(O0;)for(l0;)for(C0;)for(I0;)for(R0;)for(B0;)for(M0;)for(P0;)for(V0;)for(G0;)for(J0;)for(K0;)for(Z0;)for(Y0;)for(ir0;)for(rr0;)for(H0;)for($0;)for(Q0;)for(W0;)for(nr0;)for(or0;)for(sr0;)for(tr0;)for(ar0;)for(vr0;)for(er0;)for(pr0;)for(lr0;)for(yr0;)for(cr0;)for(dr0;)for(fr0;)for(ur0;)for(nr0;)for(wr0;)for(Sr0;)for(xr0;)for(jr0;)for(gr0;)for(br0;)for(mr0;)for(pr0;)for(lr0;)for(Cr0;)for(Rr0;)for(Ir0;)for(Tr0;)for(Or0;)for(Er0;)for(_r0;)for(wr0;)for(Sr0;)for(xr0;)for(_0;)for(c0;)for(R0;)for(A0;)for(T0;)for(P0;)for(V0;)for(z0;)for(N0;)for(K0;)for(Z0;)for(Y0;)for(F0;)for(U0;)for(H0;)for($0;)for(Q0;)for(W0;)for(X0;)for(G0;)for(sr0;)for(tr0;)for(ar0;)for(vr0;)for(er0;)for(ir0;)for(rr0;)for(yr0;)for(cr0;)for(dr0;)for(fr0;)for(ur0;)for(nr0;)for(or0;)for(sr0;)for(xr0;)for(jr0;)for(gr0;)for(br0;)for(mr0;)for(pr0;)for(lr0;)for(yr0;)for(cr0;)for(Ir0;)for(Tr0;)for(Or0;)for(Er0;)for(_r0;)for(wr0;)for(Sr0;)for(xr0;)for(jr0;)for(gr=u&&(n=u-1);else if(o==="wrap")n<0?(n+=u,n<0&&(n%=u,n!==0&&(n+=u))):n>=u&&(n-=u,n>=u&&(n%=u));else if(n<0||n>=u)throw new RangeError(bO("invalid argument. Subscripts must not exceed array dimensions. Subscript: `%u`. Value: `%d`.",d,n));f=r[d],f<0&&e===0?s-=n*f:s+=n*f}return s}ey.exports=SO});var ji=D(function(pM,iy){"use strict";var wO=ay();iy.exports=wO});var sy=D(function(mM,vy){"use strict";function ty(r,e,a,i,v,t){var o,s,u,f,n;if(t>=e.length)return r.accessors[0](r.data,i);for(u=[],f=e[t],o=a[t],n=0;n0;)for(k0;)for(w0;)for(N0;)for(L0;)for(C0;)for(F0;)for(U0;)for(B0;)for(M0;)for(W0;)for(X0;)for(G0;)for(J0;)for(K0;)for(vr0;)for(er0;)for(ir0;)for(rr0;)for(H0;)for($0;)for(fr0;)for(ur0;)for(nr0;)for(or0;)for(sr0;)for(tr0;)for(ar0;)for(br0;)for(mr0;)for(pr0;)for(lr0;)for(yr0;)for(cr0;)for(dr0;)for(fr0;)for(Er0;)for(_r0;)for(wr0;)for(Sr0;)for(xr0;)for(jr0;)for(gr0;)for(br0;)for(mr0;)for(Kr0;)for(Ur0;)for(Cr0;)for(Rr0;)for(Ir0;)for(Tr0;)for(Or0;)for(Er0;)for(_r0;)for(wr0;)for(O0;)for(l0;)for(C0;)for(I0;)for(R0;)for(B0;)for(M0;)for(P0;)for(V0;)for(G0;)for(J0;)for(K0;)for(Z0;)for(Y0;)for(ir0;)for(rr0;)for(H0;)for($0;)for(Q0;)for(W0;)for(nr0;)for(or0;)for(sr0;)for(tr0;)for(ar0;)for(vr0;)for(er0;)for(pr0;)for(lr0;)for(yr0;)for(cr0;)for(dr0;)for(fr0;)for(ur0;)for(nr0;)for(wr0;)for(Sr0;)for(xr0;)for(jr0;)for(gr0;)for(br0;)for(mr0;)for(pr0;)for(lr0;)for(Cr0;)for(Rr0;)for(Ir0;)for(Tr0;)for(Or0;)for(Er