Skip to content

Commit b51882d

Browse files
committed
refactor: use generalized utility
--- 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: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent e5ddc80 commit b51882d

File tree

1 file changed

+4
-36
lines changed
  • lib/node_modules/@stdlib/ndarray/base/binary-output-dtype/lib

1 file changed

+4
-36
lines changed

lib/node_modules/@stdlib/ndarray/base/binary-output-dtype/lib/main.js

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
// MODULES //
2222

23-
var unaryOutputDataType = require( '@stdlib/ndarray/base/unary-output-dtype' );
24-
var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
25-
var promotionRules = require( '@stdlib/ndarray/promotion-rules' );
26-
var format = require( '@stdlib/string/format' );
23+
var outputDataType = require( '@stdlib/ndarray/base/output-dtype' );
2724

2825

2926
// MAIN //
@@ -34,45 +31,16 @@ var format = require( '@stdlib/string/format' );
3431
* @param {string} xdtype - first input ndarray data type
3532
* @param {string} ydtype - second input ndarray data type
3633
* @param {string} policy - output ndarray data type policy
37-
* @throws {TypeError} second argument must be a recognized data type policy
38-
* @throws {Error} unexpected error
34+
* @throws {TypeError} third argument must be a recognized data type policy
35+
* @throws {Error} must provide data types amenable to type promotion
3936
* @returns {string} output ndarray data type
4037
*
4138
* @example
4239
* var dt = resolve( 'float64', 'float32', 'complex_floating_point' );
4340
* // returns <string>
4441
*/
4542
function resolve( xdtype, ydtype, policy ) {
46-
var dt;
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-
return policy;
52-
}
53-
if ( policy === 'same' ) {
54-
// When the policy is "same", we require that all data types (both input and output) be the same...
55-
if ( xdtype !== ydtype ) {
56-
throw new Error( format( 'invalid arguments. Unable to resolve an output data type. The output data type policy is "same" and yet the input data types are not equal. Data types: [%s, %s].', xdtype, ydtype ) );
57-
}
58-
return xdtype;
59-
}
60-
if ( policy === 'default' || policy === 'default_index' ) {
61-
return unaryOutputDataType( 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
62-
}
63-
// For all other policies, we always apply type promotion rules...
64-
dt = promotionRules( xdtype, ydtype );
65-
if ( dt === null || dt === -1 ) {
66-
throw new Error( 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 ) );
67-
}
68-
// Resolve the output data type by treating this scenario as equivalent to passing the promoted data type as an input to a unary function...
69-
try {
70-
dt = unaryOutputDataType( dt, policy );
71-
} catch ( err ) { // eslint-disable-line no-unused-vars
72-
// We should only get here if the policy is invalid...
73-
throw new TypeError( format( 'invalid argument. Third argument must be a supported data type policy. Value: `%s`.', policy ) );
74-
}
75-
return dt;
43+
return outputDataType( [ xdtype, ydtype ], policy );
7644
}
7745

7846

0 commit comments

Comments
 (0)