From 8c8032055e03be6129f5f5d8557dea7d2673eadb Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 3 Sep 2024 13:55:39 +0500 Subject: [PATCH 01/14] feat: add ndarray/base/to-reversed --- .../ndarray/base/to-reversed/README.md | 139 +++++++ .../base/to-reversed/benchmarks/benchmark.js | 393 ++++++++++++++++++ .../ndarray/base/to-reversed/docs/repl.txt | 34 ++ .../base/to-reversed/docs/types/index.d.ts | 372 +++++++++++++++++ .../base/to-reversed/docs/types/test.ts | 62 +++ .../base/to-reversed/examples/index.js | 42 ++ .../ndarray/base/to-reversed/lib/index.js | 59 +++ .../ndarray/base/to-reversed/lib/main.js | 82 ++++ .../ndarray/base/to-reversed/package.json | 68 +++ .../ndarray/base/to-reversed/test/test.js | 370 +++++++++++++++++ 10 files changed, 1621 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/benchmarks/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md new file mode 100644 index 000000000000..91d10f941a59 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md @@ -0,0 +1,139 @@ + + +# toReversed + +> Return an ndarray where the order of elements of an input ndarray is reversed along each dimension. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); +``` + +#### toReversed( x ) + +Return an ndarray where the order of elements of an input ndarray is reversed along each dimension. + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); + +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( 'float64', buffer, shape, strides, offset, 'row-major' ); +// returns + +var y = toReversed( x ); +// returns + +console.log( y.data ); +// => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var ndarray = require( '@stdlib/ndarray/ctor' ); + +// Create data buffer: +var buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +// Define shape of the input array: +var shape = [ 3, 2 ]; + +// Define the array strides: +var strides = [ 2, 1 ]; + +// Define the index offset: +var offset = 0; + +var x = ndarray( 'float64', buf, shape, strides, offset, 'row-major' ); + +// Create a new ndarray where the order of elements of an input ndarray is reversed: +var y = toReversed( x ); + +console.log( y.data ); +// => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/benchmarks/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/benchmarks/benchmark.js new file mode 100644 index 000000000000..5b44812e2094 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/benchmarks/benchmark.js @@ -0,0 +1,393 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 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 no-restricted-syntax */ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var baseEmpty = require( '@stdlib/ndarray/base/empty' ); +var empty = require( '@stdlib/ndarray/empty' ); +var pkg = require( './../package.json' ).name; +var toReversed = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::0d,base', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [], 'row-major' ), + baseEmpty( 'float32', [], 'row-major' ), + baseEmpty( 'int32', [], 'row-major' ), + baseEmpty( 'complex128', [], 'row-major' ), + baseEmpty( 'generic', [], 'row-major' ) + ]; + + 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+'::0d,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [], { 'dtype': 'float64' } ), + empty( [], { 'dtype': 'float32' } ), + empty( [], { 'dtype': 'int32' } ), + empty( [], { 'dtype': 'complex128' } ), + empty( [], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline */ + + 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,base', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2 ], { 'dtype': 'float64' } ), + empty( [ 2 ], { 'dtype': 'float32' } ), + empty( [ 2 ], { 'dtype': 'int32' } ), + empty( [ 2 ], { 'dtype': 'complex128' } ), + empty( [ 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,base', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,base', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,base', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,base', function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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,non-base', function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = 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/base/to-reversed/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt new file mode 100644 index 000000000000..4dff74ceadb2 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( x ) + Returns an ndarray where the order of elements of an input ndarray is + reversed along each dimension. + + Parameters + ---------- + x: ndarray + Input array. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + // Define ndarray data and meta data... + > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); + > var dtype = 'float64'; + > var shape = [ 2, 2 ]; + > var sx = [ 2, 1 ]; + > var ox = 0; + > var order = 'row-major'; + + // Using ndarrays... + > var x = {{alias:@stdlib/ndarray/ctor}}( dtype, xbuf, shape, sx, ox, order ); + > var y = {{alias}}( x ); + > y.data + [ 4.0, 3.0, 2.0, 1.0 ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts new file mode 100644 index 000000000000..0c21ee7cf50c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts @@ -0,0 +1,372 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @param x - input array +* @returns output array +* +* @example +* var typedarray = require( '@stdlib/array/typed' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* 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 y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: float64ndarray ): float64ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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 ], 'float32' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: float32ndarray ): float32ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'int32' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: int32ndarray ): int32ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'int16' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: int16ndarray ): int16ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'int8' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: int8ndarray ): int8ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'uint32' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: uint32ndarray ): uint32ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'uint16' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: uint16ndarray ): uint16ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'uint8' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: uint8ndarray ): uint8ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 2, 3, 4, 5, 6 ], 'uint8c' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: uint8cndarray ): uint8cndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +*/ +declare function toReversed( x: complex128ndarray ): complex128ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +*/ +declare function toReversed( x: complex64ndarray ): complex64ndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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 = [ 1, 2, 3, 4, 5, 6 ]; +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = toReversed( x ); +* // returns +** +* console.log( y.data ); +* // => [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: genericndarray ): genericndarray; + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @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 = [ 1, 2, 3, 4, 5, 6 ]; +* var shape = [ 3, 2 ]; +* var strides = [ 2, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +** +* var y = toReversed( x ); +* // returns +* +* console.log( y.data ); +* // returns [ 6, 5, 4, 3, 2, 1 ] +*/ +declare function toReversed( x: typedndarray ): typedndarray; + + +// EXPORTS // + +export = toReversed; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts new file mode 100644 index 000000000000..5067d3ddb548 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts @@ -0,0 +1,62 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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( 'float32', sh, order ) ); // $ExpectType float32ndarray + toReversed( empty( 'complex128', sh, order ) ); // $ExpectType complex128ndarray + toReversed( empty( 'complex64', sh, order ) ); // $ExpectType complex64ndarray + toReversed( empty( 'int32', sh, order ) ); // $ExpectType int32ndarray + toReversed( empty( 'int16', sh, order ) ); // $ExpectType int16ndarray + toReversed( empty( 'int8', sh, order ) ); // $ExpectType int8ndarray + toReversed( empty( 'uint32', sh, order ) ); // $ExpectType uint32ndarray + toReversed( empty( 'uint16', sh, order ) ); // $ExpectType uint16ndarray + toReversed( empty( 'uint8', sh, order ) ); // $ExpectType uint8ndarray + toReversed( empty( 'uint8c', sh, order ) ); // $ExpectType uint8cndarray +} + +// The compiler throws an error if the function is provided an 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( x, false ); // $ExpectError + toReversed( x, {} ); // $ExpectError + toReversed( x, 1, '10', {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js new file mode 100644 index 000000000000..f2a378949040 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 toReversed = require( './../lib' ); + +// Create data buffer: +var buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; + +// Define shape of the input array: +var shape = [ 3, 2 ]; + +// Define the array strides: +var strides = [ 2, 1 ]; + +// Define the index offset: +var offset = 0; + +var x = ndarray( 'float64', buf, shape, strides, offset, 'row-major' ); + +// Create a new ndarray where the order of elements of an input ndarray is reversed: +var y = toReversed( x ); + +console.log( y.data ); +// => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js new file mode 100644 index 000000000000..e019c85f18fb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @module @stdlib/ndarray/base/to-reversed +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); +* +* // Create data buffer: +* var xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define shape of the input array: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray: +* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* +* // Create a new ndarray where the order of elements of an input ndarray is reversed: +* var y = toReversed( x ); +* +* console.log( y.data ); +* // => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js new file mode 100644 index 000000000000..d7f0651e906b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js @@ -0,0 +1,82 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var numel = require( '@stdlib/ndarray/base/numel' ); +var zeros = require( '@stdlib/array/zeros' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var reverse = require( '@stdlib/ndarray/base/reverse' ); +var assign = require( '@stdlib/ndarray/base/assign' ); + + +// MAIN // + +/** +* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* +* @param {ndarray} x - input array +* @returns {ndarray} output array +* +* @example +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* // Create data buffer: +* var xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* +* // Define shape of the input array: +* var shape = [ 3, 2 ]; +* +* // Define the array strides: +* var sx = [ 2, 1 ]; +* +* // Define the index offset: +* var ox = 0; +* +* // Create the input ndarray: +* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* +* // Create a new ndarray where the order of elements of an input ndarray is reversed: +* var y = toReversed( x ); +* +* console.log( y.data ); +* // => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +*/ +function toReversed( x ) { + var out; + var x1; + + // Create an output ndarray with the same shape and strides as the input: + out = ndarray( x.dtype, zeros( numel( x.shape ), x.dtype ), x.shape, shape2strides( x.shape ), 0, x.order ); // eslint-disable-line max-len + + // Create a reversed view of the input ndarray: + x1 = reverse( x, false ); + + // Assign the elements of the reversed input ndarray view to the output ndarray: + assign( [ x1, out ] ); + + return out; +} + + +// EXPORTS // + +module.exports = toReversed; diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json b/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json new file mode 100644 index 000000000000..16d7ea8f01e9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/ndarray/base/reverse", + "version": "0.0.0", + "description": "Return an 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", + "base", + "data", + "structure", + "vector", + "ndarray", + "matrix", + "slice", + "view", + "reverse", + "to-reversed", + "flip", + "numpy.flip" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js new file mode 100644 index 000000000000..b13daf68e197 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js @@ -0,0 +1,370 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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 isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); +var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); +var linspace = require( '@stdlib/array/linspace' ); +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 returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, linspace( 0.0, 100.0, 6 ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Float64Array([ + 100.0, + 80.0, + 60.0, + 40.0, + 20.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, contiguous, accessors)', function test( t ) { + var expected; + var start; + var stop; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + opts = { + 'dtypes': 'complex128' + }; + + start = new Complex128( 0.0, 0.0 ); + stop = new Complex128( 100.0, 100.0 ); + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, linspace( start, stop, 6, opts ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Complex128Array([ + 100.0, + 100.0, + 80.0, + 80.0, + 60.0, + 60.0, + 40.0, + 40.0, + 20.0, + 20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (column-major, contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, linspace( 0.0, 100.0, 6 ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Float64Array([ + 100.0, + 40.0, + 80.0, + 20.0, + 60.0, + 0.0 + ]); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (column-major, contiguous, accessors)', function test( t ) { + var expected; + var start; + var stop; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + opts = { + 'dtypes': 'complex128' + }; + + start = new Complex128( 0.0, 0.0 ); + stop = new Complex128( 100.0, 100.0 ); + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, linspace( start, stop, 6, opts ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Complex128Array([ + 100.0, + 100.0, + 80.0, + 80.0, + 60.0, + 60.0, + 40.0, + 40.0, + 20.0, + 20.0, + 0.0, + 0.0 + ]); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, non-contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = [ 4, 4, 1 ]; + o = 1; + + x = ndarray( dt, linspace( 0.0, 100.0, 11 ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Float64Array([ + 100.0, + 90.0, + 60.0, + 50.0, + 20.0, + 10.0 + ]); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, non-contiguous, accessors)', function test( t ) { + var expected; + var start; + var stop; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + opts = { + 'dtypes': 'complex128' + }; + + start = new Complex128( 0.0, 0.0 ); + stop = new Complex128( 100.0, 100.0 ); + + dt = 'complex128'; + ord = 'row-major'; + sh = [ 3, 1, 2 ]; + st = [ 4, 4, 1 ]; + o = 1; + + x = ndarray( dt, linspace( start, stop, 11, opts ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Complex128Array([ + 100.0, + 100.0, + 90.0, + 90.0, + 60.0, + 60.0, + 50.0, + 50.0, + 20.0, + 20.0, + 10.0, + 10.0 + ]); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (column-major, non-contiguous)', function test( t ) { + var expected; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + dt = 'float64'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = [ 1, 6, 6 ]; + o = 1; + + x = ndarray( dt, linspace( 0.0, 100.0, 11 ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Float64Array([ + 90.0, + 30.0, + 80.0, + 20.0, + 70.0, + 10.0 + ]); + + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, non-contiguous, accessors)', function test( t ) { + var expected; + var start; + var stop; + var opts; + var ord; + var sh; + var st; + var dt; + var o; + var x; + var y; + + opts = { + 'dtypes': 'complex128' + }; + + start = new Complex128( 0.0, 0.0 ); + stop = new Complex128( 100.0, 100.0 ); + + dt = 'complex128'; + ord = 'column-major'; + sh = [ 3, 1, 2 ]; + st = [ 1, 6, 6 ]; + o = 1; + + x = ndarray( dt, linspace( start, stop, 11, opts ), sh, st, o, ord ); + + y = toReversed( x ); + + expected = new Complex128Array([ + 90.0, + 90.0, + 30.0, + 30.0, + 80.0, + 80.0, + 20.0, + 20.0, + 70.0, + 70.0, + 10.0, + 10.0 + ]); + + t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + t.end(); +}); From 4b89308533a0e5edc0cc95c1fa8d91205c70fb7b Mon Sep 17 00:00:00 2001 From: headlessNode Date: Tue, 3 Sep 2024 14:29:35 +0500 Subject: [PATCH 02/14] fix: add required module in readme examples section --- lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md index 91d10f941a59..c021c9d99323 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md @@ -88,6 +88,7 @@ The function accepts the following arguments: ```javascript var ndarray = require( '@stdlib/ndarray/ctor' ); +var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); // Create data buffer: var buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; From 1f020647bce8eba7e10dbbaf4368306863d3c328 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 00:21:58 -0700 Subject: [PATCH 03/14] refactor: use accessor functions and ensure we return an ndarray of the same "kind" --- .../ndarray/base/to-reversed/lib/index.js | 11 ++--- .../ndarray/base/to-reversed/lib/main.js | 43 ++++++++++++++----- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js index e019c85f18fb..e3df08d715e3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js @@ -19,19 +19,20 @@ 'use strict'; /** -* Return an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* Return a new ndarray where the order of elements of an input ndarray is reversed along each dimension. * * @module @stdlib/ndarray/base/to-reversed * * @example +* var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); * * // Create data buffer: -* var xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * * // Define shape of the input array: -* var shape = [ 3, 2 ]; +* var sh = [ 3, 2 ]; * * // Define the array strides: * var sx = [ 2, 1 ]; @@ -40,9 +41,9 @@ * var ox = 0; * * // Create the input ndarray: -* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* var x = ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * -* // Create a new ndarray where the order of elements of an input ndarray is reversed: +* // Create a new ndarray where the order of elements of the input ndarray is reversed: * var y = toReversed( x ); * * console.log( y.data ); diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js index d7f0651e906b..066ab326cb05 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js @@ -22,28 +22,37 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var numel = require( '@stdlib/ndarray/base/numel' ); +var dtype = require( '@stdlib/ndarray/base/dtype' ); +var shape = require( '@stdlib/ndarray/base/shape' ); +var order = require( '@stdlib/ndarray/base/order' ); var zeros = require( '@stdlib/array/zeros' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); var reverse = require( '@stdlib/ndarray/base/reverse' ); var assign = require( '@stdlib/ndarray/base/assign' ); +var defaults = require( '@stdlib/ndarray/defaults' ); + + +// VARIABLES // + +var ORDER = defaults( 'order' ); // MAIN // /** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension. * * @param {ndarray} x - input array * @returns {ndarray} output array * * @example +* var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); * * // Create data buffer: -* var xbuf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); * * // Define shape of the input array: -* var shape = [ 3, 2 ]; +* var sh = [ 3, 2 ]; * * // Define the array strides: * var sx = [ 2, 1 ]; @@ -52,26 +61,38 @@ var assign = require( '@stdlib/ndarray/base/assign' ); * var ox = 0; * * // Create the input ndarray: -* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' ); +* var x = ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); * -* // Create a new ndarray where the order of elements of an input ndarray is reversed: +* // Create a new ndarray where the order of elements of the input ndarray is reversed: * var y = toReversed( x ); * * console.log( y.data ); * // => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] */ function toReversed( x ) { + var ctor; var out; - var x1; + var ord; + var sh; + var dt; + var xr; - // Create an output ndarray with the same shape and strides as the input: - out = ndarray( x.dtype, zeros( numel( x.shape ), x.dtype ), x.shape, shape2strides( x.shape ), 0, x.order ); // eslint-disable-line max-len + // Extract ndarray meta data: + dt = dtype( x ); + sh = shape( x, true ); + ord = order( x ) || ORDER; // Create a reversed view of the input ndarray: - x1 = reverse( x, false ); + xr = reverse( x, false ); + + // Resolve the output array constructor: + ctor = x.constructor; + + // Create an output ndarray with the same shape and data type as the input ndarray: + out = new ctor( dt, zeros( numel( sh ), dt ), sh, shape2strides( sh, ord ), 0, ord ); // eslint-disable-line max-len // Assign the elements of the reversed input ndarray view to the output ndarray: - assign( [ x1, out ] ); + assign( [ xr, out ] ); return out; } From e2a943e4fa5b65c4d6c9ac3cccfb584e7c478728 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:22:53 -0700 Subject: [PATCH 04/14] docs: update examples and description --- .../ndarray/base/to-reversed/README.md | 66 +++++++++++++------ .../base/to-reversed/examples/index.js | 52 +++++++++++---- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md index c021c9d99323..8ea96d725ab0 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md @@ -20,7 +20,7 @@ limitations under the License. # toReversed -> Return an ndarray where the order of elements of an input ndarray is reversed along each dimension. +> Return a new ndarray where the order of elements of an input ndarray is reversed along each dimension. @@ -42,24 +42,31 @@ var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); #### toReversed( x ) -Return an ndarray where the order of elements of an input ndarray is reversed along each dimension. +Returns a new ndarray where the order of elements of an input ndarray 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( 'float64', buffer, shape, strides, offset, 'row-major' ); +var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); // returns +var sh = x.shape; +// returns [ 3, 2 ] + var y = toReversed( x ); // returns -console.log( y.data ); -// => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +sh = y.shape; +// returns [ 3, 2 ] + +arr = ndarray2array( y ); +// returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] ``` The function accepts the following arguments: @@ -87,28 +94,49 @@ The function accepts the following arguments: ```javascript -var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); -// Create data buffer: -var buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +// Create a linear ndarray buffer: +var buf = zeroTo( 16 ); -// Define shape of the input array: -var shape = [ 3, 2 ]; +// Create a one-dimensional ndarray: +var x1 = array( buf, { + 'shape': [ 16 ] +}); -// Define the array strides: -var strides = [ 2, 1 ]; +// Reverse element order: +var y1 = toReversed( x1, false ); +// returns -// Define the index offset: -var offset = 0; +var a1 = ndarray2array( y1 ); +// returns [ 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ] -var x = ndarray( 'float64', buf, shape, strides, offset, 'row-major' ); +// Create a two-dimensional ndarray: +var x2 = array( buf, { + 'shape': [ 4, 4 ] +}); -// Create a new ndarray where the order of elements of an input ndarray is reversed: -var y = toReversed( x ); +// Reverse element order: +var y2 = toReversed( x2, false ); +// returns + +var a2 = ndarray2array( y2 ); +// returns [ [ 15, 14, 13, 12 ], [ 11, 10, 9, 8 ], [ 7, 6, 5, 4 ], [ 3, 2, 1, 0 ] ] + +// Create a three-dimensional ndarray: +var x3 = array( buf, { + 'shape': [ 2, 4, 2 ] +}); + +// Reverse element order: +var y3 = toReversed( x3, false ); +// returns -console.log( y.data ); -// => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +var a3 = ndarray2array( y3 ); +// returns [ [ [ 15, 14 ], [ 13, 12 ], [ 11, 10 ], [ 9, 8 ] ], [ [ 7, 6 ], [ 5, 4 ], [ 3, 2 ], [ 1, 0 ] ] ] ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js index f2a378949040..076aabf41e2d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/examples/index.js @@ -18,25 +18,49 @@ 'use strict'; -var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var zeroTo = require( '@stdlib/array/base/zero-to' ); var toReversed = require( './../lib' ); -// Create data buffer: -var buf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; +// Create a linear ndarray buffer: +var buf = zeroTo( 16 ); -// Define shape of the input array: -var shape = [ 3, 2 ]; +// Create a one-dimensional ndarray: +var x1 = array( buf, { + 'shape': [ 16 ] +}); -// Define the array strides: -var strides = [ 2, 1 ]; +// Reverse element order: +var y1 = toReversed( x1, false ); +// returns -// Define the index offset: -var offset = 0; +var a1 = ndarray2array( y1 ); +console.log( a1 ); +// => [ 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ] -var x = ndarray( 'float64', buf, shape, strides, offset, 'row-major' ); +// Create a two-dimensional ndarray: +var x2 = array( buf, { + 'shape': [ 4, 4 ] +}); -// Create a new ndarray where the order of elements of an input ndarray is reversed: -var y = toReversed( x ); +// Reverse element order: +var y2 = toReversed( x2, false ); +// returns -console.log( y.data ); -// => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +var a2 = ndarray2array( y2 ); +console.log( a2 ); +// => [ [ 15, 14, 13, 12 ], [ 11, 10, 9, 8 ], [ 7, 6, 5, 4 ], [ 3, 2, 1, 0 ] ] + +// Create a three-dimensional ndarray: +var x3 = array( buf, { + 'shape': [ 2, 4, 2 ] +}); + +// Reverse element order: +var y3 = toReversed( x3, false ); +// returns + +var a3 = ndarray2array( y3 ); +console.log( a3 ); +// => [ [ [ 15, 14 ], [ 13, 12 ], [ 11, 10 ], [ 9, 8 ] ], [ [ 7, 6 ], [ 5, 4 ], [ 3, 2 ], [ 1, 0 ] ] ] From 362411254e0bbdf2f093b15190be032b5e4f8da6 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:26:15 -0700 Subject: [PATCH 05/14] fix: update package name and description --- .../@stdlib/ndarray/base/to-reversed/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json b/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json index 16d7ea8f01e9..83039614a287 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/ndarray/base/reverse", + "name": "@stdlib/ndarray/base/to-reversed", "version": "0.0.0", - "description": "Return an ndarray where the order of elements of an input ndarray is reversed along each dimension.", + "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", From 6c7555a58f547882cacbf2436699547531643e34 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:28:56 -0700 Subject: [PATCH 06/14] docs: update description and examples --- .../ndarray/base/to-reversed/docs/repl.txt | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt index 4dff74ceadb2..c45dc1017181 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( x ) - Returns an ndarray where the order of elements of an input ndarray is + Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension. Parameters @@ -15,19 +15,16 @@ Examples -------- - // Define ndarray data and meta data... - > var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0 ] ); - > var dtype = 'float64'; - > var shape = [ 2, 2 ]; - > var sx = [ 2, 1 ]; - > var ox = 0; - > var order = 'row-major'; - - // Using ndarrays... - > var x = {{alias:@stdlib/ndarray/ctor}}( dtype, xbuf, shape, sx, ox, order ); - > var y = {{alias}}( x ); - > y.data - [ 4.0, 3.0, 2.0, 1.0 ] + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + + > x.shape + [ 2, 2 ] + > var y = {{alias}}( x ) + + > y.shape + [ 2, 2 ] + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ [ 4, 3 ], [ 2, 1 ] ] See Also -------- From dafc9613d8169ac97cb7a217a3bcd79570c54ad6 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:33:12 -0700 Subject: [PATCH 07/14] docs: update examples --- .../ndarray/base/to-reversed/lib/index.js | 32 +++++++------- .../ndarray/base/to-reversed/lib/main.js | 44 ++++++++++--------- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js index e3df08d715e3..e8bc2ac40d52 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/index.js @@ -24,30 +24,32 @@ * @module @stdlib/ndarray/base/to-reversed * * @example -* var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * var toReversed = require( '@stdlib/ndarray/base/to-reversed' ); * -* // Create data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* 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; * -* // Define shape of the input array: -* var sh = [ 3, 2 ]; +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns * -* // Define the array strides: -* var sx = [ 2, 1 ]; +* var sh = x.shape; +* // returns [ 3, 2 ] * -* // Define the index offset: -* var ox = 0; +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* // Create the input ndarray: -* var x = ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Create a new ndarray where the order of elements of the input ndarray is reversed: * var y = toReversed( x ); +* // returns +* +* sh = y.shape; +* // returns [ 3, 2 ] * -* console.log( y.data ); -* // => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +* arr = ndarray2array( y ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js index 066ab326cb05..b8775ab16619 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js @@ -22,9 +22,9 @@ var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); var numel = require( '@stdlib/ndarray/base/numel' ); -var dtype = require( '@stdlib/ndarray/base/dtype' ); -var shape = require( '@stdlib/ndarray/base/shape' ); -var order = require( '@stdlib/ndarray/base/order' ); +var getDType = require( '@stdlib/ndarray/base/dtype' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); var zeros = require( '@stdlib/array/zeros' ); var reverse = require( '@stdlib/ndarray/base/reverse' ); var assign = require( '@stdlib/ndarray/base/assign' ); @@ -45,29 +45,31 @@ var ORDER = defaults( 'order' ); * @returns {ndarray} output array * * @example -* var Float64Array = require( '@stdlib/array/float64' ); * var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); * -* // Create data buffer: -* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); +* 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; * -* // Define shape of the input array: -* var sh = [ 3, 2 ]; +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns * -* // Define the array strides: -* var sx = [ 2, 1 ]; +* var sh = x.shape; +* // returns [ 3, 2 ] * -* // Define the index offset: -* var ox = 0; +* var arr = ndarray2array( x ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] * -* // Create the input ndarray: -* var x = ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' ); -* -* // Create a new ndarray where the order of elements of the input ndarray is reversed: * var y = toReversed( x ); +* // returns +* +* sh = y.shape; +* // returns [ 3, 2 ] * -* console.log( y.data ); -* // => [ 6.0, 5.0, 4.0, 3.0, 2.0, 1.0 ] +* arr = ndarray2array( y ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] */ function toReversed( x ) { var ctor; @@ -78,9 +80,9 @@ function toReversed( x ) { var xr; // Extract ndarray meta data: - dt = dtype( x ); - sh = shape( x, true ); - ord = order( x ) || ORDER; + dt = getDType( x ); + sh = getShape( x, true ); + ord = getOrder( x ) || ORDER; // Create a reversed view of the input ndarray: xr = reverse( x, false ); From 96bf70e41cb7156a119a7f8737d93da47b75611d Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:37:36 -0700 Subject: [PATCH 08/14] refactor: simplify allocation logic --- .../ndarray/base/to-reversed/lib/main.js | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js index b8775ab16619..99be2504d934 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/lib/main.js @@ -20,20 +20,9 @@ // MODULES // -var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); -var numel = require( '@stdlib/ndarray/base/numel' ); -var getDType = require( '@stdlib/ndarray/base/dtype' ); -var getShape = require( '@stdlib/ndarray/base/shape' ); -var getOrder = require( '@stdlib/ndarray/base/order' ); -var zeros = require( '@stdlib/array/zeros' ); +var emptyLike = require( '@stdlib/ndarray/base/empty-like' ); var reverse = require( '@stdlib/ndarray/base/reverse' ); var assign = require( '@stdlib/ndarray/base/assign' ); -var defaults = require( '@stdlib/ndarray/defaults' ); - - -// VARIABLES // - -var ORDER = defaults( 'order' ); // MAIN // @@ -72,26 +61,14 @@ var ORDER = defaults( 'order' ); * // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] */ function toReversed( x ) { - var ctor; var out; - var ord; - var sh; - var dt; var xr; - // Extract ndarray meta data: - dt = getDType( x ); - sh = getShape( x, true ); - ord = getOrder( x ) || ORDER; - // Create a reversed view of the input ndarray: xr = reverse( x, false ); - // Resolve the output array constructor: - ctor = x.constructor; - // Create an output ndarray with the same shape and data type as the input ndarray: - out = new ctor( dt, zeros( numel( sh ), dt ), sh, shape2strides( sh, ord ), 0, ord ); // eslint-disable-line max-len + out = emptyLike( x ); // Assign the elements of the reversed input ndarray view to the output ndarray: assign( [ xr, out ] ); From 68584693f367dcc1a1c298b945fd648a270b8f42 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:46:41 -0700 Subject: [PATCH 09/14] refactor: simplify type declarations --- .../base/to-reversed/docs/types/index.d.ts | 332 +----------------- 1 file changed, 12 insertions(+), 320 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts index 0c21ee7cf50c..8630acfc231d 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/index.d.ts @@ -20,10 +20,10 @@ /// -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; +import { ndarray } from '@stdlib/types/ndarray'; /** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. +* Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension. * * @param x - input array * @returns output array @@ -31,6 +31,7 @@ import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndar * @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 ]; @@ -40,331 +41,22 @@ import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndar * var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); * // returns * -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: float64ndarray ): float64ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: float32ndarray ): float32ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: int32ndarray ): int32ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: int16ndarray ): int16ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: int8ndarray ): int8ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: uint32ndarray ): uint32ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: uint16ndarray ): uint16ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -* -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: uint8ndarray ): uint8ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; +* var sh = x.shape; +* // returns [ 3, 2 ] * -* var x = ndarray( 'uint8c', 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 * -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: uint8cndarray ): uint8cndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -*/ -declare function toReversed( x: complex128ndarray ): complex128ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -*/ -declare function toReversed( x: complex64ndarray ): complex64ndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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 = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var y = toReversed( x ); -* // returns -** -* console.log( y.data ); -* // => [ 6, 5, 4, 3, 2, 1 ] -*/ -declare function toReversed( x: genericndarray ): genericndarray; - -/** -* Returns an ndarray where the order of elements of an input ndarray is reversed along each dimension. -* -* @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 = [ 1, 2, 3, 4, 5, 6 ]; -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); -* // returns -** -* var y = toReversed( x ); -* // returns +* sh = y.shape; +* // returns [ 3, 2 ] * -* console.log( y.data ); -* // returns [ 6, 5, 4, 3, 2, 1 ] +* arr = ndarray2array( y ); +* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] */ -declare function toReversed( x: typedndarray ): typedndarray; +declare function toReversed( x: T ): T; // EXPORTS // From d6fa906a6b0cb068700646795c7465dd0b1183a7 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:47:41 -0700 Subject: [PATCH 10/14] test: add test case --- .../@stdlib/ndarray/base/to-reversed/docs/types/test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts index 5067d3ddb548..e4d9a460c5ad 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/docs/types/test.ts @@ -38,6 +38,7 @@ import toReversed = require( './index' ); toReversed( empty( 'uint16', sh, order ) ); // $ExpectType uint16ndarray toReversed( empty( 'uint8', sh, order ) ); // $ExpectType uint8ndarray toReversed( empty( 'uint8c', sh, order ) ); // $ExpectType uint8cndarray + toReversed( empty( 'generic', sh, order ) ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided an argument which is not an ndarray... From 61a3971253f854dfc6712178877f670aac5c4fe3 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:49:12 -0700 Subject: [PATCH 11/14] refactor: simplify type declarations --- .../base/reverse/docs/types/index.d.ts | 436 +----------------- .../ndarray/base/reverse/docs/types/test.ts | 2 + 2 files changed, 4 insertions(+), 434 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/index.d.ts index 84473380aa6c..55facc3dd5da 100644 --- a/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/index.d.ts @@ -20,7 +20,7 @@ /// -import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, complex128ndarray, complex64ndarray } from '@stdlib/types/ndarray'; +import { ndarray } from '@stdlib/types/ndarray'; /** * Returns a view of an input ndarray in which the order of elements along each dimension is reversed. @@ -57,439 +57,7 @@ import { typedndarray, genericndarray, float64ndarray, float32ndarray, int32ndar * arr = ndarray2array( y ); * // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] */ -declare function reverse( x: float64ndarray, writable: boolean ): float64ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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 ], 'float32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'float32', 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 = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6.0, 5.0 ], [ 4.0, 3.0 ], [ 2.0, 1.0 ] ] -*/ -declare function reverse( x: float32ndarray, writable: boolean ): float32ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'int32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: int32ndarray, writable: boolean ): int32ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'int16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: int16ndarray, writable: boolean ): int16ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'int8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: int8ndarray, writable: boolean ): int8ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'uint32' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: uint32ndarray, writable: boolean ): uint32ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'uint16' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: uint16ndarray, writable: boolean ): uint16ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'uint8' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: uint8ndarray, writable: boolean ): uint8ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 2, 3, 4, 5, 6 ], 'uint8c' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var arr = ndarray2array( x ); -* // returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: uint8cndarray, writable: boolean ): uint8cndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex128' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -*/ -declare function reverse( x: complex128ndarray, writable: boolean ): complex128ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ], 'complex64' ); -* var shape = [ 3, 2 ]; -* var strides = [ 2, 1 ]; -* var offset = 0; -* -* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); -* // returns -* -* var sh = x.shape; -* // returns [ 3, 2 ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -*/ -declare function reverse( x: complex64ndarray, writable: boolean ): complex64ndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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 = [ 1, 2, 3, 4, 5, 6 ]; -* 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, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: genericndarray, writable: boolean ): genericndarray; - -/** -* Returns a view of an input ndarray in which the order of elements along each dimension is reversed. -* -* @param x - input array -* @param writable - boolean indicating whether a returned array should be writable -* @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 = [ 1, 2, 3, 4, 5, 6 ]; -* 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, 2 ], [ 3, 4 ], [ 5, 6 ] ] -* -* var y = reverse( x, false ); -* // returns -* -* sh = y.shape; -* // returns [ 3, 2 ] -* -* arr = ndarray2array( y ); -* // returns [ [ 6, 5 ], [ 4, 3 ], [ 2, 1 ] ] -*/ -declare function reverse( x: typedndarray, writable: boolean ): typedndarray; +declare function reverse( x: T, writable: boolean ): T; // EXPORTS // diff --git a/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/test.ts index 919526faa039..bbfb9d494dbf 100644 --- a/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/base/reverse/docs/types/test.ts @@ -38,6 +38,7 @@ import reverse = require( './index' ); reverse( empty( 'uint16', sh, order ), false ); // $ExpectType uint16ndarray reverse( empty( 'uint8', sh, order ), false ); // $ExpectType uint8ndarray reverse( empty( 'uint8c', sh, order ), false ); // $ExpectType uint8cndarray + reverse( empty( 'generic', sh, order ), false ); // $ExpectType genericndarray reverse( empty( 'float64', sh, order ), true ); // $ExpectType float64ndarray reverse( empty( 'float32', sh, order ), true ); // $ExpectType float32ndarray @@ -50,6 +51,7 @@ import reverse = require( './index' ); reverse( empty( 'uint16', sh, order ), true ); // $ExpectType uint16ndarray reverse( empty( 'uint8', sh, order ), true ); // $ExpectType uint8ndarray reverse( empty( 'uint8c', sh, order ), true ); // $ExpectType uint8cndarray + reverse( empty( 'generic', sh, order ), false ); // $ExpectType genericndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... From 47b343e65ebff7ccaafc85c1a059c318d17b1b20 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:56:06 -0700 Subject: [PATCH 12/14] test: update tests to match `ndarray/base/reverse` --- .../ndarray/base/to-reversed/test/test.js | 393 ++++++------------ 1 file changed, 123 insertions(+), 270 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js index b13daf68e197..4e552c5e36e6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js @@ -21,15 +21,14 @@ // MODULES // var tape = require( 'tape' ); -var isSameComplex128Array = require( '@stdlib/assert/is-same-complex128array' ); -var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); -var Complex128Array = require( '@stdlib/array/complex128' ); -var Float64Array = require( '@stdlib/array/float64' ); -var Complex128 = require( '@stdlib/complex/float64/ctor' ); -var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); -var strides2offset = require( '@stdlib/ndarray/base/strides2offset' ); -var linspace = require( '@stdlib/array/linspace' ); -var ndarray = require( '@stdlib/ndarray/ctor' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +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 toReversed = require( './../lib' ); @@ -41,330 +40,184 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, contiguous)', function test( t ) { - var expected; - var ord; - var sh; - var st; - var dt; - var o; +tape( 'when provided a zero-dimensional input array, the function returns a new zero-dimensional array (base)', function test( t ) { + var actual; var x; - var y; - dt = 'float64'; - ord = 'row-major'; - sh = [ 3, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); + x = scalar2ndarray( 3.14, 'float64', 'row-major' ); - x = ndarray( dt, linspace( 0.0, 100.0, 6 ), sh, st, o, ord ); + actual = toReversed( 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' ); - y = toReversed( x ); - - expected = new Float64Array([ - 100.0, - 80.0, - 60.0, - 40.0, - 20.0, - 0.0 - ]); - - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, contiguous, accessors)', function test( t ) { - var expected; - var start; - var stop; - var opts; - var ord; - var sh; - var st; - var dt; - var o; +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; - var y; - opts = { - 'dtypes': 'complex128' - }; + x = new baseCtor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - start = new Complex128( 0.0, 0.0 ); - stop = new Complex128( 100.0, 100.0 ); + actual = toReversed( 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' ); - dt = 'complex128'; - ord = 'row-major'; - sh = [ 3, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, linspace( start, stop, 6, opts ), sh, st, o, ord ); - - y = toReversed( x ); - - expected = new Complex128Array([ - 100.0, - 100.0, - 80.0, - 80.0, - 60.0, - 60.0, - 40.0, - 40.0, - 20.0, - 20.0, - 0.0, - 0.0 - ]); - - t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (column-major, contiguous)', function test( t ) { - var expected; - var ord; - var sh; - var st; - var dt; - var o; +tape( 'when provided a zero-dimensional input array, the function returns a new zero-dimensional array (non-base, offset, read-only)', function test( t ) { + var actual; var x; - var y; - - dt = 'float64'; - ord = 'column-major'; - sh = [ 3, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, linspace( 0.0, 100.0, 6 ), sh, st, o, ord ); - y = toReversed( x ); + x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - expected = new Float64Array([ - 100.0, - 40.0, - 80.0, - 20.0, - 60.0, - 0.0 - ]); + actual = toReversed( 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.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (column-major, contiguous, accessors)', function test( t ) { - var expected; - var start; - var stop; - var opts; - var ord; - var sh; - var st; - var dt; - var o; +tape( 'when provided a zero-dimensional input array, the function returns a new zero-dimensional array (non-base, offset, writable)', function test( t ) { + var actual; var x; - var y; - opts = { - 'dtypes': 'complex128' - }; + x = new ctor( 'float64', typedarray( zeroTo( 4 ), 'float64' ), [], [ 0 ], 3, 'row-major' ); - start = new Complex128( 0.0, 0.0 ); - stop = new Complex128( 100.0, 100.0 ); + actual = toReversed( 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.strictEqual( isReadOnly( actual ), false, 'returns expected value' ); - dt = 'complex128'; - ord = 'row-major'; - sh = [ 3, 1, 2 ]; - st = shape2strides( sh, ord ); - o = strides2offset( sh, st ); - - x = ndarray( dt, linspace( start, stop, 6, opts ), sh, st, o, ord ); - - y = toReversed( x ); - - expected = new Complex128Array([ - 100.0, - 100.0, - 80.0, - 80.0, - 60.0, - 60.0, - 40.0, - 40.0, - 20.0, - 20.0, - 0.0, - 0.0 - ]); - - t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, non-contiguous)', function test( t ) { +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along each dimension (ndims=1)', function test( t ) { var expected; + var actual; + var buf; var ord; var sh; var st; - var dt; var o; var x; - var y; + var i; - dt = 'float64'; + buf = typedarray( zeroTo( 30 ), 'float64' ); + sh = [ 6 ]; + st = [ 2 ]; + o = 4; ord = 'row-major'; - sh = [ 3, 1, 2 ]; - st = [ 4, 4, 1 ]; - o = 1; - x = ndarray( dt, linspace( 0.0, 100.0, 11 ), sh, st, o, ord ); + x = new ctor( 'float64', buf, sh, st, o, ord ); - y = toReversed( x ); + actual = toReversed( x ); - expected = new Float64Array([ - 100.0, - 90.0, - 60.0, - 50.0, - 20.0, - 10.0 - ]); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( actual.ndims, 1, 'returns expected value' ); + t.strictEqual( actual.length, 6, 'returns expected value' ); + t.strictEqual( actual.dtype, x.dtype, 'returns expected value' ); + t.notEqual( actual.data, x.data, 'returns expected value' ); - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + expected = [ 14, 12, 10, 8, 6, 4 ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( actual.iget( i ), expected[ i ], 'returns expected value' ); + } t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, non-contiguous, accessors)', function test( t ) { +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along each dimension (ndims=2)', function test( t ) { var expected; - var start; - var stop; - var opts; + var actual; + var buf; var ord; var sh; var st; - var dt; var o; var x; - var y; - opts = { - 'dtypes': 'complex128' - }; - - start = new Complex128( 0.0, 0.0 ); - stop = new Complex128( 100.0, 100.0 ); - - dt = 'complex128'; + buf = typedarray( zeroTo( 30 ), 'float64' ); + sh = [ 4, 3 ]; + st = [ 6, 2 ]; + o = 4; ord = 'row-major'; - sh = [ 3, 1, 2 ]; - st = [ 4, 4, 1 ]; - o = 1; - - x = ndarray( dt, linspace( start, stop, 11, opts ), sh, st, o, ord ); - - y = toReversed( x ); - - expected = new Complex128Array([ - 100.0, - 100.0, - 90.0, - 90.0, - 60.0, - 60.0, - 50.0, - 50.0, - 20.0, - 20.0, - 10.0, - 10.0 - ]); - - t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); - t.end(); -}); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (column-major, non-contiguous)', function test( t ) { - var expected; - var ord; - var sh; - var st; - var dt; - var o; - var x; - var y; + x = new ctor( 'float64', buf, sh, st, o, ord ); - dt = 'float64'; - ord = 'column-major'; - sh = [ 3, 1, 2 ]; - st = [ 1, 6, 6 ]; - o = 1; + actual = toReversed( x ); - x = ndarray( dt, linspace( 0.0, 100.0, 11 ), sh, st, o, ord ); + 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' ); - y = toReversed( x ); - - expected = new Float64Array([ - 90.0, - 30.0, - 80.0, - 20.0, - 70.0, - 10.0 - ]); - - t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + expected = [ + [ 26, 24, 22 ], + [ 20, 18, 16 ], + [ 14, 12, 10 ], + [ 8, 6, 4 ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function returns an ndarray where the elements of an input ndarray are reversed along each dimension (row-major, non-contiguous, accessors)', function test( t ) { +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along each dimension (ndims=3)', function test( t ) { var expected; - var start; - var stop; - var opts; + var actual; + var buf; var ord; var sh; var st; - var dt; var o; var x; - var y; - - opts = { - 'dtypes': 'complex128' - }; - - start = new Complex128( 0.0, 0.0 ); - stop = new Complex128( 100.0, 100.0 ); - - dt = 'complex128'; - ord = 'column-major'; - sh = [ 3, 1, 2 ]; - st = [ 1, 6, 6 ]; - o = 1; - - x = ndarray( dt, linspace( start, stop, 11, opts ), sh, st, o, ord ); - - y = toReversed( x ); - - expected = new Complex128Array([ - 90.0, - 90.0, - 30.0, - 30.0, - 80.0, - 80.0, - 20.0, - 20.0, - 70.0, - 70.0, - 10.0, - 10.0 - ]); - - t.strictEqual( isSameComplex128Array( y.data, expected ), true, 'returns expected value' ); + + 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 = toReversed( 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 = [ + [ + [ 56, 54, 52 ], + [ 50, 48, 46 ], + [ 44, 42, 40 ], + [ 38, 36, 34 ] + ], + [ + [ 32, 30, 28 ], + [ 26, 24, 22 ], + [ 20, 18, 16 ], + [ 14, 12, 10 ] + ] + ]; + actual = ndarray2array( actual ); + t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); From 145e34bb9779c68b9001a2b9fda1d4521eacdaa1 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 01:57:43 -0700 Subject: [PATCH 13/14] test: fix grammar --- .../@stdlib/ndarray/base/to-reversed/test/test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js b/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js index 4e552c5e36e6..2e53be75ea58 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/test/test.js @@ -106,7 +106,7 @@ tape( 'when provided a zero-dimensional input array, the function returns a new t.end(); }); -tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along each dimension (ndims=1)', function test( t ) { +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray is reversed along each dimension (ndims=1)', function test( t ) { var expected; var actual; var buf; @@ -140,7 +140,7 @@ tape( 'the function returns a new ndarray where the order of the elements of an t.end(); }); -tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along each dimension (ndims=2)', function test( t ) { +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray is reversed along each dimension (ndims=2)', function test( t ) { var expected; var actual; var buf; @@ -177,7 +177,7 @@ tape( 'the function returns a new ndarray where the order of the elements of an t.end(); }); -tape( 'the function returns a new ndarray where the order of the elements of an input ndarray are reversed along each dimension (ndims=3)', function test( t ) { +tape( 'the function returns a new ndarray where the order of the elements of an input ndarray is reversed along each dimension (ndims=3)', function test( t ) { var expected; var actual; var buf; From ebadaa9788c1e7fcfdc4d03d4df2f09ef6a27702 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Sat, 7 Sep 2024 02:00:52 -0700 Subject: [PATCH 14/14] docs: fix example --- lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md index 8ea96d725ab0..bac1913676b6 100644 --- a/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/to-reversed/README.md @@ -59,6 +59,9 @@ var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); var sh = x.shape; // returns [ 3, 2 ] +var arr = ndarray2array( x ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] + var y = toReversed( x ); // returns