From 4085da8ec09f956b14f6fbb9922429e96b036b3e Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 27 Sep 2025 12:23:06 +0500 Subject: [PATCH 1/4] feat: add ndarray/to-reversed --- 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 --- --- .../@stdlib/ndarray/to-reversed/README.md | 142 +++++++++++ .../to-reversed/benchmark/benchmark.js | 222 ++++++++++++++++++ .../@stdlib/ndarray/to-reversed/docs/repl.txt | 28 +++ .../ndarray/to-reversed/docs/types/index.d.ts | 57 +++++ .../ndarray/to-reversed/docs/types/test.ts | 53 +++++ .../ndarray/to-reversed/examples/index.js | 38 +++ .../@stdlib/ndarray/to-reversed/lib/index.js | 56 +++++ .../@stdlib/ndarray/to-reversed/lib/main.js | 68 ++++++ .../@stdlib/ndarray/to-reversed/package.json | 65 +++++ .../@stdlib/ndarray/to-reversed/test/test.js | 182 ++++++++++++++ 10 files changed, 911 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/README.md b/lib/node_modules/@stdlib/ndarray/to-reversed/README.md new file mode 100644 index 000000000000..80658341a9bf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/README.md @@ -0,0 +1,142 @@ + + +# toReversed + +> Return a new [`ndarray`][@stdlib/ndarray/ctor] where the order of elements of an input [`ndarray`][@stdlib/ndarray/ctor] is reversed along each dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toReversed = require( '@stdlib/ndarray/to-reversed' ); +``` + +#### toReversed( x ) + +Returns a new [`ndarray`][@stdlib/ndarray/ctor] where the order of elements of an input [`ndarray`][@stdlib/ndarray/ctor] is reversed along each dimension. + +```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 arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = toReversed( x ); +// returns + +arr = ndarray2array( y ); +// returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var toReversed = require( '@stdlib/ndarray/to-reversed' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; +var shape = [ 2, 2, 2 ]; +var strides = [ 4, 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +console.log( ndarray2array( x ) ); + +var y = toReversed( x ); +// returns + +console.log( ndarray2array( y ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/to-reversed/benchmark/benchmark.js new file mode 100644 index 000000000000..083b55221f74 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/benchmark/benchmark.js @@ -0,0 +1,222 @@ +/** +* @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 empty = require( '@stdlib/ndarray/empty' ); +var pkg = require( './../package.json' ).name; +var toReversed = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::0d', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [], { 'dtype': 'float64' } ), + empty( [], { 'dtype': 'float32' } ), + empty( [], { 'dtype': 'int32' } ), + empty( [], { 'dtype': 'complex128' } ), + empty( [], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = toReversed( values[ i%values.length ] ); + 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', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversed( values[ i%values.length ] ); + 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', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversed( values[ i%values.length ] ); + 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', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversed( values[ i%values.length ] ); + 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', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversed( values[ i%values.length ] ); + 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', function benchmark( b ) { + var values; + var v; + 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++ ) { + v = toReversed( values[ i%values.length ] ); + 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/to-reversed/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt new file mode 100644 index 000000000000..4dcb0978613b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt @@ -0,0 +1,28 @@ +{{alias}}( x ) + Returns a new ndarray where the order of elements of an input ndarray is + reversed along each dimension. + + Parameters + ---------- + x: ndarray + Input array. + + Returns + ------- + out: ndarray + A new ndarray where the order of elements along each dimension is + reversed. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + + > {{alias:@stdlib/ndarray/to-array}}( x ) + [ [ 1, 2 ], [ 3, 4 ] ] + > var y = {{alias}}( x ) + + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ [ 4, 3 ], [ 2, 1 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/index.d.ts new file mode 100644 index 000000000000..f8ffe4baf320 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/index.d.ts @@ -0,0 +1,57 @@ +/* +* @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 is reversed along each dimension. +* +* @param x - input array +* @returns output ndarray +* +* @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 arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversed( x ); +* // returns +* +* arr = ndarray2array( y ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +*/ +declare function toReversed( x: T ): T; + + +// EXPORTS // + +export = toReversed; diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/test.ts new file mode 100644 index 000000000000..1d099a81813a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/types/test.ts @@ -0,0 +1,53 @@ +/* +* @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 toReversed = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + toReversed( empty( 'float64', sh, order ) ); // $ExpectType float64ndarray + toReversed( empty( 'complex64', sh, order ) ); // $ExpectType complex64ndarray + toReversed( empty( 'int32', sh, order ) ); // $ExpectType int32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + toReversed( '10' ); // $ExpectError + toReversed( 10 ); // $ExpectError + toReversed( false ); // $ExpectError + toReversed( true ); // $ExpectError + toReversed( null ); // $ExpectError + toReversed( [] ); // $ExpectError + toReversed( {} ); // $ExpectError + toReversed( ( 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' ); + + toReversed(); // $ExpectError + toReversed( x, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js b/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js new file mode 100644 index 000000000000..32ba6ca9cc18 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js @@ -0,0 +1,38 @@ +/** +* @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 ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var toReversed = require( './../lib' ); + +var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; +var shape = [ 2, 2, 2 ]; +var strides = [ 4, 2, 1 ]; +var offset = 0; + +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +// returns + +console.log( ndarray2array( x ) ); + +var y = toReversed( x ); +// returns + +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/lib/index.js b/lib/node_modules/@stdlib/ndarray/to-reversed/lib/index.js new file mode 100644 index 000000000000..41858554e39f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/lib/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'; + +/** +* Return a new ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @module @stdlib/ndarray/to-reversed +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var toReversed = require( '@stdlib/ndarray/to-reversed' ); +* +* 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 arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversed( x ); +* // returns +* +* arr = ndarray2array( y ); +* // 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/to-reversed/lib/main.js b/lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js new file mode 100644 index 000000000000..c9ac55343296 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js @@ -0,0 +1,68 @@ +/** +* @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 isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var base = require( '@stdlib/ndarray/base/to-reversed' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @param {ndarray} x - input array +* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @returns {ndarray} output ndarray +* +* @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 arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = toReversed( x ); +* // returns +* +* arr = ndarray2array( y ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] +*/ +function toReversed( x ) { + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + return base( x ); +} + + +// EXPORTS // + +module.exports = toReversed; diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/package.json b/lib/node_modules/@stdlib/ndarray/to-reversed/package.json new file mode 100644 index 000000000000..dfb091d98e11 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ndarray/to-reversed", + "version": "0.0.0", + "description": "Return a new ndarray where the order of elements of an input ndarray is reversed along each dimension.", + "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", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "reverse", + "reversed", + "to-reversed", + "flip" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js new file mode 100644 index 000000000000..4641fe7b2383 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js @@ -0,0 +1,182 @@ +/** +* @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/zero-to' ); +var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var toReversed = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toReversed, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + toReversed( value ); + }; + } +}); + +tape( 'the function returns a new zero-dimensional ndarray if provided a zero-dimensional input ndarray', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( 10.0, 'float64', 'row-major' ); + + actual = toReversed( x ); + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), x.get(), 'returns expected value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements along each dimension is reversed (ndims=1)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 10, 'float64' ); + sh = [ 5 ]; + st = [ 2 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = toReversed( x ); + expected = [ 8, 6, 4, 2, 0 ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns exepcted value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements along each 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 = zeroTo( 12, 'float64' ); + sh = [ 3, 2 ]; + st = [ 4, 2 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = toReversed( x ); + expected = [ + [ 10, 8 ], + [ 6, 4 ], + [ 2, 0 ] + ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of elements along each 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 = zeroTo( 24, 'float64' ); + sh = [ 2, 3, 2 ]; + st = [ 12, 4, 2 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = toReversed( x ); + expected = [ + [ + [ 22, 20 ], + [ 18, 16 ], + [ 14, 12 ] + ], + [ + [ 10, 8 ], + [ 6, 4 ], + [ 2, 0 ] + ] + ]; + + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From 26b075b1b4f265df27811d21c9f61978aef9a144 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 27 Sep 2025 12:41:19 +0500 Subject: [PATCH 2/4] test: fix import --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js index 4641fe7b2383..91a1d7896a21 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js @@ -23,7 +23,7 @@ var tape = require( 'tape' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var zeroTo = require( '@stdlib/array/zero-to' ); -var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var getShape = require( '@stdlib/ndarray/shape' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -71,7 +71,10 @@ tape( 'the function returns a new zero-dimensional ndarray if provided a zero-di var actual; var x; - x = scalar2ndarray( 10.0, 'float64', 'row-major' ); + x = scalar2ndarray( 10.0, { + 'dtype': 'float64', + 'order': 'row-major' + }); actual = toReversed( x ); From 999db0ec4d4c5f6bcd4bd6025c5fe86bd2573545 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 1 Oct 2025 00:09:39 +0500 Subject: [PATCH 3/4] chore: apply suggestions from code review --- 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: na - task: lint_repl_help status: na - 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: na - 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: na - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/to-reversed/README.md | 24 +++++-------------- .../ndarray/to-reversed/examples/index.js | 13 ++-------- .../@stdlib/ndarray/to-reversed/lib/main.js | 2 +- .../@stdlib/ndarray/to-reversed/test/test.js | 10 ++++++++ 4 files changed, 19 insertions(+), 30 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/README.md b/lib/node_modules/@stdlib/ndarray/to-reversed/README.md index 80658341a9bf..14a48bc1a2b0 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/README.md +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/README.md @@ -45,15 +45,12 @@ var toReversed = require( '@stdlib/ndarray/to-reversed' ); Returns a new [`ndarray`][@stdlib/ndarray/ctor] where the order of elements of an input [`ndarray`][@stdlib/ndarray/ctor] is reversed along each dimension. ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); 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' ); +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], { + 'shape': [ 3, 2 ] +}); // returns var arr = ndarray2array( x ); @@ -87,23 +84,14 @@ arr = ndarray2array( y ); ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); +var uniform = require( '@stdlib/random/uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var toReversed = require( '@stdlib/ndarray/to-reversed' ); -var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; -var shape = [ 2, 2, 2 ]; -var strides = [ 4, 2, 1 ]; -var offset = 0; - -var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -// returns - +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); console.log( ndarray2array( x ) ); var y = toReversed( x ); -// returns - console.log( ndarray2array( y ) ); ``` diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js b/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js index 32ba6ca9cc18..d3fc0e2ed6c7 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/examples/index.js @@ -18,21 +18,12 @@ 'use strict'; -var ndarray = require( '@stdlib/ndarray/ctor' ); +var uniform = require( '@stdlib/random/uniform' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var toReversed = require( './../lib' ); -var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]; -var shape = [ 2, 2, 2 ]; -var strides = [ 4, 2, 1 ]; -var offset = 0; - -var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -// returns - +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); console.log( ndarray2array( x ) ); var y = toReversed( x ); -// returns - console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js b/lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js index c9ac55343296..4696fd5b135d 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/lib/main.js @@ -31,7 +31,7 @@ var format = require( '@stdlib/string/format' ); * Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension. * * @param {ndarray} x - input array -* @throws {TypeError} first argument must be an ndarray having one or more dimensions +* @throws {TypeError} first argument must be an ndarray * @returns {ndarray} output ndarray * * @example diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js index 91a1d7896a21..0be2258ffcab 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js @@ -21,10 +21,12 @@ // MODULES // var tape = require( 'tape' ); +var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var zeroTo = require( '@stdlib/array/zero-to' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var getShape = require( '@stdlib/ndarray/shape' ); +var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var toReversed = require( './../lib' ); @@ -78,9 +80,11 @@ tape( 'the function returns a new zero-dimensional ndarray if provided a zero-di actual = toReversed( x ); + t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), x.get(), 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.end(); }); @@ -106,8 +110,10 @@ tape( 'the function returns a new ndarray where the order of elements along each actual = toReversed( x ); expected = [ 8, 6, 4, 2, 0 ]; + t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns exepcted value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); @@ -138,8 +144,10 @@ tape( 'the function returns a new ndarray where the order of elements along each [ 2, 0 ] ]; + t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); @@ -177,8 +185,10 @@ tape( 'the function returns a new ndarray where the order of elements along each ] ]; + t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); t.end(); From 1559a3c223c0e367c729ad6786cbed49d8eda30a Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 2 Oct 2025 12:36:28 +0100 Subject: [PATCH 4/4] chore: minor clean-up --- 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: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt | 1 + lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt index 4dcb0978613b..bc206c67442e 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/docs/repl.txt @@ -1,3 +1,4 @@ + {{alias}}( x ) Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension. diff --git a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js index 0be2258ffcab..db84bd9b35c9 100644 --- a/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/to-reversed/test/test.js @@ -26,6 +26,7 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); var zeroTo = require( '@stdlib/array/zero-to' ); var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); var getShape = require( '@stdlib/ndarray/shape' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); var getDType = require( '@stdlib/ndarray/dtype' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); var ndarray = require( '@stdlib/ndarray/ctor' ); @@ -84,6 +85,7 @@ tape( 'the function returns a new zero-dimensional ndarray if provided a zero-di t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.strictEqual( actual.get(), x.get(), 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.end(); @@ -112,7 +114,8 @@ tape( 'the function returns a new ndarray where the order of elements along each t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); - t.deepEqual( getShape( x ), getShape( actual ), 'returns exepcted value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -147,6 +150,7 @@ tape( 'the function returns a new ndarray where the order of elements along each t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); @@ -188,6 +192,7 @@ tape( 'the function returns a new ndarray where the order of elements along each t.notEqual( actual, x, 'returns expected value' ); t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.notEqual( getData( actual ), getData( x ), 'returns expected value' ); t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' );