diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/README.md b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/README.md new file mode 100644 index 000000000000..4c35ebf8a093 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/README.md @@ -0,0 +1,141 @@ + + +# toReversedDimensions + +> Return a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toReversedDimensions = require( '@stdlib/ndarray/base/to-reversed-dimensions' ); +``` + +#### toReversedDimensions( x, dims ) + +Returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = toReversedDimensions( x, [ 0, 1 ] ); +// returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **dims**: dimension indices along which to reverse elements. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var toReversedDimensions = require( '@stdlib/ndarray/base/to-reversed-dimensions' ); + +// Create a 3x2 matrix: +var x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] ); + +// Reverse the order of the first axis: +var y = toReversedDimensions( x, [ 0 ] ); +var arr = ndarray2array( y ); +// returns [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ] + +// Reverse the order of the second axis: +y = toReversedDimensions( x, [ 1 ] ); +arr = ndarray2array( y ); +// returns [ [ 2, 1 ], [ 4, 3 ], [ 6, 5 ] ] + +// Reverse the order of all axes: +y = toReversedDimensions( x, [ 0, 1 ] ); +arr = ndarray2array( y ); +// returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] + +// Supports negative dimension indices: +y = toReversedDimensions( x, [ -2, -1 ] ); +arr = ndarray2array( y ); +// returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/benchmark/benchmark.js new file mode 100644 index 000000000000..9e3dd07f57e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/benchmark/benchmark.js @@ -0,0 +1,332 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var baseEmpty = require( '@stdlib/ndarray/base/empty' ); +var empty = require( '@stdlib/ndarray/empty' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var toReversedDimensions = require( './../lib' ); + + +// MAIN // + +bench( format( '%s::base:ndims=1', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::non-base:ndims=1', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2 ], { 'dtype': 'float64' } ), + empty( [ 2 ], { 'dtype': 'float32' } ), + empty( [ 2 ], { 'dtype': 'int32' } ), + empty( [ 2 ], { 'dtype': 'complex128' } ), + empty( [ 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:ndims=2', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::non-base:ndims=2', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:ndims=3,dims=[0,1,2]', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1, 2 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::non-base:ndims=3,dims=[0,1,2]', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1, 2 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:ndims=4', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1, 2, 3 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::non-base:ndims=4', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1, 2, 3 ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::base:ndims=5', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1, 2, 3, 4 ] ); // eslint-disable-line max-len + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::non-base:ndims=5', pkg ), function benchmark( b ) { + var values; + var out; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toReversedDimensions( values[ i%values.length ], [ 0, 1, 2, 3, 4 ] ); // eslint-disable-line max-len + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/repl.txt new file mode 100644 index 000000000000..c4d7375366e5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( x, dims ) + Returns a new ndarray where the order of elements of an input ndarray along + specified dimensions is reversed. + + Parameters + ---------- + x: ndarray + Input array. + + dims: ArrayLikeObject + Dimension indices along which to reverse elements. If provided an + integer less than zero, the dimension index is resolved relative to the + last dimension, with the last dimension corresponding to the value `-1`. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + [ [ 1, 2 ], [ 3, 4 ] ] + > var y = {{alias}}( x, [ 0, 1 ] ) + [ [ 4, 3 ], [ 2, 1 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/types/index.d.ts new file mode 100644 index 000000000000..909e8d3d4494 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/types/index.d.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 { typedndarray } from '@stdlib/types/ndarray'; +import { Collection } from '@stdlib/types/array'; + +/** +* Returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. +* +* @param x - input array +* @param dims - indices of dimensions to reverse +* @returns output array +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversedDimensions( x, [ 0, 1 ] ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +*/ +declare function toReversedDimensions = typedndarray>( x: U, dims: Collection ): U; + + +// EXPORTS // + +export = toReversedDimensions; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/types/test.ts new file mode 100644 index 000000000000..0af8a27cb062 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/docs/types/test.ts @@ -0,0 +1,76 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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( '@stdlib/ndarray/base/zeros' ); +import toReversedDimensions = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + toReversedDimensions( zeros( 'float64', sh, ord ), [ 0 ] ); // $ExpectType float64ndarray + toReversedDimensions( zeros( 'float32', sh, ord ), [ 0 ] ); // $ExpectType float32ndarray + toReversedDimensions( zeros( 'complex128', sh, ord ), [ 0 ] ); // $ExpectType complex128ndarray + toReversedDimensions( zeros( 'complex64', sh, ord ), [ 0 ] ); // $ExpectType complex64ndarray + toReversedDimensions( zeros( 'int32', sh, ord ), [ 0 ] ); // $ExpectType int32ndarray + toReversedDimensions( zeros( 'int16', sh, ord ), [ 0 ] ); // $ExpectType int16ndarray + toReversedDimensions( zeros( 'int8', sh, ord ), [ 0 ] ); // $ExpectType int8ndarray + toReversedDimensions( zeros( 'uint32', sh, ord ), [ 0 ] ); // $ExpectType uint32ndarray + toReversedDimensions( zeros( 'uint16', sh, ord ), [ 0 ] ); // $ExpectType uint16ndarray + toReversedDimensions( zeros( 'uint8', sh, ord ), [ 0 ] ); // $ExpectType uint8ndarray + toReversedDimensions( zeros( 'uint8c', sh, ord ), [ 0 ] ); // $ExpectType uint8cndarray + toReversedDimensions( zeros( 'generic', sh, ord ), [ 0 ] ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + toReversedDimensions( '10', [ 0 ] ); // $ExpectError + toReversedDimensions( 10, [ 0 ] ); // $ExpectError + toReversedDimensions( false, [ 0 ] ); // $ExpectError + toReversedDimensions( true, [ 0 ] ); // $ExpectError + toReversedDimensions( null, [ 0 ] ); // $ExpectError + toReversedDimensions( void 0, [ 0 ] ); // $ExpectError + toReversedDimensions( [], [ 0 ] ); // $ExpectError + toReversedDimensions( {}, [ 0 ] ); // $ExpectError + toReversedDimensions( ( x: number ): number => x, [ 0 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a collection of numbers... +{ + const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + toReversedDimensions( x, '10' ); // $ExpectError + toReversedDimensions( x, 10 ); // $ExpectError + toReversedDimensions( x, false ); // $ExpectError + toReversedDimensions( x, true ); // $ExpectError + toReversedDimensions( x, null ); // $ExpectError + toReversedDimensions( x, void 0 ); // $ExpectError + toReversedDimensions( x, {} ); // $ExpectError + toReversedDimensions( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + toReversedDimensions(); // $ExpectError + toReversedDimensions( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError + toReversedDimensions( zeros( 'float64', [ 2, 2 ], 'row-major' ), [ 0 ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/examples/index.js new file mode 100644 index 000000000000..4939d4e441cb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/examples/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var toReversedDimensions = require( './../lib' ); + +// Create a 3x2 matrix: +var x = array( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] ); + +// Reverse the order of the first axis: +var y = toReversedDimensions( x, [ 0 ] ); +console.log( ndarray2array( y ) ); +// => [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ] + +// Reverse the order of the second axis: +y = toReversedDimensions( x, [ 1 ] ); +console.log( ndarray2array( y ) ); +// => [ [ 2, 1 ], [ 4, 3 ], [ 6, 5 ] ] + +// Reverse the order of all axes: +y = toReversedDimensions( x, [ 0, 1 ] ); +console.log( ndarray2array( y ) ); +// => [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] + +// Supports negative dimension indices: +y = toReversedDimensions( x, [ -2, -1 ] ); +console.log( ndarray2array( y ) ); +// => [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/lib/index.js new file mode 100644 index 000000000000..d4d8da84c2c4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. +* +* @module @stdlib/ndarray/base/to-reversed-dimensions +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var toReversedDimensions = require( '@stdlib/ndarray/base/to-reversed-dimensions' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversedDimensions( x, [ 0, 1 ] ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/lib/main.js new file mode 100644 index 000000000000..6296395f257d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/lib/main.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 emptyLike = require( '@stdlib/ndarray/base/empty-like' ); +var reverseDimensions = require( '@stdlib/ndarray/base/reverse-dimensions' ); +var assign = require( '@stdlib/ndarray/base/assign' ); + + +// MAIN // + +/** +* Returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed. +* +* @param {ndarray} x - input array +* @param {IntegerArray} dims - indices of dimensions to reverse +* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {RangeError} dimension index exceeds the number of dimensions +* @throws {Error} must provide unique dimension indices +* @returns {ndarray} output array +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversedDimensions( x, [ 0, 1 ] ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +*/ +function toReversedDimensions( x, dims ) { + var out; + var xr; + + // Create a reversed view of the input ndarray: + xr = reverseDimensions( x, dims, false ); + + // Create an output ndarray having the same shape and data type as the reversed view: + out = emptyLike( xr ); + + // Assign the elements of the reversed view to the output ndarray: + assign( [ xr, out ] ); + + return out; +} + + +// EXPORTS // + +module.exports = toReversedDimensions; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/package.json b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/package.json new file mode 100644 index 000000000000..8003292dc492 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/to-reversed-dimensions", + "version": "0.0.0", + "description": "Return a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed.", + "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", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "reverse", + "dimensions", + "flip", + "numpy.flip" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/test/test.js new file mode 100644 index 000000000000..6cb78a8e3bf5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimensions/test/test.js @@ -0,0 +1,444 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var base = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var zeros = require( '@stdlib/ndarray/zeros' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var toReversedDimensions = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toReversedDimensions, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a zero-dimensional array', function test( t ) { + var values; + var i; + + values = [ + zeros( [] ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error' ); + } + t.end(); + + function badValue( x ) { + return function badValue() { + toReversedDimensions( x, [ 0 ] ); + }; + } +}); + +tape( 'the function throws an error if provided out-of-bounds dimension indices', function test( t ) { + var values; + var i; + + values = [ + zeros( [ 1 ] ), + zeros( [ 1, 1 ] ), + zeros( [ 1, 1, 1 ] ), + zeros( [ 1, 1, 1, 1 ] ) + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ], [ 10 ] ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); + t.throws( badValue( values[ i ], [ -10 ] ), RangeError, 'throws an error when provided ' + values[ i ].shape.join( 'x' ) ); + } + t.end(); + + function badValue( x, dims ) { + return function badValue() { + toReversedDimensions( x, dims ); + }; + } +}); + +tape( 'the function throws an error if provided duplicate dimension indices', function test( t ) { + var values; + var x; + var i; + + x = zeros( [ 2, 2, 2 ] ); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 2, 2 ], + [ 0, -3 ], + [ -2, 1 ], + [ -1, 2 ] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices ['+values[ i ]+']' ); + } + t.end(); + + function badValue( dims ) { + return function badValue() { + toReversedDimensions( x, dims ); + }; + } +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=float64, base, row-major)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + t.notEqual( arr, x, 'returns expected value' ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=float64, base, column-major)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + + // In column-major with strides [1,2], x = [ [ 1.0, 3.0, 5.0 ], [ 2.0, 4.0, 6.0 ] ] + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 6.0, 4.0, 2.0 ], [ 5.0, 3.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=float64, non-base)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'float64' + }); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=float32)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=complex128, base)', function test( t ) { + var arr; + var buf; + var v; + var x; + + buf = new Complex128Array([ + 1.0, + 1.0, + 2.0, + 2.0, + 3.0, + 3.0, + 4.0, + 4.0 + ]); + x = new base( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + // Original matrix: [ [ 1+1i, 2+2i ], [ 3+3i, 4+4i ] ] + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + + v = arr.get( 0, 0 ); + t.strictEqual( real( v ), 4.0, 'returns expected value' ); + t.strictEqual( imag( v ), 4.0, 'returns expected value' ); + v = arr.get( 0, 1 ); + t.strictEqual( real( v ), 3.0, 'returns expected value' ); + t.strictEqual( imag( v ), 3.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( real( v ), 2.0, 'returns expected value' ); + t.strictEqual( imag( v ), 2.0, 'returns expected value' ); + v = arr.get( 1, 1 ); + t.strictEqual( real( v ), 1.0, 'returns expected value' ); + t.strictEqual( imag( v ), 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=complex64, base)', function test( t ) { + var arr; + var buf; + var v; + var x; + + buf = new Complex64Array([ + 1.0, + 1.0, + 2.0, + 2.0, + 3.0, + 3.0, + 4.0, + 4.0 + ]); + x = new base( 'complex64', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + + v = arr.get( 0, 0 ); + t.strictEqual( realf( v ), 4.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); + v = arr.get( 0, 1 ); + t.strictEqual( realf( v ), 3.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 3.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( realf( v ), 2.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); + v = arr.get( 1, 1 ); + t.strictEqual( realf( v ), 1.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along specified dimensions is reversed (dtype=generic)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = [ 1, 2, 3, 4, 5, 6 ]; + x = new base( 'generic', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + expected = [ [ 6, 5, 4 ], [ 3, 2, 1 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports reversing a single dimension', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + arr = toReversedDimensions( x, [ 0 ] ); + expected = [ [ 4.0, 5.0, 6.0 ], [ 1.0, 2.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + arr = toReversedDimensions( x, [ 1 ] ); + expected = [ [ 3.0, 2.0, 1.0 ], [ 6.0, 5.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative dimension indices', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + // dims=[-2,-1] should be equivalent to dims=[0,1]: + arr = toReversedDimensions( x, [ -2, -1 ] ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // dims=[0,-1] should be equivalent to dims=[0,1]: + arr = toReversedDimensions( x, [ 0, -1 ] ); + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // dims=[-2] should be equivalent to dims=[0]: + arr = toReversedDimensions( x, [ -2 ] ); + expected = [ [ 4.0, 5.0, 6.0 ], [ 1.0, 2.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function produces the same result regardless of the order of the dimension indices', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + arr = toReversedDimensions( x, [ 1, 0 ] ); + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports higher-dimensional ndarrays', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]; + x = new base( 'generic', buf, [ 2, 2, 3 ], [ 6, 3, 1 ], 0, 'row-major' ); + + // Reverse all axes: + arr = toReversedDimensions( x, [ 0, 1, 2 ] ); + t.deepEqual( getShape( arr ), [ 2, 2, 3 ], 'returns expected value' ); + expected = [ + [ [ 12, 11, 10 ], [ 9, 8, 7 ] ], + [ [ 6, 5, 4 ], [ 3, 2, 1 ] ] + ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // Reverse only the last two axes: + arr = toReversedDimensions( x, [ 1, 2 ] ); + expected = [ + [ [ 6, 5, 4 ], [ 3, 2, 1 ] ], + [ [ 12, 11, 10 ], [ 9, 8, 7 ] ] + ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports ndarrays having a non-zero offset', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 2, 'row-major' ); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the original arrangement when reversing twice along the same dimensions', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + arr = toReversedDimensions( x, [ 0, 1 ] ); + arr = toReversedDimensions( arr, [ 0, 1 ] ); + + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + t.notEqual( getData( arr ), getData( x ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function does not mutate the input ndarray', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + + arr = toReversedDimensions( x, [ 0, 1 ] ); + t.deepEqual( ndarray2array( x ), expected, 'returns expected value' ); + + arr = toReversedDimensions( x, [ 1 ] ); + t.deepEqual( ndarray2array( x ), expected, 'returns expected value' ); + + t.notEqual( arr, x, 'returns expected value' ); + t.end(); +});