<commit_before>(function(root, library) {
    if (typeof define === 'function' && define.amd) {
        define([], library);
    } else {
        root.matrix = library();
    }
})(this, function() {
    /**
     *  Custom Error "class" to be thrown on matrix.js
     *  related errors.
     */
    function MatrixError(message) {
        this.name = 'MatrixError';
        this.message = message;
    }


    /**
     *  Performs matrix addition on given matrices.
     */
    function _matrixAddition(a, b) {
        var result = [];
        for (var i = 0; i < a.length; i++) {
            result.push([]);
            for (var j = 0; j < b.length; j++) {
                result[i].push(a[i][j] + b[i][j]);
            }
        }
        return result;
    }


    /**
     *  Performs scalar addition on the given matrix and scalar value.
     */
    function _scalarAddition(matrix, scalar) {
        var result = [];
        for (var i = 0; i < matrix.length; i++) {
            result.push([]);
            for (var j = 0; j < matrix[i].length; j++) {
                result[i].push(matrix[i][j] + scalar);
            }
        }
        return result;
    }


    /**
     *  Performs matrix when given two matrices, or scalar addition when given
     *  a matrix and a scalar value.
     */
    function add(a, b) {
        if (a instanceof Array && b instanceof Array) {
            if (!valid(a) || !valid(b)) {
                throw new MatrixError('A given matrix is invalid.');
            } else if (a.length !== b.length || a[0].length !== b[0].length) {
                throw new MatrixError('Matrices are not of the same '
                    + 'dimensions.');
            }
            return _matrixAddition(a, b);
        } else if ((typeof a === 'number' && b instanceof Array)
                || (typeof b === 'number' && a instanceof Array)) {
            var matrix = a instanceof Array ? a : b;
            var scalar = a instanceof Array ? b : a;
            return _scalarAddition(matrix, scalar);
        }
        throw new MatrixError('No matrices given.');
    }


    /**
     *  Creates an identity matrix with the given size.
     */
    function identity(size) {
        if (size !== undefined && size >= 0) {
            var matrix = [];
            for (var i = 0; i < size; i++) {
                matrix.push([]);
                for (var j = 0; j < size; j++) {
                    matrix[i][j] = i === j ? 1 : 0;
                }
            }
            return matrix;
        }
        throw new MatrixError('Invalid matrix dimensions given.');
    }


    /**
     *  Accepts a matrix and returns the transpose of the
     *  given matrix.
     */
    function transpose(matrix) {
        if (valid(matrix)) {
            var result = [];
            for (var i = 0; matrix.length && i < matrix[0].length; i++) {
                result[i] = [];
                for (var j = 0; j < matrix.length; j++) {
                    result[i].push(matrix[j][i]);
                }
            }
            return result;
        }
        throw new MatrixError('Given matrix is invalid.');
    }


    /**
     *  Validates a given matrix, returning true if it is
     *  valid or false otherwise.
     */
    function valid(matrix) {
        if (matrix instanceof Array) {
            for (var i = 0; i < matrix.length - 1; i++) {
                if (matrix[i].length !== matrix[i + 1].length) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }


    /**
     *  Creates a ones matrix with the given dimensions.
     */
    function ones(rows, columns) {
        columns = columns || rows;
        if (typeof rows === 'number' && typeof columns === 'number') {
            var matrix = [];
            for (var i = 0; i < rows; i++) {
                matrix.push([]);
                for (var j = 0; j < columns; j++) {
                    matrix[i].push(1);
                }
            }
            return matrix;
        }
        throw new TypeError('Matrix dimensions should be integers.');
    }


    /**
     *  Creates a zeros matrix with the given dimensions.
     */
    function zeros(rows, columns) {
        columns = columns || rows;
        if (typeof rows === 'number' && typeof columns === 'number') {
            var matrix = [];
            for (var i = 0; i < rows; i++) {
                matrix.push([]);
                for (var j = 0; j < columns; j++) {
                    matrix[i].push(0);
                }
            }
            return matrix;
        }
        throw new TypeError('Matrix dimensions should be integers.');
    }


    // Attach matrix methods to Array.prototype
    Array.prototype.add = function(value) {
        return add(this, value);
    };

    Array.prototype.valid = function() {
        return valid(this);
    };

    Array.prototype.transpose = function() {
        return transpose(this);
    };

<commit_msg>integrated matrix.identity into array prototype<commit_after>(function(root, library) {
    if (typeof define === 'function' && define.amd) {
        define([], library);
    } else {
        root.matrix = library();
    }
})(this, function() {
    /**
     *  Custom Error "class" to be thrown on matrix.js
     *  related errors.
     */
    function MatrixError(message) {
        this.name = 'MatrixError';
        this.message = message;
    }


    /**
     *  Performs matrix addition on given matrices.
     */
    function _matrixAddition(a, b) {
        var result = [];
        for (var i = 0; i < a.length; i++) {
            result.push([]);
            for (var j = 0; j < b.length; j++) {
                result[i].push(a[i][j] + b[i][j]);
            }
        }
        return result;
    }


    /**
     *  Performs scalar addition on the given matrix and scalar value.
     */
    function _scalarAddition(matrix, scalar) {
        var result = [];
        for (var i = 0; i < matrix.length; i++) {
            result.push([]);
            for (var j = 0; j < matrix[i].length; j++) {
                result[i].push(matrix[i][j] + scalar);
            }
        }
        return result;
    }


    /**
     *  Performs matrix when given two matrices, or scalar addition when given
     *  a matrix and a scalar value.
     */
    function add(a, b) {
        if (a instanceof Array && b instanceof Array) {
            if (!valid(a) || !valid(b)) {
                throw new MatrixError('A given matrix is invalid.');
            } else if (a.length !== b.length || a[0].length !== b[0].length) {
                throw new MatrixError('Matrices are not of the same '
                    + 'dimensions.');
            }
            return _matrixAddition(a, b);
        } else if ((typeof a === 'number' && b instanceof Array)
                || (typeof b === 'number' && a instanceof Array)) {
            var matrix = a instanceof Array ? a : b;
            var scalar = a instanceof Array ? b : a;
            return _scalarAddition(matrix, scalar);
        }
        throw new MatrixError('No matrices given.');
    }


    /**
     *  Creates an identity matrix with the given size.
     */
    function identity(size) {
        if (size !== undefined && size >= 0) {
            var matrix = [];
            for (var i = 0; i < size; i++) {
                matrix.push([]);
                for (var j = 0; j < size; j++) {
                    matrix[i][j] = i === j ? 1 : 0;
                }
            }
            return matrix;
        }
        throw new MatrixError('Invalid matrix dimensions given.');
    }


    /**
     *  Accepts a matrix and returns the transpose of the
     *  given matrix.
     */
    function transpose(matrix) {
        if (valid(matrix)) {
            var result = [];
            for (var i = 0; matrix.length && i < matrix[0].length; i++) {
                result[i] = [];
                for (var j = 0; j < matrix.length; j++) {
                    result[i].push(matrix[j][i]);
                }
            }
            return result;
        }
        throw new MatrixError('Given matrix is invalid.');
    }


    /**
     *  Validates a given matrix, returning true if it is
     *  valid or false otherwise.
     */
    function valid(matrix) {
        if (matrix instanceof Array) {
            for (var i = 0; i < matrix.length - 1; i++) {
                if (matrix[i].length !== matrix[i + 1].length) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }


    /**
     *  Creates a ones matrix with the given dimensions.
     */
    function ones(rows, columns) {
        columns = columns || rows;
        if (typeof rows === 'number' && typeof columns === 'number') {
            var matrix = [];
            for (var i = 0; i < rows; i++) {
                matrix.push([]);
                for (var j = 0; j < columns; j++) {
                    matrix[i].push(1);
                }
            }
            return matrix;
        }
        throw new TypeError('Matrix dimensions should be integers.');
    }


    /**
     *  Creates a zeros matrix with the given dimensions.
     */
    function zeros(rows, columns) {
        columns = columns || rows;
        if (typeof rows === 'number' && typeof columns === 'number') {
            var matrix = [];
            for (var i = 0; i < rows; i++) {
                matrix.push([]);
                for (var j = 0; j < columns; j++) {
                    matrix[i].push(0);
                }
            }
            return matrix;
        }
        throw new TypeError('Matrix dimensions should be integers.');
    }


    // Attach matrix methods to Array.prototype
    Array.prototype.add = function(value) {
        return add(this, value);
    };

    Array.prototype.identity = function() {
        return identity(this);
    };

    Array.prototype.valid = function() {
        return valid(this);
    };

    Array.prototype.transpose = function() {
        return transpose(this);
    };


{'fraction_non_alphanumeric': 0.13362367613580126, 'fraction_numerical': 0.004553103038701376, 'mean_word_length': 1.4091559370529327, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 5, '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': '5645354', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2718, 'n_words': 854}