<commit_before>'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/math/base/random/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/math/base/random/discrete-uniform' );
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var shape2strides = require( '@stdlib/types/ndarray/base/shape2strides' );
var strides2offset = require( '@stdlib/types/ndarray/base/strides2offset' );
var pkg = require( './../package.json' ).name;
var sub2ind = require( './../lib' );


// MAIN //

bench( pkg+':mode=throw', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

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

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*10.0 );
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'throw' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=wrap', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

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

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*100.0 ) - 50.0;
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'wrap' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=clamp', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

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

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*20.0 ) - 5.0;
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'clamp' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});<commit_msg>Add benchmarks when offset is `0`<commit_after>'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/math/base/random/randu' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/math/base/random/discrete-uniform' );
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
var shape2strides = require( '@stdlib/types/ndarray/base/shape2strides' );
var strides2offset = require( '@stdlib/types/ndarray/base/strides2offset' );
var pkg = require( './../package.json' ).name;
var sub2ind = require( './../lib' );


// MAIN //

bench( pkg+':mode=throw', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

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

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*10.0 );
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'throw' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=throw,offset=0', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

	shape = [ 10, 10, 10 ];
	strides = shape2strides( shape, 'row-major' );
	offset = 0;

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*10.0 );
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'throw' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=wrap', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

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

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*100.0 ) - 50.0;
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'wrap' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=wrap,offset=0', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

	shape = [ 10, 10, 10 ];
	strides = shape2strides( shape, 'row-major' );
	offset = 0;

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*100.0 ) - 50.0;
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'wrap' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=clamp', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

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

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*20.0 ) - 5.0;
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'clamp' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':mode=clamp,offset=0', function benchmark( b ) {
	var strides;
	var offset;
	var shape;
	var out;
	var s0;
	var s1;
	var s2;
	var i;

	shape = [ 10, 10, 10 ];
	strides = shape2strides( shape, 'row-major' );
	offset = 0;

	s0 = discreteUniform( 0, shape[ 0 ]-1 );
	s1 = discreteUniform( 0, shape[ 1 ]-1 );
	s2 = discreteUniform( 0, shape[ 2 ]-1 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		s2 = floor( randu()*20.0 ) - 5.0;
		out = sub2ind( shape, strides, offset, s0, s1, s2, 'clamp' );
		if ( out !== out ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( !isInteger( out ) ) {
		b.fail( 'should return an integer' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});
{'fraction_non_alphanumeric': 0.19302114411726554, 'fraction_numerical': 0.04150992346607861, 'mean_word_length': 3.1185897435897436, 'pattern_counts': {'":': 0, '<': 12, '<?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': '535473', 'n_tokens_mistral': 3460, 'n_tokens_neox': 3136, 'n_words': 908}