From 707f380d83c8ac9a62061757fd064cce6e1e7a2e Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 19 Mar 2026 02:46:12 +0500 Subject: [PATCH 1/9] feat: add ndarray/base/rot90 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/ndarray/base/rot90/README.md | 153 +++++ .../ndarray/base/rot90/benchmark/benchmark.js | 272 +++++++++ .../@stdlib/ndarray/base/rot90/docs/repl.txt | 46 ++ .../ndarray/base/rot90/docs/types/index.d.ts | 97 ++++ .../ndarray/base/rot90/docs/types/test.ts | 90 +++ .../ndarray/base/rot90/examples/index.js | 46 ++ .../@stdlib/ndarray/base/rot90/lib/index.js | 44 ++ .../@stdlib/ndarray/base/rot90/lib/main.js | 102 ++++ .../@stdlib/ndarray/base/rot90/package.json | 66 +++ .../@stdlib/ndarray/base/rot90/test/test.js | 548 ++++++++++++++++++ 10 files changed, 1464 insertions(+) create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/README.md create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/lib/index.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/package.json create mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/README.md b/lib/node_modules/@stdlib/ndarray/base/rot90/README.md new file mode 100644 index 000000000000..b8b80a8a72f9 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/README.md @@ -0,0 +1,153 @@ + + +# rot90 + +> Rotate a matrix (or a stack of matrices) by 90 degrees. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var rot90 = require( '@stdlib/ndarray/base/rot90' ); +``` + +#### rot90( x, k, writable ) + +Rotates a matrix (or a stack of matrices) `x` by 90 degrees. + +```javascript +var array = require( '@stdlib/ndarray/array' ); + +var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +// returns [ [ 1, 2 ], [ 3, 4 ] ] + +var y = rot90( x, 1, false ); +// returns [ [ 2, 4 ], [ 1, 3 ] ] +``` + +The function accepts the following arguments: + +- **x**: input ndarray. +- **k**: number of times to rotate by 90 degrees. Positive values rotate counterclockwise. Negative values rotate clockwise. +- **writable**: boolean indicating whether a returned ndarray should be writable. + +
+ + + + + +
+ +## Notes + +- The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. +- The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. +- If provided an ndarray with fewer than two dimensions, the function returns the input array unchanged. + +
+ + + + + +
+ +## Examples + + + +```javascript +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rot90 = require( '@stdlib/ndarray/base/rot90' ); + +// Create a 2x3 matrix: +var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + +// Rotate 90 degrees counterclockwise: +var y = rot90( x, 1, false ); +var arr = ndarray2array( y ); +// returns [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] + +// Rotate 180 degrees: +y = rot90( x, 2, false ); +arr = ndarray2array( y ); +// returns [ [ 6, 5, 4 ], [ 3, 2, 1 ] ] + +// Rotate 270 degrees counterclockwise (equivalent to 90 degrees clockwise): +y = rot90( x, 3, false ); +arr = ndarray2array( y ); +// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] + +// Rotate 360 degrees (equivalent to no rotation): +y = rot90( x, 4, false ); +arr = ndarray2array( y ); +// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + +// Rotate 90 degrees clockwise (equivalent to k=-1): +y = rot90( x, -1, false ); +arr = ndarray2array( y ); +// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js new file mode 100644 index 000000000000..b2b4e20eee3a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js @@ -0,0 +1,272 @@ +/** +* @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 baseEmpty = require( '@stdlib/ndarray/base/empty' ); +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::2d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( values[ i%values.length ], 1, false ); + 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::2d,non-base', 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 ], 1, false ); + 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::3d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( values[ i%values.length ], 1, false ); + 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::3d,non-base', 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 ], 1, false ); + 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::4d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( values[ i%values.length ], 1, false ); + 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::4d,non-base', 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 ], 1, false ); + 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::5d,base', pkg ), function benchmark( b ) { + var values; + var v; + var i; + + values = [ + baseEmpty( 'float64', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'float32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'int32', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'complex128', [ 2, 2, 2, 2, 2 ], 'row-major' ), + baseEmpty( 'generic', [ 2, 2, 2, 2, 2 ], 'row-major' ) + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = rot90( values[ i%values.length ], 1, false ); + 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::5d,non-base', 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 ], 1, false ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an ndarray' ); + } + } + b.toc(); + if ( !isndarrayLike( v ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt new file mode 100644 index 000000000000..ba03ac741d6b --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt @@ -0,0 +1,46 @@ + +{{alias}}( x, k, writable ) + Rotates a matrix (or a stack of matrices) by 90 degrees. + + Positive values of `k` rotate counterclockwise. Negative values of `k` + rotate clockwise. + + The returned ndarray is a *view* of the input ndarray. Accordingly, writing + to the original ndarray will mutate the returned ndarray and vice versa. + + The `writable` parameter only applies to ndarray constructors supporting + read-only instances. + + If provided an ndarray with fewer than two dimensions, the function returns + the input array unchanged. + + Parameters + ---------- + x: ndarray + Input array. + + k: integer + Number of times to rotate by 90 degrees. + + writable: boolean + Boolean indicating whether the returned ndarray should be writable. + + Returns + ------- + out: ndarray + Output array. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) + [ [ 1, 2 ], [ 3, 4 ] ] + > var y = {{alias}}( x, 1, false ) + [ [ 2, 4 ], [ 1, 3 ] ] + > y = {{alias}}( x, 2, false ) + [ [ 4, 3 ], [ 2, 1 ] ] + > y = {{alias}}( x, 3, false ) + [ [ 3, 1 ], [ 4, 2 ] ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts new file mode 100644 index 000000000000..d9be4b30451a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { ndarray, typedndarray, genericndarray } from '@stdlib/types/ndarray'; + +/** +* Rotates a matrix (or a stack of matrices) by 90 degrees. +* +* @param x - input array +* @param k - number of times to rotate by 90 degrees +* @param writable - boolean indicating whether the returned ndarray should be writable +* @returns ndarray view +* +* @example +* var array = require( `@stdlib/ndarray/array` ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = rot90( x, 1, false ); +* // returns [ [ 2, 4 ], [ 1, 3 ] ] +*/ +declare function rot90 = typedndarray>( x: T, k: number, writable: boolean ): T; + +/** +* Rotates a matrix (or a stack of matrices) by 90 degrees. +* +* @param x - input array +* @param k - number of times to rotate by 90 degrees +* @param writable - boolean indicating whether the returned ndarray should be writable +* @returns ndarray view +* +* @example +* var array = require( `@stdlib/ndarray/array` ); +* var ndarray2array = require( `@stdlib/ndarray/to-array` ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { +* 'dtype': 'generic' +* }); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = rot90( x, 1, false ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ [ 2, 4 ], [ 1, 3 ] ] +*/ +declare function rot90 = genericndarray>( x: T, k: number, writable: boolean ): T; + +/** +* Rotates a matrix (or a stack of matrices) by 90 degrees. +* +* @param x - input array +* @param k - number of times to rotate by 90 degrees +* @param writable - boolean indicating whether the returned ndarray should be writable +* @returns ndarray view +* +* @example +* var array = require( `@stdlib/ndarray/array` ); +* var ndarray2array = require( `@stdlib/ndarray/to-array` ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { +* 'dtype': 'generic' +* }); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = rot90( x, 1, false ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ [ 2, 4 ], [ 1, 3 ] ] +*/ +declare function rot90( x: ndarray, k: number, writable: boolean ): ndarray; + + +// EXPORTS // + +export = rot90; diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts new file mode 100644 index 000000000000..63f71eb75edb --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts @@ -0,0 +1,90 @@ +/* +* @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. +*/ + +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import rot90 = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + rot90( zeros( 'float64', sh, ord ), 1, false ); // $ExpectType float64ndarray + rot90( zeros( 'float32', sh, ord ), 1, false ); // $ExpectType float32ndarray + rot90( zeros( 'complex128', sh, ord ), 1, false ); // $ExpectType complex128ndarray + rot90( zeros( 'complex64', sh, ord ), 1, false ); // $ExpectType complex64ndarray + rot90( zeros( 'int32', sh, ord ), 1, false ); // $ExpectType int32ndarray + rot90( zeros( 'int16', sh, ord ), 1, false ); // $ExpectType int16ndarray + rot90( zeros( 'int8', sh, ord ), 1, false ); // $ExpectType int8ndarray + rot90( zeros( 'uint32', sh, ord ), 1, false ); // $ExpectType uint32ndarray + rot90( zeros( 'uint16', sh, ord ), 1, false ); // $ExpectType uint16ndarray + rot90( zeros( 'uint8', sh, ord ), 1, false ); // $ExpectType uint8ndarray + rot90( zeros( 'uint8c', sh, ord ), 1, false ); // $ExpectType uint8cndarray + rot90( zeros( 'generic', sh, ord ), 1, false ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray having a recognized/supported data type... +{ + rot90( '10', 1, false ); // $ExpectError + rot90( 10, 1, false ); // $ExpectError + rot90( false, 1, false ); // $ExpectError + rot90( true, 1, false ); // $ExpectError + rot90( null, 1, false ); // $ExpectError + rot90( void 0, 1, false ); // $ExpectError + rot90( [], 1, false ); // $ExpectError + rot90( {}, 1, false ); // $ExpectError + rot90( ( x: number ): number => x, 1, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + rot90( x, '10', false ); // $ExpectError + rot90( x, false, false ); // $ExpectError + rot90( x, true, false ); // $ExpectError + rot90( x, null, false ); // $ExpectError + rot90( x, void 0, false ); // $ExpectError + rot90( x, [], false ); // $ExpectError + rot90( x, {}, false ); // $ExpectError + rot90( x, ( x: number ): number => x, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a boolean... +{ + const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + rot90( x, 1, '10' ); // $ExpectError + rot90( x, 1, 10 ); // $ExpectError + rot90( x, 1, null ); // $ExpectError + rot90( x, 1, void 0 ); // $ExpectError + rot90( x, 1, [] ); // $ExpectError + rot90( x, 1, {} ); // $ExpectError + rot90( x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + rot90(); // $ExpectError + rot90( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError + rot90( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError + rot90( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1, false, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js new file mode 100644 index 000000000000..eec1e6413eed --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js @@ -0,0 +1,46 @@ +/** +* @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 array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var rot90 = require( './../lib' ); + +// Create a 2x3 matrix: +var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); + +// Rotate 90 degrees counterclockwise: +var y = rot90( x, 1, false ); +console.log( ndarray2array( y ) ); +// => [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] + +// Rotate 180 degrees: +y = rot90( x, 2, false ); +console.log( ndarray2array( y ) ); +// => [ [ 6, 5, 4 ], [ 3, 2, 1 ] ] + +// Rotate 270 degrees counterclockwise: +y = rot90( x, 3, false ); +console.log( ndarray2array( y ) ); +// => [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] + +// Rotate 360 degrees: +y = rot90( x, 4, false ); +console.log( ndarray2array( y ) ); +// => [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/rot90/lib/index.js new file mode 100644 index 000000000000..9659dd12bf36 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/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'; + +/** +* Rotate a matrix (or a stack of matrices) by 90 degrees. +* +* @module @stdlib/ndarray/base/rot90 +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* var rot90 = require( '@stdlib/ndarray/base/rot90' ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = rot90( x, 1, false ); +* // returns [ [ 2, 4 ], [ 1, 3 ] ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js new file mode 100644 index 000000000000..f9b27953c879 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js @@ -0,0 +1,102 @@ +/** +* @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 getDType = require( '@stdlib/ndarray/base/dtype' ); +var getShape = require( '@stdlib/ndarray/base/shape' ); +var getStrides = require( '@stdlib/ndarray/base/strides' ); +var getOffset = require( '@stdlib/ndarray/base/offset' ); +var getOrder = require( '@stdlib/ndarray/base/order' ); +var getData = require( '@stdlib/ndarray/base/data-buffer' ); + + +// MAIN // + +/** +* Rotate a matrix (or a stack of matrices) by 90 degrees. +* +* @param {ndarray} x - input array +* @param {integer} k - number of times to rotate by 90 degrees +* @param {boolean} writable - boolean indicating whether the returned ndarray should be writable +* @returns {ndarray} ndarray view +* +* @example +* var array = require( '@stdlib/ndarray/array' ); +* +* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns [ [ 1, 2 ], [ 3, 4 ] ] +* +* var y = rot90( x, 1, false ); +* // returns [ [ 2, 4 ], [ 1, 3 ] ] +* +*/ +function rot90( x, k, writable ) { + var offset; + var nk; + var sh; + var st; + var sm; + var sn; + var M; + var N; + var d; + + sh = getShape( x, true ); + d = sh.length; + if ( d < 2 ) { + return x; + } + st = getStrides( x, true ); + offset = getOffset( x ); + nk = ( ( k % 4 ) + 4 ) % 4; + + // Cache the original shape and stride values for the last two dimensions: + M = sh[ d-2 ]; + N = sh[ d-1 ]; + sm = st[ d-2 ]; + sn = st[ d-1 ]; + + if ( nk === 1 ) { + sh[ d-2 ] = N; + sh[ d-1 ] = M; + st[ d-2 ] = -sn; + st[ d-1 ] = sm; + offset += ( N - 1 ) * sn; + } else if ( nk === 2 ) { + st[ d-2 ] = -sm; + st[ d-1 ] = -sn; + offset += ( ( M - 1 ) * sm ) + ( ( N - 1 ) * sn ); + } else if ( nk === 3 ) { + sh[ d-2 ] = N; + sh[ d-1 ] = M; + st[ d-2 ] = sn; + st[ d-1 ] = -sm; + offset += ( M - 1 ) * sm; + } + return new x.constructor( getDType( x ), getData( x ), sh, st, offset, getOrder( x ), { // eslint-disable-line max-len + 'readonly': !writable + }); +} + + +// EXPORTS // + +module.exports = rot90; diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/package.json b/lib/node_modules/@stdlib/ndarray/base/rot90/package.json new file mode 100644 index 000000000000..ec44bc96c7a0 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ndarray/base/rot90", + "version": "0.0.0", + "description": "Rotate a matrix (or a stack of matrices) by 90 degrees.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "types", + "base", + "data", + "structure", + "ndarray", + "matrix", + "rotate", + "rotation", + "rot90", + "view", + "numpy.rot90" + ] +} diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js b/lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js new file mode 100644 index 000000000000..aa25225b42d1 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js @@ -0,0 +1,548 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var real = require( '@stdlib/complex/float64/real' ); +var imag = require( '@stdlib/complex/float64/imag' ); +var realf = require( '@stdlib/complex/float32/real' ); +var imagf = require( '@stdlib/complex/float32/imag' ); +var instanceOf = require( '@stdlib/assert/instance-of' ); +var isReadOnly = require( '@stdlib/ndarray/base/assert/is-read-only' ); +var base = require( '@stdlib/ndarray/base/ctor' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var array = require( '@stdlib/ndarray/array' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var getData = require( '@stdlib/ndarray/data-buffer' ); +var getDType = require( '@stdlib/ndarray/dtype' ); +var getOrder = require( '@stdlib/ndarray/order' ); +var getShape = require( '@stdlib/ndarray/shape' ); +var getStrides = require( '@stdlib/ndarray/strides' ); +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 returns the input array unchanged if provided an ndarray having fewer than two dimensions (0d)', function test( t ) { + var arr; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ); + arr = rot90( x, 1, false ); + + t.strictEqual( arr, x, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the input array unchanged if provided an ndarray having fewer than two dimensions (1d)', function test( t ) { + var arr; + var x; + + x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ); + arr = rot90( x, 1, false ); + + t.strictEqual( arr, x, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=float64, base, row-major)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + // k=0 (no rotation): + arr = rot90( x, 0, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + t.deepEqual( getStrides( arr ), [ 3, 1 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + t.strictEqual( getOrder( arr ), getOrder( x ), 'returns expected value' ); + t.notEqual( arr, x, 'returns expected value' ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1 (90 degrees counterclockwise): + arr = rot90( x, 1, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2 (180 degrees): + arr = rot90( x, 2, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3 (270 degrees counterclockwise): + arr = rot90( x, 3, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=float64, base, column-major)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 1, 2 ], 0, 'column-major' ); + + // In column-major with strides [1,2], x = [ [ 1.0, 3.0, 5.0 ], [ 2.0, 4.0, 6.0 ] ] + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + expected = [ [ 6.0, 4.0, 2.0 ], [ 5.0, 3.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3: + arr = rot90( x, 3, false ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + expected = [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=float64, non-base)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'float64' + }); + + // k=0: + arr = rot90( x, 0, false ); + t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3: + arr = rot90( x, 3, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=float32, base)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3: + arr = rot90( x, 3, false ); + t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=float32, non-base)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'float32' + }); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1, writable: + arr = rot90( x, 1, true ); + t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix (dtype=complex128, base)', function test( t ) { + var arr; + var buf; + var v; + var x; + + buf = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); + x = new base( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + + v = arr.get( 0, 0 ); + t.strictEqual( real( v ), 2.0, 'returns expected value' ); + t.strictEqual( imag( v ), 2.0, 'returns expected value' ); + v = arr.get( 0, 1 ); + t.strictEqual( real( v ), 4.0, 'returns expected value' ); + t.strictEqual( imag( v ), 4.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( real( v ), 1.0, 'returns expected value' ); + t.strictEqual( imag( v ), 1.0, 'returns expected value' ); + v = arr.get( 1, 1 ); + t.strictEqual( real( v ), 3.0, 'returns expected value' ); + t.strictEqual( imag( v ), 3.0, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + v = arr.get( 0, 0 ); + t.strictEqual( real( v ), 4.0, 'returns expected value' ); + t.strictEqual( imag( v ), 4.0, 'returns expected value' ); + v = arr.get( 0, 1 ); + t.strictEqual( real( v ), 3.0, 'returns expected value' ); + t.strictEqual( imag( v ), 3.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( real( v ), 2.0, 'returns expected value' ); + t.strictEqual( imag( v ), 2.0, 'returns expected value' ); + v = arr.get( 1, 1 ); + t.strictEqual( real( v ), 1.0, 'returns expected value' ); + t.strictEqual( imag( v ), 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix (dtype=complex64, base)', function test( t ) { + var arr; + var buf; + var v; + var x; + + buf = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); + x = new base( 'complex64', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); + t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + + v = arr.get( 0, 0 ); + t.strictEqual( realf( v ), 2.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); + v = arr.get( 0, 1 ); + t.strictEqual( realf( v ), 4.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( realf( v ), 1.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 1.0, 'returns expected value' ); + v = arr.get( 1, 1 ); + t.strictEqual( realf( v ), 3.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 3.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=generic, base)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = [ 1, 2, 3, 4, 5, 6 ]; + x = new base( 'generic', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + // k=0: + arr = rot90( x, 0, false ); + t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 6, 5, 4 ], [ 3, 2, 1 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3: + arr = rot90( x, 3, false ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function rotates a matrix for all values of k (dtype=generic, non-base)', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = [ 1, 2, 3, 4, 5, 6 ]; + x = array( buf, { + 'shape': [ 2, 3 ], + 'dtype': 'generic' + }); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1, writable: + arr = rot90( x, 1, true ); + t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports negative values of k', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + // k=-1`````: + arr = rot90( x, -1, false ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=-2: + arr = rot90( x, -2, false ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=-3: + arr = rot90( x, -3, false ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=-4: + arr = rot90( x, -4, false ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports a stack of matrices for all values of k', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]; + x = new base( 'generic', buf, [ 2, 2, 3 ], [ 6, 3, 1 ], 0, 'row-major' ); + + // k=0: + arr = rot90( x, 0, false ); + t.deepEqual( getShape( arr ), [ 2, 2, 3 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ + [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], + [ [ 7, 8, 9 ], [ 10, 11, 12 ] ] + ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1: + arr = rot90( x, 1, false ); + t.deepEqual( getShape( arr ), [ 2, 3, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ + [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ], + [ [ 9, 12 ], [ 8, 11 ], [ 7, 10 ] ] + ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + t.deepEqual( getShape( arr ), [ 2, 2, 3 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ + [ [ 6, 5, 4 ], [ 3, 2, 1 ] ], + [ [ 12, 11, 10 ], [ 9, 8, 7 ] ] + ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3: + arr = rot90( x, 3, false ); + t.deepEqual( getShape( arr ), [ 2, 3, 2 ], 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + expected = [ + [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ], + [ [ 10, 7 ], [ 11, 8 ], [ 12, 9 ] ] + ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports the `writable` parameter', function test( t ) { + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + x = array( buf, { + 'shape': [ 2, 2 ], + 'dtype': 'float64' + }); + + // k=0: + arr = rot90( x, 0, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + arr = rot90( x, 0, true ); + t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); + + // k=1: + arr = rot90( x, 1, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + arr = rot90( x, 1, true ); + t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); + + // k=2: + arr = rot90( x, 2, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + arr = rot90( x, 2, true ); + t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); + + // k=3: + arr = rot90( x, 3, false ); + t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); + arr = rot90( x, 3, true ); + t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); + + t.end(); +}); + +tape( 'rotating four times returns the original arrangement', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); + + arr = rot90( x, 1, false ); + arr = rot90( arr, 1, false ); + arr = rot90( arr, 1, false ); + arr = rot90( arr, 1, false ); + + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); + + t.end(); +}); From 55fe38929eda990619525b28f734863361a4dab2 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 25 Mar 2026 04:15:54 +0500 Subject: [PATCH 2/9] 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: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../ndarray/base/rot90/docs/types/test.ts | 90 ------ .../ndarray/base/{rot90 => rotr90}/README.md | 40 +-- .../{rot90 => rotr90}/benchmark/benchmark.js | 18 +- .../base/{rot90 => rotr90}/docs/repl.txt | 11 +- .../{rot90 => rotr90}/docs/types/index.d.ts | 26 +- .../ndarray/base/rotr90/docs/types/test.ts | 90 ++++++ .../base/{rot90 => rotr90}/examples/index.js | 23 +- .../base/{rot90 => rotr90}/lib/index.js | 10 +- .../base/{rot90 => rotr90}/lib/main.js | 36 ++- .../base/{rot90 => rotr90}/package.json | 10 +- .../base/{rot90 => rotr90}/test/test.js | 276 ++++++++++-------- 11 files changed, 337 insertions(+), 293 deletions(-) delete mode 100644 lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/README.md (81%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/benchmark/benchmark.js (93%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/docs/repl.txt (86%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/docs/types/index.d.ts (73%) create mode 100644 lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/test.ts rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/examples/index.js (75%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/lib/index.js (78%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/lib/main.js (86%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/package.json (87%) rename lib/node_modules/@stdlib/ndarray/base/{rot90 => rotr90}/test/test.js (77%) diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts deleted file mode 100644 index 63f71eb75edb..000000000000 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/test.ts +++ /dev/null @@ -1,90 +0,0 @@ -/* -* @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. -*/ - -import zeros = require( '@stdlib/ndarray/base/zeros' ); -import rot90 = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - const sh = [ 2, 2 ]; - const ord = 'row-major'; - - rot90( zeros( 'float64', sh, ord ), 1, false ); // $ExpectType float64ndarray - rot90( zeros( 'float32', sh, ord ), 1, false ); // $ExpectType float32ndarray - rot90( zeros( 'complex128', sh, ord ), 1, false ); // $ExpectType complex128ndarray - rot90( zeros( 'complex64', sh, ord ), 1, false ); // $ExpectType complex64ndarray - rot90( zeros( 'int32', sh, ord ), 1, false ); // $ExpectType int32ndarray - rot90( zeros( 'int16', sh, ord ), 1, false ); // $ExpectType int16ndarray - rot90( zeros( 'int8', sh, ord ), 1, false ); // $ExpectType int8ndarray - rot90( zeros( 'uint32', sh, ord ), 1, false ); // $ExpectType uint32ndarray - rot90( zeros( 'uint16', sh, ord ), 1, false ); // $ExpectType uint16ndarray - rot90( zeros( 'uint8', sh, ord ), 1, false ); // $ExpectType uint8ndarray - rot90( zeros( 'uint8c', sh, ord ), 1, false ); // $ExpectType uint8cndarray - rot90( zeros( 'generic', sh, ord ), 1, false ); // $ExpectType genericndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an ndarray having a recognized/supported data type... -{ - rot90( '10', 1, false ); // $ExpectError - rot90( 10, 1, false ); // $ExpectError - rot90( false, 1, false ); // $ExpectError - rot90( true, 1, false ); // $ExpectError - rot90( null, 1, false ); // $ExpectError - rot90( void 0, 1, false ); // $ExpectError - rot90( [], 1, false ); // $ExpectError - rot90( {}, 1, false ); // $ExpectError - rot90( ( x: number ): number => x, 1, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not a number... -{ - const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); - - rot90( x, '10', false ); // $ExpectError - rot90( x, false, false ); // $ExpectError - rot90( x, true, false ); // $ExpectError - rot90( x, null, false ); // $ExpectError - rot90( x, void 0, false ); // $ExpectError - rot90( x, [], false ); // $ExpectError - rot90( x, {}, false ); // $ExpectError - rot90( x, ( x: number ): number => x, false ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a boolean... -{ - const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); - - rot90( x, 1, '10' ); // $ExpectError - rot90( x, 1, 10 ); // $ExpectError - rot90( x, 1, null ); // $ExpectError - rot90( x, 1, void 0 ); // $ExpectError - rot90( x, 1, [] ); // $ExpectError - rot90( x, 1, {} ); // $ExpectError - rot90( x, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - rot90(); // $ExpectError - rot90( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError - rot90( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError - rot90( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1, false, {} ); // $ExpectError -} diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/README.md b/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md similarity index 81% rename from lib/node_modules/@stdlib/ndarray/base/rot90/README.md rename to lib/node_modules/@stdlib/ndarray/base/rotr90/README.md index b8b80a8a72f9..5d88f8bc52cb 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# rot90 +# rotr90 -> Rotate a matrix (or a stack of matrices) by 90 degrees. +> Rotate a matrix (or a stack of matrices) 90 degrees clockwise. @@ -37,12 +37,12 @@ limitations under the License. ## Usage ```javascript -var rot90 = require( '@stdlib/ndarray/base/rot90' ); +var rotr90 = require( '@stdlib/ndarray/base/rotr90' ); ``` -#### rot90( x, k, writable ) +#### rotr90( x, k, writable ) -Rotates a matrix (or a stack of matrices) `x` by 90 degrees. +Rotates a matrix (or a stack of matrices) `x` 90 degrees clockwise. ```javascript var array = require( '@stdlib/ndarray/array' ); @@ -50,14 +50,14 @@ var array = require( '@stdlib/ndarray/array' ); var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns [ [ 1, 2 ], [ 3, 4 ] ] -var y = rot90( x, 1, false ); -// returns [ [ 2, 4 ], [ 1, 3 ] ] +var y = rotr90( x, 1, false ); +// returns [ [ 3, 1 ], [ 4, 2 ] ] ``` The function accepts the following arguments: - **x**: input ndarray. -- **k**: number of times to rotate by 90 degrees. Positive values rotate counterclockwise. Negative values rotate clockwise. +- **k**: number of times to rotate by 90 degrees. Positive values rotate clockwise. Negative values rotate counterclockwise. - **writable**: boolean indicating whether a returned ndarray should be writable. @@ -89,35 +89,35 @@ The function accepts the following arguments: ```javascript var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var rot90 = require( '@stdlib/ndarray/base/rot90' ); +var rotr90 = require( '@stdlib/ndarray/base/rotr90' ); // Create a 2x3 matrix: var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); -// Rotate 90 degrees counterclockwise: -var y = rot90( x, 1, false ); +// Rotate 90 degrees clockwise: +var y = rotr90( x, 1, false ); var arr = ndarray2array( y ); -// returns [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] +// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] // Rotate 180 degrees: -y = rot90( x, 2, false ); +y = rotr90( x, 2, false ); arr = ndarray2array( y ); // returns [ [ 6, 5, 4 ], [ 3, 2, 1 ] ] -// Rotate 270 degrees counterclockwise (equivalent to 90 degrees clockwise): -y = rot90( x, 3, false ); +// Rotate 270 degrees clockwise (equivalent to 90 degrees counterclockwise): +y = rotr90( x, 3, false ); arr = ndarray2array( y ); -// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] +// returns [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] // Rotate 360 degrees (equivalent to no rotation): -y = rot90( x, 4, false ); +y = rotr90( x, 4, false ); arr = ndarray2array( y ); // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] -// Rotate 90 degrees clockwise (equivalent to k=-1): -y = rot90( x, -1, false ); +// Rotate 90 degrees counterclockwise (equivalent to k=-1): +y = rotr90( x, -1, false ); arr = ndarray2array( y ); -// returns [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] +// returns [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] ``` diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/benchmark/benchmark.js similarity index 93% rename from lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js rename to lib/node_modules/@stdlib/ndarray/base/rotr90/benchmark/benchmark.js index b2b4e20eee3a..7c791d963ac7 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/benchmark/benchmark.js @@ -26,7 +26,7 @@ var baseEmpty = require( '@stdlib/ndarray/base/empty' ); var empty = require( '@stdlib/ndarray/empty' ); var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; -var rot90 = require( './../lib' ); +var rotr90 = require( './../lib' ); // MAIN // @@ -46,7 +46,7 @@ bench( format( '%s::2d,base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -78,7 +78,7 @@ bench( format( '%s::2d,non-base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -106,7 +106,7 @@ bench( format( '%s::3d,base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -138,7 +138,7 @@ bench( format( '%s::3d,non-base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -166,7 +166,7 @@ bench( format( '%s::4d,base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -198,7 +198,7 @@ bench( format( '%s::4d,non-base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -226,7 +226,7 @@ bench( format( '%s::5d,base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } @@ -258,7 +258,7 @@ bench( format( '%s::5d,non-base', pkg ), function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = rot90( values[ i%values.length ], 1, false ); + v = rotr90( values[ i%values.length ], 1, false ); if ( typeof v !== 'object' ) { b.fail( 'should return an ndarray' ); } diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt similarity index 86% rename from lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt rename to lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt index ba03ac741d6b..b27123de433b 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt @@ -1,9 +1,9 @@ {{alias}}( x, k, writable ) - Rotates a matrix (or a stack of matrices) by 90 degrees. + Rotates a matrix (or a stack of matrices) 90 degrees clockwise. - Positive values of `k` rotate counterclockwise. Negative values of `k` - rotate clockwise. + Positive values of `k` rotate clockwise. Negative values of `k` rotate + counterclockwise. The returned ndarray is a *view* of the input ndarray. Accordingly, writing to the original ndarray will mutate the returned ndarray and vice versa. @@ -35,12 +35,11 @@ > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1, 2 ], [ 3, 4 ] ] ) [ [ 1, 2 ], [ 3, 4 ] ] > var y = {{alias}}( x, 1, false ) - [ [ 2, 4 ], [ 1, 3 ] ] + [ [ 3, 1 ], [ 4, 2 ] ] > y = {{alias}}( x, 2, false ) [ [ 4, 3 ], [ 2, 1 ] ] > y = {{alias}}( x, 3, false ) - [ [ 3, 1 ], [ 4, 2 ] ] + [ [ 2, 4 ], [ 1, 3 ] ] See Also -------- - diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts similarity index 73% rename from lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts rename to lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts index d9be4b30451a..fb55571e8934 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts @@ -23,7 +23,7 @@ import { ndarray, typedndarray, genericndarray } from '@stdlib/types/ndarray'; /** -* Rotates a matrix (or a stack of matrices) by 90 degrees. +* Rotates a matrix (or a stack of matrices) 90 degrees clockwise. * * @param x - input array * @param k - number of times to rotate by 90 degrees @@ -36,13 +36,13 @@ import { ndarray, typedndarray, genericndarray } from '@stdlib/types/ndarray'; * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var y = rot90( x, 1, false ); -* // returns [ [ 2, 4 ], [ 1, 3 ] ] +* var y = rotr90( x, 1, false ); +* // returns [ [ 3, 1 ], [ 4, 2 ] ] */ -declare function rot90 = typedndarray>( x: T, k: number, writable: boolean ): T; +declare function rotr90 = typedndarray>( x: T, k: number, writable: boolean ): T; /** -* Rotates a matrix (or a stack of matrices) by 90 degrees. +* Rotates a matrix (or a stack of matrices) 90 degrees clockwise. * * @param x - input array * @param k - number of times to rotate by 90 degrees @@ -58,16 +58,16 @@ declare function rot90 = typedndarray>( * }); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var y = rot90( x, 1, false ); +* var y = rotr90( x, 1, false ); * // returns * * var arr = ndarray2array( y ); -* // returns [ [ 2, 4 ], [ 1, 3 ] ] +* // returns [ [ 3, 1 ], [ 4, 2 ] ] */ -declare function rot90 = genericndarray>( x: T, k: number, writable: boolean ): T; +declare function rotr90 = genericndarray>( x: T, k: number, writable: boolean ): T; /** -* Rotates a matrix (or a stack of matrices) by 90 degrees. +* Rotates a matrix (or a stack of matrices) 90 degrees clockwise. * * @param x - input array * @param k - number of times to rotate by 90 degrees @@ -83,15 +83,15 @@ declare function rot90 = genericndarray[ [ 1, 2 ], [ 3, 4 ] ] * -* var y = rot90( x, 1, false ); +* var y = rotr90( x, 1, false ); * // returns * * var arr = ndarray2array( y ); -* // returns [ [ 2, 4 ], [ 1, 3 ] ] +* // returns [ [ 3, 1 ], [ 4, 2 ] ] */ -declare function rot90( x: ndarray, k: number, writable: boolean ): ndarray; +declare function rotr90( x: ndarray, k: number, writable: boolean ): ndarray; // EXPORTS // -export = rot90; +export = rotr90; diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/test.ts new file mode 100644 index 000000000000..b46b31a0d0ee --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/test.ts @@ -0,0 +1,90 @@ +/* +* @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. +*/ + +import zeros = require( '@stdlib/ndarray/base/zeros' ); +import rotr90 = require( './index' ); + + +// TESTS // + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + rotr90( zeros( 'float64', sh, ord ), 1, false ); // $ExpectType float64ndarray + rotr90( zeros( 'float32', sh, ord ), 1, false ); // $ExpectType float32ndarray + rotr90( zeros( 'complex128', sh, ord ), 1, false ); // $ExpectType complex128ndarray + rotr90( zeros( 'complex64', sh, ord ), 1, false ); // $ExpectType complex64ndarray + rotr90( zeros( 'int32', sh, ord ), 1, false ); // $ExpectType int32ndarray + rotr90( zeros( 'int16', sh, ord ), 1, false ); // $ExpectType int16ndarray + rotr90( zeros( 'int8', sh, ord ), 1, false ); // $ExpectType int8ndarray + rotr90( zeros( 'uint32', sh, ord ), 1, false ); // $ExpectType uint32ndarray + rotr90( zeros( 'uint16', sh, ord ), 1, false ); // $ExpectType uint16ndarray + rotr90( zeros( 'uint8', sh, ord ), 1, false ); // $ExpectType uint8ndarray + rotr90( zeros( 'uint8c', sh, ord ), 1, false ); // $ExpectType uint8cndarray + rotr90( zeros( 'generic', sh, ord ), 1, false ); // $ExpectType genericndarray +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray having a recognized/supported data type... +{ + rotr90( '10', 1, false ); // $ExpectError + rotr90( 10, 1, false ); // $ExpectError + rotr90( false, 1, false ); // $ExpectError + rotr90( true, 1, false ); // $ExpectError + rotr90( null, 1, false ); // $ExpectError + rotr90( void 0, 1, false ); // $ExpectError + rotr90( [], 1, false ); // $ExpectError + rotr90( {}, 1, false ); // $ExpectError + rotr90( ( x: number ): number => x, 1, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a number... +{ + const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + rotr90( x, '10', false ); // $ExpectError + rotr90( x, false, false ); // $ExpectError + rotr90( x, true, false ); // $ExpectError + rotr90( x, null, false ); // $ExpectError + rotr90( x, void 0, false ); // $ExpectError + rotr90( x, [], false ); // $ExpectError + rotr90( x, {}, false ); // $ExpectError + rotr90( x, ( x: number ): number => x, false ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a boolean... +{ + const x = zeros( 'float64', [ 2, 2 ], 'row-major' ); + + rotr90( x, 1, '10' ); // $ExpectError + rotr90( x, 1, 10 ); // $ExpectError + rotr90( x, 1, null ); // $ExpectError + rotr90( x, 1, void 0 ); // $ExpectError + rotr90( x, 1, [] ); // $ExpectError + rotr90( x, 1, {} ); // $ExpectError + rotr90( x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + rotr90(); // $ExpectError + rotr90( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError + rotr90( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1 ); // $ExpectError + rotr90( zeros( 'float64', [ 2, 2 ], 'row-major' ), 1, false, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js similarity index 75% rename from lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js rename to lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js index eec1e6413eed..5d04949135a3 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js @@ -20,27 +20,32 @@ var array = require( '@stdlib/ndarray/array' ); var ndarray2array = require( '@stdlib/ndarray/to-array' ); -var rot90 = require( './../lib' ); +var rotr90 = require( './../lib' ); // Create a 2x3 matrix: var x = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] ); -// Rotate 90 degrees counterclockwise: -var y = rot90( x, 1, false ); +// Rotate 90 degrees clockwise: +var y = rotr90( x, 1, false ); console.log( ndarray2array( y ) ); -// => [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] +// => [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] // Rotate 180 degrees: -y = rot90( x, 2, false ); +y = rotr90( x, 2, false ); console.log( ndarray2array( y ) ); // => [ [ 6, 5, 4 ], [ 3, 2, 1 ] ] -// Rotate 270 degrees counterclockwise: -y = rot90( x, 3, false ); +// Rotate 270 degrees clockwise: +y = rotr90( x, 3, false ); console.log( ndarray2array( y ) ); -// => [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ] +// => [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] // Rotate 360 degrees: -y = rot90( x, 4, false ); +y = rotr90( x, 4, false ); console.log( ndarray2array( y ) ); // => [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] + +// Rotate 90 degrees counterclockwise (equivalent to k=-1): +y = rotr90( x, -1, false ); +console.log( ndarray2array( y ) ); +// => [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/index.js similarity index 78% rename from lib/node_modules/@stdlib/ndarray/base/rot90/lib/index.js rename to lib/node_modules/@stdlib/ndarray/base/rotr90/lib/index.js index 9659dd12bf36..8647408a8d05 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/lib/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/index.js @@ -19,19 +19,19 @@ 'use strict'; /** -* Rotate a matrix (or a stack of matrices) by 90 degrees. +* Rotate a matrix (or a stack of matrices) 90 degrees clockwise. * -* @module @stdlib/ndarray/base/rot90 +* @module @stdlib/ndarray/base/rotr90 * * @example * var array = require( '@stdlib/ndarray/array' ); -* var rot90 = require( '@stdlib/ndarray/base/rot90' ); +* var rotr90 = require( '@stdlib/ndarray/base/rotr90' ); * * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var y = rot90( x, 1, false ); -* // returns [ [ 2, 4 ], [ 1, 3 ] ] +* var y = rotr90( x, 1, false ); +* // returns [ [ 3, 1 ], [ 4, 2 ] ] */ // MODULES // diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js similarity index 86% rename from lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js rename to lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js index f9b27953c879..e408ba35528f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js @@ -31,7 +31,7 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); // MAIN // /** -* Rotate a matrix (or a stack of matrices) by 90 degrees. +* Rotates a matrix (or a stack of matrices) 90 degrees clockwise. * * @param {ndarray} x - input array * @param {integer} k - number of times to rotate by 90 degrees @@ -44,13 +44,12 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] ); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * -* var y = rot90( x, 1, false ); -* // returns [ [ 2, 4 ], [ 1, 3 ] ] +* var y = rotr90( x, 1, false ); +* // returns [ [ 3, 1 ], [ 4, 2 ] ] * */ -function rot90( x, k, writable ) { +function rotr90( x, k, writable ) { var offset; - var nk; var sh; var st; var sm; @@ -66,7 +65,12 @@ function rot90( x, k, writable ) { } st = getStrides( x, true ); offset = getOffset( x ); - nk = ( ( k % 4 ) + 4 ) % 4; + + // Normalize k to the range [0, 3]: + k %= 4; + if ( k < 0 ) { + k += 4; + } // Cache the original shape and stride values for the last two dimensions: M = sh[ d-2 ]; @@ -74,22 +78,22 @@ function rot90( x, k, writable ) { sm = st[ d-2 ]; sn = st[ d-1 ]; - if ( nk === 1 ) { + if ( k === 1 ) { sh[ d-2 ] = N; sh[ d-1 ] = M; - st[ d-2 ] = -sn; - st[ d-1 ] = sm; - offset += ( N - 1 ) * sn; - } else if ( nk === 2 ) { + st[ d-2 ] = sn; + st[ d-1 ] = -sm; + offset += ( M - 1 ) * sm; + } else if ( k === 2 ) { st[ d-2 ] = -sm; st[ d-1 ] = -sn; offset += ( ( M - 1 ) * sm ) + ( ( N - 1 ) * sn ); - } else if ( nk === 3 ) { + } else if ( k === 3 ) { sh[ d-2 ] = N; sh[ d-1 ] = M; - st[ d-2 ] = sn; - st[ d-1 ] = -sm; - offset += ( M - 1 ) * sm; + st[ d-2 ] = -sn; + st[ d-1 ] = sm; + offset += ( N - 1 ) * sn; } return new x.constructor( getDType( x ), getData( x ), sh, st, offset, getOrder( x ), { // eslint-disable-line max-len 'readonly': !writable @@ -99,4 +103,4 @@ function rot90( x, k, writable ) { // EXPORTS // -module.exports = rot90; +module.exports = rotr90; diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/package.json b/lib/node_modules/@stdlib/ndarray/base/rotr90/package.json similarity index 87% rename from lib/node_modules/@stdlib/ndarray/base/rot90/package.json rename to lib/node_modules/@stdlib/ndarray/base/rotr90/package.json index ec44bc96c7a0..2ed04b6b5fea 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/package.json +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/ndarray/base/rot90", + "name": "@stdlib/ndarray/base/rotr90", "version": "0.0.0", - "description": "Rotate a matrix (or a stack of matrices) by 90 degrees.", + "description": "Rotate a matrix (or a stack of matrices) 90 degrees clockwise.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -59,8 +59,8 @@ "matrix", "rotate", "rotation", - "rot90", - "view", - "numpy.rot90" + "rotr90", + "clockwise", + "view" ] } diff --git a/lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/test/test.js similarity index 77% rename from lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js rename to lib/node_modules/@stdlib/ndarray/base/rotr90/test/test.js index aa25225b42d1..ec9f16095269 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rot90/test/test.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/test/test.js @@ -40,14 +40,14 @@ var getDType = require( '@stdlib/ndarray/dtype' ); var getOrder = require( '@stdlib/ndarray/order' ); var getShape = require( '@stdlib/ndarray/shape' ); var getStrides = require( '@stdlib/ndarray/strides' ); -var rot90 = require( './../lib' ); +var rotr90 = 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.strictEqual( typeof rotr90, 'function', 'main export is a function' ); t.end(); }); @@ -56,8 +56,11 @@ tape( 'the function returns the input array unchanged if provided an ndarray hav var x; x = new ndarray( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ); - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); + t.strictEqual( arr, x, 'returns expected value' ); + x = new base( 'float64', new Float64Array( [ 5.0 ] ), [], [ 0 ], 0, 'row-major' ); + arr = rotr90( x, 1, false ); t.strictEqual( arr, x, 'returns expected value' ); t.end(); @@ -68,14 +71,17 @@ tape( 'the function returns the input array unchanged if provided an ndarray hav var x; x = new ndarray( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ); - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); + t.strictEqual( arr, x, 'returns expected value' ); + x = new base( 'float64', new Float64Array( [ 1.0, 2.0, 3.0 ] ), [ 3 ], [ 1 ], 0, 'row-major' ); + arr = rotr90( x, 1, false ); t.strictEqual( arr, x, 'returns expected value' ); t.end(); }); -tape( 'the function rotates a matrix for all values of k (dtype=float64, base, row-major)', function test( t ) { +tape( 'the function rotates a matrix clockwise for all values of k (dtype=float64, base, row-major)', function test( t ) { var expected; var arr; var buf; @@ -85,7 +91,7 @@ tape( 'the function rotates a matrix for all values of k (dtype=float64, base, r x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); // k=0 (no rotation): - arr = rot90( x, 0, false ); + arr = rotr90( x, 0, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); @@ -96,17 +102,17 @@ tape( 'the function rotates a matrix for all values of k (dtype=float64, base, r expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); - // k=1 (90 degrees counterclockwise): - arr = rot90( x, 1, false ); + // k=1 (90 degrees clockwise): + arr = rotr90( x, 1, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=2 (180 degrees): - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); @@ -114,19 +120,19 @@ tape( 'the function rotates a matrix for all values of k (dtype=float64, base, r expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); - // k=3 (270 degrees counterclockwise): - arr = rot90( x, 3, false ); + // k=3 (270 degrees clockwise): + arr = rotr90( x, 3, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); t.end(); }); -tape( 'the function rotates a matrix for all values of k (dtype=float64, base, column-major)', function test( t ) { +tape( 'the function rotates a matrix clockwise for all values of k (dtype=float64, base, column-major)', function test( t ) { var expected; var arr; var buf; @@ -138,29 +144,29 @@ tape( 'the function rotates a matrix for all values of k (dtype=float64, base, c // In column-major with strides [1,2], x = [ [ 1.0, 3.0, 5.0 ], [ 2.0, 4.0, 6.0 ] ] // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; + expected = [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); expected = [ [ 6.0, 4.0, 2.0 ], [ 5.0, 3.0, 1.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=3: - arr = rot90( x, 3, false ); + arr = rotr90( x, 3, false ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); - expected = [ [ 2.0, 1.0 ], [ 4.0, 3.0 ], [ 6.0, 5.0 ] ]; + expected = [ [ 5.0, 6.0 ], [ 3.0, 4.0 ], [ 1.0, 2.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); t.end(); }); -tape( 'the function rotates a matrix for all values of k (dtype=float64, non-base)', function test( t ) { +tape( 'the function rotates a matrix clockwise for all values of k (dtype=float64, non-base)', function test( t ) { var expected; var arr; var buf; @@ -173,7 +179,7 @@ tape( 'the function rotates a matrix for all values of k (dtype=float64, non-bas }); // k=0: - arr = rot90( x, 0, false ); + arr = rotr90( x, 0, false ); t.strictEqual( instanceOf( arr, ndarray ), true, 'returns expected value' ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); @@ -181,30 +187,30 @@ tape( 'the function rotates a matrix for all values of k (dtype=float64, non-bas t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=3: - arr = rot90( x, 3, false ); + arr = rotr90( x, 3, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); t.end(); }); -tape( 'the function rotates a matrix for all values of k (dtype=float32, base)', function test( t ) { +tape( 'the function rotates a matrix clockwise for all values of k (dtype=float32)', function test( t ) { var expected; var arr; var buf; @@ -214,55 +220,44 @@ tape( 'the function rotates a matrix for all values of k (dtype=float32, base)', x = new base( 'float32', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.deepEqual( getShape( arr ), [ 2, 3 ], 'returns expected value' ); expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=3: - arr = rot90( x, 3, false ); + arr = rotr90( x, 3, false ); t.deepEqual( getShape( arr ), [ 3, 2 ], 'returns expected value' ); - expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function rotates a matrix for all values of k (dtype=float32, non-base)', function test( t ) { - var expected; - var arr; - var buf; - var x; - - buf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + // Non-base, k=1: x = array( buf, { 'shape': [ 2, 3 ], 'dtype': 'float32' }); - - // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); - expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); - // k=1, writable: - arr = rot90( x, 1, true ); + // Non-base, k=1, writable: + arr = rotr90( x, 1, true ); t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); t.end(); }); -tape( 'the function rotates a matrix (dtype=complex128, base)', function test( t ) { +tape( 'the function rotates a matrix clockwise (dtype=complex128, base)', function test( t ) { var arr; var buf; var v; @@ -271,28 +266,28 @@ tape( 'the function rotates a matrix (dtype=complex128, base)', function test( t buf = new Complex128Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); x = new base( 'complex128', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - // k=1: - arr = rot90( x, 1, false ); + // k=1 (90 degrees clockwise): + arr = rotr90( x, 1, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); v = arr.get( 0, 0 ); - t.strictEqual( real( v ), 2.0, 'returns expected value' ); - t.strictEqual( imag( v ), 2.0, 'returns expected value' ); + t.strictEqual( real( v ), 3.0, 'returns expected value' ); + t.strictEqual( imag( v ), 3.0, 'returns expected value' ); v = arr.get( 0, 1 ); - t.strictEqual( real( v ), 4.0, 'returns expected value' ); - t.strictEqual( imag( v ), 4.0, 'returns expected value' ); - v = arr.get( 1, 0 ); t.strictEqual( real( v ), 1.0, 'returns expected value' ); t.strictEqual( imag( v ), 1.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( real( v ), 4.0, 'returns expected value' ); + t.strictEqual( imag( v ), 4.0, 'returns expected value' ); v = arr.get( 1, 1 ); - t.strictEqual( real( v ), 3.0, 'returns expected value' ); - t.strictEqual( imag( v ), 3.0, 'returns expected value' ); + t.strictEqual( real( v ), 2.0, 'returns expected value' ); + t.strictEqual( imag( v ), 2.0, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); v = arr.get( 0, 0 ); t.strictEqual( real( v ), 4.0, 'returns expected value' ); t.strictEqual( imag( v ), 4.0, 'returns expected value' ); @@ -309,7 +304,7 @@ tape( 'the function rotates a matrix (dtype=complex128, base)', function test( t t.end(); }); -tape( 'the function rotates a matrix (dtype=complex64, base)', function test( t ) { +tape( 'the function rotates a matrix clockwise (dtype=complex64, base)', function test( t ) { var arr; var buf; var v; @@ -318,30 +313,30 @@ tape( 'the function rotates a matrix (dtype=complex64, base)', function test( t buf = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] ); x = new base( 'complex64', buf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); - // k=1: - arr = rot90( x, 1, false ); + // k=1 (90 degrees clockwise): + arr = rotr90( x, 1, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( String( getDType( arr ) ), String( getDType( x ) ), 'returns expected value' ); t.deepEqual( getShape( arr ), [ 2, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); v = arr.get( 0, 0 ); - t.strictEqual( realf( v ), 2.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); + t.strictEqual( realf( v ), 3.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 3.0, 'returns expected value' ); v = arr.get( 0, 1 ); - t.strictEqual( realf( v ), 4.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); - v = arr.get( 1, 0 ); t.strictEqual( realf( v ), 1.0, 'returns expected value' ); t.strictEqual( imagf( v ), 1.0, 'returns expected value' ); + v = arr.get( 1, 0 ); + t.strictEqual( realf( v ), 4.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 4.0, 'returns expected value' ); v = arr.get( 1, 1 ); - t.strictEqual( realf( v ), 3.0, 'returns expected value' ); - t.strictEqual( imagf( v ), 3.0, 'returns expected value' ); + t.strictEqual( realf( v ), 2.0, 'returns expected value' ); + t.strictEqual( imagf( v ), 2.0, 'returns expected value' ); t.end(); }); -tape( 'the function rotates a matrix for all values of k (dtype=generic, base)', function test( t ) { +tape( 'the function rotates a matrix clockwise for all values of k (dtype=generic)', function test( t ) { var expected; var arr; var buf; @@ -351,60 +346,49 @@ tape( 'the function rotates a matrix for all values of k (dtype=generic, base)', x = new base( 'generic', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); // k=0: - arr = rot90( x, 0, false ); + arr = rotr90( x, 0, false ); t.strictEqual( instanceOf( arr, base ), true, 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ]; + expected = [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ [ 6, 5, 4 ], [ 3, 2, 1 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=3: - arr = rot90( x, 3, false ); + arr = rotr90( x, 3, false ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ]; + expected = [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function rotates a matrix for all values of k (dtype=generic, non-base)', function test( t ) { - var expected; - var arr; - var buf; - var x; - - buf = [ 1, 2, 3, 4, 5, 6 ]; + // Non-base, k=1: x = array( buf, { 'shape': [ 2, 3 ], 'dtype': 'generic' }); - - // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); - expected = [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ]; + expected = [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); - // k=1, writable: - arr = rot90( x, 1, true ); + // Non-base, k=1, writable: + arr = rotr90( x, 1, true ); t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); t.end(); }); -tape( 'the function supports negative values of k', function test( t ) { +tape( 'the function supports negative and large values of k', function test( t ) { var expected; var arr; var buf; @@ -413,23 +397,43 @@ tape( 'the function supports negative values of k', function test( t ) { buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); - // k=-1`````: - arr = rot90( x, -1, false ); - expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + // k=-1 (90 degrees counterclockwise): + arr = rotr90( x, -1, false ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=-2: - arr = rot90( x, -2, false ); + arr = rotr90( x, -2, false ); expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=-3: - arr = rot90( x, -3, false ); - expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + arr = rotr90( x, -3, false ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=-4: - arr = rot90( x, -4, false ); + arr = rotr90( x, -4, false ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=5 (same as k=1): + arr = rotr90( x, 5, false ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=8 (same as k=0): + arr = rotr90( x, 8, false ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=-5 (same as k=-1): + arr = rotr90( x, -5, false ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=-8 (same as k=0): + arr = rotr90( x, -8, false ); expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); @@ -446,7 +450,7 @@ tape( 'the function supports a stack of matrices for all values of k', function x = new base( 'generic', buf, [ 2, 2, 3 ], [ 6, 3, 1 ], 0, 'row-major' ); // k=0: - arr = rot90( x, 0, false ); + arr = rotr90( x, 0, false ); t.deepEqual( getShape( arr ), [ 2, 2, 3 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ @@ -456,17 +460,17 @@ tape( 'the function supports a stack of matrices for all values of k', function t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.deepEqual( getShape( arr ), [ 2, 3, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ - [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ], - [ [ 9, 12 ], [ 8, 11 ], [ 7, 10 ] ] + [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ], + [ [ 10, 7 ], [ 11, 8 ], [ 12, 9 ] ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.deepEqual( getShape( arr ), [ 2, 2, 3 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ @@ -476,12 +480,12 @@ tape( 'the function supports a stack of matrices for all values of k', function t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); // k=3: - arr = rot90( x, 3, false ); + arr = rotr90( x, 3, false ); t.deepEqual( getShape( arr ), [ 2, 3, 2 ], 'returns expected value' ); t.strictEqual( getData( arr ), getData( x ), 'returns expected value' ); expected = [ - [ [ 4, 1 ], [ 5, 2 ], [ 6, 3 ] ], - [ [ 10, 7 ], [ 11, 8 ], [ 12, 9 ] ] + [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ], + [ [ 9, 12 ], [ 8, 11 ], [ 7, 10 ] ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); @@ -500,32 +504,64 @@ tape( 'the function supports the `writable` parameter', function test( t ) { }); // k=0: - arr = rot90( x, 0, false ); + arr = rotr90( x, 0, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); - arr = rot90( x, 0, true ); + arr = rotr90( x, 0, true ); t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); // k=1: - arr = rot90( x, 1, false ); + arr = rotr90( x, 1, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); - arr = rot90( x, 1, true ); + arr = rotr90( x, 1, true ); t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); // k=2: - arr = rot90( x, 2, false ); + arr = rotr90( x, 2, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); - arr = rot90( x, 2, true ); + arr = rotr90( x, 2, true ); t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); // k=3: - arr = rot90( x, 3, false ); + arr = rotr90( x, 3, false ); t.strictEqual( isReadOnly( arr ), true, 'returns expected value' ); - arr = rot90( x, 3, true ); + arr = rotr90( x, 3, true ); t.strictEqual( isReadOnly( arr ), false, 'returns expected value' ); t.end(); }); +tape( 'the function supports a non-zero offset', function test( t ) { + var expected; + var arr; + var buf; + var x; + + buf = new Float64Array( [ 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 2, 'row-major' ); + + // k=0: + arr = rotr90( x, 0, false ); + expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=1: + arr = rotr90( x, 1, false ); + expected = [ [ 4.0, 1.0 ], [ 5.0, 2.0 ], [ 6.0, 3.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=2: + arr = rotr90( x, 2, false ); + expected = [ [ 6.0, 5.0, 4.0 ], [ 3.0, 2.0, 1.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + // k=3: + arr = rotr90( x, 3, false ); + expected = [ [ 3.0, 6.0 ], [ 2.0, 5.0 ], [ 1.0, 4.0 ] ]; + t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); + + t.end(); +}); + tape( 'rotating four times returns the original arrangement', function test( t ) { var expected; var arr; @@ -535,10 +571,10 @@ tape( 'rotating four times returns the original arrangement', function test( t ) buf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); x = new base( 'float64', buf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' ); - arr = rot90( x, 1, false ); - arr = rot90( arr, 1, false ); - arr = rot90( arr, 1, false ); - arr = rot90( arr, 1, false ); + arr = rotr90( x, 1, false ); + arr = rotr90( arr, 1, false ); + arr = rotr90( arr, 1, false ); + arr = rotr90( arr, 1, false ); expected = [ [ 1.0, 2.0, 3.0 ], [ 4.0, 5.0, 6.0 ] ]; t.deepEqual( ndarray2array( arr ), expected, 'returns expected value' ); From 9c0c42905950e969bcb1f02011028747ee8940c3 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Wed, 25 Mar 2026 04:22:49 +0500 Subject: [PATCH 3/9] docs: 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: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_license_headers status: passed --- --- lib/node_modules/@stdlib/ndarray/base/rotr90/README.md | 2 ++ .../@stdlib/ndarray/base/rotr90/docs/repl.txt | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md b/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md index 5d88f8bc52cb..107629c3c874 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md @@ -71,6 +71,8 @@ The function accepts the following arguments: ## Notes - The `writable` parameter **only** applies to ndarray constructors supporting **read-only** instances. +- If `k > 0` the function rotates the matrix clockwise. +- If `k < 0` the function rotates the matrix counterclockwise. - The returned ndarray is a **view** of the input ndarray. Accordingly, writing to the original ndarray will **mutate** the returned ndarray and vice versa. - If provided an ndarray with fewer than two dimensions, the function returns the input array unchanged. diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt index b27123de433b..51747bfef8ff 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/repl.txt @@ -2,8 +2,11 @@ {{alias}}( x, k, writable ) Rotates a matrix (or a stack of matrices) 90 degrees clockwise. - Positive values of `k` rotate clockwise. Negative values of `k` rotate - counterclockwise. + If `k > 0` the function rotates the matrix clockwise. If `k < 0` the + function rotates the matrix counterclockwise. + + If provided an ndarray with fewer than two dimensions, the function returns + the input array unchanged. The returned ndarray is a *view* of the input ndarray. Accordingly, writing to the original ndarray will mutate the returned ndarray and vice versa. @@ -11,9 +14,6 @@ The `writable` parameter only applies to ndarray constructors supporting read-only instances. - If provided an ndarray with fewer than two dimensions, the function returns - the input array unchanged. - Parameters ---------- x: ndarray From fb1bb2ae62f346e557923d01003112c9d08144e3 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 17:19:10 -0700 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/ndarray/base/rotr90/lib/main.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js index e408ba35528f..9ebf15c6cb31 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js @@ -66,29 +66,33 @@ function rotr90( x, k, writable ) { st = getStrides( x, true ); offset = getOffset( x ); - // Normalize k to the range [0, 3]: + // Normalize `k` to the interval [0, 3]: k %= 4; if ( k < 0 ) { k += 4; } - // Cache the original shape and stride values for the last two dimensions: M = sh[ d-2 ]; N = sh[ d-1 ]; sm = st[ d-2 ]; sn = st[ d-1 ]; + // Case: rotate 90 deg clockwise if ( k === 1 ) { sh[ d-2 ] = N; sh[ d-1 ] = M; st[ d-2 ] = sn; st[ d-1 ] = -sm; offset += ( M - 1 ) * sm; - } else if ( k === 2 ) { + } + // Case: rotate 180 deg clockwise (i.e., reverse both dimensions) + else if ( k === 2 ) { st[ d-2 ] = -sm; st[ d-1 ] = -sn; offset += ( ( M - 1 ) * sm ) + ( ( N - 1 ) * sn ); - } else if ( k === 3 ) { + } + // Case: rotate 270 deg clockwise + else if ( k === 3 ) { sh[ d-2 ] = N; sh[ d-1 ] = M; st[ d-2 ] = -sn; From bf5a40d01159c40574ca72ec84fb2da2b5e5ed4d Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 17:19:59 -0700 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js index 9ebf15c6cb31..3fd5dfdd9aab 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/lib/main.js @@ -46,7 +46,6 @@ var getData = require( '@stdlib/ndarray/base/data-buffer' ); * * var y = rotr90( x, 1, false ); * // returns [ [ 3, 1 ], [ 4, 2 ] ] -* */ function rotr90( x, k, writable ) { var offset; From 0a75fd3638102af1025a764699f169b26780ebaa Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 17:27:21 -0700 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../ndarray/base/rotr90/docs/types/index.d.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts index fb55571e8934..1e0bf74fd31c 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/docs/types/index.d.ts @@ -51,18 +51,13 @@ declare function rotr90 = typedndarray> * * @example * var array = require( `@stdlib/ndarray/array` ); -* var ndarray2array = require( `@stdlib/ndarray/to-array` ); -* * var x = array( [ [ 1, 2 ], [ 3, 4 ] ], { * 'dtype': 'generic' * }); * // returns [ [ 1, 2 ], [ 3, 4 ] ] * * var y = rotr90( x, 1, false ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ [ 3, 1 ], [ 4, 2 ] ] +* // returns [ [ 3, 1 ], [ 4, 2 ] ] */ declare function rotr90 = genericndarray>( x: T, k: number, writable: boolean ): T; @@ -76,7 +71,6 @@ declare function rotr90 = genericndarray = genericndarray[ [ 1, 2 ], [ 3, 4 ] ] * * var y = rotr90( x, 1, false ); -* // returns -* -* var arr = ndarray2array( y ); -* // returns [ [ 3, 1 ], [ 4, 2 ] ] +* // returns [ [ 3, 1 ], [ 4, 2 ] ] */ declare function rotr90( x: ndarray, k: number, writable: boolean ): ndarray; From 0af31050882d877203beddcb94b340b81a27c2a2 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 17:29:35 -0700 Subject: [PATCH 7/9] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js index 5d04949135a3..e20e6027a497 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js @@ -45,7 +45,7 @@ y = rotr90( x, 4, false ); console.log( ndarray2array( y ) ); // => [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] -// Rotate 90 degrees counterclockwise (equivalent to k=-1): +// Rotate 90 degrees counterclockwise: y = rotr90( x, -1, false ); console.log( ndarray2array( y ) ); // => [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] From 5b870ea76acaf6677c30d083a0275cdef5dff138 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 17:30:16 -0700 Subject: [PATCH 8/9] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js index e20e6027a497..bf9d2b615260 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/examples/index.js @@ -45,7 +45,7 @@ y = rotr90( x, 4, false ); console.log( ndarray2array( y ) ); // => [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] -// Rotate 90 degrees counterclockwise: +// Rotate 90 degrees counterclockwise (equivalent to k=3): y = rotr90( x, -1, false ); console.log( ndarray2array( y ) ); // => [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ] From 463d14fb079d8af18f4ca66a939538028b58c60c Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 6 Apr 2026 17:32:48 -0700 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/ndarray/base/rotr90/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md b/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md index 107629c3c874..e7e9e86de58f 100644 --- a/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md +++ b/lib/node_modules/@stdlib/ndarray/base/rotr90/README.md @@ -42,7 +42,7 @@ var rotr90 = require( '@stdlib/ndarray/base/rotr90' ); #### rotr90( x, k, writable ) -Rotates a matrix (or a stack of matrices) `x` 90 degrees clockwise. +Rotates a matrix (or a stack of matrices) 90 degrees clockwise. ```javascript var array = require( '@stdlib/ndarray/array' ); @@ -116,7 +116,7 @@ y = rotr90( x, 4, false ); arr = ndarray2array( y ); // returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] -// Rotate 90 degrees counterclockwise (equivalent to k=-1): +// Rotate 90 degrees counterclockwise (equivalent to 270 degrees clockwise): y = rotr90( x, -1, false ); arr = ndarray2array( y ); // returns [ [ 3, 6 ], [ 2, 5 ], [ 1, 4 ] ]