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..38c8373d6284 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/README.md @@ -0,0 +1,137 @@ + + +# 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. +- Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. + +
+ + + + + +
+ +## 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..174327dfddd7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( x[, options] ) + 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 + 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. 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 + ------- + 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..e0bcbfb0a84e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts @@ -0,0 +1,68 @@ +/* +* @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 { ArrayLike } 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?: 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 output array +* +* @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..5f3e5654baa7 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/lib/main.js @@ -0,0 +1,97 @@ +/** +* @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 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 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. +* +* ## 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 +* @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 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 ( !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; + } + } + 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..515192812909 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/rot90/test/test.js @@ -0,0 +1,796 @@ +/** +* @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 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; + 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(); +});