From 8c135bd3b4c4d905bbd1665eb79a5a73d8d60580 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 6 Dec 2025 16:07:12 +0500 Subject: [PATCH 1/6] feat: add ndarray/base/to-reversed-dimension --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../base/to-reversed-dimension/README.md | 162 +++++++++ .../benchmark/benchmark.js | 331 +++++++++++++++++ .../base/to-reversed-dimension/docs/repl.txt | 36 ++ .../docs/types/index.d.ts | 65 ++++ .../to-reversed-dimension/docs/types/test.ts | 118 ++++++ .../to-reversed-dimension/examples/index.js | 56 +++ .../base/to-reversed-dimension/lib/index.js | 64 ++++ .../base/to-reversed-dimension/lib/main.js | 83 +++++ .../base/to-reversed-dimension/package.json | 66 ++++ .../base/to-reversed-dimension/test/test.js | 343 ++++++++++++++++++ 10 files changed, 1324 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/README.md b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/README.md new file mode 100644 index 000000000000..b1c14cbc6e2a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/README.md @@ -0,0 +1,162 @@ + + +# toReversedDimension + +> Return a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toReversedDimension = require( '@stdlib/ndarray/base/to-reversed-dimension' ); +``` + +#### toReversedDimension( x, dim ) + +Returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +var shape = [ 3, 2 ]; +var strides = [ 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +var sh = x.shape; +// returns [ 3, 2 ] + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = toReversedDimension( x, 0 ); +// returns + +sh = y.shape; +// returns [ 3, 2 ] + +arr = ndarray2array( y ); +// returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **dim**: index of dimension 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 zeroTo = require( '@stdlib/array/base/zero-to' ); +var toReversedDimension = require( '@stdlib/ndarray/base/to-reversed-dimension' ); + +// Create a linear ndarray buffer: +var buf = zeroTo( 16 ); + +// Create a three-dimensional ndarray: +var x = array( buf, { + 'shape': [ 2, 4, 2 ] +}); + +// Reverse the order of first axis: +var y0 = toReversedDimension( x, 0 ); +// returns + +var a0 = ndarray2array( y0 ); +// returns [ [ [ 8, 9 ], [ 10, 11 ], [ 12, 13 ], [ 14, 15 ] ], [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ], [ 6, 7 ] ] ] + +// Reverse the order of second axis: +var y1 = toReversedDimension( x, 1 ); +// returns + +var a1 = ndarray2array( y1 ); +// returns [ [ [ 6, 7 ], [ 4, 5 ], [ 2, 3 ], [ 0, 1 ] ], [ [ 14, 15 ], [ 12, 13 ], [ 10, 11 ], [ 8, 9 ] ] ] + +// Reverse the order of third axis: +var y2 = toReversedDimension( x, 2 ); +// returns + +var a2 = ndarray2array( y2 ); +// returns [ [ [ 1, 0 ], [ 3, 2 ], [ 5, 4 ], [ 7, 6 ] ], [ [ 9, 8 ], [ 11, 10 ], [ 13, 12 ], [ 15, 14 ] ] ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/benchmark/benchmark.js new file mode 100644 index 000000000000..52867829595c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/benchmark/benchmark.js @@ -0,0 +1,331 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 pkg = require( './../package.json' ).name; +var toReversedDimension = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::1d,base', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::1d,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::2d,base', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::2d,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::3d,base', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::3d,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::4d,base', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::4d,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::5d,base', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::5d,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + 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 */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toReversedDimension( values[ i%values.length ], 0 ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/repl.txt new file mode 100644 index 000000000000..460d378ea048 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/repl.txt @@ -0,0 +1,36 @@ + +{{alias}}( x, dim ) + Returns a new ndarray where the order of elements of an input ndarray along + a specified dimension is reversed. + + Parameters + ---------- + x: ndarray + Input array. + + dim: integer + Index of dimension to reverse. If less than zero, the 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 ] ] ) + + > x.shape + [ 2, 2 ] + > var y = {{alias}}( x, 0 ) + + > y.shape + [ 2, 2 ] + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ [ 3, 4 ], [ 1, 2 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/index.d.ts new file mode 100644 index 000000000000..9c1dd3a90758 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/index.d.ts @@ -0,0 +1,65 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 { ndarray } from '@stdlib/types/ndarray'; + +/** +* Returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed. +* +* @param x - input array +* @param dim - index of dimension to reverse +* @returns output array +* +* @example +* var typedarray = require( '@stdlib/array/typed' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = typedarray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], 'float64' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 2 ] +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversedDimension( x, 0 ); +* // returns +* +* sh = y.shape; +* // returns [ 3, 2 ] +* +* arr = ndarray2array( y ); +* // returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +*/ +declare function toReversedDimension( x: T, dim: number ): T; + + +// EXPORTS // + +export = toReversedDimension; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts new file mode 100644 index 000000000000..1d632e595ec8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts @@ -0,0 +1,118 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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 empty = require( '@stdlib/ndarray/base/empty' ); +import toReversedDimension = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + toReversedDimension( empty( 'float64', sh, order ), 0 ); // $ExpectType float64ndarray + toReversedDimension( empty( 'float32', sh, order ), 0 ); // $ExpectType float32ndarray + toReversedDimension( empty( 'complex128', sh, order ), 0 ); // $ExpectType complex128ndarray + toReversedDimension( empty( 'complex64', sh, order ), 0 ); // $ExpectType complex64ndarray + toReversedDimension( empty( 'int32', sh, order ), 0 ); // $ExpectType int32ndarray + toReversedDimension( empty( 'int16', sh, order ), 0 ); // $ExpectType int16ndarray + toReversedDimension( empty( 'int8', sh, order ), 0 ); // $ExpectType int8ndarray + toReversedDimension( empty( 'uint32', sh, order ), 0 ); // $ExpectType uint32ndarray + toReversedDimension( empty( 'uint16', sh, order ), 0 ); // $ExpectType uint16ndarray + toReversedDimension( empty( 'uint8', sh, order ), 0 ); // $ExpectType uint8ndarray + toReversedDimension( empty( 'uint8c', sh, order ), 0 ); // $ExpectType uint8cndarray + + toReversedDimension( empty( 'float64', sh, order ), 0 ); // $ExpectType float64ndarray + toReversedDimension( empty( 'float32', sh, order ), 0 ); // $ExpectType float32ndarray + toReversedDimension( empty( 'complex128', sh, order ), 0 ); // $ExpectType complex128ndarray + toReversedDimension( empty( 'complex64', sh, order ), 0 ); // $ExpectType complex64ndarray + toReversedDimension( empty( 'int32', sh, order ), 0 ); // $ExpectType int32ndarray + toReversedDimension( empty( 'int16', sh, order ), 0 ); // $ExpectType int16ndarray + toReversedDimension( empty( 'int8', sh, order ), 0 ); // $ExpectType int8ndarray + toReversedDimension( empty( 'uint32', sh, order ), 0 ); // $ExpectType uint32ndarray + toReversedDimension( empty( 'uint16', sh, order ), 0 ); // $ExpectType uint16ndarray + toReversedDimension( empty( 'uint8', sh, order ), 0 ); // $ExpectType uint8ndarray + toReversedDimension( empty( 'uint8c', sh, order ), 0 ); // $ExpectType uint8cndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + toReversedDimension( '10', 0 ); // $ExpectError + toReversedDimension( 10, 0 ); // $ExpectError + toReversedDimension( false, 0 ); // $ExpectError + toReversedDimension( true, 0 ); // $ExpectError + toReversedDimension( null, 0 ); // $ExpectError + toReversedDimension( [], 0 ); // $ExpectError + toReversedDimension( {}, 0 ); // $ExpectError + toReversedDimension( ( x: number ): number => x, 0 ); // $ExpectError + + toReversedDimension( '10', 0 ); // $ExpectError + toReversedDimension( 10, 0 ); // $ExpectError + toReversedDimension( false, 0 ); // $ExpectError + toReversedDimension( true, 0 ); // $ExpectError + toReversedDimension( null, 0 ); // $ExpectError + toReversedDimension( [], 0 ); // $ExpectError + toReversedDimension( {}, 0 ); // $ExpectError + toReversedDimension( ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + toReversedDimension( x, '5' ); // $ExpectError + toReversedDimension( x ); // $ExpectError + toReversedDimension( x ); // $ExpectError + toReversedDimension( x, null ); // $ExpectError + toReversedDimension( x, undefined ); // $ExpectError + toReversedDimension( x, [ '5' ] ); // $ExpectError + toReversedDimension( x, {} ); // $ExpectError + toReversedDimension( x, ( x: number ): number => x ); // $ExpectError + + toReversedDimension( x, '5' ); // $ExpectError + toReversedDimension( x ); // $ExpectError + toReversedDimension( x ); // $ExpectError + toReversedDimension( x, null ); // $ExpectError + toReversedDimension( x, undefined ); // $ExpectError + toReversedDimension( x, [ '5' ] ); // $ExpectError + toReversedDimension( x, {} ); // $ExpectError + toReversedDimension( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a boolean... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + toReversedDimension( x, 0, '5' ); // $ExpectError + toReversedDimension( x, 0, 5 ); // $ExpectError + toReversedDimension( x, 0, null ); // $ExpectError + toReversedDimension( x, 0, undefined ); // $ExpectError + toReversedDimension( x, 0, [ '5' ] ); // $ExpectError + toReversedDimension( x, 0, {} ); // $ExpectError + toReversedDimension( x, 0, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + + toReversedDimension( x ); // $ExpectError + toReversedDimension( x, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/examples/index.js new file mode 100644 index 000000000000..6987c4044e70 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/examples/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 zeroTo = require( '@stdlib/array/base/zero-to' ); +var toReversedDimension = require( './../lib' ); + +// Create a linear ndarray buffer: +var buf = zeroTo( 16 ); + +// Create a three-dimensional ndarray: +var x = array( buf, { + 'shape': [ 2, 4, 2 ] +}); + +// Reverse the order of first axis: +var y0 = toReversedDimension( x, 0 ); +// returns + +var a0 = ndarray2array( y0 ); +console.log( a0 ); +// => [ [ [ 8, 9 ], [ 10, 11 ], [ 12, 13 ], [ 14, 15 ] ], [ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ], [ 6, 7 ] ] ] + +// Reverse the order of second axis: +var y1 = toReversedDimension( x, 1 ); +// returns + +var a1 = ndarray2array( y1 ); +console.log( a1 ); +// => [ [ [ 6, 7 ], [ 4, 5 ], [ 2, 3 ], [ 0, 1 ] ], [ [ 14, 15 ], [ 12, 13 ], [ 10, 11 ], [ 8, 9 ] ] ] + +// Reverse the order of third axis: +var y2 = toReversedDimension( x, 2 ); +// returns + +var a2 = ndarray2array( y2 ); +console.log( a2 ); +// => [ [ [ 1, 0 ], [ 3, 2 ], [ 5, 4 ], [ 7, 6 ] ], [ [ 9, 8 ], [ 11, 10 ], [ 13, 12 ], [ 15, 14 ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js new file mode 100644 index 000000000000..aa33bc0b1982 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +/* eslint-disable stdlib/jsdoc-doctest */ + +'use strict'; + +/** +* Return a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed. +* +* @module @stdlib/ndarray/base/to-reversed-dimension +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var toReversedDimension = require( '@stdlib/ndarray/base/to-reversed-dimension' ); +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 2 ] +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversed( x ); +* // returns +* +* sh = y.shape; +* // returns [ 3, 2 ] +* +* arr = ndarray2array( y ); +* // returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/main.js new file mode 100644 index 000000000000..baaffc010488 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/main.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 reverseDimension = require( '@stdlib/ndarray/base/reverse-dimension' ); +var assign = require( '@stdlib/ndarray/base/assign' ); + + +// MAIN // + +/** +* Returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed. +* +* @param {ndarray} x - input array +* @param {integer} dim - index of dimension to reverse +* @returns {ndarray} output array +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var sh = x.shape; +* // returns [ 3, 2 ] +* +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversedDimension( x, 0 ); +* // returns +* +* sh = y.shape; +* // returns [ 3, 2 ] +* +* arr = ndarray2array( y ); +* // returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +*/ +function toReversedDimension( x, dim ) { + var out; + var xr; + + // Create a reversed view of the input ndarray: + xr = reverseDimension( x, dim, false ); + + // Create an output ndarray with the same shape and data type as the input ndarray: + out = emptyLike( x ); + + // Assign the elements of the reversed input ndarray view to the output ndarray: + assign( [ xr, out ] ); + + return out; +} + + +// EXPORTS // + +module.exports = toReversedDimension; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/package.json b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/package.json new file mode 100644 index 000000000000..2f404992d46a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/to-reversed-dimension", + "version": "0.0.0", + "description": "Return a new ndarray where the order of elements of an input ndarray along a specified dimension 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", + "dimenions", + "flip", + "numpy.flip" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/test/test.js new file mode 100644 index 000000000000..80e6f0e06142 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/test/test.js @@ -0,0 +1,343 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var typedarray = require( '@stdlib/array/typed' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ctor = require( '@stdlib/ndarray/ctor' ); +var toReverseDimension = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toReverseDimension, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed (ndims=1)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + var i; + + buf = typedarray( zeroTo( 30 ), 'float64' ); + sh = [ 6 ]; + st = [ 2 ]; + o = 4; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = toReverseDimension( x, 0 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 1, 'returns expected value' ); + t.strictEqual( actual.length, 6, 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ 14, 12, 10, 8, 6, 4 ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); + } + + actual = toReverseDimension( x, -1 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 1, 'returns expected value' ); + t.strictEqual( actual.length, 6, 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ 14, 12, 10, 8, 6, 4 ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed (ndims=2)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( zeroTo( 30 ), 'float64' ); + sh = [ 4, 3 ]; + st = [ 6, 2 ]; + o = 4; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = toReverseDimension( x, 0 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 2, 'returns expected value' ); + t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ 22, 24, 26 ], + [ 16, 18, 20 ], + [ 10, 12, 14 ], + [ 4, 6, 8 ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, -2 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 2, 'returns expected value' ); + t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ 22, 24, 26 ], + [ 16, 18, 20 ], + [ 10, 12, 14 ], + [ 4, 6, 8 ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, 1 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 2, 'returns expected value' ); + t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ 8, 6, 4 ], + [ 14, 12, 10 ], + [ 20, 18, 16 ], + [ 26, 24, 22 ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, -1 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 2, 'returns expected value' ); + t.deepEqual( actual.shape, [ 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ 8, 6, 4 ], + [ 14, 12, 10 ], + [ 20, 18, 16 ], + [ 26, 24, 22 ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed (ndims=3)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = typedarray( zeroTo( 100 ), 'float64' ); + sh = [ 2, 4, 3 ]; + st = [ 24, 6, 2 ]; + o = 10; + ord = 'row-major'; + + x = new ctor( 'float64', buf, sh, st, o, ord ); + + actual = toReverseDimension( x, 0 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 3, 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ + [ 34, 36, 38 ], + [ 40, 42, 44 ], + [ 46, 48, 50 ], + [ 52, 54, 56 ] + ], + [ + [ 10, 12, 14 ], + [ 16, 18, 20 ], + [ 22, 24, 26 ], + [ 28, 30, 32 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, -3 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 3, 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ + [ 34, 36, 38 ], + [ 40, 42, 44 ], + [ 46, 48, 50 ], + [ 52, 54, 56 ] + ], + [ + [ 10, 12, 14 ], + [ 16, 18, 20 ], + [ 22, 24, 26 ], + [ 28, 30, 32 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, 1 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 3, 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ + [ 28, 30, 32 ], + [ 22, 24, 26 ], + [ 16, 18, 20 ], + [ 10, 12, 14 ] + ], + [ + [ 52, 54, 56 ], + [ 46, 48, 50 ], + [ 40, 42, 44 ], + [ 34, 36, 38 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, -2 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 3, 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ + [ 28, 30, 32 ], + [ 22, 24, 26 ], + [ 16, 18, 20 ], + [ 10, 12, 14 ] + ], + [ + [ 52, 54, 56 ], + [ 46, 48, 50 ], + [ 40, 42, 44 ], + [ 34, 36, 38 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, 2 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 3, 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ + [ 14, 12, 10 ], + [ 20, 18, 16 ], + [ 26, 24, 22 ], + [ 32, 30, 28 ] + ], + [ + [ 38, 36, 34 ], + [ 44, 42, 40 ], + [ 50, 48, 46 ], + [ 56, 54, 52 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + + actual = toReverseDimension( x, -1 ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 3, 'returns expected value' ); + t.deepEqual( actual.shape, [ 2, 4, 3 ], 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + expected = [ + [ + [ 14, 12, 10 ], + [ 20, 18, 16 ], + [ 26, 24, 22 ], + [ 32, 30, 28 ] + ], + [ + [ 38, 36, 34 ], + [ 44, 42, 40 ], + [ 50, 48, 46 ], + [ 56, 54, 52 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); From 5b5c3e08f9b7467f9f7fe72966d6d1a3030b98a6 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 21:50:39 -0800 Subject: [PATCH 2/6] Apply suggestions from code review Signed-off-by: Athan --- .../to-reversed-dimension/docs/types/test.ts | 47 +------------------ 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts index 1d632e595ec8..d6b9213d563c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts @@ -38,18 +38,6 @@ import toReversedDimension = require( './index' ); toReversedDimension( empty( 'uint16', sh, order ), 0 ); // $ExpectType uint16ndarray toReversedDimension( empty( 'uint8', sh, order ), 0 ); // $ExpectType uint8ndarray toReversedDimension( empty( 'uint8c', sh, order ), 0 ); // $ExpectType uint8cndarray - - toReversedDimension( empty( 'float64', sh, order ), 0 ); // $ExpectType float64ndarray - toReversedDimension( empty( 'float32', sh, order ), 0 ); // $ExpectType float32ndarray - toReversedDimension( empty( 'complex128', sh, order ), 0 ); // $ExpectType complex128ndarray - toReversedDimension( empty( 'complex64', sh, order ), 0 ); // $ExpectType complex64ndarray - toReversedDimension( empty( 'int32', sh, order ), 0 ); // $ExpectType int32ndarray - toReversedDimension( empty( 'int16', sh, order ), 0 ); // $ExpectType int16ndarray - toReversedDimension( empty( 'int8', sh, order ), 0 ); // $ExpectType int8ndarray - toReversedDimension( empty( 'uint32', sh, order ), 0 ); // $ExpectType uint32ndarray - toReversedDimension( empty( 'uint16', sh, order ), 0 ); // $ExpectType uint16ndarray - toReversedDimension( empty( 'uint8', sh, order ), 0 ); // $ExpectType uint8ndarray - toReversedDimension( empty( 'uint8c', sh, order ), 0 ); // $ExpectType uint8cndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... @@ -62,15 +50,6 @@ import toReversedDimension = require( './index' ); toReversedDimension( [], 0 ); // $ExpectError toReversedDimension( {}, 0 ); // $ExpectError toReversedDimension( ( x: number ): number => x, 0 ); // $ExpectError - - toReversedDimension( '10', 0 ); // $ExpectError - toReversedDimension( 10, 0 ); // $ExpectError - toReversedDimension( false, 0 ); // $ExpectError - toReversedDimension( true, 0 ); // $ExpectError - toReversedDimension( null, 0 ); // $ExpectError - toReversedDimension( [], 0 ); // $ExpectError - toReversedDimension( {}, 0 ); // $ExpectError - toReversedDimension( ( x: number ): number => x, 0 ); // $ExpectError } // The compiler throws an error if the function is provided a second argument which is not a number... @@ -78,35 +57,13 @@ import toReversedDimension = require( './index' ); const x = empty( 'float64', [ 2, 2 ], 'row-major' ); toReversedDimension( x, '5' ); // $ExpectError - toReversedDimension( x ); // $ExpectError - toReversedDimension( x ); // $ExpectError + toReversedDimension( x, true ); // $ExpectError + toReversedDimension( x, false ); // $ExpectError toReversedDimension( x, null ); // $ExpectError toReversedDimension( x, undefined ); // $ExpectError toReversedDimension( x, [ '5' ] ); // $ExpectError toReversedDimension( x, {} ); // $ExpectError toReversedDimension( x, ( x: number ): number => x ); // $ExpectError - - toReversedDimension( x, '5' ); // $ExpectError - toReversedDimension( x ); // $ExpectError - toReversedDimension( x ); // $ExpectError - toReversedDimension( x, null ); // $ExpectError - toReversedDimension( x, undefined ); // $ExpectError - toReversedDimension( x, [ '5' ] ); // $ExpectError - toReversedDimension( x, {} ); // $ExpectError - toReversedDimension( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = empty( 'float64', [ 2, 2 ], 'row-major' ); - - toReversedDimension( x, 0, '5' ); // $ExpectError - toReversedDimension( x, 0, 5 ); // $ExpectError - toReversedDimension( x, 0, null ); // $ExpectError - toReversedDimension( x, 0, undefined ); // $ExpectError - toReversedDimension( x, 0, [ '5' ] ); // $ExpectError - toReversedDimension( x, 0, {} ); // $ExpectError - toReversedDimension( x, 0, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided an unsupported number of arguments... From a71109415a297877c1215de1adb729bf0509c45b Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 21:51:23 -0800 Subject: [PATCH 3/6] test: add missing case Signed-off-by: Athan --- .../ndarray/base/to-reversed-dimension/docs/types/test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts index d6b9213d563c..26584e2cabf7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/docs/types/test.ts @@ -70,6 +70,7 @@ import toReversedDimension = require( './index' ); { const x = empty( 'float64', [ 2, 2 ], 'row-major' ); + toReversedDimension(); // $ExpectError toReversedDimension( x ); // $ExpectError toReversedDimension( x, 0, {} ); // $ExpectError } From cdee107b15ca9197c1cb52b50172431152bcae2f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 21:52:21 -0800 Subject: [PATCH 4/6] style: enable lint rule Signed-off-by: Athan --- .../@stdlib/ndarray/base/to-reversed-dimension/lib/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js index aa33bc0b1982..41b4ed7cce8b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable stdlib/jsdoc-doctest */ - 'use strict'; /** From 8ddafa18f268d9d4e449c5ad1dd789ed04ef7f51 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 21:52:59 -0800 Subject: [PATCH 5/6] docs: fix example Signed-off-by: Athan --- .../@stdlib/ndarray/base/to-reversed-dimension/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js index 41b4ed7cce8b..5b8009108a5d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js @@ -42,7 +42,7 @@ * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = toReversed( x ); +* var y = toReversedDimension( x ); * // returns * * sh = y.shape; From d67fc281b668ce35f4edeff8e5092b8fac5165fe Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 21:53:41 -0800 Subject: [PATCH 6/6] docs: fix example Signed-off-by: Athan --- .../@stdlib/ndarray/base/to-reversed-dimension/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js index 5b8009108a5d..bf82a330d455 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed-dimension/lib/index.js @@ -42,7 +42,7 @@ * var arr = ndarray2array( x ); * // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* var y = toReversedDimension( x ); +* var y = toReversedDimension( x, 0 ); * // returns * * sh = y.shape;