Resolve the output ndarray data type from a list of input ndarray data types.
var outputDataType = require( '@stdlib/ndarray/base/output-dtype' );Resolves the output ndarray data type from a list of input ndarray data types according to a data type policy.
var dt = outputDataType( [ 'int32', 'uint32' ], 'floating_point' );
// returns 'float64'The function supports the following parameters:
- dtypes: list of input ndarray data types.
- policy: output data type policy.
If policy is a data type, the function always returns the policy value (i.e., the second argument).
var dt = outputDataType( [ 'float32', 'float32' ], 'float64' );
// returns 'float64'
dt = outputDataType( [ 'int32', 'complex128' ], 'float64' );
// returns 'float64'
// ...-
When provided more than data type, the function always applies type promotion to the provided data types, except for the following data type policies:
defaultdefault_indexsame<dtype>
var naryFunction = require( '@stdlib/utils/nary-function' );
var unzip = require( '@stdlib/utils/unzip' );
var cartesianProduct = require( '@stdlib/array/base/cartesian-product' );
var dtypes = require( '@stdlib/ndarray/dtypes' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var outputDataType = require( '@stdlib/ndarray/base/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',
'promoted'
];
// Generate data type pairs:
var pairs = cartesianProduct( dt, dt );
// Generate argument pairs:
var args = cartesianProduct( pairs, policies );
// Unzip the argument pair array:
args = unzip( args );
// Resolve output data types:
logEachMap( 'dtypes: (%15s). policy: %-24s. output dtype: %s.', args[ 0 ], args[ 1 ], naryFunction( outputDataType, 2 ) );