Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

outputDataType

Resolve the output ndarray data type from a list of input ndarray data types.

Usage

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:

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

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 ) );