Comparing version 6.2.0 to 6.3.0
@@ -0,1 +1,10 @@ | ||
# [6.3.0](https://github.com/mljs/matrix/compare/v6.2.0...v6.3.0) (2019-08-16) | ||
### Features | ||
* add UMD build ([#92](https://github.com/mljs/matrix/issues/92)) ([3b82b07](https://github.com/mljs/matrix/commit/3b82b07)) | ||
# [6.2.0](https://github.com/mljs/matrix/compare/v6.1.2...v6.2.0) (2019-07-20) | ||
@@ -2,0 +11,0 @@ |
@@ -8,3 +8,3 @@ type MaybeMatrix = AbstractMatrix | number[][]; | ||
* Random number generator. | ||
* Default: `Math.random` | ||
* @default `Math.random` | ||
*/ | ||
@@ -16,3 +16,3 @@ random: () => number; | ||
* Minimum value. | ||
* Default: 0. | ||
* @default `0` | ||
*/ | ||
@@ -23,3 +23,3 @@ min: number; | ||
* Maximum value. | ||
* Default: 1000. | ||
* @default `1000` | ||
*/ | ||
@@ -30,3 +30,3 @@ max: number; | ||
* Random number generator. | ||
* Default: Math.random. | ||
* @default `Math.random` | ||
*/ | ||
@@ -38,3 +38,3 @@ random: () => number; | ||
* Number of times the rows should be repeated. | ||
* Default: 1. | ||
* @default `1` | ||
*/ | ||
@@ -45,3 +45,3 @@ rows?: number; | ||
* Number of times the columns should be repeated. | ||
* Default: 1. | ||
* @default `1` | ||
*/ | ||
@@ -52,7 +52,9 @@ columns?: number; | ||
/** | ||
* Minimum scaled value. Default: 0. | ||
* Minimum scaled value. | ||
* @default `0` | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum scaled value. Default: 1. | ||
* Maximum scaled value. | ||
* @default `1` | ||
*/ | ||
@@ -86,3 +88,3 @@ max?: number; | ||
/** | ||
* Default: true. | ||
* @default `true` | ||
*/ | ||
@@ -94,7 +96,7 @@ center?: boolean; | ||
/** | ||
* Default: true. | ||
* @default `true` | ||
*/ | ||
center?: boolean; | ||
/** | ||
* Default: true. | ||
* @default `true` | ||
*/ | ||
@@ -193,4 +195,4 @@ scale?: boolean; | ||
* @param rows - Number of rows. | ||
* @param columns - Number of columns. Default: rows. | ||
* @param value - Value to fill the diagonal with. Default: 1. | ||
* @param columns - Number of columns. Default: `rows`. | ||
* @param value - Value to fill the diagonal with. Default: `1`. | ||
* @returns - The new identity matrix. | ||
@@ -636,4 +638,4 @@ */ | ||
* @param indices - Array containing the row indices. | ||
* @param startColumn - First column index. Default: 0. | ||
* @param endColumn - Last column index. Default: columns - 1. | ||
* @param startColumn - First column index. Default: `0`. | ||
* @param endColumn - Last column index. Default: `this.columns - 1`. | ||
*/ | ||
@@ -649,4 +651,4 @@ subMatrixRow( | ||
* @param indices - Array containing the column indices. | ||
* @param startRow - First row index. Default: 0. | ||
* @param endRow - Last row index. Default: rows - 1. | ||
* @param startRow - First row index. Default: `0`. | ||
* @param endRow - Last row index. Default: `this.rows - 1`. | ||
*/ | ||
@@ -947,3 +949,3 @@ subMatrixColumn( | ||
/** | ||
* Default: 1. | ||
* @default: `1` | ||
*/ | ||
@@ -969,3 +971,5 @@ rows?: number; | ||
/** | ||
* @param useSVD - Default: false. | ||
* @param leftHandSide | ||
* @param rightHandSide | ||
* @param useSVD - Default: `false`. | ||
*/ | ||
@@ -981,3 +985,3 @@ export function solve( | ||
* @param matrix - Matrix to invert. | ||
* @param useSVD - Use the singular value decomposition to compute the inverse. Default: false. | ||
* @param useSVD - Use the singular value decomposition to compute the inverse. Default: `false`. | ||
*/ | ||
@@ -995,3 +999,3 @@ export function inverse(matrix: MaybeMatrix, useSVD?: boolean): Matrix; | ||
* If an absolute value is inferior to this threshold, it will equals zero. | ||
* Default: 10e-10. | ||
* @default `10e-10` | ||
*/ | ||
@@ -1002,3 +1006,3 @@ thresholdValue?: number; | ||
* If the error is inferior to that threshold, the linear combination found is accepted and the row is dependent from other rows. | ||
* Default: 10e-10. | ||
* @default `10e-10` | ||
*/ | ||
@@ -1024,3 +1028,3 @@ thresholdError?: number; | ||
* @param matrix | ||
* @param threshold - Threshold for taking inverse of singular values. Default: Number.EPSILON. | ||
* @param threshold - Threshold for taking inverse of singular values. Default: `Number.EPSILON`. | ||
* @returns - The (pseudo)inverted matrix. | ||
@@ -1054,3 +1058,3 @@ */ | ||
/** | ||
* Default: true. | ||
* @default `true` | ||
*/ | ||
@@ -1060,3 +1064,3 @@ computeLeftSingularVectors?: boolean; | ||
/** | ||
* Default: true. | ||
* @default `true` | ||
*/ | ||
@@ -1066,3 +1070,3 @@ computeRightSingularVectors?: boolean; | ||
/** | ||
* Default: false. | ||
* @default `false` | ||
*/ | ||
@@ -1110,3 +1114,3 @@ autoTranspose?: boolean; | ||
/** | ||
* Default: false. | ||
* @default `false` | ||
*/ | ||
@@ -1188,3 +1192,3 @@ assumeSymmetric?: boolean; | ||
* The maximum number of allowed iterations before beraking the loop if convergence is not achieved. | ||
* Default: 1000 | ||
* @default 1000 | ||
*/ | ||
@@ -1194,3 +1198,3 @@ maxIterations?: boolean; | ||
* Termination criteria | ||
* Default: 1e-10 | ||
* @default 1e-10 | ||
*/ | ||
@@ -1197,0 +1201,0 @@ terminationCriteria?: number; |
{ | ||
"name": "ml-matrix", | ||
"version": "6.2.0", | ||
"version": "6.3.0", | ||
"description": "Matrix manipulation and computation library", | ||
"main": "matrix.js", | ||
"module": "src/index.js", | ||
"jsdelivr": "matrix.umd.js", | ||
"unpkg": "matrix.umd.js", | ||
"types": "matrix.d.ts", | ||
@@ -12,2 +14,3 @@ "sideEffects": false, | ||
"matrix.js", | ||
"matrix.umd.js", | ||
"src" | ||
@@ -56,17 +59,22 @@ ], | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.4.4", | ||
"@babel/plugin-transform-modules-commonjs": "^7.5.0", | ||
"benchmark": "^2.1.4", | ||
"csv-parse": "^4.4.3", | ||
"eslint": "^6.0.1", | ||
"eslint-config-cheminfo": "^1.20.1", | ||
"eslint-plugin-import": "^2.18.0", | ||
"eslint-plugin-jest": "^22.7.1", | ||
"jest": "^24.8.0", | ||
"csv-parse": "^4.4.5", | ||
"eslint": "^6.1.0", | ||
"eslint-config-cheminfo": "^2.0.3", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jest": "^22.15.1", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"jest": "^24.9.0", | ||
"jest-matcher-deep-close-to": "^1.3.0", | ||
"mathjs": "^6.0.2", | ||
"ml-dataset-iris": "^1.0.0", | ||
"mathjs": "^6.0.4", | ||
"ml-dataset-iris": "^1.1.1", | ||
"numeric": "^1.2.6", | ||
"prettier": "^1.18.2", | ||
"pretty-hrtime": "^1.0.3", | ||
"rollup": "^1.16.3", | ||
"typedoc": "^0.14.2" | ||
"rollup": "^1.19.4", | ||
"rollup-plugin-commonjs": "^10.0.2", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-terser": "^5.1.1", | ||
"typedoc": "^0.15.0" | ||
}, | ||
@@ -73,0 +81,0 @@ "dependencies": { |
@@ -6,3 +6,7 @@ import Matrix from './matrix'; | ||
let yIsSame = false; | ||
if (typeof yMatrix === 'object' && !Matrix.isMatrix(yMatrix) && !Array.isArray(yMatrix)) { | ||
if ( | ||
typeof yMatrix === 'object' && | ||
!Matrix.isMatrix(yMatrix) && | ||
!Array.isArray(yMatrix) | ||
) { | ||
options = yMatrix; | ||
@@ -33,11 +37,17 @@ yMatrix = xMatrix; | ||
const sdx = xMatrix.standardDeviation('column', { unbiased: true }); | ||
const sdy = yIsSame ? sdx : yMatrix.standardDeviation('column', { unbiased: true }); | ||
const sdy = yIsSame | ||
? sdx | ||
: yMatrix.standardDeviation('column', { unbiased: true }); | ||
const correlation = xMatrix.transpose().mmul(yMatrix); | ||
for (let i = 0; i < correlation.rows; i++) { | ||
for (let j = 0; j < correlation.columns; j++) { | ||
correlation.set(i, j, correlation.get(i, j) * (1 / (sdx[i] * sdy[j])) * (1 / (xMatrix.rows - 1))); | ||
const corr = xMatrix.transpose().mmul(yMatrix); | ||
for (let i = 0; i < corr.rows; i++) { | ||
for (let j = 0; j < corr.columns; j++) { | ||
corr.set( | ||
i, | ||
j, | ||
corr.get(i, j) * (1 / (sdx[i] * sdy[j])) * (1 / (xMatrix.rows - 1)), | ||
); | ||
} | ||
} | ||
return correlation; | ||
return corr; | ||
} |
@@ -6,3 +6,7 @@ import Matrix from './matrix'; | ||
let yIsSame = false; | ||
if (typeof yMatrix === 'object' && !Matrix.isMatrix(yMatrix) && !Array.isArray(yMatrix)) { | ||
if ( | ||
typeof yMatrix === 'object' && | ||
!Matrix.isMatrix(yMatrix) && | ||
!Array.isArray(yMatrix) | ||
) { | ||
options = yMatrix; | ||
@@ -24,9 +28,9 @@ yMatrix = xMatrix; | ||
} | ||
const covariance = xMatrix.transpose().mmul(yMatrix); | ||
for (let i = 0; i < covariance.rows; i++) { | ||
for (let j = 0; j < covariance.columns; j++) { | ||
covariance.set(i, j, covariance.get(i, j) * (1 / (xMatrix.rows - 1))); | ||
const cov = xMatrix.transpose().mmul(yMatrix); | ||
for (let i = 0; i < cov.rows; i++) { | ||
for (let j = 0; j < cov.columns; j++) { | ||
cov.set(i, j, cov.get(i, j) * (1 / (xMatrix.rows - 1))); | ||
} | ||
} | ||
return covariance; | ||
return cov; | ||
} |
@@ -11,12 +11,12 @@ import Matrix from '../matrix'; | ||
var a = value; | ||
var dimension = a.rows; | ||
var l = new Matrix(dimension, dimension); | ||
var positiveDefinite = true; | ||
var i, j, k; | ||
let a = value; | ||
let dimension = a.rows; | ||
let l = new Matrix(dimension, dimension); | ||
let positiveDefinite = true; | ||
let i, j, k; | ||
for (j = 0; j < dimension; j++) { | ||
var d = 0; | ||
let d = 0; | ||
for (k = 0; k < j; k++) { | ||
var s = 0; | ||
let s = 0; | ||
for (i = 0; i < k; i++) { | ||
@@ -49,4 +49,4 @@ s += l.get(k, i) * l.get(j, i); | ||
var l = this.L; | ||
var dimension = l.rows; | ||
let l = this.L; | ||
let dimension = l.rows; | ||
@@ -57,5 +57,5 @@ if (value.rows !== dimension) { | ||
var count = value.columns; | ||
var B = value.clone(); | ||
var i, j, k; | ||
let count = value.columns; | ||
let B = value.clone(); | ||
let i, j, k; | ||
@@ -62,0 +62,0 @@ for (k = 0; k < dimension; k++) { |
@@ -15,10 +15,10 @@ import Matrix from '../matrix'; | ||
var n = matrix.columns; | ||
var V = new Matrix(n, n); | ||
var d = new Float64Array(n); | ||
var e = new Float64Array(n); | ||
var value = matrix; | ||
var i, j; | ||
let n = matrix.columns; | ||
let V = new Matrix(n, n); | ||
let d = new Float64Array(n); | ||
let e = new Float64Array(n); | ||
let value = matrix; | ||
let i, j; | ||
var isSymmetric = false; | ||
let isSymmetric = false; | ||
if (assumeSymmetric) { | ||
@@ -39,4 +39,4 @@ isSymmetric = true; | ||
} else { | ||
var H = new Matrix(n, n); | ||
var ort = new Float64Array(n); | ||
let H = new Matrix(n, n); | ||
let ort = new Float64Array(n); | ||
for (j = 0; j < n; j++) { | ||
@@ -70,7 +70,7 @@ for (i = 0; i < n; i++) { | ||
get diagonalMatrix() { | ||
var n = this.n; | ||
var e = this.e; | ||
var d = this.d; | ||
var X = new Matrix(n, n); | ||
var i, j; | ||
let n = this.n; | ||
let e = this.e; | ||
let d = this.d; | ||
let X = new Matrix(n, n); | ||
let i, j; | ||
for (i = 0; i < n; i++) { | ||
@@ -92,3 +92,3 @@ for (j = 0; j < n; j++) { | ||
function tred2(n, e, d, V) { | ||
var f, g, h, i, j, k, hh, scale; | ||
let f, g, h, i, j, k, hh, scale; | ||
@@ -202,3 +202,3 @@ for (j = 0; j < n; j++) { | ||
function tql2(n, e, d, V) { | ||
var g, h, i, j, k, l, m, p, r, dl1, c, c2, c3, el1, s, s2, iter; | ||
let g, h, i, j, k, l, m, p, r, dl1, c, c2, c3, el1, s, s2, iter; | ||
@@ -211,5 +211,5 @@ for (i = 1; i < n; i++) { | ||
var f = 0; | ||
var tst1 = 0; | ||
var eps = Number.EPSILON; | ||
let f = 0; | ||
let tst1 = 0; | ||
let eps = Number.EPSILON; | ||
@@ -307,6 +307,6 @@ for (l = 0; l < n; l++) { | ||
function orthes(n, H, ort, V) { | ||
var low = 0; | ||
var high = n - 1; | ||
var f, g, h, i, j, m; | ||
var scale; | ||
let low = 0; | ||
let high = n - 1; | ||
let f, g, h, i, j, m; | ||
let scale; | ||
@@ -391,17 +391,17 @@ for (m = low + 1; m <= high - 1; m++) { | ||
function hqr2(nn, e, d, V, H) { | ||
var n = nn - 1; | ||
var low = 0; | ||
var high = nn - 1; | ||
var eps = Number.EPSILON; | ||
var exshift = 0; | ||
var norm = 0; | ||
var p = 0; | ||
var q = 0; | ||
var r = 0; | ||
var s = 0; | ||
var z = 0; | ||
var iter = 0; | ||
var i, j, k, l, m, t, w, x, y; | ||
var ra, sa, vr, vi; | ||
var notlast, cdivres; | ||
let n = nn - 1; | ||
let low = 0; | ||
let high = nn - 1; | ||
let eps = Number.EPSILON; | ||
let exshift = 0; | ||
let norm = 0; | ||
let p = 0; | ||
let q = 0; | ||
let r = 0; | ||
let s = 0; | ||
let z = 0; | ||
let iter = 0; | ||
let i, j, k, l, m, t, w, x, y; | ||
let ra, sa, vr, vi; | ||
let notlast, cdivres; | ||
@@ -671,3 +671,3 @@ for (i = 0; i < nn; i++) { | ||
n, | ||
Math.abs(x) > Math.abs(z) ? (-r - w * t) / x : (-s - y * t) / z | ||
Math.abs(x) > Math.abs(z) ? (-r - w * t) / x : (-s - y * t) / z, | ||
); | ||
@@ -737,3 +737,3 @@ } | ||
vr, | ||
vi | ||
vi, | ||
); | ||
@@ -746,3 +746,3 @@ H.set(i, n - 1, cdivres[0]); | ||
n - 1, | ||
(-ra - w * H.get(i, n - 1) + q * H.get(i, n)) / x | ||
(-ra - w * H.get(i, n - 1) + q * H.get(i, n)) / x, | ||
); | ||
@@ -752,3 +752,3 @@ H.set( | ||
n, | ||
(-sa - w * H.get(i, n) - q * H.get(i, n - 1)) / x | ||
(-sa - w * H.get(i, n) - q * H.get(i, n - 1)) / x, | ||
); | ||
@@ -760,3 +760,3 @@ } else { | ||
z, | ||
q | ||
q, | ||
); | ||
@@ -800,3 +800,3 @@ H.set(i + 1, n - 1, cdivres[0]); | ||
function cdiv(xr, xi, yr, yi) { | ||
var r, d; | ||
let r, d; | ||
if (Math.abs(yr) > Math.abs(yi)) { | ||
@@ -803,0 +803,0 @@ r = yi / yr; |
@@ -8,9 +8,9 @@ import Matrix from '../matrix'; | ||
var lu = matrix.clone(); | ||
var rows = lu.rows; | ||
var columns = lu.columns; | ||
var pivotVector = new Float64Array(rows); | ||
var pivotSign = 1; | ||
var i, j, k, p, s, t, v; | ||
var LUcolj, kmax; | ||
let lu = matrix.clone(); | ||
let rows = lu.rows; | ||
let columns = lu.columns; | ||
let pivotVector = new Float64Array(rows); | ||
let pivotSign = 1; | ||
let i, j, k, p, s, t, v; | ||
let LUcolj, kmax; | ||
@@ -72,5 +72,5 @@ for (i = 0; i < rows; i++) { | ||
isSingular() { | ||
var data = this.LU; | ||
var col = data.columns; | ||
for (var j = 0; j < col; j++) { | ||
let data = this.LU; | ||
let col = data.columns; | ||
for (let j = 0; j < col; j++) { | ||
if (data.get(j, j) === 0) { | ||
@@ -86,4 +86,4 @@ return true; | ||
var lu = this.LU; | ||
var rows = lu.rows; | ||
let lu = this.LU; | ||
let rows = lu.rows; | ||
@@ -97,6 +97,6 @@ if (rows !== value.rows) { | ||
var count = value.columns; | ||
var X = value.subMatrixRow(this.pivotVector, 0, count - 1); | ||
var columns = lu.columns; | ||
var i, j, k; | ||
let count = value.columns; | ||
let X = value.subMatrixRow(this.pivotVector, 0, count - 1); | ||
let columns = lu.columns; | ||
let i, j, k; | ||
@@ -124,9 +124,9 @@ for (k = 0; k < columns; k++) { | ||
get determinant() { | ||
var data = this.LU; | ||
let data = this.LU; | ||
if (!data.isSquare()) { | ||
throw new Error('Matrix must be square'); | ||
} | ||
var determinant = this.pivotSign; | ||
var col = data.columns; | ||
for (var j = 0; j < col; j++) { | ||
let determinant = this.pivotSign; | ||
let col = data.columns; | ||
for (let j = 0; j < col; j++) { | ||
determinant *= data.get(j, j); | ||
@@ -138,8 +138,8 @@ } | ||
get lowerTriangularMatrix() { | ||
var data = this.LU; | ||
var rows = data.rows; | ||
var columns = data.columns; | ||
var X = new Matrix(rows, columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
let data = this.LU; | ||
let rows = data.rows; | ||
let columns = data.columns; | ||
let X = new Matrix(rows, columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
if (i > j) { | ||
@@ -158,8 +158,8 @@ X.set(i, j, data.get(i, j)); | ||
get upperTriangularMatrix() { | ||
var data = this.LU; | ||
var rows = data.rows; | ||
var columns = data.columns; | ||
var X = new Matrix(rows, columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
let data = this.LU; | ||
let rows = data.rows; | ||
let columns = data.columns; | ||
let X = new Matrix(rows, columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
if (i <= j) { | ||
@@ -166,0 +166,0 @@ X.set(i, j, data.get(i, j)); |
@@ -10,10 +10,10 @@ import Matrix from '../matrix'; | ||
var qr = value.clone(); | ||
var m = value.rows; | ||
var n = value.columns; | ||
var rdiag = new Float64Array(n); | ||
var i, j, k, s; | ||
let qr = value.clone(); | ||
let m = value.rows; | ||
let n = value.columns; | ||
let rdiag = new Float64Array(n); | ||
let i, j, k, s; | ||
for (k = 0; k < n; k++) { | ||
var nrm = 0; | ||
let nrm = 0; | ||
for (i = k; i < m; i++) { | ||
@@ -51,4 +51,4 @@ nrm = hypotenuse(nrm, qr.get(i, k)); | ||
var qr = this.QR; | ||
var m = qr.rows; | ||
let qr = this.QR; | ||
let m = qr.rows; | ||
@@ -62,6 +62,6 @@ if (value.rows !== m) { | ||
var count = value.columns; | ||
var X = value.clone(); | ||
var n = qr.columns; | ||
var i, j, k, s; | ||
let count = value.columns; | ||
let X = value.clone(); | ||
let n = qr.columns; | ||
let i, j, k, s; | ||
@@ -95,4 +95,4 @@ for (k = 0; k < n; k++) { | ||
isFullRank() { | ||
var columns = this.QR.columns; | ||
for (var i = 0; i < columns; i++) { | ||
let columns = this.QR.columns; | ||
for (let i = 0; i < columns; i++) { | ||
if (this.Rdiag[i] === 0) { | ||
@@ -106,6 +106,6 @@ return false; | ||
get upperTriangularMatrix() { | ||
var qr = this.QR; | ||
var n = qr.columns; | ||
var X = new Matrix(n, n); | ||
var i, j; | ||
let qr = this.QR; | ||
let n = qr.columns; | ||
let X = new Matrix(n, n); | ||
let i, j; | ||
for (i = 0; i < n; i++) { | ||
@@ -126,7 +126,7 @@ for (j = 0; j < n; j++) { | ||
get orthogonalMatrix() { | ||
var qr = this.QR; | ||
var rows = qr.rows; | ||
var columns = qr.columns; | ||
var X = new Matrix(rows, columns); | ||
var i, j, k, s; | ||
let qr = this.QR; | ||
let rows = qr.rows; | ||
let columns = qr.columns; | ||
let X = new Matrix(rows, columns); | ||
let i, j, k, s; | ||
@@ -133,0 +133,0 @@ for (k = columns - 1; k >= 0; k--) { |
@@ -10,4 +10,4 @@ import Matrix from '../matrix'; | ||
var m = value.rows; | ||
var n = value.columns; | ||
let m = value.rows; | ||
let n = value.columns; | ||
@@ -17,10 +17,10 @@ const { | ||
computeRightSingularVectors = true, | ||
autoTranspose = false | ||
autoTranspose = false, | ||
} = options; | ||
var wantu = Boolean(computeLeftSingularVectors); | ||
var wantv = Boolean(computeRightSingularVectors); | ||
let wantu = Boolean(computeLeftSingularVectors); | ||
let wantv = Boolean(computeRightSingularVectors); | ||
var swapped = false; | ||
var a; | ||
let swapped = false; | ||
let a; | ||
if (m < n) { | ||
@@ -31,3 +31,3 @@ if (!autoTranspose) { | ||
console.warn( | ||
'Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose' | ||
'Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose', | ||
); | ||
@@ -39,3 +39,3 @@ } else { | ||
swapped = true; | ||
var aux = wantu; | ||
let aux = wantu; | ||
wantu = wantv; | ||
@@ -48,17 +48,17 @@ wantv = aux; | ||
var nu = Math.min(m, n); | ||
var ni = Math.min(m + 1, n); | ||
var s = new Float64Array(ni); | ||
var U = new Matrix(m, nu); | ||
var V = new Matrix(n, n); | ||
let nu = Math.min(m, n); | ||
let ni = Math.min(m + 1, n); | ||
let s = new Float64Array(ni); | ||
let U = new Matrix(m, nu); | ||
let V = new Matrix(n, n); | ||
var e = new Float64Array(n); | ||
var work = new Float64Array(m); | ||
let e = new Float64Array(n); | ||
let work = new Float64Array(m); | ||
var si = new Float64Array(ni); | ||
let si = new Float64Array(ni); | ||
for (let i = 0; i < ni; i++) si[i] = i; | ||
var nct = Math.min(m - 1, n); | ||
var nrt = Math.max(0, Math.min(n - 2, m)); | ||
var mrc = Math.max(nct, nrt); | ||
let nct = Math.min(m - 1, n); | ||
let nrt = Math.max(0, Math.min(n - 2, m)); | ||
let mrc = Math.max(nct, nrt); | ||
@@ -210,5 +210,5 @@ for (let k = 0; k < mrc; k++) { | ||
var pp = p - 1; | ||
var iter = 0; | ||
var eps = Number.EPSILON; | ||
let pp = p - 1; | ||
let iter = 0; | ||
let eps = Number.EPSILON; | ||
while (p > 0) { | ||
@@ -304,3 +304,3 @@ let k, kase; | ||
Math.abs(s[k]), | ||
Math.abs(e[k]) | ||
Math.abs(e[k]), | ||
); | ||
@@ -406,3 +406,3 @@ const sp = s[p - 1] / scale; | ||
if (swapped) { | ||
var tmp = V; | ||
let tmp = V; | ||
V = U; | ||
@@ -420,6 +420,6 @@ U = tmp; | ||
solve(value) { | ||
var Y = value; | ||
var e = this.threshold; | ||
var scols = this.s.length; | ||
var Ls = Matrix.zeros(scols, scols); | ||
let Y = value; | ||
let e = this.threshold; | ||
let scols = this.s.length; | ||
let Ls = Matrix.zeros(scols, scols); | ||
@@ -434,9 +434,9 @@ for (let i = 0; i < scols; i++) { | ||
var U = this.U; | ||
var V = this.rightSingularVectors; | ||
let U = this.U; | ||
let V = this.rightSingularVectors; | ||
var VL = V.mmul(Ls); | ||
var vrows = V.rows; | ||
var urows = U.rows; | ||
var VLU = Matrix.zeros(vrows, urows); | ||
let VL = V.mmul(Ls); | ||
let vrows = V.rows; | ||
let urows = U.rows; | ||
let VLU = Matrix.zeros(vrows, urows); | ||
@@ -461,7 +461,7 @@ for (let i = 0; i < vrows; i++) { | ||
inverse() { | ||
var V = this.V; | ||
var e = this.threshold; | ||
var vrows = V.rows; | ||
var vcols = V.columns; | ||
var X = new Matrix(vrows, this.s.length); | ||
let V = this.V; | ||
let e = this.threshold; | ||
let vrows = V.rows; | ||
let vcols = V.columns; | ||
let X = new Matrix(vrows, this.s.length); | ||
@@ -476,7 +476,7 @@ for (let i = 0; i < vrows; i++) { | ||
var U = this.U; | ||
let U = this.U; | ||
var urows = U.rows; | ||
var ucols = U.columns; | ||
var Y = new Matrix(vrows, urows); | ||
let urows = U.rows; | ||
let ucols = U.columns; | ||
let Y = new Matrix(vrows, urows); | ||
@@ -505,6 +505,6 @@ for (let i = 0; i < vrows; i++) { | ||
get rank() { | ||
var tol = Math.max(this.m, this.n) * this.s[0] * Number.EPSILON; | ||
var r = 0; | ||
var s = this.s; | ||
for (var i = 0, ii = s.length; i < ii; i++) { | ||
let tol = Math.max(this.m, this.n) * this.s[0] * Number.EPSILON; | ||
let r = 0; | ||
let s = this.s; | ||
for (let i = 0, ii = s.length; i < ii; i++) { | ||
if (s[i] > tol) { | ||
@@ -511,0 +511,0 @@ r++; |
export function hypotenuse(a, b) { | ||
var r = 0; | ||
let r = 0; | ||
if (Math.abs(a) > Math.abs(b)) { | ||
@@ -4,0 +4,0 @@ r = b / a; |
@@ -8,3 +8,3 @@ import Matrix from './matrix'; | ||
if (matrix.isSquare()) { | ||
var a, b, c, d; | ||
let a, b, c, d; | ||
if (matrix.columns === 2) { | ||
@@ -20,3 +20,3 @@ // 2 x 2 matrix | ||
// 3 x 3 matrix | ||
var subMatrix0, subMatrix1, subMatrix2; | ||
let subMatrix0, subMatrix1, subMatrix2; | ||
subMatrix0 = new MatrixSelectionView(matrix, [1, 2], [1, 2]); | ||
@@ -23,0 +23,0 @@ subMatrix1 = new MatrixSelectionView(matrix, [1, 2], [0, 2]); |
@@ -22,5 +22,5 @@ export function inspectMatrix() { | ||
const result = []; | ||
for (var i = 0; i < maxI; i++) { | ||
for (let i = 0; i < maxI; i++) { | ||
let line = []; | ||
for (var j = 0; j < maxJ; j++) { | ||
for (let j = 0; j < maxJ; j++) { | ||
line.push(formatNumber(matrix.get(i, j))); | ||
@@ -27,0 +27,0 @@ } |
@@ -5,4 +5,4 @@ import Matrix from './matrix'; | ||
function xrange(n, exception) { | ||
var range = []; | ||
for (var i = 0; i < n; i++) { | ||
let range = []; | ||
for (let i = 0; i < n; i++) { | ||
if (i !== exception) { | ||
@@ -20,3 +20,3 @@ range.push(i); | ||
thresholdValue = 10e-10, | ||
thresholdError = 10e-10 | ||
thresholdError = 10e-10, | ||
) { | ||
@@ -26,4 +26,4 @@ if (error > thresholdError) { | ||
} else { | ||
var returnArray = matrix.addRow(index, [0]); | ||
for (var i = 0; i < returnArray.rows; i++) { | ||
let returnArray = matrix.addRow(index, [0]); | ||
for (let i = 0; i < returnArray.rows; i++) { | ||
if (Math.abs(returnArray.get(i, 0)) < thresholdValue) { | ||
@@ -41,11 +41,11 @@ returnArray.set(i, 0, 0); | ||
var n = matrix.rows; | ||
var results = new Matrix(n, n); | ||
let n = matrix.rows; | ||
let results = new Matrix(n, n); | ||
for (var i = 0; i < n; i++) { | ||
var b = Matrix.columnVector(matrix.getRow(i)); | ||
var Abis = matrix.subMatrixRow(xrange(n, i)).transpose(); | ||
var svd = new SingularValueDecomposition(Abis); | ||
var x = svd.solve(b); | ||
var error = Matrix.sub(b, Abis.mmul(x)) | ||
for (let i = 0; i < n; i++) { | ||
let b = Matrix.columnVector(matrix.getRow(i)); | ||
let Abis = matrix.subMatrixRow(xrange(n, i)).transpose(); | ||
let svd = new SingularValueDecomposition(Abis); | ||
let x = svd.solve(b); | ||
let error = Matrix.sub(b, Abis.mmul(x)) | ||
.abs() | ||
@@ -55,3 +55,3 @@ .max(); | ||
i, | ||
dependenciesOneRow(error, x, i, thresholdValue, thresholdError) | ||
dependenciesOneRow(error, x, i, thresholdValue, thresholdError), | ||
); | ||
@@ -58,0 +58,0 @@ } |
@@ -8,4 +8,4 @@ export function installMathOperations(AbstractMatrix, Matrix) { | ||
AbstractMatrix.prototype.addS = function addS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) + value); | ||
@@ -23,4 +23,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) + matrix.get(i, j)); | ||
@@ -33,3 +33,3 @@ } | ||
AbstractMatrix.add = function add(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.add(value); | ||
@@ -44,4 +44,4 @@ }; | ||
AbstractMatrix.prototype.subS = function subS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) - value); | ||
@@ -59,4 +59,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) - matrix.get(i, j)); | ||
@@ -69,3 +69,3 @@ } | ||
AbstractMatrix.sub = function sub(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.sub(value); | ||
@@ -84,4 +84,4 @@ }; | ||
AbstractMatrix.prototype.mulS = function mulS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) * value); | ||
@@ -99,4 +99,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) * matrix.get(i, j)); | ||
@@ -109,3 +109,3 @@ } | ||
AbstractMatrix.mul = function mul(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.mul(value); | ||
@@ -124,4 +124,4 @@ }; | ||
AbstractMatrix.prototype.divS = function divS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) / value); | ||
@@ -139,4 +139,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) / matrix.get(i, j)); | ||
@@ -149,3 +149,3 @@ } | ||
AbstractMatrix.div = function div(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.div(value); | ||
@@ -164,4 +164,4 @@ }; | ||
AbstractMatrix.prototype.modS = function modS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) % value); | ||
@@ -179,4 +179,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) % matrix.get(i, j)); | ||
@@ -189,3 +189,3 @@ } | ||
AbstractMatrix.mod = function mod(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.mod(value); | ||
@@ -204,4 +204,4 @@ }; | ||
AbstractMatrix.prototype.andS = function andS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) & value); | ||
@@ -219,4 +219,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) & matrix.get(i, j)); | ||
@@ -229,3 +229,3 @@ } | ||
AbstractMatrix.and = function and(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.and(value); | ||
@@ -240,4 +240,4 @@ }; | ||
AbstractMatrix.prototype.orS = function orS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) | value); | ||
@@ -255,4 +255,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) | matrix.get(i, j)); | ||
@@ -265,3 +265,3 @@ } | ||
AbstractMatrix.or = function or(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.or(value); | ||
@@ -276,4 +276,4 @@ }; | ||
AbstractMatrix.prototype.xorS = function xorS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) ^ value); | ||
@@ -291,4 +291,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) ^ matrix.get(i, j)); | ||
@@ -301,3 +301,3 @@ } | ||
AbstractMatrix.xor = function xor(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.xor(value); | ||
@@ -312,4 +312,4 @@ }; | ||
AbstractMatrix.prototype.leftShiftS = function leftShiftS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) << value); | ||
@@ -327,4 +327,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) << matrix.get(i, j)); | ||
@@ -337,3 +337,3 @@ } | ||
AbstractMatrix.leftShift = function leftShift(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.leftShift(value); | ||
@@ -348,4 +348,4 @@ }; | ||
AbstractMatrix.prototype.signPropagatingRightShiftS = function signPropagatingRightShiftS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) >> value); | ||
@@ -363,4 +363,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) >> matrix.get(i, j)); | ||
@@ -373,3 +373,3 @@ } | ||
AbstractMatrix.signPropagatingRightShift = function signPropagatingRightShift(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.signPropagatingRightShift(value); | ||
@@ -384,4 +384,4 @@ }; | ||
AbstractMatrix.prototype.rightShiftS = function rightShiftS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) >>> value); | ||
@@ -399,4 +399,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) >>> matrix.get(i, j)); | ||
@@ -409,3 +409,3 @@ } | ||
AbstractMatrix.rightShift = function rightShift(matrix, value) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.rightShift(value); | ||
@@ -419,4 +419,4 @@ }; | ||
AbstractMatrix.prototype.not = function not() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, ~(this.get(i, j))); | ||
@@ -429,3 +429,3 @@ } | ||
AbstractMatrix.not = function not(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.not(); | ||
@@ -435,4 +435,4 @@ }; | ||
AbstractMatrix.prototype.abs = function abs() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.abs(this.get(i, j))); | ||
@@ -445,3 +445,3 @@ } | ||
AbstractMatrix.abs = function abs(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.abs(); | ||
@@ -451,4 +451,4 @@ }; | ||
AbstractMatrix.prototype.acos = function acos() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.acos(this.get(i, j))); | ||
@@ -461,3 +461,3 @@ } | ||
AbstractMatrix.acos = function acos(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.acos(); | ||
@@ -467,4 +467,4 @@ }; | ||
AbstractMatrix.prototype.acosh = function acosh() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.acosh(this.get(i, j))); | ||
@@ -477,3 +477,3 @@ } | ||
AbstractMatrix.acosh = function acosh(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.acosh(); | ||
@@ -483,4 +483,4 @@ }; | ||
AbstractMatrix.prototype.asin = function asin() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.asin(this.get(i, j))); | ||
@@ -493,3 +493,3 @@ } | ||
AbstractMatrix.asin = function asin(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.asin(); | ||
@@ -499,4 +499,4 @@ }; | ||
AbstractMatrix.prototype.asinh = function asinh() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.asinh(this.get(i, j))); | ||
@@ -509,3 +509,3 @@ } | ||
AbstractMatrix.asinh = function asinh(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.asinh(); | ||
@@ -515,4 +515,4 @@ }; | ||
AbstractMatrix.prototype.atan = function atan() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.atan(this.get(i, j))); | ||
@@ -525,3 +525,3 @@ } | ||
AbstractMatrix.atan = function atan(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.atan(); | ||
@@ -531,4 +531,4 @@ }; | ||
AbstractMatrix.prototype.atanh = function atanh() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.atanh(this.get(i, j))); | ||
@@ -541,3 +541,3 @@ } | ||
AbstractMatrix.atanh = function atanh(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.atanh(); | ||
@@ -547,4 +547,4 @@ }; | ||
AbstractMatrix.prototype.cbrt = function cbrt() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.cbrt(this.get(i, j))); | ||
@@ -557,3 +557,3 @@ } | ||
AbstractMatrix.cbrt = function cbrt(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.cbrt(); | ||
@@ -563,4 +563,4 @@ }; | ||
AbstractMatrix.prototype.ceil = function ceil() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.ceil(this.get(i, j))); | ||
@@ -573,3 +573,3 @@ } | ||
AbstractMatrix.ceil = function ceil(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.ceil(); | ||
@@ -579,4 +579,4 @@ }; | ||
AbstractMatrix.prototype.clz32 = function clz32() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.clz32(this.get(i, j))); | ||
@@ -589,3 +589,3 @@ } | ||
AbstractMatrix.clz32 = function clz32(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.clz32(); | ||
@@ -595,4 +595,4 @@ }; | ||
AbstractMatrix.prototype.cos = function cos() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.cos(this.get(i, j))); | ||
@@ -605,3 +605,3 @@ } | ||
AbstractMatrix.cos = function cos(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.cos(); | ||
@@ -611,4 +611,4 @@ }; | ||
AbstractMatrix.prototype.cosh = function cosh() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.cosh(this.get(i, j))); | ||
@@ -621,3 +621,3 @@ } | ||
AbstractMatrix.cosh = function cosh(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.cosh(); | ||
@@ -627,4 +627,4 @@ }; | ||
AbstractMatrix.prototype.exp = function exp() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.exp(this.get(i, j))); | ||
@@ -637,3 +637,3 @@ } | ||
AbstractMatrix.exp = function exp(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.exp(); | ||
@@ -643,4 +643,4 @@ }; | ||
AbstractMatrix.prototype.expm1 = function expm1() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.expm1(this.get(i, j))); | ||
@@ -653,3 +653,3 @@ } | ||
AbstractMatrix.expm1 = function expm1(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.expm1(); | ||
@@ -659,4 +659,4 @@ }; | ||
AbstractMatrix.prototype.floor = function floor() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.floor(this.get(i, j))); | ||
@@ -669,3 +669,3 @@ } | ||
AbstractMatrix.floor = function floor(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.floor(); | ||
@@ -675,4 +675,4 @@ }; | ||
AbstractMatrix.prototype.fround = function fround() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.fround(this.get(i, j))); | ||
@@ -685,3 +685,3 @@ } | ||
AbstractMatrix.fround = function fround(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.fround(); | ||
@@ -691,4 +691,4 @@ }; | ||
AbstractMatrix.prototype.log = function log() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.log(this.get(i, j))); | ||
@@ -701,3 +701,3 @@ } | ||
AbstractMatrix.log = function log(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.log(); | ||
@@ -707,4 +707,4 @@ }; | ||
AbstractMatrix.prototype.log1p = function log1p() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.log1p(this.get(i, j))); | ||
@@ -717,3 +717,3 @@ } | ||
AbstractMatrix.log1p = function log1p(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.log1p(); | ||
@@ -723,4 +723,4 @@ }; | ||
AbstractMatrix.prototype.log10 = function log10() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.log10(this.get(i, j))); | ||
@@ -733,3 +733,3 @@ } | ||
AbstractMatrix.log10 = function log10(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.log10(); | ||
@@ -739,4 +739,4 @@ }; | ||
AbstractMatrix.prototype.log2 = function log2() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.log2(this.get(i, j))); | ||
@@ -749,3 +749,3 @@ } | ||
AbstractMatrix.log2 = function log2(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.log2(); | ||
@@ -755,4 +755,4 @@ }; | ||
AbstractMatrix.prototype.round = function round() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.round(this.get(i, j))); | ||
@@ -765,3 +765,3 @@ } | ||
AbstractMatrix.round = function round(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.round(); | ||
@@ -771,4 +771,4 @@ }; | ||
AbstractMatrix.prototype.sign = function sign() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.sign(this.get(i, j))); | ||
@@ -781,3 +781,3 @@ } | ||
AbstractMatrix.sign = function sign(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.sign(); | ||
@@ -787,4 +787,4 @@ }; | ||
AbstractMatrix.prototype.sin = function sin() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.sin(this.get(i, j))); | ||
@@ -797,3 +797,3 @@ } | ||
AbstractMatrix.sin = function sin(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.sin(); | ||
@@ -803,4 +803,4 @@ }; | ||
AbstractMatrix.prototype.sinh = function sinh() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.sinh(this.get(i, j))); | ||
@@ -813,3 +813,3 @@ } | ||
AbstractMatrix.sinh = function sinh(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.sinh(); | ||
@@ -819,4 +819,4 @@ }; | ||
AbstractMatrix.prototype.sqrt = function sqrt() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.sqrt(this.get(i, j))); | ||
@@ -829,3 +829,3 @@ } | ||
AbstractMatrix.sqrt = function sqrt(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.sqrt(); | ||
@@ -835,4 +835,4 @@ }; | ||
AbstractMatrix.prototype.tan = function tan() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.tan(this.get(i, j))); | ||
@@ -845,3 +845,3 @@ } | ||
AbstractMatrix.tan = function tan(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.tan(); | ||
@@ -851,4 +851,4 @@ }; | ||
AbstractMatrix.prototype.tanh = function tanh() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.tanh(this.get(i, j))); | ||
@@ -861,3 +861,3 @@ } | ||
AbstractMatrix.tanh = function tanh(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.tanh(); | ||
@@ -867,4 +867,4 @@ }; | ||
AbstractMatrix.prototype.trunc = function trunc() { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.trunc(this.get(i, j))); | ||
@@ -877,3 +877,3 @@ } | ||
AbstractMatrix.trunc = function trunc(matrix) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.trunc(); | ||
@@ -883,3 +883,3 @@ }; | ||
AbstractMatrix.pow = function pow(matrix, arg0) { | ||
var newMatrix = new Matrix(matrix); | ||
const newMatrix = new Matrix(matrix); | ||
return newMatrix.pow(arg0); | ||
@@ -894,4 +894,4 @@ }; | ||
AbstractMatrix.prototype.powS = function powS(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.pow(this.get(i, j), value)); | ||
@@ -909,4 +909,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, Math.pow(this.get(i, j), matrix.get(i, j))); | ||
@@ -913,0 +913,0 @@ } |
@@ -9,3 +9,3 @@ import rescale from 'ml-array-rescale'; | ||
checkRange, | ||
checkIndices | ||
checkIndices, | ||
} from './util'; | ||
@@ -30,3 +30,3 @@ import { | ||
getScaleByColumn, | ||
getScaleAll | ||
getScaleAll, | ||
} from './stat'; | ||
@@ -38,9 +38,9 @@ import { inspectMatrix } from './inspect'; | ||
static from1DArray(newRows, newColumns, newData) { | ||
var length = newRows * newColumns; | ||
let length = newRows * newColumns; | ||
if (length !== newData.length) { | ||
throw new RangeError('data length does not match given dimensions'); | ||
} | ||
var newMatrix = new Matrix(newRows, newColumns); | ||
for (var row = 0; row < newRows; row++) { | ||
for (var column = 0; column < newColumns; column++) { | ||
let newMatrix = new Matrix(newRows, newColumns); | ||
for (let row = 0; row < newRows; row++) { | ||
for (let column = 0; column < newColumns; column++) { | ||
newMatrix.set(row, column, newData[row * newColumns + column]); | ||
@@ -53,4 +53,4 @@ } | ||
static rowVector(newData) { | ||
var vector = new Matrix(1, newData.length); | ||
for (var i = 0; i < newData.length; i++) { | ||
let vector = new Matrix(1, newData.length); | ||
for (let i = 0; i < newData.length; i++) { | ||
vector.set(0, i, newData[i]); | ||
@@ -62,4 +62,4 @@ } | ||
static columnVector(newData) { | ||
var vector = new Matrix(newData.length, 1); | ||
for (var i = 0; i < newData.length; i++) { | ||
let vector = new Matrix(newData.length, 1); | ||
for (let i = 0; i < newData.length; i++) { | ||
vector.set(i, 0, newData[i]); | ||
@@ -83,5 +83,5 @@ } | ||
const { random = Math.random } = options; | ||
var matrix = new Matrix(rows, columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
let matrix = new Matrix(rows, columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
matrix.set(i, j, random()); | ||
@@ -101,7 +101,7 @@ } | ||
if (min >= max) throw new RangeError('min must be smaller than max'); | ||
var interval = max - min; | ||
var matrix = new Matrix(rows, columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
var value = min + Math.round(random() * interval); | ||
let interval = max - min; | ||
let matrix = new Matrix(rows, columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
let value = min + Math.round(random() * interval); | ||
matrix.set(i, j, value); | ||
@@ -116,5 +116,5 @@ } | ||
if (value === undefined) value = 1; | ||
var min = Math.min(rows, columns); | ||
var matrix = this.zeros(rows, columns); | ||
for (var i = 0; i < min; i++) { | ||
let min = Math.min(rows, columns); | ||
let matrix = this.zeros(rows, columns); | ||
for (let i = 0; i < min; i++) { | ||
matrix.set(i, i, value); | ||
@@ -126,8 +126,8 @@ } | ||
static diag(data, rows, columns) { | ||
var l = data.length; | ||
let l = data.length; | ||
if (rows === undefined) rows = l; | ||
if (columns === undefined) columns = rows; | ||
var min = Math.min(l, rows, columns); | ||
var matrix = this.zeros(rows, columns); | ||
for (var i = 0; i < min; i++) { | ||
let min = Math.min(l, rows, columns); | ||
let matrix = this.zeros(rows, columns); | ||
for (let i = 0; i < min; i++) { | ||
matrix.set(i, i, data[i]); | ||
@@ -141,7 +141,7 @@ } | ||
matrix2 = this.checkMatrix(matrix2); | ||
var rows = matrix1.rows; | ||
var columns = matrix1.columns; | ||
var result = new Matrix(rows, columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
let rows = matrix1.rows; | ||
let columns = matrix1.columns; | ||
let result = new Matrix(rows, columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
result.set(i, j, Math.min(matrix1.get(i, j), matrix2.get(i, j))); | ||
@@ -156,7 +156,7 @@ } | ||
matrix2 = this.checkMatrix(matrix2); | ||
var rows = matrix1.rows; | ||
var columns = matrix1.columns; | ||
var result = new this(rows, columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
let rows = matrix1.rows; | ||
let columns = matrix1.columns; | ||
let result = new this(rows, columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
result.set(i, j, Math.max(matrix1.get(i, j), matrix2.get(i, j))); | ||
@@ -184,4 +184,4 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
callback.call(this, i, j); | ||
@@ -194,5 +194,5 @@ } | ||
to1DArray() { | ||
var array = []; | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let array = []; | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
array.push(this.get(i, j)); | ||
@@ -205,6 +205,6 @@ } | ||
to2DArray() { | ||
var copy = []; | ||
for (var i = 0; i < this.rows; i++) { | ||
let copy = []; | ||
for (let i = 0; i < this.rows; i++) { | ||
copy.push([]); | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
copy[i].push(this.get(i, j)); | ||
@@ -238,4 +238,4 @@ } | ||
if (this.isSquare()) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j <= i; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j <= i; j++) { | ||
if (this.get(i, j) !== this.get(j, i)) { | ||
@@ -310,3 +310,3 @@ return false; | ||
let k = 0; | ||
while ((h < result.rows) && (k < result.columns)) { | ||
while (h < result.rows && k < result.columns) { | ||
let iMax = h; | ||
@@ -351,3 +351,3 @@ for (let i = h; i < result.rows; i++) { | ||
let pivot = false; | ||
while ((p < n) && (pivot === false)) { | ||
while (p < n && pivot === false) { | ||
if (result.get(h, p) === 1) { | ||
@@ -391,5 +391,5 @@ pivot = true; | ||
} | ||
var matrix = new Matrix(this.rows * rows, this.columns * columns); | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < columns; j++) { | ||
let matrix = new Matrix(this.rows * rows, this.columns * columns); | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < columns; j++) { | ||
matrix.setSubMatrix(this, this.rows * i, this.columns * j); | ||
@@ -402,4 +402,4 @@ } | ||
fill(value) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, value); | ||
@@ -417,4 +417,4 @@ } | ||
checkRowIndex(this, index); | ||
var row = []; | ||
for (var i = 0; i < this.columns; i++) { | ||
let row = []; | ||
for (let i = 0; i < this.columns; i++) { | ||
row.push(this.get(index, i)); | ||
@@ -432,3 +432,3 @@ } | ||
array = checkRowVector(this, array); | ||
for (var i = 0; i < this.columns; i++) { | ||
for (let i = 0; i < this.columns; i++) { | ||
this.set(index, i, array[i]); | ||
@@ -442,4 +442,4 @@ } | ||
checkRowIndex(this, row2); | ||
for (var i = 0; i < this.columns; i++) { | ||
var temp = this.get(row1, i); | ||
for (let i = 0; i < this.columns; i++) { | ||
let temp = this.get(row1, i); | ||
this.set(row1, i, this.get(row2, i)); | ||
@@ -453,4 +453,4 @@ this.set(row2, i, temp); | ||
checkColumnIndex(this, index); | ||
var column = []; | ||
for (var i = 0; i < this.rows; i++) { | ||
let column = []; | ||
for (let i = 0; i < this.rows; i++) { | ||
column.push(this.get(i, index)); | ||
@@ -468,3 +468,3 @@ } | ||
array = checkColumnVector(this, array); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
this.set(i, index, array[i]); | ||
@@ -478,4 +478,4 @@ } | ||
checkColumnIndex(this, column2); | ||
for (var i = 0; i < this.rows; i++) { | ||
var temp = this.get(i, column1); | ||
for (let i = 0; i < this.rows; i++) { | ||
let temp = this.get(i, column1); | ||
this.set(i, column1, this.get(i, column2)); | ||
@@ -489,4 +489,4 @@ this.set(i, column2, temp); | ||
vector = checkRowVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) + vector[j]); | ||
@@ -500,4 +500,4 @@ } | ||
vector = checkRowVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) - vector[j]); | ||
@@ -511,4 +511,4 @@ } | ||
vector = checkRowVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) * vector[j]); | ||
@@ -522,4 +522,4 @@ } | ||
vector = checkRowVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) / vector[j]); | ||
@@ -533,4 +533,4 @@ } | ||
vector = checkColumnVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) + vector[i]); | ||
@@ -544,4 +544,4 @@ } | ||
vector = checkColumnVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) - vector[i]); | ||
@@ -555,4 +555,4 @@ } | ||
vector = checkColumnVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) * vector[i]); | ||
@@ -566,4 +566,4 @@ } | ||
vector = checkColumnVector(this, vector); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
this.set(i, j, this.get(i, j) / vector[i]); | ||
@@ -577,3 +577,3 @@ } | ||
checkRowIndex(this, index); | ||
for (var i = 0; i < this.columns; i++) { | ||
for (let i = 0; i < this.columns; i++) { | ||
this.set(index, i, this.get(index, i) * value); | ||
@@ -586,3 +586,3 @@ } | ||
checkColumnIndex(this, index); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
this.set(i, index, this.get(i, index) * value); | ||
@@ -594,5 +594,5 @@ } | ||
max() { | ||
var v = this.get(0, 0); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let v = this.get(0, 0); | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
if (this.get(i, j) > v) { | ||
@@ -607,6 +607,6 @@ v = this.get(i, j); | ||
maxIndex() { | ||
var v = this.get(0, 0); | ||
var idx = [0, 0]; | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let v = this.get(0, 0); | ||
let idx = [0, 0]; | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
if (this.get(i, j) > v) { | ||
@@ -623,5 +623,5 @@ v = this.get(i, j); | ||
min() { | ||
var v = this.get(0, 0); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let v = this.get(0, 0); | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
if (this.get(i, j) < v) { | ||
@@ -636,6 +636,6 @@ v = this.get(i, j); | ||
minIndex() { | ||
var v = this.get(0, 0); | ||
var idx = [0, 0]; | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let v = this.get(0, 0); | ||
let idx = [0, 0]; | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
if (this.get(i, j) < v) { | ||
@@ -653,4 +653,4 @@ v = this.get(i, j); | ||
checkRowIndex(this, row); | ||
var v = this.get(row, 0); | ||
for (var i = 1; i < this.columns; i++) { | ||
let v = this.get(row, 0); | ||
for (let i = 1; i < this.columns; i++) { | ||
if (this.get(row, i) > v) { | ||
@@ -665,5 +665,5 @@ v = this.get(row, i); | ||
checkRowIndex(this, row); | ||
var v = this.get(row, 0); | ||
var idx = [row, 0]; | ||
for (var i = 1; i < this.columns; i++) { | ||
let v = this.get(row, 0); | ||
let idx = [row, 0]; | ||
for (let i = 1; i < this.columns; i++) { | ||
if (this.get(row, i) > v) { | ||
@@ -679,4 +679,4 @@ v = this.get(row, i); | ||
checkRowIndex(this, row); | ||
var v = this.get(row, 0); | ||
for (var i = 1; i < this.columns; i++) { | ||
let v = this.get(row, 0); | ||
for (let i = 1; i < this.columns; i++) { | ||
if (this.get(row, i) < v) { | ||
@@ -691,5 +691,5 @@ v = this.get(row, i); | ||
checkRowIndex(this, row); | ||
var v = this.get(row, 0); | ||
var idx = [row, 0]; | ||
for (var i = 1; i < this.columns; i++) { | ||
let v = this.get(row, 0); | ||
let idx = [row, 0]; | ||
for (let i = 1; i < this.columns; i++) { | ||
if (this.get(row, i) < v) { | ||
@@ -705,4 +705,4 @@ v = this.get(row, i); | ||
checkColumnIndex(this, column); | ||
var v = this.get(0, column); | ||
for (var i = 1; i < this.rows; i++) { | ||
let v = this.get(0, column); | ||
for (let i = 1; i < this.rows; i++) { | ||
if (this.get(i, column) > v) { | ||
@@ -717,5 +717,5 @@ v = this.get(i, column); | ||
checkColumnIndex(this, column); | ||
var v = this.get(0, column); | ||
var idx = [0, column]; | ||
for (var i = 1; i < this.rows; i++) { | ||
let v = this.get(0, column); | ||
let idx = [0, column]; | ||
for (let i = 1; i < this.rows; i++) { | ||
if (this.get(i, column) > v) { | ||
@@ -731,4 +731,4 @@ v = this.get(i, column); | ||
checkColumnIndex(this, column); | ||
var v = this.get(0, column); | ||
for (var i = 1; i < this.rows; i++) { | ||
let v = this.get(0, column); | ||
for (let i = 1; i < this.rows; i++) { | ||
if (this.get(i, column) < v) { | ||
@@ -743,5 +743,5 @@ v = this.get(i, column); | ||
checkColumnIndex(this, column); | ||
var v = this.get(0, column); | ||
var idx = [0, column]; | ||
for (var i = 1; i < this.rows; i++) { | ||
let v = this.get(0, column); | ||
let idx = [0, column]; | ||
for (let i = 1; i < this.rows; i++) { | ||
if (this.get(i, column) < v) { | ||
@@ -756,5 +756,5 @@ v = this.get(i, column); | ||
diag() { | ||
var min = Math.min(this.rows, this.columns); | ||
var diag = []; | ||
for (var i = 0; i < min; i++) { | ||
let min = Math.min(this.rows, this.columns); | ||
let diag = []; | ||
for (let i = 0; i < min; i++) { | ||
diag.push(this.get(i, i)); | ||
@@ -766,8 +766,8 @@ } | ||
norm(type = 'frobenius') { | ||
var result = 0; | ||
let result = 0; | ||
if (type === 'max') { | ||
return this.max(); | ||
} else if (type === 'frobenius') { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
result = result + this.get(i, j) * this.get(i, j); | ||
@@ -783,5 +783,5 @@ } | ||
cumulativeSum() { | ||
var sum = 0; | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let sum = 0; | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
sum += this.get(i, j); | ||
@@ -796,8 +796,8 @@ this.set(i, j, sum); | ||
if (AbstractMatrix.isMatrix(vector2)) vector2 = vector2.to1DArray(); | ||
var vector1 = this.to1DArray(); | ||
let vector1 = this.to1DArray(); | ||
if (vector1.length !== vector2.length) { | ||
throw new RangeError('vectors do not have the same size'); | ||
} | ||
var dot = 0; | ||
for (var i = 0; i < vector1.length; i++) { | ||
let dot = 0; | ||
for (let i = 0; i < vector1.length; i++) { | ||
dot += vector1[i] * vector2[i]; | ||
@@ -811,17 +811,17 @@ } | ||
var m = this.rows; | ||
var n = this.columns; | ||
var p = other.columns; | ||
let m = this.rows; | ||
let n = this.columns; | ||
let p = other.columns; | ||
var result = new Matrix(m, p); | ||
let result = new Matrix(m, p); | ||
var Bcolj = new Float64Array(n); | ||
for (var j = 0; j < p; j++) { | ||
for (var k = 0; k < n; k++) { | ||
let Bcolj = new Float64Array(n); | ||
for (let j = 0; j < p; j++) { | ||
for (let k = 0; k < n; k++) { | ||
Bcolj[k] = other.get(k, j); | ||
} | ||
for (var i = 0; i < m; i++) { | ||
var s = 0; | ||
for (k = 0; k < n; k++) { | ||
for (let i = 0; i < m; i++) { | ||
let s = 0; | ||
for (let k = 0; k < n; k++) { | ||
s += this.get(i, k) * Bcolj[k]; | ||
@@ -838,3 +838,3 @@ } | ||
other = Matrix.checkMatrix(other); | ||
var result = new Matrix(2, 2); | ||
let result = new Matrix(2, 2); | ||
const a11 = this.get(0, 0); | ||
@@ -873,3 +873,3 @@ const b11 = other.get(0, 0); | ||
other = Matrix.checkMatrix(other); | ||
var result = new Matrix(3, 3); | ||
let result = new Matrix(3, 3); | ||
@@ -944,11 +944,11 @@ const a00 = this.get(0, 0); | ||
y = Matrix.checkMatrix(y); | ||
var x = this.clone(); | ||
var r1 = x.rows; | ||
var c1 = x.columns; | ||
var r2 = y.rows; | ||
var c2 = y.columns; | ||
let x = this.clone(); | ||
let r1 = x.rows; | ||
let c1 = x.columns; | ||
let r2 = y.rows; | ||
let c2 = y.columns; | ||
if (c1 !== r2) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`Multiplying ${r1} x ${c1} and ${r2} x ${c2} matrix: dimensions do not match.` | ||
`Multiplying ${r1} x ${c1} and ${r2} x ${c2} matrix: dimensions do not match.`, | ||
); | ||
@@ -960,8 +960,8 @@ } | ||
function embed(mat, rows, cols) { | ||
var r = mat.rows; | ||
var c = mat.columns; | ||
let r = mat.rows; | ||
let c = mat.columns; | ||
if (r === rows && c === cols) { | ||
return mat; | ||
} else { | ||
var resultat = AbstractMatrix.zeros(rows, cols); | ||
let resultat = AbstractMatrix.zeros(rows, cols); | ||
resultat = resultat.setSubMatrix(mat, 0, 0); | ||
@@ -976,4 +976,4 @@ return resultat; | ||
var r = Math.max(r1, r2); | ||
var c = Math.max(c1, c2); | ||
let r = Math.max(r1, r2); | ||
let c = Math.max(c1, c2); | ||
x = embed(x, r, c); | ||
@@ -1001,48 +1001,48 @@ y = embed(y, r, c); | ||
var halfRows = parseInt(a.rows / 2, 10); | ||
var halfCols = parseInt(a.columns / 2, 10); | ||
let halfRows = parseInt(a.rows / 2, 10); | ||
let halfCols = parseInt(a.columns / 2, 10); | ||
// Subdivide input matrices. | ||
var a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1); | ||
var b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1); | ||
let a11 = a.subMatrix(0, halfRows - 1, 0, halfCols - 1); | ||
let b11 = b.subMatrix(0, halfRows - 1, 0, halfCols - 1); | ||
var a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1); | ||
var b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1); | ||
let a12 = a.subMatrix(0, halfRows - 1, halfCols, a.columns - 1); | ||
let b12 = b.subMatrix(0, halfRows - 1, halfCols, b.columns - 1); | ||
var a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1); | ||
var b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1); | ||
let a21 = a.subMatrix(halfRows, a.rows - 1, 0, halfCols - 1); | ||
let b21 = b.subMatrix(halfRows, b.rows - 1, 0, halfCols - 1); | ||
var a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1); | ||
var b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1); | ||
let a22 = a.subMatrix(halfRows, a.rows - 1, halfCols, a.columns - 1); | ||
let b22 = b.subMatrix(halfRows, b.rows - 1, halfCols, b.columns - 1); | ||
// Compute intermediate values. | ||
var m1 = blockMult( | ||
let m1 = blockMult( | ||
AbstractMatrix.add(a11, a22), | ||
AbstractMatrix.add(b11, b22), | ||
halfRows, | ||
halfCols | ||
halfCols, | ||
); | ||
var m2 = blockMult(AbstractMatrix.add(a21, a22), b11, halfRows, halfCols); | ||
var m3 = blockMult(a11, AbstractMatrix.sub(b12, b22), halfRows, halfCols); | ||
var m4 = blockMult(a22, AbstractMatrix.sub(b21, b11), halfRows, halfCols); | ||
var m5 = blockMult(AbstractMatrix.add(a11, a12), b22, halfRows, halfCols); | ||
var m6 = blockMult( | ||
let m2 = blockMult(AbstractMatrix.add(a21, a22), b11, halfRows, halfCols); | ||
let m3 = blockMult(a11, AbstractMatrix.sub(b12, b22), halfRows, halfCols); | ||
let m4 = blockMult(a22, AbstractMatrix.sub(b21, b11), halfRows, halfCols); | ||
let m5 = blockMult(AbstractMatrix.add(a11, a12), b22, halfRows, halfCols); | ||
let m6 = blockMult( | ||
AbstractMatrix.sub(a21, a11), | ||
AbstractMatrix.add(b11, b12), | ||
halfRows, | ||
halfCols | ||
halfCols, | ||
); | ||
var m7 = blockMult( | ||
let m7 = blockMult( | ||
AbstractMatrix.sub(a12, a22), | ||
AbstractMatrix.add(b21, b22), | ||
halfRows, | ||
halfCols | ||
halfCols, | ||
); | ||
// Combine intermediate values into the output. | ||
var c11 = AbstractMatrix.add(m1, m4); | ||
let c11 = AbstractMatrix.add(m1, m4); | ||
c11.sub(m5); | ||
c11.add(m7); | ||
var c12 = AbstractMatrix.add(m3, m5); | ||
var c21 = AbstractMatrix.add(m2, m4); | ||
var c22 = AbstractMatrix.sub(m1, m2); | ||
let c12 = AbstractMatrix.add(m3, m5); | ||
let c21 = AbstractMatrix.add(m2, m4); | ||
let c22 = AbstractMatrix.sub(m1, m2); | ||
c22.add(m3); | ||
@@ -1052,3 +1052,3 @@ c22.add(m6); | ||
// Crop output to the desired size (undo dynamic padding). | ||
var resultat = AbstractMatrix.zeros(2 * c11.rows, 2 * c11.columns); | ||
let resultat = AbstractMatrix.zeros(2 * c11.rows, 2 * c11.columns); | ||
resultat = resultat.setSubMatrix(c11, 0, 0); | ||
@@ -1071,4 +1071,4 @@ resultat = resultat.setSubMatrix(c12, c11.rows, 0); | ||
if (min >= max) throw new RangeError('min must be smaller than max'); | ||
var newMatrix = new Matrix(this.rows, this.columns); | ||
for (var i = 0; i < this.rows; i++) { | ||
let newMatrix = new Matrix(this.rows, this.columns); | ||
for (let i = 0; i < this.rows; i++) { | ||
const row = this.getRow(i); | ||
@@ -1089,4 +1089,4 @@ rescale(row, { min, max, output: row }); | ||
if (min >= max) throw new RangeError('min must be smaller than max'); | ||
var newMatrix = new Matrix(this.rows, this.columns); | ||
for (var i = 0; i < this.columns; i++) { | ||
let newMatrix = new Matrix(this.rows, this.columns); | ||
for (let i = 0; i < this.columns; i++) { | ||
const column = this.getColumn(i); | ||
@@ -1096,3 +1096,3 @@ rescale(column, { | ||
max: max, | ||
output: column | ||
output: column, | ||
}); | ||
@@ -1106,6 +1106,6 @@ newMatrix.setColumn(i, column); | ||
const middle = Math.ceil(this.columns / 2); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < middle; j++) { | ||
var first = this.get(i, j); | ||
var last = this.get(i, this.columns - 1 - j); | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < middle; j++) { | ||
let first = this.get(i, j); | ||
let last = this.get(i, this.columns - 1 - j); | ||
this.set(i, j, last); | ||
@@ -1120,6 +1120,6 @@ this.set(i, this.columns - 1 - j, first); | ||
const middle = Math.ceil(this.rows / 2); | ||
for (var j = 0; j < this.columns; j++) { | ||
for (var i = 0; i < middle; i++) { | ||
var first = this.get(i, j); | ||
var last = this.get(this.rows - 1 - i, j); | ||
for (let j = 0; j < this.columns; j++) { | ||
for (let i = 0; i < middle; i++) { | ||
let first = this.get(i, j); | ||
let last = this.get(this.rows - 1 - i, j); | ||
this.set(i, j, last); | ||
@@ -1135,12 +1135,12 @@ this.set(this.rows - 1 - i, j, first); | ||
var m = this.rows; | ||
var n = this.columns; | ||
var p = other.rows; | ||
var q = other.columns; | ||
let m = this.rows; | ||
let n = this.columns; | ||
let p = other.rows; | ||
let q = other.columns; | ||
var result = new Matrix(m * p, n * q); | ||
for (var i = 0; i < m; i++) { | ||
for (var j = 0; j < n; j++) { | ||
for (var k = 0; k < p; k++) { | ||
for (var l = 0; l < q; l++) { | ||
let result = new Matrix(m * p, n * q); | ||
for (let i = 0; i < m; i++) { | ||
for (let j = 0; j < n; j++) { | ||
for (let k = 0; k < p; k++) { | ||
for (let l = 0; l < q; l++) { | ||
result.set(p * i + k, q * j + l, this.get(i, j) * other.get(k, l)); | ||
@@ -1155,5 +1155,5 @@ } | ||
transpose() { | ||
var result = new Matrix(this.columns, this.rows); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (var j = 0; j < this.columns; j++) { | ||
let result = new Matrix(this.columns, this.rows); | ||
for (let i = 0; i < this.rows; i++) { | ||
for (let j = 0; j < this.columns; j++) { | ||
result.set(j, i, this.get(i, j)); | ||
@@ -1166,3 +1166,3 @@ } | ||
sortRows(compareFunction = compareNumbers) { | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
this.setRow(i, this.getRow(i).sort(compareFunction)); | ||
@@ -1174,3 +1174,3 @@ } | ||
sortColumns(compareFunction = compareNumbers) { | ||
for (var i = 0; i < this.columns; i++) { | ||
for (let i = 0; i < this.columns; i++) { | ||
this.setColumn(i, this.getColumn(i).sort(compareFunction)); | ||
@@ -1183,8 +1183,8 @@ } | ||
checkRange(this, startRow, endRow, startColumn, endColumn); | ||
var newMatrix = new Matrix( | ||
let newMatrix = new Matrix( | ||
endRow - startRow + 1, | ||
endColumn - startColumn + 1 | ||
endColumn - startColumn + 1, | ||
); | ||
for (var i = startRow; i <= endRow; i++) { | ||
for (var j = startColumn; j <= endColumn; j++) { | ||
for (let i = startRow; i <= endRow; i++) { | ||
for (let j = startColumn; j <= endColumn; j++) { | ||
newMatrix.set(i - startRow, j - startColumn, this.get(i, j)); | ||
@@ -1209,5 +1209,5 @@ } | ||
var newMatrix = new Matrix(indices.length, endColumn - startColumn + 1); | ||
for (var i = 0; i < indices.length; i++) { | ||
for (var j = startColumn; j <= endColumn; j++) { | ||
let newMatrix = new Matrix(indices.length, endColumn - startColumn + 1); | ||
for (let i = 0; i < indices.length; i++) { | ||
for (let j = startColumn; j <= endColumn; j++) { | ||
if (indices[i] < 0 || indices[i] >= this.rows) { | ||
@@ -1235,5 +1235,5 @@ throw new RangeError(`Row index out of range: ${indices[i]}`); | ||
var newMatrix = new Matrix(endRow - startRow + 1, indices.length); | ||
for (var i = 0; i < indices.length; i++) { | ||
for (var j = startRow; j <= endRow; j++) { | ||
let newMatrix = new Matrix(endRow - startRow + 1, indices.length); | ||
for (let i = 0; i < indices.length; i++) { | ||
for (let j = startRow; j <= endRow; j++) { | ||
if (indices[i] < 0 || indices[i] >= this.columns) { | ||
@@ -1250,7 +1250,7 @@ throw new RangeError(`Column index out of range: ${indices[i]}`); | ||
matrix = Matrix.checkMatrix(matrix); | ||
var endRow = startRow + matrix.rows - 1; | ||
var endColumn = startColumn + matrix.columns - 1; | ||
let endRow = startRow + matrix.rows - 1; | ||
let endColumn = startColumn + matrix.columns - 1; | ||
checkRange(this, startRow, endRow, startColumn, endColumn); | ||
for (var i = 0; i < matrix.rows; i++) { | ||
for (var j = 0; j < matrix.columns; j++) { | ||
for (let i = 0; i < matrix.rows; i++) { | ||
for (let j = 0; j < matrix.columns; j++) { | ||
this.set(startRow + i, startColumn + j, matrix.get(i, j)); | ||
@@ -1263,8 +1263,8 @@ } | ||
selection(rowIndices, columnIndices) { | ||
var indices = checkIndices(this, rowIndices, columnIndices); | ||
var newMatrix = new Matrix(rowIndices.length, columnIndices.length); | ||
for (var i = 0; i < indices.row.length; i++) { | ||
var rowIndex = indices.row[i]; | ||
for (var j = 0; j < indices.column.length; j++) { | ||
var columnIndex = indices.column[j]; | ||
let indices = checkIndices(this, rowIndices, columnIndices); | ||
let newMatrix = new Matrix(rowIndices.length, columnIndices.length); | ||
for (let i = 0; i < indices.row.length; i++) { | ||
let rowIndex = indices.row[i]; | ||
for (let j = 0; j < indices.column.length; j++) { | ||
let columnIndex = indices.column[j]; | ||
newMatrix.set(i, j, this.get(rowIndex, columnIndex)); | ||
@@ -1277,5 +1277,5 @@ } | ||
trace() { | ||
var min = Math.min(this.rows, this.columns); | ||
var trace = 0; | ||
for (var i = 0; i < min; i++) { | ||
let min = Math.min(this.rows, this.columns); | ||
let trace = 0; | ||
for (let i = 0; i < min; i++) { | ||
trace += this.get(i, i); | ||
@@ -1287,5 +1287,5 @@ } | ||
clone() { | ||
var newMatrix = new Matrix(this.rows, this.columns); | ||
for (var row = 0; row < this.rows; row++) { | ||
for (var column = 0; column < this.columns; column++) { | ||
let newMatrix = new Matrix(this.rows, this.columns); | ||
for (let row = 0; row < this.rows; row++) { | ||
for (let column = 0; column < this.columns; column++) { | ||
newMatrix.set(row, column, this.get(row, column)); | ||
@@ -1390,3 +1390,3 @@ } | ||
} else { | ||
for (var i = 0; i < variance.length; i++) { | ||
for (let i = 0; i < variance.length; i++) { | ||
variance[i] = Math.sqrt(variance[i]); | ||
@@ -1421,3 +1421,4 @@ } | ||
return this; | ||
} case undefined: { | ||
} | ||
case undefined: { | ||
if (typeof center !== 'number') { | ||
@@ -1520,3 +1521,3 @@ throw new TypeError('center must be a number'); | ||
throw new TypeError( | ||
'Data must be a 2D array with at least one element' | ||
'Data must be a 2D array with at least one element', | ||
); | ||
@@ -1533,3 +1534,3 @@ } | ||
throw new TypeError( | ||
'First argument must be a positive number or an array' | ||
'First argument must be a positive number or an array', | ||
); | ||
@@ -1578,3 +1579,3 @@ } | ||
} | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
const newRow = new Float64Array(this.columns - 1); | ||
@@ -1600,3 +1601,3 @@ for (let j = 0; j < index; j++) { | ||
array = checkColumnVector(this, array); | ||
for (var i = 0; i < this.rows; i++) { | ||
for (let i = 0; i < this.rows; i++) { | ||
const newRow = new Float64Array(this.columns + 1); | ||
@@ -1603,0 +1604,0 @@ let j = 0; |
@@ -6,9 +6,9 @@ import SVD from './dc/svd'; | ||
matrix = Matrix.checkMatrix(matrix); | ||
var svdSolution = new SVD(matrix, { autoTranspose: true }); | ||
let svdSolution = new SVD(matrix, { autoTranspose: true }); | ||
var U = svdSolution.leftSingularVectors; | ||
var V = svdSolution.rightSingularVectors; | ||
var s = svdSolution.diagonal; | ||
let U = svdSolution.leftSingularVectors; | ||
let V = svdSolution.rightSingularVectors; | ||
let s = svdSolution.diagonal; | ||
for (var i = 0; i < s.length; i++) { | ||
for (let i = 0; i < s.length; i++) { | ||
if (Math.abs(s[i]) > threshold) { | ||
@@ -15,0 +15,0 @@ s[i] = 1.0 / s[i]; |
import { newArray } from './util'; | ||
export function sumByRow(matrix) { | ||
var sum = newArray(matrix.rows); | ||
for (var i = 0; i < matrix.rows; ++i) { | ||
for (var j = 0; j < matrix.columns; ++j) { | ||
let sum = newArray(matrix.rows); | ||
for (let i = 0; i < matrix.rows; ++i) { | ||
for (let j = 0; j < matrix.columns; ++j) { | ||
sum[i] += matrix.get(i, j); | ||
@@ -14,5 +14,5 @@ } | ||
export function sumByColumn(matrix) { | ||
var sum = newArray(matrix.columns); | ||
for (var i = 0; i < matrix.rows; ++i) { | ||
for (var j = 0; j < matrix.columns; ++j) { | ||
let sum = newArray(matrix.columns); | ||
for (let i = 0; i < matrix.rows; ++i) { | ||
for (let j = 0; j < matrix.columns; ++j) { | ||
sum[j] += matrix.get(i, j); | ||
@@ -25,5 +25,5 @@ } | ||
export function sumAll(matrix) { | ||
var v = 0; | ||
for (var i = 0; i < matrix.rows; i++) { | ||
for (var j = 0; j < matrix.columns; j++) { | ||
let v = 0; | ||
for (let i = 0; i < matrix.rows; i++) { | ||
for (let j = 0; j < matrix.columns; j++) { | ||
v += matrix.get(i, j); | ||
@@ -36,5 +36,5 @@ } | ||
export function productByRow(matrix) { | ||
var sum = newArray(matrix.rows, 1); | ||
for (var i = 0; i < matrix.rows; ++i) { | ||
for (var j = 0; j < matrix.columns; ++j) { | ||
let sum = newArray(matrix.rows, 1); | ||
for (let i = 0; i < matrix.rows; ++i) { | ||
for (let j = 0; j < matrix.columns; ++j) { | ||
sum[i] *= matrix.get(i, j); | ||
@@ -47,5 +47,5 @@ } | ||
export function productByColumn(matrix) { | ||
var sum = newArray(matrix.columns, 1); | ||
for (var i = 0; i < matrix.rows; ++i) { | ||
for (var j = 0; j < matrix.columns; ++j) { | ||
let sum = newArray(matrix.columns, 1); | ||
for (let i = 0; i < matrix.rows; ++i) { | ||
for (let j = 0; j < matrix.columns; ++j) { | ||
sum[j] *= matrix.get(i, j); | ||
@@ -58,5 +58,5 @@ } | ||
export function productAll(matrix) { | ||
var v = 1; | ||
for (var i = 0; i < matrix.rows; i++) { | ||
for (var j = 0; j < matrix.columns; j++) { | ||
let v = 1; | ||
for (let i = 0; i < matrix.rows; i++) { | ||
for (let j = 0; j < matrix.columns; j++) { | ||
v *= matrix.get(i, j); | ||
@@ -73,7 +73,7 @@ } | ||
for (var i = 0; i < rows; i++) { | ||
var sum1 = 0; | ||
var sum2 = 0; | ||
var x = 0; | ||
for (var j = 0; j < cols; j++) { | ||
for (let i = 0; i < rows; i++) { | ||
let sum1 = 0; | ||
let sum2 = 0; | ||
let x = 0; | ||
for (let j = 0; j < cols; j++) { | ||
x = matrix.get(i, j) - mean[i]; | ||
@@ -97,7 +97,7 @@ sum1 += x; | ||
for (var j = 0; j < cols; j++) { | ||
var sum1 = 0; | ||
var sum2 = 0; | ||
var x = 0; | ||
for (var i = 0; i < rows; i++) { | ||
for (let j = 0; j < cols; j++) { | ||
let sum1 = 0; | ||
let sum2 = 0; | ||
let x = 0; | ||
for (let i = 0; i < rows; i++) { | ||
x = matrix.get(i, j) - mean[j]; | ||
@@ -121,7 +121,7 @@ sum1 += x; | ||
var sum1 = 0; | ||
var sum2 = 0; | ||
var x = 0; | ||
for (var i = 0; i < rows; i++) { | ||
for (var j = 0; j < cols; j++) { | ||
let sum1 = 0; | ||
let sum2 = 0; | ||
let x = 0; | ||
for (let i = 0; i < rows; i++) { | ||
for (let j = 0; j < cols; j++) { | ||
x = matrix.get(i, j) - mean; | ||
@@ -128,0 +128,0 @@ sum1 += x; |
@@ -9,3 +9,3 @@ /** | ||
export function checkRowIndex(matrix, index, outer) { | ||
var max = outer ? matrix.rows : matrix.rows - 1; | ||
let max = outer ? matrix.rows : matrix.rows - 1; | ||
if (index < 0 || index > max) { | ||
@@ -24,3 +24,3 @@ throw new RangeError('Row index out of range'); | ||
export function checkColumnIndex(matrix, index, outer) { | ||
var max = outer ? matrix.columns : matrix.columns - 1; | ||
let max = outer ? matrix.columns : matrix.columns - 1; | ||
if (index < 0 || index > max) { | ||
@@ -45,3 +45,3 @@ throw new RangeError('Column index out of range'); | ||
throw new RangeError( | ||
'vector size must be the same as the number of columns' | ||
'vector size must be the same as the number of columns', | ||
); | ||
@@ -73,3 +73,3 @@ } | ||
row: checkRowIndices(matrix, rowIndices), | ||
column: checkColumnIndices(matrix, columnIndices) | ||
column: checkColumnIndices(matrix, columnIndices), | ||
}; | ||
@@ -83,3 +83,3 @@ } | ||
var rowOut = rowIndices.some((r) => { | ||
let rowOut = rowIndices.some((r) => { | ||
return r < 0 || r >= matrix.rows; | ||
@@ -102,3 +102,3 @@ }); | ||
var columnOut = columnIndices.some((c) => { | ||
let columnOut = columnIndices.some((c) => { | ||
return c < 0 || c >= matrix.columns; | ||
@@ -140,4 +140,4 @@ }); | ||
export function newArray(length, value = 0) { | ||
var array = []; | ||
for (var i = 0; i < length; i++) { | ||
let array = []; | ||
for (let i = 0; i < length; i++) { | ||
array.push(value); | ||
@@ -144,0 +144,0 @@ } |
@@ -0,0 +0,0 @@ import { checkColumnIndices } from '../util'; |
@@ -0,0 +0,0 @@ import BaseView from './base'; |
@@ -0,0 +0,0 @@ import BaseView from './base'; |
@@ -0,0 +0,0 @@ import { checkRowIndices } from '../util'; |
@@ -7,3 +7,3 @@ import { checkIndices } from '../util'; | ||
constructor(matrix, rowIndices, columnIndices) { | ||
var indices = checkIndices(matrix, rowIndices, columnIndices); | ||
let indices = checkIndices(matrix, rowIndices, columnIndices); | ||
super(matrix, indices.row.length, indices.column.length); | ||
@@ -18,3 +18,3 @@ this.rowIndices = indices.row; | ||
this.columnIndices[columnIndex], | ||
value | ||
value, | ||
); | ||
@@ -27,5 +27,5 @@ return this; | ||
this.rowIndices[rowIndex], | ||
this.columnIndices[columnIndex] | ||
this.columnIndices[columnIndex], | ||
); | ||
} | ||
} |
@@ -17,3 +17,3 @@ import { checkRange } from '../util'; | ||
this.startColumn + columnIndex, | ||
value | ||
value, | ||
); | ||
@@ -26,5 +26,5 @@ return this; | ||
this.startRow + rowIndex, | ||
this.startColumn + columnIndex | ||
this.startColumn + columnIndex, | ||
); | ||
} | ||
} |
@@ -0,0 +0,0 @@ import BaseView from './base'; |
@@ -17,3 +17,3 @@ import { AbstractMatrix } from '../matrix'; | ||
set(rowIndex, columnIndex, value) { | ||
var index = this._calculateIndex(rowIndex, columnIndex); | ||
let index = this._calculateIndex(rowIndex, columnIndex); | ||
this.data[index] = value; | ||
@@ -24,3 +24,3 @@ return this; | ||
get(rowIndex, columnIndex) { | ||
var index = this._calculateIndex(rowIndex, columnIndex); | ||
let index = this._calculateIndex(rowIndex, columnIndex); | ||
return this.data[index]; | ||
@@ -27,0 +27,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
378459
41
10427
20