@datagrok/bio 2.11.28 → 2.11.30

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/23.js +2 -0
  3. package/dist/23.js.map +1 -0
  4. package/dist/282.js +2 -0
  5. package/dist/282.js.map +1 -0
  6. package/dist/36.js +2 -0
  7. package/dist/36.js.map +1 -0
  8. package/dist/40.js +2 -0
  9. package/dist/40.js.map +1 -0
  10. package/dist/413.js +2 -0
  11. package/dist/413.js.map +1 -0
  12. package/dist/42.js +1 -1
  13. package/dist/42.js.map +1 -1
  14. package/dist/427.js +2 -0
  15. package/dist/427.js.map +1 -0
  16. package/dist/65.js +2 -0
  17. package/dist/65.js.map +1 -0
  18. package/dist/709.js +3 -0
  19. package/dist/709.js.map +1 -0
  20. package/dist/package-test.js +1 -1
  21. package/dist/package-test.js.map +1 -1
  22. package/dist/package.js +1 -1
  23. package/dist/package.js.map +1 -1
  24. package/files/tests/to-atomic-level-msa-fasta-input.csv +10 -0
  25. package/files/tests/to-atomic-level-msa-fasta-output.csv +2178 -0
  26. package/package.json +9 -9
  27. package/src/package.ts +12 -10
  28. package/src/tests/msa-tests.ts +2 -2
  29. package/src/tests/pepsea-tests.ts +1 -1
  30. package/src/tests/renderers-test.ts +16 -16
  31. package/src/tests/splitters-test.ts +7 -12
  32. package/src/tests/substructure-filters-tests.ts +277 -55
  33. package/src/tests/to-atomic-level-tests.ts +32 -22
  34. package/src/tests/utils/sequences-generators.ts +6 -3
  35. package/src/tests/utils.ts +6 -6
  36. package/src/utils/cell-renderer.ts +2 -0
  37. package/src/utils/docker.ts +36 -0
  38. package/src/viewers/vd-regions-viewer.ts +4 -0
  39. package/src/viewers/web-logo-viewer.ts +4 -0
  40. package/src/widgets/bio-substructure-filter-helm.ts +168 -0
  41. package/src/widgets/bio-substructure-filter-types.ts +131 -0
  42. package/src/widgets/bio-substructure-filter.ts +215 -175
  43. package/src/widgets/composition-analysis-widget.ts +1 -1
  44. package/dist/100.js +0 -2
  45. package/dist/100.js.map +0 -1
  46. package/dist/118.js +0 -2
  47. package/dist/118.js.map +0 -1
  48. package/dist/361.js +0 -2
  49. package/dist/361.js.map +0 -1
  50. package/dist/471.js +0 -2
  51. package/dist/471.js.map +0 -1
  52. package/dist/649.js +0 -2
  53. package/dist/649.js.map +0 -1
  54. package/dist/664.js +0 -2
  55. package/dist/664.js.map +0 -1
  56. package/dist/886.js +0 -3
  57. package/dist/886.js.map +0 -1
  58. /package/dist/{886.js.LICENSE.txt → 709.js.LICENSE.txt} +0 -0
package/dist/709.js ADDED
@@ -0,0 +1,3 @@
1
+ /*! For license information please see 709.js.LICENSE.txt */
2
+ (self.webpackChunkbio=self.webpackChunkbio||[]).push([[709],{6709:(t,e,r)=>{"use strict";class n extends Float32Array{}var s=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={[s.CF.Euclidean]:function(t,e){let r=0;const n=t.length;if(n!==e.length)throw new Error("The dimensionality of the vectors must match");for(let s=0;s<n;++s)r+=Math.pow(t[s]-e[s],2);return Math.sqrt(r)}},c={[s.W.Levenshtein]:o.T,[s.W.JaroWinkler]:i.H$,[s.W.Manhattan]:function(t,e){if(t.length!==e.length)return 1;{let r=0;for(let n=1;n<t.length;n++)r+=t[n]==e[n]?0:1;return r/t.length}},[s.W.Onehot]:function(t,e){return t===e?0:1}},f={[s.gk.Tanimoto]:h.KR,[s.gk.Dice]:h._h,[s.gk.Asymmetric]:h.yU,[s.gk.BraunBlanquet]:h.Dz,[s.gk.Cosine]:h.Zd,[s.gk.Kulczynski]:h.s,[s.gk.McConnaughey]:h.aW,[s.gk.RogotGoldberg]:h.MI,[s.gk.Russel]:h.fX,[s.gk.Sokal]:h.NB,[s.gk.Hamming]:h.UX,[s.gk.Euclidean]:h.WI},g={[s.gd.TanimotoIntArray]:h.FV},m={[s.Yc.Difference]:h.bX},w={[s.Qe.Vector]:{[s.CF.Euclidean]:u[s.CF.Euclidean]},[s.Qe.String]:{[s.W.Levenshtein]:c[s.W.Levenshtein],[s.W.JaroWinkler]:c[s.W.JaroWinkler],[s.W.Manhattan]:c[s.W.Manhattan],[s.W.Onehot]:c[s.W.Onehot]},[s.Qe.BitArray]:{[s.gk.Tanimoto]:f[s.gk.Tanimoto],[s.gk.Dice]:f[s.gk.Dice],[s.gk.Asymmetric]:f[s.gk.Asymmetric],[s.gk.BraunBlanquet]:f[s.gk.BraunBlanquet],[s.gk.Cosine]:f[s.gk.Cosine],[s.gk.Kulczynski]:f[s.gk.Kulczynski],[s.gk.McConnaughey]:f[s.gk.McConnaughey],[s.gk.RogotGoldberg]:f[s.gk.RogotGoldberg],[s.gk.Russel]:f[s.gk.Russel],[s.gk.Sokal]:f[s.gk.Sokal]},[s.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]},[s.Qe.Number]:{[s.Yc.Difference]:m[s.Yc.Difference]},[s.Qe.IntArray]:{[s.gd.TanimotoIntArray]:g[s.gd.TanimotoIntArray]}},p=Object.keys(w).reduce(((t,e)=>{for(const r of Object.keys(w[e]))t[r]=e;return t}),{});class d{method;dataType;constructor(t){this.method=t,this.dataType=p[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 r=this.method,p[r]==s.Qe.MacroMolecule.toString()||function(t){return p[t]==s.Qe.Number.toString()}(this.method)?e[this.dataType][this.method](t):e[this.dataType][this.method];var r}static getMetricByDataType(t){return Object.keys(w[t])}static get availableMeasures(){return Object.keys(w)}}var y,b;(b=y||(y={})).EUCLIDEAN="EUCLIDEAN",b.MANHATTAN="MANHATTAN";const M=t=>null==t;function x(t,e,r,n){if(r>t[t.length-1])return;const s=t.findIndex((t=>r<t));t.pop(),t.splice(s,0,r),e.pop(),e.splice(s,0,n)}class v{_workers;_workerCount;_terminateOnComplete;constructor(t=!0,e=!0){const n=navigator.hardwareConcurrency;this._workerCount=t?Math.max(n-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,n){return await this.calcMulti([t],[e],r,[n??{}],[1],y.MANHATTAN)}async calcMulti(t,e,r=!0,n=[{}],s=[1],o=y.MANHATTAN){if(t.length<1)throw new Error("values must contain at least one array");if(e.length!==t.length||n.length!==t.length||s.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,w=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const i=Math.floor(r*u),p=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*p+4*h*(h-1)-7)/2-.5),g=p-h*f+Math.floor((f+1)*(f+2)/2)),this._workers[r].postMessage({values:t,fnNames:e,startRow:d,startCol:y,chunckSize:p-i,opts:n,weights:s,aggregationMethod:o}),a[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:n,distanceMatrixData:s,min:o,max:h}})=>{this._terminateOnComplete&&setTimeout((()=>this._workers[r].terminate())),n?e(n):(c.set(s,i),o<m&&(m=o),h>w&&(w=h),t())}}))}await Promise.all(a),r&&c.forEach(((t,e)=>{c[e]=(t-m)/(w-m)})),i(c)}catch(t){h(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}function E(t,e){return Math.floor(e()*t)}function k(t){return t()}function S(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function N(t){return S(t).map(((t,e)=>e))}function A(t,e){return S(t).map((()=>e))}function C(t){return A(t,0)}function R(t){return function(t){return t.reduce(((t,e)=>t+e))}(t)/t.length}function I(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 n=C(t);for(let s=0;s<t;s++){let t=!0;for(;t;){const o=E(e,r);let i=!1;for(let t=0;t<s;t++)if(o===n[t]){i=!0;break}i||(t=!1),n[s]=o}}return n}function T(t,e,r){const n=[];let s=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 n=0;n<r;n++)e.push(t[s]),s+=1;n.push(e)}return n}function z(t,e){const r=r=>S(t).map((()=>A(e,r))),n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function D(t,e,r){const n=C(t);for(let s=0;s<t;s++){let t=!0,o=0;for(;t;){o=E(e,r);let i=!1;for(let t=0;t<s;t++)if(o===n[t]){i=!0;break}i||(t=!1)}n[s]=o}return n}function V(t,e,r,n,s){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(n===o[t])return 0;return _(t,e,r,n,s)}function _(t,e,r,n,s){const o=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,o[0]=n,h[0]=s;let a=0,l=0;for(;;){const e=2*a+1,n=e+1,s=t[0][0].length;if(e>=s)break;if(n>=s){if(!(i[e]>r))break;l=e}else if(i[e]>=i[n]){if(!(r<i[e]))break;l=e}else{if(!(r<i[n]))break;l=n}i[a]=i[l],o[a]=o[l],h[a]=h[l],a=l}return i[a]=r,o[a]=n,h[a]=s,1}function P(t,e,r,n,s){const o=z(e,n);for(let n=0;n<e;n++)for(let e=0;e<r;e++){if(t[0][n][e]<0)continue;const r=t[0][n][e],i=t[2][n][e],h=k(s);V(o,n,h,r,i),V(o,r,h,n,i),t[2][n][e]=0}return o}function O(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const n=e[t],s=r[t];for(let t=0;t<n.length-1;t++){const e=n.length-t-1,r=s.length-t-1,o=n[0];n[0]=n[e],n[e]=o;const i=s[0];s[0]=s[r],s[r]=i,q(s,n,r,0)}}return{indices:e,weights:r}}function q(t,e,r,n){for(;2*n+1<r;){const s=2*n+1,o=s+1;let i=n;if(t[i]<t[s]&&(i=s),o<r&&t[i]<t[o]&&(i=o),i===n)break;{const r=t[n];t[n]=t[i],t[i]=r;const s=e[n];e[n]=e[i],e[i]=s,n=i}}}function L(t,e){const r=t[0][e],n=t[1][e],s=t[2][e];let o=1/0,i=-1;for(let t=0;t>r.length;t++)1===s[t]&&n[t]<o&&(o=n[t],i=t);return i>=0?(s[i]=0,Math.floor(r[i])):-1}class j{entries=new Map;nRows=0;nCols=0;constructor(t,e,r,n){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=n[0],this.nCols=n[1];for(let n=0;n<r.length;n++){const s=t[n],o=e[n];this.checkDims(s,o);const i=this.makeKey(s,o);this.entries.set(i,{value:r[n],row:s,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 n=this.makeKey(t,e);this.entries.has(n)?this.entries.get(n).value=r:this.entries.set(n,{value:r,row:t,col:e})}get(t,e,r=0){const n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).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((n=>{e[r++]=t(n.value,n.row,n.col)}));const n=[this.nRows,this.nCols];return new j(this.getRows(),this.getCols(),e,n)}toArray(){const t=S(this.nRows).map((()=>C(this.nCols)));return this.entries.forEach((e=>{t[e.row][e.col]=e.value})),t}}function U(t){const e=t.getRows(),r=t.getCols(),n=t.getValues(),s=r.length,o=new Int32Array(s),i=new Int32Array(s),h=new Float32Array(s);o.set(e),i.set(r),h.set(n);const a=[t.nCols,t.nRows];return new j(i,o,h,a)}function $(t,e){return B(t,e,((t,e)=>t*e))}function W(t,e){return B(t,e,((t,e)=>t+e))}function Y(t,e){return B(t,e,((t,e)=>t-e))}function G(t,e){return t.map((t=>t*e))}function K(t){const e=new Set,r=t.getValues(),n=t.getRows(),s=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=n.filter(o),a=s.filter(o);return new j(h,a,i,t.getDims())}function X(t,e="l2"){const r=Q[e],n=new Map;t.forEach(((t,e,r)=>{const s=n.get(e)||[];s.push(r),n.set(e,s)}));const s=new j([],[],[],t.getDims());for(const e of n.keys()){const o=n.get(e).sort(),i=r(o.map((r=>t.get(e,r))));for(let t=0;t<i.length;t++)s.set(e,o[t],i[t])}return s}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 B(t,e,r){const n=new Set,s=[],o=[],i=[],h=(n,h)=>{s.push(n),o.push(h);const a=r(t.get(n,h),e.get(n,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],s=`${e}:${r}`;n.add(s),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],s=`${e}:${r}`;n.has(s)||h(e,r)}const m=[t.nRows,t.nCols];return new j(s,o,i,m)}function H(t){const e=[];t.forEach(((t,r,n)=>{e.push({value:t,row:r,col:n})})),e.sort(((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row));const r=[],n=[],s=[];let o=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==o&&(o=i,s.push(t)),r.push(h),n.push(a)}return{indices:r,values:n,indptr:s}}class J{hyperplanes;offsets;children;indices;constructor(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n}}function Z(t,e,r,n){const s=Math.max(10,e),o=N(r).map(((e,r)=>function(t,e=30,r,n){return tt(t,N(t.length),e,r,n)}(t,s,r,n))),i=o.map((t=>function(t,e){const r=rt(t),n=nt(t),s=N(r).map((()=>t.hyperplane?1:0)),o=C(r),i=N(r).map((()=>[-1,-1])),h=N(n).map((()=>N(e).map((()=>-1))));return et(t,s,o,i,h,0,0),new J(s,o,i,h)}(t,s)));return i}function tt(t,e,r=30,n,s){if(e.length>r){const o=function(t,e,r){const n=E(e.length,r);let s=E(e.length,r);s+=n===s?1:0,s%=e.length;const o=e[n],i=e[s];let h=0,a=0;a=t[o]-t[i],h-=a*(t[o]+t[i])/2;let l=0,u=0;const c=C(e.length);for(let n=0;n<e.length;n++){let s=h;s+=a*t[e[n]],0===s?(c[n]=E(2,r),0===c[n]?l+=1:u+=1):s>0?(c[n]=0,l+=1):(c[n]=1,u+=1)}const f=C(l),g=C(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,s),{indicesLeft:i,indicesRight:h,hyperplane:a,offset:l}=o;return{leftChild:tt(t,i,r,n+1,s),rightChild:tt(t,h,r,n+1,s),isLeaf:!1,hyperplane:a,offset:l}}return{indices:e,isLeaf:!0}}function et(t,e,r,n,s,o,i){if(t.isLeaf)return n[o][0]=-i,s[i].splice(0,t.indices.length,...t.indices),{nodeNum:o,leafNum:i+=1};{e[o]=t.hyperplane,r[o]=t.offset,n[o][0]=o+1;const h=o;let a=et(t.leftChild,e,r,n,s,o+1,i);return o=a.nodeNum,i=a.leafNum,n[h][1]=o+1,a=et(t.rightChild,e,r,n,s,o+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function rt(t){return t.isLeaf?1:1+rt(t.leftChild)+rt(t.rightChild)}function nt(t){return t.isLeaf?1:nt(t.leftChild)+nt(t.rightChild)}function st(t,e,r,n){let s=e;return s+=t*r,0===s?E(2,n):s>0?0:1}function ot(t,e,r){let n=0;for(;e.children[n][0]>0;)n=0===st(e.hyperplanes[n],e.offsets[n],t,r)?e.children[n][0]:e.children[n][1];const s=-1*e.children[n][0];return e.indices[s]}const it=Object.prototype.toString;function ht(t){return it.call(t).endsWith("Array]")}function at(t,e,r){let n=0;const s=r(e);for(let e=0;e<t.x.length;e++)n+=Math.abs(t.y[e]-s(t.x[e]));return n}const lt=Object.prototype.toString;function ut(t){return lt.call(t).endsWith("Array]")}const ct=Object.prototype.toString;function ft(t){return ct.call(t).endsWith("Array]")}const gt=Object.prototype.toString;const mt=Object.prototype.toString;function wt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!ft(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(!ft(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var n=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!mt.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 n=r.fromIndex,s=void 0===n?0:n,o=r.toIndex,i=void 0===o?t.length:o;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=s||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[s],a=s+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!gt.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 n=r.fromIndex,s=void 0===n?0:n,o=r.toIndex,i=void 0===o?t.length:o;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=s||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[s],a=s+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(n===s)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?n:0:o,h=r.max,a=void 0===h?r.autoMinMax?s:1:h;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-i)/(s-n),u=0;u<t.length;u++)e[u]=(t[u]-n)*l+i;return e}const pt=" ".repeat(2),dt=" ".repeat(4);function yt(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:s=8,padMinus:o="auto"}=e;return`${t.constructor.name} {\n${pt}[\n${dt}${function(t,e,r,n,s){const{rows:o,columns:i}=t,h=Math.min(o,e),a=Math.min(i,r),l=[];if("auto"===s){s=!1;t:for(let e=0;e<h;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let o=0;o<a;o++)r.push(bt(t.get(e,o),n,s));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${dt}`)}(t,r,n,s,o)}\n${pt}]\n${pt}rows: ${t.rows}\n${pt}columns: ${t.columns}\n}`}function bt(t,e,r){return(t>=0&&r?` ${Mt(t,e-1)}`:Mt(t,e)).padEnd(e)}function Mt(t,e){let r=t.toString();if(r.length<=e)return r;let n=t.toFixed(e);if(n.length>e&&(n=t.toFixed(Math.max(0,e-(n.length-e)))),n.length<=e&&!n.startsWith("0.000")&&!n.startsWith("-0.000"))return n;let s=t.toExponential(e);return s.length>e&&(s=t.toExponential(Math.max(0,e-(s.length-e)))),s.slice(0)}function xt(t,e,r){let n=r?t.rows:t.rows-1;if(e<0||e>n)throw new RangeError("Row index out of range")}function vt(t,e,r){let n=r?t.columns:t.columns-1;if(e<0||e>n)throw new RangeError("Column index out of range")}function Et(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 kt(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 St(t,e,r,n,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(At("startRow",e),At("endRow",r),At("startColumn",n),At("endColumn",s),e>r||n>s||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||s<0||s>=t.columns)throw new RangeError("Submatrix indices are out of range")}function Nt(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function At(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function Ct(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class Rt{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new Ft(t,e);for(let s=0;s<t;s++)for(let t=0;t<e;t++)n.set(s,t,r[s*e+t]);return n}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:n=Math.random}=r;let s=new Ft(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,n());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:o=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let i=s-n,h=new Ft(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+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 n=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<n;t++)s.set(t,t,r);return s}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let s=Math.min(n,e,r),o=this.zeros(e,r);for(let e=0;e<s;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,n=t.columns,s=new Ft(r,n);for(let o=0;o<r;o++)for(let r=0;r<n;r++)s.set(o,r,Math.min(t.get(o,r),e.get(o,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let o=0;o<r;o++)for(let r=0;r<n;r++)s.set(o,r,Math.max(t.get(o,r),e.get(o,r)));return s}static checkMatrix(t){return Rt.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,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/s);for(let n=e+1;n<t.rows;n++){let s=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let o=r+1;o<t.columns;o++)t.set(n,o,t.get(n,o)-t.get(e,o)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let s=0,o=!1;for(;s<r&&!1===o;)1===t.get(n,s)?o=!0:s++;for(let r=0;r<n;r++){let o=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-o*t.get(n,i);t.set(r,i,e)}}n--}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 n=new Ft(this.rows*e,this.columns*r);for(let t=0;t<e;t++)for(let e=0;e<r;e++)n.setSubMatrix(this,this.rows*t,this.columns*e);return n}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){xt(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){xt(this,t),e=Et(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){xt(this,t),xt(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){vt(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){vt(this,t),e=kt(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){vt(this,t),vt(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=Et(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=Et(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=Et(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=Et(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=kt(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=kt(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=kt(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=kt(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){xt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){vt(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(){Ct(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);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(){Ct(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(xt(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){xt(this,t),Ct(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(xt(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){xt(this,t),Ct(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(vt(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){vt(this,t),Ct(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(vt(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){vt(this,t),Ct(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);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){Rt.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 n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=Ft.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new Ft(e,n),o=new Float64Array(r);for(let i=0;i<n;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 n=0;n<r;n++)e+=this.get(t,n)*o[n];s.set(t,i,e)}}return s}strassen2x2(t){t=Ft.checkMatrix(t);let e=new Ft(2,2);const r=this.get(0,0),n=t.get(0,0),s=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)*(n+l),c=(i+a)*n,f=r*(o-l),g=a*(h-n),m=(r+s)*l,w=u+g-m+(s-a)*(h+l),p=f+m,d=c+g,y=u-c+f+(i-r)*(n+o);return e.set(0,0,w),e.set(0,1,p),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=Ft.checkMatrix(t);let e=new Ft(3,3);const r=this.get(0,0),n=this.get(0,1),s=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),w=t.get(1,1),p=t.get(1,2),d=t.get(2,0),y=t.get(2,1),b=t.get(2,2),M=(r-o)*(-f+w),x=(-r+o+i)*(c-f+w),v=(o+i)*(-c+f),E=r*c,k=(-r+a+l)*(c-g+p),S=(-r+a)*(g-p),N=(a+l)*(-c+g),A=(-s+l+u)*(w+d-y),C=(s-u)*(w-y),R=s*d,I=(l+u)*(-d+y),F=(-s+i+h)*(p+d-b),T=(s-h)*(p-b),z=(i+h)*(-d+b),D=E+R+n*m,V=(r+n+s-o-i-l-u)*w+x+v+E+A+R+I,_=E+k+N+(r+n+s-i-h-a-l)*p+R+F+z,P=M+i*(-c+f+m-w-p-d+b)+x+E+R+F+T,O=M+x+v+E+h*y,q=R+F+T+z+o*g,L=E+k+S+l*(-c+g+m-w-p-d+y)+A+C+R,j=A+C+R+I+a*f,U=E+k+S+N+u*b;return e.set(0,0,D),e.set(0,1,V),e.set(0,2,_),e.set(1,0,P),e.set(1,1,O),e.set(1,2,q),e.set(2,0,L),e.set(2,1,j),e.set(2,2,U),e}mmulStrassen(t){t=Ft.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,o=t.columns;function i(t,e,r){let n=t.rows,s=t.columns;if(n===e&&s===r)return t;{let n=Rt.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${o} matrix: dimensions do not match.`);let h=Math.max(r,s),a=Math.max(n,o);return e=i(e,h,a),function t(e,r,n,s){if(n<=512||s<=512)return e.mmul(r);n%2==1&&s%2==1?(e=i(e,n+1,s+1),r=i(r,n+1,s+1)):n%2==1?(e=i(e,n+1,s),r=i(r,n+1,s)):s%2==1&&(e=i(e,n,s+1),r=i(r,n,s+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),w=r.subMatrix(o,r.rows-1,h,r.columns-1),p=t(Rt.add(a,m),Rt.add(l,w),o,h),d=t(Rt.add(f,m),l,o,h),y=t(a,Rt.sub(c,w),o,h),b=t(m,Rt.sub(g,l),o,h),M=t(Rt.add(a,u),w,o,h),x=t(Rt.sub(f,a),Rt.add(l,c),o,h),v=t(Rt.sub(u,m),Rt.add(g,w),o,h),E=Rt.add(p,b);E.sub(M),E.add(v);let k=Rt.add(y,M),S=Rt.add(d,b),N=Rt.sub(p,d);N.add(y),N.add(x);let A=Rt.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(k,E.rows,0),A=A.setSubMatrix(S,0,E.columns),A=A.setSubMatrix(N,E.rows,E.columns),A.subMatrix(0,n-1,0,s-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 n=new Ft(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&wt(s,{min:e,max:r,output:s}),n.setRow(t,s)}return n}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 n=new Ft(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&wt(s,{min:e,max:r,output:s}),n.setColumn(t,s)}return n}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),n=this.get(e,this.columns-1-r);this.set(e,r,n),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),n=this.get(this.rows-1-r,e);this.set(r,e,n),this.set(this.rows-1-r,e,t)}return this}kroneckerProduct(t){t=Ft.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,o=new Ft(e*n,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let h=0;h<s;h++)o.set(n*i+r,s*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,n=this.kroneckerProduct(Ft.eye(r,r)),s=Ft.eye(e,e).kroneckerProduct(t);return n.add(s)}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=It){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=It){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){St(this,t,e,r,n);let s=new Ft(e-t+1,n-r+1);for(let o=t;o<=e;o++)for(let e=r;e<=n;e++)s.set(o-t,e-r,this.get(o,e));return s}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 n=new Ft(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let o=e;o<=r;o++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,o-e,this.get(t[s],o))}return n}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 n=new Ft(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let o=e;o<=r;o++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(o-e,s,this.get(o,t[s]))}return n}setSubMatrix(t,e,r){if((t=Ft.checkMatrix(t)).isEmpty())return this;St(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let s=0;s<t.columns;s++)this.set(e+n,r+s,t.get(n,s));return this}selection(t,e){!function(t,e){if(!ut(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(!ut(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 n=0;n<t.length;n++){let s=t[n];for(let t=0;t<e.length;t++){let o=e[t];r.set(n,t,this.get(s,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=Nt(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=Nt(t.columns);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]+=t.get(r,n);return e}(this);case void 0:return function(t){let e=0;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e+=t.get(r,n);return e}(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return function(t){let e=Nt(t.rows,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]*=t.get(r,n);return e}(this);case"column":return function(t){let e=Nt(t.columns,1);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[n]*=t.get(r,n);return e}(this);case void 0:return function(t){let e=1;for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)e*=t.get(r,n);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:n=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!ut(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=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(i,e)-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,n);case"column":if(!ut(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=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(e,i)-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,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,s=t.columns,o=n*s;let i=0,h=0,a=0;for(let e=0;e<n;e++)for(let n=0;n<s;n++)a=t.get(e,n)-r,i+=a,h+=a*a;return e?(h-i*i/o)/(o-1):(h-i*i/o)/o}(this,r,n);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(!ut(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[r])}(this,r),this;case"column":if(!ut(r))throw new TypeError("center must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-e[n])}(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 n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)-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 n=0;for(let e=0;e<t.columns;e++)n+=Math.pow(t.get(r,e),2)/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!ut(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/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 n=0;for(let e=0;e<t.rows;e++)n+=Math.pow(t.get(e,r),2)/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!ut(r))throw new TypeError("scale must be an array");return function(t,e){for(let r=0;r<t.rows;r++)for(let n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e[n])}(this,r),this;case void 0:if(void 0===r)r=function(t){const e=t.size-1;let r=0;for(let n=0;n<t.columns;n++)for(let s=0;s<t.rows;s++)r+=Math.pow(t.get(s,n),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 n=0;n<t.columns;n++)t.set(r,n,t.get(r,n)/e)}(this,r),this;default:throw new Error(`invalid option: ${t}`)}}toString(t){return yt(this,t)}}function It(t,e){return t-e}Rt.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Rt.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return yt(this)}),Rt.random=Rt.rand,Rt.randomInt=Rt.randInt,Rt.diagonal=Rt.diag,Rt.prototype.diagonal=Rt.prototype.diag,Rt.identity=Rt.eye,Rt.prototype.negate=Rt.prototype.neg,Rt.prototype.tensorProduct=Rt.prototype.kroneckerProduct;class Ft extends Rt{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(!ut(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 n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!r[n].every((t=>"number"==typeof t)))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(r[n]))}}}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 xt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),xt(this,t,!0),e=Float64Array.from(Et(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){vt(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let n=0;n<t;n++)r[n]=this.data[e][n];for(let n=t+1;n<this.columns;n++)r[n-1]=this.data[e][n];this.data[e]=r}return this.columns-=1,this}addColumn(t,e){void 0===e&&(e=t,t=this.columns),vt(this,t,!0),e=kt(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let s=0;for(;s<t;s++)n[s]=this.data[r][s];for(n[s++]=e[r];s<this.columns+1;s++)n[s]=this.data[r][s-1];this.data[r]=n}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}}(Rt,Ft);class Tt extends Rt{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,n,s,o,i,h,a,l,u=(t=Tt.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,n=0;n<l;n++)o+=u.get(e,n)*a[n];a[e]-=o,u.set(e,r,a[e])}for(s=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[s])&&(s=e);if(s!==r){for(n=0;n<f;n++)i=u.get(s,n),u.set(s,n,u.get(r,n)),u.set(r,n,i);h=g[s],g[s]=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,n,s,o=t.columns,i=t.subMatrixRow(this.pivotVector,0,o-1),h=e.columns;for(s=0;s<h;s++)for(r=s+1;r<h;r++)for(n=0;n<o;n++)i.set(r,n,i.get(r,n)-i.get(s,n)*e.get(r,s));for(s=h-1;s>=0;s--){for(n=0;n<o;n++)i.set(s,n,i.get(s,n)/e.get(s,s));for(r=0;r<s;r++)for(n=0;n<o;n++)i.set(r,n,i.get(r,n)-i.get(s,n)*e.get(r,s))}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 n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new Ft(e,r);for(let s=0;s<e;s++)for(let e=0;e<r;e++)s>e?n.set(s,e,t.get(s,e)):s===e?n.set(s,e,1):n.set(s,e,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new Ft(e,r);for(let s=0;s<e;s++)for(let e=0;e<r;e++)s<=e?n.set(s,e,t.get(s,e)):n.set(s,e,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function Dt(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 Vt{constructor(t){let e,r,n,s,o=(t=Tt.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(n=0;n<h;n++){let t=0;for(e=n;e<i;e++)t=Dt(t,o.get(e,n));if(0!==t){for(o.get(n,n)<0&&(t=-t),e=n;e<i;e++)o.set(e,n,o.get(e,n)/t);for(o.set(n,n,o.get(n,n)+1),r=n+1;r<h;r++){for(s=0,e=n;e<i;e++)s+=o.get(e,n)*o.get(e,r);for(s=-s/o.get(n,n),e=n;e<i;e++)o.set(e,r,o.get(e,r)+s*o.get(e,n))}}a[n]=-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 n,s,o,i,h=t.columns,a=t.clone(),l=e.columns;for(o=0;o<l;o++)for(s=0;s<h;s++){for(i=0,n=o;n<r;n++)i+=e.get(n,o)*a.get(n,s);for(i=-i/e.get(o,o),n=o;n<r;n++)a.set(n,s,a.get(n,s)+i*e.get(n,o))}for(o=l-1;o>=0;o--){for(s=0;s<h;s++)a.set(o,s,a.get(o,s)/this.Rdiag[o]);for(n=0;n<o;n++)for(s=0;s<h;s++)a.set(n,s,a.get(n,s)-a.get(o,s)*e.get(n,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,n=r.columns,s=new Ft(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)t<e?s.set(t,e,r.get(t,e)):t===e?s.set(t,e,this.Rdiag[t]):s.set(t,e,0);return s}get orthogonalMatrix(){let t,e,r,n,s=this.QR,o=s.rows,i=s.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!==s.get(r,r)){for(n=0,t=r;t<o;t++)n+=s.get(t,r)*h.get(t,e);for(n=-n/s.get(r,r),t=r;t<o;t++)h.set(t,e,h.get(t,e)+n*s.get(t,r))}}return h}}class _t{constructor(t,e={}){if((t=Tt.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:o=!0,autoTranspose:i=!1}=e;let h,a=Boolean(s),l=Boolean(o),u=!1;if(r<n)if(i){h=t.transpose(),r=h.rows,n=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,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new Ft(r,c),w=new Ft(n,n),p=new Float64Array(n),d=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let b=Math.min(r-1,n),M=Math.max(0,Math.min(n-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]=Dt(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<n;e++){if(t<b&&0!==g[t]){let n=0;for(let s=t;s<r;s++)n+=h.get(s,t)*h.get(s,e);n=-n/h.get(t,t);for(let s=t;s<r;s++)h.set(s,e,h.get(s,e)+n*h.get(s,t))}p[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){p[t]=0;for(let e=t+1;e<n;e++)p[t]=Dt(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<n;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)d[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)d[e]+=p[r]*h.get(e,r);for(let e=t+1;e<n;e++){let n=-p[e]/p[t+1];for(let s=t+1;s<r;s++)h.set(s,e,h.get(s,e)+n*d[s])}}if(l)for(let e=t+1;e<n;e++)w.set(e,t,p[e])}}let v=Math.min(n,r+1);if(b<n&&(g[b]=h.get(b,b)),r<v&&(g[v-1]=0),M+1<v&&(p[M]=h.get(M,v-1)),p[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 n=0;for(let s=t;s<r;s++)n+=m.get(s,t)*m.get(s,e);n=-n/m.get(t,t);for(let s=t;s<r;s++)m.set(s,e,m.get(s,e)+n*m.get(s,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=n-1;t>=0;t--){if(t<M&&0!==p[t])for(let e=t+1;e<n;e++){let r=0;for(let s=t+1;s<n;s++)r+=w.get(s,t)*w.get(s,e);r=-r/w.get(t+1,t);for(let s=t+1;s<n;s++)w.set(s,e,w.get(s,e)+r*w.get(s,t))}for(let e=0;e<n;e++)w.set(e,t,0);w.set(t,t,1)}let E=v-1,k=0,S=Number.EPSILON;for(;v>0;){let t,e;for(t=v-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[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(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(g[r])<=S*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=p[v-2];p[v-2]=0;for(let r=v-2;r>=t;r--){let s=Dt(g[r],e),o=g[r]/s,i=e/s;if(g[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=o*p[r-1]),l)for(let t=0;t<n;t++)s=o*w.get(t,r)+i*w.get(t,v-1),w.set(t,v-1,-i*w.get(t,r)+o*w.get(t,v-1)),w.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let n=t;n<v;n++){let s=Dt(g[n],e),o=g[n]/s,i=e/s;if(g[n]=s,e=-i*p[n],p[n]=o*p[n],a)for(let e=0;e<r;e++)s=o*m.get(e,n)+i*m.get(e,t-1),m.set(e,t-1,-i*m.get(e,n)+o*m.get(e,t-1)),m.set(e,n,s)}break}case 3:{const e=Math.max(Math.abs(g[v-1]),Math.abs(g[v-2]),Math.abs(p[v-2]),Math.abs(g[t]),Math.abs(p[t])),s=g[v-1]/e,o=g[v-2]/e,i=p[v-2]/e,h=g[t]/e,u=p[t]/e,c=((o+s)*(o-s)+i*i)/2,f=s*i*(s*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+s)*(h-s)+d,b=h*u;for(let e=t;e<v-1;e++){let s=Dt(y,b);0===s&&(s=Number.MIN_VALUE);let o=y/s,i=b/s;if(e!==t&&(p[e-1]=s),y=o*g[e]+i*p[e],p[e]=o*p[e]-i*g[e],b=i*g[e+1],g[e+1]=o*g[e+1],l)for(let t=0;t<n;t++)s=o*w.get(t,e)+i*w.get(t,e+1),w.set(t,e+1,-i*w.get(t,e)+o*w.get(t,e+1)),w.set(t,e,s);if(s=Dt(y,b),0===s&&(s=Number.MIN_VALUE),o=y/s,i=b/s,g[e]=s,y=o*p[e]+i*g[e+1],g[e+1]=-i*p[e]+o*g[e+1],b=i*p[e+1],p[e+1]=o*p[e+1],a&&e<r-1)for(let t=0;t<r;t++)s=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,s)}p[v-2]=y,k+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=E;e++)w.set(e,t,-w.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<n-1)for(let r=0;r<n;r++)e=w.get(r,t+1),w.set(r,t+1,w.get(r,t)),w.set(r,t,e);if(a&&t<r-1)for(let n=0;n<r;n++)e=m.get(n,t+1),m.set(n,t+1,m.get(n,t)),m.set(n,t,e);t++}k=0,v--}}if(u){let t=w;w=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=w}solve(t){let e=t,r=this.threshold,n=this.s.length,s=Ft.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let o=this.U,i=this.rightSingularVectors,h=i.mmul(s),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 s=0;s<n;s++)r+=h.get(t,s)*o.get(e,s);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,n=t.columns,s=new Ft(r,this.s.length);for(let o=0;o<r;o++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&s.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 n=0;n<h;n++)r+=s.get(t,n)*o.get(e,n);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 n=0,s=r.length;n<s;n++)r[n]>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 Pt(t,e,r,n,s){let o=r*n*n,i=Ft.eye(e.length,e.length,o);const h=s(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,n,s){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]+=n;let l=s(o);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new Ft(h)}(t,a,e,n,s),u=function(t,e){const r=t.x.length;let n=new Array(r);for(let s=0;s<r;s++)n[s]=[t.y[s]-e[s]];return new Ft(n)}(t,a),c=function(t,e=!1){return t=Tt.checkMatrix(t),e?new _t(t).inverse():function(t,e,r=!1){return t=Tt.checkMatrix(t),e=Tt.checkMatrix(e),r?new _t(t).solve(e):t.isSquare()?new zt(t).solve(e):new Vt(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(n).transpose())).to1DArray()}const Ot=1e-5,qt=.001;class Lt{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=jt;knnIndices;knnDistances;graph;X;isInitialized=!1;rpForest=[];initFromRandom;initFromTree;search;searchGraph;Y;embedding=[];optimizationState=new Ut;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:n}=this.initializeSimplicialSetEmbedding();return this.optimizationState.head=e,this.optimizationState.tail=r,this.optimizationState.epochsPerSample=n,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()}makeSearchFns(){const{initFromTree:t,initFromRandom:e}=(r=this.distanceFn,{initFromRandom:function(t,e,n,s,o){for(let i=0;i<n.length;i++){const h=F(t,e.length,o);for(let t=0;t<h.length;t++)h[t]<0||V(s,i,r(e[h[t]],n[i]),h[t],1)}},initFromTree:function(t,e,n,s,o){for(let i=0;i<n.length;i++){const h=ot(n[i],t,o);for(let t=0;t<h.length;t++){if(h[t]<0)return;V(s,i,r(e[h[t]],n[i]),h[t],1)}}}});var r;this.initFromTree=t,this.initFromRandom=e,this.search=function(t){return function(e,r,n,s){const{indices:o,indptr:i}=H(r);for(let r=0;r<s.length;r++){const h=new Set(n[0][r]);for(;;){const a=L(n,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)||(_(n,r,t(e[o],s[r]),o,1),h.add(o))}}return n}}(this.distanceFn)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],s=new j([],[],[],n);for(let t=0;t<e.length;t++){const n=e[t],o=r[t];for(let e=0;e<n.length;e++){const r=n[e],i=o[e];i>0&&s.set(t,r,i)}}return B(s,U(s),((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 n=function(t,e,r,n,s,o,i){const h=z(r.length,n);if(s(n,e,r,h,i),t)for(const n of t)o(n,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),s=this.search(e,this.searchGraph,n,t);let{indices:o,weights:i}=O(s);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 w=H(X(m,"l1")),p=t.length,d=function(t,e,r){const n=C(t.length).map((t=>C(r[0].length)));for(let s=0;s<t.length;s++)for(let o=0;o<t[0].length;o++)for(let i=0;i<r[0].length;i++){const h=t[s][o];n[s][i]+=e[s][o]*r[h][i]}return n}(T(w.indices,p,this.nNeighbors),T(w.values,p,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=K(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,n=function(t,e){return function(r,n,s,o=10,i=50,h=.001,a=.5,l=!0){const u=r.length,c=z(r.length,s);for(let n=0;n<r.length;n++){const o=D(s,r.length,e);for(let e=0;e<o.length;e++){const s=t(r[n],r[o[e]]);V(c,n,s,o[e],1),V(c,o[e],s,n,1)}}if(l)for(let e=0;e<n.length;e++)for(let s=0;s<n[e].length&&!(n[e][s]<0);s++)for(let o=s+1;o<n[e].length&&!(n[e][o]<0);o++){const i=t(r[n[e][s]],r[n[e][o]]);V(c,n[e][s],i,n[e][o],1),V(c,n[e][o],i,n[e][s],1)}for(let n=0;n<o;n++){const n=P(c,u,s,i,e);let o=0;for(let s=0;s<u;s++)for(let h=0;h<i;h++){const l=Math.floor(n[0][s][h]);if(!(l<0||k(e)<a))for(let e=0;e<i;e++){const i=Math.floor(n[0][s][e]),a=n[2][s][h],u=n[2][s][e];if(i<0||!a&&!u)continue;const f=t(r[l],r[i]);o+=V(c,l,f,i,1),o+=V(c,i,f,l,1)}}if(o<=h*s*r.length)break}return O(c)}}(e,this.random),s=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=Z(t,r,s,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}=n(t,h,r,i);return{knnIndices:a,knnDistances:l}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:n=[],knnDistances:s=[],localConnectivity:o}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(s,e,o),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(n,s,i,h),c=[t.length,t.length],f=new j(a,l,u,c),g=U(f),m=$(f,g),w=Y(W(f,g),m);return W(G(w,r),G(m,1-r))}categoricalSimplicialSetIntersection(t,e,r,n=1){let s=function(t,e,r=1,n=5){return t.map(((t,s,o)=>-1===e[s]||-1===e[o]?t*Math.exp(-r):e[s]!==e[o]?t*Math.exp(-n):t))}(t,e,n,r);return s=K(s),function(t){const e=U(t=X(t,"max"));return K(t=W(t,Y(e,$(e,t))))}(s)}smoothKNNDistance(t,e,r=1,n=64,s=1){const o=Math.log(e)/Math.log(2)*s,i=C(t.length),h=C(t.length);for(let e=0;e<t.length;e++){let s=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),n=r-t;t>0?(i[e]=c[t-1],n>Ot&&(i[e]+=n*(c[t]-c[t-1]))):i[e]=n*c[0]}else c.length>0&&(i[e]=I(c));for(let r=0;r<n;r++){let r=0;for(let n=1;n<t[e].length;n++){const s=t[e][n]-i[e];r+=s>0?Math.exp(-s/l):1}if(Math.abs(r-o)<Ot)break;r>o?(a=l,l=(s+a)/2):(s=l,a===1/0?l*=2:l=(s+a)/2)}if(h[e]=l,i[e]>0){const t=R(u);h[e]<qt*t&&(h[e]=qt*t)}else{const r=R(t.map(R));h[e]<qt*r&&(h[e]=qt*r)}}return{sigmas:h,rhos:i}}computeMembershipStrengths(t,e,r,n){const s=t.length,o=t[0].length,i=C(s*o),h=C(s*o),a=C(s*o);for(let l=0;l<s;l++)for(let s=0;s<o;s++){let u=0;-1!==t[l][s]&&(u=t[l][s]===l?0:e[l][s]-n[l]<=0?1:Math.exp(-(e[l][s]-n[l])/r[l]),i[l*o+s]=l,h[l*o+s]=t[l][s],a[l*o+s]=u)}return{rows:i,cols:h,vals:a}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:e}=this,r=this.graph.getValues();let n=0;for(let t=0;t<r.length;t++){const e=r[t];n<r[t]&&(n=e)}const s=this.graph.map((e=>e<n/t?0:e));this.embedding=C(s.nRows).map((()=>C(e).map((()=>20*k(this.random)-10))));const o=[],i=[],h=[],a=s.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=A(t.length,-1),n=I(t),s=t.map((t=>t/n*e));return s.forEach(((t,n)=>{t>0&&(r[n]=e/s[n])})),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:n,headEmbedding:s,tailEmbedding:o}=this.optimizationState,i=s[0].length,h=s.length===o.length,a=n.map((t=>t/r)),l=[...a],u=[...n];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:n,epochsPerSample:s}=this.optimizationState,o=this.getNEpochs(),i=this.graph.nCols,{a:h,b:a}=function(t,e){const r=function(t,e,r){return S(300).map(((t,r)=>0+r*((e-0)/299)))}(0,3*t).map((t=>t<e?1:t)),n=C(r.length).map(((n,s)=>r[s]>=e?Math.exp(-(r[s]-e)/t):n)),s={x:r,y:n},{parameterValues:o}=function(t,e,r={}){let{maxIterations:n=100,gradientDifference:s=.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(!ht(t.x)||t.x.length<2||!ht(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(!ht(u))throw new Error("initialValues must be an array");let f,g=at(t,u,e),m=g<=i;for(f=0;f<n&&!m;f++){u=Pt(t,u,o,s,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(g=at(t,u,e),isNaN(g))break;m=g<=i}return{parameterValues:u,parameterError:g,iterations:f}}(s,(([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:n,epochsPerSample:s,a:h,b:a,nEpochs:o,nVertices:i})}optimizeLayoutStep(t){const{optimizationState:e}=this,{head:r,tail:n,headEmbedding:s,tailEmbedding:o,epochsPerSample:i,epochOfNextSample:h,epochOfNextNegativeSample:a,epochsPerNegativeSample:l,moveOther:u,initialAlpha:c,alpha:f,gamma:g,a:m,b:w,dim:p,nEpochs:d,nVertices:y}=e;for(let e=0;e<i.length;e++){if(h[e]>t)continue;const c=r[e],d=n[e],b=s[c],M=o[d],x=Wt(b,M);let v=0;x>0&&(v=-2*m*w*Math.pow(x,w-1),v/=m*Math.pow(x,w)+1);for(let t=0;t<p;t++){const e=$t(v*(b[t]-M[t]),4);b[t]+=e*f,u&&(M[t]+=-e*f)}h[e]+=i[e];const k=Math.floor((t-a[e])/l[e]);for(let t=0;t<k;t++){const t=E(y,this.random),e=o[t],r=Wt(b,e);let n=0;if(r>0)n=2*g*w,n/=(.001+r)*(m*Math.pow(r,w)+1);else if(c===t)continue;for(let t=0;t<p;t++){let r=4;n>0&&(r=$t(n*(b[t]-e[t]),4)),b[t]+=r*f}}a[e]+=k*l[e]}return e.alpha=c*(1-t/d),e.currentEpoch+=1,s}optimizeLayoutAsync(t=(()=>!0)){return new Promise(((e,r)=>{const n=async()=>{try{const{nEpochs:r,currentEpoch:s}=this.optimizationState;this.embedding=this.optimizeLayoutStep(s);const o=this.optimizationState.currentEpoch,i=!1===t(o),h=o===r;if(i||h)return e(h);setTimeout((()=>n()),0)}catch(t){r(t)}};setTimeout((()=>n()),0)}))}optimizeLayout(t=(()=>!0)){let e=!1,r=[];for(;!e;){const{nEpochs:n,currentEpoch:s}=this.optimizationState;r=this.optimizeLayoutStep(s);const o=this.optimizationState.currentEpoch,i=!1===t(o);e=o===n||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 Ut{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 $t(t,e){return t>e?e:t<-e?-e:t}function Wt(t,e){let r=0;for(let n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}class Yt{_workerCount;constructor(){this._workerCount=Math.max(navigator.hardwareConcurrency-2,1)}async calcMultiColumn(t,e,n,s=[{}],o=[1],i=y.EUCLIDEAN){const h=t[0].length*(t[0].length-1)/2,a=Math.floor(h/this._workerCount),l=t[0].length>2e4?await this.getMinimalThreshold(t,e,s,o,i):0;n<l&&(console.log(`using threshold ${l}`),n=l),s.forEach(((t,e)=>s[e].threshold=n));const u=new Array(this._workerCount),c=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(23),r.b))));for(let r=0;r<this._workerCount;r++)u[r]=new Promise(((l,u)=>{const f=r*a,g=r===this._workerCount-1?h:(r+1)*a;g<=f&&l({i:new Int32Array(0),j:new Int32Array(0),distance:new Float32Array(0),idx:r}),c[r].postMessage({values:t,startIdx:f,endIdx:g,threshold:n,fnNames:e,opts:s,weights:o,aggregationMethod:i}),c[r].onmessage=({data:{error:t,i:e,j:n,distance:s}})=>{t?(c[r].terminate(),u(t)):(c[r].terminate(),l({i:e,j:n,distance:s,idx:r}))}}));const f=await Promise.all(u),g=f.reduce(((t,e)=>t+e.i.length),0),m=new Int32Array(g),w=new Int32Array(g),p=new Float32Array(g);let d=0;for(const t of f)m.set(t.i,d),w.set(t.j,d),p.set(t.distance,d),d+=t.i.length;return{i:m,j:w,distance:p}}async calc(t,e,r,n={}){return await this.calcMultiColumn([t],[e],r,[n],[1])}async getKNN(t,e,r=15,n={}){return await this.multiColumnKNN([t],[e],r,[n],[1])}async getThresholdKNN(t,e,r=.8,n={}){return await this.multiColumnThresholdKnn([t],[e],r,[n],[1])}async multiColumnThresholdKnn(t,e,n=.8,s,o,i=y.EUCLIDEAN){if(t.length!==e.length||t.length!==s.length||t.length!==o.length)throw new Error("values, distance functions, options and weights arrays should have the same length");if(t.some((e=>e.length!==t[0].length)))throw new Error("all values arrays should have the same length");const h=t[0].length*(t[0].length-1)/2,a=Math.floor(h/this._workerCount),l=new Array(this._workerCount),u=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(427),r.b))));for(let r=0;r<this._workerCount;r++)l[r]=new Promise(((l,c)=>{const f=r*a,g=r===this._workerCount-1?h:(r+1)*a;g<=f&&l({knnDistances:new Array(0),knnIndexes:new Array(0)}),u[r].postMessage({values:t,startIdx:f,endIdx:g,fnNames:e,opts:s,threshold:n,weights:o,aggregationMethod:i}),u[r].onmessage=({data:{error:t,knnDistances:e,knnIndexes:n}})=>{t?(u[r].terminate(),c(t)):(u[r].terminate(),l({knnDistances:e,knnIndexes:n}))}}));const c=await Promise.all(l),f=new Int32Array(t[0].length);for(const e of c)for(let r=0;r<t[0].length;++r)f[r]+=e.knnIndexes[r]?.length??0;const g={knnDistances:new Array(t[0].length).fill(null).map(((t,e)=>new Array(f[e]))),knnIndexes:new Array(t[0].length).fill(null).map(((t,e)=>new Array(f[e])))};for(const e of c)for(let r=0;r<t[0].length;++r)for(let t=0;t<e.knnDistances[r]?.length;++t)g.knnDistances[r][f[r]-1]=e.knnDistances[r][t],g.knnIndexes[r][f[r]-1]=e.knnIndexes[r][t],f[r]-=1;return g}async multiColumnKNN(t,e,n=15,s,o,i=y.EUCLIDEAN){if(t.length!==e.length||t.length!==s.length||t.length!==o.length)throw new Error("values, distance functions, options and weights arrays should have the same length");if(t.some((e=>e.length!==t[0].length)))throw new Error("all values arrays should have the same length");const h=t[0].length*(t[0].length-1)/2,a=Math.floor(h/this._workerCount),l=new Array(this._workerCount),u=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(282),r.b))));for(let r=0;r<this._workerCount;r++)l[r]=new Promise(((l,c)=>{const f=r*a,g=r===this._workerCount-1?h:(r+1)*a;g<=f&&l({knnDistances:new Array(0),knnIndexes:new Array(0)}),u[r].postMessage({values:t,startIdx:f,endIdx:g,fnNames:e,opts:s,nNeighbours:n,weights:o,aggregationMethod:i}),u[r].onmessage=({data:{error:t,knnDistances:e,knnIndexes:n}})=>{t?(u[r].terminate(),c(t)):(u[r].terminate(),l({knnDistances:e,knnIndexes:n}))}}));const c=await Promise.all(l),f={knnDistances:new Array(t[0].length).fill(null).map((()=>new Array(n).fill(99999))),knnIndexes:new Array(t[0].length).fill(null).map((()=>new Array(n).fill(-1)))};for(const e of c)for(let r=0;r<t[0].length;++r)for(let t=0;t<e.knnDistances[r]?.length;++t)x(f.knnDistances[r],f.knnIndexes[r],e.knnDistances[r][t],e.knnIndexes[r][t]);return f}async getSampleDistances(t,e,n=[],s,o=y.EUCLIDEAN){const i=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(40),r.b))));try{const r=t[0].length*(t[0].length-1)/2,h=Math.floor(r/this._workerCount),a=1e6,l=Math.max(Math.min(r/1e3,a),Math.min(r,a)),u=Math.floor(l/this._workerCount),c=new Array(this._workerCount);for(let a=0;a<this._workerCount;a++)c[a]=new Promise(((l,c)=>{const f=a*h,g=a===this._workerCount-1?r:(a+1)*h;i[a].postMessage({values:t,startIdx:f,endIdx:g,sampleLength:u,fnNames:e,opts:n,weights:s,aggregationMethod:o}),i[a].onmessage=({data:{error:t,distance:e}})=>{i[a].terminate(),t?c(t):l({distance:e})}}));const f=await Promise.all(c),g=f.reduce(((t,e)=>t+e.distance.length),0),m=new Float32Array(g);let w=0;for(const t of f)m.set(t.distance,w),w+=t.distance.length;return m.sort(),m}catch(t){return i?.forEach((t=>t?.terminate())),console.error(t),new Float32Array(1).fill(.5)}}async getMinimalThreshold(t,e,r=[],n,s=y.EUCLIDEAN){try{const o=t.length*(t.length-1)/2,i=await this.getSampleDistances(t,e,r,n,s);return 1-i[Math.floor(7e7/o*i.length)]}catch(t){return console.error(t),.5}}static calcSync(t,e,r,n){const s=[],o=[],i=[];let h=0,a=0,l=0;const u=t.length*(t.length-1)/2;for(;h<u;){const e=M(t[a])||M(t[l])?1:r(t[a],t[l]);1-e>=n&&(s.push(a),o.push(l),i.push(e)),h++,l++,l===t.length&&(a++,l=a+1)}return{i:new Int32Array(s),j:new Int32Array(o),distance:new Float32Array(i)}}}var Gt=r(9657),Kt=r(6377),Xt=r.n(Kt);class Qt{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 n=Math.sqrt(-2*Math.log(r)/r);return this.vValue=e*n,this.returnV=!0,t*n}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 n=void 0!==r,s=new Array(t).fill(null).map((()=>new Float32Array(e)));if(n)for(let n=0;n<t;n++)s[n]=new Float32Array(e).fill(r);else for(let r=0;r<t;r++)for(let t=0;t<e;t++)s[r][t]=this.randn(0,1e-4);return s}l2(t,e){const r=t.length;let n=0;for(let s=0;s<r;s++){const r=t[s],o=e[s];n+=(r-o)*(r-o)}return n}xtod(t){const e=t.length,r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const o=this.l2(t[n],t[s]);r[n*e+s]=o,r[s*e+n]=o}return r}getIterSize(t){return t<=2e3?100:t<=3e3?90:t<=5e3?80:70}d2p(t,e,r,n){const s=(i=n,(t,e)=>i*t+e-Math.floor((t+2)*(t+1)/2)),o=new Float32Array(n*n);var i;for(let e=0;e<n;e++)for(let r=e+1;r<n;r++)o[e*n+r]=o[r*n+e]=t[s(e,r)];const h=n,a=Math.log(e),l=this.zeros(h*h),u=this.zeros(h);for(let t=0;t<h;t++){let e=-1/0,s=1/0,i=1,c=!1;const f=Math.floor(this.getIterSize(n)/5);let g=0;for(;!c;){let n=0;for(let e=0;e<h;e++){const r=t===e?0:Math.exp(-o[t*h+e]*i);u[e]=r,n+=r}let l=0;for(let t=0;t<h;t++){let e;e=0===n?0:u[t]/n,u[t]=e,e>1e-7&&(l-=e*Math.log(e))}l>a?(e=i,s===1/0?i*=2:i=(i+s)/2):(s=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 n=this.xtod(t);this.P=this.d2p(n,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,n=e.grad,s=this.zeros(this.dim);for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const r=n[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*n[e][t];this.ystep[e][t]=a,this.Y[e][t]+=a,s[t]+=this.Y[e][t]}for(let e=0;e<t;e++)for(let r=0;r<this.dim;r++)this.Y[e][r]-=s[r]/t;return r}debugGrad(){const t=this.N,e=this.costGrad(this.Y).grad,r=1e-5;for(let n=0;n<t;n++)for(let t=0;t<this.dim;t++){const s=this.Y[n][t];this.Y[n][t]=s+r;const o=this.costGrad(this.Y);this.Y[n][t]=s-r;const i=this.costGrad(this.Y),h=e[n][t],a=(o.cost-i.cost)/(2*r);console.log(n+","+t+": gradcheck analytic: "+h+" vs. numerical: "+a),this.Y[n][t]=s}}quArr;costGrad(t){const e=this.N,r=this.dim,n=this.P,s=this.iter<100?4:1;this.quArr??=this.zeros(e*e);let o=0;for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const i=1/(1+new Array(r).reduce(((e,r,o)=>e+Math.pow(t[n][o]-t[s][o],2)),0));this.quArr[n*e+s]=i,this.quArr[s*e+n]=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+=-n[a*e+l]*Math.log(u)*2;const c=4*(s*n[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 Bt{data;weights;aggregationMethod;constructor(t){this.data=t.data,this.weights=t.weights,this.aggregationMethod=t.aggregationMethod}}class Ht extends Bt{reducer;iterations;distanceFnames;distanceFns;distanceFnArgs;progressFunc;constructor(t){super(t);const e=t.randomSeed??Date(),r=Xt()(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 v(!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 Jt extends Bt{reducer;distanceFnames;distanceFns;vectors;progressFunc;distanceFnArgs;constructor(t){const e=t.randomSeed??Date(),r=Xt()(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 Lt(t)}async transform(t){console.time("knn graph");const e=await(new Yt).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 s=r,new Array(s.length).fill(0).map(((t,e)=>n.from(s[e])));var s}}const Zt={UMAP:Jt,"t-SNE":Ht};class te{reducer;constructor(t,e,r,n,s,o){const i=[];for(let e=0;e<r.length;++e){const n=new d(r[e]).getMeasure(o.distanceFnArgs[e]);i.push(n);let s=2048;for(let r=0;r<t[e].length;++r)if(t[e][r]&&t[e][r]._length){s=t[e][r]._length;break}if(h=r[e],"BitArray"==p[h])for(let r=0;r<t[e].length;++r)t[e][r]&&t[e][r]._data?t[e][r]=new Gt.Z(t[e][r]._data,t[e][r]._length):t[e][r]=new Gt.Z(s)}var h;"UMAP"==e?this.reducer=new Jt({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:n,aggregationMethod:s,...o}):"t-SNE"==e&&(this.reducer=new Ht({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:n,aggregationMethod:s,...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 n(r.length).fill(0).map(((t,n)=>r[n][e]))))),e}static availableMetricsByType(t){return Object.keys(w[t])}static get availableMethods(){return Object.keys(Zt)}static get availableMetrics(){let t=[];return Object.values(w).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}async function ee(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:n,weights:s,aggregationMethod:o}})=>{let i;try{const h=await async function(t,e,r,n,s,o){const i=new te(t,e,r,n,s,{...o,progressFunc:ee});return await i.transform(!0)}(t,e,r,s,o,n);i={embedding:h}}catch(t){i={error:t}}self.postMessage({error:i.error,embedding:i.embedding})}},6377:(t,e,r)=>{var n=r(4832),s=r(8652),o=r(801),i=r(2030),h=r(3618),a=r(9049),l=r(1971);l.alea=n,l.xor128=s,l.xorwow=o,l.xorshift7=i,l.xor4096=h,l.tychei=a,t.exports=l},4832:function(t,e,r){var n;!function(t,s,o){function i(t){var e,r=this,n=(e=4022871197,function(t){t=String(t);for(var r=0;r<t.length;r++){var n=.02519603282416938*(e+=t.charCodeAt(r));n-=e=n>>>0,e=(n*=e)>>>0,e+=4294967296*(n-=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=n(" "),r.s1=n(" "),r.s2=n(" "),r.s0-=n(t),r.s0<0&&(r.s0+=1),r.s1-=n(t),r.s1<0&&(r.s1+=1),r.s2-=n(t),r.s2<0&&(r.s2+=1),n=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),n=e&&e.state,s=r.next;return s.int32=function(){return 4294967296*r.next()|0},s.double=function(){return s()+11102230246251565e-32*(2097152*s()|0)},s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.alea=a}(0,t=r.nmd(t),r.amdD)},9049:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this,r="";e.next=function(){var t=e.b,r=e.c,n=e.d,s=e.a;return t=t<<25^t>>>7^r,r=r-n|0,n=n<<24^n>>>8^s,s=s-t|0,e.b=t=t<<20^t>>>12^r,e.c=r=r-n|0,e.d=n<<16^r>>>16^s,e.a=s-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 n=0;n<r.length+20;n++)e.b^=0|r.charCodeAt(n),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),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.tychei=a}(0,t=r.nmd(t),r.amdD)},8652:function(t,e,r){var n;!function(t,s,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 n=0;n<r.length+64;n++)e.x^=0|r.charCodeAt(n),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),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xor128=a}(0,t=r.nmd(t),r.amdD)},3618:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this;e.next=function(){var t,r,n=e.w,s=e.X,o=e.i;return e.w=n=n+1640531527|0,r=s[o+34&127],t=s[o=o+1&127],r^=r<<13,t^=t<<17,r^=r>>>15,t^=t>>>12,r=s[o]=r^t,e.i=o,r+(n^n>>>16)|0},function(t,e){var r,n,s,o,i,h=[],a=128;for(e===(0|e)?(n=e,e=null):(e+="\0",n=0,a=Math.max(a,e.length)),s=0,o=-32;o<a;++o)e&&(n^=e.charCodeAt((o+32)%e.length)),0===o&&(i=n),n^=n<<10,n^=n>>>15,n^=n<<4,n^=n>>>13,o>=0&&(i=i+1640531527|0,s=0==(r=h[127&o]^=n+i)?s+1:0);for(s>=128&&(h[127&(e&&e.length||0)]=-1),s=127,o=512;o>0;--o)n=h[s+34&127],r=h[s=s+1&127],n^=n<<13,r^=r<<17,n^=n>>>15,r^=r>>>12,h[s]=n^r;t.w=i,t.X=h,t.i=s}(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),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&(n.X&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xor4096=a}(0,t=r.nmd(t),r.amdD)},2030:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this;e.next=function(){var t,r,n=e.x,s=e.i;return t=n[s],r=(t^=t>>>7)^t<<24,r^=(t=n[s+1&7])^t>>>10,r^=(t=n[s+3&7])^t>>>3,r^=(t=n[s+4&7])^t<<7,t=n[s+7&7],r^=(t^=t<<13)^t<<9,n[s]=r,e.i=s+1&7,r},function(t,e){var r,n=[];if(e===(0|e))n[0]=e;else for(e=""+e,r=0;r<e.length;++r)n[7&r]=n[7&r]<<15^e.charCodeAt(r)+n[r+1&7]<<13;for(;n.length<8;)n.push(0);for(r=0;r<8&&0===n[r];++r);for(8==r?n[7]=-1:n[r],t.x=n,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),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&(n.x&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xorshift7=a}(0,t=r.nmd(t),r.amdD)},801:function(t,e,r){var n;!function(t,s,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 n=0;n<r.length+64;n++)e.x^=0|r.charCodeAt(n),n==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),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xorwow=a}(0,t=r.nmd(t),r.amdD)},1971:function(t,e,r){var n;!function(s,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 w(t,e,r){var n=[],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),(s.crypto||s.msCrypto).getRandomValues(t)),M(t)}catch(t){var e=s.navigator,r=e&&e.plugins;return[+new Date,s,r,s.screen,M(o)]}}():t,3),n),w=new p(n),x=function(){for(var t=w.g(l),e=c,r=0;t<f;)t=(t+r)*a,e*=a,r=w.g(1);for(;t>=g;)t/=2,e/=2,r>>>=1;return(t+r)/e};return x.int32=function(){return 0|w.g(4)},x.quick=function(){return w.g(4)/4294967296},x.double=x,b(M(w.S),o),(e.pass||r||function(t,e,r,n){return n&&(n.S&&d(n,w),t.state=function(){return d(w,{})}),r?(i[u]=t,e):t})(x,m,"global"in e?e.global:this==i,e.state)}function p(t){var e,r=t.length,n=this,s=0,o=n.i=n.j=0,i=n.S=[];for(r||(t=[r++]);s<a;)i[s]=s++;for(s=0;s<a;s++)i[s]=i[o=m&o+t[s%r]+(e=i[s])],i[o]=e;(n.g=function(t){for(var e,r=0,s=n.i,o=n.j,i=n.S;t--;)e=i[s=m&s+1],r=r*a+i[m&(i[s]=i[o=m&o+e])+(i[o]=e)];return n.i=s,n.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,n=[],s=typeof t;if(e&&"object"==s)for(r in t)try{n.push(y(t[r],e-1))}catch(t){}return n.length?n:"string"==s?t:t+"\0"}function b(t,e){for(var r,n=t+"",s=0;s<n.length;)e[m&s]=m&(r^=19*e[m&s])+n.charCodeAt(s++);return M(e)}function M(t){return String.fromCharCode.apply(0,t)}if(b(i.random(),o),t.exports){t.exports=w;try{h=r(5042)}catch(t){}}else void 0===(n=function(){return w}.call(e,r,e,t))||(t.exports=n)}("undefined"!=typeof self?self:this,[],Math)}}]);
3
+ //# sourceMappingURL=709.js.map