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
function resolve( idtype1, idtype2, odtype, policy ) {
340
329
var dt;
341
330
if ( policy === 'none' ) {
342
-
if (idtype1 !== idtype2) {
343
-
throw new Error( format( 'Inputs must match under "none" policy. Got %s and %s.', idtype1, idtype2 ) );
344
-
}
331
+
// When the policy is 'none', casting behavior is implementation-defined, so we just return the input ndarray data type as is...
345
332
return idtype1;
346
333
}
347
334
if ( policy === 'output' ) {
348
335
return odtype;
349
336
}
350
337
if ( policy === 'promoted' ) {
351
-
dt = promotionRules( idtype1, idtype2 );
352
-
if ( dt === -1 ) {
353
-
throw new Error( format( 'invalid operation. Unable to promote the first input and second input data types. First input data type: %s. Second input data type: %s.', idtype1, idtype2 ) );
354
-
}
355
-
dt = promotionRules( dt, odtype );
356
-
if ( dt === -1 ) {
357
-
throw new Error( format( 'invalid operation. Unable to promote the input and output data types. Input data type: %s. Output data type: %s.', dt, odtype ) );
throw new Error( format( 'invalid operation. Unable to promote the input and output data types. Input data types: [%s]. Output data type: %s.', join( [ idtype1, idtype2 ], ', ' ), odtype ) );
358
341
}
359
342
return dt;
360
343
}
361
344
if ( policy === 'accumulation' ) {
362
-
if ( isFloatingPointDataType( idtype1 ) || isFloatingPointDataType( idtype2 ) || idtype1 === 'generic' || idtype2 === 'generic' ) { // NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited
363
-
return promotionRules(idtype1, idtype2);
345
+
// When the accumulation policy is 'accumulation', we consider the input ndarray data type in isolation, irrespective of the output data type or the data types of additional input ndarrays...
346
+
347
+
// If an input data type is floating-point, allow accumulation in that data type as overflow/underflow is handled naturally as a built-in feature of that data type...
348
+
if ( isFloatingPointDataType( idtype1 ) || idtype1 === 'generic' ) { // NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited
349
+
return idtype1;
364
350
}
365
-
// Unless the input data type value range is larger than the default un/signed integer data type, accumulate in the default un/signed integer data type, as accumulating in smaller range integer data types (e.g., `int8`) are at high risk for overflow, especially for ndarrays containing many elements...
366
-
if ( isUnsignedIntegerDataType( idtype1 ) <spanclass="branch-0 cbranch-no" title="branch not covered" >&& isUnsignedIntegerDataType( idtype2 ) </span>) <spanclass="branch-0 cbranch-no" title="branch not covered" >{ // eslint-disable-line max-len</span>
367
-
<spanclass="cstat-no" title="statement not covered" > return promotionRules(</span>
368
-
<spanclass="cstat-no" title="statement not covered" > promotionRules(idtype1, idtype2), DEFAULT_UNSIGNED_INTEGER_DTYPE</span>
369
-
<spanclass="cstat-no" title="statement not covered" > );</span>
351
+
// Unless an input data type value range is larger than the default un/signed integer data type, accumulate in the default un/signed integer data type, as accumulating in smaller range integer data types (e.g., `int8`) are at high risk for overflow, especially for ndarrays containing many elements...
352
+
if ( isUnsignedIntegerDataType( idtype1 ) ) <spanclass="branch-0 cbranch-no" title="branch not covered" >{</span>
<spanclass="cstat-no" title="statement not covered" ><spanclass="branch-0 cbranch-no" title="branch not covered" > // For all other input data types, accumulate in the default real-valued floating-point data type...</span></span>
377
359
<spanclass="cstat-no" title="statement not covered" > return DEFAULT_REAL_FLOATING_POINT_DTYPE;</span>
0 commit comments