@stdlib/ndarray-base-assert-is-safe-data-type-cast

Determine if an ndarray data type can be safely cast to another ndarray data type.

Usage no npm install needed!

<script type="module">
  import stdlibNdarrayBaseAssertIsSafeDataTypeCast from 'https://cdn.skypack.dev/@stdlib/ndarray-base-assert-is-safe-data-type-cast';
</script>

README

isSafeCast

NPM version Build Status Coverage Status

Determine whether an ndarray data type can be safely cast to another ndarray data type.

Installation

npm install @stdlib/ndarray-base-assert-is-safe-data-type-cast

Usage

var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );

isSafeCast( from, to )

Returns a boolean indicating whether an ndarray data type can be safely cast to another ndarray data type.

var bool = isSafeCast( 'float32', 'float64' );
// returns true

bool = isSafeCast( 'float64', 'int32' );
// returns false

Examples

var dtypes = require( '@stdlib/ndarray-dtypes' );
var isSafeCast = require( '@stdlib/ndarray-base-assert-is-safe-data-type-cast' );

var DTYPES;
var bool;
var dt;
var i;
var j;

// Get a list of supported ndarray data types:
DTYPES = dtypes();

// For each data type, determine whether one can safely cast to another data type...
for ( i = 0; i < DTYPES.length; i++ ) {
    dt = DTYPES[ i ];
    for ( j = 0; j < DTYPES.length; j++ ) {
        bool = isSafeCast( dt, DTYPES[ j ] );
        console.log( '%s => %s. Safe? %s.', dt, DTYPES[ j ], bool );
    }
}

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

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2022. The Stdlib Authors.