@stdlib/ndarray-base-binary-output-dtype
v0.1.1
Published
Resolve the output ndarray data type for a binary function.
Readme
binaryOutputDataType
Resolve the output ndarray data type for a binary function.
Installation
npm install @stdlib/ndarray-base-binary-output-dtypeUsage
var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );binaryOutputDataType( xdtype, ydtype, policy )
Resolves the output ndarray data type for a binary function according to a data type policy.
var dt = binaryOutputDataType( 'int32', 'float32', 'floating_point' );
var s = String( dt );
// returns 'float64'The function supports the following parameters:
- xdtype: first input ndarray data type.
- ydtype: second input ndarray data type.
- policy: output data type policy.
If policy is a data type, the function always returns the policy value (i.e., the third argument).
var dt = binaryOutputDataType( 'float32', 'float32', 'float64' );
var s = String( dt );
// returns 'float64'
dt = binaryOutputDataType( 'int32', 'int8', 'float64' );
s = String( dt );
// returns 'float64'
// ...Notes
The function always applies type promotion to the provided data types, except for the following data type policies:
defaultdefault_indexsame<dtype>
Examples
var naryFunction = require( '@stdlib/utils-nary-function' );
var unzip = require( '@stdlib/utils-unzip' );
var nCartesianProduct = require( '@stdlib/array-base-n-cartesian-product' );
var dtypes = require( '@stdlib/ndarray-dtypes' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var binaryOutputDataType = require( '@stdlib/ndarray-base-binary-output-dtype' );
// Get the list of real-valued data types:
var dt = dtypes( 'real' );
// Define a list of output data type policies:
var policies = [
'default',
'real',
'floating_point',
'complex_floating_point'
];
// Generate dtype-policy Cartesian products:
var args = nCartesianProduct( dt, dt, policies );
// Unzip the argument pair array:
args = unzip( args );
// Resolve output data types:
logEachMap( 'dtypes: (%7s, %7s). policy: %-24s. output dtype: %s.', args[ 0 ], args[ 1 ], args[ 2 ], naryFunction( binaryOutputDataType, 3 ) );Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
