@datagrok/bio 2.11.41 → 2.12.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.
- package/CHANGELOG.md +14 -0
- package/README.md +1 -1
- package/detectors.js +11 -11
- package/dist/36.js +1 -1
- package/dist/36.js.map +1 -1
- package/dist/413.js +1 -1
- package/dist/413.js.map +1 -1
- package/dist/590.js +1 -1
- package/dist/590.js.map +1 -1
- package/dist/709.js +1 -1
- package/dist/709.js.map +1 -1
- package/dist/895.js +1 -1
- package/dist/895.js.map +1 -1
- package/dist/package-test.js +2 -2
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +2 -2
- package/dist/package.js.map +1 -1
- package/package.json +10 -10
- package/src/analysis/sequence-activity-cliffs.ts +9 -9
- package/src/analysis/sequence-diversity-viewer.ts +3 -3
- package/src/analysis/sequence-search-base-viewer.ts +2 -2
- package/src/analysis/sequence-similarity-viewer.ts +10 -10
- package/src/analysis/sequence-space.ts +26 -23
- package/src/calculations/monomerLevelMols.ts +13 -11
- package/src/const.ts +5 -0
- package/src/package.ts +8 -8
- package/src/tests/WebLogo-layout-tests.ts +5 -2
- package/src/tests/WebLogo-positions-test.ts +20 -16
- package/src/tests/bio-tests.ts +19 -7
- package/src/tests/converters-test.ts +4 -4
- package/src/tests/detectors-benchmark-tests.ts +5 -5
- package/src/tests/detectors-tests.ts +13 -13
- package/src/tests/fasta-export-tests.ts +10 -4
- package/src/tests/mm-distance-tests.ts +10 -10
- package/src/tests/msa-tests.ts +8 -15
- package/src/tests/renderers-monomer-placer.ts +3 -3
- package/src/tests/renderers-test.ts +6 -8
- package/src/tests/splitters-test.ts +14 -13
- package/src/tests/to-atomic-level-tests.ts +2 -2
- package/src/tests/units-handler-get-region.ts +4 -4
- package/src/tests/units-handler-splitted-tests.ts +19 -17
- package/src/tests/units-handler-tests.ts +32 -32
- package/src/utils/cell-renderer.ts +40 -34
- package/src/utils/check-input-column.ts +5 -5
- package/src/utils/context-menu.ts +9 -6
- package/src/utils/convert.ts +9 -9
- package/src/utils/get-region-func-editor.ts +11 -11
- package/src/utils/get-region.ts +10 -12
- package/src/utils/macromolecule-column-widget.ts +9 -5
- package/src/utils/monomer-lib/library-file-manager/event-manager.ts +1 -1
- package/src/utils/multiple-sequence-alignment-ui.ts +6 -6
- package/src/utils/pepsea.ts +1 -0
- package/src/utils/poly-tool/transformation.ts +3 -3
- package/src/utils/save-as-fasta.ts +14 -15
- package/src/utils/sequence-to-mol.ts +4 -4
- package/src/viewers/web-logo-viewer.ts +95 -110
- package/src/widgets/bio-substructure-filter.ts +3 -3
- package/src/widgets/composition-analysis-widget.ts +26 -19
package/dist/895.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see 895.js.LICENSE.txt */
|
|
2
|
-
(self.webpackChunkbio=self.webpackChunkbio||[]).push([[895],{6814:(t,e,r)=>{"use strict";r.d(e,{cZ:()=>n,kK:()=>s}),r(7862);const s=t=>null==t;function n(t,e,r,s){if(r>t[t.length-1])return;const n=t.findIndex((t=>r<t));t.pop(),t.splice(n,0,r),e.pop(),e.splice(n,0,s)}},4895:(t,e,r)=>{"use strict";class s extends Float32Array{}var n=r(1040),o=r(1811),i=r(3979),h=r(5697);function a(t=!1,e="Assertion error."){if(!t)throw new Error(e)}var l=r(708);const u={[n.CF.Euclidean]:function(t,e){let r=0;const s=t.length;if(s!==e.length)throw new Error("The dimensionality of the vectors must match");for(let n=0;n<s;++n)r+=Math.pow(t[n]-e[n],2);return Math.sqrt(r)}},c={[n.W.Levenshtein]:o.T,[n.W.JaroWinkler]:i.H$,[n.W.Manhattan]:function(t,e){if(t.length!==e.length)return 1;{let r=0;for(let s=1;s<t.length;s++)r+=t[s]==e[s]?0:1;return r/t.length}},[n.W.Onehot]:function(t,e){return t===e?0:1}},f={[n.gk.Tanimoto]:h.KR,[n.gk.Dice]:h._h,[n.gk.Asymmetric]:h.yU,[n.gk.BraunBlanquet]:h.Dz,[n.gk.Cosine]:h.Zd,[n.gk.Kulczynski]:h.s,[n.gk.McConnaughey]:h.aW,[n.gk.RogotGoldberg]:h.MI,[n.gk.Russel]:h.fX,[n.gk.Sokal]:h.NB,[n.gk.Hamming]:h.UX,[n.gk.Euclidean]:h.WI},g={[n.gd.TanimotoIntArray]:h.FV},m={[n.Yc.Difference]:h.bX},p={[n.Qe.Vector]:{[n.CF.Euclidean]:u[n.CF.Euclidean]},[n.Qe.String]:{[n.W.Levenshtein]:c[n.W.Levenshtein],[n.W.JaroWinkler]:c[n.W.JaroWinkler],[n.W.Manhattan]:c[n.W.Manhattan],[n.W.Onehot]:c[n.W.Onehot]},[n.Qe.BitArray]:{[n.gk.Tanimoto]:f[n.gk.Tanimoto],[n.gk.Dice]:f[n.gk.Dice],[n.gk.Asymmetric]:f[n.gk.Asymmetric],[n.gk.BraunBlanquet]:f[n.gk.BraunBlanquet],[n.gk.Cosine]:f[n.gk.Cosine],[n.gk.Kulczynski]:f[n.gk.Kulczynski],[n.gk.McConnaughey]:f[n.gk.McConnaughey],[n.gk.RogotGoldberg]:f[n.gk.RogotGoldberg],[n.gk.Russel]:f[n.gk.Russel],[n.gk.Sokal]:f[n.gk.Sokal]},[n.Qe.MacroMolecule]:{[l.U.HAMMING]:l.o[l.U.HAMMING],[l.U.LEVENSHTEIN]:l.o[l.U.LEVENSHTEIN],[l.U.NEEDLEMANN_WUNSCH]:l.o[l.U.NEEDLEMANN_WUNSCH],[l.U.MONOMER_CHEMICAL_DISTANCE]:l.o[l.U.MONOMER_CHEMICAL_DISTANCE]},[n.Qe.Number]:{[n.Yc.Difference]:m[n.Yc.Difference]},[n.Qe.IntArray]:{[n.gd.TanimotoIntArray]:g[n.gd.TanimotoIntArray]}},w=Object.keys(p).reduce(((t,e)=>{for(const r of Object.keys(p[e]))t[r]=e;return t}),{});class d{method;dataType;constructor(t){this.method=t,this.dataType=w[t]}getMeasure(t){const e=p;if(!e.hasOwnProperty(this.dataType)||!e[this.dataType].hasOwnProperty(this.method))throw new Error(`Unknown measure ${this.method} for data type ${this.dataType}`);return r=this.method,w[r]==n.Qe.MacroMolecule.toString()||function(t){return w[t]==n.Qe.Number.toString()}(this.method)?e[this.dataType][this.method](t):e[this.dataType][this.method];var r}static getMetricByDataType(t){return Object.keys(p[t])}static get availableMeasures(){return Object.keys(p)}}r(6814);var y=r(7862);class b{_workers;_workerCount;_terminateOnComplete;constructor(t=!0,e=!0){const s=navigator.hardwareConcurrency;this._workerCount=t?Math.max(s-2,1):1,this._workers=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(65),r.b)))),this._terminateOnComplete=e}async calc(t,e,r=!0,s){return await this.calcMulti([t],[e],r,[s??{}],[1],y.y.MANHATTAN)}async calcMulti(t,e,r=!0,s=[{}],n=[1],o=y.y.MANHATTAN){if(t.length<1)throw new Error("values must contain at least one array");if(e.length!==t.length||s.length!==t.length||n.length!==t.length)throw new Error("values, fnNames, weights and opts must have the same length");return new Promise((async(i,h)=>{try{const h=t[0].length,a=new Array(this._workerCount),l=h*(h-1)/2;this._workerCount=Math.min(this._workerCount,l);const u=l/this._workerCount,c=new Float32Array(l);let f=0,g=1,m=0,p=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const i=Math.floor(r*u),w=r===this._workerCount-1?l:Math.floor((r+1)*u),d=f,y=g;r!==this._workerCount-1&&(f=h-2-Math.floor(Math.sqrt(-8*w+4*h*(h-1)-7)/2-.5),g=w-h*f+Math.floor((f+1)*(f+2)/2)),this._workers[r].postMessage({values:t,fnNames:e,startRow:d,startCol:y,chunckSize:w-i,opts:s,weights:n,aggregationMethod:o}),a[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:s,distanceMatrixData:n,min:o,max:h}})=>{this._terminateOnComplete&&setTimeout((()=>this._workers[r].terminate())),s?e(s):(c.set(n,i),o<m&&(m=o),h>p&&(p=h),t())}}))}await Promise.all(a),r&&c.forEach(((t,e)=>{c[e]=(t-m)/(p-m)})),i(c)}catch(t){h(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}function M(t,e){return Math.floor(e()*t)}function x(t){return t()}function v(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function E(t){return v(t).map(((t,e)=>e))}function S(t,e){return v(t).map((()=>e))}function k(t){return S(t,0)}function N(t){return function(t){return t.reduce(((t,e)=>t+e))}(t)/t.length}function A(t){let e=0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e}function R(t,e,r){const s=k(t);for(let n=0;n<t;n++){let t=!0;for(;t;){const o=M(e,r);let i=!1;for(let t=0;t<n;t++)if(o===s[t]){i=!0;break}i||(t=!1),s[n]=o}}return s}function F(t,e,r){const s=[];let n=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let o=0;o<e;o++){const e=[];for(let s=0;s<r;s++)e.push(t[n]),n+=1;s.push(e)}return s}function C(t,e){const r=r=>v(t).map((()=>S(e,r))),s=[];return s.push(r(-1)),s.push(r(1/0)),s.push(r(0)),s}function z(t,e,r){const s=k(t);for(let n=0;n<t;n++){let t=!0,o=0;for(;t;){o=M(e,r);let i=!1;for(let t=0;t<n;t++)if(o===s[t]){i=!0;break}i||(t=!1)}s[n]=o}return s}function I(t,e,r,s,n){e=Math.floor(e);const o=t[0][e];if(r>=t[1][e][0])return 0;for(let t=0;t<o.length;t++)if(s===o[t])return 0;return T(t,e,r,s,n)}function T(t,e,r,s,n){const o=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,o[0]=s,h[0]=n;let a=0,l=0;for(;;){const e=2*a+1,s=e+1,n=t[0][0].length;if(e>=n)break;if(s>=n){if(!(i[e]>r))break;l=e}else if(i[e]>=i[s]){if(!(r<i[e]))break;l=e}else{if(!(r<i[s]))break;l=s}i[a]=i[l],o[a]=o[l],h[a]=h[l],a=l}return i[a]=r,o[a]=s,h[a]=n,1}function D(t,e,r,s,n){const o=C(e,s);for(let s=0;s<e;s++)for(let e=0;e<r;e++){if(t[0][s][e]<0)continue;const r=t[0][s][e],i=t[2][s][e],h=x(n);I(o,s,h,r,i),I(o,r,h,s,i),t[2][s][e]=0}return o}function V(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const s=e[t],n=r[t];for(let t=0;t<s.length-1;t++){const e=s.length-t-1,r=n.length-t-1,o=s[0];s[0]=s[e],s[e]=o;const i=n[0];n[0]=n[r],n[r]=i,O(n,s,r,0)}}return{indices:e,weights:r}}function O(t,e,r,s){for(;2*s+1<r;){const n=2*s+1,o=n+1;let i=s;if(t[i]<t[n]&&(i=n),o<r&&t[i]<t[o]&&(i=o),i===s)break;{const r=t[s];t[s]=t[i],t[i]=r;const n=e[s];e[s]=e[i],e[i]=n,s=i}}}function q(t,e){const r=t[0][e],s=t[1][e],n=t[2][e];let o=1/0,i=-1;for(let t=0;t>r.length;t++)1===n[t]&&s[t]<o&&(o=s[t],i=t);return i>=0?(n[i]=0,Math.floor(r[i])):-1}class P{entries=new Map;nRows=0;nCols=0;constructor(t,e,r,s){if(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 n=t[s],o=e[s];this.checkDims(n,o);const i=this.makeKey(n,o);this.entries.set(i,{value:r[s],row:n,col:o})}}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){const s=this.makeKey(t,e);return this.entries.has(s)?this.entries.get(s).value:r}getAll(t=!0){const e=new Array(this.entries.size).fill(null);let r=0;return this.entries.forEach((t=>{e[r++]=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){const e=new Float32Array(this.entries.size);let r=0;this.entries.forEach((s=>{e[r++]=t(s.value,s.row,s.col)}));const s=[this.nRows,this.nCols];return new P(this.getRows(),this.getCols(),e,s)}toArray(){const t=v(this.nRows).map((()=>k(this.nCols)));return this.entries.forEach((e=>{t[e.row][e.col]=e.value})),t}}function j(t){const e=t.getRows(),r=t.getCols(),s=t.getValues(),n=r.length,o=new Int32Array(n),i=new Int32Array(n),h=new Float32Array(n);o.set(e),i.set(r),h.set(s);const a=[t.nCols,t.nRows];return new P(i,o,h,a)}function L(t,e){return X(t,e,((t,e)=>t*e))}function _(t,e){return X(t,e,((t,e)=>t+e))}function $(t,e){return X(t,e,((t,e)=>t-e))}function W(t,e){return t.map((t=>t*e))}function U(t){const e=new Set,r=t.getValues(),s=t.getRows(),n=t.getCols();for(let t=0;t<r.length;t++)0===r[t]&&e.add(t);const o=(t,r)=>!e.has(r),i=r.filter(o),h=s.filter(o),a=n.filter(o);return new P(h,a,i,t.getDims())}function Y(t,e="l2"){const r=G[e],s=new Map;t.forEach(((t,e,r)=>{const n=s.get(e)||[];n.push(r),s.set(e,n)}));const n=new P([],[],[],t.getDims());for(const e of s.keys()){const o=s.get(e).sort(),i=r(o.map((r=>t.get(e,r))));for(let t=0;t<i.length;t++)n.set(e,o[t],i[t])}return n}const G={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 X(t,e,r){const s=new Set,n=[],o=[],i=[],h=(s,h)=>{n.push(s),o.push(h);const a=r(t.get(s,h),e.get(s,h));i.push(a)},a=t.getValues(),l=t.getRows(),u=t.getCols();for(let t=0;t<a.length;t++){const e=l[t],r=u[t],n=`${e}:${r}`;s.add(n),h(e,r)}const c=e.getValues(),f=e.getRows(),g=e.getCols();for(let t=0;t<c.length;t++){const e=f[t],r=g[t],n=`${e}:${r}`;s.has(n)||h(e,r)}const m=[t.nRows,t.nCols];return new P(n,o,i,m)}function K(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=[],n=[];let o=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==o&&(o=i,n.push(t)),r.push(h),s.push(a)}return{indices:r,values:s,indptr:n}}class Q{hyperplanes;offsets;children;indices;constructor(t,e,r,s){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=s}}function B(t,e,r,s){const n=Math.max(10,e),o=E(r).map(((e,r)=>function(t,e=30,r,s){return H(t,E(t.length),e,r,s)}(t,n,r,s))),i=o.map((t=>function(t,e){const r=Z(t),s=tt(t),n=E(r).map((()=>t.hyperplane?1:0)),o=k(r),i=E(r).map((()=>[-1,-1])),h=E(s).map((()=>E(e).map((()=>-1))));return J(t,n,o,i,h,0,0),new Q(n,o,i,h)}(t,n)));return i}function H(t,e,r=30,s,n){if(e.length>r){const o=function(t,e,r){const s=M(e.length,r);let n=M(e.length,r);n+=s===n?1:0,n%=e.length;const o=e[s],i=e[n];let h=0,a=0;a=t[o]-t[i],h-=a*(t[o]+t[i])/2;let l=0,u=0;const c=k(e.length);for(let s=0;s<e.length;s++){let n=h;n+=a*t[e[s]],0===n?(c[s]=M(2,r),0===c[s]?l+=1:u+=1):n>0?(c[s]=0,l+=1):(c[s]=1,u+=1)}const f=k(l),g=k(u);l=0,u=0;for(let t=0;t<c.length;t++)0===c[t]?(f[l]=e[t],l+=1):(g[u]=e[t],u+=1);return{indicesLeft:f,indicesRight:g,hyperplane:a,offset:h}}(t,e,n),{indicesLeft:i,indicesRight:h,hyperplane:a,offset:l}=o;return{leftChild:H(t,i,r,s+1,n),rightChild:H(t,h,r,s+1,n),isLeaf:!1,hyperplane:a,offset:l}}return{indices:e,isLeaf:!0}}function J(t,e,r,s,n,o,i){if(t.isLeaf)return s[o][0]=-i,n[i].splice(0,t.indices.length,...t.indices),{nodeNum:o,leafNum:i+=1};{e[o]=t.hyperplane,r[o]=t.offset,s[o][0]=o+1;const h=o;let a=J(t.leftChild,e,r,s,n,o+1,i);return o=a.nodeNum,i=a.leafNum,s[h][1]=o+1,a=J(t.rightChild,e,r,s,n,o+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function Z(t){return t.isLeaf?1:1+Z(t.leftChild)+Z(t.rightChild)}function tt(t){return t.isLeaf?1:tt(t.leftChild)+tt(t.rightChild)}function et(t,e,r,s){let n=e;return n+=t*r,0===n?M(2,s):n>0?0:1}function rt(t,e,r){let s=0;for(;e.children[s][0]>0;)s=0===et(e.hyperplanes[s],e.offsets[s],t,r)?e.children[s][0]:e.children[s][1];const n=-1*e.children[s][0];return e.indices[n]}const st=Object.prototype.toString;function nt(t){return st.call(t).endsWith("Array]")}function ot(t,e,r){let s=0;const n=r(e);for(let e=0;e<t.x.length;e++)s+=Math.abs(t.y[e]-n(t.x[e]));return s}const it=Object.prototype.toString;function ht(t){return it.call(t).endsWith("Array]")}const at=Object.prototype.toString;function lt(t){return at.call(t).endsWith("Array]")}const ut=Object.prototype.toString;const ct=Object.prototype.toString;function ft(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!lt(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(!lt(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!ct.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=r.fromIndex,n=void 0===s?0:s,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[n],a=n+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),n=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!ut.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=r.fromIndex,n=void 0===s?0:s,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[n],a=n+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(s===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var o=r.min,i=void 0===o?r.autoMinMax?s:0:o,h=r.max,a=void 0===h?r.autoMinMax?n:1:h;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-i)/(n-s),u=0;u<t.length;u++)e[u]=(t[u]-s)*l+i;return e}const gt=" ".repeat(2),mt=" ".repeat(4);function pt(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:n=8,padMinus:o="auto"}=e;return`${t.constructor.name} {\n${gt}[\n${mt}${function(t,e,r,s,n){const{rows:o,columns:i}=t,h=Math.min(o,e),a=Math.min(i,r),l=[];if("auto"===n){n=!1;t:for(let e=0;e<h;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){n=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let o=0;o<a;o++)r.push(wt(t.get(e,o),s,n));l.push(`${r.join(" ")}`)}return a!==i&&(l[l.length-1]+=` ... ${i-r} more columns`),h!==o&&l.push(`... ${o-e} more rows`),l.join(`\n${mt}`)}(t,r,s,n,o)}\n${gt}]\n${gt}rows: ${t.rows}\n${gt}columns: ${t.columns}\n}`}function wt(t,e,r){return(t>=0&&r?` ${dt(t,e-1)}`:dt(t,e)).padEnd(e)}function dt(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 n=t.toExponential(e);return n.length>e&&(n=t.toExponential(Math.max(0,e-(n.length-e)))),n.slice(0)}function yt(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 bt(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 Mt(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 xt(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 vt(t,e,r,s,n){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(St("startRow",e),St("endRow",r),St("startColumn",s),St("endColumn",n),e>r||s>n||e<0||e>=t.rows||r<0||r>=t.rows||s<0||s>=t.columns||n<0||n>=t.columns)throw new RangeError("Submatrix indices are out of range")}function Et(t,e=0){let r=[];for(let s=0;s<t;s++)r.push(e);return r}function St(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function kt(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class Nt{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new Rt(t,e);for(let n=0;n<t;n++)for(let t=0;t<e;t++)s.set(n,t,r[n*e+t]);return s}static rowVector(t){let e=new Rt(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 Rt(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 Rt(t,e)}static ones(t,e){return new Rt(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 n=new Rt(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)n.set(r,t,s());return n}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:s=0,max:n=1e3,random:o=Math.random}=r;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(n))throw new TypeError("max must be an integer");if(s>=n)throw new RangeError("min must be smaller than max");let i=n-s,h=new Rt(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(o()*i);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let s=Math.min(t,e),n=this.zeros(t,e);for(let t=0;t<s;t++)n.set(t,t,r);return n}static diag(t,e,r){let s=t.length;void 0===e&&(e=s),void 0===r&&(r=e);let n=Math.min(s,e,r),o=this.zeros(e,r);for(let e=0;e<n;e++)o.set(e,e,t[e]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,n=new Rt(r,s);for(let o=0;o<r;o++)for(let r=0;r<s;r++)n.set(o,r,Math.min(t.get(o,r),e.get(o,r)));return n}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,n=new this(r,s);for(let o=0;o<r;o++)for(let r=0;r<s;r++)n.set(o,r,Math.max(t.get(o,r),e.get(o,r)));return n}static checkMatrix(t){return Nt.isMatrix(t)?t:new Rt(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,s=!0,n=!1;for(;t<this.rows&&s;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(s=!1,n=!0);t++}return s}isReducedEchelonForm(){let t=0,e=0,r=-1,s=!0,n=!1;for(;t<this.rows&&s;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(s=!1,n=!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 n=e;n<t.rows;n++)t.get(n,r)>t.get(s,r)&&(s=n);if(0===t.get(s,r))r++;else{t.swapRows(e,s);let n=t.get(e,r);for(let s=r;s<t.columns;s++)t.set(e,s,t.get(e,s)/n);for(let s=e+1;s<t.rows;s++){let n=t.get(s,r)/t.get(e,r);t.set(s,r,0);for(let o=r+1;o<t.columns;o++)t.set(s,o,t.get(s,o)-t.get(e,o)*n)}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 n=0,o=!1;for(;n<r&&!1===o;)1===t.get(s,n)?o=!0:n++;for(let r=0;r<s;r++){let o=t.get(r,n);for(let i=n;i<e;i++){let e=t.get(r,i)-o*t.get(s,i);t.set(r,i,e)}}s--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let s=new Rt(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){yt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Rt.rowVector(this.getRow(t))}setRow(t,e){yt(this,t),e=Mt(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){yt(this,t),yt(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){bt(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Rt.columnVector(this.getColumn(t))}setColumn(t,e){bt(this,t),e=xt(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){bt(this,t),bt(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=Mt(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=Mt(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=Mt(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=Mt(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=xt(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=xt(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=xt(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=xt(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){yt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){bt(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(){kt(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(){kt(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(yt(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){yt(this,t),kt(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(yt(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){yt(this,t),kt(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(bt(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){bt(this,t),kt(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(bt(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){bt(this,t),kt(this);let e=this.get(0,t),r=[0,t];for(let s=1;s<this.rows;s++)this.get(s,t)<e&&(e=this.get(s,t),r[0]=s);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){Nt.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=Rt.checkMatrix(t);let e=this.rows,r=this.columns,s=t.columns,n=new Rt(e,s),o=new Float64Array(r);for(let i=0;i<s;i++){for(let e=0;e<r;e++)o[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*o[s];n.set(t,i,e)}}return n}strassen2x2(t){t=Rt.checkMatrix(t);let e=new Rt(2,2);const r=this.get(0,0),s=t.get(0,0),n=this.get(0,1),o=t.get(0,1),i=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(s+l),c=(i+a)*s,f=r*(o-l),g=a*(h-s),m=(r+n)*l,p=u+g-m+(n-a)*(h+l),w=f+m,d=c+g,y=u-c+f+(i-r)*(s+o);return e.set(0,0,p),e.set(0,1,w),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=Rt.checkMatrix(t);let e=new Rt(3,3);const r=this.get(0,0),s=this.get(0,1),n=this.get(0,2),o=this.get(1,0),i=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=t.get(0,1),g=t.get(0,2),m=t.get(1,0),p=t.get(1,1),w=t.get(1,2),d=t.get(2,0),y=t.get(2,1),b=t.get(2,2),M=(r-o)*(-f+p),x=(-r+o+i)*(c-f+p),v=(o+i)*(-c+f),E=r*c,S=(-r+a+l)*(c-g+w),k=(-r+a)*(g-w),N=(a+l)*(-c+g),A=(-n+l+u)*(p+d-y),R=(n-u)*(p-y),F=n*d,C=(l+u)*(-d+y),z=(-n+i+h)*(w+d-b),I=(n-h)*(w-b),T=(i+h)*(-d+b),D=E+F+s*m,V=(r+s+n-o-i-l-u)*p+x+v+E+A+F+C,O=E+S+N+(r+s+n-i-h-a-l)*w+F+z+T,q=M+i*(-c+f+m-p-w-d+b)+x+E+F+z+I,P=M+x+v+E+h*y,j=F+z+I+T+o*g,L=E+S+k+l*(-c+g+m-p-w-d+y)+A+R+F,_=A+R+F+C+a*f,$=E+S+k+N+u*b;return e.set(0,0,D),e.set(0,1,V),e.set(0,2,O),e.set(1,0,q),e.set(1,1,P),e.set(1,2,j),e.set(2,0,L),e.set(2,1,_),e.set(2,2,$),e}mmulStrassen(t){t=Rt.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,n=t.rows,o=t.columns;function i(t,e,r){let s=t.rows,n=t.columns;if(s===e&&n===r)return t;{let s=Nt.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==n&&console.warn(`Multiplying ${r} x ${s} and ${n} x ${o} matrix: dimensions do not match.`);let h=Math.max(r,n),a=Math.max(s,o);return e=i(e,h,a),function t(e,r,s,n){if(s<=512||n<=512)return e.mmul(r);s%2==1&&n%2==1?(e=i(e,s+1,n+1),r=i(r,s+1,n+1)):s%2==1?(e=i(e,s+1,n),r=i(r,s+1,n)):n%2==1&&(e=i(e,s,n+1),r=i(r,s,n+1));let o=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,o-1,0,h-1),l=r.subMatrix(0,o-1,0,h-1),u=e.subMatrix(0,o-1,h,e.columns-1),c=r.subMatrix(0,o-1,h,r.columns-1),f=e.subMatrix(o,e.rows-1,0,h-1),g=r.subMatrix(o,r.rows-1,0,h-1),m=e.subMatrix(o,e.rows-1,h,e.columns-1),p=r.subMatrix(o,r.rows-1,h,r.columns-1),w=t(Nt.add(a,m),Nt.add(l,p),o,h),d=t(Nt.add(f,m),l,o,h),y=t(a,Nt.sub(c,p),o,h),b=t(m,Nt.sub(g,l),o,h),M=t(Nt.add(a,u),p,o,h),x=t(Nt.sub(f,a),Nt.add(l,c),o,h),v=t(Nt.sub(u,m),Nt.add(g,p),o,h),E=Nt.add(w,b);E.sub(M),E.add(v);let S=Nt.add(y,M),k=Nt.add(d,b),N=Nt.sub(w,d);N.add(y),N.add(x);let A=Nt.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(S,E.rows,0),A=A.setSubMatrix(k,0,E.columns),A=A.setSubMatrix(N,E.rows,E.columns),A.subMatrix(0,s-1,0,n-1)}(e,t=i(t,h,a),h,a)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new Rt(this.rows,this.columns);for(let t=0;t<this.rows;t++){const n=this.getRow(t);n.length>0&&ft(n,{min:e,max:r,output:n}),s.setRow(t,n)}return s}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new Rt(this.rows,this.columns);for(let t=0;t<this.columns;t++){const n=this.getColumn(t);n.length&&ft(n,{min:e,max:r,output:n}),s.setColumn(t,n)}return s}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Rt.checkMatrix(t);let e=this.rows,r=this.columns,s=t.rows,n=t.columns,o=new Rt(e*s,r*n);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<n;h++)o.set(s*i+r,n*e+h,this.get(i,e)*t.get(r,h));return o}kroneckerSum(t){if(t=Rt.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(Rt.eye(r,r)),n=Rt.eye(e,e).kroneckerProduct(t);return s.add(n)}transpose(){let t=new Rt(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=At){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=At){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,s){vt(this,t,e,r,s);let n=new Rt(e-t+1,s-r+1);for(let o=t;o<=e;o++)for(let e=r;e<=s;e++)n.set(o-t,e-r,this.get(o,e));return n}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 Rt(t.length,r-e+1);for(let n=0;n<t.length;n++)for(let o=e;o<=r;o++){if(t[n]<0||t[n]>=this.rows)throw new RangeError(`Row index out of range: ${t[n]}`);s.set(n,o-e,this.get(t[n],o))}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 Rt(r-e+1,t.length);for(let n=0;n<t.length;n++)for(let o=e;o<=r;o++){if(t[n]<0||t[n]>=this.columns)throw new RangeError(`Column index out of range: ${t[n]}`);s.set(o-e,n,this.get(o,t[n]))}return s}setSubMatrix(t,e,r){if((t=Rt.checkMatrix(t)).isEmpty())return this;vt(this,e,e+t.rows-1,r,r+t.columns-1);for(let s=0;s<t.rows;s++)for(let n=0;n<t.columns;n++)this.set(e+s,r+n,t.get(s,n));return this}selection(t,e){!function(t,e){if(!ht(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")}(this,t),function(t,e){if(!ht(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")}(this,e);let r=new Rt(t.length,e.length);for(let s=0;s<t.length;s++){let n=t[s];for(let t=0;t<e.length;t++){let o=e[t];r.set(s,t,this.get(n,o))}}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(){let t=new Rt(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=Et(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=Et(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=Et(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=Et(t.columns,1);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[s]*=t.get(r,s);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)e*=t.get(r,s);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:s=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!ht(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,n=t.columns,o=[];for(let i=0;i<s;i++){let s=0,h=0,a=0;for(let e=0;e<n;e++)a=t.get(i,e)-r[i],s+=a,h+=a*a;e?o.push((h-s*s/n)/(n-1)):o.push((h-s*s/n)/n)}return o}(this,r,s);case"column":if(!ht(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,n=t.columns,o=[];for(let i=0;i<n;i++){let n=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(e,i)-r[i],n+=a,h+=a*a;e?o.push((h-n*n/s)/(s-1)):o.push((h-n*n/s)/s)}return o}(this,r,s);case void 0:if("number"!=typeof s)throw new TypeError("mean must be a number");return function(t,e,r){const s=t.rows,n=t.columns,o=s*n;let i=0,h=0,a=0;for(let e=0;e<s;e++)for(let s=0;s<n;s++)a=t.get(e,s)-r,i+=a,h+=a*a;return e?(h-i*i/o)/(o-1):(h-i*i/o)/o}(this,r,s);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!ht(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(!ht(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e[s])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let s=0;for(let e=0;e<t.columns;e++)s+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(s))}return e}(this);else if(!ht(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let s=0;for(let e=0;e<t.rows;e++)s+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(s))}return e}(this);else if(!ht(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 n=0;n<t.rows;n++)r+=Math.pow(t.get(n,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 pt(this,t)}}function At(t,e){return t-e}Nt.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Nt.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return pt(this)}),Nt.random=Nt.rand,Nt.randomInt=Nt.randInt,Nt.diagonal=Nt.diag,Nt.prototype.diagonal=Nt.prototype.diag,Nt.identity=Nt.eye,Nt.prototype.negate=Nt.prototype.neg,Nt.prototype.tensorProduct=Nt.prototype.kroneckerProduct;class Rt extends Nt{constructor(t,e){if(super(),Rt.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!ht(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(!r[s].every((t=>"number"==typeof t)))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 yt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),yt(this,t,!0),e=Float64Array.from(Mt(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){bt(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),bt(this,t,!0),e=xt(this,e);for(let r=0;r<this.rows;r++){const s=new Float64Array(this.columns+1);let n=0;for(;n<t;n++)s[n]=this.data[r][n];for(s[n++]=e[r];n<this.columns+1;n++)s[n]=this.data[r][n-1];this.data[r]=s}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(Nt,Rt);class Ft extends Nt{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 Ct{constructor(t){let e,r,s,n,o,i,h,a,l,u=(t=Ft.checkMatrix(t)).clone(),c=u.rows,f=u.columns,g=new Float64Array(c),m=1;for(e=0;e<c;e++)g[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),o=0,s=0;s<l;s++)o+=u.get(e,s)*a[s];a[e]-=o,u.set(e,r,a[e])}for(n=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[n])&&(n=e);if(n!==r){for(s=0;s<f;s++)i=u.get(n,s),u.set(n,s,u.get(r,s)),u.set(r,s,i);h=g[n],g[n]=g[r],g[r]=h,m=-m}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=g,this.pivotSign=m}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=Rt.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,n,o=t.columns,i=t.subMatrixRow(this.pivotVector,0,o-1),h=e.columns;for(n=0;n<h;n++)for(r=n+1;r<h;r++)for(s=0;s<o;s++)i.set(r,s,i.get(r,s)-i.get(n,s)*e.get(r,n));for(n=h-1;n>=0;n--){for(s=0;s<o;s++)i.set(n,s,i.get(n,s)/e.get(n,n));for(r=0;r<n;r++)for(s=0;s<o;s++)i.set(r,s,i.get(r,s)-i.get(n,s)*e.get(r,n))}return i}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let s=0;s<r;s++)e*=t.get(s,s);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new Rt(e,r);for(let n=0;n<e;n++)for(let e=0;e<r;e++)n>e?s.set(n,e,t.get(n,e)):n===e?s.set(n,e,1):s.set(n,e,0);return s}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new Rt(e,r);for(let n=0;n<e;n++)for(let e=0;e<r;e++)n<=e?s.set(n,e,t.get(n,e)):s.set(n,e,0);return s}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function zt(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 It{constructor(t){let e,r,s,n,o=(t=Ft.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<i;e++)t=zt(t,o.get(e,s));if(0!==t){for(o.get(s,s)<0&&(t=-t),e=s;e<i;e++)o.set(e,s,o.get(e,s)/t);for(o.set(s,s,o.get(s,s)+1),r=s+1;r<h;r++){for(n=0,e=s;e<i;e++)n+=o.get(e,s)*o.get(e,r);for(n=-n/o.get(s,s),e=s;e<i;e++)o.set(e,r,o.get(e,r)+n*o.get(e,s))}}a[s]=-t}this.QR=o,this.Rdiag=a}solve(t){t=Rt.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,n,o,i,h=t.columns,a=t.clone(),l=e.columns;for(o=0;o<l;o++)for(n=0;n<h;n++){for(i=0,s=o;s<r;s++)i+=e.get(s,o)*a.get(s,n);for(i=-i/e.get(o,o),s=o;s<r;s++)a.set(s,n,a.get(s,n)+i*e.get(s,o))}for(o=l-1;o>=0;o--){for(n=0;n<h;n++)a.set(o,n,a.get(o,n)/this.Rdiag[o]);for(s=0;s<o;s++)for(n=0;n<h;n++)a.set(s,n,a.get(s,n)-a.get(o,n)*e.get(s,o))}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,n=new Rt(s,s);for(t=0;t<s;t++)for(e=0;e<s;e++)t<e?n.set(t,e,r.get(t,e)):t===e?n.set(t,e,this.Rdiag[t]):n.set(t,e,0);return n}get orthogonalMatrix(){let t,e,r,s,n=this.QR,o=n.rows,i=n.columns,h=new Rt(o,i);for(r=i-1;r>=0;r--){for(t=0;t<o;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<i;e++)if(0!==n.get(r,r)){for(s=0,t=r;t<o;t++)s+=n.get(t,r)*h.get(t,e);for(s=-s/n.get(r,r),t=r;t<o;t++)h.set(t,e,h.get(t,e)+s*n.get(t,r))}}return h}}class Tt{constructor(t,e={}){if((t=Ft.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:n=!0,computeRightSingularVectors:o=!0,autoTranspose:i=!1}=e;let h,a=Boolean(n),l=Boolean(o),u=!1;if(r<s)if(i){h=t.transpose(),r=h.rows,s=h.columns,u=!0;let e=a;a=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let c=Math.min(r,s),f=Math.min(r+1,s),g=new Float64Array(f),m=new Rt(r,c),p=new Rt(s,s),w=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){g[t]=0;for(let e=t;e<r;e++)g[t]=zt(g[t],h.get(e,t));if(0!==g[t]){h.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/g[t]);h.set(t,t,h.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<s;e++){if(t<b&&0!==g[t]){let s=0;for(let n=t;n<r;n++)s+=h.get(n,t)*h.get(n,e);s=-s/h.get(t,t);for(let n=t;n<r;n++)h.set(n,e,h.get(n,e)+s*h.get(n,t))}w[e]=h.get(t,e)}if(a&&t<b)for(let e=t;e<r;e++)m.set(e,t,h.get(e,t));if(t<M){w[t]=0;for(let e=t+1;e<s;e++)w[t]=zt(w[t],w[e]);if(0!==w[t]){w[t+1]<0&&(w[t]=0-w[t]);for(let e=t+1;e<s;e++)w[e]/=w[t];w[t+1]+=1}if(w[t]=-w[t],t+1<r&&0!==w[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]+=w[r]*h.get(e,r);for(let e=t+1;e<s;e++){let s=-w[e]/w[t+1];for(let n=t+1;n<r;n++)h.set(n,e,h.get(n,e)+s*d[n])}}if(l)for(let e=t+1;e<s;e++)p.set(e,t,w[e])}}let v=Math.min(s,r+1);if(b<s&&(g[b]=h.get(b,b)),r<v&&(g[v-1]=0),M+1<v&&(w[M]=h.get(M,v-1)),w[v-1]=0,a){for(let t=b;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=b-1;t>=0;t--)if(0!==g[t]){for(let e=t+1;e<c;e++){let s=0;for(let n=t;n<r;n++)s+=m.get(n,t)*m.get(n,e);s=-s/m.get(t,t);for(let n=t;n<r;n++)m.set(n,e,m.get(n,e)+s*m.get(n,t))}for(let e=t;e<r;e++)m.set(e,t,-m.get(e,t));m.set(t,t,1+m.get(t,t));for(let e=0;e<t-1;e++)m.set(e,t,0)}else{for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}}if(l)for(let t=s-1;t>=0;t--){if(t<M&&0!==w[t])for(let e=t+1;e<s;e++){let r=0;for(let n=t+1;n<s;n++)r+=p.get(n,t)*p.get(n,e);r=-r/p.get(t+1,t);for(let n=t+1;n<s;n++)p.set(n,e,p.get(n,e)+r*p.get(n,t))}for(let e=0;e<s;e++)p.set(e,t,0);p.set(t,t,1)}let E=v-1,S=0,k=Number.EPSILON;for(;v>0;){let t,e;for(t=v-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+k*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(w[t])<=e||Number.isNaN(w[t])){w[t]=0;break}}if(t===v-2)e=4;else{let r;for(r=v-1;r>=t&&r!==t;r--){let e=(r!==v?Math.abs(w[r]):0)+(r!==t+1?Math.abs(w[r-1]):0);if(Math.abs(g[r])<=k*e){g[r]=0;break}}r===t?e=3:r===v-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=w[v-2];w[v-2]=0;for(let r=v-2;r>=t;r--){let n=zt(g[r],e),o=g[r]/n,i=e/n;if(g[r]=n,r!==t&&(e=-i*w[r-1],w[r-1]=o*w[r-1]),l)for(let t=0;t<s;t++)n=o*p.get(t,r)+i*p.get(t,v-1),p.set(t,v-1,-i*p.get(t,r)+o*p.get(t,v-1)),p.set(t,r,n)}break}case 2:{let e=w[t-1];w[t-1]=0;for(let s=t;s<v;s++){let n=zt(g[s],e),o=g[s]/n,i=e/n;if(g[s]=n,e=-i*w[s],w[s]=o*w[s],a)for(let e=0;e<r;e++)n=o*m.get(e,s)+i*m.get(e,t-1),m.set(e,t-1,-i*m.get(e,s)+o*m.get(e,t-1)),m.set(e,s,n)}break}case 3:{const e=Math.max(Math.abs(g[v-1]),Math.abs(g[v-2]),Math.abs(w[v-2]),Math.abs(g[t]),Math.abs(w[t])),n=g[v-1]/e,o=g[v-2]/e,i=w[v-2]/e,h=g[t]/e,u=w[t]/e,c=((o+n)*(o-n)+i*i)/2,f=n*i*(n*i);let d=0;0===c&&0===f||(d=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),d=f/(c+d));let y=(h+n)*(h-n)+d,b=h*u;for(let e=t;e<v-1;e++){let n=zt(y,b);0===n&&(n=Number.MIN_VALUE);let o=y/n,i=b/n;if(e!==t&&(w[e-1]=n),y=o*g[e]+i*w[e],w[e]=o*w[e]-i*g[e],b=i*g[e+1],g[e+1]=o*g[e+1],l)for(let t=0;t<s;t++)n=o*p.get(t,e)+i*p.get(t,e+1),p.set(t,e+1,-i*p.get(t,e)+o*p.get(t,e+1)),p.set(t,e,n);if(n=zt(y,b),0===n&&(n=Number.MIN_VALUE),o=y/n,i=b/n,g[e]=n,y=o*w[e]+i*g[e+1],g[e+1]=-i*w[e]+o*g[e+1],b=i*w[e+1],w[e+1]=o*w[e+1],a&&e<r-1)for(let t=0;t<r;t++)n=o*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+o*m.get(t,e+1)),m.set(t,e,n)}w[v-2]=y,S+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(g[t]>=g[t+1]);){let e=g[t];if(g[t]=g[t+1],g[t+1]=e,l&&t<s-1)for(let r=0;r<s;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(a&&t<r-1)for(let s=0;s<r;s++)e=m.get(s,t+1),m.set(s,t+1,m.get(s,t)),m.set(s,t,e);t++}S=0,v--}}if(u){let t=p;p=m,m=t}this.m=r,this.n=s,this.s=g,this.U=m,this.V=p}solve(t){let e=t,r=this.threshold,s=this.s.length,n=Rt.zeros(s,s);for(let t=0;t<s;t++)Math.abs(this.s[t])<=r?n.set(t,t,0):n.set(t,t,1/this.s[t]);let o=this.U,i=this.rightSingularVectors,h=i.mmul(n),a=i.rows,l=o.rows,u=Rt.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let n=0;n<s;n++)r+=h.get(t,n)*o.get(e,n);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(Rt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,s=t.columns,n=new Rt(r,this.s.length);for(let o=0;o<r;o++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&n.set(o,r,t.get(o,r)/this.s[r]);let o=this.U,i=o.rows,h=o.columns,a=new Rt(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let s=0;s<h;s++)r+=n.get(t,s)*o.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,n=r.length;s<n;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 Rt.diag(this.s)}}function Dt(t,e,r,s,n){let o=r*s*s,i=Rt.eye(e.length,e.length,o);const h=n(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,n){const o=r.length,i=t.x.length;let h=new Array(o);for(let a=0;a<o;a++){h[a]=new Array(i);let o=r.slice();o[a]+=s;let l=n(o);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new Rt(h)}(t,a,e,s,n),u=function(t,e){const r=t.x.length;let s=new Array(r);for(let n=0;n<r;n++)s[n]=[t.y[n]-e[n]];return new Rt(s)}(t,a),c=function(t,e=!1){return t=Ft.checkMatrix(t),e?new Tt(t).inverse():function(t,e,r=!1){return t=Ft.checkMatrix(t),e=Ft.checkMatrix(e),r?new Tt(t).solve(e):t.isSquare()?new Ct(t).solve(e):new It(t).solve(e)}(t,Rt.eye(t.rows))}(i.add(l.mmul(l.transpose())));return(e=(e=new Rt([e])).sub(c.mmul(l).mmul(u).mul(s).transpose())).to1DArray()}const Vt=1e-5,Ot=.001;class qt{learningRate=1;localConnectivity=1;minDist=.1;nComponents=2;nEpochs=0;nNeighbors=15;negativeSampleRate=5;random=Math.random;repulsionStrength=1;setOpMixRatio=1;spread=1;transformQueueSize=4;targetMetric="categorical";targetWeight=.5;targetNNeighbors=15;distanceFn=Pt;knnIndices;knnDistances;graph;X;isInitialized=!1;rpForest=[];initFromRandom;initFromTree;search;searchGraph;Y;embedding=[];optimizationState=new jt;get neighbors(){return this.nNeighbors}constructor(t={}){const e=e=>{void 0!==t[e]&&(this[e]=t[e])};e("distanceFn"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize"),this.targetNNeighbors=t.nNeighbors||this.nNeighbors||this.targetNNeighbors}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{initFromTree:t,initFromRandom:e}=(r=this.distanceFn,{initFromRandom:function(t,e,s,n,o){for(let i=0;i<s.length;i++){const h=R(t,e.length,o);for(let t=0;t<h.length;t++)h[t]<0||I(n,i,r(e[h[t]],s[i]),h[t],1)}},initFromTree:function(t,e,s,n,o){for(let i=0;i<s.length;i++){const h=rt(s[i],t,o);for(let t=0;t<h.length;t++){if(h[t]<0)return;I(n,i,r(e[h[t]],s[i]),h[t],1)}}}});var r;this.initFromTree=t,this.initFromRandom=e,this.search=function(t){return function(e,r,s,n){const{indices:o,indptr:i}=K(r);for(let r=0;r<n.length;r++){const h=new Set(s[0][r]);for(;;){const a=q(s,r);if(-1===a)break;const l=o.slice(i[a],i[a+1]);for(const o of l)o===a||-1===o||h.has(o)||(T(s,r,t(e[o],n[r]),o,1),h.add(o))}}return s}}(this.distanceFn)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,s=[t.length,t.length],n=new P([],[],[],s);for(let t=0;t<e.length;t++){const s=e[t],o=r[t];for(let e=0;e<s.length;e++){const r=s[e],i=o[e];i>0&&n.set(t,r,i)}}return X(n,j(n),((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,n,o,i){const h=C(r.length,s);if(n(s,e,r,h,i),t)for(const s of t)o(s,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),n=this.search(e,this.searchGraph,s,t);let{indices:o,weights:i}=V(n);o=o.map((t=>t.slice(0,this.nNeighbors))),i=i.map((t=>t.slice(0,this.nNeighbors)));const h=Math.max(0,this.localConnectivity-1),{sigmas:a,rhos:l}=this.smoothKNNDistance(i,this.nNeighbors,h),{rows:u,cols:c,vals:f}=this.computeMembershipStrengths(o,i,a,l),g=[t.length,e.length];let m=new P(u,c,f,g);const p=K(Y(m,"l1")),w=t.length,d=function(t,e,r){const s=k(t.length).map((t=>k(r[0].length)));for(let n=0;n<t.length;n++)for(let o=0;o<t[0].length;o++)for(let i=0;i<r[0].length;i++){const h=t[n][o];s[n][i]+=e[n][o]*r[h][i]}return s}(F(p.indices,w,this.nNeighbors),F(p.values,w,this.nNeighbors),this.embedding),y=this.nEpochs?this.nEpochs/3:m.nRows<=1e4?100:30,b=m.getValues().reduce(((t,e)=>e>t?e:t),0);m=m.map((t=>t<b/y?0:t)),m=U(m);const M=this.makeEpochsPerSample(m.getValues(),y),x=m.getRows(),v=m.getCols();return this.assignOptimizationStateParameters({headEmbedding:d,tailEmbedding:this.embedding,head:x,tail:v,currentEpoch:0,nEpochs:y,nVertices:m.getDims()[1],epochsPerSample:M}),this.prepareForOptimizationLoop(),this.optimizeLayout()}processGraphForSupervisedProjection(){const{Y:t,X:e}=this;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){const e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}}step(){const{currentEpoch:t}=this.optimizationState;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch}getEmbedding(){return this.embedding}nearestNeighbors(t){const{distanceFn:e,nNeighbors:r}=this,s=function(t,e){return function(r,s,n,o=10,i=50,h=.001,a=.5,l=!0){const u=r.length,c=C(r.length,n);for(let s=0;s<r.length;s++){const o=z(n,r.length,e);for(let e=0;e<o.length;e++){const n=t(r[s],r[o[e]]);I(c,s,n,o[e],1),I(c,o[e],n,s,1)}}if(l)for(let e=0;e<s.length;e++)for(let n=0;n<s[e].length&&!(s[e][n]<0);n++)for(let o=n+1;o<s[e].length&&!(s[e][o]<0);o++){const i=t(r[s[e][n]],r[s[e][o]]);I(c,s[e][n],i,s[e][o],1),I(c,s[e][o],i,s[e][n],1)}for(let s=0;s<o;s++){const s=D(c,u,n,i,e);let o=0;for(let n=0;n<u;n++)for(let h=0;h<i;h++){const l=Math.floor(s[0][n][h]);if(!(l<0||x(e)<a))for(let e=0;e<i;e++){const i=Math.floor(s[0][n][e]),a=s[2][n][h],u=s[2][n][e];if(i<0||!a&&!u)continue;const f=t(r[l],r[i]);o+=I(c,l,f,i,1),o+=I(c,i,f,l,1)}}if(o<=h*n*r.length)break}return V(c)}}(e,this.random),n=5+Math.floor(.5==(o=t.length**.5/20)?0:Math.round(o));var o;const i=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));this.rpForest=B(t,r,n,this.random);const h=function(t){if(t.length>0){const e=[];for(const r of t)e.push(...r.indices);return e}return[[-1]]}(this.rpForest),{indices:a,weights:l}=s(t,h,r,i);return{knnIndices:a,knnDistances:l}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:s=[],knnDistances:n=[],localConnectivity:o}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(n,e,o),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(s,n,i,h),c=[t.length,t.length],f=new P(a,l,u,c),g=j(f),m=L(f,g),p=$(_(f,g),m);return _(W(p,r),W(m,1-r))}categoricalSimplicialSetIntersection(t,e,r,s=1){let n=function(t,e,r=1,s=5){return t.map(((t,n,o)=>-1===e[n]||-1===e[o]?t*Math.exp(-r):e[n]!==e[o]?t*Math.exp(-s):t))}(t,e,s,r);return n=U(n),function(t){const e=j(t=Y(t,"max"));return U(t=_(t,$(e,L(e,t))))}(n)}smoothKNNDistance(t,e,r=1,s=64,n=1){const o=Math.log(e)/Math.log(2)*n,i=k(t.length),h=k(t.length);for(let e=0;e<t.length;e++){let n=0,a=1/0,l=1;const u=t[e],c=u.filter((t=>t>0));if(c.length>=r){const t=Math.floor(r),s=r-t;t>0?(i[e]=c[t-1],s>Vt&&(i[e]+=s*(c[t]-c[t-1]))):i[e]=s*c[0]}else c.length>0&&(i[e]=A(c));for(let r=0;r<s;r++){let r=0;for(let s=1;s<t[e].length;s++){const n=t[e][s]-i[e];r+=n>0?Math.exp(-n/l):1}if(Math.abs(r-o)<Vt)break;r>o?(a=l,l=(n+a)/2):(n=l,a===1/0?l*=2:l=(n+a)/2)}if(h[e]=l,i[e]>0){const t=N(u);h[e]<Ot*t&&(h[e]=Ot*t)}else{const r=N(t.map(N));h[e]<Ot*r&&(h[e]=Ot*r)}}return{sigmas:h,rhos:i}}computeMembershipStrengths(t,e,r,s){const n=t.length,o=t[0].length,i=k(n*o),h=k(n*o),a=k(n*o);for(let l=0;l<n;l++)for(let n=0;n<o;n++){let u=0;-1!==t[l][n]&&(u=t[l][n]===l?0:e[l][n]-s[l]<=0?1:Math.exp(-(e[l][n]-s[l])/r[l]),i[l*o+n]=l,h[l*o+n]=t[l][n],a[l*o+n]=u)}return{rows:i,cols:h,vals:a}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:e}=this,r=this.graph.getValues();let s=0;for(let t=0;t<r.length;t++){const e=r[t];s<r[t]&&(s=e)}const n=this.graph.map((e=>e<s/t?0:e));this.embedding=k(n.nRows).map((()=>k(e).map((()=>20*x(this.random)-10))));const o=[],i=[],h=[],a=n.getAll();for(let t=0;t<a.length;t++){const e=a[t];e.value&&(o.push(e.value),h.push(e.row),i.push(e.col))}return{head:i,tail:h,epochsPerSample:this.makeEpochsPerSample(o,t)}}makeEpochsPerSample(t,e){const r=S(t.length,-1),s=A(t),n=t.map((t=>t/s*e));return n.forEach(((t,s)=>{t>0&&(r[s]=e/n[s])})),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:s,headEmbedding:n,tailEmbedding:o}=this.optimizationState,i=n[0].length,h=n.length===o.length,a=s.map((t=>t/r)),l=[...a],u=[...s];this.assignOptimizationStateParameters({epochOfNextSample:u,epochOfNextNegativeSample:l,epochsPerNegativeSample:a,moveOther:h,initialAlpha:e,alpha:e,gamma:t,dim:i})}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:s,epochsPerSample:n}=this.optimizationState,o=this.getNEpochs(),i=this.graph.nCols,{a:h,b:a}=function(t,e){const r=function(t,e,r){return v(300).map(((t,r)=>0+r*((e-0)/299)))}(0,3*t).map((t=>t<e?1:t)),s=k(r.length).map(((s,n)=>r[n]>=e?Math.exp(-(r[n]-e)/t):s)),n={x:r,y:s},{parameterValues:o}=function(t,e,r={}){let{maxIterations:s=100,gradientDifference:n=.1,damping:o=0,errorTolerance:i=.01,minValues:h,maxValues:a,initialValues:l}=r;if(o<=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(!nt(t.x)||t.x.length<2||!nt(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(!nt(u))throw new Error("initialValues must be an array");let f,g=ot(t,u,e),m=g<=i;for(f=0;f<s&&!m;f++){u=Dt(t,u,o,n,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(g=ot(t,u,e),isNaN(g))break;m=g<=i}return{parameterValues:u,parameterError:g,iterations:f}}(n,(([t,e])=>r=>1/(1+t*r**(2*e))),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[i,h]=o;return{a:i,b:h}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:s,epochsPerSample:n,a:h,b:a,nEpochs:o,nVertices:i})}optimizeLayoutStep(t){const{optimizationState:e}=this,{head:r,tail:s,headEmbedding:n,tailEmbedding:o,epochsPerSample:i,epochOfNextSample:h,epochOfNextNegativeSample:a,epochsPerNegativeSample:l,moveOther:u,initialAlpha:c,alpha:f,gamma:g,a:m,b:p,dim:w,nEpochs:d,nVertices:y}=e;for(let e=0;e<i.length;e++){if(h[e]>t)continue;const c=r[e],d=s[e],b=n[c],x=o[d],v=_t(b,x);let E=0;v>0&&(E=-2*m*p*Math.pow(v,p-1),E/=m*Math.pow(v,p)+1);for(let t=0;t<w;t++){const e=Lt(E*(b[t]-x[t]),4);b[t]+=e*f,u&&(x[t]+=-e*f)}h[e]+=i[e];const S=Math.floor((t-a[e])/l[e]);for(let t=0;t<S;t++){const t=M(y,this.random),e=o[t],r=_t(b,e);let s=0;if(r>0)s=2*g*p,s/=(.001+r)*(m*Math.pow(r,p)+1);else if(c===t)continue;for(let t=0;t<w;t++){let r=4;s>0&&(r=Lt(s*(b[t]-e[t]),4)),b[t]+=r*f}}a[e]+=S*l[e]}return e.alpha=c*(1-t/d),e.currentEpoch+=1,n}optimizeLayoutAsync(t=(()=>!0)){return new Promise(((e,r)=>{const s=async()=>{try{const{nEpochs:r,currentEpoch:n}=this.optimizationState;this.embedding=this.optimizeLayoutStep(n);const o=this.optimizationState.currentEpoch,i=!1===t(o),h=o===r;if(i||h)return e(h);setTimeout((()=>s()),0)}catch(t){r(t)}};setTimeout((()=>s()),0)}))}optimizeLayout(t=(()=>!0)){let e=!1,r=[];for(;!e;){const{nEpochs:s,currentEpoch:n}=this.optimizationState;r=this.optimizeLayoutStep(n);const o=this.optimizationState.currentEpoch,i=!1===t(o);e=o===s||i}return r}getNEpochs(){const t=this.graph;if(this.nEpochs>0)return this.nEpochs;if(!t)return 200;const e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200}}function Pt(t,e){return Math.abs(t-e)}class jt{currentEpoch=0;headEmbedding=[];tailEmbedding=[];head=[];tail=[];epochsPerSample=[];epochOfNextSample=[];epochOfNextNegativeSample=[];epochsPerNegativeSample=[];moveOther=!0;initialAlpha=1;alpha=1;gamma=1;a=1.5769434603113077;b=.8950608779109733;dim=2;nEpochs=500;nVertices=0}function Lt(t,e){return t>e?e:t<-e?-e:t}function _t(t,e){let r=0;for(let s=0;s<t.length;s++)r+=Math.pow(t[s]-e[s],2);return r}var $t=r(2590),Wt=r(9657),Ut=r(6377),Yt=r.n(Ut);class Gt{perplexity;dim;epsilon;iter=0;N;P;Y;gains;ystep;random=Math.random;assert(t,e){if(!t)throw e||"Assertion failed"}getopt(t,e,r){return t.hasOwnProperty(e)?t[e]:r}returnV=!1;vValue=0;gaussRandom(){if(this.returnV)return this.returnV=!1,this.vValue;const t=2*this.random()-1,e=2*this.random()-1,r=t*t+e*e;if(0===r||r>1)return this.gaussRandom();const s=Math.sqrt(-2*Math.log(r)/r);return this.vValue=e*s,this.returnV=!0,t*s}randn(t,e){return t+this.gaussRandom()*e}zeros(t){if(void 0===t||isNaN(t))return new Float32Array;if("undefined"==typeof ArrayBuffer){const e=new Float32Array(t);for(let r=0;r<t;r++)e[r]=0;return e}return new Float32Array(t)}randn2d(t,e,r){const s=void 0!==r,n=new Array(t).fill(null).map((()=>new Float32Array(e)));if(s)for(let s=0;s<t;s++)n[s]=new Float32Array(e).fill(r);else for(let r=0;r<t;r++)for(let t=0;t<e;t++)n[r][t]=this.randn(0,1e-4);return n}l2(t,e){const r=t.length;let s=0;for(let n=0;n<r;n++){const r=t[n],o=e[n];s+=(r-o)*(r-o)}return s}xtod(t){const e=t.length,r=this.zeros(e*e);for(let s=0;s<e;s++)for(let n=s+1;n<e;n++){const o=this.l2(t[s],t[n]);r[s*e+n]=o,r[n*e+s]=o}return r}getIterSize(t){return t<=2e3?100:t<=3e3?90:t<=5e3?80:70}d2p(t,e,r,s){const n=(i=s,(t,e)=>i*t+e-Math.floor((t+2)*(t+1)/2)),o=new Float32Array(s*s);var i;for(let e=0;e<s;e++)for(let r=e+1;r<s;r++)o[e*s+r]=o[r*s+e]=t[n(e,r)];const h=s,a=Math.log(e),l=this.zeros(h*h),u=this.zeros(h);for(let t=0;t<h;t++){let e=-1/0,n=1/0,i=1,c=!1;const f=Math.floor(this.getIterSize(s)/5);let g=0;for(;!c;){let s=0;for(let e=0;e<h;e++){const r=t===e?0:Math.exp(-o[t*h+e]*i);u[e]=r,s+=r}let l=0;for(let t=0;t<h;t++){let e;e=0===s?0:u[t]/s,u[t]=e,e>1e-7&&(l-=e*Math.log(e))}l>a?(e=i,n===1/0?i*=2:i=(i+n)/2):(n=i,e===-1/0?i/=2:i=(i+e)/2),g++,Math.abs(l-a)<r&&(c=!0),g>=f&&(c=!0)}for(let e=0;e<h;e++)l[t*h+e]=u[e]}const c=this.zeros(h*h),f=2*h;for(let t=0;t<h;t++)for(let e=0;e<h;e++)c[t*h+e]=Math.max((l[t*h+e]+l[e*h+t])/f,1e-100);return c}sign(t){return t>0?1:t<0?-1:0}constructor(t){t=t||{},this.perplexity=this.getopt(t,"perplexity",30),this.dim=this.getopt(t,"dim",2),this.epsilon=this.getopt(t,"epsilon",10),this.random=this.getopt(t,"random",Math.random)}initDataRaw(t){const e=t.length,r=t[0].length;this.assert(e>0," X is empty? You must have some data!"),this.assert(r>0," X[0] is empty? Where is the data?");const s=this.xtod(t);this.P=this.d2p(s,this.perplexity,1e-4,r),this.N=e,this.initSolution()}initDataDist(t,e){const r=t.length;this.assert(r>0," X is empty? You must have some data!"),console.time("distances to matrix"),this.P=this.d2p(t,this.perplexity,1e-4,e),console.timeEnd("distances to matrix"),this.N=e,this.initSolution()}initSolution(){this.Y=this.randn2d(this.N,this.dim),this.gains=this.randn2d(this.N,this.dim,1),this.ystep=this.randn2d(this.N,this.dim,0),this.iter=0}getSolution(){return this.Y}step(){this.iter+=1;const t=this.N,e=this.costGrad(this.Y),r=e.cost,s=e.grad,n=this.zeros(this.dim);for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const r=s[e][t],o=this.ystep[e][t],i=this.gains[e][t];let h=this.sign(r)===this.sign(o)?.8*i:i+.2;h<.01&&(h=.01),this.gains[e][t]=h;const a=(this.iter<250?.5:.8)*o-this.epsilon*h*s[e][t];this.ystep[e][t]=a,this.Y[e][t]+=a,n[t]+=this.Y[e][t]}for(let e=0;e<t;e++)for(let r=0;r<this.dim;r++)this.Y[e][r]-=n[r]/t;return r}debugGrad(){const t=this.N,e=this.costGrad(this.Y).grad,r=1e-5;for(let s=0;s<t;s++)for(let t=0;t<this.dim;t++){const n=this.Y[s][t];this.Y[s][t]=n+r;const o=this.costGrad(this.Y);this.Y[s][t]=n-r;const i=this.costGrad(this.Y),h=e[s][t],a=(o.cost-i.cost)/(2*r);console.log(s+","+t+": gradcheck analytic: "+h+" vs. numerical: "+a),this.Y[s][t]=n}}quArr;costGrad(t){const e=this.N,r=this.dim,s=this.P,n=this.iter<100?4:1;this.quArr??=this.zeros(e*e);let o=0;for(let s=0;s<e;s++)for(let n=s+1;n<e;n++){const i=1/(1+new Array(r).reduce(((e,r,o)=>e+Math.pow(t[s][o]-t[n][o],2)),0));this.quArr[s*e+n]=i,this.quArr[n*e+s]=i,o+=2*i}let i=0;const h=new Array(e).fill(null).map((()=>new Float32Array(r).fill(0)));for(let a=0;a<e;a++)for(let l=a+1;l<e;l++){const u=Math.max(this.quArr[a*e+l]/o,1e-100);i+=-s[a*e+l]*Math.log(u)*2;const c=4*(n*s[a*e+l]-u)*this.quArr[a*e+l];for(let e=0;e<r;e++)h[a][e]+=c*(t[a][e]-t[l][e]),h[l][e]+=c*(t[l][e]-t[a][e])}return{cost:i,grad:h}}}class Xt{data;weights;aggregationMethod;constructor(t){this.data=t.data,this.weights=t.weights,this.aggregationMethod=t.aggregationMethod}}class Kt extends Xt{reducer;iterations;distanceFnames;distanceFns;distanceFnArgs;progressFunc;constructor(t){super(t);const e=t.randomSeed??Date(),r=Yt()(e);t.random=r,this.reducer=new Gt(t),this.iterations=t?.iterations??this.reducer.getIterSize(this.data[0].length),this.distanceFnames=t.distanceFnames,this.distanceFns=t.distanceFns,this.distanceFnArgs=t.distanceFnArgs,this.progressFunc=t.progressFunc}async transform(){if(this.data[0].length>1e4)throw new Error("Maximum number of samples for T-SNE is 10000");const t=new b(!0,!1);try{const e=await t.calcMulti(this.data,this.distanceFnames,!1,this.distanceFnArgs,this.weights,this.aggregationMethod);t.terminate(),this.reducer.initDataDist(e,this.data[0].length);for(let t=0;t<this.iterations;++t)this.reducer.step(),this.progressFunc&&this.progressFunc(t,this.iterations,[]);return this.reducer.getSolution()}catch(e){throw t.terminate(),e}}}class Qt extends Xt{reducer;distanceFnames;distanceFns;vectors;progressFunc;distanceFnArgs;constructor(t){const e=t.randomSeed??Date(),r=Yt()(e);super(t),a("distanceFnames"in t),a("distanceFns"in t),this.distanceFnArgs=t.distanceFnArgs,this.distanceFns=t.distanceFns,this.progressFunc=t.progressFunc,this.distanceFnames=t.distanceFnames,this.vectors=new Array(this.data[0].length).fill(0).map(((t,e)=>e)),this.data[0].length<=(t.nNeighbors??15)&&(t.nNeighbors=this.data[0].length-1),t.random=r,this.reducer=new qt(t)}async transform(t){console.time("knn graph");const e=await(new $t._).multiColumnKNN(this.data,this.distanceFnames,this.reducer.neighbors,this.distanceFnArgs,this.weights,this.aggregationMethod);console.timeEnd("knn graph"),this.reducer.setPrecomputedKNN(e.knnIndexes,e.knnDistances),await new Promise((t=>{setTimeout((()=>{t()}),300)}));const r=await this.reducer.fitAsync(this.vectors,(t=>{this.progressFunc&&this.progressFunc(t,this.reducer.getNEpochs(),this.reducer.getEmbedding())}));return n=r,new Array(n.length).fill(0).map(((t,e)=>s.from(n[e])));var n}}const Bt={UMAP:Qt,"t-SNE":Kt};class Ht{reducer;constructor(t,e,r,s,n,o){const i=[];for(let e=0;e<r.length;++e){const s=new d(r[e]).getMeasure(o.distanceFnArgs[e]);i.push(s);let n=2048;for(let r=0;r<t[e].length;++r)if(t[e][r]&&t[e][r]._length){n=t[e][r]._length;break}if(h=r[e],"BitArray"==w[h])for(let r=0;r<t[e].length;++r)t[e][r]&&t[e][r]._data?t[e][r]=new Wt.Z(t[e][r]._data,t[e][r]._length):t[e][r]=new Wt.Z(n)}var h;"UMAP"==e?this.reducer=new Qt({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:s,aggregationMethod:n,...o}):"t-SNE"==e&&(this.reducer=new Kt({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:s,aggregationMethod:n,...o}))}async transform(t=!1){if(void 0===this.reducer)throw new Error("Reducer was not defined.");let e=await this.reducer.transform();var r;return t&&(r=e,e=new Array(r[0].length).fill(0).map(((t,e)=>new s(r.length).fill(0).map(((t,s)=>r[s][e]))))),e}static availableMetricsByType(t){return Object.keys(p[t])}static get availableMethods(){return Object.keys(Bt)}static get availableMetrics(){let t=[];return Object.values(p).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}async function Jt(t,e,r){t%5==0&&self.postMessage({epochNum:t,epochsLength:e,embedding:r})}self.onmessage=async({data:{columnsData:t,method:e,distanceMetrics:r,options:s,weights:n,aggregationMethod:o}})=>{let i;try{const h=await async function(t,e,r,s,n,o){const i=new Ht(t,e,r,s,n,{...o,progressFunc:Jt});return await i.transform(!0)}(t,e,r,n,o,s);i={embedding:h}}catch(t){i={error:t}}self.postMessage({error:i.error,embedding:i.embedding})}},6377:(t,e,r)=>{var s=r(4832),n=r(8652),o=r(801),i=r(2030),h=r(3618),a=r(9049),l=r(1971);l.alea=s,l.xor128=n,l.xorwow=o,l.xorshift7=i,l.xor4096=h,l.tychei=a,t.exports=l},4832:function(t,e,r){var s;!function(t,n,o){function i(t){var e,r=this,s=(e=4022871197,function(t){t=String(t);for(var r=0;r<t.length;r++){var s=.02519603282416938*(e+=t.charCodeAt(r));s-=e=s>>>0,e=(s*=e)>>>0,e+=4294967296*(s-=e)}return 2.3283064365386963e-10*(e>>>0)});r.next=function(){var t=2091639*r.s0+2.3283064365386963e-10*r.c;return r.s0=r.s1,r.s1=r.s2,r.s2=t-(r.c=0|t)},r.c=1,r.s0=s(" "),r.s1=s(" "),r.s2=s(" "),r.s0-=s(t),r.s0<0&&(r.s0+=1),r.s1-=s(t),r.s1<0&&(r.s1+=1),r.s2-=s(t),r.s2<0&&(r.s2+=1),s=null}function h(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function a(t,e){var r=new i(t),s=e&&e.state,n=r.next;return n.int32=function(){return 4294967296*r.next()|0},n.double=function(){return n()+11102230246251565e-32*(2097152*n()|0)},n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.alea=a}(0,t=r.nmd(t),r.amdD)},9049:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this,r="";e.next=function(){var t=e.b,r=e.c,s=e.d,n=e.a;return t=t<<25^t>>>7^r,r=r-s|0,s=s<<24^s>>>8^n,n=n-t|0,e.b=t=t<<20^t>>>12^r,e.c=r=r-s|0,e.d=s<<16^r>>>16^n,e.a=n-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):r+=t;for(var s=0;s<r.length+20;s++)e.b^=0|r.charCodeAt(s),e.next()}function h(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function a(t,e){var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.tychei=a}(0,t=r.nmd(t),r.amdD)},8652:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this,r="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:r+=t;for(var s=0;s<r.length+64;s++)e.x^=0|r.charCodeAt(s),e.next()}function h(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function a(t,e){var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xor128=a}(0,t=r.nmd(t),r.amdD)},3618:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this;e.next=function(){var t,r,s=e.w,n=e.X,o=e.i;return e.w=s=s+1640531527|0,r=n[o+34&127],t=n[o=o+1&127],r^=r<<13,t^=t<<17,r^=r>>>15,t^=t>>>12,r=n[o]=r^t,e.i=o,r+(s^s>>>16)|0},function(t,e){var r,s,n,o,i,h=[],a=128;for(e===(0|e)?(s=e,e=null):(e+="\0",s=0,a=Math.max(a,e.length)),n=0,o=-32;o<a;++o)e&&(s^=e.charCodeAt((o+32)%e.length)),0===o&&(i=s),s^=s<<10,s^=s>>>15,s^=s<<4,s^=s>>>13,o>=0&&(i=i+1640531527|0,n=0==(r=h[127&o]^=s+i)?n+1:0);for(n>=128&&(h[127&(e&&e.length||0)]=-1),n=127,o=512;o>0;--o)s=h[n+34&127],r=h[n=n+1&127],s^=s<<13,r^=r<<17,s^=s>>>15,r^=r>>>12,h[n]=s^r;t.w=i,t.X=h,t.i=n}(e,t)}function h(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function a(t,e){null==t&&(t=+new Date);var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&(s.X&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xor4096=a}(0,t=r.nmd(t),r.amdD)},2030:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this;e.next=function(){var t,r,s=e.x,n=e.i;return t=s[n],r=(t^=t>>>7)^t<<24,r^=(t=s[n+1&7])^t>>>10,r^=(t=s[n+3&7])^t>>>3,r^=(t=s[n+4&7])^t<<7,t=s[n+7&7],r^=(t^=t<<13)^t<<9,s[n]=r,e.i=n+1&7,r},function(t,e){var r,s=[];if(e===(0|e))s[0]=e;else for(e=""+e,r=0;r<e.length;++r)s[7&r]=s[7&r]<<15^e.charCodeAt(r)+s[r+1&7]<<13;for(;s.length<8;)s.push(0);for(r=0;r<8&&0===s[r];++r);for(8==r?s[7]=-1:s[r],t.x=s,t.i=0,r=256;r>0;--r)t.next()}(e,t)}function h(t,e){return e.x=t.x.slice(),e.i=t.i,e}function a(t,e){null==t&&(t=+new Date);var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&(s.x&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xorshift7=a}(0,t=r.nmd(t),r.amdD)},801:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this,r="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:r+=t;for(var s=0;s<r.length+64;s++)e.x^=0|r.charCodeAt(s),s==r.length&&(e.d=e.x<<10^e.x>>>4),e.next()}function h(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function a(t,e){var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xorwow=a}(0,t=r.nmd(t),r.amdD)},1971:function(t,e,r){var s;!function(n,o,i){var h,a=256,l=6,u="random",c=i.pow(a,l),f=i.pow(2,52),g=2*f,m=a-1;function p(t,e,r){var s=[],m=b(y((e=1==e?{entropy:!0}:e||{}).entropy?[t,M(o)]:null==t?function(){try{var t;return h&&(t=h.randomBytes)?t=t(a):(t=new Uint8Array(a),(n.crypto||n.msCrypto).getRandomValues(t)),M(t)}catch(t){var e=n.navigator,r=e&&e.plugins;return[+new Date,n,r,n.screen,M(o)]}}():t,3),s),p=new w(s),x=function(){for(var t=p.g(l),e=c,r=0;t<f;)t=(t+r)*a,e*=a,r=p.g(1);for(;t>=g;)t/=2,e/=2,r>>>=1;return(t+r)/e};return x.int32=function(){return 0|p.g(4)},x.quick=function(){return p.g(4)/4294967296},x.double=x,b(M(p.S),o),(e.pass||r||function(t,e,r,s){return s&&(s.S&&d(s,p),t.state=function(){return d(p,{})}),r?(i[u]=t,e):t})(x,m,"global"in e?e.global:this==i,e.state)}function w(t){var e,r=t.length,s=this,n=0,o=s.i=s.j=0,i=s.S=[];for(r||(t=[r++]);n<a;)i[n]=n++;for(n=0;n<a;n++)i[n]=i[o=m&o+t[n%r]+(e=i[n])],i[o]=e;(s.g=function(t){for(var e,r=0,n=s.i,o=s.j,i=s.S;t--;)e=i[n=m&n+1],r=r*a+i[m&(i[n]=i[o=m&o+e])+(i[o]=e)];return s.i=n,s.j=o,r})(a)}function d(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function y(t,e){var r,s=[],n=typeof t;if(e&&"object"==n)for(r in t)try{s.push(y(t[r],e-1))}catch(t){}return s.length?s:"string"==n?t:t+"\0"}function b(t,e){for(var r,s=t+"",n=0;n<s.length;)e[m&n]=m&(r^=19*e[m&n])+s.charCodeAt(n++);return M(e)}function M(t){return String.fromCharCode.apply(0,t)}if(b(i.random(),o),t.exports){t.exports=p;try{h=r(5042)}catch(t){}}else void 0===(s=function(){return p}.call(e,r,e,t))||(t.exports=s)}("undefined"!=typeof self?self:this,[],Math)}}]);
|
|
2
|
+
(self.webpackChunkbio=self.webpackChunkbio||[]).push([[895],{6814:(t,e,r)=>{"use strict";r.d(e,{cZ:()=>n,kK:()=>s}),r(7862);const s=t=>null==t;function n(t,e,r,s){if(r>t[t.length-1])return;const n=t.findIndex((t=>r<t));t.pop(),t.splice(n,0,r),e.pop(),e.splice(n,0,s)}},4895:(t,e,r)=>{"use strict";class s extends Float32Array{}var n=r(1040),o=r(1811),i=r(3979),h=r(5697);function a(t=!1,e="Assertion error."){if(!t)throw new Error(e)}var l=r(708);const u={[n.CF.Euclidean]:function(t,e){let r=0;const s=t.length;if(s!==e.length)throw new Error("The dimensionality of the vectors must match");for(let n=0;n<s;++n)r+=Math.pow(t[n]-e[n],2);return Math.sqrt(r)}},c={[n.W.Levenshtein]:o.T,[n.W.JaroWinkler]:i.H$,[n.W.Manhattan]:function(t,e){if(t.length!==e.length)return 1;{let r=0;for(let s=1;s<t.length;s++)r+=t[s]==e[s]?0:1;return r/t.length}},[n.W.Onehot]:function(t,e){return t===e?0:1}},f={[n.gk.Tanimoto]:h.KR,[n.gk.Dice]:h._h,[n.gk.Asymmetric]:h.yU,[n.gk.BraunBlanquet]:h.Dz,[n.gk.Cosine]:h.Zd,[n.gk.Kulczynski]:h.s,[n.gk.McConnaughey]:h.aW,[n.gk.RogotGoldberg]:h.MI,[n.gk.Russel]:h.fX,[n.gk.Sokal]:h.NB,[n.gk.Hamming]:h.UX,[n.gk.Euclidean]:h.WI},g={[n.gd.TanimotoIntArray]:h.FV},m={[n.Yc.Difference]:h.bX},p={[n.gj.CommonItems]:h.Jv},w={[n.Qe.Vector]:{[n.CF.Euclidean]:u[n.CF.Euclidean]},[n.Qe.String]:{[n.W.Levenshtein]:c[n.W.Levenshtein],[n.W.JaroWinkler]:c[n.W.JaroWinkler],[n.W.Manhattan]:c[n.W.Manhattan],[n.W.Onehot]:c[n.W.Onehot]},[n.Qe.BitArray]:{[n.gk.Tanimoto]:f[n.gk.Tanimoto],[n.gk.Dice]:f[n.gk.Dice],[n.gk.Asymmetric]:f[n.gk.Asymmetric],[n.gk.BraunBlanquet]:f[n.gk.BraunBlanquet],[n.gk.Cosine]:f[n.gk.Cosine],[n.gk.Kulczynski]:f[n.gk.Kulczynski],[n.gk.McConnaughey]:f[n.gk.McConnaughey],[n.gk.RogotGoldberg]:f[n.gk.RogotGoldberg],[n.gk.Russel]:f[n.gk.Russel],[n.gk.Sokal]:f[n.gk.Sokal]},[n.Qe.MacroMolecule]:{[l.U.HAMMING]:l.o[l.U.HAMMING],[l.U.LEVENSHTEIN]:l.o[l.U.LEVENSHTEIN],[l.U.NEEDLEMANN_WUNSCH]:l.o[l.U.NEEDLEMANN_WUNSCH],[l.U.MONOMER_CHEMICAL_DISTANCE]:l.o[l.U.MONOMER_CHEMICAL_DISTANCE]},[n.Qe.Number]:{[n.Yc.Difference]:m[n.Yc.Difference]},[n.Qe.IntArray]:{[n.gd.TanimotoIntArray]:g[n.gd.TanimotoIntArray]},[n.Qe.NumberArray]:{[n.gj.CommonItems]:p[n.gj.CommonItems]}},d=Object.keys(w).reduce(((t,e)=>{for(const r of Object.keys(w[e]))t[r]=e;return t}),{});class y{constructor(t){this.method=t,this.dataType=d[t]}metricNeedsArgs(t){return d[t]==n.Qe.MacroMolecule.toString()||d[t]==n.Qe.Number.toString()||function(t){return d[t]==n.Qe.NumberArray.toString()}(t)}getMeasure(t){const e=w;if(!e.hasOwnProperty(this.dataType)||!e[this.dataType].hasOwnProperty(this.method))throw new Error(`Unknown measure ${this.method} for data type ${this.dataType}`);return this.metricNeedsArgs(this.method)?e[this.dataType][this.method](t):e[this.dataType][this.method]}static getMetricByDataType(t){return Object.keys(w[t])}static get availableMeasures(){return Object.keys(w)}}r(6814);var b=r(7862);class M{constructor(t=!0,e=!0){const s=navigator.hardwareConcurrency;this._workerCount=t?Math.max(s-2,1):1,this._workers=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(65),r.b)))),this._terminateOnComplete=e}async calc(t,e,r=!0,s){return await this.calcMulti([t],[e],r,[s??{}],[1],b.y.MANHATTAN)}async calcMulti(t,e,r=!0,s=[{}],n=[1],o=b.y.MANHATTAN){if(t.length<1)throw new Error("values must contain at least one array");if(e.length!==t.length||s.length!==t.length||n.length!==t.length)throw new Error("values, fnNames, weights and opts must have the same length");return new Promise((async(i,h)=>{try{const h=t[0].length,a=new Array(this._workerCount),l=h*(h-1)/2;this._workerCount=Math.min(this._workerCount,l);const u=l/this._workerCount,c=new Float32Array(l);let f=0,g=1,m=0,p=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const i=Math.floor(r*u),w=r===this._workerCount-1?l:Math.floor((r+1)*u),d=f,y=g;r!==this._workerCount-1&&(f=h-2-Math.floor(Math.sqrt(-8*w+4*h*(h-1)-7)/2-.5),g=w-h*f+Math.floor((f+1)*(f+2)/2)),this._workers[r].postMessage({values:t,fnNames:e,startRow:d,startCol:y,chunckSize:w-i,opts:s,weights:n,aggregationMethod:o}),a[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:s,distanceMatrixData:n,min:o,max:h}})=>{this._terminateOnComplete&&setTimeout((()=>this._workers[r].terminate())),s?e(s):(c.set(n,i),o<m&&(m=o),h>p&&(p=h),t())}}))}await Promise.all(a),r&&c.forEach(((t,e)=>{c[e]=(t-m)/(p-m)})),i(c)}catch(t){h(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}function x(t,e){return Math.floor(e()*t)}function v(t){return t()}function E(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function S(t){return E(t).map(((t,e)=>e))}function N(t,e){return E(t).map((()=>e))}function k(t){return N(t,0)}function A(t){return function(t){return t.reduce(((t,e)=>t+e))}(t)/t.length}function R(t){let e=0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e}function F(t,e,r){const s=k(t);for(let n=0;n<t;n++){let t=!0;for(;t;){const o=x(e,r);let i=!1;for(let t=0;t<n;t++)if(o===s[t]){i=!0;break}i||(t=!1),s[n]=o}}return s}function C(t,e,r){const s=[];let n=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let o=0;o<e;o++){const e=[];for(let s=0;s<r;s++)e.push(t[n]),n+=1;s.push(e)}return s}function z(t,e){const r=r=>E(t).map((()=>N(e,r))),s=[];return s.push(r(-1)),s.push(r(1/0)),s.push(r(0)),s}function I(t,e,r){const s=k(t);for(let n=0;n<t;n++){let t=!0,o=0;for(;t;){o=x(e,r);let i=!1;for(let t=0;t<n;t++)if(o===s[t]){i=!0;break}i||(t=!1)}s[n]=o}return s}function T(t,e,r,s,n){e=Math.floor(e);const o=t[0][e];if(r>=t[1][e][0])return 0;for(let t=0;t<o.length;t++)if(s===o[t])return 0;return D(t,e,r,s,n)}function D(t,e,r,s,n){const o=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,o[0]=s,h[0]=n;let a=0,l=0;for(;;){const e=2*a+1,s=e+1,n=t[0][0].length;if(e>=n)break;if(s>=n){if(!(i[e]>r))break;l=e}else if(i[e]>=i[s]){if(!(r<i[e]))break;l=e}else{if(!(r<i[s]))break;l=s}i[a]=i[l],o[a]=o[l],h[a]=h[l],a=l}return i[a]=r,o[a]=s,h[a]=n,1}function V(t,e,r,s,n){const o=z(e,s);for(let s=0;s<e;s++)for(let e=0;e<r;e++){if(t[0][s][e]<0)continue;const r=t[0][s][e],i=t[2][s][e],h=v(n);T(o,s,h,r,i),T(o,r,h,s,i),t[2][s][e]=0}return o}function O(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const s=e[t],n=r[t];for(let t=0;t<s.length-1;t++){const e=s.length-t-1,r=n.length-t-1,o=s[0];s[0]=s[e],s[e]=o;const i=n[0];n[0]=n[r],n[r]=i,q(n,s,r,0)}}return{indices:e,weights:r}}function q(t,e,r,s){for(;2*s+1<r;){const n=2*s+1,o=n+1;let i=s;if(t[i]<t[n]&&(i=n),o<r&&t[i]<t[o]&&(i=o),i===s)break;{const r=t[s];t[s]=t[i],t[i]=r;const n=e[s];e[s]=e[i],e[i]=n,s=i}}}function P(t,e){const r=t[0][e],s=t[1][e],n=t[2][e];let o=1/0,i=-1;for(let t=0;t>r.length;t++)1===n[t]&&s[t]<o&&(o=s[t],i=t);return i>=0?(n[i]=0,Math.floor(r[i])):-1}class j{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 n=t[s],o=e[s];this.checkDims(n,o);const i=this.makeKey(n,o);this.entries.set(i,{value:r[s],row:n,col:o})}}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){const s=this.makeKey(t,e);return this.entries.has(s)?this.entries.get(s).value:r}getAll(t=!0){const e=new Array(this.entries.size).fill(null);let r=0;return this.entries.forEach((t=>{e[r++]=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){const e=new Float32Array(this.entries.size);let r=0;this.entries.forEach((s=>{e[r++]=t(s.value,s.row,s.col)}));const s=[this.nRows,this.nCols];return new j(this.getRows(),this.getCols(),e,s)}toArray(){const t=E(this.nRows).map((()=>k(this.nCols)));return this.entries.forEach((e=>{t[e.row][e.col]=e.value})),t}}function L(t){const e=t.getRows(),r=t.getCols(),s=t.getValues(),n=r.length,o=new Int32Array(n),i=new Int32Array(n),h=new Float32Array(n);o.set(e),i.set(r),h.set(s);const a=[t.nCols,t.nRows];return new j(i,o,h,a)}function $(t,e){return X(t,e,((t,e)=>t*e))}function _(t,e){return X(t,e,((t,e)=>t+e))}function W(t,e){return X(t,e,((t,e)=>t-e))}function U(t,e){return t.map((t=>t*e))}function Y(t){const e=new Set,r=t.getValues(),s=t.getRows(),n=t.getCols();for(let t=0;t<r.length;t++)0===r[t]&&e.add(t);const o=(t,r)=>!e.has(r),i=r.filter(o),h=s.filter(o),a=n.filter(o);return new j(h,a,i,t.getDims())}function G(t,e="l2"){const r=Q[e],s=new Map;t.forEach(((t,e,r)=>{const n=s.get(e)||[];n.push(r),s.set(e,n)}));const n=new j([],[],[],t.getDims());for(const e of s.keys()){const o=s.get(e).sort(),i=r(o.map((r=>t.get(e,r))));for(let t=0;t<i.length;t++)n.set(e,o[t],i[t])}return n}const Q={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 X(t,e,r){const s=new Set,n=[],o=[],i=[],h=(s,h)=>{n.push(s),o.push(h);const a=r(t.get(s,h),e.get(s,h));i.push(a)},a=t.getValues(),l=t.getRows(),u=t.getCols();for(let t=0;t<a.length;t++){const e=l[t],r=u[t],n=`${e}:${r}`;s.add(n),h(e,r)}const c=e.getValues(),f=e.getRows(),g=e.getCols();for(let t=0;t<c.length;t++){const e=f[t],r=g[t],n=`${e}:${r}`;s.has(n)||h(e,r)}const m=[t.nRows,t.nCols];return new j(n,o,i,m)}function K(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=[],n=[];let o=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==o&&(o=i,n.push(t)),r.push(h),s.push(a)}return{indices:r,values:s,indptr:n}}class B{constructor(t,e,r,s){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=s}}function H(t,e,r,s){const n=Math.max(10,e),o=S(r).map(((e,r)=>function(t,e=30,r,s){return J(t,S(t.length),e,r,s)}(t,n,r,s))),i=o.map((t=>function(t,e){const r=tt(t),s=et(t),n=S(r).map((()=>t.hyperplane?1:0)),o=k(r),i=S(r).map((()=>[-1,-1])),h=S(s).map((()=>S(e).map((()=>-1))));return Z(t,n,o,i,h,0,0),new B(n,o,i,h)}(t,n)));return i}function J(t,e,r=30,s,n){if(e.length>r){const o=function(t,e,r){const s=x(e.length,r);let n=x(e.length,r);n+=s===n?1:0,n%=e.length;const o=e[s],i=e[n];let h=0,a=0;a=t[o]-t[i],h-=a*(t[o]+t[i])/2;let l=0,u=0;const c=k(e.length);for(let s=0;s<e.length;s++){let n=h;n+=a*t[e[s]],0===n?(c[s]=x(2,r),0===c[s]?l+=1:u+=1):n>0?(c[s]=0,l+=1):(c[s]=1,u+=1)}const f=k(l),g=k(u);l=0,u=0;for(let t=0;t<c.length;t++)0===c[t]?(f[l]=e[t],l+=1):(g[u]=e[t],u+=1);return{indicesLeft:f,indicesRight:g,hyperplane:a,offset:h}}(t,e,n),{indicesLeft:i,indicesRight:h,hyperplane:a,offset:l}=o;return{leftChild:J(t,i,r,s+1,n),rightChild:J(t,h,r,s+1,n),isLeaf:!1,hyperplane:a,offset:l}}return{indices:e,isLeaf:!0}}function Z(t,e,r,s,n,o,i){if(t.isLeaf)return s[o][0]=-i,n[i].splice(0,t.indices.length,...t.indices),{nodeNum:o,leafNum:i+=1};{e[o]=t.hyperplane,r[o]=t.offset,s[o][0]=o+1;const h=o;let a=Z(t.leftChild,e,r,s,n,o+1,i);return o=a.nodeNum,i=a.leafNum,s[h][1]=o+1,a=Z(t.rightChild,e,r,s,n,o+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function tt(t){return t.isLeaf?1:1+tt(t.leftChild)+tt(t.rightChild)}function et(t){return t.isLeaf?1:et(t.leftChild)+et(t.rightChild)}function rt(t,e,r,s){let n=e;return n+=t*r,0===n?x(2,s):n>0?0:1}function st(t,e,r){let s=0;for(;e.children[s][0]>0;)s=0===rt(e.hyperplanes[s],e.offsets[s],t,r)?e.children[s][0]:e.children[s][1];const n=-1*e.children[s][0];return e.indices[n]}const nt=Object.prototype.toString;function ot(t){return nt.call(t).endsWith("Array]")}function it(t,e,r){let s=0;const n=r(e);for(let e=0;e<t.x.length;e++)s+=Math.abs(t.y[e]-n(t.x[e]));return s}const ht=Object.prototype.toString;function at(t){return ht.call(t).endsWith("Array]")}const lt=Object.prototype.toString;function ut(t){return lt.call(t).endsWith("Array]")}const ct=Object.prototype.toString;const ft=Object.prototype.toString;function gt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!ut(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(!ut(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!ft.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=r.fromIndex,n=void 0===s?0:s,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[n],a=n+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),n=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!ct.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var s=r.fromIndex,n=void 0===s?0:s,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[n],a=n+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(s===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var o=r.min,i=void 0===o?r.autoMinMax?s:0:o,h=r.max,a=void 0===h?r.autoMinMax?n:1:h;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-i)/(n-s),u=0;u<t.length;u++)e[u]=(t[u]-s)*l+i;return e}const mt=" ".repeat(2),pt=" ".repeat(4);function wt(t,e={}){const{maxRows:r=15,maxColumns:s=10,maxNumSize:n=8,padMinus:o="auto"}=e;return`${t.constructor.name} {\n${mt}[\n${pt}${function(t,e,r,s,n){const{rows:o,columns:i}=t,h=Math.min(o,e),a=Math.min(i,r),l=[];if("auto"===n){n=!1;t:for(let e=0;e<h;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){n=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let o=0;o<a;o++)r.push(dt(t.get(e,o),s,n));l.push(`${r.join(" ")}`)}return a!==i&&(l[l.length-1]+=` ... ${i-r} more columns`),h!==o&&l.push(`... ${o-e} more rows`),l.join(`\n${pt}`)}(t,r,s,n,o)}\n${mt}]\n${mt}rows: ${t.rows}\n${mt}columns: ${t.columns}\n}`}function dt(t,e,r){return(t>=0&&r?` ${yt(t,e-1)}`:yt(t,e)).padEnd(e)}function yt(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 n=t.toExponential(e);return n.length>e&&(n=t.toExponential(Math.max(0,e-(n.length-e)))),n.slice(0)}function bt(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 Mt(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 xt(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 vt(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 Et(t,e,r,s,n){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Nt("startRow",e),Nt("endRow",r),Nt("startColumn",s),Nt("endColumn",n),e>r||s>n||e<0||e>=t.rows||r<0||r>=t.rows||s<0||s>=t.columns||n<0||n>=t.columns)throw new RangeError("Submatrix indices are out of range")}function St(t,e=0){let r=[];for(let s=0;s<t;s++)r.push(e);return r}function Nt(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function kt(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class At{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new Ft(t,e);for(let n=0;n<t;n++)for(let t=0;t<e;t++)s.set(n,t,r[n*e+t]);return s}static rowVector(t){let e=new Ft(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 Ft(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 Ft(t,e)}static ones(t,e){return new Ft(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 n=new Ft(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)n.set(r,t,s());return n}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:s=0,max:n=1e3,random:o=Math.random}=r;if(!Number.isInteger(s))throw new TypeError("min must be an integer");if(!Number.isInteger(n))throw new TypeError("max must be an integer");if(s>=n)throw new RangeError("min must be smaller than max");let i=n-s,h=new Ft(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=s+Math.round(o()*i);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let s=Math.min(t,e),n=this.zeros(t,e);for(let t=0;t<s;t++)n.set(t,t,r);return n}static diag(t,e,r){let s=t.length;void 0===e&&(e=s),void 0===r&&(r=e);let n=Math.min(s,e,r),o=this.zeros(e,r);for(let e=0;e<n;e++)o.set(e,e,t[e]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,n=new Ft(r,s);for(let o=0;o<r;o++)for(let r=0;r<s;r++)n.set(o,r,Math.min(t.get(o,r),e.get(o,r)));return n}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,s=t.columns,n=new this(r,s);for(let o=0;o<r;o++)for(let r=0;r<s;r++)n.set(o,r,Math.max(t.get(o,r),e.get(o,r)));return n}static checkMatrix(t){return At.isMatrix(t)?t:new Ft(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,s=!0,n=!1;for(;t<this.rows&&s;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(s=!1,n=!0);t++}return s}isReducedEchelonForm(){let t=0,e=0,r=-1,s=!0,n=!1;for(;t<this.rows&&s;){for(e=0,n=!1;e<this.columns&&!1===n;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(n=!0,r=e):(s=!1,n=!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 n=e;n<t.rows;n++)t.get(n,r)>t.get(s,r)&&(s=n);if(0===t.get(s,r))r++;else{t.swapRows(e,s);let n=t.get(e,r);for(let s=r;s<t.columns;s++)t.set(e,s,t.get(e,s)/n);for(let s=e+1;s<t.rows;s++){let n=t.get(s,r)/t.get(e,r);t.set(s,r,0);for(let o=r+1;o<t.columns;o++)t.set(s,o,t.get(s,o)-t.get(e,o)*n)}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 n=0,o=!1;for(;n<r&&!1===o;)1===t.get(s,n)?o=!0:n++;for(let r=0;r<s;r++){let o=t.get(r,n);for(let i=n;i<e;i++){let e=t.get(r,i)-o*t.get(s,i);t.set(r,i,e)}}s--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let s=new Ft(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){bt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Ft.rowVector(this.getRow(t))}setRow(t,e){bt(this,t),e=xt(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){bt(this,t),bt(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){Mt(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Ft.columnVector(this.getColumn(t))}setColumn(t,e){Mt(this,t),e=vt(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){Mt(this,t),Mt(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=xt(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=xt(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=xt(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=xt(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=vt(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=vt(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=vt(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=vt(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){bt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){Mt(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(){kt(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(){kt(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(bt(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){bt(this,t),kt(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(bt(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){bt(this,t),kt(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(Mt(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){Mt(this,t),kt(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(Mt(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){Mt(this,t),kt(this);let e=this.get(0,t),r=[0,t];for(let s=1;s<this.rows;s++)this.get(s,t)<e&&(e=this.get(s,t),r[0]=s);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){let e=0;if("max"===t)return this.max();if("frobenius"===t){for(let t=0;t<this.rows;t++)for(let r=0;r<this.columns;r++)e+=this.get(t,r)*this.get(t,r);return Math.sqrt(e)}throw new RangeError(`unknown norm type: ${t}`)}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){At.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=Ft.checkMatrix(t);let e=this.rows,r=this.columns,s=t.columns,n=new Ft(e,s),o=new Float64Array(r);for(let i=0;i<s;i++){for(let e=0;e<r;e++)o[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let s=0;s<r;s++)e+=this.get(t,s)*o[s];n.set(t,i,e)}}return n}strassen2x2(t){t=Ft.checkMatrix(t);let e=new Ft(2,2);const r=this.get(0,0),s=t.get(0,0),n=this.get(0,1),o=t.get(0,1),i=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(s+l),c=(i+a)*s,f=r*(o-l),g=a*(h-s),m=(r+n)*l,p=u+g-m+(n-a)*(h+l),w=f+m,d=c+g,y=u-c+f+(i-r)*(s+o);return e.set(0,0,p),e.set(0,1,w),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=Ft.checkMatrix(t);let e=new Ft(3,3);const r=this.get(0,0),s=this.get(0,1),n=this.get(0,2),o=this.get(1,0),i=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=t.get(0,1),g=t.get(0,2),m=t.get(1,0),p=t.get(1,1),w=t.get(1,2),d=t.get(2,0),y=t.get(2,1),b=t.get(2,2),M=(r-o)*(-f+p),x=(-r+o+i)*(c-f+p),v=(o+i)*(-c+f),E=r*c,S=(-r+a+l)*(c-g+w),N=(-r+a)*(g-w),k=(a+l)*(-c+g),A=(-n+l+u)*(p+d-y),R=(n-u)*(p-y),F=n*d,C=(l+u)*(-d+y),z=(-n+i+h)*(w+d-b),I=(n-h)*(w-b),T=(i+h)*(-d+b),D=E+F+s*m,V=(r+s+n-o-i-l-u)*p+x+v+E+A+F+C,O=E+S+k+(r+s+n-i-h-a-l)*w+F+z+T,q=M+i*(-c+f+m-p-w-d+b)+x+E+F+z+I,P=M+x+v+E+h*y,j=F+z+I+T+o*g,L=E+S+N+l*(-c+g+m-p-w-d+y)+A+R+F,$=A+R+F+C+a*f,_=E+S+N+k+u*b;return e.set(0,0,D),e.set(0,1,V),e.set(0,2,O),e.set(1,0,q),e.set(1,1,P),e.set(1,2,j),e.set(2,0,L),e.set(2,1,$),e.set(2,2,_),e}mmulStrassen(t){t=Ft.checkMatrix(t);let e=this.clone(),r=e.rows,s=e.columns,n=t.rows,o=t.columns;function i(t,e,r){let s=t.rows,n=t.columns;if(s===e&&n===r)return t;{let s=At.zeros(e,r);return s=s.setSubMatrix(t,0,0),s}}s!==n&&console.warn(`Multiplying ${r} x ${s} and ${n} x ${o} matrix: dimensions do not match.`);let h=Math.max(r,n),a=Math.max(s,o);return e=i(e,h,a),function t(e,r,s,n){if(s<=512||n<=512)return e.mmul(r);s%2==1&&n%2==1?(e=i(e,s+1,n+1),r=i(r,s+1,n+1)):s%2==1?(e=i(e,s+1,n),r=i(r,s+1,n)):n%2==1&&(e=i(e,s,n+1),r=i(r,s,n+1));let o=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,o-1,0,h-1),l=r.subMatrix(0,o-1,0,h-1),u=e.subMatrix(0,o-1,h,e.columns-1),c=r.subMatrix(0,o-1,h,r.columns-1),f=e.subMatrix(o,e.rows-1,0,h-1),g=r.subMatrix(o,r.rows-1,0,h-1),m=e.subMatrix(o,e.rows-1,h,e.columns-1),p=r.subMatrix(o,r.rows-1,h,r.columns-1),w=t(At.add(a,m),At.add(l,p),o,h),d=t(At.add(f,m),l,o,h),y=t(a,At.sub(c,p),o,h),b=t(m,At.sub(g,l),o,h),M=t(At.add(a,u),p,o,h),x=t(At.sub(f,a),At.add(l,c),o,h),v=t(At.sub(u,m),At.add(g,p),o,h),E=At.add(w,b);E.sub(M),E.add(v);let S=At.add(y,M),N=At.add(d,b),k=At.sub(w,d);k.add(y),k.add(x);let A=At.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(S,E.rows,0),A=A.setSubMatrix(N,0,E.columns),A=A.setSubMatrix(k,E.rows,E.columns),A.subMatrix(0,s-1,0,n-1)}(e,t=i(t,h,a),h,a)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new Ft(this.rows,this.columns);for(let t=0;t<this.rows;t++){const n=this.getRow(t);n.length>0&>(n,{min:e,max:r,output:n}),s.setRow(t,n)}return s}scaleColumns(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let s=new Ft(this.rows,this.columns);for(let t=0;t<this.columns;t++){const n=this.getColumn(t);n.length&>(n,{min:e,max:r,output:n}),s.setColumn(t,n)}return s}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let t=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,t)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let t=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Ft.checkMatrix(t);let e=this.rows,r=this.columns,s=t.rows,n=t.columns,o=new Ft(e*s,r*n);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<s;r++)for(let h=0;h<n;h++)o.set(s*i+r,n*e+h,this.get(i,e)*t.get(r,h));return o}kroneckerSum(t){if(t=Ft.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(Ft.eye(r,r)),n=Ft.eye(e,e).kroneckerProduct(t);return s.add(n)}transpose(){let t=new Ft(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=Rt){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=Rt){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,s){Et(this,t,e,r,s);let n=new Ft(e-t+1,s-r+1);for(let o=t;o<=e;o++)for(let e=r;e<=s;e++)n.set(o-t,e-r,this.get(o,e));return n}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 Ft(t.length,r-e+1);for(let n=0;n<t.length;n++)for(let o=e;o<=r;o++){if(t[n]<0||t[n]>=this.rows)throw new RangeError(`Row index out of range: ${t[n]}`);s.set(n,o-e,this.get(t[n],o))}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 Ft(r-e+1,t.length);for(let n=0;n<t.length;n++)for(let o=e;o<=r;o++){if(t[n]<0||t[n]>=this.columns)throw new RangeError(`Column index out of range: ${t[n]}`);s.set(o-e,n,this.get(o,t[n]))}return s}setSubMatrix(t,e,r){if((t=Ft.checkMatrix(t)).isEmpty())return this;Et(this,e,e+t.rows-1,r,r+t.columns-1);for(let s=0;s<t.rows;s++)for(let n=0;n<t.columns;n++)this.set(e+s,r+n,t.get(s,n));return this}selection(t,e){!function(t,e){if(!at(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")}(this,t),function(t,e){if(!at(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")}(this,e);let r=new Ft(t.length,e.length);for(let s=0;s<t.length;s++){let n=t[s];for(let t=0;t<e.length;t++){let o=e[t];r.set(s,t,this.get(n,o))}}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(){let t=new Ft(this.rows,this.columns);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(e,r,this.get(e,r));return t}sum(t){switch(t){case"row":return function(t){let e=St(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=St(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=St(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=St(t.columns,1);for(let r=0;r<t.rows;++r)for(let s=0;s<t.columns;++s)e[s]*=t.get(r,s);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)e*=t.get(r,s);return e}(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":for(let t=0;t<this.rows;t++)e[t]/=this.columns;return e;case"column":for(let t=0;t<this.columns;t++)e[t]/=this.rows;return e;case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{unbiased:r=!0,mean:s=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!at(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,n=t.columns,o=[];for(let i=0;i<s;i++){let s=0,h=0,a=0;for(let e=0;e<n;e++)a=t.get(i,e)-r[i],s+=a,h+=a*a;e?o.push((h-s*s/n)/(n-1)):o.push((h-s*s/n)/n)}return o}(this,r,s);case"column":if(!at(s))throw new TypeError("mean must be an array");return function(t,e,r){const s=t.rows,n=t.columns,o=[];for(let i=0;i<n;i++){let n=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(e,i)-r[i],n+=a,h+=a*a;e?o.push((h-n*n/s)/(s-1)):o.push((h-n*n/s)/s)}return o}(this,r,s);case void 0:if("number"!=typeof s)throw new TypeError("mean must be a number");return function(t,e,r){const s=t.rows,n=t.columns,o=s*n;let i=0,h=0,a=0;for(let e=0;e<s;e++)for(let s=0;s<n;s++)a=t.get(e,s)-r,i+=a,h+=a*a;return e?(h-i*i/o)/(o-1):(h-i*i/o)/o}(this,r,s);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!at(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(!at(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e[s])}(this,r),this;case void 0:if("number"!=typeof r)throw new TypeError("center must be a number");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)-e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.rows;r++){let s=0;for(let e=0;e<t.columns;e++)s+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(s))}return e}(this);else if(!at(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let s=0;s<t.columns;s++)t.set(r,s,t.get(r,s)/e[r])}(this,r),this;case"column":if(void 0===r)r=function(t){const e=[];for(let r=0;r<t.columns;r++){let s=0;for(let e=0;e<t.rows;e++)s+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(s))}return e}(this);else if(!at(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 n=0;n<t.rows;n++)r+=Math.pow(t.get(n,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 wt(this,t)}}function Rt(t,e){return t-e}At.prototype.klass="Matrix","undefined"!=typeof Symbol&&(At.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return wt(this)}),At.random=At.rand,At.randomInt=At.randInt,At.diagonal=At.diag,At.prototype.diagonal=At.prototype.diag,At.identity=At.eye,At.prototype.negate=At.prototype.neg,At.prototype.tensorProduct=At.prototype.kroneckerProduct;class Ft extends At{constructor(t,e){if(super(),Ft.isMatrix(t))return t.clone();if(Number.isInteger(t)&&t>=0){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e))}else{if(!at(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(!r[s].every((t=>"number"==typeof t)))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 bt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),bt(this,t,!0),e=Float64Array.from(xt(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){Mt(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),Mt(this,t,!0),e=vt(this,e);for(let r=0;r<this.rows;r++){const s=new Float64Array(this.columns+1);let n=0;for(;n<t;n++)s[n]=this.data[r][n];for(s[n++]=e[r];n<this.columns+1;n++)s[n]=this.data[r][n-1];this.data[r]=s}return this.columns+=1,this}}!function(t,e){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t);return this},t.prototype.addM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t.get(e,r));return this},t.add=function(t,r){return new e(t).add(r)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t);return this},t.prototype.subM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t.get(e,r));return this},t.sub=function(t,r){return new e(t).sub(r)},t.prototype.subtract=t.prototype.sub,t.prototype.subtractS=t.prototype.subS,t.prototype.subtractM=t.prototype.subM,t.subtract=t.sub,t.prototype.mul=function(t){return"number"==typeof t?this.mulS(t):this.mulM(t)},t.prototype.mulS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t);return this},t.prototype.mulM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t.get(e,r));return this},t.mul=function(t,r){return new e(t).mul(r)},t.prototype.multiply=t.prototype.mul,t.prototype.multiplyS=t.prototype.mulS,t.prototype.multiplyM=t.prototype.mulM,t.multiply=t.mul,t.prototype.div=function(t){return"number"==typeof t?this.divS(t):this.divM(t)},t.prototype.divS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t);return this},t.prototype.divM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t.get(e,r));return this},t.div=function(t,r){return new e(t).div(r)},t.prototype.divide=t.prototype.div,t.prototype.divideS=t.prototype.divS,t.prototype.divideM=t.prototype.divM,t.divide=t.div,t.prototype.mod=function(t){return"number"==typeof t?this.modS(t):this.modM(t)},t.prototype.modS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t);return this},t.prototype.modM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)%t.get(e,r));return this},t.mod=function(t,r){return new e(t).mod(r)},t.prototype.modulus=t.prototype.mod,t.prototype.modulusS=t.prototype.modS,t.prototype.modulusM=t.prototype.modM,t.modulus=t.mod,t.prototype.and=function(t){return"number"==typeof t?this.andS(t):this.andM(t)},t.prototype.andS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t);return this},t.prototype.andM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)&t.get(e,r));return this},t.and=function(t,r){return new e(t).and(r)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t);return this},t.prototype.orM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)|t.get(e,r));return this},t.or=function(t,r){return new e(t).or(r)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t);return this},t.prototype.xorM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)^t.get(e,r));return this},t.xor=function(t,r){return new e(t).xor(r)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t);return this},t.prototype.leftShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)<<t.get(e,r));return this},t.leftShift=function(t,r){return new e(t).leftShift(r)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>t.get(e,r));return this},t.signPropagatingRightShift=function(t,r){return new e(t).signPropagatingRightShift(r)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)>>>t.get(e,r));return this},t.rightShift=function(t,r){return new e(t).rightShift(r)},t.prototype.zeroFillRightShift=t.prototype.rightShift,t.prototype.zeroFillRightShiftS=t.prototype.rightShiftS,t.prototype.zeroFillRightShiftM=t.prototype.rightShiftM,t.zeroFillRightShift=t.rightShift,t.prototype.not=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,~this.get(t,e));return this},t.not=function(t){return new e(t).not()},t.prototype.abs=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.abs(this.get(t,e)));return this},t.abs=function(t){return new e(t).abs()},t.prototype.acos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acos(this.get(t,e)));return this},t.acos=function(t){return new e(t).acos()},t.prototype.acosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.acosh(this.get(t,e)));return this},t.acosh=function(t){return new e(t).acosh()},t.prototype.asin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asin(this.get(t,e)));return this},t.asin=function(t){return new e(t).asin()},t.prototype.asinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.asinh(this.get(t,e)));return this},t.asinh=function(t){return new e(t).asinh()},t.prototype.atan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atan(this.get(t,e)));return this},t.atan=function(t){return new e(t).atan()},t.prototype.atanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.atanh(this.get(t,e)));return this},t.atanh=function(t){return new e(t).atanh()},t.prototype.cbrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cbrt(this.get(t,e)));return this},t.cbrt=function(t){return new e(t).cbrt()},t.prototype.ceil=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.ceil(this.get(t,e)));return this},t.ceil=function(t){return new e(t).ceil()},t.prototype.clz32=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.clz32(this.get(t,e)));return this},t.clz32=function(t){return new e(t).clz32()},t.prototype.cos=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cos(this.get(t,e)));return this},t.cos=function(t){return new e(t).cos()},t.prototype.cosh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.cosh(this.get(t,e)));return this},t.cosh=function(t){return new e(t).cosh()},t.prototype.exp=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.exp(this.get(t,e)));return this},t.exp=function(t){return new e(t).exp()},t.prototype.expm1=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.expm1(this.get(t,e)));return this},t.expm1=function(t){return new e(t).expm1()},t.prototype.floor=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.floor(this.get(t,e)));return this},t.floor=function(t){return new e(t).floor()},t.prototype.fround=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.fround(this.get(t,e)));return this},t.fround=function(t){return new e(t).fround()},t.prototype.log=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log(this.get(t,e)));return this},t.log=function(t){return new e(t).log()},t.prototype.log1p=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log1p(this.get(t,e)));return this},t.log1p=function(t){return new e(t).log1p()},t.prototype.log10=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log10(this.get(t,e)));return this},t.log10=function(t){return new e(t).log10()},t.prototype.log2=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.log2(this.get(t,e)));return this},t.log2=function(t){return new e(t).log2()},t.prototype.round=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.round(this.get(t,e)));return this},t.round=function(t){return new e(t).round()},t.prototype.sign=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sign(this.get(t,e)));return this},t.sign=function(t){return new e(t).sign()},t.prototype.sin=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sin(this.get(t,e)));return this},t.sin=function(t){return new e(t).sin()},t.prototype.sinh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sinh(this.get(t,e)));return this},t.sinh=function(t){return new e(t).sinh()},t.prototype.sqrt=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.sqrt(this.get(t,e)));return this},t.sqrt=function(t){return new e(t).sqrt()},t.prototype.tan=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tan(this.get(t,e)));return this},t.tan=function(t){return new e(t).tan()},t.prototype.tanh=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.tanh(this.get(t,e)));return this},t.tanh=function(t){return new e(t).tanh()},t.prototype.trunc=function(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)this.set(t,e,Math.trunc(this.get(t,e)));return this},t.trunc=function(t){return new e(t).trunc()},t.pow=function(t,r){return new e(t).pow(r)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t));return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,Math.pow(this.get(e,r),t.get(e,r)));return this}}(At,Ft);class Ct extends At{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 zt{constructor(t){let e,r,s,n,o,i,h,a,l,u=(t=Ct.checkMatrix(t)).clone(),c=u.rows,f=u.columns,g=new Float64Array(c),m=1;for(e=0;e<c;e++)g[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),o=0,s=0;s<l;s++)o+=u.get(e,s)*a[s];a[e]-=o,u.set(e,r,a[e])}for(n=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[n])&&(n=e);if(n!==r){for(s=0;s<f;s++)i=u.get(n,s),u.set(n,s,u.get(r,s)),u.set(r,s,i);h=g[n],g[n]=g[r],g[r]=h,m=-m}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=g,this.pivotSign=m}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=Ft.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,n,o=t.columns,i=t.subMatrixRow(this.pivotVector,0,o-1),h=e.columns;for(n=0;n<h;n++)for(r=n+1;r<h;r++)for(s=0;s<o;s++)i.set(r,s,i.get(r,s)-i.get(n,s)*e.get(r,n));for(n=h-1;n>=0;n--){for(s=0;s<o;s++)i.set(n,s,i.get(n,s)/e.get(n,n));for(r=0;r<n;r++)for(s=0;s<o;s++)i.set(r,s,i.get(r,s)-i.get(n,s)*e.get(r,n))}return i}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let s=0;s<r;s++)e*=t.get(s,s);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new Ft(e,r);for(let n=0;n<e;n++)for(let e=0;e<r;e++)n>e?s.set(n,e,t.get(n,e)):n===e?s.set(n,e,1):s.set(n,e,0);return s}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,s=new Ft(e,r);for(let n=0;n<e;n++)for(let e=0;e<r;e++)n<=e?s.set(n,e,t.get(n,e)):s.set(n,e,0);return s}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function It(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 Tt{constructor(t){let e,r,s,n,o=(t=Ct.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(s=0;s<h;s++){let t=0;for(e=s;e<i;e++)t=It(t,o.get(e,s));if(0!==t){for(o.get(s,s)<0&&(t=-t),e=s;e<i;e++)o.set(e,s,o.get(e,s)/t);for(o.set(s,s,o.get(s,s)+1),r=s+1;r<h;r++){for(n=0,e=s;e<i;e++)n+=o.get(e,s)*o.get(e,r);for(n=-n/o.get(s,s),e=s;e<i;e++)o.set(e,r,o.get(e,r)+n*o.get(e,s))}}a[s]=-t}this.QR=o,this.Rdiag=a}solve(t){t=Ft.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,n,o,i,h=t.columns,a=t.clone(),l=e.columns;for(o=0;o<l;o++)for(n=0;n<h;n++){for(i=0,s=o;s<r;s++)i+=e.get(s,o)*a.get(s,n);for(i=-i/e.get(o,o),s=o;s<r;s++)a.set(s,n,a.get(s,n)+i*e.get(s,o))}for(o=l-1;o>=0;o--){for(n=0;n<h;n++)a.set(o,n,a.get(o,n)/this.Rdiag[o]);for(s=0;s<o;s++)for(n=0;n<h;n++)a.set(s,n,a.get(s,n)-a.get(o,n)*e.get(s,o))}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,n=new Ft(s,s);for(t=0;t<s;t++)for(e=0;e<s;e++)t<e?n.set(t,e,r.get(t,e)):t===e?n.set(t,e,this.Rdiag[t]):n.set(t,e,0);return n}get orthogonalMatrix(){let t,e,r,s,n=this.QR,o=n.rows,i=n.columns,h=new Ft(o,i);for(r=i-1;r>=0;r--){for(t=0;t<o;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<i;e++)if(0!==n.get(r,r)){for(s=0,t=r;t<o;t++)s+=n.get(t,r)*h.get(t,e);for(s=-s/n.get(r,r),t=r;t<o;t++)h.set(t,e,h.get(t,e)+s*n.get(t,r))}}return h}}class Dt{constructor(t,e={}){if((t=Ct.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,s=t.columns;const{computeLeftSingularVectors:n=!0,computeRightSingularVectors:o=!0,autoTranspose:i=!1}=e;let h,a=Boolean(n),l=Boolean(o),u=!1;if(r<s)if(i){h=t.transpose(),r=h.rows,s=h.columns,u=!0;let e=a;a=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let c=Math.min(r,s),f=Math.min(r+1,s),g=new Float64Array(f),m=new Ft(r,c),p=new Ft(s,s),w=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){g[t]=0;for(let e=t;e<r;e++)g[t]=It(g[t],h.get(e,t));if(0!==g[t]){h.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/g[t]);h.set(t,t,h.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<s;e++){if(t<b&&0!==g[t]){let s=0;for(let n=t;n<r;n++)s+=h.get(n,t)*h.get(n,e);s=-s/h.get(t,t);for(let n=t;n<r;n++)h.set(n,e,h.get(n,e)+s*h.get(n,t))}w[e]=h.get(t,e)}if(a&&t<b)for(let e=t;e<r;e++)m.set(e,t,h.get(e,t));if(t<M){w[t]=0;for(let e=t+1;e<s;e++)w[t]=It(w[t],w[e]);if(0!==w[t]){w[t+1]<0&&(w[t]=0-w[t]);for(let e=t+1;e<s;e++)w[e]/=w[t];w[t+1]+=1}if(w[t]=-w[t],t+1<r&&0!==w[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]+=w[r]*h.get(e,r);for(let e=t+1;e<s;e++){let s=-w[e]/w[t+1];for(let n=t+1;n<r;n++)h.set(n,e,h.get(n,e)+s*d[n])}}if(l)for(let e=t+1;e<s;e++)p.set(e,t,w[e])}}let v=Math.min(s,r+1);if(b<s&&(g[b]=h.get(b,b)),r<v&&(g[v-1]=0),M+1<v&&(w[M]=h.get(M,v-1)),w[v-1]=0,a){for(let t=b;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=b-1;t>=0;t--)if(0!==g[t]){for(let e=t+1;e<c;e++){let s=0;for(let n=t;n<r;n++)s+=m.get(n,t)*m.get(n,e);s=-s/m.get(t,t);for(let n=t;n<r;n++)m.set(n,e,m.get(n,e)+s*m.get(n,t))}for(let e=t;e<r;e++)m.set(e,t,-m.get(e,t));m.set(t,t,1+m.get(t,t));for(let e=0;e<t-1;e++)m.set(e,t,0)}else{for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}}if(l)for(let t=s-1;t>=0;t--){if(t<M&&0!==w[t])for(let e=t+1;e<s;e++){let r=0;for(let n=t+1;n<s;n++)r+=p.get(n,t)*p.get(n,e);r=-r/p.get(t+1,t);for(let n=t+1;n<s;n++)p.set(n,e,p.get(n,e)+r*p.get(n,t))}for(let e=0;e<s;e++)p.set(e,t,0);p.set(t,t,1)}let E=v-1,S=0,N=Number.EPSILON;for(;v>0;){let t,e;for(t=v-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+N*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(w[t])<=e||Number.isNaN(w[t])){w[t]=0;break}}if(t===v-2)e=4;else{let r;for(r=v-1;r>=t&&r!==t;r--){let e=(r!==v?Math.abs(w[r]):0)+(r!==t+1?Math.abs(w[r-1]):0);if(Math.abs(g[r])<=N*e){g[r]=0;break}}r===t?e=3:r===v-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=w[v-2];w[v-2]=0;for(let r=v-2;r>=t;r--){let n=It(g[r],e),o=g[r]/n,i=e/n;if(g[r]=n,r!==t&&(e=-i*w[r-1],w[r-1]=o*w[r-1]),l)for(let t=0;t<s;t++)n=o*p.get(t,r)+i*p.get(t,v-1),p.set(t,v-1,-i*p.get(t,r)+o*p.get(t,v-1)),p.set(t,r,n)}break}case 2:{let e=w[t-1];w[t-1]=0;for(let s=t;s<v;s++){let n=It(g[s],e),o=g[s]/n,i=e/n;if(g[s]=n,e=-i*w[s],w[s]=o*w[s],a)for(let e=0;e<r;e++)n=o*m.get(e,s)+i*m.get(e,t-1),m.set(e,t-1,-i*m.get(e,s)+o*m.get(e,t-1)),m.set(e,s,n)}break}case 3:{const e=Math.max(Math.abs(g[v-1]),Math.abs(g[v-2]),Math.abs(w[v-2]),Math.abs(g[t]),Math.abs(w[t])),n=g[v-1]/e,o=g[v-2]/e,i=w[v-2]/e,h=g[t]/e,u=w[t]/e,c=((o+n)*(o-n)+i*i)/2,f=n*i*(n*i);let d=0;0===c&&0===f||(d=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),d=f/(c+d));let y=(h+n)*(h-n)+d,b=h*u;for(let e=t;e<v-1;e++){let n=It(y,b);0===n&&(n=Number.MIN_VALUE);let o=y/n,i=b/n;if(e!==t&&(w[e-1]=n),y=o*g[e]+i*w[e],w[e]=o*w[e]-i*g[e],b=i*g[e+1],g[e+1]=o*g[e+1],l)for(let t=0;t<s;t++)n=o*p.get(t,e)+i*p.get(t,e+1),p.set(t,e+1,-i*p.get(t,e)+o*p.get(t,e+1)),p.set(t,e,n);if(n=It(y,b),0===n&&(n=Number.MIN_VALUE),o=y/n,i=b/n,g[e]=n,y=o*w[e]+i*g[e+1],g[e+1]=-i*w[e]+o*g[e+1],b=i*w[e+1],w[e+1]=o*w[e+1],a&&e<r-1)for(let t=0;t<r;t++)n=o*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+o*m.get(t,e+1)),m.set(t,e,n)}w[v-2]=y,S+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(g[t]>=g[t+1]);){let e=g[t];if(g[t]=g[t+1],g[t+1]=e,l&&t<s-1)for(let r=0;r<s;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(a&&t<r-1)for(let s=0;s<r;s++)e=m.get(s,t+1),m.set(s,t+1,m.get(s,t)),m.set(s,t,e);t++}S=0,v--}}if(u){let t=p;p=m,m=t}this.m=r,this.n=s,this.s=g,this.U=m,this.V=p}solve(t){let e=t,r=this.threshold,s=this.s.length,n=Ft.zeros(s,s);for(let t=0;t<s;t++)Math.abs(this.s[t])<=r?n.set(t,t,0):n.set(t,t,1/this.s[t]);let o=this.U,i=this.rightSingularVectors,h=i.mmul(n),a=i.rows,l=o.rows,u=Ft.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let n=0;n<s;n++)r+=h.get(t,n)*o.get(e,n);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(Ft.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,s=t.columns,n=new Ft(r,this.s.length);for(let o=0;o<r;o++)for(let r=0;r<s;r++)Math.abs(this.s[r])>e&&n.set(o,r,t.get(o,r)/this.s[r]);let o=this.U,i=o.rows,h=o.columns,a=new Ft(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let s=0;s<h;s++)r+=n.get(t,s)*o.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,n=r.length;s<n;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 Ft.diag(this.s)}}function Vt(t,e,r,s,n){let o=r*s*s,i=Ft.eye(e.length,e.length,o);const h=n(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,n){const o=r.length,i=t.x.length;let h=new Array(o);for(let a=0;a<o;a++){h[a]=new Array(i);let o=r.slice();o[a]+=s;let l=n(o);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new Ft(h)}(t,a,e,s,n),u=function(t,e){const r=t.x.length;let s=new Array(r);for(let n=0;n<r;n++)s[n]=[t.y[n]-e[n]];return new Ft(s)}(t,a),c=function(t,e=!1){return t=Ct.checkMatrix(t),e?new Dt(t).inverse():function(t,e,r=!1){return t=Ct.checkMatrix(t),e=Ct.checkMatrix(e),r?new Dt(t).solve(e):t.isSquare()?new zt(t).solve(e):new Tt(t).solve(e)}(t,Ft.eye(t.rows))}(i.add(l.mmul(l.transpose())));return(e=(e=new Ft([e])).sub(c.mmul(l).mmul(u).mul(s).transpose())).to1DArray()}const Ot=1e-5,qt=.001;class Pt{get neighbors(){return this.nNeighbors}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=15,this.distanceFn=jt,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new Lt;const e=e=>{void 0!==t[e]&&(this[e]=t[e])};e("distanceFn"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize"),this.targetNNeighbors=t.nNeighbors||this.nNeighbors||this.targetNNeighbors}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{initFromTree:t,initFromRandom:e}=(r=this.distanceFn,{initFromRandom:function(t,e,s,n,o){for(let i=0;i<s.length;i++){const h=F(t,e.length,o);for(let t=0;t<h.length;t++)h[t]<0||T(n,i,r(e[h[t]],s[i]),h[t],1)}},initFromTree:function(t,e,s,n,o){for(let i=0;i<s.length;i++){const h=st(s[i],t,o);for(let t=0;t<h.length;t++){if(h[t]<0)return;T(n,i,r(e[h[t]],s[i]),h[t],1)}}}});var r;this.initFromTree=t,this.initFromRandom=e,this.search=function(t){return function(e,r,s,n){const{indices:o,indptr:i}=K(r);for(let r=0;r<n.length;r++){const h=new Set(s[0][r]);for(;;){const a=P(s,r);if(-1===a)break;const l=o.slice(i[a],i[a+1]);for(const o of l)o===a||-1===o||h.has(o)||(D(s,r,t(e[o],n[r]),o,1),h.add(o))}}return s}}(this.distanceFn)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,s=[t.length,t.length],n=new j([],[],[],s);for(let t=0;t<e.length;t++){const s=e[t],o=r[t];for(let e=0;e<s.length;e++){const r=s[e],i=o[e];i>0&&n.set(t,r,i)}}return X(n,L(n),((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,n,o,i){const h=z(r.length,s);if(n(s,e,r,h,i),t)for(const s of t)o(s,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),n=this.search(e,this.searchGraph,s,t);let{indices:o,weights:i}=O(n);o=o.map((t=>t.slice(0,this.nNeighbors))),i=i.map((t=>t.slice(0,this.nNeighbors)));const h=Math.max(0,this.localConnectivity-1),{sigmas:a,rhos:l}=this.smoothKNNDistance(i,this.nNeighbors,h),{rows:u,cols:c,vals:f}=this.computeMembershipStrengths(o,i,a,l),g=[t.length,e.length];let m=new j(u,c,f,g);const p=K(G(m,"l1")),w=t.length,d=function(t,e,r){const s=k(t.length).map((t=>k(r[0].length)));for(let n=0;n<t.length;n++)for(let o=0;o<t[0].length;o++)for(let i=0;i<r[0].length;i++){const h=t[n][o];s[n][i]+=e[n][o]*r[h][i]}return s}(C(p.indices,w,this.nNeighbors),C(p.values,w,this.nNeighbors),this.embedding),y=this.nEpochs?this.nEpochs/3:m.nRows<=1e4?100:30,b=m.getValues().reduce(((t,e)=>e>t?e:t),0);m=m.map((t=>t<b/y?0:t)),m=Y(m);const M=this.makeEpochsPerSample(m.getValues(),y),x=m.getRows(),v=m.getCols();return this.assignOptimizationStateParameters({headEmbedding:d,tailEmbedding:this.embedding,head:x,tail:v,currentEpoch:0,nEpochs:y,nVertices:m.getDims()[1],epochsPerSample:M}),this.prepareForOptimizationLoop(),this.optimizeLayout()}processGraphForSupervisedProjection(){const{Y:t,X:e}=this;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){const e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}}step(){const{currentEpoch:t}=this.optimizationState;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch}getEmbedding(){return this.embedding}nearestNeighbors(t){const{distanceFn:e,nNeighbors:r}=this,s=function(t,e){return function(r,s,n,o=10,i=50,h=.001,a=.5,l=!0){const u=r.length,c=z(r.length,n);for(let s=0;s<r.length;s++){const o=I(n,r.length,e);for(let e=0;e<o.length;e++){const n=t(r[s],r[o[e]]);T(c,s,n,o[e],1),T(c,o[e],n,s,1)}}if(l)for(let e=0;e<s.length;e++)for(let n=0;n<s[e].length&&!(s[e][n]<0);n++)for(let o=n+1;o<s[e].length&&!(s[e][o]<0);o++){const i=t(r[s[e][n]],r[s[e][o]]);T(c,s[e][n],i,s[e][o],1),T(c,s[e][o],i,s[e][n],1)}for(let s=0;s<o;s++){const s=V(c,u,n,i,e);let o=0;for(let n=0;n<u;n++)for(let h=0;h<i;h++){const l=Math.floor(s[0][n][h]);if(!(l<0||v(e)<a))for(let e=0;e<i;e++){const i=Math.floor(s[0][n][e]),a=s[2][n][h],u=s[2][n][e];if(i<0||!a&&!u)continue;const f=t(r[l],r[i]);o+=T(c,l,f,i,1),o+=T(c,i,f,l,1)}}if(o<=h*n*r.length)break}return O(c)}}(e,this.random),n=5+Math.floor(.5==(o=t.length**.5/20)?0:Math.round(o));var o;const i=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));this.rpForest=H(t,r,n,this.random);const h=function(t){if(t.length>0){const e=[];for(const r of t)e.push(...r.indices);return e}return[[-1]]}(this.rpForest),{indices:a,weights:l}=s(t,h,r,i);return{knnIndices:a,knnDistances:l}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:s=[],knnDistances:n=[],localConnectivity:o}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(n,e,o),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(s,n,i,h),c=[t.length,t.length],f=new j(a,l,u,c),g=L(f),m=$(f,g),p=W(_(f,g),m);return _(U(p,r),U(m,1-r))}categoricalSimplicialSetIntersection(t,e,r,s=1){let n=function(t,e,r=1,s=5){return t.map(((t,n,o)=>-1===e[n]||-1===e[o]?t*Math.exp(-r):e[n]!==e[o]?t*Math.exp(-s):t))}(t,e,s,r);return n=Y(n),function(t){const e=L(t=G(t,"max"));return Y(t=_(t,W(e,$(e,t))))}(n)}smoothKNNDistance(t,e,r=1,s=64,n=1){const o=Math.log(e)/Math.log(2)*n,i=k(t.length),h=k(t.length);for(let e=0;e<t.length;e++){let n=0,a=1/0,l=1;const u=t[e],c=u.filter((t=>t>0));if(c.length>=r){const t=Math.floor(r),s=r-t;t>0?(i[e]=c[t-1],s>Ot&&(i[e]+=s*(c[t]-c[t-1]))):i[e]=s*c[0]}else c.length>0&&(i[e]=R(c));for(let r=0;r<s;r++){let r=0;for(let s=1;s<t[e].length;s++){const n=t[e][s]-i[e];r+=n>0?Math.exp(-n/l):1}if(Math.abs(r-o)<Ot)break;r>o?(a=l,l=(n+a)/2):(n=l,a===1/0?l*=2:l=(n+a)/2)}if(h[e]=l,i[e]>0){const t=A(u);h[e]<qt*t&&(h[e]=qt*t)}else{const r=A(t.map(A));h[e]<qt*r&&(h[e]=qt*r)}}return{sigmas:h,rhos:i}}computeMembershipStrengths(t,e,r,s){const n=t.length,o=t[0].length,i=k(n*o),h=k(n*o),a=k(n*o);for(let l=0;l<n;l++)for(let n=0;n<o;n++){let u=0;-1!==t[l][n]&&(u=t[l][n]===l?0:e[l][n]-s[l]<=0?1:Math.exp(-(e[l][n]-s[l])/r[l]),i[l*o+n]=l,h[l*o+n]=t[l][n],a[l*o+n]=u)}return{rows:i,cols:h,vals:a}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:e}=this,r=this.graph.getValues();let s=0;for(let t=0;t<r.length;t++){const e=r[t];s<r[t]&&(s=e)}const n=this.graph.map((e=>e<s/t?0:e));this.embedding=k(n.nRows).map((()=>k(e).map((()=>20*v(this.random)-10))));const o=[],i=[],h=[],a=n.getAll();for(let t=0;t<a.length;t++){const e=a[t];e.value&&(o.push(e.value),h.push(e.row),i.push(e.col))}return{head:i,tail:h,epochsPerSample:this.makeEpochsPerSample(o,t)}}makeEpochsPerSample(t,e){const r=N(t.length,-1),s=R(t),n=t.map((t=>t/s*e));return n.forEach(((t,s)=>{t>0&&(r[s]=e/n[s])})),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:s,headEmbedding:n,tailEmbedding:o}=this.optimizationState,i=n[0].length,h=n.length===o.length,a=s.map((t=>t/r)),l=[...a],u=[...s];this.assignOptimizationStateParameters({epochOfNextSample:u,epochOfNextNegativeSample:l,epochsPerNegativeSample:a,moveOther:h,initialAlpha:e,alpha:e,gamma:t,dim:i})}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:s,epochsPerSample:n}=this.optimizationState,o=this.getNEpochs(),i=this.graph.nCols,{a:h,b:a}=function(t,e){const r=function(t,e,r){return E(300).map(((t,r)=>0+r*((e-0)/299)))}(0,3*t).map((t=>t<e?1:t)),s=k(r.length).map(((s,n)=>r[n]>=e?Math.exp(-(r[n]-e)/t):s)),n={x:r,y:s},{parameterValues:o}=function(t,e,r={}){let{maxIterations:s=100,gradientDifference:n=.1,damping:o=0,errorTolerance:i=.01,minValues:h,maxValues:a,initialValues:l}=r;if(o<=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(!ot(t.x)||t.x.length<2||!ot(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(!ot(u))throw new Error("initialValues must be an array");let f,g=it(t,u,e),m=g<=i;for(f=0;f<s&&!m;f++){u=Vt(t,u,o,n,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(g=it(t,u,e),isNaN(g))break;m=g<=i}return{parameterValues:u,parameterError:g,iterations:f}}(n,(([t,e])=>r=>1/(1+t*r**(2*e))),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[i,h]=o;return{a:i,b:h}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:s,epochsPerSample:n,a:h,b:a,nEpochs:o,nVertices:i})}optimizeLayoutStep(t){const{optimizationState:e}=this,{head:r,tail:s,headEmbedding:n,tailEmbedding:o,epochsPerSample:i,epochOfNextSample:h,epochOfNextNegativeSample:a,epochsPerNegativeSample:l,moveOther:u,initialAlpha:c,alpha:f,gamma:g,a:m,b:p,dim:w,nEpochs:d,nVertices:y}=e;for(let e=0;e<i.length;e++){if(h[e]>t)continue;const c=r[e],d=s[e],b=n[c],M=o[d],v=_t(b,M);let E=0;v>0&&(E=-2*m*p*Math.pow(v,p-1),E/=m*Math.pow(v,p)+1);for(let t=0;t<w;t++){const e=$t(E*(b[t]-M[t]),4);b[t]+=e*f,u&&(M[t]+=-e*f)}h[e]+=i[e];const S=Math.floor((t-a[e])/l[e]);for(let t=0;t<S;t++){const t=x(y,this.random),e=o[t],r=_t(b,e);let s=0;if(r>0)s=2*g*p,s/=(.001+r)*(m*Math.pow(r,p)+1);else if(c===t)continue;for(let t=0;t<w;t++){let r=4;s>0&&(r=$t(s*(b[t]-e[t]),4)),b[t]+=r*f}}a[e]+=S*l[e]}return e.alpha=c*(1-t/d),e.currentEpoch+=1,n}optimizeLayoutAsync(t=(()=>!0)){return new Promise(((e,r)=>{const s=async()=>{try{const{nEpochs:r,currentEpoch:n}=this.optimizationState;this.embedding=this.optimizeLayoutStep(n);const o=this.optimizationState.currentEpoch,i=!1===t(o),h=o===r;if(i||h)return e(h);setTimeout((()=>s()),0)}catch(t){r(t)}};setTimeout((()=>s()),0)}))}optimizeLayout(t=(()=>!0)){let e=!1,r=[];for(;!e;){const{nEpochs:s,currentEpoch:n}=this.optimizationState;r=this.optimizeLayoutStep(n);const o=this.optimizationState.currentEpoch,i=!1===t(o);e=o===s||i}return r}getNEpochs(){const t=this.graph;if(this.nEpochs>0)return this.nEpochs;if(!t)return 200;const e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200}}function jt(t,e){return Math.abs(t-e)}class Lt{constructor(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0}}function $t(t,e){return t>e?e:t<-e?-e:t}function _t(t,e){let r=0;for(let s=0;s<t.length;s++)r+=Math.pow(t[s]-e[s],2);return r}var Wt=r(2590),Ut=r(9657),Yt=r(6377),Gt=r.n(Yt);class Qt{assert(t,e){if(!t)throw e||"Assertion failed"}getopt(t,e,r){return t.hasOwnProperty(e)?t[e]:r}gaussRandom(){if(this.returnV)return this.returnV=!1,this.vValue;const t=2*this.random()-1,e=2*this.random()-1,r=t*t+e*e;if(0===r||r>1)return this.gaussRandom();const s=Math.sqrt(-2*Math.log(r)/r);return this.vValue=e*s,this.returnV=!0,t*s}randn(t,e){return t+this.gaussRandom()*e}zeros(t){if(void 0===t||isNaN(t))return new Float32Array;if("undefined"==typeof ArrayBuffer){const e=new Float32Array(t);for(let r=0;r<t;r++)e[r]=0;return e}return new Float32Array(t)}randn2d(t,e,r){const s=void 0!==r,n=new Array(t).fill(null).map((()=>new Float32Array(e)));if(s)for(let s=0;s<t;s++)n[s]=new Float32Array(e).fill(r);else for(let r=0;r<t;r++)for(let t=0;t<e;t++)n[r][t]=this.randn(0,1e-4);return n}l2(t,e){const r=t.length;let s=0;for(let n=0;n<r;n++){const r=t[n],o=e[n];s+=(r-o)*(r-o)}return s}xtod(t){const e=t.length,r=this.zeros(e*e);for(let s=0;s<e;s++)for(let n=s+1;n<e;n++){const o=this.l2(t[s],t[n]);r[s*e+n]=o,r[n*e+s]=o}return r}getIterSize(t){return t<=2e3?100:t<=3e3?90:t<=5e3?80:70}d2p(t,e,r,s){const n=(i=s,(t,e)=>i*t+e-Math.floor((t+2)*(t+1)/2)),o=new Float32Array(s*s);var i;for(let e=0;e<s;e++)for(let r=e+1;r<s;r++)o[e*s+r]=o[r*s+e]=t[n(e,r)];const h=s,a=Math.log(e),l=this.zeros(h*h),u=this.zeros(h);for(let t=0;t<h;t++){let e=-1/0,n=1/0,i=1,c=!1;const f=Math.floor(this.getIterSize(s)/5);let g=0;for(;!c;){let s=0;for(let e=0;e<h;e++){const r=t===e?0:Math.exp(-o[t*h+e]*i);u[e]=r,s+=r}let l=0;for(let t=0;t<h;t++){let e;e=0===s?0:u[t]/s,u[t]=e,e>1e-7&&(l-=e*Math.log(e))}l>a?(e=i,n===1/0?i*=2:i=(i+n)/2):(n=i,e===-1/0?i/=2:i=(i+e)/2),g++,Math.abs(l-a)<r&&(c=!0),g>=f&&(c=!0)}for(let e=0;e<h;e++)l[t*h+e]=u[e]}const c=this.zeros(h*h),f=2*h;for(let t=0;t<h;t++)for(let e=0;e<h;e++)c[t*h+e]=Math.max((l[t*h+e]+l[e*h+t])/f,1e-100);return c}sign(t){return t>0?1:t<0?-1:0}constructor(t){this.iter=0,this.random=Math.random,this.returnV=!1,this.vValue=0,t=t||{},this.perplexity=this.getopt(t,"perplexity",30),this.dim=this.getopt(t,"dim",2),this.epsilon=this.getopt(t,"epsilon",10),this.random=this.getopt(t,"random",Math.random)}initDataRaw(t){const e=t.length,r=t[0].length;this.assert(e>0," X is empty? You must have some data!"),this.assert(r>0," X[0] is empty? Where is the data?");const s=this.xtod(t);this.P=this.d2p(s,this.perplexity,1e-4,r),this.N=e,this.initSolution()}initDataDist(t,e){const r=t.length;this.assert(r>0," X is empty? You must have some data!"),console.time("distances to matrix"),this.P=this.d2p(t,this.perplexity,1e-4,e),console.timeEnd("distances to matrix"),this.N=e,this.initSolution()}initSolution(){this.Y=this.randn2d(this.N,this.dim),this.gains=this.randn2d(this.N,this.dim,1),this.ystep=this.randn2d(this.N,this.dim,0),this.iter=0}getSolution(){return this.Y}step(){this.iter+=1;const t=this.N,e=this.costGrad(this.Y),r=e.cost,s=e.grad,n=this.zeros(this.dim);for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const r=s[e][t],o=this.ystep[e][t],i=this.gains[e][t];let h=this.sign(r)===this.sign(o)?.8*i:i+.2;h<.01&&(h=.01),this.gains[e][t]=h;const a=(this.iter<250?.5:.8)*o-this.epsilon*h*s[e][t];this.ystep[e][t]=a,this.Y[e][t]+=a,n[t]+=this.Y[e][t]}for(let e=0;e<t;e++)for(let r=0;r<this.dim;r++)this.Y[e][r]-=n[r]/t;return r}debugGrad(){const t=this.N,e=this.costGrad(this.Y).grad,r=1e-5;for(let s=0;s<t;s++)for(let t=0;t<this.dim;t++){const n=this.Y[s][t];this.Y[s][t]=n+r;const o=this.costGrad(this.Y);this.Y[s][t]=n-r;const i=this.costGrad(this.Y),h=e[s][t],a=(o.cost-i.cost)/(2*r);console.log(s+","+t+": gradcheck analytic: "+h+" vs. numerical: "+a),this.Y[s][t]=n}}costGrad(t){const e=this.N,r=this.dim,s=this.P,n=this.iter<100?4:1;this.quArr??(this.quArr=this.zeros(e*e));let o=0;for(let s=0;s<e;s++)for(let n=s+1;n<e;n++){const i=1/(1+new Array(r).reduce(((e,r,o)=>e+Math.pow(t[s][o]-t[n][o],2)),0));this.quArr[s*e+n]=i,this.quArr[n*e+s]=i,o+=2*i}let i=0;const h=new Array(e).fill(null).map((()=>new Float32Array(r).fill(0)));for(let a=0;a<e;a++)for(let l=a+1;l<e;l++){const u=Math.max(this.quArr[a*e+l]/o,1e-100);i+=-s[a*e+l]*Math.log(u)*2;const c=4*(n*s[a*e+l]-u)*this.quArr[a*e+l];for(let e=0;e<r;e++)h[a][e]+=c*(t[a][e]-t[l][e]),h[l][e]+=c*(t[l][e]-t[a][e])}return{cost:i,grad:h}}}class Xt{constructor(t){this.data=t.data,this.weights=t.weights,this.aggregationMethod=t.aggregationMethod}}class Kt extends Xt{constructor(t){super(t);const e=t.randomSeed??Date(),r=Gt()(e);t.random=r,this.reducer=new Qt(t),this.iterations=t?.iterations??this.reducer.getIterSize(this.data[0].length),this.distanceFnames=t.distanceFnames,this.distanceFns=t.distanceFns,this.distanceFnArgs=t.distanceFnArgs,this.progressFunc=t.progressFunc}async transform(){if(this.data[0].length>1e4)throw new Error("Maximum number of samples for T-SNE is 10000");const t=new M(!0,!1);try{const e=await t.calcMulti(this.data,this.distanceFnames,!1,this.distanceFnArgs,this.weights,this.aggregationMethod);t.terminate(),this.reducer.initDataDist(e,this.data[0].length);for(let t=0;t<this.iterations;++t)this.reducer.step(),this.progressFunc&&this.progressFunc(t,this.iterations,[]);return this.reducer.getSolution()}catch(e){throw t.terminate(),e}}}class Bt extends Xt{constructor(t){const e=t.randomSeed??Date(),r=Gt()(e);super(t),a("distanceFnames"in t),a("distanceFns"in t),this.distanceFnArgs=t.distanceFnArgs,this.distanceFns=t.distanceFns,this.progressFunc=t.progressFunc,this.distanceFnames=t.distanceFnames,this.vectors=new Array(this.data[0].length).fill(0).map(((t,e)=>e)),this.data[0].length<=(t.nNeighbors??15)&&(t.nNeighbors=this.data[0].length-1),t.random=r,this.reducer=new Pt(t)}async transform(t){console.time("knn graph");const e=await(new Wt._).multiColumnKNN(this.data,this.distanceFnames,this.reducer.neighbors,this.distanceFnArgs,this.weights,this.aggregationMethod);console.timeEnd("knn graph"),this.reducer.setPrecomputedKNN(e.knnIndexes,e.knnDistances),await new Promise((t=>{setTimeout((()=>{t()}),300)}));const r=await this.reducer.fitAsync(this.vectors,(t=>{this.progressFunc&&this.progressFunc(t,this.reducer.getNEpochs(),this.reducer.getEmbedding())}));return n=r,new Array(n.length).fill(0).map(((t,e)=>s.from(n[e])));var n}}const Ht={UMAP:Bt,"t-SNE":Kt};class Jt{constructor(t,e,r,s,n,o){const i=[];for(let e=0;e<r.length;++e){const s=new y(r[e]).getMeasure(o.distanceFnArgs[e]);i.push(s);let n=2048;for(let r=0;r<t[e].length;++r)if(t[e][r]&&t[e][r]._length){n=t[e][r]._length;break}if(h=r[e],"BitArray"==d[h])for(let r=0;r<t[e].length;++r)t[e][r]&&t[e][r]._data?t[e][r]=new Ut.Z(t[e][r]._data,t[e][r]._length):t[e][r]=new Ut.Z(n)}var h;"UMAP"==e?this.reducer=new Bt({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:s,aggregationMethod:n,...o}):"t-SNE"==e&&(this.reducer=new Kt({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:s,aggregationMethod:n,...o}))}async transform(t=!1){if(void 0===this.reducer)throw new Error("Reducer was not defined.");let e=await this.reducer.transform();var r;return t&&(r=e,e=new Array(r[0].length).fill(0).map(((t,e)=>new s(r.length).fill(0).map(((t,s)=>r[s][e]))))),e}static availableMetricsByType(t){return Object.keys(w[t])}static get availableMethods(){return Object.keys(Ht)}static get availableMetrics(){let t=[];return Object.values(w).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}async function Zt(t,e,r){t%5==0&&self.postMessage({epochNum:t,epochsLength:e,embedding:r})}self.onmessage=async({data:{columnsData:t,method:e,distanceMetrics:r,options:s,weights:n,aggregationMethod:o}})=>{let i;try{const h=await async function(t,e,r,s,n,o){const i=new Jt(t,e,r,s,n,{...o,progressFunc:Zt});return await i.transform(!0)}(t,e,r,n,o,s);i={embedding:h}}catch(t){i={error:t}}self.postMessage({error:i.error,embedding:i.embedding})}},6377:(t,e,r)=>{var s=r(4832),n=r(8652),o=r(801),i=r(2030),h=r(3618),a=r(9049),l=r(1971);l.alea=s,l.xor128=n,l.xorwow=o,l.xorshift7=i,l.xor4096=h,l.tychei=a,t.exports=l},4832:function(t,e,r){var s;!function(t,n,o){function i(t){var e,r=this,s=(e=4022871197,function(t){t=String(t);for(var r=0;r<t.length;r++){var s=.02519603282416938*(e+=t.charCodeAt(r));s-=e=s>>>0,e=(s*=e)>>>0,e+=4294967296*(s-=e)}return 2.3283064365386963e-10*(e>>>0)});r.next=function(){var t=2091639*r.s0+2.3283064365386963e-10*r.c;return r.s0=r.s1,r.s1=r.s2,r.s2=t-(r.c=0|t)},r.c=1,r.s0=s(" "),r.s1=s(" "),r.s2=s(" "),r.s0-=s(t),r.s0<0&&(r.s0+=1),r.s1-=s(t),r.s1<0&&(r.s1+=1),r.s2-=s(t),r.s2<0&&(r.s2+=1),s=null}function h(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function a(t,e){var r=new i(t),s=e&&e.state,n=r.next;return n.int32=function(){return 4294967296*r.next()|0},n.double=function(){return n()+11102230246251565e-32*(2097152*n()|0)},n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.alea=a}(0,t=r.nmd(t),r.amdD)},9049:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this,r="";e.next=function(){var t=e.b,r=e.c,s=e.d,n=e.a;return t=t<<25^t>>>7^r,r=r-s|0,s=s<<24^s>>>8^n,n=n-t|0,e.b=t=t<<20^t>>>12^r,e.c=r=r-s|0,e.d=s<<16^r>>>16^n,e.a=n-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):r+=t;for(var s=0;s<r.length+20;s++)e.b^=0|r.charCodeAt(s),e.next()}function h(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function a(t,e){var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.tychei=a}(0,t=r.nmd(t),r.amdD)},8652:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this,r="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:r+=t;for(var s=0;s<r.length+64;s++)e.x^=0|r.charCodeAt(s),e.next()}function h(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function a(t,e){var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xor128=a}(0,t=r.nmd(t),r.amdD)},3618:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this;e.next=function(){var t,r,s=e.w,n=e.X,o=e.i;return e.w=s=s+1640531527|0,r=n[o+34&127],t=n[o=o+1&127],r^=r<<13,t^=t<<17,r^=r>>>15,t^=t>>>12,r=n[o]=r^t,e.i=o,r+(s^s>>>16)|0},function(t,e){var r,s,n,o,i,h=[],a=128;for(e===(0|e)?(s=e,e=null):(e+="\0",s=0,a=Math.max(a,e.length)),n=0,o=-32;o<a;++o)e&&(s^=e.charCodeAt((o+32)%e.length)),0===o&&(i=s),s^=s<<10,s^=s>>>15,s^=s<<4,s^=s>>>13,o>=0&&(i=i+1640531527|0,n=0==(r=h[127&o]^=s+i)?n+1:0);for(n>=128&&(h[127&(e&&e.length||0)]=-1),n=127,o=512;o>0;--o)s=h[n+34&127],r=h[n=n+1&127],s^=s<<13,r^=r<<17,s^=s>>>15,r^=r>>>12,h[n]=s^r;t.w=i,t.X=h,t.i=n}(e,t)}function h(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function a(t,e){null==t&&(t=+new Date);var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&(s.X&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xor4096=a}(0,t=r.nmd(t),r.amdD)},2030:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this;e.next=function(){var t,r,s=e.x,n=e.i;return t=s[n],r=(t^=t>>>7)^t<<24,r^=(t=s[n+1&7])^t>>>10,r^=(t=s[n+3&7])^t>>>3,r^=(t=s[n+4&7])^t<<7,t=s[n+7&7],r^=(t^=t<<13)^t<<9,s[n]=r,e.i=n+1&7,r},function(t,e){var r,s=[];if(e===(0|e))s[0]=e;else for(e=""+e,r=0;r<e.length;++r)s[7&r]=s[7&r]<<15^e.charCodeAt(r)+s[r+1&7]<<13;for(;s.length<8;)s.push(0);for(r=0;r<8&&0===s[r];++r);for(8==r?s[7]=-1:s[r],t.x=s,t.i=0,r=256;r>0;--r)t.next()}(e,t)}function h(t,e){return e.x=t.x.slice(),e.i=t.i,e}function a(t,e){null==t&&(t=+new Date);var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&(s.x&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xorshift7=a}(0,t=r.nmd(t),r.amdD)},801:function(t,e,r){var s;!function(t,n,o){function i(t){var e=this,r="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:r+=t;for(var s=0;s<r.length+64;s++)e.x^=0|r.charCodeAt(s),s==r.length&&(e.d=e.x<<10^e.x>>>4),e.next()}function h(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function a(t,e){var r=new i(t),s=e&&e.state,n=function(){return(r.next()>>>0)/4294967296};return n.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},n.int32=r.next,n.quick=n,s&&("object"==typeof s&&h(s,r),n.state=function(){return h(r,{})}),n}n&&n.exports?n.exports=a:r.amdD&&r.amdO?void 0===(s=function(){return a}.call(e,r,e,n))||(n.exports=s):this.xorwow=a}(0,t=r.nmd(t),r.amdD)},1971:function(t,e,r){var s;!function(n,o,i){var h,a=256,l=6,u="random",c=i.pow(a,l),f=i.pow(2,52),g=2*f,m=a-1;function p(t,e,r){var s=[],m=b(y((e=1==e?{entropy:!0}:e||{}).entropy?[t,M(o)]:null==t?function(){try{var t;return h&&(t=h.randomBytes)?t=t(a):(t=new Uint8Array(a),(n.crypto||n.msCrypto).getRandomValues(t)),M(t)}catch(t){var e=n.navigator,r=e&&e.plugins;return[+new Date,n,r,n.screen,M(o)]}}():t,3),s),p=new w(s),x=function(){for(var t=p.g(l),e=c,r=0;t<f;)t=(t+r)*a,e*=a,r=p.g(1);for(;t>=g;)t/=2,e/=2,r>>>=1;return(t+r)/e};return x.int32=function(){return 0|p.g(4)},x.quick=function(){return p.g(4)/4294967296},x.double=x,b(M(p.S),o),(e.pass||r||function(t,e,r,s){return s&&(s.S&&d(s,p),t.state=function(){return d(p,{})}),r?(i[u]=t,e):t})(x,m,"global"in e?e.global:this==i,e.state)}function w(t){var e,r=t.length,s=this,n=0,o=s.i=s.j=0,i=s.S=[];for(r||(t=[r++]);n<a;)i[n]=n++;for(n=0;n<a;n++)i[n]=i[o=m&o+t[n%r]+(e=i[n])],i[o]=e;(s.g=function(t){for(var e,r=0,n=s.i,o=s.j,i=s.S;t--;)e=i[n=m&n+1],r=r*a+i[m&(i[n]=i[o=m&o+e])+(i[o]=e)];return s.i=n,s.j=o,r})(a)}function d(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function y(t,e){var r,s=[],n=typeof t;if(e&&"object"==n)for(r in t)try{s.push(y(t[r],e-1))}catch(t){}return s.length?s:"string"==n?t:t+"\0"}function b(t,e){for(var r,s=t+"",n=0;n<s.length;)e[m&n]=m&(r^=19*e[m&n])+s.charCodeAt(n++);return M(e)}function M(t){return String.fromCharCode.apply(0,t)}if(b(i.random(),o),t.exports){t.exports=p;try{h=r(5042)}catch(t){}}else void 0===(s=function(){return p}.call(e,r,e,t))||(t.exports=s)}("undefined"!=typeof self?self:this,[],Math)}}]);
|
|
3
3
|
//# sourceMappingURL=895.js.map
|