@elarsaks/umap-wasm 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +349 -0
- package/dist/src/heap.d.ts +12 -0
- package/dist/src/heap.js +226 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/lib.d.ts +1 -0
- package/dist/src/lib.js +5 -0
- package/dist/src/matrix.d.ts +41 -0
- package/dist/src/matrix.js +360 -0
- package/dist/src/nn_descent.d.ts +17 -0
- package/dist/src/nn_descent.js +204 -0
- package/dist/src/tree.d.ts +16 -0
- package/dist/src/tree.js +320 -0
- package/dist/src/umap.d.ts +102 -0
- package/dist/src/umap.js +842 -0
- package/dist/src/utils.d.ts +16 -0
- package/dist/src/utils.js +137 -0
- package/dist/src/wasmBridge.d.ts +57 -0
- package/dist/src/wasmBridge.js +290 -0
- package/dist/test/matrix.test.d.ts +1 -0
- package/dist/test/matrix.test.js +169 -0
- package/dist/test/nn_descent.test.d.ts +1 -0
- package/dist/test/nn_descent.test.js +58 -0
- package/dist/test/test_data.d.ts +13 -0
- package/dist/test/test_data.js +1054 -0
- package/dist/test/tree.test.d.ts +1 -0
- package/dist/test/tree.test.js +60 -0
- package/dist/test/umap.test.d.ts +1 -0
- package/dist/test/umap.test.js +293 -0
- package/dist/test/utils.test.d.ts +1 -0
- package/dist/test/utils.test.js +128 -0
- package/dist/test/wasmDistance.test.d.ts +1 -0
- package/dist/test/wasmDistance.test.js +124 -0
- package/dist/test/wasmMatrix.test.d.ts +1 -0
- package/dist/test/wasmMatrix.test.js +389 -0
- package/dist/test/wasmTree.test.d.ts +1 -0
- package/dist/test/wasmTree.test.js +212 -0
- package/lib/umap-js.js +8657 -0
- package/lib/umap-js.min.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.UMAP=e():t.UMAP=e()}(this,()=>(()=>{var t={24(t,e,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||(n=function(t){return n=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},n(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=n(t),i=0;i<r.length;i++)"default"!==r[i]&&o(e,t,r[i]);return s(e,t),e});Object.defineProperty(e,"__esModule",{value:!0}),e.makeHeap=u,e.rejectionSample=function(t,e,r){for(var n=a.zeros(t),o=0;o<t;o++){for(var s=!0,i=0;s;){i=a.tauRandInt(e,r);for(var u=!1,h=0;h<o;h++)if(i===n[h]){u=!0;break}u||(s=!1)}n[o]=i}return n},e.heapPush=h,e.uncheckedHeapPush=l,e.buildCandidates=function(t,e,r,n,o){for(var s=u(e,n),i=0;i<e;i++)for(var l=0;l<r;l++)if(!(t[0][i][l]<0)){var c=t[0][i][l],f=t[2][i][l],m=a.tauRand(o);h(s,i,m,c,f),h(s,c,m,i,f),t[2][i][l]=0}return s},e.deheapSort=function(t){for(var e=t[0],r=t[1],n=0;n<e.length;n++)for(var o=e[n],s=r[n],i=0;i<o.length-1;i++){var a=o.length-i-1,u=s.length-i-1,h=o[0];o[0]=o[a],o[a]=h;var l=s[0];s[0]=s[u],s[u]=l,c(s,o,u,0)}return{indices:e,weights:r}},e.smallestFlagged=function(t,e){for(var r=t[0][e],n=t[1][e],o=t[2][e],s=1/0,i=-1,a=0;a>r.length;a++)1===o[a]&&n[a]<s&&(s=n[a],i=a);return i>=0?(o[i]=0,Math.floor(r[i])):-1};var a=i(r(185));function u(t,e){var r=function(r){return a.empty(t).map(function(){return a.filled(e,r)})},n=[];return n.push(r(-1)),n.push(r(1/0)),n.push(r(0)),n}function h(t,e,r,n,o){e=Math.floor(e);var s=t[0][e],i=t[1][e];if(t[2][e],r>=i[0])return 0;for(var a=0;a<s.length;a++)if(n===s[a])return 0;return l(t,e,r,n,o)}function l(t,e,r,n,o){var s=t[0][e],i=t[1][e],a=t[2][e];if(r>=i[0])return 0;i[0]=r,s[0]=n,a[0]=o;for(var u=0,h=0;;){var l=2*u+1,c=l+1,f=t[0][0].length;if(l>=f)break;if(c>=f){if(!(i[l]>r))break;h=l}else if(i[l]>=i[c]){if(!(r<i[l]))break;h=l}else{if(!(r<i[c]))break;h=c}i[u]=i[h],s[u]=s[h],a[u]=a[h],u=h}return i[u]=r,s[u]=n,a[u]=o,1}function c(t,e,r,n){for(;2*n+1<r;){var o=2*n+1,s=o+1,i=n;if(t[i]<t[o]&&(i=o),s<r&&t[i]<t[s]&&(i=s),i===n)break;var a=t[n];t[n]=t[i],t[i]=a;var u=e[n];e[n]=e[i],e[i]=u,n=i}}},47(t,e,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||(n=function(t){return n=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},n(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=n(t),i=0;i<r.length;i++)"default"!==r[i]&&o(e,t,r[i]);return s(e,t),e}),a=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0}),e.makeNNDescent=function(t,e){return function(r,n,o,s,i,a,h,l){void 0===s&&(s=10),void 0===i&&(i=50),void 0===a&&(a=.001),void 0===h&&(h=.5),void 0===l&&(l=!0);for(var f=r.length,m=u.makeHeap(r.length,o),g=0;g<r.length;g++)for(var p=u.rejectionSample(o,r.length,e),w=0;w<p.length;w++){var d=t(r[g],r[p[w]]);u.heapPush(m,g,d,p[w],1),u.heapPush(m,p[w],d,g,1)}if(l)for(var y=0;y<n.length;y++)for(g=0;g<n[y].length&&!(n[y][g]<0);g++)for(w=g+1;w<n[y].length&&!(n[y][w]<0);w++)d=t(r[n[y][g]],r[n[y][w]]),u.heapPush(m,n[y][g],d,n[y][w],1),u.heapPush(m,n[y][w],d,n[y][g],1);for(y=0;y<s;y++){var v=u.buildCandidates(m,f,o,i,e),b=0;for(g=0;g<f;g++)for(w=0;w<i;w++){var M=Math.floor(v[0][g][w]);if(!(M<0||c.tauRand(e)<h))for(var x=0;x<i;x++){var S=Math.floor(v[0][g][x]),E=v[2][g][w],A=v[2][g][x];S<0||!E&&!A||(d=t(r[M],r[S]),b+=u.heapPush(m,M,d,S,1),b+=u.heapPush(m,S,d,M,1))}}if(b<=a*o*r.length)break}return u.deheapSort(m)}},e.makeInitializations=function(t){return{initFromRandom:function(e,r,n,o,s){for(var i=0;i<n.length;i++)for(var a=c.rejectionSample(e,r.length,s),h=0;h<a.length;h++)if(!(a[h]<0)){var l=t(r[a[h]],n[i]);u.heapPush(o,i,l,a[h],1)}},initFromTree:function(e,r,n,o,s){for(var i=0;i<n.length;i++)for(var a=l.searchFlatTree(n[i],e,s),h=0;h<a.length;h++){if(a[h]<0)return;var c=t(r[a[h]],n[i]);u.heapPush(o,i,c,a[h],1)}}}},e.makeInitializedNNSearch=function(t){return function(e,r,n,o){for(var s,i,l=h.getCSR(r),c=l.indices,f=l.indptr,m=0;m<o.length;m++)for(var g=new Set(n[0][m]);;){var p=u.smallestFlagged(n,m);if(-1===p)break;var w=c.slice(f[p],f[p+1]);try{for(var d=(s=void 0,a(w)),y=d.next();!y.done;y=d.next()){var v=y.value;if(v!==p&&-1!==v&&!g.has(v)){var b=t(e[v],o[m]);u.uncheckedHeapPush(n,m,b,v,1),g.add(v)}}}catch(t){s={error:t}}finally{try{y&&!y.done&&(i=d.return)&&i.call(d)}finally{if(s)throw s.error}}}return n}},e.initializeSearch=function(t,e,r,n,o,s,i){var h,l,c=u.makeHeap(r.length,n);if(o(n,e,r,c,i),t)try{for(var f=a(t),m=f.next();!m.done;m=f.next())s(m.value,e,r,c,i)}catch(t){h={error:t}}finally{try{m&&!m.done&&(l=f.return)&&l.call(f)}finally{if(h)throw h.error}}return c};var u=i(r(24)),h=i(r(499)),l=i(r(450)),c=i(r(185))},103(t,e,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||(n=function(t){return n=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},n(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=n(t),i=0;i<r.length;i++)"default"!==r[i]&&o(e,t,r[i]);return s(e,t),e}),a=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(o,s){function i(t){try{u(n.next(t))}catch(t){s(t)}}function a(t){try{u(n.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(i,a)}u((n=n.apply(t,e||[])).next())})},u=this&&this.__generator||function(t,e){var r,n,o,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.initWasm=function(){return a(this,void 0,void 0,function(){var t=this;return u(this,function(e){return h||(h=a(t,void 0,void 0,function(){var t,e,n,o;return u(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),t="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node,e=t?"../wasm/pkg/node/umap_wasm_core.js":"../wasm/pkg/web/umap_wasm_core.js",[4,Promise.resolve("".concat(e)).then(function(t){return i(r(589)(t))})];case 1:return n=s.sent(),l=n,[2,n];case 2:throw o=s.sent(),h=null,l=null,new Error("Failed to load WASM module: ".concat(o));case 3:return[2]}})})),[2,h]})})},e.isWasmAvailable=function(){return null!==l},e.euclideanWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");var r=new Float64Array(t),n=new Float64Array(e);return l.euclidean(r,n)},e.cosineWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");var r=new Float64Array(t),n=new Float64Array(e);return l.cosine(r,n)},e.buildRpTreeWasm=function(t,e,r,n,o){if(!l)throw new Error("WASM module not initialized");for(var s=new Float64Array(e*r),i=0;i<e;i++)for(var a=0;a<r;a++)s[i*r+a]=t[i][a];return l.build_rp_tree(s,e,r,n,BigInt(o))},e.searchFlatTreeWasm=function(t,e,r){if(!l)throw new Error("WASM module not initialized");var n=new Float64Array(e),o=l.search_flat_tree(t,n,BigInt(r));return Array.from(o)},e.wasmTreeToJs=function(t){for(var e=Array.from(t.hyperplanes()),r=Array.from(t.offsets()),n=Array.from(t.children()),o=Array.from(t.indices()),s=t.dim(),i=t.n_nodes(),a=[],u=0;u<i;u++)a.push(e.slice(u*s,(u+1)*s));var h=[];for(u=0;u<i;u++)h.push([n[2*u],n[2*u+1]]);var l=0;for(u=0;u<n.length;u++){var c=n[u];if(c<=0){var f=-c;f>l&&(l=f)}}var m=l+1,g=m>0?Math.floor(o.length/m):0,p=[];for(u=0;u<m;u++){for(var w=o.slice(u*g,(u+1)*g);w.length<g;)w.push(-1);p.push(w)}return{hyperplanes:a,offsets:r,children:h,indices:p}},e.createSparseMatrixWasm=function(t,e,r,n,o){if(!l)throw new Error("WASM module not initialized");var s=new Int32Array(t),i=new Int32Array(e),a=new Float64Array(r);return new l.WasmSparseMatrix(s,i,a,n,o)},e.sparseTransposeWasm=function(t){if(!l)throw new Error("WASM module not initialized");return l.sparse_transpose(t)},e.sparseIdentityWasm=function(t){if(!l)throw new Error("WASM module not initialized");return l.sparse_identity(t)},e.sparseAddWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");return l.sparse_add(t,e)},e.sparseSubtractWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");return l.sparse_subtract(t,e)},e.sparsePairwiseMultiplyWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");return l.sparse_pairwise_multiply(t,e)},e.sparseMaximumWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");return l.sparse_maximum(t,e)},e.sparseMultiplyScalarWasm=function(t,e){if(!l)throw new Error("WASM module not initialized");return l.sparse_multiply_scalar(t,e)},e.sparseEliminateZerosWasm=function(t){if(!l)throw new Error("WASM module not initialized");return l.sparse_eliminate_zeros(t)},e.sparseNormalizeWasm=function(t,e){if(void 0===e&&(e="l2"),!l)throw new Error("WASM module not initialized");return l.sparse_normalize(t,e)},e.sparseGetCSRWasm=function(t){if(!l)throw new Error("WASM module not initialized");var e=Array.from(l.sparse_get_csr(t)),r=e[0],n=e[1],o=e[2];return{indices:e.slice(3,3+r),values:e.slice(3+r,3+r+n),indptr:e.slice(3+r+n,3+r+n+o)}},e.wasmSparseMatrixToArray=function(t){for(var e=Array.from(t.to_array()),r=t.n_rows,n=t.n_cols,o=[],s=0;s<r;s++)o.push(e.slice(s*n,(s+1)*n));return o},e.wasmSparseMatrixGetAll=function(t){for(var e=Array.from(t.get_all_ordered()),r=[],n=0;n<e.length;n+=3)r.push({row:e[n],col:e[n+1],value:e[n+2]});return r};var h=null,l=null},185(t,e){"use strict";var r=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};function n(t,e){return Math.floor(e()*t)}function o(t){for(var e=[],r=0;r<t;r++)e.push(void 0);return e}function s(t,e){return o(t).map(function(){return e})}function i(t){return s(t,0)}function a(t){return t.reduce(function(t,e){return t+e})}Object.defineProperty(e,"__esModule",{value:!0}),e.tauRandInt=n,e.tauRand=function(t){return t()},e.norm=function(t){var e,n,o=0;try{for(var s=r(t),i=s.next();!i.done;i=s.next()){var a=i.value;o+=Math.pow(a,2)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}return Math.sqrt(o)},e.empty=o,e.range=function(t){return o(t).map(function(t,e){return e})},e.filled=s,e.zeros=i,e.ones=function(t){return s(t,1)},e.linear=function(t,e,r){return o(r).map(function(n,o){return t+o*((e-t)/(r-1))})},e.sum=a,e.mean=function(t){return a(t)/t.length},e.max=function(t){for(var e=0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return e},e.max2d=function(t){for(var e=0,r=0;r<t.length;r++)for(var n=0;n<t[r].length;n++)e=t[r][n]>e?t[r][n]:e;return e},e.rejectionSample=function(t,e,r){for(var o=i(t),s=0;s<t;s++)for(var a=!0;a;){for(var u=n(e,r),h=!1,l=0;l<s;l++)if(u===o[l]){h=!0;break}h||(a=!1),o[s]=u}return o},e.reshape2d=function(t,e,r){var n=[],o=0;if(t.length!==e*r)throw new Error("Array dimensions must match input length.");for(var s=0;s<e;s++){for(var i=[],a=0;a<r;a++)i.push(t[o]),o+=1;n.push(i)}return n}},329(t,e,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||(n=function(t){return n=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},n(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=n(t),i=0;i<r.length;i++)"default"!==r[i]&&o(e,t,r[i]);return s(e,t),e}),a=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(o,s){function i(t){try{u(n.next(t))}catch(t){s(t)}}function a(t){try{u(n.throw(t))}catch(t){s(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(i,a)}u((n=n.apply(t,e||[])).next())})},u=this&&this.__generator||function(t,e){var r,n,o,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},h=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,s=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(n=s.next()).done;)i.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return i},l=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var n,o=0,s=e.length;o<s;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))},c=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.UMAP=void 0,e.euclidean=x,e.cosine=function(t,e){for(var r=0,n=0,o=0,s=0;s<t.length;s++)r+=t[s]*e[s],n+=Math.pow(t[s],2),o+=Math.pow(e[s],2);return 0===n&&0===o?0:0===n||0===o?1:1-r/Math.sqrt(n*o)},e.findABParams=R,e.fastIntersection=_,e.resetLocalConnectivity=N,e.initTransform=k;var f=i(r(24)),m=i(r(499)),g=i(r(47)),p=i(r(450)),w=i(r(185)),d=c(r(527)),y=i(r(103)),v=1e-5,b=.001,M=function(){function t(t){void 0===t&&(t={});var e=this;this.learningRate=1,this.localConnectivity=1,this.minDist=.1,this.nComponents=2,this.nEpochs=0,this.nNeighbors=15,this.negativeSampleRate=5,this.random=Math.random,this.repulsionStrength=1,this.setOpMixRatio=1,this.spread=1,this.transformQueueSize=4,this.targetMetric="categorical",this.targetWeight=.5,this.targetNNeighbors=this.nNeighbors,this.distanceFn=x,this.useWasmDistance=!1,this.useWasmMatrix=!1,this.useWasmTree=!1,this.isInitialized=!1,this.rpForest=[],this.embedding=[],this.optimizationState=new S;var r=function(r){void 0!==t[r]&&(e[r]=t[r])};r("distanceFn"),r("useWasmDistance"),r("useWasmMatrix"),r("useWasmTree"),r("learningRate"),r("localConnectivity"),r("minDist"),r("nComponents"),r("nEpochs"),r("nNeighbors"),r("negativeSampleRate"),r("random"),r("repulsionStrength"),r("setOpMixRatio"),r("spread"),r("transformQueueSize")}return t.prototype.fit=function(t){return this.initializeFit(t),this.optimizeLayout(),this.embedding},t.prototype.fitAsync=function(t){return a(this,arguments,void 0,function(t,e){return void 0===e&&(e=function(){return!0}),u(this,function(r){switch(r.label){case 0:return this.initializeFit(t),[4,this.optimizeLayoutAsync(e)];case 1:return r.sent(),[2,this.embedding]}})})},t.prototype.setSupervisedProjection=function(t,e){void 0===e&&(e={}),this.Y=t,this.targetMetric=e.targetMetric||this.targetMetric,this.targetWeight=e.targetWeight||this.targetWeight,this.targetNNeighbors=e.targetNNeighbors||this.targetNNeighbors},t.prototype.setPrecomputedKNN=function(t,e){this.knnIndices=t,this.knnDistances=e},t.prototype.initializeFit=function(t){if(t.length<=this.nNeighbors)throw new Error("Not enough data points (".concat(t.length,") to create nNeighbors: ").concat(this.nNeighbors,". Add more data points or adjust the configuration."));if(this.X===t&&this.isInitialized)return this.getNEpochs();if(this.X=t,!this.knnIndices&&!this.knnDistances){var e=this.nearestNeighbors(t);this.knnIndices=e.knnIndices,this.knnDistances=e.knnDistances}this.graph=this.fuzzySimplicialSet(t,this.nNeighbors,this.setOpMixRatio),this.makeSearchFns(),this.searchGraph=this.makeSearchGraph(t),this.processGraphForSupervisedProjection();var r=this.initializeSimplicialSetEmbedding(),n=r.head,o=r.tail,s=r.epochsPerSample;return this.optimizationState.head=n,this.optimizationState.tail=o,this.optimizationState.epochsPerSample=s,this.initializeOptimization(),this.prepareForOptimizationLoop(),this.isInitialized=!0,this.getNEpochs()},t.prototype.makeSearchFns=function(){var t=this,e=function(e,r){if(t.useWasmDistance){if(!y.isWasmAvailable())throw new Error("WASM distance requested via `useWasmDistance: true` but the wasm module is not initialized or available. Call `await wasmBridge.initWasm()` before using UMAP with wasm distances or build the wasm package.");return y.euclideanWasm(e,r)}return t.distanceFn(e,r)},r=g.makeInitializations(e),n=r.initFromTree,o=r.initFromRandom;this.initFromTree=n,this.initFromRandom=o,this.search=g.makeInitializedNNSearch(e)},t.prototype.computeDistance=function(t,e){if(this.useWasmDistance){if(!y.isWasmAvailable())throw new Error("WASM distance requested via `useWasmDistance: true` but the wasm module is not initialized or available. Call `await wasmBridge.initWasm()` before using UMAP with wasm distances or build the wasm package.");return y.euclideanWasm(t,e)}return this.distanceFn(t,e)},t.prototype.makeSearchGraph=function(t){for(var e=this.knnIndices,r=this.knnDistances,n=[t.length,t.length],o=new m.SparseMatrix([],[],[],n),s=0;s<e.length;s++)for(var i=e[s],a=r[s],u=0;u<i.length;u++){var h=i[u],l=a[u];l>0&&o.set(s,h,l)}var c=m.transpose(o);return m.maximum(o,c)},t.prototype.transform=function(t){var e=this,r=this.X;if(void 0===r||0===r.length)throw new Error("No data has been fit.");var n=Math.floor(this.nNeighbors*this.transformQueueSize);n=Math.min(r.length,n);var o=g.initializeSearch(this.rpForest,r,t,n,this.initFromRandom,this.initFromTree,this.random),s=this.search(r,this.searchGraph,o,t),i=f.deheapSort(s),a=i.indices,u=i.weights;a=a.map(function(t){return t.slice(0,e.nNeighbors)}),u=u.map(function(t){return t.slice(0,e.nNeighbors)});var h=Math.max(0,this.localConnectivity-1),l=this.smoothKNNDistance(u,this.nNeighbors,h),c=l.sigmas,p=l.rhos,d=this.computeMembershipStrengths(a,u,c,p),y=d.rows,v=d.cols,b=d.vals,M=[t.length,r.length],x=new m.SparseMatrix(y,v,b,M),S=m.normalize(x,"l1"),E=m.getCSR(S),A=t.length,R=k(w.reshape2d(E.indices,A,this.nNeighbors),w.reshape2d(E.values,A,this.nNeighbors),this.embedding),_=this.nEpochs?this.nEpochs/3:x.nRows<=1e4?100:30,N=x.getValues().reduce(function(t,e){return e>t?e:t},0);x=x.map(function(t){return t<N/_?0:t}),x=m.eliminateZeros(x);var z=this.makeEpochsPerSample(x.getValues(),_),I=x.getRows(),O=x.getCols();return this.assignOptimizationStateParameters({headEmbedding:R,tailEmbedding:this.embedding,head:I,tail:O,currentEpoch:0,nEpochs:_,nVertices:x.getDims()[1],epochsPerSample:z}),this.prepareForOptimizationLoop(),this.optimizeLayout()},t.prototype.processGraphForSupervisedProjection=function(){var t=this.Y,e=this.X;if(t){if(t.length!==e.length)throw new Error("Length of X and y must be equal");if("categorical"===this.targetMetric){var r=this.targetWeight<1?1/(1-this.targetWeight)*2.5:1e12;this.graph=this.categoricalSimplicialSetIntersection(this.graph,t,r)}}},t.prototype.step=function(){var t=this.optimizationState.currentEpoch;return t<this.getNEpochs()&&this.optimizeLayoutStep(t),this.optimizationState.currentEpoch},t.prototype.getEmbedding=function(){return this.embedding},t.prototype.nearestNeighbors=function(t){var e,r=this.distanceFn,n=this.nNeighbors,o=g.makeNNDescent(r,this.random),s=5+Math.floor(.5==(e=Math.pow(t.length,.5)/20)?0:Math.round(e)),i=Math.max(5,Math.floor(Math.round(function(t){return Math.log(t)/Math.log(2)}(t.length))));this.rpForest=p.makeForest(t,n,s,this.random,this.useWasmTree);var a=o(t,p.makeLeafArray(this.rpForest),n,i);return{knnIndices:a.indices,knnDistances:a.weights}},t.prototype.fuzzySimplicialSet=function(t,e,r){void 0===r&&(r=1);var n=this,o=n.knnIndices,s=void 0===o?[]:o,i=n.knnDistances,a=void 0===i?[]:i,u=n.localConnectivity,h=this.smoothKNNDistance(a,e,u),l=h.sigmas,c=h.rhos,f=this.computeMembershipStrengths(s,a,l,c),g=f.rows,p=f.cols,w=f.vals,d=[t.length,t.length];if(this.useWasmMatrix&&y.isWasmAvailable()){var v=y.createSparseMatrixWasm(g,p,w,d[0],d[1]),b=y.sparseTransposeWasm(v),M=y.sparsePairwiseMultiplyWasm(v,b),x=y.sparseAddWasm(v,b),S=y.sparseSubtractWasm(x,M),E=y.sparseMultiplyScalarWasm(S,r),A=y.sparseMultiplyScalarWasm(M,1-r),R=y.sparseAddWasm(E,A),_=(z=y.wasmSparseMatrixGetAll(R)).map(function(t){return t.row}),N=z.map(function(t){return t.col}),k=z.map(function(t){return t.value});return new m.SparseMatrix(_,N,k,d)}if(this.useWasmMatrix&&y.isWasmAvailable()){v=y.createSparseMatrixWasm(g,p,w,d[0],d[1]);var z,I=y.sparseTransposeWasm(v),O=y.sparsePairwiseMultiplyWasm(v,I),T=(x=y.sparseAddWasm(v,I),y.sparseSubtractWasm(x,O)),P=y.sparseMultiplyScalarWasm(T,r),j=y.sparseMultiplyScalarWasm(O,1-r);return R=y.sparseAddWasm(P,j),_=(z=y.wasmSparseMatrixGetAll(R)).map(function(t){return t.row}),N=z.map(function(t){return t.col}),k=z.map(function(t){return t.value}),new m.SparseMatrix(_,N,k,d)}var W=new m.SparseMatrix(g,p,w,d),C=m.transpose(W),F=m.pairwiseMultiply(W,C),D=m.subtract(m.add(W,C),F),q=m.multiplyScalar(D,r),V=m.multiplyScalar(F,1-r);return m.add(q,V)},t.prototype.categoricalSimplicialSetIntersection=function(t,e,r,n){void 0===n&&(n=1);var o=_(t,e,n,r);return N(o=m.eliminateZeros(o))},t.prototype.smoothKNNDistance=function(t,e,r,n,o){void 0===r&&(r=1),void 0===n&&(n=64),void 0===o&&(o=1);for(var s=Math.log(e)/Math.log(2)*o,i=w.zeros(t.length),a=w.zeros(t.length),u=0;u<t.length;u++){var h=0,l=1/0,c=1,f=t[u],m=f.filter(function(t){return t>0});if(m.length>=r){var g=Math.floor(r),p=r-g;g>0?(i[u]=m[g-1],p>v&&(i[u]+=p*(m[g]-m[g-1]))):i[u]=p*m[0]}else m.length>0&&(i[u]=w.max(m));for(var d=0;d<n;d++){for(var y=0,M=1;M<t[u].length;M++){var x=t[u][M]-i[u];y+=x>0?Math.exp(-x/c):1}if(Math.abs(y-s)<v)break;y>s?c=(h+(l=c))/2:(h=c,l===1/0?c*=2:c=(h+l)/2)}if(a[u]=c,i[u]>0){var S=w.mean(f);a[u]<b*S&&(a[u]=b*S)}else{var E=w.mean(t.map(w.mean));a[u]<b*E&&(a[u]=b*E)}}return{sigmas:a,rhos:i}},t.prototype.computeMembershipStrengths=function(t,e,r,n){for(var o=t.length,s=t[0].length,i=w.zeros(o*s),a=w.zeros(o*s),u=w.zeros(o*s),h=0;h<o;h++)for(var l=0;l<s;l++){var c=0;-1!==t[h][l]&&(c=t[h][l]===h?0:e[h][l]-n[h]<=0?1:Math.exp(-(e[h][l]-n[h])/r[h]),i[h*s+l]=h,a[h*s+l]=t[h][l],u[h*s+l]=c)}return{rows:i,cols:a,vals:u}},t.prototype.initializeSimplicialSetEmbedding=function(){for(var t=this,e=this.getNEpochs(),r=this.nComponents,n=this.graph.getValues(),o=0,s=0;s<n.length;s++){var i=n[s];o<n[s]&&(o=i)}var a=this.graph.map(function(t){return t<o/e?0:t});this.embedding=w.zeros(a.nRows).map(function(){return w.zeros(r).map(function(){return 20*w.tauRand(t.random)-10})});var u=[],h=[],l=[],c=a.getAll();for(s=0;s<c.length;s++){var f=c[s];f.value&&(u.push(f.value),l.push(f.row),h.push(f.col))}return{head:h,tail:l,epochsPerSample:this.makeEpochsPerSample(u,e)}},t.prototype.makeEpochsPerSample=function(t,e){var r=w.filled(t.length,-1),n=w.max(t),o=t.map(function(t){return t/n*e});return o.forEach(function(t,n){t>0&&(r[n]=e/o[n])}),r},t.prototype.assignOptimizationStateParameters=function(t){Object.assign(this.optimizationState,t)},t.prototype.prepareForOptimizationLoop=function(){var t=this,e=t.repulsionStrength,r=t.learningRate,n=t.negativeSampleRate,o=this.optimizationState,s=o.epochsPerSample,i=o.headEmbedding,a=o.tailEmbedding,u=i[0].length,c=i.length===a.length,f=s.map(function(t){return t/n}),m=l([],h(f),!1),g=l([],h(s),!1);this.assignOptimizationStateParameters({epochOfNextSample:g,epochOfNextNegativeSample:m,epochsPerNegativeSample:f,moveOther:c,initialAlpha:r,alpha:r,gamma:e,dim:u})},t.prototype.initializeOptimization=function(){var t=this.embedding,e=this.embedding,r=this.optimizationState,n=r.head,o=r.tail,s=r.epochsPerSample,i=this.getNEpochs(),a=this.graph.nCols,u=R(this.spread,this.minDist),h=u.a,l=u.b;this.assignOptimizationStateParameters({headEmbedding:t,tailEmbedding:e,head:n,tail:o,epochsPerSample:s,a:h,b:l,nEpochs:i,nVertices:a})},t.prototype.optimizeLayoutStep=function(t){for(var e=this.optimizationState,r=e.head,n=e.tail,o=e.headEmbedding,s=e.tailEmbedding,i=e.epochsPerSample,a=e.epochOfNextSample,u=e.epochOfNextNegativeSample,h=e.epochsPerNegativeSample,l=e.moveOther,c=e.initialAlpha,f=e.alpha,m=e.gamma,g=e.a,p=e.b,d=e.dim,y=e.nEpochs,v=e.nVertices,b=0;b<i.length;b++)if(!(a[b]>t)){var M=r[b],x=n[b],S=o[M],R=s[x],_=A(S,R),N=0;_>0&&(N=-2*g*p*Math.pow(_,p-1),N/=g*Math.pow(_,p)+1);for(var k=0;k<d;k++){var z=E(N*(S[k]-R[k]),4);S[k]+=z*f,l&&(R[k]+=-z*f)}a[b]+=i[b];for(var I=Math.floor((t-u[b])/h[b]),O=0;O<I;O++){var T=w.tauRandInt(v,this.random),P=s[T],j=A(S,P),W=0;if(j>0)W=2*m*p,W/=(.001+j)*(g*Math.pow(j,p)+1);else if(M===T)continue;for(k=0;k<d;k++)z=4,W>0&&(z=E(W*(S[k]-P[k]),4)),S[k]+=z*f}u[b]+=I*h[b]}return e.alpha=c*(1-t/y),e.currentEpoch+=1,o},t.prototype.optimizeLayoutAsync=function(t){var e=this;return void 0===t&&(t=function(){return!0}),new Promise(function(r,n){var o=function(){return a(e,void 0,void 0,function(){var e,s,i,a,h,l;return u(this,function(u){try{if(e=this.optimizationState,s=e.nEpochs,i=e.currentEpoch,this.embedding=this.optimizeLayoutStep(i),a=this.optimizationState.currentEpoch,h=!1===t(a),l=a===s,h||l)return[2,r(l)];setTimeout(function(){return o()},0)}catch(t){n(t)}return[2]})})};setTimeout(function(){return o()},0)})},t.prototype.optimizeLayout=function(t){void 0===t&&(t=function(){return!0});for(var e=!1,r=[];!e;){var n=this.optimizationState,o=n.nEpochs,s=n.currentEpoch;r=this.optimizeLayoutStep(s);var i=this.optimizationState.currentEpoch,a=!1===t(i);e=i===o||a}return r},t.prototype.getNEpochs=function(){var t=this.graph;if(this.nEpochs>0)return this.nEpochs;var e=t.nRows;return e<=2500?500:e<=5e3?400:e<=7500?300:200},t}();function x(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return Math.sqrt(r)}e.UMAP=M;var S=function(){this.currentEpoch=0,this.headEmbedding=[],this.tailEmbedding=[],this.head=[],this.tail=[],this.epochsPerSample=[],this.epochOfNextSample=[],this.epochOfNextNegativeSample=[],this.epochsPerNegativeSample=[],this.moveOther=!0,this.initialAlpha=1,this.alpha=1,this.gamma=1,this.a=1.5769434603113077,this.b=.8950608779109733,this.dim=2,this.nEpochs=500,this.nVertices=0};function E(t,e){return t>e?e:t<-e?-e:t}function A(t,e){for(var r=0,n=0;n<t.length;n++)r+=Math.pow(t[n]-e[n],2);return r}function R(t,e){var r=w.linear(0,3*t,300).map(function(t){return t<e?1:t}),n=w.zeros(r.length).map(function(n,o){return r[o]>=e?Math.exp(-(r[o]-e)/t):n}),o={x:r,y:n},s=(0,d.default)(o,function(t){var e=h(t,2),r=e[0],n=e[1];return function(t){return 1/(1+r*Math.pow(t,2*n))}},{damping:1.5,initialValues:[.5,.5],gradientDifference:.1,maxIterations:100,errorTolerance:.01}).parameterValues,i=h(s,2);return{a:i[0],b:i[1]}}function _(t,e,r,n){return void 0===r&&(r=1),void 0===n&&(n=5),t.map(function(t,o,s){return-1===e[o]||-1===e[s]?t*Math.exp(-r):e[o]!==e[s]?t*Math.exp(-n):t})}function N(t){t=m.normalize(t,"max");var e=m.transpose(t),r=m.pairwiseMultiply(e,t);return t=m.add(t,m.subtract(e,r)),m.eliminateZeros(t)}function k(t,e,r){for(var n=w.zeros(t.length).map(function(t){return w.zeros(r[0].length)}),o=0;o<t.length;o++)for(var s=0;s<t[0].length;s++)for(var i=0;i<r[0].length;i++){var a=t[o][s];n[o][i]+=e[o][s]*r[a][i]}return n}},450(t,e,r){"use strict";var n,o=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),s=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||(n=function(t){return n=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},n(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=n(t),i=0;i<r.length;i++)"default"!==r[i]&&o(e,t,r[i]);return s(e,t),e}),a=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,s=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(n=s.next()).done;)i.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return i},u=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var n,o=0,s=e.length;o<s;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))},h=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0}),e.FlatTree=void 0,e.makeForest=function(t,e,r,n,o){void 0===o&&(o=!1);var s=Math.max(10,e);if(o){if(!(0,c.isWasmAvailable)())throw new Error("WASM requested but not available");return function(t,e,r,n){for(var o=t.length,s=t[0].length,i=[],a=0;a<r;a++){var u=Math.floor(4294967295*n()),h=(0,c.buildRpTreeWasm)(t,o,s,e,u);i.push(f.fromWasm(h))}return i}(t,s,r,n)}return l.range(r).map(function(e,r){return function(t,e,r,n){return void 0===e&&(e=30),m(t,l.range(t.length),e,r,n)}(t,s,r,n)}).map(function(t){return function(t,e){var r=p(t),n=w(t),o=l.range(r).map(function(){return l.zeros(t.hyperplane?t.hyperplane.length:0)}),s=l.zeros(r),i=l.range(r).map(function(){return[-1,-1]}),a=l.range(n).map(function(){return l.range(e).map(function(){return-1})});return g(t,o,s,i,a,0,0),new f(o,s,i,a)}(t,s)})},e.makeLeafArray=function(t){var e,r;if(t.length>0){var n=[];try{for(var o=h(t),s=o.next();!s.done;s=o.next()){var i=s.value;n.push.apply(n,u([],a(i.indices),!1))}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return n}return[[-1]]},e.searchFlatTree=function(t,e,r){var n=e.getWasmTree();if(n&&(0,c.isWasmAvailable)()){var o=Math.floor(4294967295*r());return(0,c.searchFlatTreeWasm)(n,t,o)}for(var s=0;e.children[s][0]>0;)s=0===d(e.hyperplanes[s],e.offsets[s],t,r)?e.children[s][0]:e.children[s][1];var i=-1*e.children[s][0];return e.indices[i]};var l=i(r(185)),c=r(103),f=function(){function t(t,e,r,n){this.hyperplanes=t,this.offsets=e,this.children=r,this.indices=n}return t.fromWasm=function(e){var r=(0,c.wasmTreeToJs)(e),n=new t(r.hyperplanes,r.offsets,r.children,r.indices);return n.wasmTree=e,n},t.prototype.getWasmTree=function(){return this.wasmTree},t.prototype.dispose=function(){this.wasmTree&&(this.wasmTree.free(),this.wasmTree=void 0)},t}();function m(t,e,r,n,o){if(void 0===r&&(r=30),e.length>r){var s=function(t,e,r){var n=t[0].length,o=l.tauRandInt(e.length,r),s=l.tauRandInt(e.length,r);s=(s+=o===s?1:0)%e.length;for(var i=e[o],a=e[s],u=0,h=l.zeros(n),c=0;c<h.length;c++)h[c]=t[i][c]-t[a][c],u-=h[c]*(t[i][c]+t[a][c])/2;var f=0,m=0,g=l.zeros(e.length);for(c=0;c<e.length;c++){for(var p=u,w=0;w<n;w++)p+=h[w]*t[e[c]][w];0===p?(g[c]=l.tauRandInt(2,r),0===g[c]?f+=1:m+=1):p>0?(g[c]=0,f+=1):(g[c]=1,m+=1)}var d=l.zeros(f),y=l.zeros(m);for(f=0,m=0,c=0;c<g.length;c++)0===g[c]?(d[f]=e[c],f+=1):(y[m]=e[c],m+=1);return{indicesLeft:d,indicesRight:y,hyperplane:h,offset:u}}(t,e,o),i=s.indicesLeft,a=s.indicesRight,u=s.hyperplane,h=s.offset;return{leftChild:m(t,i,r,n+1,o),rightChild:m(t,a,r,n+1,o),isLeaf:!1,hyperplane:u,offset:h}}return{indices:e,isLeaf:!0}}function g(t,e,r,n,o,s,i){var h;if(t.isLeaf)return n[s][0]=-i,(h=o[i]).splice.apply(h,u([0,t.indices.length],a(t.indices),!1)),{nodeNum:s,leafNum:i+=1};e[s]=t.hyperplane,r[s]=t.offset,n[s][0]=s+1;var l=s,c=g(t.leftChild,e,r,n,o,s+1,i);return s=c.nodeNum,i=c.leafNum,n[l][1]=s+1,{nodeNum:(c=g(t.rightChild,e,r,n,o,s+1,i)).nodeNum,leafNum:c.leafNum}}function p(t){return t.isLeaf?1:1+p(t.leftChild)+p(t.rightChild)}function w(t){return t.isLeaf?1:w(t.leftChild)+w(t.rightChild)}function d(t,e,r,n){for(var o=e,s=0;s<r.length;s++)o+=t[s]*r[s];return 0===o?l.tauRandInt(2,n):o>0?0:1}e.FlatTree=f},499(t,e,r){"use strict";var n,o,s=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(e,r);o&&!("get"in o?!e.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,o)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),a=this&&this.__importStar||(n=function(t){return n=Object.getOwnPropertyNames||function(t){var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[e.length]=r);return e},n(t)},function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r=n(t),o=0;o<r.length;o++)"default"!==r[o]&&s(e,t,r[o]);return i(e,t),e}),u=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,o,s=r.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(n=s.next()).done;)i.push(n.value)}catch(t){o={error:t}}finally{try{n&&!n.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}return i},h=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(e,"__esModule",{value:!0}),e.SparseMatrix=void 0,e.transpose=function(t){var e=[],r=[],n=[];t.forEach(function(t,o,s){e.push(o),r.push(s),n.push(t)});var o=[t.nCols,t.nRows];return new c(r,e,n,o)},e.identity=function(t){for(var e=u(t,1)[0],r=new c([],[],[],t),n=0;n<e;n++)r.set(n,n,1);return r},e.pairwiseMultiply=function(t,e){return m(t,e,function(t,e){return t*e})},e.add=function(t,e){return m(t,e,function(t,e){return t+e})},e.subtract=function(t,e){return m(t,e,function(t,e){return t-e})},e.maximum=function(t,e){return m(t,e,function(t,e){return t>e?t:e})},e.multiplyScalar=function(t,e){return t.map(function(t){return t*e})},e.eliminateZeros=function(t){for(var e=new Set,r=t.getValues(),n=t.getRows(),o=t.getCols(),s=0;s<r.length;s++)0===r[s]&&e.add(s);var i=function(t,r){return!e.has(r)},a=r.filter(i),u=n.filter(i),h=o.filter(i);return new c(u,h,a,t.getDims())},e.normalize=function(t,e){var r,n;void 0===e&&(e="l2");var o=f[e],s=new Map;t.forEach(function(t,e,r){var n=s.get(e)||[];n.push(r),s.set(e,n)});var i=new c([],[],[],t.getDims()),a=function(e){for(var r=s.get(e).sort(),n=r.map(function(r){return t.get(e,r)}),a=o(n),u=0;u<a.length;u++)i.set(e,r[u],a[u])};try{for(var u=h(s.keys()),l=u.next();!l.done;l=u.next())a(l.value)}catch(t){r={error:t}}finally{try{l&&!l.done&&(n=u.return)&&n.call(u)}finally{if(r)throw r.error}}return i},e.getCSR=function(t){var e=[];t.forEach(function(t,r,n){e.push({value:t,row:r,col:n})}),e.sort(function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row});for(var r=[],n=[],o=[],s=-1,i=0;i<e.length;i++){var a=e[i],u=a.row,h=a.col,l=a.value;u!==s&&(s=u,o.push(i)),r.push(h),n.push(l)}return{indices:r,values:n,indptr:o}};var l=a(r(185)),c=function(){function t(t,e,r,n){if(this.entries=new Map,this.nRows=0,this.nCols=0,t.length!==e.length||t.length!==r.length)throw new Error("rows, cols and values arrays must all have the same length");this.nRows=n[0],this.nCols=n[1];for(var o=0;o<r.length;o++){var s=t[o],i=e[o];this.checkDims(s,i);var a=this.makeKey(s,i);this.entries.set(a,{value:r[o],row:s,col:i})}}return t.prototype.makeKey=function(t,e){return"".concat(t,":").concat(e)},t.prototype.checkDims=function(t,e){if(!(t<this.nRows&&e<this.nCols))throw new Error("row and/or col specified outside of matrix dimensions")},t.prototype.set=function(t,e,r){this.checkDims(t,e);var n=this.makeKey(t,e);this.entries.has(n)?this.entries.get(n).value=r:this.entries.set(n,{value:r,row:t,col:e})},t.prototype.get=function(t,e,r){void 0===r&&(r=0),this.checkDims(t,e);var n=this.makeKey(t,e);return this.entries.has(n)?this.entries.get(n).value:r},t.prototype.getAll=function(t){void 0===t&&(t=!0);var e=[];return this.entries.forEach(function(t){e.push(t)}),t&&e.sort(function(t,e){return t.row===e.row?t.col-e.col:t.row-e.row}),e},t.prototype.getDims=function(){return[this.nRows,this.nCols]},t.prototype.getRows=function(){return Array.from(this.entries,function(t){var e=u(t,2);return e[0],e[1].row})},t.prototype.getCols=function(){return Array.from(this.entries,function(t){var e=u(t,2);return e[0],e[1].col})},t.prototype.getValues=function(){return Array.from(this.entries,function(t){var e=u(t,2);return e[0],e[1].value})},t.prototype.forEach=function(t){this.entries.forEach(function(e){return t(e.value,e.row,e.col)})},t.prototype.map=function(e){var r=[];this.entries.forEach(function(t){r.push(e(t.value,t.row,t.col))});var n=[this.nRows,this.nCols];return new t(this.getRows(),this.getCols(),r,n)},t.prototype.toArray=function(){var t=this,e=l.empty(this.nRows).map(function(){return l.zeros(t.nCols)});return this.entries.forEach(function(t){e[t.row][t.col]=t.value}),e},t}();e.SparseMatrix=c;var f=((o={}).max=function(t){for(var e=-1/0,r=0;r<t.length;r++)e=t[r]>e?t[r]:e;return t.map(function(t){return t/e})},o.l1=function(t){for(var e=0,r=0;r<t.length;r++)e+=t[r];return t.map(function(t){return t/e})},o.l2=function(t){for(var e=0,r=0;r<t.length;r++)e+=Math.pow(t[r],2);return t.map(function(t){return Math.sqrt(Math.pow(t,2)/e)})},o);function m(t,e,r){for(var n=new Set,o=[],s=[],i=[],a=function(n,a){o.push(n),s.push(a);var u=r(t.get(n,a),e.get(n,a));i.push(u)},u=t.getValues(),h=t.getRows(),l=t.getCols(),f=0;f<u.length;f++){var m=h[f],g=l[f],p="".concat(m,":").concat(g);n.add(p),a(m,g)}var w=e.getValues(),d=e.getRows(),y=e.getCols();for(f=0;f<w.length;f++)m=d[f],g=y[f],p="".concat(m,":").concat(g),n.has(p)||a(m,g);var v=[t.nRows,t.nCols];return new c(o,s,i,v)}},527(t,e,r){"use strict";r.r(e),r.d(e,{default:()=>l});const n=Object.prototype.toString;function o(t){return n.call(t).endsWith("Array]")}function s(t,e,r){let n=0;const o=r(e);for(let e=0;e<t.x.length;e++)n+=Math.abs(t.y[e]-o(t.x[e]));return n}var i=r(673);i.y3,i.jy,i.oN,i.Hc,i.cg,i.hj,i.LU,i.Tb;const a=i.uq,u=(i.Zm,i.Dq,i.__,i.q0,i.lh,i.pI,i.zC,i.zg,i.g6,i.OL,i.ks,i.QR,i.jp,i.mk,i.W2,i.l,i.KY,i.dv,i.BR,i.Wu,i.uq,i.uq,i.a4,i.DI);function h(t,e,r,n,o){let s=r*n*n,i=a.eye(e.length,e.length,s);const h=o(e);let l=new Float64Array(t.x.length);for(let e=0;e<t.x.length;e++)l[e]=h(t.x[e]);let c=function(t,e,r,n,o){const s=r.length,i=t.x.length;let u=new Array(s);for(let a=0;a<s;a++){u[a]=new Array(i);let s=r.slice();s[a]+=n;let h=o(s);for(let r=0;r<i;r++)u[a][r]=e[r]-h(t.x[r])}return new a(u)}(t,l,e,n,o),f=function(t,e){const r=t.x.length;let n=new Array(r);for(let o=0;o<r;o++)n[o]=[t.y[o]-e[o]];return new a(n)}(t,l),m=u(i.add(c.mmul(c.transpose())));return(e=(e=new a([e])).sub(m.mmul(c).mmul(f).mul(n).transpose())).to1DArray()}function l(t,e,r={}){let{maxIterations:n=100,gradientDifference:i=.1,damping:a=0,errorTolerance:u=.01,minValues:l,maxValues:c,initialValues:f}=r;if(a<=0)throw new Error("The damping option must be a positive number");if(!t.x||!t.y)throw new Error("The data parameter must have x and y elements");if(!o(t.x)||t.x.length<2||!o(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 m=f||new Array(e.length).fill(1),g=m.length;if(c=c||new Array(g).fill(Number.MAX_SAFE_INTEGER),l=l||new Array(g).fill(Number.MIN_SAFE_INTEGER),c.length!==l.length)throw new Error("minValues and maxValues must be the same size");if(!o(m))throw new Error("initialValues must be an array");let p,w=s(t,m,e),d=w<=u;for(p=0;p<n&&!d;p++){m=h(t,m,a,i,e);for(let t=0;t<g;t++)m[t]=Math.min(Math.max(l[t],m[t]),c[t]);if(w=s(t,m,e),isNaN(w))break;d=w<=u}return{parameterValues:m,parameterError:w,iterations:p}}i.Jo,i.Zi,i.kH,i.LV},589(t){function e(t){var e=new Error("Cannot find module '"+t+"'");throw e.code="MODULE_NOT_FOUND",e}e.keys=()=>[],e.resolve=e,e.id=589,t.exports=e},673(t,e,r){"use strict";var n=r(788),o=r(718);const s=" ".repeat(2),i=" ".repeat(4);function a(t,e={}){const{maxRows:r=15,maxColumns:n=10,maxNumSize:o=8,padMinus:a="auto"}=e;return`${t.constructor.name} {\n${s}[\n${i}${function(t,e,r,n,o){const{rows:s,columns:a}=t,h=Math.min(s,e),l=Math.min(a,r),c=[];if("auto"===o){o=!1;t:for(let e=0;e<h;e++)for(let r=0;r<l;r++)if(t.get(e,r)<0){o=!0;break t}}for(let e=0;e<h;e++){let r=[];for(let s=0;s<l;s++)r.push(u(t.get(e,s),n,o));c.push(`${r.join(" ")}`)}return l!==a&&(c[c.length-1]+=` ... ${a-r} more columns`),h!==s&&c.push(`... ${s-e} more rows`),c.join(`\n${i}`)}(t,r,n,o,a)}\n${s}]\n${s}rows: ${t.rows}\n${s}columns: ${t.columns}\n}`}function u(t,e,r){return(t>=0&&r?` ${h(t,e-1)}`:h(t,e)).padEnd(e)}function h(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 o=t.toExponential(e);return o.length>e&&(o=t.toExponential(Math.max(0,e-(o.length-e)))),o.slice(0)}function l(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 c(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 f(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return e}function m(t,e){if(e.to1DArray&&(e=e.to1DArray()),e.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return e}function g(t,e){if(!n.isAnyArray(e))throw new TypeError("row indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.rows)throw new RangeError("row indices are out of range")}function p(t,e){if(!n.isAnyArray(e))throw new TypeError("column indices must be an array");for(let r=0;r<e.length;r++)if(e[r]<0||e[r]>=t.columns)throw new RangeError("column indices are out of range")}function w(t,e,r,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(y("startRow",e),y("endRow",r),y("startColumn",n),y("endColumn",o),e>r||n>o||e<0||e>=t.rows||r<0||r>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function d(t,e=0){let r=[];for(let n=0;n<t;n++)r.push(e);return r}function y(t,e){if("number"!=typeof e)throw new TypeError(`${t} must be a number`)}function v(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}class b{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let n=new S(t,e);for(let o=0;o<t;o++)for(let t=0;t<e;t++)n.set(o,t,r[o*e+t]);return n}static rowVector(t){let e=new S(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 S(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 S(t,e)}static ones(t,e){return new S(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 o=new S(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++)o.set(r,t,n());return o}static randInt(t,e,r={}){if("object"!=typeof r)throw new TypeError("options must be an object");const{min:n=0,max:o=1e3,random:s=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(o))throw new TypeError("max must be an integer");if(n>=o)throw new RangeError("min must be smaller than max");let i=o-n,a=new S(t,e);for(let r=0;r<t;r++)for(let t=0;t<e;t++){let e=n+Math.round(s()*i);a.set(r,t,e)}return a}static eye(t,e,r){void 0===e&&(e=t),void 0===r&&(r=1);let n=Math.min(t,e),o=this.zeros(t,e);for(let t=0;t<n;t++)o.set(t,t,r);return o}static diag(t,e,r){let n=t.length;void 0===e&&(e=n),void 0===r&&(r=e);let o=Math.min(n,e,r),s=this.zeros(e,r);for(let e=0;e<o;e++)s.set(e,e,t[e]);return s}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new S(r,n);for(let s=0;s<r;s++)for(let r=0;r<n;r++)o.set(s,r,Math.min(t.get(s,r),e.get(s,r)));return o}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,o=new this(r,n);for(let s=0;s<r;s++)for(let r=0;r<n;r++)o.set(s,r,Math.max(t.get(s,r),e.get(s,r)));return o}static checkMatrix(t){return b.isMatrix(t)?t:new S(t)}static isMatrix(t){return null!=t&&"Matrix"===t.klass}get size(){return this.rows*this.columns}apply(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return 1===this.rows}isColumnVector(){return 1===this.columns}isVector(){return 1===this.rows||1===this.columns}isSquare(){return this.rows===this.columns}isEmpty(){return 0===this.rows||0===this.columns}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(0!==this.get(t,t))return!1;return!0}isEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,o=!1;for(;t<this.rows&&n;){for(e=0,o=!1;e<this.columns&&!1===o;)0===this.get(t,e)?e++:1===this.get(t,e)&&e>r?(o=!0,r=e):(n=!1,o=!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 o=e;o<t.rows;o++)t.get(o,r)>t.get(n,r)&&(n=o);if(0===t.get(n,r))r++;else{t.swapRows(e,n);let o=t.get(e,r);for(let n=r;n<t.columns;n++)t.set(e,n,t.get(e,n)/o);for(let n=e+1;n<t.rows;n++){let o=t.get(n,r)/t.get(e,r);t.set(n,r,0);for(let s=r+1;s<t.columns;s++)t.set(n,s,t.get(n,s)-t.get(e,s)*o)}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 o=0,s=!1;for(;o<r&&!1===s;)1===t.get(n,o)?s=!0:o++;for(let r=0;r<n;r++){let s=t.get(r,o);for(let i=o;i<e;i++){let e=t.get(r,i)-s*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 S(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){l(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return S.rowVector(this.getRow(t))}setRow(t,e){l(this,t),e=f(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){l(this,t),l(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){c(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return S.columnVector(this.getColumn(t))}setColumn(t,e){c(this,t),e=m(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){c(this,t),c(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=f(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=f(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=f(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=f(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=m(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){l(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){c(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const t=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[e]&&(t[e]=this.get(e,r));return t}case"column":{const t=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t[r]&&(t[r]=this.get(e,r));return t}case void 0:{let t=this.get(0,0);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.get(e,r)>t&&(t=this.get(e,r));return t}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){v(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(){v(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(l(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){l(this,t),v(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(l(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){l(this,t),v(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(c(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){c(this,t),v(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(c(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){c(this,t),v(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"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${t}`)}}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){b.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=S.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,o=new S(e,n),s=new Float64Array(r);for(let i=0;i<n;i++){for(let e=0;e<r;e++)s[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)*s[n];o.set(t,i,e)}}return o}mpow(t){if(!this.isSquare())throw new RangeError("Matrix must be square");if(!Number.isInteger(t)||t<0)throw new RangeError("Exponent must be a non-negative integer");let e=S.eye(this.rows),r=this;for(let n=t;n>=1;n/=2)1&n&&(e=e.mmul(r)),r=r.mmul(r);return e}strassen2x2(t){t=S.checkMatrix(t);let e=new S(2,2);const r=this.get(0,0),n=t.get(0,0),o=this.get(0,1),s=t.get(0,1),i=this.get(1,0),a=t.get(1,0),u=this.get(1,1),h=t.get(1,1),l=(r+u)*(n+h),c=(i+u)*n,f=r*(s-h),m=u*(a-n),g=(r+o)*h,p=l+m-g+(o-u)*(a+h),w=f+g,d=c+m,y=l-c+f+(i-r)*(n+s);return e.set(0,0,p),e.set(0,1,w),e.set(1,0,d),e.set(1,1,y),e}strassen3x3(t){t=S.checkMatrix(t);let e=new S(3,3);const r=this.get(0,0),n=this.get(0,1),o=this.get(0,2),s=this.get(1,0),i=this.get(1,1),a=this.get(1,2),u=this.get(2,0),h=this.get(2,1),l=this.get(2,2),c=t.get(0,0),f=t.get(0,1),m=t.get(0,2),g=t.get(1,0),p=t.get(1,1),w=t.get(1,2),d=t.get(2,0),y=t.get(2,1),v=t.get(2,2),b=(r-s)*(-f+p),M=(-r+s+i)*(c-f+p),x=(s+i)*(-c+f),E=r*c,A=(-r+u+h)*(c-m+w),R=(-r+u)*(m-w),_=(u+h)*(-c+m),N=(-o+h+l)*(p+d-y),k=(o-l)*(p-y),z=o*d,I=(h+l)*(-d+y),O=(-o+i+a)*(w+d-v),T=(o-a)*(w-v),P=(i+a)*(-d+v),j=E+z+n*g,W=(r+n+o-s-i-h-l)*p+M+x+E+N+z+I,C=E+A+_+(r+n+o-i-a-u-h)*w+z+O+P,F=b+i*(-c+f+g-p-w-d+v)+M+E+z+O+T,D=b+M+x+E+a*y,q=z+O+T+P+s*m,V=E+A+R+h*(-c+m+g-p-w-d+y)+N+k+z,L=N+k+z+I+u*f,$=E+A+R+_+l*v;return e.set(0,0,j),e.set(0,1,W),e.set(0,2,C),e.set(1,0,F),e.set(1,1,D),e.set(1,2,q),e.set(2,0,V),e.set(2,1,L),e.set(2,2,$),e}mmulStrassen(t){t=S.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,o=t.rows,s=t.columns;function i(t,e,r){let n=t.rows,o=t.columns;if(n===e&&o===r)return t;{let n=b.zeros(e,r);return n=n.setSubMatrix(t,0,0),n}}n!==o&&console.warn(`Multiplying ${r} x ${n} and ${o} x ${s} matrix: dimensions do not match.`);let a=Math.max(r,o),u=Math.max(n,s);return e=i(e,a,u),function t(e,r,n,o){if(n<=512||o<=512)return e.mmul(r);n%2==1&&o%2==1?(e=i(e,n+1,o+1),r=i(r,n+1,o+1)):n%2==1?(e=i(e,n+1,o),r=i(r,n+1,o)):o%2==1&&(e=i(e,n,o+1),r=i(r,n,o+1));let s=parseInt(e.rows/2,10),a=parseInt(e.columns/2,10),u=e.subMatrix(0,s-1,0,a-1),h=r.subMatrix(0,s-1,0,a-1),l=e.subMatrix(0,s-1,a,e.columns-1),c=r.subMatrix(0,s-1,a,r.columns-1),f=e.subMatrix(s,e.rows-1,0,a-1),m=r.subMatrix(s,r.rows-1,0,a-1),g=e.subMatrix(s,e.rows-1,a,e.columns-1),p=r.subMatrix(s,r.rows-1,a,r.columns-1),w=t(b.add(u,g),b.add(h,p),s,a),d=t(b.add(f,g),h,s,a),y=t(u,b.sub(c,p),s,a),v=t(g,b.sub(m,h),s,a),M=t(b.add(u,l),p,s,a),x=t(b.sub(f,u),b.add(h,c),s,a),S=t(b.sub(l,g),b.add(m,p),s,a),E=b.add(w,v);E.sub(M),E.add(S);let A=b.add(y,M),R=b.add(d,v),_=b.sub(w,d);_.add(y),_.add(x);let N=b.zeros(2*E.rows,2*E.columns);return N=N.setSubMatrix(E,0,0),N=N.setSubMatrix(A,E.rows,0),N=N.setSubMatrix(R,0,E.columns),N=N.setSubMatrix(_,E.rows,E.columns),N.subMatrix(0,n-1,0,o-1)}(e,t=i(t,a,u),a,u)}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 S(this.rows,this.columns);for(let t=0;t<this.rows;t++){const s=this.getRow(t);s.length>0&&o(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 S(this.rows,this.columns);for(let t=0;t<this.columns;t++){const s=this.getColumn(t);s.length&&o(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=S.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,o=t.columns,s=new S(e*n,r*o);for(let i=0;i<e;i++)for(let e=0;e<r;e++)for(let r=0;r<n;r++)for(let a=0;a<o;a++)s.set(n*i+r,o*e+a,this.get(i,e)*t.get(r,a));return s}kroneckerSum(t){if(t=S.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(S.eye(r,r)),o=S.eye(e,e).kroneckerProduct(t);return n.add(o)}transpose(){let t=new S(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=M){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=M){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){w(this,t,e,r,n);let o=new S(e-t+1,n-r+1);for(let s=t;s<=e;s++)for(let e=r;e<=n;e++)o.set(s-t,e-r,this.get(s,e));return o}subMatrixRow(t,e,r){if(void 0===e&&(e=0),void 0===r&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new S(t.length,r-e+1);for(let o=0;o<t.length;o++)for(let s=e;s<=r;s++){if(t[o]<0||t[o]>=this.rows)throw new RangeError(`Row index out of range: ${t[o]}`);n.set(o,s-e,this.get(t[o],s))}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 S(r-e+1,t.length);for(let o=0;o<t.length;o++)for(let s=e;s<=r;s++){if(t[o]<0||t[o]>=this.columns)throw new RangeError(`Column index out of range: ${t[o]}`);n.set(s-e,o,this.get(s,t[o]))}return n}setSubMatrix(t,e,r){if((t=S.checkMatrix(t)).isEmpty())return this;w(this,e,e+t.rows-1,r,r+t.columns-1);for(let n=0;n<t.rows;n++)for(let o=0;o<t.columns;o++)this.set(e+n,r+o,t.get(n,o));return this}selection(t,e){g(this,t),p(this,e);let r=new S(t.length,e.length);for(let n=0;n<t.length;n++){let o=t[n];for(let t=0;t<e.length;t++){let s=e[t];r.set(n,t,this.get(o,s))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){return this.constructor.copy(this,new S(this.rows,this.columns))}static copy(t,e){for(const[r,n,o]of t.entries())e.set(r,n,o);return e}sum(t){switch(t){case"row":return function(t){let e=d(t.rows);for(let r=0;r<t.rows;++r)for(let n=0;n<t.columns;++n)e[r]+=t.get(r,n);return e}(this);case"column":return function(t){let e=d(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=d(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=d(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:o=this.mean(t)}=e;if("boolean"!=typeof r)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!n.isAnyArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,s=[];for(let i=0;i<n;i++){let n=0,a=0,u=0;for(let e=0;e<o;e++)u=t.get(i,e)-r[i],n+=u,a+=u*u;e?s.push((a-n*n/o)/(o-1)):s.push((a-n*n/o)/o)}return s}(this,r,o);case"column":if(!n.isAnyArray(o))throw new TypeError("mean must be an array");return function(t,e,r){const n=t.rows,o=t.columns,s=[];for(let i=0;i<o;i++){let o=0,a=0,u=0;for(let e=0;e<n;e++)u=t.get(e,i)-r[i],o+=u,a+=u*u;e?s.push((a-o*o/n)/(n-1)):s.push((a-o*o/n)/n)}return s}(this,r,o);case void 0:if("number"!=typeof o)throw new TypeError("mean must be a number");return function(t,e,r){const n=t.rows,o=t.columns,s=n*o;let i=0,a=0,u=0;for(let e=0;e<n;e++)for(let n=0;n<o;n++)u=t.get(e,n)-r,i+=u,a+=u*u;return e?(a-i*i/s)/(s-1):(a-i*i/s)/s}(this,r,o);default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){"object"==typeof t&&(e=t,t=void 0);const r=this.variance(t,e);if(void 0===t)return Math.sqrt(r);for(let t=0;t<r.length;t++)r[t]=Math.sqrt(r[t]);return r}center(t,e={}){if("object"==typeof t&&(e=t,t=void 0),"object"!=typeof e)throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":if(!n.isAnyArray(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(!n.isAnyArray(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+=t.get(r,e)**2/(t.columns-1);e.push(Math.sqrt(n))}return e}(this);else if(!n.isAnyArray(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+=t.get(e,r)**2/(t.rows-1);e.push(Math.sqrt(n))}return e}(this);else if(!n.isAnyArray(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 o=0;o<t.rows;o++)r+=t.get(o,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 a(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}function M(t,e){return t-e}function x(t){return t.every(t=>"number"==typeof t)}b.prototype.klass="Matrix","undefined"!=typeof Symbol&&(b.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return a(this)}),b.random=b.rand,b.randomInt=b.randInt,b.diagonal=b.diag,b.prototype.diagonal=b.prototype.diag,b.identity=b.eye,b.prototype.negate=b.prototype.neg,b.prototype.tensorProduct=b.prototype.kroneckerProduct;class S extends b{data;#t(t,e){if(this.data=[],!(Number.isInteger(e)&&e>=0))throw new TypeError("nColumns must be a positive integer");for(let r=0;r<t;r++)this.data.push(new Float64Array(e));this.rows=t,this.columns=e}constructor(t,e){if(super(),S.isMatrix(t))this.#t(t.rows,t.columns),S.copy(t,this);else if(Number.isInteger(t)&&t>=0)this.#t(t,e);else{if(!n.isAnyArray(t))throw new TypeError("First argument must be a positive number or an array");{const r=t;if("number"!=typeof(e=(t=r.length)?r[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let n=0;n<t;n++){if(r[n].length!==e)throw new RangeError("Inconsistent array dimensions");if(!x(r[n]))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 l(this,t),this.data.splice(t,1),this.rows-=1,this}addRow(t,e){return void 0===e&&(e=t,t=this.rows),l(this,t,!0),e=Float64Array.from(f(this,e)),this.data.splice(t,0,e),this.rows+=1,this}removeColumn(t){c(this,t);for(let e=0;e<this.rows;e++){const r=new Float64Array(this.columns-1);for(let 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),c(this,t,!0),e=m(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns+1);let o=0;for(;o<t;o++)n[o]=this.data[r][o];for(n[o++]=e[r];o<this.columns+1;o++)n[o]=this.data[r][o-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,this.get(e,r)**t);return this},t.prototype.powM=function(t){if(t=e.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)**t.get(e,r));return this}}(b,S);class E extends b{#e;get size(){return this.#e.size}get rows(){return this.#e.rows}get columns(){return this.#e.columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(t){return S.isMatrix(t)&&"SymmetricMatrix"===t.klassType}static zeros(t){return new this(t)}static ones(t){return new this(t).fill(1)}constructor(t){if(super(),S.isMatrix(t)){if(!t.isSymmetric())throw new TypeError("not symmetric data");this.#e=S.copy(t,new S(t.rows,t.rows))}else if(Number.isInteger(t)&&t>=0)this.#e=new S(t,t);else if(this.#e=new S(t),!this.isSymmetric())throw new TypeError("not symmetric data")}clone(){const t=new E(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())t.set(e,r,n);return t}toMatrix(){return new S(this)}get(t,e){return this.#e.get(t,e)}set(t,e,r){return this.#e.set(t,e,r),this.#e.set(e,t,r),this}removeCross(t){return this.#e.removeRow(t),this.#e.removeColumn(t),this}addCross(t,e){void 0===e&&(e=t,t=this.diagonalSize);const r=e.slice();return r.splice(t,1),this.#e.addRow(t,r),this.#e.addColumn(t,e),this}applyMask(t){if(t.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const e=[];for(const[r,n]of t.entries())n||e.push(r);e.reverse();for(const t of e)this.removeCross(t);return this}toCompact(){const{diagonalSize:t}=this,e=new Array(t*(t+1)/2);for(let r=0,n=0,o=0;o<e.length;o++)e[o]=this.get(n,r),++r>=t&&(r=++n);return e}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)-1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(t)}`);const n=new E(r);for(let o=0,s=0,i=0;i<e;i++)n.set(o,s,t[i]),++o>=r&&(o=++s);return n}*upperRightEntries(){for(let t=0,e=0;t<this.diagonalSize;void 0){const r=this.get(t,e);yield[t,e,r],++e>=this.diagonalSize&&(e=++t)}}*upperRightValues(){for(let t=0,e=0;t<this.diagonalSize;void 0){const r=this.get(t,e);yield r,++e>=this.diagonalSize&&(e=++t)}}}E.prototype.klassType="SymmetricMatrix";class A extends E{static isDistanceMatrix(t){return E.isSymmetricMatrix(t)&&"DistanceMatrix"===t.klassSubType}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return void 0===e&&(e=t,t=this.diagonalSize),(e=e.slice())[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new E(this)}clone(){const t=new A(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())e!==r&&t.set(e,r,n);return t}toCompact(){const{diagonalSize:t}=this,e=new Array((t-1)*t/2);for(let r=1,n=0,o=0;o<e.length;o++)e[o]=this.get(n,r),++r>=t&&(r=1+ ++n);return e}static fromCompact(t){const e=t.length;if(0===e)return new this(0);const r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const n=new this(r);for(let o=1,s=0,i=0;i<e;i++)n.set(o,s,t[i]),++o>=r&&(o=1+ ++s);return n}}A.prototype.klassSubType="DistanceMatrix";class R extends b{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class _ extends R{constructor(t,e,r){g(t,e),p(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class N extends b{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class k extends b{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}class z{constructor(t){let e,r,n,o,s,i,a,u,h,l=(t=k.checkMatrix(t)).clone(),c=l.rows,f=l.columns,m=new Float64Array(c),g=1;for(e=0;e<c;e++)m[e]=e;for(u=new Float64Array(c),r=0;r<f;r++){for(e=0;e<c;e++)u[e]=l.get(e,r);for(e=0;e<c;e++){for(h=Math.min(e,r),s=0,n=0;n<h;n++)s+=l.get(e,n)*u[n];u[e]-=s,l.set(e,r,u[e])}for(o=r,e=r+1;e<c;e++)Math.abs(u[e])>Math.abs(u[o])&&(o=e);if(o!==r){for(n=0;n<f;n++)i=l.get(o,n),l.set(o,n,l.get(r,n)),l.set(r,n,i);a=m[o],m[o]=m[r],m[r]=a,g=-g}if(r<c&&0!==l.get(r,r))for(e=r+1;e<c;e++)l.set(e,r,l.get(e,r)/l.get(r,r))}this.LU=l,this.pivotVector=m,this.pivotSign=g}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(0===t.get(r,r))return!0;return!1}solve(t){t=S.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,o,s=t.columns,i=t.subMatrixRow(this.pivotVector,0,s-1),a=e.columns;for(o=0;o<a;o++)for(r=o+1;r<a;r++)for(n=0;n<s;n++)i.set(r,n,i.get(r,n)-i.get(o,n)*e.get(r,o));for(o=a-1;o>=0;o--){for(n=0;n<s;n++)i.set(o,n,i.get(o,n)/e.get(o,o));for(r=0;r<o;r++)for(n=0;n<s;n++)i.set(r,n,i.get(r,n)-i.get(o,n)*e.get(r,o))}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 S(e,r);for(let o=0;o<e;o++)for(let e=0;e<r;e++)o>e?n.set(o,e,t.get(o,e)):o===e?n.set(o,e,1):n.set(o,e,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new S(e,r);for(let o=0;o<e;o++)for(let e=0;e<r;e++)o<=e?n.set(o,e,t.get(o,e)):n.set(o,e,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function I(t,e){let r=0;return Math.abs(t)>Math.abs(e)?(r=e/t,Math.abs(t)*Math.sqrt(1+r*r)):0!==e?(r=t/e,Math.abs(e)*Math.sqrt(1+r*r)):0}class O{constructor(t){let e,r,n,o,s=(t=k.checkMatrix(t)).clone(),i=t.rows,a=t.columns,u=new Float64Array(a);for(n=0;n<a;n++){let t=0;for(e=n;e<i;e++)t=I(t,s.get(e,n));if(0!==t){for(s.get(n,n)<0&&(t=-t),e=n;e<i;e++)s.set(e,n,s.get(e,n)/t);for(s.set(n,n,s.get(n,n)+1),r=n+1;r<a;r++){for(o=0,e=n;e<i;e++)o+=s.get(e,n)*s.get(e,r);for(o=-o/s.get(n,n),e=n;e<i;e++)s.set(e,r,s.get(e,r)+o*s.get(e,n))}}u[n]=-t}this.QR=s,this.Rdiag=u}solve(t){t=S.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,o,s,i,a=t.columns,u=t.clone(),h=e.columns;for(s=0;s<h;s++)for(o=0;o<a;o++){for(i=0,n=s;n<r;n++)i+=e.get(n,s)*u.get(n,o);for(i=-i/e.get(s,s),n=s;n<r;n++)u.set(n,o,u.get(n,o)+i*e.get(n,s))}for(s=h-1;s>=0;s--){for(o=0;o<a;o++)u.set(s,o,u.get(s,o)/this.Rdiag[s]);for(n=0;n<s;n++)for(o=0;o<a;o++)u.set(n,o,u.get(n,o)-u.get(s,o)*e.get(n,s))}return u.subMatrix(0,h-1,0,a-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(0===this.Rdiag[e])return!1;return!0}get upperTriangularMatrix(){let t,e,r=this.QR,n=r.columns,o=new S(n,n);for(t=0;t<n;t++)for(e=0;e<n;e++)t<e?o.set(t,e,r.get(t,e)):t===e?o.set(t,e,this.Rdiag[t]):o.set(t,e,0);return o}get orthogonalMatrix(){let t,e,r,n,o=this.QR,s=o.rows,i=o.columns,a=new S(s,i);for(r=i-1;r>=0;r--){for(t=0;t<s;t++)a.set(t,r,0);for(a.set(r,r,1),e=r;e<i;e++)if(0!==o.get(r,r)){for(n=0,t=r;t<s;t++)n+=o.get(t,r)*a.get(t,e);for(n=-n/o.get(r,r),t=r;t<s;t++)a.set(t,e,a.get(t,e)+n*o.get(t,r))}}return a}}class T{constructor(t,e={}){if((t=k.checkMatrix(t)).isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:o=!0,computeRightSingularVectors:s=!0,autoTranspose:i=!1}=e;let a,u=Boolean(o),h=Boolean(s),l=!1;if(r<n)if(i){a=t.transpose(),r=a.rows,n=a.columns,l=!0;let e=u;u=h,h=e}else a=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else a=t.clone();let c=Math.min(r,n),f=Math.min(r+1,n),m=new Float64Array(f),g=new S(r,c),p=new S(n,n),w=new Float64Array(n),d=new Float64Array(r),y=new Float64Array(f);for(let t=0;t<f;t++)y[t]=t;let v=Math.min(r-1,n),b=Math.max(0,Math.min(n-2,r)),M=Math.max(v,b);for(let t=0;t<M;t++){if(t<v){m[t]=0;for(let e=t;e<r;e++)m[t]=I(m[t],a.get(e,t));if(0!==m[t]){a.get(t,t)<0&&(m[t]=-m[t]);for(let e=t;e<r;e++)a.set(e,t,a.get(e,t)/m[t]);a.set(t,t,a.get(t,t)+1)}m[t]=-m[t]}for(let e=t+1;e<n;e++){if(t<v&&0!==m[t]){let n=0;for(let o=t;o<r;o++)n+=a.get(o,t)*a.get(o,e);n=-n/a.get(t,t);for(let o=t;o<r;o++)a.set(o,e,a.get(o,e)+n*a.get(o,t))}w[e]=a.get(t,e)}if(u&&t<v)for(let e=t;e<r;e++)g.set(e,t,a.get(e,t));if(t<b){w[t]=0;for(let e=t+1;e<n;e++)w[t]=I(w[t],w[e]);if(0!==w[t]){w[t+1]<0&&(w[t]=0-w[t]);for(let e=t+1;e<n;e++)w[e]/=w[t];w[t+1]+=1}if(w[t]=-w[t],t+1<r&&0!==w[t]){for(let e=t+1;e<r;e++)d[e]=0;for(let e=t+1;e<r;e++)for(let r=t+1;r<n;r++)d[e]+=w[r]*a.get(e,r);for(let e=t+1;e<n;e++){let n=-w[e]/w[t+1];for(let o=t+1;o<r;o++)a.set(o,e,a.get(o,e)+n*d[o])}}if(h)for(let e=t+1;e<n;e++)p.set(e,t,w[e])}}let x=Math.min(n,r+1);if(v<n&&(m[v]=a.get(v,v)),r<x&&(m[x-1]=0),b+1<x&&(w[b]=a.get(b,x-1)),w[x-1]=0,u){for(let t=v;t<c;t++){for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}for(let t=v-1;t>=0;t--)if(0!==m[t]){for(let e=t+1;e<c;e++){let n=0;for(let o=t;o<r;o++)n+=g.get(o,t)*g.get(o,e);n=-n/g.get(t,t);for(let o=t;o<r;o++)g.set(o,e,g.get(o,e)+n*g.get(o,t))}for(let e=t;e<r;e++)g.set(e,t,-g.get(e,t));g.set(t,t,1+g.get(t,t));for(let e=0;e<t-1;e++)g.set(e,t,0)}else{for(let e=0;e<r;e++)g.set(e,t,0);g.set(t,t,1)}}if(h)for(let t=n-1;t>=0;t--){if(t<b&&0!==w[t])for(let e=t+1;e<n;e++){let r=0;for(let o=t+1;o<n;o++)r+=p.get(o,t)*p.get(o,e);r=-r/p.get(t+1,t);for(let o=t+1;o<n;o++)p.set(o,e,p.get(o,e)+r*p.get(o,t))}for(let e=0;e<n;e++)p.set(e,t,0);p.set(t,t,1)}let E=x-1,A=Number.EPSILON;for(;x>0;){let t,e;for(t=x-2;t>=-1&&-1!==t;t--){const e=Number.MIN_VALUE+A*Math.abs(m[t]+Math.abs(m[t+1]));if(Math.abs(w[t])<=e||Number.isNaN(w[t])){w[t]=0;break}}if(t===x-2)e=4;else{let r;for(r=x-1;r>=t&&r!==t;r--){let e=(r!==x?Math.abs(w[r]):0)+(r!==t+1?Math.abs(w[r-1]):0);if(Math.abs(m[r])<=A*e){m[r]=0;break}}r===t?e=3:r===x-1?e=1:(e=2,t=r)}switch(t++,e){case 1:{let e=w[x-2];w[x-2]=0;for(let r=x-2;r>=t;r--){let o=I(m[r],e),s=m[r]/o,i=e/o;if(m[r]=o,r!==t&&(e=-i*w[r-1],w[r-1]=s*w[r-1]),h)for(let t=0;t<n;t++)o=s*p.get(t,r)+i*p.get(t,x-1),p.set(t,x-1,-i*p.get(t,r)+s*p.get(t,x-1)),p.set(t,r,o)}break}case 2:{let e=w[t-1];w[t-1]=0;for(let n=t;n<x;n++){let o=I(m[n],e),s=m[n]/o,i=e/o;if(m[n]=o,e=-i*w[n],w[n]=s*w[n],u)for(let e=0;e<r;e++)o=s*g.get(e,n)+i*g.get(e,t-1),g.set(e,t-1,-i*g.get(e,n)+s*g.get(e,t-1)),g.set(e,n,o)}break}case 3:{const e=Math.max(Math.abs(m[x-1]),Math.abs(m[x-2]),Math.abs(w[x-2]),Math.abs(m[t]),Math.abs(w[t])),o=m[x-1]/e,s=m[x-2]/e,i=w[x-2]/e,a=m[t]/e,l=w[t]/e,c=((s+o)*(s-o)+i*i)/2,f=o*i*(o*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=(a+o)*(a-o)+d,v=a*l;for(let e=t;e<x-1;e++){let o=I(y,v);0===o&&(o=Number.MIN_VALUE);let s=y/o,i=v/o;if(e!==t&&(w[e-1]=o),y=s*m[e]+i*w[e],w[e]=s*w[e]-i*m[e],v=i*m[e+1],m[e+1]=s*m[e+1],h)for(let t=0;t<n;t++)o=s*p.get(t,e)+i*p.get(t,e+1),p.set(t,e+1,-i*p.get(t,e)+s*p.get(t,e+1)),p.set(t,e,o);if(o=I(y,v),0===o&&(o=Number.MIN_VALUE),s=y/o,i=v/o,m[e]=o,y=s*w[e]+i*m[e+1],m[e+1]=-i*w[e]+s*m[e+1],v=i*w[e+1],w[e+1]=s*w[e+1],u&&e<r-1)for(let t=0;t<r;t++)o=s*g.get(t,e)+i*g.get(t,e+1),g.set(t,e+1,-i*g.get(t,e)+s*g.get(t,e+1)),g.set(t,e,o)}w[x-2]=y;break}case 4:if(m[t]<=0&&(m[t]=m[t]<0?-m[t]:0,h))for(let e=0;e<=E;e++)p.set(e,t,-p.get(e,t));for(;t<E&&!(m[t]>=m[t+1]);){let e=m[t];if(m[t]=m[t+1],m[t+1]=e,h&&t<n-1)for(let r=0;r<n;r++)e=p.get(r,t+1),p.set(r,t+1,p.get(r,t)),p.set(r,t,e);if(u&&t<r-1)for(let n=0;n<r;n++)e=g.get(n,t+1),g.set(n,t+1,g.get(n,t)),g.set(n,t,e);t++}x--}}if(l){let t=p;p=g,g=t}this.m=r,this.n=n,this.s=m,this.U=g,this.V=p}solve(t){let e=t,r=this.threshold,n=this.s.length,o=S.zeros(n,n);for(let t=0;t<n;t++)Math.abs(this.s[t])<=r?o.set(t,t,0):o.set(t,t,1/this.s[t]);let s=this.U,i=this.rightSingularVectors,a=i.mmul(o),u=i.rows,h=s.rows,l=S.zeros(u,h);for(let t=0;t<u;t++)for(let e=0;e<h;e++){let r=0;for(let o=0;o<n;o++)r+=a.get(t,o)*s.get(e,o);l.set(t,e,r)}return l.mmul(e)}solveForDiagonal(t){return this.solve(S.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,o=new S(r,this.s.length);for(let s=0;s<r;s++)for(let r=0;r<n;r++)Math.abs(this.s[r])>e&&o.set(s,r,t.get(s,r)/this.s[r]);let s=this.U,i=s.rows,a=s.columns,u=new S(r,i);for(let t=0;t<r;t++)for(let e=0;e<i;e++){let r=0;for(let n=0;n<a;n++)r+=o.get(t,n)*s.get(e,n);u.set(t,e,r)}return u}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,o=r.length;n<o;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 S.diag(this.s)}}function P(t,e,r=!1){return t=k.checkMatrix(t),e=k.checkMatrix(e),r?new T(t).solve(e):t.isSquare()?new z(t).solve(e):new O(t).solve(e)}function j(t,e){let r=[];for(let n=0;n<t;n++)n!==e&&r.push(n);return r}function W(t,e,r,n=1e-9,o=1e-9){if(t>o)return new Array(e.rows+1).fill(0);{let t=e.addRow(r,[0]);for(let e=0;e<t.rows;e++)Math.abs(t.get(e,0))<n&&t.set(e,0,0);return t.to1DArray()}}class C{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(!(t=k.checkMatrix(t)).isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n,o,s=t.columns,i=new S(s,s),a=new Float64Array(s),u=new Float64Array(s),h=t,l=!1;if(l=!!r||t.isSymmetric(),l){for(n=0;n<s;n++)for(o=0;o<s;o++)i.set(n,o,h.get(n,o));!function(t,e,r,n){let o,s,i,a,u,h,l,c;for(u=0;u<t;u++)r[u]=n.get(t-1,u);for(a=t-1;a>0;a--){for(c=0,i=0,h=0;h<a;h++)c+=Math.abs(r[h]);if(0===c)for(e[a]=r[a-1],u=0;u<a;u++)r[u]=n.get(a-1,u),n.set(a,u,0),n.set(u,a,0);else{for(h=0;h<a;h++)r[h]/=c,i+=r[h]*r[h];for(o=r[a-1],s=Math.sqrt(i),o>0&&(s=-s),e[a]=c*s,i-=o*s,r[a-1]=o-s,u=0;u<a;u++)e[u]=0;for(u=0;u<a;u++){for(o=r[u],n.set(u,a,o),s=e[u]+n.get(u,u)*o,h=u+1;h<=a-1;h++)s+=n.get(h,u)*r[h],e[h]+=n.get(h,u)*o;e[u]=s}for(o=0,u=0;u<a;u++)e[u]/=i,o+=e[u]*r[u];for(l=o/(i+i),u=0;u<a;u++)e[u]-=l*r[u];for(u=0;u<a;u++){for(o=r[u],s=e[u],h=u;h<=a-1;h++)n.set(h,u,n.get(h,u)-(o*e[h]+s*r[h]));r[u]=n.get(a-1,u),n.set(a,u,0)}}r[a]=i}for(a=0;a<t-1;a++){if(n.set(t-1,a,n.get(a,a)),n.set(a,a,1),i=r[a+1],0!==i){for(h=0;h<=a;h++)r[h]=n.get(h,a+1)/i;for(u=0;u<=a;u++){for(s=0,h=0;h<=a;h++)s+=n.get(h,a+1)*n.get(h,u);for(h=0;h<=a;h++)n.set(h,u,n.get(h,u)-s*r[h])}}for(h=0;h<=a;h++)n.set(h,a+1,0)}for(u=0;u<t;u++)r[u]=n.get(t-1,u),n.set(t-1,u,0);n.set(t-1,t-1,1),e[0]=0}(s,u,a,i),function(t,e,r,n){let o,s,i,a,u,h,l,c,f,m,g,p,w,d,y,v;for(i=1;i<t;i++)e[i-1]=e[i];e[t-1]=0;let b=0,M=0,x=Number.EPSILON;for(h=0;h<t;h++){for(M=Math.max(M,Math.abs(r[h])+Math.abs(e[h])),l=h;l<t&&!(Math.abs(e[l])<=x*M);)l++;if(l>h)do{for(o=r[h],c=(r[h+1]-o)/(2*e[h]),f=I(c,1),c<0&&(f=-f),r[h]=e[h]/(c+f),r[h+1]=e[h]*(c+f),m=r[h+1],s=o-r[h],i=h+2;i<t;i++)r[i]-=s;for(b+=s,c=r[l],g=1,p=g,w=g,d=e[h+1],y=0,v=0,i=l-1;i>=h;i--)for(w=p,p=g,v=y,o=g*e[i],s=g*c,f=I(c,e[i]),e[i+1]=y*f,y=e[i]/f,g=c/f,c=g*r[i]-y*o,r[i+1]=s+y*(g*o+y*r[i]),u=0;u<t;u++)s=n.get(u,i+1),n.set(u,i+1,y*n.get(u,i)+g*s),n.set(u,i,g*n.get(u,i)-y*s);c=-y*v*w*d*e[h]/m,e[h]=y*c,r[h]=g*c}while(Math.abs(e[h])>x*M);r[h]=r[h]+b,e[h]=0}for(i=0;i<t-1;i++){for(u=i,c=r[i],a=i+1;a<t;a++)r[a]<c&&(u=a,c=r[a]);if(u!==i)for(r[u]=r[i],r[i]=c,a=0;a<t;a++)c=n.get(a,i),n.set(a,i,n.get(a,u)),n.set(a,u,c)}}(s,u,a,i)}else{let t=new S(s,s),e=new Float64Array(s);for(o=0;o<s;o++)for(n=0;n<s;n++)t.set(n,o,h.get(n,o));!function(t,e,r,n){let o,s,i,a,u,h,l,c=t-1;for(h=1;h<=c-1;h++){for(l=0,a=h;a<=c;a++)l+=Math.abs(e.get(a,h-1));if(0!==l){for(i=0,a=c;a>=h;a--)r[a]=e.get(a,h-1)/l,i+=r[a]*r[a];for(s=Math.sqrt(i),r[h]>0&&(s=-s),i-=r[h]*s,r[h]=r[h]-s,u=h;u<t;u++){for(o=0,a=c;a>=h;a--)o+=r[a]*e.get(a,u);for(o/=i,a=h;a<=c;a++)e.set(a,u,e.get(a,u)-o*r[a])}for(a=0;a<=c;a++){for(o=0,u=c;u>=h;u--)o+=r[u]*e.get(a,u);for(o/=i,u=h;u<=c;u++)e.set(a,u,e.get(a,u)-o*r[u])}r[h]=l*r[h],e.set(h,h-1,l*s)}}for(a=0;a<t;a++)for(u=0;u<t;u++)n.set(a,u,a===u?1:0);for(h=c-1;h>=1;h--)if(0!==e.get(h,h-1)){for(a=h+1;a<=c;a++)r[a]=e.get(a,h-1);for(u=h;u<=c;u++){for(s=0,a=h;a<=c;a++)s+=r[a]*n.get(a,u);for(s=s/r[h]/e.get(h,h-1),a=h;a<=c;a++)n.set(a,u,n.get(a,u)+s*r[a])}}}(s,t,e,i),function(t,e,r,n,o){let s,i,a,u,h,l,c,f,m,g,p,w,d,y,v,b=t-1,M=t-1,x=Number.EPSILON,S=0,E=0,A=0,R=0,_=0,N=0,k=0,z=0;for(s=0;s<t;s++)for((s<0||s>M)&&(r[s]=o.get(s,s),e[s]=0),i=Math.max(s-1,0);i<t;i++)E+=Math.abs(o.get(s,i));for(;b>=0;){for(u=b;u>0&&(N=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)),0===N&&(N=E),!(Math.abs(o.get(u,u-1))<x*N));)u--;if(u===b)o.set(b,b,o.get(b,b)+S),r[b]=o.get(b,b),e[b]=0,b--,z=0;else if(u===b-1){if(c=o.get(b,b-1)*o.get(b-1,b),A=(o.get(b-1,b-1)-o.get(b,b))/2,R=A*A+c,k=Math.sqrt(Math.abs(R)),o.set(b,b,o.get(b,b)+S),o.set(b-1,b-1,o.get(b-1,b-1)+S),f=o.get(b,b),R>=0){for(k=A>=0?A+k:A-k,r[b-1]=f+k,r[b]=r[b-1],0!==k&&(r[b]=f-c/k),e[b-1]=0,e[b]=0,f=o.get(b,b-1),N=Math.abs(f)+Math.abs(k),A=f/N,R=k/N,_=Math.sqrt(A*A+R*R),A/=_,R/=_,i=b-1;i<t;i++)k=o.get(b-1,i),o.set(b-1,i,R*k+A*o.get(b,i)),o.set(b,i,R*o.get(b,i)-A*k);for(s=0;s<=b;s++)k=o.get(s,b-1),o.set(s,b-1,R*k+A*o.get(s,b)),o.set(s,b,R*o.get(s,b)-A*k);for(s=0;s<=M;s++)k=n.get(s,b-1),n.set(s,b-1,R*k+A*n.get(s,b)),n.set(s,b,R*n.get(s,b)-A*k)}else r[b-1]=f+A,r[b]=f+A,e[b-1]=k,e[b]=-k;b-=2,z=0}else{if(f=o.get(b,b),m=0,c=0,u<b&&(m=o.get(b-1,b-1),c=o.get(b,b-1)*o.get(b-1,b)),10===z){for(S+=f,s=0;s<=b;s++)o.set(s,s,o.get(s,s)-f);N=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2)),f=m=.75*N,c=-.4375*N*N}if(30===z&&(N=(m-f)/2,N=N*N+c,N>0)){for(N=Math.sqrt(N),m<f&&(N=-N),N=f-c/((m-f)/2+N),s=0;s<=b;s++)o.set(s,s,o.get(s,s)-N);S+=N,f=m=c=.964}for(z+=1,h=b-2;h>=u&&(k=o.get(h,h),_=f-k,N=m-k,A=(_*N-c)/o.get(h+1,h)+o.get(h,h+1),R=o.get(h+1,h+1)-k-_-N,_=o.get(h+2,h+1),N=Math.abs(A)+Math.abs(R)+Math.abs(_),A/=N,R/=N,_/=N,h!==u)&&!(Math.abs(o.get(h,h-1))*(Math.abs(R)+Math.abs(_))<x*(Math.abs(A)*(Math.abs(o.get(h-1,h-1))+Math.abs(k)+Math.abs(o.get(h+1,h+1)))));)h--;for(s=h+2;s<=b;s++)o.set(s,s-2,0),s>h+2&&o.set(s,s-3,0);for(a=h;a<=b-1&&(y=a!==b-1,a!==h&&(A=o.get(a,a-1),R=o.get(a+1,a-1),_=y?o.get(a+2,a-1):0,f=Math.abs(A)+Math.abs(R)+Math.abs(_),0!==f&&(A/=f,R/=f,_/=f)),0!==f);a++)if(N=Math.sqrt(A*A+R*R+_*_),A<0&&(N=-N),0!==N){for(a!==h?o.set(a,a-1,-N*f):u!==h&&o.set(a,a-1,-o.get(a,a-1)),A+=N,f=A/N,m=R/N,k=_/N,R/=A,_/=A,i=a;i<t;i++)A=o.get(a,i)+R*o.get(a+1,i),y&&(A+=_*o.get(a+2,i),o.set(a+2,i,o.get(a+2,i)-A*k)),o.set(a,i,o.get(a,i)-A*f),o.set(a+1,i,o.get(a+1,i)-A*m);for(s=0;s<=Math.min(b,a+3);s++)A=f*o.get(s,a)+m*o.get(s,a+1),y&&(A+=k*o.get(s,a+2),o.set(s,a+2,o.get(s,a+2)-A*_)),o.set(s,a,o.get(s,a)-A),o.set(s,a+1,o.get(s,a+1)-A*R);for(s=0;s<=M;s++)A=f*n.get(s,a)+m*n.get(s,a+1),y&&(A+=k*n.get(s,a+2),n.set(s,a+2,n.get(s,a+2)-A*_)),n.set(s,a,n.get(s,a)-A),n.set(s,a+1,n.get(s,a+1)-A*R)}}}if(0!==E){for(b=t-1;b>=0;b--)if(A=r[b],R=e[b],0===R)for(u=b,o.set(b,b,1),s=b-1;s>=0;s--){for(c=o.get(s,s)-A,_=0,i=u;i<=b;i++)_+=o.get(s,i)*o.get(i,b);if(e[s]<0)k=c,N=_;else if(u=s,0===e[s]?o.set(s,b,0!==c?-_/c:-_/(x*E)):(f=o.get(s,s+1),m=o.get(s+1,s),R=(r[s]-A)*(r[s]-A)+e[s]*e[s],l=(f*N-k*_)/R,o.set(s,b,l),o.set(s+1,b,Math.abs(f)>Math.abs(k)?(-_-c*l)/f:(-N-m*l)/k)),l=Math.abs(o.get(s,b)),x*l*l>1)for(i=s;i<=b;i++)o.set(i,b,o.get(i,b)/l)}else if(R<0)for(u=b-1,Math.abs(o.get(b,b-1))>Math.abs(o.get(b-1,b))?(o.set(b-1,b-1,R/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-A)/o.get(b,b-1))):(v=F(0,-o.get(b-1,b),o.get(b-1,b-1)-A,R),o.set(b-1,b-1,v[0]),o.set(b-1,b,v[1])),o.set(b,b-1,0),o.set(b,b,1),s=b-2;s>=0;s--){for(g=0,p=0,i=u;i<=b;i++)g+=o.get(s,i)*o.get(i,b-1),p+=o.get(s,i)*o.get(i,b);if(c=o.get(s,s)-A,e[s]<0)k=c,_=g,N=p;else if(u=s,0===e[s]?(v=F(-g,-p,c,R),o.set(s,b-1,v[0]),o.set(s,b,v[1])):(f=o.get(s,s+1),m=o.get(s+1,s),w=(r[s]-A)*(r[s]-A)+e[s]*e[s]-R*R,d=2*(r[s]-A)*R,0===w&&0===d&&(w=x*E*(Math.abs(c)+Math.abs(R)+Math.abs(f)+Math.abs(m)+Math.abs(k))),v=F(f*_-k*g+R*p,f*N-k*p-R*g,w,d),o.set(s,b-1,v[0]),o.set(s,b,v[1]),Math.abs(f)>Math.abs(k)+Math.abs(R)?(o.set(s+1,b-1,(-g-c*o.get(s,b-1)+R*o.get(s,b))/f),o.set(s+1,b,(-p-c*o.get(s,b)-R*o.get(s,b-1))/f)):(v=F(-_-m*o.get(s,b-1),-N-m*o.get(s,b),k,R),o.set(s+1,b-1,v[0]),o.set(s+1,b,v[1]))),l=Math.max(Math.abs(o.get(s,b-1)),Math.abs(o.get(s,b))),x*l*l>1)for(i=s;i<=b;i++)o.set(i,b-1,o.get(i,b-1)/l),o.set(i,b,o.get(i,b)/l)}for(s=0;s<t;s++)if(s<0||s>M)for(i=s;i<t;i++)n.set(s,i,o.get(s,i));for(i=t-1;i>=0;i--)for(s=0;s<=M;s++){for(k=0,a=0;a<=Math.min(i,M);a++)k+=n.get(s,a)*o.get(a,i);n.set(s,i,k)}}}(s,u,a,i,t)}this.n=s,this.e=u,this.d=a,this.V=i}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t,e,r=this.n,n=this.e,o=this.d,s=new S(r,r);for(t=0;t<r;t++){for(e=0;e<r;e++)s.set(t,e,0);s.set(t,t,o[t]),n[t]>0?s.set(t,t+1,n[t]):n[t]<0&&s.set(t,t-1,n[t])}return s}}function F(t,e,r,n){let o,s;return Math.abs(r)>Math.abs(n)?(o=n/r,s=r+o*n,[(t+o*e)/s,(e-o*t)/s]):(o=r/n,s=n+o*r,[(o*t+e)/s,(o*e-t)/s])}class D{constructor(t){if(!(t=k.checkMatrix(t)).isSymmetric())throw new Error("Matrix is not symmetric");let e,r,n,o=t,s=o.rows,i=new S(s,s),a=!0;for(r=0;r<s;r++){let t=0;for(n=0;n<r;n++){let s=0;for(e=0;e<n;e++)s+=i.get(n,e)*i.get(r,e);s=(o.get(r,n)-s)/i.get(n,n),i.set(r,n,s),t+=s*s}for(t=o.get(r,r)-t,a&&=t>0,i.set(r,r,Math.sqrt(Math.max(t,0))),n=r+1;n<s;n++)i.set(r,n,0)}this.L=i,this.positiveDefinite=a}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=k.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(!1===this.isPositiveDefinite())throw new Error("Matrix is not positive definite");let n,o,s,i=t.columns,a=t.clone();for(s=0;s<r;s++)for(o=0;o<i;o++){for(n=0;n<s;n++)a.set(s,o,a.get(s,o)-a.get(n,o)*e.get(s,n));a.set(s,o,a.get(s,o)/e.get(s,s))}for(s=r-1;s>=0;s--)for(o=0;o<i;o++){for(n=s+1;n<r;n++)a.set(s,o,a.get(s,o)-a.get(n,o)*e.get(n,s));a.set(s,o,a.get(s,o)/e.get(s,s))}return a}get lowerTriangularMatrix(){return this.L}}class q{constructor(t,e={}){t=k.checkMatrix(t);let{Y:r}=e;const{scaleScores:o=!1,maxIterations:s=1e3,terminationCriteria:i=1e-10}=e;let a;if(r){if(r=n.isAnyArray(r)&&"number"==typeof r[0]?S.columnVector(r):k.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");a=r.getColumnVector(0)}else a=t.getColumnVector(0);let u,h,l,c,f=1;for(let e=0;e<s&&f>i;e++)l=t.transpose().mmul(a).div(a.transpose().mmul(a).get(0,0)),l=l.div(l.norm()),u=t.mmul(l).div(l.transpose().mmul(l).get(0,0)),e>0&&(f=u.clone().sub(c).pow(2).sum()),c=u.clone(),r?(h=r.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0)),h=h.div(h.norm()),a=r.mmul(h).div(h.transpose().mmul(h).get(0,0))):a=u;if(r){let e=t.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0));e=e.div(e.norm());let n=t.clone().sub(u.clone().mmul(e.transpose())),o=a.transpose().mmul(u).div(u.transpose().mmul(u).get(0,0)),s=r.clone().sub(u.clone().mulS(o.get(0,0)).mmul(h.transpose()));this.t=u,this.p=e.transpose(),this.w=l.transpose(),this.q=h,this.u=a,this.s=u.transpose().mmul(u),this.xResidual=n,this.yResidual=s,this.betas=o}else this.w=l.transpose(),this.s=u.transpose().mmul(u).sqrt(),this.t=o?u.clone().div(this.s.get(0,0)):u,this.xResidual=t.sub(u.mmul(l.transpose()))}}e.y3=b,e.jy=D,e.oN=D,e.Hc=A,e.cg=C,e.hj=C,e.LU=z,e.Tb=z,e.uq=S,e.Zm=class extends R{constructor(t,e){p(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}},e.Dq=class extends R{constructor(t,e){c(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}},e.__=class extends R{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}},e.q0=class extends R{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}},e.lh=class extends R{constructor(t,e){g(t,e),super(t,e.length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}},e.pI=class extends R{constructor(t,e){l(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}},e.zC=_,e.zg=class extends R{constructor(t,e,r,n,o){w(t,e,r,n,o),super(t,r-e+1,o-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}},e.g6=class extends R{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}},e.OL=q,e.ks=q,e.QR=O,e.jp=O,e.mk=T,e.W2=T,e.l=E,e.KY=N,e.dv=k,e.BR=function(t,e=t,r={}){t=new S(t);let o=!1;if("object"!=typeof e||S.isMatrix(e)||n.isAnyArray(e)?e=new S(e):(r=e,e=t,o=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:s=!0,scale:i=!0}=r;s&&(t.center("column"),o||e.center("column")),i&&(t.scale("column"),o||e.scale("column"));const a=t.standardDeviation("column",{unbiased:!0}),u=o?a:e.standardDeviation("column",{unbiased:!0}),h=t.transpose().mmul(e);for(let e=0;e<h.rows;e++)for(let r=0;r<h.columns;r++)h.set(e,r,h.get(e,r)*(1/(a[e]*u[r]))*(1/(t.rows-1)));return h},e.Wu=function(t,e=t,r={}){t=new S(t);let o=!1;if("object"!=typeof e||S.isMatrix(e)||n.isAnyArray(e)?e=new S(e):(r=e,e=t,o=!0),t.rows!==e.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:s=!0}=r;s&&(t=t.center("column"),o||(e=e.center("column")));const i=t.transpose().mmul(e);for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)*(1/(t.rows-1)));return i},e.a4=function t(e){if((e=S.checkMatrix(e)).isSquare()){if(0===e.columns)return 1;let r,n,o,s;if(2===e.columns)return r=e.get(0,0),n=e.get(0,1),o=e.get(1,0),s=e.get(1,1),r*s-n*o;if(3===e.columns){let s,i,a;return s=new _(e,[1,2],[1,2]),i=new _(e,[1,2],[0,2]),a=new _(e,[1,2],[0,1]),r=e.get(0,0),n=e.get(0,1),o=e.get(0,2),r*t(s)-n*t(i)+o*t(a)}return new z(e).determinant}throw Error("determinant can only be calculated for a square matrix")},e.DI=function(t,e=!1){return t=k.checkMatrix(t),e?new T(t).inverse():P(t,S.eye(t.rows))},e.Jo=function(t,e={}){const{thresholdValue:r=1e-9,thresholdError:n=1e-9}=e;let o=(t=S.checkMatrix(t)).rows,s=new S(o,o);for(let e=0;e<o;e++){let i=S.columnVector(t.getRow(e)),a=t.subMatrixRow(j(o,e)).transpose(),u=new T(a).solve(i),h=S.sub(i,a.mmul(u)).abs().max();s.setRow(e,W(h,u,e,r,n))}return s},e.Zi=function(t,e=Number.EPSILON){if((t=S.checkMatrix(t)).isEmpty())return t.transpose();let r=new T(t,{autoTranspose:!0}),n=r.leftSingularVectors,o=r.rightSingularVectors,s=r.diagonal;for(let t=0;t<s.length;t++)Math.abs(s[t])>e?s[t]=1/s[t]:s[t]=0;return o.mmul(S.diag(s).mmul(n.transpose()))},e.kH=P,e.LV=function(t,e){if(n.isAnyArray(t))return t[0]&&n.isAnyArray(t[0])?new k(t):new N(t,e);throw new Error("the argument is not an array")}},718(t,e,r){"use strict";r.r(e),r.d(e,{default:()=>o});var n=r(788);function o(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,n.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==r.output){if(!(0,n.isAnyArray)(r.output))throw new TypeError("output option must be an array if specified");e=r.output}else e=new Array(t.length);var o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,n.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,i=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=o||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 a=t[o],u=o+1;u<i;u++)t[u]<a&&(a=t[u]);return a}(t),s=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(0,n.isAnyArray)(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var r=e.fromIndex,o=void 0===r?0:r,s=e.toIndex,i=void 0===s?t.length:s;if(o<0||o>=t.length||!Number.isInteger(o))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=o||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 a=t[o],u=o+1;u<i;u++)t[u]>a&&(a=t[u]);return a}(t);if(o===s)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=r.min,a=void 0===i?r.autoMinMax?o:0:i,u=r.max,h=void 0===u?r.autoMinMax?s:1:u;if(a>=h)throw new RangeError("min option must be smaller than max option");for(var l=(h-a)/(s-o),c=0;c<t.length;c++)e[c]=(t[c]-o)*l+a;return e}},788(t,e,r){"use strict";r.r(e),r.d(e,{isAnyArray:()=>o});const n=Object.prototype.toString;function o(t){const e=n.call(t);return e.endsWith("Array]")&&!e.includes("Big")}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{"use strict";var t=n;Object.defineProperty(t,"__esModule",{value:!0}),t.UMAP=void 0;var e=r(329);Object.defineProperty(t,"UMAP",{enumerable:!0,get:function(){return e.UMAP}})})(),n})());
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elarsaks/umap-wasm",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JavaScript implementation of UMAP",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Andy Coenen",
|
|
7
|
+
"email": "andycoenen@google.com"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/elarsaks/umap-wasm.git"
|
|
13
|
+
},
|
|
14
|
+
"main": "lib/umap-js.js",
|
|
15
|
+
"module": "lib/umap-js.js",
|
|
16
|
+
"unpkg": "lib/umap-js.min.js",
|
|
17
|
+
"jsdelivr": "lib/umap-js.min.js",
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./lib/umap-js.js",
|
|
22
|
+
"require": "./lib/umap-js.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib",
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"packageManager": "yarn@4.12.0",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"bundle": "rm -rf lib && webpack --config ./webpack/lib.config.ts && webpack --config ./webpack/lib.min.config.ts",
|
|
34
|
+
"build": "rm -rf dist && tsc && yarn bundle",
|
|
35
|
+
"build:wasm": "cd wasm && wasm-pack build --target web --out-dir pkg"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/jest": "^30.0.0",
|
|
39
|
+
"@types/node": "^25.0.3",
|
|
40
|
+
"jest": "^30.2.0",
|
|
41
|
+
"prando": "^5.1.2",
|
|
42
|
+
"prettier": "^3.7.4",
|
|
43
|
+
"ts-jest": "^29.4.6",
|
|
44
|
+
"ts-loader": "^9.5.4",
|
|
45
|
+
"ts-node": "^10.9.2",
|
|
46
|
+
"typescript": "^5.9.3",
|
|
47
|
+
"vitest": "^1.4.0",
|
|
48
|
+
"webpack": "^5.104.1",
|
|
49
|
+
"webpack-cli": "^6.0.1"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"ml-levenberg-marquardt": "^2.1.1"
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public",
|
|
56
|
+
"registry": "https://registry.npmjs.org/"
|
|
57
|
+
}
|
|
58
|
+
}
|