ml-matrix 6.6.0 → 6.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -5
- package/matrix.d.ts +11 -4
- package/matrix.js +21 -9
- package/matrix.umd.js +1 -1
- package/package.json +20 -19
- package/src/dc/nipals.js +3 -3
- package/src/matrix.js +15 -3
- package/CHANGELOG.md +0 -525
package/README.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
# ml-matrix
|
|
2
2
|
|
|
3
|
-
[![NPM version][npm-image]][npm-url]
|
|
4
|
-
[![build status][ci-image]][ci-url]
|
|
5
|
-
[![npm download][download-image]][download-url]
|
|
6
|
-
|
|
7
3
|
Matrix manipulation and computation library.
|
|
8
4
|
|
|
5
|
+
<h3 align="center">
|
|
6
|
+
|
|
7
|
+
<a href="https://www.zakodium.com">
|
|
8
|
+
<img src="https://www.zakodium.com/brand/zakodium-logo-white.svg" width="50" alt="Zakodium logo" />
|
|
9
|
+
</a>
|
|
10
|
+
|
|
11
|
+
<p>
|
|
12
|
+
Maintained by <a href="https://www.zakodium.com">Zakodium</a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
[![NPM version][npm-image]][npm-url]
|
|
16
|
+
[![build status][ci-image]][ci-url]
|
|
17
|
+
[![npm download][download-image]][download-url]
|
|
18
|
+
|
|
19
|
+
</h3>
|
|
20
|
+
|
|
9
21
|
## Installation
|
|
10
22
|
|
|
11
23
|
`$ npm install ml-matrix`
|
|
@@ -64,7 +76,7 @@ C.mod(2); // => C = Cinit % 2
|
|
|
64
76
|
|
|
65
77
|
// Standard Math operations : (abs, cos, round, etc.)
|
|
66
78
|
var A = new Matrix([[1, 1], [-1, -1]]);
|
|
67
|
-
var
|
|
79
|
+
var exponential = Matrix.exp(A); // exponential = Matrix [[Math.exp(1), Math.exp(1)], [Math.exp(-1), Math.exp(-1)], rows: 2, columns: 2].
|
|
68
80
|
var cosinus = Matrix.cos(A); // cosinus = Matrix [[Math.cos(1), Math.cos(1)], [Math.cos(-1), Math.cos(-1)], rows: 2, columns: 2].
|
|
69
81
|
var absolute = Matrix.abs(A); // expon = absolute [[1, 1], [1, 1], rows: 2, columns: 2].
|
|
70
82
|
// you can use 'abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cbrt', 'ceil', 'clz32', 'cos', 'cosh', 'exp', 'expm1', 'floor', 'fround', 'log', 'log1p', 'log10', 'log2', 'round', 'sign', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'
|
|
@@ -110,6 +122,7 @@ const {
|
|
|
110
122
|
QrDecomposition,
|
|
111
123
|
LuDecomposition,
|
|
112
124
|
CholeskyDecomposition,
|
|
125
|
+
EigenvalueDecomposition
|
|
113
126
|
} = require('ml-matrix');
|
|
114
127
|
|
|
115
128
|
//===========================
|
package/matrix.d.ts
CHANGED
|
@@ -608,6 +608,13 @@ export abstract class AbstractMatrix {
|
|
|
608
608
|
* @param other - Other matrix.
|
|
609
609
|
*/
|
|
610
610
|
kroneckerProduct(other: MaybeMatrix): Matrix;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Returns the Kronecker sum between `this` and `other`.
|
|
614
|
+
* @link https://en.wikipedia.org/wiki/Kronecker_product#Kronecker_sum
|
|
615
|
+
* @param other - Other matrix.
|
|
616
|
+
*/
|
|
617
|
+
kroneckerSum(other: MaybeMatrix): Matrix;
|
|
611
618
|
|
|
612
619
|
/**
|
|
613
620
|
* Alias for {@link AbstractMatrix.kroneckerProduct}.
|
|
@@ -1221,7 +1228,7 @@ export interface INipalsOptions {
|
|
|
1221
1228
|
* The maximum number of allowed iterations before beraking the loop if convergence is not achieved.
|
|
1222
1229
|
* @default 1000
|
|
1223
1230
|
*/
|
|
1224
|
-
maxIterations?:
|
|
1231
|
+
maxIterations?: number;
|
|
1225
1232
|
/**
|
|
1226
1233
|
* Termination criteria
|
|
1227
1234
|
* @default 1e-10
|
|
@@ -1242,13 +1249,13 @@ export class Nipals {
|
|
|
1242
1249
|
constructor(X: MaybeMatrix, options?: INipalsOptions);
|
|
1243
1250
|
w: Matrix;
|
|
1244
1251
|
s: Matrix;
|
|
1245
|
-
t:
|
|
1252
|
+
t: Matrix;
|
|
1246
1253
|
xResidual: Matrix;
|
|
1247
1254
|
p: Matrix;
|
|
1248
1255
|
q: Matrix;
|
|
1249
|
-
u:
|
|
1256
|
+
u: Matrix;
|
|
1250
1257
|
yResidual: Matrix;
|
|
1251
|
-
betas:
|
|
1258
|
+
betas: Matrix;
|
|
1252
1259
|
}
|
|
1253
1260
|
|
|
1254
1261
|
export { Nipals as NIPALS };
|
package/matrix.js
CHANGED
|
@@ -2244,6 +2244,7 @@ class AbstractMatrix {
|
|
|
2244
2244
|
resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns);
|
|
2245
2245
|
return resultat.subMatrix(0, rows - 1, 0, cols - 1);
|
|
2246
2246
|
}
|
|
2247
|
+
|
|
2247
2248
|
return blockMult(x, y, r, c);
|
|
2248
2249
|
}
|
|
2249
2250
|
|
|
@@ -2259,7 +2260,7 @@ class AbstractMatrix {
|
|
|
2259
2260
|
for (let i = 0; i < this.rows; i++) {
|
|
2260
2261
|
const row = this.getRow(i);
|
|
2261
2262
|
if (row.length > 0) {
|
|
2262
|
-
rescale__default[
|
|
2263
|
+
rescale__default["default"](row, { min, max, output: row });
|
|
2263
2264
|
}
|
|
2264
2265
|
newMatrix.setRow(i, row);
|
|
2265
2266
|
}
|
|
@@ -2278,7 +2279,7 @@ class AbstractMatrix {
|
|
|
2278
2279
|
for (let i = 0; i < this.columns; i++) {
|
|
2279
2280
|
const column = this.getColumn(i);
|
|
2280
2281
|
if (column.length) {
|
|
2281
|
-
rescale__default[
|
|
2282
|
+
rescale__default["default"](column, {
|
|
2282
2283
|
min: min,
|
|
2283
2284
|
max: max,
|
|
2284
2285
|
output: column,
|
|
@@ -2336,6 +2337,18 @@ class AbstractMatrix {
|
|
|
2336
2337
|
return result;
|
|
2337
2338
|
}
|
|
2338
2339
|
|
|
2340
|
+
kroneckerSum(other) {
|
|
2341
|
+
other = Matrix.checkMatrix(other);
|
|
2342
|
+
if (!this.isSquare() || !other.isSquare()) {
|
|
2343
|
+
throw new Error('Kronecker Sum needs two Square Matrices');
|
|
2344
|
+
}
|
|
2345
|
+
let m = this.rows;
|
|
2346
|
+
let n = other.rows;
|
|
2347
|
+
let AxI = this.kroneckerProduct(Matrix.eye(n, n));
|
|
2348
|
+
let IxB = Matrix.eye(m, m).kroneckerProduct(other);
|
|
2349
|
+
return AxI.add(IxB);
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2339
2352
|
transpose() {
|
|
2340
2353
|
let result = new Matrix(this.columns, this.rows);
|
|
2341
2354
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -2657,9 +2670,8 @@ class AbstractMatrix {
|
|
|
2657
2670
|
|
|
2658
2671
|
AbstractMatrix.prototype.klass = 'Matrix';
|
|
2659
2672
|
if (typeof Symbol !== 'undefined') {
|
|
2660
|
-
AbstractMatrix.prototype[
|
|
2661
|
-
|
|
2662
|
-
] = inspectMatrix;
|
|
2673
|
+
AbstractMatrix.prototype[Symbol.for('nodejs.util.inspect.custom')] =
|
|
2674
|
+
inspectMatrix;
|
|
2663
2675
|
}
|
|
2664
2676
|
|
|
2665
2677
|
function compareNumbers(a, b) {
|
|
@@ -4983,10 +4995,10 @@ class nipals {
|
|
|
4983
4995
|
} else {
|
|
4984
4996
|
Y = WrapperMatrix2D.checkMatrix(Y);
|
|
4985
4997
|
}
|
|
4986
|
-
if (
|
|
4987
|
-
throw new Error('Y
|
|
4998
|
+
if (Y.rows !== X.rows) {
|
|
4999
|
+
throw new Error('Y should have the same number of rows as X');
|
|
4988
5000
|
}
|
|
4989
|
-
u = Y;
|
|
5001
|
+
u = Y.getColumnVector(0);
|
|
4990
5002
|
} else {
|
|
4991
5003
|
u = X.getColumnVector(0);
|
|
4992
5004
|
}
|
|
@@ -5077,7 +5089,7 @@ exports.WrapperMatrix1D = WrapperMatrix1D;
|
|
|
5077
5089
|
exports.WrapperMatrix2D = WrapperMatrix2D;
|
|
5078
5090
|
exports.correlation = correlation;
|
|
5079
5091
|
exports.covariance = covariance;
|
|
5080
|
-
exports
|
|
5092
|
+
exports["default"] = Matrix;
|
|
5081
5093
|
exports.determinant = determinant;
|
|
5082
5094
|
exports.inverse = inverse;
|
|
5083
5095
|
exports.linearDependencies = linearDependencies;
|
package/matrix.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mlMatrix={})}(this,(function(t){"use strict";const e=Object.prototype.toString;function r(t){return e.call(t).endsWith("Array]")}function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=e.fromIndex,o=void 0===s?0:s,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],u=o+1;u<n;u++)t[u]>h&&(h=t[u]);return h}function o(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=e.fromIndex,o=void 0===s?0:s,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],u=o+1;u<n;u++)t[u]<h&&(h=t[u]);return h}function i(t){var e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==i.output){if(!r(i.output))throw new TypeError("output option must be an array if specified");e=i.output}else e=new Array(t.length);var n=o(t),h=s(t);if(n===h)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var u=i.min,l=void 0===u?i.autoMinMax?n:0:u,a=i.max,f=void 0===a?i.autoMinMax?h:1:a;if(l>=f)throw new RangeError("min option must be smaller than max option");for(var c=(f-l)/(h-n),m=0;m<t.length;m++)e[m]=(t[m]-n)*c+l;return e}const n=" ".repeat(2),h=" ".repeat(4);function u(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:o=8}=e;return`${t.constructor.name} {\n${n}[\n${h}${function(t,e,r,s){const{rows:o,columns:i}=t,n=Math.min(o,e),u=Math.min(i,r),a=[];for(let e=0;e<n;e++){let r=[];for(let o=0;o<u;o++)r.push(l(t.get(e,o),s));a.push(`${r.join(" ")}`)}u!==i&&(a[a.length-1]+=` ... ${i-r} more columns`);n!==o&&a.push(`... ${o-e} more rows`);return a.join(`\n${h}`)}(t,r,s,o)}\n${n}]\n${n}rows: ${t.rows}\n${n}columns: ${t.columns}\n}`}function l(t,e){const r=String(t);if(r.length<=e)return r.padEnd(e," ");const s=t.toPrecision(e-2);if(s.length<=e)return s;const o=t.toExponential(e-2),i=o.indexOf("e"),n=o.slice(i);return o.slice(0,e-n.length)+n}function a(t,e,r){let s=r?t.rows:t.rows-1;if(e<0||e>s)throw new RangeError("Row index out of range")}function f(t,e,r){let s=r?t.columns:t.columns-1;if(e<0||e>s)throw new RangeError("Column index out of range")}function c(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function m(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function g(t,e,r){return{row:w(t,e),column:p(t,r)}}function w(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function p(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");if(e.some((e=>e<0||e>=t.columns)))throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function d(t,e,r,s,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(M("startRow",e),M("endRow",r),M("startColumn",s),M("endColumn",o),e>r||s>o||e<0||e>=t.rows||r<0||r>=t.rows||s<0||s>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function y(t,e=0){let r=[];for(let s=0;s<t;s++)r.push(e);return r}function M(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function b(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class x{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new v(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)s.set(o,t,r[o*e+t]);return s}static rowVector(t){let e=new v(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new v(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new v(t,e)}static ones(t,e){return new v(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:s=Math.random}=r;let o=new v(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,s());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:s=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(s>=o)throw new RangeError("min must be smaller than max");let n=o-s,h=new v(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(i()*n);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let s=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<s;t++)o.set(t,t,r);return o}static diag(t,e,r){let s=t.length;void 0===e&&(e=s),void 0===r&&(r=e);let o=Math.min(s,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new v(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new this(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return x.isMatrix(t)?t:new v(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,s=!0,o=!1;for(;t<this.rows&&s;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(s=!1,o=!0);t++}return s}isReducedEchelonForm(){let t=0,e=0,r=-1,s=!0,o=!1;for(;t<this.rows&&s;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(s=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(s=!1);t++}return s}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let s=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(s,r)&&(s=o);if(0===t.get(s,r))r++;else{t.swapRows(e,s);let o=t.get(e,r);for(let s=r;s<t.columns;s++)t.set(e,s,t.get(e,s)/o);for(let s=e+1;s<t.rows;s++){let o=t.get(s,r)/t.get(e,r);t.set(s,r,0);for(let i=r+1;i<t.columns;i++)t.set(s,i,t.get(s,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,s=r-1;for(;s>=0;)if(0===t.maxRow(s))s--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(s,o)?i=!0:o++;for(let r=0;r<s;r++){let i=t.get(r,o);for(let n=o;n<e;n++){let e=t.get(r,n)-i*t.get(s,n);t.set(r,n,e)}}s--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let s=new v(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)s.setSubMatrix(this,this.rows*t,this.columns*e);return s}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){a(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return v.rowVector(this.getRow(t))}setRow(t,e){a(this,t),e=c(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){a(this,t),a(this,e);for(let r=0;r<this.columns;r++){let s=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,s)}return this}getColumn(t){f(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return v.columnVector(this.getColumn(t))}setColumn(t,e){f(this,t),e=m(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){f(this,t),f(this,e);for(let r=0;r<this.rows;r++){let s=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,s)}return this}addRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){a(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){f(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){if(this.isEmpty())return NaN;let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){b(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let s=0;s<this.columns;s++)this.get(r,s)>t&&(t=this.get(r,s),e[0]=r,e[1]=s);return e}min(){if(this.isEmpty())return NaN;let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){b(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let s=0;s<this.columns;s++)this.get(r,s)<t&&(t=this.get(r,s),e[0]=r,e[1]=s);return e}maxRow(t){if(a(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){a(this,t),b(this);let e=this.get(t,0),r=[t,0];for(let s=1;s<this.columns;s++)this.get(t,s)>e&&(e=this.get(t,s),r[1]=s);return r}minRow(t){if(a(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){a(this,t),b(this);let e=this.get(t,0),r=[t,0];for(let s=1;s<this.columns;s++)this.get(t,s)<e&&(e=this.get(t,s),r[1]=s);return r}maxColumn(t){if(f(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){f(this,t),b(this);let e=this.get(0,t),r=[0,t];for(let s=1;s<this.rows;s++)this.get(s,t)>e&&(e=this.get(s,t),r[0]=s);return r}minColumn(t){if(f(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){f(this,t),b(this);let e=this.get(0,t),r=[0,t];for(let s=1;s<this.rows;s++)this.get(s,t)<e&&(e=this.get(s,t),r[0]=s);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){x.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let s=0;s<e.length;s++)r+=e[s]*t[s];return r}mmul(t){t=v.checkMatrix(t);let e=this.rows,r=this.columns,s=t.columns,o=new v(e,s),i=new Float64Array(r);for(let n=0;n<s;n++){for(let e=0;e<r;e++)i[e]=t.get(e,n);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*i[s];o.set(t,n,e)}}return o}strassen2x2(t){t=v.checkMatrix(t);let e=new v(2,2);const r=this.get(0,0),s=t.get(0,0),o=this.get(0,1),i=t.get(0,1),n=this.get(1,0),h=t.get(1,0),u=this.get(1,1),l=t.get(1,1),a=(r+u)*(s+l),f=(n+u)*s,c=r*(i-l),m=u*(h-s),g=(r+o)*l,w=a+m-g+(o-u)*(h+l),p=c+g,d=f+m,y=a-f+c+(n-r)*(s+i);return e.set(0,0,w),e.set(0,1,p),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=v.checkMatrix(t);let e=new v(3,3);const r=this.get(0,0),s=this.get(0,1),o=this.get(0,2),i=this.get(1,0),n=this.get(1,1),h=this.get(1,2),u=this.get(2,0),l=this.get(2,1),a=this.get(2,2),f=t.get(0,0),c=t.get(0,1),m=t.get(0,2),g=t.get(1,0),w=t.get(1,1),p=t.get(1,2),d=t.get(2,0),y=t.get(2,1),M=t.get(2,2),b=(r-i)*(-c+w),x=(-r+i+n)*(f-c+w),E=(i+n)*(-f+c),S=r*f,R=(-r+u+l)*(f-m+p),A=(-r+u)*(m-p),I=(u+l)*(-f+m),k=(-o+l+a)*(w+d-y),V=(o-a)*(w-y),T=o*d,N=(l+a)*(-d+y),q=(-o+n+h)*(p+d-M),C=(o-h)*(p-M),F=(n+h)*(-d+M),D=S+T+s*g,j=(r+s+o-i-n-l-a)*w+x+E+S+k+T+N,$=S+R+I+(r+s+o-n-h-u-l)*p+T+q+F,L=b+n*(-f+c+g-w-p-d+M)+x+S+T+q+C,z=b+x+E+S+h*y,P=T+q+C+F+i*m,U=S+R+A+l*(-f+m+g-w-p-d+y)+k+V+T,O=k+V+T+N+u*c,_=S+R+A+I+a*M;return e.set(0,0,D),e.set(0,1,j),e.set(0,2,$),e.set(1,0,L),e.set(1,1,z),e.set(1,2,P),e.set(2,0,U),e.set(2,1,O),e.set(2,2,_),e}mmulStrassen(t){t=v.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,o=t.rows,i=t.columns;function n(t,e,r){let s=t.rows,o=t.columns;if(s===e&&o===r)return t;{let s=x.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==o&&console.warn(`Multiplying ${r} x ${s} and ${o} x ${i} matrix: dimensions do not match.`);let h=Math.max(r,o),u=Math.max(s,i);return e=n(e,h,u),function t(e,r,s,o){if(s<=512||o<=512)return e.mmul(r);s%2==1&&o%2==1?(e=n(e,s+1,o+1),r=n(r,s+1,o+1)):s%2==1?(e=n(e,s+1,o),r=n(r,s+1,o)):o%2==1&&(e=n(e,s,o+1),r=n(r,s,o+1));let i=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,h-1),l=r.subMatrix(0,i-1,0,h-1),a=e.subMatrix(0,i-1,h,e.columns-1),f=r.subMatrix(0,i-1,h,r.columns-1),c=e.subMatrix(i,e.rows-1,0,h-1),m=r.subMatrix(i,r.rows-1,0,h-1),g=e.subMatrix(i,e.rows-1,h,e.columns-1),w=r.subMatrix(i,r.rows-1,h,r.columns-1),p=t(x.add(u,g),x.add(l,w),i,h),d=t(x.add(c,g),l,i,h),y=t(u,x.sub(f,w),i,h),M=t(g,x.sub(m,l),i,h),b=t(x.add(u,a),w,i,h),E=t(x.sub(c,u),x.add(l,f),i,h),v=t(x.sub(a,g),x.add(m,w),i,h),S=x.add(p,M);S.sub(b),S.add(v);let R=x.add(y,b),A=x.add(d,M),I=x.sub(p,d);I.add(y),I.add(E);let k=x.zeros(2*S.rows,2*S.columns);return k=k.setSubMatrix(S,0,0),k=k.setSubMatrix(R,S.rows,0),k=k.setSubMatrix(A,0,S.columns),k=k.setSubMatrix(I,S.rows,S.columns),k.subMatrix(0,s-1,0,o-1)}(e,t=n(t,h,u),h,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new v(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&i(o,{min:e,max:r,output:o}),s.setRow(t,o)}return s}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new v(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&i(o,{min:e,max:r,output:o}),s.setColumn(t,o)}return s}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=v.checkMatrix(t);let e=this.rows,r=this.columns,s=t.rows,o=t.columns,i=new v(e*s,r*o);for(let n=0;n<e;n++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<o;h++)i.set(s*n+r,o*e+h,this.get(n,e)*t.get(r,h));return i}transpose(){let t=new v(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=E){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=E){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,s){d(this,t,e,r,s);let o=new v(e-t+1,s-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=s;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let s=new v(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);s.set(o,i-e,this.get(t[o],i))}return s}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let s=new v(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);s.set(i-e,o,this.get(i,t[o]))}return s}setSubMatrix(t,e,r){if((t=v.checkMatrix(t)).isEmpty())return this;d(this,e,e+t.rows-1,r,r+t.columns-1);for(let s=0;s<t.rows;s++)for(let o=0;o<t.columns;o++)this.set(e+s,r+o,t.get(s,o));return this}selection(t,e){let r=g(this,t,e),s=new v(t.length,e.length);for(let t=0;t<r.row.length;t++){let e=r.row[t];for(let o=0;o<r.column.length;o++){let i=r.column[o];s.set(t,o,this.get(e,i))}}return s}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new v(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=y(t.rows);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[r]+=t.get(r,s);return e}(this);case"column":return function(t){let e=y(t.columns);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[s]+=t.get(r,s);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)e+=t.get(r,s);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=y(t.rows,1);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[r]*=t.get(r,s);return e}(this);case"column":return function(t){let e=y(t.columns,1);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[s]*=t.get(r,s);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)e*=t.get(r,s);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:s=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Array.isArray(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,i=[];for(let n=0;n<s;n++){let s=0,h=0,u=0;for(let e=0;e<o;e++)u=t.get(n,e)-r[n],s+=u,h+=u*u;e?i.push((h-s*s/o)/(o-1)):i.push((h-s*s/o)/o)}return i}(this,r,s);case"column":if(!Array.isArray(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,i=[];for(let n=0;n<o;n++){let o=0,h=0,u=0;for(let e=0;e<s;e++)u=t.get(e,n)-r[n],o+=u,h+=u*u;e?i.push((h-o*o/s)/(s-1)):i.push((h-o*o/s)/s)}return i}(this,r,s);case void 0:if("number"!=typeof s)throw new TypeError("mean must be a number");return function(t,e,r){const s=t.rows,o=t.columns,i=s*o;let n=0,h=0,u=0;for(let e=0;e<s;e++)for(let s=0;s<o;s++)u=t.get(e,s)-r,n+=u,h+=u*u;return e?(h-n*n/i)/(i-1):(h-n*n/i)/i}(this,r,s);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Array.isArray(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e[r])}(this,r),this;case"column":if(!Array.isArray(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e[s])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let s=0;for(let e=0;e<t.columns;e++)s+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(s))}return e}(this);else if(!Array.isArray(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let s=0;for(let e=0;e<t.rows;e++)s+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(s))}return e}(this);else if(!Array.isArray(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e[s])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let s=0;s<t.columns;s++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,s),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return u(this,t)}}function E(t,e){return t-e}x.prototype.klass="Matrix","undefined"!=typeof Symbol&&(x.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return u(this)}),x.random=x.rand,x.randomInt=x.randInt,x.diagonal=x.diag,x.prototype.diagonal=x.prototype.diag,x.identity=x.eye,x.prototype.negate=x.prototype.neg,x.prototype.tensorProduct=x.prototype.kroneckerProduct;class v extends x{constructor(t,e){if(super(),v.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<t;s++){if(r[s].length!==e)throw new RangeError("Inconsistent array dimensions");this.data.push(Float64Array.from(r[s]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return a(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),a(this,t,!0),e=Float64Array.from(c(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){f(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let s=0;s<t;s++)r[s]=this.data[e][s];for(let s=t+1;s<this.columns;s++)r[s-1]=this.data[e][s];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),f(this,t,!0),e=m(this,e);for(let r=0;r<this.rows;r++){const s=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)s[o]=this.data[r][o];for(s[o++]=e[r];o<this.columns+1;o++)s[o]=this.data[r][o-1];this.data[r]=s}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(x,v);class S extends x{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class R extends S{constructor(t,e,r){let s=g(t,e,r);super(t,s.row.length,s.column.length),this.rowIndices=s.row,this.columnIndices=s.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class A extends x{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let s=this._calculateIndex(t,e);return this.data[s]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class I extends x{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}class k{constructor(t){let e,r,s,o,i,n,h,u,l,a=(t=I.checkMatrix(t)).clone(),f=a.rows,c=a.columns,m=new Float64Array(f),g=1;for(e=0;e<f;e++)m[e]=e;for(u=new Float64Array(f),r=0;r<c;r++){for(e=0;e<f;e++)u[e]=a.get(e,r);for(e=0;e<f;e++){for(l=Math.min(e,r),i=0,s=0;s<l;s++)i+=a.get(e,s)*u[s];u[e]-=i,a.set(e,r,u[e])}for(o=r,e=r+1;e<f;e++)Math.abs(u[e])>Math.abs(u[o])&&(o=e);if(o!==r){for(s=0;s<c;s++)n=a.get(o,s),a.set(o,s,a.get(r,s)),a.set(r,s,n);h=m[o],m[o]=m[r],m[r]=h,g=-g}if(r<f&&0!==a.get(r,r))for(e=r+1;e<f;e++)a.set(e,r,a.get(e,r)/a.get(r,r))}this.LU=a,this.pivotVector=m,this.pivotSign=g}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=v.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let r,s,o,i=t.columns,n=t.subMatrixRow(this.pivotVector,0,i-1),h=e.columns;for(o=0;o<h;o++)for(r=o+1;r<h;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o));for(o=h-1;o>=0;o--){for(s=0;s<i;s++)n.set(o,s,n.get(o,s)/e.get(o,o));for(r=0;r<o;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o))}return n}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let s=0;s<r;s++)e*=t.get(s,s);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new v(e,r);for(let o=0;o<e;o++)for(let e=0;e<r;e++)o>e?s.set(o,e,t.get(o,e)):o===e?s.set(o,e,1):s.set(o,e,0);return s}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new v(e,r);for(let o=0;o<e;o++)for(let e=0;e<r;e++)o<=e?s.set(o,e,t.get(o,e)):s.set(o,e,0);return s}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function V(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class T{constructor(t){let e,r,s,o,i=(t=I.checkMatrix(t)).clone(),n=t.rows,h=t.columns,u=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<n;e++)t=V(t,i.get(e,s));if(0!==t){for(i.get(s,s)<0&&(t=-t),e=s;e<n;e++)i.set(e,s,i.get(e,s)/t);for(i.set(s,s,i.get(s,s)+1),r=s+1;r<h;r++){for(o=0,e=s;e<n;e++)o+=i.get(e,s)*i.get(e,r);for(o=-o/i.get(s,s),e=s;e<n;e++)i.set(e,r,i.get(e,r)+o*i.get(e,s))}}u[s]=-t}this.QR=i,this.Rdiag=u}solve(t){t=v.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let s,o,i,n,h=t.columns,u=t.clone(),l=e.columns;for(i=0;i<l;i++)for(o=0;o<h;o++){for(n=0,s=i;s<r;s++)n+=e.get(s,i)*u.get(s,o);for(n=-n/e.get(i,i),s=i;s<r;s++)u.set(s,o,u.get(s,o)+n*e.get(s,i))}for(i=l-1;i>=0;i--){for(o=0;o<h;o++)u.set(i,o,u.get(i,o)/this.Rdiag[i]);for(s=0;s<i;s++)for(o=0;o<h;o++)u.set(s,o,u.get(s,o)-u.get(i,o)*e.get(s,i))}return u.subMatrix(0,l-1,0,h-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,s=r.columns,o=new v(s,s);for(t=0;t<s;t++)for(e=0;e<s;e++)t<e?o.set(t,e,r.get(t,e)):t===e?o.set(t,e,this.Rdiag[t]):o.set(t,e,0);return o}get orthogonalMatrix(){let t,e,r,s,o=this.QR,i=o.rows,n=o.columns,h=new v(i,n);for(r=n-1;r>=0;r--){for(t=0;t<i;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<n;e++)if(0!==o.get(r,r)){for(s=0,t=r;t<i;t++)s+=o.get(t,r)*h.get(t,e);for(s=-s/o.get(r,r),t=r;t<i;t++)h.set(t,e,h.get(t,e)+s*o.get(t,r))}}return h}}class N{constructor(t,e={}){if((t=I.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:n=!1}=e;let h,u=Boolean(o),l=Boolean(i),a=!1;if(r<s)if(n){h=t.transpose(),r=h.rows,s=h.columns,a=!0;let e=u;u=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let f=Math.min(r,s),c=Math.min(r+1,s),m=new Float64Array(c),g=new v(r,f),w=new v(s,s),p=new Float64Array(s),d=new Float64Array(r),y=new Float64Array(c);for(let t=0;t<c;t++)y[t]=t;let M=Math.min(r-1,s),b=Math.max(0,Math.min(s-2,r)),x=Math.max(M,b);for(let t=0;t<x;t++){if(t<M){m[t]=0;for(let e=t;e<r;e++)m[t]=V(m[t],h.get(e,t));if(0!==m[t]){h.get(t,t)<0&&(m[t]=-m[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/m[t]);h.set(t,t,h.get(t,t)+1)}m[t]=-m[t]}for(let e=t+1;e<s;e++){if(t<M&&0!==m[t]){let s=0;for(let o=t;o<r;o++)s+=h.get(o,t)*h.get(o,e);s=-s/h.get(t,t);for(let o=t;o<r;o++)h.set(o,e,h.get(o,e)+s*h.get(o,t))}p[e]=h.get(t,e)}if(u&&t<M)for(let e=t;e<r;e++)g.set(e,t,h.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<s;e++)p[t]=V(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<s;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)d[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<s;r++)d[e]+=p[r]*h.get(e,r);for(let e=t+1;e<s;e++){let s=-p[e]/p[t+1];for(let o=t+1;o<r;o++)h.set(o,e,h.get(o,e)+s*d[o])}}if(l)for(let e=t+1;e<s;e++)w.set(e,t,p[e])}}let E=Math.min(s,r+1);if(M<s&&(m[M]=h.get(M,M)),r<E&&(m[E-1]=0),b+1<E&&(p[b]=h.get(b,E-1)),p[E-1]=0,u){for(let t=M;t<f;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=M-1;t>=0;t--)if(0!==m[t]){for(let e=t+1;e<f;e++){let s=0;for(let o=t;o<r;o++)s+=g.get(o,t)*g.get(o,e);s=-s/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+s*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(l)for(let t=s-1;t>=0;t--){if(t<b&&0!==p[t])for(let e=t+1;e<s;e++){let r=0;for(let o=t+1;o<s;o++)r+=w.get(o,t)*w.get(o,e);r=-r/w.get(t+1,t);for(let o=t+1;o<s;o++)w.set(o,e,w.get(o,e)+r*w.get(o,t))}for(let e=0;e<s;e++)w.set(e,t,0);w.set(t,t,1)}let S=E-1,R=Number.EPSILON;for(;E>0;){let t,e;for(t=E-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+R*Math.abs(m[t]+Math.abs(m[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===E-2)e=4;else{let r;for(r=E-1;r>=t&&r!==t;r--){let e=(r!==E?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(m[r])<=R*e){m[r]=0;break}}r===t?e=3:r===E-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[E-2];p[E-2]=0;for(let r=E-2;r>=t;r--){let o=V(m[r],e),i=m[r]/o,n=e/o;if(m[r]=o,r!==t&&(e=-n*p[r-1],p[r-1]=i*p[r-1]),l)for(let t=0;t<s;t++)o=i*w.get(t,r)+n*w.get(t,E-1),w.set(t,E-1,-n*w.get(t,r)+i*w.get(t,E-1)),w.set(t,r,o)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let s=t;s<E;s++){let o=V(m[s],e),i=m[s]/o,n=e/o;if(m[s]=o,e=-n*p[s],p[s]=i*p[s],u)for(let e=0;e<r;e++)o=i*g.get(e,s)+n*g.get(e,t-1),g.set(e,t-1,-n*g.get(e,s)+i*g.get(e,t-1)),g.set(e,s,o)}break}case 3:{const e=Math.max(Math.abs(m[E-1]),Math.abs(m[E-2]),Math.abs(p[E-2]),Math.abs(m[t]),Math.abs(p[t])),o=m[E-1]/e,i=m[E-2]/e,n=p[E-2]/e,h=m[t]/e,a=p[t]/e,f=((i+o)*(i-o)+n*n)/2,c=o*n*(o*n);let d=0;0===f&&0===c||(d=f<0?0-Math.sqrt(f*f+c):Math.sqrt(f*f+c),d=c/(f+d));let y=(h+o)*(h-o)+d,M=h*a;for(let e=t;e<E-1;e++){let o=V(y,M);0===o&&(o=Number.MIN_VALUE);let i=y/o,n=M/o;if(e!==t&&(p[e-1]=o),y=i*m[e]+n*p[e],p[e]=i*p[e]-n*m[e],M=n*m[e+1],m[e+1]=i*m[e+1],l)for(let t=0;t<s;t++)o=i*w.get(t,e)+n*w.get(t,e+1),w.set(t,e+1,-n*w.get(t,e)+i*w.get(t,e+1)),w.set(t,e,o);if(o=V(y,M),0===o&&(o=Number.MIN_VALUE),i=y/o,n=M/o,m[e]=o,y=i*p[e]+n*m[e+1],m[e+1]=-n*p[e]+i*m[e+1],M=n*p[e+1],p[e+1]=i*p[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+n*g.get(t,e+1),g.set(t,e+1,-n*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}p[E-2]=y;break}case 4:if(m[t]<=0&&(m[t]=m[t]<0?-m[t]:0,l))for(let e=0;e<=S;e++)w.set(e,t,-w.get(e,t));for(;t<S&&!(m[t]>=m[t+1]);){let e=m[t];if(m[t]=m[t+1],m[t+1]=e,l&&t<s-1)for(let r=0;r<s;r++)e=w.get(r,t+1),w.set(r,t+1,w.get(r,t)),w.set(r,t,e);if(u&&t<r-1)for(let s=0;s<r;s++)e=g.get(s,t+1),g.set(s,t+1,g.get(s,t)),g.set(s,t,e);t++}E--}}if(a){let t=w;w=g,g=t}this.m=r,this.n=s,this.s=m,this.U=g,this.V=w}solve(t){let e=t,r=this.threshold,s=this.s.length,o=v.zeros(s,s);for(let t=0;t<s;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,n=this.rightSingularVectors,h=n.mmul(o),u=n.rows,l=i.rows,a=v.zeros(u,l);for(let t=0;t<u;t++)for(let e=0;e<l;e++){let r=0;for(let o=0;o<s;o++)r+=h.get(t,o)*i.get(e,o);a.set(t,e,r)}return a.mmul(e)}solveForDiagonal(t){return this.solve(v.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,s=t.columns,o=new v(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,n=i.rows,h=i.columns,u=new v(r,n);for(let t=0;t<r;t++)for(let e=0;e<n;e++){let r=0;for(let s=0;s<h;s++)r+=o.get(t,s)*i.get(e,s);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let s=0,o=r.length;s<o;s++)r[s]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return v.diag(this.s)}}function q(t,e,r=!1){return t=I.checkMatrix(t),e=I.checkMatrix(e),r?new N(t).solve(e):t.isSquare()?new k(t).solve(e):new T(t).solve(e)}function C(t,e){let r=[];for(let s=0;s<t;s++)s!==e&&r.push(s);return r}function F(t,e,r,s=1e-9,o=1e-9){if(t>o)return new Array(e.rows+1).fill(0);{let t=e.addRow(r,[0]);for(let e=0;e<t.rows;e++)Math.abs(t.get(e,0))<s&&t.set(e,0,0);return t.to1DArray()}}class D{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=I.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let s,o,i=t.columns,n=new v(i,i),h=new Float64Array(i),u=new Float64Array(i),l=t,a=!1;if(a=!!r||t.isSymmetric(),a){for(s=0;s<i;s++)for(o=0;o<i;o++)n.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,u,l,a,f;for(u=0;u<t;u++)r[u]=s.get(t-1,u);for(h=t-1;h>0;h--){for(f=0,n=0,l=0;l<h;l++)f+=Math.abs(r[l]);if(0===f)for(e[h]=r[h-1],u=0;u<h;u++)r[u]=s.get(h-1,u),s.set(h,u,0),s.set(u,h,0);else{for(l=0;l<h;l++)r[l]/=f,n+=r[l]*r[l];for(o=r[h-1],i=Math.sqrt(n),o>0&&(i=-i),e[h]=f*i,n-=o*i,r[h-1]=o-i,u=0;u<h;u++)e[u]=0;for(u=0;u<h;u++){for(o=r[u],s.set(u,h,o),i=e[u]+s.get(u,u)*o,l=u+1;l<=h-1;l++)i+=s.get(l,u)*r[l],e[l]+=s.get(l,u)*o;e[u]=i}for(o=0,u=0;u<h;u++)e[u]/=n,o+=e[u]*r[u];for(a=o/(n+n),u=0;u<h;u++)e[u]-=a*r[u];for(u=0;u<h;u++){for(o=r[u],i=e[u],l=u;l<=h-1;l++)s.set(l,u,s.get(l,u)-(o*e[l]+i*r[l]));r[u]=s.get(h-1,u),s.set(h,u,0)}}r[h]=n}for(h=0;h<t-1;h++){if(s.set(t-1,h,s.get(h,h)),s.set(h,h,1),n=r[h+1],0!==n){for(l=0;l<=h;l++)r[l]=s.get(l,h+1)/n;for(u=0;u<=h;u++){for(i=0,l=0;l<=h;l++)i+=s.get(l,h+1)*s.get(l,u);for(l=0;l<=h;l++)s.set(l,u,s.get(l,u)-i*r[l])}}for(l=0;l<=h;l++)s.set(l,h+1,0)}for(u=0;u<t;u++)r[u]=s.get(t-1,u),s.set(t-1,u,0);s.set(t-1,t-1,1),e[0]=0}(i,u,h,n),function(t,e,r,s){let o,i,n,h,u,l,a,f,c,m,g,w,p,d,y,M;for(n=1;n<t;n++)e[n-1]=e[n];e[t-1]=0;let b=0,x=0,E=Number.EPSILON;for(l=0;l<t;l++){for(x=Math.max(x,Math.abs(r[l])+Math.abs(e[l])),a=l;a<t&&!(Math.abs(e[a])<=E*x);)a++;if(a>l)do{for(o=r[l],f=(r[l+1]-o)/(2*e[l]),c=V(f,1),f<0&&(c=-c),r[l]=e[l]/(f+c),r[l+1]=e[l]*(f+c),m=r[l+1],i=o-r[l],n=l+2;n<t;n++)r[n]-=i;for(b+=i,f=r[a],g=1,w=g,p=g,d=e[l+1],y=0,M=0,n=a-1;n>=l;n--)for(p=w,w=g,M=y,o=g*e[n],i=g*f,c=V(f,e[n]),e[n+1]=y*c,y=e[n]/c,g=f/c,f=g*r[n]-y*o,r[n+1]=i+y*(g*o+y*r[n]),u=0;u<t;u++)i=s.get(u,n+1),s.set(u,n+1,y*s.get(u,n)+g*i),s.set(u,n,g*s.get(u,n)-y*i);f=-y*M*p*d*e[l]/m,e[l]=y*f,r[l]=g*f}while(Math.abs(e[l])>E*x);r[l]=r[l]+b,e[l]=0}for(n=0;n<t-1;n++){for(u=n,f=r[n],h=n+1;h<t;h++)r[h]<f&&(u=h,f=r[h]);if(u!==n)for(r[u]=r[n],r[n]=f,h=0;h<t;h++)f=s.get(h,n),s.set(h,n,s.get(h,u)),s.set(h,u,f)}}(i,u,h,n)}else{let t=new v(i,i),e=new Float64Array(i);for(o=0;o<i;o++)for(s=0;s<i;s++)t.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,u,l,a,f=0,c=t-1;for(l=f+1;l<=c-1;l++){for(a=0,h=l;h<=c;h++)a+=Math.abs(e.get(h,l-1));if(0!==a){for(n=0,h=c;h>=l;h--)r[h]=e.get(h,l-1)/a,n+=r[h]*r[h];for(i=Math.sqrt(n),r[l]>0&&(i=-i),n-=r[l]*i,r[l]=r[l]-i,u=l;u<t;u++){for(o=0,h=c;h>=l;h--)o+=r[h]*e.get(h,u);for(o/=n,h=l;h<=c;h++)e.set(h,u,e.get(h,u)-o*r[h])}for(h=0;h<=c;h++){for(o=0,u=c;u>=l;u--)o+=r[u]*e.get(h,u);for(o/=n,u=l;u<=c;u++)e.set(h,u,e.get(h,u)-o*r[u])}r[l]=a*r[l],e.set(l,l-1,a*i)}}for(h=0;h<t;h++)for(u=0;u<t;u++)s.set(h,u,h===u?1:0);for(l=c-1;l>=f+1;l--)if(0!==e.get(l,l-1)){for(h=l+1;h<=c;h++)r[h]=e.get(h,l-1);for(u=l;u<=c;u++){for(i=0,h=l;h<=c;h++)i+=r[h]*s.get(h,u);for(i=i/r[l]/e.get(l,l-1),h=l;h<=c;h++)s.set(h,u,s.get(h,u)+i*r[h])}}}(i,t,e,n),function(t,e,r,s,o){let i,n,h,u,l,a,f,c,m,g,w,p,d,y,M,b=t-1,x=0,E=t-1,v=Number.EPSILON,S=0,R=0,A=0,I=0,k=0,V=0,T=0,N=0;for(i=0;i<t;i++)for((i<x||i>E)&&(r[i]=o.get(i,i),e[i]=0),n=Math.max(i-1,0);n<t;n++)R+=Math.abs(o.get(i,n));for(;b>=x;){for(u=b;u>x&&(V=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)),0===V&&(V=R),!(Math.abs(o.get(u,u-1))<v*V));)u--;if(u===b)o.set(b,b,o.get(b,b)+S),r[b]=o.get(b,b),e[b]=0,b--,N=0;else if(u===b-1){if(f=o.get(b,b-1)*o.get(b-1,b),A=(o.get(b-1,b-1)-o.get(b,b))/2,I=A*A+f,T=Math.sqrt(Math.abs(I)),o.set(b,b,o.get(b,b)+S),o.set(b-1,b-1,o.get(b-1,b-1)+S),c=o.get(b,b),I>=0){for(T=A>=0?A+T:A-T,r[b-1]=c+T,r[b]=r[b-1],0!==T&&(r[b]=c-f/T),e[b-1]=0,e[b]=0,c=o.get(b,b-1),V=Math.abs(c)+Math.abs(T),A=c/V,I=T/V,k=Math.sqrt(A*A+I*I),A/=k,I/=k,n=b-1;n<t;n++)T=o.get(b-1,n),o.set(b-1,n,I*T+A*o.get(b,n)),o.set(b,n,I*o.get(b,n)-A*T);for(i=0;i<=b;i++)T=o.get(i,b-1),o.set(i,b-1,I*T+A*o.get(i,b)),o.set(i,b,I*o.get(i,b)-A*T);for(i=x;i<=E;i++)T=s.get(i,b-1),s.set(i,b-1,I*T+A*s.get(i,b)),s.set(i,b,I*s.get(i,b)-A*T)}else r[b-1]=c+A,r[b]=c+A,e[b-1]=T,e[b]=-T;b-=2,N=0}else{if(c=o.get(b,b),m=0,f=0,u<b&&(m=o.get(b-1,b-1),f=o.get(b,b-1)*o.get(b-1,b)),10===N){for(S+=c,i=x;i<=b;i++)o.set(i,i,o.get(i,i)-c);V=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2)),c=m=.75*V,f=-.4375*V*V}if(30===N&&(V=(m-c)/2,V=V*V+f,V>0)){for(V=Math.sqrt(V),m<c&&(V=-V),V=c-f/((m-c)/2+V),i=x;i<=b;i++)o.set(i,i,o.get(i,i)-V);S+=V,c=m=f=.964}for(N+=1,l=b-2;l>=u&&(T=o.get(l,l),k=c-T,V=m-T,A=(k*V-f)/o.get(l+1,l)+o.get(l,l+1),I=o.get(l+1,l+1)-T-k-V,k=o.get(l+2,l+1),V=Math.abs(A)+Math.abs(I)+Math.abs(k),A/=V,I/=V,k/=V,l!==u)&&!(Math.abs(o.get(l,l-1))*(Math.abs(I)+Math.abs(k))<v*(Math.abs(A)*(Math.abs(o.get(l-1,l-1))+Math.abs(T)+Math.abs(o.get(l+1,l+1)))));)l--;for(i=l+2;i<=b;i++)o.set(i,i-2,0),i>l+2&&o.set(i,i-3,0);for(h=l;h<=b-1&&(y=h!==b-1,h!==l&&(A=o.get(h,h-1),I=o.get(h+1,h-1),k=y?o.get(h+2,h-1):0,c=Math.abs(A)+Math.abs(I)+Math.abs(k),0!==c&&(A/=c,I/=c,k/=c)),0!==c);h++)if(V=Math.sqrt(A*A+I*I+k*k),A<0&&(V=-V),0!==V){for(h!==l?o.set(h,h-1,-V*c):u!==l&&o.set(h,h-1,-o.get(h,h-1)),A+=V,c=A/V,m=I/V,T=k/V,I/=A,k/=A,n=h;n<t;n++)A=o.get(h,n)+I*o.get(h+1,n),y&&(A+=k*o.get(h+2,n),o.set(h+2,n,o.get(h+2,n)-A*T)),o.set(h,n,o.get(h,n)-A*c),o.set(h+1,n,o.get(h+1,n)-A*m);for(i=0;i<=Math.min(b,h+3);i++)A=c*o.get(i,h)+m*o.get(i,h+1),y&&(A+=T*o.get(i,h+2),o.set(i,h+2,o.get(i,h+2)-A*k)),o.set(i,h,o.get(i,h)-A),o.set(i,h+1,o.get(i,h+1)-A*I);for(i=x;i<=E;i++)A=c*s.get(i,h)+m*s.get(i,h+1),y&&(A+=T*s.get(i,h+2),s.set(i,h+2,s.get(i,h+2)-A*k)),s.set(i,h,s.get(i,h)-A),s.set(i,h+1,s.get(i,h+1)-A*I)}}}if(0===R)return;for(b=t-1;b>=0;b--)if(A=r[b],I=e[b],0===I)for(u=b,o.set(b,b,1),i=b-1;i>=0;i--){for(f=o.get(i,i)-A,k=0,n=u;n<=b;n++)k+=o.get(i,n)*o.get(n,b);if(e[i]<0)T=f,V=k;else if(u=i,0===e[i]?o.set(i,b,0!==f?-k/f:-k/(v*R)):(c=o.get(i,i+1),m=o.get(i+1,i),I=(r[i]-A)*(r[i]-A)+e[i]*e[i],a=(c*V-T*k)/I,o.set(i,b,a),o.set(i+1,b,Math.abs(c)>Math.abs(T)?(-k-f*a)/c:(-V-m*a)/T)),a=Math.abs(o.get(i,b)),v*a*a>1)for(n=i;n<=b;n++)o.set(n,b,o.get(n,b)/a)}else if(I<0)for(u=b-1,Math.abs(o.get(b,b-1))>Math.abs(o.get(b-1,b))?(o.set(b-1,b-1,I/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-A)/o.get(b,b-1))):(M=j(0,-o.get(b-1,b),o.get(b-1,b-1)-A,I),o.set(b-1,b-1,M[0]),o.set(b-1,b,M[1])),o.set(b,b-1,0),o.set(b,b,1),i=b-2;i>=0;i--){for(g=0,w=0,n=u;n<=b;n++)g+=o.get(i,n)*o.get(n,b-1),w+=o.get(i,n)*o.get(n,b);if(f=o.get(i,i)-A,e[i]<0)T=f,k=g,V=w;else if(u=i,0===e[i]?(M=j(-g,-w,f,I),o.set(i,b-1,M[0]),o.set(i,b,M[1])):(c=o.get(i,i+1),m=o.get(i+1,i),p=(r[i]-A)*(r[i]-A)+e[i]*e[i]-I*I,d=2*(r[i]-A)*I,0===p&&0===d&&(p=v*R*(Math.abs(f)+Math.abs(I)+Math.abs(c)+Math.abs(m)+Math.abs(T))),M=j(c*k-T*g+I*w,c*V-T*w-I*g,p,d),o.set(i,b-1,M[0]),o.set(i,b,M[1]),Math.abs(c)>Math.abs(T)+Math.abs(I)?(o.set(i+1,b-1,(-g-f*o.get(i,b-1)+I*o.get(i,b))/c),o.set(i+1,b,(-w-f*o.get(i,b)-I*o.get(i,b-1))/c)):(M=j(-k-m*o.get(i,b-1),-V-m*o.get(i,b),T,I),o.set(i+1,b-1,M[0]),o.set(i+1,b,M[1]))),a=Math.max(Math.abs(o.get(i,b-1)),Math.abs(o.get(i,b))),v*a*a>1)for(n=i;n<=b;n++)o.set(n,b-1,o.get(n,b-1)/a),o.set(n,b,o.get(n,b)/a)}for(i=0;i<t;i++)if(i<x||i>E)for(n=i;n<t;n++)s.set(i,n,o.get(i,n));for(n=t-1;n>=x;n--)for(i=x;i<=E;i++){for(T=0,h=x;h<=Math.min(n,E);h++)T+=s.get(i,h)*o.get(h,n);s.set(i,n,T)}}(i,u,h,n,t)}this.n=i,this.e=u,this.d=h,this.V=n}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,s=this.e,o=this.d,i=new v(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)i.set(t,e,0);i.set(t,t,o[t]),s[t]>0?i.set(t,t+1,s[t]):s[t]<0&&i.set(t,t-1,s[t])}return i}}function j(t,e,r,s){let o,i;return Math.abs(r)>Math.abs(s)?(o=s/r,i=r+o*s,[(t+o*e)/i,(e-o*t)/i]):(o=r/s,i=s+o*r,[(o*t+e)/i,(o*e-t)/i])}class ${constructor(t){if(!(t=I.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,s,o=t,i=o.rows,n=new v(i,i),h=!0;for(r=0;r<i;r++){let t=0;for(s=0;s<r;s++){let i=0;for(e=0;e<s;e++)i+=n.get(s,e)*n.get(r,e);i=(o.get(r,s)-i)/n.get(s,s),n.set(r,s,i),t+=i*i}for(t=o.get(r,r)-t,h&=t>0,n.set(r,r,Math.sqrt(Math.max(t,0))),s=r+1;s<i;s++)n.set(r,s,0)}this.L=n,this.positiveDefinite=Boolean(h)}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=I.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(!1===this.isPositiveDefinite())throw new Error("Matrix is not positive definite");let s,o,i,n=t.columns,h=t.clone();for(i=0;i<r;i++)for(o=0;o<n;o++){for(s=0;s<i;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(i,s));h.set(i,o,h.get(i,o)/e.get(i,i))}for(i=r-1;i>=0;i--)for(o=0;o<n;o++){for(s=i+1;s<r;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(s,i));h.set(i,o,h.get(i,o)/e.get(i,i))}return h}get lowerTriangularMatrix(){return this.L}}class L{constructor(t,e={}){t=I.checkMatrix(t);let{Y:r}=e;const{scaleScores:s=!1,maxIterations:o=1e3,terminationCriteria:i=1e-10}=e;let n;if(r){if(r=Array.isArray(r)&&"number"==typeof r[0]?v.columnVector(r):I.checkMatrix(r),!r.isColumnVector()||r.rows!==t.rows)throw new Error("Y must be a column vector of length X.rows");n=r}else n=t.getColumnVector(0);let h,u,l,a,f=1;for(let e=0;e<o&&f>i;e++)l=t.transpose().mmul(n).div(n.transpose().mmul(n).get(0,0)),l=l.div(l.norm()),h=t.mmul(l).div(l.transpose().mmul(l).get(0,0)),e>0&&(f=h.clone().sub(a).pow(2).sum()),a=h.clone(),r?(u=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),u=u.div(u.norm()),n=r.mmul(u).div(u.transpose().mmul(u).get(0,0))):n=h;if(r){let e=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));e=e.div(e.norm());let s=t.clone().sub(h.clone().mmul(e.transpose())),o=n.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),i=r.clone().sub(h.clone().mulS(o.get(0,0)).mmul(u.transpose()));this.t=h,this.p=e.transpose(),this.w=l.transpose(),this.q=u,this.u=n,this.s=h.transpose().mmul(h),this.xResidual=s,this.yResidual=i,this.betas=o}else this.w=l.transpose(),this.s=h.transpose().mmul(h).sqrt(),this.t=s?h.clone().div(this.s.get(0,0)):h,this.xResidual=t.sub(h.mmul(l.transpose()))}}t.AbstractMatrix=x,t.CHO=$,t.CholeskyDecomposition=$,t.EVD=D,t.EigenvalueDecomposition=D,t.LU=k,t.LuDecomposition=k,t.Matrix=v,t.MatrixColumnSelectionView=class extends S{constructor(t,e){e=p(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}},t.MatrixColumnView=class extends S{constructor(t,e){f(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}},t.MatrixFlipColumnView=class extends S{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}},t.MatrixFlipRowView=class extends S{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}},t.MatrixRowSelectionView=class extends S{constructor(t,e){super(t,(e=w(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}},t.MatrixRowView=class extends S{constructor(t,e){a(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}},t.MatrixSelectionView=R,t.MatrixSubView=class extends S{constructor(t,e,r,s,o){d(t,e,r,s,o),super(t,r-e+1,o-s+1),this.startRow=e,this.startColumn=s}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}},t.MatrixTransposeView=class extends S{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}},t.NIPALS=L,t.Nipals=L,t.QR=T,t.QrDecomposition=T,t.SVD=N,t.SingularValueDecomposition=N,t.WrapperMatrix1D=A,t.WrapperMatrix2D=I,t.correlation=function(t,e=t,r={}){t=new v(t);let s=!1;if("object"!=typeof e||v.isMatrix(e)||Array.isArray(e)?e=new v(e):(r=e,e=t,s=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0,scale:i=!0}=r;o&&(t.center("column"),s||e.center("column")),i&&(t.scale("column"),s||e.scale("column"));const n=t.standardDeviation("column",{unbiased:!0}),h=s?n:e.standardDeviation("column",{unbiased:!0}),u=t.transpose().mmul(e);for(let e=0;e<u.rows;e++)for(let r=0;r<u.columns;r++)u.set(e,r,u.get(e,r)*(1/(n[e]*h[r]))*(1/(t.rows-1)));return u},t.covariance=function(t,e=t,r={}){t=new v(t);let s=!1;if("object"!=typeof e||v.isMatrix(e)||Array.isArray(e)?e=new v(e):(r=e,e=t,s=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0}=r;o&&(t=t.center("column"),s||(e=e.center("column")));const i=t.transpose().mmul(e);for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)*(1/(t.rows-1)));return i},t.default=v,t.determinant=function t(e){if((e=v.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,s,o,i;if(2===e.columns)return r=e.get(0,0),s=e.get(0,1),o=e.get(1,0),i=e.get(1,1),r*i-s*o;if(3===e.columns){let i,n,h;return i=new R(e,[1,2],[1,2]),n=new R(e,[1,2],[0,2]),h=new R(e,[1,2],[0,1]),r=e.get(0,0),s=e.get(0,1),o=e.get(0,2),r*t(i)-s*t(n)+o*t(h)}return new k(e).determinant}throw Error("determinant can only be calculated for a square matrix")},t.inverse=function(t,e=!1){return t=I.checkMatrix(t),e?new N(t).inverse():q(t,v.eye(t.rows))},t.linearDependencies=function(t,e={}){const{thresholdValue:r=1e-9,thresholdError:s=1e-9}=e;let o=(t=v.checkMatrix(t)).rows,i=new v(o,o);for(let e=0;e<o;e++){let n=v.columnVector(t.getRow(e)),h=t.subMatrixRow(C(o,e)).transpose(),u=new N(h).solve(n),l=v.sub(n,h.mmul(u)).abs().max();i.setRow(e,F(l,u,e,r,s))}return i},t.pseudoInverse=function(t,e=Number.EPSILON){if((t=v.checkMatrix(t)).isEmpty())return t.transpose();let r=new N(t,{autoTranspose:!0}),s=r.leftSingularVectors,o=r.rightSingularVectors,i=r.diagonal;for(let t=0;t<i.length;t++)Math.abs(i[t])>e?i[t]=1/i[t]:i[t]=0;return o.mmul(v.diag(i).mmul(s.transpose()))},t.solve=q,t.wrap=function(t,e){if(Array.isArray(t))return t[0]&&Array.isArray(t[0])?new I(t):new A(t,e);throw new Error("the argument is not an array")},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mlMatrix={})}(this,(function(t){"use strict";const e=Object.prototype.toString;function r(t){return e.call(t).endsWith("Array]")}function s(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=e.fromIndex,o=void 0===s?0:s,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],u=o+1;u<n;u++)t[u]>h&&(h=t[u]);return h}function o(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=e.fromIndex,o=void 0===s?0:s,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],u=o+1;u<n;u++)t[u]<h&&(h=t[u]);return h}function i(t){var e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!r(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==i.output){if(!r(i.output))throw new TypeError("output option must be an array if specified");e=i.output}else e=new Array(t.length);var n=o(t),h=s(t);if(n===h)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var u=i.min,l=void 0===u?i.autoMinMax?n:0:u,a=i.max,f=void 0===a?i.autoMinMax?h:1:a;if(l>=f)throw new RangeError("min option must be smaller than max option");for(var c=(f-l)/(h-n),m=0;m<t.length;m++)e[m]=(t[m]-n)*c+l;return e}const n=" ".repeat(2),h=" ".repeat(4);function u(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:o=8}=e;return`${t.constructor.name} {\n${n}[\n${h}${function(t,e,r,s){const{rows:o,columns:i}=t,n=Math.min(o,e),u=Math.min(i,r),a=[];for(let e=0;e<n;e++){let r=[];for(let o=0;o<u;o++)r.push(l(t.get(e,o),s));a.push(`${r.join(" ")}`)}u!==i&&(a[a.length-1]+=` ... ${i-r} more columns`);n!==o&&a.push(`... ${o-e} more rows`);return a.join(`\n${h}`)}(t,r,s,o)}\n${n}]\n${n}rows: ${t.rows}\n${n}columns: ${t.columns}\n}`}function l(t,e){const r=String(t);if(r.length<=e)return r.padEnd(e," ");const s=t.toPrecision(e-2);if(s.length<=e)return s;const o=t.toExponential(e-2),i=o.indexOf("e"),n=o.slice(i);return o.slice(0,e-n.length)+n}function a(t,e,r){let s=r?t.rows:t.rows-1;if(e<0||e>s)throw new RangeError("Row index out of range")}function f(t,e,r){let s=r?t.columns:t.columns-1;if(e<0||e>s)throw new RangeError("Column index out of range")}function c(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function m(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function g(t,e,r){return{row:w(t,e),column:p(t,r)}}function w(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for row indices");if(e.some((e=>e<0||e>=t.rows)))throw new RangeError("row indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function p(t,e){if("object"!=typeof e)throw new TypeError("unexpected type for column indices");if(e.some((e=>e<0||e>=t.columns)))throw new RangeError("column indices are out of range");return Array.isArray(e)||(e=Array.from(e)),e}function d(t,e,r,s,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(M("startRow",e),M("endRow",r),M("startColumn",s),M("endColumn",o),e>r||s>o||e<0||e>=t.rows||r<0||r>=t.rows||s<0||s>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function y(t,e=0){let r=[];for(let s=0;s<t;s++)r.push(e);return r}function M(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function b(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class x{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new v(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)s.set(o,t,r[o*e+t]);return s}static rowVector(t){let e=new v(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new v(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new v(t,e)}static ones(t,e){return new v(t,e).fill(1)}static rand(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{random:s=Math.random}=r;let o=new v(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,s());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:s=0,max:o=1e3,random:i=Math.random}=r;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(s>=o)throw new RangeError("min must be smaller than max");let n=o-s,h=new v(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(i()*n);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let s=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<s;t++)o.set(t,t,r);return o}static diag(t,e,r){let s=t.length;void 0===e&&(e=s),void 0===r&&(r=e);let o=Math.min(s,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new v(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new this(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return x.isMatrix(t)?t:new v(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,s=!0,o=!1;for(;t<this.rows&&s;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(s=!1,o=!0);t++}return s}isReducedEchelonForm(){let t=0,e=0,r=-1,s=!0,o=!1;for(;t<this.rows&&s;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(s=!1,o=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(s=!1);t++}return s}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let s=e;for(let o=e;o<t.rows;o++)t.get(o,r)>t.get(s,r)&&(s=o);if(0===t.get(s,r))r++;else{t.swapRows(e,s);let o=t.get(e,r);for(let s=r;s<t.columns;s++)t.set(e,s,t.get(e,s)/o);for(let s=e+1;s<t.rows;s++){let o=t.get(s,r)/t.get(e,r);t.set(s,r,0);for(let i=r+1;i<t.columns;i++)t.set(s,i,t.get(s,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,s=r-1;for(;s>=0;)if(0===t.maxRow(s))s--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(s,o)?i=!0:o++;for(let r=0;r<s;r++){let i=t.get(r,o);for(let n=o;n<e;n++){let e=t.get(r,n)-i*t.get(s,n);t.set(r,n,e)}}s--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let s=new v(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)s.setSubMatrix(this,this.rows*t,this.columns*e);return s}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){a(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return v.rowVector(this.getRow(t))}setRow(t,e){a(this,t),e=c(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){a(this,t),a(this,e);for(let r=0;r<this.columns;r++){let s=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,s)}return this}getColumn(t){f(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return v.columnVector(this.getColumn(t))}setColumn(t,e){f(this,t),e=m(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){f(this,t),f(this,e);for(let r=0;r<this.rows;r++){let s=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,s)}return this}addRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=c(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){a(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){f(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(){if(this.isEmpty())return NaN;let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}maxIndex(){b(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let s=0;s<this.columns;s++)this.get(r,s)>t&&(t=this.get(r,s),e[0]=r,e[1]=s);return e}min(){if(this.isEmpty())return NaN;let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t&&(t=this.get(e,r));return t}minIndex(){b(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let s=0;s<this.columns;s++)this.get(r,s)<t&&(t=this.get(r,s),e[0]=r,e[1]=s);return e}maxRow(t){if(a(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){a(this,t),b(this);let e=this.get(t,0),r=[t,0];for(let s=1;s<this.columns;s++)this.get(t,s)>e&&(e=this.get(t,s),r[1]=s);return r}minRow(t){if(a(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){a(this,t),b(this);let e=this.get(t,0),r=[t,0];for(let s=1;s<this.columns;s++)this.get(t,s)<e&&(e=this.get(t,s),r[1]=s);return r}maxColumn(t){if(f(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){f(this,t),b(this);let e=this.get(0,t),r=[0,t];for(let s=1;s<this.rows;s++)this.get(s,t)>e&&(e=this.get(s,t),r[0]=s);return r}minColumn(t){if(f(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){f(this,t),b(this);let e=this.get(0,t),r=[0,t];for(let s=1;s<this.rows;s++)this.get(s,t)<e&&(e=this.get(s,t),r[0]=s);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){x.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let s=0;s<e.length;s++)r+=e[s]*t[s];return r}mmul(t){t=v.checkMatrix(t);let e=this.rows,r=this.columns,s=t.columns,o=new v(e,s),i=new Float64Array(r);for(let n=0;n<s;n++){for(let e=0;e<r;e++)i[e]=t.get(e,n);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*i[s];o.set(t,n,e)}}return o}strassen2x2(t){t=v.checkMatrix(t);let e=new v(2,2);const r=this.get(0,0),s=t.get(0,0),o=this.get(0,1),i=t.get(0,1),n=this.get(1,0),h=t.get(1,0),u=this.get(1,1),l=t.get(1,1),a=(r+u)*(s+l),f=(n+u)*s,c=r*(i-l),m=u*(h-s),g=(r+o)*l,w=a+m-g+(o-u)*(h+l),p=c+g,d=f+m,y=a-f+c+(n-r)*(s+i);return e.set(0,0,w),e.set(0,1,p),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=v.checkMatrix(t);let e=new v(3,3);const r=this.get(0,0),s=this.get(0,1),o=this.get(0,2),i=this.get(1,0),n=this.get(1,1),h=this.get(1,2),u=this.get(2,0),l=this.get(2,1),a=this.get(2,2),f=t.get(0,0),c=t.get(0,1),m=t.get(0,2),g=t.get(1,0),w=t.get(1,1),p=t.get(1,2),d=t.get(2,0),y=t.get(2,1),M=t.get(2,2),b=(r-i)*(-c+w),x=(-r+i+n)*(f-c+w),E=(i+n)*(-f+c),S=r*f,R=(-r+u+l)*(f-m+p),A=(-r+u)*(m-p),k=(u+l)*(-f+m),I=(-o+l+a)*(w+d-y),V=(o-a)*(w-y),T=o*d,N=(l+a)*(-d+y),q=(-o+n+h)*(p+d-M),C=(o-h)*(p-M),F=(n+h)*(-d+M),D=S+T+s*g,j=(r+s+o-i-n-l-a)*w+x+E+S+I+T+N,$=S+R+k+(r+s+o-n-h-u-l)*p+T+q+F,P=b+n*(-f+c+g-w-p-d+M)+x+S+T+q+C,L=b+x+E+S+h*y,z=T+q+C+F+i*m,U=S+R+A+l*(-f+m+g-w-p-d+y)+I+V+T,O=I+V+T+N+u*c,_=S+R+A+k+a*M;return e.set(0,0,D),e.set(0,1,j),e.set(0,2,$),e.set(1,0,P),e.set(1,1,L),e.set(1,2,z),e.set(2,0,U),e.set(2,1,O),e.set(2,2,_),e}mmulStrassen(t){t=v.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,o=t.rows,i=t.columns;function n(t,e,r){let s=t.rows,o=t.columns;if(s===e&&o===r)return t;{let s=x.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==o&&console.warn(`Multiplying ${r} x ${s} and ${o} x ${i} matrix: dimensions do not match.`);let h=Math.max(r,o),u=Math.max(s,i);return e=n(e,h,u),function t(e,r,s,o){if(s<=512||o<=512)return e.mmul(r);s%2==1&&o%2==1?(e=n(e,s+1,o+1),r=n(r,s+1,o+1)):s%2==1?(e=n(e,s+1,o),r=n(r,s+1,o)):o%2==1&&(e=n(e,s,o+1),r=n(r,s,o+1));let i=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),u=e.subMatrix(0,i-1,0,h-1),l=r.subMatrix(0,i-1,0,h-1),a=e.subMatrix(0,i-1,h,e.columns-1),f=r.subMatrix(0,i-1,h,r.columns-1),c=e.subMatrix(i,e.rows-1,0,h-1),m=r.subMatrix(i,r.rows-1,0,h-1),g=e.subMatrix(i,e.rows-1,h,e.columns-1),w=r.subMatrix(i,r.rows-1,h,r.columns-1),p=t(x.add(u,g),x.add(l,w),i,h),d=t(x.add(c,g),l,i,h),y=t(u,x.sub(f,w),i,h),M=t(g,x.sub(m,l),i,h),b=t(x.add(u,a),w,i,h),E=t(x.sub(c,u),x.add(l,f),i,h),v=t(x.sub(a,g),x.add(m,w),i,h),S=x.add(p,M);S.sub(b),S.add(v);let R=x.add(y,b),A=x.add(d,M),k=x.sub(p,d);k.add(y),k.add(E);let I=x.zeros(2*S.rows,2*S.columns);return I=I.setSubMatrix(S,0,0),I=I.setSubMatrix(R,S.rows,0),I=I.setSubMatrix(A,0,S.columns),I=I.setSubMatrix(k,S.rows,S.columns),I.subMatrix(0,s-1,0,o-1)}(e,t=n(t,h,u),h,u)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new v(this.rows,this.columns);for(let t=0;t<this.rows;t++){const o=this.getRow(t);o.length>0&&i(o,{min:e,max:r,output:o}),s.setRow(t,o)}return s}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new v(this.rows,this.columns);for(let t=0;t<this.columns;t++){const o=this.getColumn(t);o.length&&i(o,{min:e,max:r,output:o}),s.setColumn(t,o)}return s}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=v.checkMatrix(t);let e=this.rows,r=this.columns,s=t.rows,o=t.columns,i=new v(e*s,r*o);for(let n=0;n<e;n++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<o;h++)i.set(s*n+r,o*e+h,this.get(n,e)*t.get(r,h));return i}kroneckerSum(t){if(t=v.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,s=this.kroneckerProduct(v.eye(r,r)),o=v.eye(e,e).kroneckerProduct(t);return s.add(o)}transpose(){let t=new v(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=E){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=E){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,s){d(this,t,e,r,s);let o=new v(e-t+1,s-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=s;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let s=new v(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);s.set(o,i-e,this.get(t[o],i))}return s}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let s=new v(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);s.set(i-e,o,this.get(i,t[o]))}return s}setSubMatrix(t,e,r){if((t=v.checkMatrix(t)).isEmpty())return this;d(this,e,e+t.rows-1,r,r+t.columns-1);for(let s=0;s<t.rows;s++)for(let o=0;o<t.columns;o++)this.set(e+s,r+o,t.get(s,o));return this}selection(t,e){let r=g(this,t,e),s=new v(t.length,e.length);for(let t=0;t<r.row.length;t++){let e=r.row[t];for(let o=0;o<r.column.length;o++){let i=r.column[o];s.set(t,o,this.get(e,i))}}return s}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new v(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=y(t.rows);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[r]+=t.get(r,s);return e}(this);case"column":return function(t){let e=y(t.columns);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[s]+=t.get(r,s);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)e+=t.get(r,s);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=y(t.rows,1);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[r]*=t.get(r,s);return e}(this);case"column":return function(t){let e=y(t.columns,1);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[s]*=t.get(r,s);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)e*=t.get(r,s);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:s=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!Array.isArray(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,i=[];for(let n=0;n<s;n++){let s=0,h=0,u=0;for(let e=0;e<o;e++)u=t.get(n,e)-r[n],s+=u,h+=u*u;e?i.push((h-s*s/o)/(o-1)):i.push((h-s*s/o)/o)}return i}(this,r,s);case"column":if(!Array.isArray(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,i=[];for(let n=0;n<o;n++){let o=0,h=0,u=0;for(let e=0;e<s;e++)u=t.get(e,n)-r[n],o+=u,h+=u*u;e?i.push((h-o*o/s)/(s-1)):i.push((h-o*o/s)/s)}return i}(this,r,s);case void 0:if("number"!=typeof s)throw new TypeError("mean must be a number");return function(t,e,r){const s=t.rows,o=t.columns,i=s*o;let n=0,h=0,u=0;for(let e=0;e<s;e++)for(let s=0;s<o;s++)u=t.get(e,s)-r,n+=u,h+=u*u;return e?(h-n*n/i)/(i-1):(h-n*n/i)/i}(this,r,s);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!Array.isArray(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e[r])}(this,r),this;case"column":if(!Array.isArray(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e[s])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let s=0;for(let e=0;e<t.columns;e++)s+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(s))}return e}(this);else if(!Array.isArray(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let s=0;for(let e=0;e<t.rows;e++)s+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(s))}return e}(this);else if(!Array.isArray(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e[s])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let s=0;s<t.columns;s++)for(let o=0;o<t.rows;o++)r+=Math.pow(t.get(o,s),2)/e;return Math.sqrt(r)}(this);else if("number"!=typeof r)throw new TypeError("scale must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return u(this,t)}}function E(t,e){return t-e}x.prototype.klass="Matrix","undefined"!=typeof Symbol&&(x.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return u(this)}),x.random=x.rand,x.randomInt=x.randInt,x.diagonal=x.diag,x.prototype.diagonal=x.prototype.diag,x.identity=x.eye,x.prototype.negate=x.prototype.neg,x.prototype.tensorProduct=x.prototype.kroneckerProduct;class v extends x{constructor(t,e){if(super(),v.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!Array.isArray(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<t;s++){if(r[s].length!==e)throw new RangeError("Inconsistent array dimensions");this.data.push(Float64Array.from(r[s]))}}}this.rows=t,this.columns=e}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}removeRow(t){return a(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),a(this,t,!0),e=Float64Array.from(c(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){f(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let s=0;s<t;s++)r[s]=this.data[e][s];for(let s=t+1;s<this.columns;s++)r[s-1]=this.data[e][s];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),f(this,t,!0),e=m(this,e);for(let r=0;r<this.rows;r++){const s=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)s[o]=this.data[r][o];for(s[o++]=e[r];o<this.columns+1;o++)s[o]=this.data[r][o-1];this.data[r]=s}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(x,v);class S extends x{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class R extends S{constructor(t,e,r){let s=g(t,e,r);super(t,s.row.length,s.column.length),this.rowIndices=s.row,this.columnIndices=s.column}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class A extends x{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!=0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let s=this._calculateIndex(t,e);return this.data[s]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class k extends x{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}class I{constructor(t){let e,r,s,o,i,n,h,u,l,a=(t=k.checkMatrix(t)).clone(),f=a.rows,c=a.columns,m=new Float64Array(f),g=1;for(e=0;e<f;e++)m[e]=e;for(u=new Float64Array(f),r=0;r<c;r++){for(e=0;e<f;e++)u[e]=a.get(e,r);for(e=0;e<f;e++){for(l=Math.min(e,r),i=0,s=0;s<l;s++)i+=a.get(e,s)*u[s];u[e]-=i,a.set(e,r,u[e])}for(o=r,e=r+1;e<f;e++)Math.abs(u[e])>Math.abs(u[o])&&(o=e);if(o!==r){for(s=0;s<c;s++)n=a.get(o,s),a.set(o,s,a.get(r,s)),a.set(r,s,n);h=m[o],m[o]=m[r],m[r]=h,g=-g}if(r<f&&0!==a.get(r,r))for(e=r+1;e<f;e++)a.set(e,r,a.get(e,r)/a.get(r,r))}this.LU=a,this.pivotVector=m,this.pivotSign=g}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=v.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let r,s,o,i=t.columns,n=t.subMatrixRow(this.pivotVector,0,i-1),h=e.columns;for(o=0;o<h;o++)for(r=o+1;r<h;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o));for(o=h-1;o>=0;o--){for(s=0;s<i;s++)n.set(o,s,n.get(o,s)/e.get(o,o));for(r=0;r<o;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o))}return n}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let s=0;s<r;s++)e*=t.get(s,s);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new v(e,r);for(let o=0;o<e;o++)for(let e=0;e<r;e++)o>e?s.set(o,e,t.get(o,e)):o===e?s.set(o,e,1):s.set(o,e,0);return s}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new v(e,r);for(let o=0;o<e;o++)for(let e=0;e<r;e++)o<=e?s.set(o,e,t.get(o,e)):s.set(o,e,0);return s}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function V(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class T{constructor(t){let e,r,s,o,i=(t=k.checkMatrix(t)).clone(),n=t.rows,h=t.columns,u=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<n;e++)t=V(t,i.get(e,s));if(0!==t){for(i.get(s,s)<0&&(t=-t),e=s;e<n;e++)i.set(e,s,i.get(e,s)/t);for(i.set(s,s,i.get(s,s)+1),r=s+1;r<h;r++){for(o=0,e=s;e<n;e++)o+=i.get(e,s)*i.get(e,r);for(o=-o/i.get(s,s),e=s;e<n;e++)i.set(e,r,i.get(e,r)+o*i.get(e,s))}}u[s]=-t}this.QR=i,this.Rdiag=u}solve(t){t=v.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let s,o,i,n,h=t.columns,u=t.clone(),l=e.columns;for(i=0;i<l;i++)for(o=0;o<h;o++){for(n=0,s=i;s<r;s++)n+=e.get(s,i)*u.get(s,o);for(n=-n/e.get(i,i),s=i;s<r;s++)u.set(s,o,u.get(s,o)+n*e.get(s,i))}for(i=l-1;i>=0;i--){for(o=0;o<h;o++)u.set(i,o,u.get(i,o)/this.Rdiag[i]);for(s=0;s<i;s++)for(o=0;o<h;o++)u.set(s,o,u.get(s,o)-u.get(i,o)*e.get(s,i))}return u.subMatrix(0,l-1,0,h-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,s=r.columns,o=new v(s,s);for(t=0;t<s;t++)for(e=0;e<s;e++)t<e?o.set(t,e,r.get(t,e)):t===e?o.set(t,e,this.Rdiag[t]):o.set(t,e,0);return o}get orthogonalMatrix(){let t,e,r,s,o=this.QR,i=o.rows,n=o.columns,h=new v(i,n);for(r=n-1;r>=0;r--){for(t=0;t<i;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<n;e++)if(0!==o.get(r,r)){for(s=0,t=r;t<i;t++)s+=o.get(t,r)*h.get(t,e);for(s=-s/o.get(r,r),t=r;t<i;t++)h.set(t,e,h.get(t,e)+s*o.get(t,r))}}return h}}class N{constructor(t,e={}){if((t=k.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:n=!1}=e;let h,u=Boolean(o),l=Boolean(i),a=!1;if(r<s)if(n){h=t.transpose(),r=h.rows,s=h.columns,a=!0;let e=u;u=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let f=Math.min(r,s),c=Math.min(r+1,s),m=new Float64Array(c),g=new v(r,f),w=new v(s,s),p=new Float64Array(s),d=new Float64Array(r),y=new Float64Array(c);for(let t=0;t<c;t++)y[t]=t;let M=Math.min(r-1,s),b=Math.max(0,Math.min(s-2,r)),x=Math.max(M,b);for(let t=0;t<x;t++){if(t<M){m[t]=0;for(let e=t;e<r;e++)m[t]=V(m[t],h.get(e,t));if(0!==m[t]){h.get(t,t)<0&&(m[t]=-m[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/m[t]);h.set(t,t,h.get(t,t)+1)}m[t]=-m[t]}for(let e=t+1;e<s;e++){if(t<M&&0!==m[t]){let s=0;for(let o=t;o<r;o++)s+=h.get(o,t)*h.get(o,e);s=-s/h.get(t,t);for(let o=t;o<r;o++)h.set(o,e,h.get(o,e)+s*h.get(o,t))}p[e]=h.get(t,e)}if(u&&t<M)for(let e=t;e<r;e++)g.set(e,t,h.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<s;e++)p[t]=V(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<s;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)d[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<s;r++)d[e]+=p[r]*h.get(e,r);for(let e=t+1;e<s;e++){let s=-p[e]/p[t+1];for(let o=t+1;o<r;o++)h.set(o,e,h.get(o,e)+s*d[o])}}if(l)for(let e=t+1;e<s;e++)w.set(e,t,p[e])}}let E=Math.min(s,r+1);if(M<s&&(m[M]=h.get(M,M)),r<E&&(m[E-1]=0),b+1<E&&(p[b]=h.get(b,E-1)),p[E-1]=0,u){for(let t=M;t<f;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=M-1;t>=0;t--)if(0!==m[t]){for(let e=t+1;e<f;e++){let s=0;for(let o=t;o<r;o++)s+=g.get(o,t)*g.get(o,e);s=-s/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+s*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(l)for(let t=s-1;t>=0;t--){if(t<b&&0!==p[t])for(let e=t+1;e<s;e++){let r=0;for(let o=t+1;o<s;o++)r+=w.get(o,t)*w.get(o,e);r=-r/w.get(t+1,t);for(let o=t+1;o<s;o++)w.set(o,e,w.get(o,e)+r*w.get(o,t))}for(let e=0;e<s;e++)w.set(e,t,0);w.set(t,t,1)}let S=E-1,R=Number.EPSILON;for(;E>0;){let t,e;for(t=E-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+R*Math.abs(m[t]+Math.abs(m[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===E-2)e=4;else{let r;for(r=E-1;r>=t&&r!==t;r--){let e=(r!==E?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(m[r])<=R*e){m[r]=0;break}}r===t?e=3:r===E-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[E-2];p[E-2]=0;for(let r=E-2;r>=t;r--){let o=V(m[r],e),i=m[r]/o,n=e/o;if(m[r]=o,r!==t&&(e=-n*p[r-1],p[r-1]=i*p[r-1]),l)for(let t=0;t<s;t++)o=i*w.get(t,r)+n*w.get(t,E-1),w.set(t,E-1,-n*w.get(t,r)+i*w.get(t,E-1)),w.set(t,r,o)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let s=t;s<E;s++){let o=V(m[s],e),i=m[s]/o,n=e/o;if(m[s]=o,e=-n*p[s],p[s]=i*p[s],u)for(let e=0;e<r;e++)o=i*g.get(e,s)+n*g.get(e,t-1),g.set(e,t-1,-n*g.get(e,s)+i*g.get(e,t-1)),g.set(e,s,o)}break}case 3:{const e=Math.max(Math.abs(m[E-1]),Math.abs(m[E-2]),Math.abs(p[E-2]),Math.abs(m[t]),Math.abs(p[t])),o=m[E-1]/e,i=m[E-2]/e,n=p[E-2]/e,h=m[t]/e,a=p[t]/e,f=((i+o)*(i-o)+n*n)/2,c=o*n*(o*n);let d=0;0===f&&0===c||(d=f<0?0-Math.sqrt(f*f+c):Math.sqrt(f*f+c),d=c/(f+d));let y=(h+o)*(h-o)+d,M=h*a;for(let e=t;e<E-1;e++){let o=V(y,M);0===o&&(o=Number.MIN_VALUE);let i=y/o,n=M/o;if(e!==t&&(p[e-1]=o),y=i*m[e]+n*p[e],p[e]=i*p[e]-n*m[e],M=n*m[e+1],m[e+1]=i*m[e+1],l)for(let t=0;t<s;t++)o=i*w.get(t,e)+n*w.get(t,e+1),w.set(t,e+1,-n*w.get(t,e)+i*w.get(t,e+1)),w.set(t,e,o);if(o=V(y,M),0===o&&(o=Number.MIN_VALUE),i=y/o,n=M/o,m[e]=o,y=i*p[e]+n*m[e+1],m[e+1]=-n*p[e]+i*m[e+1],M=n*p[e+1],p[e+1]=i*p[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+n*g.get(t,e+1),g.set(t,e+1,-n*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}p[E-2]=y;break}case 4:if(m[t]<=0&&(m[t]=m[t]<0?-m[t]:0,l))for(let e=0;e<=S;e++)w.set(e,t,-w.get(e,t));for(;t<S&&!(m[t]>=m[t+1]);){let e=m[t];if(m[t]=m[t+1],m[t+1]=e,l&&t<s-1)for(let r=0;r<s;r++)e=w.get(r,t+1),w.set(r,t+1,w.get(r,t)),w.set(r,t,e);if(u&&t<r-1)for(let s=0;s<r;s++)e=g.get(s,t+1),g.set(s,t+1,g.get(s,t)),g.set(s,t,e);t++}E--}}if(a){let t=w;w=g,g=t}this.m=r,this.n=s,this.s=m,this.U=g,this.V=w}solve(t){let e=t,r=this.threshold,s=this.s.length,o=v.zeros(s,s);for(let t=0;t<s;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let i=this.U,n=this.rightSingularVectors,h=n.mmul(o),u=n.rows,l=i.rows,a=v.zeros(u,l);for(let t=0;t<u;t++)for(let e=0;e<l;e++){let r=0;for(let o=0;o<s;o++)r+=h.get(t,o)*i.get(e,o);a.set(t,e,r)}return a.mmul(e)}solveForDiagonal(t){return this.solve(v.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,s=t.columns,o=new v(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,n=i.rows,h=i.columns,u=new v(r,n);for(let t=0;t<r;t++)for(let e=0;e<n;e++){let r=0;for(let s=0;s<h;s++)r+=o.get(t,s)*i.get(e,s);u.set(t,e,r)}return u}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let s=0,o=r.length;s<o;s++)r[s]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return v.diag(this.s)}}function q(t,e,r=!1){return t=k.checkMatrix(t),e=k.checkMatrix(e),r?new N(t).solve(e):t.isSquare()?new I(t).solve(e):new T(t).solve(e)}function C(t,e){let r=[];for(let s=0;s<t;s++)s!==e&&r.push(s);return r}function F(t,e,r,s=1e-9,o=1e-9){if(t>o)return new Array(e.rows+1).fill(0);{let t=e.addRow(r,[0]);for(let e=0;e<t.rows;e++)Math.abs(t.get(e,0))<s&&t.set(e,0,0);return t.to1DArray()}}class D{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=k.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let s,o,i=t.columns,n=new v(i,i),h=new Float64Array(i),u=new Float64Array(i),l=t,a=!1;if(a=!!r||t.isSymmetric(),a){for(s=0;s<i;s++)for(o=0;o<i;o++)n.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,u,l,a,f;for(u=0;u<t;u++)r[u]=s.get(t-1,u);for(h=t-1;h>0;h--){for(f=0,n=0,l=0;l<h;l++)f+=Math.abs(r[l]);if(0===f)for(e[h]=r[h-1],u=0;u<h;u++)r[u]=s.get(h-1,u),s.set(h,u,0),s.set(u,h,0);else{for(l=0;l<h;l++)r[l]/=f,n+=r[l]*r[l];for(o=r[h-1],i=Math.sqrt(n),o>0&&(i=-i),e[h]=f*i,n-=o*i,r[h-1]=o-i,u=0;u<h;u++)e[u]=0;for(u=0;u<h;u++){for(o=r[u],s.set(u,h,o),i=e[u]+s.get(u,u)*o,l=u+1;l<=h-1;l++)i+=s.get(l,u)*r[l],e[l]+=s.get(l,u)*o;e[u]=i}for(o=0,u=0;u<h;u++)e[u]/=n,o+=e[u]*r[u];for(a=o/(n+n),u=0;u<h;u++)e[u]-=a*r[u];for(u=0;u<h;u++){for(o=r[u],i=e[u],l=u;l<=h-1;l++)s.set(l,u,s.get(l,u)-(o*e[l]+i*r[l]));r[u]=s.get(h-1,u),s.set(h,u,0)}}r[h]=n}for(h=0;h<t-1;h++){if(s.set(t-1,h,s.get(h,h)),s.set(h,h,1),n=r[h+1],0!==n){for(l=0;l<=h;l++)r[l]=s.get(l,h+1)/n;for(u=0;u<=h;u++){for(i=0,l=0;l<=h;l++)i+=s.get(l,h+1)*s.get(l,u);for(l=0;l<=h;l++)s.set(l,u,s.get(l,u)-i*r[l])}}for(l=0;l<=h;l++)s.set(l,h+1,0)}for(u=0;u<t;u++)r[u]=s.get(t-1,u),s.set(t-1,u,0);s.set(t-1,t-1,1),e[0]=0}(i,u,h,n),function(t,e,r,s){let o,i,n,h,u,l,a,f,c,m,g,w,p,d,y,M;for(n=1;n<t;n++)e[n-1]=e[n];e[t-1]=0;let b=0,x=0,E=Number.EPSILON;for(l=0;l<t;l++){for(x=Math.max(x,Math.abs(r[l])+Math.abs(e[l])),a=l;a<t&&!(Math.abs(e[a])<=E*x);)a++;if(a>l)do{for(o=r[l],f=(r[l+1]-o)/(2*e[l]),c=V(f,1),f<0&&(c=-c),r[l]=e[l]/(f+c),r[l+1]=e[l]*(f+c),m=r[l+1],i=o-r[l],n=l+2;n<t;n++)r[n]-=i;for(b+=i,f=r[a],g=1,w=g,p=g,d=e[l+1],y=0,M=0,n=a-1;n>=l;n--)for(p=w,w=g,M=y,o=g*e[n],i=g*f,c=V(f,e[n]),e[n+1]=y*c,y=e[n]/c,g=f/c,f=g*r[n]-y*o,r[n+1]=i+y*(g*o+y*r[n]),u=0;u<t;u++)i=s.get(u,n+1),s.set(u,n+1,y*s.get(u,n)+g*i),s.set(u,n,g*s.get(u,n)-y*i);f=-y*M*p*d*e[l]/m,e[l]=y*f,r[l]=g*f}while(Math.abs(e[l])>E*x);r[l]=r[l]+b,e[l]=0}for(n=0;n<t-1;n++){for(u=n,f=r[n],h=n+1;h<t;h++)r[h]<f&&(u=h,f=r[h]);if(u!==n)for(r[u]=r[n],r[n]=f,h=0;h<t;h++)f=s.get(h,n),s.set(h,n,s.get(h,u)),s.set(h,u,f)}}(i,u,h,n)}else{let t=new v(i,i),e=new Float64Array(i);for(o=0;o<i;o++)for(s=0;s<i;s++)t.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,u,l,a,f=0,c=t-1;for(l=f+1;l<=c-1;l++){for(a=0,h=l;h<=c;h++)a+=Math.abs(e.get(h,l-1));if(0!==a){for(n=0,h=c;h>=l;h--)r[h]=e.get(h,l-1)/a,n+=r[h]*r[h];for(i=Math.sqrt(n),r[l]>0&&(i=-i),n-=r[l]*i,r[l]=r[l]-i,u=l;u<t;u++){for(o=0,h=c;h>=l;h--)o+=r[h]*e.get(h,u);for(o/=n,h=l;h<=c;h++)e.set(h,u,e.get(h,u)-o*r[h])}for(h=0;h<=c;h++){for(o=0,u=c;u>=l;u--)o+=r[u]*e.get(h,u);for(o/=n,u=l;u<=c;u++)e.set(h,u,e.get(h,u)-o*r[u])}r[l]=a*r[l],e.set(l,l-1,a*i)}}for(h=0;h<t;h++)for(u=0;u<t;u++)s.set(h,u,h===u?1:0);for(l=c-1;l>=f+1;l--)if(0!==e.get(l,l-1)){for(h=l+1;h<=c;h++)r[h]=e.get(h,l-1);for(u=l;u<=c;u++){for(i=0,h=l;h<=c;h++)i+=r[h]*s.get(h,u);for(i=i/r[l]/e.get(l,l-1),h=l;h<=c;h++)s.set(h,u,s.get(h,u)+i*r[h])}}}(i,t,e,n),function(t,e,r,s,o){let i,n,h,u,l,a,f,c,m,g,w,p,d,y,M,b=t-1,x=0,E=t-1,v=Number.EPSILON,S=0,R=0,A=0,k=0,I=0,V=0,T=0,N=0;for(i=0;i<t;i++)for((i<x||i>E)&&(r[i]=o.get(i,i),e[i]=0),n=Math.max(i-1,0);n<t;n++)R+=Math.abs(o.get(i,n));for(;b>=x;){for(u=b;u>x&&(V=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)),0===V&&(V=R),!(Math.abs(o.get(u,u-1))<v*V));)u--;if(u===b)o.set(b,b,o.get(b,b)+S),r[b]=o.get(b,b),e[b]=0,b--,N=0;else if(u===b-1){if(f=o.get(b,b-1)*o.get(b-1,b),A=(o.get(b-1,b-1)-o.get(b,b))/2,k=A*A+f,T=Math.sqrt(Math.abs(k)),o.set(b,b,o.get(b,b)+S),o.set(b-1,b-1,o.get(b-1,b-1)+S),c=o.get(b,b),k>=0){for(T=A>=0?A+T:A-T,r[b-1]=c+T,r[b]=r[b-1],0!==T&&(r[b]=c-f/T),e[b-1]=0,e[b]=0,c=o.get(b,b-1),V=Math.abs(c)+Math.abs(T),A=c/V,k=T/V,I=Math.sqrt(A*A+k*k),A/=I,k/=I,n=b-1;n<t;n++)T=o.get(b-1,n),o.set(b-1,n,k*T+A*o.get(b,n)),o.set(b,n,k*o.get(b,n)-A*T);for(i=0;i<=b;i++)T=o.get(i,b-1),o.set(i,b-1,k*T+A*o.get(i,b)),o.set(i,b,k*o.get(i,b)-A*T);for(i=x;i<=E;i++)T=s.get(i,b-1),s.set(i,b-1,k*T+A*s.get(i,b)),s.set(i,b,k*s.get(i,b)-A*T)}else r[b-1]=c+A,r[b]=c+A,e[b-1]=T,e[b]=-T;b-=2,N=0}else{if(c=o.get(b,b),m=0,f=0,u<b&&(m=o.get(b-1,b-1),f=o.get(b,b-1)*o.get(b-1,b)),10===N){for(S+=c,i=x;i<=b;i++)o.set(i,i,o.get(i,i)-c);V=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2)),c=m=.75*V,f=-.4375*V*V}if(30===N&&(V=(m-c)/2,V=V*V+f,V>0)){for(V=Math.sqrt(V),m<c&&(V=-V),V=c-f/((m-c)/2+V),i=x;i<=b;i++)o.set(i,i,o.get(i,i)-V);S+=V,c=m=f=.964}for(N+=1,l=b-2;l>=u&&(T=o.get(l,l),I=c-T,V=m-T,A=(I*V-f)/o.get(l+1,l)+o.get(l,l+1),k=o.get(l+1,l+1)-T-I-V,I=o.get(l+2,l+1),V=Math.abs(A)+Math.abs(k)+Math.abs(I),A/=V,k/=V,I/=V,l!==u)&&!(Math.abs(o.get(l,l-1))*(Math.abs(k)+Math.abs(I))<v*(Math.abs(A)*(Math.abs(o.get(l-1,l-1))+Math.abs(T)+Math.abs(o.get(l+1,l+1)))));)l--;for(i=l+2;i<=b;i++)o.set(i,i-2,0),i>l+2&&o.set(i,i-3,0);for(h=l;h<=b-1&&(y=h!==b-1,h!==l&&(A=o.get(h,h-1),k=o.get(h+1,h-1),I=y?o.get(h+2,h-1):0,c=Math.abs(A)+Math.abs(k)+Math.abs(I),0!==c&&(A/=c,k/=c,I/=c)),0!==c);h++)if(V=Math.sqrt(A*A+k*k+I*I),A<0&&(V=-V),0!==V){for(h!==l?o.set(h,h-1,-V*c):u!==l&&o.set(h,h-1,-o.get(h,h-1)),A+=V,c=A/V,m=k/V,T=I/V,k/=A,I/=A,n=h;n<t;n++)A=o.get(h,n)+k*o.get(h+1,n),y&&(A+=I*o.get(h+2,n),o.set(h+2,n,o.get(h+2,n)-A*T)),o.set(h,n,o.get(h,n)-A*c),o.set(h+1,n,o.get(h+1,n)-A*m);for(i=0;i<=Math.min(b,h+3);i++)A=c*o.get(i,h)+m*o.get(i,h+1),y&&(A+=T*o.get(i,h+2),o.set(i,h+2,o.get(i,h+2)-A*I)),o.set(i,h,o.get(i,h)-A),o.set(i,h+1,o.get(i,h+1)-A*k);for(i=x;i<=E;i++)A=c*s.get(i,h)+m*s.get(i,h+1),y&&(A+=T*s.get(i,h+2),s.set(i,h+2,s.get(i,h+2)-A*I)),s.set(i,h,s.get(i,h)-A),s.set(i,h+1,s.get(i,h+1)-A*k)}}}if(0===R)return;for(b=t-1;b>=0;b--)if(A=r[b],k=e[b],0===k)for(u=b,o.set(b,b,1),i=b-1;i>=0;i--){for(f=o.get(i,i)-A,I=0,n=u;n<=b;n++)I+=o.get(i,n)*o.get(n,b);if(e[i]<0)T=f,V=I;else if(u=i,0===e[i]?o.set(i,b,0!==f?-I/f:-I/(v*R)):(c=o.get(i,i+1),m=o.get(i+1,i),k=(r[i]-A)*(r[i]-A)+e[i]*e[i],a=(c*V-T*I)/k,o.set(i,b,a),o.set(i+1,b,Math.abs(c)>Math.abs(T)?(-I-f*a)/c:(-V-m*a)/T)),a=Math.abs(o.get(i,b)),v*a*a>1)for(n=i;n<=b;n++)o.set(n,b,o.get(n,b)/a)}else if(k<0)for(u=b-1,Math.abs(o.get(b,b-1))>Math.abs(o.get(b-1,b))?(o.set(b-1,b-1,k/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-A)/o.get(b,b-1))):(M=j(0,-o.get(b-1,b),o.get(b-1,b-1)-A,k),o.set(b-1,b-1,M[0]),o.set(b-1,b,M[1])),o.set(b,b-1,0),o.set(b,b,1),i=b-2;i>=0;i--){for(g=0,w=0,n=u;n<=b;n++)g+=o.get(i,n)*o.get(n,b-1),w+=o.get(i,n)*o.get(n,b);if(f=o.get(i,i)-A,e[i]<0)T=f,I=g,V=w;else if(u=i,0===e[i]?(M=j(-g,-w,f,k),o.set(i,b-1,M[0]),o.set(i,b,M[1])):(c=o.get(i,i+1),m=o.get(i+1,i),p=(r[i]-A)*(r[i]-A)+e[i]*e[i]-k*k,d=2*(r[i]-A)*k,0===p&&0===d&&(p=v*R*(Math.abs(f)+Math.abs(k)+Math.abs(c)+Math.abs(m)+Math.abs(T))),M=j(c*I-T*g+k*w,c*V-T*w-k*g,p,d),o.set(i,b-1,M[0]),o.set(i,b,M[1]),Math.abs(c)>Math.abs(T)+Math.abs(k)?(o.set(i+1,b-1,(-g-f*o.get(i,b-1)+k*o.get(i,b))/c),o.set(i+1,b,(-w-f*o.get(i,b)-k*o.get(i,b-1))/c)):(M=j(-I-m*o.get(i,b-1),-V-m*o.get(i,b),T,k),o.set(i+1,b-1,M[0]),o.set(i+1,b,M[1]))),a=Math.max(Math.abs(o.get(i,b-1)),Math.abs(o.get(i,b))),v*a*a>1)for(n=i;n<=b;n++)o.set(n,b-1,o.get(n,b-1)/a),o.set(n,b,o.get(n,b)/a)}for(i=0;i<t;i++)if(i<x||i>E)for(n=i;n<t;n++)s.set(i,n,o.get(i,n));for(n=t-1;n>=x;n--)for(i=x;i<=E;i++){for(T=0,h=x;h<=Math.min(n,E);h++)T+=s.get(i,h)*o.get(h,n);s.set(i,n,T)}}(i,u,h,n,t)}this.n=i,this.e=u,this.d=h,this.V=n}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,s=this.e,o=this.d,i=new v(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)i.set(t,e,0);i.set(t,t,o[t]),s[t]>0?i.set(t,t+1,s[t]):s[t]<0&&i.set(t,t-1,s[t])}return i}}function j(t,e,r,s){let o,i;return Math.abs(r)>Math.abs(s)?(o=s/r,i=r+o*s,[(t+o*e)/i,(e-o*t)/i]):(o=r/s,i=s+o*r,[(o*t+e)/i,(o*e-t)/i])}class ${constructor(t){if(!(t=k.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,s,o=t,i=o.rows,n=new v(i,i),h=!0;for(r=0;r<i;r++){let t=0;for(s=0;s<r;s++){let i=0;for(e=0;e<s;e++)i+=n.get(s,e)*n.get(r,e);i=(o.get(r,s)-i)/n.get(s,s),n.set(r,s,i),t+=i*i}for(t=o.get(r,r)-t,h&=t>0,n.set(r,r,Math.sqrt(Math.max(t,0))),s=r+1;s<i;s++)n.set(r,s,0)}this.L=n,this.positiveDefinite=Boolean(h)}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=k.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(!1===this.isPositiveDefinite())throw new Error("Matrix is not positive definite");let s,o,i,n=t.columns,h=t.clone();for(i=0;i<r;i++)for(o=0;o<n;o++){for(s=0;s<i;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(i,s));h.set(i,o,h.get(i,o)/e.get(i,i))}for(i=r-1;i>=0;i--)for(o=0;o<n;o++){for(s=i+1;s<r;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(s,i));h.set(i,o,h.get(i,o)/e.get(i,i))}return h}get lowerTriangularMatrix(){return this.L}}class P{constructor(t,e={}){t=k.checkMatrix(t);let{Y:r}=e;const{scaleScores:s=!1,maxIterations:o=1e3,terminationCriteria:i=1e-10}=e;let n;if(r){if(r=Array.isArray(r)&&"number"==typeof r[0]?v.columnVector(r):k.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");n=r.getColumnVector(0)}else n=t.getColumnVector(0);let h,u,l,a,f=1;for(let e=0;e<o&&f>i;e++)l=t.transpose().mmul(n).div(n.transpose().mmul(n).get(0,0)),l=l.div(l.norm()),h=t.mmul(l).div(l.transpose().mmul(l).get(0,0)),e>0&&(f=h.clone().sub(a).pow(2).sum()),a=h.clone(),r?(u=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),u=u.div(u.norm()),n=r.mmul(u).div(u.transpose().mmul(u).get(0,0))):n=h;if(r){let e=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));e=e.div(e.norm());let s=t.clone().sub(h.clone().mmul(e.transpose())),o=n.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),i=r.clone().sub(h.clone().mulS(o.get(0,0)).mmul(u.transpose()));this.t=h,this.p=e.transpose(),this.w=l.transpose(),this.q=u,this.u=n,this.s=h.transpose().mmul(h),this.xResidual=s,this.yResidual=i,this.betas=o}else this.w=l.transpose(),this.s=h.transpose().mmul(h).sqrt(),this.t=s?h.clone().div(this.s.get(0,0)):h,this.xResidual=t.sub(h.mmul(l.transpose()))}}t.AbstractMatrix=x,t.CHO=$,t.CholeskyDecomposition=$,t.EVD=D,t.EigenvalueDecomposition=D,t.LU=I,t.LuDecomposition=I,t.Matrix=v,t.MatrixColumnSelectionView=class extends S{constructor(t,e){e=p(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}},t.MatrixColumnView=class extends S{constructor(t,e){f(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}},t.MatrixFlipColumnView=class extends S{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}},t.MatrixFlipRowView=class extends S{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}},t.MatrixRowSelectionView=class extends S{constructor(t,e){super(t,(e=w(t,e)).length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}},t.MatrixRowView=class extends S{constructor(t,e){a(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}},t.MatrixSelectionView=R,t.MatrixSubView=class extends S{constructor(t,e,r,s,o){d(t,e,r,s,o),super(t,r-e+1,o-s+1),this.startRow=e,this.startColumn=s}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}},t.MatrixTransposeView=class extends S{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}},t.NIPALS=P,t.Nipals=P,t.QR=T,t.QrDecomposition=T,t.SVD=N,t.SingularValueDecomposition=N,t.WrapperMatrix1D=A,t.WrapperMatrix2D=k,t.correlation=function(t,e=t,r={}){t=new v(t);let s=!1;if("object"!=typeof e||v.isMatrix(e)||Array.isArray(e)?e=new v(e):(r=e,e=t,s=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0,scale:i=!0}=r;o&&(t.center("column"),s||e.center("column")),i&&(t.scale("column"),s||e.scale("column"));const n=t.standardDeviation("column",{unbiased:!0}),h=s?n:e.standardDeviation("column",{unbiased:!0}),u=t.transpose().mmul(e);for(let e=0;e<u.rows;e++)for(let r=0;r<u.columns;r++)u.set(e,r,u.get(e,r)*(1/(n[e]*h[r]))*(1/(t.rows-1)));return u},t.covariance=function(t,e=t,r={}){t=new v(t);let s=!1;if("object"!=typeof e||v.isMatrix(e)||Array.isArray(e)?e=new v(e):(r=e,e=t,s=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:o=!0}=r;o&&(t=t.center("column"),s||(e=e.center("column")));const i=t.transpose().mmul(e);for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)*(1/(t.rows-1)));return i},t.default=v,t.determinant=function t(e){if((e=v.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,s,o,i;if(2===e.columns)return r=e.get(0,0),s=e.get(0,1),o=e.get(1,0),i=e.get(1,1),r*i-s*o;if(3===e.columns){let i,n,h;return i=new R(e,[1,2],[1,2]),n=new R(e,[1,2],[0,2]),h=new R(e,[1,2],[0,1]),r=e.get(0,0),s=e.get(0,1),o=e.get(0,2),r*t(i)-s*t(n)+o*t(h)}return new I(e).determinant}throw Error("determinant can only be calculated for a square matrix")},t.inverse=function(t,e=!1){return t=k.checkMatrix(t),e?new N(t).inverse():q(t,v.eye(t.rows))},t.linearDependencies=function(t,e={}){const{thresholdValue:r=1e-9,thresholdError:s=1e-9}=e;let o=(t=v.checkMatrix(t)).rows,i=new v(o,o);for(let e=0;e<o;e++){let n=v.columnVector(t.getRow(e)),h=t.subMatrixRow(C(o,e)).transpose(),u=new N(h).solve(n),l=v.sub(n,h.mmul(u)).abs().max();i.setRow(e,F(l,u,e,r,s))}return i},t.pseudoInverse=function(t,e=Number.EPSILON){if((t=v.checkMatrix(t)).isEmpty())return t.transpose();let r=new N(t,{autoTranspose:!0}),s=r.leftSingularVectors,o=r.rightSingularVectors,i=r.diagonal;for(let t=0;t<i.length;t++)Math.abs(i[t])>e?i[t]=1/i[t]:i[t]=0;return o.mmul(v.diag(i).mmul(s.transpose()))},t.solve=q,t.wrap=function(t,e){if(Array.isArray(t))return t[0]&&Array.isArray(t[0])?new k(t):new A(t,e);throw new Error("the argument is not an array")},Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ml-matrix",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.2",
|
|
4
4
|
"description": "Matrix manipulation and computation library",
|
|
5
5
|
"main": "matrix.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"compile": "rollup -c",
|
|
19
|
-
"eslint": "eslint
|
|
19
|
+
"eslint": "eslint src testUtils.js",
|
|
20
20
|
"eslint-fix": "npm run eslint -- --fix",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"test
|
|
21
|
+
"prepack": "npm run compile",
|
|
22
|
+
"prettier": "prettier --check src",
|
|
23
|
+
"prettier-write": "prettier --write src",
|
|
24
|
+
"test": "npm run test-only && npm run eslint && npm run prettier",
|
|
25
|
+
"test-only": "jest --coverage"
|
|
25
26
|
},
|
|
26
27
|
"jest": {
|
|
27
28
|
"testEnvironment": "node"
|
|
@@ -54,24 +55,24 @@
|
|
|
54
55
|
},
|
|
55
56
|
"homepage": "https://github.com/mljs/matrix",
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
58
|
-
"@rollup/plugin-commonjs": "^
|
|
59
|
-
"@rollup/plugin-node-resolve": "^
|
|
58
|
+
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
|
|
59
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
60
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
60
61
|
"benchmark": "^2.1.4",
|
|
61
|
-
"csv-parse": "^4.
|
|
62
|
-
"eslint": "^
|
|
63
|
-
"eslint-config-cheminfo": "^
|
|
64
|
-
"jest": "^
|
|
65
|
-
"jest-matcher-deep-close-to": "^
|
|
66
|
-
"mathjs": "^
|
|
67
|
-
"ml-dataset-iris": "^1.
|
|
62
|
+
"csv-parse": "^4.16.3",
|
|
63
|
+
"eslint": "^8.1.0",
|
|
64
|
+
"eslint-config-cheminfo": "^7.1.2",
|
|
65
|
+
"jest": "^27.3.1",
|
|
66
|
+
"jest-matcher-deep-close-to": "^3.0.2",
|
|
67
|
+
"mathjs": "^9.5.1",
|
|
68
|
+
"ml-dataset-iris": "^1.2.1",
|
|
68
69
|
"numeric": "^1.2.6",
|
|
69
|
-
"prettier": "^2.1
|
|
70
|
+
"prettier": "^2.4.1",
|
|
70
71
|
"pretty-hrtime": "^1.0.3",
|
|
71
|
-
"rollup": "^2.
|
|
72
|
+
"rollup": "^2.59.0",
|
|
72
73
|
"rollup-plugin-terser": "^7.0.2"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
|
-
"ml-array-rescale": "^1.3.
|
|
76
|
+
"ml-array-rescale": "^1.3.6"
|
|
76
77
|
}
|
|
77
78
|
}
|
package/src/dc/nipals.js
CHANGED
|
@@ -18,10 +18,10 @@ export default class nipals {
|
|
|
18
18
|
} else {
|
|
19
19
|
Y = WrapperMatrix2D.checkMatrix(Y);
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
throw new Error('Y
|
|
21
|
+
if (Y.rows !== X.rows) {
|
|
22
|
+
throw new Error('Y should have the same number of rows as X');
|
|
23
23
|
}
|
|
24
|
-
u = Y;
|
|
24
|
+
u = Y.getColumnVector(0);
|
|
25
25
|
} else {
|
|
26
26
|
u = X.getColumnVector(0);
|
|
27
27
|
}
|
package/src/matrix.js
CHANGED
|
@@ -1027,6 +1027,7 @@ export class AbstractMatrix {
|
|
|
1027
1027
|
resultat = resultat.setSubMatrix(c22, c11.rows, c11.columns);
|
|
1028
1028
|
return resultat.subMatrix(0, rows - 1, 0, cols - 1);
|
|
1029
1029
|
}
|
|
1030
|
+
|
|
1030
1031
|
return blockMult(x, y, r, c);
|
|
1031
1032
|
}
|
|
1032
1033
|
|
|
@@ -1119,6 +1120,18 @@ export class AbstractMatrix {
|
|
|
1119
1120
|
return result;
|
|
1120
1121
|
}
|
|
1121
1122
|
|
|
1123
|
+
kroneckerSum(other) {
|
|
1124
|
+
other = Matrix.checkMatrix(other);
|
|
1125
|
+
if (!this.isSquare() || !other.isSquare()) {
|
|
1126
|
+
throw new Error('Kronecker Sum needs two Square Matrices');
|
|
1127
|
+
}
|
|
1128
|
+
let m = this.rows;
|
|
1129
|
+
let n = other.rows;
|
|
1130
|
+
let AxI = this.kroneckerProduct(Matrix.eye(n, n));
|
|
1131
|
+
let IxB = Matrix.eye(m, m).kroneckerProduct(other);
|
|
1132
|
+
return AxI.add(IxB);
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1122
1135
|
transpose() {
|
|
1123
1136
|
let result = new Matrix(this.columns, this.rows);
|
|
1124
1137
|
for (let i = 0; i < this.rows; i++) {
|
|
@@ -1440,9 +1453,8 @@ export class AbstractMatrix {
|
|
|
1440
1453
|
|
|
1441
1454
|
AbstractMatrix.prototype.klass = 'Matrix';
|
|
1442
1455
|
if (typeof Symbol !== 'undefined') {
|
|
1443
|
-
AbstractMatrix.prototype[
|
|
1444
|
-
|
|
1445
|
-
] = inspectMatrix;
|
|
1456
|
+
AbstractMatrix.prototype[Symbol.for('nodejs.util.inspect.custom')] =
|
|
1457
|
+
inspectMatrix;
|
|
1446
1458
|
}
|
|
1447
1459
|
|
|
1448
1460
|
function compareNumbers(a, b) {
|
package/CHANGELOG.md
DELETED
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## [6.6.0](https://www.github.com/mljs/matrix/compare/v6.5.3...v6.6.0) (2021-01-04)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
### Features
|
|
7
|
-
|
|
8
|
-
* add support for empty matrices ([#116](https://www.github.com/mljs/matrix/issues/116)) ([211de6e](https://www.github.com/mljs/matrix/commit/211de6e0880720033862f94a9629e48ae1787109))
|
|
9
|
-
|
|
10
|
-
### [6.5.3](https://www.github.com/mljs/matrix/compare/v6.5.2...v6.5.3) (2020-10-11)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Bug Fixes
|
|
14
|
-
|
|
15
|
-
* update dependencies and move documentation to gh-pages ([78e0724](https://www.github.com/mljs/matrix/commit/78e07240ae9f114c4876a7838e37d9cc95336620))
|
|
16
|
-
|
|
17
|
-
### [6.5.2](https://github.com/mljs/matrix/compare/v6.5.1...v6.5.2) (2020-10-09)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
### Bug Fixes
|
|
21
|
-
|
|
22
|
-
* benchmark of transposeViewMul ([#106](https://github.com/mljs/matrix/issues/106)) ([6407086](https://github.com/mljs/matrix/commit/64070866dfcde5fe48fa70de443ddd804f67d998))
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### Reverts
|
|
26
|
-
|
|
27
|
-
* Revert "chore: migrate release to GitHub actions (#107)" ([21ba23a](https://github.com/mljs/matrix/commit/21ba23ac133fba057769d843d09614fad09edfc9)), closes [#107](https://github.com/mljs/matrix/issues/107)
|
|
28
|
-
|
|
29
|
-
## [6.5.1](https://github.com/mljs/matrix/compare/v6.5.0...v6.5.1) (2020-07-28)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Bug Fixes
|
|
33
|
-
|
|
34
|
-
* **types:** add missing removeColumn and removeRow types ([8010f31](https://github.com/mljs/matrix/commit/8010f3182684589558e8497d9b9230dc4725d848))
|
|
35
|
-
* **types:** add types for addColum and addRow ([#105](https://github.com/mljs/matrix/issues/105)) ([b372b80](https://github.com/mljs/matrix/commit/b372b8083b24c8ff4ce55b3a5c0d2d67e16e0e8e))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
# [6.5.0](https://github.com/mljs/matrix/compare/v6.4.1...v6.5.0) (2020-05-03)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Bug Fixes
|
|
43
|
-
|
|
44
|
-
* do not change input matrices in correlation and covariance functions ([#103](https://github.com/mljs/matrix/issues/103)) ([32e3537](https://github.com/mljs/matrix/commit/32e3537aae0ed4d8cf20c6230a4d411f944b1bcb))
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### Features
|
|
48
|
-
|
|
49
|
-
* add options to toString method ([67b007c](https://github.com/mljs/matrix/commit/67b007cd0e3fb80131e3cdb434868fe3c503ef89))
|
|
50
|
-
* add toString method ([dcd5ab2](https://github.com/mljs/matrix/commit/dcd5ab28a8190e3602335bca40d7d34b7afbb15e))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
## [6.4.1](https://github.com/mljs/matrix/compare/v6.4.0...v6.4.1) (2019-09-30)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### Bug Fixes
|
|
58
|
-
|
|
59
|
-
* correctly ready elements in QR#orthogonalMatrix ([2f527a3](https://github.com/mljs/matrix/commit/2f527a3))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
# [6.4.0](https://github.com/mljs/matrix/compare/v6.3.0...v6.4.0) (2019-08-16)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Features
|
|
67
|
-
|
|
68
|
-
* add CholeskyDecomposition.isPositiveDefinite method ([#94](https://github.com/mljs/matrix/issues/94)) ([6bb33a9](https://github.com/mljs/matrix/commit/6bb33a9))
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# [6.3.0](https://github.com/mljs/matrix/compare/v6.2.0...v6.3.0) (2019-08-16)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
### Features
|
|
76
|
-
|
|
77
|
-
* add UMD build ([#92](https://github.com/mljs/matrix/issues/92)) ([3b82b07](https://github.com/mljs/matrix/commit/3b82b07))
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# [6.2.0](https://github.com/mljs/matrix/compare/v6.1.2...v6.2.0) (2019-07-20)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
### Features
|
|
85
|
-
|
|
86
|
-
* add NIPALS loop for factorization ([#91](https://github.com/mljs/matrix/issues/91)) ([043c8b6](https://github.com/mljs/matrix/commit/043c8b6))
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
## [6.1.2](https://github.com/mljs/matrix/compare/v6.1.1...v6.1.2) (2019-06-29)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
### Bug Fixes
|
|
94
|
-
|
|
95
|
-
* use more Float64Array in decompositions ([0bd8f1b](https://github.com/mljs/matrix/commit/0bd8f1b))
|
|
96
|
-
* **Matrix:** use Float64Array to improve performance ([9dfe983](https://github.com/mljs/matrix/commit/9dfe983))
|
|
97
|
-
* **SVD:** use Float64Array to avoid deopt ([85acd13](https://github.com/mljs/matrix/commit/85acd13))
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
## [6.1.1](https://github.com/mljs/matrix/compare/v6.1.0...v6.1.1) (2019-06-28)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
# [6.1.0](https://github.com/mljs/matrix/compare/v6.0.0...v6.1.0) (2019-06-22)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
### Features
|
|
109
|
-
|
|
110
|
-
* add echelonForm method ([eac0588](https://github.com/mljs/matrix/commit/eac0588))
|
|
111
|
-
* add reducedEchelonForm method ([f32a8aa](https://github.com/mljs/matrix/commit/f32a8aa))
|
|
112
|
-
* add statistical operations ([43fc4ef](https://github.com/mljs/matrix/commit/43fc4ef))
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# [6.0.0](https://github.com/mljs/matrix/compare/v6.0.0-6...v6.0.0) (2019-04-25)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# [6.0.0-6](https://github.com/mljs/matrix/compare/v6.0.0-5...v6.0.0-6) (2019-04-25)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Bug Fixes
|
|
124
|
-
|
|
125
|
-
* add linearDependencies to TS definitions ([22c4f60](https://github.com/mljs/matrix/commit/22c4f60))
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
### Code Refactoring
|
|
129
|
-
|
|
130
|
-
* rework a lot of things ([1b3cb03](https://github.com/mljs/matrix/commit/1b3cb03))
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
### Features
|
|
134
|
-
|
|
135
|
-
* add a custom Node.js inspect function ([cb51169](https://github.com/mljs/matrix/commit/cb51169))
|
|
136
|
-
* rename reverse methods to split ([def2977](https://github.com/mljs/matrix/commit/def2977))
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
### BREAKING CHANGES
|
|
140
|
-
|
|
141
|
-
* The signature of a few methods changed to take an options object:
|
|
142
|
-
- Matrix.rand / Matrix.random
|
|
143
|
-
- Matrix.randInt
|
|
144
|
-
- Matrix.prototype.repeat
|
|
145
|
-
- Matrix.prototype.scaleRows
|
|
146
|
-
- Matrix.prototype.scaleColumns
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
# [6.0.0-5](https://github.com/mljs/matrix/compare/v6.0.0-4...v6.0.0-5) (2019-04-18)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
### Code Refactoring
|
|
154
|
-
|
|
155
|
-
* remove configurable super class and circular dependencies ([dd35ec8](https://github.com/mljs/matrix/commit/dd35ec8))
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
### BREAKING CHANGES
|
|
159
|
-
|
|
160
|
-
* * It is no longer possible to make a Matrix class that extends a custom constructor
|
|
161
|
-
* `matrix.det()` was moved to a standalone function: `determinant(matrix)`
|
|
162
|
-
* `matrix.pseudoInverse()` was moved to a standalone function: `pseudoInverse(matrix)`
|
|
163
|
-
* `matrix.linearDependencies()` was moved to a standalone function: `linearDependencies(matrix)`
|
|
164
|
-
* Matrix views must be created using their constructors instead of Matrix methods.
|
|
165
|
-
For example, `matrix.transposeView()` becomes `new MatrixTransposeView(matrix)`
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
# [6.0.0-4](https://github.com/mljs/matrix/compare/v6.0.0-3...v6.0.0-4) (2019-04-18)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
### Features
|
|
173
|
-
|
|
174
|
-
* implement reverseRows and reverseColumns methods ([77e5ed7](https://github.com/mljs/matrix/commit/77e5ed7))
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# [6.0.0-3](https://github.com/mljs/matrix/compare/v6.0.0-2...v6.0.0-3) (2019-04-18)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
# [6.0.0-2](https://github.com/mljs/matrix/compare/v6.0.0-1...v6.0.0-2) (2019-04-18)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
### Features
|
|
186
|
-
|
|
187
|
-
* make JSON.stringify always return a 2D array from any matrix ([021115b](https://github.com/mljs/matrix/commit/021115b))
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
# [6.0.0-1](https://github.com/mljs/matrix/compare/v6.0.0-0...v6.0.0-1) (2019-04-18)
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
### Code Refactoring
|
|
195
|
-
|
|
196
|
-
* make sum by row or column return an array ([dbe7c99](https://github.com/mljs/matrix/commit/dbe7c99))
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
### Features
|
|
200
|
-
|
|
201
|
-
* add entropy method ([63b95d1](https://github.com/mljs/matrix/commit/63b95d1))
|
|
202
|
-
* add mean by dimension and product methods ([6b57aae](https://github.com/mljs/matrix/commit/6b57aae))
|
|
203
|
-
* add variance and standardDeviation methods ([f42f1b6](https://github.com/mljs/matrix/commit/f42f1b6))
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
### BREAKING CHANGES
|
|
207
|
-
|
|
208
|
-
* `matrix.sum('row')` and `matrix.sum('column')` now return an array instead of a Matrix.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# [6.0.0-0](https://github.com/mljs/matrix/compare/v5.3.0...v6.0.0-0) (2019-04-18)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
### chore
|
|
216
|
-
|
|
217
|
-
* remove support for Node 6 ([42e4fde](https://github.com/mljs/matrix/commit/42e4fde))
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
### Code Refactoring
|
|
221
|
-
|
|
222
|
-
* stop extending Array ([1837678](https://github.com/mljs/matrix/commit/1837678))
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
### BREAKING CHANGES
|
|
226
|
-
|
|
227
|
-
* Node.js 6 is no longer supported.
|
|
228
|
-
* * Matrix no longer extends the Array class. It means that it is not
|
|
229
|
-
possible to access and set values using array indices (e.g. matrix[i][j]).
|
|
230
|
-
The only supported way is to use matrix.get() and matrix.set().
|
|
231
|
-
* New matrices are now always filled with zeros instead of `undefined`.
|
|
232
|
-
* The static Matrix.empty() function was removed.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
# [5.3.0](https://github.com/mljs/matrix/compare/v5.2.1...v5.3.0) (2019-03-23)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
### Bug Fixes
|
|
240
|
-
|
|
241
|
-
* add isEchelonForm and isReducedEchelonForm to typings ([690edd1](https://github.com/mljs/matrix/commit/690edd1))
|
|
242
|
-
* correct matrix.d.ts file. ([#86](https://github.com/mljs/matrix/issues/86)) ([ebb273c](https://github.com/mljs/matrix/commit/ebb273c))
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
### Features
|
|
246
|
-
|
|
247
|
-
* add isEchelonForm and isReducedEchelonForm ([#84](https://github.com/mljs/matrix/issues/84)) ([dee2a94](https://github.com/mljs/matrix/commit/dee2a94))
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
## [5.2.1](https://github.com/mljs/matrix/compare/v5.2.0...v5.2.1) (2019-01-07)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
### Bug Fixes
|
|
255
|
-
|
|
256
|
-
* correct matrix.d.ts to follow TypeScript 3 ([#81](https://github.com/mljs/matrix/issues/81)) ([99329fd](https://github.com/mljs/matrix/commit/99329fd))
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
# [5.2.0](https://github.com/mljs/matrix/compare/v5.1.1...v5.2.0) (2018-09-25)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
### Bug Fixes
|
|
264
|
-
|
|
265
|
-
* complete type definitions ([ca63059](https://github.com/mljs/matrix/commit/ca63059))
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
### Features
|
|
269
|
-
|
|
270
|
-
* create index.d.ts ([#74](https://github.com/mljs/matrix/issues/74)) ([905c987](https://github.com/mljs/matrix/commit/905c987))
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
## [5.1.1](https://github.com/mljs/matrix/compare/v5.1.0...v5.1.1) (2018-05-11)
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
### Bug Fixes
|
|
278
|
-
|
|
279
|
-
* prevent infinite loop ([f684d90](https://github.com/mljs/matrix/commit/f684d90))
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
# [5.1.0](https://github.com/mljs/matrix/compare/v5.0.1...v5.1.0) (2018-05-04)
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
### Features
|
|
287
|
-
|
|
288
|
-
* add linearDependencies method ([88ee3df](https://github.com/mljs/matrix/commit/88ee3df))
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
### Performance Improvements
|
|
292
|
-
|
|
293
|
-
* add transposeViewMul benchmark ([0d24ea9](https://github.com/mljs/matrix/commit/0d24ea9))
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
## [5.0.1](https://github.com/mljs/matrix/compare/v5.0.0...v5.0.1) (2017-07-28)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
### Bug Fixes
|
|
301
|
-
|
|
302
|
-
* Add test case ([4b72211](https://github.com/mljs/matrix/commit/4b72211))
|
|
303
|
-
* bug with SVD ([f615aa3](https://github.com/mljs/matrix/commit/f615aa3))
|
|
304
|
-
* rollup didn't understood .. ([3af231d](https://github.com/mljs/matrix/commit/3af231d))
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
# [5.0.0](https://github.com/mljs/matrix/compare/v4.0.0...v5.0.0) (2017-07-21)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
### Code Refactoring
|
|
312
|
-
|
|
313
|
-
* change decompositions to classes ([00c18e8](https://github.com/mljs/matrix/commit/00c18e8))
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
### BREAKING CHANGES
|
|
317
|
-
|
|
318
|
-
* Now decompositions have to be created with "new".
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
# [4.0.0](https://github.com/mljs/matrix/compare/v3.0.0...v4.0.0) (2017-07-19)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
### Code Refactoring
|
|
326
|
-
|
|
327
|
-
* remove dependency on ml-array-utils ([1e7119d](https://github.com/mljs/matrix/commit/1e7119d))
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
### Features
|
|
331
|
-
|
|
332
|
-
* **wrap:** create a 2D or 1D WrapperMatrix ([#52](https://github.com/mljs/matrix/issues/52)) ([7900d67](https://github.com/mljs/matrix/commit/7900d67))
|
|
333
|
-
* add norm method ([#57](https://github.com/mljs/matrix/issues/57)) ([221391a](https://github.com/mljs/matrix/commit/221391a))
|
|
334
|
-
* allows to select only rows or columns as view ([#51](https://github.com/mljs/matrix/issues/51)) ([46eb916](https://github.com/mljs/matrix/commit/46eb916))
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
### BREAKING CHANGES
|
|
338
|
-
|
|
339
|
-
* The new ml-array-rescale dependency removes support for Node 4
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
# [3.0.0](https://github.com/mljs/matrix/compare/v2.3.0...v3.0.0) (2017-04-25)
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
# [2.3.0](https://github.com/mljs/matrix/compare/v2.2.0...v2.3.0) (2017-02-28)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
### Features
|
|
351
|
-
|
|
352
|
-
* add pseudoinverse function based on SVD ([3279a15](https://github.com/mljs/matrix/commit/3279a15))
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
# [2.2.0](https://github.com/mljs/matrix/compare/v2.1.0...v2.2.0) (2016-12-14)
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
### Bug Fixes
|
|
360
|
-
|
|
361
|
-
* Matrix and Lu circular dependency ([ab706b9](https://github.com/mljs/matrix/commit/ab706b9))
|
|
362
|
-
* styling issues picked up by Travis CI ([f211a1f](https://github.com/mljs/matrix/commit/f211a1f))
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
### Features
|
|
366
|
-
|
|
367
|
-
* **det:** add 2x2 and 3x3 determinants ([04ae195](https://github.com/mljs/matrix/commit/04ae195))
|
|
368
|
-
* **det:** add determinant based on LU decomposition ([90532ef](https://github.com/mljs/matrix/commit/90532ef))
|
|
369
|
-
* **det:** add determinant synonym ([5395b56](https://github.com/mljs/matrix/commit/5395b56))
|
|
370
|
-
* **sum:** sum by 'row' or 'column' ([bf5d070](https://github.com/mljs/matrix/commit/bf5d070))
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
# [2.1.0](https://github.com/mljs/matrix/compare/v2.0.0...v2.1.0) (2016-10-07)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
### Bug Fixes
|
|
378
|
-
|
|
379
|
-
* use Symbol.species as Matrix constructor in selection ([fee325e](https://github.com/mljs/matrix/commit/fee325e))
|
|
380
|
-
* use Symbol.species in evaluated static methods ([39800f9](https://github.com/mljs/matrix/commit/39800f9))
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
### Features
|
|
384
|
-
|
|
385
|
-
* add fast multiplication algorithm (strassen) ([fdc1c07](https://github.com/mljs/matrix/commit/fdc1c07))
|
|
386
|
-
* add maxValue option to Matrix.randInt ([e5a8541](https://github.com/mljs/matrix/commit/e5a8541))
|
|
387
|
-
* add value parameter to Matrix.eye ([f52e4fd](https://github.com/mljs/matrix/commit/f52e4fd)), closes [#43](https://github.com/mljs/matrix/issues/43)
|
|
388
|
-
* implement optimized algorithm for 2x2 and 3x3 multiplication ([4055ef9](https://github.com/mljs/matrix/commit/4055ef9))
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
# [2.0.0](https://github.com/mljs/matrix/compare/v1.4.0...v2.0.0) (2016-08-04)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
### Features
|
|
396
|
-
|
|
397
|
-
* add column view ([5ff6680](https://github.com/mljs/matrix/commit/5ff6680))
|
|
398
|
-
* add flipColumn and flipRow views ([55ee4a6](https://github.com/mljs/matrix/commit/55ee4a6))
|
|
399
|
-
* add method subMatrixView ([aa1df18](https://github.com/mljs/matrix/commit/aa1df18))
|
|
400
|
-
* add row view ([a9e99f2](https://github.com/mljs/matrix/commit/a9e99f2))
|
|
401
|
-
* add selection method and selection view ([59aa861](https://github.com/mljs/matrix/commit/59aa861))
|
|
402
|
-
* make use of Symbol.species to allow creating new matrices in any class ([eaee5de](https://github.com/mljs/matrix/commit/eaee5de))
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
# [1.4.0](https://github.com/mljs/matrix/compare/v1.3.0...v1.4.0) (2016-08-03)
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
### Features
|
|
410
|
-
|
|
411
|
-
* add concept of abstract matrix ([cbefc9b](https://github.com/mljs/matrix/commit/cbefc9b))
|
|
412
|
-
* add method setSubMatrix ([89b4242](https://github.com/mljs/matrix/commit/89b4242))
|
|
413
|
-
* add method with one argument template ([b66ee9f](https://github.com/mljs/matrix/commit/b66ee9f))
|
|
414
|
-
* add repeat method ([8b9eecb](https://github.com/mljs/matrix/commit/8b9eecb))
|
|
415
|
-
* add transposeView ([fb0a0c9](https://github.com/mljs/matrix/commit/fb0a0c9))
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
### BREAKING CHANGES
|
|
419
|
-
|
|
420
|
-
* This is a non trivial change and could potentially break existing code.
|
|
421
|
-
There is no known backward incompatibility though.
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
# [1.3.0](https://github.com/mljs/matrix/compare/v1.2.1...v1.3.0) (2016-07-25)
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
### Features
|
|
429
|
-
|
|
430
|
-
* add methods scaleRows and scaleColumns ([8516f83](https://github.com/mljs/matrix/commit/8516f83))
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
## [1.2.1](https://github.com/mljs/matrix/compare/v1.2.0...v1.2.1) (2016-07-07)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
### Bug Fixes
|
|
438
|
-
|
|
439
|
-
* do not use rest parameters ([2c4502e](https://github.com/mljs/matrix/commit/2c4502e))
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
# [1.2.0](https://github.com/mljs/matrix/compare/v1.1.5...v1.2.0) (2016-07-07)
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
### Features
|
|
447
|
-
|
|
448
|
-
* add support for Math.pow ([2524b73](https://github.com/mljs/matrix/commit/2524b73)), closes [#21](https://github.com/mljs/matrix/issues/21)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
## [1.1.5](https://github.com/mljs/matrix/compare/v1.1.4...v1.1.5) (2016-05-31)
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
## [1.1.4](https://github.com/mljs/matrix/compare/v1.1.3...v1.1.4) (2016-05-27)
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
## [1.1.3](https://github.com/mljs/matrix/compare/v1.1.2...v1.1.3) (2016-05-27)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
## [1.1.2](https://github.com/mljs/matrix/compare/v1.1.1...v1.1.2) (2016-05-18)
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
## [1.1.1](https://github.com/mljs/matrix/compare/v1.1.0...v1.1.1) (2016-05-18)
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
# [1.1.0](https://github.com/mljs/matrix/compare/v1.0.4...v1.1.0) (2016-05-13)
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
## [1.0.4](https://github.com/mljs/matrix/compare/v1.0.3...v1.0.4) (2015-11-21)
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
## [1.0.3](https://github.com/mljs/matrix/compare/v1.0.2...v1.0.3) (2015-11-19)
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
### Bug Fixes
|
|
484
|
-
|
|
485
|
-
* random not correctly filling rectangular matrices ([a79c3eb](https://github.com/mljs/matrix/commit/a79c3eb))
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
## [1.0.2](https://github.com/mljs/matrix/compare/v1.0.1...v1.0.2) (2015-10-05)
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
## [1.0.1](https://github.com/mljs/matrix/compare/v1.0.0...v1.0.1) (2015-09-11)
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
# [1.0.0](https://github.com/mljs/matrix/compare/v1.0.0-0...v1.0.0) (2015-09-10)
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
# [1.0.0-0](https://github.com/mljs/matrix/compare/v0.1.0...v1.0.0-0) (2015-09-09)
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
### Bug Fixes
|
|
505
|
-
|
|
506
|
-
* **matrix:** abs method should return the instance ([cd96b4b](https://github.com/mljs/matrix/commit/cd96b4b))
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
### Features
|
|
510
|
-
|
|
511
|
-
* add fullname synonyms for some methods ([4845a43](https://github.com/mljs/matrix/commit/4845a43))
|
|
512
|
-
* add static min and max methods ([41707af](https://github.com/mljs/matrix/commit/41707af))
|
|
513
|
-
* support all arithmetic operators and Math functions including static versions ([521e4fe](https://github.com/mljs/matrix/commit/521e4fe)), closes [#7](https://github.com/mljs/matrix/issues/7)
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
# [0.1.0](https://github.com/mljs/matrix/compare/v0.0.4...v0.1.0) (2015-06-11)
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
## [0.0.4](https://github.com/mljs/matrix/compare/v0.0.1...v0.0.4) (2015-06-11)
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
## 0.0.1 (2014-10-24)
|