Skip to content

Latest commit

 

History

History

unary-input-casting-dtype

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

unaryInputCastingDataType

Resolve the input ndarray casting data type for a unary function.

Usage

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