@stdlib/ndarray-base-output-dtype
v0.1.1
Published
Resolve the output data type from a list of input ndarray data types.
Readme
outputDataType
Resolve the output ndarray data type from a list of input ndarray data types.
Installation
npm install @stdlib/ndarray-base-output-dtypeUsage
var outputDataType = require( '@stdlib/ndarray-base-output-dtype' );outputDataType( dtypes, policy )
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'
// ...Notes
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>
Examples
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 ) );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.
