@elarsaks/umap-wasm 0.3.8 → 0.3.10

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.
@@ -25,6 +25,13 @@ export async function initWasm() {
25
25
  if (typeof mod.default === 'function') {
26
26
  await mod.default();
27
27
  }
28
+ if (typeof mod.init_threads === 'function') {
29
+ const canUseThreads = typeof crossOriginIsolated !== 'undefined' && crossOriginIsolated &&
30
+ typeof navigator !== 'undefined' && typeof navigator.hardwareConcurrency === 'number';
31
+ if (canUseThreads) {
32
+ await mod.init_threads(navigator.hardwareConcurrency);
33
+ }
34
+ }
28
35
  wasmModule = mod;
29
36
  return mod;
30
37
  }
package/lib/umap-js.js CHANGED
@@ -6499,6 +6499,13 @@ async function initWasm() {
6499
6499
  if (typeof mod.default === 'function') {
6500
6500
  await mod.default();
6501
6501
  }
6502
+ if (typeof mod.init_threads === 'function') {
6503
+ const canUseThreads = typeof crossOriginIsolated !== 'undefined' && crossOriginIsolated &&
6504
+ typeof navigator !== 'undefined' && typeof navigator.hardwareConcurrency === 'number';
6505
+ if (canUseThreads) {
6506
+ await mod.init_threads(navigator.hardwareConcurrency);
6507
+ }
6508
+ }
6502
6509
  wasmModule = mod;
6503
6510
  return mod;
6504
6511
  }
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.UMAP=e():t.UMAP=e()}(this,()=>(()=>{var t={433(t){function e(t){return Promise.resolve().then(()=>{var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e})}e.keys=()=>[],e.resolve=e,e.id=433,t.exports=e},673(t,e,r){"use strict";var s=r(788),o=r(718);const n=" ".repeat(2),i=" ".repeat(4);function h(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:o=8,padMinus:h="auto"}=e;return`${t.constructor.name} {\n${n}[\n${i}${function(t,e,r,s,o){const{rows:n,columns:h}=t,l=Math.min(n,e),u=Math.min(h,r),c=[];if("auto"===o){o=!1;t:for(let e=0;e<l;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<l;e++){let r=[];for(let n=0;n<u;n++)r.push(a(t.get(e,n),s,o));c.push(`${r.join(" ")}`)}return u!==h&&(c[c.length-1]+=` ... ${h-r} more columns`),l!==n&&c.push(`... ${n-e} more rows`),c.join(`\n${i}`)}(t,r,s,o,h)}\n${n}]\n${n}rows: ${t.rows}\n${n}columns: ${t.columns}\n}`}function a(t,e,r){return(t>=0&&r?` ${l(t,e-1)}`:l(t,e)).padEnd(e)}function l(t,e){let r=t.toString();if(r.length<=e)return r;let s=t.toFixed(e);if(s.length>e&&(s=t.toFixed(Math.max(0,e-(s.length-e)))),s.length<=e&&!s.startsWith("0.000")&&!s.startsWith("-0.000"))return s;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function u(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 c(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 f(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){if(!s.isAnyArray(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}function w(t,e){if(!s.isAnyArray(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}function p(t,e,r,s,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(y("startRow",e),y("endRow",r),y("startColumn",s),y("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 d(t,e=0){let r=[];for(let s=0;s<t;s++)r.push(e);return r}function y(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 M{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new E(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 E(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 E(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 E(t,e)}static ones(t,e){return new E(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 E(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:n=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 i=o-s,h=new E(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(n()*i);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),n=this.zeros(e,r);for(let e=0;e<o;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new E(r,s);for(let n=0;n<r;n++)for(let r=0;r<s;r++)o.set(n,r,Math.min(t.get(n,r),e.get(n,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 n=0;n<r;n++)for(let r=0;r<s;r++)o.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return o}static checkMatrix(t){return M.isMatrix(t)?t:new E(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}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(0!==this.get(t,t))return!1;return!0}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 n=r+1;n<t.columns;n++)t.set(s,n,t.get(s,n)-t.get(e,n)*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,n=!1;for(;o<r&&!1===n;)1===t.get(s,o)?n=!0:o++;for(let r=0;r<s;r++){let n=t.get(r,o);for(let i=o;i<e;i++){let e=t.get(r,i)-n*t.get(s,i);t.set(r,i,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 E(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){u(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return E.rowVector(this.getRow(t))}setRow(t,e){u(this,t),e=f(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){u(this,t),u(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){c(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return E.columnVector(this.getColumn(t))}setColumn(t,e){c(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){c(this,t),c(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=f(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=f(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=f(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=f(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){u(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){c(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{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}default:throw new Error(`invalid option: ${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(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{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}default:throw new Error(`invalid option: ${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(u(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){u(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(u(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){u(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(c(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){c(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(c(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){c(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"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default: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){M.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=E.checkMatrix(t);let e=this.rows,r=this.columns,s=t.columns,o=new E(e,s),n=new Float64Array(r);for(let i=0;i<s;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*n[s];o.set(t,i,e)}}return o}mpow(t){if(!this.isSquare())throw new RangeError("Matrix must be square");if(!Number.isInteger(t)||t<0)throw new RangeError("Exponent must be a non-negative integer");let e=E.eye(this.rows),r=this;for(let s=t;s>=1;s/=2)1&s&&(e=e.mmul(r)),r=r.mmul(r);return e}strassen2x2(t){t=E.checkMatrix(t);let e=new E(2,2);const r=this.get(0,0),s=t.get(0,0),o=this.get(0,1),n=t.get(0,1),i=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(s+l),c=(i+a)*s,f=r*(n-l),m=a*(h-s),g=(r+o)*l,w=u+m-g+(o-a)*(h+l),p=f+g,d=c+m,y=u-c+f+(i-r)*(s+n);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=E.checkMatrix(t);let e=new E(3,3);const r=this.get(0,0),s=this.get(0,1),o=this.get(0,2),n=this.get(1,0),i=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=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),b=t.get(2,2),M=(r-n)*(-f+w),x=(-r+n+i)*(c-f+w),S=(n+i)*(-c+f),v=r*c,A=(-r+a+l)*(c-m+p),N=(-r+a)*(m-p),R=(a+l)*(-c+m),k=(-o+l+u)*(w+d-y),z=(o-u)*(w-y),I=o*d,F=(l+u)*(-d+y),T=(-o+i+h)*(p+d-b),C=(o-h)*(p-b),D=(i+h)*(-d+b),V=v+I+s*g,q=(r+s+o-n-i-l-u)*w+x+S+v+k+I+F,W=v+A+R+(r+s+o-i-h-a-l)*p+I+T+D,P=M+i*(-c+f+g-w-p-d+b)+x+v+I+T+C,O=M+x+S+v+h*y,j=I+T+C+D+n*m,L=v+A+N+l*(-c+m+g-w-p-d+y)+k+z+I,_=k+z+I+F+a*f,$=v+A+N+R+u*b;return e.set(0,0,V),e.set(0,1,q),e.set(0,2,W),e.set(1,0,P),e.set(1,1,O),e.set(1,2,j),e.set(2,0,L),e.set(2,1,_),e.set(2,2,$),e}mmulStrassen(t){t=E.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,o=t.rows,n=t.columns;function i(t,e,r){let s=t.rows,o=t.columns;if(s===e&&o===r)return t;{let s=M.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==o&&console.warn(`Multiplying ${r} x ${s} and ${o} x ${n} matrix: dimensions do not match.`);let h=Math.max(r,o),a=Math.max(s,n);return e=i(e,h,a),function t(e,r,s,o){if(s<=512||o<=512)return e.mmul(r);s%2==1&&o%2==1?(e=i(e,s+1,o+1),r=i(r,s+1,o+1)):s%2==1?(e=i(e,s+1,o),r=i(r,s+1,o)):o%2==1&&(e=i(e,s,o+1),r=i(r,s,o+1));let n=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,n-1,0,h-1),l=r.subMatrix(0,n-1,0,h-1),u=e.subMatrix(0,n-1,h,e.columns-1),c=r.subMatrix(0,n-1,h,r.columns-1),f=e.subMatrix(n,e.rows-1,0,h-1),m=r.subMatrix(n,r.rows-1,0,h-1),g=e.subMatrix(n,e.rows-1,h,e.columns-1),w=r.subMatrix(n,r.rows-1,h,r.columns-1),p=t(M.add(a,g),M.add(l,w),n,h),d=t(M.add(f,g),l,n,h),y=t(a,M.sub(c,w),n,h),b=t(g,M.sub(m,l),n,h),x=t(M.add(a,u),w,n,h),S=t(M.sub(f,a),M.add(l,c),n,h),E=t(M.sub(u,g),M.add(m,w),n,h),v=M.add(p,b);v.sub(x),v.add(E);let A=M.add(y,x),N=M.add(d,b),R=M.sub(p,d);R.add(y),R.add(S);let k=M.zeros(2*v.rows,2*v.columns);return k=k.setSubMatrix(v,0,0),k=k.setSubMatrix(A,v.rows,0),k=k.setSubMatrix(N,0,v.columns),k=k.setSubMatrix(R,v.rows,v.columns),k.subMatrix(0,s-1,0,o-1)}(e,t=i(t,h,a),h,a)}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 E(this.rows,this.columns);for(let t=0;t<this.rows;t++){const n=this.getRow(t);n.length>0&&o(n,{min:e,max:r,output:n}),s.setRow(t,n)}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 E(this.rows,this.columns);for(let t=0;t<this.columns;t++){const n=this.getColumn(t);n.length&&o(n,{min:e,max:r,output:n}),s.setColumn(t,n)}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=E.checkMatrix(t);let e=this.rows,r=this.columns,s=t.rows,o=t.columns,n=new E(e*s,r*o);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<o;h++)n.set(s*i+r,o*e+h,this.get(i,e)*t.get(r,h));return n}kroneckerSum(t){if(t=E.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(E.eye(r,r)),o=E.eye(e,e).kroneckerProduct(t);return s.add(o)}transpose(){let t=new E(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=x){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=x){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,s){p(this,t,e,r,s);let o=new E(e-t+1,s-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=s;e++)o.set(n-t,e-r,this.get(n,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 E(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let n=e;n<=r;n++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);s.set(o,n-e,this.get(t[o],n))}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 E(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let n=e;n<=r;n++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);s.set(n-e,o,this.get(n,t[o]))}return s}setSubMatrix(t,e,r){if((t=E.checkMatrix(t)).isEmpty())return this;p(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){g(this,t),w(this,e);let r=new E(t.length,e.length);for(let s=0;s<t.length;s++){let o=t[s];for(let t=0;t<e.length;t++){let n=e[t];r.set(s,t,this.get(o,n))}}return r}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(){return this.constructor.copy(this,new E(this.rows,this.columns))}static copy(t,e){for(const[r,s,o]of t.entries())e.set(r,s,o);return e}sum(t){switch(t){case"row":return function(t){let e=d(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=d(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=d(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=d(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:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!s.isAnyArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,n=[];for(let i=0;i<s;i++){let s=0,h=0,a=0;for(let e=0;e<o;e++)a=t.get(i,e)-r[i],s+=a,h+=a*a;e?n.push((h-s*s/o)/(o-1)):n.push((h-s*s/o)/o)}return n}(this,r,o);case"column":if(!s.isAnyArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,n=[];for(let i=0;i<o;i++){let o=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(e,i)-r[i],o+=a,h+=a*a;e?n.push((h-o*o/s)/(s-1)):n.push((h-o*o/s)/s)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const s=t.rows,o=t.columns,n=s*o;let i=0,h=0,a=0;for(let e=0;e<s;e++)for(let s=0;s<o;s++)a=t.get(e,s)-r,i+=a,h+=a*a;return e?(h-i*i/n)/(n-1):(h-i*i/n)/n}(this,r,o);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(!s.isAnyArray(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(!s.isAnyArray(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+=t.get(r,e)**2/(t.columns-1);e.push(Math.sqrt(s))}return e}(this);else if(!s.isAnyArray(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+=t.get(e,r)**2/(t.rows-1);e.push(Math.sqrt(s))}return e}(this);else if(!s.isAnyArray(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+=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 h(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}function x(t,e){return t-e}function S(t){return t.every(t=>"number"==typeof t)}M.prototype.klass="Matrix","undefined"!=typeof Symbol&&(M.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return h(this)}),M.random=M.rand,M.randomInt=M.randInt,M.diagonal=M.diag,M.prototype.diagonal=M.prototype.diag,M.identity=M.eye,M.prototype.negate=M.prototype.neg,M.prototype.tensorProduct=M.prototype.kroneckerProduct;class E extends M{data;#t(t,e){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));this.rows=t,this.columns=e}constructor(t,e){if(super(),E.isMatrix(t))this.#t(t.rows,t.columns),E.copy(t,this);else if(Number.isInteger(t)&&t>=0)this.#t(t,e);else{if(!s.isAnyArray(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");if(!S(r[s]))throw new TypeError("Input data contains non-numeric values");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 u(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),u(this,t,!0),e=Float64Array.from(f(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){c(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),c(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,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,this.get(e,r)**t.get(e,r));return this}}(M,E);class v extends M{#e;get size(){return this.#e.size}get rows(){return this.#e.rows}get columns(){return this.#e.columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return E.isMatrix(t)&&"SymmetricMatrix"===t.klassType}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}constructor(t){if(super(),E.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");this.#e=E.copy(t,new E(t.rows,t.rows))}else if(Number.isInteger(t)&&t>=0)this.#e=new E(t,t);else if(this.#e=new E(t),!this.isSymmetric())throw new TypeError("not symmetric data")}clone(){const t=new v(this.diagonalSize);for(const[e,r,s]of this.upperRightEntries())t.set(e,r,s);return t}toMatrix(){return new E(this)}get(t,e){return this.#e.get(t,e)}set(t,e,r){return this.#e.set(t,e,r),this.#e.set(e,t,r),this}removeCross(t){return this.#e.removeRow(t),this.#e.removeColumn(t),this}addCross(t,e){void 0===e&&(e=t,t=this.diagonalSize);const r=e.slice();return r.splice(t,1),this.#e.addRow(t,r),this.#e.addColumn(t,e),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const e=[];for(const[r,s]of t.entries())s||e.push(r);e.reverse();for(const t of e)this.removeCross(t);return this}toCompact(){const{diagonalSize:t}=this,e=new Array(t*(t+1)/2);for(let r=0,s=0,o=0;o<e.length;o++)e[o]=this.get(s,r),++r>=t&&(r=++s);return e}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)-1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(t)}`);const s=new v(r);for(let o=0,n=0,i=0;i<e;i++)s.set(o,n,t[i]),++o>=r&&(o=++n);return s}*upperRightEntries(){for(let t=0,e=0;t<this.diagonalSize;void 0){const r=this.get(t,e);yield[t,e,r],++e>=this.diagonalSize&&(e=++t)}}*upperRightValues(){for(let t=0,e=0;t<this.diagonalSize;void 0){const r=this.get(t,e);yield r,++e>=this.diagonalSize&&(e=++t)}}}v.prototype.klassType="SymmetricMatrix";class A extends v{static isDistanceMatrix(t){return v.isSymmetricMatrix(t)&&"DistanceMatrix"===t.klassSubType}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return void 0===e&&(e=t,t=this.diagonalSize),(e=e.slice())[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new v(this)}clone(){const t=new A(this.diagonalSize);for(const[e,r,s]of this.upperRightEntries())e!==r&&t.set(e,r,s);return t}toCompact(){const{diagonalSize:t}=this,e=new Array((t-1)*t/2);for(let r=1,s=0,o=0;o<e.length;o++)e[o]=this.get(s,r),++r>=t&&(r=1+ ++s);return e}static fromCompact(t){const e=t.length;if(0===e)return new this(0);const r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const s=new this(r);for(let o=1,n=0,i=0;i<e;i++)s.set(o,n,t[i]),++o>=r&&(o=1+ ++n);return s}}A.prototype.klassSubType="DistanceMatrix";class N extends M{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class R extends N{constructor(t,e,r){g(t,e),w(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}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 k extends M{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 z extends M{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,n,i,h,a,l,u=(t=z.checkMatrix(t)).clone(),c=u.rows,f=u.columns,m=new Float64Array(c),g=1;for(e=0;e<c;e++)m[e]=e;for(a=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)a[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),n=0,s=0;s<l;s++)n+=u.get(e,s)*a[s];a[e]-=n,u.set(e,r,a[e])}for(o=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[o])&&(o=e);if(o!==r){for(s=0;s<f;s++)i=u.get(o,s),u.set(o,s,u.get(r,s)),u.set(r,s,i);h=m[o],m[o]=m[r],m[r]=h,g=-g}if(r<c&&0!==u.get(r,r))for(e=r+1;e<c;e++)u.set(e,r,u.get(e,r)/u.get(r,r))}this.LU=u,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=E.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,n=t.columns,i=t.subMatrixRow(this.pivotVector,0,n-1),h=e.columns;for(o=0;o<h;o++)for(r=o+1;r<h;r++)for(s=0;s<n;s++)i.set(r,s,i.get(r,s)-i.get(o,s)*e.get(r,o));for(o=h-1;o>=0;o--){for(s=0;s<n;s++)i.set(o,s,i.get(o,s)/e.get(o,o));for(r=0;r<o;r++)for(s=0;s<n;s++)i.set(r,s,i.get(r,s)-i.get(o,s)*e.get(r,o))}return i}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 E(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 E(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 F(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,n=(t=z.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<i;e++)t=F(t,n.get(e,s));if(0!==t){for(n.get(s,s)<0&&(t=-t),e=s;e<i;e++)n.set(e,s,n.get(e,s)/t);for(n.set(s,s,n.get(s,s)+1),r=s+1;r<h;r++){for(o=0,e=s;e<i;e++)o+=n.get(e,s)*n.get(e,r);for(o=-o/n.get(s,s),e=s;e<i;e++)n.set(e,r,n.get(e,r)+o*n.get(e,s))}}a[s]=-t}this.QR=n,this.Rdiag=a}solve(t){t=E.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,n,i,h=t.columns,a=t.clone(),l=e.columns;for(n=0;n<l;n++)for(o=0;o<h;o++){for(i=0,s=n;s<r;s++)i+=e.get(s,n)*a.get(s,o);for(i=-i/e.get(n,n),s=n;s<r;s++)a.set(s,o,a.get(s,o)+i*e.get(s,n))}for(n=l-1;n>=0;n--){for(o=0;o<h;o++)a.set(n,o,a.get(n,o)/this.Rdiag[n]);for(s=0;s<n;s++)for(o=0;o<h;o++)a.set(s,o,a.get(s,o)-a.get(n,o)*e.get(s,n))}return a.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 E(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,n=o.rows,i=o.columns,h=new E(n,i);for(r=i-1;r>=0;r--){for(t=0;t<n;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<i;e++)if(0!==o.get(r,r)){for(s=0,t=r;t<n;t++)s+=o.get(t,r)*h.get(t,e);for(s=-s/o.get(r,r),t=r;t<n;t++)h.set(t,e,h.get(t,e)+s*o.get(t,r))}}return h}}class C{constructor(t,e={}){if((t=z.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let h,a=Boolean(o),l=Boolean(n),u=!1;if(r<s)if(i){h=t.transpose(),r=h.rows,s=h.columns,u=!0;let e=a;a=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 c=Math.min(r,s),f=Math.min(r+1,s),m=new Float64Array(f),g=new E(r,c),w=new E(s,s),p=new Float64Array(s),d=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let b=Math.min(r-1,s),M=Math.max(0,Math.min(s-2,r)),x=Math.max(b,M);for(let t=0;t<x;t++){if(t<b){m[t]=0;for(let e=t;e<r;e++)m[t]=F(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<b&&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(a&&t<b)for(let e=t;e<r;e++)g.set(e,t,h.get(e,t));if(t<M){p[t]=0;for(let e=t+1;e<s;e++)p[t]=F(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 S=Math.min(s,r+1);if(b<s&&(m[b]=h.get(b,b)),r<S&&(m[S-1]=0),M+1<S&&(p[M]=h.get(M,S-1)),p[S-1]=0,a){for(let t=b;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=b-1;t>=0;t--)if(0!==m[t]){for(let e=t+1;e<c;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<M&&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 v=S-1,A=Number.EPSILON;for(;S>0;){let t,e;for(t=S-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+A*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===S-2)e=4;else{let r;for(r=S-1;r>=t&&r!==t;r--){let e=(r!==S?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(m[r])<=A*e){m[r]=0;break}}r===t?e=3:r===S-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[S-2];p[S-2]=0;for(let r=S-2;r>=t;r--){let o=F(m[r],e),n=m[r]/o,i=e/o;if(m[r]=o,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),l)for(let t=0;t<s;t++)o=n*w.get(t,r)+i*w.get(t,S-1),w.set(t,S-1,-i*w.get(t,r)+n*w.get(t,S-1)),w.set(t,r,o)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let s=t;s<S;s++){let o=F(m[s],e),n=m[s]/o,i=e/o;if(m[s]=o,e=-i*p[s],p[s]=n*p[s],a)for(let e=0;e<r;e++)o=n*g.get(e,s)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,s)+n*g.get(e,t-1)),g.set(e,s,o)}break}case 3:{const e=Math.max(Math.abs(m[S-1]),Math.abs(m[S-2]),Math.abs(p[S-2]),Math.abs(m[t]),Math.abs(p[t])),o=m[S-1]/e,n=m[S-2]/e,i=p[S-2]/e,h=m[t]/e,u=p[t]/e,c=((n+o)*(n-o)+i*i)/2,f=o*i*(o*i);let d=0;0===c&&0===f||(d=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),d=f/(c+d));let y=(h+o)*(h-o)+d,b=h*u;for(let e=t;e<S-1;e++){let o=F(y,b);0===o&&(o=Number.MIN_VALUE);let n=y/o,i=b/o;if(e!==t&&(p[e-1]=o),y=n*m[e]+i*p[e],p[e]=n*p[e]-i*m[e],b=i*m[e+1],m[e+1]=n*m[e+1],l)for(let t=0;t<s;t++)o=n*w.get(t,e)+i*w.get(t,e+1),w.set(t,e+1,-i*w.get(t,e)+n*w.get(t,e+1)),w.set(t,e,o);if(o=F(y,b),0===o&&(o=Number.MIN_VALUE),n=y/o,i=b/o,m[e]=o,y=n*p[e]+i*m[e+1],m[e+1]=-i*p[e]+n*m[e+1],b=i*p[e+1],p[e+1]=n*p[e+1],a&&e<r-1)for(let t=0;t<r;t++)o=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,o)}p[S-2]=y;break}case 4:if(m[t]<=0&&(m[t]=m[t]<0?-m[t]:0,l))for(let e=0;e<=v;e++)w.set(e,t,-w.get(e,t));for(;t<v&&!(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(a&&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++}S--}}if(u){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=E.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 n=this.U,i=this.rightSingularVectors,h=i.mmul(o),a=i.rows,l=n.rows,u=E.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let o=0;o<s;o++)r+=h.get(t,o)*n.get(e,o);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(E.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,s=t.columns,o=new E(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&o.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,h=n.columns,a=new E(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let s=0;s<h;s++)r+=o.get(t,s)*n.get(e,s);a.set(t,e,r)}return a}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 E.diag(this.s)}}function D(t,e,r=!1){return t=z.checkMatrix(t),e=z.checkMatrix(e),r?new C(t).solve(e):t.isSquare()?new I(t).solve(e):new T(t).solve(e)}function V(t,e){let r=[];for(let s=0;s<t;s++)s!==e&&r.push(s);return r}function q(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 W{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=z.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,n=t.columns,i=new E(n,n),h=new Float64Array(n),a=new Float64Array(n),l=t,u=!1;if(u=!!r||t.isSymmetric(),u){for(s=0;s<n;s++)for(o=0;o<n;o++)i.set(s,o,l.get(s,o));!function(t,e,r,s){let o,n,i,h,a,l,u,c;for(a=0;a<t;a++)r[a]=s.get(t-1,a);for(h=t-1;h>0;h--){for(c=0,i=0,l=0;l<h;l++)c+=Math.abs(r[l]);if(0===c)for(e[h]=r[h-1],a=0;a<h;a++)r[a]=s.get(h-1,a),s.set(h,a,0),s.set(a,h,0);else{for(l=0;l<h;l++)r[l]/=c,i+=r[l]*r[l];for(o=r[h-1],n=Math.sqrt(i),o>0&&(n=-n),e[h]=c*n,i-=o*n,r[h-1]=o-n,a=0;a<h;a++)e[a]=0;for(a=0;a<h;a++){for(o=r[a],s.set(a,h,o),n=e[a]+s.get(a,a)*o,l=a+1;l<=h-1;l++)n+=s.get(l,a)*r[l],e[l]+=s.get(l,a)*o;e[a]=n}for(o=0,a=0;a<h;a++)e[a]/=i,o+=e[a]*r[a];for(u=o/(i+i),a=0;a<h;a++)e[a]-=u*r[a];for(a=0;a<h;a++){for(o=r[a],n=e[a],l=a;l<=h-1;l++)s.set(l,a,s.get(l,a)-(o*e[l]+n*r[l]));r[a]=s.get(h-1,a),s.set(h,a,0)}}r[h]=i}for(h=0;h<t-1;h++){if(s.set(t-1,h,s.get(h,h)),s.set(h,h,1),i=r[h+1],0!==i){for(l=0;l<=h;l++)r[l]=s.get(l,h+1)/i;for(a=0;a<=h;a++){for(n=0,l=0;l<=h;l++)n+=s.get(l,h+1)*s.get(l,a);for(l=0;l<=h;l++)s.set(l,a,s.get(l,a)-n*r[l])}}for(l=0;l<=h;l++)s.set(l,h+1,0)}for(a=0;a<t;a++)r[a]=s.get(t-1,a),s.set(t-1,a,0);s.set(t-1,t-1,1),e[0]=0}(n,a,h,i),function(t,e,r,s){let o,n,i,h,a,l,u,c,f,m,g,w,p,d,y,b;for(i=1;i<t;i++)e[i-1]=e[i];e[t-1]=0;let M=0,x=0,S=Number.EPSILON;for(l=0;l<t;l++){for(x=Math.max(x,Math.abs(r[l])+Math.abs(e[l])),u=l;u<t&&!(Math.abs(e[u])<=S*x);)u++;if(u>l)do{for(o=r[l],c=(r[l+1]-o)/(2*e[l]),f=F(c,1),c<0&&(f=-f),r[l]=e[l]/(c+f),r[l+1]=e[l]*(c+f),m=r[l+1],n=o-r[l],i=l+2;i<t;i++)r[i]-=n;for(M+=n,c=r[u],g=1,w=g,p=g,d=e[l+1],y=0,b=0,i=u-1;i>=l;i--)for(p=w,w=g,b=y,o=g*e[i],n=g*c,f=F(c,e[i]),e[i+1]=y*f,y=e[i]/f,g=c/f,c=g*r[i]-y*o,r[i+1]=n+y*(g*o+y*r[i]),a=0;a<t;a++)n=s.get(a,i+1),s.set(a,i+1,y*s.get(a,i)+g*n),s.set(a,i,g*s.get(a,i)-y*n);c=-y*b*p*d*e[l]/m,e[l]=y*c,r[l]=g*c}while(Math.abs(e[l])>S*x);r[l]=r[l]+M,e[l]=0}for(i=0;i<t-1;i++){for(a=i,c=r[i],h=i+1;h<t;h++)r[h]<c&&(a=h,c=r[h]);if(a!==i)for(r[a]=r[i],r[i]=c,h=0;h<t;h++)c=s.get(h,i),s.set(h,i,s.get(h,a)),s.set(h,a,c)}}(n,a,h,i)}else{let t=new E(n,n),e=new Float64Array(n);for(o=0;o<n;o++)for(s=0;s<n;s++)t.set(s,o,l.get(s,o));!function(t,e,r,s){let o,n,i,h,a,l,u,c=t-1;for(l=1;l<=c-1;l++){for(u=0,h=l;h<=c;h++)u+=Math.abs(e.get(h,l-1));if(0!==u){for(i=0,h=c;h>=l;h--)r[h]=e.get(h,l-1)/u,i+=r[h]*r[h];for(n=Math.sqrt(i),r[l]>0&&(n=-n),i-=r[l]*n,r[l]=r[l]-n,a=l;a<t;a++){for(o=0,h=c;h>=l;h--)o+=r[h]*e.get(h,a);for(o/=i,h=l;h<=c;h++)e.set(h,a,e.get(h,a)-o*r[h])}for(h=0;h<=c;h++){for(o=0,a=c;a>=l;a--)o+=r[a]*e.get(h,a);for(o/=i,a=l;a<=c;a++)e.set(h,a,e.get(h,a)-o*r[a])}r[l]=u*r[l],e.set(l,l-1,u*n)}}for(h=0;h<t;h++)for(a=0;a<t;a++)s.set(h,a,h===a?1:0);for(l=c-1;l>=1;l--)if(0!==e.get(l,l-1)){for(h=l+1;h<=c;h++)r[h]=e.get(h,l-1);for(a=l;a<=c;a++){for(n=0,h=l;h<=c;h++)n+=r[h]*s.get(h,a);for(n=n/r[l]/e.get(l,l-1),h=l;h<=c;h++)s.set(h,a,s.get(h,a)+n*r[h])}}}(n,t,e,i),function(t,e,r,s,o){let n,i,h,a,l,u,c,f,m,g,w,p,d,y,b,M=t-1,x=t-1,S=Number.EPSILON,E=0,v=0,A=0,N=0,R=0,k=0,z=0,I=0;for(n=0;n<t;n++)for((n<0||n>x)&&(r[n]=o.get(n,n),e[n]=0),i=Math.max(n-1,0);i<t;i++)v+=Math.abs(o.get(n,i));for(;M>=0;){for(a=M;a>0&&(k=Math.abs(o.get(a-1,a-1))+Math.abs(o.get(a,a)),0===k&&(k=v),!(Math.abs(o.get(a,a-1))<S*k));)a--;if(a===M)o.set(M,M,o.get(M,M)+E),r[M]=o.get(M,M),e[M]=0,M--,I=0;else if(a===M-1){if(c=o.get(M,M-1)*o.get(M-1,M),A=(o.get(M-1,M-1)-o.get(M,M))/2,N=A*A+c,z=Math.sqrt(Math.abs(N)),o.set(M,M,o.get(M,M)+E),o.set(M-1,M-1,o.get(M-1,M-1)+E),f=o.get(M,M),N>=0){for(z=A>=0?A+z:A-z,r[M-1]=f+z,r[M]=r[M-1],0!==z&&(r[M]=f-c/z),e[M-1]=0,e[M]=0,f=o.get(M,M-1),k=Math.abs(f)+Math.abs(z),A=f/k,N=z/k,R=Math.sqrt(A*A+N*N),A/=R,N/=R,i=M-1;i<t;i++)z=o.get(M-1,i),o.set(M-1,i,N*z+A*o.get(M,i)),o.set(M,i,N*o.get(M,i)-A*z);for(n=0;n<=M;n++)z=o.get(n,M-1),o.set(n,M-1,N*z+A*o.get(n,M)),o.set(n,M,N*o.get(n,M)-A*z);for(n=0;n<=x;n++)z=s.get(n,M-1),s.set(n,M-1,N*z+A*s.get(n,M)),s.set(n,M,N*s.get(n,M)-A*z)}else r[M-1]=f+A,r[M]=f+A,e[M-1]=z,e[M]=-z;M-=2,I=0}else{if(f=o.get(M,M),m=0,c=0,a<M&&(m=o.get(M-1,M-1),c=o.get(M,M-1)*o.get(M-1,M)),10===I){for(E+=f,n=0;n<=M;n++)o.set(n,n,o.get(n,n)-f);k=Math.abs(o.get(M,M-1))+Math.abs(o.get(M-1,M-2)),f=m=.75*k,c=-.4375*k*k}if(30===I&&(k=(m-f)/2,k=k*k+c,k>0)){for(k=Math.sqrt(k),m<f&&(k=-k),k=f-c/((m-f)/2+k),n=0;n<=M;n++)o.set(n,n,o.get(n,n)-k);E+=k,f=m=c=.964}for(I+=1,l=M-2;l>=a&&(z=o.get(l,l),R=f-z,k=m-z,A=(R*k-c)/o.get(l+1,l)+o.get(l,l+1),N=o.get(l+1,l+1)-z-R-k,R=o.get(l+2,l+1),k=Math.abs(A)+Math.abs(N)+Math.abs(R),A/=k,N/=k,R/=k,l!==a)&&!(Math.abs(o.get(l,l-1))*(Math.abs(N)+Math.abs(R))<S*(Math.abs(A)*(Math.abs(o.get(l-1,l-1))+Math.abs(z)+Math.abs(o.get(l+1,l+1)))));)l--;for(n=l+2;n<=M;n++)o.set(n,n-2,0),n>l+2&&o.set(n,n-3,0);for(h=l;h<=M-1&&(y=h!==M-1,h!==l&&(A=o.get(h,h-1),N=o.get(h+1,h-1),R=y?o.get(h+2,h-1):0,f=Math.abs(A)+Math.abs(N)+Math.abs(R),0!==f&&(A/=f,N/=f,R/=f)),0!==f);h++)if(k=Math.sqrt(A*A+N*N+R*R),A<0&&(k=-k),0!==k){for(h!==l?o.set(h,h-1,-k*f):a!==l&&o.set(h,h-1,-o.get(h,h-1)),A+=k,f=A/k,m=N/k,z=R/k,N/=A,R/=A,i=h;i<t;i++)A=o.get(h,i)+N*o.get(h+1,i),y&&(A+=R*o.get(h+2,i),o.set(h+2,i,o.get(h+2,i)-A*z)),o.set(h,i,o.get(h,i)-A*f),o.set(h+1,i,o.get(h+1,i)-A*m);for(n=0;n<=Math.min(M,h+3);n++)A=f*o.get(n,h)+m*o.get(n,h+1),y&&(A+=z*o.get(n,h+2),o.set(n,h+2,o.get(n,h+2)-A*R)),o.set(n,h,o.get(n,h)-A),o.set(n,h+1,o.get(n,h+1)-A*N);for(n=0;n<=x;n++)A=f*s.get(n,h)+m*s.get(n,h+1),y&&(A+=z*s.get(n,h+2),s.set(n,h+2,s.get(n,h+2)-A*R)),s.set(n,h,s.get(n,h)-A),s.set(n,h+1,s.get(n,h+1)-A*N)}}}if(0!==v){for(M=t-1;M>=0;M--)if(A=r[M],N=e[M],0===N)for(a=M,o.set(M,M,1),n=M-1;n>=0;n--){for(c=o.get(n,n)-A,R=0,i=a;i<=M;i++)R+=o.get(n,i)*o.get(i,M);if(e[n]<0)z=c,k=R;else if(a=n,0===e[n]?o.set(n,M,0!==c?-R/c:-R/(S*v)):(f=o.get(n,n+1),m=o.get(n+1,n),N=(r[n]-A)*(r[n]-A)+e[n]*e[n],u=(f*k-z*R)/N,o.set(n,M,u),o.set(n+1,M,Math.abs(f)>Math.abs(z)?(-R-c*u)/f:(-k-m*u)/z)),u=Math.abs(o.get(n,M)),S*u*u>1)for(i=n;i<=M;i++)o.set(i,M,o.get(i,M)/u)}else if(N<0)for(a=M-1,Math.abs(o.get(M,M-1))>Math.abs(o.get(M-1,M))?(o.set(M-1,M-1,N/o.get(M,M-1)),o.set(M-1,M,-(o.get(M,M)-A)/o.get(M,M-1))):(b=P(0,-o.get(M-1,M),o.get(M-1,M-1)-A,N),o.set(M-1,M-1,b[0]),o.set(M-1,M,b[1])),o.set(M,M-1,0),o.set(M,M,1),n=M-2;n>=0;n--){for(g=0,w=0,i=a;i<=M;i++)g+=o.get(n,i)*o.get(i,M-1),w+=o.get(n,i)*o.get(i,M);if(c=o.get(n,n)-A,e[n]<0)z=c,R=g,k=w;else if(a=n,0===e[n]?(b=P(-g,-w,c,N),o.set(n,M-1,b[0]),o.set(n,M,b[1])):(f=o.get(n,n+1),m=o.get(n+1,n),p=(r[n]-A)*(r[n]-A)+e[n]*e[n]-N*N,d=2*(r[n]-A)*N,0===p&&0===d&&(p=S*v*(Math.abs(c)+Math.abs(N)+Math.abs(f)+Math.abs(m)+Math.abs(z))),b=P(f*R-z*g+N*w,f*k-z*w-N*g,p,d),o.set(n,M-1,b[0]),o.set(n,M,b[1]),Math.abs(f)>Math.abs(z)+Math.abs(N)?(o.set(n+1,M-1,(-g-c*o.get(n,M-1)+N*o.get(n,M))/f),o.set(n+1,M,(-w-c*o.get(n,M)-N*o.get(n,M-1))/f)):(b=P(-R-m*o.get(n,M-1),-k-m*o.get(n,M),z,N),o.set(n+1,M-1,b[0]),o.set(n+1,M,b[1]))),u=Math.max(Math.abs(o.get(n,M-1)),Math.abs(o.get(n,M))),S*u*u>1)for(i=n;i<=M;i++)o.set(i,M-1,o.get(i,M-1)/u),o.set(i,M,o.get(i,M)/u)}for(n=0;n<t;n++)if(n<0||n>x)for(i=n;i<t;i++)s.set(n,i,o.get(n,i));for(i=t-1;i>=0;i--)for(n=0;n<=x;n++){for(z=0,h=0;h<=Math.min(i,x);h++)z+=s.get(n,h)*o.get(h,i);s.set(n,i,z)}}}(n,a,h,i,t)}this.n=n,this.e=a,this.d=h,this.V=i}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,n=new E(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)n.set(t,e,0);n.set(t,t,o[t]),s[t]>0?n.set(t,t+1,s[t]):s[t]<0&&n.set(t,t-1,s[t])}return n}}function P(t,e,r,s){let o,n;return Math.abs(r)>Math.abs(s)?(o=s/r,n=r+o*s,[(t+o*e)/n,(e-o*t)/n]):(o=r/s,n=s+o*r,[(o*t+e)/n,(o*e-t)/n])}class O{constructor(t){if(!(t=z.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,s,o=t,n=o.rows,i=new E(n,n),h=!0;for(r=0;r<n;r++){let t=0;for(s=0;s<r;s++){let n=0;for(e=0;e<s;e++)n+=i.get(s,e)*i.get(r,e);n=(o.get(r,s)-n)/i.get(s,s),i.set(r,s,n),t+=n*n}for(t=o.get(r,r)-t,h&&=t>0,i.set(r,r,Math.sqrt(Math.max(t,0))),s=r+1;s<n;s++)i.set(r,s,0)}this.L=i,this.positiveDefinite=h}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=z.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,n,i=t.columns,h=t.clone();for(n=0;n<r;n++)for(o=0;o<i;o++){for(s=0;s<n;s++)h.set(n,o,h.get(n,o)-h.get(s,o)*e.get(n,s));h.set(n,o,h.get(n,o)/e.get(n,n))}for(n=r-1;n>=0;n--)for(o=0;o<i;o++){for(s=n+1;s<r;s++)h.set(n,o,h.get(n,o)-h.get(s,o)*e.get(s,n));h.set(n,o,h.get(n,o)/e.get(n,n))}return h}get lowerTriangularMatrix(){return this.L}}class j{constructor(t,e={}){t=z.checkMatrix(t);let{Y:r}=e;const{scaleScores:o=!1,maxIterations:n=1e3,terminationCriteria:i=1e-10}=e;let h;if(r){if(r=s.isAnyArray(r)&&"number"==typeof r[0]?E.columnVector(r):z.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");h=r.getColumnVector(0)}else h=t.getColumnVector(0);let a,l,u,c,f=1;for(let e=0;e<n&&f>i;e++)u=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),u=u.div(u.norm()),a=t.mmul(u).div(u.transpose().mmul(u).get(0,0)),e>0&&(f=a.clone().sub(c).pow(2).sum()),c=a.clone(),r?(l=r.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),l=l.div(l.norm()),h=r.mmul(l).div(l.transpose().mmul(l).get(0,0))):h=a;if(r){let e=t.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0));e=e.div(e.norm());let s=t.clone().sub(a.clone().mmul(e.transpose())),o=h.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),n=r.clone().sub(a.clone().mulS(o.get(0,0)).mmul(l.transpose()));this.t=a,this.p=e.transpose(),this.w=u.transpose(),this.q=l,this.u=h,this.s=a.transpose().mmul(a),this.xResidual=s,this.yResidual=n,this.betas=o}else this.w=u.transpose(),this.s=a.transpose().mmul(a).sqrt(),this.t=o?a.clone().div(this.s.get(0,0)):a,this.xResidual=t.sub(a.mmul(u.transpose()))}}e.y3=M,e.jy=O,e.oN=O,e.Hc=A,e.cg=W,e.hj=W,e.LU=I,e.Tb=I,e.uq=E,e.Zm=class extends N{constructor(t,e){w(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])}},e.Dq=class extends N{constructor(t,e){c(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)}},e.__=class extends N{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)}},e.q0=class extends N{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)}},e.lh=class extends N{constructor(t,e){g(t,e),super(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)}},e.pI=class extends N{constructor(t,e){u(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)}},e.zC=R,e.zg=class extends N{constructor(t,e,r,s,o){p(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)}},e.g6=class extends N{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)}},e.OL=j,e.ks=j,e.QR=T,e.jp=T,e.mk=C,e.W2=C,e.l=v,e.KY=k,e.dv=z,e.BR=function(t,e=t,r={}){t=new E(t);let o=!1;if("object"!=typeof e||E.isMatrix(e)||s.isAnyArray(e)?e=new E(e):(r=e,e=t,o=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:i=!0}=r;n&&(t.center("column"),o||e.center("column")),i&&(t.scale("column"),o||e.scale("column"));const h=t.standardDeviation("column",{unbiased:!0}),a=o?h:e.standardDeviation("column",{unbiased:!0}),l=t.transpose().mmul(e);for(let e=0;e<l.rows;e++)for(let r=0;r<l.columns;r++)l.set(e,r,l.get(e,r)*(1/(h[e]*a[r]))*(1/(t.rows-1)));return l},e.Wu=function(t,e=t,r={}){t=new E(t);let o=!1;if("object"!=typeof e||E.isMatrix(e)||s.isAnyArray(e)?e=new E(e):(r=e,e=t,o=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=r;n&&(t=t.center("column"),o||(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},e.a4=function t(e){if((e=E.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,s,o,n;if(2===e.columns)return r=e.get(0,0),s=e.get(0,1),o=e.get(1,0),n=e.get(1,1),r*n-s*o;if(3===e.columns){let n,i,h;return n=new R(e,[1,2],[1,2]),i=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(n)-s*t(i)+o*t(h)}return new I(e).determinant}throw Error("determinant can only be calculated for a square matrix")},e.DI=function(t,e=!1){return t=z.checkMatrix(t),e?new C(t).inverse():D(t,E.eye(t.rows))},e.Jo=function(t,e={}){const{thresholdValue:r=1e-9,thresholdError:s=1e-9}=e;let o=(t=E.checkMatrix(t)).rows,n=new E(o,o);for(let e=0;e<o;e++){let i=E.columnVector(t.getRow(e)),h=t.subMatrixRow(V(o,e)).transpose(),a=new C(h).solve(i),l=E.sub(i,h.mmul(a)).abs().max();n.setRow(e,q(l,a,e,r,s))}return n},e.Zi=function(t,e=Number.EPSILON){if((t=E.checkMatrix(t)).isEmpty())return t.transpose();let r=new C(t,{autoTranspose:!0}),s=r.leftSingularVectors,o=r.rightSingularVectors,n=r.diagonal;for(let t=0;t<n.length;t++)Math.abs(n[t])>e?n[t]=1/n[t]:n[t]=0;return o.mmul(E.diag(n).mmul(s.transpose()))},e.kH=D,e.LV=function(t,e){if(s.isAnyArray(t))return t[0]&&s.isAnyArray(t[0])?new z(t):new k(t,e);throw new Error("the argument is not an array")}},718(t,e,r){"use strict";r.r(e),r.d(e,{default:()=>o});var s=r(788);function o(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,s.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!(0,s.isAnyArray)(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,s.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,n=e.toIndex,i=void 0===n?t.length:n;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=o||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,s.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,n=e.toIndex,i=void 0===n?t.length:n;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=o||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(o===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,h=void 0===i?r.autoMinMax?o:0:i,a=r.max,l=void 0===a?r.autoMinMax?n:1:a;if(h>=l)throw new RangeError("min option must be smaller than max option");for(var u=(l-h)/(n-o),c=0;c<t.length;c++)e[c]=(t[c]-o)*u+h;return e}},788(t,e,r){"use strict";r.r(e),r.d(e,{isAnyArray:()=>o});const s=Object.prototype.toString;function o(t){const e=s.call(t);return e.endsWith("Array]")&&!e.includes("Big")}}},e={};function r(s){var o=e[s];if(void 0!==o)return o.exports;var n=e[s]={exports:{}};return t[s](n,n.exports,r),n.exports}r.d=(t,e)=>{for(var s in e)r.o(e,s)&&!r.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{"use strict";function t(t,e){return Math.floor(e()*t)}function e(t){return t()}function o(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function n(t){return o(t).map((t,e)=>e)}function i(t,e){return o(t).map(()=>e)}function h(t){return i(t,0)}function a(t){return function(t){return t.reduce((t,e)=>t+e)}(t)/t.length}function l(t){let e=0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e}function u(e,r,s){const o=h(e);for(let n=0;n<e;n++){let e=!0;for(;e;){const i=t(r,s);let h=!1;for(let t=0;t<n;t++)if(i===o[t]){h=!0;break}h||(e=!1),o[n]=i}}return o}function c(t,e,r){const s=[];let o=0,n=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let i=0;i<e;i++){const e=[];for(let s=0;s<r;s++)e.push(t[n]),n+=1;s.push(e),o+=1}return s}function f(t,e){const r=r=>o(t).map(()=>i(e,r)),s=[];return s.push(r(-1)),s.push(r(1/0)),s.push(r(0)),s}function m(e,r,s){const o=h(e);for(let n=0;n<e;n++){let e=!0,i=0;for(;e;){i=t(r,s);let h=!1;for(let t=0;t<n;t++)if(i===o[t]){h=!0;break}h||(e=!1)}o[n]=i}return o}function g(t,e,r,s,o){e=Math.floor(e);const n=t[0][e],i=t[1][e];if(t[2][e],r>=i[0])return 0;for(let t=0;t<n.length;t++)if(s===n[t])return 0;return w(t,e,r,s,o)}function w(t,e,r,s,o){const n=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,n[0]=s,h[0]=o;let a=0,l=0;for(;;){const e=2*a+1,s=e+1,o=t[0][0].length;if(e>=o)break;if(s>=o){if(!(i[e]>r))break;l=e}else if(i[e]>=i[s]){if(!(r<i[e]))break;l=e}else{if(!(r<i[s]))break;l=s}i[a]=i[l],n[a]=n[l],h[a]=h[l],a=l}return i[a]=r,n[a]=s,h[a]=o,1}function p(t,r,s,o,n){const i=f(r,o);for(let o=0;o<r;o++)for(let r=0;r<s;r++){if(t[0][o][r]<0)continue;const s=t[0][o][r],h=t[2][o][r],a=e(n);g(i,o,a,s,h),g(i,s,a,o,h),t[2][o][r]=0}return i}function d(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const s=e[t],o=r[t];for(let t=0;t<s.length-1;t++){const e=s.length-t-1,r=o.length-t-1,n=s[0];s[0]=s[e],s[e]=n;const i=o[0];o[0]=o[r],o[r]=i,y(o,s,r,0)}}return{indices:e,weights:r}}function y(t,e,r,s){for(;2*s+1<r;){const o=2*s+1,n=o+1;let i=s;if(t[i]<t[o]&&(i=o),n<r&&t[i]<t[n]&&(i=n),i===s)break;{const r=t[s];t[s]=t[i],t[i]=r;const o=e[s];e[s]=e[i],e[i]=o,s=i}}}function b(t,e){const r=t[0][e],s=t[1][e],o=t[2][e];let n=1/0,i=-1;for(let t=0;t>r.length;t++)1===o[t]&&s[t]<n&&(n=s[t],i=t);return i>=0?(o[i]=0,Math.floor(r[i])):-1}r.r(s),r.d(s,{UMAP:()=>ht,initWasm:()=>C,isWasmAvailable:()=>D});class M{constructor(t,e,r,s){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=s[0],this.nCols=s[1];for(let s=0;s<r.length;s++){const o=t[s],n=e[s];this.checkDims(o,n);const i=this.makeKey(o,n);this.entries.set(i,{value:r[s],row:o,col:n})}}makeKey(t,e){return`${t}:${e}`}checkDims(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")}set(t,e,r){this.checkDims(t,e);const s=this.makeKey(t,e);this.entries.has(s)?this.entries.get(s).value=r:this.entries.set(s,{value:r,row:t,col:e})}get(t,e,r=0){this.checkDims(t,e);const s=this.makeKey(t,e);return this.entries.has(s)?this.entries.get(s).value:r}getAll(t=!0){const e=[];return this.entries.forEach(t=>{e.push(t)}),t&&e.sort((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row),e}getDims(){return[this.nRows,this.nCols]}getRows(){return Array.from(this.entries,([t,e])=>e.row)}getCols(){return Array.from(this.entries,([t,e])=>e.col)}getValues(){return Array.from(this.entries,([t,e])=>e.value)}forEach(t){this.entries.forEach(e=>t(e.value,e.row,e.col))}map(t){let e=[];this.entries.forEach(r=>{e.push(t(r.value,r.row,r.col))});const r=[this.nRows,this.nCols];return new M(this.getRows(),this.getCols(),e,r)}toArray(){const t=o(this.nRows).map(()=>h(this.nCols));return this.entries.forEach(e=>{t[e.row][e.col]=e.value}),t}}function x(t){const e=[],r=[],s=[];t.forEach((t,o,n)=>{e.push(o),r.push(n),s.push(t)});const o=[t.nCols,t.nRows];return new M(r,e,s,o)}function S(t,e){return z(t,e,(t,e)=>t*e)}function E(t,e){return z(t,e,(t,e)=>t+e)}function v(t,e){return z(t,e,(t,e)=>t-e)}function A(t,e){return t.map(t=>t*e)}function N(t){const e=new Set,r=t.getValues(),s=t.getRows(),o=t.getCols();for(let t=0;t<r.length;t++)0===r[t]&&e.add(t);const n=(t,r)=>!e.has(r),i=r.filter(n),h=s.filter(n),a=o.filter(n);return new M(h,a,i,t.getDims())}function R(t,e="l2"){const r=k[e],s=new Map;t.forEach((t,e,r)=>{const o=s.get(e)||[];o.push(r),s.set(e,o)});const o=new M([],[],[],t.getDims());for(let e of s.keys()){const n=s.get(e).sort(),i=r(n.map(r=>t.get(e,r)));for(let t=0;t<i.length;t++)o.set(e,n[t],i[t])}return o}const k={max:t=>{let e=-1/0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map(t=>t/e)},l1:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r];return t.map(t=>t/e)},l2:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r]**2;return t.map(t=>Math.sqrt(t**2/e))}};function z(t,e,r){const s=new Set,o=[],n=[],i=[],h=(s,h)=>{o.push(s),n.push(h);const a=r(t.get(s,h),e.get(s,h));i.push(a)},a=t.getValues(),l=t.getRows(),u=t.getCols();for(let t=0;t<a.length;t++){const e=l[t],r=u[t],o=`${e}:${r}`;s.add(o),h(e,r)}const c=e.getValues(),f=e.getRows(),m=e.getCols();for(let t=0;t<c.length;t++){const e=f[t],r=m[t],o=`${e}:${r}`;s.has(o)||h(e,r)}const g=[t.nRows,t.nCols];return new M(o,n,i,g)}function I(t){const e=[];t.forEach((t,r,s)=>{e.push({value:t,row:r,col:s})}),e.sort((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row);const r=[],s=[],o=[];let n=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==n&&(n=i,o.push(t)),r.push(h),s.push(a)}return{indices:r,values:s,indptr:o}}let F=null,T=null;async function C(){return F||(F=(async()=>{try{let t;if("undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node){const e=["..","wasm","pkg","node","umap_wasm_core.js"].join("/");t=await r(433)(e)}else try{const e=["..","wasm","pkg","web","umap_wasm_core.js"].join("/");t=await r(433)(e)}catch(e){const r=`${"undefined"!=typeof window&&window.location?window.location.origin:""}/wasm/pkg/web/umap_wasm_core.js`;t=await new Function("p","return import(p)")(r)}return"function"==typeof t.default&&await t.default(),T=t,t}catch(t){throw F=null,T=null,new Error(`Failed to load WASM module: ${t}`)}})(),F)}function D(){return null!==T}function V(t,e){if(!T)throw new Error("WASM module not initialized");const r=new Float64Array(t),s=new Float64Array(e);return T.euclidean(r,s)}function q(t,e,r,s,o){if(!T)throw new Error("WASM module not initialized");const n=new Float64Array(e*r);for(let s=0;s<e;s++)for(let e=0;e<r;e++)n[s*r+e]=t[s][e];return T.build_rp_tree(n,e,r,s,BigInt(o))}function W(t,e,r,s,o){if(!T)throw new Error("WASM module not initialized");const n=new Int32Array(t),i=new Int32Array(e),h=new Float64Array(r);return new T.WasmSparseMatrix(n,i,h,s,o)}function P(t){if(!T)throw new Error("WASM module not initialized");return T.sparse_transpose(t)}function O(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_add(t,e)}function j(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_subtract(t,e)}function L(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_pairwise_multiply(t,e)}function _(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_multiply_scalar(t,e)}function $(t){const e=Array.from(t.get_all_ordered()),r=[];for(let t=0;t<e.length;t+=3)r.push({row:e[t],col:e[t+1],value:e[t+2]});return r}class U{constructor(t,e,r,s){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=s}static fromWasm(t){const e=function(t){const e=Array.from(t.hyperplanes()),r=Array.from(t.offsets()),s=Array.from(t.children()),o=Array.from(t.indices()),n=t.dim(),i=t.n_nodes(),h=[];for(let t=0;t<i;t++)h.push(e.slice(t*n,(t+1)*n));const a=[];for(let t=0;t<i;t++)a.push([s[2*t],s[2*t+1]]);let l=0;for(let t=0;t<s.length;t++){const e=s[t];if(e<=0){const t=-e;t>l&&(l=t)}}const u=l+1,c=u>0?Math.floor(o.length/u):0,f=[];for(let t=0;t<u;t++){const e=o.slice(t*c,(t+1)*c);for(;e.length<c;)e.push(-1);f.push(e)}return{hyperplanes:h,offsets:r,children:a,indices:f}}(t),r=new U(e.hyperplanes,e.offsets,e.children,e.indices);return r.wasmTree=t,r}getWasmTree(){return this.wasmTree}dispose(){this.wasmTree&&(this.wasmTree.free(),this.wasmTree=void 0)}}function B(t,e,r,s,o=!1){const i=Math.max(10,e);if(o){if(!D())throw new Error("WASM requested but not available");return function(t,e,r,s){const o=t.length,n=t[0].length,i=[];for(let h=0;h<r;h++){const r=q(t,o,n,e,Math.floor(4294967295*s()));i.push(U.fromWasm(r))}return i}(t,i,r,s)}const a=n(r).map((e,r)=>function(t,e=30,r,s){return K(t,n(t.length),e,r,s)}(t,i,r,s)),l=a.map(t=>function(t,e){const r=Q(t),s=Y(t),o=n(r).map(()=>h(t.hyperplane?t.hyperplane.length:0)),i=h(r),a=n(r).map(()=>[-1,-1]),l=n(s).map(()=>n(e).map(()=>-1));return G(t,o,i,a,l,0,0),new U(o,i,a,l)}(t,i));return l}function K(e,r,s=30,o,n){if(r.length>s){const i=function(e,r,s){const o=e[0].length;let n=t(r.length,s),i=t(r.length,s);i+=n===i?1:0,i%=r.length;const a=r[n],l=r[i];let u=0;const c=h(o);for(let t=0;t<c.length;t++)c[t]=e[a][t]-e[l][t],u-=c[t]*(e[a][t]+e[l][t])/2;let f=0,m=0;const g=h(r.length);for(let n=0;n<r.length;n++){let i=u;for(let t=0;t<o;t++)i+=c[t]*e[r[n]][t];0===i?(g[n]=t(2,s),0===g[n]?f+=1:m+=1):i>0?(g[n]=0,f+=1):(g[n]=1,m+=1)}const w=h(f),p=h(m);f=0,m=0;for(let t=0;t<g.length;t++)0===g[t]?(w[f]=r[t],f+=1):(p[m]=r[t],m+=1);return{indicesLeft:w,indicesRight:p,hyperplane:c,offset:u}}(e,r,n),{indicesLeft:a,indicesRight:l,hyperplane:u,offset:c}=i;return{leftChild:K(e,a,s,o+1,n),rightChild:K(e,l,s,o+1,n),isLeaf:!1,hyperplane:u,offset:c}}return{indices:r,isLeaf:!0}}function G(t,e,r,s,o,n,i){if(t.isLeaf)return s[n][0]=-i,o[i].splice(0,t.indices.length,...t.indices),{nodeNum:n,leafNum:i+=1};{e[n]=t.hyperplane,r[n]=t.offset,s[n][0]=n+1;const h=n;let a=G(t.leftChild,e,r,s,o,n+1,i);return n=a.nodeNum,i=a.leafNum,s[h][1]=n+1,a=G(t.rightChild,e,r,s,o,n+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function Q(t){return t.isLeaf?1:1+Q(t.leftChild)+Q(t.rightChild)}function Y(t){return t.isLeaf?1:Y(t.leftChild)+Y(t.rightChild)}function X(e,r,s,o){let n=r;for(let t=0;t<s.length;t++)n+=e[t]*s[t];return 0===n?t(2,o):n>0?0:1}function J(t,e,r){const s=e.getWasmTree();if(s&&D())return function(t,e,r){if(!T)throw new Error("WASM module not initialized");const s=new Float64Array(e),o=T.search_flat_tree(t,s,BigInt(r));return Array.from(o)}(s,t,Math.floor(4294967295*r()));let o=0;for(;e.children[o][0]>0;)o=0===X(e.hyperplanes[o],e.offsets[o],t,r)?e.children[o][0]:e.children[o][1];const n=-1*e.children[o][0];return e.indices[n]}const H=Object.prototype.toString;function Z(t){return H.call(t).endsWith("Array]")}function tt(t,e,r){let s=0;const o=r(e);for(let e=0;e<t.x.length;e++)s+=Math.abs(t.y[e]-o(t.x[e]));return s}var et=r(673);et.y3,et.jy,et.oN,et.Hc,et.cg,et.hj,et.LU,et.Tb;const rt=et.uq,st=(et.Zm,et.Dq,et.__,et.q0,et.lh,et.pI,et.zC,et.zg,et.g6,et.OL,et.ks,et.QR,et.jp,et.mk,et.W2,et.l,et.KY,et.dv,et.BR,et.Wu,et.uq,et.uq,et.a4,et.DI);function ot(t,e,r,s,o){let n=r*s*s,i=rt.eye(e.length,e.length,n);const h=o(e);let a=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)a[e]=h(t.x[e]);let l=function(t,e,r,s,o){const n=r.length,i=t.x.length;let h=new Array(n);for(let a=0;a<n;a++){h[a]=new Array(i);let n=r.slice();n[a]+=s;let l=o(n);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new rt(h)}(t,a,e,s,o),u=function(t,e){const r=t.x.length;let s=new Array(r);for(let o=0;o<r;o++)s[o]=[t.y[o]-e[o]];return new rt(s)}(t,a),c=st(i.add(l.mmul(l.transpose())));return(e=(e=new rt([e])).sub(c.mmul(l).mmul(u).mul(s).transpose())).to1DArray()}et.Jo,et.Zi,et.kH,et.LV;const nt=1e-5,it=.001;class ht{constructor(t={}){this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=at,this.useWasmDistance=!1,this.useWasmNNDescent=!1,this.useWasmMatrix=!1,this.useWasmOptimizer=!1,this.useWasmTree=!1,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new lt,this.wasmOptimizerState=null,this.rngState=BigInt(Math.floor(4294967295*Math.random()));const e=e=>{void 0!==t[e]&&(this[e]=t[e])};e("distanceFn"),e("useWasmDistance"),e("useWasmNNDescent"),e("useWasmMatrix"),e("useWasmTree"),e("useWasmOptimizer"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize")}fit(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding}async fitAsync(t,e=()=>!0){return this.initializeFit(t),await this.optimizeLayoutAsync(e),this.embedding}setSupervisedProjection(t,e={}){this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors}setPrecomputedKNN(t,e){this.knnIndices=t,this.knnDistances=e}initializeFit(t){if(t.length<=this.nNeighbors)throw new Error(`Not enough data points (${t.length}) to create nNeighbors: ${this.nNeighbors}. Add more data points or adjust the configuration.`);if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){const e=this.nearestNeighbors(t);this.knnIndices=e.knnIndices,this.knnDistances=e.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();const{head:e,tail:r,epochsPerSample:s}=this.initializeSimplicialSetEmbedding();return this.optimizationState.head=e,this.optimizationState.tail=r,this.optimizationState.epochsPerSample=s,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()}makeSearchFns(){const t=(t,e)=>{if(this.useWasmDistance){if(!D())throw new Error("WASM distance requested via `useWasmDistance: true` but the wasm module is not initialized or available. Call `await wasmBridge.initWasm()` before using UMAP with wasm distances or build the wasm package.");return V(t,e)}return this.distanceFn(t,e)},{initFromTree:e,initFromRandom:r}=(s=t,{initFromRandom:function(t,e,r,o,n){for(let i=0;i<r.length;i++){const h=u(t,e.length,n);for(let t=0;t<h.length;t++)h[t]<0||g(o,i,s(e[h[t]],r[i]),h[t],1)}},initFromTree:function(t,e,r,o,n){for(let i=0;i<r.length;i++){const h=J(r[i],t,n);for(let t=0;t<h.length;t++){if(h[t]<0)return;g(o,i,s(e[h[t]],r[i]),h[t],1)}}}});var s;this.initFromTree=e,this.initFromRandom=r,this.search=function(t){return function(e,r,s,o){const{indices:n,indptr:i}=I(r);for(let r=0;r<o.length;r++){const h=new Set(s[0][r]);for(;;){const a=b(s,r);if(-1===a)break;const l=n.slice(i[a],i[a+1]);for(const n of l)n===a||-1===n||h.has(n)||(w(s,r,t(e[n],o[r]),n,1),h.add(n))}}return s}}(t)}computeDistance(t,e){if(this.useWasmDistance){if(!D())throw new Error("WASM distance requested via `useWasmDistance: true` but the wasm module is not initialized or available. Call `await wasmBridge.initWasm()` before using UMAP with wasm distances or build the wasm package.");return V(t,e)}return this.distanceFn(t,e)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,s=[t.length,t.length],o=new M([],[],[],s);for(let t=0;t<e.length;t++){const s=e[t],n=r[t];for(let e=0;e<s.length;e++){const r=s[e],i=n[e];i>0&&o.set(t,r,i)}}return z(o,x(o),(t,e)=>t>e?t:e)}transform(t){const e=this.X;if(void 0===e||0===e.length)throw new Error("No data has been fit.");let r=Math.floor(this.nNeighbors*this.transformQueueSize);r=Math.min(e.length,r);const s=function(t,e,r,s,o,n,i){const h=f(r.length,s);if(o(s,e,r,h,i),t)for(let s of t)n(s,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),o=this.search(e,this.searchGraph,s,t);let{indices:n,weights:i}=d(o);n=n.map(t=>t.slice(0,this.nNeighbors)),i=i.map(t=>t.slice(0,this.nNeighbors));const a=Math.max(0,this.localConnectivity-1),{sigmas:l,rhos:u}=this.smoothKNNDistance(i,this.nNeighbors,a),{rows:m,cols:g,vals:w}=this.computeMembershipStrengths(n,i,l,u),p=[t.length,e.length];let y=new M(m,g,w,p);const b=I(R(y,"l1")),x=t.length,S=function(t,e,r){const s=h(t.length).map(t=>h(r[0].length));for(let o=0;o<t.length;o++)for(let n=0;n<t[0].length;n++)for(let i=0;i<r[0].length;i++){const h=t[o][n];s[o][i]+=e[o][n]*r[h][i]}return s}(c(b.indices,x,this.nNeighbors),c(b.values,x,this.nNeighbors),this.embedding),E=this.nEpochs?this.nEpochs/3:y.nRows<=1e4?100:30,v=y.getValues().reduce((t,e)=>e>t?e:t,0);y=y.map(t=>t<v/E?0:t),y=N(y);const A=this.makeEpochsPerSample(y.getValues(),E),k=y.getRows(),z=y.getCols();return this.assignOptimizationStateParameters({headEmbedding:S,tailEmbedding:this.embedding,head:k,tail:z,currentEpoch:0,nEpochs:E,nVertices:y.getDims()[1],epochsPerSample:A}),this.prepareForOptimizationLoop(),this.optimizeLayout()}processGraphForSupervisedProjection(){const{Y:t,X:e}=this;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){const e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}}step(){const{currentEpoch:t}=this.optimizationState;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch}getEmbedding(){return this.embedding}nearestNeighbors(t){const{distanceFn:r,nNeighbors:s}=this,o=function(t,r,s=!1){return function(o,n,i,h=10,a=50,l=.001,u=.5,c=!0){if(s){if(!D())throw new Error("WASM NN-Descent requested but WASM module is not available. Initialize WASM with initWasm() first.");const e=function(t,e,r,s=10,o=50,n=.001,i=.5,h=!0,a="euclidean",l=42){if(!T)throw new Error("WASM module not initialized");const u=t.length,c=t[0].length,f=new Float64Array(u*c);for(let e=0;e<u;e++)for(let r=0;r<c;r++)f[e*c+r]=t[e][r];const m=e.length,g=m>0?e[0].length:0,w=new Int32Array(m*g);for(let t=0;t<m;t++)for(let r=0;r<g;r++)w[t*g+r]=e[t][r];const p=T.nn_descent(f,u,c,w,m,g,r,s,o,n,i,h,a,BigInt(l)),d=[],y=[],b=[],M=u*r,x=2*u*r;for(let t=0;t<u;t++){const e=[],s=[],o=[];for(let n=0;n<r;n++)e.push(p[t*r+n]),s.push(p[M+t*r+n]),o.push(p[x+t*r+n]);d.push(e),y.push(s),b.push(o)}return[d,y,b]}(o,n,i,h,a,l,u,c,"cosine"===t.name?"cosine":"euclidean",Math.floor(4294967295*r()));return{indices:e[0],weights:e[1]}}const w=o.length,y=f(o.length,i);for(let e=0;e<o.length;e++){const s=m(i,o.length,r);for(let r=0;r<s.length;r++){const n=t(o[e],o[s[r]]);g(y,e,n,s[r],1),g(y,s[r],n,e,1)}}if(c)for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length&&!(n[e][r]<0);r++)for(let s=r+1;s<n[e].length&&!(n[e][s]<0);s++){const i=t(o[n[e][r]],o[n[e][s]]);g(y,n[e][r],i,n[e][s],1),g(y,n[e][s],i,n[e][r],1)}for(let s=0;s<h;s++){const s=p(y,w,i,a,r);let n=0;for(let i=0;i<w;i++)for(let h=0;h<a;h++){let l=Math.floor(s[0][i][h]);if(!(l<0||e(r)<u))for(let e=0;e<a;e++){const r=Math.floor(s[0][i][e]),a=s[2][i][h],u=s[2][i][e];if(r<0||!a&&!u)continue;const c=t(o[l],o[r]);n+=g(y,l,c,r,1),n+=g(y,r,c,l,1)}}if(n<=l*i*o.length)break}return d(y)}}(r,this.random,this.useWasmNNDescent),n=5+Math.floor(.5==(i=t.length**.5/20)?0:Math.round(i));var i;const h=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));this.rpForest=B(t,s,n,this.random,this.useWasmTree);const a=function(t){if(t.length>0){const e=[];for(let r of t)e.push(...r.indices);return e}return[[-1]]}(this.rpForest),{indices:l,weights:u}=o(t,a,s,h);return{knnIndices:l,knnDistances:u}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:s=[],knnDistances:o=[],localConnectivity:n}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(o,e,n),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(s,o,i,h),c=[t.length,t.length];if(this.useWasmMatrix&&D()){const t=W(a,l,u,c[0],c[1]),e=P(t),s=L(t,e),o=O(t,e),n=$(O(_(j(o,s),r),_(s,1-r))),i=n.map(t=>t.row),h=n.map(t=>t.col),f=n.map(t=>t.value);return new M(i,h,f,c)}if(this.useWasmMatrix&&D()){const t=W(a,l,u,c[0],c[1]),e=P(t),s=L(t,e),o=O(t,e),n=$(O(_(j(o,s),r),_(s,1-r))),i=n.map(t=>t.row),h=n.map(t=>t.col),f=n.map(t=>t.value);return new M(i,h,f,c)}const f=new M(a,l,u,c),m=x(f),g=S(f,m),w=v(E(f,m),g);return E(A(w,r),A(g,1-r))}categoricalSimplicialSetIntersection(t,e,r,s=1){let o=function(t,e,r=1,s=5){return t.map((t,o,n)=>-1===e[o]||-1===e[n]?t*Math.exp(-r):e[o]!==e[n]?t*Math.exp(-s):t)}(t,e,s,r);return o=N(o),function(t){const e=x(t=R(t,"max"));return N(t=E(t,v(e,S(e,t))))}(o)}smoothKNNDistance(t,e,r=1,s=64,o=1){const n=Math.log(e)/Math.log(2)*o,i=h(t.length),u=h(t.length);for(let e=0;e<t.length;e++){let o=0,h=1/0,c=1;const f=t[e],m=f.filter(t=>t>0);if(m.length>=r){let t=Math.floor(r),s=r-t;t>0?(i[e]=m[t-1],s>nt&&(i[e]+=s*(m[t]-m[t-1]))):i[e]=s*m[0]}else m.length>0&&(i[e]=l(m));for(let r=0;r<s;r++){let r=0;for(let s=1;s<t[e].length;s++){const o=t[e][s]-i[e];r+=o>0?Math.exp(-o/c):1}if(Math.abs(r-n)<nt)break;r>n?(h=c,c=(o+h)/2):(o=c,h===1/0?c*=2:c=(o+h)/2)}if(u[e]=c,i[e]>0){const t=a(f);u[e]<it*t&&(u[e]=it*t)}else{const r=a(t.map(a));u[e]<it*r&&(u[e]=it*r)}}return{sigmas:u,rhos:i}}computeMembershipStrengths(t,e,r,s){const o=t.length,n=t[0].length,i=h(o*n),a=h(o*n),l=h(o*n);for(let h=0;h<o;h++)for(let o=0;o<n;o++){let u=0;-1!==t[h][o]&&(u=t[h][o]===h?0:e[h][o]-s[h]<=0?1:Math.exp(-(e[h][o]-s[h])/r[h]),i[h*n+o]=h,a[h*n+o]=t[h][o],l[h*n+o]=u)}return{rows:i,cols:a,vals:l}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:r}=this,s=this.graph.getValues();let o=0;for(let t=0;t<s.length;t++){const e=s[t];o<s[t]&&(o=e)}const n=this.graph.map(e=>e<o/t?0:e);this.embedding=h(n.nRows).map(()=>h(r).map(()=>20*e(this.random)-10));const i=[],a=[],l=[],u=n.getAll();for(let t=0;t<u.length;t++){const e=u[t];e.value&&(i.push(e.value),l.push(e.row),a.push(e.col))}return{head:a,tail:l,epochsPerSample:this.makeEpochsPerSample(i,t)}}makeEpochsPerSample(t,e){const r=i(t.length,-1),s=l(t),o=t.map(t=>t/s*e);return o.forEach((t,s)=>{t>0&&(r[s]=e/o[s])}),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:s,headEmbedding:o,tailEmbedding:n}=this.optimizationState,i=o[0].length,h=o.length===n.length,a=s.map(t=>t/r),l=[...a],u=[...s];if(this.assignOptimizationStateParameters({epochOfNextSample:u,epochOfNextNegativeSample:l,epochsPerNegativeSample:a,moveOther:h,initialAlpha:e,alpha:e,gamma:t,dim:i}),this.useWasmOptimizer&&D()){const{head:r,tail:l,nEpochs:u,nVertices:c,a:f,b:m}=this.optimizationState;this.wasmOptimizerState=function(t,e,r,s,o,n,i,h,a,l,u,c,f,m){if(!T)throw new Error("WASM module not initialized");const g=new Float64Array(r.length*c),w=new Float64Array(s.length*c);for(let t=0;t<r.length;t++)for(let e=0;e<c;e++)g[t*c+e]=r[t][e];for(let t=0;t<s.length;t++)for(let e=0;e<c;e++)w[t*c+e]=s[t][e];const p=new Uint32Array(t),d=new Uint32Array(e),y=new Float64Array(o),b=new Float64Array(n);return new T.OptimizerState(p,d,g,w,y,b,i,h,a,l,u,c,f,m)}(r,l,o,n,s,a,h,e,t,f,m,i,u,c)}}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:s,epochsPerSample:n}=this.optimizationState,i=this.getNEpochs(),a=this.graph.nCols,{a:l,b:u}=function(t,e){const r=function(t,e){return o(300).map((t,r)=>0+r*((e-0)/299))}(0,3*t).map(t=>t<e?1:t),s=h(r.length).map((s,o)=>r[o]>=e?Math.exp(-(r[o]-e)/t):s),n={x:r,y:s},{parameterValues:i}=function(t,e,r={}){let{maxIterations:s=100,gradientDifference:o=.1,damping:n=0,errorTolerance:i=.01,minValues:h,maxValues:a,initialValues:l}=r;if(n<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!Z(t.x)||t.x.length<2||!Z(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");let u=l||new Array(e.length).fill(1),c=u.length;if(a=a||new Array(c).fill(Number.MAX_SAFE_INTEGER),h=h||new Array(c).fill(Number.MIN_SAFE_INTEGER),a.length!==h.length)throw new Error("minValues and maxValues must be the same size");if(!Z(u))throw new Error("initialValues must be an array");let f,m=tt(t,u,e),g=m<=i;for(f=0;f<s&&!g;f++){u=ot(t,u,n,o,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(m=tt(t,u,e),isNaN(m))break;g=m<=i}return{parameterValues:u,parameterError:m,iterations:f}}(n,([t,e])=>r=>1/(1+t*r**(2*e)),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[a,l]=i;return{a,b:l}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:s,epochsPerSample:n,a:l,b:u,nEpochs:i,nVertices:a})}optimizeLayoutStep(e){if(this.useWasmOptimizer&&this.wasmOptimizerState){const t=function(t,e){if(!T)throw new Error("WASM module not initialized");return T.optimize_layout_step(t,e)}(this.wasmOptimizerState,this.rngState),e=BigInt("6364136223846793005"),r=BigInt("1442695040888963407");this.rngState=this.rngState*e+r&BigInt("0xFFFFFFFFFFFFFFFF");const{dim:s}=this.optimizationState,{headEmbedding:o}=this.optimizationState,n=o.length;for(let e=0;e<n;e++)for(let r=0;r<s;r++)o[e][r]=t[e*s+r];return this.optimizationState.currentEpoch+=1,o}const{optimizationState:r}=this,{head:s,tail:o,headEmbedding:n,tailEmbedding:i,epochsPerSample:h,epochOfNextSample:a,epochOfNextNegativeSample:l,epochsPerNegativeSample:u,moveOther:c,initialAlpha:f,alpha:m,gamma:g,a:w,b:p,dim:d,nEpochs:y,nVertices:b}=r;for(let r=0;r<h.length;r++){if(a[r]>e)continue;const f=s[r],y=o[r],M=n[f],x=i[y],S=ct(M,x);let E=0;S>0&&(E=-2*w*p*Math.pow(S,p-1),E/=w*Math.pow(S,p)+1);for(let t=0;t<d;t++){const e=ut(E*(M[t]-x[t]),4);M[t]+=e*m,c&&(x[t]+=-e*m)}a[r]+=h[r];const v=Math.floor((e-l[r])/u[r]);for(let e=0;e<v;e++){const e=t(b,this.random),r=i[e],s=ct(M,r);let o=0;if(s>0)o=2*g*p,o/=(.001+s)*(w*Math.pow(s,p)+1);else if(f===e)continue;for(let t=0;t<d;t++){let e=4;o>0&&(e=ut(o*(M[t]-r[t]),4)),M[t]+=e*m}}l[r]+=v*u[r]}return r.alpha=f*(1-e/y),r.currentEpoch+=1,n}optimizeLayoutAsync(t=()=>!0){return new Promise((e,r)=>{const s=async()=>{try{const{nEpochs:r,currentEpoch:o}=this.optimizationState;this.embedding=this.optimizeLayoutStep(o);const n=this.optimizationState.currentEpoch,i=!1===t(n),h=n===r;if(i||h)return e(h);setTimeout(()=>s(),0)}catch(t){r(t)}};setTimeout(()=>s(),0)})}optimizeLayout(t=()=>!0){let e=!1,r=[];for(;!e;){const{nEpochs:s,currentEpoch:o}=this.optimizationState;r=this.optimizeLayoutStep(o);const n=this.optimizationState.currentEpoch,i=!1===t(n);e=n===s||i}return r}getNEpochs(){const t=this.graph;if(this.nEpochs>0)return this.nEpochs;const e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200}}function at(t,e){let r=0;for(let s=0;s<t.length;s++)r+=(t[s]-e[s])**2;return Math.sqrt(r)}class lt{constructor(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0}}function ut(t,e){return t>e?e:t<-e?-e:t}function ct(t,e){let r=0;for(let s=0;s<t.length;s++)r+=Math.pow(t[s]-e[s],2);return r}})(),s})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.UMAP=e():t.UMAP=e()}(this,()=>(()=>{var t={433(t){function e(t){return Promise.resolve().then(()=>{var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e})}e.keys=()=>[],e.resolve=e,e.id=433,t.exports=e},673(t,e,r){"use strict";var s=r(788),o=r(718);const n=" ".repeat(2),i=" ".repeat(4);function h(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:o=8,padMinus:h="auto"}=e;return`${t.constructor.name} {\n${n}[\n${i}${function(t,e,r,s,o){const{rows:n,columns:h}=t,l=Math.min(n,e),u=Math.min(h,r),c=[];if("auto"===o){o=!1;t:for(let e=0;e<l;e++)for(let r=0;r<u;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<l;e++){let r=[];for(let n=0;n<u;n++)r.push(a(t.get(e,n),s,o));c.push(`${r.join(" ")}`)}return u!==h&&(c[c.length-1]+=` ... ${h-r} more columns`),l!==n&&c.push(`... ${n-e} more rows`),c.join(`\n${i}`)}(t,r,s,o,h)}\n${n}]\n${n}rows: ${t.rows}\n${n}columns: ${t.columns}\n}`}function a(t,e,r){return(t>=0&&r?` ${l(t,e-1)}`:l(t,e)).padEnd(e)}function l(t,e){let r=t.toString();if(r.length<=e)return r;let s=t.toFixed(e);if(s.length>e&&(s=t.toFixed(Math.max(0,e-(s.length-e)))),s.length<=e&&!s.startsWith("0.000")&&!s.startsWith("-0.000"))return s;let o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function u(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 c(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 f(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){if(!s.isAnyArray(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}function w(t,e){if(!s.isAnyArray(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}function p(t,e,r,s,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(y("startRow",e),y("endRow",r),y("startColumn",s),y("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 d(t,e=0){let r=[];for(let s=0;s<t;s++)r.push(e);return r}function y(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 M{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new E(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 E(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 E(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 E(t,e)}static ones(t,e){return new E(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 E(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:n=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 i=o-s,h=new E(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(n()*i);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),n=this.zeros(e,r);for(let e=0;e<o;e++)n.set(e,e,t[e]);return n}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new E(r,s);for(let n=0;n<r;n++)for(let r=0;r<s;r++)o.set(n,r,Math.min(t.get(n,r),e.get(n,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 n=0;n<r;n++)for(let r=0;r<s;r++)o.set(n,r,Math.max(t.get(n,r),e.get(n,r)));return o}static checkMatrix(t){return M.isMatrix(t)?t:new E(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}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(0!==this.get(t,t))return!1;return!0}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 n=r+1;n<t.columns;n++)t.set(s,n,t.get(s,n)-t.get(e,n)*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,n=!1;for(;o<r&&!1===n;)1===t.get(s,o)?n=!0:o++;for(let r=0;r<s;r++){let n=t.get(r,o);for(let i=o;i<e;i++){let e=t.get(r,i)-n*t.get(s,i);t.set(r,i,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 E(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){u(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return E.rowVector(this.getRow(t))}setRow(t,e){u(this,t),e=f(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){u(this,t),u(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){c(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return E.columnVector(this.getColumn(t))}setColumn(t,e){c(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){c(this,t),c(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=f(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=f(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=f(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=f(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){u(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){c(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{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}default:throw new Error(`invalid option: ${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(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)<t[r]&&(t[r]=this.get(e,r));return t}case void 0:{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}default:throw new Error(`invalid option: ${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(u(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){u(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(u(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){u(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(c(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){c(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(c(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){c(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"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default: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){M.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=E.checkMatrix(t);let e=this.rows,r=this.columns,s=t.columns,o=new E(e,s),n=new Float64Array(r);for(let i=0;i<s;i++){for(let e=0;e<r;e++)n[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*n[s];o.set(t,i,e)}}return o}mpow(t){if(!this.isSquare())throw new RangeError("Matrix must be square");if(!Number.isInteger(t)||t<0)throw new RangeError("Exponent must be a non-negative integer");let e=E.eye(this.rows),r=this;for(let s=t;s>=1;s/=2)1&s&&(e=e.mmul(r)),r=r.mmul(r);return e}strassen2x2(t){t=E.checkMatrix(t);let e=new E(2,2);const r=this.get(0,0),s=t.get(0,0),o=this.get(0,1),n=t.get(0,1),i=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(s+l),c=(i+a)*s,f=r*(n-l),m=a*(h-s),g=(r+o)*l,w=u+m-g+(o-a)*(h+l),p=f+g,d=c+m,y=u-c+f+(i-r)*(s+n);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=E.checkMatrix(t);let e=new E(3,3);const r=this.get(0,0),s=this.get(0,1),o=this.get(0,2),n=this.get(1,0),i=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=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),b=t.get(2,2),M=(r-n)*(-f+w),x=(-r+n+i)*(c-f+w),S=(n+i)*(-c+f),v=r*c,A=(-r+a+l)*(c-m+p),N=(-r+a)*(m-p),R=(a+l)*(-c+m),k=(-o+l+u)*(w+d-y),z=(o-u)*(w-y),I=o*d,F=(l+u)*(-d+y),T=(-o+i+h)*(p+d-b),C=(o-h)*(p-b),D=(i+h)*(-d+b),V=v+I+s*g,q=(r+s+o-n-i-l-u)*w+x+S+v+k+I+F,W=v+A+R+(r+s+o-i-h-a-l)*p+I+T+D,P=M+i*(-c+f+g-w-p-d+b)+x+v+I+T+C,O=M+x+S+v+h*y,j=I+T+C+D+n*m,L=v+A+N+l*(-c+m+g-w-p-d+y)+k+z+I,_=k+z+I+F+a*f,$=v+A+N+R+u*b;return e.set(0,0,V),e.set(0,1,q),e.set(0,2,W),e.set(1,0,P),e.set(1,1,O),e.set(1,2,j),e.set(2,0,L),e.set(2,1,_),e.set(2,2,$),e}mmulStrassen(t){t=E.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,o=t.rows,n=t.columns;function i(t,e,r){let s=t.rows,o=t.columns;if(s===e&&o===r)return t;{let s=M.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==o&&console.warn(`Multiplying ${r} x ${s} and ${o} x ${n} matrix: dimensions do not match.`);let h=Math.max(r,o),a=Math.max(s,n);return e=i(e,h,a),function t(e,r,s,o){if(s<=512||o<=512)return e.mmul(r);s%2==1&&o%2==1?(e=i(e,s+1,o+1),r=i(r,s+1,o+1)):s%2==1?(e=i(e,s+1,o),r=i(r,s+1,o)):o%2==1&&(e=i(e,s,o+1),r=i(r,s,o+1));let n=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,n-1,0,h-1),l=r.subMatrix(0,n-1,0,h-1),u=e.subMatrix(0,n-1,h,e.columns-1),c=r.subMatrix(0,n-1,h,r.columns-1),f=e.subMatrix(n,e.rows-1,0,h-1),m=r.subMatrix(n,r.rows-1,0,h-1),g=e.subMatrix(n,e.rows-1,h,e.columns-1),w=r.subMatrix(n,r.rows-1,h,r.columns-1),p=t(M.add(a,g),M.add(l,w),n,h),d=t(M.add(f,g),l,n,h),y=t(a,M.sub(c,w),n,h),b=t(g,M.sub(m,l),n,h),x=t(M.add(a,u),w,n,h),S=t(M.sub(f,a),M.add(l,c),n,h),E=t(M.sub(u,g),M.add(m,w),n,h),v=M.add(p,b);v.sub(x),v.add(E);let A=M.add(y,x),N=M.add(d,b),R=M.sub(p,d);R.add(y),R.add(S);let k=M.zeros(2*v.rows,2*v.columns);return k=k.setSubMatrix(v,0,0),k=k.setSubMatrix(A,v.rows,0),k=k.setSubMatrix(N,0,v.columns),k=k.setSubMatrix(R,v.rows,v.columns),k.subMatrix(0,s-1,0,o-1)}(e,t=i(t,h,a),h,a)}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 E(this.rows,this.columns);for(let t=0;t<this.rows;t++){const n=this.getRow(t);n.length>0&&o(n,{min:e,max:r,output:n}),s.setRow(t,n)}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 E(this.rows,this.columns);for(let t=0;t<this.columns;t++){const n=this.getColumn(t);n.length&&o(n,{min:e,max:r,output:n}),s.setColumn(t,n)}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=E.checkMatrix(t);let e=this.rows,r=this.columns,s=t.rows,o=t.columns,n=new E(e*s,r*o);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<o;h++)n.set(s*i+r,o*e+h,this.get(i,e)*t.get(r,h));return n}kroneckerSum(t){if(t=E.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(E.eye(r,r)),o=E.eye(e,e).kroneckerProduct(t);return s.add(o)}transpose(){let t=new E(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=x){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=x){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,s){p(this,t,e,r,s);let o=new E(e-t+1,s-r+1);for(let n=t;n<=e;n++)for(let e=r;e<=s;e++)o.set(n-t,e-r,this.get(n,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 E(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let n=e;n<=r;n++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);s.set(o,n-e,this.get(t[o],n))}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 E(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let n=e;n<=r;n++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);s.set(n-e,o,this.get(n,t[o]))}return s}setSubMatrix(t,e,r){if((t=E.checkMatrix(t)).isEmpty())return this;p(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){g(this,t),w(this,e);let r=new E(t.length,e.length);for(let s=0;s<t.length;s++){let o=t[s];for(let t=0;t<e.length;t++){let n=e[t];r.set(s,t,this.get(o,n))}}return r}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(){return this.constructor.copy(this,new E(this.rows,this.columns))}static copy(t,e){for(const[r,s,o]of t.entries())e.set(r,s,o);return e}sum(t){switch(t){case"row":return function(t){let e=d(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=d(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=d(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=d(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:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!s.isAnyArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,n=[];for(let i=0;i<s;i++){let s=0,h=0,a=0;for(let e=0;e<o;e++)a=t.get(i,e)-r[i],s+=a,h+=a*a;e?n.push((h-s*s/o)/(o-1)):n.push((h-s*s/o)/o)}return n}(this,r,o);case"column":if(!s.isAnyArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,o=t.columns,n=[];for(let i=0;i<o;i++){let o=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(e,i)-r[i],o+=a,h+=a*a;e?n.push((h-o*o/s)/(s-1)):n.push((h-o*o/s)/s)}return n}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const s=t.rows,o=t.columns,n=s*o;let i=0,h=0,a=0;for(let e=0;e<s;e++)for(let s=0;s<o;s++)a=t.get(e,s)-r,i+=a,h+=a*a;return e?(h-i*i/n)/(n-1):(h-i*i/n)/n}(this,r,o);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(!s.isAnyArray(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(!s.isAnyArray(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+=t.get(r,e)**2/(t.columns-1);e.push(Math.sqrt(s))}return e}(this);else if(!s.isAnyArray(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+=t.get(e,r)**2/(t.rows-1);e.push(Math.sqrt(s))}return e}(this);else if(!s.isAnyArray(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+=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 h(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}function x(t,e){return t-e}function S(t){return t.every(t=>"number"==typeof t)}M.prototype.klass="Matrix","undefined"!=typeof Symbol&&(M.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return h(this)}),M.random=M.rand,M.randomInt=M.randInt,M.diagonal=M.diag,M.prototype.diagonal=M.prototype.diag,M.identity=M.eye,M.prototype.negate=M.prototype.neg,M.prototype.tensorProduct=M.prototype.kroneckerProduct;class E extends M{data;#t(t,e){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));this.rows=t,this.columns=e}constructor(t,e){if(super(),E.isMatrix(t))this.#t(t.rows,t.columns),E.copy(t,this);else if(Number.isInteger(t)&&t>=0)this.#t(t,e);else{if(!s.isAnyArray(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");if(!S(r[s]))throw new TypeError("Input data contains non-numeric values");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 u(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),u(this,t,!0),e=Float64Array.from(f(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){c(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),c(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,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,this.get(e,r)**t.get(e,r));return this}}(M,E);class v extends M{#e;get size(){return this.#e.size}get rows(){return this.#e.rows}get columns(){return this.#e.columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return E.isMatrix(t)&&"SymmetricMatrix"===t.klassType}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}constructor(t){if(super(),E.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");this.#e=E.copy(t,new E(t.rows,t.rows))}else if(Number.isInteger(t)&&t>=0)this.#e=new E(t,t);else if(this.#e=new E(t),!this.isSymmetric())throw new TypeError("not symmetric data")}clone(){const t=new v(this.diagonalSize);for(const[e,r,s]of this.upperRightEntries())t.set(e,r,s);return t}toMatrix(){return new E(this)}get(t,e){return this.#e.get(t,e)}set(t,e,r){return this.#e.set(t,e,r),this.#e.set(e,t,r),this}removeCross(t){return this.#e.removeRow(t),this.#e.removeColumn(t),this}addCross(t,e){void 0===e&&(e=t,t=this.diagonalSize);const r=e.slice();return r.splice(t,1),this.#e.addRow(t,r),this.#e.addColumn(t,e),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const e=[];for(const[r,s]of t.entries())s||e.push(r);e.reverse();for(const t of e)this.removeCross(t);return this}toCompact(){const{diagonalSize:t}=this,e=new Array(t*(t+1)/2);for(let r=0,s=0,o=0;o<e.length;o++)e[o]=this.get(s,r),++r>=t&&(r=++s);return e}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)-1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(t)}`);const s=new v(r);for(let o=0,n=0,i=0;i<e;i++)s.set(o,n,t[i]),++o>=r&&(o=++n);return s}*upperRightEntries(){for(let t=0,e=0;t<this.diagonalSize;void 0){const r=this.get(t,e);yield[t,e,r],++e>=this.diagonalSize&&(e=++t)}}*upperRightValues(){for(let t=0,e=0;t<this.diagonalSize;void 0){const r=this.get(t,e);yield r,++e>=this.diagonalSize&&(e=++t)}}}v.prototype.klassType="SymmetricMatrix";class A extends v{static isDistanceMatrix(t){return v.isSymmetricMatrix(t)&&"DistanceMatrix"===t.klassSubType}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return void 0===e&&(e=t,t=this.diagonalSize),(e=e.slice())[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new v(this)}clone(){const t=new A(this.diagonalSize);for(const[e,r,s]of this.upperRightEntries())e!==r&&t.set(e,r,s);return t}toCompact(){const{diagonalSize:t}=this,e=new Array((t-1)*t/2);for(let r=1,s=0,o=0;o<e.length;o++)e[o]=this.get(s,r),++r>=t&&(r=1+ ++s);return e}static fromCompact(t){const e=t.length;if(0===e)return new this(0);const r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const s=new this(r);for(let o=1,n=0,i=0;i<e;i++)s.set(o,n,t[i]),++o>=r&&(o=1+ ++n);return s}}A.prototype.klassSubType="DistanceMatrix";class N extends M{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class R extends N{constructor(t,e,r){g(t,e),w(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}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 k extends M{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 z extends M{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,n,i,h,a,l,u=(t=z.checkMatrix(t)).clone(),c=u.rows,f=u.columns,m=new Float64Array(c),g=1;for(e=0;e<c;e++)m[e]=e;for(a=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)a[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),n=0,s=0;s<l;s++)n+=u.get(e,s)*a[s];a[e]-=n,u.set(e,r,a[e])}for(o=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[o])&&(o=e);if(o!==r){for(s=0;s<f;s++)i=u.get(o,s),u.set(o,s,u.get(r,s)),u.set(r,s,i);h=m[o],m[o]=m[r],m[r]=h,g=-g}if(r<c&&0!==u.get(r,r))for(e=r+1;e<c;e++)u.set(e,r,u.get(e,r)/u.get(r,r))}this.LU=u,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=E.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,n=t.columns,i=t.subMatrixRow(this.pivotVector,0,n-1),h=e.columns;for(o=0;o<h;o++)for(r=o+1;r<h;r++)for(s=0;s<n;s++)i.set(r,s,i.get(r,s)-i.get(o,s)*e.get(r,o));for(o=h-1;o>=0;o--){for(s=0;s<n;s++)i.set(o,s,i.get(o,s)/e.get(o,o));for(r=0;r<o;r++)for(s=0;s<n;s++)i.set(r,s,i.get(r,s)-i.get(o,s)*e.get(r,o))}return i}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 E(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 E(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 F(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,n=(t=z.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<i;e++)t=F(t,n.get(e,s));if(0!==t){for(n.get(s,s)<0&&(t=-t),e=s;e<i;e++)n.set(e,s,n.get(e,s)/t);for(n.set(s,s,n.get(s,s)+1),r=s+1;r<h;r++){for(o=0,e=s;e<i;e++)o+=n.get(e,s)*n.get(e,r);for(o=-o/n.get(s,s),e=s;e<i;e++)n.set(e,r,n.get(e,r)+o*n.get(e,s))}}a[s]=-t}this.QR=n,this.Rdiag=a}solve(t){t=E.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,n,i,h=t.columns,a=t.clone(),l=e.columns;for(n=0;n<l;n++)for(o=0;o<h;o++){for(i=0,s=n;s<r;s++)i+=e.get(s,n)*a.get(s,o);for(i=-i/e.get(n,n),s=n;s<r;s++)a.set(s,o,a.get(s,o)+i*e.get(s,n))}for(n=l-1;n>=0;n--){for(o=0;o<h;o++)a.set(n,o,a.get(n,o)/this.Rdiag[n]);for(s=0;s<n;s++)for(o=0;o<h;o++)a.set(s,o,a.get(s,o)-a.get(n,o)*e.get(s,n))}return a.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 E(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,n=o.rows,i=o.columns,h=new E(n,i);for(r=i-1;r>=0;r--){for(t=0;t<n;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<i;e++)if(0!==o.get(r,r)){for(s=0,t=r;t<n;t++)s+=o.get(t,r)*h.get(t,e);for(s=-s/o.get(r,r),t=r;t<n;t++)h.set(t,e,h.get(t,e)+s*o.get(t,r))}}return h}}class C{constructor(t,e={}){if((t=z.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:n=!0,autoTranspose:i=!1}=e;let h,a=Boolean(o),l=Boolean(n),u=!1;if(r<s)if(i){h=t.transpose(),r=h.rows,s=h.columns,u=!0;let e=a;a=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 c=Math.min(r,s),f=Math.min(r+1,s),m=new Float64Array(f),g=new E(r,c),w=new E(s,s),p=new Float64Array(s),d=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let b=Math.min(r-1,s),M=Math.max(0,Math.min(s-2,r)),x=Math.max(b,M);for(let t=0;t<x;t++){if(t<b){m[t]=0;for(let e=t;e<r;e++)m[t]=F(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<b&&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(a&&t<b)for(let e=t;e<r;e++)g.set(e,t,h.get(e,t));if(t<M){p[t]=0;for(let e=t+1;e<s;e++)p[t]=F(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 S=Math.min(s,r+1);if(b<s&&(m[b]=h.get(b,b)),r<S&&(m[S-1]=0),M+1<S&&(p[M]=h.get(M,S-1)),p[S-1]=0,a){for(let t=b;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=b-1;t>=0;t--)if(0!==m[t]){for(let e=t+1;e<c;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<M&&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 v=S-1,A=Number.EPSILON;for(;S>0;){let t,e;for(t=S-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+A*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===S-2)e=4;else{let r;for(r=S-1;r>=t&&r!==t;r--){let e=(r!==S?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(m[r])<=A*e){m[r]=0;break}}r===t?e=3:r===S-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[S-2];p[S-2]=0;for(let r=S-2;r>=t;r--){let o=F(m[r],e),n=m[r]/o,i=e/o;if(m[r]=o,r!==t&&(e=-i*p[r-1],p[r-1]=n*p[r-1]),l)for(let t=0;t<s;t++)o=n*w.get(t,r)+i*w.get(t,S-1),w.set(t,S-1,-i*w.get(t,r)+n*w.get(t,S-1)),w.set(t,r,o)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let s=t;s<S;s++){let o=F(m[s],e),n=m[s]/o,i=e/o;if(m[s]=o,e=-i*p[s],p[s]=n*p[s],a)for(let e=0;e<r;e++)o=n*g.get(e,s)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,s)+n*g.get(e,t-1)),g.set(e,s,o)}break}case 3:{const e=Math.max(Math.abs(m[S-1]),Math.abs(m[S-2]),Math.abs(p[S-2]),Math.abs(m[t]),Math.abs(p[t])),o=m[S-1]/e,n=m[S-2]/e,i=p[S-2]/e,h=m[t]/e,u=p[t]/e,c=((n+o)*(n-o)+i*i)/2,f=o*i*(o*i);let d=0;0===c&&0===f||(d=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),d=f/(c+d));let y=(h+o)*(h-o)+d,b=h*u;for(let e=t;e<S-1;e++){let o=F(y,b);0===o&&(o=Number.MIN_VALUE);let n=y/o,i=b/o;if(e!==t&&(p[e-1]=o),y=n*m[e]+i*p[e],p[e]=n*p[e]-i*m[e],b=i*m[e+1],m[e+1]=n*m[e+1],l)for(let t=0;t<s;t++)o=n*w.get(t,e)+i*w.get(t,e+1),w.set(t,e+1,-i*w.get(t,e)+n*w.get(t,e+1)),w.set(t,e,o);if(o=F(y,b),0===o&&(o=Number.MIN_VALUE),n=y/o,i=b/o,m[e]=o,y=n*p[e]+i*m[e+1],m[e+1]=-i*p[e]+n*m[e+1],b=i*p[e+1],p[e+1]=n*p[e+1],a&&e<r-1)for(let t=0;t<r;t++)o=n*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+n*g.get(t,e+1)),g.set(t,e,o)}p[S-2]=y;break}case 4:if(m[t]<=0&&(m[t]=m[t]<0?-m[t]:0,l))for(let e=0;e<=v;e++)w.set(e,t,-w.get(e,t));for(;t<v&&!(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(a&&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++}S--}}if(u){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=E.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 n=this.U,i=this.rightSingularVectors,h=i.mmul(o),a=i.rows,l=n.rows,u=E.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let o=0;o<s;o++)r+=h.get(t,o)*n.get(e,o);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(E.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,s=t.columns,o=new E(r,this.s.length);for(let n=0;n<r;n++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&o.set(n,r,t.get(n,r)/this.s[r]);let n=this.U,i=n.rows,h=n.columns,a=new E(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let s=0;s<h;s++)r+=o.get(t,s)*n.get(e,s);a.set(t,e,r)}return a}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 E.diag(this.s)}}function D(t,e,r=!1){return t=z.checkMatrix(t),e=z.checkMatrix(e),r?new C(t).solve(e):t.isSquare()?new I(t).solve(e):new T(t).solve(e)}function V(t,e){let r=[];for(let s=0;s<t;s++)s!==e&&r.push(s);return r}function q(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 W{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=z.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,n=t.columns,i=new E(n,n),h=new Float64Array(n),a=new Float64Array(n),l=t,u=!1;if(u=!!r||t.isSymmetric(),u){for(s=0;s<n;s++)for(o=0;o<n;o++)i.set(s,o,l.get(s,o));!function(t,e,r,s){let o,n,i,h,a,l,u,c;for(a=0;a<t;a++)r[a]=s.get(t-1,a);for(h=t-1;h>0;h--){for(c=0,i=0,l=0;l<h;l++)c+=Math.abs(r[l]);if(0===c)for(e[h]=r[h-1],a=0;a<h;a++)r[a]=s.get(h-1,a),s.set(h,a,0),s.set(a,h,0);else{for(l=0;l<h;l++)r[l]/=c,i+=r[l]*r[l];for(o=r[h-1],n=Math.sqrt(i),o>0&&(n=-n),e[h]=c*n,i-=o*n,r[h-1]=o-n,a=0;a<h;a++)e[a]=0;for(a=0;a<h;a++){for(o=r[a],s.set(a,h,o),n=e[a]+s.get(a,a)*o,l=a+1;l<=h-1;l++)n+=s.get(l,a)*r[l],e[l]+=s.get(l,a)*o;e[a]=n}for(o=0,a=0;a<h;a++)e[a]/=i,o+=e[a]*r[a];for(u=o/(i+i),a=0;a<h;a++)e[a]-=u*r[a];for(a=0;a<h;a++){for(o=r[a],n=e[a],l=a;l<=h-1;l++)s.set(l,a,s.get(l,a)-(o*e[l]+n*r[l]));r[a]=s.get(h-1,a),s.set(h,a,0)}}r[h]=i}for(h=0;h<t-1;h++){if(s.set(t-1,h,s.get(h,h)),s.set(h,h,1),i=r[h+1],0!==i){for(l=0;l<=h;l++)r[l]=s.get(l,h+1)/i;for(a=0;a<=h;a++){for(n=0,l=0;l<=h;l++)n+=s.get(l,h+1)*s.get(l,a);for(l=0;l<=h;l++)s.set(l,a,s.get(l,a)-n*r[l])}}for(l=0;l<=h;l++)s.set(l,h+1,0)}for(a=0;a<t;a++)r[a]=s.get(t-1,a),s.set(t-1,a,0);s.set(t-1,t-1,1),e[0]=0}(n,a,h,i),function(t,e,r,s){let o,n,i,h,a,l,u,c,f,m,g,w,p,d,y,b;for(i=1;i<t;i++)e[i-1]=e[i];e[t-1]=0;let M=0,x=0,S=Number.EPSILON;for(l=0;l<t;l++){for(x=Math.max(x,Math.abs(r[l])+Math.abs(e[l])),u=l;u<t&&!(Math.abs(e[u])<=S*x);)u++;if(u>l)do{for(o=r[l],c=(r[l+1]-o)/(2*e[l]),f=F(c,1),c<0&&(f=-f),r[l]=e[l]/(c+f),r[l+1]=e[l]*(c+f),m=r[l+1],n=o-r[l],i=l+2;i<t;i++)r[i]-=n;for(M+=n,c=r[u],g=1,w=g,p=g,d=e[l+1],y=0,b=0,i=u-1;i>=l;i--)for(p=w,w=g,b=y,o=g*e[i],n=g*c,f=F(c,e[i]),e[i+1]=y*f,y=e[i]/f,g=c/f,c=g*r[i]-y*o,r[i+1]=n+y*(g*o+y*r[i]),a=0;a<t;a++)n=s.get(a,i+1),s.set(a,i+1,y*s.get(a,i)+g*n),s.set(a,i,g*s.get(a,i)-y*n);c=-y*b*p*d*e[l]/m,e[l]=y*c,r[l]=g*c}while(Math.abs(e[l])>S*x);r[l]=r[l]+M,e[l]=0}for(i=0;i<t-1;i++){for(a=i,c=r[i],h=i+1;h<t;h++)r[h]<c&&(a=h,c=r[h]);if(a!==i)for(r[a]=r[i],r[i]=c,h=0;h<t;h++)c=s.get(h,i),s.set(h,i,s.get(h,a)),s.set(h,a,c)}}(n,a,h,i)}else{let t=new E(n,n),e=new Float64Array(n);for(o=0;o<n;o++)for(s=0;s<n;s++)t.set(s,o,l.get(s,o));!function(t,e,r,s){let o,n,i,h,a,l,u,c=t-1;for(l=1;l<=c-1;l++){for(u=0,h=l;h<=c;h++)u+=Math.abs(e.get(h,l-1));if(0!==u){for(i=0,h=c;h>=l;h--)r[h]=e.get(h,l-1)/u,i+=r[h]*r[h];for(n=Math.sqrt(i),r[l]>0&&(n=-n),i-=r[l]*n,r[l]=r[l]-n,a=l;a<t;a++){for(o=0,h=c;h>=l;h--)o+=r[h]*e.get(h,a);for(o/=i,h=l;h<=c;h++)e.set(h,a,e.get(h,a)-o*r[h])}for(h=0;h<=c;h++){for(o=0,a=c;a>=l;a--)o+=r[a]*e.get(h,a);for(o/=i,a=l;a<=c;a++)e.set(h,a,e.get(h,a)-o*r[a])}r[l]=u*r[l],e.set(l,l-1,u*n)}}for(h=0;h<t;h++)for(a=0;a<t;a++)s.set(h,a,h===a?1:0);for(l=c-1;l>=1;l--)if(0!==e.get(l,l-1)){for(h=l+1;h<=c;h++)r[h]=e.get(h,l-1);for(a=l;a<=c;a++){for(n=0,h=l;h<=c;h++)n+=r[h]*s.get(h,a);for(n=n/r[l]/e.get(l,l-1),h=l;h<=c;h++)s.set(h,a,s.get(h,a)+n*r[h])}}}(n,t,e,i),function(t,e,r,s,o){let n,i,h,a,l,u,c,f,m,g,w,p,d,y,b,M=t-1,x=t-1,S=Number.EPSILON,E=0,v=0,A=0,N=0,R=0,k=0,z=0,I=0;for(n=0;n<t;n++)for((n<0||n>x)&&(r[n]=o.get(n,n),e[n]=0),i=Math.max(n-1,0);i<t;i++)v+=Math.abs(o.get(n,i));for(;M>=0;){for(a=M;a>0&&(k=Math.abs(o.get(a-1,a-1))+Math.abs(o.get(a,a)),0===k&&(k=v),!(Math.abs(o.get(a,a-1))<S*k));)a--;if(a===M)o.set(M,M,o.get(M,M)+E),r[M]=o.get(M,M),e[M]=0,M--,I=0;else if(a===M-1){if(c=o.get(M,M-1)*o.get(M-1,M),A=(o.get(M-1,M-1)-o.get(M,M))/2,N=A*A+c,z=Math.sqrt(Math.abs(N)),o.set(M,M,o.get(M,M)+E),o.set(M-1,M-1,o.get(M-1,M-1)+E),f=o.get(M,M),N>=0){for(z=A>=0?A+z:A-z,r[M-1]=f+z,r[M]=r[M-1],0!==z&&(r[M]=f-c/z),e[M-1]=0,e[M]=0,f=o.get(M,M-1),k=Math.abs(f)+Math.abs(z),A=f/k,N=z/k,R=Math.sqrt(A*A+N*N),A/=R,N/=R,i=M-1;i<t;i++)z=o.get(M-1,i),o.set(M-1,i,N*z+A*o.get(M,i)),o.set(M,i,N*o.get(M,i)-A*z);for(n=0;n<=M;n++)z=o.get(n,M-1),o.set(n,M-1,N*z+A*o.get(n,M)),o.set(n,M,N*o.get(n,M)-A*z);for(n=0;n<=x;n++)z=s.get(n,M-1),s.set(n,M-1,N*z+A*s.get(n,M)),s.set(n,M,N*s.get(n,M)-A*z)}else r[M-1]=f+A,r[M]=f+A,e[M-1]=z,e[M]=-z;M-=2,I=0}else{if(f=o.get(M,M),m=0,c=0,a<M&&(m=o.get(M-1,M-1),c=o.get(M,M-1)*o.get(M-1,M)),10===I){for(E+=f,n=0;n<=M;n++)o.set(n,n,o.get(n,n)-f);k=Math.abs(o.get(M,M-1))+Math.abs(o.get(M-1,M-2)),f=m=.75*k,c=-.4375*k*k}if(30===I&&(k=(m-f)/2,k=k*k+c,k>0)){for(k=Math.sqrt(k),m<f&&(k=-k),k=f-c/((m-f)/2+k),n=0;n<=M;n++)o.set(n,n,o.get(n,n)-k);E+=k,f=m=c=.964}for(I+=1,l=M-2;l>=a&&(z=o.get(l,l),R=f-z,k=m-z,A=(R*k-c)/o.get(l+1,l)+o.get(l,l+1),N=o.get(l+1,l+1)-z-R-k,R=o.get(l+2,l+1),k=Math.abs(A)+Math.abs(N)+Math.abs(R),A/=k,N/=k,R/=k,l!==a)&&!(Math.abs(o.get(l,l-1))*(Math.abs(N)+Math.abs(R))<S*(Math.abs(A)*(Math.abs(o.get(l-1,l-1))+Math.abs(z)+Math.abs(o.get(l+1,l+1)))));)l--;for(n=l+2;n<=M;n++)o.set(n,n-2,0),n>l+2&&o.set(n,n-3,0);for(h=l;h<=M-1&&(y=h!==M-1,h!==l&&(A=o.get(h,h-1),N=o.get(h+1,h-1),R=y?o.get(h+2,h-1):0,f=Math.abs(A)+Math.abs(N)+Math.abs(R),0!==f&&(A/=f,N/=f,R/=f)),0!==f);h++)if(k=Math.sqrt(A*A+N*N+R*R),A<0&&(k=-k),0!==k){for(h!==l?o.set(h,h-1,-k*f):a!==l&&o.set(h,h-1,-o.get(h,h-1)),A+=k,f=A/k,m=N/k,z=R/k,N/=A,R/=A,i=h;i<t;i++)A=o.get(h,i)+N*o.get(h+1,i),y&&(A+=R*o.get(h+2,i),o.set(h+2,i,o.get(h+2,i)-A*z)),o.set(h,i,o.get(h,i)-A*f),o.set(h+1,i,o.get(h+1,i)-A*m);for(n=0;n<=Math.min(M,h+3);n++)A=f*o.get(n,h)+m*o.get(n,h+1),y&&(A+=z*o.get(n,h+2),o.set(n,h+2,o.get(n,h+2)-A*R)),o.set(n,h,o.get(n,h)-A),o.set(n,h+1,o.get(n,h+1)-A*N);for(n=0;n<=x;n++)A=f*s.get(n,h)+m*s.get(n,h+1),y&&(A+=z*s.get(n,h+2),s.set(n,h+2,s.get(n,h+2)-A*R)),s.set(n,h,s.get(n,h)-A),s.set(n,h+1,s.get(n,h+1)-A*N)}}}if(0!==v){for(M=t-1;M>=0;M--)if(A=r[M],N=e[M],0===N)for(a=M,o.set(M,M,1),n=M-1;n>=0;n--){for(c=o.get(n,n)-A,R=0,i=a;i<=M;i++)R+=o.get(n,i)*o.get(i,M);if(e[n]<0)z=c,k=R;else if(a=n,0===e[n]?o.set(n,M,0!==c?-R/c:-R/(S*v)):(f=o.get(n,n+1),m=o.get(n+1,n),N=(r[n]-A)*(r[n]-A)+e[n]*e[n],u=(f*k-z*R)/N,o.set(n,M,u),o.set(n+1,M,Math.abs(f)>Math.abs(z)?(-R-c*u)/f:(-k-m*u)/z)),u=Math.abs(o.get(n,M)),S*u*u>1)for(i=n;i<=M;i++)o.set(i,M,o.get(i,M)/u)}else if(N<0)for(a=M-1,Math.abs(o.get(M,M-1))>Math.abs(o.get(M-1,M))?(o.set(M-1,M-1,N/o.get(M,M-1)),o.set(M-1,M,-(o.get(M,M)-A)/o.get(M,M-1))):(b=P(0,-o.get(M-1,M),o.get(M-1,M-1)-A,N),o.set(M-1,M-1,b[0]),o.set(M-1,M,b[1])),o.set(M,M-1,0),o.set(M,M,1),n=M-2;n>=0;n--){for(g=0,w=0,i=a;i<=M;i++)g+=o.get(n,i)*o.get(i,M-1),w+=o.get(n,i)*o.get(i,M);if(c=o.get(n,n)-A,e[n]<0)z=c,R=g,k=w;else if(a=n,0===e[n]?(b=P(-g,-w,c,N),o.set(n,M-1,b[0]),o.set(n,M,b[1])):(f=o.get(n,n+1),m=o.get(n+1,n),p=(r[n]-A)*(r[n]-A)+e[n]*e[n]-N*N,d=2*(r[n]-A)*N,0===p&&0===d&&(p=S*v*(Math.abs(c)+Math.abs(N)+Math.abs(f)+Math.abs(m)+Math.abs(z))),b=P(f*R-z*g+N*w,f*k-z*w-N*g,p,d),o.set(n,M-1,b[0]),o.set(n,M,b[1]),Math.abs(f)>Math.abs(z)+Math.abs(N)?(o.set(n+1,M-1,(-g-c*o.get(n,M-1)+N*o.get(n,M))/f),o.set(n+1,M,(-w-c*o.get(n,M)-N*o.get(n,M-1))/f)):(b=P(-R-m*o.get(n,M-1),-k-m*o.get(n,M),z,N),o.set(n+1,M-1,b[0]),o.set(n+1,M,b[1]))),u=Math.max(Math.abs(o.get(n,M-1)),Math.abs(o.get(n,M))),S*u*u>1)for(i=n;i<=M;i++)o.set(i,M-1,o.get(i,M-1)/u),o.set(i,M,o.get(i,M)/u)}for(n=0;n<t;n++)if(n<0||n>x)for(i=n;i<t;i++)s.set(n,i,o.get(n,i));for(i=t-1;i>=0;i--)for(n=0;n<=x;n++){for(z=0,h=0;h<=Math.min(i,x);h++)z+=s.get(n,h)*o.get(h,i);s.set(n,i,z)}}}(n,a,h,i,t)}this.n=n,this.e=a,this.d=h,this.V=i}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,n=new E(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)n.set(t,e,0);n.set(t,t,o[t]),s[t]>0?n.set(t,t+1,s[t]):s[t]<0&&n.set(t,t-1,s[t])}return n}}function P(t,e,r,s){let o,n;return Math.abs(r)>Math.abs(s)?(o=s/r,n=r+o*s,[(t+o*e)/n,(e-o*t)/n]):(o=r/s,n=s+o*r,[(o*t+e)/n,(o*e-t)/n])}class O{constructor(t){if(!(t=z.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,s,o=t,n=o.rows,i=new E(n,n),h=!0;for(r=0;r<n;r++){let t=0;for(s=0;s<r;s++){let n=0;for(e=0;e<s;e++)n+=i.get(s,e)*i.get(r,e);n=(o.get(r,s)-n)/i.get(s,s),i.set(r,s,n),t+=n*n}for(t=o.get(r,r)-t,h&&=t>0,i.set(r,r,Math.sqrt(Math.max(t,0))),s=r+1;s<n;s++)i.set(r,s,0)}this.L=i,this.positiveDefinite=h}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=z.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,n,i=t.columns,h=t.clone();for(n=0;n<r;n++)for(o=0;o<i;o++){for(s=0;s<n;s++)h.set(n,o,h.get(n,o)-h.get(s,o)*e.get(n,s));h.set(n,o,h.get(n,o)/e.get(n,n))}for(n=r-1;n>=0;n--)for(o=0;o<i;o++){for(s=n+1;s<r;s++)h.set(n,o,h.get(n,o)-h.get(s,o)*e.get(s,n));h.set(n,o,h.get(n,o)/e.get(n,n))}return h}get lowerTriangularMatrix(){return this.L}}class j{constructor(t,e={}){t=z.checkMatrix(t);let{Y:r}=e;const{scaleScores:o=!1,maxIterations:n=1e3,terminationCriteria:i=1e-10}=e;let h;if(r){if(r=s.isAnyArray(r)&&"number"==typeof r[0]?E.columnVector(r):z.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");h=r.getColumnVector(0)}else h=t.getColumnVector(0);let a,l,u,c,f=1;for(let e=0;e<n&&f>i;e++)u=t.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),u=u.div(u.norm()),a=t.mmul(u).div(u.transpose().mmul(u).get(0,0)),e>0&&(f=a.clone().sub(c).pow(2).sum()),c=a.clone(),r?(l=r.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),l=l.div(l.norm()),h=r.mmul(l).div(l.transpose().mmul(l).get(0,0))):h=a;if(r){let e=t.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0));e=e.div(e.norm());let s=t.clone().sub(a.clone().mmul(e.transpose())),o=h.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),n=r.clone().sub(a.clone().mulS(o.get(0,0)).mmul(l.transpose()));this.t=a,this.p=e.transpose(),this.w=u.transpose(),this.q=l,this.u=h,this.s=a.transpose().mmul(a),this.xResidual=s,this.yResidual=n,this.betas=o}else this.w=u.transpose(),this.s=a.transpose().mmul(a).sqrt(),this.t=o?a.clone().div(this.s.get(0,0)):a,this.xResidual=t.sub(a.mmul(u.transpose()))}}e.y3=M,e.jy=O,e.oN=O,e.Hc=A,e.cg=W,e.hj=W,e.LU=I,e.Tb=I,e.uq=E,e.Zm=class extends N{constructor(t,e){w(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])}},e.Dq=class extends N{constructor(t,e){c(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)}},e.__=class extends N{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)}},e.q0=class extends N{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)}},e.lh=class extends N{constructor(t,e){g(t,e),super(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)}},e.pI=class extends N{constructor(t,e){u(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)}},e.zC=R,e.zg=class extends N{constructor(t,e,r,s,o){p(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)}},e.g6=class extends N{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)}},e.OL=j,e.ks=j,e.QR=T,e.jp=T,e.mk=C,e.W2=C,e.l=v,e.KY=k,e.dv=z,e.BR=function(t,e=t,r={}){t=new E(t);let o=!1;if("object"!=typeof e||E.isMatrix(e)||s.isAnyArray(e)?e=new E(e):(r=e,e=t,o=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:i=!0}=r;n&&(t.center("column"),o||e.center("column")),i&&(t.scale("column"),o||e.scale("column"));const h=t.standardDeviation("column",{unbiased:!0}),a=o?h:e.standardDeviation("column",{unbiased:!0}),l=t.transpose().mmul(e);for(let e=0;e<l.rows;e++)for(let r=0;r<l.columns;r++)l.set(e,r,l.get(e,r)*(1/(h[e]*a[r]))*(1/(t.rows-1)));return l},e.Wu=function(t,e=t,r={}){t=new E(t);let o=!1;if("object"!=typeof e||E.isMatrix(e)||s.isAnyArray(e)?e=new E(e):(r=e,e=t,o=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=r;n&&(t=t.center("column"),o||(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},e.a4=function t(e){if((e=E.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,s,o,n;if(2===e.columns)return r=e.get(0,0),s=e.get(0,1),o=e.get(1,0),n=e.get(1,1),r*n-s*o;if(3===e.columns){let n,i,h;return n=new R(e,[1,2],[1,2]),i=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(n)-s*t(i)+o*t(h)}return new I(e).determinant}throw Error("determinant can only be calculated for a square matrix")},e.DI=function(t,e=!1){return t=z.checkMatrix(t),e?new C(t).inverse():D(t,E.eye(t.rows))},e.Jo=function(t,e={}){const{thresholdValue:r=1e-9,thresholdError:s=1e-9}=e;let o=(t=E.checkMatrix(t)).rows,n=new E(o,o);for(let e=0;e<o;e++){let i=E.columnVector(t.getRow(e)),h=t.subMatrixRow(V(o,e)).transpose(),a=new C(h).solve(i),l=E.sub(i,h.mmul(a)).abs().max();n.setRow(e,q(l,a,e,r,s))}return n},e.Zi=function(t,e=Number.EPSILON){if((t=E.checkMatrix(t)).isEmpty())return t.transpose();let r=new C(t,{autoTranspose:!0}),s=r.leftSingularVectors,o=r.rightSingularVectors,n=r.diagonal;for(let t=0;t<n.length;t++)Math.abs(n[t])>e?n[t]=1/n[t]:n[t]=0;return o.mmul(E.diag(n).mmul(s.transpose()))},e.kH=D,e.LV=function(t,e){if(s.isAnyArray(t))return t[0]&&s.isAnyArray(t[0])?new z(t):new k(t,e);throw new Error("the argument is not an array")}},718(t,e,r){"use strict";r.r(e),r.d(e,{default:()=>o});var s=r(788);function o(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,s.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!(0,s.isAnyArray)(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,s.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,n=e.toIndex,i=void 0===n?t.length:n;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=o||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,s.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,n=e.toIndex,i=void 0===n?t.length:n;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=o||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(o===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,h=void 0===i?r.autoMinMax?o:0:i,a=r.max,l=void 0===a?r.autoMinMax?n:1:a;if(h>=l)throw new RangeError("min option must be smaller than max option");for(var u=(l-h)/(n-o),c=0;c<t.length;c++)e[c]=(t[c]-o)*u+h;return e}},788(t,e,r){"use strict";r.r(e),r.d(e,{isAnyArray:()=>o});const s=Object.prototype.toString;function o(t){const e=s.call(t);return e.endsWith("Array]")&&!e.includes("Big")}}},e={};function r(s){var o=e[s];if(void 0!==o)return o.exports;var n=e[s]={exports:{}};return t[s](n,n.exports,r),n.exports}r.d=(t,e)=>{for(var s in e)r.o(e,s)&&!r.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{"use strict";function t(t,e){return Math.floor(e()*t)}function e(t){return t()}function o(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function n(t){return o(t).map((t,e)=>e)}function i(t,e){return o(t).map(()=>e)}function h(t){return i(t,0)}function a(t){return function(t){return t.reduce((t,e)=>t+e)}(t)/t.length}function l(t){let e=0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e}function u(e,r,s){const o=h(e);for(let n=0;n<e;n++){let e=!0;for(;e;){const i=t(r,s);let h=!1;for(let t=0;t<n;t++)if(i===o[t]){h=!0;break}h||(e=!1),o[n]=i}}return o}function c(t,e,r){const s=[];let o=0,n=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let i=0;i<e;i++){const e=[];for(let s=0;s<r;s++)e.push(t[n]),n+=1;s.push(e),o+=1}return s}function f(t,e){const r=r=>o(t).map(()=>i(e,r)),s=[];return s.push(r(-1)),s.push(r(1/0)),s.push(r(0)),s}function m(e,r,s){const o=h(e);for(let n=0;n<e;n++){let e=!0,i=0;for(;e;){i=t(r,s);let h=!1;for(let t=0;t<n;t++)if(i===o[t]){h=!0;break}h||(e=!1)}o[n]=i}return o}function g(t,e,r,s,o){e=Math.floor(e);const n=t[0][e],i=t[1][e];if(t[2][e],r>=i[0])return 0;for(let t=0;t<n.length;t++)if(s===n[t])return 0;return w(t,e,r,s,o)}function w(t,e,r,s,o){const n=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,n[0]=s,h[0]=o;let a=0,l=0;for(;;){const e=2*a+1,s=e+1,o=t[0][0].length;if(e>=o)break;if(s>=o){if(!(i[e]>r))break;l=e}else if(i[e]>=i[s]){if(!(r<i[e]))break;l=e}else{if(!(r<i[s]))break;l=s}i[a]=i[l],n[a]=n[l],h[a]=h[l],a=l}return i[a]=r,n[a]=s,h[a]=o,1}function p(t,r,s,o,n){const i=f(r,o);for(let o=0;o<r;o++)for(let r=0;r<s;r++){if(t[0][o][r]<0)continue;const s=t[0][o][r],h=t[2][o][r],a=e(n);g(i,o,a,s,h),g(i,s,a,o,h),t[2][o][r]=0}return i}function d(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const s=e[t],o=r[t];for(let t=0;t<s.length-1;t++){const e=s.length-t-1,r=o.length-t-1,n=s[0];s[0]=s[e],s[e]=n;const i=o[0];o[0]=o[r],o[r]=i,y(o,s,r,0)}}return{indices:e,weights:r}}function y(t,e,r,s){for(;2*s+1<r;){const o=2*s+1,n=o+1;let i=s;if(t[i]<t[o]&&(i=o),n<r&&t[i]<t[n]&&(i=n),i===s)break;{const r=t[s];t[s]=t[i],t[i]=r;const o=e[s];e[s]=e[i],e[i]=o,s=i}}}function b(t,e){const r=t[0][e],s=t[1][e],o=t[2][e];let n=1/0,i=-1;for(let t=0;t>r.length;t++)1===o[t]&&s[t]<n&&(n=s[t],i=t);return i>=0?(o[i]=0,Math.floor(r[i])):-1}r.r(s),r.d(s,{UMAP:()=>ht,initWasm:()=>C,isWasmAvailable:()=>D});class M{constructor(t,e,r,s){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=s[0],this.nCols=s[1];for(let s=0;s<r.length;s++){const o=t[s],n=e[s];this.checkDims(o,n);const i=this.makeKey(o,n);this.entries.set(i,{value:r[s],row:o,col:n})}}makeKey(t,e){return`${t}:${e}`}checkDims(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")}set(t,e,r){this.checkDims(t,e);const s=this.makeKey(t,e);this.entries.has(s)?this.entries.get(s).value=r:this.entries.set(s,{value:r,row:t,col:e})}get(t,e,r=0){this.checkDims(t,e);const s=this.makeKey(t,e);return this.entries.has(s)?this.entries.get(s).value:r}getAll(t=!0){const e=[];return this.entries.forEach(t=>{e.push(t)}),t&&e.sort((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row),e}getDims(){return[this.nRows,this.nCols]}getRows(){return Array.from(this.entries,([t,e])=>e.row)}getCols(){return Array.from(this.entries,([t,e])=>e.col)}getValues(){return Array.from(this.entries,([t,e])=>e.value)}forEach(t){this.entries.forEach(e=>t(e.value,e.row,e.col))}map(t){let e=[];this.entries.forEach(r=>{e.push(t(r.value,r.row,r.col))});const r=[this.nRows,this.nCols];return new M(this.getRows(),this.getCols(),e,r)}toArray(){const t=o(this.nRows).map(()=>h(this.nCols));return this.entries.forEach(e=>{t[e.row][e.col]=e.value}),t}}function x(t){const e=[],r=[],s=[];t.forEach((t,o,n)=>{e.push(o),r.push(n),s.push(t)});const o=[t.nCols,t.nRows];return new M(r,e,s,o)}function S(t,e){return z(t,e,(t,e)=>t*e)}function E(t,e){return z(t,e,(t,e)=>t+e)}function v(t,e){return z(t,e,(t,e)=>t-e)}function A(t,e){return t.map(t=>t*e)}function N(t){const e=new Set,r=t.getValues(),s=t.getRows(),o=t.getCols();for(let t=0;t<r.length;t++)0===r[t]&&e.add(t);const n=(t,r)=>!e.has(r),i=r.filter(n),h=s.filter(n),a=o.filter(n);return new M(h,a,i,t.getDims())}function R(t,e="l2"){const r=k[e],s=new Map;t.forEach((t,e,r)=>{const o=s.get(e)||[];o.push(r),s.set(e,o)});const o=new M([],[],[],t.getDims());for(let e of s.keys()){const n=s.get(e).sort(),i=r(n.map(r=>t.get(e,r)));for(let t=0;t<i.length;t++)o.set(e,n[t],i[t])}return o}const k={max:t=>{let e=-1/0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map(t=>t/e)},l1:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r];return t.map(t=>t/e)},l2:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r]**2;return t.map(t=>Math.sqrt(t**2/e))}};function z(t,e,r){const s=new Set,o=[],n=[],i=[],h=(s,h)=>{o.push(s),n.push(h);const a=r(t.get(s,h),e.get(s,h));i.push(a)},a=t.getValues(),l=t.getRows(),u=t.getCols();for(let t=0;t<a.length;t++){const e=l[t],r=u[t],o=`${e}:${r}`;s.add(o),h(e,r)}const c=e.getValues(),f=e.getRows(),m=e.getCols();for(let t=0;t<c.length;t++){const e=f[t],r=m[t],o=`${e}:${r}`;s.has(o)||h(e,r)}const g=[t.nRows,t.nCols];return new M(o,n,i,g)}function I(t){const e=[];t.forEach((t,r,s)=>{e.push({value:t,row:r,col:s})}),e.sort((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row);const r=[],s=[],o=[];let n=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==n&&(n=i,o.push(t)),r.push(h),s.push(a)}return{indices:r,values:s,indptr:o}}let F=null,T=null;async function C(){return F||(F=(async()=>{try{let t;if("undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node){const e=["..","wasm","pkg","node","umap_wasm_core.js"].join("/");t=await r(433)(e)}else try{const e=["..","wasm","pkg","web","umap_wasm_core.js"].join("/");t=await r(433)(e)}catch(e){const r=`${"undefined"!=typeof window&&window.location?window.location.origin:""}/wasm/pkg/web/umap_wasm_core.js`;t=await new Function("p","return import(p)")(r)}return"function"==typeof t.default&&await t.default(),"function"==typeof t.init_threads&&"undefined"!=typeof crossOriginIsolated&&crossOriginIsolated&&"undefined"!=typeof navigator&&"number"==typeof navigator.hardwareConcurrency&&await t.init_threads(navigator.hardwareConcurrency),T=t,t}catch(t){throw F=null,T=null,new Error(`Failed to load WASM module: ${t}`)}})(),F)}function D(){return null!==T}function V(t,e){if(!T)throw new Error("WASM module not initialized");const r=new Float64Array(t),s=new Float64Array(e);return T.euclidean(r,s)}function q(t,e,r,s,o){if(!T)throw new Error("WASM module not initialized");const n=new Float64Array(e*r);for(let s=0;s<e;s++)for(let e=0;e<r;e++)n[s*r+e]=t[s][e];return T.build_rp_tree(n,e,r,s,BigInt(o))}function W(t,e,r,s,o){if(!T)throw new Error("WASM module not initialized");const n=new Int32Array(t),i=new Int32Array(e),h=new Float64Array(r);return new T.WasmSparseMatrix(n,i,h,s,o)}function P(t){if(!T)throw new Error("WASM module not initialized");return T.sparse_transpose(t)}function O(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_add(t,e)}function j(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_subtract(t,e)}function L(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_pairwise_multiply(t,e)}function _(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_multiply_scalar(t,e)}function $(t){const e=Array.from(t.get_all_ordered()),r=[];for(let t=0;t<e.length;t+=3)r.push({row:e[t],col:e[t+1],value:e[t+2]});return r}class U{constructor(t,e,r,s){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=s}static fromWasm(t){const e=function(t){const e=Array.from(t.hyperplanes()),r=Array.from(t.offsets()),s=Array.from(t.children()),o=Array.from(t.indices()),n=t.dim(),i=t.n_nodes(),h=[];for(let t=0;t<i;t++)h.push(e.slice(t*n,(t+1)*n));const a=[];for(let t=0;t<i;t++)a.push([s[2*t],s[2*t+1]]);let l=0;for(let t=0;t<s.length;t++){const e=s[t];if(e<=0){const t=-e;t>l&&(l=t)}}const u=l+1,c=u>0?Math.floor(o.length/u):0,f=[];for(let t=0;t<u;t++){const e=o.slice(t*c,(t+1)*c);for(;e.length<c;)e.push(-1);f.push(e)}return{hyperplanes:h,offsets:r,children:a,indices:f}}(t),r=new U(e.hyperplanes,e.offsets,e.children,e.indices);return r.wasmTree=t,r}getWasmTree(){return this.wasmTree}dispose(){this.wasmTree&&(this.wasmTree.free(),this.wasmTree=void 0)}}function B(t,e,r,s,o=!1){const i=Math.max(10,e);if(o){if(!D())throw new Error("WASM requested but not available");return function(t,e,r,s){const o=t.length,n=t[0].length,i=[];for(let h=0;h<r;h++){const r=q(t,o,n,e,Math.floor(4294967295*s()));i.push(U.fromWasm(r))}return i}(t,i,r,s)}const a=n(r).map((e,r)=>function(t,e=30,r,s){return K(t,n(t.length),e,r,s)}(t,i,r,s)),l=a.map(t=>function(t,e){const r=Q(t),s=Y(t),o=n(r).map(()=>h(t.hyperplane?t.hyperplane.length:0)),i=h(r),a=n(r).map(()=>[-1,-1]),l=n(s).map(()=>n(e).map(()=>-1));return G(t,o,i,a,l,0,0),new U(o,i,a,l)}(t,i));return l}function K(e,r,s=30,o,n){if(r.length>s){const i=function(e,r,s){const o=e[0].length;let n=t(r.length,s),i=t(r.length,s);i+=n===i?1:0,i%=r.length;const a=r[n],l=r[i];let u=0;const c=h(o);for(let t=0;t<c.length;t++)c[t]=e[a][t]-e[l][t],u-=c[t]*(e[a][t]+e[l][t])/2;let f=0,m=0;const g=h(r.length);for(let n=0;n<r.length;n++){let i=u;for(let t=0;t<o;t++)i+=c[t]*e[r[n]][t];0===i?(g[n]=t(2,s),0===g[n]?f+=1:m+=1):i>0?(g[n]=0,f+=1):(g[n]=1,m+=1)}const w=h(f),p=h(m);f=0,m=0;for(let t=0;t<g.length;t++)0===g[t]?(w[f]=r[t],f+=1):(p[m]=r[t],m+=1);return{indicesLeft:w,indicesRight:p,hyperplane:c,offset:u}}(e,r,n),{indicesLeft:a,indicesRight:l,hyperplane:u,offset:c}=i;return{leftChild:K(e,a,s,o+1,n),rightChild:K(e,l,s,o+1,n),isLeaf:!1,hyperplane:u,offset:c}}return{indices:r,isLeaf:!0}}function G(t,e,r,s,o,n,i){if(t.isLeaf)return s[n][0]=-i,o[i].splice(0,t.indices.length,...t.indices),{nodeNum:n,leafNum:i+=1};{e[n]=t.hyperplane,r[n]=t.offset,s[n][0]=n+1;const h=n;let a=G(t.leftChild,e,r,s,o,n+1,i);return n=a.nodeNum,i=a.leafNum,s[h][1]=n+1,a=G(t.rightChild,e,r,s,o,n+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function Q(t){return t.isLeaf?1:1+Q(t.leftChild)+Q(t.rightChild)}function Y(t){return t.isLeaf?1:Y(t.leftChild)+Y(t.rightChild)}function X(e,r,s,o){let n=r;for(let t=0;t<s.length;t++)n+=e[t]*s[t];return 0===n?t(2,o):n>0?0:1}function J(t,e,r){const s=e.getWasmTree();if(s&&D())return function(t,e,r){if(!T)throw new Error("WASM module not initialized");const s=new Float64Array(e),o=T.search_flat_tree(t,s,BigInt(r));return Array.from(o)}(s,t,Math.floor(4294967295*r()));let o=0;for(;e.children[o][0]>0;)o=0===X(e.hyperplanes[o],e.offsets[o],t,r)?e.children[o][0]:e.children[o][1];const n=-1*e.children[o][0];return e.indices[n]}const H=Object.prototype.toString;function Z(t){return H.call(t).endsWith("Array]")}function tt(t,e,r){let s=0;const o=r(e);for(let e=0;e<t.x.length;e++)s+=Math.abs(t.y[e]-o(t.x[e]));return s}var et=r(673);et.y3,et.jy,et.oN,et.Hc,et.cg,et.hj,et.LU,et.Tb;const rt=et.uq,st=(et.Zm,et.Dq,et.__,et.q0,et.lh,et.pI,et.zC,et.zg,et.g6,et.OL,et.ks,et.QR,et.jp,et.mk,et.W2,et.l,et.KY,et.dv,et.BR,et.Wu,et.uq,et.uq,et.a4,et.DI);function ot(t,e,r,s,o){let n=r*s*s,i=rt.eye(e.length,e.length,n);const h=o(e);let a=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)a[e]=h(t.x[e]);let l=function(t,e,r,s,o){const n=r.length,i=t.x.length;let h=new Array(n);for(let a=0;a<n;a++){h[a]=new Array(i);let n=r.slice();n[a]+=s;let l=o(n);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new rt(h)}(t,a,e,s,o),u=function(t,e){const r=t.x.length;let s=new Array(r);for(let o=0;o<r;o++)s[o]=[t.y[o]-e[o]];return new rt(s)}(t,a),c=st(i.add(l.mmul(l.transpose())));return(e=(e=new rt([e])).sub(c.mmul(l).mmul(u).mul(s).transpose())).to1DArray()}et.Jo,et.Zi,et.kH,et.LV;const nt=1e-5,it=.001;class ht{constructor(t={}){this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=at,this.useWasmDistance=!1,this.useWasmNNDescent=!1,this.useWasmMatrix=!1,this.useWasmOptimizer=!1,this.useWasmTree=!1,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new lt,this.wasmOptimizerState=null,this.rngState=BigInt(Math.floor(4294967295*Math.random()));const e=e=>{void 0!==t[e]&&(this[e]=t[e])};e("distanceFn"),e("useWasmDistance"),e("useWasmNNDescent"),e("useWasmMatrix"),e("useWasmTree"),e("useWasmOptimizer"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize")}fit(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding}async fitAsync(t,e=()=>!0){return this.initializeFit(t),await this.optimizeLayoutAsync(e),this.embedding}setSupervisedProjection(t,e={}){this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors}setPrecomputedKNN(t,e){this.knnIndices=t,this.knnDistances=e}initializeFit(t){if(t.length<=this.nNeighbors)throw new Error(`Not enough data points (${t.length}) to create nNeighbors: ${this.nNeighbors}. Add more data points or adjust the configuration.`);if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){const e=this.nearestNeighbors(t);this.knnIndices=e.knnIndices,this.knnDistances=e.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();const{head:e,tail:r,epochsPerSample:s}=this.initializeSimplicialSetEmbedding();return this.optimizationState.head=e,this.optimizationState.tail=r,this.optimizationState.epochsPerSample=s,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()}makeSearchFns(){const t=(t,e)=>{if(this.useWasmDistance){if(!D())throw new Error("WASM distance requested via `useWasmDistance: true` but the wasm module is not initialized or available. Call `await wasmBridge.initWasm()` before using UMAP with wasm distances or build the wasm package.");return V(t,e)}return this.distanceFn(t,e)},{initFromTree:e,initFromRandom:r}=(s=t,{initFromRandom:function(t,e,r,o,n){for(let i=0;i<r.length;i++){const h=u(t,e.length,n);for(let t=0;t<h.length;t++)h[t]<0||g(o,i,s(e[h[t]],r[i]),h[t],1)}},initFromTree:function(t,e,r,o,n){for(let i=0;i<r.length;i++){const h=J(r[i],t,n);for(let t=0;t<h.length;t++){if(h[t]<0)return;g(o,i,s(e[h[t]],r[i]),h[t],1)}}}});var s;this.initFromTree=e,this.initFromRandom=r,this.search=function(t){return function(e,r,s,o){const{indices:n,indptr:i}=I(r);for(let r=0;r<o.length;r++){const h=new Set(s[0][r]);for(;;){const a=b(s,r);if(-1===a)break;const l=n.slice(i[a],i[a+1]);for(const n of l)n===a||-1===n||h.has(n)||(w(s,r,t(e[n],o[r]),n,1),h.add(n))}}return s}}(t)}computeDistance(t,e){if(this.useWasmDistance){if(!D())throw new Error("WASM distance requested via `useWasmDistance: true` but the wasm module is not initialized or available. Call `await wasmBridge.initWasm()` before using UMAP with wasm distances or build the wasm package.");return V(t,e)}return this.distanceFn(t,e)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,s=[t.length,t.length],o=new M([],[],[],s);for(let t=0;t<e.length;t++){const s=e[t],n=r[t];for(let e=0;e<s.length;e++){const r=s[e],i=n[e];i>0&&o.set(t,r,i)}}return z(o,x(o),(t,e)=>t>e?t:e)}transform(t){const e=this.X;if(void 0===e||0===e.length)throw new Error("No data has been fit.");let r=Math.floor(this.nNeighbors*this.transformQueueSize);r=Math.min(e.length,r);const s=function(t,e,r,s,o,n,i){const h=f(r.length,s);if(o(s,e,r,h,i),t)for(let s of t)n(s,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),o=this.search(e,this.searchGraph,s,t);let{indices:n,weights:i}=d(o);n=n.map(t=>t.slice(0,this.nNeighbors)),i=i.map(t=>t.slice(0,this.nNeighbors));const a=Math.max(0,this.localConnectivity-1),{sigmas:l,rhos:u}=this.smoothKNNDistance(i,this.nNeighbors,a),{rows:m,cols:g,vals:w}=this.computeMembershipStrengths(n,i,l,u),p=[t.length,e.length];let y=new M(m,g,w,p);const b=I(R(y,"l1")),x=t.length,S=function(t,e,r){const s=h(t.length).map(t=>h(r[0].length));for(let o=0;o<t.length;o++)for(let n=0;n<t[0].length;n++)for(let i=0;i<r[0].length;i++){const h=t[o][n];s[o][i]+=e[o][n]*r[h][i]}return s}(c(b.indices,x,this.nNeighbors),c(b.values,x,this.nNeighbors),this.embedding),E=this.nEpochs?this.nEpochs/3:y.nRows<=1e4?100:30,v=y.getValues().reduce((t,e)=>e>t?e:t,0);y=y.map(t=>t<v/E?0:t),y=N(y);const A=this.makeEpochsPerSample(y.getValues(),E),k=y.getRows(),z=y.getCols();return this.assignOptimizationStateParameters({headEmbedding:S,tailEmbedding:this.embedding,head:k,tail:z,currentEpoch:0,nEpochs:E,nVertices:y.getDims()[1],epochsPerSample:A}),this.prepareForOptimizationLoop(),this.optimizeLayout()}processGraphForSupervisedProjection(){const{Y:t,X:e}=this;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){const e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}}step(){const{currentEpoch:t}=this.optimizationState;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch}getEmbedding(){return this.embedding}nearestNeighbors(t){const{distanceFn:r,nNeighbors:s}=this,o=function(t,r,s=!1){return function(o,n,i,h=10,a=50,l=.001,u=.5,c=!0){if(s){if(!D())throw new Error("WASM NN-Descent requested but WASM module is not available. Initialize WASM with initWasm() first.");const e=function(t,e,r,s=10,o=50,n=.001,i=.5,h=!0,a="euclidean",l=42){if(!T)throw new Error("WASM module not initialized");const u=t.length,c=t[0].length,f=new Float64Array(u*c);for(let e=0;e<u;e++)for(let r=0;r<c;r++)f[e*c+r]=t[e][r];const m=e.length,g=m>0?e[0].length:0,w=new Int32Array(m*g);for(let t=0;t<m;t++)for(let r=0;r<g;r++)w[t*g+r]=e[t][r];const p=T.nn_descent(f,u,c,w,m,g,r,s,o,n,i,h,a,BigInt(l)),d=[],y=[],b=[],M=u*r,x=2*u*r;for(let t=0;t<u;t++){const e=[],s=[],o=[];for(let n=0;n<r;n++)e.push(p[t*r+n]),s.push(p[M+t*r+n]),o.push(p[x+t*r+n]);d.push(e),y.push(s),b.push(o)}return[d,y,b]}(o,n,i,h,a,l,u,c,"cosine"===t.name?"cosine":"euclidean",Math.floor(4294967295*r()));return{indices:e[0],weights:e[1]}}const w=o.length,y=f(o.length,i);for(let e=0;e<o.length;e++){const s=m(i,o.length,r);for(let r=0;r<s.length;r++){const n=t(o[e],o[s[r]]);g(y,e,n,s[r],1),g(y,s[r],n,e,1)}}if(c)for(let e=0;e<n.length;e++)for(let r=0;r<n[e].length&&!(n[e][r]<0);r++)for(let s=r+1;s<n[e].length&&!(n[e][s]<0);s++){const i=t(o[n[e][r]],o[n[e][s]]);g(y,n[e][r],i,n[e][s],1),g(y,n[e][s],i,n[e][r],1)}for(let s=0;s<h;s++){const s=p(y,w,i,a,r);let n=0;for(let i=0;i<w;i++)for(let h=0;h<a;h++){let l=Math.floor(s[0][i][h]);if(!(l<0||e(r)<u))for(let e=0;e<a;e++){const r=Math.floor(s[0][i][e]),a=s[2][i][h],u=s[2][i][e];if(r<0||!a&&!u)continue;const c=t(o[l],o[r]);n+=g(y,l,c,r,1),n+=g(y,r,c,l,1)}}if(n<=l*i*o.length)break}return d(y)}}(r,this.random,this.useWasmNNDescent),n=5+Math.floor(.5==(i=t.length**.5/20)?0:Math.round(i));var i;const h=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));this.rpForest=B(t,s,n,this.random,this.useWasmTree);const a=function(t){if(t.length>0){const e=[];for(let r of t)e.push(...r.indices);return e}return[[-1]]}(this.rpForest),{indices:l,weights:u}=o(t,a,s,h);return{knnIndices:l,knnDistances:u}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:s=[],knnDistances:o=[],localConnectivity:n}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(o,e,n),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(s,o,i,h),c=[t.length,t.length];if(this.useWasmMatrix&&D()){const t=W(a,l,u,c[0],c[1]),e=P(t),s=L(t,e),o=O(t,e),n=$(O(_(j(o,s),r),_(s,1-r))),i=n.map(t=>t.row),h=n.map(t=>t.col),f=n.map(t=>t.value);return new M(i,h,f,c)}if(this.useWasmMatrix&&D()){const t=W(a,l,u,c[0],c[1]),e=P(t),s=L(t,e),o=O(t,e),n=$(O(_(j(o,s),r),_(s,1-r))),i=n.map(t=>t.row),h=n.map(t=>t.col),f=n.map(t=>t.value);return new M(i,h,f,c)}const f=new M(a,l,u,c),m=x(f),g=S(f,m),w=v(E(f,m),g);return E(A(w,r),A(g,1-r))}categoricalSimplicialSetIntersection(t,e,r,s=1){let o=function(t,e,r=1,s=5){return t.map((t,o,n)=>-1===e[o]||-1===e[n]?t*Math.exp(-r):e[o]!==e[n]?t*Math.exp(-s):t)}(t,e,s,r);return o=N(o),function(t){const e=x(t=R(t,"max"));return N(t=E(t,v(e,S(e,t))))}(o)}smoothKNNDistance(t,e,r=1,s=64,o=1){const n=Math.log(e)/Math.log(2)*o,i=h(t.length),u=h(t.length);for(let e=0;e<t.length;e++){let o=0,h=1/0,c=1;const f=t[e],m=f.filter(t=>t>0);if(m.length>=r){let t=Math.floor(r),s=r-t;t>0?(i[e]=m[t-1],s>nt&&(i[e]+=s*(m[t]-m[t-1]))):i[e]=s*m[0]}else m.length>0&&(i[e]=l(m));for(let r=0;r<s;r++){let r=0;for(let s=1;s<t[e].length;s++){const o=t[e][s]-i[e];r+=o>0?Math.exp(-o/c):1}if(Math.abs(r-n)<nt)break;r>n?(h=c,c=(o+h)/2):(o=c,h===1/0?c*=2:c=(o+h)/2)}if(u[e]=c,i[e]>0){const t=a(f);u[e]<it*t&&(u[e]=it*t)}else{const r=a(t.map(a));u[e]<it*r&&(u[e]=it*r)}}return{sigmas:u,rhos:i}}computeMembershipStrengths(t,e,r,s){const o=t.length,n=t[0].length,i=h(o*n),a=h(o*n),l=h(o*n);for(let h=0;h<o;h++)for(let o=0;o<n;o++){let u=0;-1!==t[h][o]&&(u=t[h][o]===h?0:e[h][o]-s[h]<=0?1:Math.exp(-(e[h][o]-s[h])/r[h]),i[h*n+o]=h,a[h*n+o]=t[h][o],l[h*n+o]=u)}return{rows:i,cols:a,vals:l}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:r}=this,s=this.graph.getValues();let o=0;for(let t=0;t<s.length;t++){const e=s[t];o<s[t]&&(o=e)}const n=this.graph.map(e=>e<o/t?0:e);this.embedding=h(n.nRows).map(()=>h(r).map(()=>20*e(this.random)-10));const i=[],a=[],l=[],u=n.getAll();for(let t=0;t<u.length;t++){const e=u[t];e.value&&(i.push(e.value),l.push(e.row),a.push(e.col))}return{head:a,tail:l,epochsPerSample:this.makeEpochsPerSample(i,t)}}makeEpochsPerSample(t,e){const r=i(t.length,-1),s=l(t),o=t.map(t=>t/s*e);return o.forEach((t,s)=>{t>0&&(r[s]=e/o[s])}),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:s,headEmbedding:o,tailEmbedding:n}=this.optimizationState,i=o[0].length,h=o.length===n.length,a=s.map(t=>t/r),l=[...a],u=[...s];if(this.assignOptimizationStateParameters({epochOfNextSample:u,epochOfNextNegativeSample:l,epochsPerNegativeSample:a,moveOther:h,initialAlpha:e,alpha:e,gamma:t,dim:i}),this.useWasmOptimizer&&D()){const{head:r,tail:l,nEpochs:u,nVertices:c,a:f,b:m}=this.optimizationState;this.wasmOptimizerState=function(t,e,r,s,o,n,i,h,a,l,u,c,f,m){if(!T)throw new Error("WASM module not initialized");const g=new Float64Array(r.length*c),w=new Float64Array(s.length*c);for(let t=0;t<r.length;t++)for(let e=0;e<c;e++)g[t*c+e]=r[t][e];for(let t=0;t<s.length;t++)for(let e=0;e<c;e++)w[t*c+e]=s[t][e];const p=new Uint32Array(t),d=new Uint32Array(e),y=new Float64Array(o),b=new Float64Array(n);return new T.OptimizerState(p,d,g,w,y,b,i,h,a,l,u,c,f,m)}(r,l,o,n,s,a,h,e,t,f,m,i,u,c)}}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:s,epochsPerSample:n}=this.optimizationState,i=this.getNEpochs(),a=this.graph.nCols,{a:l,b:u}=function(t,e){const r=function(t,e){return o(300).map((t,r)=>0+r*((e-0)/299))}(0,3*t).map(t=>t<e?1:t),s=h(r.length).map((s,o)=>r[o]>=e?Math.exp(-(r[o]-e)/t):s),n={x:r,y:s},{parameterValues:i}=function(t,e,r={}){let{maxIterations:s=100,gradientDifference:o=.1,damping:n=0,errorTolerance:i=.01,minValues:h,maxValues:a,initialValues:l}=r;if(n<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!Z(t.x)||t.x.length<2||!Z(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");let u=l||new Array(e.length).fill(1),c=u.length;if(a=a||new Array(c).fill(Number.MAX_SAFE_INTEGER),h=h||new Array(c).fill(Number.MIN_SAFE_INTEGER),a.length!==h.length)throw new Error("minValues and maxValues must be the same size");if(!Z(u))throw new Error("initialValues must be an array");let f,m=tt(t,u,e),g=m<=i;for(f=0;f<s&&!g;f++){u=ot(t,u,n,o,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(m=tt(t,u,e),isNaN(m))break;g=m<=i}return{parameterValues:u,parameterError:m,iterations:f}}(n,([t,e])=>r=>1/(1+t*r**(2*e)),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[a,l]=i;return{a,b:l}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:s,epochsPerSample:n,a:l,b:u,nEpochs:i,nVertices:a})}optimizeLayoutStep(e){if(this.useWasmOptimizer&&this.wasmOptimizerState){const t=function(t,e){if(!T)throw new Error("WASM module not initialized");return T.optimize_layout_step(t,e)}(this.wasmOptimizerState,this.rngState),e=BigInt("6364136223846793005"),r=BigInt("1442695040888963407");this.rngState=this.rngState*e+r&BigInt("0xFFFFFFFFFFFFFFFF");const{dim:s}=this.optimizationState,{headEmbedding:o}=this.optimizationState,n=o.length;for(let e=0;e<n;e++)for(let r=0;r<s;r++)o[e][r]=t[e*s+r];return this.optimizationState.currentEpoch+=1,o}const{optimizationState:r}=this,{head:s,tail:o,headEmbedding:n,tailEmbedding:i,epochsPerSample:h,epochOfNextSample:a,epochOfNextNegativeSample:l,epochsPerNegativeSample:u,moveOther:c,initialAlpha:f,alpha:m,gamma:g,a:w,b:p,dim:d,nEpochs:y,nVertices:b}=r;for(let r=0;r<h.length;r++){if(a[r]>e)continue;const f=s[r],y=o[r],M=n[f],x=i[y],S=ct(M,x);let E=0;S>0&&(E=-2*w*p*Math.pow(S,p-1),E/=w*Math.pow(S,p)+1);for(let t=0;t<d;t++){const e=ut(E*(M[t]-x[t]),4);M[t]+=e*m,c&&(x[t]+=-e*m)}a[r]+=h[r];const v=Math.floor((e-l[r])/u[r]);for(let e=0;e<v;e++){const e=t(b,this.random),r=i[e],s=ct(M,r);let o=0;if(s>0)o=2*g*p,o/=(.001+s)*(w*Math.pow(s,p)+1);else if(f===e)continue;for(let t=0;t<d;t++){let e=4;o>0&&(e=ut(o*(M[t]-r[t]),4)),M[t]+=e*m}}l[r]+=v*u[r]}return r.alpha=f*(1-e/y),r.currentEpoch+=1,n}optimizeLayoutAsync(t=()=>!0){return new Promise((e,r)=>{const s=async()=>{try{const{nEpochs:r,currentEpoch:o}=this.optimizationState;this.embedding=this.optimizeLayoutStep(o);const n=this.optimizationState.currentEpoch,i=!1===t(n),h=n===r;if(i||h)return e(h);setTimeout(()=>s(),0)}catch(t){r(t)}};setTimeout(()=>s(),0)})}optimizeLayout(t=()=>!0){let e=!1,r=[];for(;!e;){const{nEpochs:s,currentEpoch:o}=this.optimizationState;r=this.optimizeLayoutStep(o);const n=this.optimizationState.currentEpoch,i=!1===t(n);e=n===s||i}return r}getNEpochs(){const t=this.graph;if(this.nEpochs>0)return this.nEpochs;const e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200}}function at(t,e){let r=0;for(let s=0;s<t.length;s++)r+=(t[s]-e[s])**2;return Math.sqrt(r)}class lt{constructor(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0}}function ut(t,e){return t>e?e:t<-e?-e:t}function ct(t,e){let r=0;for(let s=0;s<t.length;s++)r+=Math.pow(t[s]-e[s],2);return r}})(),s})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elarsaks/umap-wasm",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "JavaScript implementation of UMAP",
5
5
  "author": {
6
6
  "name": "Elar Saks",
@@ -36,7 +36,7 @@
36
36
  "preview": "npx serve . -p 4173",
37
37
  "bundle": "rm -rf lib && webpack --config ./webpack/lib.config.mjs && webpack --config ./webpack/lib.min.config.mjs",
38
38
  "build": "rm -rf dist && tsc && yarn bundle",
39
- "build:wasm": "cd wasm && wasm-pack build --target web --out-dir pkg/web && wasm-pack build --target nodejs --out-dir pkg/node && rm -f pkg/web/.gitignore pkg/node/.gitignore"
39
+ "build:wasm": "cd wasm && RUSTFLAGS=\"-C target-feature=+atomics,+bulk-memory\" rustup run nightly wasm-pack build --target web --out-dir pkg/web -- --features threads && rustup run nightly wasm-pack build --target nodejs --out-dir pkg/node && rm -f pkg/web/.gitignore pkg/node/.gitignore"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@playwright/test": "^1.57.0",
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright 2022 Google Inc. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ * Unless required by applicable law or agreed to in writing, software
8
+ * distributed under the License is distributed on an "AS IS" BASIS,
9
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ * See the License for the specific language governing permissions and
11
+ * limitations under the License.
12
+ */
13
+
14
+ // Note: we use `wasm_bindgen_worker_`-prefixed message types to make sure
15
+ // we can handle bundling into other files, which might happen to have their
16
+ // own `postMessage`/`onmessage` communication channels.
17
+ //
18
+ // If we didn't take that into the account, we could send much simpler signals
19
+ // like just `0` or whatever, but the code would be less resilient.
20
+
21
+ function waitForMsgType(target, type) {
22
+ return new Promise(resolve => {
23
+ target.addEventListener('message', function onMsg({ data }) {
24
+ if (data?.type !== type) return;
25
+ target.removeEventListener('message', onMsg);
26
+ resolve(data);
27
+ });
28
+ });
29
+ }
30
+
31
+ waitForMsgType(self, 'wasm_bindgen_worker_init').then(async ({ init, receiver }) => {
32
+ // # Note 1
33
+ // Our JS should have been generated in
34
+ // `[out-dir]/snippets/wasm-bindgen-rayon-[hash]/workerHelpers.js`,
35
+ // resolve the main module via `../../..`.
36
+ //
37
+ // This might need updating if the generated structure changes on wasm-bindgen
38
+ // side ever in the future, but works well with bundlers today. The whole
39
+ // point of this crate, after all, is to abstract away unstable features
40
+ // and temporary bugs so that you don't need to deal with them in your code.
41
+ //
42
+ // # Note 2
43
+ // This could be a regular import, but then some bundlers complain about
44
+ // circular deps.
45
+ //
46
+ // Dynamic import could be cheap if this file was inlined into the parent,
47
+ // which would require us just using `../../..` in `new Worker` below,
48
+ // but that doesn't work because wasm-pack unconditionally adds
49
+ // "sideEffects":false (see below).
50
+ //
51
+ // OTOH, even though it can't be inlined, it should be still reasonably
52
+ // cheap since the requested file is already in cache (it was loaded by
53
+ // the main thread).
54
+ const pkg = await import('../../..');
55
+ await pkg.default(init);
56
+ postMessage({ type: 'wasm_bindgen_worker_ready' });
57
+ pkg.wbg_rayon_start_worker(receiver);
58
+ });
59
+
60
+ // Note: this is never used, but necessary to prevent a bug in Firefox
61
+ // (https://bugzilla.mozilla.org/show_bug.cgi?id=1702191) where it collects
62
+ // Web Workers that have a shared WebAssembly memory with the main thread,
63
+ // but are not explicitly rooted via a `Worker` instance.
64
+ //
65
+ // By storing them in a variable, we can keep `Worker` objects around and
66
+ // prevent them from getting GC-d.
67
+ let _workers;
68
+
69
+ export async function startWorkers(module, memory, builder) {
70
+ if (builder.numThreads() === 0) {
71
+ throw new Error(`num_threads must be > 0.`);
72
+ }
73
+
74
+ const workerInit = {
75
+ type: 'wasm_bindgen_worker_init',
76
+ init: { module_or_path: module, memory },
77
+ receiver: builder.receiver()
78
+ };
79
+
80
+ _workers = await Promise.all(
81
+ Array.from({ length: builder.numThreads() }, async () => {
82
+ // Self-spawn into a new Worker.
83
+ //
84
+ // TODO: while `new URL('...', import.meta.url) becomes a semi-standard
85
+ // way to get asset URLs relative to the module across various bundlers
86
+ // and browser, ideally we should switch to `import.meta.resolve`
87
+ // once it becomes a standard.
88
+ //
89
+ // Note: we could use `../../..` as the URL here to inline workerHelpers.js
90
+ // into the parent entry instead of creating another split point -
91
+ // this would be preferable from optimization perspective -
92
+ // however, Webpack then eliminates all message handler code
93
+ // because wasm-pack produces "sideEffects":false in package.json
94
+ // unconditionally.
95
+ //
96
+ // The only way to work around that is to have side effect code
97
+ // in an entry point such as Worker file itself.
98
+ const worker = new Worker(new URL('./workerHelpers.js', import.meta.url), {
99
+ type: 'module'
100
+ });
101
+ worker.postMessage(workerInit);
102
+ await waitForMsgType(worker, 'wasm_bindgen_worker_ready');
103
+ return worker;
104
+ })
105
+ );
106
+ builder.build();
107
+ }
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright 2022 Google Inc. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ * http://www.apache.org/licenses/LICENSE-2.0
7
+ * Unless required by applicable law or agreed to in writing, software
8
+ * distributed under the License is distributed on an "AS IS" BASIS,
9
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ * See the License for the specific language governing permissions and
11
+ * limitations under the License.
12
+ */
13
+
14
+ // Note: we use `wasm_bindgen_worker_`-prefixed message types to make sure
15
+ // we can handle bundling into other files, which might happen to have their
16
+ // own `postMessage`/`onmessage` communication channels.
17
+ //
18
+ // If we didn't take that into the account, we could send much simpler signals
19
+ // like just `0` or whatever, but the code would be less resilient.
20
+
21
+ function waitForMsgType(target, type) {
22
+ return new Promise(resolve => {
23
+ target.addEventListener('message', function onMsg({ data }) {
24
+ if (data?.type !== type) return;
25
+ target.removeEventListener('message', onMsg);
26
+ resolve(data);
27
+ });
28
+ });
29
+ }
30
+
31
+ waitForMsgType(self, 'wasm_bindgen_worker_init').then(async ({ init, receiver }) => {
32
+ // # Note 1
33
+ // Our JS should have been generated in
34
+ // `[out-dir]/snippets/wasm-bindgen-rayon-[hash]/workerHelpers.js`,
35
+ // resolve the main module via `../../..`.
36
+ //
37
+ // This might need updating if the generated structure changes on wasm-bindgen
38
+ // side ever in the future, but works well with bundlers today. The whole
39
+ // point of this crate, after all, is to abstract away unstable features
40
+ // and temporary bugs so that you don't need to deal with them in your code.
41
+ //
42
+ // # Note 2
43
+ // This could be a regular import, but then some bundlers complain about
44
+ // circular deps.
45
+ //
46
+ // Dynamic import could be cheap if this file was inlined into the parent,
47
+ // which would require us just using `../../..` in `new Worker` below,
48
+ // but that doesn't work because wasm-pack unconditionally adds
49
+ // "sideEffects":false (see below).
50
+ //
51
+ // OTOH, even though it can't be inlined, it should be still reasonably
52
+ // cheap since the requested file is already in cache (it was loaded by
53
+ // the main thread).
54
+ const pkg = await import('../../..');
55
+ await pkg.default(init);
56
+ postMessage({ type: 'wasm_bindgen_worker_ready' });
57
+ pkg.wbg_rayon_start_worker(receiver);
58
+ });
59
+
60
+ // Note: this is never used, but necessary to prevent a bug in Firefox
61
+ // (https://bugzilla.mozilla.org/show_bug.cgi?id=1702191) where it collects
62
+ // Web Workers that have a shared WebAssembly memory with the main thread,
63
+ // but are not explicitly rooted via a `Worker` instance.
64
+ //
65
+ // By storing them in a variable, we can keep `Worker` objects around and
66
+ // prevent them from getting GC-d.
67
+ let _workers;
68
+
69
+ export async function startWorkers(module, memory, builder) {
70
+ if (builder.numThreads() === 0) {
71
+ throw new Error(`num_threads must be > 0.`);
72
+ }
73
+
74
+ const workerInit = {
75
+ type: 'wasm_bindgen_worker_init',
76
+ init: { module_or_path: module, memory },
77
+ receiver: builder.receiver()
78
+ };
79
+
80
+ _workers = await Promise.all(
81
+ Array.from({ length: builder.numThreads() }, async () => {
82
+ // Self-spawn into a new Worker.
83
+ //
84
+ // TODO: while `new URL('...', import.meta.url) becomes a semi-standard
85
+ // way to get asset URLs relative to the module across various bundlers
86
+ // and browser, ideally we should switch to `import.meta.resolve`
87
+ // once it becomes a standard.
88
+ //
89
+ // Note: we could use `../../..` as the URL here to inline workerHelpers.js
90
+ // into the parent entry instead of creating another split point -
91
+ // this would be preferable from optimization perspective -
92
+ // however, Webpack then eliminates all message handler code
93
+ // because wasm-pack produces "sideEffects":false in package.json
94
+ // unconditionally.
95
+ //
96
+ // The only way to work around that is to have side effect code
97
+ // in an entry point such as Worker file itself.
98
+ const worker = new Worker(new URL('./workerHelpers.js', import.meta.url), {
99
+ type: 'module'
100
+ });
101
+ worker.postMessage(workerInit);
102
+ await waitForMsgType(worker, 'wasm_bindgen_worker_ready');
103
+ return worker;
104
+ })
105
+ );
106
+ builder.build();
107
+ }
@@ -172,6 +172,10 @@ export function cosine(x: Float64Array, y: Float64Array): number;
172
172
  */
173
173
  export function euclidean(x: Float64Array, y: Float64Array): number;
174
174
 
175
+ export function initThreadPool(num_threads: number): Promise<any>;
176
+
177
+ export function init_threads(n_threads: number): Promise<any>;
178
+
175
179
  /**
176
180
  * Nearest Neighbor Descent implementation in Rust/WASM.
177
181
  *
@@ -302,6 +306,17 @@ export function sparse_transpose(matrix: WasmSparseMatrix): WasmSparseMatrix;
302
306
  */
303
307
  export function version(): string;
304
308
 
309
+ export class wbg_rayon_PoolBuilder {
310
+ private constructor();
311
+ free(): void;
312
+ [Symbol.dispose](): void;
313
+ numThreads(): number;
314
+ build(): void;
315
+ receiver(): number;
316
+ }
317
+
318
+ export function wbg_rayon_start_worker(receiver: number): void;
319
+
305
320
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
306
321
 
307
322
  export interface InitOutput {
@@ -318,6 +333,7 @@ export interface InitOutput {
318
333
  readonly flattree_indices: (a: number) => [number, number];
319
334
  readonly flattree_n_nodes: (a: number) => number;
320
335
  readonly flattree_offsets: (a: number) => any;
336
+ readonly init_threads: (a: number) => any;
321
337
  readonly nn_descent: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: bigint) => [number, number, number, number];
322
338
  readonly optimize_layout_batch: (a: number, b: bigint, c: number) => [number, number];
323
339
  readonly optimize_layout_step: (a: number, b: bigint) => [number, number];
@@ -350,6 +366,14 @@ export interface InitOutput {
350
366
  readonly wasmsparsematrix_nnz: (a: number) => number;
351
367
  readonly wasmsparsematrix_set: (a: number, b: number, c: number, d: number) => [number, number];
352
368
  readonly wasmsparsematrix_to_array: (a: number) => any;
369
+ readonly __wbg_wbg_rayon_poolbuilder_free: (a: number, b: number) => void;
370
+ readonly initThreadPool: (a: number) => any;
371
+ readonly wbg_rayon_poolbuilder_build: (a: number) => void;
372
+ readonly wbg_rayon_poolbuilder_numThreads: (a: number) => number;
373
+ readonly wbg_rayon_poolbuilder_receiver: (a: number) => number;
374
+ readonly wbg_rayon_start_worker: (a: number) => void;
375
+ readonly __wbindgen_exn_store: (a: number) => void;
376
+ readonly __externref_table_alloc: () => number;
353
377
  readonly __wbindgen_externrefs: WebAssembly.Table;
354
378
  readonly __wbindgen_malloc: (a: number, b: number) => number;
355
379
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -1,5 +1,13 @@
1
+ import { startWorkers } from './snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.js';
2
+
1
3
  let wasm;
2
4
 
5
+ function addToExternrefTable0(obj) {
6
+ const idx = wasm.__externref_table_alloc();
7
+ wasm.__wbindgen_externrefs.set(idx, obj);
8
+ return idx;
9
+ }
10
+
3
11
  function _assertClass(instance, klass) {
4
12
  if (!(instance instanceof klass)) {
5
13
  throw new Error(`expected instance of ${klass.name}`);
@@ -58,6 +66,19 @@ function getUint8ArrayMemory0() {
58
66
  return cachedUint8ArrayMemory0;
59
67
  }
60
68
 
69
+ function handleError(f, args) {
70
+ try {
71
+ return f.apply(this, args);
72
+ } catch (e) {
73
+ const idx = addToExternrefTable0(e);
74
+ wasm.__wbindgen_exn_store(idx);
75
+ }
76
+ }
77
+
78
+ function isLikeNone(x) {
79
+ return x === undefined || x === null;
80
+ }
81
+
61
82
  function passArray32ToWasm0(arg, malloc) {
62
83
  const ptr = malloc(arg.length * 4, 4) >>> 0;
63
84
  getUint32ArrayMemory0().set(arg, ptr / 4);
@@ -156,6 +177,10 @@ const WasmSparseMatrixFinalization = (typeof FinalizationRegistry === 'undefined
156
177
  ? { register: () => {}, unregister: () => {} }
157
178
  : new FinalizationRegistry(ptr => wasm.__wbg_wasmsparsematrix_free(ptr >>> 0, 1));
158
179
 
180
+ const wbg_rayon_PoolBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
181
+ ? { register: () => {}, unregister: () => {} }
182
+ : new FinalizationRegistry(ptr => wasm.__wbg_wbg_rayon_poolbuilder_free(ptr >>> 0, 1));
183
+
159
184
  /**
160
185
  * A flattened random projection tree structure for efficient nearest neighbor search.
161
186
  * The tree is represented in flat arrays for efficient memory layout and cache performance.
@@ -573,6 +598,24 @@ export function euclidean(x, y) {
573
598
  return ret;
574
599
  }
575
600
 
601
+ /**
602
+ * @param {number} num_threads
603
+ * @returns {Promise<any>}
604
+ */
605
+ export function initThreadPool(num_threads) {
606
+ const ret = wasm.initThreadPool(num_threads);
607
+ return ret;
608
+ }
609
+
610
+ /**
611
+ * @param {number} n_threads
612
+ * @returns {Promise<any>}
613
+ */
614
+ export function init_threads(n_threads) {
615
+ const ret = wasm.init_threads(n_threads);
616
+ return ret;
617
+ }
618
+
576
619
  /**
577
620
  * Nearest Neighbor Descent implementation in Rust/WASM.
578
621
  *
@@ -846,6 +889,51 @@ export function version() {
846
889
  }
847
890
  }
848
891
 
892
+ export class wbg_rayon_PoolBuilder {
893
+ static __wrap(ptr) {
894
+ ptr = ptr >>> 0;
895
+ const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
896
+ obj.__wbg_ptr = ptr;
897
+ wbg_rayon_PoolBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
898
+ return obj;
899
+ }
900
+ __destroy_into_raw() {
901
+ const ptr = this.__wbg_ptr;
902
+ this.__wbg_ptr = 0;
903
+ wbg_rayon_PoolBuilderFinalization.unregister(this);
904
+ return ptr;
905
+ }
906
+ free() {
907
+ const ptr = this.__destroy_into_raw();
908
+ wasm.__wbg_wbg_rayon_poolbuilder_free(ptr, 0);
909
+ }
910
+ /**
911
+ * @returns {number}
912
+ */
913
+ numThreads() {
914
+ const ret = wasm.wbg_rayon_poolbuilder_numThreads(this.__wbg_ptr);
915
+ return ret >>> 0;
916
+ }
917
+ build() {
918
+ wasm.wbg_rayon_poolbuilder_build(this.__wbg_ptr);
919
+ }
920
+ /**
921
+ * @returns {number}
922
+ */
923
+ receiver() {
924
+ const ret = wasm.wbg_rayon_poolbuilder_receiver(this.__wbg_ptr);
925
+ return ret >>> 0;
926
+ }
927
+ }
928
+ if (Symbol.dispose) wbg_rayon_PoolBuilder.prototype[Symbol.dispose] = wbg_rayon_PoolBuilder.prototype.free;
929
+
930
+ /**
931
+ * @param {number} receiver
932
+ */
933
+ export function wbg_rayon_start_worker(receiver) {
934
+ wasm.wbg_rayon_start_worker(receiver);
935
+ }
936
+
849
937
  const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
850
938
 
851
939
  async function __wbg_load(module, imports) {
@@ -881,9 +969,35 @@ async function __wbg_load(module, imports) {
881
969
  function __wbg_get_imports() {
882
970
  const imports = {};
883
971
  imports.wbg = {};
972
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
973
+ const ret = arg0 === undefined;
974
+ return ret;
975
+ };
976
+ imports.wbg.__wbg___wbindgen_memory_a342e963fbcabd68 = function() {
977
+ const ret = wasm.memory;
978
+ return ret;
979
+ };
980
+ imports.wbg.__wbg___wbindgen_module_967adef62ea6cbf8 = function() {
981
+ const ret = __wbg_init.__wbindgen_wasm_module;
982
+ return ret;
983
+ };
884
984
  imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
885
985
  throw new Error(getStringFromWasm0(arg0, arg1));
886
986
  };
987
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
988
+ const ret = arg0.call(arg1);
989
+ return ret;
990
+ }, arguments) };
991
+ imports.wbg.__wbg_instanceof_Window_b5cf7783caa68180 = function(arg0) {
992
+ let result;
993
+ try {
994
+ result = arg0 instanceof Window;
995
+ } catch (_) {
996
+ result = false;
997
+ }
998
+ const ret = result;
999
+ return ret;
1000
+ };
887
1001
  imports.wbg.__wbg_new_from_slice_9a48ef80d2a51f94 = function(arg0, arg1) {
888
1002
  const ret = new Float64Array(getArrayF64FromWasm0(arg0, arg1));
889
1003
  return ret;
@@ -892,6 +1006,30 @@ function __wbg_get_imports() {
892
1006
  const ret = new Int32Array(getArrayI32FromWasm0(arg0, arg1));
893
1007
  return ret;
894
1008
  };
1009
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
1010
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
1011
+ return ret;
1012
+ };
1013
+ imports.wbg.__wbg_startWorkers_2ca11761e08ff5d5 = function(arg0, arg1, arg2) {
1014
+ const ret = startWorkers(arg0, arg1, wbg_rayon_PoolBuilder.__wrap(arg2));
1015
+ return ret;
1016
+ };
1017
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
1018
+ const ret = typeof global === 'undefined' ? null : global;
1019
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1020
+ };
1021
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
1022
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
1023
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1024
+ };
1025
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
1026
+ const ret = typeof self === 'undefined' ? null : self;
1027
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1028
+ };
1029
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
1030
+ const ret = typeof window === 'undefined' ? null : window;
1031
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
1032
+ };
895
1033
  imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
896
1034
  // Cast intrinsic for `Ref(String) -> Externref`.
897
1035
  const ret = getStringFromWasm0(arg0, arg1);
Binary file
@@ -13,6 +13,7 @@ export const flattree_hyperplanes: (a: number) => any;
13
13
  export const flattree_indices: (a: number) => [number, number];
14
14
  export const flattree_n_nodes: (a: number) => number;
15
15
  export const flattree_offsets: (a: number) => any;
16
+ export const init_threads: (a: number) => any;
16
17
  export const nn_descent: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: bigint) => [number, number, number, number];
17
18
  export const optimize_layout_batch: (a: number, b: bigint, c: number) => [number, number];
18
19
  export const optimize_layout_step: (a: number, b: bigint) => [number, number];
@@ -45,6 +46,14 @@ export const wasmsparsematrix_new: (a: number, b: number, c: number, d: number,
45
46
  export const wasmsparsematrix_nnz: (a: number) => number;
46
47
  export const wasmsparsematrix_set: (a: number, b: number, c: number, d: number) => [number, number];
47
48
  export const wasmsparsematrix_to_array: (a: number) => any;
49
+ export const __wbg_wbg_rayon_poolbuilder_free: (a: number, b: number) => void;
50
+ export const initThreadPool: (a: number) => any;
51
+ export const wbg_rayon_poolbuilder_build: (a: number) => void;
52
+ export const wbg_rayon_poolbuilder_numThreads: (a: number) => number;
53
+ export const wbg_rayon_poolbuilder_receiver: (a: number) => number;
54
+ export const wbg_rayon_start_worker: (a: number) => void;
55
+ export const __wbindgen_exn_store: (a: number) => void;
56
+ export const __externref_table_alloc: () => number;
48
57
  export const __wbindgen_externrefs: WebAssembly.Table;
49
58
  export const __wbindgen_malloc: (a: number, b: number) => number;
50
59
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;