numbl 0.4.11 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-browser/browser.js +1 -1
- package/dist-browser/numbl-core/version.d.ts +1 -1
- package/dist-cli/cli.js +2 -2
- package/dist-lib/lib.js +1 -1
- package/dist-lib/numbl-core/version.d.ts +1 -1
- package/dist-site-viewer/assets/{index-fhKbvuOM.js → index-CGE1_vZ-.js} +4 -4
- package/dist-site-viewer/assets/{numbl-worker-BFP9xj5e.js → numbl-worker-DddtCPW_.js} +1 -1
- package/dist-site-viewer/index.html +1 -1
- package/package.json +1 -1
|
@@ -169,7 +169,7 @@ ${r}`};function OM(e,t){return t===0?Mu(e):e===0?`${Mu(t)}i`:t<0?`${Mu(e)} - ${M
|
|
|
169
169
|
`)}const aue=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function $p(e,t){const n=e.fields.get(t);return n===void 0?null:typeof n=="number"?n:typeof n=="boolean"?n?1:0:null}function lue(e){return e.className==="datetime"?cue(e):e.className==="duration"?uue(e):null}function cue(e){const t=$p(e,"Year"),n=$p(e,"Month"),r=$p(e,"Day"),i=$p(e,"Hour"),s=$p(e,"Minute"),o=$p(e,"Second");if(t===null||n===null||r===null||i===null||s===null||o===null)return null;const a=Math.max(0,Math.min(11,Math.floor(n)-1)),l=aue[a],c=String(Math.floor(r)).padStart(2,"0"),u=String(Math.floor(t));if(!(i!==0||s!==0||o!==0))return`${c}-${l}-${u}`;const f=String(Math.floor(i)).padStart(2,"0"),d=String(Math.floor(s)).padStart(2,"0"),p=String(Math.floor(o)).padStart(2,"0");return`${c}-${l}-${u} ${f}:${d}:${p}`}function uue(e){const t=$p(e,"Seconds");if(t===null)return null;const n=t<0,r=Math.abs(t),i=Math.floor(r/3600),s=Math.floor(r%3600/60),o=r-i*3600-s*60,a=Math.floor(o),l=o===a?String(a).padStart(2,"0"):o.toFixed(6).replace(/0+$/,"").replace(/\.$/,"");return`${n?"-":""}${String(i).padStart(2,"0")}:${String(s).padStart(2,"0")}:${l}`}function hue(e){if(!e.keyType&&!e.valueType&&e.entries.size===0)return" dictionary with unset key and value types.";const t=e.keyType??"unset",n=e.valueType??"unset",r=e.entries.size;if(r===0)return` dictionary (${t} ⟼ ${n}) with no entries.`;const s=[` dictionary (${t} ⟼ ${n}) with ${r} ${r===1?"entry":"entries"}:
|
|
170
170
|
`],o=[];let a=0;for(const{key:l,value:c}of e.entries.values()){const u=fue(l),h=Gu(c);o.push({keyStr:u,valStr:h}),a=Math.max(a,u.length)}for(const{keyStr:l,valStr:c}of o)s.push(` ${l.padEnd(a)} ⟼ ${c}`);return s.join(`
|
|
171
171
|
`)}function fue(e){return mt(e)?`"${e}"`:lt(e)?`'${e.value}'`:Gu(e)}function D(e){return typeof e=="number"?new Float64Array(e):new Float64Array(e)}function Ac(e){return e()}const A={num(e){return e},tensor(e,t,n){const r=e instanceof Float64Array?e:D(e),i=n?n instanceof Float64Array?n:D(n):void 0,s=[...t];for(;s.length>2&&s[s.length-1]===1;)s.pop();return new Da(r,s,i)},tensorRaw(e,t){return new Da(e,t)},scalar(e){return e},row(e,t){const n=t?D(t):void 0;return new Da(D(e),[1,e.length],n)},col(e,t){const n=t?D(t):void 0;return new Da(D(e),[e.length,1],n)},matrix(e,t,n,r){const i=n instanceof Float64Array?n:D(n),s=r?r instanceof Float64Array?r:D(r):void 0;return new Da(i,[e,t],s)},string(e){return e},stringArray(e,t){return new g$(e,t)},char(e){return new Sf(e)},logical(e){return e},cell(e,t){return new $ce(e,[...t])},struct(e){const t=e instanceof Map?e:new Map(Object.entries(e));return new Vce(t)},func(e,t,n=[]){return new y$(e,t,n)},classInstance(e,t,n=!1,r){const i=new Map;for(const s of t)i.set(s,r?.get(s)??A.tensor(D(0),[0,0]));return new D1(e,i,n)},classInstanceArray(e,t,n){return new UM(e,t,n)},complex(e,t){return new _$(e,t)},dummyHandle(){return new Wce},graphicsHandle(e,t){return new qce(e,t)},structArray(e,t){return new Gce(e,t)},sparseMatrix(e,t,n,r,i,s){return new Xce(e,t,n,r,i,s)},dictionary(e,t,n){return new Yce(e,t,n)}},v2=e=>{if(Re(e))return{kind:"Number"};if(Tt(e))return{kind:"Boolean"};if(mt(e))return{kind:"String"};switch(e.kind){case"complex_number":return{kind:"ComplexNumber"};case"char":return{kind:"Char"};case"tensor":return{kind:"Tensor",isComplex:e.imag!==void 0,isLogical:e._isLogical||void 0};case"cell":return{kind:"Cell",elementType:e.data.length>0?v2(e.data[0]):{kind:"Unknown"},length:"unknown"};case"struct":{const t={};for(const[n,r]of e.fields)t[n]=v2(r);return{kind:"Struct",knownFields:t}}case"function":return{kind:"Function",params:[],returns:{kind:"Unknown"}};case"class_instance":return{kind:"ClassInstance",className:e.className};case"class_instance_array":return{kind:"ClassInstance",className:e.className};case"dummy_handle":return{kind:"DummyHandle"};case"graphics_handle":return{kind:"DummyHandle"};case"struct_array":return{kind:"Unknown"};case"sparse_matrix":return{kind:"SparseMatrix",isComplex:e.pi!==void 0};case"dictionary":return{kind:"Dictionary"};default:return{kind:"Unknown"}}};let due=null;function pue(){return due}function ts(e,t){throw new Error(`** On entry to '${e}' parameter number ${t} had an illegal value`)}const Lt=0,Kn=1,kv=2,cn=0,Un=1,qs=0,Ws=1,Rr=0,Pn=1,N1=0,Wo=1,x$=2,oh=3,mue=4,gue=5,yue=6,_ue=7,vue=8,HL=9,Ih=0,Ed=0,nm=1,wo=0,So=1;function _r(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m){const y=e===Lt,_=t===Lt,b=y?n:i,x=_?i:r;let S=0;if(!y&&e!==kv&&e!==Kn?S=1:!_&&t!==kv&&t!==Kn?S=2:n<0?S=3:r<0?S=4:i<0?S=5:l<Math.max(1,b)?S=8:h<Math.max(1,x)?S=10:m<Math.max(1,n)&&(S=13),S!==0){ts("DGEMM ",S);return}if(!(n===0||r===0||(s===0||i===0)&&f===1)){if(s===0){if(f===0)for(let M=1;M<=r;M++)for(let E=1;E<=n;E++)d[p+(E-1)+(M-1)*m]=0;else for(let M=1;M<=r;M++)for(let E=1;E<=n;E++)d[p+(E-1)+(M-1)*m]=f*d[p+(E-1)+(M-1)*m];return}if(_)if(y)for(let M=1;M<=r;M++){if(f===0)for(let E=1;E<=n;E++)d[p+(E-1)+(M-1)*m]=0;else if(f!==1)for(let E=1;E<=n;E++)d[p+(E-1)+(M-1)*m]=f*d[p+(E-1)+(M-1)*m];for(let E=1;E<=i;E++){const T=s*c[u+(E-1)+(M-1)*h];for(let k=1;k<=n;k++)d[p+(k-1)+(M-1)*m]+=T*o[a+(k-1)+(E-1)*l]}}else for(let M=1;M<=r;M++)for(let E=1;E<=n;E++){let T=0;for(let k=1;k<=i;k++)T+=o[a+(k-1)+(E-1)*l]*c[u+(k-1)+(M-1)*h];f===0?d[p+(E-1)+(M-1)*m]=s*T:d[p+(E-1)+(M-1)*m]=s*T+f*d[p+(E-1)+(M-1)*m]}else if(y)for(let M=1;M<=r;M++){if(f===0)for(let E=1;E<=n;E++)d[p+(E-1)+(M-1)*m]=0;else if(f!==1)for(let E=1;E<=n;E++)d[p+(E-1)+(M-1)*m]=f*d[p+(E-1)+(M-1)*m];for(let E=1;E<=i;E++){const T=s*c[u+(M-1)+(E-1)*h];for(let k=1;k<=n;k++)d[p+(k-1)+(M-1)*m]+=T*o[a+(k-1)+(E-1)*l]}}else for(let M=1;M<=r;M++)for(let E=1;E<=n;E++){let T=0;for(let k=1;k<=i;k++)T+=o[a+(k-1)+(E-1)*l]*c[u+(M-1)+(k-1)*h];f===0?d[p+(E-1)+(M-1)*m]=s*T:d[p+(E-1)+(M-1)*m]=s*T+f*d[p+(E-1)+(M-1)*m]}}}function jM(e,t,n,r,i,s,o,a,l,c,u,h,f){const d=e===Rr,p=d?i:s,m=r===qs,y=t===cn;let _=0;if(e!==Rr&&e!==Pn?_=1:t!==cn&&t!==Un?_=2:r!==Ws&&r!==qs?_=4:i<0?_=5:s<0?_=6:c<Math.max(1,p)?_=9:f<Math.max(1,i)&&(_=11),_!==0){ts("DTRSM ",_);return}if(!(i===0||s===0)){if(o===0){for(let b=1;b<=s;b++)for(let x=1;x<=i;x++)u[h+(x-1)+(b-1)*f]=0;return}if(d)if(y)for(let b=1;b<=s;b++){if(o!==1)for(let x=1;x<=i;x++)u[h+(x-1)+(b-1)*f]=o*u[h+(x-1)+(b-1)*f];for(let x=i;x>=1;x--)if(u[h+(x-1)+(b-1)*f]!==0){m&&(u[h+(x-1)+(b-1)*f]/=a[l+(x-1)+(x-1)*c]);for(let S=1;S<=x-1;S++)u[h+(S-1)+(b-1)*f]-=u[h+(x-1)+(b-1)*f]*a[l+(S-1)+(x-1)*c]}}else for(let b=1;b<=s;b++){if(o!==1)for(let x=1;x<=i;x++)u[h+(x-1)+(b-1)*f]=o*u[h+(x-1)+(b-1)*f];for(let x=1;x<=i;x++)if(u[h+(x-1)+(b-1)*f]!==0){m&&(u[h+(x-1)+(b-1)*f]/=a[l+(x-1)+(x-1)*c]);for(let S=x+1;S<=i;S++)u[h+(S-1)+(b-1)*f]-=u[h+(x-1)+(b-1)*f]*a[l+(S-1)+(x-1)*c]}}else if(y)for(let b=1;b<=s;b++){if(o!==1)for(let x=1;x<=i;x++)u[h+(x-1)+(b-1)*f]=o*u[h+(x-1)+(b-1)*f];for(let x=1;x<=b-1;x++)if(a[l+(x-1)+(b-1)*c]!==0)for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]-=a[l+(x-1)+(b-1)*c]*u[h+(S-1)+(x-1)*f];if(m){const x=1/a[l+(b-1)+(b-1)*c];for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]=x*u[h+(S-1)+(b-1)*f]}}else for(let b=s;b>=1;b--){if(o!==1)for(let x=1;x<=i;x++)u[h+(x-1)+(b-1)*f]=o*u[h+(x-1)+(b-1)*f];for(let x=b+1;x<=s;x++)if(a[l+(x-1)+(b-1)*c]!==0)for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]-=a[l+(x-1)+(b-1)*c]*u[h+(S-1)+(x-1)*f];if(m){const x=1/a[l+(b-1)+(b-1)*c];for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]=x*u[h+(S-1)+(b-1)*f]}}}}function b2(e,t,n,r,i,s,o,a,l){let c,u,h,f;c=i,u=i,h=s,f=1;const d=Math.floor(e/32)*32;if(d!==0)for(let p=1;p<=d;p+=32){let m=c;for(let y=u;f>0?y<=h:y>=h;y+=f){const _=o[a+(m-1)];if(_!==y)for(let b=p;b<=p+31;b++){const x=t[n+(y-1)+(b-1)*r];t[n+(y-1)+(b-1)*r]=t[n+(_-1)+(b-1)*r],t[n+(_-1)+(b-1)*r]=x}m+=l}}if(d!==e){const p=d+1;let m=c;for(let y=u;f>0?y<=h:y>=h;y+=f){const _=o[a+(m-1)];if(_!==y)for(let b=p;b<=e;b++){const x=t[n+(y-1)+(b-1)*r];t[n+(y-1)+(b-1)*r]=t[n+(_-1)+(b-1)*r],t[n+(_-1)+(b-1)*r]=x}m+=l}}}function zn(e,t,n,r,i){if(!(e<=0||i<=0||t===1))if(i===1){const s=e%5;if(s!==0){for(let a=1;a<=s;a++)n[r+(a-1)]=t*n[r+(a-1)];if(e<5)return}const o=s+1;for(let a=o;a<=e;a+=5)n[r+(a-1)]=t*n[r+(a-1)],n[r+a]=t*n[r+a],n[r+(a+1)]=t*n[r+(a+1)],n[r+(a+2)]=t*n[r+(a+2)],n[r+(a+3)]=t*n[r+(a+3)]}else{const s=e*i;for(let o=1;o<=s;o+=i)n[r+(o-1)]=t*n[r+(o-1)]}}function tf(e,t,n,r){if(e<1||r<=0)return 0;if(e===1)return 1;let i=1;if(r===1){let s=Math.abs(t[n]);for(let o=2;o<=e;o++)Math.abs(t[n+(o-1)])>s&&(i=o,s=Math.abs(t[n+(o-1)]))}else{let s=0,o=Math.abs(t[n]);s+=r;for(let a=2;a<=e;a++)Math.abs(t[n+s])>o&&(i=a,o=Math.abs(t[n+s])),s+=r}return i}const oT=22250738585072014e-324;function ei(e){const t=Number.EPSILON*.5;if(e===N1)return t;if(e===Wo){const n=1/Number.MAX_VALUE;return n>=oT?n*(1+t):oT}else{if(e===x$)return 2;if(e===oh)return t*2;if(e===mue)return 53;if(e===gue)return 1;if(e===yue)return-1021;if(e===_ue)return oT;if(e===vue)return 1024;if(e===HL)return Number.MAX_VALUE}return 0}function x2(e,t,n,r,i,s,o){let a=0;if(e<0?a=-1:t<0?a=-2:i<Math.max(1,e)&&(a=-4),a!==0)return ts("DGETRF2",-a),a;if(e===0||t===0)return 0;if(e===1)s[o]=1,n[r]===0&&(a=1);else if(t===1){const l=ei(Wo),c=tf(e,n,r,1);if(s[o]=c,n[r+(c-1)]!==0){if(c!==1){const u=n[r];n[r]=n[r+(c-1)],n[r+(c-1)]=u}if(Math.abs(n[r])>=l)zn(e-1,1/n[r],n,r+1,1);else for(let u=1;u<=e-1;u++)n[r+u]=n[r+u]/n[r]}else a=1}else{const l=Math.floor(Math.min(e,t)/2),c=t-l;let u=x2(e,l,n,r,i,s,o);a===0&&u>0&&(a=u),b2(c,n,r+l*i,i,1,l,s,o,1),jM(Rr,Un,Lt,Ws,l,c,1,n,r,i,n,r+l*i,i),_r(Lt,Lt,e-l,c,l,-1,n,r+l,i,n,r+l*i,i,1,n,r+l+l*i,i),u=x2(e-l,c,n,r+l+l*i,i,s,o+l),a===0&&u>0&&(a=u+l);for(let h=l+1;h<=Math.min(e,t);h++)s[o+(h-1)]+=l;b2(l,n,r,i,l+1,Math.min(e,t),s,o,1)}return a}function Or(e,t,n,r,i,s,o){if(e===1)switch(t.toUpperCase().trim()){case"DGETRF":return 64;case"DGETRI":return 64;case"DTRTRI":return 64;case"DGEHRD":return 64;case"DORGHR":return 64;case"DGEBRD":return 64;case"DGESVD":return 64;case"DORGLQ":return 64;case"DORMLQ":return 64;case"DORGBR":return 64;case"DORMBR":return 64;case"DGELQF":return 64;default:return 1}return e===12?75:e===13?13:e===14||e===15?14:e===16?0:e===6?Math.max(Math.floor(5/3*Math.min(r,i)),1):1}function Gd(e,t,n,r,i){let a=0;if(e<0?a=-1:t<0?a=-2:r<Math.max(1,e)&&(a=-4),a!==0)return ts("DGETRF",-a),a;if(e===0||t===0)return 0;const l=Or(1,"DGETRF"," ",e,t);if(l<=1||l>=Math.min(e,t))return x2(e,t,n,0,r,i,0);const c=Math.min(e,t);for(let u=1;u<=c;u+=l){const h=Math.min(c-u+1,l),f=x2(e-u+1,h,n,0+(u-1)+(u-1)*r,r,i,0+(u-1));a===0&&f>0&&(a=f+u-1);for(let d=u;d<=Math.min(e,u+h-1);d++)i[0+(d-1)]=u-1+i[0+(d-1)];b2(u-1,n,0,r,u,u+h-1,i,0,1),u+h<=t&&(b2(t-u-h+1,n,0+(u+h-1)*r,r,u,u+h-1,i,0,1),jM(Rr,Un,Lt,Ws,h,t-u-h+1,1,n,0+(u-1)+(u-1)*r,r,n,0+(u-1)+(u+h-1)*r,r),u+h<=e&&_r(Lt,Lt,e-u-h+1,t-u-h+1,h,-1,n,0+(u+h-1)+(u-1)*r,r,n,0+(u-1)+(u+h-1)*r,r,1,n,0+(u+h-1)+(u+h-1)*r,r))}return a}function $L(e,t,n,r,i,s,o,a){const l=D(a||r);(i<=0||i>r)&&(i=r);let c=aT(n,e(l),r);t&&(c=t(c));let u=zg(c,r),h;t?h=zg(t(D(n)),r):h=zg(n,r),h===0&&(h=1);const f=[u];if(u/h<=s)return{x:l,flag:0,relres:u/h,iter:[0,0],resvec:D(f)};let d=1,p=0,m=0;for(let _=1;_<=o;_++){p=_;const b=D(r*(i+1));for(let R=0;R<r;R++)b[R]=c[R]/u;const x=D((i+1)*i),S=D(i),M=D(i),E=D(i+1);E[0]=u;let T=!1;for(let R=0;R<i;R++){m=R+1;let B=e(b.subarray(R*r,(R+1)*r));t&&(B=t(B));const F=i+1;for(let N=0;N<=R;N++){const H=N*r;let U=0;for(let G=0;G<r;G++)U+=B[G]*b[H+G];x[N+R*F]=U;for(let G=0;G<r;G++)B[G]-=U*b[H+G]}const L=zg(B,r);if(x[R+1+R*F]=L,L>1e-300){const N=(R+1)*r;for(let H=0;H<r;H++)b[N+H]=B[H]/L}for(let N=0;N<R;N++){const H=x[N+R*F],U=x[N+1+R*F];x[N+R*F]=S[N]*H+M[N]*U,x[N+1+R*F]=-M[N]*H+S[N]*U}const[j,V]=bue(x[R+R*F],x[R+1+R*F]);S[R]=j,M[R]=V,x[R+R*F]=j*x[R+R*F]+V*x[R+1+R*F],x[R+1+R*F]=0;const O=E[R];E[R]=j*O,E[R+1]=-V*O;const P=Math.abs(E[R+1]);if(f.push(P),P/h<=s){const N=YF(x,E,R+1,F);for(let H=0;H<r;H++)for(let U=0;U<=R;U++)l[H]+=b[H+U*r]*N[U];d=0,T=!0;break}}if(T)break;const k=YF(x,E,i,i+1);for(let R=0;R<r;R++)for(let B=0;B<i;B++)l[R]+=b[R+B*r]*k[B];if(c=aT(n,e(l),r),t&&(c=t(c)),u=zg(c,r),u/h<=s){d=0,m=0;break}}let y;if(d===0){let _=aT(n,e(l),r);t&&(_=t(_)),y=zg(_,r)/h}else y=u/h;return{x:l,flag:d,relres:y,iter:[p,m],resvec:D(f)}}function zg(e,t){let n=0;for(let r=0;r<t;r++)n+=e[r]*e[r];return Math.sqrt(n)}function aT(e,t,n){const r=D(n);for(let i=0;i<n;i++)r[i]=e[i]-t[i];return r}function bue(e,t){if(t===0)return[1,0];if(Math.abs(t)>Math.abs(e)){const i=e/t,s=1/Math.sqrt(1+i*i);return[s*i,s]}const n=t/e,r=1/Math.sqrt(1+n*n);return[r,r*n]}function YF(e,t,n,r){const i=D(n);for(let s=0;s<n;s++)i[s]=t[s];for(let s=n-1;s>=0;s--){for(let o=s+1;o<n;o++)i[s]-=e[s+o*r]*i[o];i[s]/=e[s+s*r]}return i}function dR(e,t,n,r,i,s,o,a){const l=D(a?a.re:r),c=D(a?a.im:r);(i<=0||i>r)&&(i=r);const u=e({re:l,im:c});let h=D(r),f=D(r);for(let S=0;S<r;S++)h[S]=n.re[S]-u.re[S],f[S]=n.im[S]-u.im[S];if(t){const S=t({re:h,im:f});h=D(S.re),f=D(S.im)}let d=Ug(h,f,r),p;if(t){const S=t({re:D(n.re),im:D(n.im)});p=Ug(S.re,S.im,r)}else p=Ug(n.re,n.im,r);p===0&&(p=1);const m=[d];if(d/p<=s)return{x:{re:l,im:c},flag:0,relres:d/p,iter:[0,0],resvec:D(m)};let y=1,_=0,b=0;for(let S=1;S<=o;S++){_=S;const M=D(r*(i+1)),E=D(r*(i+1));for(let U=0;U<r;U++)M[U]=h[U]/d,E[U]=f[U]/d;const T=i+1,k=D(T*i),R=D(T*i),B=D(i),F=D(i),L=D(i),j=D(i+1),V=D(i+1);j[0]=d;let O=!1;for(let U=0;U<i;U++){b=U+1;const G=U*r;let Z,ie;const Y=e({re:M.subarray(G,G+r),im:E.subarray(G,G+r)});if(Z=Y.re,ie=Y.im,t){const ke=t({re:Z,im:ie});Z=ke.re,ie=ke.im}Z.length!==r&&(Z=D(Z)),ie.length!==r&&(ie=D(ie));for(let ke=0;ke<=U;ke++){const _e=ke*r;let we=0,Le=0;for(let oe=0;oe<r;oe++)we+=M[_e+oe]*Z[oe]+E[_e+oe]*ie[oe],Le+=M[_e+oe]*ie[oe]-E[_e+oe]*Z[oe];k[ke+U*T]=we,R[ke+U*T]=Le;for(let oe=0;oe<r;oe++)Z[oe]-=we*M[_e+oe]-Le*E[_e+oe],ie[oe]-=we*E[_e+oe]+Le*M[_e+oe]}const ue=Ug(Z,ie,r);if(k[U+1+U*T]=ue,ue>1e-300){const ke=(U+1)*r;for(let _e=0;_e<r;_e++)M[ke+_e]=Z[_e]/ue,E[ke+_e]=ie[_e]/ue}for(let ke=0;ke<U;ke++){const _e=B[ke],we=F[ke],Le=L[ke],oe=k[ke+U*T],Q=R[ke+U*T],xe=k[ke+1+U*T],me=R[ke+1+U*T];k[ke+U*T]=_e*oe+(we*xe-Le*me),R[ke+U*T]=_e*Q+(we*me+Le*xe),k[ke+1+U*T]=-(we*oe+Le*Q)+_e*xe,R[ke+1+U*T]=-(-Le*oe+we*Q)+_e*me}const ge=k[U+U*T],te=R[U+U*T],X=k[U+1+U*T],de=R[U+1+U*T],{c:fe,sRe:ae,sIm:J,rRe:K,rIm:Se}=xue(ge,te,X,de);B[U]=fe,F[U]=ae,L[U]=J,k[U+U*T]=K,R[U+U*T]=Se,k[U+1+U*T]=0,R[U+1+U*T]=0;const ye=j[U],Ge=V[U],Fe=j[U+1],Ue=V[U+1];j[U]=fe*ye+(ae*Fe-J*Ue),V[U]=fe*Ge+(ae*Ue+J*Fe),j[U+1]=-(ae*ye+J*Ge)+fe*Fe,V[U+1]=-(-J*ye+ae*Ge)+fe*Ue;const Ee=Math.sqrt(j[U+1]*j[U+1]+V[U+1]*V[U+1]);if(m.push(Ee),Ee/p<=s){const{yRe:ke,yIm:_e}=KF(k,R,j,V,U+1,T);for(let we=0;we<r;we++)for(let Le=0;Le<=U;Le++)l[we]+=M[we+Le*r]*ke[Le]-E[we+Le*r]*_e[Le],c[we]+=M[we+Le*r]*_e[Le]+E[we+Le*r]*ke[Le];y=0,O=!0;break}}if(O)break;const{yRe:P,yIm:N}=KF(k,R,j,V,i,T);for(let U=0;U<r;U++)for(let G=0;G<i;G++)l[U]+=M[U+G*r]*P[G]-E[U+G*r]*N[G],c[U]+=M[U+G*r]*N[G]+E[U+G*r]*P[G];const H=e({re:l,im:c});h=D(r),f=D(r);for(let U=0;U<r;U++)h[U]=n.re[U]-H.re[U],f[U]=n.im[U]-H.im[U];if(t){const U=t({re:h,im:f});h=D(U.re),f=D(U.im)}if(d=Ug(h,f,r),d/p<=s){y=0,b=0;break}}let x;if(y===0){const S=e({re:l,im:c});let M=D(r),E=D(r);for(let T=0;T<r;T++)M[T]=n.re[T]-S.re[T],E[T]=n.im[T]-S.im[T];if(t){const T=t({re:M,im:E});M=D(T.re),E=D(T.im)}x=Ug(M,E,r)/p}else x=d/p;return{x:{re:l,im:c},flag:y,relres:x,iter:[_,b],resvec:D(m)}}function Ug(e,t,n){let r=0;for(let i=0;i<n;i++)r+=e[i]*e[i]+t[i]*t[i];return Math.sqrt(r)}function xue(e,t,n,r){const i=Math.sqrt(n*n+r*r);if(i===0)return{c:1,sRe:0,sIm:0,rRe:e,rIm:t};const s=Math.sqrt(e*e+t*t);if(s===0)return{c:0,sRe:n/i,sIm:-r/i,rRe:i,rIm:0};const o=Math.sqrt(s*s+i*i),a=s/o,l=e/s,c=t/s,u=(l*n+c*r)/o,h=(c*n-l*r)/o;return{c:a,sRe:u,sIm:h,rRe:l*o,rIm:c*o}}function KF(e,t,n,r,i,s){const o=D(i),a=D(i);for(let l=0;l<i;l++)o[l]=n[l],a[l]=r[l];for(let l=i-1;l>=0;l--){for(let p=l+1;p<i;p++){const m=e[l+p*s],y=t[l+p*s];o[l]-=m*o[p]-y*a[p],a[l]-=m*a[p]+y*o[p]}const c=e[l+l*s],u=t[l+l*s],h=c*c+u*u,f=o[l],d=a[l];o[l]=(f*c+d*u)/h,a[l]=(d*c-f*u)/h}return{yRe:o,yIm:a}}function pR(e,t,n,r,i,s){for(let o=0;o<e;o++){const a=r[o]-1;if(a!==o){let l=i[o];i[o]=i[a],i[a]=l,l=s[o],s[o]=s[a],s[a]=l}}for(let o=1;o<e;o++)for(let a=0;a<o;a++){const l=t[o+a*e],c=n[o+a*e];i[o]-=l*i[a]-c*s[a],s[o]-=l*s[a]+c*i[a]}for(let o=e-1;o>=0;o--){for(let f=o+1;f<e;f++){const d=t[o+f*e],p=n[o+f*e];i[o]-=d*i[f]-p*s[f],s[o]-=d*s[f]+p*i[f]}const a=t[o+o*e],l=n[o+o*e],c=a*a+l*l,u=i[o],h=s[o];i[o]=(u*a+h*l)/c,s[o]=(h*a-u*l)/c}}function Rv(e,t,n,r){for(let i=0;i<e;i++){const s=n[i]-1;if(s!==i){const o=r[i];r[i]=r[s],r[s]=o}}for(let i=1;i<e;i++)for(let s=0;s<i;s++)r[i]-=t[i+s*e]*r[s];for(let i=e-1;i>=0;i--){for(let s=i+1;s<e;s++)r[i]-=t[i+s*e]*r[s];r[i]/=t[i+i*e]}}function Yn(e,t,n,r,i,s,o,a,l,c,u,h,f,d){const p=e===Lt;let m=0;if(!p&&e!==Kn&&e!==kv?m=1:t<0?m=2:n<0?m=3:o<Math.max(1,t)?m=6:c===0?m=8:d===0&&(m=11),m!==0){ts("DGEMV ",m);return}if(t===0||n===0||r===0&&u===1)return;const y=p?n:t,_=p?t:n,b=c>0?0:(y-1)*-c,x=d>0?0:(_-1)*-d;if(u!==1)if(u===0)if(d===1)h.fill(0,f,f+_);else{let S=x;for(let M=0;M<_;M++)h[f+S]=0,S+=d}else if(d===1){const S=f+_;for(let M=f;M<S;M++)h[M]*=u}else{let S=x;for(let M=0;M<_;M++)h[f+S]*=u,S+=d}if(r!==0)if(p)if(c===1&&d===1)for(let S=0;S<n;S++){const M=r*a[l+S],E=s+S*o;for(let T=0;T<t;T++)h[f+T]+=M*i[E+T]}else if(d===1){let S=b;for(let M=0;M<n;M++){const E=r*a[l+S],T=s+M*o;for(let k=0;k<t;k++)h[f+k]+=E*i[T+k];S+=c}}else{let S=b;for(let M=0;M<n;M++){const E=r*a[l+S],T=s+M*o;let k=x;for(let R=0;R<t;R++)h[f+k]+=E*i[T+R],k+=d;S+=c}}else if(c===1&&d===1)for(let S=0;S<n;S++){let M=0;const E=s+S*o;for(let T=0;T<t;T++)M+=i[E+T]*a[l+T];h[f+S]+=r*M}else if(c===1){let S=x;for(let M=0;M<n;M++){let E=0;const T=s+M*o;for(let k=0;k<t;k++)E+=i[T+k]*a[l+k];h[f+S]+=r*E,S+=d}}else{let S=x;for(let M=0;M<n;M++){let E=0;const T=s+M*o;let k=b;for(let R=0;R<t;R++)E+=i[T+R]*a[l+k],k+=c;h[f+S]+=r*E,S+=d}}}function nf(e,t,n,r,i,s,o){if(!(e<=0))if(r===1&&o===1){const a=e%3;if(a!==0){for(let c=1;c<=a;c++){const u=t[n+(c-1)];t[n+(c-1)]=i[s+(c-1)],i[s+(c-1)]=u}if(e<3)return}const l=a+1;for(let c=l;c<=e;c+=3){let u=t[n+(c-1)];t[n+(c-1)]=i[s+(c-1)],i[s+(c-1)]=u,u=t[n+c],t[n+c]=i[s+c],i[s+c]=u,u=t[n+(c+1)],t[n+(c+1)]=i[s+(c+1)],i[s+(c+1)]=u}}else{let a=r>=0?1:(-e+1)*r+1,l=o>=0?1:(-e+1)*o+1;for(let c=1;c<=e;c++){const u=t[n+(a-1)];t[n+(a-1)]=i[s+(l-1)],i[s+(l-1)]=u,a+=r,l+=o}}}function us(e,t,n,r,i,s,o,a,l,c,u,h,f){const d=e===Rr,p=d?i:s,m=r===qs,y=t===cn;let _=0;if(e!==Rr&&e!==Pn?_=1:t!==cn&&t!==Un?_=2:n!==Lt&&n!==Kn&&n!==kv?_=3:r!==Ws&&r!==qs?_=4:i<0?_=5:s<0?_=6:c<Math.max(1,p)?_=9:f<Math.max(1,i)&&(_=11),_!==0){ts("DTRMM ",_);return}if(!(i===0||s===0)){if(o===0){for(let b=1;b<=s;b++)for(let x=1;x<=i;x++)u[h+(x-1)+(b-1)*f]=0;return}if(d)if(n===Lt){if(y){for(let b=1;b<=s;b++)for(let x=1;x<=i;x++)if(u[h+(x-1)+(b-1)*f]!==0){const S=o*u[h+(x-1)+(b-1)*f];for(let M=1;M<=x-1;M++)u[h+(M-1)+(b-1)*f]+=S*a[l+(M-1)+(x-1)*c];u[h+(x-1)+(b-1)*f]=m?S*a[l+(x-1)+(x-1)*c]:S}}else for(let b=1;b<=s;b++)for(let x=i;x>=1;x--)if(u[h+(x-1)+(b-1)*f]!==0){const S=o*u[h+(x-1)+(b-1)*f];u[h+(x-1)+(b-1)*f]=S,m&&(u[h+(x-1)+(b-1)*f]*=a[l+(x-1)+(x-1)*c]);for(let M=x+1;M<=i;M++)u[h+(M-1)+(b-1)*f]+=S*a[l+(M-1)+(x-1)*c]}}else if(y)for(let b=1;b<=s;b++)for(let x=i;x>=1;x--){let S=u[h+(x-1)+(b-1)*f];m&&(S*=a[l+(x-1)+(x-1)*c]);for(let M=1;M<=x-1;M++)S+=a[l+(M-1)+(x-1)*c]*u[h+(M-1)+(b-1)*f];u[h+(x-1)+(b-1)*f]=o*S}else for(let b=1;b<=s;b++)for(let x=1;x<=i;x++){let S=u[h+(x-1)+(b-1)*f];m&&(S*=a[l+(x-1)+(x-1)*c]);for(let M=x+1;M<=i;M++)S+=a[l+(M-1)+(x-1)*c]*u[h+(M-1)+(b-1)*f];u[h+(x-1)+(b-1)*f]=o*S}else if(n===Lt)if(y)for(let b=s;b>=1;b--){let x=o;m&&(x*=a[l+(b-1)+(b-1)*c]);for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]=x*u[h+(S-1)+(b-1)*f];for(let S=1;S<=b-1;S++)if(a[l+(S-1)+(b-1)*c]!==0){x=o*a[l+(S-1)+(b-1)*c];for(let M=1;M<=i;M++)u[h+(M-1)+(b-1)*f]+=x*u[h+(M-1)+(S-1)*f]}}else for(let b=1;b<=s;b++){let x=o;m&&(x*=a[l+(b-1)+(b-1)*c]);for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]=x*u[h+(S-1)+(b-1)*f];for(let S=b+1;S<=s;S++)if(a[l+(S-1)+(b-1)*c]!==0){x=o*a[l+(S-1)+(b-1)*c];for(let M=1;M<=i;M++)u[h+(M-1)+(b-1)*f]+=x*u[h+(M-1)+(S-1)*f]}}else if(y)for(let b=1;b<=s;b++){for(let S=1;S<=b-1;S++)if(a[l+(S-1)+(b-1)*c]!==0){const M=o*a[l+(S-1)+(b-1)*c];for(let E=1;E<=i;E++)u[h+(E-1)+(S-1)*f]+=M*u[h+(E-1)+(b-1)*f]}let x=o;if(m&&(x*=a[l+(b-1)+(b-1)*c]),x!==1)for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]=x*u[h+(S-1)+(b-1)*f]}else for(let b=s;b>=1;b--){for(let S=b+1;S<=s;S++)if(a[l+(S-1)+(b-1)*c]!==0){const M=o*a[l+(S-1)+(b-1)*c];for(let E=1;E<=i;E++)u[h+(E-1)+(S-1)*f]+=M*u[h+(E-1)+(b-1)*f]}let x=o;if(m&&(x*=a[l+(b-1)+(b-1)*c]),x!==1)for(let S=1;S<=i;S++)u[h+(S-1)+(b-1)*f]=x*u[h+(S-1)+(b-1)*f]}}}function A0(e,t,n,r,i,s,o,a,l,c){let u=0;if(e!==cn&&e!==Un?u=1:t!==Lt&&t!==Kn&&t!==kv?u=2:n!==Ws&&n!==qs?u=3:r<0?u=4:o<Math.max(1,r)&&(u=6),u!==0){ts("DTRMV ",u);return}if(r===0)return;const h=n===qs;if(t===Lt){if(e===cn){for(let f=1;f<=r;f++)if(a[l+(f-1)]!==0){const d=a[l+(f-1)];for(let p=1;p<=f-1;p++)a[l+(p-1)]+=d*i[s+(p-1)+(f-1)*o];h&&(a[l+(f-1)]*=i[s+(f-1)+(f-1)*o])}}else for(let f=r;f>=1;f--)if(a[l+(f-1)]!==0){const d=a[l+(f-1)];for(let p=r;p>=f+1;p--)a[l+(p-1)]+=d*i[s+(p-1)+(f-1)*o];h&&(a[l+(f-1)]*=i[s+(f-1)+(f-1)*o])}}else if(e===cn)for(let f=r;f>=1;f--){let d=a[l+(f-1)];h&&(d*=i[s+(f-1)+(f-1)*o]);for(let p=f-1;p>=1;p--)d+=i[s+(p-1)+(f-1)*o]*a[l+(p-1)];a[l+(f-1)]=d}else for(let f=1;f<=r;f++){let d=a[l+(f-1)];h&&(d*=i[s+(f-1)+(f-1)*o]);for(let p=f+1;p<=r;p++)d+=i[s+(p-1)+(f-1)*o]*a[l+(p-1)];a[l+(f-1)]=d}}function ZF(e,t,n,r,i,s){let o=0;if(n<0?o=-3:s<Math.max(1,n)&&(o=-5),o!==0)return ts("DTRTI2",-o),o;for(let a=1;a<=n;a++){let l;r[i+(a-1)+(a-1)*s]=1/r[i+(a-1)+(a-1)*s],l=-r[i+(a-1)+(a-1)*s],a-1>=1&&(A0(cn,Lt,t,a-1,r,i,s,r,i+(a-1)*s),zn(a-1,l,r,i+(a-1)*s,1))}return 0}function wue(e,t,n,r,i,s){let o=0;if(n<0?o=-3:s<Math.max(1,n)&&(o=-5),o!==0)return ts("DTRTRI",-o),o;if(n===0)return 0;for(let l=1;l<=n;l++)if(r[i+(l-1)+(l-1)*s]===0)return l;const a=Or(1,"DTRTRI"," ",n,-1);if(a<=1||a>=n)return ZF(e,t,n,r,i,s);for(let l=1;l<=n;l+=a){const c=Math.min(a,n-l+1);l-1>=1&&(us(Rr,cn,Lt,t,l-1,c,1,r,i,s,r,i+(l-1)*s,s),jM(Pn,cn,Lt,t,l-1,c,-1,r,i+(l-1)+(l-1)*s,s,r,i+(l-1)*s,s));const u=ZF(cn,t,c,r,i+(l-1)+(l-1)*s,s);o===0&&u!==0&&(o=u)}return o}function Sue(e,t,n,r){const o=Or(1,"DGETRI"," ",e,-1),a=Math.max(1,e*o);let l=0;if(e<0?l=-1:n<Math.max(1,e)&&(l=-3),l!==0)return ts("DGETRI",-l),l;if(e===0)return 0;if(l=wue(cn,qs,e,t,0,n),l>0)return l;const c=a,u=D(c),h=e;let f=o,d=2,p;if(f>1&&f<e?(p=Math.max(h*f,1),c<p&&(f=Math.floor(c/h),d=Math.max(2,Or(2,"DGETRI"," ",e,-1)))):p=e,f<d||f>=e)for(let m=e;m>=1;m--){for(let y=m+1;y<=e;y++)u[y-1]=t[0+(y-1)+(m-1)*n],t[0+(y-1)+(m-1)*n]=0;m<e&&Yn(Lt,e,e-m,-1,t,0+m*n,n,u,m,1,1,t,0+(m-1)*n,1)}else{const m=Math.floor((e-1)/f)*f+1;for(let y=m;y>=1;y-=f){const _=Math.min(f,e-y+1);for(let b=y;b<=y+_-1;b++)for(let x=b+1;x<=e;x++)u[x-1+(b-y)*h]=t[0+(x-1)+(b-1)*n],t[0+(x-1)+(b-1)*n]=0;y+_<=e&&_r(Lt,Lt,e,_,e-y-_+1,-1,t,0+(y+_-1)*n,n,u,y+_-1,h,1,t,0+(y-1)*n,n),jM(Pn,Un,Lt,Ws,e,_,1,u,y-1,h,t,0+(y-1)*n,n)}}for(let m=e-1;m>=1;m--){const y=r[0+(m-1)];y!==m&&nf(e,t,0+(m-1)*n,1,t,0+(y-1)*n,1)}return 0}function Eu(e,t,n,r){if(e<=0||r<=0)return 0;if(e===1)return Math.abs(t[n]);let i=0,s=1;for(let o=0;o<e;o++){const a=Math.abs(t[n+o*r]);a>0&&(i<a?(s=1+s*(i/a)*(i/a),i=a):s+=a/i*(a/i))}return i*Math.sqrt(s)}const Mue=0,Eue=1,Cue=2,Oa=2,Aue=.95;function Tue(e,t,n,r,i,s,o){let a=0,l=1,c=t;if(e<0||e>3)return a=-1,{ilo:l,ihi:c,info:a};if(t<0)return a=-2,{ilo:l,ihi:c,info:a};if(i<Math.max(1,t))return a=-4,{ilo:l,ihi:c,info:a};if(t===0)return l=1,c=0,{ilo:l,ihi:c,info:a};if(e===Mue){for(let _=1;_<=t;_++)s[o+(_-1)]=1;return l=1,c=t,{ilo:l,ihi:c,info:a}}let u=1,h=t;if(e!==Cue){let _=!0;for(;_;){_=!1;for(let b=h;b>=1;b--){let x=!0;for(let S=1;S<=h;S++)if(b!==S&&n[r+(b-1)+(S-1)*i]!==0){x=!1;break}if(x){if(s[o+(h-1)]=b,b!==h&&(nf(h,n,r+(b-1)*i,1,n,r+(h-1)*i,1),nf(t-u+1,n,r+(b-1)+(u-1)*i,i,n,r+(h-1)+(u-1)*i,i)),_=!0,h===1)return l=1,c=1,{ilo:l,ihi:c,info:a};h=h-1}}}for(_=!0;_;){_=!1;for(let b=u;b<=h;b++){let x=!0;for(let S=u;S<=h;S++)if(S!==b&&n[r+(S-1)+(b-1)*i]!==0){x=!1;break}x&&(s[o+(u-1)]=b,b!==u&&(nf(h,n,r+(b-1)*i,1,n,r+(u-1)*i,1),nf(t-u+1,n,r+(b-1)+(u-1)*i,i,n,r+(u-1)+(u-1)*i,i)),_=!0,u=u+1)}}}for(let _=u;_<=h;_++)s[o+(_-1)]=1;if(e===Eue)return l=u,c=h,{ilo:l,ihi:c,info:a};const f=ei(Wo)/ei(oh),d=1/f,p=f*Oa,m=1/p;let y=!0;for(;y;){y=!1;for(let _=u;_<=h;_++){let b=Eu(h-u+1,n,r+(u-1)+(_-1)*i,1),x=Eu(h-u+1,n,r+(_-1)+(u-1)*i,i);const S=tf(h,n,r+(_-1)*i,1);let M=Math.abs(n[r+(S-1)+(_-1)*i]);const E=tf(t-u+1,n,r+(_-1)+(u-1)*i,i);let T=Math.abs(n[r+(_-1)+(E+u-2)*i]);if(b===0||x===0)continue;if(isNaN(b+M+x+T))return a=-3,{ilo:l,ihi:c,info:a};let k=x/Oa,R=1;const B=b+x;for(;b<k&&Math.max(R,b,M)<m&&Math.min(x,k,T)>p;)R=R*Oa,b=b*Oa,M=M*Oa,x=x/Oa,k=k/Oa,T=T/Oa;for(k=b/Oa;k>=x&&Math.max(x,T)<m&&Math.min(R,b,k,M)>p;)R=R/Oa,b=b/Oa,k=k/Oa,M=M/Oa,x=x*Oa,T=T*Oa;b+x>=Aue*B||R<1&&s[o+(_-1)]<1&&R*s[o+(_-1)]<=f||R>1&&s[o+(_-1)]>1&&s[o+(_-1)]>=d/R||(k=1/R,s[o+(_-1)]=s[o+(_-1)]*R,y=!0,zn(t-u+1,k,n,r+(_-1)+(u-1)*i,i),zn(h,R,n,r+(_-1)*i,1))}}return l=u,c=h,{ilo:l,ihi:c,info:a}}function r1(e,t){const n=Number.isNaN(e),r=Number.isNaN(t);if(n)return e;if(r)return t;const i=ei(HL),s=Math.abs(e),o=Math.abs(t),a=Math.max(s,o),l=Math.min(s,o);return l===0||a>i?a:a*Math.sqrt(1+l/a*(l/a))}function Rs(e,t,n,r,i){if(e<=1)return{alpha:t,tau:0};let s=Eu(e-1,n,r,i);if(s===0)return{alpha:t,tau:0};let o=-(Math.sign(t)||1)*r1(t,s);const a=ei(Wo)/ei(N1);let l=0;if(Math.abs(o)<a){const u=1/a;do l++,zn(e-1,u,n,r,i),o*=u,t*=u;while(Math.abs(o)<a&&l<20);s=Eu(e-1,n,r,i),o=-(Math.sign(t)||1)*r1(t,s)}const c=(o-t)/o;zn(e-1,1/(t-o),n,r,i);for(let u=1;u<=l;u++)o*=a;return t=o,{alpha:t,tau:c}}function kue(e,t,n,r,i){if(e===0)return e;if(n[r+(e-1)]!==0||n[r+(e-1)+(t-1)*i]!==0)return e;let s=0;for(let o=1;o<=t;o++){let a=e;for(;a>=1&&n[r+(Math.max(a,1)-1)+(o-1)*i]===0;)a--;s=Math.max(s,a)}return s}function Rue(e,t,n,r,i){if(t===0)return t;if(n[r+(t-1)*i]!==0||n[r+(e-1)+(t-1)*i]!==0)return t;for(let s=t;s>=1;s--)for(let o=1;o<=e;o++)if(n[r+(o-1)+(s-1)*i]!==0)return s;return 0}function w2(e,t,n,r,i,s,o,a,l,c,u,h){let f=0;if(e<0?f=1:t<0?f=2:s===0?f=5:l===0?f=7:h<Math.max(1,e)&&(f=9),f!==0){ts("DGER ",f);return}if(e===0||t===0||n===0)return;const d=s>0?0:(e-1)*-s,p=l>0?0:(t-1)*-l;if(s===1&&l===1)for(let m=0;m<t;m++){const y=o[a+m];if(y!==0){const _=n*y,b=u+m*h;for(let x=0;x<e;x++)c[b+x]+=r[i+x]*_}}else if(s===1){let m=p;for(let y=0;y<t;y++){const _=o[a+m];if(_!==0){const b=n*_,x=u+y*h;for(let S=0;S<e;S++)c[x+S]+=r[i+S]*b}m+=l}}else{let m=p;for(let y=0;y<t;y++){const _=o[a+m];if(_!==0){const b=n*_,x=u+y*h;let S=d;for(let M=0;M<e;M++)c[x+M]+=r[i+S]*b,S+=s}m+=l}}}function Wa(e,t,n,r,i,s,o,a){if(!(e<=0)&&t!==0)if(i===1&&a===1){const l=e%4;if(l!==0)for(let u=1;u<=l;u++)s[o+(u-1)]+=t*n[r+(u-1)];if(e<4)return;const c=l+1;for(let u=c;u<=e;u+=4)s[o+(u-1)]+=t*n[r+(u-1)],s[o+u]+=t*n[r+u],s[o+(u+1)]+=t*n[r+(u+1)],s[o+(u+2)]+=t*n[r+(u+2)]}else{let l=1,c=1;i<0&&(l=(-e+1)*i+1),a<0&&(c=(-e+1)*a+1);for(let u=1;u<=e;u++)s[o+(c-1)]+=t*n[r+(l-1)],l+=i,c+=a}}function ul(e,t,n,r,i,s,o,a,l,c,u,h){const f=e===Rr;let d=1,p=0;if(o!==0){f?d=t:d=n;let m;for(s>0?m=1+(d-1)*s:m=1;d>1&&r[i+(m-1)]===0;)d--,m-=s;f?p=Rue(d,n,a,l,c):p=kue(t,d,a,l,c)}p!==0&&(f?d===1?zn(p,1-o,a,l,c):(Yn(Kn,d-1,p,1,a,l+1,c,r,i+s,s,0,u,h,1),Wa(p,1,a,l,c,u,h,1),Wa(p,-o,u,h,1,a,l,c),w2(d-1,p,-o,r,i+s,s,u,h,1,a,l+1,c)):d===1?zn(p,1-o,a,l,1):(Yn(Lt,p,d-1,1,a,l+c,c,r,i+s,s,0,u,h,1),Wa(p,1,a,l,1,u,h,1),Wa(p,-o,u,h,1,a,l,1),w2(p,d-1,-o,u,h,1,r,i+s,s,a,l+c,c)))}function Due(e,t,n,r,i,s,o,a,l,c){let u=0;if(e<0?u=-1:t<1||t>Math.max(1,e)?u=-2:n<Math.min(t,e)||n>e?u=-3:s<Math.max(1,e)&&(u=-5),u!==0)return u;for(let h=t;h<=n-1;h++){const f=i+h+(h-1)*s,d=i+(Math.min(h+2,e)-1)+(h-1)*s,p=Rs(n-h,r[f],r,d,1);r[f]=p.alpha,o[a+(h-1)]=p.tau,ul(Pn,n,n-h,r,i+h+(h-1)*s,1,o[a+(h-1)],r,i+h*s,s,l,c),ul(Rr,n-h,e-h,r,i+h+(h-1)*s,1,o[a+(h-1)],r,i+h+h*s,s,l,c)}return 0}function rf(e,t,n,r,i,s,o){if(!(e<=0))if(r===1&&o===1){const a=e%7;if(a!==0){for(let c=1;c<=a;c++)i[s+(c-1)]=t[n+(c-1)];if(e<7)return}const l=a+1;for(let c=l;c<=e;c+=7)i[s+(c-1)]=t[n+(c-1)],i[s+c]=t[n+c],i[s+(c+1)]=t[n+(c+1)],i[s+(c+2)]=t[n+(c+2)],i[s+(c+3)]=t[n+(c+3)],i[s+(c+4)]=t[n+(c+4)],i[s+(c+5)]=t[n+(c+5)]}else{let a=1,l=1;r<0&&(a=(-e+1)*r+1),o<0&&(l=(-e+1)*o+1);for(let c=1;c<=e;c++)i[s+(l-1)]=t[n+(a-1)],a+=r,l+=o}}function xn(e,t,n,r,i,s,o,a,l){if(e===cn)for(let c=1;c<=n;c++)for(let u=1;u<=Math.min(c,t);u++)o[a+(u-1)+(c-1)*l]=r[i+(u-1)+(c-1)*s];else if(e===Un)for(let c=1;c<=n;c++)for(let u=c;u<=t;u++)o[a+(u-1)+(c-1)*l]=r[i+(u-1)+(c-1)*s];else for(let c=1;c<=n;c++)for(let u=1;u<=t;u++)o[a+(u-1)+(c-1)*l]=r[i+(u-1)+(c-1)*s]}const QF=0,ba=1;function Nue(e,t,n,r,i,s,o,a,l,c,u,h,f,d){if(e<=1)return;let p=0;for(let m=1;m<=n;m++){m>1&&(Yn(Lt,e-t,m-1,-ba,h,f+t+0*d,d,r,i+(t+m-2)+0*s,s,ba,r,i+t+(m-1)*s,1),rf(m-1,r,i+t+(m-1)*s,1,l,c+(n-1)*u,1),A0(Un,Kn,Ws,m-1,r,i+t+0*s,s,l,c+(n-1)*u),Yn(Kn,e-t-m+1,m-1,ba,r,i+(t+m-1)+0*s,s,r,i+(t+m-1)+(m-1)*s,1,ba,l,c+(n-1)*u,1),A0(cn,Kn,qs,m-1,l,c,u,l,c+(n-1)*u),Yn(Lt,e-t-m+1,m-1,-ba,r,i+(t+m-1)+0*s,s,l,c+(n-1)*u,1,ba,r,i+(t+m-1)+(m-1)*s,1),A0(Un,Lt,Ws,m-1,r,i+t+0*s,s,l,c+(n-1)*u),Wa(m-1,-ba,l,c+(n-1)*u,1,r,i+t+(m-1)*s,1),r[i+(t+m-2)+(m-2)*s]=p);const y=i+(t+m-1)+(m-1)*s,_=i+(Math.min(t+m+1,e)-1)+(m-1)*s,b=Rs(e-t-m+1,r[y],r,_,1);r[y]=b.alpha,o[a+(m-1)]=b.tau,p=r[y],r[y]=ba,Yn(Lt,e-t,e-t-m+1,ba,r,i+t+m*s,s,r,i+(t+m-1)+(m-1)*s,1,QF,h,f+t+(m-1)*d,1),Yn(Kn,e-t-m+1,m-1,ba,r,i+(t+m-1)+0*s,s,r,i+(t+m-1)+(m-1)*s,1,QF,l,c+(m-1)*u,1),Yn(Lt,e-t,m-1,-ba,h,f+t+0*d,d,l,c+(m-1)*u,1,ba,h,f+t+(m-1)*d,1),zn(e-t,o[a+(m-1)],h,f+t+(m-1)*d,1),zn(m-1,-o[a+(m-1)],l,c+(m-1)*u,1),A0(cn,Lt,qs,m-1,l,c,u,l,c+(m-1)*u),l[c+(m-1)+(m-1)*u]=o[a+(m-1)]}r[i+(t+n-1)+(n-1)*s]=p,xn(-1,t,n,r,i+1*s,s,h,f,d),us(Pn,Un,Lt,Ws,t,n,ba,r,i+t+0*s,s,h,f,d),e>t+n&&_r(Lt,Lt,t,n,e-t-n,ba,r,i+(1+n)*s,s,r,i+(t+n)+0*s,s,ba,h,f,d),us(Pn,cn,Lt,qs,t,n,ba,l,c,u,h,f,d)}const Lue=0;function HM(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b){if(i<=0||s<=0)return;const x=t===Lt?Kn:Lt;if(r===Lue)if(e===Rr){for(let S=1;S<=o;S++)rf(s,d,p+(S-1),m,y,_+(S-1)*b,1);us(Pn,Un,Lt,Ws,s,o,1,a,l,c,y,_,b),i>o&&_r(Kn,Lt,s,o,i-o,1,d,p+o,m,a,l+o,c,1,y,_,b),us(Pn,cn,x,qs,s,o,1,u,h,f,y,_,b),i>o&&_r(Lt,Kn,i-o,s,o,-1,a,l+o,c,y,_,b,1,d,p+o,m),us(Pn,Un,Kn,Ws,s,o,1,a,l,c,y,_,b);for(let S=1;S<=o;S++)for(let M=1;M<=s;M++)d[p+(S-1)+(M-1)*m]-=y[_+(M-1)+(S-1)*b]}else{for(let S=1;S<=o;S++)rf(i,d,p+(S-1)*m,1,y,_+(S-1)*b,1);us(Pn,Un,Lt,Ws,i,o,1,a,l,c,y,_,b),s>o&&_r(Lt,Lt,i,o,s-o,1,d,p+o*m,m,a,l+o,c,1,y,_,b),us(Pn,cn,t,qs,i,o,1,u,h,f,y,_,b),s>o&&_r(Lt,Kn,i,s-o,o,-1,y,_,b,a,l+o,c,1,d,p+o*m,m),us(Pn,Un,Kn,Ws,i,o,1,a,l,c,y,_,b);for(let S=1;S<=o;S++)for(let M=1;M<=i;M++)d[p+(M-1)+(S-1)*m]-=y[_+(M-1)+(S-1)*b]}else if(e===Rr){for(let S=1;S<=o;S++)rf(s,d,p+(S-1),m,y,_+(S-1)*b,1);us(Pn,cn,Kn,Ws,s,o,1,a,l,c,y,_,b),i>o&&_r(Kn,Kn,s,o,i-o,1,d,p+o,m,a,l+o*c,c,1,y,_,b),us(Pn,cn,x,qs,s,o,1,u,h,f,y,_,b),i>o&&_r(Kn,Kn,i-o,s,o,-1,a,l+o*c,c,y,_,b,1,d,p+o,m),us(Pn,cn,Lt,Ws,s,o,1,a,l,c,y,_,b);for(let S=1;S<=o;S++)for(let M=1;M<=s;M++)d[p+(S-1)+(M-1)*m]-=y[_+(M-1)+(S-1)*b]}else{for(let S=1;S<=o;S++)rf(i,d,p+(S-1)*m,1,y,_+(S-1)*b,1);us(Pn,cn,Kn,Ws,i,o,1,a,l,c,y,_,b),s>o&&_r(Lt,Kn,i,o,s-o,1,d,p+o*m,m,a,l+o*c,c,1,y,_,b),us(Pn,cn,t,qs,i,o,1,u,h,f,y,_,b),s>o&&_r(Lt,Lt,i,s-o,o,-1,y,_,b,a,l+o*c,c,1,d,p+o*m,m),us(Pn,cn,Lt,Ws,i,o,1,a,l,c,y,_,b);for(let S=1;S<=o;S++)for(let M=1;M<=i;M++)d[p+(M-1)+(S-1)*m]-=y[_+(M-1)+(S-1)*b]}}const JF=0,e_=1,S2=64,mR=S2+1,lT=mR*S2,Iue=0,Pue=0;function gR(e,t,n,r,i,s,o,a,l,c,u){let h=0;const f=u===-1;e<0?h=-1:t<1||t>Math.max(1,e)?h=-2:n<Math.min(t,e)||n>e?h=-3:s<Math.max(1,e)?h=-5:u<Math.max(1,e)&&!f&&(h=-8);const d=n-t+1;let p;if(h===0){if(d<=1)p=1;else{const S=Math.min(S2,Or(1,"DGEHRD"," ",e,t));p=e*S+lT}l[c]=p}else p=1;if(h!==0)return h;if(f)return 0;for(let S=1;S<=t-1;S++)o[a+(S-1)]=JF;for(let S=Math.max(1,n);S<=e-1;S++)o[a+(S-1)]=JF;if(d<=1)return l[c]=1,0;let m=Math.min(S2,Or(1,"DGEHRD"," ",e,t)),y=2,_=0,b=t;m>1&&m<d&&(_=Math.max(m,Or(3,"DGEHRD"," ",e,t)),_<d&&u<p&&(y=Math.max(2,Or(2,"DGEHRD"," ",e,t)),u>=e*y+lT?m=Math.floor((u-lT)/e):m=1));const x=e;if(m<y||m>=d)b=t;else{const S=1+e*m;for(b=t;b<=n-1-_;b+=m){const M=Math.min(m,n-b);Nue(n,b,M,r,i+(b-1)*s,s,o,a+(b-1),l,c+(S-1),mR,l,c,x);const E=i+(b+M-1)+(b+M-2)*s,T=r[E];r[E]=e_,_r(Lt,Kn,n,n-b-M+1,M,-e_,l,c,x,r,i+(b+M-1)+(b-1)*s,s,e_,r,i+(b+M-1)*s,s),r[E]=T,us(Pn,Un,Kn,Ws,b,M-1,e_,r,i+b+(b-1)*s,s,l,c,x);for(let k=0;k<=M-2;k++)Wa(b,-e_,l,c+x*k,1,r,i+(b+k)*s,1);HM(Rr,Kn,Iue,Pue,n-b,e-b-M+1,M,r,i+b+(b-1)*s,s,l,c+(S-1),mR,r,i+b+(b+M-1)*s,s,l,c,x)}}return Due(e,b,n,r,i,s,o,a,l,c),l[c]=p,0}function e8(e,t,n,r,i,s,o,a,l,c){let u=0;if(e<0?u=-1:t<0||t>e?u=-2:n<0||n>t?u=-3:s<Math.max(1,e)&&(u=-5),u!==0)return ts("DORG2R",-u),u;if(t<=0)return 0;for(let h=n+1;h<=t;h++){for(let f=1;f<=e;f++)r[i+(f-1)+(h-1)*s]=0;r[i+(h-1)+(h-1)*s]=1}for(let h=n;h>=1;h--){const f=i+(h-1)+(h-1)*s,d=o[a+(h-1)];h<t&&ul(Rr,e-h+1,t-h,r,f,1,d,r,i+(h-1)+h*s,s,l,c),h<e&&zn(e-h,-d,r,i+h+(h-1)*s,1),r[f]=1-d;for(let p=1;p<=h-1;p++)r[i+(p-1)+(h-1)*s]=0}return 0}function Fc(e,t,n,r,i,s,o,a){let l=0;const c=Or(1,"DORGQR"," ",e,t);if(e<0?l=-1:t<0||t>e?l=-2:n<0||n>t?l=-3:s<Math.max(1,e)&&(l=-5),l!==0)return ts("DORGQR",-l),l;if(t<=0)return 0;const u=2;let h=0,f=t,d=0;if(c>1&&c<n&&(h=Math.max(0,Or(3,"DORGQR"," ",e,t)),h<n&&(f=t*c)),c>=u&&c<n&&h<n){const p=Math.floor((n-h-1)/c)*c;d=Math.min(n,p+c);for(let m=d+1;m<=t;m++)for(let y=1;y<=d;y++)r[i+(y-1)+(m-1)*s]=0}else d=0;if(d<t){const p=D(Math.max(1,t));e8(e-d,t-d,n-d,r,i+d+d*s,s,o,a+d,p,0)}if(d>0){const p=D(f),m=Math.floor((n-h-1)/c)*c;for(let y=m+1;y>=1;y-=c){const _=Math.min(c,n-y+1);e8(e-y+1,_,_,r,i+(y-1)+(y-1)*s,s,o,a+(y-1),p,0);for(let b=y;b<=y+_-1;b++)for(let x=1;x<=y-1;x++)r[i+(x-1)+(b-1)*s]=0}}return 0}const dw=0,t8=1;function n8(e,t,n,r,i,s,o,a,l,c,u){let h=0;const f=n-t,d=u===-1;e<0?h=-1:t<1||t>Math.max(1,e)?h=-2:n<Math.min(t,e)||n>e?h=-3:s<Math.max(1,e)?h=-5:u<Math.max(1,f)&&!d&&(h=-8);let p;if(h===0){const m=Or(1,"DORGQR"," ",f,f);p=Math.max(1,f)*m,l[c]=p}else p=1;if(h!==0)return h;if(d)return 0;if(e===0)return l[c]=1,0;for(let m=n;m>=t+1;m--){for(let y=1;y<=m-1;y++)r[i+(y-1)+(m-1)*s]=dw;for(let y=m+1;y<=n;y++)r[i+(y-1)+(m-1)*s]=r[i+(y-1)+(m-2)*s];for(let y=n+1;y<=e;y++)r[i+(y-1)+(m-1)*s]=dw}for(let m=1;m<=t;m++){for(let y=1;y<=e;y++)r[i+(y-1)+(m-1)*s]=dw;r[i+(m-1)+(m-1)*s]=t8}for(let m=n+1;m<=e;m++){for(let y=1;y<=e;y++)r[i+(y-1)+(m-1)*s]=dw;r[i+(m-1)+(m-1)*s]=t8}return f>0&&Fc(f,f,f,r,i+t+t*s,s,o,a+(t-1)),l[c]=p,0}function cT(e,t){return t>=0?Math.abs(e):-Math.abs(e)}function i1(e,t,n,r){const c=ei(Wo),u=ei(oh),h=ei(x$),f=Math.pow(h,Math.trunc(Math.log(c/u)/Math.log(h)/2)),d=1/f;let p,m,y,_,b,x,S;if(n===0)p=1,m=0;else if(t===0)p=0,m=1,b=r,r=e,e=b,t=-n,n=0;else if(e-r===0&&Math.sign(t)!==Math.sign(n))p=1,m=0;else{b=e-r,x=.5*b;const T=Math.max(Math.abs(t),Math.abs(n)),k=Math.min(Math.abs(t),Math.abs(n))*Math.sign(t)*Math.sign(n),R=Math.max(Math.abs(x),T);let B=x/R*x+T/R*k;if(B>=4*u)B=x+cT(Math.sqrt(R)*Math.sqrt(B),x),e=r+B,r=r-T/B*k,S=r1(n,B),p=B/S,m=n/S,t=t-n,n=0;else{let F=0,L=t+n,j=!0;for(;j;){j=!1,F=F+1;const H=Math.max(Math.abs(b),Math.abs(L));if(H>=d&&(L=L*f,b=b*f,F<=20)){j=!0;continue}if(H<=f&&(L=L*d,b=b*d,F<=20)){j=!0;continue}}x=.5*b,S=r1(L,b),p=Math.sqrt(.5*(1+Math.abs(L)/S)),m=-(x/(S*p))*cT(1,L);const V=e*p+t*m,O=-e*m+t*p,P=n*p+r*m,N=-n*m+r*p;if(e=V*p+P*m,t=O*p+N*m,n=-(V*m)+P*p,r=-O*m+N*p,b=.5*(e+r),e=b,r=b,n!==0)if(t!==0){if(Math.sign(t)===Math.sign(n)){const H=Math.sqrt(Math.abs(t)),U=Math.sqrt(Math.abs(n));x=cT(H*U,n),S=1/Math.sqrt(Math.abs(t+n)),e=b+x,r=b-x,t=t-n,n=0;const G=H*S,Z=U*S;b=p*G-m*Z,m=p*Z+m*G,p=b}}else t=-n,n=0,b=p,p=-m,m=b}}const M=e,E=r;return n===0?(y=0,_=0):(y=Math.sqrt(Math.abs(t))*Math.sqrt(Math.abs(n)),_=-y),{a:e,b:t,c:n,d:r,rt1r:M,rt1i:y,rt2r:E,rt2i:_,cs:p,sn:m}}function Ta(e,t,n,r,i,s,o,a,l){if(!(e<=0))if(r===1&&o===1)for(let c=1;c<=e;c++){const u=a*t[n+(c-1)]+l*i[s+(c-1)];i[s+(c-1)]=a*i[s+(c-1)]-l*t[n+(c-1)],t[n+(c-1)]=u}else{let c=1,u=1;r<0&&(c=(-e+1)*r+1),o<0&&(u=(-e+1)*o+1);for(let h=1;h<=e;h++){const f=a*t[n+(c-1)]+l*i[s+(u-1)];i[s+(u-1)]=a*i[s+(u-1)]-l*t[n+(c-1)],t[n+(c-1)]=f,c+=r,u+=o}}}function M2(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y){const T=(Z,ie)=>o+(Z-1)+(ie-1)*a,k=(Z,ie)=>m+(Z-1)+(ie-1)*y;let R=0;if(n===0)return 0;if(r===i)return l[c+(r-1)]=s[T(r,r)],u[h+(r-1)]=0,0;for(let Z=r;Z<=i-3;Z++)s[T(Z+2,Z)]=0,s[T(Z+3,Z)]=0;r<=i-2&&(s[T(i,i-2)]=0);const B=i-r+1,F=d-f+1,L=ei(Wo),j=ei(oh),V=L*(B/j);let O,P;e?(O=1,P=n):(O=0,P=0);const N=30*Math.max(10,B);let H=0,U=i;const G=D(3);e:for(;;){let Z=r;if(U<r)break;for(let ie=0;ie<=N;ie++){let Y;for(Y=U;Y>=Z+1&&!(Math.abs(s[T(Y,Y-1)])<=V);Y--){let ye=Math.abs(s[T(Y-1,Y-1)])+Math.abs(s[T(Y,Y)]);if(ye===0&&(Y-2>=r&&(ye=ye+Math.abs(s[T(Y-1,Y-2)])),Y+1<=i&&(ye=ye+Math.abs(s[T(Y+1,Y)]))),Math.abs(s[T(Y,Y-1)])<=j*ye){const Ge=Math.max(Math.abs(s[T(Y,Y-1)]),Math.abs(s[T(Y-1,Y)])),Fe=Math.min(Math.abs(s[T(Y,Y-1)]),Math.abs(s[T(Y-1,Y)])),Ue=Math.max(Math.abs(s[T(Y,Y)]),Math.abs(s[T(Y-1,Y-1)]-s[T(Y,Y)])),Ee=Math.min(Math.abs(s[T(Y,Y)]),Math.abs(s[T(Y-1,Y-1)]-s[T(Y,Y)])),ke=Ue+Ge;if(Fe*(Ge/ke)<=Math.max(V,j*(Ee*(Ue/ke))))break}}if(Z=Y,Z>r&&(s[T(Z,Z-1)]=0),Z>=U-1){if(Z===U)l[c+(U-1)]=s[T(U,U)],u[h+(U-1)]=0;else if(Z===U-1){const ye=i1(s[T(U-1,U-1)],s[T(U-1,U)],s[T(U,U-1)],s[T(U,U)]);s[T(U-1,U-1)]=ye.a,s[T(U-1,U)]=ye.b,s[T(U,U-1)]=ye.c,s[T(U,U)]=ye.d,l[c+(U-2)]=ye.rt1r,u[h+(U-2)]=ye.rt1i,l[c+(U-1)]=ye.rt2r,u[h+(U-1)]=ye.rt2i;const Ge=ye.cs,Fe=ye.sn;e&&(P>U&&Ta(P-U,s,T(U-1,U+1),a,s,T(U,U+1),a,Ge,Fe),Ta(U-O-1,s,T(O,U-1),1,s,T(O,U),1,Ge,Fe)),t&&Ta(F,p,k(f,U-1),1,p,k(f,U),1,Ge,Fe)}H=0,U=Z-1;continue e}H=H+1,e||(O=Z,P=U);let ue,ge,te,X;if(H%20===0){const ye=Math.abs(s[T(U,U-1)])+Math.abs(s[T(U-1,U-2)]);ue=.75*ye+s[T(U,U)],ge=-.4375*ye,te=ye,X=ue}else if(H%10===0){const ye=Math.abs(s[T(Z+1,Z)])+Math.abs(s[T(Z+2,Z+1)]);ue=.75*ye+s[T(Z,Z)],ge=-.4375*ye,te=ye,X=ue}else ue=s[T(U-1,U-1)],te=s[T(U,U-1)],ge=s[T(U-1,U)],X=s[T(U,U)];let de=Math.abs(ue)+Math.abs(ge)+Math.abs(te)+Math.abs(X),fe,ae,J,K;if(de===0)fe=0,ae=0,J=0,K=0;else{ue=ue/de,te=te/de,ge=ge/de,X=X/de;const ye=(ue+X)/2,Ge=(ue-ye)*(X-ye)-ge*te,Fe=Math.sqrt(Math.abs(Ge));Ge>=0?(fe=ye*de,J=fe,ae=Fe*de,K=-ae):(fe=ye+Fe,J=ye-Fe,Math.abs(fe-X)<=Math.abs(J-X)?(fe=fe*de,J=fe):(J=J*de,fe=J),ae=0,K=0)}let Se;for(Se=U-2;Se>=Z;Se--){const ye=s[T(Se+1,Se)];de=Math.abs(s[T(Se,Se)]-J)+Math.abs(K)+Math.abs(ye);const Ge=s[T(Se+1,Se)]/de;if(G[0]=Ge*s[T(Se,Se+1)]+(s[T(Se,Se)]-fe)*((s[T(Se,Se)]-J)/de)-ae*(K/de),G[1]=Ge*(s[T(Se,Se)]+s[T(Se+1,Se+1)]-fe-J),G[2]=Ge*s[T(Se+2,Se+1)],de=Math.abs(G[0])+Math.abs(G[1])+Math.abs(G[2]),G[0]=G[0]/de,G[1]=G[1]/de,G[2]=G[2]/de,Se===Z||Math.abs(s[T(Se,Se-1)])*(Math.abs(G[1])+Math.abs(G[2]))<=j*Math.abs(G[0])*(Math.abs(s[T(Se-1,Se-1)])+Math.abs(s[T(Se,Se)])+Math.abs(s[T(Se+1,Se+1)])))break}for(Y=Se;Y<=U-1;Y++){const ye=Math.min(3,U-Y+1);Y>Se&&rf(ye,s,T(Y,Y-1),1,G,0,1);const Ge=Rs(ye,G[0],G,1,1);G[0]=Ge.alpha;const Fe=Ge.tau;Y>Se?(s[T(Y,Y-1)]=G[0],s[T(Y+1,Y-1)]=0,Y<U-1&&(s[T(Y+2,Y-1)]=0)):Se>Z&&(s[T(Y,Y-1)]=s[T(Y,Y-1)]*(1-Fe));const Ue=G[1],Ee=Fe*Ue;if(ye===3){const ke=G[2],_e=Fe*ke;for(let we=Y;we<=P;we++){const Le=s[T(Y,we)]+Ue*s[T(Y+1,we)]+ke*s[T(Y+2,we)];s[T(Y,we)]=s[T(Y,we)]-Le*Fe,s[T(Y+1,we)]=s[T(Y+1,we)]-Le*Ee,s[T(Y+2,we)]=s[T(Y+2,we)]-Le*_e}for(let we=O;we<=Math.min(Y+3,U);we++){const Le=s[T(we,Y)]+Ue*s[T(we,Y+1)]+ke*s[T(we,Y+2)];s[T(we,Y)]=s[T(we,Y)]-Le*Fe,s[T(we,Y+1)]=s[T(we,Y+1)]-Le*Ee,s[T(we,Y+2)]=s[T(we,Y+2)]-Le*_e}if(t)for(let we=f;we<=d;we++){const Le=p[k(we,Y)]+Ue*p[k(we,Y+1)]+ke*p[k(we,Y+2)];p[k(we,Y)]=p[k(we,Y)]-Le*Fe,p[k(we,Y+1)]=p[k(we,Y+1)]-Le*Ee,p[k(we,Y+2)]=p[k(we,Y+2)]-Le*_e}}else if(ye===2){for(let ke=Y;ke<=P;ke++){const _e=s[T(Y,ke)]+Ue*s[T(Y+1,ke)];s[T(Y,ke)]=s[T(Y,ke)]-_e*Fe,s[T(Y+1,ke)]=s[T(Y+1,ke)]-_e*Ee}for(let ke=O;ke<=U;ke++){const _e=s[T(ke,Y)]+Ue*s[T(ke,Y+1)];s[T(ke,Y)]=s[T(ke,Y)]-_e*Fe,s[T(ke,Y+1)]=s[T(ke,Y+1)]-_e*Ee}if(t)for(let ke=f;ke<=d;ke++){const _e=p[k(ke,Y)]+Ue*p[k(ke,Y+1)];p[k(ke,Y)]=p[k(ke,Y)]-_e*Fe,p[k(ke,Y+1)]=p[k(ke,Y+1)]-_e*Ee}}}}return R=U,R}return 0}function ls(e,t,n,r,i,s,o,a){if(e===cn)for(let l=2;l<=n;l++)for(let c=1;c<=Math.min(l-1,t);c++)s[o+(c-1)+(l-1)*a]=r;else if(e===Un)for(let l=1;l<=Math.min(t,n);l++)for(let c=l+1;c<=t;c++)s[o+(c-1)+(l-1)*a]=r;else for(let l=1;l<=n;l++)for(let c=1;c<=t;c++)s[o+(c-1)+(l-1)*a]=r;for(let l=1;l<=Math.min(t,n);l++)s[o+(l-1)+(l-1)*a]=i}const Bue=[2,3,0,1],Fue=[1,0,3,2],zue=[3,2,1,0],Uue=[!1,!1,!0,!0],Oue=[!1,!0,!1,!0];function jue(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y){let _=0,b=1,x=0;if(r===0||i===0)return{scale:b,xnorm:x,info:_};const S=ei(oh),M=ei(Wo)/S,E=n,T=r+r+i-2;if(T===1){let j=s[o]+E*l[c],V=Math.abs(j);V<=M&&(j=M,V=M,_=1),b=1;const O=Math.abs(h[f]);return M*O>V&&(b=1/O),p[m]=h[f]*b/j,x=Math.abs(p[m]),{scale:b,xnorm:x,info:_}}if(T===2){const j=Math.max(S*Math.max(Math.abs(s[o]),Math.abs(l[c]),Math.abs(l[c+u]),Math.abs(l[c+1]),Math.abs(l[c+1+u])),M),V=D(4);V[0]=s[o]+E*l[c],V[3]=s[o]+E*l[c+1+u],V[1]=E*l[c+u],V[2]=E*l[c+1];const O=D(4);return O[0]=h[f],O[1]=h[f+d],r8(V,O,j,M,r,p,m,y)}if(T===3){const j=Math.max(S*Math.max(Math.abs(l[c]),Math.abs(s[o]),Math.abs(s[o+a]),Math.abs(s[o+1]),Math.abs(s[o+1+a])),M),V=D(4);V[0]=s[o]+E*l[c],V[3]=s[o+1+a]+E*l[c],V[1]=s[o+1],V[2]=s[o+a];const O=D(4);return O[0]=h[f],O[1]=h[f+1],r8(V,O,j,M,r,p,m,y)}let k=Math.max(Math.abs(l[c]),Math.abs(l[c+u]),Math.abs(l[c+1]),Math.abs(l[c+1+u]));k=Math.max(k,Math.abs(s[o]),Math.abs(s[o+a]),Math.abs(s[o+1]),Math.abs(s[o+1+a])),k=Math.max(S*k,M);const R=D(16);R[0]=s[o]+E*l[c],R[5]=s[o+1+a]+E*l[c],R[10]=s[o]+E*l[c+1+u],R[15]=s[o+1+a]+E*l[c+1+u],R[4]=s[o+a],R[1]=s[o+1],R[14]=s[o+a],R[11]=s[o+1],R[8]=E*l[c+1],R[13]=E*l[c+1],R[2]=E*l[c+u],R[7]=E*l[c+u];const B=D(4);B[0]=h[f],B[1]=h[f+1],B[2]=h[f+d],B[3]=h[f+1+d];const F=new Int32Array(4);for(let j=0;j<3;j++){let V=0,O=j,P=j;for(let N=j;N<4;N++)for(let H=j;H<4;H++)Math.abs(R[N+H*4])>=V&&(V=Math.abs(R[N+H*4]),O=N,P=H);if(O!==j){for(let H=0;H<4;H++){const U=R[O+H*4];R[O+H*4]=R[j+H*4],R[j+H*4]=U}const N=B[j];B[j]=B[O],B[O]=N}if(P!==j)for(let N=0;N<4;N++){const H=R[N+P*4];R[N+P*4]=R[N+j*4],R[N+j*4]=H}F[j]=P,Math.abs(R[j+j*4])<k&&(_=1,R[j+j*4]=k);for(let N=j+1;N<4;N++){R[N+j*4]=R[N+j*4]/R[j+j*4],B[N]=B[N]-R[N+j*4]*B[j];for(let H=j+1;H<4;H++)R[N+H*4]=R[N+H*4]-R[N+j*4]*R[j+H*4]}}Math.abs(R[15])<k&&(_=1,R[15]=k),b=1,(8*M*Math.abs(B[0])>Math.abs(R[0])||8*M*Math.abs(B[1])>Math.abs(R[5])||8*M*Math.abs(B[2])>Math.abs(R[10])||8*M*Math.abs(B[3])>Math.abs(R[15]))&&(b=.125/Math.max(Math.abs(B[0]),Math.abs(B[1]),Math.abs(B[2]),Math.abs(B[3])),B[0]*=b,B[1]*=b,B[2]*=b,B[3]*=b);const L=D(4);for(let j=0;j<4;j++){const V=3-j,O=1/R[V+V*4];L[V]=B[V]*O;for(let P=V+1;P<4;P++)L[V]=L[V]-O*R[V+P*4]*L[P]}for(let j=0;j<3;j++){const V=2-j;if(F[V]!==V){const O=L[V];L[V]=L[F[V]],L[F[V]]=O}}return p[m]=L[0],p[m+1]=L[1],p[m+y]=L[2],p[m+1+y]=L[3],x=Math.max(Math.abs(L[0])+Math.abs(L[2]),Math.abs(L[1])+Math.abs(L[3])),{scale:b,xnorm:x,info:_}}function r8(e,t,n,r,i,s,o,a){let l=0,c,u,h=0,f=Math.abs(e[0]);for(let M=1;M<4;M++)Math.abs(e[M])>f&&(f=Math.abs(e[M]),h=M);let d=e[h];Math.abs(d)<=n&&(l=1,d=n);const p=e[Bue[h]],m=e[Fue[h]]/d;let y=e[zue[h]]-p*m;const _=Uue[h],b=Oue[h];if(Math.abs(y)<=n&&(l=1,y=n),b){const M=t[1];t[1]=t[0]-m*M,t[0]=M}else t[1]=t[1]-m*t[0];c=1,(2*r*Math.abs(t[1])>Math.abs(y)||2*r*Math.abs(t[0])>Math.abs(d))&&(c=.5/Math.max(Math.abs(t[0]),Math.abs(t[1])),t[0]*=c,t[1]*=c);let x=t[1]/y,S=t[0]/d-p/d*x;if(_){const M=x;x=S,S=M}return s[o]=S,i===1?(s[o+a]=x,u=Math.abs(s[o])+Math.abs(s[o+a])):(s[o+1]=x,u=Math.max(Math.abs(s[o]),Math.abs(s[o+1]))),{scale:c,xnorm:u,info:l}}function i8(e,t,n,r,i,s,o,a,l,c,u,h){const f=e===Rr;let d=0,p=0;if(o!==0){f?d=t:d=n;let m;for(m=i+(d-1)*s;d>0&&r[m]===0;)d--,m-=s;f?p=Hue(d,n,a,l,c):p=$ue(t,d,a,l,c)}f?d>0&&(Yn(Kn,d,p,1,a,l,c,r,i,s,0,u,h,1),w2(d,p,-o,r,i,s,u,h,1,a,l,c)):d>0&&(Yn(Lt,p,d,1,a,l,c,r,i,s,0,u,h,1),w2(p,d,-o,u,h,1,r,i,s,a,l,c))}function Hue(e,t,n,r,i){if(t===0)return 0;if(n[r+(t-1)*i]!==0||n[r+(e-1)+(t-1)*i]!==0)return t;for(let s=t;s>=1;s--)for(let o=1;o<=e;o++)if(n[r+(o-1)+(s-1)*i]!==0)return s;return 0}function $ue(e,t,n,r,i){if(e===0)return 0;if(n[r+(e-1)]!==0||n[r+(e-1)+(t-1)*i]!==0)return e;for(let s=e;s>=1;s--)for(let o=1;o<=t;o++)if(n[r+(s-1)+(o-1)*i]!==0)return s;return 0}function ro(e,t,n,r,i,s,o,a,l,c,u){if(s!==0)if(e===Rr)switch(t){case 1:Vue(n,r,i,s,o,a,l);return;case 2:Wue(n,r,i,s,o,a,l);return;case 3:que(n,r,i,s,o,a,l);return;case 4:Gue(n,r,i,s,o,a,l);return;case 5:Xue(n,r,i,s,o,a,l);return;case 6:Yue(n,r,i,s,o,a,l);return;case 7:Kue(n,r,i,s,o,a,l);return;case 8:Zue(n,r,i,s,o,a,l);return;case 9:Que(n,r,i,s,o,a,l);return;case 10:Jue(n,r,i,s,o,a,l);return;default:i8(e,t,n,r,i,1,s,o,a,l,c,u);return}else switch(n){case 1:ehe(t,r,i,s,o,a);return;case 2:the(t,r,i,s,o,a,l);return;case 3:nhe(t,r,i,s,o,a,l);return;case 4:rhe(t,r,i,s,o,a,l);return;case 5:ihe(t,r,i,s,o,a,l);return;case 6:she(t,r,i,s,o,a,l);return;case 7:ohe(t,r,i,s,o,a,l);return;case 8:ahe(t,r,i,s,o,a,l);return;case 9:lhe(t,r,i,s,o,a,l);return;case 10:che(t,r,i,s,o,a,l);return;default:i8(e,t,n,r,i,1,s,o,a,l,c,u);return}}function Vue(e,t,n,r,i,s,o){const a=1-r*t[n]*t[n];for(let l=0;l<e;l++)i[s+l*o]=a*i[s+l*o]}function Wue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c;for(let h=0;h<e;h++){const f=s+h*o,d=a*i[f]+c*i[f+1];i[f]-=d*l,i[f+1]-=d*u}}function que(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h;for(let d=0;d<e;d++){const p=s+d*o,m=a*i[p]+c*i[p+1]+h*i[p+2];i[p]-=m*l,i[p+1]-=m*u,i[p+2]-=m*f}}function Gue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d;for(let m=0;m<e;m++){const y=s+m*o,_=a*i[y]+c*i[y+1]+h*i[y+2]+d*i[y+3];i[y]-=_*l,i[y+1]-=_*u,i[y+2]-=_*f,i[y+3]-=_*p}}function Xue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m;for(let _=0;_<e;_++){const b=s+_*o,x=a*i[b]+c*i[b+1]+h*i[b+2]+d*i[b+3]+m*i[b+4];i[b]-=x*l,i[b+1]-=x*u,i[b+2]-=x*f,i[b+3]-=x*p,i[b+4]-=x*y}}function Yue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_;for(let x=0;x<e;x++){const S=s+x*o,M=a*i[S]+c*i[S+1]+h*i[S+2]+d*i[S+3]+m*i[S+4]+_*i[S+5];i[S]-=M*l,i[S+1]-=M*u,i[S+2]-=M*f,i[S+3]-=M*p,i[S+4]-=M*y,i[S+5]-=M*b}}function Kue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x;for(let M=0;M<e;M++){const E=s+M*o,T=a*i[E]+c*i[E+1]+h*i[E+2]+d*i[E+3]+m*i[E+4]+_*i[E+5]+x*i[E+6];i[E]-=T*l,i[E+1]-=T*u,i[E+2]-=T*f,i[E+3]-=T*p,i[E+4]-=T*y,i[E+5]-=T*b,i[E+6]-=T*S}}function Zue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x,M=t[n+7],E=r*M;for(let T=0;T<e;T++){const k=s+T*o,R=a*i[k]+c*i[k+1]+h*i[k+2]+d*i[k+3]+m*i[k+4]+_*i[k+5]+x*i[k+6]+M*i[k+7];i[k]-=R*l,i[k+1]-=R*u,i[k+2]-=R*f,i[k+3]-=R*p,i[k+4]-=R*y,i[k+5]-=R*b,i[k+6]-=R*S,i[k+7]-=R*E}}function Que(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x,M=t[n+7],E=r*M,T=t[n+8],k=r*T;for(let R=0;R<e;R++){const B=s+R*o,F=a*i[B]+c*i[B+1]+h*i[B+2]+d*i[B+3]+m*i[B+4]+_*i[B+5]+x*i[B+6]+M*i[B+7]+T*i[B+8];i[B]-=F*l,i[B+1]-=F*u,i[B+2]-=F*f,i[B+3]-=F*p,i[B+4]-=F*y,i[B+5]-=F*b,i[B+6]-=F*S,i[B+7]-=F*E,i[B+8]-=F*k}}function Jue(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x,M=t[n+7],E=r*M,T=t[n+8],k=r*T,R=t[n+9],B=r*R;for(let F=0;F<e;F++){const L=s+F*o,j=a*i[L]+c*i[L+1]+h*i[L+2]+d*i[L+3]+m*i[L+4]+_*i[L+5]+x*i[L+6]+M*i[L+7]+T*i[L+8]+R*i[L+9];i[L]-=j*l,i[L+1]-=j*u,i[L+2]-=j*f,i[L+3]-=j*p,i[L+4]-=j*y,i[L+5]-=j*b,i[L+6]-=j*S,i[L+7]-=j*E,i[L+8]-=j*k,i[L+9]-=j*B}}function ehe(e,t,n,r,i,s,o){const a=1-r*t[n]*t[n];for(let l=0;l<e;l++)i[s+l]=a*i[s+l]}function the(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c;for(let h=0;h<e;h++){const f=a*i[s+h]+c*i[s+h+o];i[s+h]-=f*l,i[s+h+o]-=f*u}}function nhe(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h;for(let d=0;d<e;d++){const p=a*i[s+d]+c*i[s+d+o]+h*i[s+d+2*o];i[s+d]-=p*l,i[s+d+o]-=p*u,i[s+d+2*o]-=p*f}}function rhe(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d;for(let m=0;m<e;m++){const y=a*i[s+m]+c*i[s+m+o]+h*i[s+m+2*o]+d*i[s+m+3*o];i[s+m]-=y*l,i[s+m+o]-=y*u,i[s+m+2*o]-=y*f,i[s+m+3*o]-=y*p}}function ihe(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m;for(let _=0;_<e;_++){const b=a*i[s+_]+c*i[s+_+o]+h*i[s+_+2*o]+d*i[s+_+3*o]+m*i[s+_+4*o];i[s+_]-=b*l,i[s+_+o]-=b*u,i[s+_+2*o]-=b*f,i[s+_+3*o]-=b*p,i[s+_+4*o]-=b*y}}function she(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_;for(let x=0;x<e;x++){const S=a*i[s+x]+c*i[s+x+o]+h*i[s+x+2*o]+d*i[s+x+3*o]+m*i[s+x+4*o]+_*i[s+x+5*o];i[s+x]-=S*l,i[s+x+o]-=S*u,i[s+x+2*o]-=S*f,i[s+x+3*o]-=S*p,i[s+x+4*o]-=S*y,i[s+x+5*o]-=S*b}}function ohe(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x;for(let M=0;M<e;M++){const E=a*i[s+M]+c*i[s+M+o]+h*i[s+M+2*o]+d*i[s+M+3*o]+m*i[s+M+4*o]+_*i[s+M+5*o]+x*i[s+M+6*o];i[s+M]-=E*l,i[s+M+o]-=E*u,i[s+M+2*o]-=E*f,i[s+M+3*o]-=E*p,i[s+M+4*o]-=E*y,i[s+M+5*o]-=E*b,i[s+M+6*o]-=E*S}}function ahe(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x,M=t[n+7],E=r*M;for(let T=0;T<e;T++){const k=a*i[s+T]+c*i[s+T+o]+h*i[s+T+2*o]+d*i[s+T+3*o]+m*i[s+T+4*o]+_*i[s+T+5*o]+x*i[s+T+6*o]+M*i[s+T+7*o];i[s+T]-=k*l,i[s+T+o]-=k*u,i[s+T+2*o]-=k*f,i[s+T+3*o]-=k*p,i[s+T+4*o]-=k*y,i[s+T+5*o]-=k*b,i[s+T+6*o]-=k*S,i[s+T+7*o]-=k*E}}function lhe(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x,M=t[n+7],E=r*M,T=t[n+8],k=r*T;for(let R=0;R<e;R++){const B=a*i[s+R]+c*i[s+R+o]+h*i[s+R+2*o]+d*i[s+R+3*o]+m*i[s+R+4*o]+_*i[s+R+5*o]+x*i[s+R+6*o]+M*i[s+R+7*o]+T*i[s+R+8*o];i[s+R]-=B*l,i[s+R+o]-=B*u,i[s+R+2*o]-=B*f,i[s+R+3*o]-=B*p,i[s+R+4*o]-=B*y,i[s+R+5*o]-=B*b,i[s+R+6*o]-=B*S,i[s+R+7*o]-=B*E,i[s+R+8*o]-=B*k}}function che(e,t,n,r,i,s,o){const a=t[n],l=r*a,c=t[n+1],u=r*c,h=t[n+2],f=r*h,d=t[n+3],p=r*d,m=t[n+4],y=r*m,_=t[n+5],b=r*_,x=t[n+6],S=r*x,M=t[n+7],E=r*M,T=t[n+8],k=r*T,R=t[n+9],B=r*R;for(let F=0;F<e;F++){const L=a*i[s+F]+c*i[s+F+o]+h*i[s+F+2*o]+d*i[s+F+3*o]+m*i[s+F+4*o]+_*i[s+F+5*o]+x*i[s+F+6*o]+M*i[s+F+7*o]+T*i[s+F+8*o]+R*i[s+F+9*o];i[s+F]-=L*l,i[s+F+o]-=L*u,i[s+F+2*o]-=L*f,i[s+F+3*o]-=L*p,i[s+F+4*o]-=L*y,i[s+F+5*o]-=L*b,i[s+F+6*o]-=L*S,i[s+F+7*o]-=L*E,i[s+F+8*o]-=L*k,i[s+F+9*o]-=L*B}}function VL(e,t,n,r,i,s,o,a){let l;if(Math.min(t,n)===0)l=0;else{l=0;for(let c=1;c<=n;c++)for(let u=1;u<=t;u++){const h=Math.abs(r[i+(u-1)+(c-1)*s]);(l<h||isNaN(h))&&(l=h)}}return l}function uT(e,t){return t>=0&&!Object.is(t,-0)?Math.abs(e):-Math.abs(e)}function oc(e,t){const n=ei(Wo),r=1/n,i=Math.sqrt(n),s=Math.sqrt(r/2),o=Math.abs(e),a=Math.abs(t);let l,c,u;if(t===0)l=1,c=0,u=e;else if(e===0)l=0,c=uT(1,t),u=a;else if(o>i&&o<s&&a>i&&a<s){const h=Math.sqrt(e*e+t*t);l=o/h,u=uT(h,e),c=t/u}else{const h=Math.min(r,Math.max(n,o,a)),f=e/h,d=t/h,p=Math.sqrt(f*f+d*d);l=Math.abs(f)/p,u=uT(p,e),c=d/u,u=u*h}return{cs:l,sn:c,r:u}}const uhe=-1,hhe=0;function tc(e,t,n,r,i,s,o,a,l,c,u,h,f){const b=(B,F)=>r+(B-1)+(F-1)*i,x=(B,F)=>o+(B-1)+(F-1)*a,S=(B,F)=>B-1+(F-1)*4,M=(B,F)=>B-1+(F-1)*2;if(t===0||c===0||u===0||l+c>t)return 0;const T=l+1,k=l+2,R=l+3;if(c===1&&u===1){const B=n[b(l,l)],F=n[b(T,T)],L=oc(n[b(l,T)],F-B),j=L.cs,V=L.sn;k<=t&&Ta(t-l-1,n,b(l,k),i,n,b(T,k),i,j,V),Ta(l-1,n,b(1,l),1,n,b(1,T),1,j,V),n[b(l,l)]=F,n[b(T,T)]=B,Ta(t,s,x(1,l),1,s,x(1,T),1,j,V)}else{const B=c+u,F=D(16);xn(uhe,B,B,n,b(l,l),i,F,0,4);const L=VL(hhe,B,B,F,0,4),j=ei(oh),V=ei(Wo)/j,O=Math.max(10*j*L,V),P=D(4),H=jue(!1,!1,-1,c,u,F,0,4,F,c+c*4,4,F,c*4,4,P,0,2).scale,U=c+c+u-3;if(U===1){const G=D(3);G[0]=H,G[1]=P[M(1,1)],G[2]=P[M(1,2)];const Z=Rs(3,G[2],G,0,1);G[2]=1;const ie=Z.tau,Y=n[b(l,l)];if(ro(Rr,3,3,G,0,ie,F,0,4,h,f),ro(Pn,3,3,G,0,ie,F,0,4,h,f),Math.max(Math.abs(F[S(3,1)]),Math.abs(F[S(3,2)]),Math.abs(F[S(3,3)]-Y))>O)return 1;ro(Rr,3,t-l+1,G,0,ie,n,b(l,l),i,h,f),ro(Pn,T,3,G,0,ie,n,b(1,l),i,h,f),n[b(k,l)]=0,n[b(k,T)]=0,n[b(k,k)]=Y,ro(Pn,t,3,G,0,ie,s,x(1,l),a,h,f)}else if(U===2){const G=D(3);G[0]=-P[M(1,1)],G[1]=-P[M(2,1)],G[2]=H;const Z=Rs(3,G[0],G,1,1);G[0]=1;const ie=Z.tau,Y=n[b(k,k)];if(ro(Rr,3,3,G,0,ie,F,0,4,h,f),ro(Pn,3,3,G,0,ie,F,0,4,h,f),Math.max(Math.abs(F[S(2,1)]),Math.abs(F[S(3,1)]),Math.abs(F[S(1,1)]-Y))>O)return 1;ro(Pn,k,3,G,0,ie,n,b(1,l),i,h,f),ro(Rr,3,t-l,G,0,ie,n,b(l,T),i,h,f),n[b(l,l)]=Y,n[b(T,l)]=0,n[b(k,l)]=0,ro(Pn,t,3,G,0,ie,s,x(1,l),a,h,f)}else if(U===3){const G=D(3);G[0]=-P[M(1,1)],G[1]=-P[M(2,1)],G[2]=H;const Z=Rs(3,G[0],G,1,1);G[0]=1;const ie=Z.tau,Y=-ie*(P[M(1,2)]+G[1]*P[M(2,2)]),ue=D(3);ue[0]=-Y*G[1]-P[M(2,2)],ue[1]=-Y*G[2],ue[2]=H;const ge=Rs(3,ue[0],ue,1,1);ue[0]=1;const te=ge.tau;if(ro(Rr,3,4,G,0,ie,F,0,4,h,f),ro(Pn,4,3,G,0,ie,F,0,4,h,f),ro(Rr,3,4,ue,0,te,F,S(2,1),4,h,f),ro(Pn,4,3,ue,0,te,F,S(1,2),4,h,f),Math.max(Math.abs(F[S(3,1)]),Math.abs(F[S(3,2)]),Math.abs(F[S(4,1)]),Math.abs(F[S(4,2)]))>O)return 1;ro(Rr,3,t-l+1,G,0,ie,n,b(l,l),i,h,f),ro(Pn,R,3,G,0,ie,n,b(1,l),i,h,f),ro(Rr,3,t-l+1,ue,0,te,n,b(T,l),i,h,f),ro(Pn,R,3,ue,0,te,n,b(1,T),i,h,f),n[b(k,l)]=0,n[b(k,T)]=0,n[b(R,l)]=0,n[b(R,T)]=0,ro(Pn,t,3,G,0,ie,s,x(1,l),a,h,f),ro(Pn,t,3,ue,0,te,s,x(1,T),a,h,f)}if(u===2){const G=i1(n[b(l,l)],n[b(l,T)],n[b(T,l)],n[b(T,T)]);n[b(l,l)]=G.a,n[b(l,T)]=G.b,n[b(T,l)]=G.c,n[b(T,T)]=G.d;const Z=G.cs,ie=G.sn;Ta(t-l-1,n,b(l,l+2),i,n,b(T,l+2),i,Z,ie),Ta(l-1,n,b(1,l),1,n,b(1,T),1,Z,ie),Ta(t,s,x(1,l),1,s,x(1,T),1,Z,ie)}if(c===2){const G=l+u,Z=G+1,ie=i1(n[b(G,G)],n[b(G,Z)],n[b(Z,G)],n[b(Z,Z)]);n[b(G,G)]=ie.a,n[b(G,Z)]=ie.b,n[b(Z,G)]=ie.c,n[b(Z,Z)]=ie.d;const Y=ie.cs,ue=ie.sn;G+2<=t&&Ta(t-G-1,n,b(G,G+2),i,n,b(Z,G+2),i,Y,ue),Ta(G-1,n,b(1,G),1,n,b(1,Z),1,Y,ue),Ta(t,s,x(1,G),1,s,x(1,Z),1,Y,ue)}}return 0}function hT(e,t,n,r,i,s,o,a,l,c,u,h){const d=(x,S)=>r+(x-1)+(S-1)*i;let p=0;const m=e===1;if(t<0?p=-2:i<Math.max(1,t)?p=-4:a<1||a<Math.max(1,t)?p=-6:t>0&&(l.val<1||l.val>t)?p=-7:t>0&&(c.val<1||c.val>t)&&(p=-8),p!==0)return p;if(t<=1)return 0;l.val>1&&n[d(l.val,l.val-1)]!==0&&(l.val=l.val-1);let y=1;l.val<t&&n[d(l.val+1,l.val)]!==0&&(y=2),c.val>1&&n[d(c.val,c.val-1)]!==0&&(c.val=c.val-1);let _=1;if(c.val<t&&n[d(c.val+1,c.val)]!==0&&(_=2),l.val===c.val)return 0;let b;if(l.val<c.val)for(y===2&&_===1&&(c.val=c.val-1),y===1&&_===2&&(c.val=c.val+1),b=l.val;;){if(y===1||y===2){let x=1;if(b+y+1<=t&&n[d(b+y+1,b+y)]!==0&&(x=2),p=tc(m,t,n,r,i,s,o,a,b,y,x,u,h),p!==0)return c.val=b,p;b=b+x,y===2&&n[d(b+1,b)]===0&&(y=3)}else{let x=1;if(b+3<=t&&n[d(b+3,b+2)]!==0&&(x=2),p=tc(m,t,n,r,i,s,o,a,b+1,1,x,u,h),p!==0)return c.val=b,p;if(x===1)p=tc(m,t,n,r,i,s,o,a,b,1,x,u,h),b=b+1;else if(n[d(b+2,b+1)]===0&&(x=1),x===2){if(p=tc(m,t,n,r,i,s,o,a,b,1,x,u,h),p!==0)return c.val=b,p;b=b+2}else tc(m,t,n,r,i,s,o,a,b,1,1,u,h),tc(m,t,n,r,i,s,o,a,b+1,1,1,u,h),b=b+2}if(!(b<c.val))break}else for(b=l.val;;){if(y===1||y===2){let x=1;if(b>=3&&n[d(b-1,b-2)]!==0&&(x=2),p=tc(m,t,n,r,i,s,o,a,b-x,x,y,u,h),p!==0)return c.val=b,p;b=b-x,y===2&&n[d(b+1,b)]===0&&(y=3)}else{let x=1;if(b>=3&&n[d(b-1,b-2)]!==0&&(x=2),p=tc(m,t,n,r,i,s,o,a,b-x,x,1,u,h),p!==0)return c.val=b,p;if(x===1)p=tc(m,t,n,r,i,s,o,a,b,x,1,u,h),b=b-1;else if(n[d(b,b-1)]===0&&(x=1),x===2){if(p=tc(m,t,n,r,i,s,o,a,b-1,2,1,u,h),p!==0)return c.val=b,p;b=b-2}else tc(m,t,n,r,i,s,o,a,b,1,1,u,h),tc(m,t,n,r,i,s,o,a,b-1,1,1,u,h),b=b-2}if(!(b>c.val))break}return c.val=b,0}function fhe(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p){let m=0;const y=r;if(n<0?m=-3:r<0?m=-4:i<0||i>y?m=-5:a<Math.max(1,y)?m=-7:f<Math.max(1,n)&&(m=-10),m!==0)return m;if(n===0||r===0||i===0)return 0;let _,b,x;_=1,b=i,x=1;let S,M,E,T;M=n,E=1,S=0,T=0;for(let k=_;x>0?k<=b:k>=b;k+=x)S=r-k+1,T=k,ul(e,M,S,s,o+(k-1)+(k-1)*a,1,l[c+(k-1)],u,h+(E-1)+(T-1)*f,f,d,p);return 0}const w$=0,dhe=64;function Zh(e,t,n,r,i,s,o,a,l,c,u,h){if(n===0||r===0)return;if(n===1||r===1){c[u]=a[l];return}if(r<dhe){phe(e,t,n,r,i,s,o,a,l,c,u,h);return}const f=t===w$,d=f,p=!f,m=Math.floor(r/2);if(d){Zh(e,t,n,m,i,s,o,a,l,c,u,h),Zh(e,t,n-m,r-m,i,s+m+m*o,o,a,l+m,c,u+m+m*h,h);for(let y=1;y<=m;y++)for(let _=1;_<=r-m;_++)c[u+(y-1)+(m+_-1)*h]=i[s+(m+_-1)+(y-1)*o];us(Pn,Un,Lt,Ws,m,r-m,1,i,s+m+m*o,o,c,u+m*h,h),n>r&&_r(Kn,Lt,m,r-m,n-r,1,i,s+r+0*o,o,i,s+r+m*o,o,1,c,u+m*h,h),us(Rr,cn,Lt,qs,m,r-m,-1,c,u,h,c,u+m*h,h),us(Pn,cn,Lt,qs,m,r-m,1,c,u+m+m*h,h,c,u+m*h,h)}else p?(Zh(e,t,n,m,i,s,o,a,l,c,u,h),Zh(e,t,n-m,r-m,i,s+m+m*o,o,a,l+m,c,u+m+m*h,h),xn(-1,m,r-m,i,s+m*o,o,c,u+m*h,h),us(Pn,cn,Kn,Ws,m,r-m,1,i,s+m+m*o,o,c,u+m*h,h),n>r&&_r(Lt,Kn,m,r-m,n-r,1,i,s+r*o,o,i,s+m+r*o,o,1,c,u+m*h,h),us(Rr,cn,Lt,qs,m,r-m,-1,c,u,h,c,u+m*h,h),us(Pn,cn,Lt,qs,m,r-m,1,c,u+m+m*h,h,c,u+m*h,h)):(Zh(e,t,n-m,r-m,i,s,o,a,l,c,u,h),Zh(e,t,n,m,i,s+(r-m),o,a,l+(r-m),c,u+(r-m)+(r-m)*h,h),xn(-1,m,r-m,i,s+(r-m)+(n-r)*o,o,c,u+(r-m),h),us(Pn,Un,Kn,Ws,m,r-m,1,i,s+(n-r)*o,o,c,u+(r-m),h),n>r&&_r(Lt,Kn,m,r-m,n-r,1,i,s+(r-m),o,i,s,o,1,c,u+(r-m),h),us(Rr,Un,Lt,qs,m,r-m,-1,c,u+(r-m)+(r-m)*h,h,c,u+(r-m),h),us(Pn,Un,Lt,qs,m,r-m,1,c,u,h,c,u+(r-m),h))}function phe(e,t,n,r,i,s,o,a,l,c,u,h){if(n===0)return;const f=t===w$;{let d=n;for(let p=1;p<=r;p++)if(d=Math.max(p,d),a[l+(p-1)]===0)for(let m=1;m<=p;m++)c[u+(m-1)+(p-1)*h]=0;else{let m;if(f){m=p;for(let _=n;_>=p+1;_--)if(i[s+(_-1)+(p-1)*o]!==0){m=_;break}for(let _=1;_<=p-1;_++)c[u+(_-1)+(p-1)*h]=-a[l+(p-1)]*i[s+(p-1)+(_-1)*o];const y=Math.min(m,d);y>p&&Yn(Kn,y-p,p-1,-a[l+(p-1)],i,s+p+0*o,o,i,s+p+(p-1)*o,1,1,c,u+(p-1)*h,1)}else{m=p;for(let _=n;_>=p+1;_--)if(i[s+(p-1)+(_-1)*o]!==0){m=_;break}for(let _=1;_<=p-1;_++)c[u+(_-1)+(p-1)*h]=-a[l+(p-1)]*i[s+(_-1)+(p-1)*o];const y=Math.min(m,d);y>p&&Yn(Lt,p-1,y-p,-a[l+(p-1)],i,s+p*o,o,i,s+(p-1)+p*o,o,1,c,u+(p-1)*h,1)}p>1&&A0(cn,Lt,qs,p-1,c,u,h,c,u+(p-1)*h),c[u+(p-1)+(p-1)*h]=a[l+(p-1)],p>1?d=Math.max(d,m):d=m}}}const WL=64,yR=WL+1,s8=yR*WL,o8=0,a8=0;function mhe(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m){let y=0;const _=m===-1;let b,x;b=r,x=Math.max(1,n),n<0?y=-3:r<0?y=-4:i<0||i>b?y=-5:a<Math.max(1,b)?y=-7:f<Math.max(1,n)?y=-10:m<x&&!_&&(y=-12);let S,M;if(y===0?(S=Math.min(WL,64),M=x*S+s8,d[p]=M):(S=0,M=0),y!==0)return y;if(_)return 0;if(n===0||r===0||i===0)return d[p]=1,0;let E=2;const T=x;if(S>1&&S<i&&m<M&&(S=Math.floor((m-s8)/T),E=Math.max(2,2)),S<E||S>=i)fhe(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p);else{const k=1+x*S;let R,B,F;R=1,B=i,F=S;let L,j,V,O;j=n,V=1,L=0,O=0;for(let P=R;F>0?P<=B:P>=B;P+=F){const N=Math.min(S,i-P+1);Zh(o8,a8,b-P+1,N,s,o+(P-1)+(P-1)*a,a,l,c+(P-1),d,p+(k-1),yR),L=r-P+1,O=P,HM(e,t,o8,a8,j,L,N,s,o+(P-1)+(P-1)*a,a,d,p+(k-1),yR,u,h+(V-1)+(O-1)*f,f,d,p,T)}}return d[p]=M,0}function l8(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y){let _=0;const b=s-i,x=y===-1;let S,M;S=r,M=Math.max(1,n),n<0?_=-3:r<0?_=-4:i>Math.max(1,S)?_=-5:s<Math.min(i,S)||s>S?_=-6:l<Math.max(1,S)?_=-8:d<Math.max(1,n)?_=-11:y<M&&!x&&(_=-13);let E;if(_===0?(E=M*64,p[m]=E):E=0,_!==0)return _;if(x)return 0;if(n===0||r===0||b===0)return p[m]=1,0;let T,k,R,B;return T=n,k=b,R=1,B=i+1,mhe(e,t,T,k,b,o,a+i+(i-1)*l,l,c,u+(i-1),h,f+(R-1)+(B-1)*d,d,p,m,y),p[m]=E,0}function fT(e,t,n,r,i,s,o,a,l,c){if(!(e!==2&&e!==3))if(e===2){const u=Math.abs(t[n]-o)+Math.abs(a)+Math.abs(t[n+1]);if(u===0)l[c]=0,l[c+1]=0;else{const h=t[n+1]/u;l[c]=h*t[n+r]+(t[n]-i)*((t[n]-o)/u)-s*(a/u),l[c+1]=h*(t[n]+t[n+1+r]-i-o)}}else{const u=Math.abs(t[n]-o)+Math.abs(a)+Math.abs(t[n+1])+Math.abs(t[n+2]);if(u===0)l[c]=0,l[c+1]=0,l[c+2]=0;else{const h=t[n+1]/u,f=t[n+2]/u;l[c]=(t[n]-i)*((t[n]-o)/u)-s*(a/u)+t[n+r]*h+t[n+2*r]*f,l[c+1]=h*(t[n]+t[n+1+r]-i-o)+t[n+1+2*r]*f,l[c+2]=f*(t[n]+t[n+2+2*r]-i-o)+h*t[n+2+r]}}}const pw=-1;function ghe(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x,S,M,E,T,k,R,B,F,L,j,V,O,P){const U=(J,K)=>f+(J-1)+(K-1)*d,G=(J,K)=>_+(J-1)+(K-1)*b,Z=(J,K)=>S+(J-1)+(K-1)*M,ie=(J,K)=>T+(J-1)+(K-1)*k;if(o<2||i>=s)return;for(let J=1;J<=o-2;J+=2)if(c[u+(J-1)]!==-c[u+J]){let K=a[l+(J-1)];a[l+(J-1)]=a[l+J],a[l+J]=a[l+(J+1)],a[l+(J+1)]=K,K=c[u+(J-1)],c[u+(J-1)]=c[u+J],c[u+J]=c[u+(J+1)],c[u+(J+1)]=K}const Y=o-o%2,ue=ei(Wo),ge=ei(oh),te=ue*(r/ge),X=n===1||n===2;i+2<=s&&(h[U(i+2,i)]=0);const de=Math.trunc(Y/2),fe=4*de,ae=D(3);for(let J=i-2*de+1;J<=s-2;J+=2*de){let K;X?K=Math.max(i,J):e?K=1:K=i;const Se=J+fe;X&&ls(pw,fe,fe,0,1,E,T,k);for(let ye=J;ye<=Math.min(J+2*de-1,s-2);ye++){const Ge=Math.max(1,Math.trunc((i-ye)/2)+1),Fe=Math.min(de,Math.trunc((s-ye-1)/2)),Ue=Fe+1;if(Fe<de&&ye+2*(Ue-1)===s-2){const _e=ye+2*(Ue-1);if(_e===i-1){fT(2,h,U(_e+1,_e+1),d,a[l+(2*Ue-2)],c[u+(2*Ue-2)],a[l+(2*Ue-1)],c[u+(2*Ue-1)],x,Z(1,Ue));let Q=x[Z(1,Ue)];const xe=Rs(2,Q,x,Z(2,Ue),1);Q=xe.alpha,x[Z(1,Ue)]=xe.tau}else{let Q=h[U(_e+1,_e)];x[Z(2,Ue)]=h[U(_e+2,_e)];const xe=Rs(2,Q,x,Z(2,Ue),1);Q=xe.alpha,x[Z(1,Ue)]=xe.tau,h[U(_e+1,_e)]=Q,h[U(_e+2,_e)]=0}let we=x[Z(1,Ue)],Le=we*x[Z(2,Ue)];for(let Q=K;Q<=Math.min(s,_e+3);Q++){const xe=h[U(Q,_e+1)]+x[Z(2,Ue)]*h[U(Q,_e+2)];h[U(Q,_e+1)]=h[U(Q,_e+1)]-xe*we,h[U(Q,_e+2)]=h[U(Q,_e+2)]-xe*Le}let oe;X?oe=Math.min(Se,s):e?oe=r:oe=s,we=x[Z(1,Ue)],Le=we*x[Z(2,Ue)];for(let Q=_e+1;Q<=oe;Q++){const xe=h[U(_e+1,Q)]+x[Z(2,Ue)]*h[U(_e+2,Q)];h[U(_e+1,Q)]=h[U(_e+1,Q)]-xe*we,h[U(_e+2,Q)]=h[U(_e+2,Q)]-xe*Le}if(_e>=i&&h[U(_e+1,_e)]!==0){let Q=Math.abs(h[U(_e,_e)])+Math.abs(h[U(_e+1,_e+1)]);if(Q===0&&(_e>=i+1&&(Q=Q+Math.abs(h[U(_e,_e-1)])),_e>=i+2&&(Q=Q+Math.abs(h[U(_e,_e-2)])),_e>=i+3&&(Q=Q+Math.abs(h[U(_e,_e-3)])),_e<=s-2&&(Q=Q+Math.abs(h[U(_e+2,_e+1)])),_e<=s-3&&(Q=Q+Math.abs(h[U(_e+3,_e+1)])),_e<=s-4&&(Q=Q+Math.abs(h[U(_e+4,_e+1)]))),Math.abs(h[U(_e+1,_e)])<=Math.max(te,ge*Q)){const xe=Math.max(Math.abs(h[U(_e+1,_e)]),Math.abs(h[U(_e,_e+1)])),me=Math.min(Math.abs(h[U(_e+1,_e)]),Math.abs(h[U(_e,_e+1)])),be=Math.max(Math.abs(h[U(_e+1,_e+1)]),Math.abs(h[U(_e,_e)]-h[U(_e+1,_e+1)])),ve=Math.min(Math.abs(h[U(_e+1,_e+1)]),Math.abs(h[U(_e,_e)]-h[U(_e+1,_e+1)])),Be=be+xe,He=ve*(be/Be);(He===0||me*(xe/Be)<=Math.max(te,ge*He))&&(h[U(_e+1,_e)]=0)}}if(X){const Q=_e-J;we=x[Z(1,Ue)],Le=we*x[Z(2,Ue)];for(let xe=Math.max(1,i-J);xe<=fe;xe++){const me=E[ie(xe,Q+1)]+x[Z(2,Ue)]*E[ie(xe,Q+2)];E[ie(xe,Q+1)]=E[ie(xe,Q+1)]-me*we,E[ie(xe,Q+2)]=E[ie(xe,Q+2)]-me*Le}}else if(t){we=x[Z(1,Ue)],Le=we*x[Z(2,Ue)];for(let Q=p;Q<=m;Q++){const xe=y[G(Q,_e+1)]+x[Z(2,Ue)]*y[G(Q,_e+2)];y[G(Q,_e+1)]=y[G(Q,_e+1)]-xe*we,y[G(Q,_e+2)]=y[G(Q,_e+2)]-xe*Le}}}for(let _e=Fe;_e>=Ge;_e--){const we=ye+2*(_e-1);if(we===i-1){fT(3,h,U(i,i),d,a[l+(2*_e-2)],c[u+(2*_e-2)],a[l+(2*_e-1)],c[u+(2*_e-1)],x,Z(1,_e));let xe=x[Z(1,_e)];const me=Rs(3,xe,x,Z(2,_e),1);xe=me.alpha,x[Z(1,_e)]=me.tau}else{let xe=x[Z(1,_e)],me=xe*x[Z(2,_e)],be=xe*x[Z(3,_e)],ve=x[Z(3,_e)]*h[U(we+3,we+2)];h[U(we+3,we)]=-ve*xe,h[U(we+3,we+1)]=-ve*me,h[U(we+3,we+2)]=h[U(we+3,we+2)]-ve*be;let Be=h[U(we+1,we)];x[Z(2,_e)]=h[U(we+2,we)],x[Z(3,_e)]=h[U(we+3,we)];const He=Rs(3,Be,x,Z(2,_e),1);if(Be=He.alpha,x[Z(1,_e)]=He.tau,h[U(we+3,we)]!==0||h[U(we+3,we+1)]!==0||h[U(we+3,we+2)]===0)h[U(we+1,we)]=Be,h[U(we+2,we)]=0,h[U(we+3,we)]=0;else{fT(3,h,U(we+1,we+1),d,a[l+(2*_e-2)],c[u+(2*_e-2)],a[l+(2*_e-1)],c[u+(2*_e-1)],ae,0);let je=ae[0];const st=Rs(3,je,ae,1,1);je=st.alpha,ae[0]=st.tau,xe=ae[0],me=xe*ae[1],be=xe*ae[2],ve=h[U(we+1,we)]+ae[1]*h[U(we+2,we)],Math.abs(h[U(we+2,we)]-ve*me)+Math.abs(ve*be)>ge*(Math.abs(h[U(we,we)])+Math.abs(h[U(we+1,we+1)])+Math.abs(h[U(we+2,we+2)]))?(h[U(we+1,we)]=Be,h[U(we+2,we)]=0,h[U(we+3,we)]=0):(h[U(we+1,we)]=h[U(we+1,we)]-ve*xe,h[U(we+2,we)]=0,h[U(we+3,we)]=0,x[Z(1,_e)]=ae[0],x[Z(2,_e)]=ae[1],x[Z(3,_e)]=ae[2])}}const Le=x[Z(1,_e)],oe=Le*x[Z(2,_e)],Q=Le*x[Z(3,_e)];for(let xe=K;xe<=Math.min(s,we+3);xe++){const me=h[U(xe,we+1)]+x[Z(2,_e)]*h[U(xe,we+2)]+x[Z(3,_e)]*h[U(xe,we+3)];h[U(xe,we+1)]=h[U(xe,we+1)]-me*Le,h[U(xe,we+2)]=h[U(xe,we+2)]-me*oe,h[U(xe,we+3)]=h[U(xe,we+3)]-me*Q}{const xe=h[U(we+1,we+1)]+x[Z(2,_e)]*h[U(we+2,we+1)]+x[Z(3,_e)]*h[U(we+3,we+1)];h[U(we+1,we+1)]=h[U(we+1,we+1)]-xe*Le,h[U(we+2,we+1)]=h[U(we+2,we+1)]-xe*oe,h[U(we+3,we+1)]=h[U(we+3,we+1)]-xe*Q}if(!(we<i)&&h[U(we+1,we)]!==0){let xe=Math.abs(h[U(we,we)])+Math.abs(h[U(we+1,we+1)]);if(xe===0&&(we>=i+1&&(xe=xe+Math.abs(h[U(we,we-1)])),we>=i+2&&(xe=xe+Math.abs(h[U(we,we-2)])),we>=i+3&&(xe=xe+Math.abs(h[U(we,we-3)])),we<=s-2&&(xe=xe+Math.abs(h[U(we+2,we+1)])),we<=s-3&&(xe=xe+Math.abs(h[U(we+3,we+1)])),we<=s-4&&(xe=xe+Math.abs(h[U(we+4,we+1)]))),Math.abs(h[U(we+1,we)])<=Math.max(te,ge*xe)){const me=Math.max(Math.abs(h[U(we+1,we)]),Math.abs(h[U(we,we+1)])),be=Math.min(Math.abs(h[U(we+1,we)]),Math.abs(h[U(we,we+1)])),ve=Math.max(Math.abs(h[U(we+1,we+1)]),Math.abs(h[U(we,we)]-h[U(we+1,we+1)])),Be=Math.min(Math.abs(h[U(we+1,we+1)]),Math.abs(h[U(we,we)]-h[U(we+1,we+1)])),He=ve+me,je=Be*(ve/He);(je===0||be*(me/He)<=Math.max(te,ge*je))&&(h[U(we+1,we)]=0)}}}let ke;X?ke=Math.min(Se,s):e?ke=r:ke=s;for(let _e=Fe;_e>=Ge;_e--){const we=ye+2*(_e-1),Le=x[Z(1,_e)],oe=Le*x[Z(2,_e)],Q=Le*x[Z(3,_e)];for(let xe=Math.max(i,ye+2*_e);xe<=ke;xe++){const me=h[U(we+1,xe)]+x[Z(2,_e)]*h[U(we+2,xe)]+x[Z(3,_e)]*h[U(we+3,xe)];h[U(we+1,xe)]=h[U(we+1,xe)]-me*Le,h[U(we+2,xe)]=h[U(we+2,xe)]-me*oe,h[U(we+3,xe)]=h[U(we+3,xe)]-me*Q}}if(X)for(let _e=Fe;_e>=Ge;_e--){const Le=ye+2*(_e-1)-J;let oe=Math.max(1,i-J);oe=Math.max(oe,Le-(ye-J)+1);const Q=Math.min(fe,ye+2*(Fe-1)-J+5),xe=x[Z(1,_e)],me=xe*x[Z(2,_e)],be=xe*x[Z(3,_e)];for(let ve=oe;ve<=Q;ve++){const Be=E[ie(ve,Le+1)]+x[Z(2,_e)]*E[ie(ve,Le+2)]+x[Z(3,_e)]*E[ie(ve,Le+3)];E[ie(ve,Le+1)]=E[ie(ve,Le+1)]-Be*xe,E[ie(ve,Le+2)]=E[ie(ve,Le+2)]-Be*me,E[ie(ve,Le+3)]=E[ie(ve,Le+3)]-Be*be}}else if(t)for(let _e=Fe;_e>=Ge;_e--){const we=ye+2*(_e-1),Le=x[Z(1,_e)],oe=Le*x[Z(2,_e)],Q=Le*x[Z(3,_e)];for(let xe=p;xe<=m;xe++){const me=y[G(xe,we+1)]+x[Z(2,_e)]*y[G(xe,we+2)]+x[Z(3,_e)]*y[G(xe,we+3)];y[G(xe,we+1)]=y[G(xe,we+1)]-me*Le,y[G(xe,we+2)]=y[G(xe,we+2)]-me*oe,y[G(xe,we+3)]=y[G(xe,we+3)]-me*Q}}}if(X){let ye,Ge;e?(ye=1,Ge=r):(ye=i,Ge=s);const Fe=Math.max(1,i-J),Ue=fe-Math.max(0,Se-s)-Fe+1;for(let Ee=Math.min(Se,s)+1;Ee<=Ge;Ee+=j){const ke=Math.min(j,Ge-Ee+1);_r(Kn,Lt,Ue,ke,Ue,1,E,ie(Fe,Fe),k,h,U(J+Fe,Ee),d,0,V,O,P),xn(pw,Ue,ke,V,O,P,h,U(J+Fe,Ee),d)}for(let Ee=ye;Ee<=Math.max(i,J)-1;Ee+=R){const ke=Math.min(R,Math.max(i,J)-Ee);_r(Lt,Lt,ke,Ue,Ue,1,h,U(Ee,J+Fe),d,E,ie(Fe,Fe),k,0,B,F,L),xn(pw,ke,Ue,B,F,L,h,U(Ee,J+Fe),d)}if(t)for(let Ee=p;Ee<=m;Ee+=R){const ke=Math.min(R,m-Ee+1);_r(Lt,Lt,ke,Ue,Ue,1,y,G(Ee,J+Fe),b,E,ie(Fe,Fe),k,0,B,F,L),xn(pw,ke,Ue,B,F,L,y,G(Ee,J+Fe),b)}}}}const R_=-1;function c8(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x,S,M,E,T,k,R,B,F,L,j,V,O,P,N){const G=(ye,Ge)=>a+(ye-1)+(Ge-1)*l,Z=(ye,Ge)=>f+(ye-1)+(Ge-1)*d,ie=(ye,Ge)=>R+(ye-1)+(Ge-1)*B,Y=(ye,Ge)=>M+(ye-1)+(Ge-1)*E,ue=ye=>P+(ye-1);let ge=Math.min(s,i-r+1),te;if(ge<=2)te=1;else{gR(ge,1,ge-1,k,R,B,O,P,O,P,-1);const ye=Math.trunc(O[P]);l8(Pn,Lt,ge,ge,1,ge-1,k,R,B,O,P,S,M,E,O,P,-1);const Ge=Math.trunc(O[P]);rm(!0,!0,ge,1,ge,k,R,B,y,_,b,x,1,ge,S,M,E,O,P,-1);const Fe=Math.trunc(O[P]);te=Math.max(ge+Math.max(ye,Ge),Fe)}if(N===-1){O[P]=te;return}if(p.val=0,m.val=0,O[P]=1,r>i||s<1)return;const X=ei(Wo),de=ei(oh),fe=X*(n/de);ge=Math.min(s,i-r+1);const ae=i-ge+1;let J;if(ae===r?J=0:J=o[G(ae,ae-1)],i===ae){y[_+(ae-1)]=o[G(ae,ae)],b[x+(ae-1)]=0,p.val=1,m.val=0,Math.abs(J)<=Math.max(fe,de*Math.abs(o[G(ae,ae)]))&&(p.val=0,m.val=1,ae>r&&(o[G(ae,ae-1)]=0)),O[P]=1;return}xn(cn,ge,ge,o,G(ae,ae),l,k,R,B),rf(ge-1,o,G(ae+1,ae),l+1,k,ie(2,1),B+1),ls(R_,ge,ge,0,1,S,M,E);const K=Or(12,"DLAQR3","SV",ge,1);let Se;ge>K?Se=rm(!0,!0,ge,1,ge,k,R,B,y,_+(ae-1),b,x+(ae-1),1,ge,S,M,E,O,P,N):Se=M2(!0,!0,ge,1,ge,k,R,B,y,_+(ae-1),b,x+(ae-1),1,ge,S,M,E);for(let ye=1;ye<=ge-3;ye++)k[ie(ye+2,ye)]=0,k[ie(ye+3,ye)]=0;ge>2&&(k[ie(ge,ge-2)]=0);{let ye=ge,Ge=Se+1;for(;Ge<=ye;){let Fe;if(ye===1?Fe=!1:Fe=k[ie(ye,ye-1)]!==0,Fe){let Ue=Math.abs(k[ie(ye,ye)])+Math.sqrt(Math.abs(k[ie(ye,ye-1)]))*Math.sqrt(Math.abs(k[ie(ye-1,ye)]));if(Ue===0&&(Ue=Math.abs(J)),Math.max(Math.abs(J*S[Y(1,ye)]),Math.abs(J*S[Y(1,ye-1)]))<=Math.max(fe,de*Ue))ye=ye-2;else{const Ee={val:ye},ke={val:Ge};hT(1,ge,k,R,B,S,M,E,Ee,ke,O,P),Ge=ke.val+2}}else{let Ue=Math.abs(k[ie(ye,ye)]);if(Ue===0&&(Ue=Math.abs(J)),Math.abs(J*S[Y(1,ye)])<=Math.max(fe,de*Ue))ye=ye-1;else{const Ee={val:ye},ke={val:Ge};hT(1,ge,k,R,B,S,M,E,Ee,ke,O,P),Ge=ke.val+1}}}if(ye===0&&(J=0),ye<ge){let Fe=!1,Ue=ye+1;for(;!Fe;){Fe=!0;const Ee=Ue-1;Ue=Se+1;let ke;for(Ue===ye||k[ie(Ue+1,Ue)]===0?ke=Ue+1:ke=Ue+2;ke<=Ee;){let _e;ke===Ue+1?_e=Math.abs(k[ie(Ue,Ue)]):_e=Math.abs(k[ie(Ue,Ue)])+Math.sqrt(Math.abs(k[ie(Ue+1,Ue)]))*Math.sqrt(Math.abs(k[ie(Ue,Ue+1)]));let we;if(ke===Ee||k[ie(ke+1,ke)]===0?we=Math.abs(k[ie(ke,ke)]):we=Math.abs(k[ie(ke,ke)])+Math.sqrt(Math.abs(k[ie(ke+1,ke)]))*Math.sqrt(Math.abs(k[ie(ke,ke+1)])),_e>=we)Ue=ke;else{Fe=!1;const Le={val:Ue},oe={val:ke};hT(1,ge,k,R,B,S,M,E,Le,oe,O,P)===0?Ue=oe.val:Ue=ke}Ue===Ee||k[ie(Ue+1,Ue)]===0?ke=Ue+1:ke=Ue+2}}}{let Fe=ge;for(;Fe>=Se+1;)if(Fe===Se+1)y[_+(ae+Fe-2)]=k[ie(Fe,Fe)],b[x+(ae+Fe-2)]=0,Fe=Fe-1;else if(k[ie(Fe,Fe-1)]===0)y[_+(ae+Fe-2)]=k[ie(Fe,Fe)],b[x+(ae+Fe-2)]=0,Fe=Fe-1;else{const Ue=k[ie(Fe-1,Fe-1)],Ee=k[ie(Fe,Fe-1)],ke=k[ie(Fe-1,Fe)],_e=k[ie(Fe,Fe)],we=i1(Ue,ke,Ee,_e);y[_+(ae+Fe-3)]=we.rt1r,b[x+(ae+Fe-3)]=we.rt1i,y[_+(ae+Fe-2)]=we.rt2r,b[x+(ae+Fe-2)]=we.rt2i,Fe=Fe-2}}if(ye<ge||J===0){if(ye>1&&J!==0){rf(ye,S,M,E,O,P,1);let Ue=O[P];const Ee=Rs(ye,Ue,O,P+1,1);Ue=Ee.alpha;const ke=Ee.tau;ls(Un,ge-2,ge-2,0,0,k,ie(3,1),B),ul(Rr,ye,ge,O,P,1,ke,k,R,B,O,ue(ge+1)),ul(Pn,ye,ye,O,P,1,ke,k,R,B,O,ue(ge+1)),ul(Pn,ge,ye,O,P,1,ke,S,M,E,O,ue(ge+1)),gR(ge,1,ye,k,R,B,O,P,O,ue(ge+1),N-ge)}ae>1&&(o[G(ae,ae-1)]=J*S[Y(1,1)]),xn(cn,ge,ge,k,R,B,o,G(ae,ae),l),rf(ge-1,k,ie(2,1),B+1,o,G(ae+1,ae),l+1),ye>1&&J!==0&&l8(Pn,Lt,ge,ye,1,ye,k,R,B,O,P,S,M,E,O,ue(ge+1),N-ge);let Fe;e?Fe=1:Fe=r;for(let Ue=Fe;Ue<=ae-1;Ue+=F){const Ee=Math.min(F,ae-Ue);_r(Lt,Lt,Ee,ge,ge,1,o,G(Ue,ae),l,S,M,E,0,L,j,V),xn(R_,Ee,ge,L,j,V,o,G(Ue,ae),l)}if(e)for(let Ue=i+1;Ue<=n;Ue+=T){const Ee=Math.min(T,n-Ue+1);_r(Kn,Lt,ge,Ee,ge,1,S,M,E,o,G(ae,Ue),l,0,k,R,B),xn(R_,ge,Ee,k,R,B,o,G(ae,Ue),l)}if(t)for(let Ue=c;Ue<=u;Ue+=F){const Ee=Math.min(F,u-Ue+1);_r(Lt,Lt,Ee,ge,ge,1,h,Z(Ue,ae),d,S,M,E,0,L,j,V),xn(R_,Ee,ge,L,j,V,h,Z(Ue,ae),d)}}m.val=ge-ye,p.val=ye-Se}O[P]=te}function rm(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x){const F=(P,N)=>o+(P-1)+(N-1)*a,L=P=>c+(P-1),j=P=>h+(P-1);let V=0,O=1;if(n===0)return _[b]=1,0;if(n<=15)O=1,x!==-1&&(V=M2(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y));else{V=0;let P;e?P="S":P="E",t?P+="V":P+="N";let N=Or(13,"DLAQR0",P,n,r);N=Math.max(2,N),N=Math.min(i-r+1,Math.trunc((n-1)/3),N);let H=Or(15,"DLAQR0",P,n,r);H=Math.min(H,Math.trunc((n-3)/6),i-r),H=Math.max(2,H-H%2);const U={val:0},G={val:0};if(c8(e,t,n,r,i,N+1,s,o,a,f,d,p,m,y,U,G,l,c,u,h,s,o,a,n,s,o,a,n,s,o,a,_,b,-1),O=Math.max(Math.trunc(3*H/2),Math.trunc(_[b])),x===-1)return _[b]=O,0;let Z=Or(12,"DLAQR0",P,n,r);Z=Math.max(15,Z);let ie=Or(14,"DLAQR0",P,n,r);ie=Math.max(0,ie);let Y=Or(16,"DLAQR0",P,n,r);Y=Math.max(0,Y),Y=Math.min(2,Y);const ue=Math.min(Math.trunc((n-1)/3),Math.trunc(x/2));let ge=ue,te=Math.min(Math.trunc((n-3)/6),Math.trunc(2*x/3));te=te-te%2;let X=1;const de=Math.max(30,12)*Math.max(10,i-r+1);let fe=i,ae=-1;const J=D(1);for(let K=1;K<=de;K++){if(fe<r)return _[b]=O,V;let Se;{let Q;for(Q=fe;Q>=r+1&&s[F(Q,Q-1)]!==0;Q--);Q<r+1&&(Q=r),Se=Q}const ye=fe-Se+1,Ge=Math.min(ye,ue);if(X<5?ge=Math.min(Ge,N):ge=Math.min(Ge,2*ge),ge<ue)if(ge>=ye-1)ge=ye;else{const Q=fe-ge+1;Math.abs(s[F(Q,Q-1)])>Math.abs(s[F(Q-1,Q-2)])&&(ge=ge+1)}X<5?ae=-1:(ae>=0||ge>=Ge)&&(ae=ae+1,ge-ae<2&&(ae=0),ge=ge-ae);const Fe=n-ge+1,Ue=ge+1,Ee=n-ge-1-Ue+1,ke=ge+2,_e=n-ge-ke+1,we={val:0},Le={val:0};c8(e,t,n,Se,fe,ge,s,o,a,f,d,p,m,y,we,Le,l,c,u,h,s,F(Fe,1),a,Ee,s,F(Fe,Ue),a,_e,s,F(ke,1),a,_,b,x),fe=fe-Le.val;let oe=fe-we.val+1;if(Le.val===0||100*Le.val<=ge*ie&&fe-Se+1>Math.min(Z,ue)){let Q=Math.min(te,H,Math.max(2,fe-Se));if(Q=Q-Q%2,X%6===0){oe=fe-Q+1;for(let je=fe;je>=Math.max(oe+1,Se+2);je-=2){const st=Math.abs(s[F(je,je-1)])+Math.abs(s[F(je-1,je-2)]),We=.75*st+s[F(je,je)],ct=st,kt=-.4375*st,at=i1(We,ct,kt,We);l[L(je-1)]=at.rt1r,u[j(je-1)]=at.rt1i,l[L(je)]=at.rt2r,u[j(je)]=at.rt2i}oe===Se&&(l[L(oe+1)]=s[F(oe+1,oe+1)],u[j(oe+1)]=0,l[L(oe)]=l[L(oe+1)],u[j(oe)]=u[j(oe+1)])}else{if(fe-oe+1<=Math.trunc(Q/2)){oe=fe-Q+1;const je=n-Q+1;xn(R_,Q,Q,s,F(oe,oe),a,s,F(je,1),a);let st;if(Q>Z?st=rm(!1,!1,Q,1,Q,s,F(je,1),a,l,L(oe),u,j(oe),1,1,J,0,1,_,b,x):st=M2(!1,!1,Q,1,Q,s,F(je,1),a,l,L(oe),u,j(oe),1,1,J,0,1),oe=oe+st,oe>=fe){const We=s[F(fe-1,fe-1)],ct=s[F(fe,fe-1)],kt=s[F(fe-1,fe)],rt=s[F(fe,fe)],at=i1(We,kt,ct,rt);l[L(fe-1)]=at.rt1r,u[j(fe-1)]=at.rt1i,l[L(fe)]=at.rt2r,u[j(fe)]=at.rt2i,oe=fe-1}}if(fe-oe+1>Q){let je=!1;for(let st=fe;st>=oe+1&&!je;st--){je=!0;for(let We=oe;We<=st-1;We++)if(Math.abs(l[L(We)])+Math.abs(u[j(We)])<Math.abs(l[L(We+1)])+Math.abs(u[j(We+1)])){je=!1;let ct;ct=l[L(We)],l[L(We)]=l[L(We+1)],l[L(We+1)]=ct,ct=u[j(We)],u[j(We)]=u[j(We+1)],u[j(We+1)]=ct}}}for(let je=fe;je>=oe+2;je-=2)if(u[j(je)]!==-u[j(je-1)]){let st;st=l[L(je)],l[L(je)]=l[L(je-1)],l[L(je-1)]=l[L(je-2)],l[L(je-2)]=st,st=u[j(je)],u[j(je)]=u[j(je-1)],u[j(je-1)]=u[j(je-2)],u[j(je-2)]=st}}fe-oe+1===2&&u[j(fe)]===0&&(Math.abs(l[L(fe)]-s[F(fe,fe)])<Math.abs(l[L(fe-1)]-s[F(fe,fe)])?l[L(fe-1)]=l[L(fe)]:l[L(fe)]=l[L(fe-1)]),Q=Math.min(Q,fe-oe+1),Q=Q-Q%2,oe=fe-Q+1;const xe=2*Q,me=n-xe+1,be=xe+1,ve=n-xe+1-4-(xe+1)+1,Be=xe+4,He=n-xe-Be+1;ghe(e,t,Y,n,Se,fe,Q,l,L(oe),u,j(oe),s,o,a,f,d,p,m,y,_,b,3,s,F(me,1),a,He,s,F(Be,1),a,ve,s,F(me,be),a)}Le.val>0?X=1:X=X+1}V=fe}return _[b]=O,V}const mw=-1;function Og(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_){const E=(L,j)=>o+(L-1)+(j-1)*a,T=e===1,k=t===1,R=k||t===2,B=_===-1;m[y]=Math.max(1,n);let F=0;if(e!==0&&e!==1?F=-1:t!==0&&t!==1&&t!==2?F=-2:n<0?F=-3:r<1||r>Math.max(1,n)?F=-4:i<Math.min(r,n)||i>n?F=-5:a<Math.max(1,n)?F=-7:p<1||R&&p<Math.max(1,n)?F=-11:_<Math.max(1,n)&&!B&&(F=-13),F!==0)return F;if(n===0)return 0;if(B)return rm(T,R,n,r,i,s,o,a,l,c,u,h,r,i,f,d,p,m,y,_),m[y]=Math.max(Math.max(1,n),m[y]),0;{for(let j=1;j<=r-1;j++)l[c+(j-1)]=s[E(j,j)],u[h+(j-1)]=0;for(let j=i+1;j<=n;j++)l[c+(j-1)]=s[E(j,j)],u[h+(j-1)]=0;if(k&&ls(mw,n,n,0,1,f,d,p),r===i)return l[c+(r-1)]=s[E(r,r)],u[h+(r-1)]=0,0;let L=Or(12,"DHSEQR","EN",n,r);if(L=Math.max(15,L),n>L)F=rm(T,R,n,r,i,s,o,a,l,c,u,h,r,i,f,d,p,m,y,_);else if(F=M2(T,R,n,r,i,s,o,a,l,c,u,h,r,i,f,d,p),F>0){const j=F;if(n>=49)F=rm(T,R,n,r,j,s,o,a,l,c,u,h,r,i,f,d,p,m,y,_);else{const V=D(2401),O=D(49);xn(mw,n,n,s,o,a,V,0,49),V[n+(n-1)*49]=0,ls(mw,49,49-n,0,0,V,n*49,49),F=rm(T,R,49,r,j,V,0,49,l,c,u,h,r,i,f,d,p,O,0,49),(T||F!==0)&&xn(mw,n,n,V,0,49,s,o,a)}}(T||F!==0)&&n>2&&ls(Un,n-2,n-2,0,0,s,E(3,1),a),m[y]=Math.max(Math.max(1,n),m[y])}return F}function u8(e,t,n,r){let a=e,l=t,c=n,u=r;const h=Math.max(Math.abs(e),Math.abs(t)),f=Math.max(Math.abs(n),Math.abs(r));let d=1;const p=ei(HL),m=ei(Wo),y=ei(N1),_=2/(y*y);h>=.5*p&&(a=.5*a,l=.5*l,d=2*d),f>=.5*p&&(c=.5*c,u=.5*u,d=.5*d),h<=m*2/y&&(a=a*_,l=l*_,d=d/_),f<=m*2/y&&(c=c*_,u=u*_,d=d*_);let b,x;return Math.abs(u)<=Math.abs(c)?{p:b,q:x}=h8(a,l,c,u):({p:b,q:x}=h8(l,a,u,c),x=-x),b=b*d,x=x*d,{p:b,q:x}}function h8(e,t,n,r){const s=r/n,o=1/(n+r*s),a=f8(e,t,n,r,s,o),l=f8(t,-e,n,r,s,o);return{p:a,q:l}}function f8(e,t,n,r,i,s){if(i!==0){const a=t*i;return a!==0?(e+a)*s:e*s+t*s*i}else return(e+r*(t/n))*s}const d8=[!1,!1,!0,!0],p8=[!1,!0,!1,!0],Ph=[[1,2,3,4],[2,1,4,3],[3,4,1,2],[4,3,2,1]];function od(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_){const M=(O,P)=>s[o+(O-1)+(P-1)*a],E=(O,P)=>u[h+(O-1)+(P-1)*f],T=(O,P,N)=>{m[y+(O-1)+(P-1)*_]=N},k=(O,P)=>m[y+(O-1)+(P-1)*_],R=2*ei(Wo),B=1/R,F=Math.max(r,R);let L=0,j=1,V;if(t===1)if(n===1){let O=i*M(1,1)-d*l,P=Math.abs(O);P<F&&(O=F,P=F,L=1);const N=Math.abs(E(1,1));P<1&&N>1&&N>B*P&&(j=1/N),T(1,1,E(1,1)*j/O),V=Math.abs(k(1,1))}else{let O=i*M(1,1)-d*l,P=-p*l,N=Math.abs(O)+Math.abs(P);N<F&&(O=F,P=0,N=F,L=1);const H=Math.abs(E(1,1))+Math.abs(E(1,2));N<1&&H>1&&H>B*N&&(j=1/H);const U=u8(j*E(1,1),j*E(1,2),O,P);T(1,1,U.p),T(1,2,U.q),V=Math.abs(k(1,1))+Math.abs(k(1,2))}else{const O=D(4),P=D(4);if(O[0]=i*M(1,1)-d*l,O[3]=i*M(2,2)-d*c,e?(O[2]=i*M(2,1),O[1]=i*M(1,2)):(O[1]=i*M(2,1),O[2]=i*M(1,2)),n===1){let N=0,H=0;for(let J=0;J<4;J++)Math.abs(O[J])>N&&(N=Math.abs(O[J]),H=J+1);if(N<F){const J=Math.max(Math.abs(E(1,1)),Math.abs(E(2,1)));F<1&&J>1&&J>B*F&&(j=1/J);const K=j/F;return T(1,1,K*E(1,1)),T(2,1,K*E(2,1)),V=K*J,L=1,{scale:j,xnorm:V,info:L}}const U=O[H-1],G=O[Ph[H-1][1]-1],Z=O[Ph[H-1][2]-1],ie=O[Ph[H-1][3]-1],Y=1/U,ue=Y*G;let ge=ie-Z*ue;Math.abs(ge)<F&&(ge=F,L=1);let te,X;p8[H-1]?(te=E(2,1),X=E(1,1)):(te=E(1,1),X=E(2,1)),X=X-ue*te;const de=Math.max(Math.abs(te*(ge*Y)),Math.abs(X));de>1&&Math.abs(ge)<1&&de>=B*Math.abs(ge)&&(j=1/de);const fe=X*j/ge,ae=j*te*Y-fe*(Y*Z);if(d8[H-1]?(T(1,1,fe),T(2,1,ae)):(T(1,1,ae),T(2,1,fe)),V=Math.max(Math.abs(ae),Math.abs(fe)),V>1&&N>1&&V>B/N){const J=N/B;T(1,1,J*k(1,1)),T(2,1,J*k(2,1)),V=J*V,j=J*j}}else{P[0]=-p*l,P[1]=0,P[2]=0,P[3]=-p*c;let N=0,H=0;for(let me=0;me<4;me++)Math.abs(O[me])+Math.abs(P[me])>N&&(N=Math.abs(O[me])+Math.abs(P[me]),H=me+1);if(N<F){const me=Math.max(Math.abs(E(1,1))+Math.abs(E(1,2)),Math.abs(E(2,1))+Math.abs(E(2,2)));F<1&&me>1&&me>B*F&&(j=1/me);const be=j/F;return T(1,1,be*E(1,1)),T(2,1,be*E(2,1)),T(1,2,be*E(1,2)),T(2,2,be*E(2,2)),V=be*me,L=1,{scale:j,xnorm:V,info:L}}const U=O[H-1],G=P[H-1],Z=O[Ph[H-1][1]-1],ie=P[Ph[H-1][1]-1],Y=O[Ph[H-1][2]-1],ue=P[Ph[H-1][2]-1],ge=O[Ph[H-1][3]-1],te=P[Ph[H-1][3]-1];let X,de,fe,ae,J,K,Se,ye;if(H===1||H===4){if(Math.abs(U)>Math.abs(G)){const me=G/U;X=1/(U*(1+me*me)),de=-me*X}else{const me=U/G;de=-1/(G*(1+me*me)),X=-me*de}fe=Z*X,ae=Z*de,J=Y*X,K=Y*de,Se=ge-Y*fe,ye=te-Y*ae}else X=1/U,de=0,fe=Z*X,ae=ie*X,J=Y*X,K=ue*X,Se=ge-Y*fe+ue*ae,ye=-Y*ae-ue*fe;let Ge=Math.abs(Se)+Math.abs(ye);Ge<F&&(Se=F,ye=0,L=1);let Fe,Ue,Ee,ke;p8[H-1]?(Ue=E(1,1),Fe=E(2,1),ke=E(1,2),Ee=E(2,2)):(Fe=E(1,1),Ue=E(2,1),Ee=E(1,2),ke=E(2,2)),Ue=Ue-fe*Fe+ae*Ee,ke=ke-ae*Fe-fe*Ee,Ge=Math.abs(Se)+Math.abs(ye);const _e=Math.max((Math.abs(Fe)+Math.abs(Ee))*(Ge*(Math.abs(X)+Math.abs(de))),Math.abs(Ue)+Math.abs(ke));_e>1&&Ge<1&&_e>=B*Ge&&(j=1/_e,Fe=j*Fe,Ee=j*Ee,Ue=j*Ue,ke=j*ke);const we=u8(Ue,ke,Se,ye),Le=we.p,oe=we.q,Q=X*Fe-de*Ee-J*Le+K*oe,xe=de*Fe+X*Ee-K*Le-J*oe;if(d8[H-1]?(T(1,1,Le),T(2,1,Q),T(1,2,oe),T(2,2,xe)):(T(1,1,Q),T(2,1,Le),T(1,2,xe),T(2,2,oe)),V=Math.max(Math.abs(Q)+Math.abs(xe),Math.abs(Le)+Math.abs(oe)),V>1&&N>1&&V>B/N){const me=N/B;T(1,1,me*k(1,1)),T(2,1,me*k(2,1)),T(1,2,me*k(1,2)),T(2,2,me*k(2,2)),V=me*V,j=me*j}}}return{scale:j,xnorm:V,info:L}}function Bc(e,t,n,r,i,s,o){let a=0;if(e<=0)return 0;if(r===1&&o===1){const l=e%5;if(l!==0){for(let u=1;u<=l;u++)a+=t[n+(u-1)]*i[s+(u-1)];if(e<5)return a}const c=l+1;for(let u=c;u<=e;u+=5)a+=t[n+(u-1)]*i[s+(u-1)]+t[n+u]*i[s+u]+t[n+(u+1)]*i[s+(u+1)]+t[n+(u+2)]*i[s+(u+2)]+t[n+(u+3)]*i[s+(u+3)]}else{let l=1,c=1;r<0&&(l=(-e+1)*r+1),o<0&&(c=(-e+1)*o+1);for(let u=1;u<=e;u++)a+=t[n+(l-1)]*i[s+(c-1)],l+=r,c+=o}return a}const yhe=2,_he=8,dT=128;function pT(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y){const x=e===yhe,S=e===Pn||x,M=e===Rr||x;let E=0,T=dT;const k=Math.max(1,r+2*r*T);p[m]=k;const R=y===-1;!S&&!M?E=-1:r<0?E=-4:o<Math.max(1,r)?E=-6:c<1||M&&c<r?E=-8:f<1||S&&f<r?E=-10:y<Math.max(1,3*r)&&!R&&(E=-14);let B=0;if(E===0&&(B=r,d<B&&(E=-11)),E!==0)return{m:0,info:E};if(R)return{m:B,info:0};if(r===0)return{m:B,info:0};y>=r+2*r*_he?(T=Math.floor((y-r)/(2*r)),T=Math.min(T,dT),ls(-1,r,1+2*T,0,0,p,m,r)):T=1;const F=ei(Wo),L=ei(oh),j=F*(r/L),V=(1-L)/j;p[m]=0;for(let N=2;N<=r;N++){p[m+(N-1)]=0;for(let H=1;H<=N-1;H++)p[m+(N-1)]+=Math.abs(i[s+(H-1)+(N-1)*o])}const O=D(4),P=new Int32Array(dT);if(S){let N=2;T>2&&(N=T);let H=0;for(let U=r;U>=1;U--){if(H===-1){H=1;continue}else U===1||i[s+(U-1)+(U-2)*o]===0?H=0:H=-1;const G=i[s+(U-1)+(U-1)*o];let Z=0;H!==0&&(Z=Math.sqrt(Math.abs(i[s+(U-1)+(U-2)*o]))*Math.sqrt(Math.abs(i[s+(U-2)+(U-1)*o])));const ie=Math.max(L*(Math.abs(G)+Math.abs(Z)),j);if(H===0){p[m+(U-1)+N*r]=1;for(let ue=1;ue<=U-1;ue++)p[m+(ue-1)+N*r]=-i[s+(ue-1)+(U-1)*o];let Y=U-1;for(let ue=U-1;ue>=1;ue--){if(ue>Y)continue;let ge=ue;const te=ue;if(Y=ue-1,ue>1&&i[s+(ue-1)+(ue-2)*o]!==0&&(ge=ue-1,Y=ue-2),ge===te){const X=od(!1,1,1,ie,1,i,s+(ue-1)+(ue-1)*o,o,1,1,p,m+(ue-1)+N*r,r,G,0,O,0,2);let de=X.scale;const fe=X.xnorm;fe>1&&p[m+(ue-1)]>V/fe&&(O[0]=O[0]/fe,de=de/fe),de!==1&&zn(U,de,p,m+N*r,1),p[m+(ue-1)+N*r]=O[0],Wa(ue-1,-O[0],i,s+(ue-1)*o,1,p,m+N*r,1)}else{const X=od(!1,2,1,ie,1,i,s+(ue-2)+(ue-2)*o,o,1,1,p,m+(ue-2)+N*r,r,G,0,O,0,2);let de=X.scale;const fe=X.xnorm;fe>1&&Math.max(p[m+(ue-2)],p[m+(ue-1)])>V/fe&&(O[0]=O[0]/fe,O[1]=O[1]/fe,de=de/fe),de!==1&&zn(U,de,p,m+N*r,1),p[m+(ue-2)+N*r]=O[0],p[m+(ue-1)+N*r]=O[1],Wa(ue-2,-O[0],i,s+(ue-2)*o,1,p,m+N*r,1),Wa(ue-2,-O[1],i,s+(ue-1)*o,1,p,m+N*r,1)}}if(T===1){U>1&&Yn(Lt,r,U-1,1,u,h,f,p,m+N*r,1,p[m+(U-1)+N*r],u,h+(U-1)*f,1);const ue=tf(r,u,h+(U-1)*f,1),ge=1/Math.abs(u[h+(ue-1)+(U-1)*f]);zn(r,ge,u,h+(U-1)*f,1)}else{for(let ue=U+1;ue<=r;ue++)p[m+(ue-1)+N*r]=0;P[N-1]=H}}else{Math.abs(i[s+(U-2)+(U-1)*o])>=Math.abs(i[s+(U-1)+(U-2)*o])?(p[m+(U-2)+(N-1)*r]=1,p[m+(U-1)+N*r]=Z/i[s+(U-2)+(U-1)*o]):(p[m+(U-2)+(N-1)*r]=-Z/i[s+(U-1)+(U-2)*o],p[m+(U-1)+N*r]=1),p[m+(U-1)+(N-1)*r]=0,p[m+(U-2)+N*r]=0;for(let ue=1;ue<=U-2;ue++)p[m+(ue-1)+(N-1)*r]=-p[m+(U-2)+(N-1)*r]*i[s+(ue-1)+(U-2)*o],p[m+(ue-1)+N*r]=-p[m+(U-1)+N*r]*i[s+(ue-1)+(U-1)*o];let Y=U-2;for(let ue=U-2;ue>=1;ue--){if(ue>Y)continue;let ge=ue;const te=ue;if(Y=ue-1,ue>1&&i[s+(ue-1)+(ue-2)*o]!==0&&(ge=ue-1,Y=ue-2),ge===te){const X=od(!1,1,2,ie,1,i,s+(ue-1)+(ue-1)*o,o,1,1,p,m+(ue-1)+(N-1)*r,r,G,Z,O,0,2);let de=X.scale;const fe=X.xnorm;fe>1&&p[m+(ue-1)]>V/fe&&(O[0]=O[0]/fe,O[2]=O[2]/fe,de=de/fe),de!==1&&(zn(U,de,p,m+(N-1)*r,1),zn(U,de,p,m+N*r,1)),p[m+(ue-1)+(N-1)*r]=O[0],p[m+(ue-1)+N*r]=O[2],Wa(ue-1,-O[0],i,s+(ue-1)*o,1,p,m+(N-1)*r,1),Wa(ue-1,-O[2],i,s+(ue-1)*o,1,p,m+N*r,1)}else{const X=od(!1,2,2,ie,1,i,s+(ue-2)+(ue-2)*o,o,1,1,p,m+(ue-2)+(N-1)*r,r,G,Z,O,0,2);let de=X.scale;const fe=X.xnorm;if(fe>1&&Math.max(p[m+(ue-2)],p[m+(ue-1)])>V/fe){const J=1/fe;O[0]=O[0]*J,O[2]=O[2]*J,O[1]=O[1]*J,O[3]=O[3]*J,de=de*J}de!==1&&(zn(U,de,p,m+(N-1)*r,1),zn(U,de,p,m+N*r,1)),p[m+(ue-2)+(N-1)*r]=O[0],p[m+(ue-1)+(N-1)*r]=O[1],p[m+(ue-2)+N*r]=O[2],p[m+(ue-1)+N*r]=O[3],Wa(ue-2,-O[0],i,s+(ue-2)*o,1,p,m+(N-1)*r,1),Wa(ue-2,-O[1],i,s+(ue-1)*o,1,p,m+(N-1)*r,1),Wa(ue-2,-O[2],i,s+(ue-2)*o,1,p,m+N*r,1),Wa(ue-2,-O[3],i,s+(ue-1)*o,1,p,m+N*r,1)}}if(T===1){U>2?(Yn(Lt,r,U-2,1,u,h,f,p,m+(N-1)*r,1,p[m+(U-2)+(N-1)*r],u,h+(U-2)*f,1),Yn(Lt,r,U-2,1,u,h,f,p,m+N*r,1,p[m+(U-1)+N*r],u,h+(U-1)*f,1)):(zn(r,p[m+(U-2)+(N-1)*r],u,h+(U-2)*f,1),zn(r,p[m+(U-1)+N*r],u,h+(U-1)*f,1));let ue=0;for(let te=1;te<=r;te++)ue=Math.max(ue,Math.abs(u[h+(te-1)+(U-2)*f])+Math.abs(u[h+(te-1)+(U-1)*f]));const ge=1/ue;zn(r,ge,u,h+(U-2)*f,1),zn(r,ge,u,h+(U-1)*f,1)}else{for(let ue=U+1;ue<=r;ue++)p[m+(ue-1)+(N-1)*r]=0,p[m+(ue-1)+N*r]=0;P[N-2]=-H,P[N-1]=H,N=N-1}}if(T>1){let Y;if(H===0?Y=U:Y=U-1,N<=2||Y===1){_r(Lt,Lt,r,T-N+1,Y+T-N,1,u,h,f,p,m+N*r,r,0,p,m+(T+N)*r,r);let ue=1;for(let ge=N;ge<=T;ge++){if(P[ge-1]===0){const te=tf(r,p,m+(T+ge)*r,1);ue=1/Math.abs(p[m+(te-1)+(T+ge)*r])}else if(P[ge-1]===1){let te=0;for(let X=1;X<=r;X++)te=Math.max(te,Math.abs(p[m+(X-1)+(T+ge)*r])+Math.abs(p[m+(X-1)+(T+ge+1)*r]));ue=1/te}zn(r,ue,p,m+(T+ge)*r,1)}xn(-1,r,T-N+1,p,m+(T+N)*r,r,u,h+(Y-1)*f,f),N=T}else N=N-1}}}if(M){let N=1,H=0;for(let U=1;U<=r;U++){if(H===1){H=-1;continue}else U===r||i[s+U+(U-1)*o]===0?H=0:H=1;const G=i[s+(U-1)+(U-1)*o];let Z=0;H!==0&&(Z=Math.sqrt(Math.abs(i[s+(U-1)+U*o]))*Math.sqrt(Math.abs(i[s+U+(U-1)*o])));const ie=Math.max(L*(Math.abs(G)+Math.abs(Z)),j);if(H===0){p[m+(U-1)+N*r]=1;for(let te=U+1;te<=r;te++)p[m+(te-1)+N*r]=-i[s+(U-1)+(te-1)*o];let Y=1,ue=V,ge=U+1;for(let te=U+1;te<=r;te++){if(te<ge)continue;const X=te;let de=te;if(ge=te+1,te<r&&i[s+te+(te-1)*o]!==0&&(de=te+1,ge=te+2),X===de){if(p[m+(te-1)]>ue){const J=1/Y;zn(r-U+1,J,p,m+(U-1)+N*r,1),Y=1,ue=V}p[m+(te-1)+N*r]-=Bc(te-U-1,i,s+U+(te-1)*o,1,p,m+U+N*r,1);const ae=od(!1,1,1,ie,1,i,s+(te-1)+(te-1)*o,o,1,1,p,m+(te-1)+N*r,r,G,0,O,0,2).scale;ae!==1&&zn(r-U+1,ae,p,m+(U-1)+N*r,1),p[m+(te-1)+N*r]=O[0],Y=Math.max(Math.abs(p[m+(te-1)+N*r]),Y),ue=V/Y}else{if(Math.max(p[m+(te-1)],p[m+te])>ue){const K=1/Y;zn(r-U+1,K,p,m+(U-1)+N*r,1),Y=1,ue=V}p[m+(te-1)+N*r]-=Bc(te-U-1,i,s+U+(te-1)*o,1,p,m+U+N*r,1),p[m+te+N*r]-=Bc(te-U-1,i,s+U+te*o,1,p,m+U+N*r,1);const J=od(!0,2,1,ie,1,i,s+(te-1)+(te-1)*o,o,1,1,p,m+(te-1)+N*r,r,G,0,O,0,2).scale;J!==1&&zn(r-U+1,J,p,m+(U-1)+N*r,1),p[m+(te-1)+N*r]=O[0],p[m+te+N*r]=O[1],Y=Math.max(Math.abs(p[m+(te-1)+N*r]),Math.abs(p[m+te+N*r]),Y),ue=V/Y}}if(T===1){U<r&&Yn(Lt,r,r-U,1,a,l+U*c,c,p,m+U+N*r,1,p[m+(U-1)+N*r],a,l+(U-1)*c,1);const te=tf(r,a,l+(U-1)*c,1),X=1/Math.abs(a[l+(te-1)+(U-1)*c]);zn(r,X,a,l+(U-1)*c,1)}else{for(let te=1;te<=U-1;te++)p[m+(te-1)+N*r]=0;P[N-1]=H}}else{Math.abs(i[s+(U-1)+U*o])>=Math.abs(i[s+U+(U-1)*o])?(p[m+(U-1)+N*r]=Z/i[s+(U-1)+U*o],p[m+U+(N+1)*r]=1):(p[m+(U-1)+N*r]=1,p[m+U+(N+1)*r]=-Z/i[s+U+(U-1)*o]),p[m+U+N*r]=0,p[m+(U-1)+(N+1)*r]=0;for(let te=U+2;te<=r;te++)p[m+(te-1)+N*r]=-p[m+(U-1)+N*r]*i[s+(U-1)+(te-1)*o],p[m+(te-1)+(N+1)*r]=-p[m+U+(N+1)*r]*i[s+U+(te-1)*o];let Y=1,ue=V,ge=U+2;for(let te=U+2;te<=r;te++){if(te<ge)continue;const X=te;let de=te;if(ge=te+1,te<r&&i[s+te+(te-1)*o]!==0&&(de=te+1,ge=te+2),X===de){if(p[m+(te-1)]>ue){const J=1/Y;zn(r-U+1,J,p,m+(U-1)+N*r,1),zn(r-U+1,J,p,m+(U-1)+(N+1)*r,1),Y=1,ue=V}p[m+(te-1)+N*r]-=Bc(te-U-2,i,s+(U+1)+(te-1)*o,1,p,m+(U+1)+N*r,1),p[m+(te-1)+(N+1)*r]-=Bc(te-U-2,i,s+(U+1)+(te-1)*o,1,p,m+(U+1)+(N+1)*r,1);const ae=od(!1,1,2,ie,1,i,s+(te-1)+(te-1)*o,o,1,1,p,m+(te-1)+N*r,r,G,-Z,O,0,2).scale;ae!==1&&(zn(r-U+1,ae,p,m+(U-1)+N*r,1),zn(r-U+1,ae,p,m+(U-1)+(N+1)*r,1)),p[m+(te-1)+N*r]=O[0],p[m+(te-1)+(N+1)*r]=O[2],Y=Math.max(Math.abs(p[m+(te-1)+N*r]),Math.abs(p[m+(te-1)+(N+1)*r]),Y),ue=V/Y}else{if(Math.max(p[m+(te-1)],p[m+te])>ue){const K=1/Y;zn(r-U+1,K,p,m+(U-1)+N*r,1),zn(r-U+1,K,p,m+(U-1)+(N+1)*r,1),Y=1,ue=V}p[m+(te-1)+N*r]-=Bc(te-U-2,i,s+(U+1)+(te-1)*o,1,p,m+(U+1)+N*r,1),p[m+(te-1)+(N+1)*r]-=Bc(te-U-2,i,s+(U+1)+(te-1)*o,1,p,m+(U+1)+(N+1)*r,1),p[m+te+N*r]-=Bc(te-U-2,i,s+(U+1)+te*o,1,p,m+(U+1)+N*r,1),p[m+te+(N+1)*r]-=Bc(te-U-2,i,s+(U+1)+te*o,1,p,m+(U+1)+(N+1)*r,1);const J=od(!0,2,2,ie,1,i,s+(te-1)+(te-1)*o,o,1,1,p,m+(te-1)+N*r,r,G,-Z,O,0,2).scale;J!==1&&(zn(r-U+1,J,p,m+(U-1)+N*r,1),zn(r-U+1,J,p,m+(U-1)+(N+1)*r,1)),p[m+(te-1)+N*r]=O[0],p[m+(te-1)+(N+1)*r]=O[2],p[m+te+N*r]=O[1],p[m+te+(N+1)*r]=O[3],Y=Math.max(Math.abs(O[0]),Math.abs(O[2]),Math.abs(O[1]),Math.abs(O[3]),Y),ue=V/Y}}if(T===1){U<r-1?(Yn(Lt,r,r-U-1,1,a,l+(U+1)*c,c,p,m+(U+1)+N*r,1,p[m+(U-1)+N*r],a,l+(U-1)*c,1),Yn(Lt,r,r-U-1,1,a,l+(U+1)*c,c,p,m+(U+1)+(N+1)*r,1,p[m+U+(N+1)*r],a,l+U*c,1)):(zn(r,p[m+(U-1)+N*r],a,l+(U-1)*c,1),zn(r,p[m+U+(N+1)*r],a,l+U*c,1));let te=0;for(let de=1;de<=r;de++)te=Math.max(te,Math.abs(a[l+(de-1)+(U-1)*c])+Math.abs(a[l+(de-1)+U*c]));const X=1/te;zn(r,X,a,l+(U-1)*c,1),zn(r,X,a,l+U*c,1)}else{for(let te=1;te<=U-1;te++)p[m+(te-1)+N*r]=0,p[m+(te-1)+(N+1)*r]=0;P[N-1]=H,P[N]=-H,N=N+1}}if(T>1){let Y;if(H===0?Y=U:Y=U+1,N>=T-1||Y===r){_r(Lt,Lt,r,N,r-Y+N,1,a,l+(Y-N)*c,c,p,m+(Y-N)+1*r,r,0,p,m+(T+1)*r,r);let ue=1;for(let ge=1;ge<=N;ge++){if(P[ge-1]===0){const te=tf(r,p,m+(T+ge)*r,1);ue=1/Math.abs(p[m+(te-1)+(T+ge)*r])}else if(P[ge-1]===1){let te=0;for(let X=1;X<=r;X++)te=Math.max(te,Math.abs(p[m+(X-1)+(T+ge)*r])+Math.abs(p[m+(X-1)+(T+ge+1)*r]));ue=1/te}zn(r,ue,p,m+(T+ge)*r,1)}xn(-1,r,N,p,m+(T+1)*r,r,a,l+(Y-N)*c,c),N=1}else N=N+1}}}return{m:B,info:0}}const vhe=0,bhe=1,xhe=2,m8=3;function g8(e,t,n,r,i,s,o,a,l,c,u){const h=t===Pn,f=t===Rr;let d=0;if(e<0||e>3?d=-1:!h&&!f?d=-2:n<0?d=-3:r<1||r>Math.max(1,n)?d=-4:i<Math.min(r,n)||i>n?d=-5:a<0?d=-7:u<Math.max(1,n)&&(d=-9),d!==0)return d;if(n===0||a===0||e===vhe)return 0;if(r!==i&&(e===xhe||e===m8)){if(h)for(let p=r;p<=i;p++){const m=s[o+(p-1)];zn(a,m,l,c+(p-1),u)}if(f)for(let p=r;p<=i;p++){const m=1/s[o+(p-1)];zn(a,m,l,c+(p-1),u)}}if(e===bhe||e===m8){if(h)for(let p=1;p<=n;p++){let m=p;if(m>=r&&m<=i)continue;m<r&&(m=r-p);const y=Math.trunc(s[o+(m-1)]);y!==m&&nf(a,l,c+(m-1),u,l,c+(y-1),u)}if(f)for(let p=1;p<=n;p++){let m=p;if(m>=r&&m<=i)continue;m<r&&(m=r-p);const y=Math.trunc(s[o+(m-1)]);y!==m&&nf(a,l,c+(m-1),u,l,c+(y-1),u)}}return 0}const whe=4,She=5;function Oc(e,t,n,r,i,s,o,a,l,c){let u=0;const h=e;if(r===0||isNaN(r)?u=-4:isNaN(i)?u=-5:s<0?u=-6:o<0||h===whe||h===She?u=-7:c<Math.max(1,s)&&(u=-9),u!==0)return u;if(o===0||s===0)return 0;const f=ei(Wo),d=1/f;let p=r,m=i,y=!1;for(;!y;){const _=p*f;let b,x;if(_===p)b=m/p,y=!0,x=m;else if(x=m/d,x===m)b=m,y=!0,p=1;else if(Math.abs(_)>Math.abs(m)&&m!==0)b=f,y=!1,p=_;else if(Math.abs(x)>Math.abs(p))b=d,y=!1,m=x;else if(b=m/p,y=!0,b===1)return 0;for(let S=1;S<=o;S++)for(let M=1;M<=s;M++)a[l+(M-1)+(S-1)*c]*=b}return 0}const kp=0,jg=1,y8=Rr,mT=Pn,Mhe=2,gT=1,D_=0,Ehe=0,Che=-1,_8=0,gw=1,v8=0,yw=2,yT=0,_T=3;function b8(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x){const S=x!==!1;let M=0;const E=b===-1,T=e===1,k=t===1;e!==0&&e!==1?M=-1:t!==0&&t!==1?M=-2:n<0?M=-3:s<Math.max(1,n)?M=-5:f<1||T&&f<n?M=-9:(m<1||k&&m<n)&&(M=-11);let R=0,B=0;if(M===0){if(n===0)B=1,R=1;else{if(R=2*n+n*Or(1,"DGEHRD"," ",n,1),T){B=4*n,R=Math.max(R,2*n+(n-1)*Or(1,"DORGHR"," ",n,1)),Og(gw,yw,n,1,n,r,i,s,o,a,l,c,u,h,f,y,_,-1);const ge=Math.trunc(y[_]);R=Math.max(R,n+1,n+ge),pT(y8,gT,[!1],n,r,i,s,u,h,f,d,p,m,n,y,_,-1);const te=Math.trunc(y[_]);R=Math.max(R,n+te),R=Math.max(R,4*n)}else if(k){B=4*n,R=Math.max(R,2*n+(n-1)*Or(1,"DORGHR"," ",n,1)),Og(gw,yw,n,1,n,r,i,s,o,a,l,c,d,p,m,y,_,-1);const ge=Math.trunc(y[_]);R=Math.max(R,n+1,n+ge),pT(mT,gT,[!1],n,r,i,s,u,h,f,d,p,m,n,y,_,-1);const te=Math.trunc(y[_]);R=Math.max(R,n+te),R=Math.max(R,4*n)}else{B=3*n,Og(_8,v8,n,1,n,r,i,s,o,a,l,c,d,p,m,y,_,-1);const ge=Math.trunc(y[_]);R=Math.max(R,n+1,n+ge)}R=Math.max(R,B)}y[_]=R,b<B&&!E&&(M=-13)}if(M!==0)return M;if(E||n===0)return 0;const F=ei(oh);let L=ei(Wo),j=jg/L;L=Math.sqrt(L)/F,j=jg/L;const V=VL(Ehe,n,n,r,i,s);let O=!1,P=0;V>kp&&V<L?(O=!0,P=L):V>j&&(O=!0,P=j),O&&Oc(D_,0,0,V,P,n,n,r,i,s);const N=0,U=Tue(S?_T:yT,n,r,i,s,y,_+N),G=U.ilo,Z=U.ihi,ie=N+n,Y=ie+n;gR(n,G,Z,r,i,s,y,_+ie,y,_+Y,b-Y);let ue;if(T){ue=y8,xn(Un,n,n,r,i,s,u,h,f),n8(n,G,Z,u,h,f,y,_+ie,y,_+Y,b-Y);const ge=ie;M=Og(gw,yw,n,G,Z,r,i,s,o,a,l,c,u,h,f,y,_+ge,b-ge),k&&(ue=Mhe,xn(Che,n,n,u,h,f,d,p,m))}else if(k){ue=mT,xn(Un,n,n,r,i,s,d,p,m),n8(n,G,Z,d,p,m,y,_+ie,y,_+Y,b-Y);const ge=ie;M=Og(gw,yw,n,G,Z,r,i,s,o,a,l,c,d,p,m,y,_+ge,b-ge)}else{ue=mT;const ge=ie;M=Og(_8,v8,n,G,Z,r,i,s,o,a,l,c,d,p,m,y,_+ge,b-ge)}if(M!==0)return x8(M,O,P,V,n,G,o,a,l,c,y,_,R);if(T||k){const ge=ie;pT(ue,gT,[!1],n,r,i,s,u,h,f,d,p,m,n,y,_+ge,b-ge)}if(T){g8(S?_T:yT,Rr,n,G,Z,y,_+N,n,u,h,f);for(let te=1;te<=n;te++)if(l[c+(te-1)]===kp){const X=jg/Eu(n,u,h+(te-1)*f,1);zn(n,X,u,h+(te-1)*f,1)}else if(l[c+(te-1)]>kp){const X=jg/r1(Eu(n,u,h+(te-1)*f,1),Eu(n,u,h+te*f,1));zn(n,X,u,h+(te-1)*f,1),zn(n,X,u,h+te*f,1);const de=ie;for(let J=1;J<=n;J++){const K=u[h+(J-1)+(te-1)*f],Se=u[h+(J-1)+te*f];y[_+de+(J-1)]=K*K+Se*Se}const fe=tf(n,y,_+de,1),ae=oc(u[h+(fe-1)+(te-1)*f],u[h+(fe-1)+te*f]);Ta(n,u,h+(te-1)*f,1,u,h+te*f,1,ae.cs,ae.sn),u[h+(fe-1)+te*f]=kp}}if(k){g8(S?_T:yT,Pn,n,G,Z,y,_+N,n,d,p,m);for(let te=1;te<=n;te++)if(l[c+(te-1)]===kp){const X=jg/Eu(n,d,p+(te-1)*m,1);zn(n,X,d,p+(te-1)*m,1)}else if(l[c+(te-1)]>kp){const X=jg/r1(Eu(n,d,p+(te-1)*m,1),Eu(n,d,p+te*m,1));zn(n,X,d,p+(te-1)*m,1),zn(n,X,d,p+te*m,1);const de=ie;for(let J=1;J<=n;J++){const K=d[p+(J-1)+(te-1)*m],Se=d[p+(J-1)+te*m];y[_+de+(J-1)]=K*K+Se*Se}const fe=tf(n,y,_+de,1),ae=oc(d[p+(fe-1)+(te-1)*m],d[p+(fe-1)+te*m]);Ta(n,d,p+(te-1)*m,1,d,p+te*m,1,ae.cs,ae.sn),d[p+(fe-1)+te*m]=kp}}return x8(M,O,P,V,n,G,o,a,l,c,y,_,R)}function x8(e,t,n,r,i,s,o,a,l,c,u,h,f){return t&&(Oc(D_,0,0,n,r,i-e,1,o,a+e,Math.max(i-e,1)),Oc(D_,0,0,n,r,i-e,1,l,c+e,Math.max(i-e,1)),e>0&&(Oc(D_,0,0,n,r,s-1,1,o,a,i),Oc(D_,0,0,n,r,s-1,1,l,c,i))),u[h]=f,e}const nc=0,tr=1;function Ahe(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x){if(e<=0||t<=0)return;let S;if(e>=t)for(let M=1;M<=n;M++)Yn(Lt,e-M+1,M-1,-tr,r,i+(M-1)+0*s,s,_,b+(M-1)+0*x,x,tr,r,i+(M-1)+(M-1)*s,1),Yn(Lt,e-M+1,M-1,-tr,p,m+(M-1)+0*y,y,r,i+0+(M-1)*s,1,tr,r,i+(M-1)+(M-1)*s,1),S=Rs(e-M+1,r[i+(M-1)+(M-1)*s],r,i+(Math.min(M+1,e)-1)+(M-1)*s,1),o[a+(M-1)]=S.alpha,u[h+(M-1)]=S.tau,M<t?(r[i+(M-1)+(M-1)*s]=tr,Yn(Kn,e-M+1,t-M,tr,r,i+(M-1)+M*s,s,r,i+(M-1)+(M-1)*s,1,nc,_,b+M+(M-1)*x,1),Yn(Kn,e-M+1,M-1,tr,r,i+(M-1)+0*s,s,r,i+(M-1)+(M-1)*s,1,nc,_,b+0+(M-1)*x,1),Yn(Lt,t-M,M-1,-tr,_,b+M+0*x,x,_,b+0+(M-1)*x,1,tr,_,b+M+(M-1)*x,1),Yn(Kn,e-M+1,M-1,tr,p,m+(M-1)+0*y,y,r,i+(M-1)+(M-1)*s,1,nc,_,b+0+(M-1)*x,1),Yn(Kn,M-1,t-M,-tr,r,i+0+M*s,s,_,b+0+(M-1)*x,1,tr,_,b+M+(M-1)*x,1),zn(t-M,u[h+(M-1)],_,b+M+(M-1)*x,1),Yn(Lt,t-M,M,-tr,_,b+M+0*x,x,r,i+(M-1)+0*s,s,tr,r,i+(M-1)+M*s,s),Yn(Kn,M-1,t-M,-tr,r,i+0+M*s,s,p,m+(M-1)+0*y,y,tr,r,i+(M-1)+M*s,s),S=Rs(t-M,r[i+(M-1)+M*s],r,i+(M-1)+(Math.min(M+2,t)-1)*s,s),l[c+(M-1)]=S.alpha,f[d+(M-1)]=S.tau,r[i+(M-1)+M*s]=tr,Yn(Lt,e-M,t-M,tr,r,i+M+M*s,s,r,i+(M-1)+M*s,s,nc,p,m+M+(M-1)*y,1),Yn(Kn,t-M,M,tr,_,b+M+0*x,x,r,i+(M-1)+M*s,s,nc,p,m+0+(M-1)*y,1),Yn(Lt,e-M,M,-tr,r,i+M+0*s,s,p,m+0+(M-1)*y,1,tr,p,m+M+(M-1)*y,1),Yn(Lt,M-1,t-M,tr,r,i+0+M*s,s,r,i+(M-1)+M*s,s,nc,p,m+0+(M-1)*y,1),Yn(Lt,e-M,M-1,-tr,p,m+M+0*y,y,p,m+0+(M-1)*y,1,tr,p,m+M+(M-1)*y,1),zn(e-M,f[d+(M-1)],p,m+M+(M-1)*y,1)):r[i+(M-1)+(M-1)*s]=S.alpha;else for(let M=1;M<=n;M++)Yn(Lt,t-M+1,M-1,-tr,_,b+(M-1)+0*x,x,r,i+(M-1)+0*s,s,tr,r,i+(M-1)+(M-1)*s,s),Yn(Kn,M-1,t-M+1,-tr,r,i+0+(M-1)*s,s,p,m+(M-1)+0*y,y,tr,r,i+(M-1)+(M-1)*s,s),S=Rs(t-M+1,r[i+(M-1)+(M-1)*s],r,i+(M-1)+(Math.min(M+1,t)-1)*s,s),o[a+(M-1)]=S.alpha,f[d+(M-1)]=S.tau,M<e?(r[i+(M-1)+(M-1)*s]=tr,Yn(Lt,e-M,t-M+1,tr,r,i+M+(M-1)*s,s,r,i+(M-1)+(M-1)*s,s,nc,p,m+M+(M-1)*y,1),Yn(Kn,t-M+1,M-1,tr,_,b+(M-1)+0*x,x,r,i+(M-1)+(M-1)*s,s,nc,p,m+0+(M-1)*y,1),Yn(Lt,e-M,M-1,-tr,r,i+M+0*s,s,p,m+0+(M-1)*y,1,tr,p,m+M+(M-1)*y,1),Yn(Lt,M-1,t-M+1,tr,r,i+0+(M-1)*s,s,r,i+(M-1)+(M-1)*s,s,nc,p,m+0+(M-1)*y,1),Yn(Lt,e-M,M-1,-tr,p,m+M+0*y,y,p,m+0+(M-1)*y,1,tr,p,m+M+(M-1)*y,1),zn(e-M,f[d+(M-1)],p,m+M+(M-1)*y,1),Yn(Lt,e-M,M-1,-tr,r,i+M+0*s,s,_,b+(M-1)+0*x,x,tr,r,i+M+(M-1)*s,1),Yn(Lt,e-M,M,-tr,p,m+M+0*y,y,r,i+0+(M-1)*s,1,tr,r,i+M+(M-1)*s,1),S=Rs(e-M,r[i+M+(M-1)*s],r,i+(Math.min(M+2,e)-1)+(M-1)*s,1),l[c+(M-1)]=S.alpha,u[h+(M-1)]=S.tau,r[i+M+(M-1)*s]=tr,Yn(Kn,e-M,t-M,tr,r,i+M+M*s,s,r,i+M+(M-1)*s,1,nc,_,b+M+(M-1)*x,1),Yn(Kn,e-M,M-1,tr,r,i+M+0*s,s,r,i+M+(M-1)*s,1,nc,_,b+0+(M-1)*x,1),Yn(Lt,t-M,M-1,-tr,_,b+M+0*x,x,_,b+0+(M-1)*x,1,tr,_,b+M+(M-1)*x,1),Yn(Kn,e-M,M,tr,p,m+M+0*y,y,r,i+M+(M-1)*s,1,nc,_,b+0+(M-1)*x,1),Yn(Kn,M,t-M,-tr,r,i+0+M*s,s,_,b+0+(M-1)*x,1,tr,_,b+M+(M-1)*x,1),zn(t-M,u[h+(M-1)],_,b+M+(M-1)*x,1)):r[i+(M-1)+(M-1)*s]=S.alpha}function The(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p){let m=0;if(e<0?m=-1:t<0?m=-2:i<Math.max(1,e)&&(m=-4),m!==0)return ts("DGEBD2",-m),m;if(e>=t)for(let y=1;y<=t;y++){const _=r+(y-1)+(y-1)*i,b=r+Math.min(y,e-1)+(y-1)*i,{alpha:x,tau:S}=Rs(e-y+1,n[_],n,b,1);if(n[_]=x,c[u+(y-1)]=S,s[o+(y-1)]=n[_],y<t&&ul(Rr,e-y+1,t-y,n,_,1,S,n,r+(y-1)+y*i,i,d,p),y<t){const M=r+(y-1)+y*i,E=r+(y-1)+Math.min(y+1,t-1)*i,{alpha:T,tau:k}=Rs(t-y,n[M],n,E,i);n[M]=T,h[f+(y-1)]=k,a[l+(y-1)]=n[M],ul(Pn,e-y,t-y,n,M,i,k,n,r+y+y*i,i,d,p)}else h[f+(y-1)]=0}else for(let y=1;y<=e;y++){const _=r+(y-1)+(y-1)*i,b=r+(y-1)+Math.min(y,t-1)*i,{alpha:x,tau:S}=Rs(t-y+1,n[_],n,b,i);if(n[_]=x,h[f+(y-1)]=S,s[o+(y-1)]=n[_],y<e&&ul(Pn,e-y,t-y+1,n,_,i,S,n,r+y+(y-1)*i,i,d,p),y<e){const M=r+y+(y-1)*i,E=r+Math.min(y+1,e-1)+(y-1)*i,{alpha:T,tau:k}=Rs(e-y,n[M],n,E,1);n[M]=T,c[u+(y-1)]=k,a[l+(y-1)]=n[M],ul(Rr,e-y,t-y,n,M,1,k,n,r+y+y*i,i,d,p)}else c[u+(y-1)]=0}return 0}const _w=1;function io(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m){let y=0;const _=Math.min(e,t);let b,x,S;_===0?(b=1,x=1,S=1):(b=Math.max(e,t),S=Math.max(1,Or(1,"DGEBRD"," ",e,t)),x=(e+t)*S),d[p]=x;const M=m===-1;if(e<0?y=-1:t<0?y=-2:i<Math.max(1,e)?y=-4:m<b&&!M&&(y=-10),y<0)return ts("DGEBRD",-y),y;if(M)return 0;if(_===0)return d[p]=1,0;let E=Math.max(e,t);const T=e,k=t;let R;if(S>1&&S<_){if(R=Math.max(S,Or(3,"DGEBRD"," ",e,t)),R<_&&(E=x,m<E)){const F=Or(2,"DGEBRD"," ",e,t);m>=(e+t)*F?S=Math.floor(m/(e+t)):(S=1,R=_)}}else R=_;let B=1;for(;B<=_-R;B+=S)if(Ahe(e-B+1,t-B+1,S,n,r+(B-1)+(B-1)*i,i,s,o+(B-1),a,l+(B-1),c,u+(B-1),h,f+(B-1),d,p,T,d,p+T*S,k),_r(Lt,Kn,e-B-S+1,t-B-S+1,S,-_w,n,r+(B+S-1)+(B-1)*i,i,d,p+T*S+S,k,_w,n,r+(B+S-1)+(B+S-1)*i,i),_r(Lt,Lt,e-B-S+1,t-B-S+1,S,-_w,d,p+S,T,n,r+(B-1)+(B+S-1)*i,i,_w,n,r+(B+S-1)+(B+S-1)*i,i),e>=t)for(let F=B;F<=B+S-1;F++)n[r+(F-1)+(F-1)*i]=s[o+(F-1)],n[r+(F-1)+F*i]=a[l+(F-1)];else for(let F=B;F<=B+S-1;F++)n[r+(F-1)+(F-1)*i]=s[o+(F-1)],n[r+F+(F-1)*i]=a[l+(F-1)];return The(e-B+1,t-B+1,n,r+(B-1)+(B-1)*i,i,s,o+(B-1),a,l+(B-1),c,u+(B-1),h,f+(B-1),d,p),d[p]=E,0}function w8(e,t,n,r,i,s,o,a,l){let c=0;if(e<0?c=-1:t<0?c=-2:i<Math.max(1,e)&&(c=-4),c!==0)return ts("DGELQ2",-c),c;const u=Math.min(e,t);for(let h=1;h<=u;h++){const f=r+(h-1)+(h-1)*i,d=r+(h-1)+Math.min(h,t-1)*i,{alpha:p,tau:m}=Rs(t-h+1,n[f],n,d,i);n[f]=p,s[o+(h-1)]=m,h<e&&ul(Pn,e-h,t-h+1,n,f,i,m,n,r+h+(h-1)*i,i,a,l)}return 0}const S8=0,M8=1;function Bh(e,t,n,r,i,s,o,a,l,c){let u=0;const h=Math.min(e,t);let f=Or(1,"DGELQF"," ",e,t);const d=c===-1;if(e<0?u=-1:t<0?u=-2:i<Math.max(1,e)?u=-4:d||(c<=0||t>0&&c<Math.max(1,e))&&(u=-7),u!==0)return ts("DGELQF",-u),u;if(d){let x;return h===0?x=1:x=e*f,a[l]=x,0}if(h===0)return a[l]=1,0;let p=2,m=0,y=e,_=e;f>1&&f<h&&(m=Math.max(0,Or(3,"DGELQF"," ",e,t)),m<h&&(_=e,y=_*f,c<y&&(f=Math.floor(c/_),p=Math.max(2,Or(2,"DGELQF"," ",e,t)))));let b=1;if(f>=p&&f<h&&m<h)for(b=1;b<=h-m;b+=f){const x=Math.min(h-b+1,f);w8(x,t-b+1,n,r+(b-1)+(b-1)*i,i,s,o+(b-1),a,l),b+x<=e&&(Zh(S8,M8,t-b+1,x,n,r+(b-1)+(b-1)*i,i,s,o+(b-1),a,l,_),HM(Pn,Lt,S8,M8,e-b-x+1,t-b+1,x,n,r+(b-1)+(b-1)*i,i,a,l,_,n,r+(b+x-1)+(b-1)*i,i,a,l+x,_))}else b=1;return b<=h&&w8(e-b+1,t-b+1,n,r+(b-1)+(b-1)*i,i,s,o+(b-1),a,l),a[l]=y,0}function E8(e,t,n,r,i,s,o,a,l){let c=0;if(e<0?c=-1:t<0?c=-2:i<Math.max(1,e)&&(c=-4),c!==0)return ts("DGEQR2",-c),c;const u=Math.min(e,t);for(let h=1;h<=u;h++){const f=r+(h-1)+(h-1)*i,d=r+Math.min(h,e-1)+(h-1)*i,{alpha:p,tau:m}=Rs(e-h+1,n[f],n,d,1);n[f]=p,s[o+(h-1)]=m,h<t&&ul(Rr,e-h+1,t-h,n,f,1,m,n,r+(h-1)+h*i,i,a,l)}return 0}function Fh(e,t,n,r,i,s,o){const a=Math.min(e,t);let l=0;const c=Or(1,"DGEQRF"," ",e,t);if(e<0?l=-1:t<0?l=-2:i<Math.max(1,e)&&(l=-4),l!==0)return ts("DGEQRF",-l),l;if(a===0)return 0;const u=2;let h=0,f=t;c>1&&c<a&&(h=Math.max(0,Or(3,"DGEQRF"," ",e,t)),h<a&&(f=t*c));let d=1;if(c>=u&&c<a&&h<a){const p=D(f);for(d=1;d<=a-h;d+=c){const m=Math.min(a-d+1,c);E8(e-d+1,m,n,r+(d-1)+(d-1)*i,i,s,o+(d-1),p,0)}}if(d<=a){const p=D(t);E8(e-d+1,t-d+1,n,r+(d-1)+(d-1)*i,i,s,o+(d-1),p,0)}return 0}function C8(e,t,n,r,i,s,o,a,l,c){let u=0;if(e<0?u=-1:t<e?u=-2:n<0||n>e?u=-3:s<Math.max(1,e)&&(u=-5),u!==0)return ts("DORGL2",-u),u;if(e<=0)return 0;if(n<e)for(let h=1;h<=t;h++){for(let f=n+1;f<=e;f++)r[i+(f-1)+(h-1)*s]=0;h>n&&h<=e&&(r[i+(h-1)+(h-1)*s]=1)}for(let h=n;h>=1;h--){const f=i+(h-1)+(h-1)*s,d=o[a+(h-1)];h<t&&(h<e&&ul(Pn,e-h,t-h+1,r,f,s,d,r,i+h+(h-1)*s,s,l,c),zn(t-h,-d,r,i+(h-1)+h*s,s)),r[f]=1-d;for(let p=1;p<=h-1;p++)r[i+(h-1)+(p-1)*s]=0}return 0}const A8=0,T8=1,khe=1;function _u(e,t,n,r,i,s,o,a,l,c,u){let h=0;const f=Or(1,"DORGLQ"," ",e,t),d=Math.max(1,e)*f;l[c]=d;const p=u===-1;if(e<0?h=-1:t<e?h=-2:n<0||n>e?h=-3:s<Math.max(1,e)?h=-5:u<Math.max(1,e)&&!p&&(h=-8),h!==0)return ts("DORGLQ",-h),h;if(p)return 0;if(e<=0)return l[c]=1,0;let m=2,y=0,_=e,b=e,x=f;x>1&&x<n&&(y=Math.max(0,Or(3,"DORGLQ"," ",e,t)),y<n&&(b=e,_=b*x,u<_&&(x=Math.floor(u/b),m=Math.max(2,Or(2,"DORGLQ"," ",e,t)))));let S=0,M=0;if(x>=m&&x<n&&y<n){M=Math.floor((n-y-1)/x)*x,S=Math.min(n,M+x);for(let E=1;E<=S;E++)for(let T=S+1;T<=e;T++)r[i+(T-1)+(E-1)*s]=0}else S=0;if(S<e&&C8(e-S,t-S,n-S,r,i+S+S*s,s,o,a+S,l,c),S>0)for(let E=M+1;E>=1;E-=x){const T=Math.min(x,n-E+1);E+T<=e&&(Zh(A8,T8,t-E+1,T,r,i+(E-1)+(E-1)*s,s,o,a+(E-1),l,c,b),HM(Pn,khe,A8,T8,e-E-T+1,t-E+1,T,r,i+(E-1)+(E-1)*s,s,l,c,b,r,i+(E+T-1)+(E-1)*s,s,l,c+T,b)),C8(T,t-E+1,T,r,i+(E-1)+(E-1)*s,s,o,a+(E-1),l,c);for(let k=1;k<=E-1;k++)for(let R=E;R<=E+T-1;R++)r[i+(R-1)+(k-1)*s]=0}return l[c]=_,0}const vw=0,k8=1;function Yr(e,t,n,r,i,s,o,a,l,c,u,h){let f=0;const d=e===wo,p=Math.min(t,n),m=h===-1;!d&&e!==So?f=-1:t<0?f=-2:n<0||d&&(n>t||n<Math.min(t,r))||!d&&(t>n||t<Math.min(n,r))?f=-3:r<0?f=-4:o<Math.max(1,t)?f=-6:h<Math.max(1,p)&&!m&&(f=-9);let y=1;if(f===0){if(c[u]=1,d){if(t>=r){const _=Or(1,"DORGQR"," ",t,n);y=Math.max(1,n)*_}else if(t>1){const _=Or(1,"DORGQR"," ",t-1,t-1);y=Math.max(1,t-1)*_}}else if(r<n){const _=Or(1,"DORGLQ"," ",t,n);y=Math.max(1,t)*_}else if(n>1){const _=Or(1,"DORGLQ"," ",n-1,n-1);y=Math.max(1,n-1)*_}y=Math.max(y,p)}if(f!==0)return ts("DORGBR",-f),f;if(m)return c[u]=y,0;if(t===0||n===0)return c[u]=1,0;if(d)if(t>=r)Fc(t,n,r,i,s,o,a,l);else{for(let _=t;_>=2;_--){i[s+0+(_-1)*o]=vw;for(let b=_+1;b<=t;b++)i[s+(b-1)+(_-1)*o]=i[s+(b-1)+(_-2)*o]}i[s]=k8;for(let _=2;_<=t;_++)i[s+(_-1)]=vw;t>1&&Fc(t-1,t-1,t-1,i,s+1+1*o,o,a,l)}else if(r<n)_u(t,n,r,i,s,o,a,l,c,u,h);else{i[s]=k8;for(let _=2;_<=n;_++)i[s+(_-1)]=vw;for(let _=2;_<=n;_++){for(let b=_-1;b>=2;b--)i[s+(b-1)+(_-1)*o]=i[s+(b-2)+(_-1)*o];i[s+(_-1)*o]=vw}n>1&&_u(n-1,n-1,n-1,i,s+1+1*o,o,a,l,c,u,h)}return c[u]=y,0}function R8(e,t,n){let r,i;const s=Math.abs(e),o=Math.abs(t),a=Math.abs(n),l=Math.min(s,a),c=Math.max(s,a);if(l===0)r=0,c===0?i=o:i=Math.max(c,o)*Math.sqrt(1+(Math.min(c,o)/Math.max(c,o))**2);else if(o<c){const u=1+l/c,h=(c-l)/c,f=(o/c)**2,d=2/(Math.sqrt(u*u+f)+Math.sqrt(h*h+f));r=l*d,i=c/d}else{const u=c/o;if(u===0)r=l*c/o,i=o;else{const h=1+l/c,f=(c-l)/c,d=1/(Math.sqrt(1+(h*u)**2)+Math.sqrt(1+(f*u)**2));r=l*d*u,r=r+r,i=o/(d+d)}}return{ssmin:r,ssmax:i}}function xa(e,t){return t>=0?Math.abs(e):-Math.abs(e)}function Rhe(e,t,n){let l=e,c=Math.abs(l),u=n,h=Math.abs(n),f=1;const d=h>c;if(d){f=3;let F=l;l=u,u=F,F=c,c=h,h=F}const p=t,m=Math.abs(p);let y,_,b,x,S,M;if(m===0)S=h,M=c,y=1,b=1,_=0,x=0;else{let F=!0;if(m>c&&(f=2,c/m<ei(N1)&&(F=!1,M=m,h>1?S=c/(m/h):S=c/m*h,y=1,_=u/p,x=1,b=l/p)),F){const L=c-h;let j;L===c?j=1:j=L/c;const V=p/l;let O=2-j;const P=V*V,N=O*O,H=Math.sqrt(N+P);let U;j===0?U=Math.abs(V):U=Math.sqrt(j*j+P);const G=.5*(H+U);S=h/G,M=c*G,P===0?j===0?O=xa(2,l)*xa(1,p):O=p/xa(L,l)+V/O:O=(V/(H+O)+V/(U+j))*(1+G),j=Math.sqrt(O*O+4),b=2/j,x=O/j,y=(b+x*V)/G,_=u/l*x/G}}let E,T,k,R;d?(E=x,T=b,k=_,R=y):(E=y,T=_,k=b,R=x);let B=0;return f===1&&(B=xa(1,k)*xa(1,E)*xa(1,e)),f===2&&(B=xa(1,R)*xa(1,E)*xa(1,t)),f===3&&(B=xa(1,R)*xa(1,T)*xa(1,n)),M=xa(M,B),S=xa(S,B*xa(1,e)*xa(1,n)),{ssmin:S,ssmax:M,snr:R,csr:k,snl:T,csl:E}}function zh(e,t,n,r,i,s,o,a,l,c,u,h){let p=0;if(e!==Rr&&e!==Pn?p=1:n!==Ed&&n!==nm?p=3:r<0?p=4:i<0?p=5:h<Math.max(1,r)&&(p=9),p!==0)throw new Error(`DLASR: illegal argument ${p}`);if(r===0||i===0)return;let m,y,_,b,x;if(e===Rr){if(n===Ed){for(x=1;x<=r-1;x++)if(m=s[o+(x-1)],y=a[l+(x-1)],m!==1||y!==0)for(b=1;b<=i;b++)_=c[u+x+(b-1)*h],c[u+x+(b-1)*h]=m*_-y*c[u+(x-1)+(b-1)*h],c[u+(x-1)+(b-1)*h]=y*_+m*c[u+(x-1)+(b-1)*h]}else if(n===nm){for(x=r-1;x>=1;x--)if(m=s[o+(x-1)],y=a[l+(x-1)],m!==1||y!==0)for(b=1;b<=i;b++)_=c[u+x+(b-1)*h],c[u+x+(b-1)*h]=m*_-y*c[u+(x-1)+(b-1)*h],c[u+(x-1)+(b-1)*h]=y*_+m*c[u+(x-1)+(b-1)*h]}}else if(e===Pn){if(n===Ed){for(x=1;x<=i-1;x++)if(m=s[o+(x-1)],y=a[l+(x-1)],m!==1||y!==0)for(b=1;b<=r;b++)_=c[u+(b-1)+x*h],c[u+(b-1)+x*h]=m*_-y*c[u+(b-1)+(x-1)*h],c[u+(b-1)+(x-1)*h]=y*_+m*c[u+(b-1)+(x-1)*h]}else if(n===nm){for(x=i-1;x>=1;x--)if(m=s[o+(x-1)],y=a[l+(x-1)],m!==1||y!==0)for(b=1;b<=r;b++)_=c[u+(b-1)+x*h],c[u+(b-1)+x*h]=m*_-y*c[u+(b-1)+(x-1)*h],c[u+(b-1)+(x-1)*h]=y*_+m*c[u+(b-1)+(x-1)*h]}}}const Wr=0,Hg=1,D8=-1,Dhe=.01,Nhe=10,Lhe=100,Ihe=-.125,vT=6;function N8(e,t){return t>=0?Math.abs(e):-Math.abs(e)}function _s(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x){let S=0;const M=e===Un;if(e!==cn&&!M?S=-1:t<0?S=-2:n<0?S=-3:r<0?S=-4:n===0&&h<1||n>0&&h<Math.max(1,t)?S=-9:p<Math.max(1,r)&&(S=-11),S!==0)return ts("DBDSQR",-S),S;if(t===0)return 0;const E=K=>s[o+K-1],T=(K,Se)=>{s[o+K-1]=Se},k=K=>a[l+K-1],R=(K,Se)=>{a[l+K-1]=Se},B=(K,Se)=>{b[x+K-1]=Se},F=K=>u+(K-1),L=K=>d+(K-1)*p;if(t===1)return E(1)===Wr&&T(1,Wr),E(1)<Wr&&(T(1,-E(1)),n>0&&zn(n,D8,c,F(1),h)),0;const j=t-1,V=j+j,O=V+j;let P=0;const N=ei(N1),H=ei(Wo);if(M){for(let K=1;K<=t-1;K++){const Se=oc(E(K),k(K));T(K,Se.r),R(K,Se.sn*E(K+1)),T(K+1,Se.cs*E(K+1)),B(K,Se.cs),B(j+K,Se.sn)}r>0&&zh(Pn,Ih,Ed,r,t,b,x,b,x+j,f,d,p)}const G=Math.max(Nhe,Math.min(Lhe,Math.pow(N,Ihe)))*N;let Z=Wr;for(let K=1;K<=t;K++)Z=Math.max(Z,Math.abs(E(K)));for(let K=1;K<=t-1;K++)Z=Math.max(Z,Math.abs(k(K)));let ie=Wr,Y,ue,ge;if(G>=Wr){if(Y=Math.abs(E(1)),Y!==Wr){ge=Y;for(let K=2;K<=t&&(ge=Math.abs(E(K))*(ge/(ge+Math.abs(k(K-1)))),Y=Math.min(Y,ge),Y!==Wr);K++);}Y=Y/Math.sqrt(t),ue=Math.max(G*Y,vT*(t*(t*H)))}else ue=Math.max(Math.abs(G)*Z,vT*(t*(t*H)));const te=vT*t;let X=0,de=-1,fe=-1,ae=-1,J=t;e:for(;;){if(J<=1)break e;if(de>=t&&(de=de-t,X=X+1,X>=te)){S=0;for(let Fe=1;Fe<=t-1;Fe++)k(Fe)!==Wr&&S++;return S}G<Wr&&Math.abs(E(J))<=ue&&T(J,Wr),Z=Math.abs(E(J));let K=0,Se=!1;for(let Fe=1;Fe<=J-1;Fe++){K=J-Fe;const Ue=Math.abs(E(K)),Ee=Math.abs(k(K));if(G<Wr&&Ue<=ue&&T(K,Wr),Ee<=ue){Se=!0;break}Z=Math.max(Z,Ue,Ee)}if(!Se)K=0;else if(R(K,Wr),K===J-1){J=J-1;continue e}if(K=K+1,K===J-1){const Fe=Rhe(E(J-1),k(J-1),E(J));T(J-1,Fe.ssmax),R(J-1,Wr),T(J,Fe.ssmin),n>0&&Ta(n,c,F(J-1),h,c,F(J),h,Fe.csr,Fe.snr),r>0&&Ta(r,f,L(J-1),1,f,L(J),1,Fe.csl,Fe.snl),J=J-2;continue e}if((K>ae||J<fe)&&(Math.abs(E(K))>=Math.abs(E(J))?P=1:P=2),P===1){if(Math.abs(k(J-1))<=Math.abs(G)*Math.abs(E(J))||G<Wr&&Math.abs(k(J-1))<=ue){R(J-1,Wr);continue e}if(G>=Wr){ge=Math.abs(E(K)),ie=ge;let Fe=!1;for(let Ue=K;Ue<=J-1;Ue++){if(Math.abs(k(Ue))<=G*ge){R(Ue,Wr),Fe=!0;break}ge=Math.abs(E(Ue+1))*(ge/(ge+Math.abs(k(Ue)))),ie=Math.min(ie,ge)}if(Fe)continue e}}else{if(Math.abs(k(K))<=Math.abs(G)*Math.abs(E(K))||G<Wr&&Math.abs(k(K))<=ue){R(K,Wr);continue e}if(G>=Wr){ge=Math.abs(E(J)),ie=ge;let Fe=!1;for(let Ue=J-1;Ue>=K;Ue--){if(Math.abs(k(Ue))<=G*ge){R(Ue,Wr),Fe=!0;break}ge=Math.abs(E(Ue))*(ge/(ge+Math.abs(k(Ue)))),ie=Math.min(ie,ge)}if(Fe)continue e}}fe=K,ae=J;let ye,Ge;if(G>=Wr&&t*G*(ie/Z)<=Math.max(N,Dhe*G)?ye=Wr:(P===1?(Ge=Math.abs(E(K)),ye=R8(E(J-1),k(J-1),E(J)).ssmin):(Ge=Math.abs(E(J)),ye=R8(E(K),k(K),E(K+1)).ssmin),Ge>Wr&&ye/Ge*(ye/Ge)<N&&(ye=Wr)),de=de+J-K,ye===Wr)if(P===1){let Fe=Hg,Ue=Hg,Ee=Wr,ke,_e;for(let Le=K;Le<=J-1;Le++){const oe=oc(E(Le)*Fe,k(Le));Fe=oe.cs,ke=oe.sn,_e=oe.r,Le>K&&R(Le-1,Ee*_e);const Q=oc(Ue*_e,E(Le+1)*ke);Ue=Q.cs,Ee=Q.sn,T(Le,Q.r),B(Le-K+1,Fe),B(Le-K+1+j,ke),B(Le-K+1+V,Ue),B(Le-K+1+O,Ee)}const we=E(J)*Fe;T(J,we*Ue),R(J-1,we*Ee),n>0&&zh(Rr,Ih,Ed,J-K+1,n,b,x,b,x+j,c,F(K),h),r>0&&zh(Pn,Ih,Ed,r,J-K+1,b,x+V,b,x+O,f,L(K),p),Math.abs(k(J-1))<=ue&&R(J-1,Wr)}else{let Fe=Hg,Ue=Hg,Ee=Wr,ke,_e;for(let Le=J;Le>=K+1;Le--){const oe=oc(E(Le)*Fe,k(Le-1));Fe=oe.cs,ke=oe.sn,_e=oe.r,Le<J&&R(Le,Ee*_e);const Q=oc(Ue*_e,E(Le-1)*ke);Ue=Q.cs,Ee=Q.sn,T(Le,Q.r),B(Le-K,Fe),B(Le-K+j,-ke),B(Le-K+V,Ue),B(Le-K+O,-Ee)}const we=E(K)*Fe;T(K,we*Ue),R(K,we*Ee),n>0&&zh(Rr,Ih,nm,J-K+1,n,b,x+V,b,x+O,c,F(K),h),r>0&&zh(Pn,Ih,nm,r,J-K+1,b,x,b,x+j,f,L(K),p),Math.abs(k(K))<=ue&&R(K,Wr)}else if(P===1){let Fe=(Math.abs(E(K))-ye)*(N8(Hg,E(K))+ye/E(K)),Ue=k(K),Ee,ke,_e,we,Le;for(let oe=K;oe<=J-1;oe++){const Q=oc(Fe,Ue);Ee=Q.cs,ke=Q.sn,Le=Q.r,oe>K&&R(oe-1,Le),Fe=Ee*E(oe)+ke*k(oe),R(oe,Ee*k(oe)-ke*E(oe)),Ue=ke*E(oe+1),T(oe+1,Ee*E(oe+1));const xe=oc(Fe,Ue);_e=xe.cs,we=xe.sn,Le=xe.r,T(oe,Le),Fe=_e*k(oe)+we*E(oe+1),T(oe+1,_e*E(oe+1)-we*k(oe)),oe<J-1&&(Ue=we*k(oe+1),R(oe+1,_e*k(oe+1))),B(oe-K+1,Ee),B(oe-K+1+j,ke),B(oe-K+1+V,_e),B(oe-K+1+O,we)}R(J-1,Fe),n>0&&zh(Rr,Ih,Ed,J-K+1,n,b,x,b,x+j,c,F(K),h),r>0&&zh(Pn,Ih,Ed,r,J-K+1,b,x+V,b,x+O,f,L(K),p),Math.abs(k(J-1))<=ue&&R(J-1,Wr)}else{let Fe=(Math.abs(E(J))-ye)*(N8(Hg,E(J))+ye/E(J)),Ue=k(J-1),Ee,ke,_e,we,Le;for(let oe=J;oe>=K+1;oe--){const Q=oc(Fe,Ue);Ee=Q.cs,ke=Q.sn,Le=Q.r,oe<J&&R(oe,Le),Fe=Ee*E(oe)+ke*k(oe-1),R(oe-1,Ee*k(oe-1)-ke*E(oe)),Ue=ke*E(oe-1),T(oe-1,Ee*E(oe-1));const xe=oc(Fe,Ue);_e=xe.cs,we=xe.sn,Le=xe.r,T(oe,Le),Fe=_e*k(oe-1)+we*E(oe-1),T(oe-1,_e*E(oe-1)-we*k(oe-1)),oe>K+1&&(Ue=we*k(oe-2),R(oe-2,_e*k(oe-2))),B(oe-K,Ee),B(oe-K+j,-ke),B(oe-K+V,_e),B(oe-K+O,-we)}R(K,Fe),Math.abs(k(K))<=ue&&R(K,Wr),n>0&&zh(Rr,Ih,nm,J-K+1,n,b,x+V,b,x+O,c,F(K),h),r>0&&zh(Pn,Ih,nm,r,J-K+1,b,x,b,x+j,f,L(K),p)}continue e}for(let K=1;K<=t;K++)E(K)===Wr&&T(K,Wr),E(K)<Wr&&(T(K,-E(K)),n>0&&zn(n,D8,c,F(K),h));for(let K=1;K<=t-1;K++){let Se=1;ie=E(1);for(let ye=2;ye<=t+1-K;ye++)E(ye)<=ie&&(Se=ye,ie=E(ye));Se!==t+1-K&&(T(Se,E(t+1-K)),T(t+1-K,ie),n>0&&nf(n,c,F(Se),h,c,F(t+1-K),h),r>0&&nf(r,f,L(Se),1,f,L(t+1-K),1))}return 0}const Phe=0,Bhe=1,Fhe=2,zhe=3,Uhe=0,Ohe=1,jhe=2,Hhe=3,$g=0,wa=-1,$he=0,qn=0,na=1;function L8(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m,y,_){let b=0;const x=Math.min(n,r),S=e===Phe,M=e===Bhe,E=S||M,T=e===Fhe,k=e===zhe,R=t===Uhe,B=t===Ohe,F=R||B,L=t===jhe,j=t===Hhe,V=_===-1;S||M||T||k?!(R||B||L||j)||L&&T?b=-2:n<0?b=-3:r<0?b=-4:o<Math.max(1,n)?b=-6:h<1||E&&h<n?b=-9:(p<1||R&&p<r||B&&p<x)&&(b=-11):b=-1;let O=1,P=1,N=0,H=0,U=0;if(b===0){if(n>=r&&x>0){N=Or(6,"DGESVD"," ",n,r),U=5*r;const oe=r+r*32,Q=r+r*32,xe=n+n*32,me=3*r+2*r*32,be=r+r*32,ve=r+r*32;n>=N?k?(P=r+oe,P=Math.max(P,3*r+me),(L||F)&&(P=Math.max(P,3*r+be)),P=Math.max(P,U),O=Math.max(4*r,U)):T&&j?(H=r+oe,H=Math.max(H,r+Q),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,U),P=Math.max(r*r+H,r*r+n*r+r),O=Math.max(3*r+n,U)):T&&F?(H=r+oe,H=Math.max(H,r+Q),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,3*r+be),H=Math.max(H,U),P=Math.max(r*r+H,r*r+n*r+r),O=Math.max(3*r+n,U)):M&&j?(H=r+oe,H=Math.max(H,r+Q),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,U),P=r*r+H,O=Math.max(3*r+n,U)):M&&L?(H=r+oe,H=Math.max(H,r+Q),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,3*r+be),H=Math.max(H,U),P=2*r*r+H,O=Math.max(3*r+n,U)):M&&F?(H=r+oe,H=Math.max(H,r+Q),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,3*r+be),H=Math.max(H,U),P=r*r+H,O=Math.max(3*r+n,U)):S&&j?(H=r+oe,H=Math.max(H,r+xe),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,U),P=r*r+H,O=Math.max(3*r+n,U)):S&&L?(H=r+oe,H=Math.max(H,r+xe),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,3*r+be),H=Math.max(H,U),P=2*r*r+H,O=Math.max(3*r+n,U)):S&&F&&(H=r+oe,H=Math.max(H,r+xe),H=Math.max(H,3*r+me),H=Math.max(H,3*r+ve),H=Math.max(H,3*r+be),H=Math.max(H,U),P=r*r+H,O=Math.max(3*r+n,U)):(P=3*r+(n+r)*32,(M||T)&&(P=Math.max(P,3*r+r*32)),S&&(P=Math.max(P,3*r+n*32)),j||(P=Math.max(P,3*r+r*32)),P=Math.max(P,U),O=Math.max(3*r+n,U))}else if(x>0){N=Or(6,"DGESVD"," ",n,r),U=5*n;const oe=n+n*32,Q=r+r*32,xe=n+n*32,me=3*n+2*n*32,be=n+n*32,ve=n+n*32;r>=N?j?(P=n+oe,P=Math.max(P,3*n+me),(T||E)&&(P=Math.max(P,3*n+ve)),P=Math.max(P,U),O=Math.max(4*n,U)):L&&k?(H=n+oe,H=Math.max(H,n+xe),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,U),P=Math.max(n*n+H,n*n+n*r+n),O=Math.max(3*n+r,U)):L&&E?(H=n+oe,H=Math.max(H,n+xe),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,3*n+ve),H=Math.max(H,U),P=Math.max(n*n+H,n*n+n*r+n),O=Math.max(3*n+r,U)):B&&k?(H=n+oe,H=Math.max(H,n+xe),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,U),P=n*n+H,O=Math.max(3*n+r,U)):B&&T?(H=n+oe,H=Math.max(H,n+xe),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,3*n+ve),H=Math.max(H,U),P=2*n*n+H,O=Math.max(3*n+r,U)):B&&E?(H=n+oe,H=Math.max(H,n+xe),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,3*n+ve),H=Math.max(H,U),P=n*n+H,O=Math.max(3*n+r,U)):R&&k?(H=n+oe,H=Math.max(H,n+Q),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,U),P=n*n+H,O=Math.max(3*n+r,U)):R&&T?(H=n+oe,H=Math.max(H,n+Q),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,3*n+ve),H=Math.max(H,U),P=2*n*n+H,O=Math.max(3*n+r,U)):R&&E&&(H=n+oe,H=Math.max(H,n+Q),H=Math.max(H,3*n+me),H=Math.max(H,3*n+be),H=Math.max(H,3*n+ve),H=Math.max(H,U),P=n*n+H,O=Math.max(3*n+r,U)):(P=3*n+(n+r)*32,(B||L)&&(P=Math.max(P,3*n+r*32)),R&&(P=Math.max(P,3*n+r*32)),k||(P=Math.max(P,3*n+n*32)),P=Math.max(P,U),O=Math.max(3*n+r,U))}P=Math.max(P,O),m[y]=P,_<O&&!V&&(b=-13)}if(b!==0)return ts("DGESVD",-b),b;if(V||n===0||r===0)return 0;const G=ei(N1),Z=Math.sqrt(ei(Wo))/G,ie=na/Z,Y=D(1),ue=VL($he,n,r,i,s,o);let ge=0;ue>qn&&ue<Z?(ge=1,Oc($g,0,0,ue,Z,n,r,i,s,o)):ue>ie&&(ge=1,Oc($g,0,0,ue,ie,n,r,i,s,o));const te=Math.max(P,1),X=D(te+1);let de=0,fe,ae,J,K,Se,ye,Ge,Fe,Ue,Ee,ke,_e,we,Le;if(n>=r)if(n>=N)if(k)J=0,K=J+r,Fh(n,r,i,s,o,X,J),r>1&&ls(Un,r-1,r-1,qn,qn,i,s+1,o),de=0,fe=de+r,ae=fe+r,K=ae+r,io(r,r,i,s,o,a,l,X,de,X,fe,X,ae,X,K,te-K),Ge=0,(L||F)&&(Yr(So,r,r,r,i,s,o,X,ae,X,K,te-K),Ge=r),K=de+r,b=_s(cn,r,Ge,0,0,a,l,X,de,i,s,o,Y,0,1,Y,0,1,X,K),F&&xn(wa,r,r,i,s,o,f,d,p);else if(T&&j){Se=0,ke=r,_e=Math.max(r,Math.min(n,Math.floor(te/r))),J=Se+ke*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(cn,r,r,i,s,o,X,Se,ke),ls(Un,r-1,r-1,qn,qn,X,Se+1,ke),Fc(n,r,r,i,s,o,X,J),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,Se,ke,a,l,X,de,X,fe,X,ae,X,K,te-K),Yr(wo,r,r,r,X,Se,ke,X,fe,X,K,te-K),K=de+r,b=_s(cn,r,0,r,0,a,l,X,de,Y,0,1,X,Se,ke,Y,0,1,X,K),ye=de+r;for(let oe=0;oe<n;oe+=_e)we=Math.min(n-oe,_e),_r(Lt,Lt,we,r,r,na,i,s+oe,o,X,Se,ke,qn,X,ye,_e),xn(wa,we,r,X,ye,_e,i,s+oe,o)}else if(T&&F){Se=0,ke=r,_e=Math.max(r,Math.min(n,Math.floor(te/r))),J=Se+ke*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(cn,r,r,i,s,o,f,d,p),r>1&&ls(Un,r-1,r-1,qn,qn,f,d+1,p),Fc(n,r,r,i,s,o,X,J),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,f,d,p,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(Un,r,r,f,d,p,X,Se,ke),Yr(wo,r,r,r,X,Se,ke,X,fe,X,K,te-K),Yr(So,r,r,r,f,d,p,X,ae,X,K,te-K),K=de+r,b=_s(cn,r,r,r,0,a,l,X,de,f,d,p,X,Se,ke,Y,0,1,X,K),ye=de+r;for(let oe=0;oe<n;oe+=_e)we=Math.min(n-oe,_e),_r(Lt,Lt,we,r,r,na,i,s+oe,o,X,Se,ke,qn,X,ye,_e),xn(wa,we,r,X,ye,_e,i,s+oe,o)}else M?j?(Se=0,ke=r,J=Se+ke*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(cn,r,r,i,s,o,X,Se,ke),ls(Un,r-1,r-1,qn,qn,X,Se+1,ke),Fc(n,r,r,i,s,o,X,J),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,Se,ke,a,l,X,de,X,fe,X,ae,X,K,te-K),Yr(wo,r,r,r,X,Se,ke,X,fe,X,K,te-K),K=de+r,b=_s(cn,r,0,r,0,a,l,X,de,Y,0,1,X,Se,ke,Y,0,1,X,K),_r(Lt,Lt,n,r,r,na,i,s,o,X,Se,ke,qn,c,u,h)):L?(ye=0,_e=r,Se=ye+_e*r,ke=r,J=Se+ke*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(cn,r,r,i,s,o,X,ye,_e),ls(Un,r-1,r-1,qn,qn,X,ye+1,_e),Fc(n,r,r,i,s,o,X,J),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(cn,r,r,X,ye,_e,X,Se,ke),Yr(wo,r,r,r,X,ye,_e,X,fe,X,K,te-K),Yr(So,r,r,r,X,Se,ke,X,ae,X,K,te-K),K=de+r,b=_s(cn,r,r,r,0,a,l,X,de,X,Se,ke,X,ye,_e,Y,0,1,X,K),_r(Lt,Lt,n,r,r,na,i,s,o,X,ye,_e,qn,c,u,h),xn(wa,r,r,X,Se,ke,i,s,o)):F&&(ye=0,_e=r,J=ye+_e*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(cn,r,r,i,s,o,X,ye,_e),ls(Un,r-1,r-1,qn,qn,X,ye+1,_e),Fc(n,r,r,i,s,o,X,J),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(cn,r,r,X,ye,_e,f,d,p),Yr(wo,r,r,r,X,ye,_e,X,fe,X,K,te-K),Yr(So,r,r,r,f,d,p,X,ae,X,K,te-K),K=de+r,b=_s(cn,r,r,r,0,a,l,X,de,f,d,p,X,ye,_e,Y,0,1,X,K),_r(Lt,Lt,n,r,r,na,i,s,o,X,ye,_e,qn,c,u,h)):S&&(j?(Se=0,ke=r,J=Se+ke*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(Un,n,r,i,s,o,c,u,h),xn(cn,r,r,i,s,o,X,Se,ke),ls(Un,r-1,r-1,qn,qn,X,Se+1,ke),Fc(n,n,r,c,u,h,X,J),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,Se,ke,a,l,X,de,X,fe,X,ae,X,K,te-K),Yr(wo,r,r,r,X,Se,ke,X,fe,X,K,te-K),K=de+r,b=_s(cn,r,0,r,0,a,l,X,de,Y,0,1,X,Se,ke,Y,0,1,X,K),_r(Lt,Lt,n,r,r,na,c,u,h,X,Se,ke,qn,i,s,o),xn(wa,n,r,i,s,o,c,u,h)):L?(ye=0,_e=r,Se=ye+_e*r,ke=r,J=Se+ke*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(Un,n,r,i,s,o,c,u,h),Fc(n,n,r,c,u,h,X,J),xn(cn,r,r,i,s,o,X,ye,_e),ls(Un,r-1,r-1,qn,qn,X,ye+1,_e),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(cn,r,r,X,ye,_e,X,Se,ke),Yr(wo,r,r,r,X,ye,_e,X,fe,X,K,te-K),Yr(So,r,r,r,X,Se,ke,X,ae,X,K,te-K),K=de+r,b=_s(cn,r,r,r,0,a,l,X,de,X,Se,ke,X,ye,_e,Y,0,1,X,K),_r(Lt,Lt,n,r,r,na,c,u,h,X,ye,_e,qn,i,s,o),xn(wa,n,r,i,s,o,c,u,h),xn(wa,r,r,X,Se,ke,i,s,o)):F&&(ye=0,_e=r,J=ye+_e*r,K=J+r,Fh(n,r,i,s,o,X,J),xn(Un,n,r,i,s,o,c,u,h),Fc(n,n,r,c,u,h,X,J),xn(cn,r,r,i,s,o,X,ye,_e),ls(Un,r-1,r-1,qn,qn,X,ye+1,_e),de=J,fe=de+r,ae=fe+r,K=ae+r,io(r,r,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(cn,r,r,X,ye,_e,f,d,p),Yr(wo,r,r,r,X,ye,_e,X,fe,X,K,te-K),Yr(So,r,r,r,f,d,p,X,ae,X,K,te-K),K=de+r,b=_s(cn,r,r,r,0,a,l,X,de,f,d,p,X,ye,_e,Y,0,1,X,K),_r(Lt,Lt,n,r,r,na,c,u,h,X,ye,_e,qn,i,s,o),xn(wa,n,r,i,s,o,c,u,h)));else de=0,fe=de+r,ae=fe+r,K=ae+r,io(n,r,i,s,o,a,l,X,de,X,fe,X,ae,X,K,te-K),E&&(xn(Un,n,r,i,s,o,c,u,h),Ue=M?r:n,Yr(wo,n,Ue,r,c,u,h,X,fe,X,K,te-K)),F&&(xn(cn,r,r,i,s,o,f,d,p),Yr(So,r,r,r,f,d,p,X,ae,X,K,te-K)),T&&Yr(wo,n,r,r,i,s,o,X,fe,X,K,te-K),L&&Yr(So,r,r,r,i,s,o,X,ae,X,K,te-K),K=de+r,Fe=0,(E||T)&&(Fe=n),k&&(Fe=0),Ge=0,(F||L)&&(Ge=r),j&&(Ge=0),!T&&!L?b=_s(cn,r,Ge,Fe,0,a,l,X,de,f,d,p,c,u,h,Y,0,1,X,K):!T&&L?b=_s(cn,r,Ge,Fe,0,a,l,X,de,i,s,o,c,u,h,Y,0,1,X,K):b=_s(cn,r,Ge,Fe,0,a,l,X,de,f,d,p,i,s,o,Y,0,1,X,K);else if(r>=N)if(j)J=0,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),n>1&&ls(cn,n-1,n-1,qn,qn,i,s+o,o),de=0,fe=de+n,ae=fe+n,K=ae+n,io(n,n,i,s,o,a,l,X,de,X,fe,X,ae,X,K,te-K),(T||E)&&Yr(wo,n,n,n,i,s,o,X,fe,X,K,te-K),K=de+n,Fe=0,(T||E)&&(Fe=n),b=_s(cn,n,0,Fe,0,a,l,X,de,Y,0,1,i,s,o,Y,0,1,X,K),E&&xn(wa,n,n,i,s,o,c,u,h);else if(L&&k){Se=0,ke=n,_e=n,we=Math.max(n,Math.min(r,Math.floor(te/n))),J=Se+ke*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(Un,n,n,i,s,o,X,Se,ke),ls(cn,n-1,n-1,qn,qn,X,Se+ke,ke),_u(n,r,n,i,s,o,X,J,X,K,te-K),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,Se,ke,a,l,X,de,X,fe,X,ae,X,K,te-K),Yr(So,n,n,n,X,Se,ke,X,ae,X,K,te-K),K=de+n,b=_s(cn,n,n,0,0,a,l,X,de,X,Se,ke,Y,0,1,Y,0,1,X,K),ye=de+n;for(let oe=0;oe<r;oe+=we)Le=Math.min(r-oe,we),_r(Lt,Lt,n,Le,n,na,X,Se,ke,i,s+oe*o,o,qn,X,ye,_e),xn(wa,n,Le,X,ye,_e,i,s+oe*o,o)}else if(L&&E){Se=0,ke=n,_e=n,we=Math.max(n,Math.min(r,Math.floor(te/n))),J=Se+ke*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(Un,n,n,i,s,o,c,u,h),n>1&&ls(cn,n-1,n-1,qn,qn,c,u+h,h),_u(n,r,n,i,s,o,X,J,X,K,te-K),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,c,u,h,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(cn,n,n,c,u,h,X,Se,ke),Yr(So,n,n,n,X,Se,ke,X,ae,X,K,te-K),Yr(wo,n,n,n,c,u,h,X,fe,X,K,te-K),K=de+n,b=_s(cn,n,n,n,0,a,l,X,de,X,Se,ke,c,u,h,Y,0,1,X,K),ye=de+n;for(let oe=0;oe<r;oe+=we)Le=Math.min(r-oe,we),_r(Lt,Lt,n,Le,n,na,X,Se,ke,i,s+oe*o,o,qn,X,ye,_e),xn(wa,n,Le,X,ye,_e,i,s+oe*o,o)}else B?k?(Se=0,ke=n,J=Se+ke*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(Un,n,n,i,s,o,X,Se,ke),ls(cn,n-1,n-1,qn,qn,X,Se+ke,ke),_u(n,r,n,i,s,o,X,J,X,K,te-K),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,Se,ke,a,l,X,de,X,fe,X,ae,X,K,te-K),Yr(So,n,n,n,X,Se,ke,X,ae,X,K,te-K),K=de+n,b=_s(cn,n,n,0,0,a,l,X,de,X,Se,ke,Y,0,1,Y,0,1,X,K),_r(Lt,Lt,n,r,n,na,X,Se,ke,i,s,o,qn,f,d,p)):T?(ye=0,_e=n,Se=ye+_e*n,ke=n,J=Se+ke*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(Un,n,n,i,s,o,X,ye,_e),ls(cn,n-1,n-1,qn,qn,X,ye+_e,_e),_u(n,r,n,i,s,o,X,J,X,K,te-K),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(Un,n,n,X,ye,_e,X,Se,ke),Yr(So,n,n,n,X,ye,_e,X,ae,X,K,te-K),Yr(wo,n,n,n,X,Se,ke,X,fe,X,K,te-K),K=de+n,b=_s(cn,n,n,n,0,a,l,X,de,X,ye,_e,X,Se,ke,Y,0,1,X,K),_r(Lt,Lt,n,r,n,na,X,ye,_e,i,s,o,qn,f,d,p),xn(wa,n,n,X,Se,ke,i,s,o)):E&&(ye=0,_e=n,J=ye+_e*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(Un,n,n,i,s,o,X,ye,_e),ls(cn,n-1,n-1,qn,qn,X,ye+_e,_e),_u(n,r,n,i,s,o,X,J,X,K,te-K),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(Un,n,n,X,ye,_e,c,u,h),Yr(So,n,n,n,X,ye,_e,X,ae,X,K,te-K),Yr(wo,n,n,n,c,u,h,X,fe,X,K,te-K),K=de+n,b=_s(cn,n,n,n,0,a,l,X,de,X,ye,_e,c,u,h,Y,0,1,X,K),_r(Lt,Lt,n,r,n,na,X,ye,_e,i,s,o,qn,f,d,p)):R&&(k?(Se=0,ke=n,J=Se+ke*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(cn,n,r,i,s,o,f,d,p),xn(Un,n,n,i,s,o,X,Se,ke),ls(cn,n-1,n-1,qn,qn,X,Se+ke,ke),_u(r,r,n,f,d,p,X,J,X,K,te-K),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,Se,ke,a,l,X,de,X,fe,X,ae,X,K,te-K),Yr(So,n,n,n,X,Se,ke,X,ae,X,K,te-K),K=de+n,b=_s(cn,n,n,0,0,a,l,X,de,X,Se,ke,Y,0,1,Y,0,1,X,K),_r(Lt,Lt,n,r,n,na,X,Se,ke,f,d,p,qn,i,s,o),xn(wa,n,r,i,s,o,f,d,p)):T?(ye=0,_e=n,Se=ye+_e*n,ke=n,J=Se+ke*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(cn,n,r,i,s,o,f,d,p),_u(r,r,n,f,d,p,X,J,X,K,te-K),xn(Un,n,n,i,s,o,X,ye,_e),ls(cn,n-1,n-1,qn,qn,X,ye+_e,_e),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(Un,n,n,X,ye,_e,X,Se,ke),Yr(So,n,n,n,X,ye,_e,X,ae,X,K,te-K),Yr(wo,n,n,n,X,Se,ke,X,fe,X,K,te-K),K=de+n,b=_s(cn,n,n,n,0,a,l,X,de,X,ye,_e,X,Se,ke,Y,0,1,X,K),_r(Lt,Lt,n,r,n,na,X,ye,_e,f,d,p,qn,i,s,o),xn(wa,n,r,i,s,o,f,d,p),xn(wa,n,n,X,Se,ke,i,s,o)):E&&(ye=0,_e=n,J=ye+_e*n,K=J+n,Bh(n,r,i,s,o,X,J,X,K,te-K),xn(cn,n,r,i,s,o,f,d,p),_u(r,r,n,f,d,p,X,J,X,K,te-K),xn(Un,n,n,i,s,o,X,ye,_e),ls(cn,n-1,n-1,qn,qn,X,ye+_e,_e),de=J,fe=de+n,ae=fe+n,K=ae+n,io(n,n,X,ye,_e,a,l,X,de,X,fe,X,ae,X,K,te-K),xn(Un,n,n,X,ye,_e,c,u,h),Yr(So,n,n,n,X,ye,_e,X,ae,X,K,te-K),Yr(wo,n,n,n,c,u,h,X,fe,X,K,te-K),K=de+n,b=_s(cn,n,n,n,0,a,l,X,de,X,ye,_e,c,u,h,Y,0,1,X,K),_r(Lt,Lt,n,r,n,na,X,ye,_e,f,d,p,qn,i,s,o),xn(wa,n,r,i,s,o,f,d,p)));else de=0,fe=de+n,ae=fe+n,K=ae+n,io(n,r,i,s,o,a,l,X,de,X,fe,X,ae,X,K,te-K),E&&(xn(Un,n,n,i,s,o,c,u,h),Yr(wo,n,n,r,c,u,h,X,fe,X,K,te-K)),F&&(xn(cn,n,r,i,s,o,f,d,p),Ee=R?r:n,Yr(So,Ee,r,n,f,d,p,X,ae,X,K,te-K)),T&&Yr(wo,n,n,r,i,s,o,X,fe,X,K,te-K),L&&Yr(So,n,r,n,i,s,o,X,ae,X,K,te-K),K=de+n,Fe=0,(E||T)&&(Fe=n),k&&(Fe=0),Ge=0,(F||L)&&(Ge=r),j&&(Ge=0),!T&&!L?b=_s(Un,n,Ge,Fe,0,a,l,X,de,f,d,p,c,u,h,Y,0,1,X,K):!T&&L?b=_s(Un,n,Ge,Fe,0,a,l,X,de,i,s,o,c,u,h,Y,0,1,X,K):b=_s(Un,n,Ge,Fe,0,a,l,X,de,f,d,p,i,s,o,Y,0,1,X,K);if(b!==0){if(de>1)for(let oe=0;oe<x-1;oe++)m[y+oe+1]=X[oe+de];if(de<1)for(let oe=x-2;oe>=0;oe--)m[y+oe+1]=X[oe+de]}return ge===1&&(ue>ie&&Oc($g,0,0,ie,ue,x,1,a,l,x),b!==0&&ue>ie&&Oc($g,0,0,ie,ue,x-1,1,m,y+1,x),ue<Z&&Oc($g,0,0,Z,ue,x,1,a,l,x),b!==0&&ue<Z&&Oc($g,0,0,Z,ue,x-1,1,m,y+1,x)),m[y]=P,b}function Vhe(e,t,n,r,i){const s=e===cn;let o=0;if(!s&&e!==Un?o=-1:t<0?o=-2:i<Math.max(1,t)&&(o=-5),o!==0)return ts("DPOTF2",-o),o;if(t===0)return 0;if(s)for(let a=1;a<=t;a++){let l=n[r+(a-1)+(a-1)*i]-Bc(a-1,n,r+(a-1)*i,1,n,r+(a-1)*i,1);if(l<=0||Number.isNaN(l))return n[r+(a-1)+(a-1)*i]=l,a;l=Math.sqrt(l),n[r+(a-1)+(a-1)*i]=l,a<t&&(Yn(Kn,a-1,t-a,-1,n,r+a*i,i,n,r+(a-1)*i,1,1,n,r+(a-1)+a*i,i),zn(t-a,1/l,n,r+(a-1)+a*i,i))}else for(let a=1;a<=t;a++){let l=n[r+(a-1)+(a-1)*i]-Bc(a-1,n,r+(a-1),i,n,r+(a-1),i);if(l<=0||Number.isNaN(l))return n[r+(a-1)+(a-1)*i]=l,a;l=Math.sqrt(l),n[r+(a-1)+(a-1)*i]=l,a<t&&(Yn(Lt,t-a,a-1,-1,n,r+a,i,n,r+(a-1),i,1,n,r+a+(a-1)*i,1),zn(t-a,1/l,n,r+a+(a-1)*i,1))}return 0}function Whe(e,t,n,r,i,s,o,a){if(e<0)throw new Error("** On entry to 'DORGQR' parameter number 1 had an illegal value");if(t<0||t>e)throw new Error("** On entry to 'DORGQR' parameter number 2 had an illegal value");if(n<0||n>t)throw new Error("** On entry to 'DORGQR' parameter number 3 had an illegal value");if(s<Math.max(1,e))throw new Error("** On entry to 'DORGQR' parameter number 5 had an illegal value");if(t<=0)return 0;const l=D(e);for(let c=n;c<t;c++){const u=i+c*s;r.fill(0,u,u+e),r[u+c]=1}for(let c=n;c>=1;c--){const u=c-1,h=i+u*s,f=h+u,d=o[a+u];if(c<t&&d!==0){const p=e-u,m=t-c,y=f+s;l[0]=1;for(let _=1;_<p;_++)l[_]=r[f+_];for(let _=0;_<m;_++){const b=y+_*s;let x=0;for(let M=0;M<p;M++)x+=l[M]*r[b+M];const S=d*x;for(let M=0;M<p;M++)r[b+M]-=S*l[M]}}if(c<e){const p=-d;if(p!==1){const m=h+e;for(let y=f+1;y<m;y++)r[y]*=p}}r[f]=1-d,r.fill(0,h,f)}return 0}const S$=Number.EPSILON*.5,I8=22250738585072014e-324,P8=1/Number.MAX_VALUE,qhe=P8>=I8?P8*(1+S$):I8,PS=qhe/S$,bT=1/PS,B8=Number.MAX_VALUE;function _R(e,t,n,r,i,s,o){if(e<0)throw new Error("** On entry to 'DGEQRF' parameter number 1 had an illegal value");if(t<0)throw new Error("** On entry to 'DGEQRF' parameter number 2 had an illegal value");if(i<Math.max(1,e))throw new Error("** On entry to 'DGEQRF' parameter number 4 had an illegal value");const a=Math.min(e,t);if(a===0)return 0;const l=D(e);for(let c=1;c<=a;c++){const u=r+(c-1)+(c-1)*i,h=e-c+1;let f;if(h<=1)f=0;else{const d=u+1,p=h-1,m=d+p;let y=n[u],_;if(p===1)_=Math.abs(n[d]);else{let b=0,x=1;for(let S=d;S<m;S++){const M=Math.abs(n[S]);M>0&&(b<M?(x=1+x*(b/M)*(b/M),b=M):x+=M/b*(M/b))}_=b*Math.sqrt(x)}if(_===0)f=0;else{let b;{const S=Math.abs(y),M=S>_?S:_,E=S<_?S:_;b=E===0||M>B8?M:M*Math.sqrt(1+E/M*(E/M)),b=y>=0?-b:b}let x=0;if(Math.abs(b)<PS){do{x++;for(let S=d;S<m;S++)n[S]*=bT;b*=bT,y*=bT}while(Math.abs(b)<PS&&x<20);if(p===1)_=Math.abs(n[d]);else{let S=0,M=1;for(let E=d;E<m;E++){const T=Math.abs(n[E]);T>0&&(S<T?(M=1+M*(S/T)*(S/T),S=T):M+=T/S*(T/S))}_=S*Math.sqrt(M)}{const S=Math.abs(y),M=S>_?S:_,E=S<_?S:_;b=E===0||M>B8?M:M*Math.sqrt(1+E/M*(E/M)),b=y>=0?-b:b}}f=(b-y)/b;{const S=1/(y-b);for(let M=d;M<m;M++)n[M]*=S}for(let S=1;S<=x;S++)b*=PS;n[u]=b}}if(s[o+(c-1)]=f,c<t&&f!==0){const d=e-c+1,p=t-c,m=r+(c-1)+c*i;l[0]=1;for(let b=1;b<d;b++)l[b]=n[u+b];let y=d;for(;y>1&&l[y-1]===0;)y--;let _;if(p===0)_=0;else if(n[m+(p-1)*i]!==0||n[m+(y-1)+(p-1)*i]!==0)_=p;else{_=0;e:for(let b=p;b>=1;b--){const x=m+(b-1)*i;for(let S=0;S<y;S++)if(n[x+S]!==0){_=b;break e}}}if(_===0)continue;if(y===1){const b=1-f;for(let x=0;x<_;x++)n[m+x*i]*=b}else for(let b=0;b<_;b++){const x=m+b*i;let S=0;for(let E=0;E<y;E++)S+=l[E]*n[x+E];const M=f*S;for(let E=0;E<y;E++)n[x+E]-=M*l[E]}}}return 0}function Ghe(e,t,n,r,i,s,o,a,l,c,u,h,f,d,p,m){const y=n,_=i;let b=0;if(n<0?b=3:r<0?b=4:i<0?b=5:l<Math.max(1,y)?b=8:h<Math.max(1,_)?b=10:m<Math.max(1,n)&&(b=13),b!==0){ts("DGEMM ",b);return}if(!(n===0||r===0||i===0&&f===1))for(let x=0;x<r;x++){const S=u+x*h,M=p+x*m;d.fill(0,M,M+n);for(let E=0;E<i;E++){const T=s*c[S+E],k=a+E*l;for(let R=0;R<n;R++)d[M+R]+=T*o[k+R]}}}const qL=2220446049250313e-31,GL=22250738585072014e-324;function Ts(e,t){return Math.abs(e)+Math.abs(t)}function $M(e,t,n,r){if(Math.abs(n)>=Math.abs(r)){const i=r/n,s=n+r*i;return[(e+t*i)/s,(t-e*i)/s]}else{const i=n/r,s=n*i+r;return[(e*i+t)/s,(t*i-e)/s]}}function Xhe(e,t){return t>=0?Math.abs(e):-Math.abs(e)}function M$(e,t,n,r,i){if(e<=0)return[0,0];let s=0;for(let p=1;p<e;p++){const m=r+p*i;s+=t[m]*t[m]+n[m]*n[m]}const o=Math.sqrt(s),a=t[r],l=n[r];if(o===0&&l===0)return[0,0];const c=-Xhe(Math.hypot(a,l,o),a),u=(c-a)/c,h=-l/c,[f,d]=$M(1,0,a-c,l);for(let p=1;p<e;p++){const m=r+p*i,y=t[m],_=n[m];t[m]=y*f-_*d,n[m]=y*d+_*f}return t[r]=c,n[r]=0,[u,h]}function Yhe(e,t,n,r,i,s){const o=D(e),a=D(e);for(let l=1;l<=e-2;l++){const c=(l-1)*e,[u,h]=M$(e-l,t,n,c+l,1);o[0]=1,a[0]=0;for(let f=l+2;f<=e;f++)o[f-l-1]=t[c+(f-1)],a[f-l-1]=n[c+(f-1)];(u!==0||h!==0)&&(F8(t,n,e,1,e,l+1,e,o,a,u,h),Khe(t,n,e,l+1,e,l+1,e,o,a,u,-h),s&&F8(r,i,e,1,e,l+1,e,o,a,u,h));for(let f=l+2;f<=e;f++)t[c+(f-1)]=0,n[c+(f-1)]=0}}function Khe(e,t,n,r,i,s,o,a,l,c,u){for(let h=s;h<=o;h++){const f=(h-1)*n;let d=0,p=0;for(let _=0;_<=i-r;_++){const b=f+(r-1+_),x=a[_],S=l[_];d+=x*e[b]+S*t[b],p+=x*t[b]-S*e[b]}const m=c*d-u*p,y=c*p+u*d;for(let _=0;_<=i-r;_++){const b=f+(r-1+_),x=a[_],S=l[_];e[b]-=x*m-S*y,t[b]-=x*y+S*m}}}function F8(e,t,n,r,i,s,o,a,l,c,u){for(let h=r;h<=i;h++){let f=0,d=0;for(let y=0;y<=o-s;y++){const _=(s-1+y)*n+(h-1),b=a[y],x=l[y];f+=e[_]*b-t[_]*x,d+=e[_]*x+t[_]*b}const p=c*f-u*d,m=c*d+u*f;for(let y=0;y<=o-s;y++){const _=(s-1+y)*n+(h-1),b=a[y],x=l[y];e[_]-=p*b+m*x,t[_]-=m*b-p*x}}}function Zhe(e,t,n,r,i,s,o,a,l,c,u,h,f){const d=(V,O)=>(O-1)*n+(V-1),p=(V,O)=>(O-1)*n+(V-1);if(n===0)return 0;if(r===i)return a[r-1]=s[d(r,r)],l[r-1]=o[d(r,r)],0;for(let V=r;V<=i-3;V++)s[d(V+2,V)]=0,o[d(V+2,V)]=0,s[d(V+3,V)]=0,o[d(V+3,V)]=0;r<=i-2&&(s[d(i,i-2)]=0,o[d(i,i-2)]=0);const _=e?1:r,b=e?n:i;for(let V=r+1;V<=i;V++)if(o[d(V,V-1)]!==0){const O=s[d(V,V-1)],P=o[d(V,V-1)],N=Ts(O,P);let H=O/N,U=P/N;const G=Math.hypot(H,U);H=H/G,U=-U/G;const Z=Math.hypot(O,P);s[d(V,V-1)]=Z,o[d(V,V-1)]=0,Uh(s,o,H,U,d(V,V),n,b-V+1),Uh(s,o,H,-U,d(_,V),1,Math.min(b,V+1)-_+1),t&&Uh(h,f,H,-U,p(c,V),1,u-c+1)}const x=i-r+1,S=u-c+1,M=qL,E=GL*(x/M);let T=1,k=n;const R=30*Math.max(10,x);let B=0;const F=new Float64Array(2),L=new Float64Array(2);let j=i;for(;j>=r;){let V=r,O=!1;for(let P=0;P<=R;P++){let N;for(N=j;N>=V+1&&!(Ts(s[d(N,N-1)],o[d(N,N-1)])<=E);N--){let ue=Ts(s[d(N-1,N-1)],o[d(N-1,N-1)])+Ts(s[d(N,N)],o[d(N,N)]);if(ue===0&&(N-2>=r&&(ue+=Math.abs(s[d(N-1,N-2)])),N+1<=i&&(ue+=Math.abs(s[d(N+1,N)]))),Math.abs(s[d(N,N-1)])<=M*ue){const ge=Math.max(Ts(s[d(N,N-1)],o[d(N,N-1)]),Ts(s[d(N-1,N)],o[d(N-1,N)])),te=Math.min(Ts(s[d(N,N-1)],o[d(N,N-1)]),Ts(s[d(N-1,N)],o[d(N-1,N)])),X=s[d(N-1,N-1)]-s[d(N,N)],de=o[d(N-1,N-1)]-o[d(N,N)],fe=Math.max(Ts(s[d(N,N)],o[d(N,N)]),Ts(X,de)),ae=Math.min(Ts(s[d(N,N)],o[d(N,N)]),Ts(X,de)),J=fe+ge;if(te*(ge/J)<=Math.max(E,M*(ae*(fe/J))))break}}if(V=N,V>r&&(s[d(V,V-1)]=0,o[d(V,V-1)]=0),V>=j){O=!0;break}B++,e||(T=V,k=j);let H,U;if(B%20===0)H=.75*Math.abs(s[d(j,j-1)])+s[d(j,j)],U=o[d(j,j)];else if(B%10===0)H=.75*Math.abs(s[d(V+1,V)])+s[d(V,V)],U=o[d(V,V)];else{H=s[d(j,j)],U=o[d(j,j)];const[ue,ge]=xT(s[d(j-1,j)],o[d(j-1,j)]),[te,X]=xT(s[d(j,j-1)],o[d(j,j-1)]),de=ue*te-ge*X,fe=ue*X+ge*te;let ae=Ts(de,fe);if(ae!==0){const J=.5*(s[d(j-1,j-1)]-H),K=.5*(o[d(j-1,j-1)]-U),Se=Ts(J,K);ae=Math.max(ae,Se);const ye=J/ae,Ge=K/ae,Fe=de/ae,Ue=fe/ae,Ee=ye*ye-Ge*Ge+(Fe*Fe-Ue*Ue),ke=2*ye*Ge+2*Fe*Ue,[_e,we]=xT(Ee,ke);let Le=ae*_e,oe=ae*we;if(Se>0){const ve=J/Se,Be=K/Se;ve*Le+Be*oe<0&&(Le=-Le,oe=-oe)}const[Q,xe]=$M(de,fe,J+Le,K+oe),me=de*Q-fe*xe,be=de*xe+fe*Q;H-=me,U-=be}}let G,Z=0,ie=0,Y=0;for(G=j-1;G>=V+1;G--){const ue=s[d(G,G)],ge=o[d(G,G)],te=s[d(G+1,G+1)],X=o[d(G+1,G+1)];let de=ue-H,fe=ge-U,ae=s[d(G+1,G)];const J=Ts(de,fe)+Math.abs(ae);de/=J,fe/=J,ae/=J,Z=de,ie=fe,Y=ae;const K=s[d(G,G-1)];if(Math.abs(K)*Math.abs(ae)<=M*(Ts(de,fe)*(Ts(ue,ge)+Ts(te,X))))break}if(G<V+1){G=V;const ue=s[d(V,V)],ge=o[d(V,V)];let te=ue-H,X=ge-U,de=s[d(V+1,V)];const fe=Ts(te,X)+Math.abs(de);te/=fe,X/=fe,de/=fe,Z=te,ie=X,Y=de}for(let ue=G;ue<=j-1;ue++){ue>G?(F[0]=s[d(ue,ue-1)],L[0]=o[d(ue,ue-1)],F[1]=s[d(ue+1,ue-1)],L[1]=o[d(ue+1,ue-1)]):(F[0]=Z,L[0]=ie,F[1]=Y,L[1]=0);const[ge,te]=M$(2,F,L,0,1);ue>G&&(s[d(ue,ue-1)]=F[0],o[d(ue,ue-1)]=L[0],s[d(ue+1,ue-1)]=0,o[d(ue+1,ue-1)]=0);const X=F[1],de=L[1],fe=ge*X-te*de;for(let J=ue;J<=k;J++){const K=d(ue,J),Se=d(ue+1,J),ye=ge*s[K]+te*o[K]+fe*s[Se],Ge=ge*o[K]-te*s[K]+fe*o[Se];s[K]-=ye,o[K]-=Ge,s[Se]-=ye*X-Ge*de,o[Se]-=ye*de+Ge*X}const ae=Math.min(ue+2,j);for(let J=T;J<=ae;J++){const K=d(J,ue),Se=d(J,ue+1),ye=ge*s[K]-te*o[K]+fe*s[Se],Ge=ge*o[K]+te*s[K]+fe*o[Se];s[K]-=ye,o[K]-=Ge,s[Se]-=ye*X+Ge*de,o[Se]-=Ge*X-ye*de}if(t)for(let J=c;J<=u;J++){const K=p(J,ue),Se=p(J,ue+1),ye=ge*h[K]-te*f[K]+fe*h[Se],Ge=ge*f[K]+te*h[K]+fe*f[Se];h[K]-=ye,f[K]-=Ge,h[Se]-=ye*X+Ge*de,f[Se]-=Ge*X-ye*de}if(ue===G&&G>V){let J=1-ge,K=-te;const Se=Math.hypot(J,K);J/=Se,K/=Se;{const ye=d(G+1,G),Ge=s[ye],Fe=o[ye];s[ye]=Ge*J+Fe*K,o[ye]=Fe*J-Ge*K}if(G+2<=j){const ye=d(G+2,G+1),Ge=s[ye],Fe=o[ye];s[ye]=Ge*J-Fe*K,o[ye]=Ge*K+Fe*J}for(let ye=G;ye<=j;ye++)ye!==G+1&&(k>ye&&Uh(s,o,J,K,d(ye,ye+1),n,k-ye),Uh(s,o,J,-K,d(T,ye),1,ye-T),t&&Uh(h,f,J,-K,p(c,ye),1,S))}}{const ue=d(j,j-1);if(o[ue]!==0){const ge=Math.hypot(s[ue],o[ue]),te=s[ue]/ge,X=o[ue]/ge;s[ue]=ge,o[ue]=0,k>j&&Uh(s,o,te,-X,d(j,j+1),n,k-j),Uh(s,o,te,X,d(T,j),1,j-T),t&&Uh(h,f,te,X,p(c,j),1,S)}}}if(!O)return j;a[j-1]=s[d(j,j)],l[j-1]=o[d(j,j)],B=0,j=V-1}return 0}function xT(e,t){if(e===0&&t===0)return[0,0];const n=Math.hypot(e,t),r=Math.sqrt((n+Math.abs(e))/2);if(e>=0)return[r,t/(2*r)];{const i=t>=0?r:-r;return[t/(2*i),i]}}function Uh(e,t,n,r,i,s,o){for(let a=0;a<o;a++){const l=i+a*s,c=e[l],u=t[l];e[l]=c*n-u*r,t[l]=c*r+u*n}}function Qhe(e,t,n,r,i){const s=(u,h)=>(h-1)*e+(u-1),o=qL,a=GL*(e/o),l=new Float64Array(e),c=new Float64Array(e);for(let u=e;u>=1;u--){const h=Math.max(o*Ts(t[s(u,u)],n[s(u,u)]),a);l[u-1]=1,c[u-1]=0;for(let p=1;p<=u-1;p++)l[p-1]=-t[s(p,u)],c[p-1]=-n[s(p,u)];const f=t[s(u,u)],d=n[s(u,u)];for(let p=u-1;p>=1;p--){let m=t[s(p,p)]-f,y=n[s(p,p)]-d;Ts(m,y)<h&&(m=h,y=0);const[_,b]=$M(l[p-1],c[p-1],m,y);l[p-1]=_,c[p-1]=b;for(let x=1;x<=p-1;x++){const S=s(x,p);l[x-1]-=_*t[S]-b*n[S],c[x-1]-=_*n[S]+b*t[S]}}efe(e,r,i,l,c,u)}}function Jhe(e,t,n,r,i){const s=(u,h)=>(h-1)*e+(u-1),o=qL,a=GL*(e/o),l=new Float64Array(e),c=new Float64Array(e);for(let u=1;u<=e;u++){const h=Math.max(o*Ts(t[s(u,u)],n[s(u,u)]),a);l[u-1]=1,c[u-1]=0;for(let p=u+1;p<=e;p++)l[p-1]=-t[s(u,p)],c[p-1]=n[s(u,p)];const f=t[s(u,u)],d=n[s(u,u)];for(let p=u+1;p<=e;p++){let m=t[s(p,p)]-f,y=n[s(p,p)]-d;Ts(m,y)<h&&(m=h,y=0);let _=l[p-1],b=c[p-1];for(let M=u+1;M<=p-1;M++){const E=s(M,p),T=t[E],k=-n[E];_-=T*l[M-1]-k*c[M-1],b-=T*c[M-1]+k*l[M-1]}const[x,S]=$M(_,b,m,-y);l[p-1]=x,c[p-1]=S}tfe(e,r,i,l,c,u)}}function efe(e,t,n,r,i,s){const o=new Float64Array(e),a=new Float64Array(e);for(let l=0;l<e;l++){let c=0,u=0;for(let h=1;h<=s;h++){const f=(h-1)*e+l,d=r[h-1],p=i[h-1];c+=t[f]*d-n[f]*p,u+=t[f]*p+n[f]*d}o[l]=c,a[l]=u}E$(e,t,n,o,a,s)}function tfe(e,t,n,r,i,s){const o=new Float64Array(e),a=new Float64Array(e);for(let l=0;l<e;l++){let c=t[(s-1)*e+l],u=n[(s-1)*e+l];for(let h=s+1;h<=e;h++){const f=(h-1)*e+l,d=r[h-1],p=i[h-1];c+=t[f]*d-n[f]*p,u+=t[f]*p+n[f]*d}o[l]=c,a[l]=u}E$(e,t,n,o,a,s)}function E$(e,t,n,r,i,s){let o=0;for(let c=0;c<e;c++)o+=r[c]*r[c]+i[c]*i[c];if(o=Math.sqrt(o),o>0){const c=1/o;for(let u=0;u<e;u++)r[u]*=c,i[u]*=c}let a=0,l=-1;for(let c=0;c<e;c++){const u=r[c]*r[c]+i[c]*i[c];u>l&&(l=u,a=c)}if(l>0){const c=Math.sqrt(l),u=r[a]/c,h=-i[a]/c;for(let f=0;f<e;f++){const d=r[f],p=i[f];r[f]=d*u-p*h,i[f]=d*h+p*u}r[a]=c,i[a]=0}for(let c=0;c<e;c++)t[(s-1)*e+c]=r[c],n[(s-1)*e+c]=i[c]}function nfe(e,t,n,r,i){const s=D(n),o=D(n);if(n===0)return{wRe:s,wIm:o};const a=D(e),l=D(t),c=r||i,u=D(n*n),h=D(n*n);if(c)for(let p=0;p<n;p++)u[p+p*n]=1;Yhe(n,a,l,u,h,c);const f=Zhe(c,c,n,1,n,a,l,s,o,1,n,u,h);if(f!==0)throw new Error(`eigComplex: QR iteration failed to converge (info=${f})`);const d={wRe:s,wIm:o};if(i){const p=D(u),m=D(h);Qhe(n,a,l,p,m),d.VRRe=p,d.VRIm=m}if(r){const p=D(u),m=D(h);Jhe(n,a,l,p,m),d.VLRe=p,d.VLIm=m}return d}function rfe(e,t){const n=D(e),r=new Int32Array(t);if(Gd(t,t,n,t,r)>0)throw new Error("inv: matrix is singular (dgetrf)");if(Sue(t,n,t,r)>0)throw new Error("inv: matrix is singular (dgetri)");return n}function ife(e,t,n,r,i){const s=D(t*i);return Ghe(Lt,Lt,t,i,n,1,e,0,t,r,0,n,0,s,0,t),s}function sfe(e,t,n,r,i){const s=Math.min(t,n),o=D(e),a=D(s),l=_R(t,n,o,0,t,a,0);if(l<0)throw new Error(`qr: dgeqrf argument error (info=${l})`);const c=r?s:t,u=D(c*n);for(let d=0;d<n;d++){const p=Math.min(d,s-1);for(let m=0;m<=p;m++)u[m+d*c]=o[m+d*t]}const h=r?s:t;let f;if(i){const d=D(t*h),p=Math.min(n,h);for(let y=0;y<p;y++)for(let _=0;_<t;_++)d[_+y*t]=o[_+y*t];const m=Whe(t,h,s,d,0,t,a,0);if(m<0)throw new Error(`qr: dorgqr argument error (info=${m})`);f=d}else f=D(0);return{Q:f,R:u}}function ofe(e,t,n,r,i){if(t===n){const s=D(e),o=D(r),a=new Int32Array(n);if(Gd(n,n,s,n,a)>0)throw new Error("linsolve: matrix is singular (dgetrf)");for(let c=0;c<n;c++){const u=a[c]-1;if(u!==c)for(let h=0;h<i;h++){const f=o[c+h*n];o[c+h*n]=o[u+h*n],o[u+h*n]=f}}for(let c=0;c<i;c++)for(let u=1;u<n;u++)for(let h=0;h<u;h++)o[u+c*n]-=s[u+h*n]*o[h+c*n];for(let c=0;c<i;c++)for(let u=n-1;u>=0;u--){for(let h=u+1;h<n;h++)o[u+c*n]-=s[u+h*n]*o[h+c*n];o[u+c*n]/=s[u+u*n]}return o}else if(t>n){const s=n,o=D(e),a=D(s);_R(t,n,o,0,t,a,0);const l=D(r);for(let u=0;u<s;u++){const h=a[u];if(h!==0)for(let f=0;f<i;f++){let d=l[u+f*t];for(let m=1;m<t-u;m++)d+=o[u+m+u*t]*l[u+m+f*t];const p=h*d;l[u+f*t]-=p;for(let m=1;m<t-u;m++)l[u+m+f*t]-=p*o[u+m+u*t]}}const c=D(n*i);for(let u=0;u<i;u++)for(let h=n-1;h>=0;h--){let f=l[h+u*t];for(let d=h+1;d<n;d++)f-=o[h+d*t]*c[d+u*n];c[h+u*n]=f/o[h+h*t]}return c}else{const s=D(n*t);for(let u=0;u<t;u++)for(let h=0;h<n;h++)s[h+u*n]=e[u+h*t];const o=t,a=D(o);_R(n,t,s,0,n,a,0);const l=D(t*i);for(let u=0;u<i;u++)for(let h=0;h<t;h++){let f=r[h+u*t];for(let d=0;d<h;d++)f-=s[d+h*n]*l[d+u*t];l[h+u*t]=f/s[h+h*n]}const c=D(n*i);for(let u=0;u<t;u++)for(let h=0;h<i;h++)c[u+h*n]=l[u+h*t];for(let u=o-1;u>=0;u--){const h=a[u];if(h!==0)for(let f=0;f<i;f++){let d=c[u+f*n];for(let m=1;m<n-u;m++)d+=s[u+m+u*n]*c[u+m+f*n];const p=h*d;c[u+f*n]-=p;for(let m=1;m<n-u;m++)c[u+m+f*n]-=p*s[u+m+u*n]}}return c}}function afe(e,t,n,r,i){const s=D(e),o=D(t),a=D(t),l=n?t:1,c=r?t:1,u=D(l*(n?t:0)),h=D(c*(r?t:0)),f=n?1:0,d=r?1:0,p=D(1);b8(f,d,t,s,0,t,o,0,a,0,u,0,l,h,0,c,p,0,-1,i);const m=Math.max(1,Math.floor(p[0])),y=D(m);s.set(e);const _=b8(f,d,t,s,0,t,o,0,a,0,u,0,l,h,0,c,y,0,m,i);if(_>0)throw new Error(`eig: QR algorithm failed to converge (info=${_})`);if(_<0)throw new Error(`eig: illegal argument (info=${_})`);return{wr:o,wi:a,VL:n?u:void 0,VR:r?h:void 0}}function lfe(e,t,n,r,i,s,o){if(n===r){const a=D(e),l=D(t),c=D(i),u=D(s),h=new Int32Array(r);for(let f=0;f<r;f++){let d=a[f+f*r]*a[f+f*r]+l[f+f*r]*l[f+f*r],p=f;for(let b=f+1;b<r;b++){const x=a[b+f*r]*a[b+f*r]+l[b+f*r]*l[b+f*r];x>d&&(d=x,p=b)}if(h[f]=p,p!==f)for(let b=0;b<r;b++){let x=a[f+b*r];a[f+b*r]=a[p+b*r],a[p+b*r]=x,x=l[f+b*r],l[f+b*r]=l[p+b*r],l[p+b*r]=x}if(d===0)throw new Error("linsolveComplex: matrix is singular");const m=a[f+f*r],y=l[f+f*r],_=m*m+y*y;for(let b=f+1;b<r;b++){const x=a[b+f*r],S=l[b+f*r],M=(x*m+S*y)/_,E=(S*m-x*y)/_;a[b+f*r]=M,l[b+f*r]=E;for(let T=f+1;T<r;T++)a[b+T*r]-=M*a[f+T*r]-E*l[f+T*r],l[b+T*r]-=M*l[f+T*r]+E*a[f+T*r]}}for(let f=0;f<r;f++){const d=h[f];if(d!==f)for(let p=0;p<o;p++){let m=c[f+p*r];c[f+p*r]=c[d+p*r],c[d+p*r]=m,m=u[f+p*r],u[f+p*r]=u[d+p*r],u[d+p*r]=m}}for(let f=0;f<o;f++)for(let d=1;d<r;d++)for(let p=0;p<d;p++){const m=a[d+p*r],y=l[d+p*r];c[d+f*r]-=m*c[p+f*r]-y*u[p+f*r],u[d+f*r]-=m*u[p+f*r]+y*c[p+f*r]}for(let f=0;f<o;f++)for(let d=r-1;d>=0;d--){for(let x=d+1;x<r;x++){const S=a[d+x*r],M=l[d+x*r];c[d+f*r]-=S*c[x+f*r]-M*u[x+f*r],u[d+f*r]-=S*u[x+f*r]+M*c[x+f*r]}const p=a[d+d*r],m=l[d+d*r],y=p*p+m*m,_=(c[d+f*r]*p+u[d+f*r]*m)/y,b=(u[d+f*r]*p-c[d+f*r]*m)/y;c[d+f*r]=_,u[d+f*r]=b}return{re:c,im:u}}else if(n>r){const a=r,l=D(e),c=D(t),u=D(a),h=D(a);for(let y=0;y<a;y++){let _=0;for(let L=y+1;L<n;L++)_+=l[L+y*n]*l[L+y*n]+c[L+y*n]*c[L+y*n];const b=l[y+y*n],x=c[y+y*n],S=b*b+x*x;if(_===0&&x===0){u[y]=0,h[y]=0;continue}const M=Math.sqrt(S+_),E=b>=0?-M:M,T=E-b,k=-x;u[y]=T/E,h[y]=k/E;const R=b-E,B=x,F=R*R+B*B;for(let L=y+1;L<n;L++){const j=l[L+y*n],V=c[L+y*n];l[L+y*n]=(j*R+V*B)/F,c[L+y*n]=(V*R-j*B)/F}l[y+y*n]=E,c[y+y*n]=0;for(let L=y+1;L<r;L++){let j=l[y+L*n],V=c[y+L*n];for(let N=1;N<n-y;N++){const H=l[y+N+y*n],U=-c[y+N+y*n];j+=H*l[y+N+L*n]-U*c[y+N+L*n],V+=H*c[y+N+L*n]+U*l[y+N+L*n]}const O=u[y]*j+h[y]*V,P=u[y]*V-h[y]*j;l[y+L*n]-=O,c[y+L*n]-=P;for(let N=1;N<n-y;N++){const H=l[y+N+y*n],U=c[y+N+y*n];l[y+N+L*n]-=H*O-U*P,c[y+N+L*n]-=H*P+U*O}}}const f=D(i),d=D(s);for(let y=0;y<a;y++)if(!(u[y]===0&&h[y]===0))for(let _=0;_<o;_++){let b=f[y+_*n],x=d[y+_*n];for(let E=1;E<n-y;E++){const T=l[y+E+y*n],k=-c[y+E+y*n];b+=T*f[y+E+_*n]-k*d[y+E+_*n],x+=T*d[y+E+_*n]+k*f[y+E+_*n]}const S=u[y]*b+h[y]*x,M=u[y]*x-h[y]*b;f[y+_*n]-=S,d[y+_*n]-=M;for(let E=1;E<n-y;E++){const T=l[y+E+y*n],k=c[y+E+y*n];f[y+E+_*n]-=T*S-k*M,d[y+E+_*n]-=T*M+k*S}}const p=D(r*o),m=D(r*o);for(let y=0;y<o;y++)for(let _=r-1;_>=0;_--){let b=f[_+y*n],x=d[_+y*n];for(let T=_+1;T<r;T++){const k=l[_+T*n],R=c[_+T*n];b-=k*p[T+y*r]-R*m[T+y*r],x-=k*m[T+y*r]+R*p[T+y*r]}const S=l[_+_*n],M=c[_+_*n],E=S*S+M*M;p[_+y*r]=(b*S+x*M)/E,m[_+y*r]=(x*S-b*M)/E}return{re:p,im:m}}else{const a=D(r*n),l=D(r*n);for(let y=0;y<n;y++)for(let _=0;_<r;_++)a[_+y*r]=e[y+_*n],l[_+y*r]=-t[y+_*n];const c=n,u=D(c),h=D(c);for(let y=0;y<c;y++){let _=0;for(let L=y+1;L<r;L++)_+=a[L+y*r]*a[L+y*r]+l[L+y*r]*l[L+y*r];const b=a[y+y*r],x=l[y+y*r],S=b*b+x*x;if(_===0&&x===0){u[y]=0,h[y]=0;continue}const M=Math.sqrt(S+_),E=b>=0?-M:M,T=E-b,k=-x;u[y]=T/E,h[y]=k/E;const R=b-E,B=x,F=R*R+B*B;for(let L=y+1;L<r;L++){const j=a[L+y*r],V=l[L+y*r];a[L+y*r]=(j*R+V*B)/F,l[L+y*r]=(V*R-j*B)/F}a[y+y*r]=E,l[y+y*r]=0;for(let L=y+1;L<n;L++){let j=a[y+L*r],V=l[y+L*r];for(let N=1;N<r-y;N++){const H=a[y+N+y*r],U=-l[y+N+y*r];j+=H*a[y+N+L*r]-U*l[y+N+L*r],V+=H*l[y+N+L*r]+U*a[y+N+L*r]}const O=u[y]*j+h[y]*V,P=u[y]*V-h[y]*j;a[y+L*r]-=O,l[y+L*r]-=P;for(let N=1;N<r-y;N++){const H=a[y+N+y*r],U=l[y+N+y*r];a[y+N+L*r]-=H*O-U*P,l[y+N+L*r]-=H*P+U*O}}}const f=D(n*o),d=D(n*o);for(let y=0;y<o;y++)for(let _=0;_<n;_++){let b=i[_+y*n],x=s[_+y*n];for(let T=0;T<_;T++){const k=a[T+_*r],R=-l[T+_*r];b-=k*f[T+y*n]-R*d[T+y*n],x-=k*d[T+y*n]+R*f[T+y*n]}const S=a[_+_*r],M=-l[_+_*r],E=S*S+M*M;f[_+y*n]=(b*S+x*M)/E,d[_+y*n]=(x*S-b*M)/E}const p=D(r*o),m=D(r*o);for(let y=0;y<n;y++)for(let _=0;_<o;_++)p[y+_*r]=f[y+_*n],m[y+_*r]=d[y+_*n];for(let y=c-1;y>=0;y--)if(!(u[y]===0&&h[y]===0))for(let _=0;_<o;_++){let b=p[y+_*r],x=m[y+_*r];for(let E=1;E<r-y;E++){const T=a[y+E+y*r],k=-l[y+E+y*r];b+=T*p[y+E+_*r]-k*m[y+E+_*r],x+=T*m[y+E+_*r]+k*p[y+E+_*r]}const S=u[y]*b-h[y]*x,M=u[y]*x+h[y]*b;p[y+_*r]-=S,m[y+_*r]-=M;for(let E=1;E<r-y;E++){const T=a[y+E+y*r],k=l[y+E+y*r];p[y+E+_*r]-=T*S-k*M,m[y+E+_*r]-=T*M+k*S}}return{re:p,im:m}}}function cfe(e,t,n){const r=D(e),i=Math.min(t,n),s=new Int32Array(i),o=Gd(t,n,r,t,s);if(o<0)throw new Error(`lu: illegal argument (info=${o})`);return{LU:r,ipiv:s}}function ufe(e,t,n,r,i){const s=Math.min(t,n);let o=!0;for(let j=0;j<e.length;j++)if(!Number.isFinite(e[j])){o=!1;break}if(!o){const j=D(s).fill(NaN);if(!i)return{S:j};const V=r?s:t,O=r?s:n;return{U:D(t*V).fill(NaN),S:j,V:D(n*O).fill(NaN)}}const a=D(e),l=D(s),c=0,u=1,h=3,f=0,d=1,p=3;let m,y,_,b;i?r?(m=u,y=d,_=s,b=s):(m=c,y=f,_=t,b=n):(m=h,y=p,_=0,b=0);const x=i?Math.max(1,t):1,S=i?Math.max(1,b):1,M=D(x*_),E=D(S*n),T=D(1);L8(m,y,t,n,a,0,t,l,0,M,0,x,E,0,S,T,0,-1);const k=Math.max(1,Math.floor(T[0])),R=D(k);a.set(e);const B=L8(m,y,t,n,a,0,t,l,0,M,0,x,E,0,S,R,0,k);if(B>0)throw new Error(`svd: DBDSQR did not converge (info=${B})`);if(B<0)throw new Error(`svd: illegal argument (info=${B})`);if(!i)return{S:l};const F=r?s:n,L=D(n*F);for(let j=0;j<F;j++)for(let V=0;V<n;V++)L[V+j*n]=E[j+V*S];return{U:M,S:l,V:L}}function hfe(e,t,n){const r=D(e),i=Vhe(n?cn:Un,t,r,0,t);if(n)for(let s=0;s<t;s++)for(let o=s+1;o<t;o++)r[o+s*t]=0;else for(let s=0;s<t;s++)for(let o=0;o<s;o++)r[o+s*t]=0;return{R:r,info:i}}function ffe(e,t,n,r){const i=D(e),s=D(t);let o=0;if(r)for(let a=0;a<n;a++){let l=i[a+a*n];for(let u=0;u<a;u++)l-=i[u+a*n]*i[u+a*n]+s[u+a*n]*s[u+a*n];if(l<=0||Number.isNaN(l)){o=a+1;break}const c=Math.sqrt(l);i[a+a*n]=c,s[a+a*n]=0;for(let u=a+1;u<n;u++){let h=i[a+u*n],f=s[a+u*n];for(let d=0;d<a;d++){const p=i[d+a*n],m=s[d+a*n],y=i[d+u*n],_=s[d+u*n];h-=p*y+m*_,f-=p*_-m*y}i[a+u*n]=h/c,s[a+u*n]=f/c}}else for(let a=0;a<n;a++){let l=i[a+a*n];for(let u=0;u<a;u++)l-=i[a+u*n]*i[a+u*n]+s[a+u*n]*s[a+u*n];if(l<=0||Number.isNaN(l)){o=a+1;break}const c=Math.sqrt(l);i[a+a*n]=c,s[a+a*n]=0;for(let u=a+1;u<n;u++){let h=i[u+a*n],f=s[u+a*n];for(let d=0;d<a;d++){const p=i[u+d*n],m=s[u+d*n],y=i[a+d*n],_=s[a+d*n];h-=p*y+m*_,f-=m*y-p*_}i[u+a*n]=h/c,s[u+a*n]=f/c}}if(r)for(let a=0;a<n;a++)for(let l=a+1;l<n;l++)i[l+a*n]=0,s[l+a*n]=0;else for(let a=0;a<n;a++)for(let l=0;l<a;l++)i[l+a*n]=0,s[l+a*n]=0;return{RRe:i,RIm:s,info:o}}function dfe(e,t,n,r,i,s,o,a,l){const c=d=>{const p=D(t);for(let m=0;m<t;m++){let y=0;for(let _=0;_<t;_++)y+=e[m+_*t]*d[_];p[m]=y}return p};let u=null;if(o||a){const d=o?D(o):null,p=o?new Int32Array(t):null;if(d&&p&&Gd(t,t,d,t,p)>0)throw new Error("gmres: preconditioner M1 is singular");const m=a?D(a):null,y=a?new Int32Array(t):null;if(m&&y&&Gd(t,t,m,t,y)>0)throw new Error("gmres: preconditioner M2 is singular");u=_=>{const b=D(_);return d&&p&&Rv(t,d,p,b),m&&y&&Rv(t,m,y,b),b}}const h=$L(c,u,n,t,r,i,s,l),f=new Int32Array(2);return f[0]=h.iter[0],f[1]=h.iter[1],{x:h.x,flag:h.flag,relres:h.relres,iter:f,resvec:h.resvec}}function pfe(e,t,n,r,i,s,o,a,l,c,u,h,f,d){const p=b=>{const x=D(n),S=D(n);for(let M=0;M<n;M++){let E=0,T=0;for(let k=0;k<n;k++){const R=e[M+k*n],B=t[M+k*n];E+=R*b.re[k]-B*b.im[k],T+=R*b.im[k]+B*b.re[k]}x[M]=E,S[M]=T}return{re:x,im:S}};let m=null;if(l||u){const b=l?D(l):null,x=c?D(c):null,S=l?new Int32Array(n):null;b&&x&&S&&z8(n,b,x,S);const M=u?D(u):null,E=h?D(h):null,T=u?new Int32Array(n):null;M&&E&&T&&z8(n,M,E,T),m=k=>{const R=D(k.re),B=D(k.im);return b&&x&&S&&pR(n,b,x,S,R,B),M&&E&&T&&pR(n,M,E,T,R,B),{re:R,im:B}}}const y=dR(p,m,{re:r,im:i},n,s,o,a,f&&d?{re:f,im:d}:null),_=new Int32Array(2);return _[0]=y.iter[0],_[1]=y.iter[1],{xRe:y.x.re,xIm:y.x.im,flag:y.flag,relres:y.relres,iter:_,resvec:y.resvec}}function z8(e,t,n,r){for(let i=0;i<e;i++){let s=-1,o=i;for(let u=i;u<e;u++){const h=Math.sqrt(t[u+i*e]*t[u+i*e]+n[u+i*e]*n[u+i*e]);h>s&&(s=h,o=u)}if(r[i]=o+1,o!==i)for(let u=0;u<e;u++){let h=t[i+u*e];t[i+u*e]=t[o+u*e],t[o+u*e]=h,h=n[i+u*e],n[i+u*e]=n[o+u*e],n[o+u*e]=h}const a=t[i+i*e],l=n[i+i*e],c=a*a+l*l;if(c!==0)for(let u=i+1;u<e;u++){const h=t[u+i*e],f=n[u+i*e],d=(h*a+f*l)/c,p=(f*a-h*l)/c;t[u+i*e]=d,n[u+i*e]=p;for(let m=i+1;m<e;m++)t[u+m*e]-=d*t[i+m*e]-p*n[i+m*e],n[u+m*e]-=d*n[i+m*e]+p*t[i+m*e]}}}const mfe={inv:rfe,matmul:ife,qr:sfe,linsolve:ofe,linsolveComplex:lfe,eig:afe,eigComplex:nfe,lu:cfe,svd:ufe,chol:hfe,cholComplex:ffe,gmres:dfe,gmresComplex:pfe};function U8(){return mfe}const O8=new Set;function Ds(e,t){const n=pue(),r=t&&n&&n[t]?n:U8();return O8.has(e)||(O8.add(e),console.error(`[${e}] using bridge: ts-lapack (TypeScript)`)),r}const lc={ADD:0,SUB:1,MUL:2,DIV:3},Dd={ADD:0,SUB:1,MUL:2,DIV:3},Ji={SUM:0,PROD:1,MAX:2,MIN:3,ANY:4,ALL:5,MEAN:6},hi={EQ:0,NE:1,LT:2,LE:3,GT:4,GE:5},Nd={J:0,Y:1,I:2,K:3},kr={EXP:0,LOG:1,LOG2:2,LOG10:3,SQRT:4,ABS:5,FLOOR:6,CEIL:7,ROUND:8,TRUNC:9,SIN:10,COS:11,TAN:12,ASIN:13,ACOS:14,ATAN:15,SINH:16,COSH:17,TANH:18,SIGN:19};function gfe(e,t,n,r,i){switch(e){case lc.ADD:for(let s=0;s<t;s++)i[s]=n[s]+r[s];return;case lc.SUB:for(let s=0;s<t;s++)i[s]=n[s]-r[s];return;case lc.MUL:for(let s=0;s<t;s++)i[s]=n[s]*r[s];return;case lc.DIV:for(let s=0;s<t;s++)i[s]=n[s]/r[s];return;default:throw new Error(`tsRealBinaryElemwise: unknown op ${e}`)}}function yfe(e,t,n,r,i,s){if(i)switch(e){case lc.ADD:for(let o=0;o<t;o++)s[o]=n+r[o];return;case lc.SUB:for(let o=0;o<t;o++)s[o]=n-r[o];return;case lc.MUL:for(let o=0;o<t;o++)s[o]=n*r[o];return;case lc.DIV:for(let o=0;o<t;o++)s[o]=n/r[o];return;default:throw new Error(`tsRealScalarBinaryElemwise: unknown op ${e}`)}else switch(e){case lc.ADD:for(let o=0;o<t;o++)s[o]=r[o]+n;return;case lc.SUB:for(let o=0;o<t;o++)s[o]=r[o]-n;return;case lc.MUL:for(let o=0;o<t;o++)s[o]=r[o]*n;return;case lc.DIV:for(let o=0;o<t;o++)s[o]=r[o]/n;return;default:throw new Error(`tsRealScalarBinaryElemwise: unknown op ${e}`)}}function vR(e,t){return e===0&&t===0?NaN:(e>0?1:e<0?-1:0)/0}function bR(e,t){return e===0&&t===0?0:(t>0?1:t<0?-1:0)/0}function _fe(e,t,n,r,i,s,o,a){switch(e){case Dd.ADD:for(let l=0;l<t;l++)o[l]=n[l]+i[l],a[l]=(r?r[l]:0)+(s?s[l]:0);return;case Dd.SUB:for(let l=0;l<t;l++)o[l]=n[l]-i[l],a[l]=(r?r[l]:0)-(s?s[l]:0);return;case Dd.MUL:for(let l=0;l<t;l++){const c=n[l],u=r?r[l]:0,h=i[l],f=s?s[l]:0;o[l]=c*h-u*f,a[l]=c*f+u*h}return;case Dd.DIV:for(let l=0;l<t;l++){const c=n[l],u=r?r[l]:0,h=i[l],f=s?s[l]:0,d=h*h+f*f;d===0?(o[l]=vR(c,u),a[l]=bR(c,u)):(o[l]=(c*h+u*f)/d,a[l]=(u*h-c*f)/d)}return;default:throw new Error(`tsComplexBinaryElemwise: unknown op ${e}`)}}function vfe(e,t,n,r,i,s,o,a,l){switch(e){case Dd.ADD:for(let c=0;c<t;c++)a[c]=n+i[c],l[c]=r+(s?s[c]:0);return;case Dd.SUB:if(o)for(let c=0;c<t;c++)a[c]=n-i[c],l[c]=r-(s?s[c]:0);else for(let c=0;c<t;c++)a[c]=i[c]-n,l[c]=(s?s[c]:0)-r;return;case Dd.MUL:for(let c=0;c<t;c++){const u=i[c],h=s?s[c]:0;a[c]=n*u-r*h,l[c]=n*h+r*u}return;case Dd.DIV:if(o)for(let c=0;c<t;c++){const u=i[c],h=s?s[c]:0,f=u*u+h*h;f===0?(a[c]=vR(n,r),l[c]=bR(n,r)):(a[c]=(n*u+r*h)/f,l[c]=(r*u-n*h)/f)}else{const c=n*n+r*r;if(c===0)for(let u=0;u<t;u++){const h=i[u],f=s?s[u]:0;a[u]=vR(h,f),l[u]=bR(h,f)}else{const u=1/c;for(let h=0;h<t;h++){const f=i[h],d=s?s[h]:0;a[h]=(f*n+d*r)*u,l[h]=(d*n-f*r)*u}}}return;default:throw new Error(`tsComplexScalarBinaryElemwise: unknown op ${e}`)}}function bfe(e){return e>0?1:e<0?-1:e===0?0:NaN}function xfe(e,t,n,r){switch(e){case kr.EXP:for(let i=0;i<t;i++)r[i]=Math.exp(n[i]);return;case kr.LOG:for(let i=0;i<t;i++)r[i]=Math.log(n[i]);return;case kr.LOG2:for(let i=0;i<t;i++)r[i]=Math.log2(n[i]);return;case kr.LOG10:for(let i=0;i<t;i++)r[i]=Math.log10(n[i]);return;case kr.SQRT:for(let i=0;i<t;i++)r[i]=Math.sqrt(n[i]);return;case kr.ABS:for(let i=0;i<t;i++)r[i]=Math.abs(n[i]);return;case kr.FLOOR:for(let i=0;i<t;i++)r[i]=Math.floor(n[i]);return;case kr.CEIL:for(let i=0;i<t;i++)r[i]=Math.ceil(n[i]);return;case kr.ROUND:for(let i=0;i<t;i++){const s=n[i];r[i]=s>=0?Math.round(s):-Math.round(-s)}return;case kr.TRUNC:for(let i=0;i<t;i++)r[i]=Math.trunc(n[i]);return;case kr.SIN:for(let i=0;i<t;i++)r[i]=Math.sin(n[i]);return;case kr.COS:for(let i=0;i<t;i++)r[i]=Math.cos(n[i]);return;case kr.TAN:for(let i=0;i<t;i++)r[i]=Math.tan(n[i]);return;case kr.ASIN:for(let i=0;i<t;i++)r[i]=Math.asin(n[i]);return;case kr.ACOS:for(let i=0;i<t;i++)r[i]=Math.acos(n[i]);return;case kr.ATAN:for(let i=0;i<t;i++)r[i]=Math.atan(n[i]);return;case kr.SINH:for(let i=0;i<t;i++)r[i]=Math.sinh(n[i]);return;case kr.COSH:for(let i=0;i<t;i++)r[i]=Math.cosh(n[i]);return;case kr.TANH:for(let i=0;i<t;i++)r[i]=Math.tanh(n[i]);return;case kr.SIGN:for(let i=0;i<t;i++)r[i]=bfe(n[i]);return;default:throw new Error(`tsRealUnaryElemwise: unknown op ${e}`)}}const j8=1/Math.log(2),H8=1/Math.log(10);function wfe(e,t){const n=Math.exp(e);return[n*Math.cos(t),n*Math.sin(t)]}function dm(e,t){return[Math.log(Math.hypot(e,t)),Math.atan2(t,e)]}function XL(e,t){if(e===0&&t===0)return[0,0];const n=Math.hypot(e,t),r=Math.sqrt((n+e)/2),i=Math.sign(t)*Math.sqrt((n-e)/2);return t===0&&e<0?[0,Math.sqrt(-e)]:[r,i]}function C$(e,t){return[Math.sin(e)*Math.cosh(t),Math.cos(e)*Math.sinh(t)]}function A$(e,t){return[Math.cos(e)*Math.cosh(t),-Math.sin(e)*Math.sinh(t)]}function Sfe(e,t){const[n,r]=C$(e,t),[i,s]=A$(e,t),o=i*i+s*s;return[(n*i+r*s)/o,(r*i-n*s)/o]}function T$(e,t){return[Math.sinh(e)*Math.cos(t),Math.cosh(e)*Math.sin(t)]}function k$(e,t){return[Math.cosh(e)*Math.cos(t),Math.sinh(e)*Math.sin(t)]}function Mfe(e,t){const[n,r]=T$(e,t),[i,s]=k$(e,t),o=i*i+s*s;return[(n*i+r*s)/o,(r*i-n*s)/o]}function Efe(e,t){const n=e*e-t*t,r=2*e*t,i=1-n,s=-r,[o,a]=XL(i,s),[l,c]=dm(o-t,a+e);return[c,-l]}function Cfe(e,t){const n=e*e-t*t,r=2*e*t,i=1-n,s=-r,[o,a]=XL(i,s),[l,c]=dm(e-a,t+o);return[c,-l]}function Afe(e,t){const[n,r]=dm(1+t,-e),[i,s]=dm(1-t,e),o=n-i;return[-(r-s)/2,o/2]}function Tfe(e,t){const n=Math.hypot(e,t);return n===0?[0,0]:[e/n,t/n]}function $8(e){return e>=0?Math.round(e):-Math.round(-e)}function kfe(e,t,n,r,i,s){let o=null;switch(e){case kr.EXP:o=wfe;break;case kr.LOG:o=dm;break;case kr.LOG2:o=(l,c)=>{const[u,h]=dm(l,c);return[u*j8,h*j8]};break;case kr.LOG10:o=(l,c)=>{const[u,h]=dm(l,c);return[u*H8,h*H8]};break;case kr.SQRT:o=XL;break;case kr.ABS:throw new Error("tsComplexUnaryElemwise: ABS is not supported (use tsComplexAbs)");case kr.FLOOR:for(let l=0;l<t;l++)i[l]=Math.floor(n[l]),s[l]=r?Math.floor(r[l]):0;return;case kr.CEIL:for(let l=0;l<t;l++)i[l]=Math.ceil(n[l]),s[l]=r?Math.ceil(r[l]):0;return;case kr.ROUND:for(let l=0;l<t;l++)i[l]=$8(n[l]),s[l]=r?$8(r[l]):0;return;case kr.TRUNC:for(let l=0;l<t;l++)i[l]=Math.trunc(n[l]),s[l]=r?Math.trunc(r[l]):0;return;case kr.SIN:o=C$;break;case kr.COS:o=A$;break;case kr.TAN:o=Sfe;break;case kr.ASIN:o=Efe;break;case kr.ACOS:o=Cfe;break;case kr.ATAN:o=Afe;break;case kr.SINH:o=T$;break;case kr.COSH:o=k$;break;case kr.TANH:o=Mfe;break;case kr.SIGN:o=Tfe;break;default:throw new Error(`tsComplexUnaryElemwise: unknown op ${e}`)}const a=o;for(let l=0;l<t;l++){const[c,u]=a(n[l],r?r[l]:0);i[l]=c,s[l]=u}}function Rfe(e,t,n,r){if(n)for(let i=0;i<e;i++)r[i]=Math.hypot(t[i],n[i]);else for(let i=0;i<e;i++)r[i]=Math.abs(t[i])}function E2(e,t,n){switch(e){case hi.EQ:return t===n?1:0;case hi.NE:return t!==n?1:0;case hi.LT:return t<n?1:0;case hi.LE:return t<=n?1:0;case hi.GT:return t>n?1:0;case hi.GE:return t>=n?1:0;default:throw new Error(`tsRealComparison: unknown op ${e}`)}}function Dfe(e,t,n,r,i){switch(e){case hi.EQ:for(let s=0;s<t;s++)i[s]=n[s]===r[s]?1:0;return;case hi.NE:for(let s=0;s<t;s++)i[s]=n[s]!==r[s]?1:0;return;case hi.LT:for(let s=0;s<t;s++)i[s]=n[s]<r[s]?1:0;return;case hi.LE:for(let s=0;s<t;s++)i[s]=n[s]<=r[s]?1:0;return;case hi.GT:for(let s=0;s<t;s++)i[s]=n[s]>r[s]?1:0;return;case hi.GE:for(let s=0;s<t;s++)i[s]=n[s]>=r[s]?1:0;return;default:throw new Error(`tsRealComparison: unknown op ${e}`)}}function Nfe(e,t,n,r,i,s){if(i)for(let o=0;o<t;o++)s[o]=E2(e,n,r[o]);else for(let o=0;o<t;o++)s[o]=E2(e,r[o],n)}function Lfe(e,t,n,r,i,s,o){switch(e){case hi.EQ:for(let a=0;a<t;a++){const l=n[a],c=r?r[a]:0,u=i[a],h=s?s[a]:0;o[a]=l===u&&c===h?1:0}return;case hi.NE:for(let a=0;a<t;a++){const l=n[a],c=r?r[a]:0,u=i[a],h=s?s[a]:0;o[a]=l!==u||c!==h?1:0}return;case hi.LT:for(let a=0;a<t;a++)o[a]=n[a]<i[a]?1:0;return;case hi.LE:for(let a=0;a<t;a++)o[a]=n[a]<=i[a]?1:0;return;case hi.GT:for(let a=0;a<t;a++)o[a]=n[a]>i[a]?1:0;return;case hi.GE:for(let a=0;a<t;a++)o[a]=n[a]>=i[a]?1:0;return;default:throw new Error(`tsComplexComparison: unknown op ${e}`)}}function Ife(e,t,n,r,i,s,o,a){switch(e){case hi.EQ:if(o)for(let l=0;l<t;l++){const c=i[l],u=s?s[l]:0;a[l]=n===c&&r===u?1:0}else for(let l=0;l<t;l++){const c=i[l],u=s?s[l]:0;a[l]=c===n&&u===r?1:0}return;case hi.NE:if(o)for(let l=0;l<t;l++){const c=i[l],u=s?s[l]:0;a[l]=n!==c||r!==u?1:0}else for(let l=0;l<t;l++){const c=i[l],u=s?s[l]:0;a[l]=c!==n||u!==r?1:0}return;case hi.LT:case hi.LE:case hi.GT:case hi.GE:if(o)for(let l=0;l<t;l++)a[l]=E2(e,n,i[l]);else for(let l=0;l<t;l++)a[l]=E2(e,i[l],n);return;default:throw new Error(`tsComplexScalarComparison: unknown op ${e}`)}}function Pfe(e,t,n,r){switch(e){case Ji.SUM:{let i=0;for(let s=0;s<t;s++)i+=n[s];r[0]=i;return}case Ji.PROD:{let i=1;for(let s=0;s<t;s++)i*=n[s];r[0]=i;return}case Ji.MAX:{let i=-1/0,s=!1;for(let o=0;o<t;o++){const a=n[o];Number.isNaN(a)||(a>i&&(i=a),s=!0)}r[0]=s?i:NaN;return}case Ji.MIN:{let i=1/0,s=!1;for(let o=0;o<t;o++){const a=n[o];Number.isNaN(a)||(a<i&&(i=a),s=!0)}r[0]=s?i:NaN;return}case Ji.ANY:{let i=0;for(let s=0;s<t;s++)if(n[s]!==0||Number.isNaN(n[s])){i=1;break}r[0]=i;return}case Ji.ALL:{let i=1;for(let s=0;s<t;s++)if(n[s]===0){i=0;break}r[0]=i;return}case Ji.MEAN:{if(t===0){r[0]=NaN;return}let i=0;for(let s=0;s<t;s++)i+=n[s];r[0]=i/t;return}default:throw new Error(`tsRealFlatReduce: unknown op ${e}`)}}function Bfe(e,t,n,r,i,s){switch(e){case Ji.SUM:{if(!s)throw new Error("tsComplexFlatReduce(SUM): outIm is required");let o=0,a=0;for(let l=0;l<t;l++)o+=n[l],r&&(a+=r[l]);i[0]=o,s[0]=a;return}case Ji.PROD:{if(!s)throw new Error("tsComplexFlatReduce(PROD): outIm is required");let o=1,a=0;for(let l=0;l<t;l++){const c=n[l],u=r?r[l]:0,h=o*c-a*u,f=o*u+a*c;o=h,a=f}i[0]=o,s[0]=a;return}case Ji.ANY:{let o=0;for(let a=0;a<t;a++){const l=n[a],c=r?r[a]:0;if(l!==0||c!==0||Number.isNaN(l)||Number.isNaN(c)){o=1;break}}i[0]=o;return}case Ji.ALL:{let o=1;for(let a=0;a<t;a++){const l=n[a],c=r?r[a]:0;if(l===0&&c===0){o=0;break}}i[0]=o;return}default:throw new Error(`tsComplexFlatReduce: unsupported op ${e}`)}}function _c(e){const n=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,15056327351493116e-23];if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*_c(1-e));e-=1;let r=n[0];for(let s=1;s<n.length;s++)r+=n[s]/(e+s);const i=e+7+.5;return Math.sqrt(2*Math.PI)*Math.pow(i,e+.5)*Math.exp(-i)*r}function $o(e,t){if(t===0)return e===0?1:0;if(t<0&&e!==Math.floor(e))return NaN;if(t<0)return(Math.round(e)%2===0?1:-1)*$o(e,-t);if(e<0&&e===Math.floor(e))return(Math.round(-e)%2===0?1:-1)*$o(-e,t);if(e===Math.floor(e)&&e>=0){const n=Math.round(e);if(n===0)return xR(t);if(n===1)return wR(t);if(t<n)return V8(n,t);let r=xR(t),i=wR(t);for(let s=1;s<n;s++){const o=2*s/t*i-r;r=i,i=o}return i}return t<=25+Math.abs(e)/2?V8(e,t):Ufe(e,t)}function xR(e){if(e<0&&(e=-e),e<=5){const t=e*e,n=5.783185962946784,r=30.471262343662087,i=[-4794432209782018e-6,19561749194655657e-4,-24924834436096772e-2,9708622510473064],s=[1,499.563147152651,173785.4016763747,4844096583399621e-8,11185553704535683e-6,2112775201154892e-3,31051822985742256e-2,0x710505f9ecba70,0x17be34c7b662cc00],o=ws(i,t),a=ws(s,t);return(t-n)*(t-r)*(o/a)}return Ffe(e)}function Ffe(e){const t=[.0007969367292973471,.08283523921074408,1.239533716464143,5.447250030587687,8.74716500199817,5.303240382353949,1],n=[.0009244088105588637,.08562884743544745,1.2535274390105895,5.470977403304171,8.761908832370695,5.306052882353947,1],r=[-.011366383889846916,-1.2825271867050931,-19.553954425773597,-93.20601521237683,-177.68116798048806,-147.07750515495118,-51.41053267665993,-6.050143506007285],i=[1,64.3178256118178,856.4300259769806,3882.4018360540163,7240.467741956525,5930.727011873169,2062.0933166032783,242.0057402402914],s=5/e,o=s*s,a=ws(t,o)/ws(n,o),l=ws(r,o)/ws(i,o),c=e-Math.PI/4;return Math.sqrt(2/(Math.PI*e))*(a*Math.cos(c)-s*l*Math.sin(c))}function wR(e){const t=e<0?-1:1;if(e<0&&(e=-e),e<=5){const n=e*e,r=14.681970642123893,i=49.2184563216946,s=[-8999712257055594e-7,45222829799819403e-5,-7274942452218183e-2,0xd15a1534be241],o=[1,620.8364781180543,256987.25675774884,8351467914319493e-8,2215115954797925e-5,4749141220799914e-3,7843696078762359e-1,89522233618462740,5322786203326801e3],a=ws(s,n),l=ws(o,n);return t*e*(n-r)*(n-i)*(a/l)}return t*zfe(e)}function zfe(e){const t=[.0007621256162081731,.07313970569409176,1.1271960812968493,5.112079511468076,8.424045901417724,5.214515986823618,1],n=[.0005713231280725487,.06884559087544954,1.105142326340617,5.073863861286015,8.399855543276042,5.209828486823619,1],r=[.05108625947501766,4.982138729512334,75.82382841325453,366.7796093601508,710.8563049989261,597.4896124006136,211.68875710057213,25.207020585802372],i=[1,74.23732770356752,1056.4488603826283,4986.410583376536,9562.318924047562,7997.041604473507,2826.1927851763908,336.0936078106983],s=5/e,o=s*s,a=ws(t,o)/ws(n,o),l=ws(r,o)/ws(i,o),c=e-3*Math.PI/4;return Math.sqrt(2/(Math.PI*e))*(a*Math.cos(c)-s*l*Math.sin(c))}function ws(e,t){let n=e[0];for(let r=1;r<e.length;r++)n=n*t+e[r];return n}function V8(e,t){const n=t/2;let r=Math.pow(n,e)/_c(e+1),i=r;const s=-(n*n);for(let o=1;o<=300&&(r*=s/(o*(o+e)),i+=r,!(Math.abs(r)<Math.abs(i)*1e-16));o++);return i}function Ufe(e,t){const n=4*e*e,r=t-(e/2+.25)*Math.PI;let i=1,s=0,o=1,a=1;for(let l=0;l<30&&(l>0&&(o*=-(n-(4*l-3)*(4*l-3))*(n-(4*l-1)*(4*l-1))/((2*l-1)*(2*l)*64*t*t),i+=o),a=(l===0?1:a)*(l===0?(n-1)/(8*t):-(n-(4*l-1)*(4*l-1))*(n-(4*l+1)*(4*l+1))/(2*l*(2*l+1)*64*t*t)),l===0?s=(n-1)/(8*t):s+=a,!(Math.abs(o)+Math.abs(a)<1e-16));l++);return Math.sqrt(2/(Math.PI*t))*(i*Math.cos(r)-s*Math.sin(r))}function s1(e,t){if(t<=0)return NaN;if(e===Math.floor(e))return R$(Math.round(e),t);const n=Math.sin(e*Math.PI);return($o(e,t)*Math.cos(e*Math.PI)-$o(-e,t))/n}function R$(e,t){if(e<0)return(e%2===0?1:-1)*R$(-e,t);if(e===0)return W8(t);if(e===1)return q8(t);let n=W8(t),r=q8(t);for(let i=1;i<e;i++){const s=2*i/t*r-n;n=r,r=s}return r}function W8(e){if(e<=5){const t=[15592.436785523574,-1466392959039716e-8,5435264770518765e-6,-9821360657179115e-4,875906394395367e-1,-0xc5090e8ec6601,0x9d4a5b305a0018,-0x41b52d6418d9ec],n=[1,1041.2835366425984,626107.330137135,26891963339381415e-8,864002487103935e-4,20297961275010555e-3,31715775284297505e-1,0x37a4bf79f36ba00],r=e*e,i=ws(t,r),s=ws(n,r);return i/s+2/Math.PI*Math.log(e)*xR(e)}return Ofe(e)}function Ofe(e){const t=[.0007969367292973471,.08283523921074408,1.239533716464143,5.447250030587687,8.74716500199817,5.303240382353949,1],n=[.0009244088105588637,.08562884743544745,1.2535274390105895,5.470977403304171,8.761908832370695,5.306052882353947,1],r=[-.011366383889846916,-1.2825271867050931,-19.553954425773597,-93.20601521237683,-177.68116798048806,-147.07750515495118,-51.41053267665993,-6.050143506007285],i=[1,64.3178256118178,856.4300259769806,3882.4018360540163,7240.467741956525,5930.727011873169,2062.0933166032783,242.0057402402914],s=5/e,o=s*s,a=ws(t,o)/ws(n,o),l=ws(r,o)/ws(i,o),c=e-Math.PI/4;return Math.sqrt(2/(Math.PI*e))*(a*Math.sin(c)+s*l*Math.cos(c))}function q8(e){if(e<=5){const t=[12632047479017804e-7,-6473558763791603e-4,11450951154182373e-2,-8127702555013251,0x2cf35a16e6cd620,-0xacf20aeef158b80],n=[1,594.3015923461282,235564.09294306856,7348119444597217e-8,18760131610870617e-6,38823127749623857e-4,6205577271469538e-1,0xf41f1e2a3d2440,0x3721e321ece8fe00],r=e*e,i=ws(t,r),s=ws(n,r);return e*(i/s)+2/Math.PI*(wR(e)*Math.log(e)-1/e)}return jfe(e)}function jfe(e){const t=[.0007621256162081731,.07313970569409176,1.1271960812968493,5.112079511468076,8.424045901417724,5.214515986823618,1],n=[.0005713231280725487,.06884559087544954,1.105142326340617,5.073863861286015,8.399855543276042,5.209828486823619,1],r=[.05108625947501766,4.982138729512334,75.82382841325453,366.7796093601508,710.8563049989261,597.4896124006136,211.68875710057213,25.207020585802372],i=[1,74.23732770356752,1056.4488603826283,4986.410583376536,9562.318924047562,7997.041604473507,2826.1927851763908,336.0936078106983],s=5/e,o=s*s,a=ws(t,o)/ws(n,o),l=ws(r,o)/ws(i,o),c=e-3*Math.PI/4;return Math.sqrt(2/(Math.PI*e))*(a*Math.sin(c)+s*l*Math.cos(c))}function Sc(e,t){if(t===0)return e===0?1:0;if(t<0&&e!==Math.floor(e))return NaN;if(t<0)return(Math.round(e)%2===0?1:-1)*Sc(e,-t);if(e<0&&e===Math.floor(e))return Sc(-e,t);const n=t/2;let r=Math.pow(n,e)/_c(e+1),i=r;const s=n*n;for(let o=1;o<=300&&(r*=s/(o*(o+e)),i+=r,!(Math.abs(r)<Math.abs(i)*1e-16));o++);return i}function Dv(e,t){if(t<=0)return NaN;if(e<0&&(e=-e),e===Math.floor(e))return Hfe(Math.round(e),t);const n=Math.sin(e*Math.PI);return Math.PI/2*(Sc(-e,t)-Sc(e,t))/n}function Hfe(e,t){if(e===0)return G8(t);if(e===1)return X8(t);let n=G8(t),r=X8(t);for(let i=1;i<e;i++){const s=2*i/t*r+n;n=r,r=s}return r}function G8(e){const t=.5772156649015329,n=Sc(0,e),r=-(Math.log(e/2)+t)*n,i=e/2,s=i*i;let o=1,a=0,l=0;for(let c=1;c<=300&&(a+=1/c,o*=s/(c*c),l+=a*o,!(Math.abs(o*a)<Math.abs(l)*1e-16));c++);return r+l}function X8(e){const t=e/2,n=t*t;let r=1,i=-.5772156649015329,s=-.5772156649015329+1,o=r,a=(i+s)*r;for(let l=1;l<=300&&(r*=n/(l*(l+1)),i+=1/l,s+=1/(l+1),o+=r,a+=(i+s)*r,!(Math.abs(r)<Math.abs(o)*1e-16));l++);return 1/e+t*Math.log(t)*o-t/2*a}function D$(e){if(e===0)return 1/(Math.pow(3,2/3)*_c(2/3));if(e>0){const r=.6666666666666666*Math.pow(e,1.5);return 1/Math.PI*Math.sqrt(e/3)*Dv(1/3,r)}const t=-e,n=2/3*Math.pow(t,1.5);return Math.sqrt(t)/3*($o(1/3,n)+$o(-1/3,n))}function N$(e){if(e===0)return-1/(Math.pow(3,1/3)*_c(1/3));if(e>0){const r=.6666666666666666*Math.pow(e,1.5);return-(e/(Math.PI*Math.sqrt(3)))*Dv(2/3,r)}const t=-e,n=2/3*Math.pow(t,1.5);return t/3*($o(2/3,n)-$o(-2/3,n))}function L$(e){if(e===0)return 1/(Math.pow(3,1/6)*_c(2/3));if(e>0){const r=.6666666666666666*Math.pow(e,1.5);return Math.sqrt(e/3)*(Sc(1/3,r)+Sc(-1/3,r))}const t=-e,n=2/3*Math.pow(t,1.5);return Math.sqrt(t/3)*($o(-1/3,n)-$o(1/3,n))}function I$(e){if(e===0)return Math.pow(3,1/6)/_c(1/3);if(e>0){const r=.6666666666666666*Math.pow(e,1.5);return e/Math.sqrt(3)*(Sc(2/3,r)+Sc(-2/3,r))}const t=-e,n=2/3*Math.pow(t,1.5);return t/Math.sqrt(3)*($o(2/3,n)+$o(-2/3,n))}function Y8(e,t){const n=e*e*e-3*e*t*t,r=3*e*e*t-t*t*t;let i=1,s=0,o=1,a=0,l=1,c=0,u=1,h=0,f=0,d=0,p=1,m=0;for(let B=1;B<=100;B++){const F=3*B*(3*B-1),L=(3*B+1)*(3*B),j=(i*n-s*r)/F,V=(i*r+s*n)/F;i=j,s=V;const O=(o*n-a*r)/L,P=(o*r+a*n)/L;o=O,a=P,l+=i,c+=s,u+=o,h+=a;const N=3*B;f+=N*i,d+=N*s,p+=(N+1)*o,m+=(N+1)*a;const H=Math.abs(i)+Math.abs(s)+Math.abs(o)+Math.abs(a),U=Math.abs(l)+Math.abs(c)+Math.abs(u)+Math.abs(h)+1e-300;if(H<1e-16*U)break}const y=e*u-t*h,_=e*h+t*u;let b,x;if(e===0&&t===0)b=0,x=0;else{const B=e*e+t*t;b=(f*e+d*t)/B,x=(d*e-f*t)/B}const S=p,M=m,E=D$(0),T=N$(0),k=L$(0),R=I$(0);return{ai:{re:E*l+T*y,im:E*c+T*_},aip:{re:E*b+T*S,im:E*x+T*M},bi:{re:k*l+R*y,im:k*c+R*_},bip:{re:k*b+R*S,im:k*x+R*M}}}function $fe(e,t,n,r,i,s){const o=i!==0;switch(e){case Nd.J:if(o)for(let a=0;a<n;a++)s[a]=$o(t,r[a])*Math.exp(-Math.abs(r[a]));else for(let a=0;a<n;a++)s[a]=$o(t,r[a]);return;case Nd.Y:if(o)for(let a=0;a<n;a++)s[a]=s1(t,r[a])*Math.exp(-Math.abs(r[a]));else for(let a=0;a<n;a++)s[a]=s1(t,r[a]);return;case Nd.I:if(o)for(let a=0;a<n;a++)s[a]=Sc(t,r[a])*Math.exp(-Math.abs(r[a]));else for(let a=0;a<n;a++)s[a]=Sc(t,r[a]);return;case Nd.K:if(o)for(let a=0;a<n;a++)s[a]=Dv(t,r[a])*Math.exp(r[a]);else for(let a=0;a<n;a++)s[a]=Dv(t,r[a]);return;default:throw new Error(`tsBesselReal: unknown op ${e}`)}}function Vfe(e,t,n,r,i,s,o){const a=e===1?1:-1;if(i===0){for(let c=0;c<n;c++)s[c]=$o(t,r[c]),o[c]=a*s1(t,r[c]);return}const l=e===1?-1:1;for(let c=0;c<n;c++){const u=r[c],h=$o(t,u),f=a*s1(t,u),d=Math.cos(u),p=l*Math.sin(u);s[c]=h*d-f*p,o[c]=h*p+f*d}}const ho={realBinaryElemwise(e,t,n,r,i){t!==0&&gfe(e,t,n,r,i)},realScalarBinaryElemwise(e,t,n,r,i,s){t!==0&&yfe(e,t,n,r,i,s)},complexBinaryElemwise(e,t,n,r,i,s,o,a){t!==0&&_fe(e,t,n,r,i,s,o,a)},complexScalarBinaryElemwise(e,t,n,r,i,s,o,a,l){t!==0&&vfe(e,t,n,r,i,s,o,a,l)},realUnaryElemwise(e,t,n,r){t!==0&&xfe(e,t,n,r)},complexUnaryElemwise(e,t,n,r,i,s){t!==0&&kfe(e,t,n,r,i,s)},complexAbs(e,t,n,r){e!==0&&Rfe(e,t,n,r)},realComparison(e,t,n,r,i){t!==0&&Dfe(e,t,n,r,i)},realScalarComparison(e,t,n,r,i,s){t!==0&&Nfe(e,t,n,r,i,s)},complexComparison(e,t,n,r,i,s,o){t!==0&&Lfe(e,t,n,r,i,s,o)},complexScalarComparison(e,t,n,r,i,s,o,a){t!==0&&Ife(e,t,n,r,i,s,o,a)},realFlatReduce(e,t,n,r){Pfe(e,t,n,r)},complexFlatReduce(e,t,n,r,i,s){Bfe(e,t,n,r,i,s)},besselReal(e,t,n,r,i,s){n!==0&&$fe(e,t,n,r,i,s)},besselH(e,t,n,r,i,s,o){n!==0&&Vfe(e,t,n,r,i,s,o)}};function P$(e){if(e>0)return"positive";if(e===0)return"nonneg";if(e<0)return"negative"}function B$(e){return e.kind==="number"?e.sign==="nonneg"||e.sign==="positive":e.kind==="boolean"?!0:e.kind==="tensor"?!!e.nonneg:!1}function F$(e,t){if(e===t)return e;if(!e||!t)return;const n=new Set([e,t]);if(n.has("positive")&&n.has("nonneg"))return"nonneg";if(n.has("negative")&&n.has("nonpositive"))return"nonpositive"}function N_(e,t){if(e.kind===t.kind){if(e.kind==="number"&&t.kind==="number"){const n=e.exact!==void 0&&e.exact===t.exact?e.exact:void 0,r=n!==void 0?P$(n):F$(e.sign,t.sign),i=e.isInteger&&t.isInteger;return{kind:"number",...n!==void 0?{exact:n}:{},...r?{sign:r}:{},...i?{isInteger:!0}:{}}}if(e.kind==="complex_or_number"&&t.kind==="complex_or_number")return{kind:"complex_or_number",...e.pureImaginary&&t.pureImaginary?{pureImaginary:!0}:{}};if(e.kind==="tensor"&&t.kind==="tensor"){const n=e.isComplex||t.isComplex;let r,i;if(e.shape&&t.shape)e.shape.length!==t.shape.length?(r=void 0,i=void 0):(r=e.shape.map((a,l)=>a===t.shape[l]?a:-1),i=r.length);else{r=void 0;const a=e.shape?e.shape.length:e.ndim,l=t.shape?t.shape.length:t.ndim;i=a!==void 0&&a===l?a:void 0}const s=!n&&e.nonneg&&t.nonneg,o=e.isLogical&&t.isLogical;return{kind:"tensor",isComplex:n,...r?{shape:r}:{},...i!==void 0&&!r?{ndim:i}:{},...s?{nonneg:!0}:{},...o?{isLogical:!0}:{}}}if(e.kind==="string"&&t.kind==="string")return{kind:"string",value:e.value!=null&&e.value===t.value?e.value:void 0};if(e.kind==="char"&&t.kind==="char")return{kind:"char",value:e.value!=null&&e.value===t.value?e.value:void 0};if(e.kind==="boolean"&&t.kind==="boolean")return{kind:"boolean",...e.value!==void 0&&e.value===t.value?{value:e.value}:{}};if(e.kind==="struct"&&t.kind==="struct"){if(!e.fields||!t.fields)return{kind:"struct"};const n={};let r=!1;for(const i of Object.keys(e.fields))i in t.fields&&(n[i]=N_(e.fields[i],t.fields[i]),r=!0);return{kind:"struct",...r?{fields:n}:{}}}if(e.kind==="struct_array"&&t.kind==="struct_array"){if(!e.elemFields||!t.elemFields)return{kind:"struct_array"};const n={};let r=!1;for(const s of Object.keys(e.elemFields))s in t.elemFields&&(n[s]=N_(e.elemFields[s],t.elemFields[s]),r=!0);const i=e.length!==void 0&&e.length===t.length?e.length:void 0;return{kind:"struct_array",...r?{elemFields:n}:{},...i!==void 0?{length:i}:{}}}if(e.kind==="class_instance"&&t.kind==="class_instance"){if(e.className!==t.className)return{kind:"unknown"};const n=e.isHandleClass===t.isHandleClass?e.isHandleClass:void 0;if(!e.fields||!t.fields)return{kind:"class_instance",className:e.className,...n!==void 0?{isHandleClass:n}:{}};const r={};let i=!1;for(const s of Object.keys(e.fields))s in t.fields&&(r[s]=N_(e.fields[s],t.fields[s]),i=!0);return{kind:"class_instance",className:e.className,...n!==void 0?{isHandleClass:n}:{},...i?{fields:r}:{}}}if(e.kind==="dictionary"&&t.kind==="dictionary")return{kind:"dictionary"};if(e.kind==="function_handle"&&t.kind==="function_handle")return{kind:"function_handle"};if(e.kind==="cell"&&t.kind==="cell"){let n;e.shape&&t.shape&&e.shape.length===t.shape.length&&(n=e.shape.map((i,s)=>i===t.shape[s]?i:-1));let r;if(e.elements&&t.elements)for(const i of Object.keys(e.elements)){const s=Number(i),o=t.elements[s];if(!o)continue;const a=N_(e.elements[s],o);a.kind!=="unknown"&&((r??={})[s]=a)}return{kind:"cell",...n?{shape:n}:{},...r?{elements:r}:{}}}return e.kind==="sparse_matrix"&&t.kind==="sparse_matrix"?{kind:"sparse_matrix",isComplex:e.isComplex||t.isComplex,...e.m!==void 0&&e.m===t.m?{m:e.m}:{},...e.n!==void 0&&e.n===t.n?{n:e.n}:{}}:{kind:"unknown"}}return e.kind==="number"&&t.kind==="boolean"?{kind:"number",...e.isInteger?{isInteger:!0}:{}}:e.kind==="boolean"&&t.kind==="number"?{kind:"number",...t.isInteger?{isInteger:!0}:{}}:e.kind==="complex_or_number"&&(t.kind==="number"||t.kind==="boolean")||(e.kind==="number"||e.kind==="boolean")&&t.kind==="complex_or_number"?{kind:"complex_or_number"}:{kind:"unknown"}}function Wfe(e){return e.length===1?e[0]!==-1:e.length===2?e[0]===1&&e[1]!==-1||e[1]===1&&e[0]!==-1:!1}function C2(e,t){if(t!==void 0){if(t>e.length)return e.every(s=>s===1)?{scalar:!0}:{scalar:!1,shape:[...e]};const i=[...e];for(i[t-1]=1;i.length>2&&i[i.length-1]===1;)i.pop();return i.every(s=>s===1)?{scalar:!0}:{scalar:!1,shape:i}}if(Wfe(e))return{scalar:!0};const n=e.findIndex(i=>i!==1);if(n===-1)return{scalar:!0};const r=[...e];for(r[n]=1;r.length>2&&r[r.length-1]===1;)r.pop();return{scalar:!1,shape:r}}function Xc(e){return e.pi!==void 0}function ka(e,t){return e.pr[t]}function Ra(e,t){return e.pi?e.pi[t]:0}function xb(e,t){return e===0&&t===0}function Um(e){for(let t=0;t<e.length;t++)if(e[t]!==0)return D(e)}function Mr(e){const t=D(e.m*e.n),n=e.pi?D(e.m*e.n):void 0;for(let r=0;r<e.n;r++)for(let i=e.jc[r];i<e.jc[r+1];i++){const s=r*e.m+e.ir[i];t[s]=e.pr[i],n&&e.pi&&(n[s]=e.pi[i])}return A.tensor(t,[e.m,e.n],n)}function qfe(e){return Re(e)?e:Tt(e)?e?1:0:ce(e)&&e.data.length===1&&!e.imag?e.data[0]:NaN}function Xu(e){return Re(e)?{re:e,im:0}:Tt(e)?{re:e?1:0,im:0}:Ht(e)?{re:e.re,im:e.im}:ce(e)&&e.data.length===1?{re:e.data[0],im:e.imag?e.imag[0]:0}:null}function Gfe(e,t){if(e.m!==t.m||e.n!==t.n)throw new q(`Matrix dimensions must agree: [${e.m},${e.n}] vs [${t.m},${t.n}]`);const n=Xc(e)||Xc(t),r=[],i=[],s=[],o=new Int32Array(e.n+1);for(let a=0;a<e.n;a++){o[a]=r.length;let l=e.jc[a],c=t.jc[a];const u=e.jc[a+1],h=t.jc[a+1];for(;l<u&&c<h;)if(e.ir[l]<t.ir[c])r.push(e.ir[l]),i.push(ka(e,l)),s.push(Ra(e,l)),l++;else if(e.ir[l]>t.ir[c])r.push(t.ir[c]),i.push(ka(t,c)),s.push(Ra(t,c)),c++;else{const f=ka(e,l)+ka(t,c),d=Ra(e,l)+Ra(t,c);xb(f,d)||(r.push(e.ir[l]),i.push(f),s.push(d)),l++,c++}for(;l<u;)r.push(e.ir[l]),i.push(ka(e,l)),s.push(Ra(e,l)),l++;for(;c<h;)r.push(t.ir[c]),i.push(ka(t,c)),s.push(Ra(t,c)),c++}return o[e.n]=r.length,A.sparseMatrix(e.m,e.n,new Int32Array(r),o,D(i),n?Um(s):void 0)}function Xfe(e,t){if(e.m!==t.m||e.n!==t.n)throw new q(`Matrix dimensions must agree: [${e.m},${e.n}] vs [${t.m},${t.n}]`);const n=Xc(e)||Xc(t),r=[],i=[],s=[],o=new Int32Array(e.n+1);for(let a=0;a<e.n;a++){o[a]=r.length;let l=e.jc[a],c=t.jc[a];const u=e.jc[a+1],h=t.jc[a+1];for(;l<u&&c<h;)if(e.ir[l]<t.ir[c])r.push(e.ir[l]),i.push(ka(e,l)),s.push(Ra(e,l)),l++;else if(e.ir[l]>t.ir[c])r.push(t.ir[c]),i.push(-ka(t,c)),s.push(-Ra(t,c)),c++;else{const f=ka(e,l)-ka(t,c),d=Ra(e,l)-Ra(t,c);xb(f,d)||(r.push(e.ir[l]),i.push(f),s.push(d)),l++,c++}for(;l<u;)r.push(e.ir[l]),i.push(ka(e,l)),s.push(Ra(e,l)),l++;for(;c<h;)r.push(t.ir[c]),i.push(-ka(t,c)),s.push(-Ra(t,c)),c++}return o[e.n]=r.length,A.sparseMatrix(e.m,e.n,new Int32Array(r),o,D(i),n?Um(s):void 0)}function Nv(e,t,n){if(t===0&&n===0)return A.sparseMatrix(e.m,e.n,new Int32Array(0),new Int32Array(e.n+1),D(0));const r=e.pr.length,i=D(r),s=D(r);for(let o=0;o<r;o++){const a=e.pr[o],l=e.pi?e.pi[o]:0;i[o]=a*t-l*n,s[o]=a*n+l*t}return A.sparseMatrix(e.m,e.n,new Int32Array(e.ir),new Int32Array(e.jc),i,Um(Array.from(s)))}function Lv(e,t){if(t===0)return A.sparseMatrix(e.m,e.n,new Int32Array(0),new Int32Array(e.n+1),D(0));const n=D(e.pr.length);for(let i=0;i<n.length;i++)n[i]=e.pr[i]*t;const r=e.pi?D(e.pi.length):void 0;if(r&&e.pi)for(let i=0;i<r.length;i++)r[i]=e.pi[i]*t;return A.sparseMatrix(e.m,e.n,new Int32Array(e.ir),new Int32Array(e.jc),n,r)}function Yfe(e){const t=D(e.pr.length);for(let r=0;r<t.length;r++)t[r]=-e.pr[r];const n=e.pi?D(e.pi.length):void 0;if(n&&e.pi)for(let r=0;r<n.length;r++)n[r]=-e.pi[r];return A.sparseMatrix(e.m,e.n,new Int32Array(e.ir),new Int32Array(e.jc),t,n)}function z$(e){const t=e.jc[e.n],n=new Int32Array(t),r=new Int32Array(e.m+1),i=D(t),s=e.pi?D(t):void 0;for(let a=0;a<t;a++)r[e.ir[a]+1]++;for(let a=0;a<e.m;a++)r[a+1]+=r[a];const o=new Int32Array(e.m);for(let a=0;a<e.m;a++)o[a]=r[a];for(let a=0;a<e.n;a++)for(let l=e.jc[a];l<e.jc[a+1];l++){const c=e.ir[l],u=o[c]++;n[u]=a,i[u]=e.pr[l],s&&e.pi&&(s[u]=e.pi[l])}return A.sparseMatrix(e.n,e.m,n,r,i,s)}function Kfe(e){if(!e.pi)return z$(e);const t=e.jc[e.n],n=new Int32Array(t),r=new Int32Array(e.m+1),i=D(t),s=D(t);for(let a=0;a<t;a++)r[e.ir[a]+1]++;for(let a=0;a<e.m;a++)r[a+1]+=r[a];const o=new Int32Array(e.m);for(let a=0;a<e.m;a++)o[a]=r[a];for(let a=0;a<e.n;a++)for(let l=e.jc[a];l<e.jc[a+1];l++){const c=e.ir[l],u=o[c]++;n[u]=a,i[u]=e.pr[l],s[u]=-e.pi[l]}return A.sparseMatrix(e.n,e.m,n,r,i,Um(Array.from(s)))}function Zfe(e,t){if(e.n!==t.m)throw new q(`Inner matrix dimensions must agree: ${e.n} vs ${t.m}`);const n=e.m,r=t.n,i=Xc(e)||Xc(t),s=[],o=[],a=[],l=new Int32Array(r+1),c=D(n),u=i?D(n):null,h=new Int32Array(n).fill(-1);for(let f=0;f<r;f++){l[f]=s.length;const d=[];for(let p=t.jc[f];p<t.jc[f+1];p++){const m=t.ir[p],y=ka(t,p),_=i?Ra(t,p):0;for(let b=e.jc[m];b<e.jc[m+1];b++){const x=e.ir[b],S=ka(e,b),M=i?Ra(e,b):0,E=S*y-M*_,T=S*_+M*y;h[x]!==f?(h[x]=f,c[x]=E,u&&(u[x]=T),d.push(x)):(c[x]+=E,u&&(u[x]+=T))}}d.sort((p,m)=>p-m);for(const p of d){const m=c[p],y=u?u[p]:0;xb(m,y)||(s.push(p),o.push(m),a.push(y))}}return l[r]=s.length,A.sparseMatrix(n,r,new Int32Array(s),l,D(o),i?Um(a):void 0)}function Qfe(e,t){if(e.m!==t.m||e.n!==t.n)throw new q(`Matrix dimensions must agree: [${e.m},${e.n}] vs [${t.m},${t.n}]`);const n=Xc(e)||Xc(t),r=[],i=[],s=[],o=new Int32Array(e.n+1);for(let a=0;a<e.n;a++){o[a]=r.length;let l=e.jc[a],c=t.jc[a];const u=e.jc[a+1],h=t.jc[a+1];for(;l<u&&c<h;)if(e.ir[l]<t.ir[c])l++;else if(e.ir[l]>t.ir[c])c++;else{const f=ka(e,l),d=Ra(e,l),p=ka(t,c),m=Ra(t,c),y=f*p-d*m,_=f*m+d*p;xb(y,_)||(r.push(e.ir[l]),i.push(y),s.push(_)),l++,c++}}return o[e.n]=r.length,A.sparseMatrix(e.m,e.n,new Int32Array(r),o,D(i),n?Um(s):void 0)}function K8(e,t){const[n,r]=Bn(t);if(!(n===e.m||n===1)||!(r===e.n||r===1))throw new q(`Matrix dimensions must agree: [${e.m},${e.n}] vs [${n},${r}]`);const i=(u,h)=>(r===1?0:h)*n+(n===1?0:u),s=Xc(e)||t.imag!==void 0,o=[],a=[],l=[],c=new Int32Array(e.n+1);for(let u=0;u<e.n;u++){c[u]=o.length;for(let h=e.jc[u];h<e.jc[u+1];h++){const f=e.ir[h],d=i(f,u),p=e.pr[h],m=e.pi?e.pi[h]:0,y=t.data[d],_=t.imag?t.imag[d]:0,b=p*y-m*_,x=p*_+m*y;xb(b,x)||(o.push(f),a.push(b),l.push(x))}}return c[e.n]=o.length,A.sparseMatrix(e.m,e.n,new Int32Array(o),c,D(a),s?Um(l):void 0)}function Jfe(e,t){if(Dt(e)&&Dt(t))return Gfe(e,t);if(Dt(e)){const n=Xu(t);if(n){const r=Mr(e),i=D(r.data.length);for(let o=0;o<i.length;o++)i[o]=r.data[o]+n.re;const s=n.im!==0||r.imag?(()=>{const o=D(i.length);for(let a=0;a<o.length;a++)o[a]=(r.imag?r.imag[a]:0)+n.im;return o})():void 0;return A.tensor(i,r.shape,s)}}if(Dt(t)){const n=Xu(e);if(n){const r=Mr(t),i=D(r.data.length);for(let o=0;o<i.length;o++)i[o]=n.re+r.data[o];const s=n.im!==0||r.imag?(()=>{const o=D(i.length);for(let a=0;a<o.length;a++)o[a]=n.im+(r.imag?r.imag[a]:0);return o})():void 0;return A.tensor(i,r.shape,s)}}if(Dt(e)&&ce(t)){const n=Mr(e),r=D(n.data.length);for(let s=0;s<r.length;s++)r[s]=n.data[s]+t.data[s];const i=A2(n.imag,t.imag,r.length,(s,o)=>s+o);return A.tensor(r,n.shape,i)}if(ce(e)&&Dt(t)){const n=Mr(t),r=D(n.data.length);for(let s=0;s<r.length;s++)r[s]=e.data[s]+n.data[s];const i=A2(e.imag,n.imag,r.length,(s,o)=>s+o);return A.tensor(r,e.shape,i)}throw new q("mAddSparse: unexpected operand types")}function ede(e,t){if(Dt(e)&&Dt(t))return Xfe(e,t);if(Dt(e)){const n=Xu(t);if(n){const r=Mr(e),i=D(r.data.length);for(let o=0;o<i.length;o++)i[o]=r.data[o]-n.re;const s=n.im!==0||r.imag?(()=>{const o=D(i.length);for(let a=0;a<o.length;a++)o[a]=(r.imag?r.imag[a]:0)-n.im;return o})():void 0;return A.tensor(i,r.shape,s)}}if(Dt(t)){const n=Xu(e);if(n){const r=Mr(t),i=D(r.data.length);for(let o=0;o<i.length;o++)i[o]=n.re-r.data[o];const s=n.im!==0||r.imag?(()=>{const o=D(i.length);for(let a=0;a<o.length;a++)o[a]=n.im-(r.imag?r.imag[a]:0);return o})():void 0;return A.tensor(i,r.shape,s)}}if(Dt(e)&&ce(t)){const n=Mr(e),r=D(n.data.length);for(let s=0;s<r.length;s++)r[s]=n.data[s]-t.data[s];const i=A2(n.imag,t.imag,r.length,(s,o)=>s-o);return A.tensor(r,n.shape,i)}if(ce(e)&&Dt(t)){const n=Mr(t),r=D(n.data.length);for(let s=0;s<r.length;s++)r[s]=e.data[s]-n.data[s];const i=A2(e.imag,n.imag,r.length,(s,o)=>s-o);return A.tensor(r,e.shape,i)}throw new q("mSubSparse: unexpected operand types")}function A2(e,t,n,r){if(!e&&!t)return;const i=D(n);for(let s=0;s<n;s++)i[s]=r(e?e[s]:0,t?t[s]:0);return i}function tde(e,t){if(Dt(e)&&Dt(t))return Zfe(e,t);if(Dt(e)){const n=Xu(t);if(n)return n.im===0?Lv(e,n.re):Nv(e,n.re,n.im)}if(Dt(t)){const n=Xu(e);if(n)return n.im===0?Lv(t,n.re):Nv(t,n.re,n.im)}if(Dt(e)&&ce(t)){const[n,r]=Bn(t);if(e.n!==n)throw new q(`Inner matrix dimensions must agree: ${e.n} vs ${n}`);const i=e.m,s=Xc(e)||t.imag!==void 0,o=D(i*r),a=s?D(i*r):void 0;for(let l=0;l<r;l++)for(let c=0;c<e.n;c++){const u=t.data[l*n+c],h=t.imag?t.imag[l*n+c]:0;if(!(u===0&&h===0))for(let f=e.jc[c];f<e.jc[c+1];f++){const d=l*i+e.ir[f],p=e.pr[f],m=e.pi?e.pi[f]:0;o[d]+=p*u-m*h,a&&(a[d]+=p*h+m*u)}}return A.tensor(o,[i,r],a)}if(ce(e)&&Dt(t)){const[n,r]=Bn(e);if(r!==t.m)throw new q(`Inner matrix dimensions must agree: ${r} vs ${t.m}`);const i=e.imag!==void 0||Xc(t),s=D(n*t.n),o=i?D(n*t.n):void 0;for(let a=0;a<t.n;a++)for(let l=t.jc[a];l<t.jc[a+1];l++){const c=t.ir[l],u=t.pr[l],h=t.pi?t.pi[l]:0;for(let f=0;f<n;f++){const d=c*n+f,p=e.data[d],m=e.imag?e.imag[d]:0,y=a*n+f;s[y]+=p*u-m*h,o&&(o[y]+=p*h+m*u)}}return A.tensor(s,[n,t.n],o)}throw new q("mMulSparse: unexpected operand types")}function nde(e,t){if(Dt(e)&&Dt(t))return Qfe(e,t);if(Dt(e)){const n=Xu(t);if(n)return n.im===0?Lv(e,n.re):Nv(e,n.re,n.im)}if(Dt(t)){const n=Xu(e);if(n)return n.im===0?Lv(t,n.re):Nv(t,n.re,n.im)}if(Dt(e)&&ce(t))return K8(e,t);if(ce(e)&&Dt(t))return K8(t,e);throw new q("mElemMulSparse: unexpected operand types")}function rde(e,t){if(Dt(e)){const a=qfe(t);if(!isNaN(a))return Lv(e,1/a);const l=Xu(t);if(l){const c=l.re*l.re+l.im*l.im;return Nv(e,l.re/c,-l.im/c)}}if(Dt(t)){const a=Xu(e);if(a){const l=Mr(t),c=l.data.length,u=a.im!==0||l.imag!==void 0,h=D(c),f=u?D(c):void 0;for(let d=0;d<c;d++){const p=l.data[d],m=l.imag?l.imag[d]:0;if(!u)h[d]=a.re/p;else{const y=p*p+m*m;h[d]=(a.re*p+a.im*m)/y,f&&(f[d]=(a.im*p-a.re*m)/y)}}return A.tensor(h,l.shape,f)}}const n=Dt(e)?Mr(e):e,r=Dt(t)?Mr(t):t;if(!ce(n)||!ce(r))throw new q("mElemDivSparse: unexpected operand types");const i=n.imag!==void 0||r.imag!==void 0,s=D(n.data.length),o=i?D(n.data.length):void 0;for(let a=0;a<s.length;a++){const l=r.data[a],c=r.imag?r.imag[a]:0;if(!i)s[a]=n.data[a]/l;else{const u=n.data[a],h=n.imag?n.imag[a]:0,f=l*l+c*c;s[a]=(u*l+h*c)/f,o&&(o[a]=(h*l-u*c)/f)}}return A.tensor(s,n.shape,o)}const Sm=new Map;function Yu(e){return Sm.get(e)}function Rt(e){if(Sm.has(e.name))throw new Error(`registerIBuiltin: duplicate registration for '${e.name}'`);Sm.set(e.name,e)}function YL(e){Sm.set(e.name,e)}function U$(){return Array.from(Sm.keys())}const O$=new Map;function ide(e){return Sm.get(e)?.help??O$.get(e)}function sde(e,t){O$.set(e,t)}function ode(e){const t=Sm.get(e);if(!t)return;const n={kind:"number"};for(let r=1;r<=10;r++)if(t.resolve(Array(r).fill(n),1))return r}function Mc(e){if(typeof e=="boolean")return{kind:"boolean",value:e};if(typeof e=="number"){const t=P$(e);return{kind:"number",exact:e,...t?{sign:t}:{}}}if(typeof e=="string")return{kind:"string",value:e};if(lt(e))return{kind:"char",value:e.value};if(typeof e=="object"&&e!==null&&e.kind==="complex_number")return{kind:"complex_or_number"};if(typeof e=="object"&&e!==null&&e.kind==="tensor"){const t=e,n=t.shape.length>=2?t.shape.slice():[1,...t.shape];return t.imag?{kind:"tensor",isComplex:!0,shape:n}:{kind:"tensor",isComplex:!1,shape:n,...t._isLogical?{isLogical:!0}:{}}}if(Zn(e)){const t=e,n={};for(const[r,i]of t.fields)yi(i)?n[r]=ade(i):n[r]=Mc(i);return{kind:"struct",fields:n}}if(Dt(e)){const t=e;return{kind:"sparse_matrix",isComplex:!!t.pi,m:t.m,n:t.n}}if(typeof e=="object"&&e!==null&&e.kind==="cell")return{kind:"cell",shape:e.shape.slice()};if(typeof e=="object"&&e!==null&&e.kind==="dictionary")return{kind:"dictionary"};if(In(e)){const t=e,n={};for(const[r,i]of t.fields)n[r]=Mc(i);return{kind:"class_instance",className:t.className,isHandleClass:t.isHandleClass,fields:n}}return ii(e)?{kind:"class_instance",className:e.className,isHandleClass:!1,fields:{}}:typeof e=="object"&&e!==null&&e.kind==="function"?{kind:"function_handle"}:{kind:"unknown"}}function ade(e){if(e.elements.length===0)return{kind:"struct_array",length:0};const t={},n=e.elements[0];for(const[r,i]of n.fields)t[r]=Mc(i);for(let r=1;r<e.elements.length;r++){const i=e.elements[r];for(const s of Object.keys(t)){const o=i.fields.get(s);if(o===void 0){delete t[s];continue}const a=t[s],l=Mc(o);t[s]=lde(a,l)}}return{kind:"struct_array",elemFields:t,length:e.elements.length}}function lde(e,t){const n=N_(e,t);if(n.kind!=="unknown")return n;const r=s=>s.kind==="tensor"&&s.isComplex!==!0,i=s=>s.kind==="number"||s.kind==="boolean";return r(e)&&i(t)||i(e)&&r(t)?{kind:"tensor",isComplex:!1}:n}function T2(e,t){return t===0?e:new _$(e,t)}function fi(e,t,n){const r=[...n];for(;r.length>2&&r[r.length-1]===1;)r.pop();return new Da(e,r,t)}function cde(e){if(e.length!==2)return null;const t=e[0].kind,n=e[1].kind;return t!=="number"&&t!=="boolean"||n!=="number"&&n!=="boolean"?null:[{kind:"number"}]}const Z8=new Map([[Math.exp,0],[Math.log,1],[Math.log2,2],[Math.log10,3],[Math.sqrt,4],[Math.abs,5],[Math.floor,6],[Math.ceil,7],[Math.round,8],[Math.trunc,9],[Math.sin,10],[Math.cos,11],[Math.tan,12],[Math.asin,13],[Math.acos,14],[Math.atan,15],[Math.sinh,16],[Math.cosh,17],[Math.tanh,18],[Math.sign,19]]);function KL(e,t,n,r){if(Dt(e))return KL(Mr(e),t,n,r);if(typeof e=="boolean")return t(e?1:0);if(typeof e=="number")return t(e);if(Ht(e)){const i=n(e.re,e.im);return T2(i.re,i.im)}if(ce(e)){const i=e.data.length;if(!e.imag){const l=Z8.get(t);if(l!==void 0&&e.data instanceof Float64Array){const u=D(i);return ho.realUnaryElemwise(l,i,e.data,u),A.tensorRaw(u,e.shape.slice())}const c=D(i);for(let u=0;u<i;u++)c[u]=t(e.data[u]);return fi(c,void 0,e.shape.slice())}const s=Z8.get(t);if(s!==void 0&&s!==5&&e.data instanceof Float64Array&&e.imag instanceof Float64Array){const l=D(i),c=D(i);return ho.complexUnaryElemwise(s,i,e.data,e.imag,l,c),fi(l,c,e.shape.slice())}const o=D(i),a=D(i);for(let l=0;l<i;l++){const c=n(e.data[l],e.imag[l]);o[l]=c.re,a[l]=c.im}return fi(o,a,e.shape.slice())}throw new Error(`${r}: unsupported argument type`)}function j$(e,t,n,r,i){if(Dt(e))return j$(Mr(e),t,n,r,i);if(typeof e=="boolean"&&(e=e?1:0),typeof e=="number"){const s=t(e);if(!Number.isNaN(s))return s;const o=n(e,0);return T2(o.re,o.im)}if(Ht(e)){const s=n(e.re,e.im);return T2(s.re,s.im)}if(ce(e)){const s=e.data.length;if(!e.imag){if(i!==void 0&&e.data instanceof Float64Array){const h=D(s);ho.realUnaryElemwise(i,s,e.data,h);let f=-1;for(let y=0;y<s;y++)if(Number.isNaN(h[y])){f=y;break}if(f===-1)return A.tensorRaw(h,e.shape.slice());const d=D(s),p=D(s);let m=!1;for(let y=0;y<s;y++)if(!Number.isNaN(h[y]))d[y]=h[y];else{const _=n(e.data[y],0);d[y]=_.re,p[y]=_.im,_.im!==0&&(m=!0)}return fi(d,m?p:void 0,e.shape.slice())}const l=D(s),c=D(s);let u=!1;for(let h=0;h<s;h++){const f=t(e.data[h]);if(!Number.isNaN(f))l[h]=f,c[h]=0;else{const d=n(e.data[h],0);l[h]=d.re,c[h]=d.im,d.im!==0&&(u=!0)}}return fi(l,u?c:void 0,e.shape.slice())}const o=D(s),a=D(s);for(let l=0;l<s;l++){const c=n(e.data[l],e.imag[l]);o[l]=c.re,a[l]=c.im}return fi(o,a,e.shape.slice())}throw new Error(`${r}: unsupported argument type`)}function H$(e,t,n,r){if(Dt(e))return H$(Mr(e),t,n,r);if(typeof e=="boolean")return t(e?1:0);if(typeof e=="number")return t(e);if(Ht(e))return n(e.re,e.im);if(ce(e)){const i=e.data.length;if(t===Math.abs&&e.data instanceof Float64Array){if(!e.imag){const o=D(i);return ho.realUnaryElemwise(5,i,e.data,o),A.tensorRaw(o,e.shape.slice())}if(e.imag instanceof Float64Array){const o=D(i);return ho.complexAbs(i,e.data,e.imag,o),A.tensorRaw(o,e.shape.slice())}}const s=D(i);if(e.imag)for(let o=0;o<i;o++)s[o]=n(e.data[o],e.imag[o]);else for(let o=0;o<i;o++)s[o]=t(e.data[o]);return fi(s,void 0,e.shape.slice())}throw new Error(`${r}: unsupported argument type`)}function ude(e,t,n){const r=typeof e[0]=="boolean"?e[0]?1:0:e[0],i=typeof e[1]=="boolean"?e[1]?1:0:e[1];if(typeof r=="number"&&typeof i=="number")return t(r,i);throw new Error(`${n}: expected two scalar numbers`)}function ZL(e,t,n){const r=typeof e[0]=="boolean"?e[0]?1:0:e[0],i=typeof e[1]=="boolean"?e[1]?1:0:e[1],s=typeof r=="number",o=typeof i=="number",a=ce(r),l=ce(i);if(s&&o)return t(r,i);if(a&&o){const c=r,u=i,h=D(c.data.length);for(let f=0;f<c.data.length;f++)h[f]=t(c.data[f],u);return fi(h,void 0,c.shape)}if(s&&l){const c=r,u=i,h=D(u.data.length);for(let f=0;f<u.data.length;f++)h[f]=t(c,u.data[f]);return fi(h,void 0,u.shape)}if(a&&l){const c=r,u=i,h=Zu(c.shape,u.shape);if(h===null)throw new Error(`${n}: Matrix dimensions must agree`);const f=h.reduce((p,m)=>p*m,1),d=D(f);return gf(c.shape,u.shape,h,(p,m,y)=>{d[y]=t(c.data[p],u.data[m])}),fi(d,void 0,h)}throw new Error(`${n}: unsupported argument types`)}function QL(e){if(e.length!==2)return null;const t=e[0].kind,n=e[1].kind,r=["number","boolean","tensor"];return!r.includes(t)||!r.includes(n)?null:t==="tensor"||n==="tensor"?[{kind:"tensor",isComplex:!1}]:[{kind:"number"}]}function $e(e){Rt({name:e.name,help:e.help,resolve:(t,n)=>{for(const r of e.cases){const i=r.match(t,n);if(i)return{outputTypes:i,apply:r.apply}}return null}})}function Ns(e,t){const n=e.maybeComplex?l=>j$(l[0],e.realFn,e.complexFn,t,e.nativeOpCode):l=>KL(l[0],e.realFn,e.complexFn,t),r=[],i=e.numberType??(()=>({kind:"number"})),s=e.booleanType??(()=>({kind:"number"}));r.push({match:l=>{if(l.length!==1)return null;const c=l[0];if(c.kind==="number"){const u=i(c);return u?[u]:null}if(c.kind==="boolean"){const u=s(c);return u?[u]:null}return null},apply:n});const o=e.complexType??(()=>({kind:"complex_or_number"}));r.push({match:l=>{if(l.length!==1||l[0].kind!=="complex_or_number")return null;const c=o(l[0]);return c?[c]:null},apply:n});const a=e.tensorType??(l=>({kind:"tensor",isComplex:l.isComplex,shape:l.shape,ndim:l.ndim}));return r.push({match:l=>{if(l.length!==1||l[0].kind!=="tensor")return null;const c=a(l[0]);return c?[c]:null},apply:n}),r.push({match:l=>{if(l.length!==1||l[0].kind!=="sparse_matrix")return null;const c=l[0],u=c.m!==void 0&&c.n!==void 0?[c.m,c.n]:void 0,h=a({kind:"tensor",isComplex:c.isComplex,shape:u});return h?[h]:null},apply:n}),r}function VM(e,t,n){const r=i=>H$(i[0],e,t,n);return[{match:i=>{if(i.length!==1)return null;const s=i[0].kind;return s==="number"||s==="boolean"||s==="complex_or_number"?[{kind:"number",sign:"nonneg"}]:null},apply:r},{match:i=>{if(i.length!==1)return null;const s=i[0];return s.kind!=="tensor"?null:[{kind:"tensor",isComplex:!1,shape:s.shape,ndim:s.ndim,nonneg:!0}]},apply:r},{match:i=>{if(i.length!==1||i[0].kind!=="sparse_matrix")return null;const s=i[0];return[{kind:"tensor",isComplex:!1,shape:s.m!==void 0&&s.n!==void 0?[s.m,s.n]:void 0,nonneg:!0}]},apply:r}]}function JL(e,t,n,r,i){return[{match:s=>{if(s.length!==1)return null;const o=s[0].kind;return o==="number"||o==="boolean"||o==="complex_or_number"?[{kind:"boolean"}]:null},apply:s=>{const o=s[0];if(typeof o=="boolean")return e(o?1:0);if(typeof o=="number")return e(o);if(Ht(o))return t(o.re,o.im);throw new Error(`${i}: unsupported argument type`)}},{match:s=>{if(s.length!==1)return null;const o=s[0];return o.kind!=="tensor"?null:[{kind:"tensor",isComplex:!1,shape:o.shape,ndim:o.ndim,nonneg:!0,isLogical:!0}]},apply:s=>{const o=s[0];if(!ce(o))throw new Error(`${i}: unsupported argument type`);const a=o.data.length,l=D(a);if(o.imag)for(let u=0;u<a;u++)l[u]=r(o.data[u],o.imag[u])?1:0;else for(let u=0;u<a;u++)l[u]=n(o.data[u])?1:0;const c=fi(l,void 0,o.shape.slice());return c._isLogical=!0,c}}]}function Vn(e){return e instanceof Float64Array?e:D(e)}function qc(e){return typeof e=="string"?e.replace(/^['"]|['"]$/g,"").toLowerCase():e&&typeof e=="object"&&"value"in e?String(e.value).replace(/^['"]|['"]$/g,"").toLowerCase():String(e).toLowerCase()}function $$(e){return e===void 0?!1:!!(Re(e)&&e===0||mt(e)&&e.toLowerCase()==="econ"||lt(e)&&e.value.toLowerCase()==="econ")}function k2(e,t,n,r){if(!r)return A.tensor(e,[n,n]);const i=D(n*n),s=D(n*n);let o=0;for(;o<n;)if(Math.abs(t[o])===0){for(let a=0;a<n;a++)i[gn(a,o,n)]=e[gn(a,o,n)];o++}else{for(let a=0;a<n;a++){const l=e[gn(a,o,n)],c=e[gn(a,o+1,n)];i[gn(a,o,n)]=l,s[gn(a,o,n)]=c,i[gn(a,o+1,n)]=l,s[gn(a,o+1,n)]=-c}o+=2}return A.tensor(i,[n,n],s)}function Cu(e,t,n){return n&&n.some(r=>r!==0)?A.tensor(e,t,n):A.tensor(e,t)}function SR(e,t,n){const[r,i]=typeof n=="number"?[n,n]:n,s=Math.min(r,i,e.length),o=D(r*i);for(let a=0;a<s;a++)o[gn(a,a,r)]=e[a];if(t&&t.some(a=>a!==0)){const a=D(r*i);for(let l=0;l<s;l++)a[gn(l,l,r)]=t[l];return A.tensor(o,[r,i],a)}return A.tensor(o,[r,i])}function Q8(e,t,n){for(let r=0;r<t;r++){let i=Math.abs(e[r*t+r]),s=r;for(let a=r+1;a<t;a++){const l=Math.abs(e[r*t+a]);l>i&&(i=l,s=a)}if(s!==r)for(let a=0;a<n;a++){const l=e[a*t+r];e[a*t+r]=e[a*t+s],e[a*t+s]=l}const o=e[r*t+r];if(!(Math.abs(o)<1e-14)){for(let a=0;a<n;a++)e[a*t+r]/=o;for(let a=0;a<t;a++){if(a===r)continue;const l=e[r*t+a];for(let c=0;c<n;c++)e[c*t+a]-=l*e[c*t+r]}}}}function hde(e,t,n,r){const i=Yu(t);if(!i)throw new q(`${e}: builtin '${t}' not found`);const s=n.map(Mc),o=i.resolve(s,r);if(!o)throw new q(`${e}: builtin '${t}' returned no result`);const a=o.apply(n,r);return Array.isArray(a)?a[0]:a}function WM(e,t,n,r,i){const s=Ds("linsolve","linsolve");return s?.linsolve?s.linsolve(Vn(e),t,n,Vn(r),i):null}function eI(e,t,n,r,i,s,o){const a=Ds("linsolveComplex","linsolveComplex");if(!a?.linsolveComplex)throw new q("linsolveComplex: no bridge available (should not happen)");return a.linsolveComplex(Vn(e),Vn(t),n,r,Vn(i),Vn(s),o)}function tI(e,t){if(ce(e))return e;if(Re(e))return A.tensor(D([e]),[1,1]);if(Tt(e))return A.tensor(D([e?1:0]),[1,1]);if(Ht(e))return A.tensor(D([e.re]),[1,1],D([e.im]));throw new q(`${t}: argument must be numeric`)}function wT(e){if(e===1/0)return"Inf";if(e===-1/0)return"-Inf";if(isNaN(e))return"NaN";if(e===0)return"0";const t=5,n=Math.floor(Math.log10(Math.abs(e)));let r;if(n<-4||n>=t){r=e.toExponential(t-1);const i=r.indexOf("e");let s=r.slice(0,i);const o=r.slice(i);s.includes(".")&&(s=s.replace(/\.?0+$/,""));const a=o.replace(/([eE][+-])(\d)$/,"$10$2");r=s+a}else{if(Number.isInteger(e))return String(e);r=e.toPrecision(t),r.includes(".")&&(r=r.replace(/\.?0+$/,""))}return r}function J8(e){if(e===1/0)return"Inf";if(e===-1/0)return"-Inf";if(isNaN(e))return"NaN";if(e===0)return"0";if(Number.isInteger(e))return String(e);const t=5,n=Math.floor(Math.log10(Math.abs(e)));let r;if(n<-4||n>=t){r=e.toExponential(t-1);const i=r.indexOf("e");let s=r.slice(0,i);const o=r.slice(i);s.includes(".")&&(s=s.replace(/\.?0+$/,""));const a=o.replace(/([eE][+-])(\d)$/,"$10$2");r=s+a}else r=e.toPrecision(t),r.includes(".")&&(r=r.replace(/\.?0+$/,""));return r}function Oh(e,t){const n=e.match(/^%([-+ #]*)0?(\d+)?/);if(!n)return t;const i=(n[1]||"").includes("-"),o=e.slice(1).match(/^([-+ #]*)(0?)(\d+)?/),a=o?o[2]==="0":!1,l=o&&o[3]?parseInt(o[3]):0;if(l<=t.length)return t;const c=!i&&a,u=l-t.length;return i?t+" ".repeat(u):c?t[0]==="-"||t[0]==="+"?t[0]+"0".repeat(u)+t.slice(1):"0".repeat(u)+t:" ".repeat(u)+t}function Mm(e,t){const n=[];for(const s of t)if(ce(s))for(let o=0;o<s.data.length;o++)n.push(s.data[o]);else n.push(s);let r="",i=0;do{const s=i;let o=!1,a=0;for(;a<e.length&&!o;)if(e[a]==="%"&&a+1<e.length){a++;let l="%";for(;a<e.length&&!"dfigeEsoxXuc%".includes(e[a]);)if(e[a]==="*"){if(i>=n.length){o=!0;break}l+=String(Math.round(Ne(n[i++]))),a++}else l+=e[a],a++;if(o)break;if(a<e.length){const c=e[a];if(a++,c==="%")r+="%";else if(i>=n.length)o=!0;else if(c==="d"||c==="i"||c==="u"){const u=Ne(n[i++]),h=Number.isInteger(u);if(c==="u"?h&&u>=0:h){const d=u,p=l.slice(1),m=p.includes("+"),y=p.includes("-"),_=l.match(/^%[^0-9]*(\d+)/),b=_?parseInt(_[1]):0,x=!y&&/^[-+ ]*0/.test(l.slice(1)),S=String(Math.abs(d)),M=d<0?"-":m?"+":"";if(b>0){const E=x?"0":" ",T=Math.max(0,b-M.length-S.length),k=E.repeat(T);r+=y?M+S+" ".repeat(T):x?M+k+S:k+M+S}else r+=M+S}else{let d=u.toExponential(6);d=d.replace(/e([+-])(\d)$/,"e$10$2"),r+=Oh(l,d)}}else if(c==="f"){const u=Ne(n[i++]);if(!isFinite(u)||isNaN(u))r+=Oh(l,wT(u));else{const f=l.slice(1).includes("+"),d=l.match(/\.(\d+)/),p=d?parseInt(d[1]):6,m=u.toFixed(p),y=u<0?"":f?"+":"";r+=Oh(l,y+m)}}else if(c==="e"||c==="E"){const u=Ne(n[i++]);if(!isFinite(u)||isNaN(u))r+=Oh(l,wT(u));else{const h=l.match(/\.(\d+)/),f=h?parseInt(h[1]):6;let d=u.toExponential(f);d=d.replace(/e([+-])(\d)$/,"e$10$2"),c==="E"&&(d=d.toUpperCase()),r+=Oh(l,d)}}else if(c==="x"||c==="X"){const u=Math.round(Ne(n[i++]));let h=Math.abs(u).toString(16);c==="X"&&(h=h.toUpperCase()),r+=Oh(l,h)}else if(c==="o"){const u=Math.round(Ne(n[i++]));r+=Oh(l,Math.abs(u).toString(8))}else if(c==="g"||c==="G"){const u=Ne(n[i++]);if(!isFinite(u)||isNaN(u))r+=Oh(l,wT(u));else{const h=l.match(/\.(\d+)/),f=h?parseInt(h[1]):6;let d;if(u===0)d="0";else{const p=Math.floor(Math.log10(Math.abs(u)));if(p<-4||p>=f){d=u.toExponential(f-1);const m=d.indexOf("e");let y=d.slice(0,m),_=d.slice(m);y.includes(".")&&(y=y.replace(/\.?0+$/,"")),_=_.replace(/e([+-])(\d)$/,"e$10$2"),d=y+_}else d=u.toPrecision(f),d.includes(".")&&(d=d.replace(/\.?0+$/,"")),d.includes("e")&&(d=String(parseFloat(d)))}c==="G"&&(d=d.toUpperCase()),r+=Oh(l,d)}}else if(c==="s"){const u=n[i++],h=Re(u)||Tt(u)?String.fromCharCode(Math.round(Ne(u))):Xe(u),d=l.slice(1).includes("-"),p=l.match(/^%[^0-9]*(\d+)/),m=p?parseInt(p[1]):0;if(m>h.length){const y=" ".repeat(m-h.length);r+=d?h+y:y+h}else r+=h}else c==="c"?r+=String.fromCharCode(Math.round(Ne(n[i++]))):(r+=l+c,i++)}}else if(e[a]==="\\"&&a+1<e.length){switch(a++,e[a]){case"n":r+=`
|
|
172
|
-
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"a":r+="\x07";break;case"b":r+="\b";break;case"f":r+="\f";break;case"v":r+="\v";break;case"0":r+="\0";break;case"\\":r+="\\";break;default:r+="\\"+e[a]}a++}else r+=e[a],a++;if(i===s)break}while(i<n.length);return r}function MR(e){if(Ht(e))return{re:e.re,im:e.im};if(Re(e))return{re:e,im:0};if(Tt(e))return{re:e?1:0,im:0};if(ce(e)&&e.data.length===1)return{re:e.data[0],im:e.imag?e.imag[0]:0};if(Dt(e))return MR(To(e));throw new q(`Cannot use ${po(e)} in complex arithmetic`)}function ah(e,t){return Ht(e)||Ht(t)||ce(e)&&e.imag!==void 0||ce(t)&&t.imag!==void 0||Dt(e)&&e.pi!==void 0||Dt(t)&&t.pi!==void 0}function Vp(e,t){return t===0?A.num(e):A.complex(e,t)}function Iv(e){if(Ht(e))return{scalar:!0,re:e.re,im:e.im};if(Re(e))return{scalar:!0,re:e,im:0};if(Tt(e))return{scalar:!0,re:e?1:0,im:0};if(ce(e)){if(e.data.length===1)return{scalar:!0,re:e.data[0],im:e.imag?e.imag[0]:0};const t=e.imag||D(e.data.length);return{scalar:!1,re:e.data,im:t,shape:e.shape}}if(Dt(e))return Iv(To(e));throw new q(`Cannot use ${po(e)} in complex arithmetic`)}function V$(e,t,n,r){const i=Iv(e),s=Iv(t);if(i.scalar&&s.scalar)return A.logical(n(i.re,i.im,s.re,s.im));if(i.scalar&&!s.scalar){const c=s.re.length;if(s.re instanceof Float64Array&&(!s.im||s.im instanceof Float64Array)){const f=D(c);ho.complexScalarComparison(r,c,i.re,i.im,s.re,s.im,!0,f);const d=A.tensor(f,s.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(i.re,i.im,s.re[f],s.im[f])?1:0;const h=A.tensor(u,s.shape);return h._isLogical=!0,h}if(!i.scalar&&s.scalar){const c=i.re.length;if(i.re instanceof Float64Array&&(!i.im||i.im instanceof Float64Array)){const f=D(c);ho.complexScalarComparison(r,c,s.re,s.im,i.re,i.im,!1,f);const d=A.tensor(f,i.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(i.re[f],i.im[f],s.re,s.im)?1:0;const h=A.tensor(u,i.shape);return h._isLogical=!0,h}const o=i,a=s;if(o.re.length===a.re.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=o.re.length;if(o.re instanceof Float64Array&&a.re instanceof Float64Array&&(!o.im||o.im instanceof Float64Array)&&(!a.im||a.im instanceof Float64Array)){const f=D(c);ho.complexComparison(r,c,o.re,o.im,a.re,a.im,f);const d=A.tensor(f,o.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(o.re[f],o.im[f],a.re[f],a.im[f])?1:0;const h=A.tensor(u,o.shape);return h._isLogical=!0,h}const l=Zu(o.shape,a.shape);if(l!==null)return yde(o,a,l,n);throw new q(`Matrix dimensions must agree for comparison: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}function ez(e){return e>0?1/0:e<0?-1/0:0}function ER(e,t,n,r){if(n===0&&r===0)return e===0&&t===0?{re:NaN,im:0}:{re:ez(e),im:ez(t)};if(Math.abs(n)>=Math.abs(r)){const o=r/n,a=n+r*o;return{re:(e+t*o)/a,im:(t-e*o)/a}}const i=n/r,s=r+n*i;return{re:(e*i+t)/s,im:(t*i-e)/s}}function Xd(e,t,n,r){if(r!==void 0){const c=tz(e),u=tz(t);if(c&&ce(t)&&t.data.length>1){const h=nz(c.re,c.im,t.data,t.imag,t.shape,r,!0);if(h)return h}else if(u&&ce(e)&&e.data.length>1){const h=nz(u.re,u.im,e.data,e.imag,e.shape,r,!1);if(h)return h}}const i=Iv(e),s=Iv(t);if(i.scalar&&s.scalar){const c=n(i.re,i.im,s.re,s.im);return Vp(c.re,c.im)}if(i.scalar&&!s.scalar){const c=s.re.length,u=D(c),h=D(c);for(let d=0;d<c;d++){const p=n(i.re,i.im,s.re[d],s.im[d]);u[d]=p.re,h[d]=p.im}const f=h.every(d=>d===0);return A.tensor(u,s.shape,f?void 0:h)}if(!i.scalar&&s.scalar){const c=i.re.length,u=D(c),h=D(c);for(let d=0;d<c;d++){const p=n(i.re[d],i.im[d],s.re,s.im);u[d]=p.re,h[d]=p.im}const f=h.every(d=>d===0);return A.tensor(u,i.shape,f?void 0:h)}const o=i,a=s;if(o.re.length===a.re.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=o.re.length,u=D(c),h=D(c);for(let d=0;d<c;d++){const p=n(o.re[d],o.im[d],a.re[d],a.im[d]);u[d]=p.re,h[d]=p.im}const f=h.every(d=>d===0);return A.tensor(u,o.shape,f?void 0:h)}const l=Zu(o.shape,a.shape);if(l!==null)return gde(o,a,l,n);throw new q(`Matrix dimensions must agree: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}const t_=0,n_=1,Cd=2,w0=3;function qM(e,t){if(typeof e!="object"||e===null||e.kind!=="tensor"||typeof t!="object"||t===null||t.kind!=="tensor")return null;const n=e,r=t;return n.data.length!==r.data.length||n.shape.length!==r.shape.length||n.shape.some((i,s)=>i!==r.shape[s])?null:[n,r]}function GM(e,t,n){if(!(e.data instanceof Float64Array)||!(t.data instanceof Float64Array))return null;const r=e.data.length,i=D(r);return ho.realBinaryElemwise(n,r,e.data,t.data,i),A.tensorRaw(i,e.shape)}function Ku(e,t,n,r){if(t.imag||!(t.data instanceof Float64Array))return null;const i=t.data.length,s=D(i);return ho.realScalarBinaryElemwise(n,i,e,t.data,r,s),A.tensorRaw(s,t.shape)}function tz(e){return Re(e)?{re:e,im:0}:Ht(e)?{re:e.re,im:e.im}:Tt(e)?{re:e?1:0,im:0}:ce(e)&&e.data.length===1?{re:e.data[0],im:e.imag?e.imag[0]:0}:null}function nz(e,t,n,r,i,s,o){if(!(n instanceof Float64Array)||r&&!(r instanceof Float64Array))return null;const a=n.length,l=D(a),c=D(a);ho.complexScalarBinaryElemwise(s,a,e,t,n,r??null,o,l,c);let u=!0;for(let h=0;h<a;h++)if(c[h]!==0){u=!1;break}return u?A.tensorRaw(l,i):A.tensor(l,i,c)}function XM(e,t,n,r){if(e.data instanceof Float64Array&&t.data instanceof Float64Array){const u=e.data.length,h=D(u),f=D(u);ho.complexBinaryElemwise(n,u,e.data,e.imag??null,t.data,t.imag??null,h,f);let d=!0;for(let p=0;p<u;p++)if(f[p]!==0){d=!1;break}return d?A.tensorRaw(h,e.shape):A.tensor(h,e.shape,f)}const i=e.data.length,s=e.imag,o=t.imag,a=D(i),l=D(i);if(s&&o)for(let u=0;u<i;u++){const h=r(e.data[u],s[u],t.data[u],o[u]);a[u]=h.re,l[u]=h.im}else if(s)for(let u=0;u<i;u++){const h=r(e.data[u],s[u],t.data[u],0);a[u]=h.re,l[u]=h.im}else for(let u=0;u<i;u++){const h=r(e.data[u],0,t.data[u],o[u]);a[u]=h.re,l[u]=h.im}const c=l.every(u=>u===0);return A.tensor(a,e.shape,c?void 0:l)}function ST(e){if(mt(e))return e;if(lt(e))return e.value;if(Tt(e))return e?"true":"false";if(Re(e))return J8(e);if(ce(e)&&e.data.length===1&&!e.imag){const t=e.data[0];return e._isLogical===!0?t?"true":"false":J8(t)}return null}function B0(e,t){if(Wn(e)||Wn(t)){const r=Wn(e)?e:null,i=Wn(t)?t:null;if(r&&i){if(r.shape[0]!==i.shape[0]||r.shape[1]!==i.shape[1])throw new q("Array dimensions must match for string plus");return hs(r.data.map((a,l)=>a+i.data[l]),r.shape)}const s=r??i,o=ST(r?t:e);if(o===null)throw new q("Cannot concatenate this value with a string");return hs(s.data.map(a=>r?a+o:o+a),s.shape)}if(mt(e)||mt(t)){const r=ST(e),i=ST(t);if(r!==null&&i!==null)return A.string(r+i)}if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]+i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i+r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,t_);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]+i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,t_,(s,o,a,l)=>({re:s+a,im:o+l}))}if(Dt(e)||Dt(t))return Jfe(e,t);if(ah(e,t))return Xd(e,t,(r,i,s,o)=>({re:r+s,im:i+o}),t_);if(Re(e)&&ce(t)){const r=Ku(e,t,t_,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,t_,!1);if(r)return r}return yf(e,t,(r,i)=>r+i,J$)}function Pv(e,t){if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]-i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i-r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,n_);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]-i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,n_,(s,o,a,l)=>({re:s-a,im:o-l}))}if(Dt(e)||Dt(t))return ede(e,t);if(ah(e,t))return Xd(e,t,(r,i,s,o)=>({re:r-s,im:i-o}),n_);if(Re(e)&&ce(t)){const r=Ku(e,t,n_,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,n_,!1);if(r)return r}return yf(e,t,(r,i)=>r-i,eV)}function vd(e,t){if(Dt(e)||Dt(t))return tde(e,t);if(ce(e)&&e.data.length===1&&(e=Vc(e)),ce(t)&&t.data.length===1&&(t=Vc(t)),ce(e)&&ce(t))return tV(e,t);if(ah(e,t))return Xd(e,t,(n,r,i,s)=>({re:n*i-r*s,im:n*s+r*i}),Cd);if(Re(e)&&ce(t)){const n=Ku(e,t,Cd,!0);if(n)return n}else if(ce(e)&&Re(t)){const n=Ku(t,e,Cd,!1);if(n)return n}return yf(e,t,(n,r)=>n*r,uI)}function nI(e,t){if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]*i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i*r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,Cd);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]*i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,Cd,(s,o,a,l)=>({re:s*a-o*l,im:s*l+o*a}))}if(Dt(e)||Dt(t))return nde(e,t);if(ah(e,t))return Xd(e,t,(r,i,s,o)=>({re:r*s-i*o,im:r*o+i*s}),Cd);if(Re(e)&&ce(t)){const r=Ku(e,t,Cd,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,Cd,!1);if(r)return r}return yf(e,t,(r,i)=>r*i,uI)}function rI(e,t){if(Dt(e)||Dt(t))return rI(To(e),To(t));if(ce(e)&&e.data.length===1&&(e=Vc(e)),ce(t)&&t.data.length===1&&(t=Vc(t)),ce(t)){const n=Z_(tI(e,"mrdivide")),r=Z_(t),i=Bv(r,n);return Z_(i)}return ah(e,t)?Xd(e,t,ER,w0):yf(e,t,(n,r)=>n/r,hI)}function pm(e,t){if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]/i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i/r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,w0);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]/i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,w0,ER)}if(Dt(e)||Dt(t))return rde(e,t);if(ah(e,t))return Xd(e,t,ER,w0);if(Re(e)&&ce(t)){const r=Ku(e,t,w0,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,w0,!1);if(r)return r}return yf(e,t,(r,i)=>r/i,hI)}function Bv(e,t){if(Dt(e))return Bv(To(e),t);if(Dt(t))return Bv(e,To(t));if(ce(e)&&e.data.length===1&&(e=Vc(e)),ce(t)&&t.data.length===1&&(t=Vc(t)),Re(e)||Tt(e))return pm(t,e);const n=e,r=Re(t)||Tt(t)?A.tensor(D([Ne(t)]),[1,1]):t;if(!ce(n)||!ce(r))throw new q("mldivide (\\): operands must be numeric matrices");const[i,s]=Bn(n),[o,a]=Bn(r);if(o!==i)throw new q(`mldivide (\\): A is ${i}×${s} but B has ${o} rows`);if(i===0||s===0||a===0)return A.tensor(D(s*a),[s,a]);if(n.imag||r.imag){const c=n.data,u=n.imag??D(n.data.length),h=r.data,f=r.imag??D(r.data.length),d=eI(c,u,i,s,h,f,a);return Vc(A.tensor(d.re,[s,a],d.im))}const l=WM(n.data,i,s,r.data,a);if(!l)throw new q("mldivide (\\): LAPACK bridge unavailable");return Vc(A.tensor(l,[s,a]))}function fde(e,t){return pm(t,e)}function dde(e){return Number.isInteger(e)?(e&1)===0?1:-1:Number.isInteger(e*2)?0:Math.cos(Math.PI*e)}function pde(e){if(Number.isInteger(e))return 0;const t=e*2;return Number.isInteger(t)?((t-1)/2&1)===0?1:-1:Math.sin(Math.PI*e)}function CR(e,t){const n=Math.pow(-e,t);return{re:n*dde(t),im:n*pde(t)}}function W$(e,t){if(ah(e,t)){const n=MR(e),r=MR(t);if(n.im===0&&r.im===0&&n.re<0){const u=CR(n.re,r.re);return Vp(u.re,u.im)}const i=Math.hypot(n.re,n.im);if(i===0)return r.re===0&&r.im===0?Vp(1,0):r.re>0?Vp(0,0):Vp(1/0,0);const s=Math.atan2(n.im,n.re),o=Math.log(i),a=r.re*o-r.im*s,l=r.re*s+r.im*o,c=Math.exp(a);return Vp(c*Math.cos(l),c*Math.sin(l))}if(ce(e)&&(Re(t)||Tt(t))){const n=Ne(t),[r,i]=Bn(e);if(r===i&&Number.isInteger(n)){if(n===0){const l=D(r*i);for(let c=0;c<r;c++)l[gn(c,c,r)]=1;return A.tensor(l,[r,i])}let s=e,o=n;if(o<0){const l=hde("mpower","inv",[e],1);if(!ce(l))throw new q("mpower: inv returned non-tensor");s=l,o=-o}let a=s;for(let l=1;l<o;l++)a=tV(a,s);return a}}if(Re(e)&&e<0&&Re(t)&&!Number.isInteger(t)){const n=CR(e,t);return Vp(n.re,n.im)}return yf(e,t,(n,r)=>Math.pow(n,r))}function q$(e,t){if(ce(e)&&!e.imag&&Re(t)){const i=t;if(i===2){const s=D(e.data.length);for(let o=0;o<s.length;o++)s[o]=e.data[o]*e.data[o];return A.tensor(s,e.shape)}if(Number.isInteger(i)||i>=0){let s=!1;if(!Number.isInteger(i)){for(let o=0;o<e.data.length;o++)if(e.data[o]<0){s=!0;break}}if(!s){const o=D(e.data.length);for(let a=0;a<o.length;a++)o[a]=Math.pow(e.data[a],i);return A.tensor(o,e.shape)}}}const n=(i,s,o,a)=>{if(s===0&&a===0&&i<0)return CR(i,o);const l=Math.hypot(i,s);if(l===0)return o===0&&a===0?{re:1,im:0}:o>0?{re:0,im:0}:{re:1/0,im:0};const c=Math.atan2(s,i),u=Math.log(l),h=o*u-a*c,f=o*c+a*u,d=Math.exp(h);return{re:d*Math.cos(f),im:d*Math.sin(f)}};if(ah(e,t))return Xd(e,t,n);let r=!1;if(Re(e)&&e<0)r=!0;else if(ce(e)){for(let i=0;i<e.data.length;i++)if(e.data[i]<0){r=!0;break}}if(r){let i=!1;if(Re(t))i=Number.isInteger(t);else if(Tt(t))i=!0;else if(ce(t)){i=!0;for(let s=0;s<t.data.length;s++)if(!Number.isInteger(t.data[s])){i=!1;break}}return i?yf(e,t,(s,o)=>Math.pow(s,o)):Xd(e,t,n)}return yf(e,t,(i,s)=>Math.pow(i,s))}function G$(e){if(ce(e)){if(e.imag!==void 0){const n=D(e.data.length),r=D(e.imag.length);for(let i=0;i<e.data.length;i++)n[i]=-e.data[i],r[i]=-e.imag[i];return A.tensor(n,e.shape,r)}const t=D(e.data.length);for(let n=0;n<e.data.length;n++)t[n]=-e.data[n];return A.tensor(t,e.shape)}return Dt(e)?Yfe(e):Ht(e)?A.complex(-e.re,-e.im):vde(e,t=>-t)}function X$(e){const t=e.shape,n=t.length===0||t.length===1?1:t[0],r=t.length===0?1:t.length===1?t[0]:t[1],i=new Array(e.data.length);for(let s=0;s<n;s++)for(let o=0;o<r;o++)i[s*r+o]=e.data[gn(s,o,n)];return A.cell(i,[r,n])}function Y$(e,t){const[n,r]=Bn(e),i=D(e.data.length);for(let o=0;o<n;o++)for(let a=0;a<r;a++)i[o*r+a]=e.data[gn(o,a,n)];if(e.imag!==void 0){const o=D(e.imag.length),a=t?-1:1;for(let l=0;l<n;l++)for(let c=0;c<r;c++)o[l*r+c]=a*e.imag[gn(l,c,n)];return A.tensor(i,[r,n],o)}const s=A.tensor(i,[r,n]);return e._isLogical&&(s._isLogical=!0),s}function K$(e){const[t,n]=e.shape,r=new Array(e.elements.length);for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[i*n+s]=e.elements[s*t+i];return new UM(e.className,r,[n,t])}function Z$(e){const[t,n]=e.shape,r=new Array(t*n);for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[i*n+s]=e.data[s*t+i];return hs(r,[n,t])}function Q$(e){if(Dt(e))return z$(e);if(Ht(e)||Re(e)||Tt(e))return e;if(nn(e))return X$(e);if(lt(e)||mt(e))return e;if(Wn(e))return Z$(e);if(In(e))return e;if(ii(e))return K$(e);if(!ce(e))throw new q("Cannot transpose non-numeric value");return Y$(e,!1)}function Z_(e){if(Dt(e))return Kfe(e);if(Ht(e))return A.complex(e.re,-e.im);if(Re(e)||Tt(e))return e;if(nn(e))return X$(e);if(lt(e)||mt(e))return e;if(Wn(e))return Z$(e);if(In(e))return e;if(ii(e))return K$(e);if(!ce(e))throw new q("Cannot transpose non-numeric value");return Y$(e,!0)}function mde(e,t){return mt(e)&&mt(t)?[e,t]:mt(e)&<(t)?[e,t.value]:lt(e)&&mt(t)?[e.value,t]:null}function rz(e){return mt(e)?{data:[e],shape:[1,1]}:lt(e)?(e.shape?e.shape[0]:1)>1?null:{data:[e.value],shape:[1,1]}:Wn(e)?{data:e.data,shape:e.shape}:null}function L1(e,t,n){if(Wn(e)||Wn(t)){const i=rz(e),s=rz(t);if(i===null||s===null)return null;const o=i.data.length===1&&i.shape[0]*i.shape[1]===1,a=s.data.length===1&&s.shape[0]*s.shape[1]===1;if(!o&&!a&&(i.shape[0]!==s.shape[0]||i.shape[1]!==s.shape[1]))throw new q("Array dimensions must match for comparison");const l=o?s.shape:i.shape,c=o?s.data.length:i.data.length,u=D(c);for(let f=0;f<c;f++){const d=o?i.data[0]:i.data[f],p=a?s.data[0]:s.data[f];u[f]=n(d,p)?1:0}const h=A.tensor(u,[l[0],l[1]]);return h._isLogical=!0,h}const r=mde(e,t);return r===null?null:A.logical(n(r[0],r[1]))}function To(e){return Dt(e)?Mr(e):e}function iI(e,t){if(Dt(e)||Dt(t))return iI(To(e),To(t));const n=L1(e,t,(r,i)=>r===i);return n!==null?n:ah(e,t)?V$(e,t,(r,i,s,o)=>r===s&&i===o,hi.EQ):I1(e,t,(r,i)=>r===i,hi.EQ)}function sI(e,t){if(Dt(e)||Dt(t))return sI(To(e),To(t));const n=L1(e,t,(r,i)=>r!==i);return n!==null?n:ah(e,t)?V$(e,t,(r,i,s,o)=>r!==s||i!==o,hi.NE):I1(e,t,(r,i)=>r!==i,hi.NE)}function oI(e,t){if(Dt(e)||Dt(t))return oI(To(e),To(t));const n=L1(e,t,(r,i)=>r<i);return n!==null?n:I1(e,t,(r,i)=>r<i,hi.LT)}function aI(e,t){if(Dt(e)||Dt(t))return aI(To(e),To(t));const n=L1(e,t,(r,i)=>r<=i);return n!==null?n:I1(e,t,(r,i)=>r<=i,hi.LE)}function lI(e,t){if(Dt(e)||Dt(t))return lI(To(e),To(t));const n=L1(e,t,(r,i)=>r>i);return n!==null?n:I1(e,t,(r,i)=>r>i,hi.GT)}function cI(e,t){if(Dt(e)||Dt(t))return cI(To(e),To(t));const n=L1(e,t,(r,i)=>r>=i);return n!==null?n:I1(e,t,(r,i)=>r>=i,hi.GE)}function o1(e){if(Re(e))return{scalar:!0,value:e,isComplex:!1};if(Tt(e))return{scalar:!0,value:e?1:0,isComplex:!1};if(Ht(e))return{scalar:!0,re:e.re,im:e.im,isComplex:!0};if(ce(e))return e.data.length===1?e.imag!==void 0?{scalar:!0,re:e.data[0],im:e.imag[0],isComplex:!0}:{scalar:!0,value:e.data[0],isComplex:!1}:{scalar:!1,tensor:e};if(Dt(e))return o1(To(e));if(lt(e)){if(e.value.length===1)return{scalar:!0,value:e.value.charCodeAt(0),isComplex:!1};const t=D(Array.from(e.value).map(n=>n.charCodeAt(0)));return{scalar:!1,tensor:A.tensorRaw(t,[1,e.value.length])}}throw new q(`Cannot use ${po(e)} in numeric operation`)}function Zu(e,t){const n=Math.max(e.length,t.length,2),r=R2(e.length===0?[1,1]:e.length===1?[1,e[0]]:e,n),i=R2(t.length===0?[1,1]:t.length===1?[1,t[0]]:t,n),s=[];for(let o=0;o<n;o++){const a=r[o],l=i[o];if(a===l)s.push(a);else if(a===1)s.push(l);else if(l===1)s.push(a);else return null}return s}function R2(e,t){if(e.length>=t)return e;const n=[...e];for(;n.length<t;)n.push(1);return n}function gf(e,t,n,r){const i=n.length,s=n.reduce((m,y)=>m*y,1),o=R2(e,i),a=R2(t,i),l=new Array(i),c=new Array(i);let u=1,h=1;for(let m=0;m<i;m++)l[m]=o[m]===1?0:u,c[m]=a[m]===1?0:h,u*=o[m],h*=a[m];const f=new Array(i).fill(0);let d=0,p=0;for(let m=0;m<s;m++){r(d,p,m);for(let y=0;y<i&&(f[y]++,d+=l[y],p+=c[y],!(f[y]<n[y]));y++)d-=f[y]*l[y],p-=f[y]*c[y],f[y]=0}}const J$=0,eV=1,uI=2,hI=3;function iz(e,t,n,r,i){if(n.length===2){const o=n[0],a=n[1],l=D(o*a),c=e.shape,u=t.shape,h=c.length>=1?c[0]:1,f=c.length>=2?c[1]:1,d=u.length>=1?u[0]:1,p=u.length>=2?u[1]:1,m=h===1?0:1,y=f===1?0:h,_=d===1?0:1,b=p===1?0:d,x=e.data,S=t.data;let M=0;if(i===J$)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]+S[k+R*_]}else if(i===eV)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]-S[k+R*_]}else if(i===uI)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]*S[k+R*_]}else if(i===hI)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]/S[k+R*_]}else for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=r(x[T+R*m],S[k+R*_])}return A.tensor(l,n)}const s=D(n.reduce((o,a)=>o*a,1));return gf(e.shape,t.shape,n,(o,a,l)=>{s[l]=r(e.data[o],t.data[a])}),A.tensor(s,n)}function gde(e,t,n,r){const i=n.reduce((l,c)=>l*c,1),s=D(i),o=D(i);gf(e.shape,t.shape,n,(l,c,u)=>{const h=r(e.re[l],e.im[l],t.re[c],t.im[c]);s[u]=h.re,o[u]=h.im});const a=o.every(l=>l===0);return A.tensor(s,n,a?void 0:o)}function yde(e,t,n,r){const i=D(n.reduce((o,a)=>o*a,1));gf(e.shape,t.shape,n,(o,a,l)=>{i[l]=r(e.re[o],e.im[o],t.re[a],t.im[a])?1:0});const s=A.tensor(i,n);return s._isLogical=!0,s}function _de(e,t,n,r){const i=D(n.reduce((o,a)=>o*a,1));gf(e.shape,t.shape,n,(o,a,l)=>{i[l]=r(e.data[o],t.data[a])?1:0});const s=A.tensor(i,n);return s._isLogical=!0,s}function yf(e,t,n,r){if(ce(e)&&e.data.length>1){if(ce(t)&&t.data.length>1){if(e.data.length===t.data.length&&e.shape.length===t.shape.length&&e.shape.every((u,h)=>u===t.shape[h])){const u=D(e.data.length);for(let h=0;h<u.length;h++)u[h]=n(e.data[h],t.data[h]);return A.tensor(u,e.shape)}const c=Zu(e.shape,t.shape);if(c!==null)return iz(e,t,c,n,r);throw new q(`Matrix dimensions must agree: [${e.shape.join(",")}] vs [${t.shape.join(",")}]`)}if(Re(t)){const c=D(e.data.length),u=t;for(let h=0;h<c.length;h++)c[h]=n(e.data[h],u);return A.tensor(c,e.shape)}}if(ce(t)&&t.data.length>1&&Re(e)){const c=D(t.data.length),u=e;for(let h=0;h<c.length;h++)c[h]=n(u,t.data[h]);return A.tensor(c,t.shape)}const i=o1(e),s=o1(t);if(i.scalar&&s.scalar){const c=i.isComplex?i.re:i.value,u=s.isComplex?s.re:s.value;return A.num(n(c,u))}if(i.scalar&&!s.scalar){const c=s.tensor,u=D(c.data.length),h=i.isComplex?i.re:i.value;for(let f=0;f<u.length;f++)u[f]=n(h,c.data[f]);return A.tensor(u,c.shape)}if(!i.scalar&&s.scalar){const c=i.tensor,u=D(c.data.length),h=s.isComplex?s.re:s.value;for(let f=0;f<u.length;f++)u[f]=n(c.data[f],h);return A.tensor(u,c.shape)}const o=i.tensor,a=s.tensor;if(o.data.length===a.data.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=D(o.data.length);for(let u=0;u<c.length;u++)c[u]=n(o.data[u],a.data[u]);return A.tensor(c,o.shape)}const l=Zu(o.shape,a.shape);if(l!==null)return iz(o,a,l,n,r);throw new q(`Matrix dimensions must agree: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}function vde(e,t){if(ce(e)&&e.data.length>1){const i=D(e.data.length);for(let s=0;s<i.length;s++)i[s]=t(e.data[s]);return A.tensor(i,e.shape)}const n=o1(e);if(n.scalar){const i=n.isComplex?n.re:n.value;return A.num(t(i))}const r=D(n.tensor.data.length);for(let i=0;i<r.length;i++)r[i]=t(n.tensor.data[i]);return A.tensor(r,n.tensor.shape)}function I1(e,t,n,r){const i=o1(e),s=o1(t);if(i.scalar&&s.scalar){const c=i.isComplex?i.re:i.value,u=s.isComplex?s.re:s.value;return A.logical(n(c,u))}if(i.scalar&&!s.scalar){const c=i.isComplex?i.re:i.value,u=s.tensor.data.length;if(s.tensor.data instanceof Float64Array){const d=D(u);ho.realScalarComparison(r,u,c,s.tensor.data,!0,d);const p=A.tensor(d,s.tensor.shape);return p._isLogical=!0,p}const h=D(u);for(let d=0;d<u;d++)h[d]=n(c,s.tensor.data[d])?1:0;const f=A.tensor(h,s.tensor.shape);return f._isLogical=!0,f}if(!i.scalar&&s.scalar){const c=s.isComplex?s.re:s.value,u=i.tensor.data.length;if(i.tensor.data instanceof Float64Array){const d=D(u);ho.realScalarComparison(r,u,c,i.tensor.data,!1,d);const p=A.tensor(d,i.tensor.shape);return p._isLogical=!0,p}const h=D(u);for(let d=0;d<u;d++)h[d]=n(i.tensor.data[d],c)?1:0;const f=A.tensor(h,i.tensor.shape);return f._isLogical=!0,f}const o=i.tensor,a=s.tensor;if(o.data.length===a.data.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=o.data.length;if(o.data instanceof Float64Array&&a.data instanceof Float64Array){const f=D(c);ho.realComparison(r,c,o.data,a.data,f);const d=A.tensor(f,o.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(o.data[f],a.data[f])?1:0;const h=A.tensor(u,o.shape);return h._isLogical=!0,h}const l=Zu(o.shape,a.shape);if(l!==null)return _de(o,a,l,n);throw new q(`Matrix dimensions must agree for comparison: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}function Vc(e){return ce(e)&&e.data.length===1?e.imag&&e.imag[0]!==0?A.complex(e.data[0],e.imag[0]):A.num(e.data[0]):e}function tV(e,t){const[n,r]=Bn(e),[i,s]=Bn(t);if(r!==i)throw new q(`Inner matrix dimensions must agree: ${r} vs ${i}`);if(n===0||r===0||s===0)return A.tensor(D(n*s),[n,s]);if(!(e.imag!==void 0||t.imag!==void 0)){const d=Ds("matmul","matmul"),p=e.data instanceof Float64Array?e.data:D(e.data),m=t.data instanceof Float64Array?t.data:D(t.data),y=d.matmul(p,n,r,m,s);return Vc(A.tensor(y,[n,s]))}const a=e.imag||D(e.data.length),l=t.imag||D(t.data.length),c=Ds("matmul","matmulComplex");if(c.matmulComplex){const d=e.data instanceof Float64Array?e.data:D(e.data),p=a instanceof Float64Array?a:D(a),m=t.data instanceof Float64Array?t.data:D(t.data),y=l instanceof Float64Array?l:D(l),_=c.matmulComplex(d,p,n,r,m,y,s);return Vc(A.tensor(_.re,[n,s],_.im))}const u=D(n*s),h=D(n*s);for(let d=0;d<n;d++)for(let p=0;p<s;p++){let m=0,y=0;for(let b=0;b<r;b++){const x=gn(d,b,n),S=gn(b,p,i),M=e.data[x],E=a[x],T=t.data[S],k=l[S];m+=M*T-E*k,y+=M*k+E*T}const _=gn(d,p,n);u[_]=m,h[_]=y}const f=h.every(d=>d===0);return Vc(A.tensor(u,[n,s],f?void 0:h))}const bde="__COLON__";function Ni(e){return mt(e)&&e==="__COLON__"}function zu(e){if(Re(e))return{re:e,im:0};if(Tt(e))return{re:e?1:0,im:0};if(Ht(e))return{re:e.re,im:e.im};if(ce(e)&&e.data.length===1)return{re:e.data[0],im:e.imag?e.imag[0]:0};if(Dt(e)&&e.m===1&&e.n===1){const t=e.pr.length>0?e.pr[0]:0,n=e.pi&&e.pi.length>0?e.pi[0]:0;return{re:t,im:n}}throw new q(`Cannot convert ${po(e)} to number for assignment`)}function sz(e){const t=e.shape?e.shape[0]:1,n=e.shape?e.shape[1]:e.value.length,r=D(t*n);for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[s*t+i]=e.value.charCodeAt(i*n+s);return A.tensor(r,[t,n])}function xde(e){const t=e.shape.length>=2?e.shape[0]??0:1,n=e.shape.length>=2?e.shape[1]??0:e.data.length;let r="";for(let i=0;i<t;i++)for(let s=0;s<n;s++)r+=String.fromCharCode(Math.round(e.data[s*t+i]));return t>1?new Sf(r,[t,n]):A.char(r)}function jo(e){e.imag||(e.imag=D(e.data.length))}function D2(e,t){if(e.imag!==void 0){const n=e.imag[t];return n===0?A.num(e.data[t]):A.complex(e.data[t],n)}return e._isLogical===!0?e.data[t]!==0:A.num(e.data[t])}function Ao(e,t,n=t){if(Ni(e))return Array.from({length:t},(i,s)=>s);if(Tt(e))return e?[0]:[];if(ce(e)){if(e._isLogical){const i=[];for(let s=0;s<e.data.length;s++)e.data[s]!==0&&i.push(s);return i}return Array.from(e.data).map(i=>{const s=Math.round(i)-1;if(s<0||n>0&&s>=n)throw new q("Index exceeds array bounds");return s})}const r=Math.round(Ne(e))-1;if(r<0||n>0&&r>=n)throw new q("Index exceeds array bounds");return[r]}function wde(e,t,n,r){return{rowIndices:Ao(e,n),colIndices:Ao(t,r)}}function N2(e,t,n){const[r,i]=Bn(e);if(t<=r&&n<=i)return e;const s=Math.max(r,t),o=Math.max(i,n),a=D(s*o),c=e.imag!==void 0?D(s*o):void 0;for(let u=0;u<i;u++)for(let h=0;h<r;h++)a[h+u*s]=e.data[h+u*r],c&&e.imag&&(c[h+u*s]=e.imag[h+u*r]);return A.tensor(a,[s,o],c)}function Sde(e,t,n,r,i){if(ce(r)){const s=t.length,o=n.length;if(r.data.length===1){const d=r.data[0],p=r.imag?r.imag[0]:0;(p!==0||e.imag)&&jo(e);for(const m of t)for(const y of n){const _=gn(m,y,i);e.data[_]=d,e.imag&&(e.imag[_]=p)}return}const[a,l]=Bn(r),c=a===s&&l===o,u=s===1||o===1,h=a===1||l===1,f=r.data.length===s*o;if(!c&&!(u&&h&&f))throw new q("Subscripted assignment dimension mismatch");if((r.imag||e.imag)&&jo(e),c)for(let d=0;d<s;d++)for(let p=0;p<o;p++){const m=gn(t[d],n[p],i),y=gn(d,p,a);e.data[m]=r.data[y],e.imag&&(e.imag[m]=r.imag?r.imag[y]:0)}else{let d=0;for(let p=0;p<o;p++)for(let m=0;m<s;m++){const y=gn(t[m],n[p],i);e.data[y]=r.data[d],e.imag&&(e.imag[y]=r.imag?r.imag[d]:0),d++}}}else{const{re:s,im:o}=zu(r);(o!==0||e.imag)&&jo(e);for(const a of t)for(const l of n){const c=gn(a,l,i);e.data[c]=s,e.imag&&(e.imag[c]=o)}}}function Mde(e,t){if(Re(e)||Tt(e)||Ht(e))return new Array(t).fill(e);if(ce(e)){const n=[];for(let r=0;r<t;r++)e.imag?n.push(A.complex(e.data[r],e.imag[r])):n.push(A.num(e.data[r]));return n}return new Array(t).fill(e)}function MT(e,t,n){for(let r=e.jc[n];r<e.jc[n+1];r++)if(e.ir[r]===t)return{re:e.pr[r],im:e.pi?e.pi[r]:0};return{re:0,im:0}}function Ede(e,t,n){const r=t.length,i=n.length,s=new Map;for(let h=0;h<r;h++){const f=t[h],d=s.get(f);d?d.push(h):s.set(f,[h])}const o=e.pi!==void 0,a=[],l=[],c=[],u=new Int32Array(i+1);for(let h=0;h<i;h++){const f=n[h];u[h]=a.length;const d=[];for(let p=e.jc[f];p<e.jc[f+1];p++){const m=s.get(e.ir[p]);if(m!==void 0){const y=e.pr[p],_=o?e.pi[p]:0;for(const b of m)d.push({newRow:b,re:y,im:_})}}d.sort((p,m)=>p.newRow-m.newRow);for(const p of d)a.push(p.newRow),l.push(p.re),o&&c.push(p.im)}return u[i]=a.length,A.sparseMatrix(r,i,new Int32Array(a),u,D(l),o?D(c):void 0)}function nV(e,t,n){if(t.length===1){const y=e.m*e.n,_=Ao(t[0],y),b=_.map(E=>E%e.m),x=_.map(E=>Math.floor(E/e.m));let S=e;const M=Mde(n,_.length);for(let E=0;E<_.length;E++)S=nV(S,[A.num(b[E]+1),A.num(x[E]+1)],M[E]);return S}if(t.length!==2)throw new q("Sparse matrix assignment requires 1 or 2 indices");const r=Ao(t[0],e.m),i=Ao(t[1],e.n),s=r.length,o=i.length,a=D(s*o),l=D(s*o);let c=!1;if(Re(n))a.fill(n);else if(Tt(n))a.fill(n?1:0);else if(Ht(n))a.fill(n.re),l.fill(n.im),c=n.im!==0;else if(ce(n)){for(let y=0;y<n.data.length;y++)a[y]=n.data[y];if(n.imag){for(let y=0;y<n.imag.length;y++)l[y]=n.imag[y];c=!0}}else if(Dt(n))for(let y=0;y<n.n;y++)for(let _=n.jc[y];_<n.jc[y+1];_++){const b=y*s+n.ir[_];a[b]=n.pr[_],n.pi&&(l[b]=n.pi[_],c=!0)}else throw new q("Cannot assign non-numeric value into sparse matrix");const u=e.pi!==void 0||c,h=new Map;for(let y=0;y<e.n;y++){const _=[];for(let b=e.jc[y];b<e.jc[y+1];b++)_.push({row:e.ir[b],re:e.pr[b],im:e.pi?e.pi[b]:0});_.length>0&&h.set(y,_)}for(let y=0;y<o;y++){const _=i[y];let b=h.get(_);b||(b=[],h.set(_,b));for(let x=0;x<s;x++){const S=r[x],M=a[y*s+x],E=l[y*s+x];let T=!1;for(let k=0;k<b.length;k++)if(b[k].row===S){M===0&&E===0?b.splice(k,1):(b[k].re=M,b[k].im=E),T=!0;break}!T&&(M!==0||E!==0)&&b.push({row:S,re:M,im:E})}b.sort((x,S)=>x.row-S.row),b.length===0&&h.delete(_)}const f=[],d=[],p=[],m=new Int32Array(e.n+1);for(let y=0;y<e.n;y++){m[y]=f.length;const _=h.get(y);if(_)for(const b of _)f.push(b.row),d.push(b.re),u&&p.push(b.im)}return m[e.n]=f.length,A.sparseMatrix(e.m,e.n,new Int32Array(f),m,D(d),u?D(p):void 0)}function Cde(e,t){if(t.length===1){const n=t[0];if(Ni(n)){const r=e.m*e.n,i=[],s=[],o=[],a=e.pi!==void 0;for(let c=0;c<e.n;c++)for(let u=e.jc[c];u<e.jc[c+1];u++){const h=c*e.m+e.ir[u];i.push(h),s.push(e.pr[u]),a&&o.push(e.pi[u])}const l=new Int32Array([0,i.length]);return A.sparseMatrix(r,1,new Int32Array(i),l,D(s),a?D(o):void 0)}if(Re(n)){const r=Math.round(n)-1;if(r<0||r>=e.m*e.n)throw new q("Index exceeds array bounds");const i=Math.floor(r/e.m),s=r%e.m,o=MT(e,s,i);return e.pi!==void 0&&o.im!==0?A.complex(o.re,o.im):o.re}if(ce(n)||Tt(n)){const r=e.m*e.n,i=Ao(n,r),s=i.length,o=e.pi!==void 0,a=[],l=[],c=[],u=new Int32Array(s+1);for(let h=0;h<s;h++){u[h]=a.length;const f=i[h],d=Math.floor(f/e.m),p=f%e.m,m=MT(e,p,d);(m.re!==0||m.im!==0)&&(a.push(0),l.push(m.re),o&&c.push(m.im))}return u[s]=a.length,A.sparseMatrix(1,s,new Int32Array(a),u,D(l),o?D(c):void 0)}}if(t.length===2){if(Ni(t[0])){const i=Ao(t[1],e.n);if(i.length===1){const h=i[0],f=e.jc[h],p=e.jc[h+1]-f,m=new Int32Array(p),y=D(p);let _;for(let x=0;x<p;x++)m[x]=e.ir[f+x],y[x]=e.pr[f+x];if(e.pi!==void 0){_=D(p);for(let x=0;x<p;x++)_[x]=e.pi[f+x]}const b=new Int32Array([0,p]);return A.sparseMatrix(e.m,1,m,b,y,_)}const s=i.length,o=e.pi!==void 0,a=[],l=[],c=[],u=new Int32Array(s+1);for(let h=0;h<s;h++){u[h]=a.length;const f=i[h];for(let d=e.jc[f];d<e.jc[f+1];d++)a.push(e.ir[d]),l.push(e.pr[d]),o&&c.push(e.pi[d])}return u[s]=a.length,A.sparseMatrix(e.m,s,new Int32Array(a),u,D(l),o?D(c):void 0)}const n=Ao(t[0],e.m),r=Ao(t[1],e.n);if(n.length===1&&r.length===1){const i=MT(e,n[0],r[0]);return e.pi!==void 0&&i.im!==0?A.complex(i.re,i.im):i.re}return Ede(e,n,r)}throw new q("Sparse matrix supports 1 or 2 index dimensions")}function Ade(e,t){if(t.some(l=>ce(l)&&l.data.length===0)){if(t.length===2){const c=u=>Ni(u)?1:ce(u)?u.data.length:1;return A.tensor(D(0),[c(t[0]),c(t[1])])}const l=t[0];if(ce(l)){const u=l.shape.length===2&&l.shape[0]===0&&l.shape[1]===0?[0,0]:[...l.shape];return A.tensor(D(0),u)}}if(t.length===1){const l=t[0];if(Tt(l))return l?e:A.tensor(D(0),[0,0]);if(ce(l)&&l._isLogical){let c=0;for(let h=0;h<l.data.length;h++)l.data[h]&&c++;if(c===0)return A.tensor(D(0),[0,0]);const u=D(c);if(u.fill(Re(e)?e:e.re),Ht(e)&&e.im!==0){const h=D(c);return h.fill(e.im),A.tensor(u,[1,c],h)}return A.tensor(u,[1,c])}}if(t.length===1&&ce(t[0])){const l=t[0];for(let f=0;f<l.data.length;f++)if(Math.round(l.data[f])!==1)throw new q("Index exceeds array bounds");const c=l.data.length,u=Re(e)?e:e.re,h=D(c);if(h.fill(u),Ht(e)&&e.im!==0){const f=D(c);return f.fill(e.im),A.tensor(h,[...l.shape],f)}return A.tensor(h,[...l.shape])}const n=[];let r=!1;for(const l of t)if(Ni(l))n.push(1);else if(ce(l)){r=!0;for(let c=0;c<l.data.length;c++)if(Math.round(l.data[c])!==1)throw new q("Index exceeds array bounds");n.push(l.data.length)}else{if(Math.round(Ne(l))!==1)throw new q("Index exceeds array bounds");n.push(1)}if(!r)return e;const i=n.reduce((l,c)=>l*c,1),s=Re(e)?e:e.re,o=D(i);o.fill(s);const a=n.length>=2?n:[n[0],1];if(Ht(e)&&e.im!==0){const l=D(i);return l.fill(e.im),A.tensor(o,a,l)}return A.tensor(o,a)}function Tde(e,t){if(t.length===1)return kde(e,t[0]);if(e.shape.length>t.length){const n=[];for(let s=0;s<t.length-1;s++)n.push(e.shape[s]);let r=1;for(let s=t.length-1;s<e.shape.length;s++)r*=e.shape[s];n.push(r);const i=e.shape;e.shape=n;try{return t.length===2?oz(e,t[0],t[1]):az(e,t)}finally{e.shape=i}}return t.length===2?oz(e,t[0],t[1]):az(e,t)}function kde(e,t){if(Ni(t)){const n=e.imag?D(e.imag):void 0,r=A.tensor(D(e.data),[e.data.length,1],n);return e._isLogical===!0&&(r._isLogical=!0),r}if(Tt(t))return t?D2(e,0):A.tensor(D(0),[0,0]);if(Re(t)){const n=Math.round(Ne(t))-1;if(n<0||n>=e.data.length)throw new q("Index exceeds array bounds");return D2(e,n)}if(ce(t))return Bde(e,t);throw new q("Invalid index type for tensor")}function oz(e,t,n){const[r,i]=Bn(e),s=e._isLogical===!0,o=d=>(s&&ce(d)&&(d._isLogical=!0),d);if(Re(t)&&Ni(n)){const d=Math.round(t)-1;if(d<0||d>=r)throw new q("Index exceeds array bounds");const p=D(i),m=e.imag?D(i):void 0;for(let y=0;y<i;y++)p[y]=e.data[d+y*r],m&&e.imag&&(m[y]=e.imag[d+y*r]);return o(A.tensor(p,[1,i],m))}if(Ni(t)&&Re(n)){const d=Math.round(n)-1;if(d<0||d>=i)throw new q("Index exceeds array bounds");const p=d*r,m=D(r);for(let _=0;_<r;_++)m[_]=e.data[p+_];const y=e.imag?D(r):void 0;if(y&&e.imag)for(let _=0;_<r;_++)y[_]=e.imag[p+_];return o(A.tensor(m,[r,1],y))}const a=Ao(t,r),l=Ao(n,i),c=a.length,u=l.length;if(c===1&&u===1){const d=gn(a[0],l[0],r);return D2(e,d)}const h=D(c*u),f=e.imag?D(c*u):void 0;for(let d=0;d<u;d++)for(let p=0;p<c;p++){const m=gn(a[p],l[d],r),y=gn(p,d,c);h[y]=e.data[m],f&&e.imag&&(f[y]=e.imag[m])}return o(A.tensor(h,[c,u],f))}function az(e,t){const n=e.shape,r=t.map((m,y)=>{const _=y<n.length?n[y]:1;return Ao(m,_)});if(r.every(m=>m.length===1)){const m=r.map(_=>_[0]),y=Jce(n,m);return D2(e,y)}const s=r.map(m=>m.length);for(;s.length>2&&s[s.length-1]===1;)s.pop();const o=s.reduce((m,y)=>m*y,1),a=D(o),l=e.imag?D(o):void 0,c=r.length,u=new Array(c);u[0]=1;for(let m=1;m<c;m++)u[m]=u[m-1]*(m-1<n.length?n[m-1]:1);const h=r.map((m,y)=>m.map(_=>_*u[y])),f=new Array(c).fill(0);let d=0;for(let m=0;m<c;m++)d+=h[m][0];for(let m=0;m<o;m++){a[m]=e.data[d],l&&e.imag&&(l[m]=e.imag[d]);for(let y=0;y<c;y++){const _=f[y];if(f[y]++,f[y]<r[y].length){d+=h[y][f[y]]-h[y][_];break}d-=h[y][_]-h[y][0],f[y]=0}}const p=A.tensor(a,s,l);return e._isLogical===!0&&(p._isLogical=!0),p}function Rde(e,t){if(t.length===1)return Dde(e,t[0]);if(t.length===2)return Nde(e,t[0],t[1]);throw new q("Cell indexing supports 1 or 2 dimensions")}function Dde(e,t){if(Ni(t))return A.cell([...e.data],[...e.shape]);if(ce(t)){const r=[];if(t._isLogical){for(let s=0;s<t.data.length;s++)if(t.data[s]!==0){if(s>=e.data.length)throw new q("Cell index exceeds bounds");r.push(e.data[s])}}else for(let s=0;s<t.data.length;s++){const o=Math.round(t.data[s])-1;if(o<0||o>=e.data.length)throw new q("Cell index exceeds bounds");r.push(e.data[o])}const i=t.shape.length<=2&&(t.shape[0]===1||t.shape.length===2&&t.shape[1]===1);return t._isLogical||i?e.shape[1]===1&&e.shape[0]>1?A.cell(r,[r.length,1]):A.cell(r,[1,r.length]):A.cell(r,[...t.shape])}const n=Math.round(Ne(t))-1;if(n<0||n>=e.data.length)throw new q("Cell index exceeds bounds");return A.cell([e.data[n]],[1,1])}function Nde(e,t,n){const r=e.shape[0],i=e.shape.length>=2?e.shape[1]:1,{rowIndices:s,colIndices:o}=wde(t,n,r,i);if(!Ni(t)&&!Ni(n)&&!ce(t)&&!ce(n)){const l=o[0]*r+s[0];if(l<0||l>=e.data.length)throw new q("Cell index exceeds bounds");return A.cell([e.data[l]],[1,1])}const a=[];for(let l=0;l<o.length;l++)for(let c=0;c<s.length;c++){const u=o[l]*r+s[c];if(u<0||u>=e.data.length)throw new q("Cell index exceeds bounds");a.push(e.data[u])}return A.cell(a,[s.length,o.length])}function Lde(e,t){const n=e.shape??(e.value.length===0?[0,0]:[1,e.value.length]),r=n[0],i=n[1]||0;if(t.length===1){const s=t[0];if(Ni(s))return e;if(ce(s)&&s._isLogical){let a="";for(let l=0;l<s.data.length;l++)if(s.data[l]!==0){if(l>=e.value.length)throw new q("Index exceeds char array length");a+=e.value[l]}return A.char(a)}if(ce(s)){let a="";for(let l=0;l<s.data.length;l++){const c=Math.round(s.data[l])-1;if(c<0||c>=e.value.length)throw new q("Index exceeds char array length");a+=e.value[c]}return A.char(a)}const o=Math.round(Ne(s))-1;if(o<0||o>=e.value.length)throw new q("Index exceeds char array length");return A.char(e.value[o])}if(t.length===2){const s=t[0],o=t[1],a=h=>{if(ce(h)&&h._isLogical){const f=[];for(let d=0;d<h.data.length;d++)h.data[d]!==0&&f.push(d);return f}return ce(h)?Array.from(h.data,f=>Math.round(f)-1):[Math.round(Ne(h))-1]},l=Ni(s)?Array.from({length:r},(h,f)=>f):a(s),c=Ni(o)?Array.from({length:i},(h,f)=>f):a(o);let u="";for(const h of l)for(const f of c){if(h<0||h>=r||f<0||f>=i)throw new q("Index exceeds char array dimensions");u+=e.value[h*i+f]}return l.length<=1?A.char(u):new Sf(u,[l.length,c.length])}throw new q("Char indexing supports 1 or 2 dimensions")}function im(e,t){if(Ni(e))return Array.from({length:t},(n,r)=>r);if(ce(e)){if(e._isLogical){const n=[];for(let r=0;r<e.data.length;r++)e.data[r]!==0&&n.push(r);return n}return Array.from(e.data,n=>Math.round(n)-1)}return Tt(e)?e?[0]:[]:[Math.round(Ne(e))-1]}function Ide(e,t){const[n,r]=e.shape,i=e.data.length;if(t.length===2){const c=im(t[0],n),u=im(t[1],r),h=[];for(const f of u){if(f<0||f>=r)throw new q("Index exceeds array bounds");for(const d of c){if(d<0||d>=n)throw new q("Index exceeds array bounds");h.push(e.data[f*n+d])}}return hs(h,[c.length,u.length])}if(t.length!==1)throw new q("String array indexing supports 1 or 2 subscripts");const s=t[0];if(Ni(s))return hs(e.data.slice(),[i,1]);const o=im(s,i),a=[];for(const c of o){if(c<0||c>=i)throw new q("Index exceeds array bounds");a.push(e.data[c])}let l;if(n===1||r===1)l=n===1?[1,a.length]:[a.length,1];else if(ce(s)&&!s._isLogical){const c=s.shape,u=c.length>=2?c[0]:1;l=[u,a.length/(u||1)]}else ce(s)&&s._isLogical?l=[a.length,1]:l=[1,a.length];return hs(a,l)}function Pde(e,t){if(t.length===1){const l=t[0];if(Ni(l))return e;if(ce(l)&&l.data.length===0)return A.tensor(D(0),[0,0]);if(ce(l)){for(let f=0;f<l.data.length;f++)if(Math.round(l.data[f])!==1)throw new q("Index exceeds array bounds");const u=D(l.data.length);u.fill(e?1:0);const h=A.tensor(u,[...l.shape]);return h._isLogical=!0,h}if(Tt(l))return l?e:A.tensor(D(0),[0,0]);if(Math.round(Ne(l))!==1)throw new q("Index exceeds array bounds");return e}const n=[];let r=!1;for(const l of t)if(Ni(l))n.push(1);else if(Tt(l)){if(!l)return A.tensor(D(0),[0,0]);n.push(1)}else if(ce(l)){r=!0;for(let c=0;c<l.data.length;c++)if(Math.round(l.data[c])!==1)throw new q("Index exceeds array bounds");n.push(l.data.length)}else{if(Math.round(Ne(l))!==1)throw new q("Index exceeds array bounds");n.push(1)}if(!r)return e;const i=n.reduce((l,c)=>l*c,1),s=D(i);s.fill(e?1:0);const o=n.length>=2?n:[n[0],1],a=A.tensor(s,o);return a._isLogical=!0,a}function Bde(e,t){const n=e._isLogical===!0;if(t._isLogical){const f=[],d=[],p=e.imag!==void 0;for(let x=0;x<t.data.length;x++)if(t.data[x]!==0){if(x>=e.data.length)throw new q("Index exceeds array bounds");f.push(e.data[x]),p&&d.push(e.imag[x])}if(f.length===1)return p&&d[0]!==0?A.complex(f[0],d[0]):n?f[0]!==0:A.num(f[0]);const m=p&&d.some(x=>x!==0)?D(d):void 0,_=e.shape.length===2&&e.shape[0]===1?[1,f.length]:[f.length,1],b=A.tensor(D(f),_,m);return n&&(b._isLogical=!0),b}const r=[],i=e.imag!==void 0,s=[];for(let f=0;f<t.data.length;f++){const d=Math.round(t.data[f])-1;if(d<0||d>=e.data.length)throw new q("Index exceeds array bounds");r.push(e.data[d]),i&&s.push(e.imag[d])}const o=t.data.length===0&&t.shape.length===2&&t.shape[0]===0&&t.shape[1]===0,a=e.shape.length<=2&&(e.shape[0]===1||e.shape[1]===1||e.shape.length===1),l=t.shape.length<=2&&(t.shape[0]===1||t.shape[1]===1||t.shape.length===1),c=o?[0,0]:a&&l?e.shape[0]===1?[1,r.length]:[r.length,1]:t.shape,u=i&&s.some(f=>f!==0)?D(s):void 0,h=A.tensor(D(r),c,u);return n&&(h._isLogical=!0),h}function rV(e,t){if(Re(e)||Ht(e))return Ade(e,t);if(ce(e))return Tde(e,t);if(nn(e))return Rde(e,t);if(lt(e))return Lde(e,t);if(mt(e)&&t.length===1){if(Math.round(Ne(t[0]))!==1)throw new q("Index exceeds string dimensions");return e}if(Wn(e))return Ide(e,t);if(Tt(e))return Pde(e,t);if(Zn(e)||In(e)){if(t.length>=1&&t.every(r=>Re(r)?Math.round(r)===1:Tt(r)?r===!0:ce(r)?r.data.length===1&&Math.round(r.data[0])===1:!1))return e;throw new q("Index exceeds struct dimensions")}if(Dt(e))return Cde(e,t);if(yi(e)){if(t.length===1){const n=t[0];if(Re(n)){const r=Math.round(n)-1;if(r<0||r>=e.elements.length)throw new q("Index exceeds struct array bounds");return e.elements[r]}if(ce(n)){const r=[];for(let i=0;i<n.data.length;i++){const s=Math.round(n.data[i])-1;if(s<0||s>=e.elements.length)throw new q("Index exceeds struct array bounds");r.push(e.elements[s])}return A.structArray(e.fieldNames,r)}if(Tt(n)){const r=n?0:-1;if(r<0||r>=e.elements.length)throw new q("Index exceeds struct array bounds");return e.elements[r]}throw new q("Invalid index type for struct array")}throw new q("Struct array only supports single-index access")}throw new q(`Cannot index into ${po(e)}`)}function Fde(e,t,n,r){if(ce(n)&&n.data.length===0&&t.length===1)return zde(e,t[0]);if(ce(n)&&n.data.length===0&&t.length===2){const i=e.shape[0]??1,s=e.shape.length>=2?e.shape[1]:1,o=Ni(t[0])?i:Ao(t[0],i).length,a=Ni(t[1])?s:Ao(t[1],s).length;return o===0||a===0?e:Ude(e,t)}if(_2(e)){const i=e.imag?D(e.imag):void 0,s=A.tensor(D(e.data),[...e.shape],i);s._isLogical=e._isLogical,e=s}if(t.length===1)return Ode(e,t[0],n);if(t.length===2)return Hde(e,t,n);if(t.length>=3)return Wde(e,t,n);throw new q("Invalid number of indices for tensor assignment")}function zde(e,t){const n=new Set;if(Re(t))n.add(Math.round(t)-1);else if(Tt(t))t&&n.add(0);else if(ce(t)&&t._isLogical)for(let u=0;u<t.data.length;u++)t.data[u]!==0&&n.add(u);else if(ce(t))for(let u=0;u<t.data.length;u++)n.add(Math.round(t.data[u])-1);else if(Ni(t)){const u=A.tensor(D(0),[0,0]);return u._isLogical=e._isLogical,u}if(n.size===0)return e;const r=[],i=[],s=e.imag!==void 0;for(let u=0;u<e.data.length;u++)n.has(u)||(r.push(e.data[u]),s&&i.push(e.imag[u]));const a=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]!==1?[r.length,1]:[1,r.length],l=s&&i.some(u=>u!==0)?D(i):void 0,c=A.tensor(D(r),a,l);return c._isLogical=e._isLogical,c}function lz(e,t){const n=new Set;if(Re(e))n.add(Math.round(e)-1);else if(Tt(e))e&&n.add(0);else if(ce(e)&&e._isLogical)for(let r=0;r<e.data.length;r++)e.data[r]!==0&&n.add(r);else if(ce(e))for(let r=0;r<e.data.length;r++)n.add(Math.round(e.data[r])-1);else if(Ni(e))for(let r=0;r<t;r++)n.add(r);return n}function Ude(e,t){const n=e.shape[0]??1,r=e.shape.length>=2?e.shape[1]:1,i=e.imag!==void 0;if(Ni(t[1])){const s=lz(t[0],n),o=Array.from({length:n},(h,f)=>f).filter(h=>!s.has(h)),a=o.length,l=D(a*r),c=i?D(a*r):void 0;for(let h=0;h<r;h++)for(let f=0;f<o.length;f++){const d=o[f]+h*n,p=f+h*a;l[p]=e.data[d],c&&e.imag&&(c[p]=e.imag[d])}const u=A.tensor(l,[a,r],c);return u._isLogical=e._isLogical,u}if(Ni(t[0])){const s=lz(t[1],r),o=Array.from({length:r},(h,f)=>f).filter(h=>!s.has(h)),a=o.length,l=D(n*a),c=i?D(n*a):void 0;for(let h=0;h<o.length;h++){const f=o[h];for(let d=0;d<n;d++){const p=d+f*n,m=d+h*n;l[m]=e.data[p],c&&e.imag&&(c[m]=e.imag[p])}}const u=A.tensor(l,[n,a],c);return u._isLogical=e._isLogical,u}throw new q("Cannot delete from both row and column dimensions")}function Ode(e,t,n){if(Ni(t)){if(ce(n))if(n.data.length===1)n=n.imag&&n.imag[0]!==0?A.complex(n.data[0],n.imag[0]):A.num(n.data[0]);else{if(n.data.length!==e.data.length)throw new q("Subscripted assignment dimension mismatch");return e.data.set(n.data),(n.imag||e.imag)&&(jo(e),n.imag?e.imag.set(n.imag):e.imag.fill(0)),e}const{re:o,im:a}=zu(n);return e.data.fill(o),(a!==0||e.imag)&&(jo(e),e.imag.fill(a)),e}if(ce(t))return jde(e,t,n);if(Tt(t)){if(!t)return e;const{re:o,im:a}=zu(n);if(e.data.length<1)throw new q("Index exceeds array bounds");return e.data[0]=o,(a!==0||e.imag)&&(jo(e),e.imag[0]=a),e}const{re:r,im:i}=zu(n),s=Math.round(Ne(t))-1;if(s<0)throw new q("Index exceeds array bounds");if(s>=e.data.length){const o=D(s+1);o.set(e.data),o[s]=r;let a;(i!==0||e.imag)&&(a=D(s+1),e.imag&&a.set(e.imag),a[s]=i);const l=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]>1;return A.tensor(o,l?[s+1,1]:[1,s+1],a)}return e.data[s]=r,(i!==0||e.imag)&&(jo(e),e.imag[s]=i),e}function jde(e,t,n){if(t._isLogical){ce(n)&&n.data.length===1&&(n=n.imag&&n.imag[0]!==0?A.complex(n.data[0],n.imag[0]):A.num(n.data[0]));const{re:o,im:a}=ce(n)?{re:null,im:null}:zu(n);let l=-1;for(let u=0;u<t.data.length;u++)t.data[u]!==0&&(l=u);if(l>=e.data.length){const u=l+1,h=D(u);h.set(e.data);let f;e.imag&&(f=D(u),f.set(e.imag));const p=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]>1?[u,1]:[1,u];e=A.tensor(h,p,f)}let c=0;for(let u=0;u<t.data.length;u++)t.data[u]!==0&&(ce(n)?(e.data[u]=n.data[c],(n.imag||e.imag)&&(jo(e),e.imag[u]=n.imag?n.imag[c]:0)):(e.data[u]=o,(a!==0||e.imag)&&(jo(e),e.imag[u]=a)),c++);if(ce(n)&&c!==n.data.length)throw new q("Subscripted assignment dimension mismatch");return e}let r=-1;for(let o=0;o<t.data.length;o++){const a=Math.round(t.data[o])-1;if(a<0)throw new q("Index exceeds array bounds");a>r&&(r=a)}if(r>=e.data.length){const o=r+1,a=D(o);a.set(e.data);let l;e.imag&&(l=D(o),l.set(e.imag));const u=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]>1?[o,1]:[1,o];e=A.tensor(a,u,l)}if(ce(n)){if(t.data.length!==n.data.length)throw new q("Subscripted assignment dimension mismatch");(n.imag||e.imag)&&jo(e);for(let o=0;o<t.data.length;o++){const a=Math.round(t.data[o])-1;e.data[a]=n.data[o],e.imag&&(e.imag[a]=n.imag?n.imag[o]:0)}return e}const{re:i,im:s}=zu(n);(s!==0||e.imag)&&jo(e);for(let o=0;o<t.data.length;o++){const a=Math.round(t.data[o])-1;e.data[a]=i,e.imag&&(e.imag[a]=s)}return e}function Hde(e,t,n){const[r,i]=Bn(e),s=Ni(t[0]),o=Ni(t[1]),a=ce(t[0]),l=ce(t[1]);if(s&&o){if(ce(n)){if(n.data.length!==e.data.length)throw new q("Subscripted assignment dimension mismatch");return e.data.set(n.data),(n.imag||e.imag)&&(jo(e),n.imag?e.imag.set(n.imag):e.imag.fill(0)),e}const{re:m,im:y}=zu(n);return e.data.fill(m),(y!==0||e.imag)&&(jo(e),e.imag.fill(y)),e}if(s&&!o&&!l)return $de(e,t[1],n,r,i);if(!s&&!a&&o)return Vde(e,t[0],n,r,i);if(a||l){const m=e.data.length===0;let y=i,_=r;if(m&&ce(n)){const[T,k]=Bn(n);s&&!o&&(_=T),o&&!s&&(y=k)}const b=s?Array.from({length:_},(T,k)=>k):Ao(t[0],r,0),x=o?Array.from({length:y},(T,k)=>k):Ao(t[1],i,0),S=b.length>0?Math.max(...b)+1:_,M=x.length>0?Math.max(...x)+1:y;e=N2(e,S,M);const[E]=Bn(e);return Sde(e,b,x,n,E),e}if(Tt(t[0])&&!t[0]||Tt(t[1])&&!t[1])return e;const{re:c,im:u}=zu(n),h=Tt(t[0])?0:Math.round(Ne(t[0]))-1,f=Tt(t[1])?0:Math.round(Ne(t[1]))-1;if(h<0||f<0)throw new q("Index exceeds array bounds");e=N2(e,h+1,f+1);const[d]=Bn(e),p=gn(h,f,d);return e.data[p]=c,(u!==0||e.imag)&&(jo(e),e.imag[p]=u),e}function L2(e,t,n){if(ce(n)){if(n.data.length!==t.length)throw new q("Subscripted assignment dimension mismatch");(n.imag||e.imag)&&jo(e);for(let r=0;r<t.length;r++)e.data[t[r]]=n.data[r],e.imag&&(e.imag[t[r]]=n.imag?n.imag[r]:0)}else{const{re:r,im:i}=zu(n);(i!==0||e.imag)&&jo(e);for(const s of t)e.data[s]=r,e.imag&&(e.imag[s]=i)}}function $de(e,t,n,r,i){if(Tt(t)){if(!t)return e;const u=Array.from({length:r},(h,f)=>gn(f,0,r));return L2(e,u,n),e}const s=Math.round(Ne(t))-1;if(s<0)throw new q("Index exceeds array bounds");let o=r,a=i;if(o===0&&ce(n)&&n.data.length>0){o=n.data.length;const u=s+1;e=A.tensor(D(o*u),[o,u]),a=u}else if(o===0&&(Re(n)||Tt(n))){o=1;const u=s+1;e=A.tensor(D(o*u),[o,u]),a=u}s>=a&&(e=N2(e,o,s+1));const[l]=Bn(e),c=Array.from({length:l},(u,h)=>gn(h,s,l));return L2(e,c,n),e}function Vde(e,t,n,r,i){if(Tt(t)){if(!t)return e;const h=Array.from({length:i},(f,d)=>gn(0,d,r));return L2(e,h,n),e}const s=Math.round(Ne(t))-1;if(s<0)throw new q("Index exceeds array bounds");let o=r,a=i;if(a===0&&ce(n)&&n.data.length>0){a=n.data.length;const h=s+1;e=A.tensor(D(h*a),[h,a]),o=h}else if(a===0&&(Re(n)||Tt(n))){a=1;const h=s+1;e=A.tensor(D(h*a),[h,a]),o=h}s>=o&&(e=N2(e,s+1,a));const[l,c]=Bn(e),u=Array.from({length:c},(h,f)=>gn(s,f,l));return L2(e,u,n),e}function Wde(e,t,n){let r=[...e.shape];const i=ce(n)?n:null,s=i?i.shape:null;let o=0;const a=t.map((y,_)=>{const b=_<r.length?r[_]:1;if(Ni(y)){if((b===0||_>=r.length)&&s){const S=o<s.length?s[o]:1;return o++,Array.from({length:S},(M,E)=>E)}return o++,Array.from({length:b},(S,M)=>M)}return Ao(y,b,0)}),l=[...r];for(;l.length<t.length;)l.push(1);let c=!1;for(let y=0;y<a.length;y++)for(const _ of a[y])_>=l[y]&&(l[y]=_+1,c=!0);if(c||e.data.length===0){const y=l.reduce((x,S)=>x*S,1),_=D(y),b=e.imag?D(y):void 0;if(e.data.length>0){const x=[...r];for(;x.length<l.length;)x.push(1);const S=e.data.length,M=x.length,E=new Array(M);E[0]=1;for(let R=1;R<M;R++)E[R]=E[R-1]*l[R-1];const T=new Array(M).fill(0);let k=0;for(let R=0;R<S;R++){_[k]=e.data[R],b&&e.imag&&(b[k]=e.imag[R]);for(let B=0;B<M&&(T[B]++,k+=E[B],!(T[B]<x[B]));B++)k-=T[B]*E[B],T[B]=0}}for(;l.length>2&&l[l.length-1]===1;)l.pop();e=A.tensor(_,l,b),r=l}const h=a.map(y=>y.length).reduce((y,_)=>y*_,1),f=a.length,d=new Array(f);d[0]=1;for(let y=1;y<f;y++)d[y]=d[y-1]*(y-1<r.length?r[y-1]:1);const p=a.map((y,_)=>y.map(b=>b*d[_])),m=y=>{const _=new Array(f).fill(0);let b=0;for(let x=0;x<f;x++)b+=p[x][0];for(let x=0;x<h;x++){y(b,x);for(let S=0;S<f;S++){const M=_[S];if(_[S]++,_[S]<a[S].length){b+=p[S][_[S]]-p[S][M];break}b-=p[S][M]-p[S][0],_[S]=0}}};if(ce(n)){if(n.data.length!==h)throw new q("Subscripted assignment dimension mismatch");const y=n.imag!==void 0;(y||e.imag)&&jo(e),m((_,b)=>{e.data[_]=n.data[b],e.imag&&(e.imag[_]=y?n.imag[b]:0)})}else{const{re:y,im:_}=zu(n);(_!==0||e.imag)&&jo(e),m(b=>{e.data[b]=y,e.imag&&(e.imag[b]=_)})}return e}function qde(e,t,n,r=!1,i){_2(e)&&(e=A.cell(e.data.slice(),[...e.shape]));const s=o=>{const a=e,l=a.data.length;if(l===o)return;const c=a.shape[0]>1&&a.shape[1]===1;a.shape=c?[l,1]:[1,l]};if(t.length===1)return Gde(e,t[0],n,s,r,i);if(t.length===2)return Xde(e,t,n,r,i);throw new q("Cannot index-assign into cell")}function ET(e,t){const n=A.tensor(D(0),[0,0]);t&&n.incref(),e.data.push(n)}function Xp(e,t,n,r){r?e.bindElement(r,t,n):e.data[t]=n}function Gde(e,t,n,r,i=!1,s){if(Ni(t)){const c=e.data.length;if(c===1&&!nn(n))return Xp(e,0,n,s),e;if(!nn(n)||n.data.length!==c&&n.data.length!==1)throw new q("Subscripted assignment dimension mismatch");const u=n.data.length===1;for(let h=0;h<c;h++)Xp(e,h,u?n.data[0]:n.data[h],s);return e}if(ce(t)){let c;if(t._isLogical){c=[];for(let d=0;d<t.data.length;d++)t.data[d]!==0&&c.push(d)}else c=Array.from(t.data).map(d=>Math.round(d)-1);if(c.length===1&&!nn(n)){const d=c[0];if(d<0)throw new q("Cell index exceeds bounds");const p=e.data.length;for(;e.data.length<=d;)ET(e,s);return Xp(e,d,n,s),r(p),e}if(!nn(n)||n.data.length!==c.length&&n.data.length!==1)throw new q("Subscripted assignment dimension mismatch");const u=n.data.length===1,h=e.data.length;let f=-1;for(let d=0;d<c.length;d++){const p=c[d];if(p<0)throw new q("Cell index exceeds bounds");p>f&&(f=p)}for(;e.data.length<=f;)ET(e,s);for(let d=0;d<c.length;d++){const p=c[d];Xp(e,p,u?n.data[0]:n.data[d],s)}return r(h),e}const o=Math.round(Ne(t))-1;if(o<0)throw new q("Cell index exceeds bounds");const a=e.data.length;if(o>=e.data.length)for(;e.data.length<=o;)ET(e,s);const l=i&&nn(n)&&n.data.length===1?n.data[0]:n;return Xp(e,o,l,s),r(a),e}function Xde(e,t,n,r=!1,i){let s=e.shape[0],o=e.shape.length>=2?e.shape[1]:1;const a=Ao(t[0],s,0),l=Ao(t[1],o,0),c=Math.max(...a)+1,u=Math.max(...l)+1,h=Math.max(s,c),f=Math.max(o,u);if(h>s||f>o){const y=new Array(h*f);for(let _=0;_<y.length;_++){const b=A.tensor(D(0),[0,0]);i&&b.incref(),y[_]=b}for(let _=0;_<o;_++)for(let b=0;b<s;b++){const x=y[_*h+b];y[_*h+b]=e.data[_*s+b],i&&Ho(i,x)}e.data=y,e.shape=[h,f],s=h,o=f}const d=a.length,p=l.length,m=d*p;if(r&&nn(n)){if(n.data.length!==m&&n.data.length!==1)throw new q("Subscripted assignment dimension mismatch");const y=n.data.length===1;let _=0;for(let b=0;b<p;b++)for(let x=0;x<d;x++){const S=l[b]*s+a[x];Xp(e,S,y?n.data[0]:n.data[_++],i)}}else{const y=l[0]*s+a[0];Xp(e,y,n,i)}return e}function Q_(e,t,n,r=!1,i){if(Dt(e))return nV(e,t,n);if(Dt(n)&&ce(e)){const s=n,o=D(s.m*s.n),a=s.pi?D(s.m*s.n):void 0;for(let l=0;l<s.n;l++)for(let c=s.jc[l];c<s.jc[l+1];c++){const u=l*s.m+s.ir[c];o[u]=s.pr[c],a&&s.pi&&(a[u]=s.pi[c])}n=A.tensor(o,[s.m,s.n],a)}if(ce(e))return Fde(e,t,n);if(nn(e))return qde(e,t,n,r,i);throw new q(`Cannot index-assign into ${po(e)}`)}function a1(e,t,n){let r;if(t>0||t<0?r=Math.max(0,Math.floor((n-e)/t+1+1e-10)):r=0,r===0)return A.tensor(D(0),[1,0]);const i=D(r);for(let s=0;s<r;s++)i[s]=e+s*t;if(r>1){const s=e+(r-1)*t,o=Math.abs(t);Math.abs(s-n)<o*1e-10&&(i[r-1]=n)}return A.tensor(i,[1,r])}function wb(...e){if(e.length===0)return A.tensor(D(0),[0,0]);if(e.length===1)return e[0];if(e.some(t=>Dt(t)))return oV(e,1);if(e.some(t=>nn(t)))return lV(e,1);if(e.some(t=>mt(t)||Wn(t)))return iV(e,1);if(e.some(t=>lt(t))){let t="";for(const n of e)if(lt(n))t+=n.value;else if(Re(n))t+=String.fromCharCode(Math.round(n));else throw new q(`Cannot concatenate ${po(n)} into char`);return A.char(t)}return e.some(t=>Zn(t)||yi(t))?sV(e):aV(e,1)}function fI(...e){return e.length===0?A.tensor(D(0),[0,0]):e.length===1?e[0]:e.some(t=>Dt(t))?oV(e,0):e.some(t=>nn(t))?lV(e,0):e.some(t=>mt(t)||Wn(t))?iV(e,0):e.some(t=>lt(t))?Kde(e):e.some(t=>Zn(t)||yi(t))?sV(e):aV(e,0)}function Yde(e){if(mt(e))return{data:[e],rows:1,cols:1};if(Wn(e))return e.data.length===0?null:{data:e.data.slice(),rows:e.shape[0],cols:e.shape[1]};if(lt(e)){const t=e.shape?e.shape[0]:1,n=e.shape?e.shape[1]:e.value.length;if(t<=1)return{data:[e.value],rows:1,cols:1};const r=[];for(let i=0;i<t;i++)r.push(e.value.slice(i*n,(i+1)*n));return{data:r,rows:t,cols:1}}if(Re(e))return{data:[Tv(e)],rows:1,cols:1};if(Tt(e))return{data:[e?"true":"false"],rows:1,cols:1};if(ce(e)){if(e.data.length===0)return null;const t=e.shape.length>=2?e.shape[0]:1,n=e.data.length/(t||1),r=[];for(let i=0;i<e.data.length;i++)r.push(e._isLogical?e.data[i]?"true":"false":Tv(e.data[i]));return{data:r,rows:t,cols:n}}throw new q(`Cannot concatenate ${po(e)} into string array`)}function iV(e,t){const n=[];for(const a of e){const l=Yde(a);l&&n.push(l)}if(n.length===0)return A.stringArray([],[0,0]);if(t===1){const a=n[0].rows;let l=0;for(const u of n){if(u.rows!==a)throw new q("Dimensions of arrays being concatenated are not consistent");l+=u.cols}const c=[];for(const u of n)c.push(...u.data);return hs(c,[a,l])}const r=n[0].cols;let i=0;for(const a of n){if(a.cols!==r)throw new q("Dimensions of arrays being concatenated are not consistent");i+=a.rows}const s=new Array(i*r);let o=0;for(const a of n){for(let l=0;l<r;l++)for(let c=0;c<a.rows;c++)s[l*i+o+c]=a.data[l*a.rows+c];o+=a.rows}return hs(s,[i,r])}function Kde(e){let t=null,n=0,r="";for(const i of e){let s,o,a;if(lt(i))s=i.shape?i.shape[0]:1,o=i.shape?i.shape[1]:i.value.length,a=i.value;else if(mt(i))s=1,o=i.length,a=i;else if(Re(i))s=1,o=1,a=String.fromCharCode(Math.round(i));else if(ce(i)){const l=i,c=l.shape[0]??0,u=l.shape[1]??0;s=c,o=u;let h="";for(let f=0;f<c;f++)for(let d=0;d<u;d++)h+=String.fromCharCode(Math.round(l.data[d*c+f]));a=h}else throw new q(`Cannot concatenate ${po(i)} into char`);if(t===null)t=o;else if(o!==t)throw new q("Dimensions of arrays being concatenated are not consistent");n+=s,r+=a}return n<=1?A.char(r):new Sf(r,[n,t??0])}function sV(e){const t=[];let n=null;for(const r of e)if(Zn(r)){const i=Array.from(r.fields.keys());if(n===null)n=i;else if(!cz(n,i))throw new q("Cannot concatenate structs with different field names");t.push(r)}else if(yi(r)){if(n===null)n=[...r.fieldNames];else if(!cz(n,r.fieldNames))throw new q("Cannot concatenate struct arrays with different field names");for(const i of r.elements)t.push(i)}else{if(ce(r)&&r.data.length===0&&r.shape.every(i=>i===0))continue;throw new q(`Cannot concatenate ${po(r)} into struct`)}return n===null&&(n=[]),A.structArray(n,t)}function cz(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Zde(e){if(Dt(e))return e;if(Re(e))return e===0?A.sparseMatrix(1,1,new Int32Array(0),new Int32Array([0,0]),D(0)):A.sparseMatrix(1,1,new Int32Array([0]),new Int32Array([0,1]),D([e]));if(Tt(e)){const t=e?1:0;return t===0?A.sparseMatrix(1,1,new Int32Array(0),new Int32Array([0,0]),D(0)):A.sparseMatrix(1,1,new Int32Array([0]),new Int32Array([0,1]),D([t]))}if(Ht(e))return e.re===0&&e.im===0?A.sparseMatrix(1,1,new Int32Array(0),new Int32Array([0,0]),D(0)):A.sparseMatrix(1,1,new Int32Array([0]),new Int32Array([0,1]),D([e.re]),e.im!==0?D([e.im]):void 0);if(ce(e)){const t=e.shape[0]??1,n=e.shape.length>=2?e.shape[1]:1,r=e.imag!==void 0,i=[],s=[],o=[],a=new Int32Array(n+1);for(let l=0;l<n;l++){a[l]=i.length;for(let c=0;c<t;c++){const u=l*t+c,h=e.data[u],f=r?e.imag[u]:0;(h!==0||f!==0)&&(i.push(c),s.push(h),r&&o.push(f))}}return a[n]=i.length,A.sparseMatrix(t,n,new Int32Array(i),a,D(s),r?D(o):void 0)}throw new q(`Cannot concatenate ${po(e)} into sparse matrix`)}function oV(e,t){const n=e.map(Zde).filter(r=>r.m>0||r.n>0);if(n.length===0)return A.sparseMatrix(0,0,new Int32Array(0),new Int32Array([0]),D(0));if(n.length===1)return n[0];if(t===1){const r=n[0].m;for(let d=1;d<n.length;d++)if(n[d].m!==r&&n[d].m>0)throw new q("Dimensions of arrays being concatenated are not consistent");const i=n.reduce((d,p)=>d+p.n,0),s=n.some(d=>d.pi!==void 0),o=n.reduce((d,p)=>d+p.jc[p.n],0),a=new Int32Array(o),l=D(o),c=s?D(o):void 0,u=new Int32Array(i+1);let h=0,f=0;for(const d of n){const p=d.jc[d.n];for(let m=0;m<p;m++)a[h+m]=d.ir[m],l[h+m]=d.pr[m],c&&(c[h+m]=d.pi?d.pi[m]:0);for(let m=0;m<d.n;m++)u[f+m]=d.jc[m]+h;h+=p,f+=d.n}return u[i]=h,A.sparseMatrix(r,i,a,u,l,c)}else{const r=n[0].n;for(let f=1;f<n.length;f++)if(n[f].n!==r&&n[f].n>0)throw new q("Dimensions of arrays being concatenated are not consistent");const i=n.reduce((f,d)=>f+d.m,0),s=n.some(f=>f.pi!==void 0),o=n.reduce((f,d)=>f+d.jc[d.n],0),a=new Int32Array(o),l=D(o),c=s?D(o):void 0,u=new Int32Array(r+1);let h=0;for(let f=0;f<r;f++){u[f]=h;let d=0;for(const p of n){for(let m=p.jc[f];m<p.jc[f+1];m++)a[h]=p.ir[m]+d,l[h]=p.pr[m],c&&(c[h]=p.pi?p.pi[m]:0),h++;d+=p.m}}return u[r]=h,A.sparseMatrix(i,r,a,u,l,c)}}function aV(e,t){const n=e.every(y=>Tt(y)||ce(y)&&y._isLogical===!0);let r=e.map(y=>{if(Re(y))return A.tensor(D([y]),[1,1]);if(Tt(y)){const _=A.tensor(D([y?1:0]),[1,1]);return _._isLogical=!0,_}if(Ht(y))return A.tensor(D([y.re]),[1,1],D([y.im]));if(ce(y))return y;throw new q(`Cannot concatenate ${po(y)} into matrix`)});if(r=r.filter(y=>y.shape.some(_=>_>0)),r.length===0)return A.tensor(D(0),[0,0]);if(r.length===1)return r[0];const i=Math.max(2,...r.map(y=>y.shape.length));let s=r.map(y=>{const _=[...y.shape];for(;_.length<i;)_.push(1);return _});const o=r.findIndex(y=>y.data.length>0);if(o>=0){const y=s[o],_=r.map((b,x)=>{if(b.data.length>0)return!0;for(let S=0;S<i;S++)if(S!==t&&s[x][S]!==y[S])return!1;return!0});if(r=r.filter((b,x)=>_[x]),s=s.filter((b,x)=>_[x]),r.length===0)return A.tensor(D(0),[0,0]);if(r.length===1)return r[0]}const a=s[0];for(let y=1;y<s.length;y++)for(let _=0;_<i;_++)if(_!==t&&s[y][_]!==a[_])throw new q("Dimensions of arrays being concatenated are not consistent");const l=[...a];l[t]=s.reduce((y,_)=>y+_[t],0);const c=Zc(l),u=r.some(y=>y.imag!==void 0),h=D(c),f=u?D(c):void 0;let d=1;for(let y=0;y<t;y++)d*=l[y];let p=1;for(let y=t+1;y<i;y++)p*=l[y];for(let y=0;y<p;y++){let _=y*d*l[t];for(let b=0;b<r.length;b++){const x=s[b][t],S=d*x,M=y*S;if(h.set(r[b].data.subarray(M,M+S),_),f){const E=r[b].imag;E&&f.set(E.subarray(M,M+S),_)}_+=S}}const m=A.tensor(h,l,f);return n&&(m._isLogical=!0),m}function Qde(e){return lt(e)?e.value.length===0:ce(e)?e.data.length===0:!1}function lV(e,t){let n=[];for(const h of e)if(nn(h))n.push(h);else{if(Qde(h))continue;n.push(A.cell([h],[1,1]))}if(n=n.filter(h=>h.data.length>0),n.length===0)return A.cell([],[0,0]);if(n.length===1)return n[0];const r=Math.max(2,...n.map(h=>h.shape.length)),i=n.map(h=>{const f=[...h.shape];for(;f.length<r;)f.push(1);return f}),s=i[0];for(let h=1;h<i.length;h++)for(let f=0;f<r;f++)if(f!==t&&i[h][f]!==s[f])throw new q("Dimensions of arrays being concatenated are not consistent");const o=[...s];o[t]=i.reduce((h,f)=>h+f[t],0);const a=Zc(o),l=new Array(a);let c=1;for(let h=0;h<t;h++)c*=o[h];let u=1;for(let h=t+1;h<r;h++)u*=o[h];for(let h=0;h<u;h++){let f=h*c*o[t];for(let d=0;d<n.length;d++){const p=i[d][t],m=c*p,y=h*m;for(let _=0;_<m;_++)l[f+_]=n[d].data[y+_];f+=m}}return A.cell(l,o)}const Qu={r:[1,0,0],g:[0,1,0],b:[0,0,1],c:[0,1,1],m:[1,0,1],y:[1,1,0],k:[0,0,0],w:[1,1,1]},uz={red:[1,0,0],green:[0,1,0],blue:[0,0,1],cyan:[0,1,1],magenta:[1,0,1],yellow:[1,1,0],black:[0,0,0],white:[1,1,1]};function es(e){if(typeof e=="string"){const t=e.toLowerCase();return Qu[t]?Qu[t]:uz[t]?uz[t]:void 0}if(mt(e)||lt(e))return es(mt(e)?e:e.value);if(ce(e)&&e.data.length===3)return[e.data[0],e.data[1],e.data[2]]}const Jde=new Set(["r","g","b","c","m","y","k","w"]),epe=new Set(["o","+","*",".","x","_","|","s","d","^","v","<",">","p","h"]);function Ju(e){const t={};let n=0;for(;n<e.length;){if(n+1<e.length){const i=e.slice(n,n+2);if(i==="--"||i==="-."){if(t.lineStyle!==void 0)return null;t.lineStyle=i,n+=2;continue}}const r=e[n];if(r==="-"||r===":"){if(t.lineStyle!==void 0)return null;t.lineStyle=r,n++;continue}if(Jde.has(r)){if(t.color!==void 0)return null;t.color=r,n++;continue}if(epe.has(r)){if(t.marker!==void 0)return null;t.marker=r,n++;continue}return null}return t.color===void 0&&t.lineStyle===void 0&&t.marker===void 0?null:t}const tpe=new Set(["color","linestyle","linewidth","marker","markersize","markeredgecolor","markerfacecolor","markerindices"]);function ml(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return tpe.has(t)?t:null}function jr(e){if(typeof e=="number"||typeof e=="boolean")return!0;if(e&&typeof e=="object"&&"kind"in e){const t=e;return Re(t)||ce(t)||Tt(t)}return!1}function _i(e){if(typeof e=="string")return!0;if(e&&typeof e=="object"&&"kind"in e){const t=e;return mt(t)||lt(t)}return!1}function Hr(e){return mt(e)?e:lt(e)?e.value:Xe(e)}function vn(e){return Re(e)?[e]:ce(e)?Array.from(e.data):Tt(e)?[e?1:0]:[0]}function cV(e,t){const n=e.shape[0],r=t*n,i=new Array(n);for(let s=0;s<n;s++)i[s]=e.data[r+s];return i}function J_(e){return ce(e)&&e.shape.length>=2&&e.shape[0]>1&&e.shape[1]>1?e.shape[1]:1}function YM(e){const t=new Array(e);for(let n=0;n<e;n++)t[n]=n+1;return t}function mm(e){if(ce(e)&&e.shape.length>=2&&e.shape[0]>1&&e.shape[1]>1){const t=[];for(let n=0;n<e.shape[1];n++)t.push(cV(e,n));return t}return[vn(e)]}function tp(e){const t=[];let n=0;for(;n<e.length&&!(_i(e[n])&&ml(e[n]));){if(!jr(e[n])){if(_i(e[n])&&t.length>0&&Ju(Hr(e[n]))){n++;continue}break}const r=e[n];n++;let i;n<e.length&&jr(e[n])&&(i=e[n],n++);let s;if(n<e.length&&_i(e[n])&&!ml(e[n])){const o=Ju(Hr(e[n]));o&&(s=o,n++)}i!==void 0?rpe(r,i,s,t):npe(r,s,t)}for(;n<e.length;){const r=ml(e[n]);if(!r||(n++,n>=e.length))break;const i=e[n];n++,gI(t,r,i)}return t}function npe(e,t,n){const r=mm(e);for(const i of r){const s=YM(i.length);n.push(L_(s,i,t))}}function rpe(e,t,n,r){const i=J_(e),s=J_(t);if(i===1&&s===1)r.push(L_(vn(e),vn(t),n));else if(i===1&&s>1){const o=vn(e),a=mm(t);for(const l of a)r.push(L_(o,l,n))}else if(i>1&&s>1&&i===s){const o=mm(e),a=mm(t);for(let l=0;l<i;l++)r.push(L_(o[l],a[l],n))}else r.push(L_(vn(e),vn(t),n))}function L_(e,t,n){const r={x:e,y:t};return n&&(n.color&&(r.color=Qu[n.color]),n.lineStyle&&(r.lineStyle=n.lineStyle),n.marker&&(r.marker=n.marker,n.lineStyle||(r.lineStyle="none"))),r}function dI(e){const t=[];let n=0;for(;n<e.length&&!(_i(e[n])&&ml(e[n])||!jr(e[n])||n+1>=e.length||!jr(e[n+1])||n+2>=e.length||!jr(e[n+2]));){const r=e[n],i=e[n+1],s=e[n+2];n+=3;let o;if(n<e.length&&_i(e[n])&&!ml(e[n])){const a=Ju(Hr(e[n]));a&&(o=a,n++)}ipe(r,i,s,o,t)}for(;n<e.length;){const r=ml(e[n]);if(!r||(n++,n>=e.length))break;const i=e[n];n++,pI(t,r,i)}return t}function ipe(e,t,n,r,i){const s=J_(e),o=J_(t),a=J_(n),l=Math.max(s,o,a);if(l===1)i.push(hz(vn(e),vn(t),vn(n),r));else{const c=mm(e),u=mm(t),h=mm(n);for(let f=0;f<l;f++)i.push(hz(c[Math.min(f,c.length-1)],u[Math.min(f,u.length-1)],h[Math.min(f,h.length-1)],r))}}function hz(e,t,n,r){const i={x:e,y:t,z:n};return r&&(r.color&&(i.color=Qu[r.color]),r.lineStyle&&(i.lineStyle=r.lineStyle),r.marker&&(i.marker=r.marker,r.lineStyle||(i.lineStyle="none"))),i}function pI(e,t,n){switch(t){case"color":{const r=es(n);if(r)for(const i of e)i.color=r;break}case"linestyle":{const r=Hr(n);for(const i of e)i.lineStyle=r;break}case"linewidth":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.lineWidth=r;break}case"marker":{const r=Hr(n);for(const i of e)i.marker=r==="none"?void 0:r;break}case"markersize":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.markerSize=r;break}case"markeredgecolor":{const r=es(n);if(r)for(const i of e)i.markerEdgeColor=r;break}case"markerfacecolor":{const r=es(n);if(r)for(const i of e)i.markerFaceColor=r;break}case"markerindices":{const r=vn(n);for(const i of e)i.markerIndices=r;break}}}function KM(e){return!!e&&typeof e=="object"&&"kind"in e&&(e.kind==="graphics_handle"||e.kind==="dummy_handle")}function spe(e){let t=e;if(t.length>0&&KM(t[0])&&(t=t.slice(1)),t.length===0)return{kind:"2d",traces:[{x:[0,1],y:[0,1]}]};if(_i(t[0]))return ope(t);let n=0;for(let r=0;r<t.length&&jr(t[r]);r++)n++;return n>=3?{kind:"3d",traces:dI(t)}:{kind:"2d",traces:tp(t)}}function ope(e){let t,n,r;const i=[];let s=0;for(;s+1<e.length&&_i(e[s]);){const a=Hr(e[s]).toLowerCase(),l=e[s+1];a==="xdata"?t=vn(l):a==="ydata"?n=vn(l):a==="zdata"?r=vn(l):i.push(e[s],l),s+=2}if(t||(t=[0,1]),n||(n=[0,1]),r){const a={x:t,y:n,z:r,color:[0,0,0]};for(let l=0;l+1<i.length;l+=2){const c=ml(i[l]);c&&pI([a],c,i[l+1])}return{kind:"3d",traces:[a]}}const o={x:t,y:n,color:[0,0,0]};for(let a=0;a+1<i.length;a+=2){const l=ml(i[a]);l&&gI([o],l,i[a+1])}return{kind:"2d",traces:[o]}}function I2(e){if(_i(e)){const t=Hr(e).toLowerCase().replace(/^["']|["']$/g,"");return t==="flat"||t==="interp"||t==="none"?t:t==="auto"?void 0:es(t)}return es(e)}function P2(e){if(ce(e)&&e.shape.length>=2&&e.shape[1]===3){const t=e.shape[0],n=[];for(let r=0;r<t;r++)n.push([e.data[r],e.data[t+r],e.data[2*t+r]]);return n}return vn(e)}const AR=new Set(["facecolor","edgecolor","facealpha","linewidth","linestyle","marker","markerfacecolor","facevertexcdata","cdata","xdata","ydata","zdata","faces","vertices"]);function ev(e,t,n){const r=zr(e),i=zr(t),s=n?zr(n):void 0;let o=r.rows,a=r.cols;(o===1||a===1)&&(o=r.data.length,a=1);const l=[],c=[];for(let u=0;u<a;u++){const h=[];for(let f=0;f<o;f++){const d=u*o+f,p=r.data[d],m=i.data[Math.min(d,i.data.length-1)],y=s?[p,m,s.data[Math.min(d,s.data.length-1)]]:[p,m];h.push(l.length),l.push(y)}c.push(h)}return{vertices:l,faces:c,rows:o,cols:a}}function uV(e,t,n,r){if(_i(t)){const o=I2(t);o&&(e.faceColor=o);return}const i=zr(t),s=i.data.length;s===1?(e.faceColor="flat",e.faceVertexCData=new Array(n).fill(i.data[0])):i.rows===1&&i.cols===3?e.faceColor=[i.data[0],i.data[1],i.data[2]]:s===r&&r!==n?(e.faceColor="interp",e.faceVertexCData=P2(t)):(e.faceColor="flat",e.faceVertexCData=P2(t))}function B2(e,t,n){for(let r=n;r+1<t.length&&_i(t[r]);r+=2){const i=Hr(t[r]).toLowerCase(),s=t[r+1];ZM(e,i,s)}}function ZM(e,t,n){switch(t){case"facecolor":{const r=I2(n);r&&(e.faceColor=r);break}case"edgecolor":{const r=I2(n);r&&(e.edgeColor=r);break}case"facealpha":e.faceAlpha=Ne(n);break;case"linewidth":e.lineWidth=Ne(n);break;case"linestyle":e.lineStyle=Hr(n);break;case"marker":e.marker=Hr(n);break;case"markerfacecolor":{const r=_i(n)?Hr(n).toLowerCase():"";if(r==="flat"||r==="none")e.markerFaceColor=r;else{const i=es(n);i&&(e.markerFaceColor=i)}break}case"facevertexcdata":case"cdata":e.faceVertexCData=P2(n);break}}function hV(e,t){const n=zr(t),r=n.rows,s=n.cols>=3,o=[];for(let c=0;c<r;c++){const u=n.data[c],h=n.data[r+c];o.push(s?[u,h,n.data[2*r+c]]:[u,h])}const a=zr(e),l=[];for(let c=0;c<a.rows;c++){const u=[];for(let h=0;h<a.cols;h++){const f=a.data[h*a.rows+c];Number.isFinite(f)&&u.push(f-1)}u.length>0&&l.push(u)}return{vertices:o,faces:l,is3D:s}}function ape(e){const t=a=>{for(const[l,c]of e.fields)if(l.toLowerCase()===a)return c},n={vertices:[],faces:[]},r=t("faces"),i=t("vertices"),s=t("xdata"),o=t("ydata");if(r&&i){const a=hV(r,i);n.vertices=a.vertices,n.faces=a.faces,n.is3D=a.is3D}else if(s&&o){const a=t("zdata"),l=ev(s,o,a);n.vertices=l.vertices,n.faces=l.faces,n.is3D=!!a}for(const[a,l]of e.fields){const c=a.toLowerCase();c==="faces"||c==="vertices"||c==="xdata"||c==="ydata"||c==="zdata"||ZM(n,c,l)}return n}function lpe(e){let t=e;if(t.length>0&&KM(t[0])&&(t=t.slice(1)),t.length===0)throw new Error("patch requires input arguments");if(t.length===1&&Zn(t[0]))return BS(ape(t[0]));const n={vertices:[],faces:[]};if(_i(t[0])){const l={};for(let c=0;c+1<t.length&&_i(t[c]);c+=2)l[Hr(t[c]).toLowerCase()]=t[c+1];if(l.faces&&l.vertices){const c=hV(l.faces,l.vertices);n.vertices=c.vertices,n.faces=c.faces,n.is3D=c.is3D}else if(l.xdata&&l.ydata){const c=ev(l.xdata,l.ydata,l.zdata);n.vertices=c.vertices,n.faces=c.faces,n.is3D=!!l.zdata}for(const[c,u]of Object.entries(l))c==="faces"||c==="vertices"||c==="xdata"||c==="ydata"||c==="zdata"||ZM(n,c,u);return BS(n)}let r=0;for(let l=0;l<t.length&&jr(t[l]);l++)r++;if(r<2)throw new Error("patch: expected X and Y coordinates");let i=!1;if(r>=4)i=!0;else if(r===3&&t[3]!==void 0&&_i(t[3])){const l=Hr(t[3]).toLowerCase();!AR.has(l)&&I2(t[3])&&(i=!0)}let s,o;const a=i?ev(t[0],t[1],t[2]):ev(t[0],t[1],void 0);return n.vertices=a.vertices,n.faces=a.faces,n.is3D=i,i?(o=t[3],s=4):t.length>2&&!(_i(t[2])&&AR.has(Hr(t[2]).toLowerCase()))?(o=t[2],s=3):s=2,o!==void 0&&uV(n,o,a.faces.length,a.vertices.length),B2(n,t,s),BS(n)}function BS(e){return e.faceColor===void 0&&(e.faceColor=e.faceVertexCData?"flat":[0,.447,.741]),e.edgeColor===void 0&&(e.edgeColor=[0,0,0]),e}function cpe(e){let t=e;t.length>0&&KM(t[0])&&(t=t.slice(1));const n=[];let r=0;for(;r+1<t.length&&jr(t[r])&&jr(t[r+1]);){const i=ev(t[r],t[r+1],void 0),s={vertices:i.vertices,faces:i.faces,is3D:!1},o=t[r+2],a=o!==void 0&&_i(o)&&AR.has(Hr(o).toLowerCase());o!==void 0&&!a?(uV(s,o,i.faces.length,i.vertices.length),r+=3):r+=2,n.push(s)}for(const i of n)B2(i,t,r);return n.map(BS)}function fz(e){const t=zr(e),n=[];for(let r=0;r<t.rows;r++){const i=[];for(let s=0;s<t.cols;s++){const o=t.data[s*t.rows+r];Number.isFinite(o)&&i.push(o-1)}i.length>0&&n.push(i)}return n}function dz(e){return e.faceColor===void 0&&(e.faceColor=[.85,.85,.85]),e.edgeColor===void 0&&(e.edgeColor=[0,0,0]),e}function upe(e){let t=e;if(t.length>0&&KM(t[0])&&(t=t.slice(1)),t.length===0)throw new Error("trimesh requires input arguments");if(Zn(t[0])){const h=t[0],f=S=>{for(const[M,E]of h.fields)if(M.toLowerCase()===S)return E},d=f("connectivitylist"),p=f("points");if(!d||!p)throw new Error("trimesh: triangulation object must have ConnectivityList and Points fields");const m=zr(p),y=m.rows,_=m.cols>=3,b=[];for(let S=0;S<y;S++){const M=m.data[S],E=m.data[y+S];b.push(_?[M,E,m.data[2*y+S]]:[M,E])}const x={vertices:b,faces:fz(d),is3D:_};return B2(x,t,1),dz(x)}if(t.length<3)throw new Error("trimesh: expected T, x and y");let n=3,r,i;t.length>3&&jr(t[3])&&(r=t[3],n=4,t.length>4&&jr(t[4])&&(i=t[4],n=5));const s=zr(t[1]),o=zr(t[2]),a=r?zr(r):void 0,l=s.data.length,c=[];for(let h=0;h<l;h++){const f=s.data[h],d=o.data[Math.min(h,o.data.length-1)];a?c.push([f,d,a.data[Math.min(h,a.data.length-1)]]):c.push([f,d])}const u={vertices:c,faces:fz(t[0]),is3D:!!a};return i&&(u.faceVertexCData=P2(i)),B2(u,t,n),dz(u)}const hpe=new Set(["edgecolor","facecolor","facealpha"]);function fpe(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return hpe.has(t)?t:null}function mI(e){let t=0,n,r,i,s,o,a,l=0;for(let u=t;u<e.length&&jr(e[u]);u++)l++;if(l===1){const u=e[t++],h=zr(u);s=h.rows,o=h.cols,i=h.data;const f=Em(s,o);n=f.x,r=f.y}else if(l===2){const u=e[t++],h=e[t++],f=zr(u);s=f.rows,o=f.cols,i=f.data,a=vn(h);const d=Em(s,o);n=d.x,r=d.y}else if(l===3){const u=e[t++],h=e[t++],f=e[t++],d=zr(f);s=d.rows,o=d.cols,i=d.data;const p=Cm(u,h,s,o);n=p.x,r=p.y}else if(l>=4){const u=e[t++],h=e[t++],f=e[t++],d=e[t++],p=zr(f);s=p.rows,o=p.cols,i=p.data,a=vn(d);const m=Cm(u,h,s,o);n=m.x,r=m.y}else throw new Error("surf requires at least one input argument");const c={x:n,y:r,z:i,rows:s,cols:o};for(a&&(c.c=a);t<e.length;){const u=fpe(e[t]);if(!u||(t++,t>=e.length))break;const h=e[t++];ype(c,u,h)}return c}function zr(e){if(ce(e)&&e.shape.length>=2)return{data:Array.from(e.data),rows:e.shape[0],cols:e.shape[1]};if(Re(e))return{data:[e],rows:1,cols:1};const t=vn(e);return{data:t,rows:t.length,cols:1}}function Em(e,t){const n=e*t,r=new Array(n),i=new Array(n);for(let s=0;s<t;s++)for(let o=0;o<e;o++){const a=s*e+o;r[a]=s+1,i[a]=o+1}return{x:r,y:i}}function Cm(e,t,n,r){const i=vn(e),s=vn(t),o=n*r;if(i.length===o&&s.length===o)return{x:i,y:s};const a=i.length===r?i:i.slice(0,r),l=s.length===n?s:s.slice(0,n),c=new Array(o),u=new Array(o);for(let h=0;h<r;h++)for(let f=0;f<n;f++){const d=h*n+f;c[d]=a[h],u[d]=l[f]}return{x:c,y:u}}const dpe=new Set(["edgecolor","facealpha"]);function ppe(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return dpe.has(t)?t:null}function mpe(e,t,n){switch(t){case"edgecolor":{const r=TR(n);if(r!==void 0&&r.toLowerCase()==="none"){e.edgeColor="none";break}const i=es(n);i&&(e.edgeColor=i);break}case"facealpha":{const r=typeof n=="number"?n:Ne(n);e.faceAlpha=r;break}}}function gpe(e){let t=0,n,r,i,s,o,a=0;for(let c=t;c<e.length&&jr(e[c]);c++)a++;if(a===1){const c=e[t++],u=zr(c);s=u.rows,o=u.cols,i=u.data;const h=Em(s,o);n=h.x,r=h.y}else if(a>=3){const c=e[t++],u=e[t++],h=e[t++],f=zr(h);s=f.rows,o=f.cols,i=f.data;const d=Cm(c,u,s,o);n=d.x,r=d.y}else throw new Error("pcolor requires 1 or 3 numeric input arguments");const l={x:n,y:r,c:i,rows:s,cols:o};for(;t<e.length;){const c=ppe(e[t]);if(!c||(t++,t>=e.length))break;const u=e[t++];mpe(l,c,u)}return l}function ype(e,t,n){switch(t){case"edgecolor":{const r=TR(n);if(r!==void 0){const s=r.toLowerCase();if(s==="none"||s==="flat"||s==="interp"){e.edgeColor=s;break}}const i=es(n);i&&(e.edgeColor=i);break}case"facecolor":{const r=TR(n);if(r!==void 0){const s=r.toLowerCase();if(s==="flat"||s==="interp"||s==="none"||s==="texturemap"){e.faceColor=s;break}}const i=es(n);i&&(e.faceColor=i);break}case"facealpha":{const r=typeof n=="number"?n:Ne(n);e.faceAlpha=r;break}}}function TR(e){if(mt(e))return e;if(lt(e))return e.value}function fV(e){if(e.length<2)throw new Error("scatter requires at least 2 arguments");const t=vn(e[0]),n=vn(e[1]),r={x:t,y:n,marker:"o",lineStyle:"none"};let i=2,s=!1;if(i<e.length&&jr(e[i])){const o=e[i];if(Re(o))r.markerSize=Math.sqrt(o)*.5;else if(ce(o)){const a=vn(o);(a.length===1||new Set(a).size===1)&&(r.markerSize=Math.sqrt(a[0])*.5)}i++}if(i<e.length&&!ml(e[i])){if(_i(e[i])){const o=Hr(e[i]);if(o==="filled")s=!0,i++;else{const a=es(o);if(a)r.color=a,i++;else{const l=Ju(o);l?.marker&&(r.marker=l.marker,l.color&&(r.color=Qu[l.color]),i++)}}}else if(jr(e[i])){const o=es(e[i]);o&&(r.color=o,i++)}}for(;i<e.length&&_i(e[i])&&!ml(e[i]);){const o=Hr(e[i]);if(o==="filled")s=!0,i++;else{const a=Ju(o);if(a?.marker)r.marker=a.marker,a.color&&(r.color=Qu[a.color]),i++;else break}}for(s&&(r.markerFaceColor=r.color||[0,0,1]);i<e.length;){const o=ml(e[i]);if(!o||(i++,i>=e.length))break;const a=e[i];i++,gI([r],o,a)}return[r]}function gI(e,t,n){switch(t){case"color":{const r=es(n);if(r)for(const i of e)i.color=r;break}case"linestyle":{const r=Hr(n);for(const i of e)i.lineStyle=r;break}case"linewidth":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.lineWidth=r;break}case"marker":{const r=Hr(n);for(const i of e)i.marker=r==="none"?void 0:r;break}case"markersize":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.markerSize=r;break}case"markeredgecolor":{const r=es(n);if(r)for(const i of e)i.markerEdgeColor=r;break}case"markerfacecolor":{const r=es(n);if(r)for(const i of e)i.markerFaceColor=r;break}case"markerindices":{const r=vn(n);for(const i of e)i.markerIndices=r;break}}}function _pe(e){if(e.length===1){const t=zr(e[0]);return{x:[1,t.cols],y:[1,t.rows],z:t.data,rows:t.rows,cols:t.cols}}if(e.length>=3){const t=vn(e[0]),n=vn(e[1]),r=zr(e[2]);return{x:[t[0],t[t.length-1]],y:[n[0],n[n.length-1]],z:r.data,rows:r.rows,cols:r.cols}}throw new Error("imagesc requires 1 or 3+ arguments")}function vpe(e,t){let n=0,r=0;for(let m=n;m<e.length&&jr(e[m]);m++)r++;let i,s,o,a,l,c=10,u;const h=m=>{const y=vn(m);y.length<=1?c=y.length===1?y[0]:c:u=y};if(r===1){const m=zr(e[n++]);a=m.rows,l=m.cols,o=m.data;const y=Em(a,l);i=y.x,s=y.y}else if(r===2){const m=zr(e[n++]);a=m.rows,l=m.cols,o=m.data,h(e[n++]);const y=Em(a,l);i=y.x,s=y.y}else if(r===3){const m=e[n++],y=e[n++],_=zr(e[n++]);a=_.rows,l=_.cols,o=_.data;const b=Cm(m,y,a,l);i=b.x,s=b.y}else if(r>=4){const m=e[n++],y=e[n++],_=zr(e[n++]);a=_.rows,l=_.cols,o=_.data,h(e[n++]);const b=Cm(m,y,a,l);i=b.x,s=b.y}else throw new Error("contour requires at least 1 argument");let f,d,p;for(;n+1<e.length&&_i(e[n]);n+=2){const m=Hr(e[n]).toLowerCase(),y=e[n+1];switch(m){case"linewidth":f=Ne(y);break;case"linestyle":d=Hr(y);break;case"linecolor":case"color":p=_i(y)?Hr(y):vn(y);break;case"levellist":case"levels":{const _=vn(y);_.length>=1&&(u=_);break}}}return u&&(c=u.length),{x:i,y:s,z:o,rows:a,cols:l,nLevels:c,...u?{levels:u}:{},...f!==void 0?{lineWidth:f}:{},...d!==void 0?{lineStyle:d}:{},...p!==void 0?{lineColor:p}:{},filled:t}}function bpe(e,t,n,r,i,s,o,a,l,c,u,h,f){const d=(e>=f?1:0)|(t>=f?2:0)|(n>=f?4:0)|(r>=f?8:0);if(d===0||d===15)return[];const p=(k,R,B,F)=>k+(f-B)/(F-B||1)*(R-k),m=p(i,o,e,t),y=p(s,a,e,t),_=p(o,u,t,r),b=p(a,h,t,r),x=p(l,u,n,r),S=p(c,h,n,r),M=p(i,l,e,n),E=p(s,c,e,n),T=[];switch(d){case 1:case 14:T.push([m,y,M,E]);break;case 2:case 13:T.push([m,y,_,b]);break;case 3:case 12:T.push([M,E,_,b]);break;case 4:case 11:T.push([M,E,x,S]);break;case 5:case 10:T.push([m,y,x,S]);break;case 6:case 9:T.push([m,y,M,E]),T.push([x,S,_,b]);break;case 7:case 8:T.push([x,S,_,b]);break}return T}function xpe(e){const{x:t,y:n,z:r,rows:i,cols:s}=e,o=(h,f,d)=>h[d*i+f];let a=1/0,l=-1/0;for(const h of r)Number.isFinite(h)&&(h<a&&(a=h),h>l&&(l=h));let c;if(e.levels&&e.levels.length>0)c=e.levels.filter(h=>Number.isFinite(h));else{const h=Math.max(1,Math.round(e.nLevels));if(c=[],Number.isFinite(a)&&Number.isFinite(l)&&l>a){const f=(l-a)/(h+1);for(let d=1;d<=h;d++)c.push(a+d*f)}}const u=[];for(const h of c)for(let f=0;f<s-1;f++)for(let d=0;d<i-1;d++){const p=bpe(o(r,d,f),o(r,d+1,f),o(r,d,f+1),o(r,d+1,f+1),o(t,d,f),o(n,d,f),o(t,d+1,f),o(n,d+1,f),o(t,d,f+1),o(n,d,f+1),o(t,d+1,f+1),o(n,d+1,f+1),h);for(const[m,y,_,b]of p)u.push(h,2,m,y,_,b)}return{data:u,n:u.length/2,levelList:c}}function wpe(e){const t=mI(e);return t.edgeColor||(t.edgeColor="flat"),t.faceColor||(t.faceColor="none"),t}function dV(e){let t=0,n,r,i=.8,s;if(e.length===0)throw new Error("bar requires at least 1 argument");const o=e[t++];for(t<e.length&&jr(e[t])?(n=vn(o),r=vn(e[t++])):r=vn(o);t<e.length;)if(jr(e[t])){const l=e[t];if(Re(l))i=l,t++;else break}else if(_i(e[t])){const l=Hr(e[t]),c=es(l);if(c)s=c,t++;else break}else break;n||(n=YM(r.length));const a={x:n,y:r,width:i};return s&&(a.color=s),[a]}function Spe(e){return dV(e)}function pV(e){let t=0,n,r=.8,i;if(e.length===0)throw new Error("bar3 requires at least 1 argument");const s=e[t++];let o,a,l;if(t<e.length&&jr(e[t])){n=vn(s);const d=e[t++];if(ce(d)){const p=zr(d);o=Array.from(p.data),a=p.rows,l=p.cols}else o=vn(d),a=o.length,l=1}else if(ce(s)){const d=zr(s);o=Array.from(d.data),a=d.rows,l=d.cols}else o=vn(s),a=o.length,l=1;for(;t<e.length;)if(jr(e[t])){const d=e[t];if(Re(d))r=d,t++;else break}else if(_i(e[t])){const d=Hr(e[t]),p=es(d);if(p)i=p,t++;else break}else break;n||(n=YM(a));const c=[],u=[],h=[];for(let d=0;d<l;d++)for(let p=0;p<a;p++)c.push(d+1),u.push(n[p]),h.push(o[d*a+p]);const f={x:c,y:u,z:h,rows:a,cols:l,width:r};return i&&(f.color=i),f}function Mpe(e){const t=tp(e);for(const n of t){const r=n.x.length;if(r<2)continue;const i=[],s=[];for(let o=0;o<r-1;o++)i.push(n.x[o]),s.push(n.y[o]),i.push(n.x[o+1]),s.push(n.y[o]);i.push(n.x[r-1]),s.push(n.y[r-1]),n.x=i,n.y=s}return t}function Epe(e){if(e.length<2)throw new Error("errorbar requires at least 2 arguments");let t=0,n,r,i,s,o,a,l,c,u,h=0;for(let d=0;d<e.length&&jr(e[d]);d++)h++;if(h===2){r=vn(e[t++]);const d=vn(e[t++]);i=d,s=d}else if(h===3){n=vn(e[t++]),r=vn(e[t++]);const d=vn(e[t++]);i=d,s=d}else if(h===4)n=vn(e[t++]),r=vn(e[t++]),i=vn(e[t++]),s=vn(e[t++]);else if(h>=6)n=vn(e[t++]),r=vn(e[t++]),i=vn(e[t++]),s=vn(e[t++]),o=vn(e[t++]),a=vn(e[t++]);else throw new Error("errorbar: invalid number of numeric arguments");for(n||(n=YM(r.length));t<e.length&&_i(e[t]);){const d=Hr(e[t]),p=Ju(d);if(p){if(p.color){const m=es(p.color);m&&(l=m)}p.lineStyle&&(c=p.lineStyle),p.marker&&(u=p.marker),t++}else{const m=es(d);if(m)l=m,t++;else break}}const f={x:n,y:r,yNeg:i,yPos:s};return o&&(f.xNeg=o),a&&(f.xPos=a),l&&(f.color=l),c&&(f.lineStyle=c),u&&(f.marker=u),[f]}function Cpe(e){let t=0;const n=[...e],r=n.length-1;return r>=1&&jr(n[r])&&Re(n[r])&&r>=1&&jr(n[r-1])&&(t=Ne(n[r]),n.pop()),{traces:tp(n),baseValue:t}}function mV(e){if(e.length<3)throw new Error("scatter3 requires at least 3 arguments");const t=vn(e[0]),n=vn(e[1]),r=vn(e[2]),i={x:t,y:n,z:r,marker:"o",lineStyle:"none"};let s=3,o=!1;if(s<e.length&&jr(e[s])){const a=e[s];if(Re(a))i.markerSize=Math.sqrt(a)*.5;else if(ce(a)){const l=vn(a);(l.length===1||new Set(l).size===1)&&(i.markerSize=Math.sqrt(l[0])*.5)}s++}if(s<e.length&&!ml(e[s])){if(_i(e[s])){const a=Hr(e[s]);if(a==="filled")o=!0,s++;else{const l=es(a);if(l)i.color=l,s++;else{const c=Ju(a);c?.marker&&(i.marker=c.marker,c.color&&(i.color=Qu[c.color]),s++)}}}else if(jr(e[s])){const a=es(e[s]);a&&(i.color=a,s++)}}for(;s<e.length&&_i(e[s])&&!ml(e[s]);){const a=Hr(e[s]);if(a==="filled")o=!0,s++;else{const l=Ju(a);if(l?.marker)i.marker=l.marker,l.color&&(i.color=Qu[l.color]),s++;else break}}for(o&&(i.markerFaceColor=i.color||[0,0,1]);s<e.length;){const a=ml(e[s]);if(!a||(s++,s>=e.length))break;const l=e[s];s++,pI([i],a,l)}return[i]}function Ape(e){if(e.length===0)throw new Error("histogram requires at least 1 argument");let t=0;const r=vn(e[t++]).filter(u=>isFinite(u));if(r.length===0)return[];let i;if(t<e.length&&jr(e[t])){const u=e[t++];Re(u)?i=bd(r,Math.max(1,Math.round(u))):i=vn(u)}else{const u=Math.max(1,Math.ceil(Math.log2(r.length)+1));i=bd(r,u)}const s=i.length-1;if(s<=0)return[];const o=new Array(s).fill(0);for(const u of r){let h=-1;for(let f=0;f<s;f++)if(f<s-1){if(u>=i[f]&&u<i[f+1]){h=f;break}}else if(u>=i[f]&&u<=i[f+1]){h=f;break}h>=0&&o[h]++}const a=[],l=[],c=i[1]-i[0];for(let u=0;u<s;u++)a.push((i[u]+i[u+1])/2),l.push(o[u]);return[{x:a,y:l,width:c}]}function bd(e,t){const n=Math.min(...e),s=(Math.max(...e)-n||1)/t,o=[];for(let a=0;a<=t;a++)o.push(n+a*s);return o}function Tpe(e){if(e.length<2)throw new Error("histogram2 requires at least 2 arguments");let t=0;const n=vn(e[t++]).filter(y=>isFinite(y)),r=vn(e[t++]).filter(y=>isFinite(y)),i=Math.min(n.length,r.length);if(i===0)return{x:[],y:[],z:[],rows:0,cols:0,width:.8};let s,o;if(t<e.length&&jr(e[t])){const y=e[t++];if(t<e.length&&jr(e[t]))s=vn(y),o=vn(e[t++]);else if(Re(y)){const _=Math.max(1,Math.round(y));s=bd(n.slice(0,i),_),o=bd(r.slice(0,i),_)}else{const _=vn(y),b=Math.max(1,Math.round(_[0])),x=_.length>1?Math.max(1,Math.round(_[1])):b;s=bd(n.slice(0,i),b),o=bd(r.slice(0,i),x)}}else{const y=Math.max(1,Math.ceil(Math.sqrt(i)));s=bd(n.slice(0,i),y),o=bd(r.slice(0,i),y)}const a=s.length-1,l=o.length-1;if(a<=0||l<=0)return{x:[],y:[],z:[],rows:0,cols:0,width:.8};const c=new Array(a*l).fill(0);for(let y=0;y<i;y++){const _=pz(n[y],s),b=pz(r[y],o);_>=0&&b>=0&&c[_*l+b]++}const u=[],h=[],f=[];for(let y=0;y<a;y++)for(let _=0;_<l;_++)u.push((s[y]+s[y+1])/2),h.push((o[_]+o[_+1])/2),f.push(c[y*l+_]);const d=s[1]-s[0],p=o[1]-o[0],m=Math.min(d,p);return{x:u,y:h,z:f,rows:l,cols:a,width:m}}function pz(e,t){const n=t.length-1;for(let r=0;r<n;r++)if(r<n-1){if(e>=t[r]&&e<t[r+1])return r}else if(e>=t[r]&&e<=t[r+1])return r;return-1}function CT(e,t){if(e.length===0)return NaN;if(e.length===1)return e[0];const n=t/100*(e.length-1),r=Math.floor(n),i=Math.ceil(n);return r===i?e[r]:e[r]+(e[i]-e[r])*(n-r)}function AT(e,t,n,r){const i=e.filter(m=>isFinite(m));if(i.length===0)return null;i.sort((m,y)=>m-y);const s=CT(i,50),o=CT(i,25),a=CT(i,75),l=a-o,c=o-1.5*l,u=a+1.5*l;let h=o,f=a;const d=[];for(const m of i)m<c||m>u?d.push(m):(m<h&&(h=m),m>f&&(f=m));return{x:t,median:s,q1:o,q3:a,whiskerLow:h,whiskerHigh:f,outliers:d,width:n}}function kpe(e){if(e.length===0)throw new Error("boxchart requires at least 1 argument");let t=0;const n=e[t++];if(t<e.length&&jr(e[t])){const s=vn(n),o=vn(e[t++]),a=Math.min(s.length,o.length),l=new Map;for(let h=0;h<a;h++){const f=s[h];if(!isFinite(f))continue;let d=l.get(f);d||(d=[],l.set(f,d)),d.push(o[h])}const c=[],u=[...l.keys()].sort((h,f)=>h-f);for(const h of u){const f=AT(l.get(h),h,.5);f&&c.push(f)}return c}if(ce(n)&&n.shape.length>=2&&n.shape[0]>1&&n.shape[1]>1){const s=[];for(let o=0;o<n.shape[1];o++){const a=cV(n,o),l=AT(a,o+1,.5);l&&s.push(l)}return s}const r=vn(n),i=AT(r,1,.5);return i?[i]:[]}function kR(e,t,n){const r=new Array(e.length),i=new Map;for(let s=0;s<e.length;s++){let o=i.get(e[s]);o||(o=[],i.set(e[s],o)),o.push(s)}for(const[,s]of i){if(s.length<=1){for(const p of s)r[p]=e[p];continue}const o=s.slice().sort((p,m)=>t[p]-t[m]),a=o.map(p=>t[p]),l=a[0],h=(a[a.length-1]-l||1)/Math.max(3,Math.sqrt(o.length)),f=new Array(o.length);for(let p=0;p<o.length;p++){let m=0;for(let y=0;y<o.length;y++){const _=(a[p]-a[y])/h;m+=Math.exp(-.5*_*_)}f[p]=m}const d=Math.max(...f);for(let p=0;p<o.length;p++){const m=d>0?f[p]/d:0,y=n*m,_=p,b=_%2===0?1:-1,x=Math.ceil(_/2)/Math.max(1,o.length/2)*y;r[o[p]]=e[o[p]]+b*x}}return r}function Rpe(e){if(e.length<2)throw new Error("swarmchart requires at least 2 arguments");const t=vn(e[0]),n=vn(e[1]),r=kR(t,n,.3),i=[RR(r),e[1],...e.slice(2)];return fV(i)}function Dpe(e){if(e.length<3)throw new Error("swarmchart3 requires at least 3 arguments");const t=vn(e[0]),n=vn(e[1]),r=vn(e[2]),i=kR(t,r,.3),s=kR(n,r,.3),o=[RR(i),RR(s),e[2],...e.slice(3)];return mV(o)}function RR(e){return{kind:"tensor",data:D(e),shape:[1,e.length]}}function gV(e,t){if(e.length===0)throw new Error("piechart requires at least 1 argument");let n=0;const r=vn(e[n++]).filter(s=>isFinite(s)&&s>0);let i;if(n<e.length&&!jr(e[n])&&!(ce(e[n])||Re(e[n]))){i=[];const s=e[n];if(s&&typeof s=="object"&&"kind"in s&&s.kind==="cell"){const o=s;for(const a of o.data)i.push(Hr(a))}else if(_i(s)){for(i.push(Hr(s)),n++;n<e.length&&_i(e[n]);)i.push(Hr(e[n])),n++;return{values:r,names:i,innerRadius:t}}n++}return{values:r,names:i,innerRadius:t}}function Npe(e){if(e.length===0)throw new Error("heatmap requires at least 1 argument");let t=0;if(e.length>=3&&jr(e[0]),e.length>=3&&jr(e[0])&&jr(e[1])&&jr(e[2])){const r=vn(e[t++]),i=vn(e[t++]),s=zr(e[t++]);return{data:s.data,rows:s.rows,cols:s.cols,xLabels:r.map(o=>String(o)),yLabels:i.map(o=>String(o))}}const n=zr(e[t++]);return{data:n.data,rows:n.rows,cols:n.cols}}const Lpe=new Set(["color","linestyle","linewidth","showarrowhead","autoscale","autoscalefactor","marker"]);function F2(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return Lpe.has(t)?t:null}function yV(e){if(typeof e=="string")return e;if(e&&typeof e=="object"&&"kind"in e){const t=e;if(mt(t))return t;if(lt(t))return t.value}}function Ipe(e){if(e.length<2)throw new Error("quiver requires at least 2 arguments");let t=0;for(let d=0;d<e.length&&jr(e[d]);d++)t++;let n=0,r,i,s,o,a,l,c;if(t===2)c=2;else if(t===3)c=2;else if(t>=4)c=4;else throw new Error("quiver requires at least 2 numeric arguments");if(c===2){const d=e[n++],p=e[n++],m=zr(d),y=zr(p);if(a=m.rows,l=m.cols,s=m.data,o=y.data,a===1||l===1){const _=s.length;r=new Array(_),i=new Array(_);for(let b=0;b<_;b++)r[b]=b+1,i[b]=1}else{const _=Em(a,l);r=_.x,i=_.y}}else{const d=e[n++],p=e[n++],m=e[n++],y=e[n++],_=zr(m),b=zr(y);a=_.rows,l=_.cols,s=_.data,o=b.data;const x=Cm(d,p,a,l);r=x.x,i=x.y}let u=!0,h=.9;if(n<e.length&&jr(e[n])&&!_i(e[n])){const d=Ne(e[n]);d===0?u=!1:h=d*.9,n++}const f={x:r,y:i,u:s,v:o,showArrowHead:!0};for(;n<e.length&&_i(e[n])&&!F2(e[n]);){const d=yV(e[n]);if(d===void 0)break;if(d==="off"){u=!1,n++;continue}if(d==="filled"){f.markerFilled=!0,n++;continue}const p=Ju(d);if(p){p.color&&(f.color=Qu[p.color]),p.lineStyle&&(f.lineStyle=p.lineStyle),p.marker&&(f.marker=p.marker,f.showArrowHead=!1),n++;continue}const m=es(d);if(m){f.color=m,n++;continue}break}for(;n<e.length;){const d=F2(e[n]);if(!d||(n++,n>=e.length))break;const p=e[n++];switch(d){case"color":{const m=es(p);m&&(f.color=m);break}case"linestyle":f.lineStyle=Hr(p);break;case"linewidth":f.lineWidth=typeof p=="number"?p:Ne(p);break;case"marker":{const m=Hr(p);f.marker=m==="none"?void 0:m;break}case"showarrowhead":{const m=Hr(p).toLowerCase();f.showArrowHead=!(m==="off"||m==="false"||m==="0");break}case"autoscale":{const m=Hr(p).toLowerCase();u=!(m==="off"||m==="false"||m==="0");break}case"autoscalefactor":{h=(typeof p=="number"?p:Ne(p))*.9;break}}}if(u){const d=Ppe(r,i,s,o,a,l,h);if(d!==1){const p=new Array(s.length),m=new Array(o.length);for(let y=0;y<s.length;y++)p[y]=s[y]*d;for(let y=0;y<o.length;y++)m[y]=o[y]*d;f.u=p,f.v=m}}return[f]}function Ppe(e,t,n,r,i,s,o){const a=n.length;if(a===0)return 1;let l=0,c=0;for(let S=0;S<i;S++)for(let M=0;M<s-1;M++){const E=M*i+S,T=(M+1)*i+S,k=e[T]-e[E],R=t[T]-t[E],B=Math.sqrt(k*k+R*R);isFinite(B)&&B>0&&(l+=B,c++)}for(let S=0;S<i-1;S++)for(let M=0;M<s;M++){const E=M*i+S,T=M*i+S+1,k=e[T]-e[E],R=t[T]-t[E],B=Math.sqrt(k*k+R*R);isFinite(B)&&B>0&&(l+=B,c++)}const u=c>0?l/c:0;let h=1/0,f=-1/0,d=1/0,p=-1/0;for(let S=0;S<e.length;S++)isFinite(e[S])&&(e[S]<h&&(h=e[S]),e[S]>f&&(f=e[S]));for(let S=0;S<t.length;S++)isFinite(t[S])&&(t[S]<d&&(d=t[S]),t[S]>p&&(p=t[S]));const m=f-h,y=p-d;let _;m>0&&y>0?_=Math.sqrt(m*y/a):m>0?_=m/Math.max(1,a-1):y>0?_=y/Math.max(1,a-1):_=0;const b=Math.max(u,_)||1;let x=0;for(let S=0;S<a;S++){const M=n[S],E=r[S];if(!isFinite(M)||!isFinite(E))continue;const T=Math.sqrt(M*M+E*E);T>x&&(x=T)}return x===0?1:o*b/x}function Bpe(e){if(e.length<4)throw new Error("quiver3 requires at least 4 arguments");let t=0;for(let y=0;y<e.length&&jr(e[y]);y++)t++;let n=0,r,i,s,o,a,l,c,u;if((t>=6?6:4)===4){const y=zr(e[n++]);c=y.rows,u=y.cols,s=y.data,o=zr(e[n++]).data,a=zr(e[n++]).data,l=zr(e[n++]).data;const _=s.length;if(c===1||u===1){r=new Array(_),i=new Array(_);for(let b=0;b<_;b++)r[b]=b+1,i[b]=1}else{const b=Em(c,_/c);r=b.x,i=b.y}}else{const y=e[n++],_=e[n++],b=zr(e[n++]);c=b.rows,u=b.cols,s=b.data,o=zr(e[n++]).data,a=zr(e[n++]).data,l=zr(e[n++]).data;const x=o.length,S=vn(y),M=vn(_);if(S.length===x&&M.length===x)r=S,i=M;else{const E=Cm(y,_,c,u);r=E.x,i=E.y}}let f=!0,d=.9,p=.9;if(n<e.length&&jr(e[n])&&!_i(e[n])){const y=Ne(e[n]);y===0?f=!1:(d=y*.9,p=y),n++}const m={x:r,y:i,z:s,u:o,v:a,w:l,showArrowHead:!0};for(;n<e.length&&_i(e[n])&&!F2(e[n]);){const y=yV(e[n]);if(y===void 0)break;if(y==="off"){f=!1,n++;continue}if(y==="filled"){m.markerFilled=!0,n++;continue}const _=Ju(y);if(_){_.color&&(m.color=Qu[_.color]),_.lineStyle&&(m.lineStyle=_.lineStyle),_.marker&&(m.marker=_.marker,m.showArrowHead=!1),n++;continue}const b=es(y);if(b){m.color=b,n++;continue}break}for(;n<e.length;){const y=F2(e[n]);if(!y||(n++,n>=e.length))break;const _=e[n++];switch(y){case"color":{const b=es(_);b&&(m.color=b);break}case"linestyle":m.lineStyle=Hr(_);break;case"linewidth":m.lineWidth=typeof _=="number"?_:Ne(_);break;case"marker":{const b=Hr(_);m.marker=b==="none"?void 0:b;break}case"showarrowhead":{const b=Hr(_).toLowerCase();m.showArrowHead=!(b==="off"||b==="false"||b==="0");break}case"autoscale":{const b=Hr(_).toLowerCase();f=!(b==="off"||b==="false"||b==="0");break}case"autoscalefactor":{const b=typeof _=="number"?_:Ne(_);d=b*.9,p=b;break}}}if(m.autoScale=f,m.autoScaleFactor=p,f){const y=Fpe(r,i,s,o,a,l,d);y!==1&&(m.u=o.map(_=>_*y),m.v=a.map(_=>_*y),m.w=l.map(_=>_*y))}return m}function Fpe(e,t,n,r,i,s,o){const a=r.length;if(a===0)return 1;const l=m=>{let y=1/0,_=-1/0;for(const b of m)isFinite(b)&&(b<y&&(y=b),b>_&&(_=b));return _>y?_-y:0},c=l(e),u=l(t),h=l(n),f=[c,u,h].filter(m=>m>0);let d;f.length===3?d=Math.cbrt(c*u*h/a):f.length===2?d=Math.sqrt(f[0]*f[1]/a):f.length===1?d=f[0]/Math.max(1,a-1):d=1,d=d||1;let p=0;for(let m=0;m<a;m++){const y=Math.sqrt(r[m]*r[m]+i[m]*i[m]+s[m]*s[m]);isFinite(y)&&y>p&&(p=y)}return p===0?1:o*d/p}function mz(e){if(typeof e=="number")return A.num(e);if(typeof e=="boolean")return A.logical(e);if(typeof e=="string")return A.char(e);if(Array.isArray(e)){const t=D(e);return A.tensor(t,[1,e.length])}return e}const _V={line:{Color:[0,.447,.741],LineStyle:"-",LineWidth:.5,Marker:"none",MarkerSize:6},patch:{FaceColor:[0,.447,.741],EdgeColor:[0,0,0],FaceAlpha:1,LineStyle:"-",LineWidth:.5,Marker:"none"},quiver3:{LineWidth:.5,LineStyle:"-",ShowArrowHead:!0,AutoScale:!0,AutoScaleFactor:.9,Marker:"none",Color:[0,.447,.741]}};function vV(e,t){if(t in e)return t;const n=t.charAt(0).toLowerCase()+t.slice(1);if(n in e)return n;const r=t.toLowerCase();for(const i of Object.keys(e))if(i.toLowerCase()===r)return i;if(r.endsWith("data")){const i=r.slice(0,-4);for(const s of Object.keys(e))if(s.toLowerCase()===i)return s}return null}function zpe(e,t){if(Array.isArray(t)&&t.length===3&&(mt(e)||lt(e))){const n=es(e);if(n)return n}if(typeof t=="boolean"){if(typeof e=="boolean")return e;if(typeof e=="number")return e!==0;if(mt(e)||lt(e)){const n=(lt(e)?e.value:e).toLowerCase();return!(n==="off"||n==="false"||n==="0")}return!0}if(typeof t=="string")return lt(e)?e.value:mt(e)?e:String(e);if((typeof t=="number"||t===void 0)&&(typeof e=="number"||Re(e)))return e;if(Array.isArray(t)){if(ce(e))return Array.from(e.data);if(typeof e=="number")return[e]}return e}const Upe={facecolor:"faceColor",edgecolor:"edgeColor",facealpha:"faceAlpha",linewidth:"lineWidth",linestyle:"lineStyle",marker:"marker",markerfacecolor:"markerFaceColor",facevertexcdata:"faceVertexCData",cdata:"faceVertexCData"};function bV(e,t,n,r){if(t==="patch"){const a=n.toLowerCase(),l=Upe[a];if(l)return ZM(e,a,r),{key:l,value:e[l]}}const i=vV(e,n)??n.charAt(0).toLowerCase()+n.slice(1),s=e[i]??_V[t]?.[n],o=zpe(r,s);return e[i]=o,{key:i,value:o}}function DR(e,t){if(Zn(e)||In(e)){const n=e.fields.get(t);if(n===void 0)throw new q(`No field '${t}' on ${In(e)?e.className:"struct"}`);return n}if(yi(e)){if(!e.fieldNames.includes(t))throw new q(`No field '${t}' on struct array`);const n=e.elements.map(r=>{const i=r.fields.get(t);if(i===void 0)throw new q(`No field '${t}' on struct element`);return i});return wb(...n)}if(qd(e)){const n=vV(e._trace,t);if(n!==null)return mz(e._trace[n]);const r=_V[e._traceType]?.[t];if(r!==void 0)return mz(r);throw new q(`No property '${t}' on ${e._traceType} handle`)}throw new q(`Cannot access field ${t} on ${po(e)}`)}function Ope(e,t,n,r){if(In(e)){if(e.isHandleClass)return r?e.bindField(r,t,n):e.fields.set(t,n),e;if(r&&!_2(e))return e.bindField(r,t,n),e;const i=new Map(e.fields);return i.set(t,n),new D1(e.className,i,!1,e._builtinData)}if(Zn(e)){if(r&&!_2(e))return e.bindField(r,t,n),e;const i=new Map(e.fields);return i.set(t,n),A.struct(i)}if(yi(e)){if(e.elements.length===1){const i=new Map(e.elements[0].fields);return i.set(t,n),A.struct(i)}throw new q(`Cannot assign field '${t}' on a non-scalar struct array without indexing`)}return qd(e)?(bV(e._trace,e._traceType,t,n),e):Re(e)&&e===0?A.struct(new Map([[t,n]])):A.struct(new Map([[t,n]]))}const NR={pi:Math.PI,inf:1/0,Inf:1/0,nan:NaN,NaN:NaN,realmax:Number.MAX_VALUE,realmin:22250738585072014e-324};function jpe(e){if(e==="true")return A.logical(!0);if(e==="false")return A.logical(!1);if(e in NR)return A.num(NR[e]);if(e==="i"||e==="j")return A.complex(0,1)}function Hpe(){return[...Object.keys(NR),"true","false","i","j"]}const $pe={comments:{lineComment:"%",blockComment:["%{","%}"]},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}]};function Vpe(){const e=fR(),t=Hpe();return{defaultToken:"",keywords:["function","if","else","elseif","for","while","break","continue","return","end","classdef","properties","methods","events","enumeration","arguments","import","switch","case","otherwise","try","catch","global","persistent","true","false"],builtinFunctions:e,builtinConstants:t,tokenizer:{root:[[/^%%.*$/,"comment.doc"],[/%\{/,"comment","@blockComment"],[/%.*$/,"comment"],[/[a-zA-Z_]\w*/,{cases:{"@keywords":{token:"keyword",next:"@afterValue"},"@builtinFunctions":{token:"predefined",next:"@afterValue"},"@builtinConstants":{token:"constant.language",next:"@afterValue"},"@default":{token:"identifier",next:"@afterValue"}}}],[/\d+\.?\d*([eE][+-]?\d+)?/,{token:"number.float",next:"@afterValue"}],[/\.\d+([eE][+-]?\d+)?/,{token:"number.float",next:"@afterValue"}],[/"([^"\\]|\\.)*$/,"string.invalid"],[/'([^'\\]|\\.)*$/,"string.invalid"],[/"/,"string","@doubleQuotedString"],[/'/,"string","@singleQuotedString"],[/[)\]]/,{token:"@brackets",next:"@afterValue"}],[/\}/,{token:"@brackets",next:"@afterValue"}],[/[{([]/,"@brackets"],[/[;,.]/,"delimiter"],[/==|~=|<=|>=|&&|\|\||\.\.\.|\.\*|\.\/|\.\\|\.\^|[=<>~+\-*/\\^&|!@?:]/,"operator"],{include:"@whitespace"}],afterValue:[[/\.'/,"operator"],[/'/,"operator"],[/$/,{token:"",next:"@pop"}],[/(?=[\s\S])/,{token:"",next:"@pop"}]],blockComment:[[/%\}/,"comment","@pop"],[/./,"comment"]],doubleQuotedString:[[/[^\\"]+/,"string"],[/\\./,"string.escape"],[/"/,{token:"string",switchTo:"@afterValue"}]],singleQuotedString:[[/[^\\']+/,"string"],[/''/,"string.escape"],[/'/,{token:"string",switchTo:"@afterValue"}]],whitespace:[[/[ \t\r\n]+/,"white"]]}}}var re=(e=>(e[e.Integer=0]="Integer",e[e.Float=1]="Float",e[e.Str=2]="Str",e[e.Char=3]="Char",e[e.Ident=4]="Ident",e[e.Function=5]="Function",e[e.If=6]="If",e[e.Else=7]="Else",e[e.ElseIf=8]="ElseIf",e[e.For=9]="For",e[e.ParFor=10]="ParFor",e[e.While=11]="While",e[e.Break=12]="Break",e[e.Continue=13]="Continue",e[e.Return=14]="Return",e[e.End=15]="End",e[e.ClassDef=16]="ClassDef",e[e.Properties=17]="Properties",e[e.Methods=18]="Methods",e[e.Events=19]="Events",e[e.Enumeration=20]="Enumeration",e[e.Arguments=21]="Arguments",e[e.Import=22]="Import",e[e.Switch=23]="Switch",e[e.Case=24]="Case",e[e.Otherwise=25]="Otherwise",e[e.Try=26]="Try",e[e.Catch=27]="Catch",e[e.Global=28]="Global",e[e.Persistent=29]="Persistent",e[e.True=30]="True",e[e.False=31]="False",e[e.Plus=32]="Plus",e[e.Minus=33]="Minus",e[e.Star=34]="Star",e[e.Slash=35]="Slash",e[e.Backslash=36]="Backslash",e[e.Caret=37]="Caret",e[e.And=38]="And",e[e.Or=39]="Or",e[e.Tilde=40]="Tilde",e[e.At=41]="At",e[e.Question=42]="Question",e[e.Less=43]="Less",e[e.Greater=44]="Greater",e[e.Dot=45]="Dot",e[e.Colon=46]="Colon",e[e.Comma=47]="Comma",e[e.Assign=48]="Assign",e[e.Semicolon=49]="Semicolon",e[e.LParen=50]="LParen",e[e.RParen=51]="RParen",e[e.LBracket=52]="LBracket",e[e.RBracket=53]="RBracket",e[e.LBrace=54]="LBrace",e[e.RBrace=55]="RBrace",e[e.DotStar=56]="DotStar",e[e.DotSlash=57]="DotSlash",e[e.DotBackslash=58]="DotBackslash",e[e.DotCaret=59]="DotCaret",e[e.AndAnd=60]="AndAnd",e[e.OrOr=61]="OrOr",e[e.Equal=62]="Equal",e[e.NotEqual=63]="NotEqual",e[e.LessEqual=64]="LessEqual",e[e.GreaterEqual=65]="GreaterEqual",e[e.Transpose=66]="Transpose",e[e.Ellipsis=67]="Ellipsis",e[e.Newline=68]="Newline",e[e.Section=69]="Section",e[e.Error=70]="Error",e[e.Directive=71]="Directive",e))(re||{});const xV=new Map([["function",re.Function],["if",re.If],["else",re.Else],["elseif",re.ElseIf],["for",re.For],["parfor",re.ParFor],["while",re.While],["break",re.Break],["continue",re.Continue],["return",re.Return],["end",re.End],["classdef",re.ClassDef],["properties",re.Properties],["methods",re.Methods],["events",re.Events],["enumeration",re.Enumeration],["arguments",re.Arguments],["import",re.Import],["switch",re.Switch],["case",re.Case],["otherwise",re.Otherwise],["try",re.Try],["catch",re.Catch],["global",re.Global],["persistent",re.Persistent],["true",re.True],["false",re.False]]);re.True,re.False;function wV(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"}function Wpe(e){return wV(e)||e>="0"&&e<="9"}function Rp(e){return e>="0"&&e<="9"}function gz(e){return e===" "||e===" "||e==="\r"}function TT(e){return e===re.Ident||e===re.Integer||e===re.Float||e===re.True||e===re.False||e===re.End||e===re.RParen||e===re.RBracket||e===re.RBrace||e===re.Str||e===re.Char||e===re.Transpose}function kT(e,t=0){for(let n=t;n<e.length;n++){if(e[n]===`
|
|
172
|
+
`;break;case"t":r+=" ";break;case"r":r+="\r";break;case"a":r+="\x07";break;case"b":r+="\b";break;case"f":r+="\f";break;case"v":r+="\v";break;case"0":r+="\0";break;case"\\":r+="\\";break;default:r+="\\"+e[a]}a++}else r+=e[a],a++;if(i===s)break}while(i<n.length);return r}function MR(e){if(Ht(e))return{re:e.re,im:e.im};if(Re(e))return{re:e,im:0};if(Tt(e))return{re:e?1:0,im:0};if(ce(e)&&e.data.length===1)return{re:e.data[0],im:e.imag?e.imag[0]:0};if(Dt(e))return MR(To(e));throw new q(`Cannot use ${po(e)} in complex arithmetic`)}function ah(e,t){return Ht(e)||Ht(t)||ce(e)&&e.imag!==void 0||ce(t)&&t.imag!==void 0||Dt(e)&&e.pi!==void 0||Dt(t)&&t.pi!==void 0}function Vp(e,t){return t===0?A.num(e):A.complex(e,t)}function Iv(e){if(Ht(e))return{scalar:!0,re:e.re,im:e.im};if(Re(e))return{scalar:!0,re:e,im:0};if(Tt(e))return{scalar:!0,re:e?1:0,im:0};if(ce(e)){if(e.data.length===1)return{scalar:!0,re:e.data[0],im:e.imag?e.imag[0]:0};const t=e.imag||D(e.data.length);return{scalar:!1,re:e.data,im:t,shape:e.shape}}if(Dt(e))return Iv(To(e));throw new q(`Cannot use ${po(e)} in complex arithmetic`)}function V$(e,t,n,r){const i=Iv(e),s=Iv(t);if(i.scalar&&s.scalar)return A.logical(n(i.re,i.im,s.re,s.im));if(i.scalar&&!s.scalar){const c=s.re.length;if(s.re instanceof Float64Array&&(!s.im||s.im instanceof Float64Array)){const f=D(c);ho.complexScalarComparison(r,c,i.re,i.im,s.re,s.im,!0,f);const d=A.tensor(f,s.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(i.re,i.im,s.re[f],s.im[f])?1:0;const h=A.tensor(u,s.shape);return h._isLogical=!0,h}if(!i.scalar&&s.scalar){const c=i.re.length;if(i.re instanceof Float64Array&&(!i.im||i.im instanceof Float64Array)){const f=D(c);ho.complexScalarComparison(r,c,s.re,s.im,i.re,i.im,!1,f);const d=A.tensor(f,i.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(i.re[f],i.im[f],s.re,s.im)?1:0;const h=A.tensor(u,i.shape);return h._isLogical=!0,h}const o=i,a=s;if(o.re.length===a.re.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=o.re.length;if(o.re instanceof Float64Array&&a.re instanceof Float64Array&&(!o.im||o.im instanceof Float64Array)&&(!a.im||a.im instanceof Float64Array)){const f=D(c);ho.complexComparison(r,c,o.re,o.im,a.re,a.im,f);const d=A.tensor(f,o.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(o.re[f],o.im[f],a.re[f],a.im[f])?1:0;const h=A.tensor(u,o.shape);return h._isLogical=!0,h}const l=Zu(o.shape,a.shape);if(l!==null)return yde(o,a,l,n);throw new q(`Matrix dimensions must agree for comparison: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}function ez(e){return e>0?1/0:e<0?-1/0:0}function ER(e,t,n,r){if(n===0&&r===0)return e===0&&t===0?{re:NaN,im:0}:{re:ez(e),im:ez(t)};if(Math.abs(n)>=Math.abs(r)){const o=r/n,a=n+r*o;return{re:(e+t*o)/a,im:(t-e*o)/a}}const i=n/r,s=r+n*i;return{re:(e*i+t)/s,im:(t*i-e)/s}}function Xd(e,t,n,r){if(r!==void 0){const c=tz(e),u=tz(t);if(c&&ce(t)&&t.data.length>1){const h=nz(c.re,c.im,t.data,t.imag,t.shape,r,!0);if(h)return h}else if(u&&ce(e)&&e.data.length>1){const h=nz(u.re,u.im,e.data,e.imag,e.shape,r,!1);if(h)return h}}const i=Iv(e),s=Iv(t);if(i.scalar&&s.scalar){const c=n(i.re,i.im,s.re,s.im);return Vp(c.re,c.im)}if(i.scalar&&!s.scalar){const c=s.re.length,u=D(c),h=D(c);for(let d=0;d<c;d++){const p=n(i.re,i.im,s.re[d],s.im[d]);u[d]=p.re,h[d]=p.im}const f=h.every(d=>d===0);return A.tensor(u,s.shape,f?void 0:h)}if(!i.scalar&&s.scalar){const c=i.re.length,u=D(c),h=D(c);for(let d=0;d<c;d++){const p=n(i.re[d],i.im[d],s.re,s.im);u[d]=p.re,h[d]=p.im}const f=h.every(d=>d===0);return A.tensor(u,i.shape,f?void 0:h)}const o=i,a=s;if(o.re.length===a.re.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=o.re.length,u=D(c),h=D(c);for(let d=0;d<c;d++){const p=n(o.re[d],o.im[d],a.re[d],a.im[d]);u[d]=p.re,h[d]=p.im}const f=h.every(d=>d===0);return A.tensor(u,o.shape,f?void 0:h)}const l=Zu(o.shape,a.shape);if(l!==null)return gde(o,a,l,n);throw new q(`Matrix dimensions must agree: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}const t_=0,n_=1,Cd=2,w0=3;function qM(e,t){if(typeof e!="object"||e===null||e.kind!=="tensor"||typeof t!="object"||t===null||t.kind!=="tensor")return null;const n=e,r=t;return n.data.length!==r.data.length||n.shape.length!==r.shape.length||n.shape.some((i,s)=>i!==r.shape[s])?null:[n,r]}function GM(e,t,n){if(!(e.data instanceof Float64Array)||!(t.data instanceof Float64Array))return null;const r=e.data.length,i=D(r);return ho.realBinaryElemwise(n,r,e.data,t.data,i),A.tensorRaw(i,e.shape)}function Ku(e,t,n,r){if(t.imag||!(t.data instanceof Float64Array))return null;const i=t.data.length,s=D(i);return ho.realScalarBinaryElemwise(n,i,e,t.data,r,s),A.tensorRaw(s,t.shape)}function tz(e){return Re(e)?{re:e,im:0}:Ht(e)?{re:e.re,im:e.im}:Tt(e)?{re:e?1:0,im:0}:ce(e)&&e.data.length===1?{re:e.data[0],im:e.imag?e.imag[0]:0}:null}function nz(e,t,n,r,i,s,o){if(!(n instanceof Float64Array)||r&&!(r instanceof Float64Array))return null;const a=n.length,l=D(a),c=D(a);ho.complexScalarBinaryElemwise(s,a,e,t,n,r??null,o,l,c);let u=!0;for(let h=0;h<a;h++)if(c[h]!==0){u=!1;break}return u?A.tensorRaw(l,i):A.tensor(l,i,c)}function XM(e,t,n,r){if(e.data instanceof Float64Array&&t.data instanceof Float64Array){const u=e.data.length,h=D(u),f=D(u);ho.complexBinaryElemwise(n,u,e.data,e.imag??null,t.data,t.imag??null,h,f);let d=!0;for(let p=0;p<u;p++)if(f[p]!==0){d=!1;break}return d?A.tensorRaw(h,e.shape):A.tensor(h,e.shape,f)}const i=e.data.length,s=e.imag,o=t.imag,a=D(i),l=D(i);if(s&&o)for(let u=0;u<i;u++){const h=r(e.data[u],s[u],t.data[u],o[u]);a[u]=h.re,l[u]=h.im}else if(s)for(let u=0;u<i;u++){const h=r(e.data[u],s[u],t.data[u],0);a[u]=h.re,l[u]=h.im}else for(let u=0;u<i;u++){const h=r(e.data[u],0,t.data[u],o[u]);a[u]=h.re,l[u]=h.im}const c=l.every(u=>u===0);return A.tensor(a,e.shape,c?void 0:l)}function ST(e){if(mt(e))return e;if(lt(e))return e.value;if(Tt(e))return e?"true":"false";if(Re(e))return J8(e);if(ce(e)&&e.data.length===1&&!e.imag){const t=e.data[0];return e._isLogical===!0?t?"true":"false":J8(t)}return null}function B0(e,t){if(Wn(e)||Wn(t)){const r=Wn(e)?e:null,i=Wn(t)?t:null;if(r&&i){if(r.shape[0]!==i.shape[0]||r.shape[1]!==i.shape[1])throw new q("Array dimensions must match for string plus");return hs(r.data.map((a,l)=>a+i.data[l]),r.shape)}const s=r??i,o=ST(r?t:e);if(o===null)throw new q("Cannot concatenate this value with a string");return hs(s.data.map(a=>r?a+o:o+a),s.shape)}if(mt(e)||mt(t)){const r=ST(e),i=ST(t);if(r!==null&&i!==null)return A.string(r+i)}if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]+i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i+r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,t_);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]+i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,t_,(s,o,a,l)=>({re:s+a,im:o+l}))}if(Dt(e)||Dt(t))return Jfe(e,t);if(ah(e,t))return Xd(e,t,(r,i,s,o)=>({re:r+s,im:i+o}),t_);if(Re(e)&&ce(t)){const r=Ku(e,t,t_,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,t_,!1);if(r)return r}return yf(e,t,(r,i)=>r+i,J$)}function Pv(e,t){if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]-i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i-r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,n_);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]-i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,n_,(s,o,a,l)=>({re:s-a,im:o-l}))}if(Dt(e)||Dt(t))return ede(e,t);if(ah(e,t))return Xd(e,t,(r,i,s,o)=>({re:r-s,im:i-o}),n_);if(Re(e)&&ce(t)){const r=Ku(e,t,n_,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,n_,!1);if(r)return r}return yf(e,t,(r,i)=>r-i,eV)}function vd(e,t){if(Dt(e)||Dt(t))return tde(e,t);if(ce(e)&&e.data.length===1&&(e=Vc(e)),ce(t)&&t.data.length===1&&(t=Vc(t)),ce(e)&&ce(t))return tV(e,t);if(ah(e,t))return Xd(e,t,(n,r,i,s)=>({re:n*i-r*s,im:n*s+r*i}),Cd);if(Re(e)&&ce(t)){const n=Ku(e,t,Cd,!0);if(n)return n}else if(ce(e)&&Re(t)){const n=Ku(t,e,Cd,!1);if(n)return n}return yf(e,t,(n,r)=>n*r,uI)}function nI(e,t){if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]*i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i*r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,Cd);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]*i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,Cd,(s,o,a,l)=>({re:s*a-o*l,im:s*l+o*a}))}if(Dt(e)||Dt(t))return nde(e,t);if(ah(e,t))return Xd(e,t,(r,i,s,o)=>({re:r*s-i*o,im:r*o+i*s}),Cd);if(Re(e)&&ce(t)){const r=Ku(e,t,Cd,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,Cd,!1);if(r)return r}return yf(e,t,(r,i)=>r*i,uI)}function rI(e,t){if(Dt(e)||Dt(t))return rI(To(e),To(t));if(ce(e)&&e.data.length===1&&(e=Vc(e)),ce(t)&&t.data.length===1&&(t=Vc(t)),ce(t)){const n=Z_(tI(e,"mrdivide")),r=Z_(t),i=Bv(r,n);return Z_(i)}return ah(e,t)?Xd(e,t,ER,w0):yf(e,t,(n,r)=>n/r,hI)}function pm(e,t){if(ce(e)&&!e.imag&&Re(t)){const r=e.data,i=t,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=r[a]/i;return A.tensorRaw(o,e.shape)}if(Re(e)&&ce(t)&&!t.imag){const r=t.data,i=e,s=r.length,o=D(s);for(let a=0;a<s;a++)o[a]=i/r[a];return A.tensorRaw(o,t.shape)}const n=qM(e,t);if(n){const[r,i]=n;if(!r.imag&&!i.imag){const s=GM(r,i,w0);if(s)return s;const o=r.data.length,a=D(o);for(let l=0;l<o;l++)a[l]=r.data[l]/i.data[l];return A.tensorRaw(a,r.shape)}return XM(r,i,w0,ER)}if(Dt(e)||Dt(t))return rde(e,t);if(ah(e,t))return Xd(e,t,ER,w0);if(Re(e)&&ce(t)){const r=Ku(e,t,w0,!0);if(r)return r}else if(ce(e)&&Re(t)){const r=Ku(t,e,w0,!1);if(r)return r}return yf(e,t,(r,i)=>r/i,hI)}function Bv(e,t){if(Dt(e))return Bv(To(e),t);if(Dt(t))return Bv(e,To(t));if(ce(e)&&e.data.length===1&&(e=Vc(e)),ce(t)&&t.data.length===1&&(t=Vc(t)),Re(e)||Tt(e))return pm(t,e);const n=e,r=Re(t)||Tt(t)?A.tensor(D([Ne(t)]),[1,1]):t;if(!ce(n)||!ce(r))throw new q("mldivide (\\): operands must be numeric matrices");const[i,s]=Bn(n),[o,a]=Bn(r);if(o!==i)throw new q(`mldivide (\\): A is ${i}×${s} but B has ${o} rows`);if(i===0||s===0||a===0)return A.tensor(D(s*a),[s,a]);if(n.imag||r.imag){const c=n.data,u=n.imag??D(n.data.length),h=r.data,f=r.imag??D(r.data.length),d=eI(c,u,i,s,h,f,a);return Vc(A.tensor(d.re,[s,a],d.im))}const l=WM(n.data,i,s,r.data,a);if(!l)throw new q("mldivide (\\): LAPACK bridge unavailable");return Vc(A.tensor(l,[s,a]))}function fde(e,t){return pm(t,e)}function dde(e){return Number.isInteger(e)?(e&1)===0?1:-1:Number.isInteger(e*2)?0:Math.cos(Math.PI*e)}function pde(e){if(Number.isInteger(e))return 0;const t=e*2;return Number.isInteger(t)?((t-1)/2&1)===0?1:-1:Math.sin(Math.PI*e)}function CR(e,t){const n=Math.pow(-e,t);return{re:n*dde(t),im:n*pde(t)}}function W$(e,t){if(ah(e,t)){const n=MR(e),r=MR(t);if(n.im===0&&r.im===0&&n.re<0){const u=CR(n.re,r.re);return Vp(u.re,u.im)}const i=Math.hypot(n.re,n.im);if(i===0)return r.re===0&&r.im===0?Vp(1,0):r.re>0?Vp(0,0):Vp(1/0,0);const s=Math.atan2(n.im,n.re),o=Math.log(i),a=r.re*o-r.im*s,l=r.re*s+r.im*o,c=Math.exp(a);return Vp(c*Math.cos(l),c*Math.sin(l))}if(ce(e)&&(Re(t)||Tt(t))){const n=Ne(t),[r,i]=Bn(e);if(r===i&&Number.isInteger(n)){if(n===0){const l=D(r*i);for(let c=0;c<r;c++)l[gn(c,c,r)]=1;return A.tensor(l,[r,i])}let s=e,o=n;if(o<0){const l=hde("mpower","inv",[e],1);if(!ce(l))throw new q("mpower: inv returned non-tensor");s=l,o=-o}let a=s;for(let l=1;l<o;l++)a=tV(a,s);return a}}if(Re(e)&&e<0&&Re(t)&&!Number.isInteger(t)){const n=CR(e,t);return Vp(n.re,n.im)}return yf(e,t,(n,r)=>Math.pow(n,r))}function q$(e,t){if(ce(e)&&!e.imag&&Re(t)){const i=t;if(i===2){const s=D(e.data.length);for(let o=0;o<s.length;o++)s[o]=e.data[o]*e.data[o];return A.tensor(s,e.shape)}if(Number.isInteger(i)||i>=0){let s=!1;if(!Number.isInteger(i)){for(let o=0;o<e.data.length;o++)if(e.data[o]<0){s=!0;break}}if(!s){const o=D(e.data.length);for(let a=0;a<o.length;a++)o[a]=Math.pow(e.data[a],i);return A.tensor(o,e.shape)}}}const n=(i,s,o,a)=>{if(s===0&&a===0&&i<0)return CR(i,o);const l=Math.hypot(i,s);if(l===0)return o===0&&a===0?{re:1,im:0}:o>0?{re:0,im:0}:{re:1/0,im:0};const c=Math.atan2(s,i),u=Math.log(l),h=o*u-a*c,f=o*c+a*u,d=Math.exp(h);return{re:d*Math.cos(f),im:d*Math.sin(f)}};if(ah(e,t))return Xd(e,t,n);let r=!1;if(Re(e)&&e<0)r=!0;else if(ce(e)){for(let i=0;i<e.data.length;i++)if(e.data[i]<0){r=!0;break}}if(r){let i=!1;if(Re(t))i=Number.isInteger(t);else if(Tt(t))i=!0;else if(ce(t)){i=!0;for(let s=0;s<t.data.length;s++)if(!Number.isInteger(t.data[s])){i=!1;break}}return i?yf(e,t,(s,o)=>Math.pow(s,o)):Xd(e,t,n)}return yf(e,t,(i,s)=>Math.pow(i,s))}function G$(e){if(ce(e)){if(e.imag!==void 0){const n=D(e.data.length),r=D(e.imag.length);for(let i=0;i<e.data.length;i++)n[i]=-e.data[i],r[i]=-e.imag[i];return A.tensor(n,e.shape,r)}const t=D(e.data.length);for(let n=0;n<e.data.length;n++)t[n]=-e.data[n];return A.tensor(t,e.shape)}return Dt(e)?Yfe(e):Ht(e)?A.complex(-e.re,-e.im):vde(e,t=>-t)}function X$(e){const t=e.shape,n=t.length===0||t.length===1?1:t[0],r=t.length===0?1:t.length===1?t[0]:t[1],i=new Array(e.data.length);for(let s=0;s<n;s++)for(let o=0;o<r;o++)i[s*r+o]=e.data[gn(s,o,n)];return A.cell(i,[r,n])}function Y$(e,t){const[n,r]=Bn(e),i=D(e.data.length);for(let o=0;o<n;o++)for(let a=0;a<r;a++)i[o*r+a]=e.data[gn(o,a,n)];if(e.imag!==void 0){const o=D(e.imag.length),a=t?-1:1;for(let l=0;l<n;l++)for(let c=0;c<r;c++)o[l*r+c]=a*e.imag[gn(l,c,n)];return A.tensor(i,[r,n],o)}const s=A.tensor(i,[r,n]);return e._isLogical&&(s._isLogical=!0),s}function K$(e){const[t,n]=e.shape,r=new Array(e.elements.length);for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[i*n+s]=e.elements[s*t+i];return new UM(e.className,r,[n,t])}function Z$(e){const[t,n]=e.shape,r=new Array(t*n);for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[i*n+s]=e.data[s*t+i];return hs(r,[n,t])}function Q$(e){if(Dt(e))return z$(e);if(Ht(e)||Re(e)||Tt(e))return e;if(nn(e))return X$(e);if(lt(e)||mt(e))return e;if(Wn(e))return Z$(e);if(In(e))return e;if(ii(e))return K$(e);if(!ce(e))throw new q("Cannot transpose non-numeric value");return Y$(e,!1)}function Z_(e){if(Dt(e))return Kfe(e);if(Ht(e))return A.complex(e.re,-e.im);if(Re(e)||Tt(e))return e;if(nn(e))return X$(e);if(lt(e)||mt(e))return e;if(Wn(e))return Z$(e);if(In(e))return e;if(ii(e))return K$(e);if(!ce(e))throw new q("Cannot transpose non-numeric value");return Y$(e,!0)}function mde(e,t){return mt(e)&&mt(t)?[e,t]:mt(e)&<(t)?[e,t.value]:lt(e)&&mt(t)?[e.value,t]:null}function rz(e){return mt(e)?{data:[e],shape:[1,1]}:lt(e)?(e.shape?e.shape[0]:1)>1?null:{data:[e.value],shape:[1,1]}:Wn(e)?{data:e.data,shape:e.shape}:null}function L1(e,t,n){if(Wn(e)||Wn(t)){const i=rz(e),s=rz(t);if(i===null||s===null)return null;const o=i.data.length===1&&i.shape[0]*i.shape[1]===1,a=s.data.length===1&&s.shape[0]*s.shape[1]===1;if(!o&&!a&&(i.shape[0]!==s.shape[0]||i.shape[1]!==s.shape[1]))throw new q("Array dimensions must match for comparison");const l=o?s.shape:i.shape,c=o?s.data.length:i.data.length,u=D(c);for(let f=0;f<c;f++){const d=o?i.data[0]:i.data[f],p=a?s.data[0]:s.data[f];u[f]=n(d,p)?1:0}const h=A.tensor(u,[l[0],l[1]]);return h._isLogical=!0,h}const r=mde(e,t);return r===null?null:A.logical(n(r[0],r[1]))}function To(e){return Dt(e)?Mr(e):e}function iI(e,t){if(Dt(e)||Dt(t))return iI(To(e),To(t));const n=L1(e,t,(r,i)=>r===i);return n!==null?n:ah(e,t)?V$(e,t,(r,i,s,o)=>r===s&&i===o,hi.EQ):I1(e,t,(r,i)=>r===i,hi.EQ)}function sI(e,t){if(Dt(e)||Dt(t))return sI(To(e),To(t));const n=L1(e,t,(r,i)=>r!==i);return n!==null?n:ah(e,t)?V$(e,t,(r,i,s,o)=>r!==s||i!==o,hi.NE):I1(e,t,(r,i)=>r!==i,hi.NE)}function oI(e,t){if(Dt(e)||Dt(t))return oI(To(e),To(t));const n=L1(e,t,(r,i)=>r<i);return n!==null?n:I1(e,t,(r,i)=>r<i,hi.LT)}function aI(e,t){if(Dt(e)||Dt(t))return aI(To(e),To(t));const n=L1(e,t,(r,i)=>r<=i);return n!==null?n:I1(e,t,(r,i)=>r<=i,hi.LE)}function lI(e,t){if(Dt(e)||Dt(t))return lI(To(e),To(t));const n=L1(e,t,(r,i)=>r>i);return n!==null?n:I1(e,t,(r,i)=>r>i,hi.GT)}function cI(e,t){if(Dt(e)||Dt(t))return cI(To(e),To(t));const n=L1(e,t,(r,i)=>r>=i);return n!==null?n:I1(e,t,(r,i)=>r>=i,hi.GE)}function o1(e){if(Re(e))return{scalar:!0,value:e,isComplex:!1};if(Tt(e))return{scalar:!0,value:e?1:0,isComplex:!1};if(Ht(e))return{scalar:!0,re:e.re,im:e.im,isComplex:!0};if(ce(e))return e.data.length===1?e.imag!==void 0?{scalar:!0,re:e.data[0],im:e.imag[0],isComplex:!0}:{scalar:!0,value:e.data[0],isComplex:!1}:{scalar:!1,tensor:e};if(Dt(e))return o1(To(e));if(lt(e)){if(e.value.length===1)return{scalar:!0,value:e.value.charCodeAt(0),isComplex:!1};const t=D(Array.from(e.value).map(n=>n.charCodeAt(0)));return{scalar:!1,tensor:A.tensorRaw(t,[1,e.value.length])}}throw new q(`Cannot use ${po(e)} in numeric operation`)}function Zu(e,t){const n=Math.max(e.length,t.length,2),r=R2(e.length===0?[1,1]:e.length===1?[1,e[0]]:e,n),i=R2(t.length===0?[1,1]:t.length===1?[1,t[0]]:t,n),s=[];for(let o=0;o<n;o++){const a=r[o],l=i[o];if(a===l)s.push(a);else if(a===1)s.push(l);else if(l===1)s.push(a);else return null}return s}function R2(e,t){if(e.length>=t)return e;const n=[...e];for(;n.length<t;)n.push(1);return n}function gf(e,t,n,r){const i=n.length,s=n.reduce((m,y)=>m*y,1),o=R2(e,i),a=R2(t,i),l=new Array(i),c=new Array(i);let u=1,h=1;for(let m=0;m<i;m++)l[m]=o[m]===1?0:u,c[m]=a[m]===1?0:h,u*=o[m],h*=a[m];const f=new Array(i).fill(0);let d=0,p=0;for(let m=0;m<s;m++){r(d,p,m);for(let y=0;y<i&&(f[y]++,d+=l[y],p+=c[y],!(f[y]<n[y]));y++)d-=f[y]*l[y],p-=f[y]*c[y],f[y]=0}}const J$=0,eV=1,uI=2,hI=3;function iz(e,t,n,r,i){if(n.length===2){const o=n[0],a=n[1],l=D(o*a),c=e.shape,u=t.shape,h=c.length>=1?c[0]:1,f=c.length>=2?c[1]:1,d=u.length>=1?u[0]:1,p=u.length>=2?u[1]:1,m=h===1?0:1,y=f===1?0:h,_=d===1?0:1,b=p===1?0:d,x=e.data,S=t.data;let M=0;if(i===J$)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]+S[k+R*_]}else if(i===eV)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]-S[k+R*_]}else if(i===uI)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]*S[k+R*_]}else if(i===hI)for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=x[T+R*m]/S[k+R*_]}else for(let E=0;E<a;E++){const T=E*y,k=E*b;for(let R=0;R<o;R++)l[M++]=r(x[T+R*m],S[k+R*_])}return A.tensor(l,n)}const s=D(n.reduce((o,a)=>o*a,1));return gf(e.shape,t.shape,n,(o,a,l)=>{s[l]=r(e.data[o],t.data[a])}),A.tensor(s,n)}function gde(e,t,n,r){const i=n.reduce((l,c)=>l*c,1),s=D(i),o=D(i);gf(e.shape,t.shape,n,(l,c,u)=>{const h=r(e.re[l],e.im[l],t.re[c],t.im[c]);s[u]=h.re,o[u]=h.im});const a=o.every(l=>l===0);return A.tensor(s,n,a?void 0:o)}function yde(e,t,n,r){const i=D(n.reduce((o,a)=>o*a,1));gf(e.shape,t.shape,n,(o,a,l)=>{i[l]=r(e.re[o],e.im[o],t.re[a],t.im[a])?1:0});const s=A.tensor(i,n);return s._isLogical=!0,s}function _de(e,t,n,r){const i=D(n.reduce((o,a)=>o*a,1));gf(e.shape,t.shape,n,(o,a,l)=>{i[l]=r(e.data[o],t.data[a])?1:0});const s=A.tensor(i,n);return s._isLogical=!0,s}function yf(e,t,n,r){if(ce(e)&&e.data.length>1){if(ce(t)&&t.data.length>1){if(e.data.length===t.data.length&&e.shape.length===t.shape.length&&e.shape.every((u,h)=>u===t.shape[h])){const u=D(e.data.length);for(let h=0;h<u.length;h++)u[h]=n(e.data[h],t.data[h]);return A.tensor(u,e.shape)}const c=Zu(e.shape,t.shape);if(c!==null)return iz(e,t,c,n,r);throw new q(`Matrix dimensions must agree: [${e.shape.join(",")}] vs [${t.shape.join(",")}]`)}if(Re(t)){const c=D(e.data.length),u=t;for(let h=0;h<c.length;h++)c[h]=n(e.data[h],u);return A.tensor(c,e.shape)}}if(ce(t)&&t.data.length>1&&Re(e)){const c=D(t.data.length),u=e;for(let h=0;h<c.length;h++)c[h]=n(u,t.data[h]);return A.tensor(c,t.shape)}const i=o1(e),s=o1(t);if(i.scalar&&s.scalar){const c=i.isComplex?i.re:i.value,u=s.isComplex?s.re:s.value;return A.num(n(c,u))}if(i.scalar&&!s.scalar){const c=s.tensor,u=D(c.data.length),h=i.isComplex?i.re:i.value;for(let f=0;f<u.length;f++)u[f]=n(h,c.data[f]);return A.tensor(u,c.shape)}if(!i.scalar&&s.scalar){const c=i.tensor,u=D(c.data.length),h=s.isComplex?s.re:s.value;for(let f=0;f<u.length;f++)u[f]=n(c.data[f],h);return A.tensor(u,c.shape)}const o=i.tensor,a=s.tensor;if(o.data.length===a.data.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=D(o.data.length);for(let u=0;u<c.length;u++)c[u]=n(o.data[u],a.data[u]);return A.tensor(c,o.shape)}const l=Zu(o.shape,a.shape);if(l!==null)return iz(o,a,l,n,r);throw new q(`Matrix dimensions must agree: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}function vde(e,t){if(ce(e)&&e.data.length>1){const i=D(e.data.length);for(let s=0;s<i.length;s++)i[s]=t(e.data[s]);return A.tensor(i,e.shape)}const n=o1(e);if(n.scalar){const i=n.isComplex?n.re:n.value;return A.num(t(i))}const r=D(n.tensor.data.length);for(let i=0;i<r.length;i++)r[i]=t(n.tensor.data[i]);return A.tensor(r,n.tensor.shape)}function I1(e,t,n,r){const i=o1(e),s=o1(t);if(i.scalar&&s.scalar){const c=i.isComplex?i.re:i.value,u=s.isComplex?s.re:s.value;return A.logical(n(c,u))}if(i.scalar&&!s.scalar){const c=i.isComplex?i.re:i.value,u=s.tensor.data.length;if(s.tensor.data instanceof Float64Array){const d=D(u);ho.realScalarComparison(r,u,c,s.tensor.data,!0,d);const p=A.tensor(d,s.tensor.shape);return p._isLogical=!0,p}const h=D(u);for(let d=0;d<u;d++)h[d]=n(c,s.tensor.data[d])?1:0;const f=A.tensor(h,s.tensor.shape);return f._isLogical=!0,f}if(!i.scalar&&s.scalar){const c=s.isComplex?s.re:s.value,u=i.tensor.data.length;if(i.tensor.data instanceof Float64Array){const d=D(u);ho.realScalarComparison(r,u,c,i.tensor.data,!1,d);const p=A.tensor(d,i.tensor.shape);return p._isLogical=!0,p}const h=D(u);for(let d=0;d<u;d++)h[d]=n(i.tensor.data[d],c)?1:0;const f=A.tensor(h,i.tensor.shape);return f._isLogical=!0,f}const o=i.tensor,a=s.tensor;if(o.data.length===a.data.length&&o.shape.length===a.shape.length&&o.shape.every((c,u)=>c===a.shape[u])){const c=o.data.length;if(o.data instanceof Float64Array&&a.data instanceof Float64Array){const f=D(c);ho.realComparison(r,c,o.data,a.data,f);const d=A.tensor(f,o.shape);return d._isLogical=!0,d}const u=D(c);for(let f=0;f<c;f++)u[f]=n(o.data[f],a.data[f])?1:0;const h=A.tensor(u,o.shape);return h._isLogical=!0,h}const l=Zu(o.shape,a.shape);if(l!==null)return _de(o,a,l,n);throw new q(`Matrix dimensions must agree for comparison: [${o.shape.join(",")}] vs [${a.shape.join(",")}]`)}function Vc(e){return ce(e)&&e.data.length===1?e.imag&&e.imag[0]!==0?A.complex(e.data[0],e.imag[0]):A.num(e.data[0]):e}function tV(e,t){const[n,r]=Bn(e),[i,s]=Bn(t);if(r!==i)throw new q(`Inner matrix dimensions must agree: ${r} vs ${i}`);if(n===0||r===0||s===0)return A.tensor(D(n*s),[n,s]);if(!(e.imag!==void 0||t.imag!==void 0)){const d=Ds("matmul","matmul"),p=e.data instanceof Float64Array?e.data:D(e.data),m=t.data instanceof Float64Array?t.data:D(t.data),y=d.matmul(p,n,r,m,s);return Vc(A.tensor(y,[n,s]))}const a=e.imag||D(e.data.length),l=t.imag||D(t.data.length),c=Ds("matmul","matmulComplex");if(c.matmulComplex){const d=e.data instanceof Float64Array?e.data:D(e.data),p=a instanceof Float64Array?a:D(a),m=t.data instanceof Float64Array?t.data:D(t.data),y=l instanceof Float64Array?l:D(l),_=c.matmulComplex(d,p,n,r,m,y,s);return Vc(A.tensor(_.re,[n,s],_.im))}const u=D(n*s),h=D(n*s);for(let d=0;d<n;d++)for(let p=0;p<s;p++){let m=0,y=0;for(let b=0;b<r;b++){const x=gn(d,b,n),S=gn(b,p,i),M=e.data[x],E=a[x],T=t.data[S],k=l[S];m+=M*T-E*k,y+=M*k+E*T}const _=gn(d,p,n);u[_]=m,h[_]=y}const f=h.every(d=>d===0);return Vc(A.tensor(u,[n,s],f?void 0:h))}const bde="__COLON__";function Ni(e){return mt(e)&&e==="__COLON__"}function zu(e){if(Re(e))return{re:e,im:0};if(Tt(e))return{re:e?1:0,im:0};if(Ht(e))return{re:e.re,im:e.im};if(ce(e)&&e.data.length===1)return{re:e.data[0],im:e.imag?e.imag[0]:0};if(Dt(e)&&e.m===1&&e.n===1){const t=e.pr.length>0?e.pr[0]:0,n=e.pi&&e.pi.length>0?e.pi[0]:0;return{re:t,im:n}}throw new q(`Cannot convert ${po(e)} to number for assignment`)}function sz(e){const t=e.shape?e.shape[0]:1,n=e.shape?e.shape[1]:e.value.length,r=D(t*n);for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[s*t+i]=e.value.charCodeAt(i*n+s);return A.tensor(r,[t,n])}function xde(e){const t=e.shape.length>=2?e.shape[0]??0:1,n=e.shape.length>=2?e.shape[1]??0:e.data.length;let r="";for(let i=0;i<t;i++)for(let s=0;s<n;s++)r+=String.fromCharCode(Math.round(e.data[s*t+i]));return t>1?new Sf(r,[t,n]):A.char(r)}function jo(e){e.imag||(e.imag=D(e.data.length))}function D2(e,t){if(e.imag!==void 0){const n=e.imag[t];return n===0?A.num(e.data[t]):A.complex(e.data[t],n)}return e._isLogical===!0?e.data[t]!==0:A.num(e.data[t])}function Ao(e,t,n=t){if(Ni(e))return Array.from({length:t},(i,s)=>s);if(Tt(e))return e?[0]:[];if(ce(e)){if(e._isLogical){const i=[];for(let s=0;s<e.data.length;s++)e.data[s]!==0&&i.push(s);return i}return Array.from(e.data).map(i=>{const s=Math.round(i)-1;if(s<0||n>0&&s>=n)throw new q("Index exceeds array bounds");return s})}const r=Math.round(Ne(e))-1;if(r<0||n>0&&r>=n)throw new q("Index exceeds array bounds");return[r]}function wde(e,t,n,r){return{rowIndices:Ao(e,n),colIndices:Ao(t,r)}}function N2(e,t,n){const[r,i]=Bn(e);if(t<=r&&n<=i)return e;const s=Math.max(r,t),o=Math.max(i,n),a=D(s*o),c=e.imag!==void 0?D(s*o):void 0;for(let u=0;u<i;u++)for(let h=0;h<r;h++)a[h+u*s]=e.data[h+u*r],c&&e.imag&&(c[h+u*s]=e.imag[h+u*r]);return A.tensor(a,[s,o],c)}function Sde(e,t,n,r,i){if(ce(r)){const s=t.length,o=n.length;if(r.data.length===1){const d=r.data[0],p=r.imag?r.imag[0]:0;(p!==0||e.imag)&&jo(e);for(const m of t)for(const y of n){const _=gn(m,y,i);e.data[_]=d,e.imag&&(e.imag[_]=p)}return}const[a,l]=Bn(r),c=a===s&&l===o,u=s===1||o===1,h=a===1||l===1,f=r.data.length===s*o;if(!c&&!(u&&h&&f))throw new q("Subscripted assignment dimension mismatch");if((r.imag||e.imag)&&jo(e),c)for(let d=0;d<s;d++)for(let p=0;p<o;p++){const m=gn(t[d],n[p],i),y=gn(d,p,a);e.data[m]=r.data[y],e.imag&&(e.imag[m]=r.imag?r.imag[y]:0)}else{let d=0;for(let p=0;p<o;p++)for(let m=0;m<s;m++){const y=gn(t[m],n[p],i);e.data[y]=r.data[d],e.imag&&(e.imag[y]=r.imag?r.imag[d]:0),d++}}}else{const{re:s,im:o}=zu(r);(o!==0||e.imag)&&jo(e);for(const a of t)for(const l of n){const c=gn(a,l,i);e.data[c]=s,e.imag&&(e.imag[c]=o)}}}function Mde(e,t){if(Re(e)||Tt(e)||Ht(e))return new Array(t).fill(e);if(ce(e)){const n=[];for(let r=0;r<t;r++)e.imag?n.push(A.complex(e.data[r],e.imag[r])):n.push(A.num(e.data[r]));return n}return new Array(t).fill(e)}function MT(e,t,n){for(let r=e.jc[n];r<e.jc[n+1];r++)if(e.ir[r]===t)return{re:e.pr[r],im:e.pi?e.pi[r]:0};return{re:0,im:0}}function Ede(e,t,n){const r=t.length,i=n.length,s=new Map;for(let h=0;h<r;h++){const f=t[h],d=s.get(f);d?d.push(h):s.set(f,[h])}const o=e.pi!==void 0,a=[],l=[],c=[],u=new Int32Array(i+1);for(let h=0;h<i;h++){const f=n[h];u[h]=a.length;const d=[];for(let p=e.jc[f];p<e.jc[f+1];p++){const m=s.get(e.ir[p]);if(m!==void 0){const y=e.pr[p],_=o?e.pi[p]:0;for(const b of m)d.push({newRow:b,re:y,im:_})}}d.sort((p,m)=>p.newRow-m.newRow);for(const p of d)a.push(p.newRow),l.push(p.re),o&&c.push(p.im)}return u[i]=a.length,A.sparseMatrix(r,i,new Int32Array(a),u,D(l),o?D(c):void 0)}function nV(e,t,n){if(t.length===1){const y=e.m*e.n,_=Ao(t[0],y),b=_.map(E=>E%e.m),x=_.map(E=>Math.floor(E/e.m));let S=e;const M=Mde(n,_.length);for(let E=0;E<_.length;E++)S=nV(S,[A.num(b[E]+1),A.num(x[E]+1)],M[E]);return S}if(t.length!==2)throw new q("Sparse matrix assignment requires 1 or 2 indices");const r=Ao(t[0],e.m),i=Ao(t[1],e.n),s=r.length,o=i.length,a=D(s*o),l=D(s*o);let c=!1;if(Re(n))a.fill(n);else if(Tt(n))a.fill(n?1:0);else if(Ht(n))a.fill(n.re),l.fill(n.im),c=n.im!==0;else if(ce(n)){for(let y=0;y<n.data.length;y++)a[y]=n.data[y];if(n.imag){for(let y=0;y<n.imag.length;y++)l[y]=n.imag[y];c=!0}}else if(Dt(n))for(let y=0;y<n.n;y++)for(let _=n.jc[y];_<n.jc[y+1];_++){const b=y*s+n.ir[_];a[b]=n.pr[_],n.pi&&(l[b]=n.pi[_],c=!0)}else throw new q("Cannot assign non-numeric value into sparse matrix");const u=e.pi!==void 0||c,h=new Map;for(let y=0;y<e.n;y++){const _=[];for(let b=e.jc[y];b<e.jc[y+1];b++)_.push({row:e.ir[b],re:e.pr[b],im:e.pi?e.pi[b]:0});_.length>0&&h.set(y,_)}for(let y=0;y<o;y++){const _=i[y];let b=h.get(_);b||(b=[],h.set(_,b));for(let x=0;x<s;x++){const S=r[x],M=a[y*s+x],E=l[y*s+x];let T=!1;for(let k=0;k<b.length;k++)if(b[k].row===S){M===0&&E===0?b.splice(k,1):(b[k].re=M,b[k].im=E),T=!0;break}!T&&(M!==0||E!==0)&&b.push({row:S,re:M,im:E})}b.sort((x,S)=>x.row-S.row),b.length===0&&h.delete(_)}const f=[],d=[],p=[],m=new Int32Array(e.n+1);for(let y=0;y<e.n;y++){m[y]=f.length;const _=h.get(y);if(_)for(const b of _)f.push(b.row),d.push(b.re),u&&p.push(b.im)}return m[e.n]=f.length,A.sparseMatrix(e.m,e.n,new Int32Array(f),m,D(d),u?D(p):void 0)}function Cde(e,t){if(t.length===1){const n=t[0];if(Ni(n)){const r=e.m*e.n,i=[],s=[],o=[],a=e.pi!==void 0;for(let c=0;c<e.n;c++)for(let u=e.jc[c];u<e.jc[c+1];u++){const h=c*e.m+e.ir[u];i.push(h),s.push(e.pr[u]),a&&o.push(e.pi[u])}const l=new Int32Array([0,i.length]);return A.sparseMatrix(r,1,new Int32Array(i),l,D(s),a?D(o):void 0)}if(Re(n)){const r=Math.round(n)-1;if(r<0||r>=e.m*e.n)throw new q("Index exceeds array bounds");const i=Math.floor(r/e.m),s=r%e.m,o=MT(e,s,i);return e.pi!==void 0&&o.im!==0?A.complex(o.re,o.im):o.re}if(ce(n)||Tt(n)){const r=e.m*e.n,i=Ao(n,r),s=i.length,o=e.pi!==void 0,a=[],l=[],c=[],u=new Int32Array(s+1);for(let h=0;h<s;h++){u[h]=a.length;const f=i[h],d=Math.floor(f/e.m),p=f%e.m,m=MT(e,p,d);(m.re!==0||m.im!==0)&&(a.push(0),l.push(m.re),o&&c.push(m.im))}return u[s]=a.length,A.sparseMatrix(1,s,new Int32Array(a),u,D(l),o?D(c):void 0)}}if(t.length===2){if(Ni(t[0])){const i=Ao(t[1],e.n);if(i.length===1){const h=i[0],f=e.jc[h],p=e.jc[h+1]-f,m=new Int32Array(p),y=D(p);let _;for(let x=0;x<p;x++)m[x]=e.ir[f+x],y[x]=e.pr[f+x];if(e.pi!==void 0){_=D(p);for(let x=0;x<p;x++)_[x]=e.pi[f+x]}const b=new Int32Array([0,p]);return A.sparseMatrix(e.m,1,m,b,y,_)}const s=i.length,o=e.pi!==void 0,a=[],l=[],c=[],u=new Int32Array(s+1);for(let h=0;h<s;h++){u[h]=a.length;const f=i[h];for(let d=e.jc[f];d<e.jc[f+1];d++)a.push(e.ir[d]),l.push(e.pr[d]),o&&c.push(e.pi[d])}return u[s]=a.length,A.sparseMatrix(e.m,s,new Int32Array(a),u,D(l),o?D(c):void 0)}const n=Ao(t[0],e.m),r=Ao(t[1],e.n);if(n.length===1&&r.length===1){const i=MT(e,n[0],r[0]);return e.pi!==void 0&&i.im!==0?A.complex(i.re,i.im):i.re}return Ede(e,n,r)}throw new q("Sparse matrix supports 1 or 2 index dimensions")}function Ade(e,t){if(t.some(l=>ce(l)&&l.data.length===0)){if(t.length===2){const c=u=>Ni(u)?1:ce(u)?u.data.length:1;return A.tensor(D(0),[c(t[0]),c(t[1])])}const l=t[0];if(ce(l)){const u=l.shape.length===2&&l.shape[0]===0&&l.shape[1]===0?[0,0]:[...l.shape];return A.tensor(D(0),u)}}if(t.length===1){const l=t[0];if(Tt(l))return l?e:A.tensor(D(0),[0,0]);if(ce(l)&&l._isLogical){let c=0;for(let h=0;h<l.data.length;h++)l.data[h]&&c++;if(c===0)return A.tensor(D(0),[0,0]);const u=D(c);if(u.fill(Re(e)?e:e.re),Ht(e)&&e.im!==0){const h=D(c);return h.fill(e.im),A.tensor(u,[1,c],h)}return A.tensor(u,[1,c])}}if(t.length===1&&ce(t[0])){const l=t[0];for(let f=0;f<l.data.length;f++)if(Math.round(l.data[f])!==1)throw new q("Index exceeds array bounds");const c=l.data.length,u=Re(e)?e:e.re,h=D(c);if(h.fill(u),Ht(e)&&e.im!==0){const f=D(c);return f.fill(e.im),A.tensor(h,[...l.shape],f)}return A.tensor(h,[...l.shape])}const n=[];let r=!1;for(const l of t)if(Ni(l))n.push(1);else if(ce(l)){r=!0;for(let c=0;c<l.data.length;c++)if(Math.round(l.data[c])!==1)throw new q("Index exceeds array bounds");n.push(l.data.length)}else{if(Math.round(Ne(l))!==1)throw new q("Index exceeds array bounds");n.push(1)}if(!r)return e;const i=n.reduce((l,c)=>l*c,1),s=Re(e)?e:e.re,o=D(i);o.fill(s);const a=n.length>=2?n:[n[0],1];if(Ht(e)&&e.im!==0){const l=D(i);return l.fill(e.im),A.tensor(o,a,l)}return A.tensor(o,a)}function Tde(e,t){if(t.length===1)return kde(e,t[0]);if(e.shape.length>t.length){const n=[];for(let s=0;s<t.length-1;s++)n.push(e.shape[s]);let r=1;for(let s=t.length-1;s<e.shape.length;s++)r*=e.shape[s];n.push(r);const i=e.shape;e.shape=n;try{return t.length===2?oz(e,t[0],t[1]):az(e,t)}finally{e.shape=i}}return t.length===2?oz(e,t[0],t[1]):az(e,t)}function kde(e,t){if(Ni(t)){const n=e.imag?D(e.imag):void 0,r=A.tensor(D(e.data),[e.data.length,1],n);return e._isLogical===!0&&(r._isLogical=!0),r}if(Tt(t))return t?D2(e,0):A.tensor(D(0),[0,0]);if(Re(t)){const n=Math.round(Ne(t))-1;if(n<0||n>=e.data.length)throw new q("Index exceeds array bounds");return D2(e,n)}if(ce(t))return Bde(e,t);throw new q("Invalid index type for tensor")}function oz(e,t,n){const[r,i]=Bn(e),s=e._isLogical===!0,o=d=>(s&&ce(d)&&(d._isLogical=!0),d);if(Re(t)&&Ni(n)){const d=Math.round(t)-1;if(d<0||d>=r)throw new q("Index exceeds array bounds");const p=D(i),m=e.imag?D(i):void 0;for(let y=0;y<i;y++)p[y]=e.data[d+y*r],m&&e.imag&&(m[y]=e.imag[d+y*r]);return o(A.tensor(p,[1,i],m))}if(Ni(t)&&Re(n)){const d=Math.round(n)-1;if(d<0||d>=i)throw new q("Index exceeds array bounds");const p=d*r,m=D(r);for(let _=0;_<r;_++)m[_]=e.data[p+_];const y=e.imag?D(r):void 0;if(y&&e.imag)for(let _=0;_<r;_++)y[_]=e.imag[p+_];return o(A.tensor(m,[r,1],y))}const a=Ao(t,r),l=Ao(n,i),c=a.length,u=l.length;if(c===1&&u===1){const d=gn(a[0],l[0],r);return D2(e,d)}const h=D(c*u),f=e.imag?D(c*u):void 0;for(let d=0;d<u;d++)for(let p=0;p<c;p++){const m=gn(a[p],l[d],r),y=gn(p,d,c);h[y]=e.data[m],f&&e.imag&&(f[y]=e.imag[m])}return o(A.tensor(h,[c,u],f))}function az(e,t){const n=e.shape,r=t.map((m,y)=>{const _=y<n.length?n[y]:1;return Ao(m,_)});if(r.every(m=>m.length===1)){const m=r.map(_=>_[0]),y=Jce(n,m);return D2(e,y)}const s=r.map(m=>m.length);for(;s.length>2&&s[s.length-1]===1;)s.pop();const o=s.reduce((m,y)=>m*y,1),a=D(o),l=e.imag?D(o):void 0,c=r.length,u=new Array(c);u[0]=1;for(let m=1;m<c;m++)u[m]=u[m-1]*(m-1<n.length?n[m-1]:1);const h=r.map((m,y)=>m.map(_=>_*u[y])),f=new Array(c).fill(0);let d=0;for(let m=0;m<c;m++)d+=h[m][0];for(let m=0;m<o;m++){a[m]=e.data[d],l&&e.imag&&(l[m]=e.imag[d]);for(let y=0;y<c;y++){const _=f[y];if(f[y]++,f[y]<r[y].length){d+=h[y][f[y]]-h[y][_];break}d-=h[y][_]-h[y][0],f[y]=0}}const p=A.tensor(a,s,l);return e._isLogical===!0&&(p._isLogical=!0),p}function Rde(e,t){if(t.length===1)return Dde(e,t[0]);if(t.length===2)return Nde(e,t[0],t[1]);throw new q("Cell indexing supports 1 or 2 dimensions")}function Dde(e,t){if(Ni(t))return A.cell([...e.data],[...e.shape]);if(ce(t)){const r=[];if(t._isLogical){for(let s=0;s<t.data.length;s++)if(t.data[s]!==0){if(s>=e.data.length)throw new q("Cell index exceeds bounds");r.push(e.data[s])}}else for(let s=0;s<t.data.length;s++){const o=Math.round(t.data[s])-1;if(o<0||o>=e.data.length)throw new q("Cell index exceeds bounds");r.push(e.data[o])}const i=t.shape.length<=2&&(t.shape[0]===1||t.shape.length===2&&t.shape[1]===1);return t._isLogical||i?e.shape[1]===1&&e.shape[0]>1?A.cell(r,[r.length,1]):A.cell(r,[1,r.length]):A.cell(r,[...t.shape])}const n=Math.round(Ne(t))-1;if(n<0||n>=e.data.length)throw new q("Cell index exceeds bounds");return A.cell([e.data[n]],[1,1])}function Nde(e,t,n){const r=e.shape[0],i=e.shape.length>=2?e.shape[1]:1,{rowIndices:s,colIndices:o}=wde(t,n,r,i);if(!Ni(t)&&!Ni(n)&&!ce(t)&&!ce(n)){const l=o[0]*r+s[0];if(l<0||l>=e.data.length)throw new q("Cell index exceeds bounds");return A.cell([e.data[l]],[1,1])}const a=[];for(let l=0;l<o.length;l++)for(let c=0;c<s.length;c++){const u=o[l]*r+s[c];if(u<0||u>=e.data.length)throw new q("Cell index exceeds bounds");a.push(e.data[u])}return A.cell(a,[s.length,o.length])}function Lde(e,t){const n=e.shape??(e.value.length===0?[0,0]:[1,e.value.length]),r=n[0],i=n[1]||0;if(t.length===1){const s=t[0];if(Ni(s))return e;if(ce(s)&&s._isLogical){let a="";for(let l=0;l<s.data.length;l++)if(s.data[l]!==0){if(l>=e.value.length)throw new q("Index exceeds char array length");a+=e.value[l]}return A.char(a)}if(ce(s)){let a="";for(let l=0;l<s.data.length;l++){const c=Math.round(s.data[l])-1;if(c<0||c>=e.value.length)throw new q("Index exceeds char array length");a+=e.value[c]}return A.char(a)}const o=Math.round(Ne(s))-1;if(o<0||o>=e.value.length)throw new q("Index exceeds char array length");return A.char(e.value[o])}if(t.length===2){const s=t[0],o=t[1],a=h=>{if(ce(h)&&h._isLogical){const f=[];for(let d=0;d<h.data.length;d++)h.data[d]!==0&&f.push(d);return f}return ce(h)?Array.from(h.data,f=>Math.round(f)-1):[Math.round(Ne(h))-1]},l=Ni(s)?Array.from({length:r},(h,f)=>f):a(s),c=Ni(o)?Array.from({length:i},(h,f)=>f):a(o);let u="";for(const h of l)for(const f of c){if(h<0||h>=r||f<0||f>=i)throw new q("Index exceeds char array dimensions");u+=e.value[h*i+f]}return l.length<=1?A.char(u):new Sf(u,[l.length,c.length])}throw new q("Char indexing supports 1 or 2 dimensions")}function im(e,t){if(Ni(e))return Array.from({length:t},(n,r)=>r);if(ce(e)){if(e._isLogical){const n=[];for(let r=0;r<e.data.length;r++)e.data[r]!==0&&n.push(r);return n}return Array.from(e.data,n=>Math.round(n)-1)}return Tt(e)?e?[0]:[]:[Math.round(Ne(e))-1]}function Ide(e,t){const[n,r]=e.shape,i=e.data.length;if(t.length===2){const c=im(t[0],n),u=im(t[1],r),h=[];for(const f of u){if(f<0||f>=r)throw new q("Index exceeds array bounds");for(const d of c){if(d<0||d>=n)throw new q("Index exceeds array bounds");h.push(e.data[f*n+d])}}return hs(h,[c.length,u.length])}if(t.length!==1)throw new q("String array indexing supports 1 or 2 subscripts");const s=t[0];if(Ni(s))return hs(e.data.slice(),[i,1]);const o=im(s,i),a=[];for(const c of o){if(c<0||c>=i)throw new q("Index exceeds array bounds");a.push(e.data[c])}let l;if(n===1||r===1)l=n===1?[1,a.length]:[a.length,1];else if(ce(s)&&!s._isLogical){const c=s.shape,u=c.length>=2?c[0]:1;l=[u,a.length/(u||1)]}else ce(s)&&s._isLogical?l=[a.length,1]:l=[1,a.length];return hs(a,l)}function Pde(e,t){if(t.length===1){const l=t[0];if(Ni(l))return e;if(ce(l)&&l.data.length===0)return A.tensor(D(0),[0,0]);if(ce(l)){for(let f=0;f<l.data.length;f++)if(Math.round(l.data[f])!==1)throw new q("Index exceeds array bounds");const u=D(l.data.length);u.fill(e?1:0);const h=A.tensor(u,[...l.shape]);return h._isLogical=!0,h}if(Tt(l))return l?e:A.tensor(D(0),[0,0]);if(Math.round(Ne(l))!==1)throw new q("Index exceeds array bounds");return e}const n=[];let r=!1;for(const l of t)if(Ni(l))n.push(1);else if(Tt(l)){if(!l)return A.tensor(D(0),[0,0]);n.push(1)}else if(ce(l)){r=!0;for(let c=0;c<l.data.length;c++)if(Math.round(l.data[c])!==1)throw new q("Index exceeds array bounds");n.push(l.data.length)}else{if(Math.round(Ne(l))!==1)throw new q("Index exceeds array bounds");n.push(1)}if(!r)return e;const i=n.reduce((l,c)=>l*c,1),s=D(i);s.fill(e?1:0);const o=n.length>=2?n:[n[0],1],a=A.tensor(s,o);return a._isLogical=!0,a}function Bde(e,t){const n=e._isLogical===!0;if(t._isLogical){const f=[],d=[],p=e.imag!==void 0;for(let x=0;x<t.data.length;x++)if(t.data[x]!==0){if(x>=e.data.length)throw new q("Index exceeds array bounds");f.push(e.data[x]),p&&d.push(e.imag[x])}if(f.length===1)return p&&d[0]!==0?A.complex(f[0],d[0]):n?f[0]!==0:A.num(f[0]);const m=p&&d.some(x=>x!==0)?D(d):void 0,_=e.shape.length===2&&e.shape[0]===1?[1,f.length]:[f.length,1],b=A.tensor(D(f),_,m);return n&&(b._isLogical=!0),b}const r=[],i=e.imag!==void 0,s=[];for(let f=0;f<t.data.length;f++){const d=Math.round(t.data[f])-1;if(d<0||d>=e.data.length)throw new q("Index exceeds array bounds");r.push(e.data[d]),i&&s.push(e.imag[d])}const o=t.data.length===0&&t.shape.length===2&&t.shape[0]===0&&t.shape[1]===0,a=e.data.length!==1&&e.shape.length<=2&&(e.shape[0]===1||e.shape[1]===1||e.shape.length===1),l=t.shape.length<=2&&(t.shape[0]===1||t.shape[1]===1||t.shape.length===1),c=o?[0,0]:a&&l?e.shape[0]===1?[1,r.length]:[r.length,1]:t.shape,u=i&&s.some(f=>f!==0)?D(s):void 0,h=A.tensor(D(r),c,u);return n&&(h._isLogical=!0),h}function rV(e,t){if(Re(e)||Ht(e))return Ade(e,t);if(ce(e))return Tde(e,t);if(nn(e))return Rde(e,t);if(lt(e))return Lde(e,t);if(mt(e)&&t.length===1){if(Math.round(Ne(t[0]))!==1)throw new q("Index exceeds string dimensions");return e}if(Wn(e))return Ide(e,t);if(Tt(e))return Pde(e,t);if(Zn(e)||In(e)){if(t.length>=1&&t.every(r=>Re(r)?Math.round(r)===1:Tt(r)?r===!0:ce(r)?r.data.length===1&&Math.round(r.data[0])===1:!1))return e;throw new q("Index exceeds struct dimensions")}if(Dt(e))return Cde(e,t);if(yi(e)){if(t.length===1){const n=t[0];if(Re(n)){const r=Math.round(n)-1;if(r<0||r>=e.elements.length)throw new q("Index exceeds struct array bounds");return e.elements[r]}if(ce(n)){const r=[];for(let i=0;i<n.data.length;i++){const s=Math.round(n.data[i])-1;if(s<0||s>=e.elements.length)throw new q("Index exceeds struct array bounds");r.push(e.elements[s])}return A.structArray(e.fieldNames,r)}if(Tt(n)){const r=n?0:-1;if(r<0||r>=e.elements.length)throw new q("Index exceeds struct array bounds");return e.elements[r]}throw new q("Invalid index type for struct array")}throw new q("Struct array only supports single-index access")}throw new q(`Cannot index into ${po(e)}`)}function Fde(e,t,n,r){if(ce(n)&&n.data.length===0&&t.length===1)return zde(e,t[0]);if(ce(n)&&n.data.length===0&&t.length===2){const i=e.shape[0]??1,s=e.shape.length>=2?e.shape[1]:1,o=Ni(t[0])?i:Ao(t[0],i).length,a=Ni(t[1])?s:Ao(t[1],s).length;return o===0||a===0?e:Ude(e,t)}if(_2(e)){const i=e.imag?D(e.imag):void 0,s=A.tensor(D(e.data),[...e.shape],i);s._isLogical=e._isLogical,e=s}if(t.length===1)return Ode(e,t[0],n);if(t.length===2)return Hde(e,t,n);if(t.length>=3)return Wde(e,t,n);throw new q("Invalid number of indices for tensor assignment")}function zde(e,t){const n=new Set;if(Re(t))n.add(Math.round(t)-1);else if(Tt(t))t&&n.add(0);else if(ce(t)&&t._isLogical)for(let u=0;u<t.data.length;u++)t.data[u]!==0&&n.add(u);else if(ce(t))for(let u=0;u<t.data.length;u++)n.add(Math.round(t.data[u])-1);else if(Ni(t)){const u=A.tensor(D(0),[0,0]);return u._isLogical=e._isLogical,u}if(n.size===0)return e;const r=[],i=[],s=e.imag!==void 0;for(let u=0;u<e.data.length;u++)n.has(u)||(r.push(e.data[u]),s&&i.push(e.imag[u]));const a=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]!==1?[r.length,1]:[1,r.length],l=s&&i.some(u=>u!==0)?D(i):void 0,c=A.tensor(D(r),a,l);return c._isLogical=e._isLogical,c}function lz(e,t){const n=new Set;if(Re(e))n.add(Math.round(e)-1);else if(Tt(e))e&&n.add(0);else if(ce(e)&&e._isLogical)for(let r=0;r<e.data.length;r++)e.data[r]!==0&&n.add(r);else if(ce(e))for(let r=0;r<e.data.length;r++)n.add(Math.round(e.data[r])-1);else if(Ni(e))for(let r=0;r<t;r++)n.add(r);return n}function Ude(e,t){const n=e.shape[0]??1,r=e.shape.length>=2?e.shape[1]:1,i=e.imag!==void 0;if(Ni(t[1])){const s=lz(t[0],n),o=Array.from({length:n},(h,f)=>f).filter(h=>!s.has(h)),a=o.length,l=D(a*r),c=i?D(a*r):void 0;for(let h=0;h<r;h++)for(let f=0;f<o.length;f++){const d=o[f]+h*n,p=f+h*a;l[p]=e.data[d],c&&e.imag&&(c[p]=e.imag[d])}const u=A.tensor(l,[a,r],c);return u._isLogical=e._isLogical,u}if(Ni(t[0])){const s=lz(t[1],r),o=Array.from({length:r},(h,f)=>f).filter(h=>!s.has(h)),a=o.length,l=D(n*a),c=i?D(n*a):void 0;for(let h=0;h<o.length;h++){const f=o[h];for(let d=0;d<n;d++){const p=d+f*n,m=d+h*n;l[m]=e.data[p],c&&e.imag&&(c[m]=e.imag[p])}}const u=A.tensor(l,[n,a],c);return u._isLogical=e._isLogical,u}throw new q("Cannot delete from both row and column dimensions")}function Ode(e,t,n){if(Ni(t)){if(ce(n))if(n.data.length===1)n=n.imag&&n.imag[0]!==0?A.complex(n.data[0],n.imag[0]):A.num(n.data[0]);else{if(n.data.length!==e.data.length)throw new q("Subscripted assignment dimension mismatch");return e.data.set(n.data),(n.imag||e.imag)&&(jo(e),n.imag?e.imag.set(n.imag):e.imag.fill(0)),e}const{re:o,im:a}=zu(n);return e.data.fill(o),(a!==0||e.imag)&&(jo(e),e.imag.fill(a)),e}if(ce(t))return jde(e,t,n);if(Tt(t)){if(!t)return e;const{re:o,im:a}=zu(n);if(e.data.length<1)throw new q("Index exceeds array bounds");return e.data[0]=o,(a!==0||e.imag)&&(jo(e),e.imag[0]=a),e}const{re:r,im:i}=zu(n),s=Math.round(Ne(t))-1;if(s<0)throw new q("Index exceeds array bounds");if(s>=e.data.length){const o=D(s+1);o.set(e.data),o[s]=r;let a;(i!==0||e.imag)&&(a=D(s+1),e.imag&&a.set(e.imag),a[s]=i);const l=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]>1;return A.tensor(o,l?[s+1,1]:[1,s+1],a)}return e.data[s]=r,(i!==0||e.imag)&&(jo(e),e.imag[s]=i),e}function jde(e,t,n){if(t._isLogical){ce(n)&&n.data.length===1&&(n=n.imag&&n.imag[0]!==0?A.complex(n.data[0],n.imag[0]):A.num(n.data[0]));const{re:o,im:a}=ce(n)?{re:null,im:null}:zu(n);let l=-1;for(let u=0;u<t.data.length;u++)t.data[u]!==0&&(l=u);if(l>=e.data.length){const u=l+1,h=D(u);h.set(e.data);let f;e.imag&&(f=D(u),f.set(e.imag));const p=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]>1?[u,1]:[1,u];e=A.tensor(h,p,f)}let c=0;for(let u=0;u<t.data.length;u++)t.data[u]!==0&&(ce(n)?(e.data[u]=n.data[c],(n.imag||e.imag)&&(jo(e),e.imag[u]=n.imag?n.imag[c]:0)):(e.data[u]=o,(a!==0||e.imag)&&(jo(e),e.imag[u]=a)),c++);if(ce(n)&&c!==n.data.length)throw new q("Subscripted assignment dimension mismatch");return e}let r=-1;for(let o=0;o<t.data.length;o++){const a=Math.round(t.data[o])-1;if(a<0)throw new q("Index exceeds array bounds");a>r&&(r=a)}if(r>=e.data.length){const o=r+1,a=D(o);a.set(e.data);let l;e.imag&&(l=D(o),l.set(e.imag));const u=e.shape.length>=2&&e.shape[1]===1&&e.shape[0]>1?[o,1]:[1,o];e=A.tensor(a,u,l)}if(ce(n)){if(t.data.length!==n.data.length)throw new q("Subscripted assignment dimension mismatch");(n.imag||e.imag)&&jo(e);for(let o=0;o<t.data.length;o++){const a=Math.round(t.data[o])-1;e.data[a]=n.data[o],e.imag&&(e.imag[a]=n.imag?n.imag[o]:0)}return e}const{re:i,im:s}=zu(n);(s!==0||e.imag)&&jo(e);for(let o=0;o<t.data.length;o++){const a=Math.round(t.data[o])-1;e.data[a]=i,e.imag&&(e.imag[a]=s)}return e}function Hde(e,t,n){const[r,i]=Bn(e),s=Ni(t[0]),o=Ni(t[1]),a=ce(t[0]),l=ce(t[1]);if(s&&o){if(ce(n)){if(n.data.length!==e.data.length)throw new q("Subscripted assignment dimension mismatch");return e.data.set(n.data),(n.imag||e.imag)&&(jo(e),n.imag?e.imag.set(n.imag):e.imag.fill(0)),e}const{re:m,im:y}=zu(n);return e.data.fill(m),(y!==0||e.imag)&&(jo(e),e.imag.fill(y)),e}if(s&&!o&&!l)return $de(e,t[1],n,r,i);if(!s&&!a&&o)return Vde(e,t[0],n,r,i);if(a||l){const m=e.data.length===0;let y=i,_=r;if(m&&ce(n)){const[T,k]=Bn(n);s&&!o&&(_=T),o&&!s&&(y=k)}const b=s?Array.from({length:_},(T,k)=>k):Ao(t[0],r,0),x=o?Array.from({length:y},(T,k)=>k):Ao(t[1],i,0),S=b.length>0?Math.max(...b)+1:_,M=x.length>0?Math.max(...x)+1:y;e=N2(e,S,M);const[E]=Bn(e);return Sde(e,b,x,n,E),e}if(Tt(t[0])&&!t[0]||Tt(t[1])&&!t[1])return e;const{re:c,im:u}=zu(n),h=Tt(t[0])?0:Math.round(Ne(t[0]))-1,f=Tt(t[1])?0:Math.round(Ne(t[1]))-1;if(h<0||f<0)throw new q("Index exceeds array bounds");e=N2(e,h+1,f+1);const[d]=Bn(e),p=gn(h,f,d);return e.data[p]=c,(u!==0||e.imag)&&(jo(e),e.imag[p]=u),e}function L2(e,t,n){if(ce(n)){if(n.data.length!==t.length)throw new q("Subscripted assignment dimension mismatch");(n.imag||e.imag)&&jo(e);for(let r=0;r<t.length;r++)e.data[t[r]]=n.data[r],e.imag&&(e.imag[t[r]]=n.imag?n.imag[r]:0)}else{const{re:r,im:i}=zu(n);(i!==0||e.imag)&&jo(e);for(const s of t)e.data[s]=r,e.imag&&(e.imag[s]=i)}}function $de(e,t,n,r,i){if(Tt(t)){if(!t)return e;const u=Array.from({length:r},(h,f)=>gn(f,0,r));return L2(e,u,n),e}const s=Math.round(Ne(t))-1;if(s<0)throw new q("Index exceeds array bounds");let o=r,a=i;if(o===0&&ce(n)&&n.data.length>0){o=n.data.length;const u=s+1;e=A.tensor(D(o*u),[o,u]),a=u}else if(o===0&&(Re(n)||Tt(n))){o=1;const u=s+1;e=A.tensor(D(o*u),[o,u]),a=u}s>=a&&(e=N2(e,o,s+1));const[l]=Bn(e),c=Array.from({length:l},(u,h)=>gn(h,s,l));return L2(e,c,n),e}function Vde(e,t,n,r,i){if(Tt(t)){if(!t)return e;const h=Array.from({length:i},(f,d)=>gn(0,d,r));return L2(e,h,n),e}const s=Math.round(Ne(t))-1;if(s<0)throw new q("Index exceeds array bounds");let o=r,a=i;if(a===0&&ce(n)&&n.data.length>0){a=n.data.length;const h=s+1;e=A.tensor(D(h*a),[h,a]),o=h}else if(a===0&&(Re(n)||Tt(n))){a=1;const h=s+1;e=A.tensor(D(h*a),[h,a]),o=h}s>=o&&(e=N2(e,s+1,a));const[l,c]=Bn(e),u=Array.from({length:c},(h,f)=>gn(s,f,l));return L2(e,u,n),e}function Wde(e,t,n){let r=[...e.shape];const i=ce(n)?n:null,s=i?i.shape:null;let o=0;const a=t.map((y,_)=>{const b=_<r.length?r[_]:1;if(Ni(y)){if((b===0||_>=r.length)&&s){const S=o<s.length?s[o]:1;return o++,Array.from({length:S},(M,E)=>E)}return o++,Array.from({length:b},(S,M)=>M)}return Ao(y,b,0)}),l=[...r];for(;l.length<t.length;)l.push(1);let c=!1;for(let y=0;y<a.length;y++)for(const _ of a[y])_>=l[y]&&(l[y]=_+1,c=!0);if(c||e.data.length===0){const y=l.reduce((x,S)=>x*S,1),_=D(y),b=e.imag?D(y):void 0;if(e.data.length>0){const x=[...r];for(;x.length<l.length;)x.push(1);const S=e.data.length,M=x.length,E=new Array(M);E[0]=1;for(let R=1;R<M;R++)E[R]=E[R-1]*l[R-1];const T=new Array(M).fill(0);let k=0;for(let R=0;R<S;R++){_[k]=e.data[R],b&&e.imag&&(b[k]=e.imag[R]);for(let B=0;B<M&&(T[B]++,k+=E[B],!(T[B]<x[B]));B++)k-=T[B]*E[B],T[B]=0}}for(;l.length>2&&l[l.length-1]===1;)l.pop();e=A.tensor(_,l,b),r=l}const h=a.map(y=>y.length).reduce((y,_)=>y*_,1),f=a.length,d=new Array(f);d[0]=1;for(let y=1;y<f;y++)d[y]=d[y-1]*(y-1<r.length?r[y-1]:1);const p=a.map((y,_)=>y.map(b=>b*d[_])),m=y=>{const _=new Array(f).fill(0);let b=0;for(let x=0;x<f;x++)b+=p[x][0];for(let x=0;x<h;x++){y(b,x);for(let S=0;S<f;S++){const M=_[S];if(_[S]++,_[S]<a[S].length){b+=p[S][_[S]]-p[S][M];break}b-=p[S][M]-p[S][0],_[S]=0}}};if(ce(n)){if(n.data.length!==h)throw new q("Subscripted assignment dimension mismatch");const y=n.imag!==void 0;(y||e.imag)&&jo(e),m((_,b)=>{e.data[_]=n.data[b],e.imag&&(e.imag[_]=y?n.imag[b]:0)})}else{const{re:y,im:_}=zu(n);(_!==0||e.imag)&&jo(e),m(b=>{e.data[b]=y,e.imag&&(e.imag[b]=_)})}return e}function qde(e,t,n,r=!1,i){_2(e)&&(e=A.cell(e.data.slice(),[...e.shape]));const s=o=>{const a=e,l=a.data.length;if(l===o)return;const c=a.shape[0]>1&&a.shape[1]===1;a.shape=c?[l,1]:[1,l]};if(t.length===1)return Gde(e,t[0],n,s,r,i);if(t.length===2)return Xde(e,t,n,r,i);throw new q("Cannot index-assign into cell")}function ET(e,t){const n=A.tensor(D(0),[0,0]);t&&n.incref(),e.data.push(n)}function Xp(e,t,n,r){r?e.bindElement(r,t,n):e.data[t]=n}function Gde(e,t,n,r,i=!1,s){if(Ni(t)){const c=e.data.length;if(c===1&&!nn(n))return Xp(e,0,n,s),e;if(!nn(n)||n.data.length!==c&&n.data.length!==1)throw new q("Subscripted assignment dimension mismatch");const u=n.data.length===1;for(let h=0;h<c;h++)Xp(e,h,u?n.data[0]:n.data[h],s);return e}if(ce(t)){let c;if(t._isLogical){c=[];for(let d=0;d<t.data.length;d++)t.data[d]!==0&&c.push(d)}else c=Array.from(t.data).map(d=>Math.round(d)-1);if(c.length===1&&!nn(n)){const d=c[0];if(d<0)throw new q("Cell index exceeds bounds");const p=e.data.length;for(;e.data.length<=d;)ET(e,s);return Xp(e,d,n,s),r(p),e}if(!nn(n)||n.data.length!==c.length&&n.data.length!==1)throw new q("Subscripted assignment dimension mismatch");const u=n.data.length===1,h=e.data.length;let f=-1;for(let d=0;d<c.length;d++){const p=c[d];if(p<0)throw new q("Cell index exceeds bounds");p>f&&(f=p)}for(;e.data.length<=f;)ET(e,s);for(let d=0;d<c.length;d++){const p=c[d];Xp(e,p,u?n.data[0]:n.data[d],s)}return r(h),e}const o=Math.round(Ne(t))-1;if(o<0)throw new q("Cell index exceeds bounds");const a=e.data.length;if(o>=e.data.length)for(;e.data.length<=o;)ET(e,s);const l=i&&nn(n)&&n.data.length===1?n.data[0]:n;return Xp(e,o,l,s),r(a),e}function Xde(e,t,n,r=!1,i){let s=e.shape[0],o=e.shape.length>=2?e.shape[1]:1;const a=Ao(t[0],s,0),l=Ao(t[1],o,0),c=Math.max(...a)+1,u=Math.max(...l)+1,h=Math.max(s,c),f=Math.max(o,u);if(h>s||f>o){const y=new Array(h*f);for(let _=0;_<y.length;_++){const b=A.tensor(D(0),[0,0]);i&&b.incref(),y[_]=b}for(let _=0;_<o;_++)for(let b=0;b<s;b++){const x=y[_*h+b];y[_*h+b]=e.data[_*s+b],i&&Ho(i,x)}e.data=y,e.shape=[h,f],s=h,o=f}const d=a.length,p=l.length,m=d*p;if(r&&nn(n)){if(n.data.length!==m&&n.data.length!==1)throw new q("Subscripted assignment dimension mismatch");const y=n.data.length===1;let _=0;for(let b=0;b<p;b++)for(let x=0;x<d;x++){const S=l[b]*s+a[x];Xp(e,S,y?n.data[0]:n.data[_++],i)}}else{const y=l[0]*s+a[0];Xp(e,y,n,i)}return e}function Q_(e,t,n,r=!1,i){if(Dt(e))return nV(e,t,n);if(Dt(n)&&ce(e)){const s=n,o=D(s.m*s.n),a=s.pi?D(s.m*s.n):void 0;for(let l=0;l<s.n;l++)for(let c=s.jc[l];c<s.jc[l+1];c++){const u=l*s.m+s.ir[c];o[u]=s.pr[c],a&&s.pi&&(a[u]=s.pi[c])}n=A.tensor(o,[s.m,s.n],a)}if(ce(e))return Fde(e,t,n);if(nn(e))return qde(e,t,n,r,i);throw new q(`Cannot index-assign into ${po(e)}`)}function a1(e,t,n){let r;if(t>0||t<0?r=Math.max(0,Math.floor((n-e)/t+1+1e-10)):r=0,r===0)return A.tensor(D(0),[1,0]);const i=D(r);for(let s=0;s<r;s++)i[s]=e+s*t;if(r>1){const s=e+(r-1)*t,o=Math.abs(t);Math.abs(s-n)<o*1e-10&&(i[r-1]=n)}return A.tensor(i,[1,r])}function wb(...e){if(e.length===0)return A.tensor(D(0),[0,0]);if(e.length===1)return e[0];if(e.some(t=>Dt(t)))return oV(e,1);if(e.some(t=>nn(t)))return lV(e,1);if(e.some(t=>mt(t)||Wn(t)))return iV(e,1);if(e.some(t=>lt(t))){let t="";for(const n of e)if(lt(n))t+=n.value;else if(Re(n))t+=String.fromCharCode(Math.round(n));else throw new q(`Cannot concatenate ${po(n)} into char`);return A.char(t)}return e.some(t=>Zn(t)||yi(t))?sV(e):aV(e,1)}function fI(...e){return e.length===0?A.tensor(D(0),[0,0]):e.length===1?e[0]:e.some(t=>Dt(t))?oV(e,0):e.some(t=>nn(t))?lV(e,0):e.some(t=>mt(t)||Wn(t))?iV(e,0):e.some(t=>lt(t))?Kde(e):e.some(t=>Zn(t)||yi(t))?sV(e):aV(e,0)}function Yde(e){if(mt(e))return{data:[e],rows:1,cols:1};if(Wn(e))return e.data.length===0?null:{data:e.data.slice(),rows:e.shape[0],cols:e.shape[1]};if(lt(e)){const t=e.shape?e.shape[0]:1,n=e.shape?e.shape[1]:e.value.length;if(t<=1)return{data:[e.value],rows:1,cols:1};const r=[];for(let i=0;i<t;i++)r.push(e.value.slice(i*n,(i+1)*n));return{data:r,rows:t,cols:1}}if(Re(e))return{data:[Tv(e)],rows:1,cols:1};if(Tt(e))return{data:[e?"true":"false"],rows:1,cols:1};if(ce(e)){if(e.data.length===0)return null;const t=e.shape.length>=2?e.shape[0]:1,n=e.data.length/(t||1),r=[];for(let i=0;i<e.data.length;i++)r.push(e._isLogical?e.data[i]?"true":"false":Tv(e.data[i]));return{data:r,rows:t,cols:n}}throw new q(`Cannot concatenate ${po(e)} into string array`)}function iV(e,t){const n=[];for(const a of e){const l=Yde(a);l&&n.push(l)}if(n.length===0)return A.stringArray([],[0,0]);if(t===1){const a=n[0].rows;let l=0;for(const u of n){if(u.rows!==a)throw new q("Dimensions of arrays being concatenated are not consistent");l+=u.cols}const c=[];for(const u of n)c.push(...u.data);return hs(c,[a,l])}const r=n[0].cols;let i=0;for(const a of n){if(a.cols!==r)throw new q("Dimensions of arrays being concatenated are not consistent");i+=a.rows}const s=new Array(i*r);let o=0;for(const a of n){for(let l=0;l<r;l++)for(let c=0;c<a.rows;c++)s[l*i+o+c]=a.data[l*a.rows+c];o+=a.rows}return hs(s,[i,r])}function Kde(e){let t=null,n=0,r="";for(const i of e){let s,o,a;if(lt(i))s=i.shape?i.shape[0]:1,o=i.shape?i.shape[1]:i.value.length,a=i.value;else if(mt(i))s=1,o=i.length,a=i;else if(Re(i))s=1,o=1,a=String.fromCharCode(Math.round(i));else if(ce(i)){const l=i,c=l.shape[0]??0,u=l.shape[1]??0;s=c,o=u;let h="";for(let f=0;f<c;f++)for(let d=0;d<u;d++)h+=String.fromCharCode(Math.round(l.data[d*c+f]));a=h}else throw new q(`Cannot concatenate ${po(i)} into char`);if(t===null)t=o;else if(o!==t)throw new q("Dimensions of arrays being concatenated are not consistent");n+=s,r+=a}return n<=1?A.char(r):new Sf(r,[n,t??0])}function sV(e){const t=[];let n=null;for(const r of e)if(Zn(r)){const i=Array.from(r.fields.keys());if(n===null)n=i;else if(!cz(n,i))throw new q("Cannot concatenate structs with different field names");t.push(r)}else if(yi(r)){if(n===null)n=[...r.fieldNames];else if(!cz(n,r.fieldNames))throw new q("Cannot concatenate struct arrays with different field names");for(const i of r.elements)t.push(i)}else{if(ce(r)&&r.data.length===0&&r.shape.every(i=>i===0))continue;throw new q(`Cannot concatenate ${po(r)} into struct`)}return n===null&&(n=[]),A.structArray(n,t)}function cz(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Zde(e){if(Dt(e))return e;if(Re(e))return e===0?A.sparseMatrix(1,1,new Int32Array(0),new Int32Array([0,0]),D(0)):A.sparseMatrix(1,1,new Int32Array([0]),new Int32Array([0,1]),D([e]));if(Tt(e)){const t=e?1:0;return t===0?A.sparseMatrix(1,1,new Int32Array(0),new Int32Array([0,0]),D(0)):A.sparseMatrix(1,1,new Int32Array([0]),new Int32Array([0,1]),D([t]))}if(Ht(e))return e.re===0&&e.im===0?A.sparseMatrix(1,1,new Int32Array(0),new Int32Array([0,0]),D(0)):A.sparseMatrix(1,1,new Int32Array([0]),new Int32Array([0,1]),D([e.re]),e.im!==0?D([e.im]):void 0);if(ce(e)){const t=e.shape[0]??1,n=e.shape.length>=2?e.shape[1]:1,r=e.imag!==void 0,i=[],s=[],o=[],a=new Int32Array(n+1);for(let l=0;l<n;l++){a[l]=i.length;for(let c=0;c<t;c++){const u=l*t+c,h=e.data[u],f=r?e.imag[u]:0;(h!==0||f!==0)&&(i.push(c),s.push(h),r&&o.push(f))}}return a[n]=i.length,A.sparseMatrix(t,n,new Int32Array(i),a,D(s),r?D(o):void 0)}throw new q(`Cannot concatenate ${po(e)} into sparse matrix`)}function oV(e,t){const n=e.map(Zde).filter(r=>r.m>0||r.n>0);if(n.length===0)return A.sparseMatrix(0,0,new Int32Array(0),new Int32Array([0]),D(0));if(n.length===1)return n[0];if(t===1){const r=n[0].m;for(let d=1;d<n.length;d++)if(n[d].m!==r&&n[d].m>0)throw new q("Dimensions of arrays being concatenated are not consistent");const i=n.reduce((d,p)=>d+p.n,0),s=n.some(d=>d.pi!==void 0),o=n.reduce((d,p)=>d+p.jc[p.n],0),a=new Int32Array(o),l=D(o),c=s?D(o):void 0,u=new Int32Array(i+1);let h=0,f=0;for(const d of n){const p=d.jc[d.n];for(let m=0;m<p;m++)a[h+m]=d.ir[m],l[h+m]=d.pr[m],c&&(c[h+m]=d.pi?d.pi[m]:0);for(let m=0;m<d.n;m++)u[f+m]=d.jc[m]+h;h+=p,f+=d.n}return u[i]=h,A.sparseMatrix(r,i,a,u,l,c)}else{const r=n[0].n;for(let f=1;f<n.length;f++)if(n[f].n!==r&&n[f].n>0)throw new q("Dimensions of arrays being concatenated are not consistent");const i=n.reduce((f,d)=>f+d.m,0),s=n.some(f=>f.pi!==void 0),o=n.reduce((f,d)=>f+d.jc[d.n],0),a=new Int32Array(o),l=D(o),c=s?D(o):void 0,u=new Int32Array(r+1);let h=0;for(let f=0;f<r;f++){u[f]=h;let d=0;for(const p of n){for(let m=p.jc[f];m<p.jc[f+1];m++)a[h]=p.ir[m]+d,l[h]=p.pr[m],c&&(c[h]=p.pi?p.pi[m]:0),h++;d+=p.m}}return u[r]=h,A.sparseMatrix(i,r,a,u,l,c)}}function aV(e,t){const n=e.every(y=>Tt(y)||ce(y)&&y._isLogical===!0);let r=e.map(y=>{if(Re(y))return A.tensor(D([y]),[1,1]);if(Tt(y)){const _=A.tensor(D([y?1:0]),[1,1]);return _._isLogical=!0,_}if(Ht(y))return A.tensor(D([y.re]),[1,1],D([y.im]));if(ce(y))return y;throw new q(`Cannot concatenate ${po(y)} into matrix`)});if(r=r.filter(y=>y.shape.some(_=>_>0)),r.length===0)return A.tensor(D(0),[0,0]);if(r.length===1)return r[0];const i=Math.max(2,...r.map(y=>y.shape.length));let s=r.map(y=>{const _=[...y.shape];for(;_.length<i;)_.push(1);return _});const o=r.findIndex(y=>y.data.length>0);if(o>=0){const y=s[o],_=r.map((b,x)=>{if(b.data.length>0)return!0;for(let S=0;S<i;S++)if(S!==t&&s[x][S]!==y[S])return!1;return!0});if(r=r.filter((b,x)=>_[x]),s=s.filter((b,x)=>_[x]),r.length===0)return A.tensor(D(0),[0,0]);if(r.length===1)return r[0]}const a=s[0];for(let y=1;y<s.length;y++)for(let _=0;_<i;_++)if(_!==t&&s[y][_]!==a[_])throw new q("Dimensions of arrays being concatenated are not consistent");const l=[...a];l[t]=s.reduce((y,_)=>y+_[t],0);const c=Zc(l),u=r.some(y=>y.imag!==void 0),h=D(c),f=u?D(c):void 0;let d=1;for(let y=0;y<t;y++)d*=l[y];let p=1;for(let y=t+1;y<i;y++)p*=l[y];for(let y=0;y<p;y++){let _=y*d*l[t];for(let b=0;b<r.length;b++){const x=s[b][t],S=d*x,M=y*S;if(h.set(r[b].data.subarray(M,M+S),_),f){const E=r[b].imag;E&&f.set(E.subarray(M,M+S),_)}_+=S}}const m=A.tensor(h,l,f);return n&&(m._isLogical=!0),m}function Qde(e){return lt(e)?e.value.length===0:ce(e)?e.data.length===0:!1}function lV(e,t){let n=[];for(const h of e)if(nn(h))n.push(h);else{if(Qde(h))continue;n.push(A.cell([h],[1,1]))}if(n=n.filter(h=>h.data.length>0),n.length===0)return A.cell([],[0,0]);if(n.length===1)return n[0];const r=Math.max(2,...n.map(h=>h.shape.length)),i=n.map(h=>{const f=[...h.shape];for(;f.length<r;)f.push(1);return f}),s=i[0];for(let h=1;h<i.length;h++)for(let f=0;f<r;f++)if(f!==t&&i[h][f]!==s[f])throw new q("Dimensions of arrays being concatenated are not consistent");const o=[...s];o[t]=i.reduce((h,f)=>h+f[t],0);const a=Zc(o),l=new Array(a);let c=1;for(let h=0;h<t;h++)c*=o[h];let u=1;for(let h=t+1;h<r;h++)u*=o[h];for(let h=0;h<u;h++){let f=h*c*o[t];for(let d=0;d<n.length;d++){const p=i[d][t],m=c*p,y=h*m;for(let _=0;_<m;_++)l[f+_]=n[d].data[y+_];f+=m}}return A.cell(l,o)}const Qu={r:[1,0,0],g:[0,1,0],b:[0,0,1],c:[0,1,1],m:[1,0,1],y:[1,1,0],k:[0,0,0],w:[1,1,1]},uz={red:[1,0,0],green:[0,1,0],blue:[0,0,1],cyan:[0,1,1],magenta:[1,0,1],yellow:[1,1,0],black:[0,0,0],white:[1,1,1]};function es(e){if(typeof e=="string"){const t=e.toLowerCase();return Qu[t]?Qu[t]:uz[t]?uz[t]:void 0}if(mt(e)||lt(e))return es(mt(e)?e:e.value);if(ce(e)&&e.data.length===3)return[e.data[0],e.data[1],e.data[2]]}const Jde=new Set(["r","g","b","c","m","y","k","w"]),epe=new Set(["o","+","*",".","x","_","|","s","d","^","v","<",">","p","h"]);function Ju(e){const t={};let n=0;for(;n<e.length;){if(n+1<e.length){const i=e.slice(n,n+2);if(i==="--"||i==="-."){if(t.lineStyle!==void 0)return null;t.lineStyle=i,n+=2;continue}}const r=e[n];if(r==="-"||r===":"){if(t.lineStyle!==void 0)return null;t.lineStyle=r,n++;continue}if(Jde.has(r)){if(t.color!==void 0)return null;t.color=r,n++;continue}if(epe.has(r)){if(t.marker!==void 0)return null;t.marker=r,n++;continue}return null}return t.color===void 0&&t.lineStyle===void 0&&t.marker===void 0?null:t}const tpe=new Set(["color","linestyle","linewidth","marker","markersize","markeredgecolor","markerfacecolor","markerindices"]);function ml(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return tpe.has(t)?t:null}function jr(e){if(typeof e=="number"||typeof e=="boolean")return!0;if(e&&typeof e=="object"&&"kind"in e){const t=e;return Re(t)||ce(t)||Tt(t)}return!1}function _i(e){if(typeof e=="string")return!0;if(e&&typeof e=="object"&&"kind"in e){const t=e;return mt(t)||lt(t)}return!1}function Hr(e){return mt(e)?e:lt(e)?e.value:Xe(e)}function vn(e){return Re(e)?[e]:ce(e)?Array.from(e.data):Tt(e)?[e?1:0]:[0]}function cV(e,t){const n=e.shape[0],r=t*n,i=new Array(n);for(let s=0;s<n;s++)i[s]=e.data[r+s];return i}function J_(e){return ce(e)&&e.shape.length>=2&&e.shape[0]>1&&e.shape[1]>1?e.shape[1]:1}function YM(e){const t=new Array(e);for(let n=0;n<e;n++)t[n]=n+1;return t}function mm(e){if(ce(e)&&e.shape.length>=2&&e.shape[0]>1&&e.shape[1]>1){const t=[];for(let n=0;n<e.shape[1];n++)t.push(cV(e,n));return t}return[vn(e)]}function tp(e){const t=[];let n=0;for(;n<e.length&&!(_i(e[n])&&ml(e[n]));){if(!jr(e[n])){if(_i(e[n])&&t.length>0&&Ju(Hr(e[n]))){n++;continue}break}const r=e[n];n++;let i;n<e.length&&jr(e[n])&&(i=e[n],n++);let s;if(n<e.length&&_i(e[n])&&!ml(e[n])){const o=Ju(Hr(e[n]));o&&(s=o,n++)}i!==void 0?rpe(r,i,s,t):npe(r,s,t)}for(;n<e.length;){const r=ml(e[n]);if(!r||(n++,n>=e.length))break;const i=e[n];n++,gI(t,r,i)}return t}function npe(e,t,n){const r=mm(e);for(const i of r){const s=YM(i.length);n.push(L_(s,i,t))}}function rpe(e,t,n,r){const i=J_(e),s=J_(t);if(i===1&&s===1)r.push(L_(vn(e),vn(t),n));else if(i===1&&s>1){const o=vn(e),a=mm(t);for(const l of a)r.push(L_(o,l,n))}else if(i>1&&s>1&&i===s){const o=mm(e),a=mm(t);for(let l=0;l<i;l++)r.push(L_(o[l],a[l],n))}else r.push(L_(vn(e),vn(t),n))}function L_(e,t,n){const r={x:e,y:t};return n&&(n.color&&(r.color=Qu[n.color]),n.lineStyle&&(r.lineStyle=n.lineStyle),n.marker&&(r.marker=n.marker,n.lineStyle||(r.lineStyle="none"))),r}function dI(e){const t=[];let n=0;for(;n<e.length&&!(_i(e[n])&&ml(e[n])||!jr(e[n])||n+1>=e.length||!jr(e[n+1])||n+2>=e.length||!jr(e[n+2]));){const r=e[n],i=e[n+1],s=e[n+2];n+=3;let o;if(n<e.length&&_i(e[n])&&!ml(e[n])){const a=Ju(Hr(e[n]));a&&(o=a,n++)}ipe(r,i,s,o,t)}for(;n<e.length;){const r=ml(e[n]);if(!r||(n++,n>=e.length))break;const i=e[n];n++,pI(t,r,i)}return t}function ipe(e,t,n,r,i){const s=J_(e),o=J_(t),a=J_(n),l=Math.max(s,o,a);if(l===1)i.push(hz(vn(e),vn(t),vn(n),r));else{const c=mm(e),u=mm(t),h=mm(n);for(let f=0;f<l;f++)i.push(hz(c[Math.min(f,c.length-1)],u[Math.min(f,u.length-1)],h[Math.min(f,h.length-1)],r))}}function hz(e,t,n,r){const i={x:e,y:t,z:n};return r&&(r.color&&(i.color=Qu[r.color]),r.lineStyle&&(i.lineStyle=r.lineStyle),r.marker&&(i.marker=r.marker,r.lineStyle||(i.lineStyle="none"))),i}function pI(e,t,n){switch(t){case"color":{const r=es(n);if(r)for(const i of e)i.color=r;break}case"linestyle":{const r=Hr(n);for(const i of e)i.lineStyle=r;break}case"linewidth":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.lineWidth=r;break}case"marker":{const r=Hr(n);for(const i of e)i.marker=r==="none"?void 0:r;break}case"markersize":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.markerSize=r;break}case"markeredgecolor":{const r=es(n);if(r)for(const i of e)i.markerEdgeColor=r;break}case"markerfacecolor":{const r=es(n);if(r)for(const i of e)i.markerFaceColor=r;break}case"markerindices":{const r=vn(n);for(const i of e)i.markerIndices=r;break}}}function KM(e){return!!e&&typeof e=="object"&&"kind"in e&&(e.kind==="graphics_handle"||e.kind==="dummy_handle")}function spe(e){let t=e;if(t.length>0&&KM(t[0])&&(t=t.slice(1)),t.length===0)return{kind:"2d",traces:[{x:[0,1],y:[0,1]}]};if(_i(t[0]))return ope(t);let n=0;for(let r=0;r<t.length&&jr(t[r]);r++)n++;return n>=3?{kind:"3d",traces:dI(t)}:{kind:"2d",traces:tp(t)}}function ope(e){let t,n,r;const i=[];let s=0;for(;s+1<e.length&&_i(e[s]);){const a=Hr(e[s]).toLowerCase(),l=e[s+1];a==="xdata"?t=vn(l):a==="ydata"?n=vn(l):a==="zdata"?r=vn(l):i.push(e[s],l),s+=2}if(t||(t=[0,1]),n||(n=[0,1]),r){const a={x:t,y:n,z:r,color:[0,0,0]};for(let l=0;l+1<i.length;l+=2){const c=ml(i[l]);c&&pI([a],c,i[l+1])}return{kind:"3d",traces:[a]}}const o={x:t,y:n,color:[0,0,0]};for(let a=0;a+1<i.length;a+=2){const l=ml(i[a]);l&&gI([o],l,i[a+1])}return{kind:"2d",traces:[o]}}function I2(e){if(_i(e)){const t=Hr(e).toLowerCase().replace(/^["']|["']$/g,"");return t==="flat"||t==="interp"||t==="none"?t:t==="auto"?void 0:es(t)}return es(e)}function P2(e){if(ce(e)&&e.shape.length>=2&&e.shape[1]===3){const t=e.shape[0],n=[];for(let r=0;r<t;r++)n.push([e.data[r],e.data[t+r],e.data[2*t+r]]);return n}return vn(e)}const AR=new Set(["facecolor","edgecolor","facealpha","linewidth","linestyle","marker","markerfacecolor","facevertexcdata","cdata","xdata","ydata","zdata","faces","vertices"]);function ev(e,t,n){const r=zr(e),i=zr(t),s=n?zr(n):void 0;let o=r.rows,a=r.cols;(o===1||a===1)&&(o=r.data.length,a=1);const l=[],c=[];for(let u=0;u<a;u++){const h=[];for(let f=0;f<o;f++){const d=u*o+f,p=r.data[d],m=i.data[Math.min(d,i.data.length-1)],y=s?[p,m,s.data[Math.min(d,s.data.length-1)]]:[p,m];h.push(l.length),l.push(y)}c.push(h)}return{vertices:l,faces:c,rows:o,cols:a}}function uV(e,t,n,r){if(_i(t)){const o=I2(t);o&&(e.faceColor=o);return}const i=zr(t),s=i.data.length;s===1?(e.faceColor="flat",e.faceVertexCData=new Array(n).fill(i.data[0])):i.rows===1&&i.cols===3?e.faceColor=[i.data[0],i.data[1],i.data[2]]:s===r&&r!==n?(e.faceColor="interp",e.faceVertexCData=P2(t)):(e.faceColor="flat",e.faceVertexCData=P2(t))}function B2(e,t,n){for(let r=n;r+1<t.length&&_i(t[r]);r+=2){const i=Hr(t[r]).toLowerCase(),s=t[r+1];ZM(e,i,s)}}function ZM(e,t,n){switch(t){case"facecolor":{const r=I2(n);r&&(e.faceColor=r);break}case"edgecolor":{const r=I2(n);r&&(e.edgeColor=r);break}case"facealpha":e.faceAlpha=Ne(n);break;case"linewidth":e.lineWidth=Ne(n);break;case"linestyle":e.lineStyle=Hr(n);break;case"marker":e.marker=Hr(n);break;case"markerfacecolor":{const r=_i(n)?Hr(n).toLowerCase():"";if(r==="flat"||r==="none")e.markerFaceColor=r;else{const i=es(n);i&&(e.markerFaceColor=i)}break}case"facevertexcdata":case"cdata":e.faceVertexCData=P2(n);break}}function hV(e,t){const n=zr(t),r=n.rows,s=n.cols>=3,o=[];for(let c=0;c<r;c++){const u=n.data[c],h=n.data[r+c];o.push(s?[u,h,n.data[2*r+c]]:[u,h])}const a=zr(e),l=[];for(let c=0;c<a.rows;c++){const u=[];for(let h=0;h<a.cols;h++){const f=a.data[h*a.rows+c];Number.isFinite(f)&&u.push(f-1)}u.length>0&&l.push(u)}return{vertices:o,faces:l,is3D:s}}function ape(e){const t=a=>{for(const[l,c]of e.fields)if(l.toLowerCase()===a)return c},n={vertices:[],faces:[]},r=t("faces"),i=t("vertices"),s=t("xdata"),o=t("ydata");if(r&&i){const a=hV(r,i);n.vertices=a.vertices,n.faces=a.faces,n.is3D=a.is3D}else if(s&&o){const a=t("zdata"),l=ev(s,o,a);n.vertices=l.vertices,n.faces=l.faces,n.is3D=!!a}for(const[a,l]of e.fields){const c=a.toLowerCase();c==="faces"||c==="vertices"||c==="xdata"||c==="ydata"||c==="zdata"||ZM(n,c,l)}return n}function lpe(e){let t=e;if(t.length>0&&KM(t[0])&&(t=t.slice(1)),t.length===0)throw new Error("patch requires input arguments");if(t.length===1&&Zn(t[0]))return BS(ape(t[0]));const n={vertices:[],faces:[]};if(_i(t[0])){const l={};for(let c=0;c+1<t.length&&_i(t[c]);c+=2)l[Hr(t[c]).toLowerCase()]=t[c+1];if(l.faces&&l.vertices){const c=hV(l.faces,l.vertices);n.vertices=c.vertices,n.faces=c.faces,n.is3D=c.is3D}else if(l.xdata&&l.ydata){const c=ev(l.xdata,l.ydata,l.zdata);n.vertices=c.vertices,n.faces=c.faces,n.is3D=!!l.zdata}for(const[c,u]of Object.entries(l))c==="faces"||c==="vertices"||c==="xdata"||c==="ydata"||c==="zdata"||ZM(n,c,u);return BS(n)}let r=0;for(let l=0;l<t.length&&jr(t[l]);l++)r++;if(r<2)throw new Error("patch: expected X and Y coordinates");let i=!1;if(r>=4)i=!0;else if(r===3&&t[3]!==void 0&&_i(t[3])){const l=Hr(t[3]).toLowerCase();!AR.has(l)&&I2(t[3])&&(i=!0)}let s,o;const a=i?ev(t[0],t[1],t[2]):ev(t[0],t[1],void 0);return n.vertices=a.vertices,n.faces=a.faces,n.is3D=i,i?(o=t[3],s=4):t.length>2&&!(_i(t[2])&&AR.has(Hr(t[2]).toLowerCase()))?(o=t[2],s=3):s=2,o!==void 0&&uV(n,o,a.faces.length,a.vertices.length),B2(n,t,s),BS(n)}function BS(e){return e.faceColor===void 0&&(e.faceColor=e.faceVertexCData?"flat":[0,.447,.741]),e.edgeColor===void 0&&(e.edgeColor=[0,0,0]),e}function cpe(e){let t=e;t.length>0&&KM(t[0])&&(t=t.slice(1));const n=[];let r=0;for(;r+1<t.length&&jr(t[r])&&jr(t[r+1]);){const i=ev(t[r],t[r+1],void 0),s={vertices:i.vertices,faces:i.faces,is3D:!1},o=t[r+2],a=o!==void 0&&_i(o)&&AR.has(Hr(o).toLowerCase());o!==void 0&&!a?(uV(s,o,i.faces.length,i.vertices.length),r+=3):r+=2,n.push(s)}for(const i of n)B2(i,t,r);return n.map(BS)}function fz(e){const t=zr(e),n=[];for(let r=0;r<t.rows;r++){const i=[];for(let s=0;s<t.cols;s++){const o=t.data[s*t.rows+r];Number.isFinite(o)&&i.push(o-1)}i.length>0&&n.push(i)}return n}function dz(e){return e.faceColor===void 0&&(e.faceColor=[.85,.85,.85]),e.edgeColor===void 0&&(e.edgeColor=[0,0,0]),e}function upe(e){let t=e;if(t.length>0&&KM(t[0])&&(t=t.slice(1)),t.length===0)throw new Error("trimesh requires input arguments");if(Zn(t[0])){const h=t[0],f=S=>{for(const[M,E]of h.fields)if(M.toLowerCase()===S)return E},d=f("connectivitylist"),p=f("points");if(!d||!p)throw new Error("trimesh: triangulation object must have ConnectivityList and Points fields");const m=zr(p),y=m.rows,_=m.cols>=3,b=[];for(let S=0;S<y;S++){const M=m.data[S],E=m.data[y+S];b.push(_?[M,E,m.data[2*y+S]]:[M,E])}const x={vertices:b,faces:fz(d),is3D:_};return B2(x,t,1),dz(x)}if(t.length<3)throw new Error("trimesh: expected T, x and y");let n=3,r,i;t.length>3&&jr(t[3])&&(r=t[3],n=4,t.length>4&&jr(t[4])&&(i=t[4],n=5));const s=zr(t[1]),o=zr(t[2]),a=r?zr(r):void 0,l=s.data.length,c=[];for(let h=0;h<l;h++){const f=s.data[h],d=o.data[Math.min(h,o.data.length-1)];a?c.push([f,d,a.data[Math.min(h,a.data.length-1)]]):c.push([f,d])}const u={vertices:c,faces:fz(t[0]),is3D:!!a};return i&&(u.faceVertexCData=P2(i)),B2(u,t,n),dz(u)}const hpe=new Set(["edgecolor","facecolor","facealpha"]);function fpe(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return hpe.has(t)?t:null}function mI(e){let t=0,n,r,i,s,o,a,l=0;for(let u=t;u<e.length&&jr(e[u]);u++)l++;if(l===1){const u=e[t++],h=zr(u);s=h.rows,o=h.cols,i=h.data;const f=Em(s,o);n=f.x,r=f.y}else if(l===2){const u=e[t++],h=e[t++],f=zr(u);s=f.rows,o=f.cols,i=f.data,a=vn(h);const d=Em(s,o);n=d.x,r=d.y}else if(l===3){const u=e[t++],h=e[t++],f=e[t++],d=zr(f);s=d.rows,o=d.cols,i=d.data;const p=Cm(u,h,s,o);n=p.x,r=p.y}else if(l>=4){const u=e[t++],h=e[t++],f=e[t++],d=e[t++],p=zr(f);s=p.rows,o=p.cols,i=p.data,a=vn(d);const m=Cm(u,h,s,o);n=m.x,r=m.y}else throw new Error("surf requires at least one input argument");const c={x:n,y:r,z:i,rows:s,cols:o};for(a&&(c.c=a);t<e.length;){const u=fpe(e[t]);if(!u||(t++,t>=e.length))break;const h=e[t++];ype(c,u,h)}return c}function zr(e){if(ce(e)&&e.shape.length>=2)return{data:Array.from(e.data),rows:e.shape[0],cols:e.shape[1]};if(Re(e))return{data:[e],rows:1,cols:1};const t=vn(e);return{data:t,rows:t.length,cols:1}}function Em(e,t){const n=e*t,r=new Array(n),i=new Array(n);for(let s=0;s<t;s++)for(let o=0;o<e;o++){const a=s*e+o;r[a]=s+1,i[a]=o+1}return{x:r,y:i}}function Cm(e,t,n,r){const i=vn(e),s=vn(t),o=n*r;if(i.length===o&&s.length===o)return{x:i,y:s};const a=i.length===r?i:i.slice(0,r),l=s.length===n?s:s.slice(0,n),c=new Array(o),u=new Array(o);for(let h=0;h<r;h++)for(let f=0;f<n;f++){const d=h*n+f;c[d]=a[h],u[d]=l[f]}return{x:c,y:u}}const dpe=new Set(["edgecolor","facealpha"]);function ppe(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return dpe.has(t)?t:null}function mpe(e,t,n){switch(t){case"edgecolor":{const r=TR(n);if(r!==void 0&&r.toLowerCase()==="none"){e.edgeColor="none";break}const i=es(n);i&&(e.edgeColor=i);break}case"facealpha":{const r=typeof n=="number"?n:Ne(n);e.faceAlpha=r;break}}}function gpe(e){let t=0,n,r,i,s,o,a=0;for(let c=t;c<e.length&&jr(e[c]);c++)a++;if(a===1){const c=e[t++],u=zr(c);s=u.rows,o=u.cols,i=u.data;const h=Em(s,o);n=h.x,r=h.y}else if(a>=3){const c=e[t++],u=e[t++],h=e[t++],f=zr(h);s=f.rows,o=f.cols,i=f.data;const d=Cm(c,u,s,o);n=d.x,r=d.y}else throw new Error("pcolor requires 1 or 3 numeric input arguments");const l={x:n,y:r,c:i,rows:s,cols:o};for(;t<e.length;){const c=ppe(e[t]);if(!c||(t++,t>=e.length))break;const u=e[t++];mpe(l,c,u)}return l}function ype(e,t,n){switch(t){case"edgecolor":{const r=TR(n);if(r!==void 0){const s=r.toLowerCase();if(s==="none"||s==="flat"||s==="interp"){e.edgeColor=s;break}}const i=es(n);i&&(e.edgeColor=i);break}case"facecolor":{const r=TR(n);if(r!==void 0){const s=r.toLowerCase();if(s==="flat"||s==="interp"||s==="none"||s==="texturemap"){e.faceColor=s;break}}const i=es(n);i&&(e.faceColor=i);break}case"facealpha":{const r=typeof n=="number"?n:Ne(n);e.faceAlpha=r;break}}}function TR(e){if(mt(e))return e;if(lt(e))return e.value}function fV(e){if(e.length<2)throw new Error("scatter requires at least 2 arguments");const t=vn(e[0]),n=vn(e[1]),r={x:t,y:n,marker:"o",lineStyle:"none"};let i=2,s=!1;if(i<e.length&&jr(e[i])){const o=e[i];if(Re(o))r.markerSize=Math.sqrt(o)*.5;else if(ce(o)){const a=vn(o);(a.length===1||new Set(a).size===1)&&(r.markerSize=Math.sqrt(a[0])*.5)}i++}if(i<e.length&&!ml(e[i])){if(_i(e[i])){const o=Hr(e[i]);if(o==="filled")s=!0,i++;else{const a=es(o);if(a)r.color=a,i++;else{const l=Ju(o);l?.marker&&(r.marker=l.marker,l.color&&(r.color=Qu[l.color]),i++)}}}else if(jr(e[i])){const o=es(e[i]);o&&(r.color=o,i++)}}for(;i<e.length&&_i(e[i])&&!ml(e[i]);){const o=Hr(e[i]);if(o==="filled")s=!0,i++;else{const a=Ju(o);if(a?.marker)r.marker=a.marker,a.color&&(r.color=Qu[a.color]),i++;else break}}for(s&&(r.markerFaceColor=r.color||[0,0,1]);i<e.length;){const o=ml(e[i]);if(!o||(i++,i>=e.length))break;const a=e[i];i++,gI([r],o,a)}return[r]}function gI(e,t,n){switch(t){case"color":{const r=es(n);if(r)for(const i of e)i.color=r;break}case"linestyle":{const r=Hr(n);for(const i of e)i.lineStyle=r;break}case"linewidth":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.lineWidth=r;break}case"marker":{const r=Hr(n);for(const i of e)i.marker=r==="none"?void 0:r;break}case"markersize":{const r=typeof n=="number"?n:Ne(n);for(const i of e)i.markerSize=r;break}case"markeredgecolor":{const r=es(n);if(r)for(const i of e)i.markerEdgeColor=r;break}case"markerfacecolor":{const r=es(n);if(r)for(const i of e)i.markerFaceColor=r;break}case"markerindices":{const r=vn(n);for(const i of e)i.markerIndices=r;break}}}function _pe(e){if(e.length===1){const t=zr(e[0]);return{x:[1,t.cols],y:[1,t.rows],z:t.data,rows:t.rows,cols:t.cols}}if(e.length>=3){const t=vn(e[0]),n=vn(e[1]),r=zr(e[2]);return{x:[t[0],t[t.length-1]],y:[n[0],n[n.length-1]],z:r.data,rows:r.rows,cols:r.cols}}throw new Error("imagesc requires 1 or 3+ arguments")}function vpe(e,t){let n=0,r=0;for(let m=n;m<e.length&&jr(e[m]);m++)r++;let i,s,o,a,l,c=10,u;const h=m=>{const y=vn(m);y.length<=1?c=y.length===1?y[0]:c:u=y};if(r===1){const m=zr(e[n++]);a=m.rows,l=m.cols,o=m.data;const y=Em(a,l);i=y.x,s=y.y}else if(r===2){const m=zr(e[n++]);a=m.rows,l=m.cols,o=m.data,h(e[n++]);const y=Em(a,l);i=y.x,s=y.y}else if(r===3){const m=e[n++],y=e[n++],_=zr(e[n++]);a=_.rows,l=_.cols,o=_.data;const b=Cm(m,y,a,l);i=b.x,s=b.y}else if(r>=4){const m=e[n++],y=e[n++],_=zr(e[n++]);a=_.rows,l=_.cols,o=_.data,h(e[n++]);const b=Cm(m,y,a,l);i=b.x,s=b.y}else throw new Error("contour requires at least 1 argument");let f,d,p;for(;n+1<e.length&&_i(e[n]);n+=2){const m=Hr(e[n]).toLowerCase(),y=e[n+1];switch(m){case"linewidth":f=Ne(y);break;case"linestyle":d=Hr(y);break;case"linecolor":case"color":p=_i(y)?Hr(y):vn(y);break;case"levellist":case"levels":{const _=vn(y);_.length>=1&&(u=_);break}}}return u&&(c=u.length),{x:i,y:s,z:o,rows:a,cols:l,nLevels:c,...u?{levels:u}:{},...f!==void 0?{lineWidth:f}:{},...d!==void 0?{lineStyle:d}:{},...p!==void 0?{lineColor:p}:{},filled:t}}function bpe(e,t,n,r,i,s,o,a,l,c,u,h,f){const d=(e>=f?1:0)|(t>=f?2:0)|(n>=f?4:0)|(r>=f?8:0);if(d===0||d===15)return[];const p=(k,R,B,F)=>k+(f-B)/(F-B||1)*(R-k),m=p(i,o,e,t),y=p(s,a,e,t),_=p(o,u,t,r),b=p(a,h,t,r),x=p(l,u,n,r),S=p(c,h,n,r),M=p(i,l,e,n),E=p(s,c,e,n),T=[];switch(d){case 1:case 14:T.push([m,y,M,E]);break;case 2:case 13:T.push([m,y,_,b]);break;case 3:case 12:T.push([M,E,_,b]);break;case 4:case 11:T.push([M,E,x,S]);break;case 5:case 10:T.push([m,y,x,S]);break;case 6:case 9:T.push([m,y,M,E]),T.push([x,S,_,b]);break;case 7:case 8:T.push([x,S,_,b]);break}return T}function xpe(e){const{x:t,y:n,z:r,rows:i,cols:s}=e,o=(h,f,d)=>h[d*i+f];let a=1/0,l=-1/0;for(const h of r)Number.isFinite(h)&&(h<a&&(a=h),h>l&&(l=h));let c;if(e.levels&&e.levels.length>0)c=e.levels.filter(h=>Number.isFinite(h));else{const h=Math.max(1,Math.round(e.nLevels));if(c=[],Number.isFinite(a)&&Number.isFinite(l)&&l>a){const f=(l-a)/(h+1);for(let d=1;d<=h;d++)c.push(a+d*f)}}const u=[];for(const h of c)for(let f=0;f<s-1;f++)for(let d=0;d<i-1;d++){const p=bpe(o(r,d,f),o(r,d+1,f),o(r,d,f+1),o(r,d+1,f+1),o(t,d,f),o(n,d,f),o(t,d+1,f),o(n,d+1,f),o(t,d,f+1),o(n,d,f+1),o(t,d+1,f+1),o(n,d+1,f+1),h);for(const[m,y,_,b]of p)u.push(h,2,m,y,_,b)}return{data:u,n:u.length/2,levelList:c}}function wpe(e){const t=mI(e);return t.edgeColor||(t.edgeColor="flat"),t.faceColor||(t.faceColor="none"),t}function dV(e){let t=0,n,r,i=.8,s;if(e.length===0)throw new Error("bar requires at least 1 argument");const o=e[t++];for(t<e.length&&jr(e[t])?(n=vn(o),r=vn(e[t++])):r=vn(o);t<e.length;)if(jr(e[t])){const l=e[t];if(Re(l))i=l,t++;else break}else if(_i(e[t])){const l=Hr(e[t]),c=es(l);if(c)s=c,t++;else break}else break;n||(n=YM(r.length));const a={x:n,y:r,width:i};return s&&(a.color=s),[a]}function Spe(e){return dV(e)}function pV(e){let t=0,n,r=.8,i;if(e.length===0)throw new Error("bar3 requires at least 1 argument");const s=e[t++];let o,a,l;if(t<e.length&&jr(e[t])){n=vn(s);const d=e[t++];if(ce(d)){const p=zr(d);o=Array.from(p.data),a=p.rows,l=p.cols}else o=vn(d),a=o.length,l=1}else if(ce(s)){const d=zr(s);o=Array.from(d.data),a=d.rows,l=d.cols}else o=vn(s),a=o.length,l=1;for(;t<e.length;)if(jr(e[t])){const d=e[t];if(Re(d))r=d,t++;else break}else if(_i(e[t])){const d=Hr(e[t]),p=es(d);if(p)i=p,t++;else break}else break;n||(n=YM(a));const c=[],u=[],h=[];for(let d=0;d<l;d++)for(let p=0;p<a;p++)c.push(d+1),u.push(n[p]),h.push(o[d*a+p]);const f={x:c,y:u,z:h,rows:a,cols:l,width:r};return i&&(f.color=i),f}function Mpe(e){const t=tp(e);for(const n of t){const r=n.x.length;if(r<2)continue;const i=[],s=[];for(let o=0;o<r-1;o++)i.push(n.x[o]),s.push(n.y[o]),i.push(n.x[o+1]),s.push(n.y[o]);i.push(n.x[r-1]),s.push(n.y[r-1]),n.x=i,n.y=s}return t}function Epe(e){if(e.length<2)throw new Error("errorbar requires at least 2 arguments");let t=0,n,r,i,s,o,a,l,c,u,h=0;for(let d=0;d<e.length&&jr(e[d]);d++)h++;if(h===2){r=vn(e[t++]);const d=vn(e[t++]);i=d,s=d}else if(h===3){n=vn(e[t++]),r=vn(e[t++]);const d=vn(e[t++]);i=d,s=d}else if(h===4)n=vn(e[t++]),r=vn(e[t++]),i=vn(e[t++]),s=vn(e[t++]);else if(h>=6)n=vn(e[t++]),r=vn(e[t++]),i=vn(e[t++]),s=vn(e[t++]),o=vn(e[t++]),a=vn(e[t++]);else throw new Error("errorbar: invalid number of numeric arguments");for(n||(n=YM(r.length));t<e.length&&_i(e[t]);){const d=Hr(e[t]),p=Ju(d);if(p){if(p.color){const m=es(p.color);m&&(l=m)}p.lineStyle&&(c=p.lineStyle),p.marker&&(u=p.marker),t++}else{const m=es(d);if(m)l=m,t++;else break}}const f={x:n,y:r,yNeg:i,yPos:s};return o&&(f.xNeg=o),a&&(f.xPos=a),l&&(f.color=l),c&&(f.lineStyle=c),u&&(f.marker=u),[f]}function Cpe(e){let t=0;const n=[...e],r=n.length-1;return r>=1&&jr(n[r])&&Re(n[r])&&r>=1&&jr(n[r-1])&&(t=Ne(n[r]),n.pop()),{traces:tp(n),baseValue:t}}function mV(e){if(e.length<3)throw new Error("scatter3 requires at least 3 arguments");const t=vn(e[0]),n=vn(e[1]),r=vn(e[2]),i={x:t,y:n,z:r,marker:"o",lineStyle:"none"};let s=3,o=!1;if(s<e.length&&jr(e[s])){const a=e[s];if(Re(a))i.markerSize=Math.sqrt(a)*.5;else if(ce(a)){const l=vn(a);(l.length===1||new Set(l).size===1)&&(i.markerSize=Math.sqrt(l[0])*.5)}s++}if(s<e.length&&!ml(e[s])){if(_i(e[s])){const a=Hr(e[s]);if(a==="filled")o=!0,s++;else{const l=es(a);if(l)i.color=l,s++;else{const c=Ju(a);c?.marker&&(i.marker=c.marker,c.color&&(i.color=Qu[c.color]),s++)}}}else if(jr(e[s])){const a=es(e[s]);a&&(i.color=a,s++)}}for(;s<e.length&&_i(e[s])&&!ml(e[s]);){const a=Hr(e[s]);if(a==="filled")o=!0,s++;else{const l=Ju(a);if(l?.marker)i.marker=l.marker,l.color&&(i.color=Qu[l.color]),s++;else break}}for(o&&(i.markerFaceColor=i.color||[0,0,1]);s<e.length;){const a=ml(e[s]);if(!a||(s++,s>=e.length))break;const l=e[s];s++,pI([i],a,l)}return[i]}function Ape(e){if(e.length===0)throw new Error("histogram requires at least 1 argument");let t=0;const r=vn(e[t++]).filter(u=>isFinite(u));if(r.length===0)return[];let i;if(t<e.length&&jr(e[t])){const u=e[t++];Re(u)?i=bd(r,Math.max(1,Math.round(u))):i=vn(u)}else{const u=Math.max(1,Math.ceil(Math.log2(r.length)+1));i=bd(r,u)}const s=i.length-1;if(s<=0)return[];const o=new Array(s).fill(0);for(const u of r){let h=-1;for(let f=0;f<s;f++)if(f<s-1){if(u>=i[f]&&u<i[f+1]){h=f;break}}else if(u>=i[f]&&u<=i[f+1]){h=f;break}h>=0&&o[h]++}const a=[],l=[],c=i[1]-i[0];for(let u=0;u<s;u++)a.push((i[u]+i[u+1])/2),l.push(o[u]);return[{x:a,y:l,width:c}]}function bd(e,t){const n=Math.min(...e),s=(Math.max(...e)-n||1)/t,o=[];for(let a=0;a<=t;a++)o.push(n+a*s);return o}function Tpe(e){if(e.length<2)throw new Error("histogram2 requires at least 2 arguments");let t=0;const n=vn(e[t++]).filter(y=>isFinite(y)),r=vn(e[t++]).filter(y=>isFinite(y)),i=Math.min(n.length,r.length);if(i===0)return{x:[],y:[],z:[],rows:0,cols:0,width:.8};let s,o;if(t<e.length&&jr(e[t])){const y=e[t++];if(t<e.length&&jr(e[t]))s=vn(y),o=vn(e[t++]);else if(Re(y)){const _=Math.max(1,Math.round(y));s=bd(n.slice(0,i),_),o=bd(r.slice(0,i),_)}else{const _=vn(y),b=Math.max(1,Math.round(_[0])),x=_.length>1?Math.max(1,Math.round(_[1])):b;s=bd(n.slice(0,i),b),o=bd(r.slice(0,i),x)}}else{const y=Math.max(1,Math.ceil(Math.sqrt(i)));s=bd(n.slice(0,i),y),o=bd(r.slice(0,i),y)}const a=s.length-1,l=o.length-1;if(a<=0||l<=0)return{x:[],y:[],z:[],rows:0,cols:0,width:.8};const c=new Array(a*l).fill(0);for(let y=0;y<i;y++){const _=pz(n[y],s),b=pz(r[y],o);_>=0&&b>=0&&c[_*l+b]++}const u=[],h=[],f=[];for(let y=0;y<a;y++)for(let _=0;_<l;_++)u.push((s[y]+s[y+1])/2),h.push((o[_]+o[_+1])/2),f.push(c[y*l+_]);const d=s[1]-s[0],p=o[1]-o[0],m=Math.min(d,p);return{x:u,y:h,z:f,rows:l,cols:a,width:m}}function pz(e,t){const n=t.length-1;for(let r=0;r<n;r++)if(r<n-1){if(e>=t[r]&&e<t[r+1])return r}else if(e>=t[r]&&e<=t[r+1])return r;return-1}function CT(e,t){if(e.length===0)return NaN;if(e.length===1)return e[0];const n=t/100*(e.length-1),r=Math.floor(n),i=Math.ceil(n);return r===i?e[r]:e[r]+(e[i]-e[r])*(n-r)}function AT(e,t,n,r){const i=e.filter(m=>isFinite(m));if(i.length===0)return null;i.sort((m,y)=>m-y);const s=CT(i,50),o=CT(i,25),a=CT(i,75),l=a-o,c=o-1.5*l,u=a+1.5*l;let h=o,f=a;const d=[];for(const m of i)m<c||m>u?d.push(m):(m<h&&(h=m),m>f&&(f=m));return{x:t,median:s,q1:o,q3:a,whiskerLow:h,whiskerHigh:f,outliers:d,width:n}}function kpe(e){if(e.length===0)throw new Error("boxchart requires at least 1 argument");let t=0;const n=e[t++];if(t<e.length&&jr(e[t])){const s=vn(n),o=vn(e[t++]),a=Math.min(s.length,o.length),l=new Map;for(let h=0;h<a;h++){const f=s[h];if(!isFinite(f))continue;let d=l.get(f);d||(d=[],l.set(f,d)),d.push(o[h])}const c=[],u=[...l.keys()].sort((h,f)=>h-f);for(const h of u){const f=AT(l.get(h),h,.5);f&&c.push(f)}return c}if(ce(n)&&n.shape.length>=2&&n.shape[0]>1&&n.shape[1]>1){const s=[];for(let o=0;o<n.shape[1];o++){const a=cV(n,o),l=AT(a,o+1,.5);l&&s.push(l)}return s}const r=vn(n),i=AT(r,1,.5);return i?[i]:[]}function kR(e,t,n){const r=new Array(e.length),i=new Map;for(let s=0;s<e.length;s++){let o=i.get(e[s]);o||(o=[],i.set(e[s],o)),o.push(s)}for(const[,s]of i){if(s.length<=1){for(const p of s)r[p]=e[p];continue}const o=s.slice().sort((p,m)=>t[p]-t[m]),a=o.map(p=>t[p]),l=a[0],h=(a[a.length-1]-l||1)/Math.max(3,Math.sqrt(o.length)),f=new Array(o.length);for(let p=0;p<o.length;p++){let m=0;for(let y=0;y<o.length;y++){const _=(a[p]-a[y])/h;m+=Math.exp(-.5*_*_)}f[p]=m}const d=Math.max(...f);for(let p=0;p<o.length;p++){const m=d>0?f[p]/d:0,y=n*m,_=p,b=_%2===0?1:-1,x=Math.ceil(_/2)/Math.max(1,o.length/2)*y;r[o[p]]=e[o[p]]+b*x}}return r}function Rpe(e){if(e.length<2)throw new Error("swarmchart requires at least 2 arguments");const t=vn(e[0]),n=vn(e[1]),r=kR(t,n,.3),i=[RR(r),e[1],...e.slice(2)];return fV(i)}function Dpe(e){if(e.length<3)throw new Error("swarmchart3 requires at least 3 arguments");const t=vn(e[0]),n=vn(e[1]),r=vn(e[2]),i=kR(t,r,.3),s=kR(n,r,.3),o=[RR(i),RR(s),e[2],...e.slice(3)];return mV(o)}function RR(e){return{kind:"tensor",data:D(e),shape:[1,e.length]}}function gV(e,t){if(e.length===0)throw new Error("piechart requires at least 1 argument");let n=0;const r=vn(e[n++]).filter(s=>isFinite(s)&&s>0);let i;if(n<e.length&&!jr(e[n])&&!(ce(e[n])||Re(e[n]))){i=[];const s=e[n];if(s&&typeof s=="object"&&"kind"in s&&s.kind==="cell"){const o=s;for(const a of o.data)i.push(Hr(a))}else if(_i(s)){for(i.push(Hr(s)),n++;n<e.length&&_i(e[n]);)i.push(Hr(e[n])),n++;return{values:r,names:i,innerRadius:t}}n++}return{values:r,names:i,innerRadius:t}}function Npe(e){if(e.length===0)throw new Error("heatmap requires at least 1 argument");let t=0;if(e.length>=3&&jr(e[0]),e.length>=3&&jr(e[0])&&jr(e[1])&&jr(e[2])){const r=vn(e[t++]),i=vn(e[t++]),s=zr(e[t++]);return{data:s.data,rows:s.rows,cols:s.cols,xLabels:r.map(o=>String(o)),yLabels:i.map(o=>String(o))}}const n=zr(e[t++]);return{data:n.data,rows:n.rows,cols:n.cols}}const Lpe=new Set(["color","linestyle","linewidth","showarrowhead","autoscale","autoscalefactor","marker"]);function F2(e){if(!mt(e)&&!lt(e))return null;const t=mt(e)?e.toLocaleLowerCase():e.value.toLowerCase();return Lpe.has(t)?t:null}function yV(e){if(typeof e=="string")return e;if(e&&typeof e=="object"&&"kind"in e){const t=e;if(mt(t))return t;if(lt(t))return t.value}}function Ipe(e){if(e.length<2)throw new Error("quiver requires at least 2 arguments");let t=0;for(let d=0;d<e.length&&jr(e[d]);d++)t++;let n=0,r,i,s,o,a,l,c;if(t===2)c=2;else if(t===3)c=2;else if(t>=4)c=4;else throw new Error("quiver requires at least 2 numeric arguments");if(c===2){const d=e[n++],p=e[n++],m=zr(d),y=zr(p);if(a=m.rows,l=m.cols,s=m.data,o=y.data,a===1||l===1){const _=s.length;r=new Array(_),i=new Array(_);for(let b=0;b<_;b++)r[b]=b+1,i[b]=1}else{const _=Em(a,l);r=_.x,i=_.y}}else{const d=e[n++],p=e[n++],m=e[n++],y=e[n++],_=zr(m),b=zr(y);a=_.rows,l=_.cols,s=_.data,o=b.data;const x=Cm(d,p,a,l);r=x.x,i=x.y}let u=!0,h=.9;if(n<e.length&&jr(e[n])&&!_i(e[n])){const d=Ne(e[n]);d===0?u=!1:h=d*.9,n++}const f={x:r,y:i,u:s,v:o,showArrowHead:!0};for(;n<e.length&&_i(e[n])&&!F2(e[n]);){const d=yV(e[n]);if(d===void 0)break;if(d==="off"){u=!1,n++;continue}if(d==="filled"){f.markerFilled=!0,n++;continue}const p=Ju(d);if(p){p.color&&(f.color=Qu[p.color]),p.lineStyle&&(f.lineStyle=p.lineStyle),p.marker&&(f.marker=p.marker,f.showArrowHead=!1),n++;continue}const m=es(d);if(m){f.color=m,n++;continue}break}for(;n<e.length;){const d=F2(e[n]);if(!d||(n++,n>=e.length))break;const p=e[n++];switch(d){case"color":{const m=es(p);m&&(f.color=m);break}case"linestyle":f.lineStyle=Hr(p);break;case"linewidth":f.lineWidth=typeof p=="number"?p:Ne(p);break;case"marker":{const m=Hr(p);f.marker=m==="none"?void 0:m;break}case"showarrowhead":{const m=Hr(p).toLowerCase();f.showArrowHead=!(m==="off"||m==="false"||m==="0");break}case"autoscale":{const m=Hr(p).toLowerCase();u=!(m==="off"||m==="false"||m==="0");break}case"autoscalefactor":{h=(typeof p=="number"?p:Ne(p))*.9;break}}}if(u){const d=Ppe(r,i,s,o,a,l,h);if(d!==1){const p=new Array(s.length),m=new Array(o.length);for(let y=0;y<s.length;y++)p[y]=s[y]*d;for(let y=0;y<o.length;y++)m[y]=o[y]*d;f.u=p,f.v=m}}return[f]}function Ppe(e,t,n,r,i,s,o){const a=n.length;if(a===0)return 1;let l=0,c=0;for(let S=0;S<i;S++)for(let M=0;M<s-1;M++){const E=M*i+S,T=(M+1)*i+S,k=e[T]-e[E],R=t[T]-t[E],B=Math.sqrt(k*k+R*R);isFinite(B)&&B>0&&(l+=B,c++)}for(let S=0;S<i-1;S++)for(let M=0;M<s;M++){const E=M*i+S,T=M*i+S+1,k=e[T]-e[E],R=t[T]-t[E],B=Math.sqrt(k*k+R*R);isFinite(B)&&B>0&&(l+=B,c++)}const u=c>0?l/c:0;let h=1/0,f=-1/0,d=1/0,p=-1/0;for(let S=0;S<e.length;S++)isFinite(e[S])&&(e[S]<h&&(h=e[S]),e[S]>f&&(f=e[S]));for(let S=0;S<t.length;S++)isFinite(t[S])&&(t[S]<d&&(d=t[S]),t[S]>p&&(p=t[S]));const m=f-h,y=p-d;let _;m>0&&y>0?_=Math.sqrt(m*y/a):m>0?_=m/Math.max(1,a-1):y>0?_=y/Math.max(1,a-1):_=0;const b=Math.max(u,_)||1;let x=0;for(let S=0;S<a;S++){const M=n[S],E=r[S];if(!isFinite(M)||!isFinite(E))continue;const T=Math.sqrt(M*M+E*E);T>x&&(x=T)}return x===0?1:o*b/x}function Bpe(e){if(e.length<4)throw new Error("quiver3 requires at least 4 arguments");let t=0;for(let y=0;y<e.length&&jr(e[y]);y++)t++;let n=0,r,i,s,o,a,l,c,u;if((t>=6?6:4)===4){const y=zr(e[n++]);c=y.rows,u=y.cols,s=y.data,o=zr(e[n++]).data,a=zr(e[n++]).data,l=zr(e[n++]).data;const _=s.length;if(c===1||u===1){r=new Array(_),i=new Array(_);for(let b=0;b<_;b++)r[b]=b+1,i[b]=1}else{const b=Em(c,_/c);r=b.x,i=b.y}}else{const y=e[n++],_=e[n++],b=zr(e[n++]);c=b.rows,u=b.cols,s=b.data,o=zr(e[n++]).data,a=zr(e[n++]).data,l=zr(e[n++]).data;const x=o.length,S=vn(y),M=vn(_);if(S.length===x&&M.length===x)r=S,i=M;else{const E=Cm(y,_,c,u);r=E.x,i=E.y}}let f=!0,d=.9,p=.9;if(n<e.length&&jr(e[n])&&!_i(e[n])){const y=Ne(e[n]);y===0?f=!1:(d=y*.9,p=y),n++}const m={x:r,y:i,z:s,u:o,v:a,w:l,showArrowHead:!0};for(;n<e.length&&_i(e[n])&&!F2(e[n]);){const y=yV(e[n]);if(y===void 0)break;if(y==="off"){f=!1,n++;continue}if(y==="filled"){m.markerFilled=!0,n++;continue}const _=Ju(y);if(_){_.color&&(m.color=Qu[_.color]),_.lineStyle&&(m.lineStyle=_.lineStyle),_.marker&&(m.marker=_.marker,m.showArrowHead=!1),n++;continue}const b=es(y);if(b){m.color=b,n++;continue}break}for(;n<e.length;){const y=F2(e[n]);if(!y||(n++,n>=e.length))break;const _=e[n++];switch(y){case"color":{const b=es(_);b&&(m.color=b);break}case"linestyle":m.lineStyle=Hr(_);break;case"linewidth":m.lineWidth=typeof _=="number"?_:Ne(_);break;case"marker":{const b=Hr(_);m.marker=b==="none"?void 0:b;break}case"showarrowhead":{const b=Hr(_).toLowerCase();m.showArrowHead=!(b==="off"||b==="false"||b==="0");break}case"autoscale":{const b=Hr(_).toLowerCase();f=!(b==="off"||b==="false"||b==="0");break}case"autoscalefactor":{const b=typeof _=="number"?_:Ne(_);d=b*.9,p=b;break}}}if(m.autoScale=f,m.autoScaleFactor=p,f){const y=Fpe(r,i,s,o,a,l,d);y!==1&&(m.u=o.map(_=>_*y),m.v=a.map(_=>_*y),m.w=l.map(_=>_*y))}return m}function Fpe(e,t,n,r,i,s,o){const a=r.length;if(a===0)return 1;const l=m=>{let y=1/0,_=-1/0;for(const b of m)isFinite(b)&&(b<y&&(y=b),b>_&&(_=b));return _>y?_-y:0},c=l(e),u=l(t),h=l(n),f=[c,u,h].filter(m=>m>0);let d;f.length===3?d=Math.cbrt(c*u*h/a):f.length===2?d=Math.sqrt(f[0]*f[1]/a):f.length===1?d=f[0]/Math.max(1,a-1):d=1,d=d||1;let p=0;for(let m=0;m<a;m++){const y=Math.sqrt(r[m]*r[m]+i[m]*i[m]+s[m]*s[m]);isFinite(y)&&y>p&&(p=y)}return p===0?1:o*d/p}function mz(e){if(typeof e=="number")return A.num(e);if(typeof e=="boolean")return A.logical(e);if(typeof e=="string")return A.char(e);if(Array.isArray(e)){const t=D(e);return A.tensor(t,[1,e.length])}return e}const _V={line:{Color:[0,.447,.741],LineStyle:"-",LineWidth:.5,Marker:"none",MarkerSize:6},patch:{FaceColor:[0,.447,.741],EdgeColor:[0,0,0],FaceAlpha:1,LineStyle:"-",LineWidth:.5,Marker:"none"},quiver3:{LineWidth:.5,LineStyle:"-",ShowArrowHead:!0,AutoScale:!0,AutoScaleFactor:.9,Marker:"none",Color:[0,.447,.741]}};function vV(e,t){if(t in e)return t;const n=t.charAt(0).toLowerCase()+t.slice(1);if(n in e)return n;const r=t.toLowerCase();for(const i of Object.keys(e))if(i.toLowerCase()===r)return i;if(r.endsWith("data")){const i=r.slice(0,-4);for(const s of Object.keys(e))if(s.toLowerCase()===i)return s}return null}function zpe(e,t){if(Array.isArray(t)&&t.length===3&&(mt(e)||lt(e))){const n=es(e);if(n)return n}if(typeof t=="boolean"){if(typeof e=="boolean")return e;if(typeof e=="number")return e!==0;if(mt(e)||lt(e)){const n=(lt(e)?e.value:e).toLowerCase();return!(n==="off"||n==="false"||n==="0")}return!0}if(typeof t=="string")return lt(e)?e.value:mt(e)?e:String(e);if((typeof t=="number"||t===void 0)&&(typeof e=="number"||Re(e)))return e;if(Array.isArray(t)){if(ce(e))return Array.from(e.data);if(typeof e=="number")return[e]}return e}const Upe={facecolor:"faceColor",edgecolor:"edgeColor",facealpha:"faceAlpha",linewidth:"lineWidth",linestyle:"lineStyle",marker:"marker",markerfacecolor:"markerFaceColor",facevertexcdata:"faceVertexCData",cdata:"faceVertexCData"};function bV(e,t,n,r){if(t==="patch"){const a=n.toLowerCase(),l=Upe[a];if(l)return ZM(e,a,r),{key:l,value:e[l]}}const i=vV(e,n)??n.charAt(0).toLowerCase()+n.slice(1),s=e[i]??_V[t]?.[n],o=zpe(r,s);return e[i]=o,{key:i,value:o}}function DR(e,t){if(Zn(e)||In(e)){const n=e.fields.get(t);if(n===void 0)throw new q(`No field '${t}' on ${In(e)?e.className:"struct"}`);return n}if(yi(e)){if(!e.fieldNames.includes(t))throw new q(`No field '${t}' on struct array`);const n=e.elements.map(r=>{const i=r.fields.get(t);if(i===void 0)throw new q(`No field '${t}' on struct element`);return i});return wb(...n)}if(qd(e)){const n=vV(e._trace,t);if(n!==null)return mz(e._trace[n]);const r=_V[e._traceType]?.[t];if(r!==void 0)return mz(r);throw new q(`No property '${t}' on ${e._traceType} handle`)}throw new q(`Cannot access field ${t} on ${po(e)}`)}function Ope(e,t,n,r){if(In(e)){if(e.isHandleClass)return r?e.bindField(r,t,n):e.fields.set(t,n),e;if(r&&!_2(e))return e.bindField(r,t,n),e;const i=new Map(e.fields);return i.set(t,n),new D1(e.className,i,!1,e._builtinData)}if(Zn(e)){if(r&&!_2(e))return e.bindField(r,t,n),e;const i=new Map(e.fields);return i.set(t,n),A.struct(i)}if(yi(e)){if(e.elements.length===1){const i=new Map(e.elements[0].fields);return i.set(t,n),A.struct(i)}throw new q(`Cannot assign field '${t}' on a non-scalar struct array without indexing`)}return qd(e)?(bV(e._trace,e._traceType,t,n),e):Re(e)&&e===0?A.struct(new Map([[t,n]])):A.struct(new Map([[t,n]]))}const NR={pi:Math.PI,inf:1/0,Inf:1/0,nan:NaN,NaN:NaN,realmax:Number.MAX_VALUE,realmin:22250738585072014e-324};function jpe(e){if(e==="true")return A.logical(!0);if(e==="false")return A.logical(!1);if(e in NR)return A.num(NR[e]);if(e==="i"||e==="j")return A.complex(0,1)}function Hpe(){return[...Object.keys(NR),"true","false","i","j"]}const $pe={comments:{lineComment:"%",blockComment:["%{","%}"]},brackets:[["{","}"],["[","]"],["(",")"]],autoClosingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}],surroundingPairs:[{open:"{",close:"}"},{open:"[",close:"]"},{open:"(",close:")"},{open:'"',close:'"'}]};function Vpe(){const e=fR(),t=Hpe();return{defaultToken:"",keywords:["function","if","else","elseif","for","while","break","continue","return","end","classdef","properties","methods","events","enumeration","arguments","import","switch","case","otherwise","try","catch","global","persistent","true","false"],builtinFunctions:e,builtinConstants:t,tokenizer:{root:[[/^%%.*$/,"comment.doc"],[/%\{/,"comment","@blockComment"],[/%.*$/,"comment"],[/[a-zA-Z_]\w*/,{cases:{"@keywords":{token:"keyword",next:"@afterValue"},"@builtinFunctions":{token:"predefined",next:"@afterValue"},"@builtinConstants":{token:"constant.language",next:"@afterValue"},"@default":{token:"identifier",next:"@afterValue"}}}],[/\d+\.?\d*([eE][+-]?\d+)?/,{token:"number.float",next:"@afterValue"}],[/\.\d+([eE][+-]?\d+)?/,{token:"number.float",next:"@afterValue"}],[/"([^"\\]|\\.)*$/,"string.invalid"],[/'([^'\\]|\\.)*$/,"string.invalid"],[/"/,"string","@doubleQuotedString"],[/'/,"string","@singleQuotedString"],[/[)\]]/,{token:"@brackets",next:"@afterValue"}],[/\}/,{token:"@brackets",next:"@afterValue"}],[/[{([]/,"@brackets"],[/[;,.]/,"delimiter"],[/==|~=|<=|>=|&&|\|\||\.\.\.|\.\*|\.\/|\.\\|\.\^|[=<>~+\-*/\\^&|!@?:]/,"operator"],{include:"@whitespace"}],afterValue:[[/\.'/,"operator"],[/'/,"operator"],[/$/,{token:"",next:"@pop"}],[/(?=[\s\S])/,{token:"",next:"@pop"}]],blockComment:[[/%\}/,"comment","@pop"],[/./,"comment"]],doubleQuotedString:[[/[^\\"]+/,"string"],[/\\./,"string.escape"],[/"/,{token:"string",switchTo:"@afterValue"}]],singleQuotedString:[[/[^\\']+/,"string"],[/''/,"string.escape"],[/'/,{token:"string",switchTo:"@afterValue"}]],whitespace:[[/[ \t\r\n]+/,"white"]]}}}var re=(e=>(e[e.Integer=0]="Integer",e[e.Float=1]="Float",e[e.Str=2]="Str",e[e.Char=3]="Char",e[e.Ident=4]="Ident",e[e.Function=5]="Function",e[e.If=6]="If",e[e.Else=7]="Else",e[e.ElseIf=8]="ElseIf",e[e.For=9]="For",e[e.ParFor=10]="ParFor",e[e.While=11]="While",e[e.Break=12]="Break",e[e.Continue=13]="Continue",e[e.Return=14]="Return",e[e.End=15]="End",e[e.ClassDef=16]="ClassDef",e[e.Properties=17]="Properties",e[e.Methods=18]="Methods",e[e.Events=19]="Events",e[e.Enumeration=20]="Enumeration",e[e.Arguments=21]="Arguments",e[e.Import=22]="Import",e[e.Switch=23]="Switch",e[e.Case=24]="Case",e[e.Otherwise=25]="Otherwise",e[e.Try=26]="Try",e[e.Catch=27]="Catch",e[e.Global=28]="Global",e[e.Persistent=29]="Persistent",e[e.True=30]="True",e[e.False=31]="False",e[e.Plus=32]="Plus",e[e.Minus=33]="Minus",e[e.Star=34]="Star",e[e.Slash=35]="Slash",e[e.Backslash=36]="Backslash",e[e.Caret=37]="Caret",e[e.And=38]="And",e[e.Or=39]="Or",e[e.Tilde=40]="Tilde",e[e.At=41]="At",e[e.Question=42]="Question",e[e.Less=43]="Less",e[e.Greater=44]="Greater",e[e.Dot=45]="Dot",e[e.Colon=46]="Colon",e[e.Comma=47]="Comma",e[e.Assign=48]="Assign",e[e.Semicolon=49]="Semicolon",e[e.LParen=50]="LParen",e[e.RParen=51]="RParen",e[e.LBracket=52]="LBracket",e[e.RBracket=53]="RBracket",e[e.LBrace=54]="LBrace",e[e.RBrace=55]="RBrace",e[e.DotStar=56]="DotStar",e[e.DotSlash=57]="DotSlash",e[e.DotBackslash=58]="DotBackslash",e[e.DotCaret=59]="DotCaret",e[e.AndAnd=60]="AndAnd",e[e.OrOr=61]="OrOr",e[e.Equal=62]="Equal",e[e.NotEqual=63]="NotEqual",e[e.LessEqual=64]="LessEqual",e[e.GreaterEqual=65]="GreaterEqual",e[e.Transpose=66]="Transpose",e[e.Ellipsis=67]="Ellipsis",e[e.Newline=68]="Newline",e[e.Section=69]="Section",e[e.Error=70]="Error",e[e.Directive=71]="Directive",e))(re||{});const xV=new Map([["function",re.Function],["if",re.If],["else",re.Else],["elseif",re.ElseIf],["for",re.For],["parfor",re.ParFor],["while",re.While],["break",re.Break],["continue",re.Continue],["return",re.Return],["end",re.End],["classdef",re.ClassDef],["properties",re.Properties],["methods",re.Methods],["events",re.Events],["enumeration",re.Enumeration],["arguments",re.Arguments],["import",re.Import],["switch",re.Switch],["case",re.Case],["otherwise",re.Otherwise],["try",re.Try],["catch",re.Catch],["global",re.Global],["persistent",re.Persistent],["true",re.True],["false",re.False]]);re.True,re.False;function wV(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"}function Wpe(e){return wV(e)||e>="0"&&e<="9"}function Rp(e){return e>="0"&&e<="9"}function gz(e){return e===" "||e===" "||e==="\r"}function TT(e){return e===re.Ident||e===re.Integer||e===re.Float||e===re.True||e===re.False||e===re.End||e===re.RParen||e===re.RBracket||e===re.RBrace||e===re.Str||e===re.Char||e===re.Transpose}function kT(e,t=0){for(let n=t;n<e.length;n++){if(e[n]===`
|
|
173
173
|
`)return[n,1];if(e[n]==="\r")return e[n+1]===`
|
|
174
174
|
`?[n,2]:[n,1]}}const qpe={twoChar:[{pattern:".*",token:"DotStar"},{pattern:"./",token:"DotSlash"},{pattern:".\\",token:"DotBackslash"},{pattern:".^",token:"DotCaret"},{pattern:"&&",token:"AndAnd"},{pattern:"||",token:"OrOr"},{pattern:"==",token:"Equal"},{pattern:"~=",token:"NotEqual"},{pattern:"<=",token:"LessEqual"},{pattern:">=",token:"GreaterEqual"}],singleChar:[{pattern:"+",token:"Plus"},{pattern:"-",token:"Minus"},{pattern:"*",token:"Star"},{pattern:"/",token:"Slash"},{pattern:"\\",token:"Backslash"},{pattern:"^",token:"Caret"},{pattern:"&",token:"And"},{pattern:"|",token:"Or"},{pattern:"~",token:"Tilde"},{pattern:"@",token:"At"},{pattern:"?",token:"Question"},{pattern:"<",token:"Less"},{pattern:">",token:"Greater"},{pattern:".",token:"Dot"},{pattern:":",token:"Colon"},{pattern:",",token:"Comma"},{pattern:"=",token:"Assign"},{pattern:";",token:"Semicolon",special:"semicolonQuoteHeuristic"},{pattern:"(",token:"LParen"},{pattern:")",token:"RParen"},{pattern:"[",token:"LBracket"},{pattern:"]",token:"RBracket"},{pattern:"{",token:"LBrace"},{pattern:"}",token:"RBrace"}]},Gpe={blockComment:{start:"%{",end:"%}"},sectionMarker:{pattern:"%%",token:"Section"},lineComment:{start:"%"}},Xpe=[{delimiter:'"',escape:'""',token:"Str",allowMultiline:!1},{delimiter:"'",escape:"''",token:"Char",allowMultiline:!1,disambiguation:{type:"transpose",transposeToken:"Transpose",conditions:{requireAdjacency:!0,requirePrevValueOrDot:!0}}}],Ype={ellipsis:{pattern:"...",token:"Ellipsis"},newline:{pattern:`
|
|
175
175
|
`}},Kpe={integerToken:"Integer",floatToken:"Float",exponentChars:["e","E","d","D"],decimalPoint:".",dotOperatorPrefixes:["*","/","\\","^"]},Zpe={operators:qpe,comments:Gpe,strings:Xpe,special:Ype,numbers:Kpe},zc=Zpe;function Qpe(){const e=new Map;for(const t of zc.operators.twoChar)e.set(t.pattern,re[t.token]);return e}function Jpe(){const e=new Map;for(const t of zc.operators.singleChar)e.set(t.pattern,re[t.token]);return e}function eme(e){return zc.operators.singleChar.find(n=>n.pattern===e)?.special}const tme=Qpe(),nme=Jpe();function rme(e){const t=[];let n=0,r=!0;for(;n<e.length;){if(gz(e[n])){n++;continue}const i=e[n];if(i===zc.special.newline.pattern){const u=n;for(t.push({token:re.Newline,lexeme:i,start:u,end:n+1}),n++;n<e.length&&e[n]===`
|
|
@@ -4810,7 +4810,7 @@ directive is a comment, so MATLAB ignores it.`},disp:{signatures:["disp(X)"],des
|
|
|
4810
4810
|
|
|
4811
4811
|
`);u=p.pop()||"";for(const m of p){const y=m.trim();if(!y.startsWith("data: "))continue;const _=y.slice(6);try{const b=JSON.parse(_);b.type==="output"?t.onOutput(b.text):b.type==="drawnow"?t.onDrawnow(b.plotInstructions):b.type==="done"?h={...h,generatedJS:b.generatedJS}:b.type==="error"?h={success:!1,error:b.message,timedOut:b.timedOut}:b.type==="close"&&(h={...h,success:b.success})}catch{}}}return h}catch(o){return o instanceof DOMException&&o.name==="AbortError"?{success:!1,error:"Execution aborted"}:(console.error("Remote execution failed:",o),{success:!1,error:o instanceof Error?`Connection failed: ${o.message}`:"Unknown error occurred"})}}const ON="/system/";function AIe(e){return e.startsWith("/project/")?e.slice(9):e.startsWith("/")?e.slice(1):e}function uY(e){return e.startsWith(ON)?e.slice(ON.length):e}function y3(e){return e.startsWith(ON)||e==="/system"}function hY(e){const t={created:[],modified:[],deleted:[]},n={created:[],modified:[],deleted:[]};for(const r of e.created)(y3(r.path)?n:t).created.push(r);for(const r of e.modified)(y3(r.path)?n:t).modified.push(r);for(const r of e.deleted)(y3(r)?n:t).deleted.push(r);return{projectChanges:t,systemChanges:n}}async function jN(e,t,n){const r=[],i=[],s=[];return await kn.transaction("rw",kn.files,kn.fileContents,kn.projects,async()=>{for(const{path:o,content:a}of t.created){const l=n(o),c=Date.now(),u=crypto.randomUUID();await kn.files.add({id:u,projectName:e,path:l,createdAt:c,updatedAt:c}),await kn.fileContents.add({id:u,data:a}),r.push({id:u,name:l})}for(const{path:o,content:a}of t.modified){const l=n(o),c=await kn.files.where("[projectName+path]").equals([e,l]).first();c&&(await kn.fileContents.put({id:c.id,data:a}),await kn.files.update(c.id,{updatedAt:Date.now()}),i.push({path:l,data:a}))}for(const o of t.deleted){const a=n(o),l=await kn.files.where("[projectName+path]").equals([e,a]).first();l&&(await kn.files.delete(l.id),await kn.fileContents.delete(l.id),s.push(a))}(r.length>0||i.length>0||s.length>0)&&await kn.projects.update(e,{updatedAt:Date.now()})}),r.length===0&&i.length===0&&s.length===0?null:{addedFiles:r,modifiedFiles:i,deletedPaths:s}}async function fY(e){const{systemChanges:t}=hY(e);return t.created.length===0&&t.modified.length===0&&t.deleted.length===0?!1:(await I0(),await jN(Ul,t,uY)!==null)}async function TIe(e,t){const{projectChanges:n,systemChanges:r}=hY(t),i=await jN(e,n,AIe);let s=null;return(r.created.length>0||r.modified.length>0||r.deleted.length>0)&&(await I0(),s=await jN(Ul,r,uY)),{projectResult:i,systemResult:s}}const oa="system/";function dY(){const[e,t]=ne.useState([]),n=ne.useRef(new Map),r=ne.useCallback(async()=>{const _=await jA();t(_.map(b=>({id:b.id,name:oa+b.path})))},[]);ne.useEffect(()=>{r()},[r]);const i=ne.useCallback(async _=>{const b=n.current.get(_);if(b!==void 0)return b;const x=await pF(_);return n.current.set(_,x),x},[]),s=ne.useCallback(async()=>{const _=await HA();for(const[b,x]of _)n.current.set(b,x);return _},[]),o=ne.useCallback(async()=>{const[_,b]=await Promise.all([jA(),HA()]);return _.map(x=>({path:"/system/"+x.path,content:b.get(x.id)??new Uint8Array(0)}))},[]),a=ne.useCallback(async()=>{const _=new TextDecoder("utf-8"),[b,x]=await Promise.all([jA(),HA()]);return b.filter(S=>S.path.endsWith(".m")).map(S=>({name:"/system/"+S.path,source:_.decode(x.get(S.id)??new Uint8Array(0))}))},[]),l=ne.useCallback(async(_,b)=>{n.current.set(_,b),await Koe(_,b)},[]),c=ne.useCallback(async _=>{await I0();const b=_?.startsWith(oa)?_.slice(oa.length):_,x=N7(e,_),S=b?`${b}/${x}`:x,M=Date.now(),E=crypto.randomUUID(),T=new Uint8Array(0);return await kn.transaction("rw",kn.files,kn.fileContents,async()=>{await kn.files.add({id:E,projectName:Ul,path:S,createdAt:M,updatedAt:M}),await kn.fileContents.add({id:E,data:T})}),n.current.set(E,T),t(k=>[...k,{id:E,name:oa+S}]),E},[e]),u=ne.useCallback(async _=>{await I0();const b=_?.startsWith(oa)?_.slice(oa.length):_,x=kIe(e,_),S=b?`${b}/${x}`:x,M=N7(e,oa+S),E=`${S}/${M}`,T=Date.now(),k=crypto.randomUUID(),R=new Uint8Array(0);return await kn.transaction("rw",kn.files,kn.fileContents,async()=>{await kn.files.add({id:k,projectName:Ul,path:E,createdAt:T,updatedAt:T}),await kn.fileContents.add({id:k,data:R})}),n.current.set(k,R),t(B=>[...B,{id:k,name:oa+E}]),oa+S},[e]),h=ne.useCallback(async _=>{await kn.transaction("rw",kn.files,kn.fileContents,async()=>{await kn.files.delete(_),await kn.fileContents.delete(_)}),n.current.delete(_),t(b=>b.filter(x=>x.id!==_))},[]),f=ne.useCallback(async _=>{const b=e.filter(x=>x.name.startsWith(_+"/"));await kn.transaction("rw",kn.files,kn.fileContents,async()=>{for(const x of b)await kn.files.delete(x.id),await kn.fileContents.delete(x.id)});for(const x of b)n.current.delete(x.id);t(x=>x.filter(S=>!S.name.startsWith(_+"/")))},[e]),d=ne.useCallback(async(_,b)=>{const x=b.startsWith(oa)?b.slice(oa.length):b;await kn.files.update(_,{path:x,updatedAt:Date.now()}),t(S=>S.map(M=>M.id===_?{...M,name:b}:M))},[]),p=ne.useCallback(async(_,b)=>{const x=_.split("/");x[x.length-1]=b;const S=x.join("/"),M=e.filter(E=>E.name.startsWith(_+"/"));await Promise.all(M.map(E=>{const T=S+E.name.slice(_.length),k=T.startsWith(oa)?T.slice(oa.length):T;return kn.files.update(E.id,{path:k,updatedAt:Date.now()})})),t(E=>E.map(T=>T.name.startsWith(_+"/")?{...T,name:S+T.name.slice(_.length)}:T))},[e]),m=ne.useCallback(async _=>{const b=e.find(R=>R.id===_);if(!b)return"";const x=PH(e,b.name),S=x.startsWith(oa)?x.slice(oa.length):x,M=n.current.get(_)??await pF(_),E=new Uint8Array(M),T=Date.now(),k=crypto.randomUUID();return await I0(),await kn.transaction("rw",kn.files,kn.fileContents,async()=>{await kn.files.add({id:k,projectName:Ul,path:S,createdAt:T,updatedAt:T}),await kn.fileContents.add({id:k,data:E})}),n.current.set(k,E),t(R=>[...R,{id:k,name:x}]),k},[e]),y=ne.useCallback(async(_,b)=>{const x=e.find(k=>k.id===_);if(!x)return;const S=x.name.split("/"),M=S[S.length-1],E=b?`${b}/${M}`:M;if(E===x.name)return;const T=E.startsWith(oa)?E.slice(oa.length):E;await kn.files.update(_,{path:T,updatedAt:Date.now()}),t(k=>k.map(R=>R.id===_?{...R,name:E}:R))},[e]);return{systemFiles:e,reloadSystemFiles:r,updateSystemFileContent:l,addSystemFile:c,addSystemFolder:u,deleteSystemFile:h,deleteSystemFolder:f,renameSystemFile:d,renameSystemFolder:p,moveSystemFile:y,duplicateSystemFile:m,loadSystemFileContent:i,loadAllSystemContents:s,getSystemVfsFiles:o,getSystemWorkspaceFiles:a,systemContentCache:n}}function N7(e,t){const n=new Set(e.map(r=>r.name));for(let r=1;;r++){const i=`untitled${r===1?"":r}.m`,s=t?`${t}/${i}`:i;if(!n.has(s))return i}}function kIe(e,t){const n=new Set;for(const r of e)if(t){if(r.name.startsWith(t+"/")){const i=r.name.slice(t.length+1).split("/");i.length>1&&n.add(i[0])}}else{const i=r.name.split("/");i.length>1&&n.add(i[0])}for(let r=1;;r++){const i=`folder${r===1?"":r}`;if(!n.has(i))return i}}const RIe="https://github.com/mip-org/mip-core/releases/download/mip-numbl/mip-numbl-any.mhl",DIe="mip/packages/gh/mip-org/core/mip/";function NIe(e){if(/^https:\/\/github\.com\/.+\/releases\/download\/.+/.test(e)){let t=e.replace("https://github.com/","https://mip-cors-proxy.figurl.workers.dev/gh/");return t+=t.includes("?")?"&":"?",t+="t="+Date.now(),t}return e}async function LIe(){const e=await fetch(NIe(RIe));if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.arrayBuffer();return HH(new Uint8Array(t)).map(r=>({path:"/system/"+DIe+r.path,content:r.content}))}const IIe=600*1e3,pY="numbl:systemLastActivity";function mY(){try{localStorage.setItem(pY,String(Date.now()))}catch{}}function PIe(){try{const e=localStorage.getItem(pY),t=e?parseInt(e,10):0;return Number.isFinite(t)?t:0}catch{return 0}}function gY(e){ne.useEffect(()=>{let t=!1;return(async()=>{try{if(Date.now()-PIe()>IIe&&await Qoe(),mY(),t)return;if(await I0(),!await Zoe()){const n=await LIe();if(t)return;const r=Date.now();await kn.transaction("rw",kn.files,kn.fileContents,async()=>{const i=n.map(o=>{const a=o.path.replace(/^\/system\//,"");return{id:"mip:"+a,projectName:Ul,path:a,createdAt:r,updatedAt:r}}),s=n.map(o=>({id:"mip:"+o.path.replace(/^\/system\//,""),data:o.content}));await kn.files.bulkPut(i),await kn.fileContents.bulkPut(s)})}t||e()}catch(n){console.warn("Failed to ensure mip core package:",n)}})(),()=>{t=!0}},[])}qu.registerLanguage("javascript",UL);qu.registerLanguage("c",Nce);const BIe=new TextEncoder;function FIe({files:e,activeFileId:t,setActiveFileId:n,updateFileContent:r,addFile:i,addFolder:s,deleteFile:o,deleteFolder:a,renameFile:l,renameFolder:c,moveFile:u,duplicateFile:h,uploadFiles:f,headerContent:d,projectName:p,loadFileContent:m,loadAllContents:y,contentCache:_,maxInitialOutputPanelHeight:b,mergeVfsChanges:x}){const{systemFiles:S,reloadSystemFiles:M,updateSystemFileContent:E,addSystemFile:T,addSystemFolder:k,deleteSystemFile:R,deleteSystemFolder:B,renameSystemFile:F,renameSystemFolder:L,moveSystemFile:j,duplicateSystemFile:V,loadSystemFileContent:O,getSystemVfsFiles:P,getSystemWorkspaceFiles:N,loadAllSystemContents:H}=dY();gY(M);const U=ne.useCallback(ot=>ot==="system"||ot.startsWith("system/"),[]),G=ne.useCallback(ot=>S.some(It=>It.id===ot),[S]),Z=ne.useMemo(()=>[...e,...S],[e,S]),[ie,Y]=ne.useState("1"),[ue,ge]=ne.useState(""),[te,X]=ne.useState(null),[de,fe]=ne.useState(""),[ae,J]=ne.useState(!1),[K,Se]=ne.useReducer(_I,QM),[ye,Ge]=ne.useState(0),[Fe,Ue]=ne.useState("js"),[Ee,ke]=ne.useState([]),_e=ne.useCallback(ot=>{const It=[];ot?.mainFile&&It.push({name:ot.mainFile.name,ast:ot.mainFile.ast,irProgram:ot.mainFile.irProgram});for(const un of ot?.workspaceFiles??[])It.push({name:un.name,ast:un.ast,irProgram:un.irProgram});return It},[]),we=ne.useMemo(()=>{if(Ee.length===0)return null;if(Ee.length===1)return Ee[0].ast;const ot={};for(const It of Ee)ot[It.name]=It.ast;return ot},[Ee]),[Le,oe]=ne.useState(null),[Q,xe]=ne.useState(0),[me,be]=ne.useState(!1),[ve,Be]=ne.useState(),[He,je]=ne.useState("rendered"),[st,We]=ne.useState(0),[ct,kt]=ne.useState(!1),rt=ne.useRef(null),at=Voe("(max-width:768px)"),Pe=ne.useRef(at);Pe.current=at;const[Ae,ze]=ne.useState(!1),[_t,zt]=ne.useState(0),[xt,vt]=ne.useState(!1),[At,Wt]=ne.useState(fM()),[Ut,Yt]=ne.useState(!1),[Ot,hn]=ne.useState(fM()),rr=ne.useCallback(()=>{const ot=crypto.randomUUID().replace(/-/g,"").slice(0,16);return sessionStorage.setItem("numbl_passkey",ot),ot},[]),[yn,Qn]=ne.useState(()=>{const ot=sessionStorage.getItem("numbl_passkey");return ot||rr()}),Gi=ne.useRef(yn);Gi.current=yn;const ns=xt?"localhost":"browser",[vi,Ks]=ne.useState(null),[Si,Lr]=ne.useState("unknown");ne.useEffect(()=>{if(!xt){Ks(null),Lr("unknown");return}let ot=!1;return D7(At,Gi.current).then(It=>{ot||(It?(Ks(It.nativeAddon===!0),Lr("connected")):Lr("disconnected"))}),()=>{ot=!0}},[xt,At,yn]);const cr=ne.useRef(null),Xi=ne.useRef(WH()),Yi=ne.useRef(typeof SharedArrayBuffer<"u"?new SharedArrayBuffer(4):null),No=ne.useRef(null),js=ne.useRef(null),za=ne.useRef(null),[Ki,Vl]=ne.useState(!1);ne.useEffect(()=>{cr.current?.postMessage({type:"set_optimization",optimization:ie})},[ie]);const Xo=window.innerWidth>=1200?260:200,[mr,Zs]=ne.useState(Xo),[Ce,Je]=ne.useState((window.innerWidth-Xo)/2),[St,yt]=ne.useState(()=>b!=null?Math.min(window.innerHeight/2,b):window.innerHeight/2),pt=b!=null?Math.min(150,b):150,Gt=ne.useMemo(()=>Z.find(ot=>ot.id===t),[Z,t]),ht=ne.useCallback(ot=>{let It=ot.split(/[?#]/)[0];try{It=decodeURIComponent(It)}catch{}if(It=It.replace(/^\.\//,""),!It)return;const un=Qr=>Qr.split("/").pop()??Qr,Ar=Z.find(Qr=>Qr.name===It)??Z.find(Qr=>un(Qr.name)===un(It));Ar&&(n(Ar.id),at&&ze(!1))},[Z,n,at]),Et=ne.useMemo(()=>Object.keys(K.figs).map(ot=>Number(ot)).sort((ot,It)=>ot-It),[K.figs]),[qt,en]=ne.useState(!1),Xt=ne.useCallback(async()=>{const ot=Et[Q],It=K.figs[ot];if(It){en(!0);try{await oxe(It,ot)}catch(un){console.error("Figure HDF5 export failed:",un)}finally{en(!1)}}},[K.figs,Et,Q]),[Dn,rn]=ne.useState(null),Ln=ne.useCallback(async()=>{const ot=K.figs[Et[Q]];if(!ot)return;const It=mxe(ot);if(It.url){window.open(It.url,"_blank"),rn(null);return}rn({kind:"uploading"});try{const un=await xxe(ot);rn({kind:"ready",url:un})}catch{rn({kind:"failed",baseUrl:It.baseUrl})}},[K.figs,Et,Q]);ne.useEffect(()=>{const ot=Object.keys(K.figs).map(Number).sort((It,un)=>It-un);if(ot.length>0){const It=ot.indexOf(K.currentHandle);It>=0&&xe(It)}},[K.figs,K.currentHandle]);const Jn=ne.useCallback(ot=>{if(Se(ot),!Pe.current)return;const It=ot.type;It.startsWith("set_")||It==="cla"||It==="clf"||It==="close"||It==="close_all"||zt(1)},[]);ne.useEffect(()=>{const ot=It=>{const un=It.data;!un||un.source!=="numbl-uihtml"||cr.current?.postMessage({type:"html_event",compId:un.compId,kind:un.kind,name:un.name,data:un.data})};return window.addEventListener("message",ot),()=>window.removeEventListener("message",ot)},[]),ne.useEffect(()=>{if(!me)return;const ot=It=>{It.key==="Escape"&&be(!1)};return window.addEventListener("keydown",ot),()=>window.removeEventListener("keydown",ot)},[me]);const br=ne.useCallback(async(ot,It)=>{const[un,Ar,Qr]=await Promise.all([y(),P(),N()]),Ei=await H(),Wl=[...ot.map(ai=>({path:ai.name,content:un.get(ai.id)??new Uint8Array(0)})),...Ar],ji=new TextDecoder("utf-8"),go=[...ot.filter(ai=>!It||ai.id!==It).filter(ai=>ai.name.endsWith(".m")).map(ai=>({name:ai.name,source:ji.decode(un.get(ai.id)??new Uint8Array(0))})),...Qr];return{vfsFiles:Wl,workspaceFiles:go,projectContents:un,systemContents:Ei}},[y,P,N,H]),gr=ne.useCallback(async ot=>{if(!ot)return;const{created:It,modified:un,deleted:Ar}=ot;if(!(It.length===0&&un.length===0&&Ar.length===0))if(p){const{projectResult:Qr,systemResult:Ei}=await TIe(p,ot);Qr&&x&&x(Qr),Ei&&M()}else await fY(ot)&&M()},[p,x,M]),Mi=ne.useCallback(ot=>{ot.onmessage=It=>{const un=It.data;if(un.type==="request-input"){const Ar=prompt(un.prompt??"")??"",Qr=Xi.current;Qr&&qH(Qr,Ar);return}if(un.type==="output"){if(No.current==="repl"){const Ar=rt.current;Ar?.writeOutput&&Ar.writeOutput(un.text,!1)}else ge(Ar=>Ar+un.text);return}if(un.type==="drawnow"){if(un.plotInstructions?.length)for(const Ar of un.plotInstructions)Jn(Ar);return}if(un.type==="html_source_event"){document.querySelectorAll(`iframe[title="uihtml-${un.compId}"]`).forEach(Qr=>Qr.contentWindow?.postMessage({source:"numbl-host",compId:un.compId,name:un.name,dataJson:un.dataJson},"*"));return}if(un.type==="done"){if(No.current=null,fe(un.generatedJS||""),ke(_e(un.workspaceRep)),oe(un.workspaceRep?.fileSources??null),X(un.dispatchUnknownCounts??null),J(!1),un.plotInstructions?.length)for(const Ar of un.plotInstructions)Jn(Ar);gr(un.vfsChanges);return}if(un.type==="error"){No.current=null,un.generatedJS&&fe(un.generatedJS),ke(_e(un.workspaceRep)),oe(un.workspaceRep?.fileSources??null),J(!1),ge(Ar=>Ar+`
|
|
4812
4812
|
${EV(un)}
|
|
4813
|
-
`),gr(un.vfsChanges);return}if(un.type==="result"){No.current=null;const Ar=rt.current;if(un.success){if(un.plotInstructions?.length)for(const Qr of un.plotInstructions)Jn(Qr)}else un.error&&Ar?.writeOutput&&Ar.writeOutput(un.error,!0);gr(un.vfsChanges),Ar?.writePrompt&&Ar.writePrompt(),kt(!1);return}},ot.onerror=It=>{No.current=null;const un=rt.current;un?.writeOutput&&un.writeOutput(`Worker error: ${It.message}`,!0),J(!1),kt(!1)}},[Jn,_e,gr]);ne.useEffect(()=>{const ot=new Worker(new URL(""+new URL("numbl-worker-
|
|
4813
|
+
`),gr(un.vfsChanges);return}if(un.type==="result"){No.current=null;const Ar=rt.current;if(un.success){if(un.plotInstructions?.length)for(const Qr of un.plotInstructions)Jn(Qr)}else un.error&&Ar?.writeOutput&&Ar.writeOutput(un.error,!0);gr(un.vfsChanges),Ar?.writePrompt&&Ar.writePrompt(),kt(!1);return}},ot.onerror=It=>{No.current=null;const un=rt.current;un?.writeOutput&&un.writeOutput(`Worker error: ${It.message}`,!0),J(!1),kt(!1)}},[Jn,_e,gr]);ne.useEffect(()=>{const ot=new Worker(new URL(""+new URL("numbl-worker-DddtCPW_.js",import.meta.url).href,import.meta.url),{type:"module"});return cr.current=ot,Xi.current&&ot.postMessage({type:"set_input_sab",inputSAB:Xi.current}),Mi(ot),()=>{ot.terminate()}},[Mi]);const Zt=ne.useRef(!0);ne.useEffect(()=>{Zt.current=!0},[e,S]),ne.useEffect(()=>{if(ve){const ot=setTimeout(()=>{Be(void 0)},100);return()=>clearTimeout(ot)}},[ve]);const rs=ne.useCallback(async()=>{if(!Gt||!Gt.name.toLowerCase().endsWith(".m"))return;J(!0),ge(""),X(null),ke([]),oe(null),Se({type:"clear"}),zt(0);const{vfsFiles:ot,workspaceFiles:It,projectContents:un}=await br(e,t),Ar=un.get(t)??_.current.get(t)??new Uint8Array(0),Qr=T_(Ar);try{const Ei=SV(Qr);console.info("AST:",Ei)}catch{console.info("Parse check skipped - error will be handled by worker")}if(xt){const Ei=new AbortController;js.current=Ei;try{const Wl=new TextDecoder("utf-8"),ji=[];for(const ai of e){if(ai.name==="system"||ai.name.startsWith("system/"))continue;const Zo=un.get(ai.id)??_.current.get(ai.id)??new Uint8Array(0);$A(Zo)||ji.push({name:ai.name,content:Wl.decode(Zo)})}if(!ji.some(ai=>ai.name===Gt.name))ji.push({name:Gt.name,content:Qr});else{const ai=ji.findIndex(Zo=>Zo.name===Gt.name);ji[ai]={name:Gt.name,content:Qr}}const go=await CIe({files:ji,mainScript:Gt.name,optimization:ie},{onOutput:ai=>{ge(Zo=>Zo+ai)},onDrawnow:ai=>{for(const Zo of ai)Jn(Zo)}},At,Ei.signal,Gi.current);fe(go.generatedJS||""),go.success||ge(ai=>ai+`
|
|
4814
4814
|
Error: ${go.error}${go.timedOut?" (timed out)":""}
|
|
4815
4815
|
`)}catch(Wl){ge(ji=>ji+`
|
|
4816
4816
|
Remote execution failed: ${Wl instanceof Error?Wl.message:"Unknown error"}
|
|
@@ -4818,7 +4818,7 @@ Remote execution failed: ${Wl instanceof Error?Wl.message:"Unknown error"}
|
|
|
4818
4818
|
--- Execution stopped ---
|
|
4819
4819
|
`);return}if(cr.current)if(Ki){if(Yi.current){const ot=new Int32Array(Yi.current);Atomics.store(ot,0,1)}ge(ot=>ot+`
|
|
4820
4820
|
--- Cancelling execution... ---
|
|
4821
|
-
`)}else{cr.current.terminate(),No.current=null;const ot=new Worker(new URL(""+new URL("numbl-worker-
|
|
4821
|
+
`)}else{cr.current.terminate(),No.current=null;const ot=new Worker(new URL(""+new URL("numbl-worker-DddtCPW_.js",import.meta.url).href,import.meta.url),{type:"module"});cr.current=ot,Xi.current&&ot.postMessage({type:"set_input_sab",inputSAB:Xi.current}),Mi(ot),Zt.current=!0,J(!1),ge(It=>It+`
|
|
4822
4822
|
--- Execution stopped ---
|
|
4823
4823
|
`)}},[Ki,Mi]),Oi=ne.useCallback(()=>{Wt(Ot),EIe(Ot),Yt(!1)},[Ot]),Zi=ne.useCallback((ot,It)=>{It!==null&&vt(It==="local")},[]),mo=ne.useCallback(async ot=>{if(!(ct||ae)){if(kt(!0),Zt.current&&cr.current){const{vfsFiles:It,workspaceFiles:un}=await br(e);cr.current.postMessage({type:"update_workspace",workspaceFiles:un,vfsFiles:It}),Zt.current=!1}if(Yi.current){const It=new Int32Array(Yi.current);Atomics.store(It,0,0)}No.current="repl",cr.current?.postMessage({type:"execute",code:ot,cancelSAB:Yi.current??void 0})}},[ct,ae,e,br]),ms=ne.useCallback(()=>{ct||cr.current?.postMessage({type:"clear"})},[ct]),_n=ne.useCallback(ot=>{rt.current=ot},[]),ni=ne.useRef(""),[ir,er]=ne.useState(null),jn=ne.useRef(""),Ls=ir?$A(ir):!1,Yo=!!Gt?.name.toLowerCase().endsWith(".md"),ch=!!Gt?.name.toLowerCase().endsWith(".m");ne.useEffect(()=>{if(!t){er(null),jn.current="";return}er(null),jn.current="";let ot=!1;return(S.some(Ar=>Ar.id===t)?O:m)(t).then(Ar=>{ot||(jn.current=t,er(Ar))}),()=>{ot=!0}},[t,S,O,m]);const mn=Ls||Yo&&He==="rendered";ne.useEffect(()=>{mn&&(za.current=null,ni.current="")},[mn]),ne.useEffect(()=>{if(!za.current||!Gt||t===ni.current||!ir||jn.current!==t)return;ni.current=t;const ot=$A(ir)?"":T_(ir);za.current.value!==ot&&za.current.setValue(ot)},[t,Gt,ir]);const Tn=(ot,It)=>{za.current=ot,ir&&jn.current===t&&(ni.current=t),It.languages.register({id:"numbl"}),It.languages.setLanguageConfiguration("numbl",$pe),It.languages.setMonarchTokensProvider("numbl",Vpe()),It.editor.defineTheme("numbl-dark",{base:"vs-dark",inherit:!0,rules:[{token:"comment",foreground:"6A9955"},{token:"keyword",foreground:"C586C0"},{token:"number",foreground:"B5CEA8"},{token:"string",foreground:"CE9178"},{token:"operator",foreground:"D4D4D4"}],colors:{}}),It.editor.setTheme("numbl-dark")},Hn=le.jsxs(Cn,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[le.jsxs(Yy,{value:xt?0:st,onChange:(ot,It)=>We(It),sx:{borderBottom:1,borderColor:"divider",minHeight:34,"& .MuiTab-root":{textTransform:"none",fontWeight:500,fontSize:"0.8rem",minHeight:34,py:0}},children:[le.jsx(lu,{label:"Script"}),!xt&&le.jsx(lu,{label:"REPL"})]}),le.jsx(Cn,{sx:{flexGrow:1,overflow:"hidden"},children:(st===0||xt)&&!Gt?le.jsxs(Cn,{sx:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",gap:2,p:3},children:[le.jsx(Fr,{variant:"body2",color:"text.secondary",children:"No file open"}),le.jsx(Md,{variant:"contained",size:"small",startIcon:le.jsx(Fce,{}),onClick:()=>i(),sx:{textTransform:"none"},children:"New file"})]}):st===0||xt?le.jsxs(Cn,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[le.jsxs(Cn,{sx:{px:1.5,py:.5,borderBottom:1,borderColor:"divider",display:"flex",alignItems:"center",gap:1,bgcolor:"background.default"},children:[ch&&le.jsxs(le.Fragment,{children:[le.jsx(Md,{variant:"contained",color:ae?"error":"success",size:"small",startIcon:ae?le.jsx(Pce,{}):le.jsx(Ice,{}),onClick:ae?Fn:rs,sx:{py:.25,px:2,fontSize:"0.8rem",fontWeight:600,textTransform:"none",borderRadius:1.5,boxShadow:"none","&:hover":{boxShadow:"none"}},children:ae?"Stop":"Run"}),le.jsx(Su,{title:ns==="browser"?"Executing in browser":"Executing on local server"+(Si==="disconnected"?" (not connected)":"")+(vi===!0?" (native)":vi===!1?" (no native addon)":""),children:le.jsx(lo,{size:"small",onClick:()=>{hn(At),Yt(!0)},sx:{opacity:.5,"&:hover":{opacity:1}},children:ns==="browser"?le.jsx(VF,{sx:{fontSize:"0.9rem"}}):le.jsx(WF,{sx:{fontSize:"0.9rem",color:"error.main"}})})}),ns==="localhost"&&le.jsx(Fr,{variant:"caption",sx:{fontSize:"0.65rem",opacity:.5,color:"error.main"},children:Si==="disconnected"?"no server":vi?"native":vi===!1?"no native":"local"}),!xt&&le.jsx(Su,{title:Ki?"Workspace persists across runs and REPL (click for fresh each run)":"Fresh workspace each run (click to persist across runs and REPL)",children:le.jsx(Fr,{variant:"caption",onClick:()=>Vl(ot=>!ot),sx:{cursor:"pointer",fontSize:"0.7rem",px:.5,py:.1,borderRadius:.5,bgcolor:Ki?"action.selected":"transparent",opacity:Ki?1:.5,"&:hover":{opacity:1},userSelect:"none"},children:Ki?"persist":"1x"})}),le.jsx(Su,{title:ie==="0"?"Interpreter only (click for JIT)":"JIT (click to disable)",children:le.jsx(Fr,{variant:"caption",onClick:()=>Y(ot=>ot==="0"?"1":"0"),sx:{cursor:"pointer",fontSize:"0.7rem",px:.5,py:.1,borderRadius:.5,bgcolor:ie!=="0"?"action.selected":"transparent",opacity:ie!=="0"?1:.5,"&:hover":{opacity:1},userSelect:"none"},children:ie==="0"?"no jit":"jit"})})]}),Yo&&le.jsxs(OA,{value:He,exclusive:!0,size:"small",onChange:(ot,It)=>{It&&je(It)},sx:{"& .MuiToggleButton-root":{py:0,px:1,fontSize:"0.7rem",textTransform:"none",lineHeight:1.6}},children:[le.jsx(Ap,{value:"rendered",children:"Rendered"}),le.jsx(Ap,{value:"source",children:"Source"})]}),Gt&&le.jsx(Fr,{variant:"caption",color:"text.secondary",sx:{fontFamily:"monospace",fontWeight:"bold"},children:Gt.name})]}),le.jsx(Cn,{sx:{flexGrow:1,minHeight:0},children:Ls?le.jsx(Cn,{sx:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:"text.secondary"},children:le.jsxs(Fr,{variant:"body2",children:["Binary file (",ir?.length??0," bytes)"]})}):Yo&&He==="rendered"?le.jsx(Cn,{sx:{height:"100%",overflow:"auto",p:3},children:le.jsx(SIe,{source:ir?T_(ir):"",onFileLink:ht})}):le.jsx(Fle,{height:"100%",language:Gt?.name.endsWith(".js")?"javascript":Yo?"markdown":"numbl",defaultValue:ir?T_(ir):"",onChange:ot=>{const It=BIe.encode(ot||"");er(It),Zt.current=!0,G(t)?E(t,It):r(ot||"")},onMount:Tn,options:{minimap:{enabled:!1},fontSize:14,lineNumbers:"on",scrollBeyondLastLine:!1}})})]}):le.jsx(z2e,{onExecute:mo,onClear:ms,isExecuting:ct,onTerminalReady:_n})})]}),pr=le.jsxs(Cn,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[le.jsxs(Yy,{value:ye,onChange:(ot,It)=>Ge(It),sx:{borderBottom:1,borderColor:"divider",minHeight:34,"& .MuiTab-root":{textTransform:"none",fontWeight:500,fontSize:"0.8rem",minHeight:34,py:0}},children:[le.jsx(lu,{label:"Output"}),le.jsx(lu,{label:"Internals"})]}),le.jsxs(Cn,{sx:{flexGrow:1,overflow:"hidden"},children:[ye===0&&le.jsx(Cn,{sx:{height:"100%",overflow:"auto",p:1.5},children:ue?le.jsx("pre",{style:{margin:0,fontFamily:'Menlo, Monaco, "Courier New", monospace',fontSize:"13px",lineHeight:1.5,whiteSpace:"pre-wrap"},children:ue}):le.jsx(Fr,{variant:"body2",color:"text.disabled",sx:{fontStyle:"italic",mt:2,textAlign:"center"},children:"Run a script to see output here"})}),ye===1&&le.jsxs(Cn,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[le.jsx(Cn,{sx:{display:"flex",alignItems:"center",px:1,py:.5},children:le.jsxs(OA,{value:Fe,exclusive:!0,onChange:(ot,It)=>{It&&Ue(It)},size:"small",children:[le.jsx(Ap,{value:"js",sx:{py:0,px:1,fontSize:"0.75rem",textTransform:"none"},children:"JavaScript"}),le.jsx(Ap,{value:"ast",sx:{py:0,px:1,fontSize:"0.75rem",textTransform:"none"},children:"AST"}),le.jsx(Ap,{value:"dispatch",sx:{py:0,px:1,fontSize:"0.75rem",textTransform:"none"},children:"Dispatch"})]})}),le.jsxs(Cn,{sx:{flexGrow:1,overflow:"hidden"},children:[Fe==="js"&&le.jsx(Cn,{sx:{height:"100%",overflow:"auto"},children:le.jsx(qu,{language:"javascript",style:$F,customStyle:{margin:0,fontSize:12},children:de||""})}),Fe==="ast"&&le.jsx(j9,{data:we,label:"ast",fileSources:Le}),Fe==="dispatch"&&le.jsx(Cn,{sx:{height:"100%",overflow:"auto",p:1},children:te&&Object.keys(te).length>0?le.jsx("pre",{style:{margin:0,fontFamily:"monospace",fontSize:"13px",whiteSpace:"pre-wrap"},children:Object.entries(te).sort(([,ot],[,It])=>It-ot).map(([ot,It])=>`${ot}: ${It}`).join(`
|
|
4824
4824
|
`)}):le.jsx(Fr,{variant:"body2",color:"text.secondary",children:"No dispatchUnknown calls"})})]})]})]})]}),Es=le.jsxs(le.Fragment,{children:[le.jsxs(Cn,{sx:me?{position:"fixed",inset:0,zIndex:1250,bgcolor:"background.paper",display:"flex",flexDirection:"column"}:{height:"100%",display:"flex",flexDirection:"column"},children:[le.jsxs(Cn,{sx:{display:"flex",alignItems:"center",borderBottom:1,borderColor:"divider"},children:[le.jsx(Yy,{value:Q,onChange:(ot,It)=>xe(It),variant:"scrollable",scrollButtons:"auto",sx:{flexGrow:1,minHeight:34,"& .MuiTab-root":{textTransform:"none",fontWeight:500,fontSize:"0.8rem",minHeight:34,py:0}},children:Et.map(ot=>le.jsx(lu,{label:`Figure ${ot}`},ot))}),le.jsx(Su,{title:"Open this figure in the numbl figure viewer (new tab)",children:le.jsx("span",{children:le.jsx(lo,{size:"small",onClick:Ln,disabled:Et.length===0,sx:{mx:.5,flexShrink:0},children:le.jsx(Oce,{fontSize:"small"})})})}),le.jsx(Su,{title:"Download this figure's data as HDF5 (.h5)",children:le.jsx("span",{children:le.jsx(lo,{size:"small",onClick:Xt,disabled:qt||Et.length===0,sx:{mx:.5,flexShrink:0},children:le.jsx(qF,{fontSize:"small"})})})}),le.jsx(Su,{title:me?"Collapse figures (Esc)":"Expand figures to full window",children:le.jsx(lo,{size:"small",onClick:()=>be(ot=>!ot),sx:{mx:.5,flexShrink:0},children:me?le.jsx(Uce,{fontSize:"small"}):le.jsx(zce,{fontSize:"small"})})})]}),le.jsx(Cn,{sx:{flexGrow:1,overflow:"auto",p:1},children:Et.length>0?le.jsx(TD,{figure:K.figs[Et[Q]]}):le.jsx(Fr,{variant:"body2",color:"text.disabled",sx:{p:2,textAlign:"center",fontStyle:"italic"},children:"No figures"})})]}),le.jsx(ioe,{open:Dn!==null,onClose:()=>rn(null),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:le.jsxs(jte,{severity:Dn?.kind==="failed"?"warning":"info",onClose:()=>rn(null),sx:{width:"100%"},children:[Dn?.kind==="uploading"&&"Preparing a temporary link to the figure viewer…",Dn?.kind==="ready"&&le.jsxs(le.Fragment,{children:["Figure too large for a direct link — uploaded (encrypted, temporary)."," ",le.jsx(Mv,{href:Dn.url,target:"_blank",rel:"noreferrer",children:"Open in figure viewer"})]}),Dn?.kind==="failed"&&le.jsxs(le.Fragment,{children:["This figure is too large to open through a link, and the temporary upload failed. Download it (",le.jsx(qF,{fontSize:"inherit",sx:{verticalAlign:"middle"}}),") and"," ",le.jsx(Mv,{href:Dn.baseUrl,target:"_blank",rel:"noreferrer",children:"open the figure viewer"}),", then load the file."]})]})})]}),Ko=le.jsx(kme,{files:Z,activeFileId:t,onSelectFile:ot=>{n(ot),at&&ze(!1)},onAddFile:async ot=>{if(ot&&U(ot)){const It=await T(ot);It&&Be(It)}else{const It=await i(ot);It&&Be(It)}},onAddFolder:async ot=>{if(ot&&U(ot)){const It=await k(ot);It&&Be(`folder:${It}`)}else{const It=await s(ot);It&&Be(`folder:${It}`)}},onDeleteFile:ot=>G(ot)?R(ot):o(ot),onDeleteFolder:ot=>U(ot)?B(ot):a(ot),onRenameFile:(ot,It)=>G(ot)?F(ot,It):l(ot,It),onRenameFolder:(ot,It)=>U(ot)?L(ot,It):c(ot,It),onMoveFile:(ot,It)=>G(ot)?j(ot,It):u(ot,It),onDuplicateFile:async ot=>{const It=G(ot)?await V(ot):await h(ot);It&&Be(It)},onUploadFiles:f,fileCount:Z.length,triggerRenameId:ve});return le.jsxs(le.Fragment,{children:[le.jsxs(Cn,{sx:{height:"100vh",display:"flex",flexDirection:"column"},children:[le.jsxs(Cn,{sx:{display:"flex",alignItems:"center",px:1.5,py:.5,borderBottom:1,borderColor:"divider",bgcolor:"#1e1e2e",color:"#cdd6f4",minHeight:40,flexShrink:0,"& .MuiIconButton-root":{color:"#cdd6f4"},"& .MuiTypography-root":{color:"#cdd6f4"}},children:[at&&le.jsx(lo,{size:"small",onClick:()=>ze(!0),sx:{mr:.5},children:le.jsx(Bce,{fontSize:"small"})}),d]}),at?le.jsxs(le.Fragment,{children:[le.jsx(Rie,{open:Ae,onClose:()=>ze(!1),slotProps:{paper:{sx:{width:260}}},children:Ko}),le.jsxs(bw,{direction:"horizontal",initialSize:Math.round(window.innerHeight*.55),minSize:100,children:[Hn,le.jsxs(Cn,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[le.jsxs(Yy,{value:_t,onChange:(ot,It)=>zt(It),variant:"scrollable",scrollButtons:"auto",sx:{borderBottom:1,borderColor:"divider",minHeight:32},children:[le.jsx(lu,{label:"Output",sx:{minHeight:32,py:0,fontSize:"0.75rem",minWidth:0,px:1}}),le.jsx(lu,{label:"Figures",sx:{minHeight:32,py:0,fontSize:"0.75rem",minWidth:0,px:1}}),le.jsx(lu,{label:"JS",sx:{minHeight:32,py:0,fontSize:"0.75rem",minWidth:0,px:1}}),le.jsx(lu,{label:"AST",sx:{minHeight:32,py:0,fontSize:"0.75rem",minWidth:0,px:1}})]}),le.jsxs(Cn,{sx:{flexGrow:1,overflow:"hidden"},children:[_t===0&&le.jsx(Cn,{sx:{height:"100%",overflow:"auto",p:1},children:le.jsx("pre",{style:{margin:0,fontFamily:"monospace",fontSize:"13px",whiteSpace:"pre-wrap"},children:ue})}),_t===1&&le.jsx(Cn,{sx:{height:"100%",overflow:"auto",p:1},children:Et.length>0?le.jsxs(le.Fragment,{children:[Et.length>1&&le.jsx(Yy,{value:Q,onChange:(ot,It)=>xe(It),variant:"scrollable",scrollButtons:"auto",sx:{minHeight:28,mb:.5},children:Et.map(ot=>le.jsx(lu,{label:`Fig ${ot}`,sx:{minHeight:28,py:0,fontSize:"0.7rem"}},ot))}),le.jsx(TD,{figure:K.figs[Et[Q]]})]}):le.jsx(Fr,{variant:"body2",color:"text.secondary",children:"No figures"})}),_t===2&&le.jsx(Cn,{sx:{height:"100%",overflow:"auto"},children:le.jsx(qu,{language:"javascript",style:$F,customStyle:{margin:0,fontSize:12},children:de||""})}),_t===3&&le.jsx(j9,{data:we,label:"ast",fileSources:Le})]})]})]})]}):le.jsxs(bw,{direction:"vertical",initialSize:mr,minSize:150,maxSize:400,onSizeChange:Zs,children:[Ko,le.jsxs(bw,{direction:"vertical",initialSize:Ce,onSizeChange:Je,children:[Hn,le.jsxs(bw,{direction:"horizontal",initialSize:St,minSize:pt,onSizeChange:yt,children:[pr,Es]})]})]})]}),le.jsxs(oie,{open:Ut,onClose:()=>Yt(!1),maxWidth:"sm",fullWidth:!0,children:[le.jsx(vie,{children:"Execution Settings"}),le.jsxs(gie,{sx:{display:"flex",flexDirection:"column",gap:2,pt:3,overflow:"visible"},children:[le.jsxs(OA,{value:xt?"local":"browser",exclusive:!0,onChange:Zi,size:"small",children:[le.jsxs(Ap,{value:"browser",sx:{px:2},children:[le.jsx(VF,{sx:{fontSize:"1rem",mr:.5}}),"In browser"]}),le.jsxs(Ap,{value:"local",sx:{px:2},children:[le.jsx(WF,{sx:{fontSize:"1rem",mr:.5}}),"Local server"]})]}),le.jsx(Boe,{label:"Server URL",value:Ot,onChange:ot=>hn(ot.target.value),size:"small",fullWidth:!0,disabled:!xt,slotProps:{input:{style:{fontFamily:"monospace",fontSize:"0.85rem"}}},helperText:"Default: http://localhost:3001"}),le.jsxs(Cn,{sx:{display:"flex",alignItems:"center",gap:1},children:[le.jsx(Fr,{variant:"body2",color:xt?Si==="connected"?"success.main":Si==="disconnected"?"warning.main":"text.secondary":"text.disabled",children:xt?Si==="connected"?"Connected"+(vi===!0?" (native addon available)":vi===!1?" (no native addon)":""):Si==="disconnected"?"Not connected":"Checking...":"Server status: n/a"}),le.jsx(Md,{size:"small",disabled:!xt,onClick:()=>{Lr("unknown"),D7(Ot,Gi.current).then(ot=>{ot?(Ks(ot.nativeAddon===!0),Lr("connected")):Lr("disconnected")})},sx:{minWidth:0,textTransform:"none"},children:"Check"})]}),le.jsxs(Cn,{sx:{opacity:xt?1:.4},children:[le.jsx(Fr,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:"Start a local server in a terminal:"}),le.jsx(Cn,{component:"pre",sx:{bgcolor:"#1e1e1e",color:"#ccc",p:1.5,borderRadius:1,fontSize:"0.8rem",m:0,whiteSpace:"pre-wrap"},children:`# If installed globally:
|
|
@@ -4827,5 +4827,5 @@ npx numbl serve --passkey ${yn}
|
|
|
4827
4827
|
# Or from the repo (dev mode):
|
|
4828
4828
|
npx tsx src/cli.ts serve --passkey ${yn}`}),le.jsx(Fr,{variant:"caption",color:"text.disabled",onClick:()=>{Qn(rr()),Lr("disconnected")},sx:{cursor:"pointer",mt:.5,"&:hover":{color:"text.secondary"}},children:"regenerate passkey"})]})]}),le.jsxs(uie,{children:[le.jsx(Md,{onClick:()=>Yt(!1),children:"Cancel"}),le.jsx(Md,{variant:"contained",onClick:Oi,children:"Save"})]})]})]})}const zIe=4,L7=0,I7=1,UIe=2;function W1(e){let t=e.length;for(;--t>=0;)e[t]=0}const OIe=0,yY=1,jIe=2,HIe=3,$Ie=258,EP=29,zb=256,eb=zb+1+EP,q0=30,CP=19,_Y=2*eb+1,cm=15,_3=16,VIe=7,AP=256,vY=16,bY=17,xY=18,HN=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),o2=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),WIe=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),wY=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),qIe=512,Jh=new Array((eb+2)*2);W1(Jh);const fv=new Array(q0*2);W1(fv);const tb=new Array(qIe);W1(tb);const nb=new Array($Ie-HIe+1);W1(nb);const TP=new Array(EP);W1(TP);const dM=new Array(q0);W1(dM);function v3(e,t,n,r,i){this.static_tree=e,this.extra_bits=t,this.extra_base=n,this.elems=r,this.max_length=i,this.has_stree=e&&e.length}let SY,MY,EY;function b3(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}const CY=e=>e<256?tb[e]:tb[256+(e>>>7)],rb=(e,t)=>{e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255},hl=(e,t,n)=>{e.bi_valid>_3-n?(e.bi_buf|=t<<e.bi_valid&65535,rb(e,e.bi_buf),e.bi_buf=t>>_3-e.bi_valid,e.bi_valid+=n-_3):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=n)},Ru=(e,t,n)=>{hl(e,n[t*2],n[t*2+1])},AY=(e,t)=>{let n=0;do n|=e&1,e>>>=1,n<<=1;while(--t>0);return n>>>1},GIe=e=>{e.bi_valid===16?(rb(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)},XIe=(e,t)=>{const n=t.dyn_tree,r=t.max_code,i=t.stat_desc.static_tree,s=t.stat_desc.has_stree,o=t.stat_desc.extra_bits,a=t.stat_desc.extra_base,l=t.stat_desc.max_length;let c,u,h,f,d,p,m=0;for(f=0;f<=cm;f++)e.bl_count[f]=0;for(n[e.heap[e.heap_max]*2+1]=0,c=e.heap_max+1;c<_Y;c++)u=e.heap[c],f=n[n[u*2+1]*2+1]+1,f>l&&(f=l,m++),n[u*2+1]=f,!(u>r)&&(e.bl_count[f]++,d=0,u>=a&&(d=o[u-a]),p=n[u*2],e.opt_len+=p*(f+d),s&&(e.static_len+=p*(i[u*2+1]+d)));if(m!==0){do{for(f=l-1;e.bl_count[f]===0;)f--;e.bl_count[f]--,e.bl_count[f+1]+=2,e.bl_count[l]--,m-=2}while(m>0);for(f=l;f!==0;f--)for(u=e.bl_count[f];u!==0;)h=e.heap[--c],!(h>r)&&(n[h*2+1]!==f&&(e.opt_len+=(f-n[h*2+1])*n[h*2],n[h*2+1]=f),u--)}},TY=(e,t,n)=>{const r=new Array(cm+1);let i=0,s,o;for(s=1;s<=cm;s++)i=i+n[s-1]<<1,r[s]=i;for(o=0;o<=t;o++){let a=e[o*2+1];a!==0&&(e[o*2]=AY(r[a]++,a))}},YIe=()=>{let e,t,n,r,i;const s=new Array(cm+1);for(n=0,r=0;r<EP-1;r++)for(TP[r]=n,e=0;e<1<<HN[r];e++)nb[n++]=r;for(nb[n-1]=r,i=0,r=0;r<16;r++)for(dM[r]=i,e=0;e<1<<o2[r];e++)tb[i++]=r;for(i>>=7;r<q0;r++)for(dM[r]=i<<7,e=0;e<1<<o2[r]-7;e++)tb[256+i++]=r;for(t=0;t<=cm;t++)s[t]=0;for(e=0;e<=143;)Jh[e*2+1]=8,e++,s[8]++;for(;e<=255;)Jh[e*2+1]=9,e++,s[9]++;for(;e<=279;)Jh[e*2+1]=7,e++,s[7]++;for(;e<=287;)Jh[e*2+1]=8,e++,s[8]++;for(TY(Jh,eb+1,s),e=0;e<q0;e++)fv[e*2+1]=5,fv[e*2]=AY(e,5);SY=new v3(Jh,HN,zb+1,eb,cm),MY=new v3(fv,o2,0,q0,cm),EY=new v3(new Array(0),WIe,0,CP,VIe)},kY=e=>{let t;for(t=0;t<eb;t++)e.dyn_ltree[t*2]=0;for(t=0;t<q0;t++)e.dyn_dtree[t*2]=0;for(t=0;t<CP;t++)e.bl_tree[t*2]=0;e.dyn_ltree[AP*2]=1,e.opt_len=e.static_len=0,e.sym_next=e.matches=0},RY=e=>{e.bi_valid>8?rb(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},P7=(e,t,n,r)=>{const i=t*2,s=n*2;return e[i]<e[s]||e[i]===e[s]&&r[t]<=r[n]},x3=(e,t,n)=>{const r=e.heap[n];let i=n<<1;for(;i<=e.heap_len&&(i<e.heap_len&&P7(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!P7(t,r,e.heap[i],e.depth));)e.heap[n]=e.heap[i],n=i,i<<=1;e.heap[n]=r},B7=(e,t,n)=>{let r,i,s=0,o,a;if(e.sym_next!==0)do r=e.pending_buf[e.sym_buf+s++]&255,r+=(e.pending_buf[e.sym_buf+s++]&255)<<8,i=e.pending_buf[e.sym_buf+s++],r===0?Ru(e,i,t):(o=nb[i],Ru(e,o+zb+1,t),a=HN[o],a!==0&&(i-=TP[o],hl(e,i,a)),r--,o=CY(r),Ru(e,o,n),a=o2[o],a!==0&&(r-=dM[o],hl(e,r,a)));while(s<e.sym_next);Ru(e,AP,t)},$N=(e,t)=>{const n=t.dyn_tree,r=t.stat_desc.static_tree,i=t.stat_desc.has_stree,s=t.stat_desc.elems;let o,a,l=-1,c;for(e.heap_len=0,e.heap_max=_Y,o=0;o<s;o++)n[o*2]!==0?(e.heap[++e.heap_len]=l=o,e.depth[o]=0):n[o*2+1]=0;for(;e.heap_len<2;)c=e.heap[++e.heap_len]=l<2?++l:0,n[c*2]=1,e.depth[c]=0,e.opt_len--,i&&(e.static_len-=r[c*2+1]);for(t.max_code=l,o=e.heap_len>>1;o>=1;o--)x3(e,n,o);c=s;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],x3(e,n,1),a=e.heap[1],e.heap[--e.heap_max]=o,e.heap[--e.heap_max]=a,n[c*2]=n[o*2]+n[a*2],e.depth[c]=(e.depth[o]>=e.depth[a]?e.depth[o]:e.depth[a])+1,n[o*2+1]=n[a*2+1]=c,e.heap[1]=c++,x3(e,n,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],XIe(e,t),TY(n,l,e.bl_count)},F7=(e,t,n)=>{let r,i=-1,s,o=t[1],a=0,l=7,c=4;for(o===0&&(l=138,c=3),t[(n+1)*2+1]=65535,r=0;r<=n;r++)s=o,o=t[(r+1)*2+1],!(++a<l&&s===o)&&(a<c?e.bl_tree[s*2]+=a:s!==0?(s!==i&&e.bl_tree[s*2]++,e.bl_tree[vY*2]++):a<=10?e.bl_tree[bY*2]++:e.bl_tree[xY*2]++,a=0,i=s,o===0?(l=138,c=3):s===o?(l=6,c=3):(l=7,c=4))},z7=(e,t,n)=>{let r,i=-1,s,o=t[1],a=0,l=7,c=4;for(o===0&&(l=138,c=3),r=0;r<=n;r++)if(s=o,o=t[(r+1)*2+1],!(++a<l&&s===o)){if(a<c)do Ru(e,s,e.bl_tree);while(--a!==0);else s!==0?(s!==i&&(Ru(e,s,e.bl_tree),a--),Ru(e,vY,e.bl_tree),hl(e,a-3,2)):a<=10?(Ru(e,bY,e.bl_tree),hl(e,a-3,3)):(Ru(e,xY,e.bl_tree),hl(e,a-11,7));a=0,i=s,o===0?(l=138,c=3):s===o?(l=6,c=3):(l=7,c=4)}},KIe=e=>{let t;for(F7(e,e.dyn_ltree,e.l_desc.max_code),F7(e,e.dyn_dtree,e.d_desc.max_code),$N(e,e.bl_desc),t=CP-1;t>=3&&e.bl_tree[wY[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t},ZIe=(e,t,n,r)=>{let i;for(hl(e,t-257,5),hl(e,n-1,5),hl(e,r-4,4),i=0;i<r;i++)hl(e,e.bl_tree[wY[i]*2+1],3);z7(e,e.dyn_ltree,t-1),z7(e,e.dyn_dtree,n-1)},QIe=e=>{let t=4093624447,n;for(n=0;n<=31;n++,t>>>=1)if(t&1&&e.dyn_ltree[n*2]!==0)return L7;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return I7;for(n=32;n<zb;n++)if(e.dyn_ltree[n*2]!==0)return I7;return L7};let U7=!1;const JIe=e=>{U7||(YIe(),U7=!0),e.l_desc=new b3(e.dyn_ltree,SY),e.d_desc=new b3(e.dyn_dtree,MY),e.bl_desc=new b3(e.bl_tree,EY),e.bi_buf=0,e.bi_valid=0,kY(e)},DY=(e,t,n,r)=>{hl(e,(OIe<<1)+(r?1:0),3),RY(e),rb(e,n),rb(e,~n),n&&e.pending_buf.set(e.window.subarray(t,t+n),e.pending),e.pending+=n},ePe=e=>{hl(e,yY<<1,3),Ru(e,AP,Jh),GIe(e)},tPe=(e,t,n,r)=>{let i,s,o=0;e.level>0?(e.strm.data_type===UIe&&(e.strm.data_type=QIe(e)),$N(e,e.l_desc),$N(e,e.d_desc),o=KIe(e),i=e.opt_len+3+7>>>3,s=e.static_len+3+7>>>3,s<=i&&(i=s)):i=s=n+5,n+4<=i&&t!==-1?DY(e,t,n,r):e.strategy===zIe||s===i?(hl(e,(yY<<1)+(r?1:0),3),B7(e,Jh,fv)):(hl(e,(jIe<<1)+(r?1:0),3),ZIe(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),B7(e,e.dyn_ltree,e.dyn_dtree)),kY(e),r&&RY(e)},nPe=(e,t,n)=>(e.pending_buf[e.sym_buf+e.sym_next++]=t,e.pending_buf[e.sym_buf+e.sym_next++]=t>>8,e.pending_buf[e.sym_buf+e.sym_next++]=n,t===0?e.dyn_ltree[n*2]++:(e.matches++,t--,e.dyn_ltree[(nb[n]+zb+1)*2]++,e.dyn_dtree[CY(t)*2]++),e.sym_next===e.sym_end);var rPe=JIe,iPe=DY,sPe=tPe,oPe=nPe,aPe=ePe,lPe={_tr_init:rPe,_tr_stored_block:iPe,_tr_flush_block:sPe,_tr_tally:oPe,_tr_align:aPe};const cPe=(e,t,n,r)=>{let i=e&65535|0,s=e>>>16&65535|0,o=0;for(;n!==0;){o=n>2e3?2e3:n,n-=o;do i=i+t[r++]|0,s=s+i|0;while(--o);i%=65521,s%=65521}return i|s<<16|0};var ib=cPe;const uPe=()=>{let e,t=[];for(var n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=e&1?3988292384^e>>>1:e>>>1;t[n]=e}return t},hPe=new Uint32Array(uPe()),fPe=(e,t,n,r)=>{const i=hPe,s=r+n;e^=-1;for(let o=r;o<s;o++)e=e>>>8^i[(e^t[o])&255];return e^-1};var Fo=fPe,Pm={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},Ub={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:dPe,_tr_stored_block:VN,_tr_flush_block:pPe,_tr_tally:jd,_tr_align:mPe}=lPe,{Z_NO_FLUSH:Hd,Z_PARTIAL_FLUSH:gPe,Z_FULL_FLUSH:yPe,Z_FINISH:gc,Z_BLOCK:O7,Z_OK:la,Z_STREAM_END:j7,Z_STREAM_ERROR:$u,Z_DATA_ERROR:_Pe,Z_BUF_ERROR:w3,Z_DEFAULT_COMPRESSION:vPe,Z_FILTERED:bPe,Z_HUFFMAN_ONLY:SS,Z_RLE:xPe,Z_FIXED:wPe,Z_DEFAULT_STRATEGY:SPe,Z_UNKNOWN:MPe,Z_DEFLATED:TE}=Ub,EPe=9,CPe=15,APe=8,TPe=29,kPe=256,WN=kPe+1+TPe,RPe=30,DPe=19,NPe=2*WN+1,LPe=15,Zr=3,Bd=258,Vu=Bd+Zr+1,IPe=32,x1=42,kP=57,qN=69,GN=73,XN=91,YN=103,um=113,$_=666,Xa=1,q1=2,Bm=3,G1=4,PPe=3,hm=(e,t)=>(e.msg=Pm[t],t),H7=e=>e*2-(e>4?9:0),Td=e=>{let t=e.length;for(;--t>=0;)e[t]=0},BPe=e=>{let t,n,r,i=e.w_size;t=e.hash_size,r=t;do n=e.head[--r],e.head[r]=n>=i?n-i:0;while(--t);t=i,r=t;do n=e.prev[--r],e.prev[r]=n>=i?n-i:0;while(--t)};let FPe=(e,t,n)=>(t<<e.hash_shift^n)&e.hash_mask,$d=FPe;const Rl=e=>{const t=e.state;let n=t.pending;n>e.avail_out&&(n=e.avail_out),n!==0&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+n),e.next_out),e.next_out+=n,t.pending_out+=n,e.total_out+=n,e.avail_out-=n,t.pending-=n,t.pending===0&&(t.pending_out=0))},Fl=(e,t)=>{pPe(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,Rl(e.strm)},pi=(e,t)=>{e.pending_buf[e.pending++]=t},M_=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255},KN=(e,t,n,r)=>{let i=e.avail_in;return i>r&&(i=r),i===0?0:(e.avail_in-=i,t.set(e.input.subarray(e.next_in,e.next_in+i),n),e.state.wrap===1?e.adler=ib(e.adler,t,i,n):e.state.wrap===2&&(e.adler=Fo(e.adler,t,i,n)),e.next_in+=i,e.total_in+=i,i)},NY=(e,t)=>{let n=e.max_chain_length,r=e.strstart,i,s,o=e.prev_length,a=e.nice_match;const l=e.strstart>e.w_size-Vu?e.strstart-(e.w_size-Vu):0,c=e.window,u=e.w_mask,h=e.prev,f=e.strstart+Bd;let d=c[r+o-1],p=c[r+o];e.prev_length>=e.good_match&&(n>>=2),a>e.lookahead&&(a=e.lookahead);do if(i=t,!(c[i+o]!==p||c[i+o-1]!==d||c[i]!==c[r]||c[++i]!==c[r+1])){r+=2,i++;do;while(c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&c[++r]===c[++i]&&r<f);if(s=Bd-(f-r),r=f-Bd,s>o){if(e.match_start=t,o=s,s>=a)break;d=c[r+o-1],p=c[r+o]}}while((t=h[t&u])>l&&--n!==0);return o<=e.lookahead?o:e.lookahead},w1=e=>{const t=e.w_size;let n,r,i;do{if(r=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-Vu)&&(e.window.set(e.window.subarray(t,t+t-r),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,e.insert>e.strstart&&(e.insert=e.strstart),BPe(e),r+=t),e.strm.avail_in===0)break;if(n=KN(e.strm,e.window,e.strstart+e.lookahead,r),e.lookahead+=n,e.lookahead+e.insert>=Zr)for(i=e.strstart-e.insert,e.ins_h=e.window[i],e.ins_h=$d(e,e.ins_h,e.window[i+1]);e.insert&&(e.ins_h=$d(e,e.ins_h,e.window[i+Zr-1]),e.prev[i&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=i,i++,e.insert--,!(e.lookahead+e.insert<Zr)););}while(e.lookahead<Vu&&e.strm.avail_in!==0)},LY=(e,t)=>{let n=e.pending_buf_size-5>e.w_size?e.w_size:e.pending_buf_size-5,r,i,s,o=0,a=e.strm.avail_in;do{if(r=65535,s=e.bi_valid+42>>3,e.strm.avail_out<s||(s=e.strm.avail_out-s,i=e.strstart-e.block_start,r>i+e.strm.avail_in&&(r=i+e.strm.avail_in),r>s&&(r=s),r<n&&(r===0&&t!==gc||t===Hd||r!==i+e.strm.avail_in)))break;o=t===gc&&r===i+e.strm.avail_in?1:0,VN(e,0,0,o),e.pending_buf[e.pending-4]=r,e.pending_buf[e.pending-3]=r>>8,e.pending_buf[e.pending-2]=~r,e.pending_buf[e.pending-1]=~r>>8,Rl(e.strm),i&&(i>r&&(i=r),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+i),e.strm.next_out),e.strm.next_out+=i,e.strm.avail_out-=i,e.strm.total_out+=i,e.block_start+=i,r-=i),r&&(KN(e.strm,e.strm.output,e.strm.next_out,r),e.strm.next_out+=r,e.strm.avail_out-=r,e.strm.total_out+=r)}while(o===0);return a-=e.strm.avail_in,a&&(a>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=a&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-a,e.strm.next_in),e.strstart),e.strstart+=a,e.insert+=a>e.w_size-e.insert?e.w_size-e.insert:a),e.block_start=e.strstart),e.high_water<e.strstart&&(e.high_water=e.strstart),o?G1:t!==Hd&&t!==gc&&e.strm.avail_in===0&&e.strstart===e.block_start?q1:(s=e.window_size-e.strstart,e.strm.avail_in>s&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,s+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),s>e.strm.avail_in&&(s=e.strm.avail_in),s&&(KN(e.strm,e.window,e.strstart,s),e.strstart+=s,e.insert+=s>e.w_size-e.insert?e.w_size-e.insert:s),e.high_water<e.strstart&&(e.high_water=e.strstart),s=e.bi_valid+42>>3,s=e.pending_buf_size-s>65535?65535:e.pending_buf_size-s,n=s>e.w_size?e.w_size:s,i=e.strstart-e.block_start,(i>=n||(i||t===gc)&&t!==Hd&&e.strm.avail_in===0&&i<=s)&&(r=i>s?s:i,o=t===gc&&e.strm.avail_in===0&&r===i?1:0,VN(e,e.block_start,r,o),e.block_start+=r,Rl(e.strm)),o?Bm:Xa)},S3=(e,t)=>{let n,r;for(;;){if(e.lookahead<Vu){if(w1(e),e.lookahead<Vu&&t===Hd)return Xa;if(e.lookahead===0)break}if(n=0,e.lookahead>=Zr&&(e.ins_h=$d(e,e.ins_h,e.window[e.strstart+Zr-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),n!==0&&e.strstart-n<=e.w_size-Vu&&(e.match_length=NY(e,n)),e.match_length>=Zr)if(r=jd(e,e.strstart-e.match_start,e.match_length-Zr),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=Zr){e.match_length--;do e.strstart++,e.ins_h=$d(e,e.ins_h,e.window[e.strstart+Zr-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(--e.match_length!==0);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=$d(e,e.ins_h,e.window[e.strstart+1]);else r=jd(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&(Fl(e,!1),e.strm.avail_out===0))return Xa}return e.insert=e.strstart<Zr-1?e.strstart:Zr-1,t===gc?(Fl(e,!0),e.strm.avail_out===0?Bm:G1):e.sym_next&&(Fl(e,!1),e.strm.avail_out===0)?Xa:q1},v0=(e,t)=>{let n,r,i;for(;;){if(e.lookahead<Vu){if(w1(e),e.lookahead<Vu&&t===Hd)return Xa;if(e.lookahead===0)break}if(n=0,e.lookahead>=Zr&&(e.ins_h=$d(e,e.ins_h,e.window[e.strstart+Zr-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=Zr-1,n!==0&&e.prev_length<e.max_lazy_match&&e.strstart-n<=e.w_size-Vu&&(e.match_length=NY(e,n),e.match_length<=5&&(e.strategy===bPe||e.match_length===Zr&&e.strstart-e.match_start>4096)&&(e.match_length=Zr-1)),e.prev_length>=Zr&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-Zr,r=jd(e,e.strstart-1-e.prev_match,e.prev_length-Zr),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=$d(e,e.ins_h,e.window[e.strstart+Zr-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(--e.prev_length!==0);if(e.match_available=0,e.match_length=Zr-1,e.strstart++,r&&(Fl(e,!1),e.strm.avail_out===0))return Xa}else if(e.match_available){if(r=jd(e,0,e.window[e.strstart-1]),r&&Fl(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return Xa}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(r=jd(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<Zr-1?e.strstart:Zr-1,t===gc?(Fl(e,!0),e.strm.avail_out===0?Bm:G1):e.sym_next&&(Fl(e,!1),e.strm.avail_out===0)?Xa:q1},zPe=(e,t)=>{let n,r,i,s;const o=e.window;for(;;){if(e.lookahead<=Bd){if(w1(e),e.lookahead<=Bd&&t===Hd)return Xa;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=Zr&&e.strstart>0&&(i=e.strstart-1,r=o[i],r===o[++i]&&r===o[++i]&&r===o[++i])){s=e.strstart+Bd;do;while(r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&r===o[++i]&&i<s);e.match_length=Bd-(s-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=Zr?(n=jd(e,1,e.match_length-Zr),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(n=jd(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),n&&(Fl(e,!1),e.strm.avail_out===0))return Xa}return e.insert=0,t===gc?(Fl(e,!0),e.strm.avail_out===0?Bm:G1):e.sym_next&&(Fl(e,!1),e.strm.avail_out===0)?Xa:q1},UPe=(e,t)=>{let n;for(;;){if(e.lookahead===0&&(w1(e),e.lookahead===0)){if(t===Hd)return Xa;break}if(e.match_length=0,n=jd(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,n&&(Fl(e,!1),e.strm.avail_out===0))return Xa}return e.insert=0,t===gc?(Fl(e,!0),e.strm.avail_out===0?Bm:G1):e.sym_next&&(Fl(e,!1),e.strm.avail_out===0)?Xa:q1};function mu(e,t,n,r,i){this.good_length=e,this.max_lazy=t,this.nice_length=n,this.max_chain=r,this.func=i}const V_=[new mu(0,0,0,0,LY),new mu(4,4,8,4,S3),new mu(4,5,16,8,S3),new mu(4,6,32,32,S3),new mu(4,4,16,16,v0),new mu(8,16,32,32,v0),new mu(8,16,128,128,v0),new mu(8,32,128,256,v0),new mu(32,128,258,1024,v0),new mu(32,258,258,4096,v0)],OPe=e=>{e.window_size=2*e.w_size,Td(e.head),e.max_lazy_match=V_[e.level].max_lazy,e.good_match=V_[e.level].good_length,e.nice_match=V_[e.level].nice_length,e.max_chain_length=V_[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=Zr-1,e.match_available=0,e.ins_h=0};function jPe(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=TE,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(NPe*2),this.dyn_dtree=new Uint16Array((2*RPe+1)*2),this.bl_tree=new Uint16Array((2*DPe+1)*2),Td(this.dyn_ltree),Td(this.dyn_dtree),Td(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(LPe+1),this.heap=new Uint16Array(2*WN+1),Td(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(2*WN+1),Td(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const Ob=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.status!==x1&&t.status!==kP&&t.status!==qN&&t.status!==GN&&t.status!==XN&&t.status!==YN&&t.status!==um&&t.status!==$_?1:0},IY=e=>{if(Ob(e))return hm(e,$u);e.total_in=e.total_out=0,e.data_type=MPe;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap===2?kP:t.wrap?x1:um,e.adler=t.wrap===2?0:1,t.last_flush=-2,dPe(t),la},PY=e=>{const t=IY(e);return t===la&&OPe(e.state),t},HPe=(e,t)=>Ob(e)||e.state.wrap!==2?$u:(e.state.gzhead=t,la),BY=(e,t,n,r,i,s)=>{if(!e)return $u;let o=1;if(t===vPe&&(t=6),r<0?(o=0,r=-r):r>15&&(o=2,r-=16),i<1||i>EPe||n!==TE||r<8||r>15||t<0||t>9||s<0||s>wPe||r===8&&o!==1)return hm(e,$u);r===8&&(r=9);const a=new jPe;return e.state=a,a.strm=e,a.status=x1,a.wrap=o,a.gzhead=null,a.w_bits=r,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=i+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+Zr-1)/Zr),a.window=new Uint8Array(a.w_size*2),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<i+6,a.pending_buf_size=a.lit_bufsize*4,a.pending_buf=new Uint8Array(a.pending_buf_size),a.sym_buf=a.lit_bufsize,a.sym_end=(a.lit_bufsize-1)*3,a.level=t,a.strategy=s,a.method=n,PY(e)},$Pe=(e,t)=>BY(e,t,TE,CPe,APe,SPe),VPe=(e,t)=>{if(Ob(e)||t>O7||t<0)return e?hm(e,$u):$u;const n=e.state;if(!e.output||e.avail_in!==0&&!e.input||n.status===$_&&t!==gc)return hm(e,e.avail_out===0?w3:$u);const r=n.last_flush;if(n.last_flush=t,n.pending!==0){if(Rl(e),e.avail_out===0)return n.last_flush=-1,la}else if(e.avail_in===0&&H7(t)<=H7(r)&&t!==gc)return hm(e,w3);if(n.status===$_&&e.avail_in!==0)return hm(e,w3);if(n.status===x1&&n.wrap===0&&(n.status=um),n.status===x1){let i=TE+(n.w_bits-8<<4)<<8,s=-1;if(n.strategy>=SS||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,i|=s<<6,n.strstart!==0&&(i|=IPe),i+=31-i%31,M_(n,i),n.strstart!==0&&(M_(n,e.adler>>>16),M_(n,e.adler&65535)),e.adler=1,n.status=um,Rl(e),n.pending!==0)return n.last_flush=-1,la}if(n.status===kP){if(e.adler=0,pi(n,31),pi(n,139),pi(n,8),n.gzhead)pi(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),pi(n,n.gzhead.time&255),pi(n,n.gzhead.time>>8&255),pi(n,n.gzhead.time>>16&255),pi(n,n.gzhead.time>>24&255),pi(n,n.level===9?2:n.strategy>=SS||n.level<2?4:0),pi(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(pi(n,n.gzhead.extra.length&255),pi(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=Fo(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=qN;else if(pi(n,0),pi(n,0),pi(n,0),pi(n,0),pi(n,0),pi(n,n.level===9?2:n.strategy>=SS||n.level<2?4:0),pi(n,PPe),n.status=um,Rl(e),n.pending!==0)return n.last_flush=-1,la}if(n.status===qN){if(n.gzhead.extra){let i=n.pending,s=(n.gzhead.extra.length&65535)-n.gzindex;for(;n.pending+s>n.pending_buf_size;){let a=n.pending_buf_size-n.pending;if(n.pending_buf.set(n.gzhead.extra.subarray(n.gzindex,n.gzindex+a),n.pending),n.pending=n.pending_buf_size,n.gzhead.hcrc&&n.pending>i&&(e.adler=Fo(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex+=a,Rl(e),n.pending!==0)return n.last_flush=-1,la;i=0,s-=a}let o=new Uint8Array(n.gzhead.extra);n.pending_buf.set(o.subarray(n.gzindex,n.gzindex+s),n.pending),n.pending+=s,n.gzhead.hcrc&&n.pending>i&&(e.adler=Fo(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex=0}n.status=GN}if(n.status===GN){if(n.gzhead.name){let i=n.pending,s;do{if(n.pending===n.pending_buf_size){if(n.gzhead.hcrc&&n.pending>i&&(e.adler=Fo(e.adler,n.pending_buf,n.pending-i,i)),Rl(e),n.pending!==0)return n.last_flush=-1,la;i=0}n.gzindex<n.gzhead.name.length?s=n.gzhead.name.charCodeAt(n.gzindex++)&255:s=0,pi(n,s)}while(s!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=Fo(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex=0}n.status=XN}if(n.status===XN){if(n.gzhead.comment){let i=n.pending,s;do{if(n.pending===n.pending_buf_size){if(n.gzhead.hcrc&&n.pending>i&&(e.adler=Fo(e.adler,n.pending_buf,n.pending-i,i)),Rl(e),n.pending!==0)return n.last_flush=-1,la;i=0}n.gzindex<n.gzhead.comment.length?s=n.gzhead.comment.charCodeAt(n.gzindex++)&255:s=0,pi(n,s)}while(s!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=Fo(e.adler,n.pending_buf,n.pending-i,i))}n.status=YN}if(n.status===YN){if(n.gzhead.hcrc){if(n.pending+2>n.pending_buf_size&&(Rl(e),n.pending!==0))return n.last_flush=-1,la;pi(n,e.adler&255),pi(n,e.adler>>8&255),e.adler=0}if(n.status=um,Rl(e),n.pending!==0)return n.last_flush=-1,la}if(e.avail_in!==0||n.lookahead!==0||t!==Hd&&n.status!==$_){let i=n.level===0?LY(n,t):n.strategy===SS?UPe(n,t):n.strategy===xPe?zPe(n,t):V_[n.level].func(n,t);if((i===Bm||i===G1)&&(n.status=$_),i===Xa||i===Bm)return e.avail_out===0&&(n.last_flush=-1),la;if(i===q1&&(t===gPe?mPe(n):t!==O7&&(VN(n,0,0,!1),t===yPe&&(Td(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),Rl(e),e.avail_out===0))return n.last_flush=-1,la}return t!==gc?la:n.wrap<=0?j7:(n.wrap===2?(pi(n,e.adler&255),pi(n,e.adler>>8&255),pi(n,e.adler>>16&255),pi(n,e.adler>>24&255),pi(n,e.total_in&255),pi(n,e.total_in>>8&255),pi(n,e.total_in>>16&255),pi(n,e.total_in>>24&255)):(M_(n,e.adler>>>16),M_(n,e.adler&65535)),Rl(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?la:j7)},WPe=e=>{if(Ob(e))return $u;const t=e.state.status;return e.state=null,t===um?hm(e,_Pe):la},qPe=(e,t)=>{let n=t.length;if(Ob(e))return $u;const r=e.state,i=r.wrap;if(i===2||i===1&&r.status!==x1||r.lookahead)return $u;if(i===1&&(e.adler=ib(e.adler,t,n,0)),r.wrap=0,n>=r.w_size){i===0&&(Td(r.head),r.strstart=0,r.block_start=0,r.insert=0);let l=new Uint8Array(r.w_size);l.set(t.subarray(n-r.w_size,n),0),t=l,n=r.w_size}const s=e.avail_in,o=e.next_in,a=e.input;for(e.avail_in=n,e.next_in=0,e.input=t,w1(r);r.lookahead>=Zr;){let l=r.strstart,c=r.lookahead-(Zr-1);do r.ins_h=$d(r,r.ins_h,r.window[l+Zr-1]),r.prev[l&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=l,l++;while(--c);r.strstart=l,r.lookahead=Zr-1,w1(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=Zr-1,r.match_available=0,e.next_in=o,e.input=a,e.avail_in=s,r.wrap=i,la};var GPe=$Pe,XPe=BY,YPe=PY,KPe=IY,ZPe=HPe,QPe=VPe,JPe=WPe,e5e=qPe,t5e="pako deflate (from Nodeca project)",dv={deflateInit:GPe,deflateInit2:XPe,deflateReset:YPe,deflateResetKeep:KPe,deflateSetHeader:ZPe,deflate:QPe,deflateEnd:JPe,deflateSetDictionary:e5e,deflateInfo:t5e};const n5e=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r5e=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const n=t.shift();if(n){if(typeof n!="object")throw new TypeError(n+"must be non-object");for(const r in n)n5e(n,r)&&(e[r]=n[r])}}return e},i5e=e=>{let t=0;for(let r=0,i=e.length;r<i;r++)t+=e[r].length;const n=new Uint8Array(t);for(let r=0,i=0,s=e.length;r<s;r++){let o=e[r];n.set(o,i),i+=o.length}return n},kE={assign:r5e,flattenChunks:i5e};let FY=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch{FY=!1}const sb=new Uint8Array(256);for(let e=0;e<256;e++)sb[e]=e>=252?6:e>=248?5:e>=240?4:e>=224?3:e>=192?2:1;sb[254]=sb[254]=1;var s5e=e=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(e);let t,n,r,i,s,o=e.length,a=0;for(i=0;i<o;i++)n=e.charCodeAt(i),(n&64512)===55296&&i+1<o&&(r=e.charCodeAt(i+1),(r&64512)===56320&&(n=65536+(n-55296<<10)+(r-56320),i++)),a+=n<128?1:n<2048?2:n<65536?3:4;for(t=new Uint8Array(a),s=0,i=0;s<a;i++)n=e.charCodeAt(i),(n&64512)===55296&&i+1<o&&(r=e.charCodeAt(i+1),(r&64512)===56320&&(n=65536+(n-55296<<10)+(r-56320),i++)),n<128?t[s++]=n:n<2048?(t[s++]=192|n>>>6,t[s++]=128|n&63):n<65536?(t[s++]=224|n>>>12,t[s++]=128|n>>>6&63,t[s++]=128|n&63):(t[s++]=240|n>>>18,t[s++]=128|n>>>12&63,t[s++]=128|n>>>6&63,t[s++]=128|n&63);return t};const o5e=(e,t)=>{if(t<65534&&e.subarray&&FY)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let n="";for(let r=0;r<t;r++)n+=String.fromCharCode(e[r]);return n};var a5e=(e,t)=>{const n=t||e.length;if(typeof TextDecoder=="function"&&TextDecoder.prototype.decode)return new TextDecoder().decode(e.subarray(0,t));let r,i;const s=new Array(n*2);for(i=0,r=0;r<n;){let o=e[r++];if(o<128){s[i++]=o;continue}let a=sb[o];if(a>4){s[i++]=65533,r+=a-1;continue}for(o&=a===2?31:a===3?15:7;a>1&&r<n;)o=o<<6|e[r++]&63,a--;if(a>1){s[i++]=65533;continue}o<65536?s[i++]=o:(o-=65536,s[i++]=55296|o>>10&1023,s[i++]=56320|o&1023)}return o5e(s,i)},l5e=(e,t)=>{t=t||e.length,t>e.length&&(t=e.length);let n=t-1;for(;n>=0&&(e[n]&192)===128;)n--;return n<0||n===0?t:n+sb[e[n]]>t?n:t},ob={string2buf:s5e,buf2string:a5e,utf8border:l5e};function c5e(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}var zY=c5e;const UY=Object.prototype.toString,{Z_NO_FLUSH:u5e,Z_SYNC_FLUSH:h5e,Z_FULL_FLUSH:f5e,Z_FINISH:d5e,Z_OK:pM,Z_STREAM_END:p5e,Z_DEFAULT_COMPRESSION:m5e,Z_DEFAULT_STRATEGY:g5e,Z_DEFLATED:y5e}=Ub;function jb(e){this.options=kE.assign({level:m5e,method:y5e,chunkSize:16384,windowBits:15,memLevel:8,strategy:g5e},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zY,this.strm.avail_out=0;let n=dv.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(n!==pM)throw new Error(Pm[n]);if(t.header&&dv.deflateSetHeader(this.strm,t.header),t.dictionary){let r;if(typeof t.dictionary=="string"?r=ob.string2buf(t.dictionary):UY.call(t.dictionary)==="[object ArrayBuffer]"?r=new Uint8Array(t.dictionary):r=t.dictionary,n=dv.deflateSetDictionary(this.strm,r),n!==pM)throw new Error(Pm[n]);this._dict_set=!0}}jb.prototype.push=function(e,t){const n=this.strm,r=this.options.chunkSize;let i,s;if(this.ended)return!1;for(t===~~t?s=t:s=t===!0?d5e:u5e,typeof e=="string"?n.input=ob.string2buf(e):UY.call(e)==="[object ArrayBuffer]"?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){if(n.avail_out===0&&(n.output=new Uint8Array(r),n.next_out=0,n.avail_out=r),(s===h5e||s===f5e)&&n.avail_out<=6){this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;continue}if(i=dv.deflate(n,s),i===p5e)return n.next_out>0&&this.onData(n.output.subarray(0,n.next_out)),i=dv.deflateEnd(this.strm),this.onEnd(i),this.ended=!0,i===pM;if(n.avail_out===0){this.onData(n.output);continue}if(s>0&&n.next_out>0){this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;continue}if(n.avail_in===0)break}return!0};jb.prototype.onData=function(e){this.chunks.push(e)};jb.prototype.onEnd=function(e){e===pM&&(this.result=kE.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function RP(e,t){const n=new jb(t);if(n.push(e,!0),n.err)throw n.msg||Pm[n.err];return n.result}function _5e(e,t){return t=t||{},t.raw=!0,RP(e,t)}function v5e(e,t){return t=t||{},t.gzip=!0,RP(e,t)}var b5e=jb,x5e=RP,w5e=_5e,S5e=v5e,M5e={Deflate:b5e,deflate:x5e,deflateRaw:w5e,gzip:S5e};const MS=16209,E5e=16191;var C5e=function(t,n){let r,i,s,o,a,l,c,u,h,f,d,p,m,y,_,b,x,S,M,E,T,k,R,B;const F=t.state;r=t.next_in,R=t.input,i=r+(t.avail_in-5),s=t.next_out,B=t.output,o=s-(n-t.avail_out),a=s+(t.avail_out-257),l=F.dmax,c=F.wsize,u=F.whave,h=F.wnext,f=F.window,d=F.hold,p=F.bits,m=F.lencode,y=F.distcode,_=(1<<F.lenbits)-1,b=(1<<F.distbits)-1;e:do{p<15&&(d+=R[r++]<<p,p+=8,d+=R[r++]<<p,p+=8),x=m[d&_];t:for(;;){if(S=x>>>24,d>>>=S,p-=S,S=x>>>16&255,S===0)B[s++]=x&65535;else if(S&16){M=x&65535,S&=15,S&&(p<S&&(d+=R[r++]<<p,p+=8),M+=d&(1<<S)-1,d>>>=S,p-=S),p<15&&(d+=R[r++]<<p,p+=8,d+=R[r++]<<p,p+=8),x=y[d&b];n:for(;;){if(S=x>>>24,d>>>=S,p-=S,S=x>>>16&255,S&16){if(E=x&65535,S&=15,p<S&&(d+=R[r++]<<p,p+=8,p<S&&(d+=R[r++]<<p,p+=8)),E+=d&(1<<S)-1,E>l){t.msg="invalid distance too far back",F.mode=MS;break e}if(d>>>=S,p-=S,S=s-o,E>S){if(S=E-S,S>u&&F.sane){t.msg="invalid distance too far back",F.mode=MS;break e}if(T=0,k=f,h===0){if(T+=c-S,S<M){M-=S;do B[s++]=f[T++];while(--S);T=s-E,k=B}}else if(h<S){if(T+=c+h-S,S-=h,S<M){M-=S;do B[s++]=f[T++];while(--S);if(T=0,h<M){S=h,M-=S;do B[s++]=f[T++];while(--S);T=s-E,k=B}}}else if(T+=h-S,S<M){M-=S;do B[s++]=f[T++];while(--S);T=s-E,k=B}for(;M>2;)B[s++]=k[T++],B[s++]=k[T++],B[s++]=k[T++],M-=3;M&&(B[s++]=k[T++],M>1&&(B[s++]=k[T++]))}else{T=s-E;do B[s++]=B[T++],B[s++]=B[T++],B[s++]=B[T++],M-=3;while(M>2);M&&(B[s++]=B[T++],M>1&&(B[s++]=B[T++]))}}else if((S&64)===0){x=y[(x&65535)+(d&(1<<S)-1)];continue n}else{t.msg="invalid distance code",F.mode=MS;break e}break}}else if((S&64)===0){x=m[(x&65535)+(d&(1<<S)-1)];continue t}else if(S&32){F.mode=E5e;break e}else{t.msg="invalid literal/length code",F.mode=MS;break e}break}}while(r<i&&s<a);M=p>>3,r-=M,p-=M<<3,d&=(1<<p)-1,t.next_in=r,t.next_out=s,t.avail_in=r<i?5+(i-r):5-(r-i),t.avail_out=s<a?257+(a-s):257-(s-a),F.hold=d,F.bits=p};const b0=15,$7=852,V7=592,W7=0,M3=1,q7=2,A5e=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),T5e=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),k5e=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),R5e=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]),D5e=(e,t,n,r,i,s,o,a)=>{const l=a.bits;let c=0,u=0,h=0,f=0,d=0,p=0,m=0,y=0,_=0,b=0,x,S,M,E,T,k=null,R;const B=new Uint16Array(b0+1),F=new Uint16Array(b0+1);let L=null,j,V,O;for(c=0;c<=b0;c++)B[c]=0;for(u=0;u<r;u++)B[t[n+u]]++;for(d=l,f=b0;f>=1&&B[f]===0;f--);if(d>f&&(d=f),f===0)return i[s++]=1<<24|64<<16|0,i[s++]=1<<24|64<<16|0,a.bits=1,0;for(h=1;h<f&&B[h]===0;h++);for(d<h&&(d=h),y=1,c=1;c<=b0;c++)if(y<<=1,y-=B[c],y<0)return-1;if(y>0&&(e===W7||f!==1))return-1;for(F[1]=0,c=1;c<b0;c++)F[c+1]=F[c]+B[c];for(u=0;u<r;u++)t[n+u]!==0&&(o[F[t[n+u]]++]=u);if(e===W7?(k=L=o,R=20):e===M3?(k=A5e,L=T5e,R=257):(k=k5e,L=R5e,R=0),b=0,u=0,c=h,T=s,p=d,m=0,M=-1,_=1<<d,E=_-1,e===M3&&_>$7||e===q7&&_>V7)return 1;for(;;){j=c-m,o[u]+1<R?(V=0,O=o[u]):o[u]>=R?(V=L[o[u]-R],O=k[o[u]-R]):(V=96,O=0),x=1<<c-m,S=1<<p,h=S;do S-=x,i[T+(b>>m)+S]=j<<24|V<<16|O|0;while(S!==0);for(x=1<<c-1;b&x;)x>>=1;if(x!==0?(b&=x-1,b+=x):b=0,u++,--B[c]===0){if(c===f)break;c=t[n+o[u]]}if(c>d&&(b&E)!==M){for(m===0&&(m=d),T+=h,p=c-m,y=1<<p;p+m<f&&(y-=B[p+m],!(y<=0));)p++,y<<=1;if(_+=1<<p,e===M3&&_>$7||e===q7&&_>V7)return 1;M=b&E,i[M]=d<<24|p<<16|T-s|0}}return b!==0&&(i[T+b]=c-m<<24|64<<16|0),a.bits=d,0};var pv=D5e;const N5e=0,OY=1,jY=2,{Z_FINISH:G7,Z_BLOCK:L5e,Z_TREES:ES,Z_OK:Fm,Z_STREAM_END:I5e,Z_NEED_DICT:P5e,Z_STREAM_ERROR:Ec,Z_DATA_ERROR:HY,Z_MEM_ERROR:$Y,Z_BUF_ERROR:B5e,Z_DEFLATED:X7}=Ub,RE=16180,Y7=16181,K7=16182,Z7=16183,Q7=16184,J7=16185,ej=16186,tj=16187,nj=16188,rj=16189,mM=16190,Gh=16191,E3=16192,ij=16193,C3=16194,sj=16195,oj=16196,aj=16197,lj=16198,CS=16199,AS=16200,cj=16201,uj=16202,hj=16203,fj=16204,dj=16205,A3=16206,pj=16207,mj=16208,vs=16209,VY=16210,WY=16211,F5e=852,z5e=592,U5e=15,O5e=U5e,gj=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function j5e(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const Wm=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode<RE||t.mode>WY?1:0},qY=e=>{if(Wm(e))return Ec;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=t.wrap&1),t.mode=RE,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(F5e),t.distcode=t.distdyn=new Int32Array(z5e),t.sane=1,t.back=-1,Fm},GY=e=>{if(Wm(e))return Ec;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,qY(e)},XY=(e,t)=>{let n;if(Wm(e))return Ec;const r=e.state;return t<0?(n=0,t=-t):(n=(t>>4)+5,t<48&&(t&=15)),t&&(t<8||t>15)?Ec:(r.window!==null&&r.wbits!==t&&(r.window=null),r.wrap=n,r.wbits=t,GY(e))},YY=(e,t)=>{if(!e)return Ec;const n=new j5e;e.state=n,n.strm=e,n.window=null,n.mode=RE;const r=XY(e,t);return r!==Fm&&(e.state=null),r},H5e=e=>YY(e,O5e);let yj=!0,T3,k3;const $5e=e=>{if(yj){T3=new Int32Array(512),k3=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(pv(OY,e.lens,0,288,T3,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;pv(jY,e.lens,0,32,k3,0,e.work,{bits:5}),yj=!1}e.lencode=T3,e.lenbits=9,e.distcode=k3,e.distbits=5},KY=(e,t,n,r)=>{let i;const s=e.state;return s.window===null&&(s.wsize=1<<s.wbits,s.wnext=0,s.whave=0,s.window=new Uint8Array(s.wsize)),r>=s.wsize?(s.window.set(t.subarray(n-s.wsize,n),0),s.wnext=0,s.whave=s.wsize):(i=s.wsize-s.wnext,i>r&&(i=r),s.window.set(t.subarray(n-r,n-r+i),s.wnext),r-=i,r?(s.window.set(t.subarray(n-r,n),0),s.wnext=r,s.whave=s.wsize):(s.wnext+=i,s.wnext===s.wsize&&(s.wnext=0),s.whave<s.wsize&&(s.whave+=i))),0},V5e=(e,t)=>{let n,r,i,s,o,a,l,c,u,h,f,d,p,m,y=0,_,b,x,S,M,E,T,k;const R=new Uint8Array(4);let B,F;const L=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(Wm(e)||!e.output||!e.input&&e.avail_in!==0)return Ec;n=e.state,n.mode===Gh&&(n.mode=E3),o=e.next_out,i=e.output,l=e.avail_out,s=e.next_in,r=e.input,a=e.avail_in,c=n.hold,u=n.bits,h=a,f=l,k=Fm;e:for(;;)switch(n.mode){case RE:if(n.wrap===0){n.mode=E3;break}for(;u<16;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(n.wrap&2&&c===35615){n.wbits===0&&(n.wbits=15),n.check=0,R[0]=c&255,R[1]=c>>>8&255,n.check=Fo(n.check,R,2,0),c=0,u=0,n.mode=Y7;break}if(n.head&&(n.head.done=!1),!(n.wrap&1)||(((c&255)<<8)+(c>>8))%31){e.msg="incorrect header check",n.mode=vs;break}if((c&15)!==X7){e.msg="unknown compression method",n.mode=vs;break}if(c>>>=4,u-=4,T=(c&15)+8,n.wbits===0&&(n.wbits=T),T>15||T>n.wbits){e.msg="invalid window size",n.mode=vs;break}n.dmax=1<<n.wbits,n.flags=0,e.adler=n.check=1,n.mode=c&512?rj:Gh,c=0,u=0;break;case Y7:for(;u<16;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(n.flags=c,(n.flags&255)!==X7){e.msg="unknown compression method",n.mode=vs;break}if(n.flags&57344){e.msg="unknown header flags set",n.mode=vs;break}n.head&&(n.head.text=c>>8&1),n.flags&512&&n.wrap&4&&(R[0]=c&255,R[1]=c>>>8&255,n.check=Fo(n.check,R,2,0)),c=0,u=0,n.mode=K7;case K7:for(;u<32;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}n.head&&(n.head.time=c),n.flags&512&&n.wrap&4&&(R[0]=c&255,R[1]=c>>>8&255,R[2]=c>>>16&255,R[3]=c>>>24&255,n.check=Fo(n.check,R,4,0)),c=0,u=0,n.mode=Z7;case Z7:for(;u<16;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}n.head&&(n.head.xflags=c&255,n.head.os=c>>8),n.flags&512&&n.wrap&4&&(R[0]=c&255,R[1]=c>>>8&255,n.check=Fo(n.check,R,2,0)),c=0,u=0,n.mode=Q7;case Q7:if(n.flags&1024){for(;u<16;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}n.length=c,n.head&&(n.head.extra_len=c),n.flags&512&&n.wrap&4&&(R[0]=c&255,R[1]=c>>>8&255,n.check=Fo(n.check,R,2,0)),c=0,u=0}else n.head&&(n.head.extra=null);n.mode=J7;case J7:if(n.flags&1024&&(d=n.length,d>a&&(d=a),d&&(n.head&&(T=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(s,s+d),T)),n.flags&512&&n.wrap&4&&(n.check=Fo(n.check,r,d,s)),a-=d,s+=d,n.length-=d),n.length))break e;n.length=0,n.mode=ej;case ej:if(n.flags&2048){if(a===0)break e;d=0;do T=r[s+d++],n.head&&T&&n.length<65536&&(n.head.name+=String.fromCharCode(T));while(T&&d<a);if(n.flags&512&&n.wrap&4&&(n.check=Fo(n.check,r,d,s)),a-=d,s+=d,T)break e}else n.head&&(n.head.name=null);n.length=0,n.mode=tj;case tj:if(n.flags&4096){if(a===0)break e;d=0;do T=r[s+d++],n.head&&T&&n.length<65536&&(n.head.comment+=String.fromCharCode(T));while(T&&d<a);if(n.flags&512&&n.wrap&4&&(n.check=Fo(n.check,r,d,s)),a-=d,s+=d,T)break e}else n.head&&(n.head.comment=null);n.mode=nj;case nj:if(n.flags&512){for(;u<16;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(n.wrap&4&&c!==(n.check&65535)){e.msg="header crc mismatch",n.mode=vs;break}c=0,u=0}n.head&&(n.head.hcrc=n.flags>>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=Gh;break;case rj:for(;u<32;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}e.adler=n.check=gj(c),c=0,u=0,n.mode=mM;case mM:if(n.havedict===0)return e.next_out=o,e.avail_out=l,e.next_in=s,e.avail_in=a,n.hold=c,n.bits=u,P5e;e.adler=n.check=1,n.mode=Gh;case Gh:if(t===L5e||t===ES)break e;case E3:if(n.last){c>>>=u&7,u-=u&7,n.mode=A3;break}for(;u<3;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}switch(n.last=c&1,c>>>=1,u-=1,c&3){case 0:n.mode=ij;break;case 1:if($5e(n),n.mode=CS,t===ES){c>>>=2,u-=2;break e}break;case 2:n.mode=oj;break;case 3:e.msg="invalid block type",n.mode=vs}c>>>=2,u-=2;break;case ij:for(c>>>=u&7,u-=u&7;u<32;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if((c&65535)!==(c>>>16^65535)){e.msg="invalid stored block lengths",n.mode=vs;break}if(n.length=c&65535,c=0,u=0,n.mode=C3,t===ES)break e;case C3:n.mode=sj;case sj:if(d=n.length,d){if(d>a&&(d=a),d>l&&(d=l),d===0)break e;i.set(r.subarray(s,s+d),o),a-=d,s+=d,l-=d,o+=d,n.length-=d;break}n.mode=Gh;break;case oj:for(;u<14;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(n.nlen=(c&31)+257,c>>>=5,u-=5,n.ndist=(c&31)+1,c>>>=5,u-=5,n.ncode=(c&15)+4,c>>>=4,u-=4,n.nlen>286||n.ndist>30){e.msg="too many length or distance symbols",n.mode=vs;break}n.have=0,n.mode=aj;case aj:for(;n.have<n.ncode;){for(;u<3;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}n.lens[L[n.have++]]=c&7,c>>>=3,u-=3}for(;n.have<19;)n.lens[L[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,B={bits:n.lenbits},k=pv(N5e,n.lens,0,19,n.lencode,0,n.work,B),n.lenbits=B.bits,k){e.msg="invalid code lengths set",n.mode=vs;break}n.have=0,n.mode=lj;case lj:for(;n.have<n.nlen+n.ndist;){for(;y=n.lencode[c&(1<<n.lenbits)-1],_=y>>>24,b=y>>>16&255,x=y&65535,!(_<=u);){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(x<16)c>>>=_,u-=_,n.lens[n.have++]=x;else{if(x===16){for(F=_+2;u<F;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(c>>>=_,u-=_,n.have===0){e.msg="invalid bit length repeat",n.mode=vs;break}T=n.lens[n.have-1],d=3+(c&3),c>>>=2,u-=2}else if(x===17){for(F=_+3;u<F;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}c>>>=_,u-=_,T=0,d=3+(c&7),c>>>=3,u-=3}else{for(F=_+7;u<F;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}c>>>=_,u-=_,T=0,d=11+(c&127),c>>>=7,u-=7}if(n.have+d>n.nlen+n.ndist){e.msg="invalid bit length repeat",n.mode=vs;break}for(;d--;)n.lens[n.have++]=T}}if(n.mode===vs)break;if(n.lens[256]===0){e.msg="invalid code -- missing end-of-block",n.mode=vs;break}if(n.lenbits=9,B={bits:n.lenbits},k=pv(OY,n.lens,0,n.nlen,n.lencode,0,n.work,B),n.lenbits=B.bits,k){e.msg="invalid literal/lengths set",n.mode=vs;break}if(n.distbits=6,n.distcode=n.distdyn,B={bits:n.distbits},k=pv(jY,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,B),n.distbits=B.bits,k){e.msg="invalid distances set",n.mode=vs;break}if(n.mode=CS,t===ES)break e;case CS:n.mode=AS;case AS:if(a>=6&&l>=258){e.next_out=o,e.avail_out=l,e.next_in=s,e.avail_in=a,n.hold=c,n.bits=u,C5e(e,f),o=e.next_out,i=e.output,l=e.avail_out,s=e.next_in,r=e.input,a=e.avail_in,c=n.hold,u=n.bits,n.mode===Gh&&(n.back=-1);break}for(n.back=0;y=n.lencode[c&(1<<n.lenbits)-1],_=y>>>24,b=y>>>16&255,x=y&65535,!(_<=u);){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(b&&(b&240)===0){for(S=_,M=b,E=x;y=n.lencode[E+((c&(1<<S+M)-1)>>S)],_=y>>>24,b=y>>>16&255,x=y&65535,!(S+_<=u);){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}c>>>=S,u-=S,n.back+=S}if(c>>>=_,u-=_,n.back+=_,n.length=x,b===0){n.mode=dj;break}if(b&32){n.back=-1,n.mode=Gh;break}if(b&64){e.msg="invalid literal/length code",n.mode=vs;break}n.extra=b&15,n.mode=cj;case cj:if(n.extra){for(F=n.extra;u<F;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}n.length+=c&(1<<n.extra)-1,c>>>=n.extra,u-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=uj;case uj:for(;y=n.distcode[c&(1<<n.distbits)-1],_=y>>>24,b=y>>>16&255,x=y&65535,!(_<=u);){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if((b&240)===0){for(S=_,M=b,E=x;y=n.distcode[E+((c&(1<<S+M)-1)>>S)],_=y>>>24,b=y>>>16&255,x=y&65535,!(S+_<=u);){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}c>>>=S,u-=S,n.back+=S}if(c>>>=_,u-=_,n.back+=_,b&64){e.msg="invalid distance code",n.mode=vs;break}n.offset=x,n.extra=b&15,n.mode=hj;case hj:if(n.extra){for(F=n.extra;u<F;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}n.offset+=c&(1<<n.extra)-1,c>>>=n.extra,u-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg="invalid distance too far back",n.mode=vs;break}n.mode=fj;case fj:if(l===0)break e;if(d=f-l,n.offset>d){if(d=n.offset-d,d>n.whave&&n.sane){e.msg="invalid distance too far back",n.mode=vs;break}d>n.wnext?(d-=n.wnext,p=n.wsize-d):p=n.wnext-d,d>n.length&&(d=n.length),m=n.window}else m=i,p=o-n.offset,d=n.length;d>l&&(d=l),l-=d,n.length-=d;do i[o++]=m[p++];while(--d);n.length===0&&(n.mode=AS);break;case dj:if(l===0)break e;i[o++]=n.length,l--,n.mode=AS;break;case A3:if(n.wrap){for(;u<32;){if(a===0)break e;a--,c|=r[s++]<<u,u+=8}if(f-=l,e.total_out+=f,n.total+=f,n.wrap&4&&f&&(e.adler=n.check=n.flags?Fo(n.check,i,f,o-f):ib(n.check,i,f,o-f)),f=l,n.wrap&4&&(n.flags?c:gj(c))!==n.check){e.msg="incorrect data check",n.mode=vs;break}c=0,u=0}n.mode=pj;case pj:if(n.wrap&&n.flags){for(;u<32;){if(a===0)break e;a--,c+=r[s++]<<u,u+=8}if(n.wrap&4&&c!==(n.total&4294967295)){e.msg="incorrect length check",n.mode=vs;break}c=0,u=0}n.mode=mj;case mj:k=I5e;break e;case vs:k=HY;break e;case VY:return $Y;case WY:default:return Ec}return e.next_out=o,e.avail_out=l,e.next_in=s,e.avail_in=a,n.hold=c,n.bits=u,(n.wsize||f!==e.avail_out&&n.mode<vs&&(n.mode<A3||t!==G7))&&KY(e,e.output,e.next_out,f-e.avail_out),h-=e.avail_in,f-=e.avail_out,e.total_in+=h,e.total_out+=f,n.total+=f,n.wrap&4&&f&&(e.adler=n.check=n.flags?Fo(n.check,i,f,e.next_out-f):ib(n.check,i,f,e.next_out-f)),e.data_type=n.bits+(n.last?64:0)+(n.mode===Gh?128:0)+(n.mode===CS||n.mode===C3?256:0),(h===0&&f===0||t===G7)&&k===Fm&&(k=B5e),k},W5e=e=>{if(Wm(e))return Ec;let t=e.state;return t.window&&(t.window=null),e.state=null,Fm},q5e=(e,t)=>{if(Wm(e))return Ec;const n=e.state;return(n.wrap&2)===0?Ec:(n.head=t,t.done=!1,Fm)},G5e=(e,t)=>{const n=t.length;let r,i,s;return Wm(e)||(r=e.state,r.wrap!==0&&r.mode!==mM)?Ec:r.mode===mM&&(i=1,i=ib(i,t,n,0),i!==r.check)?HY:(s=KY(e,t,n,n),s?(r.mode=VY,$Y):(r.havedict=1,Fm))};var X5e=GY,Y5e=XY,K5e=qY,Z5e=H5e,Q5e=YY,J5e=V5e,e4e=W5e,t4e=q5e,n4e=G5e,r4e="pako inflate (from Nodeca project)",ef={inflateReset:X5e,inflateReset2:Y5e,inflateResetKeep:K5e,inflateInit:Z5e,inflateInit2:Q5e,inflate:J5e,inflateEnd:e4e,inflateGetHeader:t4e,inflateSetDictionary:n4e,inflateInfo:r4e};function i4e(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1}var s4e=i4e;const ZY=Object.prototype.toString,{Z_NO_FLUSH:o4e,Z_FINISH:a4e,Z_OK:ab,Z_STREAM_END:R3,Z_NEED_DICT:D3,Z_STREAM_ERROR:l4e,Z_DATA_ERROR:_j,Z_MEM_ERROR:c4e}=Ub;function Hb(e){this.options=kE.assign({chunkSize:1024*64,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,t.windowBits===0&&(t.windowBits=-15)),t.windowBits>=0&&t.windowBits<16&&!(e&&e.windowBits)&&(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(t.windowBits&15)===0&&(t.windowBits|=15),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new zY,this.strm.avail_out=0;let n=ef.inflateInit2(this.strm,t.windowBits);if(n!==ab)throw new Error(Pm[n]);if(this.header=new s4e,ef.inflateGetHeader(this.strm,this.header),t.dictionary&&(typeof t.dictionary=="string"?t.dictionary=ob.string2buf(t.dictionary):ZY.call(t.dictionary)==="[object ArrayBuffer]"&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(n=ef.inflateSetDictionary(this.strm,t.dictionary),n!==ab)))throw new Error(Pm[n])}Hb.prototype.push=function(e,t){const n=this.strm,r=this.options.chunkSize,i=this.options.dictionary;let s,o,a;if(this.ended)return!1;for(t===~~t?o=t:o=t===!0?a4e:o4e,ZY.call(e)==="[object ArrayBuffer]"?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){for(n.avail_out===0&&(n.output=new Uint8Array(r),n.next_out=0,n.avail_out=r),s=ef.inflate(n,o),s===D3&&i&&(s=ef.inflateSetDictionary(n,i),s===ab?s=ef.inflate(n,o):s===_j&&(s=D3));n.avail_in>0&&s===R3&&n.state.wrap>0&&e[n.next_in]!==0;)ef.inflateReset(n),s=ef.inflate(n,o);switch(s){case l4e:case _j:case D3:case c4e:return this.onEnd(s),this.ended=!0,!1}if(a=n.avail_out,n.next_out&&(n.avail_out===0||s===R3))if(this.options.to==="string"){let l=ob.utf8border(n.output,n.next_out),c=n.next_out-l,u=ob.buf2string(n.output,l);n.next_out=c,n.avail_out=r-c,c&&n.output.set(n.output.subarray(l,l+c),0),this.onData(u)}else this.onData(n.output.length===n.next_out?n.output:n.output.subarray(0,n.next_out));if(!(s===ab&&a===0)){if(s===R3)return s=ef.inflateEnd(this.strm),this.onEnd(s),this.ended=!0,!0;if(n.avail_in===0)break}}return!0};Hb.prototype.onData=function(e){this.chunks.push(e)};Hb.prototype.onEnd=function(e){e===ab&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=kE.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function DP(e,t){const n=new Hb(t);if(n.push(e),n.err)throw n.msg||Pm[n.err];return n.result}function u4e(e,t){return t=t||{},t.raw=!0,DP(e,t)}var h4e=Hb,f4e=DP,d4e=u4e,p4e=DP,m4e={Inflate:h4e,inflate:f4e,inflateRaw:d4e,ungzip:p4e};const{Deflate:g4e,deflate:y4e,deflateRaw:_4e,gzip:v4e}=M5e,{Inflate:b4e,inflate:x4e,inflateRaw:w4e,ungzip:S4e}=m4e;var M4e=g4e,E4e=y4e,C4e=_4e,A4e=v4e,T4e=b4e,k4e=x4e,R4e=w4e,D4e=S4e,N4e=Ub,L4e={Deflate:M4e,deflate:E4e,deflateRaw:C4e,gzip:A4e,Inflate:T4e,inflate:k4e,inflateRaw:R4e,ungzip:D4e,constants:N4e};const I4e=new TextEncoder;function P4e(e,t,n){const r=e.find(l=>l.id===n),i={files:e.map(l=>({name:l.name,content:T_(t.get(l.id)??new Uint8Array(0))})),activeFileName:r?.name??null},s=JSON.stringify(i),o=L4e.deflate(I4e.encode(s));let a=btoa(String.fromCharCode(...o));return a=a.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),a}const B4e="https://numbl.org";function F4e(){const{files:e,activeFileId:t,loading:n,title:r,repository:i,maxInitialOutputPanelHeight:s,loadError:o,setActiveFileId:a,updateFileContent:l,addFile:c,addFolder:u,deleteFile:h,deleteFolder:f,renameFile:d,renameFolder:p,moveFile:m,duplicateFile:y,uploadFiles:_,loadFileContent:b,loadAllContents:x,contentCache:S}=$H(),[M,E]=ne.useState(!1);ne.useEffect(()=>{r&&(document.title=r)},[r]);const T=ne.useCallback(async()=>{try{const R=await x(),B=P4e(e,R,t),F=`${B4e}/share#${B}`;if(F.length>64e3){alert("Project is too large to share via URL. Try reducing the number or size of files.");return}await navigator.clipboard.writeText(F),E(!0),setTimeout(()=>E(!1),2e3)}catch(R){console.error("Failed to generate share URL:",R),alert("Failed to generate share URL.")}},[e,t,x]);if(n)return le.jsx(Cn,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:le.jsx(L0,{})});const k=le.jsxs(le.Fragment,{children:[le.jsxs(Fr,{variant:"body2",fontWeight:"medium",sx:{flexGrow:1},noWrap:!0,children:[r||"numbl project",o&&le.jsx(Fr,{component:"span",variant:"caption",color:"warning.main",sx:{ml:1},children:"(bundle failed to load)"})]}),i&&le.jsx(Su,{title:"View source repository",children:le.jsx(lo,{size:"small",component:"a",href:i,target:"_blank",rel:"noopener noreferrer",sx:{mr:.5},children:le.jsx(nH,{fontSize:"small"})})}),le.jsx(Su,{title:M?"Copied!":"Copy shareable URL",children:le.jsx(lo,{size:"small",onClick:T,sx:{mr:.5},children:le.jsx($ee,{fontSize:"small"})})}),le.jsx(Mv,{href:"https://numbl.org",target:"_blank",rel:"noopener noreferrer",variant:"caption",underline:"hover",sx:{opacity:.7,"&:hover":{opacity:1}},children:"powered by numbl"})]});return le.jsx(FIe,{files:e,activeFileId:t,setActiveFileId:a,updateFileContent:l,addFile:c,addFolder:u,deleteFile:h,deleteFolder:f,renameFile:d,renameFolder:p,moveFile:m,duplicateFile:y,uploadFiles:_,headerContent:k,loadFileContent:b,loadAllContents:x,contentCache:S,maxInitialOutputPanelHeight:s??void 0})}const z4e=oi(le.jsx("path",{d:"M9.4 16.6 4.8 12l4.6-4.6L8 6l-6 6 6 6zm5.2 0 4.6-4.6-4.6-4.6L16 6l6 6-6 6z"})),U4e="https://numbl.org";function O4e(e,t){if(e.length===0)return{spec:null,unknownSlug:!1};if(!t)return{spec:e[0],unknownSlug:!1};const n=e.find(r=>r.id===t);return n?{spec:n,unknownSlug:!1}:{spec:e[0],unknownSlug:!0}}function j4e({figureId:e}){const{files:t,loading:n,title:r,repository:i,figures:s,loadError:o,loadAllContents:a}=$H(),{reloadSystemFiles:l,getSystemVfsFiles:c,getSystemWorkspaceFiles:u}=dY();gY(l);const{spec:h,unknownSlug:f}=ne.useMemo(()=>O4e(s,e),[s,e]),[d,p]=ne.useState(""),[m,y]=ne.useState(!1),[_,b]=ne.useState(!1),[x,S]=ne.useState(!1),[M,E]=ne.useReducer(_I,QM),T=ne.useRef(null),k=ne.useRef(WH()),R=ne.useRef(null),B=h?.name||r||"Figure";ne.useEffect(()=>{document.title=B},[B]);const F=ne.useMemo(()=>{const H=Object.keys(M.figs).map(Number).sort((U,G)=>U-G);return H.length===0?null:M.figs[H[H.length-1]]},[M.figs]),L=F!==null,j=ne.useCallback(H=>{E(H)},[]),V=ne.useCallback(H=>{H.onmessage=U=>{const G=U.data;if(G.type==="request-input"){const Z=prompt(G.prompt??"")??"";k.current&&qH(k.current,Z);return}if(G.type==="output"){p(Z=>Z+G.text);return}if(G.type==="drawnow"){if(G.plotInstructions?.length)for(const Z of G.plotInstructions)j(Z);return}if(G.type==="html_source_event"){document.querySelectorAll(`iframe[title="uihtml-${G.compId}"]`).forEach(ie=>ie.contentWindow?.postMessage({source:"numbl-host",compId:G.compId,name:G.name,dataJson:G.dataJson},"*"));return}if(G.type==="done"){if(y(!1),G.vfsChanges&&fY(G.vfsChanges).then(Z=>{Z&&l()}),G.plotInstructions?.length)for(const Z of G.plotInstructions)j(Z);return}if(G.type==="error"){y(!1),b(!0),S(!0),p(Z=>Z+`
|
|
4829
4829
|
${EV(G)}
|
|
4830
|
-
`);return}}},[j,l]);ne.useEffect(()=>{const H=new Worker(new URL(""+new URL("numbl-worker-
|
|
4830
|
+
`);return}}},[j,l]);ne.useEffect(()=>{const H=new Worker(new URL(""+new URL("numbl-worker-DddtCPW_.js",import.meta.url).href,import.meta.url),{type:"module"});return T.current=H,V(H),R.current=null,()=>{H.terminate(),T.current=null}},[V]),ne.useEffect(()=>{const H=U=>{const G=U.data;!G||G.source!=="numbl-uihtml"||T.current?.postMessage({type:"html_event",compId:G.compId,kind:G.kind,name:G.name,data:G.data})};return window.addEventListener("message",H),()=>window.removeEventListener("message",H)},[]);const O=ne.useCallback(async()=>{const H=T.current;if(!H||!h)return;const U=t.find(X=>X.name===h.entry);if(!U){b(!0),S(!0),p(`Figure script not found in the project bundle: ${h.entry}
|
|
4831
4831
|
`);return}y(!0),b(!1),p(""),E({type:"clear"}),mY();const G=new TextDecoder("utf-8"),[Z,ie,Y]=await Promise.all([a(),c(),u()]),ue=[...t.map(X=>({path:X.name,content:Z.get(X.id)??new Uint8Array(0)})),...ie],ge=[...t.filter(X=>X.name.endsWith(".m")).map(X=>({name:X.name,source:G.decode(Z.get(X.id)??new Uint8Array(0))})),...Y],te=G.decode(Z.get(U.id)??new Uint8Array(0));H.postMessage({type:"update_workspace",workspaceFiles:ge,vfsFiles:ue}),H.postMessage({type:"run",code:te,options:{displayResults:!0,maxIterations:1e7,optimization:1},workspaceFiles:ge,vfsFiles:ue,mainFileName:U.name,persistent:!0,inputSAB:k.current??void 0})},[h,t,a,c,u]);ne.useEffect(()=>{n||!h||!T.current||R.current!==h.id&&(R.current=h.id,O())},[n,h,O]);const P=ne.useMemo(()=>window.location.pathname+window.location.search,[]);if(n)return le.jsx(Cn,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh"},children:le.jsx(L0,{})});if(!h)return le.jsxs(Cn,{sx:{display:"flex",flexDirection:"column",gap:1,justifyContent:"center",alignItems:"center",height:"100vh",textAlign:"center",px:2},children:[le.jsx(Fr,{variant:"h6",children:"No figure view configured"}),le.jsx(Fr,{variant:"body2",color:"text.secondary",children:o?"The project bundle failed to load.":'This project declares no "figures" in numbl-project.json.'}),le.jsx(Mv,{href:P,underline:"hover",children:"Open the full IDE"})]});const N=x||!L;return le.jsxs(Cn,{sx:{display:"flex",flexDirection:"column",height:"100vh"},children:[le.jsxs(Cn,{sx:{display:"flex",alignItems:"center",gap:1,px:1.5,py:.5,bgcolor:"grey.100",borderBottom:1,borderColor:"divider",minHeight:40},children:[le.jsx(Fr,{variant:"body2",fontWeight:"medium",noWrap:!0,children:B}),m&&le.jsxs(Cn,{sx:{display:"flex",alignItems:"center",gap:.5},children:[le.jsx(L0,{size:12}),le.jsx(Fr,{variant:"caption",color:"text.secondary",children:"Running…"})]}),le.jsx(Cn,{sx:{flexGrow:1}}),L&&le.jsx(Md,{size:"small",onClick:()=>S(H=>!H),sx:{textTransform:"none",fontSize:"0.75rem"},children:x?"Hide output":"Show output"}),le.jsx(Su,{title:"View / edit the code in the full IDE",children:le.jsx(Md,{size:"small",href:P,startIcon:le.jsx(z4e,{fontSize:"small"}),sx:{textTransform:"none",fontSize:"0.75rem"},children:"Code"})}),i&&le.jsx(Su,{title:"View source repository",children:le.jsx(lo,{size:"small",component:"a",href:i,target:"_blank",rel:"noopener noreferrer",children:le.jsx(nH,{fontSize:"small"})})}),le.jsx(Mv,{href:U4e,target:"_blank",rel:"noopener noreferrer",variant:"caption",underline:"hover",sx:{opacity:.7,"&:hover":{opacity:1}},children:"powered by numbl"})]}),f&&le.jsxs(Cn,{sx:{px:1.5,py:.5,bgcolor:"#fff8e1",borderBottom:"1px solid #f0e0a0",fontSize:13,color:"#5c4a00"},children:["Unknown figure “",e,"”. Showing “",B,"” instead."]}),le.jsxs(Cn,{sx:{flexGrow:1,position:"relative",minHeight:0},children:[L&&le.jsx(Cn,{sx:{position:"absolute",inset:0,display:"flex",justifyContent:"center",alignItems:"center",bgcolor:"#fff"},children:F&&le.jsx(TD,{figure:F})}),N&&le.jsxs(Cn,{sx:{position:"absolute",left:0,right:0,bottom:0,top:L?"auto":0,maxHeight:L?"45%":"100%",overflow:"auto",p:1.5,bgcolor:"#1e1e1e",fontFamily:"monospace",fontSize:13,color:_?"#f48771":"#d4d4d4",whiteSpace:"pre-wrap",wordBreak:"break-word",borderTop:L?"1px solid #333":void 0},children:[m&&!d&&le.jsxs(Cn,{sx:{display:"flex",alignItems:"center",gap:1},children:[le.jsx(L0,{size:14,sx:{color:"#d4d4d4"}}),le.jsx("span",{children:"Running…"})]}),d||!m&&le.jsx("span",{style:{opacity:.5},children:"—"})]})]})]})}function H4e(){const[e,t]=ne.useState(()=>window.location.hash);return ne.useEffect(()=>{const n=()=>t(window.location.hash);return window.addEventListener("hashchange",n),()=>window.removeEventListener("hashchange",n)},[]),e}function $4e(){const e=H4e(),t=/^#figure(?:\/(.*))?$/.exec(e);if(t){const n=t[1]?.split(/[?#]/)[0],r=n?decodeURIComponent(n):void 0;return le.jsx(j4e,{figureId:r})}return le.jsx(F4e,{})}EZ.createRoot(document.getElementById("root")).render(le.jsx(ne.StrictMode,{children:le.jsx($4e,{})}));
|