Determine if a buffer length is compatible with an array shape.
npm install @stdlib/ndarray-base-assert-is-buffer-length-compatible-shape
Alternatively,
- To load the package in a website via a
script
tag without installation and bundlers, use the ES Module available on theesm
branch. - If you are using Deno, visit the
deno
branch. - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umd
branch.
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
var isBufferLengthCompatibleShape = require( '@stdlib/ndarray-base-assert-is-buffer-length-compatible-shape' );
Returns a boolean
indicating if a buffer length
is compatible with a provided shape
array.
var shape = [ 2, 2 ];
var bool = isBufferLengthCompatibleShape( 10, shape );
// returns true
bool = isBufferLengthCompatibleShape( 3, shape );
// returns false
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
var isBufferLengthCompatibleShape = require( '@stdlib/ndarray-base-assert-is-buffer-length-compatible-shape' );
var shape;
var bool;
var len;
var i;
len = 500; // buffer length
shape = [ 0, 0, 0 ];
for ( i = 0; i < 100; i++ ) {
// Generate a random array shape:
shape[ 0 ] = discreteUniform( 1, 10 );
shape[ 1 ] = discreteUniform( 1, 10 );
shape[ 2 ] = discreteUniform( 1, 10 );
// Determine if the buffer length is compatible with the shape array:
bool = isBufferLengthCompatibleShape( len, shape );
console.log( 'Buffer length: %d. Shape: %s. Compatible: %s.', len, shape.join( 'x' ), bool );
}
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.
See LICENSE.
Copyright © 2016-2023. The Stdlib Authors.