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: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -379,6 +379,8 @@ A total of 15 issues were closed in this release:
379
379
380
380
<details>
381
381
382
+
-[`ad9966a`](https://github.com/stdlib-js/stdlib/commit/ad9966a5d6c560c6a4b2c785f2caafdd472b8399) - **refactor:** reuse existing logic by building on `ndarray/base/unary-output-dtype`_(by Athan Reines)_
* Wraps a data type validation function to also check for a "generic" data type.
160
-
*
161
-
* @private
162
-
* @param {Function} fcn - validation function
163
-
* @returns {Function} wrapped validation function
164
-
*/
165
-
functionwrap(fcn){
166
-
returnwrapper;
167
-
168
-
/**
169
-
* Tests whether a provided data type is either "generic" or satisfies a data type validation function.
170
-
*
171
-
* @private
172
-
* @param {*} value - input value
173
-
* @returns {boolean} boolean indicating whether a provided value passes a test
174
-
*/
175
-
functionwrapper(value){
176
-
return(value==='generic')||fcn(value);
177
-
}
178
-
}
179
-
180
-
181
29
// MAIN //
182
30
183
31
/**
@@ -196,14 +44,11 @@ function wrap( fcn ) {
196
44
*/
197
45
functionresolve(xdtype,ydtype,policy){
198
46
vardt;
199
-
varp;
200
-
if(policy==='default'){
201
-
// When the policy is "default", the output data type should always be the default data type without consideration for the input data types:
202
-
returnDEFAULT_DTYPE;
203
-
}
204
-
if(policy==='default_index'){
205
-
// When the policy is "default_index", the output data type should always be the default index data type without consideration for the input data types:
206
-
returnDEFAULT_INDEX_DTYPE;
47
+
48
+
// Check for a policy mandating an explicit data type...
49
+
if(isDataType(policy)){
50
+
// When the policy is a specific data type, the output data type should always be the specified data type without consideration for the input data types:
51
+
returnpolicy;
207
52
}
208
53
if(policy==='same'){
209
54
// When the policy is "same", we require that all data types (both input and output) be the same...
// When the policy is a specific data type, the output data type should always be the specified data type without consideration for the input data types:
218
-
returnpolicy;
60
+
if(policy==='default'||policy==='default_index'){
61
+
returnunaryOutputDataType(xdtype,policy);// note: these policies are independent of the input data type, so it doesn't matter what data type we provide as the first argument
219
62
}
220
-
// From this point forward, we always apply type promotion rules...
63
+
// For all other policies, we always apply type promotion rules...
221
64
dt=promotionRules(xdtype,ydtype);
222
65
if(dt===null||dt===-1){
223
66
thrownewError(format('invalid arguments. Unable to apply type promotion rules when resolving a data type to which the input data types can be safely cast. Data types: [%s, %s].',xdtype,ydtype));
224
67
}
225
-
if(policy==='promoted'){
226
-
// If the policy is "promoted", we're done...
227
-
returndt;
228
-
}
229
-
if(policy==='accumulation'){
230
-
// If the promoted 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...
231
-
if(isFloatingPointDataType(dt)||dt==='generic'){// NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited
232
-
returndt;
233
-
}
234
-
// Unless the promoted 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 small range integer data types (e.g., `int8`) are at high risk for overflow, especially for ndarrays containing many elements...
0 commit comments