<commit_before>// Matrix.js
// =========

// Matrix.js is a costom library developed to address the need for 
// certain matrix math functions in Javascript. This custom class 
// implements several mathematical functions ranging from basic 
// addition and subtraction to some more programmer-oriented 
// functions such as the hadamard (element-wise) product.

// __TODO:__
// - DETERMINANTS
// - INVERSES
// - TRANSFORMATIONS

// Require underscore.
var _ = require("underscore");

// Matrix Class
// ============
// The main class in Matrix.js. Treated as (more or less) a reference 
// data-type from here on out. Defines several properties in the 
// constructor which are unique to each specific instance, and 
// defines some functions which are available to the object alone.
var Matrix = module.exports = function Matrix(dimensions) {
	if(!(this instanceof Matrix)) return new Matrix(dimensions);
	if(typeof dimensions === 'undefined' && dimensions === null) {
		dimensions = [2, 2];
	}

	var row, col;

	// The matrix value object is where all values in the array are 
	// stored. It is a non-enumerable property defined as a 2D array 
	// with dimensions specified at creation. By default, it is 
	// defined as an identity matrix. If you would like to use a 
	// zero-filled matrix, use the `zero()` function.

	// __DEVELOPER'S NOTE:__ Defined here to keep values of different 
	// instances separate.
	Object.defineProperty(this, 'value', {
		value: [],
		configurable: false,
		enumerable: false,
		writable: true
	});

	is2D = Array.isArray(dimensions[0]) ? true : false;

	// Dimensional properties of the matrix, such as how many rows 
	// and columns, and an array containing the row and column info.
	// Row and column information is set at creation and is 
	// determined by the 'dimensions' argument. 
	Object.defineProperties(this, {
		rows: {
			value: is2D ? dimensions.length : dimensions[0],
			writable: false
		},
		cols: {
			value: is2D ? dimensions[0].length : dimensions[1],
			writable: false
		},
		dimensions: {
			get: function() {
				return [this.rows, this.cols];
			},
			enumerable: false
		}
	});

	// If the dimensions argument is a 2D array, it is assumed that 
	// it contains an array of values. If it is a 1D array, it is 
	// assumed to be the dimensions of the matrix.

	// Only the first two arrays in a 2D array count. If there are 
	// deeper nested arrays, it won't pick up on that information.
	if(is2D) {
		for(row = 0; row < dimensions.length; row++) {
			this.value[row] = [];
			for(col = 0; col < dimensions[0].length; col++) {
				this.value[row][col] = dimensions[row][col] || 0;
			}
		}
	}
	else {
		this.reset();
	}
};

// Matrix Properties
// -----------------
// Properties of the matrix object, such as the transpose of the 
// matrix and the identity matrix of the same dimensions.
Object.defineProperties(Matrix.prototype, {

	T: {
		get: function() {
			var result = new Matrix([this.cols, this.rows]);
			result.value = _.zip.apply(_, this.value);
			return result;
		},
		enumerable: false
	},

	I: {
		get: function() {
			return new Matrix(this.dimensions).value;
		},
		enumerable: false
	}

});

_.extend(Matrix.prototype, {
	// Custom Getter and Setter Functions
	// ----------------------------------
	// These functions are custom getter and setter methods for the 
	// `value` property defined on the Matrix object above. These 
	// allow for a more intuitive (I think) way to access and set the 
	// values of the matrix.

	// Example usage:
	// 
	//     A = new Matrix([2,3]);
	//     A.set(1,1)(4);
	//     console.log(A.value); //[ [ 0, 0, 0 ], [ 0, 4, 0 ] ]
	//     console.log(A.get(1,1)); // 4

	get: function(x, y) {
		return this.value[x][y];
	},

	set: function(x, y) {
		return (function(_value) {
			this.value[x][y] = _value;
		}).bind(this);
	},

	valueOf: function() {
		return this.value;
	},

	copy: function(M) {
		if(!(M instanceof Matrix)) M = new Matrix(M);
		for(row = 0; row < M.rows; row++) {
			for(col = 0; col < M.cols; col++) {
				this.value[row][col] = M.value[row][col];
			}
		}
	},

	reset: function(value) {
		this.zero();
		for(i = 0; i < this.dimensions[0]; i++) {
			this.set(i, i)(1);
		}
	},

	// Zero function accepts optional values as parameters. If a 
	// value is supplied, the matrix will fill itself to that value 
	// rather than defaulting to an identity matrix. This is one way 
	// to zero-out a matrix or fill it with a specific value.
	zero: function(value) {
		value || (value = 0);
		var row, col;
		for(row = 0; row < this.rows; row++) {
			this.value[row] = [];

			for(col = 0; col < this.cols; col++) {
				this.value[row][col] = value;
			}
		}
	}
});

// Matrix Math Functions
// =====================
// Functions are implemented on the Matrix object, i.e. not part of  
// the prototype object. These functions accept multiple arguments 
// and return a new Matrix object. Arguments can be 
// scalars or Matrices.
_.extend(Matrix, {
<commit_msg>Modified zero() function.<commit_after>// Matrix.js
// =========

// Matrix.js is a costom library developed to address the need for 
// certain matrix math functions in Javascript. This custom class 
// implements several mathematical functions ranging from basic 
// addition and subtraction to some more programmer-oriented 
// functions such as the hadamard (element-wise) product.

// __TODO:__
// - DETERMINANTS
// - INVERSES
// - TRANSFORMATIONS

// Require underscore.
var _ = require("underscore");

// Matrix Class
// ============
// The main class in Matrix.js. Treated as (more or less) a reference 
// data-type from here on out. Defines several properties in the 
// constructor which are unique to each specific instance, and 
// defines some functions which are available to the object alone.
var Matrix = module.exports = function Matrix(dimensions) {
	if(!(this instanceof Matrix)) return new Matrix(dimensions);
	if(typeof dimensions === 'undefined' && dimensions === null) {
		dimensions = [2, 2];
	}

	var row, col;

	// The matrix value object is where all values in the array are 
	// stored. It is a non-enumerable property defined as a 2D array 
	// with dimensions specified at creation. By default, it is 
	// defined as an identity matrix. If you would like to use a 
	// zero-filled matrix, use the `zero()` function.

	// __DEVELOPER'S NOTE:__ Defined here to keep values of different 
	// instances separate.
	Object.defineProperty(this, 'value', {
		value: [],
		configurable: false,
		enumerable: false,
		writable: true
	});

	is2D = Array.isArray(dimensions[0]) ? true : false;

	// Dimensional properties of the matrix, such as how many rows 
	// and columns, and an array containing the row and column info.
	// Row and column information is set at creation and is 
	// determined by the 'dimensions' argument. 
	Object.defineProperties(this, {
		rows: {
			value: is2D ? dimensions.length : dimensions[0],
			writable: false
		},
		cols: {
			value: is2D ? dimensions[0].length : dimensions[1],
			writable: false
		},
		dimensions: {
			get: function() {
				return [this.rows, this.cols];
			},
			enumerable: false
		}
	});

	// If the dimensions argument is a 2D array, it is assumed that 
	// it contains an array of values. If it is a 1D array, it is 
	// assumed to be the dimensions of the matrix.

	// Only the first two arrays in a 2D array count. If there are 
	// deeper nested arrays, it won't pick up on that information.
	if(is2D) {
		for(row = 0; row < dimensions.length; row++) {
			this.value[row] = [];
			for(col = 0; col < dimensions[0].length; col++) {
				this.value[row][col] = dimensions[row][col] || 0;
			}
		}
	}
	else {
		this.reset();
	}
};

// Matrix Properties
// -----------------
// Properties of the matrix object, such as the transpose of the 
// matrix and the identity matrix of the same dimensions.
Object.defineProperties(Matrix.prototype, {

	T: {
		get: function() {
			var result = new Matrix([this.cols, this.rows]);
			result.value = _.zip.apply(_, this.value);
			return result;
		},
		enumerable: false
	},

	I: {
		get: function() {
			return new Matrix(this.dimensions).value;
		},
		enumerable: false
	}

});

_.extend(Matrix.prototype, {
	// Custom Getter and Setter Functions
	// ----------------------------------
	// These functions are custom getter and setter methods for the 
	// `value` property defined on the Matrix object above. These 
	// allow for a more intuitive (I think) way to access and set the 
	// values of the matrix.

	// Example usage:
	// 
	//     A = new Matrix([2,3]);
	//     A.set(1,1)(4);
	//     console.log(A.value); //[ [ 0, 0, 0 ], [ 0, 4, 0 ] ]
	//     console.log(A.get(1,1)); // 4

	get: function(x, y) {
		return this.value[x][y];
	},

	set: function(x, y) {
		return (function(_value) {
			this.value[x][y] = _value;
		}).bind(this);
	},

	valueOf: function() {
		return this.value;
	},

	copy: function(M) {
		if(!(M instanceof Matrix)) M = new Matrix(M);
		for(row = 0; row < M.rows; row++) {
			for(col = 0; col < M.cols; col++) {
				this.value[row][col] = M.value[row][col];
			}
		}
	},

	reset: function(value) {
		this.zero();
		for(i = 0; i < this.dimensions[0]; i++) {
			this.set(i, i)(1);
		}
	},

	// Zero function accepts optional values as parameters. If a 
	// value is supplied, the matrix will fill itself to that value 
	// rather than defaulting to an identity matrix. This is one way 
	// to zero-out a matrix or fill it with a specific value.
	zero: function(value) {
		value || (value = 0);
		var row, col;
		for(row = 0; row < this.rows; row++) {
			this.value[row] = [];

			for(col = 0; col < this.cols; col++) {
				if(_.isFunction(value)) this.value[row][col] = value();
				else this.value[row][col] = value;
			}
		}
	}
});

// Matrix Math Functions
// =====================
// Functions are implemented on the Matrix object, i.e. not part of  
// the prototype object. These functions accept multiple arguments 
// and return a new Matrix object. Arguments can be 
// scalars or Matrices.
_.extend(Matrix, {

{'fraction_non_alphanumeric': 0.1488515461867356, 'fraction_numerical': 0.007954658446852938, 'mean_word_length': 2.8759152215799615, 'pattern_counts': {'":': 0, '<': 17, '<?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': '6141862', 'n_tokens_mistral': 3461, 'n_tokens_neox': 3121, 'n_words': 1148}