diff --git a/base/broadcast-arrays/README.md b/base/broadcast-arrays/README.md
new file mode 100644
index 00000000..af0b2fdb
--- /dev/null
+++ b/base/broadcast-arrays/README.md
@@ -0,0 +1,160 @@
+
+
+# broadcastArrays
+
+> Broadcast [ndarrays][@stdlib/ndarray/base/ctor] to a common shape.
+
+
+
+
+
+
+
+
+
+
+
+## Usage
+
+```javascript
+var broadcastArrays = require( '@stdlib/ndarray/base/broadcast-arrays' );
+```
+
+#### broadcastArrays( arrays )
+
+Broadcasts a list of [ndarrays][@stdlib/ndarray/base/ctor] to a common shape.
+
+```javascript
+var array = require( '@stdlib/ndarray/array' );
+var zeros = require( '@stdlib/ndarray/zeros' );
+
+// Create a 2x2 ndarray:
+var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+// returns
+
+// Create a 2x2x2 ndarray:
+var y = zeros( [ 2, 2, 2 ] );
+// returns
+
+// Broadcast to a common shape:
+var out = broadcastArrays( [ x, y ] );
+// returns [ , ]
+```
+
+
+
+
+
+
+
+
+
+## Notes
+
+- The function throws an error if provided [broadcast-incompatible][@stdlib/ndarray/base/broadcast-shapes] ndarrays.
+- Returned [ndarrays][@stdlib/ndarray/base/ctor] are views on their respective underlying data buffers. The views are typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to a returned [ndarray][@stdlib/ndarray/base/ctor], copy the [ndarray][@stdlib/ndarray/base/ctor] **before** performing operations which may mutate elements.
+- Returned [ndarrays][@stdlib/ndarray/base/ctor] are "base" [ndarrays][@stdlib/ndarray/base/ctor], and, thus, the returned [ndarrays][@stdlib/ndarray/base/ctor] do not perform bounds checking or afford any of the guarantees of the non-base [ndarray][@stdlib/ndarray/ctor] constructor. The primary intent of this function is to broadcast ndarray-like objects within internal implementations and to do so with minimal overhead.
+- The function always returns new [ndarray][@stdlib/ndarray/base/ctor] instances even if an input [ndarray][@stdlib/ndarray/base/ctor] shape and the broadcasted shape are the same.
+
+
+
+
+
+
+
+
+
+## Examples
+
+
+
+```javascript
+var array = require( '@stdlib/ndarray/array' );
+var zeros = require( '@stdlib/ndarray/zeros' );
+var numel = require( '@stdlib/ndarray/base/numel' );
+var ind2sub = require( '@stdlib/ndarray/ind2sub' );
+var broadcastArrays = require( '@stdlib/ndarray/base/broadcast-arrays' );
+
+// Create a 2x2 array:
+var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+// returns
+
+// Create a 3x2x2 array:
+var y = zeros( [ 3, 2, 2 ] );
+// returns
+
+// Broadcast the arrays to a common shape:
+var out = broadcastArrays( [ x, y ] );
+// returns [ , ]
+
+// Retrieve the common shape:
+var sh = out[ 0 ].shape;
+// returns [ 3, 2, 2 ]
+
+// Retrieve the number of elements:
+var N = numel( sh );
+
+// Loop through the array elements...
+var sub;
+var v;
+var i;
+for ( i = 0; i < N; i++ ) {
+ v = out[ 0 ].iget( i );
+ sub = ind2sub( sh, i );
+ console.log( 'X[%s] = %d', sub.join( ', ' ), v );
+}
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
+
+[@stdlib/ndarray/base/ctor]: https://github.com/stdlib-js/ndarray/tree/main/base/ctor
+
+[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray/tree/main/base/broadcast-shapes
+
+
+
+
diff --git a/base/broadcast-arrays/benchmark/benchmark.js b/base/broadcast-arrays/benchmark/benchmark.js
new file mode 100644
index 00000000..c3689775
--- /dev/null
+++ b/base/broadcast-arrays/benchmark/benchmark.js
@@ -0,0 +1,168 @@
+/**
+* @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 Float64Array = require( '@stdlib/array/float64' );
+var ndarrayBase = require( './../../../base/ctor' );
+var ndarray = require( './../../../ctor' );
+var zeros = require( './../../../base/zeros' );
+var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
+var pkg = require( './../package.json' ).name;
+var broadcastArrays = require( './../lib' );
+
+
+// MAIN //
+
+bench( pkg+'::base_ndarray,2d:num_arrays=2', function benchmark( b ) {
+ var strides;
+ var values;
+ var buffer;
+ var offset;
+ var dtype;
+ var shape;
+ var order;
+ var out;
+ var y;
+ var i;
+
+ dtype = 'float64';
+ buffer = new Float64Array( 4 );
+ shape = [ 2, 2 ];
+ strides = [ 2, 1 ];
+ offset = 0;
+ order = 'row-major';
+
+ values = [
+ ndarrayBase( dtype, buffer, shape, strides, offset, order ),
+ ndarrayBase( dtype, buffer, shape, strides, offset, order ),
+ ndarrayBase( dtype, buffer, shape, strides, offset, order ),
+ ndarrayBase( dtype, buffer, shape, strides, offset, order ),
+ ndarrayBase( dtype, buffer, shape, strides, offset, order )
+ ];
+ y = zeros( dtype, [ 2, 2, 2 ], order );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = broadcastArrays( [ values[ i%values.length ], y ] );
+ if ( typeof out !== 'object' ) {
+ b.fail( 'should return an object' );
+ }
+ }
+ b.toc();
+ if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) {
+ b.fail( 'should return an array of ndarrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
+
+bench( pkg+'::ndarray,2d:num_arrays=2', function benchmark( b ) {
+ var strides;
+ var values;
+ var buffer;
+ var offset;
+ var dtype;
+ var shape;
+ var order;
+ var out;
+ var y;
+ var i;
+
+ dtype = 'float64';
+ buffer = new Float64Array( 4 );
+ shape = [ 2, 2 ];
+ strides = [ 2, 1 ];
+ offset = 0;
+ order = 'row-major';
+
+ values = [
+ ndarray( dtype, buffer, shape, strides, offset, order ),
+ ndarray( dtype, buffer, shape, strides, offset, order ),
+ ndarray( dtype, buffer, shape, strides, offset, order ),
+ ndarray( dtype, buffer, shape, strides, offset, order ),
+ ndarray( dtype, buffer, shape, strides, offset, order )
+ ];
+ y = zeros( dtype, [ 2, 2, 2 ], order );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = broadcastArrays( [ values[ i%values.length ], y ] );
+ if ( typeof out !== 'object' ) {
+ b.fail( 'should return an object' );
+ }
+ }
+ b.toc();
+ if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) {
+ b.fail( 'should return an array of ndarrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
+
+bench( pkg+'::ndarray_like,2d:num_arrays=2', function benchmark( b ) {
+ var strides;
+ var values;
+ var buffer;
+ var offset;
+ var dtype;
+ var shape;
+ var order;
+ var out;
+ var obj;
+ var y;
+ var i;
+
+ dtype = 'float64';
+ buffer = new Float64Array( 4 );
+ shape = [ 2, 2 ];
+ strides = [ 2, 1 ];
+ offset = 0;
+ order = 'row-major';
+
+ values = [];
+ for ( i = 0; i < 5; i++ ) {
+ obj = {
+ 'dtype': dtype,
+ 'data': buffer,
+ 'shape': shape,
+ 'strides': strides,
+ 'offset': offset,
+ 'order': order
+ };
+ values.push( obj );
+ }
+ y = zeros( dtype, [ 2, 2, 2 ], order );
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = broadcastArrays( [ values[ i%values.length ], y ] );
+ if ( typeof out !== 'object' ) {
+ b.fail( 'should return an object' );
+ }
+ }
+ b.toc();
+ if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) {
+ b.fail( 'should return an array of ndarrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+});
diff --git a/base/broadcast-arrays/benchmark/benchmark.ndims.js b/base/broadcast-arrays/benchmark/benchmark.ndims.js
new file mode 100644
index 00000000..9123dbb6
--- /dev/null
+++ b/base/broadcast-arrays/benchmark/benchmark.ndims.js
@@ -0,0 +1,113 @@
+/**
+* @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 array = require( './../../../array' );
+var zeros = require( './../../../zeros' );
+var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
+var pkg = require( './../package.json' ).name;
+var broadcastArrays = require( './../lib' );
+
+
+// FUNCTIONS //
+
+/**
+* Creates a benchmark function.
+*
+* @private
+* @param {PositiveInteger} ndims - number of dimensions to which to broadcast
+* @returns {Function} benchmark function
+*/
+function createBenchmark( ndims ) {
+ var shape;
+ var sh;
+ var x;
+ var y;
+ var i;
+
+ x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+ sh = x.shape;
+
+ shape = [];
+ for ( i = 0; i < ndims; i++ ) {
+ shape.push( 0 );
+ }
+ for ( i = ndims; i >= 1; i-- ) {
+ if ( i > sh.length ) {
+ shape[ ndims-i ] = 5;
+ } else {
+ shape[ ndims-i ] = sh[ i-1 ];
+ }
+ }
+ y = zeros( shape );
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var out;
+ var i;
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = broadcastArrays( [ x, y ] );
+ if ( typeof out !== 'object' ) {
+ b.fail( 'should return an object' );
+ }
+ }
+ b.toc();
+ if ( !isndarrayLike( out[ 0 ] ) || !isndarrayLike( out[ 1 ] ) ) {
+ b.fail( 'should return an array of ndarrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 2;
+ max = 10;
+
+ for ( i = min; i <= max; i++ ) {
+ f = createBenchmark( i );
+ bench( pkg+'::ndarray,2d::num_arrays=2,from_ndims=2,to_ndims='+i, f );
+ }
+}
+
+main();
diff --git a/base/broadcast-arrays/benchmark/benchmark.num_arrays.js b/base/broadcast-arrays/benchmark/benchmark.num_arrays.js
new file mode 100644
index 00000000..a84f9db7
--- /dev/null
+++ b/base/broadcast-arrays/benchmark/benchmark.num_arrays.js
@@ -0,0 +1,125 @@
+/**
+* @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 array = require( './../../../array' );
+var zeros = require( './../../../zeros' );
+var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
+var isArray = require( '@stdlib/assert/is-array' );
+var pkg = require( './../package.json' ).name;
+var broadcastArrays = require( './../lib' );
+
+
+// FUNCTIONS //
+
+/**
+* Creates a benchmark function.
+*
+* @private
+* @param {PositiveInteger} narrays - number of arrays to broadcast
+* @param {PositiveInteger} ndims - number of dimensions
+* @returns {Function} benchmark function
+*/
+function createBenchmark( narrays, ndims ) {
+ var arrays;
+ var shape;
+ var sh;
+ var x;
+ var y;
+ var i;
+
+ x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+ sh = x.shape;
+
+ shape = [];
+ for ( i = 0; i < ndims; i++ ) {
+ shape.push( 0 );
+ }
+ for ( i = ndims; i >= 1; i-- ) {
+ if ( i > sh.length ) {
+ shape[ ndims-i ] = 5;
+ } else {
+ shape[ ndims-i ] = sh[ i-1 ];
+ }
+ }
+ arrays = [ x ];
+ for ( i = 1; i < narrays; i++ ) {
+ if ( i < narrays-1 ) {
+ y = zeros( sh );
+ } else {
+ y = zeros( shape );
+ }
+ arrays.push( y );
+ }
+
+ return benchmark;
+
+ /**
+ * Benchmark function.
+ *
+ * @private
+ * @param {Benchmark} b - benchmark instance
+ */
+ function benchmark( b ) {
+ var out;
+ var i;
+
+ b.tic();
+ for ( i = 0; i < b.iterations; i++ ) {
+ out = broadcastArrays( arrays );
+ if ( typeof out !== 'object' ) {
+ b.fail( 'should return an object' );
+ }
+ }
+ b.toc();
+ if ( !isArray( out ) || !isndarrayLike( out[ 0 ] ) ) {
+ b.fail( 'should return an array of ndarrays' );
+ }
+ b.pass( 'benchmark finished' );
+ b.end();
+ }
+}
+
+
+// MAIN //
+
+/**
+* Main execution sequence.
+*
+* @private
+*/
+function main() {
+ var min;
+ var max;
+ var f;
+ var i;
+
+ min = 1;
+ max = 10;
+
+ for ( i = min; i <= max; i++ ) {
+ f = createBenchmark( i, 10 );
+ bench( pkg+'::ndarray,2d::num_arrays='+i+',from_ndims=2,to_ndims=10', f );
+ }
+}
+
+main();
diff --git a/base/broadcast-arrays/docs/repl.txt b/base/broadcast-arrays/docs/repl.txt
new file mode 100644
index 00000000..1fcf3b64
--- /dev/null
+++ b/base/broadcast-arrays/docs/repl.txt
@@ -0,0 +1,70 @@
+
+{{alias}}( arrays )
+ Broadcasts ndarrays to a common shape.
+
+ The returned arrays are views on their respective underlying array data
+ buffers. The views are typically **not** contiguous. As more than one
+ element of a returned view may refer to the same memory location, writing
+ to a view may affect multiple elements. If you need to write to a returned
+ array, copy the array before performing operations which may mutate
+ elements.
+
+ Returned arrays are "base" ndarrays, and, thus, returned arrays do not
+ perform bounds checking or afford any of the guarantees of the non-base
+ ndarray constructor. The primary intent of this function is to broadcast
+ ndarray-like objects within internal implementations and to do so with
+ minimal overhead.
+
+ The function throws an error if provided broadcast-incompatible ndarrays.
+
+ The function always returns new ndarray instances even if an input ndarray
+ and the broadcasted shape are the same.
+
+ Parameters
+ ----------
+ arrays: ArrayLike
+ List of ndarrays.
+
+ Returns
+ -------
+ out: Array
+ Broadcasted arrays.
+
+ Examples
+ --------
+ > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] )
+
+ > var sh = x.shape
+ [ 2, 2 ]
+ > var y = {{alias:@stdlib/ndarray/zeros}}( [ 3, 2, 2 ] )
+
+ > var out = {{alias}}( [ x, y ] )
+ [ , ]
+
+ // Retrieve the broadcasted "x" array:
+ > var bx = out[ 0 ]
+
+ > sh = bx.shape
+ [ 3, 2, 2 ]
+
+ // Retrieve broadcasted elements...
+ > var v = bx.get( 0, 0, 0 )
+ 1
+ > v = bx.get( 0, 0, 1 )
+ 2
+ > v = bx.get( 0, 1, 0 )
+ 3
+ > v = bx.get( 0, 1, 1 )
+ 4
+ > v = bx.get( 1, 0, 0 )
+ 1
+ > v = bx.get( 1, 1, 0 )
+ 3
+ > v = bx.get( 2, 0, 0 )
+ 1
+ > v = bx.get( 2, 1, 1 )
+ 4
+
+ See Also
+ --------
+
diff --git a/base/broadcast-arrays/docs/types/index.d.ts b/base/broadcast-arrays/docs/types/index.d.ts
new file mode 100644
index 00000000..8332bbf2
--- /dev/null
+++ b/base/broadcast-arrays/docs/types/index.d.ts
@@ -0,0 +1,106 @@
+/*
+* @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 { ArrayLike } from '@stdlib/types/array';
+import { ndarray } from '@stdlib/types/ndarray';
+
+/**
+* Broadcasts ndarrays to a common shape.
+*
+* ## Notes
+*
+* - The function throws an error if provided broadcast-incompatible ndarrays.
+* - The returned arrays are views on their respective underlying array data buffers. The views are typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to a returned array, copy the array before performing operations which may mutate elements.
+* - The returned arrays are "base" ndarrays, and, thus, returned arrays do not perform bounds checking or afford any of the guarantees of the non-base ndarray constructor. The primary intent of this function is to broadcast ndarray-like objects within internal implementations and to do so with minimal overhead.
+* - The function always returns new ndarray instances even if an input ndarray shape and the broadcasted shape are the same.
+*
+* @param arrays - input arrays
+* @throws input arrays must be broadcast compatible
+* @returns list of broadcasted arrays
+*
+* @example
+* var array = require( '@stdlib/ndarray/array' );
+* var zeros = require( '@stdlib/ndarray/zeros' );
+*
+* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+* // returns
+*
+* var shx = x1.shape;
+* // returns [ 2, 2 ]
+*
+* var y1 = zeros( [ 3, 2, 2 ] );
+* // returns
+*
+* var shy = y1.shape;
+* // returns [ 3, 2, 2 ]
+*
+* var out = broadcastArrays( [ x1, y1 ] );
+* // returns
+*
+* var x2 = out[ 0 ];
+* // returns
+*
+* var y2 = out[ 1 ];
+* // returns
+*
+* shx = x2.shape;
+* // returns [ 3, 2, 2 ]
+*
+* shy = y2.shape;
+* // returns [ 3, 2, 2 ]
+*
+* var v = x2.get( 0, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 0, 0, 1 );
+* // returns 2
+*
+* v = x2.get( 1, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 1, 1, 0 );
+* // returns 3
+*
+* v = x2.get( 2, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 2, 1, 1 );
+* // returns 4
+*
+* @example
+* var zeros = require( '@stdlib/ndarray/zeros' );
+*
+* var x = zeros( [ 2, 2 ] );
+* // returns
+*
+* var y = zeros( [ 4, 2 ] );
+* // returns
+*
+* var out = broadcastArrays( [ x, y ] );
+* // throws
+*/
+declare function broadcastArrays( arrays: ArrayLike ): Array;
+
+
+// EXPORTS //
+
+export = broadcastArrays;
diff --git a/base/broadcast-arrays/docs/types/test.ts b/base/broadcast-arrays/docs/types/test.ts
new file mode 100644
index 00000000..51739c8f
--- /dev/null
+++ b/base/broadcast-arrays/docs/types/test.ts
@@ -0,0 +1,54 @@
+/*
+* @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 zeros = require( './../../../../zeros' );
+import broadcastArrays = require( './index' );
+
+
+// TESTS //
+
+// The function returns an array of ndarrays...
+{
+ const x = zeros( [ 2, 2 ] );
+ const y = zeros( [ 2, 2, 2 ] );
+
+ broadcastArrays( [ x ] ); // $ExpectType ndarray[]
+ broadcastArrays( [ x, y ] ); // $ExpectType ndarray[]
+ broadcastArrays( [ x, y, x ] ); // $ExpectType ndarray[]
+}
+
+// The compiler throws an error if the function is not provided a first argument which is an array of ndarrays...
+{
+ broadcastArrays( '5' ); // $ExpectError
+ broadcastArrays( 5 ); // $ExpectError
+ broadcastArrays( true ); // $ExpectError
+ broadcastArrays( false ); // $ExpectError
+ broadcastArrays( null ); // $ExpectError
+ broadcastArrays( {} ); // $ExpectError
+ broadcastArrays( [ '5' ] ); // $ExpectError
+ broadcastArrays( ( x: number ): number => x ); // $ExpectError
+}
+
+// The compiler throws an error if the function is provided an unsupported number of arguments...
+{
+ const x = zeros( [ 2, 2 ] );
+ const y = zeros( [ 2, 2, 2 ] );
+
+ broadcastArrays(); // $ExpectError
+ broadcastArrays( [ x, y ], {} ); // $ExpectError
+}
diff --git a/base/broadcast-arrays/examples/index.js b/base/broadcast-arrays/examples/index.js
new file mode 100644
index 00000000..1cb24426
--- /dev/null
+++ b/base/broadcast-arrays/examples/index.js
@@ -0,0 +1,54 @@
+/**
+* @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 zeros = require( './../../../zeros' );
+var numel = require( './../../../base/numel' );
+var ind2sub = require( './../../../ind2sub' );
+var broadcastArrays = require( './../lib' );
+
+// Create a 2x2 array:
+var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+// returns
+
+// Create a 3x2x2 array:
+var y = zeros( [ 3, 2, 2 ] );
+// returns
+
+// Broadcast the arrays to a common shape:
+var out = broadcastArrays( [ x, y ] );
+// returns [ , ]
+
+// Retrieve the common shape:
+var sh = out[ 0 ].shape;
+// returns [ 3, 2, 2 ]
+
+// Retrieve the number of elements:
+var N = numel( sh );
+
+// Loop through the array elements...
+var sub;
+var v;
+var i;
+for ( i = 0; i < N; i++ ) {
+ v = out[ 0 ].iget( i );
+ sub = ind2sub( sh, i );
+ console.log( 'X[%s] = %d', sub.join( ', ' ), v );
+}
diff --git a/base/broadcast-arrays/lib/index.js b/base/broadcast-arrays/lib/index.js
new file mode 100644
index 00000000..7479f9ba
--- /dev/null
+++ b/base/broadcast-arrays/lib/index.js
@@ -0,0 +1,84 @@
+/**
+* @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';
+
+/**
+* Broadcast ndarrays to a common shape.
+*
+* @module @stdlib/ndarray/base/broadcast-arrays
+*
+* @example
+* var array = require( '@stdlib/ndarray/array' );
+* var zeros = require( '@stdlib/ndarray/zeros' );
+* var broadcastArrays = require( '@stdlib/ndarray/base/broadcast-arrays' );
+*
+* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+* // returns
+*
+* var shx = x1.shape;
+* // returns [ 2, 2 ]
+*
+* var y1 = zeros( [ 3, 2, 2 ] );
+* // returns
+*
+* var shy = y1.shape;
+* // returns [ 3, 2, 2 ]
+*
+* var out = broadcastArrays( [ x1, y1 ] );
+* // returns
+*
+* var x2 = out[ 0 ];
+* // returns
+*
+* var y2 = out[ 1 ];
+* // returns
+*
+* shx = x2.shape;
+* // returns [ 3, 2, 2 ]
+*
+* shy = y2.shape;
+* // returns [ 3, 2, 2 ]
+*
+* var v = x2.get( 0, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 0, 0, 1 );
+* // returns 2
+*
+* v = x2.get( 1, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 1, 1, 0 );
+* // returns 3
+*
+* v = x2.get( 2, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 2, 1, 1 );
+* // returns 4
+*/
+
+// MODULES //
+
+var main = require( './main.js' );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/base/broadcast-arrays/lib/main.js b/base/broadcast-arrays/lib/main.js
new file mode 100644
index 00000000..7a23801c
--- /dev/null
+++ b/base/broadcast-arrays/lib/main.js
@@ -0,0 +1,132 @@
+/**
+* @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 broadcastShapes = require( './../../../base/broadcast-shapes' );
+var broadcastArray = require( './../../../base/broadcast-array' );
+var getShape = require( './../../../base/shape' );
+
+
+// MAIN //
+
+/**
+* Broadcasts ndarrays to a common shape.
+*
+* ## Notes
+*
+* - The returned arrays are views on their respective underlying data buffers. The views are typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to a view may affect multiple elements. If you need to write to one of the returned arrays, copy the array before performing operations which may mutate elements.
+*
+* @param {ArrayLikeObject} arrays - list of input arrays
+* @throws {Error} input arrays must be broadcast compatible
+* @returns {Array} broadcasted arrays
+*
+* @example
+* var array = require( '@stdlib/ndarray/array' );
+* var zeros = require( '@stdlib/ndarray/zeros' );
+*
+* var x1 = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+* // returns
+*
+* var shx = x1.shape;
+* // returns [ 2, 2 ]
+*
+* var y1 = zeros( [ 3, 2, 2 ] );
+* // returns
+*
+* var shy = y1.shape;
+* // returns [ 3, 2, 2 ]
+*
+* var out = broadcastArrays( [ x1, y1 ] );
+* // returns
+*
+* var x2 = out[ 0 ];
+* // returns
+*
+* var y2 = out[ 1 ];
+* // returns
+*
+* shx = x2.shape;
+* // returns [ 3, 2, 2 ]
+*
+* shy = y2.shape;
+* // returns [ 3, 2, 2 ]
+*
+* var v = x2.get( 0, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 0, 0, 1 );
+* // returns 2
+*
+* v = x2.get( 1, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 1, 1, 0 );
+* // returns 3
+*
+* v = x2.get( 2, 0, 0 );
+* // returns 1
+*
+* v = x2.get( 2, 1, 1 );
+* // returns 4
+*
+* @example
+* var zeros = require( '@stdlib/ndarray/zeros' );
+*
+* var x = zeros( [ 2, 2 ] );
+* // returns
+*
+* var y = zeros( [ 4, 2 ] );
+* // returns
+*
+* var out = broadcastArrays( [ x, y ] );
+* // throws
+*/
+function broadcastArrays( arrays ) {
+ var shapes;
+ var out;
+ var sh;
+ var N;
+ var i;
+
+ N = arrays.length;
+
+ // Resolve the list of shapes...
+ shapes = [];
+ for ( i = 0; i < N; i++ ) {
+ shapes.push( getShape( arrays[ i ], false ) );
+ }
+ // Broadcast the shapes to a common shape:
+ sh = broadcastShapes( shapes );
+ if ( sh === null ) {
+ throw new Error( 'invalid arguments. Input arrays must be broadcast compatible.' );
+ }
+ // Broadcast each array to the common shape...
+ out = [];
+ for ( i = 0; i < N; i++ ) {
+ out.push( broadcastArray( arrays[ i ], sh ) );
+ }
+ return out;
+}
+
+
+// EXPORTS //
+
+module.exports = broadcastArrays;
diff --git a/base/broadcast-arrays/package.json b/base/broadcast-arrays/package.json
new file mode 100644
index 00000000..8d9c159e
--- /dev/null
+++ b/base/broadcast-arrays/package.json
@@ -0,0 +1,68 @@
+{
+ "name": "@stdlib/ndarray/base/broadcast-arrays",
+ "version": "0.0.0",
+ "description": "Broadcast ndarrays to a common shape.",
+ "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",
+ "broadcast",
+ "broadcasting",
+ "reshape",
+ "multidimensional",
+ "array",
+ "utilities",
+ "utility",
+ "utils",
+ "util"
+ ],
+ "__stdlib__": {}
+}
diff --git a/base/broadcast-arrays/test/test.js b/base/broadcast-arrays/test/test.js
new file mode 100644
index 00000000..a9415a50
--- /dev/null
+++ b/base/broadcast-arrays/test/test.js
@@ -0,0 +1,396 @@
+/**
+* @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 isArray = require( '@stdlib/assert/is-array' );
+var array = require( './../../../array' );
+var zeros = require( './../../../zeros' );
+var ndarray = require( './../../../base/ctor' );
+var broadcastArrays = require( './../lib' );
+
+
+// TESTS //
+
+tape( 'main export is a function', function test( t ) {
+ t.ok( true, __filename );
+ t.strictEqual( typeof broadcastArrays, 'function', 'main export is a function' );
+ t.end();
+});
+
+tape( 'the function throws an error if provided a desired shape and an input array shape are broadcast-incompatible', function test( t ) {
+ var values;
+ var x;
+ var i;
+
+ x = array({
+ 'shape': [ 10, 10 ]
+ });
+
+ values = [
+ [ 10, 20, 10 ],
+ [ 10, 10, 100 ],
+ [ 10, 10, 2 ],
+ [ 10, 10, 9 ],
+ [ 10, 2, 10 ],
+ [ 10, 9, 10 ]
+ ];
+ for ( i = 0; i < values.length; i++ ) {
+ t.throws( badValue( values[ i ] ), Error, 'throws an error when provided shape ('+values[ i ].join( ',')+')' );
+ }
+ t.end();
+
+ function badValue( value ) {
+ return function badValue() {
+ broadcastArrays( [ x, zeros( value ) ] );
+ };
+ }
+});
+
+tape( 'the function returns an empty array if provided an empty array', function test( t ) {
+ var out = broadcastArrays( [] );
+ t.strictEqual( isArray( out ), true, 'returns expected value' );
+ t.deepEqual( out, [], 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function returns "base" ndarray instances (1 array)', function test( t ) {
+ var out;
+ var x;
+
+ x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+ out = broadcastArrays( [ x ] );
+
+ t.strictEqual( isArray( out ), true, 'returns expected value' );
+ t.strictEqual( out.length, 1, 'returns expected value' );
+
+ t.notEqual( out[ 0 ], x, 'returns new instance' );
+ t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns "base" ndarray instances (2 arrays)', function test( t ) {
+ var out;
+ var x;
+ var y;
+
+ x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+ y = zeros( [ 2, 2, 2 ] );
+ out = broadcastArrays( [ x, y ] );
+
+ t.strictEqual( isArray( out ), true, 'returns expected value' );
+ t.strictEqual( out.length, 2, 'returns expected value' );
+
+ t.notEqual( out[ 0 ], x, 'returns new instance' );
+ t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' );
+
+ t.notEqual( out[ 1 ], y, 'returns new instance' );
+ t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns "base" ndarray instances (>2 arrays)', function test( t ) {
+ var out;
+ var x;
+ var y;
+ var z;
+
+ x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+ y = zeros( [ 2, 2, 2 ] );
+ z = zeros( [ 1 ] );
+ out = broadcastArrays( [ x, y, z ] );
+
+ t.strictEqual( isArray( out ), true, 'returns expected value' );
+ t.strictEqual( out.length, 3, 'returns expected value' );
+
+ t.notEqual( out[ 0 ], x, 'returns new instance' );
+ t.strictEqual( out[ 0 ] instanceof ndarray, true, 'returns expected value' );
+
+ t.notEqual( out[ 1 ], y, 'returns new instance' );
+ t.strictEqual( out[ 1 ] instanceof ndarray, true, 'returns expected value' );
+
+ t.notEqual( out[ 2 ], z, 'returns new instance' );
+ t.strictEqual( out[ 2 ] instanceof ndarray, true, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function returns views over underlying array data buffers', function test( t ) {
+ var out;
+ var x;
+ var y;
+ var z;
+
+ x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
+ y = zeros( [ 2, 2, 2 ] );
+ z = zeros( [ 1 ] );
+ out = broadcastArrays( [ x, y, z ] );
+
+ t.strictEqual( out[ 0 ].data, x.data, 'returns expected value' );
+ t.strictEqual( out[ 1 ].data, y.data, 'returns expected value' );
+ t.strictEqual( out[ 2 ].data, z.data, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function broadcasts input arrays (row-major)', function test( t ) {
+ var expected;
+ var data;
+ var out;
+ var x;
+ var y;
+ var v;
+ var i;
+
+ data = [ 1, 2, 3, 4 ];
+ x = array( data, {
+ 'dtype': 'generic',
+ 'shape': [ 2, 2 ],
+ 'order': 'row-major'
+ });
+ y = zeros( [ 5, 1, 2 ], {
+ 'order': 'row-major',
+ 'dtype': 'generic'
+ });
+
+ expected = [ 5, 2, 2 ];
+ out = broadcastArrays( [ x, y ] );
+
+ t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' );
+ t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' );
+
+ for ( i = 0; i < expected[ 0 ]; i++ ) {
+ v = out[ 0 ].get( i, 0, 0 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' );
+
+ v = out[ 0 ].get( i, 0, 1 );
+ t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',0,1)' );
+
+ v = out[ 0 ].get( i, 1, 0 );
+ t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',1,0)' );
+
+ v = out[ 0 ].get( i, 1, 1 );
+ t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' );
+ }
+ t.end();
+});
+
+tape( 'the function broadcasts input arrays (row-major; strides)', function test( t ) {
+ var expected;
+ var data;
+ var out;
+ var x;
+ var y;
+ var v;
+ var i;
+
+ data = [ 1, 2, 3, 4 ];
+ x = ndarray( 'generic', data, [ 2, 2 ], [ -2, -1 ], 3, 'row-major' );
+ y = ndarray( 'generic', [ 0, 0, 0, 0, 0 ], [ 5, 1, 1 ], [ -1, -1, -1 ], 4, 'row-major' );
+
+ expected = [ 5, 2, 2 ];
+ out = broadcastArrays( [ x, y ] );
+
+ t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' );
+ t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' );
+
+ for ( i = 0; i < expected[ 0 ]; i++ ) {
+ v = out[ 0 ].get( i, 0, 0 );
+ t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',0,0)' );
+
+ v = out[ 0 ].get( i, 0, 1 );
+ t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' );
+
+ v = out[ 0 ].get( i, 1, 0 );
+ t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' );
+
+ v = out[ 0 ].get( i, 1, 1 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' );
+ }
+ t.end();
+});
+
+tape( 'the function broadcasts input arrays (column-major)', function test( t ) {
+ var expected;
+ var data;
+ var out;
+ var x;
+ var y;
+ var v;
+ var i;
+
+ data = [ 1, 2, 3, 4 ];
+ x = array( data, {
+ 'dtype': 'generic',
+ 'shape': [ 2, 2 ],
+ 'order': 'column-major'
+ });
+ y = zeros( [ 5, 1, 2 ], {
+ 'order': 'row-major',
+ 'dtype': 'generic'
+ });
+
+ expected = [ 5, 2, 2 ];
+ out = broadcastArrays( [ x, y ] );
+
+ t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' );
+ t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' );
+
+ for ( i = 0; i < expected[ 0 ]; i++ ) {
+ v = out[ 0 ].get( i, 0, 0 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' );
+
+ v = out[ 0 ].get( i, 0, 1 );
+ t.strictEqual( v, data[ 2 ], 'returns expected value for element ('+i+',0,1)' );
+
+ v = out[ 0 ].get( i, 1, 0 );
+ t.strictEqual( v, data[ 1 ], 'returns expected value for element ('+i+',1,0)' );
+
+ v = out[ 0 ].get( i, 1, 1 );
+ t.strictEqual( v, data[ 3 ], 'returns expected value for element ('+i+',1,1)' );
+ }
+ t.end();
+});
+
+tape( 'the function broadcasts input arrays (same shape)', function test( t ) {
+ var expected;
+ var data;
+ var out;
+ var x;
+ var y;
+ var v;
+ var i;
+
+ data = [ 1, 2, 3, 4, 5, 6, 7, 8 ];
+ x = array( data, {
+ 'dtype': 'generic',
+ 'shape': [ 2, 2, 2 ],
+ 'order': 'row-major'
+ });
+ y = zeros( [ 2, 2, 2 ], {
+ 'dtype': 'generic',
+ 'order': 'row-major'
+ });
+
+ expected = [ 2, 2, 2 ];
+ out = broadcastArrays( [ x, y ] );
+
+ t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' );
+ t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' );
+
+ for ( i = 0; i < expected[ 0 ]; i++ ) {
+ v = out[ 0 ].get( i, 0, 0 );
+ t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' );
+
+ v = out[ 0 ].get( i, 0, 1 );
+ t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' );
+
+ v = out[ 0 ].get( i, 1, 0 );
+ t.strictEqual( v, x.get( i, 1, 0 ), 'returns expected value for element ('+i+',1,0)' );
+
+ v = out[ 0 ].get( i, 1, 1 );
+ t.strictEqual( v, x.get( i, 1, 1 ), 'returns expected value for element ('+i+',1,1)' );
+ }
+ t.end();
+});
+
+tape( 'the function broadcasts input arrays (same number of dimensions)', function test( t ) {
+ var expected;
+ var data;
+ var out;
+ var x;
+ var y;
+ var v;
+ var i;
+
+ data = [ 1, 2, 3, 4 ];
+ x = array( data, {
+ 'dtype': 'generic',
+ 'shape': [ 2, 1, 2 ],
+ 'order': 'row-major'
+ });
+ y = zeros( [ 1, 2, 1 ], {
+ 'dtype': 'generic',
+ 'order': 'row-major'
+ });
+
+ expected = [ 2, 2, 2 ];
+ out = broadcastArrays( [ x, y ] );
+
+ t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' );
+ t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' );
+
+ for ( i = 0; i < expected[ 0 ]; i++ ) {
+ v = out[ 0 ].get( i, 0, 0 );
+ t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',0,0)' );
+
+ v = out[ 0 ].get( i, 0, 1 );
+ t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',0,1)' );
+
+ v = out[ 0 ].get( i, 1, 0 );
+ t.strictEqual( v, x.get( i, 0, 0 ), 'returns expected value for element ('+i+',1,0)' );
+
+ v = out[ 0 ].get( i, 1, 1 );
+ t.strictEqual( v, x.get( i, 0, 1 ), 'returns expected value for element ('+i+',1,1)' );
+ }
+ t.end();
+});
+
+tape( 'the function broadcasts input arrays (0-dimensional array)', function test( t ) {
+ var expected;
+ var data;
+ var out;
+ var x;
+ var y;
+ var v;
+ var i;
+
+ data = [ 1 ];
+ x = ndarray( 'generic', data, [], [ 0 ], 0, 'row-major' );
+
+ y = zeros( [ 5, 2, 2 ], {
+ 'dtype': 'generic',
+ 'order': 'row-major'
+ });
+
+ expected = [ 5, 2, 2 ];
+ out = broadcastArrays( [ x, y ] );
+
+ t.deepEqual( out[ 0 ].shape, expected, 'returns expected shape' );
+ t.deepEqual( out[ 1 ].shape, expected, 'returns expected shape' );
+
+ for ( i = 0; i < expected[ 0 ]; i++ ) {
+ v = out[ 0 ].get( i, 0, 0 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,0)' );
+
+ v = out[ 0 ].get( i, 0, 1 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',0,1)' );
+
+ v = out[ 0 ].get( i, 1, 0 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,0)' );
+
+ v = out[ 0 ].get( i, 1, 1 );
+ t.strictEqual( v, data[ 0 ], 'returns expected value for element ('+i+',1,1)' );
+ }
+ t.end();
+});
diff --git a/base/lib/index.js b/base/lib/index.js
index 0b96d452..0dc30326 100644
--- a/base/lib/index.js
+++ b/base/lib/index.js
@@ -94,6 +94,15 @@ setReadOnly( ns, 'bind2vind', require( './../../base/bind2vind' ) );
*/
setReadOnly( ns, 'broadcastArray', require( './../../base/broadcast-array' ) );
+/**
+* @name broadcastArrays
+* @memberof ns
+* @readonly
+* @type {Function}
+* @see {@link module:@stdlib/ndarray/base/broadcast-arrays}
+*/
+setReadOnly( ns, 'broadcastArrays', require( './../../base/broadcast-arrays' ) );
+
/**
* @name broadcastScalar
* @memberof ns
diff --git a/dist/index.js b/dist/index.js
index c9cb4993..b7ec697e 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1,4 +1,4 @@
-"use strict";var P=function(r,a){return function(){return a||r((a={exports:{}}).exports,a),a.exports}};var av=P(function(rW,ev){"use strict";function G6(r){var a,e,i,v;for(a=r.length,e=[],v=0;v=0;v--)e[v]=i,i*=r[v];return e}function J6(r){var a,e,i;for(a=[],e=1,i=0;i=0;v--)a[v]=i,i*=r[v];return a}function W6(r,a){var e,i;for(e=1,i=0;iv&&(i=!1),i||a)v=t;else return 0;return i&&a?3:i?1:2}dv.exports=a5});var De=P(function(sW,cv){"use strict";var i5=lv();cv.exports=i5});var pv=P(function(oW,yv){"use strict";function t5(r){var a,e,i;if(a=r.length,a===0)return 0;for(e=1,i=0;i0?t+=o*(r[s]-1):o<0&&(v+=o*(r[s]-1))}return[v,t]}Bv.exports=T5});var Yv=P(function(SW,Uv){"use strict";function I5(r,a,e,i){var v,t,o,s,u;for(v=r.length,t=e,o=e,u=0;u0?o+=s*(r[u]-1):s<0&&(t+=s*(r[u]-1))}return i[0]=t,i[1]=o,i}Uv.exports=I5});var qe=P(function(jW,Gv){"use strict";var k5=require("@stdlib/utils/define-nonenumerable-read-only-property"),Kv=Fv(),N5=Yv();k5(Kv,"assign",N5);Gv.exports=Kv});var Zv=P(function(EW,Jv){"use strict";var A5=qe();function R5(r,a,e,i){var v=A5(a,e,i);return v[0]>=0&&v[1]=0;o--)t=r%e[o],r-=t,r/=e[o],v+=t*a[o];return this._accessors?this._buffer.get(v):this._buffer[v]}ds.exports=G5});var ys=P(function(PW,cs){"use strict";function J5(r,a){var e,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(a,this._offset+r):this._buffer[this._offset+r]=a,this;if(this._iterationOrder===-1)return this._accessors?this._buffer.set(a,this._offset-r):this._buffer[this._offset-r]=a,this}if(i=this._shape,e=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*e[s];return this._accessors?this._buffer.set(a,t):this._buffer[t]=a,this}cs.exports=J5});var ms=P(function(VW,ps){"use strict";function Z5(){var r,a;for(r=this._offset,a=0;a=0;o--)t=this.iget(this._length-1-o),r+=Ei(t)+", "+_i(t),o>0&&(r+=", ");else for(o=2;o>=0;o--)r+=this.iget(this._length-1-o),o>0&&(r+=", ")}if(e=rw[this.dtype],i+=$5(e,"{{data}}",r),i+=", ",a===0?i+="[]":i+="[ "+this._shape.join(", ")+" ]",i+=", ",i+="[ ",a===0)i+="0";else for(o=0;oa?a:r}Ys.exports=Xw});var ja=P(function(rQ,Gs){"use strict";var Ww=Ks();Gs.exports=Ww});var Zs=P(function(eQ,Js){"use strict";function Qw(r,a){var e=a+1;return r<0?(r+=e,r<0&&(r%=e,r!==0&&(r+=e)),r):(r>a&&(r-=e,r>a&&(r%=e)),r)}Js.exports=Qw});var Ea=P(function(aQ,Xs){"use strict";var Hw=Zs();Xs.exports=Hw});var Qs=P(function(iQ,Ws){"use strict";function $w(r,a){return r<0?(r+=a+1,r<0?-1:r):r>a?-1:r}Ws.exports=$w});var Ie=P(function(tQ,Hs){"use strict";var rS=Qs();Hs.exports=rS});var ro=P(function(vQ,$s){"use strict";var eS=require("@stdlib/array/base/assert/contains").factory,aS=Ce(),iS=eS(aS());$s.exports=iS});var Be=P(function(sQ,eo){"use strict";var tS=ro();eo.exports=tS});var io=P(function(oQ,ao){"use strict";var vS=ja(),sS=Ea(),oS=Ie(),nS=Be(),Ii=require("@stdlib/string/format"),uS={wrap:sS,clamp:vS,normalize:dS,throw:fS};function fS(r,a){if(r<0||r>a)throw new RangeError(Ii("invalid argument. Index must resolve to a value on the interval: [0, %d]. Value: `%d`.",a,r));return r}function dS(r,a){var e=oS(r,a);if(e<0||e>a)throw new RangeError(Ii("invalid argument. Index must resolve to a value on the interval: [0, %d]. Value: `%d`.",a,r));return e}function lS(r){if(!nS(r))throw new TypeError(Ii("invalid argument. First argument must be a recognized index mode. Value: `%s`.",r));return uS[r]}ao.exports=lS});var vo=P(function(nQ,to){"use strict";var cS=ja(),yS=Ea(),pS=Ie(),mS=require("@stdlib/string/format");function gS(r,a,e){var i;if(e==="clamp")return cS(r,a);if(e==="wrap")return yS(r,a);if(i=r,e==="normalize"&&(i=pS(i,a)),i<0||i>a)throw new RangeError(mS("invalid argument. Index must resolve to a value on the interval: [0, %d]. Value: `%d`.",a,r));return i}to.exports=gS});var Fe=P(function(uQ,oo){"use strict";var xS=require("@stdlib/utils/define-nonenumerable-read-only-property"),qS=io(),so=vo();xS(so,"factory",qS);oo.exports=so});var fo=P(function(fQ,uo){"use strict";var hS=require("@stdlib/assert/is-integer").isPrimitive,bS=Fe(),wS=te(),SS=require("@stdlib/string/format"),no=wS.prototype.iget;function jS(r){if(this._ndims>0){if(!hS(r))throw new TypeError(SS("invalid argument. Index must be an integer. Value: `%s`.",r));return r=bS(r,this._length-1,this._mode),no.call(this,r)}return no.call(this)}uo.exports=jS});var yo=P(function(dQ,co){"use strict";var ES=require("@stdlib/assert/is-integer").isPrimitive,_S=Fe(),OS=te(),TS=require("@stdlib/string/format"),lo=OS.prototype.iset;function IS(r,a){if(this._flags.READONLY)throw new Error("invalid invocation. Cannot write to a read-only array.");if(this._ndims>0){if(!ES(r))throw new TypeError(TS("invalid argument. Index must be an integer. Value: `%s`.",r));r=_S(r,this._length-1,this._mode),lo.call(this,r,a)}else lo.call(this,r);return this}co.exports=IS});var go=P(function(lQ,mo){"use strict";var kS=require("@stdlib/assert/is-integer").isPrimitive,NS=Fe(),po=require("@stdlib/string/format");function AS(){var r,a,e,i;if(arguments.length!==this._ndims)throw new RangeError(po("invalid arguments. Number of indices must match the number of dimensions. ndims: `%u`. nargs: `%u`.",this._ndims,arguments.length));for(r=this._offset,e=this._submode.length,i=0;i0))throw new TypeError(le("invalid argument. Third argument must be an array-like object containing nonnegative integers. Value: `%s`.",e));if(s=e.length,s>Io)throw new RangeError(le("invalid argument. Number of dimensions must not exceed %u due to stack limits. Value: `%u`.",Io,s));if(!US(i))throw new TypeError(le("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(le("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(le("invalid argument. Fourth argument must contain a single element equal to 0. Value: `%d`.",i[0]))}if(!FS(v))throw new TypeError(le("invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.",v));if(!YS(t))throw new TypeError(le("invalid argument. Sixth argument must be a supported order. Value: `%s`.",t));if(s>0&&!GS(a.length,e,i,v)&&JS(e)>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=e8,u.readonly=a8,arguments.length>6&&(f=r8(u,o),f))throw f;return this._mode=u.mode,u.submode===void 0&&(u.submode=[this._mode]),this._submode=u.submode,n=To(e,s),d=To(i,s||1),ko.call(this,r,a,n,d,v,t),this._flags.READONLY=u.readonly,this}XS(ce,ko);ta(ce,"name","ndarray");ta(ce.prototype,"get",HS);ta(ce.prototype,"iget",WS);ta(ce.prototype,"set",$S);ta(ce.prototype,"iset",QS);No.exports=ce});var ye=P(function(gQ,Ro){"use strict";var i8=Ao();Ro.exports=i8});var Do=P(function(xQ,t8){t8.exports=["none","equiv","safe","mostly-safe","same-kind","unsafe"]});var Co=P(function(qQ,zo){"use strict";var v8=Do();function s8(){return v8.slice()}zo.exports=s8});var Vo=P(function(hQ,Po){"use strict";function o8(){return{none:0,equiv:1,safe:2,"mostly-safe":3,"same-kind":4,unsafe:5}}Po.exports=o8});var Ni=P(function(bQ,Mo){"use strict";var n8=require("@stdlib/utils/define-nonenumerable-read-only-property"),Lo=Co(),u8=Vo();n8(Lo,"enum",u8);Mo.exports=Lo});var Uo=P(function(wQ,Fo){"use strict";var f8=Ni(),Bo=f8(),d8=Bo.length;function l8(r){var a;for(a=0;a0}sn.exports=C8});var Ia=P(function(DQ,nn){"use strict";var P8=on();nn.exports=P8});var un=P(function(zQ,V8){V8.exports={float64:{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},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:0,int8:0,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:0,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:0,uint8:0,uint8c:0,complex128:1,complex64:0,binary:0,generic:1},uint16:{float64:1,float32:1,int32:1,int16:0,int8:0,uint32:1,uint16:1,uint8:0,uint8c:0,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:1},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:1},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 ln=P(function(CQ,dn){"use strict";var fn=require("@stdlib/utils/keys"),L8=require("@stdlib/assert/has-own-property"),M8=ve(),Na=un(),ka;function B8(){var r,a,e,i,v,t,o,s,u;for(e={},r=fn(Na),a=r.length,u=0;u0}yn.exports=J8});var Aa=P(function(LQ,mn){"use strict";var Z8=pn();mn.exports=Z8});var gn=P(function(MQ,X8){X8.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 hn=P(function(BQ,qn){"use strict";var xn=require("@stdlib/utils/keys"),W8=require("@stdlib/assert/has-own-property"),Q8=ve(),Da=gn(),Ra;function H8(){var r,a,e,i,v,t,o,s,u;for(e={},r=xn(Da),a=r.length,u=0;u0}wn.exports=tj});var Ci=P(function(YQ,jn){"use strict";var vj=Sn();jn.exports=vj});var _n=P(function(KQ,En){"use strict";var sj=Ia(),oj=Aa(),nj=Ci();function uj(r,a,e){return e==="unsafe"||r===a?!0:e==="none"||e==="equiv"?!1:e==="safe"?sj(r,a):e==="mostly-safe"?oj(r,a):nj(r,a)}En.exports=uj});var Pi=P(function(GQ,On){"use strict";var fj=_n();On.exports=fj});var In=P(function(JQ,Tn){"use strict";var dj=require("@stdlib/buffer/ctor"),lj=require("@stdlib/array/float64"),cj=require("@stdlib/array/float32"),yj=require("@stdlib/array/int16"),pj=require("@stdlib/array/int32"),mj=require("@stdlib/array/int8"),gj=require("@stdlib/array/uint16"),xj=require("@stdlib/array/uint32"),qj=require("@stdlib/array/uint8"),hj=require("@stdlib/array/uint8c"),bj=require("@stdlib/array/complex64"),wj=require("@stdlib/array/complex128"),Sj={binary:dj,float64:lj,float32:cj,generic:Array,int16:yj,int32:pj,int8:mj,uint16:gj,uint32:xj,uint8:qj,uint8c:hj,complex64:bj,complex128:wj};Tn.exports=Sj});var Nn=P(function(ZQ,kn){"use strict";var jj=In();function Ej(r){return jj[r]||null}kn.exports=Ej});var sa=P(function(XQ,An){"use strict";var _j=Nn();An.exports=_j});var Dn=P(function(WQ,Rn){"use strict";function Oj(r){var a;for(a=0;a=0&&r.length=NE(a)}Uu.exports=AE});var Gu=P(function(OH,Ku){"use strict";var RE=Yu();Ku.exports=RE});var Xu=P(function(TH,Zu){"use strict";var Ju=require("@stdlib/math/base/special/abs");function DE(r){var a,e,i,v;if(a=r.length,a===0)return!1;for(e=Ju(r[0]),v=1;ve)return!1;e=i}return!0}Nf.exports=b_});var Gi=P(function(QH,Rf){"use strict";var w_=Af();Rf.exports=w_});var zf=P(function(HH,Df){"use strict";var S_=oa(),j_=de(),E_=Gi();function __(r,a,e){return j_(a)!==0&&E_(a)&&S_(r,a,e)}Df.exports=__});var Pf=P(function($H,Cf){"use strict";var O_=zf();Cf.exports=O_});var Lf=P(function(r$,Vf){"use strict";var T_=require("@stdlib/array/base/assert/contains").factory,I_=Kr(),k_=T_(I_("signed_integer"));Vf.exports=k_});var Ba=P(function(e$,Mf){"use strict";var N_=Lf();Mf.exports=N_});var Ff=P(function(a$,Bf){"use strict";var A_=require("@stdlib/array/base/assert/contains").factory,R_=Kr(),D_=A_(R_("unsigned_integer"));Bf.exports=D_});var Fa=P(function(i$,Uf){"use strict";var z_=Ff();Uf.exports=z_});var Kf=P(function(t$,Yf){"use strict";var Vr=require("@stdlib/utils/define-read-only-property"),Pr={};Vr(Pr,"isAllowedDataTypeCast",Pi());Vr(Pr,"isBufferLengthCompatible",ji());Vr(Pr,"isBufferLengthCompatibleShape",Gu());Vr(Pr,"isCastingMode",Ai());Vr(Pr,"isColumnMajor",Fi());Vr(Pr,"isColumnMajorContiguous",tf());Vr(Pr,"isComplexFloatingPointDataType",na());Vr(Pr,"isContiguous",df());Vr(Pr,"isDataType",Me());Vr(Pr,"isFloatingPointDataType",La());Vr(Pr,"isIndexMode",Be());Vr(Pr,"isIntegerDataType",Ui());Vr(Pr,"isMostlySafeDataTypeCast",Aa());Vr(Pr,"isNumericDataType",Yi());Vr(Pr,"isOrder",ae());Vr(Pr,"isReadOnly",re());Vr(Pr,"isRealDataType",Ma());Vr(Pr,"isRealFloatingPointDataType",Ki());Vr(Pr,"isRowMajor",Gi());Vr(Pr,"isRowMajorContiguous",Pf());Vr(Pr,"isSafeDataTypeCast",Ia());Vr(Pr,"isSameKindDataTypeCast",Ci());Vr(Pr,"isSignedIntegerDataType",Ba());Vr(Pr,"isSingleSegmentCompatible",oa());Vr(Pr,"isUnsignedIntegerDataType",Fa());Yf.exports=Pr});var Jf=P(function(v$,Gf){"use strict";function C_(r){return r.dtype}Gf.exports=C_});var Xr=P(function(s$,Zf){"use strict";var P_=Jf();Zf.exports=P_});var Wf=P(function(o$,Xf){"use strict";var V_=require("@stdlib/array/base/copy-indexed");function L_(r,a){var e=r.shape;return a?V_(e):e}Xf.exports=L_});var Jr=P(function(n$,Qf){"use strict";var M_=Wf();Qf.exports=M_});var $f=P(function(u$,Hf){"use strict";var B_=Gr(),F_=require("@stdlib/array/base/copy-indexed"),U_="row-major";function Y_(r,a){var e,i,v;return v=r.strides,typeof v!="object"||v===null?(i=r.shape,i.length===0?[0]:(e=r.order,typeof e!="string"&&(e=U_),B_(i,e))):a?F_(v):v}Hf.exports=Y_});var ee=P(function(f$,rd){"use strict";var K_=$f();rd.exports=K_});var ad=P(function(d$,ed){"use strict";var G_=Zr();function J_(r){var a,e,i;return i=r.offset,typeof i=="number"?i:(e=r.shape,e.length===0||(a=r.strides,typeof a!="object"||a===null)?0:G_(e,a))}ed.exports=J_});var pe=P(function(l$,id){"use strict";var Z_=ad();id.exports=Z_});var vd=P(function(c$,td){"use strict";var X_=De(),Ji="row-major",W_="column-major";function Q_(r){var a,e;return e=r.order,typeof e=="string"?e:(a=r.strides,typeof a!="object"||a===null||(e=X_(a),e===1||e===3)?Ji:e===2?W_:r.shape.length===0?Ji:null)}td.exports=Q_});var Wr=P(function(y$,sd){"use strict";var H_=vd();sd.exports=H_});var nd=P(function(p$,od){"use strict";function $_(r){return r.data}od.exports=$_});var we=P(function(m$,ud){"use strict";var rO=nd();ud.exports=rO});var dd=P(function(g$,fd){"use strict";var eO=require("@stdlib/array/base/assert/is-accessor-array"),aO=require("@stdlib/array/base/accessor-getter"),iO=require("@stdlib/array/base/accessor-setter"),tO=require("@stdlib/array/base/getter"),vO=require("@stdlib/array/base/setter"),sO=zr(),oO=Xr(),nO=Jr(),uO=ee(),fO=pe(),dO=Wr(),lO=we();function cO(r){var a,e,i,v;return a=lO(r),i=nO(r,!0),v=oO(r),e=eO(a),{ref:r,dtype:v,data:a,length:sO(i),shape:i,strides:uO(r,!0),offset:fO(r),order:dO(r),accessorProtocol:e,accessors:e?[aO(v),iO(v)]:[tO(v),vO(v)]}}fd.exports=cO});var Ge=P(function(x$,ld){"use strict";var yO=dd();ld.exports=yO});var yd=P(function(q$,cd){"use strict";function pO(r,a){var e,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<=e));)r[o+1]=n,a[s+1]=a[s],o-=1,s-=1;r[o+1]=u,a[s+1]=f,v+=1,t+=1}}cd.exports=pO});var gd=P(function(h$,md){"use strict";var mO=require("@stdlib/array/base/zero-to"),gO=require("@stdlib/array/base/copy-indexed"),pd=require("@stdlib/array/base/take-indexed"),xO=yd();function qO(r,a,e){var i;return i=mO(r.length),a=gO(a),xO(a,i),r=pd(r,i),e=pd(e,i),{sh:r,sx:a,sy:e}}md.exports=qO});var Ir=P(function(b$,xd){"use strict";var hO=gd();xd.exports=hO});var hd=P(function(w$,qd){"use strict";var bO={BLOCK_SIZE_IN_BYTES:64,BLOCK_SIZE_IN_ELEMENTS:8};qd.exports=bO});var Sd=P(function(S$,wd){"use strict";var bd=_e(),Zi=hd();function wO(r,a){var e,i;return e=bd(r),i=bd(a),e===null||i===null?Zi.BLOCK_SIZE_IN_ELEMENTS:e>i?Zi.BLOCK_SIZE_IN_BYTES/e|0:Zi.BLOCK_SIZE_IN_BYTES/i|0}wd.exports=wO});var kr=P(function(j$,jd){"use strict";var SO=Sd();jd.exports=SO});var _d=P(function(E$,Ed){"use strict";var jO=Ir(),EO=kr();function _O(r,a){var e,i,v,t,o,s,u,f,n,d,g,b,y,l,x,m,w,T,q,j,E,c,h,p,S;for(S=jO(r.shape,r.strides,a.strides),b=S.sh,x=S.sx,m=S.sy,e=EO(r.dtype,a.dtype),w=r.offset,T=a.offset,i=r.data,v=a.data,s=x[0],f=m[0],t=r.accessors[0],o=a.accessors[1],p=b[1];p>0;)for(p0;)for(h0;)for(I0;)for(R0;)for(A0;)for(M0;)for(L0;)for(V0;)for(C0;)for(J0;)for(Y0;)for(G0;)for(K0;)for(U0;)for(er0;)for(H0;)for($0;)for(X0;)for(Q0;)for(W0;)for(or0;)for(sr0;)for(vr0;)for(ar0;)for(tr0;)for(rr0;)for(ir0;)for(yr0;)for(lr0;)for(cr0;)for(fr0;)for(dr0;)for(ur0;)for(nr0;)for(or0;)for(br0;)for(mr0;)for(qr0;)for(xr0;)for(hr0;)for(gr0;)for(pr0;)for(yr0;)for(lr0;)for(Dr0;)for(Nr0;)for(Tr0;)for(Or0;)for(_r0;)for(Er0;)for(jr0;)for(br0;)for(mr0;)for(qr0;)for(c0;)for(E0;)for(A0;)for(O0;)for(N0;)for(V0;)for(C0;)for(k0;)for(z0;)for(G0;)for(K0;)for(U0;)for(F0;)for(B0;)for($0;)for(X0;)for(Q0;)for(W0;)for(Z0;)for(J0;)for(vr0;)for(ar0;)for(tr0;)for(rr0;)for(ir0;)for(er0;)for(H0;)for(cr0;)for(fr0;)for(dr0;)for(ur0;)for(nr0;)for(or0;)for(sr0;)for(vr0;)for(qr0;)for(xr0;)for(hr0;)for(gr0;)for(pr0;)for(yr0;)for(lr0;)for(cr0;)for(fr0;)for(Tr0;)for(Or0;)for(_r0;)for(Er0;)for(jr0;)for(br0;)for(mr0;)for(qr0;)for(xr0;)for(hr=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(t==="normalize"&&v<0&&(v+=s),v<0||v>=s)throw new RangeError(zT("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",s,v));if(u=e,i==="column-major"){for(n=0;n=0;n--)f=v%r[n],v-=f,v/=r[n],u+=f*a[n];return u}I0.exports=CT});var me=P(function(err,N0){"use strict";var PT=k0();N0.exports=PT});var z0=P(function(arr,D0){"use strict";var VT=zr(),A0=me(),R0="throw";function LT(r,a){var e,i,v,t,o,s,u,f,n,d,g,b,y,l,x;for(f=r.shape,o=VT(f),e=r.data,i=a.data,n=r.strides,d=a.strides,g=r.offset,b=a.offset,v=r.order,t=a.order,s=r.accessors[0],u=a.accessors[1],x=0;x=0&&(n=r[o],i=n<0?-n:n,!(i<=e));)r[o+1]=n,a[s+1]=a[s],o-=1,s-=1;r[o+1]=u,a[s+1]=f,v+=1,t+=1}}pl.exports=XI});var ql=P(function(xrr,xl){"use strict";var WI=require("@stdlib/array/base/zero-to"),QI=require("@stdlib/array/base/copy-indexed"),Ua=require("@stdlib/array/base/take-indexed"),HI=require("@stdlib/array/base/filled"),Wi=De(),$I=ml(),gl=3;function rk(r,a,e,i){var v,t,o,s,u,f,n,d,g,b;if(v=WI(r.length),f=Wi(a),n=Wi(e),d=Wi(i),t=HI([],4),t[f].push(a),t[n].push(e),t[d].push(i),o=t[0].length,o===gl)u=a;else if(o===gl-1){for(g=1;g<4;g++)if(t[g].length){u=t[g][0];break}}else{for(b=0,g=1;g<4;g++)s=t[g].length,s>=o&&(o=s,b=g);u=t[b][0]}return u=QI(u),$I(u,v),r=Ua(r,v),a=a===u?u:Ua(a,v),e=e===u?u:Ua(e,v),i=i===u?u:Ua(i,v),{sh:r,sx:a,sy:e,sz:i}}xl.exports=rk});var bl=P(function(qrr,hl){"use strict";var ek=ql();hl.exports=ek});var Sl=P(function(hrr,wl){"use strict";var ak={BLOCK_SIZE_IN_BYTES:64,BLOCK_SIZE_IN_ELEMENTS:8};wl.exports=ak});var El=P(function(brr,jl){"use strict";var Qi=_e(),Ya=Sl();function ik(r,a,e){var i,v,t;return i=Qi(r),v=Qi(a),t=Qi(e),i===null||v===null||t===null?Ya.BLOCK_SIZE_IN_ELEMENTS:i>v&&i>t?Ya.BLOCK_SIZE_IN_BYTES/i|0:v>t?Ya.BLOCK_SIZE_IN_BYTES/v|0:Ya.BLOCK_SIZE_IN_BYTES/t|0}jl.exports=ik});var Ol=P(function(wrr,_l){"use strict";var tk=El();_l.exports=tk});var kl=P(function(Srr,Il){"use strict";var vk=require("@stdlib/string/format"),Ka=require("@stdlib/math/base/special/trunc"),Tl=require("@stdlib/math/base/special/abs");function sk(r,a,e,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(t==="normalize"&&v<0&&(v+=s),v<0||v>=s)throw new RangeError(vk("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=a[d],n<0?(f=Ka(v/n),v-=f*n,f+=r[d]-1):(f=Ka(v/n),v-=f*n),u+=f*Tl(n);return u}for(d=0;d=0;f--)if(n=s-o+f,!(n<0)){if(u=v[n],i=a[f],i!==0&&if&&(f=a[n]);for(n=0;n=0;){for(t=a[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}e[n]=i,n-=1}return e}Bl.exports=_k});var Yl=P(function(krr,Ul){"use strict";var Ok=Fl();Ul.exports=Ok});var Gl=P(function(Nrr,Kl){"use strict";var Tk=va(),Ik=za();function kk(r){var a=Ik(r);return a?Tk(a):null}Kl.exports=kk});var Zl=P(function(Arr,Jl){"use strict";var Nk=Gl();Jl.exports=Nk});var Wl=P(function(Rrr,Xl){"use strict";function Ak(){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"}}Xl.exports=Ak});var $l=P(function(Drr,Hl){"use strict";var Rk=ve(),Ql=Wl(),Hi;function Dk(r){return arguments.length===0?Ql():(Hi===void 0&&(Hi=Ql()),Hi[Rk(r)]||null)}Hl.exports=Dk});var $i=P(function(zrr,rc){"use strict";var zk=$l();rc.exports=zk});var tc=P(function(Crr,ic){"use strict";var ec=require("@stdlib/utils/object-inverse"),ac=$i(),rt;function Ck(r){return arguments.length===0?ec(ac()):(rt===void 0&&(rt=ec(ac())),rt[r]||null)}ic.exports=Ck});var sc=P(function(Prr,vc){"use strict";var Pk=tc();vc.exports=Pk});var nc=P(function(Vrr,oc){"use strict";function Vk(){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"}}oc.exports=Vk});var dc=P(function(Lrr,fc){"use strict";var Lk=ve(),uc=nc(),et;function Mk(r){return arguments.length===0?uc():(et===void 0&&(et=uc()),et[Lk(r)]||null)}fc.exports=Mk});var cc=P(function(Mrr,lc){"use strict";var Bk=dc();lc.exports=Bk});var pc=P(function(Brr,yc){"use strict";var Fk=_a(),Uk=va();function Yk(r){var a=typeof r;return a==="number"?Fk(r)?r:null:a==="string"?Uk(r):null}yc.exports=Yk});var Ja=P(function(Frr,mc){"use strict";var Kk=pc();mc.exports=Kk});var gc=P(function(Urr,Gk){Gk.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 qc=P(function(Yrr,xc){"use strict";var Jk=ve(),Zk=gc();function Xk(r){return Zk[Jk(r)]||null}xc.exports=Xk});var bc=P(function(Krr,hc){"use strict";var Wk=qc();hc.exports=Wk});var jc=P(function(Grr,Sc){"use strict";var Qk=require("@stdlib/assert/is-array-like-object"),wc=require("@stdlib/assert/is-nonnegative-integer").isPrimitive,Hk=ve(),at=require("@stdlib/string/format");function $k(r,a,e){var i,v,t,o,s,u,f,n;if(!Qk(r))throw new TypeError(at("invalid argument. First argument must be an array-like object. Value: `%s`.",r));if(!wc(a))throw new TypeError(at("invalid argument. Second argument must be a nonnegative integer. Value: `%s`.",a));if(!wc(e))throw new TypeError(at("invalid argument. Third argument must be a nonnegative integer. Value: `%s`.",e));if(i=r.length,i===0)throw new RangeError("invalid argument. First argument must contain at least one element.");if(s=a+e,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*a,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=tN(a),o=eN(a,e)):(t=1,o=[0]),r==="binary"?v=sN(t):v=vN(t,r),new iN(r,v,a,o,aN(a,o),e)}_c.exports=oN});var Ic=P(function(Xrr,Tc){"use strict";var nN=Oc();Tc.exports=nN});var Nc=P(function(Wrr,kc){"use strict";var uN=Gr(),fN=Zr(),dN=zr(),lN=Xr(),cN=Jr(),yN=Wr(),pN=require("@stdlib/array/empty"),mN=require("@stdlib/buffer/alloc-unsafe");function gN(r){var a,e,i,v,t,o,s;return s=lN(r),t=cN(r,!0),v=yN(r),a=t.length,a>0?(e=dN(t),o=uN(t,v)):(e=1,o=[0]),s==="binary"?i=mN(e):i=pN(e,s),new r.constructor(s,i,t,o,fN(t,o),v)}kc.exports=gN});var Rc=P(function(Qrr,Ac){"use strict";var xN=Nc();Ac.exports=xN});var Lc=P(function(Hrr,Vc){"use strict";var qN=re(),Dc=Xr(),hN=Jr(),bN=ee(),zc=pe(),wN=Wr(),Cc=we(),Pc=require("@stdlib/string/format");function SN(r,a){var e,i,v,t,o,s,u;if(t=hN(r,!1),o=bN(r,!1),v=wN(r),s=t.length,e=[],i=[],a<0){if(a<-s-1)throw new RangeError(Pc("invalid argument. Specified axis is out-of-bounds. Must be on the interval: [-%u-1, %u]. Value: `%d`.",s,s,a));a+=s+1}else if(a>s)throw new RangeError(Pc("invalid argument. Specified axis is out-of-bounds. Must be on the interval: [-%u-1, %u]. Value: `%d`.",s,s,a));if(a===0)for(i.push(1),e.push(o[0]),u=0;u0&&(g=NN(g.length))}else g=Xc(b);return Wc(g)===0?LN(d,o,tt(g,f),u,!i):(t=PN(b,v,t),g=tt(g,f),g.length===0?new d(o,vt(r),[],[0],t,u,{readonly:!i}):(v=VN(b,v,f),new d(o,vt(r),g,v,t,u,{readonly:!i})))}Hc.exports=MN});var Br=P(function(ter,r1){"use strict";var BN=$c();r1.exports=BN});var a1=P(function(ver,e1){"use strict";function FN(r){var a=r.ndims;return typeof a=="number"?a:r.shape.length}e1.exports=FN});var ge=P(function(ser,i1){"use strict";var UN=a1();i1.exports=UN});var v1=P(function(oer,t1){"use strict";var YN=require("@stdlib/slice/base/args2multislice"),KN=require("@stdlib/slice/ctor"),GN=Br(),JN=require("@stdlib/array/base/filled"),ZN=ge(),st=require("@stdlib/string/format");function XN(r,a,e){var i,v,t;if(v=ZN(r),v===0)throw new TypeError(st("invalid argument. First argument must be an ndarray having one or more dimensions. Number of dimensions: %d.",v));if(t=a,t<0){if(t+=v,t<0)throw new RangeError(st("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,a))}else if(t>=v)throw new RangeError(st("invalid argument. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.",v,a));return i=JN(null,v),i[t]=new KN(null,null,-1),GN(r,YN(i),!0,e)}t1.exports=XN});var Za=P(function(ner,s1){"use strict";var WN=v1();s1.exports=WN});var n1=P(function(uer,o1){"use strict";var QN=require("@stdlib/slice/multi"),HN=Za(),$N=Br(),rA=ge();function eA(r,a){return rA(r)===0?$N(r,new QN,!0,a):HN(r,-1,a)}o1.exports=eA});var f1=P(function(fer,u1){"use strict";var aA=n1();u1.exports=aA});var y1=P(function(der,c1){"use strict";var d1=require("@stdlib/slice/multi"),iA=Za(),l1=Br(),tA=ge();function vA(r,a){var e=tA(r);return e===0?l1(r,new d1,!0,a):e===1?l1(r,new d1(null),!0,a):iA(r,-2,a)}c1.exports=vA});var m1=P(function(ler,p1){"use strict";var sA=y1();p1.exports=sA});var x1=P(function(cer,g1){"use strict";var oA=require("@stdlib/array/base/assert/is-accessor-array"),nA=require("@stdlib/array/base/accessor-setter"),uA=require("@stdlib/array/base/setter"),fA=se(),dA=te(),lA=require("@stdlib/string/format");function cA(r,a,e){var i,v;if(i=fA(a,1),i===null)throw new TypeError(lA("invalid argument. Second argument must be a recognized data type. Value: `%s`.",a));return/^complex/.test(a)&&typeof r=="number"&&(r=[r,0]),oA(i)?v=nA(a):v=uA(a),v(i,0,r),new dA(a,i,[],[0],0,e)}g1.exports=cA});var h1=P(function(yer,q1){"use strict";var yA=x1();q1.exports=yA});var ot=P(function(per,b1){"use strict";var pA=require("@stdlib/string/format"),Xa=require("@stdlib/math/base/special/trunc");function mA(r,a,e,i,v,t,o){var s,u,f,n,d;for(s=r.length,u=1,d=0;d=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(t==="normalize"&&v<0&&(v+=u),v<0||v>=u)throw new RangeError(pA("invalid argument. Linear index must not exceed array dimensions. Number of array elements: `%u`. Value: `%d`.",u,v));if(e===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=a[d],n<0?(f=Xa(v/n),v-=f*n,o[d]=r[d]-1+f):(f=Xa(v/n),v-=f*n,o[d]=f);return o}for(d=0;d0&&(v+=a[t]*(r[t]-1))}return v}_1.exports=wA});var I1=P(function(qer,T1){"use strict";var SA=O1();T1.exports=SA});var A1=P(function(her,N1){"use strict";var k1=Ga(),jA=Jr();function EA(r,a){var e,i,v;if(i=a.length,e=jA(r,!1),e.length===i){for(v=0;vi;t--)v[t]=e[t];for(t=i;t>=0&&(o=(e[t]+1)%a[t],v[t]=o,!(o>0));t--);for(t-=1;t>=0;t--)v[t]=e[t];return v}function zA(r,a,e,i,v){var t,o;for(t=0;t0));t++);for(t+=1;t=t)return null;return a===RA?DA(t,r,e,i,v):zA(t,r,e,i,v)}U1.exports=CA});var K1=P(function(Oer,Y1){"use strict";var PA=require("@stdlib/array/base/zeros"),VA=ut();function LA(r,a,e,i){return VA(r,a,e,i,PA(r.length))}Y1.exports=LA});var ue=P(function(Ter,J1){"use strict";var MA=require("@stdlib/utils/define-nonenumerable-read-only-property"),G1=K1(),BA=ut();MA(G1,"assign",BA);J1.exports=G1});var X1=P(function(Ier,Z1){"use strict";function FA(r){var a,e;for(a=0,e=0;e=0&&(n=r[o],i=n<0?-n:n,!(i<=e));)r[o+1]=n,a[s+1]=a[s],o-=1,s-=1;r[o+1]=u,a[s+1]=f,v+=1,t+=1}}H1.exports=YA});var ey=P(function(Aer,ry){"use strict";var KA=require("@stdlib/array/base/zero-to"),GA=require("@stdlib/array/base/copy-indexed"),JA=require("@stdlib/array/base/take-indexed"),ZA=$1();function XA(r,a){var e;return e=KA(r.length),a=GA(a),ZA(a,e),r=JA(r,e),{sh:r,sx:a}}ry.exports=XA});var Fr=P(function(Rer,ay){"use strict";var WA=ey();ay.exports=WA});var ty=P(function(Der,iy){"use strict";var QA={BLOCK_SIZE_IN_BYTES:64,BLOCK_SIZE_IN_ELEMENTS:8};iy.exports=QA});var oy=P(function(zer,sy){"use strict";var HA=_e(),vy=ty();function $A(r){var a=HA(r);return a===null?vy.BLOCK_SIZE_IN_ELEMENTS:vy.BLOCK_SIZE_IN_BYTES/a|0}sy.exports=$A});var Ur=P(function(Cer,ny){"use strict";var rR=oy();ny.exports=rR});var fy=P(function(Per,uy){"use strict";var eR=Fr(),aR=Ur();function iR(r,a){var e,i,v,t,o,s,u,f,n,d,g,b,y,l,x,m,w;for(w=eR(r.shape,r.strides),u=w.sh,d=w.sx,e=aR(r.dtype),g=r.offset,i=r.data,t=d[0],v=r.accessors[1],m=u[1];m>0;)for(m0;)for(x0;)for(E0;)for(j0;)for(q0;)for(_0;)for(S0;)for(p0;)for(h0;)for(I0;)for(R0;)for(A0;)for(O0;)for(N0;)for(V0;)for(C0;)for(k0;)for(z0;)for(D0;)for(I0;)for(U0;)for(F0;)for(B0;)for(M0;)for(L0;)for(V0;)for(C0;)for(Z0;)for(J0;)for(Y0;)for(G0;)for(K0;)for(U0;)for(F0;)for(B0;)for(H0;)for($0;)for(X0;)for(Q0;)for(W0;)for(Z0;)for(J0;)for(Y0;)for(G0;)for(ar0;)for(tr0;)for(rr0;)for(ir0;)for(er0;)for(H0;)for($0;)for(X0;)for(Q0;)for(W0;)for(x0;)for(l0;)for(j0;)for(q0;)for(T0;)for(S0;)for(p0;)for(h0;)for(c0;)for(R0;)for(A0;)for(O0;)for(N0;)for(_0;)for(C0;)for(k0;)for(z0;)for(D0;)for(I0;)for(R0;)for(F0;)for(B0;)for(M0;)for(L0;)for(V