Skip to content

Commit 2104202

Browse files
committed
refactor: cleanup & fixes
--- 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 1dc0ed5 commit 2104202

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
--------
5050
> var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0 ], [ 2.0 ] ] );
5151
> var y = {{alias:@stdlib/ndarray/array}}( [ [ 3.0 ], [ 4.0 ] ] );
52-
> var z = {{alias:@stdlib/ndarra/array}}( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] );
52+
> var z = {{alias:@stdlib/ndarray/array}}( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] );
5353
> var out = {{alias}}.assign( [ x, y ], z, -1 )
5454
<ndarray>
5555
> var bool = ( out === z )

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ var output = require( './output.js' );
4848
* @param {ndarray} out - output ndarray
4949
* @param {NegativeInteger} dim - dimension along which the ndarrays are concatenated
5050
* @throws {TypeError} first argument must be an array of ndarray-like objects
51-
* @throws {RangeError} first argument must have more than one ndarray
52-
* @throws {TypeError} second argument must be an array of ndarray-like objects
51+
* @throws {RangeError} first argument must have one or more ndarrays
52+
* @throws {TypeError} second argument must be an ndarray-like object
5353
* @returns {ndarray} output ndarray
5454
*
5555
* @example
@@ -96,10 +96,10 @@ function assign( arrays, out, dim ) {
9696

9797
if ( arguments.length > 1 ) {
9898
if ( !isInteger( dim ) ) {
99-
throw new TypeError( format( 'invalid argument. Second argument must be a negative integer. Value: `%s`.', dim ) );
99+
throw new TypeError( format( 'invalid argument. Third argument must be a negative integer. Value: `%s`.', dim ) );
100100
}
101101
if ( isNonNegativeInteger( dim ) ) {
102-
throw new TypeError( format( 'invalid argument. Second argument must be a negative integer. Value: `%s`.', dim ) );
102+
throw new TypeError( format( 'invalid argument. Third argument must be a negative integer. Value: `%s`.', dim ) );
103103
}
104104
}
105105

lib/node_modules/@stdlib/ndarray/concat/test/test.assign.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tape( 'main export is a function', function test( t ) {
3838
t.end();
3939
});
4040

41-
tape( 'the function throws an error if provided a first argument which is not an array of ndarrays', function test( t ) {
41+
tape( 'the function throws an error if provided a first argument which is not an array of ndarrays or an empty array', function test( t ) {
4242
var values;
4343
var out;
4444
var i;
@@ -54,13 +54,18 @@ tape( 'the function throws an error if provided a first argument which is not an
5454
null,
5555
void 0,
5656
{},
57+
[],
5758
[ 'beep', 'boop' ],
5859
[ 1, 2, 3 ],
5960
[ null ]
6061
];
6162

6263
for ( i = 0; i < values.length; i++ ) {
63-
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
64+
if ( i === 8 ) {
65+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
66+
} else {
67+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
68+
}
6469
}
6570
t.end();
6671

@@ -71,12 +76,14 @@ tape( 'the function throws an error if provided a first argument which is not an
7176
}
7277
});
7378

74-
tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) {
79+
tape( 'the function throws an error if provided a second argument which is not an ndarray or has incompatible shape', function test( t ) {
7580
var values;
7681
var x;
82+
var y;
7783
var i;
7884

7985
x = zeros( [ 2, 2 ] );
86+
y = zeros( [ 2, 2 ] );
8087

8188
values = [
8289
'5',
@@ -88,17 +95,22 @@ tape( 'the function throws an error if provided a second argument which is not a
8895
void 0,
8996
[],
9097
{},
91-
function noop() {}
98+
function noop() {},
99+
zeros( [ 3, 4 ] )
92100
];
93101

94102
for ( i = 0; i < values.length; i++ ) {
95-
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
103+
if ( i === 10 ) {
104+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
105+
} else {
106+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
107+
}
96108
}
97109
t.end();
98110

99111
function badValue( value ) {
100112
return function badValue() {
101-
assign( [ x ], value, -1 );
113+
assign( [ x, y ], value, -1 );
102114
};
103115
}
104116
});

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ tape( 'main export is a function', function test( t ) {
3939
t.end();
4040
});
4141

42-
tape( 'the function throws an error if provided a first argument which is not an array of ndarrays', function test( t ) {
42+
tape( 'the function throws an error if provided a first argument which is not an array of ndarrays or an empty array', function test( t ) {
4343
var values;
4444
var i;
4545

@@ -52,13 +52,18 @@ tape( 'the function throws an error if provided a first argument which is not an
5252
null,
5353
void 0,
5454
{},
55+
[],
5556
[ 'beep', 'boop' ],
5657
[ 1, 2, 3 ],
5758
[ null ]
5859
];
5960

6061
for ( i = 0; i < values.length; i++ ) {
61-
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
62+
if ( i === 8 ) {
63+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
64+
} else {
65+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
66+
}
6267
}
6368
t.end();
6469

@@ -152,6 +157,21 @@ tape( 'the function concatenates ndarrays along a specified dimension', function
152157
t.deepEqual( getShape( out ), [ 2, 5 ], 'returns expected value' );
153158
t.deepEqual( actual, expected, 'returns expected value' );
154159

160+
xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
161+
x = new ndarray( 'float64', xbuf, [ 2, 2 ], [ 2, 1 ], 0, 'row-major' );
162+
163+
out = concat( [ x ], -1 );
164+
165+
actual = ndarray2array( out );
166+
expected = [
167+
[ 1.0, 2.0 ],
168+
[ 3.0, 4.0 ]
169+
];
170+
171+
t.strictEqual( getDtype( out ), 'float64', 'returns expected value' );
172+
t.deepEqual( getShape( out ), [ 2, 2 ], 'returns expected value' );
173+
t.deepEqual( actual, expected, 'returns expected value' );
174+
155175
t.end();
156176
});
157177

0 commit comments

Comments
 (0)