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
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/README.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,11 +18,9 @@ limitations under the License.
18
18
19
19
-->
20
20
21
-
<!-- eslint-disable id-length -->
22
-
23
21
# binaryInputCastingDataType
24
22
25
-
> Resolve the input ndarray casting [data type][@stdlib/ndarray/dtypes] for a binary function.
23
+
> Resolve the casting [data type][@stdlib/ndarray/dtypes] for an input ndarray provided to a binary function.
26
24
27
25
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
28
26
@@ -46,7 +44,7 @@ var binaryInputCastingDataType = require( '@stdlib/ndarray/base/binary-input-cas
Resolves the input ndarray casting [data type][@stdlib/ndarray/dtypes] for a binary function according to a [data type policy][@stdlib/ndarray/input-casting-policies].
47
+
Resolves the casting [data type][@stdlib/ndarray/dtypes] for an input ndarray provided to a binary function according to a [data type policy][@stdlib/ndarray/input-casting-policies].
@@ -41,10 +42,10 @@ var DEFAULT_REAL_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.real_floating_poin
41
42
// MAIN //
42
43
43
44
/**
44
-
* Resolves the input ndarray casting data type for a binary function.
45
+
* Resolves the casting data type for an input ndarray provided to a binary function.
45
46
*
46
-
* @param {string} idtype1 - first input ndarray data type
47
-
* @param {string} idtype2 - second input ndarray data type
47
+
* @param {string} idtype1 - input ndarray data type
48
+
* @param {string} idtype2 - additional input ndarray data type
48
49
* @param {string} odtype - output ndarray data type
49
50
* @param {string} policy - input ndarray data type casting policy
50
51
* @throws {TypeError} fourth argument must be a recognized data type policy
@@ -58,39 +59,30 @@ var DEFAULT_REAL_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.real_floating_poin
58
59
functionresolve(idtype1,idtype2,odtype,policy){
59
60
vardt;
60
61
if(policy==='none'){
61
-
if(idtype1!==idtype2){
62
-
thrownewError(format('Inputs must match under "none" policy. Got %s and %s.',idtype1,idtype2));
63
-
}
62
+
// When the policy is 'none', casting behavior is implementation-defined, so we just return the input ndarray data type as is...
64
63
returnidtype1;
65
64
}
66
65
if(policy==='output'){
67
66
returnodtype;
68
67
}
69
68
if(policy==='promoted'){
70
-
dt=promotionRules(idtype1,idtype2);
71
-
if(dt===-1){
72
-
thrownewError(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));
73
-
}
74
-
dt=promotionRules(dt,odtype);
75
-
if(dt===-1){
76
-
thrownewError(format('invalid operation. Unable to promote the input and output data types. Input data type: %s. Output data type: %s.',dt,odtype));
69
+
dt=promoteDataTypes([idtype1,idtype2,odtype]);
70
+
if(dt===null){
71
+
thrownewError(format('invalid operation. Unable to promote the input and output data types. Input data types: [%s]. Output data type: %s.',join([idtype1,idtype2],', '),odtype));
77
72
}
78
73
returndt;
79
74
}
80
75
if(policy==='accumulation'){
81
-
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
82
-
returnpromotionRules(idtype1,idtype2);
76
+
// 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...
77
+
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
78
+
returnidtype1;
83
79
}
84
-
// 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...
// 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...
0 commit comments