@stdlib/ndarray-base-unary-input-casting-dtype
v0.1.1
Published
Resolve the input ndarray casting data type for a unary function.
Readme
unaryInputCastingDataType
Resolve the input ndarray casting data type for a unary function.
Installation
npm install @stdlib/ndarray-base-unary-input-casting-dtypeUsage
var unaryInputCastingDataType = require( '@stdlib/ndarray-base-unary-input-casting-dtype' );unaryInputCastingDataType( idtype, odtype, policy )
Resolves the input ndarray casting data type for a unary function according to a data type policy.
var dt = unaryInputCastingDataType( 'int32', 'float64', 'promoted' );
// returns 'float64'The function supports the following parameters:
- idtype: 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 third argument).
var dt = unaryInputCastingDataType( 'float32', 'float64', 'complex128' );
// returns 'complex128'
dt = unaryInputCastingDataType( 'int32', '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 dtypes = require( '@stdlib/ndarray-dtypes' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var inputCastingDataType = require( '@stdlib/ndarray-base-unary-input-casting-dtype' );
// Get the list of real-valued data types:
var dt = dtypes( 'real' );
// Define a list of casting policies:
var policies = [
'none',
'promoted',
'accumulation',
'output'
];
// Generate dtype-policy argument groups:
var args = nCartesianProduct( dt, dt, policies );
// Unzip the argument arrays:
args = unzip( args );
// Resolve casting data types:
logEachMap( 'dtypes: (%10s, %10s). policy: %20s. result: %10s.', args[ 0 ], args[ 1 ], args[ 2 ], naryFunction( inputCastingDataType, 3 ) );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.
