w-cluster 1.0.13 → 1.0.14

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/README.md CHANGED
@@ -278,9 +278,9 @@ testCluster()
278
278
  ```alias
279
279
 
280
280
  <!-- for basic -->
281
- <script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.13/dist/w-cluster.umd.js"></script>
281
+ <script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.14/dist/w-cluster.umd.js"></script>
282
282
 
283
283
  <!-- for web workers -->
284
- <script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.13/dist/w-cluster.wk.umd.js"></script>
284
+ <script src="https://cdn.jsdelivr.net/npm/w-cluster@1.0.14/dist/w-cluster.wk.umd.js"></script>
285
285
 
286
286
  ```
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * w-cluster v1.0.13
2
+ * w-cluster v1.0.14
3
3
  * (c) 2018-2021 yuda-lyu(semisphere)
4
4
  * Released under the MIT License.
5
5
  */
6
- !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-cluster"]=r()}(this,(function(){"use strict";function t(t,r,e,n,o,i,s){try{var a=t[i](s),u=a.value}catch(t){return void e(t)}a.done?r(u):Promise.resolve(u).then(n,o)}function r(r){return function(){var e=this,n=arguments;return new Promise((function(o,i){var s=r.apply(e,n);function a(r){t(s,o,i,a,u,"next",r)}function u(r){t(s,o,i,a,u,"throw",r)}a(void 0)}))}}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){var r={exports:{}};return t(r,r.exports),r.exports}var s=i((function(t){var r=function(t){var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=r&&r.prototype instanceof d?r:d,i=Object.create(o.prototype),s=new A(n||[]);return i._invoke=function(t,r,e){var n=l;return function(o,i){if(n===m)throw new Error("Generator is already running");if(n===g){if("throw"===o)throw i;return C()}for(e.method=o,e.arg=i;;){var s=e.delegate;if(s){var a=_(s,e);if(a){if(a===p)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===l)throw n=g,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=m;var u=h(t,r,e);if("normal"===u.type){if(n=e.done?g:v,u.arg===p)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=g,e.method="throw",e.arg=u.arg)}}}(t,e,s),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var l="suspendedStart",v="suspendedYield",m="executing",g="completed",p={};function d(){}function w(){}function y(){}var b={};c(b,s,(function(){return this}));var M=Object.getPrototypeOf,x=M&&M(M(O([])));x&&x!==n&&o.call(x,s)&&(b=x);var k=y.prototype=d.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function n(i,s,a,u){var c=h(t[i],t,s);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"===e(l)&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var i;this._invoke=function(t,e){function o(){return new r((function(r,o){n(t,e,r,o)}))}return i=i?i.then(o,o):o()}}function _(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,_(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function j(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function R(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function O(t){if(t){var e=t[s];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:C}}function C(){return{value:r,done:!0}}return w.prototype=y,c(k,"constructor",y),c(y,"constructor",w),w.displayName=c(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,c(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},E(S.prototype),c(S.prototype,a,(function(){return this})),t.AsyncIterator=S,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var s=new S(f(r,e,n,o),i);return t.isGeneratorFunction(e)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},E(k),c(k,u,"Generator"),c(k,s,(function(){return this})),c(k,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(R),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return a.type="throw",a.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var u=o.call(s,"catchLoc"),c=o.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=r,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(s)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),p},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),R(e),p}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;R(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:O(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),p}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"===("undefined"==typeof globalThis?"undefined":e(globalThis))?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}})),a=s,u=Array.isArray,c="object"==e(n)&&n&&n.Object===Object&&n,f="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,h=c||f||Function("return this")(),l=h.Symbol,v=Object.prototype,m=v.hasOwnProperty,g=v.toString,p=l?l.toStringTag:void 0;var d=function(t){var r=m.call(t,p),e=t[p];try{t[p]=void 0;var n=!0}catch(t){}var o=g.call(t);return n&&(r?t[p]=e:delete t[p]),o},w=Object.prototype.toString;var y=function(t){return w.call(t)},b=l?l.toStringTag:void 0;var M=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":b&&b in Object(t)?d(t):y(t)};var x=function(t){return null!=t&&"object"==e(t)};var k=function(t){return"symbol"==e(t)||x(t)&&"[object Symbol]"==M(t)},E=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/;var _=function(t,r){if(u(t))return!1;var n=e(t);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!k(t))||(S.test(t)||!E.test(t)||null!=r&&t in Object(r))};var j=function(t){var r=e(t);return null!=t&&("object"==r||"function"==r)};var R,A=function(t){if(!j(t))return!1;var r=M(t);return"[object Function]"==r||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r},O=h["__core-js_shared__"],C=(R=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"";var I=function(t){return!!C&&C in t},N=Function.prototype.toString;var F=function(t){if(null!=t){try{return N.call(t)}catch(t){}try{return t+""}catch(t){}}return""},T=/^\[object .+?Constructor\]$/,P=Function.prototype,z=Object.prototype,L=P.toString,V=z.hasOwnProperty,q=RegExp("^"+L.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var D=function(t){return!(!j(t)||I(t))&&(A(t)?q:T).test(F(t))};var U=function(t,r){return null==t?void 0:t[r]};var B=function(t,r){var e=U(t,r);return D(e)?e:void 0},G=B(Object,"create");var $=function(){this.__data__=G?G(null):{},this.size=0};var K=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r},W=Object.prototype.hasOwnProperty;var X=function(t){var r=this.__data__;if(G){var e=r[t];return"__lodash_hash_undefined__"===e?void 0:e}return W.call(r,t)?r[t]:void 0},Y=Object.prototype.hasOwnProperty;var J=function(t){var r=this.__data__;return G?void 0!==r[t]:Y.call(r,t)};var Z=function(t,r){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=G&&void 0===r?"__lodash_hash_undefined__":r,this};function H(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}H.prototype.clear=$,H.prototype.delete=K,H.prototype.get=X,H.prototype.has=J,H.prototype.set=Z;var Q=H;var tt=function(){this.__data__=[],this.size=0};var rt=function(t,r){return t===r||t!=t&&r!=r};var et=function(t,r){for(var e=t.length;e--;)if(rt(t[e][0],r))return e;return-1},nt=Array.prototype.splice;var ot=function(t){var r=this.__data__,e=et(r,t);return!(e<0)&&(e==r.length-1?r.pop():nt.call(r,e,1),--this.size,!0)};var it=function(t){var r=this.__data__,e=et(r,t);return e<0?void 0:r[e][1]};var st=function(t){return et(this.__data__,t)>-1};var at=function(t,r){var e=this.__data__,n=et(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this};function ut(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}ut.prototype.clear=tt,ut.prototype.delete=ot,ut.prototype.get=it,ut.prototype.has=st,ut.prototype.set=at;var ct=ut,ft=B(h,"Map");var ht=function(){this.size=0,this.__data__={hash:new Q,map:new(ft||ct),string:new Q}};var lt=function(t){var r=e(t);return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t};var vt=function(t,r){var e=t.__data__;return lt(r)?e["string"==typeof r?"string":"hash"]:e.map};var mt=function(t){var r=vt(this,t).delete(t);return this.size-=r?1:0,r};var gt=function(t){return vt(this,t).get(t)};var pt=function(t){return vt(this,t).has(t)};var dt=function(t,r){var e=vt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this};function wt(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}wt.prototype.clear=ht,wt.prototype.delete=mt,wt.prototype.get=gt,wt.prototype.has=pt,wt.prototype.set=dt;var yt=wt;function bt(t,r){if("function"!=typeof t||null!=r&&"function"!=typeof r)throw new TypeError("Expected a function");var e=function e(){var n=arguments,o=r?r.apply(this,n):n[0],i=e.cache;if(i.has(o))return i.get(o);var s=t.apply(this,n);return e.cache=i.set(o,s)||i,s};return e.cache=new(bt.Cache||yt),e}bt.Cache=yt;var Mt=bt;var xt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,kt=/\\(\\)?/g,Et=function(t){var r=Mt(t,(function(t){return 500===e.size&&e.clear(),t})),e=r.cache;return r}((function(t){var r=[];return 46===t.charCodeAt(0)&&r.push(""),t.replace(xt,(function(t,e,n,o){r.push(n?o.replace(kt,"$1"):e||t)})),r}));var St=function(t,r){for(var e=-1,n=null==t?0:t.length,o=Array(n);++e<n;)o[e]=r(t[e],e,t);return o},_t=l?l.prototype:void 0,jt=_t?_t.toString:void 0;var Rt=function t(r){if("string"==typeof r)return r;if(u(r))return St(r,t)+"";if(k(r))return jt?jt.call(r):"";var e=r+"";return"0"==e&&1/r==-Infinity?"-0":e};var At=function(t){return null==t?"":Rt(t)};var Ot=function(t,r){return u(t)?t:_(t,r)?[t]:Et(At(t))};var Ct=function(t){if("string"==typeof t||k(t))return t;var r=t+"";return"0"==r&&1/t==-Infinity?"-0":r};var It=function(t,r){for(var e=0,n=(r=Ot(r,t)).length;null!=t&&e<n;)t=t[Ct(r[e++])];return e&&e==n?t:void 0};var Nt=function(t,r,e){var n=null==t?void 0:It(t,r);return void 0===n?e:n},Ft=Object.prototype;var Tt=function(t){var r=t&&t.constructor;return t===("function"==typeof r&&r.prototype||Ft)};var Pt=function(t,r){return function(e){return t(r(e))}}(Object.keys,Object),zt=Object.prototype.hasOwnProperty;var Lt=function(t){if(!Tt(t))return Pt(t);var r=[];for(var e in Object(t))zt.call(t,e)&&"constructor"!=e&&r.push(e);return r},Vt=B(h,"DataView"),qt=B(h,"Promise"),Dt=B(h,"Set"),Ut=B(h,"WeakMap"),Bt="[object Map]",Gt="[object Promise]",$t="[object Set]",Kt="[object WeakMap]",Wt="[object DataView]",Xt=F(Vt),Yt=F(ft),Jt=F(qt),Zt=F(Dt),Ht=F(Ut),Qt=M;(Vt&&Qt(new Vt(new ArrayBuffer(1)))!=Wt||ft&&Qt(new ft)!=Bt||qt&&Qt(qt.resolve())!=Gt||Dt&&Qt(new Dt)!=$t||Ut&&Qt(new Ut)!=Kt)&&(Qt=function(t){var r=M(t),e="[object Object]"==r?t.constructor:void 0,n=e?F(e):"";if(n)switch(n){case Xt:return Wt;case Yt:return Bt;case Jt:return Gt;case Zt:return $t;case Ht:return Kt}return r});var tr=Qt;var rr=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991};var er=function(t){return null!=t&&rr(t.length)&&!A(t)};var nr=function(t){return"string"==typeof t||!u(t)&&x(t)&&"[object String]"==M(t)};var or=function(t){return function(r){return null==r?void 0:r[t]}},ir=or("length"),sr=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var ar=function(t){return sr.test(t)},ur="[\\ud800-\\udfff]",cr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",fr="\\ud83c[\\udffb-\\udfff]",hr="[^\\ud800-\\udfff]",lr="(?:\\ud83c[\\udde6-\\uddff]){2}",vr="[\\ud800-\\udbff][\\udc00-\\udfff]",mr="(?:"+cr+"|"+fr+")"+"?",gr="[\\ufe0e\\ufe0f]?",pr=gr+mr+("(?:\\u200d(?:"+[hr,lr,vr].join("|")+")"+gr+mr+")*"),dr="(?:"+[hr+cr+"?",cr,lr,vr,ur].join("|")+")",wr=RegExp(fr+"(?="+fr+")|"+dr+pr,"g");var yr=function(t){for(var r=wr.lastIndex=0;wr.test(t);)++r;return r};var br=function(t){return ar(t)?yr(t):ir(t)};var Mr=function(t){if(null==t)return 0;if(er(t))return nr(t)?br(t):t.length;var r=tr(t);return"[object Map]"==r||"[object Set]"==r?t.size:Lt(t).length};function xr(t){return"[object Array]"===Object.prototype.toString.call(t)}function kr(t){return"[object Object]"===Object.prototype.toString.call(t)}function Er(t){return"[object String]"===Object.prototype.toString.call(t)}function Sr(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(kr(t)){for(var r in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Er(t)||""!==t)}(t)||!!function(t){return!!xr(t)&&0===t.length}(t))))}function _r(t){return!!xr(t)&&(0!==t.length&&(1!==t.length||!Sr(t[0])))}var jr=function(t){return!0===t||!1===t||x(t)&&"[object Boolean]"==M(t)};function Rr(t){return jr(t)}function Ar(t){return!(!Er(t)||""===t)}function Or(t){var r=!1;return Ar(t)?r=!isNaN(Number(t)):function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)&&(r=!0),r}var Cr=/\s/;var Ir=function(t){for(var r=t.length;r--&&Cr.test(t.charAt(r)););return r},Nr=/^\s+/;var Fr=function(t){return t?t.slice(0,Ir(t)+1).replace(Nr,""):t},Tr=/^[-+]0x[0-9a-f]+$/i,Pr=/^0b[01]+$/i,zr=/^0o[0-7]+$/i,Lr=parseInt;var Vr=function(t){if("number"==typeof t)return t;if(k(t))return NaN;if(j(t)){var r="function"==typeof t.valueOf?t.valueOf():t;t=j(r)?r+"":r}if("string"!=typeof t)return 0===t?t:+t;t=Fr(t);var e=Pr.test(t);return e||zr.test(t)?Lr(t.slice(2),e?2:8):Tr.test(t)?NaN:+t},qr=1/0;var Dr=function(t){return t?(t=Vr(t))===qr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ur=function(t){var r=Dr(t),e=r%1;return r==r?e?r-e:r:0},Br=h.isFinite,Gr=Math.min;var $r=function(t){var r=Math[t];return function(t,e){if(t=Vr(t),(e=null==e?0:Gr(Ur(e),292))&&Br(t)){var n=(At(t)+"e").split("e"),o=r(n[0]+"e"+(+n[1]+e));return+((n=(At(o)+"e").split("e"))[0]+"e"+(+n[1]-e))}return r(t)}}("round");function Kr(t){if(!Or(t))return 0;t=function(t){return Or(t)?Dr(t):0}(t);var r=$r(t);return"0"===String(r)?0:r}function Wr(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function Xr(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function Yr(t,r,e){return r&&Xr(t.prototype,r),e&&Xr(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function Jr(t,r){return Jr=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t},Jr(t,r)}function Zr(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&Jr(t,r)}function Hr(t,r){if(r&&("object"===e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function Qr(t){return Qr=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Qr(t)}var te=Object.prototype.toString;function re(t){return te.call(t).endsWith("Array]")}function ee(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!re(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function ne(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!re(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function oe(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!re(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==e.output){if(!re(e.output))throw new TypeError("output option must be an array if specified");r=e.output}else r=new Array(t.length);var n=ne(t),o=ee(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=e.min,s=void 0===i?e.autoMinMax?n:0:i,a=e.max,u=void 0===a?e.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var c=(u-s)/(o-n),f=0;f<t.length;f++)r[f]=(t[f]-n)*c+s;return r}var ie=" ".repeat(2),se=" ".repeat(4);function ae(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.maxRows,n=void 0===e?15:e,o=r.maxColumns,i=void 0===o?10:o,s=r.maxNumSize,a=void 0===s?8:s;return"".concat(t.constructor.name," {\n").concat(ie,"[\n").concat(se).concat(ue(t,n,i,a),"\n").concat(ie,"]\n").concat(ie,"rows: ").concat(t.rows,"\n").concat(ie,"columns: ").concat(t.columns,"\n}")}function ue(t,r,e,n){for(var o=t.rows,i=t.columns,s=Math.min(o,r),a=Math.min(i,e),u=[],c=0;c<s;c++){for(var f=[],h=0;h<a;h++)f.push(ce(t.get(c,h),n));u.push("".concat(f.join(" ")))}return a!==i&&(u[u.length-1]+=" ... ".concat(i-e," more columns")),s!==o&&u.push("... ".concat(o-r," more rows")),u.join("\n".concat(se))}function ce(t,r){var e=String(t);if(e.length<=r)return e.padEnd(r," ");var n=t.toPrecision(r-2);if(n.length<=r)return n;var o=t.toExponential(r-2),i=o.indexOf("e"),s=o.slice(i);return o.slice(0,r-s.length)+s}function fe(t,r,e){var n=e?t.rows:t.rows-1;if(r<0||r>n)throw new RangeError("Row index out of range")}function he(t,r,e){var n=e?t.columns:t.columns-1;if(r<0||r>n)throw new RangeError("Column index out of range")}function le(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return r}function ve(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return r}function me(t,r,e,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(pe("startRow",r),pe("endRow",e),pe("startColumn",n),pe("endColumn",o),r>e||n>o||r<0||r>=t.rows||e<0||e>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function ge(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=[],n=0;n<t;n++)e.push(r);return e}function pe(t,r){if("number"!=typeof r)throw new TypeError("".concat(t," must be a number"))}function de(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}function we(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<n;s++){for(var a=0,u=0,c=0,f=0;f<o;f++)a+=c=t.get(s,f)-e[s],u+=c*c;r?i.push((u-a*a/o)/(o-1)):i.push((u-a*a/o)/o)}return i}function ye(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<o;s++){for(var a=0,u=0,c=0,f=0;f<n;f++)a+=c=t.get(f,s)-e[s],u+=c*c;r?i.push((u-a*a/n)/(n-1)):i.push((u-a*a/n)/n)}return i}function be(t,r,e){for(var n=t.rows,o=t.columns,i=n*o,s=0,a=0,u=0,c=0;c<n;c++)for(var f=0;f<o;f++)s+=u=t.get(c,f)-e,a+=u*u;return r?(a-s*s/i)/(i-1):(a-s*s/i)/i}function Me(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[e])}function xe(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[n])}function ke(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r)}function Ee(t){for(var r=[],e=0;e<t.rows;e++){for(var n=0,o=0;o<t.columns;o++)n+=Math.pow(t.get(e,o),2)/(t.columns-1);r.push(Math.sqrt(n))}return r}function Se(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[e])}function _e(t){for(var r=[],e=0;e<t.columns;e++){for(var n=0,o=0;o<t.rows;o++)n+=Math.pow(t.get(o,e),2)/(t.rows-1);r.push(Math.sqrt(n))}return r}function je(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[n])}function Re(t){for(var r=t.size-1,e=0,n=0;n<t.columns;n++)for(var o=0;o<t.rows;o++)e+=Math.pow(t.get(o,n),2)/r;return Math.sqrt(e)}function Ae(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r)}function Oe(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}var Ce=function(){function t(){Wr(this,t)}return Yr(t,[{key:"size",get:function(){return this.rows*this.columns}},{key:"apply",value:function(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.call(this,r,e);return this}},{key:"to1DArray",value:function(){for(var t=[],r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.push(this.get(r,e));return t}},{key:"to2DArray",value:function(){for(var t=[],r=0;r<this.rows;r++){t.push([]);for(var e=0;e<this.columns;e++)t[r].push(this.get(r,e))}return t}},{key:"toJSON",value:function(){return this.to2DArray()}},{key:"isRowVector",value:function(){return 1===this.rows}},{key:"isColumnVector",value:function(){return 1===this.columns}},{key:"isVector",value:function(){return 1===this.rows||1===this.columns}},{key:"isSquare",value:function(){return this.rows===this.columns}},{key:"isEmpty",value:function(){return 0===this.rows||0===this.columns}},{key:"isSymmetric",value:function(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var r=0;r<=t;r++)if(this.get(t,r)!==this.get(r,t))return!1;return!0}return!1}},{key:"isEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);t++}return n}},{key:"isReducedEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);for(var i=r+1;i<this.rows;i++)0!==this.get(t,i)&&(n=!1);t++}return n}},{key:"echelonForm",value:function(){for(var t=this.clone(),r=0,e=0;r<t.rows&&e<t.columns;){for(var n=r,o=r;o<t.rows;o++)t.get(o,e)>t.get(n,e)&&(n=o);if(0===t.get(n,e))e++;else{t.swapRows(r,n);for(var i=t.get(r,e),s=e;s<t.columns;s++)t.set(r,s,t.get(r,s)/i);for(var a=r+1;a<t.rows;a++){var u=t.get(a,e)/t.get(r,e);t.set(a,e,0);for(var c=e+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(r,c)*u)}r++,e++}}return t}},{key:"reducedEchelonForm",value:function(){for(var t=this.echelonForm(),r=t.columns,e=t.rows,n=e-1;n>=0;)if(0===t.maxRow(n))n--;else{for(var o=0,i=!1;o<e&&!1===i;)1===t.get(n,o)?i=!0:o++;for(var s=0;s<n;s++)for(var a=t.get(s,o),u=o;u<r;u++){var c=t.get(s,u)-a*t.get(n,u);t.set(s,u,c)}n--}return t}},{key:"set",value:function(){throw new Error("set method is unimplemented")}},{key:"get",value:function(){throw new Error("get method is unimplemented")}},{key:"repeat",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.rows,n=void 0===r?1:r,o=t.columns,i=void 0===o?1:o;if(!Number.isInteger(n)||n<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(i)||i<=0)throw new TypeError("columns must be a positive integer");for(var s=new Ne(this.rows*n,this.columns*i),a=0;a<n;a++)for(var u=0;u<i;u++)s.setSubMatrix(this,this.rows*a,this.columns*u);return s}},{key:"fill",value:function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,t);return this}},{key:"neg",value:function(){return this.mulS(-1)}},{key:"getRow",value:function(t){fe(this,t);for(var r=[],e=0;e<this.columns;e++)r.push(this.get(t,e));return r}},{key:"getRowVector",value:function(t){return Ne.rowVector(this.getRow(t))}},{key:"setRow",value:function(t,r){fe(this,t),r=le(this,r);for(var e=0;e<this.columns;e++)this.set(t,e,r[e]);return this}},{key:"swapRows",value:function(t,r){fe(this,t),fe(this,r);for(var e=0;e<this.columns;e++){var n=this.get(t,e);this.set(t,e,this.get(r,e)),this.set(r,e,n)}return this}},{key:"getColumn",value:function(t){he(this,t);for(var r=[],e=0;e<this.rows;e++)r.push(this.get(e,t));return r}},{key:"getColumnVector",value:function(t){return Ne.columnVector(this.getColumn(t))}},{key:"setColumn",value:function(t,r){he(this,t),r=ve(this,r);for(var e=0;e<this.rows;e++)this.set(e,t,r[e]);return this}},{key:"swapColumns",value:function(t,r){he(this,t),he(this,r);for(var e=0;e<this.rows;e++){var n=this.get(e,t);this.set(e,t,this.get(e,r)),this.set(e,r,n)}return this}},{key:"addRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[e]);return this}},{key:"subRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[e]);return this}},{key:"mulRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[e]);return this}},{key:"divRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[e]);return this}},{key:"addColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[r]);return this}},{key:"subColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[r]);return this}},{key:"mulColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[r]);return this}},{key:"divColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[r]);return this}},{key:"mulRow",value:function(t,r){fe(this,t);for(var e=0;e<this.columns;e++)this.set(t,e,this.get(t,e)*r);return this}},{key:"mulColumn",value:function(t,r){he(this,t);for(var e=0;e<this.rows;e++)this.set(e,t,this.get(e,t)*r);return this}},{key:"max",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)>t&&(t=this.get(r,e));return t}},{key:"maxIndex",value:function(){de(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"min",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)<t&&(t=this.get(r,e));return t}},{key:"minIndex",value:function(){de(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"maxRow",value:function(t){if(fe(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)>r&&(r=this.get(t,e));return r}},{key:"maxRowIndex",value:function(t){fe(this,t),de(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)>r&&(r=this.get(t,n),e[1]=n);return e}},{key:"minRow",value:function(t){if(fe(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)<r&&(r=this.get(t,e));return r}},{key:"minRowIndex",value:function(t){fe(this,t),de(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)<r&&(r=this.get(t,n),e[1]=n);return e}},{key:"maxColumn",value:function(t){if(he(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)>r&&(r=this.get(e,t));return r}},{key:"maxColumnIndex",value:function(t){he(this,t),de(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)>r&&(r=this.get(n,t),e[0]=n);return e}},{key:"minColumn",value:function(t){if(he(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)<r&&(r=this.get(e,t));return r}},{key:"minColumnIndex",value:function(t){he(this,t),de(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)<r&&(r=this.get(n,t),e[0]=n);return e}},{key:"diag",value:function(){for(var t=Math.min(this.rows,this.columns),r=[],e=0;e<t;e++)r.push(this.get(e,e));return r}},{key:"norm",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"frobenius",r=0;if("max"===t)return this.max();if("frobenius"===t){for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)r+=this.get(e,n)*this.get(e,n);return Math.sqrt(r)}throw new RangeError("unknown norm type: ".concat(t))}},{key:"cumulativeSum",value:function(){for(var t=0,r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t+=this.get(r,e),this.set(r,e,t);return this}},{key:"dot",value:function(r){t.isMatrix(r)&&(r=r.to1DArray());var e=this.to1DArray();if(e.length!==r.length)throw new RangeError("vectors do not have the same size");for(var n=0,o=0;o<e.length;o++)n+=e[o]*r[o];return n}},{key:"mmul",value:function(t){t=Ne.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.columns,o=new Ne(r,n),i=new Float64Array(e),s=0;s<n;s++){for(var a=0;a<e;a++)i[a]=t.get(a,s);for(var u=0;u<r;u++){for(var c=0,f=0;f<e;f++)c+=this.get(u,f)*i[f];o.set(u,s,c)}}return o}},{key:"strassen2x2",value:function(t){t=Ne.checkMatrix(t);var r=new Ne(2,2),e=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),c=t.get(1,1),f=(e+u)*(n+c),h=(s+u)*n,l=e*(i-c),v=u*(a-n),m=(e+o)*c,g=f+v-m+(o-u)*(a+c),p=l+m,d=h+v,w=f-h+l+(s-e)*(n+i);return r.set(0,0,g),r.set(0,1,p),r.set(1,0,d),r.set(1,1,w),r}},{key:"strassen3x3",value:function(t){t=Ne.checkMatrix(t);var r=new Ne(3,3),e=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),c=this.get(2,1),f=this.get(2,2),h=t.get(0,0),l=t.get(0,1),v=t.get(0,2),m=t.get(1,0),g=t.get(1,1),p=t.get(1,2),d=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(e-i)*(-l+g),M=(-e+i+s)*(h-l+g),x=(i+s)*(-h+l),k=e*h,E=(-e+u+c)*(h-v+p),S=(-e+u)*(v-p),_=(u+c)*(-h+v),j=(-o+c+f)*(g+d-w),R=(o-f)*(g-w),A=o*d,O=(c+f)*(-d+w),C=(-o+s+a)*(p+d-y),I=(o-a)*(p-y),N=(s+a)*(-d+y),F=k+A+n*m,T=(e+n+o-i-s-c-f)*g+M+x+k+j+A+O,P=k+E+_+(e+n+o-s-a-u-c)*p+A+C+N,z=b+s*(-h+l+m-g-p-d+y)+M+k+A+C+I,L=b+M+x+k+a*w,V=A+C+I+N+i*v,q=k+E+S+c*(-h+v+m-g-p-d+w)+j+R+A,D=j+R+A+O+u*l,U=k+E+S+_+f*y;return r.set(0,0,F),r.set(0,1,T),r.set(0,2,P),r.set(1,0,z),r.set(1,1,L),r.set(1,2,V),r.set(2,0,q),r.set(2,1,D),r.set(2,2,U),r}},{key:"mmulStrassen",value:function(r){r=Ne.checkMatrix(r);var e=this.clone(),n=e.rows,o=e.columns,i=r.rows,s=r.columns;function a(r,e,n){var o=r.rows,i=r.columns;if(o===e&&i===n)return r;var s=t.zeros(e,n);return s=s.setSubMatrix(r,0,0)}o!==i&&console.warn("Multiplying ".concat(n," x ").concat(o," and ").concat(i," x ").concat(s," matrix: dimensions do not match."));var u=Math.max(n,i),c=Math.max(o,s);return function r(e,n,o,i){if(o<=512||i<=512)return e.mmul(n);o%2==1&&i%2==1?(e=a(e,o+1,i+1),n=a(n,o+1,i+1)):o%2==1?(e=a(e,o+1,i),n=a(n,o+1,i)):i%2==1&&(e=a(e,o,i+1),n=a(n,o,i+1));var s=parseInt(e.rows/2,10),u=parseInt(e.columns/2,10),c=e.subMatrix(0,s-1,0,u-1),f=n.subMatrix(0,s-1,0,u-1),h=e.subMatrix(0,s-1,u,e.columns-1),l=n.subMatrix(0,s-1,u,n.columns-1),v=e.subMatrix(s,e.rows-1,0,u-1),m=n.subMatrix(s,n.rows-1,0,u-1),g=e.subMatrix(s,e.rows-1,u,e.columns-1),p=n.subMatrix(s,n.rows-1,u,n.columns-1),d=r(t.add(c,g),t.add(f,p),s,u),w=r(t.add(v,g),f,s,u),y=r(c,t.sub(l,p),s,u),b=r(g,t.sub(m,f),s,u),M=r(t.add(c,h),p,s,u),x=r(t.sub(v,c),t.add(f,l),s,u),k=r(t.sub(h,g),t.add(m,p),s,u),E=t.add(d,b);E.sub(M),E.add(k);var S=t.add(y,M),_=t.add(w,b),j=t.sub(d,w);j.add(y),j.add(x);var R=t.zeros(2*E.rows,2*E.columns);return(R=(R=(R=(R=R.setSubMatrix(E,0,0)).setSubMatrix(S,E.rows,0)).setSubMatrix(_,0,E.columns)).setSubMatrix(j,E.rows,E.columns)).subMatrix(0,o-1,0,i-1)}(e=a(e,u,c),r=a(r,u,c),u,c)}},{key:"scaleRows",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new Ne(this.rows,this.columns),a=0;a<this.rows;a++){var u=this.getRow(a);u.length>0&&oe(u,{min:n,max:i,output:u}),s.setRow(a,u)}return s}},{key:"scaleColumns",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new Ne(this.rows,this.columns),a=0;a<this.columns;a++){var u=this.getColumn(a);u.length&&oe(u,{min:n,max:i,output:u}),s.setColumn(a,u)}return s}},{key:"flipRows",value:function(){for(var t=Math.ceil(this.columns/2),r=0;r<this.rows;r++)for(var e=0;e<t;e++){var n=this.get(r,e),o=this.get(r,this.columns-1-e);this.set(r,e,o),this.set(r,this.columns-1-e,n)}return this}},{key:"flipColumns",value:function(){for(var t=Math.ceil(this.rows/2),r=0;r<this.columns;r++)for(var e=0;e<t;e++){var n=this.get(e,r),o=this.get(this.rows-1-e,r);this.set(e,r,o),this.set(this.rows-1-e,r,n)}return this}},{key:"kroneckerProduct",value:function(t){t=Ne.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.rows,o=t.columns,i=new Ne(r*n,e*o),s=0;s<r;s++)for(var a=0;a<e;a++)for(var u=0;u<n;u++)for(var c=0;c<o;c++)i.set(n*s+u,o*a+c,this.get(s,a)*t.get(u,c));return i}},{key:"kroneckerSum",value:function(t){if(t=Ne.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");var r=this.rows,e=t.rows,n=this.kroneckerProduct(Ne.eye(e,e)),o=Ne.eye(r,r).kroneckerProduct(t);return n.add(o)}},{key:"transpose",value:function(){for(var t=new Ne(this.columns,this.rows),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(e,r,this.get(r,e));return t}},{key:"sortRows",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ie,r=0;r<this.rows;r++)this.setRow(r,this.getRow(r).sort(t));return this}},{key:"sortColumns",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ie,r=0;r<this.columns;r++)this.setColumn(r,this.getColumn(r).sort(t));return this}},{key:"subMatrix",value:function(t,r,e,n){me(this,t,r,e,n);for(var o=new Ne(r-t+1,n-e+1),i=t;i<=r;i++)for(var s=e;s<=n;s++)o.set(i-t,s-e,this.get(i,s));return o}},{key:"subMatrixRow",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.columns-1),r>e||r<0||r>=this.columns||e<0||e>=this.columns)throw new RangeError("Argument out of range");for(var n=new Ne(t.length,e-r+1),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError("Row index out of range: ".concat(t[o]));n.set(o,i-r,this.get(t[o],i))}return n}},{key:"subMatrixColumn",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.rows-1),r>e||r<0||r>=this.rows||e<0||e>=this.rows)throw new RangeError("Argument out of range");for(var n=new Ne(e-r+1,t.length),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError("Column index out of range: ".concat(t[o]));n.set(i-r,o,this.get(i,t[o]))}return n}},{key:"setSubMatrix",value:function(t,r,e){if((t=Ne.checkMatrix(t)).isEmpty())return this;me(this,r,r+t.rows-1,e,e+t.columns-1);for(var n=0;n<t.rows;n++)for(var o=0;o<t.columns;o++)this.set(r+n,e+o,t.get(n,o));return this}},{key:"selection",value:function(t,r){!function(t,r){if(!re(r))throw new TypeError("row indices must be an array");for(var e=0;e<r.length;e++)if(r[e]<0||r[e]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,r){if(!re(r))throw new TypeError("column indices must be an array");for(var e=0;e<r.length;e++)if(r[e]<0||r[e]>=t.columns)throw new RangeError("column indices are out of range")}(this,r);for(var e=new Ne(t.length,r.length),n=0;n<t.length;n++)for(var o=t[n],i=0;i<r.length;i++){var s=r[i];e.set(n,i,this.get(o,s))}return e}},{key:"trace",value:function(){for(var t=Math.min(this.rows,this.columns),r=0,e=0;e<t;e++)r+=this.get(e,e);return r}},{key:"clone",value:function(){for(var t=new Ne(this.rows,this.columns),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(r,e,this.get(r,e));return t}},{key:"sum",value:function(t){switch(t){case"row":return function(t){for(var r=ge(t.rows),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]+=t.get(e,n);return r}(this);case"column":return function(t){for(var r=ge(t.columns),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]+=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=0,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r+=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"product",value:function(t){switch(t){case"row":return function(t){for(var r=ge(t.rows,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]*=t.get(e,n);return r}(this);case"column":return function(t){for(var r=ge(t.columns,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]*=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=1,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r*=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"mean",value:function(t){var r=this.sum(t);switch(t){case"row":for(var e=0;e<this.rows;e++)r[e]/=this.columns;return r;case"column":for(var n=0;n<this.columns;n++)r[n]/=this.rows;return r;case void 0:return r/this.size;default:throw new Error("invalid option: ".concat(t))}}},{key:"variance",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.unbiased,i=void 0===o||o,s=n.mean,a=void 0===s?this.mean(t):s;if("boolean"!=typeof i)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!re(a))throw new TypeError("mean must be an array");return we(this,i,a);case"column":if(!re(a))throw new TypeError("mean must be an array");return ye(this,i,a);case void 0:if("number"!=typeof a)throw new TypeError("mean must be a number");return be(this,i,a);default:throw new Error("invalid option: ".concat(t))}}},{key:"standardDeviation",value:function(t,r){"object"===e(t)&&(r=t,t=void 0);var n=this.variance(t,r);if(void 0===t)return Math.sqrt(n);for(var o=0;o<n.length;o++)n[o]=Math.sqrt(n[o]);return n}},{key:"center",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.center,i=void 0===o?this.mean(t):o;switch(t){case"row":if(!re(i))throw new TypeError("center must be an array");return Me(this,i),this;case"column":if(!re(i))throw new TypeError("center must be an array");return xe(this,i),this;case void 0:if("number"!=typeof i)throw new TypeError("center must be a number");return ke(this,i),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"scale",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r.scale;switch(t){case"row":if(void 0===n)n=Ee(this);else if(!re(n))throw new TypeError("scale must be an array");return Se(this,n),this;case"column":if(void 0===n)n=_e(this);else if(!re(n))throw new TypeError("scale must be an array");return je(this,n),this;case void 0:if(void 0===n)n=Re(this);else if("number"!=typeof n)throw new TypeError("scale must be a number");return Ae(this,n),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"toString",value:function(t){return ae(this,t)}}],[{key:"from1DArray",value:function(t,r,e){if(t*r!==e.length)throw new RangeError("data length does not match given dimensions");for(var n=new Ne(t,r),o=0;o<t;o++)for(var i=0;i<r;i++)n.set(o,i,e[o*r+i]);return n}},{key:"rowVector",value:function(t){for(var r=new Ne(1,t.length),e=0;e<t.length;e++)r.set(0,e,t[e]);return r}},{key:"columnVector",value:function(t){for(var r=new Ne(t.length,1),e=0;e<t.length;e++)r.set(e,0,t[e]);return r}},{key:"zeros",value:function(t,r){return new Ne(t,r)}},{key:"ones",value:function(t,r){return new Ne(t,r).fill(1)}},{key:"rand",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");for(var o=n.random,i=void 0===o?Math.random:o,s=new Ne(t,r),a=0;a<t;a++)for(var u=0;u<r;u++)s.set(a,u,i());return s}},{key:"randInt",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");var o=n.min,i=void 0===o?0:o,s=n.max,a=void 0===s?1e3:s,u=n.random,c=void 0===u?Math.random:u;if(!Number.isInteger(i))throw new TypeError("min must be an integer");if(!Number.isInteger(a))throw new TypeError("max must be an integer");if(i>=a)throw new RangeError("min must be smaller than max");for(var f=a-i,h=new Ne(t,r),l=0;l<t;l++)for(var v=0;v<r;v++){var m=i+Math.round(c()*f);h.set(l,v,m)}return h}},{key:"eye",value:function(t,r,e){void 0===r&&(r=t),void 0===e&&(e=1);for(var n=Math.min(t,r),o=this.zeros(t,r),i=0;i<n;i++)o.set(i,i,e);return o}},{key:"diag",value:function(t,r,e){var n=t.length;void 0===r&&(r=n),void 0===e&&(e=r);for(var o=Math.min(n,r,e),i=this.zeros(r,e),s=0;s<o;s++)i.set(s,s,t[s]);return i}},{key:"min",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new Ne(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.min(t.get(i,s),r.get(i,s)));return o}},{key:"max",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new this(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.max(t.get(i,s),r.get(i,s)));return o}},{key:"checkMatrix",value:function(r){return t.isMatrix(r)?r:new Ne(r)}},{key:"isMatrix",value:function(t){return null!=t&&"Matrix"===t.klass}}]),t}();function Ie(t,r){return t-r}Ce.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Ce.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return ae(this)}),Ce.random=Ce.rand,Ce.randomInt=Ce.randInt,Ce.diagonal=Ce.diag,Ce.prototype.diagonal=Ce.prototype.diag,Ce.identity=Ce.eye,Ce.prototype.negate=Ce.prototype.neg,Ce.prototype.tensorProduct=Ce.prototype.kroneckerProduct;var Ne=function(t){Zr(e,t);var r=Oe(e);function e(t,n){var o;if(Wr(this,e),o=r.call(this),e.isMatrix(t))return Hr(o,t.clone());if(Number.isInteger(t)&&t>=0){if(o.data=[],!(Number.isInteger(n)&&n>=0))throw new TypeError("nColumns must be a positive integer");for(var i=0;i<t;i++)o.data.push(new Float64Array(n))}else{if(!re(t))throw new TypeError("First argument must be a positive number or an array");var s=t;if("number"!=typeof(n=(t=s.length)?s[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");o.data=[];for(var a=0;a<t;a++){if(s[a].length!==n)throw new RangeError("Inconsistent array dimensions");o.data.push(Float64Array.from(s[a]))}}return o.rows=t,o.columns=n,o}return Yr(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}},{key:"removeRow",value:function(t){return fe(this,t),this.data.splice(t,1),this.rows-=1,this}},{key:"addRow",value:function(t,r){return void 0===r&&(r=t,t=this.rows),fe(this,t,!0),r=Float64Array.from(le(this,r)),this.data.splice(t,0,r),this.rows+=1,this}},{key:"removeColumn",value:function(t){he(this,t);for(var r=0;r<this.rows;r++){for(var e=new Float64Array(this.columns-1),n=0;n<t;n++)e[n]=this.data[r][n];for(var o=t+1;o<this.columns;o++)e[o-1]=this.data[r][o];this.data[r]=e}return this.columns-=1,this}},{key:"addColumn",value:function(t,r){void 0===r&&(r=t,t=this.columns),he(this,t,!0),r=ve(this,r);for(var e=0;e<this.rows;e++){for(var n=new Float64Array(this.columns+1),o=0;o<t;o++)n[o]=this.data[e][o];for(n[o++]=r[e];o<this.columns+1;o++)n[o]=this.data[e][o-1];this.data[e]=n}return this.columns+=1,this}}]),e}(Ce);function Fe(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}function Te(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}!function(t,r){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t);return this},t.prototype.addM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)+t.get(e,n));return this},t.add=function(t,e){return new r(t).add(e)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t);return this},t.prototype.subM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)-t.get(e,n));return this},t.sub=function(t,e){return new r(t).sub(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t);return this},t.prototype.mulM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)*t.get(e,n));return this},t.mul=function(t,e){return new r(t).mul(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t);return this},t.prototype.divM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)/t.get(e,n));return this},t.div=function(t,e){return new r(t).div(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)%t);return this},t.prototype.modM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)%t.get(e,n));return this},t.mod=function(t,e){return new r(t).mod(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)&t);return this},t.prototype.andM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)&t.get(e,n));return this},t.and=function(t,e){return new r(t).and(e)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)|t);return this},t.prototype.orM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)|t.get(e,n));return this},t.or=function(t,e){return new r(t).or(e)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)^t);return this},t.prototype.xorM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)^t.get(e,n));return this},t.xor=function(t,e){return new r(t).xor(e)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)<<t);return this},t.prototype.leftShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)<<t.get(e,n));return this},t.leftShift=function(t,e){return new r(t).leftShift(e)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>t.get(e,n));return this},t.signPropagatingRightShift=function(t,e){return new r(t).signPropagatingRightShift(e)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>>t.get(e,n));return this},t.rightShift=function(t,e){return new r(t).rightShift(e)},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(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,~this.get(t,r));return this},t.not=function(t){return new r(t).not()},t.prototype.abs=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.abs(this.get(t,r)));return this},t.abs=function(t){return new r(t).abs()},t.prototype.acos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acos(this.get(t,r)));return this},t.acos=function(t){return new r(t).acos()},t.prototype.acosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acosh(this.get(t,r)));return this},t.acosh=function(t){return new r(t).acosh()},t.prototype.asin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asin(this.get(t,r)));return this},t.asin=function(t){return new r(t).asin()},t.prototype.asinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asinh(this.get(t,r)));return this},t.asinh=function(t){return new r(t).asinh()},t.prototype.atan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atan(this.get(t,r)));return this},t.atan=function(t){return new r(t).atan()},t.prototype.atanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atanh(this.get(t,r)));return this},t.atanh=function(t){return new r(t).atanh()},t.prototype.cbrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cbrt(this.get(t,r)));return this},t.cbrt=function(t){return new r(t).cbrt()},t.prototype.ceil=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.ceil(this.get(t,r)));return this},t.ceil=function(t){return new r(t).ceil()},t.prototype.clz32=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.clz32(this.get(t,r)));return this},t.clz32=function(t){return new r(t).clz32()},t.prototype.cos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cos(this.get(t,r)));return this},t.cos=function(t){return new r(t).cos()},t.prototype.cosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cosh(this.get(t,r)));return this},t.cosh=function(t){return new r(t).cosh()},t.prototype.exp=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.exp(this.get(t,r)));return this},t.exp=function(t){return new r(t).exp()},t.prototype.expm1=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.expm1(this.get(t,r)));return this},t.expm1=function(t){return new r(t).expm1()},t.prototype.floor=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.floor(this.get(t,r)));return this},t.floor=function(t){return new r(t).floor()},t.prototype.fround=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.fround(this.get(t,r)));return this},t.fround=function(t){return new r(t).fround()},t.prototype.log=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log(this.get(t,r)));return this},t.log=function(t){return new r(t).log()},t.prototype.log1p=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log1p(this.get(t,r)));return this},t.log1p=function(t){return new r(t).log1p()},t.prototype.log10=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log10(this.get(t,r)));return this},t.log10=function(t){return new r(t).log10()},t.prototype.log2=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log2(this.get(t,r)));return this},t.log2=function(t){return new r(t).log2()},t.prototype.round=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.round(this.get(t,r)));return this},t.round=function(t){return new r(t).round()},t.prototype.sign=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sign(this.get(t,r)));return this},t.sign=function(t){return new r(t).sign()},t.prototype.sin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sin(this.get(t,r)));return this},t.sin=function(t){return new r(t).sin()},t.prototype.sinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sinh(this.get(t,r)));return this},t.sinh=function(t){return new r(t).sinh()},t.prototype.sqrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sqrt(this.get(t,r)));return this},t.sqrt=function(t){return new r(t).sqrt()},t.prototype.tan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tan(this.get(t,r)));return this},t.tan=function(t){return new r(t).tan()},t.prototype.tanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tanh(this.get(t,r)));return this},t.tanh=function(t){return new r(t).tanh()},t.prototype.trunc=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.trunc(this.get(t,r)));return this},t.trunc=function(t){return new r(t).trunc()},t.pow=function(t,e){return new r(t).pow(e)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,Math.pow(this.get(r,e),t));return this},t.prototype.powM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,Math.pow(this.get(e,n),t.get(e,n)));return this}}(Ce,Ne);var Pe=function(t){Zr(e,t);var r=Te(e);function e(t){return Wr(this,e),r.call(this,t,t.columns,t.rows)}return Yr(e,[{key:"set",value:function(t,r,e){return this.matrix.set(r,t,e),this}},{key:"get",value:function(t,r){return this.matrix.get(r,t)}}]),e}(function(t){Zr(e,t);var r=Fe(e);function e(t,n,o){var i;return Wr(this,e),(i=r.call(this)).matrix=t,i.rows=n,i.columns=o,i}return Yr(e)}(Ce));function ze(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}var Le=function(t){Zr(e,t);var r=ze(e);function e(t){var n;return Wr(this,e),(n=r.call(this)).data=t,n.rows=t.length,n.columns=t[0].length,n}return Yr(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}}]),e}(Ce);function Ve(t,r){var e=0;return Math.abs(t)>Math.abs(r)?(e=r/t,Math.abs(t)*Math.sqrt(1+e*e)):0!==r?(e=t/r,Math.abs(r)*Math.sqrt(1+e*e)):0}var qe=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Wr(this,t),(r=Le.checkMatrix(r)).isEmpty())throw new Error("Matrix must be non-empty");var n,o=r.rows,i=r.columns,s=e.computeLeftSingularVectors,a=void 0===s||s,u=e.computeRightSingularVectors,c=void 0===u||u,f=e.autoTranspose,h=void 0!==f&&f,l=Boolean(a),v=Boolean(c),m=!1;if(o<i)if(h){o=(n=r.transpose()).rows,i=n.columns,m=!0;var g=l;l=v,v=g}else n=r.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else n=r.clone();for(var p=Math.min(o,i),d=Math.min(o+1,i),w=new Float64Array(d),y=new Ne(o,p),b=new Ne(i,i),M=new Float64Array(i),x=new Float64Array(o),k=new Float64Array(d),E=0;E<d;E++)k[E]=E;for(var S=Math.min(o-1,i),_=Math.max(0,Math.min(i-2,o)),j=Math.max(S,_),R=0;R<j;R++){if(R<S){w[R]=0;for(var A=R;A<o;A++)w[R]=Ve(w[R],n.get(A,R));if(0!==w[R]){n.get(R,R)<0&&(w[R]=-w[R]);for(var O=R;O<o;O++)n.set(O,R,n.get(O,R)/w[R]);n.set(R,R,n.get(R,R)+1)}w[R]=-w[R]}for(var C=R+1;C<i;C++){if(R<S&&0!==w[R]){for(var I=0,N=R;N<o;N++)I+=n.get(N,R)*n.get(N,C);I=-I/n.get(R,R);for(var F=R;F<o;F++)n.set(F,C,n.get(F,C)+I*n.get(F,R))}M[C]=n.get(R,C)}if(l&&R<S)for(var T=R;T<o;T++)y.set(T,R,n.get(T,R));if(R<_){M[R]=0;for(var P=R+1;P<i;P++)M[R]=Ve(M[R],M[P]);if(0!==M[R]){M[R+1]<0&&(M[R]=0-M[R]);for(var z=R+1;z<i;z++)M[z]/=M[R];M[R+1]+=1}if(M[R]=-M[R],R+1<o&&0!==M[R]){for(var L=R+1;L<o;L++)x[L]=0;for(var V=R+1;V<o;V++)for(var q=R+1;q<i;q++)x[V]+=M[q]*n.get(V,q);for(var D=R+1;D<i;D++)for(var U=-M[D]/M[R+1],B=R+1;B<o;B++)n.set(B,D,n.get(B,D)+U*x[B])}if(v)for(var G=R+1;G<i;G++)b.set(G,R,M[G])}}var $=Math.min(i,o+1);if(S<i&&(w[S]=n.get(S,S)),o<$&&(w[$-1]=0),_+1<$&&(M[_]=n.get(_,$-1)),M[$-1]=0,l){for(var K=S;K<p;K++){for(var W=0;W<o;W++)y.set(W,K,0);y.set(K,K,1)}for(var X=S-1;X>=0;X--)if(0!==w[X]){for(var Y=X+1;Y<p;Y++){for(var J=0,Z=X;Z<o;Z++)J+=y.get(Z,X)*y.get(Z,Y);J=-J/y.get(X,X);for(var H=X;H<o;H++)y.set(H,Y,y.get(H,Y)+J*y.get(H,X))}for(var Q=X;Q<o;Q++)y.set(Q,X,-y.get(Q,X));y.set(X,X,1+y.get(X,X));for(var tt=0;tt<X-1;tt++)y.set(tt,X,0)}else{for(var rt=0;rt<o;rt++)y.set(rt,X,0);y.set(X,X,1)}}if(v)for(var et=i-1;et>=0;et--){if(et<_&&0!==M[et])for(var nt=et+1;nt<i;nt++){for(var ot=0,it=et+1;it<i;it++)ot+=b.get(it,et)*b.get(it,nt);ot=-ot/b.get(et+1,et);for(var st=et+1;st<i;st++)b.set(st,nt,b.get(st,nt)+ot*b.get(st,et))}for(var at=0;at<i;at++)b.set(at,et,0);b.set(et,et,1)}for(var ut=$-1,ct=Number.EPSILON;$>0;){var ft=void 0,ht=void 0;for(ft=$-2;ft>=-1&&-1!==ft;ft--){var lt=Number.MIN_VALUE+ct*Math.abs(w[ft]+Math.abs(w[ft+1]));if(Math.abs(M[ft])<=lt||Number.isNaN(M[ft])){M[ft]=0;break}}if(ft===$-2)ht=4;else{var vt=void 0;for(vt=$-1;vt>=ft&&vt!==ft;vt--){var mt=(vt!==$?Math.abs(M[vt]):0)+(vt!==ft+1?Math.abs(M[vt-1]):0);if(Math.abs(w[vt])<=ct*mt){w[vt]=0;break}}vt===ft?ht=3:vt===$-1?ht=1:(ht=2,ft=vt)}switch(ft++,ht){case 1:var gt=M[$-2];M[$-2]=0;for(var pt=$-2;pt>=ft;pt--){var dt=Ve(w[pt],gt),wt=w[pt]/dt,yt=gt/dt;if(w[pt]=dt,pt!==ft&&(gt=-yt*M[pt-1],M[pt-1]=wt*M[pt-1]),v)for(var bt=0;bt<i;bt++)dt=wt*b.get(bt,pt)+yt*b.get(bt,$-1),b.set(bt,$-1,-yt*b.get(bt,pt)+wt*b.get(bt,$-1)),b.set(bt,pt,dt)}break;case 2:var Mt=M[ft-1];M[ft-1]=0;for(var xt=ft;xt<$;xt++){var kt=Ve(w[xt],Mt),Et=w[xt]/kt,St=Mt/kt;if(w[xt]=kt,Mt=-St*M[xt],M[xt]=Et*M[xt],l)for(var _t=0;_t<o;_t++)kt=Et*y.get(_t,xt)+St*y.get(_t,ft-1),y.set(_t,ft-1,-St*y.get(_t,xt)+Et*y.get(_t,ft-1)),y.set(_t,xt,kt)}break;case 3:var jt=Math.max(Math.abs(w[$-1]),Math.abs(w[$-2]),Math.abs(M[$-2]),Math.abs(w[ft]),Math.abs(M[ft])),Rt=w[$-1]/jt,At=w[$-2]/jt,Ot=M[$-2]/jt,Ct=w[ft]/jt,It=M[ft]/jt,Nt=((At+Rt)*(At-Rt)+Ot*Ot)/2,Ft=Rt*Ot*(Rt*Ot),Tt=0;0===Nt&&0===Ft||(Tt=Ft/(Nt+(Tt=Nt<0?0-Math.sqrt(Nt*Nt+Ft):Math.sqrt(Nt*Nt+Ft))));for(var Pt=(Ct+Rt)*(Ct-Rt)+Tt,zt=Ct*It,Lt=ft;Lt<$-1;Lt++){var Vt=Ve(Pt,zt);0===Vt&&(Vt=Number.MIN_VALUE);var qt=Pt/Vt,Dt=zt/Vt;if(Lt!==ft&&(M[Lt-1]=Vt),Pt=qt*w[Lt]+Dt*M[Lt],M[Lt]=qt*M[Lt]-Dt*w[Lt],zt=Dt*w[Lt+1],w[Lt+1]=qt*w[Lt+1],v)for(var Ut=0;Ut<i;Ut++)Vt=qt*b.get(Ut,Lt)+Dt*b.get(Ut,Lt+1),b.set(Ut,Lt+1,-Dt*b.get(Ut,Lt)+qt*b.get(Ut,Lt+1)),b.set(Ut,Lt,Vt);if(0===(Vt=Ve(Pt,zt))&&(Vt=Number.MIN_VALUE),qt=Pt/Vt,Dt=zt/Vt,w[Lt]=Vt,Pt=qt*M[Lt]+Dt*w[Lt+1],w[Lt+1]=-Dt*M[Lt]+qt*w[Lt+1],zt=Dt*M[Lt+1],M[Lt+1]=qt*M[Lt+1],l&&Lt<o-1)for(var Bt=0;Bt<o;Bt++)Vt=qt*y.get(Bt,Lt)+Dt*y.get(Bt,Lt+1),y.set(Bt,Lt+1,-Dt*y.get(Bt,Lt)+qt*y.get(Bt,Lt+1)),y.set(Bt,Lt,Vt)}M[$-2]=Pt;break;case 4:if(w[ft]<=0&&(w[ft]=w[ft]<0?-w[ft]:0,v))for(var Gt=0;Gt<=ut;Gt++)b.set(Gt,ft,-b.get(Gt,ft));for(;ft<ut&&!(w[ft]>=w[ft+1]);){var $t=w[ft];if(w[ft]=w[ft+1],w[ft+1]=$t,v&&ft<i-1)for(var Kt=0;Kt<i;Kt++)$t=b.get(Kt,ft+1),b.set(Kt,ft+1,b.get(Kt,ft)),b.set(Kt,ft,$t);if(l&&ft<o-1)for(var Wt=0;Wt<o;Wt++)$t=y.get(Wt,ft+1),y.set(Wt,ft+1,y.get(Wt,ft)),y.set(Wt,ft,$t);ft++}$--}}if(m){var Xt=b;b=y,y=Xt}this.m=o,this.n=i,this.s=w,this.U=y,this.V=b}return Yr(t,[{key:"solve",value:function(t){for(var r=t,e=this.threshold,n=this.s.length,o=Ne.zeros(n,n),i=0;i<n;i++)Math.abs(this.s[i])<=e?o.set(i,i,0):o.set(i,i,1/this.s[i]);for(var s=this.U,a=this.rightSingularVectors,u=a.mmul(o),c=a.rows,f=s.rows,h=Ne.zeros(c,f),l=0;l<c;l++)for(var v=0;v<f;v++){for(var m=0,g=0;g<n;g++)m+=u.get(l,g)*s.get(v,g);h.set(l,v,m)}return h.mmul(r)}},{key:"solveForDiagonal",value:function(t){return this.solve(Ne.diag(t))}},{key:"inverse",value:function(){for(var t=this.V,r=this.threshold,e=t.rows,n=t.columns,o=new Ne(e,this.s.length),i=0;i<e;i++)for(var s=0;s<n;s++)Math.abs(this.s[s])>r&&o.set(i,s,t.get(i,s)/this.s[s]);for(var a=this.U,u=a.rows,c=a.columns,f=new Ne(e,u),h=0;h<e;h++)for(var l=0;l<u;l++){for(var v=0,m=0;m<c;m++)v+=o.get(h,m)*a.get(l,m);f.set(h,l,v)}return f}},{key:"condition",get:function(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}},{key:"norm2",get:function(){return this.s[0]}},{key:"rank",get:function(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,r=0,e=this.s,n=0,o=e.length;n<o;n++)e[n]>t&&r++;return r}},{key:"diagonal",get:function(){return Array.from(this.s)}},{key:"threshold",get:function(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}},{key:"leftSingularVectors",get:function(){return this.U}},{key:"rightSingularVectors",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){return Ne.diag(this.s)}}]),t}(),De=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Wr(this,t);var n=e.assumeSymmetric,o=void 0!==n&&n;if(!(r=Le.checkMatrix(r)).isSquare())throw new Error("Matrix is not a square matrix");if(r.isEmpty())throw new Error("Matrix must be non-empty");var i,s,a=r.columns,u=new Ne(a,a),c=new Float64Array(a),f=new Float64Array(a),h=r;if(!!o||r.isSymmetric()){for(i=0;i<a;i++)for(s=0;s<a;s++)u.set(i,s,h.get(i,s));Ue(a,f,c,u),Be(a,f,c,u)}else{var l=new Ne(a,a),v=new Float64Array(a);for(s=0;s<a;s++)for(i=0;i<a;i++)l.set(i,s,h.get(i,s));Ge(a,l,v,u),$e(a,f,c,u,l)}this.n=a,this.e=f,this.d=c,this.V=u}return Yr(t,[{key:"realEigenvalues",get:function(){return Array.from(this.d)}},{key:"imaginaryEigenvalues",get:function(){return Array.from(this.e)}},{key:"eigenvectorMatrix",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){var t,r,e=this.n,n=this.e,o=this.d,i=new Ne(e,e);for(t=0;t<e;t++){for(r=0;r<e;r++)i.set(t,r,0);i.set(t,t,o[t]),n[t]>0?i.set(t,t+1,n[t]):n[t]<0&&i.set(t,t-1,n[t])}return i}}]),t}();function Ue(t,r,e,n){var o,i,s,a,u,c,f,h;for(u=0;u<t;u++)e[u]=n.get(t-1,u);for(a=t-1;a>0;a--){for(h=0,s=0,c=0;c<a;c++)h+=Math.abs(e[c]);if(0===h)for(r[a]=e[a-1],u=0;u<a;u++)e[u]=n.get(a-1,u),n.set(a,u,0),n.set(u,a,0);else{for(c=0;c<a;c++)e[c]/=h,s+=e[c]*e[c];for(o=e[a-1],i=Math.sqrt(s),o>0&&(i=-i),r[a]=h*i,s-=o*i,e[a-1]=o-i,u=0;u<a;u++)r[u]=0;for(u=0;u<a;u++){for(o=e[u],n.set(u,a,o),i=r[u]+n.get(u,u)*o,c=u+1;c<=a-1;c++)i+=n.get(c,u)*e[c],r[c]+=n.get(c,u)*o;r[u]=i}for(o=0,u=0;u<a;u++)r[u]/=s,o+=r[u]*e[u];for(f=o/(s+s),u=0;u<a;u++)r[u]-=f*e[u];for(u=0;u<a;u++){for(o=e[u],i=r[u],c=u;c<=a-1;c++)n.set(c,u,n.get(c,u)-(o*r[c]+i*e[c]));e[u]=n.get(a-1,u),n.set(a,u,0)}}e[a]=s}for(a=0;a<t-1;a++){if(n.set(t-1,a,n.get(a,a)),n.set(a,a,1),0!==(s=e[a+1])){for(c=0;c<=a;c++)e[c]=n.get(c,a+1)/s;for(u=0;u<=a;u++){for(i=0,c=0;c<=a;c++)i+=n.get(c,a+1)*n.get(c,u);for(c=0;c<=a;c++)n.set(c,u,n.get(c,u)-i*e[c])}}for(c=0;c<=a;c++)n.set(c,a+1,0)}for(u=0;u<t;u++)e[u]=n.get(t-1,u),n.set(t-1,u,0);n.set(t-1,t-1,1),r[0]=0}function Be(t,r,e,n){var o,i,s,a,u,c,f,h,l,v,m,g,p,d,w,y;for(s=1;s<t;s++)r[s-1]=r[s];r[t-1]=0;var b=0,M=0,x=Number.EPSILON;for(c=0;c<t;c++){for(M=Math.max(M,Math.abs(e[c])+Math.abs(r[c])),f=c;f<t&&!(Math.abs(r[f])<=x*M);)f++;if(f>c)do{for(o=e[c],l=Ve(h=(e[c+1]-o)/(2*r[c]),1),h<0&&(l=-l),e[c]=r[c]/(h+l),e[c+1]=r[c]*(h+l),v=e[c+1],i=o-e[c],s=c+2;s<t;s++)e[s]-=i;for(b+=i,h=e[f],g=m=1,p=m,d=r[c+1],w=0,y=0,s=f-1;s>=c;s--)for(p=g,g=m,y=w,o=m*r[s],i=m*h,l=Ve(h,r[s]),r[s+1]=w*l,w=r[s]/l,h=(m=h/l)*e[s]-w*o,e[s+1]=i+w*(m*o+w*e[s]),u=0;u<t;u++)i=n.get(u,s+1),n.set(u,s+1,w*n.get(u,s)+m*i),n.set(u,s,m*n.get(u,s)-w*i);h=-w*y*p*d*r[c]/v,r[c]=w*h,e[c]=m*h}while(Math.abs(r[c])>x*M);e[c]=e[c]+b,r[c]=0}for(s=0;s<t-1;s++){for(u=s,h=e[s],a=s+1;a<t;a++)e[a]<h&&(u=a,h=e[a]);if(u!==s)for(e[u]=e[s],e[s]=h,a=0;a<t;a++)h=n.get(a,s),n.set(a,s,n.get(a,u)),n.set(a,u,h)}}function Ge(t,r,e,n){var o,i,s,a,u,c,f,h=t-1;for(c=1;c<=h-1;c++){for(f=0,a=c;a<=h;a++)f+=Math.abs(r.get(a,c-1));if(0!==f){for(s=0,a=h;a>=c;a--)e[a]=r.get(a,c-1)/f,s+=e[a]*e[a];for(i=Math.sqrt(s),e[c]>0&&(i=-i),s-=e[c]*i,e[c]=e[c]-i,u=c;u<t;u++){for(o=0,a=h;a>=c;a--)o+=e[a]*r.get(a,u);for(o/=s,a=c;a<=h;a++)r.set(a,u,r.get(a,u)-o*e[a])}for(a=0;a<=h;a++){for(o=0,u=h;u>=c;u--)o+=e[u]*r.get(a,u);for(o/=s,u=c;u<=h;u++)r.set(a,u,r.get(a,u)-o*e[u])}e[c]=f*e[c],r.set(c,c-1,f*i)}}for(a=0;a<t;a++)for(u=0;u<t;u++)n.set(a,u,a===u?1:0);for(c=h-1;c>=1;c--)if(0!==r.get(c,c-1)){for(a=c+1;a<=h;a++)e[a]=r.get(a,c-1);for(u=c;u<=h;u++){for(i=0,a=c;a<=h;a++)i+=e[a]*n.get(a,u);for(i=i/e[c]/r.get(c,c-1),a=c;a<=h;a++)n.set(a,u,n.get(a,u)+i*e[a])}}}function $e(t,r,e,n,o){var i,s,a,u,c,f,h,l,v,m,g,p,d,w,y,b=t-1,M=t-1,x=Number.EPSILON,k=0,E=0,S=0,_=0,j=0,R=0,A=0,O=0;for(i=0;i<t;i++)for((i<0||i>M)&&(e[i]=o.get(i,i),r[i]=0),s=Math.max(i-1,0);s<t;s++)E+=Math.abs(o.get(i,s));for(;b>=0;){for(u=b;u>0&&(0===(R=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)))&&(R=E),!(Math.abs(o.get(u,u-1))<x*R));)u--;if(u===b)o.set(b,b,o.get(b,b)+k),e[b]=o.get(b,b),r[b]=0,b--,O=0;else if(u===b-1){if(h=o.get(b,b-1)*o.get(b-1,b),_=(S=(o.get(b-1,b-1)-o.get(b,b))/2)*S+h,A=Math.sqrt(Math.abs(_)),o.set(b,b,o.get(b,b)+k),o.set(b-1,b-1,o.get(b-1,b-1)+k),l=o.get(b,b),_>=0){for(A=S>=0?S+A:S-A,e[b-1]=l+A,e[b]=e[b-1],0!==A&&(e[b]=l-h/A),r[b-1]=0,r[b]=0,S=(l=o.get(b,b-1))/(R=Math.abs(l)+Math.abs(A)),_=A/R,S/=j=Math.sqrt(S*S+_*_),_/=j,s=b-1;s<t;s++)A=o.get(b-1,s),o.set(b-1,s,_*A+S*o.get(b,s)),o.set(b,s,_*o.get(b,s)-S*A);for(i=0;i<=b;i++)A=o.get(i,b-1),o.set(i,b-1,_*A+S*o.get(i,b)),o.set(i,b,_*o.get(i,b)-S*A);for(i=0;i<=M;i++)A=n.get(i,b-1),n.set(i,b-1,_*A+S*n.get(i,b)),n.set(i,b,_*n.get(i,b)-S*A)}else e[b-1]=l+S,e[b]=l+S,r[b-1]=A,r[b]=-A;b-=2,O=0}else{if(l=o.get(b,b),v=0,h=0,u<b&&(v=o.get(b-1,b-1),h=o.get(b,b-1)*o.get(b-1,b)),10===O){for(k+=l,i=0;i<=b;i++)o.set(i,i,o.get(i,i)-l);l=v=.75*(R=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2))),h=-.4375*R*R}if(30===O&&(R=(R=(v-l)/2)*R+h)>0){for(R=Math.sqrt(R),v<l&&(R=-R),R=l-h/((v-l)/2+R),i=0;i<=b;i++)o.set(i,i,o.get(i,i)-R);k+=R,l=v=h=.964}for(O+=1,c=b-2;c>=u&&(S=((j=l-(A=o.get(c,c)))*(R=v-A)-h)/o.get(c+1,c)+o.get(c,c+1),_=o.get(c+1,c+1)-A-j-R,j=o.get(c+2,c+1),S/=R=Math.abs(S)+Math.abs(_)+Math.abs(j),_/=R,j/=R,c!==u)&&!(Math.abs(o.get(c,c-1))*(Math.abs(_)+Math.abs(j))<x*(Math.abs(S)*(Math.abs(o.get(c-1,c-1))+Math.abs(A)+Math.abs(o.get(c+1,c+1)))));)c--;for(i=c+2;i<=b;i++)o.set(i,i-2,0),i>c+2&&o.set(i,i-3,0);for(a=c;a<=b-1&&(w=a!==b-1,a!==c&&(S=o.get(a,a-1),_=o.get(a+1,a-1),j=w?o.get(a+2,a-1):0,0!==(l=Math.abs(S)+Math.abs(_)+Math.abs(j))&&(S/=l,_/=l,j/=l)),0!==l);a++)if(R=Math.sqrt(S*S+_*_+j*j),S<0&&(R=-R),0!==R){for(a!==c?o.set(a,a-1,-R*l):u!==c&&o.set(a,a-1,-o.get(a,a-1)),l=(S+=R)/R,v=_/R,A=j/R,_/=S,j/=S,s=a;s<t;s++)S=o.get(a,s)+_*o.get(a+1,s),w&&(S+=j*o.get(a+2,s),o.set(a+2,s,o.get(a+2,s)-S*A)),o.set(a,s,o.get(a,s)-S*l),o.set(a+1,s,o.get(a+1,s)-S*v);for(i=0;i<=Math.min(b,a+3);i++)S=l*o.get(i,a)+v*o.get(i,a+1),w&&(S+=A*o.get(i,a+2),o.set(i,a+2,o.get(i,a+2)-S*j)),o.set(i,a,o.get(i,a)-S),o.set(i,a+1,o.get(i,a+1)-S*_);for(i=0;i<=M;i++)S=l*n.get(i,a)+v*n.get(i,a+1),w&&(S+=A*n.get(i,a+2),n.set(i,a+2,n.get(i,a+2)-S*j)),n.set(i,a,n.get(i,a)-S),n.set(i,a+1,n.get(i,a+1)-S*_)}}}if(0!==E){for(b=t-1;b>=0;b--)if(S=e[b],0===(_=r[b]))for(u=b,o.set(b,b,1),i=b-1;i>=0;i--){for(h=o.get(i,i)-S,j=0,s=u;s<=b;s++)j+=o.get(i,s)*o.get(s,b);if(r[i]<0)A=h,R=j;else if(u=i,0===r[i]?o.set(i,b,0!==h?-j/h:-j/(x*E)):(l=o.get(i,i+1),v=o.get(i+1,i),f=(l*R-A*j)/(_=(e[i]-S)*(e[i]-S)+r[i]*r[i]),o.set(i,b,f),o.set(i+1,b,Math.abs(l)>Math.abs(A)?(-j-h*f)/l:(-R-v*f)/A)),x*(f=Math.abs(o.get(i,b)))*f>1)for(s=i;s<=b;s++)o.set(s,b,o.get(s,b)/f)}else if(_<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,_/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-S)/o.get(b,b-1))):(y=Ke(0,-o.get(b-1,b),o.get(b-1,b-1)-S,_),o.set(b-1,b-1,y[0]),o.set(b-1,b,y[1])),o.set(b,b-1,0),o.set(b,b,1),i=b-2;i>=0;i--){for(m=0,g=0,s=u;s<=b;s++)m+=o.get(i,s)*o.get(s,b-1),g+=o.get(i,s)*o.get(s,b);if(h=o.get(i,i)-S,r[i]<0)A=h,j=m,R=g;else if(u=i,0===r[i]?(y=Ke(-m,-g,h,_),o.set(i,b-1,y[0]),o.set(i,b,y[1])):(l=o.get(i,i+1),v=o.get(i+1,i),p=(e[i]-S)*(e[i]-S)+r[i]*r[i]-_*_,d=2*(e[i]-S)*_,0===p&&0===d&&(p=x*E*(Math.abs(h)+Math.abs(_)+Math.abs(l)+Math.abs(v)+Math.abs(A))),y=Ke(l*j-A*m+_*g,l*R-A*g-_*m,p,d),o.set(i,b-1,y[0]),o.set(i,b,y[1]),Math.abs(l)>Math.abs(A)+Math.abs(_)?(o.set(i+1,b-1,(-m-h*o.get(i,b-1)+_*o.get(i,b))/l),o.set(i+1,b,(-g-h*o.get(i,b)-_*o.get(i,b-1))/l)):(y=Ke(-j-v*o.get(i,b-1),-R-v*o.get(i,b),A,_),o.set(i+1,b-1,y[0]),o.set(i+1,b,y[1]))),x*(f=Math.max(Math.abs(o.get(i,b-1)),Math.abs(o.get(i,b))))*f>1)for(s=i;s<=b;s++)o.set(s,b-1,o.get(s,b-1)/f),o.set(s,b,o.get(s,b)/f)}for(i=0;i<t;i++)if(i<0||i>M)for(s=i;s<t;s++)n.set(i,s,o.get(i,s));for(s=t-1;s>=0;s--)for(i=0;i<=M;i++){for(A=0,a=0;a<=Math.min(s,M);a++)A+=n.get(i,a)*o.get(a,s);n.set(i,s,A)}}}function Ke(t,r,e,n){var o,i;return Math.abs(e)>Math.abs(n)?[(t+(o=n/e)*r)/(i=e+o*n),(r-o*t)/i]:[((o=e/n)*t+r)/(i=n+o*e),(o*r-t)/i]}var We=Yr((function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Wr(this,t),r=Le.checkMatrix(r);var n,o=e.Y,i=e.scaleScores,s=void 0!==i&&i,a=e.maxIterations,u=void 0===a?1e3:a,c=e.terminationCriteria,f=void 0===c?1e-10:c;if(o){if((o=re(o)&&"number"==typeof o[0]?Ne.columnVector(o):Le.checkMatrix(o)).rows!==r.rows)throw new Error("Y should have the same number of rows as X");n=o.getColumnVector(0)}else n=r.getColumnVector(0);for(var h,l,v,m,g=1,p=0;p<u&&g>f;p++)v=(v=r.transpose().mmul(n).div(n.transpose().mmul(n).get(0,0))).div(v.norm()),h=r.mmul(v).div(v.transpose().mmul(v).get(0,0)),p>0&&(g=h.clone().sub(m).pow(2).sum()),m=h.clone(),o?(l=(l=o.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0))).div(l.norm()),n=o.mmul(l).div(l.transpose().mmul(l).get(0,0))):n=h;if(o){var d=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));d=d.div(d.norm());var w=r.clone().sub(h.clone().mmul(d.transpose())),y=n.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),b=o.clone().sub(h.clone().mulS(y.get(0,0)).mmul(l.transpose()));this.t=h,this.p=d.transpose(),this.w=v.transpose(),this.q=l,this.u=n,this.s=h.transpose().mmul(h),this.xResidual=w,this.yResidual=b,this.betas=y}else this.w=v.transpose(),this.s=h.transpose().mmul(h).sqrt(),this.t=s?h.clone().div(this.s.get(0,0)):h,this.xResidual=r.sub(h.mmul(v.transpose()))}));function Xe(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Ye(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Ye(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Ye(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var Je=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Wr(this,t),!0===r){var n=e;return this.center=n.center,this.scale=n.scale,this.means=n.means,this.stdevs=n.stdevs,this.U=Ne.checkMatrix(n.U),this.S=n.S,this.R=n.R,void(this.excludedFeatures=n.excludedFeatures||[])}r=new Ne(r);var o=e.isCovarianceMatrix,i=void 0!==o&&o,s=e.method,a=void 0===s?"SVD":s,u=e.nCompNIPALS,c=void 0===u?2:u,f=e.center,h=void 0===f||f,l=e.scale,v=void 0!==l&&l,m=e.ignoreZeroVariance,g=void 0!==m&&m;if(this.center=h,this.scale=v,this.means=null,this.stdevs=null,this.excludedFeatures=[],i)this._computeFromCovarianceMatrix(r);else switch(this._adjust(r,g),a){case"covarianceMatrix":var p=new Pe(r).mmul(r).div(r.rows-1);this._computeFromCovarianceMatrix(p);break;case"NIPALS":this._computeWithNIPALS(r,c);break;case"SVD":var d=new qe(r,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=d.rightSingularVectors;var w,y=d.diagonal,b=[],M=Xe(y);try{for(M.s();!(w=M.n()).done;){var x=w.value;b.push(x*x/(r.rows-1))}}catch(t){M.e(t)}finally{M.f()}this.S=b;break;default:throw new Error("unknown method: ".concat(a))}}return Yr(t,[{key:"predict",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.nComponents,n=void 0===e?this.U.columns:e;if(t=new Ne(t),this.center&&(t.subRowVector(this.means),this.scale)){var o,i=Xe(this.excludedFeatures);try{for(i.s();!(o=i.n()).done;){var s=o.value;t.removeColumn(s)}}catch(t){i.e(t)}finally{i.f()}t.divRowVector(this.stdevs)}var a=t.mmul(this.U);return a.subMatrix(0,a.rows-1,0,n-1)}},{key:"invert",value:function(t){var r=(t=Ne.checkMatrix(t)).mmul(this.U.transpose());return this.center&&(this.scale&&r.mulRowVector(this.stdevs),r.addRowVector(this.means)),r}},{key:"getExplainedVariance",value:function(){var t,r=0,e=Xe(this.S);try{for(e.s();!(t=e.n()).done;){var n=t.value;r+=n}}catch(t){e.e(t)}finally{e.f()}return this.S.map((function(t){return t/r}))}},{key:"getCumulativeVariance",value:function(){for(var t=this.getExplainedVariance(),r=1;r<t.length;r++)t[r]+=t[r-1];return t}},{key:"getEigenvectors",value:function(){return this.U}},{key:"getEigenvalues",value:function(){return this.S}},{key:"getStandardDeviations",value:function(){return this.S.map((function(t){return Math.sqrt(t)}))}},{key:"getLoadings",value:function(){return this.U.transpose()}},{key:"toJSON",value:function(){return{name:"PCA",center:this.center,scale:this.scale,means:this.means,stdevs:this.stdevs,U:this.U,S:this.S,excludedFeatures:this.excludedFeatures}}},{key:"_adjust",value:function(t,r){if(this.center){var e=t.mean("column"),n=this.scale?t.standardDeviation("column",{mean:e}):null;if(this.means=e,t.subRowVector(e),this.scale){for(var o=0;o<n.length;o++)if(0===n[o]){if(!r)throw new RangeError("Cannot scale the dataset (standard deviation is zero at index ".concat(o));t.removeColumn(o),n.splice(o,1),this.excludedFeatures.push(o),o--}this.stdevs=n,t.divRowVector(n)}}}},{key:"_computeFromCovarianceMatrix",value:function(t){var r=new De(t,{assumeSymmetric:!0});this.U=r.eigenvectorMatrix,this.U.flipRows(),this.S=r.realEigenvalues,this.S.reverse()}},{key:"_computeWithNIPALS",value:function(t,r){this.U=new Ne(r,t.columns),this.S=[];for(var e=t,n=0;n<r;n++){var o=new We(e);this.U.setRow(n,o.w.transpose()),this.S.push(Math.pow(o.s.get(0,0),2)),e=o.xResidual}this.U=this.U.transpose()}}],[{key:"load",value:function(r){if("string"!=typeof r.name)throw new TypeError("model must have a name property");if("PCA"!==r.name)throw new RangeError("invalid model: ".concat(r.name));return new t(!0,r)}}]),t}();function Ze(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!_r(t))throw new Error("data is not eff. array");var e=Nt(r,"scale");Rr(e)||(e=!0);var n=Nt(r,"nCompNIPALS");Or(n)||(n=2),n=Kr(n);var o=Mr(Nt(t,0,[]));if(0===o)throw new Error("invalid dimension of data");if(n>o)throw new Error("nCompNIPALS[".concat(n,"] is more than the dimension[").concat(o,"] of data"));var i="NIPALS",s=new Je(t,{method:i,scale:e,nCompNIPALS:n}),a=s.predict(t),u=a.toJSON();return u}var He=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n&&!1!==r(t[e],e,t););return t};var Qe=function(t){return function(r,e,n){for(var o=-1,i=Object(r),s=n(r),a=s.length;a--;){var u=s[t?a:++o];if(!1===e(i[u],u,i))break}return r}}();var tn=function(t,r){for(var e=-1,n=Array(t);++e<t;)n[e]=r(e);return n};var rn=function(t){return x(t)&&"[object Arguments]"==M(t)},en=Object.prototype,nn=en.hasOwnProperty,on=en.propertyIsEnumerable,sn=rn(function(){return arguments}())?rn:function(t){return x(t)&&nn.call(t,"callee")&&!on.call(t,"callee")},an=sn;var un=function(){return!1},cn=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e?h.Buffer:void 0,i=(o?o.isBuffer:void 0)||un;t.exports=i})),fn=/^(?:0|[1-9]\d*)$/;var hn=function(t,r){var n=e(t);return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&fn.test(t))&&t>-1&&t%1==0&&t<r},ln={};ln["[object Float32Array]"]=ln["[object Float64Array]"]=ln["[object Int8Array]"]=ln["[object Int16Array]"]=ln["[object Int32Array]"]=ln["[object Uint8Array]"]=ln["[object Uint8ClampedArray]"]=ln["[object Uint16Array]"]=ln["[object Uint32Array]"]=!0,ln["[object Arguments]"]=ln["[object Array]"]=ln["[object ArrayBuffer]"]=ln["[object Boolean]"]=ln["[object DataView]"]=ln["[object Date]"]=ln["[object Error]"]=ln["[object Function]"]=ln["[object Map]"]=ln["[object Number]"]=ln["[object Object]"]=ln["[object RegExp]"]=ln["[object Set]"]=ln["[object String]"]=ln["[object WeakMap]"]=!1;var vn=function(t){return x(t)&&rr(t.length)&&!!ln[M(t)]};var mn=function(t){return function(r){return t(r)}},gn=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e&&c.process,i=function(){try{var t=n&&n.require&&n.require("util").types;return t||o&&o.binding&&o.binding("util")}catch(t){}}();t.exports=i})),pn=gn&&gn.isTypedArray,dn=pn?mn(pn):vn,wn=Object.prototype.hasOwnProperty;var yn=function(t,r){var e=u(t),n=!e&&an(t),o=!e&&!n&&cn(t),i=!e&&!n&&!o&&dn(t),s=e||n||o||i,a=s?tn(t.length,String):[],c=a.length;for(var f in t)!r&&!wn.call(t,f)||s&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||hn(f,c))||a.push(f);return a};var bn=function(t){return er(t)?yn(t):Lt(t)};var Mn=function(t,r){return function(e,n){if(null==e)return e;if(!er(e))return t(e,n);for(var o=e.length,i=r?o:-1,s=Object(e);(r?i--:++i<o)&&!1!==n(s[i],i,s););return e}}((function(t,r){return t&&Qe(t,r,bn)}));var xn=function(t){return t};var kn=function(t){return"function"==typeof t?t:xn};var En=function(t,r){return(u(t)?He:Mn)(t,kn(r))};var Sn=function(){this.__data__=new ct,this.size=0};var _n=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e};var jn=function(t){return this.__data__.get(t)};var Rn=function(t){return this.__data__.has(t)};var An=function(t,r){var e=this.__data__;if(e instanceof ct){var n=e.__data__;if(!ft||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new yt(n)}return e.set(t,r),this.size=e.size,this};function On(t){var r=this.__data__=new ct(t);this.size=r.size}On.prototype.clear=Sn,On.prototype.delete=_n,On.prototype.get=jn,On.prototype.has=Rn,On.prototype.set=An;var Cn=On;var In=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this};var Nn=function(t){return this.__data__.has(t)};function Fn(t){var r=-1,e=null==t?0:t.length;for(this.__data__=new yt;++r<e;)this.add(t[r])}Fn.prototype.add=Fn.prototype.push=In,Fn.prototype.has=Nn;var Tn=Fn;var Pn=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n;)if(r(t[e],e,t))return!0;return!1};var zn=function(t,r){return t.has(r)};var Ln=function(t,r,e,n,o,i){var s=1&e,a=t.length,u=r.length;if(a!=u&&!(s&&u>a))return!1;var c=i.get(t),f=i.get(r);if(c&&f)return c==r&&f==t;var h=-1,l=!0,v=2&e?new Tn:void 0;for(i.set(t,r),i.set(r,t);++h<a;){var m=t[h],g=r[h];if(n)var p=s?n(g,m,h,r,t,i):n(m,g,h,t,r,i);if(void 0!==p){if(p)continue;l=!1;break}if(v){if(!Pn(r,(function(t,r){if(!zn(v,r)&&(m===t||o(m,t,e,n,i)))return v.push(r)}))){l=!1;break}}else if(m!==g&&!o(m,g,e,n,i)){l=!1;break}}return i.delete(t),i.delete(r),l},Vn=h.Uint8Array;var qn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t,n){e[++r]=[n,t]})),e};var Dn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t){e[++r]=t})),e},Un=l?l.prototype:void 0,Bn=Un?Un.valueOf:void 0;var Gn=function(t,r,e,n,o,i,s){switch(e){case"[object DataView]":if(t.byteLength!=r.byteLength||t.byteOffset!=r.byteOffset)return!1;t=t.buffer,r=r.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=r.byteLength||!i(new Vn(t),new Vn(r)));case"[object Boolean]":case"[object Date]":case"[object Number]":return rt(+t,+r);case"[object Error]":return t.name==r.name&&t.message==r.message;case"[object RegExp]":case"[object String]":return t==r+"";case"[object Map]":var a=qn;case"[object Set]":var u=1&n;if(a||(a=Dn),t.size!=r.size&&!u)return!1;var c=s.get(t);if(c)return c==r;n|=2,s.set(t,r);var f=Ln(a(t),a(r),n,o,i,s);return s.delete(t),f;case"[object Symbol]":if(Bn)return Bn.call(t)==Bn.call(r)}return!1};var $n=function(t,r){for(var e=-1,n=r.length,o=t.length;++e<n;)t[o+e]=r[e];return t};var Kn=function(t,r,e){var n=r(t);return u(t)?n:$n(n,e(t))};var Wn=function(t,r){for(var e=-1,n=null==t?0:t.length,o=0,i=[];++e<n;){var s=t[e];r(s,e,t)&&(i[o++]=s)}return i};var Xn=function(){return[]},Yn=Object.prototype.propertyIsEnumerable,Jn=Object.getOwnPropertySymbols,Zn=Jn?function(t){return null==t?[]:(t=Object(t),Wn(Jn(t),(function(r){return Yn.call(t,r)})))}:Xn;var Hn=function(t){return Kn(t,bn,Zn)},Qn=Object.prototype.hasOwnProperty;var to=function(t,r,e,n,o,i){var s=1&e,a=Hn(t),u=a.length;if(u!=Hn(r).length&&!s)return!1;for(var c=u;c--;){var f=a[c];if(!(s?f in r:Qn.call(r,f)))return!1}var h=i.get(t),l=i.get(r);if(h&&l)return h==r&&l==t;var v=!0;i.set(t,r),i.set(r,t);for(var m=s;++c<u;){var g=t[f=a[c]],p=r[f];if(n)var d=s?n(p,g,f,r,t,i):n(g,p,f,t,r,i);if(!(void 0===d?g===p||o(g,p,e,n,i):d)){v=!1;break}m||(m="constructor"==f)}if(v&&!m){var w=t.constructor,y=r.constructor;w==y||!("constructor"in t)||!("constructor"in r)||"function"==typeof w&&w instanceof w&&"function"==typeof y&&y instanceof y||(v=!1)}return i.delete(t),i.delete(r),v},ro="[object Arguments]",eo="[object Array]",no="[object Object]",oo=Object.prototype.hasOwnProperty;var io=function(t,r,e,n,o,i){var s=u(t),a=u(r),c=s?eo:tr(t),f=a?eo:tr(r),h=(c=c==ro?no:c)==no,l=(f=f==ro?no:f)==no,v=c==f;if(v&&cn(t)){if(!cn(r))return!1;s=!0,h=!1}if(v&&!h)return i||(i=new Cn),s||dn(t)?Ln(t,r,e,n,o,i):Gn(t,r,c,e,n,o,i);if(!(1&e)){var m=h&&oo.call(t,"__wrapped__"),g=l&&oo.call(r,"__wrapped__");if(m||g){var p=m?t.value():t,d=g?r.value():r;return i||(i=new Cn),o(p,d,e,n,i)}}return!!v&&(i||(i=new Cn),to(t,r,e,n,o,i))};var so=function t(r,e,n,o,i){return r===e||(null==r||null==e||!x(r)&&!x(e)?r!=r&&e!=e:io(r,e,n,o,t,i))};var ao=function(t,r,e,n){var o=e.length,i=o,s=!n;if(null==t)return!i;for(t=Object(t);o--;){var a=e[o];if(s&&a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var u=(a=e[o])[0],c=t[u],f=a[1];if(s&&a[2]){if(void 0===c&&!(u in t))return!1}else{var h=new Cn;if(n)var l=n(c,f,u,t,r,h);if(!(void 0===l?so(f,c,3,n,h):l))return!1}}return!0};var uo=function(t){return t==t&&!j(t)};var co=function(t){for(var r=bn(t),e=r.length;e--;){var n=r[e],o=t[n];r[e]=[n,o,uo(o)]}return r};var fo=function(t,r){return function(e){return null!=e&&(e[t]===r&&(void 0!==r||t in Object(e)))}};var ho=function(t){var r=co(t);return 1==r.length&&r[0][2]?fo(r[0][0],r[0][1]):function(e){return e===t||ao(e,t,r)}};var lo=function(t,r){return null!=t&&r in Object(t)};var vo=function(t,r,e){for(var n=-1,o=(r=Ot(r,t)).length,i=!1;++n<o;){var s=Ct(r[n]);if(!(i=null!=t&&e(t,s)))break;t=t[s]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&rr(o)&&hn(s,o)&&(u(t)||an(t))};var mo=function(t,r){return null!=t&&vo(t,r,lo)};var go=function(t,r){return _(t)&&uo(r)?fo(Ct(t),r):function(e){var n=Nt(e,t);return void 0===n&&n===r?mo(e,t):so(r,n,3)}};var po=function(t){return function(r){return It(r,t)}};var wo=function(t){return _(t)?or(Ct(t)):po(t)};var yo=function(t){return"function"==typeof t?t:null==t?xn:"object"==e(t)?u(t)?go(t[0],t[1]):ho(t):wo(t)};var bo=function(t,r){var e=-1,n=er(t)?Array(t.length):[];return Mn(t,(function(t,o,i){n[++e]=r(t,o,i)})),n};var Mo=function(t,r){return(u(t)?St:bo)(t,yo(r))};var xo=function(t,r){return St(r,(function(r){return t[r]}))};var ko=function(t){return null==t?[]:xo(t,bn(t))};function Eo(t,r){if(!kr(t))return{};if(!_r(r))return{};var e={};return En(r,(function(r){(function(t,r){return!!kr(t)&&!(!Ar(r)&&!Or(r))&&r in t})(t,r)&&(e[r]=Nt(t,r))})),e}function So(t){if(kr(t)){for(var r in t)return!0;return!1}return!1}var _o=Array.prototype.join;var jo=function(t,r){return null==t?"":_o.call(t,r)},Ro=Yr((function t(r){var e=this;Wr(this,t),this.getCost=function(){return e.Elements.map((function(t){return t.DistanceFromMedoid})).reduce((function(t,r){return t+r}),0)},this.findBestMedoidIdx=function(t){return e.Elements.map((function(r){return e.calcCostForGivenElementAsMedoid(r,t)})).reduce((function(t,r,e,n){return r.CostIfMadeMedoid<n[t].CostIfMadeMedoid?e:t}),0)},this.calcCostForGivenElementAsMedoid=function(r,n){return{CostIfMadeMedoid:new t({Elements:e.Elements.map((function(t){return{DistanceFromMedoid:n(t.Element,r.Element),Element:t.Element}})),Medoid:r.Element}).getCost(),Element:r}},this.Elements=r.Elements,this.Medoid=r.Medoid})),Ao=Ro,Oo=Object.defineProperty({Cluster:Ao},"__esModule",{value:!0}),Co=Object.defineProperty({distance:function(t,r){if(t.length!==r.length)throw new Error("the inputs must have the same dimension");var e=Array.from(t.keys()).map((function(e){return Math.pow(Math.abs(t[e]-r[e]),2)})).reduce((function(t,r){return t+r}),0);return Math.sqrt(e)}},"__esModule",{value:!0}),Io=Object.defineProperty({kGtElementArrLength:"k must be less than the number of elements in the input array"},"__esModule",{value:!0});function No(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Fo(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Fo(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Fo(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var To=function(){function t(r,e,n){var o=this;Wr(this,t),this.Elements=r,this.K=e,this.DistanceFn=n,this.OptimisationCompleted=!1,this.iterate=function(){o.IterationCount++,o.Clusters||o.allocateToClustersAroundCurrentMedoids();for(var r=o.Medoids,e=o.Clusters,n=o.calculateCurrentCost(),i=n,s=0;s<o.Medoids.length;s++){var a,u=No(o.Elements.filter((function(t){return 0===o.Medoids.filter((function(r){return 0===o.DistanceFn(t,r)})).length})));try{for(u.s();!(a=u.n()).done;){var c=a.value,f=o.Medoids.slice();f[s]=c;var h=new t(o.Elements.slice(),o.K,o.DistanceFn);h.Medoids=f,h.allocateToClustersAroundCurrentMedoids();var l=h.calculateCurrentCost();l<i&&(i=l,o.Clusters=h.Clusters,o.Medoids=f)}}catch(t){u.e(t)}finally{u.f()}}return o.calculateCurrentCost()<n||(o.Clusters=e,o.Medoids=r,o.OptimisationCompleted=!0,!1)},this.getClusteredData=function(){return o.OptimisationCompleted||o.runToCompletion(),o.Clusters.map((function(t){return t.Elements.map((function(t){return t.Element}))}))},this.runToCompletion=function(){for(;o.iterate(););},this.allocateToClustersAroundCurrentMedoids=function(){o.Clusters=new Array,o.Medoids.forEach((function(t){o.Clusters.push(new Oo.Cluster({Elements:[],Medoid:t}))})),o.Elements.forEach((function(t,r){var e=o.findDistances(o.Clusters.map((function(t){return t.Medoid})),t),n=e.reduce((function(t,r,e,n){return r<n[t]?e:t}),0);o.Clusters[n].Elements.push({DistanceFromMedoid:e[n],Element:t})}))},this.calculateCurrentCost=function(){return o.Clusters.map((function(t){return t.getCost()})).reduce((function(t,r){return t+r}),0)},this.findDistances=function(t,r){return t.map((function(t){return o.DistanceFn(t,r)}))},this.selectInitialMedoids=function(){if(o.K>=o.Elements.length)throw Io.kGtElementArrLength;for(var t=[],r=function(t,r){var e,n=No(r);try{for(n.s();!(e=n.n()).done;){var i=e.value;if(0===o.DistanceFn(i,t))return!1}}catch(t){n.e(t)}finally{n.f()}return!0},e=0;e<o.Elements.length&&t.length<o.K;)r(o.Elements[e],t)&&t.push(o.Elements[e]),e++;return t},this.DistanceFn=this.DistanceFn||Co.distance,this.Medoids=this.selectInitialMedoids(),this.IterationCount=0}return Yr(t,[{key:"OptimisationStarted",get:function(){return this.IterationCount>0}}]),t}();To.clusterElements=function(t,r,e){return To.getInstance(t,r,e),new Array},To.getInstance=function(t,r,e){return new To(t,r,e)};var Po=To,zo=Object.defineProperty({Clusterer:Po},"__esModule",{value:!0}),Lo=o(i((function(t,r){function e(t){for(var e in t)r.hasOwnProperty(e)||(r[e]=t[e])}Object.defineProperty(r,"__esModule",{value:!0}),e(Oo),e(zo)})));function Vo(t,r){for(var e=0,n=0;n<t.length;n++)e+=(t[n]-r[n])*(t[n]-r[n]);return e}var qo={distanceFunction:Vo};function Do(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:qo,n=e.distanceFunction||qo.distanceFunction,o=e.similarityFunction||qo.similarityFunction,i=-1;if("function"==typeof o)for(var s=Number.MIN_VALUE,a=0;a<t.length;a++){var u=o(r,t[a]);u>s&&(s=u,i=a)}else{if("function"!=typeof n)throw new Error("A similarity or distance function it's required");for(var c=Number.MAX_VALUE,f=0;f<t.length;f++){var h=n(r,t[f]);h<c&&(c=h,i=f)}}return i}function Uo(t,r,e,n){for(var o=0;o<t.length;o++)e[o]=Do(r,t[o],{distanceFunction:n});return e}var Bo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();Wr(this,t),this.state=new Uint32Array(4),this.init(r),this.random=this.getFloat.bind(this)}return Yr(t,[{key:"getUint32",value:function(){return this.nextState(),this.state[3]+this.state[2]>>>0}},{key:"getFloat",value:function(){return 5.960464477539063e-8*(this.getUint32()>>>8)}},{key:"init",value:function(t){if(!Number.isInteger(t))throw new TypeError("seed must be an integer");this.state[0]=t,this.state[1]=0,this.state[2]=0,this.state[3]=0;for(var r=1;r<8;r++)this.state[3&r]^=r+(e=1812433253,n=this.state[r-1&3]^this.state[r-1&3]>>>30>>>0,o=void 0,o=65535&(e>>>=0),((e-o)*(n>>>=0)>>>0)+o*n>>>0)>>>0;var e,n,o;this.periodCertification();for(var i=0;i<8;i++)this.nextState()}},{key:"periodCertification",value:function(){0===this.state[0]&&0===this.state[1]&&0===this.state[2]&&0===this.state[3]&&(this.state[0]=88,this.state[1]=83,this.state[2]=65,this.state[3]=68)}},{key:"nextState",value:function(){var t=this.state[0];t^=t<<15,t^=t>>>18,t^=this.state[3]<<11,this.state[0]=this.state[1],this.state[1]=this.state[2],this.state[2]=this.state[3],this.state[3]=t}}]),t}();function Go(t){var r,e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.random,i=n.size,s=void 0===i?1:i,a=n.replace,u=void 0!==a&&a,c=n.probabilities;if(r="number"==typeof t?$o(t):t.slice(),c){if(!u)throw new Error("choice with probabilities and no replacement is not implemented");if(c.length!==r.length)throw new Error("the length of probabilities option should be equal to the number of choices");e=[c[0]];for(var f=1;f<c.length;f++)e[f]=e[f-1]+c[f];if(Math.abs(1-e[e.length-1])>1e-8)throw new Error("probabilities should sum to 1, but instead sums to ".concat(e[e.length-1]))}if(!1===u&&s>r.length)throw new Error("size option is too large");for(var h=[],l=0;l<s;l++){var v=Ko(r.length,o,e);h.push(r[v]),u||r.splice(v,1)}return h}function $o(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Ko(t,r,e){var n=r();if(e){for(var o=0;n>e[o];)o++;return o}return Math.floor(n*t)}var Wo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.random;if(Wr(this,t),"number"==typeof r){var e=new Bo(r);this.randomGenerator=e.random}else this.randomGenerator=r}return Yr(t,[{key:"choice",value:function(t,r){return Go(t,r,this.randomGenerator)}},{key:"random",value:function(){return this.randomGenerator()}},{key:"randInt",value:function(t,r){return void 0===r&&(r=t,t=0),t+Math.floor(this.randomGenerator()*(r-t))}},{key:"randomSample",value:function(t){for(var r=[],e=0;e<t;e++)r.push(this.random());return r}}]),t}();function Xo(t,r){for(var e=new Ne(t.rows,r.rows),n=0;n<t.rows;n++)for(var o=0;o<r.rows;o++)e.set(n,o,Vo(t.getRow(n),r.getRow(o)));return e}function Yo(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Jo(t){for(var r=[t[0]],e=1;e<t.length;e++)r[e]=r[e-1]+t[e];return r}var Zo=Symbol("distance"),Ho=function(){function t(r,e,n,o,i){Wr(this,t),this.clusters=r,this.centroids=e,this.converged=n,this.iterations=o,this[Zo]=i}return Yr(t,[{key:"nearest",value:function(t){var r=new Array(t.length);return Uo(t,this.centroids.map((function(t){return t.centroid})),r,this[Zo])}},{key:"computeInformation",value:function(r){for(var e=this.centroids.map((function(t){return{centroid:t,error:0,size:0}})),n=0;n<r.length;n++)e[this.clusters[n]].error+=this[Zo](r[n],this.centroids[this.clusters[n]]),e[this.clusters[n]].size++;for(var o=0;o<this.centroids.length;o++)e[o].size?e[o].error/=e[o].size:e[o].error=null;return new t(this.clusters,e,this.converged,this.iterations,this[Zo])}}]),t}(),Qo=a.mark(ei),ti={maxIterations:100,tolerance:1e-6,withIterations:!1,initialization:"kmeans++",distanceFunction:Vo};function ri(t,r,e,n,o,i){var s=function(t,r,e,n){for(var o=r[0].length,i=new Array(n),s=new Array(n),a=0;a<n;a++){i[a]=new Array(o),s[a]=0;for(var u=0;u<o;u++)i[a][u]=0}for(var c=0;c<r.length;c++){s[e[c]]++;for(var f=0;f<o;f++)i[e[c]][f]+=r[c][f]}for(var h=0;h<n;h++)for(var l=0;l<o;l++)s[h]?i[h][l]/=s[h]:i[h][l]=t[h][l];return i}(t,r,e=Uo(r,t,e,o.distanceFunction),n),a=function(t,r,e,n){for(var o=0;o<t.length;o++)if(e(t[o],r[o])>n)return!1;return!0}(s,t,o.distanceFunction,o.tolerance);return new Ho(e,s,a,i,o.distanceFunction)}function ei(t,r,e,n,o){var i,s,u;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:i=!1,s=0;case 2:if(i||!(s<o.maxIterations)){a.next=10;break}return u=ri(t,r,e,n,o,++s),a.next=6,u.computeInformation(r);case 6:i=u.converged,t=u.centroids,a.next=2;break;case 10:case"end":return a.stop()}}),Qo)}function ni(t,r,e){if(e=Object.assign({},ti,e),r<=0||r>t.length||!Number.isInteger(r))throw new Error("K should be a positive integer smaller than the number of points");var n;if(Array.isArray(e.initialization)){if(e.initialization.length!==r)throw new Error("The initial centers should have the same length as K");n=e.initialization}else switch(e.initialization){case"kmeans++":n=function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=(t=new Ne(t)).rows,o=new Wo(e.seed),i=[],s=e.localTrials||2+Math.floor(Math.log(r)),a=o.randInt(n);i.push(t.getRow(a));for(var u=new Ne(1,t.rows),c=0;c<t.rows;c++)u.set(0,c,Vo(t.getRow(c),i[0]));for(var f=[Jo(u.getRow(0))],h=1/f[0][n-1],l=Ne.mul(u,h),v=1;v<r;v++){for(var m=o.choice(n,{replace:!0,size:s,probabilities:l[0]}),g=Xo(t.selection(m,Yo(t.columns)),t),p=void 0,d=void 0,w=void 0,y=0;y<s;y++){var b=Ne.min(u,[g.getRow(y)]),M=b.sum();(void 0===p||M<d)&&(p=m[y],d=M,w=b)}i[v]=t.getRow(p),f=[Jo((u=w).getRow(0))],l=Ne.mul(u,1/f[0][n-1])}return i}(t,r,e);break;case"random":n=function(t,r,e){return new Wo(e).choice(t,{size:r})}(t,r,e.seed);break;case"mostDistant":n=function(t,r,e,n){var o=new Wo(n),i=new Array(r);if(i[0]=Math.floor(o.random()*t.length),r>1){for(var s={dist:-1,index:-1},a=0;a<t.length;++a)e[i[0]][a]>s.dist&&(s.dist=e[i[0]][a],s.index=a);if(i[1]=s.index,r>2)for(var u=2;u<r;++u){for(var c={dist:-1,index:-1},f=0;f<t.length;++f){for(var h={dist:Number.MAX_VALUE,index:-1},l=0;l<u;++l)e[l][f]<h.dist&&-1===i.indexOf(f)&&(h={dist:e[l][f],index:f});h.dist!==Number.MAX_VALUE&&h.dist>c.dist&&(c=Object.assign({},h))}i[u]=c.index}}return i.map((function(r){return t[r]}))}(t,r,function(t,r){for(var e=new Array(t.length),n=0;n<t.length;++n)for(var o=n;o<t.length;++o){e[n]||(e[n]=new Array(t.length)),e[o]||(e[o]=new Array(t.length));var i=r(t[n],t[o]);e[n][o]=i,e[o][n]=i}return e}(t,e.distanceFunction),e.seed);break;default:throw new Error('Unknown initialization method: "'.concat(e.initialization,'"'))}0===e.maxIterations&&(e.maxIterations=Number.MAX_VALUE);var o=new Array(t.length);if(e.withIterations)return ei(n,t,o,r,e);for(var i,s=!1,a=0;!s&&a<e.maxIterations;)s=(i=ri(n,t,o,r,e,++a)).converged,n=i.centroids;return i.computeInformation(t)}function oi(t,r){var e={};function n(t){return jo(t,":")}En(t,(function(t,r){var o=n(t);e[o]=r}));var o=Lo.Clusterer.getInstance(t,r).getClusteredData();return o=Mo(o,(function(t){return Mo(t,(function(t){var r=n(t);return e[r]}))}))}function ii(t,r){var e=ni(t,r),n={};return En(e.clusters,(function(t,r){n[t]||(n[t]=[]),n[t].push(r)})),ko(n)}function si(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Nt(r,"kNumber");e=Or(e)?Kr(e):2;var n,o=Nt(r,"mode");if("k-medoids"!==o&&"k-means"!==o&&(o="k-medoids"),"k-medoids"===o)n=oi(t,e);else{if("k-means"!==o)throw new Error("invalid mode[".concat(o,"]"));n=ii(t,e)}return n}function ai(t){var r={};En(t,(function(t){En(t,(function(t,e){r[e]||(r[e]=0),0===r[e]&&Or(t)&&(r[e]=1),1!==r[e]||Or(t)||(r[e]=-1)}))}));var e=[];return En(r,(function(t,r){1===t&&e.push(r)})),e}function ui(t,r){return Mo(t,(function(t){var e=Eo(t,r);return ko(e)}))}function ci(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!_r(t))throw new Error("data is not eff. array");var e=Nt(r,"kNumber");Or(e)||(e=2),e=Kr(e);var n=Nt(r,"nCompNIPALS");Or(n)||(n=2),n=Kr(n);var o=Nt(r,"mode"),i="",s=Mr(t),a=0,u=0;if(En(t,(function(t){So(t)?a+=1:_r(t)&&(u+=1)})),a===s)i="obj";else{if(u!==s)throw new Error("data is not of the same type");i="mat"}var c,f=null;"obj"===i?(f=ai(t),c=ui(t,f)):c=t;var h=Ze(c,{nCompNIPALS:n}),l=si(h,{kNumber:e,mode:o}),v=Mo(l,(function(t){return Mo(t,(function(t){return h[t]}))})),m=Mo(l,(function(r){return Mo(r,(function(r){return t[r]}))}));return{keys:f,ginds:l,gmat:v,gltdt:m}}function fi(){return fi=r(a.mark((function t(r){var e,n=arguments;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.abrupt("return",Ze(r,e));case 2:case"end":return t.stop()}}),t)}))),fi.apply(this,arguments)}function hi(){return hi=r(a.mark((function t(r){var e,n=arguments;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.prev=1,t.abrupt("return",ci(r,e));case 5:return t.prev=5,t.t0=t.catch(1),t.abrupt("return",Promise.reject(t.t0));case 8:case"end":return t.stop()}}),t,null,[[1,5]])}))),hi.apply(this,arguments)}var li={PCA:function(t){return fi.apply(this,arguments)},cluster:function(t){return hi.apply(this,arguments)}};return li}));
6
+ !function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-cluster"]=r()}(this,(function(){"use strict";function t(t,r,e,n,o,i,s){try{var a=t[i](s),u=a.value}catch(t){return void e(t)}a.done?r(u):Promise.resolve(u).then(n,o)}function r(r){return function(){var e=this,n=arguments;return new Promise((function(o,i){var s=r.apply(e,n);function a(r){t(s,o,i,a,u,"next",r)}function u(r){t(s,o,i,a,u,"throw",r)}a(void 0)}))}}function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function i(t){var r={exports:{}};return t(r,r.exports),r.exports}var s=i((function(t){var r=function(t){var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},s=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=r&&r.prototype instanceof d?r:d,i=Object.create(o.prototype),s=new A(n||[]);return i._invoke=function(t,r,e){var n=l;return function(o,i){if(n===m)throw new Error("Generator is already running");if(n===g){if("throw"===o)throw i;return C()}for(e.method=o,e.arg=i;;){var s=e.delegate;if(s){var a=_(s,e);if(a){if(a===p)continue;return a}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===l)throw n=g,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=m;var u=h(t,r,e);if("normal"===u.type){if(n=e.done?g:v,u.arg===p)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=g,e.method="throw",e.arg=u.arg)}}}(t,e,s),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=f;var l="suspendedStart",v="suspendedYield",m="executing",g="completed",p={};function d(){}function w(){}function y(){}var b={};c(b,s,(function(){return this}));var M=Object.getPrototypeOf,x=M&&M(M(O([])));x&&x!==n&&o.call(x,s)&&(b=x);var k=y.prototype=d.prototype=Object.create(b);function E(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function n(i,s,a,u){var c=h(t[i],t,s);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"===e(l)&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var i;this._invoke=function(t,e){function o(){return new r((function(r,o){n(t,e,r,o)}))}return i=i?i.then(o,o):o()}}function _(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,_(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,p;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function j(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function R(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(j,this),this.reset(!0)}function O(t){if(t){var e=t[s];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:C}}function C(){return{value:r,done:!0}}return w.prototype=y,c(k,"constructor",y),c(y,"constructor",w),w.displayName=c(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===w||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,c(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},E(S.prototype),c(S.prototype,a,(function(){return this})),t.AsyncIterator=S,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var s=new S(f(r,e,n,o),i);return t.isGeneratorFunction(e)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},E(k),c(k,u,"Generator"),c(k,s,(function(){return this})),c(k,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(R),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return a.type="throw",a.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var s=this.tryEntries[i],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var u=o.call(s,"catchLoc"),c=o.call(s,"finallyLoc");if(u&&c){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var s=i?i.completion:{};return s.type=t,s.arg=r,i?(this.method="next",this.next=i.finallyLoc,p):this.complete(s)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),p},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),R(e),p}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;R(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:O(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),p}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"===("undefined"==typeof globalThis?"undefined":e(globalThis))?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}})),a=s,u=Array.isArray,c="object"==e(n)&&n&&n.Object===Object&&n,f="object"==("undefined"==typeof self?"undefined":e(self))&&self&&self.Object===Object&&self,h=c||f||Function("return this")(),l=h.Symbol,v=Object.prototype,m=v.hasOwnProperty,g=v.toString,p=l?l.toStringTag:void 0;var d=function(t){var r=m.call(t,p),e=t[p];try{t[p]=void 0;var n=!0}catch(t){}var o=g.call(t);return n&&(r?t[p]=e:delete t[p]),o},w=Object.prototype.toString;var y=function(t){return w.call(t)},b=l?l.toStringTag:void 0;var M=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":b&&b in Object(t)?d(t):y(t)};var x=function(t){return null!=t&&"object"==e(t)};var k=function(t){return"symbol"==e(t)||x(t)&&"[object Symbol]"==M(t)},E=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/;var _=function(t,r){if(u(t))return!1;var n=e(t);return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!k(t))||(S.test(t)||!E.test(t)||null!=r&&t in Object(r))};var j=function(t){var r=e(t);return null!=t&&("object"==r||"function"==r)};var R,A=function(t){if(!j(t))return!1;var r=M(t);return"[object Function]"==r||"[object GeneratorFunction]"==r||"[object AsyncFunction]"==r||"[object Proxy]"==r},O=h["__core-js_shared__"],C=(R=/[^.]+$/.exec(O&&O.keys&&O.keys.IE_PROTO||""))?"Symbol(src)_1."+R:"";var I=function(t){return!!C&&C in t},N=Function.prototype.toString;var F=function(t){if(null!=t){try{return N.call(t)}catch(t){}try{return t+""}catch(t){}}return""},T=/^\[object .+?Constructor\]$/,P=Function.prototype,z=Object.prototype,L=P.toString,V=z.hasOwnProperty,q=RegExp("^"+L.call(V).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var D=function(t){return!(!j(t)||I(t))&&(A(t)?q:T).test(F(t))};var U=function(t,r){return null==t?void 0:t[r]};var B=function(t,r){var e=U(t,r);return D(e)?e:void 0},G=B(Object,"create");var $=function(){this.__data__=G?G(null):{},this.size=0};var K=function(t){var r=this.has(t)&&delete this.__data__[t];return this.size-=r?1:0,r},W=Object.prototype.hasOwnProperty;var X=function(t){var r=this.__data__;if(G){var e=r[t];return"__lodash_hash_undefined__"===e?void 0:e}return W.call(r,t)?r[t]:void 0},Y=Object.prototype.hasOwnProperty;var J=function(t){var r=this.__data__;return G?void 0!==r[t]:Y.call(r,t)};var Z=function(t,r){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=G&&void 0===r?"__lodash_hash_undefined__":r,this};function H(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}H.prototype.clear=$,H.prototype.delete=K,H.prototype.get=X,H.prototype.has=J,H.prototype.set=Z;var Q=H;var tt=function(){this.__data__=[],this.size=0};var rt=function(t,r){return t===r||t!=t&&r!=r};var et=function(t,r){for(var e=t.length;e--;)if(rt(t[e][0],r))return e;return-1},nt=Array.prototype.splice;var ot=function(t){var r=this.__data__,e=et(r,t);return!(e<0)&&(e==r.length-1?r.pop():nt.call(r,e,1),--this.size,!0)};var it=function(t){var r=this.__data__,e=et(r,t);return e<0?void 0:r[e][1]};var st=function(t){return et(this.__data__,t)>-1};var at=function(t,r){var e=this.__data__,n=et(e,t);return n<0?(++this.size,e.push([t,r])):e[n][1]=r,this};function ut(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}ut.prototype.clear=tt,ut.prototype.delete=ot,ut.prototype.get=it,ut.prototype.has=st,ut.prototype.set=at;var ct=ut,ft=B(h,"Map");var ht=function(){this.size=0,this.__data__={hash:new Q,map:new(ft||ct),string:new Q}};var lt=function(t){var r=e(t);return"string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==t:null===t};var vt=function(t,r){var e=t.__data__;return lt(r)?e["string"==typeof r?"string":"hash"]:e.map};var mt=function(t){var r=vt(this,t).delete(t);return this.size-=r?1:0,r};var gt=function(t){return vt(this,t).get(t)};var pt=function(t){return vt(this,t).has(t)};var dt=function(t,r){var e=vt(this,t),n=e.size;return e.set(t,r),this.size+=e.size==n?0:1,this};function wt(t){var r=-1,e=null==t?0:t.length;for(this.clear();++r<e;){var n=t[r];this.set(n[0],n[1])}}wt.prototype.clear=ht,wt.prototype.delete=mt,wt.prototype.get=gt,wt.prototype.has=pt,wt.prototype.set=dt;var yt=wt;function bt(t,r){if("function"!=typeof t||null!=r&&"function"!=typeof r)throw new TypeError("Expected a function");var e=function e(){var n=arguments,o=r?r.apply(this,n):n[0],i=e.cache;if(i.has(o))return i.get(o);var s=t.apply(this,n);return e.cache=i.set(o,s)||i,s};return e.cache=new(bt.Cache||yt),e}bt.Cache=yt;var Mt=bt;var xt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,kt=/\\(\\)?/g,Et=function(t){var r=Mt(t,(function(t){return 500===e.size&&e.clear(),t})),e=r.cache;return r}((function(t){var r=[];return 46===t.charCodeAt(0)&&r.push(""),t.replace(xt,(function(t,e,n,o){r.push(n?o.replace(kt,"$1"):e||t)})),r}));var St=function(t,r){for(var e=-1,n=null==t?0:t.length,o=Array(n);++e<n;)o[e]=r(t[e],e,t);return o},_t=l?l.prototype:void 0,jt=_t?_t.toString:void 0;var Rt=function t(r){if("string"==typeof r)return r;if(u(r))return St(r,t)+"";if(k(r))return jt?jt.call(r):"";var e=r+"";return"0"==e&&1/r==-Infinity?"-0":e};var At=function(t){return null==t?"":Rt(t)};var Ot=function(t,r){return u(t)?t:_(t,r)?[t]:Et(At(t))};var Ct=function(t){if("string"==typeof t||k(t))return t;var r=t+"";return"0"==r&&1/t==-Infinity?"-0":r};var It=function(t,r){for(var e=0,n=(r=Ot(r,t)).length;null!=t&&e<n;)t=t[Ct(r[e++])];return e&&e==n?t:void 0};var Nt=function(t,r,e){var n=null==t?void 0:It(t,r);return void 0===n?e:n},Ft=Object.prototype;var Tt=function(t){var r=t&&t.constructor;return t===("function"==typeof r&&r.prototype||Ft)};var Pt=function(t,r){return function(e){return t(r(e))}}(Object.keys,Object),zt=Object.prototype.hasOwnProperty;var Lt=function(t){if(!Tt(t))return Pt(t);var r=[];for(var e in Object(t))zt.call(t,e)&&"constructor"!=e&&r.push(e);return r},Vt=B(h,"DataView"),qt=B(h,"Promise"),Dt=B(h,"Set"),Ut=B(h,"WeakMap"),Bt="[object Map]",Gt="[object Promise]",$t="[object Set]",Kt="[object WeakMap]",Wt="[object DataView]",Xt=F(Vt),Yt=F(ft),Jt=F(qt),Zt=F(Dt),Ht=F(Ut),Qt=M;(Vt&&Qt(new Vt(new ArrayBuffer(1)))!=Wt||ft&&Qt(new ft)!=Bt||qt&&Qt(qt.resolve())!=Gt||Dt&&Qt(new Dt)!=$t||Ut&&Qt(new Ut)!=Kt)&&(Qt=function(t){var r=M(t),e="[object Object]"==r?t.constructor:void 0,n=e?F(e):"";if(n)switch(n){case Xt:return Wt;case Yt:return Bt;case Jt:return Gt;case Zt:return $t;case Ht:return Kt}return r});var tr=Qt;var rr=function(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991};var er=function(t){return null!=t&&rr(t.length)&&!A(t)};var nr=function(t){return"string"==typeof t||!u(t)&&x(t)&&"[object String]"==M(t)};var or=function(t){return function(r){return null==r?void 0:r[t]}},ir=or("length"),sr=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var ar=function(t){return sr.test(t)},ur="[\\ud800-\\udfff]",cr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",fr="\\ud83c[\\udffb-\\udfff]",hr="[^\\ud800-\\udfff]",lr="(?:\\ud83c[\\udde6-\\uddff]){2}",vr="[\\ud800-\\udbff][\\udc00-\\udfff]",mr="(?:"+cr+"|"+fr+")"+"?",gr="[\\ufe0e\\ufe0f]?",pr=gr+mr+("(?:\\u200d(?:"+[hr,lr,vr].join("|")+")"+gr+mr+")*"),dr="(?:"+[hr+cr+"?",cr,lr,vr,ur].join("|")+")",wr=RegExp(fr+"(?="+fr+")|"+dr+pr,"g");var yr=function(t){for(var r=wr.lastIndex=0;wr.test(t);)++r;return r};var br=function(t){return ar(t)?yr(t):ir(t)};var Mr=function(t){if(null==t)return 0;if(er(t))return nr(t)?br(t):t.length;var r=tr(t);return"[object Map]"==r||"[object Set]"==r?t.size:Lt(t).length};function xr(t){return"[object Array]"===Object.prototype.toString.call(t)}function kr(t){return"[object Object]"===Object.prototype.toString.call(t)}function Er(t){return"[object String]"===Object.prototype.toString.call(t)}function Sr(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(kr(t)){for(var r in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Er(t)||""!==t)}(t)||!!function(t){return!!xr(t)&&0===t.length}(t))))}function _r(t){return!!xr(t)&&(0!==t.length&&(1!==t.length||!Sr(t[0])))}var jr=function(t){return!0===t||!1===t||x(t)&&"[object Boolean]"==M(t)};function Rr(t){return jr(t)}function Ar(t){return!(!Er(t)||""===t)}function Or(t){var r=!1;return Ar(t)?r=!isNaN(Number(t)):function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)&&(r=!0),r}var Cr=/\s/;var Ir=function(t){for(var r=t.length;r--&&Cr.test(t.charAt(r)););return r},Nr=/^\s+/;var Fr=function(t){return t?t.slice(0,Ir(t)+1).replace(Nr,""):t},Tr=/^[-+]0x[0-9a-f]+$/i,Pr=/^0b[01]+$/i,zr=/^0o[0-7]+$/i,Lr=parseInt;var Vr=function(t){if("number"==typeof t)return t;if(k(t))return NaN;if(j(t)){var r="function"==typeof t.valueOf?t.valueOf():t;t=j(r)?r+"":r}if("string"!=typeof t)return 0===t?t:+t;t=Fr(t);var e=Pr.test(t);return e||zr.test(t)?Lr(t.slice(2),e?2:8):Tr.test(t)?NaN:+t},qr=1/0;var Dr=function(t){return t?(t=Vr(t))===qr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0};var Ur=function(t){var r=Dr(t),e=r%1;return r==r?e?r-e:r:0},Br=h.isFinite,Gr=Math.min;var $r=function(t){var r=Math[t];return function(t,e){if(t=Vr(t),(e=null==e?0:Gr(Ur(e),292))&&Br(t)){var n=(At(t)+"e").split("e"),o=r(n[0]+"e"+(+n[1]+e));return+((n=(At(o)+"e").split("e"))[0]+"e"+(+n[1]-e))}return r(t)}}("round");function Kr(t){if(!Or(t))return 0;t=function(t){return Or(t)?Dr(t):0}(t);var r=$r(t);return"0"===String(r)?0:r}function Wr(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}function Xr(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function Yr(t,r,e){return r&&Xr(t.prototype,r),e&&Xr(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function Jr(t,r){return Jr=Object.setPrototypeOf||function(t,r){return t.__proto__=r,t},Jr(t,r)}function Zr(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&Jr(t,r)}function Hr(t,r){if(r&&("object"===e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function Qr(t){return Qr=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},Qr(t)}var te=Object.prototype.toString;function re(t){return te.call(t).endsWith("Array]")}function ee(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!re(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]>s&&(s=t[a]);return s}function ne(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!re(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");var e=r.fromIndex,n=void 0===e?0:e,o=r.toIndex,i=void 0===o?t.length:o;if(n<0||n>=t.length||!Number.isInteger(n))throw new Error("fromIndex must be a positive integer smaller than length");if(i<=n||i>t.length||!Number.isInteger(i))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var s=t[n],a=n+1;a<i;a++)t[a]<s&&(s=t[a]);return s}function oe(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!re(t))throw new TypeError("input must be an array");if(0===t.length)throw new TypeError("input must not be empty");if(void 0!==e.output){if(!re(e.output))throw new TypeError("output option must be an array if specified");r=e.output}else r=new Array(t.length);var n=ne(t),o=ee(t);if(n===o)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var i=e.min,s=void 0===i?e.autoMinMax?n:0:i,a=e.max,u=void 0===a?e.autoMinMax?o:1:a;if(s>=u)throw new RangeError("min option must be smaller than max option");for(var c=(u-s)/(o-n),f=0;f<t.length;f++)r[f]=(t[f]-n)*c+s;return r}var ie=" ".repeat(2),se=" ".repeat(4);function ae(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=r.maxRows,n=void 0===e?15:e,o=r.maxColumns,i=void 0===o?10:o,s=r.maxNumSize,a=void 0===s?8:s;return"".concat(t.constructor.name," {\n").concat(ie,"[\n").concat(se).concat(ue(t,n,i,a),"\n").concat(ie,"]\n").concat(ie,"rows: ").concat(t.rows,"\n").concat(ie,"columns: ").concat(t.columns,"\n}")}function ue(t,r,e,n){for(var o=t.rows,i=t.columns,s=Math.min(o,r),a=Math.min(i,e),u=[],c=0;c<s;c++){for(var f=[],h=0;h<a;h++)f.push(ce(t.get(c,h),n));u.push("".concat(f.join(" ")))}return a!==i&&(u[u.length-1]+=" ... ".concat(i-e," more columns")),s!==o&&u.push("... ".concat(o-r," more rows")),u.join("\n".concat(se))}function ce(t,r){var e=String(t);if(e.length<=r)return e.padEnd(r," ");var n=t.toPrecision(r-2);if(n.length<=r)return n;var o=t.toExponential(r-2),i=o.indexOf("e"),s=o.slice(i);return o.slice(0,r-s.length)+s}function fe(t,r,e){var n=e?t.rows:t.rows-1;if(r<0||r>n)throw new RangeError("Row index out of range")}function he(t,r,e){var n=e?t.columns:t.columns-1;if(r<0||r>n)throw new RangeError("Column index out of range")}function le(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.columns)throw new RangeError("vector size must be the same as the number of columns");return r}function ve(t,r){if(r.to1DArray&&(r=r.to1DArray()),r.length!==t.rows)throw new RangeError("vector size must be the same as the number of rows");return r}function me(t,r,e,n,o){if(5!==arguments.length)throw new RangeError("expected 4 arguments");if(pe("startRow",r),pe("endRow",e),pe("startColumn",n),pe("endColumn",o),r>e||n>o||r<0||r>=t.rows||e<0||e>=t.rows||n<0||n>=t.columns||o<0||o>=t.columns)throw new RangeError("Submatrix indices are out of range")}function ge(t){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,e=[],n=0;n<t;n++)e.push(r);return e}function pe(t,r){if("number"!=typeof r)throw new TypeError("".concat(t," must be a number"))}function de(t){if(t.isEmpty())throw new Error("Empty matrix has no elements to index")}function we(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<n;s++){for(var a=0,u=0,c=0,f=0;f<o;f++)a+=c=t.get(s,f)-e[s],u+=c*c;r?i.push((u-a*a/o)/(o-1)):i.push((u-a*a/o)/o)}return i}function ye(t,r,e){for(var n=t.rows,o=t.columns,i=[],s=0;s<o;s++){for(var a=0,u=0,c=0,f=0;f<n;f++)a+=c=t.get(f,s)-e[s],u+=c*c;r?i.push((u-a*a/n)/(n-1)):i.push((u-a*a/n)/n)}return i}function be(t,r,e){for(var n=t.rows,o=t.columns,i=n*o,s=0,a=0,u=0,c=0;c<n;c++)for(var f=0;f<o;f++)s+=u=t.get(c,f)-e,a+=u*u;return r?(a-s*s/i)/(i-1):(a-s*s/i)/i}function Me(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[e])}function xe(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r[n])}function ke(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)-r)}function Ee(t){for(var r=[],e=0;e<t.rows;e++){for(var n=0,o=0;o<t.columns;o++)n+=Math.pow(t.get(e,o),2)/(t.columns-1);r.push(Math.sqrt(n))}return r}function Se(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[e])}function _e(t){for(var r=[],e=0;e<t.columns;e++){for(var n=0,o=0;o<t.rows;o++)n+=Math.pow(t.get(o,e),2)/(t.rows-1);r.push(Math.sqrt(n))}return r}function je(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r[n])}function Re(t){for(var r=t.size-1,e=0,n=0;n<t.columns;n++)for(var o=0;o<t.rows;o++)e+=Math.pow(t.get(o,n),2)/r;return Math.sqrt(e)}function Ae(t,r){for(var e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)t.set(e,n,t.get(e,n)/r)}function Oe(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}var Ce=function(){function t(){Wr(this,t)}return Yr(t,[{key:"size",get:function(){return this.rows*this.columns}},{key:"apply",value:function(t){if("function"!=typeof t)throw new TypeError("callback must be a function");for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.call(this,r,e);return this}},{key:"to1DArray",value:function(){for(var t=[],r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.push(this.get(r,e));return t}},{key:"to2DArray",value:function(){for(var t=[],r=0;r<this.rows;r++){t.push([]);for(var e=0;e<this.columns;e++)t[r].push(this.get(r,e))}return t}},{key:"toJSON",value:function(){return this.to2DArray()}},{key:"isRowVector",value:function(){return 1===this.rows}},{key:"isColumnVector",value:function(){return 1===this.columns}},{key:"isVector",value:function(){return 1===this.rows||1===this.columns}},{key:"isSquare",value:function(){return this.rows===this.columns}},{key:"isEmpty",value:function(){return 0===this.rows||0===this.columns}},{key:"isSymmetric",value:function(){if(this.isSquare()){for(var t=0;t<this.rows;t++)for(var r=0;r<=t;r++)if(this.get(t,r)!==this.get(r,t))return!1;return!0}return!1}},{key:"isEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);t++}return n}},{key:"isReducedEchelonForm",value:function(){for(var t=0,r=0,e=-1,n=!0,o=!1;t<this.rows&&n;){for(r=0,o=!1;r<this.columns&&!1===o;)0===this.get(t,r)?r++:1===this.get(t,r)&&r>e?(o=!0,e=r):(n=!1,o=!0);for(var i=r+1;i<this.rows;i++)0!==this.get(t,i)&&(n=!1);t++}return n}},{key:"echelonForm",value:function(){for(var t=this.clone(),r=0,e=0;r<t.rows&&e<t.columns;){for(var n=r,o=r;o<t.rows;o++)t.get(o,e)>t.get(n,e)&&(n=o);if(0===t.get(n,e))e++;else{t.swapRows(r,n);for(var i=t.get(r,e),s=e;s<t.columns;s++)t.set(r,s,t.get(r,s)/i);for(var a=r+1;a<t.rows;a++){var u=t.get(a,e)/t.get(r,e);t.set(a,e,0);for(var c=e+1;c<t.columns;c++)t.set(a,c,t.get(a,c)-t.get(r,c)*u)}r++,e++}}return t}},{key:"reducedEchelonForm",value:function(){for(var t=this.echelonForm(),r=t.columns,e=t.rows,n=e-1;n>=0;)if(0===t.maxRow(n))n--;else{for(var o=0,i=!1;o<e&&!1===i;)1===t.get(n,o)?i=!0:o++;for(var s=0;s<n;s++)for(var a=t.get(s,o),u=o;u<r;u++){var c=t.get(s,u)-a*t.get(n,u);t.set(s,u,c)}n--}return t}},{key:"set",value:function(){throw new Error("set method is unimplemented")}},{key:"get",value:function(){throw new Error("get method is unimplemented")}},{key:"repeat",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.rows,n=void 0===r?1:r,o=t.columns,i=void 0===o?1:o;if(!Number.isInteger(n)||n<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(i)||i<=0)throw new TypeError("columns must be a positive integer");for(var s=new Ne(this.rows*n,this.columns*i),a=0;a<n;a++)for(var u=0;u<i;u++)s.setSubMatrix(this,this.rows*a,this.columns*u);return s}},{key:"fill",value:function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,t);return this}},{key:"neg",value:function(){return this.mulS(-1)}},{key:"getRow",value:function(t){fe(this,t);for(var r=[],e=0;e<this.columns;e++)r.push(this.get(t,e));return r}},{key:"getRowVector",value:function(t){return Ne.rowVector(this.getRow(t))}},{key:"setRow",value:function(t,r){fe(this,t),r=le(this,r);for(var e=0;e<this.columns;e++)this.set(t,e,r[e]);return this}},{key:"swapRows",value:function(t,r){fe(this,t),fe(this,r);for(var e=0;e<this.columns;e++){var n=this.get(t,e);this.set(t,e,this.get(r,e)),this.set(r,e,n)}return this}},{key:"getColumn",value:function(t){he(this,t);for(var r=[],e=0;e<this.rows;e++)r.push(this.get(e,t));return r}},{key:"getColumnVector",value:function(t){return Ne.columnVector(this.getColumn(t))}},{key:"setColumn",value:function(t,r){he(this,t),r=ve(this,r);for(var e=0;e<this.rows;e++)this.set(e,t,r[e]);return this}},{key:"swapColumns",value:function(t,r){he(this,t),he(this,r);for(var e=0;e<this.rows;e++){var n=this.get(e,t);this.set(e,t,this.get(e,r)),this.set(e,r,n)}return this}},{key:"addRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[e]);return this}},{key:"subRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[e]);return this}},{key:"mulRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[e]);return this}},{key:"divRowVector",value:function(t){t=le(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[e]);return this}},{key:"addColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t[r]);return this}},{key:"subColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t[r]);return this}},{key:"mulColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t[r]);return this}},{key:"divColumnVector",value:function(t){t=ve(this,t);for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t[r]);return this}},{key:"mulRow",value:function(t,r){fe(this,t);for(var e=0;e<this.columns;e++)this.set(t,e,this.get(t,e)*r);return this}},{key:"mulColumn",value:function(t,r){he(this,t);for(var e=0;e<this.rows;e++)this.set(e,t,this.get(e,t)*r);return this}},{key:"max",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)>t&&(t=this.get(r,e));return t}},{key:"maxIndex",value:function(){de(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)>t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"min",value:function(){if(this.isEmpty())return NaN;for(var t=this.get(0,0),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.get(r,e)<t&&(t=this.get(r,e));return t}},{key:"minIndex",value:function(){de(this);for(var t=this.get(0,0),r=[0,0],e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.get(e,n)<t&&(t=this.get(e,n),r[0]=e,r[1]=n);return r}},{key:"maxRow",value:function(t){if(fe(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)>r&&(r=this.get(t,e));return r}},{key:"maxRowIndex",value:function(t){fe(this,t),de(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)>r&&(r=this.get(t,n),e[1]=n);return e}},{key:"minRow",value:function(t){if(fe(this,t),this.isEmpty())return NaN;for(var r=this.get(t,0),e=1;e<this.columns;e++)this.get(t,e)<r&&(r=this.get(t,e));return r}},{key:"minRowIndex",value:function(t){fe(this,t),de(this);for(var r=this.get(t,0),e=[t,0],n=1;n<this.columns;n++)this.get(t,n)<r&&(r=this.get(t,n),e[1]=n);return e}},{key:"maxColumn",value:function(t){if(he(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)>r&&(r=this.get(e,t));return r}},{key:"maxColumnIndex",value:function(t){he(this,t),de(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)>r&&(r=this.get(n,t),e[0]=n);return e}},{key:"minColumn",value:function(t){if(he(this,t),this.isEmpty())return NaN;for(var r=this.get(0,t),e=1;e<this.rows;e++)this.get(e,t)<r&&(r=this.get(e,t));return r}},{key:"minColumnIndex",value:function(t){he(this,t),de(this);for(var r=this.get(0,t),e=[0,t],n=1;n<this.rows;n++)this.get(n,t)<r&&(r=this.get(n,t),e[0]=n);return e}},{key:"diag",value:function(){for(var t=Math.min(this.rows,this.columns),r=[],e=0;e<t;e++)r.push(this.get(e,e));return r}},{key:"norm",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"frobenius",r=0;if("max"===t)return this.max();if("frobenius"===t){for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)r+=this.get(e,n)*this.get(e,n);return Math.sqrt(r)}throw new RangeError("unknown norm type: ".concat(t))}},{key:"cumulativeSum",value:function(){for(var t=0,r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t+=this.get(r,e),this.set(r,e,t);return this}},{key:"dot",value:function(r){t.isMatrix(r)&&(r=r.to1DArray());var e=this.to1DArray();if(e.length!==r.length)throw new RangeError("vectors do not have the same size");for(var n=0,o=0;o<e.length;o++)n+=e[o]*r[o];return n}},{key:"mmul",value:function(t){t=Ne.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.columns,o=new Ne(r,n),i=new Float64Array(e),s=0;s<n;s++){for(var a=0;a<e;a++)i[a]=t.get(a,s);for(var u=0;u<r;u++){for(var c=0,f=0;f<e;f++)c+=this.get(u,f)*i[f];o.set(u,s,c)}}return o}},{key:"strassen2x2",value:function(t){t=Ne.checkMatrix(t);var r=new Ne(2,2),e=this.get(0,0),n=t.get(0,0),o=this.get(0,1),i=t.get(0,1),s=this.get(1,0),a=t.get(1,0),u=this.get(1,1),c=t.get(1,1),f=(e+u)*(n+c),h=(s+u)*n,l=e*(i-c),v=u*(a-n),m=(e+o)*c,g=f+v-m+(o-u)*(a+c),p=l+m,d=h+v,w=f-h+l+(s-e)*(n+i);return r.set(0,0,g),r.set(0,1,p),r.set(1,0,d),r.set(1,1,w),r}},{key:"strassen3x3",value:function(t){t=Ne.checkMatrix(t);var r=new Ne(3,3),e=this.get(0,0),n=this.get(0,1),o=this.get(0,2),i=this.get(1,0),s=this.get(1,1),a=this.get(1,2),u=this.get(2,0),c=this.get(2,1),f=this.get(2,2),h=t.get(0,0),l=t.get(0,1),v=t.get(0,2),m=t.get(1,0),g=t.get(1,1),p=t.get(1,2),d=t.get(2,0),w=t.get(2,1),y=t.get(2,2),b=(e-i)*(-l+g),M=(-e+i+s)*(h-l+g),x=(i+s)*(-h+l),k=e*h,E=(-e+u+c)*(h-v+p),S=(-e+u)*(v-p),_=(u+c)*(-h+v),j=(-o+c+f)*(g+d-w),R=(o-f)*(g-w),A=o*d,O=(c+f)*(-d+w),C=(-o+s+a)*(p+d-y),I=(o-a)*(p-y),N=(s+a)*(-d+y),F=k+A+n*m,T=(e+n+o-i-s-c-f)*g+M+x+k+j+A+O,P=k+E+_+(e+n+o-s-a-u-c)*p+A+C+N,z=b+s*(-h+l+m-g-p-d+y)+M+k+A+C+I,L=b+M+x+k+a*w,V=A+C+I+N+i*v,q=k+E+S+c*(-h+v+m-g-p-d+w)+j+R+A,D=j+R+A+O+u*l,U=k+E+S+_+f*y;return r.set(0,0,F),r.set(0,1,T),r.set(0,2,P),r.set(1,0,z),r.set(1,1,L),r.set(1,2,V),r.set(2,0,q),r.set(2,1,D),r.set(2,2,U),r}},{key:"mmulStrassen",value:function(r){r=Ne.checkMatrix(r);var e=this.clone(),n=e.rows,o=e.columns,i=r.rows,s=r.columns;function a(r,e,n){var o=r.rows,i=r.columns;if(o===e&&i===n)return r;var s=t.zeros(e,n);return s=s.setSubMatrix(r,0,0)}o!==i&&console.warn("Multiplying ".concat(n," x ").concat(o," and ").concat(i," x ").concat(s," matrix: dimensions do not match."));var u=Math.max(n,i),c=Math.max(o,s);return function r(e,n,o,i){if(o<=512||i<=512)return e.mmul(n);o%2==1&&i%2==1?(e=a(e,o+1,i+1),n=a(n,o+1,i+1)):o%2==1?(e=a(e,o+1,i),n=a(n,o+1,i)):i%2==1&&(e=a(e,o,i+1),n=a(n,o,i+1));var s=parseInt(e.rows/2,10),u=parseInt(e.columns/2,10),c=e.subMatrix(0,s-1,0,u-1),f=n.subMatrix(0,s-1,0,u-1),h=e.subMatrix(0,s-1,u,e.columns-1),l=n.subMatrix(0,s-1,u,n.columns-1),v=e.subMatrix(s,e.rows-1,0,u-1),m=n.subMatrix(s,n.rows-1,0,u-1),g=e.subMatrix(s,e.rows-1,u,e.columns-1),p=n.subMatrix(s,n.rows-1,u,n.columns-1),d=r(t.add(c,g),t.add(f,p),s,u),w=r(t.add(v,g),f,s,u),y=r(c,t.sub(l,p),s,u),b=r(g,t.sub(m,f),s,u),M=r(t.add(c,h),p,s,u),x=r(t.sub(v,c),t.add(f,l),s,u),k=r(t.sub(h,g),t.add(m,p),s,u),E=t.add(d,b);E.sub(M),E.add(k);var S=t.add(y,M),_=t.add(w,b),j=t.sub(d,w);j.add(y),j.add(x);var R=t.zeros(2*E.rows,2*E.columns);return(R=(R=(R=(R=R.setSubMatrix(E,0,0)).setSubMatrix(S,E.rows,0)).setSubMatrix(_,0,E.columns)).setSubMatrix(j,E.rows,E.columns)).subMatrix(0,o-1,0,i-1)}(e=a(e,u,c),r=a(r,u,c),u,c)}},{key:"scaleRows",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new Ne(this.rows,this.columns),a=0;a<this.rows;a++){var u=this.getRow(a);u.length>0&&oe(u,{min:n,max:i,output:u}),s.setRow(a,u)}return s}},{key:"scaleColumns",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if("object"!==e(t))throw new TypeError("options must be an object");var r=t.min,n=void 0===r?0:r,o=t.max,i=void 0===o?1:o;if(!Number.isFinite(n))throw new TypeError("min must be a number");if(!Number.isFinite(i))throw new TypeError("max must be a number");if(n>=i)throw new RangeError("min must be smaller than max");for(var s=new Ne(this.rows,this.columns),a=0;a<this.columns;a++){var u=this.getColumn(a);u.length&&oe(u,{min:n,max:i,output:u}),s.setColumn(a,u)}return s}},{key:"flipRows",value:function(){for(var t=Math.ceil(this.columns/2),r=0;r<this.rows;r++)for(var e=0;e<t;e++){var n=this.get(r,e),o=this.get(r,this.columns-1-e);this.set(r,e,o),this.set(r,this.columns-1-e,n)}return this}},{key:"flipColumns",value:function(){for(var t=Math.ceil(this.rows/2),r=0;r<this.columns;r++)for(var e=0;e<t;e++){var n=this.get(e,r),o=this.get(this.rows-1-e,r);this.set(e,r,o),this.set(this.rows-1-e,r,n)}return this}},{key:"kroneckerProduct",value:function(t){t=Ne.checkMatrix(t);for(var r=this.rows,e=this.columns,n=t.rows,o=t.columns,i=new Ne(r*n,e*o),s=0;s<r;s++)for(var a=0;a<e;a++)for(var u=0;u<n;u++)for(var c=0;c<o;c++)i.set(n*s+u,o*a+c,this.get(s,a)*t.get(u,c));return i}},{key:"kroneckerSum",value:function(t){if(t=Ne.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");var r=this.rows,e=t.rows,n=this.kroneckerProduct(Ne.eye(e,e)),o=Ne.eye(r,r).kroneckerProduct(t);return n.add(o)}},{key:"transpose",value:function(){for(var t=new Ne(this.columns,this.rows),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(e,r,this.get(r,e));return t}},{key:"sortRows",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ie,r=0;r<this.rows;r++)this.setRow(r,this.getRow(r).sort(t));return this}},{key:"sortColumns",value:function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Ie,r=0;r<this.columns;r++)this.setColumn(r,this.getColumn(r).sort(t));return this}},{key:"subMatrix",value:function(t,r,e,n){me(this,t,r,e,n);for(var o=new Ne(r-t+1,n-e+1),i=t;i<=r;i++)for(var s=e;s<=n;s++)o.set(i-t,s-e,this.get(i,s));return o}},{key:"subMatrixRow",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.columns-1),r>e||r<0||r>=this.columns||e<0||e>=this.columns)throw new RangeError("Argument out of range");for(var n=new Ne(t.length,e-r+1),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.rows)throw new RangeError("Row index out of range: ".concat(t[o]));n.set(o,i-r,this.get(t[o],i))}return n}},{key:"subMatrixColumn",value:function(t,r,e){if(void 0===r&&(r=0),void 0===e&&(e=this.rows-1),r>e||r<0||r>=this.rows||e<0||e>=this.rows)throw new RangeError("Argument out of range");for(var n=new Ne(e-r+1,t.length),o=0;o<t.length;o++)for(var i=r;i<=e;i++){if(t[o]<0||t[o]>=this.columns)throw new RangeError("Column index out of range: ".concat(t[o]));n.set(i-r,o,this.get(i,t[o]))}return n}},{key:"setSubMatrix",value:function(t,r,e){if((t=Ne.checkMatrix(t)).isEmpty())return this;me(this,r,r+t.rows-1,e,e+t.columns-1);for(var n=0;n<t.rows;n++)for(var o=0;o<t.columns;o++)this.set(r+n,e+o,t.get(n,o));return this}},{key:"selection",value:function(t,r){!function(t,r){if(!re(r))throw new TypeError("row indices must be an array");for(var e=0;e<r.length;e++)if(r[e]<0||r[e]>=t.rows)throw new RangeError("row indices are out of range")}(this,t),function(t,r){if(!re(r))throw new TypeError("column indices must be an array");for(var e=0;e<r.length;e++)if(r[e]<0||r[e]>=t.columns)throw new RangeError("column indices are out of range")}(this,r);for(var e=new Ne(t.length,r.length),n=0;n<t.length;n++)for(var o=t[n],i=0;i<r.length;i++){var s=r[i];e.set(n,i,this.get(o,s))}return e}},{key:"trace",value:function(){for(var t=Math.min(this.rows,this.columns),r=0,e=0;e<t;e++)r+=this.get(e,e);return r}},{key:"clone",value:function(){for(var t=new Ne(this.rows,this.columns),r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)t.set(r,e,this.get(r,e));return t}},{key:"sum",value:function(t){switch(t){case"row":return function(t){for(var r=ge(t.rows),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]+=t.get(e,n);return r}(this);case"column":return function(t){for(var r=ge(t.columns),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]+=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=0,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r+=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"product",value:function(t){switch(t){case"row":return function(t){for(var r=ge(t.rows,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[e]*=t.get(e,n);return r}(this);case"column":return function(t){for(var r=ge(t.columns,1),e=0;e<t.rows;++e)for(var n=0;n<t.columns;++n)r[n]*=t.get(e,n);return r}(this);case void 0:return function(t){for(var r=1,e=0;e<t.rows;e++)for(var n=0;n<t.columns;n++)r*=t.get(e,n);return r}(this);default:throw new Error("invalid option: ".concat(t))}}},{key:"mean",value:function(t){var r=this.sum(t);switch(t){case"row":for(var e=0;e<this.rows;e++)r[e]/=this.columns;return r;case"column":for(var n=0;n<this.columns;n++)r[n]/=this.rows;return r;case void 0:return r/this.size;default:throw new Error("invalid option: ".concat(t))}}},{key:"variance",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.unbiased,i=void 0===o||o,s=n.mean,a=void 0===s?this.mean(t):s;if("boolean"!=typeof i)throw new TypeError("unbiased must be a boolean");switch(t){case"row":if(!re(a))throw new TypeError("mean must be an array");return we(this,i,a);case"column":if(!re(a))throw new TypeError("mean must be an array");return ye(this,i,a);case void 0:if("number"!=typeof a)throw new TypeError("mean must be a number");return be(this,i,a);default:throw new Error("invalid option: ".concat(t))}}},{key:"standardDeviation",value:function(t,r){"object"===e(t)&&(r=t,t=void 0);var n=this.variance(t,r);if(void 0===t)return Math.sqrt(n);for(var o=0;o<n.length;o++)n[o]=Math.sqrt(n[o]);return n}},{key:"center",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r,o=n.center,i=void 0===o?this.mean(t):o;switch(t){case"row":if(!re(i))throw new TypeError("center must be an array");return Me(this,i),this;case"column":if(!re(i))throw new TypeError("center must be an array");return xe(this,i),this;case void 0:if("number"!=typeof i)throw new TypeError("center must be a number");return ke(this,i),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"scale",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if("object"===e(t)&&(r=t,t=void 0),"object"!==e(r))throw new TypeError("options must be an object");var n=r.scale;switch(t){case"row":if(void 0===n)n=Ee(this);else if(!re(n))throw new TypeError("scale must be an array");return Se(this,n),this;case"column":if(void 0===n)n=_e(this);else if(!re(n))throw new TypeError("scale must be an array");return je(this,n),this;case void 0:if(void 0===n)n=Re(this);else if("number"!=typeof n)throw new TypeError("scale must be a number");return Ae(this,n),this;default:throw new Error("invalid option: ".concat(t))}}},{key:"toString",value:function(t){return ae(this,t)}}],[{key:"from1DArray",value:function(t,r,e){if(t*r!==e.length)throw new RangeError("data length does not match given dimensions");for(var n=new Ne(t,r),o=0;o<t;o++)for(var i=0;i<r;i++)n.set(o,i,e[o*r+i]);return n}},{key:"rowVector",value:function(t){for(var r=new Ne(1,t.length),e=0;e<t.length;e++)r.set(0,e,t[e]);return r}},{key:"columnVector",value:function(t){for(var r=new Ne(t.length,1),e=0;e<t.length;e++)r.set(e,0,t[e]);return r}},{key:"zeros",value:function(t,r){return new Ne(t,r)}},{key:"ones",value:function(t,r){return new Ne(t,r).fill(1)}},{key:"rand",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");for(var o=n.random,i=void 0===o?Math.random:o,s=new Ne(t,r),a=0;a<t;a++)for(var u=0;u<r;u++)s.set(a,u,i());return s}},{key:"randInt",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("object"!==e(n))throw new TypeError("options must be an object");var o=n.min,i=void 0===o?0:o,s=n.max,a=void 0===s?1e3:s,u=n.random,c=void 0===u?Math.random:u;if(!Number.isInteger(i))throw new TypeError("min must be an integer");if(!Number.isInteger(a))throw new TypeError("max must be an integer");if(i>=a)throw new RangeError("min must be smaller than max");for(var f=a-i,h=new Ne(t,r),l=0;l<t;l++)for(var v=0;v<r;v++){var m=i+Math.round(c()*f);h.set(l,v,m)}return h}},{key:"eye",value:function(t,r,e){void 0===r&&(r=t),void 0===e&&(e=1);for(var n=Math.min(t,r),o=this.zeros(t,r),i=0;i<n;i++)o.set(i,i,e);return o}},{key:"diag",value:function(t,r,e){var n=t.length;void 0===r&&(r=n),void 0===e&&(e=r);for(var o=Math.min(n,r,e),i=this.zeros(r,e),s=0;s<o;s++)i.set(s,s,t[s]);return i}},{key:"min",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new Ne(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.min(t.get(i,s),r.get(i,s)));return o}},{key:"max",value:function(t,r){t=this.checkMatrix(t),r=this.checkMatrix(r);for(var e=t.rows,n=t.columns,o=new this(e,n),i=0;i<e;i++)for(var s=0;s<n;s++)o.set(i,s,Math.max(t.get(i,s),r.get(i,s)));return o}},{key:"checkMatrix",value:function(r){return t.isMatrix(r)?r:new Ne(r)}},{key:"isMatrix",value:function(t){return null!=t&&"Matrix"===t.klass}}]),t}();function Ie(t,r){return t-r}Ce.prototype.klass="Matrix","undefined"!=typeof Symbol&&(Ce.prototype[Symbol.for("nodejs.util.inspect.custom")]=function(){return ae(this)}),Ce.random=Ce.rand,Ce.randomInt=Ce.randInt,Ce.diagonal=Ce.diag,Ce.prototype.diagonal=Ce.prototype.diag,Ce.identity=Ce.eye,Ce.prototype.negate=Ce.prototype.neg,Ce.prototype.tensorProduct=Ce.prototype.kroneckerProduct;var Ne=function(t){Zr(e,t);var r=Oe(e);function e(t,n){var o;if(Wr(this,e),o=r.call(this),e.isMatrix(t))return Hr(o,t.clone());if(Number.isInteger(t)&&t>=0){if(o.data=[],!(Number.isInteger(n)&&n>=0))throw new TypeError("nColumns must be a positive integer");for(var i=0;i<t;i++)o.data.push(new Float64Array(n))}else{if(!re(t))throw new TypeError("First argument must be a positive number or an array");var s=t;if("number"!=typeof(n=(t=s.length)?s[0].length:0))throw new TypeError("Data must be a 2D array with at least one element");o.data=[];for(var a=0;a<t;a++){if(s[a].length!==n)throw new RangeError("Inconsistent array dimensions");o.data.push(Float64Array.from(s[a]))}}return o.rows=t,o.columns=n,o}return Yr(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}},{key:"removeRow",value:function(t){return fe(this,t),this.data.splice(t,1),this.rows-=1,this}},{key:"addRow",value:function(t,r){return void 0===r&&(r=t,t=this.rows),fe(this,t,!0),r=Float64Array.from(le(this,r)),this.data.splice(t,0,r),this.rows+=1,this}},{key:"removeColumn",value:function(t){he(this,t);for(var r=0;r<this.rows;r++){for(var e=new Float64Array(this.columns-1),n=0;n<t;n++)e[n]=this.data[r][n];for(var o=t+1;o<this.columns;o++)e[o-1]=this.data[r][o];this.data[r]=e}return this.columns-=1,this}},{key:"addColumn",value:function(t,r){void 0===r&&(r=t,t=this.columns),he(this,t,!0),r=ve(this,r);for(var e=0;e<this.rows;e++){for(var n=new Float64Array(this.columns+1),o=0;o<t;o++)n[o]=this.data[e][o];for(n[o++]=r[e];o<this.columns+1;o++)n[o]=this.data[e][o-1];this.data[e]=n}return this.columns+=1,this}}]),e}(Ce);function Fe(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}function Te(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}!function(t,r){t.prototype.add=function(t){return"number"==typeof t?this.addS(t):this.addM(t)},t.prototype.addS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)+t);return this},t.prototype.addM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)+t.get(e,n));return this},t.add=function(t,e){return new r(t).add(e)},t.prototype.sub=function(t){return"number"==typeof t?this.subS(t):this.subM(t)},t.prototype.subS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)-t);return this},t.prototype.subM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)-t.get(e,n));return this},t.sub=function(t,e){return new r(t).sub(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)*t);return this},t.prototype.mulM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)*t.get(e,n));return this},t.mul=function(t,e){return new r(t).mul(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)/t);return this},t.prototype.divM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)/t.get(e,n));return this},t.div=function(t,e){return new r(t).div(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)%t);return this},t.prototype.modM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)%t.get(e,n));return this},t.mod=function(t,e){return new r(t).mod(e)},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(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)&t);return this},t.prototype.andM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)&t.get(e,n));return this},t.and=function(t,e){return new r(t).and(e)},t.prototype.or=function(t){return"number"==typeof t?this.orS(t):this.orM(t)},t.prototype.orS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)|t);return this},t.prototype.orM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)|t.get(e,n));return this},t.or=function(t,e){return new r(t).or(e)},t.prototype.xor=function(t){return"number"==typeof t?this.xorS(t):this.xorM(t)},t.prototype.xorS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)^t);return this},t.prototype.xorM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)^t.get(e,n));return this},t.xor=function(t,e){return new r(t).xor(e)},t.prototype.leftShift=function(t){return"number"==typeof t?this.leftShiftS(t):this.leftShiftM(t)},t.prototype.leftShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)<<t);return this},t.prototype.leftShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)<<t.get(e,n));return this},t.leftShift=function(t,e){return new r(t).leftShift(e)},t.prototype.signPropagatingRightShift=function(t){return"number"==typeof t?this.signPropagatingRightShiftS(t):this.signPropagatingRightShiftM(t)},t.prototype.signPropagatingRightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>t);return this},t.prototype.signPropagatingRightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>t.get(e,n));return this},t.signPropagatingRightShift=function(t,e){return new r(t).signPropagatingRightShift(e)},t.prototype.rightShift=function(t){return"number"==typeof t?this.rightShiftS(t):this.rightShiftM(t)},t.prototype.rightShiftS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,this.get(r,e)>>>t);return this},t.prototype.rightShiftM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,this.get(e,n)>>>t.get(e,n));return this},t.rightShift=function(t,e){return new r(t).rightShift(e)},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(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,~this.get(t,r));return this},t.not=function(t){return new r(t).not()},t.prototype.abs=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.abs(this.get(t,r)));return this},t.abs=function(t){return new r(t).abs()},t.prototype.acos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acos(this.get(t,r)));return this},t.acos=function(t){return new r(t).acos()},t.prototype.acosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.acosh(this.get(t,r)));return this},t.acosh=function(t){return new r(t).acosh()},t.prototype.asin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asin(this.get(t,r)));return this},t.asin=function(t){return new r(t).asin()},t.prototype.asinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.asinh(this.get(t,r)));return this},t.asinh=function(t){return new r(t).asinh()},t.prototype.atan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atan(this.get(t,r)));return this},t.atan=function(t){return new r(t).atan()},t.prototype.atanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.atanh(this.get(t,r)));return this},t.atanh=function(t){return new r(t).atanh()},t.prototype.cbrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cbrt(this.get(t,r)));return this},t.cbrt=function(t){return new r(t).cbrt()},t.prototype.ceil=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.ceil(this.get(t,r)));return this},t.ceil=function(t){return new r(t).ceil()},t.prototype.clz32=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.clz32(this.get(t,r)));return this},t.clz32=function(t){return new r(t).clz32()},t.prototype.cos=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cos(this.get(t,r)));return this},t.cos=function(t){return new r(t).cos()},t.prototype.cosh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.cosh(this.get(t,r)));return this},t.cosh=function(t){return new r(t).cosh()},t.prototype.exp=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.exp(this.get(t,r)));return this},t.exp=function(t){return new r(t).exp()},t.prototype.expm1=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.expm1(this.get(t,r)));return this},t.expm1=function(t){return new r(t).expm1()},t.prototype.floor=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.floor(this.get(t,r)));return this},t.floor=function(t){return new r(t).floor()},t.prototype.fround=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.fround(this.get(t,r)));return this},t.fround=function(t){return new r(t).fround()},t.prototype.log=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log(this.get(t,r)));return this},t.log=function(t){return new r(t).log()},t.prototype.log1p=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log1p(this.get(t,r)));return this},t.log1p=function(t){return new r(t).log1p()},t.prototype.log10=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log10(this.get(t,r)));return this},t.log10=function(t){return new r(t).log10()},t.prototype.log2=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.log2(this.get(t,r)));return this},t.log2=function(t){return new r(t).log2()},t.prototype.round=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.round(this.get(t,r)));return this},t.round=function(t){return new r(t).round()},t.prototype.sign=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sign(this.get(t,r)));return this},t.sign=function(t){return new r(t).sign()},t.prototype.sin=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sin(this.get(t,r)));return this},t.sin=function(t){return new r(t).sin()},t.prototype.sinh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sinh(this.get(t,r)));return this},t.sinh=function(t){return new r(t).sinh()},t.prototype.sqrt=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.sqrt(this.get(t,r)));return this},t.sqrt=function(t){return new r(t).sqrt()},t.prototype.tan=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tan(this.get(t,r)));return this},t.tan=function(t){return new r(t).tan()},t.prototype.tanh=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.tanh(this.get(t,r)));return this},t.tanh=function(t){return new r(t).tanh()},t.prototype.trunc=function(){for(var t=0;t<this.rows;t++)for(var r=0;r<this.columns;r++)this.set(t,r,Math.trunc(this.get(t,r)));return this},t.trunc=function(t){return new r(t).trunc()},t.pow=function(t,e){return new r(t).pow(e)},t.prototype.pow=function(t){return"number"==typeof t?this.powS(t):this.powM(t)},t.prototype.powS=function(t){for(var r=0;r<this.rows;r++)for(var e=0;e<this.columns;e++)this.set(r,e,Math.pow(this.get(r,e),t));return this},t.prototype.powM=function(t){if(t=r.checkMatrix(t),this.rows!==t.rows||this.columns!==t.columns)throw new RangeError("Matrices dimensions must be equal");for(var e=0;e<this.rows;e++)for(var n=0;n<this.columns;n++)this.set(e,n,Math.pow(this.get(e,n),t.get(e,n)));return this}}(Ce,Ne);var Pe=function(t){Zr(e,t);var r=Te(e);function e(t){return Wr(this,e),r.call(this,t,t.columns,t.rows)}return Yr(e,[{key:"set",value:function(t,r,e){return this.matrix.set(r,t,e),this}},{key:"get",value:function(t,r){return this.matrix.get(r,t)}}]),e}(function(t){Zr(e,t);var r=Fe(e);function e(t,n,o){var i;return Wr(this,e),(i=r.call(this)).matrix=t,i.rows=n,i.columns=o,i}return Yr(e)}(Ce));function ze(t){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,n=Qr(t);if(r){var o=Qr(this).constructor;e=Reflect.construct(n,arguments,o)}else e=n.apply(this,arguments);return Hr(this,e)}}var Le=function(t){Zr(e,t);var r=ze(e);function e(t){var n;return Wr(this,e),(n=r.call(this)).data=t,n.rows=t.length,n.columns=t[0].length,n}return Yr(e,[{key:"set",value:function(t,r,e){return this.data[t][r]=e,this}},{key:"get",value:function(t,r){return this.data[t][r]}}]),e}(Ce);function Ve(t,r){var e=0;return Math.abs(t)>Math.abs(r)?(e=r/t,Math.abs(t)*Math.sqrt(1+e*e)):0!==r?(e=t/r,Math.abs(r)*Math.sqrt(1+e*e)):0}var qe=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(Wr(this,t),(r=Le.checkMatrix(r)).isEmpty())throw new Error("Matrix must be non-empty");var n,o=r.rows,i=r.columns,s=e.computeLeftSingularVectors,a=void 0===s||s,u=e.computeRightSingularVectors,c=void 0===u||u,f=e.autoTranspose,h=void 0!==f&&f,l=Boolean(a),v=Boolean(c),m=!1;if(o<i)if(h){o=(n=r.transpose()).rows,i=n.columns,m=!0;var g=l;l=v,v=g}else n=r.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else n=r.clone();for(var p=Math.min(o,i),d=Math.min(o+1,i),w=new Float64Array(d),y=new Ne(o,p),b=new Ne(i,i),M=new Float64Array(i),x=new Float64Array(o),k=new Float64Array(d),E=0;E<d;E++)k[E]=E;for(var S=Math.min(o-1,i),_=Math.max(0,Math.min(i-2,o)),j=Math.max(S,_),R=0;R<j;R++){if(R<S){w[R]=0;for(var A=R;A<o;A++)w[R]=Ve(w[R],n.get(A,R));if(0!==w[R]){n.get(R,R)<0&&(w[R]=-w[R]);for(var O=R;O<o;O++)n.set(O,R,n.get(O,R)/w[R]);n.set(R,R,n.get(R,R)+1)}w[R]=-w[R]}for(var C=R+1;C<i;C++){if(R<S&&0!==w[R]){for(var I=0,N=R;N<o;N++)I+=n.get(N,R)*n.get(N,C);I=-I/n.get(R,R);for(var F=R;F<o;F++)n.set(F,C,n.get(F,C)+I*n.get(F,R))}M[C]=n.get(R,C)}if(l&&R<S)for(var T=R;T<o;T++)y.set(T,R,n.get(T,R));if(R<_){M[R]=0;for(var P=R+1;P<i;P++)M[R]=Ve(M[R],M[P]);if(0!==M[R]){M[R+1]<0&&(M[R]=0-M[R]);for(var z=R+1;z<i;z++)M[z]/=M[R];M[R+1]+=1}if(M[R]=-M[R],R+1<o&&0!==M[R]){for(var L=R+1;L<o;L++)x[L]=0;for(var V=R+1;V<o;V++)for(var q=R+1;q<i;q++)x[V]+=M[q]*n.get(V,q);for(var D=R+1;D<i;D++)for(var U=-M[D]/M[R+1],B=R+1;B<o;B++)n.set(B,D,n.get(B,D)+U*x[B])}if(v)for(var G=R+1;G<i;G++)b.set(G,R,M[G])}}var $=Math.min(i,o+1);if(S<i&&(w[S]=n.get(S,S)),o<$&&(w[$-1]=0),_+1<$&&(M[_]=n.get(_,$-1)),M[$-1]=0,l){for(var K=S;K<p;K++){for(var W=0;W<o;W++)y.set(W,K,0);y.set(K,K,1)}for(var X=S-1;X>=0;X--)if(0!==w[X]){for(var Y=X+1;Y<p;Y++){for(var J=0,Z=X;Z<o;Z++)J+=y.get(Z,X)*y.get(Z,Y);J=-J/y.get(X,X);for(var H=X;H<o;H++)y.set(H,Y,y.get(H,Y)+J*y.get(H,X))}for(var Q=X;Q<o;Q++)y.set(Q,X,-y.get(Q,X));y.set(X,X,1+y.get(X,X));for(var tt=0;tt<X-1;tt++)y.set(tt,X,0)}else{for(var rt=0;rt<o;rt++)y.set(rt,X,0);y.set(X,X,1)}}if(v)for(var et=i-1;et>=0;et--){if(et<_&&0!==M[et])for(var nt=et+1;nt<i;nt++){for(var ot=0,it=et+1;it<i;it++)ot+=b.get(it,et)*b.get(it,nt);ot=-ot/b.get(et+1,et);for(var st=et+1;st<i;st++)b.set(st,nt,b.get(st,nt)+ot*b.get(st,et))}for(var at=0;at<i;at++)b.set(at,et,0);b.set(et,et,1)}for(var ut=$-1,ct=Number.EPSILON;$>0;){var ft=void 0,ht=void 0;for(ft=$-2;ft>=-1&&-1!==ft;ft--){var lt=Number.MIN_VALUE+ct*Math.abs(w[ft]+Math.abs(w[ft+1]));if(Math.abs(M[ft])<=lt||Number.isNaN(M[ft])){M[ft]=0;break}}if(ft===$-2)ht=4;else{var vt=void 0;for(vt=$-1;vt>=ft&&vt!==ft;vt--){var mt=(vt!==$?Math.abs(M[vt]):0)+(vt!==ft+1?Math.abs(M[vt-1]):0);if(Math.abs(w[vt])<=ct*mt){w[vt]=0;break}}vt===ft?ht=3:vt===$-1?ht=1:(ht=2,ft=vt)}switch(ft++,ht){case 1:var gt=M[$-2];M[$-2]=0;for(var pt=$-2;pt>=ft;pt--){var dt=Ve(w[pt],gt),wt=w[pt]/dt,yt=gt/dt;if(w[pt]=dt,pt!==ft&&(gt=-yt*M[pt-1],M[pt-1]=wt*M[pt-1]),v)for(var bt=0;bt<i;bt++)dt=wt*b.get(bt,pt)+yt*b.get(bt,$-1),b.set(bt,$-1,-yt*b.get(bt,pt)+wt*b.get(bt,$-1)),b.set(bt,pt,dt)}break;case 2:var Mt=M[ft-1];M[ft-1]=0;for(var xt=ft;xt<$;xt++){var kt=Ve(w[xt],Mt),Et=w[xt]/kt,St=Mt/kt;if(w[xt]=kt,Mt=-St*M[xt],M[xt]=Et*M[xt],l)for(var _t=0;_t<o;_t++)kt=Et*y.get(_t,xt)+St*y.get(_t,ft-1),y.set(_t,ft-1,-St*y.get(_t,xt)+Et*y.get(_t,ft-1)),y.set(_t,xt,kt)}break;case 3:var jt=Math.max(Math.abs(w[$-1]),Math.abs(w[$-2]),Math.abs(M[$-2]),Math.abs(w[ft]),Math.abs(M[ft])),Rt=w[$-1]/jt,At=w[$-2]/jt,Ot=M[$-2]/jt,Ct=w[ft]/jt,It=M[ft]/jt,Nt=((At+Rt)*(At-Rt)+Ot*Ot)/2,Ft=Rt*Ot*(Rt*Ot),Tt=0;0===Nt&&0===Ft||(Tt=Ft/(Nt+(Tt=Nt<0?0-Math.sqrt(Nt*Nt+Ft):Math.sqrt(Nt*Nt+Ft))));for(var Pt=(Ct+Rt)*(Ct-Rt)+Tt,zt=Ct*It,Lt=ft;Lt<$-1;Lt++){var Vt=Ve(Pt,zt);0===Vt&&(Vt=Number.MIN_VALUE);var qt=Pt/Vt,Dt=zt/Vt;if(Lt!==ft&&(M[Lt-1]=Vt),Pt=qt*w[Lt]+Dt*M[Lt],M[Lt]=qt*M[Lt]-Dt*w[Lt],zt=Dt*w[Lt+1],w[Lt+1]=qt*w[Lt+1],v)for(var Ut=0;Ut<i;Ut++)Vt=qt*b.get(Ut,Lt)+Dt*b.get(Ut,Lt+1),b.set(Ut,Lt+1,-Dt*b.get(Ut,Lt)+qt*b.get(Ut,Lt+1)),b.set(Ut,Lt,Vt);if(0===(Vt=Ve(Pt,zt))&&(Vt=Number.MIN_VALUE),qt=Pt/Vt,Dt=zt/Vt,w[Lt]=Vt,Pt=qt*M[Lt]+Dt*w[Lt+1],w[Lt+1]=-Dt*M[Lt]+qt*w[Lt+1],zt=Dt*M[Lt+1],M[Lt+1]=qt*M[Lt+1],l&&Lt<o-1)for(var Bt=0;Bt<o;Bt++)Vt=qt*y.get(Bt,Lt)+Dt*y.get(Bt,Lt+1),y.set(Bt,Lt+1,-Dt*y.get(Bt,Lt)+qt*y.get(Bt,Lt+1)),y.set(Bt,Lt,Vt)}M[$-2]=Pt;break;case 4:if(w[ft]<=0&&(w[ft]=w[ft]<0?-w[ft]:0,v))for(var Gt=0;Gt<=ut;Gt++)b.set(Gt,ft,-b.get(Gt,ft));for(;ft<ut&&!(w[ft]>=w[ft+1]);){var $t=w[ft];if(w[ft]=w[ft+1],w[ft+1]=$t,v&&ft<i-1)for(var Kt=0;Kt<i;Kt++)$t=b.get(Kt,ft+1),b.set(Kt,ft+1,b.get(Kt,ft)),b.set(Kt,ft,$t);if(l&&ft<o-1)for(var Wt=0;Wt<o;Wt++)$t=y.get(Wt,ft+1),y.set(Wt,ft+1,y.get(Wt,ft)),y.set(Wt,ft,$t);ft++}$--}}if(m){var Xt=b;b=y,y=Xt}this.m=o,this.n=i,this.s=w,this.U=y,this.V=b}return Yr(t,[{key:"solve",value:function(t){for(var r=t,e=this.threshold,n=this.s.length,o=Ne.zeros(n,n),i=0;i<n;i++)Math.abs(this.s[i])<=e?o.set(i,i,0):o.set(i,i,1/this.s[i]);for(var s=this.U,a=this.rightSingularVectors,u=a.mmul(o),c=a.rows,f=s.rows,h=Ne.zeros(c,f),l=0;l<c;l++)for(var v=0;v<f;v++){for(var m=0,g=0;g<n;g++)m+=u.get(l,g)*s.get(v,g);h.set(l,v,m)}return h.mmul(r)}},{key:"solveForDiagonal",value:function(t){return this.solve(Ne.diag(t))}},{key:"inverse",value:function(){for(var t=this.V,r=this.threshold,e=t.rows,n=t.columns,o=new Ne(e,this.s.length),i=0;i<e;i++)for(var s=0;s<n;s++)Math.abs(this.s[s])>r&&o.set(i,s,t.get(i,s)/this.s[s]);for(var a=this.U,u=a.rows,c=a.columns,f=new Ne(e,u),h=0;h<e;h++)for(var l=0;l<u;l++){for(var v=0,m=0;m<c;m++)v+=o.get(h,m)*a.get(l,m);f.set(h,l,v)}return f}},{key:"condition",get:function(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}},{key:"norm2",get:function(){return this.s[0]}},{key:"rank",get:function(){for(var t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,r=0,e=this.s,n=0,o=e.length;n<o;n++)e[n]>t&&r++;return r}},{key:"diagonal",get:function(){return Array.from(this.s)}},{key:"threshold",get:function(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}},{key:"leftSingularVectors",get:function(){return this.U}},{key:"rightSingularVectors",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){return Ne.diag(this.s)}}]),t}(),De=function(){function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Wr(this,t);var n=e.assumeSymmetric,o=void 0!==n&&n;if(!(r=Le.checkMatrix(r)).isSquare())throw new Error("Matrix is not a square matrix");if(r.isEmpty())throw new Error("Matrix must be non-empty");var i,s,a=r.columns,u=new Ne(a,a),c=new Float64Array(a),f=new Float64Array(a),h=r;if(!!o||r.isSymmetric()){for(i=0;i<a;i++)for(s=0;s<a;s++)u.set(i,s,h.get(i,s));Ue(a,f,c,u),Be(a,f,c,u)}else{var l=new Ne(a,a),v=new Float64Array(a);for(s=0;s<a;s++)for(i=0;i<a;i++)l.set(i,s,h.get(i,s));Ge(a,l,v,u),$e(a,f,c,u,l)}this.n=a,this.e=f,this.d=c,this.V=u}return Yr(t,[{key:"realEigenvalues",get:function(){return Array.from(this.d)}},{key:"imaginaryEigenvalues",get:function(){return Array.from(this.e)}},{key:"eigenvectorMatrix",get:function(){return this.V}},{key:"diagonalMatrix",get:function(){var t,r,e=this.n,n=this.e,o=this.d,i=new Ne(e,e);for(t=0;t<e;t++){for(r=0;r<e;r++)i.set(t,r,0);i.set(t,t,o[t]),n[t]>0?i.set(t,t+1,n[t]):n[t]<0&&i.set(t,t-1,n[t])}return i}}]),t}();function Ue(t,r,e,n){var o,i,s,a,u,c,f,h;for(u=0;u<t;u++)e[u]=n.get(t-1,u);for(a=t-1;a>0;a--){for(h=0,s=0,c=0;c<a;c++)h+=Math.abs(e[c]);if(0===h)for(r[a]=e[a-1],u=0;u<a;u++)e[u]=n.get(a-1,u),n.set(a,u,0),n.set(u,a,0);else{for(c=0;c<a;c++)e[c]/=h,s+=e[c]*e[c];for(o=e[a-1],i=Math.sqrt(s),o>0&&(i=-i),r[a]=h*i,s-=o*i,e[a-1]=o-i,u=0;u<a;u++)r[u]=0;for(u=0;u<a;u++){for(o=e[u],n.set(u,a,o),i=r[u]+n.get(u,u)*o,c=u+1;c<=a-1;c++)i+=n.get(c,u)*e[c],r[c]+=n.get(c,u)*o;r[u]=i}for(o=0,u=0;u<a;u++)r[u]/=s,o+=r[u]*e[u];for(f=o/(s+s),u=0;u<a;u++)r[u]-=f*e[u];for(u=0;u<a;u++){for(o=e[u],i=r[u],c=u;c<=a-1;c++)n.set(c,u,n.get(c,u)-(o*r[c]+i*e[c]));e[u]=n.get(a-1,u),n.set(a,u,0)}}e[a]=s}for(a=0;a<t-1;a++){if(n.set(t-1,a,n.get(a,a)),n.set(a,a,1),0!==(s=e[a+1])){for(c=0;c<=a;c++)e[c]=n.get(c,a+1)/s;for(u=0;u<=a;u++){for(i=0,c=0;c<=a;c++)i+=n.get(c,a+1)*n.get(c,u);for(c=0;c<=a;c++)n.set(c,u,n.get(c,u)-i*e[c])}}for(c=0;c<=a;c++)n.set(c,a+1,0)}for(u=0;u<t;u++)e[u]=n.get(t-1,u),n.set(t-1,u,0);n.set(t-1,t-1,1),r[0]=0}function Be(t,r,e,n){var o,i,s,a,u,c,f,h,l,v,m,g,p,d,w,y;for(s=1;s<t;s++)r[s-1]=r[s];r[t-1]=0;var b=0,M=0,x=Number.EPSILON;for(c=0;c<t;c++){for(M=Math.max(M,Math.abs(e[c])+Math.abs(r[c])),f=c;f<t&&!(Math.abs(r[f])<=x*M);)f++;if(f>c)do{for(o=e[c],l=Ve(h=(e[c+1]-o)/(2*r[c]),1),h<0&&(l=-l),e[c]=r[c]/(h+l),e[c+1]=r[c]*(h+l),v=e[c+1],i=o-e[c],s=c+2;s<t;s++)e[s]-=i;for(b+=i,h=e[f],g=m=1,p=m,d=r[c+1],w=0,y=0,s=f-1;s>=c;s--)for(p=g,g=m,y=w,o=m*r[s],i=m*h,l=Ve(h,r[s]),r[s+1]=w*l,w=r[s]/l,h=(m=h/l)*e[s]-w*o,e[s+1]=i+w*(m*o+w*e[s]),u=0;u<t;u++)i=n.get(u,s+1),n.set(u,s+1,w*n.get(u,s)+m*i),n.set(u,s,m*n.get(u,s)-w*i);h=-w*y*p*d*r[c]/v,r[c]=w*h,e[c]=m*h}while(Math.abs(r[c])>x*M);e[c]=e[c]+b,r[c]=0}for(s=0;s<t-1;s++){for(u=s,h=e[s],a=s+1;a<t;a++)e[a]<h&&(u=a,h=e[a]);if(u!==s)for(e[u]=e[s],e[s]=h,a=0;a<t;a++)h=n.get(a,s),n.set(a,s,n.get(a,u)),n.set(a,u,h)}}function Ge(t,r,e,n){var o,i,s,a,u,c,f,h=t-1;for(c=1;c<=h-1;c++){for(f=0,a=c;a<=h;a++)f+=Math.abs(r.get(a,c-1));if(0!==f){for(s=0,a=h;a>=c;a--)e[a]=r.get(a,c-1)/f,s+=e[a]*e[a];for(i=Math.sqrt(s),e[c]>0&&(i=-i),s-=e[c]*i,e[c]=e[c]-i,u=c;u<t;u++){for(o=0,a=h;a>=c;a--)o+=e[a]*r.get(a,u);for(o/=s,a=c;a<=h;a++)r.set(a,u,r.get(a,u)-o*e[a])}for(a=0;a<=h;a++){for(o=0,u=h;u>=c;u--)o+=e[u]*r.get(a,u);for(o/=s,u=c;u<=h;u++)r.set(a,u,r.get(a,u)-o*e[u])}e[c]=f*e[c],r.set(c,c-1,f*i)}}for(a=0;a<t;a++)for(u=0;u<t;u++)n.set(a,u,a===u?1:0);for(c=h-1;c>=1;c--)if(0!==r.get(c,c-1)){for(a=c+1;a<=h;a++)e[a]=r.get(a,c-1);for(u=c;u<=h;u++){for(i=0,a=c;a<=h;a++)i+=e[a]*n.get(a,u);for(i=i/e[c]/r.get(c,c-1),a=c;a<=h;a++)n.set(a,u,n.get(a,u)+i*e[a])}}}function $e(t,r,e,n,o){var i,s,a,u,c,f,h,l,v,m,g,p,d,w,y,b=t-1,M=t-1,x=Number.EPSILON,k=0,E=0,S=0,_=0,j=0,R=0,A=0,O=0;for(i=0;i<t;i++)for((i<0||i>M)&&(e[i]=o.get(i,i),r[i]=0),s=Math.max(i-1,0);s<t;s++)E+=Math.abs(o.get(i,s));for(;b>=0;){for(u=b;u>0&&(0===(R=Math.abs(o.get(u-1,u-1))+Math.abs(o.get(u,u)))&&(R=E),!(Math.abs(o.get(u,u-1))<x*R));)u--;if(u===b)o.set(b,b,o.get(b,b)+k),e[b]=o.get(b,b),r[b]=0,b--,O=0;else if(u===b-1){if(h=o.get(b,b-1)*o.get(b-1,b),_=(S=(o.get(b-1,b-1)-o.get(b,b))/2)*S+h,A=Math.sqrt(Math.abs(_)),o.set(b,b,o.get(b,b)+k),o.set(b-1,b-1,o.get(b-1,b-1)+k),l=o.get(b,b),_>=0){for(A=S>=0?S+A:S-A,e[b-1]=l+A,e[b]=e[b-1],0!==A&&(e[b]=l-h/A),r[b-1]=0,r[b]=0,S=(l=o.get(b,b-1))/(R=Math.abs(l)+Math.abs(A)),_=A/R,S/=j=Math.sqrt(S*S+_*_),_/=j,s=b-1;s<t;s++)A=o.get(b-1,s),o.set(b-1,s,_*A+S*o.get(b,s)),o.set(b,s,_*o.get(b,s)-S*A);for(i=0;i<=b;i++)A=o.get(i,b-1),o.set(i,b-1,_*A+S*o.get(i,b)),o.set(i,b,_*o.get(i,b)-S*A);for(i=0;i<=M;i++)A=n.get(i,b-1),n.set(i,b-1,_*A+S*n.get(i,b)),n.set(i,b,_*n.get(i,b)-S*A)}else e[b-1]=l+S,e[b]=l+S,r[b-1]=A,r[b]=-A;b-=2,O=0}else{if(l=o.get(b,b),v=0,h=0,u<b&&(v=o.get(b-1,b-1),h=o.get(b,b-1)*o.get(b-1,b)),10===O){for(k+=l,i=0;i<=b;i++)o.set(i,i,o.get(i,i)-l);l=v=.75*(R=Math.abs(o.get(b,b-1))+Math.abs(o.get(b-1,b-2))),h=-.4375*R*R}if(30===O&&(R=(R=(v-l)/2)*R+h)>0){for(R=Math.sqrt(R),v<l&&(R=-R),R=l-h/((v-l)/2+R),i=0;i<=b;i++)o.set(i,i,o.get(i,i)-R);k+=R,l=v=h=.964}for(O+=1,c=b-2;c>=u&&(S=((j=l-(A=o.get(c,c)))*(R=v-A)-h)/o.get(c+1,c)+o.get(c,c+1),_=o.get(c+1,c+1)-A-j-R,j=o.get(c+2,c+1),S/=R=Math.abs(S)+Math.abs(_)+Math.abs(j),_/=R,j/=R,c!==u)&&!(Math.abs(o.get(c,c-1))*(Math.abs(_)+Math.abs(j))<x*(Math.abs(S)*(Math.abs(o.get(c-1,c-1))+Math.abs(A)+Math.abs(o.get(c+1,c+1)))));)c--;for(i=c+2;i<=b;i++)o.set(i,i-2,0),i>c+2&&o.set(i,i-3,0);for(a=c;a<=b-1&&(w=a!==b-1,a!==c&&(S=o.get(a,a-1),_=o.get(a+1,a-1),j=w?o.get(a+2,a-1):0,0!==(l=Math.abs(S)+Math.abs(_)+Math.abs(j))&&(S/=l,_/=l,j/=l)),0!==l);a++)if(R=Math.sqrt(S*S+_*_+j*j),S<0&&(R=-R),0!==R){for(a!==c?o.set(a,a-1,-R*l):u!==c&&o.set(a,a-1,-o.get(a,a-1)),l=(S+=R)/R,v=_/R,A=j/R,_/=S,j/=S,s=a;s<t;s++)S=o.get(a,s)+_*o.get(a+1,s),w&&(S+=j*o.get(a+2,s),o.set(a+2,s,o.get(a+2,s)-S*A)),o.set(a,s,o.get(a,s)-S*l),o.set(a+1,s,o.get(a+1,s)-S*v);for(i=0;i<=Math.min(b,a+3);i++)S=l*o.get(i,a)+v*o.get(i,a+1),w&&(S+=A*o.get(i,a+2),o.set(i,a+2,o.get(i,a+2)-S*j)),o.set(i,a,o.get(i,a)-S),o.set(i,a+1,o.get(i,a+1)-S*_);for(i=0;i<=M;i++)S=l*n.get(i,a)+v*n.get(i,a+1),w&&(S+=A*n.get(i,a+2),n.set(i,a+2,n.get(i,a+2)-S*j)),n.set(i,a,n.get(i,a)-S),n.set(i,a+1,n.get(i,a+1)-S*_)}}}if(0!==E){for(b=t-1;b>=0;b--)if(S=e[b],0===(_=r[b]))for(u=b,o.set(b,b,1),i=b-1;i>=0;i--){for(h=o.get(i,i)-S,j=0,s=u;s<=b;s++)j+=o.get(i,s)*o.get(s,b);if(r[i]<0)A=h,R=j;else if(u=i,0===r[i]?o.set(i,b,0!==h?-j/h:-j/(x*E)):(l=o.get(i,i+1),v=o.get(i+1,i),f=(l*R-A*j)/(_=(e[i]-S)*(e[i]-S)+r[i]*r[i]),o.set(i,b,f),o.set(i+1,b,Math.abs(l)>Math.abs(A)?(-j-h*f)/l:(-R-v*f)/A)),x*(f=Math.abs(o.get(i,b)))*f>1)for(s=i;s<=b;s++)o.set(s,b,o.get(s,b)/f)}else if(_<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,_/o.get(b,b-1)),o.set(b-1,b,-(o.get(b,b)-S)/o.get(b,b-1))):(y=Ke(0,-o.get(b-1,b),o.get(b-1,b-1)-S,_),o.set(b-1,b-1,y[0]),o.set(b-1,b,y[1])),o.set(b,b-1,0),o.set(b,b,1),i=b-2;i>=0;i--){for(m=0,g=0,s=u;s<=b;s++)m+=o.get(i,s)*o.get(s,b-1),g+=o.get(i,s)*o.get(s,b);if(h=o.get(i,i)-S,r[i]<0)A=h,j=m,R=g;else if(u=i,0===r[i]?(y=Ke(-m,-g,h,_),o.set(i,b-1,y[0]),o.set(i,b,y[1])):(l=o.get(i,i+1),v=o.get(i+1,i),p=(e[i]-S)*(e[i]-S)+r[i]*r[i]-_*_,d=2*(e[i]-S)*_,0===p&&0===d&&(p=x*E*(Math.abs(h)+Math.abs(_)+Math.abs(l)+Math.abs(v)+Math.abs(A))),y=Ke(l*j-A*m+_*g,l*R-A*g-_*m,p,d),o.set(i,b-1,y[0]),o.set(i,b,y[1]),Math.abs(l)>Math.abs(A)+Math.abs(_)?(o.set(i+1,b-1,(-m-h*o.get(i,b-1)+_*o.get(i,b))/l),o.set(i+1,b,(-g-h*o.get(i,b)-_*o.get(i,b-1))/l)):(y=Ke(-j-v*o.get(i,b-1),-R-v*o.get(i,b),A,_),o.set(i+1,b-1,y[0]),o.set(i+1,b,y[1]))),x*(f=Math.max(Math.abs(o.get(i,b-1)),Math.abs(o.get(i,b))))*f>1)for(s=i;s<=b;s++)o.set(s,b-1,o.get(s,b-1)/f),o.set(s,b,o.get(s,b)/f)}for(i=0;i<t;i++)if(i<0||i>M)for(s=i;s<t;s++)n.set(i,s,o.get(i,s));for(s=t-1;s>=0;s--)for(i=0;i<=M;i++){for(A=0,a=0;a<=Math.min(s,M);a++)A+=n.get(i,a)*o.get(a,s);n.set(i,s,A)}}}function Ke(t,r,e,n){var o,i;return Math.abs(e)>Math.abs(n)?[(t+(o=n/e)*r)/(i=e+o*n),(r-o*t)/i]:[((o=e/n)*t+r)/(i=n+o*e),(o*r-t)/i]}var We=Yr((function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Wr(this,t),r=Le.checkMatrix(r);var n,o=e.Y,i=e.scaleScores,s=void 0!==i&&i,a=e.maxIterations,u=void 0===a?1e3:a,c=e.terminationCriteria,f=void 0===c?1e-10:c;if(o){if((o=re(o)&&"number"==typeof o[0]?Ne.columnVector(o):Le.checkMatrix(o)).rows!==r.rows)throw new Error("Y should have the same number of rows as X");n=o.getColumnVector(0)}else n=r.getColumnVector(0);for(var h,l,v,m,g=1,p=0;p<u&&g>f;p++)v=(v=r.transpose().mmul(n).div(n.transpose().mmul(n).get(0,0))).div(v.norm()),h=r.mmul(v).div(v.transpose().mmul(v).get(0,0)),p>0&&(g=h.clone().sub(m).pow(2).sum()),m=h.clone(),o?(l=(l=o.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0))).div(l.norm()),n=o.mmul(l).div(l.transpose().mmul(l).get(0,0))):n=h;if(o){var d=r.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0));d=d.div(d.norm());var w=r.clone().sub(h.clone().mmul(d.transpose())),y=n.transpose().mmul(h).div(h.transpose().mmul(h).get(0,0)),b=o.clone().sub(h.clone().mulS(y.get(0,0)).mmul(l.transpose()));this.t=h,this.p=d.transpose(),this.w=v.transpose(),this.q=l,this.u=n,this.s=h.transpose().mmul(h),this.xResidual=w,this.yResidual=b,this.betas=y}else this.w=v.transpose(),this.s=h.transpose().mmul(h).sqrt(),this.t=s?h.clone().div(this.s.get(0,0)):h,this.xResidual=r.sub(h.mmul(v.transpose()))}));function Xe(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Ye(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Ye(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Ye(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var Je=function(){function t(r){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0;if(Wr(this,t),this.U=null,this.S=null,o)return this.center=o.center,this.scale=o.scale,this.means=o.means,this.stdevs=o.stdevs,this.U=Ne.checkMatrix(o.U),this.S=o.S,this.R=o.R,void(this.excludedFeatures=o.excludedFeatures||[]);e=(Array.isArray(r),new Ne(r));var i=n.isCovarianceMatrix,s=void 0!==i&&i,a=n.method,u=void 0===a?"SVD":a,c=n.nCompNIPALS,f=void 0===c?2:c,h=n.center,l=void 0===h||h,v=n.scale,m=void 0!==v&&v,g=n.ignoreZeroVariance,p=void 0!==g&&g;if(this.center=l,this.scale=m,this.means=null,this.stdevs=null,this.excludedFeatures=[],s)this._computeFromCovarianceMatrix(e);else switch(this._adjust(e,p),u){case"covarianceMatrix":var d=new Pe(e).mmul(e).div(e.rows-1);this._computeFromCovarianceMatrix(d);break;case"NIPALS":this._computeWithNIPALS(e,f);break;case"SVD":var w=new qe(e,{computeLeftSingularVectors:!1,computeRightSingularVectors:!0,autoTranspose:!0});this.U=w.rightSingularVectors;var y,b=w.diagonal,M=[],x=Xe(b);try{for(x.s();!(y=x.n()).done;){var k=y.value;M.push(k*k/(e.rows-1))}}catch(t){x.e(t)}finally{x.f()}this.S=M;break;default:throw new Error("unknown method: ".concat(u))}}return Yr(t,[{key:"predict",value:function(t){var r,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e.nComponents,o=void 0===n?this.U.columns:n;if(r=(Array.isArray(t),new Ne(t)),this.center&&(r.subRowVector(this.means),this.scale)){var i,s=Xe(this.excludedFeatures);try{for(s.s();!(i=s.n()).done;){var a=i.value;r.removeColumn(a)}}catch(t){s.e(t)}finally{s.f()}r.divRowVector(this.stdevs)}var u=r.mmul(this.U);return u.subMatrix(0,u.rows-1,0,o-1)}},{key:"invert",value:function(t){var r=(t=Ne.checkMatrix(t)).mmul(this.U.transpose());return this.center&&(this.scale&&r.mulRowVector(this.stdevs),r.addRowVector(this.means)),r}},{key:"getExplainedVariance",value:function(){var t=0;if(this.S){var r,e=Xe(this.S);try{for(e.s();!(r=e.n()).done;){var n=r.value;t+=n}}catch(t){e.e(t)}finally{e.f()}}return this.S?this.S.map((function(r){return r/t})):[]}},{key:"getCumulativeVariance",value:function(){for(var t=this.getExplainedVariance(),r=1;r<t.length;r++)t[r]+=t[r-1];return t}},{key:"getEigenvectors",value:function(){return this.U}},{key:"getEigenvalues",value:function(){return this.S}},{key:"getStandardDeviations",value:function(){return this.S.map((function(t){return Math.sqrt(t)}))}},{key:"getLoadings",value:function(){return this.U.transpose()}},{key:"toJSON",value:function(){return{name:"PCA",center:this.center,scale:this.scale,means:this.means,stdevs:this.stdevs,U:this.U,S:this.S,excludedFeatures:this.excludedFeatures}}},{key:"_adjust",value:function(t,r){if(this.center){var e=t.mean("column"),n=this.scale?t.standardDeviation("column",{mean:e}):null;if(this.means=e,t.subRowVector(e),this.scale){for(var o=0;o<n.length;o++)if(0===n[o]){if(!r)throw new RangeError("Cannot scale the dataset (standard deviation is zero at index ".concat(o));t.removeColumn(o),n.splice(o,1),this.excludedFeatures.push(o),o--}this.stdevs=n,t.divRowVector(n)}}}},{key:"_computeFromCovarianceMatrix",value:function(t){var r=new De(t,{assumeSymmetric:!0});this.U=r.eigenvectorMatrix,this.U.flipRows(),this.S=r.realEigenvalues,this.S.reverse()}},{key:"_computeWithNIPALS",value:function(t,r){this.U=new Ne(r,t.columns),this.S=[];for(var e=t,n=0;n<r;n++){var o=new We(e);this.U.setRow(n,o.w.transpose()),this.S.push(Math.pow(o.s.get(0,0),2)),e=o.xResidual}this.U=this.U.transpose()}}],[{key:"load",value:function(r){if("string"!=typeof r.name)throw new TypeError("model must have a name property");if("PCA"!==r.name)throw new RangeError("invalid model: ".concat(r.name));return new t(void 0,void 0,r)}}]),t}();function Ze(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!_r(t))throw new Error("data is not eff. array");var e=Nt(r,"scale");Rr(e)||(e=!0);var n=Nt(r,"nCompNIPALS");Or(n)||(n=2),n=Kr(n);var o=Mr(Nt(t,0,[]));if(0===o)throw new Error("invalid dimension of data");if(n>o)throw new Error("nCompNIPALS[".concat(n,"] is more than the dimension[").concat(o,"] of data"));var i="NIPALS",s=new Je(t,{method:i,scale:e,nCompNIPALS:n}),a=s.predict(t),u=a.toJSON();return u}var He=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n&&!1!==r(t[e],e,t););return t};var Qe=function(t){return function(r,e,n){for(var o=-1,i=Object(r),s=n(r),a=s.length;a--;){var u=s[t?a:++o];if(!1===e(i[u],u,i))break}return r}}();var tn=function(t,r){for(var e=-1,n=Array(t);++e<t;)n[e]=r(e);return n};var rn=function(t){return x(t)&&"[object Arguments]"==M(t)},en=Object.prototype,nn=en.hasOwnProperty,on=en.propertyIsEnumerable,sn=rn(function(){return arguments}())?rn:function(t){return x(t)&&nn.call(t,"callee")&&!on.call(t,"callee")},an=sn;var un=function(){return!1},cn=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e?h.Buffer:void 0,i=(o?o.isBuffer:void 0)||un;t.exports=i})),fn=/^(?:0|[1-9]\d*)$/;var hn=function(t,r){var n=e(t);return!!(r=null==r?9007199254740991:r)&&("number"==n||"symbol"!=n&&fn.test(t))&&t>-1&&t%1==0&&t<r},ln={};ln["[object Float32Array]"]=ln["[object Float64Array]"]=ln["[object Int8Array]"]=ln["[object Int16Array]"]=ln["[object Int32Array]"]=ln["[object Uint8Array]"]=ln["[object Uint8ClampedArray]"]=ln["[object Uint16Array]"]=ln["[object Uint32Array]"]=!0,ln["[object Arguments]"]=ln["[object Array]"]=ln["[object ArrayBuffer]"]=ln["[object Boolean]"]=ln["[object DataView]"]=ln["[object Date]"]=ln["[object Error]"]=ln["[object Function]"]=ln["[object Map]"]=ln["[object Number]"]=ln["[object Object]"]=ln["[object RegExp]"]=ln["[object Set]"]=ln["[object String]"]=ln["[object WeakMap]"]=!1;var vn=function(t){return x(t)&&rr(t.length)&&!!ln[M(t)]};var mn=function(t){return function(r){return t(r)}},gn=i((function(t,r){var e=r&&!r.nodeType&&r,n=e&&t&&!t.nodeType&&t,o=n&&n.exports===e&&c.process,i=function(){try{var t=n&&n.require&&n.require("util").types;return t||o&&o.binding&&o.binding("util")}catch(t){}}();t.exports=i})),pn=gn&&gn.isTypedArray,dn=pn?mn(pn):vn,wn=Object.prototype.hasOwnProperty;var yn=function(t,r){var e=u(t),n=!e&&an(t),o=!e&&!n&&cn(t),i=!e&&!n&&!o&&dn(t),s=e||n||o||i,a=s?tn(t.length,String):[],c=a.length;for(var f in t)!r&&!wn.call(t,f)||s&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||hn(f,c))||a.push(f);return a};var bn=function(t){return er(t)?yn(t):Lt(t)};var Mn=function(t,r){return function(e,n){if(null==e)return e;if(!er(e))return t(e,n);for(var o=e.length,i=r?o:-1,s=Object(e);(r?i--:++i<o)&&!1!==n(s[i],i,s););return e}}((function(t,r){return t&&Qe(t,r,bn)}));var xn=function(t){return t};var kn=function(t){return"function"==typeof t?t:xn};var En=function(t,r){return(u(t)?He:Mn)(t,kn(r))};var Sn=function(){this.__data__=new ct,this.size=0};var _n=function(t){var r=this.__data__,e=r.delete(t);return this.size=r.size,e};var jn=function(t){return this.__data__.get(t)};var Rn=function(t){return this.__data__.has(t)};var An=function(t,r){var e=this.__data__;if(e instanceof ct){var n=e.__data__;if(!ft||n.length<199)return n.push([t,r]),this.size=++e.size,this;e=this.__data__=new yt(n)}return e.set(t,r),this.size=e.size,this};function On(t){var r=this.__data__=new ct(t);this.size=r.size}On.prototype.clear=Sn,On.prototype.delete=_n,On.prototype.get=jn,On.prototype.has=Rn,On.prototype.set=An;var Cn=On;var In=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this};var Nn=function(t){return this.__data__.has(t)};function Fn(t){var r=-1,e=null==t?0:t.length;for(this.__data__=new yt;++r<e;)this.add(t[r])}Fn.prototype.add=Fn.prototype.push=In,Fn.prototype.has=Nn;var Tn=Fn;var Pn=function(t,r){for(var e=-1,n=null==t?0:t.length;++e<n;)if(r(t[e],e,t))return!0;return!1};var zn=function(t,r){return t.has(r)};var Ln=function(t,r,e,n,o,i){var s=1&e,a=t.length,u=r.length;if(a!=u&&!(s&&u>a))return!1;var c=i.get(t),f=i.get(r);if(c&&f)return c==r&&f==t;var h=-1,l=!0,v=2&e?new Tn:void 0;for(i.set(t,r),i.set(r,t);++h<a;){var m=t[h],g=r[h];if(n)var p=s?n(g,m,h,r,t,i):n(m,g,h,t,r,i);if(void 0!==p){if(p)continue;l=!1;break}if(v){if(!Pn(r,(function(t,r){if(!zn(v,r)&&(m===t||o(m,t,e,n,i)))return v.push(r)}))){l=!1;break}}else if(m!==g&&!o(m,g,e,n,i)){l=!1;break}}return i.delete(t),i.delete(r),l},Vn=h.Uint8Array;var qn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t,n){e[++r]=[n,t]})),e};var Dn=function(t){var r=-1,e=Array(t.size);return t.forEach((function(t){e[++r]=t})),e},Un=l?l.prototype:void 0,Bn=Un?Un.valueOf:void 0;var Gn=function(t,r,e,n,o,i,s){switch(e){case"[object DataView]":if(t.byteLength!=r.byteLength||t.byteOffset!=r.byteOffset)return!1;t=t.buffer,r=r.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=r.byteLength||!i(new Vn(t),new Vn(r)));case"[object Boolean]":case"[object Date]":case"[object Number]":return rt(+t,+r);case"[object Error]":return t.name==r.name&&t.message==r.message;case"[object RegExp]":case"[object String]":return t==r+"";case"[object Map]":var a=qn;case"[object Set]":var u=1&n;if(a||(a=Dn),t.size!=r.size&&!u)return!1;var c=s.get(t);if(c)return c==r;n|=2,s.set(t,r);var f=Ln(a(t),a(r),n,o,i,s);return s.delete(t),f;case"[object Symbol]":if(Bn)return Bn.call(t)==Bn.call(r)}return!1};var $n=function(t,r){for(var e=-1,n=r.length,o=t.length;++e<n;)t[o+e]=r[e];return t};var Kn=function(t,r,e){var n=r(t);return u(t)?n:$n(n,e(t))};var Wn=function(t,r){for(var e=-1,n=null==t?0:t.length,o=0,i=[];++e<n;){var s=t[e];r(s,e,t)&&(i[o++]=s)}return i};var Xn=function(){return[]},Yn=Object.prototype.propertyIsEnumerable,Jn=Object.getOwnPropertySymbols,Zn=Jn?function(t){return null==t?[]:(t=Object(t),Wn(Jn(t),(function(r){return Yn.call(t,r)})))}:Xn;var Hn=function(t){return Kn(t,bn,Zn)},Qn=Object.prototype.hasOwnProperty;var to=function(t,r,e,n,o,i){var s=1&e,a=Hn(t),u=a.length;if(u!=Hn(r).length&&!s)return!1;for(var c=u;c--;){var f=a[c];if(!(s?f in r:Qn.call(r,f)))return!1}var h=i.get(t),l=i.get(r);if(h&&l)return h==r&&l==t;var v=!0;i.set(t,r),i.set(r,t);for(var m=s;++c<u;){var g=t[f=a[c]],p=r[f];if(n)var d=s?n(p,g,f,r,t,i):n(g,p,f,t,r,i);if(!(void 0===d?g===p||o(g,p,e,n,i):d)){v=!1;break}m||(m="constructor"==f)}if(v&&!m){var w=t.constructor,y=r.constructor;w==y||!("constructor"in t)||!("constructor"in r)||"function"==typeof w&&w instanceof w&&"function"==typeof y&&y instanceof y||(v=!1)}return i.delete(t),i.delete(r),v},ro="[object Arguments]",eo="[object Array]",no="[object Object]",oo=Object.prototype.hasOwnProperty;var io=function(t,r,e,n,o,i){var s=u(t),a=u(r),c=s?eo:tr(t),f=a?eo:tr(r),h=(c=c==ro?no:c)==no,l=(f=f==ro?no:f)==no,v=c==f;if(v&&cn(t)){if(!cn(r))return!1;s=!0,h=!1}if(v&&!h)return i||(i=new Cn),s||dn(t)?Ln(t,r,e,n,o,i):Gn(t,r,c,e,n,o,i);if(!(1&e)){var m=h&&oo.call(t,"__wrapped__"),g=l&&oo.call(r,"__wrapped__");if(m||g){var p=m?t.value():t,d=g?r.value():r;return i||(i=new Cn),o(p,d,e,n,i)}}return!!v&&(i||(i=new Cn),to(t,r,e,n,o,i))};var so=function t(r,e,n,o,i){return r===e||(null==r||null==e||!x(r)&&!x(e)?r!=r&&e!=e:io(r,e,n,o,t,i))};var ao=function(t,r,e,n){var o=e.length,i=o,s=!n;if(null==t)return!i;for(t=Object(t);o--;){var a=e[o];if(s&&a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var u=(a=e[o])[0],c=t[u],f=a[1];if(s&&a[2]){if(void 0===c&&!(u in t))return!1}else{var h=new Cn;if(n)var l=n(c,f,u,t,r,h);if(!(void 0===l?so(f,c,3,n,h):l))return!1}}return!0};var uo=function(t){return t==t&&!j(t)};var co=function(t){for(var r=bn(t),e=r.length;e--;){var n=r[e],o=t[n];r[e]=[n,o,uo(o)]}return r};var fo=function(t,r){return function(e){return null!=e&&(e[t]===r&&(void 0!==r||t in Object(e)))}};var ho=function(t){var r=co(t);return 1==r.length&&r[0][2]?fo(r[0][0],r[0][1]):function(e){return e===t||ao(e,t,r)}};var lo=function(t,r){return null!=t&&r in Object(t)};var vo=function(t,r,e){for(var n=-1,o=(r=Ot(r,t)).length,i=!1;++n<o;){var s=Ct(r[n]);if(!(i=null!=t&&e(t,s)))break;t=t[s]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&rr(o)&&hn(s,o)&&(u(t)||an(t))};var mo=function(t,r){return null!=t&&vo(t,r,lo)};var go=function(t,r){return _(t)&&uo(r)?fo(Ct(t),r):function(e){var n=Nt(e,t);return void 0===n&&n===r?mo(e,t):so(r,n,3)}};var po=function(t){return function(r){return It(r,t)}};var wo=function(t){return _(t)?or(Ct(t)):po(t)};var yo=function(t){return"function"==typeof t?t:null==t?xn:"object"==e(t)?u(t)?go(t[0],t[1]):ho(t):wo(t)};var bo=function(t,r){var e=-1,n=er(t)?Array(t.length):[];return Mn(t,(function(t,o,i){n[++e]=r(t,o,i)})),n};var Mo=function(t,r){return(u(t)?St:bo)(t,yo(r))};var xo=function(t,r){return St(r,(function(r){return t[r]}))};var ko=function(t){return null==t?[]:xo(t,bn(t))};function Eo(t,r){if(!kr(t))return{};if(!_r(r))return{};var e={};return En(r,(function(r){(function(t,r){return!!kr(t)&&!(!Ar(r)&&!Or(r))&&r in t})(t,r)&&(e[r]=Nt(t,r))})),e}function So(t){if(kr(t)){for(var r in t)return!0;return!1}return!1}var _o=Array.prototype.join;var jo=function(t,r){return null==t?"":_o.call(t,r)},Ro=Yr((function t(r){var e=this;Wr(this,t),this.getCost=function(){return e.Elements.map((function(t){return t.DistanceFromMedoid})).reduce((function(t,r){return t+r}),0)},this.findBestMedoidIdx=function(t){return e.Elements.map((function(r){return e.calcCostForGivenElementAsMedoid(r,t)})).reduce((function(t,r,e,n){return r.CostIfMadeMedoid<n[t].CostIfMadeMedoid?e:t}),0)},this.calcCostForGivenElementAsMedoid=function(r,n){return{CostIfMadeMedoid:new t({Elements:e.Elements.map((function(t){return{DistanceFromMedoid:n(t.Element,r.Element),Element:t.Element}})),Medoid:r.Element}).getCost(),Element:r}},this.Elements=r.Elements,this.Medoid=r.Medoid})),Ao=Ro,Oo=Object.defineProperty({Cluster:Ao},"__esModule",{value:!0}),Co=Object.defineProperty({distance:function(t,r){if(t.length!==r.length)throw new Error("the inputs must have the same dimension");var e=Array.from(t.keys()).map((function(e){return Math.pow(Math.abs(t[e]-r[e]),2)})).reduce((function(t,r){return t+r}),0);return Math.sqrt(e)}},"__esModule",{value:!0}),Io=Object.defineProperty({kGtElementArrLength:"k must be less than the number of elements in the input array"},"__esModule",{value:!0});function No(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!e){if(Array.isArray(t)||(e=function(t,r){if(!t)return;if("string"==typeof t)return Fo(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);"Object"===e&&t.constructor&&(e=t.constructor.name);if("Map"===e||"Set"===e)return Array.from(t);if("Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return Fo(t,r)}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){e=e.call(t)},n:function(){var t=e.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==e.return||e.return()}finally{if(a)throw i}}}}function Fo(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}var To=function(){function t(r,e,n){var o=this;Wr(this,t),this.Elements=r,this.K=e,this.DistanceFn=n,this.OptimisationCompleted=!1,this.iterate=function(){o.IterationCount++,o.Clusters||o.allocateToClustersAroundCurrentMedoids();for(var r=o.Medoids,e=o.Clusters,n=o.calculateCurrentCost(),i=n,s=0;s<o.Medoids.length;s++){var a,u=No(o.Elements.filter((function(t){return 0===o.Medoids.filter((function(r){return 0===o.DistanceFn(t,r)})).length})));try{for(u.s();!(a=u.n()).done;){var c=a.value,f=o.Medoids.slice();f[s]=c;var h=new t(o.Elements.slice(),o.K,o.DistanceFn);h.Medoids=f,h.allocateToClustersAroundCurrentMedoids();var l=h.calculateCurrentCost();l<i&&(i=l,o.Clusters=h.Clusters,o.Medoids=f)}}catch(t){u.e(t)}finally{u.f()}}return o.calculateCurrentCost()<n||(o.Clusters=e,o.Medoids=r,o.OptimisationCompleted=!0,!1)},this.getClusteredData=function(){return o.OptimisationCompleted||o.runToCompletion(),o.Clusters.map((function(t){return t.Elements.map((function(t){return t.Element}))}))},this.runToCompletion=function(){for(;o.iterate(););},this.allocateToClustersAroundCurrentMedoids=function(){o.Clusters=new Array,o.Medoids.forEach((function(t){o.Clusters.push(new Oo.Cluster({Elements:[],Medoid:t}))})),o.Elements.forEach((function(t,r){var e=o.findDistances(o.Clusters.map((function(t){return t.Medoid})),t),n=e.reduce((function(t,r,e,n){return r<n[t]?e:t}),0);o.Clusters[n].Elements.push({DistanceFromMedoid:e[n],Element:t})}))},this.calculateCurrentCost=function(){return o.Clusters.map((function(t){return t.getCost()})).reduce((function(t,r){return t+r}),0)},this.findDistances=function(t,r){return t.map((function(t){return o.DistanceFn(t,r)}))},this.selectInitialMedoids=function(){if(o.K>=o.Elements.length)throw Io.kGtElementArrLength;for(var t=[],r=function(t,r){var e,n=No(r);try{for(n.s();!(e=n.n()).done;){var i=e.value;if(0===o.DistanceFn(i,t))return!1}}catch(t){n.e(t)}finally{n.f()}return!0},e=0;e<o.Elements.length&&t.length<o.K;)r(o.Elements[e],t)&&t.push(o.Elements[e]),e++;return t},this.DistanceFn=this.DistanceFn||Co.distance,this.Medoids=this.selectInitialMedoids(),this.IterationCount=0}return Yr(t,[{key:"OptimisationStarted",get:function(){return this.IterationCount>0}}]),t}();To.clusterElements=function(t,r,e){return To.getInstance(t,r,e),new Array},To.getInstance=function(t,r,e){return new To(t,r,e)};var Po=To,zo=Object.defineProperty({Clusterer:Po},"__esModule",{value:!0}),Lo=o(i((function(t,r){function e(t){for(var e in t)r.hasOwnProperty(e)||(r[e]=t[e])}Object.defineProperty(r,"__esModule",{value:!0}),e(Oo),e(zo)})));function Vo(t,r){for(var e=0,n=0;n<t.length;n++)e+=(t[n]-r[n])*(t[n]-r[n]);return e}var qo={distanceFunction:Vo};function Do(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:qo,n=e.distanceFunction||qo.distanceFunction,o=e.similarityFunction||qo.similarityFunction,i=-1;if("function"==typeof o)for(var s=Number.MIN_VALUE,a=0;a<t.length;a++){var u=o(r,t[a]);u>s&&(s=u,i=a)}else{if("function"!=typeof n)throw new Error("A similarity or distance function it's required");for(var c=Number.MAX_VALUE,f=0;f<t.length;f++){var h=n(r,t[f]);h<c&&(c=h,i=f)}}return i}function Uo(t,r,e,n){for(var o=0;o<t.length;o++)e[o]=Do(r,t[o],{distanceFunction:n});return e}var Bo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Date.now();Wr(this,t),this.state=new Uint32Array(4),this.init(r),this.random=this.getFloat.bind(this)}return Yr(t,[{key:"getUint32",value:function(){return this.nextState(),this.state[3]+this.state[2]>>>0}},{key:"getFloat",value:function(){return 5.960464477539063e-8*(this.getUint32()>>>8)}},{key:"init",value:function(t){if(!Number.isInteger(t))throw new TypeError("seed must be an integer");this.state[0]=t,this.state[1]=0,this.state[2]=0,this.state[3]=0;for(var r=1;r<8;r++)this.state[3&r]^=r+(e=1812433253,n=this.state[r-1&3]^this.state[r-1&3]>>>30>>>0,o=void 0,o=65535&(e>>>=0),((e-o)*(n>>>=0)>>>0)+o*n>>>0)>>>0;var e,n,o;this.periodCertification();for(var i=0;i<8;i++)this.nextState()}},{key:"periodCertification",value:function(){0===this.state[0]&&0===this.state[1]&&0===this.state[2]&&0===this.state[3]&&(this.state[0]=88,this.state[1]=83,this.state[2]=65,this.state[3]=68)}},{key:"nextState",value:function(){var t=this.state[0];t^=t<<15,t^=t>>>18,t^=this.state[3]<<11,this.state[0]=this.state[1],this.state[1]=this.state[2],this.state[2]=this.state[3],this.state[3]=t}}]),t}();function Go(t){var r,e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.random,i=n.size,s=void 0===i?1:i,a=n.replace,u=void 0!==a&&a,c=n.probabilities;if(r="number"==typeof t?$o(t):t.slice(),c){if(!u)throw new Error("choice with probabilities and no replacement is not implemented");if(c.length!==r.length)throw new Error("the length of probabilities option should be equal to the number of choices");e=[c[0]];for(var f=1;f<c.length;f++)e[f]=e[f-1]+c[f];if(Math.abs(1-e[e.length-1])>1e-8)throw new Error("probabilities should sum to 1, but instead sums to ".concat(e[e.length-1]))}if(!1===u&&s>r.length)throw new Error("size option is too large");for(var h=[],l=0;l<s;l++){var v=Ko(r.length,o,e);h.push(r[v]),u||r.splice(v,1)}return h}function $o(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Ko(t,r,e){var n=r();if(e){for(var o=0;n>e[o];)o++;return o}return Math.floor(n*t)}var Wo=function(){function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Math.random;if(Wr(this,t),"number"==typeof r){var e=new Bo(r);this.randomGenerator=e.random}else this.randomGenerator=r}return Yr(t,[{key:"choice",value:function(t,r){return Go(t,r,this.randomGenerator)}},{key:"random",value:function(){return this.randomGenerator()}},{key:"randInt",value:function(t,r){return void 0===r&&(r=t,t=0),t+Math.floor(this.randomGenerator()*(r-t))}},{key:"randomSample",value:function(t){for(var r=[],e=0;e<t;e++)r.push(this.random());return r}}]),t}();function Xo(t,r){for(var e=new Ne(t.rows,r.rows),n=0;n<t.rows;n++)for(var o=0;o<r.rows;o++)e.set(n,o,Vo(t.getRow(n),r.getRow(o)));return e}function Yo(t){for(var r=[],e=0;e<t;e++)r.push(e);return r}function Jo(t){for(var r=[t[0]],e=1;e<t.length;e++)r[e]=r[e-1]+t[e];return r}var Zo=Symbol("distance"),Ho=function(){function t(r,e,n,o,i){Wr(this,t),this.clusters=r,this.centroids=e,this.converged=n,this.iterations=o,this[Zo]=i}return Yr(t,[{key:"nearest",value:function(t){var r=new Array(t.length);return Uo(t,this.centroids.map((function(t){return t.centroid})),r,this[Zo])}},{key:"computeInformation",value:function(r){for(var e=this.centroids.map((function(t){return{centroid:t,error:0,size:0}})),n=0;n<r.length;n++)e[this.clusters[n]].error+=this[Zo](r[n],this.centroids[this.clusters[n]]),e[this.clusters[n]].size++;for(var o=0;o<this.centroids.length;o++)e[o].size?e[o].error/=e[o].size:e[o].error=null;return new t(this.clusters,e,this.converged,this.iterations,this[Zo])}}]),t}(),Qo=a.mark(ei),ti={maxIterations:100,tolerance:1e-6,withIterations:!1,initialization:"kmeans++",distanceFunction:Vo};function ri(t,r,e,n,o,i){var s=function(t,r,e,n){for(var o=r[0].length,i=new Array(n),s=new Array(n),a=0;a<n;a++){i[a]=new Array(o),s[a]=0;for(var u=0;u<o;u++)i[a][u]=0}for(var c=0;c<r.length;c++){s[e[c]]++;for(var f=0;f<o;f++)i[e[c]][f]+=r[c][f]}for(var h=0;h<n;h++)for(var l=0;l<o;l++)s[h]?i[h][l]/=s[h]:i[h][l]=t[h][l];return i}(t,r,e=Uo(r,t,e,o.distanceFunction),n),a=function(t,r,e,n){for(var o=0;o<t.length;o++)if(e(t[o],r[o])>n)return!1;return!0}(s,t,o.distanceFunction,o.tolerance);return new Ho(e,s,a,i,o.distanceFunction)}function ei(t,r,e,n,o){var i,s,u;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:i=!1,s=0;case 2:if(i||!(s<o.maxIterations)){a.next=10;break}return u=ri(t,r,e,n,o,++s),a.next=6,u.computeInformation(r);case 6:i=u.converged,t=u.centroids,a.next=2;break;case 10:case"end":return a.stop()}}),Qo)}function ni(t,r,e){if(e=Object.assign({},ti,e),r<=0||r>t.length||!Number.isInteger(r))throw new Error("K should be a positive integer smaller than the number of points");var n;if(Array.isArray(e.initialization)){if(e.initialization.length!==r)throw new Error("The initial centers should have the same length as K");n=e.initialization}else switch(e.initialization){case"kmeans++":n=function(t,r){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=(t=new Ne(t)).rows,o=new Wo(e.seed),i=[],s=e.localTrials||2+Math.floor(Math.log(r)),a=o.randInt(n);i.push(t.getRow(a));for(var u=new Ne(1,t.rows),c=0;c<t.rows;c++)u.set(0,c,Vo(t.getRow(c),i[0]));for(var f=[Jo(u.getRow(0))],h=1/f[0][n-1],l=Ne.mul(u,h),v=1;v<r;v++){for(var m=o.choice(n,{replace:!0,size:s,probabilities:l[0]}),g=Xo(t.selection(m,Yo(t.columns)),t),p=void 0,d=void 0,w=void 0,y=0;y<s;y++){var b=Ne.min(u,[g.getRow(y)]),M=b.sum();(void 0===p||M<d)&&(p=m[y],d=M,w=b)}i[v]=t.getRow(p),f=[Jo((u=w).getRow(0))],l=Ne.mul(u,1/f[0][n-1])}return i}(t,r,e);break;case"random":n=function(t,r,e){return new Wo(e).choice(t,{size:r})}(t,r,e.seed);break;case"mostDistant":n=function(t,r,e,n){var o=new Wo(n),i=new Array(r);if(i[0]=Math.floor(o.random()*t.length),r>1){for(var s={dist:-1,index:-1},a=0;a<t.length;++a)e[i[0]][a]>s.dist&&(s.dist=e[i[0]][a],s.index=a);if(i[1]=s.index,r>2)for(var u=2;u<r;++u){for(var c={dist:-1,index:-1},f=0;f<t.length;++f){for(var h={dist:Number.MAX_VALUE,index:-1},l=0;l<u;++l)e[l][f]<h.dist&&-1===i.indexOf(f)&&(h={dist:e[l][f],index:f});h.dist!==Number.MAX_VALUE&&h.dist>c.dist&&(c=Object.assign({},h))}i[u]=c.index}}return i.map((function(r){return t[r]}))}(t,r,function(t,r){for(var e=new Array(t.length),n=0;n<t.length;++n)for(var o=n;o<t.length;++o){e[n]||(e[n]=new Array(t.length)),e[o]||(e[o]=new Array(t.length));var i=r(t[n],t[o]);e[n][o]=i,e[o][n]=i}return e}(t,e.distanceFunction),e.seed);break;default:throw new Error('Unknown initialization method: "'.concat(e.initialization,'"'))}0===e.maxIterations&&(e.maxIterations=Number.MAX_VALUE);var o=new Array(t.length);if(e.withIterations)return ei(n,t,o,r,e);for(var i,s=!1,a=0;!s&&a<e.maxIterations;)s=(i=ri(n,t,o,r,e,++a)).converged,n=i.centroids;return i.computeInformation(t)}function oi(t,r){var e={};function n(t){return jo(t,":")}En(t,(function(t,r){var o=n(t);e[o]=r}));var o=Lo.Clusterer.getInstance(t,r).getClusteredData();return o=Mo(o,(function(t){return Mo(t,(function(t){var r=n(t);return e[r]}))}))}function ii(t,r){var e=ni(t,r),n={};return En(e.clusters,(function(t,r){n[t]||(n[t]=[]),n[t].push(r)})),ko(n)}function si(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Nt(r,"kNumber");e=Or(e)?Kr(e):2;var n,o=Nt(r,"mode");if("k-medoids"!==o&&"k-means"!==o&&(o="k-medoids"),"k-medoids"===o)n=oi(t,e);else{if("k-means"!==o)throw new Error("invalid mode[".concat(o,"]"));n=ii(t,e)}return n}function ai(t){var r={};En(t,(function(t){En(t,(function(t,e){r[e]||(r[e]=0),0===r[e]&&Or(t)&&(r[e]=1),1!==r[e]||Or(t)||(r[e]=-1)}))}));var e=[];return En(r,(function(t,r){1===t&&e.push(r)})),e}function ui(t,r){return Mo(t,(function(t){var e=Eo(t,r);return ko(e)}))}function ci(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!_r(t))throw new Error("data is not eff. array");var e=Nt(r,"kNumber");Or(e)||(e=2),e=Kr(e);var n=Nt(r,"nCompNIPALS");Or(n)||(n=2),n=Kr(n);var o=Nt(r,"mode"),i="",s=Mr(t),a=0,u=0;if(En(t,(function(t){So(t)?a+=1:_r(t)&&(u+=1)})),a===s)i="obj";else{if(u!==s)throw new Error("data is not of the same type");i="mat"}var c,f=null;"obj"===i?(f=ai(t),c=ui(t,f)):c=t;var h=Ze(c,{nCompNIPALS:n}),l=si(h,{kNumber:e,mode:o}),v=Mo(l,(function(t){return Mo(t,(function(t){return h[t]}))})),m=Mo(l,(function(r){return Mo(r,(function(r){return t[r]}))}));return{keys:f,ginds:l,gmat:v,gltdt:m}}function fi(){return fi=r(a.mark((function t(r){var e,n=arguments;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.abrupt("return",Ze(r,e));case 2:case"end":return t.stop()}}),t)}))),fi.apply(this,arguments)}function hi(){return hi=r(a.mark((function t(r){var e,n=arguments;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>1&&void 0!==n[1]?n[1]:{},t.prev=1,t.abrupt("return",ci(r,e));case 5:return t.prev=5,t.t0=t.catch(1),t.abrupt("return",Promise.reject(t.t0));case 8:case"end":return t.stop()}}),t,null,[[1,5]])}))),hi.apply(this,arguments)}var li={PCA:function(t){return fi.apply(this,arguments)},cluster:function(t){return hi.apply(this,arguments)}};return li}));
7
7
  //# sourceMappingURL=w-cluster.umd.js.map