@elarsaks/umap-wasm 0.4.8 → 0.5.0

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.
@@ -64,7 +64,7 @@ export declare function wasmSparseMatrixGetAllTyped(matrix: WasmSparseMatrix): {
64
64
  export declare function nnDescentWasm(data: number[][], leafArray: ArrayLike<number>[], nNeighbors: number, nIters?: number, maxCandidates?: number, delta?: number, rho?: number, rpTreeInit?: boolean, distanceMetric?: string, seed?: number): number[][][];
65
65
  export declare function nnDescentWasmFlat(flatData: Float64Array, nSamples: number, dim: number, flatLeafArray: Int32Array, nLeaves: number, leafSize: number, nNeighbors: number, nIters?: number, maxCandidates?: number, delta?: number, rho?: number, rpTreeInit?: boolean, distanceMetric?: string, seed?: number): number[];
66
66
  export interface WasmOptimizerState {
67
- head_embedding: Float32Array;
67
+ head_embedding: Float64Array;
68
68
  current_epoch: number;
69
69
  n_epochs: number;
70
70
  head_embedding_ptr(): number;
@@ -74,8 +74,8 @@ export interface WasmOptimizerState {
74
74
  free(): void;
75
75
  }
76
76
  export declare function createOptimizerState(head: number[], tail: number[], headEmbedding: number[][], tailEmbedding: number[][], epochsPerSample: number[], epochsPerNegativeSample: number[], moveOther: boolean, initialAlpha: number, gamma: number, a: number, b: number, dim: number, nEpochs: number, nVertices: number): WasmOptimizerState;
77
- export declare function optimizeLayoutStepWasm(state: WasmOptimizerState): Float32Array;
77
+ export declare function optimizeLayoutStepWasm(state: WasmOptimizerState): Float64Array;
78
78
  export declare function optimizeLayoutStepInPlaceWasm(state: WasmOptimizerState): void;
79
- export declare function optimizeLayoutBatchWasm(state: WasmOptimizerState, nSteps: number): Float32Array;
79
+ export declare function optimizeLayoutBatchWasm(state: WasmOptimizerState, nSteps: number): Float64Array;
80
80
  export declare function optimizeLayoutBatchInPlaceWasm(state: WasmOptimizerState, nSteps: number): void;
81
- export declare function getOptimizerEmbeddingView(state: WasmOptimizerState): Float32Array;
81
+ export declare function getOptimizerEmbeddingView(state: WasmOptimizerState): Float64Array;
@@ -273,8 +273,8 @@ export function nnDescentWasmFlat(flatData, nSamples, dim, flatLeafArray, nLeave
273
273
  export function createOptimizerState(head, tail, headEmbedding, tailEmbedding, epochsPerSample, epochsPerNegativeSample, moveOther, initialAlpha, gamma, a, b, dim, nEpochs, nVertices) {
274
274
  if (!wasmModule)
275
275
  throw new Error('WASM module not initialized');
276
- const flatHeadEmbedding = new Float32Array(headEmbedding.length * dim);
277
- const flatTailEmbedding = new Float32Array(tailEmbedding.length * dim);
276
+ const flatHeadEmbedding = new Float64Array(headEmbedding.length * dim);
277
+ const flatTailEmbedding = new Float64Array(tailEmbedding.length * dim);
278
278
  for (let i = 0; i < headEmbedding.length; i++) {
279
279
  for (let j = 0; j < dim; j++) {
280
280
  flatHeadEmbedding[i * dim + j] = headEmbedding[i][j];
@@ -287,8 +287,8 @@ export function createOptimizerState(head, tail, headEmbedding, tailEmbedding, e
287
287
  }
288
288
  const headArray = new Uint32Array(head);
289
289
  const tailArray = new Uint32Array(tail);
290
- const epochsPerSampleArray = new Float32Array(epochsPerSample);
291
- const epochsPerNegativeSampleArray = new Float32Array(epochsPerNegativeSample);
290
+ const epochsPerSampleArray = new Float64Array(epochsPerSample);
291
+ const epochsPerNegativeSampleArray = new Float64Array(epochsPerNegativeSample);
292
292
  return new wasmModule.OptimizerState(headArray, tailArray, flatHeadEmbedding, flatTailEmbedding, epochsPerSampleArray, epochsPerNegativeSampleArray, moveOther, initialAlpha, gamma, a, b, dim, nEpochs, nVertices);
293
293
  }
294
294
  export function optimizeLayoutStepWasm(state) {
@@ -322,5 +322,5 @@ export function getOptimizerEmbeddingView(state) {
322
322
  if (!memory?.buffer) {
323
323
  throw new Error('WASM memory is not available');
324
324
  }
325
- return new Float32Array(memory.buffer, ptr, len);
325
+ return new Float64Array(memory.buffer, ptr, len);
326
326
  }
package/lib/umap-js.js CHANGED
@@ -6747,8 +6747,8 @@ function nnDescentWasmFlat(flatData, nSamples, dim, flatLeafArray, nLeaves, leaf
6747
6747
  function createOptimizerState(head, tail, headEmbedding, tailEmbedding, epochsPerSample, epochsPerNegativeSample, moveOther, initialAlpha, gamma, a, b, dim, nEpochs, nVertices) {
6748
6748
  if (!wasmModule)
6749
6749
  throw new Error('WASM module not initialized');
6750
- const flatHeadEmbedding = new Float32Array(headEmbedding.length * dim);
6751
- const flatTailEmbedding = new Float32Array(tailEmbedding.length * dim);
6750
+ const flatHeadEmbedding = new Float64Array(headEmbedding.length * dim);
6751
+ const flatTailEmbedding = new Float64Array(tailEmbedding.length * dim);
6752
6752
  for (let i = 0; i < headEmbedding.length; i++) {
6753
6753
  for (let j = 0; j < dim; j++) {
6754
6754
  flatHeadEmbedding[i * dim + j] = headEmbedding[i][j];
@@ -6761,8 +6761,8 @@ function createOptimizerState(head, tail, headEmbedding, tailEmbedding, epochsPe
6761
6761
  }
6762
6762
  const headArray = new Uint32Array(head);
6763
6763
  const tailArray = new Uint32Array(tail);
6764
- const epochsPerSampleArray = new Float32Array(epochsPerSample);
6765
- const epochsPerNegativeSampleArray = new Float32Array(epochsPerNegativeSample);
6764
+ const epochsPerSampleArray = new Float64Array(epochsPerSample);
6765
+ const epochsPerNegativeSampleArray = new Float64Array(epochsPerNegativeSample);
6766
6766
  return new wasmModule.OptimizerState(headArray, tailArray, flatHeadEmbedding, flatTailEmbedding, epochsPerSampleArray, epochsPerNegativeSampleArray, moveOther, initialAlpha, gamma, a, b, dim, nEpochs, nVertices);
6767
6767
  }
6768
6768
  function optimizeLayoutStepWasm(state) {
@@ -6796,7 +6796,7 @@ function getOptimizerEmbeddingView(state) {
6796
6796
  if (!memory?.buffer) {
6797
6797
  throw new Error('WASM memory is not available');
6798
6798
  }
6799
- return new Float32Array(memory.buffer, ptr, len);
6799
+ return new Float64Array(memory.buffer, ptr, len);
6800
6800
  }
6801
6801
 
6802
6802
  ;// ./src/tree.ts
@@ -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 i=" ".repeat(2),n=" ".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${i}[\n${n}${function(t,e,r,s,o){const{rows:i,columns:h}=t,l=Math.min(i,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 i=0;i<u;i++)r.push(a(t.get(e,i),s,o));c.push(`${r.join(" ")}`)}return u!==h&&(c[c.length-1]+=` ... ${h-r} more columns`),l!==i&&c.push(`... ${i-e} more rows`),c.join(`\n${n}`)}(t,r,s,o,h)}\n${i}]\n${i}rows: ${t.rows}\n${i}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:i=Math.random}=r;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(s>=o)throw new RangeError("min must be smaller than max");let n=o-s,h=new E(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(i()*n);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let s=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<s;t++)o.set(t,t,r);return o}static diag(t,e,r){let s=t.length;void 0===e&&(e=s),void 0===r&&(r=e);let o=Math.min(s,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new E(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new this(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return 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 i=r+1;i<t.columns;i++)t.set(s,i,t.get(s,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,s=r-1;for(;s>=0;)if(0===t.maxRow(s))s--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(s,o)?i=!0:o++;for(let r=0;r<s;r++){let i=t.get(r,o);for(let n=o;n<e;n++){let e=t.get(r,n)-i*t.get(s,n);t.set(r,n,e)}}s--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let s=new 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),i=new Float64Array(r);for(let n=0;n<s;n++){for(let e=0;e<r;e++)i[e]=t.get(e,n);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*i[s];o.set(t,n,e)}}return o}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),i=t.get(0,1),n=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=(n+a)*s,f=r*(i-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+(n-r)*(s+i);return e.set(0,0,w),e.set(0,1,p),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=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),i=this.get(1,0),n=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-i)*(-f+w),x=(-r+i+n)*(c-f+w),S=(i+n)*(-c+f),v=r*c,A=(-r+a+l)*(c-m+p),z=(-r+a)*(m-p),N=(a+l)*(-c+m),R=(-o+l+u)*(w+d-y),k=(o-u)*(w-y),F=o*d,I=(l+u)*(-d+y),T=(-o+n+h)*(p+d-b),C=(o-h)*(p-b),W=(n+h)*(-d+b),D=v+F+s*g,V=(r+s+o-i-n-l-u)*w+x+S+v+R+F+I,q=v+A+N+(r+s+o-n-h-a-l)*p+F+T+W,L=M+n*(-c+f+g-w-p-d+b)+x+v+F+T+C,O=M+x+S+v+h*y,_=F+T+C+W+i*m,P=v+A+z+l*(-c+m+g-w-p-d+y)+R+k+F,j=R+k+F+I+a*f,$=v+A+z+N+u*b;return e.set(0,0,D),e.set(0,1,V),e.set(0,2,q),e.set(1,0,L),e.set(1,1,O),e.set(1,2,_),e.set(2,0,P),e.set(2,1,j),e.set(2,2,$),e}mmulStrassen(t){t=E.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,o=t.rows,i=t.columns;function n(t,e,r){let s=t.rows,o=t.columns;if(s===e&&o===r)return t;{let s=M.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==o&&console.warn(`Multiplying ${r} x ${s} and ${o} x ${i} matrix: dimensions do not match.`);let h=Math.max(r,o),a=Math.max(s,i);return e=n(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=n(e,s+1,o+1),r=n(r,s+1,o+1)):s%2==1?(e=n(e,s+1,o),r=n(r,s+1,o)):o%2==1&&(e=n(e,s,o+1),r=n(r,s,o+1));let i=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,i-1,0,h-1),l=r.subMatrix(0,i-1,0,h-1),u=e.subMatrix(0,i-1,h,e.columns-1),c=r.subMatrix(0,i-1,h,r.columns-1),f=e.subMatrix(i,e.rows-1,0,h-1),m=r.subMatrix(i,r.rows-1,0,h-1),g=e.subMatrix(i,e.rows-1,h,e.columns-1),w=r.subMatrix(i,r.rows-1,h,r.columns-1),p=t(M.add(a,g),M.add(l,w),i,h),d=t(M.add(f,g),l,i,h),y=t(a,M.sub(c,w),i,h),b=t(g,M.sub(m,l),i,h),x=t(M.add(a,u),w,i,h),S=t(M.sub(f,a),M.add(l,c),i,h),E=t(M.sub(u,g),M.add(m,w),i,h),v=M.add(p,b);v.sub(x),v.add(E);let A=M.add(y,x),z=M.add(d,b),N=M.sub(p,d);N.add(y),N.add(S);let R=M.zeros(2*v.rows,2*v.columns);return R=R.setSubMatrix(v,0,0),R=R.setSubMatrix(A,v.rows,0),R=R.setSubMatrix(z,0,v.columns),R=R.setSubMatrix(N,v.rows,v.columns),R.subMatrix(0,s-1,0,o-1)}(e,t=n(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 i=this.getRow(t);i.length>0&&o(i,{min:e,max:r,output:i}),s.setRow(t,i)}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 i=this.getColumn(t);i.length&&o(i,{min:e,max:r,output:i}),s.setColumn(t,i)}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,i=new E(e*s,r*o);for(let n=0;n<e;n++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<o;h++)i.set(s*n+r,o*e+h,this.get(n,e)*t.get(r,h));return i}kroneckerSum(t){if(t=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 i=t;i<=e;i++)for(let e=r;e<=s;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let s=new E(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);s.set(o,i-e,this.get(t[o],i))}return s}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let s=new E(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);s.set(i-e,o,this.get(i,t[o]))}return s}setSubMatrix(t,e,r){if((t=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 i=e[t];r.set(s,t,this.get(o,i))}}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,i=[];for(let n=0;n<s;n++){let s=0,h=0,a=0;for(let e=0;e<o;e++)a=t.get(n,e)-r[n],s+=a,h+=a*a;e?i.push((h-s*s/o)/(o-1)):i.push((h-s*s/o)/o)}return i}(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,i=[];for(let n=0;n<o;n++){let o=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(e,n)-r[n],o+=a,h+=a*a;e?i.push((h-o*o/s)/(s-1)):i.push((h-o*o/s)/s)}return i}(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,i=s*o;let n=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,n+=a,h+=a*a;return e?(h-n*n/i)/(i-1):(h-n*n/i)/i}(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,i=0,n=0;n<e;n++)s.set(o,i,t[n]),++o>=r&&(o=++i);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,i=0,n=0;n<e;n++)s.set(o,i,t[n]),++o>=r&&(o=1+ ++i);return s}}A.prototype.klassSubType="DistanceMatrix";class z extends M{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class N extends z{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 R 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 k 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 F{constructor(t){let e,r,s,o,i,n,h,a,l,u=(t=k.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),i=0,s=0;s<l;s++)i+=u.get(e,s)*a[s];a[e]-=i,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++)n=u.get(o,s),u.set(o,s,u.get(r,s)),u.set(r,s,n);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,i=t.columns,n=t.subMatrixRow(this.pivotVector,0,i-1),h=e.columns;for(o=0;o<h;o++)for(r=o+1;r<h;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o));for(o=h-1;o>=0;o--){for(s=0;s<i;s++)n.set(o,s,n.get(o,s)/e.get(o,o));for(r=0;r<o;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o))}return n}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let s=0;s<r;s++)e*=t.get(s,s);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new 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 I(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class T{constructor(t){let e,r,s,o,i=(t=k.checkMatrix(t)).clone(),n=t.rows,h=t.columns,a=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<n;e++)t=I(t,i.get(e,s));if(0!==t){for(i.get(s,s)<0&&(t=-t),e=s;e<n;e++)i.set(e,s,i.get(e,s)/t);for(i.set(s,s,i.get(s,s)+1),r=s+1;r<h;r++){for(o=0,e=s;e<n;e++)o+=i.get(e,s)*i.get(e,r);for(o=-o/i.get(s,s),e=s;e<n;e++)i.set(e,r,i.get(e,r)+o*i.get(e,s))}}a[s]=-t}this.QR=i,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,i,n,h=t.columns,a=t.clone(),l=e.columns;for(i=0;i<l;i++)for(o=0;o<h;o++){for(n=0,s=i;s<r;s++)n+=e.get(s,i)*a.get(s,o);for(n=-n/e.get(i,i),s=i;s<r;s++)a.set(s,o,a.get(s,o)+n*e.get(s,i))}for(i=l-1;i>=0;i--){for(o=0;o<h;o++)a.set(i,o,a.get(i,o)/this.Rdiag[i]);for(s=0;s<i;s++)for(o=0;o<h;o++)a.set(s,o,a.get(s,o)-a.get(i,o)*e.get(s,i))}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,i=o.rows,n=o.columns,h=new E(i,n);for(r=n-1;r>=0;r--){for(t=0;t<i;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<n;e++)if(0!==o.get(r,r)){for(s=0,t=r;t<i;t++)s+=o.get(t,r)*h.get(t,e);for(s=-s/o.get(r,r),t=r;t<i;t++)h.set(t,e,h.get(t,e)+s*o.get(t,r))}}return h}}class C{constructor(t,e={}){if((t=k.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:n=!1}=e;let h,a=Boolean(o),l=Boolean(i),u=!1;if(r<s)if(n){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]=I(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]=I(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=I(m[r],e),i=m[r]/o,n=e/o;if(m[r]=o,r!==t&&(e=-n*p[r-1],p[r-1]=i*p[r-1]),l)for(let t=0;t<s;t++)o=i*w.get(t,r)+n*w.get(t,S-1),w.set(t,S-1,-n*w.get(t,r)+i*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=I(m[s],e),i=m[s]/o,n=e/o;if(m[s]=o,e=-n*p[s],p[s]=i*p[s],a)for(let e=0;e<r;e++)o=i*g.get(e,s)+n*g.get(e,t-1),g.set(e,t-1,-n*g.get(e,s)+i*g.get(e,t-1)),g.set(e,s,o)}break}case 3:{const e=Math.max(Math.abs(m[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,i=m[S-2]/e,n=p[S-2]/e,h=m[t]/e,u=p[t]/e,c=((i+o)*(i-o)+n*n)/2,f=o*n*(o*n);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=I(y,b);0===o&&(o=Number.MIN_VALUE);let i=y/o,n=b/o;if(e!==t&&(p[e-1]=o),y=i*m[e]+n*p[e],p[e]=i*p[e]-n*m[e],b=n*m[e+1],m[e+1]=i*m[e+1],l)for(let t=0;t<s;t++)o=i*w.get(t,e)+n*w.get(t,e+1),w.set(t,e+1,-n*w.get(t,e)+i*w.get(t,e+1)),w.set(t,e,o);if(o=I(y,b),0===o&&(o=Number.MIN_VALUE),i=y/o,n=b/o,m[e]=o,y=i*p[e]+n*m[e+1],m[e+1]=-n*p[e]+i*m[e+1],b=n*p[e+1],p[e+1]=i*p[e+1],a&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+n*g.get(t,e+1),g.set(t,e+1,-n*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}p[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 i=this.U,n=this.rightSingularVectors,h=n.mmul(o),a=n.rows,l=i.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)*i.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 i=0;i<r;i++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,n=i.rows,h=i.columns,a=new E(r,n);for(let t=0;t<r;t++)for(let e=0;e<n;e++){let r=0;for(let s=0;s<h;s++)r+=o.get(t,s)*i.get(e,s);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 W(t,e,r=!1){return t=k.checkMatrix(t),e=k.checkMatrix(e),r?new C(t).solve(e):t.isSquare()?new F(t).solve(e):new T(t).solve(e)}function D(t,e){let r=[];for(let s=0;s<t;s++)s!==e&&r.push(s);return r}function V(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 q{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=k.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let s,o,i=t.columns,n=new E(i,i),h=new Float64Array(i),a=new Float64Array(i),l=t,u=!1;if(u=!!r||t.isSymmetric(),u){for(s=0;s<i;s++)for(o=0;o<i;o++)n.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,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,n=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,n+=r[l]*r[l];for(o=r[h-1],i=Math.sqrt(n),o>0&&(i=-i),e[h]=c*i,n-=o*i,r[h-1]=o-i,a=0;a<h;a++)e[a]=0;for(a=0;a<h;a++){for(o=r[a],s.set(a,h,o),i=e[a]+s.get(a,a)*o,l=a+1;l<=h-1;l++)i+=s.get(l,a)*r[l],e[l]+=s.get(l,a)*o;e[a]=i}for(o=0,a=0;a<h;a++)e[a]/=n,o+=e[a]*r[a];for(u=o/(n+n),a=0;a<h;a++)e[a]-=u*r[a];for(a=0;a<h;a++){for(o=r[a],i=e[a],l=a;l<=h-1;l++)s.set(l,a,s.get(l,a)-(o*e[l]+i*r[l]));r[a]=s.get(h-1,a),s.set(h,a,0)}}r[h]=n}for(h=0;h<t-1;h++){if(s.set(t-1,h,s.get(h,h)),s.set(h,h,1),n=r[h+1],0!==n){for(l=0;l<=h;l++)r[l]=s.get(l,h+1)/n;for(a=0;a<=h;a++){for(i=0,l=0;l<=h;l++)i+=s.get(l,h+1)*s.get(l,a);for(l=0;l<=h;l++)s.set(l,a,s.get(l,a)-i*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}(i,a,h,n),function(t,e,r,s){let o,i,n,h,a,l,u,c,f,m,g,w,p,d,y,b;for(n=1;n<t;n++)e[n-1]=e[n];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=I(c,1),c<0&&(f=-f),r[l]=e[l]/(c+f),r[l+1]=e[l]*(c+f),m=r[l+1],i=o-r[l],n=l+2;n<t;n++)r[n]-=i;for(M+=i,c=r[u],g=1,w=g,p=g,d=e[l+1],y=0,b=0,n=u-1;n>=l;n--)for(p=w,w=g,b=y,o=g*e[n],i=g*c,f=I(c,e[n]),e[n+1]=y*f,y=e[n]/f,g=c/f,c=g*r[n]-y*o,r[n+1]=i+y*(g*o+y*r[n]),a=0;a<t;a++)i=s.get(a,n+1),s.set(a,n+1,y*s.get(a,n)+g*i),s.set(a,n,g*s.get(a,n)-y*i);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(n=0;n<t-1;n++){for(a=n,c=r[n],h=n+1;h<t;h++)r[h]<c&&(a=h,c=r[h]);if(a!==n)for(r[a]=r[n],r[n]=c,h=0;h<t;h++)c=s.get(h,n),s.set(h,n,s.get(h,a)),s.set(h,a,c)}}(i,a,h,n)}else{let t=new E(i,i),e=new Float64Array(i);for(o=0;o<i;o++)for(s=0;s<i;s++)t.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,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(n=0,h=c;h>=l;h--)r[h]=e.get(h,l-1)/u,n+=r[h]*r[h];for(i=Math.sqrt(n),r[l]>0&&(i=-i),n-=r[l]*i,r[l]=r[l]-i,a=l;a<t;a++){for(o=0,h=c;h>=l;h--)o+=r[h]*e.get(h,a);for(o/=n,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/=n,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*i)}}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(i=0,h=l;h<=c;h++)i+=r[h]*s.get(h,a);for(i=i/r[l]/e.get(l,l-1),h=l;h<=c;h++)s.set(h,a,s.get(h,a)+i*r[h])}}}(i,t,e,n),function(t,e,r,s,o){let i,n,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,z=0,N=0,R=0,k=0,F=0;for(i=0;i<t;i++)for((i<0||i>x)&&(r[i]=o.get(i,i),e[i]=0),n=Math.max(i-1,0);n<t;n++)v+=Math.abs(o.get(i,n));for(;M>=0;){for(a=M;a>0&&(R=Math.abs(o.get(a-1,a-1))+Math.abs(o.get(a,a)),0===R&&(R=v),!(Math.abs(o.get(a,a-1))<S*R));)a--;if(a===M)o.set(M,M,o.get(M,M)+E),r[M]=o.get(M,M),e[M]=0,M--,F=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,z=A*A+c,k=Math.sqrt(Math.abs(z)),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),z>=0){for(k=A>=0?A+k:A-k,r[M-1]=f+k,r[M]=r[M-1],0!==k&&(r[M]=f-c/k),e[M-1]=0,e[M]=0,f=o.get(M,M-1),R=Math.abs(f)+Math.abs(k),A=f/R,z=k/R,N=Math.sqrt(A*A+z*z),A/=N,z/=N,n=M-1;n<t;n++)k=o.get(M-1,n),o.set(M-1,n,z*k+A*o.get(M,n)),o.set(M,n,z*o.get(M,n)-A*k);for(i=0;i<=M;i++)k=o.get(i,M-1),o.set(i,M-1,z*k+A*o.get(i,M)),o.set(i,M,z*o.get(i,M)-A*k);for(i=0;i<=x;i++)k=s.get(i,M-1),s.set(i,M-1,z*k+A*s.get(i,M)),s.set(i,M,z*s.get(i,M)-A*k)}else r[M-1]=f+A,r[M]=f+A,e[M-1]=k,e[M]=-k;M-=2,F=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===F){for(E+=f,i=0;i<=M;i++)o.set(i,i,o.get(i,i)-f);R=Math.abs(o.get(M,M-1))+Math.abs(o.get(M-1,M-2)),f=m=.75*R,c=-.4375*R*R}if(30===F&&(R=(m-f)/2,R=R*R+c,R>0)){for(R=Math.sqrt(R),m<f&&(R=-R),R=f-c/((m-f)/2+R),i=0;i<=M;i++)o.set(i,i,o.get(i,i)-R);E+=R,f=m=c=.964}for(F+=1,l=M-2;l>=a&&(k=o.get(l,l),N=f-k,R=m-k,A=(N*R-c)/o.get(l+1,l)+o.get(l,l+1),z=o.get(l+1,l+1)-k-N-R,N=o.get(l+2,l+1),R=Math.abs(A)+Math.abs(z)+Math.abs(N),A/=R,z/=R,N/=R,l!==a)&&!(Math.abs(o.get(l,l-1))*(Math.abs(z)+Math.abs(N))<S*(Math.abs(A)*(Math.abs(o.get(l-1,l-1))+Math.abs(k)+Math.abs(o.get(l+1,l+1)))));)l--;for(i=l+2;i<=M;i++)o.set(i,i-2,0),i>l+2&&o.set(i,i-3,0);for(h=l;h<=M-1&&(y=h!==M-1,h!==l&&(A=o.get(h,h-1),z=o.get(h+1,h-1),N=y?o.get(h+2,h-1):0,f=Math.abs(A)+Math.abs(z)+Math.abs(N),0!==f&&(A/=f,z/=f,N/=f)),0!==f);h++)if(R=Math.sqrt(A*A+z*z+N*N),A<0&&(R=-R),0!==R){for(h!==l?o.set(h,h-1,-R*f):a!==l&&o.set(h,h-1,-o.get(h,h-1)),A+=R,f=A/R,m=z/R,k=N/R,z/=A,N/=A,n=h;n<t;n++)A=o.get(h,n)+z*o.get(h+1,n),y&&(A+=N*o.get(h+2,n),o.set(h+2,n,o.get(h+2,n)-A*k)),o.set(h,n,o.get(h,n)-A*f),o.set(h+1,n,o.get(h+1,n)-A*m);for(i=0;i<=Math.min(M,h+3);i++)A=f*o.get(i,h)+m*o.get(i,h+1),y&&(A+=k*o.get(i,h+2),o.set(i,h+2,o.get(i,h+2)-A*N)),o.set(i,h,o.get(i,h)-A),o.set(i,h+1,o.get(i,h+1)-A*z);for(i=0;i<=x;i++)A=f*s.get(i,h)+m*s.get(i,h+1),y&&(A+=k*s.get(i,h+2),s.set(i,h+2,s.get(i,h+2)-A*N)),s.set(i,h,s.get(i,h)-A),s.set(i,h+1,s.get(i,h+1)-A*z)}}}if(0!==v){for(M=t-1;M>=0;M--)if(A=r[M],z=e[M],0===z)for(a=M,o.set(M,M,1),i=M-1;i>=0;i--){for(c=o.get(i,i)-A,N=0,n=a;n<=M;n++)N+=o.get(i,n)*o.get(n,M);if(e[i]<0)k=c,R=N;else if(a=i,0===e[i]?o.set(i,M,0!==c?-N/c:-N/(S*v)):(f=o.get(i,i+1),m=o.get(i+1,i),z=(r[i]-A)*(r[i]-A)+e[i]*e[i],u=(f*R-k*N)/z,o.set(i,M,u),o.set(i+1,M,Math.abs(f)>Math.abs(k)?(-N-c*u)/f:(-R-m*u)/k)),u=Math.abs(o.get(i,M)),S*u*u>1)for(n=i;n<=M;n++)o.set(n,M,o.get(n,M)/u)}else if(z<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,z/o.get(M,M-1)),o.set(M-1,M,-(o.get(M,M)-A)/o.get(M,M-1))):(b=L(0,-o.get(M-1,M),o.get(M-1,M-1)-A,z),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),i=M-2;i>=0;i--){for(g=0,w=0,n=a;n<=M;n++)g+=o.get(i,n)*o.get(n,M-1),w+=o.get(i,n)*o.get(n,M);if(c=o.get(i,i)-A,e[i]<0)k=c,N=g,R=w;else if(a=i,0===e[i]?(b=L(-g,-w,c,z),o.set(i,M-1,b[0]),o.set(i,M,b[1])):(f=o.get(i,i+1),m=o.get(i+1,i),p=(r[i]-A)*(r[i]-A)+e[i]*e[i]-z*z,d=2*(r[i]-A)*z,0===p&&0===d&&(p=S*v*(Math.abs(c)+Math.abs(z)+Math.abs(f)+Math.abs(m)+Math.abs(k))),b=L(f*N-k*g+z*w,f*R-k*w-z*g,p,d),o.set(i,M-1,b[0]),o.set(i,M,b[1]),Math.abs(f)>Math.abs(k)+Math.abs(z)?(o.set(i+1,M-1,(-g-c*o.get(i,M-1)+z*o.get(i,M))/f),o.set(i+1,M,(-w-c*o.get(i,M)-z*o.get(i,M-1))/f)):(b=L(-N-m*o.get(i,M-1),-R-m*o.get(i,M),k,z),o.set(i+1,M-1,b[0]),o.set(i+1,M,b[1]))),u=Math.max(Math.abs(o.get(i,M-1)),Math.abs(o.get(i,M))),S*u*u>1)for(n=i;n<=M;n++)o.set(n,M-1,o.get(n,M-1)/u),o.set(n,M,o.get(n,M)/u)}for(i=0;i<t;i++)if(i<0||i>x)for(n=i;n<t;n++)s.set(i,n,o.get(i,n));for(n=t-1;n>=0;n--)for(i=0;i<=x;i++){for(k=0,h=0;h<=Math.min(n,x);h++)k+=s.get(i,h)*o.get(h,n);s.set(i,n,k)}}}(i,a,h,n,t)}this.n=i,this.e=a,this.d=h,this.V=n}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,s=this.e,o=this.d,i=new E(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)i.set(t,e,0);i.set(t,t,o[t]),s[t]>0?i.set(t,t+1,s[t]):s[t]<0&&i.set(t,t-1,s[t])}return i}}function L(t,e,r,s){let o,i;return Math.abs(r)>Math.abs(s)?(o=s/r,i=r+o*s,[(t+o*e)/i,(e-o*t)/i]):(o=r/s,i=s+o*r,[(o*t+e)/i,(o*e-t)/i])}class O{constructor(t){if(!(t=k.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,s,o=t,i=o.rows,n=new E(i,i),h=!0;for(r=0;r<i;r++){let t=0;for(s=0;s<r;s++){let i=0;for(e=0;e<s;e++)i+=n.get(s,e)*n.get(r,e);i=(o.get(r,s)-i)/n.get(s,s),n.set(r,s,i),t+=i*i}for(t=o.get(r,r)-t,h&&=t>0,n.set(r,r,Math.sqrt(Math.max(t,0))),s=r+1;s<i;s++)n.set(r,s,0)}this.L=n,this.positiveDefinite=h}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=k.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(!1===this.isPositiveDefinite())throw new Error("Matrix is not positive definite");let s,o,i,n=t.columns,h=t.clone();for(i=0;i<r;i++)for(o=0;o<n;o++){for(s=0;s<i;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(i,s));h.set(i,o,h.get(i,o)/e.get(i,i))}for(i=r-1;i>=0;i--)for(o=0;o<n;o++){for(s=i+1;s<r;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(s,i));h.set(i,o,h.get(i,o)/e.get(i,i))}return h}get lowerTriangularMatrix(){return this.L}}class _{constructor(t,e={}){t=k.checkMatrix(t);let{Y:r}=e;const{scaleScores:o=!1,maxIterations:i=1e3,terminationCriteria:n=1e-10}=e;let h;if(r){if(r=s.isAnyArray(r)&&"number"==typeof r[0]?E.columnVector(r):k.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<i&&f>n;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)),i=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=i,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=q,e.hj=q,e.LU=F,e.Tb=F,e.uq=E,e.Zm=class extends z{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 z{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 z{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 z{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 z{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 z{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=N,e.zg=class extends z{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 z{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=_,e.ks=_,e.QR=T,e.jp=T,e.mk=C,e.W2=C,e.l=v,e.KY=R,e.dv=k,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:i=!0,scale:n=!0}=r;i&&(t.center("column"),o||e.center("column")),n&&(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:i=!0}=r;i&&(t=t.center("column"),o||(e=e.center("column")));const n=t.transpose().mmul(e);for(let e=0;e<n.rows;e++)for(let r=0;r<n.columns;r++)n.set(e,r,n.get(e,r)*(1/(t.rows-1)));return n},e.a4=function t(e){if((e=E.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,s,o,i;if(2===e.columns)return r=e.get(0,0),s=e.get(0,1),o=e.get(1,0),i=e.get(1,1),r*i-s*o;if(3===e.columns){let i,n,h;return i=new N(e,[1,2],[1,2]),n=new N(e,[1,2],[0,2]),h=new N(e,[1,2],[0,1]),r=e.get(0,0),s=e.get(0,1),o=e.get(0,2),r*t(i)-s*t(n)+o*t(h)}return new F(e).determinant}throw Error("determinant can only be calculated for a square matrix")},e.DI=function(t,e=!1){return t=k.checkMatrix(t),e?new C(t).inverse():W(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,i=new E(o,o);for(let e=0;e<o;e++){let n=E.columnVector(t.getRow(e)),h=t.subMatrixRow(D(o,e)).transpose(),a=new C(h).solve(n),l=E.sub(n,h.mmul(a)).abs().max();i.setRow(e,V(l,a,e,r,s))}return i},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,i=r.diagonal;for(let t=0;t<i.length;t++)Math.abs(i[t])>e?i[t]=1/i[t]:i[t]=0;return o.mmul(E.diag(i).mmul(s.transpose()))},e.kH=W,e.LV=function(t,e){if(s.isAnyArray(t))return t[0]&&s.isAnyArray(t[0])?new k(t):new R(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,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<n;a++)t[a]<h&&(h=t[a]);return h}(t),i=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,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<n;a++)t[a]>h&&(h=t[a]);return h}(t);if(o===i)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,h=void 0===n?r.autoMinMax?o:0:n,a=r.max,l=void 0===a?r.autoMinMax?i:1:a;if(h>=l)throw new RangeError("min option must be smaller than max option");for(var u=(l-h)/(i-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 i=e[s]={exports:{}};return t[s](i,i.exports,r),i.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 i(t){return o(t).map((t,e)=>e)}function n(t,e){return o(t).map(()=>e)}function h(t){return n(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 i=0;i<e;i++){let e=!0;for(;e;){const n=t(r,s);let h=!1;for(let t=0;t<i;t++)if(n===o[t]){h=!0;break}h||(e=!1),o[i]=n}}return o}function c(t,e,r){const s=[];let o=0,i=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let n=0;n<e;n++){const e=[];for(let s=0;s<r;s++)e.push(t[i]),i+=1;s.push(e),o+=1}return s}function f(t,e){const r=r=>o(t).map(()=>n(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 i=0;i<e;i++){let e=!0,n=0;for(;e;){n=t(r,s);let h=!1;for(let t=0;t<i;t++)if(n===o[t]){h=!0;break}h||(e=!1)}o[i]=n}return o}function g(t,e,r,s,o){e=Math.floor(e);const i=t[0][e],n=t[1][e];if(t[2][e],r>=n[0])return 0;for(let t=0;t<i.length;t++)if(s===i[t])return 0;return w(t,e,r,s,o)}function w(t,e,r,s,o){const i=t[0][e],n=t[1][e],h=t[2][e];if(r>=n[0])return 0;n[0]=r,i[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(!(n[e]>r))break;l=e}else if(n[e]>=n[s]){if(!(r<n[e]))break;l=e}else{if(!(r<n[s]))break;l=s}n[a]=n[l],i[a]=i[l],h[a]=h[l],a=l}return n[a]=r,i[a]=s,h[a]=o,1}function p(t,r,s,o,i){const n=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(i);g(n,o,a,s,h),g(n,s,a,o,h),t[2][o][r]=0}return n}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,i=s[0];s[0]=s[e],s[e]=i;const n=o[0];o[0]=o[r],o[r]=n,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,i=o+1;let n=s;if(t[n]<t[o]&&(n=o),i<r&&t[n]<t[i]&&(n=i),n===s)break;{const r=t[s];t[s]=t[n],t[n]=r;const o=e[s];e[s]=e[n],e[n]=o,s=n}}}function b(t,e){const r=t[0][e],s=t[1][e],o=t[2][e];let i=1/0,n=-1;for(let t=0;t>r.length;t++)1===o[t]&&s[t]<i&&(i=s[t],n=t);return n>=0?(o[n]=0,Math.floor(r[n])):-1}r.r(s),r.d(s,{UMAP:()=>lt,initWasm:()=>W,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],i=e[s];this.checkDims(o,i);const n=this.makeKey(o,i);this.entries.set(n,{value:r[s],row:o,col:i})}}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,i)=>{e.push(o),r.push(i),s.push(t)});const o=[t.nCols,t.nRows];return new M(r,e,s,o)}function S(t,e){return k(t,e,(t,e)=>t*e)}function E(t,e){return k(t,e,(t,e)=>t+e)}function v(t,e){return k(t,e,(t,e)=>t-e)}function A(t,e){return t.map(t=>t*e)}function z(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 i=(t,r)=>!e.has(r),n=r.filter(i),h=s.filter(i),a=o.filter(i);return new M(h,a,n,t.getDims())}function N(t,e="l2"){const r=R[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 i=s.get(e).sort(),n=r(i.map(r=>t.get(e,r)));for(let t=0;t<n.length;t++)o.set(e,i[t],n[t])}return o}const R={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 k(t,e,r){const s=new Set,o=[],i=[],n=[],h=(s,h)=>{o.push(s),i.push(h);const a=r(t.get(s,h),e.get(s,h));n.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,i,n,g)}function F(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 i=-1;for(let t=0;t<e.length;t++){const{row:n,col:h,value:a}=e[t];n!==i&&(i=n,o.push(t)),r.push(h),s.push(a)}return{indices:r,values:s,indptr:o}}let I=null,T=null,C=null;async function W(){return I||(I=(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&&(C=await t.default()),T=t,t}catch(t){throw I=null,T=null,C=null,new Error(`Failed to load WASM module: ${t}`)}})(),I)}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");return T.build_rp_tree(t,e,r,s,BigInt(o))}function L(t,e,r,s,o){if(!T)throw new Error("WASM module not initialized");const i=new Int32Array(t),n=new Int32Array(e),h=new Float64Array(r);return new T.WasmSparseMatrix(i,n,h,s,o)}function O(t){if(!T)throw new Error("WASM module not initialized");return T.sparse_transpose(t)}function _(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_add(t,e)}function P(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_subtract(t,e)}function j(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 U(t){const e=t.get_all_ordered(),r=Math.floor(e.length/3),s=new Int32Array(r),o=new Int32Array(r),i=new Float64Array(r);let n=0;for(let t=0;t<e.length;t+=3)s[n]=e[t],o[n]=e[t+1],i[n]=e[t+2],n+=1;return{rows:s,cols:o,values:i}}function B(t,e,r,s,o,i,n,h=10,a=50,l=.001,u=.5,c=!0,f="euclidean",m=42){if(!T)throw new Error("WASM module not initialized");return T.nn_descent(t,e,r,s,o,i,n,h,a,l,u,c,f,BigInt(m))}class K{constructor(t,e,r,s){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=s}static fromWasm(t){const e=new K([],new Float64Array(0),[],[]),r=t.children();let s=-1;for(let t=0;t<r.length;t++){const e=r[t];if(e<=0){const t=-e;t>s&&(s=t)}}const o=s+1,i=t.indices(),n=o>0?Math.floor(i.length/o):0;e.hyperplanesFlat=t.hyperplanes(),e.offsetsFlat=t.offsets(),e.childrenFlat=r,e.indicesFlat=i,e.dim=t.dim(),e.nNodes=t.n_nodes(),e.nLeaves=o,e.leafSize=n;const h=new Array(e.nNodes);for(let t=0;t<e.nNodes;t++){const r=t*e.dim;h[t]=e.hyperplanesFlat.subarray(r,r+e.dim)}const a=new Array(e.nNodes);for(let t=0;t<e.nNodes;t++){const r=2*t;a[t]=e.childrenFlat.subarray(r,r+2)}const l=new Array(e.nLeaves);for(let t=0;t<e.nLeaves;t++){const r=t*e.leafSize;l[t]=e.indicesFlat.subarray(r,r+e.leafSize)}return e.hyperplanes=h,e.offsets=e.offsetsFlat,e.children=a,e.indices=l,e.wasmTree=t,e}getWasmTree(){return this.wasmTree}getFlatHyperplanes(){return this.hyperplanesFlat}getFlatOffsets(){return this.offsetsFlat}getFlatChildren(){return this.childrenFlat}getFlatLeafMeta(){if(this.indicesFlat&&void 0!==this.nLeaves&&void 0!==this.leafSize)return{indices:this.indicesFlat,nLeaves:this.nLeaves,leafSize:this.leafSize}}getDim(){return this.dim}dispose(){this.wasmTree&&(this.wasmTree.free(),this.wasmTree=void 0)}}function G(t,e,r,s,o=!1){const n=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,i=t[0].length,n=[],h=new Float64Array(o*i);for(let e=0;e<o;e++)for(let r=0;r<i;r++)h[e*i+r]=t[e][r];for(let t=0;t<r;t++){const t=q(h,o,i,e,Math.floor(4294967295*s()));n.push(K.fromWasm(t))}return n}(t,n,r,s)}const a=i(r).map((e,r)=>function(t,e=30,r,s){return Q(t,i(t.length),e,r,s)}(t,n,r,s)),l=a.map(t=>function(t,e){const r=X(t),s=H(t),o=i(r).map(()=>h(t.hyperplane?t.hyperplane.length:0)),n=h(r),a=i(r).map(()=>[-1,-1]),l=i(s).map(()=>i(e).map(()=>-1));return Y(t,o,n,a,l,0,0),new K(o,n,a,l)}(t,n));return l}function Q(e,r,s=30,o,i){if(r.length>s){const n=function(e,r,s){const o=e[0].length;let i=t(r.length,s),n=t(r.length,s);n+=i===n?1:0,n%=r.length;const a=r[i],l=r[n];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 i=0;i<r.length;i++){let n=u;for(let t=0;t<o;t++)n+=c[t]*e[r[i]][t];0===n?(g[i]=t(2,s),0===g[i]?f+=1:m+=1):n>0?(g[i]=0,f+=1):(g[i]=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,i),{indicesLeft:a,indicesRight:l,hyperplane:u,offset:c}=n;return{leftChild:Q(e,a,s,o+1,i),rightChild:Q(e,l,s,o+1,i),isLeaf:!1,hyperplane:u,offset:c}}return{indices:r,isLeaf:!0}}function Y(t,e,r,s,o,i,n){if(t.isLeaf)return s[i][0]=-n,o[n].splice(0,t.indices.length,...t.indices),{nodeNum:i,leafNum:n+=1};{e[i]=t.hyperplane,r[i]=t.offset,s[i][0]=i+1;const h=i;let a=Y(t.leftChild,e,r,s,o,i+1,n);return i=a.nodeNum,n=a.leafNum,s[h][1]=i+1,a=Y(t.rightChild,e,r,s,o,i+1,n),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function X(t){return t.isLeaf?1:1+X(t.leftChild)+X(t.rightChild)}function H(t){return t.isLeaf?1:H(t.leftChild)+H(t.rightChild)}function J(e,r,s,o){let i=r;for(let t=0;t<s.length;t++)i+=e[t]*s[t];return 0===i?t(2,o):i>0?0:1}function Z(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()));const o=e.getFlatChildren(),i=e.getFlatHyperplanes(),n=e.getFlatOffsets(),h=e.getDim(),a=e.getFlatLeafMeta();if(o&&i&&n&&void 0!==h&&a){let e=0;for(;o[2*e]>0;){const s=n[e],a=e*h;e=0===J(i.subarray(a,a+h),s,t,r)?o[2*e]:o[2*e+1]}const s=-o[2*e],{indices:l,leafSize:u}=a,c=s*u,f=new Array(u);for(let t=0;t<u;t++)f[t]=l[c+t];return f}let l=0;for(;e.children[l][0]>0;)l=0===J(e.hyperplanes[l],e.offsets[l],t,r)?e.children[l][0]:e.children[l][1];const u=-1*e.children[l][0];return e.indices[u]}const tt=Object.prototype.toString;function et(t){return tt.call(t).endsWith("Array]")}function rt(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 st=r(673);st.y3,st.jy,st.oN,st.Hc,st.cg,st.hj,st.LU,st.Tb;const ot=st.uq,it=(st.Zm,st.Dq,st.__,st.q0,st.lh,st.pI,st.zC,st.zg,st.g6,st.OL,st.ks,st.QR,st.jp,st.mk,st.W2,st.l,st.KY,st.dv,st.BR,st.Wu,st.uq,st.uq,st.a4,st.DI);function nt(t,e,r,s,o){let i=r*s*s,n=ot.eye(e.length,e.length,i);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 i=r.length,n=t.x.length;let h=new Array(i);for(let a=0;a<i;a++){h[a]=new Array(n);let i=r.slice();i[a]+=s;let l=o(i);for(let r=0;r<n;r++)h[a][r]=e[r]-l(t.x[r])}return new ot(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 ot(s)}(t,a),c=it(n.add(l.mmul(l.transpose())));return(e=(e=new ot([e])).sub(c.mmul(l).mmul(u).mul(s).transpose())).to1DArray()}st.Jo,st.Zi,st.kH,st.LV;const ht=1e-5,at=.001;class lt{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=ut,this.useWasmDistance=!1,this.useWasmNNDescent=!1,this.useWasmMatrix=!1,this.useWasmOptimizer=!1,this.useWasmTree=!1,this.wasmBatchSize=10,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new ct,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("wasmBatchSize"),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,i){for(let n=0;n<r.length;n++){const h=u(t,e.length,i);for(let t=0;t<h.length;t++)h[t]<0||g(o,n,s(e[h[t]],r[n]),h[t],1)}},initFromTree:function(t,e,r,o,i){for(let n=0;n<r.length;n++){const h=Z(r[n],t,i);for(let t=0;t<h.length;t++){if(h[t]<0)return;g(o,n,s(e[h[t]],r[n]),h[t],1)}}}});var s;this.initFromTree=e,this.initFromRandom=r,this.search=function(t){return function(e,r,s,o){const{indices:i,indptr:n}=F(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=i.slice(n[a],n[a+1]);for(const i of l)i===a||-1===i||h.has(i)||(w(s,r,t(e[i],o[r]),i,1),h.add(i))}}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],i=r[t];for(let e=0;e<s.length;e++){const r=s[e],n=i[e];n>0&&o.set(t,r,n)}}return k(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,i,n){const h=f(r.length,s);if(o(s,e,r,h,n),t)for(let s of t)i(s,e,r,h,n);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),o=this.search(e,this.searchGraph,s,t);let{indices:i,weights:n}=d(o);i=i.map(t=>t.slice(0,this.nNeighbors)),n=n.map(t=>t.slice(0,this.nNeighbors));const a=Math.max(0,this.localConnectivity-1),{sigmas:l,rhos:u}=this.smoothKNNDistance(n,this.nNeighbors,a),{rows:m,cols:g,vals:w}=this.computeMembershipStrengths(i,n,l,u),p=[t.length,e.length];let y=new M(m,g,w,p);const b=F(N(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 i=0;i<t[0].length;i++)for(let n=0;n<r[0].length;n++){const h=t[o][i];s[o][n]+=e[o][i]*r[h][n]}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=z(y);const A=this.makeEpochsPerSample(y.getValues(),E),R=y.getRows(),k=y.getCols();return this.assignOptimizationStateParameters({headEmbedding:S,tailEmbedding:this.embedding,head:R,tail:k,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.useWasmOptimizer&&this.wasmOptimizerState?this.materializeEmbeddingFromWasm():this.embedding}nearestNeighbors(t){const{distanceFn:r,nNeighbors:s}=this,o=function(t,r,s=!1){return function(o,i,n,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="cosine"===t.name?"cosine":"euclidean",s=Math.floor(4294967295*r()),f=o.length,m=o[0].length,g=new Float64Array(f*m);for(let t=0;t<f;t++)for(let e=0;e<m;e++)g[t*m+e]=o[t][e];const w=i.length,p=w>0?i[0].length:0,d=new Int32Array(w*p);for(let t=0;t<w;t++)for(let e=0;e<p;e++)d[t*p+e]=i[t][e];const y=B(g,f,m,d,w,p,n,h,a,l,u,c,e,s),b=[],M=[],x=f*n;for(let t=0;t<f;t++){const e=[],r=[];for(let s=0;s<n;s++)e.push(y[t*n+s]),r.push(y[x+t*n+s]);b.push(e),M.push(r)}return{indices:b,weights:M}}const w=o.length,y=f(o.length,n);for(let e=0;e<o.length;e++){const s=m(n,o.length,r);for(let r=0;r<s.length;r++){const i=t(o[e],o[s[r]]);g(y,e,i,s[r],1),g(y,s[r],i,e,1)}}if(c)for(let e=0;e<i.length;e++)for(let r=0;r<i[e].length&&!(i[e][r]<0);r++)for(let s=r+1;s<i[e].length&&!(i[e][s]<0);s++){const n=t(o[i[e][r]],o[i[e][s]]);g(y,i[e][r],n,i[e][s],1),g(y,i[e][s],n,i[e][r],1)}for(let s=0;s<h;s++){const s=p(y,w,n,a,r);let i=0;for(let n=0;n<w;n++)for(let h=0;h<a;h++){let l=Math.floor(s[0][n][h]);if(!(l<0||e(r)<u))for(let e=0;e<a;e++){const r=Math.floor(s[0][n][e]),a=s[2][n][h],u=s[2][n][e];if(r<0||!a&&!u)continue;const c=t(o[l],o[r]);i+=g(y,l,c,r,1),i+=g(y,r,c,l,1)}}if(i<=l*n*o.length)break}return d(y)}}(r,this.random,this.useWasmNNDescent),i=5+Math.floor(.5==(n=t.length**.5/20)?0:Math.round(n));var n;const h=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));if(this.rpForest=G(t,s,i,this.random,this.useWasmTree),this.useWasmNNDescent&&D()){const e=t.length,o=t[0].length,i=new Float64Array(e*o);for(let r=0;r<e;r++)for(let e=0;e<o;e++)i[r*o+e]=t[r][e];const{flatLeafArray:n,nLeaves:a,leafSize:l}=function(t){if(0===t.length)return{flatLeafArray:new Int32Array([-1]),nLeaves:1,leafSize:1};let e=-1,r=0;for(const s of t){const t=s.getFlatLeafMeta();t?(-1===e&&(e=t.leafSize),r+=t.nLeaves):(-1===e&&(e=s.indices[0]?.length??0),r+=s.indices.length)}const s=new Int32Array(r*e);let o=0;for(const r of t){const t=r.getFlatLeafMeta();if(t)s.set(t.indices,o),o+=t.indices.length;else{for(let t=0;t<r.indices.length;t++){const i=r.indices[t];for(let r=0;r<e;r++)s[o+t*e+r]=i[r]}o+=r.indices.length*e}}return{flatLeafArray:s,nLeaves:r,leafSize:e}}(this.rpForest),u=B(i,e,o,n,a,l,s,h,50,.001,.5,!0,"cosine"===r.name?"cosine":"euclidean",Math.floor(4294967295*this.random())),c=[],f=[],m=e*s;for(let t=0;t<e;t++){const e=[],r=[];for(let o=0;o<s;o++)e.push(u[t*s+o]),r.push(u[m+t*s+o]);c.push(e),f.push(r)}return{knnIndices:c,knnDistances:f}}const a=function(t){if(t.length>0){const e=[];for(let r of t){if(r.indices.length>0){e.push(...r.indices);continue}const t=r.getFlatLeafMeta();if(!t)continue;const{indices:s,nLeaves:o,leafSize:i}=t;for(let t=0;t<o;t++){const r=t*i,o=new Array(i);for(let t=0;t<i;t++)o[t]=s[r+t];e.push(o)}}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:i}=this,{sigmas:n,rhos:h}=this.smoothKNNDistance(o,e,i),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(s,o,n,h),c=[t.length,t.length];if(this.useWasmMatrix&&D()){const t=L(a,l,u,c[0],c[1]),e=O(t),s=j(t,e),o=_(t,e),i=_($(P(o,s),r),$(s,1-r)),{rows:n,cols:h,values:f}=U(i);return new M(n,h,f,c)}if(this.useWasmMatrix&&D()){const t=L(a,l,u,c[0],c[1]),e=O(t),s=j(t,e),o=_(t,e),i=_($(P(o,s),r),$(s,1-r)),{rows:n,cols:h,values:f}=U(i);return new M(n,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,i)=>-1===e[o]||-1===e[i]?t*Math.exp(-r):e[o]!==e[i]?t*Math.exp(-s):t)}(t,e,s,r);return o=z(o),function(t){const e=x(t=N(t,"max"));return z(t=E(t,v(e,S(e,t))))}(o)}smoothKNNDistance(t,e,r=1,s=64,o=1){const i=Math.log(e)/Math.log(2)*o,n=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?(n[e]=m[t-1],s>ht&&(n[e]+=s*(m[t]-m[t-1]))):n[e]=s*m[0]}else m.length>0&&(n[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]-n[e];r+=o>0?Math.exp(-o/c):1}if(Math.abs(r-i)<ht)break;r>i?(h=c,c=(o+h)/2):(o=c,h===1/0?c*=2:c=(o+h)/2)}if(u[e]=c,n[e]>0){const t=a(f);u[e]<at*t&&(u[e]=at*t)}else{const r=a(t.map(a));u[e]<at*r&&(u[e]=at*r)}}return{sigmas:u,rhos:n}}computeMembershipStrengths(t,e,r,s){const o=t.length,i=t[0].length,n=h(o*i),a=h(o*i),l=h(o*i);for(let h=0;h<o;h++)for(let o=0;o<i;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]),n[h*i+o]=h,a[h*i+o]=t[h][o],l[h*i+o]=u)}return{rows:n,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 i=this.graph.map(e=>e<o/t?0:e);this.embedding=h(i.nRows).map(()=>h(r).map(()=>20*e(this.random)-10));const n=[],a=[],l=[],u=i.getAll();for(let t=0;t<u.length;t++){const e=u[t];e.value&&(n.push(e.value),l.push(e.row),a.push(e.col))}return{head:a,tail:l,epochsPerSample:this.makeEpochsPerSample(n,t)}}makeEpochsPerSample(t,e){const r=n(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:i}=this.optimizationState,n=o[0].length,h=o.length===i.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:n}),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,i,n,h,a,l,u,c,f,m){if(!T)throw new Error("WASM module not initialized");const g=new Float32Array(r.length*c),w=new Float32Array(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 Float32Array(o),b=new Float32Array(i);return new T.OptimizerState(p,d,g,w,y,b,n,h,a,l,u,c,f,m)}(r,l,o,i,s,a,h,e,t,f,m,n,u,c),this.rngState=BigInt(Math.floor(4294967295*this.random())),this.wasmOptimizerState.set_rng_seed(this.rngState)}}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:s,epochsPerSample:i}=this.optimizationState,n=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),i={x:r,y:s},{parameterValues:n}=function(t,e,r={}){let{maxIterations:s=100,gradientDifference:o=.1,damping:i=0,errorTolerance:n=.01,minValues:h,maxValues:a,initialValues:l}=r;if(i<=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(!et(t.x)||t.x.length<2||!et(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(!et(u))throw new Error("initialValues must be an array");let f,m=rt(t,u,e),g=m<=n;for(f=0;f<s&&!g;f++){u=nt(t,u,i,o,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(m=rt(t,u,e),isNaN(m))break;g=m<=n}return{parameterValues:u,parameterError:m,iterations:f}}(i,([t,e])=>r=>1/(1+t*r**(2*e)),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[a,l]=n;return{a,b:l}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:s,epochsPerSample:i,a:l,b:u,nEpochs:n,nVertices:a})}optimizeLayoutStep(e){if(this.useWasmOptimizer&&this.wasmOptimizerState)return function(t){if(!T)throw new Error("WASM module not initialized");T.optimize_layout_step_in_place(t)}(this.wasmOptimizerState),this.optimizationState.currentEpoch+=1,this.materializeEmbeddingFromWasm();const{optimizationState:r}=this,{head:s,tail:o,headEmbedding:i,tailEmbedding:n,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=i[f],x=n[y],S=mt(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=ft(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=n[e],s=mt(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=ft(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,i}optimizeLayoutAsync(t=()=>!0){return new Promise((e,r)=>{const s=async()=>{try{if(this.useWasmOptimizer&&this.wasmOptimizerState){const{nEpochs:r,currentEpoch:o}=this.optimizationState;if(o>=r)return this.embedding=this.materializeEmbeddingFromWasm(),e(!0);const i=Math.max(1,this.wasmBatchSize),n=Math.min(i,r-o),h=o,a=this.optimizeLayoutBatchWasm(n);let l=!1;for(let e=h+1;e<=h+a;e++)if(!1===t(e)){l=!0;break}const u=this.optimizationState.currentEpoch===r;return l||u?(this.embedding=this.materializeEmbeddingFromWasm(),e(u)):void setTimeout(()=>s(),0)}const{nEpochs:r,currentEpoch:o}=this.optimizationState;this.embedding=this.optimizeLayoutStep(o);const i=this.optimizationState.currentEpoch,n=!1===t(i),h=i===r;if(n||h)return e(h);setTimeout(()=>s(),0)}catch(t){r(t)}};setTimeout(()=>s(),0)})}optimizeLayout(t=()=>!0){let e=!1,r=[];if(this.useWasmOptimizer&&this.wasmOptimizerState){for(;!e;){const{nEpochs:r,currentEpoch:s}=this.optimizationState,o=Math.max(1,this.wasmBatchSize),i=Math.min(o,r-s),n=s,h=this.optimizeLayoutBatchWasm(i);let a=!1;for(let e=n+1;e<=n+h;e++)if(!1===t(e)){a=!0;break}e=this.optimizationState.currentEpoch===r||a}return r=this.materializeEmbeddingFromWasm(),r}for(;!e;){const{nEpochs:s,currentEpoch:o}=this.optimizationState;r=this.optimizeLayoutStep(o);const i=this.optimizationState.currentEpoch,n=!1===t(i);e=i===s||n}return r}optimizeLayoutBatchWasm(t){if(!this.wasmOptimizerState)throw new Error("WASM optimizer state is not initialized.");const e=this.optimizationState.nEpochs-this.optimizationState.currentEpoch,r=Math.min(t,e);return r<=0?0:(function(t,e){if(!T)throw new Error("WASM module not initialized");T.optimize_layout_batch_in_place(t,e)}(this.wasmOptimizerState,r),this.optimizationState.currentEpoch+=r,r)}materializeEmbeddingFromWasm(){if(!this.wasmOptimizerState)return this.embedding;const{dim:t,nVertices:e}=this.optimizationState,r=function(t){if(!T)throw new Error("WASM module not initialized");const e=t.head_embedding_ptr(),r=t.head_embedding_len(),s=C?.memory??T?.memory??T?.__wasm?.memory;if(!s?.buffer)throw new Error("WASM memory is not available");return new Float32Array(s.buffer,e,r)}(this.wasmOptimizerState),s=new Array(e);for(let o=0;o<e;o++){const e=new Array(t),i=o*t;for(let s=0;s<t;s++)e[s]=r[i+s];s[o]=e}return this.embedding=s,s}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 ut(t,e){let r=0;for(let s=0;s<t.length;s++)r+=(t[s]-e[s])**2;return Math.sqrt(r)}class ct{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 ft(t,e){return t>e?e:t<-e?-e:t}function mt(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 i=" ".repeat(2),n=" ".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${i}[\n${n}${function(t,e,r,s,o){const{rows:i,columns:h}=t,l=Math.min(i,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 i=0;i<u;i++)r.push(a(t.get(e,i),s,o));c.push(`${r.join(" ")}`)}return u!==h&&(c[c.length-1]+=` ... ${h-r} more columns`),l!==i&&c.push(`... ${i-e} more rows`),c.join(`\n${n}`)}(t,r,s,o,h)}\n${i}]\n${i}rows: ${t.rows}\n${i}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:i=Math.random}=r;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(s>=o)throw new RangeError("min must be smaller than max");let n=o-s,h=new E(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(i()*n);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let s=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<s;t++)o.set(t,t,r);return o}static diag(t,e,r){let s=t.length;void 0===e&&(e=s),void 0===r&&(r=e);let o=Math.min(s,e,r),i=this.zeros(e,r);for(let e=0;e<o;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new E(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.min(t.get(i,r),e.get(i,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,o=new this(r,s);for(let i=0;i<r;i++)for(let r=0;r<s;r++)o.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return o}static checkMatrix(t){return 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 i=r+1;i<t.columns;i++)t.set(s,i,t.get(s,i)-t.get(e,i)*o)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,s=r-1;for(;s>=0;)if(0===t.maxRow(s))s--;else{let o=0,i=!1;for(;o<r&&!1===i;)1===t.get(s,o)?i=!0:o++;for(let r=0;r<s;r++){let i=t.get(r,o);for(let n=o;n<e;n++){let e=t.get(r,n)-i*t.get(s,n);t.set(r,n,e)}}s--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let s=new 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),i=new Float64Array(r);for(let n=0;n<s;n++){for(let e=0;e<r;e++)i[e]=t.get(e,n);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*i[s];o.set(t,n,e)}}return o}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),i=t.get(0,1),n=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=(n+a)*s,f=r*(i-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+(n-r)*(s+i);return e.set(0,0,w),e.set(0,1,p),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=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),i=this.get(1,0),n=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-i)*(-f+w),x=(-r+i+n)*(c-f+w),S=(i+n)*(-c+f),v=r*c,A=(-r+a+l)*(c-m+p),z=(-r+a)*(m-p),N=(a+l)*(-c+m),R=(-o+l+u)*(w+d-y),k=(o-u)*(w-y),F=o*d,I=(l+u)*(-d+y),T=(-o+n+h)*(p+d-b),C=(o-h)*(p-b),W=(n+h)*(-d+b),D=v+F+s*g,V=(r+s+o-i-n-l-u)*w+x+S+v+R+F+I,q=v+A+N+(r+s+o-n-h-a-l)*p+F+T+W,L=M+n*(-c+f+g-w-p-d+b)+x+v+F+T+C,O=M+x+S+v+h*y,_=F+T+C+W+i*m,P=v+A+z+l*(-c+m+g-w-p-d+y)+R+k+F,j=R+k+F+I+a*f,$=v+A+z+N+u*b;return e.set(0,0,D),e.set(0,1,V),e.set(0,2,q),e.set(1,0,L),e.set(1,1,O),e.set(1,2,_),e.set(2,0,P),e.set(2,1,j),e.set(2,2,$),e}mmulStrassen(t){t=E.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,o=t.rows,i=t.columns;function n(t,e,r){let s=t.rows,o=t.columns;if(s===e&&o===r)return t;{let s=M.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==o&&console.warn(`Multiplying ${r} x ${s} and ${o} x ${i} matrix: dimensions do not match.`);let h=Math.max(r,o),a=Math.max(s,i);return e=n(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=n(e,s+1,o+1),r=n(r,s+1,o+1)):s%2==1?(e=n(e,s+1,o),r=n(r,s+1,o)):o%2==1&&(e=n(e,s,o+1),r=n(r,s,o+1));let i=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,i-1,0,h-1),l=r.subMatrix(0,i-1,0,h-1),u=e.subMatrix(0,i-1,h,e.columns-1),c=r.subMatrix(0,i-1,h,r.columns-1),f=e.subMatrix(i,e.rows-1,0,h-1),m=r.subMatrix(i,r.rows-1,0,h-1),g=e.subMatrix(i,e.rows-1,h,e.columns-1),w=r.subMatrix(i,r.rows-1,h,r.columns-1),p=t(M.add(a,g),M.add(l,w),i,h),d=t(M.add(f,g),l,i,h),y=t(a,M.sub(c,w),i,h),b=t(g,M.sub(m,l),i,h),x=t(M.add(a,u),w,i,h),S=t(M.sub(f,a),M.add(l,c),i,h),E=t(M.sub(u,g),M.add(m,w),i,h),v=M.add(p,b);v.sub(x),v.add(E);let A=M.add(y,x),z=M.add(d,b),N=M.sub(p,d);N.add(y),N.add(S);let R=M.zeros(2*v.rows,2*v.columns);return R=R.setSubMatrix(v,0,0),R=R.setSubMatrix(A,v.rows,0),R=R.setSubMatrix(z,0,v.columns),R=R.setSubMatrix(N,v.rows,v.columns),R.subMatrix(0,s-1,0,o-1)}(e,t=n(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 i=this.getRow(t);i.length>0&&o(i,{min:e,max:r,output:i}),s.setRow(t,i)}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 i=this.getColumn(t);i.length&&o(i,{min:e,max:r,output:i}),s.setColumn(t,i)}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,i=new E(e*s,r*o);for(let n=0;n<e;n++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<o;h++)i.set(s*n+r,o*e+h,this.get(n,e)*t.get(r,h));return i}kroneckerSum(t){if(t=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 i=t;i<=e;i++)for(let e=r;e<=s;e++)o.set(i-t,e-r,this.get(i,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let s=new E(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);s.set(o,i-e,this.get(t[o],i))}return s}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let s=new E(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let i=e;i<=r;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);s.set(i-e,o,this.get(i,t[o]))}return s}setSubMatrix(t,e,r){if((t=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 i=e[t];r.set(s,t,this.get(o,i))}}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,i=[];for(let n=0;n<s;n++){let s=0,h=0,a=0;for(let e=0;e<o;e++)a=t.get(n,e)-r[n],s+=a,h+=a*a;e?i.push((h-s*s/o)/(o-1)):i.push((h-s*s/o)/o)}return i}(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,i=[];for(let n=0;n<o;n++){let o=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(e,n)-r[n],o+=a,h+=a*a;e?i.push((h-o*o/s)/(s-1)):i.push((h-o*o/s)/s)}return i}(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,i=s*o;let n=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,n+=a,h+=a*a;return e?(h-n*n/i)/(i-1):(h-n*n/i)/i}(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,i=0,n=0;n<e;n++)s.set(o,i,t[n]),++o>=r&&(o=++i);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,i=0,n=0;n<e;n++)s.set(o,i,t[n]),++o>=r&&(o=1+ ++i);return s}}A.prototype.klassSubType="DistanceMatrix";class z extends M{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class N extends z{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 R 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 k 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 F{constructor(t){let e,r,s,o,i,n,h,a,l,u=(t=k.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),i=0,s=0;s<l;s++)i+=u.get(e,s)*a[s];a[e]-=i,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++)n=u.get(o,s),u.set(o,s,u.get(r,s)),u.set(r,s,n);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,i=t.columns,n=t.subMatrixRow(this.pivotVector,0,i-1),h=e.columns;for(o=0;o<h;o++)for(r=o+1;r<h;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o));for(o=h-1;o>=0;o--){for(s=0;s<i;s++)n.set(o,s,n.get(o,s)/e.get(o,o));for(r=0;r<o;r++)for(s=0;s<i;s++)n.set(r,s,n.get(r,s)-n.get(o,s)*e.get(r,o))}return n}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let s=0;s<r;s++)e*=t.get(s,s);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new 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 I(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class T{constructor(t){let e,r,s,o,i=(t=k.checkMatrix(t)).clone(),n=t.rows,h=t.columns,a=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<n;e++)t=I(t,i.get(e,s));if(0!==t){for(i.get(s,s)<0&&(t=-t),e=s;e<n;e++)i.set(e,s,i.get(e,s)/t);for(i.set(s,s,i.get(s,s)+1),r=s+1;r<h;r++){for(o=0,e=s;e<n;e++)o+=i.get(e,s)*i.get(e,r);for(o=-o/i.get(s,s),e=s;e<n;e++)i.set(e,r,i.get(e,r)+o*i.get(e,s))}}a[s]=-t}this.QR=i,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,i,n,h=t.columns,a=t.clone(),l=e.columns;for(i=0;i<l;i++)for(o=0;o<h;o++){for(n=0,s=i;s<r;s++)n+=e.get(s,i)*a.get(s,o);for(n=-n/e.get(i,i),s=i;s<r;s++)a.set(s,o,a.get(s,o)+n*e.get(s,i))}for(i=l-1;i>=0;i--){for(o=0;o<h;o++)a.set(i,o,a.get(i,o)/this.Rdiag[i]);for(s=0;s<i;s++)for(o=0;o<h;o++)a.set(s,o,a.get(s,o)-a.get(i,o)*e.get(s,i))}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,i=o.rows,n=o.columns,h=new E(i,n);for(r=n-1;r>=0;r--){for(t=0;t<i;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<n;e++)if(0!==o.get(r,r)){for(s=0,t=r;t<i;t++)s+=o.get(t,r)*h.get(t,e);for(s=-s/o.get(r,r),t=r;t<i;t++)h.set(t,e,h.get(t,e)+s*o.get(t,r))}}return h}}class C{constructor(t,e={}){if((t=k.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:i=!0,autoTranspose:n=!1}=e;let h,a=Boolean(o),l=Boolean(i),u=!1;if(r<s)if(n){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]=I(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]=I(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=I(m[r],e),i=m[r]/o,n=e/o;if(m[r]=o,r!==t&&(e=-n*p[r-1],p[r-1]=i*p[r-1]),l)for(let t=0;t<s;t++)o=i*w.get(t,r)+n*w.get(t,S-1),w.set(t,S-1,-n*w.get(t,r)+i*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=I(m[s],e),i=m[s]/o,n=e/o;if(m[s]=o,e=-n*p[s],p[s]=i*p[s],a)for(let e=0;e<r;e++)o=i*g.get(e,s)+n*g.get(e,t-1),g.set(e,t-1,-n*g.get(e,s)+i*g.get(e,t-1)),g.set(e,s,o)}break}case 3:{const e=Math.max(Math.abs(m[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,i=m[S-2]/e,n=p[S-2]/e,h=m[t]/e,u=p[t]/e,c=((i+o)*(i-o)+n*n)/2,f=o*n*(o*n);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=I(y,b);0===o&&(o=Number.MIN_VALUE);let i=y/o,n=b/o;if(e!==t&&(p[e-1]=o),y=i*m[e]+n*p[e],p[e]=i*p[e]-n*m[e],b=n*m[e+1],m[e+1]=i*m[e+1],l)for(let t=0;t<s;t++)o=i*w.get(t,e)+n*w.get(t,e+1),w.set(t,e+1,-n*w.get(t,e)+i*w.get(t,e+1)),w.set(t,e,o);if(o=I(y,b),0===o&&(o=Number.MIN_VALUE),i=y/o,n=b/o,m[e]=o,y=i*p[e]+n*m[e+1],m[e+1]=-n*p[e]+i*m[e+1],b=n*p[e+1],p[e+1]=i*p[e+1],a&&e<r-1)for(let t=0;t<r;t++)o=i*g.get(t,e)+n*g.get(t,e+1),g.set(t,e+1,-n*g.get(t,e)+i*g.get(t,e+1)),g.set(t,e,o)}p[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 i=this.U,n=this.rightSingularVectors,h=n.mmul(o),a=n.rows,l=i.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)*i.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 i=0;i<r;i++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&o.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,n=i.rows,h=i.columns,a=new E(r,n);for(let t=0;t<r;t++)for(let e=0;e<n;e++){let r=0;for(let s=0;s<h;s++)r+=o.get(t,s)*i.get(e,s);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 W(t,e,r=!1){return t=k.checkMatrix(t),e=k.checkMatrix(e),r?new C(t).solve(e):t.isSquare()?new F(t).solve(e):new T(t).solve(e)}function D(t,e){let r=[];for(let s=0;s<t;s++)s!==e&&r.push(s);return r}function V(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 q{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=k.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let s,o,i=t.columns,n=new E(i,i),h=new Float64Array(i),a=new Float64Array(i),l=t,u=!1;if(u=!!r||t.isSymmetric(),u){for(s=0;s<i;s++)for(o=0;o<i;o++)n.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,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,n=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,n+=r[l]*r[l];for(o=r[h-1],i=Math.sqrt(n),o>0&&(i=-i),e[h]=c*i,n-=o*i,r[h-1]=o-i,a=0;a<h;a++)e[a]=0;for(a=0;a<h;a++){for(o=r[a],s.set(a,h,o),i=e[a]+s.get(a,a)*o,l=a+1;l<=h-1;l++)i+=s.get(l,a)*r[l],e[l]+=s.get(l,a)*o;e[a]=i}for(o=0,a=0;a<h;a++)e[a]/=n,o+=e[a]*r[a];for(u=o/(n+n),a=0;a<h;a++)e[a]-=u*r[a];for(a=0;a<h;a++){for(o=r[a],i=e[a],l=a;l<=h-1;l++)s.set(l,a,s.get(l,a)-(o*e[l]+i*r[l]));r[a]=s.get(h-1,a),s.set(h,a,0)}}r[h]=n}for(h=0;h<t-1;h++){if(s.set(t-1,h,s.get(h,h)),s.set(h,h,1),n=r[h+1],0!==n){for(l=0;l<=h;l++)r[l]=s.get(l,h+1)/n;for(a=0;a<=h;a++){for(i=0,l=0;l<=h;l++)i+=s.get(l,h+1)*s.get(l,a);for(l=0;l<=h;l++)s.set(l,a,s.get(l,a)-i*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}(i,a,h,n),function(t,e,r,s){let o,i,n,h,a,l,u,c,f,m,g,w,p,d,y,b;for(n=1;n<t;n++)e[n-1]=e[n];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=I(c,1),c<0&&(f=-f),r[l]=e[l]/(c+f),r[l+1]=e[l]*(c+f),m=r[l+1],i=o-r[l],n=l+2;n<t;n++)r[n]-=i;for(M+=i,c=r[u],g=1,w=g,p=g,d=e[l+1],y=0,b=0,n=u-1;n>=l;n--)for(p=w,w=g,b=y,o=g*e[n],i=g*c,f=I(c,e[n]),e[n+1]=y*f,y=e[n]/f,g=c/f,c=g*r[n]-y*o,r[n+1]=i+y*(g*o+y*r[n]),a=0;a<t;a++)i=s.get(a,n+1),s.set(a,n+1,y*s.get(a,n)+g*i),s.set(a,n,g*s.get(a,n)-y*i);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(n=0;n<t-1;n++){for(a=n,c=r[n],h=n+1;h<t;h++)r[h]<c&&(a=h,c=r[h]);if(a!==n)for(r[a]=r[n],r[n]=c,h=0;h<t;h++)c=s.get(h,n),s.set(h,n,s.get(h,a)),s.set(h,a,c)}}(i,a,h,n)}else{let t=new E(i,i),e=new Float64Array(i);for(o=0;o<i;o++)for(s=0;s<i;s++)t.set(s,o,l.get(s,o));!function(t,e,r,s){let o,i,n,h,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(n=0,h=c;h>=l;h--)r[h]=e.get(h,l-1)/u,n+=r[h]*r[h];for(i=Math.sqrt(n),r[l]>0&&(i=-i),n-=r[l]*i,r[l]=r[l]-i,a=l;a<t;a++){for(o=0,h=c;h>=l;h--)o+=r[h]*e.get(h,a);for(o/=n,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/=n,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*i)}}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(i=0,h=l;h<=c;h++)i+=r[h]*s.get(h,a);for(i=i/r[l]/e.get(l,l-1),h=l;h<=c;h++)s.set(h,a,s.get(h,a)+i*r[h])}}}(i,t,e,n),function(t,e,r,s,o){let i,n,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,z=0,N=0,R=0,k=0,F=0;for(i=0;i<t;i++)for((i<0||i>x)&&(r[i]=o.get(i,i),e[i]=0),n=Math.max(i-1,0);n<t;n++)v+=Math.abs(o.get(i,n));for(;M>=0;){for(a=M;a>0&&(R=Math.abs(o.get(a-1,a-1))+Math.abs(o.get(a,a)),0===R&&(R=v),!(Math.abs(o.get(a,a-1))<S*R));)a--;if(a===M)o.set(M,M,o.get(M,M)+E),r[M]=o.get(M,M),e[M]=0,M--,F=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,z=A*A+c,k=Math.sqrt(Math.abs(z)),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),z>=0){for(k=A>=0?A+k:A-k,r[M-1]=f+k,r[M]=r[M-1],0!==k&&(r[M]=f-c/k),e[M-1]=0,e[M]=0,f=o.get(M,M-1),R=Math.abs(f)+Math.abs(k),A=f/R,z=k/R,N=Math.sqrt(A*A+z*z),A/=N,z/=N,n=M-1;n<t;n++)k=o.get(M-1,n),o.set(M-1,n,z*k+A*o.get(M,n)),o.set(M,n,z*o.get(M,n)-A*k);for(i=0;i<=M;i++)k=o.get(i,M-1),o.set(i,M-1,z*k+A*o.get(i,M)),o.set(i,M,z*o.get(i,M)-A*k);for(i=0;i<=x;i++)k=s.get(i,M-1),s.set(i,M-1,z*k+A*s.get(i,M)),s.set(i,M,z*s.get(i,M)-A*k)}else r[M-1]=f+A,r[M]=f+A,e[M-1]=k,e[M]=-k;M-=2,F=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===F){for(E+=f,i=0;i<=M;i++)o.set(i,i,o.get(i,i)-f);R=Math.abs(o.get(M,M-1))+Math.abs(o.get(M-1,M-2)),f=m=.75*R,c=-.4375*R*R}if(30===F&&(R=(m-f)/2,R=R*R+c,R>0)){for(R=Math.sqrt(R),m<f&&(R=-R),R=f-c/((m-f)/2+R),i=0;i<=M;i++)o.set(i,i,o.get(i,i)-R);E+=R,f=m=c=.964}for(F+=1,l=M-2;l>=a&&(k=o.get(l,l),N=f-k,R=m-k,A=(N*R-c)/o.get(l+1,l)+o.get(l,l+1),z=o.get(l+1,l+1)-k-N-R,N=o.get(l+2,l+1),R=Math.abs(A)+Math.abs(z)+Math.abs(N),A/=R,z/=R,N/=R,l!==a)&&!(Math.abs(o.get(l,l-1))*(Math.abs(z)+Math.abs(N))<S*(Math.abs(A)*(Math.abs(o.get(l-1,l-1))+Math.abs(k)+Math.abs(o.get(l+1,l+1)))));)l--;for(i=l+2;i<=M;i++)o.set(i,i-2,0),i>l+2&&o.set(i,i-3,0);for(h=l;h<=M-1&&(y=h!==M-1,h!==l&&(A=o.get(h,h-1),z=o.get(h+1,h-1),N=y?o.get(h+2,h-1):0,f=Math.abs(A)+Math.abs(z)+Math.abs(N),0!==f&&(A/=f,z/=f,N/=f)),0!==f);h++)if(R=Math.sqrt(A*A+z*z+N*N),A<0&&(R=-R),0!==R){for(h!==l?o.set(h,h-1,-R*f):a!==l&&o.set(h,h-1,-o.get(h,h-1)),A+=R,f=A/R,m=z/R,k=N/R,z/=A,N/=A,n=h;n<t;n++)A=o.get(h,n)+z*o.get(h+1,n),y&&(A+=N*o.get(h+2,n),o.set(h+2,n,o.get(h+2,n)-A*k)),o.set(h,n,o.get(h,n)-A*f),o.set(h+1,n,o.get(h+1,n)-A*m);for(i=0;i<=Math.min(M,h+3);i++)A=f*o.get(i,h)+m*o.get(i,h+1),y&&(A+=k*o.get(i,h+2),o.set(i,h+2,o.get(i,h+2)-A*N)),o.set(i,h,o.get(i,h)-A),o.set(i,h+1,o.get(i,h+1)-A*z);for(i=0;i<=x;i++)A=f*s.get(i,h)+m*s.get(i,h+1),y&&(A+=k*s.get(i,h+2),s.set(i,h+2,s.get(i,h+2)-A*N)),s.set(i,h,s.get(i,h)-A),s.set(i,h+1,s.get(i,h+1)-A*z)}}}if(0!==v){for(M=t-1;M>=0;M--)if(A=r[M],z=e[M],0===z)for(a=M,o.set(M,M,1),i=M-1;i>=0;i--){for(c=o.get(i,i)-A,N=0,n=a;n<=M;n++)N+=o.get(i,n)*o.get(n,M);if(e[i]<0)k=c,R=N;else if(a=i,0===e[i]?o.set(i,M,0!==c?-N/c:-N/(S*v)):(f=o.get(i,i+1),m=o.get(i+1,i),z=(r[i]-A)*(r[i]-A)+e[i]*e[i],u=(f*R-k*N)/z,o.set(i,M,u),o.set(i+1,M,Math.abs(f)>Math.abs(k)?(-N-c*u)/f:(-R-m*u)/k)),u=Math.abs(o.get(i,M)),S*u*u>1)for(n=i;n<=M;n++)o.set(n,M,o.get(n,M)/u)}else if(z<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,z/o.get(M,M-1)),o.set(M-1,M,-(o.get(M,M)-A)/o.get(M,M-1))):(b=L(0,-o.get(M-1,M),o.get(M-1,M-1)-A,z),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),i=M-2;i>=0;i--){for(g=0,w=0,n=a;n<=M;n++)g+=o.get(i,n)*o.get(n,M-1),w+=o.get(i,n)*o.get(n,M);if(c=o.get(i,i)-A,e[i]<0)k=c,N=g,R=w;else if(a=i,0===e[i]?(b=L(-g,-w,c,z),o.set(i,M-1,b[0]),o.set(i,M,b[1])):(f=o.get(i,i+1),m=o.get(i+1,i),p=(r[i]-A)*(r[i]-A)+e[i]*e[i]-z*z,d=2*(r[i]-A)*z,0===p&&0===d&&(p=S*v*(Math.abs(c)+Math.abs(z)+Math.abs(f)+Math.abs(m)+Math.abs(k))),b=L(f*N-k*g+z*w,f*R-k*w-z*g,p,d),o.set(i,M-1,b[0]),o.set(i,M,b[1]),Math.abs(f)>Math.abs(k)+Math.abs(z)?(o.set(i+1,M-1,(-g-c*o.get(i,M-1)+z*o.get(i,M))/f),o.set(i+1,M,(-w-c*o.get(i,M)-z*o.get(i,M-1))/f)):(b=L(-N-m*o.get(i,M-1),-R-m*o.get(i,M),k,z),o.set(i+1,M-1,b[0]),o.set(i+1,M,b[1]))),u=Math.max(Math.abs(o.get(i,M-1)),Math.abs(o.get(i,M))),S*u*u>1)for(n=i;n<=M;n++)o.set(n,M-1,o.get(n,M-1)/u),o.set(n,M,o.get(n,M)/u)}for(i=0;i<t;i++)if(i<0||i>x)for(n=i;n<t;n++)s.set(i,n,o.get(i,n));for(n=t-1;n>=0;n--)for(i=0;i<=x;i++){for(k=0,h=0;h<=Math.min(n,x);h++)k+=s.get(i,h)*o.get(h,n);s.set(i,n,k)}}}(i,a,h,n,t)}this.n=i,this.e=a,this.d=h,this.V=n}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,s=this.e,o=this.d,i=new E(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)i.set(t,e,0);i.set(t,t,o[t]),s[t]>0?i.set(t,t+1,s[t]):s[t]<0&&i.set(t,t-1,s[t])}return i}}function L(t,e,r,s){let o,i;return Math.abs(r)>Math.abs(s)?(o=s/r,i=r+o*s,[(t+o*e)/i,(e-o*t)/i]):(o=r/s,i=s+o*r,[(o*t+e)/i,(o*e-t)/i])}class O{constructor(t){if(!(t=k.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,s,o=t,i=o.rows,n=new E(i,i),h=!0;for(r=0;r<i;r++){let t=0;for(s=0;s<r;s++){let i=0;for(e=0;e<s;e++)i+=n.get(s,e)*n.get(r,e);i=(o.get(r,s)-i)/n.get(s,s),n.set(r,s,i),t+=i*i}for(t=o.get(r,r)-t,h&&=t>0,n.set(r,r,Math.sqrt(Math.max(t,0))),s=r+1;s<i;s++)n.set(r,s,0)}this.L=n,this.positiveDefinite=h}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=k.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(!1===this.isPositiveDefinite())throw new Error("Matrix is not positive definite");let s,o,i,n=t.columns,h=t.clone();for(i=0;i<r;i++)for(o=0;o<n;o++){for(s=0;s<i;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(i,s));h.set(i,o,h.get(i,o)/e.get(i,i))}for(i=r-1;i>=0;i--)for(o=0;o<n;o++){for(s=i+1;s<r;s++)h.set(i,o,h.get(i,o)-h.get(s,o)*e.get(s,i));h.set(i,o,h.get(i,o)/e.get(i,i))}return h}get lowerTriangularMatrix(){return this.L}}class _{constructor(t,e={}){t=k.checkMatrix(t);let{Y:r}=e;const{scaleScores:o=!1,maxIterations:i=1e3,terminationCriteria:n=1e-10}=e;let h;if(r){if(r=s.isAnyArray(r)&&"number"==typeof r[0]?E.columnVector(r):k.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<i&&f>n;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)),i=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=i,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=q,e.hj=q,e.LU=F,e.Tb=F,e.uq=E,e.Zm=class extends z{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 z{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 z{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 z{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 z{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 z{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=N,e.zg=class extends z{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 z{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=_,e.ks=_,e.QR=T,e.jp=T,e.mk=C,e.W2=C,e.l=v,e.KY=R,e.dv=k,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:i=!0,scale:n=!0}=r;i&&(t.center("column"),o||e.center("column")),n&&(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:i=!0}=r;i&&(t=t.center("column"),o||(e=e.center("column")));const n=t.transpose().mmul(e);for(let e=0;e<n.rows;e++)for(let r=0;r<n.columns;r++)n.set(e,r,n.get(e,r)*(1/(t.rows-1)));return n},e.a4=function t(e){if((e=E.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,s,o,i;if(2===e.columns)return r=e.get(0,0),s=e.get(0,1),o=e.get(1,0),i=e.get(1,1),r*i-s*o;if(3===e.columns){let i,n,h;return i=new N(e,[1,2],[1,2]),n=new N(e,[1,2],[0,2]),h=new N(e,[1,2],[0,1]),r=e.get(0,0),s=e.get(0,1),o=e.get(0,2),r*t(i)-s*t(n)+o*t(h)}return new F(e).determinant}throw Error("determinant can only be calculated for a square matrix")},e.DI=function(t,e=!1){return t=k.checkMatrix(t),e?new C(t).inverse():W(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,i=new E(o,o);for(let e=0;e<o;e++){let n=E.columnVector(t.getRow(e)),h=t.subMatrixRow(D(o,e)).transpose(),a=new C(h).solve(n),l=E.sub(n,h.mmul(a)).abs().max();i.setRow(e,V(l,a,e,r,s))}return i},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,i=r.diagonal;for(let t=0;t<i.length;t++)Math.abs(i[t])>e?i[t]=1/i[t]:i[t]=0;return o.mmul(E.diag(i).mmul(s.transpose()))},e.kH=W,e.LV=function(t,e){if(s.isAnyArray(t))return t[0]&&s.isAnyArray(t[0])?new k(t):new R(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,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<n;a++)t[a]<h&&(h=t[a]);return h}(t),i=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,i=e.toIndex,n=void 0===i?t.length:i;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(n<=o||n>t.length||!Number.isInteger(n))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[o],a=o+1;a<n;a++)t[a]>h&&(h=t[a]);return h}(t);if(o===i)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var n=r.min,h=void 0===n?r.autoMinMax?o:0:n,a=r.max,l=void 0===a?r.autoMinMax?i:1:a;if(h>=l)throw new RangeError("min option must be smaller than max option");for(var u=(l-h)/(i-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 i=e[s]={exports:{}};return t[s](i,i.exports,r),i.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 i(t){return o(t).map((t,e)=>e)}function n(t,e){return o(t).map(()=>e)}function h(t){return n(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 i=0;i<e;i++){let e=!0;for(;e;){const n=t(r,s);let h=!1;for(let t=0;t<i;t++)if(n===o[t]){h=!0;break}h||(e=!1),o[i]=n}}return o}function c(t,e,r){const s=[];let o=0,i=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let n=0;n<e;n++){const e=[];for(let s=0;s<r;s++)e.push(t[i]),i+=1;s.push(e),o+=1}return s}function f(t,e){const r=r=>o(t).map(()=>n(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 i=0;i<e;i++){let e=!0,n=0;for(;e;){n=t(r,s);let h=!1;for(let t=0;t<i;t++)if(n===o[t]){h=!0;break}h||(e=!1)}o[i]=n}return o}function g(t,e,r,s,o){e=Math.floor(e);const i=t[0][e],n=t[1][e];if(t[2][e],r>=n[0])return 0;for(let t=0;t<i.length;t++)if(s===i[t])return 0;return w(t,e,r,s,o)}function w(t,e,r,s,o){const i=t[0][e],n=t[1][e],h=t[2][e];if(r>=n[0])return 0;n[0]=r,i[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(!(n[e]>r))break;l=e}else if(n[e]>=n[s]){if(!(r<n[e]))break;l=e}else{if(!(r<n[s]))break;l=s}n[a]=n[l],i[a]=i[l],h[a]=h[l],a=l}return n[a]=r,i[a]=s,h[a]=o,1}function p(t,r,s,o,i){const n=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(i);g(n,o,a,s,h),g(n,s,a,o,h),t[2][o][r]=0}return n}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,i=s[0];s[0]=s[e],s[e]=i;const n=o[0];o[0]=o[r],o[r]=n,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,i=o+1;let n=s;if(t[n]<t[o]&&(n=o),i<r&&t[n]<t[i]&&(n=i),n===s)break;{const r=t[s];t[s]=t[n],t[n]=r;const o=e[s];e[s]=e[n],e[n]=o,s=n}}}function b(t,e){const r=t[0][e],s=t[1][e],o=t[2][e];let i=1/0,n=-1;for(let t=0;t>r.length;t++)1===o[t]&&s[t]<i&&(i=s[t],n=t);return n>=0?(o[n]=0,Math.floor(r[n])):-1}r.r(s),r.d(s,{UMAP:()=>lt,initWasm:()=>W,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],i=e[s];this.checkDims(o,i);const n=this.makeKey(o,i);this.entries.set(n,{value:r[s],row:o,col:i})}}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,i)=>{e.push(o),r.push(i),s.push(t)});const o=[t.nCols,t.nRows];return new M(r,e,s,o)}function S(t,e){return k(t,e,(t,e)=>t*e)}function E(t,e){return k(t,e,(t,e)=>t+e)}function v(t,e){return k(t,e,(t,e)=>t-e)}function A(t,e){return t.map(t=>t*e)}function z(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 i=(t,r)=>!e.has(r),n=r.filter(i),h=s.filter(i),a=o.filter(i);return new M(h,a,n,t.getDims())}function N(t,e="l2"){const r=R[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 i=s.get(e).sort(),n=r(i.map(r=>t.get(e,r)));for(let t=0;t<n.length;t++)o.set(e,i[t],n[t])}return o}const R={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 k(t,e,r){const s=new Set,o=[],i=[],n=[],h=(s,h)=>{o.push(s),i.push(h);const a=r(t.get(s,h),e.get(s,h));n.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,i,n,g)}function F(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 i=-1;for(let t=0;t<e.length;t++){const{row:n,col:h,value:a}=e[t];n!==i&&(i=n,o.push(t)),r.push(h),s.push(a)}return{indices:r,values:s,indptr:o}}let I=null,T=null,C=null;async function W(){return I||(I=(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&&(C=await t.default()),T=t,t}catch(t){throw I=null,T=null,C=null,new Error(`Failed to load WASM module: ${t}`)}})(),I)}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");return T.build_rp_tree(t,e,r,s,BigInt(o))}function L(t,e,r,s,o){if(!T)throw new Error("WASM module not initialized");const i=new Int32Array(t),n=new Int32Array(e),h=new Float64Array(r);return new T.WasmSparseMatrix(i,n,h,s,o)}function O(t){if(!T)throw new Error("WASM module not initialized");return T.sparse_transpose(t)}function _(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_add(t,e)}function P(t,e){if(!T)throw new Error("WASM module not initialized");return T.sparse_subtract(t,e)}function j(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 U(t){const e=t.get_all_ordered(),r=Math.floor(e.length/3),s=new Int32Array(r),o=new Int32Array(r),i=new Float64Array(r);let n=0;for(let t=0;t<e.length;t+=3)s[n]=e[t],o[n]=e[t+1],i[n]=e[t+2],n+=1;return{rows:s,cols:o,values:i}}function B(t,e,r,s,o,i,n,h=10,a=50,l=.001,u=.5,c=!0,f="euclidean",m=42){if(!T)throw new Error("WASM module not initialized");return T.nn_descent(t,e,r,s,o,i,n,h,a,l,u,c,f,BigInt(m))}class K{constructor(t,e,r,s){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=s}static fromWasm(t){const e=new K([],new Float64Array(0),[],[]),r=t.children();let s=-1;for(let t=0;t<r.length;t++){const e=r[t];if(e<=0){const t=-e;t>s&&(s=t)}}const o=s+1,i=t.indices(),n=o>0?Math.floor(i.length/o):0;e.hyperplanesFlat=t.hyperplanes(),e.offsetsFlat=t.offsets(),e.childrenFlat=r,e.indicesFlat=i,e.dim=t.dim(),e.nNodes=t.n_nodes(),e.nLeaves=o,e.leafSize=n;const h=new Array(e.nNodes);for(let t=0;t<e.nNodes;t++){const r=t*e.dim;h[t]=e.hyperplanesFlat.subarray(r,r+e.dim)}const a=new Array(e.nNodes);for(let t=0;t<e.nNodes;t++){const r=2*t;a[t]=e.childrenFlat.subarray(r,r+2)}const l=new Array(e.nLeaves);for(let t=0;t<e.nLeaves;t++){const r=t*e.leafSize;l[t]=e.indicesFlat.subarray(r,r+e.leafSize)}return e.hyperplanes=h,e.offsets=e.offsetsFlat,e.children=a,e.indices=l,e.wasmTree=t,e}getWasmTree(){return this.wasmTree}getFlatHyperplanes(){return this.hyperplanesFlat}getFlatOffsets(){return this.offsetsFlat}getFlatChildren(){return this.childrenFlat}getFlatLeafMeta(){if(this.indicesFlat&&void 0!==this.nLeaves&&void 0!==this.leafSize)return{indices:this.indicesFlat,nLeaves:this.nLeaves,leafSize:this.leafSize}}getDim(){return this.dim}dispose(){this.wasmTree&&(this.wasmTree.free(),this.wasmTree=void 0)}}function G(t,e,r,s,o=!1){const n=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,i=t[0].length,n=[],h=new Float64Array(o*i);for(let e=0;e<o;e++)for(let r=0;r<i;r++)h[e*i+r]=t[e][r];for(let t=0;t<r;t++){const t=q(h,o,i,e,Math.floor(4294967295*s()));n.push(K.fromWasm(t))}return n}(t,n,r,s)}const a=i(r).map((e,r)=>function(t,e=30,r,s){return Q(t,i(t.length),e,r,s)}(t,n,r,s)),l=a.map(t=>function(t,e){const r=X(t),s=H(t),o=i(r).map(()=>h(t.hyperplane?t.hyperplane.length:0)),n=h(r),a=i(r).map(()=>[-1,-1]),l=i(s).map(()=>i(e).map(()=>-1));return Y(t,o,n,a,l,0,0),new K(o,n,a,l)}(t,n));return l}function Q(e,r,s=30,o,i){if(r.length>s){const n=function(e,r,s){const o=e[0].length;let i=t(r.length,s),n=t(r.length,s);n+=i===n?1:0,n%=r.length;const a=r[i],l=r[n];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 i=0;i<r.length;i++){let n=u;for(let t=0;t<o;t++)n+=c[t]*e[r[i]][t];0===n?(g[i]=t(2,s),0===g[i]?f+=1:m+=1):n>0?(g[i]=0,f+=1):(g[i]=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,i),{indicesLeft:a,indicesRight:l,hyperplane:u,offset:c}=n;return{leftChild:Q(e,a,s,o+1,i),rightChild:Q(e,l,s,o+1,i),isLeaf:!1,hyperplane:u,offset:c}}return{indices:r,isLeaf:!0}}function Y(t,e,r,s,o,i,n){if(t.isLeaf)return s[i][0]=-n,o[n].splice(0,t.indices.length,...t.indices),{nodeNum:i,leafNum:n+=1};{e[i]=t.hyperplane,r[i]=t.offset,s[i][0]=i+1;const h=i;let a=Y(t.leftChild,e,r,s,o,i+1,n);return i=a.nodeNum,n=a.leafNum,s[h][1]=i+1,a=Y(t.rightChild,e,r,s,o,i+1,n),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function X(t){return t.isLeaf?1:1+X(t.leftChild)+X(t.rightChild)}function H(t){return t.isLeaf?1:H(t.leftChild)+H(t.rightChild)}function J(e,r,s,o){let i=r;for(let t=0;t<s.length;t++)i+=e[t]*s[t];return 0===i?t(2,o):i>0?0:1}function Z(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()));const o=e.getFlatChildren(),i=e.getFlatHyperplanes(),n=e.getFlatOffsets(),h=e.getDim(),a=e.getFlatLeafMeta();if(o&&i&&n&&void 0!==h&&a){let e=0;for(;o[2*e]>0;){const s=n[e],a=e*h;e=0===J(i.subarray(a,a+h),s,t,r)?o[2*e]:o[2*e+1]}const s=-o[2*e],{indices:l,leafSize:u}=a,c=s*u,f=new Array(u);for(let t=0;t<u;t++)f[t]=l[c+t];return f}let l=0;for(;e.children[l][0]>0;)l=0===J(e.hyperplanes[l],e.offsets[l],t,r)?e.children[l][0]:e.children[l][1];const u=-1*e.children[l][0];return e.indices[u]}const tt=Object.prototype.toString;function et(t){return tt.call(t).endsWith("Array]")}function rt(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 st=r(673);st.y3,st.jy,st.oN,st.Hc,st.cg,st.hj,st.LU,st.Tb;const ot=st.uq,it=(st.Zm,st.Dq,st.__,st.q0,st.lh,st.pI,st.zC,st.zg,st.g6,st.OL,st.ks,st.QR,st.jp,st.mk,st.W2,st.l,st.KY,st.dv,st.BR,st.Wu,st.uq,st.uq,st.a4,st.DI);function nt(t,e,r,s,o){let i=r*s*s,n=ot.eye(e.length,e.length,i);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 i=r.length,n=t.x.length;let h=new Array(i);for(let a=0;a<i;a++){h[a]=new Array(n);let i=r.slice();i[a]+=s;let l=o(i);for(let r=0;r<n;r++)h[a][r]=e[r]-l(t.x[r])}return new ot(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 ot(s)}(t,a),c=it(n.add(l.mmul(l.transpose())));return(e=(e=new ot([e])).sub(c.mmul(l).mmul(u).mul(s).transpose())).to1DArray()}st.Jo,st.Zi,st.kH,st.LV;const ht=1e-5,at=.001;class lt{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=ut,this.useWasmDistance=!1,this.useWasmNNDescent=!1,this.useWasmMatrix=!1,this.useWasmOptimizer=!1,this.useWasmTree=!1,this.wasmBatchSize=10,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new ct,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("wasmBatchSize"),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,i){for(let n=0;n<r.length;n++){const h=u(t,e.length,i);for(let t=0;t<h.length;t++)h[t]<0||g(o,n,s(e[h[t]],r[n]),h[t],1)}},initFromTree:function(t,e,r,o,i){for(let n=0;n<r.length;n++){const h=Z(r[n],t,i);for(let t=0;t<h.length;t++){if(h[t]<0)return;g(o,n,s(e[h[t]],r[n]),h[t],1)}}}});var s;this.initFromTree=e,this.initFromRandom=r,this.search=function(t){return function(e,r,s,o){const{indices:i,indptr:n}=F(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=i.slice(n[a],n[a+1]);for(const i of l)i===a||-1===i||h.has(i)||(w(s,r,t(e[i],o[r]),i,1),h.add(i))}}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],i=r[t];for(let e=0;e<s.length;e++){const r=s[e],n=i[e];n>0&&o.set(t,r,n)}}return k(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,i,n){const h=f(r.length,s);if(o(s,e,r,h,n),t)for(let s of t)i(s,e,r,h,n);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),o=this.search(e,this.searchGraph,s,t);let{indices:i,weights:n}=d(o);i=i.map(t=>t.slice(0,this.nNeighbors)),n=n.map(t=>t.slice(0,this.nNeighbors));const a=Math.max(0,this.localConnectivity-1),{sigmas:l,rhos:u}=this.smoothKNNDistance(n,this.nNeighbors,a),{rows:m,cols:g,vals:w}=this.computeMembershipStrengths(i,n,l,u),p=[t.length,e.length];let y=new M(m,g,w,p);const b=F(N(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 i=0;i<t[0].length;i++)for(let n=0;n<r[0].length;n++){const h=t[o][i];s[o][n]+=e[o][i]*r[h][n]}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=z(y);const A=this.makeEpochsPerSample(y.getValues(),E),R=y.getRows(),k=y.getCols();return this.assignOptimizationStateParameters({headEmbedding:S,tailEmbedding:this.embedding,head:R,tail:k,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.useWasmOptimizer&&this.wasmOptimizerState?this.materializeEmbeddingFromWasm():this.embedding}nearestNeighbors(t){const{distanceFn:r,nNeighbors:s}=this,o=function(t,r,s=!1){return function(o,i,n,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="cosine"===t.name?"cosine":"euclidean",s=Math.floor(4294967295*r()),f=o.length,m=o[0].length,g=new Float64Array(f*m);for(let t=0;t<f;t++)for(let e=0;e<m;e++)g[t*m+e]=o[t][e];const w=i.length,p=w>0?i[0].length:0,d=new Int32Array(w*p);for(let t=0;t<w;t++)for(let e=0;e<p;e++)d[t*p+e]=i[t][e];const y=B(g,f,m,d,w,p,n,h,a,l,u,c,e,s),b=[],M=[],x=f*n;for(let t=0;t<f;t++){const e=[],r=[];for(let s=0;s<n;s++)e.push(y[t*n+s]),r.push(y[x+t*n+s]);b.push(e),M.push(r)}return{indices:b,weights:M}}const w=o.length,y=f(o.length,n);for(let e=0;e<o.length;e++){const s=m(n,o.length,r);for(let r=0;r<s.length;r++){const i=t(o[e],o[s[r]]);g(y,e,i,s[r],1),g(y,s[r],i,e,1)}}if(c)for(let e=0;e<i.length;e++)for(let r=0;r<i[e].length&&!(i[e][r]<0);r++)for(let s=r+1;s<i[e].length&&!(i[e][s]<0);s++){const n=t(o[i[e][r]],o[i[e][s]]);g(y,i[e][r],n,i[e][s],1),g(y,i[e][s],n,i[e][r],1)}for(let s=0;s<h;s++){const s=p(y,w,n,a,r);let i=0;for(let n=0;n<w;n++)for(let h=0;h<a;h++){let l=Math.floor(s[0][n][h]);if(!(l<0||e(r)<u))for(let e=0;e<a;e++){const r=Math.floor(s[0][n][e]),a=s[2][n][h],u=s[2][n][e];if(r<0||!a&&!u)continue;const c=t(o[l],o[r]);i+=g(y,l,c,r,1),i+=g(y,r,c,l,1)}}if(i<=l*n*o.length)break}return d(y)}}(r,this.random,this.useWasmNNDescent),i=5+Math.floor(.5==(n=t.length**.5/20)?0:Math.round(n));var n;const h=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));if(this.rpForest=G(t,s,i,this.random,this.useWasmTree),this.useWasmNNDescent&&D()){const e=t.length,o=t[0].length,i=new Float64Array(e*o);for(let r=0;r<e;r++)for(let e=0;e<o;e++)i[r*o+e]=t[r][e];const{flatLeafArray:n,nLeaves:a,leafSize:l}=function(t){if(0===t.length)return{flatLeafArray:new Int32Array([-1]),nLeaves:1,leafSize:1};let e=-1,r=0;for(const s of t){const t=s.getFlatLeafMeta();t?(-1===e&&(e=t.leafSize),r+=t.nLeaves):(-1===e&&(e=s.indices[0]?.length??0),r+=s.indices.length)}const s=new Int32Array(r*e);let o=0;for(const r of t){const t=r.getFlatLeafMeta();if(t)s.set(t.indices,o),o+=t.indices.length;else{for(let t=0;t<r.indices.length;t++){const i=r.indices[t];for(let r=0;r<e;r++)s[o+t*e+r]=i[r]}o+=r.indices.length*e}}return{flatLeafArray:s,nLeaves:r,leafSize:e}}(this.rpForest),u=B(i,e,o,n,a,l,s,h,50,.001,.5,!0,"cosine"===r.name?"cosine":"euclidean",Math.floor(4294967295*this.random())),c=[],f=[],m=e*s;for(let t=0;t<e;t++){const e=[],r=[];for(let o=0;o<s;o++)e.push(u[t*s+o]),r.push(u[m+t*s+o]);c.push(e),f.push(r)}return{knnIndices:c,knnDistances:f}}const a=function(t){if(t.length>0){const e=[];for(let r of t){if(r.indices.length>0){e.push(...r.indices);continue}const t=r.getFlatLeafMeta();if(!t)continue;const{indices:s,nLeaves:o,leafSize:i}=t;for(let t=0;t<o;t++){const r=t*i,o=new Array(i);for(let t=0;t<i;t++)o[t]=s[r+t];e.push(o)}}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:i}=this,{sigmas:n,rhos:h}=this.smoothKNNDistance(o,e,i),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(s,o,n,h),c=[t.length,t.length];if(this.useWasmMatrix&&D()){const t=L(a,l,u,c[0],c[1]),e=O(t),s=j(t,e),o=_(t,e),i=_($(P(o,s),r),$(s,1-r)),{rows:n,cols:h,values:f}=U(i);return new M(n,h,f,c)}if(this.useWasmMatrix&&D()){const t=L(a,l,u,c[0],c[1]),e=O(t),s=j(t,e),o=_(t,e),i=_($(P(o,s),r),$(s,1-r)),{rows:n,cols:h,values:f}=U(i);return new M(n,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,i)=>-1===e[o]||-1===e[i]?t*Math.exp(-r):e[o]!==e[i]?t*Math.exp(-s):t)}(t,e,s,r);return o=z(o),function(t){const e=x(t=N(t,"max"));return z(t=E(t,v(e,S(e,t))))}(o)}smoothKNNDistance(t,e,r=1,s=64,o=1){const i=Math.log(e)/Math.log(2)*o,n=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?(n[e]=m[t-1],s>ht&&(n[e]+=s*(m[t]-m[t-1]))):n[e]=s*m[0]}else m.length>0&&(n[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]-n[e];r+=o>0?Math.exp(-o/c):1}if(Math.abs(r-i)<ht)break;r>i?(h=c,c=(o+h)/2):(o=c,h===1/0?c*=2:c=(o+h)/2)}if(u[e]=c,n[e]>0){const t=a(f);u[e]<at*t&&(u[e]=at*t)}else{const r=a(t.map(a));u[e]<at*r&&(u[e]=at*r)}}return{sigmas:u,rhos:n}}computeMembershipStrengths(t,e,r,s){const o=t.length,i=t[0].length,n=h(o*i),a=h(o*i),l=h(o*i);for(let h=0;h<o;h++)for(let o=0;o<i;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]),n[h*i+o]=h,a[h*i+o]=t[h][o],l[h*i+o]=u)}return{rows:n,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 i=this.graph.map(e=>e<o/t?0:e);this.embedding=h(i.nRows).map(()=>h(r).map(()=>20*e(this.random)-10));const n=[],a=[],l=[],u=i.getAll();for(let t=0;t<u.length;t++){const e=u[t];e.value&&(n.push(e.value),l.push(e.row),a.push(e.col))}return{head:a,tail:l,epochsPerSample:this.makeEpochsPerSample(n,t)}}makeEpochsPerSample(t,e){const r=n(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:i}=this.optimizationState,n=o[0].length,h=o.length===i.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:n}),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,i,n,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(i);return new T.OptimizerState(p,d,g,w,y,b,n,h,a,l,u,c,f,m)}(r,l,o,i,s,a,h,e,t,f,m,n,u,c),this.rngState=BigInt(Math.floor(4294967295*this.random())),this.wasmOptimizerState.set_rng_seed(this.rngState)}}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:s,epochsPerSample:i}=this.optimizationState,n=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),i={x:r,y:s},{parameterValues:n}=function(t,e,r={}){let{maxIterations:s=100,gradientDifference:o=.1,damping:i=0,errorTolerance:n=.01,minValues:h,maxValues:a,initialValues:l}=r;if(i<=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(!et(t.x)||t.x.length<2||!et(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(!et(u))throw new Error("initialValues must be an array");let f,m=rt(t,u,e),g=m<=n;for(f=0;f<s&&!g;f++){u=nt(t,u,i,o,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(m=rt(t,u,e),isNaN(m))break;g=m<=n}return{parameterValues:u,parameterError:m,iterations:f}}(i,([t,e])=>r=>1/(1+t*r**(2*e)),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[a,l]=n;return{a,b:l}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:s,epochsPerSample:i,a:l,b:u,nEpochs:n,nVertices:a})}optimizeLayoutStep(e){if(this.useWasmOptimizer&&this.wasmOptimizerState)return function(t){if(!T)throw new Error("WASM module not initialized");T.optimize_layout_step_in_place(t)}(this.wasmOptimizerState),this.optimizationState.currentEpoch+=1,this.materializeEmbeddingFromWasm();const{optimizationState:r}=this,{head:s,tail:o,headEmbedding:i,tailEmbedding:n,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=i[f],x=n[y],S=mt(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=ft(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=n[e],s=mt(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=ft(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,i}optimizeLayoutAsync(t=()=>!0){return new Promise((e,r)=>{const s=async()=>{try{if(this.useWasmOptimizer&&this.wasmOptimizerState){const{nEpochs:r,currentEpoch:o}=this.optimizationState;if(o>=r)return this.embedding=this.materializeEmbeddingFromWasm(),e(!0);const i=Math.max(1,this.wasmBatchSize),n=Math.min(i,r-o),h=o,a=this.optimizeLayoutBatchWasm(n);let l=!1;for(let e=h+1;e<=h+a;e++)if(!1===t(e)){l=!0;break}const u=this.optimizationState.currentEpoch===r;return l||u?(this.embedding=this.materializeEmbeddingFromWasm(),e(u)):void setTimeout(()=>s(),0)}const{nEpochs:r,currentEpoch:o}=this.optimizationState;this.embedding=this.optimizeLayoutStep(o);const i=this.optimizationState.currentEpoch,n=!1===t(i),h=i===r;if(n||h)return e(h);setTimeout(()=>s(),0)}catch(t){r(t)}};setTimeout(()=>s(),0)})}optimizeLayout(t=()=>!0){let e=!1,r=[];if(this.useWasmOptimizer&&this.wasmOptimizerState){for(;!e;){const{nEpochs:r,currentEpoch:s}=this.optimizationState,o=Math.max(1,this.wasmBatchSize),i=Math.min(o,r-s),n=s,h=this.optimizeLayoutBatchWasm(i);let a=!1;for(let e=n+1;e<=n+h;e++)if(!1===t(e)){a=!0;break}e=this.optimizationState.currentEpoch===r||a}return r=this.materializeEmbeddingFromWasm(),r}for(;!e;){const{nEpochs:s,currentEpoch:o}=this.optimizationState;r=this.optimizeLayoutStep(o);const i=this.optimizationState.currentEpoch,n=!1===t(i);e=i===s||n}return r}optimizeLayoutBatchWasm(t){if(!this.wasmOptimizerState)throw new Error("WASM optimizer state is not initialized.");const e=this.optimizationState.nEpochs-this.optimizationState.currentEpoch,r=Math.min(t,e);return r<=0?0:(function(t,e){if(!T)throw new Error("WASM module not initialized");T.optimize_layout_batch_in_place(t,e)}(this.wasmOptimizerState,r),this.optimizationState.currentEpoch+=r,r)}materializeEmbeddingFromWasm(){if(!this.wasmOptimizerState)return this.embedding;const{dim:t,nVertices:e}=this.optimizationState,r=function(t){if(!T)throw new Error("WASM module not initialized");const e=t.head_embedding_ptr(),r=t.head_embedding_len(),s=C?.memory??T?.memory??T?.__wasm?.memory;if(!s?.buffer)throw new Error("WASM memory is not available");return new Float64Array(s.buffer,e,r)}(this.wasmOptimizerState),s=new Array(e);for(let o=0;o<e;o++){const e=new Array(t),i=o*t;for(let s=0;s<t;s++)e[s]=r[i+s];s[o]=e}return this.embedding=s,s}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 ut(t,e){let r=0;for(let s=0;s<t.length;s++)r+=(t[s]-e[s])**2;return Math.sqrt(r)}class ct{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 ft(t,e){return t>e?e:t<-e?-e:t}function mt(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.4.8",
3
+ "version": "0.5.0",
4
4
  "description": "JavaScript implementation of UMAP",
5
5
  "author": {
6
6
  "name": "Elar Saks",
@@ -49,7 +49,7 @@ export class OptimizerState {
49
49
  /**
50
50
  * Create a new optimizer state with the given parameters.
51
51
  */
52
- constructor(head: Uint32Array, tail: Uint32Array, head_embedding: Float32Array, tail_embedding: Float32Array, epochs_per_sample: Float32Array, epochs_per_negative_sample: Float32Array, move_other: boolean, initial_alpha: number, gamma: number, a: number, b: number, dim: number, n_epochs: number, n_vertices: number);
52
+ constructor(head: Uint32Array, tail: Uint32Array, head_embedding: Float64Array, tail_embedding: Float64Array, epochs_per_sample: Float64Array, epochs_per_negative_sample: Float64Array, move_other: boolean, initial_alpha: number, gamma: number, a: number, b: number, dim: number, n_epochs: number, n_vertices: number);
53
53
  /**
54
54
  * Get the current RNG seed/state.
55
55
  */
@@ -61,7 +61,7 @@ export class OptimizerState {
61
61
  /**
62
62
  * Get the current embedding as a flat array.
63
63
  */
64
- readonly head_embedding: Float32Array;
64
+ readonly head_embedding: Float64Array;
65
65
  /**
66
66
  * Get the total number of epochs.
67
67
  */
@@ -229,7 +229,7 @@ export function nn_descent(data_flat: Float64Array, n_samples: number, dim: numb
229
229
  * # Returns
230
230
  * The final embedding as a flat vector
231
231
  */
232
- export function optimize_layout_batch(state: OptimizerState, n_steps: number): Float32Array;
232
+ export function optimize_layout_batch(state: OptimizerState, n_steps: number): Float64Array;
233
233
 
234
234
  /**
235
235
  * Perform multiple optimization steps in place without cloning the embedding.
@@ -244,7 +244,7 @@ export function optimize_layout_batch_in_place(state: OptimizerState, n_steps: n
244
244
  * # Returns
245
245
  * The updated embedding as a flat vector
246
246
  */
247
- export function optimize_layout_step(state: OptimizerState): Float32Array;
247
+ export function optimize_layout_step(state: OptimizerState): Float64Array;
248
248
 
249
249
  /**
250
250
  * Perform a single optimization step in place without cloning the embedding.
@@ -8,11 +8,6 @@ function _assertClass(instance, klass) {
8
8
  }
9
9
  }
10
10
 
11
- function getArrayF32FromWasm0(ptr, len) {
12
- ptr = ptr >>> 0;
13
- return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
14
- }
15
-
16
11
  function getArrayF64FromWasm0(ptr, len) {
17
12
  ptr = ptr >>> 0;
18
13
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
@@ -28,14 +23,6 @@ function getArrayU32FromWasm0(ptr, len) {
28
23
  return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
29
24
  }
30
25
 
31
- let cachedFloat32ArrayMemory0 = null;
32
- function getFloat32ArrayMemory0() {
33
- if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
34
- cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
35
- }
36
- return cachedFloat32ArrayMemory0;
37
- }
38
-
39
26
  let cachedFloat64ArrayMemory0 = null;
40
27
  function getFloat64ArrayMemory0() {
41
28
  if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
@@ -80,13 +67,6 @@ function passArray32ToWasm0(arg, malloc) {
80
67
  return ptr;
81
68
  }
82
69
 
83
- function passArrayF32ToWasm0(arg, malloc) {
84
- const ptr = malloc(arg.length * 4, 4) >>> 0;
85
- getFloat32ArrayMemory0().set(arg, ptr / 4);
86
- WASM_VECTOR_LEN = arg.length;
87
- return ptr;
88
- }
89
-
90
70
  function passArrayF64ToWasm0(arg, malloc) {
91
71
  const ptr = malloc(arg.length * 8, 8) >>> 0;
92
72
  getFloat64ArrayMemory0().set(arg, ptr / 8);
@@ -280,12 +260,12 @@ class OptimizerState {
280
260
  }
281
261
  /**
282
262
  * Get the current embedding as a flat array.
283
- * @returns {Float32Array}
263
+ * @returns {Float64Array}
284
264
  */
285
265
  get head_embedding() {
286
266
  const ret = wasm.optimizerstate_head_embedding(this.__wbg_ptr);
287
- var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
288
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
267
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
268
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
289
269
  return v1;
290
270
  }
291
271
  /**
@@ -308,10 +288,10 @@ class OptimizerState {
308
288
  * Create a new optimizer state with the given parameters.
309
289
  * @param {Uint32Array} head
310
290
  * @param {Uint32Array} tail
311
- * @param {Float32Array} head_embedding
312
- * @param {Float32Array} tail_embedding
313
- * @param {Float32Array} epochs_per_sample
314
- * @param {Float32Array} epochs_per_negative_sample
291
+ * @param {Float64Array} head_embedding
292
+ * @param {Float64Array} tail_embedding
293
+ * @param {Float64Array} epochs_per_sample
294
+ * @param {Float64Array} epochs_per_negative_sample
315
295
  * @param {boolean} move_other
316
296
  * @param {number} initial_alpha
317
297
  * @param {number} gamma
@@ -326,13 +306,13 @@ class OptimizerState {
326
306
  const len0 = WASM_VECTOR_LEN;
327
307
  const ptr1 = passArray32ToWasm0(tail, wasm.__wbindgen_malloc);
328
308
  const len1 = WASM_VECTOR_LEN;
329
- const ptr2 = passArrayF32ToWasm0(head_embedding, wasm.__wbindgen_malloc);
309
+ const ptr2 = passArrayF64ToWasm0(head_embedding, wasm.__wbindgen_malloc);
330
310
  const len2 = WASM_VECTOR_LEN;
331
- const ptr3 = passArrayF32ToWasm0(tail_embedding, wasm.__wbindgen_malloc);
311
+ const ptr3 = passArrayF64ToWasm0(tail_embedding, wasm.__wbindgen_malloc);
332
312
  const len3 = WASM_VECTOR_LEN;
333
- const ptr4 = passArrayF32ToWasm0(epochs_per_sample, wasm.__wbindgen_malloc);
313
+ const ptr4 = passArrayF64ToWasm0(epochs_per_sample, wasm.__wbindgen_malloc);
334
314
  const len4 = WASM_VECTOR_LEN;
335
- const ptr5 = passArrayF32ToWasm0(epochs_per_negative_sample, wasm.__wbindgen_malloc);
315
+ const ptr5 = passArrayF64ToWasm0(epochs_per_negative_sample, wasm.__wbindgen_malloc);
336
316
  const len5 = WASM_VECTOR_LEN;
337
317
  const ret = wasm.optimizerstate_new(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, move_other, initial_alpha, gamma, a, b, dim, n_epochs, n_vertices);
338
318
  this.__wbg_ptr = ret >>> 0;
@@ -696,13 +676,13 @@ exports.nn_descent = nn_descent;
696
676
  * The final embedding as a flat vector
697
677
  * @param {OptimizerState} state
698
678
  * @param {number} n_steps
699
- * @returns {Float32Array}
679
+ * @returns {Float64Array}
700
680
  */
701
681
  function optimize_layout_batch(state, n_steps) {
702
682
  _assertClass(state, OptimizerState);
703
683
  const ret = wasm.optimize_layout_batch(state.__wbg_ptr, n_steps);
704
- var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
705
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
684
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
685
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
706
686
  return v1;
707
687
  }
708
688
  exports.optimize_layout_batch = optimize_layout_batch;
@@ -726,13 +706,13 @@ exports.optimize_layout_batch_in_place = optimize_layout_batch_in_place;
726
706
  * # Returns
727
707
  * The updated embedding as a flat vector
728
708
  * @param {OptimizerState} state
729
- * @returns {Float32Array}
709
+ * @returns {Float64Array}
730
710
  */
731
711
  function optimize_layout_step(state) {
732
712
  _assertClass(state, OptimizerState);
733
713
  const ret = wasm.optimize_layout_step(state.__wbg_ptr);
734
- var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
735
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
714
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
715
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
736
716
  return v1;
737
717
  }
738
718
  exports.optimize_layout_step = optimize_layout_step;
@@ -49,7 +49,7 @@ export class OptimizerState {
49
49
  /**
50
50
  * Create a new optimizer state with the given parameters.
51
51
  */
52
- constructor(head: Uint32Array, tail: Uint32Array, head_embedding: Float32Array, tail_embedding: Float32Array, epochs_per_sample: Float32Array, epochs_per_negative_sample: Float32Array, move_other: boolean, initial_alpha: number, gamma: number, a: number, b: number, dim: number, n_epochs: number, n_vertices: number);
52
+ constructor(head: Uint32Array, tail: Uint32Array, head_embedding: Float64Array, tail_embedding: Float64Array, epochs_per_sample: Float64Array, epochs_per_negative_sample: Float64Array, move_other: boolean, initial_alpha: number, gamma: number, a: number, b: number, dim: number, n_epochs: number, n_vertices: number);
53
53
  /**
54
54
  * Get the current RNG seed/state.
55
55
  */
@@ -61,7 +61,7 @@ export class OptimizerState {
61
61
  /**
62
62
  * Get the current embedding as a flat array.
63
63
  */
64
- readonly head_embedding: Float32Array;
64
+ readonly head_embedding: Float64Array;
65
65
  /**
66
66
  * Get the total number of epochs.
67
67
  */
@@ -229,7 +229,7 @@ export function nn_descent(data_flat: Float64Array, n_samples: number, dim: numb
229
229
  * # Returns
230
230
  * The final embedding as a flat vector
231
231
  */
232
- export function optimize_layout_batch(state: OptimizerState, n_steps: number): Float32Array;
232
+ export function optimize_layout_batch(state: OptimizerState, n_steps: number): Float64Array;
233
233
 
234
234
  /**
235
235
  * Perform multiple optimization steps in place without cloning the embedding.
@@ -244,7 +244,7 @@ export function optimize_layout_batch_in_place(state: OptimizerState, n_steps: n
244
244
  * # Returns
245
245
  * The updated embedding as a flat vector
246
246
  */
247
- export function optimize_layout_step(state: OptimizerState): Float32Array;
247
+ export function optimize_layout_step(state: OptimizerState): Float64Array;
248
248
 
249
249
  /**
250
250
  * Perform a single optimization step in place without cloning the embedding.
@@ -6,11 +6,6 @@ function _assertClass(instance, klass) {
6
6
  }
7
7
  }
8
8
 
9
- function getArrayF32FromWasm0(ptr, len) {
10
- ptr = ptr >>> 0;
11
- return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
12
- }
13
-
14
9
  function getArrayF64FromWasm0(ptr, len) {
15
10
  ptr = ptr >>> 0;
16
11
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
@@ -26,14 +21,6 @@ function getArrayU32FromWasm0(ptr, len) {
26
21
  return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
27
22
  }
28
23
 
29
- let cachedFloat32ArrayMemory0 = null;
30
- function getFloat32ArrayMemory0() {
31
- if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
32
- cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
33
- }
34
- return cachedFloat32ArrayMemory0;
35
- }
36
-
37
24
  let cachedFloat64ArrayMemory0 = null;
38
25
  function getFloat64ArrayMemory0() {
39
26
  if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
@@ -78,13 +65,6 @@ function passArray32ToWasm0(arg, malloc) {
78
65
  return ptr;
79
66
  }
80
67
 
81
- function passArrayF32ToWasm0(arg, malloc) {
82
- const ptr = malloc(arg.length * 4, 4) >>> 0;
83
- getFloat32ArrayMemory0().set(arg, ptr / 4);
84
- WASM_VECTOR_LEN = arg.length;
85
- return ptr;
86
- }
87
-
88
68
  function passArrayF64ToWasm0(arg, malloc) {
89
69
  const ptr = malloc(arg.length * 8, 8) >>> 0;
90
70
  getFloat64ArrayMemory0().set(arg, ptr / 8);
@@ -285,12 +265,12 @@ export class OptimizerState {
285
265
  }
286
266
  /**
287
267
  * Get the current embedding as a flat array.
288
- * @returns {Float32Array}
268
+ * @returns {Float64Array}
289
269
  */
290
270
  get head_embedding() {
291
271
  const ret = wasm.optimizerstate_head_embedding(this.__wbg_ptr);
292
- var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
293
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
272
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
273
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
294
274
  return v1;
295
275
  }
296
276
  /**
@@ -313,10 +293,10 @@ export class OptimizerState {
313
293
  * Create a new optimizer state with the given parameters.
314
294
  * @param {Uint32Array} head
315
295
  * @param {Uint32Array} tail
316
- * @param {Float32Array} head_embedding
317
- * @param {Float32Array} tail_embedding
318
- * @param {Float32Array} epochs_per_sample
319
- * @param {Float32Array} epochs_per_negative_sample
296
+ * @param {Float64Array} head_embedding
297
+ * @param {Float64Array} tail_embedding
298
+ * @param {Float64Array} epochs_per_sample
299
+ * @param {Float64Array} epochs_per_negative_sample
320
300
  * @param {boolean} move_other
321
301
  * @param {number} initial_alpha
322
302
  * @param {number} gamma
@@ -331,13 +311,13 @@ export class OptimizerState {
331
311
  const len0 = WASM_VECTOR_LEN;
332
312
  const ptr1 = passArray32ToWasm0(tail, wasm.__wbindgen_malloc);
333
313
  const len1 = WASM_VECTOR_LEN;
334
- const ptr2 = passArrayF32ToWasm0(head_embedding, wasm.__wbindgen_malloc);
314
+ const ptr2 = passArrayF64ToWasm0(head_embedding, wasm.__wbindgen_malloc);
335
315
  const len2 = WASM_VECTOR_LEN;
336
- const ptr3 = passArrayF32ToWasm0(tail_embedding, wasm.__wbindgen_malloc);
316
+ const ptr3 = passArrayF64ToWasm0(tail_embedding, wasm.__wbindgen_malloc);
337
317
  const len3 = WASM_VECTOR_LEN;
338
- const ptr4 = passArrayF32ToWasm0(epochs_per_sample, wasm.__wbindgen_malloc);
318
+ const ptr4 = passArrayF64ToWasm0(epochs_per_sample, wasm.__wbindgen_malloc);
339
319
  const len4 = WASM_VECTOR_LEN;
340
- const ptr5 = passArrayF32ToWasm0(epochs_per_negative_sample, wasm.__wbindgen_malloc);
320
+ const ptr5 = passArrayF64ToWasm0(epochs_per_negative_sample, wasm.__wbindgen_malloc);
341
321
  const len5 = WASM_VECTOR_LEN;
342
322
  const ret = wasm.optimizerstate_new(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, move_other, initial_alpha, gamma, a, b, dim, n_epochs, n_vertices);
343
323
  this.__wbg_ptr = ret >>> 0;
@@ -695,13 +675,13 @@ export function nn_descent(data_flat, n_samples, dim, leaf_array_flat, n_leaves,
695
675
  * The final embedding as a flat vector
696
676
  * @param {OptimizerState} state
697
677
  * @param {number} n_steps
698
- * @returns {Float32Array}
678
+ * @returns {Float64Array}
699
679
  */
700
680
  export function optimize_layout_batch(state, n_steps) {
701
681
  _assertClass(state, OptimizerState);
702
682
  const ret = wasm.optimize_layout_batch(state.__wbg_ptr, n_steps);
703
- var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
704
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
683
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
684
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
705
685
  return v1;
706
686
  }
707
687
 
@@ -723,13 +703,13 @@ export function optimize_layout_batch_in_place(state, n_steps) {
723
703
  * # Returns
724
704
  * The updated embedding as a flat vector
725
705
  * @param {OptimizerState} state
726
- * @returns {Float32Array}
706
+ * @returns {Float64Array}
727
707
  */
728
708
  export function optimize_layout_step(state) {
729
709
  _assertClass(state, OptimizerState);
730
710
  const ret = wasm.optimize_layout_step(state.__wbg_ptr);
731
- var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
732
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
711
+ var v1 = getArrayF64FromWasm0(ret[0], ret[1]).slice();
712
+ wasm.__wbindgen_free(ret[0], ret[1] * 8, 8);
733
713
  return v1;
734
714
  }
735
715
 
@@ -974,7 +954,6 @@ function __wbg_get_imports() {
974
954
  function __wbg_finalize_init(instance, module) {
975
955
  wasm = instance.exports;
976
956
  __wbg_init.__wbindgen_wasm_module = module;
977
- cachedFloat32ArrayMemory0 = null;
978
957
  cachedFloat64ArrayMemory0 = null;
979
958
  cachedInt32ArrayMemory0 = null;
980
959
  cachedUint32ArrayMemory0 = null;
Binary file