time-to-botec/js/node_modules/@stdlib/ndarray/base/assert/is-buffer-length-compatible-shape/README.md
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

3.0 KiB

isBufferLengthCompatibleShape

Determine if a buffer length is compatible with an array shape.

Usage

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 false

Examples

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