From 9e31f2fa185f4b7b58329eafaf2f122017a2cd09 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Sat, 6 Dec 2025 14:54:07 +0500 Subject: [PATCH 1/4] feat: add ndarray/base/to-flippedud --- 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 --- --- .../ndarray/base/to-flippedud/README.md | 150 ++++++++++++++ .../base/to-flippedud/benchmark/benchmark.js | 135 +++++++++++++ .../ndarray/base/to-flippedud/docs/repl.txt | 31 +++ .../base/to-flippedud/docs/types/index.d.ts | 64 ++++++ .../base/to-flippedud/docs/types/test.ts | 63 ++++++ .../base/to-flippedud/examples/index.js | 40 ++++ .../ndarray/base/to-flippedud/lib/index.js | 56 ++++++ .../ndarray/base/to-flippedud/lib/main.js | 93 +++++++++ .../ndarray/base/to-flippedud/package.json | 71 +++++++ .../ndarray/base/to-flippedud/test/test.js | 188 ++++++++++++++++++ 10 files changed, 891 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-flippedud/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/README.md b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/README.md new file mode 100644 index 000000000000..ef4fdc041f2b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/README.md @@ -0,0 +1,150 @@ + + +# toFlippedud + +> Return a new ndarray where the order of elements along the second-to-last dimension of an input ndarray is reversed. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toFlippedud = require( '@stdlib/ndarray/base/to-flippedud' ); +``` + +#### toFlippedud( x ) + +Returns a new ndarray where the order of elements along the second-to-last dimension of an input ndarray 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 = toFlippedud( x ); +// 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. + +
+ + + + + +
+ +## Notes + +- If provided a zero-dimensional ndarray, as the ndarray has no dimensions to reverse, the function simply returns a copy the input ndarray. Similarly, if provided a one-dimensional ndarray, as the ndarray has only one dimension, the function simply returns a copy of the input ndarray. + +
+ + + + + +
+ +## Examples + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); +var toFlippedud = require( '@stdlib/ndarray/base/to-flippedud' ); + +// 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 second-to-last dimension: +var y = toFlippedud( x ); +// returns + +var a = ndarray2array( y ); +console.log( a ); +// => [ [ [ 6, 7 ], [ 4, 5 ], [ 2, 3 ], [ 0, 1 ] ], [ [ 14, 15 ], [ 12, 13 ], [ 10, 11 ], [ 8, 9 ] ] ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/benchmark/benchmark.js new file mode 100644 index 000000000000..553ea0eb9462 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/benchmark/benchmark.js @@ -0,0 +1,135 @@ +/** +* @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 zeroTo = require( '@stdlib/array/base/zero-to' ); +var baseCtor = require( '@stdlib/ndarray/base/ctor' ); +var pkg = require( './../package.json' ).name; +var toFlippedud = require( './../lib' ); + + +// MAIN // + +bench( pkg+':ndims=1', function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseCtor( 'float64', zeroTo( 10 ), [ 10 ], [ 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 5 ), [ 5 ], [ 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 20 ), [ 20 ], [ 1 ], 0, 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toFlippedud( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=2,len=100', function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseCtor( 'float64', zeroTo( 100 ), [ 10, 10 ], [ 10, 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 100 ), [ 5, 20 ], [ 20, 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 100 ), [ 20, 5 ], [ 5, 1 ], 0, 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toFlippedud( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=3,len=1000', function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseCtor( 'float64', zeroTo( 1000 ), [ 10, 10, 10 ], [ 100, 10, 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 1000 ), [ 5, 20, 10 ], [ 200, 10, 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 1000 ), [ 20, 5, 10 ], [ 50, 10, 1 ], 0, 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toFlippedud( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':ndims=2,len=10000', function benchmark( b ) { + var values; + var out; + var i; + + values = [ + baseCtor( 'float64', zeroTo( 10000 ), [ 100, 100 ], [ 100, 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 10000 ), [ 50, 200 ], [ 200, 1 ], 0, 'row-major' ), + baseCtor( 'float64', zeroTo( 10000 ), [ 200, 50 ], [ 50, 1 ], 0, 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = toFlippedud( values[ i%values.length ] ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( out ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/repl.txt new file mode 100644 index 000000000000..8474cc3b2333 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/repl.txt @@ -0,0 +1,31 @@ + +{{alias}}( x ) + Returns a new ndarray where the order of elements along the second-to-last + dimension of an input ndarray is reversed. + + Parameters + ---------- + x: ndarray + Input array. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] ) + + > x.shape + [ 3, 2 ] + > var y = {{alias}}( x ) + + > y.shape + [ 3, 2 ] + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ [ 5, 6 ], [ 3, 4 ], [ 1, 2 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/index.d.ts new file mode 100644 index 000000000000..6630fff7c8eb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Returns a new ndarray where the order of elements along the second-to-last dimension of an input ndarray is reversed. +* +* @param x - input array +* @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 = toFlippedud( x ); +* // 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 toFlippedud( x: T ): T; + + +// EXPORTS // + +export = toFlippedud; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/test.ts new file mode 100644 index 000000000000..79878d69efe1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/docs/types/test.ts @@ -0,0 +1,63 @@ +/* +* @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 toFlippedud = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const order = 'row-major'; + const sh = [ 2, 2 ]; + + toFlippedud( empty( 'float64', sh, order ) ); // $ExpectType float64ndarray + toFlippedud( empty( 'float32', sh, order ) ); // $ExpectType float32ndarray + toFlippedud( empty( 'complex128', sh, order ) ); // $ExpectType complex128ndarray + toFlippedud( empty( 'complex64', sh, order ) ); // $ExpectType complex64ndarray + toFlippedud( empty( 'int32', sh, order ) ); // $ExpectType int32ndarray + toFlippedud( empty( 'int16', sh, order ) ); // $ExpectType int16ndarray + toFlippedud( empty( 'int8', sh, order ) ); // $ExpectType int8ndarray + toFlippedud( empty( 'uint32', sh, order ) ); // $ExpectType uint32ndarray + toFlippedud( empty( 'uint16', sh, order ) ); // $ExpectType uint16ndarray + toFlippedud( empty( 'uint8', sh, order ) ); // $ExpectType uint8ndarray + toFlippedud( empty( 'uint8c', sh, order ) ); // $ExpectType uint8cndarray + toFlippedud( empty( 'generic', sh, order ) ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided an argument which is not an ndarray... +{ + toFlippedud( '10' ); // $ExpectError + toFlippedud( 10 ); // $ExpectError + toFlippedud( false ); // $ExpectError + toFlippedud( true ); // $ExpectError + toFlippedud( null ); // $ExpectError + toFlippedud( [] ); // $ExpectError + toFlippedud( {} ); // $ExpectError + toFlippedud( ( 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' ); + + toFlippedud( x, false ); // $ExpectError + toFlippedud( x, {} ); // $ExpectError + toFlippedud( x, 1, '10', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/examples/index.js new file mode 100644 index 000000000000..9872531dfb7d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/examples/index.js @@ -0,0 +1,40 @@ +/** +* @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 toFlippedud = 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 second-to-last dimension: +var y = toFlippedud( x ); +// returns + +var a = ndarray2array( y ); +console.log( a ); +// => [ [ [ 6, 7 ], [ 4, 5 ], [ 2, 3 ], [ 0, 1 ] ], [ [ 14, 15 ], [ 12, 13 ], [ 10, 11 ], [ 8, 9 ] ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/index.js new file mode 100644 index 000000000000..a84a5cec8a52 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/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 along the second-to-last dimension of an input ndarray is reversed. +* +* @module @stdlib/ndarray/base/to-flippedud +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var toFlippedud = require( '@stdlib/ndarray/base/to-flippedud' ); +* +* 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 = toFlippedud( x ); +* // returns +* +* 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-flippedud/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js new file mode 100644 index 000000000000..85bb1bb2d71f --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js @@ -0,0 +1,93 @@ +/** +* @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' ); +var ndims = require( '@stdlib/ndarray/base/ndims' ); + + +// MAIN // + +/** +* Returns a new ndarray where the order of elements along the second-to-last dimension of an input ndarray is reversed. +* +* @param {ndarray} x - input array +* @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 = toFlippedud( x ); +* // returns +* +* sh = y.shape; +* // returns [ 3, 2 ] +* +* arr = ndarray2array( y ); +* // returns [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ] +*/ +function toFlippedud( x ) { + var out; + var xr; + var N; + + // Get the number of dimensions: + N = ndims( x ); + + // Create an output ndarray with the same shape and data type as the input ndarray: + out = emptyLike( x ); + + // Check whether we were provided a zero-dimensional or a one-dimensional array... + if ( N === 0 || N === 1 ) { + // Nothing to reverse, so just copy the scalar value: + assign( [ x, out ] ); + return out; + } + // Create a view of the input ndarray with the second-to-last dimension reversed: + xr = reverseDimension( x, -2, false ); + + // Assign the elements of the reversed view to the output ndarray: + assign( [ xr, out ] ); + + return out; +} + + +// EXPORTS // + +module.exports = toFlippedud; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json new file mode 100644 index 000000000000..eed0e9716a6c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/ndarray/base/to-flippedud", + "version": "0.0.0", + "description": "Return a new ndarray where the order of elements along the second-to-last dimension of an input ndarray 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", + "slice", + "view", + "reverse", + "flipud", + "to-flippedud", + "flip", + "updown", + "rows", + "numpy.flipud" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/test/test.js new file mode 100644 index 000000000000..63a9eeb4e64a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/test/test.js @@ -0,0 +1,188 @@ +/** +* @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 scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var baseCtor = require( '@stdlib/ndarray/base/ctor' ); +var ctor = require( '@stdlib/ndarray/ctor' ); +var toFlippedud = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof toFlippedud, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'when provided a zero-dimensional input array, the function returns a new zero-dimensional array (base)', function test( t ) { + var actual; + var x; + + x = scalar2ndarray( 3.14, 'float64', 'row-major' ); + + actual = toFlippedud( x ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 0, 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.strictEqual( actual.get(), x.get(), 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + t.end(); +}); + +tape( 'when provided a zero-dimensional input array, the function returns a new zero-dimensional array (base, offset)', function test( t ) { + var actual; + var x; + + x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); + + actual = toFlippedud( x ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 0, 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.strictEqual( actual.get(), 3, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); + + t.end(); +}); + +tape( 'when provided a one-dimensional input array, the function returns a new one-dimensional array', 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 = toFlippedud( x ); + + 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 = [ 4, 6, 8, 10, 12, 14 ]; // No reversal for 1D arrays + 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 the elements of an input ndarray are reversed along the second-to-last dimension (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 = toFlippedud( x ); + + 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' ); + t.end(); +}); + +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along the second-to-last dimension (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 = toFlippedud( x ); + + 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' ); + t.end(); +}); From f90ff32b35b88c169899261bbdb20ee0656da616 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 20:46:55 -0800 Subject: [PATCH 2/4] docs: fix comment Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js index 85bb1bb2d71f..391f5546d9b8 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js @@ -74,7 +74,7 @@ function toFlippedud( x ) { // Check whether we were provided a zero-dimensional or a one-dimensional array... if ( N === 0 || N === 1 ) { - // Nothing to reverse, so just copy the scalar value: + // Nothing to reverse, so just return a copy: assign( [ x, out ] ); return out; } From d18fa7ad7f2cccc690b15e8b51bd7bb71c7b06e6 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 20:47:37 -0800 Subject: [PATCH 3/4] docs: update comment Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js index 391f5546d9b8..26be68959f98 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/lib/main.js @@ -74,7 +74,7 @@ function toFlippedud( x ) { // Check whether we were provided a zero-dimensional or a one-dimensional array... if ( N === 0 || N === 1 ) { - // Nothing to reverse, so just return a copy: + // No second-to-last dimension to reverse, so just return a copy: assign( [ x, out ] ); return out; } From 6d0a94a64d1e218f49b46f108d0701a7b84fb85f Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 7 Dec 2025 20:48:54 -0800 Subject: [PATCH 4/4] chore: update keywords Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json index eed0e9716a6c..2ef4a61aeb79 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/to-flippedud/package.json @@ -62,7 +62,6 @@ "view", "reverse", "flipud", - "to-flippedud", "flip", "updown", "rows",