Skip to content

Commit 91c2563

Browse files
committed
chore: clean-up
--- 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: 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: passed - task: lint_license_headers status: passed ---
1 parent 8487482 commit 91c2563

File tree

8 files changed

+70
-28
lines changed

8 files changed

+70
-28
lines changed

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# toReversedDimension
2222

23-
> Return a new [`ndarray`][@stdlib/ndarray/ctor] where the order of elements of an input [`ndarray`][@stdlib/ndarray/ctor] is reversed.
23+
> Return a new [ndarray][@stdlib/ndarray/ctor] where the order of elements of an input [ndarray][@stdlib/ndarray/ctor] along a specified dimension is reversed.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -42,7 +42,7 @@ var toReversedDimension = require( '@stdlib/ndarray/to-reversed-dimension' );
4242

4343
#### toReversedDimension( x\[, options] )
4444

45-
Returns a new [`ndarray`][@stdlib/ndarray/ctor] where the order of elements of an input [`ndarray`][@stdlib/ndarray/ctor] is reversed.
45+
Returns a new [ndarray][@stdlib/ndarray/ctor] where the order of elements of an input [ndarray][@stdlib/ndarray/ctor] along a specified dimension is reversed.
4646

4747
```javascript
4848
var array = require( '@stdlib/ndarray/array' );
@@ -56,7 +56,7 @@ var y = toReversedDimension( x );
5656

5757
The function accepts the following arguments:
5858

59-
- **x**: input ndarray.
59+
- **x**: input [ndarray][@stdlib/ndarray/ctor].
6060
- **options**: function options (_optional_).
6161

6262
The function supports the following options:
@@ -86,12 +86,12 @@ The function supports the following options:
8686
```javascript
8787
var uniform = require( '@stdlib/random/uniform' );
8888
var ndarray2array = require( '@stdlib/ndarray/to-array' );
89-
var toReversed = require( '@stdlib/ndarray/to-reversed-dimension' );
89+
var toReversedDimension = require( '@stdlib/ndarray/to-reversed-dimension' );
9090

9191
var x = uniform( [ 3, 3, 3 ], -10.0, 10.0 );
9292
console.log( ndarray2array( x ) );
9393

94-
var y = toReversed( x );
94+
var y = toReversedDimension( x );
9595
console.log( ndarray2array( y ) );
9696
```
9797

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{{alias}}( x[, options] )
3-
Returns a new ndarray where the order of elements of an input ndarray is
4-
reversed.
3+
Returns a new ndarray where the order of elements of an input ndarray along
4+
a specified dimension is reversed.
55

66
Parameters
77
----------

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/docs/types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
import { ndarray } from '@stdlib/types/ndarray';
2424

2525
/**
26-
* Base options.
26+
* Interface describing function options.
2727
*/
2828
interface Options {
2929
/**
30-
* Index of dimension to reverse.
30+
* Index of dimension to reverse. Default: `-1`.
3131
*/
3232
dim?: number;
3333
}
3434

3535
/**
36-
* Returns a new ndarray where the order of elements of an input ndarray is reversed.
36+
* Returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed.
3737
*
3838
* @param x - input array
3939
* @param options - function options

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/docs/types/test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import toReversedDimension = require( './index' );
6363
toReversedDimension( x, ( x: number ): number => x ); // $ExpectError
6464
}
6565

66-
// The compiler throws an error if the function is provided a `options.dim` property which is not a number...
66+
// The compiler throws an error if the function is provided a `dim` option which is not a number...
6767
{
6868
const x = empty( [ 2, 2 ] );
6969

@@ -72,6 +72,7 @@ import toReversedDimension = require( './index' );
7272
toReversedDimension( x, { 'dim': false } ); // $ExpectError
7373
toReversedDimension( x, { 'dim': null } ); // $ExpectError
7474
toReversedDimension( x, { 'dim': [ '5' ] } ); // $ExpectError
75+
toReversedDimension( x, { 'dim': {} } ); // $ExpectError
7576
toReversedDimension( x, { 'dim': ( x: number ): number => x} ); // $ExpectError
7677
}
7778

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Return a new ndarray where the order of elements of an input ndarray is reversed along a specified dimension.
22+
* Return a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed.
2323
*
2424
* @module @stdlib/ndarray/to-reversed-dimension
2525
*

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/lib/main.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,28 @@
2020

2121
// MODULES //
2222

23-
var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' );
24-
var base = require( '@stdlib/ndarray/base/to-reversed-dimension' );
2523
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2624
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
2725
var isObject = require( '@stdlib/assert/is-plain-object' );
2826
var isInteger = require( '@stdlib/assert/is-integer' );
29-
var format = require( '@stdlib/string/format' );
27+
var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' );
28+
var base = require( '@stdlib/ndarray/base/to-reversed-dimension' );
3029
var ndims = require( '@stdlib/ndarray/ndims' );
30+
var format = require( '@stdlib/string/format' );
3131

3232

3333
// MAIN //
3434

3535
/**
36-
* Returns a new ndarray where the order of elements of an input ndarray is reversed.
36+
* Returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed.
3737
*
38-
* @param {ndarray} x - input array
39-
* @param {Object} options - function options
40-
* @param {integer} options.dim - index of dimension to reverse
38+
* @param {ndarrayLike} x - input array
39+
* @param {Object} [options] - function options
40+
* @param {integer} [options.dim=-1] - index of dimension to reverse
4141
* @throws {TypeError} first argument must be an ndarray
4242
* @throws {TypeError} options argument must be an object
43+
* @throws {TypeError} must provide valid options
44+
* @throws {RangeError} `dim` option is out-of-bounds
4345
* @returns {ndarray} output array
4446
*
4547
* @example
@@ -53,13 +55,11 @@ var ndims = require( '@stdlib/ndarray/ndims' );
5355
*/
5456
function toReversedDimension( x, options ) {
5557
var opts;
56-
var d;
5758
var N;
58-
59+
var d;
5960
if ( !isndarrayLike( x ) ) {
6061
throw new TypeError( format( 'invalid argument. First argument must be an ndarray. Value: `%s`.', x ) );
6162
}
62-
N = ndims( x );
6363
opts = {
6464
'dim': -1
6565
};
@@ -74,7 +74,11 @@ function toReversedDimension( x, options ) {
7474
opts.dim = options.dim;
7575
}
7676
}
77+
N = ndims( x );
7778
d = normalizeIndex( opts.dim, N-1 );
79+
if ( d === -1 ) {
80+
throw new RangeError( format( 'invalid option. Dimension index exceeds the number of dimensions. Number of dimensions: %d. Value: `%d`.', N, d ) );
81+
}
7882
return base( x, d );
7983
}
8084

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/ndarray/to-reversed-dimension",
33
"version": "0.0.0",
4-
"description": "Return a new ndarray where the order of elements of an input ndarray is reversed.",
4+
"description": "Return a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",
@@ -52,7 +52,6 @@
5252
"stdlib",
5353
"stdtypes",
5454
"types",
55-
"base",
5655
"data",
5756
"structure",
5857
"vector",

lib/node_modules/@stdlib/ndarray/to-reversed-dimension/test/test.js

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ tape( 'the function throws an error if provided an options argument which is not
129129
}
130130
});
131131

132-
tape( 'the function returns an error if provided a `dim` option which is not an integer', function test( t ) {
132+
tape( 'the function throws an error if provided a `dim` option which is not an integer', function test( t ) {
133133
var values;
134134
var x;
135135
var i;
@@ -162,7 +162,45 @@ tape( 'the function returns an error if provided a `dim` option which is not an
162162
}
163163
});
164164

165-
tape( 'the function returns a new ndarray where the order of elements of an input ndarray is reversed (ndims=1)', function test( t ) {
165+
tape( 'the function throws an error if provided a `dim` option which is out-of-bounds', function test( t ) {
166+
var values;
167+
var x;
168+
var i;
169+
170+
x = empty( [ 2, 2 ] );
171+
values = [
172+
-4,
173+
-3,
174+
2,
175+
3,
176+
4
177+
];
178+
179+
for ( i = 0; i < values.length; i++ ) {
180+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
181+
}
182+
t.end();
183+
184+
function badValue( value ) {
185+
return function badValue() {
186+
toReversedDimension( x, {
187+
'dim': value
188+
});
189+
};
190+
}
191+
});
192+
193+
tape( 'the function throws an error if provided a zero-dimensional ndarray', function test( t ) {
194+
var x = empty( [] );
195+
t.throws( badValue, RangeError, 'throws an error' );
196+
t.end();
197+
198+
function badValue() {
199+
toReversedDimension( x );
200+
}
201+
});
202+
203+
tape( 'the function returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed (ndims=1)', function test( t ) {
166204
var expected;
167205
var actual;
168206
var x;
@@ -193,7 +231,7 @@ tape( 'the function returns a new ndarray where the order of elements of an inpu
193231
t.end();
194232
});
195233

196-
tape( 'the function returns a new ndarray where the order of elements of an input ndarray is reversed (ndims=2)', function test( t ) {
234+
tape( 'the function returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed (ndims=2)', function test( t ) {
197235
var expected;
198236
var actual;
199237
var x;
@@ -225,7 +263,7 @@ tape( 'the function returns a new ndarray where the order of elements of an inpu
225263
t.end();
226264
});
227265

228-
tape( 'the function returns a new ndarray where the order of elements of an input ndarray is reversed (ndims=3)', function test( t ) {
266+
tape( 'the function returns a new ndarray where the order of elements of an input ndarray along a specified dimension is reversed (ndims=3)', function test( t ) {
229267
var expected;
230268
var actual;
231269
var x;

0 commit comments

Comments
 (0)