<commit_before>'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/math/base/random/randu' );
var isArray = require( '@stdlib/assert/is-array' );
var shape2strides = require( '@stdlib/types/ndarray/base/shape2strides' );
var strides2offset = require( '@stdlib/types/ndarray/base/strides2offset' );
var numel = require( '@stdlib/types/ndarray/base/numel' );
var pkg = require( './../package.json' ).name;
var ndarray2array = require( './../lib' );


// MAIN //

bench( pkg+':order=row-major', function benchmark( b ) {
	var strides;
	var buffer;
	var offset;
	var order;
	var shape;
	var len;
	var out;
	var i;

	shape = [ 10, 10, 10 ];
	order = 'row-major';
	len = numel( shape );
	strides = shape2strides( shape, order );
	offset = strides2offset( shape, strides );

	buffer = new Array( len );
	for ( i = 0; i < len; i++ ) {
		buffer[ i ] = i;
	}

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		strides[ 1 ] *= ( randu() < 0.5 ) ? -1 : 1;
		out = ndarray2array( buffer, shape, strides, offset, order );
		if ( out.length !== shape[ 0 ] ) {
			b.fail( 'should have expected length' );
		}
	}
	b.toc();
	if (
		!isArray( out ) ||
		!isArray( out[ 0 ] ) ||
		!isArray( out[ 0 ][ 0 ] )
	) {
		b.fail( 'should return an array of arrays' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':order=column-major', function benchmark( b ) {
	var strides;
	var buffer;
	var offset;
	var order;
	var shape;
	var len;
	var out;
	var i;

	shape = [ 10, 10, 10 ];
	order = 'column-major';
	len = numel( shape );
	strides = shape2strides( shape, order );
	offset = strides2offset( shape, strides );

	buffer = new Array( len );
	for ( i = 0; i < len; i++ ) {
		buffer[ i ] = i;
	}

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		strides[ 1 ] *= ( randu() < 0.5 ) ? -1 : 1;
		out = ndarray2array( buffer, shape, strides, offset, order );
		if ( out.length !== shape[ 0 ] ) {
			b.fail( 'should have expected length' );
		}
	}
	b.toc();
	if (
		!isArray( out ) ||
		!isArray( out[ 0 ] ) ||
		!isArray( out[ 0 ][ 0 ] )
	) {
		b.fail( 'should return an array of arrays' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});<commit_msg>Use utility to test for an array of arrays<commit_after>'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/math/base/random/randu' );
var isArrayArray = require( '@stdlib/assert/is-array-array' );
var shape2strides = require( '@stdlib/types/ndarray/base/shape2strides' );
var strides2offset = require( '@stdlib/types/ndarray/base/strides2offset' );
var numel = require( '@stdlib/types/ndarray/base/numel' );
var pkg = require( './../package.json' ).name;
var ndarray2array = require( './../lib' );


// MAIN //

bench( pkg+':order=row-major', function benchmark( b ) {
	var strides;
	var buffer;
	var offset;
	var order;
	var shape;
	var len;
	var out;
	var i;

	shape = [ 10, 10, 10 ];
	order = 'row-major';
	len = numel( shape );
	strides = shape2strides( shape, order );
	offset = strides2offset( shape, strides );

	buffer = new Array( len );
	for ( i = 0; i < len; i++ ) {
		buffer[ i ] = i;
	}

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		strides[ 1 ] *= ( randu() < 0.5 ) ? -1 : 1;
		out = ndarray2array( buffer, shape, strides, offset, order );
		if ( out.length !== shape[ 0 ] ) {
			b.fail( 'should have expected length' );
		}
	}
	b.toc();
	if (
		!isArrayArray( out ) ||
		!isArrayArray( out[ 0 ] )
	) {
		b.fail( 'should return an array of arrays' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':order=column-major', function benchmark( b ) {
	var strides;
	var buffer;
	var offset;
	var order;
	var shape;
	var len;
	var out;
	var i;

	shape = [ 10, 10, 10 ];
	order = 'column-major';
	len = numel( shape );
	strides = shape2strides( shape, order );
	offset = strides2offset( shape, strides );

	buffer = new Array( len );
	for ( i = 0; i < len; i++ ) {
		buffer[ i ] = i;
	}

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		strides[ 1 ] *= ( randu() < 0.5 ) ? -1 : 1;
		out = ndarray2array( buffer, shape, strides, offset, order );
		if ( out.length !== shape[ 0 ] ) {
			b.fail( 'should have expected length' );
		}
	}
	b.toc();
	if (
		!isArrayArray( out ) ||
		!isArrayArray( out[ 0 ] )
	) {
		b.fail( 'should return an array of arrays' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});
{'fraction_non_alphanumeric': 0.1889853747714808, 'fraction_numerical': 0.019652650822669104, 'mean_word_length': 3.0527777777777776, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '421044', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1683, 'n_words': 482}