@stdlib/ndarray-base-ternary-output-dtype
v0.1.1
Published
Resolve the output ndarray data type for a ternary function.
Readme
ternaryOutputDataType
Resolve the output ndarray data type for a ternary function.
Installation
npm install @stdlib/ndarray-base-ternary-output-dtypeUsage
var ternaryOutputDataType = require( '@stdlib/ndarray-base-ternary-output-dtype' );ternaryOutputDataType( xdtype, ydtype, zdtype, policy )
Resolves the output ndarray data type for a ternary function according to a data type policy.
var dt = ternaryOutputDataType( 'int32', 'float32', '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.
- zdtype: third 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 = ternaryOutputDataType( 'float32', 'float32', 'float32', 'float64' );
var s = String( dt );
// returns 'float64'
dt = ternaryOutputDataType( 'int32', 'int8', 'int32', '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 ternaryOutputDataType = require( '@stdlib/ndarray-base-ternary-output-dtype' );
// Get the list of real-valued floating-point data types:
var dt = dtypes( 'real_floating_point' );
// 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, dt, policies );
// Unzip the argument pair array:
args = unzip( args );
// Resolve output data types:
logEachMap( 'dtypes: (%7s, %7s, %7s). policy: %-24s. output dtype: %s.', args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], naryFunction( ternaryOutputDataType, 4 ) );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.
