@guihz/trading-vue-editor-tes 0.0.17 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,14 +51,14 @@ Example:
51
51
  * Dual licensed under the MIT or GPL Version 2 licenses.
52
52
  **/(function(i,t){(function(e){var r=2e3,n={s:1,n:0,d:1};function s(v,E){if(isNaN(v=parseInt(v,10)))throw g();return v*E}function u(v,E){if(E===0)throw w();var b=Object.create(_.prototype);b.s=v<0?-1:1,v=v<0?-v:v;var N=m(v,E);return b.n=v/N,b.d=E/N,b}function l(v){for(var E={},b=v,N=2,x=4;x<=b;){for(;b%N===0;)b/=N,E[N]=(E[N]||0)+1;x+=1+2*N++}return b!==v?b>1&&(E[b]=(E[b]||0)+1):E[v]=(E[v]||0)+1,E}var f=function(v,E){var b=0,N=1,x=1,F=0,M=0,S=0,$=1,C=1,I=0,R=1,U=1,q=1,k=1e7,P;if(v!=null)if(E!==void 0){if(b=v,N=E,x=b*N,b%1!==0||N%1!==0)throw y()}else switch(typeof v){case"object":{if("d"in v&&"n"in v)b=v.n,N=v.d,"s"in v&&(b*=v.s);else if(0 in v)b=v[0],1 in v&&(N=v[1]);else throw g();x=b*N;break}case"number":{if(v<0&&(x=v,v=-v),v%1===0)b=v;else if(v>0){for(v>=1&&(C=Math.pow(10,Math.floor(1+Math.log(v)/Math.LN10)),v/=C);R<=k&&q<=k;)if(P=(I+U)/(R+q),v===P){R+q<=k?(b=I+U,N=R+q):q>R?(b=U,N=q):(b=I,N=R);break}else v>P?(I+=U,R+=q):(U+=I,q+=R),R>k?(b=U,N=q):(b=I,N=R);b*=C}else(isNaN(v)||isNaN(E))&&(N=b=NaN);break}case"string":{if(R=v.match(/\d+|./g),R===null)throw g();if(R[I]==="-"?(x=-1,I++):R[I]==="+"&&I++,R.length===I+1?M=s(R[I++],x):R[I+1]==="."||R[I]==="."?(R[I]!=="."&&(F=s(R[I++],x)),I++,(I+1===R.length||R[I+1]==="("&&R[I+3]===")"||R[I+1]==="'"&&R[I+3]==="'")&&(M=s(R[I],x),$=Math.pow(10,R[I].length),I++),(R[I]==="("&&R[I+2]===")"||R[I]==="'"&&R[I+2]==="'")&&(S=s(R[I+1],x),C=Math.pow(10,R[I+1].length)-1,I+=3)):R[I+1]==="/"||R[I+1]===":"?(M=s(R[I],x),$=s(R[I+2],1),I+=3):R[I+3]==="/"&&R[I+1]===" "&&(F=s(R[I],x),M=s(R[I+2],x),$=s(R[I+4],1),I+=5),R.length<=I){N=$*C,x=b=S+N*F+C*M;break}}default:throw g()}if(N===0)throw w();n.s=x<0?-1:1,n.n=Math.abs(b),n.d=Math.abs(N)};function p(v,E,b){for(var N=1;E>0;v=v*v%b,E>>=1)E&1&&(N=N*v%b);return N}function h(v,E){for(;E%2===0;E/=2);for(;E%5===0;E/=5);if(E===1)return 0;for(var b=10%E,N=1;b!==1;N++)if(b=b*10%E,N>r)return 0;return N}function c(v,E,b){for(var N=1,x=p(10,b,E),F=0;F<300;F++){if(N===x)return F;N=N*10%E,x=x*10%E}return 0}function m(v,E){if(!v)return E;if(!E)return v;for(;;){if(v%=E,!v)return E;if(E%=v,!E)return v}}function _(v,E){if(f(v,E),this instanceof _)v=m(n.d,n.n),this.s=n.s,this.n=n.n/v,this.d=n.d/v;else return u(n.s*n.n,n.d)}var w=function(){return new Error("Division by Zero")},g=function(){return new Error("Invalid argument")},y=function(){return new Error("Parameters must be integer")};_.prototype={s:1,n:0,d:1,abs:function(){return u(this.n,this.d)},neg:function(){return u(-this.s*this.n,this.d)},add:function(v,E){return f(v,E),u(this.s*this.n*n.d+n.s*this.d*n.n,this.d*n.d)},sub:function(v,E){return f(v,E),u(this.s*this.n*n.d-n.s*this.d*n.n,this.d*n.d)},mul:function(v,E){return f(v,E),u(this.s*n.s*this.n*n.n,this.d*n.d)},div:function(v,E){return f(v,E),u(this.s*n.s*this.n*n.d,this.d*n.n)},clone:function(){return u(this.s*this.n,this.d)},mod:function(v,E){if(isNaN(this.n)||isNaN(this.d))return new _(NaN);if(v===void 0)return u(this.s*this.n%this.d,1);if(f(v,E),n.n===0&&this.d===0)throw w();return u(this.s*(n.d*this.n)%(n.n*this.d),n.d*this.d)},gcd:function(v,E){return f(v,E),u(m(n.n,this.n)*m(n.d,this.d),n.d*this.d)},lcm:function(v,E){return f(v,E),n.n===0&&this.n===0?u(0,1):u(n.n*this.n,m(n.n,this.n)*m(n.d,this.d))},ceil:function(v){return v=Math.pow(10,v||0),isNaN(this.n)||isNaN(this.d)?new _(NaN):u(Math.ceil(v*this.s*this.n/this.d),v)},floor:function(v){return v=Math.pow(10,v||0),isNaN(this.n)||isNaN(this.d)?new _(NaN):u(Math.floor(v*this.s*this.n/this.d),v)},round:function(v){return v=Math.pow(10,v||0),isNaN(this.n)||isNaN(this.d)?new _(NaN):u(Math.round(v*this.s*this.n/this.d),v)},inverse:function(){return u(this.s*this.d,this.n)},pow:function(v,E){if(f(v,E),n.d===1)return n.s<0?u(Math.pow(this.s*this.d,n.n),Math.pow(this.n,n.n)):u(Math.pow(this.s*this.n,n.n),Math.pow(this.d,n.n));if(this.s<0)return null;var b=l(this.n),N=l(this.d),x=1,F=1;for(var M in b)if(M!=="1"){if(M==="0"){x=0;break}if(b[M]*=n.n,b[M]%n.d===0)b[M]/=n.d;else return null;x*=Math.pow(M,b[M])}for(var M in N)if(M!=="1"){if(N[M]*=n.n,N[M]%n.d===0)N[M]/=n.d;else return null;F*=Math.pow(M,N[M])}return n.s<0?u(F,x):u(x,F)},equals:function(v,E){return f(v,E),this.s*this.n*n.d===n.s*n.n*this.d},compare:function(v,E){f(v,E);var b=this.s*this.n*n.d-n.s*n.n*this.d;return(0<b)-(b<0)},simplify:function(v){if(isNaN(this.n)||isNaN(this.d))return this;v=v||.001;for(var E=this.abs(),b=E.toContinued(),N=1;N<b.length;N++){for(var x=u(b[N-1],1),F=N-2;F>=0;F--)x=x.inverse().add(b[F]);if(Math.abs(x.sub(E).valueOf())<v)return x.mul(this.s)}return this},divisible:function(v,E){return f(v,E),!(!(n.n*this.d)||this.n*n.d%(n.n*this.d))},valueOf:function(){return this.s*this.n/this.d},toFraction:function(v){var E,b="",N=this.n,x=this.d;return this.s<0&&(b+="-"),x===1?b+=N:(v&&(E=Math.floor(N/x))>0&&(b+=E,b+=" ",N%=x),b+=N,b+="/",b+=x),b},toLatex:function(v){var E,b="",N=this.n,x=this.d;return this.s<0&&(b+="-"),x===1?b+=N:(v&&(E=Math.floor(N/x))>0&&(b+=E,N%=x),b+="\\frac{",b+=N,b+="}{",b+=x,b+="}"),b},toContinued:function(){var v,E=this.n,b=this.d,N=[];if(isNaN(E)||isNaN(b))return N;do N.push(Math.floor(E/b)),v=E%b,E=b,b=v;while(E!==1);return N},toString:function(v){var E=this.n,b=this.d;if(isNaN(E)||isNaN(b))return"NaN";v=v||15;var N=h(E,b),x=c(E,b,N),F=this.s<0?"-":"";if(F+=E/b|0,E%=b,E*=10,E&&(F+="."),N){for(var M=x;M--;)F+=E/b|0,E%=b,E*=10;F+="(";for(var M=N;M--;)F+=E/b|0,E%=b,E*=10;F+=")"}else for(var M=v;E&&M--;)F+=E/b|0,E%=b,E*=10;return F}},Object.defineProperty(_,"__esModule",{value:!0}),_.default=_,_.Fraction=_,i.exports=_})()})(_f);var Ym=_f.exports,Hr=jt(Ym),jm="Fraction",Zm=[],Gm=mt(jm,Zm,()=>(Object.defineProperty(Hr,"name",{value:"Fraction"}),Hr.prototype.constructor=Hr,Hr.prototype.type="Fraction",Hr.prototype.isFraction=!0,Hr.prototype.toJSON=function(){return{mathjs:"Fraction",n:this.s*this.n,d:this.d}},Hr.fromJSON=function(i){return new Hr(i)},Hr),{isClass:!0}),Km="Matrix",Hm=[],Jm=mt(Km,Hm,()=>{function i(){if(!(this instanceof i))throw new SyntaxError("Constructor must be called with the new operator")}return i.prototype.type="Matrix",i.prototype.isMatrix=!0,i.prototype.storage=function(){throw new Error("Cannot invoke storage on a Matrix interface")},i.prototype.datatype=function(){throw new Error("Cannot invoke datatype on a Matrix interface")},i.prototype.create=function(t,e){throw new Error("Cannot invoke create on a Matrix interface")},i.prototype.subset=function(t,e,r){throw new Error("Cannot invoke subset on a Matrix interface")},i.prototype.get=function(t){throw new Error("Cannot invoke get on a Matrix interface")},i.prototype.set=function(t,e,r){throw new Error("Cannot invoke set on a Matrix interface")},i.prototype.resize=function(t,e){throw new Error("Cannot invoke resize on a Matrix interface")},i.prototype.reshape=function(t,e){throw new Error("Cannot invoke reshape on a Matrix interface")},i.prototype.clone=function(){throw new Error("Cannot invoke clone on a Matrix interface")},i.prototype.size=function(){throw new Error("Cannot invoke size on a Matrix interface")},i.prototype.map=function(t,e){throw new Error("Cannot invoke map on a Matrix interface")},i.prototype.forEach=function(t){throw new Error("Cannot invoke forEach on a Matrix interface")},i.prototype[Symbol.iterator]=function(){throw new Error("Cannot iterate a Matrix interface")},i.prototype.toArray=function(){throw new Error("Cannot invoke toArray on a Matrix interface")},i.prototype.valueOf=function(){throw new Error("Cannot invoke valueOf on a Matrix interface")},i.prototype.format=function(t){throw new Error("Cannot invoke format on a Matrix interface")},i.prototype.toString=function(){throw new Error("Cannot invoke toString on a Matrix interface")},i},{isClass:!0});function wf(i){return Object.keys(i.signatures||{}).reduce(function(t,e){var r=(e.match(/,/g)||[]).length+1;return Math.max(t,r)},-1)}var Xm="DenseMatrix",Vm=["Matrix"],Qm=mt(Xm,Vm,i=>{var{Matrix:t}=i;function e(h,c){if(!(this instanceof e))throw new SyntaxError("Constructor must be called with the new operator");if(c&&!Ur(c))throw new Error("Invalid datatype: "+c);if(fe(h))h.type==="DenseMatrix"?(this._data=te(h._data),this._size=te(h._size),this._datatype=c||h._datatype):(this._data=h.toArray(),this._size=h.size(),this._datatype=c||h._datatype);else if(h&&ge(h.data)&&ge(h.size))this._data=h.data,this._size=h.size,Zl(this._data,this._size),this._datatype=c||h.datatype;else if(ge(h))this._data=p(h),this._size=Ae(this._data),Zl(this._data,this._size),this._datatype=c;else{if(h)throw new TypeError("Unsupported type of data ("+cn(h)+")");this._data=[],this._size=[0],this._datatype=c}}e.prototype=new t,e.prototype.createDenseMatrix=function(h,c){return new e(h,c)},Object.defineProperty(e,"name",{value:"DenseMatrix"}),e.prototype.constructor=e,e.prototype.type="DenseMatrix",e.prototype.isDenseMatrix=!0,e.prototype.getDataType=function(){return Es(this._data,cn)},e.prototype.storage=function(){return"dense"},e.prototype.datatype=function(){return this._datatype},e.prototype.create=function(h,c){return new e(h,c)},e.prototype.subset=function(h,c,m){switch(arguments.length){case 1:return r(this,h);case 2:case 3:return s(this,h,c,m);default:throw new SyntaxError("Wrong number of arguments")}},e.prototype.get=function(h){if(!ge(h))throw new TypeError("Array expected");if(h.length!==this._size.length)throw new Zt(h.length,this._size.length);for(var c=0;c<h.length;c++)ve(h[c],this._size[c]);for(var m=this._data,_=0,w=h.length;_<w;_++){var g=h[_];ve(g,m.length),m=m[g]}return m},e.prototype.set=function(h,c,m){if(!ge(h))throw new TypeError("Array expected");if(h.length<this._size.length)throw new Zt(h.length,this._size.length,"<");var _,w,g,y=h.map(function(E){return E+1});f(this,y,m);var v=this._data;for(_=0,w=h.length-1;_<w;_++)g=h[_],ve(g,v.length),v=v[g];return g=h[h.length-1],ve(g,v.length),v[g]=c,this};function r(h,c){if(!na(c))throw new TypeError("Invalid index");var m=c.isScalar();if(m)return h.get(c.min());var _=c.size();if(_.length!==h._size.length)throw new Zt(_.length,h._size.length);for(var w=c.min(),g=c.max(),y=0,v=h._size.length;y<v;y++)ve(w[y],h._size[y]),ve(g[y],h._size[y]);return new e(n(h._data,c,_.length,0),h._datatype)}function n(h,c,m,_){var w=_===m-1,g=c.dimension(_);return w?g.map(function(y){return ve(y,h.length),h[y]}).valueOf():g.map(function(y){ve(y,h.length);var v=h[y];return n(v,c,m,_+1)}).valueOf()}function s(h,c,m,_){if(!c||c.isIndex!==!0)throw new TypeError("Invalid index");var w=c.size(),g=c.isScalar(),y;if(fe(m)?(y=m.size(),m=m.valueOf()):y=Ae(m),g){if(y.length!==0)throw new TypeError("Scalar expected");h.set(c.min(),m,_)}else{if(!ni(y,w))try{y.length===0?m=Vl([m],w):m=Vl(m,w),y=Ae(m)}catch{}if(w.length<h._size.length)throw new Zt(w.length,h._size.length,"<");if(y.length<w.length){for(var v=0,E=0;w[v]===1&&y[v]===1;)v++;for(;w[v]===1;)E++,v++;m=Kl(m,w.length,E,y)}if(!ni(w,y))throw new Zt(w,y,">");var b=c.max().map(function(F){return F+1});f(h,b,_);var N=w.length,x=0;u(h._data,c,m,N,x)}return h}function u(h,c,m,_,w){var g=w===_-1,y=c.dimension(w);g?y.forEach(function(v,E){ve(v),h[v]=m[E[0]]}):y.forEach(function(v,E){ve(v),u(h[v],c,m[E[0]],_,w+1)})}e.prototype.resize=function(h,c,m){if(!qi(h))throw new TypeError("Array or Matrix expected");var _=h.valueOf().map(g=>Array.isArray(g)&&g.length===1?g[0]:g),w=m?this.clone():this;return l(w,_,c)};function l(h,c,m){if(c.length===0){for(var _=h._data;ge(_);)_=_[0];return _}return h._size=c.slice(0),h._data=ua(h._data,h._size,m),h}e.prototype.reshape=function(h,c){var m=c?this.clone():this;m._data=fa(m._data,h);var _=m._size.reduce((w,g)=>w*g);return m._size=ca(h,_),m};function f(h,c,m){for(var _=h._size.slice(0),w=!1;_.length<c.length;)_.push(0),w=!0;for(var g=0,y=c.length;g<y;g++)c[g]>_[g]&&(_[g]=c[g],w=!0);w&&l(h,_,m)}e.prototype.clone=function(){var h=new e({data:te(this._data),size:te(this._size),datatype:this._datatype});return h},e.prototype.size=function(){return this._size.slice(0)},e.prototype.map=function(h){var c=this,m=wf(h),_=function y(v,E){return ge(v)?v.map(function(b,N){return y(b,E.concat(N))}):m===1?h(v):m===2?h(v,E):h(v,E,c)},w=_(this._data,[]),g=this._datatype!==void 0?Es(w,cn):void 0;return new e(w,g)},e.prototype.forEach=function(h){var c=this,m=function _(w,g){ge(w)?w.forEach(function(y,v){_(y,g.concat(v))}):h(w,g,c)};m(this._data,[])},e.prototype[Symbol.iterator]=function*(){var h=function*c(m,_){if(ge(m))for(var w=0;w<m.length;w++)yield*c(m[w],_.concat(w));else yield{value:m,index:_}};yield*h(this._data,[])},e.prototype.rows=function(){var h=[],c=this.size();if(c.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");var m=this._data;for(var _ of m)h.push(new e([_],this._datatype));return h},e.prototype.columns=function(){var h=this,c=[],m=this.size();if(m.length!==2)throw new TypeError("Rows can only be returned for a 2D matrix.");for(var _=this._data,w=function(v){var E=_.map(b=>[b[v]]);c.push(new e(E,h._datatype))},g=0;g<m[1];g++)w(g);return c},e.prototype.toArray=function(){return te(this._data)},e.prototype.valueOf=function(){return this._data},e.prototype.format=function(h){return se(this._data,h)},e.prototype.toString=function(){return se(this._data)},e.prototype.toJSON=function(){return{mathjs:"DenseMatrix",data:this._data,size:this._size,datatype:this._datatype}},e.prototype.diagonal=function(h){if(h){if(ye(h)&&(h=h.toNumber()),!ue(h)||!he(h))throw new TypeError("The parameter k must be an integer number")}else h=0;for(var c=h>0?h:0,m=h<0?-h:0,_=this._size[0],w=this._size[1],g=Math.min(_-m,w-c),y=[],v=0;v<g;v++)y[v]=this._data[v+m][v+c];return new e({data:y,size:[g],datatype:this._datatype})},e.diagonal=function(h,c,m,_){if(!ge(h))throw new TypeError("Array expected, size parameter");if(h.length!==2)throw new Error("Only two dimensions matrix are supported");if(h=h.map(function(M){if(ye(M)&&(M=M.toNumber()),!ue(M)||!he(M)||M<1)throw new Error("Size values must be positive integers");return M}),m){if(ye(m)&&(m=m.toNumber()),!ue(m)||!he(m))throw new TypeError("The parameter k must be an integer number")}else m=0;var w=m>0?m:0,g=m<0?-m:0,y=h[0],v=h[1],E=Math.min(y-g,v-w),b;if(ge(c)){if(c.length!==E)throw new Error("Invalid value array length");b=function(S){return c[S]}}else if(fe(c)){var N=c.size();if(N.length!==1||N[0]!==E)throw new Error("Invalid matrix length");b=function(S){return c.get([S])}}else b=function(){return c};_||(_=ye(b(0))?b(0).mul(0):0);var x=[];if(h.length>0){x=ua(x,h,_);for(var F=0;F<E;F++)x[F+g][F+w]=b(F)}return new e({data:x,size:[y,v]})},e.fromJSON=function(h){return new e(h)},e.prototype.swapRows=function(h,c){if(!ue(h)||!he(h)||!ue(c)||!he(c))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return ve(h,this._size[0]),ve(c,this._size[0]),e._swapRows(h,c,this._data),this},e._swapRows=function(h,c,m){var _=m[h];m[h]=m[c],m[c]=_};function p(h){return fe(h)?p(h.valueOf()):ge(h)?h.map(p):h}return e},{isClass:!0});function tg(i){var t=i.length,e=i[0].length,r,n,s=[];for(n=0;n<e;n++){var u=[];for(r=0;r<t;r++)u.push(i[r][n]);s.push(u)}return s}function Ts(i){for(var t=0;t<i.length;t++)if(qi(i[t]))return!0;return!1}function Wi(i,t){fe(i)&&(i=i.valueOf());for(var e=0,r=i.length;e<r;e++){var n=i[e];Array.isArray(n)?Wi(n,t):t(n)}}function Ir(i,t,e){return i&&typeof i.map=="function"?i.map(function(r){return Ir(r,t)}):t(i)}function ya(i,t,e){var r=Array.isArray(i)?Ae(i):i.size();if(t<0||t>=r.length)throw new hn(t,r.length);return fe(i)?i.create($s(i.valueOf(),t,e)):$s(i,t,e)}function $s(i,t,e){var r,n,s,u;if(t<=0)if(Array.isArray(i[0])){for(u=tg(i),n=[],r=0;r<u.length;r++)n[r]=$s(u[r],t-1,e);return n}else{for(s=i[0],r=1;r<i.length;r++)s=e(s,i[r]);return s}else{for(n=[],r=0;r<i.length;r++)n[r]=$s(i[r],t-1,e);return n}}var Df="isInteger",eg=["typed"],rg=mt(Df,eg,i=>{var{typed:t}=i;return t(Df,{number:he,BigNumber:function(r){return r.isInt()},Fraction:function(r){return r.d===1&&isFinite(r.n)},"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),yf="number",Os="number, number";function bf(i){return Math.abs(i)}bf.signature=yf;function Ef(i,t){return i+t}Ef.signature=Os;function Af(i,t){return i-t}Af.signature=Os;function xf(i,t){return i*t}xf.signature=Os;function Cf(i){return-i}Cf.signature=yf;function Ff(i,t){return i*i<1&&t===1/0||i*i>1&&t===-1/0?0:Math.pow(i,t)}Ff.signature=Os;var Mf="number";function Nf(i){return i===0}Nf.signature=Mf;function Sf(i){return Number.isNaN(i)}Sf.signature=Mf;var Bf="isNumeric",ng=["typed"],ig=mt(Bf,ng,i=>{var{typed:t}=i;return t(Bf,{"number | BigNumber | Fraction | boolean":()=>!0,"Complex | Unit | string | null | undefined | Node":()=>!1,"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),If="isZero",sg=["typed"],og=mt(If,sg,i=>{var{typed:t}=i;return t(If,{number:Nf,BigNumber:function(r){return r.isZero()},Complex:function(r){return r.re===0&&r.im===0},Fraction:function(r){return r.d===1&&r.n===0},Unit:t.referToSelf(e=>r=>t.find(e,r.valueType())(r.value)),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),Tf="isNaN",ag=["typed"],ug=mt(Tf,ag,i=>{var{typed:t}=i;return t(Tf,{number:Sf,BigNumber:function(r){return r.isNaN()},Fraction:function(r){return!1},Complex:function(r){return r.isNaN()},Unit:function(r){return Number.isNaN(r.value)},"Array | Matrix":function(r){return Ir(r,Number.isNaN)}})});function Rs(i,t,e){if(e==null)return i.eq(t);if(i.eq(t))return!0;if(i.isNaN()||t.isNaN())return!1;if(i.isFinite()&&t.isFinite()){var r=i.minus(t).abs();if(r.isZero())return!0;var n=i.constructor.max(i.abs(),t.abs());return r.lte(n.times(e))}return!1}function lg(i,t,e){return zn(i.re,t.re,e)&&zn(i.im,t.im,e)}var Ls=mt("compareUnits",["typed"],i=>{var{typed:t}=i;return{"Unit, Unit":t.referToSelf(e=>(r,n)=>{if(!r.equalBase(n))throw new Error("Cannot compare units with different base");return t.find(e,[r.valueType(),n.valueType()])(r.value,n.value)})}}),Ps="equalScalar",fg=["typed","config"],cg=mt(Ps,fg,i=>{var{typed:t,config:e}=i,r=Ls({typed:t});return t(Ps,{"boolean, boolean":function(s,u){return s===u},"number, number":function(s,u){return zn(s,u,e.epsilon)},"BigNumber, BigNumber":function(s,u){return s.eq(u)||Rs(s,u,e.epsilon)},"Fraction, Fraction":function(s,u){return s.equals(u)},"Complex, Complex":function(s,u){return lg(s,u,e.epsilon)}},r)});mt(Ps,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Ps,{"number, number":function(n,s){return zn(n,s,e.epsilon)}})});var hg="SparseMatrix",pg=["typed","equalScalar","Matrix"],dg=mt(hg,pg,i=>{var{typed:t,equalScalar:e,Matrix:r}=i;function n(g,y){if(!(this instanceof n))throw new SyntaxError("Constructor must be called with the new operator");if(y&&!Ur(y))throw new Error("Invalid datatype: "+y);if(fe(g))s(this,g,y);else if(g&&ge(g.index)&&ge(g.ptr)&&ge(g.size))this._values=g.values,this._index=g.index,this._ptr=g.ptr,this._size=g.size,this._datatype=y||g.datatype;else if(ge(g))u(this,g,y);else{if(g)throw new TypeError("Unsupported type of data ("+cn(g)+")");this._values=[],this._index=[],this._ptr=[0],this._size=[0,0],this._datatype=y}}function s(g,y,v){y.type==="SparseMatrix"?(g._values=y._values?te(y._values):void 0,g._index=te(y._index),g._ptr=te(y._ptr),g._size=te(y._size),g._datatype=v||y._datatype):u(g,y.valueOf(),v||y._datatype)}function u(g,y,v){g._values=[],g._index=[],g._ptr=[],g._datatype=v;var E=y.length,b=0,N=e,x=0;if(Ur(v)&&(N=t.find(e,[v,v])||e,x=t.convert(0,v)),E>0){var F=0;do{g._ptr.push(g._index.length);for(var M=0;M<E;M++){var S=y[M];if(ge(S)){if(F===0&&b<S.length&&(b=S.length),F<S.length){var $=S[F];N($,x)||(g._values.push($),g._index.push(M))}}else F===0&&b<1&&(b=1),N(S,x)||(g._values.push(S),g._index.push(M))}F++}while(F<b)}g._ptr.push(g._index.length),g._size=[E,b]}n.prototype=new r,n.prototype.createSparseMatrix=function(g,y){return new n(g,y)},Object.defineProperty(n,"name",{value:"SparseMatrix"}),n.prototype.constructor=n,n.prototype.type="SparseMatrix",n.prototype.isSparseMatrix=!0,n.prototype.getDataType=function(){return Es(this._values,cn)},n.prototype.storage=function(){return"sparse"},n.prototype.datatype=function(){return this._datatype},n.prototype.create=function(g,y){return new n(g,y)},n.prototype.density=function(){var g=this._size[0],y=this._size[1];return g!==0&&y!==0?this._index.length/(g*y):0},n.prototype.subset=function(g,y,v){if(!this._values)throw new Error("Cannot invoke subset on a Pattern only matrix");switch(arguments.length){case 1:return l(this,g);case 2:case 3:return f(this,g,y,v);default:throw new SyntaxError("Wrong number of arguments")}};function l(g,y){if(!na(y))throw new TypeError("Invalid index");var v=y.isScalar();if(v)return g.get(y.min());var E=y.size();if(E.length!==g._size.length)throw new Zt(E.length,g._size.length);var b,N,x,F,M=y.min(),S=y.max();for(b=0,N=g._size.length;b<N;b++)ve(M[b],g._size[b]),ve(S[b],g._size[b]);var $=g._values,C=g._index,I=g._ptr,R=y.dimension(0),U=y.dimension(1),q=[],k=[];R.forEach(function(V,tt){k[V]=tt[0],q[V]=!0});var P=$?[]:void 0,K=[],G=[];return U.forEach(function(V){for(G.push(K.length),x=I[V],F=I[V+1];x<F;x++)b=C[x],q[b]===!0&&(K.push(k[b]),P&&P.push($[x]))}),G.push(K.length),new n({values:P,index:K,ptr:G,size:E,datatype:g._datatype})}function f(g,y,v,E){if(!y||y.isIndex!==!0)throw new TypeError("Invalid index");var b=y.size(),N=y.isScalar(),x;if(fe(v)?(x=v.size(),v=v.toArray()):x=Ae(v),N){if(x.length!==0)throw new TypeError("Scalar expected");g.set(y.min(),v,E)}else{if(b.length!==1&&b.length!==2)throw new Zt(b.length,g._size.length,"<");if(x.length<b.length){for(var F=0,M=0;b[F]===1&&x[F]===1;)F++;for(;b[F]===1;)M++,F++;v=Kl(v,b.length,M,x)}if(!ni(b,x))throw new Zt(b,x,">");if(b.length===1){var S=y.dimension(0);S.forEach(function(I,R){ve(I),g.set([I,0],v[R[0]],E)})}else{var $=y.dimension(0),C=y.dimension(1);$.forEach(function(I,R){ve(I),C.forEach(function(U,q){ve(U),g.set([I,U],v[R[0]][q[0]],E)})})}}return g}n.prototype.get=function(g){if(!ge(g))throw new TypeError("Array expected");if(g.length!==this._size.length)throw new Zt(g.length,this._size.length);if(!this._values)throw new Error("Cannot invoke get on a Pattern only matrix");var y=g[0],v=g[1];ve(y,this._size[0]),ve(v,this._size[1]);var E=p(y,this._ptr[v],this._ptr[v+1],this._index);return E<this._ptr[v+1]&&this._index[E]===y?this._values[E]:0},n.prototype.set=function(g,y,v){if(!ge(g))throw new TypeError("Array expected");if(g.length!==this._size.length)throw new Zt(g.length,this._size.length);if(!this._values)throw new Error("Cannot invoke set on a Pattern only matrix");var E=g[0],b=g[1],N=this._size[0],x=this._size[1],F=e,M=0;Ur(this._datatype)&&(F=t.find(e,[this._datatype,this._datatype])||e,M=t.convert(0,this._datatype)),(E>N-1||b>x-1)&&(m(this,Math.max(E+1,N),Math.max(b+1,x),v),N=this._size[0],x=this._size[1]),ve(E,N),ve(b,x);var S=p(E,this._ptr[b],this._ptr[b+1],this._index);return S<this._ptr[b+1]&&this._index[S]===E?F(y,M)?h(S,b,this._values,this._index,this._ptr):this._values[S]=y:F(y,M)||c(S,E,b,y,this._values,this._index,this._ptr),this};function p(g,y,v,E){if(v-y===0)return v;for(var b=y;b<v;b++)if(E[b]===g)return b;return y}function h(g,y,v,E,b){v.splice(g,1),E.splice(g,1);for(var N=y+1;N<b.length;N++)b[N]--}function c(g,y,v,E,b,N,x){b.splice(g,0,E),N.splice(g,0,y);for(var F=v+1;F<x.length;F++)x[F]++}n.prototype.resize=function(g,y,v){if(!qi(g))throw new TypeError("Array or Matrix expected");var E=g.valueOf().map(N=>Array.isArray(N)&&N.length===1?N[0]:N);if(E.length!==2)throw new Error("Only two dimensions matrix are supported");E.forEach(function(N){if(!ue(N)||!he(N)||N<0)throw new TypeError("Invalid size, must contain positive integers (size: "+se(E)+")")});var b=v?this.clone():this;return m(b,E[0],E[1],y)};function m(g,y,v,E){var b=E||0,N=e,x=0;Ur(g._datatype)&&(N=t.find(e,[g._datatype,g._datatype])||e,x=t.convert(0,g._datatype),b=t.convert(b,g._datatype));var F=!N(b,x),M=g._size[0],S=g._size[1],$,C,I;if(v>S){for(C=S;C<v;C++)if(g._ptr[C]=g._values.length,F)for($=0;$<M;$++)g._values.push(b),g._index.push($);g._ptr[v]=g._values.length}else v<S&&(g._ptr.splice(v+1,S-v),g._values.splice(g._ptr[v],g._values.length),g._index.splice(g._ptr[v],g._index.length));if(S=v,y>M){if(F){var R=0;for(C=0;C<S;C++){g._ptr[C]=g._ptr[C]+R,I=g._ptr[C+1]+R;var U=0;for($=M;$<y;$++,U++)g._values.splice(I+U,0,b),g._index.splice(I+U,0,$),R++}g._ptr[S]=g._values.length}}else if(y<M){var q=0;for(C=0;C<S;C++){g._ptr[C]=g._ptr[C]-q;var k=g._ptr[C],P=g._ptr[C+1]-q;for(I=k;I<P;I++)$=g._index[I],$>y-1&&(g._values.splice(I,1),g._index.splice(I,1),q++)}g._ptr[C]=g._values.length}return g._size[0]=y,g._size[1]=v,g}n.prototype.reshape=function(g,y){if(!ge(g))throw new TypeError("Array expected");if(g.length!==2)throw new Error("Sparse matrices can only be reshaped in two dimensions");g.forEach(function(V){if(!ue(V)||!he(V)||V<=-2||V===0)throw new TypeError("Invalid size, must contain positive integers or -1 (size: "+se(g)+")")});var v=this._size[0]*this._size[1];g=ca(g,v);var E=g[0]*g[1];if(v!==E)throw new Error("Reshaping sparse matrix will result in the wrong number of elements");var b=y?this.clone():this;if(this._size[0]===g[0]&&this._size[1]===g[1])return b;for(var N=[],x=0;x<b._ptr.length;x++)for(var F=0;F<b._ptr[x+1]-b._ptr[x];F++)N.push(x);for(var M=b._values.slice(),S=b._index.slice(),$=0;$<b._index.length;$++){var C=S[$],I=N[$],R=C*b._size[1]+I;N[$]=R%g[1],S[$]=Math.floor(R/g[1])}b._values.length=0,b._index.length=0,b._ptr.length=g[1]+1,b._size=g.slice();for(var U=0;U<b._ptr.length;U++)b._ptr[U]=0;for(var q=0;q<M.length;q++){var k=S[q],P=N[q],K=M[q],G=p(k,b._ptr[P],b._ptr[P+1],b._index);c(G,k,P,K,b._values,b._index,b._ptr)}return b},n.prototype.clone=function(){var g=new n({values:this._values?te(this._values):void 0,index:te(this._index),ptr:te(this._ptr),size:te(this._size),datatype:this._datatype});return g},n.prototype.size=function(){return this._size.slice(0)},n.prototype.map=function(g,y){if(!this._values)throw new Error("Cannot invoke map on a Pattern only matrix");var v=this,E=this._size[0],b=this._size[1],N=wf(g),x=function(M,S,$){return N===1?g(M):N===2?g(M,[S,$]):g(M,[S,$],v)};return _(this,0,E-1,0,b-1,x,y)};function _(g,y,v,E,b,N,x){var F=[],M=[],S=[],$=e,C=0;Ur(g._datatype)&&($=t.find(e,[g._datatype,g._datatype])||e,C=t.convert(0,g._datatype));for(var I=function(lt,wt,yt){lt=N(lt,wt,yt),$(lt,C)||(F.push(lt),M.push(wt))},R=E;R<=b;R++){S.push(F.length);var U=g._ptr[R],q=g._ptr[R+1];if(x)for(var k=U;k<q;k++){var P=g._index[k];P>=y&&P<=v&&I(g._values[k],P-y,R-E)}else{for(var K={},G=U;G<q;G++){var V=g._index[G];K[V]=g._values[G]}for(var tt=y;tt<=v;tt++){var ft=tt in K?K[tt]:0;I(ft,tt-y,R-E)}}}return S.push(F.length),new n({values:F,index:M,ptr:S,size:[v-y+1,b-E+1]})}n.prototype.forEach=function(g,y){if(!this._values)throw new Error("Cannot invoke forEach on a Pattern only matrix");for(var v=this,E=this._size[0],b=this._size[1],N=0;N<b;N++){var x=this._ptr[N],F=this._ptr[N+1];if(y)for(var M=x;M<F;M++){var S=this._index[M];g(this._values[M],[S,N],v)}else{for(var $={},C=x;C<F;C++){var I=this._index[C];$[I]=this._values[C]}for(var R=0;R<E;R++){var U=R in $?$[R]:0;g(U,[R,N],v)}}}},n.prototype[Symbol.iterator]=function*(){if(!this._values)throw new Error("Cannot iterate a Pattern only matrix");for(var g=this._size[1],y=0;y<g;y++)for(var v=this._ptr[y],E=this._ptr[y+1],b=v;b<E;b++){var N=this._index[b];yield{value:this._values[b],index:[N,y]}}},n.prototype.toArray=function(){return w(this._values,this._index,this._ptr,this._size,!0)},n.prototype.valueOf=function(){return w(this._values,this._index,this._ptr,this._size,!1)};function w(g,y,v,E,b){var N=E[0],x=E[1],F=[],M,S;for(M=0;M<N;M++)for(F[M]=[],S=0;S<x;S++)F[M][S]=0;for(S=0;S<x;S++)for(var $=v[S],C=v[S+1],I=$;I<C;I++)M=y[I],F[M][S]=g?b?te(g[I]):g[I]:1;return F}return n.prototype.format=function(g){for(var y=this._size[0],v=this._size[1],E=this.density(),b="Sparse Matrix ["+se(y,g)+" x "+se(v,g)+"] density: "+se(E,g)+`
53
53
  `,N=0;N<v;N++)for(var x=this._ptr[N],F=this._ptr[N+1],M=x;M<F;M++){var S=this._index[M];b+=`
54
- (`+se(S,g)+", "+se(N,g)+") ==> "+(this._values?se(this._values[M],g):"X")}return b},n.prototype.toString=function(){return se(this.toArray())},n.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(g){if(g){if(ye(g)&&(g=g.toNumber()),!ue(g)||!he(g))throw new TypeError("The parameter k must be an integer number")}else g=0;var y=g>0?g:0,v=g<0?-g:0,E=this._size[0],b=this._size[1],N=Math.min(E-v,b-y),x=[],F=[],M=[];M[0]=0;for(var S=y;S<b&&x.length<N;S++)for(var $=this._ptr[S],C=this._ptr[S+1],I=$;I<C;I++){var R=this._index[I];if(R===S-y+v){x.push(this._values[I]),F[x.length-1]=R-v;break}}return M.push(x.length),new n({values:x,index:F,ptr:M,size:[N,1]})},n.fromJSON=function(g){return new n(g)},n.diagonal=function(g,y,v,E,b){if(!ge(g))throw new TypeError("Array expected, size parameter");if(g.length!==2)throw new Error("Only two dimensions matrix are supported");if(g=g.map(function(V){if(ye(V)&&(V=V.toNumber()),!ue(V)||!he(V)||V<1)throw new Error("Size values must be positive integers");return V}),v){if(ye(v)&&(v=v.toNumber()),!ue(v)||!he(v))throw new TypeError("The parameter k must be an integer number")}else v=0;var N=e,x=0;Ur(b)&&(N=t.find(e,[b,b])||e,x=t.convert(0,b));var F=v>0?v:0,M=v<0?-v:0,S=g[0],$=g[1],C=Math.min(S-M,$-F),I;if(ge(y)){if(y.length!==C)throw new Error("Invalid value array length");I=function(tt){return y[tt]}}else if(fe(y)){var R=y.size();if(R.length!==1||R[0]!==C)throw new Error("Invalid matrix length");I=function(tt){return y.get([tt])}}else I=function(){return y};for(var U=[],q=[],k=[],P=0;P<$;P++){k.push(U.length);var K=P-F;if(K>=0&&K<C){var G=I(K);N(G,x)||(q.push(K+M),U.push(G))}}return k.push(U.length),new n({values:U,index:q,ptr:k,size:[S,$]})},n.prototype.swapRows=function(g,y){if(!ue(g)||!he(g)||!ue(y)||!he(y))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return ve(g,this._size[0]),ve(y,this._size[0]),n._swapRows(g,y,this._size[1],this._values,this._index,this._ptr),this},n._forEachRow=function(g,y,v,E,b){for(var N=E[g],x=E[g+1],F=N;F<x;F++)b(v[F],y[F])},n._swapRows=function(g,y,v,E,b,N){for(var x=0;x<v;x++){var F=N[x],M=N[x+1],S=p(g,F,M,b),$=p(y,F,M,b);if(S<M&&$<M&&b[S]===g&&b[$]===y){if(E){var C=E[S];E[S]=E[$],E[$]=C}continue}if(S<M&&b[S]===g&&($>=M||b[$]!==y)){var I=E?E[S]:void 0;b.splice($,0,y),E&&E.splice($,0,I),b.splice($<=S?S+1:S,1),E&&E.splice($<=S?S+1:S,1);continue}if($<M&&b[$]===y&&(S>=M||b[S]!==g)){var R=E?E[$]:void 0;b.splice(S,0,g),E&&E.splice(S,0,R),b.splice(S<=$?$+1:$,1),E&&E.splice(S<=$?$+1:$,1)}}},n},{isClass:!0}),mg="number",gg=["typed"];function vg(i){var t=i.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(t){var e={"0b":2,"0o":8,"0x":16}[t[1]],r=t[2],n=t[3];return{input:i,radix:e,integerPart:r,fractionalPart:n}}else return null}function _g(i){for(var t=parseInt(i.integerPart,i.radix),e=0,r=0;r<i.fractionalPart.length;r++){var n=parseInt(i.fractionalPart[r],i.radix);e+=n/Math.pow(i.radix,r+1)}var s=t+e;if(isNaN(s))throw new SyntaxError('String "'+i.input+'" is not a valid number');return s}var wg=mt(mg,gg,i=>{var{typed:t}=i,e=t("number",{"":function(){return 0},number:function(n){return n},string:function(n){if(n==="NaN")return NaN;var s=vg(n);if(s)return _g(s);var u=0,l=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);l&&(u=Number(l[2]),n=l[1]);var f=Number(n);if(isNaN(f))throw new SyntaxError('String "'+n+'" is not a valid number');if(l){if(f>2**u-1)throw new SyntaxError('String "'.concat(n,'" is out of range'));f>=2**(u-1)&&(f=f-2**u)}return f},BigNumber:function(n){return n.toNumber()},Fraction:function(n){return n.valueOf()},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),null:function(n){return 0},"Unit, string | Unit":function(n,s){return n.toNumber(s)},"Array | Matrix":t.referToSelf(r=>n=>Ir(n,r))});return e.fromJSON=function(r){return parseFloat(r.value)},e}),Dg="bignumber",yg=["typed","BigNumber"],bg=mt(Dg,yg,i=>{var{typed:t,BigNumber:e}=i;return t("bignumber",{"":function(){return new e(0)},number:function(n){return new e(n+"")},string:function(n){var s=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(s){var u=s[2],l=e(s[1]),f=new e(2).pow(Number(u));if(l.gt(f.sub(1)))throw new SyntaxError('String "'.concat(n,'" is out of range'));var p=new e(2).pow(Number(u)-1);return l.gte(p)?l.sub(f):l}return new e(n)},BigNumber:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Fraction:function(n){return new e(n.n).div(n.d).times(n.s)},null:function(n){return new e(0)},"Array | Matrix":t.referToSelf(r=>n=>Ir(n,r))})}),Eg="fraction",Ag=["typed","Fraction"],xg=mt(Eg,Ag,i=>{var{typed:t,Fraction:e}=i;return t("fraction",{number:function(n){if(!isFinite(n)||isNaN(n))throw new Error(n+" cannot be represented as a fraction");return new e(n)},string:function(n){return new e(n)},"number, number":function(n,s){return new e(n,s)},null:function(n){return new e(0)},BigNumber:function(n){return new e(n.toString())},Fraction:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Object:function(n){return new e(n)},"Array | Matrix":t.referToSelf(r=>n=>Ir(n,r))})}),$f="matrix",Cg=["typed","Matrix","DenseMatrix","SparseMatrix"],Fg=mt($f,Cg,i=>{var{typed:t,Matrix:e,DenseMatrix:r,SparseMatrix:n}=i;return t($f,{"":function(){return s([])},string:function(l){return s([],l)},"string, string":function(l,f){return s([],l,f)},Array:function(l){return s(l)},Matrix:function(l){return s(l,l.storage())},"Array | Matrix, string":s,"Array | Matrix, string, string":s});function s(u,l,f){if(l==="dense"||l==="default"||l===void 0)return new r(u,f);if(l==="sparse")return new n(u,f);throw new TypeError("Unknown matrix type "+JSON.stringify(l)+".")}}),Of="unaryMinus",Mg=["typed"],Ng=mt(Of,Mg,i=>{var{typed:t}=i;return t(Of,{number:Cf,"Complex | BigNumber | Fraction":e=>e.neg(),Unit:t.referToSelf(e=>r=>{var n=r.clone();return n.value=t.find(e,n.valueType())(r.value),n}),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),Rf="abs",Sg=["typed"],Bg=mt(Rf,Sg,i=>{var{typed:t}=i;return t(Rf,{number:bf,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),Lf="addScalar",Ig=["typed"],Tg=mt(Lf,Ig,i=>{var{typed:t}=i;return t(Lf,{"number, number":Ef,"Complex, Complex":function(r,n){return r.add(n)},"BigNumber, BigNumber":function(r,n){return r.plus(n)},"Fraction, Fraction":function(r,n){return r.add(n)},"Unit, Unit":t.referToSelf(e=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),Pf="subtractScalar",$g=["typed"],Og=mt(Pf,$g,i=>{var{typed:t}=i;return t(Pf,{"number, number":Af,"Complex, Complex":function(r,n){return r.sub(n)},"BigNumber, BigNumber":function(r,n){return r.minus(n)},"Fraction, Fraction":function(r,n){return r.sub(n)},"Unit, Unit":t.referToSelf(e=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),Rg="matAlgo11xS0s",Lg=["typed","equalScalar"],ba=mt(Rg,Lg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u,l){var f=n._values,p=n._index,h=n._ptr,c=n._size,m=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var _=c[0],w=c[1],g,y=e,v=0,E=u;typeof m=="string"&&(g=m,y=t.find(e,[g,g]),v=t.convert(0,g),s=t.convert(s,g),E=t.find(u,[g,g]));for(var b=[],N=[],x=[],F=0;F<w;F++){x[F]=N.length;for(var M=h[F],S=h[F+1],$=M;$<S;$++){var C=p[$],I=l?E(s,f[$]):E(f[$],s);y(I,v)||(N.push(C),b.push(I))}}return x[w]=N.length,n.createSparseMatrix({values:b,index:N,ptr:x,size:[_,w],datatype:g})}}),Pg="matAlgo12xSfs",zg=["typed","DenseMatrix"],li=mt(Pg,zg,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,u,l){var f=n._values,p=n._index,h=n._ptr,c=n._size,m=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var _=c[0],w=c[1],g,y=u;typeof m=="string"&&(g=m,s=t.convert(s,g),y=t.find(u,[g,g]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=h[N],M=h[N+1],S=F;S<M;S++){var $=p[S];E[$]=f[S],b[$]=x}for(var C=0;C<_;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?y(s,E[C]):y(E[C],s):v[C][N]=l?y(s,0):y(0,s)}return new e({data:v,size:[_,w],datatype:g})}}),qg="matAlgo14xDs",Ug=["typed"],Ea=mt(qg,Ug,i=>{var{typed:t}=i;return function(n,s,u,l){var f=n._data,p=n._size,h=n._datatype,c,m=u;typeof h=="string"&&(c=h,s=t.convert(s,c),m=t.find(u,[c,c]));var _=p.length>0?e(m,0,p,p[0],f,s,l):[];return n.createDenseMatrix({data:_,size:te(p),datatype:c})};function e(r,n,s,u,l,f,p){var h=[];if(n===s.length-1)for(var c=0;c<u;c++)h[c]=p?r(f,l[c]):r(l[c],f);else for(var m=0;m<u;m++)h[m]=e(r,n+1,s,s[n+1],l[m],f,p);return h}}),kg="matAlgo02xDS0",Wg=["typed","equalScalar"],Yg=mt(kg,Wg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u,l){var f=n._data,p=n._size,h=n._datatype||n.getDataType(),c=s._values,m=s._index,_=s._ptr,w=s._size,g=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(p.length!==w.length)throw new Zt(p.length,w.length);if(p[0]!==w[0]||p[1]!==w[1])throw new RangeError("Dimension mismatch. Matrix A ("+p+") must match Matrix B ("+w+")");if(!c)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var y=p[0],v=p[1],E,b=e,N=0,x=u;typeof h=="string"&&h===g&&h!=="mixed"&&(E=h,b=t.find(e,[E,E]),N=t.convert(0,E),x=t.find(u,[E,E]));for(var F=[],M=[],S=[],$=0;$<v;$++){S[$]=M.length;for(var C=_[$],I=_[$+1],R=C;R<I;R++){var U=m[R],q=l?x(c[R],f[U][$]):x(f[U][$],c[R]);b(q,N)||(M.push(U),F.push(q))}}return S[v]=M.length,s.createSparseMatrix({values:F,index:M,ptr:S,size:[y,v],datatype:h===n._datatype&&g===s._datatype?E:void 0})}}),jg="matAlgo03xDSf",Zg=["typed"],fi=mt(jg,Zg,i=>{var{typed:t}=i;return function(r,n,s,u){var l=r._data,f=r._size,p=r._datatype||r.getDataType(),h=n._values,c=n._index,m=n._ptr,_=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==_.length)throw new Zt(f.length,_.length);if(f[0]!==_[0]||f[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+_+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var g=f[0],y=f[1],v,E=0,b=s;typeof p=="string"&&p===w&&p!=="mixed"&&(v=p,E=t.convert(0,v),b=t.find(s,[v,v]));for(var N=[],x=0;x<g;x++)N[x]=[];for(var F=[],M=[],S=0;S<y;S++){for(var $=S+1,C=m[S],I=m[S+1],R=C;R<I;R++){var U=c[R];F[U]=u?b(h[R],l[U][S]):b(l[U][S],h[R]),M[U]=$}for(var q=0;q<g;q++)M[q]===$?N[q][S]=F[q]:N[q][S]=u?b(E,l[q][S]):b(l[q][S],E)}return r.createDenseMatrix({data:N,size:[g,y],datatype:p===r._datatype&&w===n._datatype?v:void 0})}}),Gg="matAlgo05xSfSf",Kg=["typed","equalScalar"],zf=mt(Gg,Kg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u){var l=n._values,f=n._index,p=n._ptr,h=n._size,c=n._datatype||n._data===void 0?n._datatype:n.getDataType(),m=s._values,_=s._index,w=s._ptr,g=s._size,y=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(h.length!==g.length)throw new Zt(h.length,g.length);if(h[0]!==g[0]||h[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+g+")");var v=h[0],E=h[1],b,N=e,x=0,F=u;typeof c=="string"&&c===y&&c!=="mixed"&&(b=c,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(u,[b,b]));var M=l&&m?[]:void 0,S=[],$=[],C=M?[]:void 0,I=M?[]:void 0,R=[],U=[],q,k,P,K;for(k=0;k<E;k++){$[k]=S.length;var G=k+1;for(P=p[k],K=p[k+1];P<K;P++)q=f[P],S.push(q),R[q]=G,C&&(C[q]=l[P]);for(P=w[k],K=w[k+1];P<K;P++)q=_[P],R[q]!==G&&S.push(q),U[q]=G,I&&(I[q]=m[P]);if(M)for(P=$[k];P<S.length;){q=S[P];var V=R[q],tt=U[q];if(V===G||tt===G){var ft=V===G?C[q]:x,vt=tt===G?I[q]:x,lt=F(ft,vt);N(lt,x)?S.splice(P,1):(M.push(lt),P++)}}}return $[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:$,size:[v,E],datatype:c===n._datatype&&y===s._datatype?b:void 0})}}),Hg="matAlgo13xDD",Jg=["typed"],Xg=mt(Hg,Jg,i=>{var{typed:t}=i;return function(n,s,u){var l=n._data,f=n._size,p=n._datatype,h=s._data,c=s._size,m=s._datatype,_=[];if(f.length!==c.length)throw new Zt(f.length,c.length);for(var w=0;w<f.length;w++){if(f[w]!==c[w])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+c+")");_[w]=f[w]}var g,y=u;typeof p=="string"&&p===m&&(g=p,y=t.find(u,[g,g]));var v=_.length>0?e(y,0,_,_[0],l,h):[];return n.createDenseMatrix({data:v,size:_,datatype:g})};function e(r,n,s,u,l,f){var p=[];if(n===s.length-1)for(var h=0;h<u;h++)p[h]=r(l[h],f[h]);else for(var c=0;c<u;c++)p[c]=e(r,n+1,s,s[n+1],l[c],f[c]);return p}}),Vg="broadcast",Qg=["concat"],tv=mt(Vg,Qg,i=>{var{concat:t}=i;return function(n,s){var u=Math.max(n._size.length,s._size.length);if(n._size.length===s._size.length&&n._size.every((w,g)=>w===s._size[g]))return[n,s];for(var l=e(n._size,u,0),f=e(s._size,u,0),p=[],h=0;h<u;h++)p[h]=Math.max(l[h],f[h]);As(l,p),As(f,p);var c=n.clone(),m=s.clone();c._size.length<u?c.reshape(e(c._size,u,1)):m._size.length<u&&m.reshape(e(m._size,u,1));for(var _=0;_<u;_++)c._size[_]<p[_]&&(c=r(c,p[_],_)),m._size[_]<p[_]&&(m=r(m,p[_],_));return[c,m]};function e(n,s,u){return[...Array(s-n.length).fill(u),...n]}function r(n,s,u){return t(...Array(s).fill(n),u)}}),ev="matrixAlgorithmSuite",rv=["typed","matrix","concat"],qn=mt(ev,rv,i=>{var{typed:t,matrix:e,concat:r}=i,n=Xg({typed:t}),s=Ea({typed:t}),u=tv({concat:r});return function(f){var p=f.elop,h=f.SD||f.DS,c;p?(c={"DenseMatrix, DenseMatrix":(g,y)=>n(...u(g,y),p),"Array, Array":(g,y)=>n(...u(e(g),e(y)),p).valueOf(),"Array, DenseMatrix":(g,y)=>n(...u(e(g),y),p),"DenseMatrix, Array":(g,y)=>n(...u(g,e(y)),p)},f.SS&&(c["SparseMatrix, SparseMatrix"]=(g,y)=>f.SS(...u(g,y),p,!1)),f.DS&&(c["DenseMatrix, SparseMatrix"]=(g,y)=>f.DS(...u(g,y),p,!1),c["Array, SparseMatrix"]=(g,y)=>f.DS(...u(e(g),y),p,!1)),h&&(c["SparseMatrix, DenseMatrix"]=(g,y)=>h(...u(y,g),p,!0),c["SparseMatrix, Array"]=(g,y)=>h(...u(e(y),g),p,!0))):(c={"DenseMatrix, DenseMatrix":t.referToSelf(g=>(y,v)=>n(...u(y,v),g)),"Array, Array":t.referToSelf(g=>(y,v)=>n(...u(e(y),e(v)),g).valueOf()),"Array, DenseMatrix":t.referToSelf(g=>(y,v)=>n(...u(e(y),v),g)),"DenseMatrix, Array":t.referToSelf(g=>(y,v)=>n(...u(y,e(v)),g))},f.SS&&(c["SparseMatrix, SparseMatrix"]=t.referToSelf(g=>(y,v)=>f.SS(...u(y,v),g,!1))),f.DS&&(c["DenseMatrix, SparseMatrix"]=t.referToSelf(g=>(y,v)=>f.DS(...u(y,v),g,!1)),c["Array, SparseMatrix"]=t.referToSelf(g=>(y,v)=>f.DS(...u(e(y),v),g,!1))),h&&(c["SparseMatrix, DenseMatrix"]=t.referToSelf(g=>(y,v)=>h(...u(v,y),g,!0)),c["SparseMatrix, Array"]=t.referToSelf(g=>(y,v)=>h(...u(e(v),y),g,!0))));var m=f.scalar||"any",_=f.Ds||f.Ss;_&&(p?(c["DenseMatrix,"+m]=(g,y)=>s(g,y,p,!1),c[m+", DenseMatrix"]=(g,y)=>s(y,g,p,!0),c["Array,"+m]=(g,y)=>s(e(g),y,p,!1).valueOf(),c[m+", Array"]=(g,y)=>s(e(y),g,p,!0).valueOf()):(c["DenseMatrix,"+m]=t.referToSelf(g=>(y,v)=>s(y,v,g,!1)),c[m+", DenseMatrix"]=t.referToSelf(g=>(y,v)=>s(v,y,g,!0)),c["Array,"+m]=t.referToSelf(g=>(y,v)=>s(e(y),v,g,!1).valueOf()),c[m+", Array"]=t.referToSelf(g=>(y,v)=>s(e(v),y,g,!0).valueOf())));var w=f.sS!==void 0?f.sS:f.Ss;return p?(f.Ss&&(c["SparseMatrix,"+m]=(g,y)=>f.Ss(g,y,p,!1)),w&&(c[m+", SparseMatrix"]=(g,y)=>w(y,g,p,!0))):(f.Ss&&(c["SparseMatrix,"+m]=t.referToSelf(g=>(y,v)=>f.Ss(y,v,g,!1))),w&&(c[m+", SparseMatrix"]=t.referToSelf(g=>(y,v)=>w(v,y,g,!0)))),p&&p.signatures&&Bl(c,p.signatures),c}}),nv="matAlgo01xDSid",iv=["typed"],qf=mt(nv,iv,i=>{var{typed:t}=i;return function(r,n,s,u){var l=r._data,f=r._size,p=r._datatype||r.getDataType(),h=n._values,c=n._index,m=n._ptr,_=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==_.length)throw new Zt(f.length,_.length);if(f[0]!==_[0]||f[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+_+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var g=f[0],y=f[1],v=typeof p=="string"&&p!=="mixed"&&p===w?p:void 0,E=v?t.find(s,[v,v]):s,b,N,x=[];for(b=0;b<g;b++)x[b]=[];var F=[],M=[];for(N=0;N<y;N++){for(var S=N+1,$=m[N],C=m[N+1],I=$;I<C;I++)b=c[I],F[b]=u?E(h[I],l[b][N]):E(l[b][N],h[I]),M[b]=S;for(b=0;b<g;b++)M[b]===S?x[b][N]=F[b]:x[b][N]=l[b][N]}return r.createDenseMatrix({data:x,size:[g,y],datatype:p===r._datatype&&w===n._datatype?v:void 0})}}),sv="matAlgo04xSidSid",ov=["typed","equalScalar"],av=mt(sv,ov,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u){var l=n._values,f=n._index,p=n._ptr,h=n._size,c=n._datatype||n._data===void 0?n._datatype:n.getDataType(),m=s._values,_=s._index,w=s._ptr,g=s._size,y=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(h.length!==g.length)throw new Zt(h.length,g.length);if(h[0]!==g[0]||h[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+g+")");var v=h[0],E=h[1],b,N=e,x=0,F=u;typeof c=="string"&&c===y&&c!=="mixed"&&(b=c,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(u,[b,b]));var M=l&&m?[]:void 0,S=[],$=[],C=l&&m?[]:void 0,I=l&&m?[]:void 0,R=[],U=[],q,k,P,K,G;for(k=0;k<E;k++){$[k]=S.length;var V=k+1;for(K=p[k],G=p[k+1],P=K;P<G;P++)q=f[P],S.push(q),R[q]=V,C&&(C[q]=l[P]);for(K=w[k],G=w[k+1],P=K;P<G;P++)if(q=_[P],R[q]===V){if(C){var tt=F(C[q],m[P]);N(tt,x)?R[q]=null:C[q]=tt}}else S.push(q),U[q]=V,I&&(I[q]=m[P]);if(C&&I)for(P=$[k];P<S.length;)q=S[P],R[q]===V?(M[P]=C[q],P++):U[q]===V?(M[P]=I[q],P++):S.splice(P,1)}return $[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:$,size:[v,E],datatype:c===n._datatype&&y===s._datatype?b:void 0})}}),uv="matAlgo10xSids",lv=["typed","DenseMatrix"],Uf=mt(uv,lv,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,u,l){var f=n._values,p=n._index,h=n._ptr,c=n._size,m=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var _=c[0],w=c[1],g,y=u;typeof m=="string"&&(g=m,s=t.convert(s,g),y=t.find(u,[g,g]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=h[N],M=h[N+1],S=F;S<M;S++){var $=p[S];E[$]=f[S],b[$]=x}for(var C=0;C<_;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?y(s,E[C]):y(E[C],s):v[C][N]=s}return new e({data:v,size:[_,w],datatype:g})}}),fv="multiplyScalar",cv=["typed"],hv=mt(fv,cv,i=>{var{typed:t}=i;return t("multiplyScalar",{"number, number":xf,"Complex, Complex":function(r,n){return r.mul(n)},"BigNumber, BigNumber":function(r,n){return r.times(n)},"Fraction, Fraction":function(r,n){return r.mul(n)},"number | Fraction | BigNumber | Complex, Unit":(e,r)=>r.multiply(e),"Unit, number | Fraction | BigNumber | Complex | Unit":(e,r)=>e.multiply(r)})}),kf="multiply",pv=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],dv=mt(kf,pv,i=>{var{typed:t,matrix:e,addScalar:r,multiplyScalar:n,equalScalar:s,dot:u}=i,l=ba({typed:t,equalScalar:s}),f=Ea({typed:t});function p(x,F){switch(x.length){case 1:switch(F.length){case 1:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+x[0]+") must match Matrix rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;case 2:switch(F.length){case 1:if(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+x[1]+") must match Vector length ("+F[0]+")");break;case 2:if(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+x[1]+") must match Matrix B rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+x.length+" dimensions)")}}function h(x,F,M){if(M===0)throw new Error("Cannot multiply two empty vectors");return u(x,F)}function c(x,F){if(F.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return m(x,F)}function m(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._data,I=F._size,R=F._datatype||F.getDataType(),U=S[0],q=I[1],k,P=r,K=n;$&&R&&$===R&&typeof $=="string"&&$!=="mixed"&&(k=$,P=t.find(r,[k,k]),K=t.find(n,[k,k]));for(var G=[],V=0;V<q;V++){for(var tt=K(M[0],C[0][V]),ft=1;ft<U;ft++)tt=P(tt,K(M[ft],C[ft][V]));G[V]=tt}return x.createDenseMatrix({data:G,size:[q],datatype:$===x._datatype&&R===F._datatype?k:void 0})}var _=t("_multiplyMatrixVector",{"DenseMatrix, any":g,"SparseMatrix, any":E}),w=t("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":y,"DenseMatrix, SparseMatrix":v,"SparseMatrix, DenseMatrix":b,"SparseMatrix, SparseMatrix":N});function g(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._data,I=F._datatype||F.getDataType(),R=S[0],U=S[1],q,k=r,P=n;$&&I&&$===I&&typeof $=="string"&&$!=="mixed"&&(q=$,k=t.find(r,[q,q]),P=t.find(n,[q,q]));for(var K=[],G=0;G<R;G++){for(var V=M[G],tt=P(V[0],C[0]),ft=1;ft<U;ft++)tt=k(tt,P(V[ft],C[ft]));K[G]=tt}return x.createDenseMatrix({data:K,size:[R],datatype:$===x._datatype&&I===F._datatype?q:void 0})}function y(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._data,I=F._size,R=F._datatype||F.getDataType(),U=S[0],q=S[1],k=I[1],P,K=r,G=n;$&&R&&$===R&&typeof $=="string"&&$!=="mixed"&&$!=="mixed"&&(P=$,K=t.find(r,[P,P]),G=t.find(n,[P,P]));for(var V=[],tt=0;tt<U;tt++){var ft=M[tt];V[tt]=[];for(var vt=0;vt<k;vt++){for(var lt=G(ft[0],C[0][vt]),wt=1;wt<q;wt++)lt=K(lt,G(ft[wt],C[wt][vt]));V[tt][vt]=lt}}return x.createDenseMatrix({data:V,size:[U,k],datatype:$===x._datatype&&R===F._datatype?P:void 0})}function v(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._values,I=F._index,R=F._ptr,U=F._size,q=F._datatype||F._data===void 0?F._datatype:F.getDataType();if(!C)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var k=S[0],P=U[1],K,G=r,V=n,tt=s,ft=0;$&&q&&$===q&&typeof $=="string"&&$!=="mixed"&&(K=$,G=t.find(r,[K,K]),V=t.find(n,[K,K]),tt=t.find(s,[K,K]),ft=t.convert(0,K));for(var vt=[],lt=[],wt=[],yt=F.createSparseMatrix({values:vt,index:lt,ptr:wt,size:[k,P],datatype:$===x._datatype&&q===F._datatype?K:void 0}),St=0;St<P;St++){wt[St]=lt.length;var bt=R[St],ee=R[St+1];if(ee>bt)for(var It=0,Mt=0;Mt<k;Mt++){for(var ie=Mt+1,Xt=void 0,zt=bt;zt<ee;zt++){var Gt=I[zt];It!==ie?(Xt=V(M[Mt][Gt],C[zt]),It=ie):Xt=G(Xt,V(M[Mt][Gt],C[zt]))}It===ie&&!tt(Xt,ft)&&(lt.push(Mt),vt.push(Xt))}}return wt[P]=lt.length,yt}function E(x,F){var M=x._values,S=x._index,$=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var I=F._data,R=F._datatype||F.getDataType(),U=x._size[0],q=F._size[0],k=[],P=[],K=[],G,V=r,tt=n,ft=s,vt=0;C&&R&&C===R&&typeof C=="string"&&C!=="mixed"&&(G=C,V=t.find(r,[G,G]),tt=t.find(n,[G,G]),ft=t.find(s,[G,G]),vt=t.convert(0,G));var lt=[],wt=[];K[0]=0;for(var yt=0;yt<q;yt++){var St=I[yt];if(!ft(St,vt))for(var bt=$[yt],ee=$[yt+1],It=bt;It<ee;It++){var Mt=S[It];wt[Mt]?lt[Mt]=V(lt[Mt],tt(St,M[It])):(wt[Mt]=!0,P.push(Mt),lt[Mt]=tt(St,M[It]))}}for(var ie=P.length,Xt=0;Xt<ie;Xt++){var zt=P[Xt];k[Xt]=lt[zt]}return K[1]=P.length,x.createSparseMatrix({values:k,index:P,ptr:K,size:[U,1],datatype:C===x._datatype&&R===F._datatype?G:void 0})}function b(x,F){var M=x._values,S=x._index,$=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var I=F._data,R=F._datatype||F.getDataType(),U=x._size[0],q=F._size[0],k=F._size[1],P,K=r,G=n,V=s,tt=0;C&&R&&C===R&&typeof C=="string"&&C!=="mixed"&&(P=C,K=t.find(r,[P,P]),G=t.find(n,[P,P]),V=t.find(s,[P,P]),tt=t.convert(0,P));for(var ft=[],vt=[],lt=[],wt=x.createSparseMatrix({values:ft,index:vt,ptr:lt,size:[U,k],datatype:C===x._datatype&&R===F._datatype?P:void 0}),yt=[],St=[],bt=0;bt<k;bt++){lt[bt]=vt.length;for(var ee=bt+1,It=0;It<q;It++){var Mt=I[It][bt];if(!V(Mt,tt))for(var ie=$[It],Xt=$[It+1],zt=ie;zt<Xt;zt++){var Gt=S[zt];St[Gt]!==ee?(St[Gt]=ee,vt.push(Gt),yt[Gt]=G(Mt,M[zt])):yt[Gt]=K(yt[Gt],G(Mt,M[zt]))}}for(var Ce=lt[bt],sr=vt.length,Me=Ce;Me<sr;Me++){var Vr=vt[Me];ft[Me]=yt[Vr]}}return lt[k]=vt.length,wt}function N(x,F){var M=x._values,S=x._index,$=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType(),I=F._values,R=F._index,U=F._ptr,q=F._datatype||F._data===void 0?F._datatype:F.getDataType(),k=x._size[0],P=F._size[1],K=M&&I,G,V=r,tt=n;C&&q&&C===q&&typeof C=="string"&&C!=="mixed"&&(G=C,V=t.find(r,[G,G]),tt=t.find(n,[G,G]));for(var ft=K?[]:void 0,vt=[],lt=[],wt=x.createSparseMatrix({values:ft,index:vt,ptr:lt,size:[k,P],datatype:C===x._datatype&&q===F._datatype?G:void 0}),yt=K?[]:void 0,St=[],bt,ee,It,Mt,ie,Xt,zt,Gt,Ce=0;Ce<P;Ce++){lt[Ce]=vt.length;var sr=Ce+1;for(ie=U[Ce],Xt=U[Ce+1],Mt=ie;Mt<Xt;Mt++)if(Gt=R[Mt],K)for(ee=$[Gt],It=$[Gt+1],bt=ee;bt<It;bt++)zt=S[bt],St[zt]!==sr?(St[zt]=sr,vt.push(zt),yt[zt]=tt(I[Mt],M[bt])):yt[zt]=V(yt[zt],tt(I[Mt],M[bt]));else for(ee=$[Gt],It=$[Gt+1],bt=ee;bt<It;bt++)zt=S[bt],St[zt]!==sr&&(St[zt]=sr,vt.push(zt));if(K)for(var Me=lt[Ce],Vr=vt.length,wn=Me;wn<Vr;wn++){var Qr=vt[wn];ft[wn]=yt[Qr]}}return lt[P]=vt.length,wt}return t(kf,n,{"Array, Array":t.referTo("Matrix, Matrix",x=>(F,M)=>{p(Ae(F),Ae(M));var S=x(e(F),e(M));return fe(S)?S.valueOf():S}),"Matrix, Matrix":function(F,M){var S=F.size(),$=M.size();return p(S,$),S.length===1?$.length===1?h(F,M,S[0]):c(F,M):$.length===1?_(F,M):w(F,M)},"Matrix, Array":t.referTo("Matrix,Matrix",x=>(F,M)=>x(F,e(M))),"Array, Matrix":t.referToSelf(x=>(F,M)=>x(e(F,M.storage()),M)),"SparseMatrix, any":function(F,M){return l(F,M,n,!1)},"DenseMatrix, any":function(F,M){return f(F,M,n,!1)},"any, SparseMatrix":function(F,M){return l(M,F,n,!0)},"any, DenseMatrix":function(F,M){return f(M,F,n,!0)},"Array, any":function(F,M){return f(e(F),M,n,!1).valueOf()},"any, Array":function(F,M){return f(e(M),F,n,!0).valueOf()},"any, any":n,"any, any, ...any":t.referToSelf(x=>(F,M,S)=>{for(var $=x(F,M),C=0;C<S.length;C++)$=x($,S[C]);return $})})}),Wf="subtract",mv=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],gv=mt(Wf,mv,i=>{var{typed:t,matrix:e,equalScalar:r,subtractScalar:n,unaryMinus:s,DenseMatrix:u,concat:l}=i,f=qf({typed:t}),p=fi({typed:t}),h=zf({typed:t,equalScalar:r}),c=Uf({typed:t,DenseMatrix:u}),m=li({typed:t,DenseMatrix:u}),_=qn({typed:t,matrix:e,concat:l});return t(Wf,{"any, any":n},_({elop:n,SS:h,DS:f,SD:p,Ss:m,sS:c}))}),vv="matAlgo07xSSf",_v=["typed","DenseMatrix"],zs=mt(vv,_v,i=>{var{typed:t,DenseMatrix:e}=i;return function(s,u,l){var f=s._size,p=s._datatype||s._data===void 0?s._datatype:s.getDataType(),h=u._size,c=u._datatype||u._data===void 0?u._datatype:u.getDataType();if(f.length!==h.length)throw new Zt(f.length,h.length);if(f[0]!==h[0]||f[1]!==h[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+h+")");var m=f[0],_=f[1],w,g=0,y=l;typeof p=="string"&&p===c&&p!=="mixed"&&(w=p,g=t.convert(0,w),y=t.find(l,[w,w]));var v,E,b=[];for(v=0;v<m;v++)b[v]=[];var N=[],x=[],F=[],M=[];for(E=0;E<_;E++){var S=E+1;for(r(s,E,F,N,S),r(u,E,M,x,S),v=0;v<m;v++){var $=F[v]===S?N[v]:g,C=M[v]===S?x[v]:g;b[v][E]=y($,C)}}return new e({data:b,size:[m,_],datatype:p===s._datatype&&c===u._datatype?w:void 0})};function r(n,s,u,l,f){for(var p=n._values,h=n._index,c=n._ptr,m=c[s],_=c[s+1];m<_;m++){var w=h[m];u[w]=f,l[w]=p[m]}}}),Yf="conj",wv=["typed"],Dv=mt(Yf,wv,i=>{var{typed:t}=i;return t(Yf,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.conjugate(),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),jf="concat",yv=["typed","matrix","isInteger"],bv=mt(jf,yv,i=>{var{typed:t,matrix:e,isInteger:r}=i;return t(jf,{"...Array | Matrix | number | BigNumber":function(s){var u,l=s.length,f=-1,p,h=!1,c=[];for(u=0;u<l;u++){var m=s[u];if(fe(m)&&(h=!0),ue(m)||ye(m)){if(u!==l-1)throw new Error("Dimension must be specified as last argument");if(p=f,f=m.valueOf(),!r(f))throw new TypeError("Integer number expected for dimension");if(f<0||u>0&&f>p)throw new hn(f,p+1)}else{var _=te(m).valueOf(),w=Ae(_);if(c[u]=_,p=f,f=w.length-1,u>0&&f!==p)throw new Zt(p+1,f+1)}}if(c.length===0)throw new SyntaxError("At least one matrix expected");for(var g=c.shift();c.length;)g=Xl(g,c.shift(),f);return h?e(g):g},"...string":function(s){return s.join("")}})}),Zf="count",Ev=["typed","size","prod"],Av=mt(Zf,Ev,i=>{var{typed:t,size:e,prod:r}=i;return t(Zf,{string:function(s){return s.length},"Matrix | Array":function(s){return r(e(s))}})}),Gf="identity",xv=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],Cv=mt(Gf,xv,i=>{var{typed:t,config:e,matrix:r,BigNumber:n,DenseMatrix:s,SparseMatrix:u}=i;return t(Gf,{"":function(){return e.matrix==="Matrix"?r([]):[]},string:function(h){return r(h)},"number | BigNumber":function(h){return f(h,h,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(h,c){return f(h,h,c)},"number | BigNumber, number | BigNumber":function(h,c){return f(h,c,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(h,c,m){return f(h,c,m)},Array:function(h){return l(h)},"Array, string":function(h,c){return l(h,c)},Matrix:function(h){return l(h.valueOf(),h.storage())},"Matrix, string":function(h,c){return l(h.valueOf(),c)}});function l(p,h){switch(p.length){case 0:return h?r(h):[];case 1:return f(p[0],p[0],h);case 2:return f(p[0],p[1],h);default:throw new Error("Vector containing two values expected")}}function f(p,h,c){var m=ye(p)||ye(h)?n:null;if(ye(p)&&(p=p.toNumber()),ye(h)&&(h=h.toNumber()),!he(p)||p<1)throw new Error("Parameters in function identity must be positive integers");if(!he(h)||h<1)throw new Error("Parameters in function identity must be positive integers");var _=m?new n(1):1,w=m?new m(0):0,g=[p,h];if(c){if(c==="sparse")return u.diagonal(g,_,0,w);if(c==="dense")return s.diagonal(g,_,0,w);throw new TypeError('Unknown matrix type "'.concat(c,'"'))}for(var y=ua([],g,w),v=p<h?p:h,E=0;E<v;E++)y[E][E]=_;return y}}),Kf="kron",Fv=["typed","matrix","multiplyScalar"],Mv=mt(Kf,Fv,i=>{var{typed:t,matrix:e,multiplyScalar:r}=i;return t(Kf,{"Matrix, Matrix":function(u,l){return e(n(u.toArray(),l.toArray()))},"Matrix, Array":function(u,l){return e(n(u.toArray(),l))},"Array, Matrix":function(u,l){return e(n(u,l.toArray()))},"Array, Array":n});function n(s,u){if(Ae(s).length===1&&(s=[s]),Ae(u).length===1&&(u=[u]),Ae(s).length>2||Ae(u).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(s.length)+", y = "+JSON.stringify(u.length)+")");var l=[],f=[];return s.map(function(p){return u.map(function(h){return f=[],l.push(f),p.map(function(c){return h.map(function(m){return f.push(r(c,m))})})})})&&l}});function Nv(){throw new Error('No "bignumber" implementation available')}function Sv(){throw new Error('No "fraction" implementation available')}function Bv(){throw new Error('No "matrix" implementation available')}var Hf="reshape",Iv=["typed","isInteger","matrix"],Tv=mt(Hf,Iv,i=>{var{typed:t,isInteger:e}=i;return t(Hf,{"Matrix, Array":function(n,s){return n.reshape(s,!0)},"Array, Array":function(n,s){return s.forEach(function(u){if(!e(u))throw new TypeError("Invalid size for dimension: "+u)}),fa(n,s)}})}),Jf="size",$v=["typed","config","?matrix"],Ov=mt(Jf,$v,i=>{var{typed:t,config:e,matrix:r}=i;return t(Jf,{Matrix:function(s){return s.create(s.size())},Array:Ae,string:function(s){return e.matrix==="Array"?[s.length]:r([s.length])},"number | Complex | BigNumber | Unit | boolean | null":function(s){return e.matrix==="Array"?[]:r?r([]):Bv()}})}),Xf="transpose",Rv=["typed","matrix"],Lv=mt(Xf,Rv,i=>{var{typed:t,matrix:e}=i;return t(Xf,{Array:u=>r(e(u)).valueOf(),Matrix:r,any:te});function r(u){var l=u.size(),f;switch(l.length){case 1:f=u.clone();break;case 2:{var p=l[0],h=l[1];if(h===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+se(l)+")");switch(u.storage()){case"dense":f=n(u,p,h);break;case"sparse":f=s(u,p,h);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+se(l)+")")}return f}function n(u,l,f){for(var p=u._data,h=[],c,m=0;m<f;m++){c=h[m]=[];for(var _=0;_<l;_++)c[_]=te(p[_][m])}return u.createDenseMatrix({data:h,size:[f,l],datatype:u._datatype})}function s(u,l,f){for(var p=u._values,h=u._index,c=u._ptr,m=p?[]:void 0,_=[],w=[],g=[],y=0;y<l;y++)g[y]=0;var v,E,b;for(v=0,E=h.length;v<E;v++)g[h[v]]++;for(var N=0,x=0;x<l;x++)w.push(N),N+=g[x],g[x]=w[x];for(w.push(N),b=0;b<f;b++)for(var F=c[b],M=c[b+1],S=F;S<M;S++){var $=g[h[S]]++;_[$]=b,p&&(m[$]=te(p[S]))}return u.createSparseMatrix({values:m,index:_,ptr:w,size:[f,l],datatype:u._datatype})}}),Vf="ctranspose",Pv=["typed","transpose","conj"],zv=mt(Vf,Pv,i=>{var{typed:t,transpose:e,conj:r}=i;return t(Vf,{any:function(s){return r(e(s))}})}),Qf="mode",qv=["typed","isNaN","isNumeric"],Uv=mt(Qf,qv,i=>{var{typed:t,isNaN:e,isNumeric:r}=i;return t(Qf,{"Array | Matrix":n,"...":function(u){return n(u)}});function n(s){s=ha(s.valueOf());var u=s.length;if(u===0)throw new Error("Cannot calculate mode of an empty array");for(var l={},f=[],p=0,h=0;h<s.length;h++){var c=s[h];if(r(c)&&e(c))throw new Error("Cannot calculate mode of an array containing NaN values");c in l||(l[c]=0),l[c]++,l[c]===p?f.push(c):l[c]>p&&(p=l[c],f=[c])}return f}});function vn(i,t,e){var r;return String(i).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+cn(e)+", value: "+JSON.stringify(e)+")":" (type: "+i.data.actual+")",new TypeError("Cannot calculate "+t+", unexpected type of argument"+r)):String(i).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+cn(e)+", value: "+JSON.stringify(e)+")":"",new TypeError("Cannot calculate "+t+", no ordering relation is defined for complex numbers"+r)):i}var tc="prod",kv=["typed","config","multiplyScalar","numeric"],Wv=mt(tc,kv,i=>{var{typed:t,config:e,multiplyScalar:r,numeric:n}=i;return t(tc,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(l,f){throw new Error("prod(A, dim) is not yet supported")},"...":function(l){return s(l)}});function s(u){var l;if(Wi(u,function(f){try{l=l===void 0?f:r(l,f)}catch(p){throw vn(p,"prod",f)}}),typeof l=="string"&&(l=n(l,e.number)),l===void 0)throw new Error("Cannot calculate prod of an empty array");return l}}),Yv="numeric",jv=["number","?bignumber","?fraction"],Zv=mt(Yv,jv,i=>{var{number:t,bignumber:e,fraction:r}=i,n={string:!0,number:!0,BigNumber:!0,Fraction:!0},s={number:u=>t(u),BigNumber:e?u=>e(u):Nv,Fraction:r?u=>r(u):Sv};return function(l){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",p=arguments.length>2?arguments[2]:void 0;if(p!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var h=cn(l);if(!(h in n))throw new TypeError("Cannot convert "+l+' of type "'+h+'"; valid input types are '+Object.keys(n).join(", "));if(!(f in s))throw new TypeError("Cannot convert "+l+' to type "'+f+'"; valid output types are '+Object.keys(s).join(", "));return f===h?l:s[f](l)}}),ec="divideScalar",Gv=["typed","numeric"],Kv=mt(ec,Gv,i=>{var{typed:t,numeric:e}=i;return t(ec,{"number, number":function(n,s){return n/s},"Complex, Complex":function(n,s){return n.div(s)},"BigNumber, BigNumber":function(n,s){return n.div(s)},"Fraction, Fraction":function(n,s){return n.div(s)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,n)=>r.divide(n),"number | Fraction | Complex | BigNumber, Unit":(r,n)=>n.divideInto(r)})}),rc="pow",Hv=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],Jv=mt(rc,Hv,i=>{var{typed:t,config:e,identity:r,multiply:n,matrix:s,inv:u,number:l,fraction:f,Complex:p}=i;return t(rc,{"number, number":h,"Complex, Complex":function(w,g){return w.pow(g)},"BigNumber, BigNumber":function(w,g){return g.isInteger()||w>=0||e.predictable?w.pow(g):new p(w.toNumber(),0).pow(g.toNumber(),0)},"Fraction, Fraction":function(w,g){var y=w.pow(g);if(y!=null)return y;if(e.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return h(w.valueOf(),g.valueOf())},"Array, number":c,"Array, BigNumber":function(w,g){return c(w,g.toNumber())},"Matrix, number":m,"Matrix, BigNumber":function(w,g){return m(w,g.toNumber())},"Unit, number | BigNumber":function(w,g){return w.pow(g)}});function h(_,w){if(e.predictable&&!he(w)&&_<0)try{var g=f(w),y=l(g);if((w===y||Math.abs((w-y)/w)<1e-14)&&g.d%2===1)return(g.n%2===0?1:-1)*Math.pow(-_,w)}catch{}return e.predictable&&(_<-1&&w===1/0||_>-1&&_<0&&w===-1/0)?NaN:he(w)||_>=0||e.predictable?Ff(_,w):_*_<1&&w===1/0||_*_>1&&w===-1/0?0:new p(_,0).pow(w,0)}function c(_,w){if(!he(w))throw new TypeError("For A^b, b must be an integer (value is "+w+")");var g=Ae(_);if(g.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+g.length+" dimensions)");if(g[0]!==g[1])throw new Error("For A^b, A must be square (size is "+g[0]+"x"+g[1]+")");if(w<0)try{return c(u(_),-w)}catch(E){throw E.message==="Cannot calculate inverse, determinant is zero"?new TypeError("For A^b, when A is not invertible, b must be a positive integer (value is "+w+")"):E}for(var y=r(g[0]).valueOf(),v=_;w>=1;)(w&1)===1&&(y=n(v,y)),w>>=1,v=n(v,v);return y}function m(_,w){return s(c(_.valueOf(),w))}}),nc="dotDivide",Xv=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],Vv=mt(nc,Xv,i=>{var{typed:t,matrix:e,equalScalar:r,divideScalar:n,DenseMatrix:s,concat:u}=i,l=Yg({typed:t,equalScalar:r}),f=fi({typed:t}),p=zs({typed:t,DenseMatrix:s}),h=ba({typed:t,equalScalar:r}),c=li({typed:t,DenseMatrix:s}),m=qn({typed:t,matrix:e,concat:u});return t(nc,m({elop:n,SS:p,DS:f,SD:l,Ss:h,sS:c}))}),qs="compare",Qv=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],t_=mt(qs,Qv,i=>{var{typed:t,config:e,equalScalar:r,matrix:n,BigNumber:s,Fraction:u,DenseMatrix:l,concat:f}=i,p=fi({typed:t}),h=zf({typed:t,equalScalar:r}),c=li({typed:t,DenseMatrix:l}),m=qn({typed:t,matrix:n,concat:f}),_=Ls({typed:t});return t(qs,e_({typed:t,config:e}),{"boolean, boolean":function(g,y){return g===y?0:g>y?1:-1},"BigNumber, BigNumber":function(g,y){return Rs(g,y,e.epsilon)?new s(0):new s(g.cmp(y))},"Fraction, Fraction":function(g,y){return new u(g.compare(y))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},_,m({SS:h,DS:p,Ss:c}))}),e_=mt(qs,["typed","config"],i=>{var{typed:t,config:e}=i;return t(qs,{"number, number":function(n,s){return zn(n,s,e.epsilon)?0:n>s?1:-1}})}),Us="equal",r_=["typed","matrix","equalScalar","DenseMatrix","concat"],n_=mt(Us,r_,i=>{var{typed:t,matrix:e,equalScalar:r,DenseMatrix:n,concat:s}=i,u=fi({typed:t}),l=zs({typed:t,DenseMatrix:n}),f=li({typed:t,DenseMatrix:n}),p=qn({typed:t,matrix:e,concat:s});return t(Us,i_({typed:t,equalScalar:r}),p({elop:r,SS:l,DS:u,Ss:f}))}),i_=mt(Us,["typed","equalScalar"],i=>{var{typed:t,equalScalar:e}=i;return t(Us,{"any, any":function(n,s){return n===null?s===null:s===null?n===null:n===void 0?s===void 0:s===void 0?n===void 0:e(n,s)}})}),ks="smaller",s_=["typed","config","matrix","DenseMatrix","concat"],o_=mt(ks,s_,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,u=fi({typed:t}),l=zs({typed:t,DenseMatrix:n}),f=li({typed:t,DenseMatrix:n}),p=qn({typed:t,matrix:r,concat:s}),h=Ls({typed:t});return t(ks,a_({typed:t,config:e}),{"boolean, boolean":(c,m)=>c<m,"BigNumber, BigNumber":function(m,_){return m.lt(_)&&!Rs(m,_,e.epsilon)},"Fraction, Fraction":(c,m)=>c.compare(m)===-1,"Complex, Complex":function(m,_){throw new TypeError("No ordering relation is defined for complex numbers")}},h,p({SS:l,DS:u,Ss:f}))}),a_=mt(ks,["typed","config"],i=>{var{typed:t,config:e}=i;return t(ks,{"number, number":function(n,s){return n<s&&!zn(n,s,e.epsilon)}})}),Ws="larger",u_=["typed","config","matrix","DenseMatrix","concat"],l_=mt(Ws,u_,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,u=fi({typed:t}),l=zs({typed:t,DenseMatrix:n}),f=li({typed:t,DenseMatrix:n}),p=qn({typed:t,matrix:r,concat:s}),h=Ls({typed:t});return t(Ws,f_({typed:t,config:e}),{"boolean, boolean":(c,m)=>c>m,"BigNumber, BigNumber":function(m,_){return m.gt(_)&&!Rs(m,_,e.epsilon)},"Fraction, Fraction":(c,m)=>c.compare(m)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},h,p({SS:l,DS:u,Ss:f}))}),f_=mt(Ws,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Ws,{"number, number":function(n,s){return n>s&&!zn(n,s,e.epsilon)}})}),ic="deepEqual",c_=["typed","equal"],h_=mt(ic,c_,i=>{var{typed:t,equal:e}=i;return t(ic,{"any, any":function(s,u){return r(s.valueOf(),u.valueOf())}});function r(n,s){if(Array.isArray(n))if(Array.isArray(s)){var u=n.length;if(u!==s.length)return!1;for(var l=0;l<u;l++)if(!r(n[l],s[l]))return!1;return!0}else return!1;else return Array.isArray(s)?!1:e(n,s)}}),sc="partitionSelect",p_=["typed","isNumeric","isNaN","compare"],d_=mt(sc,p_,i=>{var{typed:t,isNumeric:e,isNaN:r,compare:n}=i,s=n,u=(p,h)=>-n(p,h);return t(sc,{"Array | Matrix, number":function(h,c){return l(h,c,s)},"Array | Matrix, number, string":function(h,c,m){if(m==="asc")return l(h,c,s);if(m==="desc")return l(h,c,u);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":l});function l(p,h,c){if(!he(h)||h<0)throw new Error("k must be a non-negative integer");if(fe(p)){var m=p.size();if(m.length>1)throw new Error("Only one dimensional matrices supported");return f(p.valueOf(),h,c)}if(Array.isArray(p))return f(p,h,c)}function f(p,h,c){if(h>=p.length)throw new Error("k out of bounds");for(var m=0;m<p.length;m++)if(e(p[m])&&r(p[m]))return p[m];for(var _=0,w=p.length-1;_<w;){for(var g=_,y=w,v=p[Math.floor(Math.random()*(w-_+1))+_];g<y;)if(c(p[g],v)>=0){var E=p[y];p[y]=p[g],p[g]=E,--y}else++g;c(p[g],v)>0&&--g,h<=g?w=g:_=g+1}return p[h]}}),oc="max",m_=["typed","config","numeric","larger"],g_=mt(oc,m_,i=>{var{typed:t,config:e,numeric:r,larger:n}=i;return t(oc,{"Array | Matrix":u,"Array | Matrix, number | BigNumber":function(f,p){return ya(f,p.valueOf(),s)},"...":function(f){if(Ts(f))throw new TypeError("Scalar values expected in function max");return u(f)}});function s(l,f){try{return n(l,f)?l:f}catch(p){throw vn(p,"max",f)}}function u(l){var f;if(Wi(l,function(p){try{isNaN(p)&&typeof p=="number"?f=NaN:(f===void 0||n(p,f))&&(f=p)}catch(h){throw vn(h,"max",p)}}),f===void 0)throw new Error("Cannot calculate max of an empty array");return typeof f=="string"&&(f=r(f,e.number)),f}}),ac="min",v_=["typed","config","numeric","smaller"],__=mt(ac,v_,i=>{var{typed:t,config:e,numeric:r,smaller:n}=i;return t(ac,{"Array | Matrix":u,"Array | Matrix, number | BigNumber":function(f,p){return ya(f,p.valueOf(),s)},"...":function(f){if(Ts(f))throw new TypeError("Scalar values expected in function min");return u(f)}});function s(l,f){try{return n(l,f)?l:f}catch(p){throw vn(p,"min",f)}}function u(l){var f;if(Wi(l,function(p){try{isNaN(p)&&typeof p=="number"?f=NaN:(f===void 0||n(p,f))&&(f=p)}catch(h){throw vn(h,"min",p)}}),f===void 0)throw new Error("Cannot calculate min of an empty array");return typeof f=="string"&&(f=r(f,e.number)),f}}),uc="add",w_=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],D_=mt(uc,w_,i=>{var{typed:t,matrix:e,addScalar:r,equalScalar:n,DenseMatrix:s,SparseMatrix:u,concat:l}=i,f=qf({typed:t}),p=av({typed:t,equalScalar:n}),h=Uf({typed:t,DenseMatrix:s}),c=qn({typed:t,matrix:e,concat:l});return t(uc,{"any, any":r,"any, any, ...any":t.referToSelf(m=>(_,w,g)=>{for(var y=m(_,w),v=0;v<g.length;v++)y=m(y,g[v]);return y})},c({elop:r,DS:f,SS:p,Ss:h}))}),lc="dot",y_=["typed","addScalar","multiplyScalar","conj","size"],b_=mt(lc,y_,i=>{var{typed:t,addScalar:e,multiplyScalar:r,conj:n,size:s}=i;return t(lc,{"Array | DenseMatrix, Array | DenseMatrix":l,"SparseMatrix, SparseMatrix":f});function u(h,c){var m=p(h),_=p(c),w,g;if(m.length===1)w=m[0];else if(m.length===2&&m[1]===1)w=m[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+m.join(", ")+")");if(_.length===1)g=_[0];else if(_.length===2&&_[1]===1)g=_[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+_.join(", ")+")");if(w!==g)throw new RangeError("Vectors must have equal length ("+w+" != "+g+")");if(w===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return w}function l(h,c){var m=u(h,c),_=fe(h)?h._data:h,w=fe(h)?h._datatype||h.getDataType():void 0,g=fe(c)?c._data:c,y=fe(c)?c._datatype||c.getDataType():void 0,v=p(h).length===2,E=p(c).length===2,b=e,N=r;if(w&&y&&w===y&&typeof w=="string"&&w!=="mixed"){var x=w;b=t.find(e,[x,x]),N=t.find(r,[x,x])}if(!v&&!E){for(var F=N(n(_[0]),g[0]),M=1;M<m;M++)F=b(F,N(n(_[M]),g[M]));return F}if(!v&&E){for(var S=N(n(_[0]),g[0][0]),$=1;$<m;$++)S=b(S,N(n(_[$]),g[$][0]));return S}if(v&&!E){for(var C=N(n(_[0][0]),g[0]),I=1;I<m;I++)C=b(C,N(n(_[I][0]),g[I]));return C}if(v&&E){for(var R=N(n(_[0][0]),g[0][0]),U=1;U<m;U++)R=b(R,N(n(_[U][0]),g[U][0]));return R}}function f(h,c){u(h,c);for(var m=h._index,_=h._values,w=c._index,g=c._values,y=0,v=e,E=r,b=0,N=0;b<m.length&&N<w.length;){var x=m[b],F=w[N];if(x<F){b++;continue}if(x>F){N++;continue}x===F&&(y=v(y,E(_[b],g[N])),b++,N++)}return y}function p(h){return fe(h)?h.size():s(h)}}),E_="trace",A_=["typed","matrix","add"],x_=mt(E_,A_,i=>{var{typed:t,matrix:e,add:r}=i;return t("trace",{Array:function(l){return n(e(l))},SparseMatrix:s,DenseMatrix:n,any:te});function n(u){var l=u._size,f=u._data;switch(l.length){case 1:if(l[0]===1)return te(f[0]);throw new RangeError("Matrix must be square (size: "+se(l)+")");case 2:{var p=l[0],h=l[1];if(p===h){for(var c=0,m=0;m<p;m++)c=r(c,f[m][m]);return c}else throw new RangeError("Matrix must be square (size: "+se(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+se(l)+")")}}function s(u){var l=u._values,f=u._index,p=u._ptr,h=u._size,c=h[0],m=h[1];if(c===m){var _=0;if(l.length>0)for(var w=0;w<m;w++)for(var g=p[w],y=p[w+1],v=g;v<y;v++){var E=f[v];if(E===w){_=r(_,l[v]);break}if(E>w)break}return _}throw new RangeError("Matrix must be square (size: "+se(h)+")")}}),fc="det",C_=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],F_=mt(fc,C_,i=>{var{typed:t,matrix:e,subtractScalar:r,multiply:n,divideScalar:s,isZero:u,unaryMinus:l}=i;return t(fc,{any:function(h){return te(h)},"Array | Matrix":function(h){var c;switch(fe(h)?c=h.size():Array.isArray(h)?(h=e(h),c=h.size()):c=[],c.length){case 0:return te(h);case 1:if(c[0]===1)return te(h.valueOf()[0]);if(c[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+se(c)+")");case 2:{var m=c[0],_=c[1];if(m===_)return f(h.clone().valueOf(),m);if(_===0)return 1;throw new RangeError("Matrix must be square (size: "+se(c)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+se(c)+")")}}});function f(p,h,c){if(h===1)return te(p[0][0]);if(h===2)return r(n(p[0][0],p[1][1]),n(p[1][0],p[0][1]));for(var m=!1,_=new Array(h).fill(0).map((M,S)=>S),w=0;w<h;w++){var g=_[w];if(u(p[g][w])){var y=void 0;for(y=w+1;y<h;y++)if(!u(p[_[y]][w])){g=_[y],_[y]=_[w],_[w]=g,m=!m;break}if(y===h)return p[g][w]}for(var v=p[g][w],E=w===0?1:p[_[w-1]][w-1],b=w+1;b<h;b++)for(var N=_[b],x=w+1;x<h;x++)p[N][x]=s(r(n(p[N][x],v),n(p[N][w],p[g][x])),E)}var F=p[_[h-1]][h-1];return m?l(F):F}}),cc="inv",M_=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],N_=mt(cc,M_,i=>{var{typed:t,matrix:e,divideScalar:r,addScalar:n,multiply:s,unaryMinus:u,det:l,identity:f,abs:p}=i;return t(cc,{"Array | Matrix":function(m){var _=fe(m)?m.size():Ae(m);switch(_.length){case 1:if(_[0]===1)return fe(m)?e([r(1,m.valueOf()[0])]):[r(1,m[0])];throw new RangeError("Matrix must be square (size: "+se(_)+")");case 2:{var w=_[0],g=_[1];if(w===g)return fe(m)?e(h(m.valueOf(),w,g),m.storage()):h(m,w,g);throw new RangeError("Matrix must be square (size: "+se(_)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+se(_)+")")}},any:function(m){return r(1,m)}});function h(c,m,_){var w,g,y,v,E;if(m===1){if(v=c[0][0],v===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,v)]]}else if(m===2){var b=l(c);if(b===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(c[1][1],b),r(u(c[0][1]),b)],[r(u(c[1][0]),b),r(c[0][0],b)]]}else{var N=c.concat();for(w=0;w<m;w++)N[w]=N[w].concat();for(var x=f(m).valueOf(),F=0;F<_;F++){var M=p(N[F][F]),S=F;for(w=F+1;w<m;)p(N[w][F])>M&&(M=p(N[w][F]),S=w),w++;if(M===0)throw Error("Cannot calculate inverse, determinant is zero");w=S,w!==F&&(E=N[F],N[F]=N[w],N[w]=E,E=x[F],x[F]=x[w],x[w]=E);var $=N[F],C=x[F];for(w=0;w<m;w++){var I=N[w],R=x[w];if(w!==F){if(I[F]!==0){for(y=r(u(I[F]),$[F]),g=F;g<_;g++)I[g]=n(I[g],s(y,$[g]));for(g=0;g<_;g++)R[g]=n(R[g],s(y,C[g]))}}else{for(y=$[F],g=F;g<_;g++)I[g]=r(I[g],y);for(g=0;g<_;g++)R[g]=r(R[g],y)}}}return x}}}),hc="pinv",S_=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],B_=mt(hc,S_,i=>{var{typed:t,matrix:e,inv:r,deepEqual:n,equal:s,dotDivide:u,dot:l,ctranspose:f,divideScalar:p,multiply:h,add:c,Complex:m}=i;return t(hc,{"Array | Matrix":function(b){var N=fe(b)?b.size():Ae(b);switch(N.length){case 1:return v(b)?f(b):N[0]===1?r(b):u(f(b),l(b,b));case 2:{if(v(b))return f(b);var x=N[0],F=N[1];if(x===F)try{return r(b)}catch(M){if(!(M instanceof Error&&M.message.match(/Cannot calculate inverse, determinant is zero/)))throw M}return fe(b)?e(_(b.valueOf(),x,F),b.storage()):_(b,x,F)}default:throw new RangeError("Matrix must be two dimensional (size: "+se(N)+")")}},any:function(b){return s(b,0)?te(b):p(1,b)}});function _(E,b,N){var{C:x,F}=g(E,b,N),M=h(r(h(f(x),x)),f(x)),S=h(f(F),r(h(F,f(F))));return h(S,M)}function w(E,b,N){for(var x=te(E),F=0,M=0;M<b;M++){if(N<=F)return x;for(var S=M;y(x[S][F]);)if(S++,b===S&&(S=M,F++,N===F))return x;[x[S],x[M]]=[x[M],x[S]];for(var $=x[M][F],C=0;C<N;C++)x[M][C]=u(x[M][C],$);for(var I=0;I<b;I++)if(I!==M){$=x[I][F];for(var R=0;R<N;R++)x[I][R]=c(x[I][R],h(-1,h($,x[M][R])))}F++}return x}function g(E,b,N){var x=w(E,b,N),F=E.map((S,$)=>S.filter((C,I)=>I<b&&!y(l(x[I],x[I])))),M=x.filter((S,$)=>!y(l(x[$],x[$])));return{C:F,F:M}}function y(E){return s(c(E,m(1,1)),c(0,m(1,1)))}function v(E){return n(c(E,m(1,1)),c(h(E,0),m(1,1)))}}),I_="divide",T_=["typed","matrix","multiply","equalScalar","divideScalar","inv"],$_=mt(I_,T_,i=>{var{typed:t,matrix:e,multiply:r,equalScalar:n,divideScalar:s,inv:u}=i,l=ba({typed:t,equalScalar:n}),f=Ea({typed:t});return t("divide",Bl({"Array | Matrix, Array | Matrix":function(h,c){return r(h,u(c))},"DenseMatrix, any":function(h,c){return f(h,c,s,!1)},"SparseMatrix, any":function(h,c){return l(h,c,s,!1)},"Array, any":function(h,c){return f(e(h),c,s,!1).valueOf()},"any, Array | Matrix":function(h,c){return r(h,u(c))}},s.signatures))}),pc="sum",O_=["typed","config","add","numeric"],R_=mt(pc,O_,i=>{var{typed:t,config:e,add:r,numeric:n}=i;return t(pc,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":u,"...":function(f){if(Ts(f))throw new TypeError("Scalar values expected in function sum");return s(f)}});function s(l){var f;return Wi(l,function(p){try{f=f===void 0?p:r(f,p)}catch(h){throw vn(h,"sum",p)}}),f===void 0&&(f=n(0,e.number)),typeof f=="string"&&(f=n(f,e.number)),f}function u(l,f){try{var p=ya(l,f,r);return p}catch(h){throw vn(h,"sum")}}}),dc="median",L_=["typed","add","divide","compare","partitionSelect"],P_=mt(dc,L_,i=>{var{typed:t,add:e,divide:r,compare:n,partitionSelect:s}=i;function u(p){try{p=ha(p.valueOf());var h=p.length;if(h===0)throw new Error("Cannot calculate median of an empty array");if(h%2===0){for(var c=h/2-1,m=s(p,c+1),_=p[c],w=0;w<c;++w)n(p[w],_)>0&&(_=p[w]);return f(_,m)}else{var g=s(p,(h-1)/2);return l(g)}}catch(y){throw vn(y,"median")}}var l=t({"number | BigNumber | Complex | Unit":function(h){return h}}),f=t({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(h,c){return r(e(h,c),2)}});return t(dc,{"Array | Matrix":u,"Array | Matrix, number | BigNumber":function(h,c){throw new Error("median(A, dim) is not yet supported")},"...":function(h){if(Ts(h))throw new TypeError("Scalar values expected in function median");return u(h)}})}),Ys=zm({config:nr}),Aa=Wm({}),xa=Gm({}),Ca=Jm({}),Wr=Qm({Matrix:Ca}),Ft=kd({BigNumber:Ys,Complex:Aa,DenseMatrix:Wr,Fraction:xa}),z_=Bg({typed:Ft}),js=Tg({typed:Ft}),q_=bg({BigNumber:Ys,typed:Ft}),mc=Dv({typed:Ft}),_n=cg({config:nr,typed:Ft}),Zs=rg({typed:Ft}),U_=og({typed:Ft}),Gs=hv({typed:Ft}),gc=wg({typed:Ft}),Fa=dg({Matrix:Ca,equalScalar:_n,typed:Ft}),vc=Og({typed:Ft}),_c=ug({typed:Ft}),Ma=Ng({typed:Ft}),wc=xg({Fraction:xa,typed:Ft}),Dc=ig({typed:Ft}),xe=Fg({DenseMatrix:Wr,Matrix:Ca,SparseMatrix:Fa,typed:Ft}),yc=Uv({isNaN:_c,isNumeric:Dc,typed:Ft}),Yi=Zv({bignumber:q_,fraction:wc,number:gc}),k_=Wv({config:nr,multiplyScalar:Gs,numeric:Yi,typed:Ft}),W_=Tv({isInteger:Zs,matrix:xe,typed:Ft}),bc=Ov({matrix:xe,config:nr,typed:Ft}),Ec=Lv({matrix:xe,typed:Ft}),Un=bv({isInteger:Zs,matrix:xe,typed:Ft}),Y_=Av({prod:k_,size:bc,typed:Ft}),j_=zv({conj:mc,transpose:Ec,typed:Ft}),ji=Kv({numeric:Yi,typed:Ft}),Z_=Vv({DenseMatrix:Wr,concat:Un,divideScalar:ji,equalScalar:_n,matrix:xe,typed:Ft}),Ac=n_({DenseMatrix:Wr,concat:Un,equalScalar:_n,matrix:xe,typed:Ft}),xc=Cv({BigNumber:Ys,DenseMatrix:Wr,SparseMatrix:Fa,config:nr,matrix:xe,typed:Ft}),G_=Mv({matrix:xe,multiplyScalar:Gs,typed:Ft}),K_=o_({DenseMatrix:Wr,concat:Un,config:nr,matrix:xe,typed:Ft}),H_=gv({DenseMatrix:Wr,concat:Un,equalScalar:_n,matrix:xe,subtractScalar:vc,typed:Ft,unaryMinus:Ma}),Zi=D_({DenseMatrix:Wr,SparseMatrix:Fa,addScalar:js,concat:Un,equalScalar:_n,matrix:xe,typed:Ft}),Cc=t_({BigNumber:Ys,DenseMatrix:Wr,Fraction:xa,concat:Un,config:nr,equalScalar:_n,matrix:xe,typed:Ft}),J_=h_({equal:Ac,typed:Ft}),Fc=b_({addScalar:js,conj:mc,multiplyScalar:Gs,size:bc,typed:Ft}),X_=l_({DenseMatrix:Wr,concat:Un,config:nr,matrix:xe,typed:Ft}),Na=__({config:nr,numeric:Yi,smaller:K_,typed:Ft}),ci=dv({addScalar:js,dot:Fc,equalScalar:_n,matrix:xe,multiplyScalar:Gs,typed:Ft}),V_=d_({compare:Cc,isNaN:_c,isNumeric:Dc,typed:Ft}),Q_=R_({add:Zi,config:nr,numeric:Yi,typed:Ft}),t1=x_({add:Zi,matrix:xe,typed:Ft}),Mc=F_({divideScalar:ji,isZero:U_,matrix:xe,multiply:ci,subtractScalar:vc,typed:Ft,unaryMinus:Ma}),e1=g_({config:nr,larger:X_,numeric:Yi,typed:Ft}),Ks=N_({abs:z_,addScalar:js,det:Mc,divideScalar:ji,identity:xc,matrix:xe,multiply:ci,typed:Ft,unaryMinus:Ma}),r1=B_({Complex:Aa,add:Zi,ctranspose:j_,deepEqual:J_,divideScalar:ji,dot:Fc,dotDivide:Z_,equal:Ac,inv:Ks,matrix:xe,multiply:ci,typed:Ft}),n1=Jv({Complex:Aa,config:nr,fraction:wc,identity:xc,inv:Ks,matrix:xe,multiply:ci,number:gc,typed:Ft}),i1=$_({divideScalar:ji,equalScalar:_n,inv:Ks,matrix:xe,multiply:ci,typed:Ft}),Nc=P_({add:Zi,compare:Cc,divide:i1,partitionSelect:V_,typed:Ft});class s1{constructor(t,e,r){Z(this,"_cacheData");Z(this,"_variables");Z(this,"_math");Z(this,"_timeframe");this._cacheData={},this._variables=t,this._math=e,this._timeframe=r}alma({series:t,length:e,offset:r,sigma:n,floor:s},u){if(e===void 0||r===void 0||n===void 0)return;const l=this._cacheDataList(t,e,`alma_${u}`);if(l===void 0)return;let f=r*(e-1);s&&(f=Math.floor(f));const p=e/n;let h=0,c=0;for(let m=0;m<=e-1;m++){const _=Math.exp(-1*Math.pow(m-f,2)/(2*Math.pow(p,2)));h+=_,c+=l[l.length-1-(e-m-1)]*_}return c/h}sma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;let n=0;const s=this._cacheDataList(t,e,`sma_${r}`);if(s===void 0)return;const u=s.slice(-e);return n=Q_(...u)/e,n}rma({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;const n=this._cacheData[`sma_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`sma_${r}`]=n;const{sum:s}=this._cacheData[`rma_${r}`]||{},u=1/e,l=s===void 0?this.sma({source:t,length:e},r):u*t+(1-u)*(s||0);return this._cacheDataHandle(`rma_${r}`,{sum:l}),l}atr({length:t},e){const{high:r,close:n}=this._cacheData[`atr_${e}`]||{},{high:s,close:u,low:l}=this._variables,f=r===void 0?s-l:Math.max(Math.max(s-l,Math.abs(s-n)),Math.abs(l-n));return this._cacheDataHandle(`atr_${e}`,{high:s,close:u}),this.rma({source:f,length:t},e)}barssince({condition:t},e){let{count:r}=this._cacheData[`barssince_${e}`]||{};if(t)r=0;else{if(r===void 0)return;r+=1}return this._cacheDataHandle(`barssince_${e}`,{count:r}),r}stdev({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0)return;const s=this._cacheDataList(t,e,`stdev_${n}`),u=this.sma({source:t,length:e},n);if(s===void 0)return;let l=0;for(let f=0;f<e;f++){const p=this._sum(s[s.length-1-f],-(u||0));l+=p*p}return r||e<=1?Math.sqrt(l/e):Math.sqrt(l/(e-1))}_sum(t,e){let n=t+e;return Math.abs(n)<=1e-10&&(n=0),n}bb({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[];const s=this.sma({source:t,length:e},n),u=this.stdev({source:t,length:e},n);if(s===void 0||u===void 0)return[];const l=r*u;return[s,s+l,s-l]}bbw({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.sma({source:t,length:e},n),u=this.stdev({source:t,length:e},n);if(s===void 0||u===void 0)return;const l=r*u;return(s+l-(s-l))/s}cci({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r),s=this.dev({source:t,length:e},r);if(!(n===void 0||s===void 0))return(t-n)/(.015*s)}change({source:t,length:e=1},r){const n=this._cacheData[`change_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`change_${r}`]=n;const s=n[n.length-1-e];if(!(t===void 0||isNaN(t)))return s===void 0?s:typeof t=="boolean"?s!==t:t-s}cmo({series:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.change({source:t},r);if(n===void 0)return;const s=this._math.sum({source:n>=0?n:0,length:e},`sm1_${r}`),u=this._math.sum({source:n>=0?0:-n,length:e},`sm2_${r}`);if(!(s===void 0||u===void 0))return 100*(s-u)/(s+u)}cog({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this._cacheDataList(t,e,`cog_${r}`),s=this._math.sum({source:t,length:e},r);if(s===void 0||n===void 0)return;let u=0;for(let l=0;l<e;l++){const f=n[n.length-1-l];u+=f*(l+1)}return-u/s}correlation({source1:t,source2:e,length:r},n){if(t===void 0||isNaN(t)||e===void 0||isNaN(e)||r===void 0)return;const s=this._cacheDataList([t,e],r,`correlation_${n}`),u=this.sma({source:t,length:r},`sma1_${n}`),l=this.sma({source:e,length:r},`sma2_${n}`);if(u===void 0||l===void 0||s===void 0)return;let f=0,p=0,h=0;for(let m=0;m<r;m++){const[_,w]=s[s.length-1-m],g=_-u,y=w-l;f+=g*y,p+=g*g,h+=y*y}return isNaN(p)||isNaN(f)||isNaN(h)?void 0:f/Math.sqrt(p*h)}cross({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`cross_${r}`]||{};return this._cacheDataHandle(`cross_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e||n<=s&&t>e}crossover({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossover_${r}`]||{};return this._cacheDataHandle(`crossover_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n<=s&&t>e}crossunder({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossunder_${r}`]||{};return this._cacheDataHandle(`crossunder_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e}cum({source:t=0},e){t=isNaN(t)?0:t;let{sum:r}=this._cacheData[`cum_${e}`]||{};return r=r||0,r+=t,this._cacheDataHandle(`cum_${e}`,{sum:r}),r}dev({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r);let s=0;const u=this._cacheDataList(t,e,`dev_${r}`);if(!(!u||n===void 0)){for(let l=0;l<e;l++){const f=u[u.length-1-l];s+=Math.abs(f-n)}return s/e}}dmi({diLength:t,adxSmoothing:e},r){if(t===void 0||e===void 0)return[void 0,void 0,void 0];const n=`dmi_${r}`,{low:s,high:u,close:l,PDMS:f,NDMS:p,TRS:h,ADX:c,count:m=0}=this._cacheData[n]||{},{low:_,high:w,close:g}=this._variables;if(s===void 0||u===void 0||l===void 0)return this._cacheData[n]={low:_,high:w,close:g,PDMS:f,NDMS:p,TRS:w-_,count:1},[void 0,void 0,void 0];let y=w-u,v=s-_;y=y>v&&y>0?y:0,v=v>y&&v>0?v:0,y===v&&(y=v=0);const E=Math.max(w-_,Math.abs(w-l),Math.abs(_-l));if(m<t)return this._cacheDataHandle(n,{low:_,high:w,close:g,PDMS:(f||0)+y,NDMS:(p||0)+v,TRS:(h||0)+E,count:m+1}),[void 0,void 0,void 0];{const b=f-f/t+y,N=p-p/t+v,x=h-h/t+E,F=b/x*100,M=N/x*100,S=Math.abs((F-M)/(F+M))*100;let $=S,C=[F,M,void 0];if(m+1-t<e){const I=m+1-t;$=((c||0)*(I-1)+S)/I}else $=(c*(e-1)+S)/e,C=[F,M,$];return this._cacheDataHandle(n,{low:_,high:w,close:g,PDMS:b,NDMS:N,TRS:x,ADX:$,count:m+1}),C}}ema({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;let{sum:n,count:s=1}=this._cacheData[`ema_${r}`]||{};const u=this.sma({source:t,length:e},r);if(s>e){const l=2/(e+1);n=n===void 0?t:l*t+(1-l)*(n||0)}else n=u;return s+=1,this._cacheDataHandle(`ema_${r}`,{sum:n,count:s}),n}falling({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,fallings:s=[]}=this._cacheData[`falling_${r}`]||{};s.push(n>t);const u=s.slice(-e);return this._cacheDataHandle(`falling_${r}`,{source:t,fallings:u}),u.length<e?!1:u.every(l=>l)}rising({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,risings:s=[]}=this._cacheData[`rising_${r}`]||{};s.push(n<t);const u=s.slice(-e);return this._cacheDataHandle(`rising_${r}`,{source:t,risings:u}),u.length<e?!1:u.every(l=>l)}highest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highest_${r}`]||[],{high:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`highest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.max(...l.slice(-e))}highestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highestbars_${r}`]||[],{high:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`highestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((p,h,c,m)=>h>=m[p]?c:p,0)-e+1}wma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`wma_${r}`);if(!n)return;let s=0,u=0;for(let l=0;l<e;l++){const f=(e-l)*e;s+=f,u+=n[n.length-1-l]*f}return u/s}hma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this.wma({source:t,length:e},r),s=this.wma({source:t,length:Math.round(e/2)},r);return n===void 0||s===void 0?void 0:this.wma({source:2*s-n,length:Math.floor(Math.sqrt(e))},`hma_${r}`)}kc({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[void 0,void 0,void 0];const u=this.ema({source:t,length:e},s),{ta:l,high:f,low:p}=this._variables,h=n?l.tr:f-p,c=this.ema({source:h,length:e},`range_${s}`);return[u,u+c*r,u-c*r]}kcw({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const u=this.ema({source:t,length:e},s),{ta:l,high:f,low:p}=this._variables,h=n?l.tr:f-p,c=this.ema({source:h,length:e},`range_${s}`);return(u+c*r-(u-c*r))/u}linreg({source:t,length:e,offset:r},n){if(e===void 0||r===void 0)return;const s=this._cacheDataList(t,e,`dev_${n}`);if(!s)return;const u=s.slice(-e).filter(_=>_!==void 0);let l=0,f=0,p=0,h=0;for(const[_,w]of u.entries())l+=_,f+=w,p+=_*w,h+=_*_;const c=(e*p-l*f)/(e*h-l*l);return(f-c*l)/e+c*(e-1-r)}lowest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowest_${r}`]||[],{low:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`lowest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.min(...l.slice(-e))}lowestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowestbars_${r}`]||[],{low:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`lowestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((p,h,c,m)=>h<=m[p]?c:p,0)-e+1}macd({source:t,fastlen:e,slowlen:r,siglen:n},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0||n===void 0)return[void 0,void 0,void 0];const u=this.ema({source:t,length:e},`ema1_${s}`),l=this.ema({source:t,length:r},`ema2_${s}`);if(u===void 0||l===void 0)return[void 0,void 0,void 0];const f=u-l,p=this.ema({source:f,length:n},`macd_${s}`);if(p===void 0)return[f,p,void 0];const h=f-p;return[f,p,h]}max({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`max_${e}`]||0;return t>r&&(r=t),this._cacheData[`max_${e}`]=r,r}min({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`min_${e}`]||1/0;return t<r&&(r=t),this._cacheData[`min_${e}`]=r,r}median({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`dev_${r}`);if(n)return Nc(n.slice(-e))}mfi({series:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const{volume:n}=this._variables,s=this.change({source:t},r),u=this._math.sum({source:n*(s>=0?0:t),length:e},`lower_${r}`),l=this._math.sum({source:n*(s<=0?0:t),length:e},`upper_${r}`);if(!(l===void 0||u===void 0))return 100-100/(1+l/u)}mode({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`mode_${r}`);if(n)return Na(yc(n.slice(-e)))}mom({source:t,length:e},r){if(e===void 0||e<0)return;const n=`mom_${r}`,s=this._cacheData[n]||[];if(s[this._variables.bar_index]=t,this._cacheData[n]=s,s.length<=e||t===void 0||isNaN(t))return;let u=s.length-e-1,l;for(;l===void 0&&u>=0;)l=s[u],u--;return l===void 0?l:t-l}percentile_linear_interpolation({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e+1,`percentile_linear_interpolation_${n}`);if(!s)return;const u=this._sort(s.slice(-(e+1))),l=u.length;r/=100;const f=1/(l*2);if(r<=f)return u[0];if(r>=1-1/(l*2))return u[l-1];for(const[p,h]of u.entries()){const c=u[p-1];if(r<(p+.5)/l)return c===void 0||h===void 0?void 0:c+(h-c)*(r-(p-.5)/l)/(1/l)}}percentile_nearest_rank({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||t===void 0||isNaN(t)||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e,`percentile_nearest_rank_${n}`);if(!s)return;const u=this._sort(s.slice(-e)),l=r/100*u.length,f=Math.ceil(l)-1;return u[f>=u.length?u.length-1:f]}percentrank({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`percentile_nearest_rank_${r}`);if(!n)return;const s=n.slice(-(e+1)),u=t;if(u===void 0)return;let l=0;for(let f=0;f<s.length;f++)s[f]!==void 0&&(s[f]<u||s[f]===u&&f<e)&&l++;return l/(s.length-1)*100}pivot_point_levels({type:t,anchor:e,developing:r},n){const s=new Jt;let{close:u,open:l,low:f,high:p}=this._variables;const h=`pivot_point_levels_${n}`,{close:c,low:m,high:_,open:w,result:g}=this._cacheData[h]||{};if(!e&&(_&&m&&(p=Math.max(_,p),f=Math.min(m,f)),this._cacheDataHandle(h,{close:u,open:l,low:f,high:p,result:g}),!r))return s._value=g||[],s;const y={close:u,open:l,low:f,high:p};e===!0&&!r&&(u=c,l=w,f=m,p=_);const v=this._getPivotPointLevels(p,f,u,l,r,t);return this._cacheDataHandle(h,{...y,result:v}),s._value=v,s}_getPivotPointLevels(t,e,r,n,s,u){if(r===void 0||n===void 0||e===void 0||t===void 0)return[];switch(u){case Pn.traditional:return this._traditional(t,e,r);case Pn.fibonacci:return this._fibonacci(t,e,r);case Pn.woodie:return s?[]:this._woodie(t,e);case Pn.classic:return this._classic(t,e,r);case Pn.dm:return this._DM(t,e,r,n);case Pn.camarilla:return this._camarilla(t,e,r);default:return[]}}_traditional(t,e,r){const n=(t+e+r)/3,s=n*2-e,u=n+(t-e),l=n*2+(t-2*e),f=n*3+(t-3*e),p=n*4+(t-4*e),h=n*2-t,c=n-(t-e),m=n*2-(2*t-e),_=n*3-(3*t-e),w=n*4-(4*t-e);return[n,s,h,u,c,l,m,f,_,p,w]}_fibonacci(t,e,r){const n=(t+e+r)/3,s=n+.382*(t-e),u=n-.382*(t-e),l=n+.618*(t-e),f=n-.618*(t-e),p=n+(t-e),h=n-(t-e);return[n,s,u,l,f,p,h]}_woodie(t,e){const{open:r}=this._variables,n=(t+e+2*r)/4,s=2*n-e,u=2*n-t,l=n+(t-e),f=n-(t-e),p=t+2*(n-e),h=e-2*(t-n),c=p+(t-e),m=h-(t-e);return[n,s,u,l,f,p,h,c,m]}_classic(t,e,r){const n=(t+e+r)/3,s=2*n-e,u=2*n-t,l=n+(t-e),f=n-(t-e),p=n+2*(t-e),h=n-2*(t-e),c=n+3*(t-e),m=n-3*(t-e);return[n,s,u,l,f,p,h,c,m]}_DM(t,e,r,n){let s;n===r?s=t+e+2*r:r>n?s=2*t+e+r:s=2*e+t+r;const u=s/4,l=s/2-e,f=s/2-t;return[u,l,f]}_camarilla(t,e,r){const n=(t+e+r)/3,s=r+1.1*(t-e)/12,u=r-1.1*(t-e)/12,l=r+1.1*(t-e)/6,f=r-1.1*(t-e)/6,p=r+1.1*(t-e)/4,h=r-1.1*(t-e)/4,c=r+1.1*(t-e)/2,m=r-1.1*(t-e)/2,_=t/e*r,w=r-(_-r);return[n,s,u,l,f,p,h,c,m,_,w]}pivothigh({source:t=this._variables.high,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivothigh_${n}`);if(!s)return;const u=s.slice(-(e+r+1)),l=u[e];return Math.max(...u)===l?l:void 0}pivotlow({source:t=this._variables.low,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivotlow_${n}`);if(!s)return;const u=s.slice(-(e+r+1)),l=u[e];return Math.min(...u)===l?l:void 0}range({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const n=this._cacheDataList(t,e,`range_${r}`);if(!n)return;const s=n.filter(f=>f!==void 0).slice(-e),u=Math.max(...s),l=Math.min(...s);return u-l}roc({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`roc_${r}`),s=this.change({source:t,length:e},r);if(n)return 100*s/n[n.length-1-e]}rsi({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const{source:n}=this._cacheData[`rsi_${r}`]||{},s=Math.max(t-n,0),u=Math.max(n-t,0),l=this.rma({source:s,length:e},`rma1_${r}`),f=this.rma({source:u,length:e},`rma2_${r}`);if(this._cacheDataHandle(`rsi_${r}`,{source:t}),!(l===void 0||f===void 0))return 100-100/(1+l/f)}sar({start:t,inc:e,max:r},n){if(t===void 0||e===void 0||r===void 0)return;const{close:s,low:u,high:l,preLow:f,preHigh:p,data:h={}}=this._cacheData[`sar_${n}`]||{};let{result:c,maxMin:m,acceleration:_,isBelow:w}=h,g=!1;const{close:y,low:v,high:E,bar_index:b}=this._variables;return b===1&&(y>s?(w=!0,m=E,c=u):(w=!1,m=v,c=l),g=!0,_=t),c=c+_*(m-c),w?c>v&&(g=!0,w=!1,c=Math.max(E,m||0),m=v,_=t):c<E&&(g=!0,w=!0,c=Math.min(v,m||0),m=E,_=t),g||(w?E>(m||0)&&(m=E,_=Math.min((_||0)+e,r)):v<(m||0)&&(m=v,_=Math.min((_||0)+e,r))),w?(c=Math.min(c,u),b>1&&(c=Math.min(c,f))):(c=Math.max(c,l),b>1&&(c=Math.max(c,p))),this._cacheDataHandle(`sar_${n}`,{high:E,close:y,low:v,preLow:u,preHigh:l,data:Object.assign(h,{result:c,maxMin:m,acceleration:_,isBelow:w})}),c}stoch({source:t,high:e,low:r,length:n},s){if(n===void 0||e===void 0||r===void 0||t===void 0||isNaN(t)||n<0)return;const u=this.lowest({source:r,length:n},s),l=this.highest({source:e,length:n},s);if(!(u===void 0||l===void 0))return 100*(this._variables.close-u)/(l-u)}supertrend({factor:t,atrPeriod:e},r){if(t===void 0||e===void 0)return[void 0,void 0];const{hl2:n,close:s}=this._variables,u=`supertrend_${r}`,{upperBand:l,lowerBand:f,superTrend:p,atr:h,close:c}=this._cacheData[u]||{},m=this.atr({length:e},r);if(m===void 0)return this._cacheDataHandle(u,{close:s}),[void 0,void 0];let _=n+t*m,w=n-t*m;const g=l||0,y=f||0;w=w>y||c<y?w:y,_=_<g||c>g?_:g;let v;h===void 0?v=1:p===g?v=s>_?-1:1:v=s<w?1:-1;const E=v===-1?w:_;return this._cacheDataHandle(u,{upperBand:_,lowerBand:w,superTrend:E,atr:m,close:s}),[E,v]}swma({source:t},e){let{list:r}=this._cacheData[`swma_${e}`]||{};if(r||(r=[]),r.push(t),r=r.slice(-4),this._cacheDataHandle(`swma_${e}`,{list:r}),!(r.filter(n=>n!==void 0).length<4))return r[3]*1/6+r[2]*2/6+r[1]*2/6+r[0]*1/6}tr({handle_na:t=!1},e){const{close:r,low:n,high:s}=this._variables,{close:u}=this._cacheData[`tr_${e}`]||{};return this._cacheDataHandle(`tr_${e}`,{close:r}),u===void 0?t?s-n:void 0:Math.max(s-n,Math.abs(s-u),Math.abs(n-u))}tsi({source:t,short_length:e,long_length:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.change({source:t},n);if(s===void 0)return;const u=this.ema({source:Math.abs(s),length:e},`absema1_${n}`),l=this.ema({source:s,length:e},`ema1_${n}`);if(l===void 0)return;const f=this.ema({source:l,length:r},`ema2_${n}`),p=this.ema({source:u,length:e},`absema2_${n}`);if(f!==void 0)return f/p}valuewhen({condition:t,source:e,occurrence:r},n){if(e===void 0||r===void 0||r<0)return;let{list:s}=this._cacheData[`valuewhen_${n}`]||{};return s||(s=[]),t&&s.push(e),this._cacheDataHandle(`valuewhen_${n}`,{list:s}),s[s.length-1-r]}variance({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0||e<0)return;const s=this.sma({source:t,length:e},n);if(s===void 0)return;const u=t-s,l=this._math.sum({source:u*u,length:e},n);if(l!==void 0)return r||e<=1?l/e:l/(e-1)}vwap({source:t,anchor:e,stdev_mult:r},n){if(t===void 0)return;e=e===void 0?this._timeframe.change({timeframe:"1D"},n):e;const{volume:s}=this._variables;let{sum:u=0,sumV:l=0,count:f=0,isReset:p,sumS:h=0}=this._cacheData[`vwap_${n}`]||{};if(e&&(u=l=f=h=0,p=!0),!p)return r!==void 0?[]:void 0;const c=t*s+u,m=s+l,_=c/m;return f++,r!==void 0?(h=s*Math.pow(t,2)+h,this._cacheDataHandle(`vwap_${n}`,{sum:c,sumV:m,count:f,isReset:p,sumS:h}),this._computeBands(h,m,r,_)):(this._cacheDataHandle(`vwap_${n}`,{sum:c,sumV:m,count:f,isReset:p}),_)}_computeBands(t,e,r,n){let s=t/e-Math.pow(n,2);s=s<0?0:s;const u=Math.sqrt(s),l=u!==void 0&&!isNaN(u)?n+r*u:void 0,f=u!==void 0&&!isNaN(u)?n-r*u:void 0;return[n,l,f]}vwma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0||e<=0)return;const{volume:n}=this._variables,s=this.sma({source:t*n,length:e},`sma1_${r}`),u=this.sma({source:n,length:e},`sma2_${r}`);if(!(s===void 0||u===void 0))return s/u}wpr({length:t},e){if(t===void 0||t<=0)return;const r=this.highest({length:t},e),n=this.lowest({length:t},e),{close:s}=this._variables;if(!(r===void 0||n===void 0))return(r-s)/(r-n)*-100}_sort(t){const e=t.length;for(let r=0;r<e;r++){let n={};for(let s=0;s<e-r;s++){const{currentVal:u,currentIndex:l}=n,f=t[s];if(f!==void 0){if(u!==void 0&&f<u){t.splice(s,1),t.splice(l,0,f),n={currentIndex:l+1,currentVal:u};continue}n={currentIndex:s,currentVal:f}}}}return t}_cacheDataList(t,e,r){const n=this._cacheData[r]||[];n[this._variables.bar_index]=t,this._cacheData[r]=n;const s=n.filter(()=>!0);if(!(s.length<e))return s}_cacheDataHandle(t,e){const{barIndex:r}=this._cacheData[t]||{};r!==this._variables.bar_index&&(this._cacheData[t]=Object.assign(e,{barIndex:this._variables.bar_index}))}}const o1={onlyInLoop:"'$text' is only allowed inside loops",invalidType:"Invalid argument 'expr$index' in 'operator SQBR' call",typeUseError:"Cannot specify a type form '$text' without also specifying the type.",notTypeKeyword:"'$text' is not a valid type keyword in variable declaration",undeclared:"Undeclared identifier '$name'",repeatVar:"'$name' is already defined",typeMismatch:"Cannot call '$operator' with argument '$index'. An argument of '$typeE' type was used but a '$typeR' is expected.",assignTypeMismatch:"Cannot assign a value of the `$typeE` type to the '$name' variable. The variable is declared with the `$typeR` type.",voidNotVar:"Void expression cannot be assigned to a variable",declareTypeErr:"Declared type '$type' is not compatible with assigned type '$valueType'",mapKeyValErr:"Cannot put <$typeA, $typeB> pairs into a map containing `$typeC` keys and `$typeD` values. The maps passed into the `$name()` function must have the same key types and value types.",inputSourceErr:"Invalid value for the '$name' parameter of the '$funcName' function. Possible values: [open, high, low, close, hl2, hlc3, ohlc4, hlcc4, volume].",buildInUseErr:"Cannot use '$name' as the default value of a type's field. The default value cannot be a function, variable or calculation.",argsLenErr:"Too many arguments passed into the `$name()` function call. Passed $lenA arguments but expected $lenB.",requiredParamErr:"No value assigned to the `$argName` parameter in $name()",argsSyntaxErr:"Syntax error after the argument for `$argName`. Arguments without their parameter name cannot be used after arguments with parameter names.",requestArgsErr:"Type $type cannot be used in $name '$argName' argument",mapKeyErr:"Incorrect `key` type `$type` in the variable. The `key` type must be one of the following: int, float, string, bool, color.",templateErr:"Incorrect number of arguments for the template: $countA expected, $countB passed.",templateNoSupportErr:"The '$name()' function does not support templates",ifOrSwitchTypeErr:"Return type of one of the '$keyword' blocks is not compatible with return type of other block(s) ($types)",argsNameErr:"The '$name' function does not have an argument with the name '$argName'",noFiledErr:"Object has no field $name",methodNotExistErr:"Could not find method or method reference '$methodName' for '$name'",tupleVarErr:"Syntax error: The quantities of tuple elements on each side of the assignment operator do not match. The right side has $indexA but the left side has $indexB.",tupleLeftVarErr:"Invalid assignment. Cannot assign a tuple to a variable '$name'.",tupleRightVarErr:"Cannot assign a variable to a tuple. The right side must be a function call or structure ('if', 'switch', 'for', 'while') returning a tuple with the same number of elements.",tempateTypeErr:"Syntax error: Only templates for arrays and matrices consist of a single type identifier enclosed in angle brackets.",qualifierErr:"'$name' is not a valid type qualifier. Possible values: 'const', 'simple', 'series'",notFindFuncErr:"Could not find function or function reference '$name'",naVarErr:"Value with NA type cannot be assigned to a variable that was defined without type keyword",notHistoryErr:"Variable '$name' doesn't have history values",defaultValueErr:"The default value cannot be a function, variable or calculation.",defaultValueTypeErr:"Default value of type $typeE can not be assigned to an argument of type $typeR",unaryErr:"Syntax error at input '$sign'",funcArgAssignErr:"Function arguments cannot be mutable ('$name')",declaredErr:"A variable declared with the '$prefix' keyword cannot accept values of the '$type' form. Assign a '$prefix' value to this variable or remove the '$prefix' keyword from its declaration.",globalFuncErr:"Cannot use '$name' in local scope",onlyStatementErr:"Scripts must contain one declaration statement: `indicator()`, `strategy()` or `library()`, Your script has $count.",modifyGlobalVarErr:"Cannot modify global variable '$name' in function",inputDefvalErr:"Arguments of input function must be of constant type, or 'source' builtin variables.",objectIsNaErr:"Cannot access the '$name' $type of an undefined object. The object is 'na'."};Pr.SERIES,Pr.SIMPLE,Pr.INPUT,Pr.CONST,Pr.INT,Pr.FLOAT,Pr.BOOL,Pr.COLOR,Pr.STRING;const a1=["close","open","high","low","hl2","hlc3","hlcc4","ohlc4","volume"];var hi=(i=>(i[i.Hint=1]="Hint",i[i.Info=2]="Info",i[i.Warning=4]="Warning",i[i.Error=8]="Error",i))(hi||{});class u1{constructor(t,e){Z(this,"_cacheData");Z(this,"_variables");Z(this,"_errorListener");Z(this,"_count");Z(this,"_historyInputs");Z(this,"_name");this._cacheData={},this._variables=t,this._errorListener=e,this._count=-1,this._name=`inputs_${Tp()}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(t){for(const e of t){const r=e.id;if(!this._cacheData[r])return;Object.assign(this._cacheData[r],{...e,isModify:!0}),self.workerStorage.updateValue(this._name,`in_${e.index}`,{modifyDefval:e.sourceTypeName||e.defval})}}input(t,e){return this._cacheHandle(t,e)}int(t,e){return this._cacheHandle(t,e,"int")}bool(t,e){return this._cacheHandle(t,e,"bool")}color(t,e){return this._cacheHandle(t,e,"color")}time(t,e){return this._cacheHandle(t,e,"time")}float(t,e){return this._cacheHandle(t,e,"float")}price(t,e){return this._cacheHandle(t,e,"price")}source(t,e){return this._cacheHandle(t,e,"source")}string(t,e){return this._cacheHandle(t,e,"string")}symbol(t,e){return this._cacheHandle(t,e,"symbol")}session(t,e){return this._cacheHandle(t,e,"session")}text_area(t,e){return this._cacheHandle(t,e,"text_area")}timeframe(t,e){return this._cacheHandle(t,e,"timeframe")}_cacheHandle(t,e,r){const n=`${r||"input"}_${e}`,s=this._cacheData[n];if(t.defval===void 0&&this._errorListener.addError(o1.inputDefvalErr,e,hi.Error),s)s.isModify?s.sourceTypeName&&(this._cacheData[n].defval=this._variables[s.sourceTypeName]):Object.assign(this._cacheData[n],t);else{const{defval:u,display:l}=t;this._displayVerify(e,l),this._count++,t={inputType:r,...t,index:this._count},this._cacheData[n]=t,this._judgeHistoryInputs(t),(r||t.inputType)==="source"?this._cacheData[n].options=a1:t.options&&!t.options.includes(u)&&this._errorListener.addError(`input's defval should be in options, but '${u}' is not in [${t.options.toString()}]`,e,hi.Error)}return this._cacheData[n].defval}_judgeHistoryInputs(t){const{defval:e,sourceTypeName:r,index:n}=t;let s=r||e;const u=`in_${n}`,l=this._historyInputs[u];if(!l)self.workerStorage.setValue(this._name,u,{defval:s});else{const{defval:f,modifyDefval:p}=l;f===s?s=p||s:self.workerStorage.setValue(this._name,u,{defval:s})}r?t.sourceTypeName=s:t.defval=s}_displayVerify(t,e){!e||!e.length||e.includes(er.dataWindow)||e.includes(er.statusLine)||this._errorListener.addError("Invalid argument 'display' in 'input' call. Possible values: [display.none, display.data_window, display.status_line, display.all]",t,hi.Error)}getInputs(){var n;const t=Object.keys(this._cacheData),e=new Map,r=[];for(const s of t){const u=this._cacheData[s];u.id=s;const{group:l}=u;l?e.has(l)?(n=e.get(l))==null||n.push(u):e.set(l,[u]):r.push(u)}return[...this._getGroups(e),{inputs:r}]}_getGroups(t){const e=[];for(const[r,n]of t)e.push({name:r,inputs:n});return e}}class l1{color({x:t}){return t}new({color:t,transp:e=100}){const{r,g:n,b:s}=this._parseColor(t);return`rgba(${Math.round(r)}, ${Math.round(n)}, ${Math.round(s)}, ${e/100})`}rgb({red:t,green:e,blue:r,transp:n=0}){return`rgba(${t}, ${e}, ${r}, ${n/100})`}g({color:t}){return t?this._parseColor(t).g:0}r({color:t}){return t?this._parseColor(t).r:0}b({color:t}){return t?this._parseColor(t).b:0}t({color:t}){return t?Math.round(this._parseColor(t).a*100):0}from_gradient({value:t,bottom_value:e,top_value:r,bottom_color:n,top_color:s}){const u=(t-e)/(r-e),l=Math.min(Math.max(u,0),1),{r:f,g:p,b:h,a:c}=this._parseColor(n),{r:m,g:_,b:w,a:g}=this._parseColor(s),y=f+l*(m-f),v=p+l*(_-p),E=h+l*(w-h),b=c+l*(g-c);return`rgba(${Math.round(y)}, ${Math.round(v)}, ${Math.round(E)}, ${b.toFixed(2)})`}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const u=t.substring(7);u?s=(255-parseInt(u,16))/255:s=1}else{const u=this._parserRgbColor(t);e=u[0],r=u[1],n=u[2],s=u[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}}var Pt={};const f1=Object.prototype.toString;function Gi(i){const t=f1.call(i);return t.endsWith("Array]")&&!t.includes("Big")}var c1=Object.freeze({__proto__:null,isAnyArray:Gi}),h1=De(c1);function p1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Gi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var u=i[r],l=r+1;l<s;l++)i[l]>u&&(u=i[l]);return u}function d1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Gi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var u=i[r],l=r+1;l<s;l++)i[l]<u&&(u=i[l]);return u}function m1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(Gi(i)){if(i.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var e;if(t.output!==void 0){if(!Gi(t.output))throw new TypeError("output option must be an array if specified");e=t.output}else e=new Array(i.length);var r=d1(i),n=p1(i);if(r===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var s=t.min,u=s===void 0?t.autoMinMax?r:0:s,l=t.max,f=l===void 0?t.autoMinMax?n:1:l;if(u>=f)throw new RangeError("min option must be smaller than max option");for(var p=(f-u)/(n-r),h=0;h<i.length;h++)e[h]=(i[h]-r)*p+u;return e}var g1=Object.freeze({__proto__:null,default:m1}),v1=De(g1);Object.defineProperty(Pt,"__esModule",{value:!0});var Je=h1,Sc=v1;const Hs=" ".repeat(2),Bc=" ".repeat(4);function _1(){return Ic(this)}function Ic(i,t={}){const{maxRows:e=15,maxColumns:r=10,maxNumSize:n=8,padMinus:s="auto"}=t;return`${i.constructor.name} {
54
+ (`+se(S,g)+", "+se(N,g)+") ==> "+(this._values?se(this._values[M],g):"X")}return b},n.prototype.toString=function(){return se(this.toArray())},n.prototype.toJSON=function(){return{mathjs:"SparseMatrix",values:this._values,index:this._index,ptr:this._ptr,size:this._size,datatype:this._datatype}},n.prototype.diagonal=function(g){if(g){if(ye(g)&&(g=g.toNumber()),!ue(g)||!he(g))throw new TypeError("The parameter k must be an integer number")}else g=0;var y=g>0?g:0,v=g<0?-g:0,E=this._size[0],b=this._size[1],N=Math.min(E-v,b-y),x=[],F=[],M=[];M[0]=0;for(var S=y;S<b&&x.length<N;S++)for(var $=this._ptr[S],C=this._ptr[S+1],I=$;I<C;I++){var R=this._index[I];if(R===S-y+v){x.push(this._values[I]),F[x.length-1]=R-v;break}}return M.push(x.length),new n({values:x,index:F,ptr:M,size:[N,1]})},n.fromJSON=function(g){return new n(g)},n.diagonal=function(g,y,v,E,b){if(!ge(g))throw new TypeError("Array expected, size parameter");if(g.length!==2)throw new Error("Only two dimensions matrix are supported");if(g=g.map(function(V){if(ye(V)&&(V=V.toNumber()),!ue(V)||!he(V)||V<1)throw new Error("Size values must be positive integers");return V}),v){if(ye(v)&&(v=v.toNumber()),!ue(v)||!he(v))throw new TypeError("The parameter k must be an integer number")}else v=0;var N=e,x=0;Ur(b)&&(N=t.find(e,[b,b])||e,x=t.convert(0,b));var F=v>0?v:0,M=v<0?-v:0,S=g[0],$=g[1],C=Math.min(S-M,$-F),I;if(ge(y)){if(y.length!==C)throw new Error("Invalid value array length");I=function(tt){return y[tt]}}else if(fe(y)){var R=y.size();if(R.length!==1||R[0]!==C)throw new Error("Invalid matrix length");I=function(tt){return y.get([tt])}}else I=function(){return y};for(var U=[],q=[],k=[],P=0;P<$;P++){k.push(U.length);var K=P-F;if(K>=0&&K<C){var G=I(K);N(G,x)||(q.push(K+M),U.push(G))}}return k.push(U.length),new n({values:U,index:q,ptr:k,size:[S,$]})},n.prototype.swapRows=function(g,y){if(!ue(g)||!he(g)||!ue(y)||!he(y))throw new Error("Row index must be positive integers");if(this._size.length!==2)throw new Error("Only two dimensional matrix is supported");return ve(g,this._size[0]),ve(y,this._size[0]),n._swapRows(g,y,this._size[1],this._values,this._index,this._ptr),this},n._forEachRow=function(g,y,v,E,b){for(var N=E[g],x=E[g+1],F=N;F<x;F++)b(v[F],y[F])},n._swapRows=function(g,y,v,E,b,N){for(var x=0;x<v;x++){var F=N[x],M=N[x+1],S=p(g,F,M,b),$=p(y,F,M,b);if(S<M&&$<M&&b[S]===g&&b[$]===y){if(E){var C=E[S];E[S]=E[$],E[$]=C}continue}if(S<M&&b[S]===g&&($>=M||b[$]!==y)){var I=E?E[S]:void 0;b.splice($,0,y),E&&E.splice($,0,I),b.splice($<=S?S+1:S,1),E&&E.splice($<=S?S+1:S,1);continue}if($<M&&b[$]===y&&(S>=M||b[S]!==g)){var R=E?E[$]:void 0;b.splice(S,0,g),E&&E.splice(S,0,R),b.splice(S<=$?$+1:$,1),E&&E.splice(S<=$?$+1:$,1)}}},n},{isClass:!0}),mg="number",gg=["typed"];function vg(i){var t=i.match(/(0[box])([0-9a-fA-F]*)\.([0-9a-fA-F]*)/);if(t){var e={"0b":2,"0o":8,"0x":16}[t[1]],r=t[2],n=t[3];return{input:i,radix:e,integerPart:r,fractionalPart:n}}else return null}function _g(i){for(var t=parseInt(i.integerPart,i.radix),e=0,r=0;r<i.fractionalPart.length;r++){var n=parseInt(i.fractionalPart[r],i.radix);e+=n/Math.pow(i.radix,r+1)}var s=t+e;if(isNaN(s))throw new SyntaxError('String "'+i.input+'" is not a valid number');return s}var wg=mt(mg,gg,i=>{var{typed:t}=i,e=t("number",{"":function(){return 0},number:function(n){return n},string:function(n){if(n==="NaN")return NaN;var s=vg(n);if(s)return _g(s);var u=0,l=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);l&&(u=Number(l[2]),n=l[1]);var f=Number(n);if(isNaN(f))throw new SyntaxError('String "'+n+'" is not a valid number');if(l){if(f>2**u-1)throw new SyntaxError('String "'.concat(n,'" is out of range'));f>=2**(u-1)&&(f=f-2**u)}return f},BigNumber:function(n){return n.toNumber()},Fraction:function(n){return n.valueOf()},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),null:function(n){return 0},"Unit, string | Unit":function(n,s){return n.toNumber(s)},"Array | Matrix":t.referToSelf(r=>n=>Ir(n,r))});return e.fromJSON=function(r){return parseFloat(r.value)},e}),Dg="bignumber",yg=["typed","BigNumber"],bg=mt(Dg,yg,i=>{var{typed:t,BigNumber:e}=i;return t("bignumber",{"":function(){return new e(0)},number:function(n){return new e(n+"")},string:function(n){var s=n.match(/(0[box][0-9a-fA-F]*)i([0-9]*)/);if(s){var u=s[2],l=e(s[1]),f=new e(2).pow(Number(u));if(l.gt(f.sub(1)))throw new SyntaxError('String "'.concat(n,'" is out of range'));var p=new e(2).pow(Number(u)-1);return l.gte(p)?l.sub(f):l}return new e(n)},BigNumber:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Fraction:function(n){return new e(n.n).div(n.d).times(n.s)},null:function(n){return new e(0)},"Array | Matrix":t.referToSelf(r=>n=>Ir(n,r))})}),Eg="fraction",Ag=["typed","Fraction"],xg=mt(Eg,Ag,i=>{var{typed:t,Fraction:e}=i;return t("fraction",{number:function(n){if(!isFinite(n)||isNaN(n))throw new Error(n+" cannot be represented as a fraction");return new e(n)},string:function(n){return new e(n)},"number, number":function(n,s){return new e(n,s)},null:function(n){return new e(0)},BigNumber:function(n){return new e(n.toString())},Fraction:function(n){return n},Unit:t.referToSelf(r=>n=>{var s=n.clone();return s.value=r(n.value),s}),Object:function(n){return new e(n)},"Array | Matrix":t.referToSelf(r=>n=>Ir(n,r))})}),$f="matrix",Cg=["typed","Matrix","DenseMatrix","SparseMatrix"],Fg=mt($f,Cg,i=>{var{typed:t,Matrix:e,DenseMatrix:r,SparseMatrix:n}=i;return t($f,{"":function(){return s([])},string:function(l){return s([],l)},"string, string":function(l,f){return s([],l,f)},Array:function(l){return s(l)},Matrix:function(l){return s(l,l.storage())},"Array | Matrix, string":s,"Array | Matrix, string, string":s});function s(u,l,f){if(l==="dense"||l==="default"||l===void 0)return new r(u,f);if(l==="sparse")return new n(u,f);throw new TypeError("Unknown matrix type "+JSON.stringify(l)+".")}}),Of="unaryMinus",Mg=["typed"],Ng=mt(Of,Mg,i=>{var{typed:t}=i;return t(Of,{number:Cf,"Complex | BigNumber | Fraction":e=>e.neg(),Unit:t.referToSelf(e=>r=>{var n=r.clone();return n.value=t.find(e,n.valueType())(r.value),n}),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),Rf="abs",Sg=["typed"],Bg=mt(Rf,Sg,i=>{var{typed:t}=i;return t(Rf,{number:bf,"Complex | BigNumber | Fraction | Unit":e=>e.abs(),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),Lf="addScalar",Ig=["typed"],Tg=mt(Lf,Ig,i=>{var{typed:t}=i;return t(Lf,{"number, number":Ef,"Complex, Complex":function(r,n){return r.add(n)},"BigNumber, BigNumber":function(r,n){return r.plus(n)},"Fraction, Fraction":function(r,n){return r.add(n)},"Unit, Unit":t.referToSelf(e=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),Pf="subtractScalar",$g=["typed"],Og=mt(Pf,$g,i=>{var{typed:t}=i;return t(Pf,{"number, number":Af,"Complex, Complex":function(r,n){return r.sub(n)},"BigNumber, BigNumber":function(r,n){return r.minus(n)},"Fraction, Fraction":function(r,n){return r.sub(n)},"Unit, Unit":t.referToSelf(e=>(r,n)=>{if(r.value===null||r.value===void 0)throw new Error("Parameter x contains a unit with undefined value");if(n.value===null||n.value===void 0)throw new Error("Parameter y contains a unit with undefined value");if(!r.equalBase(n))throw new Error("Units do not match");var s=r.clone();return s.value=t.find(e,[s.valueType(),n.valueType()])(s.value,n.value),s.fixPrefix=!1,s})})}),Rg="matAlgo11xS0s",Lg=["typed","equalScalar"],ba=mt(Rg,Lg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u,l){var f=n._values,p=n._index,h=n._ptr,c=n._size,m=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var _=c[0],w=c[1],g,y=e,v=0,E=u;typeof m=="string"&&(g=m,y=t.find(e,[g,g]),v=t.convert(0,g),s=t.convert(s,g),E=t.find(u,[g,g]));for(var b=[],N=[],x=[],F=0;F<w;F++){x[F]=N.length;for(var M=h[F],S=h[F+1],$=M;$<S;$++){var C=p[$],I=l?E(s,f[$]):E(f[$],s);y(I,v)||(N.push(C),b.push(I))}}return x[w]=N.length,n.createSparseMatrix({values:b,index:N,ptr:x,size:[_,w],datatype:g})}}),Pg="matAlgo12xSfs",zg=["typed","DenseMatrix"],li=mt(Pg,zg,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,u,l){var f=n._values,p=n._index,h=n._ptr,c=n._size,m=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var _=c[0],w=c[1],g,y=u;typeof m=="string"&&(g=m,s=t.convert(s,g),y=t.find(u,[g,g]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=h[N],M=h[N+1],S=F;S<M;S++){var $=p[S];E[$]=f[S],b[$]=x}for(var C=0;C<_;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?y(s,E[C]):y(E[C],s):v[C][N]=l?y(s,0):y(0,s)}return new e({data:v,size:[_,w],datatype:g})}}),qg="matAlgo14xDs",Ug=["typed"],Ea=mt(qg,Ug,i=>{var{typed:t}=i;return function(n,s,u,l){var f=n._data,p=n._size,h=n._datatype,c,m=u;typeof h=="string"&&(c=h,s=t.convert(s,c),m=t.find(u,[c,c]));var _=p.length>0?e(m,0,p,p[0],f,s,l):[];return n.createDenseMatrix({data:_,size:te(p),datatype:c})};function e(r,n,s,u,l,f,p){var h=[];if(n===s.length-1)for(var c=0;c<u;c++)h[c]=p?r(f,l[c]):r(l[c],f);else for(var m=0;m<u;m++)h[m]=e(r,n+1,s,s[n+1],l[m],f,p);return h}}),kg="matAlgo02xDS0",Wg=["typed","equalScalar"],Yg=mt(kg,Wg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u,l){var f=n._data,p=n._size,h=n._datatype||n.getDataType(),c=s._values,m=s._index,_=s._ptr,w=s._size,g=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(p.length!==w.length)throw new Zt(p.length,w.length);if(p[0]!==w[0]||p[1]!==w[1])throw new RangeError("Dimension mismatch. Matrix A ("+p+") must match Matrix B ("+w+")");if(!c)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var y=p[0],v=p[1],E,b=e,N=0,x=u;typeof h=="string"&&h===g&&h!=="mixed"&&(E=h,b=t.find(e,[E,E]),N=t.convert(0,E),x=t.find(u,[E,E]));for(var F=[],M=[],S=[],$=0;$<v;$++){S[$]=M.length;for(var C=_[$],I=_[$+1],R=C;R<I;R++){var U=m[R],q=l?x(c[R],f[U][$]):x(f[U][$],c[R]);b(q,N)||(M.push(U),F.push(q))}}return S[v]=M.length,s.createSparseMatrix({values:F,index:M,ptr:S,size:[y,v],datatype:h===n._datatype&&g===s._datatype?E:void 0})}}),jg="matAlgo03xDSf",Zg=["typed"],fi=mt(jg,Zg,i=>{var{typed:t}=i;return function(r,n,s,u){var l=r._data,f=r._size,p=r._datatype||r.getDataType(),h=n._values,c=n._index,m=n._ptr,_=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==_.length)throw new Zt(f.length,_.length);if(f[0]!==_[0]||f[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+_+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var g=f[0],y=f[1],v,E=0,b=s;typeof p=="string"&&p===w&&p!=="mixed"&&(v=p,E=t.convert(0,v),b=t.find(s,[v,v]));for(var N=[],x=0;x<g;x++)N[x]=[];for(var F=[],M=[],S=0;S<y;S++){for(var $=S+1,C=m[S],I=m[S+1],R=C;R<I;R++){var U=c[R];F[U]=u?b(h[R],l[U][S]):b(l[U][S],h[R]),M[U]=$}for(var q=0;q<g;q++)M[q]===$?N[q][S]=F[q]:N[q][S]=u?b(E,l[q][S]):b(l[q][S],E)}return r.createDenseMatrix({data:N,size:[g,y],datatype:p===r._datatype&&w===n._datatype?v:void 0})}}),Gg="matAlgo05xSfSf",Kg=["typed","equalScalar"],zf=mt(Gg,Kg,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u){var l=n._values,f=n._index,p=n._ptr,h=n._size,c=n._datatype||n._data===void 0?n._datatype:n.getDataType(),m=s._values,_=s._index,w=s._ptr,g=s._size,y=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(h.length!==g.length)throw new Zt(h.length,g.length);if(h[0]!==g[0]||h[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+g+")");var v=h[0],E=h[1],b,N=e,x=0,F=u;typeof c=="string"&&c===y&&c!=="mixed"&&(b=c,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(u,[b,b]));var M=l&&m?[]:void 0,S=[],$=[],C=M?[]:void 0,I=M?[]:void 0,R=[],U=[],q,k,P,K;for(k=0;k<E;k++){$[k]=S.length;var G=k+1;for(P=p[k],K=p[k+1];P<K;P++)q=f[P],S.push(q),R[q]=G,C&&(C[q]=l[P]);for(P=w[k],K=w[k+1];P<K;P++)q=_[P],R[q]!==G&&S.push(q),U[q]=G,I&&(I[q]=m[P]);if(M)for(P=$[k];P<S.length;){q=S[P];var V=R[q],tt=U[q];if(V===G||tt===G){var ft=V===G?C[q]:x,vt=tt===G?I[q]:x,lt=F(ft,vt);N(lt,x)?S.splice(P,1):(M.push(lt),P++)}}}return $[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:$,size:[v,E],datatype:c===n._datatype&&y===s._datatype?b:void 0})}}),Hg="matAlgo13xDD",Jg=["typed"],Xg=mt(Hg,Jg,i=>{var{typed:t}=i;return function(n,s,u){var l=n._data,f=n._size,p=n._datatype,h=s._data,c=s._size,m=s._datatype,_=[];if(f.length!==c.length)throw new Zt(f.length,c.length);for(var w=0;w<f.length;w++){if(f[w]!==c[w])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+c+")");_[w]=f[w]}var g,y=u;typeof p=="string"&&p===m&&(g=p,y=t.find(u,[g,g]));var v=_.length>0?e(y,0,_,_[0],l,h):[];return n.createDenseMatrix({data:v,size:_,datatype:g})};function e(r,n,s,u,l,f){var p=[];if(n===s.length-1)for(var h=0;h<u;h++)p[h]=r(l[h],f[h]);else for(var c=0;c<u;c++)p[c]=e(r,n+1,s,s[n+1],l[c],f[c]);return p}}),Vg="broadcast",Qg=["concat"],tv=mt(Vg,Qg,i=>{var{concat:t}=i;return function(n,s){var u=Math.max(n._size.length,s._size.length);if(n._size.length===s._size.length&&n._size.every((w,g)=>w===s._size[g]))return[n,s];for(var l=e(n._size,u,0),f=e(s._size,u,0),p=[],h=0;h<u;h++)p[h]=Math.max(l[h],f[h]);As(l,p),As(f,p);var c=n.clone(),m=s.clone();c._size.length<u?c.reshape(e(c._size,u,1)):m._size.length<u&&m.reshape(e(m._size,u,1));for(var _=0;_<u;_++)c._size[_]<p[_]&&(c=r(c,p[_],_)),m._size[_]<p[_]&&(m=r(m,p[_],_));return[c,m]};function e(n,s,u){return[...Array(s-n.length).fill(u),...n]}function r(n,s,u){return t(...Array(s).fill(n),u)}}),ev="matrixAlgorithmSuite",rv=["typed","matrix","concat"],qn=mt(ev,rv,i=>{var{typed:t,matrix:e,concat:r}=i,n=Xg({typed:t}),s=Ea({typed:t}),u=tv({concat:r});return function(f){var p=f.elop,h=f.SD||f.DS,c;p?(c={"DenseMatrix, DenseMatrix":(g,y)=>n(...u(g,y),p),"Array, Array":(g,y)=>n(...u(e(g),e(y)),p).valueOf(),"Array, DenseMatrix":(g,y)=>n(...u(e(g),y),p),"DenseMatrix, Array":(g,y)=>n(...u(g,e(y)),p)},f.SS&&(c["SparseMatrix, SparseMatrix"]=(g,y)=>f.SS(...u(g,y),p,!1)),f.DS&&(c["DenseMatrix, SparseMatrix"]=(g,y)=>f.DS(...u(g,y),p,!1),c["Array, SparseMatrix"]=(g,y)=>f.DS(...u(e(g),y),p,!1)),h&&(c["SparseMatrix, DenseMatrix"]=(g,y)=>h(...u(y,g),p,!0),c["SparseMatrix, Array"]=(g,y)=>h(...u(e(y),g),p,!0))):(c={"DenseMatrix, DenseMatrix":t.referToSelf(g=>(y,v)=>n(...u(y,v),g)),"Array, Array":t.referToSelf(g=>(y,v)=>n(...u(e(y),e(v)),g).valueOf()),"Array, DenseMatrix":t.referToSelf(g=>(y,v)=>n(...u(e(y),v),g)),"DenseMatrix, Array":t.referToSelf(g=>(y,v)=>n(...u(y,e(v)),g))},f.SS&&(c["SparseMatrix, SparseMatrix"]=t.referToSelf(g=>(y,v)=>f.SS(...u(y,v),g,!1))),f.DS&&(c["DenseMatrix, SparseMatrix"]=t.referToSelf(g=>(y,v)=>f.DS(...u(y,v),g,!1)),c["Array, SparseMatrix"]=t.referToSelf(g=>(y,v)=>f.DS(...u(e(y),v),g,!1))),h&&(c["SparseMatrix, DenseMatrix"]=t.referToSelf(g=>(y,v)=>h(...u(v,y),g,!0)),c["SparseMatrix, Array"]=t.referToSelf(g=>(y,v)=>h(...u(e(v),y),g,!0))));var m=f.scalar||"any",_=f.Ds||f.Ss;_&&(p?(c["DenseMatrix,"+m]=(g,y)=>s(g,y,p,!1),c[m+", DenseMatrix"]=(g,y)=>s(y,g,p,!0),c["Array,"+m]=(g,y)=>s(e(g),y,p,!1).valueOf(),c[m+", Array"]=(g,y)=>s(e(y),g,p,!0).valueOf()):(c["DenseMatrix,"+m]=t.referToSelf(g=>(y,v)=>s(y,v,g,!1)),c[m+", DenseMatrix"]=t.referToSelf(g=>(y,v)=>s(v,y,g,!0)),c["Array,"+m]=t.referToSelf(g=>(y,v)=>s(e(y),v,g,!1).valueOf()),c[m+", Array"]=t.referToSelf(g=>(y,v)=>s(e(v),y,g,!0).valueOf())));var w=f.sS!==void 0?f.sS:f.Ss;return p?(f.Ss&&(c["SparseMatrix,"+m]=(g,y)=>f.Ss(g,y,p,!1)),w&&(c[m+", SparseMatrix"]=(g,y)=>w(y,g,p,!0))):(f.Ss&&(c["SparseMatrix,"+m]=t.referToSelf(g=>(y,v)=>f.Ss(y,v,g,!1))),w&&(c[m+", SparseMatrix"]=t.referToSelf(g=>(y,v)=>w(v,y,g,!0)))),p&&p.signatures&&Bl(c,p.signatures),c}}),nv="matAlgo01xDSid",iv=["typed"],qf=mt(nv,iv,i=>{var{typed:t}=i;return function(r,n,s,u){var l=r._data,f=r._size,p=r._datatype||r.getDataType(),h=n._values,c=n._index,m=n._ptr,_=n._size,w=n._datatype||n._data===void 0?n._datatype:n.getDataType();if(f.length!==_.length)throw new Zt(f.length,_.length);if(f[0]!==_[0]||f[1]!==_[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+_+")");if(!h)throw new Error("Cannot perform operation on Dense Matrix and Pattern Sparse Matrix");var g=f[0],y=f[1],v=typeof p=="string"&&p!=="mixed"&&p===w?p:void 0,E=v?t.find(s,[v,v]):s,b,N,x=[];for(b=0;b<g;b++)x[b]=[];var F=[],M=[];for(N=0;N<y;N++){for(var S=N+1,$=m[N],C=m[N+1],I=$;I<C;I++)b=c[I],F[b]=u?E(h[I],l[b][N]):E(l[b][N],h[I]),M[b]=S;for(b=0;b<g;b++)M[b]===S?x[b][N]=F[b]:x[b][N]=l[b][N]}return r.createDenseMatrix({data:x,size:[g,y],datatype:p===r._datatype&&w===n._datatype?v:void 0})}}),sv="matAlgo04xSidSid",ov=["typed","equalScalar"],av=mt(sv,ov,i=>{var{typed:t,equalScalar:e}=i;return function(n,s,u){var l=n._values,f=n._index,p=n._ptr,h=n._size,c=n._datatype||n._data===void 0?n._datatype:n.getDataType(),m=s._values,_=s._index,w=s._ptr,g=s._size,y=s._datatype||s._data===void 0?s._datatype:s.getDataType();if(h.length!==g.length)throw new Zt(h.length,g.length);if(h[0]!==g[0]||h[1]!==g[1])throw new RangeError("Dimension mismatch. Matrix A ("+h+") must match Matrix B ("+g+")");var v=h[0],E=h[1],b,N=e,x=0,F=u;typeof c=="string"&&c===y&&c!=="mixed"&&(b=c,N=t.find(e,[b,b]),x=t.convert(0,b),F=t.find(u,[b,b]));var M=l&&m?[]:void 0,S=[],$=[],C=l&&m?[]:void 0,I=l&&m?[]:void 0,R=[],U=[],q,k,P,K,G;for(k=0;k<E;k++){$[k]=S.length;var V=k+1;for(K=p[k],G=p[k+1],P=K;P<G;P++)q=f[P],S.push(q),R[q]=V,C&&(C[q]=l[P]);for(K=w[k],G=w[k+1],P=K;P<G;P++)if(q=_[P],R[q]===V){if(C){var tt=F(C[q],m[P]);N(tt,x)?R[q]=null:C[q]=tt}}else S.push(q),U[q]=V,I&&(I[q]=m[P]);if(C&&I)for(P=$[k];P<S.length;)q=S[P],R[q]===V?(M[P]=C[q],P++):U[q]===V?(M[P]=I[q],P++):S.splice(P,1)}return $[E]=S.length,n.createSparseMatrix({values:M,index:S,ptr:$,size:[v,E],datatype:c===n._datatype&&y===s._datatype?b:void 0})}}),uv="matAlgo10xSids",lv=["typed","DenseMatrix"],Uf=mt(uv,lv,i=>{var{typed:t,DenseMatrix:e}=i;return function(n,s,u,l){var f=n._values,p=n._index,h=n._ptr,c=n._size,m=n._datatype;if(!f)throw new Error("Cannot perform operation on Pattern Sparse Matrix and Scalar value");var _=c[0],w=c[1],g,y=u;typeof m=="string"&&(g=m,s=t.convert(s,g),y=t.find(u,[g,g]));for(var v=[],E=[],b=[],N=0;N<w;N++){for(var x=N+1,F=h[N],M=h[N+1],S=F;S<M;S++){var $=p[S];E[$]=f[S],b[$]=x}for(var C=0;C<_;C++)N===0&&(v[C]=[]),b[C]===x?v[C][N]=l?y(s,E[C]):y(E[C],s):v[C][N]=s}return new e({data:v,size:[_,w],datatype:g})}}),fv="multiplyScalar",cv=["typed"],hv=mt(fv,cv,i=>{var{typed:t}=i;return t("multiplyScalar",{"number, number":xf,"Complex, Complex":function(r,n){return r.mul(n)},"BigNumber, BigNumber":function(r,n){return r.times(n)},"Fraction, Fraction":function(r,n){return r.mul(n)},"number | Fraction | BigNumber | Complex, Unit":(e,r)=>r.multiply(e),"Unit, number | Fraction | BigNumber | Complex | Unit":(e,r)=>e.multiply(r)})}),kf="multiply",pv=["typed","matrix","addScalar","multiplyScalar","equalScalar","dot"],dv=mt(kf,pv,i=>{var{typed:t,matrix:e,addScalar:r,multiplyScalar:n,equalScalar:s,dot:u}=i,l=ba({typed:t,equalScalar:s}),f=Ea({typed:t});function p(x,F){switch(x.length){case 1:switch(F.length){case 1:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vectors must have the same length");break;case 2:if(x[0]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Vector length ("+x[0]+") must match Matrix rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;case 2:switch(F.length){case 1:if(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix columns ("+x[1]+") must match Vector length ("+F[0]+")");break;case 2:if(x[1]!==F[0])throw new RangeError("Dimension mismatch in multiplication. Matrix A columns ("+x[1]+") must match Matrix B rows ("+F[0]+")");break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix B has "+F.length+" dimensions)")}break;default:throw new Error("Can only multiply a 1 or 2 dimensional matrix (Matrix A has "+x.length+" dimensions)")}}function h(x,F,M){if(M===0)throw new Error("Cannot multiply two empty vectors");return u(x,F)}function c(x,F){if(F.storage()!=="dense")throw new Error("Support for SparseMatrix not implemented");return m(x,F)}function m(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._data,I=F._size,R=F._datatype||F.getDataType(),U=S[0],q=I[1],k,P=r,K=n;$&&R&&$===R&&typeof $=="string"&&$!=="mixed"&&(k=$,P=t.find(r,[k,k]),K=t.find(n,[k,k]));for(var G=[],V=0;V<q;V++){for(var tt=K(M[0],C[0][V]),ft=1;ft<U;ft++)tt=P(tt,K(M[ft],C[ft][V]));G[V]=tt}return x.createDenseMatrix({data:G,size:[q],datatype:$===x._datatype&&R===F._datatype?k:void 0})}var _=t("_multiplyMatrixVector",{"DenseMatrix, any":g,"SparseMatrix, any":E}),w=t("_multiplyMatrixMatrix",{"DenseMatrix, DenseMatrix":y,"DenseMatrix, SparseMatrix":v,"SparseMatrix, DenseMatrix":b,"SparseMatrix, SparseMatrix":N});function g(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._data,I=F._datatype||F.getDataType(),R=S[0],U=S[1],q,k=r,P=n;$&&I&&$===I&&typeof $=="string"&&$!=="mixed"&&(q=$,k=t.find(r,[q,q]),P=t.find(n,[q,q]));for(var K=[],G=0;G<R;G++){for(var V=M[G],tt=P(V[0],C[0]),ft=1;ft<U;ft++)tt=k(tt,P(V[ft],C[ft]));K[G]=tt}return x.createDenseMatrix({data:K,size:[R],datatype:$===x._datatype&&I===F._datatype?q:void 0})}function y(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._data,I=F._size,R=F._datatype||F.getDataType(),U=S[0],q=S[1],k=I[1],P,K=r,G=n;$&&R&&$===R&&typeof $=="string"&&$!=="mixed"&&$!=="mixed"&&(P=$,K=t.find(r,[P,P]),G=t.find(n,[P,P]));for(var V=[],tt=0;tt<U;tt++){var ft=M[tt];V[tt]=[];for(var vt=0;vt<k;vt++){for(var lt=G(ft[0],C[0][vt]),wt=1;wt<q;wt++)lt=K(lt,G(ft[wt],C[wt][vt]));V[tt][vt]=lt}}return x.createDenseMatrix({data:V,size:[U,k],datatype:$===x._datatype&&R===F._datatype?P:void 0})}function v(x,F){var M=x._data,S=x._size,$=x._datatype||x.getDataType(),C=F._values,I=F._index,R=F._ptr,U=F._size,q=F._datatype||F._data===void 0?F._datatype:F.getDataType();if(!C)throw new Error("Cannot multiply Dense Matrix times Pattern only Matrix");var k=S[0],P=U[1],K,G=r,V=n,tt=s,ft=0;$&&q&&$===q&&typeof $=="string"&&$!=="mixed"&&(K=$,G=t.find(r,[K,K]),V=t.find(n,[K,K]),tt=t.find(s,[K,K]),ft=t.convert(0,K));for(var vt=[],lt=[],wt=[],yt=F.createSparseMatrix({values:vt,index:lt,ptr:wt,size:[k,P],datatype:$===x._datatype&&q===F._datatype?K:void 0}),St=0;St<P;St++){wt[St]=lt.length;var bt=R[St],ee=R[St+1];if(ee>bt)for(var It=0,Mt=0;Mt<k;Mt++){for(var ie=Mt+1,Xt=void 0,zt=bt;zt<ee;zt++){var Gt=I[zt];It!==ie?(Xt=V(M[Mt][Gt],C[zt]),It=ie):Xt=G(Xt,V(M[Mt][Gt],C[zt]))}It===ie&&!tt(Xt,ft)&&(lt.push(Mt),vt.push(Xt))}}return wt[P]=lt.length,yt}function E(x,F){var M=x._values,S=x._index,$=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var I=F._data,R=F._datatype||F.getDataType(),U=x._size[0],q=F._size[0],k=[],P=[],K=[],G,V=r,tt=n,ft=s,vt=0;C&&R&&C===R&&typeof C=="string"&&C!=="mixed"&&(G=C,V=t.find(r,[G,G]),tt=t.find(n,[G,G]),ft=t.find(s,[G,G]),vt=t.convert(0,G));var lt=[],wt=[];K[0]=0;for(var yt=0;yt<q;yt++){var St=I[yt];if(!ft(St,vt))for(var bt=$[yt],ee=$[yt+1],It=bt;It<ee;It++){var Mt=S[It];wt[Mt]?lt[Mt]=V(lt[Mt],tt(St,M[It])):(wt[Mt]=!0,P.push(Mt),lt[Mt]=tt(St,M[It]))}}for(var ie=P.length,Xt=0;Xt<ie;Xt++){var zt=P[Xt];k[Xt]=lt[zt]}return K[1]=P.length,x.createSparseMatrix({values:k,index:P,ptr:K,size:[U,1],datatype:C===x._datatype&&R===F._datatype?G:void 0})}function b(x,F){var M=x._values,S=x._index,$=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType();if(!M)throw new Error("Cannot multiply Pattern only Matrix times Dense Matrix");var I=F._data,R=F._datatype||F.getDataType(),U=x._size[0],q=F._size[0],k=F._size[1],P,K=r,G=n,V=s,tt=0;C&&R&&C===R&&typeof C=="string"&&C!=="mixed"&&(P=C,K=t.find(r,[P,P]),G=t.find(n,[P,P]),V=t.find(s,[P,P]),tt=t.convert(0,P));for(var ft=[],vt=[],lt=[],wt=x.createSparseMatrix({values:ft,index:vt,ptr:lt,size:[U,k],datatype:C===x._datatype&&R===F._datatype?P:void 0}),yt=[],St=[],bt=0;bt<k;bt++){lt[bt]=vt.length;for(var ee=bt+1,It=0;It<q;It++){var Mt=I[It][bt];if(!V(Mt,tt))for(var ie=$[It],Xt=$[It+1],zt=ie;zt<Xt;zt++){var Gt=S[zt];St[Gt]!==ee?(St[Gt]=ee,vt.push(Gt),yt[Gt]=G(Mt,M[zt])):yt[Gt]=K(yt[Gt],G(Mt,M[zt]))}}for(var Ce=lt[bt],sr=vt.length,Me=Ce;Me<sr;Me++){var Vr=vt[Me];ft[Me]=yt[Vr]}}return lt[k]=vt.length,wt}function N(x,F){var M=x._values,S=x._index,$=x._ptr,C=x._datatype||x._data===void 0?x._datatype:x.getDataType(),I=F._values,R=F._index,U=F._ptr,q=F._datatype||F._data===void 0?F._datatype:F.getDataType(),k=x._size[0],P=F._size[1],K=M&&I,G,V=r,tt=n;C&&q&&C===q&&typeof C=="string"&&C!=="mixed"&&(G=C,V=t.find(r,[G,G]),tt=t.find(n,[G,G]));for(var ft=K?[]:void 0,vt=[],lt=[],wt=x.createSparseMatrix({values:ft,index:vt,ptr:lt,size:[k,P],datatype:C===x._datatype&&q===F._datatype?G:void 0}),yt=K?[]:void 0,St=[],bt,ee,It,Mt,ie,Xt,zt,Gt,Ce=0;Ce<P;Ce++){lt[Ce]=vt.length;var sr=Ce+1;for(ie=U[Ce],Xt=U[Ce+1],Mt=ie;Mt<Xt;Mt++)if(Gt=R[Mt],K)for(ee=$[Gt],It=$[Gt+1],bt=ee;bt<It;bt++)zt=S[bt],St[zt]!==sr?(St[zt]=sr,vt.push(zt),yt[zt]=tt(I[Mt],M[bt])):yt[zt]=V(yt[zt],tt(I[Mt],M[bt]));else for(ee=$[Gt],It=$[Gt+1],bt=ee;bt<It;bt++)zt=S[bt],St[zt]!==sr&&(St[zt]=sr,vt.push(zt));if(K)for(var Me=lt[Ce],Vr=vt.length,wn=Me;wn<Vr;wn++){var Qr=vt[wn];ft[wn]=yt[Qr]}}return lt[P]=vt.length,wt}return t(kf,n,{"Array, Array":t.referTo("Matrix, Matrix",x=>(F,M)=>{p(Ae(F),Ae(M));var S=x(e(F),e(M));return fe(S)?S.valueOf():S}),"Matrix, Matrix":function(F,M){var S=F.size(),$=M.size();return p(S,$),S.length===1?$.length===1?h(F,M,S[0]):c(F,M):$.length===1?_(F,M):w(F,M)},"Matrix, Array":t.referTo("Matrix,Matrix",x=>(F,M)=>x(F,e(M))),"Array, Matrix":t.referToSelf(x=>(F,M)=>x(e(F,M.storage()),M)),"SparseMatrix, any":function(F,M){return l(F,M,n,!1)},"DenseMatrix, any":function(F,M){return f(F,M,n,!1)},"any, SparseMatrix":function(F,M){return l(M,F,n,!0)},"any, DenseMatrix":function(F,M){return f(M,F,n,!0)},"Array, any":function(F,M){return f(e(F),M,n,!1).valueOf()},"any, Array":function(F,M){return f(e(M),F,n,!0).valueOf()},"any, any":n,"any, any, ...any":t.referToSelf(x=>(F,M,S)=>{for(var $=x(F,M),C=0;C<S.length;C++)$=x($,S[C]);return $})})}),Wf="subtract",mv=["typed","matrix","equalScalar","subtractScalar","unaryMinus","DenseMatrix","concat"],gv=mt(Wf,mv,i=>{var{typed:t,matrix:e,equalScalar:r,subtractScalar:n,unaryMinus:s,DenseMatrix:u,concat:l}=i,f=qf({typed:t}),p=fi({typed:t}),h=zf({typed:t,equalScalar:r}),c=Uf({typed:t,DenseMatrix:u}),m=li({typed:t,DenseMatrix:u}),_=qn({typed:t,matrix:e,concat:l});return t(Wf,{"any, any":n},_({elop:n,SS:h,DS:f,SD:p,Ss:m,sS:c}))}),vv="matAlgo07xSSf",_v=["typed","DenseMatrix"],zs=mt(vv,_v,i=>{var{typed:t,DenseMatrix:e}=i;return function(s,u,l){var f=s._size,p=s._datatype||s._data===void 0?s._datatype:s.getDataType(),h=u._size,c=u._datatype||u._data===void 0?u._datatype:u.getDataType();if(f.length!==h.length)throw new Zt(f.length,h.length);if(f[0]!==h[0]||f[1]!==h[1])throw new RangeError("Dimension mismatch. Matrix A ("+f+") must match Matrix B ("+h+")");var m=f[0],_=f[1],w,g=0,y=l;typeof p=="string"&&p===c&&p!=="mixed"&&(w=p,g=t.convert(0,w),y=t.find(l,[w,w]));var v,E,b=[];for(v=0;v<m;v++)b[v]=[];var N=[],x=[],F=[],M=[];for(E=0;E<_;E++){var S=E+1;for(r(s,E,F,N,S),r(u,E,M,x,S),v=0;v<m;v++){var $=F[v]===S?N[v]:g,C=M[v]===S?x[v]:g;b[v][E]=y($,C)}}return new e({data:b,size:[m,_],datatype:p===s._datatype&&c===u._datatype?w:void 0})};function r(n,s,u,l,f){for(var p=n._values,h=n._index,c=n._ptr,m=c[s],_=c[s+1];m<_;m++){var w=h[m];u[w]=f,l[w]=p[m]}}}),Yf="conj",wv=["typed"],Dv=mt(Yf,wv,i=>{var{typed:t}=i;return t(Yf,{"number | BigNumber | Fraction":e=>e,Complex:e=>e.conjugate(),"Array | Matrix":t.referToSelf(e=>r=>Ir(r,e))})}),jf="concat",yv=["typed","matrix","isInteger"],bv=mt(jf,yv,i=>{var{typed:t,matrix:e,isInteger:r}=i;return t(jf,{"...Array | Matrix | number | BigNumber":function(s){var u,l=s.length,f=-1,p,h=!1,c=[];for(u=0;u<l;u++){var m=s[u];if(fe(m)&&(h=!0),ue(m)||ye(m)){if(u!==l-1)throw new Error("Dimension must be specified as last argument");if(p=f,f=m.valueOf(),!r(f))throw new TypeError("Integer number expected for dimension");if(f<0||u>0&&f>p)throw new hn(f,p+1)}else{var _=te(m).valueOf(),w=Ae(_);if(c[u]=_,p=f,f=w.length-1,u>0&&f!==p)throw new Zt(p+1,f+1)}}if(c.length===0)throw new SyntaxError("At least one matrix expected");for(var g=c.shift();c.length;)g=Xl(g,c.shift(),f);return h?e(g):g},"...string":function(s){return s.join("")}})}),Zf="count",Ev=["typed","size","prod"],Av=mt(Zf,Ev,i=>{var{typed:t,size:e,prod:r}=i;return t(Zf,{string:function(s){return s.length},"Matrix | Array":function(s){return r(e(s))}})}),Gf="identity",xv=["typed","config","matrix","BigNumber","DenseMatrix","SparseMatrix"],Cv=mt(Gf,xv,i=>{var{typed:t,config:e,matrix:r,BigNumber:n,DenseMatrix:s,SparseMatrix:u}=i;return t(Gf,{"":function(){return e.matrix==="Matrix"?r([]):[]},string:function(h){return r(h)},"number | BigNumber":function(h){return f(h,h,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, string":function(h,c){return f(h,h,c)},"number | BigNumber, number | BigNumber":function(h,c){return f(h,c,e.matrix==="Matrix"?"dense":void 0)},"number | BigNumber, number | BigNumber, string":function(h,c,m){return f(h,c,m)},Array:function(h){return l(h)},"Array, string":function(h,c){return l(h,c)},Matrix:function(h){return l(h.valueOf(),h.storage())},"Matrix, string":function(h,c){return l(h.valueOf(),c)}});function l(p,h){switch(p.length){case 0:return h?r(h):[];case 1:return f(p[0],p[0],h);case 2:return f(p[0],p[1],h);default:throw new Error("Vector containing two values expected")}}function f(p,h,c){var m=ye(p)||ye(h)?n:null;if(ye(p)&&(p=p.toNumber()),ye(h)&&(h=h.toNumber()),!he(p)||p<1)throw new Error("Parameters in function identity must be positive integers");if(!he(h)||h<1)throw new Error("Parameters in function identity must be positive integers");var _=m?new n(1):1,w=m?new m(0):0,g=[p,h];if(c){if(c==="sparse")return u.diagonal(g,_,0,w);if(c==="dense")return s.diagonal(g,_,0,w);throw new TypeError('Unknown matrix type "'.concat(c,'"'))}for(var y=ua([],g,w),v=p<h?p:h,E=0;E<v;E++)y[E][E]=_;return y}}),Kf="kron",Fv=["typed","matrix","multiplyScalar"],Mv=mt(Kf,Fv,i=>{var{typed:t,matrix:e,multiplyScalar:r}=i;return t(Kf,{"Matrix, Matrix":function(u,l){return e(n(u.toArray(),l.toArray()))},"Matrix, Array":function(u,l){return e(n(u.toArray(),l))},"Array, Matrix":function(u,l){return e(n(u,l.toArray()))},"Array, Array":n});function n(s,u){if(Ae(s).length===1&&(s=[s]),Ae(u).length===1&&(u=[u]),Ae(s).length>2||Ae(u).length>2)throw new RangeError("Vectors with dimensions greater then 2 are not supported expected (Size x = "+JSON.stringify(s.length)+", y = "+JSON.stringify(u.length)+")");var l=[],f=[];return s.map(function(p){return u.map(function(h){return f=[],l.push(f),p.map(function(c){return h.map(function(m){return f.push(r(c,m))})})})})&&l}});function Nv(){throw new Error('No "bignumber" implementation available')}function Sv(){throw new Error('No "fraction" implementation available')}function Bv(){throw new Error('No "matrix" implementation available')}var Hf="reshape",Iv=["typed","isInteger","matrix"],Tv=mt(Hf,Iv,i=>{var{typed:t,isInteger:e}=i;return t(Hf,{"Matrix, Array":function(n,s){return n.reshape(s,!0)},"Array, Array":function(n,s){return s.forEach(function(u){if(!e(u))throw new TypeError("Invalid size for dimension: "+u)}),fa(n,s)}})}),Jf="size",$v=["typed","config","?matrix"],Ov=mt(Jf,$v,i=>{var{typed:t,config:e,matrix:r}=i;return t(Jf,{Matrix:function(s){return s.create(s.size())},Array:Ae,string:function(s){return e.matrix==="Array"?[s.length]:r([s.length])},"number | Complex | BigNumber | Unit | boolean | null":function(s){return e.matrix==="Array"?[]:r?r([]):Bv()}})}),Xf="transpose",Rv=["typed","matrix"],Lv=mt(Xf,Rv,i=>{var{typed:t,matrix:e}=i;return t(Xf,{Array:u=>r(e(u)).valueOf(),Matrix:r,any:te});function r(u){var l=u.size(),f;switch(l.length){case 1:f=u.clone();break;case 2:{var p=l[0],h=l[1];if(h===0)throw new RangeError("Cannot transpose a 2D matrix with no columns (size: "+se(l)+")");switch(u.storage()){case"dense":f=n(u,p,h);break;case"sparse":f=s(u,p,h);break}}break;default:throw new RangeError("Matrix must be a vector or two dimensional (size: "+se(l)+")")}return f}function n(u,l,f){for(var p=u._data,h=[],c,m=0;m<f;m++){c=h[m]=[];for(var _=0;_<l;_++)c[_]=te(p[_][m])}return u.createDenseMatrix({data:h,size:[f,l],datatype:u._datatype})}function s(u,l,f){for(var p=u._values,h=u._index,c=u._ptr,m=p?[]:void 0,_=[],w=[],g=[],y=0;y<l;y++)g[y]=0;var v,E,b;for(v=0,E=h.length;v<E;v++)g[h[v]]++;for(var N=0,x=0;x<l;x++)w.push(N),N+=g[x],g[x]=w[x];for(w.push(N),b=0;b<f;b++)for(var F=c[b],M=c[b+1],S=F;S<M;S++){var $=g[h[S]]++;_[$]=b,p&&(m[$]=te(p[S]))}return u.createSparseMatrix({values:m,index:_,ptr:w,size:[f,l],datatype:u._datatype})}}),Vf="ctranspose",Pv=["typed","transpose","conj"],zv=mt(Vf,Pv,i=>{var{typed:t,transpose:e,conj:r}=i;return t(Vf,{any:function(s){return r(e(s))}})}),Qf="mode",qv=["typed","isNaN","isNumeric"],Uv=mt(Qf,qv,i=>{var{typed:t,isNaN:e,isNumeric:r}=i;return t(Qf,{"Array | Matrix":n,"...":function(u){return n(u)}});function n(s){s=ha(s.valueOf());var u=s.length;if(u===0)throw new Error("Cannot calculate mode of an empty array");for(var l={},f=[],p=0,h=0;h<s.length;h++){var c=s[h];if(r(c)&&e(c))throw new Error("Cannot calculate mode of an array containing NaN values");c in l||(l[c]=0),l[c]++,l[c]===p?f.push(c):l[c]>p&&(p=l[c],f=[c])}return f}});function vn(i,t,e){var r;return String(i).indexOf("Unexpected type")!==-1?(r=arguments.length>2?" (type: "+cn(e)+", value: "+JSON.stringify(e)+")":" (type: "+i.data.actual+")",new TypeError("Cannot calculate "+t+", unexpected type of argument"+r)):String(i).indexOf("complex numbers")!==-1?(r=arguments.length>2?" (type: "+cn(e)+", value: "+JSON.stringify(e)+")":"",new TypeError("Cannot calculate "+t+", no ordering relation is defined for complex numbers"+r)):i}var tc="prod",kv=["typed","config","multiplyScalar","numeric"],Wv=mt(tc,kv,i=>{var{typed:t,config:e,multiplyScalar:r,numeric:n}=i;return t(tc,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":function(l,f){throw new Error("prod(A, dim) is not yet supported")},"...":function(l){return s(l)}});function s(u){var l;if(Wi(u,function(f){try{l=l===void 0?f:r(l,f)}catch(p){throw vn(p,"prod",f)}}),typeof l=="string"&&(l=n(l,e.number)),l===void 0)throw new Error("Cannot calculate prod of an empty array");return l}}),Yv="numeric",jv=["number","?bignumber","?fraction"],Zv=mt(Yv,jv,i=>{var{number:t,bignumber:e,fraction:r}=i,n={string:!0,number:!0,BigNumber:!0,Fraction:!0},s={number:u=>t(u),BigNumber:e?u=>e(u):Nv,Fraction:r?u=>r(u):Sv};return function(l){var f=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"number",p=arguments.length>2?arguments[2]:void 0;if(p!==void 0)throw new SyntaxError("numeric() takes one or two arguments");var h=cn(l);if(!(h in n))throw new TypeError("Cannot convert "+l+' of type "'+h+'"; valid input types are '+Object.keys(n).join(", "));if(!(f in s))throw new TypeError("Cannot convert "+l+' to type "'+f+'"; valid output types are '+Object.keys(s).join(", "));return f===h?l:s[f](l)}}),ec="divideScalar",Gv=["typed","numeric"],Kv=mt(ec,Gv,i=>{var{typed:t,numeric:e}=i;return t(ec,{"number, number":function(n,s){return n/s},"Complex, Complex":function(n,s){return n.div(s)},"BigNumber, BigNumber":function(n,s){return n.div(s)},"Fraction, Fraction":function(n,s){return n.div(s)},"Unit, number | Complex | Fraction | BigNumber | Unit":(r,n)=>r.divide(n),"number | Fraction | Complex | BigNumber, Unit":(r,n)=>n.divideInto(r)})}),rc="pow",Hv=["typed","config","identity","multiply","matrix","inv","fraction","number","Complex"],Jv=mt(rc,Hv,i=>{var{typed:t,config:e,identity:r,multiply:n,matrix:s,inv:u,number:l,fraction:f,Complex:p}=i;return t(rc,{"number, number":h,"Complex, Complex":function(w,g){return w.pow(g)},"BigNumber, BigNumber":function(w,g){return g.isInteger()||w>=0||e.predictable?w.pow(g):new p(w.toNumber(),0).pow(g.toNumber(),0)},"Fraction, Fraction":function(w,g){var y=w.pow(g);if(y!=null)return y;if(e.predictable)throw new Error("Result of pow is non-rational and cannot be expressed as a fraction");return h(w.valueOf(),g.valueOf())},"Array, number":c,"Array, BigNumber":function(w,g){return c(w,g.toNumber())},"Matrix, number":m,"Matrix, BigNumber":function(w,g){return m(w,g.toNumber())},"Unit, number | BigNumber":function(w,g){return w.pow(g)}});function h(_,w){if(e.predictable&&!he(w)&&_<0)try{var g=f(w),y=l(g);if((w===y||Math.abs((w-y)/w)<1e-14)&&g.d%2===1)return(g.n%2===0?1:-1)*Math.pow(-_,w)}catch{}return e.predictable&&(_<-1&&w===1/0||_>-1&&_<0&&w===-1/0)?NaN:he(w)||_>=0||e.predictable?Ff(_,w):_*_<1&&w===1/0||_*_>1&&w===-1/0?0:new p(_,0).pow(w,0)}function c(_,w){if(!he(w))throw new TypeError("For A^b, b must be an integer (value is "+w+")");var g=Ae(_);if(g.length!==2)throw new Error("For A^b, A must be 2 dimensional (A has "+g.length+" dimensions)");if(g[0]!==g[1])throw new Error("For A^b, A must be square (size is "+g[0]+"x"+g[1]+")");if(w<0)try{return c(u(_),-w)}catch(E){throw E.message==="Cannot calculate inverse, determinant is zero"?new TypeError("For A^b, when A is not invertible, b must be a positive integer (value is "+w+")"):E}for(var y=r(g[0]).valueOf(),v=_;w>=1;)(w&1)===1&&(y=n(v,y)),w>>=1,v=n(v,v);return y}function m(_,w){return s(c(_.valueOf(),w))}}),nc="dotDivide",Xv=["typed","matrix","equalScalar","divideScalar","DenseMatrix","concat"],Vv=mt(nc,Xv,i=>{var{typed:t,matrix:e,equalScalar:r,divideScalar:n,DenseMatrix:s,concat:u}=i,l=Yg({typed:t,equalScalar:r}),f=fi({typed:t}),p=zs({typed:t,DenseMatrix:s}),h=ba({typed:t,equalScalar:r}),c=li({typed:t,DenseMatrix:s}),m=qn({typed:t,matrix:e,concat:u});return t(nc,m({elop:n,SS:p,DS:f,SD:l,Ss:h,sS:c}))}),qs="compare",Qv=["typed","config","matrix","equalScalar","BigNumber","Fraction","DenseMatrix","concat"],t_=mt(qs,Qv,i=>{var{typed:t,config:e,equalScalar:r,matrix:n,BigNumber:s,Fraction:u,DenseMatrix:l,concat:f}=i,p=fi({typed:t}),h=zf({typed:t,equalScalar:r}),c=li({typed:t,DenseMatrix:l}),m=qn({typed:t,matrix:n,concat:f}),_=Ls({typed:t});return t(qs,e_({typed:t,config:e}),{"boolean, boolean":function(g,y){return g===y?0:g>y?1:-1},"BigNumber, BigNumber":function(g,y){return Rs(g,y,e.epsilon)?new s(0):new s(g.cmp(y))},"Fraction, Fraction":function(g,y){return new u(g.compare(y))},"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},_,m({SS:h,DS:p,Ss:c}))}),e_=mt(qs,["typed","config"],i=>{var{typed:t,config:e}=i;return t(qs,{"number, number":function(n,s){return zn(n,s,e.epsilon)?0:n>s?1:-1}})}),Us="equal",r_=["typed","matrix","equalScalar","DenseMatrix","concat"],n_=mt(Us,r_,i=>{var{typed:t,matrix:e,equalScalar:r,DenseMatrix:n,concat:s}=i,u=fi({typed:t}),l=zs({typed:t,DenseMatrix:n}),f=li({typed:t,DenseMatrix:n}),p=qn({typed:t,matrix:e,concat:s});return t(Us,i_({typed:t,equalScalar:r}),p({elop:r,SS:l,DS:u,Ss:f}))}),i_=mt(Us,["typed","equalScalar"],i=>{var{typed:t,equalScalar:e}=i;return t(Us,{"any, any":function(n,s){return n===null?s===null:s===null?n===null:n===void 0?s===void 0:s===void 0?n===void 0:e(n,s)}})}),ks="smaller",s_=["typed","config","matrix","DenseMatrix","concat"],o_=mt(ks,s_,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,u=fi({typed:t}),l=zs({typed:t,DenseMatrix:n}),f=li({typed:t,DenseMatrix:n}),p=qn({typed:t,matrix:r,concat:s}),h=Ls({typed:t});return t(ks,a_({typed:t,config:e}),{"boolean, boolean":(c,m)=>c<m,"BigNumber, BigNumber":function(m,_){return m.lt(_)&&!Rs(m,_,e.epsilon)},"Fraction, Fraction":(c,m)=>c.compare(m)===-1,"Complex, Complex":function(m,_){throw new TypeError("No ordering relation is defined for complex numbers")}},h,p({SS:l,DS:u,Ss:f}))}),a_=mt(ks,["typed","config"],i=>{var{typed:t,config:e}=i;return t(ks,{"number, number":function(n,s){return n<s&&!zn(n,s,e.epsilon)}})}),Ws="larger",u_=["typed","config","matrix","DenseMatrix","concat"],l_=mt(Ws,u_,i=>{var{typed:t,config:e,matrix:r,DenseMatrix:n,concat:s}=i,u=fi({typed:t}),l=zs({typed:t,DenseMatrix:n}),f=li({typed:t,DenseMatrix:n}),p=qn({typed:t,matrix:r,concat:s}),h=Ls({typed:t});return t(Ws,f_({typed:t,config:e}),{"boolean, boolean":(c,m)=>c>m,"BigNumber, BigNumber":function(m,_){return m.gt(_)&&!Rs(m,_,e.epsilon)},"Fraction, Fraction":(c,m)=>c.compare(m)===1,"Complex, Complex":function(){throw new TypeError("No ordering relation is defined for complex numbers")}},h,p({SS:l,DS:u,Ss:f}))}),f_=mt(Ws,["typed","config"],i=>{var{typed:t,config:e}=i;return t(Ws,{"number, number":function(n,s){return n>s&&!zn(n,s,e.epsilon)}})}),ic="deepEqual",c_=["typed","equal"],h_=mt(ic,c_,i=>{var{typed:t,equal:e}=i;return t(ic,{"any, any":function(s,u){return r(s.valueOf(),u.valueOf())}});function r(n,s){if(Array.isArray(n))if(Array.isArray(s)){var u=n.length;if(u!==s.length)return!1;for(var l=0;l<u;l++)if(!r(n[l],s[l]))return!1;return!0}else return!1;else return Array.isArray(s)?!1:e(n,s)}}),sc="partitionSelect",p_=["typed","isNumeric","isNaN","compare"],d_=mt(sc,p_,i=>{var{typed:t,isNumeric:e,isNaN:r,compare:n}=i,s=n,u=(p,h)=>-n(p,h);return t(sc,{"Array | Matrix, number":function(h,c){return l(h,c,s)},"Array | Matrix, number, string":function(h,c,m){if(m==="asc")return l(h,c,s);if(m==="desc")return l(h,c,u);throw new Error('Compare string must be "asc" or "desc"')},"Array | Matrix, number, function":l});function l(p,h,c){if(!he(h)||h<0)throw new Error("k must be a non-negative integer");if(fe(p)){var m=p.size();if(m.length>1)throw new Error("Only one dimensional matrices supported");return f(p.valueOf(),h,c)}if(Array.isArray(p))return f(p,h,c)}function f(p,h,c){if(h>=p.length)throw new Error("k out of bounds");for(var m=0;m<p.length;m++)if(e(p[m])&&r(p[m]))return p[m];for(var _=0,w=p.length-1;_<w;){for(var g=_,y=w,v=p[Math.floor(Math.random()*(w-_+1))+_];g<y;)if(c(p[g],v)>=0){var E=p[y];p[y]=p[g],p[g]=E,--y}else++g;c(p[g],v)>0&&--g,h<=g?w=g:_=g+1}return p[h]}}),oc="max",m_=["typed","config","numeric","larger"],g_=mt(oc,m_,i=>{var{typed:t,config:e,numeric:r,larger:n}=i;return t(oc,{"Array | Matrix":u,"Array | Matrix, number | BigNumber":function(f,p){return ya(f,p.valueOf(),s)},"...":function(f){if(Ts(f))throw new TypeError("Scalar values expected in function max");return u(f)}});function s(l,f){try{return n(l,f)?l:f}catch(p){throw vn(p,"max",f)}}function u(l){var f;if(Wi(l,function(p){try{isNaN(p)&&typeof p=="number"?f=NaN:(f===void 0||n(p,f))&&(f=p)}catch(h){throw vn(h,"max",p)}}),f===void 0)throw new Error("Cannot calculate max of an empty array");return typeof f=="string"&&(f=r(f,e.number)),f}}),ac="min",v_=["typed","config","numeric","smaller"],__=mt(ac,v_,i=>{var{typed:t,config:e,numeric:r,smaller:n}=i;return t(ac,{"Array | Matrix":u,"Array | Matrix, number | BigNumber":function(f,p){return ya(f,p.valueOf(),s)},"...":function(f){if(Ts(f))throw new TypeError("Scalar values expected in function min");return u(f)}});function s(l,f){try{return n(l,f)?l:f}catch(p){throw vn(p,"min",f)}}function u(l){var f;if(Wi(l,function(p){try{isNaN(p)&&typeof p=="number"?f=NaN:(f===void 0||n(p,f))&&(f=p)}catch(h){throw vn(h,"min",p)}}),f===void 0)throw new Error("Cannot calculate min of an empty array");return typeof f=="string"&&(f=r(f,e.number)),f}}),uc="add",w_=["typed","matrix","addScalar","equalScalar","DenseMatrix","SparseMatrix","concat"],D_=mt(uc,w_,i=>{var{typed:t,matrix:e,addScalar:r,equalScalar:n,DenseMatrix:s,SparseMatrix:u,concat:l}=i,f=qf({typed:t}),p=av({typed:t,equalScalar:n}),h=Uf({typed:t,DenseMatrix:s}),c=qn({typed:t,matrix:e,concat:l});return t(uc,{"any, any":r,"any, any, ...any":t.referToSelf(m=>(_,w,g)=>{for(var y=m(_,w),v=0;v<g.length;v++)y=m(y,g[v]);return y})},c({elop:r,DS:f,SS:p,Ss:h}))}),lc="dot",y_=["typed","addScalar","multiplyScalar","conj","size"],b_=mt(lc,y_,i=>{var{typed:t,addScalar:e,multiplyScalar:r,conj:n,size:s}=i;return t(lc,{"Array | DenseMatrix, Array | DenseMatrix":l,"SparseMatrix, SparseMatrix":f});function u(h,c){var m=p(h),_=p(c),w,g;if(m.length===1)w=m[0];else if(m.length===2&&m[1]===1)w=m[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+m.join(", ")+")");if(_.length===1)g=_[0];else if(_.length===2&&_[1]===1)g=_[0];else throw new RangeError("Expected a column vector, instead got a matrix of size ("+_.join(", ")+")");if(w!==g)throw new RangeError("Vectors must have equal length ("+w+" != "+g+")");if(w===0)throw new RangeError("Cannot calculate the dot product of empty vectors");return w}function l(h,c){var m=u(h,c),_=fe(h)?h._data:h,w=fe(h)?h._datatype||h.getDataType():void 0,g=fe(c)?c._data:c,y=fe(c)?c._datatype||c.getDataType():void 0,v=p(h).length===2,E=p(c).length===2,b=e,N=r;if(w&&y&&w===y&&typeof w=="string"&&w!=="mixed"){var x=w;b=t.find(e,[x,x]),N=t.find(r,[x,x])}if(!v&&!E){for(var F=N(n(_[0]),g[0]),M=1;M<m;M++)F=b(F,N(n(_[M]),g[M]));return F}if(!v&&E){for(var S=N(n(_[0]),g[0][0]),$=1;$<m;$++)S=b(S,N(n(_[$]),g[$][0]));return S}if(v&&!E){for(var C=N(n(_[0][0]),g[0]),I=1;I<m;I++)C=b(C,N(n(_[I][0]),g[I]));return C}if(v&&E){for(var R=N(n(_[0][0]),g[0][0]),U=1;U<m;U++)R=b(R,N(n(_[U][0]),g[U][0]));return R}}function f(h,c){u(h,c);for(var m=h._index,_=h._values,w=c._index,g=c._values,y=0,v=e,E=r,b=0,N=0;b<m.length&&N<w.length;){var x=m[b],F=w[N];if(x<F){b++;continue}if(x>F){N++;continue}x===F&&(y=v(y,E(_[b],g[N])),b++,N++)}return y}function p(h){return fe(h)?h.size():s(h)}}),E_="trace",A_=["typed","matrix","add"],x_=mt(E_,A_,i=>{var{typed:t,matrix:e,add:r}=i;return t("trace",{Array:function(l){return n(e(l))},SparseMatrix:s,DenseMatrix:n,any:te});function n(u){var l=u._size,f=u._data;switch(l.length){case 1:if(l[0]===1)return te(f[0]);throw new RangeError("Matrix must be square (size: "+se(l)+")");case 2:{var p=l[0],h=l[1];if(p===h){for(var c=0,m=0;m<p;m++)c=r(c,f[m][m]);return c}else throw new RangeError("Matrix must be square (size: "+se(l)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+se(l)+")")}}function s(u){var l=u._values,f=u._index,p=u._ptr,h=u._size,c=h[0],m=h[1];if(c===m){var _=0;if(l.length>0)for(var w=0;w<m;w++)for(var g=p[w],y=p[w+1],v=g;v<y;v++){var E=f[v];if(E===w){_=r(_,l[v]);break}if(E>w)break}return _}throw new RangeError("Matrix must be square (size: "+se(h)+")")}}),fc="det",C_=["typed","matrix","subtractScalar","multiply","divideScalar","isZero","unaryMinus"],F_=mt(fc,C_,i=>{var{typed:t,matrix:e,subtractScalar:r,multiply:n,divideScalar:s,isZero:u,unaryMinus:l}=i;return t(fc,{any:function(h){return te(h)},"Array | Matrix":function(h){var c;switch(fe(h)?c=h.size():Array.isArray(h)?(h=e(h),c=h.size()):c=[],c.length){case 0:return te(h);case 1:if(c[0]===1)return te(h.valueOf()[0]);if(c[0]===0)return 1;throw new RangeError("Matrix must be square (size: "+se(c)+")");case 2:{var m=c[0],_=c[1];if(m===_)return f(h.clone().valueOf(),m);if(_===0)return 1;throw new RangeError("Matrix must be square (size: "+se(c)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+se(c)+")")}}});function f(p,h,c){if(h===1)return te(p[0][0]);if(h===2)return r(n(p[0][0],p[1][1]),n(p[1][0],p[0][1]));for(var m=!1,_=new Array(h).fill(0).map((M,S)=>S),w=0;w<h;w++){var g=_[w];if(u(p[g][w])){var y=void 0;for(y=w+1;y<h;y++)if(!u(p[_[y]][w])){g=_[y],_[y]=_[w],_[w]=g,m=!m;break}if(y===h)return p[g][w]}for(var v=p[g][w],E=w===0?1:p[_[w-1]][w-1],b=w+1;b<h;b++)for(var N=_[b],x=w+1;x<h;x++)p[N][x]=s(r(n(p[N][x],v),n(p[N][w],p[g][x])),E)}var F=p[_[h-1]][h-1];return m?l(F):F}}),cc="inv",M_=["typed","matrix","divideScalar","addScalar","multiply","unaryMinus","det","identity","abs"],N_=mt(cc,M_,i=>{var{typed:t,matrix:e,divideScalar:r,addScalar:n,multiply:s,unaryMinus:u,det:l,identity:f,abs:p}=i;return t(cc,{"Array | Matrix":function(m){var _=fe(m)?m.size():Ae(m);switch(_.length){case 1:if(_[0]===1)return fe(m)?e([r(1,m.valueOf()[0])]):[r(1,m[0])];throw new RangeError("Matrix must be square (size: "+se(_)+")");case 2:{var w=_[0],g=_[1];if(w===g)return fe(m)?e(h(m.valueOf(),w,g),m.storage()):h(m,w,g);throw new RangeError("Matrix must be square (size: "+se(_)+")")}default:throw new RangeError("Matrix must be two dimensional (size: "+se(_)+")")}},any:function(m){return r(1,m)}});function h(c,m,_){var w,g,y,v,E;if(m===1){if(v=c[0][0],v===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(1,v)]]}else if(m===2){var b=l(c);if(b===0)throw Error("Cannot calculate inverse, determinant is zero");return[[r(c[1][1],b),r(u(c[0][1]),b)],[r(u(c[1][0]),b),r(c[0][0],b)]]}else{var N=c.concat();for(w=0;w<m;w++)N[w]=N[w].concat();for(var x=f(m).valueOf(),F=0;F<_;F++){var M=p(N[F][F]),S=F;for(w=F+1;w<m;)p(N[w][F])>M&&(M=p(N[w][F]),S=w),w++;if(M===0)throw Error("Cannot calculate inverse, determinant is zero");w=S,w!==F&&(E=N[F],N[F]=N[w],N[w]=E,E=x[F],x[F]=x[w],x[w]=E);var $=N[F],C=x[F];for(w=0;w<m;w++){var I=N[w],R=x[w];if(w!==F){if(I[F]!==0){for(y=r(u(I[F]),$[F]),g=F;g<_;g++)I[g]=n(I[g],s(y,$[g]));for(g=0;g<_;g++)R[g]=n(R[g],s(y,C[g]))}}else{for(y=$[F],g=F;g<_;g++)I[g]=r(I[g],y);for(g=0;g<_;g++)R[g]=r(R[g],y)}}}return x}}}),hc="pinv",S_=["typed","matrix","inv","deepEqual","equal","dotDivide","dot","ctranspose","divideScalar","multiply","add","Complex"],B_=mt(hc,S_,i=>{var{typed:t,matrix:e,inv:r,deepEqual:n,equal:s,dotDivide:u,dot:l,ctranspose:f,divideScalar:p,multiply:h,add:c,Complex:m}=i;return t(hc,{"Array | Matrix":function(b){var N=fe(b)?b.size():Ae(b);switch(N.length){case 1:return v(b)?f(b):N[0]===1?r(b):u(f(b),l(b,b));case 2:{if(v(b))return f(b);var x=N[0],F=N[1];if(x===F)try{return r(b)}catch(M){if(!(M instanceof Error&&M.message.match(/Cannot calculate inverse, determinant is zero/)))throw M}return fe(b)?e(_(b.valueOf(),x,F),b.storage()):_(b,x,F)}default:throw new RangeError("Matrix must be two dimensional (size: "+se(N)+")")}},any:function(b){return s(b,0)?te(b):p(1,b)}});function _(E,b,N){var{C:x,F}=g(E,b,N),M=h(r(h(f(x),x)),f(x)),S=h(f(F),r(h(F,f(F))));return h(S,M)}function w(E,b,N){for(var x=te(E),F=0,M=0;M<b;M++){if(N<=F)return x;for(var S=M;y(x[S][F]);)if(S++,b===S&&(S=M,F++,N===F))return x;[x[S],x[M]]=[x[M],x[S]];for(var $=x[M][F],C=0;C<N;C++)x[M][C]=u(x[M][C],$);for(var I=0;I<b;I++)if(I!==M){$=x[I][F];for(var R=0;R<N;R++)x[I][R]=c(x[I][R],h(-1,h($,x[M][R])))}F++}return x}function g(E,b,N){var x=w(E,b,N),F=E.map((S,$)=>S.filter((C,I)=>I<b&&!y(l(x[I],x[I])))),M=x.filter((S,$)=>!y(l(x[$],x[$])));return{C:F,F:M}}function y(E){return s(c(E,m(1,1)),c(0,m(1,1)))}function v(E){return n(c(E,m(1,1)),c(h(E,0),m(1,1)))}}),I_="divide",T_=["typed","matrix","multiply","equalScalar","divideScalar","inv"],$_=mt(I_,T_,i=>{var{typed:t,matrix:e,multiply:r,equalScalar:n,divideScalar:s,inv:u}=i,l=ba({typed:t,equalScalar:n}),f=Ea({typed:t});return t("divide",Bl({"Array | Matrix, Array | Matrix":function(h,c){return r(h,u(c))},"DenseMatrix, any":function(h,c){return f(h,c,s,!1)},"SparseMatrix, any":function(h,c){return l(h,c,s,!1)},"Array, any":function(h,c){return f(e(h),c,s,!1).valueOf()},"any, Array | Matrix":function(h,c){return r(h,u(c))}},s.signatures))}),pc="sum",O_=["typed","config","add","numeric"],R_=mt(pc,O_,i=>{var{typed:t,config:e,add:r,numeric:n}=i;return t(pc,{"Array | Matrix":s,"Array | Matrix, number | BigNumber":u,"...":function(f){if(Ts(f))throw new TypeError("Scalar values expected in function sum");return s(f)}});function s(l){var f;return Wi(l,function(p){try{f=f===void 0?p:r(f,p)}catch(h){throw vn(h,"sum",p)}}),f===void 0&&(f=n(0,e.number)),typeof f=="string"&&(f=n(f,e.number)),f}function u(l,f){try{var p=ya(l,f,r);return p}catch(h){throw vn(h,"sum")}}}),dc="median",L_=["typed","add","divide","compare","partitionSelect"],P_=mt(dc,L_,i=>{var{typed:t,add:e,divide:r,compare:n,partitionSelect:s}=i;function u(p){try{p=ha(p.valueOf());var h=p.length;if(h===0)throw new Error("Cannot calculate median of an empty array");if(h%2===0){for(var c=h/2-1,m=s(p,c+1),_=p[c],w=0;w<c;++w)n(p[w],_)>0&&(_=p[w]);return f(_,m)}else{var g=s(p,(h-1)/2);return l(g)}}catch(y){throw vn(y,"median")}}var l=t({"number | BigNumber | Complex | Unit":function(h){return h}}),f=t({"number | BigNumber | Complex | Unit, number | BigNumber | Complex | Unit":function(h,c){return r(e(h,c),2)}});return t(dc,{"Array | Matrix":u,"Array | Matrix, number | BigNumber":function(h,c){throw new Error("median(A, dim) is not yet supported")},"...":function(h){if(Ts(h))throw new TypeError("Scalar values expected in function median");return u(h)}})}),Ys=zm({config:nr}),Aa=Wm({}),xa=Gm({}),Ca=Jm({}),Wr=Qm({Matrix:Ca}),Ft=kd({BigNumber:Ys,Complex:Aa,DenseMatrix:Wr,Fraction:xa}),z_=Bg({typed:Ft}),js=Tg({typed:Ft}),q_=bg({BigNumber:Ys,typed:Ft}),mc=Dv({typed:Ft}),_n=cg({config:nr,typed:Ft}),Zs=rg({typed:Ft}),U_=og({typed:Ft}),Gs=hv({typed:Ft}),gc=wg({typed:Ft}),Fa=dg({Matrix:Ca,equalScalar:_n,typed:Ft}),vc=Og({typed:Ft}),_c=ug({typed:Ft}),Ma=Ng({typed:Ft}),wc=xg({Fraction:xa,typed:Ft}),Dc=ig({typed:Ft}),xe=Fg({DenseMatrix:Wr,Matrix:Ca,SparseMatrix:Fa,typed:Ft}),yc=Uv({isNaN:_c,isNumeric:Dc,typed:Ft}),Yi=Zv({bignumber:q_,fraction:wc,number:gc}),k_=Wv({config:nr,multiplyScalar:Gs,numeric:Yi,typed:Ft}),W_=Tv({isInteger:Zs,matrix:xe,typed:Ft}),bc=Ov({matrix:xe,config:nr,typed:Ft}),Ec=Lv({matrix:xe,typed:Ft}),Un=bv({isInteger:Zs,matrix:xe,typed:Ft}),Y_=Av({prod:k_,size:bc,typed:Ft}),j_=zv({conj:mc,transpose:Ec,typed:Ft}),ji=Kv({numeric:Yi,typed:Ft}),Z_=Vv({DenseMatrix:Wr,concat:Un,divideScalar:ji,equalScalar:_n,matrix:xe,typed:Ft}),Ac=n_({DenseMatrix:Wr,concat:Un,equalScalar:_n,matrix:xe,typed:Ft}),xc=Cv({BigNumber:Ys,DenseMatrix:Wr,SparseMatrix:Fa,config:nr,matrix:xe,typed:Ft}),G_=Mv({matrix:xe,multiplyScalar:Gs,typed:Ft}),K_=o_({DenseMatrix:Wr,concat:Un,config:nr,matrix:xe,typed:Ft}),H_=gv({DenseMatrix:Wr,concat:Un,equalScalar:_n,matrix:xe,subtractScalar:vc,typed:Ft,unaryMinus:Ma}),Zi=D_({DenseMatrix:Wr,SparseMatrix:Fa,addScalar:js,concat:Un,equalScalar:_n,matrix:xe,typed:Ft}),Cc=t_({BigNumber:Ys,DenseMatrix:Wr,Fraction:xa,concat:Un,config:nr,equalScalar:_n,matrix:xe,typed:Ft}),J_=h_({equal:Ac,typed:Ft}),Fc=b_({addScalar:js,conj:mc,multiplyScalar:Gs,size:bc,typed:Ft}),X_=l_({DenseMatrix:Wr,concat:Un,config:nr,matrix:xe,typed:Ft}),Na=__({config:nr,numeric:Yi,smaller:K_,typed:Ft}),ci=dv({addScalar:js,dot:Fc,equalScalar:_n,matrix:xe,multiplyScalar:Gs,typed:Ft}),V_=d_({compare:Cc,isNaN:_c,isNumeric:Dc,typed:Ft}),Q_=R_({add:Zi,config:nr,numeric:Yi,typed:Ft}),t1=x_({add:Zi,matrix:xe,typed:Ft}),Mc=F_({divideScalar:ji,isZero:U_,matrix:xe,multiply:ci,subtractScalar:vc,typed:Ft,unaryMinus:Ma}),e1=g_({config:nr,larger:X_,numeric:Yi,typed:Ft}),Ks=N_({abs:z_,addScalar:js,det:Mc,divideScalar:ji,identity:xc,matrix:xe,multiply:ci,typed:Ft,unaryMinus:Ma}),r1=B_({Complex:Aa,add:Zi,ctranspose:j_,deepEqual:J_,divideScalar:ji,dot:Fc,dotDivide:Z_,equal:Ac,inv:Ks,matrix:xe,multiply:ci,typed:Ft}),n1=Jv({Complex:Aa,config:nr,fraction:wc,identity:xc,inv:Ks,matrix:xe,multiply:ci,number:gc,typed:Ft}),i1=$_({divideScalar:ji,equalScalar:_n,inv:Ks,matrix:xe,multiply:ci,typed:Ft}),Nc=P_({add:Zi,compare:Cc,divide:i1,partitionSelect:V_,typed:Ft});class s1{constructor(t,e,r){Z(this,"_cacheData");Z(this,"_variables");Z(this,"_math");Z(this,"_timeframe");this._cacheData={},this._variables=t,this._math=e,this._timeframe=r}alma({series:t,length:e,offset:r,sigma:n,floor:s},u){if(e===void 0||r===void 0||n===void 0)return;const l=this._cacheDataList(t,e,`alma_${u}`);if(l===void 0)return;let f=r*(e-1);s&&(f=Math.floor(f));const p=e/n;let h=0,c=0;for(let m=0;m<=e-1;m++){const _=Math.exp(-1*Math.pow(m-f,2)/(2*Math.pow(p,2)));h+=_,c+=l[l.length-1-(e-m-1)]*_}return c/h}sma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;let n=0;const s=this._cacheDataList(t,e,`sma_${r}`);if(s===void 0)return;const u=s.slice(-e);return n=Q_(...u)/e,n}rma({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;const n=this._cacheData[`sma_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`sma_${r}`]=n;const{sum:s}=this._cacheData[`rma_${r}`]||{},u=1/e,l=s===void 0?this.sma({source:t,length:e},r):u*t+(1-u)*(s||0);return this._cacheDataHandle(`rma_${r}`,{sum:l}),l}atr({length:t},e){const{high:r,close:n}=this._cacheData[`atr_${e}`]||{},{high:s,close:u,low:l}=this._variables,f=r===void 0?s-l:Math.max(Math.max(s-l,Math.abs(s-n)),Math.abs(l-n));return this._cacheDataHandle(`atr_${e}`,{high:s,close:u}),this.rma({source:f,length:t},e)}barssince({condition:t},e){let{count:r}=this._cacheData[`barssince_${e}`]||{};if(t)r=0;else{if(r===void 0)return;r+=1}return this._cacheDataHandle(`barssince_${e}`,{count:r}),r}stdev({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0)return;const s=this._cacheDataList(t,e,`stdev_${n}`),u=this.sma({source:t,length:e},n);if(s===void 0)return;let l=0;for(let f=0;f<e;f++){const p=this._sum(s[s.length-1-f],-(u||0));l+=p*p}return r||e<=1?Math.sqrt(l/e):Math.sqrt(l/(e-1))}_sum(t,e){let n=t+e;return Math.abs(n)<=1e-10&&(n=0),n}bb({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[];const s=this.sma({source:t,length:e},n),u=this.stdev({source:t,length:e},n);if(s===void 0||u===void 0)return[];const l=r*u;return[s,s+l,s-l]}bbw({series:t,length:e,mult:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.sma({source:t,length:e},n),u=this.stdev({source:t,length:e},n);if(s===void 0||u===void 0)return;const l=r*u;return(s+l-(s-l))/s}cci({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r),s=this.dev({source:t,length:e},r);if(!(n===void 0||s===void 0))return(t-n)/(.015*s)}change({source:t,length:e=1},r){const n=this._cacheData[`change_${r}`]||[];n[this._variables.bar_index]=t,this._cacheData[`change_${r}`]=n;const s=n[n.length-1-e];if(!(t===void 0||isNaN(t)))return s===void 0?s:typeof t=="boolean"?s!==t:t-s}cmo({series:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.change({source:t},r);if(n===void 0)return;const s=this._math.sum({source:n>=0?n:0,length:e},`sm1_${r}`),u=this._math.sum({source:n>=0?0:-n,length:e},`sm2_${r}`);if(!(s===void 0||u===void 0))return 100*(s-u)/(s+u)}cog({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this._cacheDataList(t,e,`cog_${r}`),s=this._math.sum({source:t,length:e},r);if(s===void 0||n===void 0)return;let u=0;for(let l=0;l<e;l++){const f=n[n.length-1-l];u+=f*(l+1)}return-u/s}correlation({source1:t,source2:e,length:r},n){if(t===void 0||isNaN(t)||e===void 0||isNaN(e)||r===void 0)return;const s=this._cacheDataList([t,e],r,`correlation_${n}`),u=this.sma({source:t,length:r},`sma1_${n}`),l=this.sma({source:e,length:r},`sma2_${n}`);if(u===void 0||l===void 0||s===void 0)return;let f=0,p=0,h=0;for(let m=0;m<r;m++){const[_,w]=s[s.length-1-m],g=_-u,y=w-l;f+=g*y,p+=g*g,h+=y*y}return isNaN(p)||isNaN(f)||isNaN(h)?void 0:f/Math.sqrt(p*h)}cross({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`cross_${r}`]||{};return this._cacheDataHandle(`cross_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e||n<=s&&t>e}crossover({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossover_${r}`]||{};return this._cacheDataHandle(`crossover_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n<=s&&t>e}crossunder({source1:t,source2:e},r){if(t===void 0||e===void 0)return!1;const{source1:n,source2:s}=this._cacheData[`crossunder_${r}`]||{};return this._cacheDataHandle(`crossunder_${r}`,{source1:t,source2:e}),n===void 0||s===void 0?!1:n>=s&&t<e}cum({source:t=0},e){t=isNaN(t)?0:t;let{sum:r}=this._cacheData[`cum_${e}`]||{};return r=r||0,r+=t,this._cacheDataHandle(`cum_${e}`,{sum:r}),r}dev({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return;const n=this.sma({source:t,length:e},r);let s=0;const u=this._cacheDataList(t,e,`dev_${r}`);if(!(!u||n===void 0)){for(let l=0;l<e;l++){const f=u[u.length-1-l];s+=Math.abs(f-n)}return s/e}}dmi({diLength:t,adxSmoothing:e},r){if(t===void 0||e===void 0)return[void 0,void 0,void 0];const n=`dmi_${r}`,{low:s,high:u,close:l,PDMS:f,NDMS:p,TRS:h,ADX:c,count:m=0}=this._cacheData[n]||{},{low:_,high:w,close:g}=this._variables;if(s===void 0||u===void 0||l===void 0)return this._cacheData[n]={low:_,high:w,close:g,PDMS:f,NDMS:p,TRS:w-_,count:1},[void 0,void 0,void 0];let y=w-u,v=s-_;y=y>v&&y>0?y:0,v=v>y&&v>0?v:0,y===v&&(y=v=0);const E=Math.max(w-_,Math.abs(w-l),Math.abs(_-l));if(m<t)return this._cacheDataHandle(n,{low:_,high:w,close:g,PDMS:(f||0)+y,NDMS:(p||0)+v,TRS:(h||0)+E,count:m+1}),[void 0,void 0,void 0];{const b=f-f/t+y,N=p-p/t+v,x=h-h/t+E,F=b/x*100,M=N/x*100,S=Math.abs((F-M)/(F+M))*100;let $=S,C=[F,M,void 0];if(m+1-t<e){const I=m+1-t;$=((c||0)*(I-1)+S)/I}else $=(c*(e-1)+S)/e,C=[F,M,$];return this._cacheDataHandle(n,{low:_,high:w,close:g,PDMS:b,NDMS:N,TRS:x,ADX:$,count:m+1}),C}}ema({source:t,length:e},r){if(t===void 0||e===void 0||isNaN(t))return;let{sum:n,count:s=1}=this._cacheData[`ema_${r}`]||{};const u=this.sma({source:t,length:e},r);if(s>e){const l=2/(e+1);n=n===void 0?t:l*t+(1-l)*(n||0)}else n=u;return s+=1,this._cacheDataHandle(`ema_${r}`,{sum:n,count:s}),n}falling({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,fallings:s=[]}=this._cacheData[`falling_${r}`]||{};s.push(n>t);const u=s.slice(-e);return this._cacheDataHandle(`falling_${r}`,{source:t,fallings:u}),u.length<e?!1:u.every(l=>l)}rising({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0)return!1;const{source:n,risings:s=[]}=this._cacheData[`rising_${r}`]||{};s.push(n<t);const u=s.slice(-e);return this._cacheDataHandle(`rising_${r}`,{source:t,risings:u}),u.length<e?!1:u.every(l=>l)}highest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highest_${r}`]||[],{high:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`highest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.max(...l.slice(-e))}highestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`highestbars_${r}`]||[],{high:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`highestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((p,h,c,m)=>h>=m[p]?c:p,0)-e+1}wma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`wma_${r}`);if(!n)return;let s=0,u=0;for(let l=0;l<e;l++){const f=(e-l)*e;s+=f,u+=n[n.length-1-l]*f}return u/s}hma({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this.wma({source:t,length:e},r),s=this.wma({source:t,length:Math.round(e/2)},r);return n===void 0||s===void 0?void 0:this.wma({source:2*s-n,length:Math.floor(Math.sqrt(e))},`hma_${r}`)}kc({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return[void 0,void 0,void 0];const u=this.ema({source:t,length:e},s),{ta:l,high:f,low:p}=this._variables,h=n?l.tr:f-p,c=this.ema({source:h,length:e},`range_${s}`);return[u,u+c*r,u-c*r]}kcw({series:t,length:e,mult:r,useTrueRange:n=!0},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const u=this.ema({source:t,length:e},s),{ta:l,high:f,low:p}=this._variables,h=n?l.tr:f-p,c=this.ema({source:h,length:e},`range_${s}`);return(u+c*r-(u-c*r))/u}linreg({source:t,length:e,offset:r},n){if(e===void 0||r===void 0)return;const s=this._cacheDataList(t,e,`dev_${n}`);if(!s)return;const u=s.slice(-e).filter(_=>_!==void 0);let l=0,f=0,p=0,h=0;for(const[_,w]of u.entries())l+=_,f+=w,p+=_*w,h+=_*_;const c=(e*p-l*f)/(e*h-l*l);return(f-c*l)/e+c*(e-1-r)}lowest({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowest_${r}`]||[],{low:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`lowest_${r}`]=n;const l=n.filter(()=>!0);if(!(l.length<e))return Math.min(...l.slice(-e))}lowestbars({source:t,length:e},r){if(e===void 0||e<=0)return;const n=this._cacheData[`lowestbars_${r}`]||[],{low:s,bar_index:u}=this._variables;typeof t!="number"?n[u]=s:n[u]=t,this._cacheData[`lowestbars_${r}`]=n;const l=n.filter(()=>!0);return l.length<e?void 0:l.slice(-e).reduce((p,h,c,m)=>h<=m[p]?c:p,0)-e+1}macd({source:t,fastlen:e,slowlen:r,siglen:n},s){if(t===void 0||isNaN(t)||e===void 0||r===void 0||n===void 0)return[void 0,void 0,void 0];const u=this.ema({source:t,length:e},`ema1_${s}`),l=this.ema({source:t,length:r},`ema2_${s}`);if(u===void 0||l===void 0)return[void 0,void 0,void 0];const f=u-l,p=this.ema({source:f,length:n},`macd_${s}`);if(p===void 0)return[f,p,void 0];const h=f-p;return[f,p,h]}max({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`max_${e}`]||0;return t>r&&(r=t),this._cacheData[`max_${e}`]=r,r}min({source:t},e){if(t===void 0||isNaN(t))return;let r=this._cacheData[`min_${e}`]||1/0;return t<r&&(r=t),this._cacheData[`min_${e}`]=r,r}median({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`dev_${r}`);if(n)return Nc(n.slice(-e))}mfi({series:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const{volume:n}=this._variables,s=this.change({source:t},r),u=this._math.sum({source:n*(s>=0?0:t),length:e},`lower_${r}`),l=this._math.sum({source:n*(s<=0?0:t),length:e},`upper_${r}`);if(!(l===void 0||u===void 0))return 100-100/(1+l/u)}mode({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<=0)return;const n=this._cacheDataList(t,e,`mode_${r}`);if(n)return Na(yc(n.slice(-e)))}mom({source:t,length:e},r){if(e===void 0||e<0)return;const n=`mom_${r}`,s=this._cacheData[n]||[];if(s[this._variables.bar_index]=t,this._cacheData[n]=s,s.length<=e||t===void 0||isNaN(t))return;let u=s.length-e-1,l;for(;l===void 0&&u>=0;)l=s[u],u--;return l===void 0?l:t-l}percentile_linear_interpolation({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e+1,`percentile_linear_interpolation_${n}`);if(!s)return;const u=this._sort(s.slice(-(e+1))),l=u.length;r/=100;const f=1/(l*2);if(r<=f)return u[0];if(r>=1-1/(l*2))return u[l-1];for(const[p,h]of u.entries()){const c=u[p-1];if(r<(p+.5)/l)return c===void 0||h===void 0?void 0:c+(h-c)*(r-(p-.5)/l)/(1/l)}}percentile_nearest_rank({source:t,length:e,percentage:r},n){if(e===void 0||r===void 0||t===void 0||isNaN(t)||e<0||r<0||r>100)return;const s=this._cacheDataList(t,e,`percentile_nearest_rank_${n}`);if(!s)return;const u=this._sort(s.slice(-e)),l=r/100*u.length,f=Math.ceil(l)-1;return u[f>=u.length?u.length-1:f]}percentrank({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`percentile_nearest_rank_${r}`);if(!n)return;const s=n.slice(-(e+1)),u=t;if(u===void 0)return;let l=0;for(let f=0;f<s.length;f++)s[f]!==void 0&&(s[f]<u||s[f]===u&&f<e)&&l++;return l/(s.length-1)*100}pivot_point_levels({type:t,anchor:e,developing:r},n){const s=new Jt;let{close:u,open:l,low:f,high:p}=this._variables;const h=`pivot_point_levels_${n}`,{close:c,low:m,high:_,open:w,result:g}=this._cacheData[h]||{};if(!e&&(_&&m&&(p=Math.max(_,p),f=Math.min(m,f)),this._cacheDataHandle(h,{close:u,open:l,low:f,high:p,result:g}),!r))return s._value=g||[],s;const y={close:u,open:l,low:f,high:p};e===!0&&!r&&(u=c,l=w,f=m,p=_);const v=this._getPivotPointLevels(p,f,u,l,r,t);return this._cacheDataHandle(h,{...y,result:v}),s._value=v,s}_getPivotPointLevels(t,e,r,n,s,u){if(r===void 0||n===void 0||e===void 0||t===void 0)return[];switch(u){case Pn.traditional:return this._traditional(t,e,r);case Pn.fibonacci:return this._fibonacci(t,e,r);case Pn.woodie:return s?[]:this._woodie(t,e);case Pn.classic:return this._classic(t,e,r);case Pn.dm:return this._DM(t,e,r,n);case Pn.camarilla:return this._camarilla(t,e,r);default:return[]}}_traditional(t,e,r){const n=(t+e+r)/3,s=n*2-e,u=n+(t-e),l=n*2+(t-2*e),f=n*3+(t-3*e),p=n*4+(t-4*e),h=n*2-t,c=n-(t-e),m=n*2-(2*t-e),_=n*3-(3*t-e),w=n*4-(4*t-e);return[n,s,h,u,c,l,m,f,_,p,w]}_fibonacci(t,e,r){const n=(t+e+r)/3,s=n+.382*(t-e),u=n-.382*(t-e),l=n+.618*(t-e),f=n-.618*(t-e),p=n+(t-e),h=n-(t-e);return[n,s,u,l,f,p,h]}_woodie(t,e){const{open:r}=this._variables,n=(t+e+2*r)/4,s=2*n-e,u=2*n-t,l=n+(t-e),f=n-(t-e),p=t+2*(n-e),h=e-2*(t-n),c=p+(t-e),m=h-(t-e);return[n,s,u,l,f,p,h,c,m]}_classic(t,e,r){const n=(t+e+r)/3,s=2*n-e,u=2*n-t,l=n+(t-e),f=n-(t-e),p=n+2*(t-e),h=n-2*(t-e),c=n+3*(t-e),m=n-3*(t-e);return[n,s,u,l,f,p,h,c,m]}_DM(t,e,r,n){let s;n===r?s=t+e+2*r:r>n?s=2*t+e+r:s=2*e+t+r;const u=s/4,l=s/2-e,f=s/2-t;return[u,l,f]}_camarilla(t,e,r){const n=(t+e+r)/3,s=r+1.1*(t-e)/12,u=r-1.1*(t-e)/12,l=r+1.1*(t-e)/6,f=r-1.1*(t-e)/6,p=r+1.1*(t-e)/4,h=r-1.1*(t-e)/4,c=r+1.1*(t-e)/2,m=r-1.1*(t-e)/2,_=t/e*r,w=r-(_-r);return[n,s,u,l,f,p,h,c,m,_,w]}pivothigh({source:t=this._variables.high,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivothigh_${n}`);if(!s)return;const u=s.slice(-(e+r+1)),l=u[e];return Math.max(...u)===l?l:void 0}pivotlow({source:t=this._variables.low,leftbars:e,rightbars:r},n){if(e===void 0||r===void 0||e<0||r<0)return;const s=this._cacheDataList(t,e+r+1,`pivotlow_${n}`);if(!s)return;const u=s.slice(-(e+r+1)),l=u[e];return Math.min(...u)===l?l:void 0}range({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const n=this._cacheDataList(t,e,`range_${r}`);if(!n)return;const s=n.filter(f=>f!==void 0).slice(-e),u=Math.max(...s),l=Math.min(...s);return u-l}roc({source:t,length:e},r){if(e===void 0||e<0)return;const n=this._cacheDataList(t,e+1,`roc_${r}`),s=this.change({source:t,length:e},r);if(n)return 100*s/n[n.length-1-e]}rsi({source:t,length:e},r){if(e===void 0||t===void 0||isNaN(t)||e<0)return;const{source:n}=this._cacheData[`rsi_${r}`]||{},s=Math.max(t-n,0),u=Math.max(n-t,0),l=this.rma({source:s,length:e},`rma1_${r}`),f=this.rma({source:u,length:e},`rma2_${r}`);if(this._cacheDataHandle(`rsi_${r}`,{source:t}),!(l===void 0||f===void 0))return 100-100/(1+l/f)}sar({start:t,inc:e,max:r},n){if(t===void 0||e===void 0||r===void 0)return;const{close:s,low:u,high:l,preLow:f,preHigh:p,data:h={}}=this._cacheData[`sar_${n}`]||{};let{result:c,maxMin:m,acceleration:_,isBelow:w}=h,g=!1;const{close:y,low:v,high:E,bar_index:b}=this._variables;return b===1&&(y>s?(w=!0,m=E,c=u):(w=!1,m=v,c=l),g=!0,_=t),c=c+_*(m-c),w?c>v&&(g=!0,w=!1,c=Math.max(E,m||0),m=v,_=t):c<E&&(g=!0,w=!0,c=Math.min(v,m||0),m=E,_=t),g||(w?E>(m||0)&&(m=E,_=Math.min((_||0)+e,r)):v<(m||0)&&(m=v,_=Math.min((_||0)+e,r))),w?(c=Math.min(c,u),b>1&&(c=Math.min(c,f))):(c=Math.max(c,l),b>1&&(c=Math.max(c,p))),this._cacheDataHandle(`sar_${n}`,{high:E,close:y,low:v,preLow:u,preHigh:l,data:Object.assign(h,{result:c,maxMin:m,acceleration:_,isBelow:w})}),c}stoch({source:t,high:e,low:r,length:n},s){if(n===void 0||e===void 0||r===void 0||t===void 0||isNaN(t)||n<0)return;const u=this.lowest({source:r,length:n},s),l=this.highest({source:e,length:n},s);if(!(u===void 0||l===void 0))return 100*(this._variables.close-u)/(l-u)}supertrend({factor:t,atrPeriod:e},r){if(t===void 0||e===void 0)return[void 0,void 0];const{hl2:n,close:s}=this._variables,u=`supertrend_${r}`,{upperBand:l,lowerBand:f,superTrend:p,atr:h,close:c}=this._cacheData[u]||{},m=this.atr({length:e},r);if(m===void 0)return this._cacheDataHandle(u,{close:s}),[void 0,void 0];let _=n+t*m,w=n-t*m;const g=l||0,y=f||0;w=w>y||c<y?w:y,_=_<g||c>g?_:g;let v;h===void 0?v=1:p===g?v=s>_?-1:1:v=s<w?1:-1;const E=v===-1?w:_;return this._cacheDataHandle(u,{upperBand:_,lowerBand:w,superTrend:E,atr:m,close:s}),[E,v]}swma({source:t},e){let{list:r}=this._cacheData[`swma_${e}`]||{};if(r||(r=[]),r.push(t),r=r.slice(-4),this._cacheDataHandle(`swma_${e}`,{list:r}),!(r.filter(n=>n!==void 0).length<4))return r[3]*1/6+r[2]*2/6+r[1]*2/6+r[0]*1/6}tr({handle_na:t=!1},e){const{close:r,low:n,high:s}=this._variables,{close:u}=this._cacheData[`tr_${e}`]||{};return this._cacheDataHandle(`tr_${e}`,{close:r}),u===void 0?t?s-n:void 0:Math.max(s-n,Math.abs(s-u),Math.abs(n-u))}tsi({source:t,short_length:e,long_length:r},n){if(t===void 0||isNaN(t)||e===void 0||r===void 0)return;const s=this.change({source:t},n);if(s===void 0)return;const u=this.ema({source:Math.abs(s),length:e},`absema1_${n}`),l=this.ema({source:s,length:e},`ema1_${n}`);if(l===void 0)return;const f=this.ema({source:l,length:r},`ema2_${n}`),p=this.ema({source:u,length:e},`absema2_${n}`);if(f!==void 0)return f/p}valuewhen({condition:t,source:e,occurrence:r},n){if(e===void 0||r===void 0||r<0)return;let{list:s}=this._cacheData[`valuewhen_${n}`]||{};return s||(s=[]),t&&s.push(e),this._cacheDataHandle(`valuewhen_${n}`,{list:s}),s[s.length-1-r]}variance({source:t,length:e,biased:r=!0},n){if(t===void 0||isNaN(t)||e===void 0||e<0)return;const s=this.sma({source:t,length:e},n),u=this._cacheDataList(t,e,`mode_${n}`);if(!u||s===void 0)return;const l=u.filter(p=>p!==void 0&&!isNaN(p)).slice(-e);if(l.length<e)return;const f=l.reduce((p,h)=>p+Math.pow(h-s,2),0);if(f!==void 0)return r||e<=1?f/e:f/(e-1)}vwap({source:t,anchor:e,stdev_mult:r},n){if(t===void 0)return;e=e===void 0?this._timeframe.change({timeframe:"1D"},n):e;const{volume:s}=this._variables;let{sum:u=0,sumV:l=0,count:f=0,isReset:p,sumS:h=0}=this._cacheData[`vwap_${n}`]||{};if(e&&(u=l=f=h=0,p=!0),!p)return r!==void 0?[]:void 0;const c=t*s+u,m=s+l,_=c/m;return f++,r!==void 0?(h=s*Math.pow(t,2)+h,this._cacheDataHandle(`vwap_${n}`,{sum:c,sumV:m,count:f,isReset:p,sumS:h}),this._computeBands(h,m,r,_)):(this._cacheDataHandle(`vwap_${n}`,{sum:c,sumV:m,count:f,isReset:p}),_)}_computeBands(t,e,r,n){let s=t/e-Math.pow(n,2);s=s<0?0:s;const u=Math.sqrt(s),l=u!==void 0&&!isNaN(u)?n+r*u:void 0,f=u!==void 0&&!isNaN(u)?n-r*u:void 0;return[n,l,f]}vwma({source:t,length:e},r){if(t===void 0||isNaN(t)||e===void 0||e<=0)return;const{volume:n}=this._variables,s=this.sma({source:t*n,length:e},`sma1_${r}`),u=this.sma({source:n,length:e},`sma2_${r}`);if(!(s===void 0||u===void 0))return s/u}wpr({length:t},e){if(t===void 0||t<=0)return;const r=this.highest({length:t},e),n=this.lowest({length:t},e),{close:s}=this._variables;if(!(r===void 0||n===void 0))return(r-s)/(r-n)*-100}_sort(t){const e=t.length;for(let r=0;r<e;r++){let n={};for(let s=0;s<e-r;s++){const{currentVal:u,currentIndex:l}=n,f=t[s];if(f!==void 0){if(u!==void 0&&f<u){t.splice(s,1),t.splice(l,0,f),n={currentIndex:l+1,currentVal:u};continue}n={currentIndex:s,currentVal:f}}}}return t}_cacheDataList(t,e,r){const n=this._cacheData[r]||[];n[this._variables.bar_index]=t,this._cacheData[r]=n;const s=n.filter(()=>!0);if(!(s.length<e))return s}_cacheDataHandle(t,e){const{barIndex:r}=this._cacheData[t]||{};r!==this._variables.bar_index&&(this._cacheData[t]=Object.assign(e,{barIndex:this._variables.bar_index}))}}const o1={onlyInLoop:"'$text' is only allowed inside loops",invalidType:"Invalid argument 'expr$index' in 'operator SQBR' call",typeUseError:"Cannot specify a type form '$text' without also specifying the type.",notTypeKeyword:"'$text' is not a valid type keyword in variable declaration",undeclared:"Undeclared identifier '$name'",repeatVar:"'$name' is already defined",typeMismatch:"Cannot call '$operator' with argument '$index'. An argument of '$typeE' type was used but a '$typeR' is expected.",assignTypeMismatch:"Cannot assign a value of the `$typeE` type to the '$name' variable. The variable is declared with the `$typeR` type.",voidNotVar:"Void expression cannot be assigned to a variable",declareTypeErr:"Declared type '$type' is not compatible with assigned type '$valueType'",mapKeyValErr:"Cannot put <$typeA, $typeB> pairs into a map containing `$typeC` keys and `$typeD` values. The maps passed into the `$name()` function must have the same key types and value types.",inputSourceErr:"Invalid value for the '$name' parameter of the '$funcName' function. Possible values: [open, high, low, close, hl2, hlc3, ohlc4, hlcc4, volume].",buildInUseErr:"Cannot use '$name' as the default value of a type's field. The default value cannot be a function, variable or calculation.",argsLenErr:"Too many arguments passed into the `$name()` function call. Passed $lenA arguments but expected $lenB.",requiredParamErr:"No value assigned to the `$argName` parameter in $name()",argsSyntaxErr:"Syntax error after the argument for `$argName`. Arguments without their parameter name cannot be used after arguments with parameter names.",requestArgsErr:"Type $type cannot be used in $name '$argName' argument",mapKeyErr:"Incorrect `key` type `$type` in the variable. The `key` type must be one of the following: int, float, string, bool, color.",templateErr:"Incorrect number of arguments for the template: $countA expected, $countB passed.",templateNoSupportErr:"The '$name()' function does not support templates",ifOrSwitchTypeErr:"Return type of one of the '$keyword' blocks is not compatible with return type of other block(s) ($types)",argsNameErr:"The '$name' function does not have an argument with the name '$argName'",noFiledErr:"Object has no field $name",methodNotExistErr:"Could not find method or method reference '$methodName' for '$name'",tupleVarErr:"Syntax error: The quantities of tuple elements on each side of the assignment operator do not match. The right side has $indexA but the left side has $indexB.",tupleLeftVarErr:"Invalid assignment. Cannot assign a tuple to a variable '$name'.",tupleRightVarErr:"Cannot assign a variable to a tuple. The right side must be a function call or structure ('if', 'switch', 'for', 'while') returning a tuple with the same number of elements.",tempateTypeErr:"Syntax error: Only templates for arrays and matrices consist of a single type identifier enclosed in angle brackets.",qualifierErr:"'$name' is not a valid type qualifier. Possible values: 'const', 'simple', 'series'",notFindFuncErr:"Could not find function or function reference '$name'",naVarErr:"Value with NA type cannot be assigned to a variable that was defined without type keyword",notHistoryErr:"Variable '$name' doesn't have history values",defaultValueErr:"The default value cannot be a function, variable or calculation.",defaultValueTypeErr:"Default value of type $typeE can not be assigned to an argument of type $typeR",unaryErr:"Syntax error at input '$sign'",funcArgAssignErr:"Function arguments cannot be mutable ('$name')",declaredErr:"A variable declared with the '$prefix' keyword cannot accept values of the '$type' form. Assign a '$prefix' value to this variable or remove the '$prefix' keyword from its declaration.",globalFuncErr:"Cannot use '$name' in local scope",onlyStatementErr:"Scripts must contain one declaration statement: `indicator()`, `strategy()` or `library()`, Your script has $count.",modifyGlobalVarErr:"Cannot modify global variable '$name' in function",inputDefvalErr:"Arguments of input function must be of constant type, or 'source' builtin variables.",objectIsNaErr:"Cannot access the '$name' $type of an undefined object. The object is 'na'."};Pr.SERIES,Pr.SIMPLE,Pr.INPUT,Pr.CONST,Pr.INT,Pr.FLOAT,Pr.BOOL,Pr.COLOR,Pr.STRING;const a1=["close","open","high","low","hl2","hlc3","hlcc4","ohlc4","volume"];var hi=(i=>(i[i.Hint=1]="Hint",i[i.Info=2]="Info",i[i.Warning=4]="Warning",i[i.Error=8]="Error",i))(hi||{});class u1{constructor(t,e){Z(this,"_cacheData");Z(this,"_variables");Z(this,"_errorListener");Z(this,"_count");Z(this,"_historyInputs");Z(this,"_name");this._cacheData={},this._variables=t,this._errorListener=e,this._count=-1,this._name=`inputs_${Tp()}`,this._historyInputs=self.workerStorage.get(this._name)||{}}update(t){for(const e of t){const r=e.id;if(!this._cacheData[r])return;Object.assign(this._cacheData[r],{...e,isModify:!0}),self.workerStorage.updateValue(this._name,`in_${e.index}`,{modifyDefval:e.sourceTypeName||e.defval})}}input(t,e){return this._cacheHandle(t,e)}int(t,e){return this._cacheHandle(t,e,"int")}bool(t,e){return this._cacheHandle(t,e,"bool")}color(t,e){return this._cacheHandle(t,e,"color")}time(t,e){return this._cacheHandle(t,e,"time")}float(t,e){return this._cacheHandle(t,e,"float")}price(t,e){return this._cacheHandle(t,e,"price")}source(t,e){return this._cacheHandle(t,e,"source")}string(t,e){return this._cacheHandle(t,e,"string")}symbol(t,e){return this._cacheHandle(t,e,"symbol")}session(t,e){return this._cacheHandle(t,e,"session")}text_area(t,e){return this._cacheHandle(t,e,"text_area")}timeframe(t,e){return this._cacheHandle(t,e,"timeframe")}_cacheHandle(t,e,r){const n=`${r||"input"}_${e}`,s=this._cacheData[n];if(t.defval===void 0&&this._errorListener.addError(o1.inputDefvalErr,e,hi.Error),s)s.isModify?s.sourceTypeName&&(this._cacheData[n].defval=this._variables[s.sourceTypeName]):Object.assign(this._cacheData[n],t);else{const{defval:u,display:l}=t;this._displayVerify(e,l),this._count++,t={inputType:r,...t,index:this._count},this._cacheData[n]=t,this._judgeHistoryInputs(t),(r||t.inputType)==="source"?this._cacheData[n].options=a1:t.options&&!t.options.includes(u)&&this._errorListener.addError(`input's defval should be in options, but '${u}' is not in [${t.options.toString()}]`,e,hi.Error)}return this._cacheData[n].defval}_judgeHistoryInputs(t){const{defval:e,sourceTypeName:r,index:n}=t;let s=r||e;const u=`in_${n}`,l=this._historyInputs[u];if(!l)self.workerStorage.setValue(this._name,u,{defval:s});else{const{defval:f,modifyDefval:p}=l;f===s?s=p||s:self.workerStorage.setValue(this._name,u,{defval:s})}r?t.sourceTypeName=s:t.defval=s}_displayVerify(t,e){!e||!e.length||e.includes(er.dataWindow)||e.includes(er.statusLine)||this._errorListener.addError("Invalid argument 'display' in 'input' call. Possible values: [display.none, display.data_window, display.status_line, display.all]",t,hi.Error)}getInputs(){var n;const t=Object.keys(this._cacheData),e=new Map,r=[];for(const s of t){const u=this._cacheData[s];u.id=s;const{group:l}=u;l?e.has(l)?(n=e.get(l))==null||n.push(u):e.set(l,[u]):r.push(u)}return[...this._getGroups(e),{inputs:r}]}_getGroups(t){const e=[];for(const[r,n]of t)e.push({name:r,inputs:n});return e}}class l1{color({x:t}){return t}new({color:t,transp:e=100}){const{r,g:n,b:s}=this._parseColor(t);return`rgba(${Math.round(r)}, ${Math.round(n)}, ${Math.round(s)}, ${e/100})`}rgb({red:t,green:e,blue:r,transp:n=0}){return`rgba(${t}, ${e}, ${r}, ${n/100})`}g({color:t}){return t?this._parseColor(t).g:0}r({color:t}){return t?this._parseColor(t).r:0}b({color:t}){return t?this._parseColor(t).b:0}t({color:t}){return t?Math.round(this._parseColor(t).a*100):0}from_gradient({value:t,bottom_value:e,top_value:r,bottom_color:n,top_color:s}){const u=(t-e)/(r-e),l=Math.min(Math.max(u,0),1),{r:f,g:p,b:h,a:c}=this._parseColor(n),{r:m,g:_,b:w,a:g}=this._parseColor(s),y=f+l*(m-f),v=p+l*(_-p),E=h+l*(w-h),b=c+l*(g-c);return`rgba(${Math.round(y)}, ${Math.round(v)}, ${Math.round(E)}, ${b.toFixed(2)})`}_parseColor(t){let e,r,n,s;if(t.startsWith("#")){e=parseInt(t.substring(1,3),16),r=parseInt(t.substring(3,5),16),n=parseInt(t.substring(5,7),16);const u=t.substring(7);u?s=(255-parseInt(u,16))/255:s=1}else{const u=this._parserRgbColor(t);e=u[0],r=u[1],n=u[2],s=u[3]||1}return{r:e,g:r,b:n,a:s}}_parserRgbColor(t){var e;return((e=t.match(/\d+/g))==null?void 0:e.map(Number))||[]}}var Pt={};const f1=Object.prototype.toString;function Gi(i){const t=f1.call(i);return t.endsWith("Array]")&&!t.includes("Big")}var c1=Object.freeze({__proto__:null,isAnyArray:Gi}),h1=De(c1);function p1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Gi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var u=i[r],l=r+1;l<s;l++)i[l]>u&&(u=i[l]);return u}function d1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!Gi(i))throw new TypeError("input must be an array");if(i.length===0)throw new TypeError("input must not be empty");var e=t.fromIndex,r=e===void 0?0:e,n=t.toIndex,s=n===void 0?i.length:n;if(r<0||r>=i.length||!Number.isInteger(r))throw new Error("fromIndex must be a positive integer smaller than length");if(s<=r||s>i.length||!Number.isInteger(s))throw new Error("toIndex must be an integer greater than fromIndex and at most equal to length");for(var u=i[r],l=r+1;l<s;l++)i[l]<u&&(u=i[l]);return u}function m1(i){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(Gi(i)){if(i.length===0)throw new TypeError("input must not be empty")}else throw new TypeError("input must be an array");var e;if(t.output!==void 0){if(!Gi(t.output))throw new TypeError("output option must be an array if specified");e=t.output}else e=new Array(i.length);var r=d1(i),n=p1(i);if(r===n)throw new RangeError("minimum and maximum input values are equal. Cannot rescale a constant array");var s=t.min,u=s===void 0?t.autoMinMax?r:0:s,l=t.max,f=l===void 0?t.autoMinMax?n:1:l;if(u>=f)throw new RangeError("min option must be smaller than max option");for(var p=(f-u)/(n-r),h=0;h<i.length;h++)e[h]=(i[h]-r)*p+u;return e}var g1=Object.freeze({__proto__:null,default:m1}),v1=De(g1);Object.defineProperty(Pt,"__esModule",{value:!0});var Je=h1,Sc=v1;const Hs=" ".repeat(2),Bc=" ".repeat(4);function _1(){return Ic(this)}function Ic(i,t={}){const{maxRows:e=15,maxColumns:r=10,maxNumSize:n=8,padMinus:s="auto"}=t;return`${i.constructor.name} {
55
55
  ${Hs}[
56
56
  ${Bc}${w1(i,e,r,n,s)}
57
57
  ${Hs}]
58
58
  ${Hs}rows: ${i.rows}
59
59
  ${Hs}columns: ${i.columns}
60
60
  }`}function w1(i,t,e,r,n){const{rows:s,columns:u}=i,l=Math.min(s,t),f=Math.min(u,e),p=[];if(n==="auto"){n=!1;t:for(let h=0;h<l;h++)for(let c=0;c<f;c++)if(i.get(h,c)<0){n=!0;break t}}for(let h=0;h<l;h++){let c=[];for(let m=0;m<f;m++)c.push(D1(i.get(h,m),r,n));p.push(`${c.join(" ")}`)}return f!==u&&(p[p.length-1]+=` ... ${u-e} more columns`),l!==s&&p.push(`... ${s-t} more rows`),p.join(`
61
- ${Bc}`)}function D1(i,t,e){return(i>=0&&e?` ${Tc(i,t-1)}`:Tc(i,t)).padEnd(t)}function Tc(i,t){let e=i.toString();if(e.length<=t)return e;let r=i.toFixed(t);if(r.length>t&&(r=i.toFixed(Math.max(0,t-(r.length-t)))),r.length<=t&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=i.toExponential(t);return n.length>t&&(n=i.toExponential(Math.max(0,t-(n.length-t)))),n.slice(0)}function y1(i,t){i.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},i.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r);return this},i.prototype.addM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r.get(n,s));return this},i.add=function(r,n){return new t(r).add(n)},i.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},i.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r);return this},i.prototype.subM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r.get(n,s));return this},i.sub=function(r,n){return new t(r).sub(n)},i.prototype.subtract=i.prototype.sub,i.prototype.subtractS=i.prototype.subS,i.prototype.subtractM=i.prototype.subM,i.subtract=i.sub,i.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},i.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r);return this},i.prototype.mulM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r.get(n,s));return this},i.mul=function(r,n){return new t(r).mul(n)},i.prototype.multiply=i.prototype.mul,i.prototype.multiplyS=i.prototype.mulS,i.prototype.multiplyM=i.prototype.mulM,i.multiply=i.mul,i.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},i.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r);return this},i.prototype.divM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r.get(n,s));return this},i.div=function(r,n){return new t(r).div(n)},i.prototype.divide=i.prototype.div,i.prototype.divideS=i.prototype.divS,i.prototype.divideM=i.prototype.divM,i.divide=i.div,i.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},i.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r);return this},i.prototype.modM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r.get(n,s));return this},i.mod=function(r,n){return new t(r).mod(n)},i.prototype.modulus=i.prototype.mod,i.prototype.modulusS=i.prototype.modS,i.prototype.modulusM=i.prototype.modM,i.modulus=i.mod,i.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},i.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r);return this},i.prototype.andM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r.get(n,s));return this},i.and=function(r,n){return new t(r).and(n)},i.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},i.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r);return this},i.prototype.orM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r.get(n,s));return this},i.or=function(r,n){return new t(r).or(n)},i.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},i.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r);return this},i.prototype.xorM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r.get(n,s));return this},i.xor=function(r,n){return new t(r).xor(n)},i.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},i.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r);return this},i.prototype.leftShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r.get(n,s));return this},i.leftShift=function(r,n){return new t(r).leftShift(n)},i.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},i.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r);return this},i.prototype.signPropagatingRightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r.get(n,s));return this},i.signPropagatingRightShift=function(r,n){return new t(r).signPropagatingRightShift(n)},i.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},i.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r);return this},i.prototype.rightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r.get(n,s));return this},i.rightShift=function(r,n){return new t(r).rightShift(n)},i.prototype.zeroFillRightShift=i.prototype.rightShift,i.prototype.zeroFillRightShiftS=i.prototype.rightShiftS,i.prototype.zeroFillRightShiftM=i.prototype.rightShiftM,i.zeroFillRightShift=i.rightShift,i.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,~this.get(r,n));return this},i.not=function(r){return new t(r).not()},i.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.abs(this.get(r,n)));return this},i.abs=function(r){return new t(r).abs()},i.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acos(this.get(r,n)));return this},i.acos=function(r){return new t(r).acos()},i.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acosh(this.get(r,n)));return this},i.acosh=function(r){return new t(r).acosh()},i.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asin(this.get(r,n)));return this},i.asin=function(r){return new t(r).asin()},i.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asinh(this.get(r,n)));return this},i.asinh=function(r){return new t(r).asinh()},i.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atan(this.get(r,n)));return this},i.atan=function(r){return new t(r).atan()},i.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atanh(this.get(r,n)));return this},i.atanh=function(r){return new t(r).atanh()},i.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cbrt(this.get(r,n)));return this},i.cbrt=function(r){return new t(r).cbrt()},i.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.ceil(this.get(r,n)));return this},i.ceil=function(r){return new t(r).ceil()},i.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.clz32(this.get(r,n)));return this},i.clz32=function(r){return new t(r).clz32()},i.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cos(this.get(r,n)));return this},i.cos=function(r){return new t(r).cos()},i.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cosh(this.get(r,n)));return this},i.cosh=function(r){return new t(r).cosh()},i.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.exp(this.get(r,n)));return this},i.exp=function(r){return new t(r).exp()},i.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.expm1(this.get(r,n)));return this},i.expm1=function(r){return new t(r).expm1()},i.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.floor(this.get(r,n)));return this},i.floor=function(r){return new t(r).floor()},i.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.fround(this.get(r,n)));return this},i.fround=function(r){return new t(r).fround()},i.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log(this.get(r,n)));return this},i.log=function(r){return new t(r).log()},i.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log1p(this.get(r,n)));return this},i.log1p=function(r){return new t(r).log1p()},i.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log10(this.get(r,n)));return this},i.log10=function(r){return new t(r).log10()},i.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log2(this.get(r,n)));return this},i.log2=function(r){return new t(r).log2()},i.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.round(this.get(r,n)));return this},i.round=function(r){return new t(r).round()},i.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sign(this.get(r,n)));return this},i.sign=function(r){return new t(r).sign()},i.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sin(this.get(r,n)));return this},i.sin=function(r){return new t(r).sin()},i.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sinh(this.get(r,n)));return this},i.sinh=function(r){return new t(r).sinh()},i.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sqrt(this.get(r,n)));return this},i.sqrt=function(r){return new t(r).sqrt()},i.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tan(this.get(r,n)));return this},i.tan=function(r){return new t(r).tan()},i.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tanh(this.get(r,n)));return this},i.tanh=function(r){return new t(r).tanh()},i.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.trunc(this.get(r,n)));return this},i.trunc=function(r){return new t(r).trunc()},i.pow=function(r,n){return new t(r).pow(n)},i.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},i.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r));return this},i.prototype.powM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r.get(n,s)));return this}}function vr(i,t,e){let r=e?i.rows:i.rows-1;if(t<0||t>r)throw new RangeError("Row index out of range")}function _r(i,t,e){let r=e?i.columns:i.columns-1;if(t<0||t>r)throw new RangeError("Column index out of range")}function pi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.columns)throw new RangeError("vector size must be the same as the number of columns");return t}function di(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.rows)throw new RangeError("vector size must be the same as the number of rows");return t}function Sa(i,t){if(!Je.isAnyArray(t))throw new TypeError("row indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.rows)throw new RangeError("row indices are out of range")}function Ba(i,t){if(!Je.isAnyArray(t))throw new TypeError("column indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.columns)throw new RangeError("column indices are out of range")}function Ia(i,t,e,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Xs("startRow",t),Xs("endRow",e),Xs("startColumn",r),Xs("endColumn",n),t>e||r>n||t<0||t>=i.rows||e<0||e>=i.rows||r<0||r>=i.columns||n<0||n>=i.columns)throw new RangeError("Submatrix indices are out of range")}function Js(i,t=0){let e=[];for(let r=0;r<i;r++)e.push(t);return e}function Xs(i,t){if(typeof t!="number")throw new TypeError(`${i} must be a number`)}function mi(i){if(i.isEmpty())throw new Error("Empty matrix has no elements to index")}function b1(i){let t=Js(i.rows);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]+=i.get(e,r);return t}function E1(i){let t=Js(i.columns);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]+=i.get(e,r);return t}function A1(i){let t=0;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t+=i.get(e,r);return t}function x1(i){let t=Js(i.rows,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]*=i.get(e,r);return t}function C1(i){let t=Js(i.columns,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]*=i.get(e,r);return t}function F1(i){let t=1;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t*=i.get(e,r);return t}function M1(i,t,e){const r=i.rows,n=i.columns,s=[];for(let u=0;u<r;u++){let l=0,f=0,p=0;for(let h=0;h<n;h++)p=i.get(u,h)-e[u],l+=p,f+=p*p;t?s.push((f-l*l/n)/(n-1)):s.push((f-l*l/n)/n)}return s}function N1(i,t,e){const r=i.rows,n=i.columns,s=[];for(let u=0;u<n;u++){let l=0,f=0,p=0;for(let h=0;h<r;h++)p=i.get(h,u)-e[u],l+=p,f+=p*p;t?s.push((f-l*l/r)/(r-1)):s.push((f-l*l/r)/r)}return s}function S1(i,t,e){const r=i.rows,n=i.columns,s=r*n;let u=0,l=0,f=0;for(let p=0;p<r;p++)for(let h=0;h<n;h++)f=i.get(p,h)-e,u+=f,l+=f*f;return t?(l-u*u/s)/(s-1):(l-u*u/s)/s}function B1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[e])}function I1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[r])}function T1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t)}function $1(i){const t=[];for(let e=0;e<i.rows;e++){let r=0;for(let n=0;n<i.columns;n++)r+=Math.pow(i.get(e,n),2)/(i.columns-1);t.push(Math.sqrt(r))}return t}function O1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[e])}function R1(i){const t=[];for(let e=0;e<i.columns;e++){let r=0;for(let n=0;n<i.rows;n++)r+=Math.pow(i.get(n,e),2)/(i.rows-1);t.push(Math.sqrt(r))}return t}function L1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[r])}function P1(i){const t=i.size-1;let e=0;for(let r=0;r<i.columns;r++)for(let n=0;n<i.rows;n++)e+=Math.pow(i.get(n,r),2)/t;return Math.sqrt(e)}function z1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t)}class $t{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new pt(t,e);for(let u=0;u<t;u++)for(let l=0;l<e;l++)s.set(u,l,r[u*e+l]);return s}static rowVector(t){let e=new pt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new pt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new pt(t,e)}static ones(t,e){return new pt(t,e).fill(1)}static rand(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let s=new pt(t,e);for(let u=0;u<t;u++)for(let l=0;l<e;l++)s.set(u,l,n());return s}static randInt(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:u=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let l=s-n,f=new pt(t,e);for(let p=0;p<t;p++)for(let h=0;h<e;h++){let c=n+Math.round(u()*l);f.set(p,h,c)}return f}static eye(t,e,r){e===void 0&&(e=t),r===void 0&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let u=0;u<n;u++)s.set(u,u,r);return s}static diag(t,e,r){let n=t.length;e===void 0&&(e=n),r===void 0&&(r=e);let s=Math.min(n,e,r),u=this.zeros(e,r);for(let l=0;l<s;l++)u.set(l,l,t[l]);return u}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new pt(r,n);for(let u=0;u<r;u++)for(let l=0;l<n;l++)s.set(u,l,Math.min(t.get(u,l),e.get(u,l)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let u=0;u<r;u++)for(let l=0;l<n;l++)s.set(u,l,Math.max(t.get(u,l),e.get(u,l)));return s}static checkMatrix(t){return $t.isMatrix(t)?t:new pt(t)}static isMatrix(t){return t!=null&&t.klass==="Matrix"}get size(){return this.rows*this.columns}apply(t){if(typeof t!="function")throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(this.get(t,t)!==0)return!1;return!0}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let u=e+1;u<this.rows;u++)this.get(t,u)!==0&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(t.get(n,r)===0)r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let u=r;u<t.columns;u++)t.set(e,u,t.get(e,u)/s);for(let u=e+1;u<t.rows;u++){let l=t.get(u,r)/t.get(e,r);t.set(u,r,0);for(let f=r+1;f<t.columns;f++)t.set(u,f,t.get(u,f)-t.get(e,f)*l)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(t.maxRow(n)===0)n--;else{let s=0,u=!1;for(;s<r&&u===!1;)t.get(n,s)===1?u=!0:s++;for(let l=0;l<n;l++){let f=t.get(l,s);for(let p=s;p<e;p++){let h=t.get(l,p)-f*t.get(n,p);t.set(l,p,h)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new pt(this.rows*e,this.columns*r);for(let s=0;s<e;s++)for(let u=0;u<r;u++)n.setSubMatrix(this,this.rows*s,this.columns*u);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){vr(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return pt.rowVector(this.getRow(t))}setRow(t,e){vr(this,t),e=pi(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){vr(this,t),vr(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){_r(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return pt.columnVector(this.getColumn(t))}setColumn(t,e){_r(this,t),e=di(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){_r(this,t),_r(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){vr(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){_r(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){mi(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}minIndex(){mi(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(vr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){vr(this,t),mi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(vr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){vr(this,t),mi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(_r(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){_r(this,t),mi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(_r(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){_r(this,t),mi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${t}`)}}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){$t.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new pt(e,n),u=new Float64Array(r);for(let l=0;l<n;l++){for(let f=0;f<r;f++)u[f]=t.get(f,l);for(let f=0;f<e;f++){let p=0;for(let h=0;h<r;h++)p+=this.get(f,h)*u[h];s.set(f,l,p)}}return s}strassen2x2(t){t=pt.checkMatrix(t);let e=new pt(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),u=t.get(0,1),l=this.get(1,0),f=t.get(1,0),p=this.get(1,1),h=t.get(1,1),c=(r+p)*(n+h),m=(l+p)*n,_=r*(u-h),w=p*(f-n),g=(r+s)*h,y=(l-r)*(n+u),v=(s-p)*(f+h),E=c+w-g+v,b=_+g,N=m+w,x=c-m+_+y;return e.set(0,0,E),e.set(0,1,b),e.set(1,0,N),e.set(1,1,x),e}strassen3x3(t){t=pt.checkMatrix(t);let e=new pt(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),u=this.get(1,0),l=this.get(1,1),f=this.get(1,2),p=this.get(2,0),h=this.get(2,1),c=this.get(2,2),m=t.get(0,0),_=t.get(0,1),w=t.get(0,2),g=t.get(1,0),y=t.get(1,1),v=t.get(1,2),E=t.get(2,0),b=t.get(2,1),N=t.get(2,2),x=(r+n+s-u-l-h-c)*y,F=(r-u)*(-_+y),M=l*(-m+_+g-y-v-E+N),S=(-r+u+l)*(m-_+y),$=(u+l)*(-m+_),C=r*m,I=(-r+p+h)*(m-w+v),R=(-r+p)*(w-v),U=(p+h)*(-m+w),q=(r+n+s-l-f-p-h)*v,k=h*(-m+w+g-y-v-E+b),P=(-s+h+c)*(y+E-b),K=(s-c)*(y-b),G=s*E,V=(h+c)*(-E+b),tt=(-s+l+f)*(v+E-N),ft=(s-f)*(v-N),vt=(l+f)*(-E+N),lt=n*g,wt=f*b,yt=u*w,St=p*_,bt=c*N,ee=C+G+lt,It=x+S+$+C+P+G+V,Mt=C+I+U+q+G+tt+vt,ie=F+M+S+C+G+tt+ft,Xt=F+S+$+C+wt,zt=G+tt+ft+vt+yt,Gt=C+I+R+k+P+K+G,Ce=P+K+G+V+St,sr=C+I+R+U+bt;return e.set(0,0,ee),e.set(0,1,It),e.set(0,2,Mt),e.set(1,0,ie),e.set(1,1,Xt),e.set(1,2,zt),e.set(2,0,Gt),e.set(2,1,Ce),e.set(2,2,sr),e}mmulStrassen(t){t=pt.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,u=t.columns;n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${u} matrix: dimensions do not match.`);function l(c,m,_){let w=c.rows,g=c.columns;if(w===m&&g===_)return c;{let y=$t.zeros(m,_);return y=y.setSubMatrix(c,0,0),y}}let f=Math.max(r,s),p=Math.max(n,u);e=l(e,f,p),t=l(t,f,p);function h(c,m,_,w){if(_<=512||w<=512)return c.mmul(m);_%2===1&&w%2===1?(c=l(c,_+1,w+1),m=l(m,_+1,w+1)):_%2===1?(c=l(c,_+1,w),m=l(m,_+1,w)):w%2===1&&(c=l(c,_,w+1),m=l(m,_,w+1));let g=parseInt(c.rows/2,10),y=parseInt(c.columns/2,10),v=c.subMatrix(0,g-1,0,y-1),E=m.subMatrix(0,g-1,0,y-1),b=c.subMatrix(0,g-1,y,c.columns-1),N=m.subMatrix(0,g-1,y,m.columns-1),x=c.subMatrix(g,c.rows-1,0,y-1),F=m.subMatrix(g,m.rows-1,0,y-1),M=c.subMatrix(g,c.rows-1,y,c.columns-1),S=m.subMatrix(g,m.rows-1,y,m.columns-1),$=h($t.add(v,M),$t.add(E,S),g,y),C=h($t.add(x,M),E,g,y),I=h(v,$t.sub(N,S),g,y),R=h(M,$t.sub(F,E),g,y),U=h($t.add(v,b),S,g,y),q=h($t.sub(x,v),$t.add(E,N),g,y),k=h($t.sub(b,M),$t.add(F,S),g,y),P=$t.add($,R);P.sub(U),P.add(k);let K=$t.add(I,U),G=$t.add(C,R),V=$t.sub($,C);V.add(I),V.add(q);let tt=$t.zeros(2*P.rows,2*P.columns);return tt=tt.setSubMatrix(P,0,0),tt=tt.setSubMatrix(K,P.rows,0),tt=tt.setSubMatrix(G,0,P.columns),tt=tt.setSubMatrix(V,P.rows,P.columns),tt.subMatrix(0,_-1,0,w-1)}return h(e,t,f,p)}scaleRows(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.rows;s++){const u=this.getRow(s);u.length>0&&Sc(u,{min:e,max:r,output:u}),n.setRow(s,u)}return n}scaleColumns(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.columns;s++){const u=this.getColumn(s);u.length&&Sc(u,{min:e,max:r,output:u}),n.setColumn(s,u)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let n=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,n)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let n=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,n)}return this}kroneckerProduct(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,u=new pt(e*n,r*s);for(let l=0;l<e;l++)for(let f=0;f<r;f++)for(let p=0;p<n;p++)for(let h=0;h<s;h++)u.set(n*l+p,s*f+h,this.get(l,f)*t.get(p,h));return u}kroneckerSum(t){if(t=pt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(pt.eye(r,r)),s=pt.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new pt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=$c){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=$c){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Ia(this,t,e,r,n);let s=new pt(e-t+1,n-r+1);for(let u=t;u<=e;u++)for(let l=r;l<=n;l++)s.set(u-t,l-r,this.get(u,l));return s}subMatrixRow(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new pt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let u=e;u<=r;u++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,u-e,this.get(t[s],u))}return n}subMatrixColumn(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new pt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let u=e;u<=r;u++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(u-e,s,this.get(u,t[s]))}return n}setSubMatrix(t,e,r){if(t=pt.checkMatrix(t),t.isEmpty())return this;let n=e+t.rows-1,s=r+t.columns-1;Ia(this,e,n,r,s);for(let u=0;u<t.rows;u++)for(let l=0;l<t.columns;l++)this.set(e+u,r+l,t.get(u,l));return this}selection(t,e){Sa(this,t),Ba(this,e);let r=new pt(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let u=0;u<e.length;u++){let l=e[u];r.set(n,u,this.get(s,l))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){return this.constructor.copy(this,new pt(this.rows,this.columns))}static copy(t,e){for(const[r,n,s]of t.entries())e.set(r,n,s);return e}sum(t){switch(t){case"row":return b1(this);case"column":return E1(this);case void 0:return A1(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return x1(this);case"column":return C1(this);case void 0:return F1(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":{for(let r=0;r<this.rows;r++)e[r]/=this.columns;return e}case"column":{for(let r=0;r<this.columns;r++)e[r]/=this.rows;return e}case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(t){case"row":{if(!Je.isAnyArray(n))throw new TypeError("mean must be an array");return M1(this,r,n)}case"column":{if(!Je.isAnyArray(n))throw new TypeError("mean must be an array");return N1(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return S1(this,r,n)}default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){typeof t=="object"&&(e=t,t=void 0);const r=this.variance(t,e);if(t===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":{if(!Je.isAnyArray(r))throw new TypeError("center must be an array");return B1(this,r),this}case"column":{if(!Je.isAnyArray(r))throw new TypeError("center must be an array");return I1(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return T1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":{if(r===void 0)r=$1(this);else if(!Je.isAnyArray(r))throw new TypeError("scale must be an array");return O1(this,r),this}case"column":{if(r===void 0)r=R1(this);else if(!Je.isAnyArray(r))throw new TypeError("scale must be an array");return L1(this,r),this}case void 0:{if(r===void 0)r=P1(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return z1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}toString(t){return Ic(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}$t.prototype.klass="Matrix",typeof Symbol<"u"&&($t.prototype[Symbol.for("nodejs.util.inspect.custom")]=_1);function $c(i,t){return i-t}function q1(i){return i.every(t=>typeof t=="number")}$t.random=$t.rand,$t.randomInt=$t.randInt,$t.diagonal=$t.diag,$t.prototype.diagonal=$t.prototype.diag,$t.identity=$t.eye,$t.prototype.negate=$t.prototype.neg,$t.prototype.tensorProduct=$t.prototype.kroneckerProduct;let pt=(Di=class extends $t{constructor(e,r){super();Dl(this,Xi);Z(this,"data");if(Di.isMatrix(e))yl(this,Xi,bl).call(this,e.rows,e.columns),Di.copy(e,this);else if(Number.isInteger(e)&&e>=0)yl(this,Xi,bl).call(this,e,r);else if(Je.isAnyArray(e)){const n=e;if(e=n.length,r=e?n[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<e;s++){if(n[s].length!==r)throw new RangeError("Inconsistent array dimensions");if(!q1(n[s]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[s]))}this.rows=e,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(e,r,n){return this.data[e][r]=n,this}get(e,r){return this.data[e][r]}removeRow(e){return vr(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,r){return r===void 0&&(r=e,e=this.rows),vr(this,e,!0),r=Float64Array.from(pi(this,r)),this.data.splice(e,0,r),this.rows+=1,this}removeColumn(e){_r(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let s=0;s<e;s++)n[s]=this.data[r][s];for(let s=e+1;s<this.columns;s++)n[s-1]=this.data[r][s];this.data[r]=n}return this.columns-=1,this}addColumn(e,r){typeof r>"u"&&(r=e,e=this.columns),_r(this,e,!0),r=di(this,r);for(let n=0;n<this.rows;n++){const s=new Float64Array(this.columns+1);let u=0;for(;u<e;u++)s[u]=this.data[n][u];for(s[u++]=r[n];u<this.columns+1;u++)s[u]=this.data[n][u-1];this.data[n]=s}return this.columns+=1,this}},Xi=new WeakSet,bl=function(e,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<e;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=e,this.columns=r},Di);y1($t,pt);const lo=class lo extends $t{constructor(e){super();Dl(this,qe,void 0);if(pt.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");ea(this,qe,pt.copy(e,new pt(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)ea(this,qe,new pt(e,e));else if(ea(this,qe,new pt(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Lr(this,qe).size}get rows(){return Lr(this,qe).rows}get columns(){return Lr(this,qe).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(e){return pt.isMatrix(e)&&e.klassType==="SymmetricMatrix"}static zeros(e){return new this(e)}static ones(e){return new this(e).fill(1)}clone(){const e=new lo(this.diagonalSize);for(const[r,n,s]of this.upperRightEntries())e.set(r,n,s);return e}toMatrix(){return new pt(this)}get(e,r){return Lr(this,qe).get(e,r)}set(e,r,n){return Lr(this,qe).set(e,r,n),Lr(this,qe).set(r,e,n),this}removeCross(e){return Lr(this,qe).removeRow(e),Lr(this,qe).removeColumn(e),this}addCross(e,r){r===void 0&&(r=e,e=this.diagonalSize);const n=r.slice();return n.splice(e,1),Lr(this,qe).addRow(e,n),Lr(this,qe).addColumn(e,r),this}applyMask(e){if(e.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,s]of e.entries())s||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:e}=this,r=new Array(e*(e+1)/2);for(let n=0,s=0,u=0;u<r.length;u++)r[u]=this.get(s,n),++n>=e&&(n=++s);return r}static fromCompact(e){const r=e.length,n=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(n))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(e)}`);const s=new lo(n);for(let u=0,l=0,f=0;f<r;f++)s.set(u,l,e[f]),++u>=n&&(u=++l);return s}*upperRightEntries(){for(let e=0,r=0;e<this.diagonalSize;void 0){const n=this.get(e,r);yield[e,r,n],++r>=this.diagonalSize&&(r=++e)}}*upperRightValues(){for(let e=0,r=0;e<this.diagonalSize;void 0)yield this.get(e,r),++r>=this.diagonalSize&&(r=++e)}};qe=new WeakMap;let kn=lo;kn.prototype.klassType="SymmetricMatrix";class Vs extends kn{static isDistanceMatrix(t){return kn.isSymmetricMatrix(t)&&t.klassSubType==="DistanceMatrix"}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return e===void 0&&(e=t,t=this.diagonalSize),e=e.slice(),e[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new kn(this)}clone(){const t=new Vs(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())e!==r&&t.set(e,r,n);return t}toCompact(){const{diagonalSize:t}=this,e=(t-1)*t/2,r=new Array(e);for(let n=1,s=0,u=0;u<r.length;u++)r[u]=this.get(s,n),++n>=t&&(n=++s+1);return r}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const n=new this(r);for(let s=1,u=0,l=0;l<e;l++)n.set(s,u,t[l]),++s>=r&&(s=++u+1);return n}}Vs.prototype.klassSubType="DistanceMatrix";class Jr extends $t{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class U1 extends Jr{constructor(t,e){_r(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class k1 extends Jr{constructor(t,e){Ba(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class W1 extends Jr{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}class Y1 extends Jr{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class j1 extends Jr{constructor(t,e){vr(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class Z1 extends Jr{constructor(t,e){Sa(t,e),super(t,e.length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class Qs extends Jr{constructor(t,e,r){Sa(t,e),Ba(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class G1 extends Jr{constructor(t,e,r,n,s){Ia(t,e,r,n,s),super(t,r-e+1,s-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class K1 extends Jr{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class Oc extends $t{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class ir extends $t{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function H1(i,t){if(Je.isAnyArray(i))return i[0]&&Je.isAnyArray(i[0])?new ir(i):new Oc(i,t);throw new Error("the argument is not an array")}class to{constructor(t){t=ir.checkMatrix(t);let e=t.clone(),r=e.rows,n=e.columns,s=new Float64Array(r),u=1,l,f,p,h,c,m,_,w,g;for(l=0;l<r;l++)s[l]=l;for(w=new Float64Array(r),f=0;f<n;f++){for(l=0;l<r;l++)w[l]=e.get(l,f);for(l=0;l<r;l++){for(g=Math.min(l,f),c=0,p=0;p<g;p++)c+=e.get(l,p)*w[p];w[l]-=c,e.set(l,f,w[l])}for(h=f,l=f+1;l<r;l++)Math.abs(w[l])>Math.abs(w[h])&&(h=l);if(h!==f){for(p=0;p<n;p++)m=e.get(h,p),e.set(h,p,e.get(f,p)),e.set(f,p,m);_=s[h],s[h]=s[f],s[f]=_,u=-u}if(f<r&&e.get(f,f)!==0)for(l=f+1;l<r;l++)e.set(l,f,e.get(l,f)/e.get(f,f))}this.LU=e,this.pivotVector=s,this.pivotSign=u}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(t.get(r,r)===0)return!0;return!1}solve(t){t=pt.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=t.columns,s=t.subMatrixRow(this.pivotVector,0,n-1),u=e.columns,l,f,p;for(p=0;p<u;p++)for(l=p+1;l<u;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(p,f)*e.get(l,p));for(p=u-1;p>=0;p--){for(f=0;f<n;f++)s.set(p,f,s.get(p,f)/e.get(p,p));for(l=0;l<p;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(p,f)*e.get(l,p))}return s}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let u=0;u<r;u++)s>u?n.set(s,u,t.get(s,u)):s===u?n.set(s,u,1):n.set(s,u,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let u=0;u<r;u++)s<=u?n.set(s,u,t.get(s,u)):n.set(s,u,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function Xr(i,t){let e=0;return Math.abs(i)>Math.abs(t)?(e=t/i,Math.abs(i)*Math.sqrt(1+e*e)):t!==0?(e=i/t,Math.abs(t)*Math.sqrt(1+e*e)):0}class Ta{constructor(t){t=ir.checkMatrix(t);let e=t.clone(),r=t.rows,n=t.columns,s=new Float64Array(n),u,l,f,p;for(f=0;f<n;f++){let h=0;for(u=f;u<r;u++)h=Xr(h,e.get(u,f));if(h!==0){for(e.get(f,f)<0&&(h=-h),u=f;u<r;u++)e.set(u,f,e.get(u,f)/h);for(e.set(f,f,e.get(f,f)+1),l=f+1;l<n;l++){for(p=0,u=f;u<r;u++)p+=e.get(u,f)*e.get(u,l);for(p=-p/e.get(f,f),u=f;u<r;u++)e.set(u,l,e.get(u,l)+p*e.get(u,f))}}s[f]=-h}this.QR=e,this.Rdiag=s}solve(t){t=pt.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=t.columns,s=t.clone(),u=e.columns,l,f,p,h;for(p=0;p<u;p++)for(f=0;f<n;f++){for(h=0,l=p;l<r;l++)h+=e.get(l,p)*s.get(l,f);for(h=-h/e.get(p,p),l=p;l<r;l++)s.set(l,f,s.get(l,f)+h*e.get(l,p))}for(p=u-1;p>=0;p--){for(f=0;f<n;f++)s.set(p,f,s.get(p,f)/this.Rdiag[p]);for(l=0;l<p;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(p,f)*e.get(l,p))}return s.subMatrix(0,u-1,0,n-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(this.Rdiag[e]===0)return!1;return!0}get upperTriangularMatrix(){let t=this.QR,e=t.columns,r=new pt(e,e),n,s;for(n=0;n<e;n++)for(s=0;s<e;s++)n<s?r.set(n,s,t.get(n,s)):n===s?r.set(n,s,this.Rdiag[n]):r.set(n,s,0);return r}get orthogonalMatrix(){let t=this.QR,e=t.rows,r=t.columns,n=new pt(e,r),s,u,l,f;for(l=r-1;l>=0;l--){for(s=0;s<e;s++)n.set(s,l,0);for(n.set(l,l,1),u=l;u<r;u++)if(t.get(l,l)!==0){for(f=0,s=l;s<e;s++)f+=t.get(s,l)*n.get(s,u);for(f=-f/t.get(l,l),s=l;s<e;s++)n.set(s,u,n.get(s,u)+f*t.get(s,l))}}return n}}class gi{constructor(t,e={}){if(t=ir.checkMatrix(t),t.isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:u=!0,autoTranspose:l=!1}=e;let f=!!s,p=!!u,h=!1,c;if(r<n)if(!l)c=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{c=t.transpose(),r=c.rows,n=c.columns,h=!0;let C=f;f=p,p=C}else c=t.clone();let m=Math.min(r,n),_=Math.min(r+1,n),w=new Float64Array(_),g=new pt(r,m),y=new pt(n,n),v=new Float64Array(n),E=new Float64Array(r),b=new Float64Array(_);for(let C=0;C<_;C++)b[C]=C;let N=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),F=Math.max(N,x);for(let C=0;C<F;C++){if(C<N){w[C]=0;for(let I=C;I<r;I++)w[C]=Xr(w[C],c.get(I,C));if(w[C]!==0){c.get(C,C)<0&&(w[C]=-w[C]);for(let I=C;I<r;I++)c.set(I,C,c.get(I,C)/w[C]);c.set(C,C,c.get(C,C)+1)}w[C]=-w[C]}for(let I=C+1;I<n;I++){if(C<N&&w[C]!==0){let R=0;for(let U=C;U<r;U++)R+=c.get(U,C)*c.get(U,I);R=-R/c.get(C,C);for(let U=C;U<r;U++)c.set(U,I,c.get(U,I)+R*c.get(U,C))}v[I]=c.get(C,I)}if(f&&C<N)for(let I=C;I<r;I++)g.set(I,C,c.get(I,C));if(C<x){v[C]=0;for(let I=C+1;I<n;I++)v[C]=Xr(v[C],v[I]);if(v[C]!==0){v[C+1]<0&&(v[C]=0-v[C]);for(let I=C+1;I<n;I++)v[I]/=v[C];v[C+1]+=1}if(v[C]=-v[C],C+1<r&&v[C]!==0){for(let I=C+1;I<r;I++)E[I]=0;for(let I=C+1;I<r;I++)for(let R=C+1;R<n;R++)E[I]+=v[R]*c.get(I,R);for(let I=C+1;I<n;I++){let R=-v[I]/v[C+1];for(let U=C+1;U<r;U++)c.set(U,I,c.get(U,I)+R*E[U])}}if(p)for(let I=C+1;I<n;I++)y.set(I,C,v[I])}}let M=Math.min(n,r+1);if(N<n&&(w[N]=c.get(N,N)),r<M&&(w[M-1]=0),x+1<M&&(v[x]=c.get(x,M-1)),v[M-1]=0,f){for(let C=N;C<m;C++){for(let I=0;I<r;I++)g.set(I,C,0);g.set(C,C,1)}for(let C=N-1;C>=0;C--)if(w[C]!==0){for(let I=C+1;I<m;I++){let R=0;for(let U=C;U<r;U++)R+=g.get(U,C)*g.get(U,I);R=-R/g.get(C,C);for(let U=C;U<r;U++)g.set(U,I,g.get(U,I)+R*g.get(U,C))}for(let I=C;I<r;I++)g.set(I,C,-g.get(I,C));g.set(C,C,1+g.get(C,C));for(let I=0;I<C-1;I++)g.set(I,C,0)}else{for(let I=0;I<r;I++)g.set(I,C,0);g.set(C,C,1)}}if(p)for(let C=n-1;C>=0;C--){if(C<x&&v[C]!==0)for(let I=C+1;I<n;I++){let R=0;for(let U=C+1;U<n;U++)R+=y.get(U,C)*y.get(U,I);R=-R/y.get(C+1,C);for(let U=C+1;U<n;U++)y.set(U,I,y.get(U,I)+R*y.get(U,C))}for(let I=0;I<n;I++)y.set(I,C,0);y.set(C,C,1)}let S=M-1,$=Number.EPSILON;for(;M>0;){let C,I;for(C=M-2;C>=-1&&C!==-1;C--){const R=Number.MIN_VALUE+$*Math.abs(w[C]+Math.abs(w[C+1]));if(Math.abs(v[C])<=R||Number.isNaN(v[C])){v[C]=0;break}}if(C===M-2)I=4;else{let R;for(R=M-1;R>=C&&R!==C;R--){let U=(R!==M?Math.abs(v[R]):0)+(R!==C+1?Math.abs(v[R-1]):0);if(Math.abs(w[R])<=$*U){w[R]=0;break}}R===C?I=3:R===M-1?I=1:(I=2,C=R)}switch(C++,I){case 1:{let R=v[M-2];v[M-2]=0;for(let U=M-2;U>=C;U--){let q=Xr(w[U],R),k=w[U]/q,P=R/q;if(w[U]=q,U!==C&&(R=-P*v[U-1],v[U-1]=k*v[U-1]),p)for(let K=0;K<n;K++)q=k*y.get(K,U)+P*y.get(K,M-1),y.set(K,M-1,-P*y.get(K,U)+k*y.get(K,M-1)),y.set(K,U,q)}break}case 2:{let R=v[C-1];v[C-1]=0;for(let U=C;U<M;U++){let q=Xr(w[U],R),k=w[U]/q,P=R/q;if(w[U]=q,R=-P*v[U],v[U]=k*v[U],f)for(let K=0;K<r;K++)q=k*g.get(K,U)+P*g.get(K,C-1),g.set(K,C-1,-P*g.get(K,U)+k*g.get(K,C-1)),g.set(K,U,q)}break}case 3:{const R=Math.max(Math.abs(w[M-1]),Math.abs(w[M-2]),Math.abs(v[M-2]),Math.abs(w[C]),Math.abs(v[C])),U=w[M-1]/R,q=w[M-2]/R,k=v[M-2]/R,P=w[C]/R,K=v[C]/R,G=((q+U)*(q-U)+k*k)/2,V=U*k*(U*k);let tt=0;(G!==0||V!==0)&&(G<0?tt=0-Math.sqrt(G*G+V):tt=Math.sqrt(G*G+V),tt=V/(G+tt));let ft=(P+U)*(P-U)+tt,vt=P*K;for(let lt=C;lt<M-1;lt++){let wt=Xr(ft,vt);wt===0&&(wt=Number.MIN_VALUE);let yt=ft/wt,St=vt/wt;if(lt!==C&&(v[lt-1]=wt),ft=yt*w[lt]+St*v[lt],v[lt]=yt*v[lt]-St*w[lt],vt=St*w[lt+1],w[lt+1]=yt*w[lt+1],p)for(let bt=0;bt<n;bt++)wt=yt*y.get(bt,lt)+St*y.get(bt,lt+1),y.set(bt,lt+1,-St*y.get(bt,lt)+yt*y.get(bt,lt+1)),y.set(bt,lt,wt);if(wt=Xr(ft,vt),wt===0&&(wt=Number.MIN_VALUE),yt=ft/wt,St=vt/wt,w[lt]=wt,ft=yt*v[lt]+St*w[lt+1],w[lt+1]=-St*v[lt]+yt*w[lt+1],vt=St*v[lt+1],v[lt+1]=yt*v[lt+1],f&&lt<r-1)for(let bt=0;bt<r;bt++)wt=yt*g.get(bt,lt)+St*g.get(bt,lt+1),g.set(bt,lt+1,-St*g.get(bt,lt)+yt*g.get(bt,lt+1)),g.set(bt,lt,wt)}v[M-2]=ft;break}case 4:{if(w[C]<=0&&(w[C]=w[C]<0?-w[C]:0,p))for(let R=0;R<=S;R++)y.set(R,C,-y.get(R,C));for(;C<S&&!(w[C]>=w[C+1]);){let R=w[C];if(w[C]=w[C+1],w[C+1]=R,p&&C<n-1)for(let U=0;U<n;U++)R=y.get(U,C+1),y.set(U,C+1,y.get(U,C)),y.set(U,C,R);if(f&&C<r-1)for(let U=0;U<r;U++)R=g.get(U,C+1),g.set(U,C+1,g.get(U,C)),g.set(U,C,R);C++}M--;break}}}if(h){let C=y;y=g,g=C}this.m=r,this.n=n,this.s=w,this.U=g,this.V=y}solve(t){let e=t,r=this.threshold,n=this.s.length,s=pt.zeros(n,n);for(let m=0;m<n;m++)Math.abs(this.s[m])<=r?s.set(m,m,0):s.set(m,m,1/this.s[m]);let u=this.U,l=this.rightSingularVectors,f=l.mmul(s),p=l.rows,h=u.rows,c=pt.zeros(p,h);for(let m=0;m<p;m++)for(let _=0;_<h;_++){let w=0;for(let g=0;g<n;g++)w+=f.get(m,g)*u.get(_,g);c.set(m,_,w)}return c.mmul(e)}solveForDiagonal(t){return this.solve(pt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new pt(r,this.s.length);for(let h=0;h<r;h++)for(let c=0;c<n;c++)Math.abs(this.s[c])>e&&s.set(h,c,t.get(h,c)/this.s[c]);let u=this.U,l=u.rows,f=u.columns,p=new pt(r,l);for(let h=0;h<r;h++)for(let c=0;c<l;c++){let m=0;for(let _=0;_<f;_++)m+=s.get(h,_)*u.get(c,_);p.set(h,c,m)}return p}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return pt.diag(this.s)}}function J1(i,t=!1){return i=ir.checkMatrix(i),t?new gi(i).inverse():Rc(i,pt.eye(i.rows))}function Rc(i,t,e=!1){return i=ir.checkMatrix(i),t=ir.checkMatrix(t),e?new gi(i).solve(t):i.isSquare()?new to(i).solve(t):new Ta(i).solve(t)}function eo(i){if(i=pt.checkMatrix(i),i.isSquare()){if(i.columns===0)return 1;let t,e,r,n;if(i.columns===2)return t=i.get(0,0),e=i.get(0,1),r=i.get(1,0),n=i.get(1,1),t*n-e*r;if(i.columns===3){let s,u,l;return s=new Qs(i,[1,2],[1,2]),u=new Qs(i,[1,2],[0,2]),l=new Qs(i,[1,2],[0,1]),t=i.get(0,0),e=i.get(0,1),r=i.get(0,2),t*eo(s)-e*eo(u)+r*eo(l)}else return new to(i).determinant}else throw Error("determinant can only be calculated for a square matrix")}function X1(i,t){let e=[];for(let r=0;r<i;r++)r!==t&&e.push(r);return e}function V1(i,t,e,r=1e-9,n=1e-9){if(i>n)return new Array(t.rows+1).fill(0);{let s=t.addRow(e,[0]);for(let u=0;u<s.rows;u++)Math.abs(s.get(u,0))<r&&s.set(u,0,0);return s.to1DArray()}}function Q1(i,t={}){const{thresholdValue:e=1e-9,thresholdError:r=1e-9}=t;i=pt.checkMatrix(i);let n=i.rows,s=new pt(n,n);for(let u=0;u<n;u++){let l=pt.columnVector(i.getRow(u)),f=i.subMatrixRow(X1(n,u)).transpose(),h=new gi(f).solve(l),c=pt.sub(l,f.mmul(h)).abs().max();s.setRow(u,V1(c,h,u,e,r))}return s}function tw(i,t=Number.EPSILON){if(i=pt.checkMatrix(i),i.isEmpty())return i.transpose();let e=new gi(i,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,s=e.diagonal;for(let u=0;u<s.length;u++)Math.abs(s[u])>t?s[u]=1/s[u]:s[u]=0;return n.mmul(pt.diag(s).mmul(r.transpose()))}function ew(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!Je.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(i=i.center("column"),r||(t=t.center("column")));const s=i.transpose().mmul(t);for(let u=0;u<s.rows;u++)for(let l=0;l<s.columns;l++)s.set(u,l,s.get(u,l)*(1/(i.rows-1)));return s}function rw(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!Je.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:s=!0}=e;n&&(i.center("column"),r||t.center("column")),s&&(i.scale("column"),r||t.scale("column"));const u=i.standardDeviation("column",{unbiased:!0}),l=r?u:t.standardDeviation("column",{unbiased:!0}),f=i.transpose().mmul(t);for(let p=0;p<f.rows;p++)for(let h=0;h<f.columns;h++)f.set(p,h,f.get(p,h)*(1/(u[p]*l[h]))*(1/(i.rows-1)));return f}let Lc=class{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(t=ir.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n=t.columns,s=new pt(n,n),u=new Float64Array(n),l=new Float64Array(n),f=t,p,h,c=!1;if(r?c=!0:c=t.isSymmetric(),c){for(p=0;p<n;p++)for(h=0;h<n;h++)s.set(p,h,f.get(p,h));nw(n,l,u,s),iw(n,l,u,s)}else{let m=new pt(n,n),_=new Float64Array(n);for(h=0;h<n;h++)for(p=0;p<n;p++)m.set(p,h,f.get(p,h));sw(n,m,_,s),ow(n,l,u,s,m)}this.n=n,this.e=l,this.d=u,this.V=s}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t=this.n,e=this.e,r=this.d,n=new pt(t,t),s,u;for(s=0;s<t;s++){for(u=0;u<t;u++)n.set(s,u,0);n.set(s,s,r[s]),e[s]>0?n.set(s,s+1,e[s]):e[s]<0&&n.set(s,s-1,e[s])}return n}};function nw(i,t,e,r){let n,s,u,l,f,p,h,c;for(f=0;f<i;f++)e[f]=r.get(i-1,f);for(l=i-1;l>0;l--){for(c=0,u=0,p=0;p<l;p++)c=c+Math.abs(e[p]);if(c===0)for(t[l]=e[l-1],f=0;f<l;f++)e[f]=r.get(l-1,f),r.set(l,f,0),r.set(f,l,0);else{for(p=0;p<l;p++)e[p]/=c,u+=e[p]*e[p];for(n=e[l-1],s=Math.sqrt(u),n>0&&(s=-s),t[l]=c*s,u=u-n*s,e[l-1]=n-s,f=0;f<l;f++)t[f]=0;for(f=0;f<l;f++){for(n=e[f],r.set(f,l,n),s=t[f]+r.get(f,f)*n,p=f+1;p<=l-1;p++)s+=r.get(p,f)*e[p],t[p]+=r.get(p,f)*n;t[f]=s}for(n=0,f=0;f<l;f++)t[f]/=u,n+=t[f]*e[f];for(h=n/(u+u),f=0;f<l;f++)t[f]-=h*e[f];for(f=0;f<l;f++){for(n=e[f],s=t[f],p=f;p<=l-1;p++)r.set(p,f,r.get(p,f)-(n*t[p]+s*e[p]));e[f]=r.get(l-1,f),r.set(l,f,0)}}e[l]=u}for(l=0;l<i-1;l++){if(r.set(i-1,l,r.get(l,l)),r.set(l,l,1),u=e[l+1],u!==0){for(p=0;p<=l;p++)e[p]=r.get(p,l+1)/u;for(f=0;f<=l;f++){for(s=0,p=0;p<=l;p++)s+=r.get(p,l+1)*r.get(p,f);for(p=0;p<=l;p++)r.set(p,f,r.get(p,f)-s*e[p])}}for(p=0;p<=l;p++)r.set(p,l+1,0)}for(f=0;f<i;f++)e[f]=r.get(i-1,f),r.set(i-1,f,0);r.set(i-1,i-1,1),t[0]=0}function iw(i,t,e,r){let n,s,u,l,f,p,h,c,m,_,w,g,y,v,E,b;for(u=1;u<i;u++)t[u-1]=t[u];t[i-1]=0;let N=0,x=0,F=Number.EPSILON;for(p=0;p<i;p++){for(x=Math.max(x,Math.abs(e[p])+Math.abs(t[p])),h=p;h<i&&!(Math.abs(t[h])<=F*x);)h++;if(h>p)do{for(n=e[p],c=(e[p+1]-n)/(2*t[p]),m=Xr(c,1),c<0&&(m=-m),e[p]=t[p]/(c+m),e[p+1]=t[p]*(c+m),_=e[p+1],s=n-e[p],u=p+2;u<i;u++)e[u]-=s;for(N=N+s,c=e[h],w=1,g=w,y=w,v=t[p+1],E=0,b=0,u=h-1;u>=p;u--)for(y=g,g=w,b=E,n=w*t[u],s=w*c,m=Xr(c,t[u]),t[u+1]=E*m,E=t[u]/m,w=c/m,c=w*e[u]-E*n,e[u+1]=s+E*(w*n+E*e[u]),f=0;f<i;f++)s=r.get(f,u+1),r.set(f,u+1,E*r.get(f,u)+w*s),r.set(f,u,w*r.get(f,u)-E*s);c=-E*b*y*v*t[p]/_,t[p]=E*c,e[p]=w*c}while(Math.abs(t[p])>F*x);e[p]=e[p]+N,t[p]=0}for(u=0;u<i-1;u++){for(f=u,c=e[u],l=u+1;l<i;l++)e[l]<c&&(f=l,c=e[l]);if(f!==u)for(e[f]=e[u],e[u]=c,l=0;l<i;l++)c=r.get(l,u),r.set(l,u,r.get(l,f)),r.set(l,f,c)}}function sw(i,t,e,r){let n=0,s=i-1,u,l,f,p,h,c,m;for(c=n+1;c<=s-1;c++){for(m=0,p=c;p<=s;p++)m=m+Math.abs(t.get(p,c-1));if(m!==0){for(f=0,p=s;p>=c;p--)e[p]=t.get(p,c-1)/m,f+=e[p]*e[p];for(l=Math.sqrt(f),e[c]>0&&(l=-l),f=f-e[c]*l,e[c]=e[c]-l,h=c;h<i;h++){for(u=0,p=s;p>=c;p--)u+=e[p]*t.get(p,h);for(u=u/f,p=c;p<=s;p++)t.set(p,h,t.get(p,h)-u*e[p])}for(p=0;p<=s;p++){for(u=0,h=s;h>=c;h--)u+=e[h]*t.get(p,h);for(u=u/f,h=c;h<=s;h++)t.set(p,h,t.get(p,h)-u*e[h])}e[c]=m*e[c],t.set(c,c-1,m*l)}}for(p=0;p<i;p++)for(h=0;h<i;h++)r.set(p,h,p===h?1:0);for(c=s-1;c>=n+1;c--)if(t.get(c,c-1)!==0){for(p=c+1;p<=s;p++)e[p]=t.get(p,c-1);for(h=c;h<=s;h++){for(l=0,p=c;p<=s;p++)l+=e[p]*r.get(p,h);for(l=l/e[c]/t.get(c,c-1),p=c;p<=s;p++)r.set(p,h,r.get(p,h)+l*e[p])}}}function ow(i,t,e,r,n){let s=i-1,u=0,l=i-1,f=Number.EPSILON,p=0,h=0,c=0,m=0,_=0,w=0,g=0,y=0,v,E,b,N,x,F,M,S,$,C,I,R,U,q,k;for(v=0;v<i;v++)for((v<u||v>l)&&(e[v]=n.get(v,v),t[v]=0),E=Math.max(v-1,0);E<i;E++)h=h+Math.abs(n.get(v,E));for(;s>=u;){for(N=s;N>u&&(w=Math.abs(n.get(N-1,N-1))+Math.abs(n.get(N,N)),w===0&&(w=h),!(Math.abs(n.get(N,N-1))<f*w));)N--;if(N===s)n.set(s,s,n.get(s,s)+p),e[s]=n.get(s,s),t[s]=0,s--,y=0;else if(N===s-1){if(M=n.get(s,s-1)*n.get(s-1,s),c=(n.get(s-1,s-1)-n.get(s,s))/2,m=c*c+M,g=Math.sqrt(Math.abs(m)),n.set(s,s,n.get(s,s)+p),n.set(s-1,s-1,n.get(s-1,s-1)+p),S=n.get(s,s),m>=0){for(g=c>=0?c+g:c-g,e[s-1]=S+g,e[s]=e[s-1],g!==0&&(e[s]=S-M/g),t[s-1]=0,t[s]=0,S=n.get(s,s-1),w=Math.abs(S)+Math.abs(g),c=S/w,m=g/w,_=Math.sqrt(c*c+m*m),c=c/_,m=m/_,E=s-1;E<i;E++)g=n.get(s-1,E),n.set(s-1,E,m*g+c*n.get(s,E)),n.set(s,E,m*n.get(s,E)-c*g);for(v=0;v<=s;v++)g=n.get(v,s-1),n.set(v,s-1,m*g+c*n.get(v,s)),n.set(v,s,m*n.get(v,s)-c*g);for(v=u;v<=l;v++)g=r.get(v,s-1),r.set(v,s-1,m*g+c*r.get(v,s)),r.set(v,s,m*r.get(v,s)-c*g)}else e[s-1]=S+c,e[s]=S+c,t[s-1]=g,t[s]=-g;s=s-2,y=0}else{if(S=n.get(s,s),$=0,M=0,N<s&&($=n.get(s-1,s-1),M=n.get(s,s-1)*n.get(s-1,s)),y===10){for(p+=S,v=u;v<=s;v++)n.set(v,v,n.get(v,v)-S);w=Math.abs(n.get(s,s-1))+Math.abs(n.get(s-1,s-2)),S=$=.75*w,M=-.4375*w*w}if(y===30&&(w=($-S)/2,w=w*w+M,w>0)){for(w=Math.sqrt(w),$<S&&(w=-w),w=S-M/(($-S)/2+w),v=u;v<=s;v++)n.set(v,v,n.get(v,v)-w);p+=w,S=$=M=.964}for(y=y+1,x=s-2;x>=N&&(g=n.get(x,x),_=S-g,w=$-g,c=(_*w-M)/n.get(x+1,x)+n.get(x,x+1),m=n.get(x+1,x+1)-g-_-w,_=n.get(x+2,x+1),w=Math.abs(c)+Math.abs(m)+Math.abs(_),c=c/w,m=m/w,_=_/w,!(x===N||Math.abs(n.get(x,x-1))*(Math.abs(m)+Math.abs(_))<f*(Math.abs(c)*(Math.abs(n.get(x-1,x-1))+Math.abs(g)+Math.abs(n.get(x+1,x+1))))));)x--;for(v=x+2;v<=s;v++)n.set(v,v-2,0),v>x+2&&n.set(v,v-3,0);for(b=x;b<=s-1&&(q=b!==s-1,b!==x&&(c=n.get(b,b-1),m=n.get(b+1,b-1),_=q?n.get(b+2,b-1):0,S=Math.abs(c)+Math.abs(m)+Math.abs(_),S!==0&&(c=c/S,m=m/S,_=_/S)),S!==0);b++)if(w=Math.sqrt(c*c+m*m+_*_),c<0&&(w=-w),w!==0){for(b!==x?n.set(b,b-1,-w*S):N!==x&&n.set(b,b-1,-n.get(b,b-1)),c=c+w,S=c/w,$=m/w,g=_/w,m=m/c,_=_/c,E=b;E<i;E++)c=n.get(b,E)+m*n.get(b+1,E),q&&(c=c+_*n.get(b+2,E),n.set(b+2,E,n.get(b+2,E)-c*g)),n.set(b,E,n.get(b,E)-c*S),n.set(b+1,E,n.get(b+1,E)-c*$);for(v=0;v<=Math.min(s,b+3);v++)c=S*n.get(v,b)+$*n.get(v,b+1),q&&(c=c+g*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-c*_)),n.set(v,b,n.get(v,b)-c),n.set(v,b+1,n.get(v,b+1)-c*m);for(v=u;v<=l;v++)c=S*r.get(v,b)+$*r.get(v,b+1),q&&(c=c+g*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-c*_)),r.set(v,b,r.get(v,b)-c),r.set(v,b+1,r.get(v,b+1)-c*m)}}}if(h!==0){for(s=i-1;s>=0;s--)if(c=e[s],m=t[s],m===0)for(N=s,n.set(s,s,1),v=s-1;v>=0;v--){for(M=n.get(v,v)-c,_=0,E=N;E<=s;E++)_=_+n.get(v,E)*n.get(E,s);if(t[v]<0)g=M,w=_;else if(N=v,t[v]===0?n.set(v,s,M!==0?-_/M:-_/(f*h)):(S=n.get(v,v+1),$=n.get(v+1,v),m=(e[v]-c)*(e[v]-c)+t[v]*t[v],F=(S*w-g*_)/m,n.set(v,s,F),n.set(v+1,s,Math.abs(S)>Math.abs(g)?(-_-M*F)/S:(-w-$*F)/g)),F=Math.abs(n.get(v,s)),f*F*F>1)for(E=v;E<=s;E++)n.set(E,s,n.get(E,s)/F)}else if(m<0)for(N=s-1,Math.abs(n.get(s,s-1))>Math.abs(n.get(s-1,s))?(n.set(s-1,s-1,m/n.get(s,s-1)),n.set(s-1,s,-(n.get(s,s)-c)/n.get(s,s-1))):(k=ro(0,-n.get(s-1,s),n.get(s-1,s-1)-c,m),n.set(s-1,s-1,k[0]),n.set(s-1,s,k[1])),n.set(s,s-1,0),n.set(s,s,1),v=s-2;v>=0;v--){for(C=0,I=0,E=N;E<=s;E++)C=C+n.get(v,E)*n.get(E,s-1),I=I+n.get(v,E)*n.get(E,s);if(M=n.get(v,v)-c,t[v]<0)g=M,_=C,w=I;else if(N=v,t[v]===0?(k=ro(-C,-I,M,m),n.set(v,s-1,k[0]),n.set(v,s,k[1])):(S=n.get(v,v+1),$=n.get(v+1,v),R=(e[v]-c)*(e[v]-c)+t[v]*t[v]-m*m,U=(e[v]-c)*2*m,R===0&&U===0&&(R=f*h*(Math.abs(M)+Math.abs(m)+Math.abs(S)+Math.abs($)+Math.abs(g))),k=ro(S*_-g*C+m*I,S*w-g*I-m*C,R,U),n.set(v,s-1,k[0]),n.set(v,s,k[1]),Math.abs(S)>Math.abs(g)+Math.abs(m)?(n.set(v+1,s-1,(-C-M*n.get(v,s-1)+m*n.get(v,s))/S),n.set(v+1,s,(-I-M*n.get(v,s)-m*n.get(v,s-1))/S)):(k=ro(-_-$*n.get(v,s-1),-w-$*n.get(v,s),g,m),n.set(v+1,s-1,k[0]),n.set(v+1,s,k[1]))),F=Math.max(Math.abs(n.get(v,s-1)),Math.abs(n.get(v,s))),f*F*F>1)for(E=v;E<=s;E++)n.set(E,s-1,n.get(E,s-1)/F),n.set(E,s,n.get(E,s)/F)}for(v=0;v<i;v++)if(v<u||v>l)for(E=v;E<i;E++)r.set(v,E,n.get(v,E));for(E=i-1;E>=u;E--)for(v=u;v<=l;v++){for(g=0,b=u;b<=Math.min(E,l);b++)g=g+r.get(v,b)*n.get(b,E);r.set(v,E,g)}}}function ro(i,t,e,r){let n,s;return Math.abs(e)>Math.abs(r)?(n=r/e,s=e+n*r,[(i+n*t)/s,(t-n*i)/s]):(n=e/r,s=r+n*e,[(n*i+t)/s,(n*t-i)/s])}class Pc{constructor(t){if(t=ir.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");let e=t,r=e.rows,n=new pt(r,r),s=!0,u,l,f;for(l=0;l<r;l++){let p=0;for(f=0;f<l;f++){let h=0;for(u=0;u<f;u++)h+=n.get(f,u)*n.get(l,u);h=(e.get(l,f)-h)/n.get(f,f),n.set(l,f,h),p=p+h*h}for(p=e.get(l,l)-p,s&=p>0,n.set(l,l,Math.sqrt(Math.max(p,0))),f=l+1;f<r;f++)n.set(l,f,0)}this.L=n,this.positiveDefinite=!!s}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=ir.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=t.columns,s=t.clone(),u,l,f;for(f=0;f<r;f++)for(l=0;l<n;l++){for(u=0;u<f;u++)s.set(f,l,s.get(f,l)-s.get(u,l)*e.get(f,u));s.set(f,l,s.get(f,l)/e.get(f,f))}for(f=r-1;f>=0;f--)for(l=0;l<n;l++){for(u=f+1;u<r;u++)s.set(f,l,s.get(f,l)-s.get(u,l)*e.get(u,f));s.set(f,l,s.get(f,l)/e.get(f,f))}return s}get lowerTriangularMatrix(){return this.L}}class zc{constructor(t,e={}){t=ir.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:s=1e3,terminationCriteria:u=1e-10}=e;let l;if(r){if(Je.isAnyArray(r)&&typeof r[0]=="number"?r=pt.columnVector(r):r=ir.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=t.getColumnVector(0);let f=1,p,h,c,m;for(let _=0;_<s&&f>u;_++)c=t.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),c=c.div(c.norm()),p=t.mmul(c).div(c.transpose().mmul(c).get(0,0)),_>0&&(f=p.clone().sub(m).pow(2).sum()),m=p.clone(),r?(h=r.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0)),h=h.div(h.norm()),l=r.mmul(h).div(h.transpose().mmul(h).get(0,0))):l=p;if(r){let _=t.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0));_=_.div(_.norm());let w=t.clone().sub(p.clone().mmul(_.transpose())),g=l.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0)),y=r.clone().sub(p.clone().mulS(g.get(0,0)).mmul(h.transpose()));this.t=p,this.p=_.transpose(),this.w=c.transpose(),this.q=h,this.u=l,this.s=p.transpose().mmul(p),this.xResidual=w,this.yResidual=y,this.betas=g}else this.w=c.transpose(),this.s=p.transpose().mmul(p).sqrt(),n?this.t=p.clone().div(this.s.get(0,0)):this.t=p,this.xResidual=t.sub(p.mmul(c.transpose()))}}Pt.AbstractMatrix=$t,Pt.CHO=Pc,Pt.CholeskyDecomposition=Pc,Pt.DistanceMatrix=Vs,Pt.EVD=Lc;var aw=Pt.EigenvalueDecomposition=Lc;Pt.LU=to,Pt.LuDecomposition=to;var qc=Pt.Matrix=pt;Pt.MatrixColumnSelectionView=k1,Pt.MatrixColumnView=U1,Pt.MatrixFlipColumnView=W1,Pt.MatrixFlipRowView=Y1,Pt.MatrixRowSelectionView=Z1,Pt.MatrixRowView=j1,Pt.MatrixSelectionView=Qs,Pt.MatrixSubView=G1,Pt.MatrixTransposeView=K1,Pt.NIPALS=zc,Pt.Nipals=zc,Pt.QR=Ta,Pt.QrDecomposition=Ta,Pt.SVD=gi,Pt.SingularValueDecomposition=gi,Pt.SymmetricMatrix=kn,Pt.WrapperMatrix1D=Oc,Pt.WrapperMatrix2D=ir,Pt.correlation=rw,Pt.covariance=ew;var Uc=Pt.default=pt;Pt.determinant=eo,Pt.inverse=J1,Pt.linearDependencies=Q1,Pt.pseudoInverse=tw,Pt.solve=Rc,Pt.wrap=H1;const kc=aw,Wc=qc;Uc.Matrix&&Uc.Matrix;class uw{new({rows:t,columns:e,initial_value:r}={}){return new $a(t,e,r)}avg({id:t}){return t==null?void 0:t.avg()}col({id:t,column:e}){return t==null?void 0:t.col({column:e})}det({id:t}){return t==null?void 0:t.det()}get({id:t,row:e,column:r}){return t==null?void 0:t.get({row:e,column:r})}inv({id:t}){return t==null?void 0:t.inv()}max({id:t}){return t==null?void 0:t.max()}min({id:t}){return t==null?void 0:t.min()}pow({id:t,power:e}){return t==null?void 0:t.pow({power:e})}row({id:t,row:e}){return t==null?void 0:t.row({row:e})}set({id:t,row:e,column:r,value:n}){t==null||t.set({row:e,column:r,value:n})}sum({id:t,id2:e}){return t==null?void 0:t.sum({id2:e})}copy({id:t}){return t==null?void 0:t.copy()}diff({id:t,id2:e}){return t==null?void 0:t.diff({id2:e})}rows({id:t}){return t==null?void 0:t.rows()}columns({id:t}){return t==null?void 0:t.columns()}fill({id:t,value:e,from_row:r,to_row:n,from_column:s,to_column:u}){t==null||t.fill({value:e,from_row:r,to_row:n,from_column:s,to_column:u})}kron({id:t,id2:e}){return t==null?void 0:t.kron({id2:e})}mode({id:t}){return t==null?void 0:t.mode()}mult({id:t,id2:e}){return t==null?void 0:t.mult({id2:e})}pinv({id:t}){return t==null?void 0:t.pinv()}rank({id:t}){return t==null?void 0:t.rank()}sort({id:t,column:e,order:r}){t==null||t.sort({column:e,order:r})}trace({id:t}){return t==null?void 0:t.trace()}concat({id:t,id2:e}){return t==null?void 0:t.concat({id2:e})}median({id:t}){return t==null?void 0:t.median()}add_col({id:t,column:e,array_id:r}){t==null||t.add_col({column:e,array_id:r})}add_row({id:t,row:e,array_id:r}){t==null||t.add_row({row:e,array_id:r})}is_zero({id:t}){return t==null?void 0:t.is_zero()}reshape({id:t,rows:e,columns:r}){return t==null?void 0:t.reshape({rows:e,columns:r})}reverse({id:t}){t==null||t.reverse()}is_binary({id:t}){return t==null?void 0:t.is_binary()}is_square({id:t}){return t==null?void 0:t.is_square()}submatrix({id:t,from_row:e,to_row:r,from_column:n,to_column:s}){return t==null?void 0:t.submatrix({from_row:e,to_row:r,from_column:n,to_column:s})}swap_rows({id:t,row1:e,row2:r}){t==null||t.swap_rows({row1:e,row2:r})}transpose({id:t}){return t==null?void 0:t.transpose()}remove_col({id:t,column:e}){return t==null?void 0:t.remove_col({column:e})}remove_row({id:t,row:e}){return t==null?void 0:t.remove_row({row:e})}eigenvalues({id:t}){return t==null?void 0:t.eigenvalues()}is_diagonal({id:t}){return t==null?void 0:t.is_diagonal()}is_identity({id:t}){return t==null?void 0:t.is_identity()}eigenvectors({id:t}){return t==null?void 0:t.eigenvectors()}is_symmetric({id:t}){return t==null?void 0:t.is_symmetric()}swap_columns({id:t,column1:e,column2:r}){t==null||t.swap_columns({column1:e,column2:r})}is_stochastic({id:t}){return t==null?void 0:t.is_stochastic()}is_triangular({id:t}){return t==null?void 0:t.is_triangular()}elements_count({id:t}){return t==null?void 0:t.elements_count()}is_antidiagonal({id:t}){return t==null?void 0:t.is_antidiagonal()}is_antisymmetric({id:t}){return t==null?void 0:t.is_antisymmetric()}}class $a{constructor(t=0,e=0,r=void 0){Z(this,"_matrixInstance");this._matrixInstance=this._createMatrix(t,e,r)}get _matrixArray(){return this._matrixInstance.map(t=>[...t._value])}get _value(){return this._matrixInstance}set _value(t){this._matrixInstance=t}get isMatrix(){return!0}_createMatrix(t,e,r){return Array.from(new Array(t),()=>new Jt(e,r))}avg(){let t=0,e=0;for(const n of this._matrixInstance)for(const s of n._value)t+=s,e+=1;return t/e}col({column:t=0}){const e=[];for(const n of this._matrixInstance)e.push(n._value[t]);const r=new Jt;return r._value=e,r}det(){return Mc(this._matrixArray)}get({row:t=0,column:e=0}){var r,n;return(n=(r=this._matrixInstance[t])==null?void 0:r._value)==null?void 0:n[e]}inv(){const t=Ks(this._matrixArray);return this._newMatrix(t)}max(){return e1(this._matrixArray)}min(){return Na(this._matrixArray)}pow({power:t}){const e=n1(this._matrixArray,t);return this._newMatrix(e)}row({row:t=0}){return this._matrixInstance[t]}set({row:t,column:e,value:r}){this._matrixInstance[t]._value[e]=r}sum({id2:t}){const e=Zi(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:t}){const e=H_(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:t,from_row:e=0,to_row:r=this.rows(),from_column:n=0,to_column:s=this.columns()}={}){for(const[u,l]of this._matrixInstance.entries())for(const[f]of l._value.entries())u<r&&u>=e&&f>=n&&f<s&&(l._value[f]=t)}kron({id2:t}){const e=G_(this._matrixArray,t._matrixArray);return this._newMatrix(e)}mode(){return Na(yc(this._matrixArray))}mult({id2:t}){const e=typeof t=="number"?t:t._matrixArray?t._matrixArray:t._value,r=ci(this._matrixArray,e);return this._newMatrix(r)}pinv(){const t=r1(this._matrixArray);return this._newMatrix(t)}rank(){return this._matrixRank(this._matrixArray)}sort({column:t=0,order:e=Rn.ascending}={}){this._matrixInstance.sort((r,n)=>{const s=r._value[t],u=n._value[t];return e!==Rn.descending?s-u:u-s})}trace(){return t1(this._matrixArray)}concat({id2:t}){for(const e of t._value)this._matrixInstance.push(e);return this}median(){return Nc(this._matrixArray)}add_col({column:t=this.columns(),array_id:e}={}){for(const[r,n]of this._matrixInstance.entries())n._value[t]=e?e._value[r]:void 0}add_row({row:t,array_id:e}){this._matrixInstance.splice(t||this.rows(),0,e||new Jt(this.columns()))}is_zero(){return this._matrixArray.every(t=>t.every(e=>e===0))}reshape({rows:t,columns:e}){const r=W_(this._matrixArray,[t,e]);this._matrixInstance=r.map(n=>{const s=new Jt;return s._value=[...n],s})}reverse(){this._matrixInstance.reverse();for(const t of this._matrixInstance)t._value.reverse()}is_binary(){return this._matrixArray.every(t=>t.every(e=>e===0||e===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:t=0,to_row:e=this.rows(),from_column:r=0,to_column:n=this.columns()}={}){const s=this._matrixArray.splice(t,e-1),u=[];for(const l of s)u.push(l.splice(r,n-1));return this._newMatrix(u)}swap_rows({row1:t,row2:e}){const r=this._matrixInstance[t],n=this._matrixInstance[e];this._matrixInstance[t]=n,this._matrixInstance[e]=r}transpose(){const t=Ec(this._matrixArray);return this._newMatrix(t)}remove_col({column:t=this.columns()}={}){const e=[];for(const n of this._matrixInstance){const s=n._value.splice(t,1);e.push(s[0])}const r=new Jt;return r._value=e,r}remove_row({row:t=this.rows()}={}){return this._matrixInstance.splice(t,1)[0]}eigenvalues(){const t=new kc(new Wc(this._matrixArray)),e=new Jt;return e._value=t.realEigenvalues,e}is_diagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0)return!1;return!0}is_identity(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0||n===s&&r[n][s]!==1)return!1;return!0}eigenvectors(){const t=new kc(new Wc(this._matrixArray));return this._newMatrix(t.eigenvectorMatrix.to2DArray())}is_symmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=n+1;s<e;s++)if(r[n][s]!==r[s][n])return!1;return!0}swap_columns({column1:t,column2:e}){for(const r of this._matrixInstance){const n=r._value[t],s=r._value[e];r._value[t]=s,r._value[e]=n}}is_stochastic(){const t=this._matrixArray;for(let e=0;e<t.length;e++){let r=0;for(let n=0;n<t[e].length;n++){if(t[e][n]<0)return!1;r+=t[e][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const t=this.rows(),e=this.columns();return t!==e?!1:this._isUpperTriangular(t)||this._isLowerTriangular(t)}elements_count(){return Y_(this._matrixArray)}is_antidiagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n+s!==t-1&&r[n][s]!==0)return!1;return!0}is_antisymmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n!==s&&r[n][s]!==-r[s][n])return!1;return!0}_isUpperTriangular(t){const e=this._matrixArray;for(let r=1;r<t;r++)for(let n=0;n<r;n++)if(e[r][n]!==0)return!1;return!0}_isLowerTriangular(t){const e=this._matrixArray;for(let r=0;r<t-1;r++)for(let n=r+1;n<t;n++)if(e[r][n]!==0)return!1;return!0}_newMatrix(t){const e=new $a;return e._value=t.map(r=>{const n=new Jt;return n._value=[...r],n}),e}_matrixRank(t){let e=0;const r=t.length,n=t[0].length,s=[...t].map(u=>[...u]);for(let u=0;u<r&&!(u>=n);u++){let l=u;for(;l<r&&s[l][u]===0;)l++;if(l===r)continue;if(l!==u){const p=s[l];s[l]=s[u],s[u]=p}const f=s[u][u];for(let p=0;p<n;p++)s[u][p]/=f;for(let p=u+1;p<r;p++){const h=s[p][u];s[p]=s[p].map((c,m)=>c-h*s[u][m]),s[p][u]=0}}for(let u=0;u<r;u++)s[u].some(l=>Number(l.toFixed(8))!==0)&&e++;return e}}class lw{constructor(t){Z(this,"_variables");Z(this,"_cacheData");this._variables=t,this._cacheData={}}change({timeframe:t},e){const r=Tn(t),n=Tn(this._variables.timeframe.period);if(r<n)return!0;const s=`change_${e}`,u=this._cacheData[s],l=this._variables.time*1e3;if(u){if(u.offset){if(u.currentTime+u.offset<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else if(u.currentTime+r*1e3<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else{const f=this._calcTimeOffset(l,t);return this._cacheData[s]={currentTime:l,offset:f},!1}return!1}in_seconds({timeframe:t}={}){return Tn(t||this._variables.timeframe.period)}from_seconds({seconds:t=0}){const e=t*1e3,r=ne.duration(e);if(r.years())return"12M";const s=r.asMonths();if(Zs(s))return`${s}M`;const u=r.asWeeks();if(Zs(u))return`${u}M`;const l=r.asDays();if(l>=1)return`${Math.ceil(l)}D`;const f=r.asMinutes();if(f>=1)return`${Math.ceil(f)}`;const p=r.asSeconds();return p<=1?"1S":p<=5?"5S":p<=10?"10S":p<=15?"15S":p<=30?"30S":"1"}_calcTimeOffset(t,e){let r=0;if(e.includes("W")){const l=ne(t).day();e="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(e.includes("M")){const l=ne(t).date();e="1D";const f=ne(t).daysInMonth();l!==1&&(r=(f-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(t,e),s=Tn(e)*1e3,u=t-n-Math.floor((t-n)/s)*s;return r?r-u:u}}class fw{pos({source:t,str:e}){return t==null?void 0:t.indexOf(e)}trim({source:t}){return t==null?void 0:t.trim()}lower({source:t}){return t==null?void 0:t.toLocaleLowerCase()}match({source:t,regex:e}){const r=t==null?void 0:t.match(new RegExp(e));return r?r[0]:""}split({string:t,separator:e}){const r=t==null?void 0:t.split(e),n=new Jt;return n._value=r||[],n}upper({source:t}){return t==null?void 0:t.toLocaleUpperCase()}format({formatString:t},e){return this._strFormat(t,e)}length({string:t}){return t==null?void 0:t.length}repeat({source:t,repeat:e=0,separator:r=""}){return Array.from(new Array(e),()=>t).join(r)}replace({source:t,target:e,replacement:r,occurrence:n=0}){let s=-1;for(let u=0;u<n+1&&(s=t.indexOf(e,s+1),s!==-1);u++);return s!==-1?t.substring(0,s)+r+t.substring(s+e.length):t}contains({source:t,str:e}){return t==null?void 0:t.includes(e)}endswith({source:t,str:e}){return t==null?void 0:t.endsWith(e)}tonumber({string:t}){if(/[^\d.]/.test(t))return;const e=parseFloat(t);return isNaN(e)?void 0:e}tostring({value:t,format:e}){if(t===void 0)return"NaN";if(typeof t=="object"){if(t.isArray)return this._arrToStr(t._value,e);if(t.isMatrix){const r=[];for(const n of t._matrixArray)r.push(this._arrToStr(n,e));return r.join(`
61
+ ${Bc}`)}function D1(i,t,e){return(i>=0&&e?` ${Tc(i,t-1)}`:Tc(i,t)).padEnd(t)}function Tc(i,t){let e=i.toString();if(e.length<=t)return e;let r=i.toFixed(t);if(r.length>t&&(r=i.toFixed(Math.max(0,t-(r.length-t)))),r.length<=t&&!r.startsWith("0.000")&&!r.startsWith("-0.000"))return r;let n=i.toExponential(t);return n.length>t&&(n=i.toExponential(Math.max(0,t-(n.length-t)))),n.slice(0)}function y1(i,t){i.prototype.add=function(r){return typeof r=="number"?this.addS(r):this.addM(r)},i.prototype.addS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r);return this},i.prototype.addM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)+r.get(n,s));return this},i.add=function(r,n){return new t(r).add(n)},i.prototype.sub=function(r){return typeof r=="number"?this.subS(r):this.subM(r)},i.prototype.subS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r);return this},i.prototype.subM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)-r.get(n,s));return this},i.sub=function(r,n){return new t(r).sub(n)},i.prototype.subtract=i.prototype.sub,i.prototype.subtractS=i.prototype.subS,i.prototype.subtractM=i.prototype.subM,i.subtract=i.sub,i.prototype.mul=function(r){return typeof r=="number"?this.mulS(r):this.mulM(r)},i.prototype.mulS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r);return this},i.prototype.mulM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)*r.get(n,s));return this},i.mul=function(r,n){return new t(r).mul(n)},i.prototype.multiply=i.prototype.mul,i.prototype.multiplyS=i.prototype.mulS,i.prototype.multiplyM=i.prototype.mulM,i.multiply=i.mul,i.prototype.div=function(r){return typeof r=="number"?this.divS(r):this.divM(r)},i.prototype.divS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r);return this},i.prototype.divM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)/r.get(n,s));return this},i.div=function(r,n){return new t(r).div(n)},i.prototype.divide=i.prototype.div,i.prototype.divideS=i.prototype.divS,i.prototype.divideM=i.prototype.divM,i.divide=i.div,i.prototype.mod=function(r){return typeof r=="number"?this.modS(r):this.modM(r)},i.prototype.modS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r);return this},i.prototype.modM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)%r.get(n,s));return this},i.mod=function(r,n){return new t(r).mod(n)},i.prototype.modulus=i.prototype.mod,i.prototype.modulusS=i.prototype.modS,i.prototype.modulusM=i.prototype.modM,i.modulus=i.mod,i.prototype.and=function(r){return typeof r=="number"?this.andS(r):this.andM(r)},i.prototype.andS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r);return this},i.prototype.andM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)&r.get(n,s));return this},i.and=function(r,n){return new t(r).and(n)},i.prototype.or=function(r){return typeof r=="number"?this.orS(r):this.orM(r)},i.prototype.orS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r);return this},i.prototype.orM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)|r.get(n,s));return this},i.or=function(r,n){return new t(r).or(n)},i.prototype.xor=function(r){return typeof r=="number"?this.xorS(r):this.xorM(r)},i.prototype.xorS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r);return this},i.prototype.xorM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)^r.get(n,s));return this},i.xor=function(r,n){return new t(r).xor(n)},i.prototype.leftShift=function(r){return typeof r=="number"?this.leftShiftS(r):this.leftShiftM(r)},i.prototype.leftShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r);return this},i.prototype.leftShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)<<r.get(n,s));return this},i.leftShift=function(r,n){return new t(r).leftShift(n)},i.prototype.signPropagatingRightShift=function(r){return typeof r=="number"?this.signPropagatingRightShiftS(r):this.signPropagatingRightShiftM(r)},i.prototype.signPropagatingRightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r);return this},i.prototype.signPropagatingRightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>r.get(n,s));return this},i.signPropagatingRightShift=function(r,n){return new t(r).signPropagatingRightShift(n)},i.prototype.rightShift=function(r){return typeof r=="number"?this.rightShiftS(r):this.rightShiftM(r)},i.prototype.rightShiftS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r);return this},i.prototype.rightShiftM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,this.get(n,s)>>>r.get(n,s));return this},i.rightShift=function(r,n){return new t(r).rightShift(n)},i.prototype.zeroFillRightShift=i.prototype.rightShift,i.prototype.zeroFillRightShiftS=i.prototype.rightShiftS,i.prototype.zeroFillRightShiftM=i.prototype.rightShiftM,i.zeroFillRightShift=i.rightShift,i.prototype.not=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,~this.get(r,n));return this},i.not=function(r){return new t(r).not()},i.prototype.abs=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.abs(this.get(r,n)));return this},i.abs=function(r){return new t(r).abs()},i.prototype.acos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acos(this.get(r,n)));return this},i.acos=function(r){return new t(r).acos()},i.prototype.acosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.acosh(this.get(r,n)));return this},i.acosh=function(r){return new t(r).acosh()},i.prototype.asin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asin(this.get(r,n)));return this},i.asin=function(r){return new t(r).asin()},i.prototype.asinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.asinh(this.get(r,n)));return this},i.asinh=function(r){return new t(r).asinh()},i.prototype.atan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atan(this.get(r,n)));return this},i.atan=function(r){return new t(r).atan()},i.prototype.atanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.atanh(this.get(r,n)));return this},i.atanh=function(r){return new t(r).atanh()},i.prototype.cbrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cbrt(this.get(r,n)));return this},i.cbrt=function(r){return new t(r).cbrt()},i.prototype.ceil=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.ceil(this.get(r,n)));return this},i.ceil=function(r){return new t(r).ceil()},i.prototype.clz32=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.clz32(this.get(r,n)));return this},i.clz32=function(r){return new t(r).clz32()},i.prototype.cos=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cos(this.get(r,n)));return this},i.cos=function(r){return new t(r).cos()},i.prototype.cosh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.cosh(this.get(r,n)));return this},i.cosh=function(r){return new t(r).cosh()},i.prototype.exp=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.exp(this.get(r,n)));return this},i.exp=function(r){return new t(r).exp()},i.prototype.expm1=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.expm1(this.get(r,n)));return this},i.expm1=function(r){return new t(r).expm1()},i.prototype.floor=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.floor(this.get(r,n)));return this},i.floor=function(r){return new t(r).floor()},i.prototype.fround=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.fround(this.get(r,n)));return this},i.fround=function(r){return new t(r).fround()},i.prototype.log=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log(this.get(r,n)));return this},i.log=function(r){return new t(r).log()},i.prototype.log1p=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log1p(this.get(r,n)));return this},i.log1p=function(r){return new t(r).log1p()},i.prototype.log10=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log10(this.get(r,n)));return this},i.log10=function(r){return new t(r).log10()},i.prototype.log2=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.log2(this.get(r,n)));return this},i.log2=function(r){return new t(r).log2()},i.prototype.round=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.round(this.get(r,n)));return this},i.round=function(r){return new t(r).round()},i.prototype.sign=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sign(this.get(r,n)));return this},i.sign=function(r){return new t(r).sign()},i.prototype.sin=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sin(this.get(r,n)));return this},i.sin=function(r){return new t(r).sin()},i.prototype.sinh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sinh(this.get(r,n)));return this},i.sinh=function(r){return new t(r).sinh()},i.prototype.sqrt=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.sqrt(this.get(r,n)));return this},i.sqrt=function(r){return new t(r).sqrt()},i.prototype.tan=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tan(this.get(r,n)));return this},i.tan=function(r){return new t(r).tan()},i.prototype.tanh=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.tanh(this.get(r,n)));return this},i.tanh=function(r){return new t(r).tanh()},i.prototype.trunc=function(){for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.set(r,n,Math.trunc(this.get(r,n)));return this},i.trunc=function(r){return new t(r).trunc()},i.pow=function(r,n){return new t(r).pow(n)},i.prototype.pow=function(r){return typeof r=="number"?this.powS(r):this.powM(r)},i.prototype.powS=function(r){for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r));return this},i.prototype.powM=function(r){if(r=t.checkMatrix(r),this.rows!==r.rows||this.columns!==r.columns)throw new RangeError("Matrices dimensions must be equal");for(let n=0;n<this.rows;n++)for(let s=0;s<this.columns;s++)this.set(n,s,Math.pow(this.get(n,s),r.get(n,s)));return this}}function vr(i,t,e){let r=e?i.rows:i.rows-1;if(t<0||t>r)throw new RangeError("Row index out of range")}function _r(i,t,e){let r=e?i.columns:i.columns-1;if(t<0||t>r)throw new RangeError("Column index out of range")}function pi(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.columns)throw new RangeError("vector size must be the same as the number of columns");return t}function di(i,t){if(t.to1DArray&&(t=t.to1DArray()),t.length!==i.rows)throw new RangeError("vector size must be the same as the number of rows");return t}function Sa(i,t){if(!Je.isAnyArray(t))throw new TypeError("row indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.rows)throw new RangeError("row indices are out of range")}function Ba(i,t){if(!Je.isAnyArray(t))throw new TypeError("column indices must be an array");for(let e=0;e<t.length;e++)if(t[e]<0||t[e]>=i.columns)throw new RangeError("column indices are out of range")}function Ia(i,t,e,r,n){if(arguments.length!==5)throw new RangeError("expected 4 arguments");if(Xs("startRow",t),Xs("endRow",e),Xs("startColumn",r),Xs("endColumn",n),t>e||r>n||t<0||t>=i.rows||e<0||e>=i.rows||r<0||r>=i.columns||n<0||n>=i.columns)throw new RangeError("Submatrix indices are out of range")}function Js(i,t=0){let e=[];for(let r=0;r<i;r++)e.push(t);return e}function Xs(i,t){if(typeof t!="number")throw new TypeError(`${i} must be a number`)}function mi(i){if(i.isEmpty())throw new Error("Empty matrix has no elements to index")}function b1(i){let t=Js(i.rows);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]+=i.get(e,r);return t}function E1(i){let t=Js(i.columns);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]+=i.get(e,r);return t}function A1(i){let t=0;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t+=i.get(e,r);return t}function x1(i){let t=Js(i.rows,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[e]*=i.get(e,r);return t}function C1(i){let t=Js(i.columns,1);for(let e=0;e<i.rows;++e)for(let r=0;r<i.columns;++r)t[r]*=i.get(e,r);return t}function F1(i){let t=1;for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)t*=i.get(e,r);return t}function M1(i,t,e){const r=i.rows,n=i.columns,s=[];for(let u=0;u<r;u++){let l=0,f=0,p=0;for(let h=0;h<n;h++)p=i.get(u,h)-e[u],l+=p,f+=p*p;t?s.push((f-l*l/n)/(n-1)):s.push((f-l*l/n)/n)}return s}function N1(i,t,e){const r=i.rows,n=i.columns,s=[];for(let u=0;u<n;u++){let l=0,f=0,p=0;for(let h=0;h<r;h++)p=i.get(h,u)-e[u],l+=p,f+=p*p;t?s.push((f-l*l/r)/(r-1)):s.push((f-l*l/r)/r)}return s}function S1(i,t,e){const r=i.rows,n=i.columns,s=r*n;let u=0,l=0,f=0;for(let p=0;p<r;p++)for(let h=0;h<n;h++)f=i.get(p,h)-e,u+=f,l+=f*f;return t?(l-u*u/s)/(s-1):(l-u*u/s)/s}function B1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[e])}function I1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t[r])}function T1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)-t)}function $1(i){const t=[];for(let e=0;e<i.rows;e++){let r=0;for(let n=0;n<i.columns;n++)r+=Math.pow(i.get(e,n),2)/(i.columns-1);t.push(Math.sqrt(r))}return t}function O1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[e])}function R1(i){const t=[];for(let e=0;e<i.columns;e++){let r=0;for(let n=0;n<i.rows;n++)r+=Math.pow(i.get(n,e),2)/(i.rows-1);t.push(Math.sqrt(r))}return t}function L1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t[r])}function P1(i){const t=i.size-1;let e=0;for(let r=0;r<i.columns;r++)for(let n=0;n<i.rows;n++)e+=Math.pow(i.get(n,r),2)/t;return Math.sqrt(e)}function z1(i,t){for(let e=0;e<i.rows;e++)for(let r=0;r<i.columns;r++)i.set(e,r,i.get(e,r)/t)}class $t{static from1DArray(t,e,r){if(t*e!==r.length)throw new RangeError("data length does not match given dimensions");let s=new pt(t,e);for(let u=0;u<t;u++)for(let l=0;l<e;l++)s.set(u,l,r[u*e+l]);return s}static rowVector(t){let e=new pt(1,t.length);for(let r=0;r<t.length;r++)e.set(0,r,t[r]);return e}static columnVector(t){let e=new pt(t.length,1);for(let r=0;r<t.length;r++)e.set(r,0,t[r]);return e}static zeros(t,e){return new pt(t,e)}static ones(t,e){return new pt(t,e).fill(1)}static rand(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{random:n=Math.random}=r;let s=new pt(t,e);for(let u=0;u<t;u++)for(let l=0;l<e;l++)s.set(u,l,n());return s}static randInt(t,e,r={}){if(typeof r!="object")throw new TypeError("options must be an object");const{min:n=0,max:s=1e3,random:u=Math.random}=r;if(!Number.isInteger(n))throw new TypeError("min must be an integer");if(!Number.isInteger(s))throw new TypeError("max must be an integer");if(n>=s)throw new RangeError("min must be smaller than max");let l=s-n,f=new pt(t,e);for(let p=0;p<t;p++)for(let h=0;h<e;h++){let c=n+Math.round(u()*l);f.set(p,h,c)}return f}static eye(t,e,r){e===void 0&&(e=t),r===void 0&&(r=1);let n=Math.min(t,e),s=this.zeros(t,e);for(let u=0;u<n;u++)s.set(u,u,r);return s}static diag(t,e,r){let n=t.length;e===void 0&&(e=n),r===void 0&&(r=e);let s=Math.min(n,e,r),u=this.zeros(e,r);for(let l=0;l<s;l++)u.set(l,l,t[l]);return u}static min(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new pt(r,n);for(let u=0;u<r;u++)for(let l=0;l<n;l++)s.set(u,l,Math.min(t.get(u,l),e.get(u,l)));return s}static max(t,e){t=this.checkMatrix(t),e=this.checkMatrix(e);let r=t.rows,n=t.columns,s=new this(r,n);for(let u=0;u<r;u++)for(let l=0;l<n;l++)s.set(u,l,Math.max(t.get(u,l),e.get(u,l)));return s}static checkMatrix(t){return $t.isMatrix(t)?t:new pt(t)}static isMatrix(t){return t!=null&&t.klass==="Matrix"}get size(){return this.rows*this.columns}apply(t){if(typeof t!="function")throw new TypeError("callback must be a function");for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.call(this,e,r);return this}to1DArray(){let t=[];for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.push(this.get(e,r));return t}to2DArray(){let t=[];for(let e=0;e<this.rows;e++){t.push([]);for(let r=0;r<this.columns;r++)t[e].push(this.get(e,r))}return t}toJSON(){return this.to2DArray()}isRowVector(){return this.rows===1}isColumnVector(){return this.columns===1}isVector(){return this.rows===1||this.columns===1}isSquare(){return this.rows===this.columns}isEmpty(){return this.rows===0||this.columns===0}isSymmetric(){if(this.isSquare()){for(let t=0;t<this.rows;t++)for(let e=0;e<=t;e++)if(this.get(t,e)!==this.get(e,t))return!1;return!0}return!1}isDistance(){if(!this.isSymmetric())return!1;for(let t=0;t<this.rows;t++)if(this.get(t,t)!==0)return!1;return!0}isEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);t++}return n}isReducedEchelonForm(){let t=0,e=0,r=-1,n=!0,s=!1;for(;t<this.rows&&n;){for(e=0,s=!1;e<this.columns&&s===!1;)this.get(t,e)===0?e++:this.get(t,e)===1&&e>r?(s=!0,r=e):(n=!1,s=!0);for(let u=e+1;u<this.rows;u++)this.get(t,u)!==0&&(n=!1);t++}return n}echelonForm(){let t=this.clone(),e=0,r=0;for(;e<t.rows&&r<t.columns;){let n=e;for(let s=e;s<t.rows;s++)t.get(s,r)>t.get(n,r)&&(n=s);if(t.get(n,r)===0)r++;else{t.swapRows(e,n);let s=t.get(e,r);for(let u=r;u<t.columns;u++)t.set(e,u,t.get(e,u)/s);for(let u=e+1;u<t.rows;u++){let l=t.get(u,r)/t.get(e,r);t.set(u,r,0);for(let f=r+1;f<t.columns;f++)t.set(u,f,t.get(u,f)-t.get(e,f)*l)}e++,r++}}return t}reducedEchelonForm(){let t=this.echelonForm(),e=t.columns,r=t.rows,n=r-1;for(;n>=0;)if(t.maxRow(n)===0)n--;else{let s=0,u=!1;for(;s<r&&u===!1;)t.get(n,s)===1?u=!0:s++;for(let l=0;l<n;l++){let f=t.get(l,s);for(let p=s;p<e;p++){let h=t.get(l,p)-f*t.get(n,p);t.set(l,p,h)}}n--}return t}set(){throw new Error("set method is unimplemented")}get(){throw new Error("get method is unimplemented")}repeat(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{rows:e=1,columns:r=1}=t;if(!Number.isInteger(e)||e<=0)throw new TypeError("rows must be a positive integer");if(!Number.isInteger(r)||r<=0)throw new TypeError("columns must be a positive integer");let n=new pt(this.rows*e,this.columns*r);for(let s=0;s<e;s++)for(let u=0;u<r;u++)n.setSubMatrix(this,this.rows*s,this.columns*u);return n}fill(t){for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,t);return this}neg(){return this.mulS(-1)}getRow(t){vr(this,t);let e=[];for(let r=0;r<this.columns;r++)e.push(this.get(t,r));return e}getRowVector(t){return pt.rowVector(this.getRow(t))}setRow(t,e){vr(this,t),e=pi(this,e);for(let r=0;r<this.columns;r++)this.set(t,r,e[r]);return this}swapRows(t,e){vr(this,t),vr(this,e);for(let r=0;r<this.columns;r++){let n=this.get(t,r);this.set(t,r,this.get(e,r)),this.set(e,r,n)}return this}getColumn(t){_r(this,t);let e=[];for(let r=0;r<this.rows;r++)e.push(this.get(r,t));return e}getColumnVector(t){return pt.columnVector(this.getColumn(t))}setColumn(t,e){_r(this,t),e=di(this,e);for(let r=0;r<this.rows;r++)this.set(r,t,e[r]);return this}swapColumns(t,e){_r(this,t),_r(this,e);for(let r=0;r<this.rows;r++){let n=this.get(r,t);this.set(r,t,this.get(r,e)),this.set(r,e,n)}return this}addRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[r]);return this}subRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[r]);return this}mulRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[r]);return this}divRowVector(t){t=pi(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[r]);return this}addColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)+t[e]);return this}subColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)-t[e]);return this}mulColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)*t[e]);return this}divColumnVector(t){t=di(this,t);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)this.set(e,r,this.get(e,r)/t[e]);return this}mulRow(t,e){vr(this,t);for(let r=0;r<this.columns;r++)this.set(t,r,this.get(t,r)*e);return this}mulColumn(t,e){_r(this,t);for(let r=0;r<this.rows;r++)this.set(r,t,this.get(r,t)*e);return this}max(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.NEGATIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}maxIndex(){mi(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)>t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}min(t){if(this.isEmpty())return NaN;switch(t){case"row":{const e=new Array(this.rows).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[r]&&(e[r]=this.get(r,n));return e}case"column":{const e=new Array(this.columns).fill(Number.POSITIVE_INFINITY);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e[n]&&(e[n]=this.get(r,n));return e}case void 0:{let e=this.get(0,0);for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<e&&(e=this.get(r,n));return e}default:throw new Error(`invalid option: ${t}`)}}minIndex(){mi(this);let t=this.get(0,0),e=[0,0];for(let r=0;r<this.rows;r++)for(let n=0;n<this.columns;n++)this.get(r,n)<t&&(t=this.get(r,n),e[0]=r,e[1]=n);return e}maxRow(t){if(vr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)>e&&(e=this.get(t,r));return e}maxRowIndex(t){vr(this,t),mi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)>e&&(e=this.get(t,n),r[1]=n);return r}minRow(t){if(vr(this,t),this.isEmpty())return NaN;let e=this.get(t,0);for(let r=1;r<this.columns;r++)this.get(t,r)<e&&(e=this.get(t,r));return e}minRowIndex(t){vr(this,t),mi(this);let e=this.get(t,0),r=[t,0];for(let n=1;n<this.columns;n++)this.get(t,n)<e&&(e=this.get(t,n),r[1]=n);return r}maxColumn(t){if(_r(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)>e&&(e=this.get(r,t));return e}maxColumnIndex(t){_r(this,t),mi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)>e&&(e=this.get(n,t),r[0]=n);return r}minColumn(t){if(_r(this,t),this.isEmpty())return NaN;let e=this.get(0,t);for(let r=1;r<this.rows;r++)this.get(r,t)<e&&(e=this.get(r,t));return e}minColumnIndex(t){_r(this,t),mi(this);let e=this.get(0,t),r=[0,t];for(let n=1;n<this.rows;n++)this.get(n,t)<e&&(e=this.get(n,t),r[0]=n);return r}diag(){let t=Math.min(this.rows,this.columns),e=[];for(let r=0;r<t;r++)e.push(this.get(r,r));return e}norm(t="frobenius"){switch(t){case"max":return this.max();case"frobenius":return Math.sqrt(this.dot(this));default:throw new RangeError(`unknown norm type: ${t}`)}}cumulativeSum(){let t=0;for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t+=this.get(e,r),this.set(e,r,t);return this}dot(t){$t.isMatrix(t)&&(t=t.to1DArray());let e=this.to1DArray();if(e.length!==t.length)throw new RangeError("vectors do not have the same size");let r=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n];return r}mmul(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.columns,s=new pt(e,n),u=new Float64Array(r);for(let l=0;l<n;l++){for(let f=0;f<r;f++)u[f]=t.get(f,l);for(let f=0;f<e;f++){let p=0;for(let h=0;h<r;h++)p+=this.get(f,h)*u[h];s.set(f,l,p)}}return s}strassen2x2(t){t=pt.checkMatrix(t);let e=new pt(2,2);const r=this.get(0,0),n=t.get(0,0),s=this.get(0,1),u=t.get(0,1),l=this.get(1,0),f=t.get(1,0),p=this.get(1,1),h=t.get(1,1),c=(r+p)*(n+h),m=(l+p)*n,_=r*(u-h),w=p*(f-n),g=(r+s)*h,y=(l-r)*(n+u),v=(s-p)*(f+h),E=c+w-g+v,b=_+g,N=m+w,x=c-m+_+y;return e.set(0,0,E),e.set(0,1,b),e.set(1,0,N),e.set(1,1,x),e}strassen3x3(t){t=pt.checkMatrix(t);let e=new pt(3,3);const r=this.get(0,0),n=this.get(0,1),s=this.get(0,2),u=this.get(1,0),l=this.get(1,1),f=this.get(1,2),p=this.get(2,0),h=this.get(2,1),c=this.get(2,2),m=t.get(0,0),_=t.get(0,1),w=t.get(0,2),g=t.get(1,0),y=t.get(1,1),v=t.get(1,2),E=t.get(2,0),b=t.get(2,1),N=t.get(2,2),x=(r+n+s-u-l-h-c)*y,F=(r-u)*(-_+y),M=l*(-m+_+g-y-v-E+N),S=(-r+u+l)*(m-_+y),$=(u+l)*(-m+_),C=r*m,I=(-r+p+h)*(m-w+v),R=(-r+p)*(w-v),U=(p+h)*(-m+w),q=(r+n+s-l-f-p-h)*v,k=h*(-m+w+g-y-v-E+b),P=(-s+h+c)*(y+E-b),K=(s-c)*(y-b),G=s*E,V=(h+c)*(-E+b),tt=(-s+l+f)*(v+E-N),ft=(s-f)*(v-N),vt=(l+f)*(-E+N),lt=n*g,wt=f*b,yt=u*w,St=p*_,bt=c*N,ee=C+G+lt,It=x+S+$+C+P+G+V,Mt=C+I+U+q+G+tt+vt,ie=F+M+S+C+G+tt+ft,Xt=F+S+$+C+wt,zt=G+tt+ft+vt+yt,Gt=C+I+R+k+P+K+G,Ce=P+K+G+V+St,sr=C+I+R+U+bt;return e.set(0,0,ee),e.set(0,1,It),e.set(0,2,Mt),e.set(1,0,ie),e.set(1,1,Xt),e.set(1,2,zt),e.set(2,0,Gt),e.set(2,1,Ce),e.set(2,2,sr),e}mmulStrassen(t){t=pt.checkMatrix(t);let e=this.clone(),r=e.rows,n=e.columns,s=t.rows,u=t.columns;n!==s&&console.warn(`Multiplying ${r} x ${n} and ${s} x ${u} matrix: dimensions do not match.`);function l(c,m,_){let w=c.rows,g=c.columns;if(w===m&&g===_)return c;{let y=$t.zeros(m,_);return y=y.setSubMatrix(c,0,0),y}}let f=Math.max(r,s),p=Math.max(n,u);e=l(e,f,p),t=l(t,f,p);function h(c,m,_,w){if(_<=512||w<=512)return c.mmul(m);_%2===1&&w%2===1?(c=l(c,_+1,w+1),m=l(m,_+1,w+1)):_%2===1?(c=l(c,_+1,w),m=l(m,_+1,w)):w%2===1&&(c=l(c,_,w+1),m=l(m,_,w+1));let g=parseInt(c.rows/2,10),y=parseInt(c.columns/2,10),v=c.subMatrix(0,g-1,0,y-1),E=m.subMatrix(0,g-1,0,y-1),b=c.subMatrix(0,g-1,y,c.columns-1),N=m.subMatrix(0,g-1,y,m.columns-1),x=c.subMatrix(g,c.rows-1,0,y-1),F=m.subMatrix(g,m.rows-1,0,y-1),M=c.subMatrix(g,c.rows-1,y,c.columns-1),S=m.subMatrix(g,m.rows-1,y,m.columns-1),$=h($t.add(v,M),$t.add(E,S),g,y),C=h($t.add(x,M),E,g,y),I=h(v,$t.sub(N,S),g,y),R=h(M,$t.sub(F,E),g,y),U=h($t.add(v,b),S,g,y),q=h($t.sub(x,v),$t.add(E,N),g,y),k=h($t.sub(b,M),$t.add(F,S),g,y),P=$t.add($,R);P.sub(U),P.add(k);let K=$t.add(I,U),G=$t.add(C,R),V=$t.sub($,C);V.add(I),V.add(q);let tt=$t.zeros(2*P.rows,2*P.columns);return tt=tt.setSubMatrix(P,0,0),tt=tt.setSubMatrix(K,P.rows,0),tt=tt.setSubMatrix(G,0,P.columns),tt=tt.setSubMatrix(V,P.rows,P.columns),tt.subMatrix(0,_-1,0,w-1)}return h(e,t,f,p)}scaleRows(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.rows;s++){const u=this.getRow(s);u.length>0&&Sc(u,{min:e,max:r,output:u}),n.setRow(s,u)}return n}scaleColumns(t={}){if(typeof t!="object")throw new TypeError("options must be an object");const{min:e=0,max:r=1}=t;if(!Number.isFinite(e))throw new TypeError("min must be a number");if(!Number.isFinite(r))throw new TypeError("max must be a number");if(e>=r)throw new RangeError("min must be smaller than max");let n=new pt(this.rows,this.columns);for(let s=0;s<this.columns;s++){const u=this.getColumn(s);u.length&&Sc(u,{min:e,max:r,output:u}),n.setColumn(s,u)}return n}flipRows(){const t=Math.ceil(this.columns/2);for(let e=0;e<this.rows;e++)for(let r=0;r<t;r++){let n=this.get(e,r),s=this.get(e,this.columns-1-r);this.set(e,r,s),this.set(e,this.columns-1-r,n)}return this}flipColumns(){const t=Math.ceil(this.rows/2);for(let e=0;e<this.columns;e++)for(let r=0;r<t;r++){let n=this.get(r,e),s=this.get(this.rows-1-r,e);this.set(r,e,s),this.set(this.rows-1-r,e,n)}return this}kroneckerProduct(t){t=pt.checkMatrix(t);let e=this.rows,r=this.columns,n=t.rows,s=t.columns,u=new pt(e*n,r*s);for(let l=0;l<e;l++)for(let f=0;f<r;f++)for(let p=0;p<n;p++)for(let h=0;h<s;h++)u.set(n*l+p,s*f+h,this.get(l,f)*t.get(p,h));return u}kroneckerSum(t){if(t=pt.checkMatrix(t),!this.isSquare()||!t.isSquare())throw new Error("Kronecker Sum needs two Square Matrices");let e=this.rows,r=t.rows,n=this.kroneckerProduct(pt.eye(r,r)),s=pt.eye(e,e).kroneckerProduct(t);return n.add(s)}transpose(){let t=new pt(this.columns,this.rows);for(let e=0;e<this.rows;e++)for(let r=0;r<this.columns;r++)t.set(r,e,this.get(e,r));return t}sortRows(t=$c){for(let e=0;e<this.rows;e++)this.setRow(e,this.getRow(e).sort(t));return this}sortColumns(t=$c){for(let e=0;e<this.columns;e++)this.setColumn(e,this.getColumn(e).sort(t));return this}subMatrix(t,e,r,n){Ia(this,t,e,r,n);let s=new pt(e-t+1,n-r+1);for(let u=t;u<=e;u++)for(let l=r;l<=n;l++)s.set(u-t,l-r,this.get(u,l));return s}subMatrixRow(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.columns-1),e>r||e<0||e>=this.columns||r<0||r>=this.columns)throw new RangeError("Argument out of range");let n=new pt(t.length,r-e+1);for(let s=0;s<t.length;s++)for(let u=e;u<=r;u++){if(t[s]<0||t[s]>=this.rows)throw new RangeError(`Row index out of range: ${t[s]}`);n.set(s,u-e,this.get(t[s],u))}return n}subMatrixColumn(t,e,r){if(e===void 0&&(e=0),r===void 0&&(r=this.rows-1),e>r||e<0||e>=this.rows||r<0||r>=this.rows)throw new RangeError("Argument out of range");let n=new pt(r-e+1,t.length);for(let s=0;s<t.length;s++)for(let u=e;u<=r;u++){if(t[s]<0||t[s]>=this.columns)throw new RangeError(`Column index out of range: ${t[s]}`);n.set(u-e,s,this.get(u,t[s]))}return n}setSubMatrix(t,e,r){if(t=pt.checkMatrix(t),t.isEmpty())return this;let n=e+t.rows-1,s=r+t.columns-1;Ia(this,e,n,r,s);for(let u=0;u<t.rows;u++)for(let l=0;l<t.columns;l++)this.set(e+u,r+l,t.get(u,l));return this}selection(t,e){Sa(this,t),Ba(this,e);let r=new pt(t.length,e.length);for(let n=0;n<t.length;n++){let s=t[n];for(let u=0;u<e.length;u++){let l=e[u];r.set(n,u,this.get(s,l))}}return r}trace(){let t=Math.min(this.rows,this.columns),e=0;for(let r=0;r<t;r++)e+=this.get(r,r);return e}clone(){return this.constructor.copy(this,new pt(this.rows,this.columns))}static copy(t,e){for(const[r,n,s]of t.entries())e.set(r,n,s);return e}sum(t){switch(t){case"row":return b1(this);case"column":return E1(this);case void 0:return A1(this);default:throw new Error(`invalid option: ${t}`)}}product(t){switch(t){case"row":return x1(this);case"column":return C1(this);case void 0:return F1(this);default:throw new Error(`invalid option: ${t}`)}}mean(t){const e=this.sum(t);switch(t){case"row":{for(let r=0;r<this.rows;r++)e[r]/=this.columns;return e}case"column":{for(let r=0;r<this.columns;r++)e[r]/=this.rows;return e}case void 0:return e/this.size;default:throw new Error(`invalid option: ${t}`)}}variance(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{unbiased:r=!0,mean:n=this.mean(t)}=e;if(typeof r!="boolean")throw new TypeError("unbiased must be a boolean");switch(t){case"row":{if(!Je.isAnyArray(n))throw new TypeError("mean must be an array");return M1(this,r,n)}case"column":{if(!Je.isAnyArray(n))throw new TypeError("mean must be an array");return N1(this,r,n)}case void 0:{if(typeof n!="number")throw new TypeError("mean must be a number");return S1(this,r,n)}default:throw new Error(`invalid option: ${t}`)}}standardDeviation(t,e){typeof t=="object"&&(e=t,t=void 0);const r=this.variance(t,e);if(t===void 0)return Math.sqrt(r);for(let n=0;n<r.length;n++)r[n]=Math.sqrt(r[n]);return r}center(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");const{center:r=this.mean(t)}=e;switch(t){case"row":{if(!Je.isAnyArray(r))throw new TypeError("center must be an array");return B1(this,r),this}case"column":{if(!Je.isAnyArray(r))throw new TypeError("center must be an array");return I1(this,r),this}case void 0:{if(typeof r!="number")throw new TypeError("center must be a number");return T1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}scale(t,e={}){if(typeof t=="object"&&(e=t,t=void 0),typeof e!="object")throw new TypeError("options must be an object");let r=e.scale;switch(t){case"row":{if(r===void 0)r=$1(this);else if(!Je.isAnyArray(r))throw new TypeError("scale must be an array");return O1(this,r),this}case"column":{if(r===void 0)r=R1(this);else if(!Je.isAnyArray(r))throw new TypeError("scale must be an array");return L1(this,r),this}case void 0:{if(r===void 0)r=P1(this);else if(typeof r!="number")throw new TypeError("scale must be a number");return z1(this,r),this}default:throw new Error(`invalid option: ${t}`)}}toString(t){return Ic(this,t)}[Symbol.iterator](){return this.entries()}*entries(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield[t,e,this.get(t,e)]}*values(){for(let t=0;t<this.rows;t++)for(let e=0;e<this.columns;e++)yield this.get(t,e)}}$t.prototype.klass="Matrix",typeof Symbol<"u"&&($t.prototype[Symbol.for("nodejs.util.inspect.custom")]=_1);function $c(i,t){return i-t}function q1(i){return i.every(t=>typeof t=="number")}$t.random=$t.rand,$t.randomInt=$t.randInt,$t.diagonal=$t.diag,$t.prototype.diagonal=$t.prototype.diag,$t.identity=$t.eye,$t.prototype.negate=$t.prototype.neg,$t.prototype.tensorProduct=$t.prototype.kroneckerProduct;let pt=(Di=class extends $t{constructor(e,r){super();Dl(this,Xi);Z(this,"data");if(Di.isMatrix(e))yl(this,Xi,bl).call(this,e.rows,e.columns),Di.copy(e,this);else if(Number.isInteger(e)&&e>=0)yl(this,Xi,bl).call(this,e,r);else if(Je.isAnyArray(e)){const n=e;if(e=n.length,r=e?n[0].length:0,typeof r!="number")throw new TypeError("Data must be a 2D array with at least one element");this.data=[];for(let s=0;s<e;s++){if(n[s].length!==r)throw new RangeError("Inconsistent array dimensions");if(!q1(n[s]))throw new TypeError("Input data contains non-numeric values");this.data.push(Float64Array.from(n[s]))}this.rows=e,this.columns=r}else throw new TypeError("First argument must be a positive number or an array")}set(e,r,n){return this.data[e][r]=n,this}get(e,r){return this.data[e][r]}removeRow(e){return vr(this,e),this.data.splice(e,1),this.rows-=1,this}addRow(e,r){return r===void 0&&(r=e,e=this.rows),vr(this,e,!0),r=Float64Array.from(pi(this,r)),this.data.splice(e,0,r),this.rows+=1,this}removeColumn(e){_r(this,e);for(let r=0;r<this.rows;r++){const n=new Float64Array(this.columns-1);for(let s=0;s<e;s++)n[s]=this.data[r][s];for(let s=e+1;s<this.columns;s++)n[s-1]=this.data[r][s];this.data[r]=n}return this.columns-=1,this}addColumn(e,r){typeof r>"u"&&(r=e,e=this.columns),_r(this,e,!0),r=di(this,r);for(let n=0;n<this.rows;n++){const s=new Float64Array(this.columns+1);let u=0;for(;u<e;u++)s[u]=this.data[n][u];for(s[u++]=r[n];u<this.columns+1;u++)s[u]=this.data[n][u-1];this.data[n]=s}return this.columns+=1,this}},Xi=new WeakSet,bl=function(e,r){if(this.data=[],Number.isInteger(r)&&r>=0)for(let n=0;n<e;n++)this.data.push(new Float64Array(r));else throw new TypeError("nColumns must be a positive integer");this.rows=e,this.columns=r},Di);y1($t,pt);const lo=class lo extends $t{constructor(e){super();Dl(this,qe,void 0);if(pt.isMatrix(e)){if(!e.isSymmetric())throw new TypeError("not symmetric data");ea(this,qe,pt.copy(e,new pt(e.rows,e.rows)))}else if(Number.isInteger(e)&&e>=0)ea(this,qe,new pt(e,e));else if(ea(this,qe,new pt(e)),!this.isSymmetric())throw new TypeError("not symmetric data")}get size(){return Lr(this,qe).size}get rows(){return Lr(this,qe).rows}get columns(){return Lr(this,qe).columns}get diagonalSize(){return this.rows}static isSymmetricMatrix(e){return pt.isMatrix(e)&&e.klassType==="SymmetricMatrix"}static zeros(e){return new this(e)}static ones(e){return new this(e).fill(1)}clone(){const e=new lo(this.diagonalSize);for(const[r,n,s]of this.upperRightEntries())e.set(r,n,s);return e}toMatrix(){return new pt(this)}get(e,r){return Lr(this,qe).get(e,r)}set(e,r,n){return Lr(this,qe).set(e,r,n),Lr(this,qe).set(r,e,n),this}removeCross(e){return Lr(this,qe).removeRow(e),Lr(this,qe).removeColumn(e),this}addCross(e,r){r===void 0&&(r=e,e=this.diagonalSize);const n=r.slice();return n.splice(e,1),Lr(this,qe).addRow(e,n),Lr(this,qe).addColumn(e,r),this}applyMask(e){if(e.length!==this.diagonalSize)throw new RangeError("Mask size do not match with matrix size");const r=[];for(const[n,s]of e.entries())s||r.push(n);r.reverse();for(const n of r)this.removeCross(n);return this}toCompact(){const{diagonalSize:e}=this,r=new Array(e*(e+1)/2);for(let n=0,s=0,u=0;u<r.length;u++)r[u]=this.get(s,n),++n>=e&&(n=++s);return r}static fromCompact(e){const r=e.length,n=(Math.sqrt(8*r+1)-1)/2;if(!Number.isInteger(n))throw new TypeError(`This array is not a compact representation of a Symmetric Matrix, ${JSON.stringify(e)}`);const s=new lo(n);for(let u=0,l=0,f=0;f<r;f++)s.set(u,l,e[f]),++u>=n&&(u=++l);return s}*upperRightEntries(){for(let e=0,r=0;e<this.diagonalSize;void 0){const n=this.get(e,r);yield[e,r,n],++r>=this.diagonalSize&&(r=++e)}}*upperRightValues(){for(let e=0,r=0;e<this.diagonalSize;void 0)yield this.get(e,r),++r>=this.diagonalSize&&(r=++e)}};qe=new WeakMap;let kn=lo;kn.prototype.klassType="SymmetricMatrix";class Vs extends kn{static isDistanceMatrix(t){return kn.isSymmetricMatrix(t)&&t.klassSubType==="DistanceMatrix"}constructor(t){if(super(t),!this.isDistance())throw new TypeError("Provided arguments do no produce a distance matrix")}set(t,e,r){return t===e&&(r=0),super.set(t,e,r)}addCross(t,e){return e===void 0&&(e=t,t=this.diagonalSize),e=e.slice(),e[t]=0,super.addCross(t,e)}toSymmetricMatrix(){return new kn(this)}clone(){const t=new Vs(this.diagonalSize);for(const[e,r,n]of this.upperRightEntries())e!==r&&t.set(e,r,n);return t}toCompact(){const{diagonalSize:t}=this,e=(t-1)*t/2,r=new Array(e);for(let n=1,s=0,u=0;u<r.length;u++)r[u]=this.get(s,n),++n>=t&&(n=++s+1);return r}static fromCompact(t){const e=t.length,r=(Math.sqrt(8*e+1)+1)/2;if(!Number.isInteger(r))throw new TypeError(`This array is not a compact representation of a DistanceMatrix, ${JSON.stringify(t)}`);const n=new this(r);for(let s=1,u=0,l=0;l<e;l++)n.set(s,u,t[l]),++s>=r&&(s=++u+1);return n}}Vs.prototype.klassSubType="DistanceMatrix";class Jr extends $t{constructor(t,e,r){super(),this.matrix=t,this.rows=e,this.columns=r}}class U1 extends Jr{constructor(t,e){_r(t,e),super(t,t.rows,1),this.column=e}set(t,e,r){return this.matrix.set(t,this.column,r),this}get(t){return this.matrix.get(t,this.column)}}class k1 extends Jr{constructor(t,e){Ba(t,e),super(t,t.rows,e.length),this.columnIndices=e}set(t,e,r){return this.matrix.set(t,this.columnIndices[e],r),this}get(t,e){return this.matrix.get(t,this.columnIndices[e])}}class W1 extends Jr{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(t,this.columns-e-1,r),this}get(t,e){return this.matrix.get(t,this.columns-e-1)}}class Y1 extends Jr{constructor(t){super(t,t.rows,t.columns)}set(t,e,r){return this.matrix.set(this.rows-t-1,e,r),this}get(t,e){return this.matrix.get(this.rows-t-1,e)}}class j1 extends Jr{constructor(t,e){vr(t,e),super(t,1,t.columns),this.row=e}set(t,e,r){return this.matrix.set(this.row,e,r),this}get(t,e){return this.matrix.get(this.row,e)}}class Z1 extends Jr{constructor(t,e){Sa(t,e),super(t,e.length,t.columns),this.rowIndices=e}set(t,e,r){return this.matrix.set(this.rowIndices[t],e,r),this}get(t,e){return this.matrix.get(this.rowIndices[t],e)}}class Qs extends Jr{constructor(t,e,r){Sa(t,e),Ba(t,r),super(t,e.length,r.length),this.rowIndices=e,this.columnIndices=r}set(t,e,r){return this.matrix.set(this.rowIndices[t],this.columnIndices[e],r),this}get(t,e){return this.matrix.get(this.rowIndices[t],this.columnIndices[e])}}class G1 extends Jr{constructor(t,e,r,n,s){Ia(t,e,r,n,s),super(t,r-e+1,s-n+1),this.startRow=e,this.startColumn=n}set(t,e,r){return this.matrix.set(this.startRow+t,this.startColumn+e,r),this}get(t,e){return this.matrix.get(this.startRow+t,this.startColumn+e)}}class K1 extends Jr{constructor(t){super(t,t.columns,t.rows)}set(t,e,r){return this.matrix.set(e,t,r),this}get(t,e){return this.matrix.get(e,t)}}class Oc extends $t{constructor(t,e={}){const{rows:r=1}=e;if(t.length%r!==0)throw new Error("the data length is not divisible by the number of rows");super(),this.rows=r,this.columns=t.length/r,this.data=t}set(t,e,r){let n=this._calculateIndex(t,e);return this.data[n]=r,this}get(t,e){let r=this._calculateIndex(t,e);return this.data[r]}_calculateIndex(t,e){return t*this.columns+e}}class ir extends $t{constructor(t){super(),this.data=t,this.rows=t.length,this.columns=t[0].length}set(t,e,r){return this.data[t][e]=r,this}get(t,e){return this.data[t][e]}}function H1(i,t){if(Je.isAnyArray(i))return i[0]&&Je.isAnyArray(i[0])?new ir(i):new Oc(i,t);throw new Error("the argument is not an array")}class to{constructor(t){t=ir.checkMatrix(t);let e=t.clone(),r=e.rows,n=e.columns,s=new Float64Array(r),u=1,l,f,p,h,c,m,_,w,g;for(l=0;l<r;l++)s[l]=l;for(w=new Float64Array(r),f=0;f<n;f++){for(l=0;l<r;l++)w[l]=e.get(l,f);for(l=0;l<r;l++){for(g=Math.min(l,f),c=0,p=0;p<g;p++)c+=e.get(l,p)*w[p];w[l]-=c,e.set(l,f,w[l])}for(h=f,l=f+1;l<r;l++)Math.abs(w[l])>Math.abs(w[h])&&(h=l);if(h!==f){for(p=0;p<n;p++)m=e.get(h,p),e.set(h,p,e.get(f,p)),e.set(f,p,m);_=s[h],s[h]=s[f],s[f]=_,u=-u}if(f<r&&e.get(f,f)!==0)for(l=f+1;l<r;l++)e.set(l,f,e.get(l,f)/e.get(f,f))}this.LU=e,this.pivotVector=s,this.pivotSign=u}isSingular(){let t=this.LU,e=t.columns;for(let r=0;r<e;r++)if(t.get(r,r)===0)return!0;return!1}solve(t){t=pt.checkMatrix(t);let e=this.LU;if(e.rows!==t.rows)throw new Error("Invalid matrix dimensions");if(this.isSingular())throw new Error("LU matrix is singular");let n=t.columns,s=t.subMatrixRow(this.pivotVector,0,n-1),u=e.columns,l,f,p;for(p=0;p<u;p++)for(l=p+1;l<u;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(p,f)*e.get(l,p));for(p=u-1;p>=0;p--){for(f=0;f<n;f++)s.set(p,f,s.get(p,f)/e.get(p,p));for(l=0;l<p;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(p,f)*e.get(l,p))}return s}get determinant(){let t=this.LU;if(!t.isSquare())throw new Error("Matrix must be square");let e=this.pivotSign,r=t.columns;for(let n=0;n<r;n++)e*=t.get(n,n);return e}get lowerTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let u=0;u<r;u++)s>u?n.set(s,u,t.get(s,u)):s===u?n.set(s,u,1):n.set(s,u,0);return n}get upperTriangularMatrix(){let t=this.LU,e=t.rows,r=t.columns,n=new pt(e,r);for(let s=0;s<e;s++)for(let u=0;u<r;u++)s<=u?n.set(s,u,t.get(s,u)):n.set(s,u,0);return n}get pivotPermutationVector(){return Array.from(this.pivotVector)}}function Xr(i,t){let e=0;return Math.abs(i)>Math.abs(t)?(e=t/i,Math.abs(i)*Math.sqrt(1+e*e)):t!==0?(e=i/t,Math.abs(t)*Math.sqrt(1+e*e)):0}class Ta{constructor(t){t=ir.checkMatrix(t);let e=t.clone(),r=t.rows,n=t.columns,s=new Float64Array(n),u,l,f,p;for(f=0;f<n;f++){let h=0;for(u=f;u<r;u++)h=Xr(h,e.get(u,f));if(h!==0){for(e.get(f,f)<0&&(h=-h),u=f;u<r;u++)e.set(u,f,e.get(u,f)/h);for(e.set(f,f,e.get(f,f)+1),l=f+1;l<n;l++){for(p=0,u=f;u<r;u++)p+=e.get(u,f)*e.get(u,l);for(p=-p/e.get(f,f),u=f;u<r;u++)e.set(u,l,e.get(u,l)+p*e.get(u,f))}}s[f]=-h}this.QR=e,this.Rdiag=s}solve(t){t=pt.checkMatrix(t);let e=this.QR,r=e.rows;if(t.rows!==r)throw new Error("Matrix row dimensions must agree");if(!this.isFullRank())throw new Error("Matrix is rank deficient");let n=t.columns,s=t.clone(),u=e.columns,l,f,p,h;for(p=0;p<u;p++)for(f=0;f<n;f++){for(h=0,l=p;l<r;l++)h+=e.get(l,p)*s.get(l,f);for(h=-h/e.get(p,p),l=p;l<r;l++)s.set(l,f,s.get(l,f)+h*e.get(l,p))}for(p=u-1;p>=0;p--){for(f=0;f<n;f++)s.set(p,f,s.get(p,f)/this.Rdiag[p]);for(l=0;l<p;l++)for(f=0;f<n;f++)s.set(l,f,s.get(l,f)-s.get(p,f)*e.get(l,p))}return s.subMatrix(0,u-1,0,n-1)}isFullRank(){let t=this.QR.columns;for(let e=0;e<t;e++)if(this.Rdiag[e]===0)return!1;return!0}get upperTriangularMatrix(){let t=this.QR,e=t.columns,r=new pt(e,e),n,s;for(n=0;n<e;n++)for(s=0;s<e;s++)n<s?r.set(n,s,t.get(n,s)):n===s?r.set(n,s,this.Rdiag[n]):r.set(n,s,0);return r}get orthogonalMatrix(){let t=this.QR,e=t.rows,r=t.columns,n=new pt(e,r),s,u,l,f;for(l=r-1;l>=0;l--){for(s=0;s<e;s++)n.set(s,l,0);for(n.set(l,l,1),u=l;u<r;u++)if(t.get(l,l)!==0){for(f=0,s=l;s<e;s++)f+=t.get(s,l)*n.get(s,u);for(f=-f/t.get(l,l),s=l;s<e;s++)n.set(s,u,n.get(s,u)+f*t.get(s,l))}}return n}}class gi{constructor(t,e={}){if(t=ir.checkMatrix(t),t.isEmpty())throw new Error("Matrix must be non-empty");let r=t.rows,n=t.columns;const{computeLeftSingularVectors:s=!0,computeRightSingularVectors:u=!0,autoTranspose:l=!1}=e;let f=!!s,p=!!u,h=!1,c;if(r<n)if(!l)c=t.clone(),console.warn("Computing SVD on a matrix with more columns than rows. Consider enabling autoTranspose");else{c=t.transpose(),r=c.rows,n=c.columns,h=!0;let C=f;f=p,p=C}else c=t.clone();let m=Math.min(r,n),_=Math.min(r+1,n),w=new Float64Array(_),g=new pt(r,m),y=new pt(n,n),v=new Float64Array(n),E=new Float64Array(r),b=new Float64Array(_);for(let C=0;C<_;C++)b[C]=C;let N=Math.min(r-1,n),x=Math.max(0,Math.min(n-2,r)),F=Math.max(N,x);for(let C=0;C<F;C++){if(C<N){w[C]=0;for(let I=C;I<r;I++)w[C]=Xr(w[C],c.get(I,C));if(w[C]!==0){c.get(C,C)<0&&(w[C]=-w[C]);for(let I=C;I<r;I++)c.set(I,C,c.get(I,C)/w[C]);c.set(C,C,c.get(C,C)+1)}w[C]=-w[C]}for(let I=C+1;I<n;I++){if(C<N&&w[C]!==0){let R=0;for(let U=C;U<r;U++)R+=c.get(U,C)*c.get(U,I);R=-R/c.get(C,C);for(let U=C;U<r;U++)c.set(U,I,c.get(U,I)+R*c.get(U,C))}v[I]=c.get(C,I)}if(f&&C<N)for(let I=C;I<r;I++)g.set(I,C,c.get(I,C));if(C<x){v[C]=0;for(let I=C+1;I<n;I++)v[C]=Xr(v[C],v[I]);if(v[C]!==0){v[C+1]<0&&(v[C]=0-v[C]);for(let I=C+1;I<n;I++)v[I]/=v[C];v[C+1]+=1}if(v[C]=-v[C],C+1<r&&v[C]!==0){for(let I=C+1;I<r;I++)E[I]=0;for(let I=C+1;I<r;I++)for(let R=C+1;R<n;R++)E[I]+=v[R]*c.get(I,R);for(let I=C+1;I<n;I++){let R=-v[I]/v[C+1];for(let U=C+1;U<r;U++)c.set(U,I,c.get(U,I)+R*E[U])}}if(p)for(let I=C+1;I<n;I++)y.set(I,C,v[I])}}let M=Math.min(n,r+1);if(N<n&&(w[N]=c.get(N,N)),r<M&&(w[M-1]=0),x+1<M&&(v[x]=c.get(x,M-1)),v[M-1]=0,f){for(let C=N;C<m;C++){for(let I=0;I<r;I++)g.set(I,C,0);g.set(C,C,1)}for(let C=N-1;C>=0;C--)if(w[C]!==0){for(let I=C+1;I<m;I++){let R=0;for(let U=C;U<r;U++)R+=g.get(U,C)*g.get(U,I);R=-R/g.get(C,C);for(let U=C;U<r;U++)g.set(U,I,g.get(U,I)+R*g.get(U,C))}for(let I=C;I<r;I++)g.set(I,C,-g.get(I,C));g.set(C,C,1+g.get(C,C));for(let I=0;I<C-1;I++)g.set(I,C,0)}else{for(let I=0;I<r;I++)g.set(I,C,0);g.set(C,C,1)}}if(p)for(let C=n-1;C>=0;C--){if(C<x&&v[C]!==0)for(let I=C+1;I<n;I++){let R=0;for(let U=C+1;U<n;U++)R+=y.get(U,C)*y.get(U,I);R=-R/y.get(C+1,C);for(let U=C+1;U<n;U++)y.set(U,I,y.get(U,I)+R*y.get(U,C))}for(let I=0;I<n;I++)y.set(I,C,0);y.set(C,C,1)}let S=M-1,$=Number.EPSILON;for(;M>0;){let C,I;for(C=M-2;C>=-1&&C!==-1;C--){const R=Number.MIN_VALUE+$*Math.abs(w[C]+Math.abs(w[C+1]));if(Math.abs(v[C])<=R||Number.isNaN(v[C])){v[C]=0;break}}if(C===M-2)I=4;else{let R;for(R=M-1;R>=C&&R!==C;R--){let U=(R!==M?Math.abs(v[R]):0)+(R!==C+1?Math.abs(v[R-1]):0);if(Math.abs(w[R])<=$*U){w[R]=0;break}}R===C?I=3:R===M-1?I=1:(I=2,C=R)}switch(C++,I){case 1:{let R=v[M-2];v[M-2]=0;for(let U=M-2;U>=C;U--){let q=Xr(w[U],R),k=w[U]/q,P=R/q;if(w[U]=q,U!==C&&(R=-P*v[U-1],v[U-1]=k*v[U-1]),p)for(let K=0;K<n;K++)q=k*y.get(K,U)+P*y.get(K,M-1),y.set(K,M-1,-P*y.get(K,U)+k*y.get(K,M-1)),y.set(K,U,q)}break}case 2:{let R=v[C-1];v[C-1]=0;for(let U=C;U<M;U++){let q=Xr(w[U],R),k=w[U]/q,P=R/q;if(w[U]=q,R=-P*v[U],v[U]=k*v[U],f)for(let K=0;K<r;K++)q=k*g.get(K,U)+P*g.get(K,C-1),g.set(K,C-1,-P*g.get(K,U)+k*g.get(K,C-1)),g.set(K,U,q)}break}case 3:{const R=Math.max(Math.abs(w[M-1]),Math.abs(w[M-2]),Math.abs(v[M-2]),Math.abs(w[C]),Math.abs(v[C])),U=w[M-1]/R,q=w[M-2]/R,k=v[M-2]/R,P=w[C]/R,K=v[C]/R,G=((q+U)*(q-U)+k*k)/2,V=U*k*(U*k);let tt=0;(G!==0||V!==0)&&(G<0?tt=0-Math.sqrt(G*G+V):tt=Math.sqrt(G*G+V),tt=V/(G+tt));let ft=(P+U)*(P-U)+tt,vt=P*K;for(let lt=C;lt<M-1;lt++){let wt=Xr(ft,vt);wt===0&&(wt=Number.MIN_VALUE);let yt=ft/wt,St=vt/wt;if(lt!==C&&(v[lt-1]=wt),ft=yt*w[lt]+St*v[lt],v[lt]=yt*v[lt]-St*w[lt],vt=St*w[lt+1],w[lt+1]=yt*w[lt+1],p)for(let bt=0;bt<n;bt++)wt=yt*y.get(bt,lt)+St*y.get(bt,lt+1),y.set(bt,lt+1,-St*y.get(bt,lt)+yt*y.get(bt,lt+1)),y.set(bt,lt,wt);if(wt=Xr(ft,vt),wt===0&&(wt=Number.MIN_VALUE),yt=ft/wt,St=vt/wt,w[lt]=wt,ft=yt*v[lt]+St*w[lt+1],w[lt+1]=-St*v[lt]+yt*w[lt+1],vt=St*v[lt+1],v[lt+1]=yt*v[lt+1],f&&lt<r-1)for(let bt=0;bt<r;bt++)wt=yt*g.get(bt,lt)+St*g.get(bt,lt+1),g.set(bt,lt+1,-St*g.get(bt,lt)+yt*g.get(bt,lt+1)),g.set(bt,lt,wt)}v[M-2]=ft;break}case 4:{if(w[C]<=0&&(w[C]=w[C]<0?-w[C]:0,p))for(let R=0;R<=S;R++)y.set(R,C,-y.get(R,C));for(;C<S&&!(w[C]>=w[C+1]);){let R=w[C];if(w[C]=w[C+1],w[C+1]=R,p&&C<n-1)for(let U=0;U<n;U++)R=y.get(U,C+1),y.set(U,C+1,y.get(U,C)),y.set(U,C,R);if(f&&C<r-1)for(let U=0;U<r;U++)R=g.get(U,C+1),g.set(U,C+1,g.get(U,C)),g.set(U,C,R);C++}M--;break}}}if(h){let C=y;y=g,g=C}this.m=r,this.n=n,this.s=w,this.U=g,this.V=y}solve(t){let e=t,r=this.threshold,n=this.s.length,s=pt.zeros(n,n);for(let m=0;m<n;m++)Math.abs(this.s[m])<=r?s.set(m,m,0):s.set(m,m,1/this.s[m]);let u=this.U,l=this.rightSingularVectors,f=l.mmul(s),p=l.rows,h=u.rows,c=pt.zeros(p,h);for(let m=0;m<p;m++)for(let _=0;_<h;_++){let w=0;for(let g=0;g<n;g++)w+=f.get(m,g)*u.get(_,g);c.set(m,_,w)}return c.mmul(e)}solveForDiagonal(t){return this.solve(pt.diag(t))}inverse(){let t=this.V,e=this.threshold,r=t.rows,n=t.columns,s=new pt(r,this.s.length);for(let h=0;h<r;h++)for(let c=0;c<n;c++)Math.abs(this.s[c])>e&&s.set(h,c,t.get(h,c)/this.s[c]);let u=this.U,l=u.rows,f=u.columns,p=new pt(r,l);for(let h=0;h<r;h++)for(let c=0;c<l;c++){let m=0;for(let _=0;_<f;_++)m+=s.get(h,_)*u.get(c,_);p.set(h,c,m)}return p}get condition(){return this.s[0]/this.s[Math.min(this.m,this.n)-1]}get norm2(){return this.s[0]}get rank(){let t=Math.max(this.m,this.n)*this.s[0]*Number.EPSILON,e=0,r=this.s;for(let n=0,s=r.length;n<s;n++)r[n]>t&&e++;return e}get diagonal(){return Array.from(this.s)}get threshold(){return Number.EPSILON/2*Math.max(this.m,this.n)*this.s[0]}get leftSingularVectors(){return this.U}get rightSingularVectors(){return this.V}get diagonalMatrix(){return pt.diag(this.s)}}function J1(i,t=!1){return i=ir.checkMatrix(i),t?new gi(i).inverse():Rc(i,pt.eye(i.rows))}function Rc(i,t,e=!1){return i=ir.checkMatrix(i),t=ir.checkMatrix(t),e?new gi(i).solve(t):i.isSquare()?new to(i).solve(t):new Ta(i).solve(t)}function eo(i){if(i=pt.checkMatrix(i),i.isSquare()){if(i.columns===0)return 1;let t,e,r,n;if(i.columns===2)return t=i.get(0,0),e=i.get(0,1),r=i.get(1,0),n=i.get(1,1),t*n-e*r;if(i.columns===3){let s,u,l;return s=new Qs(i,[1,2],[1,2]),u=new Qs(i,[1,2],[0,2]),l=new Qs(i,[1,2],[0,1]),t=i.get(0,0),e=i.get(0,1),r=i.get(0,2),t*eo(s)-e*eo(u)+r*eo(l)}else return new to(i).determinant}else throw Error("determinant can only be calculated for a square matrix")}function X1(i,t){let e=[];for(let r=0;r<i;r++)r!==t&&e.push(r);return e}function V1(i,t,e,r=1e-9,n=1e-9){if(i>n)return new Array(t.rows+1).fill(0);{let s=t.addRow(e,[0]);for(let u=0;u<s.rows;u++)Math.abs(s.get(u,0))<r&&s.set(u,0,0);return s.to1DArray()}}function Q1(i,t={}){const{thresholdValue:e=1e-9,thresholdError:r=1e-9}=t;i=pt.checkMatrix(i);let n=i.rows,s=new pt(n,n);for(let u=0;u<n;u++){let l=pt.columnVector(i.getRow(u)),f=i.subMatrixRow(X1(n,u)).transpose(),h=new gi(f).solve(l),c=pt.sub(l,f.mmul(h)).abs().max();s.setRow(u,V1(c,h,u,e,r))}return s}function tw(i,t=Number.EPSILON){if(i=pt.checkMatrix(i),i.isEmpty())return i.transpose();let e=new gi(i,{autoTranspose:!0}),r=e.leftSingularVectors,n=e.rightSingularVectors,s=e.diagonal;for(let u=0;u<s.length;u++)Math.abs(s[u])>t?s[u]=1/s[u]:s[u]=0;return n.mmul(pt.diag(s).mmul(r.transpose()))}function ew(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!Je.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0}=e;n&&(i=i.center("column"),r||(t=t.center("column")));const s=i.transpose().mmul(t);for(let u=0;u<s.rows;u++)for(let l=0;l<s.columns;l++)s.set(u,l,s.get(u,l)*(1/(i.rows-1)));return s}function rw(i,t=i,e={}){i=new pt(i);let r=!1;if(typeof t=="object"&&!pt.isMatrix(t)&&!Je.isAnyArray(t)?(e=t,t=i,r=!0):t=new pt(t),i.rows!==t.rows)throw new TypeError("Both matrices must have the same number of rows");const{center:n=!0,scale:s=!0}=e;n&&(i.center("column"),r||t.center("column")),s&&(i.scale("column"),r||t.scale("column"));const u=i.standardDeviation("column",{unbiased:!0}),l=r?u:t.standardDeviation("column",{unbiased:!0}),f=i.transpose().mmul(t);for(let p=0;p<f.rows;p++)for(let h=0;h<f.columns;h++)f.set(p,h,f.get(p,h)*(1/(u[p]*l[h]))*(1/(i.rows-1)));return f}let Lc=class{constructor(t,e={}){const{assumeSymmetric:r=!1}=e;if(t=ir.checkMatrix(t),!t.isSquare())throw new Error("Matrix is not a square matrix");if(t.isEmpty())throw new Error("Matrix must be non-empty");let n=t.columns,s=new pt(n,n),u=new Float64Array(n),l=new Float64Array(n),f=t,p,h,c=!1;if(r?c=!0:c=t.isSymmetric(),c){for(p=0;p<n;p++)for(h=0;h<n;h++)s.set(p,h,f.get(p,h));nw(n,l,u,s),iw(n,l,u,s)}else{let m=new pt(n,n),_=new Float64Array(n);for(h=0;h<n;h++)for(p=0;p<n;p++)m.set(p,h,f.get(p,h));sw(n,m,_,s),ow(n,l,u,s,m)}this.n=n,this.e=l,this.d=u,this.V=s}get realEigenvalues(){return Array.from(this.d)}get imaginaryEigenvalues(){return Array.from(this.e)}get eigenvectorMatrix(){return this.V}get diagonalMatrix(){let t=this.n,e=this.e,r=this.d,n=new pt(t,t),s,u;for(s=0;s<t;s++){for(u=0;u<t;u++)n.set(s,u,0);n.set(s,s,r[s]),e[s]>0?n.set(s,s+1,e[s]):e[s]<0&&n.set(s,s-1,e[s])}return n}};function nw(i,t,e,r){let n,s,u,l,f,p,h,c;for(f=0;f<i;f++)e[f]=r.get(i-1,f);for(l=i-1;l>0;l--){for(c=0,u=0,p=0;p<l;p++)c=c+Math.abs(e[p]);if(c===0)for(t[l]=e[l-1],f=0;f<l;f++)e[f]=r.get(l-1,f),r.set(l,f,0),r.set(f,l,0);else{for(p=0;p<l;p++)e[p]/=c,u+=e[p]*e[p];for(n=e[l-1],s=Math.sqrt(u),n>0&&(s=-s),t[l]=c*s,u=u-n*s,e[l-1]=n-s,f=0;f<l;f++)t[f]=0;for(f=0;f<l;f++){for(n=e[f],r.set(f,l,n),s=t[f]+r.get(f,f)*n,p=f+1;p<=l-1;p++)s+=r.get(p,f)*e[p],t[p]+=r.get(p,f)*n;t[f]=s}for(n=0,f=0;f<l;f++)t[f]/=u,n+=t[f]*e[f];for(h=n/(u+u),f=0;f<l;f++)t[f]-=h*e[f];for(f=0;f<l;f++){for(n=e[f],s=t[f],p=f;p<=l-1;p++)r.set(p,f,r.get(p,f)-(n*t[p]+s*e[p]));e[f]=r.get(l-1,f),r.set(l,f,0)}}e[l]=u}for(l=0;l<i-1;l++){if(r.set(i-1,l,r.get(l,l)),r.set(l,l,1),u=e[l+1],u!==0){for(p=0;p<=l;p++)e[p]=r.get(p,l+1)/u;for(f=0;f<=l;f++){for(s=0,p=0;p<=l;p++)s+=r.get(p,l+1)*r.get(p,f);for(p=0;p<=l;p++)r.set(p,f,r.get(p,f)-s*e[p])}}for(p=0;p<=l;p++)r.set(p,l+1,0)}for(f=0;f<i;f++)e[f]=r.get(i-1,f),r.set(i-1,f,0);r.set(i-1,i-1,1),t[0]=0}function iw(i,t,e,r){let n,s,u,l,f,p,h,c,m,_,w,g,y,v,E,b;for(u=1;u<i;u++)t[u-1]=t[u];t[i-1]=0;let N=0,x=0,F=Number.EPSILON;for(p=0;p<i;p++){for(x=Math.max(x,Math.abs(e[p])+Math.abs(t[p])),h=p;h<i&&!(Math.abs(t[h])<=F*x);)h++;if(h>p)do{for(n=e[p],c=(e[p+1]-n)/(2*t[p]),m=Xr(c,1),c<0&&(m=-m),e[p]=t[p]/(c+m),e[p+1]=t[p]*(c+m),_=e[p+1],s=n-e[p],u=p+2;u<i;u++)e[u]-=s;for(N=N+s,c=e[h],w=1,g=w,y=w,v=t[p+1],E=0,b=0,u=h-1;u>=p;u--)for(y=g,g=w,b=E,n=w*t[u],s=w*c,m=Xr(c,t[u]),t[u+1]=E*m,E=t[u]/m,w=c/m,c=w*e[u]-E*n,e[u+1]=s+E*(w*n+E*e[u]),f=0;f<i;f++)s=r.get(f,u+1),r.set(f,u+1,E*r.get(f,u)+w*s),r.set(f,u,w*r.get(f,u)-E*s);c=-E*b*y*v*t[p]/_,t[p]=E*c,e[p]=w*c}while(Math.abs(t[p])>F*x);e[p]=e[p]+N,t[p]=0}for(u=0;u<i-1;u++){for(f=u,c=e[u],l=u+1;l<i;l++)e[l]<c&&(f=l,c=e[l]);if(f!==u)for(e[f]=e[u],e[u]=c,l=0;l<i;l++)c=r.get(l,u),r.set(l,u,r.get(l,f)),r.set(l,f,c)}}function sw(i,t,e,r){let n=0,s=i-1,u,l,f,p,h,c,m;for(c=n+1;c<=s-1;c++){for(m=0,p=c;p<=s;p++)m=m+Math.abs(t.get(p,c-1));if(m!==0){for(f=0,p=s;p>=c;p--)e[p]=t.get(p,c-1)/m,f+=e[p]*e[p];for(l=Math.sqrt(f),e[c]>0&&(l=-l),f=f-e[c]*l,e[c]=e[c]-l,h=c;h<i;h++){for(u=0,p=s;p>=c;p--)u+=e[p]*t.get(p,h);for(u=u/f,p=c;p<=s;p++)t.set(p,h,t.get(p,h)-u*e[p])}for(p=0;p<=s;p++){for(u=0,h=s;h>=c;h--)u+=e[h]*t.get(p,h);for(u=u/f,h=c;h<=s;h++)t.set(p,h,t.get(p,h)-u*e[h])}e[c]=m*e[c],t.set(c,c-1,m*l)}}for(p=0;p<i;p++)for(h=0;h<i;h++)r.set(p,h,p===h?1:0);for(c=s-1;c>=n+1;c--)if(t.get(c,c-1)!==0){for(p=c+1;p<=s;p++)e[p]=t.get(p,c-1);for(h=c;h<=s;h++){for(l=0,p=c;p<=s;p++)l+=e[p]*r.get(p,h);for(l=l/e[c]/t.get(c,c-1),p=c;p<=s;p++)r.set(p,h,r.get(p,h)+l*e[p])}}}function ow(i,t,e,r,n){let s=i-1,u=0,l=i-1,f=Number.EPSILON,p=0,h=0,c=0,m=0,_=0,w=0,g=0,y=0,v,E,b,N,x,F,M,S,$,C,I,R,U,q,k;for(v=0;v<i;v++)for((v<u||v>l)&&(e[v]=n.get(v,v),t[v]=0),E=Math.max(v-1,0);E<i;E++)h=h+Math.abs(n.get(v,E));for(;s>=u;){for(N=s;N>u&&(w=Math.abs(n.get(N-1,N-1))+Math.abs(n.get(N,N)),w===0&&(w=h),!(Math.abs(n.get(N,N-1))<f*w));)N--;if(N===s)n.set(s,s,n.get(s,s)+p),e[s]=n.get(s,s),t[s]=0,s--,y=0;else if(N===s-1){if(M=n.get(s,s-1)*n.get(s-1,s),c=(n.get(s-1,s-1)-n.get(s,s))/2,m=c*c+M,g=Math.sqrt(Math.abs(m)),n.set(s,s,n.get(s,s)+p),n.set(s-1,s-1,n.get(s-1,s-1)+p),S=n.get(s,s),m>=0){for(g=c>=0?c+g:c-g,e[s-1]=S+g,e[s]=e[s-1],g!==0&&(e[s]=S-M/g),t[s-1]=0,t[s]=0,S=n.get(s,s-1),w=Math.abs(S)+Math.abs(g),c=S/w,m=g/w,_=Math.sqrt(c*c+m*m),c=c/_,m=m/_,E=s-1;E<i;E++)g=n.get(s-1,E),n.set(s-1,E,m*g+c*n.get(s,E)),n.set(s,E,m*n.get(s,E)-c*g);for(v=0;v<=s;v++)g=n.get(v,s-1),n.set(v,s-1,m*g+c*n.get(v,s)),n.set(v,s,m*n.get(v,s)-c*g);for(v=u;v<=l;v++)g=r.get(v,s-1),r.set(v,s-1,m*g+c*r.get(v,s)),r.set(v,s,m*r.get(v,s)-c*g)}else e[s-1]=S+c,e[s]=S+c,t[s-1]=g,t[s]=-g;s=s-2,y=0}else{if(S=n.get(s,s),$=0,M=0,N<s&&($=n.get(s-1,s-1),M=n.get(s,s-1)*n.get(s-1,s)),y===10){for(p+=S,v=u;v<=s;v++)n.set(v,v,n.get(v,v)-S);w=Math.abs(n.get(s,s-1))+Math.abs(n.get(s-1,s-2)),S=$=.75*w,M=-.4375*w*w}if(y===30&&(w=($-S)/2,w=w*w+M,w>0)){for(w=Math.sqrt(w),$<S&&(w=-w),w=S-M/(($-S)/2+w),v=u;v<=s;v++)n.set(v,v,n.get(v,v)-w);p+=w,S=$=M=.964}for(y=y+1,x=s-2;x>=N&&(g=n.get(x,x),_=S-g,w=$-g,c=(_*w-M)/n.get(x+1,x)+n.get(x,x+1),m=n.get(x+1,x+1)-g-_-w,_=n.get(x+2,x+1),w=Math.abs(c)+Math.abs(m)+Math.abs(_),c=c/w,m=m/w,_=_/w,!(x===N||Math.abs(n.get(x,x-1))*(Math.abs(m)+Math.abs(_))<f*(Math.abs(c)*(Math.abs(n.get(x-1,x-1))+Math.abs(g)+Math.abs(n.get(x+1,x+1))))));)x--;for(v=x+2;v<=s;v++)n.set(v,v-2,0),v>x+2&&n.set(v,v-3,0);for(b=x;b<=s-1&&(q=b!==s-1,b!==x&&(c=n.get(b,b-1),m=n.get(b+1,b-1),_=q?n.get(b+2,b-1):0,S=Math.abs(c)+Math.abs(m)+Math.abs(_),S!==0&&(c=c/S,m=m/S,_=_/S)),S!==0);b++)if(w=Math.sqrt(c*c+m*m+_*_),c<0&&(w=-w),w!==0){for(b!==x?n.set(b,b-1,-w*S):N!==x&&n.set(b,b-1,-n.get(b,b-1)),c=c+w,S=c/w,$=m/w,g=_/w,m=m/c,_=_/c,E=b;E<i;E++)c=n.get(b,E)+m*n.get(b+1,E),q&&(c=c+_*n.get(b+2,E),n.set(b+2,E,n.get(b+2,E)-c*g)),n.set(b,E,n.get(b,E)-c*S),n.set(b+1,E,n.get(b+1,E)-c*$);for(v=0;v<=Math.min(s,b+3);v++)c=S*n.get(v,b)+$*n.get(v,b+1),q&&(c=c+g*n.get(v,b+2),n.set(v,b+2,n.get(v,b+2)-c*_)),n.set(v,b,n.get(v,b)-c),n.set(v,b+1,n.get(v,b+1)-c*m);for(v=u;v<=l;v++)c=S*r.get(v,b)+$*r.get(v,b+1),q&&(c=c+g*r.get(v,b+2),r.set(v,b+2,r.get(v,b+2)-c*_)),r.set(v,b,r.get(v,b)-c),r.set(v,b+1,r.get(v,b+1)-c*m)}}}if(h!==0){for(s=i-1;s>=0;s--)if(c=e[s],m=t[s],m===0)for(N=s,n.set(s,s,1),v=s-1;v>=0;v--){for(M=n.get(v,v)-c,_=0,E=N;E<=s;E++)_=_+n.get(v,E)*n.get(E,s);if(t[v]<0)g=M,w=_;else if(N=v,t[v]===0?n.set(v,s,M!==0?-_/M:-_/(f*h)):(S=n.get(v,v+1),$=n.get(v+1,v),m=(e[v]-c)*(e[v]-c)+t[v]*t[v],F=(S*w-g*_)/m,n.set(v,s,F),n.set(v+1,s,Math.abs(S)>Math.abs(g)?(-_-M*F)/S:(-w-$*F)/g)),F=Math.abs(n.get(v,s)),f*F*F>1)for(E=v;E<=s;E++)n.set(E,s,n.get(E,s)/F)}else if(m<0)for(N=s-1,Math.abs(n.get(s,s-1))>Math.abs(n.get(s-1,s))?(n.set(s-1,s-1,m/n.get(s,s-1)),n.set(s-1,s,-(n.get(s,s)-c)/n.get(s,s-1))):(k=ro(0,-n.get(s-1,s),n.get(s-1,s-1)-c,m),n.set(s-1,s-1,k[0]),n.set(s-1,s,k[1])),n.set(s,s-1,0),n.set(s,s,1),v=s-2;v>=0;v--){for(C=0,I=0,E=N;E<=s;E++)C=C+n.get(v,E)*n.get(E,s-1),I=I+n.get(v,E)*n.get(E,s);if(M=n.get(v,v)-c,t[v]<0)g=M,_=C,w=I;else if(N=v,t[v]===0?(k=ro(-C,-I,M,m),n.set(v,s-1,k[0]),n.set(v,s,k[1])):(S=n.get(v,v+1),$=n.get(v+1,v),R=(e[v]-c)*(e[v]-c)+t[v]*t[v]-m*m,U=(e[v]-c)*2*m,R===0&&U===0&&(R=f*h*(Math.abs(M)+Math.abs(m)+Math.abs(S)+Math.abs($)+Math.abs(g))),k=ro(S*_-g*C+m*I,S*w-g*I-m*C,R,U),n.set(v,s-1,k[0]),n.set(v,s,k[1]),Math.abs(S)>Math.abs(g)+Math.abs(m)?(n.set(v+1,s-1,(-C-M*n.get(v,s-1)+m*n.get(v,s))/S),n.set(v+1,s,(-I-M*n.get(v,s)-m*n.get(v,s-1))/S)):(k=ro(-_-$*n.get(v,s-1),-w-$*n.get(v,s),g,m),n.set(v+1,s-1,k[0]),n.set(v+1,s,k[1]))),F=Math.max(Math.abs(n.get(v,s-1)),Math.abs(n.get(v,s))),f*F*F>1)for(E=v;E<=s;E++)n.set(E,s-1,n.get(E,s-1)/F),n.set(E,s,n.get(E,s)/F)}for(v=0;v<i;v++)if(v<u||v>l)for(E=v;E<i;E++)r.set(v,E,n.get(v,E));for(E=i-1;E>=u;E--)for(v=u;v<=l;v++){for(g=0,b=u;b<=Math.min(E,l);b++)g=g+r.get(v,b)*n.get(b,E);r.set(v,E,g)}}}function ro(i,t,e,r){let n,s;return Math.abs(e)>Math.abs(r)?(n=r/e,s=e+n*r,[(i+n*t)/s,(t-n*i)/s]):(n=e/r,s=r+n*e,[(n*i+t)/s,(n*t-i)/s])}class Pc{constructor(t){if(t=ir.checkMatrix(t),!t.isSymmetric())throw new Error("Matrix is not symmetric");let e=t,r=e.rows,n=new pt(r,r),s=!0,u,l,f;for(l=0;l<r;l++){let p=0;for(f=0;f<l;f++){let h=0;for(u=0;u<f;u++)h+=n.get(f,u)*n.get(l,u);h=(e.get(l,f)-h)/n.get(f,f),n.set(l,f,h),p=p+h*h}for(p=e.get(l,l)-p,s&=p>0,n.set(l,l,Math.sqrt(Math.max(p,0))),f=l+1;f<r;f++)n.set(l,f,0)}this.L=n,this.positiveDefinite=!!s}isPositiveDefinite(){return this.positiveDefinite}solve(t){t=ir.checkMatrix(t);let e=this.L,r=e.rows;if(t.rows!==r)throw new Error("Matrix dimensions do not match");if(this.isPositiveDefinite()===!1)throw new Error("Matrix is not positive definite");let n=t.columns,s=t.clone(),u,l,f;for(f=0;f<r;f++)for(l=0;l<n;l++){for(u=0;u<f;u++)s.set(f,l,s.get(f,l)-s.get(u,l)*e.get(f,u));s.set(f,l,s.get(f,l)/e.get(f,f))}for(f=r-1;f>=0;f--)for(l=0;l<n;l++){for(u=f+1;u<r;u++)s.set(f,l,s.get(f,l)-s.get(u,l)*e.get(u,f));s.set(f,l,s.get(f,l)/e.get(f,f))}return s}get lowerTriangularMatrix(){return this.L}}class zc{constructor(t,e={}){t=ir.checkMatrix(t);let{Y:r}=e;const{scaleScores:n=!1,maxIterations:s=1e3,terminationCriteria:u=1e-10}=e;let l;if(r){if(Je.isAnyArray(r)&&typeof r[0]=="number"?r=pt.columnVector(r):r=ir.checkMatrix(r),r.rows!==t.rows)throw new Error("Y should have the same number of rows as X");l=r.getColumnVector(0)}else l=t.getColumnVector(0);let f=1,p,h,c,m;for(let _=0;_<s&&f>u;_++)c=t.transpose().mmul(l).div(l.transpose().mmul(l).get(0,0)),c=c.div(c.norm()),p=t.mmul(c).div(c.transpose().mmul(c).get(0,0)),_>0&&(f=p.clone().sub(m).pow(2).sum()),m=p.clone(),r?(h=r.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0)),h=h.div(h.norm()),l=r.mmul(h).div(h.transpose().mmul(h).get(0,0))):l=p;if(r){let _=t.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0));_=_.div(_.norm());let w=t.clone().sub(p.clone().mmul(_.transpose())),g=l.transpose().mmul(p).div(p.transpose().mmul(p).get(0,0)),y=r.clone().sub(p.clone().mulS(g.get(0,0)).mmul(h.transpose()));this.t=p,this.p=_.transpose(),this.w=c.transpose(),this.q=h,this.u=l,this.s=p.transpose().mmul(p),this.xResidual=w,this.yResidual=y,this.betas=g}else this.w=c.transpose(),this.s=p.transpose().mmul(p).sqrt(),n?this.t=p.clone().div(this.s.get(0,0)):this.t=p,this.xResidual=t.sub(p.mmul(c.transpose()))}}Pt.AbstractMatrix=$t,Pt.CHO=Pc,Pt.CholeskyDecomposition=Pc,Pt.DistanceMatrix=Vs,Pt.EVD=Lc;var aw=Pt.EigenvalueDecomposition=Lc;Pt.LU=to,Pt.LuDecomposition=to;var qc=Pt.Matrix=pt;Pt.MatrixColumnSelectionView=k1,Pt.MatrixColumnView=U1,Pt.MatrixFlipColumnView=W1,Pt.MatrixFlipRowView=Y1,Pt.MatrixRowSelectionView=Z1,Pt.MatrixRowView=j1,Pt.MatrixSelectionView=Qs,Pt.MatrixSubView=G1,Pt.MatrixTransposeView=K1,Pt.NIPALS=zc,Pt.Nipals=zc,Pt.QR=Ta,Pt.QrDecomposition=Ta,Pt.SVD=gi,Pt.SingularValueDecomposition=gi,Pt.SymmetricMatrix=kn,Pt.WrapperMatrix1D=Oc,Pt.WrapperMatrix2D=ir,Pt.correlation=rw,Pt.covariance=ew;var Uc=Pt.default=pt;Pt.determinant=eo,Pt.inverse=J1,Pt.linearDependencies=Q1,Pt.pseudoInverse=tw,Pt.solve=Rc,Pt.wrap=H1;const kc=aw,Wc=qc;Uc.Matrix&&Uc.Matrix;class uw{new({rows:t,columns:e,initial_value:r}={}){return new $a(t,e,r)}avg({id:t}){return t==null?void 0:t.avg()}col({id:t,column:e}){return t==null?void 0:t.col({column:e})}det({id:t}){return t==null?void 0:t.det()}get({id:t,row:e,column:r}){return t==null?void 0:t.get({row:e,column:r})}inv({id:t}){return t==null?void 0:t.inv()}max({id:t}){return t==null?void 0:t.max()}min({id:t}){return t==null?void 0:t.min()}pow({id:t,power:e}){return t==null?void 0:t.pow({power:e})}row({id:t,row:e}){return t==null?void 0:t.row({row:e})}set({id:t,row:e,column:r,value:n}){t==null||t.set({row:e,column:r,value:n})}sum({id:t,id2:e}){return t==null?void 0:t.sum({id2:e})}copy({id:t}){return t==null?void 0:t.copy()}diff({id:t,id2:e}){return t==null?void 0:t.diff({id2:e})}rows({id:t}){return t==null?void 0:t.rows()}columns({id:t}){return t==null?void 0:t.columns()}fill({id:t,value:e,from_row:r,to_row:n,from_column:s,to_column:u}){t==null||t.fill({value:e,from_row:r,to_row:n,from_column:s,to_column:u})}kron({id:t,id2:e}){return t==null?void 0:t.kron({id2:e})}mode({id:t}){return t==null?void 0:t.mode()}mult({id:t,id2:e}){return t==null?void 0:t.mult({id2:e})}pinv({id:t}){return t==null?void 0:t.pinv()}rank({id:t}){return t==null?void 0:t.rank()}sort({id:t,column:e,order:r}){t==null||t.sort({column:e,order:r})}trace({id:t}){return t==null?void 0:t.trace()}concat({id:t,id2:e}){return t==null?void 0:t.concat({id2:e})}median({id:t}){return t==null?void 0:t.median()}add_col({id:t,column:e,array_id:r}){t==null||t.add_col({column:e,array_id:r})}add_row({id:t,row:e,array_id:r}){t==null||t.add_row({row:e,array_id:r})}is_zero({id:t}){return t==null?void 0:t.is_zero()}reshape({id:t,rows:e,columns:r}){return t==null?void 0:t.reshape({rows:e,columns:r})}reverse({id:t}){t==null||t.reverse()}is_binary({id:t}){return t==null?void 0:t.is_binary()}is_square({id:t}){return t==null?void 0:t.is_square()}submatrix({id:t,from_row:e,to_row:r,from_column:n,to_column:s}){return t==null?void 0:t.submatrix({from_row:e,to_row:r,from_column:n,to_column:s})}swap_rows({id:t,row1:e,row2:r}){t==null||t.swap_rows({row1:e,row2:r})}transpose({id:t}){return t==null?void 0:t.transpose()}remove_col({id:t,column:e}){return t==null?void 0:t.remove_col({column:e})}remove_row({id:t,row:e}){return t==null?void 0:t.remove_row({row:e})}eigenvalues({id:t}){return t==null?void 0:t.eigenvalues()}is_diagonal({id:t}){return t==null?void 0:t.is_diagonal()}is_identity({id:t}){return t==null?void 0:t.is_identity()}eigenvectors({id:t}){return t==null?void 0:t.eigenvectors()}is_symmetric({id:t}){return t==null?void 0:t.is_symmetric()}swap_columns({id:t,column1:e,column2:r}){t==null||t.swap_columns({column1:e,column2:r})}is_stochastic({id:t}){return t==null?void 0:t.is_stochastic()}is_triangular({id:t}){return t==null?void 0:t.is_triangular()}elements_count({id:t}){return t==null?void 0:t.elements_count()}is_antidiagonal({id:t}){return t==null?void 0:t.is_antidiagonal()}is_antisymmetric({id:t}){return t==null?void 0:t.is_antisymmetric()}}class $a{constructor(t=0,e=0,r=void 0){Z(this,"_matrixInstance");this._matrixInstance=this._createMatrix(t,e,r)}get _matrixArray(){return this._matrixInstance.map(t=>[...t._value])}get _value(){return this._matrixInstance}set _value(t){this._matrixInstance=t}get isMatrix(){return!0}_createMatrix(t,e,r){return Array.from(new Array(t),()=>new Jt(e,r))}avg(){let t=0,e=0;for(const n of this._matrixInstance)for(const s of n._value)t+=s,e+=1;return t/e}col({column:t=0}){const e=[];for(const n of this._matrixInstance)e.push(n._value[t]);const r=new Jt;return r._value=e,r}det(){return Mc(this._matrixArray)}get({row:t=0,column:e=0}){var r,n;return(n=(r=this._matrixInstance[t])==null?void 0:r._value)==null?void 0:n[e]}inv(){const t=Ks(this._matrixArray);return this._newMatrix(t)}max(){return e1(this._matrixArray)}min(){return Na(this._matrixArray)}pow({power:t}){const e=n1(this._matrixArray,t);return this._newMatrix(e)}row({row:t=0}){return this._matrixInstance[t]}set({row:t,column:e,value:r}){this._matrixInstance[t].set({index:e,value:r})}sum({id2:t}){const e=Zi(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}copy(){return this._newMatrix(this._matrixArray)}diff({id2:t}){const e=H_(this._matrixArray,typeof t=="number"?t:t._matrixArray);return this._newMatrix(e)}rows(){return this._matrixInstance.length}columns(){return this._matrixArray.length&&this._matrixArray[0].length}fill({value:t,from_row:e=0,to_row:r=this.rows(),from_column:n=0,to_column:s=this.columns()}={}){for(const[u,l]of this._matrixInstance.entries())for(const[f]of l._value.entries())u<r&&u>=e&&f>=n&&f<s&&l.set({index:f,value:t})}kron({id2:t}){const e=G_(this._matrixArray,t._matrixArray);return this._newMatrix(e)}mode(){return Na(yc(this._matrixArray))}mult({id2:t}){const e=typeof t=="number"?t:t._matrixArray?t._matrixArray:t._value,r=ci(this._matrixArray,e);return this._newMatrix(r)}pinv(){const t=r1(this._matrixArray);return this._newMatrix(t)}rank(){return this._matrixRank(this._matrixArray)}sort({column:t=0,order:e=Rn.ascending}={}){this._matrixInstance.sort((r,n)=>{const s=r._value[t],u=n._value[t];return e!==Rn.descending?s-u:u-s})}trace(){return t1(this._matrixArray)}concat({id2:t}){for(const e of t._value)this._matrixInstance.push(e);return this}median(){return Nc(this._matrixArray)}add_col({column:t=this.columns(),array_id:e}={}){for(const[r,n]of this._matrixInstance.entries())n.set({index:t,value:e?e._value[r]:void 0})}add_row({row:t,array_id:e}){this._matrixInstance.splice(t||this.rows(),0,e||new Jt(this.columns()))}is_zero(){return this._matrixArray.every(t=>t.every(e=>e===0))}reshape({rows:t,columns:e}){const r=W_(this._matrixArray,[t,e]);this._matrixInstance=r.map(n=>{const s=new Jt;return s._value=[...n],s})}reverse(){this._matrixInstance.reverse();for(const t of this._matrixInstance)t._value.reverse()}is_binary(){return this._matrixArray.every(t=>t.every(e=>e===0||e===1))}is_square(){return this.rows()===this.columns()}submatrix({from_row:t=0,to_row:e=this.rows(),from_column:r=0,to_column:n=this.columns()}={}){const s=this._matrixArray.splice(t,e-1),u=[];for(const l of s)u.push(l.splice(r,n-1));return this._newMatrix(u)}swap_rows({row1:t,row2:e}){const r=this._matrixInstance[t],n=this._matrixInstance[e];this._matrixInstance[t]=n,this._matrixInstance[e]=r}transpose(){const t=Ec(this._matrixArray);return this._newMatrix(t)}remove_col({column:t=this.columns()}={}){const e=[];for(const n of this._matrixInstance){const s=n._value.splice(t,1);e.push(s[0])}const r=new Jt;return r._value=e,r}remove_row({row:t=this.rows()}={}){return this._matrixInstance.splice(t,1)[0]}eigenvalues(){const t=new kc(new Wc(this._matrixArray)),e=new Jt;return e._value=t.realEigenvalues,e}is_diagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0)return!1;return!0}is_identity(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<e;s++)if(n!==s&&r[n][s]!==0||n===s&&r[n][s]!==1)return!1;return!0}eigenvectors(){const t=new kc(new Wc(this._matrixArray));return this._newMatrix(t.eigenvectorMatrix.to2DArray())}is_symmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=n+1;s<e;s++)if(r[n][s]!==r[s][n])return!1;return!0}swap_columns({column1:t,column2:e}){for(const r of this._matrixInstance){const n=r._value[t],s=r._value[e];r.set({index:t,value:s}),r.set({index:e,value:n})}}is_stochastic(){const t=this._matrixArray;for(let e=0;e<t.length;e++){let r=0;for(let n=0;n<t[e].length;n++){if(t[e][n]<0)return!1;r+=t[e][n]}if(Math.abs(r-1)>Number.EPSILON)return!1}return!0}is_triangular(){const t=this.rows(),e=this.columns();return t!==e?!1:this._isUpperTriangular(t)||this._isLowerTriangular(t)}elements_count(){return Y_(this._matrixArray)}is_antidiagonal(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n+s!==t-1&&r[n][s]!==0)return!1;return!0}is_antisymmetric(){const t=this.rows(),e=this.columns();if(t!==e)return!1;const r=this._matrixArray;for(let n=0;n<t;n++)for(let s=0;s<t;s++)if(n!==s&&r[n][s]!==-r[s][n])return!1;return!0}_isUpperTriangular(t){const e=this._matrixArray;for(let r=1;r<t;r++)for(let n=0;n<r;n++)if(e[r][n]!==0)return!1;return!0}_isLowerTriangular(t){const e=this._matrixArray;for(let r=0;r<t-1;r++)for(let n=r+1;n<t;n++)if(e[r][n]!==0)return!1;return!0}_newMatrix(t){const e=new $a;return e._value=t.map(r=>{const n=new Jt;return n._value=[...r],n}),e}_matrixRank(t){let e=0;const r=t.length,n=t[0].length,s=[...t].map(u=>[...u]);for(let u=0;u<r&&!(u>=n);u++){let l=u;for(;l<r&&s[l][u]===0;)l++;if(l===r)continue;if(l!==u){const p=s[l];s[l]=s[u],s[u]=p}const f=s[u][u];for(let p=0;p<n;p++)s[u][p]/=f;for(let p=u+1;p<r;p++){const h=s[p][u];s[p]=s[p].map((c,m)=>c-h*s[u][m]),s[p][u]=0}}for(let u=0;u<r;u++)s[u].some(l=>Number(l.toFixed(8))!==0)&&e++;return e}}class lw{constructor(t){Z(this,"_variables");Z(this,"_cacheData");this._variables=t,this._cacheData={}}change({timeframe:t},e){const r=Tn(t),n=Tn(this._variables.timeframe.period);if(r<n)return!0;const s=`change_${e}`,u=this._cacheData[s],l=this._variables.time;if(u){if(u.offset){if(u.currentTime+u.offset<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else if(u.currentTime+r*1e3<=l)return this._cacheData[s]={currentTime:l,offset:0},!0}else{const f=this._calcTimeOffset(l,t);return this._cacheData[s]={currentTime:l,offset:f},!1}return!1}in_seconds({timeframe:t}={}){return Tn(t||this._variables.timeframe.period)}from_seconds({seconds:t=0}){const e=t*1e3,r=ne.duration(e);if(r.years())return"12M";const s=r.asMonths();if(Zs(s))return`${s}M`;const u=r.asWeeks();if(Zs(u))return`${u}M`;const l=r.asDays();if(l>=1)return`${Math.ceil(l)}D`;const f=r.asMinutes();if(f>=1)return`${Math.ceil(f)}`;const p=r.asSeconds();return p<=1?"1S":p<=5?"5S":p<=10?"10S":p<=15?"15S":p<=30?"30S":"1"}_calcTimeOffset(t,e){let r=0;if(e.includes("W")){const l=ne(t).day();e="1D",l!==1&&(r=(8-l)*60*60*24*1e3)}else if(e.includes("M")){const l=ne(t).date();e="1D";const f=ne(t).daysInMonth();l!==1&&(r=(f-l+1)*60*60*24*1e3)}const n=this._variables.getTimeTradingday(t,e),s=Tn(e)*1e3,u=t-n-Math.floor((t-n)/s)*s;return r?r-u:u}}class fw{pos({source:t,str:e}){return t==null?void 0:t.indexOf(e)}trim({source:t}){return t==null?void 0:t.trim()}lower({source:t}){return t==null?void 0:t.toLocaleLowerCase()}match({source:t,regex:e}){const r=t==null?void 0:t.match(new RegExp(e));return r?r[0]:""}split({string:t,separator:e}){const r=t==null?void 0:t.split(e),n=new Jt;return n._value=r||[],n}upper({source:t}){return t==null?void 0:t.toLocaleUpperCase()}format({formatString:t},e){return this._strFormat(t,e)}length({string:t}){return t==null?void 0:t.length}repeat({source:t,repeat:e=0,separator:r=""}){return Array.from(new Array(e),()=>t).join(r)}replace({source:t,target:e,replacement:r,occurrence:n=0}){let s=-1;for(let u=0;u<n+1&&(s=t.indexOf(e,s+1),s!==-1);u++);return s!==-1?t.substring(0,s)+r+t.substring(s+e.length):t}contains({source:t,str:e}){return t==null?void 0:t.includes(e)}endswith({source:t,str:e}){return t==null?void 0:t.endsWith(e)}tonumber({string:t}){if(/[^\d.]/.test(t))return;const e=parseFloat(t);return isNaN(e)?void 0:e}tostring({value:t,format:e}){if(t===void 0)return"NaN";if(typeof t=="object"){if(t.isArray)return this._arrToStr(t._value,e);if(t.isMatrix){const r=[];for(const n of t._matrixArray)r.push(this._arrToStr(n,e));return r.join(`
62
62
  `)}}if(typeof t=="string")return t;if(typeof t=="boolean")return String(t);if(typeof t=="number")return this._formatNumber(t,e)}_arrToStr(t,e){return`[${t.map(n=>typeof n=="number"?this._formatNumber(n,e):n).toString()}]`}substring({source:t,begin_pos:e=0,end_pos:r}){return t==null?void 0:t.substring(e,r)}startswith({source:t,str:e}){return t==null?void 0:t.startsWith(e)}format_time({time:t,format:e="yyyy-MM-dd'T'HH:mm:ssZ",timezone:r}){return Mr(t,r).format(e)}replace_all({source:t,target:e,replacement:r}){return t==null?void 0:t.replace(new RegExp(e,"g"),r)}_formatNumber(t,e){if(!e)return t;switch(e){case"integer":return String(Math.round(t));case"currency":return`$${t}`;case"percent":return`${t*100}%`;default:const r=e.split(".")[1],n=r?r.length:0;return parseFloat(t.toFixed(n))}}_strFormat(t,e){let r=t;return e.forEach((n,s)=>{if(typeof n=="number"){const u=`\\{\\s*${s}\\s*,\\s*number\\s*,\\s*([^\\}]+)\\s*\\}`,l=t.match(new RegExp(u));if(l){const f=l[1];r=r.replace(new RegExp(u,"g"),String(this._formatNumber(n,f)))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),String(n))}else r=r.replace(new RegExp(`\\{${s}\\}`,"g"),n)}),r}}class cw{new(){return new Oa}copy({id:t}){return t==null?void 0:t.copy()}get({id:t,key:e}){return t==null?void 0:t.get({key:e})}put({id:t,key:e,value:r}){return t==null?void 0:t.put({key:e,value:r})}keys({id:t}){return t==null?void 0:t.keys()}size({id:t}){return t==null?void 0:t.size()}clear({id:t}){t==null||t.clear()}remove({id:t,key:e}){return t==null?void 0:t.remove({key:e})}values({id:t}){return t==null?void 0:t.values()}put_all({id:t,id2:e}){t==null||t.put_all({id2:e})}contains({id:t,key:e}){return t==null?void 0:t.contains({key:e})}}class Oa{constructor(){Z(this,"_mapInstance");this._mapInstance=new Map}get isMap(){return!0}_copyMap(t){const e=new Oa;return e._mapInstance=new Map(t.entries()),e}copy(){return this._copyMap(this._mapInstance)}get({key:t}){return this._mapInstance.get(t)}put({key:t,value:e}){return this._mapInstance.set(t,e)}keys(){const t=new Jt;return t._value=[...this._mapInstance.keys()],t}size(){return this._mapInstance.size}clear(){this._mapInstance.clear()}remove({key:t}){const e=this._mapInstance.get(t);return this._mapInstance.delete(t),e||void 0}values(){const t=new Jt;return t._value=[...this._mapInstance.values()],t}put_all({id2:t}){this._mapInstance=new Map([...this._mapInstance,...t._mapInstance])}contains({key:t}){return this._mapInstance.has(t)}}class hw{constructor(t){Z(this,"_variables");this._variables=t}new({price:t,time:e,index:r}){return new Wn(t,r,e)}now({price:t}){const{time:e,bar_index:r}=this._variables;return new Wn(t,r,e)}copy({id:t}){const{price:e,time:r,index:n}=t||{};return new Wn(e,n,r)}from_index({price:t,index:e}){return new Wn(t,e)}from_time({price:t,time:e}){return new Wn(t,void 0,e)}}class Wn{constructor(t,e,r){Z(this,"_index");Z(this,"_price");Z(this,"_time");this._index=e,this._price=t,this._time=r}get index(){return this._index}get price(){return this._price}get time(){return this._time}copy(){return new Wn(this._price,this._index,this._time)}}class pw{constructor(t){Z(this,"_variables");Z(this,"_defaultLabel",{text:"",xloc:Ie.bar_index,yloc:zi.price,size:qr.normal,style:me.styleLabelDown,textalign:Ke.alignCenter});this._variables=t}new(t,e){const r=`label_${e}`,n={...this._defaultLabel,...t,id:r};t.point&&(n.x=n.xloc===Ie.bar_index?t.point.index:t.point.time,n.y=t.point.price);const s=new Ki(r,this._variables);return this._variables.label.add(r,n,s),s}label(t,e){return t.x?t.x:new Ki(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}get_x({id:t},e){return t==null?void 0:t.get_x(e)}get_y({id:t},e){return t==null?void 0:t.get_y(e)}set_x({id:t,...e},r){t==null||t.set_x(e,r)}set_y({id:t,...e},r){t==null||t.set_y(e,r)}delete({id:t}){t==null||t.delete()}get_text({id:t},e){return t==null?void 0:t.get_text(e)}set_xy({id:t,...e},r){t==null||t.set_xy(e,r)}set_size({id:t,...e},r){t==null||t.set_size(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}set_yloc({id:t,...e},r){t==null||t.set_yloc(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_tooltip({id:t,...e},r){t==null||t.set_tooltip(e,r)}set_point({id:t,...e},r){t==null||t.set_point(e,r)}set_text({id:t,...e},r){t==null||t.set_text(e,r)}set_textcolor({id:t,...e},r){t==null||t.set_textcolor(e,r)}set_textalign({id:t,...e},r){t==null||t.set_textalign(e,r)}set_text_font_family({id:t,...e},r){t==null||t.set_text_font_family(e,r)}}class Ki{constructor(t,e){Z(this,"_id");Z(this,"_variables");this._id=t,this._variables=e}copy(t){const e=`label_${t}`,r=this._getLabel(t),n=new Ki(e,this._variables);return r&&this._variables.label.add(e,{...r,id:e},n),n}get_x(t){var e;return(e=this._getLabel(t))==null?void 0:e.x}get_y(t){var e;return(e=this._getLabel(t))==null?void 0:e.y}set_x({x:t},e){const r=this._getLabel(e);r&&(r.x=t)}set_y({y:t},e){const r=this._getLabel(e);r&&(r.y=t)}delete(){this._variables.label.delete(this._id)}set_xy({x:t,y:e},r){const n=this._getLabel(r);n&&(n.x=t,n.y=e)}get_text(t){var e;return(e=this._getLabel(t))==null?void 0:e.text}set_size({size:t},e){const r=this._getLabel(e);r&&(r.size=t)}set_text({text:t},e){const r=this._getLabel(e);r&&(r.text=t)}set_xloc({x:t,xloc:e},r){const n=this._getLabel(r);n&&(n.x=t,n.xloc=e)}set_yloc({yloc:t},e){const r=this._getLabel(e);r&&(r.yloc=t)}set_color({color:t},e){const r=this._getLabel(e);r&&(r.color=t)}set_point({point:t},e){const r=this._getLabel(e);r&&(r.x=r.xloc===Ie.bar_index?t==null?void 0:t.index:t==null?void 0:t.time,r.y=t==null?void 0:t.price)}set_style({style:t},e){const r=this._getLabel(e);r&&(r.style=t)}set_tooltip({tooltip:t},e){const r=this._getLabel(e);r&&(r.tooltip=t)}set_textalign({textalign:t},e){const r=this._getLabel(e);r&&(r.textalign=t)}set_textcolor({textcolor:t},e){const r=this._getLabel(e);r&&(r.textcolor=t)}set_text_font_family({text_font_family:t},e){const r=this._getLabel(e);r&&(r.text_font_family=t)}_getLabel(t){const e=this._variables.label.get(this._id);return e||console.log(`错误${t}: label 不存在`),e}}const dw={freq_all:fn.freqAll,freq_once_per_bar:fn.freqOncePerBar,freq_once_per_bar_close:fn.freqOncePerBarClose},mw={gaps_off:Li.gapsOff,gaps_on:Li.gapsOn,lookahead_off:Li.lookaheadOff,lookahead_on:Li.lookaheadOn},vi={aqua:"#00BCD4",black:"#363A45",blue:"#2196F3",fuchsia:"#E040FB",gray:"#787B86",green:"#4CAF50",lime:"#00E676",maroon:"#880E4F",navy:"#311B92",olive:"#808000",orange:"#FF9800",purple:"#9C27B0",red:"#FF5252",silver:"#B2B5BE",teal:"#00897B",white:"#FFFFFF",yellow:"#FFEB3B"},Yc={AUD:"AUD",BTC:"BTC",CAD:"CAD",CHF:"CHF",ETH:"ETH",EUR:"EUR",GBP:"GBP",HKD:"HKD",INR:"INR",JPY:"JPY",KRW:"KRW",MYR:"MYR",NOK:"NOK",NONE:"NONE",NZD:"NZD",RUB:"RUB",SEK:"SEK",SGD:"SGD",TRY:"TRY",USD:"USD",USDT:"USDT",ZAR:"ZAR"},gw={friday:6,monday:2,saturday:7,sunday:1,thursday:5,tuesday:3,wednesday:4},vw={all:[er.dataWindow,er.pane,er.priceScale,er.statusLine],data_window:[er.dataWindow],none:[],pane:[er.pane],price_scale:[er.priceScale],status_line:[er.statusLine]},_w={both:$n.both,left:$n.left,none:$n.none,right:$n.right},ww={inherit:On.inherit,mintick:On.mintick,percent:On.percent,price:On.price,volume:On.volume},Dw={style_solid:vs.styleSolid,style_dashed:vs.styleDashed,style_dotted:vs.styleDotted},yw={style_arrowdown:me.styleArrowdown,style_arrowup:me.styleArrowup,style_circle:me.styleCircle,style_cross:me.styleCross,style_diamond:me.styleDiamond,style_flag:me.styleFlag,style_label_center:me.styleLabelCenter,style_label_down:me.styleLabelDown,style_label_left:me.styleLabelLeft,style_label_lower_left:me.styleLabelLowerLeft,style_label_lower_right:me.styleLabelLowerRight,style_label_right:me.styleLabelRight,style_label_up:me.styleLabelUp,style_label_upper_left:me.styleLabelUpperLeft,style_label_upper_right:me.styleLabelUpperRight,style_none:me.styleNone,style_square:me.styleSquare,style_text_outline:me.styleTextOutline,style_triangledown:me.styleTriangledown,style_triangleup:me.styleTriangleup,style_xcross:me.styleXcross},bw={style_arrow_both:zr.styleArrowBoth,style_arrow_left:zr.styleArrowLeft,style_arrow_right:zr.styleArrowRight,style_dashed:zr.styleDashed,style_dotted:zr.styleDotted,style_solid:zr.styleSolid},Ew={abovebar:ri.abovebar,absolute:ri.absolute,belowbar:ri.belowbar,bottom:ri.bottom,top:ri.top},Aw={e:2.718281828459045,phi:1.618033988749895,pi:3.141592653589793,rphi:.6180339887498948},xw={style_area:mr.styleArea,style_areabr:mr.styleAreabr,style_circles:mr.styleCircles,style_columns:mr.styleColumns,style_cross:mr.styleCross,style_histogram:mr.styleHistogram,style_line:mr.styleLine,style_linebr:mr.styleLinebr,style_stepline:mr.styleStepline,style_stepline_diamond:mr.styleSteplineDiamond,style_steplinebr:mr.styleSteplinebr},Cw={bottom_center:Nr.bottomCenter,bottom_left:Nr.bottomLeft,bottom_right:Nr.bottomRight,middle_center:Nr.middleCenter,middle_left:Nr.middleLeft,middle_right:Nr.middleRight,top_center:Nr.topCenter,top_left:Nr.topLeft,top_right:Nr.topRight},Fw={left:_s.left,none:_s.none,right:_s.right},Mw={arrowdown:rr.arrowdown,arrowup:rr.arrowup,circle:rr.circle,cross:rr.cross,diamond:rr.diamond,flag:rr.flag,labeldown:rr.labeldown,labelup:rr.labelup,square:rr.square,triangledown:rr.triangledown,triangleup:rr.triangleup,xcross:rr.xcross},Nw={auto:qr.auto,huge:qr.huge,large:qr.large,normal:qr.normal,small:qr.small,tiny:qr.tiny},Sw={cash:Gr.cash,fixed:Gr.fixed,percent_of_equity:Gr.percentOfEquity,commission:{cash_per_contract:Pi.cashPerContract,cash_per_order:Pi.cashPerOrder,percent:Pi.percent},direction:{all:Ge.all,long:Ge.long,short:Ge.short},oca:{cancel:Ln.cancel,none:Ln.none,reduce:Ln.reduce}},Bw={align_bottom:Ke.alignBottom,align_center:Ke.alignCenter,align_left:Ke.alignLeft,align_right:Ke.alignRight,align_top:Ke.alignTop,wrap_auto:Ke.wrapAuto,wrap_none:Ke.wrapNone},Iw={bar_index:Ie.bar_index,bar_time:Ie.bar_time},Tw={abovebar:zi.abovebar,belowbar:zi.belowbar,price:zi.price},$w={actual:ws.actual,estimate:ws.estimate,standardized:ws.standardized};class Ow{constructor(){Z(this,"adjustment",{dividends:gs.dividends,none:gs.none,splits:gs.splits});Z(this,"alert",dw);Z(this,"barmerge",mw);Z(this,"color",vi);Z(this,"currency",Yc);Z(this,"dayofweek",gw);Z(this,"earnings",$w);Z(this,"display",vw);Z(this,"extend",_w);Z(this,"font",{family_default:"SimSun",family_monospace:"Monospace"});Z(this,"format",ww);Z(this,"hline",Dw);Z(this,"label",yw);Z(this,"line",bw);Z(this,"location",Ew);Z(this,"math",Aw);Z(this,"order",{ascending:Rn.ascending,descending:Rn.descending});Z(this,"plot",xw);Z(this,"position",Cw);Z(this,"scale",Fw);Z(this,"session",{extended:ra.extended,regular:ra.regular});Z(this,"shape",Mw);Z(this,"size",Nw);Z(this,"splits",{denominator:"denominator",numerator:"numerator"});Z(this,"strategy",Sw);Z(this,"text",Bw);Z(this,"xloc",Iw);Z(this,"yloc",Tw)}updateData(){}}class Rw{constructor(t){Z(this,"_variables");Z(this,"_defaultPolyline",{curved:!1,closed:!1,xloc:Ie.bar_index,line_color:vi.blue,line_style:zr.styleSolid,line_width:1});this._variables=t}new(t,e){const r=`polyline_${e}`,n=Object.assign({},this._defaultPolyline,t,{id:r}),s=new jc(r,this._variables);return this._variables.polyline.add(r,n,s),s}delete({id:t}){t&&t.delete()}}class jc{constructor(t,e){Z(this,"_id");Z(this,"_variables");this._variables=e,this._id=t}delete(){this._variables.polyline.delete(this._id)}}class Lw{constructor(t){Z(this,"_variables");Z(this,"_defaultLine",{xloc:Ie.bar_index,extend:$n.none,style:zr.styleSolid});this._variables=t}new({first_point:t,second_point:e,...r},n){const s=`line_${n}`,u={...this._defaultLine,...r,id:s};if(t&&e){const f=u.xloc===Ie.bar_index?t.index:t.time,p=u.xloc===Ie.bar_index?e.index:e.time;Object.assign(u,{x1:f,y1:t.price,x2:p,y2:e.price})}const l=new Hi(s,this._variables);return this._variables.line.add(s,u,l),l}line(t,e){return t.x?t.x:new Hi(e,this._variables)}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_x1({id:t},e){return t==null?void 0:t.get_x1(e)}get_x2({id:t},e){return t==null?void 0:t.get_x2(e)}get_y1({id:t},e){return t==null?void 0:t.get_y1(e)}get_y2({id:t},e){return t==null?void 0:t.get_y2(e)}set_x1({id:t,...e},r){t==null||t.set_x1(e,r)}set_x2({id:t,...e},r){t==null||t.set_x2(e,r)}set_y1({id:t,...e},r){t==null||t.set_y1(e,r)}set_y2({id:t,...e},r){t==null||t.set_y2(e,r)}set_xy1({id:t,...e},r){t==null||t.set_xy1(e,r)}set_xy2({id:t,...e},r){t==null||t.set_xy2(e,r)}set_xloc({id:t,...e},r){t==null||t.set_xloc(e,r)}get_price({id:t,...e},r){return t==null?void 0:t.get_price(e,r)}set_color({id:t,...e},r){t==null||t.set_color(e,r)}set_style({id:t,...e},r){t==null||t.set_style(e,r)}set_width({id:t,...e},r){t==null||t.set_width(e,r)}set_extend({id:t,...e},r){t==null||t.set_extend(e,r)}set_first_point({id:t,...e},r){t==null||t.set_first_point(e,r)}set_second_point({id:t,...e},r){t==null||t.set_second_point(e,r)}}class Hi{constructor(t,e){Z(this,"_variables");Z(this,"_id");this._id=t,this._variables=e}get data(){return this._variables.line.get(this._id)}copy(t){const e=`line_${t}`,r=this._getLine(t),n=new Hi(e,this._variables);return r&&this._variables.line.add(e,{...r,id:e},n),n}delete(){this._variables.line.delete(this._id)}get_price({x:t},e){const r=this._getLine(e);if(t===void 0)return t;if(r&&r.xloc===Ie.bar_index){const{x1:n,y1:s,x2:u,y2:l}=r;return n===void 0||u===void 0||s===void 0||l===void 0?void 0:(l-s)/(u-n)*(t-n)+s}}get_x1(t){var e;return(e=this._getLine(t))==null?void 0:e.x1}get_x2(t){var e;return(e=this._getLine(t))==null?void 0:e.x2}get_y1(t){var e;return(e=this._getLine(t))==null?void 0:e.y1}get_y2(t){var e;return(e=this._getLine(t))==null?void 0:e.y2}set_x1({x:t},e){const r=this._getLine(e);r&&(r.x1=t)}set_x2({x:t},e){const r=this._getLine(e);r&&(r.x2=t)}set_y1({y:t},e){const r=this._getLine(e);r&&(r.y1=t)}set_y2({y:t},e){const r=this._getLine(e);r&&(r.y2=t)}set_xy1({x:t,y:e},r){const n=this._getLine(r);n&&(n.x1=t,n.y1=e)}set_xy2({x:t,y:e},r){const n=this._getLine(r);n&&(n.x2=t,n.y2=e)}set_xloc({xloc:t,x1:e,x2:r},n){const s=this._getLine(n);s&&(s.xloc=t,s.x1=e,s.x2=r)}set_color({color:t},e){const r=this._getLine(e);r&&(r.color=t)}set_style({style:t},e){const r=this._getLine(e);r&&(r.style=t)}set_width({width:t},e){const r=this._getLine(e);r&&(r.width=t)}set_extend({extend:t},e){const r=this._getLine(e);r&&(r.extend=t)}set_first_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:u}=t||{},l=r.xloc===Ie.bar_index?n:s,f=u;l&&(r.x1=l),f&&(r.y1=f)}}set_second_point({point:t},e){const r=this._getLine(e);if(r){const{index:n,time:s,price:u}=t||{},l=r.xloc===Ie.bar_index?n:s,f=u;l&&(r.x2=l),f&&(r.y2=f)}}_getLine(t){const e=this._variables.line.get(this._id);return e||console.log(`${t}: line 不存在`),e}}class Pw{constructor(t){Z(this,"_variables");this._variables=t}new({line1:t,line2:e,color:r},n){const s=`linefill_${n}`,u=t==null?void 0:t.data,l=e==null?void 0:e.data;u&&(u.linefills=u.linefills||[],u.linefills.push(s)),l&&(l.linefills=l.linefills||[],l.linefills.push(s));const f=new no(this._variables,s,t,e);return(u||l)&&this._variables.linefill.add(s,{line1:u,line2:l,color:r,id:s},f),f}delete({id:t}){t==null||t.delete()}get_line1({id:t}){return t==null?void 0:t.get_line1()}get_line2({id:t}){return t==null?void 0:t.get_line2()}set_color({id:t,...e}){t==null||t.set_color(e)}}class no{constructor(t,e,r,n){Z(this,"_id");Z(this,"_line1");Z(this,"_line2");Z(this,"_variables");this._variables=t,this._id=e,this._line1=r,this._line2=n}linefill(t,e){return t.x?t.x:new no(this._variables,e)}delete(){var e,r;const t=this._variables.linefill.get(this._id);if(t){const{line1:n,line2:s}=t;n&&(n.linefills=(e=n.linefills)==null?void 0:e.filter(u=>u!==this._id)),s&&(s.linefills=(r=s.linefills)==null?void 0:r.filter(u=>u!==this._id))}this._line1=void 0,this._line2=void 0,this._variables.linefill.delete(this._id)}get_line1(){return this._line1}get_line2(){return this._line2}set_color({color:t}){const e=this._variables.linefill.get(this._id);e&&(e.color=t)}}class zw{constructor(t){Z(this,"_variables");Z(this,"_defaultBox",{border_color:vi.blue,border_width:1,bgcolor:vi.blue,xloc:Ie.bar_index,extend:$n.none,style:zr.styleSolid,text:"",text_size:qr.auto,text_color:vi.black,text_halign:Ke.alignCenter,text_valign:Ke.alignCenter,text_wrap:Ke.wrapNone});this._variables=t}box({x:t},e){return t===void 0?new Ji(this._variables,e):t}new({top_left:t,bottom_right:e,...r},n){const s=`box_${n}`,u={...this._defaultBox,...r,id:s};if(t){const{price:f,time:p,index:h}=t;u.top=f,u.left=u.xloc===Ie.bar_index?h:p}if(e){const{price:f,time:p,index:h}=e;u.bottom=f,u.right=u.xloc===Ie.bar_index?h:p}const l=new Ji(this._variables,s);return this._variables.box.add(s,u,l),l}copy({id:t},e){return t==null?void 0:t.copy(e)}delete({id:t}){t==null||t.delete()}get_top({id:t}){return t==null?void 0:t.get_top()}get_bottom({id:t}){return t==null?void 0:t.get_bottom()}get_left({id:t}){return t==null?void 0:t.get_left()}get_right({id:t}){return t==null?void 0:t.get_right()}set_top({id:t,...e}){t==null||t.set_top(e)}set_bottom({id:t,...e}){t==null||t.set_bottom(e)}set_left({id:t,...e}){t==null||t.set_left(e)}set_right({id:t,...e}){t==null||t.set_right(e)}set_extend({id:t,...e}){t==null||t.set_extend(e)}set_bgcolor({id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({id:t,...e}){t==null||t.set_border_color(e)}set_border_width({id:t,...e}){t==null||t.set_border_width(e)}set_border_style({id:t,...e}){t==null||t.set_border_style(e)}set_lefttop({id:t,...e}){t==null||t.set_lefttop(e)}set_rightbottom({id:t,...e}){t==null||t.set_rightbottom(e)}set_text_size({id:t,...e}){t==null||t.set_text_size(e)}set_text_wrap({id:t,...e}){t==null||t.set_text_wrap(e)}set_text_color({id:t,...e}){t==null||t.set_text_color(e)}set_text_halign({id:t,...e}){t==null||t.set_text_halign(e)}set_text_valign({id:t,...e}){t==null||t.set_text_valign(e)}set_top_left_point({id:t,...e}){t==null||t.set_top_left_point(e)}set_bottom_right_point({id:t,...e}){t==null||t.set_bottom_right_point(e)}set_text_font_family({id:t,...e}){t==null||t.set_text_font_family(e)}}class Ji{constructor(t,e){Z(this,"_id");Z(this,"_variables");this._variables=t,this._id=e}copy(t){const e=`box_${t}`,r=this._getBox(),n=new Ji(this._variables,e);return r&&this._variables.box.add(e,{...r,id:e},n),n}delete(){this._variables.box.delete(this._id)}get_top(){const t=this._getBox();return t&&t.top}set_top({top:t}){const e=this._getBox();e&&(e.top=t)}get_left(){const t=this._getBox();return t&&t.left}set_left({left:t}){const e=this._getBox();e&&(e.left=t)}set_text({text:t}){const e=this._getBox();e&&(e.text=t)}get_right(){const t=this._getBox();return t&&t.right}set_right({right:t}){const e=this._getBox();e&&(e.right=t)}get_bottom(){const t=this._getBox();return t&&t.bottom}set_bottom({bottom:t}){const e=this._getBox();e&&(e.bottom=t)}set_extend({extend:t}){const e=this._getBox();e&&(e.extend=t)}set_bgcolor({color:t}){const e=this._getBox();e&&(e.bgcolor=t)}set_lefttop({left:t,top:e}){const r=this._getBox();r&&(r.left=t,r.top=e)}set_text_size({text_size:t}){const e=this._getBox();e&&(e.text_size=t)}set_text_wrap({text_wrap:t}){const e=this._getBox();e&&(e.text_wrap=t)}set_text_color({text_color:t}){const e=this._getBox();e&&(e.text_color=t)}set_rightbottom({right:t,bottom:e}){const r=this._getBox();r&&(r.right=t,r.bottom=e)}set_text_halign({text_halign:t}){const e=this._getBox();e&&(e.text_halign=t)}set_text_valign({text_valign:t}){const e=this._getBox();e&&(e.text_valign=t)}set_top_left_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.top=n,e.left=e.xloc===Ie.bar_index?r:s}}set_border_color({color:t}){const e=this._getBox();e&&(e.border_color=t)}set_border_style({style:t}){const e=this._getBox();e&&(e.border_style=t)}set_border_width({width:t}){const e=this._getBox();e&&(e.border_width=t)}set_bottom_right_point({point:t}){const e=this._getBox();if(e){const{index:r,price:n,time:s}=t||{};e.bottom=n,e.right=e.xloc===Ie.bar_index?r:s}}set_text_font_family({text_font_family:t}){const e=this._getBox();e&&(e.text_font_family=t)}_getBox(){return this._variables.box.get(this._id)}}class qw{constructor(t){Z(this,"_variables");Z(this,"_defaultTable",{position:Nr.topLeft,columns:0,rows:0,frame_width:0,border_width:0});this._variables=t}table({x:t},e){return t||new Ra(this._variables,e)}new(t,e){const r=`table_${e}`,n={...this._defaultTable,...t,cell:[],id:r},s=new Ra(this._variables,r);return this._variables.table.add(r,n,s),s}cell({table_id:t,...e}){t==null||t.cell(e)}cell_set_bgcolor({table_id:t,...e}){t==null||t.cell_set_bgcolor(e)}cell_set_height({table_id:t,...e}){t==null||t.cell_set_height(e)}cell_set_text({table_id:t,...e}){t==null||t.cell_set_text(e)}cell_set_text_color({table_id:t,...e}){t==null||t.cell_set_text_color(e)}cell_set_text_font_family({table_id:t,...e}){t==null||t.cell_set_text_font_family(e)}cell_set_text_halign({table_id:t,...e}){t==null||t.cell_set_text_halign(e)}cell_set_text_valign({table_id:t,...e}){t==null||t.cell_set_text_valign(e)}cell_set_text_size({table_id:t,...e}){t==null||t.cell_set_text_size(e)}cell_set_tooltip({table_id:t,...e}){t==null||t.cell_set_tooltip(e)}cell_set_width({table_id:t,...e}){t==null||t.cell_set_width(e)}clear({table_id:t,...e}){t==null||t.clear(e)}delete({table_id:t}){t==null||t.delete()}merge_cells({table_id:t,...e},r){t==null||t.merge_cells(e,r)}set_bgcolor({table_id:t,...e}){t==null||t.set_bgcolor(e)}set_border_color({table_id:t,...e}){t==null||t.set_border_color(e)}set_border_width({table_id:t,...e}){t==null||t.set_border_width(e)}set_frame_color({table_id:t,...e}){t==null||t.set_frame_color(e)}set_frame_width({table_id:t,...e}){t==null||t.set_frame_width(e)}set_position({table_id:t,...e}){t==null||t.set_position(e)}}class Ra{constructor(t,e){Z(this,"_id");Z(this,"_variables");Z(this,"_defaultCell",{column:0,row:0,text:"",text_color:vi.black,text_halign:Ke.alignCenter,text_valign:Ke.alignCenter,text_size:qr.normal});this._variables=t,this._id=e}cell(t){const e={...this._defaultCell,...t},{column:r=0,row:n=0}=e,s=this._variables.table.get(this._id);if(s){const u=s.cell||[],l=u[n]||[];l[r]=e,u[n]=l,s.cell=u}}cell_set_bgcolor({column:t=0,row:e=0,bgcolor:r}){const n=this._getTableItem(t,e);n&&(n.bgcolor=r)}cell_set_height({column:t=0,row:e=0,height:r}){const n=this._getTableItem(t,e);n&&(n.height=r)}cell_set_text({column:t=0,row:e=0,text:r}){const n=this._getTableItem(t,e);n&&(n.text=r)}cell_set_text_color({column:t=0,row:e=0,text_color:r}){const n=this._getTableItem(t,e);n&&(n.text_color=r)}cell_set_text_font_family({column:t=0,row:e=0,text_font_family:r}){const n=this._getTableItem(t,e);n&&(n.text_font_family=r)}cell_set_text_halign({column:t=0,row:e=0,text_halign:r}){const n=this._getTableItem(t,e);n&&(n.text_halign=r)}cell_set_text_valign({column:t=0,row:e=0,text_valign:r}){const n=this._getTableItem(t,e);n&&(n.text_valign=r)}cell_set_text_size({column:t=0,row:e=0,text_size:r}){const n=this._getTableItem(t,e);n&&(n.text_size=r)}cell_set_tooltip({column:t=0,row:e=0,tooltip:r}){const n=this._getTableItem(t,e);n&&(n.tooltip=r)}cell_set_width({column:t=0,row:e=0,width:r}){const n=this._getTableItem(t,e);n&&(n.width=r)}clear({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0}){const s=this._variables.table.get(this._id);if(s){const u=s.cell;if(u)for(let l=e;l<=n;l++)for(let f=t;f<=r;f++){const p=u[l];p&&(p[f]=void 0)}}}delete(){this._variables.table.delete(this._id)}merge_cells({start_column:t=0,start_row:e=0,end_column:r=0,end_row:n=0},s){if(t>r||e>n){console.log(`error ${s}: start_column > end_column or start_row > end_row`);return}const u=this._getTableItem(t,e);if(!u)return;this.clear({start_column:t,start_row:e,end_column:r,end_row:n});const l=this._variables.table.get(this._id);l.cell[e][t]={...u,isMerge:!0,merge_columns:r-t+1,merge_rows:n-e+1}}set_bgcolor({bgcolor:t}){const e=this._variables.table.get(this._id);e&&(e.bgcolor=t)}set_border_color({border_color:t}){const e=this._variables.table.get(this._id);e&&(e.border_color=t)}set_border_width({border_width:t}){const e=this._variables.table.get(this._id);e&&(e.border_width=t)}set_frame_color({frame_color:t}){const e=this._variables.table.get(this._id);e&&(e.frame_color=t)}set_frame_width({frame_width:t}){const e=this._variables.table.get(this._id);e&&(e.frame_width=t)}set_position({position:t}){const e=this._variables.table.get(this._id);e&&(e.position=t)}_getTableItem(t,e){const r=this._variables.table.get(this._id);if(r){const n=r.cell;return n?n[e][t]:void 0}}}class Uw{constructor(t,e,r=.001){Z(this,"_variables");Z(this,"_options");Z(this,"_totalChangeCapital");Z(this,"_freezeCapital");Z(this,"_historyOrder");Z(this,"_orders");Z(this,"_pendingOrders");Z(this,"_mintick");Z(this,"_funcOptions");this._variables=t,this._options={overlay:!1,format:On.inherit,pyramiding:0,calc_on_order_fills:!1,calc_on_every_tick:!1,max_bars_back:0,backtest_fill_limits_assumption:0,default_qty_type:Gr.fixed,default_qty_value:1,initial_capital:1e6,currency:Yc.NONE,slippage:0,commission_type:Pi.percent,commission_value:0,process_orders_on_close:!1,close_entries_rule:"FIFO",margin_long:0,margin_short:0,explicit_plot_zorder:!1,max_lines_count:50,max_labels_count:50,max_boxes_count:50,calc_bars_count:0,risk_free_rate:2,use_bar_magnifier:!1,fill_orders_on_standard_ohlc:!1,max_polylines_count:50},this._funcOptions=e,this._totalChangeCapital=0,this._freezeCapital=0,this._orders=[],this._pendingOrders=[],this._historyOrder=[],this._mintick=r}updateOptions(t){Object.assign(this._options,t),this._pendingOrderHandle(),this._calcProfitAndLoss()}strategy(t){this._options={...t},Object.assign(this._funcOptions,{strategy:this._options,scriptType:"strategy"})}order(t){this._orderHandle(t)}entry(t){this._entryHandle(t)}close(t){const{immediately:e}=t;e||this._options.process_orders_on_close?this._closeOrderHandle(t,!0):this._pendingOrders.push({...t,place_order_type:"close"})}close_all(t){const{immediately:e}=t;e||this._options.process_orders_on_close?this._closeAllOrders(t,this._variables.close):this._pendingOrders.push({...t,place_order_type:"close_all"})}cancel({id:t}){this._pendingOrders=this._pendingOrders.filter(e=>e.id===t?(["entry","order"].includes(e.place_order_type||"")&&(this._freezeCapital-=e.in_price*(e.qty||0)),!1):!0)}cancel_all(){for(const t of this._pendingOrders)["entry","order"].includes(t.place_order_type||"")&&(this._freezeCapital-=t.in_price*(t.qty||0));this._pendingOrders=[]}exit(t){this._exit(t)}_calcDefaultQty(t,e){const{default_qty_type:r=Gr.fixed,default_qty_value:n=1}=this._options,s=this._getCapital(e);switch(r){case Gr.fixed:return n;case Gr.cash:return n/t;case Gr.percentOfEquity:return(s-this._freezeCapital+this._totalChangeCapital)*n/100/t}}_getCapital(t){const{initial_capital:e=1e6,margin_long:r=0,margin_short:n=0}=this._options;let s=e;return r<100&&r>0&&t===1?s=e*100/r:n<=100&&n>0&&t===-1&&(s=e*100/n),s}_calcProfitAndLoss(){const{high:t,low:e,close:r}=this._variables;for(const n of this._orders){const{in_price:s,qty:u=0,max_profit:l=0,trading_loss:f=0,total_profit:p=0,direction:h}=n,c=h===Ge.long?1:-1,m=(r-s)*c*u,_=(t-s)*u,w=(e-s)*u;let g=c===1?_:-w;g=Math.max(g,l);let y=c===1?w:-_;y=Math.min(y,f),Object.assign(n,{profit:m,max_profit:g,trading_loss:y,total_profit:p+m})}}_orderHandle(t){const{process_orders_on_close:e,slippage:r=0}=this._options,{orders:n,isMarketPrice:s,quantities:u,close:l,price:f,activePrice:p}=this._orderArgsParse(t),h=t.direction===Ge.long?1:-1;if(u<=0)return;let c=u;if(s&&e){if(n.length){const g=this._processOrders(n,l,c,t.comment);if(g<=0)return;c=g}const _=l+h*r*this._mintick;if(!this._judgeCapitalEnough(c,_,h))return;this._freezeCapital+=c*_,this._ocaGroupVerify(c,t.oca_name,t.oca_type),this._orders.push({...t,in_price:_,in_time:this._variables.time,total_profit:this._totalChangeCapital,qty:c,place_order_type:"order"});return}this._judgeCapitalEnough(u,f,h)&&this._addPendingOrders(t,f,c,s,p)}_judgeCapitalEnough(t,e,r){if(t<=0)return!1;const{margin_long:n=0,margin_short:s=0}=this._options;if((n===0||n===100)&&r===1||s===0&&r===-1)return!0;const l=this._getCapital(r)-this._freezeCapital+this._totalChangeCapital;return t*e<=l}_ocaGroupVerify(t,e,r){if(!e||!r||r===Ln.none)return!1;let n=!1;switch(r){case Ln.cancel:this._pendingOrders=this._pendingOrders.filter(s=>{if(s.oca_name===e)this._freezeCapital-=s.in_price*(s.qty||0),s.isCancel=!0,n=!0;else return!0});break;case Ln.reduce:this._pendingOrders=this._pendingOrders.filter(s=>{const{qty:u=0,in_price:l,oca_name:f}=s;if(e===f){this._freezeCapital-=t*l;const p=u-t;return n=!0,p<=0?(s.isCancel=!0,!1):(s.qty=p,!0)}else return!0});break}return n}_processOrders(t,e,r,n){let s=r;for(const u of t)if(s=this._processOrder(u,e,s,n),s<=0)break;return this._orders=this._orders.filter(u=>!u.isDeal),s}_addPendingOrders(t,e,r,n,s){const u=this._pendingOrders.find(l=>l.id===t.id);if(u){const{qty:l=0,in_price:f=0}=u;this._freezeCapital+=r*e-f*l,Object.assign(u,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s})}else{this._freezeCapital+=e*r;const l={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"order"};this._pendingOrders.push(l)}}_orderArgsParse(t){const{direction:e,qty:r,stop:n}=t;let s=t.limit||0;const{close:u}=this._variables;let l=u,f=!1,p;const h=e===Ge.long?1:-1,c=n&&(n-u)*h>0,{backtest_fill_limits_assumption:m=0}=this._options;m>0&&s&&(s-=m*this._mintick*h);const _=s&&(s-u)*h<0;c&&_?(p=n,l=s):c?l=n:_?l=s:f=!0;const w=r||this._calcDefaultQty(l,h)||1;return{orders:this._orders.filter(y=>y.direction!==e),isMarketPrice:f,activePrice:p,quantities:w,close:u,price:l}}_entryHandle(t){const{process_orders_on_close:e}=this._options,{orders:r,isMarketPrice:n,quantities:s,close:u,price:l,activePrice:f}=this._orderArgsParse(t);if(s<=0)return;if(r.length&&n&&e){this._entryOrder(r,u,s,t);return}this._judgeCapitalEnough(s,u,t.direction===Ge.long?1:-1)&&this._addPendingEntry(t,l,s,n,f)}_entryOrder(t,e,r,n){const{time:s}=this._variables,{slippage:u=0}=this._options,{in_price:l,oca_name:f,oca_type:p,direction:h,comment:c,qty:m=0}=n,_=h===Ge.long?1:-1;this._closeOrders(t,e,c);const{pendingOrders:w,orders:g}=this._getEntryOrders(h),y=w.length+g.length;if(y&&y>=(this._options.pyramiding||0)||(e=e+u*this._mintick*_,!this._judgeCapitalEnough(r,e,_)))return;this._freezeCapital+=e*r;const E=this._ocaGroupVerify(r,f,p);l&&!E&&(this._freezeCapital-=l*m),this._orders.push({...n,in_price:e,qty:r,in_time:s,place_order_type:"entry",total_profit:this._totalChangeCapital})}_getEntryOrders(t){const e=this._pendingOrders.filter(n=>n.place_order_type==="entry"&&n.direction===t),r=this._orders.filter(n=>n.place_order_type==="entry"&&n.direction===t);return{pendingOrders:e,orders:r}}_addPendingEntry(t,e,r,n,s){const{pendingOrders:u,orders:l}=this._getEntryOrders(t.direction),f=u.length+l.length,p=u.find(h=>h.id===t.id);if(p){const{qty:h=0,in_price:c=0}=p;this._freezeCapital+=r*e-c*h,Object.assign(p,{...t,in_price:e,isMarketPrice:n,qty:r,active_price:s})}else if(!f||f<(this._options.pyramiding||0)){this._freezeCapital+=e*r;const h={...t,in_price:e,isMarketPrice:n,qty:r,active_price:s,place_order_type:"entry"};this._pendingOrders.push(h)}}_closeAllOrders(t,e){const{comment:r}=t;this._closeOrders(this._orders,e,r),this._orders=[]}_closeOrders(t,e,r){for(const n of t)this._closeOrder(n,e,r)}_closeOrder(t,e,r){const{time:n}=this._variables,{slippage:s=0}=this._options,{in_price:u,qty:l=0,direction:f}=t,p=f===Ge.long?1:-1;e=e-p*s*this._mintick,t.isDeal=!0;const h=(e-u)*p*l;this._totalChangeCapital+=h,this._freezeCapital-=u*l,this._historyOrder.push({...t,out_price:e,out_time:n,out_comment:r,profit:h,total_profit:this._totalChangeCapital})}_ordersHandle(){if(!this._orders.length)return;const t=this._orders.filter(u=>u.place_order_type==="exit"&&!u.hasExit),{open:e,low:r,high:n,close:s}=this._variables;for(const u of t){const{stop:l,limit:f,trail_stop_price:p,isMarketPriceLimit:h,isMarketPriceStop:c,direction:m,id:_,comment:w,qty:g,active_price:y,trail_offset:v=0}=u;let E=p;const b=m===Ge.long?1:-1;let N;if(h)N=e;else if(c)N=e;else if(f&&r<=f&&n>=f&&(N=f),l&&r<=l&&n>=l&&(N=l),E)if((E-e)*b>=0)N=E;else{const x=(b===1?n:r)-v*b*this._mintick;(x-E)*b>0&&(E=x)}N?this._processExitOnClose(u,N,{from_entry:_,comment:w,qty:g}):y&&(p?E=(b===1?n:r)-v*b*this._mintick:y<=n&&y>=r&&(E=y-v*b*this._mintick),u.trail_stop_price=E)}}_pendingOrderHandle(){if(!this._pendingOrders.length)return;const t=[];for(const e of this._pendingOrders){const{isCancel:r,place_order_type:n}=e;if(r)continue;let s;switch(n){case"entry":s=this._entryOrderHandle(e);break;case"order":s=this._orderOrderHandle(e);break;case"close":this._closeOrderHandle(e);break;case"exit":s=this._exitOrderHandle(e);break;case"close_all":this._closeAllOrders(e,this._variables.open);break}s&&t.push(s)}this._pendingOrders=t}_entryOrderHandle(t){const{open:e,low:r,high:n}=this._variables,{isMarketPrice:s,qty:u=0,in_price:l,direction:f,active_price:p}=t;if(p&&n>=p&&r<=p)return delete t.active_price,t;let h=l;if(s&&(h=e),h<=n&&h>=r){const c=this._orders.filter(m=>m.direction===f);this._entryOrder(c,h,u,t)}else return t}_orderOrderHandle(t){const{open:e,low:r,high:n,time:s}=this._variables,{slippage:u=0}=this._options,{isMarketPrice:l,qty:f=0,in_price:p,direction:h,comment:c,oca_name:m,oca_type:_,active_price:w}=t;if(w&&n>=w&&r<=w)return delete t.active_price,t;let g=p,y=f;if(l&&(g=e),g<=n&&g>=r){const v=this._orders.filter(N=>N.direction===h);if(v.length&&(y=this._processOrders(v,g,f,c),y<=0))return;const E=h===Ge.long?1:-1;this._ocaGroupVerify(y,m,_)||(this._freezeCapital-=f*p),this._freezeCapital+=y*g,this._orders.push({...t,in_price:g+E*u*this._mintick,in_time:s,total_profit:this._totalChangeCapital,qty:y});return}else return t}_closeOrderHandle(t,e){const{id:r,qty:n,qty_percent:s=100,comment:u}=t,l=this._orders.filter(c=>c.id===r);if(!l.length)return;let f=0;if(n?f=n:(f=l.reduce((c,m)=>c+(m.qty||0),f),f=s/100*f),f<=0)return;const{open:p,close:h}=this._variables;this._processOrders(l,e?h:p,f,u)}_exitOrderHandle(t){const{from_entry:e}=t,r=this._orders.filter(n=>(!e||e===n.id)&&!n.hasExit);if(r.length)this._ordersToExit(r,t);else return t}_exit(t){const{profit:e,loss:r,stop:n,limit:s,trail_offset:u,trail_price:l,trail_points:f,from_entry:p="",id:h}=t;if(this._isNaN(e)&&this._isNaN(r)&&this._isNaN(n)&&this._isNaN(s)&&this._isNaN(u)&&(this._isNaN(f)||this._isNaN(l))){console.log("error");return}const c={...t,place_order_type:"exit"},m=this._orders.filter(_=>(!p||p===_.id)&&!_.hasExit);if(m.length)this._ordersToExit(m,c);else{if(!this._pendingOrders.filter(g=>!p||p===g.id).length)return;const w=this._pendingOrders.find(g=>g.id===h);w?Object.assign(w,{...t}):this._pendingOrders.push(c)}}_ordersToExit(t,e){const{qty:r,qty_percent:n=100}=e;for(const s of t){const{qty:u=0}=s,l=s.direction===Ge.long?1:-1;e.qty=r?r>=u?u:r:n*u,!(this._stopProfit(s,l,e)||this._stopLoss(s,l,e)||this._trailStopLoss(s,l,e))&&(s.place_order_type="exit")}}_stopProfit(t,e,r){const{limit:n,profit:s}=r;let u=n;const{close:l}=this._variables,{in_price:f}=t,{process_orders_on_close:p}=this._options;if(!this._isNaN(s)&&this._isNaN(n)&&(u=f+e*s*this._mintick),t.limit=u,u&&(u-l)*e<=0&&(t.isMarketPriceLimit=!0,u=l,p))return this._processExitOnClose(t,u,r),!0}_stopLoss(t,e,r){const{stop:n,loss:s}=r;let u=n;const{close:l}=this._variables,{in_price:f}=t,{process_orders_on_close:p}=this._options;if(!this._isNaN(s)&&this._isNaN(n)&&(u=f-e*s*this._mintick),t.stop=u,u&&(u-l)*e>=0&&(t.isMarketPriceStop=!0,u=l,p))return this._processExitOnClose(t,u,r),!0}_trailStopLoss(t,e,r){const{trail_offset:n,trail_price:s,trail_points:u}=r;if(!this._isNaN(n)){const{close:l}=this._variables,{in_price:f}=t,{process_orders_on_close:p}=this._options;let h;if(this._isNaN(s)?this._isNaN(u)||(h=f+u*e*this._mintick):h=s,t.trail_offset=n,h&&(h-l)*e<=0){const c=l-n*e*this._mintick;if((c-l)*e>=0&&(t.isMarketPriceStop=!0,p))return this._processExitOnClose(t,l,r),!0;t.trail_stop_price=c}t.active_price=h}}_processExitOnClose(t,e,r){const{qty:n=0,from_entry:s,comment:u,id:l}=r,{close_entries_rule:f="FIFO"}=this._options;if(f==="FIFO"){const p=this._orders.filter(c=>!s||s===c.id),h=this._processExitOrders(p,e,n,u||l);h&&!h.hasExit?(h.hasExit=!0,Object.assign(t,{trail_stop_price:h.trail_stop_price,stop:h.stop,limit:h.limit,trail_offset:h.trail_offset,active_price:h.active_price})):h&&(t.hasExit=!0)}else t.hasExit=!0,this._processOrders([t],e,n,u||l)}_processExitOrders(t,e,r,n){let s=r,u;for(const l of t)if(u=l,s=this._processOrder(l,e,s,n),s<=0||!l.hasExit)break;return this._orders=this._orders.filter(l=>!l.isDeal),u}_processOrder(t,e,r,n){const{time:s}=this._variables,{slippage:u=0}=this._options,{in_price:l,qty:f=0,max_profit:p=0,trading_loss:h=0,direction:c}=t,m=c===Ge.long?1:-1;if(e=e-m*u*this._mintick,r<f){const _=f-r,w=(e-l)*m*r;this._totalChangeCapital+=w;const g=p/f*r,y=h/f*r;this._freezeCapital-=l*r,this._historyOrder.push({...t,out_price:e,out_time:s,out_comment:n,profit:w,qty:r,total_profit:this._totalChangeCapital,max_profit:g,trading_loss:y}),Object.assign(t,{qty:_,max_profit:p-g,trading_loss:h-y}),r=0}else{t.isDeal=!0;const _=(e-l)*m*f;this._totalChangeCapital+=_,this._freezeCapital-=l*f,this._historyOrder.push({...t,out_price:e,out_time:s,out_comment:n,profit:_,total_profit:this._totalChangeCapital}),r-=f}return r}_isNaN(t){return t===void 0||isNaN(t)}}class kw{constructor(t){Z(this,"_logs");Z(this,"_variables");this._variables=t,this._logs=[]}get logs(){return this._logs}clearLogs(){this._logs=[]}info(t,e){this._addLog(t,e,"info")}error(t,e){this._addLog(t,e,"error")}warning(t,e){this._addLog(t,e,"warning")}_addLog(t,e,r){const{message:n,formatString:s}=t,{time:u,bar_index:l}=this._variables;let f=n;s&&Array.isArray(e)&&e.length&&(f=s.replace(/{(\d+)}/g,(p,h)=>e[h]?String(e[h]):p)),f&&this._logs.push({message:f,time:u,barIndex:l,type:r})}}class Ww{constructor(t){Z(this,"_errorListener");this._errorListener=t}error({message:t},e){this._errorListener.addError(t,e,hi.Error)}}class Yw{constructor(){Z(this,"_errors");this._errors=new Map}clear(){this._errors.clear()}get errors(){return Fr.flatMap([...this._errors.values()])}addError(t,e,r){const[n,s]=e.split("_").slice(-2),u=this._errors.get(e),l={message:t,endLineNumber:Number(n),startColumn:Number(s),endColumn:Number(s),startLineNumber:Number(n),type:r};u?u.push(l):this._errors.set(e,[l])}}ne.extend(Ip),ne.extend(Mp),ne.extend(Sp);class jw{constructor(){Z(this,"_cacheData");Z(this,"_barIndex");Z(this,"_isRealTimeBar");Z(this,"_barstate");Z(this,"_priceVariables");Z(this,"_lastBarIndex");Z(this,"_currentBarTime");Z(this,"_lastBarTime");Z(this,"_period");Z(this,"_offsetTime");Z(this,"_timeframe");Z(this,"_ta");Z(this,"_polyline");Z(this,"_label");Z(this,"_line");Z(this,"_linefill");Z(this,"_box");Z(this,"_table");this._cacheData={varData:{},varNewData:{},varipData:{}},this._barIndex=0,this._lastBarIndex=0,this._currentBarTime=0,this._lastBarTime=0,this._offsetTime=0,this._period="",this._isRealTimeBar=!1,this._barstate=new Zw,this._timeframe=new Gw,this._priceVariables={close:0,open:0,low:0,high:0,volume:0},this._ta=new Kw,this._polyline=new _i,this._label=new _i,this._line=new _i,this._linefill=new _i,this._box=new _i,this._table=new _i}get table(){return this._table}get box(){return this._box}get linefill(){return this._linefill}get line(){return this._line}get polyline(){return this._polyline}get label(){return this._label}get ta(){return this._ta}get na(){}get last_bar_index(){return this._lastBarIndex}get bar_index(){return this._barIndex}get barstate(){return this._barstate}get close(){return this._priceVariables.close}get low(){return this._priceVariables.low}get open(){return this._priceVariables.open}get high(){return this._priceVariables.high}get volume(){return this._priceVariables.volume}get ohlc4(){const{close:t,open:e,high:r,low:n}=this._priceVariables;return(t+e+r+n)/4}get hl2(){const{high:t,low:e}=this._priceVariables;return(t+e)/2}get hlc3(){const{close:t,high:e,low:r}=this._priceVariables;return(t+e+r)/3}get hlcc4(){const{close:t,high:e,low:r}=this._priceVariables;return(t*2+e+r)/4}get hour(){return ne(this._currentBarTime).subtract(this._offsetTime,"hour").hour()}get minute(){return ne(this._currentBarTime).minute()}get second(){return ne(this._currentBarTime).second()}get month(){return ne(this._currentBarTime).month()+1}get year(){return ne(this._currentBarTime).year()}get dayofweek(){return ne(this._currentBarTime).day()+1}get dayofmonth(){return ne(this._currentBarTime).date()}get weekofyear(){return ne(this._currentBarTime).week()}get last_bar_time(){return this._lastBarTime}get time(){return this._currentBarTime}get time_close(){const[t,e]=ms(this._period);return this._isRealTimeBar?void 0:ne(this._currentBarTime).add(t,e).valueOf()}get timenow(){return Date.now()}get time_tradingday(){return this.getTimeTradingday(this._currentBarTime,this._period)}get timeframe(){return this._timeframe}getTimeTradingday(t,e){const[r,n]=ms(e),s=ne(t).add(r,n);return["M","w","y"].includes(n)?s.subtract(1,"d").valueOf():s.startOf("d").add(this._offsetTime,"h").valueOf()}updateData(t){const{barIndex:e,c:r,o:n,h:s,l:u,volume:l,lastBarIndex:f,time:p,lastBarTime:h,period:c="1D",offsetTime:m=5}=t;this._priceVariables={close:Number(r),open:Number(n),high:Number(s),low:Number(u),volume:Number(l)},e>this._barIndex&&this._isRealTimeBar&&(this._cacheData.varData=this._cacheData.varNewData,this._cacheData.varNewData={}),this._currentBarTime=p*1e3,this._lastBarIndex=f,this._barIndex=e,this._lastBarTime=h*1e3,this._period=c,this._offsetTime=m,this._timeframe.update(c),this._barstate.update(e,f,!1,!1),this.ta.update({...this._priceVariables,hlc3:this.hlc3,barIndex:e})}getCacheData(t,e,r){let n=this._cacheData[t]||[];n[this._barIndex]=r,n=n.filter(()=>!0);const s=n[n.length-1-e];return this._cacheData[t]=n,s}setCacheData(t,e){const r=this._cacheData[t]||[];r[this._barIndex]=e,this._cacheData[t]=r}getTypeInstance(t,e){return new xp(t,e)}getVarValue(t,e,r){const n=`${t}_${e}`,s=r==="var"?this._cacheData.varData[n]:this._cacheData.varipData[n];if(s)return s}setVarValue(t,e,r,n){const s=`${t}_${e}`;let u;switch(typeof r=="object"&&r&&(n="var",u=r.varipKeys),n){case"var":if(this._isRealTimeBar){const l=Fr.cloneDeep(r);if(this._cacheData.varNewData[s]=l,u&&u.length)for(const f of u)this._cacheData.varData[s][f]=l[f]}else this._cacheData.varData[s]=r;break;case"varip":this._cacheData.varipData[s]=r;break}return r}add(t,e){return Array.isArray(t)&&Array.isArray(e)?Fr.uniq([...t,...e]):Number(t)+Number(e)}sub(t,e){return Array.isArray(t)&&Array.isArray(e)?t.filter(r=>!e.includes(r)):Number(t)-Number(e)}againAssignParse(t,e){var n;if(e)return;const r=(n=t==null?void 0:t.constructor)==null?void 0:n.name;if(r)switch(r){case Ki.name:case jc.name:case Ji.name:case Ra.name:case Hi.name:case no.name:t==null||t.delete();break}}}class _i{constructor(t=50){Z(this,"_all");Z(this,"_allInstance");Z(this,"_pseudoArrayAll");Z(this,"_maxLength");this._all=new Map,this._allInstance=new Map,this._pseudoArrayAll=new Jt,this._maxLength=t}setMaxLen(t){this._maxLength=t}get data(){return[...this._all.values()]}get all(){return this._pseudoArrayAll._value=[...this._allInstance.values()],this._pseudoArrayAll}add(t,e,r){this._all.set(t,e),this._allInstance.set(t,r);const n=[...this._all.keys()];if(n.length>this._maxLength){const s=n.shift();s&&this.delete(s)}}get(t){return this._all.get(t)}getInstance(t){return this._allInstance.get(t)}delete(t){this._all.delete(t),this._allInstance.delete(t)}}class Zw{constructor(){Z(this,"_isMarketOpen");Z(this,"_currentBarIndex");Z(this,"_totalBarIndex");Z(this,"_isRealTimeBar");Z(this,"_preBarIndex");this._currentBarIndex=0,this._totalBarIndex=0,this._isRealTimeBar=!1,this._preBarIndex=0,this._isMarketOpen=!0}update(t,e,r,n){this._preBarIndex=this._currentBarIndex,this._currentBarIndex=t,this._totalBarIndex=e,this._isRealTimeBar=r,this._isMarketOpen=n}get isnew(){return!this._isRealTimeBar||this._preBarIndex!==this._currentBarIndex}get islast(){return this._currentBarIndex===this._totalBarIndex}get isfirst(){return this._currentBarIndex===0}get ishistory(){return!this._isRealTimeBar}get isrealtime(){return this._isRealTimeBar}get isconfirmed(){return!this._isRealTimeBar}get islastconfirmedhistory(){return this._isMarketOpen?this._currentBarIndex===this._totalBarIndex-1:this._currentBarIndex===this._totalBarIndex}}class Gw{constructor(){Z(this,"_period");Z(this,"_multiplier");Z(this,"_unit");this._period="1",this._multiplier=1,this._unit="m"}update(t){if(!t)return;this._period=t;const[e,r]=ms(t);this._multiplier=e,this._unit=r}get isdaily(){return this._unit==="d"}get isdwm(){return["d","w","M"].includes(this._unit)}get isintraday(){return["s","m","h"].includes(this._unit)}get isminutes(){return this._unit==="m"}get ismonthly(){return this._unit==="M"}get isseconds(){return this._unit==="s"}get isweekly(){return this._unit==="w"}get multiplier(){return this._multiplier}get period(){return this._period}}class Kw{constructor(){Z(this,"_preAccdist");Z(this,"_preNvi");Z(this,"_prePvi");Z(this,"_preObv");Z(this,"_prePvt");Z(this,"_preWad");Z(this,"_preVwap");Z(this,"_preValue");Z(this,"_currentData");Z(this,"_preData");this._preAccdist=0,this._preNvi=0,this._prePvi=0,this._preObv=0,this._prePvt=0,this._preWad=0,this._preVwap={},this._preValue={},this._currentData={},this._preData={}}update(t){this._preValue={},t.barIndex!==this._currentData.barIndex&&(this._preData={...this._currentData}),this._currentData={...t}}get isRealTime(){return this._preData.barIndex===this._currentData.barIndex}get accdist(){if(this._preValue.accdist)return this._preValue.accdist;const{close:t,low:e,high:r,volume:n}=this._currentData;if(r===e)return this._preAccdist;const s=(t-e-(r-t))/(r-e)*n+this._preAccdist;return!this.isRealTime&&(this._preAccdist=s),this._preValue.accdist=s,s}get iii(){if(this._preValue.iii)return this._preValue.iii;const{close:t,low:e,high:r,volume:n}=this._currentData,s=(2*t-r-e)/((r-e)*n);return this._preValue.iii=s,s}get nvi(){return this._preValue.nvi?this._preValue.nvi:this._getNvi()}get wvad(){if(this._preValue.wvad)return this._preValue.wvad;const{close:t,low:e,high:r,volume:n,open:s}=this._currentData,u=(t-s)/(r-e)*n;return this._preValue.wvad=u,u}get obv(){if(this._preValue.obv)return this._preValue.obv;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._preObv=0;return}const n=Math.sign(t-r)*e+this._preObv;return!this.isRealTime&&(this._preObv=n),this._preValue.obv=n,n}get pvi(){return this._preValue.pvi?this._preValue.pvi:this._getPvi()}get tr(){if(this._preValue.tr)return this._preValue.tr;const{low:t,high:e}=this._currentData,{close:r}=this._preData;if(r===void 0)return;const n=Math.max(e-t,Math.abs(e-r),Math.abs(t-r));return this._preValue.tr=n,n}get pvt(){if(this._preValue.pvt)return this._preValue.pvt;const{close:t,volume:e}=this._currentData,{close:r}=this._preData;if(r===void 0){this._prePvt=0;return}const n=(t-r)/r*e+this._prePvt;return!this.isRealTime&&(this._prePvt=n),this._preValue.pvt=n,n}get wad(){if(this._preValue.wad)return this._preValue.wad;const{close:t,high:e,low:r}=this._currentData,{close:n}=this._preData;if(n===void 0)return this._preWad=0,0;const s=Math.max(e,n),u=Math.min(r,n),l=t-n,p=(l>0?t-u:l<0?t-s:0)+this._preWad;return!this.isRealTime&&(this._preWad=p),this._preValue.wad=p,p}get vwap(){if(this._preValue.vwap)return this._preValue.vwap;const{hlc3:t,volume:e}=this._currentData;let{sum:r=0,sumV:n=0,isReset:s}=this._preVwap;if(self.buildInFunctions.timeframe.change({timeframe:"1D"},"vwap_buildin")&&(s=!0,r=n=0),!s)return;const l=t*e+r,f=e+n;!this.isRealTime&&(this._preVwap={sum:l,sumV:f,isReset:s});const p=l/f;return this._preValue.vwap=p,p}_getNvi(){const t=this._preNvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let u=1;const l=t||1;return n&&e?u=s<r?l+(n-e)/e*l:l:u=l,!this.isRealTime&&(this._preNvi=u),this._preValue.nvi=u,u}_getPvi(){const t=this._prePvi||1,{close:e=0,volume:r=0}=this._preData,{close:n,volume:s}=this._currentData;let u=1;const l=t||1;return n&&e?u=s>r?l+(n-e)/e*l:l:u=l,!this.isRealTime&&(this._prePvi=u),this._preValue.pvi=u,u}}var Zc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){return function(e,r,n){r.prototype.isBetween=function(s,u,l,f){var p=n(s),h=n(u),c=(f=f||"()")[0]==="(",m=f[1]===")";return(c?this.isAfter(p,l):!this.isBefore(p,l))&&(m?this.isBefore(h,l):!this.isAfter(h,l))||(c?this.isBefore(p,l):!this.isAfter(p,l))&&(m?this.isAfter(h,l):!this.isBefore(h,l))}}})})(Zc);var Hw=Zc.exports,Jw=jt(Hw),Gc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){return function(e,r,n){var s=r.prototype,u=function(m){var _,w=m.date,g=m.utc,y={};if(!((_=w)===null||_ instanceof Date||_ instanceof Array||s.$utils().u(_)||_.constructor.name!=="Object")){if(!Object.keys(w).length)return new Date;var v=g?n.utc():n();Object.keys(w).forEach(function($){var C,I;y[C=$,I=s.$utils().p(C),I==="date"?"day":I]=w[$]});var E=y.day||(y.year||y.month>=0?1:v.date()),b=y.year||v.year(),N=y.month>=0?y.month:y.year||y.day?0:v.month(),x=y.hour||0,F=y.minute||0,M=y.second||0,S=y.millisecond||0;return g?new Date(Date.UTC(b,N,E,x,F,M,S)):new Date(b,N,E,x,F,M,S)}return w},l=s.parse;s.parse=function(m){m.date=u.bind(this)(m),l.bind(this)(m)};var f=s.set,p=s.add,h=s.subtract,c=function(m,_,w,g){g===void 0&&(g=1);var y=Object.keys(_),v=this;return y.forEach(function(E){v=m.bind(v)(_[E]*g,E)}),v};s.set=function(m,_){return _=_===void 0?m:_,m.constructor.name==="Object"?c.bind(this)(function(w,g){return f.bind(this)(g,w)},_,m):f.bind(this)(m,_)},s.add=function(m,_){return m.constructor.name==="Object"?c.bind(this)(p,m,_):p.bind(this)(m,_)},s.subtract=function(m,_){return m.constructor.name==="Object"?c.bind(this)(p,m,_,-1):h.bind(this)(m,_)}}})})(Gc);var Xw=Gc.exports,Vw=jt(Xw),Kc={exports:{}};(function(i,t){(function(e,r){i.exports=r()})(Wt,function(){var e,r,n=1e3,s=6e4,u=36e5,l=864e5,f=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,p=31536e6,h=2628e6,c=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,m={years:p,months:h,days:l,hours:u,minutes:s,seconds:n,milliseconds:1,weeks:6048e5},_=function(F){return F instanceof N},w=function(F,M,S){return new N(F,S,M.$l)},g=function(F){return r.p(F)+"s"},y=function(F){return F<0},v=function(F){return y(F)?Math.ceil(F):Math.floor(F)},E=function(F){return Math.abs(F)},b=function(F,M){return F?y(F)?{negative:!0,format:""+E(F)+M}:{negative:!1,format:""+F+M}:{negative:!1,format:""}},N=function(){function F(S,$,C){var I=this;if(this.$d={},this.$l=C,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),$)return w(S*m[g($)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function(q){I.$d[g(q)]=S[q]}),this.calMilliseconds(),this;if(typeof S=="string"){var R=S.match(c);if(R){var U=R.slice(2).map(function(q){return q!=null?Number(q):0});return this.$d.years=U[0],this.$d.months=U[1],this.$d.weeks=U[2],this.$d.days=U[3],this.$d.hours=U[4],this.$d.minutes=U[5],this.$d.seconds=U[6],this.calMilliseconds(),this}}return this}var M=F.prototype;return M.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function($,C){return $+(S.$d[C]||0)*m[C]},0)},M.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=v(S/p),S%=p,this.$d.months=v(S/h),S%=h,this.$d.days=v(S/l),S%=l,this.$d.hours=v(S/u),S%=u,this.$d.minutes=v(S/s),S%=s,this.$d.seconds=v(S/n),S%=n,this.$d.milliseconds=S},M.toISOString=function(){var S=b(this.$d.years,"Y"),$=b(this.$d.months,"M"),C=+this.$d.days||0;this.$d.weeks&&(C+=7*this.$d.weeks);var I=b(C,"D"),R=b(this.$d.hours,"H"),U=b(this.$d.minutes,"M"),q=this.$d.seconds||0;this.$d.milliseconds&&(q+=this.$d.milliseconds/1e3,q=Math.round(1e3*q)/1e3);var k=b(q,"S"),P=S.negative||$.negative||I.negative||R.negative||U.negative||k.negative,K=R.format||U.format||k.format?"T":"",G=(P?"-":"")+"P"+S.format+$.format+I.format+K+R.format+U.format+k.format;return G==="P"||G==="-P"?"P0D":G},M.toJSON=function(){return this.toISOString()},M.format=function(S){var $=S||"YYYY-MM-DDTHH:mm:ss",C={Y:this.$d.years,YY:r.s(this.$d.years,2,"0"),YYYY:r.s(this.$d.years,4,"0"),M:this.$d.months,MM:r.s(this.$d.months,2,"0"),D:this.$d.days,DD:r.s(this.$d.days,2,"0"),H:this.$d.hours,HH:r.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:r.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:r.s(this.$d.seconds,2,"0"),SSS:r.s(this.$d.milliseconds,3,"0")};return $.replace(f,function(I,R){return R||String(C[I])})},M.as=function(S){return this.$ms/m[g(S)]},M.get=function(S){var $=this.$ms,C=g(S);return C==="milliseconds"?$%=1e3:$=C==="weeks"?v($/m[C]):this.$d[C],$||0},M.add=function(S,$,C){var I;return I=$?S*m[g($)]:_(S)?S.$ms:w(S,this).$ms,w(this.$ms+I*(C?-1:1),this)},M.subtract=function(S,$){return this.add(S,$,!0)},M.locale=function(S){var $=this.clone();return $.$l=S,$},M.clone=function(){return w(this.$ms,this)},M.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},M.valueOf=function(){return this.asMilliseconds()},M.milliseconds=function(){return this.get("milliseconds")},M.asMilliseconds=function(){return this.as("milliseconds")},M.seconds=function(){return this.get("seconds")},M.asSeconds=function(){return this.as("seconds")},M.minutes=function(){return this.get("minutes")},M.asMinutes=function(){return this.as("minutes")},M.hours=function(){return this.get("hours")},M.asHours=function(){return this.as("hours")},M.days=function(){return this.get("days")},M.asDays=function(){return this.as("days")},M.weeks=function(){return this.get("weeks")},M.asWeeks=function(){return this.as("weeks")},M.months=function(){return this.get("months")},M.asMonths=function(){return this.as("months")},M.years=function(){return this.get("years")},M.asYears=function(){return this.as("years")},F}(),x=function(F,M,S){return F.add(M.years()*S,"y").add(M.months()*S,"M").add(M.days()*S,"d").add(M.hours()*S,"h").add(M.minutes()*S,"m").add(M.seconds()*S,"s").add(M.milliseconds()*S,"ms")};return function(F,M,S){e=S,r=S().$utils(),S.duration=function(I,R){var U=S.locale();return w(I,{$l:U},R)},S.isDuration=_;var $=M.prototype.add,C=M.prototype.subtract;M.prototype.add=function(I,R){return _(I)?x(this,I,1):$.bind(this)(I,R)},M.prototype.subtract=function(I,R){return _(I)?x(this,I,-1):C.bind(this)(I,R)}}})})(Kc);var Qw=Kc.exports,tD=jt(Qw);ne.extend(Jw),ne.extend(Vw),ne.extend(tD);class eD{constructor(t,e){Z(this,"array");Z(this,"color");Z(this,"math");Z(this,"str");Z(this,"map");Z(this,"matrix");Z(this,"timeframe");Z(this,"ta");Z(this,"input");Z(this,"_variables");Z(this,"_cacheData");Z(this,"_options");Z(this,"_errorListener");Z(this,"_plots");Z(this,"_alerts");Z(this,"_bgColors");Z(this,"_hlines");Z(this,"_fills");Z(this,"chart");Z(this,"line");Z(this,"label");Z(this,"polyline");Z(this,"box");Z(this,"table");Z(this,"linefill");Z(this,"log");Z(this,"runtime");Z(this,"strategy");this._variables=e,this.array=new Op,this.math=new Rp(t),this.color=new l1,this.str=new fw,this.map=new cw,this.timeframe=new lw(e),this.matrix=new uw,this.ta=new s1(e,this.math,this.timeframe),this._cacheData={},this._options={},this._bgColors={},this._alerts=new Map,this._hlines=new Map,this._fills=new Map,this._errorListener=new Yw,this.input=new u1(e,this._errorListener),this._plots=new Map,this.chart={point:new hw(e)},this.line=new Lw(e),this.label=new pw(e),this.polyline=new Rw(e),this.box=new zw(e),this.table=new qw(e),this.linefill=new Pw(e),this.log=new kw(e),this.runtime=new Ww(this._errorListener),this.strategy=new Uw(this._variables,this._options,t)}get errors(){return this._errorListener.errors}get options(){const t=this.input.getInputs(),e=this._alerts.size?[...this._alerts.values()]:void 0;this._alerts.clear();const r=Object.keys(this._bgColors).length?{...this._bgColors}:void 0,n=this._hlines.size?[...this._hlines.values()]:void 0,s=this._fills.size?[...this._fills.values()]:void 0,u=this.log.logs.length?this.log.logs:void 0;return this.log.clearLogs(),Object.assign(this._options,{inputGroups:t,plots:[...this._plots.values()],draws:this._getDraws(),alerts:e,colors:r,hlines:n,fills:s,logs:u})}_getDraws(){const{line:t,linefill:e,table:r,box:n,polyline:s,label:u}=this._variables,l={};return t.data.length&&(l.lines=t.data),e.data.length&&(l.linefills=e.data),r.data.length&&(l.tables=r.data),n.data.length&&(l.boxes=n.data),s.data.length&&(l.polylines=s.data),u.data.length&&(l.labels=u.data),Object.keys(l).length?l:void 0}update(t){const{barIndex:e,inputs:r}=t;r&&r.length&&this.input.update(r),this.math.update(e)}indicator(t){this._variables.bar_index||(this._options.scriptType="indicator",this._options.indicator=t)}plot(t,e){const{series:r,color:n,seriesColors:s,...u}=t,{bar_index:l}=this._variables,f=`plot_${e}`,p=this._plots.get(f),h=(p==null?void 0:p.data)||[],c=r!==void 0&&isNaN(r)?void 0:r;if(h[l]=c,s!=null&&s.length&&(this._seriesColorHandle(t,f),h[l]={value:c,itemStyle:{color:n}}),!p){const m=n?[n]:void 0;this._plots.set(f,{editable:!0,...u,colors:m,data:h,id:f})}return{type:"plot",key:f}}plotbar(t,e){const{open:r,close:n,low:s,high:u,color:l,seriesColors:f,...p}=t,{bar_index:h}=this._variables,c=`plotbar_${e}`,m=this._plots.get(c),_=(m==null?void 0:m.data)||[],w=n!==void 0&&isNaN(n)?void 0:n,g=r!==void 0&&isNaN(r)?void 0:r,y=s!==void 0&&isNaN(s)?void 0:s,v=u!==void 0&&isNaN(u)?void 0:u,E=[g,w,y,v];if(_[h]=E,f!=null&&f.length&&(this._seriesColorHandle(t,c),_[h]={value:E,itemStyle:{color:l}}),!m){const b=l?[l]:void 0;this._plots.set(c,{editable:!0,...p,colors:b,data:_,id:c})}}plotchar(t,e){const{series:r,color:n,textcolor:s,...u}=t,{bar_index:l}=this._variables,f=`plotchar_${e}`,p=this._plots.get(f),h=(p==null?void 0:p.data)||[];h[l]={value:r,color:n,textcolor:s},p||this._plots.set(f,{editable:!0,...u,data:h,id:f})}plotarrow(t,e){const{series:r,colorup:n,colordown:s,...u}=t,{bar_index:l}=this._variables,f=`plotarrow_${e}`,p=this._plots.get(f),h=(p==null?void 0:p.data)||[];h[l]={value:r!==void 0&&isNaN(r)?void 0:r,colorup:n,colordown:s},p||this._plots.set(f,{editable:!0,...u,data:h,id:f})}plotshape(t,e){const{series:r,color:n,textcolor:s,...u}=t,{bar_index:l}=this._variables,f=`plotshape_${e}`,p=this._plots.get(f),h=(p==null?void 0:p.data)||[];h[l]={value:r,color:n,textcolor:s},p||this._plots.set(f,{editable:!0,...u,data:h,id:f})}plotcandle(t,e){const{wickcolor:r,bordercolor:n,color:s,close:u,open:l,low:f,high:p,...h}=t,{bar_index:c}=this._variables,m=`plotcandle_${e}`,_=this._plots.get(m),w=(_==null?void 0:_.data)||[],g=u!==void 0&&isNaN(u)?void 0:u,y=l!==void 0&&isNaN(l)?void 0:l,v=f!==void 0&&isNaN(f)?void 0:f,E=p!==void 0&&isNaN(p)?void 0:p,b=[y,g,v,E];w[c]={value:b,wickcolor:r,bordercolor:n,color:s},_||this._plots.set(m,{editable:!0,...h,data:w,id:m})}hline(t,e){const r=`hline_${e}`;return this._hlines.set(r,{linewidth:1,editable:!0,display:er.all,...t}),{type:"hline",key:r}}fill(t,e){const r=`fill_${e}`;this._fills.set(r,{display:er.all,editable:!0,fillgaps:!1,...t})}alert({message:t,freq:e=fn.freqOncePerBar},r){const{bar_index:n,_isRealTimeBar:s,last_bar_index:u}=this._variables,l=`alert_${r}`,f=this._cacheData[l].barIndex;if(e===fn.freqOncePerBar&&n===f){this._alerts.delete(l);return}const p={message:t,freq:e,id:l,type:"alert"};if(s){e!==fn.freqOncePerBarClose&&this._alerts.set(l,p),this._cacheData[l].barIndex=n;return}if(!s&&e===fn.freqOncePerBarClose&&n===f&&u===n-1){this._alerts.set(l,p),this._cacheData[l].barIndex=n;return}this._alerts.delete(l)}alertcondition({condition:t,message:e,title:r},n){const{_isRealTimeBar:s}=this._variables,u=`alertcondition_${n}`;s&&t?this._alerts.set(u,{message:e,title:r,id:u,type:"alertcondition"}):this._alerts.delete(u)}barcolor(t){this._setColors(t,"barcolor")}bgcolor(t){this._setColors(t,"bgcolor")}_setColors(t,e){var l,f;const{color:r,...n}=t,{bar_index:s}=this._variables,u=((l=this._bgColors[e])==null?void 0:l.colors)||[];if(!u[s]){const p=((f=this._bgColors[e])==null?void 0:f.setColors)||[];p.includes(r)||p.push(r),u[s]=r,this._bgColors[e]={...n,colors:u,setColors:p}}}max_bars_back({var:t,num:e,var_name:r}){console.log(t,e,r)}float({x:t}){return t}bool({x:t}){return t||!1}string({x:t}){return t}int({x:t}){return t&&Math.trunc(t)}na({x:t}){return t===void 0}fixnan({source:t},e){return t===void 0||isNaN(t)?this._cacheData[`fixnan_${e}`]:(this._cacheData[`fixnan_${e}`]=t,t)}nz({source:t,replacement:e}){return t!==void 0&&!isNaN(t)?t:e||0}time({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._timeHandle(this._variables.time,s,t,e,r,n)}time_close({timeframe:t="",session:e,timezone:r,bars_back:n=0},s){return this._variables.time_close&&this._timeHandle(this._variables.time_close,s,t,e,r,n)}timestamp({dateString:t,timezone:e,year:r,month:n,day:s,hour:u=0,minute:l=0,second:f=0}){if(t)return ne(t).valueOf();let p=ne({year:r,month:n,day:s,hour:u,minute:l,second:f});return e&&(p=Mr(p.valueOf(),e)),p.valueOf()}weekofyear({time:t,timezone:e}){return Mr(t,e).week()}year({time:t,timezone:e}){return Mr(t,e).year()}second({time:t,timezone:e}){return Mr(t,e).second()}month({time:t,timezone:e}){return Mr(t,e).month()+1}minute({time:t,timezone:e}){return Mr(t,e).minute()}hour({time:t,timezone:e}){return Mr(t,e).hour()}dayofweek({time:t,timezone:e}){return Mr(t,e).day()+1}dayofmonth({time:t,timezone:e}){return Mr(t,e).date()}_calcTimeOffset(t,e){const r=this._variables.getTimeTradingday(t,e),n=Tn(e)*1e3;return t-r-Math.floor((t-r)/n)*n}_timeHandle(t,e,r="",n,s,u=0){const l=r||this._variables.timeframe.period,f=Tn(l),p=Tn(this._variables.timeframe.period);let h;if(f<=p)h=t;else{const c=`time_${e}`,m=this._cacheData[c];if(m)m.currentTime+f*1e3-m.offset<=t?(h=t,this._cacheData[c]={currentTime:t,offset:0}):h=m;else{const _=this._calcTimeOffset(t,l);this._cacheData[c]={currentTime:t,offset:_},h=t}}if(n){const{timePeriods:c,weeks:m}=this._parserSession(n),_=ne(t).format("YYYY-MM-DD"),w=h;h=void 0;for(const y of c){const[v,E]=y;if(ne(t).isBetween(`${_} ${v}`,`${_} ${E}`,"hour")){ne(w).isBetween(`${_} ${v}`,`${_} ${E}`,"hour")?h=w:h=ne(`${_} ${v}`).valueOf();break}}const g=this._variables.dayofweek;h&&!m.includes(g)&&(h=void 0)}return s&&(h=h&&Mr(h,s).valueOf()),h&&h-u*p*1e3}_seriesColorHandle(t,e){var s,u;const{seriesColors:r}=t,n=this._plots.get(e);if(n&&r!=null&&r.length)for(const l of r){if((s=n.gradientColorKeys)!=null&&s.includes(l))continue;const f=t[l],p=n[`${l}s`]||[];p.includes(f)||(p.push(f),n[`${l}s`]=p,p.length>5&&(n[`${l}s`]=[],(u=n.gradientColorKeys)==null||u.push(l)))}}_parserSession(t){const e=t.split(":"),r=e[0],s=(e[1]||"1234567").split("").map(l=>{const f=parseInt(l,10);if(f<1||f>7)throw new Error(`Invalid day of week: ${l}`);return f});return{timePeriods:r.split(",").map(l=>{const f=l.split("-");if(f.length!==2)throw new Error(`Invalid time period: ${l}`);return[this._processTime(f[0]),this._processTime(f[1])]}),weeks:s}}_processTime(t){const e=parseInt(t.slice(0,2),10),r=parseInt(t.slice(2),10);if(!(e>=0&&e<=23)&&r>=0&&r<=59)throw new Error("Invalid time: Time must be within 00:00 to 23:59");return`${e}:${r}`}}/**
63
63
  * @license
64
64
  * Copyright 2019 Google LLC
@@ -65026,7 +65026,7 @@ function Jr(s, i, a) {
65026
65026
  function Tb() {
65027
65027
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
65028
65028
  }
65029
- const pu = new Worker(new URL("" + new URL("assets/scriptsRunWorker-CT7aptUT.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
65029
+ const pu = new Worker(new URL("" + new URL("assets/scriptsRunWorker-vL9x1NCe.js", import.meta.url).href, import.meta.url), { type: "module", name: "Run TccScript Server" });
65030
65030
  pu.onerror = (s) => {
65031
65031
  console.error(s);
65032
65032
  };
@@ -135,7 +135,7 @@ function print() { __p += __j.call(arguments, '') }
135
135
  * @license
136
136
  * Copyright 2019 Google LLC
137
137
  * SPDX-License-Identifier: Apache-2.0
138
- */const eo=Symbol("Comlink.proxy"),ep=Symbol("Comlink.endpoint"),tp=Symbol("Comlink.releaseProxy"),si=Symbol("Comlink.finalizer"),Ga=Symbol("Comlink.thrown"),to=s=>typeof s=="object"&&s!==null||typeof s=="function",rp={canHandle:s=>to(s)&&s[eo],serialize(s){const{port1:i,port2:a}=new MessageChannel;return ao(s,i),[a,[a]]},deserialize(s){return s.start(),ii(s)}},ap={canHandle:s=>to(s)&&Ga in s,serialize({value:s}){let i;return s instanceof Error?i={isError:!0,value:{message:s.message,name:s.name,stack:s.stack}}:i={isError:!1,value:s},[i,[]]},deserialize(s){throw s.isError?Object.assign(new Error(s.value.message),s.value):s.value}},ro=new Map([["proxy",rp],["throw",ap]]);function sp(s,i){for(const a of s)if(i===a||a==="*"||a instanceof RegExp&&a.test(i))return!0;return!1}function ao(s,i=globalThis,a=["*"]){i.addEventListener("message",function l(u){if(!u||!u.data)return;if(!sp(a,u.origin)){console.warn(`Invalid origin '${u.origin}' for comlink proxy`);return}const{id:p,type:m,path:b}=Object.assign({path:[]},u.data),g=(u.data.argumentList||[]).map(_r);let v;try{const w=b.slice(0,-1).reduce((O,P)=>O[P],s),D=b.reduce((O,P)=>O[P],s);switch(m){case"GET":v=D;break;case"SET":w[b.slice(-1)[0]]=_r(u.data.value),v=!0;break;case"APPLY":v=D.apply(w,g);break;case"CONSTRUCT":{const O=new D(...g);v=up(O)}break;case"ENDPOINT":{const{port1:O,port2:P}=new MessageChannel;ao(s,P),v=cp(O,[O])}break;case"RELEASE":v=void 0;break;default:return}}catch(w){v={value:w,[Ga]:0}}Promise.resolve(v).catch(w=>({value:w,[Ga]:0})).then(w=>{const[D,O]=Qa(w);i.postMessage(Object.assign(Object.assign({},D),{id:p}),O),m==="RELEASE"&&(i.removeEventListener("message",l),so(i),si in s&&typeof s[si]=="function"&&s[si]())}).catch(w=>{const[D,O]=Qa({value:new TypeError("Unserializable return value"),[Ga]:0});i.postMessage(Object.assign(Object.assign({},D),{id:p}),O)})}),i.start&&i.start()}function ip(s){return s.constructor.name==="MessagePort"}function so(s){ip(s)&&s.close()}function ii(s,i){return ni(s,[],i)}function Ya(s){if(s)throw new Error("Proxy has been released and is not useable")}function io(s){return Nr(s,{type:"RELEASE"}).then(()=>{so(s)})}const Va=new WeakMap,Ka="FinalizationRegistry"in globalThis&&new FinalizationRegistry(s=>{const i=(Va.get(s)||0)-1;Va.set(s,i),i===0&&io(s)});function np(s,i){const a=(Va.get(i)||0)+1;Va.set(i,a),Ka&&Ka.register(s,i,s)}function op(s){Ka&&Ka.unregister(s)}function ni(s,i=[],a=function(){}){let l=!1;const u=new Proxy(a,{get(p,m){if(Ya(l),m===tp)return()=>{op(u),io(s),l=!0};if(m==="then"){if(i.length===0)return{then:()=>u};const b=Nr(s,{type:"GET",path:i.map(g=>g.toString())}).then(_r);return b.then.bind(b)}return ni(s,[...i,m])},set(p,m,b){Ya(l);const[g,v]=Qa(b);return Nr(s,{type:"SET",path:[...i,m].map(w=>w.toString()),value:g},v).then(_r)},apply(p,m,b){Ya(l);const g=i[i.length-1];if(g===ep)return Nr(s,{type:"ENDPOINT"}).then(_r);if(g==="bind")return ni(s,i.slice(0,-1));const[v,w]=no(b);return Nr(s,{type:"APPLY",path:i.map(D=>D.toString()),argumentList:v},w).then(_r)},construct(p,m){Ya(l);const[b,g]=no(m);return Nr(s,{type:"CONSTRUCT",path:i.map(v=>v.toString()),argumentList:b},g).then(_r)}});return np(u,s),u}function lp(s){return Array.prototype.concat.apply([],s)}function no(s){const i=s.map(Qa);return[i.map(a=>a[0]),lp(i.map(a=>a[1]))]}const oo=new WeakMap;function cp(s,i){return oo.set(s,i),s}function up(s){return Object.assign(s,{[eo]:!0})}function Qa(s){for(const[i,a]of ro)if(a.canHandle(s)){const[l,u]=a.serialize(s);return[{type:"HANDLER",name:i,value:l},u]}return[{type:"RAW",value:s},oo.get(s)||[]]}function _r(s){switch(s.type){case"HANDLER":return ro.get(s.name).deserialize(s.value);case"RAW":return s.value}}function Nr(s,i,a){return new Promise(l=>{const u=dp();s.addEventListener("message",function p(m){!m.data||!m.data.id||m.data.id!==u||(s.removeEventListener("message",p),l(m.data))}),s.start&&s.start(),s.postMessage(Object.assign({id:u},i),a)})}function dp(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const lo=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-CT7aptUT.js").href:new URL("assets/scriptsRunWorker-CT7aptUT.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Fa&&Fa.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});lo.onerror=s=>{console.error(s)};const pp=ii(lo),mp=ii(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-ClJL6TbY.js").href:new URL("assets/parserTccWorker-ClJL6TbY.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Fa&&Fa.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function co(s,i=!1){const{functions:a,types:l,constants:u,variables:p,methods:m}=At;return await mp(s,i,{functions:Object.fromEntries(a),methods:Object.fromEntries(m),types:Object.fromEntries(l),constants:Object.fromEntries(u),variables:Object.fromEntries(p)})}async function uo(s,i,a=!0){return await pp(s,i,a)}function fp(s){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor.worker-CT5Cb1wO.js").href:new URL("assets/editor.worker-CT5Cb1wO.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),{name:s==null?void 0:s.name})}var Ct;(function(s){s.BOOL="bool",s.INT="int",s.FLOAT="float",s.ARRAY="array",s.BOX="box",s.CHART_POINT="chart.point",s.COLOR="color",s.CONST="const",s.LABEL="label",s.LINE="line",s.LINEFILL="linefill",s.MAP="map",s.MATRIX="matrix",s.POLYLINE="polyline",s.SERIES="series",s.SIMPLE="simple",s.STRING="string",s.TABLE="table",s.UNDETERMINED="undetermined type",s.INPUT="input",s.NA="na",s.VOID="void"})(Ct||(Ct={}));var po;(function(s){s.FlowStmt="FlowStmt",s.DeclareAssign="DeclareAssign",s.VarBlockStmt="VarBlockStmt",s.VarSingle="VarSingle",s.VarMultiple="VarMultiple",s.ParenthesizedExpression="ParenthesizedExpression",s.AdditiveExpression="AdditiveExpression",s.RelationalExpression="RelationalExpression",s.EqualityExpression="EqualityExpression",s.TernaryExpression="TernaryExpression",s.UnaryExpression="UnaryExpression",s.NotExpression="NotExpression",s.MemberIndexExpression="MemberIndexExpression",s.MethodExpression="MethodExpression",s.LogicalAndExpression="LogicalAndExpression",s.LogicalOrExpression="LogicalOrExpression",s.MultiplicativeExpression="MultiplicativeExpression",s.Brackethesized="Brackethesized",s.IfStatement="IfStatement",s.ForToStatement="ForToStatement",s.ForInStatement="ForInStatement",s.SwitchStatement="SwitchStatement",s.CaseClause="CaseClause",s.DefaultCaluse="DefaultCaluse",s.WhileStatement="WhileStatement",s.ImportElement="ImportElement",s.Literal="Literal",s.ArrowFunction="ArrowFunction",s.ArrowMethod="ArrowMethod",s.TypeStatement="TypeStatement",s.Name="Name",s.AgainAssign="AgainAssign"})(po||(po={}));var mo;(function(s){s.dividends="dividends",s.none="none",s.splits="splits"})(mo||(mo={}));var fo;(function(s){s.freqAll="freq_all",s.freqOncePerBar="freq_once_per_bar",s.freqOncePerBarClose="freq_once_per_bar_close"})(fo||(fo={}));var yo;(function(s){s.gapsOff="gaps_off",s.gapsOn="gaps_on",s.lookaheadOff="lookahead_off",s.lookaheadOn="lookahead_on"})(yo||(yo={}));var ho;(function(s){s.all="all",s.dataWindow="data_window",s.none="none",s.pane="pane",s.priceScale="price_scale",s.statusLine="status_line"})(ho||(ho={}));var _o;(function(s){s.both="both",s.left="left",s.none="none",s.right="right"})(_o||(_o={}));var go;(function(s){s.inherit="inherit",s.mintick="mintick",s.percent="percent",s.price="price",s.volume="volume"})(go||(go={}));var bo;(function(s){s.styleDashed="style_dashed",s.styleDotted="style_dotted",s.styleSolid="style_solid"})(bo||(bo={}));var xo;(function(s){s.styleArrowdown="style_arrowdown",s.styleArrowup="style_arrowup",s.styleCircle="style_circle",s.styleCross="style_cross",s.styleDiamond="style_diamond",s.styleFlag="style_flag",s.styleLabelCenter="style_label_center",s.styleLabelDown="style_label_down",s.styleLabelLeft="style_label_left",s.styleLabelLowerLeft="style_label_lower_left",s.styleLabelLowerRight="style_label_lower_right",s.styleLabelRight="style_label_right",s.styleLabelUp="style_label_up",s.styleLabelUpperLeft="style_label_upper_left",s.styleLabelUpperRight="style_label_upper_right",s.styleNone="style_none",s.styleSquare="style_square",s.styleTextOutline="style_text_outline",s.styleTriangledown="style_triangledown",s.styleTriangleup="style_triangleup",s.styleXcross="style_xcross"})(xo||(xo={}));var vo;(function(s){s.styleArrowBoth="style_arrow_both",s.styleArrowLeft="style_arrow_left",s.styleArrowRight="style_arrow_right",s.styleDashed="style_dashed",s.styleDotted="style_dotted",s.styleSolid="style_solid"})(vo||(vo={}));var wo;(function(s){s.abovebar="abovebar",s.absolute="absolute",s.belowbar="belowbar",s.bottom="bottom",s.top="top"})(wo||(wo={}));var To;(function(s){s.ascending="ascending",s.descending="descending"})(To||(To={}));var Io;(function(s){s.styleArea="Area",s.styleAreabr="Area With Breaks",s.styleCircles="Circles",s.styleColumns="Columns",s.styleCross="Cross",s.styleHistogram="Histogram",s.styleLine="Line",s.styleLinebr="Line With Breaks",s.styleStepline="Step Line",s.styleSteplineDiamond="Step Line With Diamonds",s.styleSteplinebr="Step line with Breaks"})(Io||(Io={}));var Do;(function(s){s.bottomCenter="bottom_center",s.bottomLeft="bottom_left",s.bottomRight="bottom_right",s.middleCenter="middle_center",s.middleLeft="middle_left",s.middleRight="middle_right",s.topCenter="top_center",s.topLeft="top_left",s.topRight="top_right"})(Do||(Do={}));var ko;(function(s){s.left="left",s.none="none",s.right="right"})(ko||(ko={}));var Ao;(function(s){s.extended="extended",s.regular="regular"})(Ao||(Ao={}));var qo;(function(s){s.arrowdown="arrowdown",s.arrowup="arrowup",s.circle="circle",s.cross="cross",s.diamond="diamond",s.flag="flag",s.labeldown="labeldown",s.labelup="labelup",s.square="square",s.triangledown="triangledown",s.triangleup="triangleup",s.xcross="xcross"})(qo||(qo={}));var Co;(function(s){s.auto="auto",s.huge="huge",s.large="large",s.normal="normal",s.small="small",s.tiny="tiny"})(Co||(Co={}));var So;(function(s){s.cash="cash",s.fixed="fixed",s.percentOfEquity="percent_of_equity"})(So||(So={}));var zo;(function(s){s.cashPerContract="cash_per_contract",s.cashPerOrder="cash_per_order",s.percent="percent"})(zo||(zo={}));var No;(function(s){s.all="all",s.long="long",s.short="short"})(No||(No={}));var Oo;(function(s){s.cancel="cancel",s.none="none",s.reduce="reduce"})(Oo||(Oo={}));var Po;(function(s){s.alignBottom="align_bottom",s.alignCenter="align_center",s.alignLeft="align_left",s.alignRight="align_right",s.alignTop="align_top",s.wrapAuto="wrap_auto",s.wrapNone="wrap_none"})(Po||(Po={}));var Ro;(function(s){s.bar_index="bar_index",s.bar_time="bar_time"})(Ro||(Ro={}));var Eo;(function(s){s.abovebar="abovebar",s.belowbar="belowbar",s.price="price"})(Eo||(Eo={}));var Lo;(function(s){s.actual="actual",s.estimate="estimate",s.standardized="standardized"})(Lo||(Lo={}));var Mo;(function(s){s.traditional="Traditional",s.fibonacci="Fibonacci",s.woodie="Woodie",s.classic="Classic",s.dm="DM",s.camarilla="Camarilla"})(Mo||(Mo={})),Ct.SERIES,Ct.SIMPLE,Ct.INPUT,Ct.CONST,Ct.INT,Ct.FLOAT,Ct.BOOL,Ct.COLOR,Ct.STRING;const yp={domReadOnly:!0,scrollBeyondLastLine:!1,readOnly:!0,minimap:{enabled:!1},scrollbar:{vertical:"hidden",horizontal:"hidden",alwaysConsumeMouseWheel:!1},contextmenu:!1};self.MonacoEnvironment={getWorker(){return new fp({name:"Editor Worker"})}},Qs.config({monaco:pu});const hp=(s,i)=>{const{height:a,width:l,theme:u,options:p,hasDiff:m,readOnly:b,onChange:g,onDeclareConfigChange:v,onCursorPositionChange:w}=s,D=M.useRef(null);M.useImperativeHandle(i,()=>({saveScript(){var E;(E=D.current)==null||E.saveScripts()},setScript(E){var K;(K=D.current)==null||K.setValue(E)},gotoLine(){var E;(E=D.current)==null||E.gotoLine()},getEditorLayout(){var E;return(E=D.current)==null?void 0:E.getEditorLayout()}})),M.useEffect(()=>{var E,K;m?(K=D.current)==null||K.addDiffDecorations():(E=D.current)==null||E.removeDiffDecorations()},[m]);function O(E,K){var he;zr.initBuiltinsTrees(),D.current=new Zd(E,K),m&&((he=D.current)==null||he.addDiffDecorations());const $=E.getValue()+`
138
+ */const eo=Symbol("Comlink.proxy"),ep=Symbol("Comlink.endpoint"),tp=Symbol("Comlink.releaseProxy"),si=Symbol("Comlink.finalizer"),Ga=Symbol("Comlink.thrown"),to=s=>typeof s=="object"&&s!==null||typeof s=="function",rp={canHandle:s=>to(s)&&s[eo],serialize(s){const{port1:i,port2:a}=new MessageChannel;return ao(s,i),[a,[a]]},deserialize(s){return s.start(),ii(s)}},ap={canHandle:s=>to(s)&&Ga in s,serialize({value:s}){let i;return s instanceof Error?i={isError:!0,value:{message:s.message,name:s.name,stack:s.stack}}:i={isError:!1,value:s},[i,[]]},deserialize(s){throw s.isError?Object.assign(new Error(s.value.message),s.value):s.value}},ro=new Map([["proxy",rp],["throw",ap]]);function sp(s,i){for(const a of s)if(i===a||a==="*"||a instanceof RegExp&&a.test(i))return!0;return!1}function ao(s,i=globalThis,a=["*"]){i.addEventListener("message",function l(u){if(!u||!u.data)return;if(!sp(a,u.origin)){console.warn(`Invalid origin '${u.origin}' for comlink proxy`);return}const{id:p,type:m,path:b}=Object.assign({path:[]},u.data),g=(u.data.argumentList||[]).map(_r);let v;try{const w=b.slice(0,-1).reduce((O,P)=>O[P],s),D=b.reduce((O,P)=>O[P],s);switch(m){case"GET":v=D;break;case"SET":w[b.slice(-1)[0]]=_r(u.data.value),v=!0;break;case"APPLY":v=D.apply(w,g);break;case"CONSTRUCT":{const O=new D(...g);v=up(O)}break;case"ENDPOINT":{const{port1:O,port2:P}=new MessageChannel;ao(s,P),v=cp(O,[O])}break;case"RELEASE":v=void 0;break;default:return}}catch(w){v={value:w,[Ga]:0}}Promise.resolve(v).catch(w=>({value:w,[Ga]:0})).then(w=>{const[D,O]=Qa(w);i.postMessage(Object.assign(Object.assign({},D),{id:p}),O),m==="RELEASE"&&(i.removeEventListener("message",l),so(i),si in s&&typeof s[si]=="function"&&s[si]())}).catch(w=>{const[D,O]=Qa({value:new TypeError("Unserializable return value"),[Ga]:0});i.postMessage(Object.assign(Object.assign({},D),{id:p}),O)})}),i.start&&i.start()}function ip(s){return s.constructor.name==="MessagePort"}function so(s){ip(s)&&s.close()}function ii(s,i){return ni(s,[],i)}function Ya(s){if(s)throw new Error("Proxy has been released and is not useable")}function io(s){return Nr(s,{type:"RELEASE"}).then(()=>{so(s)})}const Va=new WeakMap,Ka="FinalizationRegistry"in globalThis&&new FinalizationRegistry(s=>{const i=(Va.get(s)||0)-1;Va.set(s,i),i===0&&io(s)});function np(s,i){const a=(Va.get(i)||0)+1;Va.set(i,a),Ka&&Ka.register(s,i,s)}function op(s){Ka&&Ka.unregister(s)}function ni(s,i=[],a=function(){}){let l=!1;const u=new Proxy(a,{get(p,m){if(Ya(l),m===tp)return()=>{op(u),io(s),l=!0};if(m==="then"){if(i.length===0)return{then:()=>u};const b=Nr(s,{type:"GET",path:i.map(g=>g.toString())}).then(_r);return b.then.bind(b)}return ni(s,[...i,m])},set(p,m,b){Ya(l);const[g,v]=Qa(b);return Nr(s,{type:"SET",path:[...i,m].map(w=>w.toString()),value:g},v).then(_r)},apply(p,m,b){Ya(l);const g=i[i.length-1];if(g===ep)return Nr(s,{type:"ENDPOINT"}).then(_r);if(g==="bind")return ni(s,i.slice(0,-1));const[v,w]=no(b);return Nr(s,{type:"APPLY",path:i.map(D=>D.toString()),argumentList:v},w).then(_r)},construct(p,m){Ya(l);const[b,g]=no(m);return Nr(s,{type:"CONSTRUCT",path:i.map(v=>v.toString()),argumentList:b},g).then(_r)}});return np(u,s),u}function lp(s){return Array.prototype.concat.apply([],s)}function no(s){const i=s.map(Qa);return[i.map(a=>a[0]),lp(i.map(a=>a[1]))]}const oo=new WeakMap;function cp(s,i){return oo.set(s,i),s}function up(s){return Object.assign(s,{[eo]:!0})}function Qa(s){for(const[i,a]of ro)if(a.canHandle(s)){const[l,u]=a.serialize(s);return[{type:"HANDLER",name:i,value:l},u]}return[{type:"RAW",value:s},oo.get(s)||[]]}function _r(s){switch(s.type){case"HANDLER":return ro.get(s.name).deserialize(s.value);case"RAW":return s.value}}function Nr(s,i,a){return new Promise(l=>{const u=dp();s.addEventListener("message",function p(m){!m.data||!m.data.id||m.data.id!==u||(s.removeEventListener("message",p),l(m.data))}),s.start&&s.start(),s.postMessage(Object.assign({id:u},i),a)})}function dp(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}const lo=new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/scriptsRunWorker-vL9x1NCe.js").href:new URL("assets/scriptsRunWorker-vL9x1NCe.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Fa&&Fa.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Run TccScript Server"});lo.onerror=s=>{console.error(s)};const pp=ii(lo),mp=ii(new Worker(new URL(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/parserTccWorker-ClJL6TbY.js").href:new URL("assets/parserTccWorker-ClJL6TbY.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Fa&&Fa.src||new URL("trading-vue-editor.umd.cjs",document.baseURI).href),{type:"module",name:"Parser TccScript Server"}));async function co(s,i=!1){const{functions:a,types:l,constants:u,variables:p,methods:m}=At;return await mp(s,i,{functions:Object.fromEntries(a),methods:Object.fromEntries(m),types:Object.fromEntries(l),constants:Object.fromEntries(u),variables:Object.fromEntries(p)})}async function uo(s,i,a=!0){return await pp(s,i,a)}function fp(s){return new Worker(""+(typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__dirname+"/assets/editor.worker-CT5Cb1wO.js").href:new URL("assets/editor.worker-CT5Cb1wO.js",typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||document.baseURI).href),{name:s==null?void 0:s.name})}var Ct;(function(s){s.BOOL="bool",s.INT="int",s.FLOAT="float",s.ARRAY="array",s.BOX="box",s.CHART_POINT="chart.point",s.COLOR="color",s.CONST="const",s.LABEL="label",s.LINE="line",s.LINEFILL="linefill",s.MAP="map",s.MATRIX="matrix",s.POLYLINE="polyline",s.SERIES="series",s.SIMPLE="simple",s.STRING="string",s.TABLE="table",s.UNDETERMINED="undetermined type",s.INPUT="input",s.NA="na",s.VOID="void"})(Ct||(Ct={}));var po;(function(s){s.FlowStmt="FlowStmt",s.DeclareAssign="DeclareAssign",s.VarBlockStmt="VarBlockStmt",s.VarSingle="VarSingle",s.VarMultiple="VarMultiple",s.ParenthesizedExpression="ParenthesizedExpression",s.AdditiveExpression="AdditiveExpression",s.RelationalExpression="RelationalExpression",s.EqualityExpression="EqualityExpression",s.TernaryExpression="TernaryExpression",s.UnaryExpression="UnaryExpression",s.NotExpression="NotExpression",s.MemberIndexExpression="MemberIndexExpression",s.MethodExpression="MethodExpression",s.LogicalAndExpression="LogicalAndExpression",s.LogicalOrExpression="LogicalOrExpression",s.MultiplicativeExpression="MultiplicativeExpression",s.Brackethesized="Brackethesized",s.IfStatement="IfStatement",s.ForToStatement="ForToStatement",s.ForInStatement="ForInStatement",s.SwitchStatement="SwitchStatement",s.CaseClause="CaseClause",s.DefaultCaluse="DefaultCaluse",s.WhileStatement="WhileStatement",s.ImportElement="ImportElement",s.Literal="Literal",s.ArrowFunction="ArrowFunction",s.ArrowMethod="ArrowMethod",s.TypeStatement="TypeStatement",s.Name="Name",s.AgainAssign="AgainAssign"})(po||(po={}));var mo;(function(s){s.dividends="dividends",s.none="none",s.splits="splits"})(mo||(mo={}));var fo;(function(s){s.freqAll="freq_all",s.freqOncePerBar="freq_once_per_bar",s.freqOncePerBarClose="freq_once_per_bar_close"})(fo||(fo={}));var yo;(function(s){s.gapsOff="gaps_off",s.gapsOn="gaps_on",s.lookaheadOff="lookahead_off",s.lookaheadOn="lookahead_on"})(yo||(yo={}));var ho;(function(s){s.all="all",s.dataWindow="data_window",s.none="none",s.pane="pane",s.priceScale="price_scale",s.statusLine="status_line"})(ho||(ho={}));var _o;(function(s){s.both="both",s.left="left",s.none="none",s.right="right"})(_o||(_o={}));var go;(function(s){s.inherit="inherit",s.mintick="mintick",s.percent="percent",s.price="price",s.volume="volume"})(go||(go={}));var bo;(function(s){s.styleDashed="style_dashed",s.styleDotted="style_dotted",s.styleSolid="style_solid"})(bo||(bo={}));var xo;(function(s){s.styleArrowdown="style_arrowdown",s.styleArrowup="style_arrowup",s.styleCircle="style_circle",s.styleCross="style_cross",s.styleDiamond="style_diamond",s.styleFlag="style_flag",s.styleLabelCenter="style_label_center",s.styleLabelDown="style_label_down",s.styleLabelLeft="style_label_left",s.styleLabelLowerLeft="style_label_lower_left",s.styleLabelLowerRight="style_label_lower_right",s.styleLabelRight="style_label_right",s.styleLabelUp="style_label_up",s.styleLabelUpperLeft="style_label_upper_left",s.styleLabelUpperRight="style_label_upper_right",s.styleNone="style_none",s.styleSquare="style_square",s.styleTextOutline="style_text_outline",s.styleTriangledown="style_triangledown",s.styleTriangleup="style_triangleup",s.styleXcross="style_xcross"})(xo||(xo={}));var vo;(function(s){s.styleArrowBoth="style_arrow_both",s.styleArrowLeft="style_arrow_left",s.styleArrowRight="style_arrow_right",s.styleDashed="style_dashed",s.styleDotted="style_dotted",s.styleSolid="style_solid"})(vo||(vo={}));var wo;(function(s){s.abovebar="abovebar",s.absolute="absolute",s.belowbar="belowbar",s.bottom="bottom",s.top="top"})(wo||(wo={}));var To;(function(s){s.ascending="ascending",s.descending="descending"})(To||(To={}));var Io;(function(s){s.styleArea="Area",s.styleAreabr="Area With Breaks",s.styleCircles="Circles",s.styleColumns="Columns",s.styleCross="Cross",s.styleHistogram="Histogram",s.styleLine="Line",s.styleLinebr="Line With Breaks",s.styleStepline="Step Line",s.styleSteplineDiamond="Step Line With Diamonds",s.styleSteplinebr="Step line with Breaks"})(Io||(Io={}));var Do;(function(s){s.bottomCenter="bottom_center",s.bottomLeft="bottom_left",s.bottomRight="bottom_right",s.middleCenter="middle_center",s.middleLeft="middle_left",s.middleRight="middle_right",s.topCenter="top_center",s.topLeft="top_left",s.topRight="top_right"})(Do||(Do={}));var ko;(function(s){s.left="left",s.none="none",s.right="right"})(ko||(ko={}));var Ao;(function(s){s.extended="extended",s.regular="regular"})(Ao||(Ao={}));var qo;(function(s){s.arrowdown="arrowdown",s.arrowup="arrowup",s.circle="circle",s.cross="cross",s.diamond="diamond",s.flag="flag",s.labeldown="labeldown",s.labelup="labelup",s.square="square",s.triangledown="triangledown",s.triangleup="triangleup",s.xcross="xcross"})(qo||(qo={}));var Co;(function(s){s.auto="auto",s.huge="huge",s.large="large",s.normal="normal",s.small="small",s.tiny="tiny"})(Co||(Co={}));var So;(function(s){s.cash="cash",s.fixed="fixed",s.percentOfEquity="percent_of_equity"})(So||(So={}));var zo;(function(s){s.cashPerContract="cash_per_contract",s.cashPerOrder="cash_per_order",s.percent="percent"})(zo||(zo={}));var No;(function(s){s.all="all",s.long="long",s.short="short"})(No||(No={}));var Oo;(function(s){s.cancel="cancel",s.none="none",s.reduce="reduce"})(Oo||(Oo={}));var Po;(function(s){s.alignBottom="align_bottom",s.alignCenter="align_center",s.alignLeft="align_left",s.alignRight="align_right",s.alignTop="align_top",s.wrapAuto="wrap_auto",s.wrapNone="wrap_none"})(Po||(Po={}));var Ro;(function(s){s.bar_index="bar_index",s.bar_time="bar_time"})(Ro||(Ro={}));var Eo;(function(s){s.abovebar="abovebar",s.belowbar="belowbar",s.price="price"})(Eo||(Eo={}));var Lo;(function(s){s.actual="actual",s.estimate="estimate",s.standardized="standardized"})(Lo||(Lo={}));var Mo;(function(s){s.traditional="Traditional",s.fibonacci="Fibonacci",s.woodie="Woodie",s.classic="Classic",s.dm="DM",s.camarilla="Camarilla"})(Mo||(Mo={})),Ct.SERIES,Ct.SIMPLE,Ct.INPUT,Ct.CONST,Ct.INT,Ct.FLOAT,Ct.BOOL,Ct.COLOR,Ct.STRING;const yp={domReadOnly:!0,scrollBeyondLastLine:!1,readOnly:!0,minimap:{enabled:!1},scrollbar:{vertical:"hidden",horizontal:"hidden",alwaysConsumeMouseWheel:!1},contextmenu:!1};self.MonacoEnvironment={getWorker(){return new fp({name:"Editor Worker"})}},Qs.config({monaco:pu});const hp=(s,i)=>{const{height:a,width:l,theme:u,options:p,hasDiff:m,readOnly:b,onChange:g,onDeclareConfigChange:v,onCursorPositionChange:w}=s,D=M.useRef(null);M.useImperativeHandle(i,()=>({saveScript(){var E;(E=D.current)==null||E.saveScripts()},setScript(E){var K;(K=D.current)==null||K.setValue(E)},gotoLine(){var E;(E=D.current)==null||E.gotoLine()},getEditorLayout(){var E;return(E=D.current)==null?void 0:E.getEditorLayout()}})),M.useEffect(()=>{var E,K;m?(K=D.current)==null||K.addDiffDecorations():(E=D.current)==null||E.removeDiffDecorations()},[m]);function O(E,K){var he;zr.initBuiltinsTrees(),D.current=new Zd(E,K),m&&((he=D.current)==null||he.addDiffDecorations());const $=E.getValue()+`
139
139
 
140
140
  `;D.current.onChangeCursorPosition(w),g&&g($),!b&&P($)}const P=M.useCallback(async E=>{var j;const K=Date.now(),{errors:$,functions:he,methods:le,types:J,variables:ue,overloadsFuncs:ee,preParserCode:ze}=await co(E),ge=new Map(Object.entries(he)),se=new Map(Object.entries(le)),ot=new Map(Object.entries(J)),_t=new Map(Object.entries(ue));la.setUserDefined({functions:ge,methods:se,types:ot,variables:_t},ee),zr.setUserDefind(ge,ot,_t,se);const Re=$.map(re=>({...re,severity:re.type||st.MarkerSeverity.Error}));if(b)return;try{console.log(ze);const re=await uo(ze,{isPreParser:!0});console.log(re),v&&v(re)}catch(re){console.log(re,"==================error- Run TccScript Server"),$.push({message:`Runtime Error: ${re.message}`,startLineNumber:0,endLineNumber:0,startColumn:0,endColumn:0})}(j=D.current)==null||j.setModelMarkers(Re);const Ee=Date.now();console.log((Ee-K)/1e3)},[v,b]),F=M.useMemo(()=>zd.debounce(P,1e3),[P]);function B(E){var K;if(b){P(E||"");return}(K=D.current)==null||K.setModelMarkers([]),localStorage.setItem(Vn,E||""),E!==void 0&&(E=E+`
141
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guihz/trading-vue-editor-tes",
3
- "version": "0.0.017",
3
+ "version": "0.0.019",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"