Skip to content

Commit 33f60ac

Browse files
committed
fix: 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: 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: na - task: lint_license_headers status: passed ---
1 parent 000e3c2 commit 33f60ac

4 files changed

Lines changed: 425 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ var concat = require( '@stdlib/ndarray/concat' ).assign;
3434
*
3535
* @param {ArrayLikeObject<ndarrayLike>} arrays - array-like object containing input ndarrays
3636
* @param {ndarrayLike} out - output ndarray
37+
* @throws {TypeError} first argument must be an array-like object containing one or more ndarrays
38+
* @throws {TypeError} second argument must be an ndarray-like object
39+
* @throws {TypeError} second argument must have a valid shape
40+
* @throws {RangeError} must provide ndarrays having two or more dimensions
41+
* @throws {Error} must provide ndarrays which are broadcast-compatible with one another
42+
* @throws {Error} must provide ndarrays which can be safely cast to a common data type
43+
* @throws {Error} input ndarrays must be safely castable to the output ndarray data type
3744
* @returns {ndarrayLike} output ndarray
3845
*
3946
* @example

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ var concat = require( '@stdlib/ndarray/concat' );
3333
* - Input ndarrays must have more than one dimension.
3434
*
3535
* @param {ArrayLikeObject<ndarrayLike>} arrays - array-like object containing input ndarrays
36+
* @throws {TypeError} first argument must be an array-like object containing one or more ndarrays
37+
* @throws {RangeError} must provide ndarrays having two or more dimensions
38+
* @throws {Error} must provide ndarrays which are broadcast-compatible with one another
39+
* @throws {Error} must provide ndarrays which can be safely cast to a common data type
3640
* @returns {ndarray} output ndarray
3741
*
3842
* @example

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

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var ndarray2array = require( '@stdlib/ndarray/to-array' );
2626
var Float64Array = require( '@stdlib/array/float64' );
2727
var Int32Array = require( '@stdlib/array/int32' );
2828
var zeros = require( '@stdlib/ndarray/zeros' );
29+
var empty = require( '@stdlib/ndarray/empty' );
2930
var assign = require( './../lib/assign.js' );
3031

3132

@@ -37,6 +38,270 @@ tape( 'main export is a function', function test( t ) {
3738
t.end();
3839
});
3940

41+
tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) {
42+
var values;
43+
var out;
44+
var i;
45+
46+
out = zeros( [ 4, 2 ] );
47+
48+
values = [
49+
'5',
50+
5,
51+
NaN,
52+
true,
53+
false,
54+
null,
55+
void 0,
56+
{},
57+
function noop() {}
58+
];
59+
60+
for ( i = 0; i < values.length; i++ ) {
61+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
62+
}
63+
t.end();
64+
65+
function badValue( value ) {
66+
return function badValue() {
67+
assign( value, out );
68+
};
69+
}
70+
});
71+
72+
tape( 'the function throws an error if provided a first argument which is an empty array-like object', function test( t ) {
73+
var out = zeros( [ 4, 2 ] );
74+
t.throws( bad, TypeError, 'throws an error' );
75+
t.end();
76+
77+
function bad() {
78+
assign( [], out );
79+
}
80+
});
81+
82+
tape( 'the function throws an error if provided a first argument containing values which are not ndarrays', function test( t ) {
83+
var values;
84+
var out;
85+
var i;
86+
87+
out = zeros( [ 4, 2 ] );
88+
89+
values = [
90+
[ 'beep', 'boop' ],
91+
[ 1, 2, 3 ],
92+
[ null ]
93+
];
94+
95+
for ( i = 0; i < values.length; i++ ) {
96+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
97+
}
98+
t.end();
99+
100+
function badValue( value ) {
101+
return function badValue() {
102+
assign( value, out );
103+
};
104+
}
105+
});
106+
107+
tape( 'the function throws an error if provided a second argument which is not an ndarray', function test( t ) {
108+
var values;
109+
var x;
110+
var y;
111+
var i;
112+
113+
x = zeros( [ 2, 2 ] );
114+
y = zeros( [ 2, 2 ] );
115+
116+
values = [
117+
'5',
118+
5,
119+
NaN,
120+
true,
121+
false,
122+
null,
123+
void 0,
124+
[],
125+
{},
126+
function noop() {}
127+
];
128+
129+
for ( i = 0; i < values.length; i++ ) {
130+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
131+
}
132+
t.end();
133+
134+
function badValue( value ) {
135+
return function badValue() {
136+
assign( [ x, y ], value );
137+
};
138+
}
139+
});
140+
141+
tape( 'the function throws an error if provided a first argument containing ndarrays having fewer than two dimensions', function test( t ) {
142+
var values;
143+
var out;
144+
var i;
145+
146+
out = zeros( [ 6 ] );
147+
148+
values = [
149+
[
150+
empty( [ 3 ], {
151+
'dtype': 'float64'
152+
}),
153+
empty( [ 3 ], {
154+
'dtype': 'float64'
155+
})
156+
],
157+
[
158+
empty( [ 2, 2 ], {
159+
'dtype': 'float64'
160+
}),
161+
empty( [ 2 ], {
162+
'dtype': 'float64'
163+
})
164+
]
165+
];
166+
167+
for ( i = 0; i < values.length; i++ ) {
168+
t.throws( badValue( values[ i ] ), RangeError, 'throws an error when provided ' + values[ i ] );
169+
}
170+
t.end();
171+
172+
function badValue( value ) {
173+
return function badValue() {
174+
assign( value, out );
175+
};
176+
}
177+
});
178+
179+
tape( 'the function throws an error if provided a first argument containing ndarrays which are not broadcast-compatible', function test( t ) {
180+
var values;
181+
var out;
182+
var i;
183+
184+
out = zeros( [ 4, 3 ] );
185+
186+
values = [
187+
[
188+
empty( [ 2, 2 ], {
189+
'dtype': 'float64'
190+
}),
191+
empty( [ 2, 3 ], {
192+
'dtype': 'float64'
193+
})
194+
]
195+
];
196+
197+
for ( i = 0; i < values.length; i++ ) {
198+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
199+
}
200+
t.end();
201+
202+
function badValue( value ) {
203+
return function badValue() {
204+
assign( value, out );
205+
};
206+
}
207+
});
208+
209+
tape( 'the function throws an error if provided a first argument containing ndarrays which do not promote to a common data type', function test( t ) {
210+
var values;
211+
var out;
212+
var i;
213+
214+
out = zeros( [ 4, 2 ], {
215+
'dtype': 'float64'
216+
});
217+
218+
values = [
219+
[
220+
empty( [ 2, 2 ], {
221+
'dtype': 'bool'
222+
}),
223+
empty( [ 2, 2 ], {
224+
'dtype': 'float64'
225+
})
226+
]
227+
];
228+
229+
for ( i = 0; i < values.length; i++ ) {
230+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
231+
}
232+
t.end();
233+
234+
function badValue( value ) {
235+
return function badValue() {
236+
assign( value, out );
237+
};
238+
}
239+
});
240+
241+
tape( 'the function throws an error if provided a second argument having a data type to which input ndarrays cannot be safely cast', function test( t ) {
242+
var values;
243+
var out;
244+
var i;
245+
246+
out = empty( [ 4, 2 ], {
247+
'dtype': 'bool'
248+
});
249+
250+
values = [
251+
[
252+
empty( [ 2, 2 ], {
253+
'dtype': 'float32'
254+
}),
255+
empty( [ 2, 2 ], {
256+
'dtype': 'float64'
257+
})
258+
]
259+
];
260+
261+
for ( i = 0; i < values.length; i++ ) {
262+
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
263+
}
264+
t.end();
265+
266+
function badValue( value ) {
267+
return function badValue() {
268+
assign( value, out );
269+
};
270+
}
271+
});
272+
273+
tape( 'the function throws an error if provided a second argument having an invalid shape', function test( t ) {
274+
var values;
275+
var out;
276+
var i;
277+
278+
out = zeros( [ 5, 5 ], {
279+
'dtype': 'float64'
280+
});
281+
282+
values = [
283+
[
284+
empty( [ 2, 2 ], {
285+
'dtype': 'float64'
286+
}),
287+
empty( [ 2, 2 ], {
288+
'dtype': 'float64'
289+
})
290+
]
291+
];
292+
293+
for ( i = 0; i < values.length; i++ ) {
294+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
295+
}
296+
t.end();
297+
298+
function badValue( value ) {
299+
return function badValue() {
300+
assign( value, out );
301+
};
302+
}
303+
});
304+
40305
tape( 'the function concatenates two-dimensional ndarrays along the second-to-last dimension', function test( t ) {
41306
var expected;
42307
var actual;

0 commit comments

Comments
 (0)