You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Delegate `dtype` validation to `emptyLike` during output array creation:
338
+
if(!isMostlySafeCast(opts.dtype,options.dtype)){
339
+
thrownewTypeError(format('invalid option. First argument cannot be safely cast to the specified data type. Input data type: %s. Option: `%s`.',String(opts.dtype),String(options.dtype)));
@@ -269,6 +270,38 @@ tape( 'the function throws an error if provided an invalid `dtype` option', func
269
270
}
270
271
});
271
272
273
+
tape('the function throws an error if provided a first argument which cannot be safely cast to a specified `dtype` option',functiontest(t){
274
+
varvalues;
275
+
varx;
276
+
vari;
277
+
278
+
x=empty([2,2],{
279
+
'dtype': 'bool'
280
+
});
281
+
282
+
values=[
283
+
'float64',
284
+
'complex128',
285
+
'float32',
286
+
'complex64',
287
+
'int32'
288
+
];
289
+
290
+
for(i=0;i<values.length;i++){
291
+
t.throws(badValue(values[i]),TypeError,'throws an error when provided '+values[i]);
292
+
}
293
+
t.end();
294
+
295
+
functionbadValue(value){
296
+
returnfunctionbadValue(){
297
+
varopts={
298
+
'dtype': value
299
+
};
300
+
flattenFrom(x,0,opts);
301
+
};
302
+
}
303
+
});
304
+
272
305
tape('by default, the function flattens all dimensions of a provided input ndarray starting from a specified dimension in lexicographic order (row-major, contiguous)',functiontest(t){
@@ -336,7 +337,9 @@ function flatten( x, options ) {
336
337
}
337
338
}
338
339
if(hasOwnProp(options,'dtype')){
339
-
// Delegate `dtype` validation to `emptyLike` during output array creation:
340
+
if(!isMostlySafeCast(opts.dtype,options.dtype)){
341
+
thrownewTypeError(format('invalid option. First argument cannot be safely cast to the specified data type. Input data type: %s. Option: `%s`.',String(opts.dtype),String(options.dtype)));
0 commit comments