From a7e796dbcd5c0416c9d55104609453f2dc75c734 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Mon, 24 Nov 2025 14:19:09 +0500 Subject: [PATCH 1/2] feat: add ndarray/fliplr --- .../@stdlib/ndarray/fliplr/README.md | 130 ++++++++++ .../ndarray/fliplr/benchmark/benchmark.js | 223 ++++++++++++++++++ .../@stdlib/ndarray/fliplr/docs/repl.txt | 29 +++ .../ndarray/fliplr/docs/types/index.d.ts | 57 +++++ .../@stdlib/ndarray/fliplr/docs/types/test.ts | 53 +++++ .../@stdlib/ndarray/fliplr/examples/index.js | 29 +++ .../@stdlib/ndarray/fliplr/lib/index.js | 58 +++++ .../@stdlib/ndarray/fliplr/lib/main.js | 68 ++++++ .../@stdlib/ndarray/fliplr/package.json | 65 +++++ .../@stdlib/ndarray/fliplr/test/test.js | 205 ++++++++++++++++ 10 files changed, 917 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/fliplr/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/README.md b/lib/node_modules/@stdlib/ndarray/fliplr/README.md new file mode 100644 index 000000000000..0bd6c6e8c416 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/README.md @@ -0,0 +1,130 @@ + + +# fliplr + +> Return a **read-only** view of an input [`ndarray`][@stdlib/ndarray/ctor] in which the order of elements along the last dimension is reversed. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var fliplr = require( '@stdlib/ndarray/fliplr' ); +``` + +#### fliplr( x ) + +Returns a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] in which the order of elements along the last dimension is reversed. + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], { + 'shape': [ 3, 2 ] +}); +// returns + +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + +var y = fliplr( x ); +// returns + +arr = ndarray2array( y ); +// returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ] +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fliplr = require( '@stdlib/ndarray/fliplr' ); + +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); + +var y = fliplr( x ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/fliplr/benchmark/benchmark.js new file mode 100644 index 000000000000..25da30315f49 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/benchmark/benchmark.js @@ -0,0 +1,223 @@ +/** +* @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 fliplr = 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 = fliplr( 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 = fliplr( 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 = fliplr( 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 = fliplr( 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 = fliplr( 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 = fliplr( 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/fliplr/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/fliplr/docs/repl.txt new file mode 100644 index 000000000000..9b13b44470c6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/docs/repl.txt @@ -0,0 +1,29 @@ + +{{alias}}( x ) + Returns a read-only view of an input ndarray in which the order of elements + along the last dimension is reversed. + + Parameters + ---------- + x: ndarray + Input array. + + Returns + ------- + out: ndarray + A read-only view of an input ndarray in which the order of elements + along the last 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 ) + [ [ 2, 1 ], [ 4, 3 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/fliplr/docs/types/index.d.ts new file mode 100644 index 000000000000..e009335f09d9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/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 read-only view of an input ndarray in which the order of elements along the last dimension is reversed. +* +* @param x - input array +* @returns 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 arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] +* +* var y = fliplr( x ); +* // returns +* +* arr = ndarray2array( y ); +* // returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ] +*/ +declare function fliplr( x: T ): T; + + +// EXPORTS // + +export = fliplr; diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/fliplr/docs/types/test.ts new file mode 100644 index 000000000000..55926264eb68 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/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 fliplr = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + fliplr( empty( 'float64', sh, order ) ); // $ExpectType float64ndarray + fliplr( empty( 'complex64', sh, order ) ); // $ExpectType complex64ndarray + fliplr( empty( 'int32', sh, order ) ); // $ExpectType int32ndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + fliplr( '10' ); // $ExpectError + fliplr( 10 ); // $ExpectError + fliplr( false ); // $ExpectError + fliplr( true ); // $ExpectError + fliplr( null ); // $ExpectError + fliplr( [] ); // $ExpectError + fliplr( {} ); // $ExpectError + fliplr( ( 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' ); + + fliplr(); // $ExpectError + fliplr( x, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/examples/index.js b/lib/node_modules/@stdlib/ndarray/fliplr/examples/index.js new file mode 100644 index 000000000000..c6b700de1eb4 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/examples/index.js @@ -0,0 +1,29 @@ +/** +* @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 uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fliplr = require( './../lib' ); + +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); + +var y = fliplr( x ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js b/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js new file mode 100644 index 000000000000..aa374cf01e59 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js @@ -0,0 +1,58 @@ +/** +* @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 read-only view of an input ndarray in which the order of elements along the last dimension is reversed. +* +* @module @stdlib/ndarray/fliplr +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var fliplr = require( '@stdlib/ndarray/fliplr' ); +* +* 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 = fliplr( x ); +* // returns +* +* arr = ndarray2array( y ); +* // returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/lib/main.js b/lib/node_modules/@stdlib/ndarray/fliplr/lib/main.js new file mode 100644 index 000000000000..8589d705e2f9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/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/fliplr' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a read-only view of an input ndarray in which the order of elements along the last dimension is reversed. +* +* @param {ndarray} x - input array +* @throws {TypeError} first argument must be an ndarray +* @returns {ndarray} ndarray view +* +* @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 = fliplr( x ); +* // returns +* +* arr = ndarray2array( y ); +* // returns [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ] +*/ +function fliplr( x ) { + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + return base( x, false ); +} + + +// EXPORTS // + +module.exports = fliplr; diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/package.json b/lib/node_modules/@stdlib/ndarray/fliplr/package.json new file mode 100644 index 000000000000..746e488f1228 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/package.json @@ -0,0 +1,65 @@ +{ + "name": "@stdlib/ndarray/fliplr", + "version": "0.0.0", + "description": "Return a read-only view of an input ndarray in which the order of elements along the last 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", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "view", + "reverse", + "flip", + "fliplr" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/test/test.js b/lib/node_modules/@stdlib/ndarray/fliplr/test/test.js new file mode 100644 index 000000000000..dee909c7a0f6 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/fliplr/test/test.js @@ -0,0 +1,205 @@ +/** +* @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 isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var fliplr = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof fliplr, '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() { + fliplr( value ); + }; + } +}); + +tape( 'the function returns a read-only view of a zero-dimensional input ndarray', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( 10.0, { + 'dtype': 'float64', + 'order': 'row-major' + }); + + actual = fliplr( x ); + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( actual.get(), x.get(), 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a read-only view of an input ndarray in which the order of elements along the last 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 = fliplr( x ); + expected = [ 8, 6, 4, 2, 0 ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), 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 read-only view of an input ndarray in which the order of elements along the last 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 = fliplr( x ); + expected = [ + [ 2, 0 ], + [ 6, 4 ], + [ 10, 8 ] + ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), 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 read-only view of an input ndarray in which the order of elements along the last 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 = fliplr( x ); + expected = [ + [ + [ 2, 0 ], + [ 6, 4 ], + [ 10, 8 ] + ], + [ + [ 14, 12 ], + [ 18, 16 ], + [ 22, 20 ] + ] + ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( x ), getShape( actual ), 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From 4751108ba23563a7be396e6a45b4c400a3753a35 Mon Sep 17 00:00:00 2001 From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> Date: Mon, 24 Nov 2025 14:37:24 +0500 Subject: [PATCH 2/2] fix: apply suggestions from code review Signed-off-by: Muhammad Haris <101793258+headlessNode@users.noreply.github.com> --- lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js b/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js index aa374cf01e59..fe4e491bd353 100644 --- a/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/fliplr/lib/index.js @@ -16,8 +16,6 @@ * limitations under the License. */ -/* eslint-disable stdlib/jsdoc-doctest */ - 'use strict'; /**