<commit_before>'use strict';

// MODULES //

var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; // eslint-disable-line no-unused-vars


// MAIN //

/**
* Returns a getter function for arrays having a specified number of dimensions.
*
* @private
* @param {PositiveInteger} ndims - array dimensions
* @returns {Function} getter
*
* @example
* var f = get( 3 );
* // returns <Function>
*/
function get( ndims ) {
	var n = ndims - 1;
	var f;
	var i;

	// Code generation. Start with function definition...
	f = '(function iife() {return function get(';

	/*
	* Create the index input arguments...
	* > function get( i0, i1, ...) {
	*/
	for ( i = 0; i < ndims; i++ ) {
		f += 'i' + i;
		if ( i < n ) {
			f += ',';
		}
	}
	f += '){';

	// Create the function body...

	/*
	* Type check each index.
	* > if ( !isInteger( i0 ) ) { throw new TypeError( ... ) }
	*/
	for ( i = 0; i < ndims; i++ ) {
		f += 'if (!isInteger(i'+i+')) {throw new TypeError(\'invalid input argument. Indices must be integer valued. Argument: '+i+'. Value: `\'+i'+i+'+\'`.\');}';
	}
	/*
	* Index into the array according to the offset and strides...
	* > return data[offset+strides[0]*i0+strides[1]*i1+...];
	*/
	f += 'return this._buffer[this._offset+';
	for ( i = 0; i < ndims; i++ ) {
		f += 'this._strides['+i+']*i'+i;
		if ( i < n ) {
			f += '+';
		}
	}
	f += '];';

	// Close the function:
	f += '}';

	// Close the IIFE:
	f += '})()';

	// Add a source directive for debugging:
	f += '//# sourceURL=ndarray.ctor.get.js';

	// Create the function in the current scope to allow access to required modules:
	return eval( f ); // eslint-disable-line no-eval

	/*
	* e.g., returns
	*     function get( i0, i1, i2 ) {
	*         if ( !isInteger( i0 ) ) {
	*             throw new TypeError( 'invalid input argument. Indices must be integer valued. Argument: 0. Value: `'+i0+'`.' );
	*         }
	*         if ( !isInteger( i1 ) ) {
	*             throw new TypeError( 'invalid input argument. Indices must be integer valued. Argument: 1. Value: `'+i1+'`.' );
	*         }
	*         if ( !isInteger( i2 ) ) {
	*             throw new TypeError( 'invalid input argument. Indices must be integer valued. Argument: 2. Value: `'+i2+'`.' );
	*         }
	*         return this._buffer[ this._offset + this._strides[0]*i0 + this._strides[1]*i1 + this._strides[2]*i2 ];
	*     }
	*/
} // end FUNCTION get()


// EXPORTS //
<commit_msg>Add support for an index mode<commit_after>'use strict';

// MODULES //

var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; // eslint-disable-line no-unused-vars
var getIndex = require( './get_index.js' ); // eslint-disable-line no-unused-vars


// MAIN //

/**
* Returns a getter function for arrays having a specified number of dimensions.
*
* @private
* @param {PositiveInteger} ndims - array dimensions
* @returns {Function} getter
*
* @example
* var f = get( 3 );
* // returns <Function>
*/
function get( ndims ) {
	var n = ndims - 1;
	var f;
	var i;

	// Code generation. Start with function definition...
	f = '(function iife(){return function get(';

	/*
	* Create the index input arguments...
	* > function get( i0, i1, ...) {
	*/
	for ( i = 0; i < ndims; i++ ) {
		f += 'i' + i;
		if ( i < n ) {
			f += ',';
		}
	}
	f += '){';

	// Create the function body...

	/*
	* Type check each index.
	* > if ( !isInteger( i0 ) ) { throw new TypeError( ... ) }
	*/
	for ( i = 0; i < ndims; i++ ) {
		f += 'if(!isInteger(i'+i+')){throw new TypeError(\'invalid input argument. Indices must be integer valued. Argument: '+i+'. Value: `\'+i'+i+'+\'`.\');}';
	}
	/*
	* Resolve indices based on the index mode.
	* > i0 = getIndex( i0, shape[0], mode );
	*/
	for ( i = 0; i < ndims; i++ ) {
		f += 'i'+i+'=getIndex(i'+i+',this._shape['+i+'],this._mode);';
	}
	/*
	* Index into the array according to the offset and strides...
	* > return data[offset+strides[0]*i0+strides[1]*i1+...];
	*/
	f += 'return this._buffer[this._offset+';
	for ( i = 0; i < ndims; i++ ) {
		f += 'this._strides['+i+']*i'+i;
		if ( i < n ) {
			f += '+';
		}
	}
	f += '];';

	// Close the function:
	f += '}';

	// Close the IIFE:
	f += '})()';

	// Add a source directive for debugging:
	f += '//# sourceURL=ndarray.ctor.get.js';

	// Create the function in the current scope to allow access to required modules:
	return eval( f ); // eslint-disable-line no-eval

	/*
	* e.g., returns
	*     function get( i0, i1, i2 ) {
	*         if ( !isInteger( i0 ) ) {
	*             throw new TypeError( 'invalid input argument. Indices must be integer valued. Argument: 0. Value: `'+i0+'`.' );
	*         }
	*         if ( !isInteger( i1 ) ) {
	*             throw new TypeError( 'invalid input argument. Indices must be integer valued. Argument: 1. Value: `'+i1+'`.' );
	*         }
	*         if ( !isInteger( i2 ) ) {
	*             throw new TypeError( 'invalid input argument. Indices must be integer valued. Argument: 2. Value: `'+i2+'`.' );
	*         }
	*         i0 = getIndex( i0, this._shape[ 0 ], this._mode );
	*         i1 = getIndex( i1, this._shape[ 1 ], this._mode );
	*         i2 = getIndex( i2, this._shape[ 2 ], this._mode );
	*         return this._buffer[ this._offset + this._strides[0]*i0 + this._strides[1]*i1 + this._strides[2]*i2 ];
	*     }
	*/
} // end FUNCTION get()


// EXPORTS //

{'fraction_non_alphanumeric': 0.1954391255182812, 'fraction_numerical': 0.01375800980022616, 'mean_word_length': 2.448343079922027, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 12, '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': '5562363', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1950, 'n_words': 556}