Skip to content

Commit e652244

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: 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: 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 1fb9e9f commit e652244

File tree

8 files changed

+87
-51
lines changed

8 files changed

+87
-51
lines changed

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

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

2121
# shift
2222

23-
> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the first element(s) along a specific dimension.
23+
> Return an array containing a read-only truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a read-only view of the first element(s) along a specified dimension.
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,24 +42,17 @@ var shift = require( '@stdlib/ndarray/shift' );
4242

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

45-
Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the first element(s) along a specific dimension.
45+
Returns an array containing a **read-only** truncated view of an input [`ndarray`][@stdlib/ndarray/ctor] and a **read-only** view of the first element(s) along a specified dimension.
4646

4747
```javascript
48-
var ndarray = require( '@stdlib/ndarray/ctor' );
49-
var getShape = require( '@stdlib/ndarray/shape' );
48+
var array = require( '@stdlib/ndarray/array' );
5049
var ndarray2array = require( '@stdlib/ndarray/to-array' );
5150

52-
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
53-
var shape = [ 3, 2 ];
54-
var strides = [ 2, 1 ];
55-
var offset = 0;
56-
57-
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
51+
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], {
52+
'shape': [ 3, 2 ]
53+
});
5854
// returns <ndarray>
5955

60-
var sh = getShape( x );
61-
// returns [ 3, 2 ]
62-
6356
var arr = ndarray2array( x );
6457
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
6558

@@ -82,24 +75,17 @@ The function supports the following `options`:
8275

8376
- **dim**: dimension along which to perform the operation. If provided an integer less than zero, the dimension index is resolved relative to the last dimension, with the last dimension corresponding to the value `-1`. Default: `0`.
8477

85-
By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a desired dimension, provide the `dim` option.
78+
By default, the function performs operation along the first dimension of the input [`ndarray`][@stdlib/ndarray/ctor]. To perform operation along a specific dimension, provide the `dim` option.
8679

8780
```javascript
88-
var ndarray = require( '@stdlib/ndarray/ctor' );
89-
var getShape = require( '@stdlib/ndarray/shape' );
81+
var array = require( '@stdlib/ndarray/array' );
9082
var ndarray2array = require( '@stdlib/ndarray/to-array' );
9183

92-
var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ];
93-
var shape = [ 3, 2 ];
94-
var strides = [ 2, 1 ];
95-
var offset = 0;
96-
97-
var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
84+
var x = array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ], {
85+
'shape': [ 3, 2 ]
86+
});
9887
// returns <ndarray>
9988

100-
var sh = getShape( x );
101-
// returns [ 3, 2 ]
102-
10389
var arr = ndarray2array( x );
10490
// returns [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]
10591

@@ -140,20 +126,17 @@ arr = ndarray2array( y[ 1 ] );
140126
```javascript
141127
var array = require( '@stdlib/ndarray/array' );
142128
var ndarray2array = require( '@stdlib/ndarray/to-array' );
143-
var zeroTo = require( '@stdlib/array/base/zero-to' );
144-
var shift = require( '@stdlib/ndarray/shift' );
129+
var zeroTo = require( '@stdlib/array/zero-to' );
130+
var pop = require( '@stdlib/ndarray/pop' );
145131

146-
// Create a linear ndarray buffer:
147-
var buf = zeroTo( 27 );
148-
149-
// Create an ndarray which is a stack of three 3x3 matrices:
150-
var x = array( buf, {
132+
// Create an ndarray:
133+
var x = array( zeroTo( 27 ), {
151134
'shape': [ 3, 3, 3 ]
152135
});
136+
console.log( ndarray2array( x ) );
153137

154-
// Perform the operation:
138+
// Remove the first stack from a stack of matrices:
155139
var y = shift( x );
156-
// returns [ <ndarray>, <ndarray> ]
157140

158141
console.log( ndarray2array( y[ 0 ] ) );
159142
console.log( ndarray2array( y[ 1 ] ) );

lib/node_modules/@stdlib/ndarray/shift/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] )
33
Returns an array containing a read-only truncated view of an input ndarray
4-
and a read-only view of the first element(s) along a specific dimension.
4+
and a read-only view of the first element(s) along a specified dimension.
55

66
Parameters
77
----------
@@ -21,7 +21,7 @@
2121
-------
2222
out: Array<ndarray>
2323
An array containing a read-only truncated view of an input ndarray and a
24-
read-only view of the first element(s) along a specific dimension.
24+
read-only view of the first element(s) along a specified dimension.
2525

2626
Examples
2727
--------

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ interface Options {
3333
}
3434

3535
/**
36-
* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension.
36+
* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension.
3737
*
3838
* @param x - input array
3939
* @param options - function options

lib/node_modules/@stdlib/ndarray/shift/examples/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020

2121
var array = require( '@stdlib/ndarray/array' );
2222
var ndarray2array = require( '@stdlib/ndarray/to-array' );
23-
var zeroTo = require( '@stdlib/array/base/zero-to' );
23+
var zeroTo = require( '@stdlib/array/zero-to' );
2424
var shift = require( './../lib' );
2525

26-
// Create a linear ndarray buffer:
27-
var buf = zeroTo( 27 );
28-
2926
// Create an ndarray:
30-
var x = array( buf, {
27+
var x = array( zeroTo( 27 ), {
3128
'shape': [ 3, 3, 3 ]
3229
});
3330
console.log( ndarray2array( x ) );
3431

35-
// Perform the operation:
32+
// Remove the first stack from a stack of matrices:
3633
var y = shift( x );
3734

3835
console.log( ndarray2array( y[ 0 ] ) );

lib/node_modules/@stdlib/ndarray/shift/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 an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension.
22+
* Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension.
2323
*
2424
* @module @stdlib/ndarray/shift
2525
*

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ var format = require( '@stdlib/string/format' );
3131
// MAIN //
3232

3333
/**
34-
* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension.
34+
* Returns an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension.
3535
*
3636
* @param {ndarray} x - input array
3737
* @param {Object} [options] - function options
3838
* @param {integer} [options.dim=0] - dimension along which to perform the operation
3939
* @throws {TypeError} first argument must be an ndarray having one or more dimensions
40+
* @throws {RangeError} dimension index exceeds the number of dimensions
4041
* @throws {TypeError} options argument must be an object
4142
* * @throws {TypeError} must provide valid options
42-
* @returns {Array<ndarray>} a list of ndarrays
43+
* @returns {Array<ndarray>} a list of ndarray views
4344
*
4445
* @example
4546
* var ndarray = require( '@stdlib/ndarray/ctor' );
@@ -82,7 +83,7 @@ function shift( x ) {
8283
}
8384
if ( hasOwnProp( options, 'dim' ) ) {
8485
if ( !isInteger( options.dim ) ) {
85-
throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'strict', options.strict ) );
86+
throw new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'strict', options.strict ) );
8687
}
8788
opts.dim = options.dim;
8889
}

lib/node_modules/@stdlib/ndarray/shift/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/ndarray/shift",
33
"version": "0.0.0",
4-
"description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specific dimension.",
4+
"description": "Return an array containing a read-only truncated view of an input ndarray and a read-only view of the first element(s) along a specified dimension.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

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

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,20 @@ tape( 'the function returns an array containing ndarrays (ndims=1, options)', fu
246246
t.deepEqual( ndarray2array( actual[0] ), [ 1, 2, 3, 4, 5 ], 'returns expected value' );
247247
t.deepEqual( ndarray2array( actual[1] ), [ 0 ], 'returns expected value' );
248248

249+
opts = {
250+
'dim': -1
251+
};
252+
actual = shift( x, opts );
253+
254+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
255+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
256+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
257+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
258+
t.deepEqual( getShape( actual[0] ), [ 5 ], 'returns expected value' );
259+
t.deepEqual( getShape( actual[1] ), [ 1 ], 'returns expected value' );
260+
t.deepEqual( ndarray2array( actual[0] ), [ 1, 2, 3, 4, 5 ], 'returns expected value' );
261+
t.deepEqual( ndarray2array( actual[1] ), [ 0 ], 'returns expected value' );
262+
249263
t.end();
250264
});
251265

@@ -298,11 +312,25 @@ tape( 'the function returns an array containing ndarrays (ndims=2, options)', fu
298312

299313
x = new ndarray( 'float64', buf, sh, st, o, ord );
300314
opts = {
301-
'dim': 1
315+
'dim': 0
302316
};
303317

304318
actual = shift( x, opts );
305319

320+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
321+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
322+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
323+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
324+
t.deepEqual( getShape( actual[0] ), [ 1, 4 ], 'returns expected value' );
325+
t.deepEqual( getShape( actual[1] ), [ 1, 4 ], 'returns expected value' );
326+
t.deepEqual( ndarray2array( actual[0] ), [ [ 4, 5, 6, 7] ], 'returns expected value' );
327+
t.deepEqual( ndarray2array( actual[1] ), [ [ 0, 1, 2, 3 ] ], 'returns expected value' );
328+
329+
opts = {
330+
'dim': -1
331+
};
332+
actual = shift( x, opts );
333+
306334
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
307335
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
308336
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
@@ -387,10 +415,24 @@ tape( 'the function returns an array containing ndarrays (ndims=3, options)', fu
387415
*];
388416
*/
389417
x = new ndarray( 'float64', buf, sh, st, o, ord );
418+
390419
opts = {
391-
'dim': 1
420+
'dim': 0
392421
};
422+
actual = shift( x, opts );
393423

424+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
425+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
426+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
427+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
428+
t.deepEqual( getShape( actual[0] ), [ 1, 2, 2 ], 'returns expected value' );
429+
t.deepEqual( getShape( actual[1] ), [ 1, 2, 2 ], 'returns expected value' );
430+
t.deepEqual( ndarray2array( actual[0] ), [ [ [ 4, 5 ], [ 6, 7 ] ] ], 'returns expected value' );
431+
t.deepEqual( ndarray2array( actual[1] ), [ [ [ 0, 1 ], [ 2, 3 ] ] ], 'returns expected value' );
432+
433+
opts = {
434+
'dim': -2
435+
};
394436
actual = shift( x, opts );
395437

396438
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
@@ -468,9 +510,22 @@ tape( 'the function returns empty views if provided an empty array (ndims=2, opt
468510
sh = [ 2, 0 ];
469511
x = new ndarray( 'float64', buf, sh, st, o, ord );
470512
opts = {
471-
'dim': 1
513+
'dim': 0
472514
};
515+
actual = shift( x, opts );
473516

517+
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );
518+
t.strictEqual( isndarrayLike( actual[1] ), true, 'returns expected value' );
519+
t.strictEqual( isReadOnly( actual[0] ), true, 'returns expected value' );
520+
t.strictEqual( isReadOnly( actual[1] ), true, 'returns expected value' );
521+
t.deepEqual( getShape( actual[0] ), [ 1, 0 ], 'returns expected value' );
522+
t.deepEqual( getShape( actual[1] ), [ 1, 0 ], 'returns expected value' );
523+
t.deepEqual( ndarray2array( actual[0] ), [], 'returns expected value' );
524+
t.deepEqual( ndarray2array( actual[1] ), [], 'returns expected value' );
525+
526+
opts = {
527+
'dim': -1
528+
};
474529
actual = shift( x, opts );
475530

476531
t.strictEqual( isndarrayLike( actual[0] ), true, 'returns expected value' );

0 commit comments

Comments
 (0)