0.2.2 • Published 1 year ago
@stdlib/ndarray-base-assert-is-buffer-length-compatible-shape v0.2.2
isBufferLengthCompatibleShape
Determine if a buffer length is compatible with an array shape.
Installation
npm install @stdlib/ndarray-base-assert-is-buffer-length-compatible-shapeUsage
var isBufferLengthCompatibleShape = require( '@stdlib/ndarray-base-assert-is-buffer-length-compatible-shape' );isBufferLengthCompatibleShape( len, 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 falseExamples
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 );
}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-2024. The Stdlib Authors.