Skip to content

Commit 30c433f

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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 1539193 commit 30c433f

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var normalizeIndex = require( '@stdlib/ndarray/base/normalize-index' );
2525
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
2626
var indicesComplement = require( '@stdlib/array/base/indices-complement' );
2727
var nditerStacks = require( '@stdlib/ndarray/iter/stacks' );
28+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' );
2829
var getShape = require( '@stdlib/ndarray/shape' );
2930
var getStrides = require( '@stdlib/ndarray/strides' );
3031
var getDtype = require( '@stdlib/ndarray/dtype' );
@@ -40,9 +41,10 @@ var output = require( './output.js' );
4041
* Concatenates a list of ndarrays along a specified ndarray dimension.
4142
*
4243
* @param {ArrayLikeObject<Object>} arrays - array-like object containing input ndarrays
43-
* @param {integer} dim - dimension along which the arrays are concatenated
44+
* @param {NegativeInteger} dim - dimension along which the arrays are concatenated
4445
* @throws {TypeError} first argument must be an array of ndarray-like objects
45-
* @throws {RangeError} first argument must have more than one ndarray
46+
* @throws {RangeError} first argument must have one or more ndarrays
47+
* @throws {TypeError} second argument must be a negative integer
4648
* @returns {ndarray} output ndarray
4749
*
4850
* @example
@@ -56,11 +58,11 @@ var output = require( './output.js' );
5658
* var ybuf = new Float64Array( [ -5.0, 6.0, -7.0, 8.0, -9.0, 10.0 ] );
5759
* var y = new ndarray( 'float64', ybuf, [ 2, 3 ], [ 3, 1 ], 0, 'row-major' );
5860
*
59-
* var out = concat( [ x, y ] );
61+
* var out = concat( [ x, y ], -1 );
6062
* // returns <ndarray>
6163
*
6264
* var arr = ndarray2array( out );
63-
* // returns [ [ -1.0, 2.0, -5.0, 6.0, 7.0 ], [ -3.0, 4.0, 8.0, 9.0, 10.0 ] ]
65+
* // returns [ [ -1.0, 2.0, -5.0, 6.0, -7.0 ], [ -3.0, 4.0, 8.0, -9.0, 10.0 ] ]
6466
*/
6567
function concat( arrays, dim ) {
6668
var istacks;
@@ -69,6 +71,7 @@ function concat( arrays, dim ) {
6971
var shapes;
7072
var dtypes;
7173
var orders;
74+
var nargs;
7275
var arrs;
7376
var out;
7477
var mi;
@@ -77,10 +80,14 @@ function concat( arrays, dim ) {
7780
var s;
7881
var i;
7982

83+
nargs = arguments.length;
84+
if ( nargs === 2 && isNonNegativeInteger( dim ) ) {
85+
throw new TypeError( format( 'invalid argument. Second argument must be a negative integer. Value: `%s`.', dim ) );
86+
}
8087
N = arrays.length;
8188
arrs = [];
8289
if ( N < 1 ) {
83-
throw new RangeError( format( 'invalid argument. First argument must have more than one ndarray. Value: `%s`.', N ) );
90+
throw new RangeError( format( 'invalid argument. First argument must have one or more ndarrays. Value: `%s`.', N ) );
8491
}
8592
// Unpack the ndarrays and standardize ndarray meta data:
8693
shapes = [];
@@ -89,7 +96,7 @@ function concat( arrays, dim ) {
8996
orders = [];
9097
for ( i = 0; i < N; i++ ) {
9198
if ( !isndarrayLike( arrays[ i ] ) ) {
92-
throw new TypeError( format( 'invalid argument. First argument must be an array of ndarray-like objects. Value: `%s`.', arrays[ i ] ) );
99+
throw new TypeError( format( 'invalid argument. First argument must be an array of ndarrays. Value: `%s`.', arrays[ i ] ) );
93100
}
94101
arrs[ i ] = arrays[ i ];
95102
shapes.push( getShape( arrs[ i ] ) );

lib/node_modules/@stdlib/ndarray/concat/lib/output.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var empty = require( '@stdlib/ndarray/empty' );
2626
var slice = require( '@stdlib/array/slice' );
2727
var getShape = require( '@stdlib/ndarray/shape' );
2828
var getDtype = require( '@stdlib/ndarray/dtype' );
29-
var getOrder = require( '@stdlib/ndarray/order' );
3029
var format = require( '@stdlib/string/format' );
3130

3231

@@ -73,6 +72,7 @@ function resolveOutputOrder( orders ) {
7372
*/
7473
function output( shapes, dtypes, orders, dim, out ) {
7574
var ord;
75+
var osh;
7676
var sh;
7777
var dt;
7878
var s;
@@ -89,14 +89,12 @@ function output( shapes, dtypes, orders, dim, out ) {
8989
if ( getDtype( out ) !== dt ) {
9090
throw new TypeError( format( 'invalid argument. Output ndarray must have a dtype of `%s`. Value: `%s`.', dt, getDtype( out ) ) );
9191
}
92-
if ( getOrder( out ) !== ord ) {
93-
throw new TypeError( format( 'invalid argument. Output ndarray must have an order of `%s`. Value: `%s`.', ord, getOrder( out ) ) );
94-
}
95-
if ( getShape( out ).length !== sh.length ) {
92+
osh = getShape( out );
93+
if ( osh.length !== sh.length ) {
9694
throw new RangeError( format( 'invalid argument. Output ndarray must have %d dimensions. Value: %d.', sh.length, getShape( out ).length ) );
9795
}
9896
for ( i = 0; i < sh.length; i++ ) {
99-
if ( getShape( out )[ i ] !== sh[ i ] ) {
97+
if ( osh[ i ] !== sh[ i ] ) {
10098
throw new RangeError( format( 'invalid argument. Output ndarray dimension %d must have size %d. Value: %d.', i, sh[ i ], getShape( out )[ i ] ) );
10199
}
102100
}

0 commit comments

Comments
 (0)