Skip to content

Commit dceb694

Browse files
committed
refactor: apply suggestions from code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: skipped - task: lint_license_headers status: passed ---
1 parent 492e68f commit dceb694

5 files changed

Lines changed: 63 additions & 9 deletions

File tree

lib/node_modules/@stdlib/ndarray/rot90/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ The function accepts the following options:
7676

7777
- If `k > 0`, the function rotates the plane from the first specified dimension toward the second specified dimension. This means that, for a two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane counterclockwise.
7878
- If `k < 0`, the function rotates the plane from the second specified dimension toward the first specified dimension. This means that, for a two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane clockwise.
79+
- Each provided dimension index must reside on the interval `[-ndims, ndims-1]`.
7980

8081
</section>
8182

lib/node_modules/@stdlib/ndarray/rot90/docs/repl.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
Returns a read-only view of an input ndarray rotated 90 degrees in a
44
specified plane.
55

6+
If `k > 0`, the function rotates the plane from the first specified
7+
dimension toward the second specified dimension. This means that, for a
8+
two-dimensional ndarray and `dims = [0, 1]`, the function rotates the plane
9+
counterclockwise.
10+
11+
If `k < 0`, the function rotates the plane from the second specified
12+
dimension toward the first specified dimension. This means that, for a
13+
two-dimensional ndarray and `dims = [1, 0]`, the function rotates the plane
14+
clockwise.
15+
16+
Each provided dimension index must reside on the interval [-ndims, ndims-1].
17+
618
Parameters
719
----------
820
x: ndarray
@@ -16,7 +28,9 @@
1628

1729
options.dims: ArrayLikeObject<integer> (optional)
1830
Dimension indices defining the plane of rotation. Must contain exactly
19-
two unique dimension indices. Default: [ -2, -1 ].
31+
two unique dimension indices. If less than zero, an index is resolved
32+
relative to the last dimension, with the last dimension corresponding to
33+
the value `-1`. Default: [ -2, -1 ].
2034

2135
Returns
2236
-------

lib/node_modules/@stdlib/ndarray/rot90/docs/types/index.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// <reference types="@stdlib/types"/>
2222

2323
import { ndarray } from '@stdlib/types/ndarray';
24-
import { Collection } from '@stdlib/types/array';
24+
import { ArrayLike } from '@stdlib/types/array';
2525

2626
/**
2727
* Interface defining function options.
@@ -35,17 +35,21 @@ interface Options {
3535
/**
3636
* Dimension indices defining the plane of rotation (default: [-2, -1]).
3737
*/
38-
dims?: Collection<number>;
38+
dims?: ArrayLike<number>;
3939
}
4040

4141
/**
4242
* Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane.
4343
*
44+
* ## Notes
45+
*
46+
* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`.
47+
*
4448
* @param x - input array
4549
* @param options - function options
4650
* @param options.k - number of times to rotate by 90 degrees (default: 1)
4751
* @param options.dims - dimension indices defining the plane of rotation (default: [-2, -1])
48-
* @returns ndarray view
52+
* @returns output array
4953
*
5054
* @example
5155
* var array = require( '@stdlib/ndarray/array' );

lib/node_modules/@stdlib/ndarray/rot90/lib/main.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
// MODULES //
2222

23-
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
23+
var isIntegerArray = require( '@stdlib/assert/is-integer-array' ).primitives;
24+
var isEmptyCollection = require( '@stdlib/assert/is-empty-collection' );
2425
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
26+
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
2527
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
26-
var isCollection = require( '@stdlib/assert/is-collection' );
2728
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2829
var base = require( '@stdlib/ndarray/base/rot90' );
2930
var format = require( '@stdlib/string/format' );
@@ -34,14 +35,18 @@ var format = require( '@stdlib/string/format' );
3435
/**
3536
* Returns a read-only view of an input ndarray rotated 90 degrees in a specified plane.
3637
*
38+
* ## Notes
39+
*
40+
* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`.
41+
*
3742
* @param {ndarray} x - input array
3843
* @param {Options} [options] - function options
3944
* @param {integer} [options.k=1] - number of times to rotate by 90 degrees
4045
* @param {IntegerArray} [options.dims=[-2,-1]] - dimension indices defining the plane of rotation
4146
* @throws {TypeError} first argument must be an ndarray
4247
* @throws {TypeError} options argument must be an object
4348
* @throws {TypeError} `k` option must be an integer
44-
* @throws {TypeError} `dims` option must be an array-like object of integers
49+
* @throws {TypeError} `dims` option must be an array of integers
4550
* @throws {RangeError} must provide exactly two dimension indices
4651
* @throws {RangeError} input ndarray must have at least two dimensions
4752
* @throws {RangeError} must provide valid dimension indices
@@ -77,8 +82,8 @@ function rot90( x, options ) {
7782
k = options.k;
7883
}
7984
if ( hasOwnProp( options, 'dims' ) ) {
80-
if ( !isCollection( options.dims ) ) {
81-
throw new TypeError( format( 'invalid option. `%s` option must be an array-like object. Option: `%s`.', 'dims', options.dims ) );
85+
if ( !isIntegerArray( options.dims ) && !isEmptyCollection( options.dims ) ) { // eslint-disable-line max-len
86+
throw new TypeError( format( 'invalid option. `%s` option must be an array of integers. Option: `%s`.', 'dims', options.dims ) );
8287
}
8388
dims = options.dims;
8489
}

lib/node_modules/@stdlib/ndarray/rot90/test/test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,36 @@ tape( 'the function throws an error if provided a `dims` option which is not an
170170
}
171171
});
172172

173+
tape( 'the function throws an error if provided a `dims` option which is not an array of integers', function test( t ) {
174+
var values;
175+
var x;
176+
var i;
177+
178+
x = new ndarray( 'float64', [ 1, 2, 3, 4 ], [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
179+
180+
values = [
181+
[ '0', '1' ],
182+
[ 0.5, 1.5 ],
183+
[ NaN, NaN ],
184+
[ null, null ],
185+
[ true, false ],
186+
[ {}, {} ]
187+
];
188+
189+
for ( i = 0; i < values.length; i++ ) {
190+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided [' + values[ i ] + ']' );
191+
}
192+
t.end();
193+
194+
function badValue( value ) {
195+
return function badValue() {
196+
rot90( x, {
197+
'dims': value
198+
});
199+
};
200+
}
201+
});
202+
173203
tape( 'the function throws an error if provided a `dims` option which does not contain exactly two dimension indices', function test( t ) {
174204
var values;
175205
var x;

0 commit comments

Comments
 (0)