JSPM

@stdlib/ndarray-base-assert-is-same-kind-data-type-cast

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 81
  • Score
    100M100P100Q113796F
  • License Apache-2.0

Determine if an ndarray data type can be safely cast to, or is of the same kind as, another ndarray data type.

Package Exports

  • @stdlib/ndarray-base-assert-is-same-kind-data-type-cast

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@stdlib/ndarray-base-assert-is-same-kind-data-type-cast) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

isSameKindCast

NPM version Build Status Coverage Status dependencies

Determine whether an ndarray data type can be safely cast to, or is of the same "kind" as, another ndarray data type.

Installation

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

Usage

var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-data-type-cast' );

isSameKindCast( from, to )

Returns a boolean indicating whether an ndarray data type can be safely cast to, or is of the same "kind" as, another ndarray data type (e.g., casting between signed integers or between floats).

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

bool = isSameKindCast( 'uint16', 'int16' );
// returns false

Examples

var dtypes = require( '@stdlib/ndarray-dtypes' );
var isSameKindCast = require( '@stdlib/ndarray-base-assert-is-same-kind-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 cast to another data type...
for ( i = 0; i < DTYPES.length; i++ ) {
    dt = DTYPES[ i ];
    for ( j = 0; j < DTYPES.length; j++ ) {
        bool = isSameKindCast( dt, DTYPES[ j ] );
        console.log( '%s => %s. Allowed cast? %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.


License

See LICENSE.

Copyright © 2016-2021. The Stdlib Authors.