@datagrok/bio 2.11.26 → 2.11.27

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/dist/42.js ADDED
@@ -0,0 +1,2 @@
1
+ var bio;(()=>{var r,e,t={5042:()=>{}},o={};function i(r){var e=o[r];if(void 0!==e)return e.exports;var n=o[r]={id:r,loaded:!1,exports:{}};return t[r].call(n.exports,n,n.exports,i),n.loaded=!0,n.exports}i.m=t,i.x=()=>{var r=i.O(void 0,[649,886],(()=>i(2886)));return i.O(r)},i.amdD=function(){throw new Error("define cannot be used indirect")},i.amdO={},r=[],i.O=(e,t,o,n)=>{if(!t){var a=1/0;for(s=0;s<r.length;s++){for(var[t,o,n]=r[s],c=!0,l=0;l<t.length;l++)(!1&n||a>=n)&&Object.keys(i.O).every((r=>i.O[r](t[l])))?t.splice(l--,1):(c=!1,n<a&&(a=n));if(c){r.splice(s--,1);var p=o();void 0!==p&&(e=p)}}return e}n=n||0;for(var s=r.length;s>0&&r[s-1][2]>n;s--)r[s]=r[s-1];r[s]=[t,o,n]},i.n=r=>{var e=r&&r.__esModule?()=>r.default:()=>r;return i.d(e,{a:e}),e},i.d=(r,e)=>{for(var t in e)i.o(e,t)&&!i.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},i.f={},i.e=r=>Promise.all(Object.keys(i.f).reduce(((e,t)=>(i.f[t](r,e),e)),[])),i.u=r=>r+".js",i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(r){if("object"==typeof window)return window}}(),i.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),i.nmd=r=>(r.paths=[],r.children||(r.children=[]),r),(()=>{var r;i.g.importScripts&&(r=i.g.location+"");var e=i.g.document;if(!r&&e&&(e.currentScript&&(r=e.currentScript.src),!r)){var t=e.getElementsByTagName("script");if(t.length)for(var o=t.length-1;o>-1&&!r;)r=t[o--].src}if(!r)throw new Error("Automatic publicPath is not supported in this browser");r=r.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=r})(),(()=>{i.b=self.location+"";var r={42:1};i.f.i=(e,t)=>{r[e]||importScripts(i.p+i.u(e))};var e=self.webpackChunkbio=self.webpackChunkbio||[],t=e.push.bind(e);e.push=e=>{var[o,n,a]=e;for(var c in n)i.o(n,c)&&(i.m[c]=n[c]);for(a&&a(i);o.length;)r[o.pop()]=1;t(e)}})(),e=i.x,i.x=()=>Promise.all([i.e(649),i.e(886)]).then(e);var n=i.x();bio=n})();
2
+ //# sourceMappingURL=42.js.map
package/dist/42.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"42.js","mappings":"kBAAIA,ECAAC,E,gBCCAC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaE,QAGrB,IAAIC,EAASN,EAAyBE,GAAY,CACjDK,GAAIL,EACJM,QAAQ,EACRH,QAAS,CAAC,GAUX,OANAI,EAAoBP,GAAUQ,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASJ,GAG3EK,EAAOE,QAAS,EAGTF,EAAOD,OACf,CAGAJ,EAAoBU,EAAIF,EAGxBR,EAAoBW,EAAI,KAGvB,IAAIC,EAAsBZ,EAAoBa,OAAEV,EAAW,CAAC,IAAI,MAAM,IAAOH,EAAoB,QAEjG,OADsBA,EAAoBa,EAAED,EAClB,ECpC3BZ,EAAoBc,KAAO,WAC1B,MAAM,IAAIC,MAAM,iCACjB,ECFAf,EAAoBgB,KAAO,CAAC,EJAxBnB,EAAW,GACfG,EAAoBa,EAAI,CAACI,EAAQC,EAAUC,EAAIC,KAC9C,IAAGF,EAAH,CAMA,IAAIG,EAAeC,IACnB,IAASC,EAAI,EAAGA,EAAI1B,EAAS2B,OAAQD,IAAK,CAGzC,IAFA,IAAKL,EAAUC,EAAIC,GAAYvB,EAAS0B,GACpCE,GAAY,EACPC,EAAI,EAAGA,EAAIR,EAASM,OAAQE,MACpB,EAAXN,GAAsBC,GAAgBD,IAAaO,OAAOC,KAAK5B,EAAoBa,GAAGgB,OAAOC,GAAS9B,EAAoBa,EAAEiB,GAAKZ,EAASQ,MAC9IR,EAASa,OAAOL,IAAK,IAErBD,GAAY,EACTL,EAAWC,IAAcA,EAAeD,IAG7C,GAAGK,EAAW,CACb5B,EAASkC,OAAOR,IAAK,GACrB,IAAIS,EAAIb,SACEhB,IAAN6B,IAAiBf,EAASe,EAC/B,CACD,CACA,OAAOf,CAnBP,CAJCG,EAAWA,GAAY,EACvB,IAAI,IAAIG,EAAI1B,EAAS2B,OAAQD,EAAI,GAAK1B,EAAS0B,EAAI,GAAG,GAAKH,EAAUG,IAAK1B,EAAS0B,GAAK1B,EAAS0B,EAAI,GACrG1B,EAAS0B,GAAK,CAACL,EAAUC,EAAIC,EAqBjB,EKzBdpB,EAAoBiC,EAAK5B,IACxB,IAAI6B,EAAS7B,GAAUA,EAAO8B,WAC7B,IAAO9B,EAAiB,QACxB,IAAM,EAEP,OADAL,EAAoBoC,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdlC,EAAoBoC,EAAI,CAAChC,EAASkC,KACjC,IAAI,IAAIR,KAAOQ,EACXtC,EAAoBuC,EAAED,EAAYR,KAAS9B,EAAoBuC,EAAEnC,EAAS0B,IAC5EH,OAAOa,eAAepC,EAAS0B,EAAK,CAAEW,YAAY,EAAMC,IAAKJ,EAAWR,IAE1E,ECND9B,EAAoB2C,EAAI,CAAC,EAGzB3C,EAAoB4C,EAAKC,GACjBC,QAAQC,IAAIpB,OAAOC,KAAK5B,EAAoB2C,GAAGK,QAAO,CAACC,EAAUnB,KACvE9B,EAAoB2C,EAAEb,GAAKe,EAASI,GAC7BA,IACL,KCNJjD,EAAoBkD,EAAKL,GAEZA,EAAU,MCHvB7C,EAAoBmD,EAAI,WACvB,GAA0B,iBAAfC,WAAyB,OAAOA,WAC3C,IACC,OAAOC,MAAQ,IAAIC,SAAS,cAAb,EAChB,CAAE,MAAOV,GACR,GAAsB,iBAAXW,OAAqB,OAAOA,MACxC,CACA,CAPuB,GCAxBvD,EAAoBuC,EAAI,CAACiB,EAAKC,IAAU9B,OAAO+B,UAAUC,eAAelD,KAAK+C,EAAKC,GCAlFzD,EAAoB4D,IAAOvD,IAC1BA,EAAOwD,MAAQ,GACVxD,EAAOyD,WAAUzD,EAAOyD,SAAW,IACjCzD,G,MCHR,IAAI0D,EACA/D,EAAoBmD,EAAEa,gBAAeD,EAAY/D,EAAoBmD,EAAEc,SAAW,IACtF,IAAIC,EAAWlE,EAAoBmD,EAAEe,SACrC,IAAKH,GAAaG,IACbA,EAASC,gBACZJ,EAAYG,EAASC,cAAcC,MAC/BL,GAAW,CACf,IAAIM,EAAUH,EAASI,qBAAqB,UAC5C,GAAGD,EAAQ7C,OAEV,IADA,IAAID,EAAI8C,EAAQ7C,OAAS,EAClBD,GAAK,IAAMwC,GAAWA,EAAYM,EAAQ9C,KAAK6C,GAExD,CAID,IAAKL,EAAW,MAAM,IAAIhD,MAAM,yDAChCgD,EAAYA,EAAUQ,QAAQ,OAAQ,IAAIA,QAAQ,QAAS,IAAIA,QAAQ,YAAa,KACpFvE,EAAoBwE,EAAIT,C,WClBxB/D,EAAoByE,EAAIC,KAAKT,SAAW,GAIxC,IAAIU,EAAkB,CACrB,GAAI,GAgBL3E,EAAoB2C,EAAEpB,EAAI,CAACsB,EAASI,KAE/B0B,EAAgB9B,IAElBmB,cAAchE,EAAoBwE,EAAIxE,EAAoBkD,EAAEL,GAE9D,EAGD,IAAI+B,EAAqBF,KAAsB,gBAAIA,KAAsB,iBAAK,GAC1EG,EAA6BD,EAAmBE,KAAKC,KAAKH,GAC9DA,EAAmBE,KAvBCE,IACnB,IAAK9D,EAAU+D,EAAaC,GAAWF,EACvC,IAAI,IAAI/E,KAAYgF,EAChBjF,EAAoBuC,EAAE0C,EAAahF,KACrCD,EAAoBU,EAAET,GAAYgF,EAAYhF,IAIhD,IADGiF,GAASA,EAAQlF,GACdkB,EAASM,QACdmD,EAAgBzD,EAASiE,OAAS,EACnCN,EAA2BG,EAAK,C,KZnB7BlF,EAAOE,EAAoBW,EAC/BX,EAAoBW,EAAI,IAChBmC,QAAQC,IAAI,CAClB/C,EAAoB4C,EAAE,KACtB5C,EAAoB4C,EAAE,OACpBwC,KAAKtF,GaJT,IAAIc,EAAsBZ,EAAoBW,I","sources":["webpack://bio/webpack/runtime/chunk loaded","webpack://bio/webpack/runtime/startup chunk dependencies","webpack://bio/webpack/bootstrap","webpack://bio/webpack/runtime/amd define","webpack://bio/webpack/runtime/amd options","webpack://bio/webpack/runtime/compat get default export","webpack://bio/webpack/runtime/define property getters","webpack://bio/webpack/runtime/ensure chunk","webpack://bio/webpack/runtime/get javascript chunk filename","webpack://bio/webpack/runtime/global","webpack://bio/webpack/runtime/hasOwnProperty shorthand","webpack://bio/webpack/runtime/node module decorator","webpack://bio/webpack/runtime/publicPath","webpack://bio/webpack/runtime/importScripts chunk loading","webpack://bio/webpack/startup"],"sourcesContent":["var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar [chunkIds, fn, priority] = deferred[i];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","var next = __webpack_require__.x;\n__webpack_require__.x = () => {\n\treturn Promise.all([\n\t\t__webpack_require__.e(649),\n\t\t__webpack_require__.e(886)\n\t]).then(next);\n};","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\tid: moduleId,\n\t\tloaded: false,\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Flag the module as loaded\n\tmodule.loaded = true;\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n// the startup function\n__webpack_require__.x = () => {\n\t// Load entry module and return exports\n\t// This entry module depends on other loaded chunks and execution need to be delayed\n\tvar __webpack_exports__ = __webpack_require__.O(undefined, [649,886], () => (__webpack_require__(2886)))\n\t__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n\treturn __webpack_exports__;\n};\n\n","__webpack_require__.amdD = function () {\n\tthrow new Error('define cannot be used indirect');\n};","__webpack_require__.amdO = {};","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.f = {};\n// This file contains only the entry chunk.\n// The chunk loading function for additional chunks\n__webpack_require__.e = (chunkId) => {\n\treturn Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {\n\t\t__webpack_require__.f[key](chunkId, promises);\n\t\treturn promises;\n\t}, []));\n};","// This function allow to reference async chunks and sibling chunks for the entrypoint\n__webpack_require__.u = (chunkId) => {\n\t// return url for filenames based on template\n\treturn \"\" + chunkId + \".js\";\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","__webpack_require__.nmd = (module) => {\n\tmodule.paths = [];\n\tif (!module.children) module.children = [];\n\treturn module;\n};","var scriptUrl;\nif (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + \"\";\nvar document = __webpack_require__.g.document;\nif (!scriptUrl && document) {\n\tif (document.currentScript)\n\t\tscriptUrl = document.currentScript.src;\n\tif (!scriptUrl) {\n\t\tvar scripts = document.getElementsByTagName(\"script\");\n\t\tif(scripts.length) {\n\t\t\tvar i = scripts.length - 1;\n\t\t\twhile (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;\n\t\t}\n\t}\n}\n// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration\n// or pass an empty string (\"\") and set the __webpack_public_path__ variable from your code to use your own logic.\nif (!scriptUrl) throw new Error(\"Automatic publicPath is not supported in this browser\");\nscriptUrl = scriptUrl.replace(/#.*$/, \"\").replace(/\\?.*$/, \"\").replace(/\\/[^\\/]+$/, \"/\");\n__webpack_require__.p = scriptUrl;","__webpack_require__.b = self.location + \"\";\n\n// object to store loaded chunks\n// \"1\" means \"already loaded\"\nvar installedChunks = {\n\t42: 1\n};\n\n// importScripts chunk loading\nvar installChunk = (data) => {\n\tvar [chunkIds, moreModules, runtime] = data;\n\tfor(var moduleId in moreModules) {\n\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t}\n\t}\n\tif(runtime) runtime(__webpack_require__);\n\twhile(chunkIds.length)\n\t\tinstalledChunks[chunkIds.pop()] = 1;\n\tparentChunkLoadingFunction(data);\n};\n__webpack_require__.f.i = (chunkId, promises) => {\n\t// \"1\" is the signal for \"already loaded\"\n\tif(!installedChunks[chunkId]) {\n\t\tif(true) { // all chunks have JS\n\t\t\timportScripts(__webpack_require__.p + __webpack_require__.u(chunkId));\n\t\t}\n\t}\n};\n\nvar chunkLoadingGlobal = self[\"webpackChunkbio\"] = self[\"webpackChunkbio\"] || [];\nvar parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);\nchunkLoadingGlobal.push = installChunk;\n\n// no HMR\n\n// no HMR manifest","// run startup\nvar __webpack_exports__ = __webpack_require__.x();\n"],"names":["deferred","next","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","id","loaded","__webpack_modules__","call","m","x","__webpack_exports__","O","amdD","Error","amdO","result","chunkIds","fn","priority","notFulfilled","Infinity","i","length","fulfilled","j","Object","keys","every","key","splice","r","n","getter","__esModule","d","a","definition","o","defineProperty","enumerable","get","f","e","chunkId","Promise","all","reduce","promises","u","g","globalThis","this","Function","window","obj","prop","prototype","hasOwnProperty","nmd","paths","children","scriptUrl","importScripts","location","document","currentScript","src","scripts","getElementsByTagName","replace","p","b","self","installedChunks","chunkLoadingGlobal","parentChunkLoadingFunction","push","bind","data","moreModules","runtime","pop","then"],"sourceRoot":""}
package/dist/886.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /*! For license information please see 886.js.LICENSE.txt */
2
- var bio;(()=>{"use strict";var t,e,r={2886:(t,e,r)=>{class n extends Float32Array{}var s,o,i,h,a,l,u=r(7659);!function(t){t.Levenshtein="Levenshtein",t.JaroWinkler="Jaro-Winkler",t.Manhattan="Manhattan",t.Onehot="One-Hot"}(s||(s={})),function(t){t.Euclidean="Euclidean"}(o||(o={})),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.TanimotoIntArray="TanimotoIntArray"}(h||(h={})),function(t){t.Vector="Vector",t.String="String",t.BitArray="BitArray",t.MacroMolecule="MacroMolecule",t.Number="Number",t.IntArray="IntArray"}(a||(a={})),function(t){t.Difference="Difference"}(l||(l={}));var c=r(1811),f=r(3979);class g{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=g._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 g(t._length);r._length=t._length,r._data=g._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 g(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 g(t);for(let n=0;n<t;++n)r.setBit(n,e(n));return r._version=0,r}static fromString(t){return g.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const r=new g(t);return r._data=e,r}static fromBytes(t){const e=t.length,r=new g(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 g(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 g.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),o=Math.max(t,e);if(r)for(let t=s;t<=o;t++)this.setTrue(t);else for(let t=s;t<=o;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+=g._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+=g._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+=g._onBitCount[255&e];let o=this._data[s]&t._data[s];const i=31&this._length;for(0!=i&&(o&=~(4294967295<<i));0!=o;o>>>=8)r+=g._onBitCount[255&o];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=g._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=g._lastOnBit[t>>>24];if(r>=0)return r+32*n+e}}return-1}}g._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]),g._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]),g._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 m=r(708);function w(t,e){const r=t.trueCount()+e.trueCount();if(0==r)return 1;const n=t.andWithCountBits(e,!0);return n/(r-n)}function p(t){return 0===t?3402823e32:1/t-1}function d(t=!1,e="Assertion error."){if(!t)throw new Error(e)}i.Tanimoto,i.Dice,i.Asymmetric,i.BraunBlanquet,i.Cosine,i.Kulczynski,i.McConnaughey,i.RogotGoldberg,i.Russel,i.Sokal,i.Hamming,i.Euclidean,i.Tanimoto,i.Dice,i.Asymmetric,i.BraunBlanquet,i.Cosine,i.Kulczynski,i.McConnaughey,i.RogotGoldberg,i.Russel,i.Sokal,i.Hamming,i.Euclidean,i.Tanimoto,i.Dice,i.Cosine,i.Tanimoto,i.Asymmetric,i.Cosine,i.Sokal,m.U.HAMMING,m.U.LEVENSHTEIN,m.U.MONOMER_CHEMICAL_DISTANCE,m.U.NEEDLEMANN_WUNSCH;const y={[o.Euclidean]:function(t,e){let r=0;const n=t.length;if(n!==e.length)throw new Error("The dimensionality of the vectors must match");for(let s=0;s<n;++s)r+=Math.pow(t[s]-e[s],2);return Math.sqrt(r)}},M={[s.Levenshtein]:c.T,[s.JaroWinkler]:f.H$,[s.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.Onehot]:function(t,e){return t===e?0:1}},b={[i.Tanimoto]:function(t,e){return p(w(t,e))},[i.Dice]:function(t,e){return p(function(t,e){const r=t.trueCount()+e.trueCount();return 0==r?0:2*t.andWithCountBits(e,!0)/r}(t,e))},[i.Asymmetric]:function(t,e){return p(function(t,e){const r=Math.min(t.trueCount(),e.trueCount());return 0==r?0:t.andWithCountBits(e,!0)/r}(t,e))},[i.BraunBlanquet]:function(t,e){return p(function(t,e){const r=Math.max(t.trueCount(),e.trueCount());return 0==r?0:t.andWithCountBits(e,!0)/r}(t,e))},[i.Cosine]:function(t,e){return p(function(t,e){const r=t.trueCount()*e.trueCount();return 0==r?0:t.andWithCountBits(e,!0)/Math.sqrt(r)}(t,e))},[i.Kulczynski]:function(t,e){return p(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.trueCount()*e.trueCount();return 0==n?0:t.andWithCountBits(e,!0)*r/(2*n)}(t,e))},[i.McConnaughey]:function(t,e){return p(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.trueCount()*e.trueCount();return 0==n?0:(t.andWithCountBits(e,!0)*r-n)/n}(t,e))},[i.RogotGoldberg]:function(t,e){return p(function(t,e){const r=t.andWithCountBits(e,!0),n=t.countBits(!0)+e.countBits(!0),s=t.length,o=s-n+r;return r==s||o==s?1:r/n+o/(2*s-n)}(t,e))},[i.Russel]:function(t,e){return p(function(t,e){return 0==t.length?0:t.andWithCountBits(e,!0)/t.length}(t,e))},[i.Sokal]:function(t,e){return p(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.andWithCountBits(e,!0);return n/(2*r-3*n)}(t,e))},[i.Hamming]:function(t,e){return t.trueCount()+e.trueCount()-2*t.andWithCountBits(e,!0)},[i.Euclidean]:function(t,e){return Math.sqrt(t.trueCount()+e.trueCount()-2*t.andWithCountBits(e,!0))}},E={[h.TanimotoIntArray]:function(t,e){return p(w(new g(t,32*t.length),new g(e,32*e.length)))}},v={[l.Difference]:function(t,e){return Math.abs(t-e)}},x={[a.Vector]:{[o.Euclidean]:y[o.Euclidean]},[a.String]:{[s.Levenshtein]:M[s.Levenshtein],[s.JaroWinkler]:M[s.JaroWinkler],[s.Manhattan]:M[s.Manhattan],[s.Onehot]:M[s.Onehot]},[a.BitArray]:{[i.Tanimoto]:b[i.Tanimoto],[i.Dice]:b[i.Dice],[i.Asymmetric]:b[i.Asymmetric],[i.BraunBlanquet]:b[i.BraunBlanquet],[i.Cosine]:b[i.Cosine],[i.Kulczynski]:b[i.Kulczynski],[i.McConnaughey]:b[i.McConnaughey],[i.RogotGoldberg]:b[i.RogotGoldberg],[i.Russel]:b[i.Russel],[i.Sokal]:b[i.Sokal]},[a.MacroMolecule]:{[m.U.HAMMING]:m.o[m.U.HAMMING],[m.U.LEVENSHTEIN]:m.o[m.U.LEVENSHTEIN],[m.U.NEEDLEMANN_WUNSCH]:m.o[m.U.NEEDLEMANN_WUNSCH],[m.U.MONOMER_CHEMICAL_DISTANCE]:m.o[m.U.MONOMER_CHEMICAL_DISTANCE]},[a.Number]:{[l.Difference]:v[l.Difference]},[a.IntArray]:{[h.TanimotoIntArray]:E[h.TanimotoIntArray]}},_=Object.keys(x).reduce(((t,e)=>{for(const r of Object.keys(x[e]))t[r]=e;return t}),{});class S{method;dataType;constructor(t){this.method=t,this.dataType=_[t]}getMeasure(t){const e=x;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,_[r]==a.MacroMolecule.toString()?e[this.dataType][this.method](t):e[this.dataType][this.method];var r}static getMetricByDataType(t){return Object.keys(x[t])}static get availableMeasures(){return Object.keys(x)}}var N;!function(t){t.EUCLIDEAN="EUCLIDEAN",t.MANHATTAN="MANHATTAN"}(N||(N={}));const A=t=>null==t;function k(t,e,r,n){if(r>t[t.length-1])return;const s=t.findIndex((t=>r<t));t.pop(),t.splice(s,0,r),e.pop(),e.splice(s,0,n)}class C{_workers;_workerCount;_terminateOnComplete;constructor(t=!0,e=!0){const n=navigator.hardwareConcurrency;this._workerCount=t?Math.max(n-2,1):1,this._workers=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(100),r.b)))),this._terminateOnComplete=e}async calc(t,e,r=!0,n){return new Promise((async(s,o)=>{try{const o=t.length,i=new Array(this._workerCount),h=o*(o-1)/2;this._workerCount=Math.min(this._workerCount,h);const a=h/this._workerCount,l=new Float32Array(h);let u=0,c=1,f=0,g=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const s=Math.floor(r*a),m=r===this._workerCount-1?h:Math.floor((r+1)*a),w=u,p=c;r!==this._workerCount-1&&(u=o-2-Math.floor(Math.sqrt(-8*m+4*o*(o-1)-7)/2-.5),c=m-o*u+Math.floor((u+1)*(u+2)/2)),this._workers[r].postMessage({values:t,fnName:e,startRow:w,startCol:p,chunckSize:m-s,opts:n}),i[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:n,distanceMatrixData:o,min:i,max:h}})=>{this._terminateOnComplete&&this._workers[r].terminate(),n?e(n):(l.set(o,s),i<f&&(f=i),h>g&&(g=h),t())}}))}await Promise.all(i),r&&l.forEach(((t,e)=>{l[e]=(t-f)/(g-f)})),s(l)}catch(t){o(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}function R(t,e){return Math.floor(e()*t)}function I(t){return t()}function F(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function T(t){return F(t).map(((t,e)=>e))}function V(t,e){return F(t).map((()=>e))}function z(t){return V(t,0)}function D(t){return function(t){return t.reduce(((t,e)=>t+e))}(t)/t.length}function B(t){let e=0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e}function O(t,e,r){const n=z(t);for(let s=0;s<t;s++){let t=!0;for(;t;){const o=R(e,r);let i=!1;for(let t=0;t<s;t++)if(o===n[t]){i=!0;break}i||(t=!1),n[s]=o}}return n}function L(t,e,r){const n=[];let s=0,o=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let i=0;i<e;i++){const e=[];for(let n=0;n<r;n++)e.push(t[o]),o+=1;n.push(e),s+=1}return n}function P(t,e){const r=r=>F(t).map((()=>V(e,r))),n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function j(t,e,r){const n=z(t);for(let s=0;s<t;s++){let t=!0,o=0;for(;t;){o=R(e,r);let i=!1;for(let t=0;t<s;t++)if(o===n[t]){i=!0;break}i||(t=!1)}n[s]=o}return n}function q(t,e,r,n,s){e=Math.floor(e);const o=t[0][e],i=t[1][e];if(t[2][e],r>=i[0])return 0;for(let t=0;t<o.length;t++)if(n===o[t])return 0;return $(t,e,r,n,s)}function $(t,e,r,n,s){const o=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,o[0]=n,h[0]=s;let a=0,l=0;for(;;){const e=2*a+1,n=e+1,s=t[0][0].length;if(e>=s)break;if(n>=s){if(!(i[e]>r))break;l=e}else if(i[e]>=i[n]){if(!(r<i[e]))break;l=e}else{if(!(r<i[n]))break;l=n}i[a]=i[l],o[a]=o[l],h[a]=h[l],a=l}return i[a]=r,o[a]=n,h[a]=s,1}function U(t,e,r,n,s){const o=P(e,n);for(let n=0;n<e;n++)for(let e=0;e<r;e++){if(t[0][n][e]<0)continue;const r=t[0][n][e],i=t[2][n][e],h=I(s);q(o,n,h,r,i),q(o,r,h,n,i),t[2][n][e]=0}return o}function W(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const n=e[t],s=r[t];for(let t=0;t<n.length-1;t++){const e=n.length-t-1,r=s.length-t-1,o=n[0];n[0]=n[e],n[e]=o;const i=s[0];s[0]=s[r],s[r]=i,G(s,n,r,0)}}return{indices:e,weights:r}}function G(t,e,r,n){for(;2*n+1<r;){const s=2*n+1,o=s+1;let i=n;if(t[i]<t[s]&&(i=s),o<r&&t[i]<t[o]&&(i=o),i===n)break;{const r=t[n];t[n]=t[i],t[i]=r;const s=e[n];e[n]=e[i],e[i]=s,n=i}}}function H(t,e){const r=t[0][e],n=t[1][e],s=t[2][e];let o=1/0,i=-1;for(let t=0;t>r.length;t++)1===s[t]&&n[t]<o&&(o=n[t],i=t);return i>=0?(s[i]=0,Math.floor(r[i])):-1}class K{entries=new Map;nRows=0;nCols=0;constructor(t,e,r,n){if(t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(let n=0;n<r.length;n++){const s=t[n],o=e[n];this.checkDims(s,o);const i=this.makeKey(s,o);this.entries.set(i,{value:r[n],row:s,col:o})}}makeKey(t,e){return`${t}:${e}`}checkDims(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")}set(t,e,r){this.checkDims(t,e);const n=this.makeKey(t,e);this.entries.has(n)?this.entries.get(n).value=r:this.entries.set(n,{value:r,row:t,col:e})}get(t,e,r=0){const n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).value:r}getAll(t=!0){const e=new Array(this.entries.size).fill(null);let r=0;return this.entries.forEach((t=>{e[r++]=t})),t&&e.sort(((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row)),e}getDims(){return[this.nRows,this.nCols]}getRows(){return Array.from(this.entries,(([t,e])=>e.row))}getCols(){return Array.from(this.entries,(([t,e])=>e.col))}getValues(){return Array.from(this.entries,(([t,e])=>e.value))}forEach(t){this.entries.forEach((e=>t(e.value,e.row,e.col)))}map(t){const e=new Float32Array(this.entries.size);let r=0;this.entries.forEach((n=>{e[r++]=t(n.value,n.row,n.col)}));const n=[this.nRows,this.nCols];return new K(this.getRows(),this.getCols(),e,n)}toArray(){const t=F(this.nRows).map((()=>z(this.nCols)));return this.entries.forEach((e=>{t[e.row][e.col]=e.value})),t}}function Y(t){const e=t.getRows(),r=t.getCols(),n=t.getValues(),s=r.length,o=new Int32Array(s),i=new Int32Array(s),h=new Float32Array(s);o.set(e),i.set(r),h.set(n);const a=[t.nCols,t.nRows];return new K(i,o,h,a)}function X(t,e){return nt(t,e,((t,e)=>t*e))}function Q(t,e){return nt(t,e,((t,e)=>t+e))}function J(t,e){return nt(t,e,((t,e)=>t-e))}function Z(t,e){return t.map((t=>t*e))}function tt(t){const e=new Set,r=t.getValues(),n=t.getRows(),s=t.getCols();for(let t=0;t<r.length;t++)0===r[t]&&e.add(t);const o=(t,r)=>!e.has(r),i=r.filter(o),h=n.filter(o),a=s.filter(o);return new K(h,a,i,t.getDims())}function et(t,e="l2"){const r=rt[e],n=new Map;t.forEach(((t,e,r)=>{const s=n.get(e)||[];s.push(r),n.set(e,s)}));const s=new K([],[],[],t.getDims());for(let e of n.keys()){const o=n.get(e).sort(),i=r(o.map((r=>t.get(e,r))));for(let t=0;t<i.length;t++)s.set(e,o[t],i[t])}return s}const rt={max:t=>{let e=-1/0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map((t=>t/e))},l1:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r];return t.map((t=>t/e))},l2:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r]**2;return t.map((t=>Math.sqrt(t**2/e)))}};function nt(t,e,r){const n=new Set,s=[],o=[],i=[],h=(n,h)=>{s.push(n),o.push(h);const a=r(t.get(n,h),e.get(n,h));i.push(a)},a=t.getValues(),l=t.getRows(),u=t.getCols();for(let t=0;t<a.length;t++){const e=l[t],r=u[t],s=`${e}:${r}`;n.add(s),h(e,r)}const c=e.getValues(),f=e.getRows(),g=e.getCols();for(let t=0;t<c.length;t++){const e=f[t],r=g[t],s=`${e}:${r}`;n.has(s)||h(e,r)}const m=[t.nRows,t.nCols];return new K(s,o,i,m)}function st(t){const e=[];t.forEach(((t,r,n)=>{e.push({value:t,row:r,col:n})})),e.sort(((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row));const r=[],n=[],s=[];let o=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==o&&(o=i,s.push(t)),r.push(h),n.push(a)}return{indices:r,values:n,indptr:s}}class ot{hyperplanes;offsets;children;indices;constructor(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n}}function it(t,e,r,n){const s=Math.max(10,e),o=T(r).map(((e,r)=>function(t,e=30,r,n){return ht(t,T(t.length),e,r,n)}(t,s,r,n))),i=o.map((t=>function(t,e){const r=lt(t),n=ut(t),s=T(r).map((()=>t.hyperplane?1:0)),o=z(r),i=T(r).map((()=>[-1,-1])),h=T(n).map((()=>T(e).map((()=>-1))));return at(t,s,o,i,h,0,0),new ot(s,o,i,h)}(t,s)));return i}function ht(t,e,r=30,n,s){if(e.length>r){const o=function(t,e,r){let n=R(e.length,r),s=R(e.length,r);s+=n===s?1:0,s%=e.length;const o=e[n],i=e[s];let h=0,a=0;a=t[o]-t[i],h-=a*(t[o]+t[i])/2;let l=0,u=0;const c=z(e.length);for(let n=0;n<e.length;n++){let s=h;s+=a*t[e[n]],0===s?(c[n]=R(2,r),0===c[n]?l+=1:u+=1):s>0?(c[n]=0,l+=1):(c[n]=1,u+=1)}const f=z(l),g=z(u);l=0,u=0;for(let t=0;t<c.length;t++)0===c[t]?(f[l]=e[t],l+=1):(g[u]=e[t],u+=1);return{indicesLeft:f,indicesRight:g,hyperplane:a,offset:h}}(t,e,s),{indicesLeft:i,indicesRight:h,hyperplane:a,offset:l}=o;return{leftChild:ht(t,i,r,n+1,s),rightChild:ht(t,h,r,n+1,s),isLeaf:!1,hyperplane:a,offset:l}}return{indices:e,isLeaf:!0}}function at(t,e,r,n,s,o,i){if(t.isLeaf)return n[o][0]=-i,s[i].splice(0,t.indices.length,...t.indices),{nodeNum:o,leafNum:i+=1};{e[o]=t.hyperplane,r[o]=t.offset,n[o][0]=o+1;const h=o;let a=at(t.leftChild,e,r,n,s,o+1,i);return o=a.nodeNum,i=a.leafNum,n[h][1]=o+1,a=at(t.rightChild,e,r,n,s,o+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function lt(t){return t.isLeaf?1:1+lt(t.leftChild)+lt(t.rightChild)}function ut(t){return t.isLeaf?1:ut(t.leftChild)+ut(t.rightChild)}function ct(t,e,r,n){let s=e;return s+=t*r,0===s?R(2,n):s>0?0:1}function ft(t,e,r){let n=0;for(;e.children[n][0]>0;)n=0===ct(e.hyperplanes[n],e.offsets[n],t,r)?e.children[n][0]:e.children[n][1];const s=-1*e.children[n][0];return e.indices[s]}const gt=Object.prototype.toString;function mt(t){return gt.call(t).endsWith("Array]")}function wt(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 pt=Object.prototype.toString;function dt(t){return pt.call(t).endsWith("Array]")}const yt=Object.prototype.toString;function Mt(t){return yt.call(t).endsWith("Array]")}const bt=Object.prototype.toString;const Et=Object.prototype.toString;function vt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Mt(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(!Mt(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,!Et.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var n=r.fromIndex,s=void 0===n?0:n,o=r.toIndex,i=void 0===o?t.length:o;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=s||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[s],a=s+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!bt.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var n=r.fromIndex,s=void 0===n?0:n,o=r.toIndex,i=void 0===o?t.length:o;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=s||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[s],a=s+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(n===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var o=r.min,i=void 0===o?r.autoMinMax?n:0:o,h=r.max,a=void 0===h?r.autoMinMax?s:1:h;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-i)/(s-n),u=0;u<t.length;u++)e[u]=(t[u]-n)*l+i;return e}const xt=" ".repeat(2),_t=" ".repeat(4);function St(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:s=8,padMinus:o="auto"}=e;return`${t.constructor.name} {\n${xt}[\n${_t}${function(t,e,r,n,s){const{rows:o,columns:i}=t,h=Math.min(o,e),a=Math.min(i,r),l=[];if("auto"===s){s=!1;t:for(let e=0;e<h;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let o=0;o<a;o++)r.push(Nt(t.get(e,o),n,s));l.push(`${r.join(" ")}`)}return a!==i&&(l[l.length-1]+=` ... ${i-r} more columns`),h!==o&&l.push(`... ${o-e} more rows`),l.join(`\n${_t}`)}(t,r,n,s,o)}\n${xt}]\n${xt}rows: ${t.rows}\n${xt}columns: ${t.columns}\n}`}function Nt(t,e,r){return(t>=0&&r?` ${At(t,e-1)}`:At(t,e)).padEnd(e)}function At(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 kt(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 Ct(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 Rt(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 It(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 Ft(t,e,r,n,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(Vt("startRow",e),Vt("endRow",r),Vt("startColumn",n),Vt("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 Tt(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function Vt(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function zt(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class Dt{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new Ot(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 Ot(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 Ot(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 Ot(t,e)}static ones(t,e){return new Ot(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 Ot(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,n());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:o=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let i=s-n,h=new Ot(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(o()*i);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<n;t++)s.set(t,t,r);return s}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let s=Math.min(n,e,r),o=this.zeros(e,r);for(let e=0;e<s;e++)o.set(e,e,t[e]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new Ot(r,n);for(let o=0;o<r;o++)for(let r=0;r<n;r++)s.set(o,r,Math.min(t.get(o,r),e.get(o,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let o=0;o<r;o++)for(let r=0;r<n;r++)s.set(o,r,Math.max(t.get(o,r),e.get(o,r)));return s}static checkMatrix(t){return Dt.isMatrix(t)?t:new Ot(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/s);for(let n=e+1;n<t.rows;n++){let s=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let o=r+1;o<t.columns;o++)t.set(n,o,t.get(n,o)-t.get(e,o)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let s=0,o=!1;for(;s<r&&!1===o;)1===t.get(n,s)?o=!0:s++;for(let r=0;r<n;r++){let o=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-o*t.get(n,i);t.set(r,i,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new Ot(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){kt(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Ot.rowVector(this.getRow(t))}setRow(t,e){kt(this,t),e=Rt(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){kt(this,t),kt(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){Ct(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Ot.columnVector(this.getColumn(t))}setColumn(t,e){Ct(this,t),e=It(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){Ct(this,t),Ct(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=Rt(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=Rt(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=Rt(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=Rt(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=It(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=It(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=It(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=It(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){kt(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){Ct(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(){zt(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(){zt(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(kt(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){kt(this,t),zt(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(kt(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){kt(this,t),zt(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(Ct(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){Ct(this,t),zt(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(Ct(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){Ct(this,t),zt(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){Dt.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=Ot.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new Ot(e,n),o=new Float64Array(r);for(let i=0;i<n;i++){for(let e=0;e<r;e++)o[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*o[n];s.set(t,i,e)}}return s}strassen2x2(t){t=Ot.checkMatrix(t);let e=new Ot(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),o=t.get(0,1),i=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(n+l),c=(i+a)*n,f=r*(o-l),g=a*(h-n),m=(r+s)*l,w=u+g-m+(s-a)*(h+l),p=f+m,d=c+g,y=u-c+f+(i-r)*(n+o);return e.set(0,0,w),e.set(0,1,p),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=Ot.checkMatrix(t);let e=new Ot(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),o=this.get(1,0),i=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=t.get(0,1),g=t.get(0,2),m=t.get(1,0),w=t.get(1,1),p=t.get(1,2),d=t.get(2,0),y=t.get(2,1),M=t.get(2,2),b=(r-o)*(-f+w),E=(-r+o+i)*(c-f+w),v=(o+i)*(-c+f),x=r*c,_=(-r+a+l)*(c-g+p),S=(-r+a)*(g-p),N=(a+l)*(-c+g),A=(-s+l+u)*(w+d-y),k=(s-u)*(w-y),C=s*d,R=(l+u)*(-d+y),I=(-s+i+h)*(p+d-M),F=(s-h)*(p-M),T=(i+h)*(-d+M),V=x+C+n*m,z=(r+n+s-o-i-l-u)*w+E+v+x+A+C+R,D=x+_+N+(r+n+s-i-h-a-l)*p+C+I+T,B=b+i*(-c+f+m-w-p-d+M)+E+x+C+I+F,O=b+E+v+x+h*y,L=C+I+F+T+o*g,P=x+_+S+l*(-c+g+m-w-p-d+y)+A+k+C,j=A+k+C+R+a*f,q=x+_+S+N+u*M;return e.set(0,0,V),e.set(0,1,z),e.set(0,2,D),e.set(1,0,B),e.set(1,1,O),e.set(1,2,L),e.set(2,0,P),e.set(2,1,j),e.set(2,2,q),e}mmulStrassen(t){t=Ot.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,o=t.columns;function i(t,e,r){let n=t.rows,s=t.columns;if(n===e&&s===r)return t;{let n=Dt.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${o} matrix: dimensions do not match.`);let h=Math.max(r,s),a=Math.max(n,o);return e=i(e,h,a),function t(e,r,n,s){if(n<=512||s<=512)return e.mmul(r);n%2==1&&s%2==1?(e=i(e,n+1,s+1),r=i(r,n+1,s+1)):n%2==1?(e=i(e,n+1,s),r=i(r,n+1,s)):s%2==1&&(e=i(e,n,s+1),r=i(r,n,s+1));let o=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,o-1,0,h-1),l=r.subMatrix(0,o-1,0,h-1),u=e.subMatrix(0,o-1,h,e.columns-1),c=r.subMatrix(0,o-1,h,r.columns-1),f=e.subMatrix(o,e.rows-1,0,h-1),g=r.subMatrix(o,r.rows-1,0,h-1),m=e.subMatrix(o,e.rows-1,h,e.columns-1),w=r.subMatrix(o,r.rows-1,h,r.columns-1),p=t(Dt.add(a,m),Dt.add(l,w),o,h),d=t(Dt.add(f,m),l,o,h),y=t(a,Dt.sub(c,w),o,h),M=t(m,Dt.sub(g,l),o,h),b=t(Dt.add(a,u),w,o,h),E=t(Dt.sub(f,a),Dt.add(l,c),o,h),v=t(Dt.sub(u,m),Dt.add(g,w),o,h),x=Dt.add(p,M);x.sub(b),x.add(v);let _=Dt.add(y,b),S=Dt.add(d,M),N=Dt.sub(p,d);N.add(y),N.add(E);let A=Dt.zeros(2*x.rows,2*x.columns);return A=A.setSubMatrix(x,0,0),A=A.setSubMatrix(_,x.rows,0),A=A.setSubMatrix(S,0,x.columns),A=A.setSubMatrix(N,x.rows,x.columns),A.subMatrix(0,n-1,0,s-1)}(e,t=i(t,h,a),h,a)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new Ot(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&vt(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 Ot(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&vt(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=Ot.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,o=new Ot(e*n,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let h=0;h<s;h++)o.set(n*i+r,s*e+h,this.get(i,e)*t.get(r,h));return o}kroneckerSum(t){if(t=Ot.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(Ot.eye(r,r)),s=Ot.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new Ot(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=Bt){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=Bt){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Ft(this,t,e,r,n);let s=new Ot(e-t+1,n-r+1);for(let o=t;o<=e;o++)for(let e=r;e<=n;e++)s.set(o-t,e-r,this.get(o,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new Ot(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let o=e;o<=r;o++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,o-e,this.get(t[s],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new Ot(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let o=e;o<=r;o++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(o-e,s,this.get(o,t[s]))}return n}setSubMatrix(t,e,r){if((t=Ot.checkMatrix(t)).isEmpty())return this;Ft(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(!dt(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(!dt(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 Ot(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let t=0;t<e.length;t++){let o=e[t];r.set(n,t,this.get(s,o))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Ot(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=Tt(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=Tt(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=Tt(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=Tt(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(!dt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,o=[];for(let i=0;i<n;i++){let n=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(i,e)-r[i],n+=a,h+=a*a;e?o.push((h-n*n/s)/(s-1)):o.push((h-n*n/s)/s)}return o}(this,r,n);case"column":if(!dt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,o=[];for(let i=0;i<s;i++){let s=0,h=0,a=0;for(let e=0;e<n;e++)a=t.get(e,i)-r[i],s+=a,h+=a*a;e?o.push((h-s*s/n)/(n-1)):o.push((h-s*s/n)/n)}return o}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,s=t.columns,o=n*s;let i=0,h=0,a=0;for(let e=0;e<n;e++)for(let n=0;n<s;n++)a=t.get(e,n)-r,i+=a,h+=a*a;return e?(h-i*i/o)/(o-1):(h-i*i/o)/o}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!dt(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(!dt(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(!dt(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(!dt(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 St(this,t)}}function Bt(t,e){return t-e}Dt.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Dt.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return St(this)}),Dt.random=Dt.rand,Dt.randomInt=Dt.randInt,Dt.diagonal=Dt.diag,Dt.prototype.diagonal=Dt.prototype.diag,Dt.identity=Dt.eye,Dt.prototype.negate=Dt.prototype.neg,Dt.prototype.tensorProduct=Dt.prototype.kroneckerProduct;class Ot extends Dt{constructor(t,e){if(super(),Ot.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(!dt(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 kt(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),kt(this,t,!0),e=Float64Array.from(Rt(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){Ct(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),Ct(this,t,!0),e=It(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}}(Dt,Ot);class Lt extends Dt{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 Pt{constructor(t){let e,r,n,s,o,i,h,a,l,u=(t=Lt.checkMatrix(t)).clone(),c=u.rows,f=u.columns,g=new Float64Array(c),m=1;for(e=0;e<c;e++)g[e]=e;for(a=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)a[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),o=0,n=0;n<l;n++)o+=u.get(e,n)*a[n];a[e]-=o,u.set(e,r,a[e])}for(s=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[s])&&(s=e);if(s!==r){for(n=0;n<f;n++)i=u.get(s,n),u.set(s,n,u.get(r,n)),u.set(r,n,i);h=g[s],g[s]=g[r],g[r]=h,m=-m}if(r<c&&0!==u.get(r,r))for(e=r+1;e<c;e++)u.set(e,r,u.get(e,r)/u.get(r,r))}this.LU=u,this.pivotVector=g,this.pivotSign=m}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=Ot.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let r,n,s,o=t.columns,i=t.subMatrixRow(this.pivotVector,0,o-1),h=e.columns;for(s=0;s<h;s++)for(r=s+1;r<h;r++)for(n=0;n<o;n++)i.set(r,n,i.get(r,n)-i.get(s,n)*e.get(r,s));for(s=h-1;s>=0;s--){for(n=0;n<o;n++)i.set(s,n,i.get(s,n)/e.get(s,s));for(r=0;r<s;r++)for(n=0;n<o;n++)i.set(r,n,i.get(r,n)-i.get(s,n)*e.get(r,s))}return i}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new Ot(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 Ot(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 jt(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 qt{constructor(t){let e,r,n,s,o=(t=Lt.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(n=0;n<h;n++){let t=0;for(e=n;e<i;e++)t=jt(t,o.get(e,n));if(0!==t){for(o.get(n,n)<0&&(t=-t),e=n;e<i;e++)o.set(e,n,o.get(e,n)/t);for(o.set(n,n,o.get(n,n)+1),r=n+1;r<h;r++){for(s=0,e=n;e<i;e++)s+=o.get(e,n)*o.get(e,r);for(s=-s/o.get(n,n),e=n;e<i;e++)o.set(e,r,o.get(e,r)+s*o.get(e,n))}}a[n]=-t}this.QR=o,this.Rdiag=a}solve(t){t=Ot.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n,s,o,i,h=t.columns,a=t.clone(),l=e.columns;for(o=0;o<l;o++)for(s=0;s<h;s++){for(i=0,n=o;n<r;n++)i+=e.get(n,o)*a.get(n,s);for(i=-i/e.get(o,o),n=o;n<r;n++)a.set(n,s,a.get(n,s)+i*e.get(n,o))}for(o=l-1;o>=0;o--){for(s=0;s<h;s++)a.set(o,s,a.get(o,s)/this.Rdiag[o]);for(n=0;n<o;n++)for(s=0;s<h;s++)a.set(n,s,a.get(n,s)-a.get(o,s)*e.get(n,o))}return a.subMatrix(0,l-1,0,h-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,n=r.columns,s=new Ot(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)t<e?s.set(t,e,r.get(t,e)):t===e?s.set(t,e,this.Rdiag[t]):s.set(t,e,0);return s}get orthogonalMatrix(){let t,e,r,n,s=this.QR,o=s.rows,i=s.columns,h=new Ot(o,i);for(r=i-1;r>=0;r--){for(t=0;t<o;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<i;e++)if(0!==s.get(r,r)){for(n=0,t=r;t<o;t++)n+=s.get(t,r)*h.get(t,e);for(n=-n/s.get(r,r),t=r;t<o;t++)h.set(t,e,h.get(t,e)+n*s.get(t,r))}}return h}}class $t{constructor(t,e={}){if((t=Lt.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:o=!0,autoTranspose:i=!1}=e;let h,a=Boolean(s),l=Boolean(o),u=!1;if(r<n)if(i){h=t.transpose(),r=h.rows,n=h.columns,u=!0;let e=a;a=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new Ot(r,c),w=new Ot(n,n),p=new Float64Array(n),d=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let M=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),E=Math.max(M,b);for(let t=0;t<E;t++){if(t<M){g[t]=0;for(let e=t;e<r;e++)g[t]=jt(g[t],h.get(e,t));if(0!==g[t]){h.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/g[t]);h.set(t,t,h.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<n;e++){if(t<M&&0!==g[t]){let n=0;for(let s=t;s<r;s++)n+=h.get(s,t)*h.get(s,e);n=-n/h.get(t,t);for(let s=t;s<r;s++)h.set(s,e,h.get(s,e)+n*h.get(s,t))}p[e]=h.get(t,e)}if(a&&t<M)for(let e=t;e<r;e++)m.set(e,t,h.get(e,t));if(t<b){p[t]=0;for(let e=t+1;e<n;e++)p[t]=jt(p[t],p[e]);if(0!==p[t]){p[t+1]<0&&(p[t]=0-p[t]);for(let e=t+1;e<n;e++)p[e]/=p[t];p[t+1]+=1}if(p[t]=-p[t],t+1<r&&0!==p[t]){for(let e=t+1;e<r;e++)d[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)d[e]+=p[r]*h.get(e,r);for(let e=t+1;e<n;e++){let n=-p[e]/p[t+1];for(let s=t+1;s<r;s++)h.set(s,e,h.get(s,e)+n*d[s])}}if(l)for(let e=t+1;e<n;e++)w.set(e,t,p[e])}}let v=Math.min(n,r+1);if(M<n&&(g[M]=h.get(M,M)),r<v&&(g[v-1]=0),b+1<v&&(p[b]=h.get(b,v-1)),p[v-1]=0,a){for(let t=M;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=M-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+=w.get(s,t)*w.get(s,e);r=-r/w.get(t+1,t);for(let s=t+1;s<n;s++)w.set(s,e,w.get(s,e)+r*w.get(s,t))}for(let e=0;e<n;e++)w.set(e,t,0);w.set(t,t,1)}let x=v-1,_=0,S=Number.EPSILON;for(;v>0;){let t,e;for(t=v-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(p[t])<=e||Number.isNaN(p[t])){p[t]=0;break}}if(t===v-2)e=4;else{let r;for(r=v-1;r>=t&&r!==t;r--){let e=(r!==v?Math.abs(p[r]):0)+(r!==t+1?Math.abs(p[r-1]):0);if(Math.abs(g[r])<=S*e){g[r]=0;break}}r===t?e=3:r===v-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=p[v-2];p[v-2]=0;for(let r=v-2;r>=t;r--){let s=jt(g[r],e),o=g[r]/s,i=e/s;if(g[r]=s,r!==t&&(e=-i*p[r-1],p[r-1]=o*p[r-1]),l)for(let t=0;t<n;t++)s=o*w.get(t,r)+i*w.get(t,v-1),w.set(t,v-1,-i*w.get(t,r)+o*w.get(t,v-1)),w.set(t,r,s)}break}case 2:{let e=p[t-1];p[t-1]=0;for(let n=t;n<v;n++){let s=jt(g[n],e),o=g[n]/s,i=e/s;if(g[n]=s,e=-i*p[n],p[n]=o*p[n],a)for(let e=0;e<r;e++)s=o*m.get(e,n)+i*m.get(e,t-1),m.set(e,t-1,-i*m.get(e,n)+o*m.get(e,t-1)),m.set(e,n,s)}break}case 3:{const e=Math.max(Math.abs(g[v-1]),Math.abs(g[v-2]),Math.abs(p[v-2]),Math.abs(g[t]),Math.abs(p[t])),s=g[v-1]/e,o=g[v-2]/e,i=p[v-2]/e,h=g[t]/e,u=p[t]/e,c=((o+s)*(o-s)+i*i)/2,f=s*i*(s*i);let d=0;0===c&&0===f||(d=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),d=f/(c+d));let y=(h+s)*(h-s)+d,M=h*u;for(let e=t;e<v-1;e++){let s=jt(y,M);0===s&&(s=Number.MIN_VALUE);let o=y/s,i=M/s;if(e!==t&&(p[e-1]=s),y=o*g[e]+i*p[e],p[e]=o*p[e]-i*g[e],M=i*g[e+1],g[e+1]=o*g[e+1],l)for(let t=0;t<n;t++)s=o*w.get(t,e)+i*w.get(t,e+1),w.set(t,e+1,-i*w.get(t,e)+o*w.get(t,e+1)),w.set(t,e,s);if(s=jt(y,M),0===s&&(s=Number.MIN_VALUE),o=y/s,i=M/s,g[e]=s,y=o*p[e]+i*g[e+1],g[e+1]=-i*p[e]+o*g[e+1],M=i*p[e+1],p[e+1]=o*p[e+1],a&&e<r-1)for(let t=0;t<r;t++)s=o*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+o*m.get(t,e+1)),m.set(t,e,s)}p[v-2]=y,_+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=x;e++)w.set(e,t,-w.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=w.get(r,t+1),w.set(r,t+1,w.get(r,t)),w.set(r,t,e);if(a&&t<r-1)for(let n=0;n<r;n++)e=m.get(n,t+1),m.set(n,t+1,m.get(n,t)),m.set(n,t,e);t++}_=0,v--}}if(u){let t=w;w=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=w}solve(t){let e=t,r=this.threshold,n=this.s.length,s=Ot.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let o=this.U,i=this.rightSingularVectors,h=i.mmul(s),a=i.rows,l=o.rows,u=Ot.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let s=0;s<n;s++)r+=h.get(t,s)*o.get(e,s);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(Ot.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new Ot(r,this.s.length);for(let o=0;o<r;o++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&s.set(o,r,t.get(o,r)/this.s[r]);let o=this.U,i=o.rows,h=o.columns,a=new Ot(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let n=0;n<h;n++)r+=s.get(t,n)*o.get(e,n);a.set(t,e,r)}return a}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Ot.diag(this.s)}}function Ut(t,e,r,n,s){let o=r*n*n,i=Ot.eye(e.length,e.length,o);const h=s(e);let a=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)a[e]=h(t.x[e]);let l=function(t,e,r,n,s){const o=r.length,i=t.x.length;let h=new Array(o);for(let a=0;a<o;a++){h[a]=new Array(i);let o=r.slice();o[a]+=n;let l=s(o);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new Ot(h)}(t,a,e,n,s),u=function(t,e){const r=t.x.length;let n=new Array(r);for(let s=0;s<r;s++)n[s]=[t.y[s]-e[s]];return new Ot(n)}(t,a),c=function(t,e=!1){return t=Lt.checkMatrix(t),e?new $t(t).inverse():function(t,e,r=!1){return t=Lt.checkMatrix(t),e=Lt.checkMatrix(e),r?new $t(t).solve(e):t.isSquare()?new Pt(t).solve(e):new qt(t).solve(e)}(t,Ot.eye(t.rows))}(i.add(l.mmul(l.transpose())));return(e=(e=new Ot([e])).sub(c.mmul(l).mmul(u).mul(n).transpose())).to1DArray()}const Wt=1e-5,Gt=.001;class Ht{learningRate=1;localConnectivity=1;minDist=.1;nComponents=2;nEpochs=0;nNeighbors=15;negativeSampleRate=5;random=Math.random;repulsionStrength=1;setOpMixRatio=1;spread=1;transformQueueSize=4;targetMetric="categorical";targetWeight=.5;targetNNeighbors=this.nNeighbors;distanceFn=Kt;knnIndices;knnDistances;graph;X;isInitialized=!1;rpForest=[];initFromRandom;initFromTree;search;searchGraph;Y;embedding=[];optimizationState=new Yt;get neighbors(){return this.nNeighbors}constructor(t={}){const e=e=>{void 0!==t[e]&&(this[e]=t[e])};e("distanceFn"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize")}fit(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding}async fitAsync(t,e=(()=>!0)){return this.initializeFit(t),await this.optimizeLayoutAsync(e),this.embedding}setSupervisedProjection(t,e={}){this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors}setPrecomputedKNN(t,e){this.knnIndices=t,this.knnDistances=e}initializeFit(t){if(t.length<=this.nNeighbors)throw new Error(`Not enough data points (${t.length}) to create nNeighbors: ${this.nNeighbors}. Add more data points or adjust the configuration.`);if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){const e=this.nearestNeighbors(t);this.knnIndices=e.knnIndices,this.knnDistances=e.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();const{head:e,tail:r,epochsPerSample:n}=this.initializeSimplicialSetEmbedding();return this.optimizationState.head=e,this.optimizationState.tail=r,this.optimizationState.epochsPerSample=n,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()}makeSearchFns(){const{initFromTree:t,initFromRandom:e}=(r=this.distanceFn,{initFromRandom:function(t,e,n,s,o){for(let i=0;i<n.length;i++){const h=O(t,e.length,o);for(let t=0;t<h.length;t++)h[t]<0||q(s,i,r(e[h[t]],n[i]),h[t],1)}},initFromTree:function(t,e,n,s,o){for(let i=0;i<n.length;i++){const h=ft(n[i],t,o);for(let t=0;t<h.length;t++){if(h[t]<0)return;q(s,i,r(e[h[t]],n[i]),h[t],1)}}}});var r;this.initFromTree=t,this.initFromRandom=e,this.search=function(t){return function(e,r,n,s){const{indices:o,indptr:i}=st(r);for(let r=0;r<s.length;r++){const h=new Set(n[0][r]);for(;;){const a=H(n,r);if(-1===a)break;const l=o.slice(i[a],i[a+1]);for(const o of l)o===a||-1===o||h.has(o)||($(n,r,t(e[o],s[r]),o,1),h.add(o))}}return n}}(this.distanceFn)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],s=new K([],[],[],n);for(let t=0;t<e.length;t++){const n=e[t],o=r[t];for(let e=0;e<n.length;e++){const r=n[e],i=o[e];i>0&&s.set(t,r,i)}}return nt(s,Y(s),((t,e)=>t>e?t:e))}transform(t){const e=this.X;if(void 0===e||0===e.length)throw new Error("No data has been fit.");let r=Math.floor(this.nNeighbors*this.transformQueueSize);r=Math.min(e.length,r);const n=function(t,e,r,n,s,o,i){const h=P(r.length,n);if(s(n,e,r,h,i),t)for(let n of t)o(n,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),s=this.search(e,this.searchGraph,n,t);let{indices:o,weights:i}=W(s);o=o.map((t=>t.slice(0,this.nNeighbors))),i=i.map((t=>t.slice(0,this.nNeighbors)));const h=Math.max(0,this.localConnectivity-1),{sigmas:a,rhos:l}=this.smoothKNNDistance(i,this.nNeighbors,h),{rows:u,cols:c,vals:f}=this.computeMembershipStrengths(o,i,a,l),g=[t.length,e.length];let m=new K(u,c,f,g);const w=st(et(m,"l1")),p=t.length,d=function(t,e,r){const n=z(t.length).map((t=>z(r[0].length)));for(let s=0;s<t.length;s++)for(let o=0;o<t[0].length;o++)for(let i=0;i<r[0].length;i++){const h=t[s][o];n[s][i]+=e[s][o]*r[h][i]}return n}(L(w.indices,p,this.nNeighbors),L(w.values,p,this.nNeighbors),this.embedding),y=this.nEpochs?this.nEpochs/3:m.nRows<=1e4?100:30,M=m.getValues().reduce(((t,e)=>e>t?e:t),0);m=m.map((t=>t<M/y?0:t)),m=tt(m);const b=this.makeEpochsPerSample(m.getValues(),y),E=m.getRows(),v=m.getCols();return this.assignOptimizationStateParameters({headEmbedding:d,tailEmbedding:this.embedding,head:E,tail:v,currentEpoch:0,nEpochs:y,nVertices:m.getDims()[1],epochsPerSample:b}),this.prepareForOptimizationLoop(),this.optimizeLayout()}processGraphForSupervisedProjection(){const{Y:t,X:e}=this;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){const e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}}step(){const{currentEpoch:t}=this.optimizationState;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch}getEmbedding(){return this.embedding}nearestNeighbors(t){const{distanceFn:e,nNeighbors:r}=this,n=function(t,e){return function(r,n,s,o=10,i=50,h=.001,a=.5,l=!0){const u=r.length,c=P(r.length,s);for(let n=0;n<r.length;n++){const o=j(s,r.length,e);for(let e=0;e<o.length;e++){const s=t(r[n],r[o[e]]);q(c,n,s,o[e],1),q(c,o[e],s,n,1)}}if(l)for(let e=0;e<n.length;e++)for(let s=0;s<n[e].length&&!(n[e][s]<0);s++)for(let o=s+1;o<n[e].length&&!(n[e][o]<0);o++){const i=t(r[n[e][s]],r[n[e][o]]);q(c,n[e][s],i,n[e][o],1),q(c,n[e][o],i,n[e][s],1)}for(let n=0;n<o;n++){const n=U(c,u,s,i,e);let o=0;for(let s=0;s<u;s++)for(let h=0;h<i;h++){let l=Math.floor(n[0][s][h]);if(!(l<0||I(e)<a))for(let e=0;e<i;e++){const i=Math.floor(n[0][s][e]),a=n[2][s][h],u=n[2][s][e];if(i<0||!a&&!u)continue;const f=t(r[l],r[i]);o+=q(c,l,f,i,1),o+=q(c,i,f,l,1)}}if(o<=h*s*r.length)break}return W(c)}}(e,this.random),s=5+Math.floor(.5==(o=t.length**.5/20)?0:Math.round(o));var o;const i=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));this.rpForest=it(t,r,s,this.random);const h=function(t){if(t.length>0){const e=[];for(let r of t)e.push(...r.indices);return e}return[[-1]]}(this.rpForest),{indices:a,weights:l}=n(t,h,r,i);return{knnIndices:a,knnDistances:l}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:n=[],knnDistances:s=[],localConnectivity:o}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(s,e,o),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(n,s,i,h),c=[t.length,t.length],f=new K(a,l,u,c),g=Y(f),m=X(f,g),w=J(Q(f,g),m);return Q(Z(w,r),Z(m,1-r))}categoricalSimplicialSetIntersection(t,e,r,n=1){let s=function(t,e,r=1,n=5){return t.map(((t,s,o)=>-1===e[s]||-1===e[o]?t*Math.exp(-r):e[s]!==e[o]?t*Math.exp(-n):t))}(t,e,n,r);return s=tt(s),function(t){const e=Y(t=et(t,"max"));return tt(t=Q(t,J(e,X(e,t))))}(s)}smoothKNNDistance(t,e,r=1,n=64,s=1){const o=Math.log(e)/Math.log(2)*s,i=z(t.length),h=z(t.length);for(let e=0;e<t.length;e++){let s=0,a=1/0,l=1;const u=t[e],c=u.filter((t=>t>0));if(c.length>=r){let t=Math.floor(r),n=r-t;t>0?(i[e]=c[t-1],n>Wt&&(i[e]+=n*(c[t]-c[t-1]))):i[e]=n*c[0]}else c.length>0&&(i[e]=B(c));for(let r=0;r<n;r++){let r=0;for(let n=1;n<t[e].length;n++){const s=t[e][n]-i[e];r+=s>0?Math.exp(-s/l):1}if(Math.abs(r-o)<Wt)break;r>o?(a=l,l=(s+a)/2):(s=l,a===1/0?l*=2:l=(s+a)/2)}if(h[e]=l,i[e]>0){const t=D(u);h[e]<Gt*t&&(h[e]=Gt*t)}else{const r=D(t.map(D));h[e]<Gt*r&&(h[e]=Gt*r)}}return{sigmas:h,rhos:i}}computeMembershipStrengths(t,e,r,n){const s=t.length,o=t[0].length,i=z(s*o),h=z(s*o),a=z(s*o);for(let l=0;l<s;l++)for(let s=0;s<o;s++){let u=0;-1!==t[l][s]&&(u=t[l][s]===l?0:e[l][s]-n[l]<=0?1:Math.exp(-(e[l][s]-n[l])/r[l]),i[l*o+s]=l,h[l*o+s]=t[l][s],a[l*o+s]=u)}return{rows:i,cols:h,vals:a}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:e}=this,r=this.graph.getValues();let n=0;for(let t=0;t<r.length;t++){const e=r[t];n<r[t]&&(n=e)}const s=this.graph.map((e=>e<n/t?0:e));this.embedding=z(s.nRows).map((()=>z(e).map((()=>20*I(this.random)-10))));const o=[],i=[],h=[],a=s.getAll();for(let t=0;t<a.length;t++){const e=a[t];e.value&&(o.push(e.value),h.push(e.row),i.push(e.col))}return{head:i,tail:h,epochsPerSample:this.makeEpochsPerSample(o,t)}}makeEpochsPerSample(t,e){const r=V(t.length,-1),n=B(t),s=t.map((t=>t/n*e));return s.forEach(((t,n)=>{t>0&&(r[n]=e/s[n])})),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:n,headEmbedding:s,tailEmbedding:o}=this.optimizationState,i=s[0].length,h=s.length===o.length,a=n.map((t=>t/r)),l=[...a],u=[...n];this.assignOptimizationStateParameters({epochOfNextSample:u,epochOfNextNegativeSample:l,epochsPerNegativeSample:a,moveOther:h,initialAlpha:e,alpha:e,gamma:t,dim:i})}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:n,epochsPerSample:s}=this.optimizationState,o=this.getNEpochs(),i=this.graph.nCols,{a:h,b:a}=function(t,e){const r=function(t,e,r){return F(300).map(((t,r)=>0+r*((e-0)/299)))}(0,3*t).map((t=>t<e?1:t)),n=z(r.length).map(((n,s)=>r[s]>=e?Math.exp(-(r[s]-e)/t):n)),s={x:r,y:n},{parameterValues:o}=function(t,e,r={}){let{maxIterations:n=100,gradientDifference:s=.1,damping:o=0,errorTolerance:i=.01,minValues:h,maxValues:a,initialValues:l}=r;if(o<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!mt(t.x)||t.x.length<2||!mt(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");let u=l||new Array(e.length).fill(1),c=u.length;if(a=a||new Array(c).fill(Number.MAX_SAFE_INTEGER),h=h||new Array(c).fill(Number.MIN_SAFE_INTEGER),a.length!==h.length)throw new Error("minValues and maxValues must be the same size");if(!mt(u))throw new Error("initialValues must be an array");let f,g=wt(t,u,e),m=g<=i;for(f=0;f<n&&!m;f++){u=Ut(t,u,o,s,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(g=wt(t,u,e),isNaN(g))break;m=g<=i}return{parameterValues:u,parameterError:g,iterations:f}}(s,(([t,e])=>r=>1/(1+t*r**(2*e))),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[i,h]=o;return{a:i,b:h}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:n,epochsPerSample:s,a:h,b:a,nEpochs:o,nVertices:i})}optimizeLayoutStep(t){const{optimizationState:e}=this,{head:r,tail:n,headEmbedding:s,tailEmbedding:o,epochsPerSample:i,epochOfNextSample:h,epochOfNextNegativeSample:a,epochsPerNegativeSample:l,moveOther:u,initialAlpha:c,alpha:f,gamma:g,a:m,b:w,dim:p,nEpochs:d,nVertices:y}=e;for(let e=0;e<i.length;e++){if(h[e]>t)continue;const c=r[e],d=n[e],M=s[c],b=o[d],E=Qt(M,b);let v=0;E>0&&(v=-2*m*w*Math.pow(E,w-1),v/=m*Math.pow(E,w)+1);for(let t=0;t<p;t++){const e=Xt(v*(M[t]-b[t]),4);M[t]+=e*f,u&&(b[t]+=-e*f)}h[e]+=i[e];const x=Math.floor((t-a[e])/l[e]);for(let t=0;t<x;t++){const t=R(y,this.random),e=o[t],r=Qt(M,e);let n=0;if(r>0)n=2*g*w,n/=(.001+r)*(m*Math.pow(r,w)+1);else if(c===t)continue;for(let t=0;t<p;t++){let r=4;n>0&&(r=Xt(n*(M[t]-e[t]),4)),M[t]+=r*f}}a[e]+=x*l[e]}return e.alpha=c*(1-t/d),e.currentEpoch+=1,s}optimizeLayoutAsync(t=(()=>!0)){return new Promise(((e,r)=>{const n=async()=>{try{const{nEpochs:r,currentEpoch:s}=this.optimizationState;this.embedding=this.optimizeLayoutStep(s);const o=this.optimizationState.currentEpoch,i=!1===t(o),h=o===r;if(i||h)return e(h);setTimeout((()=>n()),0)}catch(t){r(t)}};setTimeout((()=>n()),0)}))}optimizeLayout(t=(()=>!0)){let e=!1,r=[];for(;!e;){const{nEpochs:n,currentEpoch:s}=this.optimizationState;r=this.optimizeLayoutStep(s);const o=this.optimizationState.currentEpoch,i=!1===t(o);e=o===n||i}return r}getNEpochs(){const t=this.graph;if(this.nEpochs>0)return this.nEpochs;if(!t)return 200;const e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200}}function Kt(t,e){return Math.abs(t-e)}class Yt{currentEpoch=0;headEmbedding=[];tailEmbedding=[];head=[];tail=[];epochsPerSample=[];epochOfNextSample=[];epochOfNextNegativeSample=[];epochsPerNegativeSample=[];moveOther=!0;initialAlpha=1;alpha=1;gamma=1;a=1.5769434603113077;b=.8950608779109733;dim=2;nEpochs=500;nVertices=0}function Xt(t,e){return t>e?e:t<-e?-e:t}function Qt(t,e){let r=0;for(let n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}class Jt{_workerCount;constructor(){this._workerCount=Math.max(navigator.hardwareConcurrency-2,1)}async calc(t,e,n,s={}){const o=t.length*(t.length-1)/2,i=Math.floor(o/this._workerCount),h=t.length>2e4?await this.getMinimalThreshold(t,e,s):0;n<h&&(console.log(`using threshold ${h}`),n=h),s.threshold=n;const a=new Array(this._workerCount),l=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(471),r.b))));for(let r=0;r<this._workerCount;r++)a[r]=new Promise(((h,a)=>{const u=r*i,c=r===this._workerCount-1?o:(r+1)*i;c<=u&&h({i:new Int32Array(0),j:new Int32Array(0),distance:new Float32Array(0),idx:r}),l[r].postMessage({values:t,startIdx:u,endIdx:c,threshold:n,fnName:e,opts:s}),l[r].onmessage=({data:{error:t,i:e,j:n,distance:s}})=>{t?(l[r].terminate(),a(t)):(l[r].terminate(),h({i:e,j:n,distance:s,idx:r}))}}));const u=await Promise.all(a),c=u.reduce(((t,e)=>t+e.i.length),0),f=new Int32Array(c),g=new Int32Array(c),m=new Float32Array(c);let w=0;for(const t of u)f.set(t.i,w),g.set(t.j,w),m.set(t.distance,w),w+=t.i.length;return{i:f,j:g,distance:m}}async getKNN(t,e,r=15,n={}){return await this.multiColumnKNN([t],[e],r,[n],[1])}async multiColumnKNN(t,e,n=15,s,o,i=N.EUCLIDEAN){if(t.length!==e.length||t.length!==s.length||t.length!==o.length)throw new Error("values, distance functions, options and weights arrays should have the same length");if(t.some((e=>e.length!==t[0].length)))throw new Error("all values arrays should have the same length");const h=t[0].length*(t[0].length-1)/2,a=Math.floor(h/this._workerCount),l=new Array(this._workerCount),u=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(664),r.b))));for(let r=0;r<this._workerCount;r++)l[r]=new Promise(((l,c)=>{const f=r*a,g=r===this._workerCount-1?h:(r+1)*a;g<=f&&l({knnDistances:new Array(0),knnIndexes:new Array(0)}),u[r].postMessage({values:t,startIdx:f,endIdx:g,fnNames:e,opts:s,nNeighbours:n,weights:o,aggregationMethod:i}),u[r].onmessage=({data:{error:t,knnDistances:e,knnIndexes:n}})=>{t?(u[r].terminate(),c(t)):(u[r].terminate(),l({knnDistances:e,knnIndexes:n}))}}));const c=await Promise.all(l),f={knnDistances:new Array(t[0].length).fill(null).map((()=>new Array(n).fill(99999))),knnIndexes:new Array(t[0].length).fill(null).map((()=>new Array(n).fill(-1)))};for(const e of c)for(let r=0;r<t[0].length;++r)for(let t=0;t<e.knnDistances[r]?.length;++t)k(f.knnDistances[r],f.knnIndexes[r],e.knnDistances[r][t],e.knnIndexes[r][t]);return f}async getSampleDistances(t,e,n={}){const s=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(118),r.b)))),o=t.slice();for(let t=o.length-1;t>0;t--){const e=Math.floor(Math.random()*(t+1));[o[t],o[e]]=[o[e],o[t]]}try{const r=t.length*(t.length-1)/2,i=Math.floor(r/this._workerCount),h=1e6,a=Math.max(Math.min(r/1e3,h),Math.min(r,h)),l=Math.floor(a/this._workerCount),u=new Array(this._workerCount);for(let t=0;t<this._workerCount;t++)u[t]=new Promise(((h,a)=>{const u=t*i,c=t===this._workerCount-1?r:(t+1)*i;s[t].postMessage({values:o,startIdx:u,endIdx:c,sampleLength:l,fnName:e,opts:n}),s[t].onmessage=({data:{error:e,distance:r}})=>{s[t].terminate(),e?a(e):h({distance:r})}}));const c=await Promise.all(u),f=c.reduce(((t,e)=>t+e.distance.length),0),g=new Float32Array(f);let m=0;for(const t of c)g.set(t.distance,m),m+=t.distance.length;return g.sort(),g}catch(t){return s?.forEach((t=>t?.terminate())),console.error(t),new Float32Array(1).fill(.5)}}async getMinimalThreshold(t,e,r={}){try{const n=t.length*(t.length-1)/2,s=await this.getSampleDistances(t,e,r);return 1-s[Math.floor(7e7/n*s.length)]}catch(t){return console.error(t),.5}}static calcSync(t,e,r,n){const s=[],o=[],h=[];let a=0,l=0,u=0;const c=t.length*(t.length-1)/2;for(;a<c;){const c=A(t[l])||A(t[u])?1:r(t[l],t[u]);(Object.values(i).some((t=>t===e))?1/(1+c):1-c)>=n&&(s.push(l),o.push(u),h.push(c)),a++,u++,u===t.length&&(l++,u=l+1)}return{i:new Int32Array(s),j:new Int32Array(o),distance:new Float32Array(h)}}}class Zt{data;weights;aggregationMethod;constructor(t){this.data=t.data,this.weights=t.weights,this.aggregationMethod=t.aggregationMethod}}class te extends Zt{reducer;iterations;distanceFnames;distanceFns;distanceFnArgs;constructor(t){super(t),this.reducer=new u.Z(t),this.iterations=t?.iterations??100,this.distanceFnames=t.distanceFnames,this.distanceFns=t.distanceFns,this.distanceFnArgs=t.distanceFnArgs}async transform(){if(this.data[0].length>1e4)throw new Error("Maximum number of samples for T-SNE is 10000");const t=new C(!0,!1);try{const n=(e=this.aggregationMethod,r=this.weights,e===N.MANHATTAN?t=>t.reduce(((t,e,n)=>t+e*r[n]),0):t=>{const e=t.reduce(((t,e,n)=>t+(e*r[n])**2),0);return Math.sqrt(e)}),s=[];for(let e=0;e<this.data.length;++e){const r=await t.calc(this.data[e],this.distanceFnames[e],!1,this.distanceFnArgs[e]);s.push(r)}const o=new Float32Array(s[0].length).fill(0);for(let t=0;t<s[0].length;++t)o[t]=n(s.map((e=>e[t])));const i=function(t,e){const r=function(t){return(e,r)=>t*e+r-Math.floor((e+2)*(e+1)/2)}(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)}(o,this.data[0].length);this.reducer.initDataDist(i);for(let t=0;t<this.iterations;++t)this.reducer.step();return t.terminate(),this.reducer.getSolution()}catch(e){throw t.terminate(),e}var e,r}}class ee extends Zt{reducer;distanceFnames;distanceFns;vectors;progressFunc;distanceFnArgs;constructor(t){super(t),d("distanceFnames"in t),d("distanceFns"in t),this.distanceFnArgs=t.distanceFnArgs,this.distanceFns=t.distanceFns,this.progressFunc=t.progressFunc,this.distanceFnames=t.distanceFnames,this.vectors=new Array(this.data[0].length).fill(0).map(((t,e)=>e)),this.data[0].length<15&&(t.nNeighbors=this.data[0].length-1),this.reducer=new Ht(t)}async transform(t){console.time("knn graph");const e=await(new Jt).multiColumnKNN(this.data,this.distanceFnames,this.reducer.neighbors,this.distanceFnArgs,this.weights,this.aggregationMethod);console.timeEnd("knn graph"),this.reducer.setPrecomputedKNN(e.knnIndexes,e.knnDistances),await new Promise((t=>{setTimeout((()=>{t()}),300)}));const r=await this.reducer.fitAsync(this.vectors,(t=>{this.progressFunc&&this.progressFunc(t,this.reducer.getNEpochs(),this.reducer.getEmbedding())}));return s=r,new Array(s.length).fill(0).map(((t,e)=>n.from(s[e])));var s}}const re={UMAP:ee,"t-SNE":te};class ne{reducer;constructor(t,e,r,n,s,o){const i=[];for(let e=0;e<r.length;++e){const n=new S(r[e]).getMeasure(o.distanceFnArgs[e]);i.push(n);let s=2048;for(let r=0;r<t[e].length;++r)if(t[e][r]&&t[e][r]._length){s=t[e][r]._length;break}if(h=r[e],"BitArray"==_[h])for(let r=0;r<t[e].length;++r)t[e][r]&&t[e][r]._data?t[e][r]=new g(t[e][r]._data,t[e][r]._length):t[e][r]=new g(s)}var h;"UMAP"==e?this.reducer=new ee({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:n,aggregationMethod:s,...o}):"t-SNE"==e&&(this.reducer=new te({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:n,aggregationMethod:s,...o}))}async transform(t=!1){if(void 0===this.reducer)throw new Error("Reducer was not defined.");let e=await this.reducer.transform();var r;return t&&(r=e,e=new Array(r[0].length).fill(0).map(((t,e)=>new n(r.length).fill(0).map(((t,n)=>r[n][e]))))),e}static availableMetricsByType(t){return Object.keys(x[t])}static get availableMethods(){return Object.keys(re)}static get availableMetrics(){let t=[];return Object.values(x).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}async function se(t,e,r){t%5==0&&self.postMessage({epochNum:t,epochsLength:e,embedding:r})}self.onmessage=async({data:{columnsData:t,method:e,distanceMetrics:r,options:n,weights:s,aggregationMethod:o}})=>{let i;try{const h=await async function(t,e,r,n,s,o){const i=new ne(t,e,r,n,s,{...o,progressFunc:se});return await i.transform(!0)}(t,e,r,s,o,n);i={embedding:h}}catch(t){i={error:t}}self.postMessage({error:i.error,embedding:i.embedding})}},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 o=0;o<t;o++){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],o=e[s];n+=(r-o)*(r-o)}return n}xtod(t){const e=t.length,r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const o=this.L2(t[n],t[s]);r[n*e+s]=o,r[s*e+n]=o}return r}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 o=Math.log(e),i=this.zeros(s*s),h=this.zeros(s);for(let e=0;e<s;e++){let n=-1/0,a=1/0,l=1,u=!1;const c=50;let f=0;for(;!u;){let i=0;for(let r=0;r<s;r++){let n=Math.exp(-t[e*s+r]*l);e===r&&(n=0),h[r]=n,i+=n}let g=0;for(let t=0;t<s;t++){let e;e=0===i?0:h[t]/i,h[t]=e,e>1e-7&&(g-=e*Math.log(e))}g>o?(n=l,a===1/0?l*=2:l=(l+a)/2):(a=l,n===-1/0?l/=2:l=(l+n)/2),f++,Math.abs(g-o)<r&&(u=!0),f>=c&&(u=!0)}for(let t=0;t<s;t++)i[e*s+t]=h[t]}const a=this.zeros(s*s),l=2*s;for(let t=0;t<s;t++)for(let e=0;e<s;e++)a[t*s+e]=Math.max((i[t*s+e]+i[e*s+t])/l,1e-100);return a}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 o=t[n][s];r[n*e+s]=o,r[s*e+n]=o}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],o=this.ystep[e][t],i=this.gains[e][t];let h=this.sign(r)===this.sign(o)?.8*i:i+.2;h<.01&&(h=.01),this.gains[e][t]=h;const a=(this.iter<250?.5:.8)*o-this.epsilon*h*n[e][t];this.ystep[e][t]=a,this.Y[e][t]+=a,s[t]+=this.Y[e][t]}for(let e=0;e<t;e++)for(let r=0;r<this.dim;r++)this.Y[e][r]-=s[r]/t;return r}debugGrad(){const t=this.N,e=this.costGrad(this.Y),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 o=this.costGrad(this.Y);this.Y[e][t]=s-n;const i=this.costGrad(this.Y),h=r[e][t],a=(o.cost-i.cost)/(2*n);console.log(e+","+t+": gradcheck analytic: "+h+" vs. numerical: "+a),this.Y[e][t]=s}}costGrad(t){const e=this.N,r=this.dim,n=this.P,s=this.iter<100?4:1,o=this.zeros(e*e);let i=0;for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){let h=0;for(let e=0;e<r;e++){const r=t[n][e]-t[s][e];h+=r*r}const a=1/(1+h);o[n*e+s]=a,o[s*e+n]=a,i+=2*a}const h=e*e,a=this.zeros(h);for(let t=0;t<h;t++)a[t]=Math.max(o[t]/i,1e-100);let l=0;const u=[];for(let i=0;i<e;i++){const h=new Array(r);for(let t=0;t<r;t++)h[t]=0;for(let u=0;u<e;u++){l+=-n[i*e+u]*Math.log(a[i*e+u]);const c=4*(s*n[i*e+u]-a[i*e+u])*o[i*e+u];for(let e=0;e<r;e++)h[e]+=c*(t[i][e]-t[u][e])}u.push(h)}return{cost:l,grad:u}}}}},n={};function s(t){var e=n[t];if(void 0!==e)return e.exports;var o=n[t]={exports:{}};return r[t](o,o.exports,s),o.exports}s.m=r,s.x=()=>{var t=s.O(void 0,[649],(()=>s(2886)));return s.O(t)},t=[],s.O=(e,r,n,o)=>{if(!r){var i=1/0;for(u=0;u<t.length;u++){for(var[r,n,o]=t[u],h=!0,a=0;a<r.length;a++)(!1&o||i>=o)&&Object.keys(s.O).every((t=>s.O[t](r[a])))?r.splice(a--,1):(h=!1,o<i&&(i=o));if(h){t.splice(u--,1);var l=n();void 0!==l&&(e=l)}}return e}o=o||0;for(var u=t.length;u>0&&t[u-1][2]>o;u--)t[u]=t[u-1];t[u]=[r,n,o]},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),(()=>{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={886: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,o,i]=e;for(var h in o)s.o(o,h)&&(s.m[h]=o[h]);for(i&&i(s);n.length;)t[n.pop()]=1;r(e)}})(),e=s.x,s.x=()=>s.e(649).then(e);var o=s.x();bio=o})();
2
+ (self.webpackChunkbio=self.webpackChunkbio||[]).push([[886],{2886:(t,e,r)=>{"use strict";class n extends Float32Array{}var s,o,i,h,a,l,u=r(7659);!function(t){t.Levenshtein="Levenshtein",t.JaroWinkler="Jaro-Winkler",t.Manhattan="Manhattan",t.Onehot="One-Hot"}(s||(s={})),function(t){t.Euclidean="Euclidean"}(o||(o={})),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.TanimotoIntArray="TanimotoIntArray"}(h||(h={})),function(t){t.Vector="Vector",t.String="String",t.BitArray="BitArray",t.MacroMolecule="MacroMolecule",t.Number="Number",t.IntArray="IntArray"}(a||(a={})),function(t){t.Difference="Difference"}(l||(l={}));var c=r(1811),f=r(3979);class g{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=g._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 g(t._length);r._length=t._length,r._data=g._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 g(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 g(t);for(let n=0;n<t;++n)r.setBit(n,e(n));return r._version=0,r}static fromString(t){return g.fromSeq(t.length,(e=>"1"==t.charAt(e)))}static fromUint32Array(t,e){const r=new g(t);return r._data=e,r}static fromBytes(t){const e=t.length,r=new g(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 g(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 g.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),o=Math.max(t,e);if(r)for(let t=s;t<=o;t++)this.setTrue(t);else for(let t=s;t<=o;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+=g._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+=g._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+=g._onBitCount[255&e];let o=this._data[s]&t._data[s];const i=31&this._length;for(0!=i&&(o&=~(4294967295<<i));0!=o;o>>>=8)r+=g._onBitCount[255&o];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=g._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=g._lastOnBit[t>>>24];if(r>=0)return r+32*n+e}}return-1}}g._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]),g._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]),g._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 m=r(708);function w(t,e){const r=t.trueCount()+e.trueCount();if(0==r)return 1;const n=t.andWithCountBits(e,!0);return n/(r-n)}function d(t){return 0===t?3402823e32:1/t-1}function p(t=!1,e="Assertion error."){if(!t)throw new Error(e)}i.Tanimoto,i.Dice,i.Asymmetric,i.BraunBlanquet,i.Cosine,i.Kulczynski,i.McConnaughey,i.RogotGoldberg,i.Russel,i.Sokal,i.Hamming,i.Euclidean,i.Tanimoto,i.Dice,i.Asymmetric,i.BraunBlanquet,i.Cosine,i.Kulczynski,i.McConnaughey,i.RogotGoldberg,i.Russel,i.Sokal,i.Hamming,i.Euclidean,i.Tanimoto,i.Dice,i.Cosine,i.Tanimoto,i.Asymmetric,i.Cosine,i.Sokal,m.U.HAMMING,m.U.LEVENSHTEIN,m.U.MONOMER_CHEMICAL_DISTANCE,m.U.NEEDLEMANN_WUNSCH;const y={[o.Euclidean]:function(t,e){let r=0;const n=t.length;if(n!==e.length)throw new Error("The dimensionality of the vectors must match");for(let s=0;s<n;++s)r+=Math.pow(t[s]-e[s],2);return Math.sqrt(r)}},M={[s.Levenshtein]:c.T,[s.JaroWinkler]:f.H$,[s.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.Onehot]:function(t,e){return t===e?0:1}},b={[i.Tanimoto]:function(t,e){return d(w(t,e))},[i.Dice]:function(t,e){return d(function(t,e){const r=t.trueCount()+e.trueCount();return 0==r?0:2*t.andWithCountBits(e,!0)/r}(t,e))},[i.Asymmetric]:function(t,e){return d(function(t,e){const r=Math.min(t.trueCount(),e.trueCount());return 0==r?0:t.andWithCountBits(e,!0)/r}(t,e))},[i.BraunBlanquet]:function(t,e){return d(function(t,e){const r=Math.max(t.trueCount(),e.trueCount());return 0==r?0:t.andWithCountBits(e,!0)/r}(t,e))},[i.Cosine]:function(t,e){return d(function(t,e){const r=t.trueCount()*e.trueCount();return 0==r?0:t.andWithCountBits(e,!0)/Math.sqrt(r)}(t,e))},[i.Kulczynski]:function(t,e){return d(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.trueCount()*e.trueCount();return 0==n?0:t.andWithCountBits(e,!0)*r/(2*n)}(t,e))},[i.McConnaughey]:function(t,e){return d(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.trueCount()*e.trueCount();return 0==n?0:(t.andWithCountBits(e,!0)*r-n)/n}(t,e))},[i.RogotGoldberg]:function(t,e){return d(function(t,e){const r=t.andWithCountBits(e,!0),n=t.countBits(!0)+e.countBits(!0),s=t.length,o=s-n+r;return r==s||o==s?1:r/n+o/(2*s-n)}(t,e))},[i.Russel]:function(t,e){return d(function(t,e){return 0==t.length?0:t.andWithCountBits(e,!0)/t.length}(t,e))},[i.Sokal]:function(t,e){return d(function(t,e){const r=t.trueCount()+e.trueCount(),n=t.andWithCountBits(e,!0);return n/(2*r-3*n)}(t,e))},[i.Hamming]:function(t,e){return t.trueCount()+e.trueCount()-2*t.andWithCountBits(e,!0)},[i.Euclidean]:function(t,e){return Math.sqrt(t.trueCount()+e.trueCount()-2*t.andWithCountBits(e,!0))}},x={[h.TanimotoIntArray]:function(t,e){return d(w(new g(t,32*t.length),new g(e,32*e.length)))}},v={[l.Difference]:function(t,e){return Math.abs(t-e)}},E={[a.Vector]:{[o.Euclidean]:y[o.Euclidean]},[a.String]:{[s.Levenshtein]:M[s.Levenshtein],[s.JaroWinkler]:M[s.JaroWinkler],[s.Manhattan]:M[s.Manhattan],[s.Onehot]:M[s.Onehot]},[a.BitArray]:{[i.Tanimoto]:b[i.Tanimoto],[i.Dice]:b[i.Dice],[i.Asymmetric]:b[i.Asymmetric],[i.BraunBlanquet]:b[i.BraunBlanquet],[i.Cosine]:b[i.Cosine],[i.Kulczynski]:b[i.Kulczynski],[i.McConnaughey]:b[i.McConnaughey],[i.RogotGoldberg]:b[i.RogotGoldberg],[i.Russel]:b[i.Russel],[i.Sokal]:b[i.Sokal]},[a.MacroMolecule]:{[m.U.HAMMING]:m.o[m.U.HAMMING],[m.U.LEVENSHTEIN]:m.o[m.U.LEVENSHTEIN],[m.U.NEEDLEMANN_WUNSCH]:m.o[m.U.NEEDLEMANN_WUNSCH],[m.U.MONOMER_CHEMICAL_DISTANCE]:m.o[m.U.MONOMER_CHEMICAL_DISTANCE]},[a.Number]:{[l.Difference]:v[l.Difference]},[a.IntArray]:{[h.TanimotoIntArray]:x[h.TanimotoIntArray]}},_=Object.keys(E).reduce(((t,e)=>{for(const r of Object.keys(E[e]))t[r]=e;return t}),{});class S{method;dataType;constructor(t){this.method=t,this.dataType=_[t]}getMeasure(t){const e=E;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,_[r]==a.MacroMolecule.toString()?e[this.dataType][this.method](t):e[this.dataType][this.method];var r}static getMetricByDataType(t){return Object.keys(E[t])}static get availableMeasures(){return Object.keys(E)}}var N;!function(t){t.EUCLIDEAN="EUCLIDEAN",t.MANHATTAN="MANHATTAN"}(N||(N={}));const A=t=>null==t;function C(t,e,r,n){if(r>t[t.length-1])return;const s=t.findIndex((t=>r<t));t.pop(),t.splice(s,0,r),e.pop(),e.splice(s,0,n)}class k{_workers;_workerCount;_terminateOnComplete;constructor(t=!0,e=!0){const n=navigator.hardwareConcurrency;this._workerCount=t?Math.max(n-2,1):1,this._workers=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(100),r.b)))),this._terminateOnComplete=e}async calc(t,e,r=!0,n){return new Promise((async(s,o)=>{try{const o=t.length,i=new Array(this._workerCount),h=o*(o-1)/2;this._workerCount=Math.min(this._workerCount,h);const a=h/this._workerCount,l=new Float32Array(h);let u=0,c=1,f=0,g=Number.MIN_VALUE;for(let r=0;r<this._workerCount;r++){const s=Math.floor(r*a),m=r===this._workerCount-1?h:Math.floor((r+1)*a),w=u,d=c;r!==this._workerCount-1&&(u=o-2-Math.floor(Math.sqrt(-8*m+4*o*(o-1)-7)/2-.5),c=m-o*u+Math.floor((u+1)*(u+2)/2)),this._workers[r].postMessage({values:t,fnName:e,startRow:w,startCol:d,chunckSize:m-s,opts:n}),i[r]=new Promise(((t,e)=>{this._workers[r].onmessage=({data:{error:n,distanceMatrixData:o,min:i,max:h}})=>{this._terminateOnComplete&&this._workers[r].terminate(),n?e(n):(l.set(o,s),i<f&&(f=i),h>g&&(g=h),t())}}))}await Promise.all(i),r&&l.forEach(((t,e)=>{l[e]=(t-f)/(g-f)})),s(l)}catch(t){o(t)}}))}terminate(){this._workers.forEach((t=>t.terminate()))}}function R(t,e){return Math.floor(e()*t)}function I(t){return t()}function F(t){const e=[];for(let r=0;r<t;r++)e.push(void 0);return e}function T(t){return F(t).map(((t,e)=>e))}function z(t,e){return F(t).map((()=>e))}function D(t){return z(t,0)}function V(t){return function(t){return t.reduce(((t,e)=>t+e))}(t)/t.length}function B(t){let e=0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e}function O(t,e,r){const n=D(t);for(let s=0;s<t;s++){let t=!0;for(;t;){const o=R(e,r);let i=!1;for(let t=0;t<s;t++)if(o===n[t]){i=!0;break}i||(t=!1),n[s]=o}}return n}function L(t,e,r){const n=[];let s=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(let o=0;o<e;o++){const e=[];for(let n=0;n<r;n++)e.push(t[s]),s+=1;n.push(e)}return n}function P(t,e){const r=r=>F(t).map((()=>z(e,r))),n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function q(t,e,r){const n=D(t);for(let s=0;s<t;s++){let t=!0,o=0;for(;t;){o=R(e,r);let i=!1;for(let t=0;t<s;t++)if(o===n[t]){i=!0;break}i||(t=!1)}n[s]=o}return n}function j(t,e,r,n,s){e=Math.floor(e);const o=t[0][e];if(r>=t[1][e][0])return 0;for(let t=0;t<o.length;t++)if(n===o[t])return 0;return $(t,e,r,n,s)}function $(t,e,r,n,s){const o=t[0][e],i=t[1][e],h=t[2][e];if(r>=i[0])return 0;i[0]=r,o[0]=n,h[0]=s;let a=0,l=0;for(;;){const e=2*a+1,n=e+1,s=t[0][0].length;if(e>=s)break;if(n>=s){if(!(i[e]>r))break;l=e}else if(i[e]>=i[n]){if(!(r<i[e]))break;l=e}else{if(!(r<i[n]))break;l=n}i[a]=i[l],o[a]=o[l],h[a]=h[l],a=l}return i[a]=r,o[a]=n,h[a]=s,1}function U(t,e,r,n,s){const o=P(e,n);for(let n=0;n<e;n++)for(let e=0;e<r;e++){if(t[0][n][e]<0)continue;const r=t[0][n][e],i=t[2][n][e],h=I(s);j(o,n,h,r,i),j(o,r,h,n,i),t[2][n][e]=0}return o}function W(t){const e=t[0],r=t[1];for(let t=0;t<e.length;t++){const n=e[t],s=r[t];for(let t=0;t<n.length-1;t++){const e=n.length-t-1,r=s.length-t-1,o=n[0];n[0]=n[e],n[e]=o;const i=s[0];s[0]=s[r],s[r]=i,G(s,n,r,0)}}return{indices:e,weights:r}}function G(t,e,r,n){for(;2*n+1<r;){const s=2*n+1,o=s+1;let i=n;if(t[i]<t[s]&&(i=s),o<r&&t[i]<t[o]&&(i=o),i===n)break;{const r=t[n];t[n]=t[i],t[i]=r;const s=e[n];e[n]=e[i],e[i]=s,n=i}}}function H(t,e){const r=t[0][e],n=t[1][e],s=t[2][e];let o=1/0,i=-1;for(let t=0;t>r.length;t++)1===s[t]&&n[t]<o&&(o=n[t],i=t);return i>=0?(s[i]=0,Math.floor(r[i])):-1}class K{entries=new Map;nRows=0;nCols=0;constructor(t,e,r,n){if(t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(let n=0;n<r.length;n++){const s=t[n],o=e[n];this.checkDims(s,o);const i=this.makeKey(s,o);this.entries.set(i,{value:r[n],row:s,col:o})}}makeKey(t,e){return`${t}:${e}`}checkDims(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")}set(t,e,r){this.checkDims(t,e);const n=this.makeKey(t,e);this.entries.has(n)?this.entries.get(n).value=r:this.entries.set(n,{value:r,row:t,col:e})}get(t,e,r=0){const n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).value:r}getAll(t=!0){const e=new Array(this.entries.size).fill(null);let r=0;return this.entries.forEach((t=>{e[r++]=t})),t&&e.sort(((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row)),e}getDims(){return[this.nRows,this.nCols]}getRows(){return Array.from(this.entries,(([t,e])=>e.row))}getCols(){return Array.from(this.entries,(([t,e])=>e.col))}getValues(){return Array.from(this.entries,(([t,e])=>e.value))}forEach(t){this.entries.forEach((e=>t(e.value,e.row,e.col)))}map(t){const e=new Float32Array(this.entries.size);let r=0;this.entries.forEach((n=>{e[r++]=t(n.value,n.row,n.col)}));const n=[this.nRows,this.nCols];return new K(this.getRows(),this.getCols(),e,n)}toArray(){const t=F(this.nRows).map((()=>D(this.nCols)));return this.entries.forEach((e=>{t[e.row][e.col]=e.value})),t}}function Y(t){const e=t.getRows(),r=t.getCols(),n=t.getValues(),s=r.length,o=new Int32Array(s),i=new Int32Array(s),h=new Float32Array(s);o.set(e),i.set(r),h.set(n);const a=[t.nCols,t.nRows];return new K(i,o,h,a)}function X(t,e){return nt(t,e,((t,e)=>t*e))}function Q(t,e){return nt(t,e,((t,e)=>t+e))}function J(t,e){return nt(t,e,((t,e)=>t-e))}function Z(t,e){return t.map((t=>t*e))}function tt(t){const e=new Set,r=t.getValues(),n=t.getRows(),s=t.getCols();for(let t=0;t<r.length;t++)0===r[t]&&e.add(t);const o=(t,r)=>!e.has(r),i=r.filter(o),h=n.filter(o),a=s.filter(o);return new K(h,a,i,t.getDims())}function et(t,e="l2"){const r=rt[e],n=new Map;t.forEach(((t,e,r)=>{const s=n.get(e)||[];s.push(r),n.set(e,s)}));const s=new K([],[],[],t.getDims());for(const e of n.keys()){const o=n.get(e).sort(),i=r(o.map((r=>t.get(e,r))));for(let t=0;t<i.length;t++)s.set(e,o[t],i[t])}return s}const rt={max:t=>{let e=-1/0;for(let r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map((t=>t/e))},l1:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r];return t.map((t=>t/e))},l2:t=>{let e=0;for(let r=0;r<t.length;r++)e+=t[r]**2;return t.map((t=>Math.sqrt(t**2/e)))}};function nt(t,e,r){const n=new Set,s=[],o=[],i=[],h=(n,h)=>{s.push(n),o.push(h);const a=r(t.get(n,h),e.get(n,h));i.push(a)},a=t.getValues(),l=t.getRows(),u=t.getCols();for(let t=0;t<a.length;t++){const e=l[t],r=u[t],s=`${e}:${r}`;n.add(s),h(e,r)}const c=e.getValues(),f=e.getRows(),g=e.getCols();for(let t=0;t<c.length;t++){const e=f[t],r=g[t],s=`${e}:${r}`;n.has(s)||h(e,r)}const m=[t.nRows,t.nCols];return new K(s,o,i,m)}function st(t){const e=[];t.forEach(((t,r,n)=>{e.push({value:t,row:r,col:n})})),e.sort(((t,e)=>t.row===e.row?t.col-e.col:t.row-e.row));const r=[],n=[],s=[];let o=-1;for(let t=0;t<e.length;t++){const{row:i,col:h,value:a}=e[t];i!==o&&(o=i,s.push(t)),r.push(h),n.push(a)}return{indices:r,values:n,indptr:s}}class ot{hyperplanes;offsets;children;indices;constructor(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n}}function it(t,e,r,n){const s=Math.max(10,e),o=T(r).map(((e,r)=>function(t,e=30,r,n){return ht(t,T(t.length),e,r,n)}(t,s,r,n))),i=o.map((t=>function(t,e){const r=lt(t),n=ut(t),s=T(r).map((()=>t.hyperplane?1:0)),o=D(r),i=T(r).map((()=>[-1,-1])),h=T(n).map((()=>T(e).map((()=>-1))));return at(t,s,o,i,h,0,0),new ot(s,o,i,h)}(t,s)));return i}function ht(t,e,r=30,n,s){if(e.length>r){const o=function(t,e,r){const n=R(e.length,r);let s=R(e.length,r);s+=n===s?1:0,s%=e.length;const o=e[n],i=e[s];let h=0,a=0;a=t[o]-t[i],h-=a*(t[o]+t[i])/2;let l=0,u=0;const c=D(e.length);for(let n=0;n<e.length;n++){let s=h;s+=a*t[e[n]],0===s?(c[n]=R(2,r),0===c[n]?l+=1:u+=1):s>0?(c[n]=0,l+=1):(c[n]=1,u+=1)}const f=D(l),g=D(u);l=0,u=0;for(let t=0;t<c.length;t++)0===c[t]?(f[l]=e[t],l+=1):(g[u]=e[t],u+=1);return{indicesLeft:f,indicesRight:g,hyperplane:a,offset:h}}(t,e,s),{indicesLeft:i,indicesRight:h,hyperplane:a,offset:l}=o;return{leftChild:ht(t,i,r,n+1,s),rightChild:ht(t,h,r,n+1,s),isLeaf:!1,hyperplane:a,offset:l}}return{indices:e,isLeaf:!0}}function at(t,e,r,n,s,o,i){if(t.isLeaf)return n[o][0]=-i,s[i].splice(0,t.indices.length,...t.indices),{nodeNum:o,leafNum:i+=1};{e[o]=t.hyperplane,r[o]=t.offset,n[o][0]=o+1;const h=o;let a=at(t.leftChild,e,r,n,s,o+1,i);return o=a.nodeNum,i=a.leafNum,n[h][1]=o+1,a=at(t.rightChild,e,r,n,s,o+1,i),{nodeNum:a.nodeNum,leafNum:a.leafNum}}}function lt(t){return t.isLeaf?1:1+lt(t.leftChild)+lt(t.rightChild)}function ut(t){return t.isLeaf?1:ut(t.leftChild)+ut(t.rightChild)}function ct(t,e,r,n){let s=e;return s+=t*r,0===s?R(2,n):s>0?0:1}function ft(t,e,r){let n=0;for(;e.children[n][0]>0;)n=0===ct(e.hyperplanes[n],e.offsets[n],t,r)?e.children[n][0]:e.children[n][1];const s=-1*e.children[n][0];return e.indices[s]}const gt=Object.prototype.toString;function mt(t){return gt.call(t).endsWith("Array]")}function wt(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 dt=Object.prototype.toString;function pt(t){return dt.call(t).endsWith("Array]")}const yt=Object.prototype.toString;function Mt(t){return yt.call(t).endsWith("Array]")}const bt=Object.prototype.toString;const xt=Object.prototype.toString;function vt(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Mt(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(!Mt(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,!xt.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var n=r.fromIndex,s=void 0===n?0:n,o=r.toIndex,i=void 0===o?t.length:o;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=s||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[s],a=s+1;a<i;a++)t[a]<h&&(h=t[a]);return h}(t),s=function(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(e=t,!bt.call(e).endsWith("Array]"))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var n=r.fromIndex,s=void 0===n?0:n,o=r.toIndex,i=void 0===o?t.length:o;if(s<0||s>=t.length||!Number.isInteger(s))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=s||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var h=t[s],a=s+1;a<i;a++)t[a]>h&&(h=t[a]);return h}(t);if(n===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var o=r.min,i=void 0===o?r.autoMinMax?n:0:o,h=r.max,a=void 0===h?r.autoMinMax?s:1:h;if(i>=a)throw new RangeError("min option must be smaller than max option");for(var l=(a-i)/(s-n),u=0;u<t.length;u++)e[u]=(t[u]-n)*l+i;return e}const Et=" ".repeat(2),_t=" ".repeat(4);function St(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:s=8,padMinus:o="auto"}=e;return`${t.constructor.name} {\n${Et}[\n${_t}${function(t,e,r,n,s){const{rows:o,columns:i}=t,h=Math.min(o,e),a=Math.min(i,r),l=[];if("auto"===s){s=!1;t:for(let e=0;e<h;e++)for(let r=0;r<a;r++)if(t.get(e,r)<0){s=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let o=0;o<a;o++)r.push(Nt(t.get(e,o),n,s));l.push(`${r.join(" ")}`)}return a!==i&&(l[l.length-1]+=` ... ${i-r} more columns`),h!==o&&l.push(`... ${o-e} more rows`),l.join(`\n${_t}`)}(t,r,n,s,o)}\n${Et}]\n${Et}rows: ${t.rows}\n${Et}columns: ${t.columns}\n}`}function Nt(t,e,r){return(t>=0&&r?` ${At(t,e-1)}`:At(t,e)).padEnd(e)}function At(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 Ct(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 kt(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 Rt(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 It(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 Ft(t,e,r,n,s){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(zt("startRow",e),zt("endRow",r),zt("startColumn",n),zt("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 Tt(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function zt(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function Dt(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class Vt{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new Ot(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 Ot(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 Ot(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 Ot(t,e)}static ones(t,e){return new Ot(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 Ot(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)s.set(r,t,n());return s}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:o=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let i=s-n,h=new Ot(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(o()*i);h.set(r,t,e)}return h}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let t=0;t<n;t++)s.set(t,t,r);return s}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let s=Math.min(n,e,r),o=this.zeros(e,r);for(let e=0;e<s;e++)o.set(e,e,t[e]);return o}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new Ot(r,n);for(let o=0;o<r;o++)for(let r=0;r<n;r++)s.set(o,r,Math.min(t.get(o,r),e.get(o,r)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let o=0;o<r;o++)for(let r=0;r<n;r++)s.set(o,r,Math.max(t.get(o,r),e.get(o,r)));return s}static checkMatrix(t){return Vt.isMatrix(t)?t:new Ot(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&!1===s;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let r=e+1;r<this.rows;r++)0!==this.get(t,r)&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/s);for(let n=e+1;n<t.rows;n++){let s=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let o=r+1;o<t.columns;o++)t.set(n,o,t.get(n,o)-t.get(e,o)*s)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(0===t.maxRow(n))n--;else{let s=0,o=!1;for(;s<r&&!1===o;)1===t.get(n,s)?o=!0:s++;for(let r=0;r<n;r++){let o=t.get(r,s);for(let i=s;i<e;i++){let e=t.get(r,i)-o*t.get(n,i);t.set(r,i,e)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new Ot(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){Ct(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return Ot.rowVector(this.getRow(t))}setRow(t,e){Ct(this,t),e=Rt(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){Ct(this,t),Ct(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){kt(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return Ot.columnVector(this.getColumn(t))}setColumn(t,e){kt(this,t),e=It(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){kt(this,t),kt(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=Rt(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=Rt(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=Rt(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=Rt(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=It(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=It(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=It(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=It(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){Ct(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){kt(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(){Dt(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(){Dt(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(Ct(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){Ct(this,t),Dt(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(Ct(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){Ct(this,t),Dt(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(kt(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){kt(this,t),Dt(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(kt(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){kt(this,t),Dt(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){Vt.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=Ot.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new Ot(e,n),o=new Float64Array(r);for(let i=0;i<n;i++){for(let e=0;e<r;e++)o[e]=t.get(e,i);for(let t=0;t<e;t++){let e=0;for(let n=0;n<r;n++)e+=this.get(t,n)*o[n];s.set(t,i,e)}}return s}strassen2x2(t){t=Ot.checkMatrix(t);let e=new Ot(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),o=t.get(0,1),i=this.get(1,0),h=t.get(1,0),a=this.get(1,1),l=t.get(1,1),u=(r+a)*(n+l),c=(i+a)*n,f=r*(o-l),g=a*(h-n),m=(r+s)*l,w=u+g-m+(s-a)*(h+l),d=f+m,p=c+g,y=u-c+f+(i-r)*(n+o);return e.set(0,0,w),e.set(0,1,d),e.set(1,0,p),e.set(1,1,y),e}strassen3x3(t){t=Ot.checkMatrix(t);let e=new Ot(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),o=this.get(1,0),i=this.get(1,1),h=this.get(1,2),a=this.get(2,0),l=this.get(2,1),u=this.get(2,2),c=t.get(0,0),f=t.get(0,1),g=t.get(0,2),m=t.get(1,0),w=t.get(1,1),d=t.get(1,2),p=t.get(2,0),y=t.get(2,1),M=t.get(2,2),b=(r-o)*(-f+w),x=(-r+o+i)*(c-f+w),v=(o+i)*(-c+f),E=r*c,_=(-r+a+l)*(c-g+d),S=(-r+a)*(g-d),N=(a+l)*(-c+g),A=(-s+l+u)*(w+p-y),C=(s-u)*(w-y),k=s*p,R=(l+u)*(-p+y),I=(-s+i+h)*(d+p-M),F=(s-h)*(d-M),T=(i+h)*(-p+M),z=E+k+n*m,D=(r+n+s-o-i-l-u)*w+x+v+E+A+k+R,V=E+_+N+(r+n+s-i-h-a-l)*d+k+I+T,B=b+i*(-c+f+m-w-d-p+M)+x+E+k+I+F,O=b+x+v+E+h*y,L=k+I+F+T+o*g,P=E+_+S+l*(-c+g+m-w-d-p+y)+A+C+k,q=A+C+k+R+a*f,j=E+_+S+N+u*M;return e.set(0,0,z),e.set(0,1,D),e.set(0,2,V),e.set(1,0,B),e.set(1,1,O),e.set(1,2,L),e.set(2,0,P),e.set(2,1,q),e.set(2,2,j),e}mmulStrassen(t){t=Ot.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,o=t.columns;function i(t,e,r){let n=t.rows,s=t.columns;if(n===e&&s===r)return t;{let n=Vt.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${o} matrix: dimensions do not match.`);let h=Math.max(r,s),a=Math.max(n,o);return e=i(e,h,a),function t(e,r,n,s){if(n<=512||s<=512)return e.mmul(r);n%2==1&&s%2==1?(e=i(e,n+1,s+1),r=i(r,n+1,s+1)):n%2==1?(e=i(e,n+1,s),r=i(r,n+1,s)):s%2==1&&(e=i(e,n,s+1),r=i(r,n,s+1));let o=parseInt(e.rows/2,10),h=parseInt(e.columns/2,10),a=e.subMatrix(0,o-1,0,h-1),l=r.subMatrix(0,o-1,0,h-1),u=e.subMatrix(0,o-1,h,e.columns-1),c=r.subMatrix(0,o-1,h,r.columns-1),f=e.subMatrix(o,e.rows-1,0,h-1),g=r.subMatrix(o,r.rows-1,0,h-1),m=e.subMatrix(o,e.rows-1,h,e.columns-1),w=r.subMatrix(o,r.rows-1,h,r.columns-1),d=t(Vt.add(a,m),Vt.add(l,w),o,h),p=t(Vt.add(f,m),l,o,h),y=t(a,Vt.sub(c,w),o,h),M=t(m,Vt.sub(g,l),o,h),b=t(Vt.add(a,u),w,o,h),x=t(Vt.sub(f,a),Vt.add(l,c),o,h),v=t(Vt.sub(u,m),Vt.add(g,w),o,h),E=Vt.add(d,M);E.sub(b),E.add(v);let _=Vt.add(y,b),S=Vt.add(p,M),N=Vt.sub(d,p);N.add(y),N.add(x);let A=Vt.zeros(2*E.rows,2*E.columns);return A=A.setSubMatrix(E,0,0),A=A.setSubMatrix(_,E.rows,0),A=A.setSubMatrix(S,0,E.columns),A=A.setSubMatrix(N,E.rows,E.columns),A.subMatrix(0,n-1,0,s-1)}(e,t=i(t,h,a),h,a)}scaleRows(t={}){if("object"!=typeof t)throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new Ot(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&vt(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 Ot(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&vt(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=Ot.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,o=new Ot(e*n,r*s);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let h=0;h<s;h++)o.set(n*i+r,s*e+h,this.get(i,e)*t.get(r,h));return o}kroneckerSum(t){if(t=Ot.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(Ot.eye(r,r)),s=Ot.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new Ot(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=Bt){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=Bt){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Ft(this,t,e,r,n);let s=new Ot(e-t+1,n-r+1);for(let o=t;o<=e;o++)for(let e=r;e<=n;e++)s.set(o-t,e-r,this.get(o,e));return s}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new Ot(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let o=e;o<=r;o++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,o-e,this.get(t[s],o))}return n}subMatrixColumn(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new Ot(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let o=e;o<=r;o++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(o-e,s,this.get(o,t[s]))}return n}setSubMatrix(t,e,r){if((t=Ot.checkMatrix(t)).isEmpty())return this;Ft(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(!pt(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(!pt(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 Ot(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let t=0;t<e.length;t++){let o=e[t];r.set(n,t,this.get(s,o))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){let t=new Ot(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=Tt(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=Tt(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=Tt(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=Tt(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(!pt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,o=[];for(let i=0;i<n;i++){let n=0,h=0,a=0;for(let e=0;e<s;e++)a=t.get(i,e)-r[i],n+=a,h+=a*a;e?o.push((h-n*n/s)/(s-1)):o.push((h-n*n/s)/s)}return o}(this,r,n);case"column":if(!pt(n))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,s=t.columns,o=[];for(let i=0;i<s;i++){let s=0,h=0,a=0;for(let e=0;e<n;e++)a=t.get(e,i)-r[i],s+=a,h+=a*a;e?o.push((h-s*s/n)/(n-1)):o.push((h-s*s/n)/n)}return o}(this,r,n);case void 0:if("number"!=typeof n)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,s=t.columns,o=n*s;let i=0,h=0,a=0;for(let e=0;e<n;e++)for(let n=0;n<s;n++)a=t.get(e,n)-r,i+=a,h+=a*a;return e?(h-i*i/o)/(o-1):(h-i*i/o)/o}(this,r,n);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!pt(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(!pt(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(!pt(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(!pt(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 St(this,t)}}function Bt(t,e){return t-e}Vt.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Vt.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return St(this)}),Vt.random=Vt.rand,Vt.randomInt=Vt.randInt,Vt.diagonal=Vt.diag,Vt.prototype.diagonal=Vt.prototype.diag,Vt.identity=Vt.eye,Vt.prototype.negate=Vt.prototype.neg,Vt.prototype.tensorProduct=Vt.prototype.kroneckerProduct;class Ot extends Vt{constructor(t,e){if(super(),Ot.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(!pt(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 Ct(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),Ct(this,t,!0),e=Float64Array.from(Rt(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){kt(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),kt(this,t,!0),e=It(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}}(Vt,Ot);class Lt extends Vt{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 Pt{constructor(t){let e,r,n,s,o,i,h,a,l,u=(t=Lt.checkMatrix(t)).clone(),c=u.rows,f=u.columns,g=new Float64Array(c),m=1;for(e=0;e<c;e++)g[e]=e;for(a=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)a[e]=u.get(e,r);for(e=0;e<c;e++){for(l=Math.min(e,r),o=0,n=0;n<l;n++)o+=u.get(e,n)*a[n];a[e]-=o,u.set(e,r,a[e])}for(s=r,e=r+1;e<c;e++)Math.abs(a[e])>Math.abs(a[s])&&(s=e);if(s!==r){for(n=0;n<f;n++)i=u.get(s,n),u.set(s,n,u.get(r,n)),u.set(r,n,i);h=g[s],g[s]=g[r],g[r]=h,m=-m}if(r<c&&0!==u.get(r,r))for(e=r+1;e<c;e++)u.set(e,r,u.get(e,r)/u.get(r,r))}this.LU=u,this.pivotVector=g,this.pivotSign=m}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=Ot.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let r,n,s,o=t.columns,i=t.subMatrixRow(this.pivotVector,0,o-1),h=e.columns;for(s=0;s<h;s++)for(r=s+1;r<h;r++)for(n=0;n<o;n++)i.set(r,n,i.get(r,n)-i.get(s,n)*e.get(r,s));for(s=h-1;s>=0;s--){for(n=0;n<o;n++)i.set(s,n,i.get(s,n)/e.get(s,s));for(r=0;r<s;r++)for(n=0;n<o;n++)i.set(r,n,i.get(r,n)-i.get(s,n)*e.get(r,s))}return i}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new Ot(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 Ot(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 qt(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 jt{constructor(t){let e,r,n,s,o=(t=Lt.checkMatrix(t)).clone(),i=t.rows,h=t.columns,a=new Float64Array(h);for(n=0;n<h;n++){let t=0;for(e=n;e<i;e++)t=qt(t,o.get(e,n));if(0!==t){for(o.get(n,n)<0&&(t=-t),e=n;e<i;e++)o.set(e,n,o.get(e,n)/t);for(o.set(n,n,o.get(n,n)+1),r=n+1;r<h;r++){for(s=0,e=n;e<i;e++)s+=o.get(e,n)*o.get(e,r);for(s=-s/o.get(n,n),e=n;e<i;e++)o.set(e,r,o.get(e,r)+s*o.get(e,n))}}a[n]=-t}this.QR=o,this.Rdiag=a}solve(t){t=Ot.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n,s,o,i,h=t.columns,a=t.clone(),l=e.columns;for(o=0;o<l;o++)for(s=0;s<h;s++){for(i=0,n=o;n<r;n++)i+=e.get(n,o)*a.get(n,s);for(i=-i/e.get(o,o),n=o;n<r;n++)a.set(n,s,a.get(n,s)+i*e.get(n,o))}for(o=l-1;o>=0;o--){for(s=0;s<h;s++)a.set(o,s,a.get(o,s)/this.Rdiag[o]);for(n=0;n<o;n++)for(s=0;s<h;s++)a.set(n,s,a.get(n,s)-a.get(o,s)*e.get(n,o))}return a.subMatrix(0,l-1,0,h-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,n=r.columns,s=new Ot(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)t<e?s.set(t,e,r.get(t,e)):t===e?s.set(t,e,this.Rdiag[t]):s.set(t,e,0);return s}get orthogonalMatrix(){let t,e,r,n,s=this.QR,o=s.rows,i=s.columns,h=new Ot(o,i);for(r=i-1;r>=0;r--){for(t=0;t<o;t++)h.set(t,r,0);for(h.set(r,r,1),e=r;e<i;e++)if(0!==s.get(r,r)){for(n=0,t=r;t<o;t++)n+=s.get(t,r)*h.get(t,e);for(n=-n/s.get(r,r),t=r;t<o;t++)h.set(t,e,h.get(t,e)+n*s.get(t,r))}}return h}}class $t{constructor(t,e={}){if((t=Lt.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:o=!0,autoTranspose:i=!1}=e;let h,a=Boolean(s),l=Boolean(o),u=!1;if(r<n)if(i){h=t.transpose(),r=h.rows,n=h.columns,u=!0;let e=a;a=l,l=e}else h=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else h=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),g=new Float64Array(f),m=new Ot(r,c),w=new Ot(n,n),d=new Float64Array(n),p=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let M=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),x=Math.max(M,b);for(let t=0;t<x;t++){if(t<M){g[t]=0;for(let e=t;e<r;e++)g[t]=qt(g[t],h.get(e,t));if(0!==g[t]){h.get(t,t)<0&&(g[t]=-g[t]);for(let e=t;e<r;e++)h.set(e,t,h.get(e,t)/g[t]);h.set(t,t,h.get(t,t)+1)}g[t]=-g[t]}for(let e=t+1;e<n;e++){if(t<M&&0!==g[t]){let n=0;for(let s=t;s<r;s++)n+=h.get(s,t)*h.get(s,e);n=-n/h.get(t,t);for(let s=t;s<r;s++)h.set(s,e,h.get(s,e)+n*h.get(s,t))}d[e]=h.get(t,e)}if(a&&t<M)for(let e=t;e<r;e++)m.set(e,t,h.get(e,t));if(t<b){d[t]=0;for(let e=t+1;e<n;e++)d[t]=qt(d[t],d[e]);if(0!==d[t]){d[t+1]<0&&(d[t]=0-d[t]);for(let e=t+1;e<n;e++)d[e]/=d[t];d[t+1]+=1}if(d[t]=-d[t],t+1<r&&0!==d[t]){for(let e=t+1;e<r;e++)p[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)p[e]+=d[r]*h.get(e,r);for(let e=t+1;e<n;e++){let n=-d[e]/d[t+1];for(let s=t+1;s<r;s++)h.set(s,e,h.get(s,e)+n*p[s])}}if(l)for(let e=t+1;e<n;e++)w.set(e,t,d[e])}}let v=Math.min(n,r+1);if(M<n&&(g[M]=h.get(M,M)),r<v&&(g[v-1]=0),b+1<v&&(d[b]=h.get(b,v-1)),d[v-1]=0,a){for(let t=M;t<c;t++){for(let e=0;e<r;e++)m.set(e,t,0);m.set(t,t,1)}for(let t=M-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!==d[t])for(let e=t+1;e<n;e++){let r=0;for(let s=t+1;s<n;s++)r+=w.get(s,t)*w.get(s,e);r=-r/w.get(t+1,t);for(let s=t+1;s<n;s++)w.set(s,e,w.get(s,e)+r*w.get(s,t))}for(let e=0;e<n;e++)w.set(e,t,0);w.set(t,t,1)}let E=v-1,_=0,S=Number.EPSILON;for(;v>0;){let t,e;for(t=v-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+S*Math.abs(g[t]+Math.abs(g[t+1]));if(Math.abs(d[t])<=e||Number.isNaN(d[t])){d[t]=0;break}}if(t===v-2)e=4;else{let r;for(r=v-1;r>=t&&r!==t;r--){let e=(r!==v?Math.abs(d[r]):0)+(r!==t+1?Math.abs(d[r-1]):0);if(Math.abs(g[r])<=S*e){g[r]=0;break}}r===t?e=3:r===v-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=d[v-2];d[v-2]=0;for(let r=v-2;r>=t;r--){let s=qt(g[r],e),o=g[r]/s,i=e/s;if(g[r]=s,r!==t&&(e=-i*d[r-1],d[r-1]=o*d[r-1]),l)for(let t=0;t<n;t++)s=o*w.get(t,r)+i*w.get(t,v-1),w.set(t,v-1,-i*w.get(t,r)+o*w.get(t,v-1)),w.set(t,r,s)}break}case 2:{let e=d[t-1];d[t-1]=0;for(let n=t;n<v;n++){let s=qt(g[n],e),o=g[n]/s,i=e/s;if(g[n]=s,e=-i*d[n],d[n]=o*d[n],a)for(let e=0;e<r;e++)s=o*m.get(e,n)+i*m.get(e,t-1),m.set(e,t-1,-i*m.get(e,n)+o*m.get(e,t-1)),m.set(e,n,s)}break}case 3:{const e=Math.max(Math.abs(g[v-1]),Math.abs(g[v-2]),Math.abs(d[v-2]),Math.abs(g[t]),Math.abs(d[t])),s=g[v-1]/e,o=g[v-2]/e,i=d[v-2]/e,h=g[t]/e,u=d[t]/e,c=((o+s)*(o-s)+i*i)/2,f=s*i*(s*i);let p=0;0===c&&0===f||(p=c<0?0-Math.sqrt(c*c+f):Math.sqrt(c*c+f),p=f/(c+p));let y=(h+s)*(h-s)+p,M=h*u;for(let e=t;e<v-1;e++){let s=qt(y,M);0===s&&(s=Number.MIN_VALUE);let o=y/s,i=M/s;if(e!==t&&(d[e-1]=s),y=o*g[e]+i*d[e],d[e]=o*d[e]-i*g[e],M=i*g[e+1],g[e+1]=o*g[e+1],l)for(let t=0;t<n;t++)s=o*w.get(t,e)+i*w.get(t,e+1),w.set(t,e+1,-i*w.get(t,e)+o*w.get(t,e+1)),w.set(t,e,s);if(s=qt(y,M),0===s&&(s=Number.MIN_VALUE),o=y/s,i=M/s,g[e]=s,y=o*d[e]+i*g[e+1],g[e+1]=-i*d[e]+o*g[e+1],M=i*d[e+1],d[e+1]=o*d[e+1],a&&e<r-1)for(let t=0;t<r;t++)s=o*m.get(t,e)+i*m.get(t,e+1),m.set(t,e+1,-i*m.get(t,e)+o*m.get(t,e+1)),m.set(t,e,s)}d[v-2]=y,_+=1;break}case 4:if(g[t]<=0&&(g[t]=g[t]<0?-g[t]:0,l))for(let e=0;e<=E;e++)w.set(e,t,-w.get(e,t));for(;t<E&&!(g[t]>=g[t+1]);){let e=g[t];if(g[t]=g[t+1],g[t+1]=e,l&&t<n-1)for(let r=0;r<n;r++)e=w.get(r,t+1),w.set(r,t+1,w.get(r,t)),w.set(r,t,e);if(a&&t<r-1)for(let n=0;n<r;n++)e=m.get(n,t+1),m.set(n,t+1,m.get(n,t)),m.set(n,t,e);t++}_=0,v--}}if(u){let t=w;w=m,m=t}this.m=r,this.n=n,this.s=g,this.U=m,this.V=w}solve(t){let e=t,r=this.threshold,n=this.s.length,s=Ot.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?s.set(t,t,0):s.set(t,t,1/this.s[t]);let o=this.U,i=this.rightSingularVectors,h=i.mmul(s),a=i.rows,l=o.rows,u=Ot.zeros(a,l);for(let t=0;t<a;t++)for(let e=0;e<l;e++){let r=0;for(let s=0;s<n;s++)r+=h.get(t,s)*o.get(e,s);u.set(t,e,r)}return u.mmul(e)}solveForDiagonal(t){return this.solve(Ot.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new Ot(r,this.s.length);for(let o=0;o<r;o++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&s.set(o,r,t.get(o,r)/this.s[r]);let o=this.U,i=o.rows,h=o.columns,a=new Ot(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let n=0;n<h;n++)r+=s.get(t,n)*o.get(e,n);a.set(t,e,r)}return a}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return Ot.diag(this.s)}}function Ut(t,e,r,n,s){let o=r*n*n,i=Ot.eye(e.length,e.length,o);const h=s(e);let a=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)a[e]=h(t.x[e]);let l=function(t,e,r,n,s){const o=r.length,i=t.x.length;let h=new Array(o);for(let a=0;a<o;a++){h[a]=new Array(i);let o=r.slice();o[a]+=n;let l=s(o);for(let r=0;r<i;r++)h[a][r]=e[r]-l(t.x[r])}return new Ot(h)}(t,a,e,n,s),u=function(t,e){const r=t.x.length;let n=new Array(r);for(let s=0;s<r;s++)n[s]=[t.y[s]-e[s]];return new Ot(n)}(t,a),c=function(t,e=!1){return t=Lt.checkMatrix(t),e?new $t(t).inverse():function(t,e,r=!1){return t=Lt.checkMatrix(t),e=Lt.checkMatrix(e),r?new $t(t).solve(e):t.isSquare()?new Pt(t).solve(e):new jt(t).solve(e)}(t,Ot.eye(t.rows))}(i.add(l.mmul(l.transpose())));return(e=(e=new Ot([e])).sub(c.mmul(l).mmul(u).mul(n).transpose())).to1DArray()}const Wt=1e-5,Gt=.001;class Ht{learningRate=1;localConnectivity=1;minDist=.1;nComponents=2;nEpochs=0;nNeighbors=15;negativeSampleRate=5;random=Math.random;repulsionStrength=1;setOpMixRatio=1;spread=1;transformQueueSize=4;targetMetric="categorical";targetWeight=.5;targetNNeighbors=15;distanceFn=Kt;knnIndices;knnDistances;graph;X;isInitialized=!1;rpForest=[];initFromRandom;initFromTree;search;searchGraph;Y;embedding=[];optimizationState=new Yt;get neighbors(){return this.nNeighbors}constructor(t={}){const e=e=>{void 0!==t[e]&&(this[e]=t[e])};e("distanceFn"),e("learningRate"),e("localConnectivity"),e("minDist"),e("nComponents"),e("nEpochs"),e("nNeighbors"),e("negativeSampleRate"),e("random"),e("repulsionStrength"),e("setOpMixRatio"),e("spread"),e("transformQueueSize"),this.targetNNeighbors=t.nNeighbors||this.nNeighbors||this.targetNNeighbors}fit(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding}async fitAsync(t,e=(()=>!0)){return this.initializeFit(t),await this.optimizeLayoutAsync(e),this.embedding}setSupervisedProjection(t,e={}){this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors}setPrecomputedKNN(t,e){this.knnIndices=t,this.knnDistances=e}initializeFit(t){if(t.length<=this.nNeighbors)throw new Error(`Not enough data points (${t.length}) to create nNeighbors: ${this.nNeighbors}. Add more data points or adjust the configuration.`);if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){const e=this.nearestNeighbors(t);this.knnIndices=e.knnIndices,this.knnDistances=e.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();const{head:e,tail:r,epochsPerSample:n}=this.initializeSimplicialSetEmbedding();return this.optimizationState.head=e,this.optimizationState.tail=r,this.optimizationState.epochsPerSample=n,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()}makeSearchFns(){const{initFromTree:t,initFromRandom:e}=(r=this.distanceFn,{initFromRandom:function(t,e,n,s,o){for(let i=0;i<n.length;i++){const h=O(t,e.length,o);for(let t=0;t<h.length;t++)h[t]<0||j(s,i,r(e[h[t]],n[i]),h[t],1)}},initFromTree:function(t,e,n,s,o){for(let i=0;i<n.length;i++){const h=ft(n[i],t,o);for(let t=0;t<h.length;t++){if(h[t]<0)return;j(s,i,r(e[h[t]],n[i]),h[t],1)}}}});var r;this.initFromTree=t,this.initFromRandom=e,this.search=function(t){return function(e,r,n,s){const{indices:o,indptr:i}=st(r);for(let r=0;r<s.length;r++){const h=new Set(n[0][r]);for(;;){const a=H(n,r);if(-1===a)break;const l=o.slice(i[a],i[a+1]);for(const o of l)o===a||-1===o||h.has(o)||($(n,r,t(e[o],s[r]),o,1),h.add(o))}}return n}}(this.distanceFn)}makeSearchGraph(t){const e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],s=new K([],[],[],n);for(let t=0;t<e.length;t++){const n=e[t],o=r[t];for(let e=0;e<n.length;e++){const r=n[e],i=o[e];i>0&&s.set(t,r,i)}}return nt(s,Y(s),((t,e)=>t>e?t:e))}transform(t){const e=this.X;if(void 0===e||0===e.length)throw new Error("No data has been fit.");let r=Math.floor(this.nNeighbors*this.transformQueueSize);r=Math.min(e.length,r);const n=function(t,e,r,n,s,o,i){const h=P(r.length,n);if(s(n,e,r,h,i),t)for(const n of t)o(n,e,r,h,i);return h}(this.rpForest,e,t,r,this.initFromRandom,this.initFromTree,this.random),s=this.search(e,this.searchGraph,n,t);let{indices:o,weights:i}=W(s);o=o.map((t=>t.slice(0,this.nNeighbors))),i=i.map((t=>t.slice(0,this.nNeighbors)));const h=Math.max(0,this.localConnectivity-1),{sigmas:a,rhos:l}=this.smoothKNNDistance(i,this.nNeighbors,h),{rows:u,cols:c,vals:f}=this.computeMembershipStrengths(o,i,a,l),g=[t.length,e.length];let m=new K(u,c,f,g);const w=st(et(m,"l1")),d=t.length,p=function(t,e,r){const n=D(t.length).map((t=>D(r[0].length)));for(let s=0;s<t.length;s++)for(let o=0;o<t[0].length;o++)for(let i=0;i<r[0].length;i++){const h=t[s][o];n[s][i]+=e[s][o]*r[h][i]}return n}(L(w.indices,d,this.nNeighbors),L(w.values,d,this.nNeighbors),this.embedding),y=this.nEpochs?this.nEpochs/3:m.nRows<=1e4?100:30,M=m.getValues().reduce(((t,e)=>e>t?e:t),0);m=m.map((t=>t<M/y?0:t)),m=tt(m);const b=this.makeEpochsPerSample(m.getValues(),y),x=m.getRows(),v=m.getCols();return this.assignOptimizationStateParameters({headEmbedding:p,tailEmbedding:this.embedding,head:x,tail:v,currentEpoch:0,nEpochs:y,nVertices:m.getDims()[1],epochsPerSample:b}),this.prepareForOptimizationLoop(),this.optimizeLayout()}processGraphForSupervisedProjection(){const{Y:t,X:e}=this;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){const e=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,e)}}}step(){const{currentEpoch:t}=this.optimizationState;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch}getEmbedding(){return this.embedding}nearestNeighbors(t){const{distanceFn:e,nNeighbors:r}=this,n=function(t,e){return function(r,n,s,o=10,i=50,h=.001,a=.5,l=!0){const u=r.length,c=P(r.length,s);for(let n=0;n<r.length;n++){const o=q(s,r.length,e);for(let e=0;e<o.length;e++){const s=t(r[n],r[o[e]]);j(c,n,s,o[e],1),j(c,o[e],s,n,1)}}if(l)for(let e=0;e<n.length;e++)for(let s=0;s<n[e].length&&!(n[e][s]<0);s++)for(let o=s+1;o<n[e].length&&!(n[e][o]<0);o++){const i=t(r[n[e][s]],r[n[e][o]]);j(c,n[e][s],i,n[e][o],1),j(c,n[e][o],i,n[e][s],1)}for(let n=0;n<o;n++){const n=U(c,u,s,i,e);let o=0;for(let s=0;s<u;s++)for(let h=0;h<i;h++){const l=Math.floor(n[0][s][h]);if(!(l<0||I(e)<a))for(let e=0;e<i;e++){const i=Math.floor(n[0][s][e]),a=n[2][s][h],u=n[2][s][e];if(i<0||!a&&!u)continue;const f=t(r[l],r[i]);o+=j(c,l,f,i,1),o+=j(c,i,f,l,1)}}if(o<=h*s*r.length)break}return W(c)}}(e,this.random),s=5+Math.floor(.5==(o=t.length**.5/20)?0:Math.round(o));var o;const i=Math.max(5,Math.floor(Math.round((t=>Math.log(t)/Math.log(2))(t.length))));this.rpForest=it(t,r,s,this.random);const h=function(t){if(t.length>0){const e=[];for(const r of t)e.push(...r.indices);return e}return[[-1]]}(this.rpForest),{indices:a,weights:l}=n(t,h,r,i);return{knnIndices:a,knnDistances:l}}fuzzySimplicialSet(t,e,r=1){const{knnIndices:n=[],knnDistances:s=[],localConnectivity:o}=this,{sigmas:i,rhos:h}=this.smoothKNNDistance(s,e,o),{rows:a,cols:l,vals:u}=this.computeMembershipStrengths(n,s,i,h),c=[t.length,t.length],f=new K(a,l,u,c),g=Y(f),m=X(f,g),w=J(Q(f,g),m);return Q(Z(w,r),Z(m,1-r))}categoricalSimplicialSetIntersection(t,e,r,n=1){let s=function(t,e,r=1,n=5){return t.map(((t,s,o)=>-1===e[s]||-1===e[o]?t*Math.exp(-r):e[s]!==e[o]?t*Math.exp(-n):t))}(t,e,n,r);return s=tt(s),function(t){const e=Y(t=et(t,"max"));return tt(t=Q(t,J(e,X(e,t))))}(s)}smoothKNNDistance(t,e,r=1,n=64,s=1){const o=Math.log(e)/Math.log(2)*s,i=D(t.length),h=D(t.length);for(let e=0;e<t.length;e++){let s=0,a=1/0,l=1;const u=t[e],c=u.filter((t=>t>0));if(c.length>=r){const t=Math.floor(r),n=r-t;t>0?(i[e]=c[t-1],n>Wt&&(i[e]+=n*(c[t]-c[t-1]))):i[e]=n*c[0]}else c.length>0&&(i[e]=B(c));for(let r=0;r<n;r++){let r=0;for(let n=1;n<t[e].length;n++){const s=t[e][n]-i[e];r+=s>0?Math.exp(-s/l):1}if(Math.abs(r-o)<Wt)break;r>o?(a=l,l=(s+a)/2):(s=l,a===1/0?l*=2:l=(s+a)/2)}if(h[e]=l,i[e]>0){const t=V(u);h[e]<Gt*t&&(h[e]=Gt*t)}else{const r=V(t.map(V));h[e]<Gt*r&&(h[e]=Gt*r)}}return{sigmas:h,rhos:i}}computeMembershipStrengths(t,e,r,n){const s=t.length,o=t[0].length,i=D(s*o),h=D(s*o),a=D(s*o);for(let l=0;l<s;l++)for(let s=0;s<o;s++){let u=0;-1!==t[l][s]&&(u=t[l][s]===l?0:e[l][s]-n[l]<=0?1:Math.exp(-(e[l][s]-n[l])/r[l]),i[l*o+s]=l,h[l*o+s]=t[l][s],a[l*o+s]=u)}return{rows:i,cols:h,vals:a}}initializeSimplicialSetEmbedding(){const t=this.getNEpochs(),{nComponents:e}=this,r=this.graph.getValues();let n=0;for(let t=0;t<r.length;t++){const e=r[t];n<r[t]&&(n=e)}const s=this.graph.map((e=>e<n/t?0:e));this.embedding=D(s.nRows).map((()=>D(e).map((()=>20*I(this.random)-10))));const o=[],i=[],h=[],a=s.getAll();for(let t=0;t<a.length;t++){const e=a[t];e.value&&(o.push(e.value),h.push(e.row),i.push(e.col))}return{head:i,tail:h,epochsPerSample:this.makeEpochsPerSample(o,t)}}makeEpochsPerSample(t,e){const r=z(t.length,-1),n=B(t),s=t.map((t=>t/n*e));return s.forEach(((t,n)=>{t>0&&(r[n]=e/s[n])})),r}assignOptimizationStateParameters(t){Object.assign(this.optimizationState,t)}prepareForOptimizationLoop(){const{repulsionStrength:t,learningRate:e,negativeSampleRate:r}=this,{epochsPerSample:n,headEmbedding:s,tailEmbedding:o}=this.optimizationState,i=s[0].length,h=s.length===o.length,a=n.map((t=>t/r)),l=[...a],u=[...n];this.assignOptimizationStateParameters({epochOfNextSample:u,epochOfNextNegativeSample:l,epochsPerNegativeSample:a,moveOther:h,initialAlpha:e,alpha:e,gamma:t,dim:i})}initializeOptimization(){const t=this.embedding,e=this.embedding,{head:r,tail:n,epochsPerSample:s}=this.optimizationState,o=this.getNEpochs(),i=this.graph.nCols,{a:h,b:a}=function(t,e){const r=function(t,e,r){return F(300).map(((t,r)=>0+r*((e-0)/299)))}(0,3*t).map((t=>t<e?1:t)),n=D(r.length).map(((n,s)=>r[s]>=e?Math.exp(-(r[s]-e)/t):n)),s={x:r,y:n},{parameterValues:o}=function(t,e,r={}){let{maxIterations:n=100,gradientDifference:s=.1,damping:o=0,errorTolerance:i=.01,minValues:h,maxValues:a,initialValues:l}=r;if(o<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!mt(t.x)||t.x.length<2||!mt(t.y)||t.y.length<2)throw new Error("The data parameter elements must be an array with more than 2 points");if(t.x.length!==t.y.length)throw new Error("The data parameter elements must have the same size");let u=l||new Array(e.length).fill(1),c=u.length;if(a=a||new Array(c).fill(Number.MAX_SAFE_INTEGER),h=h||new Array(c).fill(Number.MIN_SAFE_INTEGER),a.length!==h.length)throw new Error("minValues and maxValues must be the same size");if(!mt(u))throw new Error("initialValues must be an array");let f,g=wt(t,u,e),m=g<=i;for(f=0;f<n&&!m;f++){u=Ut(t,u,o,s,e);for(let t=0;t<c;t++)u[t]=Math.min(Math.max(h[t],u[t]),a[t]);if(g=wt(t,u,e),isNaN(g))break;m=g<=i}return{parameterValues:u,parameterError:g,iterations:f}}(s,(([t,e])=>r=>1/(1+t*r**(2*e))),{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}),[i,h]=o;return{a:i,b:h}}(this.spread,this.minDist);this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:r,tail:n,epochsPerSample:s,a:h,b:a,nEpochs:o,nVertices:i})}optimizeLayoutStep(t){const{optimizationState:e}=this,{head:r,tail:n,headEmbedding:s,tailEmbedding:o,epochsPerSample:i,epochOfNextSample:h,epochOfNextNegativeSample:a,epochsPerNegativeSample:l,moveOther:u,initialAlpha:c,alpha:f,gamma:g,a:m,b:w,dim:d,nEpochs:p,nVertices:y}=e;for(let e=0;e<i.length;e++){if(h[e]>t)continue;const c=r[e],p=n[e],M=s[c],b=o[p],x=Qt(M,b);let v=0;x>0&&(v=-2*m*w*Math.pow(x,w-1),v/=m*Math.pow(x,w)+1);for(let t=0;t<d;t++){const e=Xt(v*(M[t]-b[t]),4);M[t]+=e*f,u&&(b[t]+=-e*f)}h[e]+=i[e];const E=Math.floor((t-a[e])/l[e]);for(let t=0;t<E;t++){const t=R(y,this.random),e=o[t],r=Qt(M,e);let n=0;if(r>0)n=2*g*w,n/=(.001+r)*(m*Math.pow(r,w)+1);else if(c===t)continue;for(let t=0;t<d;t++){let r=4;n>0&&(r=Xt(n*(M[t]-e[t]),4)),M[t]+=r*f}}a[e]+=E*l[e]}return e.alpha=c*(1-t/p),e.currentEpoch+=1,s}optimizeLayoutAsync(t=(()=>!0)){return new Promise(((e,r)=>{const n=async()=>{try{const{nEpochs:r,currentEpoch:s}=this.optimizationState;this.embedding=this.optimizeLayoutStep(s);const o=this.optimizationState.currentEpoch,i=!1===t(o),h=o===r;if(i||h)return e(h);setTimeout((()=>n()),0)}catch(t){r(t)}};setTimeout((()=>n()),0)}))}optimizeLayout(t=(()=>!0)){let e=!1,r=[];for(;!e;){const{nEpochs:n,currentEpoch:s}=this.optimizationState;r=this.optimizeLayoutStep(s);const o=this.optimizationState.currentEpoch,i=!1===t(o);e=o===n||i}return r}getNEpochs(){const t=this.graph;if(this.nEpochs>0)return this.nEpochs;if(!t)return 200;const e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200}}function Kt(t,e){return Math.abs(t-e)}class Yt{currentEpoch=0;headEmbedding=[];tailEmbedding=[];head=[];tail=[];epochsPerSample=[];epochOfNextSample=[];epochOfNextNegativeSample=[];epochsPerNegativeSample=[];moveOther=!0;initialAlpha=1;alpha=1;gamma=1;a=1.5769434603113077;b=.8950608779109733;dim=2;nEpochs=500;nVertices=0}function Xt(t,e){return t>e?e:t<-e?-e:t}function Qt(t,e){let r=0;for(let n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}class Jt{_workerCount;constructor(){this._workerCount=Math.max(navigator.hardwareConcurrency-2,1)}async calc(t,e,n,s={}){const o=t.length*(t.length-1)/2,i=Math.floor(o/this._workerCount),h=t.length>2e4?await this.getMinimalThreshold(t,e,s):0;n<h&&(console.log(`using threshold ${h}`),n=h),s.threshold=n;const a=new Array(this._workerCount),l=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(471),r.b))));for(let r=0;r<this._workerCount;r++)a[r]=new Promise(((h,a)=>{const u=r*i,c=r===this._workerCount-1?o:(r+1)*i;c<=u&&h({i:new Int32Array(0),j:new Int32Array(0),distance:new Float32Array(0),idx:r}),l[r].postMessage({values:t,startIdx:u,endIdx:c,threshold:n,fnName:e,opts:s}),l[r].onmessage=({data:{error:t,i:e,j:n,distance:s}})=>{t?(l[r].terminate(),a(t)):(l[r].terminate(),h({i:e,j:n,distance:s,idx:r}))}}));const u=await Promise.all(a),c=u.reduce(((t,e)=>t+e.i.length),0),f=new Int32Array(c),g=new Int32Array(c),m=new Float32Array(c);let w=0;for(const t of u)f.set(t.i,w),g.set(t.j,w),m.set(t.distance,w),w+=t.i.length;return{i:f,j:g,distance:m}}async getKNN(t,e,r=15,n={}){return await this.multiColumnKNN([t],[e],r,[n],[1])}async multiColumnKNN(t,e,n=15,s,o,i=N.EUCLIDEAN){if(t.length!==e.length||t.length!==s.length||t.length!==o.length)throw new Error("values, distance functions, options and weights arrays should have the same length");if(t.some((e=>e.length!==t[0].length)))throw new Error("all values arrays should have the same length");const h=t[0].length*(t[0].length-1)/2,a=Math.floor(h/this._workerCount),l=new Array(this._workerCount),u=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(664),r.b))));for(let r=0;r<this._workerCount;r++)l[r]=new Promise(((l,c)=>{const f=r*a,g=r===this._workerCount-1?h:(r+1)*a;g<=f&&l({knnDistances:new Array(0),knnIndexes:new Array(0)}),u[r].postMessage({values:t,startIdx:f,endIdx:g,fnNames:e,opts:s,nNeighbours:n,weights:o,aggregationMethod:i}),u[r].onmessage=({data:{error:t,knnDistances:e,knnIndexes:n}})=>{t?(u[r].terminate(),c(t)):(u[r].terminate(),l({knnDistances:e,knnIndexes:n}))}}));const c=await Promise.all(l),f={knnDistances:new Array(t[0].length).fill(null).map((()=>new Array(n).fill(99999))),knnIndexes:new Array(t[0].length).fill(null).map((()=>new Array(n).fill(-1)))};for(const e of c)for(let r=0;r<t[0].length;++r)for(let t=0;t<e.knnDistances[r]?.length;++t)C(f.knnDistances[r],f.knnIndexes[r],e.knnDistances[r][t],e.knnIndexes[r][t]);return f}async getSampleDistances(t,e,n={}){const s=new Array(this._workerCount).fill(null).map((()=>new Worker(new URL(r.p+r.u(118),r.b)))),o=t.slice();for(let t=o.length-1;t>0;t--){const e=Math.floor(Math.random()*(t+1));[o[t],o[e]]=[o[e],o[t]]}try{const r=t.length*(t.length-1)/2,i=Math.floor(r/this._workerCount),h=1e6,a=Math.max(Math.min(r/1e3,h),Math.min(r,h)),l=Math.floor(a/this._workerCount),u=new Array(this._workerCount);for(let t=0;t<this._workerCount;t++)u[t]=new Promise(((h,a)=>{const u=t*i,c=t===this._workerCount-1?r:(t+1)*i;s[t].postMessage({values:o,startIdx:u,endIdx:c,sampleLength:l,fnName:e,opts:n}),s[t].onmessage=({data:{error:e,distance:r}})=>{s[t].terminate(),e?a(e):h({distance:r})}}));const c=await Promise.all(u),f=c.reduce(((t,e)=>t+e.distance.length),0),g=new Float32Array(f);let m=0;for(const t of c)g.set(t.distance,m),m+=t.distance.length;return g.sort(),g}catch(t){return s?.forEach((t=>t?.terminate())),console.error(t),new Float32Array(1).fill(.5)}}async getMinimalThreshold(t,e,r={}){try{const n=t.length*(t.length-1)/2,s=await this.getSampleDistances(t,e,r);return 1-s[Math.floor(7e7/n*s.length)]}catch(t){return console.error(t),.5}}static calcSync(t,e,r,n){const s=[],o=[],h=[];let a=0,l=0,u=0;const c=t.length*(t.length-1)/2;for(;a<c;){const c=A(t[l])||A(t[u])?1:r(t[l],t[u]);(Object.values(i).some((t=>t===e))?1/(1+c):1-c)>=n&&(s.push(l),o.push(u),h.push(c)),a++,u++,u===t.length&&(l++,u=l+1)}return{i:new Int32Array(s),j:new Int32Array(o),distance:new Float32Array(h)}}}var Zt=r(6377),te=r.n(Zt);class ee{data;weights;aggregationMethod;constructor(t){this.data=t.data,this.weights=t.weights,this.aggregationMethod=t.aggregationMethod}}class re extends ee{reducer;iterations;distanceFnames;distanceFns;distanceFnArgs;constructor(t){super(t),this.reducer=new u.Z(t),this.iterations=t?.iterations??100,this.distanceFnames=t.distanceFnames,this.distanceFns=t.distanceFns,this.distanceFnArgs=t.distanceFnArgs}async transform(){if(this.data[0].length>1e4)throw new Error("Maximum number of samples for T-SNE is 10000");const t=new k(!0,!1);try{const n=(e=this.aggregationMethod,r=this.weights,e===N.MANHATTAN?t=>t.reduce(((t,e,n)=>t+e*r[n]),0):t=>{const e=t.reduce(((t,e,n)=>t+(e*r[n])**2),0);return Math.sqrt(e)}),s=[];for(let e=0;e<this.data.length;++e){const r=await t.calc(this.data[e],this.distanceFnames[e],!1,this.distanceFnArgs[e]);s.push(r)}const o=new Float32Array(s[0].length).fill(0);for(let t=0;t<s[0].length;++t)o[t]=n(s.map((e=>e[t])));const i=function(t,e){const r=function(t){return(e,r)=>t*e+r-Math.floor((e+2)*(e+1)/2)}(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)}(o,this.data[0].length);this.reducer.initDataDist(i);for(let t=0;t<this.iterations;++t)this.reducer.step();return t.terminate(),this.reducer.getSolution()}catch(e){throw t.terminate(),e}var e,r}}class ne extends ee{reducer;distanceFnames;distanceFns;vectors;progressFunc;distanceFnArgs;constructor(t){const e=t.randomSeed??Date(),r=te()(e);console.log(e),console.log(r(),r(),r()),super(t),p("distanceFnames"in t),p("distanceFns"in t),this.distanceFnArgs=t.distanceFnArgs,this.distanceFns=t.distanceFns,this.progressFunc=t.progressFunc,this.distanceFnames=t.distanceFnames,this.vectors=new Array(this.data[0].length).fill(0).map(((t,e)=>e)),this.data[0].length<15&&(t.nNeighbors=this.data[0].length-1),t.random=r,this.reducer=new Ht(t)}async transform(t){console.time("knn graph");const e=await(new Jt).multiColumnKNN(this.data,this.distanceFnames,this.reducer.neighbors,this.distanceFnArgs,this.weights,this.aggregationMethod);console.timeEnd("knn graph"),this.reducer.setPrecomputedKNN(e.knnIndexes,e.knnDistances),await new Promise((t=>{setTimeout((()=>{t()}),300)}));const r=await this.reducer.fitAsync(this.vectors,(t=>{this.progressFunc&&this.progressFunc(t,this.reducer.getNEpochs(),this.reducer.getEmbedding())}));return s=r,new Array(s.length).fill(0).map(((t,e)=>n.from(s[e])));var s}}const se={UMAP:ne,"t-SNE":re};class oe{reducer;constructor(t,e,r,n,s,o){const i=[];for(let e=0;e<r.length;++e){const n=new S(r[e]).getMeasure(o.distanceFnArgs[e]);i.push(n);let s=2048;for(let r=0;r<t[e].length;++r)if(t[e][r]&&t[e][r]._length){s=t[e][r]._length;break}if(h=r[e],"BitArray"==_[h])for(let r=0;r<t[e].length;++r)t[e][r]&&t[e][r]._data?t[e][r]=new g(t[e][r]._data,t[e][r]._length):t[e][r]=new g(s)}var h;"UMAP"==e?this.reducer=new ne({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:n,aggregationMethod:s,...o}):"t-SNE"==e&&(this.reducer=new re({data:t,distanceFnames:r,distanceFns:i,distanceFnArgs:o.distanceFnArgs,weights:n,aggregationMethod:s,...o}))}async transform(t=!1){if(void 0===this.reducer)throw new Error("Reducer was not defined.");let e=await this.reducer.transform();var r;return t&&(r=e,e=new Array(r[0].length).fill(0).map(((t,e)=>new n(r.length).fill(0).map(((t,n)=>r[n][e]))))),e}static availableMetricsByType(t){return Object.keys(E[t])}static get availableMethods(){return Object.keys(se)}static get availableMetrics(){let t=[];return Object.values(E).forEach((e=>{const r=Object.values(e);t=[...t,...r]})),t}}async function ie(t,e,r){t%5==0&&self.postMessage({epochNum:t,epochsLength:e,embedding:r})}self.onmessage=async({data:{columnsData:t,method:e,distanceMetrics:r,options:n,weights:s,aggregationMethod:o}})=>{let i;try{const h=await async function(t,e,r,n,s,o){const i=new oe(t,e,r,n,s,{...o,progressFunc:ie});return await i.transform(!0)}(t,e,r,s,o,n);i={embedding:h}}catch(t){i={error:t}}self.postMessage({error:i.error,embedding:i.embedding})}},7659:(t,e,r)=>{"use strict";e.Z=void 0;var n=r(6215);Object.defineProperty(e,"Z",{enumerable:!0,get:function(){return n.TSNE}})},6215:(t,e)=>{"use strict";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 o=0;o<t;o++){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],o=e[s];n+=(r-o)*(r-o)}return n}xtod(t){const e=t.length,r=this.zeros(e*e);for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){const o=this.L2(t[n],t[s]);r[n*e+s]=o,r[s*e+n]=o}return r}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 o=Math.log(e),i=this.zeros(s*s),h=this.zeros(s);for(let e=0;e<s;e++){let n=-1/0,a=1/0,l=1,u=!1;const c=50;let f=0;for(;!u;){let i=0;for(let r=0;r<s;r++){let n=Math.exp(-t[e*s+r]*l);e===r&&(n=0),h[r]=n,i+=n}let g=0;for(let t=0;t<s;t++){let e;e=0===i?0:h[t]/i,h[t]=e,e>1e-7&&(g-=e*Math.log(e))}g>o?(n=l,a===1/0?l*=2:l=(l+a)/2):(a=l,n===-1/0?l/=2:l=(l+n)/2),f++,Math.abs(g-o)<r&&(u=!0),f>=c&&(u=!0)}for(let t=0;t<s;t++)i[e*s+t]=h[t]}const a=this.zeros(s*s),l=2*s;for(let t=0;t<s;t++)for(let e=0;e<s;e++)a[t*s+e]=Math.max((i[t*s+e]+i[e*s+t])/l,1e-100);return a}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 o=t[n][s];r[n*e+s]=o,r[s*e+n]=o}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],o=this.ystep[e][t],i=this.gains[e][t];let h=this.sign(r)===this.sign(o)?.8*i:i+.2;h<.01&&(h=.01),this.gains[e][t]=h;const a=(this.iter<250?.5:.8)*o-this.epsilon*h*n[e][t];this.ystep[e][t]=a,this.Y[e][t]+=a,s[t]+=this.Y[e][t]}for(let e=0;e<t;e++)for(let r=0;r<this.dim;r++)this.Y[e][r]-=s[r]/t;return r}debugGrad(){const t=this.N,e=this.costGrad(this.Y),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 o=this.costGrad(this.Y);this.Y[e][t]=s-n;const i=this.costGrad(this.Y),h=r[e][t],a=(o.cost-i.cost)/(2*n);console.log(e+","+t+": gradcheck analytic: "+h+" vs. numerical: "+a),this.Y[e][t]=s}}costGrad(t){const e=this.N,r=this.dim,n=this.P,s=this.iter<100?4:1,o=this.zeros(e*e);let i=0;for(let n=0;n<e;n++)for(let s=n+1;s<e;s++){let h=0;for(let e=0;e<r;e++){const r=t[n][e]-t[s][e];h+=r*r}const a=1/(1+h);o[n*e+s]=a,o[s*e+n]=a,i+=2*a}const h=e*e,a=this.zeros(h);for(let t=0;t<h;t++)a[t]=Math.max(o[t]/i,1e-100);let l=0;const u=[];for(let i=0;i<e;i++){const h=new Array(r);for(let t=0;t<r;t++)h[t]=0;for(let u=0;u<e;u++){l+=-n[i*e+u]*Math.log(a[i*e+u]);const c=4*(s*n[i*e+u]-a[i*e+u])*o[i*e+u];for(let e=0;e<r;e++)h[e]+=c*(t[i][e]-t[u][e])}u.push(h)}return{cost:l,grad:u}}}},6377:(t,e,r)=>{var n=r(4832),s=r(8652),o=r(801),i=r(2030),h=r(3618),a=r(9049),l=r(1971);l.alea=n,l.xor128=s,l.xorwow=o,l.xorshift7=i,l.xor4096=h,l.tychei=a,t.exports=l},4832:function(t,e,r){var n;!function(t,s,o){function i(t){var e,r=this,n=(e=4022871197,function(t){t=String(t);for(var r=0;r<t.length;r++){var n=.02519603282416938*(e+=t.charCodeAt(r));n-=e=n>>>0,e=(n*=e)>>>0,e+=4294967296*(n-=e)}return 2.3283064365386963e-10*(e>>>0)});r.next=function(){var t=2091639*r.s0+2.3283064365386963e-10*r.c;return r.s0=r.s1,r.s1=r.s2,r.s2=t-(r.c=0|t)},r.c=1,r.s0=n(" "),r.s1=n(" "),r.s2=n(" "),r.s0-=n(t),r.s0<0&&(r.s0+=1),r.s1-=n(t),r.s1<0&&(r.s1+=1),r.s2-=n(t),r.s2<0&&(r.s2+=1),n=null}function h(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function a(t,e){var r=new i(t),n=e&&e.state,s=r.next;return s.int32=function(){return 4294967296*r.next()|0},s.double=function(){return s()+11102230246251565e-32*(2097152*s()|0)},s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.alea=a}(0,t=r.nmd(t),r.amdD)},9049:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this,r="";e.next=function(){var t=e.b,r=e.c,n=e.d,s=e.a;return t=t<<25^t>>>7^r,r=r-n|0,n=n<<24^n>>>8^s,s=s-t|0,e.b=t=t<<20^t>>>12^r,e.c=r=r-n|0,e.d=n<<16^r>>>16^s,e.a=s-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):r+=t;for(var n=0;n<r.length+20;n++)e.b^=0|r.charCodeAt(n),e.next()}function h(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function a(t,e){var r=new i(t),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.tychei=a}(0,t=r.nmd(t),r.amdD)},8652:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this,r="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:r+=t;for(var n=0;n<r.length+64;n++)e.x^=0|r.charCodeAt(n),e.next()}function h(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function a(t,e){var r=new i(t),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xor128=a}(0,t=r.nmd(t),r.amdD)},3618:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this;e.next=function(){var t,r,n=e.w,s=e.X,o=e.i;return e.w=n=n+1640531527|0,r=s[o+34&127],t=s[o=o+1&127],r^=r<<13,t^=t<<17,r^=r>>>15,t^=t>>>12,r=s[o]=r^t,e.i=o,r+(n^n>>>16)|0},function(t,e){var r,n,s,o,i,h=[],a=128;for(e===(0|e)?(n=e,e=null):(e+="\0",n=0,a=Math.max(a,e.length)),s=0,o=-32;o<a;++o)e&&(n^=e.charCodeAt((o+32)%e.length)),0===o&&(i=n),n^=n<<10,n^=n>>>15,n^=n<<4,n^=n>>>13,o>=0&&(i=i+1640531527|0,s=0==(r=h[127&o]^=n+i)?s+1:0);for(s>=128&&(h[127&(e&&e.length||0)]=-1),s=127,o=512;o>0;--o)n=h[s+34&127],r=h[s=s+1&127],n^=n<<13,r^=r<<17,n^=n>>>15,r^=r>>>12,h[s]=n^r;t.w=i,t.X=h,t.i=s}(e,t)}function h(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function a(t,e){null==t&&(t=+new Date);var r=new i(t),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&(n.X&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xor4096=a}(0,t=r.nmd(t),r.amdD)},2030:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this;e.next=function(){var t,r,n=e.x,s=e.i;return t=n[s],r=(t^=t>>>7)^t<<24,r^=(t=n[s+1&7])^t>>>10,r^=(t=n[s+3&7])^t>>>3,r^=(t=n[s+4&7])^t<<7,t=n[s+7&7],r^=(t^=t<<13)^t<<9,n[s]=r,e.i=s+1&7,r},function(t,e){var r,n=[];if(e===(0|e))n[0]=e;else for(e=""+e,r=0;r<e.length;++r)n[7&r]=n[7&r]<<15^e.charCodeAt(r)+n[r+1&7]<<13;for(;n.length<8;)n.push(0);for(r=0;r<8&&0===n[r];++r);for(8==r?n[7]=-1:n[r],t.x=n,t.i=0,r=256;r>0;--r)t.next()}(e,t)}function h(t,e){return e.x=t.x.slice(),e.i=t.i,e}function a(t,e){null==t&&(t=+new Date);var r=new i(t),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&(n.x&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xorshift7=a}(0,t=r.nmd(t),r.amdD)},801:function(t,e,r){var n;!function(t,s,o){function i(t){var e=this,r="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:r+=t;for(var n=0;n<r.length+64;n++)e.x^=0|r.charCodeAt(n),n==r.length&&(e.d=e.x<<10^e.x>>>4),e.next()}function h(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function a(t,e){var r=new i(t),n=e&&e.state,s=function(){return(r.next()>>>0)/4294967296};return s.double=function(){do{var t=((r.next()>>>11)+(r.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},s.int32=r.next,s.quick=s,n&&("object"==typeof n&&h(n,r),s.state=function(){return h(r,{})}),s}s&&s.exports?s.exports=a:r.amdD&&r.amdO?void 0===(n=function(){return a}.call(e,r,e,s))||(s.exports=n):this.xorwow=a}(0,t=r.nmd(t),r.amdD)},1971:function(t,e,r){var n;!function(s,o,i){var h,a=256,l=6,u="random",c=i.pow(a,l),f=i.pow(2,52),g=2*f,m=a-1;function w(t,e,r){var n=[],m=M(y((e=1==e?{entropy:!0}:e||{}).entropy?[t,b(o)]:null==t?function(){try{var t;return h&&(t=h.randomBytes)?t=t(a):(t=new Uint8Array(a),(s.crypto||s.msCrypto).getRandomValues(t)),b(t)}catch(t){var e=s.navigator,r=e&&e.plugins;return[+new Date,s,r,s.screen,b(o)]}}():t,3),n),w=new d(n),x=function(){for(var t=w.g(l),e=c,r=0;t<f;)t=(t+r)*a,e*=a,r=w.g(1);for(;t>=g;)t/=2,e/=2,r>>>=1;return(t+r)/e};return x.int32=function(){return 0|w.g(4)},x.quick=function(){return w.g(4)/4294967296},x.double=x,M(b(w.S),o),(e.pass||r||function(t,e,r,n){return n&&(n.S&&p(n,w),t.state=function(){return p(w,{})}),r?(i[u]=t,e):t})(x,m,"global"in e?e.global:this==i,e.state)}function d(t){var e,r=t.length,n=this,s=0,o=n.i=n.j=0,i=n.S=[];for(r||(t=[r++]);s<a;)i[s]=s++;for(s=0;s<a;s++)i[s]=i[o=m&o+t[s%r]+(e=i[s])],i[o]=e;(n.g=function(t){for(var e,r=0,s=n.i,o=n.j,i=n.S;t--;)e=i[s=m&s+1],r=r*a+i[m&(i[s]=i[o=m&o+e])+(i[o]=e)];return n.i=s,n.j=o,r})(a)}function p(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function y(t,e){var r,n=[],s=typeof t;if(e&&"object"==s)for(r in t)try{n.push(y(t[r],e-1))}catch(t){}return n.length?n:"string"==s?t:t+"\0"}function M(t,e){for(var r,n=t+"",s=0;s<n.length;)e[m&s]=m&(r^=19*e[m&s])+n.charCodeAt(s++);return b(e)}function b(t){return String.fromCharCode.apply(0,t)}if(M(i.random(),o),t.exports){t.exports=w;try{h=r(5042)}catch(t){}}else void 0===(n=function(){return w}.call(e,r,e,t))||(t.exports=n)}("undefined"!=typeof self?self:this,[],Math)}}]);
3
3
  //# sourceMappingURL=886.js.map