Skip to content

Latest commit

 

History

History

shape2strides

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

shape2strides

Generate a stride array from an array shape.

Usage

var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );

shape2strides( shape, order )

Generates a stride array from an array shape.

var strides = shape2strides( [ 3, 2 ], 'row-major' );
// returns [ 2, 1 ]

The order parameter specifies whether an array is row-major (C-style) or column-major (Fortran-style).

var strides = shape2strides( [ 3, 2 ], 'column-major' );
// returns [ 1, 3 ]

shape2strides.assign( shape, order, out )

Generates a stride array from an array shape and assigns results to a provided output array.

var shape = [ 3, 2 ];
var strides = [ 0, 0 ];

var out = shape2strides.assign( shape, 'row-major', strides );
// returns [ 2, 1 ]

var bool = ( strides === out );
// returns true

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );

var strides;
var shape;
var i;

shape = new Array( 3 );
for ( i = 0; i < 100; i++ ) {
    shape[ 0 ] = discreteUniform( 1, 10 );
    shape[ 1 ] = discreteUniform( 1, 10 );
    shape[ 2 ] = discreteUniform( 1, 10 );
    strides = shape2strides( shape, 'row-major' );
    console.log( 'shape: %s. strides: %s.', shape.join( 'x' ), strides.join( ', ' ) );
}