@datagrok/bio 2.7.1 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/detectors.js +30 -0
- package/dist/18.js +1 -1
- package/dist/18.js.map +1 -1
- package/dist/190.js +1 -1
- package/dist/190.js.map +1 -1
- package/dist/452.js.map +1 -1
- package/dist/729.js +1 -1
- package/dist/729.js.map +1 -1
- package/dist/79.js.map +1 -1
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +11 -5
- package/src/package-types.ts +19 -8
- package/src/package.ts +29 -16
- package/src/substructure-search/substructure-search.ts +1 -0
- package/src/tests/converters-test.ts +3 -3
- package/src/utils/cell-renderer.ts +1 -1
- package/src/utils/context-menu.ts +30 -0
- package/src/utils/convert.ts +2 -4
- package/src/utils/macromolecule-column-widget.ts +1 -1
- package/src/viewers/vd-regions-viewer.ts +2 -1
- package/src/widgets/package-settings-editor-widget.ts +16 -6
- package/src/widgets/representations.ts +1 -1
- package/tsconfig.json +2 -3
- package/webpack.config.js +1 -1
package/dist/729.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var bio;(()=>{"use strict";var t,e,r={1040:(t,e,r)=>{var n,s,i,o,a;r.d(e,{CF:()=>s,Qe:()=>o,W:()=>n,Yc:()=>a,gk:()=>i}),function(t){t.Levenshtein="Levenshtein",t.JaroWinkler="Jaro-Winkler",t.Manhattan="Manhattan"}(n||(n={})),function(t){t.Euclidean="Euclidean"}(s||(s={})),function(t){t.Tanimoto="Tanimoto",t.Dice="Dice",t.Asymmetric="Asymmetric",t.BraunBlanquet="Braun-Blanquet",t.Cosine="Cosine",t.Kulczynski="Kulczynski",t.McConnaughey="Mc-Connaughey",t.RogotGoldberg="Rogot-Goldberg",t.Russel="Russel",t.Sokal="Sokal",t.Hamming="Hamming",t.Euclidean="Euclidean"}(i||(i={})),function(t){t.Vector="Vector",t.String="String",t.BitArray="BitArray",t.MacroMolecule="MacroMolecule",t.Number="Number"}(o||(o={})),function(t){t.NumericDistance="NumericDistance"}(a||(a={}))},1729:(t,e,r)=>{var n=r(4221),s=r(7659),i=r(3659);function o(t){return Math.random()*t}function a(t){return Math.floor(o(t))}function h(t=!1,e="Assertion error."){if(!t)throw new Error(e)}function l(t,e,r=1){const n=t.length;h(n==e.length,"Vector lengths do not match.");const s=new i.OW(n);for(let n=0;n<t.length;++n)s[n]=t[n]+r*e[n];return s}function u(t,e,r=1){const n=function(t,e,r=0){return new Array(t).fill(r).map((()=>new i.OW(e).fill(r)))}(t,e);for(let s=0;s<t;++s)for(let t=0;t<e;++t)n[s][t]=o(r);return n}function c(t,e){const r=function(t){let e=0;for(let r=0;r<t.length;++r)e+=t[r];return e}(function(t){const e=t.length,r=new i.OW(e);for(let e=0;e<t.length;++e)r[e]=t[e]*t[e];return r}(l(t,e,-1)));return Math.sqrt(r)}function f(t){return(e,r)=>t*e+r-Math.floor((e+2)*(e+1)/2)}class g{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(18),r.b)))),this._terminateOnComplete=e}async calc(t,e,r=!0){return new Promise((async(n,s)=>{try{const s=t.length,i=new Array(this._workerCount),o=s*(s-1)/2;this._workerCount=Math.min(this._workerCount,o);const a=o/this._workerCount,h=new Float32Array(o);let l=0,u=1,c=0,f=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const n=Math.floor(r*a),g=r===this._workerCount-1?o:Math.floor((r+1)*a),m=l,d=u;r!==this._workerCount-1&&(l=s-2-Math.floor(Math.sqrt(-8*g+4*s*(s-1)-7)/2-.5),u=g-s*l+Math.floor((l+1)*(l+2)/2)),this._workers[r].postMessage({values:t,fnName:e,startRow:m,startCol:d,chunckSize:g-n}),i[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:s,distanceMatrixData:i,min:o,max:a}})=>{this._terminateOnComplete&&this._workers[r].terminate(),s?e(s):(h.set(i,n),o<c&&(c=o),a>f&&(f=a),t())}}))}await Promise.all(i),r&&h.forEach(((t,e)=>{h[e]=(t-c)/(f-c)})),n(h)}catch(t){s(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}class m{constructor(t){this.steps=t?.steps??0,this.cycles=t?.cycles??1e6,this.cutoff=t?.cutoff??0,this.lambda=t?.lambda??2,this.dlambda=t?.dlambda??.01,this.lambda2=this.lambda/2,this.dlambda2=this.dlambda/2,this.epsilon=t?.epsilon??1e-10,this.distanceFunction=t?.distance??c,this.distance=new Float32Array,this.distanceFunctionName=t?.distanceFunctionName}async initDistance(t){this.dmIndexFunct=f(t.length);const e=new g(!0,!1);this.distance=await e.calc(t,this.distanceFunctionName),e.terminate()}calcDistance(t,e,r){return this.distance[this.dmIndexFunct(e,r)]}async embed(t){const e=t.length,r=u(e,m.dimension,40);let n=this.lambda2;0===this.steps&&(this.steps=t.length-1),await this.initDistance(t);for(let s=0;s<this.cycles;++s){for(let s=0;s<this.steps;++s){const s=a(e);let i=a(e);for(;s==i;)i=a(e);const o=r[s],h=r[i],u=this.calcDistance(t,s,i),f=c(o,h);if(0==this.cutoff||u<=this.cutoff||f<u){const t=n*(u-f)/(f+this.epsilon),e=l(o,h,-1);r[s]=l(o,e,t),r[i]=l(h,e,-t)}}if(n-=this.dlambda2,n<=0)break}return r}}m.dimension=2;class d extends m{async embed(t){const e=t.length,r=u(e,d.dimension,40);let n=this.lambda;await this.initDistance(t);for(let s=0;s<this.cycles;++s){const s=a(e),i=r[s];for(let o=0;o<e;++o){if(s==o)continue;const e=r[o],a=this.calcDistance(t,s,o),h=c(i,e);if(0==this.cutoff||a<=this.cutoff||h<a){const t=n*(a-h)/(h+this.epsilon),s=l(i,e,-1);r[o]=l(e,s,-t)}}if(n-=this.dlambda,n<=0)break}return r}}class p extends m{constructor(t){super(t),this.cycles=t?.cycles??1e3,this.steps=t?.steps??1e5,this.radiusPercent=t?.radiusPercent??1,this.maxDistance=t?.maxDistance??null,this.maxDistanceSteps=t?.maxDistanceSteps??null}async embed(t){const e=t.length,r=u(e,p.dimension,40);if(await this.initDistance(t),null===this.maxDistanceSteps&&(this.maxDistanceSteps=e*Math.floor((e-1)/2)),null===this.maxDistance){this.maxDistance=-1e37;for(let r=0;r<this.maxDistanceSteps;r++){const r=a(e);let n=a(e);for(;r==n;)n=a(e);const s=this.calcDistance(t,r,n);s>this.maxDistance&&(this.maxDistance=s)}}let n=this.lambda;const s=0==this.radiusPercent?this.maxDistance:this.maxDistance*this.radiusPercent;for(let i=0;i<this.cycles;++i){for(let i=0;i<this.steps;++i){const i=a(e);let o=a(e);for(;i==o;)o=a(e);const h=r[i],u=r[o],f=this.calcDistance(t,i,o),g=c(h,u);if(f<=s||g<f){const t=.5*n*(f-g)/(g+this.epsilon),e=l(h,u,-1);r[i]=l(h,e,t),r[o]=l(u,e,-t)}}if(n-=(this.lambda-this.dlambda)/(this.cycles-1),n<this.dlambda)break}return r}}var w=r(1811),y=r(3979),v=r(5697),b=r(489),M=r(1040);const _={[M.CF.Euclidean]:c},x={[M.W.Levenshtein]:w.T,[M.W.JaroWinkler]:y.H$,[M.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={[M.gk.Tanimoto]:v.KR,[M.gk.Dice]:v._h,[M.gk.Asymmetric]:v.yU,[M.gk.BraunBlanquet]:v.Dz,[M.gk.Cosine]:v.Zd,[M.gk.Kulczynski]:v.s,[M.gk.McConnaughey]:v.aW,[M.gk.RogotGoldberg]:v.MI,[M.gk.Russel]:v.fX,[M.gk.Sokal]:v.NB,[M.gk.Hamming]:v.UX,[M.gk.Euclidean]:v.WI},E={[M.Yc.NumericDistance]:v.bX},k={[M.Qe.Vector]:{[M.CF.Euclidean]:_[M.CF.Euclidean]},[M.Qe.String]:{[M.W.Levenshtein]:x[M.W.Levenshtein],[M.W.JaroWinkler]:x[M.W.JaroWinkler],[M.W.Manhattan]:x[M.W.Manhattan]},[M.Qe.BitArray]:{[M.gk.Tanimoto]:S[M.gk.Tanimoto],[M.gk.Dice]:S[M.gk.Dice],[M.gk.Asymmetric]:S[M.gk.Asymmetric],[M.gk.BraunBlanquet]:S[M.gk.BraunBlanquet],[M.gk.Cosine]:S[M.gk.Cosine],[M.gk.Kulczynski]:S[M.gk.Kulczynski],[M.gk.McConnaughey]:S[M.gk.McConnaughey],[M.gk.RogotGoldberg]:S[M.gk.RogotGoldberg],[M.gk.Russel]:S[M.gk.Russel],[M.gk.Sokal]:S[M.gk.Sokal]},[M.Qe.MacroMolecule]:{[b.U.HAMMING]:b.o[b.U.HAMMING],[b.U.LEVENSHTEIN]:b.o[b.U.LEVENSHTEIN],[b.U.NEEDLEMANN_WUNSCH]:b.o[b.U.NEEDLEMANN_WUNSCH]},[M.Qe.Number]:{[M.Yc.NumericDistance]:E[M.Yc.NumericDistance]}},N=Object.keys(k).reduce(((t,e)=>{for(const r of Object.keys(k[e]))t[r]=e;return t}),{});class R{constructor(t){this.method=t,this.dataType=N[t]}getMeasure(t){const e=k;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,N[r]==M.Qe.MacroMolecule.toString()?e[this.dataType][this.method](t):e[this.dataType][this.method];var r}static getMetricByDataType(t){return Object.keys(k[t])}static get availableMeasures(){return Object.keys(k)}}class I{constructor(t,e=!1){if(this._length=0,this._version=0,this._updateLevel=0,this._selectedCount=0,this._selectedCountVersion=-1,this._selectedIndexesVersion=-1,this._versionedName="",this._versionedNameVersion=-1,this.SHRINK_THRESHOLD=256,"number"==typeof t){const r=t,n=I._createBuffer(r);if(e)for(let t=0;t<n.length;t++)n[t]=-1;this._data=n,this._length=r}else{if(!(t instanceof Uint32Array))throw new Error("Invalid constructor");this._data=t,this._length=e}}getRawData(){return this._data}assureGoez(t,e){if(t<0)throw new Error(`${e} should be greater than zero`)}assureInRange(t,e,r,n){if(t<e||t>r)throw new Error(`Argument ${n} (${t}) out of range (${e}, ${r})`)}copy(t,e,r){for(let n=0;n<r;n++)e[n]=t[n]}copyFrom(t){if(this._length!=t._length)throw new Error(`Lengths differ (${this._length} != ${t._length})`);this.copy(t._data,this._data,this.lengthInInts),this._version++}get length(){return this._length}get buffer(){return this._data}set buffer(t){this._data=t,this._version++}get version(){return this._version}set version(t){this._version=t}incrementVersion(t=!0){this._version++}get lengthInInts(){return Math.floor((this._length+31)/32)}get versionedName(){return this._version==this._versionedNameVersion?this._versionedName:""}set versionedName(t){this._versionedName=t,this._versionedNameVersion=this._version}get self(){return this}setLength(t){if(t<0)throw new Error("should be >= 0");if(t==this._length)return;const e=Math.floor((t+31)/32);if(e>this._data.length||e+this.SHRINK_THRESHOLD<this._data.length){const t=new Uint32Array(e);this.copy(this._data,t,e>this._data.length?this._data.length:e),this._data=t}t>this._length&&(this._length%32>0&&(this._data[this.lengthInInts-1]&=(1<<(this._length%32&31))-1),this._data.fill(0,this.lengthInInts,e)),this._length=t,this._version++}static fromAnd(t,e){if(t._length!=e._length)throw new Error(`Lengths differ (${t._length} != ${e._length})`);const r=new I(t._length);r._length=t._length,r._data=I._createBuffer(r._length),r._version=0;const n=t.lengthInInts;for(let s=0;s<n;s++)r._data[s]=t._data[s]&e._data[s];return r}static _createBuffer(t){return new Uint32Array(Math.floor((t+31)/32))}static fromValues(t){const e=new I(t.length);e._version=0;for(let r=0;r<e._length;r++)t[r]&&(e._data[Math.floor(r/32)]|=1<<(r%32&31));return e}static fromSeq(t,e){const r=new I(t);for(let n=0;n<t;++n)r.setBit(n,e(n));return r._version=0,r}static fromString(t){return I.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const r=new I(t);return r._data=e,r}static fromBytes(t){const e=t.length,r=new I(8*e);r._data=new Uint32Array(Math.floor((e+3)/4)),r._length=8*e;let n=0,s=0;for(;e-s>=4;)r._data[n++]=255&t[s]|(255&t[s+1])<<8|(255&t[s+2])<<16|(255&t[s+3])<<24,s+=4;return e-s==3&&(r._data[n]=(255&t[s+2])<<16),e-s==2&&(r._data[n]|=(255&t[s+1])<<8),e-s==1&&(r._data[n]|=255&t[s]),r._version=0,r}toString(){return`${this._length} bits, ${this.countBits(!0)} set`}equals(t){if(this==t)return!0;if(null==t)return!1;if(this._length!=t._length)return!1;if(0==this._length)return!0;for(let e=0;e<this._data.length-1;e++)if(this._data[e]!=t._data[e])return!1;for(let e=8*(this._data.length-1);e<this._length;e++)if(this.getBit(e)!=t.getBit(e))return!1;return!0}clone(){const t=new I(0,!1);return t._data=Uint32Array.from(this._data),t._length=this._length,t._version=this._version,t}init(t,e){this.setAll(!1,!1);for(let e=0;e<this._length;e++)t(e)&&(this._data[Math.floor(e/32)]|=1<<(e%32&31));return this.incrementVersion(e),this}invert(t=!0){for(let t=0;t<this._data.length;t++)this._data[t]^=-1;this.incrementVersion(t)}setAll(t,e=!1){const r=t?-1:0,n=this.lengthInInts;for(let t=0;t<n;t++)this._data[t]=r;this.incrementVersion(e)}setIndexes(t,e=!0,r=!0,n=!0){r&&this.setAll(!e,!1);for(const r of t)this.setFast(r,e);this.incrementVersion(n)}everyIndex(t,e=!0){for(const r of t)if(this.getBit(r)!=e)return!1;return!0}anyIndex(t,e=!0){for(const r of t)if(this.getBit(r)==e)return!0;return!1}setWhere(t,e=!0,r=!0,n=!0,s=!0){if(r&&s&&this.setAll(!e,!1),s)for(let r=0;r<this._length;r++)t(r)&&this.setFast(r,e);else for(let r=0;r<this._length;r++)this.setFast(r,t(r)?e:!e);this.incrementVersion(n)}getRange(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const r=[];for(let n=t;n<e;++n)r.push(this.getBit(n));return I.fromValues(r)}getRangeAsList(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const r=[];for(let n=t;n<e;++n)r.push(this.getBit(n));return r}setRange(t,e,r,n=!0){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length-1,"to");const s=Math.min(t,e),i=Math.max(t,e);if(r)for(let t=s;t<=i;t++)this.setTrue(t);else for(let t=s;t<=i;t++)this.setFalse(t);return this.incrementVersion(n),this}setRandom(t,e,r=!0){if(t<0||t>this._length)throw new Error("n must be >= 0 && <= Count");t>this._length/2&&this.setRandom(this._length-t,!e),this.setAll(!e);for(let r=0;r<t;){const t=Math.floor(Math.random()*this._length);this.getBit(t)!=e&&(this.setFast(t,e),r++)}this.incrementVersion(r)}and(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]&=t._data[e];return this.incrementVersion(e),this}andNot(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");const r=this.lengthInInts;for(let e=0;e<r;e++)this._data[e]&=~t._data[e];return this.incrementVersion(e),this}notAnd(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]=~this._data[e]&t._data[e];return this.incrementVersion(e),this}not(t=!0){for(let t=0,e=this.lengthInInts;t<e;t++)this._data[t]=~this._data[t];return this.incrementVersion(t),this}or(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]|=t._data[e];return this.incrementVersion(e),this}xor(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]^=t._data[e];return this.incrementVersion(e),this}insertAt(t,e,r=!1){if(this.assureInRange(t,0,this._length,"pos"),0==e)return;const n=this._length;this.setLength(this._length+e);for(let r=n-1;r>=t;r--)this.setBit(r+e,this.getBit(r));for(let n=t;n<t+e;n++)this.setBit(n,r)}removeAt(t,e=1){if(e<0)throw new Error("n cannot be negative");if(this.assureInRange(t,0,this._length-e,"pos"),this.contains(!0))for(let r=t;r<this._length-e;r++)this.setBit(r,this.getBit(r+e));this.setLength(this._length-e)}removeByMask(t,e=!0){if(this._length!=t.length)throw new Error("length != mask.length");if(t==this)this.setLength(t.countBits(!e)),this.setAll(!e);else{let r=0;for(let n=-1;-1!=(n=t.findNext(n,!e));)this.setFast(r++,this.getBit(n));this._length=r,this._version++}return this}getBit(t){return 0!=(this._data[Math.floor(t/32)]&1<<(31&t))}setBit(t,e,r=!0){this.setFast(t,e),this._version++}setFast(t,e){e?this._data[Math.floor(t/32)]|=1<<(31&t):this._data[Math.floor(t/32)]&=~(1<<(31&t))}setTrue(t){this._data[Math.floor(t/32)]|=1<<(31&t)}setFalse(t){this._data[Math.floor(t/32)]&=~(1<<(31&t))}trueCount(){return this.countBits(!0)}falseCount(){return this.countBits(!1)}countBits(t){if(0==this._length)return 0;if(this._selectedCountVersion!=this._version){this._selectedCount=0;const t=this.lengthInInts;let e=0;for(;e<t-1;e++)for(let t=this._data[e];0!=t;t>>>=8)this._selectedCount+=I._onBitCount[255&t];let r=this._data[e];const n=31&this._length;for(0!=n&&(r&=~(4294967295<<n));0!=r;r>>>=8)this._selectedCount+=I._onBitCount[255&r];this._selectedCountVersion=this._version}return t?this._selectedCount:this._length-this._selectedCount}countWhere(t){let e=0;if(this.trueCount()==this._length)for(let r=0;r<this._length;r++)e+=t(r)?1:0;else for(let r=-1;-1!=(r=this.findNext(r,!0));)e+=t(r)?1:0;return e}andWithCountBits(t,e){if(0==this._length)return 0;let r=0;const n=this.lengthInInts;let s=0;for(;s<n-1;s++)for(let e=this._data[s]&t._data[s];0!=e;e>>>=8)r+=I._onBitCount[255&e];let i=this._data[s]&t._data[s];const o=31&this._length;for(0!=o&&(i&=~(4294967295<<o));0!=i;i>>>=8)r+=I._onBitCount[255&i];return e?r:this._length-r}clear(){this.setLength(0)}contains(t){return this.findNext(-1,t)>=0}get allTrue(){return this.countBits(!0)==this._length}get allFalse(){return this.countBits(!1)==this._length}get anyTrue(){return this.countBits(!0)>0}get anyFalse(){return this.countBits(!1)>0}findNext(t,e=!0){if(this.assureInRange(t,-1,this._length,"index"),t>=this._length-1)return-1;let r=31&(t=t<0?0:t+1);const n=this.lengthInInts;for(let s=Math.floor(t/32);s<n;s++){let n=e?this._data[s]:~this._data[s];if(0!=r)n&=4294967295<<r&4294967295,r=0;else if(!e&&-4294967296==n)continue;for(let e=0;0!=n;e+=8,n>>>=8){const r=I._firstOnBit[255&n];if(r>=0)return(t=r+32*s+e)>=this._length?-1:t}}return-1}findPrev(t,e=!0){if(0==t)return-1;this.assureInRange(t,-1,this._length,"index");let r=1+(t=t<0?this._length-1:t-1)&31;for(let n=Math.floor(t/32);n>=0;n--){let t=e?this._data[n]:~this._data[n];0!=r&&(t&=~(4294967295<<r),r=0);for(let e=24;0!=t;e-=8,t<<=8){const r=I._lastOnBit[t>>>24];if(r>=0)return r+32*n+e}}return-1}}I._onBitCount=Int8Array.from([0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]),I._firstOnBit=Int8Array.from([-1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0]),I._lastOnBit=Int8Array.from([-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]);var z,A=r(6814);class F{get data(){return this._data}get size(){return this._size}constructor(t,e){if(null==e){if(null==t)throw new Error("Arguments error: data or size is required.");if(this._data=t,this._size=(1+Math.sqrt(1+8*this._data.length))/2,this._size!=Math.floor(this._size))throw new Error(`Invalid data length ${this._data.length} leads to non integer size ${this._size}`)}else{this._size=e;const r=e*(e-1)/2;if(t){if(t.length!=r)throw new Error(`Invalid data length. Observations size ${e} requires data length ${r}.`);this._data=t}else this._data=new Float32Array(r)}}_linearizeIJ(t,e){if(!(t<e))throw new Error("i must be less than j");return this._size*t+e-Math.floor((t+2)*(t+1)/2)}get(t,e){return t==e?0:t<e?this._data[this._linearizeIJ(t,e)]:this._data[this._linearizeIJ(e,t)]}set(t,e,r){this._data[this._linearizeIJ(t,e)]=r}static calc(t,e){const r=t.length,n=new F(void 0,r);for(let s=0;s<r;s++)for(let i=s+1;i<r;i++)n.set(s,i,(0,A.k)(t[s])||(0,A.k)(t[i])?1:e(t[s],t[i]));return n}square(){for(let t=0;t<this._data.length;t++)this._data[t]=this._data[t]**2}add(t){if(this._size!==t._size)throw new Error(`Matrices must have the same size. This size: ${this._size}, other size: ${t._size}`);for(let e=0;e<this._data.length;e++)this._data[e]+=t._data[e]}sqrt(){for(let t=0;t<this._data.length;t++)this._data[t]=Math.sqrt(this._data[t])}normalize(){let t=0,e=this._data[0];for(let r=0;r<this._data.length;r++)this._data[r]<t&&(t=this._data[r]),this._data[r]>e&&(e=this._data[r]);const r=e-t;for(let n=0;n<this._data.length;n++)this._data[n]=0===r?this._data[n]-t:(this._data[n]-t)/(e-t)}}!function(t){t.UMAP="UMAP",t.T_SNE="t-SNE"}(z||(z={}));class C{constructor(t){this.data=t.data}}const T={UMAP:class extends C{constructor(t){super(t),h("distanceFname"in t),h("distanceFn"in t),this.distanceFn=t.distanceFn,this.distanceFname=t.distanceFname,this.dmIndexFunc=f(this.data.length),this.vectors=new Array(this.data.length).fill(0).map(((t,e)=>[e])),this.usingDistanceMatrix=!(!t.preCalculateDistanceMatrix&&this.data.length>2e4),this.usingDistanceMatrix?t.distanceFn=this._encodedDistanceMatrix.bind(this):t.distanceFn=this._encodedDistance.bind(this),this.data.length<15&&(t.nNeighbors=this.data.length-1),this.reducer=new n.u(t)}_encodedDistanceMatrix(t,e){return t[0]===e[0]?0:t[0]>e[0]?this.distanceMatrix[this.dmIndexFunc(e[0],t[0])]:this.distanceMatrix[this.dmIndexFunc(t[0],e[0])]}_encodedDistance(t,e){return this.distanceFn(this.data[t[0]],this.data[e[0]])}async transform(t){this.usingDistanceMatrix&&(this.distanceMatrix=t?await(async()=>{const t=new g(!0,!1);try{const e=await t.calc(this.data,this.distanceFname);return t.terminate(),e}catch(e){throw t.terminate(),e}})():(()=>F.calc(this.data,((t,e)=>this.distanceFn(t,e))).data)());const e=this.reducer.fit(this.vectors);return{embedding:(r=e,new Array(r.length).fill(0).map(((t,e)=>i.OW.from(r[e])))),...this.distanceMatrix?{distance:this.distanceMatrix}:{}};var r}},"t-SNE":class extends C{constructor(t){super(t),this.reducer=new s.Z(t),this.iterations=t?.iterations??100,this.distanceFname=t.distanceFname,this.distanceFn=t.distanceFn}async transform(t){const e=t?await(async()=>{const t=new g(!0,!1);try{const e=await t.calc(this.data,this.distanceFname);return t.terminate(),e}catch(e){throw t.terminate(),e}})():(()=>{const t=F.calc(this.data,((t,e)=>this.distanceFn(t,e)));return t.normalize(),t.data})(),r=function(t,e){const r=f(e);function n(t,e){const n=Number(t),s=Number(e);return r(n,s)}const s={get:(t,r,s)=>"length"===r?e:new Proxy(t,function(t){return{get:(e,r,s)=>t===r?0:e[Number(t)>Number(r)?n(r,t):n(t,r)]}}(r))};return new Proxy(t,s)}(e,this.data.length);this.reducer.initDataDist(r);for(let t=0;t<this.iterations;++t)this.reducer.step();return{distance:e,embedding:this.reducer.getSolution()}}},SPE:class extends C{constructor(t){super(t),this.reducer=new m(t)}async transform(){const t=await this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}},pSPE:class extends C{constructor(t){super(t),this.reducer=new d(t)}async transform(){const t=await this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}},OriginalSPE:class extends C{constructor(t){super(t),this.reducer=new p(t)}async transform(){const t=await this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}}};class P{constructor(t,e,r,n){const s=new R(r).getMeasure();let i={};if("BitArray"==N[r])for(let e=0;e<t.length;++e)t[e]=new I(t[e]._data,t[e]._length);i="UMAP"==e?{data:t,distanceFn:s,distanceFname:r,nEpochs:n?.cycles,...n}:"t-SNE"==e?{data:t,distanceFn:s,distanceFname:r,iterations:n?.cycles??void 0,...n}:{data:t,distance:s,distanceFunctionName:r,...n},this.reducer=new T[e](i)}async transform(t=!1,e){if(void 0===this.reducer)throw new Error("Reducer was not defined.");let{embedding:r,distance:n}=await this.reducer.transform(e);var s;return t&&(s=r,r=new Array(s[0].length).fill(0).map(((t,e)=>new i.OW(s.length).fill(0).map(((t,r)=>s[r][e]))))),{distance:n,embedding:r}}static availableMetricsByType(t){return Object.keys(k[t])}static get availableMethods(){return Object.keys(T)}static get availableMetrics(){let t=[];return Object.values(k).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}self.onmessage=async({data:{columnData:t,method:e,measure:r,options:n,parallelDistanceWorkers:s}})=>{let i;try{i=await async function(t,e,r,n,s){const i=new P(t,e,r,n);return await i.transform(!0,s)}(t,e,r,n,s)}catch(t){i={error:t}}self.postMessage({error:i.error,distance:i.distance,embedding:i.embedding})}},7659:(t,e,r)=>{e.Z=void 0;var n=r(6215);Object.defineProperty(e,"Z",{enumerable:!0,get:function(){return n.TSNE}})},6215:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TSNE=void 0,e.TSNE=class{constructor(t){this.returnV=!1,this.vValue=0,this.iter=0,t=t||{},this.perplexity=this.getopt(t,"perplexity",30),this.dim=this.getopt(t,"dim",2),this.epsilon=this.getopt(t,"epsilon",10)}assert(t,e){if(!t)throw e||"Assertion failed"}getopt(t,e,r){return t.hasOwnProperty(e)?t[e]:r}gaussRandom(){if(this.returnV)return this.returnV=!1,this.vValue;const t=2*Math.random()-1,e=2*Math.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[];if("undefined"==typeof ArrayBuffer){const e=new Array(t);for(let r=0;r<t;r++)e[r]=0;return e}return new Float64Array(t)}randn2d(t,e,r){const n=void 0!==r,s=[];for(let i=0;i<t;i++){const t=[];for(let s=0;s<e;s++)n?t.push(r):t.push(this.randn(0,1e-4));s.push(t)}return s}L2(t,e){const r=t.length;let n=0;for(let s=0;s<r;s++){const r=t[s],i=e[s];n+=(r-i)*(r-i)}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 i=this.L2(t[n],t[s]);r[n*e+s]=i,r[s*e+n]=i}return r}d2p(t,e,r){const n=Math.sqrt(t.length),s=Math.floor(n);this.assert(s===n,"D should have square number of elements.");const i=Math.log(e),o=this.zeros(s*s),a=this.zeros(s);for(let e=0;e<s;e++){let n=-1/0,h=1/0,l=1,u=!1;const c=50;let f=0;for(;!u;){let o=0;for(let r=0;r<s;r++){let n=Math.exp(-t[e*s+r]*l);e===r&&(n=0),a[r]=n,o+=n}let g=0;for(let t=0;t<s;t++){let e;e=0===o?0:a[t]/o,a[t]=e,e>1e-7&&(g-=e*Math.log(e))}g>i?(n=l,h===1/0?l*=2:l=(l+h)/2):(h=l,n===-1/0?l/=2:l=(l+n)/2),f++,Math.abs(g-i)<r&&(u=!0),f>=c&&(u=!0)}for(let t=0;t<s;t++)o[e*s+t]=a[t]}const h=this.zeros(s*s),l=2*s;for(let t=0;t<s;t++)for(let e=0;e<s;e++)h[t*s+e]=Math.max((o[t*s+e]+o[e*s+t])/l,1e-100);return h}sign(t){return t>0?1:t<0?-1:0}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),this.N=e,this.initSolution()}initDataDist(t){const e=t.length;this.assert(e>0," X is empty? You must have some data!");const r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const i=t[n][s];r[n*e+s]=i,r[s*e+n]=i}this.P=this.d2p(r,this.perplexity,1e-4),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],i=this.ystep[e][t],o=this.gains[e][t];let a=this.sign(r)===this.sign(i)?.8*o:o+.2;a<.01&&(a=.01),this.gains[e][t]=a;const h=(this.iter<250?.5:.8)*i-this.epsilon*a*n[e][t];this.ystep[e][t]=h,this.Y[e][t]+=h,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),r=(e.cost,e.grad),n=1e-5;for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const s=this.Y[e][t];this.Y[e][t]=s+n;const i=this.costGrad(this.Y);this.Y[e][t]=s-n;const o=this.costGrad(this.Y),a=r[e][t],h=(i.cost-o.cost)/(2*n);console.log(e+","+t+": gradcheck analytic: "+a+" vs. numerical: "+h),this.Y[e][t]=s}}costGrad(t){const e=this.N,r=this.dim,n=this.P,s=this.iter<100?4:1,i=this.zeros(e*e);let o=0;for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){let a=0;for(let e=0;e<r;e++){const r=t[n][e]-t[s][e];a+=r*r}const h=1/(1+a);i[n*e+s]=h,i[s*e+n]=h,o+=2*h}const a=e*e,h=this.zeros(a);for(let t=0;t<a;t++)h[t]=Math.max(i[t]/o,1e-100);let l=0;const u=[];for(let o=0;o<e;o++){const a=new Array(r);for(let t=0;t<r;t++)a[t]=0;for(let u=0;u<e;u++){l+=-n[o*e+u]*Math.log(h[o*e+u]);const c=4*(s*n[o*e+u]-h[o*e+u])*i[o*e+u];for(let e=0;e<r;e++)a[e]+=c*(t[o][e]-t[u][e])}u.push(a)}return{cost:l,grad:u}}}},9251:(t,e,r)=>{r.r(e),r.d(e,{default:()=>P});const n=Object.prototype.toString;function s(t){return n.call(t).endsWith("Array]")}function i(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 o=Object.prototype.toString;function a(t){return o.call(t).endsWith("Array]")}const h=Object.prototype.toString;function l(t){return h.call(t).endsWith("Array]")}const u=Object.prototype.toString;const c=Object.prototype.toString;function f(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!l(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(!l(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,!c.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,i=r.toIndex,o=void 0===i?t.length:i;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(o<=s||o>t.length||!Number.isInteger(o))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=t[s],h=s+1;h<o;h++)t[h]<a&&(a=t[h]);return a}(t),s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!u.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,i=r.toIndex,o=void 0===i?t.length:i;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(o<=s||o>t.length||!Number.isInteger(o))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=t[s],h=s+1;h<o;h++)t[h]>a&&(a=t[h]);return a}(t);if(n===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,o=void 0===i?r.autoMinMax?n:0:i,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(o>=h)throw new RangeError("min option must be smaller than max option");for(var f=(h-o)/(s-n),g=0;g<t.length;g++)e[g]=(t[g]-n)*f+o;return e}const g=" ".repeat(2),m=" ".repeat(4);function d(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:s=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\n${g}[\n${m}${function(t,e,r,n,s){const{rows:i,columns:o}=t,a=Math.min(i,e),h=Math.min(o,r),l=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<h;i++)r.push(p(t.get(e,i),n,s));l.push(`${r.join(" ")}`)}return h!==o&&(l[l.length-1]+=` ... ${o-r} more columns`),a!==i&&l.push(`... ${i-e} more rows`),l.join(`\n${m}`)}(t,r,n,s,i)}\n${g}]\n${g}rows: ${t.rows}\n${g}columns: ${t.columns}\n}`}function p(t,e,r){return(t>=0&&r?` ${w(t,e-1)}`:w(t,e)).padEnd(e)}function w(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 y(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 v(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 b(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function M(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function _(t,e,r,n,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(S("startRow",e),S("endRow",r),S("startColumn",n),S("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 x(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function S(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function E(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class k{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new R(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 R(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 R(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 R(t,e)}static ones(t,e){return new R(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 R(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:i=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 o=s-n,a=new R(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*o);a.set(r,t,e)}return a}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),i=this.zeros(e,r);for(let e=0;e<s;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new R(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)s.set(i,r,Math.min(t.get(i,r),e.get(i,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 i=0;i<r;i++)for(let r=0;r<n;r++)s.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return s}static checkMatrix(t){return k.isMatrix(t)?t:new R(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 i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*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,i=!1;for(;s<r&&!1===i;)1===t.get(n,s)?i=!0:s++;for(let r=0;r<n;r++){let i=t.get(r,s);for(let o=s;o<e;o++){let e=t.get(r,o)-i*t.get(n,o);t.set(r,o,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 R(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){y(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return R.rowVector(this.getRow(t))}setRow(t,e){y(this,t),e=b(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){y(this,t),y(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){v(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return R.columnVector(this.getColumn(t))}setColumn(t,e){v(this,t),e=M(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){v(this,t),v(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=b(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=b(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=b(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=b(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){y(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){v(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(){E(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(){E(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(y(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){y(this,t),E(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(y(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){y(this,t),E(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(v(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){v(this,t),E(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(v(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){v(this,t),E(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){k.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=R.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new R(e,n),i=new Float64Array(r);for(let o=0;o<n;o++){for(let e=0;e<r;e++)i[e]=t.get(e,o);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];s.set(t,o,e)}}return s}strassen2x2(t){t=R.checkMatrix(t);let e=new R(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),i=t.get(0,1),o=this.get(1,0),a=t.get(1,0),h=this.get(1,1),l=t.get(1,1),u=(r+h)*(n+l),c=(o+h)*n,f=r*(i-l),g=h*(a-n),m=(r+s)*l,d=u+g-m+(s-h)*(a+l),p=f+m,w=c+g,y=u-c+f+(o-r)*(n+i);return e.set(0,0,d),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=R.checkMatrix(t);let e=new R(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),i=this.get(1,0),o=this.get(1,1),a=this.get(1,2),h=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),d=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),b=(r-i)*(-f+d),M=(-r+i+o)*(c-f+d),_=(i+o)*(-c+f),x=r*c,S=(-r+h+l)*(c-g+p),E=(-r+h)*(g-p),k=(h+l)*(-c+g),N=(-s+l+u)*(d+w-y),I=(s-u)*(d-y),z=s*w,A=(l+u)*(-w+y),F=(-s+o+a)*(p+w-v),C=(s-a)*(p-v),T=(o+a)*(-w+v),P=x+z+n*m,D=(r+n+s-i-o-l-u)*d+M+_+x+N+z+A,V=x+S+k+(r+n+s-o-a-h-l)*p+z+F+T,O=b+o*(-c+f+m-d-p-w+v)+M+x+z+F+C,j=b+M+_+x+a*y,B=z+F+C+T+i*g,q=x+S+E+l*(-c+g+m-d-p-w+y)+N+I+z,L=N+I+z+A+h*f,$=x+S+E+k+u*v;return e.set(0,0,P),e.set(0,1,D),e.set(0,2,V),e.set(1,0,O),e.set(1,1,j),e.set(1,2,B),e.set(2,0,q),e.set(2,1,L),e.set(2,2,$),e}mmulStrassen(t){t=R.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,i=t.columns;function o(t,e,r){let n=t.rows,s=t.columns;if(n===e&&s===r)return t;{let n=k.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(n,i);return e=o(e,a,h),function t(e,r,n,s){if(n<=512||s<=512)return e.mmul(r);n%2==1&&s%2==1?(e=o(e,n+1,s+1),r=o(r,n+1,s+1)):n%2==1?(e=o(e,n+1,s),r=o(r,n+1,s)):s%2==1&&(e=o(e,n,s+1),r=o(r,n,s+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,i-1,0,a-1),l=r.subMatrix(0,i-1,0,a-1),u=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),g=r.subMatrix(i,r.rows-1,0,a-1),m=e.subMatrix(i,e.rows-1,a,e.columns-1),d=r.subMatrix(i,r.rows-1,a,r.columns-1),p=t(k.add(h,m),k.add(l,d),i,a),w=t(k.add(f,m),l,i,a),y=t(h,k.sub(c,d),i,a),v=t(m,k.sub(g,l),i,a),b=t(k.add(h,u),d,i,a),M=t(k.sub(f,h),k.add(l,c),i,a),_=t(k.sub(u,m),k.add(g,d),i,a),x=k.add(p,v);x.sub(b),x.add(_);let S=k.add(y,b),E=k.add(w,v),N=k.sub(p,w);N.add(y),N.add(M);let R=k.zeros(2*x.rows,2*x.columns);return R=R.setSubMatrix(x,0,0),R=R.setSubMatrix(S,x.rows,0),R=R.setSubMatrix(E,0,x.columns),R=R.setSubMatrix(N,x.rows,x.columns),R.subMatrix(0,n-1,0,s-1)}(e,t=o(t,a,h),a,h)}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 R(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&f(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 R(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&f(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=R.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,i=new R(e*n,r*s);for(let o=0;o<e;o++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<s;a++)i.set(n*o+r,s*e+a,this.get(o,e)*t.get(r,a));return i}kroneckerSum(t){if(t=R.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(R.eye(r,r)),s=R.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new R(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=N){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=N){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){_(this,t,e,r,n);let s=new R(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)s.set(i-t,e-r,this.get(i,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 R(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let i=e;i<=r;i++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,i-e,this.get(t[s],i))}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 R(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let i=e;i<=r;i++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(i-e,s,this.get(i,t[s]))}return n}setSubMatrix(t,e,r){if((t=R.checkMatrix(t)).isEmpty())return this;_(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(!a(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(!a(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 R(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 i=e[t];r.set(n,t,this.get(s,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new R(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=x(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=x(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=x(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=x(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(!a(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,i=[];for(let o=0;o<n;o++){let n=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(o,e)-r[o],n+=h,a+=h*h;e?i.push((a-n*n/s)/(s-1)):i.push((a-n*n/s)/s)}return i}(this,r,n);case"column":if(!a(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,i=[];for(let o=0;o<s;o++){let s=0,a=0,h=0;for(let e=0;e<n;e++)h=t.get(e,o)-r[o],s+=h,a+=h*h;e?i.push((a-s*s/n)/(n-1)):i.push((a-s*s/n)/n)}return i}(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,i=n*s;let o=0,a=0,h=0;for(let e=0;e<n;e++)for(let n=0;n<s;n++)h=t.get(e,n)-r,o+=h,a+=h*h;return e?(a-o*o/i)/(i-1):(a-o*o/i)/i}(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(!a(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(!a(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(!a(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(!a(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 d(this,t)}}function N(t,e){return t-e}k.prototype.klass="Matrix","undefined"!=typeof Symbol&&(k.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return d(this)}),k.random=k.rand,k.randomInt=k.randInt,k.diagonal=k.diag,k.prototype.diagonal=k.prototype.diag,k.identity=k.eye,k.prototype.negate=k.prototype.neg,k.prototype.tensorProduct=k.prototype.kroneckerProduct;class R extends k{constructor(t,e){if(super(),R.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(!a(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 y(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),y(this,t,!0),e=Float64Array.from(b(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){v(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),v(this,t,!0),e=M(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}}(k,R);class I extends k{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 z{constructor(t){let e,r,n,s,i,o,a,h,l,u=(t=I.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(h=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)h[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),i=0,n=0;n<l;n++)i+=u.get(e,n)*h[n];h[e]-=i,u.set(e,r,h[e])}for(s=r,e=r+1;e<c;e++)Math.abs(h[e])>Math.abs(h[s])&&(s=e);if(s!==r){for(n=0;n<f;n++)o=u.get(s,n),u.set(s,n,u.get(r,n)),u.set(r,n,o);a=g[s],g[s]=g[r],g[r]=a,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=R.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,i=t.columns,o=t.subMatrixRow(this.pivotVector,0,i-1),a=e.columns;for(s=0;s<a;s++)for(r=s+1;r<a;r++)for(n=0;n<i;n++)o.set(r,n,o.get(r,n)-o.get(s,n)*e.get(r,s));for(s=a-1;s>=0;s--){for(n=0;n<i;n++)o.set(s,n,o.get(s,n)/e.get(s,s));for(r=0;r<s;r++)for(n=0;n<i;n++)o.set(r,n,o.get(r,n)-o.get(s,n)*e.get(r,s))}return o}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 R(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 R(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 A(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 F{constructor(t){let e,r,n,s,i=(t=I.checkMatrix(t)).clone(),o=t.rows,a=t.columns,h=new Float64Array(a);for(n=0;n<a;n++){let t=0;for(e=n;e<o;e++)t=A(t,i.get(e,n));if(0!==t){for(i.get(n,n)<0&&(t=-t),e=n;e<o;e++)i.set(e,n,i.get(e,n)/t);for(i.set(n,n,i.get(n,n)+1),r=n+1;r<a;r++){for(s=0,e=n;e<o;e++)s+=i.get(e,n)*i.get(e,r);for(s=-s/i.get(n,n),e=n;e<o;e++)i.set(e,r,i.get(e,r)+s*i.get(e,n))}}h[n]=-t}this.QR=i,this.Rdiag=h}solve(t){t=R.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,i,o,a=t.columns,h=t.clone(),l=e.columns;for(i=0;i<l;i++)for(s=0;s<a;s++){for(o=0,n=i;n<r;n++)o+=e.get(n,i)*h.get(n,s);for(o=-o/e.get(i,i),n=i;n<r;n++)h.set(n,s,h.get(n,s)+o*e.get(n,i))}for(i=l-1;i>=0;i--){for(s=0;s<a;s++)h.set(i,s,h.get(i,s)/this.Rdiag[i]);for(n=0;n<i;n++)for(s=0;s<a;s++)h.set(n,s,h.get(n,s)-h.get(i,s)*e.get(n,i))}return h.subMatrix(0,l-1,0,a-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 R(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,i=s.rows,o=s.columns,a=new R(i,o);for(r=o-1;r>=0;r--){for(t=0;t<i;t++)a.set(t,r,0);for(a.set(r,r,1),e=r;e<o;e++)if(0!==s.get(r,r)){for(n=0,t=r;t<i;t++)n+=s.get(t,r)*a.get(t,e);for(n=-n/s.get(r,r),t=r;t<i;t++)a.set(t,e,a.get(t,e)+n*s.get(t,r))}}return a}}class C{constructor(t,e={}){if((t=I.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:i=!0,autoTranspose:o=!1}=e;let a,h=Boolean(s),l=Boolean(i),u=!1;if(r<n)if(o){a=t.transpose(),r=a.rows,n=a.columns,u=!0;let e=h;h=l,l=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new R(r,c),d=new R(n,n),p=new Float64Array(n),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),M=Math.max(v,b);for(let t=0;t<M;t++){if(t<v){g[t]=0;for(let e=t;e<r;e++)g[t]=A(g[t],a.get(e,t));if(0!==g[t]){a.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/g[t]);a.set(t,t,a.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==g[t]){let n=0;for(let s=t;s<r;s++)n+=a.get(s,t)*a.get(s,e);n=-n/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+n*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)m.set(e,t,a.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<n;e++)p[t]=A(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++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)w[e]+=p[r]*a.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++)a.set(s,e,a.get(s,e)+n*w[s])}}if(l)for(let e=t+1;e<n;e++)d.set(e,t,p[e])}}let _=Math.min(n,r+1);if(v<n&&(g[v]=a.get(v,v)),r<_&&(g[_-1]=0),b+1<_&&(p[b]=a.get(b,_-1)),p[_-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=v-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<b&&0!==p[t])for(let e=t+1;e<n;e++){let r=0;for(let s=t+1;s<n;s++)r+=d.get(s,t)*d.get(s,e);r=-r/d.get(t+1,t);for(let s=t+1;s<n;s++)d.set(s,e,d.get(s,e)+r*d.get(s,t))}for(let e=0;e<n;e++)d.set(e,t,0);d.set(t,t,1)}let x=_-1,S=0,E=Number.EPSILON;for(;_>0;){let t,e;for(t=_-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+E*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===_-2)e=4;else{let r;for(r=_-1;r>=t&&r!==t;r--){let e=(r!==_?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(g[r])<=E*e){g[r]=0;break}}r===t?e=3:r===_-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[_-2];p[_-2]=0;for(let r=_-2;r>=t;r--){let s=A(g[r],e),i=g[r]/s,o=e/s;if(g[r]=s,r!==t&&(e=-o*p[r-1],p[r-1]=i*p[r-1]),l)for(let t=0;t<n;t++)s=i*d.get(t,r)+o*d.get(t,_-1),d.set(t,_-1,-o*d.get(t,r)+i*d.get(t,_-1)),d.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let n=t;n<_;n++){let s=A(g[n],e),i=g[n]/s,o=e/s;if(g[n]=s,e=-o*p[n],p[n]=i*p[n],h)for(let e=0;e<r;e++)s=i*m.get(e,n)+o*m.get(e,t-1),m.set(e,t-1,-o*m.get(e,n)+i*m.get(e,t-1)),m.set(e,n,s)}break}case 3:{const e=Math.max(Math.abs(g[_-1]),Math.abs(g[_-2]),Math.abs(p[_-2]),Math.abs(g[t]),Math.abs(p[t])),s=g[_-1]/e,i=g[_-2]/e,o=p[_-2]/e,a=g[t]/e,u=p[t]/e,c=((i+s)*(i-s)+o*o)/2,f=s*o*(s*o);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*u;for(let e=t;e<_-1;e++){let s=A(y,v);0===s&&(s=Number.MIN_VALUE);let i=y/s,o=v/s;if(e!==t&&(p[e-1]=s),y=i*g[e]+o*p[e],p[e]=i*p[e]-o*g[e],v=o*g[e+1],g[e+1]=i*g[e+1],l)for(let t=0;t<n;t++)s=i*d.get(t,e)+o*d.get(t,e+1),d.set(t,e+1,-o*d.get(t,e)+i*d.get(t,e+1)),d.set(t,e,s);if(s=A(y,v),0===s&&(s=Number.MIN_VALUE),i=y/s,o=v/s,g[e]=s,y=i*p[e]+o*g[e+1],g[e+1]=-o*p[e]+i*g[e+1],v=o*p[e+1],p[e+1]=i*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=i*m.get(t,e)+o*m.get(t,e+1),m.set(t,e+1,-o*m.get(t,e)+i*m.get(t,e+1)),m.set(t,e,s)}p[_-2]=y,S+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=x;e++)d.set(e,t,-d.get(e,t));for(;t<x&&!(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=d.get(r,t+1),d.set(r,t+1,d.get(r,t)),d.set(r,t,e);if(h&&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++}S=0,_--}}if(u){let t=d;d=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=d}solve(t){let e=t,r=this.threshold,n=this.s.length,s=R.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 i=this.U,o=this.rightSingularVectors,a=o.mmul(s),h=o.rows,l=i.rows,u=R.zeros(h,l);for(let t=0;t<h;t++)for(let e=0;e<l;e++){let r=0;for(let s=0;s<n;s++)r+=a.get(t,s)*i.get(e,s);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(R.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new R(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&s.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,o=i.rows,a=i.columns,h=new R(r,o);for(let t=0;t<r;t++)for(let e=0;e<o;e++){let r=0;for(let n=0;n<a;n++)r+=s.get(t,n)*i.get(e,n);h.set(t,e,r)}return h}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 R.diag(this.s)}}function T(t,e,r,n,s){let i=r*n*n,o=R.eye(e.length,e.length,i);const a=s(e);let h=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)h[e]=a(t.x[e]);let l=function(t,e,r,n,s){const i=r.length,o=t.x.length;let a=new Array(i);for(let h=0;h<i;h++){a[h]=new Array(o);let i=r.slice();i[h]+=n;let l=s(i);for(let r=0;r<o;r++)a[h][r]=e[r]-l(t.x[r])}return new R(a)}(t,h,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 R(n)}(t,h),c=function(t,e=!1){return t=I.checkMatrix(t),e?new C(t).inverse():function(t,e,r=!1){return t=I.checkMatrix(t),e=I.checkMatrix(e),r?new C(t).solve(e):t.isSquare()?new z(t).solve(e):new F(t).solve(e)}(t,R.eye(t.rows))}(o.add(l.mmul(l.transpose())));return(e=(e=new R([e])).sub(c.mmul(l).mmul(u).mul(n).transpose())).to1DArray()}function P(t,e,r={}){let{maxIterations:n=100,gradientDifference:o=.1,damping:a=0,errorTolerance:h=.01,minValues:l,maxValues:u,initialValues:c}=r;if(a<=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(!s(t.x)||t.x.length<2||!s(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 f=c||new Array(e.length).fill(1),g=f.length;if(u=u||new Array(g).fill(Number.MAX_SAFE_INTEGER),l=l||new Array(g).fill(Number.MIN_SAFE_INTEGER),u.length!==l.length)throw new Error("minValues and maxValues must be the same size");if(!s(f))throw new Error("initialValues must be an array");let m,d=i(t,f,e),p=d<=h;for(m=0;m<n&&!p;m++){f=T(t,f,a,o,e);for(let t=0;t<g;t++)f[t]=Math.min(Math.max(l[t],f[t]),u[t]);if(d=i(t,f,e),isNaN(d))break;p=d<=h}return{parameterValues:f,parameterError:d,iterations:m}}},9378:function(t,e,r){var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var s=n(r(4517));function i(t,e){var r=function(r){return s.empty(t).map((function(){return s.filled(e,r)}))},n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function o(t,e,r,n,s){e=Math.floor(e);var i=t[0][e],o=t[1][e];if(t[2][e],r>=o[0])return 0;for(var h=0;h<i.length;h++)if(n===i[h])return 0;return a(t,e,r,n,s)}function a(t,e,r,n,s){var i=t[0][e],o=t[1][e],a=t[2][e];if(r>=o[0])return 0;o[0]=r,i[0]=n,a[0]=s;for(var h=0,l=0;;){var u=2*h+1,c=u+1,f=t[0][0].length;if(u>=f)break;if(c>=f){if(!(o[u]>r))break;l=u}else if(o[u]>=o[c]){if(!(r<o[u]))break;l=u}else{if(!(r<o[c]))break;l=c}o[h]=o[l],i[h]=i[l],a[h]=a[l],h=l}return o[h]=r,i[h]=n,a[h]=s,1}function h(t,e,r,n){for(;2*n+1<r;){var s=2*n+1,i=s+1,o=n;if(t[o]<t[s]&&(o=s),i<r&&t[o]<t[i]&&(o=i),o===n)break;var a=t[n];t[n]=t[o],t[o]=a;var h=e[n];e[n]=e[o],e[o]=h,n=o}}e.makeHeap=i,e.rejectionSample=function(t,e,r){for(var n=s.zeros(t),i=0;i<t;i++){for(var o=!0,a=0;o;){a=s.tauRandInt(e,r);for(var h=!1,l=0;l<i;l++)if(a===n[l]){h=!0;break}h||(o=!1)}n[i]=a}return n},e.heapPush=o,e.uncheckedHeapPush=a,e.buildCandidates=function(t,e,r,n,a){for(var h=i(e,n),l=0;l<e;l++)for(var u=0;u<r;u++)if(!(t[0][l][u]<0)){var c=t[0][l][u],f=t[2][l][u],g=s.tauRand(a);o(h,l,g,c,f),o(h,c,g,l,f),t[2][l][u]=0}return h},e.deheapSort=function(t){for(var e=t[0],r=t[1],n=0;n<e.length;n++)for(var s=e[n],i=r[n],o=0;o<s.length-1;o++){var a=s.length-o-1,l=i.length-o-1,u=s[0];s[0]=s[a],s[a]=u;var c=i[0];i[0]=i[l],i[l]=c,h(i,s,l,0)}return{indices:e,weights:r}},e.smallestFlagged=function(t,e){for(var r=t[0][e],n=t[1][e],s=t[2][e],i=1/0,o=-1,a=0;a>r.length;a++)1===s[a]&&n[a]<i&&(i=n[a],o=a);return o>=0?(s[o]=0,Math.floor(r[o])):-1}},4221:(t,e,r)=>{var n=r(4364);e.u=n.UMAP},5686:function(t,e,r){var n,s=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var a=o(r(4517)),h=function(){function t(t,e,r,n){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(var s=0;s<r.length;s++){var i=t[s],o=e[s];this.checkDims(i,o);var a=this.makeKey(i,o);this.entries.set(a,{value:r[s],row:i,col:o})}}return t.prototype.makeKey=function(t,e){return t+":"+e},t.prototype.checkDims=function(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")},t.prototype.set=function(t,e,r){this.checkDims(t,e);var 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})},t.prototype.get=function(t,e,r){void 0===r&&(r=0),this.checkDims(t,e);var n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).value:r},t.prototype.getAll=function(t){void 0===t&&(t=!0);var e=[];return this.entries.forEach((function(t){e.push(t)})),t&&e.sort((function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row})),e},t.prototype.getDims=function(){return[this.nRows,this.nCols]},t.prototype.getRows=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].row}))},t.prototype.getCols=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].col}))},t.prototype.getValues=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].value}))},t.prototype.forEach=function(t){this.entries.forEach((function(e){return t(e.value,e.row,e.col)}))},t.prototype.map=function(e){var r=[];this.entries.forEach((function(t){r.push(e(t.value,t.row,t.col))}));var n=[this.nRows,this.nCols];return new t(this.getRows(),this.getCols(),r,n)},t.prototype.toArray=function(){var t=this,e=a.empty(this.nRows).map((function(){return a.zeros(t.nCols)}));return this.entries.forEach((function(t){e[t.row][t.col]=t.value})),e},t}();e.SparseMatrix=h,e.transpose=function(t){var e=[],r=[],n=[];t.forEach((function(t,s,i){e.push(s),r.push(i),n.push(t)}));var s=[t.nCols,t.nRows];return new h(r,e,n,s)},e.identity=function(t){for(var e=s(t,1)[0],r=new h([],[],[],t),n=0;n<e;n++)r.set(n,n,1);return r},e.pairwiseMultiply=function(t,e){return u(t,e,(function(t,e){return t*e}))},e.add=function(t,e){return u(t,e,(function(t,e){return t+e}))},e.subtract=function(t,e){return u(t,e,(function(t,e){return t-e}))},e.maximum=function(t,e){return u(t,e,(function(t,e){return t>e?t:e}))},e.multiplyScalar=function(t,e){return t.map((function(t){return t*e}))},e.eliminateZeros=function(t){for(var e=new Set,r=t.getValues(),n=t.getRows(),s=t.getCols(),i=0;i<r.length;i++)0===r[i]&&e.add(i);var o=function(t,r){return!e.has(r)},a=r.filter(o),l=n.filter(o),u=s.filter(o);return new h(l,u,a,t.getDims())},e.normalize=function(t,e){var r,n;void 0===e&&(e="l2");var s=l[e],o=new Map;t.forEach((function(t,e,r){var n=o.get(e)||[];n.push(r),o.set(e,n)}));var a=new h([],[],[],t.getDims()),u=function(e){for(var r=o.get(e).sort(),n=r.map((function(r){return t.get(e,r)})),i=s(n),h=0;h<i.length;h++)a.set(e,r[h],i[h])};try{for(var c=i(o.keys()),f=c.next();!f.done;f=c.next())u(f.value)}catch(t){r={error:t}}finally{try{f&&!f.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}return a};var l=((n={}).max=function(t){for(var e=-1/0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map((function(t){return t/e}))},n.l1=function(t){for(var e=0,r=0;r<t.length;r++)e+=t[r];return t.map((function(t){return t/e}))},n.l2=function(t){for(var e=0,r=0;r<t.length;r++)e+=Math.pow(t[r],2);return t.map((function(t){return Math.sqrt(Math.pow(t,2)/e)}))},n);function u(t,e,r){for(var n=new Set,s=[],i=[],o=[],a=function(n,a){s.push(n),i.push(a);var h=r(t.get(n,a),e.get(n,a));o.push(h)},l=t.getValues(),u=t.getRows(),c=t.getCols(),f=0;f<l.length;f++){var g=(w=u[f])+":"+(y=c[f]);n.add(g),a(w,y)}var m=e.getValues(),d=e.getRows(),p=e.getCols();for(f=0;f<m.length;f++){var w,y;g=(w=d[f])+":"+(y=p[f]),n.has(g)||a(w,y)}var v=[t.nRows,t.nCols];return new h(s,i,o,v)}e.getCSR=function(t){var e=[];t.forEach((function(t,r,n){e.push({value:t,row:r,col:n})})),e.sort((function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row}));for(var r=[],n=[],s=[],i=-1,o=0;o<e.length;o++){var a=e[o],h=a.row,l=a.col,u=a.value;h!==i&&(i=h,s.push(o)),r.push(l),n.push(u)}return{indices:r,values:n,indptr:s}}},760:function(t,e,r){var n=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var i=s(r(9378)),o=s(r(5686)),a=s(r(2320)),h=s(r(4517));e.makeNNDescent=function(t,e){return function(r,n,s,o,a,l,u,c){void 0===o&&(o=10),void 0===a&&(a=50),void 0===l&&(l=.001),void 0===u&&(u=.5),void 0===c&&(c=!0);for(var f=r.length,g=i.makeHeap(r.length,s),m=0;m<r.length;m++)for(var d=i.rejectionSample(s,r.length,e),p=0;p<d.length;p++){var w=t(r[m],r[d[p]]);i.heapPush(g,m,w,d[p],1),i.heapPush(g,d[p],w,m,1)}if(c)for(var y=0;y<n.length;y++)for(m=0;m<n[y].length&&!(n[y][m]<0);m++)for(p=m+1;p<n[y].length&&!(n[y][p]<0);p++)w=t(r[n[y][m]],r[n[y][p]]),i.heapPush(g,n[y][m],w,n[y][p],1),i.heapPush(g,n[y][p],w,n[y][m],1);for(y=0;y<o;y++){var v=i.buildCandidates(g,f,s,a,e),b=0;for(m=0;m<f;m++)for(p=0;p<a;p++){var M=Math.floor(v[0][m][p]);if(!(M<0||h.tauRand(e)<u))for(var _=0;_<a;_++){var x=Math.floor(v[0][m][_]),S=v[2][m][p],E=v[2][m][_];x<0||!S&&!E||(w=t(r[M],r[x]),b+=i.heapPush(g,M,w,x,1),b+=i.heapPush(g,x,w,M,1))}}if(b<=l*s*r.length)break}return i.deheapSort(g)}},e.makeInitializations=function(t){return{initFromRandom:function(e,r,n,s,o){for(var a=0;a<n.length;a++)for(var l=h.rejectionSample(e,r.length,o),u=0;u<l.length;u++)if(!(l[u]<0)){var c=t(r[l[u]],n[a]);i.heapPush(s,a,c,l[u],1)}},initFromTree:function(e,r,n,s,o){for(var h=0;h<n.length;h++)for(var l=a.searchFlatTree(n[h],e,o),u=0;u<l.length;u++){if(l[u]<0)return;var c=t(r[l[u]],n[h]);i.heapPush(s,h,c,l[u],1)}}}},e.makeInitializedNNSearch=function(t){return function(e,r,s,a){for(var h,l,u=o.getCSR(r),c=u.indices,f=u.indptr,g=0;g<a.length;g++)for(var m=new Set(s[0][g]);;){var d=i.smallestFlagged(s,g);if(-1===d)break;var p=c.slice(f[d],f[d+1]);try{for(var w=n(p),y=w.next();!y.done;y=w.next()){var v=y.value;if(v!==d&&-1!==v&&!m.has(v)){var b=t(e[v],a[g]);i.uncheckedHeapPush(s,g,b,v,1),m.add(v)}}}catch(t){h={error:t}}finally{try{y&&!y.done&&(l=w.return)&&l.call(w)}finally{if(h)throw h.error}}}return s}},e.initializeSearch=function(t,e,r,s,o,a,h){var l,u,c=i.makeHeap(r.length,s);if(o(s,e,r,c,h),t)try{for(var f=n(t),g=f.next();!g.done;g=f.next())a(g.value,e,r,c,h)}catch(t){l={error:t}}finally{try{g&&!g.done&&(u=f.return)&&u.call(f)}finally{if(l)throw l.error}}return c}},2320:function(t,e,r){var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},s=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var a=o(r(4517)),h=function(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n};function l(t,e,r,n,s){if(void 0===r&&(r=30),e.length>r){var i=function(t,e,r){var n=t[0].length,s=a.tauRandInt(e.length,r),i=a.tauRandInt(e.length,r);i=(i+=s===i?1:0)%e.length;for(var o=e[s],h=e[i],l=0,u=a.zeros(n),c=0;c<u.length;c++)u[c]=t[o][c]-t[h][c],l-=u[c]*(t[o][c]+t[h][c])/2;var f=0,g=0,m=a.zeros(e.length);for(c=0;c<e.length;c++){for(var d=l,p=0;p<n;p++)d+=u[p]*t[e[c]][p];0===d?(m[c]=a.tauRandInt(2,r),0===m[c]?f+=1:g+=1):d>0?(m[c]=0,f+=1):(m[c]=1,g+=1)}var w=a.zeros(f),y=a.zeros(g);for(f=0,g=0,c=0;c<m.length;c++)0===m[c]?(w[f]=e[c],f+=1):(y[g]=e[c],g+=1);return{indicesLeft:w,indicesRight:y,hyperplane:u,offset:l}}(t,e,s),o=i.indicesLeft,h=i.indicesRight,u=i.hyperplane,c=i.offset;return{leftChild:l(t,o,r,n+1,s),rightChild:l(t,h,r,n+1,s),isLeaf:!1,hyperplane:u,offset:c}}return{indices:e,isLeaf:!0}}function u(t,e,r,n,i,o,a){var h;if(t.isLeaf)return n[o][0]=-a,(h=i[a]).splice.apply(h,s([0,t.indices.length],t.indices)),{nodeNum:o,leafNum:a+=1};e[o]=t.hyperplane,r[o]=t.offset,n[o][0]=o+1;var l=o,c=u(t.leftChild,e,r,n,i,o+1,a);return o=c.nodeNum,a=c.leafNum,n[l][1]=o+1,{nodeNum:(c=u(t.rightChild,e,r,n,i,o+1,a)).nodeNum,leafNum:c.leafNum}}function c(t){return t.isLeaf?1:1+c(t.leftChild)+c(t.rightChild)}function f(t){return t.isLeaf?1:f(t.leftChild)+f(t.rightChild)}function g(t,e,r,n){for(var s=e,i=0;i<r.length;i++)s+=t[i]*r[i];return 0===s?a.tauRandInt(2,n):s>0?0:1}e.FlatTree=h,e.makeForest=function(t,e,r,n){var s=Math.max(10,e);return a.range(r).map((function(e,r){return function(t,e,r,n){return void 0===e&&(e=30),l(t,a.range(t.length),e,r,n)}(t,s,r,n)})).map((function(t){return function(t,e){var r=c(t),n=f(t),s=a.range(r).map((function(){return a.zeros(t.hyperplane?t.hyperplane.length:0)})),i=a.zeros(r),o=a.range(r).map((function(){return[-1,-1]})),l=a.range(n).map((function(){return a.range(e).map((function(){return-1}))}));return u(t,s,i,o,l,0,0),new h(s,i,o,l)}(t,s)}))},e.makeLeafArray=function(t){var e,r;if(t.length>0){var n=[];try{for(var o=i(t),a=o.next();!a.done;a=o.next()){var h=a.value;n.push.apply(n,s(h.indices))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return n}return[[-1]]},e.searchFlatTree=function(t,e,r){for(var n=0;e.children[n][0]>0;)n=0===g(e.hyperplanes[n],e.offsets[n],t,r)?e.children[n][0]:e.children[n][1];var s=-1*e.children[n][0];return e.indices[s]}},4364:function(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(s,i){function o(t){try{h(n.next(t))}catch(t){i(t)}}function a(t){try{h(n.throw(t))}catch(t){i(t)}}function h(t){t.done?s(t.value):new r((function(e){e(t.value)})).then(o,a)}h((n=n.apply(t,e||[])).next())}))},s=this&&this.__generator||function(t,e){var r,n,s,i,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(s=2&i[0]?n.return:i[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,i[1])).done)return s;switch(n=0,s&&(i=[2&i[0],s.value]),i[0]){case 0:case 1:s=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((s=(s=o.trys).length>0&&s[s.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!s||i[1]>s[0]&&i[1]<s[3])){o.label=i[1];break}if(6===i[0]&&o.label<s[1]){o.label=s[1],s=i;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(i);break}s[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(t){i=[6,t],n=0}finally{r=s=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},i=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},o=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t},a=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e},h=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var l=a(r(9378)),u=a(r(5686)),c=a(r(760)),f=a(r(2320)),g=a(r(4517)),m=h(r(9251)),d=1e-5,p=.001,w=function(){function t(t){void 0===t&&(t={});var e=this;this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=y,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new v;var r=function(r){void 0!==t[r]&&(e[r]=t[r])};r("distanceFn"),r("learningRate"),r("localConnectivity"),r("minDist"),r("nComponents"),r("nEpochs"),r("nNeighbors"),r("negativeSampleRate"),r("random"),r("repulsionStrength"),r("setOpMixRatio"),r("spread"),r("transformQueueSize")}return t.prototype.fit=function(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding},t.prototype.fitAsync=function(t,e){return void 0===e&&(e=function(){return!0}),n(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return this.initializeFit(t),[4,this.optimizeLayoutAsync(e)];case 1:return r.sent(),[2,this.embedding]}}))}))},t.prototype.setSupervisedProjection=function(t,e){void 0===e&&(e={}),this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors},t.prototype.setPrecomputedKNN=function(t,e){this.knnIndices=t,this.knnDistances=e},t.prototype.initializeFit=function(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){var 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();var r=this.initializeSimplicialSetEmbedding(),n=r.head,s=r.tail,i=r.epochsPerSample;return this.optimizationState.head=n,this.optimizationState.tail=s,this.optimizationState.epochsPerSample=i,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()},t.prototype.makeSearchFns=function(){var t=c.makeInitializations(this.distanceFn),e=t.initFromTree,r=t.initFromRandom;this.initFromTree=e,this.initFromRandom=r,this.search=c.makeInitializedNNSearch(this.distanceFn)},t.prototype.makeSearchGraph=function(t){for(var e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],s=new u.SparseMatrix([],[],[],n),i=0;i<e.length;i++)for(var o=e[i],a=r[i],h=0;h<o.length;h++){var l=o[h],c=a[h];c>0&&s.set(i,l,c)}var f=u.transpose(s);return u.maximum(s,f)},t.prototype.transform=function(t){var e=this,r=this.X;if(void 0===r||0===r.length)throw new Error("No data has been fit.");var n=Math.floor(this.nNeighbors*this.transformQueueSize);n=Math.min(r.length,n);var s=c.initializeSearch(this.rpForest,r,t,n,this.initFromRandom,this.initFromTree,this.random),i=this.search(r,this.searchGraph,s,t),o=l.deheapSort(i),a=o.indices,h=o.weights;a=a.map((function(t){return t.slice(0,e.nNeighbors)})),h=h.map((function(t){return t.slice(0,e.nNeighbors)}));var f=Math.max(0,this.localConnectivity-1),m=this.smoothKNNDistance(h,this.nNeighbors,f),d=m.sigmas,p=m.rhos,w=this.computeMembershipStrengths(a,h,d,p),y=w.rows,v=w.cols,b=w.vals,M=[t.length,r.length],_=new u.SparseMatrix(y,v,b,M),x=u.normalize(_,"l1"),S=u.getCSR(x),k=t.length,N=E(g.reshape2d(S.indices,k,this.nNeighbors),g.reshape2d(S.values,k,this.nNeighbors),this.embedding),R=this.nEpochs?this.nEpochs/3:_.nRows<=1e4?100:30,I=_.getValues().reduce((function(t,e){return e>t?e:t}),0);_=_.map((function(t){return t<I/R?0:t})),_=u.eliminateZeros(_);var z=this.makeEpochsPerSample(_.getValues(),R),A=_.getRows(),F=_.getCols();return this.assignOptimizationStateParameters({headEmbedding:N,tailEmbedding:this.embedding,head:A,tail:F,currentEpoch:0,nEpochs:R,nVertices:_.getDims()[1],epochsPerSample:z}),this.prepareForOptimizationLoop(),this.optimizeLayout()},t.prototype.processGraphForSupervisedProjection=function(){var t=this.Y,e=this.X;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){var r=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,r)}}},t.prototype.step=function(){var t=this.optimizationState.currentEpoch;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch},t.prototype.getEmbedding=function(){return this.embedding},t.prototype.nearestNeighbors=function(t){var e,r=this.distanceFn,n=this.nNeighbors,s=c.makeNNDescent(r,this.random),i=5+Math.floor(.5==(e=Math.pow(t.length,.5)/20)?0:Math.round(e)),o=Math.max(5,Math.floor(Math.round(function(t){return Math.log(t)/Math.log(2)}(t.length))));this.rpForest=f.makeForest(t,n,i,this.random);var a=s(t,f.makeLeafArray(this.rpForest),n,o);return{knnIndices:a.indices,knnDistances:a.weights}},t.prototype.fuzzySimplicialSet=function(t,e,r){void 0===r&&(r=1);var n=this,s=n.knnIndices,i=void 0===s?[]:s,o=n.knnDistances,a=void 0===o?[]:o,h=n.localConnectivity,l=this.smoothKNNDistance(a,e,h),c=l.sigmas,f=l.rhos,g=this.computeMembershipStrengths(i,a,c,f),m=g.rows,d=g.cols,p=g.vals,w=[t.length,t.length],y=new u.SparseMatrix(m,d,p,w),v=u.transpose(y),b=u.pairwiseMultiply(y,v),M=u.subtract(u.add(y,v),b),_=u.multiplyScalar(M,r),x=u.multiplyScalar(b,1-r);return u.add(_,x)},t.prototype.categoricalSimplicialSetIntersection=function(t,e,r,n){void 0===n&&(n=1);var s=x(t,e,n,r);return S(s=u.eliminateZeros(s))},t.prototype.smoothKNNDistance=function(t,e,r,n,s){void 0===r&&(r=1),void 0===n&&(n=64),void 0===s&&(s=1);for(var i=Math.log(e)/Math.log(2)*s,o=g.zeros(t.length),a=g.zeros(t.length),h=0;h<t.length;h++){var l=0,u=1/0,c=1,f=t[h],m=f.filter((function(t){return t>0}));if(m.length>=r){var w=Math.floor(r),y=r-w;w>0?(o[h]=m[w-1],y>d&&(o[h]+=y*(m[w]-m[w-1]))):o[h]=y*m[0]}else m.length>0&&(o[h]=g.max(m));for(var v=0;v<n;v++){for(var b=0,M=1;M<t[h].length;M++){var _=t[h][M]-o[h];b+=_>0?Math.exp(-_/c):1}if(Math.abs(b-i)<d)break;b>i?c=(l+(u=c))/2:(l=c,u===1/0?c*=2:c=(l+u)/2)}if(a[h]=c,o[h]>0){var x=g.mean(f);a[h]<p*x&&(a[h]=p*x)}else{var S=g.mean(t.map(g.mean));a[h]<p*S&&(a[h]=p*S)}}return{sigmas:a,rhos:o}},t.prototype.computeMembershipStrengths=function(t,e,r,n){for(var s=t.length,i=t[0].length,o=g.zeros(s*i),a=g.zeros(s*i),h=g.zeros(s*i),l=0;l<s;l++)for(var u=0;u<i;u++){var c=0;-1!==t[l][u]&&(c=t[l][u]===l?0:e[l][u]-n[l]<=0?1:Math.exp(-(e[l][u]-n[l])/r[l]),o[l*i+u]=l,a[l*i+u]=t[l][u],h[l*i+u]=c)}return{rows:o,cols:a,vals:h}},t.prototype.initializeSimplicialSetEmbedding=function(){for(var t=this,e=this.getNEpochs(),r=this.nComponents,n=this.graph.getValues(),s=0,i=0;i<n.length;i++){var o=n[i];s<n[i]&&(s=o)}var a=this.graph.map((function(t){return t<s/e?0:t}));this.embedding=g.zeros(a.nRows).map((function(){return g.zeros(r).map((function(){return 20*g.tauRand(t.random)-10}))}));var h=[],l=[],u=[],c=a.getAll();for(i=0;i<c.length;i++){var f=c[i];f.value&&(h.push(f.value),u.push(f.row),l.push(f.col))}return{head:l,tail:u,epochsPerSample:this.makeEpochsPerSample(h,e)}},t.prototype.makeEpochsPerSample=function(t,e){var r=g.filled(t.length,-1),n=g.max(t),s=t.map((function(t){return t/n*e}));return s.forEach((function(t,n){t>0&&(r[n]=e/s[n])})),r},t.prototype.assignOptimizationStateParameters=function(t){Object.assign(this.optimizationState,t)},t.prototype.prepareForOptimizationLoop=function(){var t=this,e=t.repulsionStrength,r=t.learningRate,n=t.negativeSampleRate,s=this.optimizationState,i=s.epochsPerSample,a=s.headEmbedding,h=s.tailEmbedding,l=a[0].length,u=a.length===h.length,c=i.map((function(t){return t/n})),f=o(c),g=o(i);this.assignOptimizationStateParameters({epochOfNextSample:g,epochOfNextNegativeSample:f,epochsPerNegativeSample:c,moveOther:u,initialAlpha:r,alpha:r,gamma:e,dim:l})},t.prototype.initializeOptimization=function(){var t=this.embedding,e=this.embedding,r=this.optimizationState,n=r.head,s=r.tail,i=r.epochsPerSample,o=this.getNEpochs(),a=this.graph.nCols,h=_(this.spread,this.minDist),l=h.a,u=h.b;this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:n,tail:s,epochsPerSample:i,a:l,b:u,nEpochs:o,nVertices:a})},t.prototype.optimizeLayoutStep=function(t){for(var e=this.optimizationState,r=e.head,n=e.tail,s=e.headEmbedding,i=e.tailEmbedding,o=e.epochsPerSample,a=e.epochOfNextSample,h=e.epochOfNextNegativeSample,l=e.epochsPerNegativeSample,u=e.moveOther,c=e.initialAlpha,f=e.alpha,m=e.gamma,d=e.a,p=e.b,w=e.dim,y=e.nEpochs,v=e.nVertices,_=0;_<o.length;_++)if(!(a[_]>t)){var x=r[_],S=n[_],E=s[x],k=i[S],N=M(E,k),R=0;N>0&&(R=-2*d*p*Math.pow(N,p-1),R/=d*Math.pow(N,p)+1);for(var I=0;I<w;I++){var z=b(R*(E[I]-k[I]),4);E[I]+=z*f,u&&(k[I]+=-z*f)}a[_]+=o[_];for(var A=Math.floor((t-h[_])/l[_]),F=0;F<A;F++){var C=g.tauRandInt(v,this.random),T=i[C],P=M(E,T),D=0;if(P>0)D=2*m*p,D/=(.001+P)*(d*Math.pow(P,p)+1);else if(x===C)continue;for(I=0;I<w;I++)z=4,D>0&&(z=b(D*(E[I]-T[I]),4)),E[I]+=z*f}h[_]+=A*l[_]}return e.alpha=c*(1-t/y),e.currentEpoch+=1,s},t.prototype.optimizeLayoutAsync=function(t){var e=this;return void 0===t&&(t=function(){return!0}),new Promise((function(r,i){var o=function(){return n(e,void 0,void 0,(function(){var e,n,a,h,l,u;return s(this,(function(s){try{if(e=this.optimizationState,n=e.nEpochs,a=e.currentEpoch,this.embedding=this.optimizeLayoutStep(a),h=this.optimizationState.currentEpoch,l=!1===t(h),u=h===n,l||u)return[2,r(u)];setTimeout((function(){return o()}),0)}catch(t){i(t)}return[2]}))}))};setTimeout((function(){return o()}),0)}))},t.prototype.optimizeLayout=function(t){void 0===t&&(t=function(){return!0});for(var e=!1,r=[];!e;){var n=this.optimizationState,s=n.nEpochs,i=n.currentEpoch;r=this.optimizeLayoutStep(i);var o=this.optimizationState.currentEpoch,a=!1===t(o);e=o===s||a}return r},t.prototype.getNEpochs=function(){var t=this.graph;if(this.nEpochs>0)return this.nEpochs;var e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200},t}();function y(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return Math.sqrt(r)}e.UMAP=w,e.euclidean=y,e.cosine=function(t,e){for(var r=0,n=0,s=0,i=0;i<t.length;i++)r+=t[i]*e[i],n+=Math.pow(t[i],2),s+=Math.pow(e[i],2);return 0===n&&0===s?0:0===n||0===s?1:1-r/Math.sqrt(n*s)};var v=function(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0};function b(t,e){return t>e?e:t<-e?-e:t}function M(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}function _(t,e){var r=g.linear(0,3*t,300).map((function(t){return t<e?1:t})),n=g.zeros(r.length).map((function(n,s){return r[s]>=e?Math.exp(-(r[s]-e)/t):n})),s={x:r,y:n},o=m.default(s,(function(t){var e=i(t,2),r=e[0],n=e[1];return function(t){return 1/(1+r*Math.pow(t,2*n))}}),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}).parameterValues,a=i(o,2);return{a:a[0],b:a[1]}}function x(t,e,r,n){return void 0===r&&(r=1),void 0===n&&(n=5),t.map((function(t,s,i){return-1===e[s]||-1===e[i]?t*Math.exp(-r):e[s]!==e[i]?t*Math.exp(-n):t}))}function S(t){t=u.normalize(t,"max");var e=u.transpose(t),r=u.pairwiseMultiply(e,t);return t=u.add(t,u.subtract(e,r)),u.eliminateZeros(t)}function E(t,e,r){for(var n=g.zeros(t.length).map((function(t){return g.zeros(r[0].length)})),s=0;s<t.length;s++)for(var i=0;i<t[0].length;i++)for(var o=0;o<r[0].length;o++){var a=t[s][i];n[s][o]+=e[s][i]*r[a][o]}return n}e.findABParams=_,e.fastIntersection=x,e.resetLocalConnectivity=S,e.initTransform=E},4517:function(t,e){var r=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}};function n(t,e){return Math.floor(e()*t)}function s(t){for(var e=[],r=0;r<t;r++)e.push(void 0);return e}function i(t,e){return s(t).map((function(){return e}))}function o(t){return i(t,0)}function a(t){return t.reduce((function(t,e){return t+e}))}Object.defineProperty(e,"__esModule",{value:!0}),e.tauRandInt=n,e.tauRand=function(t){return t()},e.norm=function(t){var e,n,s=0;try{for(var i=r(t),o=i.next();!o.done;o=i.next()){var a=o.value;s+=Math.pow(a,2)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return Math.sqrt(s)},e.empty=s,e.range=function(t){return s(t).map((function(t,e){return e}))},e.filled=i,e.zeros=o,e.ones=function(t){return i(t,1)},e.linear=function(t,e,r){return s(r).map((function(n,s){return t+s*((e-t)/(r-1))}))},e.sum=a,e.mean=function(t){return a(t)/t.length},e.max=function(t){for(var e=0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e},e.max2d=function(t){for(var e=0,r=0;r<t.length;r++)for(var n=0;n<t[r].length;n++)e=t[r][n]>e?t[r][n]:e;return e},e.rejectionSample=function(t,e,r){for(var s=o(t),i=0;i<t;i++)for(var a=!0;a;){for(var h=n(e,r),l=!1,u=0;u<i;u++)if(h===s[u]){l=!0;break}l||(a=!1),s[i]=h}return s},e.reshape2d=function(t,e,r){var n=[],s=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(var i=0;i<e;i++){for(var o=[],a=0;a<r;a++)o.push(t[s]),s+=1;n.push(o)}return n}}},n={};function s(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,s),i.exports}s.m=r,s.x=()=>{var t=s.O(void 0,[1,452],(()=>s(1729)));return s.O(t)},t=[],s.O=(e,r,n,i)=>{if(!r){var o=1/0;for(u=0;u<t.length;u++){for(var[r,n,i]=t[u],a=!0,h=0;h<r.length;h++)(!1&i||o>=i)&&Object.keys(s.O).every((t=>s.O[t](r[h])))?r.splice(h--,1):(a=!1,i<o&&(o=i));if(a){t.splice(u--,1);var l=n();void 0!==l&&(e=l)}}return e}i=i||0;for(var u=t.length;u>0&&t[u-1][2]>i;u--)t[u]=t[u-1];t[u]=[r,n,i]},s.d=(t,e)=>{for(var r in e)s.o(e,r)&&!s.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},s.f={},s.e=t=>Promise.all(Object.keys(s.f).reduce(((e,r)=>(s.f[r](t,e),e)),[])),s.u=t=>t+".js",s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;s.g.importScripts&&(t=s.g.location+"");var e=s.g.document;if(!t&&e&&(e.currentScript&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");r.length&&(t=r[r.length-1].src)}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=t})(),(()=>{s.b=self.location+"";var t={729:1};s.f.i=(e,r)=>{t[e]||importScripts(s.p+s.u(e))};var e=self.webpackChunkbio=self.webpackChunkbio||[],r=e.push.bind(e);e.push=e=>{var[n,i,o]=e;for(var a in i)s.o(i,a)&&(s.m[a]=i[a]);for(o&&o(s);n.length;)t[n.pop()]=1;r(e)}})(),e=s.x,s.x=()=>Promise.all([s.e(1),s.e(452)]).then(e);var i=s.x();bio=i})();
|
|
1
|
+
var bio;(()=>{"use strict";var t,e,r={1040:(t,e,r)=>{var n,s,i,o,a;r.d(e,{CF:()=>s,Qe:()=>o,W:()=>n,Yc:()=>a,gk:()=>i}),function(t){t.Levenshtein="Levenshtein",t.JaroWinkler="Jaro-Winkler",t.Manhattan="Manhattan"}(n||(n={})),function(t){t.Euclidean="Euclidean"}(s||(s={})),function(t){t.Tanimoto="Tanimoto",t.Dice="Dice",t.Asymmetric="Asymmetric",t.BraunBlanquet="Braun-Blanquet",t.Cosine="Cosine",t.Kulczynski="Kulczynski",t.McConnaughey="Mc-Connaughey",t.RogotGoldberg="Rogot-Goldberg",t.Russel="Russel",t.Sokal="Sokal",t.Hamming="Hamming",t.Euclidean="Euclidean"}(i||(i={})),function(t){t.Vector="Vector",t.String="String",t.BitArray="BitArray",t.MacroMolecule="MacroMolecule",t.Number="Number"}(o||(o={})),function(t){t.NumericDistance="NumericDistance"}(a||(a={}))},1729:(t,e,r)=>{var n=r(4221),s=r(7659),i=r(3659);function o(t){return Math.random()*t}function a(t){return Math.floor(o(t))}function h(t=!1,e="Assertion error."){if(!t)throw new Error(e)}function l(t,e,r=1){const n=t.length;h(n==e.length,"Vector lengths do not match.");const s=new i.OW(n);for(let n=0;n<t.length;++n)s[n]=t[n]+r*e[n];return s}function u(t,e,r=1){const n=function(t,e,r=0){return new Array(t).fill(r).map((()=>new i.OW(e).fill(r)))}(t,e);for(let s=0;s<t;++s)for(let t=0;t<e;++t)n[s][t]=o(r);return n}function c(t,e){const r=function(t){let e=0;for(let r=0;r<t.length;++r)e+=t[r];return e}(function(t){const e=t.length,r=new i.OW(e);for(let e=0;e<t.length;++e)r[e]=t[e]*t[e];return r}(l(t,e,-1)));return Math.sqrt(r)}function f(t){return(e,r)=>t*e+r-Math.floor((e+2)*(e+1)/2)}class g{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(18),r.b)))),this._terminateOnComplete=e}async calc(t,e,r=!0){return new Promise((async(n,s)=>{try{const s=t.length,i=new Array(this._workerCount),o=s*(s-1)/2;this._workerCount=Math.min(this._workerCount,o);const a=o/this._workerCount,h=new Float32Array(o);let l=0,u=1,c=0,f=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const n=Math.floor(r*a),g=r===this._workerCount-1?o:Math.floor((r+1)*a),m=l,d=u;r!==this._workerCount-1&&(l=s-2-Math.floor(Math.sqrt(-8*g+4*s*(s-1)-7)/2-.5),u=g-s*l+Math.floor((l+1)*(l+2)/2)),this._workers[r].postMessage({values:t,fnName:e,startRow:m,startCol:d,chunckSize:g-n}),i[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:s,distanceMatrixData:i,min:o,max:a}})=>{this._terminateOnComplete&&this._workers[r].terminate(),s?e(s):(h.set(i,n),o<c&&(c=o),a>f&&(f=a),t())}}))}await Promise.all(i),r&&h.forEach(((t,e)=>{h[e]=(t-c)/(f-c)})),n(h)}catch(t){s(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}class m{constructor(t){this.steps=t?.steps??0,this.cycles=t?.cycles??1e6,this.cutoff=t?.cutoff??0,this.lambda=t?.lambda??2,this.dlambda=t?.dlambda??.01,this.lambda2=this.lambda/2,this.dlambda2=this.dlambda/2,this.epsilon=t?.epsilon??1e-10,this.distanceFunction=t?.distance??c,this.distance=new Float32Array,this.distanceFunctionName=t?.distanceFunctionName}async initDistance(t){this.dmIndexFunct=f(t.length);const e=new g(!0,!1);this.distance=await e.calc(t,this.distanceFunctionName),e.terminate()}calcDistance(t,e,r){return this.distance[this.dmIndexFunct(e,r)]}async embed(t){const e=t.length,r=u(e,m.dimension,40);let n=this.lambda2;0===this.steps&&(this.steps=t.length-1),await this.initDistance(t);for(let s=0;s<this.cycles;++s){for(let s=0;s<this.steps;++s){const s=a(e);let i=a(e);for(;s==i;)i=a(e);const o=r[s],h=r[i],u=this.calcDistance(t,s,i),f=c(o,h);if(0==this.cutoff||u<=this.cutoff||f<u){const t=n*(u-f)/(f+this.epsilon),e=l(o,h,-1);r[s]=l(o,e,t),r[i]=l(h,e,-t)}}if(n-=this.dlambda2,n<=0)break}return r}}m.dimension=2;class d extends m{async embed(t){const e=t.length,r=u(e,d.dimension,40);let n=this.lambda;await this.initDistance(t);for(let s=0;s<this.cycles;++s){const s=a(e),i=r[s];for(let o=0;o<e;++o){if(s==o)continue;const e=r[o],a=this.calcDistance(t,s,o),h=c(i,e);if(0==this.cutoff||a<=this.cutoff||h<a){const t=n*(a-h)/(h+this.epsilon),s=l(i,e,-1);r[o]=l(e,s,-t)}}if(n-=this.dlambda,n<=0)break}return r}}class p extends m{constructor(t){super(t),this.cycles=t?.cycles??1e3,this.steps=t?.steps??1e5,this.radiusPercent=t?.radiusPercent??1,this.maxDistance=t?.maxDistance??null,this.maxDistanceSteps=t?.maxDistanceSteps??null}async embed(t){const e=t.length,r=u(e,p.dimension,40);if(await this.initDistance(t),null===this.maxDistanceSteps&&(this.maxDistanceSteps=e*Math.floor((e-1)/2)),null===this.maxDistance){this.maxDistance=-1e37;for(let r=0;r<this.maxDistanceSteps;r++){const r=a(e);let n=a(e);for(;r==n;)n=a(e);const s=this.calcDistance(t,r,n);s>this.maxDistance&&(this.maxDistance=s)}}let n=this.lambda;const s=0==this.radiusPercent?this.maxDistance:this.maxDistance*this.radiusPercent;for(let i=0;i<this.cycles;++i){for(let i=0;i<this.steps;++i){const i=a(e);let o=a(e);for(;i==o;)o=a(e);const h=r[i],u=r[o],f=this.calcDistance(t,i,o),g=c(h,u);if(f<=s||g<f){const t=.5*n*(f-g)/(g+this.epsilon),e=l(h,u,-1);r[i]=l(h,e,t),r[o]=l(u,e,-t)}}if(n-=(this.lambda-this.dlambda)/(this.cycles-1),n<this.dlambda)break}return r}}var w=r(1811),y=r(3979),v=r(5697),b=r(489),M=r(1040);const _={[M.CF.Euclidean]:c},x={[M.W.Levenshtein]:w.T,[M.W.JaroWinkler]:y.H$,[M.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={[M.gk.Tanimoto]:v.KR,[M.gk.Dice]:v._h,[M.gk.Asymmetric]:v.yU,[M.gk.BraunBlanquet]:v.Dz,[M.gk.Cosine]:v.Zd,[M.gk.Kulczynski]:v.s,[M.gk.McConnaughey]:v.aW,[M.gk.RogotGoldberg]:v.MI,[M.gk.Russel]:v.fX,[M.gk.Sokal]:v.NB,[M.gk.Hamming]:v.UX,[M.gk.Euclidean]:v.WI},E={[M.Yc.NumericDistance]:v.bX},k={[M.Qe.Vector]:{[M.CF.Euclidean]:_[M.CF.Euclidean]},[M.Qe.String]:{[M.W.Levenshtein]:x[M.W.Levenshtein],[M.W.JaroWinkler]:x[M.W.JaroWinkler],[M.W.Manhattan]:x[M.W.Manhattan]},[M.Qe.BitArray]:{[M.gk.Tanimoto]:S[M.gk.Tanimoto],[M.gk.Dice]:S[M.gk.Dice],[M.gk.Asymmetric]:S[M.gk.Asymmetric],[M.gk.BraunBlanquet]:S[M.gk.BraunBlanquet],[M.gk.Cosine]:S[M.gk.Cosine],[M.gk.Kulczynski]:S[M.gk.Kulczynski],[M.gk.McConnaughey]:S[M.gk.McConnaughey],[M.gk.RogotGoldberg]:S[M.gk.RogotGoldberg],[M.gk.Russel]:S[M.gk.Russel],[M.gk.Sokal]:S[M.gk.Sokal]},[M.Qe.MacroMolecule]:{[b.U.HAMMING]:b.o[b.U.HAMMING],[b.U.LEVENSHTEIN]:b.o[b.U.LEVENSHTEIN],[b.U.NEEDLEMANN_WUNSCH]:b.o[b.U.NEEDLEMANN_WUNSCH]},[M.Qe.Number]:{[M.Yc.NumericDistance]:E[M.Yc.NumericDistance]}},N=Object.keys(k).reduce(((t,e)=>{for(const r of Object.keys(k[e]))t[r]=e;return t}),{});class R{constructor(t){this.method=t,this.dataType=N[t]}getMeasure(t){const e=k;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,N[r]==M.Qe.MacroMolecule.toString()?e[this.dataType][this.method](t):e[this.dataType][this.method];var r}static getMetricByDataType(t){return Object.keys(k[t])}static get availableMeasures(){return Object.keys(k)}}class I{constructor(t,e=!1){if(this._length=0,this._version=0,this._updateLevel=0,this._selectedCount=0,this._selectedCountVersion=-1,this._selectedIndexesVersion=-1,this._versionedName="",this._versionedNameVersion=-1,this.SHRINK_THRESHOLD=256,"number"==typeof t){const r=t,n=I._createBuffer(r);if(e)for(let t=0;t<n.length;t++)n[t]=-1;this._data=n,this._length=r}else{if(!(t instanceof Uint32Array))throw new Error("Invalid constructor");this._data=t,this._length=e}}getRawData(){return this._data}assureGoez(t,e){if(t<0)throw new Error(`${e} should be greater than zero`)}assureInRange(t,e,r,n){if(t<e||t>r)throw new Error(`Argument ${n} (${t}) out of range (${e}, ${r})`)}copy(t,e,r){for(let n=0;n<r;n++)e[n]=t[n]}copyFrom(t){if(this._length!=t._length)throw new Error(`Lengths differ (${this._length} != ${t._length})`);this.copy(t._data,this._data,this.lengthInInts),this._version++}get length(){return this._length}get buffer(){return this._data}set buffer(t){this._data=t,this._version++}get version(){return this._version}set version(t){this._version=t}incrementVersion(t=!0){this._version++}get lengthInInts(){return Math.floor((this._length+31)/32)}get versionedName(){return this._version==this._versionedNameVersion?this._versionedName:""}set versionedName(t){this._versionedName=t,this._versionedNameVersion=this._version}get self(){return this}setLength(t){if(t<0)throw new Error("should be >= 0");if(t==this._length)return;const e=Math.floor((t+31)/32);if(e>this._data.length||e+this.SHRINK_THRESHOLD<this._data.length){const t=new Uint32Array(e);this.copy(this._data,t,e>this._data.length?this._data.length:e),this._data=t}t>this._length&&(this._length%32>0&&(this._data[this.lengthInInts-1]&=(1<<(this._length%32&31))-1),this._data.fill(0,this.lengthInInts,e)),this._length=t,this._version++}static fromAnd(t,e){if(t._length!=e._length)throw new Error(`Lengths differ (${t._length} != ${e._length})`);const r=new I(t._length);r._length=t._length,r._data=I._createBuffer(r._length),r._version=0;const n=t.lengthInInts;for(let s=0;s<n;s++)r._data[s]=t._data[s]&e._data[s];return r}static _createBuffer(t){return new Uint32Array(Math.floor((t+31)/32))}static fromValues(t){const e=new I(t.length);e._version=0;for(let r=0;r<e._length;r++)t[r]&&(e._data[Math.floor(r/32)]|=1<<(r%32&31));return e}static fromSeq(t,e){const r=new I(t);for(let n=0;n<t;++n)r.setBit(n,e(n));return r._version=0,r}static fromString(t){return I.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const r=new I(t);return r._data=e,r}static fromBytes(t){const e=t.length,r=new I(8*e);r._data=new Uint32Array(Math.floor((e+3)/4)),r._length=8*e;let n=0,s=0;for(;e-s>=4;)r._data[n++]=255&t[s]|(255&t[s+1])<<8|(255&t[s+2])<<16|(255&t[s+3])<<24,s+=4;return e-s==3&&(r._data[n]=(255&t[s+2])<<16),e-s==2&&(r._data[n]|=(255&t[s+1])<<8),e-s==1&&(r._data[n]|=255&t[s]),r._version=0,r}toString(){return`${this._length} bits, ${this.countBits(!0)} set`}equals(t){if(this==t)return!0;if(null==t)return!1;if(this._length!=t._length)return!1;if(0==this._length)return!0;for(let e=0;e<this._data.length-1;e++)if(this._data[e]!=t._data[e])return!1;for(let e=8*(this._data.length-1);e<this._length;e++)if(this.getBit(e)!=t.getBit(e))return!1;return!0}clone(){const t=new I(0,!1);return t._data=Uint32Array.from(this._data),t._length=this._length,t._version=this._version,t}init(t,e){this.setAll(!1,!1);for(let e=0;e<this._length;e++)t(e)&&(this._data[Math.floor(e/32)]|=1<<(e%32&31));return this.incrementVersion(e),this}invert(t=!0){for(let t=0;t<this._data.length;t++)this._data[t]^=-1;this.incrementVersion(t)}setAll(t,e=!1){const r=t?-1:0,n=this.lengthInInts;for(let t=0;t<n;t++)this._data[t]=r;this.incrementVersion(e)}setIndexes(t,e=!0,r=!0,n=!0){r&&this.setAll(!e,!1);for(const r of t)this.setFast(r,e);this.incrementVersion(n)}everyIndex(t,e=!0){for(const r of t)if(this.getBit(r)!=e)return!1;return!0}anyIndex(t,e=!0){for(const r of t)if(this.getBit(r)==e)return!0;return!1}setWhere(t,e=!0,r=!0,n=!0,s=!0){if(r&&s&&this.setAll(!e,!1),s)for(let r=0;r<this._length;r++)t(r)&&this.setFast(r,e);else for(let r=0;r<this._length;r++)this.setFast(r,t(r)?e:!e);this.incrementVersion(n)}getRange(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const r=[];for(let n=t;n<e;++n)r.push(this.getBit(n));return I.fromValues(r)}getRangeAsList(t,e){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length,"to");const r=[];for(let n=t;n<e;++n)r.push(this.getBit(n));return r}setRange(t,e,r,n=!0){this.assureInRange(t,0,this._length-1,"from"),this.assureInRange(e,0,this._length-1,"to");const s=Math.min(t,e),i=Math.max(t,e);if(r)for(let t=s;t<=i;t++)this.setTrue(t);else for(let t=s;t<=i;t++)this.setFalse(t);return this.incrementVersion(n),this}setRandom(t,e,r=!0){if(t<0||t>this._length)throw new Error("n must be >= 0 && <= Count");t>this._length/2&&this.setRandom(this._length-t,!e),this.setAll(!e);for(let r=0;r<t;){const t=Math.floor(Math.random()*this._length);this.getBit(t)!=e&&(this.setFast(t,e),r++)}this.incrementVersion(r)}and(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]&=t._data[e];return this.incrementVersion(e),this}andNot(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");const r=this.lengthInInts;for(let e=0;e<r;e++)this._data[e]&=~t._data[e];return this.incrementVersion(e),this}notAnd(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]=~this._data[e]&t._data[e];return this.incrementVersion(e),this}not(t=!0){for(let t=0,e=this.lengthInInts;t<e;t++)this._data[t]=~this._data[t];return this.incrementVersion(t),this}or(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]|=t._data[e];return this.incrementVersion(e),this}xor(t,e=!0){if(this._length!=t._length)throw new Error("Array lengths differ.");for(let e=0,r=this.lengthInInts;e<r;e++)this._data[e]^=t._data[e];return this.incrementVersion(e),this}insertAt(t,e,r=!1){if(this.assureInRange(t,0,this._length,"pos"),0==e)return;const n=this._length;this.setLength(this._length+e);for(let r=n-1;r>=t;r--)this.setBit(r+e,this.getBit(r));for(let n=t;n<t+e;n++)this.setBit(n,r)}removeAt(t,e=1){if(e<0)throw new Error("n cannot be negative");if(this.assureInRange(t,0,this._length-e,"pos"),this.contains(!0))for(let r=t;r<this._length-e;r++)this.setBit(r,this.getBit(r+e));this.setLength(this._length-e)}removeByMask(t,e=!0){if(this._length!=t.length)throw new Error("length != mask.length");if(t==this)this.setLength(t.countBits(!e)),this.setAll(!e);else{let r=0;for(let n=-1;-1!=(n=t.findNext(n,!e));)this.setFast(r++,this.getBit(n));this._length=r,this._version++}return this}getBit(t){return 0!=(this._data[Math.floor(t/32)]&1<<(31&t))}setBit(t,e,r=!0){this.setFast(t,e),this._version++}setFast(t,e){e?this._data[Math.floor(t/32)]|=1<<(31&t):this._data[Math.floor(t/32)]&=~(1<<(31&t))}setTrue(t){this._data[Math.floor(t/32)]|=1<<(31&t)}setFalse(t){this._data[Math.floor(t/32)]&=~(1<<(31&t))}trueCount(){return this.countBits(!0)}falseCount(){return this.countBits(!1)}countBits(t){if(0==this._length)return 0;if(this._selectedCountVersion!=this._version){this._selectedCount=0;const t=this.lengthInInts;let e=0;for(;e<t-1;e++)for(let t=this._data[e];0!=t;t>>>=8)this._selectedCount+=I._onBitCount[255&t];let r=this._data[e];const n=31&this._length;for(0!=n&&(r&=~(4294967295<<n));0!=r;r>>>=8)this._selectedCount+=I._onBitCount[255&r];this._selectedCountVersion=this._version}return t?this._selectedCount:this._length-this._selectedCount}countWhere(t){let e=0;if(this.trueCount()==this._length)for(let r=0;r<this._length;r++)e+=t(r)?1:0;else for(let r=-1;-1!=(r=this.findNext(r,!0));)e+=t(r)?1:0;return e}andWithCountBits(t,e){if(0==this._length)return 0;let r=0;const n=this.lengthInInts;let s=0;for(;s<n-1;s++)for(let e=this._data[s]&t._data[s];0!=e;e>>>=8)r+=I._onBitCount[255&e];let i=this._data[s]&t._data[s];const o=31&this._length;for(0!=o&&(i&=~(4294967295<<o));0!=i;i>>>=8)r+=I._onBitCount[255&i];return e?r:this._length-r}clear(){this.setLength(0)}contains(t){return this.findNext(-1,t)>=0}get allTrue(){return this.countBits(!0)==this._length}get allFalse(){return this.countBits(!1)==this._length}get anyTrue(){return this.countBits(!0)>0}get anyFalse(){return this.countBits(!1)>0}findNext(t,e=!0){if(this.assureInRange(t,-1,this._length,"index"),t>=this._length-1)return-1;let r=31&(t=t<0?0:t+1);const n=this.lengthInInts;for(let s=Math.floor(t/32);s<n;s++){let n=e?this._data[s]:~this._data[s];if(0!=r)n&=4294967295<<r&4294967295,r=0;else if(!e&&-4294967296==n)continue;for(let e=0;0!=n;e+=8,n>>>=8){const r=I._firstOnBit[255&n];if(r>=0)return(t=r+32*s+e)>=this._length?-1:t}}return-1}findPrev(t,e=!0){if(0==t)return-1;this.assureInRange(t,-1,this._length,"index");let r=1+(t=t<0?this._length-1:t-1)&31;for(let n=Math.floor(t/32);n>=0;n--){let t=e?this._data[n]:~this._data[n];0!=r&&(t&=~(4294967295<<r),r=0);for(let e=24;0!=t;e-=8,t<<=8){const r=I._lastOnBit[t>>>24];if(r>=0)return r+32*n+e}}return-1}}I._onBitCount=Int8Array.from([0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8]),I._firstOnBit=Int8Array.from([-1,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0]),I._lastOnBit=Int8Array.from([-1,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7]);var z,A=r(6814);class F{get data(){return this._data}get size(){return this._size}constructor(t,e){if(null==e){if(null==t)throw new Error("Arguments error: data or size is required.");if(this._data=t,this._size=(1+Math.sqrt(1+8*this._data.length))/2,this._size!=Math.floor(this._size))throw new Error(`Invalid data length ${this._data.length} leads to non integer size ${this._size}`)}else{this._size=e;const r=e*(e-1)/2;if(t){if(t.length!=r)throw new Error(`Invalid data length. Observations size ${e} requires data length ${r}.`);this._data=t}else this._data=new Float32Array(r)}}_linearizeIJ(t,e){if(!(t<e))throw new Error("i must be less than j");return this._size*t+e-Math.floor((t+2)*(t+1)/2)}get(t,e){return t==e?0:t<e?this._data[this._linearizeIJ(t,e)]:this._data[this._linearizeIJ(e,t)]}set(t,e,r){this._data[this._linearizeIJ(t,e)]=r}static calc(t,e){const r=t.length,n=new F(void 0,r);for(let s=0;s<r;s++)for(let i=s+1;i<r;i++)n.set(s,i,(0,A.k)(t[s])||(0,A.k)(t[i])?1:e(t[s],t[i]));return n}square(){for(let t=0;t<this._data.length;t++)this._data[t]=this._data[t]**2}add(t){if(this._size!==t._size)throw new Error(`Matrices must have the same size. This size: ${this._size}, other size: ${t._size}`);for(let e=0;e<this._data.length;e++)this._data[e]+=t._data[e]}sqrt(){for(let t=0;t<this._data.length;t++)this._data[t]=Math.sqrt(this._data[t])}normalize(){let t=0,e=this._data[0];for(let r=0;r<this._data.length;r++)this._data[r]<t&&(t=this._data[r]),this._data[r]>e&&(e=this._data[r]);const r=e-t;for(let n=0;n<this._data.length;n++)this._data[n]=0===r?this._data[n]-t:(this._data[n]-t)/(e-t)}}!function(t){t.UMAP="UMAP",t.T_SNE="t-SNE"}(z||(z={}));class C{constructor(t){this.data=t.data}}const T={UMAP:class extends C{constructor(t){super(t),h("distanceFname"in t),h("distanceFn"in t),this.distanceFn=t.distanceFn,this.distanceFname=t.distanceFname,this.dmIndexFunc=f(this.data.length),this.vectors=new Array(this.data.length).fill(0).map(((t,e)=>[e])),this.usingDistanceMatrix=!(!t.preCalculateDistanceMatrix&&this.data.length>2e4),this.usingDistanceMatrix?t.distanceFn=this._encodedDistanceMatrix.bind(this):t.distanceFn=this._encodedDistance.bind(this),this.data.length<15&&(t.nNeighbors=this.data.length-1),this.reducer=new n.u(t)}_encodedDistanceMatrix(t,e){return t[0]===e[0]?0:t[0]>e[0]?this.distanceMatrix[this.dmIndexFunc(e[0],t[0])]:this.distanceMatrix[this.dmIndexFunc(t[0],e[0])]}_encodedDistance(t,e){return this.distanceFn(this.data[t[0]],this.data[e[0]])}async transform(t){this.usingDistanceMatrix&&(this.distanceMatrix=t?await(async()=>{const t=new g(!0,!1);try{const e=await t.calc(this.data,this.distanceFname);return t.terminate(),e}catch(e){throw t.terminate(),e}})():(()=>F.calc(this.data,((t,e)=>this.distanceFn(t,e))).data)());const e=this.reducer.fit(this.vectors);return{embedding:(r=e,new Array(r.length).fill(0).map(((t,e)=>i.OW.from(r[e])))),...this.distanceMatrix?{distance:this.distanceMatrix}:{}};var r}},"t-SNE":class extends C{constructor(t){super(t),this.reducer=new s.Z(t),this.iterations=t?.iterations??100,this.distanceFname=t.distanceFname,this.distanceFn=t.distanceFn}async transform(t){const e=t?await(async()=>{const t=new g(!0,!1);try{const e=await t.calc(this.data,this.distanceFname);return t.terminate(),e}catch(e){throw t.terminate(),e}})():(()=>{const t=F.calc(this.data,((t,e)=>this.distanceFn(t,e)));return t.normalize(),t.data})(),r=function(t,e){const r=f(e);function n(t,e){const n=Number(t),s=Number(e);return r(n,s)}const s={get:(t,r,s)=>"length"===r?e:new Proxy(t,function(t){return{get:(e,r,s)=>t===r?0:e[Number(t)>Number(r)?n(r,t):n(t,r)]}}(r))};return new Proxy(t,s)}(e,this.data.length);this.reducer.initDataDist(r);for(let t=0;t<this.iterations;++t)this.reducer.step();return{distance:e,embedding:this.reducer.getSolution()}}},SPE:class extends C{constructor(t){super(t),this.reducer=new m(t)}async transform(){const t=await this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}},pSPE:class extends C{constructor(t){super(t),this.reducer=new d(t)}async transform(){const t=await this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}},OriginalSPE:class extends C{constructor(t){super(t),this.reducer=new p(t)}async transform(){const t=await this.reducer.embed(this.data);return{distance:this.reducer.distance,embedding:t}}}};class P{constructor(t,e,r,n){const s=new R(r).getMeasure();let i={};if("BitArray"==N[r])for(let e=0;e<t.length;++e)t[e]=new I(t[e]._data,t[e]._length);i="UMAP"==e?{data:t,distanceFn:s,distanceFname:r,nEpochs:n?.cycles,...n}:"t-SNE"==e?{data:t,distanceFn:s,distanceFname:r,iterations:n?.cycles??void 0,...n}:{data:t,distance:s,distanceFunctionName:r,...n},this.reducer=new T[e](i)}async transform(t=!1,e){if(void 0===this.reducer)throw new Error("Reducer was not defined.");let{embedding:r,distance:n}=await this.reducer.transform(e);var s;return t&&(s=r,r=new Array(s[0].length).fill(0).map(((t,e)=>new i.OW(s.length).fill(0).map(((t,r)=>s[r][e]))))),{distance:n,embedding:r}}static availableMetricsByType(t){return Object.keys(k[t])}static get availableMethods(){return Object.keys(T)}static get availableMetrics(){let t=[];return Object.values(k).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}self.onmessage=async({data:{columnData:t,method:e,measure:r,options:n,parallelDistanceWorkers:s}})=>{let i;try{i=await async function(t,e,r,n,s){const i=new P(t,e,r,n);return await i.transform(!0,s)}(t,e,r,n,s)}catch(t){i={error:t}}self.postMessage({error:i.error,distance:i.distance,embedding:i.embedding})}},7659:(t,e,r)=>{e.Z=void 0;var n=r(6215);Object.defineProperty(e,"Z",{enumerable:!0,get:function(){return n.TSNE}})},6215:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TSNE=void 0,e.TSNE=class{constructor(t){this.returnV=!1,this.vValue=0,this.iter=0,t=t||{},this.perplexity=this.getopt(t,"perplexity",30),this.dim=this.getopt(t,"dim",2),this.epsilon=this.getopt(t,"epsilon",10)}assert(t,e){if(!t)throw e||"Assertion failed"}getopt(t,e,r){return t.hasOwnProperty(e)?t[e]:r}gaussRandom(){if(this.returnV)return this.returnV=!1,this.vValue;const t=2*Math.random()-1,e=2*Math.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[];if("undefined"==typeof ArrayBuffer){const e=new Array(t);for(let r=0;r<t;r++)e[r]=0;return e}return new Float64Array(t)}randn2d(t,e,r){const n=void 0!==r,s=[];for(let i=0;i<t;i++){const t=[];for(let s=0;s<e;s++)n?t.push(r):t.push(this.randn(0,1e-4));s.push(t)}return s}L2(t,e){const r=t.length;let n=0;for(let s=0;s<r;s++){const r=t[s],i=e[s];n+=(r-i)*(r-i)}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 i=this.L2(t[n],t[s]);r[n*e+s]=i,r[s*e+n]=i}return r}d2p(t,e,r){const n=Math.sqrt(t.length),s=Math.floor(n);this.assert(s===n,"D should have square number of elements.");const i=Math.log(e),o=this.zeros(s*s),a=this.zeros(s);for(let e=0;e<s;e++){let n=-1/0,h=1/0,l=1,u=!1;const c=50;let f=0;for(;!u;){let o=0;for(let r=0;r<s;r++){let n=Math.exp(-t[e*s+r]*l);e===r&&(n=0),a[r]=n,o+=n}let g=0;for(let t=0;t<s;t++){let e;e=0===o?0:a[t]/o,a[t]=e,e>1e-7&&(g-=e*Math.log(e))}g>i?(n=l,h===1/0?l*=2:l=(l+h)/2):(h=l,n===-1/0?l/=2:l=(l+n)/2),f++,Math.abs(g-i)<r&&(u=!0),f>=c&&(u=!0)}for(let t=0;t<s;t++)o[e*s+t]=a[t]}const h=this.zeros(s*s),l=2*s;for(let t=0;t<s;t++)for(let e=0;e<s;e++)h[t*s+e]=Math.max((o[t*s+e]+o[e*s+t])/l,1e-100);return h}sign(t){return t>0?1:t<0?-1:0}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),this.N=e,this.initSolution()}initDataDist(t){const e=t.length;this.assert(e>0," X is empty? You must have some data!");const r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const i=t[n][s];r[n*e+s]=i,r[s*e+n]=i}this.P=this.d2p(r,this.perplexity,1e-4),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],i=this.ystep[e][t],o=this.gains[e][t];let a=this.sign(r)===this.sign(i)?.8*o:o+.2;a<.01&&(a=.01),this.gains[e][t]=a;const h=(this.iter<250?.5:.8)*i-this.epsilon*a*n[e][t];this.ystep[e][t]=h,this.Y[e][t]+=h,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),r=(e.cost,e.grad),n=1e-5;for(let e=0;e<t;e++)for(let t=0;t<this.dim;t++){const s=this.Y[e][t];this.Y[e][t]=s+n;const i=this.costGrad(this.Y);this.Y[e][t]=s-n;const o=this.costGrad(this.Y),a=r[e][t],h=(i.cost-o.cost)/(2*n);console.log(e+","+t+": gradcheck analytic: "+a+" vs. numerical: "+h),this.Y[e][t]=s}}costGrad(t){const e=this.N,r=this.dim,n=this.P,s=this.iter<100?4:1,i=this.zeros(e*e);let o=0;for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){let a=0;for(let e=0;e<r;e++){const r=t[n][e]-t[s][e];a+=r*r}const h=1/(1+a);i[n*e+s]=h,i[s*e+n]=h,o+=2*h}const a=e*e,h=this.zeros(a);for(let t=0;t<a;t++)h[t]=Math.max(i[t]/o,1e-100);let l=0;const u=[];for(let o=0;o<e;o++){const a=new Array(r);for(let t=0;t<r;t++)a[t]=0;for(let u=0;u<e;u++){l+=-n[o*e+u]*Math.log(h[o*e+u]);const c=4*(s*n[o*e+u]-h[o*e+u])*i[o*e+u];for(let e=0;e<r;e++)a[e]+=c*(t[o][e]-t[u][e])}u.push(a)}return{cost:l,grad:u}}}},9251:(t,e,r)=>{r.r(e),r.d(e,{default:()=>P});const n=Object.prototype.toString;function s(t){return n.call(t).endsWith("Array]")}function i(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 o=Object.prototype.toString;function a(t){return o.call(t).endsWith("Array]")}const h=Object.prototype.toString;function l(t){return h.call(t).endsWith("Array]")}const u=Object.prototype.toString;const c=Object.prototype.toString;function f(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!l(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(!l(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,!c.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,i=r.toIndex,o=void 0===i?t.length:i;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(o<=s||o>t.length||!Number.isInteger(o))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=t[s],h=s+1;h<o;h++)t[h]<a&&(a=t[h]);return a}(t),s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!u.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,i=r.toIndex,o=void 0===i?t.length:i;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(o<=s||o>t.length||!Number.isInteger(o))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var a=t[s],h=s+1;h<o;h++)t[h]>a&&(a=t[h]);return a}(t);if(n===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,o=void 0===i?r.autoMinMax?n:0:i,a=r.max,h=void 0===a?r.autoMinMax?s:1:a;if(o>=h)throw new RangeError("min option must be smaller than max option");for(var f=(h-o)/(s-n),g=0;g<t.length;g++)e[g]=(t[g]-n)*f+o;return e}const g=" ".repeat(2),m=" ".repeat(4);function d(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:s=8,padMinus:i="auto"}=e;return`${t.constructor.name} {\n${g}[\n${m}${function(t,e,r,n,s){const{rows:i,columns:o}=t,a=Math.min(i,e),h=Math.min(o,r),l=[];if("auto"===s){s=!1;t:for(let e=0;e<a;e++)for(let r=0;r<h;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<a;e++){let r=[];for(let i=0;i<h;i++)r.push(p(t.get(e,i),n,s));l.push(`${r.join(" ")}`)}return h!==o&&(l[l.length-1]+=` ... ${o-r} more columns`),a!==i&&l.push(`... ${i-e} more rows`),l.join(`\n${m}`)}(t,r,n,s,i)}\n${g}]\n${g}rows: ${t.rows}\n${g}columns: ${t.columns}\n}`}function p(t,e,r){return(t>=0&&r?` ${w(t,e-1)}`:w(t,e)).padEnd(e)}function w(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 y(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 v(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 b(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function M(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function _(t,e,r,n,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(S("startRow",e),S("endRow",r),S("startColumn",n),S("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 x(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function S(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function E(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class k{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new R(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 R(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 R(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 R(t,e)}static ones(t,e){return new R(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 R(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:i=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 o=s-n,a=new R(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(i()*o);a.set(r,t,e)}return a}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),i=this.zeros(e,r);for(let e=0;e<s;e++)i.set(e,e,t[e]);return i}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new R(r,n);for(let i=0;i<r;i++)for(let r=0;r<n;r++)s.set(i,r,Math.min(t.get(i,r),e.get(i,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 i=0;i<r;i++)for(let r=0;r<n;r++)s.set(i,r,Math.max(t.get(i,r),e.get(i,r)));return s}static checkMatrix(t){return k.isMatrix(t)?t:new R(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 i=r+1;i<t.columns;i++)t.set(n,i,t.get(n,i)-t.get(e,i)*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,i=!1;for(;s<r&&!1===i;)1===t.get(n,s)?i=!0:s++;for(let r=0;r<n;r++){let i=t.get(r,s);for(let o=s;o<e;o++){let e=t.get(r,o)-i*t.get(n,o);t.set(r,o,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 R(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){y(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return R.rowVector(this.getRow(t))}setRow(t,e){y(this,t),e=b(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){y(this,t),y(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){v(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return R.columnVector(this.getColumn(t))}setColumn(t,e){v(this,t),e=M(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){v(this,t),v(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=b(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=b(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=b(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=b(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=M(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){y(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){v(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(){E(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(){E(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(y(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){y(this,t),E(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(y(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){y(this,t),E(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(v(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){v(this,t),E(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(v(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){v(this,t),E(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){k.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=R.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new R(e,n),i=new Float64Array(r);for(let o=0;o<n;o++){for(let e=0;e<r;e++)i[e]=t.get(e,o);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*i[n];s.set(t,o,e)}}return s}strassen2x2(t){t=R.checkMatrix(t);let e=new R(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),i=t.get(0,1),o=this.get(1,0),a=t.get(1,0),h=this.get(1,1),l=t.get(1,1),u=(r+h)*(n+l),c=(o+h)*n,f=r*(i-l),g=h*(a-n),m=(r+s)*l,d=u+g-m+(s-h)*(a+l),p=f+m,w=c+g,y=u-c+f+(o-r)*(n+i);return e.set(0,0,d),e.set(0,1,p),e.set(1,0,w),e.set(1,1,y),e}strassen3x3(t){t=R.checkMatrix(t);let e=new R(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),i=this.get(1,0),o=this.get(1,1),a=this.get(1,2),h=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),d=t.get(1,1),p=t.get(1,2),w=t.get(2,0),y=t.get(2,1),v=t.get(2,2),b=(r-i)*(-f+d),M=(-r+i+o)*(c-f+d),_=(i+o)*(-c+f),x=r*c,S=(-r+h+l)*(c-g+p),E=(-r+h)*(g-p),k=(h+l)*(-c+g),N=(-s+l+u)*(d+w-y),I=(s-u)*(d-y),z=s*w,A=(l+u)*(-w+y),F=(-s+o+a)*(p+w-v),C=(s-a)*(p-v),T=(o+a)*(-w+v),P=x+z+n*m,D=(r+n+s-i-o-l-u)*d+M+_+x+N+z+A,V=x+S+k+(r+n+s-o-a-h-l)*p+z+F+T,O=b+o*(-c+f+m-d-p-w+v)+M+x+z+F+C,j=b+M+_+x+a*y,B=z+F+C+T+i*g,q=x+S+E+l*(-c+g+m-d-p-w+y)+N+I+z,L=N+I+z+A+h*f,$=x+S+E+k+u*v;return e.set(0,0,P),e.set(0,1,D),e.set(0,2,V),e.set(1,0,O),e.set(1,1,j),e.set(1,2,B),e.set(2,0,q),e.set(2,1,L),e.set(2,2,$),e}mmulStrassen(t){t=R.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,i=t.columns;function o(t,e,r){let n=t.rows,s=t.columns;if(n===e&&s===r)return t;{let n=k.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${i} matrix: dimensions do not match.`);let a=Math.max(r,s),h=Math.max(n,i);return e=o(e,a,h),function t(e,r,n,s){if(n<=512||s<=512)return e.mmul(r);n%2==1&&s%2==1?(e=o(e,n+1,s+1),r=o(r,n+1,s+1)):n%2==1?(e=o(e,n+1,s),r=o(r,n+1,s)):s%2==1&&(e=o(e,n,s+1),r=o(r,n,s+1));let i=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),h=e.subMatrix(0,i-1,0,a-1),l=r.subMatrix(0,i-1,0,a-1),u=e.subMatrix(0,i-1,a,e.columns-1),c=r.subMatrix(0,i-1,a,r.columns-1),f=e.subMatrix(i,e.rows-1,0,a-1),g=r.subMatrix(i,r.rows-1,0,a-1),m=e.subMatrix(i,e.rows-1,a,e.columns-1),d=r.subMatrix(i,r.rows-1,a,r.columns-1),p=t(k.add(h,m),k.add(l,d),i,a),w=t(k.add(f,m),l,i,a),y=t(h,k.sub(c,d),i,a),v=t(m,k.sub(g,l),i,a),b=t(k.add(h,u),d,i,a),M=t(k.sub(f,h),k.add(l,c),i,a),_=t(k.sub(u,m),k.add(g,d),i,a),x=k.add(p,v);x.sub(b),x.add(_);let S=k.add(y,b),E=k.add(w,v),N=k.sub(p,w);N.add(y),N.add(M);let R=k.zeros(2*x.rows,2*x.columns);return R=R.setSubMatrix(x,0,0),R=R.setSubMatrix(S,x.rows,0),R=R.setSubMatrix(E,0,x.columns),R=R.setSubMatrix(N,x.rows,x.columns),R.subMatrix(0,n-1,0,s-1)}(e,t=o(t,a,h),a,h)}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 R(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&f(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 R(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&f(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=R.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,i=new R(e*n,r*s);for(let o=0;o<e;o++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<s;a++)i.set(n*o+r,s*e+a,this.get(o,e)*t.get(r,a));return i}kroneckerSum(t){if(t=R.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(R.eye(r,r)),s=R.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new R(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=N){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=N){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){_(this,t,e,r,n);let s=new R(e-t+1,n-r+1);for(let i=t;i<=e;i++)for(let e=r;e<=n;e++)s.set(i-t,e-r,this.get(i,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 R(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let i=e;i<=r;i++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,i-e,this.get(t[s],i))}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 R(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let i=e;i<=r;i++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(i-e,s,this.get(i,t[s]))}return n}setSubMatrix(t,e,r){if((t=R.checkMatrix(t)).isEmpty())return this;_(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(!a(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(!a(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 R(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 i=e[t];r.set(n,t,this.get(s,i))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new R(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=x(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=x(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=x(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=x(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(!a(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,i=[];for(let o=0;o<n;o++){let n=0,a=0,h=0;for(let e=0;e<s;e++)h=t.get(o,e)-r[o],n+=h,a+=h*h;e?i.push((a-n*n/s)/(s-1)):i.push((a-n*n/s)/s)}return i}(this,r,n);case"column":if(!a(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,i=[];for(let o=0;o<s;o++){let s=0,a=0,h=0;for(let e=0;e<n;e++)h=t.get(e,o)-r[o],s+=h,a+=h*h;e?i.push((a-s*s/n)/(n-1)):i.push((a-s*s/n)/n)}return i}(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,i=n*s;let o=0,a=0,h=0;for(let e=0;e<n;e++)for(let n=0;n<s;n++)h=t.get(e,n)-r,o+=h,a+=h*h;return e?(a-o*o/i)/(i-1):(a-o*o/i)/i}(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(!a(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(!a(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(!a(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(!a(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 d(this,t)}}function N(t,e){return t-e}k.prototype.klass="Matrix","undefined"!=typeof Symbol&&(k.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return d(this)}),k.random=k.rand,k.randomInt=k.randInt,k.diagonal=k.diag,k.prototype.diagonal=k.prototype.diag,k.identity=k.eye,k.prototype.negate=k.prototype.neg,k.prototype.tensorProduct=k.prototype.kroneckerProduct;class R extends k{constructor(t,e){if(super(),R.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(!a(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 y(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),y(this,t,!0),e=Float64Array.from(b(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){v(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),v(this,t,!0),e=M(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}}(k,R);class I extends k{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 z{constructor(t){let e,r,n,s,i,o,a,h,l,u=(t=I.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(h=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)h[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),i=0,n=0;n<l;n++)i+=u.get(e,n)*h[n];h[e]-=i,u.set(e,r,h[e])}for(s=r,e=r+1;e<c;e++)Math.abs(h[e])>Math.abs(h[s])&&(s=e);if(s!==r){for(n=0;n<f;n++)o=u.get(s,n),u.set(s,n,u.get(r,n)),u.set(r,n,o);a=g[s],g[s]=g[r],g[r]=a,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=R.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,i=t.columns,o=t.subMatrixRow(this.pivotVector,0,i-1),a=e.columns;for(s=0;s<a;s++)for(r=s+1;r<a;r++)for(n=0;n<i;n++)o.set(r,n,o.get(r,n)-o.get(s,n)*e.get(r,s));for(s=a-1;s>=0;s--){for(n=0;n<i;n++)o.set(s,n,o.get(s,n)/e.get(s,s));for(r=0;r<s;r++)for(n=0;n<i;n++)o.set(r,n,o.get(r,n)-o.get(s,n)*e.get(r,s))}return o}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 R(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 R(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 A(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 F{constructor(t){let e,r,n,s,i=(t=I.checkMatrix(t)).clone(),o=t.rows,a=t.columns,h=new Float64Array(a);for(n=0;n<a;n++){let t=0;for(e=n;e<o;e++)t=A(t,i.get(e,n));if(0!==t){for(i.get(n,n)<0&&(t=-t),e=n;e<o;e++)i.set(e,n,i.get(e,n)/t);for(i.set(n,n,i.get(n,n)+1),r=n+1;r<a;r++){for(s=0,e=n;e<o;e++)s+=i.get(e,n)*i.get(e,r);for(s=-s/i.get(n,n),e=n;e<o;e++)i.set(e,r,i.get(e,r)+s*i.get(e,n))}}h[n]=-t}this.QR=i,this.Rdiag=h}solve(t){t=R.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,i,o,a=t.columns,h=t.clone(),l=e.columns;for(i=0;i<l;i++)for(s=0;s<a;s++){for(o=0,n=i;n<r;n++)o+=e.get(n,i)*h.get(n,s);for(o=-o/e.get(i,i),n=i;n<r;n++)h.set(n,s,h.get(n,s)+o*e.get(n,i))}for(i=l-1;i>=0;i--){for(s=0;s<a;s++)h.set(i,s,h.get(i,s)/this.Rdiag[i]);for(n=0;n<i;n++)for(s=0;s<a;s++)h.set(n,s,h.get(n,s)-h.get(i,s)*e.get(n,i))}return h.subMatrix(0,l-1,0,a-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 R(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,i=s.rows,o=s.columns,a=new R(i,o);for(r=o-1;r>=0;r--){for(t=0;t<i;t++)a.set(t,r,0);for(a.set(r,r,1),e=r;e<o;e++)if(0!==s.get(r,r)){for(n=0,t=r;t<i;t++)n+=s.get(t,r)*a.get(t,e);for(n=-n/s.get(r,r),t=r;t<i;t++)a.set(t,e,a.get(t,e)+n*s.get(t,r))}}return a}}class C{constructor(t,e={}){if((t=I.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:i=!0,autoTranspose:o=!1}=e;let a,h=Boolean(s),l=Boolean(i),u=!1;if(r<n)if(o){a=t.transpose(),r=a.rows,n=a.columns,u=!0;let e=h;h=l,l=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new R(r,c),d=new R(n,n),p=new Float64Array(n),w=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),M=Math.max(v,b);for(let t=0;t<M;t++){if(t<v){g[t]=0;for(let e=t;e<r;e++)g[t]=A(g[t],a.get(e,t));if(0!==g[t]){a.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/g[t]);a.set(t,t,a.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==g[t]){let n=0;for(let s=t;s<r;s++)n+=a.get(s,t)*a.get(s,e);n=-n/a.get(t,t);for(let s=t;s<r;s++)a.set(s,e,a.get(s,e)+n*a.get(s,t))}p[e]=a.get(t,e)}if(h&&t<v)for(let e=t;e<r;e++)m.set(e,t,a.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<n;e++)p[t]=A(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++)w[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)w[e]+=p[r]*a.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++)a.set(s,e,a.get(s,e)+n*w[s])}}if(l)for(let e=t+1;e<n;e++)d.set(e,t,p[e])}}let _=Math.min(n,r+1);if(v<n&&(g[v]=a.get(v,v)),r<_&&(g[_-1]=0),b+1<_&&(p[b]=a.get(b,_-1)),p[_-1]=0,h){for(let t=v;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=v-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<b&&0!==p[t])for(let e=t+1;e<n;e++){let r=0;for(let s=t+1;s<n;s++)r+=d.get(s,t)*d.get(s,e);r=-r/d.get(t+1,t);for(let s=t+1;s<n;s++)d.set(s,e,d.get(s,e)+r*d.get(s,t))}for(let e=0;e<n;e++)d.set(e,t,0);d.set(t,t,1)}let x=_-1,S=0,E=Number.EPSILON;for(;_>0;){let t,e;for(t=_-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+E*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===_-2)e=4;else{let r;for(r=_-1;r>=t&&r!==t;r--){let e=(r!==_?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(g[r])<=E*e){g[r]=0;break}}r===t?e=3:r===_-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[_-2];p[_-2]=0;for(let r=_-2;r>=t;r--){let s=A(g[r],e),i=g[r]/s,o=e/s;if(g[r]=s,r!==t&&(e=-o*p[r-1],p[r-1]=i*p[r-1]),l)for(let t=0;t<n;t++)s=i*d.get(t,r)+o*d.get(t,_-1),d.set(t,_-1,-o*d.get(t,r)+i*d.get(t,_-1)),d.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let n=t;n<_;n++){let s=A(g[n],e),i=g[n]/s,o=e/s;if(g[n]=s,e=-o*p[n],p[n]=i*p[n],h)for(let e=0;e<r;e++)s=i*m.get(e,n)+o*m.get(e,t-1),m.set(e,t-1,-o*m.get(e,n)+i*m.get(e,t-1)),m.set(e,n,s)}break}case 3:{const e=Math.max(Math.abs(g[_-1]),Math.abs(g[_-2]),Math.abs(p[_-2]),Math.abs(g[t]),Math.abs(p[t])),s=g[_-1]/e,i=g[_-2]/e,o=p[_-2]/e,a=g[t]/e,u=p[t]/e,c=((i+s)*(i-s)+o*o)/2,f=s*o*(s*o);let w=0;0===c&&0===f||(w=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),w=f/(c+w));let y=(a+s)*(a-s)+w,v=a*u;for(let e=t;e<_-1;e++){let s=A(y,v);0===s&&(s=Number.MIN_VALUE);let i=y/s,o=v/s;if(e!==t&&(p[e-1]=s),y=i*g[e]+o*p[e],p[e]=i*p[e]-o*g[e],v=o*g[e+1],g[e+1]=i*g[e+1],l)for(let t=0;t<n;t++)s=i*d.get(t,e)+o*d.get(t,e+1),d.set(t,e+1,-o*d.get(t,e)+i*d.get(t,e+1)),d.set(t,e,s);if(s=A(y,v),0===s&&(s=Number.MIN_VALUE),i=y/s,o=v/s,g[e]=s,y=i*p[e]+o*g[e+1],g[e+1]=-o*p[e]+i*g[e+1],v=o*p[e+1],p[e+1]=i*p[e+1],h&&e<r-1)for(let t=0;t<r;t++)s=i*m.get(t,e)+o*m.get(t,e+1),m.set(t,e+1,-o*m.get(t,e)+i*m.get(t,e+1)),m.set(t,e,s)}p[_-2]=y,S+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=x;e++)d.set(e,t,-d.get(e,t));for(;t<x&&!(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=d.get(r,t+1),d.set(r,t+1,d.get(r,t)),d.set(r,t,e);if(h&&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++}S=0,_--}}if(u){let t=d;d=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=d}solve(t){let e=t,r=this.threshold,n=this.s.length,s=R.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 i=this.U,o=this.rightSingularVectors,a=o.mmul(s),h=o.rows,l=i.rows,u=R.zeros(h,l);for(let t=0;t<h;t++)for(let e=0;e<l;e++){let r=0;for(let s=0;s<n;s++)r+=a.get(t,s)*i.get(e,s);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(R.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new R(r,this.s.length);for(let i=0;i<r;i++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&s.set(i,r,t.get(i,r)/this.s[r]);let i=this.U,o=i.rows,a=i.columns,h=new R(r,o);for(let t=0;t<r;t++)for(let e=0;e<o;e++){let r=0;for(let n=0;n<a;n++)r+=s.get(t,n)*i.get(e,n);h.set(t,e,r)}return h}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 R.diag(this.s)}}function T(t,e,r,n,s){let i=r*n*n,o=R.eye(e.length,e.length,i);const a=s(e);let h=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)h[e]=a(t.x[e]);let l=function(t,e,r,n,s){const i=r.length,o=t.x.length;let a=new Array(i);for(let h=0;h<i;h++){a[h]=new Array(o);let i=r.slice();i[h]+=n;let l=s(i);for(let r=0;r<o;r++)a[h][r]=e[r]-l(t.x[r])}return new R(a)}(t,h,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 R(n)}(t,h),c=function(t,e=!1){return t=I.checkMatrix(t),e?new C(t).inverse():function(t,e,r=!1){return t=I.checkMatrix(t),e=I.checkMatrix(e),r?new C(t).solve(e):t.isSquare()?new z(t).solve(e):new F(t).solve(e)}(t,R.eye(t.rows))}(o.add(l.mmul(l.transpose())));return(e=(e=new R([e])).sub(c.mmul(l).mmul(u).mul(n).transpose())).to1DArray()}function P(t,e,r={}){let{maxIterations:n=100,gradientDifference:o=.1,damping:a=0,errorTolerance:h=.01,minValues:l,maxValues:u,initialValues:c}=r;if(a<=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(!s(t.x)||t.x.length<2||!s(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 f=c||new Array(e.length).fill(1),g=f.length;if(u=u||new Array(g).fill(Number.MAX_SAFE_INTEGER),l=l||new Array(g).fill(Number.MIN_SAFE_INTEGER),u.length!==l.length)throw new Error("minValues and maxValues must be the same size");if(!s(f))throw new Error("initialValues must be an array");let m,d=i(t,f,e),p=d<=h;for(m=0;m<n&&!p;m++){f=T(t,f,a,o,e);for(let t=0;t<g;t++)f[t]=Math.min(Math.max(l[t],f[t]),u[t]);if(d=i(t,f,e),isNaN(d))break;p=d<=h}return{parameterValues:f,parameterError:d,iterations:m}}},9378:function(t,e,r){var n=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var s=n(r(4517));function i(t,e){var r=function(r){return s.empty(t).map((function(){return s.filled(e,r)}))},n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function o(t,e,r,n,s){e=Math.floor(e);var i=t[0][e],o=t[1][e];if(t[2][e],r>=o[0])return 0;for(var h=0;h<i.length;h++)if(n===i[h])return 0;return a(t,e,r,n,s)}function a(t,e,r,n,s){var i=t[0][e],o=t[1][e],a=t[2][e];if(r>=o[0])return 0;o[0]=r,i[0]=n,a[0]=s;for(var h=0,l=0;;){var u=2*h+1,c=u+1,f=t[0][0].length;if(u>=f)break;if(c>=f){if(!(o[u]>r))break;l=u}else if(o[u]>=o[c]){if(!(r<o[u]))break;l=u}else{if(!(r<o[c]))break;l=c}o[h]=o[l],i[h]=i[l],a[h]=a[l],h=l}return o[h]=r,i[h]=n,a[h]=s,1}function h(t,e,r,n){for(;2*n+1<r;){var s=2*n+1,i=s+1,o=n;if(t[o]<t[s]&&(o=s),i<r&&t[o]<t[i]&&(o=i),o===n)break;var a=t[n];t[n]=t[o],t[o]=a;var h=e[n];e[n]=e[o],e[o]=h,n=o}}e.makeHeap=i,e.rejectionSample=function(t,e,r){for(var n=s.zeros(t),i=0;i<t;i++){for(var o=!0,a=0;o;){a=s.tauRandInt(e,r);for(var h=!1,l=0;l<i;l++)if(a===n[l]){h=!0;break}h||(o=!1)}n[i]=a}return n},e.heapPush=o,e.uncheckedHeapPush=a,e.buildCandidates=function(t,e,r,n,a){for(var h=i(e,n),l=0;l<e;l++)for(var u=0;u<r;u++)if(!(t[0][l][u]<0)){var c=t[0][l][u],f=t[2][l][u],g=s.tauRand(a);o(h,l,g,c,f),o(h,c,g,l,f),t[2][l][u]=0}return h},e.deheapSort=function(t){for(var e=t[0],r=t[1],n=0;n<e.length;n++)for(var s=e[n],i=r[n],o=0;o<s.length-1;o++){var a=s.length-o-1,l=i.length-o-1,u=s[0];s[0]=s[a],s[a]=u;var c=i[0];i[0]=i[l],i[l]=c,h(i,s,l,0)}return{indices:e,weights:r}},e.smallestFlagged=function(t,e){for(var r=t[0][e],n=t[1][e],s=t[2][e],i=1/0,o=-1,a=0;a>r.length;a++)1===s[a]&&n[a]<i&&(i=n[a],o=a);return o>=0?(s[o]=0,Math.floor(r[o])):-1}},4221:(t,e,r)=>{var n=r(4364);e.u=n.UMAP},5686:function(t,e,r){var n,s=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var a=o(r(4517)),h=function(){function t(t,e,r,n){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(var s=0;s<r.length;s++){var i=t[s],o=e[s];this.checkDims(i,o);var a=this.makeKey(i,o);this.entries.set(a,{value:r[s],row:i,col:o})}}return t.prototype.makeKey=function(t,e){return t+":"+e},t.prototype.checkDims=function(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")},t.prototype.set=function(t,e,r){this.checkDims(t,e);var 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})},t.prototype.get=function(t,e,r){void 0===r&&(r=0),this.checkDims(t,e);var n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).value:r},t.prototype.getAll=function(t){void 0===t&&(t=!0);var e=[];return this.entries.forEach((function(t){e.push(t)})),t&&e.sort((function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row})),e},t.prototype.getDims=function(){return[this.nRows,this.nCols]},t.prototype.getRows=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].row}))},t.prototype.getCols=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].col}))},t.prototype.getValues=function(){return Array.from(this.entries,(function(t){var e=s(t,2);return e[0],e[1].value}))},t.prototype.forEach=function(t){this.entries.forEach((function(e){return t(e.value,e.row,e.col)}))},t.prototype.map=function(e){var r=[];this.entries.forEach((function(t){r.push(e(t.value,t.row,t.col))}));var n=[this.nRows,this.nCols];return new t(this.getRows(),this.getCols(),r,n)},t.prototype.toArray=function(){var t=this,e=a.empty(this.nRows).map((function(){return a.zeros(t.nCols)}));return this.entries.forEach((function(t){e[t.row][t.col]=t.value})),e},t}();e.SparseMatrix=h,e.transpose=function(t){var e=[],r=[],n=[];t.forEach((function(t,s,i){e.push(s),r.push(i),n.push(t)}));var s=[t.nCols,t.nRows];return new h(r,e,n,s)},e.identity=function(t){for(var e=s(t,1)[0],r=new h([],[],[],t),n=0;n<e;n++)r.set(n,n,1);return r},e.pairwiseMultiply=function(t,e){return u(t,e,(function(t,e){return t*e}))},e.add=function(t,e){return u(t,e,(function(t,e){return t+e}))},e.subtract=function(t,e){return u(t,e,(function(t,e){return t-e}))},e.maximum=function(t,e){return u(t,e,(function(t,e){return t>e?t:e}))},e.multiplyScalar=function(t,e){return t.map((function(t){return t*e}))},e.eliminateZeros=function(t){for(var e=new Set,r=t.getValues(),n=t.getRows(),s=t.getCols(),i=0;i<r.length;i++)0===r[i]&&e.add(i);var o=function(t,r){return!e.has(r)},a=r.filter(o),l=n.filter(o),u=s.filter(o);return new h(l,u,a,t.getDims())},e.normalize=function(t,e){var r,n;void 0===e&&(e="l2");var s=l[e],o=new Map;t.forEach((function(t,e,r){var n=o.get(e)||[];n.push(r),o.set(e,n)}));var a=new h([],[],[],t.getDims()),u=function(e){for(var r=o.get(e).sort(),n=r.map((function(r){return t.get(e,r)})),i=s(n),h=0;h<i.length;h++)a.set(e,r[h],i[h])};try{for(var c=i(o.keys()),f=c.next();!f.done;f=c.next())u(f.value)}catch(t){r={error:t}}finally{try{f&&!f.done&&(n=c.return)&&n.call(c)}finally{if(r)throw r.error}}return a};var l=((n={}).max=function(t){for(var e=-1/0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map((function(t){return t/e}))},n.l1=function(t){for(var e=0,r=0;r<t.length;r++)e+=t[r];return t.map((function(t){return t/e}))},n.l2=function(t){for(var e=0,r=0;r<t.length;r++)e+=Math.pow(t[r],2);return t.map((function(t){return Math.sqrt(Math.pow(t,2)/e)}))},n);function u(t,e,r){for(var n=new Set,s=[],i=[],o=[],a=function(n,a){s.push(n),i.push(a);var h=r(t.get(n,a),e.get(n,a));o.push(h)},l=t.getValues(),u=t.getRows(),c=t.getCols(),f=0;f<l.length;f++){var g=(w=u[f])+":"+(y=c[f]);n.add(g),a(w,y)}var m=e.getValues(),d=e.getRows(),p=e.getCols();for(f=0;f<m.length;f++){var w,y;g=(w=d[f])+":"+(y=p[f]),n.has(g)||a(w,y)}var v=[t.nRows,t.nCols];return new h(s,i,o,v)}e.getCSR=function(t){var e=[];t.forEach((function(t,r,n){e.push({value:t,row:r,col:n})})),e.sort((function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row}));for(var r=[],n=[],s=[],i=-1,o=0;o<e.length;o++){var a=e[o],h=a.row,l=a.col,u=a.value;h!==i&&(i=h,s.push(o)),r.push(l),n.push(u)}return{indices:r,values:n,indptr:s}}},760:function(t,e,r){var n=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var i=s(r(9378)),o=s(r(5686)),a=s(r(2320)),h=s(r(4517));e.makeNNDescent=function(t,e){return function(r,n,s,o,a,l,u,c){void 0===o&&(o=10),void 0===a&&(a=50),void 0===l&&(l=.001),void 0===u&&(u=.5),void 0===c&&(c=!0);for(var f=r.length,g=i.makeHeap(r.length,s),m=0;m<r.length;m++)for(var d=i.rejectionSample(s,r.length,e),p=0;p<d.length;p++){var w=t(r[m],r[d[p]]);i.heapPush(g,m,w,d[p],1),i.heapPush(g,d[p],w,m,1)}if(c)for(var y=0;y<n.length;y++)for(m=0;m<n[y].length&&!(n[y][m]<0);m++)for(p=m+1;p<n[y].length&&!(n[y][p]<0);p++)w=t(r[n[y][m]],r[n[y][p]]),i.heapPush(g,n[y][m],w,n[y][p],1),i.heapPush(g,n[y][p],w,n[y][m],1);for(y=0;y<o;y++){var v=i.buildCandidates(g,f,s,a,e),b=0;for(m=0;m<f;m++)for(p=0;p<a;p++){var M=Math.floor(v[0][m][p]);if(!(M<0||h.tauRand(e)<u))for(var _=0;_<a;_++){var x=Math.floor(v[0][m][_]),S=v[2][m][p],E=v[2][m][_];x<0||!S&&!E||(w=t(r[M],r[x]),b+=i.heapPush(g,M,w,x,1),b+=i.heapPush(g,x,w,M,1))}}if(b<=l*s*r.length)break}return i.deheapSort(g)}},e.makeInitializations=function(t){return{initFromRandom:function(e,r,n,s,o){for(var a=0;a<n.length;a++)for(var l=h.rejectionSample(e,r.length,o),u=0;u<l.length;u++)if(!(l[u]<0)){var c=t(r[l[u]],n[a]);i.heapPush(s,a,c,l[u],1)}},initFromTree:function(e,r,n,s,o){for(var h=0;h<n.length;h++)for(var l=a.searchFlatTree(n[h],e,o),u=0;u<l.length;u++){if(l[u]<0)return;var c=t(r[l[u]],n[h]);i.heapPush(s,h,c,l[u],1)}}}},e.makeInitializedNNSearch=function(t){return function(e,r,s,a){for(var h,l,u=o.getCSR(r),c=u.indices,f=u.indptr,g=0;g<a.length;g++)for(var m=new Set(s[0][g]);;){var d=i.smallestFlagged(s,g);if(-1===d)break;var p=c.slice(f[d],f[d+1]);try{for(var w=n(p),y=w.next();!y.done;y=w.next()){var v=y.value;if(v!==d&&-1!==v&&!m.has(v)){var b=t(e[v],a[g]);i.uncheckedHeapPush(s,g,b,v,1),m.add(v)}}}catch(t){h={error:t}}finally{try{y&&!y.done&&(l=w.return)&&l.call(w)}finally{if(h)throw h.error}}}return s}},e.initializeSearch=function(t,e,r,s,o,a,h){var l,u,c=i.makeHeap(r.length,s);if(o(s,e,r,c,h),t)try{for(var f=n(t),g=f.next();!g.done;g=f.next())a(g.value,e,r,c,h)}catch(t){l={error:t}}finally{try{g&&!g.done&&(u=f.return)&&u.call(f)}finally{if(l)throw l.error}}return c}},2320:function(t,e,r){var n=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},s=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(n(arguments[e]));return t},i=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}},o=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e};Object.defineProperty(e,"__esModule",{value:!0});var a=o(r(4517)),h=function(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n};function l(t,e,r,n,s){if(void 0===r&&(r=30),e.length>r){var i=function(t,e,r){var n=t[0].length,s=a.tauRandInt(e.length,r),i=a.tauRandInt(e.length,r);i=(i+=s===i?1:0)%e.length;for(var o=e[s],h=e[i],l=0,u=a.zeros(n),c=0;c<u.length;c++)u[c]=t[o][c]-t[h][c],l-=u[c]*(t[o][c]+t[h][c])/2;var f=0,g=0,m=a.zeros(e.length);for(c=0;c<e.length;c++){for(var d=l,p=0;p<n;p++)d+=u[p]*t[e[c]][p];0===d?(m[c]=a.tauRandInt(2,r),0===m[c]?f+=1:g+=1):d>0?(m[c]=0,f+=1):(m[c]=1,g+=1)}var w=a.zeros(f),y=a.zeros(g);for(f=0,g=0,c=0;c<m.length;c++)0===m[c]?(w[f]=e[c],f+=1):(y[g]=e[c],g+=1);return{indicesLeft:w,indicesRight:y,hyperplane:u,offset:l}}(t,e,s),o=i.indicesLeft,h=i.indicesRight,u=i.hyperplane,c=i.offset;return{leftChild:l(t,o,r,n+1,s),rightChild:l(t,h,r,n+1,s),isLeaf:!1,hyperplane:u,offset:c}}return{indices:e,isLeaf:!0}}function u(t,e,r,n,i,o,a){var h;if(t.isLeaf)return n[o][0]=-a,(h=i[a]).splice.apply(h,s([0,t.indices.length],t.indices)),{nodeNum:o,leafNum:a+=1};e[o]=t.hyperplane,r[o]=t.offset,n[o][0]=o+1;var l=o,c=u(t.leftChild,e,r,n,i,o+1,a);return o=c.nodeNum,a=c.leafNum,n[l][1]=o+1,{nodeNum:(c=u(t.rightChild,e,r,n,i,o+1,a)).nodeNum,leafNum:c.leafNum}}function c(t){return t.isLeaf?1:1+c(t.leftChild)+c(t.rightChild)}function f(t){return t.isLeaf?1:f(t.leftChild)+f(t.rightChild)}function g(t,e,r,n){for(var s=e,i=0;i<r.length;i++)s+=t[i]*r[i];return 0===s?a.tauRandInt(2,n):s>0?0:1}e.FlatTree=h,e.makeForest=function(t,e,r,n){var s=Math.max(10,e);return a.range(r).map((function(e,r){return function(t,e,r,n){return void 0===e&&(e=30),l(t,a.range(t.length),e,r,n)}(t,s,r,n)})).map((function(t){return function(t,e){var r=c(t),n=f(t),s=a.range(r).map((function(){return a.zeros(t.hyperplane?t.hyperplane.length:0)})),i=a.zeros(r),o=a.range(r).map((function(){return[-1,-1]})),l=a.range(n).map((function(){return a.range(e).map((function(){return-1}))}));return u(t,s,i,o,l,0,0),new h(s,i,o,l)}(t,s)}))},e.makeLeafArray=function(t){var e,r;if(t.length>0){var n=[];try{for(var o=i(t),a=o.next();!a.done;a=o.next()){var h=a.value;n.push.apply(n,s(h.indices))}}catch(t){e={error:t}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return n}return[[-1]]},e.searchFlatTree=function(t,e,r){for(var n=0;e.children[n][0]>0;)n=0===g(e.hyperplanes[n],e.offsets[n],t,r)?e.children[n][0]:e.children[n][1];var s=-1*e.children[n][0];return e.indices[s]}},4364:function(t,e,r){var n=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))((function(s,i){function o(t){try{h(n.next(t))}catch(t){i(t)}}function a(t){try{h(n.throw(t))}catch(t){i(t)}}function h(t){t.done?s(t.value):new r((function(e){e(t.value)})).then(o,a)}h((n=n.apply(t,e||[])).next())}))},s=this&&this.__generator||function(t,e){var r,n,s,i,o={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;o;)try{if(r=1,n&&(s=2&i[0]?n.return:i[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,i[1])).done)return s;switch(n=0,s&&(i=[2&i[0],s.value]),i[0]){case 0:case 1:s=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,n=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!((s=(s=o.trys).length>0&&s[s.length-1])||6!==i[0]&&2!==i[0])){o=0;continue}if(3===i[0]&&(!s||i[1]>s[0]&&i[1]<s[3])){o.label=i[1];break}if(6===i[0]&&o.label<s[1]){o.label=s[1],s=i;break}if(s&&o.label<s[2]){o.label=s[2],o.ops.push(i);break}s[2]&&o.ops.pop(),o.trys.pop();continue}i=e.call(t,o)}catch(t){i=[6,t],n=0}finally{r=s=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},i=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,s,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){s={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(s)throw s.error}}return o},o=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t},a=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e},h=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var l=a(r(9378)),u=a(r(5686)),c=a(r(760)),f=a(r(2320)),g=a(r(4517)),m=h(r(9251)),d=1e-5,p=.001,w=function(){function t(t){void 0===t&&(t={});var e=this;this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=y,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new v;var r=function(r){void 0!==t[r]&&(e[r]=t[r])};r("distanceFn"),r("learningRate"),r("localConnectivity"),r("minDist"),r("nComponents"),r("nEpochs"),r("nNeighbors"),r("negativeSampleRate"),r("random"),r("repulsionStrength"),r("setOpMixRatio"),r("spread"),r("transformQueueSize")}return t.prototype.fit=function(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding},t.prototype.fitAsync=function(t,e){return void 0===e&&(e=function(){return!0}),n(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return this.initializeFit(t),[4,this.optimizeLayoutAsync(e)];case 1:return r.sent(),[2,this.embedding]}}))}))},t.prototype.setSupervisedProjection=function(t,e){void 0===e&&(e={}),this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors},t.prototype.setPrecomputedKNN=function(t,e){this.knnIndices=t,this.knnDistances=e},t.prototype.initializeFit=function(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){var 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();var r=this.initializeSimplicialSetEmbedding(),n=r.head,s=r.tail,i=r.epochsPerSample;return this.optimizationState.head=n,this.optimizationState.tail=s,this.optimizationState.epochsPerSample=i,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()},t.prototype.makeSearchFns=function(){var t=c.makeInitializations(this.distanceFn),e=t.initFromTree,r=t.initFromRandom;this.initFromTree=e,this.initFromRandom=r,this.search=c.makeInitializedNNSearch(this.distanceFn)},t.prototype.makeSearchGraph=function(t){for(var e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],s=new u.SparseMatrix([],[],[],n),i=0;i<e.length;i++)for(var o=e[i],a=r[i],h=0;h<o.length;h++){var l=o[h],c=a[h];c>0&&s.set(i,l,c)}var f=u.transpose(s);return u.maximum(s,f)},t.prototype.transform=function(t){var e=this,r=this.X;if(void 0===r||0===r.length)throw new Error("No data has been fit.");var n=Math.floor(this.nNeighbors*this.transformQueueSize);n=Math.min(r.length,n);var s=c.initializeSearch(this.rpForest,r,t,n,this.initFromRandom,this.initFromTree,this.random),i=this.search(r,this.searchGraph,s,t),o=l.deheapSort(i),a=o.indices,h=o.weights;a=a.map((function(t){return t.slice(0,e.nNeighbors)})),h=h.map((function(t){return t.slice(0,e.nNeighbors)}));var f=Math.max(0,this.localConnectivity-1),m=this.smoothKNNDistance(h,this.nNeighbors,f),d=m.sigmas,p=m.rhos,w=this.computeMembershipStrengths(a,h,d,p),y=w.rows,v=w.cols,b=w.vals,M=[t.length,r.length],_=new u.SparseMatrix(y,v,b,M),x=u.normalize(_,"l1"),S=u.getCSR(x),k=t.length,N=E(g.reshape2d(S.indices,k,this.nNeighbors),g.reshape2d(S.values,k,this.nNeighbors),this.embedding),R=this.nEpochs?this.nEpochs/3:_.nRows<=1e4?100:30,I=_.getValues().reduce((function(t,e){return e>t?e:t}),0);_=_.map((function(t){return t<I/R?0:t})),_=u.eliminateZeros(_);var z=this.makeEpochsPerSample(_.getValues(),R),A=_.getRows(),F=_.getCols();return this.assignOptimizationStateParameters({headEmbedding:N,tailEmbedding:this.embedding,head:A,tail:F,currentEpoch:0,nEpochs:R,nVertices:_.getDims()[1],epochsPerSample:z}),this.prepareForOptimizationLoop(),this.optimizeLayout()},t.prototype.processGraphForSupervisedProjection=function(){var t=this.Y,e=this.X;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){var r=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,r)}}},t.prototype.step=function(){var t=this.optimizationState.currentEpoch;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch},t.prototype.getEmbedding=function(){return this.embedding},t.prototype.nearestNeighbors=function(t){var e,r=this.distanceFn,n=this.nNeighbors,s=c.makeNNDescent(r,this.random),i=5+Math.floor(.5==(e=Math.pow(t.length,.5)/20)?0:Math.round(e)),o=Math.max(5,Math.floor(Math.round(function(t){return Math.log(t)/Math.log(2)}(t.length))));this.rpForest=f.makeForest(t,n,i,this.random);var a=s(t,f.makeLeafArray(this.rpForest),n,o);return{knnIndices:a.indices,knnDistances:a.weights}},t.prototype.fuzzySimplicialSet=function(t,e,r){void 0===r&&(r=1);var n=this,s=n.knnIndices,i=void 0===s?[]:s,o=n.knnDistances,a=void 0===o?[]:o,h=n.localConnectivity,l=this.smoothKNNDistance(a,e,h),c=l.sigmas,f=l.rhos,g=this.computeMembershipStrengths(i,a,c,f),m=g.rows,d=g.cols,p=g.vals,w=[t.length,t.length],y=new u.SparseMatrix(m,d,p,w),v=u.transpose(y),b=u.pairwiseMultiply(y,v),M=u.subtract(u.add(y,v),b),_=u.multiplyScalar(M,r),x=u.multiplyScalar(b,1-r);return u.add(_,x)},t.prototype.categoricalSimplicialSetIntersection=function(t,e,r,n){void 0===n&&(n=1);var s=x(t,e,n,r);return S(s=u.eliminateZeros(s))},t.prototype.smoothKNNDistance=function(t,e,r,n,s){void 0===r&&(r=1),void 0===n&&(n=64),void 0===s&&(s=1);for(var i=Math.log(e)/Math.log(2)*s,o=g.zeros(t.length),a=g.zeros(t.length),h=0;h<t.length;h++){var l=0,u=1/0,c=1,f=t[h],m=f.filter((function(t){return t>0}));if(m.length>=r){var w=Math.floor(r),y=r-w;w>0?(o[h]=m[w-1],y>d&&(o[h]+=y*(m[w]-m[w-1]))):o[h]=y*m[0]}else m.length>0&&(o[h]=g.max(m));for(var v=0;v<n;v++){for(var b=0,M=1;M<t[h].length;M++){var _=t[h][M]-o[h];b+=_>0?Math.exp(-_/c):1}if(Math.abs(b-i)<d)break;b>i?c=(l+(u=c))/2:(l=c,u===1/0?c*=2:c=(l+u)/2)}if(a[h]=c,o[h]>0){var x=g.mean(f);a[h]<p*x&&(a[h]=p*x)}else{var S=g.mean(t.map(g.mean));a[h]<p*S&&(a[h]=p*S)}}return{sigmas:a,rhos:o}},t.prototype.computeMembershipStrengths=function(t,e,r,n){for(var s=t.length,i=t[0].length,o=g.zeros(s*i),a=g.zeros(s*i),h=g.zeros(s*i),l=0;l<s;l++)for(var u=0;u<i;u++){var c=0;-1!==t[l][u]&&(c=t[l][u]===l?0:e[l][u]-n[l]<=0?1:Math.exp(-(e[l][u]-n[l])/r[l]),o[l*i+u]=l,a[l*i+u]=t[l][u],h[l*i+u]=c)}return{rows:o,cols:a,vals:h}},t.prototype.initializeSimplicialSetEmbedding=function(){for(var t=this,e=this.getNEpochs(),r=this.nComponents,n=this.graph.getValues(),s=0,i=0;i<n.length;i++){var o=n[i];s<n[i]&&(s=o)}var a=this.graph.map((function(t){return t<s/e?0:t}));this.embedding=g.zeros(a.nRows).map((function(){return g.zeros(r).map((function(){return 20*g.tauRand(t.random)-10}))}));var h=[],l=[],u=[],c=a.getAll();for(i=0;i<c.length;i++){var f=c[i];f.value&&(h.push(f.value),u.push(f.row),l.push(f.col))}return{head:l,tail:u,epochsPerSample:this.makeEpochsPerSample(h,e)}},t.prototype.makeEpochsPerSample=function(t,e){var r=g.filled(t.length,-1),n=g.max(t),s=t.map((function(t){return t/n*e}));return s.forEach((function(t,n){t>0&&(r[n]=e/s[n])})),r},t.prototype.assignOptimizationStateParameters=function(t){Object.assign(this.optimizationState,t)},t.prototype.prepareForOptimizationLoop=function(){var t=this,e=t.repulsionStrength,r=t.learningRate,n=t.negativeSampleRate,s=this.optimizationState,i=s.epochsPerSample,a=s.headEmbedding,h=s.tailEmbedding,l=a[0].length,u=a.length===h.length,c=i.map((function(t){return t/n})),f=o(c),g=o(i);this.assignOptimizationStateParameters({epochOfNextSample:g,epochOfNextNegativeSample:f,epochsPerNegativeSample:c,moveOther:u,initialAlpha:r,alpha:r,gamma:e,dim:l})},t.prototype.initializeOptimization=function(){var t=this.embedding,e=this.embedding,r=this.optimizationState,n=r.head,s=r.tail,i=r.epochsPerSample,o=this.getNEpochs(),a=this.graph.nCols,h=_(this.spread,this.minDist),l=h.a,u=h.b;this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:n,tail:s,epochsPerSample:i,a:l,b:u,nEpochs:o,nVertices:a})},t.prototype.optimizeLayoutStep=function(t){for(var e=this.optimizationState,r=e.head,n=e.tail,s=e.headEmbedding,i=e.tailEmbedding,o=e.epochsPerSample,a=e.epochOfNextSample,h=e.epochOfNextNegativeSample,l=e.epochsPerNegativeSample,u=e.moveOther,c=e.initialAlpha,f=e.alpha,m=e.gamma,d=e.a,p=e.b,w=e.dim,y=e.nEpochs,v=e.nVertices,_=0;_<o.length;_++)if(!(a[_]>t)){var x=r[_],S=n[_],E=s[x],k=i[S],N=M(E,k),R=0;N>0&&(R=-2*d*p*Math.pow(N,p-1),R/=d*Math.pow(N,p)+1);for(var I=0;I<w;I++){var z=b(R*(E[I]-k[I]),4);E[I]+=z*f,u&&(k[I]+=-z*f)}a[_]+=o[_];for(var A=Math.floor((t-h[_])/l[_]),F=0;F<A;F++){var C=g.tauRandInt(v,this.random),T=i[C],P=M(E,T),D=0;if(P>0)D=2*m*p,D/=(.001+P)*(d*Math.pow(P,p)+1);else if(x===C)continue;for(I=0;I<w;I++)z=4,D>0&&(z=b(D*(E[I]-T[I]),4)),E[I]+=z*f}h[_]+=A*l[_]}return e.alpha=c*(1-t/y),e.currentEpoch+=1,s},t.prototype.optimizeLayoutAsync=function(t){var e=this;return void 0===t&&(t=function(){return!0}),new Promise((function(r,i){var o=function(){return n(e,void 0,void 0,(function(){var e,n,a,h,l,u;return s(this,(function(s){try{if(e=this.optimizationState,n=e.nEpochs,a=e.currentEpoch,this.embedding=this.optimizeLayoutStep(a),h=this.optimizationState.currentEpoch,l=!1===t(h),u=h===n,l||u)return[2,r(u)];setTimeout((function(){return o()}),0)}catch(t){i(t)}return[2]}))}))};setTimeout((function(){return o()}),0)}))},t.prototype.optimizeLayout=function(t){void 0===t&&(t=function(){return!0});for(var e=!1,r=[];!e;){var n=this.optimizationState,s=n.nEpochs,i=n.currentEpoch;r=this.optimizeLayoutStep(i);var o=this.optimizationState.currentEpoch,a=!1===t(o);e=o===s||a}return r},t.prototype.getNEpochs=function(){var t=this.graph;if(this.nEpochs>0)return this.nEpochs;var e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200},t}();function y(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return Math.sqrt(r)}e.UMAP=w,e.euclidean=y,e.cosine=function(t,e){for(var r=0,n=0,s=0,i=0;i<t.length;i++)r+=t[i]*e[i],n+=Math.pow(t[i],2),s+=Math.pow(e[i],2);return 0===n&&0===s?0:0===n||0===s?1:1-r/Math.sqrt(n*s)};var v=function(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0};function b(t,e){return t>e?e:t<-e?-e:t}function M(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}function _(t,e){var r=g.linear(0,3*t,300).map((function(t){return t<e?1:t})),n=g.zeros(r.length).map((function(n,s){return r[s]>=e?Math.exp(-(r[s]-e)/t):n})),s={x:r,y:n},o=m.default(s,(function(t){var e=i(t,2),r=e[0],n=e[1];return function(t){return 1/(1+r*Math.pow(t,2*n))}}),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}).parameterValues,a=i(o,2);return{a:a[0],b:a[1]}}function x(t,e,r,n){return void 0===r&&(r=1),void 0===n&&(n=5),t.map((function(t,s,i){return-1===e[s]||-1===e[i]?t*Math.exp(-r):e[s]!==e[i]?t*Math.exp(-n):t}))}function S(t){t=u.normalize(t,"max");var e=u.transpose(t),r=u.pairwiseMultiply(e,t);return t=u.add(t,u.subtract(e,r)),u.eliminateZeros(t)}function E(t,e,r){for(var n=g.zeros(t.length).map((function(t){return g.zeros(r[0].length)})),s=0;s<t.length;s++)for(var i=0;i<t[0].length;i++)for(var o=0;o<r[0].length;o++){var a=t[s][i];n[s][o]+=e[s][i]*r[a][o]}return n}e.findABParams=_,e.fastIntersection=x,e.resetLocalConnectivity=S,e.initTransform=E},4517:function(t,e){var r=this&&this.__values||function(t){var e="function"==typeof Symbol&&t[Symbol.iterator],r=0;return e?e.call(t):{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}};function n(t,e){return Math.floor(e()*t)}function s(t){for(var e=[],r=0;r<t;r++)e.push(void 0);return e}function i(t,e){return s(t).map((function(){return e}))}function o(t){return i(t,0)}function a(t){return t.reduce((function(t,e){return t+e}))}Object.defineProperty(e,"__esModule",{value:!0}),e.tauRandInt=n,e.tauRand=function(t){return t()},e.norm=function(t){var e,n,s=0;try{for(var i=r(t),o=i.next();!o.done;o=i.next()){var a=o.value;s+=Math.pow(a,2)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return Math.sqrt(s)},e.empty=s,e.range=function(t){return s(t).map((function(t,e){return e}))},e.filled=i,e.zeros=o,e.ones=function(t){return i(t,1)},e.linear=function(t,e,r){return s(r).map((function(n,s){return t+s*((e-t)/(r-1))}))},e.sum=a,e.mean=function(t){return a(t)/t.length},e.max=function(t){for(var e=0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e},e.max2d=function(t){for(var e=0,r=0;r<t.length;r++)for(var n=0;n<t[r].length;n++)e=t[r][n]>e?t[r][n]:e;return e},e.rejectionSample=function(t,e,r){for(var s=o(t),i=0;i<t;i++)for(var a=!0;a;){for(var h=n(e,r),l=!1,u=0;u<i;u++)if(h===s[u]){l=!0;break}l||(a=!1),s[i]=h}return s},e.reshape2d=function(t,e,r){var n=[],s=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(var i=0;i<e;i++){for(var o=[],a=0;a<r;a++)o.push(t[s]),s+=1;n.push(o)}return n}}},n={};function s(t){var e=n[t];if(void 0!==e)return e.exports;var i=n[t]={exports:{}};return r[t].call(i.exports,i,i.exports,s),i.exports}s.m=r,s.x=()=>{var t=s.O(void 0,[1,452],(()=>s(1729)));return s.O(t)},t=[],s.O=(e,r,n,i)=>{if(!r){var o=1/0;for(u=0;u<t.length;u++){for(var[r,n,i]=t[u],a=!0,h=0;h<r.length;h++)(!1&i||o>=i)&&Object.keys(s.O).every((t=>s.O[t](r[h])))?r.splice(h--,1):(a=!1,i<o&&(o=i));if(a){t.splice(u--,1);var l=n();void 0!==l&&(e=l)}}return e}i=i||0;for(var u=t.length;u>0&&t[u-1][2]>i;u--)t[u]=t[u-1];t[u]=[r,n,i]},s.d=(t,e)=>{for(var r in e)s.o(e,r)&&!s.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},s.f={},s.e=t=>Promise.all(Object.keys(s.f).reduce(((e,r)=>(s.f[r](t,e),e)),[])),s.u=t=>t+".js",s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},(()=>{var t;s.g.importScripts&&(t=s.g.location+"");var e=s.g.document;if(!t&&e&&(e.currentScript&&(t=e.currentScript.src),!t)){var r=e.getElementsByTagName("script");if(r.length)for(var n=r.length-1;n>-1&&!t;)t=r[n--].src}if(!t)throw new Error("Automatic publicPath is not supported in this browser");t=t.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=t})(),(()=>{s.b=self.location+"";var t={729:1};s.f.i=(e,r)=>{t[e]||importScripts(s.p+s.u(e))};var e=self.webpackChunkbio=self.webpackChunkbio||[],r=e.push.bind(e);e.push=e=>{var[n,i,o]=e;for(var a in i)s.o(i,a)&&(s.m[a]=i[a]);for(o&&o(s);n.length;)t[n.pop()]=1;r(e)}})(),e=s.x,s.x=()=>Promise.all([s.e(1),s.e(452)]).then(e);var i=s.x();bio=i})();
|
|
2
2
|
//# sourceMappingURL=729.js.map
|