From 019b464ff35ae88d6b09320db63b83493ee94197 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 22 Apr 2026 02:46:41 +0500 Subject: [PATCH 1/8] feat: add ndarray/rot90 --- .../@stdlib/ndarray/rot90/README.md | 136 ++++ .../ndarray/rot90/benchmark/benchmark.js | 196 +++++ .../@stdlib/ndarray/rot90/docs/repl.txt | 37 + .../ndarray/rot90/docs/types/index.d.ts | 64 ++ .../@stdlib/ndarray/rot90/docs/types/test.ts | 93 +++ .../@stdlib/ndarray/rot90/examples/index.js | 29 + .../@stdlib/ndarray/rot90/lib/index.js | 44 + .../@stdlib/ndarray/rot90/lib/main.js | 92 +++ .../@stdlib/ndarray/rot90/package.json | 66 ++ .../@stdlib/ndarray/rot90/test/test.js | 766 ++++++++++++++++++ 10 files changed, 1523 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/rot90/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/rot90/README.md b/lib/node_modules/@stdlib/ndarray/rot90/README.md new file mode 100644 index 000000000000..fd40f97ec7ea --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/README.md @@ -0,0 +1,136 @@ + + +# rot90 + +> Return a **read-only** view of an input ndarray rotated `90` degrees in a specified plane. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var rot90 = require( '@stdlib/ndarray/rot90' ); +``` + +#### rot90( x\[, options] ) + +Returns a read-only view of an input [`ndarray`][@stdlib/ndarray/ctor] rotated `90` degrees in a specified plane. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] + +var y = rot90( x ); +// returns [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ] +``` + +The function accepts the following arguments: + +- **x**: input [`ndarray`][@stdlib/ndarray/ctor]. +- **options**: function options. + +The function accepts the following options: + +- **k**: number of times to rotate by `90` degrees. Positive values rotate counterclockwise. Negative values rotate clockwise. Default: `1`. +- **dims**: dimension indices defining the plane of rotation. Must contain exactly two unique dimension indices. If a dimension index is provided as an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `[-2, -1]`. + +
+ + + + + +
+ +## Notes + +- If `k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane counterclockwise. +- If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane clockwise. + +
+ + + + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rot90 = require( '@stdlib/ndarray/rot90' ); + +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); + +var y = rot90( x ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/rot90/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/rot90/benchmark/benchmark.js new file mode 100644 index 000000000000..3b52b808b11c --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/benchmark/benchmark.js @@ -0,0 +1,196 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var empty = require( '@stdlib/ndarray/empty' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var rot90 = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:ndims=2', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( 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( format( '%s:ndims=3', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( 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( format( '%s:ndims=3,dims=[0,2]', pkg ), function benchmark( b ) { + var values; + var opts; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + opts = { + 'dims': [ 0, 2 ] + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( values[ i%values.length ], opts ); + 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( format( '%s:ndims=4', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( 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( format( '%s:ndims=5', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + /* eslint-disable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + values = [ + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float64' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'float32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'int32' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'complex128' } ), + empty( [ 2, 2, 2, 2, 2 ], { 'dtype': 'generic' } ) + ]; + + /* eslint-enable object-curly-newline, stdlib/line-closing-bracket-spacing */ + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( 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/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt new file mode 100644 index 000000000000..95cf0430422d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt @@ -0,0 +1,37 @@ + +{{alias}}( x[, options] ) + Returns a read-only view of an input ndarray rotated 90 degrees in a + specified plane. + + Parameters + ---------- + x: ndarray + Input array. + + options: Object (optional) + Function options. + + options.k: integer (optional) + Number of times to rotate by 90 degrees. Default: 1. + + options.dims: ArrayLikeObject (optional) + Dimension indices defining the plane of rotation. Must contain exactly + two unique dimension indices. Default: [ -2, -1 ]. + + Returns + ------- + out: ndarray + A read-only view of an input ndarray rotated 90 degrees in a specified + plane. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + [ [ 1, 2 ], [ 3, 4 ] ] + > var y = {{alias}}( x ) + [ [ 2, 4 ], [ 1, 3 ] ] + > y = {{alias}}( x, { 'k': 2 } ) + [ [ 4, 3 ], [ 2, 1 ] ] + + See Also + -------- diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts new file mode 100644 index 000000000000..7772dc1a828d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts @@ -0,0 +1,64 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; +import { Collection } from '@stdlib/types/array'; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * Number of times to rotate by 90 degrees (default: 1). + */ + k?: number; + + /** + * Dimension indices defining the plane of rotation (default: [-2, -1]). + */ + dims?: Collection; +} + +/** +* Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane. +* +* @param x - input array +* @param options - function options +* @param options.k - number of times to rotate by 90 degrees (default: 1) +* @param options.dims - dimension indices defining the plane of rotation (default: [-2, -1]) +* @returns ndarray view +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = rot90( x ); +* // returns [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ] +*/ +declare function rot90( x: T, options?: Options ): T; + + +// EXPORTS // + +export = rot90; diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts new file mode 100644 index 000000000000..2fbdf2cfe538 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts @@ -0,0 +1,93 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 space-in-parens */ + +import zeros = require( '@stdlib/ndarray/zeros' ); +import rot90 = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + rot90( zeros( [ 2, 2 ] ) ); // $ExpectType typedndarray + rot90( zeros( [ 2, 2 ] ), {} ); // $ExpectType typedndarray + rot90( zeros( [ 2, 2 ] ), { 'k': 2 } ); // $ExpectType typedndarray + rot90( zeros( [ 2, 2 ] ), { 'dims': [ 0, 1 ] } ); // $ExpectType typedndarray + rot90( zeros( [ 2, 2 ] ), { 'k': 2, 'dims': [ 0, 1 ] } ); // $ExpectType typedndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + rot90( '10' ); // $ExpectError + rot90( 10 ); // $ExpectError + rot90( false ); // $ExpectError + rot90( true ); // $ExpectError + rot90( null ); // $ExpectError + rot90( void 0 ); // $ExpectError + rot90( [] ); // $ExpectError + rot90( {} ); // $ExpectError + rot90( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an object... +{ + const x = zeros( [ 2, 2 ] ); + + rot90( x, '10' ); // $ExpectError + rot90( x, 10 ); // $ExpectError + rot90( x, false ); // $ExpectError + rot90( x, true ); // $ExpectError + rot90( x, null ); // $ExpectError + rot90( x, [] ); // $ExpectError + rot90( x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `k` option which is not a number... +{ + const x = zeros( [ 2, 2 ] ); + + rot90( x, { 'k': '10' } ); // $ExpectError + rot90( x, { 'k': false } ); // $ExpectError + rot90( x, { 'k': true } ); // $ExpectError + rot90( x, { 'k': null } ); // $ExpectError + rot90( x, { 'k': [] } ); // $ExpectError + rot90( x, { 'k': {} } ); // $ExpectError + rot90( x, { 'k': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `dims` option which is not a collection of numbers... +{ + const x = zeros( [ 2, 2 ] ); + + rot90( x, { 'dims': '10' } ); // $ExpectError + rot90( x, { 'dims': 10 } ); // $ExpectError + rot90( x, { 'dims': false } ); // $ExpectError + rot90( x, { 'dims': true } ); // $ExpectError + rot90( x, { 'dims': null } ); // $ExpectError + rot90( x, { 'dims': {} } ); // $ExpectError + rot90( x, { 'dims': [ '0', '1' ] } ); // $ExpectError + rot90( x, { 'dims': ( x: number ): number => x } ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + rot90(); // $ExpectError + rot90( zeros( [ 2, 2 ] ), {}, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/rot90/examples/index.js b/lib/node_modules/@stdlib/ndarray/rot90/examples/index.js new file mode 100644 index 000000000000..4f69ab1bbda8 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/examples/index.js @@ -0,0 +1,29 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rot90 = require( './../lib' ); + +var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 ); +console.log( ndarray2array( x ) ); + +var y = rot90( x ); +console.log( ndarray2array( y ) ); diff --git a/lib/node_modules/@stdlib/ndarray/rot90/lib/index.js b/lib/node_modules/@stdlib/ndarray/rot90/lib/index.js new file mode 100644 index 000000000000..5b6822e0b90b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a read-only view of an input ndarray rotated 90 degrees in a specified plane. +* +* @module @stdlib/ndarray/rot90 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var rot90 = require( '@stdlib/ndarray/rot90' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = rot90( x ); +* // returns [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js new file mode 100644 index 000000000000..e13a8a11cf31 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isCollection = require( '@stdlib/assert/is-collection' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var base = require( '@stdlib/ndarray/base/rot90' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane. +* +* @param {ndarray} x - input array +* @param {Options} [options] - function options +* @param {integer} [options.k=1] - number of times to rotate by 90 degrees +* @param {IntegerArray} [options.dims=[-2,-1]] - dimension indices defining the plane of rotation +* @throws {TypeError} first argument must be an ndarray +* @throws {TypeError} options argument must be an object +* @throws {TypeError} `k` option must be an integer +* @throws {TypeError} `dims` option must be an array-like object of integers +* @throws {RangeError} must provide exactly two dimension indices +* @throws {RangeError} input ndarray must have at least two dimensions +* @throws {RangeError} must provide valid dimension indices +* @throws {Error} must provide unique dimension indices +* @returns {ndarray} ndarray view +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); +* // returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] +* +* var y = rot90( x ); +* // returns [ [ 2.0, 4.0 ], [ 1.0, 3.0 ] ] +*/ +function rot90( x, options ) { + var dims; + var k; + + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) ); + } + dims = [ -2, -1 ]; + k = 1; + if ( arguments.length > 1 ) { + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } + if ( hasOwnProp( options, 'k' ) ) { + if ( !isInteger( options.k ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'k', options.k ) ); + } + k = options.k; + } + if ( hasOwnProp( options, 'dims' ) ) { + if ( !isCollection( options.dims ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be an array-like object. Option: `%s`.', 'dims', options.dims ) ); + } + dims = options.dims; + } + } + return base( x, dims, k, false ); +} + + +// EXPORTS // + +module.exports = rot90; diff --git a/lib/node_modules/@stdlib/ndarray/rot90/package.json b/lib/node_modules/@stdlib/ndarray/rot90/package.json new file mode 100644 index 000000000000..b0aee960b787 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/rot90", + "version": "0.0.0", + "description": "Return a read-only view of an input ndarray rotated 90 degrees in a specified plane.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "data", + "structure", + "ndarray", + "matrix", + "view", + "rotate", + "rotation", + "rot90", + "plane", + "axis" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/rot90/test/test.js b/lib/node_modules/@stdlib/ndarray/rot90/test/test.js new file mode 100644 index 000000000000..4d85ec478b21 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/test/test.js @@ -0,0 +1,766 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var isEqualDataType = require( '@stdlib/ndarray/base/assert/is-equal-data-type' ); +var zeroTo = require( '@stdlib/array/zero-to' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rot90 = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof rot90, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( value ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not an object', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, value ); + }; + } +}); + +tape( 'the function throws an error if provided a `k` option which is not an integer', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, { + 'k': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which is not an array-like object', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + 5, + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option which does not contain exactly two dimension indices', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + [], + [ 0 ], + [ 0, 1, 0 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices [' + values[ i ] + ']' ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option having out-of-bounds dimension indices', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + [ 0, 2 ], + [ 2, 0 ], + [ -3, 0 ], + [ 0, -3 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided dimension indices [' + values[ i ] + ']' ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `dims` option having duplicate dimension indices', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + [ 0, 0 ], + [ 1, 1 ], + [ 0, -2 ], + [ -1, 1 ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided dimension indices [' + values[ i ] + ']' ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, { + 'dims': value + }); + }; + } +}); + +tape( 'the function throws an error if provided an input ndarray having fewer than two dimensions', function test( t ) { + var values; + var i; + + values = [ + scalar2ndarray( 5.0 ), + array( [ 1.0, 2.0, 3.0 ] ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided an ndarray having ' + values[ i ].ndims + ' dimensions' ); + } + t.end(); + + function badValue( x ) { + return function badValue() { + rot90( x ); + }; + } +}); + +tape( 'the function returns a read-only view of a matrix rotated 90 degrees counterclockwise (k=1, ndims=2)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = rot90( x ); + expected = [ + [ 2, 5 ], + [ 1, 4 ], + [ 0, 3 ] + ]; + + t.notEqual( actual, x, 'returns expected value' ); + t.strictEqual( isndarrayLike( actual ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a read-only view of a matrix rotated 180 degrees (k=2, ndims=2)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = rot90( x, { + 'k': 2 + }); + expected = [ + [ 5, 4, 3 ], + [ 2, 1, 0 ] + ]; + + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a read-only view of a matrix rotated 270 degrees counterclockwise (k=3, ndims=2)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = rot90( x, { + 'k': 3 + }); + expected = [ + [ 3, 0 ], + [ 4, 1 ], + [ 5, 2 ] + ]; + + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a read-only view of a matrix without rotation for k=0', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + actual = rot90( x, { + 'k': 0 + }); + expected = [ + [ 0, 1, 2 ], + [ 3, 4, 5 ] + ]; + + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative values of k (clockwise rotation)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + // k=-1 (90 deg clockwise, equivalent to k=3): + actual = rot90( x, { + 'k': -1 + }); + expected = [ + [ 3, 0 ], + [ 4, 1 ], + [ 5, 2 ] + ]; + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // k=-2 (equivalent to k=2): + actual = rot90( x, { + 'k': -2 + }); + expected = [ + [ 5, 4, 3 ], + [ 2, 1, 0 ] + ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // k=-3 (equivalent to k=1): + actual = rot90( x, { + 'k': -3 + }); + expected = [ + [ 2, 5 ], + [ 1, 4 ], + [ 0, 3 ] + ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function normalizes large values of k', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + // k=5 (same as k=1): + actual = rot90( x, { + 'k': 5 + }); + expected = [ + [ 2, 5 ], + [ 1, 4 ], + [ 0, 3 ] + ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // k=8 (same as k=0): + actual = rot90( x, { + 'k': 8 + }); + expected = [ + [ 0, 1, 2 ], + [ 3, 4, 5 ] + ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a `dims` option', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + // dims=[-2,-1] (same as default): + actual = rot90( x, { + 'dims': [ -2, -1 ] + }); + expected = [ + [ 2, 5 ], + [ 1, 4 ], + [ 0, 3 ] + ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // dims=[1,0] (rotation from axis 1 toward axis 0 = clockwise): + actual = rot90( x, { + 'dims': [ 1, 0 ] + }); + expected = [ + [ 3, 0 ], + [ 4, 1 ], + [ 5, 2 ] + ]; + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a stack of matrices (ndims=3)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 12, 'float64' ); + sh = [ 2, 2, 3 ]; + st = [ 6, 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + // k=1 (90 deg counterclockwise): + actual = rot90( x ); + expected = [ + [ + [ 2, 5 ], + [ 1, 4 ], + [ 0, 3 ] + ], + [ + [ 8, 11 ], + [ 7, 10 ], + [ 6, 9 ] + ] + ]; + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 3, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // k=2 (180 deg): + actual = rot90( x, { + 'k': 2 + }); + expected = [ + [ + [ 5, 4, 3 ], + [ 2, 1, 0 ] + ], + [ + [ 11, 10, 9 ], + [ 8, 7, 6 ] + ] + ]; + t.deepEqual( getShape( actual ), [ 2, 2, 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // k=-1 (90 deg clockwise): + actual = rot90( x, { + 'k': -1 + }); + expected = [ + [ + [ 3, 0 ], + [ 4, 1 ], + [ 5, 2 ] + ], + [ + [ 9, 6 ], + [ 10, 7 ], + [ 11, 8 ] + ] + ]; + t.deepEqual( getShape( actual ), [ 2, 3, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports rotation in arbitrary planes (ndims=3)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 12, 'float64' ); + sh = [ 2, 2, 3 ]; + st = [ 6, 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + // dims=[0,1]: + actual = rot90( x, { + 'dims': [ 0, 1 ] + }); + expected = [ + [ + [ 3, 4, 5 ], + [ 9, 10, 11 ] + ], + [ + [ 0, 1, 2 ], + [ 6, 7, 8 ] + ] + ]; + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 2, 2, 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + // dims=[0,2]: + actual = rot90( x, { + 'dims': [ 0, 2 ] + }); + expected = [ + [ + [ 2, 8 ], + [ 5, 11 ] + ], + [ + [ 1, 7 ], + [ 4, 10 ] + ], + [ + [ 0, 6 ], + [ 3, 9 ] + ] + ]; + t.deepEqual( getShape( actual ), [ 3, 2, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports column-major input arrays', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'float64' ); + sh = [ 2, 3 ]; + st = [ 1, 2 ]; + o = 0; + ord = 'column-major'; + + x = new ndarray( 'float64', buf, sh, st, o, ord ); + + // In column-major with strides [ 1, 2 ], x = [ [ 0, 2, 4 ], [ 1, 3, 5 ] ]: + actual = rot90( x ); + expected = [ + [ 4, 5 ], + [ 2, 3 ], + [ 0, 1 ] + ]; + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + actual = rot90( x, { + 'k': 2 + }); + expected = [ + [ 5, 3, 1 ], + [ 4, 2, 0 ] + ]; + t.deepEqual( getShape( actual ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function preserves the input data type (dtype=int32)', function test( t ) { + var expected; + var actual; + var buf; + var ord; + var sh; + var st; + var o; + var x; + + buf = zeroTo( 6, 'int32' ); + sh = [ 2, 3 ]; + st = [ 3, 1 ]; + o = 0; + ord = 'row-major'; + + x = new ndarray( 'int32', buf, sh, st, o, ord ); + + actual = rot90( x ); + expected = [ + [ 2, 5 ], + [ 1, 4 ], + [ 0, 3 ] + ]; + + t.strictEqual( isReadOnly( actual ), true, 'returns expected value' ); + t.strictEqual( getData( actual ), getData( x ), 'returns expected value' ); + t.strictEqual( isEqualDataType( getDType( actual ), getDType( x ) ), true, 'returns expected value' ); + t.deepEqual( getShape( actual ), [ 3, 2 ], 'returns expected value' ); + t.deepEqual( ndarray2array( actual ), expected, 'returns expected value' ); + + t.end(); +}); From dceb69497112c052b78a0344af1f766947250d6f Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 22 Apr 2026 20:58:42 +0500 Subject: [PATCH 2/8] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: skipped - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/rot90/README.md | 1 + .../@stdlib/ndarray/rot90/docs/repl.txt | 16 +++++++++- .../ndarray/rot90/docs/types/index.d.ts | 10 +++++-- .../@stdlib/ndarray/rot90/lib/main.js | 15 ++++++---- .../@stdlib/ndarray/rot90/test/test.js | 30 +++++++++++++++++++ 5 files changed, 63 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/README.md b/lib/node_modules/@stdlib/ndarray/rot90/README.md index fd40f97ec7ea..38c8373d6284 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/README.md +++ b/lib/node_modules/@stdlib/ndarray/rot90/README.md @@ -76,6 +76,7 @@ The function accepts the following options: - If `k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane counterclockwise. - If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane clockwise. +- Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt index 95cf0430422d..174327dfddd7 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt @@ -3,6 +3,18 @@ Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane. + If `k > 0`, the function rotates the plane from the first specified + dimension toward the second specified dimension. This means that, for a + two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane + counterclockwise. + + If `k < 0`, the function rotates the plane from the second specified + dimension toward the first specified dimension. This means that, for a + two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane + clockwise. + + Each provided dimension index must reside on the interval [-ndims, ndims-1]. + Parameters ---------- x: ndarray @@ -16,7 +28,9 @@ options.dims: ArrayLikeObject (optional) Dimension indices defining the plane of rotation. Must contain exactly - two unique dimension indices. Default: [ -2, -1 ]. + two unique dimension indices. If less than zero, an index is resolved + relative to the last dimension, with the last dimension corresponding to + the value `-1`. Default: [ -2, -1 ]. Returns ------- diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts index 7772dc1a828d..e0bcbfb0a84e 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts @@ -21,7 +21,7 @@ /// import { ndarray } from '@stdlib/types/ndarray'; -import { Collection } from '@stdlib/types/array'; +import { ArrayLike } from '@stdlib/types/array'; /** * Interface defining function options. @@ -35,17 +35,21 @@ interface Options { /** * Dimension indices defining the plane of rotation (default: [-2, -1]). */ - dims?: Collection; + dims?: ArrayLike; } /** * Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane. * +* ## Notes +* +* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. +* * @param x - input array * @param options - function options * @param options.k - number of times to rotate by 90 degrees (default: 1) * @param options.dims - dimension indices defining the plane of rotation (default: [-2, -1]) -* @returns ndarray view +* @returns output array * * @example * var array = require( '@stdlib/ndarray/array' ); diff --git a/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js index e13a8a11cf31..5f3e5654baa7 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js @@ -20,10 +20,11 @@ // MODULES // -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isIntegerArray = require( '@stdlib/assert/is-integer-array' ).primitives; +var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' ); var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); -var isCollection = require( '@stdlib/assert/is-collection' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var base = require( '@stdlib/ndarray/base/rot90' ); var format = require( '@stdlib/string/format' ); @@ -34,6 +35,10 @@ var format = require( '@stdlib/string/format' ); /** * Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane. * +* ## Notes +* +* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. +* * @param {ndarray} x - input array * @param {Options} [options] - function options * @param {integer} [options.k=1] - number of times to rotate by 90 degrees @@ -41,7 +46,7 @@ var format = require( '@stdlib/string/format' ); * @throws {TypeError} first argument must be an ndarray * @throws {TypeError} options argument must be an object * @throws {TypeError} `k` option must be an integer -* @throws {TypeError} `dims` option must be an array-like object of integers +* @throws {TypeError} `dims` option must be an array of integers * @throws {RangeError} must provide exactly two dimension indices * @throws {RangeError} input ndarray must have at least two dimensions * @throws {RangeError} must provide valid dimension indices @@ -77,8 +82,8 @@ function rot90( x, options ) { k = options.k; } if ( hasOwnProp( options, 'dims' ) ) { - if ( !isCollection( options.dims ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object. Option: `%s`.', 'dims', options.dims ) ); + if ( !isIntegerArray( options.dims ) && !isEmptyCollection( options.dims ) ) { // eslint-disable-line max-len + throw new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', options.dims ) ); } dims = options.dims; } diff --git a/lib/node_modules/@stdlib/ndarray/rot90/test/test.js b/lib/node_modules/@stdlib/ndarray/rot90/test/test.js index 4d85ec478b21..515192812909 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/rot90/test/test.js @@ -170,6 +170,36 @@ tape( 'the function throws an error if provided a `dims` option which is not an } }); +tape( 'the function throws an error if provided a `dims` option which is not an array of integers', function test( t ) { + var values; + var x; + var i; + + x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + values = [ + [ '0', '1' ], + [ 0.5, 1.5 ], + [ NaN, NaN ], + [ null, null ], + [ true, false ], + [ {}, {} ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided [' + values[ i ] + ']' ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + rot90( x, { + 'dims': value + }); + }; + } +}); + tape( 'the function throws an error if provided a `dims` option which does not contain exactly two dimension indices', function test( t ) { var values; var x; From b3aad989da8fdf1aeee9c0bcf09c91bda8158482 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 23:08:53 -0700 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts index e0bcbfb0a84e..08a20a63d1ad 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts @@ -21,7 +21,7 @@ /// import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; +import { Collection } from '@stdlib/types/array'; /** * Interface defining function options. @@ -35,7 +35,7 @@ interface Options { /** * Dimension indices defining the plane of rotation (default: [-2, -1]). */ - dims?: ArrayLike; + dims?: Collection; } /** From d131eed62a4274516b502d7d509f835d89466518 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 23 Apr 2026 23:50:39 -0700 Subject: [PATCH 4/8] test: fix broken tests Signed-off-by: Athan --- .../@stdlib/ndarray/rot90/docs/types/test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts index 2fbdf2cfe538..7c95770f611a 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/test.ts @@ -26,11 +26,11 @@ import rot90 = require( './index' ); // The function returns an ndarray... { - rot90( zeros( [ 2, 2 ] ) ); // $ExpectType typedndarray - rot90( zeros( [ 2, 2 ] ), {} ); // $ExpectType typedndarray - rot90( zeros( [ 2, 2 ] ), { 'k': 2 } ); // $ExpectType typedndarray - rot90( zeros( [ 2, 2 ] ), { 'dims': [ 0, 1 ] } ); // $ExpectType typedndarray - rot90( zeros( [ 2, 2 ] ), { 'k': 2, 'dims': [ 0, 1 ] } ); // $ExpectType typedndarray + rot90( zeros( [ 2, 2 ] ) ); // $ExpectType float64ndarray + rot90( zeros( [ 2, 2 ] ), {} ); // $ExpectType float64ndarray + rot90( zeros( [ 2, 2 ] ), { 'k': 2 } ); // $ExpectType float64ndarray + rot90( zeros( [ 2, 2 ] ), { 'dims': [ 0, 1 ] } ); // $ExpectType float64ndarray + rot90( zeros( [ 2, 2 ] ), { 'k': 2, 'dims': [ 0, 1 ] } ); // $ExpectType float64ndarray } // The compiler throws an error if the function is provided a first argument which is not an ndarray... From 5b1f2c6aa93e0da608b78f52721f7cc38642e913 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 24 Apr 2026 00:15:32 -0700 Subject: [PATCH 5/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt index 174327dfddd7..b5adc8f9baa6 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt @@ -10,7 +10,7 @@ If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a - two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane + two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane clockwise. Each provided dimension index must reside on the interval [-ndims, ndims-1]. From 526ab9d8b1a86df0fd2e22887437a906f4febaed Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 24 Apr 2026 00:16:04 -0700 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/rot90/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/README.md b/lib/node_modules/@stdlib/ndarray/rot90/README.md index 38c8373d6284..71b6ff1b2360 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/README.md +++ b/lib/node_modules/@stdlib/ndarray/rot90/README.md @@ -75,7 +75,7 @@ The function accepts the following options: ## Notes - If `k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane counterclockwise. -- If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane clockwise. +- If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane clockwise. - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. From fea3862c04e5f93040430795915c3d7eeac3aa10 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 24 Apr 2026 00:19:19 -0700 Subject: [PATCH 7/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/rot90/README.md | 4 ++-- lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt | 12 ++++++------ .../@stdlib/ndarray/rot90/docs/types/index.d.ts | 2 ++ lib/node_modules/@stdlib/ndarray/rot90/lib/main.js | 2 ++ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/README.md b/lib/node_modules/@stdlib/ndarray/rot90/README.md index 71b6ff1b2360..302d90fcbe38 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/README.md +++ b/lib/node_modules/@stdlib/ndarray/rot90/README.md @@ -74,8 +74,8 @@ The function accepts the following options: ## Notes -- If `k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane counterclockwise. -- If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane clockwise. +- If `options.k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates the plane counterclockwise. +- If `options.k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates the plane clockwise. - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt index b5adc8f9baa6..cc244f035ace 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt @@ -3,15 +3,15 @@ Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane. - If `k > 0`, the function rotates the plane from the first specified + If `options.k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a - two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane - counterclockwise. + two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates + the plane counterclockwise. - If `k < 0`, the function rotates the plane from the second specified + If `options.k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a - two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane - clockwise. + two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates + the plane clockwise. Each provided dimension index must reside on the interval [-ndims, ndims-1]. diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts index 08a20a63d1ad..ce0c4fb05137 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts @@ -43,6 +43,8 @@ interface Options { * * ## Notes * +* - If `options.k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates the plane counterclockwise. +* - If `options.k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates the plane clockwise. * - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. * * @param x - input array diff --git a/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js index 5f3e5654baa7..03a2a5374d27 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js @@ -37,6 +37,8 @@ var format = require( '@stdlib/string/format' ); * * ## Notes * +* - If `options.k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates the plane counterclockwise. +* - If `options.k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `options.dims = [0, 1]`, the function rotates the plane clockwise. * - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. * * @param {ndarray} x - input array From 49a97448b58f2b395b706aa3b3272efc2151479a Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 24 Apr 2026 00:21:28 -0700 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt index cc244f035ace..3718562dd9ce 100644 --- a/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt @@ -35,8 +35,7 @@ Returns ------- out: ndarray - A read-only view of an input ndarray rotated 90 degrees in a specified - plane. + Output array view. Examples --------