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 = new Array( 3 );
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 );
}