@stdlib/ndarray-base-binary-input-casting-dtype
v0.1.1
Published
Resolve the casting data type for an input ndarray provided to a binary function.
Readme
binaryInputCastingDataType
Resolve the casting data type for an input ndarray provided to a binary function.
Installation
npm install @stdlib/ndarray-base-binary-input-casting-dtypeUsage
var binaryInputCastingDataType = require( '@stdlib/ndarray-base-binary-input-casting-dtype' );binaryInputCastingDataType( idtype1, idtype2, odtype, policy )
Resolves the casting data type for an input ndarray provided to a binary function according to a data type policy.
var dt = binaryInputCastingDataType( 'int32', 'int32', 'float64', 'promoted' );
// returns 'float64'The function supports the following parameters:
- idtype1: input ndarray data type.
- idtype2: additional input ndarray data type.
- odtype: output ndarray data type.
- policy: input ndarray casting policy.
If policy is a data type, the function always returns the policy value (i.e., the fourth argument).
var dt = binaryInputCastingDataType( 'float32', 'float32', 'float64', 'complex128' );
// returns 'complex128'
dt = binaryInputCastingDataType( 'int32', 'float64', 'float64', 'complex128' );
// returns 'complex128'
// ...Examples
var naryFunction = require( '@stdlib/utils-nary-function' );
var unzip = require( '@stdlib/utils-unzip' );
var nCartesianProduct = require( '@stdlib/array-base-n-cartesian-product' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var inputCastingDataType = require( '@stdlib/ndarray-base-binary-input-casting-dtype' );
var idt1 = [
'float32',
'float64'
];
var idt2 = [
'int8',
'uint8',
'uint16',
'uint32'
];
var odt = [
'float32',
'float64',
'complex64',
'complex128'
];
// Define a list of casting policies:
var policies = [
'promoted',
'accumulation',
'output'
];
// Generate dtype-policy argument groups:
var args = nCartesianProduct( idt1, idt2, odt, policies );
// Unzip the argument arrays:
args = unzip( args );
// Resolve casting data types:
logEachMap( 'dtypes: (%10s, %10s, %10s). policy: %20s. result: %10s.', args[ 0 ], args[ 1 ], args[ 2 ], args[ 3 ], naryFunction( inputCastingDataType, 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.
