numpy-ts 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var np=(()=>{var Yr=Object.defineProperty;var vu=Object.getOwnPropertyDescriptor;var Ou=Object.getOwnPropertyNames;var Uu=Object.prototype.hasOwnProperty;var Tu=(r,t)=>{for(var e in t)Yr(r,e,{get:t[e],enumerable:!0})},$u=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ou(t))!Uu.call(r,o)&&o!==e&&Yr(r,o,{get:()=>t[o],enumerable:!(n=vu(t,o))||n.enumerable});return r};var Mu=r=>$u(Yr({},"__esModule",{value:!0}),r);var il={};Tu(il,{DTYPE_TO_DESCR:()=>Nr,InvalidNpyError:()=>Z,NDArray:()=>z,SUPPORTED_DTYPES:()=>Rr,UnsupportedDTypeError:()=>Q,__version__:()=>sl,absolute:()=>Da,append:()=>Bs,arange:()=>Po,arccos:()=>Pa,arccosh:()=>Ka,arcsin:()=>Fa,arcsinh:()=>Xa,arctan:()=>ja,arctan2:()=>Ra,arctanh:()=>rs,argpartition:()=>Ri,argsort:()=>Fi,around:()=>Yt,array:()=>j,array_equal:()=>Vs,array_equiv:()=>qs,array_split:()=>is,asanyarray:()=>Qo,asarray:()=>br,ascontiguousarray:()=>Xo,asfortranarray:()=>Ko,atleast_1d:()=>Ns,atleast_2d:()=>Ds,atleast_3d:()=>xs,average:()=>Ws,bitwise_and:()=>fi,bitwise_not:()=>yi,bitwise_or:()=>mi,bitwise_xor:()=>pi,broadcast_arrays:()=>Ts,broadcast_shapes:()=>$s,broadcast_to:()=>Us,cbrt:()=>ai,ceil:()=>Qi,choose:()=>Cs,column_stack:()=>Is,compress:()=>Ii,concatenate:()=>or,copy:()=>Wo,cos:()=>Va,cosh:()=>Ja,count_nonzero:()=>Ji,cross:()=>mu,cumprod:()=>Ps,cumsum:()=>Fs,deg2rad:()=>Ga,degrees:()=>Za,delete:()=>Es,diag:()=>Gt,diag_indices:()=>Bi,diag_indices_from:()=>Ei,diagflat:()=>ra,diagonal:()=>Oa,diff:()=>cu,divmod:()=>ii,dot:()=>Ea,dsplit:()=>ws,dstack:()=>as,ediff1d:()=>lu,einsum:()=>Si,empty:()=>Zt,empty_like:()=>Yo,exp:()=>pa,exp2:()=>ya,expand_dims:()=>ds,expm1:()=>da,extract:()=>Yi,eye:()=>Lt,fabs:()=>si,fix:()=>Xi,flatnonzero:()=>Wi,flip:()=>jr,fliplr:()=>gs,flipud:()=>hs,floor:()=>Ki,floor_divide:()=>za,frombuffer:()=>ia,fromfile:()=>ua,fromfunction:()=>ta,fromiter:()=>ca,fromstring:()=>la,full:()=>Wt,full_like:()=>Jo,geomspace:()=>Lo,gradient:()=>fu,heaviside:()=>li,hsplit:()=>cs,hstack:()=>os,hypot:()=>La,identity:()=>Zo,in1d:()=>nu,indices:()=>Mi,inner:()=>$a,insert:()=>vs,intersect1d:()=>ou,invert:()=>di,isin:()=>au,ix_:()=>ki,kron:()=>Ua,left_shift:()=>gi,lexsort:()=>Pi,linalg:()=>Ni,linspace:()=>jo,loadNpz:()=>re,loadNpzSync:()=>te,log:()=>ga,log10:()=>Aa,log1p:()=>ba,log2:()=>ha,logaddexp:()=>Sa,logaddexp2:()=>Na,logspace:()=>Ro,mask_indices:()=>$i,median:()=>Rs,meshgrid:()=>ea,mod:()=>Ia,moveaxis:()=>es,nanargmax:()=>ti,nanargmin:()=>ri,nancumprod:()=>ni,nancumsum:()=>ei,nanmax:()=>Ks,nanmean:()=>Ys,nanmedian:()=>oi,nanmin:()=>Xs,nanprod:()=>Hs,nanstd:()=>Qs,nansum:()=>Gs,nanvar:()=>Js,negative:()=>xa,nonzero:()=>Zi,ones:()=>Rt,ones_like:()=>Ho,outer:()=>Ma,packbits:()=>Ai,pad:()=>Os,parseNpy:()=>Dr,parseNpyData:()=>Zr,parseNpyHeader:()=>Lr,parseNpz:()=>Wr,parseNpzSync:()=>Gr,partition:()=>ji,percentile:()=>Ls,place:()=>_i,positive:()=>_a,power:()=>ma,ptp:()=>js,put:()=>ks,put_along_axis:()=>xi,putmask:()=>wi,quantile:()=>Zs,rad2deg:()=>Ha,radians:()=>Wa,ravel:()=>ms,ravel_multi_index:()=>Ci,reciprocal:()=>Ba,remainder:()=>ci,repeat:()=>fs,reshape:()=>ps,resize:()=>_s,right_shift:()=>hi,rint:()=>ru,roll:()=>bs,rollaxis:()=>Ss,rot90:()=>As,round:()=>Yt,row_stack:()=>zs,searchsorted:()=>Hi,select:()=>zi,serializeNpy:()=>cr,serializeNpz:()=>ee,serializeNpzSync:()=>ne,setdiff1d:()=>su,setxor1d:()=>iu,sign:()=>wa,sin:()=>Ca,sinh:()=>Ya,sort:()=>qi,sort_complex:()=>Li,split:()=>ss,sqrt:()=>fa,square:()=>ui,squeeze:()=>ys,stack:()=>ns,swapaxes:()=>ts,take:()=>Ms,take_along_axis:()=>Di,tan:()=>qa,tanh:()=>Qa,tensordot:()=>ka,tile:()=>ls,trace:()=>va,transpose:()=>Ta,tri:()=>na,tril:()=>oa,tril_indices:()=>vi,tril_indices_from:()=>Oi,triu:()=>aa,triu_indices:()=>Ui,triu_indices_from:()=>Ti,trunc:()=>tu,union1d:()=>uu,unique:()=>eu,unpackbits:()=>bi,unravel_index:()=>Vi,vander:()=>sa,vsplit:()=>us,vstack:()=>Ht,where:()=>Gi,zeros:()=>J,zeros_like:()=>Go});function oe(r){if(!r.includes(":")){if(r.includes("."))throw new Error(`Invalid slice index: "${r}" (must be integer)`);let a=parseInt(r,10);if(isNaN(a))throw new Error(`Invalid slice index: "${r}"`);return{start:a,stop:null,step:1,isIndex:!0}}let t=r.split(":");if(t.length>3)throw new Error(`Invalid slice notation: "${r}" (too many colons)`);let e=t[0]===""?null:parseInt(t[0],10),n=t[1]===""||t[1]===void 0?null:parseInt(t[1],10),o=t[2]===""||t[2]===void 0?1:parseInt(t[2],10);if(e!==null&&isNaN(e))throw new Error(`Invalid start index in slice: "${r}"`);if(n!==null&&isNaN(n))throw new Error(`Invalid stop index in slice: "${r}"`);if(isNaN(o))throw new Error(`Invalid step in slice: "${r}"`);if(o===0)throw new Error("Slice step cannot be zero");return{start:e,stop:n,step:o,isIndex:!1}}function ae(r,t){let{start:e,stop:n}=r,{step:o,isIndex:a}=r;if(a){if(e===null)throw new Error("Index cannot be null");let i=e<0?t+e:e;if(i<0||i>=t)throw new Error(`Index ${e} is out of bounds for size ${t}`);return{start:i,stop:i+1,step:1,isIndex:!0}}return o>0?(e===null&&(e=0),n===null&&(n=t)):(e===null&&(e=t-1),n===null&&(n=-t-1)),e<0&&(e=t+e),n<0&&(n=t+n),e=Math.max(0,Math.min(e,t)),n=Math.max(-1,Math.min(n,t)),{start:e,stop:n,step:o,isIndex:!1}}var q="float64";function T(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function ie(r){switch(r){case"float64":case"int64":case"uint64":return 8;case"float32":case"int32":case"uint32":return 4;case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${r}`)}}function ue(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function se(r){return r==="float64"||r==="float32"}function I(r){return r==="int64"||r==="uint64"}function k(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(se(r)||se(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){let c=t;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}if(t==="float32"){let c=r;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}return"float32"}let e=r.startsWith("int"),n=t.startsWith("int"),o=r.startsWith("uint"),a=t.startsWith("uint"),i=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,u=i(r),s=i(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&u===s){if(u===8)return"int16";if(u===16)return"int32";if(u===32)return"int64"}if(o&&n&&u===s){if(s===8)return"int16";if(s===16)return"int32";if(s===32)return"int64"}if(e&&n||o&&a){let c=Math.max(u,s);return e?c===64?"int64":c===32?"int32":c===16?"int16":"int8":c===64?"uint64":c===32?"uint32":c===16?"uint16":"uint8"}return e&&a?u>s?r:s===8?"int16":s===16?"int32":s===32?"int64":"float64":o&&n?s>u?t:u===8?"int16":u===16?"int32":u===32?"int64":"float64":"float64"}var N=class r{constructor(t,e,n,o,a){this._data=t,this._shape=e,this._strides=n,this._offset=o,this._dtype=a}get shape(){return this._shape}get ndim(){return this._shape.length}get size(){return this._shape.reduce((t,e)=>t*e,1)}get dtype(){return this._dtype}get data(){return this._data}get strides(){return this._strides}get offset(){return this._offset}get isCContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=n-1;a>=0;a--){if(e[a]!==o)return!1;o*=t[a]}return!0}get isFContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=0;a<n;a++){if(e[a]!==o)return!1;o*=t[a]}return!0}iget(t){let e=this._shape,n=this._strides,o=e.length;if(o===0)return this._data[this._offset];let a=t,i=this._offset;for(let u=0;u<o;u++){let s=1;for(let l=u+1;l<o;l++)s*=e[l];let c=Math.floor(a/s);a=a%s,i+=c*n[u]}return this._data[i]}iset(t,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let i=t,u=this._offset;for(let s=0;s<a;s++){let c=1;for(let m=s+1;m<a;m++)c*=n[m];let l=Math.floor(i/c);i=i%c,u+=l*o[s]}this._data[u]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];return this._data[n]}set(t,e){let n=this._strides,o=this._offset;for(let a=0;a<t.length;a++)o+=t[a]*n[a];this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=T(e);if(!o)throw new Error(`Cannot copy array with dtype ${e}`);let a=new o(n);if(this.isCContiguous&&this._offset===0)if(I(e)){let i=this._data,u=a;for(let s=0;s<n;s++)u[s]=i[s]}else a.set(this._data);else if(I(e)){let i=a;for(let u=0;u<n;u++)i[u]=this.iget(u)}else for(let i=0;i<n;i++)a[i]=this.iget(i);return new r(a,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let i=o??r._computeStrides(e),u=a??0;return new r(t,e,i,u,n)}static zeros(t,e=q){let n=t.reduce((i,u)=>i*u,1),o=T(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return new r(a,t,r._computeStrides(t),0,e)}static ones(t,e=q){let n=t.reduce((i,u)=>i*u,1),o=T(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return I(e)?a.fill(BigInt(1)):a.fill(1),new r(a,t,r._computeStrides(t),0,e)}static _computeStrides(t){let e=new Array(t.length),n=1;for(let o=t.length-1;o>=0;o--)e[o]=n,n*=t[o];return e}};function L(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}function mr(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let i=0;i<o;i++){let u=i<o-e?1:r[i-(o-e)],s=i<o-n?1:t[i-(o-n)];if(u===s)a[i]=u;else if(u===1)a[i]=s;else if(s===1)a[i]=u;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function ku(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let i=0;i<n;i++){let u=o-n+i,s=r[i],c=e[u];if(s===c)a[u]=t[i];else if(s===1)a[u]=0;else throw new Error("Invalid broadcast")}return a}function wr(r,t){let e=ku(r.shape,r.strides,t);return N.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function F(r,t,e,n){let o=mr(r.shape,t.shape),a=wr(r,o),i=wr(t,o),u=k(r.dtype,t.dtype),s=N.zeros(o,u),c=s.data,l=s.size;if(I(u)){let m=c;for(let f=0;f<l;f++){let p=a.iget(f),y=i.iget(f),d=typeof p=="bigint"?p:BigInt(Math.round(p)),g=typeof y=="bigint"?y:BigInt(Math.round(y));n==="add"?m[f]=d+g:n==="subtract"?m[f]=d-g:n==="multiply"?m[f]=d*g:n==="divide"?m[f]=d/g:m[f]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let m=I(r.dtype)||I(t.dtype);for(let f=0;f<l;f++){let p=a.iget(f),y=i.iget(f),d=Number(p),g=Number(y);c[f]=e(d,g)}}return s}function K(r,t,e){let n=mr(r.shape,t.shape),o=wr(r,n),a=wr(t,n),i=n.reduce((c,l)=>c*l,1),u=new Uint8Array(i),s=I(r.dtype)||I(t.dtype);for(let c=0;c<i;c++){let l=o.iget(c),m=a.iget(c),f=Number(l),p=Number(m);u[c]=e(f,p)?1:0}return N.fromData(u,n,"bool")}function C(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,u=e?n:n!=="float32"&&n!=="float64"?"float64":n,s=N.zeros(o,u),c=s.data,l=r.data;if(I(n))if(I(u)){let m=c;for(let f=0;f<a;f++){let p=Number(l[f]);m[f]=BigInt(Math.round(t(p)))}}else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));return s}function Jr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function ce(r,t){return typeof t=="number"?Fu(r,t):Jr(r,t)?Cu(r,t):F(r,t,(e,n)=>e+n,"add")}function Cu(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;if(!I(r.dtype)||!I(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m+f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]+m[f]}}else if(I(r.dtype)||I(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];u[c]=l+m}else for(let c=0;c<o;c++)u[c]=a[c]+i[c];return n}function le(r,t){return typeof t=="number"?Pu(r,t):Jr(r,t)?Vu(r,t):F(r,t,(e,n)=>e-n,"subtract")}function Vu(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;if(!I(r.dtype)||!I(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m-f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]-m[f]}}else if(I(r.dtype)||I(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];u[c]=l-m}else for(let c=0;c<o;c++)u[c]=a[c]-i[c];return n}function fe(r,t){return typeof t=="number"?ju(r,t):Jr(r,t)?qu(r,t):F(r,t,(e,n)=>e*n,"multiply")}function qu(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;if(!I(r.dtype)||!I(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m*f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]*m[f]}}else if(I(r.dtype)||I(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];u[c]=l*m}else for(let c=0;c<o;c++)u[c]=a[c]*i[c];return n}function me(r,t){if(typeof t=="number")return Ru(r,t);let e=r.dtype==="float64",n=t.dtype==="float64",o=r.dtype==="float32",a=t.dtype==="float32";if(e||n){let s=e?r:ar(r,"float64"),c=n?t:ar(t,"float64");return F(s,c,(l,m)=>l/m,"divide")}if(o||a){let s=o?r:ar(r,"float32"),c=a?t:ar(t,"float32");return F(s,c,(l,m)=>l/m,"divide")}let i=ar(r,"float64"),u=ar(t,"float64");return F(i,u,(s,c)=>s/c,"divide")}function ar(r,t){let e=N.zeros(Array.from(r.shape),t),n=r.size,o=r.data,a=e.data;for(let i=0;i<n;i++)a[i]=Number(o[i]);return e}function Fu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]+l}else for(let s=0;s<a;s++)u[s]=Number(o[s])+t;return i}function Pu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]-l}else for(let s=0;s<a;s++)u[s]=Number(o[s])-t;return i}function ju(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]*l}else for(let s=0;s<a;s++)u[s]=Number(o[s])*t;return i}function Ru(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e!=="float32"&&e!=="float64"?"float64":e,s=N.zeros(n,u),c=s.data;if(I(e))for(let l=0;l<a;l++)c[l]=Number(o[l])/t;else for(let l=0;l<a;l++)c[l]=Number(o[l])/t;return s}function pe(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=N.zeros(e,t),i=a.data;if(I(t)){let u=n,s=i;for(let c=0;c<o;c++){let l=u[c];s[c]=l<0n?-l:l}}else for(let u=0;u<o;u++)i[u]=Math.abs(Number(n[u]));return a}function ye(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=N.zeros(e,t),i=a.data;if(I(t)){let u=n,s=i;for(let c=0;c<o;c++)s[c]=-u[c]}else for(let u=0;u<o;u++)i[u]=-Number(n[u]);return a}function de(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=N.zeros(e,t),i=a.data;if(I(t)){let u=n,s=i;for(let c=0;c<o;c++){let l=u[c];s[c]=l>0n?1n:l<0n?-1n:0n}}else for(let u=0;u<o;u++){let s=Number(n[u]);i[u]=s>0?1:s<0?-1:0}return a}function Ir(r,t){return typeof t=="number"?Lu(r,t):F(r,t,(e,n)=>(e%n+n)%n,"mod")}function Lu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++){let f=s[m];c[m]=(f%l+l)%l}}else for(let s=0;s<a;s++){let c=Number(o[s]);u[s]=(c%t+t)%t}return i}function Qr(r,t){return typeof t=="number"?Zu(r,t):F(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function Zu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]/l}else for(let s=0;s<a;s++)u[s]=Math.floor(Number(o[s])/t);return i}function ge(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=N.zeros(e,t),i=a.data;for(let u=0;u<o;u++)i[u]=n[u];return a}function he(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,i=t!=="float32"&&t!=="float64"?"float64":t,u=N.zeros(e,i),s=u.data;if(I(t))for(let c=0;c<o;c++)s[c]=1/Number(n[c]);else for(let c=0;c<o;c++)s[c]=1/Number(n[c]);return u}function Ae(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,i=t!=="float32"&&t!=="float64"?"float64":t,u=N.zeros(e,i),s=u.data;for(let c=0;c<o;c++)s[c]=Math.cbrt(Number(n[c]));return u}function be(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=N.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.abs(Number(n[s]));return i}function Se(r,t){let e=Qr(r,t),n=Ir(r,t);return[e,n]}function Ne(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=N.zeros(e,t),i=a.data;if(I(t)){let u=n,s=i;for(let c=0;c<o;c++)s[c]=u[c]*u[c]}else for(let u=0;u<o;u++){let s=Number(n[u]);i[u]=s*s}return a}function De(r,t){return Ir(r,t)}function xe(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=N.zeros(n,a),u=i.data;if(typeof t=="number")for(let s=0;s<o;s++){let c=Number(r.data[s]);c<0?u[s]=0:c===0?u[s]=t:u[s]=1}else{let s=t.data,c=t.shape;if(n.every((l,m)=>l===c[m]))for(let l=0;l<o;l++){let m=Number(r.data[l]);m<0?u[l]=0:m===0?u[l]=Number(s[l]):u[l]=1}else for(let l=0;l<o;l++){let m=Number(r.data[l]),f=l%t.size;m<0?u[l]=0:m===0?u[l]=Number(s[f]):u[l]=1}}return i}function rr(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);let t=Math.max(...r.map(n=>n.length)),e=new Array(t);for(let n=0;n<t;n++){let o=1;for(let a of r){let i=a.length-t+n,u=i<0?1:a[i];if(u!==1){if(o===1)o=u;else if(o!==u)return null}}e[n]=o}return e}function Gu(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let i=0;i<n;i++){let u=o-n+i,s=r[i],c=e[u];if(s===c)a[u]=t[i];else if(s===1)a[u]=0;else throw new Error("Invalid broadcast")}return a}function Y(r,t){let e=Gu(r.shape,r.strides,t);return N.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function Xr(...r){let t=rr(r);if(t===null){let e=r.map(n=>`(${n.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return t}function we(r,t){return typeof t=="number"?Hu(r,t):K(r,t,(e,n)=>e>n)}function Ie(r,t){return typeof t=="number"?Yu(r,t):K(r,t,(e,n)=>e>=n)}function ze(r,t){return typeof t=="number"?Ju(r,t):K(r,t,(e,n)=>e<n)}function _e(r,t){return typeof t=="number"?Qu(r,t):K(r,t,(e,n)=>e<=n)}function Be(r,t){return typeof t=="number"?Xu(r,t):K(r,t,(e,n)=>e===n)}function Ee(r,t){return typeof t=="number"?Ku(r,t):K(r,t,(e,n)=>e!==n)}function Kr(r,t,e=1e-5,n=1e-8){return typeof t=="number"?rc(r,t,e,n):K(r,t,(o,a)=>{let i=Math.abs(o-a),u=n+e*Math.abs(a);return i<=u})}function ve(r,t,e=1e-5,n=1e-8){let o=Kr(r,t,e,n),a=o.data;for(let i=0;i<o.size;i++)if(a[i]===0)return!1;return!0}function Oe(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=rr(e);if(n===null)return!1;let o=Y(r,n),a=Y(t,n),i=n.length,u=n.reduce((l,m)=>l*m,1),s=I(o.dtype),c=I(a.dtype);for(let l=0;l<u;l++){let m=l,f=new Array(i);for(let d=i-1;d>=0;d--)f[d]=m%n[d],m=Math.floor(m/n[d]);let p=o.get(...f),y=a.get(...f);if(s||c){let d=typeof p=="bigint"?p:BigInt(Number(p)),g=typeof y=="bigint"?y:BigInt(Number(y));if(d!==g)return!1}else if(p!==y)return!1}return!0}function Hu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]>t?1:0;return N.fromData(e,Array.from(r.shape),"bool")}function Yu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]>=t?1:0;return N.fromData(e,Array.from(r.shape),"bool")}function Ju(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]<t?1:0;return N.fromData(e,Array.from(r.shape),"bool")}function Qu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]<=t?1:0;return N.fromData(e,Array.from(r.shape),"bool")}function Xu(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(I(o)){let a=BigInt(Math.round(t)),i=n;for(let u=0;u<r.size;u++)e[u]=i[u]===a?1:0}else for(let a=0;a<r.size;a++)e[a]=n[a]===t?1:0;return N.fromData(e,Array.from(r.shape),"bool")}function Ku(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]!==t?1:0;return N.fromData(e,Array.from(r.shape),"bool")}function rc(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,i=r.dtype;if(I(i)){let u=a;for(let s=0;s<r.size;s++){let c=Number(u[s]),l=Math.abs(c-t),m=n+e*Math.abs(t);o[s]=l<=m?1:0}}else for(let u=0;u<r.size;u++){let s=Number(a[u]),c=Math.abs(s-t),l=n+e*Math.abs(t);o[u]=c<=l?1:0}return N.fromData(o,Array.from(r.shape),"bool")}function O(r,t){let e=0,n=1;for(let o=r.length-1;o>=0;o--)e+=r[o]*n,n*=t[o];return e}function U(r,t,e,n){let o=n.length,a=new Array(o),i=Array.from(n).filter((s,c)=>c!==t),u=r;for(let s=i.length-1;s>=0;s--)a[s>=t?s+1:s]=u%i[s],u=Math.floor(u/i[s]);return a[t]=e,a}function pr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0)if(I(n)){let y=u,d=BigInt(0);for(let g=0;g<i;g++)d+=y[g];return Number(d)}else{let y=0;for(let d=0;d<i;d++)y+=Number(u[d]);return y}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return pr(r);let l=N.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(I(n)){let y=u,d=m;for(let g=0;g<p;g++){let b=BigInt(0);for(let A=0;A<f;A++){let h=U(g,s,A,o),S=O(h,o);b+=y[S]}d[g]=b}}else for(let y=0;y<p;y++){let d=0;for(let g=0;g<f;g++){let b=U(y,s,g,o),A=O(b,o);d+=Number(u[A])}m[y]=d}if(e){let y=[...o];return y[s]=1,N.fromData(m,y,n)}return l}function zr(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return pr(r)/r.size;let a=t;if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error(`axis ${t} is out of bounds for array of dimension ${o.length}`);let i=pr(r,t,e);if(typeof i=="number")return i/o[a];let u=o[a],s=n;(I(n)||n.startsWith("int")||n.startsWith("uint"))&&(s="float64");let c=N.zeros(Array.from(i.shape),s),l=c.data,m=i.data;if(I(n)){let f=m;for(let p=0;p<l.length;p++)l[p]=Number(f[p])/u}else for(let f=0;f<l.length;f++)l[f]=Number(m[f])/u;return c}function _r(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0){if(i===0)throw new Error("max of empty array");let y=u[0];for(let d=1;d<i;d++)u[d]>y&&(y=u[d]);return Number(y)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return _r(r);let l=N.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(I(n)){let y=u,d=m;for(let g=0;g<p;g++){let b=U(g,s,0,o),A=O(b,o),h=y[A];for(let S=1;S<f;S++){let D=U(g,s,S,o),x=O(D,o),w=y[x];w>h&&(h=w)}d[g]=h}}else for(let y=0;y<p;y++){let d=-1/0;for(let g=0;g<f;g++){let b=U(y,s,g,o),A=O(b,o),h=Number(u[A]);h>d&&(d=h)}m[y]=d}if(e){let y=[...o];return y[s]=1,N.fromData(m,y,n)}return l}function rt(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0)if(I(n)){let y=u,d=BigInt(1);for(let g=0;g<i;g++)d*=y[g];return Number(d)}else{let y=1;for(let d=0;d<i;d++)y*=Number(u[d]);return y}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return rt(r);let l=N.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(I(n)){let y=u,d=m;for(let g=0;g<p;g++){let b=BigInt(1);for(let A=0;A<f;A++){let h=U(g,s,A,o),S=O(h,o);b*=y[S]}d[g]=b}}else for(let y=0;y<p;y++){let d=1;for(let g=0;g<f;g++){let b=U(y,s,g,o),A=O(b,o);d*=Number(u[A])}m[y]=d}if(e){let y=[...o];return y[s]=1,N.fromData(m,y,n)}return l}function Br(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0){if(i===0)throw new Error("min of empty array");let y=u[0];for(let d=1;d<i;d++)u[d]<y&&(y=u[d]);return Number(y)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return Br(r);let l=N.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(I(n)){let y=u,d=m;for(let g=0;g<p;g++){let b=U(g,s,0,o),A=O(b,o),h=y[A];for(let S=1;S<f;S++){let D=U(g,s,S,o),x=O(D,o),w=y[x];w<h&&(h=w)}d[g]=h}}else for(let y=0;y<p;y++){let d=1/0;for(let g=0;g<f;g++){let b=U(y,s,g,o),A=O(b,o),h=Number(u[A]);h<d&&(d=h)}m[y]=d}if(e){let y=[...o];return y[s]=1,N.fromData(m,y,n)}return l}function tt(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let p=i[0],y=0;for(let d=1;d<a;d++)i[d]<p&&(p=i[d],y=d);return y}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return tt(r);let c=N.zeros(s,"int32"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);if(I(e)){let p=i;for(let y=0;y<f;y++){let d=U(y,u,0,n),g=O(d,n),b=p[g],A=0;for(let h=1;h<m;h++){let S=U(y,u,h,n),D=O(S,n),x=p[D];x<b&&(b=x,A=h)}l[y]=A}}else for(let p=0;p<f;p++){let y=1/0,d=0;for(let g=0;g<m;g++){let b=U(p,u,g,n),A=O(b,n),h=Number(i[A]);h<y&&(y=h,d=g)}l[p]=d}return c}function et(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmax of empty array");let p=i[0],y=0;for(let d=1;d<a;d++)i[d]>p&&(p=i[d],y=d);return y}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return et(r);let c=N.zeros(s,"int32"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);if(I(e)){let p=i;for(let y=0;y<f;y++){let d=U(y,u,0,n),g=O(d,n),b=p[g],A=0;for(let h=1;h<m;h++){let S=U(y,u,h,n),D=O(S,n),x=p[D];x>b&&(b=x,A=h)}l[y]=A}}else for(let p=0;p<f;p++){let y=-1/0,d=0;for(let g=0;g<m;g++){let b=U(p,u,g,n),A=O(b,n),h=Number(i[A]);h>y&&(y=h,d=g)}l[p]=d}return c}function nt(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.size,u=r.data,s=zr(r,t,n);if(t===void 0){let b=s,A=0;for(let h=0;h<i;h++){let S=Number(u[h])-b;A+=S*S}return A/(i-e)}let c=t;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let l=o[c],m=s,f=m.data,p=n?m.shape:Array.from(o).filter((b,A)=>A!==c),y=N.zeros(Array.from(p),"float64"),d=y.data,g=p.reduce((b,A)=>b*A,1);for(let b=0;b<g;b++){let A=0,h=Number(f[b]);for(let S=0;S<l;S++){let D=U(b,c,S,o),x=O(D,o),w=Number(u[x])-h;A+=w*w}d[b]=A/(l-e)}return y}function Ue(r,t,e=0,n=!1){let o=nt(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=N.zeros(Array.from(o.shape),"float64"),i=o.data,u=a.data;for(let s=0;s<i.length;s++)u[s]=Math.sqrt(Number(i[s]));return a}function ot(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(!i[p])return!1;return!0}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return ot(r);let c=N.zeros(s,"bool"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);for(let p=0;p<f;p++){let y=!0;for(let d=0;d<m;d++){let g=U(p,u,d,n),b=O(g,n);if(!i[b]){y=!1;break}}l[p]=y?1:0}if(e){let p=[...n];return p[u]=1,N.fromData(l,p,"bool")}return c}function at(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(i[p])return!0;return!1}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return at(r);let c=N.zeros(s,"bool"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);for(let p=0;p<f;p++){let y=!1;for(let d=0;d<m;d++){let g=U(p,u,d,n),b=O(g,n);if(i[b]){y=!0;break}}l[p]=y?1:0}if(e){let p=[...n];return p[u]=1,N.fromData(l,p,"bool")}return c}function st(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=0;for(let d=0;d<f;d++)y+=Number(o[d]),p[d]=y;return N.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++)Math.floor(f/m)%u===0?i[f]=Number(o[f]):i[f]=i[f-m]+Number(o[f]);return N.fromData(i,[...e],"float64")}function it(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=1;for(let d=0;d<f;d++)y*=Number(o[d]),p[d]=y;return N.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++)Math.floor(f/m)%u===0?i[f]=Number(o[f]):i[f]=i[f-m]*Number(o[f]);return N.fromData(i,[...e],"float64")}function ut(r,t,e=!1){let n=_r(r,t,e),o=Br(r,t,e);if(typeof n=="number"&&typeof o=="number")return n-o;let a=n,i=o,u=a.data,s=i.data,c=new Float64Array(a.size);for(let l=0;l<a.size;l++)c[l]=Number(u[l])-Number(s[l]);return N.fromData(c,[...a.shape],"float64")}function ct(r,t,e=!1){return sr(r,.5,t,e)}function lt(r,t,e,n=!1){return sr(r,t/100,e,n)}function sr(r,t,e,n=!1){if(t<0||t>1)throw new Error("Quantile must be between 0 and 1");let o=r.shape,a=o.length,i=r.data;if(e===void 0){let p=[];for(let h=0;h<r.size;h++)p.push(Number(i[h]));p.sort((h,S)=>h-S);let y=p.length,d=t*(y-1),g=Math.floor(d),b=Math.ceil(d);if(g===b)return p[g];let A=d-g;return p[g]*(1-A)+p[b]*A}let u=e;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let s=Array.from(o).filter((p,y)=>y!==u);if(s.length===0)return sr(r,t);let c=s.reduce((p,y)=>p*y,1),l=o[u],m=new Float64Array(c);for(let p=0;p<c;p++){let y=[];for(let h=0;h<l;h++){let S=U(p,u,h,o),D=O(S,o);y.push(Number(i[D]))}y.sort((h,S)=>h-S);let d=y.length,g=t*(d-1),b=Math.floor(g),A=Math.ceil(g);if(b===A)m[p]=y[b];else{let h=g-b;m[p]=y[b]*(1-h)+y[A]*h}}let f=N.fromData(m,s,"float64");if(n){let p=[...o];return p[u]=1,N.fromData(m,p,"float64")}return f}function Er(r,t,e,n=!1){let o=r.shape,a=o.length,i=r.data;if(e===void 0)return zr(r,t,n);if(t===void 0){let y=0,d=0,g=e.data;for(let b=0;b<r.size;b++){let A=Number(g[b%e.size]);y+=Number(i[b])*A,d+=A}return d===0?NaN:y/d}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let s=Array.from(o).filter((y,d)=>d!==u);if(s.length===0)return Er(r,void 0,e);let c=s.reduce((y,d)=>y*d,1),l=o[u],m=e.data,f=new Float64Array(c);for(let y=0;y<c;y++){let d=0,g=0;for(let b=0;b<l;b++){let A=U(y,u,b,o),h=O(A,o),S=Number(m[b%e.size]);d+=Number(i[h])*S,g+=S}f[y]=g===0?NaN:d/g}let p=N.fromData(f,s,"float64");if(n){let y=[...o];return y[u]=1,N.fromData(f,y,"float64")}return p}function vr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=0;for(let p=0;p<r.size;p++){let y=Number(a[p]);isNaN(y)||(f+=y)}return f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return vr(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=0;for(let y=0;y<c;y++){let d=U(f,i,y,n),g=O(d,n),b=Number(a[g]);isNaN(b)||(p+=b)}l[f]=p}let m=N.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,N.fromData(l,f,"float64")}return m}function Or(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=1;for(let p=0;p<r.size;p++){let y=Number(a[p]);isNaN(y)||(f*=y)}return f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return Or(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=1;for(let y=0;y<c;y++){let d=U(f,i,y,n),g=O(d,n),b=Number(a[g]);isNaN(b)||(p*=b)}l[f]=p}let m=N.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,N.fromData(l,f,"float64")}return m}function Ur(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=0,p=0;for(let y=0;y<r.size;y++){let d=Number(a[y]);isNaN(d)||(f+=d,p++)}return p===0?NaN:f/p}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return Ur(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=0,y=0;for(let d=0;d<c;d++){let g=U(f,i,d,n),b=O(g,n),A=Number(a[b]);isNaN(A)||(p+=A,y++)}l[f]=y===0?NaN:p/y}let m=N.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,N.fromData(l,f,"float64")}return m}function yr(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.data;if(t===void 0){let p=0,y=0;for(let b=0;b<r.size;b++){let A=Number(i[b]);isNaN(A)||(p+=A,y++)}if(y-e<=0)return NaN;let d=p/y,g=0;for(let b=0;b<r.size;b++){let A=Number(i[b]);isNaN(A)||(g+=(A-d)**2)}return g/(y-e)}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let s=Array.from(o).filter((p,y)=>y!==u);if(s.length===0)return yr(r,void 0,e);let c=s.reduce((p,y)=>p*y,1),l=o[u],m=new Float64Array(c);for(let p=0;p<c;p++){let y=0,d=0;for(let A=0;A<l;A++){let h=U(p,u,A,o),S=O(h,o),D=Number(i[S]);isNaN(D)||(y+=D,d++)}if(d-e<=0){m[p]=NaN;continue}let g=y/d,b=0;for(let A=0;A<l;A++){let h=U(p,u,A,o),S=O(h,o),D=Number(i[S]);isNaN(D)||(b+=(D-g)**2)}m[p]=b/(d-e)}let f=N.fromData(m,s,"float64");if(n){let p=[...o];return p[u]=1,N.fromData(m,p,"float64")}return f}function ft(r,t,e=0,n=!1){let o=yr(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,i=new Float64Array(a.size);for(let u=0;u<a.size;u++)i[u]=Math.sqrt(Number(a.data[u]));return N.fromData(i,[...a.shape],"float64")}function Tr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=1/0;for(let p=0;p<r.size;p++){let y=Number(a[p]);!isNaN(y)&&y<f&&(f=y)}return f===1/0?NaN:f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return Tr(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=1/0;for(let y=0;y<c;y++){let d=U(f,i,y,n),g=O(d,n),b=Number(a[g]);!isNaN(b)&&b<p&&(p=b)}l[f]=p===1/0?NaN:p}let m=N.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,N.fromData(l,f,"float64")}return m}function $r(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=-1/0;for(let p=0;p<r.size;p++){let y=Number(a[p]);!isNaN(y)&&y>f&&(f=y)}return f===-1/0?NaN:f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return $r(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=-1/0;for(let y=0;y<c;y++){let d=U(f,i,y,n),g=O(d,n),b=Number(a[g]);!isNaN(b)&&b>p&&(p=b)}l[f]=p===-1/0?NaN:p}let m=N.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,N.fromData(l,f,"float64")}return m}function Mr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=1/0,m=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p<l&&(l=p,m=f)}return m}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,m)=>m!==a);if(i.length===0)return Mr(r);let u=i.reduce((l,m)=>l*m,1),s=e[a],c=new Int32Array(u);for(let l=0;l<u;l++){let m=1/0,f=0;for(let p=0;p<s;p++){let y=U(l,a,p,e),d=O(y,e),g=Number(o[d]);!isNaN(g)&&g<m&&(m=g,f=p)}c[l]=f}return N.fromData(c,i,"int32")}function kr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=-1/0,m=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p>l&&(l=p,m=f)}return m}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,m)=>m!==a);if(i.length===0)return kr(r);let u=i.reduce((l,m)=>l*m,1),s=e[a],c=new Int32Array(u);for(let l=0;l<u;l++){let m=-1/0,f=0;for(let p=0;p<s;p++){let y=U(l,a,p,e),d=O(y,e),g=Number(o[d]);!isNaN(g)&&g>m&&(m=g,f=p)}c[l]=f}return N.fromData(c,i,"int32")}function mt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=0;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(y+=g),p[d]=y}return N.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/m)%u===0?i[f]=isNaN(p)?0:p:i[f]=i[f-m]+(isNaN(p)?0:p)}return N.fromData(i,[...e],"float64")}function pt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=1;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(y*=g),p[d]=y}return N.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/m)%u===0?i[f]=isNaN(p)?1:p:i[f]=i[f-m]*(isNaN(p)?1:p)}return N.fromData(i,[...e],"float64")}function Cr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=[];for(let d=0;d<r.size;d++){let g=Number(a[d]);isNaN(g)||f.push(g)}if(f.length===0)return NaN;f.sort((d,g)=>d-g);let p=f.length,y=Math.floor(p/2);return p%2===0?(f[y-1]+f[y])/2:f[y]}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return Cr(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=[];for(let g=0;g<c;g++){let b=U(f,i,g,n),A=O(b,n),h=Number(a[A]);isNaN(h)||p.push(h)}if(p.length===0){l[f]=NaN;continue}p.sort((g,b)=>g-b);let y=p.length,d=Math.floor(y/2);y%2===0?l[f]=(p[d-1]+p[d])/2:l[f]=p[d]}let m=N.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,N.fromData(l,f,"float64")}return m}function P(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((m,f,p)=>p===o?m:m*f,1),l=e/c;if(!Number.isInteger(l))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((m,f)=>f===o?l:m)}else a=t;if(a.reduce((c,l)=>c*l,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){let c=r.data;return N.fromData(c,a,n,L(a),0)}let s=r.copy().data;return N.fromData(s,a,n,L(a),0)}function Vr(r){let t=r.size,e=r.dtype,n=T(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let u=r.data.slice(r.offset,r.offset+t);return N.fromData(u,[t],e,[1],0)}let o=new n(t),a=I(e);for(let i=0;i<t;i++){let u=r.iget(i);o[i]=u}return N.fromData(o,[t],e,[1],0)}function ir(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return N.fromData(n,[t],e,[1],0)}return Vr(r)}function gr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype,u;if(t===void 0)u=Array.from({length:n},(m,f)=>n-1-f);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let m=new Set;for(let f of t){let p=f<0?n+f:f;if(p<0||p>=n)throw new Error(`axis ${f} is out of bounds for array of dimension ${n}`);if(m.has(p))throw new Error("repeated axis in transpose");m.add(p)}u=t.map(f=>f<0?n+f:f)}let s=u.map(m=>e[m]),c=Array.from(o),l=u.map(m=>c[m]);return N.fromData(a,s,i,l,r.offset)}function Te(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype;if(t===void 0){let u=[],s=[];for(let c=0;c<n;c++)e[c]!==1&&(u.push(e[c]),s.push(o[c]));return u.length===0&&(u.push(1),s.push(1)),N.fromData(a,u,i,s,r.offset)}else{let u=t<0?n+t:t;if(u<0||u>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[u]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[u]})`);let s=[],c=[];for(let l=0;l<n;l++)l!==u&&(s.push(e[l]),c.push(o[l]));return N.fromData(a,s,i,c,r.offset)}}function dr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype,u=t;if(u<0&&(u=n+t+1),u<0||u>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let s=[...Array.from(e)];s.splice(u,0,1);let c=[...Array.from(o)],l=u<n?o[u]*(e[u]||1):1;return c.splice(u,0,l),N.fromData(a,s,i,c,r.offset)}function $e(r,t,e){let n=r.shape,o=n.length,a=r.strides,i=r.data,u=r.dtype,s=t<0?o+t:t,c=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${o}`);if(c<0||c>=o)throw new Error(`axis2 ${e} is out of bounds for array of dimension ${o}`);if(s===c)return N.fromData(i,Array.from(n),u,Array.from(a),r.offset);let l=Array.from(n),m=Array.from(a);return[l[s],l[c]]=[l[c],l[s]],[m[s],m[c]]=[m[c],m[s]],N.fromData(i,l,u,m,r.offset)}function yt(r,t,e){let n=r.ndim,o=Array.isArray(t)?t:[t],a=Array.isArray(e)?e:[e];if(o.length!==a.length)throw new Error("source and destination must have the same number of elements");let i=o.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`source axis ${c} is out of bounds for array of dimension ${n}`);return l}),u=a.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`destination axis ${c} is out of bounds for array of dimension ${n}`);return l});if(new Set(i).size!==i.length)throw new Error("repeated axis in source");if(new Set(u).size!==u.length)throw new Error("repeated axis in destination");let s=[];for(let c=0;c<n;c++)i.includes(c)||s.push(c);for(let c=0;c<i.length;c++){let l=u[c];s.splice(l,0,i[c])}return gr(r,s)}function er(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();let e=r[0],n=e.ndim,o=e.dtype,a=t<0?n+t:t;if(a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);for(let p=1;p<r.length;p++){let y=r[p];if(y.ndim!==n)throw new Error("all the input arrays must have same number of dimensions");for(let d=0;d<n;d++)if(d!==a&&y.shape[d]!==e.shape[d])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}let i=Array.from(e.shape),u=e.shape[a];for(let p=1;p<r.length;p++)u+=r[p].shape[a];i[a]=u;let s=i.reduce((p,y)=>p*y,1),c=T(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(s),m=L(i),f=0;for(let p of r){let y=p.shape[a];nc(p,l,i,m,a,f,o),f+=y}return N.fromData(l,i,o)}function nc(r,t,e,n,o,a,i){let u=r.shape,s=u.length,c=r.size,l=i==="int64"||i==="uint64";if(o===0&&r.isCContiguous&&s>0){let p=a*n[0],y=r.data,d=r.offset,g=d+c;t.set(y.subarray(d,g),p);return}if(o===1&&s===2&&r.isCContiguous){let p=u[0],y=u[1],d=e[1],g=r.data,b=r.offset;for(let A=0;A<p;A++){let h=b+A*y,S=A*d+a;t.set(g.subarray(h,h+y),S)}return}let m=new Array(s).fill(0),f=a*n[o];for(let p=0;p<c;p++){let y=r.iget(p),d=f;for(let g=0;g<s;g++)d+=m[g]*n[g];t[d]=y;for(let g=s-1;g>=0&&(m[g]++,!(m[g]<u[g]));g--)m[g]=0}}function Me(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let u=1;u<r.length;u++){let s=r[u];if(s.ndim!==o)throw new Error("all input arrays must have the same shape");for(let c=0;c<o;c++)if(s.shape[c]!==n[c])throw new Error("all input arrays must have the same shape")}let i=r.map(u=>dr(u,a));return er(i,a)}function ke(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?P(e,[1,e.shape[0]]):e);return er(t,0)}function dt(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?er(r,0):er(r,1)}function Ce(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?P(dr(P(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?dr(e,2):e);return er(t,2)}function Ve(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[a],u;if(typeof t=="number"){if(i%t!==0)throw new Error("array split does not result in an equal division");let s=i/t;u=[];for(let c=1;c<t;c++)u.push(c*s)}else u=t;return qe(r,u,a)}function hr(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[a],u;if(typeof t=="number"){let s=t,c=Math.floor(i/s),l=i%s;u=[];let m=0;for(let f=0;f<s-1;f++)m+=c+(f<l?1:0),u.push(m)}else u=t;return qe(r,u,a)}function qe(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],i=[];for(let u=0;u<a.length-1;u++){let s=a[u],c=a[u+1];if(s>c)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=c-s;let m=r.offset+s*r.strides[e];i.push(N.fromData(r.data,l,r.dtype,Array.from(r.strides),m))}return i}function Fe(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return hr(r,t,0)}function Pe(r,t){if(r.ndim<1)throw new Error("hsplit only works on arrays of 1 or more dimensions");let e=r.ndim===1?0:1;return hr(r,t,e)}function je(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],i=Math.max(n,a.length),u=new Array(i).fill(1),s=new Array(i).fill(1);for(let A=0;A<n;A++)u[i-n+A]=e[A];for(let A=0;A<a.length;A++)s[i-a.length+A]=a[A];let c=u.map((A,h)=>A*s[h]),l=c.reduce((A,h)=>A*h,1),m=T(o);if(!m)throw new Error(`Cannot tile array with dtype ${o}`);let f=new m(l),p=L(c),y=r;n<i&&(y=P(r,u));let d=o==="int64"||o==="uint64",g=y.strides,b=new Array(i).fill(0);for(let A=0;A<l;A++){let h=y.offset;for(let x=0;x<i;x++){let w=b[x]%u[x];h+=w*g[x]}let S=y.data[h],D=0;for(let x=0;x<i;x++)D+=b[x]*p[x];f[D]=S;for(let x=i-1;x>=0&&(b[x]++,!(b[x]<c[x]));x--)b[x]=0}return N.fromData(f,c,o)}function Re(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let A=i,h=Array.isArray(t)?t:new Array(A).fill(t);if(h.length!==A)throw new Error(`operands could not be broadcast together with shape (${A},) (${h.length},)`);let S=h.reduce((_,B)=>_+B,0),D=T(a);if(!D)throw new Error(`Cannot repeat array with dtype ${a}`);let x=new D(S),w=0;for(let _=0;_<A;_++){let B=r.iget(_),E=h[_];for(let v=0;v<E;v++)x[w++]=B}return N.fromData(x,[S],a)}let u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u],c=Array.isArray(t)?t:new Array(s).fill(t);if(c.length!==s)throw new Error(`operands could not be broadcast together with shape (${s},) (${c.length},)`);let l=Array.from(n);l[u]=c.reduce((A,h)=>A+h,0);let m=l.reduce((A,h)=>A*h,1),f=T(a);if(!f)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new f(m),y=L(l),d=new Array(o).fill(0),g=a==="int64"||a==="uint64",b=[0];for(let A=0;A<s;A++)b.push(b[A]+c[A]);for(let A=0;A<i;A++){let h=r.iget(A),S=d[u],D=c[S],x=0;for(let B=0;B<o;B++)B!==u&&(x+=d[B]*y[B]);let w=y[u],_=b[S];for(let B=0;B<D;B++){let E=x+(_+B)*w;p[E]=h}for(let B=o-1;B>=0&&(d[B]++,!(d[B]<n[B]));B--)d[B]=0}return N.fromData(p,l,a)}function Le(r,t){let e=r.shape,n=e.length,o=r.dtype,a=r.size,i;if(t===void 0)i=new Set(Array.from({length:n},(f,p)=>p));else if(typeof t=="number"){let f=t<0?n+t:t;if(f<0||f>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);i=new Set([f])}else i=new Set(t.map(f=>{let p=f<0?n+f:f;if(p<0||p>=n)throw new Error(`axis ${f} is out of bounds for array of dimension ${n}`);return p}));let u=T(o);if(!u)throw new Error(`Cannot flip array with dtype ${o}`);let s=new u(a),c=I(o);if(n===1&&r.isCContiguous){let f=r.data,p=r.offset;for(let y=0;y<a;y++)s[y]=f[p+a-1-y];return N.fromData(s,[...e],o)}if(n===2&&r.isCContiguous){let f=e[0],p=e[1],y=r.data,d=r.offset;if(i.size===2){for(let g=0;g<a;g++)s[g]=y[d+a-1-g];return N.fromData(s,[...e],o)}if(i.size===1){if(i.has(0)){for(let g=0;g<f;g++){let b=d+(f-1-g)*p,A=g*p;for(let h=0;h<p;h++)s[A+h]=y[b+h]}return N.fromData(s,[...e],o)}else if(i.has(1)){for(let g=0;g<f;g++){let b=d+g*p,A=g*p;for(let h=0;h<p;h++)s[A+h]=y[b+p-1-h]}return N.fromData(s,[...e],o)}}}let l=new Array(n),m=new Array(n).fill(0);for(let f=0;f<a;f++){for(let d=0;d<n;d++)l[d]=i.has(d)?e[d]-1-m[d]:m[d];let p=r.offset;for(let d=0;d<n;d++)p+=l[d]*r.strides[d];let y=r.data[p];s[f]=y;for(let d=n-1;d>=0&&(m[d]++,!(m[d]<e[d]));d--)m[d]=0}return N.fromData(s,[...e],o)}function Ze(r,t=1,e=[0,1]){let n=r.shape,o=n.length,a=r.dtype;if(o<2)throw new Error("Input must be at least 2-D");let i=e[0]<0?o+e[0]:e[0],u=e[1]<0?o+e[1]:e[1];if(i<0||i>=o||u<0||u>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(i===u)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let s=T(a);if(!s)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[i],c[u]]=[c[u],c[i]]);let l=c.reduce((g,b)=>g*b,1),m=new s(l),f=L(c),p=I(a),y=new Array(o).fill(0),d=new Array(o);for(let g=0;g<r.size;g++){for(let D=0;D<o;D++)d[D]=y[D];let b,A;t===1?(b=n[u]-1-y[u],A=y[i]):t===2?(b=n[i]-1-y[i],A=n[u]-1-y[u],d[i]=b,d[u]=A):(b=y[u],A=n[i]-1-y[i]),t!==2&&(d[i]=b,d[u]=A);let h=0;for(let D=0;D<o;D++)h+=d[D]*f[D];let S=r.iget(g);m[h]=S;for(let D=o-1;D>=0&&(y[D]++,!(y[D]<n[D]));D--)y[D]=0}return N.fromData(m,c,a)}function We(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let y=Array.isArray(t)?t.reduce((h,S)=>h+S,0):t,d=Vr(r),g=T(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let b=new g(i),A=I(a);for(let h=0;h<i;h++){let S=((h-y)%i+i)%i,D=d.iget(S);b[h]=D}return N.fromData(b,[...n],a)}let u=Array.isArray(t)?t:[t],s=Array.isArray(e)?e:[e];if(u.length!==s.length)throw new Error("shift and axis must have the same length");let c=s.map(y=>{let d=y<0?o+y:y;if(d<0||d>=o)throw new Error(`axis ${y} is out of bounds for array of dimension ${o}`);return d}),l=T(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let m=new l(i),f=I(a),p=new Array(o).fill(0);for(let y=0;y<i;y++){let d=[...p];for(let A=0;A<c.length;A++){let h=c[A],S=n[h],D=u[A];d[h]=((d[h]-D)%S+S)%S}let g=r.offset;for(let A=0;A<o;A++)g+=d[A]*r.strides[A];let b=r.data[g];m[y]=b;for(let A=o-1;A>=0&&(p[A]++,!(p[A]<n[A]));A--)p[A]=0}return N.fromData(m,[...n],a)}function Ge(r,t,e=0){let n=r.ndim,o=t<0?n+t:t;if(o<0||o>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let a=e<0?n+e:e;if(a<0||a>n)throw new Error(`start ${e} is out of bounds`);return o<a&&a--,o===a?N.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):yt(r,o,a)}function He(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return hr(r,t,2)}function Ye(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?P(e,[e.shape[0],1]):e);return dt(t)}function Je(r,t){let e=r.dtype,n=t.reduce((s,c)=>s*c,1),o=r.size,a=T(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let i=new a(n),u=I(e);for(let s=0;s<n;s++){let c=s%o,l=r.iget(c);i[s]=l}return N.fromData(i,t,e)}function Qe(r){return r.map(t=>t.ndim===0?P(t,[1]):t)}function Xe(r){return r.map(t=>t.ndim===0?P(t,[1,1]):t.ndim===1?P(t,[1,t.shape[0]]):t)}function Ke(r){return r.map(t=>t.ndim===0?P(t,[1,1,1]):t.ndim===1?P(t,[1,t.shape[0],1]):t.ndim===2?P(t,[t.shape[0],t.shape[1],1]):t)}function oc(r,t,e,n,o,a,i,u,s,c,l,m,f,p){if(m===0)for(let b=0;b<n*o;b++)f[b]=0;else if(m!==1)for(let b=0;b<n*o;b++)f[b]=(f[b]??0)*m;let y=r==="row-major",d=t==="transpose",g=e==="transpose";if(y&&!d&&!g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[b*s+S]??0)*(c[S*l+A]??0);f[b*p+A]=(f[b*p+A]??0)+i*h}else if(y&&d&&!g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[S*s+b]??0)*(c[S*l+A]??0);f[b*p+A]=(f[b*p+A]??0)+i*h}else if(y&&!d&&g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[b*s+S]??0)*(c[A*l+S]??0);f[b*p+A]=(f[b*p+A]??0)+i*h}else if(y&&d&&g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[S*s+b]??0)*(c[A*l+S]??0);f[b*p+A]=(f[b*p+A]??0)+i*h}else if(!y&&!d&&!g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[S*s+b]??0)*(c[A*l+S]??0);f[A*p+b]=(f[A*p+b]??0)+i*h}else if(!y&&d&&!g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[b*s+S]??0)*(c[A*l+S]??0);f[A*p+b]=(f[A*p+b]??0)+i*h}else if(!y&&!d&&g)for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[S*s+b]??0)*(c[S*l+A]??0);f[A*p+b]=(f[A*p+b]??0)+i*h}else for(let b=0;b<n;b++)for(let A=0;A<o;A++){let h=0;for(let S=0;S<a;S++)h+=(u[b*s+S]??0)*(c[S*l+A]??0);f[A*p+b]=(f[A*p+b]??0)+i*h}}function ht(r,t){let e=r.ndim,n=t.ndim;if(e===0||n===0){let o=e===0?r.get():null,a=n===0?t.get():null;if(e===0&&n===0)return typeof o=="bigint"&&typeof a=="bigint"?o*a:Number(o)*Number(a);if(e===0){let i=k(r.dtype,t.dtype),u=N.zeros([...t.shape],i);for(let s=0;s<t.size;s++){let c=t.data[s+t.offset];typeof o=="bigint"&&typeof c=="bigint"?u.data[s]=o*c:u.data[s]=Number(o)*Number(c)}return u}else{let i=k(r.dtype,t.dtype),u=N.zeros([...r.shape],i);for(let s=0;s<r.size;s++){let c=r.data[s+r.offset];typeof c=="bigint"&&typeof a=="bigint"?u.data[s]=c*a:u.data[s]=Number(c)*Number(a)}return u}}if(e===1&&n===1){if(r.shape[0]!==t.shape[0])throw new Error(`dot: incompatible shapes (${r.shape[0]},) and (${t.shape[0]},)`);let o=r.shape[0],a=0;for(let i=0;i<o;i++){let u=r.get(i),s=t.get(i);typeof u=="bigint"&&typeof s=="bigint"?a=Number(a)+Number(u*s):a+=Number(u)*Number(s)}return a}if(e===2&&n===2)return G(r,t);if(e===2&&n===1){let[o,a]=r.shape,i=t.shape[0];if(a!==i)throw new Error(`dot: incompatible shapes (${o},${a}) and (${i},)`);let u=k(r.dtype,t.dtype),s=N.zeros([o],u);for(let c=0;c<o;c++){let l=0;for(let m=0;m<a;m++){let f=r.get(c,m),p=t.get(m);typeof f=="bigint"&&typeof p=="bigint"?l=Number(l)+Number(f*p):l+=Number(f)*Number(p)}s.set([c],l)}return s}if(e===1&&n===2){let o=r.shape[0],[a,i]=t.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${i})`);let u=k(r.dtype,t.dtype),s=N.zeros([i],u);for(let c=0;c<i;c++){let l=0;for(let m=0;m<o;m++){let f=r.get(m),p=t.get(m,c);typeof f=="bigint"&&typeof p=="bigint"?l=Number(l)+Number(f*p):l+=Number(f)*Number(p)}s.set([c],l)}return s}if(e>2&&n===1){let o=r.shape[e-1],a=t.shape[0];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and (${a},)`);let i=[...r.shape.slice(0,-1)],u=k(r.dtype,t.dtype),s=N.zeros(i,u),c=i.reduce((l,m)=>l*m,1);for(let l=0;l<c;l++){let m=0,f=l,p=[];for(let y=i.length-1;y>=0;y--)p[y]=f%i[y],f=Math.floor(f/i[y]);for(let y=0;y<o;y++){let d=[...p,y],g=r.get(...d),b=t.get(y);typeof g=="bigint"&&typeof b=="bigint"?m=Number(m)+Number(g*b):m+=Number(g)*Number(b)}s.set(p,m)}return s}if(e===1&&n>2){let o=r.shape[0],a=1,i=t.shape[a];if(o!==i)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(t.shape)}`);let u=[...t.shape.slice(0,a),...t.shape.slice(a+1)],s=k(r.dtype,t.dtype),c=N.zeros(u,s),l=u.reduce((m,f)=>m*f,1);for(let m=0;m<l;m++){let f=m,p=[];for(let b=u.length-1;b>=0;b--)p[b]=f%u[b],f=Math.floor(f/u[b]);let y=p.slice(0,a),d=p.slice(a),g=0;for(let b=0;b<o;b++){let A=r.get(b),h=[...y,b,...d],S=t.get(...h);typeof A=="bigint"&&typeof S=="bigint"?g=Number(g)+Number(A*S):g+=Number(A)*Number(S)}c.set(p,g)}return c}if(e>=2&&n>=2&&!(e===2&&n===2)){let o=r.shape[e-1],a=t.shape[n-2];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and ${JSON.stringify(t.shape)}`);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],u=k(r.dtype,t.dtype),s=N.zeros(i,u),c=r.shape.slice(0,-1).reduce((p,y)=>p*y,1),l=t.shape.slice(0,-2).reduce((p,y)=>p*y,1),m=t.shape[n-1],f=o;for(let p=0;p<c;p++)for(let y=0;y<l;y++)for(let d=0;d<m;d++){let g=0;for(let A=0;A<f;A++){let h=p*f+A,S=r.data[h+r.offset],D=y*f*m+A*m+d,x=t.data[D+t.offset];typeof S=="bigint"&&typeof x=="bigint"?g=Number(g)+Number(S*x):g+=Number(S)*Number(x)}let b=p*l*m+y*m+d;s.data[b]=g}return s}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function G(r,t){if(r.ndim!==2||t.ndim!==2)throw new Error("matmul requires 2D arrays");let[e=0,n=0]=r.shape,[o=0,a=0]=t.shape;if(n!==o)throw new Error(`matmul shape mismatch: (${e},${n}) @ (${o},${a})`);let i=k(r.dtype,t.dtype),u=i.startsWith("int")||i.startsWith("uint")||i==="bool"?"float64":i;if(u!=="float64")throw new Error(`matmul currently only supports float64, got ${u}`);let s=r.dtype==="float64"?r.data:Float64Array.from(Array.from(r.data).map(Number)),c=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number));r.offset>0&&(s=s.subarray(r.offset)),t.offset>0&&(c=c.subarray(t.offset));let[l=0,m=0]=r.strides,[f=0,p=0]=t.strides,y=m>l,d=p>f,g=y?"transpose":"no-transpose",b=d?"transpose":"no-transpose",A,h;y?A=m:A=l,d?h=p:h=f;let S=N.zeros([e,a],"float64");return oc("row-major",g,b,e,a,n,1,s,A,c,h,0,S.data,a),S}function nn(r){if(r.ndim!==2)throw new Error(`trace requires 2D array, got ${r.ndim}D`);let[t=0,e=0]=r.shape,n=Math.min(t,e),o=0;for(let a=0;a<n;a++){let i=r.get(a,a);typeof i=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+i:o=(typeof o=="bigint"?Number(o):o)+i}return o}function tn(r,t){return gr(r,t)}function on(r,t){let e=r.ndim,n=t.ndim,o=r.shape[e-1],a=t.shape[n-1];if(o!==a)throw new Error(`inner: incompatible shapes - last dimensions ${o} and ${a} don't match`);if(e===1&&n===1)return ht(r,t);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],u=k(r.dtype,t.dtype),s=N.zeros(i,u),c=e===1?1:r.shape.slice(0,-1).reduce((f,p)=>f*p,1),l=n===1?1:t.shape.slice(0,-1).reduce((f,p)=>f*p,1),m=o;for(let f=0;f<c;f++)for(let p=0;p<l;p++){let y=0;for(let g=0;g<m;g++){let b=e===1?g:f*m+g,A=n===1?g:p*m+g,h=r.data[b+r.offset],S=t.data[A+t.offset];typeof h=="bigint"&&typeof S=="bigint"?y=Number(y)+Number(h*S):y+=Number(h)*Number(S)}if(i.length===0)return y;let d=c===1?p:f*l+p;s.data[d]=y}return s}function At(r,t){let e=r.ndim===1?r:ir(r),n=t.ndim===1?t:ir(t),o=e.size,a=n.size,i=k(r.dtype,t.dtype),u=N.zeros([o,a],i);for(let s=0;s<o;s++)for(let c=0;c<a;c++){let l=e.get(s),m=n.get(c),f;typeof l=="bigint"&&typeof m=="bigint"?f=l*m:f=Number(l)*Number(m),u.set([s,c],f)}return u}function an(r,t,e){let n,o;if(typeof e=="number"){let f=e;if(f<0)throw new Error("tensordot: axes must be non-negative");if(f>r.ndim||f>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:f},(p,y)=>r.ndim-f+y),o=Array.from({length:f},(p,y)=>y)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let f=0;f<n.length;f++){let p=n[f],y=o[f];if(p<0||p>=r.ndim||y<0||y>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[p]!==t.shape[y])throw new Error(`tensordot: shape mismatch on axes ${p} and ${y}: ${r.shape[p]} != ${t.shape[y]}`)}let a=[],i=[];for(let f=0;f<r.ndim;f++)n.includes(f)||a.push(f);for(let f=0;f<t.ndim;f++)o.includes(f)||i.push(f);let u=[...a.map(f=>r.shape[f]),...i.map(f=>t.shape[f])];if(u.length===0){let f=0,p=n.map(y=>r.shape[y]).reduce((y,d)=>y*d,1);for(let y=0;y<p;y++){let d=y,g=new Array(n.length);for(let D=n.length-1;D>=0;D--){let x=n[D];g[D]=d%r.shape[x],d=Math.floor(d/r.shape[x])}let b=new Array(r.ndim),A=new Array(t.ndim);for(let D=0;D<n.length;D++)b[n[D]]=g[D];for(let D=0;D<o.length;D++)A[o[D]]=g[D];let h=r.get(...b),S=t.get(...A);typeof h=="bigint"&&typeof S=="bigint"?f=Number(f)+Number(h*S):f+=Number(h)*Number(S)}return f}let s=k(r.dtype,t.dtype),c=N.zeros(u,s),l=u.reduce((f,p)=>f*p,1),m=n.map(f=>r.shape[f]).reduce((f,p)=>f*p,1);for(let f=0;f<l;f++){let p=f,y=[];for(let A=u.length-1;A>=0;A--)y[A]=p%u[A],p=Math.floor(p/u[A]);let d=y.slice(0,a.length),g=y.slice(a.length),b=0;for(let A=0;A<m;A++){p=A;let h=[];for(let _=n.length-1;_>=0;_--){let B=n[_];h[_]=p%r.shape[B],p=Math.floor(p/r.shape[B])}let S=new Array(r.ndim),D=new Array(t.ndim);for(let _=0;_<a.length;_++)S[a[_]]=d[_];for(let _=0;_<i.length;_++)D[i[_]]=g[_];for(let _=0;_<n.length;_++)S[n[_]]=h[_],D[o[_]]=h[_];let x=r.get(...S),w=t.get(...D);typeof x=="bigint"&&typeof w=="bigint"?b=Number(b)+Number(x*w):b+=Number(x)*Number(w)}c.set(y,b)}return c}function sn(r,t=0,e=0,n=1){let o=r.shape,a=o.length;if(a<2)throw new Error("diagonal requires an array of at least two dimensions");let i=e<0?a+e:e,u=n<0?a+n:n;if(i<0||i>=a||u<0||u>=a)throw new Error("axis out of bounds");if(i===u)throw new Error("axis1 and axis2 cannot be the same");let s=o[i],c=o[u],l;t>=0?l=Math.max(0,Math.min(s,c-t)):l=Math.max(0,Math.min(s+t,c));let m=[];for(let d=0;d<a;d++)d!==i&&d!==u&&m.push(o[d]);m.push(l);let f=N.zeros(m,r.dtype),p=o.filter((d,g)=>g!==i&&g!==u),y=p.reduce((d,g)=>d*g,1);for(let d=0;d<y;d++){let g=d,b=[];for(let A=p.length-1;A>=0;A--)b.unshift(g%p[A]),g=Math.floor(g/p[A]);for(let A=0;A<l;A++){let h=new Array(a),S=0;for(let w=0;w<a;w++)w===i?h[w]=t>=0?A:A-t:w===u?h[w]=t>=0?A+t:A:h[w]=b[S++];let D=[...b,A],x=r.get(...h);f.set(D,x)}}return f}function un(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=ac(n)):(n=r.slice(0,e),o=r.slice(e+2));let a=n.split(",").map(d=>d.trim());if(a.length!==t.length)throw new Error(`einsum: expected ${a.length} operands, got ${t.length}`);let i=new Map;for(let d=0;d<t.length;d++){let g=a[d],b=t[d];if(g.length!==b.ndim)throw new Error(`einsum: operand ${d} has ${b.ndim} dimensions but subscript '${g}' has ${g.length} indices`);for(let A=0;A<g.length;A++){let h=g[A],S=b.shape[A];if(i.has(h)){if(i.get(h)!==S)throw new Error(`einsum: size mismatch for index '${h}': ${i.get(h)} vs ${S}`)}else i.set(h,S)}}for(let d of o)if(!i.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let u=new Set(o),s=new Set;for(let d of a)for(let g of d)s.add(g);let c=[];for(let d of s)u.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,g]=a,[b,A]=t;if(d.length===2&&g.length===2&&o.length===2&&b.ndim===2&&A.ndim===2){let[h,S]=[d[0],d[1]],[D,x]=[g[0],g[1]],[w,_]=[o[0],o[1]];if(h===w&&x===_&&S===D&&c.length===1&&c[0]===S||h===w&&x===_&&S===D&&c.length===1&&c[0]===S)return G(b,A);if(S===w&&x===_&&h===D&&c.length===1&&c[0]===h){let B=tn(b);return G(B,A)}if(h===w&&D===_&&S===x&&c.length===1&&c[0]===S){let B=tn(A);return G(b,B)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&b.ndim===1&&A.ndim===1)return gt(t,a,c,i);if(d&&g&&d.length===1&&g.length===1&&o.length===2&&o===d+g&&c.length===0&&b.ndim===1&&A.ndim===1)return At(b,A)}if(t.length===1&&a[0].length===2&&o.length===0){let d=a[0];if(d[0]===d[1]&&t[0].ndim===2)return gt(t,a,c,i)}let l=Array.from(o).map(d=>i.get(d));if(l.length===0)return gt(t,a,c,i);let m=t[0].dtype;for(let d=1;d<t.length;d++)m=k(m,t[d].dtype);let f=N.zeros(l,m),p=l.reduce((d,g)=>d*g,1),y=1;for(let d of c)y*=i.get(d);for(let d=0;d<p;d++){let g=sc(d,l),b=new Map;for(let h=0;h<o.length;h++)b.set(o[h],g[h]);let A=0;for(let h=0;h<y;h++){let S=h;for(let x=c.length-1;x>=0;x--){let w=c[x],_=i.get(w);b.set(w,S%_),S=Math.floor(S/_)}let D=1;for(let x=0;x<t.length;x++){let w=t[x],_=a[x],B=[];for(let v of _)B.push(b.get(v));let E=w.get(...B);D*=Number(E)}A+=D}f.set(g,A)}return f}function ac(r){let t=new Map,e=r.split(",");for(let o of e)for(let a of o.trim())t.set(a,(t.get(a)||0)+1);let n=[];for(let[o,a]of t)a===1&&n.push(o);return n.sort().join("")}function gt(r,t,e,n){let o=1;for(let i of e)o*=n.get(i);let a=0;for(let i=0;i<o;i++){let u=new Map,s=i;for(let l=e.length-1;l>=0;l--){let m=e[l],f=n.get(m);u.set(m,s%f),s=Math.floor(s/f)}let c=1;for(let l=0;l<r.length;l++){let m=r[l],f=t[l],p=[];for(let d of f)p.push(u.get(d));let y=m.get(...p);c*=Number(y)}a+=c}return a}function sc(r,t){let e=new Array(t.length),n=r;for(let o=t.length-1;o>=0;o--)e[o]=n%t[o],n=Math.floor(n/t[o]);return e}function cn(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,i=k(r.dtype,t.dtype),u=Math.max(o,a),s=new Array(u),c=new Array(u).fill(1),l=new Array(u).fill(1);for(let y=0;y<o;y++)c[u-o+y]=e[y];for(let y=0;y<a;y++)l[u-a+y]=n[y];for(let y=0;y<u;y++)s[y]=c[y]*l[y];let m=N.zeros(s,i),f=e.reduce((y,d)=>y*d,1),p=n.reduce((y,d)=>y*d,1);for(let y=0;y<f;y++){let d=y,g=new Array(o);for(let h=o-1;h>=0;h--)g[h]=d%e[h],d=Math.floor(d/e[h]);let b=new Array(u).fill(0);for(let h=0;h<o;h++)b[u-o+h]=g[h];let A=r.get(...g);for(let h=0;h<p;h++){let S=h,D=new Array(a);for(let E=a-1;E>=0;E--)D[E]=S%n[E],S=Math.floor(S/n[E]);let x=new Array(u).fill(0);for(let E=0;E<a;E++)x[u-a+E]=D[E];let w=t.get(...D),_=new Array(u);for(let E=0;E<u;E++)_[E]=b[E]*l[E]+x[E];let B=typeof A=="bigint"||typeof w=="bigint"?BigInt(Number(A))*BigInt(Number(w)):Number(A)*Number(w);m.set(_,B)}}return m}function ln(r,t,e=-1,n=-1,o=-1,a){a!==void 0&&(e=a,n=a,o=a);let i=(h,S)=>h<0?S+h:h,u=i(e,r.ndim),s=i(n,t.ndim);if(r.ndim===1&&t.ndim===1){let h=r.shape[0],S=t.shape[0];if(h===3&&S===3){let D=Number(r.get(0)),x=Number(r.get(1)),w=Number(r.get(2)),_=Number(t.get(0)),B=Number(t.get(1)),E=Number(t.get(2)),v=N.zeros([3],"float64");return v.set([0],x*E-w*B),v.set([1],w*_-D*E),v.set([2],D*B-x*_),v}else if(h===2&&S===2){let D=Number(r.get(0)),x=Number(r.get(1)),w=Number(t.get(0)),_=Number(t.get(1));return D*_-x*w}else if(h===2&&S===3||h===3&&S===2){let D=Number(r.get(0)),x=Number(r.get(1)),w=h===3?Number(r.get(2)):0,_=Number(t.get(0)),B=Number(t.get(1)),E=S===3?Number(t.get(2)):0,v=N.zeros([3],"float64");return v.set([0],x*E-w*B),v.set([1],w*_-D*E),v.set([2],D*B-x*_),v}else throw new Error(`cross: incompatible dimensions for cross product: ${h} and ${S}`)}let c=r.shape[u],l=t.shape[s];if(c!==2&&c!==3||l!==2&&l!==3)throw new Error(`cross: incompatible dimensions for cross product: ${c} and ${l}`);let m=c===2&&l===2?0:3,f=[...r.shape.slice(0,u),...r.shape.slice(u+1)],p=[...t.shape.slice(0,s),...t.shape.slice(s+1)];if(f.length!==p.length)throw new Error("cross: incompatible shapes for cross product");for(let h=0;h<f.length;h++)if(f[h]!==p[h])throw new Error("cross: incompatible shapes for cross product");let y=f,d=o<0?y.length+1+o:o,g;if(m===0?g=y:g=[...y.slice(0,d),m,...y.slice(d)],g.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");let b=N.zeros(g,"float64"),A=y.reduce((h,S)=>h*S,1);for(let h=0;h<A;h++){let S=h,D=[];for(let R=y.length-1;R>=0;R--)D[R]=S%y[R],S=Math.floor(S/y[R]);let x=[...D.slice(0,u),0,...D.slice(u)],w=[...D.slice(0,s),0,...D.slice(s)],_=R=>(x[u]=R,Number(r.get(...x))),B=R=>(w[s]=R,Number(t.get(...w))),E=_(0),v=_(1),$=c===3?_(2):0,M=B(0),V=B(1),W=l===3?B(2):0;if(m===0)b.set(D,E*V-v*M);else{let R=v*W-$*V,fr=$*M-E*W,zu=E*V-v*M,Hr=(_u,Bu)=>{let Eu=[...D.slice(0,d),_u,...D.slice(d)];b.set(Eu,Bu)};Hr(0,R),Hr(1,fr),Hr(2,zu)}}return b}function ur(r,t=2,e,n=!1){if(typeof t!="number")throw new Error("vector_norm: ord must be a number");if(e==null){let c=r.ndim===1?r:ir(r),l=c.size,m;if(t===1/0){m=0;for(let f=0;f<l;f++)m=Math.max(m,Math.abs(Number(c.get(f))))}else if(t===-1/0){m=1/0;for(let f=0;f<l;f++)m=Math.min(m,Math.abs(Number(c.get(f))))}else if(t===0){m=0;for(let f=0;f<l;f++)Number(c.get(f))!==0&&m++}else if(t===1){m=0;for(let f=0;f<l;f++)m+=Math.abs(Number(c.get(f)))}else if(t===2){m=0;for(let f=0;f<l;f++){let p=Number(c.get(f));m+=p*p}m=Math.sqrt(m)}else{m=0;for(let f=0;f<l;f++)m+=Math.pow(Math.abs(Number(c.get(f))),t);m=Math.pow(m,1/t)}if(n){let f=new Array(r.ndim).fill(1),p=N.zeros(f,"float64");return p.set(new Array(r.ndim).fill(0),m),p}return m}let o=e<0?r.ndim+e:e;if(o<0||o>=r.ndim)throw new Error(`vector_norm: axis ${e} out of bounds for array with ${r.ndim} dimensions`);let a=n?[...r.shape.slice(0,o),1,...r.shape.slice(o+1)]:[...r.shape.slice(0,o),...r.shape.slice(o+1)];if(a.length===0)return ur(r,t,null,!1);let i=N.zeros(a,"float64"),u=r.shape[o],s=a.reduce((c,l)=>c*l,1);for(let c=0;c<s;c++){let l=c,m=[];for(let y=a.length-1;y>=0;y--)m[y]=l%a[y],l=Math.floor(l/a[y]);let f=n?[...m.slice(0,o),0,...m.slice(o+1)]:[...m.slice(0,o),0,...m.slice(o)],p;if(t===1/0){p=0;for(let y=0;y<u;y++)f[o]=y,p=Math.max(p,Math.abs(Number(r.get(...f))))}else if(t===-1/0){p=1/0;for(let y=0;y<u;y++)f[o]=y,p=Math.min(p,Math.abs(Number(r.get(...f))))}else if(t===0){p=0;for(let y=0;y<u;y++)f[o]=y,Number(r.get(...f))!==0&&p++}else if(t===1){p=0;for(let y=0;y<u;y++)f[o]=y,p+=Math.abs(Number(r.get(...f)))}else if(t===2){p=0;for(let y=0;y<u;y++){f[o]=y;let d=Number(r.get(...f));p+=d*d}p=Math.sqrt(p)}else{p=0;for(let y=0;y<u;y++)f[o]=y,p+=Math.pow(Math.abs(Number(r.get(...f))),t);p=Math.pow(p,1/t)}i.set(m,p)}return i}function nr(r,t="fro",e=!1){if(r.ndim!==2)throw new Error(`matrix_norm: input must be 2D, got ${r.ndim}D`);let[n,o]=r.shape,a;if(t==="fro"){a=0;for(let i=0;i<n;i++)for(let u=0;u<o;u++){let s=Number(r.get(i,u));a+=s*s}a=Math.sqrt(a)}else if(t==="nuc"){let{s:i}=tr(r);a=0;for(let u=0;u<i.size;u++)a+=Number(i.get(u))}else if(t===1){a=0;for(let i=0;i<o;i++){let u=0;for(let s=0;s<n;s++)u+=Math.abs(Number(r.get(s,i)));a=Math.max(a,u)}}else if(t===-1){a=1/0;for(let i=0;i<o;i++){let u=0;for(let s=0;s<n;s++)u+=Math.abs(Number(r.get(s,i)));a=Math.min(a,u)}}else if(t===1/0){a=0;for(let i=0;i<n;i++){let u=0;for(let s=0;s<o;s++)u+=Math.abs(Number(r.get(i,s)));a=Math.max(a,u)}}else if(t===-1/0){a=1/0;for(let i=0;i<n;i++){let u=0;for(let s=0;s<o;s++)u+=Math.abs(Number(r.get(i,s)));a=Math.min(a,u)}}else if(t===2){let{s:i}=tr(r);a=Number(i.get(0))}else if(t===-2){let{s:i}=tr(r);a=Number(i.get(i.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${t}`);if(e){let i=N.zeros([1,1],"float64");return i.set([0,0],a),i}return a}function fn(r,t=null,e=null,n=!1){if(t===null)return e===null?ur(r,2,null,n):typeof e=="number"?ur(r,2,e,n):nr(r,"fro",n);if(Array.isArray(e)){if(e.length!==2)throw new Error("norm: axis must be a 2-tuple for matrix norms");let o=e[0]<0?r.ndim+e[0]:e[0],a=e[1]<0?r.ndim+e[1]:e[1];if(r.ndim!==2||o!==0&&o!==1||a!==0&&a!==1||o===a)throw new Error("norm: complex axis specification not yet supported");return nr(r,t,n)}if(r.ndim===2&&e===null&&(t==="fro"||t==="nuc"))return nr(r,t,n);if(typeof t!="number"&&t!==null)throw new Error(`norm: ord '${t}' not valid for vector norm`);return ur(r,t??2,e,n)}function bt(r,t="reduced"){if(r.ndim!==2)throw new Error(`qr: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape,o=Math.min(e,n),a=N.zeros([e,n],"float64");for(let p=0;p<e;p++)for(let y=0;y<n;y++)a.set([p,y],Number(r.get(p,y)));let i=[],u=[];for(let p=0;p<o;p++){let y=e-p,d=[];for(let D=p;D<e;D++)d.push(Number(a.get(D,p)));let g=0;for(let D=0;D<y;D++)g+=d[D]*d[D];if(g=Math.sqrt(g),g<1e-15){i.push(d),u.push(0);continue}let b=d[0]>=0?1:-1,A=d[0]+b*g,h=[1];for(let D=1;D<y;D++)h.push(d[D]/A);let S=b*A/g;u.push(S),i.push(h);for(let D=p;D<n;D++){let x=0;for(let w=0;w<y;w++)x+=h[w]*Number(a.get(p+w,D));for(let w=0;w<y;w++)a.set([p+w,D],Number(a.get(p+w,D))-S*h[w]*x)}}if(t==="raw"){let p=N.zeros([e,n],"float64");for(let d=0;d<e;d++)for(let g=0;g<n;g++)p.set([d,g],Number(a.get(d,g)));let y=N.zeros([o],"float64");for(let d=0;d<o;d++)y.set([d],u[d]);return{h:p,tau:y}}if(t==="r"){let p=N.zeros([o,n],"float64");for(let y=0;y<o;y++)for(let d=y;d<n;d++)p.set([y,d],Number(a.get(y,d)));return p}let s=t==="complete"?e:o,c=N.zeros([e,s],"float64");for(let p=0;p<Math.min(e,s);p++)c.set([p,p],1);for(let p=o-1;p>=0;p--){let y=i[p],d=u[p],g=e-p;for(let b=p;b<s;b++){let A=0;for(let h=0;h<g;h++)A+=y[h]*Number(c.get(p+h,b));for(let h=0;h<g;h++)c.set([p+h,b],Number(c.get(p+h,b))-d*y[h]*A)}}let l=N.zeros([e,s],"float64");for(let p=0;p<e;p++)for(let y=0;y<s;y++)l.set([p,y],Number(c.get(p,y)));let m=t==="complete"?e:o,f=N.zeros([m,n],"float64");for(let p=0;p<m;p++)for(let y=0;y<n;y++)y>=p&&f.set([p,y],Number(a.get(p,y)));return{q:l,r:f}}function mn(r,t=!1){if(r.ndim!==2)throw new Error(`cholesky: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`cholesky: matrix must be square, got ${e}x${n}`);let o=e,a=N.zeros([o,o],"float64");for(let i=0;i<o;i++)for(let u=0;u<=i;u++){let s=0;if(i===u){for(let l=0;l<u;l++)s+=Number(a.get(u,l))**2;let c=Number(r.get(u,u))-s;if(c<0)throw new Error("cholesky: matrix is not positive definite");a.set([u,u],Math.sqrt(c))}else{for(let l=0;l<u;l++)s+=Number(a.get(i,l))*Number(a.get(u,l));let c=Number(a.get(u,u));if(Math.abs(c)<1e-15)throw new Error("cholesky: matrix is not positive definite");a.set([i,u],(Number(r.get(i,u))-s)/c)}}if(t){let i=N.zeros([o,o],"float64");for(let u=0;u<o;u++)for(let s=u;s<o;s++)i.set([u,s],Number(a.get(s,u)));return i}return a}function tr(r){if(r.ndim!==2)throw new Error(`svd: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape,n=Math.min(t,e),o=N.zeros([e,e],"float64");for(let m=0;m<e;m++)for(let f=0;f<e;f++){let p=0;for(let y=0;y<t;y++)p+=Number(r.get(y,m))*Number(r.get(y,f));o.set([m,f],p)}let{values:a,vectors:i}=St(o),u=Array.from({length:e},(m,f)=>f);u.sort((m,f)=>a[f]-a[m]);let s=N.zeros([n],"float64");for(let m=0;m<n;m++){let f=a[u[m]];s.set([m],Math.sqrt(Math.max(0,f)))}let c=N.zeros([e,e],"float64");for(let m=0;m<e;m++)for(let f=0;f<e;f++)c.set([m,f],i[f][u[m]]);let l=N.zeros([t,t],"float64");for(let m=0;m<t;m++)for(let f=0;f<n;f++){let p=Number(s.get(f));if(p>1e-10){let y=0;for(let d=0;d<e;d++)y+=Number(r.get(m,d))*Number(c.get(f,d));l.set([m,f],y/p)}}if(t>n)for(let m=n;m<t;m++){let f=new Array(t).fill(0);f[m]=1;for(let y=0;y<m;y++){let d=0;for(let g=0;g<t;g++)d+=f[g]*Number(l.get(g,y));for(let g=0;g<t;g++)f[g]=f[g]-d*Number(l.get(g,y))}let p=0;for(let y=0;y<t;y++)p+=f[y]*f[y];if(p=Math.sqrt(p),p>1e-10)for(let y=0;y<t;y++)l.set([y,m],f[y]/p)}return{u:l,s,vt:c}}function St(r){let t=r.shape[0],e=100*t*t,n=1e-10,o=[];for(let u=0;u<t;u++){o.push([]);for(let s=0;s<t;s++)o[u].push(Number(r.get(u,s)))}let a=[];for(let u=0;u<t;u++){a.push([]);for(let s=0;s<t;s++)a[u].push(u===s?1:0)}for(let u=0;u<e;u++){let s=0,c=0,l=1;for(let h=0;h<t;h++)for(let S=h+1;S<t;S++)Math.abs(o[h][S])>s&&(s=Math.abs(o[h][S]),c=h,l=S);if(s<n)break;let m=o[c][c],f=o[l][l],p=o[c][l],y;Math.abs(m-f)<1e-15?y=Math.PI/4:y=.5*Math.atan2(2*p,f-m);let d=Math.cos(y),g=Math.sin(y),b=d*d*m+g*g*f-2*g*d*p,A=g*g*m+d*d*f+2*g*d*p;o[c][c]=b,o[l][l]=A,o[c][l]=0,o[l][c]=0;for(let h=0;h<t;h++)if(h!==c&&h!==l){let S=o[h][c],D=o[h][l];o[h][c]=d*S-g*D,o[c][h]=o[h][c],o[h][l]=g*S+d*D,o[l][h]=o[h][l]}for(let h=0;h<t;h++){let S=a[h][c],D=a[h][l];a[h][c]=d*S-g*D,a[h][l]=g*S+d*D}}let i=[];for(let u=0;u<t;u++)i.push(o[u][u]);return{values:i,vectors:a}}function pn(r,t=!0,e=!0){let n=tr(r);if(!e)return n.s;if(!t){let[o,a]=r.shape,i=Math.min(o,a),u=N.zeros([o,i],"float64");for(let c=0;c<o;c++)for(let l=0;l<i;l++)u.set([c,l],Number(n.u.get(c,l)));let s=N.zeros([i,a],"float64");for(let c=0;c<i;c++)for(let l=0;l<a;l++)s.set([c,l],Number(n.vt.get(c,l)));return{u,s:n.s,vt:s}}return n}function yn(r){if(r.ndim!==2)throw new Error(`det: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`det: matrix must be square, got ${t}x${e}`);let n=t;if(n===0)return 1;let o=r.data;if(n===1)return Number(o[0]);if(n===2)return Number(o[0])*Number(o[3])-Number(o[1])*Number(o[2]);let{lu:a,sign:i}=Nt(r),u=a.data,s=i;for(let c=0;c<n;c++)s*=u[c*n+c];return s}function Nt(r){let[t,e]=r.shape,n=t,o=e,a=N.zeros([n,o],"float64"),i=a.data,u=r.data;for(let l=0;l<n*o;l++)i[l]=Number(u[l]);let s=Array.from({length:n},(l,m)=>m),c=1;for(let l=0;l<Math.min(n,o);l++){let m=Math.abs(i[l*o+l]),f=l;for(let y=l+1;y<n;y++){let d=Math.abs(i[y*o+l]);d>m&&(m=d,f=y)}if(f!==l){for(let d=0;d<o;d++){let g=i[l*o+d];i[l*o+d]=i[f*o+d],i[f*o+d]=g}let y=s[l];s[l]=s[f],s[f]=y,c=-c}let p=i[l*o+l];if(Math.abs(p)>1e-15)for(let y=l+1;y<n;y++){let d=i[y*o+l]/p;i[y*o+l]=d;for(let g=l+1;g<o;g++)i[y*o+g]=i[y*o+g]-d*i[l*o+g]}}return{lu:a,piv:s,sign:c}}function qr(r){if(r.ndim!==2)throw new Error(`inv: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`inv: matrix must be square, got ${t}x${e}`);let n=t,{lu:o,piv:a}=Nt(r),i=o.data,u=N.zeros([n,n],"float64"),s=u.data;for(let c=0;c<n;c++){let l=new Float64Array(n);for(let m=0;m<n;m++){let f=a[m]===c?1:0;for(let p=0;p<m;p++)f-=i[m*n+p]*l[p];l[m]=f}for(let m=n-1;m>=0;m--){let f=l[m];for(let y=m+1;y<n;y++)f-=i[m*n+y]*s[y*n+c];let p=i[m*n+m];if(Math.abs(p)<1e-15)throw new Error("inv: singular matrix");s[m*n+c]=f/p}}return u}function en(r,t){let[e]=r.shape,n=e,{lu:o,piv:a}=Nt(r),i=o.data,u=t.data,s=new Float64Array(n);for(let f=0;f<n;f++)s[f]=Number(u[a[f]]);let c=new Float64Array(n);for(let f=0;f<n;f++){let p=s[f];for(let y=0;y<f;y++)p-=i[f*n+y]*c[y];c[f]=p}let l=N.zeros([n],"float64"),m=l.data;for(let f=n-1;f>=0;f--){let p=c[f];for(let d=f+1;d<n;d++)p-=i[f*n+d]*m[d];let y=i[f*n+f];if(Math.abs(y)<1e-15)throw new Error("solve: singular matrix");m[f]=p/y}return l}function dn(r,t){if(r.ndim!==2)throw new Error(`solve: coefficient matrix must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`solve: coefficient matrix must be square, got ${e}x${n}`);let o=e;if(t.ndim===1){if(t.shape[0]!==o)throw new Error(`solve: incompatible shapes (${e},${n}) and (${t.shape[0]},)`);return en(r,t)}if(t.ndim===2){if(t.shape[0]!==o)throw new Error(`solve: incompatible shapes (${e},${n}) and (${t.shape[0]},${t.shape[1]})`);let a=t.shape[1],i=N.zeros([o,a],"float64");for(let u=0;u<a;u++){let s=N.zeros([o],"float64");for(let l=0;l<o;l++)s.set([l],Number(t.get(l,u)));let c=en(r,s);for(let l=0;l<o;l++)i.set([l,u],Number(c.get(l)))}return i}throw new Error(`solve: b must be 1D or 2D, got ${t.ndim}D`)}function gn(r,t,e=null){if(r.ndim!==2)throw new Error(`lstsq: coefficient matrix must be 2D, got ${r.ndim}D`);let[n,o]=r.shape,{u:a,s:i,vt:u}=tr(r),s=Math.min(n,o),c=e??Math.max(n,o)*Number.EPSILON,m=Number(i.get(0))*c,f=0;for(let A=0;A<s;A++)Number(i.get(A))>m&&f++;let p=t.ndim===1?P(t,[t.size,1]):t,y=p.shape[1];if(p.shape[0]!==n)throw new Error(`lstsq: incompatible shapes (${n},${o}) and (${t.shape.join(",")})`);let d=N.zeros([o,y],"float64");for(let A=0;A<y;A++){let h=new Array(n).fill(0);for(let S=0;S<n;S++)for(let D=0;D<n;D++)h[S]+=Number(a.get(D,S))*Number(p.get(D,A));for(let S=0;S<o;S++){let D=0;for(let x=0;x<s;x++){let w=Number(i.get(x));w>m&&(D+=Number(u.get(x,S))*h[x]/w)}d.set([S,A],D)}}let g;if(n>o){g=N.zeros([y],"float64");for(let A=0;A<y;A++){let h=0;for(let S=0;S<n;S++){let D=0;for(let w=0;w<o;w++)D+=Number(r.get(S,w))*Number(d.get(w,A));let x=D-Number(p.get(S,A));h+=x*x}g.set([A],h)}}else g=N.zeros([0],"float64");return{x:t.ndim===1?P(d,[o]):d,residuals:g,rank:f,s:i}}function hn(r,t=2){if(r.ndim!==2)throw new Error(`cond: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(t===2||t===-2){let{s:u}=tr(r),s=Math.min(e,n),c=Number(u.get(0)),l=Number(u.get(s-1));return t===2?l>0?c/l:1/0:c>0?l/c:0}if(e!==n)throw new Error(`cond: matrix must be square for p=${t}`);let o=nr(r,t),a=qr(r),i=nr(a,t);return o*i}function An(r,t){if(r.ndim===0)return Number(r.get())!==0?1:0;if(r.ndim===1){for(let i=0;i<r.size;i++)if(Number(r.get(i))!==0)return 1;return 0}if(r.ndim!==2)throw new Error(`matrix_rank: input must be at most 2D, got ${r.ndim}D`);let{s:e}=tr(r),n=Number(e.get(0)),o=t??n*Math.max(r.shape[0],r.shape[1])*Number.EPSILON,a=0;for(let i=0;i<e.size;i++)Number(e.get(i))>o&&a++;return a}function bn(r,t){if(r.ndim!==2)throw new Error(`matrix_power: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`matrix_power: matrix must be square, got ${e}x${n}`);let o=e;if(!Number.isInteger(t))throw new Error("matrix_power: exponent must be an integer");if(t===0){let c=N.zeros([o,o],"float64");for(let l=0;l<o;l++)c.set([l,l],1);return c}let a=r,i=t;t<0&&(a=qr(r),i=-t);let u=N.zeros([o,o],"float64");for(let c=0;c<o;c++)u.set([c,c],1);let s=N.zeros([o,o],"float64");for(let c=0;c<o;c++)for(let l=0;l<o;l++)s.set([c,l],Number(a.get(c,l)));for(;i>0;)i&1&&(u=G(u,s)),s=G(s,s),i>>=1;return u}function Sn(r,t=1e-15){if(r.ndim!==2)throw new Error(`pinv: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape,{u:o,s:a,vt:i}=tr(r),u=Math.min(e,n),c=Number(a.get(0))*t,l=N.zeros([n,e],"float64");for(let m=0;m<n;m++)for(let f=0;f<e;f++){let p=0;for(let y=0;y<u;y++){let d=Number(a.get(y));d>c&&(p+=Number(i.get(y,m))*Number(o.get(f,y))/d)}l.set([m,f],p)}return l}function Dt(r){if(r.ndim!==2)throw new Error(`eig: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`eig: matrix must be square, got ${t}x${e}`);let n=t,o=!0;r:for(let c=0;c<n;c++)for(let l=c+1;l<n;l++)if(Math.abs(Number(r.get(c,l))-Number(r.get(l,c)))>1e-10){o=!1;break r}if(o){let{values:c,vectors:l}=St(r),m=N.zeros([n],"float64"),f=N.zeros([n,n],"float64");for(let p=0;p<n;p++){m.set([p],c[p]);for(let y=0;y<n;y++)f.set([y,p],l[y][p])}return{w:m,v:f}}console.warn("numpy-ts: eig() called on non-symmetric matrix. Complex eigenvalues are not supported; results may be inaccurate. For symmetric matrices, use eigh() instead.");let{values:a,vectors:i}=ic(r),u=N.zeros([n],"float64"),s=N.zeros([n,n],"float64");for(let c=0;c<n;c++){u.set([c],a[c]);for(let l=0;l<n;l++)s.set([l,c],i[l][c])}return{w:u,v:s}}function ic(r){let t=r.shape[0],e=1e3,n=1e-10,o=N.zeros([t,t],"float64");for(let s=0;s<t;s++)for(let c=0;c<t;c++)o.set([s,c],Number(r.get(s,c)));let a=N.zeros([t,t],"float64");for(let s=0;s<t;s++)a.set([s,s],1);for(let s=0;s<e;s++){let c=0;for(let p=0;p<t;p++)for(let y=0;y<t;y++)p!==y&&(c+=Number(o.get(p,y))**2);if(Math.sqrt(c)<n*t)break;let l=bt(o,"reduced"),m=l.q,f=l.r;o=G(f,m),a=G(a,m)}let i=[];for(let s=0;s<t;s++)i.push(Number(o.get(s,s)));let u=[];for(let s=0;s<t;s++){u.push([]);for(let c=0;c<t;c++)u[s].push(Number(a.get(s,c)))}return{values:i,vectors:u}}function xt(r,t="L"){if(r.ndim!==2)throw new Error(`eigh: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`eigh: matrix must be square, got ${e}x${n}`);let o=e,a=N.zeros([o,o],"float64");for(let m=0;m<o;m++)for(let f=0;f<o;f++)t==="L"?m>=f&&(a.set([m,f],Number(r.get(m,f))),a.set([f,m],Number(r.get(m,f)))):f>=m&&(a.set([m,f],Number(r.get(m,f))),a.set([f,m],Number(r.get(m,f))));let{values:i,vectors:u}=St(a),s=Array.from({length:o},(m,f)=>f);s.sort((m,f)=>i[m]-i[f]);let c=N.zeros([o],"float64"),l=N.zeros([o,o],"float64");for(let m=0;m<o;m++){c.set([m],i[s[m]]);for(let f=0;f<o;f++)l.set([f,m],u[f][s[m]])}return{w:c,v:l}}function Nn(r){let{w:t}=Dt(r);return t}function Dn(r,t="L"){let{w:e}=xt(r,t);return e}function xn(r){return C(r,Math.sqrt,!1)}function wn(r,t){return typeof t=="number"?cc(r,t):F(r,t,Math.pow,"power")}function cc(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,c=N.zeros(n,s),l=c.data;if(I(e))if(I(s)&&Number.isInteger(t)&&t>=0){let m=o,f=l;for(let p=0;p<a;p++)f[p]=m[p]**BigInt(t)}else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);return c}function In(r){return C(r,Math.exp,!1)}function zn(r){return C(r,t=>Math.pow(2,t),!1)}function _n(r){return C(r,Math.expm1,!1)}function Bn(r){return C(r,Math.log,!1)}function En(r){return C(r,Math.log2,!1)}function vn(r){return C(r,Math.log10,!1)}function On(r){return C(r,Math.log1p,!1)}function Un(r,t){return typeof t=="number"?fc(r,t):lc(r,t)}function lc(r,t){let e=mr(r.shape,t.shape),n=e.reduce((c,l)=>c*l,1),o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=N.zeros(e,i),s=u.data;for(let c=0;c<n;c++){let l=(I(o),Number(r.iget(c))),m=(I(a),Number(t.iget(c))),f=Math.max(l,m),p=Math.min(l,m);s[c]=f+Math.log1p(Math.exp(p-f))}return u}function fc(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=N.zeros(n,a),u=i.data;for(let s=0;s<o;s++){let c=(I(e),Number(r.data[s])),l=Math.max(c,t),m=Math.min(c,t);u[s]=l+Math.log1p(Math.exp(m-l))}return i}function Tn(r,t){return typeof t=="number"?pc(r,t):mc(r,t)}function mc(r,t){let e=mr(r.shape,t.shape),n=e.reduce((l,m)=>l*m,1),o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=N.zeros(e,i),s=u.data,c=Math.LOG2E;for(let l=0;l<n;l++){let m=(I(o),Number(r.iget(l))),f=(I(a),Number(t.iget(l))),p=Math.max(m,f),y=Math.min(m,f);s[l]=p+Math.log1p(Math.pow(2,y-p))*c}return u}function pc(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=N.zeros(n,a),u=i.data,s=Math.LOG2E;for(let c=0;c<o;c++){let l=(I(e),Number(r.data[c])),m=Math.max(l,t),f=Math.min(l,t);u[c]=m+Math.log1p(Math.pow(2,f-m))*s}return i}function $n(r){return C(r,Math.sin,!1)}function Mn(r){return C(r,Math.cos,!1)}function kn(r){return C(r,Math.tan,!1)}function Cn(r){return C(r,Math.asin,!1)}function Vn(r){return C(r,Math.acos,!1)}function qn(r){return C(r,Math.atan,!1)}function Fn(r,t){return typeof t=="number"?gc(r,t):dc(r,t)}function dc(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=N.zeros(e,i),s=u.data;for(let c=0;c<n;c++){let l=(I(o),Number(r.data[c])),m=(I(a),Number(t.data[c]));s[c]=Math.atan2(l,m)}return u}function gc(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",u=N.zeros(n,i),s=u.data;if(I(e))for(let c=0;c<a;c++)s[c]=Math.atan2(Number(o[c]),t);else for(let c=0;c<a;c++)s[c]=Math.atan2(Number(o[c]),t);return u}function Pn(r,t){return typeof t=="number"?Ac(r,t):hc(r,t)}function hc(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=N.zeros(e,i),s=u.data;for(let c=0;c<n;c++){let l=(I(o),Number(r.data[c])),m=(I(a),Number(t.data[c]));s[c]=Math.hypot(l,m)}return u}function Ac(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",u=N.zeros(n,i),s=u.data;if(I(e))for(let c=0;c<a;c++)s[c]=Math.hypot(Number(o[c]),t);else for(let c=0;c<a;c++)s[c]=Math.hypot(Number(o[c]),t);return u}function jn(r){let t=180/Math.PI;return C(r,e=>e*t,!1)}function Rn(r){let t=Math.PI/180;return C(r,e=>e*t,!1)}function Ln(r){return C(r,Math.sinh,!1)}function Zn(r){return C(r,Math.cosh,!1)}function Wn(r){return C(r,Math.tanh,!1)}function Gn(r){return C(r,Math.asinh,!1)}function Hn(r){return C(r,Math.acosh,!1)}function Yn(r){return C(r,Math.atanh,!1)}function wt(r,t){let e=r.shape,n=e.length,o=t.length;if(o<n)throw new Error("input operand has more dimensions than allowed by the axis remapping");let a=rr([Array.from(e),t]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);for(let i=0;i<o;i++)if(a[i]!==t[i])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);return Y(r,t)}function Jn(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=rr(t);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${t.map(n=>`(${n.join(",")})`).join(" ")}`);return r.map(n=>Y(n,e))}function Qn(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let y=r.size;for(let A of t){let h=A<0?y+A:A;if(h<0||h>=y)throw new Error(`index ${A} is out of bounds for axis 0 with size ${y}`)}let d=t.length,g=T(a);if(!g)throw new Error(`Cannot take from array with dtype ${a}`);let b=new g(d);for(let A=0;A<d;A++){let h=t[A];h<0&&(h=y+h);let S=r.iget(h);I(a),b[A]=S}return N.fromData(b,[d],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i];for(let y of t){let d=y<0?u+y:y;if(d<0||d>=u)throw new Error(`index ${y} is out of bounds for axis ${i} with size ${u}`)}let s=Array.from(n);s[i]=t.length;let c=s.reduce((y,d)=>y*d,1),l=T(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let m=new l(c),f=L(s),p=new Array(o).fill(0);for(let y=0;y<c;y++){let d=[...p],g=p[i],b=t[g];b<0&&(b=u+b),d[i]=b;let A=r.get(...d),h=0;for(let S=0;S<o;S++)h+=p[S]*f[S];I(a),m[h]=A;for(let S=o-1;S>=0&&(p[S]++,!(p[S]<s[S]));S--)p[S]=0}return N.fromData(m,s,a)}function Xn(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=new Array(t.length).fill(e);else{a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i));if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let i=[...a];a=[];for(let u=0;u<t.length;u++)a.push(i[u%i.length])}}for(let i=0;i<t.length;i++){let u=t[i];if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`index ${t[i]} is out of bounds for axis 0 with size ${n}`);let s=a[i];I(o)?typeof s!="bigint"&&(s=BigInt(Math.round(Number(s)))):typeof s=="bigint"&&(s=Number(s)),r.iset(u,s)}}function Kn(r,t){if(t.length===0)throw new Error("choices cannot be empty");let e=r.shape,n=t.length,o=t[0].dtype,a=t.map(f=>Array.from(f.shape));a.unshift(Array.from(e));let i=rr(a);if(i===null)throw new Error("operands could not be broadcast together");let u=Y(r,i),s=t.map(f=>Y(f,i)),c=i.reduce((f,p)=>f*p,1),l=T(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let m=new l(c);for(let f=0;f<c;f++){let p=Number(u.iget(f));if(p<0||p>=n)throw new Error(`index ${p} is out of bounds for axis 0 with size ${n}`);let y=s[p].iget(f);I(o),m[f]=y}return N.fromData(m,i,o)}function ro(r,t,e=!1){if(r.ndim!==t.ndim)return!1;for(let o=0;o<r.ndim;o++)if(r.shape[o]!==t.shape[o])return!1;let n=r.size;for(let o=0;o<n;o++){let a=r.iget(o),i=t.iget(o);if(e){let u=typeof a=="number"&&Number.isNaN(a),s=typeof i=="number"&&Number.isNaN(i);if(u&&s)continue}if(a!==i)return!1}return!0}function to(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=t.shape;if(u.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${u.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==i&&u[d]!==n[d]&&u[d]!==1&&n[d]!==1)throw new Error(`index ${u[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let s=Array.from(u),c=s.reduce((d,g)=>d*g,1),l=T(a);if(!l)throw new Error(`Cannot take_along_axis with dtype ${a}`);let m=new l(c),f=L(n),p=L(u),y=n[i];for(let d=0;d<c;d++){let g=new Array(o),b=d;for(let w=o-1;w>=0;w--)g[w]=b%s[w],b=Math.floor(b/s[w]);let A=0;for(let w=0;w<o;w++){let _=u[w]===1?0:g[w];A+=_*p[w]}let h=Number(t.iget(A));if(h<0&&(h=y+h),h<0||h>=y)throw new Error(`index ${h} is out of bounds for axis ${i} with size ${y}`);let S=[...g];S[i]=h;let D=0;for(let w=0;w<o;w++){let _=n[w]===1?0:S[w];D+=_*f[w]}let x=r.iget(D);I(a),m[d]=x}return N.fromData(m,s,a)}function eo(r,t,e,n){let o=r.shape,a=o.length,i=r.dtype,u=n<0?a+n:n;if(u<0||u>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let s=t.shape,c=e.shape;if(s.length!==a||c.length!==a)throw new Error("indices, arr, and values must have same ndim");let l=o[u],m=L(o),f=L(s),p=L(c),y=s.reduce((d,g)=>d*g,1);for(let d=0;d<y;d++){let g=new Array(a),b=d;for(let _=a-1;_>=0;_--)g[_]=b%s[_],b=Math.floor(b/s[_]);let A=0;for(let _=0;_<a;_++)A+=g[_]*f[_];let h=Number(t.iget(A));if(h<0&&(h=l+h),h<0||h>=l)throw new Error(`index ${h} is out of bounds for axis ${u} with size ${l}`);let S=0;for(let _=0;_<a;_++){let B=c[_]===1?0:g[_];S+=B*p[_]}let D=e.iget(S),x=[...g];x[u]=h;let w=0;for(let _=0;_<a;_++)w+=x[_]*m[_];I(i)?typeof D!="bigint"&&(D=BigInt(Math.round(Number(D)))):typeof D=="bigint"&&(D=Number(D)),r.iset(w,D)}}function no(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let u=0;u<e.size;u++)a.push(e.iget(u))}let i=0;for(let u=0;u<n;u++)if(t.iget(u)){let c=a[i%a.length];I(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(u,c),i++}}function oo(r,t,e){let n=t.shape,o=n.length,a=t.dtype,i=t.data,u=I(a);if(e===void 0){let A=0,h=Math.min(r.size,t.size);for(let w=0;w<h;w++)r.iget(w)&&A++;let S=T(a);if(!S)throw new Error(`Cannot compress with dtype ${a}`);let D=new S(A),x=0;for(let w=0;w<h;w++)r.iget(w)&&(D[x]=i[w],x++);return N.fromData(D,[A],a)}let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let c=n[s],l=Math.min(r.size,c),m=[];for(let A=0;A<l;A++)r.iget(A)&&m.push(A);let f=m.length,p=[...n];p[s]=f;let y=p.reduce((A,h)=>A*h,1),d=T(a);if(!d)throw new Error(`Cannot compress with dtype ${a}`);let g=new d(y),b=L(n);if(s===0){let A=b[0],h=n.slice(1).reduce((D,x)=>D*x,1),S=0;for(let D=0;D<f;D++){let w=m[D]*A;if(u){let _=i,B=g;for(let E=0;E<h;E++)B[S++]=_[w+E]}else{let _=i,B=g;for(let E=0;E<h;E++)B[S++]=_[w+E]}}}else{let A=n.slice(0,s).reduce((D,x)=>D*x,1),h=n.slice(s+1).reduce((D,x)=>D*x,1),S=0;for(let D=0;D<A;D++)for(let x=0;x<f;x++){let w=m[x],_=0,B=D;for(let E=s-1;E>=0;E--){let v=B%n[E];B=Math.floor(B/n[E]),_+=v*b[E]}if(_+=w*b[s],u){let E=i,v=g;for(let $=0;$<h;$++)v[S++]=E[_+$]}else{let E=i,v=g;for(let $=0;$<h;$++)v[S++]=E[_+$]}}}return N.fromData(g,p,a)}function ao(r,t,e=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");let n=[...r.map(f=>Array.from(f.shape)),...t.map(f=>Array.from(f.shape))],o=rr(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,i=o.reduce((f,p)=>f*p,1),u=T(a);if(!u)throw new Error(`Cannot select with dtype ${a}`);let s=e;I(a)?s=typeof e=="bigint"?e:BigInt(e):s=typeof e=="bigint"?Number(e):e;let c=new u(i);for(let f=0;f<i;f++)I(a),c[f]=s;let l=r.map(f=>Y(f,o)),m=t.map(f=>Y(f,o));for(let f=0;f<i;f++)for(let p=0;p<r.length;p++)if(l[p].iget(f)){let y=m[p].iget(f);I(a),c[f]=y;break}return N.fromData(c,o,a)}function so(r,t,e){let n=r.size,o=r.dtype,a=[];for(let u=0;u<e.size;u++)a.push(e.iget(u));if(a.length===0)return;let i=0;for(let u=0;u<n;u++)if(t.iget(u)){let c=a[i%a.length];I(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(u,c),i++}}function It(r,t=2){if(t<1)throw new Error("ndim must be at least 1");let e=new Int32Array(r);for(let o=0;o<r;o++)e[o]=o;let n=[];for(let o=0;o<t;o++)n.push(N.fromData(new Int32Array(e),[r],"int32"));return n}function io(r){let t=r.shape,e=t.length;if(e<2)throw new Error("array must be at least 2-D");let n=t[0];for(let o=1;o<e;o++)if(t[o]!==n)throw new Error("All dimensions of input must be equal");return It(n,e)}function zt(r,t=0,e){let n=e??r,o=[],a=[];for(let i=0;i<r;i++)for(let u=0;u<=Math.min(i+t,n-1);u++)u>=0&&(o.push(i),a.push(u));return[N.fromData(new Int32Array(o),[o.length],"int32"),N.fromData(new Int32Array(a),[a.length],"int32")]}function uo(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return zt(e[0],t,e[1])}function _t(r,t=0,e){let n=e??r,o=[],a=[];for(let i=0;i<r;i++)for(let u=Math.max(i+t,0);u<n;u++)o.push(i),a.push(u);return[N.fromData(new Int32Array(o),[o.length],"int32"),N.fromData(new Int32Array(a),[a.length],"int32")]}function co(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return _t(e[0],t,e[1])}function lo(r,t,e=0){let n=t(r,e),o=n.shape;if(o.length!==2||o[0]!==r||o[1]!==r)throw new Error("mask_func must return n x n array");let a=[],i=[];for(let u=0;u<r;u++)for(let s=0;s<r;s++)n.get(u,s)&&(a.push(u),i.push(s));return[N.fromData(new Int32Array(a),[a.length],"int32"),N.fromData(new Int32Array(i),[i.length],"int32")]}function fo(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((s,c)=>s*c,1),a=T(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let i=new a(o),u=r.reduce((s,c)=>s*c,1);for(let s=0;s<e;s++){let c=s*u;for(let l=0;l<u;l++){let m=new Array(e),f=l;for(let y=e-1;y>=0;y--)m[y]=f%r[y],f=Math.floor(f/r[y]);let p=m[s];t==="int64"?i[c+l]=BigInt(p):i[c+l]=p}}return N.fromData(i,n,t)}function mo(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,i=o.dtype,u=new Array(t).fill(1);u[n]=a;let s=T(i);if(!s)throw new Error(`Cannot create ix_ with dtype ${i}`);let c=new s(a);for(let l=0;l<a;l++){let m=o.iget(l);I(i),c[l]=m}e.push(N.fromData(c,u,i))}return e}function po(r,t,e="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");let n=r[0].size,o=t.length,a=new Int32Array(n),i=new Array(o),u=1;for(let s=o-1;s>=0;s--)i[s]=u,u*=t[s];for(let s=0;s<n;s++){let c=0;for(let l=0;l<o;l++){let m=Number(r[l].iget(s)),f=t[l];if(e==="wrap")m=(m%f+f)%f;else if(e==="clip")m=Math.max(0,Math.min(m,f-1));else if(m<0||m>=f)throw new Error(`index ${m} is out of bounds for axis ${l} with size ${f}`);c+=m*i[l]}a[s]=c}return N.fromData(a,[n],"int32")}function yo(r,t,e="C"){let n=t.length,o,a;if(typeof r=="number")o=[r],a=[];else{o=[];for(let l=0;l<r.size;l++)o.push(Number(r.iget(l)));a=Array.from(r.shape)}let i=o.length,u=t.reduce((l,m)=>l*m,1),s=new Array(n);if(e==="C"){let l=1;for(let m=n-1;m>=0;m--)s[m]=l,l*=t[m]}else{let l=1;for(let m=0;m<n;m++)s[m]=l,l*=t[m]}let c=[];for(let l=0;l<n;l++){let m=new Int32Array(i);c.push(N.fromData(m,a.length?a:[1],"int32"))}for(let l=0;l<i;l++){let m=o[l];if(m<0||m>=u)throw new Error(`index ${m} is out of bounds for array with size ${u}`);if(e==="C")for(let f=0;f<n;f++){let p=Math.floor(m/s[f]);m=m%s[f],c[f].data[l]=p%t[f]}else for(let f=n-1;f>=0;f--){let p=Math.floor(m/s[f]);m=m%s[f],c[f].data[l]=p%t[f]}}return typeof r=="number"?c.map(l=>{let m=l.iget(0);return N.fromData(new Int32Array([Number(m)]),[],"int32")}):c}function H(r,t){if(!ue(r)&&r!=="bool")throw new TypeError(`ufunc '${t}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function Ar(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Ao(r,t){return H(r.dtype,"bitwise_and"),typeof t=="number"?xc(r,t):(H(t.dtype,"bitwise_and"),Ar(r,t)?Dc(r,t):F(r,t,(e,n)=>e&n,"bitwise_and"))}function Dc(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;if(!I(r.dtype)||!I(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m&f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]&m[f]}}else for(let s=0;s<o;s++)u[s]=a[s]&i[s];return n}function xc(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]&l}else for(let s=0;s<a;s++)u[s]=o[s]&t;return i}function bo(r,t){return H(r.dtype,"bitwise_or"),typeof t=="number"?Ic(r,t):(H(t.dtype,"bitwise_or"),Ar(r,t)?wc(r,t):F(r,t,(e,n)=>e|n,"bitwise_or"))}function wc(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;if(!I(r.dtype)||!I(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m|f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]|m[f]}}else for(let s=0;s<o;s++)u[s]=a[s]|i[s];return n}function Ic(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]|l}else for(let s=0;s<a;s++)u[s]=o[s]|t;return i}function So(r,t){return H(r.dtype,"bitwise_xor"),typeof t=="number"?_c(r,t):(H(t.dtype,"bitwise_xor"),Ar(r,t)?zc(r,t):F(r,t,(e,n)=>e^n,"bitwise_xor"))}function zc(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;if(!I(r.dtype)||!I(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m^f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]^m[f]}}else for(let s=0;s<o;s++)u[s]=a[s]^i[s];return n}function _c(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]^l}else for(let s=0;s<a;s++)u[s]=o[s]^t;return i}function Bt(r){H(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=N.zeros(e,t),i=a.data;if(I(t)){let u=n,s=i;for(let c=0;c<o;c++)s[c]=~u[c]}else for(let u=0;u<o;u++)i[u]=~n[u];return a}function No(r){return Bt(r)}function Do(r,t){if(H(r.dtype,"left_shift"),typeof t=="number")return go(r,t);if(H(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=I(t.dtype)?Number(t.data[0]):t.data[0];return go(r,e)}return Ar(r,t)?Bc(r,t):F(r,t,(e,n)=>e<<n,"left_shift")}function Bc(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),m=typeof i[c]=="bigint"?i[c]:BigInt(Math.round(Number(i[c])));s[c]=l<<m}}else for(let s=0;s<o;s++)u[s]=a[s]<<i[s];return n}function go(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]<<l}else for(let s=0;s<a;s++)u[s]=o[s]<<t;return i}function xo(r,t){if(H(r.dtype,"right_shift"),typeof t=="number")return ho(r,t);if(H(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=I(t.dtype)?Number(t.data[0]):t.data[0];return ho(r,e)}return Ar(r,t)?Ec(r,t):F(r,t,(e,n)=>e>>n,"right_shift")}function Ec(r,t){let e=k(r.dtype,t.dtype),n=N.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(I(e)){let s=u;for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),m=typeof i[c]=="bigint"?i[c]:BigInt(Math.round(Number(i[c])));s[c]=l>>m}}else for(let s=0;s<o;s++)u[s]=a[s]>>i[s];return n}function ho(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=N.zeros(n,e),u=i.data;if(I(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]>>l}else for(let s=0;s<a;s++)u[s]=o[s]>>t;return i}function wo(r,t=-1,e="big"){let n=Array.from(r.shape),o=n.length;if(t<0&&(t=o+t),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=n[t],i=Math.ceil(a/8),u=[...n];u[t]=i;let s=N.zeros(u,"uint8"),c=s.data;if(o===1){for(let g=0;g<i;g++){let b=0;for(let A=0;A<8;A++){let h=g*8+A;if(h<a){let S=Number(r.data[h])!==0?1:0;e==="big"?b|=S<<7-A:b|=S<<A}}c[g]=b}return s}let l=n.slice(0,t),m=n.slice(t+1),f=l.reduce((g,b)=>g*b,1),p=m.reduce((g,b)=>g*b,1),y=Fr(n),d=Fr(u);for(let g=0;g<f;g++)for(let b=0;b<p;b++)for(let A=0;A<i;A++){let h=0;for(let w=0;w<8;w++){let _=A*8+w;if(_<a){let B=0,E=g;for(let M=0;M<t;M++){let V=M<t-1?l.slice(M+1).reduce((R,fr)=>R*fr,1):1,W=Math.floor(E/V);E%=V,B+=W*y[M]}B+=_*y[t];let v=b;for(let M=t+1;M<o;M++){let V=M<o-1?m.slice(M-t).reduce((R,fr)=>R*fr,1):1,W=Math.floor(v/V);v%=V,B+=W*y[M]}let $=Number(r.data[B])!==0?1:0;e==="big"?h|=$<<7-w:h|=$<<w}}let S=0,D=g;for(let w=0;w<t;w++){let _=w<t-1?l.slice(w+1).reduce((E,v)=>E*v,1):1,B=Math.floor(D/_);D%=_,S+=B*d[w]}S+=A*d[t];let x=b;for(let w=t+1;w<o;w++){let _=w<o-1?m.slice(w-t).reduce((E,v)=>E*v,1):1,B=Math.floor(x/_);x%=_,S+=B*d[w]}c[S]=h}return s}function Io(r,t=-1,e=-1,n="big"){if(r.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");let o=Array.from(r.shape),a=o.length;if(t<0&&(t=a+t),t<0||t>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=o[t],u=i*8;e>=0&&(u=e);let s=[...o];s[t]=u;let c=N.zeros(s,"uint8"),l=c.data;if(a===1){for(let b=0;b<i;b++){let A=Number(r.data[b]);for(let h=0;h<8;h++){let S=b*8+h;if(S>=u)break;n==="big"?l[S]=A>>7-h&1:l[S]=A>>h&1}}return c}let m=o.slice(0,t),f=o.slice(t+1),p=m.reduce((b,A)=>b*A,1),y=f.reduce((b,A)=>b*A,1),d=Fr(o),g=Fr(s);for(let b=0;b<p;b++)for(let A=0;A<y;A++)for(let h=0;h<i;h++){let S=0,D=b;for(let _=0;_<t;_++){let B=_<t-1?m.slice(_+1).reduce((v,$)=>v*$,1):1,E=Math.floor(D/B);D%=B,S+=E*d[_]}S+=h*d[t];let x=A;for(let _=t+1;_<a;_++){let B=_<a-1?f.slice(_-t).reduce((v,$)=>v*$,1):1,E=Math.floor(x/B);x%=B,S+=E*d[_]}let w=Number(r.data[S]);for(let _=0;_<8;_++){let B=h*8+_;if(B>=u)break;let E=0;D=b;for(let v=0;v<t;v++){let $=v<t-1?m.slice(v+1).reduce((V,W)=>V*W,1):1,M=Math.floor(D/$);D%=$,E+=M*g[v]}E+=B*g[t],x=A;for(let v=t+1;v<a;v++){let $=v<a-1?f.slice(v-t).reduce((V,W)=>V*W,1):1,M=Math.floor(x/$);x%=$,E+=M*g[v]}n==="big"?l[E]=w>>7-_&1:l[E]=w>>_&1}}return c}function Fr(r){let t=r.length,e=new Array(t),n=1;for(let o=t-1;o>=0;o--)e[o]=n,n*=r[o];return e}function Et(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return r.copy();let i=t;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let u=r.copy(),s=u.data,c=e[i],l=Array.from(e).filter((f,p)=>p!==i),m=l.length===0?1:l.reduce((f,p)=>f*p,1);if(I(o)){let f=a,p=s;for(let y=0;y<m;y++){let d=[];for(let g=0;g<c;g++){let b=U(y,i,g,e),A=O(b,e);d.push({value:f[A],idx:g})}d.sort((g,b)=>g.value<b.value?-1:g.value>b.value?1:0);for(let g=0;g<c;g++){let b=U(y,i,g,e),A=O(b,e);p[A]=d[g].value}}}else for(let f=0;f<m;f++){let p=[];for(let y=0;y<c;y++){let d=U(f,i,y,e),g=O(d,e);p.push(Number(a[g]))}p.sort((y,d)=>isNaN(y)&&isNaN(d)?0:isNaN(y)?1:isNaN(d)?-1:y-d);for(let y=0;y<c;y++){let d=U(f,i,y,e),g=O(d,e);s[g]=p[y]}}return u}function vt(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return N.zeros([0],"int32");let i=t;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let u=N.zeros(Array.from(e),"int32"),s=u.data,c=e[i],l=Array.from(e).filter((f,p)=>p!==i),m=l.length===0?1:l.reduce((f,p)=>f*p,1);if(I(o)){let f=a;for(let p=0;p<m;p++){let y=[];for(let d=0;d<c;d++){let g=U(p,i,d,e),b=O(g,e);y.push({value:f[b],idx:d})}y.sort((d,g)=>d.value<g.value?-1:d.value>g.value?1:0);for(let d=0;d<c;d++){let g=U(p,i,d,e),b=O(g,e);s[b]=y[d].idx}}}else for(let f=0;f<m;f++){let p=[];for(let y=0;y<c;y++){let d=U(f,i,y,e),g=O(d,e);p.push({value:Number(a[g]),idx:y})}p.sort((y,d)=>isNaN(y.value)&&isNaN(d.value)?0:isNaN(y.value)?1:isNaN(d.value)?-1:y.value-d.value);for(let y=0;y<c;y++){let d=U(f,i,y,e),g=O(d,e);s[g]=p[y].idx}}return u}function zo(r){if(r.length===0)return N.zeros([0],"int32");let e=r[0].size;for(let i of r){if(i.ndim!==1)throw new Error("keys must be 1D arrays");if(i.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let i=0;i<e;i++)n.push(i);n.sort((i,u)=>{for(let s=r.length-1;s>=0;s--){let l=r[s].data,m=Number(l[i]),f=Number(l[u]);if(!(isNaN(m)&&isNaN(f))){if(isNaN(m))return 1;if(isNaN(f)||m<f)return-1;if(m>f)return 1}}return 0});let o=N.zeros([e],"int32"),a=o.data;for(let i=0;i<e;i++)a[i]=n[i];return o}function Oc(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],i=r[o],u=r[n],s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++){let f=r[m],p=isNaN(f),y=isNaN(c);!p&&(y||f<=c)&&([r[l],r[m]]=[r[m],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function Uc(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],i=r[o],u=r[n],s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++)r[m]<=c&&([r[l],r[m]]=[r[m],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function Tc(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,i=r[o].value,u=r[n].value,s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++){let f=r[m].value,p=isNaN(f),y=isNaN(c);!p&&(y||f<=c)&&([r[l],r[m]]=[r[m],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function $c(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,i=r[o].value,u=r[n].value,s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++)r[m].value<=c&&([r[l],r[m]]=[r[m],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function Ot(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype;if(o===0)return r.copy();let i=e;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i],s=t;if(s<0&&(s=u+s),s<0||s>=u)throw new Error(`kth(=${t}) out of bounds (${u})`);let c=r.copy(),l=c.data,m=Array.from(n).filter((p,y)=>y!==i),f=m.length===0?1:m.reduce((p,y)=>p*y,1);if(I(a)){let p=l;for(let y=0;y<f;y++){let d=[];for(let g=0;g<u;g++){let b=U(y,i,g,n),A=O(b,n);d.push(p[A])}Uc(d,s);for(let g=0;g<u;g++){let b=U(y,i,g,n),A=O(b,n);p[A]=d[g]}}}else for(let p=0;p<f;p++){let y=[];for(let d=0;d<u;d++){let g=U(p,i,d,n),b=O(g,n);y.push(Number(l[b]))}Oc(y,s);for(let d=0;d<u;d++){let g=U(p,i,d,n),b=O(g,n);l[b]=y[d]}}return c}function Ut(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,i=r.data;if(o===0)return N.zeros([0],"int32");let u=e;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u],c=t;if(c<0&&(c=s+c),c<0||c>=s)throw new Error(`kth(=${t}) out of bounds (${s})`);let l=N.zeros(Array.from(n),"int32"),m=l.data,f=Array.from(n).filter((y,d)=>d!==u),p=f.length===0?1:f.reduce((y,d)=>y*d,1);if(I(a)){let y=i;for(let d=0;d<p;d++){let g=[];for(let b=0;b<s;b++){let A=U(d,u,b,n),h=O(A,n);g.push({value:y[h],idx:b})}$c(g,c);for(let b=0;b<s;b++){let A=U(d,u,b,n),h=O(A,n);m[h]=g[b].idx}}}else for(let y=0;y<p;y++){let d=[];for(let g=0;g<s;g++){let b=U(y,u,g,n),A=O(b,n);d.push({value:Number(i[A]),idx:g})}Tc(d,c);for(let g=0;g<s;g++){let b=U(y,u,g,n),A=O(b,n);m[A]=d[g].idx}}return l}function _o(r){let t=r.dtype,e=r.size,n=r.data,o=[];for(let u=0;u<e;u++)o.push(Number(n[u]));o.sort((u,s)=>isNaN(u)&&isNaN(s)?0:isNaN(u)?1:isNaN(s)?-1:u-s);let a=N.zeros([e],t),i=a.data;for(let u=0;u<e;u++)i[u]=o[u];return a}function Pr(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=[];for(let l=0;l<e;l++)a.push([]);let i=[],u=1;for(let l=e-1;l>=0;l--)i.unshift(u),u*=t[l];for(let l=0;l<o;l++)if(n[l]){let m=l;for(let f=0;f<e;f++){let p=Math.floor(m/i[f]);m=m%i[f],a[f].push(p)}}let s=a[0]?.length??0,c=[];for(let l=0;l<e;l++){let m=N.zeros([s],"int32"),f=m.data;for(let p=0;p<s;p++)f[p]=a[l][p];c.push(m)}return c}function Bo(r){let t=r.data,e=r.size,n=[];for(let i=0;i<e;i++)t[i]&&n.push(i);let o=N.zeros([n.length],"int32"),a=o.data;for(let i=0;i<n.length;i++)a[i]=n[i];return o}function Eo(r,t,e){if(t===void 0&&e===void 0)return Pr(r);if(t===void 0||e===void 0)throw new Error("either both or neither of x and y should be given");let n=r.shape,o=t.shape,a=e.shape,i=Math.max(n.length,o.length,a.length),u=B=>{let E=Array(i).fill(1);for(let v=0;v<B.length;v++)E[i-B.length+v]=B[v];return E},s=u(n),c=u(o),l=u(a),m=[];for(let B=0;B<i;B++){let E=[s[B],c[B],l[B]],v=Math.max(...E);for(let $ of E)if($!==1&&$!==v)throw new Error("operands could not be broadcast together");m.push(v)}let f=t.dtype,p=N.zeros(m,f),y=p.data,d=r.data,g=t.data,b=e.data,A=(B,E)=>{let v=[],$=1;for(let M=B.length-1;M>=0;M--)v.unshift($),$*=B[M];for(;v.length<E.length;)v.unshift(0);for(let M=0;M<E.length;M++)E[M]===1&&m[M]!==1&&(v[M]=0);return v},h=A(n,s),S=A(o,c),D=A(a,l),x=[],w=1;for(let B=m.length-1;B>=0;B--)x.unshift(w),w*=m[B];let _=m.reduce((B,E)=>B*E,1);for(let B=0;B<_;B++){let E=B,v=0,$=0,M=0;for(let V=0;V<i;V++){let W=Math.floor(E/x[V]);E=E%x[V],v+=W*h[V],$+=W*S[V],M+=W*D[V]}d[v]?y[B]=g[$]:y[B]=b[M]}return p}function Tt(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.data,o=r.size,a=t.data,i=t.size,u=N.zeros([i],"int32"),s=u.data;for(let c=0;c<i;c++){let l=Number(a[c]),m=0,f=o;if(e==="left")for(;m<f;){let p=Math.floor((m+f)/2);Number(n[p])<l?m=p+1:f=p}else for(;m<f;){let p=Math.floor((m+f)/2);Number(n[p])<=l?m=p+1:f=p}s[c]=m}return u}function vo(r,t){let e=r.data,n=t.data,o=t.dtype,a=Math.min(r.size,t.size),i=0;for(let l=0;l<a;l++)e[l]&&i++;let u=N.zeros([i],o),s=u.data,c=0;if(I(o)){let l=n,m=s;for(let f=0;f<a;f++)e[f]&&(m[c++]=l[f])}else for(let l=0;l<a;l++)e[l]&&(s[c++]=n[l]);return u}function $t(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size;if(t===void 0){let f=0;for(let p=0;p<a;p++)o[p]&&f++;return f}let i=t;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let u=Array.from(e).filter((f,p)=>p!==i);if(u.length===0)return $t(r);let s=N.zeros(u,"int32"),c=s.data,l=e[i],m=u.reduce((f,p)=>f*p,1);for(let f=0;f<m;f++){let p=0;for(let y=0;y<l;y++){let d=U(f,i,y,e),g=O(d,e);o[g]&&p++}c[f]=p}return s}function Oo(r){if(!isFinite(r))return r;let t=Math.floor(r),e=r-t;return Math.abs(e-.5)<1e-10?t%2===0?t:t+1:Math.round(r)}function Mt(r,t=0){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",u=N.zeros(n,i),s=u.data,c=Math.pow(10,t);for(let l=0;l<a;l++){let m=Number(o[l]);s[l]=Oo(m*c)/c}return u}function kt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=N.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.ceil(Number(n[s]));return i}function Ct(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=N.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.trunc(Number(n[s]));return i}function Vt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=N.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.floor(Number(n[s]));return i}function qt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=N.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Oo(Number(n[s]));return i}function Ft(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=N.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.trunc(Number(n[s]));return i}function X(r,t=!1,e=!1,n=!1){let o=r.dtype,a=r.size,i=r.data,u=[];for(let h=0;h<a;h++)u.push({value:Number(i[h]),index:h});u.sort((h,S)=>isNaN(h.value)&&isNaN(S.value)?0:isNaN(h.value)?1:isNaN(S.value)?-1:h.value-S.value);let s=[],c=[],l=new Array(a),m=[],f,p=0;for(let h=0;h<u.length;h++){let{value:S,index:D}=u[h];f===void 0||isNaN(S)&&!isNaN(f)||!isNaN(S)&&isNaN(f)||!isNaN(S)&&!isNaN(f)&&S!==f?(f!==void 0&&m.push(p),s.push(S),c.push(D),p=1,f=S):p++}p>0&&m.push(p);let y=new Map,d=-1;for(let h=0;h<s.length;h++){let S=s[h];isNaN(S)?d=h:y.set(S,h)}for(let h=0;h<a;h++){let S=Number(i[h]);isNaN(S)?l[h]=d:l[h]=y.get(S)}let g=N.zeros([s.length],o),b=g.data;for(let h=0;h<s.length;h++)b[h]=s[h];if(!t&&!e&&!n)return g;let A={values:g};if(t){let h=N.zeros([c.length],"int32"),S=h.data;for(let D=0;D<c.length;D++)S[D]=c[D];A.indices=h}if(e){let h=N.zeros([l.length],"int32"),S=h.data;for(let D=0;D<l.length;D++)S[D]=l[D];A.inverse=h}if(n){let h=N.zeros([m.length],"int32"),S=h.data;for(let D=0;D<m.length;D++)S[D]=m[D];A.counts=h}return A}function Uo(r,t){return Pt(r,t)}function To(r,t){let e=r.dtype,n=X(r),o=X(t),a=new Set;for(let c=0;c<o.size;c++)a.add(Number(o.data[c]));let i=[];for(let c=0;c<n.size;c++){let l=Number(n.data[c]);a.has(l)&&i.push(l)}i.sort((c,l)=>c-l);let u=N.zeros([i.length],e),s=u.data;for(let c=0;c<i.length;c++)s[c]=i[c];return u}function Pt(r,t){let e=Array.from(r.shape),n=r.size,o=new Set;for(let s=0;s<t.size;s++)o.add(Number(t.data[s]));let a=N.zeros(e,"bool"),i=a.data,u=r.data;for(let s=0;s<n;s++){let c=Number(u[s]);i[s]=o.has(c)?1:0}return a}function $o(r,t){let e=r.dtype,n=X(r),o=new Set;for(let s=0;s<t.size;s++)o.add(Number(t.data[s]));let a=[];for(let s=0;s<n.size;s++){let c=Number(n.data[s]);o.has(c)||a.push(c)}let i=N.zeros([a.length],e),u=i.data;for(let s=0;s<a.length;s++)u[s]=a[s];return i}function Mo(r,t){let e=r.dtype,n=X(r),o=X(t),a=new Set,i=new Set;for(let l=0;l<n.size;l++)a.add(Number(n.data[l]));for(let l=0;l<o.size;l++)i.add(Number(o.data[l]));let u=[];for(let l of a)i.has(l)||u.push(l);for(let l of i)a.has(l)||u.push(l);u.sort((l,m)=>l-m);let s=N.zeros([u.length],e),c=s.data;for(let l=0;l<u.length;l++)c[l]=u[l];return s}function ko(r,t){let e=r.dtype,n=X(r),o=X(t),a=new Set;for(let c=0;c<n.size;c++)a.add(Number(n.data[c]));for(let c=0;c<o.size;c++)a.add(Number(o.data[c]));let i=Array.from(a);i.sort((c,l)=>c-l);let u=N.zeros([i.length],e),s=u.data;for(let c=0;c<i.length;c++)s[c]=i[c];return u}function jt(r,t=1,e=-1){if(t<0)throw new Error(`order must be non-negative but got ${t}`);if(t===0)return r.copy();let n=Array.from(r.shape),o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);if(n[a]<t+1)throw new Error(`diff requires at least ${t+1} elements along axis ${e}, but got ${n[a]}`);let i=r;for(let u=0;u<t;u++)i=Vc(i,a);return i}function Vc(r,t){let e=Array.from(r.shape),n=e.length,o=e[t],a=[...e];a[t]=o-1;let i=r.dtype,u=I(i)?"float64":i,s=N.zeros(a,u),c=s.data,l=r.strides,m=s.size;for(let f=0;f<m;f++){let p=f,y=new Array(n);for(let D=n-1;D>=0;D--)y[D]=p%a[D],p=Math.floor(p/a[D]);let d=[...y],g=[...y];g[t]=d[t]+1;let b=0,A=0;for(let D=0;D<n;D++)b+=d[D]*l[D],A+=g[D]*l[D];let h=(I(i),Number(r.data[b])),S=(I(i),Number(r.data[A]));c[f]=S-h}return s}function Co(r,t=null,e=null){let n=r.size,o=r.dtype,a=I(o)?"float64":o,i=Math.max(0,n-1),u=e?e.length:0,s=t?t.length:0,c=u+i+s,l=N.zeros([c],a),m=l.data,f=0;if(e)for(let p of e)m[f++]=p;for(let p=0;p<i;p++){let y=(I(o),Number(r.iget(p))),d=(I(o),Number(r.iget(p+1)));m[f++]=d-y}if(t)for(let p of t)m[f++]=p;return l}function Vo(r,t=1,e=null){let o=Array.from(r.shape).length,a;if(e===null)a=Array.from({length:o},(s,c)=>c);else if(typeof e=="number"){let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);a=[s]}else a=e.map(s=>{let c=s<0?o+s:s;if(c<0||c>=o)throw new Error(`axis ${s} is out of bounds for array of dimension ${o}`);return c});let i;if(typeof t=="number")i=a.map(()=>t);else{if(t.length!==a.length)throw new Error("Number of spacings must match number of axes");i=t}let u=[];for(let s=0;s<a.length;s++)u.push(qc(r,a[s],i[s]));return u.length===1?u[0]:u}function qc(r,t,e){let n=Array.from(r.shape),o=n.length,a=n[t];if(a<2)throw new Error(`Shape of array along axis ${t} must be at least 2, but got ${a}`);let i=r.dtype,u=I(i)?"float64":i==="float32"?"float32":"float64",s=N.zeros(n,u),c=s.data,l=r.strides,m=e,f=2*m,p=r.size;for(let y=0;y<p;y++){let d=y,g=new Array(o);for(let h=o-1;h>=0;h--)g[h]=d%n[h],d=Math.floor(d/n[h]);let b=g[t],A;if(b===0){let h=[...g];h[t]=1;let S=0;for(let w=0;w<o;w++)S+=h[w]*l[w];let D=(I(i),Number(r.data[y]));A=((I(i),Number(r.data[S]))-D)/m}else if(b===a-1){let h=[...g];h[t]=a-2;let S=0;for(let w=0;w<o;w++)S+=h[w]*l[w];let D=(I(i),Number(r.data[y])),x=(I(i),Number(r.data[S]));A=(D-x)/m}else{let h=[...g],S=[...g];h[t]=b+1,S[t]=b-1;let D=0,x=0;for(let B=0;B<o;B++)D+=h[B]*l[B],x+=S[B]*l[B];let w=(I(i),Number(r.data[D])),_=(I(i),Number(r.data[x]));A=(w-_)/f}c[y]=A}return s}function qo(r,t,e=-1,n=-1,o=-1){let a=Array.from(r.shape),i=Array.from(t.shape),u=a.length,s=i.length,c=e<0?u+e:e,l=n<0?s+n:n;if(c<0||c>=u)throw new Error(`axisa ${e} is out of bounds for array of dimension ${u}`);if(l<0||l>=s)throw new Error(`axisb ${n} is out of bounds for array of dimension ${s}`);let m=a[c],f=i[l];if(m!==2&&m!==3)throw new Error(`incompatible dimensions for cross product (dimension must be 2 or 3, got ${m})`);if(f!==2&&f!==3)throw new Error(`incompatible dimensions for cross product (dimension must be 2 or 3, got ${f})`);let p=k(r.dtype,t.dtype);if(u===1&&s===1&&m===3&&f===3){let y=N.zeros([3],p),d=y.data,g=Number(r.iget(0)),b=Number(r.iget(1)),A=Number(r.iget(2)),h=Number(t.iget(0)),S=Number(t.iget(1)),D=Number(t.iget(2));return d[0]=b*D-A*S,d[1]=A*h-g*D,d[2]=g*S-b*h,y}if(u===1&&s===1&&m===2&&f===2){let y=N.zeros([],p),d=Number(r.iget(0)),g=Number(r.iget(1)),b=Number(t.iget(0)),A=Number(t.iget(1));return y.data[0]=d*A-g*b,y}if(u===1&&s===1){if(m===2&&f===3){let y=N.zeros([3],p),d=y.data,g=Number(r.iget(0)),b=Number(r.iget(1)),A=Number(t.iget(0)),h=Number(t.iget(1)),S=Number(t.iget(2));return d[0]=b*S,d[1]=-g*S,d[2]=g*h-b*A,y}else if(m===3&&f===2){let y=N.zeros([3],p),d=y.data,g=Number(r.iget(0)),b=Number(r.iget(1)),A=Number(r.iget(2)),h=Number(t.iget(0)),S=Number(t.iget(1));return d[0]=-A*S,d[1]=A*h,d[2]=g*S-b*h,y}}if(u===2&&s===2&&c===1&&l===1){let y=a[0];if(i[0]!==y)throw new Error(`Shape mismatch: a has ${y} vectors, b has ${i[0]} vectors`);if(m===3&&f===3){let d=N.zeros([y,3],p),g=d.data;for(let b=0;b<y;b++){let A=Number(r.iget(b*3)),h=Number(r.iget(b*3+1)),S=Number(r.iget(b*3+2)),D=Number(t.iget(b*3)),x=Number(t.iget(b*3+1)),w=Number(t.iget(b*3+2));g[b*3]=h*w-S*x,g[b*3+1]=S*D-A*w,g[b*3+2]=A*x-h*D}return d}if(m===2&&f===2){let d=N.zeros([y],p),g=d.data;for(let b=0;b<y;b++){let A=Number(r.iget(b*2)),h=Number(r.iget(b*2+1)),S=Number(t.iget(b*2)),D=Number(t.iget(b*2+1));g[b]=A*D-h*S}return d}}throw new Error(`cross product not implemented for arrays with shapes ${JSON.stringify(a)} and ${JSON.stringify(i)}`)}var z=class r{constructor(t,e){this._storage=t,this._base=e}get storage(){return this._storage}static _fromStorage(t,e){return new r(t,e)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let e=t.map((n,o)=>{let a=n;if(a<0&&(a=this.shape[o]+a),a<0||a>=this.shape[o])throw new Error(`Index ${n} is out of bounds for axis ${o} with size ${this.shape[o]}`);return a});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let n=t.map((i,u)=>{let s=i;if(s<0&&(s=this.shape[u]+s),s<0||s>=this.shape[u])throw new Error(`Index ${i} is out of bounds for axis ${u} with size ${this.shape[u]}`);return s}),o=this.dtype,a;I(o)?a=typeof e=="bigint"?e:BigInt(Math.round(e)):o==="bool"?a=e?1:0:a=Number(e),this._storage.set(n,a)}copy(){return new r(this._storage.copy())}astype(t,e=!0){let n=this.dtype;if(n===t&&!e)return this;if(n===t&&e)return this.copy();let o=Array.from(this.shape),a=this.size,i=T(t);if(!i)throw new Error(`Cannot convert to dtype ${t}`);let u=new i(a),s=this.data;if(I(n)&&!I(t)){let l=s;if(t==="bool")for(let m=0;m<a;m++)u[m]=l[m]!==BigInt(0)?1:0;else for(let m=0;m<a;m++)u[m]=Number(l[m])}else if(!I(n)&&I(t)){let l=s;for(let m=0;m<a;m++)u[m]=BigInt(Math.round(Number(l[m])))}else if(t==="bool"){let l=s;for(let m=0;m<a;m++)u[m]=l[m]!==0?1:0}else if(n==="bool"&&!I(t)){let l=s;for(let m=0;m<a;m++)u[m]=l[m]}else if(!I(n)&&!I(t)){let l=s;for(let m=0;m<a;m++)u[m]=l[m]}else{let l=s;for(let m=0;m<a;m++)u[m]=l[m]}let c=N.fromData(u,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=ce(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=le(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=fe(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=me(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=Ir(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=Qr(this._storage,e);return r._fromStorage(n)}positive(){let t=ge(this._storage);return r._fromStorage(t)}reciprocal(){let t=he(this._storage);return r._fromStorage(t)}sqrt(){let t=xn(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=wn(this._storage,e);return r._fromStorage(n)}exp(){let t=In(this._storage);return r._fromStorage(t)}exp2(){let t=zn(this._storage);return r._fromStorage(t)}expm1(){let t=_n(this._storage);return r._fromStorage(t)}log(){let t=Bn(this._storage);return r._fromStorage(t)}log2(){let t=En(this._storage);return r._fromStorage(t)}log10(){let t=vn(this._storage);return r._fromStorage(t)}log1p(){let t=On(this._storage);return r._fromStorage(t)}logaddexp(t){let e=typeof t=="number"?t:t._storage,n=Un(this._storage,e);return r._fromStorage(n)}logaddexp2(t){let e=typeof t=="number"?t:t._storage,n=Tn(this._storage,e);return r._fromStorage(n)}absolute(){let t=pe(this._storage);return r._fromStorage(t)}negative(){let t=ye(this._storage);return r._fromStorage(t)}sign(){let t=de(this._storage);return r._fromStorage(t)}around(t=0){let e=Mt(this._storage,t);return r._fromStorage(e)}round(t=0){return this.around(t)}ceil(){let t=kt(this._storage);return r._fromStorage(t)}fix(){let t=Ct(this._storage);return r._fromStorage(t)}floor(){let t=Vt(this._storage);return r._fromStorage(t)}rint(){let t=qt(this._storage);return r._fromStorage(t)}trunc(){let t=Ft(this._storage);return r._fromStorage(t)}sin(){let t=$n(this._storage);return r._fromStorage(t)}cos(){let t=Mn(this._storage);return r._fromStorage(t)}tan(){let t=kn(this._storage);return r._fromStorage(t)}arcsin(){let t=Cn(this._storage);return r._fromStorage(t)}arccos(){let t=Vn(this._storage);return r._fromStorage(t)}arctan(){let t=qn(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=Fn(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=Pn(this._storage,e);return r._fromStorage(n)}degrees(){let t=jn(this._storage);return r._fromStorage(t)}radians(){let t=Rn(this._storage);return r._fromStorage(t)}sinh(){let t=Ln(this._storage);return r._fromStorage(t)}cosh(){let t=Zn(this._storage);return r._fromStorage(t)}tanh(){let t=Wn(this._storage);return r._fromStorage(t)}arcsinh(){let t=Gn(this._storage);return r._fromStorage(t)}arccosh(){let t=Hn(this._storage);return r._fromStorage(t)}arctanh(){let t=Yn(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=we(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=Ie(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=ze(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=_e(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=Be(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=Ee(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=Kr(this._storage,o,e,n);return r._fromStorage(a)}allclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage;return ve(this._storage,o,e,n)}bitwise_and(t){let e=typeof t=="number"?t:t._storage,n=Ao(this._storage,e);return r._fromStorage(n)}bitwise_or(t){let e=typeof t=="number"?t:t._storage,n=bo(this._storage,e);return r._fromStorage(n)}bitwise_xor(t){let e=typeof t=="number"?t:t._storage,n=So(this._storage,e);return r._fromStorage(n)}bitwise_not(){let t=Bt(this._storage);return r._fromStorage(t)}invert(){let t=No(this._storage);return r._fromStorage(t)}left_shift(t){let e=typeof t=="number"?t:t._storage,n=Do(this._storage,e);return r._fromStorage(n)}right_shift(t){let e=typeof t=="number"?t:t._storage,n=xo(this._storage,e);return r._fromStorage(n)}sum(t,e=!1){let n=pr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=zr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=_r(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=Br(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=rt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=tt(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=et(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=nt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=Ue(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=ot(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=at(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(st(this._storage,t))}cumprod(t){return r._fromStorage(it(this._storage,t))}ptp(t,e=!1){let n=ut(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=ct(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=lt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=sr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=Er(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=vr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=Or(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=Ur(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=yr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=ft(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=Tr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=$r(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=Mr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=kr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(mt(this._storage,t))}nancumprod(t){return r._fromStorage(pt(this._storage,t))}nanmedian(t,e=!1){let n=Cr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}sort(t=-1){return r._fromStorage(Et(this._storage,t))}argsort(t=-1){return r._fromStorage(vt(this._storage,t))}partition(t,e=-1){return r._fromStorage(Ot(this._storage,t,e))}argpartition(t,e=-1){return r._fromStorage(Ut(this._storage,t,e))}nonzero(){return Pr(this._storage).map(e=>r._fromStorage(e))}searchsorted(t,e="left"){return r._fromStorage(Tt(this._storage,t._storage,e))}diff(t=1,e=-1){return r._fromStorage(jt(this._storage,t,e))}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=P(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Vr(this._storage);return r._fromStorage(t)}ravel(){let t=ir(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=gr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=Te(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=dr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=$e(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=yt(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=Re(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=Qn(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;Xn(this._storage,t,n)}matmul(t){let e=G(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=ht(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return nn(this._storage)}inner(t){let e=on(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=At(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=an(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=Ae(this._storage);return r._fromStorage(t)}fabs(){let t=be(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=Se(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=Ne(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=De(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=xe(this._storage,e);return r._fromStorage(n)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);let e=t.map((s,c)=>{let l=oe(s);return ae(l,this.shape[c])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});let n=[],o=[],a=this._storage.offset;for(let s=0;s<e.length;s++){let c=e[s],l=this._storage.strides[s];if(a+=c.start*l,!c.isIndex){let m;c.step>0?m=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):m=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(m),o.push(l*c.step)}}let i=N.fromData(this._storage.data,n,this._storage.dtype,o,a),u=this._base??this;return new r(i,u)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let t=this.shape,e=t.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let i=[];for(let u=0;u<t[a];u++)o[a]=u,i.push(n(o,a+1));return i};return n(new Array(e),0)}};function J(r,t=q){let e=N.zeros(r,t);return new z(e)}function Rt(r,t=q){let e=N.ones(r,t);return new z(e)}function Pc(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function Fo(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>Fo(t)):!1}function jc(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function j(r,t){if(r instanceof z)return!t||r.dtype===t?r.copy():r.astype(t);let e=Fo(r),n=Pc(r),o=n.reduce((l,m)=>l*m,1),a=t;a||(e?a="int64":a=q);let i=T(a);if(!i)throw new Error(`Cannot create array with dtype ${a}`);let u=new i(o),s=jc(r);if(I(a)){let l=u;for(let m=0;m<o;m++){let f=s[m];l[m]=typeof f=="bigint"?f:BigInt(Math.round(Number(f)))}}else if(a==="bool"){let l=u;for(let m=0;m<o;m++)l[m]=s[m]?1:0}else{let l=u;for(let m=0;m<o;m++){let f=s[m];l[m]=Number(f)}}let c=N.fromData(u,n,a);return new z(c)}function Po(r,t,e=1,n=q){let o=r,a=t;if(t===void 0&&(o=0,a=r),a===void 0)throw new Error("stop is required");let i=Math.max(0,Math.ceil((a-o)/e)),u=T(n);if(!u)throw new Error(`Cannot create arange array with dtype ${n}`);let s=new u(i);if(I(n))for(let l=0;l<i;l++)s[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<i;l++)s[l]=o+l*e!==0?1:0;else for(let l=0;l<i;l++)s[l]=o+l*e;let c=N.fromData(s,[i],n);return new z(c)}function jo(r,t,e=50,n=q){if(e<0)throw new Error("num must be non-negative");if(e===0)return j([],n);if(e===1)return j([r],n);let o=T(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),i=(t-r)/(e-1);if(I(n))for(let s=0;s<e;s++)a[s]=BigInt(Math.round(r+s*i));else if(n==="bool")for(let s=0;s<e;s++)a[s]=r+s*i!==0?1:0;else for(let s=0;s<e;s++)a[s]=r+s*i;let u=N.fromData(a,[e],n);return new z(u)}function Ro(r,t,e=50,n=10,o=q){if(e<0)throw new Error("num must be non-negative");if(e===0)return j([],o);if(e===1)return j([Math.pow(n,r)],o);let a=T(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let i=new a(e),u=(t-r)/(e-1);if(I(o))for(let c=0;c<e;c++){let l=r+c*u;i[c]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let c=0;c<e;c++){let l=r+c*u;i[c]=Math.pow(n,l)!==0?1:0}else for(let c=0;c<e;c++){let l=r+c*u;i[c]=Math.pow(n,l)}let s=N.fromData(i,[e],o);return new z(s)}function Lo(r,t,e=50,n=q){if(e<0)throw new Error("num must be non-negative");if(r===0||t===0)throw new Error("Geometric sequence cannot include zero");if(e===0)return j([],n);if(e===1)return j([r],n);let o=Math.sign(r),a=Math.sign(t);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let i=T(n);if(!i)throw new Error(`Cannot create geomspace array with dtype ${n}`);let u=new i(e),s=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-s)/(e-1);if(I(n))for(let f=0;f<e;f++){let p=o*Math.exp(s+f*l);u[f]=BigInt(Math.round(p))}else if(n==="bool")for(let f=0;f<e;f++){let p=o*Math.exp(s+f*l);u[f]=p!==0?1:0}else for(let f=0;f<e;f++){let p=o*Math.exp(s+f*l);u[f]=p}let m=N.fromData(u,[e],n);return new z(m)}function Lt(r,t,e=0,n=q){let o=t??r,a=J([r,o],n),i=a.data;if(I(n)){let u=i;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(u[s*o+c]=BigInt(1))}}else{let u=i;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(u[s*o+c]=1)}}return a}function Zt(r,t=q){return J(r,t)}function Wt(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=q);let o=T(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((s,c)=>s*c,1),i=new o(a);if(I(n)){let s=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));i.fill(s)}else n==="bool"?i.fill(t?1:0):i.fill(Number(t));let u=N.fromData(i,r,n);return new z(u)}function Zo(r,t=q){return Lt(r,r,0,t)}function br(r,t){return r instanceof z?!t||r.dtype===t?r:r.astype(t):j(r,t)}function Wo(r){return r.copy()}function Go(r,t){return J(Array.from(r.shape),t??r.dtype)}function Ho(r,t){return Rt(Array.from(r.shape),t??r.dtype)}function Yo(r,t){return Zt(Array.from(r.shape),t??r.dtype)}function Jo(r,t,e){return Wt(Array.from(r.shape),t,e??r.dtype)}function Qo(r,t){return br(r,t)}function Xo(r,t){let e=br(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function Ko(r,t){return br(r,t).copy()}function Gt(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=J([n,n],r.dtype);for(let a=0;a<e;a++){let i=t>=0?a:a-t,u=t>=0?a+t:a;o.set([i,u],r.get([a]))}return o}else if(r.ndim===2){let[e,n]=r.shape,o,a,i;if(t>=0?(o=0,a=t,i=Math.min(e,n-t)):(o=-t,a=0,i=Math.min(e+t,n)),i<=0)return J([0],r.dtype);let u=T(r.dtype),s=new u(i);for(let l=0;l<i;l++){let m=r.get([o+l,a+l]);I(r.dtype)?s[l]=typeof m=="bigint"?m:BigInt(m):s[l]=m}let c=N.fromData(s,[i],r.dtype);return new z(c)}else throw new Error("Input must be 1-D or 2-D")}function ra(r,t=0){let e=r.flatten();return Gt(e,t)}function ta(r,t,e=q){let n=t.reduce((c,l)=>c*l,1),o=T(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),i=t.length,u=new Array(i).fill(0);for(let c=0;c<n;c++){let l=r(...u);I(e)?a[c]=typeof l=="bigint"?l:BigInt(Number(l)):e==="bool"?a[c]=l?1:0:a[c]=Number(l);for(let m=i-1;m>=0&&(u[m]++,!(u[m]<t[m]));m--)u[m]=0}let s=N.fromData(a,t,e);return new z(s)}function ea(...r){let t=[],e="xy";for(let u of r)u instanceof z?t.push(u):typeof u=="object"&&"indexing"in u&&(e=u.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(u=>u.size);e==="xy"&&t.length>=2&&(t=[t[1],t[0],...t.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,i=[];for(let u=0;u<t.length;u++){let s=t[u],c=s.size,l=new Array(a).fill(1);l[u]=c;let m=s.reshape(...l),f=wt(m.storage,o),p=z._fromStorage(f.copy());i.push(p)}return e==="xy"&&i.length>=2&&([i[0],i[1]]=[i[1],i[0]]),i}function na(r,t,e=0,n=q){let o=t??r,a=J([r,o],n);for(let i=0;i<r;i++)for(let u=0;u<=i+e&&u<o;u++)u>=0&&a.set([i,u],1);return a}function oa(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],i=n.slice(0,-2).reduce((u,s)=>u*s,1);for(let u=0;u<i;u++)for(let s=0;s<o;s++)for(let c=0;c<a;c++)if(c>s+t){let l=[],m=u;for(let f=n.length-3;f>=0;f--)l.unshift(m%n[f]),m=Math.floor(m/n[f]);l.push(s,c),e.set(l,0)}return e}function aa(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],i=n.slice(0,-2).reduce((u,s)=>u*s,1);for(let u=0;u<i;u++)for(let s=0;s<o;s++)for(let c=0;c<a;c++)if(c<s+t){let l=[],m=u;for(let f=n.length-3;f>=0;f--)l.unshift(m%n[f]),m=Math.floor(m/n[f]);l.push(s,c),e.set(l,0)}return e}function sa(r,t,e=!1){if(r.ndim!==1)throw new Error("Input must be 1-D");let n=r.size,o=t??n;if(o<0)throw new Error("N must be non-negative");let a=J([n,o],r.dtype);for(let i=0;i<n;i++){let u=r.get([i]);for(let s=0;s<o;s++){let c=e?s:o-1-s;a.set([i,s],Math.pow(u,c))}}return a}function ia(r,t=q,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let i=Rc(t),u=o.byteLength-a,s=Math.floor(u/i),c=e<0?s:Math.min(e,s);if(c<=0)return j([],t);let l=T(t);if(!l)throw new Error(`Unsupported dtype: ${t}`);let m=new l(o,a,c),f=N.fromData(m,[c],t);return new z(f)}function ua(r,t=q,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return j(n,t)}function ca(r,t=q,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return j(n,t)}function la(r,t=q,e=-1,n=""){let o;n===""?o=r.trim().split(/\s+/):o=r.split(n);let a=[],i=0;for(let u of o){if(e>=0&&i>=e)break;let s=u.trim();s!==""&&(I(t)?a.push(BigInt(s)):a.push(parseFloat(s)),i++)}return j(a,t)}function Rc(r){switch(r){case"int8":case"uint8":case"bool":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;case"int64":case"uint64":case"float64":return 8;default:return 8}}function fa(r){return r.sqrt()}function ma(r,t){return r.power(t)}function pa(r){return r.exp()}function ya(r){return r.exp2()}function da(r){return r.expm1()}function ga(r){return r.log()}function ha(r){return r.log2()}function Aa(r){return r.log10()}function ba(r){return r.log1p()}function Sa(r,t){return r.logaddexp(t)}function Na(r,t){return r.logaddexp2(t)}function Da(r){return r.absolute()}function xa(r){return r.negative()}function wa(r){return r.sign()}function Ia(r,t){return r.mod(t)}function za(r,t){return r.floor_divide(t)}function _a(r){return r.positive()}function Ba(r){return r.reciprocal()}function Ea(r,t){return r.dot(t)}function va(r){return r.trace()}function Oa(r,t=0,e=0,n=1){let o=sn(r.storage,t,e,n);return z._fromStorage(o)}function Ua(r,t){let e=cn(r.storage,t.storage);return z._fromStorage(e)}function Ta(r,t){return r.transpose(t)}function $a(r,t){return r.inner(t)}function Ma(r,t){return r.outer(t)}function ka(r,t,e=2){return r.tensordot(t,e)}function Ca(r){return r.sin()}function Va(r){return r.cos()}function qa(r){return r.tan()}function Fa(r){return r.arcsin()}function Pa(r){return r.arccos()}function ja(r){return r.arctan()}function Ra(r,t){return r.arctan2(t)}function La(r,t){return r.hypot(t)}function Za(r){return r.degrees()}function Wa(r){return r.radians()}function Ga(r){return r.radians()}function Ha(r){return r.degrees()}function Ya(r){return r.sinh()}function Ja(r){return r.cosh()}function Qa(r){return r.tanh()}function Xa(r){return r.arcsinh()}function Ka(r){return r.arccosh()}function rs(r){return r.arctanh()}function ts(r,t,e){return r.swapaxes(t,e)}function es(r,t,e){return r.moveaxis(t,e)}function or(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");let e=r.map(o=>o.storage),n=er(e,t);return z._fromStorage(n)}function ns(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r.map(o=>o.storage),n=Me(e,t);return z._fromStorage(n)}function Ht(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=ke(t);return z._fromStorage(e)}function os(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=dt(t);return z._fromStorage(e)}function as(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Ce(t);return z._fromStorage(e)}function ss(r,t,e=0){return Ve(r.storage,t,e).map(o=>z._fromStorage(o,r.base??r))}function is(r,t,e=0){return hr(r.storage,t,e).map(o=>z._fromStorage(o,r.base??r))}function us(r,t){return Fe(r.storage,t).map(n=>z._fromStorage(n,r.base??r))}function cs(r,t){return Pe(r.storage,t).map(n=>z._fromStorage(n,r.base??r))}function ls(r,t){let e=je(r.storage,t);return z._fromStorage(e)}function fs(r,t,e){return r.repeat(t,e)}function ms(r){return r.ravel()}function ps(r,t){return r.reshape(...t)}function ys(r,t){return r.squeeze(t)}function ds(r,t){return r.expand_dims(t)}function jr(r,t){let e=Le(r.storage,t);return z._fromStorage(e)}function gs(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return jr(r,1)}function hs(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return jr(r,0)}function As(r,t=1,e=[0,1]){let n=Ze(r.storage,t,e);return z._fromStorage(n)}function bs(r,t,e){let n=We(r.storage,t,e);return z._fromStorage(n)}function Ss(r,t,e=0){let n=Ge(r.storage,t,e);return z._fromStorage(n,r.base??r)}function Ns(...r){let t=r.map(o=>o.storage),n=Qe(t).map((o,a)=>o===t[a]?r[a]:z._fromStorage(o));return n.length===1?n[0]:n}function Ds(...r){let t=r.map(o=>o.storage),n=Xe(t).map((o,a)=>o===t[a]?r[a]:z._fromStorage(o));return n.length===1?n[0]:n}function xs(...r){let t=r.map(o=>o.storage),n=Ke(t).map((o,a)=>o===t[a]?r[a]:z._fromStorage(o));return n.length===1?n[0]:n}function ws(r,t){return He(r.storage,t).map(n=>z._fromStorage(n,r.base??r))}function Is(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Ye(t);return z._fromStorage(e)}function zs(r){return Ht(r)}function _s(r,t){let e=Je(r.storage,t);return z._fromStorage(e)}function Bs(r,t,e){let n=t instanceof z?t:j(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return or([o,a])}return or([r,n],e)}function Es(r,t,e){let n=r.dtype;if(e===void 0){let p=r.flatten(),d=(Array.isArray(t)?t:[t]).map(S=>S<0?p.size+S:S),g=[];for(let S=0;S<p.size;S++)d.includes(S)||g.push(S);let b=T(n),A=new b(g.length);for(let S=0;S<g.length;S++){let D=p.get([g[S]]);I(n)?A[S]=typeof D=="bigint"?D:BigInt(D):A[S]=D}let h=N.fromData(A,[g.length],n);return new z(h)}let o=r.shape,a=o.length,i=e<0?a+e:e;if(i<0||i>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let u=o[i],s=Array.isArray(t)?t:[t],c=new Set(s.map(p=>p<0?u+p:p)),l=[],m=0;for(let p=0;p<=u;p++)(c.has(p)||p===u)&&(p>m&&l.push([m,p]),m=p+1);if(l.length===0){let p=[...o];return p[i]=0,J(p,n)}let f=[];for(let[p,y]of l){let d=o.map(()=>":");d[i]=`${p}:${y}`,f.push(r.slice(...d))}return or(f,i)}function vs(r,t,e,n){let o=e instanceof z?e:j(e,r.dtype);if(n===void 0){let m=r.flatten(),f=o.flatten(),p=t<0?m.size+t:t;if(p<0||p>m.size)throw new Error(`index ${t} is out of bounds for array of size ${m.size}`);let y=p>0?m.slice(`0:${p}`):null,d=p<m.size?m.slice(`${p}:`):null,g=[];return y&&g.push(y),g.push(f),d&&g.push(d),or(g)}let a=r.shape,i=a.length,u=n<0?i+n:n;if(u<0||u>=i)throw new Error(`axis ${n} is out of bounds for array of dimension ${i}`);let s=a[u],c=t<0?s+t:t;if(c<0||c>s)throw new Error(`index ${t} is out of bounds for axis ${n} with size ${s}`);let l=[];if(c>0){let m=a.map(()=>":");m[u]=`0:${c}`,l.push(r.slice(...m))}if(l.push(o),c<s){let m=a.map(()=>":");m[u]=`${c}:`,l.push(r.slice(...m))}return or(l,u)}function Os(r,t,e="constant",n=0){let o=r.shape,a=o.length,i=r.dtype,u;if(typeof t=="number"?u=o.map(()=>[t,t]):Array.isArray(t)&&typeof t[0]=="number"?u=o.map(()=>t):u=t,u.length!==a)throw new Error(`pad_width must have ${a} elements`);let s=o.map((d,g)=>d+u[g][0]+u[g][1]),c=s.reduce((d,g)=>d*g,1),l=T(i),m=new l(c),f=I(i);e==="constant"&&(f?m.fill(BigInt(n)):m.fill(n));let p=new Array(a).fill(0);for(let d=0;d<c;d++){let g=!0,b=[];for(let h=0;h<a;h++){let[S]=u[h],D=p[h]-S;if(D<0||D>=o[h]){g=!1;break}b.push(D)}let A;if(g)A=r.get(b);else if(e==="constant"){for(let h=a-1;h>=0&&(p[h]++,!(p[h]<s[h]));h--)p[h]=0;continue}else{let h=[];for(let S=0;S<a;S++){let[D]=u[S],x=p[S]-D,w=o[S];x<0?e==="edge"?x=0:e==="reflect"?(x=-x,x>=w&&(x=w-1)):e==="symmetric"?(x=-x-1,x>=w&&(x=w-1),x<0&&(x=0)):e==="wrap"&&(x=(x%w+w)%w):x>=w&&(e==="edge"?x=w-1:e==="reflect"?(x=2*w-x-2,x<0&&(x=0)):e==="symmetric"?(x=2*w-x-1,x<0&&(x=0)):e==="wrap"&&(x=x%w)),h.push(Math.max(0,Math.min(w-1,x)))}A=r.get(h)}f?m[d]=typeof A=="bigint"?A:BigInt(Number(A)):m[d]=Number(A);for(let h=a-1;h>=0&&(p[h]++,!(p[h]<s[h]));h--)p[h]=0}let y=N.fromData(m,s,i);return new z(y)}function Us(r,t){let e=wt(r.storage,t);return z._fromStorage(e,r.base??r)}function Ts(...r){let t=r.map(n=>n.storage);return Jn(t).map((n,o)=>z._fromStorage(n,r[o].base??r[o]))}function $s(...r){return Xr(...r)}function Ms(r,t,e){return r.take(t,e)}function ks(r,t,e){r.put(t,e)}function Cs(r,t){let e=t.map(o=>o.storage),n=Kn(r.storage,e);return z._fromStorage(n)}function Vs(r,t,e=!1){return ro(r.storage,t.storage,e)}function qs(r,t){return Oe(r.storage,t.storage)}function Fs(r,t){return z._fromStorage(st(r.storage,t))}function Ps(r,t){return z._fromStorage(it(r.storage,t))}function js(r,t,e=!1){let n=ut(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function Rs(r,t,e=!1){let n=ct(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function Ls(r,t,e,n=!1){let o=lt(r.storage,t,e,n);return typeof o=="number"?o:z._fromStorage(o)}function Zs(r,t,e,n=!1){let o=sr(r.storage,t,e,n);return typeof o=="number"?o:z._fromStorage(o)}function Ws(r,t,e,n=!1){let o=e?e.storage:void 0,a=Er(r.storage,t,o,n);return typeof a=="number"?a:z._fromStorage(a)}function Gs(r,t,e=!1){let n=vr(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function Hs(r,t,e=!1){let n=Or(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function Ys(r,t,e=!1){let n=Ur(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function Js(r,t,e=0,n=!1){let o=yr(r.storage,t,e,n);return typeof o=="number"?o:z._fromStorage(o)}function Qs(r,t,e=0,n=!1){let o=ft(r.storage,t,e,n);return typeof o=="number"?o:z._fromStorage(o)}function Xs(r,t,e=!1){let n=Tr(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function Ks(r,t,e=!1){let n=$r(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function ri(r,t){let e=Mr(r.storage,t);return typeof e=="number"?e:z._fromStorage(e)}function ti(r,t){let e=kr(r.storage,t);return typeof e=="number"?e:z._fromStorage(e)}function ei(r,t){return z._fromStorage(mt(r.storage,t))}function ni(r,t){return z._fromStorage(pt(r.storage,t))}function oi(r,t,e=!1){let n=Cr(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)}function ai(r){return r.cbrt()}function si(r){return r.fabs()}function ii(r,t){return r.divmod(t)}function ui(r){return r.square()}function ci(r,t){return r.remainder(t)}function li(r,t){return r.heaviside(t)}function fi(r,t){return r.bitwise_and(t)}function mi(r,t){return r.bitwise_or(t)}function pi(r,t){return r.bitwise_xor(t)}function yi(r){return r.bitwise_not()}function di(r){return r.invert()}function gi(r,t){return r.left_shift(t)}function hi(r,t){return r.right_shift(t)}function Ai(r,t=-1,e="big"){let n=wo(r.storage,t,e);return z._fromStorage(n)}function bi(r,t=-1,e=-1,n="big"){let o=Io(r.storage,t,e,n);return z._fromStorage(o)}function Si(r,...t){let e=t.map(o=>o.storage),n=un(r,...e);return typeof n=="number"||typeof n=="bigint"?n:z._fromStorage(n)}var Ni={cross:(r,t,e=-1,n=-1,o=-1,a)=>{let i=ln(r.storage,t.storage,e,n,o,a);return typeof i=="number"?i:z._fromStorage(i)},norm:(r,t=null,e=null,n=!1)=>{let o=fn(r.storage,t,e,n);return typeof o=="number"?o:z._fromStorage(o)},vector_norm:(r,t=2,e,n=!1)=>{let o=ur(r.storage,t,e,n);return typeof o=="number"?o:z._fromStorage(o)},matrix_norm:(r,t="fro",e=!1)=>{let n=nr(r.storage,t,e);return typeof n=="number"?n:z._fromStorage(n)},qr:(r,t="reduced")=>{let e=bt(r.storage,t);return e instanceof N?z._fromStorage(e):"q"in e&&"r"in e?{q:z._fromStorage(e.q),r:z._fromStorage(e.r)}:{h:z._fromStorage(e.h),tau:z._fromStorage(e.tau)}},cholesky:(r,t=!1)=>z._fromStorage(mn(r.storage,t)),svd:(r,t=!0,e=!0)=>{let n=pn(r.storage,t,e);return"u"in n?{u:z._fromStorage(n.u),s:z._fromStorage(n.s),vt:z._fromStorage(n.vt)}:z._fromStorage(n)},det:r=>yn(r.storage),inv:r=>z._fromStorage(qr(r.storage)),solve:(r,t)=>z._fromStorage(dn(r.storage,t.storage)),lstsq:(r,t,e=null)=>{let n=gn(r.storage,t.storage,e);return{x:z._fromStorage(n.x),residuals:z._fromStorage(n.residuals),rank:n.rank,s:z._fromStorage(n.s)}},cond:(r,t=2)=>hn(r.storage,t),matrix_rank:(r,t)=>An(r.storage,t),matrix_power:(r,t)=>z._fromStorage(bn(r.storage,t)),pinv:(r,t=1e-15)=>z._fromStorage(Sn(r.storage,t)),eig:r=>{let t=Dt(r.storage);return{w:z._fromStorage(t.w),v:z._fromStorage(t.v)}},eigh:(r,t="L")=>{let e=xt(r.storage,t);return{w:z._fromStorage(e.w),v:z._fromStorage(e.v)}},eigvals:r=>z._fromStorage(Nn(r.storage)),eigvalsh:(r,t="L")=>z._fromStorage(Dn(r.storage,t))};function Di(r,t,e){return z._fromStorage(to(r.storage,t.storage,e))}function xi(r,t,e,n){eo(r.storage,t.storage,e.storage,n)}function wi(r,t,e){let n=e instanceof z?e.storage:e;no(r.storage,t.storage,n)}function Ii(r,t,e){return z._fromStorage(oo(r.storage,t.storage,e))}function zi(r,t,e=0){let n=r.map(a=>a.storage),o=t.map(a=>a.storage);return z._fromStorage(ao(n,o,e))}function _i(r,t,e){so(r.storage,t.storage,e.storage)}function Bi(r,t=2){return It(r,t).map(n=>z._fromStorage(n))}function Ei(r){return io(r.storage).map(e=>z._fromStorage(e))}function vi(r,t=0,e){return zt(r,t,e).map(o=>z._fromStorage(o))}function Oi(r,t=0){return uo(r.storage,t).map(n=>z._fromStorage(n))}function Ui(r,t=0,e){return _t(r,t,e).map(o=>z._fromStorage(o))}function Ti(r,t=0){return co(r.storage,t).map(n=>z._fromStorage(n))}function $i(r,t,e=0){return lo(r,(a,i)=>t(a,i).storage,e).map(a=>z._fromStorage(a))}function Mi(r,t="int32"){return z._fromStorage(fo(r,t))}function ki(...r){return mo(...r.map(e=>e.storage)).map(e=>z._fromStorage(e))}function Ci(r,t,e="raise"){let n=r.map(o=>o.storage);return z._fromStorage(po(n,t,e))}function Vi(r,t,e="C"){let n=r instanceof z?r.storage:r;return yo(n,t,e).map(a=>z._fromStorage(a))}function qi(r,t=-1){return z._fromStorage(Et(r.storage,t))}function Fi(r,t=-1){return z._fromStorage(vt(r.storage,t))}function Pi(r){let t=r.map(e=>e.storage);return z._fromStorage(zo(t))}function ji(r,t,e=-1){return z._fromStorage(Ot(r.storage,t,e))}function Ri(r,t,e=-1){return z._fromStorage(Ut(r.storage,t,e))}function Li(r){return z._fromStorage(_o(r.storage))}function Zi(r){return Pr(r.storage).map(e=>z._fromStorage(e))}function Wi(r){return z._fromStorage(Bo(r.storage))}function Gi(r,t,e){let n=Eo(r.storage,t?.storage,e?.storage);return Array.isArray(n)?n.map(o=>z._fromStorage(o)):z._fromStorage(n)}function Hi(r,t,e="left"){return z._fromStorage(Tt(r.storage,t.storage,e))}function Yi(r,t){return z._fromStorage(vo(r.storage,t.storage))}function Ji(r,t){let e=$t(r.storage,t);return typeof e=="number"?e:z._fromStorage(e)}function Yt(r,t=0){return z._fromStorage(Mt(r.storage,t))}function Qi(r){return z._fromStorage(kt(r.storage))}function Xi(r){return z._fromStorage(Ct(r.storage))}function Ki(r){return z._fromStorage(Vt(r.storage))}function ru(r){return z._fromStorage(qt(r.storage))}function tu(r){return z._fromStorage(Ft(r.storage))}function eu(r,t=!1,e=!1,n=!1){let o=X(r.storage,t,e,n);if(o instanceof N)return z._fromStorage(o);let a={values:z._fromStorage(o.values)};return o.indices&&(a.indices=z._fromStorage(o.indices)),o.inverse&&(a.inverse=z._fromStorage(o.inverse)),o.counts&&(a.counts=z._fromStorage(o.counts)),a}function nu(r,t){return z._fromStorage(Uo(r.storage,t.storage))}function ou(r,t){return z._fromStorage(To(r.storage,t.storage))}function au(r,t){return z._fromStorage(Pt(r.storage,t.storage))}function su(r,t){return z._fromStorage($o(r.storage,t.storage))}function iu(r,t){return z._fromStorage(Mo(r.storage,t.storage))}function uu(r,t){return z._fromStorage(ko(r.storage,t.storage))}function cu(r,t=1,e=-1){return z._fromStorage(jt(r.storage,t,e))}function lu(r,t=null,e=null){return z._fromStorage(Co(r.storage,t,e))}function fu(r,t=1,e=null){let n=Vo(r.storage,t,e);return Array.isArray(n)?n.map(o=>z._fromStorage(o)):z._fromStorage(n)}function mu(r,t,e=-1,n=-1,o=-1){return z._fromStorage(qo(r.storage,t.storage,e,n,o))}var Sr=new Uint8Array([147,78,85,77,80,89]),Rr=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];function Jt(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}var Lc={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},Nr={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},pu={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};function yu(r){if(r.startsWith("[")||r.startsWith("("))throw new Q(`Structured/compound dtypes are not supported: ${r}`);let t="",e=r;(r[0]==="<"||r[0]===">"||r[0]==="="||r[0]==="|")&&(t=r[0],e=r.slice(1));let n=e[0];if(n&&n in pu)throw new Q(`Unsupported dtype: ${pu[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Lc[e];if(!o)throw new Q(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Rr.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Jt(),i=t==="<"||t==="|"||t==="="&&a,u=t===">"||t==="="&&!a,s=parseInt(e.slice(1),10),c=s>1&&(u&&a||i&&!a);return{dtype:o,needsByteSwap:c,itemsize:s}}var Q=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},Z=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}};function Dr(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Lr(t);return Zr(t,e)}function Lr(r){if(r.length<10)throw new Z("File too small to be a valid NPY file");for(let c=0;c<Sr.length;c++)if(r[c]!==Sr[c])throw new Z("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new Z(`Unsupported NPY version: ${t}.${e}`);let n,o;t===1?(n=r[8]|r[9]<<8,o=10):(n=r[8]|r[9]<<8|r[10]<<16|r[11]<<24,o=12);let a=o+n;if(r.length<a)throw new Z("File truncated: header extends beyond file");let i=r.slice(o,a),u=new TextDecoder("utf-8").decode(i).trim(),s=Zc(u);return{version:{major:t,minor:e},header:s,dataOffset:a}}function Zr(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:i}=yu(e.descr),u=e.shape.reduce((d,g)=>d*g,1),s=u*i,c=r.length-n;if(c<s)throw new Z(`File truncated: expected ${s} bytes of data, got ${c}`);let l=new ArrayBuffer(s);new Uint8Array(l).set(r.subarray(n,n+s));let f=Wc(l,o,u,a,i),p=e.shape,y;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),g=N.fromData(f,d,o);y=Gc(g,d),p=e.shape}else y=N.fromData(f,[...p],o);return new z(y)}function Zc(r){let t=r.match(/'descr'\s*:\s*'([^']+)'/),e=r.match(/'fortran_order'\s*:\s*(True|False)/),n=r.match(/'shape'\s*:\s*\(([^)]*)\)/);if(!t||!e||!n)throw new Z(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",i=n[1].trim(),u;return i===""?u=[]:u=i.split(",").map(s=>s.trim()).filter(s=>s!=="").map(s=>{let c=parseInt(s,10);if(isNaN(c))throw new Z(`Invalid shape value: ${s}`);return c}),{descr:o,fortran_order:a,shape:u}}function Wc(r,t,e,n,o){let a=T(t);if(!a)throw new Z(`Cannot create array for dtype: ${t}`);if(!n)return new a(r,0,e);let i=new Uint8Array(r),u=new Uint8Array(r.byteLength);for(let s=0;s<e;s++){let c=s*o;for(let l=0;l<o;l++)u[c+l]=i[c+o-1-l]}return new a(u.buffer,0,e)}function Gc(r,t){let e=t.length,n=r.size,o=r.dtype,a=T(o);if(!a)throw new Z(`Cannot create array for dtype: ${o}`);let i=new a(n),u=[...t].reverse(),s=du(t),c=du(u),l=new Array(e).fill(0);for(let m=0;m<n;m++){let f=m;for(let y=0;y<e;y++){let d=s[y];l[y]=Math.floor(f/d),f=f%d}let p=0;for(let y=0;y<e;y++)p+=l[e-1-y]*c[y];I(o),i[p]=r.iget(m)}return N.fromData(i,u,o)}function du(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}function cr(r){let t=r.shape,e=r.dtype,n=Nr[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,i=12,s=(64-(i+a.length+1)%64)%64;a=a+" ".repeat(s)+`
2
- `;let c=new TextEncoder().encode(a),l=c.length,m=r.size,f=ie(e),p=m*f,y=i+l+p,d=new Uint8Array(y);d.set(Sr,0),d[6]=3,d[7]=0,d[8]=l&255,d[9]=l>>8&255,d[10]=l>>16&255,d[11]=l>>24&255,d.set(c,i);let g=i+l;return Hc(r,d.subarray(g),f),d}function Hc(r,t,e){let n=r.dtype,o=r.size,a=Jt(),i=I(n),u=r._storage;if(u.isCContiguous&&u.offset===0&&a){let c=u.data,l=new Uint8Array(c.buffer,c.byteOffset,o*e);t.set(l)}else{let c=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let l=0;l<o;l++){let m=u.iget(l),f=l*e;i?Yc(c,f,m,n==="uint64"):Jc(c,f,m,n)}}}function Yc(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Jc(r,t,e,n){switch(n){case"float64":r.setFloat64(t,e,!0);break;case"float32":r.setFloat32(t,e,!0);break;case"int32":r.setInt32(t,e,!0);break;case"int16":r.setInt16(t,e,!0);break;case"int8":r.setInt8(t,e);break;case"uint32":r.setUint32(t,e,!0);break;case"uint16":r.setUint16(t,e,!0);break;case"uint8":case"bool":r.setUint8(t,e);break;default:throw new Error(`Unsupported dtype for serialization: ${n}`)}}var Qc=(()=>{let r=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;r[t]=e}return r})();function Qt(r){let t=4294967295;for(let e=0;e<r.length;e++)t=Qc[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}async function gu(r){let t=Au(r),e=new Map;for(let n of t){let o=await Xc(n);e.set(n.name,o)}return e}function hu(r){let t=Au(r),e=new Map;for(let n of t){if(n.compressionMethod!==0)throw new Error(`Cannot read compressed entry synchronously: ${n.name}. Use readZip() (async) for DEFLATE-compressed files.`);e.set(n.name,n.compressedData)}return e}function Au(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=[],o=-1;for(let c=t.length-22;c>=0;c--)if(e.getUint32(c,!0)===101010256){o=c;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),i=e.getUint16(o+10,!0),u=[],s=a;for(let c=0;c<i&&e.getUint32(s,!0)===33639248;c++){let m=e.getUint16(s+10,!0),f=e.getUint32(s+16,!0),p=e.getUint32(s+20,!0),y=e.getUint32(s+24,!0),d=e.getUint16(s+28,!0),g=e.getUint16(s+30,!0),b=e.getUint16(s+32,!0),A=e.getUint32(s+42,!0),h=t.slice(s+46,s+46+d),S=new TextDecoder("utf-8").decode(h);u.push({name:S,compressionMethod:m,crc32:f,compressedSize:p,uncompressedSize:y,localHeaderOffset:A}),s=s+46+d+g+b}for(let c of u){let l=c.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let f=e.getUint16(l+26,!0),p=e.getUint16(l+28,!0),y=l+30+f+p,d=t.slice(y,y+c.compressedSize);n.push({name:c.name,compressedData:d,compressionMethod:c.compressionMethod,crc32:c.crc32,compressedSize:c.compressedSize,uncompressedSize:c.uncompressedSize})}return n}async function Xc(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Kc(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Kc(r){if(typeof DecompressionStream>"u")throw new Error("DecompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new DecompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let i=a.reduce((c,l)=>c+l.length,0),u=new Uint8Array(i),s=0;for(let c of a)u.set(c,s),s+=c.length;return u}async function Wr(r,t={}){let e=t.force??!1,n=await gu(r);return bu(n,e)}function Gr(r,t={}){let e=t.force??!1,n=hu(r);return bu(n,e)}function bu(r,t){let e=new Map,n=[],o=new Map;for(let[a,i]of r){if(!a.endsWith(".npy"))continue;let u=a.slice(0,-4);try{let s=Dr(i);e.set(u,s)}catch(s){if(s instanceof Q&&t)n.push(u),o.set(u,s.message);else throw s}}return{arrays:e,skipped:n,errors:o}}async function re(r,t={}){let e=await Wr(r,t);return Object.fromEntries(e.arrays)}function te(r,t={}){let e=Gr(r,t);return Object.fromEntries(e.arrays)}async function Su(r,t={}){let e=t.compress??!1,n=[];for(let[f,p]of r){let y=Qt(p),d,g;e?(d=await tl(p),d.length<p.length?g=8:(d=p,g=0)):(d=p,g=0),n.push({name:f,data:p,compressedData:d,crc:y,compressionMethod:g,offset:0})}let o=0;for(let f of n){let p=new TextEncoder().encode(f.name);o+=30+p.length+f.compressedData.length}let a=0;for(let f of n){let p=new TextEncoder().encode(f.name);a+=46+p.length}let u=o+a+22,s=new Uint8Array(u),c=new DataView(s.buffer),l=0;for(let f of n)f.offset=l,l=Du(s,c,l,f);let m=l;for(let f of n)l=xu(s,c,l,f);return wu(c,l,n.length,a,m),s}function Nu(r){let t=[];for(let[l,m]of r){let f=Qt(m);t.push({name:l,data:m,compressedData:m,crc:f,compressionMethod:0,offset:0})}let e=0;for(let l of t){let m=new TextEncoder().encode(l.name);e+=30+m.length+l.compressedData.length}let n=0;for(let l of t){let m=new TextEncoder().encode(l.name);n+=46+m.length}let a=e+n+22,i=new Uint8Array(a),u=new DataView(i.buffer),s=0;for(let l of t)l.offset=s,s=Du(i,u,s,l);let c=s;for(let l of t)s=xu(i,u,s,l);return wu(u,s,t.length,n,c),i}function Du(r,t,e,n){let o=new TextEncoder().encode(n.name);return t.setUint32(e,67324752,!0),e+=4,t.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,n.compressionMethod,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,33,!0),e+=2,t.setUint32(e,n.crc,!0),e+=4,t.setUint32(e,n.compressedData.length,!0),e+=4,t.setUint32(e,n.data.length,!0),e+=4,t.setUint16(e,o.length,!0),e+=2,t.setUint16(e,0,!0),e+=2,r.set(o,e),e+=o.length,r.set(n.compressedData,e),e+=n.compressedData.length,e}function xu(r,t,e,n){let o=new TextEncoder().encode(n.name);return t.setUint32(e,33639248,!0),e+=4,t.setUint16(e,20,!0),e+=2,t.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,n.compressionMethod,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,33,!0),e+=2,t.setUint32(e,n.crc,!0),e+=4,t.setUint32(e,n.compressedData.length,!0),e+=4,t.setUint32(e,n.data.length,!0),e+=4,t.setUint16(e,o.length,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint32(e,0,!0),e+=4,t.setUint32(e,n.offset,!0),e+=4,r.set(o,e),e+=o.length,e}function wu(r,t,e,n,o){r.setUint32(t,101010256,!0),t+=4,r.setUint16(t,0,!0),t+=2,r.setUint16(t,0,!0),t+=2,r.setUint16(t,e,!0),t+=2,r.setUint16(t,e,!0),t+=2,r.setUint32(t,n,!0),t+=4,r.setUint32(t,o,!0),t+=4,r.setUint16(t,0,!0)}async function tl(r){if(typeof CompressionStream>"u")throw new Error("CompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new CompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let i=a.reduce((c,l)=>c+l.length,0),u=new Uint8Array(i),s=0;for(let c of a)u.set(c,s),s+=c.length;return u}async function ee(r,t={}){let e=Iu(r);return Su(e,{compress:t.compress??!1})}function ne(r){let t=Iu(r);return Nu(t)}function Iu(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=cr(o);t.set(`arr_${n}.npy`,a)}return t}let e=r instanceof Map?r.entries():Object.entries(r);for(let[n,o]of e){if(typeof n!="string"||n.length===0)throw new Error("Array names must be non-empty strings");let a=cr(o),i=n.endsWith(".npy")?n:`${n}.npy`;t.set(i,a)}return t}var sl="0.9.0";return Mu(il);})();
1
+ "use strict";var np=(()=>{var Zt=Object.defineProperty;var Yf=Object.getOwnPropertyDescriptor;var Hf=Object.getOwnPropertyNames;var Jf=Object.prototype.hasOwnProperty;var Xf=(r,t)=>{for(var e in t)Zt(r,e,{get:t[e],enumerable:!0})},Qf=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Hf(t))!Jf.call(r,o)&&o!==e&&Zt(r,o,{get:()=>t[o],enumerable:!(n=Yf(t,o))||n.enumerable});return r};var Kf=r=>Qf(Zt({},"__esModule",{value:!0}),r);var sp={};Xf(sp,{Complex:()=>O,DTYPE_TO_DESCR:()=>ut,InvalidNpyError:()=>sr,NDArray:()=>v,SUPPORTED_DTYPES:()=>Mt,UnsupportedDTypeError:()=>xr,__version__:()=>ap,abs:()=>He,absolute:()=>He,acos:()=>Qe,acosh:()=>en,amax:()=>un,amin:()=>cn,angle:()=>Jc,append:()=>vu,arange:()=>Ks,arccos:()=>Qe,arccosh:()=>en,arcsin:()=>Xe,arcsinh:()=>tn,arctan:()=>Ke,arctan2:()=>rn,arctanh:()=>nn,argpartition:()=>Ml,argsort:()=>zl,argwhere:()=>El,around:()=>Ft,array:()=>or,array_equal:()=>Lu,array_equiv:()=>Zu,array_split:()=>lu,asanyarray:()=>ci,asarray:()=>st,ascontiguousarray:()=>li,asfortranarray:()=>fi,asin:()=>Xe,asinh:()=>tn,atan:()=>Ke,atan2:()=>rn,atanh:()=>nn,atleast_1d:()=>wu,atleast_2d:()=>Iu,atleast_3d:()=>zu,average:()=>Ju,bincount:()=>rf,bindex:()=>Vu,bitwise_and:()=>xc,bitwise_not:()=>Ic,bitwise_or:()=>Nc,bitwise_xor:()=>wc,broadcast_arrays:()=>Uu,broadcast_shapes:()=>$u,broadcast_to:()=>Cu,cbrt:()=>cc,ceil:()=>Rl,choose:()=>Pu,column_stack:()=>Fu,compress:()=>ll,concatenate:()=>vr,conj:()=>ln,conjugate:()=>Hc,convolve:()=>sf,copy:()=>oi,copysign:()=>kc,copyto:()=>ju,corrcoef:()=>cf,correlate:()=>af,cos:()=>Yi,cosh:()=>eu,count_nonzero:()=>$l,cov:()=>uf,cross:()=>Kl,cumprod:()=>sn,cumsum:()=>an,cumulative_prod:()=>sn,cumulative_sum:()=>an,deg2rad:()=>Ki,degrees:()=>Xi,delete:()=>Eu,diag:()=>We,diag_indices:()=>pl,diag_indices_from:()=>dl,diagflat:()=>mi,diagonal:()=>Vi,diff:()=>Jl,digitize:()=>tf,divide:()=>Je,divmod:()=>fc,dot:()=>ki,dsplit:()=>_u,dstack:()=>uu,ediff1d:()=>Xl,einsum:()=>al,empty:()=>Ze,empty_like:()=>ii,exp:()=>wi,exp2:()=>Ii,expand_dims:()=>bu,expm1:()=>zi,extract:()=>Ul,eye:()=>Le,fabs:()=>lc,fill_diagonal:()=>yl,fix:()=>kl,flatnonzero:()=>Tl,flip:()=>_t,fliplr:()=>hu,flipud:()=>Su,float_power:()=>dc,floor:()=>ql,floor_divide:()=>Ui,fmod:()=>gc,frexp:()=>Ac,frombuffer:()=>hi,fromfile:()=>Si,fromfunction:()=>yi,fromiter:()=>Di,fromstring:()=>xi,full:()=>Ge,full_like:()=>ui,gcd:()=>bc,geomspace:()=>ei,gradient:()=>Ql,heaviside:()=>pc,histogram:()=>ef,histogram2d:()=>nf,histogramdd:()=>of,hsplit:()=>mu,hstack:()=>iu,hypot:()=>Ji,identity:()=>ni,iindex:()=>qu,imag:()=>Yc,in1d:()=>Ll,indices:()=>Dl,inner:()=>Li,insert:()=>Tu,intersect1d:()=>Zl,invert:()=>zc,iscomplex:()=>Pc,iscomplexobj:()=>Lc,isdtype:()=>nl,isfinite:()=>Cc,isfortran:()=>Kc,isin:()=>Gl,isinf:()=>Uc,isnan:()=>$c,isnat:()=>Rc,isneginf:()=>Xc,isposinf:()=>Qc,isreal:()=>Zc,isrealobj:()=>Gc,isscalar:()=>tl,iterable:()=>el,ix_:()=>xl,kron:()=>ji,lcm:()=>hc,ldexp:()=>Sc,left_shift:()=>_c,lexsort:()=>_l,linalg:()=>sl,linspace:()=>ri,loadNpz:()=>dn,loadNpzSync:()=>gn,log:()=>_i,log10:()=>Mi,log1p:()=>Bi,log2:()=>Fi,logaddexp:()=>vi,logaddexp2:()=>Ei,logical_and:()=>vc,logical_not:()=>Tc,logical_or:()=>Ec,logical_xor:()=>Oc,logspace:()=>ti,mask_indices:()=>Sl,max:()=>un,median:()=>Wu,meshgrid:()=>pi,min:()=>cn,mod:()=>Ci,modf:()=>Dc,moveaxis:()=>au,nanargmax:()=>ac,nanargmin:()=>oc,nancumprod:()=>ic,nancumsum:()=>sc,nanmax:()=>nc,nanmean:()=>Ku,nanmedian:()=>uc,nanmin:()=>ec,nanprod:()=>Qu,nanstd:()=>tc,nansum:()=>Xu,nanvar:()=>rc,negative:()=>Ti,nextafter:()=>Vc,nonzero:()=>vl,ones:()=>Pe,ones_like:()=>si,outer:()=>Zi,packbits:()=>Mc,pad:()=>Ou,parseNpy:()=>ct,parseNpyData:()=>vt,parseNpyHeader:()=>Bt,parseNpz:()=>Et,parseNpzSync:()=>Tt,partition:()=>Fl,percentile:()=>Yu,place:()=>ml,positive:()=>$i,pow:()=>Ye,power:()=>Ye,promote_types:()=>ol,ptp:()=>Gu,put:()=>ku,put_along_axis:()=>ul,putmask:()=>cl,quantile:()=>Hu,rad2deg:()=>ru,radians:()=>Qi,random:()=>op,ravel:()=>du,ravel_multi_index:()=>Nl,real:()=>Wc,real_if_close:()=>rl,reciprocal:()=>Ri,remainder:()=>yc,repeat:()=>pu,reshape:()=>gu,resize:()=>Bu,right_shift:()=>Fc,rint:()=>Vl,roll:()=>xu,rollaxis:()=>Nu,rot90:()=>Du,round:()=>Ft,round_:()=>Ft,row_stack:()=>Mu,searchsorted:()=>Cl,select:()=>fl,serializeNpy:()=>Pr,serializeNpz:()=>An,serializeNpzSync:()=>bn,setdiff1d:()=>Wl,setxor1d:()=>Yl,sign:()=>Oi,signbit:()=>qc,sin:()=>Wi,sinh:()=>tu,sort:()=>Il,sort_complex:()=>Bl,spacing:()=>jc,split:()=>cu,sqrt:()=>Ni,square:()=>mc,squeeze:()=>Au,stack:()=>su,swapaxes:()=>ou,take:()=>Ru,take_along_axis:()=>il,tan:()=>Hi,tanh:()=>nu,tensordot:()=>Gi,tile:()=>yu,trace:()=>qi,transpose:()=>Pi,tri:()=>di,tril:()=>gi,tril_indices:()=>gl,tril_indices_from:()=>Al,triu:()=>Ai,triu_indices:()=>bl,triu_indices_from:()=>hl,true_divide:()=>Je,trunc:()=>jl,union1d:()=>Hl,unique:()=>Pl,unpackbits:()=>Bc,unravel_index:()=>wl,vander:()=>bi,vsplit:()=>fu,vstack:()=>on,where:()=>Ol,zeros:()=>Dr,zeros_like:()=>ai});var O=class r{constructor(t,e=0){this.re=t,this.im=e}abs(){return Math.sqrt(this.re*this.re+this.im*this.im)}angle(){return Math.atan2(this.im,this.re)}conj(){return new r(this.re,-this.im)}add(t){return typeof t=="number"?new r(this.re+t,this.im):new r(this.re+t.re,this.im+t.im)}sub(t){return typeof t=="number"?new r(this.re-t,this.im):new r(this.re-t.re,this.im-t.im)}mul(t){return typeof t=="number"?new r(this.re*t,this.im*t):new r(this.re*t.re-this.im*t.im,this.re*t.im+this.im*t.re)}div(t){if(typeof t=="number")return new r(this.re/t,this.im/t);let e=t.re*t.re+t.im*t.im;return new r((this.re*t.re+this.im*t.im)/e,(this.im*t.re-this.re*t.im)/e)}neg(){return new r(-this.re,-this.im)}equals(t){return this.re===t.re&&this.im===t.im}toString(){return this.im===0?`(${this.re}+0j)`:this.im<0?`(${this.re}${this.im}j)`:`(${this.re}+${this.im}j)`}static from(t){if(t instanceof r)return t;if(typeof t=="number")return new r(t,0);if(Array.isArray(t))return new r(t[0]??0,t[1]??0);if(typeof t=="object"&&t!==null&&"re"in t)return new r(t.re??0,t.im??0);throw new Error(`Cannot convert ${t} to Complex`)}static isComplex(t){return t instanceof r||typeof t=="object"&&t!==null&&"re"in t&&"im"in t}};function zn(r){if(!r.includes(":")){if(r.includes("."))throw new Error(`Invalid slice index: "${r}" (must be integer)`);let a=parseInt(r,10);if(isNaN(a))throw new Error(`Invalid slice index: "${r}"`);return{start:a,stop:null,step:1,isIndex:!0}}let t=r.split(":");if(t.length>3)throw new Error(`Invalid slice notation: "${r}" (too many colons)`);let e=t[0]===""?null:parseInt(t[0],10),n=t[1]===""||t[1]===void 0?null:parseInt(t[1],10),o=t[2]===""||t[2]===void 0?1:parseInt(t[2],10);if(e!==null&&isNaN(e))throw new Error(`Invalid start index in slice: "${r}"`);if(n!==null&&isNaN(n))throw new Error(`Invalid stop index in slice: "${r}"`);if(isNaN(o))throw new Error(`Invalid step in slice: "${r}"`);if(o===0)throw new Error("Slice step cannot be zero");return{start:e,stop:n,step:o,isIndex:!1}}function _n(r,t){let{start:e,stop:n}=r,{step:o,isIndex:a}=r;if(a){if(e===null)throw new Error("Index cannot be null");let u=e<0?t+e:e;if(u<0||u>=t)throw new Error(`Index ${e} is out of bounds for size ${t}`);return{start:u,stop:u+1,step:1,isIndex:!0}}return o>0?(e===null&&(e=0),n===null&&(n=t)):(e===null&&(e=t-1),n===null&&(n=-t-1)),e<0&&(e=t+e),n<0&&(n=t+n),e=Math.max(0,Math.min(e,t)),n=Math.max(-1,Math.min(n,t)),{start:e,stop:n,step:o,isIndex:!1}}var X="float64";function P(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"complex128":return Float64Array;case"complex64":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function yt(r){switch(r){case"complex128":return 16;case"float64":case"int64":case"uint64":case"complex64":return 8;case"float32":case"int32":case"uint32":return 4;case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${r}`)}}function Mn(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function Fn(r){return r==="float64"||r==="float32"}function B(r){return r==="int64"||r==="uint64"}function M(r){return r==="complex64"||r==="complex128"}function q(r,t,e){if(M(r)){let n=e?` ${e}`:"";throw new TypeError(`ufunc '${t}' not supported for complex dtype '${r}'.${n}`)}}function Zr(r){if(r==="complex128")return"float64";if(r==="complex64")return"float32";throw new Error(`${r} is not a complex dtype`)}function Bn(r){return typeof r=="object"&&r!==null&&"re"in r&&"im"in r}function G(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(M(r)||M(t)){if(M(r)&&M(t))return r==="complex128"||t==="complex128"?"complex128":"complex64";let c=M(r)?r:t,l=M(r)?t:r;return c==="complex128"||l==="float64"||l==="int64"||l==="uint64"||l==="int32"||l==="uint32"?"complex128":"complex64"}if(Fn(r)||Fn(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){let c=t;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}if(t==="float32"){let c=r;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}return"float32"}let e=r.startsWith("int"),n=t.startsWith("int"),o=r.startsWith("uint"),a=t.startsWith("uint"),u=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,s=u(r),i=u(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&s===i){if(s===8)return"int16";if(s===16)return"int32";if(s===32)return"int64"}if(o&&n&&s===i){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(e&&n||o&&a){let c=Math.max(s,i);return e?c===64?"int64":c===32?"int32":c===16?"int16":"int8":c===64?"uint64":c===32?"uint32":c===16?"uint16":"uint8"}return e&&a?s>i?r:i===8?"int16":i===16?"int32":i===32?"int64":"float64":o&&n?i>s?t:s===8?"int16":s===16?"int32":s===32?"int64":"float64":"float64"}var x=class r{constructor(t,e,n,o,a){this._data=t,this._shape=e,this._strides=n,this._offset=o,this._dtype=a}get shape(){return this._shape}get ndim(){return this._shape.length}get size(){return this._shape.reduce((t,e)=>t*e,1)}get dtype(){return this._dtype}get data(){return this._data}get strides(){return this._strides}get offset(){return this._offset}get isCContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=n-1;a>=0;a--){if(e[a]!==o)return!1;o*=t[a]}return!0}get isFContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=0;a<n;a++){if(e[a]!==o)return!1;o*=t[a]}return!0}iget(t){let e=this._shape,n=this._strides,o=e.length,a=M(this._dtype),u;if(o===0)u=this._offset;else{let s=t;u=this._offset;for(let i=0;i<o;i++){let c=1;for(let m=i+1;m<o;m++)c*=e[m];let l=Math.floor(s/c);s=s%c,u+=l*n[i]}}if(a){let s=u*2,i=this._data[s],c=this._data[s+1];return new O(i,c)}return this._data[u]}iset(t,e){let n=this._shape,o=this._strides,a=n.length,u=M(this._dtype),s;if(a===0)s=this._offset;else{let i=t;s=this._offset;for(let c=0;c<a;c++){let l=1;for(let d=c+1;d<a;d++)l*=n[d];let m=Math.floor(i/l);i=i%l,s+=m*o[c]}}if(u){let i=s*2,c,l;e instanceof O?(c=e.re,l=e.im):typeof e=="object"&&e!==null&&"re"in e?(c=e.re,l=e.im??0):(c=Number(e),l=0),this._data[i]=c,this._data[i+1]=l}else this._data[s]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];if(M(this._dtype)){let o=n*2,a=this._data[o],u=this._data[o+1];return new O(a,u)}return this._data[n]}set(t,e){let n=this._strides,o=this._offset;for(let a=0;a<t.length;a++)o+=t[a]*n[a];if(M(this._dtype)){let a=o*2,u,s;e instanceof O?(u=e.re,s=e.im):typeof e=="object"&&e!==null&&"re"in e?(u=e.re,s=e.im??0):(u=Number(e),s=0),this._data[a]=u,this._data[a+1]=s}else this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=M(e),a=P(e);if(!a)throw new Error(`Cannot copy array with dtype ${e}`);let u=o?n*2:n,s=new a(u);if(this.isCContiguous&&this._offset===0)if(B(e)){let i=this._data,c=s;for(let l=0;l<u;l++)c[l]=i[l]}else s.set(this._data.subarray(0,u));else if(B(e)){let i=s;for(let c=0;c<n;c++)i[c]=this.iget(c)}else if(o){let i=s;for(let c=0;c<n;c++){let l=this.iget(c);i[c*2]=l.re,i[c*2+1]=l.im}}else for(let i=0;i<n;i++)s[i]=this.iget(i);return new r(s,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let u=o??r._computeStrides(e),s=a??0;return new r(t,e,u,s,n)}static zeros(t,e=X){let n=t.reduce((i,c)=>i*c,1),o=M(e),a=P(e);if(!a)throw new Error(`Cannot create array with dtype ${e}`);let u=o?n*2:n,s=new a(u);return new r(s,t,r._computeStrides(t),0,e)}static ones(t,e=X){let n=t.reduce((i,c)=>i*c,1),o=M(e),a=P(e);if(!a)throw new Error(`Cannot create array with dtype ${e}`);let u=o?n*2:n,s=new a(u);if(B(e))s.fill(BigInt(1));else if(o){let i=s;for(let c=0;c<n;c++)i[c*2]=1,i[c*2+1]=0}else s.fill(1);return new r(s,t,r._computeStrides(t),0,e)}static _computeStrides(t){let e=new Array(t.length),n=1;for(let o=t.length-1;o>=0;o--)e[o]=n,n*=t[o];return e}};function ar(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}function yr(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);let t=Math.max(...r.map(n=>n.length)),e=new Array(t);for(let n=0;n<t;n++){let o=1;for(let a of r){let u=a.length-t+n,s=u<0?1:a[u];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[n]=o}return e}function rm(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let s=o-n+u,i=r[u],c=e[s];if(i===c)a[s]=t[u];else if(i===1)a[s]=0;else throw new Error("Invalid broadcast")}return a}function lr(r,t){let e=rm(r.shape,r.strides,t);return x.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function Gt(...r){let t=yr(r);if(t===null){let e=r.map(n=>`(${n.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return t}function Ir(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let u=0;u<o;u++){let s=u<o-e?1:r[u-(o-e)],i=u<o-n?1:t[u-(o-n)];if(s===i)a[u]=s;else if(s===1)a[u]=i;else if(i===1)a[u]=s;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function tm(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let s=o-n+u,i=r[u],c=e[s];if(i===c)a[s]=t[u];else if(i===1)a[s]=0;else throw new Error("Invalid broadcast")}return a}function pt(r,t){let e=tm(r.shape,r.strides,t);return x.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function J(r,t,e,n){let o=Ir(r.shape,t.shape),a=pt(r,o),u=pt(t,o),s=G(r.dtype,t.dtype),i=x.zeros(o,s),c=i.data,l=i.size;if(B(s)){let m=c;for(let d=0;d<l;d++){let p=a.iget(d),f=u.iget(d),y=p instanceof O?p.re:p,g=f instanceof O?f.re:f,h=typeof y=="bigint"?y:BigInt(Math.round(y)),b=typeof g=="bigint"?g:BigInt(Math.round(g));n==="add"?m[d]=h+b:n==="subtract"?m[d]=h-b:n==="multiply"?m[d]=h*b:n==="divide"?m[d]=h/b:m[d]=BigInt(Math.round(e(Number(h),Number(b))))}}else{let m=B(r.dtype)||B(t.dtype);for(let d=0;d<l;d++){let p=a.iget(d),f=u.iget(d),y=Number(p),g=Number(f);c[d]=e(y,g)}}return i}function fr(r,t,e){let n=Ir(r.shape,t.shape),o=pt(r,n),a=pt(t,n),u=n.reduce((c,l)=>c*l,1),s=new Uint8Array(u),i=B(r.dtype)||B(t.dtype);for(let c=0;c<u;c++){let l=o.iget(c),m=a.iget(c),d=Number(l),p=Number(m);s[c]=e(d,p)?1:0}return x.fromData(s,n,"bool")}function Y(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,s=e?n:n!=="float32"&&n!=="float64"?"float64":n,i=x.zeros(o,s),c=i.data,l=r.data;if(B(n))if(B(s)){let m=c;for(let d=0;d<a;d++){let p=Number(l[d]);m[d]=BigInt(Math.round(t(p)))}}else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));return i}function Wt(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function ur(r,t){return[r[t*2],r[t*2+1]]}function Nr(r,t,e,n){r[t*2]=e,r[t*2+1]=n}function vn(r,t){return typeof t=="number"?am(r,t):Wt(r,t)?em(r,t):J(r,t,(e,n)=>e+n,"add")}function em(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(M(e)){let i=s,c=M(r.dtype),l=M(t.dtype);for(let m=0;m<o;m++){let[d,p]=c?ur(a,m):[Number(a[m]),0],[f,y]=l?ur(u,m):[Number(u[m]),0];Nr(i,m,d+f,p+y)}return n}if(B(e)){let i=s;if(!B(r.dtype)||!B(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),d=typeof u[l]=="bigint"?u[l]:BigInt(Math.round(Number(u[l])));i[l]=m+d}else{let l=a,m=u;for(let d=0;d<o;d++)i[d]=l[d]+m[d]}}else if(B(r.dtype)||B(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof u[c]=="bigint"?Number(u[c]):u[c];s[c]=l+m}else for(let c=0;c<o;c++)s[c]=a[c]+u[c];return n}function En(r,t){return typeof t=="number"?sm(r,t):Wt(r,t)?nm(r,t):J(r,t,(e,n)=>e-n,"subtract")}function nm(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(M(e)){let i=s,c=M(r.dtype),l=M(t.dtype);for(let m=0;m<o;m++){let[d,p]=c?ur(a,m):[Number(a[m]),0],[f,y]=l?ur(u,m):[Number(u[m]),0];Nr(i,m,d-f,p-y)}return n}if(B(e)){let i=s;if(!B(r.dtype)||!B(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),d=typeof u[l]=="bigint"?u[l]:BigInt(Math.round(Number(u[l])));i[l]=m-d}else{let l=a,m=u;for(let d=0;d<o;d++)i[d]=l[d]-m[d]}}else if(B(r.dtype)||B(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof u[c]=="bigint"?Number(u[c]):u[c];s[c]=l-m}else for(let c=0;c<o;c++)s[c]=a[c]-u[c];return n}function Tn(r,t){return typeof t=="number"?im(r,t):Wt(r,t)?om(r,t):J(r,t,(e,n)=>e*n,"multiply")}function om(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(M(e)){let i=s,c=M(r.dtype),l=M(t.dtype);for(let m=0;m<o;m++){let[d,p]=c?ur(a,m):[Number(a[m]),0],[f,y]=l?ur(u,m):[Number(u[m]),0],g=d*f-p*y,h=d*y+p*f;Nr(i,m,g,h)}return n}if(B(e)){let i=s;if(!B(r.dtype)||!B(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),d=typeof u[l]=="bigint"?u[l]:BigInt(Math.round(Number(u[l])));i[l]=m*d}else{let l=a,m=u;for(let d=0;d<o;d++)i[d]=l[d]*m[d]}}else if(B(r.dtype)||B(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof u[c]=="bigint"?Number(u[c]):u[c];s[c]=l*m}else for(let c=0;c<o;c++)s[c]=a[c]*u[c];return n}function On(r,t){if(typeof t=="number")return um(r,t);let e=M(r.dtype),n=M(t.dtype);if(e||n){let l=G(r.dtype,t.dtype),m=x.zeros(Array.from(r.shape),l),d=m.data,p=r.size,f=r.data,y=t.data;for(let g=0;g<p;g++){let[h,b]=e?ur(f,g):[Number(f[g]),0],[A,S]=n?ur(y,g):[Number(y[g]),0],D=A*A+S*S,w=(h*A+b*S)/D,N=(b*A-h*S)/D;Nr(d,g,w,N)}return m}let o=r.dtype==="float64",a=t.dtype==="float64",u=r.dtype==="float32",s=t.dtype==="float32";if(o||a){let l=o?r:Tr(r,"float64"),m=a?t:Tr(t,"float64");return J(l,m,(d,p)=>d/p,"divide")}if(u||s){let l=u?r:Tr(r,"float32"),m=s?t:Tr(t,"float32");return J(l,m,(d,p)=>d/p,"divide")}let i=Tr(r,"float64"),c=Tr(t,"float64");return J(i,c,(l,m)=>l/m,"divide")}function Tr(r,t){let e=x.zeros(Array.from(r.shape),t),n=r.size,o=r.data,a=e.data;for(let u=0;u<n;u++)a[u]=Number(o[u]);return e}function am(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(M(e)){let i=o,c=s;for(let l=0;l<a;l++){let[m,d]=ur(i,l);Nr(c,l,m+t,d)}}else if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]+l}else for(let i=0;i<a;i++)s[i]=Number(o[i])+t;return u}function sm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(M(e)){let i=o,c=s;for(let l=0;l<a;l++){let[m,d]=ur(i,l);Nr(c,l,m-t,d)}}else if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]-l}else for(let i=0;i<a;i++)s[i]=Number(o[i])-t;return u}function im(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(M(e)){let i=o,c=s;for(let l=0;l<a;l++){let[m,d]=ur(i,l);Nr(c,l,m*t,d*t)}}else if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]*l}else for(let i=0;i<a;i++)s[i]=Number(o[i])*t;return u}function um(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size;if(M(e)){let l=x.zeros(n,e),m=o,d=l.data;for(let p=0;p<a;p++){let[f,y]=ur(m,p);Nr(d,p,f/t,y/t)}return l}let s=e!=="float32"&&e!=="float64"?"float64":e,i=x.zeros(n,s),c=i.data;if(B(e))for(let l=0;l<a;l++)c[l]=Number(o[l])/t;else for(let l=0;l<a;l++)c[l]=Number(o[l])/t;return i}function Cn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size;if(M(t)){let s=Zr(t),i=x.zeros(e,s),c=i.data,l=n;for(let m=0;m<o;m++){let d=l[m*2],p=l[m*2+1];c[m]=Math.sqrt(d*d+p*p)}return i}let a=x.zeros(e,t),u=a.data;if(B(t)){let s=n,i=u;for(let c=0;c<o;c++){let l=s[c];i[c]=l<0n?-l:l}}else for(let s=0;s<o;s++)u[s]=Math.abs(Number(n[s]));return a}function Un(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=x.zeros(e,t),u=a.data;if(M(t)){let s=n,i=u;for(let c=0;c<o;c++){let[l,m]=ur(s,c);Nr(i,c,-l,-m)}}else if(B(t)){let s=n,i=u;for(let c=0;c<o;c++)i[c]=-s[c]}else for(let s=0;s<o;s++)u[s]=-Number(n[s]);return a}function $n(r){q(r.dtype,"sign","Sign is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=x.zeros(e,t),u=a.data;if(B(t)){let s=n,i=u;for(let c=0;c<o;c++){let l=s[c];i[c]=l>0n?1n:l<0n?-1n:0n}}else for(let s=0;s<o;s++){let i=Number(n[s]);u[s]=i>0?1:i<0?-1:0}return a}function dt(r,t){return q(r.dtype,"mod","Modulo is not defined for complex numbers."),typeof t!="number"&&q(t.dtype,"mod","Modulo is not defined for complex numbers."),typeof t=="number"?cm(r,t):J(r,t,(e,n)=>(e%n+n)%n,"mod")}function cm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++){let d=i[m];c[m]=(d%l+l)%l}}else for(let i=0;i<a;i++){let c=Number(o[i]);s[i]=(c%t+t)%t}return u}function Yt(r,t){return q(r.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof t!="number"&&q(t.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof t=="number"?lm(r,t):J(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function lm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]/l}else for(let i=0;i<a;i++)s[i]=Math.floor(Number(o[i])/t);return u}function Rn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=x.zeros(e,t),u=a.data;if(M(t)){let s=n,i=u;for(let c=0;c<o;c++)i[c*2]=s[c*2],i[c*2+1]=s[c*2+1]}else for(let s=0;s<o;s++)u[s]=n[s];return a}function kn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size;if(M(t)){let c=x.zeros(e,t),l=n,m=c.data;for(let d=0;d<o;d++){let p=l[d*2],f=l[d*2+1],y=p*p+f*f;m[d*2]=p/y,m[d*2+1]=-f/y}return c}let u=t!=="float32"&&t!=="float64"?"float64":t,s=x.zeros(e,u),i=s.data;if(B(t))for(let c=0;c<o;c++)i[c]=1/Number(n[c]);else for(let c=0;c<o;c++)i[c]=1/Number(n[c]);return s}function qn(r){let t=r.dtype;q(t,"cbrt","cbrt is not supported for complex numbers.");let e=Array.from(r.shape),n=r.data,o=r.size,u=t!=="float32"&&t!=="float64"?"float64":t,s=x.zeros(e,u),i=s.data;for(let c=0;c<o;c++)i[c]=Math.cbrt(Number(n[c]));return s}function Vn(r){let t=r.dtype;q(t,"fabs","fabs is only for real numbers. Use absolute() for complex.");let e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",u=x.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Math.abs(Number(n[i]));return u}function jn(r,t){let e=Yt(r,t),n=dt(r,t);return[e,n]}function Pn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=x.zeros(e,t),u=a.data;if(M(t)){let s=n,i=u;for(let c=0;c<o;c++){let l=s[c*2],m=s[c*2+1];i[c*2]=l*l-m*m,i[c*2+1]=2*l*m}}else if(B(t)){let s=n,i=u;for(let c=0;c<o;c++)i[c]=s[c]*s[c]}else for(let s=0;s<o;s++){let i=Number(n[s]);u[s]=i*i}return a}function Ln(r,t){return dt(r,t)}function Zn(r,t){q(r.dtype,"heaviside","Heaviside step function is not defined for complex numbers."),typeof t!="number"&&q(t.dtype,"heaviside","Heaviside step function is not defined for complex numbers.");let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=x.zeros(n,a),s=u.data;if(typeof t=="number")for(let i=0;i<o;i++){let c=Number(r.data[i]);c<0?s[i]=0:c===0?s[i]=t:s[i]=1}else{let i=t.data,c=t.shape;if(n.every((l,m)=>l===c[m]))for(let l=0;l<o;l++){let m=Number(r.data[l]);m<0?s[l]=0:m===0?s[l]=Number(i[l]):s[l]=1}else for(let l=0;l<o;l++){let m=Number(r.data[l]),d=l%t.size;m<0?s[l]=0:m===0?s[l]=Number(i[d]):s[l]=1}}return u}function Gn(r,t){let e=r.dtype;if(M(e)){let n=r.data,o=r.size,a=x.zeros(Array.from(r.shape),e),u=a.data;if(typeof t=="number")for(let s=0;s<o;s++){let i=n[s*2],c=n[s*2+1],l=Math.hypot(i,c),m=Math.atan2(c,i),d=Math.pow(l,t),p=m*t;u[s*2]=d*Math.cos(p),u[s*2+1]=d*Math.sin(p)}else{let s=t.data,i=M(t.dtype);for(let c=0;c<o;c++){let l=n[c*2],m=n[c*2+1],d,p;i?(d=s[c*2],p=s[c*2+1]):(d=Number(s[c]),p=0);let f=Math.hypot(l,m),y=Math.atan2(m,l),g=Math.log(f),h=y,b=d*g-p*h,A=d*h+p*g,S=Math.exp(b);u[c*2]=S*Math.cos(A),u[c*2+1]=S*Math.sin(A)}}return a}if(typeof t=="number"){let n=x.zeros(Array.from(r.shape),"float64"),o=n.data,a=r.data,u=r.size;for(let s=0;s<u;s++)o[s]=Math.pow(Number(a[s]),t);return n}return J(r,t,(n,o)=>Math.pow(n,o),"float_power")}function Wn(r,t){if(q(r.dtype,"fmod","fmod is not defined for complex numbers."),typeof t!="number"&&q(t.dtype,"fmod","fmod is not defined for complex numbers."),typeof t=="number"){let e=r.copy(),n=e.data,o=r.size;for(let a=0;a<o;a++){let u=Number(n[a]);n[a]=u-Math.trunc(u/t)*t}return e}return J(r,t,(e,n)=>e-Math.trunc(e/n)*n,"fmod")}function Yn(r){q(r.dtype,"frexp","frexp is not defined for complex numbers.");let t=x.zeros(Array.from(r.shape),"float64"),e=x.zeros(Array.from(r.shape),"int32"),n=t.data,o=e.data,a=r.data,u=r.size;for(let s=0;s<u;s++){let i=Number(a[s]);if(i===0||!isFinite(i))n[s]=i,o[s]=0;else{let c=Math.floor(Math.log2(Math.abs(i)))+1,l=i/Math.pow(2,c);n[s]=l,o[s]=c}}return[t,e]}function Hn(r,t){q(r.dtype,"gcd","GCD is only defined for integers."),typeof t!="number"&&q(t.dtype,"gcd","GCD is only defined for integers.");let e=(i,c)=>{for(i=Math.abs(Math.trunc(i)),c=Math.abs(Math.trunc(c));c!==0;){let l=c;c=i%c,i=l}return i};if(typeof t=="number"){let i=x.zeros(Array.from(r.shape),"int32"),c=i.data,l=r.data,m=r.size,d=Math.abs(Math.trunc(t));for(let p=0;p<m;p++)c[p]=e(Number(l[p]),d);return i}let n=J(r,t,e,"gcd"),o=x.zeros(Array.from(n.shape),"int32"),a=o.data,u=n.data,s=n.size;for(let i=0;i<s;i++)a[i]=Math.round(Number(u[i]));return o}function Jn(r,t){q(r.dtype,"lcm","LCM is only defined for integers."),typeof t!="number"&&q(t.dtype,"lcm","LCM is only defined for integers.");let e=(c,l)=>{for(c=Math.abs(Math.trunc(c)),l=Math.abs(Math.trunc(l));l!==0;){let m=l;l=c%l,c=m}return c},n=(c,l)=>(c=Math.abs(Math.trunc(c)),l=Math.abs(Math.trunc(l)),c===0||l===0?0:c*l/e(c,l));if(typeof t=="number"){let c=x.zeros(Array.from(r.shape),"int32"),l=c.data,m=r.data,d=r.size,p=Math.abs(Math.trunc(t));for(let f=0;f<d;f++)l[f]=n(Number(m[f]),p);return c}let o=J(r,t,n,"lcm"),a=x.zeros(Array.from(o.shape),"int32"),u=a.data,s=o.data,i=o.size;for(let c=0;c<i;c++)u[c]=Math.round(Number(s[c]));return a}function Xn(r,t){if(q(r.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof t!="number"&&q(t.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof t=="number"){let e=x.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size,u=Math.pow(2,t);for(let s=0;s<a;s++)n[s]=Number(o[s])*u;return e}return J(r,t,(e,n)=>e*Math.pow(2,n),"ldexp")}function Qn(r){q(r.dtype,"modf","modf is not defined for complex numbers.");let t=x.zeros(Array.from(r.shape),"float64"),e=x.zeros(Array.from(r.shape),"float64"),n=t.data,o=e.data,a=r.data,u=r.size;for(let s=0;s<u;s++){let i=Number(a[s]),c=Math.trunc(i);o[s]=c,n[s]=i-c}return[t,e]}function Fr(r,t){return[r[t*2],r[t*2+1]]}function Kn(r,t){if(M(r.dtype))return Fr(r.data,t);let e=r.iget(t);return e instanceof O?[e.re,e.im]:[Number(e),0]}function Or(r,t,e){let n=yr([Array.from(r.shape),Array.from(t.shape)]);if(!n)throw new Error("Cannot broadcast arrays together");let o=lr(r,n),a=lr(t,n),u=n.reduce((i,c)=>i*c,1),s=new Uint8Array(u);for(let i=0;i<u;i++){let[c,l]=Kn(o,i),[m,d]=Kn(a,i);s[i]=e(c,l,m,d)?1:0}return x.fromData(s,n,"bool")}function ro(r,t){return typeof t=="number"?mm(r,t):M(r.dtype)||M(t.dtype)?Or(r,t,(e,n,o,a)=>e!==o?e>o:n>a):fr(r,t,(e,n)=>e>n)}function to(r,t){return typeof t=="number"?ym(r,t):M(r.dtype)||M(t.dtype)?Or(r,t,(e,n,o,a)=>e!==o?e>=o:n>=a):fr(r,t,(e,n)=>e>=n)}function eo(r,t){return typeof t=="number"?pm(r,t):M(r.dtype)||M(t.dtype)?Or(r,t,(e,n,o,a)=>e!==o?e<o:n<a):fr(r,t,(e,n)=>e<n)}function no(r,t){return typeof t=="number"?dm(r,t):M(r.dtype)||M(t.dtype)?Or(r,t,(e,n,o,a)=>e!==o?e<=o:n<=a):fr(r,t,(e,n)=>e<=n)}function oo(r,t){return typeof t=="number"?gm(r,t):M(r.dtype)||M(t.dtype)?Or(r,t,(e,n,o,a)=>e===o&&n===a):fr(r,t,(e,n)=>e===n)}function ao(r,t){return typeof t=="number"?Am(r,t):M(r.dtype)||M(t.dtype)?Or(r,t,(e,n,o,a)=>e!==o||n!==a):fr(r,t,(e,n)=>e!==n)}function Ht(r,t,e=1e-5,n=1e-8){return typeof t=="number"?bm(r,t,e,n):fr(r,t,(o,a)=>{let u=Math.abs(o-a),s=n+e*Math.abs(a);return u<=s})}function so(r,t,e=1e-5,n=1e-8){let o=Ht(r,t,e,n),a=o.data;for(let u=0;u<o.size;u++)if(a[u]===0)return!1;return!0}function io(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=yr(e);if(n===null)return!1;let o=lr(r,n),a=lr(t,n),u=n.length,s=n.reduce((l,m)=>l*m,1),i=B(o.dtype),c=B(a.dtype);for(let l=0;l<s;l++){let m=l,d=new Array(u);for(let y=u-1;y>=0;y--)d[y]=m%n[y],m=Math.floor(m/n[y]);let p=o.get(...d),f=a.get(...d);if(i||c){let y=typeof p=="bigint"?p:BigInt(Number(p)),g=typeof f=="bigint"?f:BigInt(Number(f));if(y!==g)return!1}else if(p!==f)return!1}return!0}function mm(r,t){let e=new Uint8Array(r.size),n=r.data;if(M(r.dtype)){let o=n;for(let a=0;a<r.size;a++){let[u,s]=Fr(o,a);e[a]=(u!==t?u>t:s>0)?1:0}}else for(let o=0;o<r.size;o++)e[o]=n[o]>t?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function ym(r,t){let e=new Uint8Array(r.size),n=r.data;if(M(r.dtype)){let o=n;for(let a=0;a<r.size;a++){let[u,s]=Fr(o,a);e[a]=(u!==t?u>=t:s>=0)?1:0}}else for(let o=0;o<r.size;o++)e[o]=n[o]>=t?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function pm(r,t){let e=new Uint8Array(r.size),n=r.data;if(M(r.dtype)){let o=n;for(let a=0;a<r.size;a++){let[u,s]=Fr(o,a);e[a]=(u!==t?u<t:s<0)?1:0}}else for(let o=0;o<r.size;o++)e[o]=n[o]<t?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function dm(r,t){let e=new Uint8Array(r.size),n=r.data;if(M(r.dtype)){let o=n;for(let a=0;a<r.size;a++){let[u,s]=Fr(o,a);e[a]=(u!==t?u<=t:s<=0)?1:0}}else for(let o=0;o<r.size;o++)e[o]=n[o]<=t?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function gm(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(M(o)){let a=n;for(let u=0;u<r.size;u++){let[s,i]=Fr(a,u);e[u]=s===t&&i===0?1:0}}else if(B(o)){let a=BigInt(Math.round(t)),u=n;for(let s=0;s<r.size;s++)e[s]=u[s]===a?1:0}else for(let a=0;a<r.size;a++)e[a]=n[a]===t?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function Am(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(M(o)){let a=n;for(let u=0;u<r.size;u++){let[s,i]=Fr(a,u);e[u]=s!==t||i!==0?1:0}}else for(let a=0;a<r.size;a++)e[a]=n[a]!==t?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function bm(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,u=r.dtype;if(B(u)){let s=a;for(let i=0;i<r.size;i++){let c=Number(s[i]),l=Math.abs(c-t),m=n+e*Math.abs(t);o[i]=l<=m?1:0}}else for(let s=0;s<r.size;s++){let i=Number(a[s]),c=Math.abs(i-t),l=n+e*Math.abs(t);o[s]=c<=l?1:0}return x.fromData(o,Array.from(r.shape),"bool")}function U(r,t){let e=0,n=1;for(let o=r.length-1;o>=0;o--)e+=r[o]*n,n*=t[o];return e}function $(r,t,e,n){let o=n.length,a=new Array(o),u=Array.from(n).filter((i,c)=>c!==t),s=r;for(let i=u.length-1;i>=0;i--)a[i>=t?i+1:i]=s%u[i],s=Math.floor(s/u[i]);return a[t]=e,a}function Gr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,s=r.data;if(t===void 0)if(M(n)){let f=s,y=0,g=0;for(let h=0;h<u;h++)y+=f[h*2],g+=f[h*2+1];return new O(y,g)}else if(B(n)){let f=s,y=BigInt(0);for(let g=0;g<u;g++)y+=f[g];return Number(y)}else{let f=0;for(let y=0;y<u;y++)f+=Number(s[y]);return f}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((f,y)=>y!==i);if(c.length===0)return Gr(r);let l=x.zeros(c,n),m=l.data,d=o[i],p=c.reduce((f,y)=>f*y,1);if(M(n)){let f=s,y=m;for(let g=0;g<p;g++){let h=0,b=0;for(let A=0;A<d;A++){let S=$(g,i,A,o),D=U(S,o);h+=f[D*2],b+=f[D*2+1]}y[g*2]=h,y[g*2+1]=b}}else if(B(n)){let f=s,y=m;for(let g=0;g<p;g++){let h=BigInt(0);for(let b=0;b<d;b++){let A=$(g,i,b,o),S=U(A,o);h+=f[S]}y[g]=h}}else for(let f=0;f<p;f++){let y=0;for(let g=0;g<d;g++){let h=$(f,i,g,o),b=U(h,o);y+=Number(s[b])}m[f]=y}if(e){let f=[...o];return f[i]=1,x.fromData(m,f,n)}return l}function gt(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0){let d=Gr(r);return d instanceof O?new O(d.re/r.size,d.im/r.size):d/r.size}let a=t;if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error(`axis ${t} is out of bounds for array of dimension ${o.length}`);let u=Gr(r,t,e);if(typeof u=="number")return u/o[a];if(u instanceof O)return new O(u.re/o[a],u.im/o[a]);let s=o[a],i=n;M(n)?i=n:(B(n)||n.startsWith("int")||n.startsWith("uint"))&&(i="float64");let c=x.zeros(Array.from(u.shape),i),l=c.data,m=u.data;if(M(n)){let d=m,p=l,f=u.size;for(let y=0;y<f;y++)p[y*2]=d[y*2]/s,p[y*2+1]=d[y*2+1]/s}else if(B(n)){let d=m;for(let p=0;p<l.length;p++)l[p]=Number(d[p])/s}else for(let d=0;d<l.length;d++)l[d]=Number(m[d])/s;return c}function Cr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,s=r.data;if(M(n)){let f=s;if(t===void 0){if(u===0)throw new Error("max of empty array");let D=f[0],w=f[1];for(let N=1;N<u;N++){let I=f[N*2],z=f[N*2+1];if(isNaN(I)||isNaN(z))return new O(NaN,NaN);(I>D||I===D&&z>w)&&(D=I,w=z)}return isNaN(D)||isNaN(w)?new O(NaN,NaN):new O(D,w)}let y=t;if(y<0&&(y=a+y),y<0||y>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let g=Array.from(o).filter((D,w)=>w!==y);if(g.length===0)return Cr(r);let h=x.zeros(g,n),b=h.data,A=o[y],S=g.reduce((D,w)=>D*w,1);for(let D=0;D<S;D++){let w=$(D,y,0,o),N=U(w,o),I=f[N*2],z=f[N*2+1];for(let F=1;F<A;F++){let _=$(D,y,F,o),E=U(_,o),T=f[E*2],C=f[E*2+1];if(isNaN(T)||isNaN(C)){I=NaN,z=NaN;break}(T>I||T===I&&C>z)&&(I=T,z=C)}b[D*2]=I,b[D*2+1]=z}if(e){let D=[...o];return D[y]=1,x.fromData(b,D,n)}return h}if(t===void 0){if(u===0)throw new Error("max of empty array");let f=s[0];for(let y=1;y<u;y++)s[y]>f&&(f=s[y]);return Number(f)}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((f,y)=>y!==i);if(c.length===0)return Cr(r);let l=x.zeros(c,n),m=l.data,d=o[i],p=c.reduce((f,y)=>f*y,1);if(B(n)){let f=s,y=m;for(let g=0;g<p;g++){let h=$(g,i,0,o),b=U(h,o),A=f[b];for(let S=1;S<d;S++){let D=$(g,i,S,o),w=U(D,o),N=f[w];N>A&&(A=N)}y[g]=A}}else for(let f=0;f<p;f++){let y=-1/0;for(let g=0;g<d;g++){let h=$(f,i,g,o),b=U(h,o),A=Number(s[b]);A>y&&(y=A)}m[f]=y}if(e){let f=[...o];return f[i]=1,x.fromData(m,f,n)}return l}function Jt(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,s=r.data;if(t===void 0)if(M(n)){let f=s,y=1,g=0;for(let h=0;h<u;h++){let b=f[h*2],A=f[h*2+1],S=y*b-g*A,D=y*A+g*b;y=S,g=D}return new O(y,g)}else if(B(n)){let f=s,y=BigInt(1);for(let g=0;g<u;g++)y*=f[g];return Number(y)}else{let f=1;for(let y=0;y<u;y++)f*=Number(s[y]);return f}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((f,y)=>y!==i);if(c.length===0)return Jt(r);let l=x.zeros(c,n),m=l.data,d=o[i],p=c.reduce((f,y)=>f*y,1);if(M(n)){let f=s,y=m;for(let g=0;g<p;g++){let h=1,b=0;for(let A=0;A<d;A++){let S=$(g,i,A,o),D=U(S,o),w=f[D*2],N=f[D*2+1],I=h*w-b*N,z=h*N+b*w;h=I,b=z}y[g*2]=h,y[g*2+1]=b}}else if(B(n)){let f=s,y=m;for(let g=0;g<p;g++){let h=BigInt(1);for(let b=0;b<d;b++){let A=$(g,i,b,o),S=U(A,o);h*=f[S]}y[g]=h}}else for(let f=0;f<p;f++){let y=1;for(let g=0;g<d;g++){let h=$(f,i,g,o),b=U(h,o);y*=Number(s[b])}m[f]=y}if(e){let f=[...o];return f[i]=1,x.fromData(m,f,n)}return l}function Ur(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,s=r.data;if(M(n)){let f=s;if(t===void 0){if(u===0)throw new Error("min of empty array");let D=f[0],w=f[1];for(let N=1;N<u;N++){let I=f[N*2],z=f[N*2+1];if(isNaN(I)||isNaN(z))return new O(NaN,NaN);(I<D||I===D&&z<w)&&(D=I,w=z)}return isNaN(D)||isNaN(w)?new O(NaN,NaN):new O(D,w)}let y=t;if(y<0&&(y=a+y),y<0||y>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let g=Array.from(o).filter((D,w)=>w!==y);if(g.length===0)return Ur(r);let h=x.zeros(g,n),b=h.data,A=o[y],S=g.reduce((D,w)=>D*w,1);for(let D=0;D<S;D++){let w=$(D,y,0,o),N=U(w,o),I=f[N*2],z=f[N*2+1];for(let F=1;F<A;F++){let _=$(D,y,F,o),E=U(_,o),T=f[E*2],C=f[E*2+1];if(isNaN(T)||isNaN(C)){I=NaN,z=NaN;break}(T<I||T===I&&C<z)&&(I=T,z=C)}b[D*2]=I,b[D*2+1]=z}if(e){let D=[...o];return D[y]=1,x.fromData(b,D,n)}return h}if(t===void 0){if(u===0)throw new Error("min of empty array");let f=s[0];for(let y=1;y<u;y++)s[y]<f&&(f=s[y]);return Number(f)}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((f,y)=>y!==i);if(c.length===0)return Ur(r);let l=x.zeros(c,n),m=l.data,d=o[i],p=c.reduce((f,y)=>f*y,1);if(B(n)){let f=s,y=m;for(let g=0;g<p;g++){let h=$(g,i,0,o),b=U(h,o),A=f[b];for(let S=1;S<d;S++){let D=$(g,i,S,o),w=U(D,o),N=f[w];N<A&&(A=N)}y[g]=A}}else for(let f=0;f<p;f++){let y=1/0;for(let g=0;g<d;g++){let h=$(f,i,g,o),b=U(h,o),A=Number(s[b]);A<y&&(y=A)}m[f]=y}if(e){let f=[...o];return f[i]=1,x.fromData(m,f,n)}return l}function zr(r,t,e,n){return r<e?-1:r>e?1:t<n?-1:t>n?1:0}function Xt(r,t){let e=r.dtype,n=M(e),o=r.shape,a=o.length,u=r.size,s=r.data;if(t===void 0){if(u===0)throw new Error("argmin of empty array");if(n){let g=s,h=g[0],b=g[1],A=0;for(let S=1;S<u;S++){let D=g[S*2],w=g[S*2+1];zr(D,w,h,b)<0&&(h=D,b=w,A=S)}return A}let f=s[0],y=0;for(let g=1;g<u;g++)s[g]<f&&(f=s[g],y=g);return y}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((f,y)=>y!==i);if(c.length===0)return Xt(r);let l=x.zeros(c,"int32"),m=l.data,d=o[i],p=c.reduce((f,y)=>f*y,1);if(n){let f=s;for(let y=0;y<p;y++){let g=$(y,i,0,o),h=U(g,o),b=f[h*2],A=f[h*2+1],S=0;for(let D=1;D<d;D++){let w=$(y,i,D,o),N=U(w,o),I=f[N*2],z=f[N*2+1];zr(I,z,b,A)<0&&(b=I,A=z,S=D)}m[y]=S}}else if(B(e)){let f=s;for(let y=0;y<p;y++){let g=$(y,i,0,o),h=U(g,o),b=f[h],A=0;for(let S=1;S<d;S++){let D=$(y,i,S,o),w=U(D,o),N=f[w];N<b&&(b=N,A=S)}m[y]=A}}else for(let f=0;f<p;f++){let y=1/0,g=0;for(let h=0;h<d;h++){let b=$(f,i,h,o),A=U(b,o),S=Number(s[A]);S<y&&(y=S,g=h)}m[f]=g}return l}function Qt(r,t){let e=r.dtype,n=M(e),o=r.shape,a=o.length,u=r.size,s=r.data;if(t===void 0){if(u===0)throw new Error("argmax of empty array");if(n){let g=s,h=g[0],b=g[1],A=0;for(let S=1;S<u;S++){let D=g[S*2],w=g[S*2+1];zr(D,w,h,b)>0&&(h=D,b=w,A=S)}return A}let f=s[0],y=0;for(let g=1;g<u;g++)s[g]>f&&(f=s[g],y=g);return y}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((f,y)=>y!==i);if(c.length===0)return Qt(r);let l=x.zeros(c,"int32"),m=l.data,d=o[i],p=c.reduce((f,y)=>f*y,1);if(n){let f=s;for(let y=0;y<p;y++){let g=$(y,i,0,o),h=U(g,o),b=f[h*2],A=f[h*2+1],S=0;for(let D=1;D<d;D++){let w=$(y,i,D,o),N=U(w,o),I=f[N*2],z=f[N*2+1];zr(I,z,b,A)>0&&(b=I,A=z,S=D)}m[y]=S}}else if(B(e)){let f=s;for(let y=0;y<p;y++){let g=$(y,i,0,o),h=U(g,o),b=f[h],A=0;for(let S=1;S<d;S++){let D=$(y,i,S,o),w=U(D,o),N=f[w];N>b&&(b=N,A=S)}m[y]=A}}else for(let f=0;f<p;f++){let y=-1/0,g=0;for(let h=0;h<d;h++){let b=$(f,i,h,o),A=U(b,o),S=Number(s[A]);S>y&&(y=S,g=h)}m[f]=g}return l}function Kt(r,t,e=0,n=!1){let o=r.dtype,a=r.shape,u=a.length,s=r.size,i=r.data,c=gt(r,t,n);if(t===void 0){if(M(o)){let S=i,D=c,w=0;for(let N=0;N<s;N++){let I=S[N*2],z=S[N*2+1],F=I-D.re,_=z-D.im;w+=F*F+_*_}return w/(s-e)}let b=c,A=0;for(let S=0;S<s;S++){let D=Number(i[S])-b;A+=D*D}return A/(s-e)}let l=t;if(l<0&&(l=u+l),l<0||l>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let m=a[l],d=c,p=d.data,f=n?d.shape:Array.from(a).filter((b,A)=>A!==l),y=x.zeros(Array.from(f),"float64"),g=y.data,h=f.reduce((b,A)=>b*A,1);if(M(o)){let b=i,A=p;for(let S=0;S<h;S++){let D=0,w=A[S*2],N=A[S*2+1];for(let I=0;I<m;I++){let z=$(S,l,I,a),F=U(z,a),_=b[F*2],E=b[F*2+1],T=_-w,C=E-N;D+=T*T+C*C}g[S]=D/(m-e)}}else for(let b=0;b<h;b++){let A=0,S=Number(p[b]);for(let D=0;D<m;D++){let w=$(b,l,D,a),N=U(w,a),I=Number(i[N])-S;A+=I*I}g[b]=A/(m-e)}return y}function uo(r,t,e=0,n=!1){let o=Kt(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=x.zeros(Array.from(o.shape),"float64"),u=o.data,s=a.data;for(let i=0;i<u.length;i++)s[i]=Math.sqrt(Number(u[i]));return a}function re(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,u=r.data;if(t===void 0){for(let p=0;p<a;p++)if(!u[p])return!1;return!0}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((p,f)=>f!==s);if(i.length===0)return re(r);let c=x.zeros(i,"bool"),l=c.data,m=n[s],d=i.reduce((p,f)=>p*f,1);for(let p=0;p<d;p++){let f=!0;for(let y=0;y<m;y++){let g=$(p,s,y,n),h=U(g,n);if(!u[h]){f=!1;break}}l[p]=f?1:0}if(e){let p=[...n];return p[s]=1,x.fromData(l,p,"bool")}return c}function te(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,u=r.data;if(t===void 0){for(let p=0;p<a;p++)if(u[p])return!0;return!1}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((p,f)=>f!==s);if(i.length===0)return te(r);let c=x.zeros(i,"bool"),l=c.data,m=n[s],d=i.reduce((p,f)=>p*f,1);for(let p=0;p<d;p++){let f=!1;for(let y=0;y<m;y++){let g=$(p,s,y,n),h=U(g,n);if(u[h]){f=!0;break}}l[p]=f?1:0}if(e){let p=[...n];return p[s]=1,x.fromData(l,p,"bool")}return c}function ee(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data;if(M(e)){let p=a,f=r.size;if(t===void 0){let N=x.zeros([f],e),I=N.data,z=0,F=0;for(let _=0;_<f;_++)z+=p[_*2],F+=p[_*2+1],I[_*2]=z,I[_*2+1]=F;return N}let y=t;if(y<0&&(y=o+y),y<0||y>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=x.zeros([...n],e),h=g.data,b=n[y],A=[],S=1;for(let N=o-1;N>=0;N--)A.unshift(S),S*=n[N];let D=r.size,w=A[y];for(let N=0;N<D;N++)Math.floor(N/w)%b===0?(h[N*2]=p[N*2],h[N*2+1]=p[N*2+1]):(h[N*2]=h[(N-w)*2]+p[N*2],h[N*2+1]=h[(N-w)*2+1]+p[N*2+1]);return g}if(t===void 0){let p=r.size,f=new Float64Array(p),y=0;for(let g=0;g<p;g++)y+=Number(a[g]),f[g]=y;return x.fromData(f,[p],"float64")}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=new Float64Array(r.size),i=n[u],c=[],l=1;for(let p=o-1;p>=0;p--)c.unshift(l),l*=n[p];let m=r.size,d=c[u];for(let p=0;p<m;p++)Math.floor(p/d)%i===0?s[p]=Number(a[p]):s[p]=s[p-d]+Number(a[p]);return x.fromData(s,[...n],"float64")}function ne(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data;if(M(e)){let p=a,f=r.size;if(t===void 0){let N=x.zeros([f],e),I=N.data,z=1,F=0;for(let _=0;_<f;_++){let E=p[_*2],T=p[_*2+1],C=z*E-F*T,k=z*T+F*E;z=C,F=k,I[_*2]=z,I[_*2+1]=F}return N}let y=t;if(y<0&&(y=o+y),y<0||y>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=x.zeros([...n],e),h=g.data,b=n[y],A=[],S=1;for(let N=o-1;N>=0;N--)A.unshift(S),S*=n[N];let D=r.size,w=A[y];for(let N=0;N<D;N++)if(Math.floor(N/w)%b===0)h[N*2]=p[N*2],h[N*2+1]=p[N*2+1];else{let z=h[(N-w)*2],F=h[(N-w)*2+1],_=p[N*2],E=p[N*2+1];h[N*2]=z*_-F*E,h[N*2+1]=z*E+F*_}return g}if(t===void 0){let p=r.size,f=new Float64Array(p),y=1;for(let g=0;g<p;g++)y*=Number(a[g]),f[g]=y;return x.fromData(f,[p],"float64")}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=new Float64Array(r.size),i=n[u],c=[],l=1;for(let p=o-1;p>=0;p--)c.unshift(l),l*=n[p];let m=r.size,d=c[u];for(let p=0;p<m;p++)Math.floor(p/d)%i===0?s[p]=Number(a[p]):s[p]=s[p-d]*Number(a[p]);return x.fromData(s,[...n],"float64")}function oe(r,t,e=!1){let n=r.dtype;if(M(n)){let m=Cr(r,t,e),d=Ur(r,t,e);if(m instanceof O&&d instanceof O)return new O(m.re-d.re,m.im-d.im);let p=m,f=d,y=p.data,g=f.data,h=new Float64Array(p.size*2);for(let b=0;b<p.size;b++)h[b*2]=y[b*2]-g[b*2],h[b*2+1]=y[b*2+1]-g[b*2+1];return x.fromData(h,[...p.shape],n)}let o=Cr(r,t,e),a=Ur(r,t,e);if(typeof o=="number"&&typeof a=="number")return o-a;let u=o,s=a,i=u.data,c=s.data,l=new Float64Array(u.size);for(let m=0;m<u.size;m++)l[m]=Number(i[m])-Number(c[m]);return x.fromData(l,[...u.shape],"float64")}function ae(r,t,e=!1){return Rr(r,.5,t,e)}function se(r,t,e,n=!1){return Rr(r,t/100,e,n)}function Rr(r,t,e,n=!1){if(q(r.dtype,"quantile","Complex numbers are not orderable."),t<0||t>1)throw new Error("Quantile must be between 0 and 1");let o=r.shape,a=o.length,u=r.data;if(e===void 0){let p=[];for(let A=0;A<r.size;A++)p.push(Number(u[A]));p.sort((A,S)=>A-S);let f=p.length,y=t*(f-1),g=Math.floor(y),h=Math.ceil(y);if(g===h)return p[g];let b=y-g;return p[g]*(1-b)+p[h]*b}let s=e;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((p,f)=>f!==s);if(i.length===0)return Rr(r,t);let c=i.reduce((p,f)=>p*f,1),l=o[s],m=new Float64Array(c);for(let p=0;p<c;p++){let f=[];for(let A=0;A<l;A++){let S=$(p,s,A,o),D=U(S,o);f.push(Number(u[D]))}f.sort((A,S)=>A-S);let y=f.length,g=t*(y-1),h=Math.floor(g),b=Math.ceil(g);if(h===b)m[p]=f[h];else{let A=g-h;m[p]=f[h]*(1-A)+f[b]*A}}let d=x.fromData(m,i,"float64");if(n){let p=[...o];return p[s]=1,x.fromData(m,p,"float64")}return d}function Wr(r,t,e,n=!1){let o=r.dtype,a=r.shape,u=a.length,s=r.data;if(e===void 0)return gt(r,t,n);if(M(o)){let y=s,g=e.data;if(t===void 0){let N=0,I=0,z=0;for(let F=0;F<r.size;F++){let _=Number(g[F%e.size]),E=y[F*2],T=y[F*2+1];N+=E*_,I+=T*_,z+=_}return z===0?new O(NaN,NaN):new O(N/z,I/z)}let h=t;if(h<0&&(h=u+h),h<0||h>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let b=Array.from(a).filter((N,I)=>I!==h);if(b.length===0)return Wr(r,void 0,e);let A=b.reduce((N,I)=>N*I,1),S=a[h],D=x.zeros(b,o),w=D.data;for(let N=0;N<A;N++){let I=0,z=0,F=0;for(let _=0;_<S;_++){let E=$(N,h,_,a),T=U(E,a),C=Number(g[_%e.size]),k=y[T*2],V=y[T*2+1];I+=k*C,z+=V*C,F+=C}F===0?(w[N*2]=NaN,w[N*2+1]=NaN):(w[N*2]=I/F,w[N*2+1]=z/F)}if(n){let N=[...a];return N[h]=1,x.fromData(w,N,o)}return D}if(t===void 0){let y=0,g=0,h=e.data;for(let b=0;b<r.size;b++){let A=Number(h[b%e.size]);y+=Number(s[b])*A,g+=A}return g===0?NaN:y/g}let i=t;if(i<0&&(i=u+i),i<0||i>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let c=Array.from(a).filter((y,g)=>g!==i);if(c.length===0)return Wr(r,void 0,e);let l=c.reduce((y,g)=>y*g,1),m=a[i],d=e.data,p=new Float64Array(l);for(let y=0;y<l;y++){let g=0,h=0;for(let b=0;b<m;b++){let A=$(y,i,b,a),S=U(A,a),D=Number(d[b%e.size]);g+=Number(s[S])*D,h+=D}p[y]=h===0?NaN:g/h}let f=x.fromData(p,c,"float64");if(n){let y=[...a];return y[i]=1,x.fromData(p,y,"float64")}return f}function K(r,t){return isNaN(r)||isNaN(t)}function At(r,t,e=!1){let n=r.dtype,o=M(n),a=r.shape,u=a.length,s=r.data;if(t===void 0){if(o){let y=s,g=0,h=0;for(let b=0;b<r.size;b++){let A=y[b*2],S=y[b*2+1];K(A,S)||(g+=A,h+=S)}return new O(g,h)}let f=0;for(let y=0;y<r.size;y++){let g=Number(s[y]);isNaN(g)||(f+=g)}return f}let i=t;if(i<0&&(i=u+i),i<0||i>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let c=Array.from(a).filter((f,y)=>y!==i);if(c.length===0)return At(r);let l=c.reduce((f,y)=>f*y,1),m=a[i];if(o){let f=s,y=new Float64Array(l*2);for(let g=0;g<l;g++){let h=0,b=0;for(let A=0;A<m;A++){let S=$(g,i,A,a),D=U(S,a),w=f[D*2],N=f[D*2+1];K(w,N)||(h+=w,b+=N)}y[g*2]=h,y[g*2+1]=b}if(e){let g=[...a];return g[i]=1,x.fromData(y,g,n)}return x.fromData(y,c,n)}let d=new Float64Array(l);for(let f=0;f<l;f++){let y=0;for(let g=0;g<m;g++){let h=$(f,i,g,a),b=U(h,a),A=Number(s[b]);isNaN(A)||(y+=A)}d[f]=y}let p=x.fromData(d,c,"float64");if(e){let f=[...a];return f[i]=1,x.fromData(d,f,"float64")}return p}function bt(r,t,e=!1){let n=r.dtype,o=M(n),a=r.shape,u=a.length,s=r.data;if(t===void 0){if(o){let y=s,g=1,h=0;for(let b=0;b<r.size;b++){let A=y[b*2],S=y[b*2+1];if(!K(A,S)){let D=g*A-h*S,w=g*S+h*A;g=D,h=w}}return new O(g,h)}let f=1;for(let y=0;y<r.size;y++){let g=Number(s[y]);isNaN(g)||(f*=g)}return f}let i=t;if(i<0&&(i=u+i),i<0||i>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let c=Array.from(a).filter((f,y)=>y!==i);if(c.length===0)return bt(r);let l=c.reduce((f,y)=>f*y,1),m=a[i];if(o){let f=s,y=new Float64Array(l*2);for(let g=0;g<l;g++){let h=1,b=0;for(let A=0;A<m;A++){let S=$(g,i,A,a),D=U(S,a),w=f[D*2],N=f[D*2+1];if(!K(w,N)){let I=h*w-b*N,z=h*N+b*w;h=I,b=z}}y[g*2]=h,y[g*2+1]=b}if(e){let g=[...a];return g[i]=1,x.fromData(y,g,n)}return x.fromData(y,c,n)}let d=new Float64Array(l);for(let f=0;f<l;f++){let y=1;for(let g=0;g<m;g++){let h=$(f,i,g,a),b=U(h,a),A=Number(s[b]);isNaN(A)||(y*=A)}d[f]=y}let p=x.fromData(d,c,"float64");if(e){let f=[...a];return f[i]=1,x.fromData(d,f,"float64")}return p}function ht(r,t,e=!1){let n=r.dtype,o=M(n),a=r.shape,u=a.length,s=r.data;if(t===void 0){if(o){let g=s,h=0,b=0,A=0;for(let S=0;S<r.size;S++){let D=g[S*2],w=g[S*2+1];K(D,w)||(h+=D,b+=w,A++)}return A===0?new O(NaN,NaN):new O(h/A,b/A)}let f=0,y=0;for(let g=0;g<r.size;g++){let h=Number(s[g]);isNaN(h)||(f+=h,y++)}return y===0?NaN:f/y}let i=t;if(i<0&&(i=u+i),i<0||i>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let c=Array.from(a).filter((f,y)=>y!==i);if(c.length===0)return ht(r);let l=c.reduce((f,y)=>f*y,1),m=a[i];if(o){let f=s,y=new Float64Array(l*2);for(let g=0;g<l;g++){let h=0,b=0,A=0;for(let S=0;S<m;S++){let D=$(g,i,S,a),w=U(D,a),N=f[w*2],I=f[w*2+1];K(N,I)||(h+=N,b+=I,A++)}A===0?(y[g*2]=NaN,y[g*2+1]=NaN):(y[g*2]=h/A,y[g*2+1]=b/A)}if(e){let g=[...a];return g[i]=1,x.fromData(y,g,n)}return x.fromData(y,c,n)}let d=new Float64Array(l);for(let f=0;f<l;f++){let y=0,g=0;for(let h=0;h<m;h++){let b=$(f,i,h,a),A=U(b,a),S=Number(s[A]);isNaN(S)||(y+=S,g++)}d[f]=g===0?NaN:y/g}let p=x.fromData(d,c,"float64");if(e){let f=[...a];return f[i]=1,x.fromData(d,f,"float64")}return p}function $r(r,t,e=0,n=!1){let o=r.dtype,a=r.shape,u=a.length,s=r.data;if(M(o)){let f=s;if(t===void 0){let D=0,w=0,N=0;for(let _=0;_<r.size;_++){let E=f[_*2],T=f[_*2+1];K(E,T)||(D+=E,w+=T,N++)}if(N-e<=0)return NaN;let I=D/N,z=w/N,F=0;for(let _=0;_<r.size;_++){let E=f[_*2],T=f[_*2+1];if(!K(E,T)){let C=E-I,k=T-z;F+=C*C+k*k}}return F/(N-e)}let y=t;if(y<0&&(y=u+y),y<0||y>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let g=Array.from(a).filter((D,w)=>w!==y);if(g.length===0)return $r(r,void 0,e);let h=g.reduce((D,w)=>D*w,1),b=a[y],A=new Float64Array(h);for(let D=0;D<h;D++){let w=0,N=0,I=0;for(let E=0;E<b;E++){let T=$(D,y,E,a),C=U(T,a),k=f[C*2],V=f[C*2+1];K(k,V)||(w+=k,N+=V,I++)}if(I-e<=0){A[D]=NaN;continue}let z=w/I,F=N/I,_=0;for(let E=0;E<b;E++){let T=$(D,y,E,a),C=U(T,a),k=f[C*2],V=f[C*2+1];if(!K(k,V)){let R=k-z,L=V-F;_+=R*R+L*L}}A[D]=_/(I-e)}let S=x.fromData(A,g,"float64");if(n){let D=[...a];return D[y]=1,x.fromData(A,D,"float64")}return S}if(t===void 0){let f=0,y=0;for(let b=0;b<r.size;b++){let A=Number(s[b]);isNaN(A)||(f+=A,y++)}if(y-e<=0)return NaN;let g=f/y,h=0;for(let b=0;b<r.size;b++){let A=Number(s[b]);isNaN(A)||(h+=(A-g)**2)}return h/(y-e)}let i=t;if(i<0&&(i=u+i),i<0||i>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let c=Array.from(a).filter((f,y)=>y!==i);if(c.length===0)return $r(r,void 0,e);let l=c.reduce((f,y)=>f*y,1),m=a[i],d=new Float64Array(l);for(let f=0;f<l;f++){let y=0,g=0;for(let A=0;A<m;A++){let S=$(f,i,A,a),D=U(S,a),w=Number(s[D]);isNaN(w)||(y+=w,g++)}if(g-e<=0){d[f]=NaN;continue}let h=y/g,b=0;for(let A=0;A<m;A++){let S=$(f,i,A,a),D=U(S,a),w=Number(s[D]);isNaN(w)||(b+=(w-h)**2)}d[f]=b/(g-e)}let p=x.fromData(d,c,"float64");if(n){let f=[...a];return f[i]=1,x.fromData(d,f,"float64")}return p}function ie(r,t,e=0,n=!1){let o=$r(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,u=new Float64Array(a.size);for(let s=0;s<a.size;s++)u[s]=Math.sqrt(Number(a.data[s]));return x.fromData(u,[...a.shape],"float64")}function Yr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.data;if(M(n)){let p=u;if(t===void 0){let S=1/0,D=1/0,w=!1;for(let N=0;N<r.size;N++){let I=p[N*2],z=p[N*2+1];isNaN(I)||isNaN(z)||(w?(I<S||I===S&&z<D)&&(S=I,D=z):(S=I,D=z,w=!0))}return w?new O(S,D):new O(NaN,NaN)}let f=t;if(f<0&&(f=a+f),f<0||f>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let y=Array.from(o).filter((S,D)=>D!==f);if(y.length===0)return Yr(r);let g=y.reduce((S,D)=>S*D,1),h=o[f],b=new Float64Array(g*2);for(let S=0;S<g;S++){let D=1/0,w=1/0,N=!1;for(let I=0;I<h;I++){let z=$(S,f,I,o),F=U(z,o),_=p[F*2],E=p[F*2+1];isNaN(_)||isNaN(E)||(N?(_<D||_===D&&E<w)&&(D=_,w=E):(D=_,w=E,N=!0))}b[S*2]=N?D:NaN,b[S*2+1]=N?w:NaN}let A=x.fromData(b,y,n);if(e){let S=[...o];return S[f]=1,x.fromData(b,S,n)}return A}if(t===void 0){let p=1/0;for(let f=0;f<r.size;f++){let y=Number(u[f]);!isNaN(y)&&y<p&&(p=y)}return p===1/0?NaN:p}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((p,f)=>f!==s);if(i.length===0)return Yr(r);let c=i.reduce((p,f)=>p*f,1),l=o[s],m=new Float64Array(c);for(let p=0;p<c;p++){let f=1/0;for(let y=0;y<l;y++){let g=$(p,s,y,o),h=U(g,o),b=Number(u[h]);!isNaN(b)&&b<f&&(f=b)}m[p]=f===1/0?NaN:f}let d=x.fromData(m,i,"float64");if(e){let p=[...o];return p[s]=1,x.fromData(m,p,"float64")}return d}function Hr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.data;if(M(n)){let p=u;if(t===void 0){let S=-1/0,D=-1/0,w=!1;for(let N=0;N<r.size;N++){let I=p[N*2],z=p[N*2+1];isNaN(I)||isNaN(z)||(w?(I>S||I===S&&z>D)&&(S=I,D=z):(S=I,D=z,w=!0))}return w?new O(S,D):new O(NaN,NaN)}let f=t;if(f<0&&(f=a+f),f<0||f>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let y=Array.from(o).filter((S,D)=>D!==f);if(y.length===0)return Hr(r);let g=y.reduce((S,D)=>S*D,1),h=o[f],b=new Float64Array(g*2);for(let S=0;S<g;S++){let D=-1/0,w=-1/0,N=!1;for(let I=0;I<h;I++){let z=$(S,f,I,o),F=U(z,o),_=p[F*2],E=p[F*2+1];isNaN(_)||isNaN(E)||(N?(_>D||_===D&&E>w)&&(D=_,w=E):(D=_,w=E,N=!0))}b[S*2]=N?D:NaN,b[S*2+1]=N?w:NaN}let A=x.fromData(b,y,n);if(e){let S=[...o];return S[f]=1,x.fromData(b,S,n)}return A}if(t===void 0){let p=-1/0;for(let f=0;f<r.size;f++){let y=Number(u[f]);!isNaN(y)&&y>p&&(p=y)}return p===-1/0?NaN:p}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((p,f)=>f!==s);if(i.length===0)return Hr(r);let c=i.reduce((p,f)=>p*f,1),l=o[s],m=new Float64Array(c);for(let p=0;p<c;p++){let f=-1/0;for(let y=0;y<l;y++){let g=$(p,s,y,o),h=U(g,o),b=Number(u[h]);!isNaN(b)&&b>f&&(f=b)}m[p]=f===-1/0?NaN:f}let d=x.fromData(m,i,"float64");if(e){let p=[...o];return p[s]=1,x.fromData(m,p,"float64")}return d}function Jr(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data;if(M(e)){let m=a;if(t===void 0){let h=1/0,b=1/0,A=-1;for(let S=0;S<r.size;S++){let D=m[S*2],w=m[S*2+1];!K(D,w)&&zr(D,w,h,b)<0&&(h=D,b=w,A=S)}return A}let d=t;if(d<0&&(d=o+d),d<0||d>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let p=Array.from(n).filter((h,b)=>b!==d);if(p.length===0)return Jr(r);let f=p.reduce((h,b)=>h*b,1),y=n[d],g=new Int32Array(f);for(let h=0;h<f;h++){let b=1/0,A=1/0,S=0;for(let D=0;D<y;D++){let w=$(h,d,D,n),N=U(w,n),I=m[N*2],z=m[N*2+1];!K(I,z)&&zr(I,z,b,A)<0&&(b=I,A=z,S=D)}g[h]=S}return x.fromData(g,p,"int32")}if(t===void 0){let m=1/0,d=-1;for(let p=0;p<r.size;p++){let f=Number(a[p]);!isNaN(f)&&f<m&&(m=f,d=p)}return d}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((m,d)=>d!==u);if(s.length===0)return Jr(r);let i=s.reduce((m,d)=>m*d,1),c=n[u],l=new Int32Array(i);for(let m=0;m<i;m++){let d=1/0,p=0;for(let f=0;f<c;f++){let y=$(m,u,f,n),g=U(y,n),h=Number(a[g]);!isNaN(h)&&h<d&&(d=h,p=f)}l[m]=p}return x.fromData(l,s,"int32")}function Xr(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data;if(M(e)){let m=a;if(t===void 0){let h=-1/0,b=-1/0,A=-1;for(let S=0;S<r.size;S++){let D=m[S*2],w=m[S*2+1];!K(D,w)&&zr(D,w,h,b)>0&&(h=D,b=w,A=S)}return A}let d=t;if(d<0&&(d=o+d),d<0||d>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let p=Array.from(n).filter((h,b)=>b!==d);if(p.length===0)return Xr(r);let f=p.reduce((h,b)=>h*b,1),y=n[d],g=new Int32Array(f);for(let h=0;h<f;h++){let b=-1/0,A=-1/0,S=0;for(let D=0;D<y;D++){let w=$(h,d,D,n),N=U(w,n),I=m[N*2],z=m[N*2+1];!K(I,z)&&zr(I,z,b,A)>0&&(b=I,A=z,S=D)}g[h]=S}return x.fromData(g,p,"int32")}if(t===void 0){let m=-1/0,d=-1;for(let p=0;p<r.size;p++){let f=Number(a[p]);!isNaN(f)&&f>m&&(m=f,d=p)}return d}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((m,d)=>d!==u);if(s.length===0)return Xr(r);let i=s.reduce((m,d)=>m*d,1),c=n[u],l=new Int32Array(i);for(let m=0;m<i;m++){let d=-1/0,p=0;for(let f=0;f<c;f++){let y=$(m,u,f,n),g=U(y,n),h=Number(a[g]);!isNaN(h)&&h>d&&(d=h,p=f)}l[m]=p}return x.fromData(l,s,"int32")}function ue(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data;if(M(e)){let p=a,f=r.size;if(t===void 0){let N=x.zeros([f],e),I=N.data,z=0,F=0;for(let _=0;_<f;_++){let E=p[_*2],T=p[_*2+1];K(E,T)||(z+=E,F+=T),I[_*2]=z,I[_*2+1]=F}return N}let y=t;if(y<0&&(y=o+y),y<0||y>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=x.zeros([...n],e),h=g.data,b=n[y],A=[],S=1;for(let N=o-1;N>=0;N--)A.unshift(S),S*=n[N];let D=r.size,w=A[y];for(let N=0;N<D;N++){let I=p[N*2],z=p[N*2+1],F=Math.floor(N/w)%b,_=K(I,z);F===0?(h[N*2]=_?0:I,h[N*2+1]=_?0:z):(h[N*2]=h[(N-w)*2]+(_?0:I),h[N*2+1]=h[(N-w)*2+1]+(_?0:z))}return g}if(t===void 0){let p=r.size,f=new Float64Array(p),y=0;for(let g=0;g<p;g++){let h=Number(a[g]);isNaN(h)||(y+=h),f[g]=y}return x.fromData(f,[p],"float64")}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=new Float64Array(r.size),i=n[u],c=[],l=1;for(let p=o-1;p>=0;p--)c.unshift(l),l*=n[p];let m=r.size,d=c[u];for(let p=0;p<m;p++){let f=Number(a[p]);Math.floor(p/d)%i===0?s[p]=isNaN(f)?0:f:s[p]=s[p-d]+(isNaN(f)?0:f)}return x.fromData(s,[...n],"float64")}function ce(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data;if(M(e)){let p=a,f=r.size;if(t===void 0){let N=x.zeros([f],e),I=N.data,z=1,F=0;for(let _=0;_<f;_++){let E=p[_*2],T=p[_*2+1];if(!K(E,T)){let C=z*E-F*T,k=z*T+F*E;z=C,F=k}I[_*2]=z,I[_*2+1]=F}return N}let y=t;if(y<0&&(y=o+y),y<0||y>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=x.zeros([...n],e),h=g.data,b=n[y],A=[],S=1;for(let N=o-1;N>=0;N--)A.unshift(S),S*=n[N];let D=r.size,w=A[y];for(let N=0;N<D;N++){let I=p[N*2],z=p[N*2+1],F=Math.floor(N/w)%b,_=K(I,z);if(F===0)h[N*2]=_?1:I,h[N*2+1]=_?0:z;else{let E=h[(N-w)*2],T=h[(N-w)*2+1];_?(h[N*2]=E,h[N*2+1]=T):(h[N*2]=E*I-T*z,h[N*2+1]=E*z+T*I)}}return g}if(t===void 0){let p=r.size,f=new Float64Array(p),y=1;for(let g=0;g<p;g++){let h=Number(a[g]);isNaN(h)||(y*=h),f[g]=y}return x.fromData(f,[p],"float64")}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=new Float64Array(r.size),i=n[u],c=[],l=1;for(let p=o-1;p>=0;p--)c.unshift(l),l*=n[p];let m=r.size,d=c[u];for(let p=0;p<m;p++){let f=Number(a[p]);Math.floor(p/d)%i===0?s[p]=isNaN(f)?1:f:s[p]=s[p-d]*(isNaN(f)?1:f)}return x.fromData(s,[...n],"float64")}function St(r,t,e=!1){q(r.dtype,"nanmedian","Complex numbers are not orderable.");let n=r.shape,o=n.length,a=r.data;if(t===void 0){let d=[];for(let y=0;y<r.size;y++){let g=Number(a[y]);isNaN(g)||d.push(g)}if(d.length===0)return NaN;d.sort((y,g)=>y-g);let p=d.length,f=Math.floor(p/2);return p%2===0?(d[f-1]+d[f])/2:d[f]}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((d,p)=>p!==u);if(s.length===0)return St(r);let i=s.reduce((d,p)=>d*p,1),c=n[u],l=new Float64Array(i);for(let d=0;d<i;d++){let p=[];for(let g=0;g<c;g++){let h=$(d,u,g,n),b=U(h,n),A=Number(a[b]);isNaN(A)||p.push(A)}if(p.length===0){l[d]=NaN;continue}p.sort((g,h)=>g-h);let f=p.length,y=Math.floor(f/2);f%2===0?l[d]=(p[y-1]+p[y])/2:l[d]=p[y]}let m=x.fromData(l,s,"float64");if(e){let d=[...n];return d[u]=1,x.fromData(l,d,"float64")}return m}function nr(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((m,d,p)=>p===o?m:m*d,1),l=e/c;if(!Number.isInteger(l))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((m,d)=>d===o?l:m)}else a=t;if(a.reduce((c,l)=>c*l,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){let c=r.data;return x.fromData(c,a,n,ar(a),0)}let i=r.copy().data;return x.fromData(i,a,n,ar(a),0)}function Dt(r){let t=r.size,e=r.dtype,n=P(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let s=r.data.slice(r.offset,r.offset+t);return x.fromData(s,[t],e,[1],0)}let o=new n(t),a=B(e);for(let u=0;u<t;u++){let s=r.iget(u);o[u]=s}return x.fromData(o,[t],e,[1],0)}function kr(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return x.fromData(n,[t],e,[1],0)}return Dt(r)}function Kr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype,s;if(t===void 0)s=Array.from({length:n},(m,d)=>n-1-d);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let m=new Set;for(let d of t){let p=d<0?n+d:d;if(p<0||p>=n)throw new Error(`axis ${d} is out of bounds for array of dimension ${n}`);if(m.has(p))throw new Error("repeated axis in transpose");m.add(p)}s=t.map(d=>d<0?n+d:d)}let i=s.map(m=>e[m]),c=Array.from(o),l=s.map(m=>c[m]);return x.fromData(a,i,u,l,r.offset)}function co(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype;if(t===void 0){let s=[],i=[];for(let c=0;c<n;c++)e[c]!==1&&(s.push(e[c]),i.push(o[c]));return s.length===0&&(s.push(1),i.push(1)),x.fromData(a,s,u,i,r.offset)}else{let s=t<0?n+t:t;if(s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[s]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[s]})`);let i=[],c=[];for(let l=0;l<n;l++)l!==s&&(i.push(e[l]),c.push(o[l]));return x.fromData(a,i,u,c,r.offset)}}function Qr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype,s=t;if(s<0&&(s=n+t+1),s<0||s>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let i=[...Array.from(e)];i.splice(s,0,1);let c=[...Array.from(o)],l=s<n?o[s]*(e[s]||1):1;return c.splice(s,0,l),x.fromData(a,i,u,c,r.offset)}function lo(r,t,e){let n=r.shape,o=n.length,a=r.strides,u=r.data,s=r.dtype,i=t<0?o+t:t,c=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${o}`);if(c<0||c>=o)throw new Error(`axis2 ${e} is out of bounds for array of dimension ${o}`);if(i===c)return x.fromData(u,Array.from(n),s,Array.from(a),r.offset);let l=Array.from(n),m=Array.from(a);return[l[i],l[c]]=[l[c],l[i]],[m[i],m[c]]=[m[c],m[i]],x.fromData(u,l,s,m,r.offset)}function le(r,t,e){let n=r.ndim,o=Array.isArray(t)?t:[t],a=Array.isArray(e)?e:[e];if(o.length!==a.length)throw new Error("source and destination must have the same number of elements");let u=o.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`source axis ${c} is out of bounds for array of dimension ${n}`);return l}),s=a.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`destination axis ${c} is out of bounds for array of dimension ${n}`);return l});if(new Set(u).size!==u.length)throw new Error("repeated axis in source");if(new Set(s).size!==s.length)throw new Error("repeated axis in destination");let i=[];for(let c=0;c<n;c++)u.includes(c)||i.push(c);for(let c=0;c<u.length;c++){let l=s[c];i.splice(l,0,u[c])}return Kr(r,i)}function Mr(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();let e=r[0],n=e.ndim,o=e.dtype,a=t<0?n+t:t;if(a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);for(let p=1;p<r.length;p++){let f=r[p];if(f.ndim!==n)throw new Error("all the input arrays must have same number of dimensions");for(let y=0;y<n;y++)if(y!==a&&f.shape[y]!==e.shape[y])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}let u=Array.from(e.shape),s=e.shape[a];for(let p=1;p<r.length;p++)s+=r[p].shape[a];u[a]=s;let i=u.reduce((p,f)=>p*f,1),c=P(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(i),m=ar(u),d=0;for(let p of r){let f=p.shape[a];Dm(p,l,u,m,a,d,o),d+=f}return x.fromData(l,u,o)}function Dm(r,t,e,n,o,a,u){let s=r.shape,i=s.length,c=r.size,l=u==="int64"||u==="uint64";if(o===0&&r.isCContiguous&&i>0){let p=a*n[0],f=r.data,y=r.offset,g=y+c;t.set(f.subarray(y,g),p);return}if(o===1&&i===2&&r.isCContiguous){let p=s[0],f=s[1],y=e[1],g=r.data,h=r.offset;for(let b=0;b<p;b++){let A=h+b*f,S=b*y+a;t.set(g.subarray(A,A+f),S)}return}let m=new Array(i).fill(0),d=a*n[o];for(let p=0;p<c;p++){let f=r.iget(p),y=d;for(let g=0;g<i;g++)y+=m[g]*n[g];t[y]=f;for(let g=i-1;g>=0&&(m[g]++,!(m[g]<s[g]));g--)m[g]=0}}function fo(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let s=1;s<r.length;s++){let i=r[s];if(i.ndim!==o)throw new Error("all input arrays must have the same shape");for(let c=0;c<o;c++)if(i.shape[c]!==n[c])throw new Error("all input arrays must have the same shape")}let u=r.map(s=>Qr(s,a));return Mr(u,a)}function mo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?nr(e,[1,e.shape[0]]):e);return Mr(t,0)}function fe(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?Mr(r,0):Mr(r,1)}function yo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?nr(Qr(nr(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?Qr(e,2):e);return Mr(t,2)}function po(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[a],s;if(typeof t=="number"){if(u%t!==0)throw new Error("array split does not result in an equal division");let i=u/t;s=[];for(let c=1;c<t;c++)s.push(c*i)}else s=t;return go(r,s,a)}function rt(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[a],s;if(typeof t=="number"){let i=t,c=Math.floor(u/i),l=u%i;s=[];let m=0;for(let d=0;d<i-1;d++)m+=c+(d<l?1:0),s.push(m)}else s=t;return go(r,s,a)}function go(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],u=[];for(let s=0;s<a.length-1;s++){let i=a[s],c=a[s+1];if(i>c)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=c-i;let m=r.offset+i*r.strides[e];u.push(x.fromData(r.data,l,r.dtype,Array.from(r.strides),m))}return u}function Ao(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return rt(r,t,0)}function bo(r,t){if(r.ndim<1)throw new Error("hsplit only works on arrays of 1 or more dimensions");let e=r.ndim===1?0:1;return rt(r,t,e)}function ho(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],u=Math.max(n,a.length),s=new Array(u).fill(1),i=new Array(u).fill(1);for(let b=0;b<n;b++)s[u-n+b]=e[b];for(let b=0;b<a.length;b++)i[u-a.length+b]=a[b];let c=s.map((b,A)=>b*i[A]),l=c.reduce((b,A)=>b*A,1),m=P(o);if(!m)throw new Error(`Cannot tile array with dtype ${o}`);let d=new m(l),p=ar(c),f=r;n<u&&(f=nr(r,s));let y=o==="int64"||o==="uint64",g=f.strides,h=new Array(u).fill(0);for(let b=0;b<l;b++){let A=f.offset;for(let w=0;w<u;w++){let N=h[w]%s[w];A+=N*g[w]}let S=f.data[A],D=0;for(let w=0;w<u;w++)D+=h[w]*p[w];d[D]=S;for(let w=u-1;w>=0&&(h[w]++,!(h[w]<c[w]));w--)h[w]=0}return x.fromData(d,c,o)}function So(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=r.size;if(e===void 0){let b=u,A=Array.isArray(t)?t:new Array(b).fill(t);if(A.length!==b)throw new Error(`operands could not be broadcast together with shape (${b},) (${A.length},)`);let S=A.reduce((I,z)=>I+z,0),D=P(a);if(!D)throw new Error(`Cannot repeat array with dtype ${a}`);let w=new D(S),N=0;for(let I=0;I<b;I++){let z=r.iget(I),F=A[I];for(let _=0;_<F;_++)w[N++]=z}return x.fromData(w,[S],a)}let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[s],c=Array.isArray(t)?t:new Array(i).fill(t);if(c.length!==i)throw new Error(`operands could not be broadcast together with shape (${i},) (${c.length},)`);let l=Array.from(n);l[s]=c.reduce((b,A)=>b+A,0);let m=l.reduce((b,A)=>b*A,1),d=P(a);if(!d)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new d(m),f=ar(l),y=new Array(o).fill(0),g=a==="int64"||a==="uint64",h=[0];for(let b=0;b<i;b++)h.push(h[b]+c[b]);for(let b=0;b<u;b++){let A=r.iget(b),S=y[s],D=c[S],w=0;for(let z=0;z<o;z++)z!==s&&(w+=y[z]*f[z]);let N=f[s],I=h[S];for(let z=0;z<D;z++){let F=w+(I+z)*N;p[F]=A}for(let z=o-1;z>=0&&(y[z]++,!(y[z]<n[z]));z--)y[z]=0}return x.fromData(p,l,a)}function Do(r,t){let e=r.shape,n=e.length,o=r.dtype,a=r.size,u;if(t===void 0)u=new Set(Array.from({length:n},(d,p)=>p));else if(typeof t=="number"){let d=t<0?n+t:t;if(d<0||d>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);u=new Set([d])}else u=new Set(t.map(d=>{let p=d<0?n+d:d;if(p<0||p>=n)throw new Error(`axis ${d} is out of bounds for array of dimension ${n}`);return p}));let s=P(o);if(!s)throw new Error(`Cannot flip array with dtype ${o}`);let i=new s(a),c=B(o);if(n===1&&r.isCContiguous){let d=r.data,p=r.offset;for(let f=0;f<a;f++)i[f]=d[p+a-1-f];return x.fromData(i,[...e],o)}if(n===2&&r.isCContiguous){let d=e[0],p=e[1],f=r.data,y=r.offset;if(u.size===2){for(let g=0;g<a;g++)i[g]=f[y+a-1-g];return x.fromData(i,[...e],o)}if(u.size===1){if(u.has(0)){for(let g=0;g<d;g++){let h=y+(d-1-g)*p,b=g*p;for(let A=0;A<p;A++)i[b+A]=f[h+A]}return x.fromData(i,[...e],o)}else if(u.has(1)){for(let g=0;g<d;g++){let h=y+g*p,b=g*p;for(let A=0;A<p;A++)i[b+A]=f[h+p-1-A]}return x.fromData(i,[...e],o)}}}let l=new Array(n),m=new Array(n).fill(0);for(let d=0;d<a;d++){for(let y=0;y<n;y++)l[y]=u.has(y)?e[y]-1-m[y]:m[y];let p=r.offset;for(let y=0;y<n;y++)p+=l[y]*r.strides[y];let f=r.data[p];i[d]=f;for(let y=n-1;y>=0&&(m[y]++,!(m[y]<e[y]));y--)m[y]=0}return x.fromData(i,[...e],o)}function xo(r,t=1,e=[0,1]){let n=r.shape,o=n.length,a=r.dtype;if(o<2)throw new Error("Input must be at least 2-D");let u=e[0]<0?o+e[0]:e[0],s=e[1]<0?o+e[1]:e[1];if(u<0||u>=o||s<0||s>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(u===s)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let i=P(a);if(!i)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[u],c[s]]=[c[s],c[u]]);let l=c.reduce((g,h)=>g*h,1),m=new i(l),d=ar(c),p=B(a),f=new Array(o).fill(0),y=new Array(o);for(let g=0;g<r.size;g++){for(let D=0;D<o;D++)y[D]=f[D];let h,b;t===1?(h=n[s]-1-f[s],b=f[u]):t===2?(h=n[u]-1-f[u],b=n[s]-1-f[s],y[u]=h,y[s]=b):(h=f[s],b=n[u]-1-f[u]),t!==2&&(y[u]=h,y[s]=b);let A=0;for(let D=0;D<o;D++)A+=y[D]*d[D];let S=r.iget(g);m[A]=S;for(let D=o-1;D>=0&&(f[D]++,!(f[D]<n[D]));D--)f[D]=0}return x.fromData(m,c,a)}function No(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=r.size;if(e===void 0){let f=Array.isArray(t)?t.reduce((A,S)=>A+S,0):t,y=Dt(r),g=P(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let h=new g(u),b=B(a);for(let A=0;A<u;A++){let S=((A-f)%u+u)%u,D=y.iget(S);h[A]=D}return x.fromData(h,[...n],a)}let s=Array.isArray(t)?t:[t],i=Array.isArray(e)?e:[e];if(s.length!==i.length)throw new Error("shift and axis must have the same length");let c=i.map(f=>{let y=f<0?o+f:f;if(y<0||y>=o)throw new Error(`axis ${f} is out of bounds for array of dimension ${o}`);return y}),l=P(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let m=new l(u),d=B(a),p=new Array(o).fill(0);for(let f=0;f<u;f++){let y=[...p];for(let b=0;b<c.length;b++){let A=c[b],S=n[A],D=s[b];y[A]=((y[A]-D)%S+S)%S}let g=r.offset;for(let b=0;b<o;b++)g+=y[b]*r.strides[b];let h=r.data[g];m[f]=h;for(let b=o-1;b>=0&&(p[b]++,!(p[b]<n[b]));b--)p[b]=0}return x.fromData(m,[...n],a)}function wo(r,t,e=0){let n=r.ndim,o=t<0?n+t:t;if(o<0||o>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let a=e<0?n+e:e;if(a<0||a>n)throw new Error(`start ${e} is out of bounds`);return o<a&&a--,o===a?x.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):le(r,o,a)}function Io(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return rt(r,t,2)}function zo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?nr(e,[e.shape[0],1]):e);return fe(t)}function _o(r,t){let e=r.dtype,n=t.reduce((i,c)=>i*c,1),o=r.size,a=P(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let u=new a(n),s=B(e);for(let i=0;i<n;i++){let c=i%o,l=r.iget(c);u[i]=l}return x.fromData(u,t,e)}function Fo(r){return r.map(t=>t.ndim===0?nr(t,[1]):t)}function Mo(r){return r.map(t=>t.ndim===0?nr(t,[1,1]):t.ndim===1?nr(t,[1,t.shape[0]]):t)}function Bo(r){return r.map(t=>t.ndim===0?nr(t,[1,1,1]):t.ndim===1?nr(t,[1,t.shape[0],1]):t.ndim===2?nr(t,[t.shape[0],t.shape[1],1]):t)}function qr(r,t){if(r instanceof O||t instanceof O){let e=r instanceof O?r:new O(Number(r),0),n=t instanceof O?t:new O(Number(t),0);return e.mul(n)}return typeof r=="bigint"&&typeof t=="bigint"?Number(r*t):Number(r)*Number(t)}function xm(r,t,e,n,o,a,u,s,i,c,l,m,d,p){if(m===0)for(let h=0;h<n*o;h++)d[h]=0;else if(m!==1)for(let h=0;h<n*o;h++)d[h]=(d[h]??0)*m;let f=r==="row-major",y=t==="transpose",g=e==="transpose";if(f&&!y&&!g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[h*i+S]??0)*(c[S*l+b]??0);d[h*p+b]=(d[h*p+b]??0)+u*A}else if(f&&y&&!g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[S*i+h]??0)*(c[S*l+b]??0);d[h*p+b]=(d[h*p+b]??0)+u*A}else if(f&&!y&&g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[h*i+S]??0)*(c[b*l+S]??0);d[h*p+b]=(d[h*p+b]??0)+u*A}else if(f&&y&&g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[S*i+h]??0)*(c[b*l+S]??0);d[h*p+b]=(d[h*p+b]??0)+u*A}else if(!f&&!y&&!g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[S*i+h]??0)*(c[b*l+S]??0);d[b*p+h]=(d[b*p+h]??0)+u*A}else if(!f&&y&&!g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[h*i+S]??0)*(c[b*l+S]??0);d[b*p+h]=(d[b*p+h]??0)+u*A}else if(!f&&!y&&g)for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[S*i+h]??0)*(c[S*l+b]??0);d[b*p+h]=(d[b*p+h]??0)+u*A}else for(let h=0;h<n;h++)for(let b=0;b<o;b++){let A=0;for(let S=0;S<a;S++)A+=(s[h*i+S]??0)*(c[S*l+b]??0);d[b*p+h]=(d[b*p+h]??0)+u*A}}function ye(r,t){let e=r.ndim,n=t.ndim,o=M(r.dtype)||M(t.dtype);if(e===0||n===0){let a=e===0?r.get():null,u=n===0?t.get():null;if(e===0&&n===0)return qr(a,u);if(e===0){let s=G(r.dtype,t.dtype),i=x.zeros([...t.shape],s),c=(l,m)=>{let d=new Array(m.length),p=l;for(let f=m.length-1;f>=0;f--)d[f]=p%m[f],p=Math.floor(p/m[f]);return d};for(let l=0;l<t.size;l++){let m=c(l,t.shape),d=t.get(...m);i.set(m,qr(a,d))}return i}else{let s=G(r.dtype,t.dtype),i=x.zeros([...r.shape],s),c=(l,m)=>{let d=new Array(m.length),p=l;for(let f=m.length-1;f>=0;f--)d[f]=p%m[f],p=Math.floor(p/m[f]);return d};for(let l=0;l<r.size;l++){let m=c(l,r.shape),d=r.get(...m);i.set(m,qr(d,u))}return i}}if(e===1&&n===1){if(r.shape[0]!==t.shape[0])throw new Error(`dot: incompatible shapes (${r.shape[0]},) and (${t.shape[0]},)`);let a=r.shape[0];if(o){let s=0,i=0;for(let c=0;c<a;c++){let l=r.get(c),m=t.get(c),d=qr(l,m);d instanceof O?(s+=d.re,i+=d.im):s+=d}return new O(s,i)}let u=0;for(let s=0;s<a;s++){let i=r.get(s),c=t.get(s);typeof i=="bigint"&&typeof c=="bigint"?u=Number(u)+Number(i*c):u+=Number(i)*Number(c)}return u}if(e===2&&n===2)return pr(r,t);if(e===2&&n===1){let[a,u]=r.shape,s=t.shape[0];if(u!==s)throw new Error(`dot: incompatible shapes (${a},${u}) and (${s},)`);let i=G(r.dtype,t.dtype),c=x.zeros([a],i);if(o)for(let l=0;l<a;l++){let m=0,d=0;for(let p=0;p<u;p++){let f=r.get(l,p),y=t.get(p),g=f instanceof O?f:new O(Number(f),0),h=y instanceof O?y:new O(Number(y),0);m+=g.re*h.re-g.im*h.im,d+=g.re*h.im+g.im*h.re}c.set([l],new O(m,d))}else for(let l=0;l<a;l++){let m=0;for(let d=0;d<u;d++){let p=r.get(l,d),f=t.get(d);typeof p=="bigint"&&typeof f=="bigint"?m=Number(m)+Number(p*f):m+=Number(p)*Number(f)}c.set([l],m)}return c}if(e===1&&n===2){let a=r.shape[0],[u,s]=t.shape;if(a!==u)throw new Error(`dot: incompatible shapes (${a},) and (${u},${s})`);let i=G(r.dtype,t.dtype),c=x.zeros([s],i);if(o)for(let l=0;l<s;l++){let m=0,d=0;for(let p=0;p<a;p++){let f=r.get(p),y=t.get(p,l),g=f instanceof O?f:new O(Number(f),0),h=y instanceof O?y:new O(Number(y),0);m+=g.re*h.re-g.im*h.im,d+=g.re*h.im+g.im*h.re}c.set([l],new O(m,d))}else for(let l=0;l<s;l++){let m=0;for(let d=0;d<a;d++){let p=r.get(d),f=t.get(d,l);typeof p=="bigint"&&typeof f=="bigint"?m=Number(m)+Number(p*f):m+=Number(p)*Number(f)}c.set([l],m)}return c}if(e>2&&n===1){let a=r.shape[e-1],u=t.shape[0];if(a!==u)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and (${u},)`);let s=[...r.shape.slice(0,-1)],i=G(r.dtype,t.dtype),c=x.zeros(s,i),l=s.reduce((m,d)=>m*d,1);if(o)for(let m=0;m<l;m++){let d=0,p=0,f=m,y=[];for(let g=s.length-1;g>=0;g--)y[g]=f%s[g],f=Math.floor(f/s[g]);for(let g=0;g<a;g++){let h=[...y,g],b=r.get(...h),A=t.get(g),S=b instanceof O?b:new O(Number(b),0),D=A instanceof O?A:new O(Number(A),0);d+=S.re*D.re-S.im*D.im,p+=S.re*D.im+S.im*D.re}c.set(y,new O(d,p))}else for(let m=0;m<l;m++){let d=0,p=m,f=[];for(let y=s.length-1;y>=0;y--)f[y]=p%s[y],p=Math.floor(p/s[y]);for(let y=0;y<a;y++){let g=[...f,y],h=r.get(...g),b=t.get(y);typeof h=="bigint"&&typeof b=="bigint"?d=Number(d)+Number(h*b):d+=Number(h)*Number(b)}c.set(f,d)}return c}if(e===1&&n>2){let a=r.shape[0],u=1,s=t.shape[u];if(a!==s)throw new Error(`dot: incompatible shapes (${a},) and ${JSON.stringify(t.shape)}`);let i=[...t.shape.slice(0,u),...t.shape.slice(u+1)],c=G(r.dtype,t.dtype),l=x.zeros(i,c),m=i.reduce((d,p)=>d*p,1);if(o)for(let d=0;d<m;d++){let p=d,f=[];for(let A=i.length-1;A>=0;A--)f[A]=p%i[A],p=Math.floor(p/i[A]);let y=f.slice(0,u),g=f.slice(u),h=0,b=0;for(let A=0;A<a;A++){let S=r.get(A),D=[...y,A,...g],w=t.get(...D),N=S instanceof O?S:new O(Number(S),0),I=w instanceof O?w:new O(Number(w),0);h+=N.re*I.re-N.im*I.im,b+=N.re*I.im+N.im*I.re}l.set(f,new O(h,b))}else for(let d=0;d<m;d++){let p=d,f=[];for(let b=i.length-1;b>=0;b--)f[b]=p%i[b],p=Math.floor(p/i[b]);let y=f.slice(0,u),g=f.slice(u),h=0;for(let b=0;b<a;b++){let A=r.get(b),S=[...y,b,...g],D=t.get(...S);typeof A=="bigint"&&typeof D=="bigint"?h=Number(h)+Number(A*D):h+=Number(A)*Number(D)}l.set(f,h)}return l}if(e>=2&&n>=2&&!(e===2&&n===2)){let a=r.shape[e-1],u=t.shape[n-2];if(a!==u)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and ${JSON.stringify(t.shape)}`);let s=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],i=G(r.dtype,t.dtype),c=x.zeros(s,i),l=r.shape.slice(0,-1).reduce((f,y)=>f*y,1),m=t.shape.slice(0,-2).reduce((f,y)=>f*y,1),d=t.shape[n-1],p=a;if(o)for(let f=0;f<l;f++)for(let y=0;y<m;y++)for(let g=0;g<d;g++){let h=0,b=0;for(let D=0;D<p;D++){let w=[],N=f;for(let C=r.shape.length-2;C>=0;C--)w.unshift(N%r.shape[C]),N=Math.floor(N/r.shape[C]);w.push(D);let I=r.get(...w),z=[],F=y;for(let C=t.shape.length-3;C>=0;C--)z.unshift(F%t.shape[C]),F=Math.floor(F/t.shape[C]);z.push(D,g);let _=t.get(...z),E=I instanceof O?I:new O(Number(I),0),T=_ instanceof O?_:new O(Number(_),0);h+=E.re*T.re-E.im*T.im,b+=E.re*T.im+E.im*T.re}let A=f*m*d+y*d+g,S=c.data;S[A*2]=h,S[A*2+1]=b}else for(let f=0;f<l;f++)for(let y=0;y<m;y++)for(let g=0;g<d;g++){let h=0;for(let A=0;A<p;A++){let S=f*p+A,D=y*p*d+A*d+g,w=r.data[S+r.offset],N=t.data[D+t.offset];typeof w=="bigint"&&typeof N=="bigint"?h=Number(h)+Number(w*N):h+=Number(w)*Number(N)}let b=f*m*d+y*d+g;c.data[b]=h}return c}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function pr(r,t){if(r.ndim!==2||t.ndim!==2)throw new Error("matmul requires 2D arrays");let[e=0,n=0]=r.shape,[o=0,a=0]=t.shape;if(n!==o)throw new Error(`matmul shape mismatch: (${e},${n}) @ (${o},${a})`);let u=G(r.dtype,t.dtype);if(M(u)){let D=x.zeros([e,a],u),w=D.data,N=r.data,I=t.data;for(let z=0;z<e;z++)for(let F=0;F<a;F++){let _=0,E=0;for(let C=0;C<n;C++){let k=(z*n+C)*2,V=(C*a+F)*2,R=N[k],L=N[k+1],j=I[V],H=I[V+1];_+=R*j-L*H,E+=R*H+L*j}let T=z*a+F;w[T*2]=_,w[T*2+1]=E}return D}let s=u.startsWith("int")||u.startsWith("uint")||u==="bool"?"float64":u;if(s!=="float64")throw new Error(`matmul currently only supports float64, got ${s}`);let i=r.dtype==="float64"?r.data:Float64Array.from(Array.from(r.data).map(Number)),c=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number));r.offset>0&&(i=i.subarray(r.offset)),t.offset>0&&(c=c.subarray(t.offset));let[l=0,m=0]=r.strides,[d=0,p=0]=t.strides,f=m>l,y=p>d,g=f?"transpose":"no-transpose",h=y?"transpose":"no-transpose",b,A;f?b=m:b=l,y?A=p:A=d;let S=x.zeros([e,a],"float64");return xm("row-major",g,h,e,a,n,1,i,b,c,A,0,S.data,a),S}function Oo(r){if(r.ndim!==2)throw new Error(`trace requires 2D array, got ${r.ndim}D`);let[t=0,e=0]=r.shape,n=Math.min(t,e);if(M(r.dtype)){let a=0,u=0;for(let s=0;s<n;s++){let i=r.get(s,s);a+=i.re,u+=i.im}return new O(a,u)}let o=0;for(let a=0;a<n;a++){let u=r.get(a,a);typeof u=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+u:o=(typeof o=="bigint"?Number(o):o)+u}return o}function Eo(r,t){return Kr(r,t)}function Co(r,t){let e=r.ndim,n=t.ndim,o=M(r.dtype)||M(t.dtype),a=r.shape[e-1],u=t.shape[n-1];if(a!==u)throw new Error(`inner: incompatible shapes - last dimensions ${a} and ${u} don't match`);if(e===1&&n===1)return ye(r,t);let s=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],i=G(r.dtype,t.dtype),c=x.zeros(s,i),l=e===1?1:r.shape.slice(0,-1).reduce((p,f)=>p*f,1),m=n===1?1:t.shape.slice(0,-1).reduce((p,f)=>p*f,1),d=a;if(o)for(let p=0;p<l;p++)for(let f=0;f<m;f++){let y=0,g=0;for(let A=0;A<d;A++){let S,D;if(e===1)S=r.get(A);else{let I=[],z=p,F=r.shape.slice(0,-1);for(let _=F.length-1;_>=0;_--)I.unshift(z%F[_]),z=Math.floor(z/F[_]);I.push(A),S=r.get(...I)}if(n===1)D=t.get(A);else{let I=[],z=f,F=t.shape.slice(0,-1);for(let _=F.length-1;_>=0;_--)I.unshift(z%F[_]),z=Math.floor(z/F[_]);I.push(A),D=t.get(...I)}let w=S instanceof O?S:new O(Number(S),0),N=D instanceof O?D:new O(Number(D),0);y+=w.re*N.re-w.im*N.im,g+=w.re*N.im+w.im*N.re}if(s.length===0)return new O(y,g);let h=l===1?f:p*m+f,b=c.data;b[h*2]=y,b[h*2+1]=g}else for(let p=0;p<l;p++)for(let f=0;f<m;f++){let y=0;for(let h=0;h<d;h++){let b=e===1?h:p*d+h,A=n===1?h:f*d+h,S=r.data[b+r.offset],D=t.data[A+t.offset];typeof S=="bigint"&&typeof D=="bigint"?y=Number(y)+Number(S*D):y+=Number(S)*Number(D)}if(s.length===0)return y;let g=l===1?f:p*m+f;c.data[g]=y}return c}function pe(r,t){let e=r.ndim===1?r:kr(r),n=t.ndim===1?t:kr(t),o=e.size,a=n.size,u=G(r.dtype,t.dtype),s=x.zeros([o,a],u);for(let i=0;i<o;i++)for(let c=0;c<a;c++){let l=e.get(i),m=n.get(c),d=qr(l,m);s.set([i,c],d)}return s}function Uo(r,t,e){let n,o;if(typeof e=="number"){let f=e;if(f<0)throw new Error("tensordot: axes must be non-negative");if(f>r.ndim||f>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:f},(y,g)=>r.ndim-f+g),o=Array.from({length:f},(y,g)=>g)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let f=0;f<n.length;f++){let y=n[f],g=o[f];if(y<0||y>=r.ndim||g<0||g>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[y]!==t.shape[g])throw new Error(`tensordot: shape mismatch on axes ${y} and ${g}: ${r.shape[y]} != ${t.shape[g]}`)}let a=[],u=[];for(let f=0;f<r.ndim;f++)n.includes(f)||a.push(f);for(let f=0;f<t.ndim;f++)o.includes(f)||u.push(f);let s=[...a.map(f=>r.shape[f]),...u.map(f=>t.shape[f])],i=G(r.dtype,t.dtype),c=M(i),l=f=>f instanceof O?{re:f.re,im:f.im}:{re:Number(f),im:0};if(s.length===0){let f=0,y=0,g=n.map(h=>r.shape[h]).reduce((h,b)=>h*b,1);for(let h=0;h<g;h++){let b=h,A=new Array(n.length);for(let I=n.length-1;I>=0;I--){let z=n[I];A[I]=b%r.shape[z],b=Math.floor(b/r.shape[z])}let S=new Array(r.ndim),D=new Array(t.ndim);for(let I=0;I<n.length;I++)S[n[I]]=A[I];for(let I=0;I<o.length;I++)D[o[I]]=A[I];let w=r.get(...S),N=t.get(...D);if(c){let I=l(w),z=l(N);f+=I.re*z.re-I.im*z.im,y+=I.re*z.im+I.im*z.re}else typeof w=="bigint"&&typeof N=="bigint"?f+=Number(w*N):f+=Number(w)*Number(N)}return c?new O(f,y):f}let m=x.zeros(s,i),d=s.reduce((f,y)=>f*y,1),p=n.map(f=>r.shape[f]).reduce((f,y)=>f*y,1);for(let f=0;f<d;f++){let y=f,g=[];for(let D=s.length-1;D>=0;D--)g[D]=y%s[D],y=Math.floor(y/s[D]);let h=g.slice(0,a.length),b=g.slice(a.length),A=0,S=0;for(let D=0;D<p;D++){y=D;let w=[];for(let _=n.length-1;_>=0;_--){let E=n[_];w[_]=y%r.shape[E],y=Math.floor(y/r.shape[E])}let N=new Array(r.ndim),I=new Array(t.ndim);for(let _=0;_<a.length;_++)N[a[_]]=h[_];for(let _=0;_<u.length;_++)I[u[_]]=b[_];for(let _=0;_<n.length;_++)N[n[_]]=w[_],I[o[_]]=w[_];let z=r.get(...N),F=t.get(...I);if(c){let _=l(z),E=l(F);A+=_.re*E.re-_.im*E.im,S+=_.re*E.im+_.im*E.re}else typeof z=="bigint"&&typeof F=="bigint"?A+=Number(z*F):A+=Number(z)*Number(F)}c?m.set(g,new O(A,S)):m.set(g,A)}return m}function $o(r,t=0,e=0,n=1){let o=r.shape,a=o.length;if(a<2)throw new Error("diagonal requires an array of at least two dimensions");let u=e<0?a+e:e,s=n<0?a+n:n;if(u<0||u>=a||s<0||s>=a)throw new Error("axis out of bounds");if(u===s)throw new Error("axis1 and axis2 cannot be the same");let i=o[u],c=o[s],l;t>=0?l=Math.max(0,Math.min(i,c-t)):l=Math.max(0,Math.min(i+t,c));let m=[];for(let y=0;y<a;y++)y!==u&&y!==s&&m.push(o[y]);m.push(l);let d=x.zeros(m,r.dtype),p=o.filter((y,g)=>g!==u&&g!==s),f=p.reduce((y,g)=>y*g,1);for(let y=0;y<f;y++){let g=y,h=[];for(let b=p.length-1;b>=0;b--)h.unshift(g%p[b]),g=Math.floor(g/p[b]);for(let b=0;b<l;b++){let A=new Array(a),S=0;for(let N=0;N<a;N++)N===u?A[N]=t>=0?b:b-t:N===s?A[N]=t>=0?b+t:b:A[N]=h[S++];let D=[...h,b],w=r.get(...A);d.set(D,w)}}return d}function Ro(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=Nm(n)):(n=r.slice(0,e),o=r.slice(e+2));let a=n.split(",").map(y=>y.trim());if(a.length!==t.length)throw new Error(`einsum: expected ${a.length} operands, got ${t.length}`);let u=new Map;for(let y=0;y<t.length;y++){let g=a[y],h=t[y];if(g.length!==h.ndim)throw new Error(`einsum: operand ${y} has ${h.ndim} dimensions but subscript '${g}' has ${g.length} indices`);for(let b=0;b<g.length;b++){let A=g[b],S=h.shape[b];if(u.has(A)){if(u.get(A)!==S)throw new Error(`einsum: size mismatch for index '${A}': ${u.get(A)} vs ${S}`)}else u.set(A,S)}}for(let y of o)if(!u.has(y))throw new Error(`einsum: output subscript contains unknown index '${y}'`);let s=new Set(o),i=new Set;for(let y of a)for(let g of y)i.add(g);let c=[];for(let y of i)s.has(y)||c.push(y);if(t.length===2&&a.length===2){let[y,g]=a,[h,b]=t;if(y.length===2&&g.length===2&&o.length===2&&h.ndim===2&&b.ndim===2){let[A,S]=[y[0],y[1]],[D,w]=[g[0],g[1]],[N,I]=[o[0],o[1]];if(A===N&&w===I&&S===D&&c.length===1&&c[0]===S||A===N&&w===I&&S===D&&c.length===1&&c[0]===S)return pr(h,b);if(S===N&&w===I&&A===D&&c.length===1&&c[0]===A){let z=Eo(h);return pr(z,b)}if(A===N&&D===I&&S===w&&c.length===1&&c[0]===S){let z=Eo(b);return pr(h,z)}}if(y.length===1&&g.length===1&&y===g&&o.length===0&&h.ndim===1&&b.ndim===1)return me(t,a,c,u);if(y&&g&&y.length===1&&g.length===1&&o.length===2&&o===y+g&&c.length===0&&h.ndim===1&&b.ndim===1)return pe(h,b)}if(t.length===1&&a[0].length===2&&o.length===0){let y=a[0];if(y[0]===y[1]&&t[0].ndim===2)return me(t,a,c,u)}let l=Array.from(o).map(y=>u.get(y));if(l.length===0)return me(t,a,c,u);let m=t[0].dtype;for(let y=1;y<t.length;y++)m=G(m,t[y].dtype);let d=x.zeros(l,m),p=l.reduce((y,g)=>y*g,1),f=1;for(let y of c)f*=u.get(y);for(let y=0;y<p;y++){let g=wm(y,l),h=new Map;for(let A=0;A<o.length;A++)h.set(o[A],g[A]);let b=0;for(let A=0;A<f;A++){let S=A;for(let w=c.length-1;w>=0;w--){let N=c[w],I=u.get(N);h.set(N,S%I),S=Math.floor(S/I)}let D=1;for(let w=0;w<t.length;w++){let N=t[w],I=a[w],z=[];for(let _ of I)z.push(h.get(_));let F=N.get(...z);D*=Number(F)}b+=D}d.set(g,b)}return d}function Nm(r){let t=new Map,e=r.split(",");for(let o of e)for(let a of o.trim())t.set(a,(t.get(a)||0)+1);let n=[];for(let[o,a]of t)a===1&&n.push(o);return n.sort().join("")}function me(r,t,e,n){let o=!1;for(let c of r)if(M(c.dtype)){o=!0;break}let a=c=>c instanceof O?{re:c.re,im:c.im}:{re:Number(c),im:0},u=1;for(let c of e)u*=n.get(c);let s=0,i=0;for(let c=0;c<u;c++){let l=new Map,m=c;for(let f=e.length-1;f>=0;f--){let y=e[f],g=n.get(y);l.set(y,m%g),m=Math.floor(m/g)}let d=1,p=0;for(let f=0;f<r.length;f++){let y=r[f],g=t[f],h=[];for(let A of g)h.push(l.get(A));let b=y.get(...h);if(o){let A=a(b),S=d*A.re-p*A.im,D=d*A.im+p*A.re;d=S,p=D}else d*=Number(b)}s+=d,i+=p}return o?new O(s,i):s}function wm(r,t){let e=new Array(t.length),n=r;for(let o=t.length-1;o>=0;o--)e[o]=n%t[o],n=Math.floor(n/t[o]);return e}function ko(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,u=G(r.dtype,t.dtype),s=Math.max(o,a),i=new Array(s),c=new Array(s).fill(1),l=new Array(s).fill(1);for(let f=0;f<o;f++)c[s-o+f]=e[f];for(let f=0;f<a;f++)l[s-a+f]=n[f];for(let f=0;f<s;f++)i[f]=c[f]*l[f];let m=x.zeros(i,u),d=e.reduce((f,y)=>f*y,1),p=n.reduce((f,y)=>f*y,1);for(let f=0;f<d;f++){let y=f,g=new Array(o);for(let A=o-1;A>=0;A--)g[A]=y%e[A],y=Math.floor(y/e[A]);let h=new Array(s).fill(0);for(let A=0;A<o;A++)h[s-o+A]=g[A];let b=r.get(...g);for(let A=0;A<p;A++){let S=A,D=new Array(a);for(let F=a-1;F>=0;F--)D[F]=S%n[F],S=Math.floor(S/n[F]);let w=new Array(s).fill(0);for(let F=0;F<a;F++)w[s-a+F]=D[F];let N=t.get(...D),I=new Array(s);for(let F=0;F<s;F++)I[F]=h[F]*l[F]+w[F];let z=qr(b,N);m.set(I,z)}}return m}function qo(r,t,e=-1,n=-1,o=-1,a){a!==void 0&&(e=a,n=a,o=a);let u=(A,S)=>A<0?S+A:A,s=u(e,r.ndim),i=u(n,t.ndim);if(r.ndim===1&&t.ndim===1){let A=r.shape[0],S=t.shape[0];if(A===3&&S===3){let D=Number(r.get(0)),w=Number(r.get(1)),N=Number(r.get(2)),I=Number(t.get(0)),z=Number(t.get(1)),F=Number(t.get(2)),_=x.zeros([3],"float64");return _.set([0],w*F-N*z),_.set([1],N*I-D*F),_.set([2],D*z-w*I),_}else if(A===2&&S===2){let D=Number(r.get(0)),w=Number(r.get(1)),N=Number(t.get(0)),I=Number(t.get(1));return D*I-w*N}else if(A===2&&S===3||A===3&&S===2){let D=Number(r.get(0)),w=Number(r.get(1)),N=A===3?Number(r.get(2)):0,I=Number(t.get(0)),z=Number(t.get(1)),F=S===3?Number(t.get(2)):0,_=x.zeros([3],"float64");return _.set([0],w*F-N*z),_.set([1],N*I-D*F),_.set([2],D*z-w*I),_}else throw new Error(`cross: incompatible dimensions for cross product: ${A} and ${S}`)}let c=r.shape[s],l=t.shape[i];if(c!==2&&c!==3||l!==2&&l!==3)throw new Error(`cross: incompatible dimensions for cross product: ${c} and ${l}`);let m=c===2&&l===2?0:3,d=[...r.shape.slice(0,s),...r.shape.slice(s+1)],p=[...t.shape.slice(0,i),...t.shape.slice(i+1)];if(d.length!==p.length)throw new Error("cross: incompatible shapes for cross product");for(let A=0;A<d.length;A++)if(d[A]!==p[A])throw new Error("cross: incompatible shapes for cross product");let f=d,y=o<0?f.length+1+o:o,g;if(m===0?g=f:g=[...f.slice(0,y),m,...f.slice(y)],g.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");let h=x.zeros(g,"float64"),b=f.reduce((A,S)=>A*S,1);for(let A=0;A<b;A++){let S=A,D=[];for(let V=f.length-1;V>=0;V--)D[V]=S%f[V],S=Math.floor(S/f[V]);let w=[...D.slice(0,s),0,...D.slice(s)],N=[...D.slice(0,i),0,...D.slice(i)],I=V=>(w[s]=V,Number(r.get(...w))),z=V=>(N[i]=V,Number(t.get(...N))),F=I(0),_=I(1),E=c===3?I(2):0,T=z(0),C=z(1),k=l===3?z(2):0;if(m===0)h.set(D,F*C-_*T);else{let V=_*k-E*C,R=E*T-F*k,L=F*C-_*T,j=(H,Q)=>{let Z=[...D.slice(0,y),H,...D.slice(y)];h.set(Z,Q)};j(0,V),j(1,R),j(2,L)}}return h}function Vr(r,t=2,e,n=!1){if(typeof t!="number")throw new Error("vector_norm: ord must be a number");if(e==null){let c=r.ndim===1?r:kr(r),l=c.size,m;if(t===1/0){m=0;for(let d=0;d<l;d++)m=Math.max(m,Math.abs(Number(c.get(d))))}else if(t===-1/0){m=1/0;for(let d=0;d<l;d++)m=Math.min(m,Math.abs(Number(c.get(d))))}else if(t===0){m=0;for(let d=0;d<l;d++)Number(c.get(d))!==0&&m++}else if(t===1){m=0;for(let d=0;d<l;d++)m+=Math.abs(Number(c.get(d)))}else if(t===2){m=0;for(let d=0;d<l;d++){let p=Number(c.get(d));m+=p*p}m=Math.sqrt(m)}else{m=0;for(let d=0;d<l;d++)m+=Math.pow(Math.abs(Number(c.get(d))),t);m=Math.pow(m,1/t)}if(n){let d=new Array(r.ndim).fill(1),p=x.zeros(d,"float64");return p.set(new Array(r.ndim).fill(0),m),p}return m}let o=e<0?r.ndim+e:e;if(o<0||o>=r.ndim)throw new Error(`vector_norm: axis ${e} out of bounds for array with ${r.ndim} dimensions`);let a=n?[...r.shape.slice(0,o),1,...r.shape.slice(o+1)]:[...r.shape.slice(0,o),...r.shape.slice(o+1)];if(a.length===0)return Vr(r,t,null,!1);let u=x.zeros(a,"float64"),s=r.shape[o],i=a.reduce((c,l)=>c*l,1);for(let c=0;c<i;c++){let l=c,m=[];for(let f=a.length-1;f>=0;f--)m[f]=l%a[f],l=Math.floor(l/a[f]);let d=n?[...m.slice(0,o),0,...m.slice(o+1)]:[...m.slice(0,o),0,...m.slice(o)],p;if(t===1/0){p=0;for(let f=0;f<s;f++)d[o]=f,p=Math.max(p,Math.abs(Number(r.get(...d))))}else if(t===-1/0){p=1/0;for(let f=0;f<s;f++)d[o]=f,p=Math.min(p,Math.abs(Number(r.get(...d))))}else if(t===0){p=0;for(let f=0;f<s;f++)d[o]=f,Number(r.get(...d))!==0&&p++}else if(t===1){p=0;for(let f=0;f<s;f++)d[o]=f,p+=Math.abs(Number(r.get(...d)))}else if(t===2){p=0;for(let f=0;f<s;f++){d[o]=f;let y=Number(r.get(...d));p+=y*y}p=Math.sqrt(p)}else{p=0;for(let f=0;f<s;f++)d[o]=f,p+=Math.pow(Math.abs(Number(r.get(...d))),t);p=Math.pow(p,1/t)}u.set(m,p)}return u}function Br(r,t="fro",e=!1){if(r.ndim!==2)throw new Error(`matrix_norm: input must be 2D, got ${r.ndim}D`);let[n,o]=r.shape,a;if(t==="fro"){a=0;for(let u=0;u<n;u++)for(let s=0;s<o;s++){let i=Number(r.get(u,s));a+=i*i}a=Math.sqrt(a)}else if(t==="nuc"){let{s:u}=_r(r);a=0;for(let s=0;s<u.size;s++)a+=Number(u.get(s))}else if(t===1){a=0;for(let u=0;u<o;u++){let s=0;for(let i=0;i<n;i++)s+=Math.abs(Number(r.get(i,u)));a=Math.max(a,s)}}else if(t===-1){a=1/0;for(let u=0;u<o;u++){let s=0;for(let i=0;i<n;i++)s+=Math.abs(Number(r.get(i,u)));a=Math.min(a,s)}}else if(t===1/0){a=0;for(let u=0;u<n;u++){let s=0;for(let i=0;i<o;i++)s+=Math.abs(Number(r.get(u,i)));a=Math.max(a,s)}}else if(t===-1/0){a=1/0;for(let u=0;u<n;u++){let s=0;for(let i=0;i<o;i++)s+=Math.abs(Number(r.get(u,i)));a=Math.min(a,s)}}else if(t===2){let{s:u}=_r(r);a=Number(u.get(0))}else if(t===-2){let{s:u}=_r(r);a=Number(u.get(u.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${t}`);if(e){let u=x.zeros([1,1],"float64");return u.set([0,0],a),u}return a}function Vo(r,t=null,e=null,n=!1){if(t===null)return e===null?Vr(r,2,null,n):typeof e=="number"?Vr(r,2,e,n):Br(r,"fro",n);if(Array.isArray(e)){if(e.length!==2)throw new Error("norm: axis must be a 2-tuple for matrix norms");let o=e[0]<0?r.ndim+e[0]:e[0],a=e[1]<0?r.ndim+e[1]:e[1];if(r.ndim!==2||o!==0&&o!==1||a!==0&&a!==1||o===a)throw new Error("norm: complex axis specification not yet supported");return Br(r,t,n)}if(r.ndim===2&&e===null&&(t==="fro"||t==="nuc"))return Br(r,t,n);if(typeof t!="number"&&t!==null)throw new Error(`norm: ord '${t}' not valid for vector norm`);return Vr(r,t??2,e,n)}function de(r,t="reduced"){if(r.ndim!==2)throw new Error(`qr: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape,o=Math.min(e,n),a=x.zeros([e,n],"float64");for(let p=0;p<e;p++)for(let f=0;f<n;f++)a.set([p,f],Number(r.get(p,f)));let u=[],s=[];for(let p=0;p<o;p++){let f=e-p,y=[];for(let D=p;D<e;D++)y.push(Number(a.get(D,p)));let g=0;for(let D=0;D<f;D++)g+=y[D]*y[D];if(g=Math.sqrt(g),g<1e-15){u.push(y),s.push(0);continue}let h=y[0]>=0?1:-1,b=y[0]+h*g,A=[1];for(let D=1;D<f;D++)A.push(y[D]/b);let S=h*b/g;s.push(S),u.push(A);for(let D=p;D<n;D++){let w=0;for(let N=0;N<f;N++)w+=A[N]*Number(a.get(p+N,D));for(let N=0;N<f;N++)a.set([p+N,D],Number(a.get(p+N,D))-S*A[N]*w)}}if(t==="raw"){let p=x.zeros([e,n],"float64");for(let y=0;y<e;y++)for(let g=0;g<n;g++)p.set([y,g],Number(a.get(y,g)));let f=x.zeros([o],"float64");for(let y=0;y<o;y++)f.set([y],s[y]);return{h:p,tau:f}}if(t==="r"){let p=x.zeros([o,n],"float64");for(let f=0;f<o;f++)for(let y=f;y<n;y++)p.set([f,y],Number(a.get(f,y)));return p}let i=t==="complete"?e:o,c=x.zeros([e,i],"float64");for(let p=0;p<Math.min(e,i);p++)c.set([p,p],1);for(let p=o-1;p>=0;p--){let f=u[p],y=s[p],g=e-p;for(let h=p;h<i;h++){let b=0;for(let A=0;A<g;A++)b+=f[A]*Number(c.get(p+A,h));for(let A=0;A<g;A++)c.set([p+A,h],Number(c.get(p+A,h))-y*f[A]*b)}}let l=x.zeros([e,i],"float64");for(let p=0;p<e;p++)for(let f=0;f<i;f++)l.set([p,f],Number(c.get(p,f)));let m=t==="complete"?e:o,d=x.zeros([m,n],"float64");for(let p=0;p<m;p++)for(let f=0;f<n;f++)f>=p&&d.set([p,f],Number(a.get(p,f)));return{q:l,r:d}}function jo(r,t=!1){if(r.ndim!==2)throw new Error(`cholesky: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`cholesky: matrix must be square, got ${e}x${n}`);let o=e,a=x.zeros([o,o],"float64");for(let u=0;u<o;u++)for(let s=0;s<=u;s++){let i=0;if(u===s){for(let l=0;l<s;l++)i+=Number(a.get(s,l))**2;let c=Number(r.get(s,s))-i;if(c<0)throw new Error("cholesky: matrix is not positive definite");a.set([s,s],Math.sqrt(c))}else{for(let l=0;l<s;l++)i+=Number(a.get(u,l))*Number(a.get(s,l));let c=Number(a.get(s,s));if(Math.abs(c)<1e-15)throw new Error("cholesky: matrix is not positive definite");a.set([u,s],(Number(r.get(u,s))-i)/c)}}if(t){let u=x.zeros([o,o],"float64");for(let s=0;s<o;s++)for(let i=s;i<o;i++)u.set([s,i],Number(a.get(i,s)));return u}return a}function _r(r){if(r.ndim!==2)throw new Error(`svd: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape,n=Math.min(t,e),o=x.zeros([e,e],"float64");for(let m=0;m<e;m++)for(let d=0;d<e;d++){let p=0;for(let f=0;f<t;f++)p+=Number(r.get(f,m))*Number(r.get(f,d));o.set([m,d],p)}let{values:a,vectors:u}=ge(o),s=Array.from({length:e},(m,d)=>d);s.sort((m,d)=>a[d]-a[m]);let i=x.zeros([n],"float64");for(let m=0;m<n;m++){let d=a[s[m]];i.set([m],Math.sqrt(Math.max(0,d)))}let c=x.zeros([e,e],"float64");for(let m=0;m<e;m++)for(let d=0;d<e;d++)c.set([m,d],u[d][s[m]]);let l=x.zeros([t,t],"float64");for(let m=0;m<t;m++)for(let d=0;d<n;d++){let p=Number(i.get(d));if(p>1e-10){let f=0;for(let y=0;y<e;y++)f+=Number(r.get(m,y))*Number(c.get(d,y));l.set([m,d],f/p)}}if(t>n)for(let m=n;m<t;m++){let d=new Array(t).fill(0);d[m]=1;for(let f=0;f<m;f++){let y=0;for(let g=0;g<t;g++)y+=d[g]*Number(l.get(g,f));for(let g=0;g<t;g++)d[g]=d[g]-y*Number(l.get(g,f))}let p=0;for(let f=0;f<t;f++)p+=d[f]*d[f];if(p=Math.sqrt(p),p>1e-10)for(let f=0;f<t;f++)l.set([f,m],d[f]/p)}return{u:l,s:i,vt:c}}function ge(r){let t=r.shape[0],e=100*t*t,n=1e-10,o=[];for(let s=0;s<t;s++){o.push([]);for(let i=0;i<t;i++)o[s].push(Number(r.get(s,i)))}let a=[];for(let s=0;s<t;s++){a.push([]);for(let i=0;i<t;i++)a[s].push(s===i?1:0)}for(let s=0;s<e;s++){let i=0,c=0,l=1;for(let A=0;A<t;A++)for(let S=A+1;S<t;S++)Math.abs(o[A][S])>i&&(i=Math.abs(o[A][S]),c=A,l=S);if(i<n)break;let m=o[c][c],d=o[l][l],p=o[c][l],f;Math.abs(m-d)<1e-15?f=Math.PI/4:f=.5*Math.atan2(2*p,d-m);let y=Math.cos(f),g=Math.sin(f),h=y*y*m+g*g*d-2*g*y*p,b=g*g*m+y*y*d+2*g*y*p;o[c][c]=h,o[l][l]=b,o[c][l]=0,o[l][c]=0;for(let A=0;A<t;A++)if(A!==c&&A!==l){let S=o[A][c],D=o[A][l];o[A][c]=y*S-g*D,o[c][A]=o[A][c],o[A][l]=g*S+y*D,o[l][A]=o[A][l]}for(let A=0;A<t;A++){let S=a[A][c],D=a[A][l];a[A][c]=y*S-g*D,a[A][l]=g*S+y*D}}let u=[];for(let s=0;s<t;s++)u.push(o[s][s]);return{values:u,vectors:a}}function Po(r,t=!0,e=!0){let n=_r(r);if(!e)return n.s;if(!t){let[o,a]=r.shape,u=Math.min(o,a),s=x.zeros([o,u],"float64");for(let c=0;c<o;c++)for(let l=0;l<u;l++)s.set([c,l],Number(n.u.get(c,l)));let i=x.zeros([u,a],"float64");for(let c=0;c<u;c++)for(let l=0;l<a;l++)i.set([c,l],Number(n.vt.get(c,l)));return{u:s,s:n.s,vt:i}}return n}function Lo(r){if(r.ndim!==2)throw new Error(`det: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`det: matrix must be square, got ${t}x${e}`);let n=t;if(n===0)return 1;let o=r.data;if(n===1)return Number(o[0]);if(n===2)return Number(o[0])*Number(o[3])-Number(o[1])*Number(o[2]);let{lu:a,sign:u}=Ae(r),s=a.data,i=u;for(let c=0;c<n;c++)i*=s[c*n+c];return i}function Ae(r){let[t,e]=r.shape,n=t,o=e,a=x.zeros([n,o],"float64"),u=a.data,s=r.data;for(let l=0;l<n*o;l++)u[l]=Number(s[l]);let i=Array.from({length:n},(l,m)=>m),c=1;for(let l=0;l<Math.min(n,o);l++){let m=Math.abs(u[l*o+l]),d=l;for(let f=l+1;f<n;f++){let y=Math.abs(u[f*o+l]);y>m&&(m=y,d=f)}if(d!==l){for(let y=0;y<o;y++){let g=u[l*o+y];u[l*o+y]=u[d*o+y],u[d*o+y]=g}let f=i[l];i[l]=i[d],i[d]=f,c=-c}let p=u[l*o+l];if(Math.abs(p)>1e-15)for(let f=l+1;f<n;f++){let y=u[f*o+l]/p;u[f*o+l]=y;for(let g=l+1;g<o;g++)u[f*o+g]=u[f*o+g]-y*u[l*o+g]}}return{lu:a,piv:i,sign:c}}function xt(r){if(r.ndim!==2)throw new Error(`inv: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`inv: matrix must be square, got ${t}x${e}`);let n=t,{lu:o,piv:a}=Ae(r),u=o.data,s=x.zeros([n,n],"float64"),i=s.data;for(let c=0;c<n;c++){let l=new Float64Array(n);for(let m=0;m<n;m++){let d=a[m]===c?1:0;for(let p=0;p<m;p++)d-=u[m*n+p]*l[p];l[m]=d}for(let m=n-1;m>=0;m--){let d=l[m];for(let f=m+1;f<n;f++)d-=u[m*n+f]*i[f*n+c];let p=u[m*n+m];if(Math.abs(p)<1e-15)throw new Error("inv: singular matrix");i[m*n+c]=d/p}}return s}function To(r,t){let[e]=r.shape,n=e,{lu:o,piv:a}=Ae(r),u=o.data,s=t.data,i=new Float64Array(n);for(let d=0;d<n;d++)i[d]=Number(s[a[d]]);let c=new Float64Array(n);for(let d=0;d<n;d++){let p=i[d];for(let f=0;f<d;f++)p-=u[d*n+f]*c[f];c[d]=p}let l=x.zeros([n],"float64"),m=l.data;for(let d=n-1;d>=0;d--){let p=c[d];for(let y=d+1;y<n;y++)p-=u[d*n+y]*m[y];let f=u[d*n+d];if(Math.abs(f)<1e-15)throw new Error("solve: singular matrix");m[d]=p/f}return l}function Zo(r,t){if(r.ndim!==2)throw new Error(`solve: coefficient matrix must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`solve: coefficient matrix must be square, got ${e}x${n}`);let o=e;if(t.ndim===1){if(t.shape[0]!==o)throw new Error(`solve: incompatible shapes (${e},${n}) and (${t.shape[0]},)`);return To(r,t)}if(t.ndim===2){if(t.shape[0]!==o)throw new Error(`solve: incompatible shapes (${e},${n}) and (${t.shape[0]},${t.shape[1]})`);let a=t.shape[1],u=x.zeros([o,a],"float64");for(let s=0;s<a;s++){let i=x.zeros([o],"float64");for(let l=0;l<o;l++)i.set([l],Number(t.get(l,s)));let c=To(r,i);for(let l=0;l<o;l++)u.set([l,s],Number(c.get(l)))}return u}throw new Error(`solve: b must be 1D or 2D, got ${t.ndim}D`)}function Go(r,t,e=null){if(r.ndim!==2)throw new Error(`lstsq: coefficient matrix must be 2D, got ${r.ndim}D`);let[n,o]=r.shape,{u:a,s:u,vt:s}=_r(r),i=Math.min(n,o),c=e??Math.max(n,o)*Number.EPSILON,m=Number(u.get(0))*c,d=0;for(let b=0;b<i;b++)Number(u.get(b))>m&&d++;let p=t.ndim===1?nr(t,[t.size,1]):t,f=p.shape[1];if(p.shape[0]!==n)throw new Error(`lstsq: incompatible shapes (${n},${o}) and (${t.shape.join(",")})`);let y=x.zeros([o,f],"float64");for(let b=0;b<f;b++){let A=new Array(n).fill(0);for(let S=0;S<n;S++)for(let D=0;D<n;D++)A[S]+=Number(a.get(D,S))*Number(p.get(D,b));for(let S=0;S<o;S++){let D=0;for(let w=0;w<i;w++){let N=Number(u.get(w));N>m&&(D+=Number(s.get(w,S))*A[w]/N)}y.set([S,b],D)}}let g;if(n>o){g=x.zeros([f],"float64");for(let b=0;b<f;b++){let A=0;for(let S=0;S<n;S++){let D=0;for(let N=0;N<o;N++)D+=Number(r.get(S,N))*Number(y.get(N,b));let w=D-Number(p.get(S,b));A+=w*w}g.set([b],A)}}else g=x.zeros([0],"float64");return{x:t.ndim===1?nr(y,[o]):y,residuals:g,rank:d,s:u}}function Wo(r,t=2){if(r.ndim!==2)throw new Error(`cond: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(t===2||t===-2){let{s}=_r(r),i=Math.min(e,n),c=Number(s.get(0)),l=Number(s.get(i-1));return t===2?l>0?c/l:1/0:c>0?l/c:0}if(e!==n)throw new Error(`cond: matrix must be square for p=${t}`);let o=Br(r,t),a=xt(r),u=Br(a,t);return o*u}function Yo(r,t){if(r.ndim===0)return Number(r.get())!==0?1:0;if(r.ndim===1){for(let u=0;u<r.size;u++)if(Number(r.get(u))!==0)return 1;return 0}if(r.ndim!==2)throw new Error(`matrix_rank: input must be at most 2D, got ${r.ndim}D`);let{s:e}=_r(r),n=Number(e.get(0)),o=t??n*Math.max(r.shape[0],r.shape[1])*Number.EPSILON,a=0;for(let u=0;u<e.size;u++)Number(e.get(u))>o&&a++;return a}function Ho(r,t){if(r.ndim!==2)throw new Error(`matrix_power: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`matrix_power: matrix must be square, got ${e}x${n}`);let o=e;if(!Number.isInteger(t))throw new Error("matrix_power: exponent must be an integer");if(t===0){let c=x.zeros([o,o],"float64");for(let l=0;l<o;l++)c.set([l,l],1);return c}let a=r,u=t;t<0&&(a=xt(r),u=-t);let s=x.zeros([o,o],"float64");for(let c=0;c<o;c++)s.set([c,c],1);let i=x.zeros([o,o],"float64");for(let c=0;c<o;c++)for(let l=0;l<o;l++)i.set([c,l],Number(a.get(c,l)));for(;u>0;)u&1&&(s=pr(s,i)),i=pr(i,i),u>>=1;return s}function Jo(r,t=1e-15){if(r.ndim!==2)throw new Error(`pinv: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape,{u:o,s:a,vt:u}=_r(r),s=Math.min(e,n),c=Number(a.get(0))*t,l=x.zeros([n,e],"float64");for(let m=0;m<n;m++)for(let d=0;d<e;d++){let p=0;for(let f=0;f<s;f++){let y=Number(a.get(f));y>c&&(p+=Number(u.get(f,m))*Number(o.get(d,f))/y)}l.set([m,d],p)}return l}function be(r){if(r.ndim!==2)throw new Error(`eig: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`eig: matrix must be square, got ${t}x${e}`);let n=t,o=!0;r:for(let c=0;c<n;c++)for(let l=c+1;l<n;l++)if(Math.abs(Number(r.get(c,l))-Number(r.get(l,c)))>1e-10){o=!1;break r}if(o){let{values:c,vectors:l}=ge(r),m=x.zeros([n],"float64"),d=x.zeros([n,n],"float64");for(let p=0;p<n;p++){m.set([p],c[p]);for(let f=0;f<n;f++)d.set([f,p],l[f][p])}return{w:m,v:d}}console.warn("numpy-ts: eig() called on non-symmetric matrix. Complex eigenvalues are not supported; results may be inaccurate. For symmetric matrices, use eigh() instead.");let{values:a,vectors:u}=Im(r),s=x.zeros([n],"float64"),i=x.zeros([n,n],"float64");for(let c=0;c<n;c++){s.set([c],a[c]);for(let l=0;l<n;l++)i.set([l,c],u[l][c])}return{w:s,v:i}}function Im(r){let t=r.shape[0],e=1e3,n=1e-10,o=x.zeros([t,t],"float64");for(let i=0;i<t;i++)for(let c=0;c<t;c++)o.set([i,c],Number(r.get(i,c)));let a=x.zeros([t,t],"float64");for(let i=0;i<t;i++)a.set([i,i],1);for(let i=0;i<e;i++){let c=0;for(let p=0;p<t;p++)for(let f=0;f<t;f++)p!==f&&(c+=Number(o.get(p,f))**2);if(Math.sqrt(c)<n*t)break;let l=de(o,"reduced"),m=l.q,d=l.r;o=pr(d,m),a=pr(a,m)}let u=[];for(let i=0;i<t;i++)u.push(Number(o.get(i,i)));let s=[];for(let i=0;i<t;i++){s.push([]);for(let c=0;c<t;c++)s[i].push(Number(a.get(i,c)))}return{values:u,vectors:s}}function he(r,t="L"){if(r.ndim!==2)throw new Error(`eigh: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`eigh: matrix must be square, got ${e}x${n}`);let o=e,a=x.zeros([o,o],"float64");for(let m=0;m<o;m++)for(let d=0;d<o;d++)t==="L"?m>=d&&(a.set([m,d],Number(r.get(m,d))),a.set([d,m],Number(r.get(m,d)))):d>=m&&(a.set([m,d],Number(r.get(m,d))),a.set([d,m],Number(r.get(m,d))));let{values:u,vectors:s}=ge(a),i=Array.from({length:o},(m,d)=>d);i.sort((m,d)=>u[m]-u[d]);let c=x.zeros([o],"float64"),l=x.zeros([o,o],"float64");for(let m=0;m<o;m++){c.set([m],u[i[m]]);for(let d=0;d<o;d++)l.set([d,m],s[d][i[m]])}return{w:c,v:l}}function Xo(r){let{w:t}=be(r);return t}function Qo(r,t="L"){let{w:e}=he(r,t);return e}function Ko(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=Math.sqrt(i*i+c*c),m=Math.sqrt((l+i)/2),d=(c>=0?1:-1)*Math.sqrt((l-i)/2);u[s*2]=m,u[s*2+1]=d}return a}return Y(r,Math.sqrt,!1)}function ra(r,t){if(typeof t=="number")return Fm(r,t);let e=M(r.dtype),n=M(t.dtype);return e||n?_m(r,t):J(r,t,Math.pow,"power")}function _m(r,t){let e=M(r.dtype),n=M(t.dtype),o=r.dtype==="complex128"||t.dtype==="complex128"||t.dtype==="float64"?"complex128":"complex64",a=Array.from(r.shape),u=r.size,s=x.zeros(a,o),i=s.data;for(let c=0;c<u;c++){let l,m;if(e){let S=r.data;l=S[c*2],m=S[c*2+1]}else l=Number(r.iget(c)),m=0;let d,p;if(n){let S=t.data;d=S[c*2],p=S[c*2+1]}else d=Number(t.iget(c)),p=0;let f=Math.sqrt(l*l+m*m),y=Math.atan2(m,l),g=Math.log(f),h=d*g-p*y,b=d*y+p*g,A=Math.exp(h);i[c*2]=A*Math.cos(b),i[c*2+1]=A*Math.sin(b)}return s}function Fm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size;if(M(e)){let m=x.zeros(n,e),d=o,p=m.data;for(let f=0;f<a;f++){let y=d[f*2],g=d[f*2+1],h=Math.sqrt(y*y+g*g),b=Math.atan2(g,y),A=Math.pow(h,t),S=b*t;p[f*2]=A*Math.cos(S),p[f*2+1]=A*Math.sin(S)}return m}let i=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,c=x.zeros(n,i),l=c.data;if(B(e))if(B(i)&&Number.isInteger(t)&&t>=0){let m=o,d=l;for(let p=0;p<a;p++)d[p]=m[p]**BigInt(t)}else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);return c}function ta(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=Math.exp(i);u[s*2]=l*Math.cos(c),u[s*2+1]=l*Math.sin(c)}return a}return Y(r,Math.exp,!1)}function ea(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=Math.LN2,u=x.zeros(e,t),s=u.data;for(let i=0;i<n;i++){let c=o[i*2],l=o[i*2+1],m=Math.exp(c*a),d=l*a;s[i*2]=m*Math.cos(d),s[i*2+1]=m*Math.sin(d)}return u}return Y(r,e=>Math.pow(2,e),!1)}function na(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=Math.exp(i);u[s*2]=l*Math.cos(c)-1,u[s*2+1]=l*Math.sin(c)}return a}return Y(r,Math.expm1,!1)}function oa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=Math.sqrt(i*i+c*c),m=Math.atan2(c,i);u[s*2]=Math.log(l),u[s*2+1]=m}return a}return Y(r,Math.log,!1)}function aa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=1/Math.LN2,u=x.zeros(e,t),s=u.data;for(let i=0;i<n;i++){let c=o[i*2],l=o[i*2+1],m=Math.sqrt(c*c+l*l),d=Math.atan2(l,c);s[i*2]=Math.log(m)*a,s[i*2+1]=d*a}return u}return Y(r,Math.log2,!1)}function sa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=1/Math.LN10,u=x.zeros(e,t),s=u.data;for(let i=0;i<n;i++){let c=o[i*2],l=o[i*2+1],m=Math.sqrt(c*c+l*l),d=Math.atan2(l,c);s[i*2]=Math.log(m)*a,s[i*2+1]=d*a}return u}return Y(r,Math.log10,!1)}function ia(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=1+i,m=Math.sqrt(l*l+c*c),d=Math.atan2(c,l);u[s*2]=Math.log(m),u[s*2+1]=d}return a}return Y(r,Math.log1p,!1)}function ua(r,t){return q(r.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof t!="number"&&q(t.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof t=="number"?Bm(r,t):Mm(r,t)}function Mm(r,t){let e=Ir(r.shape,t.shape),n=e.reduce((c,l)=>c*l,1),o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",s=x.zeros(e,u),i=s.data;for(let c=0;c<n;c++){let l=(B(o),Number(r.iget(c))),m=(B(a),Number(t.iget(c))),d=Math.max(l,m),p=Math.min(l,m);i[c]=d+Math.log1p(Math.exp(p-d))}return s}function Bm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=x.zeros(n,a),s=u.data;for(let i=0;i<o;i++){let c=(B(e),Number(r.data[i])),l=Math.max(c,t),m=Math.min(c,t);s[i]=l+Math.log1p(Math.exp(m-l))}return u}function ca(r,t){return q(r.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof t!="number"&&q(t.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof t=="number"?Em(r,t):vm(r,t)}function vm(r,t){let e=Ir(r.shape,t.shape),n=e.reduce((l,m)=>l*m,1),o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",s=x.zeros(e,u),i=s.data,c=Math.LOG2E;for(let l=0;l<n;l++){let m=(B(o),Number(r.iget(l))),d=(B(a),Number(t.iget(l))),p=Math.max(m,d),f=Math.min(m,d);i[l]=p+Math.log1p(Math.pow(2,f-p))*c}return s}function Em(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=x.zeros(n,a),s=u.data,i=Math.LOG2E;for(let c=0;c<o;c++){let l=(B(e),Number(r.data[c])),m=Math.max(l,t),d=Math.min(l,t);s[c]=m+Math.log1p(Math.pow(2,d-m))*i}return u}function la(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1];u[s*2]=Math.sin(i)*Math.cosh(c),u[s*2+1]=Math.cos(i)*Math.sinh(c)}return a}return Y(r,Math.sin,!1)}function fa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1];u[s*2]=Math.cos(i)*Math.cosh(c),u[s*2+1]=-Math.sin(i)*Math.sinh(c)}return a}return Y(r,Math.cos,!1)}function ma(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=Math.cos(2*i)+Math.cosh(2*c);u[s*2]=Math.sin(2*i)/l,u[s*2+1]=Math.sinh(2*c)/l}return a}return Y(r,Math.tan,!1)}function ya(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=-c,m=i,d=i*i-c*c,p=2*i*c,f=1-d,y=-p,g=Math.sqrt(f*f+y*y),h=Math.sqrt((g+f)/2),b=(y>=0?1:-1)*Math.sqrt((g-f)/2),A=l+h,S=m+b,D=Math.sqrt(A*A+S*S),w=Math.log(D),I=Math.atan2(S,A),z=-w;Math.abs(c)<1e-15&&i>1&&(z=-z),u[s*2]=I,u[s*2+1]=z}return a}return Y(r,Math.asin,!1)}function pa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=i*i-c*c,m=2*i*c,d=1-l,p=-m,f=Math.sqrt(d*d+p*p),y=Math.sqrt((f+d)/2),h=-((p>=0?1:-1)*Math.sqrt((f-d)/2)),b=y,A=i+h,S=c+b,D=Math.sqrt(A*A+S*S),w=Math.log(D),I=Math.atan2(S,A),z=-w;Math.abs(c)<1e-15&&i>1&&(z=-z),u[s*2]=I,u[s*2+1]=z}return a}return Y(r,Math.acos,!1)}function da(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],l=-o[s*2+1],m=i,d=1-l,p=-m,f=1+l,y=m,g=f*f+y*y,h=(d*f+p*y)/g,b=(p*f-d*y)/g,A=Math.sqrt(h*h+b*b),S=Math.log(A),D=Math.atan2(b,h);u[s*2]=-D/2,u[s*2+1]=S/2}return a}return Y(r,Math.atan,!1)}function ga(r,t){return q(r.dtype,"arctan2","arctan2 is only defined for real numbers."),typeof t!="number"&&q(t.dtype,"arctan2","arctan2 is only defined for real numbers."),typeof t=="number"?Cm(r,t):Om(r,t)}function Om(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",s=x.zeros(e,u),i=s.data;for(let c=0;c<n;c++){let l=(B(o),Number(r.data[c])),m=(B(a),Number(t.data[c]));i[c]=Math.atan2(l,m)}return s}function Cm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e==="float32"?"float32":"float64",s=x.zeros(n,u),i=s.data;if(B(e))for(let c=0;c<a;c++)i[c]=Math.atan2(Number(o[c]),t);else for(let c=0;c<a;c++)i[c]=Math.atan2(Number(o[c]),t);return s}function Aa(r,t){return q(r.dtype,"hypot","hypot is only defined for real numbers."),typeof t!="number"&&q(t.dtype,"hypot","hypot is only defined for real numbers."),typeof t=="number"?$m(r,t):Um(r,t)}function Um(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",s=x.zeros(e,u),i=s.data;for(let c=0;c<n;c++){let l=(B(o),Number(r.data[c])),m=(B(a),Number(t.data[c]));i[c]=Math.hypot(l,m)}return s}function $m(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e==="float32"?"float32":"float64",s=x.zeros(n,u),i=s.data;if(B(e))for(let c=0;c<a;c++)i[c]=Math.hypot(Number(o[c]),t);else for(let c=0;c<a;c++)i[c]=Math.hypot(Number(o[c]),t);return s}function ba(r){q(r.dtype,"degrees","degrees is only defined for real numbers.");let t=180/Math.PI;return Y(r,e=>e*t,!1)}function ha(r){q(r.dtype,"radians","radians is only defined for real numbers.");let t=Math.PI/180;return Y(r,e=>e*t,!1)}function Sa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1];u[s*2]=Math.sinh(i)*Math.cos(c),u[s*2+1]=Math.cosh(i)*Math.sin(c)}return a}return Y(r,Math.sinh,!1)}function Da(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1];u[s*2]=Math.cosh(i)*Math.cos(c),u[s*2+1]=Math.sinh(i)*Math.sin(c)}return a}return Y(r,Math.cosh,!1)}function xa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=Math.cosh(2*i)+Math.cos(2*c);u[s*2]=Math.sinh(2*i)/l,u[s*2+1]=Math.sin(2*c)/l}return a}return Y(r,Math.tanh,!1)}function Na(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=i*i-c*c,m=2*i*c,d=l+1,p=m,f=Math.sqrt(d*d+p*p),y=Math.sqrt((f+d)/2),g=(p>=0?1:-1)*Math.sqrt((f-d)/2),h=i+y,b=c+g,A=Math.sqrt(h*h+b*b);u[s*2]=Math.log(A),u[s*2+1]=Math.atan2(b,h)}return a}return Y(r,Math.asinh,!1)}function wa(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=i*i-c*c,m=2*i*c,d=l-1,p=m,f=Math.sqrt(d*d+p*p),y=Math.sqrt((f+d)/2),g=(p>=0?1:-1)*Math.sqrt((f-d)/2),h=i+y,b=c+g,A=Math.sqrt(h*h+b*b),S=Math.log(A),D=Math.atan2(b,h);Math.abs(c)<1e-15&&i<1&&(D=-D),u[s*2]=S,u[s*2+1]=D}return a}return Y(r,Math.acosh,!1)}function Ia(r){let t=r.dtype;if(M(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=x.zeros(e,t),u=a.data;for(let s=0;s<n;s++){let i=o[s*2],c=o[s*2+1],l=1+i,m=c,d=1-i,p=-c,f=d*d+p*p,y=(l*d+m*p)/f,g=(m*d-l*p)/f,h=Math.sqrt(y*y+g*g),b=Math.log(h),A=Math.atan2(g,y);u[s*2]=b/2,u[s*2+1]=A/2}return a}return Y(r,Math.atanh,!1)}function Nt(r,t){let e=r.shape,n=e.length,o=t.length;if(o<n)throw new Error("input operand has more dimensions than allowed by the axis remapping");let a=yr([Array.from(e),t]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);for(let u=0;u<o;u++)if(a[u]!==t[u])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);return lr(r,t)}function za(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=yr(t);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${t.map(n=>`(${n.join(",")})`).join(" ")}`);return r.map(n=>lr(n,e))}function _a(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let f=r.size;for(let b of t){let A=b<0?f+b:b;if(A<0||A>=f)throw new Error(`index ${b} is out of bounds for axis 0 with size ${f}`)}let y=t.length,g=P(a);if(!g)throw new Error(`Cannot take from array with dtype ${a}`);let h=new g(y);for(let b=0;b<y;b++){let A=t[b];A<0&&(A=f+A);let S=r.iget(A);B(a),h[b]=S}return x.fromData(h,[y],a)}let u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u];for(let f of t){let y=f<0?s+f:f;if(y<0||y>=s)throw new Error(`index ${f} is out of bounds for axis ${u} with size ${s}`)}let i=Array.from(n);i[u]=t.length;let c=i.reduce((f,y)=>f*y,1),l=P(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let m=new l(c),d=ar(i),p=new Array(o).fill(0);for(let f=0;f<c;f++){let y=[...p],g=p[u],h=t[g];h<0&&(h=s+h),y[u]=h;let b=r.get(...y),A=0;for(let S=0;S<o;S++)A+=p[S]*d[S];B(a),m[A]=b;for(let S=o-1;S>=0&&(p[S]++,!(p[S]<i[S]));S--)p[S]=0}return x.fromData(m,i,a)}function Fa(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=new Array(t.length).fill(e);else{a=[];for(let u=0;u<e.size;u++){let s=e.iget(u);a.push(s instanceof O?s.re:s)}if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let u=[...a];a=[];for(let s=0;s<t.length;s++)a.push(u[s%u.length])}}for(let u=0;u<t.length;u++){let s=t[u];if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`index ${t[u]} is out of bounds for axis 0 with size ${n}`);let i=a[u];B(o)?typeof i!="bigint"&&(i=BigInt(Math.round(Number(i)))):typeof i=="bigint"&&(i=Number(i)),r.iset(s,i)}}function Ma(r,t){if(t.length===0)throw new Error("choices cannot be empty");let e=r.shape,n=t.length,o=t[0].dtype,a=t.map(d=>Array.from(d.shape));a.unshift(Array.from(e));let u=yr(a);if(u===null)throw new Error("operands could not be broadcast together");let s=lr(r,u),i=t.map(d=>lr(d,u)),c=u.reduce((d,p)=>d*p,1),l=P(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let m=new l(c);for(let d=0;d<c;d++){let p=Number(s.iget(d));if(p<0||p>=n)throw new Error(`index ${p} is out of bounds for axis 0 with size ${n}`);let f=i[p].iget(d);B(o),m[d]=f}return x.fromData(m,u,o)}function Ba(r,t,e=!1){if(r.ndim!==t.ndim)return!1;for(let o=0;o<r.ndim;o++)if(r.shape[o]!==t.shape[o])return!1;let n=r.size;for(let o=0;o<n;o++){let a=r.iget(o),u=t.iget(o);if(e){let s=typeof a=="number"&&Number.isNaN(a),i=typeof u=="number"&&Number.isNaN(u);if(s&&i)continue}if(a!==u)return!1}return!0}function va(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=t.shape;if(s.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${s.length} vs ${o}`);for(let y=0;y<o;y++)if(y!==u&&s[y]!==n[y]&&s[y]!==1&&n[y]!==1)throw new Error(`index ${s[y]} is out of bounds for size ${n[y]} in dimension ${y}`);let i=Array.from(s),c=i.reduce((y,g)=>y*g,1),l=P(a);if(!l)throw new Error(`Cannot take_along_axis with dtype ${a}`);let m=new l(c),d=ar(n),p=ar(s),f=n[u];for(let y=0;y<c;y++){let g=new Array(o),h=y;for(let N=o-1;N>=0;N--)g[N]=h%i[N],h=Math.floor(h/i[N]);let b=0;for(let N=0;N<o;N++){let I=s[N]===1?0:g[N];b+=I*p[N]}let A=Number(t.iget(b));if(A<0&&(A=f+A),A<0||A>=f)throw new Error(`index ${A} is out of bounds for axis ${u} with size ${f}`);let S=[...g];S[u]=A;let D=0;for(let N=0;N<o;N++){let I=n[N]===1?0:S[N];D+=I*d[N]}let w=r.iget(D);B(a),m[y]=w}return x.fromData(m,i,a)}function Ea(r,t,e,n){let o=r.shape,a=o.length,u=r.dtype,s=n<0?a+n:n;if(s<0||s>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let i=t.shape,c=e.shape;if(i.length!==a||c.length!==a)throw new Error("indices, arr, and values must have same ndim");let l=o[s],m=ar(o),d=ar(i),p=ar(c),f=i.reduce((y,g)=>y*g,1);for(let y=0;y<f;y++){let g=new Array(a),h=y;for(let I=a-1;I>=0;I--)g[I]=h%i[I],h=Math.floor(h/i[I]);let b=0;for(let I=0;I<a;I++)b+=g[I]*d[I];let A=Number(t.iget(b));if(A<0&&(A=l+A),A<0||A>=l)throw new Error(`index ${A} is out of bounds for axis ${s} with size ${l}`);let S=0;for(let I=0;I<a;I++){let z=c[I]===1?0:g[I];S+=z*p[I]}let D=e.iget(S),w=[...g];w[s]=A;let N=0;for(let I=0;I<a;I++)N+=w[I]*m[I];B(u)?typeof D!="bigint"&&(D=BigInt(Math.round(Number(D)))):typeof D=="bigint"&&(D=Number(D)),r.iset(N,D)}}function Ta(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let s=0;s<e.size;s++){let i=e.iget(s);a.push(i instanceof O?i.re:i)}}let u=0;for(let s=0;s<n;s++)if(t.iget(s)){let c=a[u%a.length];B(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(s,c),u++}}function Se(r,t,e){let n=t.shape,o=n.length,a=t.dtype,u=t.data,s=B(a);if(e===void 0){let b=0,A=Math.min(r.size,t.size);for(let N=0;N<A;N++)r.iget(N)&&b++;let S=P(a);if(!S)throw new Error(`Cannot compress with dtype ${a}`);let D=new S(b),w=0;for(let N=0;N<A;N++)r.iget(N)&&(D[w]=u[N],w++);return x.fromData(D,[b],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let c=n[i],l=Math.min(r.size,c),m=[];for(let b=0;b<l;b++)r.iget(b)&&m.push(b);let d=m.length,p=[...n];p[i]=d;let f=p.reduce((b,A)=>b*A,1),y=P(a);if(!y)throw new Error(`Cannot compress with dtype ${a}`);let g=new y(f),h=ar(n);if(i===0){let b=h[0],A=n.slice(1).reduce((D,w)=>D*w,1),S=0;for(let D=0;D<d;D++){let N=m[D]*b;if(s){let I=u,z=g;for(let F=0;F<A;F++)z[S++]=I[N+F]}else{let I=u,z=g;for(let F=0;F<A;F++)z[S++]=I[N+F]}}}else{let b=n.slice(0,i).reduce((D,w)=>D*w,1),A=n.slice(i+1).reduce((D,w)=>D*w,1),S=0;for(let D=0;D<b;D++)for(let w=0;w<d;w++){let N=m[w],I=0,z=D;for(let F=i-1;F>=0;F--){let _=z%n[F];z=Math.floor(z/n[F]),I+=_*h[F]}if(I+=N*h[i],s){let F=u,_=g;for(let E=0;E<A;E++)_[S++]=F[I+E]}else{let F=u,_=g;for(let E=0;E<A;E++)_[S++]=F[I+E]}}}return x.fromData(g,p,a)}function Oa(r,t,e=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");let n=[...r.map(d=>Array.from(d.shape)),...t.map(d=>Array.from(d.shape))],o=yr(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,u=o.reduce((d,p)=>d*p,1),s=P(a);if(!s)throw new Error(`Cannot select with dtype ${a}`);let i=e;B(a)?i=typeof e=="bigint"?e:BigInt(e):i=typeof e=="bigint"?Number(e):e;let c=new s(u);for(let d=0;d<u;d++)B(a),c[d]=i;let l=r.map(d=>lr(d,o)),m=t.map(d=>lr(d,o));for(let d=0;d<u;d++)for(let p=0;p<r.length;p++)if(l[p].iget(d)){let f=m[p].iget(d);B(a),c[d]=f;break}return x.fromData(c,o,a)}function Ca(r,t,e){let n=r.size,o=r.dtype,a=[];for(let s=0;s<e.size;s++){let i=e.iget(s);a.push(i instanceof O?i.re:i)}if(a.length===0)return;let u=0;for(let s=0;s<n;s++)if(t.iget(s)){let c=a[u%a.length];B(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(s,c),u++}}function De(r,t=2){if(t<1)throw new Error("ndim must be at least 1");let e=new Int32Array(r);for(let o=0;o<r;o++)e[o]=o;let n=[];for(let o=0;o<t;o++)n.push(x.fromData(new Int32Array(e),[r],"int32"));return n}function Ua(r){let t=r.shape,e=t.length;if(e<2)throw new Error("array must be at least 2-D");let n=t[0];for(let o=1;o<e;o++)if(t[o]!==n)throw new Error("All dimensions of input must be equal");return De(n,e)}function xe(r,t=0,e){let n=e??r,o=[],a=[];for(let u=0;u<r;u++)for(let s=0;s<=Math.min(u+t,n-1);s++)s>=0&&(o.push(u),a.push(s));return[x.fromData(new Int32Array(o),[o.length],"int32"),x.fromData(new Int32Array(a),[a.length],"int32")]}function $a(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return xe(e[0],t,e[1])}function Ne(r,t=0,e){let n=e??r,o=[],a=[];for(let u=0;u<r;u++)for(let s=Math.max(u+t,0);s<n;s++)o.push(u),a.push(s);return[x.fromData(new Int32Array(o),[o.length],"int32"),x.fromData(new Int32Array(a),[a.length],"int32")]}function Ra(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return Ne(e[0],t,e[1])}function ka(r,t,e=0){let n=t(r,e),o=n.shape;if(o.length!==2||o[0]!==r||o[1]!==r)throw new Error("mask_func must return n x n array");let a=[],u=[];for(let s=0;s<r;s++)for(let i=0;i<r;i++)n.get(s,i)&&(a.push(s),u.push(i));return[x.fromData(new Int32Array(a),[a.length],"int32"),x.fromData(new Int32Array(u),[u.length],"int32")]}function qa(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((i,c)=>i*c,1),a=P(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let u=new a(o),s=r.reduce((i,c)=>i*c,1);for(let i=0;i<e;i++){let c=i*s;for(let l=0;l<s;l++){let m=new Array(e),d=l;for(let f=e-1;f>=0;f--)m[f]=d%r[f],d=Math.floor(d/r[f]);let p=m[i];t==="int64"?u[c+l]=BigInt(p):u[c+l]=p}}return x.fromData(u,n,t)}function Va(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,u=o.dtype,s=new Array(t).fill(1);s[n]=a;let i=P(u);if(!i)throw new Error(`Cannot create ix_ with dtype ${u}`);let c=new i(a);for(let l=0;l<a;l++){let m=o.iget(l);B(u),c[l]=m}e.push(x.fromData(c,s,u))}return e}function ja(r,t,e="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");let n=r[0].size,o=t.length,a=new Int32Array(n),u=new Array(o),s=1;for(let i=o-1;i>=0;i--)u[i]=s,s*=t[i];for(let i=0;i<n;i++){let c=0;for(let l=0;l<o;l++){let m=Number(r[l].iget(i)),d=t[l];if(e==="wrap")m=(m%d+d)%d;else if(e==="clip")m=Math.max(0,Math.min(m,d-1));else if(m<0||m>=d)throw new Error(`index ${m} is out of bounds for axis ${l} with size ${d}`);c+=m*u[l]}a[i]=c}return x.fromData(a,[n],"int32")}function Pa(r,t,e="C"){let n=t.length,o,a;if(typeof r=="number")o=[r],a=[];else{o=[];for(let l=0;l<r.size;l++)o.push(Number(r.iget(l)));a=Array.from(r.shape)}let u=o.length,s=t.reduce((l,m)=>l*m,1),i=new Array(n);if(e==="C"){let l=1;for(let m=n-1;m>=0;m--)i[m]=l,l*=t[m]}else{let l=1;for(let m=0;m<n;m++)i[m]=l,l*=t[m]}let c=[];for(let l=0;l<n;l++){let m=new Int32Array(u);c.push(x.fromData(m,a.length?a:[1],"int32"))}for(let l=0;l<u;l++){let m=o[l];if(m<0||m>=s)throw new Error(`index ${m} is out of bounds for array with size ${s}`);if(e==="C")for(let d=0;d<n;d++){let p=Math.floor(m/i[d]);m=m%i[d],c[d].data[l]=p%t[d]}else for(let d=n-1;d>=0;d--){let p=Math.floor(m/i[d]);m=m%i[d],c[d].data[l]=p%t[d]}}return typeof r=="number"?c.map(l=>{let m=l.iget(0);return x.fromData(new Int32Array([Number(m)]),[],"int32")}):c}function La(r,t,e=!1){let n=r.shape,o=n.length;if(o<2)throw new Error("array must be at least 2-d");let a;if(o===2)a=n[1]+1;else{a=1;for(let c=1;c<o;c++){let l=1;for(let m=c;m<o;m++)l*=n[m];a+=l}}let u=r.data,s=r.size,i=Math.min(...n);if(e&&o===2&&(i=Math.max(n[0],n[1])),typeof t=="number")for(let c=0;c<i&&c*a<s;c++){let l=c*a;if(l<s)u[l]=t;else break}else{let c=t.data,l=t.size;for(let m=0;m<i&&m*a<s;m++){let d=m*a;if(d<s)u[d]=c[m%l];else break}}}function dr(r,t){if(!Mn(r)&&r!=="bool")throw new TypeError(`ufunc '${t}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function tt(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Wa(r,t){return dr(r.dtype,"bitwise_and"),typeof t=="number"?jm(r,t):(dr(t.dtype,"bitwise_and"),tt(r,t)?Vm(r,t):J(r,t,(e,n)=>e&n,"bitwise_and"))}function Vm(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(B(e)){let i=s;if(!B(r.dtype)||!B(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),d=typeof u[l]=="bigint"?u[l]:BigInt(Math.round(Number(u[l])));i[l]=m&d}else{let l=a,m=u;for(let d=0;d<o;d++)i[d]=l[d]&m[d]}}else for(let i=0;i<o;i++)s[i]=a[i]&u[i];return n}function jm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]&l}else for(let i=0;i<a;i++)s[i]=o[i]&t;return u}function Ya(r,t){return dr(r.dtype,"bitwise_or"),typeof t=="number"?Lm(r,t):(dr(t.dtype,"bitwise_or"),tt(r,t)?Pm(r,t):J(r,t,(e,n)=>e|n,"bitwise_or"))}function Pm(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(B(e)){let i=s;if(!B(r.dtype)||!B(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),d=typeof u[l]=="bigint"?u[l]:BigInt(Math.round(Number(u[l])));i[l]=m|d}else{let l=a,m=u;for(let d=0;d<o;d++)i[d]=l[d]|m[d]}}else for(let i=0;i<o;i++)s[i]=a[i]|u[i];return n}function Lm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]|l}else for(let i=0;i<a;i++)s[i]=o[i]|t;return u}function Ha(r,t){return dr(r.dtype,"bitwise_xor"),typeof t=="number"?Gm(r,t):(dr(t.dtype,"bitwise_xor"),tt(r,t)?Zm(r,t):J(r,t,(e,n)=>e^n,"bitwise_xor"))}function Zm(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(B(e)){let i=s;if(!B(r.dtype)||!B(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),d=typeof u[l]=="bigint"?u[l]:BigInt(Math.round(Number(u[l])));i[l]=m^d}else{let l=a,m=u;for(let d=0;d<o;d++)i[d]=l[d]^m[d]}}else for(let i=0;i<o;i++)s[i]=a[i]^u[i];return n}function Gm(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]^l}else for(let i=0;i<a;i++)s[i]=o[i]^t;return u}function we(r){dr(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=x.zeros(e,t),u=a.data;if(B(t)){let s=n,i=u;for(let c=0;c<o;c++)i[c]=~s[c]}else for(let s=0;s<o;s++)u[s]=~n[s];return a}function Ja(r){return we(r)}function Xa(r,t){if(dr(r.dtype,"left_shift"),typeof t=="number")return Za(r,t);if(dr(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=B(t.dtype)?Number(t.data[0]):t.data[0];return Za(r,e)}return tt(r,t)?Wm(r,t):J(r,t,(e,n)=>e<<n,"left_shift")}function Wm(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(B(e)){let i=s;for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),m=typeof u[c]=="bigint"?u[c]:BigInt(Math.round(Number(u[c])));i[c]=l<<m}}else for(let i=0;i<o;i++)s[i]=a[i]<<u[i];return n}function Za(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]<<l}else for(let i=0;i<a;i++)s[i]=o[i]<<t;return u}function Qa(r,t){if(dr(r.dtype,"right_shift"),typeof t=="number")return Ga(r,t);if(dr(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=B(t.dtype)?Number(t.data[0]):t.data[0];return Ga(r,e)}return tt(r,t)?Ym(r,t):J(r,t,(e,n)=>e>>n,"right_shift")}function Ym(r,t){let e=G(r.dtype,t.dtype),n=x.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,s=n.data;if(B(e)){let i=s;for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),m=typeof u[c]=="bigint"?u[c]:BigInt(Math.round(Number(u[c])));i[c]=l>>m}}else for(let i=0;i<o;i++)s[i]=a[i]>>u[i];return n}function Ga(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=x.zeros(n,e),s=u.data;if(B(e)){let i=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=i[m]>>l}else for(let i=0;i<a;i++)s[i]=o[i]>>t;return u}function Ka(r,t=-1,e="big"){let n=Array.from(r.shape),o=n.length;if(t<0&&(t=o+t),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=n[t],u=Math.ceil(a/8),s=[...n];s[t]=u;let i=x.zeros(s,"uint8"),c=i.data;if(o===1){for(let g=0;g<u;g++){let h=0;for(let b=0;b<8;b++){let A=g*8+b;if(A<a){let S=Number(r.data[A])!==0?1:0;e==="big"?h|=S<<7-b:h|=S<<b}}c[g]=h}return i}let l=n.slice(0,t),m=n.slice(t+1),d=l.reduce((g,h)=>g*h,1),p=m.reduce((g,h)=>g*h,1),f=wt(n),y=wt(s);for(let g=0;g<d;g++)for(let h=0;h<p;h++)for(let b=0;b<u;b++){let A=0;for(let N=0;N<8;N++){let I=b*8+N;if(I<a){let z=0,F=g;for(let T=0;T<t;T++){let C=T<t-1?l.slice(T+1).reduce((V,R)=>V*R,1):1,k=Math.floor(F/C);F%=C,z+=k*f[T]}z+=I*f[t];let _=h;for(let T=t+1;T<o;T++){let C=T<o-1?m.slice(T-t).reduce((V,R)=>V*R,1):1,k=Math.floor(_/C);_%=C,z+=k*f[T]}let E=Number(r.data[z])!==0?1:0;e==="big"?A|=E<<7-N:A|=E<<N}}let S=0,D=g;for(let N=0;N<t;N++){let I=N<t-1?l.slice(N+1).reduce((F,_)=>F*_,1):1,z=Math.floor(D/I);D%=I,S+=z*y[N]}S+=b*y[t];let w=h;for(let N=t+1;N<o;N++){let I=N<o-1?m.slice(N-t).reduce((F,_)=>F*_,1):1,z=Math.floor(w/I);w%=I,S+=z*y[N]}c[S]=A}return i}function rs(r,t=-1,e=-1,n="big"){if(r.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");let o=Array.from(r.shape),a=o.length;if(t<0&&(t=a+t),t<0||t>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=o[t],s=u*8;e>=0&&(s=e);let i=[...o];i[t]=s;let c=x.zeros(i,"uint8"),l=c.data;if(a===1){for(let h=0;h<u;h++){let b=Number(r.data[h]);for(let A=0;A<8;A++){let S=h*8+A;if(S>=s)break;n==="big"?l[S]=b>>7-A&1:l[S]=b>>A&1}}return c}let m=o.slice(0,t),d=o.slice(t+1),p=m.reduce((h,b)=>h*b,1),f=d.reduce((h,b)=>h*b,1),y=wt(o),g=wt(i);for(let h=0;h<p;h++)for(let b=0;b<f;b++)for(let A=0;A<u;A++){let S=0,D=h;for(let I=0;I<t;I++){let z=I<t-1?m.slice(I+1).reduce((_,E)=>_*E,1):1,F=Math.floor(D/z);D%=z,S+=F*y[I]}S+=A*y[t];let w=b;for(let I=t+1;I<a;I++){let z=I<a-1?d.slice(I-t).reduce((_,E)=>_*E,1):1,F=Math.floor(w/z);w%=z,S+=F*y[I]}let N=Number(r.data[S]);for(let I=0;I<8;I++){let z=A*8+I;if(z>=s)break;let F=0;D=h;for(let _=0;_<t;_++){let E=_<t-1?m.slice(_+1).reduce((C,k)=>C*k,1):1,T=Math.floor(D/E);D%=E,F+=T*g[_]}F+=z*g[t],w=b;for(let _=t+1;_<a;_++){let E=_<a-1?d.slice(_-t).reduce((C,k)=>C*k,1):1,T=Math.floor(w/E);w%=E,F+=T*g[_]}n==="big"?l[F]=N>>7-I&1:l[F]=N>>I&1}}return c}function wt(r){let t=r.length,e=new Array(t),n=1;for(let o=t-1;o>=0;o--)e[o]=n,n*=r[o];return e}function jr(r){return r!==0&&r!==0n}function br(r,t){let e=r[t*2],n=r[t*2+1];return e!==0||n!==0}function nt(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function es(r,t){return typeof t=="number"?Xm(r,t):nt(r,t)?Jm(r,t):fr(r,t,(e,n)=>jr(e)&&jr(n))}function Jm(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.size,u=B(r.dtype),s=B(t.dtype),i=M(r.dtype),c=M(t.dtype);if(i||c)for(let l=0;l<a;l++){let m=i?br(n,l):n[l]!==0,d=c?br(o,l):o[l]!==0;e[l]=m&&d?1:0}else if(u||s)for(let l=0;l<a;l++){let m=u?n[l]!==0n:n[l]!==0,d=s?o[l]!==0n:o[l]!==0;e[l]=m&&d?1:0}else for(let l=0;l<a;l++)e[l]=n[l]!==0&&o[l]!==0?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function Xm(r,t){let e=new Uint8Array(r.size),n=r.data,o=t!==0,a=r.size;if(M(r.dtype)){let u=n;for(let s=0;s<a;s++)e[s]=br(u,s)&&o?1:0}else if(B(r.dtype)){let u=n;for(let s=0;s<a;s++)e[s]=u[s]!==0n&&o?1:0}else for(let u=0;u<a;u++)e[u]=n[u]!==0&&o?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function ns(r,t){return typeof t=="number"?Km(r,t):nt(r,t)?Qm(r,t):fr(r,t,(e,n)=>jr(e)||jr(n))}function Qm(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.size,u=B(r.dtype),s=B(t.dtype),i=M(r.dtype),c=M(t.dtype);if(i||c)for(let l=0;l<a;l++){let m=i?br(n,l):n[l]!==0,d=c?br(o,l):o[l]!==0;e[l]=m||d?1:0}else if(u||s)for(let l=0;l<a;l++){let m=u?n[l]!==0n:n[l]!==0,d=s?o[l]!==0n:o[l]!==0;e[l]=m||d?1:0}else for(let l=0;l<a;l++)e[l]=n[l]!==0||o[l]!==0?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function Km(r,t){let e=new Uint8Array(r.size),n=r.data,o=t!==0,a=r.size;if(M(r.dtype)){let u=n;for(let s=0;s<a;s++)e[s]=br(u,s)||o?1:0}else if(B(r.dtype)){let u=n;for(let s=0;s<a;s++)e[s]=u[s]!==0n||o?1:0}else for(let u=0;u<a;u++)e[u]=n[u]!==0||o?1:0;return x.fromData(e,Array.from(r.shape),"bool")}function os(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(M(r.dtype)){let o=e;for(let a=0;a<n;a++)t[a]=br(o,a)?0:1}else if(B(r.dtype)){let o=e;for(let a=0;a<n;a++)t[a]=o[a]===0n?1:0}else for(let o=0;o<n;o++)t[o]=e[o]===0?1:0;return x.fromData(t,Array.from(r.shape),"bool")}function as(r,t){return typeof t=="number"?ty(r,t):nt(r,t)?ry(r,t):fr(r,t,(e,n)=>jr(e)!==jr(n))}function ry(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.size,u=B(r.dtype),s=B(t.dtype),i=M(r.dtype),c=M(t.dtype);if(i||c)for(let l=0;l<a;l++){let m=i?br(n,l):n[l]!==0,d=c?br(o,l):o[l]!==0;e[l]=m!==d?1:0}else if(u||s)for(let l=0;l<a;l++){let m=u?n[l]!==0n:n[l]!==0,d=s?o[l]!==0n:o[l]!==0;e[l]=m!==d?1:0}else for(let l=0;l<a;l++){let m=n[l]!==0,d=o[l]!==0;e[l]=m!==d?1:0}return x.fromData(e,Array.from(r.shape),"bool")}function ty(r,t){let e=new Uint8Array(r.size),n=r.data,o=t!==0,a=r.size;if(M(r.dtype)){let u=n;for(let s=0;s<a;s++){let i=br(u,s);e[s]=i!==o?1:0}}else if(B(r.dtype)){let u=n;for(let s=0;s<a;s++){let i=u[s]!==0n;e[s]=i!==o?1:0}}else for(let u=0;u<a;u++){let s=n[u]!==0;e[u]=s!==o?1:0}return x.fromData(e,Array.from(r.shape),"bool")}function ss(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(M(r.dtype)){let o=e;for(let a=0;a<n;a++){let u=o[a*2],s=o[a*2+1];t[a]=Number.isFinite(u)&&Number.isFinite(s)?1:0}}else if(B(r.dtype))for(let o=0;o<n;o++)t[o]=1;else for(let o=0;o<n;o++){let a=e[o];t[o]=Number.isFinite(a)?1:0}return x.fromData(t,Array.from(r.shape),"bool")}function is(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(M(r.dtype)){let o=e;for(let a=0;a<n;a++){let u=o[a*2],s=o[a*2+1],i=!Number.isFinite(u)&&!Number.isNaN(u),c=!Number.isFinite(s)&&!Number.isNaN(s);t[a]=i||c?1:0}}else if(B(r.dtype))for(let o=0;o<n;o++)t[o]=0;else for(let o=0;o<n;o++){let a=e[o];t[o]=!Number.isFinite(a)&&!Number.isNaN(a)?1:0}return x.fromData(t,Array.from(r.shape),"bool")}function us(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(M(r.dtype)){let o=e;for(let a=0;a<n;a++){let u=o[a*2],s=o[a*2+1];t[a]=Number.isNaN(u)||Number.isNaN(s)?1:0}}else if(B(r.dtype))for(let o=0;o<n;o++)t[o]=0;else for(let o=0;o<n;o++)t[o]=Number.isNaN(e[o])?1:0;return x.fromData(t,Array.from(r.shape),"bool")}function cs(r){let t=new Uint8Array(r.size);return x.fromData(t,Array.from(r.shape),"bool")}function ls(r,t){if(q(r.dtype,"copysign","copysign is only defined for real numbers."),typeof t!="number"&&q(t.dtype,"copysign","copysign is only defined for real numbers."),typeof t=="number")return ny(r,t);if(nt(r,t))return ey(r,t);let e=Ir(r.shape,t.shape),n=e.reduce((i,c)=>i*c,1),o=x.zeros(e,"float64"),a=o.data,u=It(r,e),s=It(t,e);for(let i=0;i<n;i++){let c=Number(u.iget(i)),l=Number(s.iget(i));a[i]=Math.sign(l)*Math.abs(c)}return o}function ey(r,t){let e=x.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,u=t.data,s=B(r.dtype),i=B(t.dtype);for(let c=0;c<o;c++){let l=s?Number(a[c]):a[c],m=i?Number(u[c]):u[c];n[c]=Math.sign(m)*Math.abs(l)}return e}function ny(r,t){let e=x.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size,u=Math.sign(t);if(B(r.dtype)){let s=o;for(let i=0;i<a;i++)n[i]=u*Math.abs(Number(s[i]))}else for(let s=0;s<a;s++)n[s]=u*Math.abs(o[s]);return e}function fs(r){q(r.dtype,"signbit","signbit is only defined for real numbers.");let t=new Uint8Array(r.size),e=r.data,n=r.size;if(B(r.dtype)){let o=e;for(let a=0;a<n;a++)t[a]=o[a]<0n?1:0}else for(let o=0;o<n;o++){let a=e[o];t[o]=a<0||Object.is(a,-0)?1:0}return x.fromData(t,Array.from(r.shape),"bool")}function ms(r,t){if(q(r.dtype,"nextafter","nextafter is only defined for real numbers."),typeof t!="number"&&q(t.dtype,"nextafter","nextafter is only defined for real numbers."),typeof t=="number")return ay(r,t);if(nt(r,t))return oy(r,t);let e=Ir(r.shape,t.shape),n=e.reduce((i,c)=>i*c,1),o=x.zeros(e,"float64"),a=o.data,u=It(r,e),s=It(t,e);for(let i=0;i<n;i++){let c=Number(u.iget(i)),l=Number(s.iget(i));a[i]=et(c,l)}return o}function oy(r,t){let e=x.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,u=t.data,s=B(r.dtype),i=B(t.dtype);for(let c=0;c<o;c++){let l=s?Number(a[c]):a[c],m=i?Number(u[c]):u[c];n[c]=et(l,m)}return e}function ay(r,t){let e=x.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size;if(B(r.dtype)){let u=o;for(let s=0;s<a;s++)n[s]=et(Number(u[s]),t)}else for(let u=0;u<a;u++)n[u]=et(o[u],t);return e}function et(r,t){if(Number.isNaN(r)||Number.isNaN(t))return NaN;if(r===t)return t;if(r===0)return t>0?Number.MIN_VALUE:-Number.MIN_VALUE;let e=new ArrayBuffer(8),n=new Float64Array(e),o=new BigInt64Array(e);n[0]=r;let a=o[0];return r>0&&t>r||r<0&&t>r?a=a+1n:a=a-1n,o[0]=a,n[0]}function ys(r){q(r.dtype,"spacing","spacing is only defined for real numbers.");let t=x.zeros(Array.from(r.shape),"float64"),e=t.data,n=r.data,o=r.size;if(B(r.dtype)){let a=n;for(let u=0;u<o;u++)e[u]=ts(Number(a[u]))}else for(let a=0;a<o;a++)e[a]=ts(n[a]);return t}function ts(r){if(Number.isNaN(r))return NaN;if(!Number.isFinite(r))return NaN;if(Math.abs(r)===0)return Number.MIN_VALUE;let e=et(r,1/0);return Math.abs(e-r)}function It(r,t){let e=r.shape.length,n=t.length,o=new Array(n).fill(0);for(let a=0;a<e;a++){let u=n-e+a,s=r.shape[a],i=t[u];if(s===i)o[u]=r.strides[a];else if(s===1)o[u]=0;else throw new Error("Invalid broadcast")}return x.fromData(r.data,Array.from(t),r.dtype,o,r.offset)}function ps(r){let t=r.dtype,e=r.size,n=new Uint8Array(e);if(M(t)){let o=r.data;for(let a=0;a<e;a++)n[a]=o[a*2+1]!==0?1:0}return x.fromData(n,Array.from(r.shape),"bool")}function ds(r){return M(r.dtype)}function gs(r){let t=r.dtype,e=r.size,n=new Uint8Array(e);if(M(t)){let o=r.data;for(let a=0;a<e;a++)n[a]=o[a*2+1]===0?1:0}else n.fill(1);return x.fromData(n,Array.from(r.shape),"bool")}function As(r){return!M(r.dtype)}function bs(r){q(r.dtype,"isneginf","This operation is not supported for complex values because it would be ambiguous.");let t=new Uint8Array(r.size),e=r.data,n=r.size;if(!B(r.dtype))for(let o=0;o<n;o++){let a=e[o];t[o]=a===-1/0?1:0}return x.fromData(t,Array.from(r.shape),"bool")}function hs(r){q(r.dtype,"isposinf","This operation is not supported for complex values because it would be ambiguous.");let t=new Uint8Array(r.size),e=r.data,n=r.size;if(!B(r.dtype))for(let o=0;o<n;o++){let a=e[o];t[o]=a===1/0?1:0}return x.fromData(t,Array.from(r.shape),"bool")}function Ss(r){return r.isFContiguous}function Ds(r,t=100){let e=r.dtype;if(M(e)){let n=r.data,o=r.size,u=t*(e==="complex64"?11920929e-14:2220446049250313e-31),s=!0;for(let i=0;i<o;i++){let c=n[i*2+1];if(Math.abs(c)>u){s=!1;break}}if(s){let i=e==="complex64"?"float32":"float64",c=x.zeros(Array.from(r.shape),i),l=c.data;for(let m=0;m<o;m++)l[m]=n[m*2];return c}return r.copy()}return r.copy()}function xs(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"||typeof r=="string"}function Ns(r){return r==null?!1:typeof r[Symbol.iterator]=="function"}function ws(r,t){let n={b:["bool"],i:["int8","int16","int32","int64"],u:["uint8","uint16","uint32","uint64"],f:["float32","float64"]}[t];return n?n.includes(r):!1}function Is(r,t){let e=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"],n=e.indexOf(r),o=e.indexOf(t);return n<=o?r:t}function zs(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(M(t)){let o=Zr(t),a=x.zeros(e,o),u=a.data,s=r.data;for(let i=0;i<n;i++)u[i]=s[i*2];return a}return r.copy()}function _s(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(M(t)){let a=Zr(t),u=x.zeros(e,a),s=u.data,i=r.data;for(let c=0;c<n;c++)s[c]=i[c*2+1];return u}let o=t==="float32"?"float32":"float64";return x.zeros(e,o)}function Fs(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(M(t)){let o=P(t),a=n*2,u=new o(a),s=r.data;for(let i=0;i<n;i++)u[i*2]=s[i*2],u[i*2+1]=-s[i*2+1];return x.fromData(u,e,t)}return r.copy()}function Ms(r,t=!1){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=x.zeros(n,"float64"),u=a.data;if(M(e)){let s=r.data;for(let i=0;i<o;i++){let c=s[i*2],l=s[i*2+1],m=Math.atan2(l,c);t&&(m=m*180/Math.PI),u[i]=m}}else for(let s=0;s<o;s++){let i=r.iget(s),l=(i instanceof O?i.re:Number(i))>=0?0:Math.PI;t&&(l=l*180/Math.PI),u[s]=l}return a}function hr(r,t,e){if(e){let n=r[t*2],o=r[t*2+1];return n!==0||o!==0}return!!r[t]}function ot(r,t,e,n){let o=isNaN(r)||isNaN(t),a=isNaN(e)||isNaN(n);return o&&a?0:o?1:a||r<e?-1:r>e?1:t<n?-1:t>n?1:0}function Ie(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return r.copy();let u=t;if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=r.copy(),i=s.data,c=e[u],l=Array.from(e).filter((d,p)=>p!==u),m=l.length===0?1:l.reduce((d,p)=>d*p,1);if(M(o)){let d=a,p=i;for(let f=0;f<m;f++){let y=[];for(let g=0;g<c;g++){let h=$(f,u,g,e),b=U(h,e);y.push({re:d[b*2],im:d[b*2+1],idx:g})}y.sort((g,h)=>ot(g.re,g.im,h.re,h.im));for(let g=0;g<c;g++){let h=$(f,u,g,e),b=U(h,e);p[b*2]=y[g].re,p[b*2+1]=y[g].im}}}else if(B(o)){let d=a,p=i;for(let f=0;f<m;f++){let y=[];for(let g=0;g<c;g++){let h=$(f,u,g,e),b=U(h,e);y.push({value:d[b],idx:g})}y.sort((g,h)=>g.value<h.value?-1:g.value>h.value?1:0);for(let g=0;g<c;g++){let h=$(f,u,g,e),b=U(h,e);p[b]=y[g].value}}}else for(let d=0;d<m;d++){let p=[];for(let f=0;f<c;f++){let y=$(d,u,f,e),g=U(y,e);p.push(Number(a[g]))}p.sort((f,y)=>isNaN(f)&&isNaN(y)?0:isNaN(f)?1:isNaN(y)?-1:f-y);for(let f=0;f<c;f++){let y=$(d,u,f,e),g=U(y,e);i[g]=p[f]}}return s}function ze(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return x.zeros([0],"int32");let u=t;if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=x.zeros(Array.from(e),"int32"),i=s.data,c=e[u],l=Array.from(e).filter((d,p)=>p!==u),m=l.length===0?1:l.reduce((d,p)=>d*p,1);if(M(o)){let d=a;for(let p=0;p<m;p++){let f=[];for(let y=0;y<c;y++){let g=$(p,u,y,e),h=U(g,e);f.push({re:d[h*2],im:d[h*2+1],idx:y})}f.sort((y,g)=>ot(y.re,y.im,g.re,g.im));for(let y=0;y<c;y++){let g=$(p,u,y,e),h=U(g,e);i[h]=f[y].idx}}}else if(B(o)){let d=a;for(let p=0;p<m;p++){let f=[];for(let y=0;y<c;y++){let g=$(p,u,y,e),h=U(g,e);f.push({value:d[h],idx:y})}f.sort((y,g)=>y.value<g.value?-1:y.value>g.value?1:0);for(let y=0;y<c;y++){let g=$(p,u,y,e),h=U(g,e);i[h]=f[y].idx}}}else for(let d=0;d<m;d++){let p=[];for(let f=0;f<c;f++){let y=$(d,u,f,e),g=U(y,e);p.push({value:Number(a[g]),idx:f})}p.sort((f,y)=>isNaN(f.value)&&isNaN(y.value)?0:isNaN(f.value)?1:isNaN(y.value)?-1:f.value-y.value);for(let f=0;f<c;f++){let y=$(d,u,f,e),g=U(y,e);i[g]=p[f].idx}}return s}function Bs(r){if(r.length===0)return x.zeros([0],"int32");let e=r[0].size;for(let u of r){if(u.ndim!==1)throw new Error("keys must be 1D arrays");if(u.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let u=0;u<e;u++)n.push(u);n.sort((u,s)=>{for(let i=r.length-1;i>=0;i--){let l=r[i].data,m=Number(l[u]),d=Number(l[s]);if(!(isNaN(m)&&isNaN(d))){if(isNaN(m))return 1;if(isNaN(d)||m<d)return-1;if(m>d)return 1}}return 0});let o=x.zeros([e],"int32"),a=o.data;for(let u=0;u<e;u++)a[u]=n[u];return o}function uy(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],u=r[o],s=r[n],i;a<=u&&u<=s||s<=u&&u<=a?i=o:u<=a&&a<=s||s<=a&&a<=u?i=e:i=n;let c=r[i];[r[i],r[n]]=[r[n],r[i]];let l=e;for(let m=e;m<n;m++){let d=r[m],p=isNaN(d),f=isNaN(c);!p&&(f||d<=c)&&([r[l],r[m]]=[r[m],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function cy(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],u=r[o],s=r[n],i;a<=u&&u<=s||s<=u&&u<=a?i=o:u<=a&&a<=s||s<=a&&a<=u?i=e:i=n;let c=r[i];[r[i],r[n]]=[r[n],r[i]];let l=e;for(let m=e;m<n;m++)r[m]<=c&&([r[l],r[m]]=[r[m],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function ly(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,u=r[o].value,s=r[n].value,i;a<=u&&u<=s||s<=u&&u<=a?i=o:u<=a&&a<=s||s<=a&&a<=u?i=e:i=n;let c=r[i].value;[r[i],r[n]]=[r[n],r[i]];let l=e;for(let m=e;m<n;m++){let d=r[m].value,p=isNaN(d),f=isNaN(c);!p&&(f||d<=c)&&([r[l],r[m]]=[r[m],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function fy(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,u=r[o].value,s=r[n].value,i;a<=u&&u<=s||s<=u&&u<=a?i=o:u<=a&&a<=s||s<=a&&a<=u?i=e:i=n;let c=r[i].value;[r[i],r[n]]=[r[n],r[i]];let l=e;for(let m=e;m<n;m++)r[m].value<=c&&([r[l],r[m]]=[r[m],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function _e(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype;if(o===0)return r.copy();let u=e;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u],i=t;if(i<0&&(i=s+i),i<0||i>=s)throw new Error(`kth(=${t}) out of bounds (${s})`);let c=r.copy(),l=c.data,m=Array.from(n).filter((p,f)=>f!==u),d=m.length===0?1:m.reduce((p,f)=>p*f,1);if(B(a)){let p=l;for(let f=0;f<d;f++){let y=[];for(let g=0;g<s;g++){let h=$(f,u,g,n),b=U(h,n);y.push(p[b])}cy(y,i);for(let g=0;g<s;g++){let h=$(f,u,g,n),b=U(h,n);p[b]=y[g]}}}else for(let p=0;p<d;p++){let f=[];for(let y=0;y<s;y++){let g=$(p,u,y,n),h=U(g,n);f.push(Number(l[h]))}uy(f,i);for(let y=0;y<s;y++){let g=$(p,u,y,n),h=U(g,n);l[h]=f[y]}}return c}function Fe(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,u=r.data;if(o===0)return x.zeros([0],"int32");let s=e;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[s],c=t;if(c<0&&(c=i+c),c<0||c>=i)throw new Error(`kth(=${t}) out of bounds (${i})`);let l=x.zeros(Array.from(n),"int32"),m=l.data,d=Array.from(n).filter((f,y)=>y!==s),p=d.length===0?1:d.reduce((f,y)=>f*y,1);if(B(a)){let f=u;for(let y=0;y<p;y++){let g=[];for(let h=0;h<i;h++){let b=$(y,s,h,n),A=U(b,n);g.push({value:f[A],idx:h})}fy(g,c);for(let h=0;h<i;h++){let b=$(y,s,h,n),A=U(b,n);m[A]=g[h].idx}}}else for(let f=0;f<p;f++){let y=[];for(let g=0;g<i;g++){let h=$(f,s,g,n),b=U(h,n);y.push({value:Number(u[b]),idx:g})}ly(y,c);for(let g=0;g<i;g++){let h=$(f,s,g,n),b=U(h,n);m[b]=y[g].idx}}return l}function vs(r){let t=r.dtype,e=r.size,n=r.data;if(M(t)){let o=n,a=[];for(let i=0;i<e;i++)a.push({re:o[i*2],im:o[i*2+1]});a.sort((i,c)=>ot(i.re,i.im,c.re,c.im));let u=x.zeros([e],"complex128"),s=u.data;for(let i=0;i<e;i++)s[i*2]=a[i].re,s[i*2+1]=a[i].im;return u}else{let o=[];for(let s=0;s<e;s++)o.push(Number(n[s]));o.sort((s,i)=>isNaN(s)&&isNaN(i)?0:isNaN(s)?1:isNaN(i)?-1:s-i);let a=x.zeros([e],"complex128"),u=a.data;for(let s=0;s<e;s++)u[s*2]=o[s],u[s*2+1]=0;return a}}function zt(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=M(r.dtype),u=[];for(let m=0;m<e;m++)u.push([]);let s=[],i=1;for(let m=e-1;m>=0;m--)s.unshift(i),i*=t[m];for(let m=0;m<o;m++)if(hr(n,m,a)){let d=m;for(let p=0;p<e;p++){let f=Math.floor(d/s[p]);d=d%s[p],u[p].push(f)}}let c=u[0]?.length??0,l=[];for(let m=0;m<e;m++){let d=x.zeros([c],"int32"),p=d.data;for(let f=0;f<c;f++)p[f]=u[m][f];l.push(d)}return l}function Me(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=M(r.dtype),u=[],s=[],i=1;for(let p=e-1;p>=0;p--)s.unshift(i),i*=t[p];for(let p=0;p<o;p++)if(hr(n,p,a)){let f=[],y=p;for(let g=0;g<e;g++){let h=Math.floor(y/s[g]);y=y%s[g],f.push(h)}u.push(f)}let c=u.length,l=e===0?[c,1]:[c,e],m=x.zeros(l,"int32"),d=m.data;for(let p=0;p<c;p++){let f=u[p];for(let y=0;y<(e===0?1:e);y++)d[p*(e===0?1:e)+y]=f[y]??0}return m}function Es(r){let t=r.data,e=r.size,n=M(r.dtype),o=[];for(let s=0;s<e;s++)hr(t,s,n)&&o.push(s);let a=x.zeros([o.length],"int32"),u=a.data;for(let s=0;s<o.length;s++)u[s]=o[s];return a}function Ts(r,t,e){if(t===void 0&&e===void 0)return zt(r);if(t===void 0||e===void 0)throw new Error("either both or neither of x and y should be given");let n=r.shape,o=t.shape,a=e.shape,u=Math.max(n.length,o.length,a.length),s=_=>{let E=Array(u).fill(1);for(let T=0;T<_.length;T++)E[u-_.length+T]=_[T];return E},i=s(n),c=s(o),l=s(a),m=[];for(let _=0;_<u;_++){let E=[i[_],c[_],l[_]],T=Math.max(...E);for(let C of E)if(C!==1&&C!==T)throw new Error("operands could not be broadcast together");m.push(T)}let d=t.dtype,p=x.zeros(m,d),f=p.data,y=r.data,g=t.data,h=e.data,b=(_,E)=>{let T=[],C=1;for(let k=_.length-1;k>=0;k--)T.unshift(C),C*=_[k];for(;T.length<E.length;)T.unshift(0);for(let k=0;k<E.length;k++)E[k]===1&&m[k]!==1&&(T[k]=0);return T},A=b(n,i),S=b(o,c),D=b(a,l),w=[],N=1;for(let _=m.length-1;_>=0;_--)w.unshift(N),N*=m[_];let I=m.reduce((_,E)=>_*E,1),z=M(r.dtype),F=M(d);for(let _=0;_<I;_++){let E=_,T=0,C=0,k=0;for(let V=0;V<u;V++){let R=Math.floor(E/w[V]);E=E%w[V],T+=R*A[V],C+=R*S[V],k+=R*D[V]}hr(y,T,z)?F?(f[_*2]=g[C*2],f[_*2+1]=g[C*2+1]):f[_]=g[C]:F?(f[_*2]=h[k*2],f[_*2+1]=h[k*2+1]):f[_]=h[k]}return p}function Be(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.data,o=r.size,a=t.data,u=t.size,s=M(r.dtype),i=x.zeros([u],"int32"),c=i.data;if(s){let l=n,m=a;for(let d=0;d<u;d++){let p=m[d*2],f=m[d*2+1],y=0,g=o;if(e==="left")for(;y<g;){let h=Math.floor((y+g)/2),b=l[h*2],A=l[h*2+1];ot(b,A,p,f)<0?y=h+1:g=h}else for(;y<g;){let h=Math.floor((y+g)/2),b=l[h*2],A=l[h*2+1];ot(b,A,p,f)<=0?y=h+1:g=h}c[d]=y}}else for(let l=0;l<u;l++){let m=Number(a[l]),d=0,p=o;if(e==="left")for(;d<p;){let f=Math.floor((d+p)/2);Number(n[f])<m?d=f+1:p=f}else for(;d<p;){let f=Math.floor((d+p)/2);Number(n[f])<=m?d=f+1:p=f}c[l]=d}return i}function Os(r,t){let e=r.data,n=t.data,o=t.dtype,a=M(r.dtype),u=M(o),s=Math.min(r.size,t.size),i=0;for(let d=0;d<s;d++)hr(e,d,a)&&i++;let c=x.zeros([i],o),l=c.data,m=0;if(B(o)){let d=n,p=l;for(let f=0;f<s;f++)hr(e,f,a)&&(p[m++]=d[f])}else if(u){let d=n,p=l;for(let f=0;f<s;f++)hr(e,f,a)&&(p[m*2]=d[f*2],p[m*2+1]=d[f*2+1],m++)}else for(let d=0;d<s;d++)hr(e,d,a)&&(l[m++]=n[d]);return c}function ve(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size,u=M(r.dtype);if(t===void 0){let p=0;for(let f=0;f<a;f++)hr(o,f,u)&&p++;return p}let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((p,f)=>f!==s);if(i.length===0)return ve(r);let c=x.zeros(i,"int32"),l=c.data,m=e[s],d=i.reduce((p,f)=>p*f,1);for(let p=0;p<d;p++){let f=0;for(let y=0;y<m;y++){let g=$(p,s,y,e),h=U(g,e);hr(o,h,u)&&f++}l[p]=f}return c}function Cs(r){if(!isFinite(r))return r;let t=Math.floor(r),e=r-t;return Math.abs(e-.5)<1e-10?t%2===0?t:t+1:Math.round(r)}function Ee(r,t=0){q(r.dtype,"around","Rounding is not defined for complex numbers.");let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e==="float32"?"float32":"float64",s=x.zeros(n,u),i=s.data,c=Math.pow(10,t);for(let l=0;l<a;l++){let m=Number(o[l]);i[l]=Cs(m*c)/c}return s}function Te(r){q(r.dtype,"ceil","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",u=x.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Math.ceil(Number(n[i]));return u}function Oe(r){q(r.dtype,"fix","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",u=x.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Math.trunc(Number(n[i]));return u}function Ce(r){q(r.dtype,"floor","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",u=x.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Math.floor(Number(n[i]));return u}function Ue(r){q(r.dtype,"rint","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",u=x.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Cs(Number(n[i]));return u}function $e(r){q(r.dtype,"trunc","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",u=x.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Math.trunc(Number(n[i]));return u}function Re(r,t,e,n){let o=isNaN(r)||isNaN(t),a=isNaN(e)||isNaN(n);return o&&a?0:o?1:a||r<e?-1:r>e?1:t<n?-1:t>n?1:0}function py(r,t,e,n){let o=isNaN(r)||isNaN(t),a=isNaN(e)||isNaN(n);return o&&a?!0:o||a?!1:r===e&&t===n}function wr(r,t=!1,e=!1,n=!1){let o=r.dtype,a=r.size,u=r.data;if(M(o)){let A=u,S=[];for(let R=0;R<a;R++)S.push({re:A[R*2],im:A[R*2+1],index:R});S.sort((R,L)=>Re(R.re,R.im,L.re,L.im));let D=[],w=[],N=new Array(a),I=[],z,F,_=0;for(let R=0;R<S.length;R++){let{re:L,im:j,index:H}=S[R];z===void 0||!py(L,j,z,F)?(z!==void 0&&I.push(_),D.push({re:L,im:j}),w.push(H),_=1,z=L,F=j):_++}_>0&&I.push(_);let E=new Map,T=-1;for(let R=0;R<D.length;R++){let{re:L,im:j}=D[R];isNaN(L)||isNaN(j)?T=R:E.set(`${L},${j}`,R)}for(let R=0;R<a;R++){let L=A[R*2],j=A[R*2+1];isNaN(L)||isNaN(j)?N[R]=T:N[R]=E.get(`${L},${j}`)}let C=x.zeros([D.length],o),k=C.data;for(let R=0;R<D.length;R++)k[R*2]=D[R].re,k[R*2+1]=D[R].im;if(!t&&!e&&!n)return C;let V={values:C};if(t){let R=x.zeros([w.length],"int32"),L=R.data;for(let j=0;j<w.length;j++)L[j]=w[j];V.indices=R}if(e){let R=x.zeros([N.length],"int32"),L=R.data;for(let j=0;j<N.length;j++)L[j]=N[j];V.inverse=R}if(n){let R=x.zeros([I.length],"int32"),L=R.data;for(let j=0;j<I.length;j++)L[j]=I[j];V.counts=R}return V}let s=[];for(let A=0;A<a;A++)s.push({value:Number(u[A]),index:A});s.sort((A,S)=>isNaN(A.value)&&isNaN(S.value)?0:isNaN(A.value)?1:isNaN(S.value)?-1:A.value-S.value);let i=[],c=[],l=new Array(a),m=[],d,p=0;for(let A=0;A<s.length;A++){let{value:S,index:D}=s[A];d===void 0||isNaN(S)&&!isNaN(d)||!isNaN(S)&&isNaN(d)||!isNaN(S)&&!isNaN(d)&&S!==d?(d!==void 0&&m.push(p),i.push(S),c.push(D),p=1,d=S):p++}p>0&&m.push(p);let f=new Map,y=-1;for(let A=0;A<i.length;A++){let S=i[A];isNaN(S)?y=A:f.set(S,A)}for(let A=0;A<a;A++){let S=Number(u[A]);isNaN(S)?l[A]=y:l[A]=f.get(S)}let g=x.zeros([i.length],o),h=g.data;for(let A=0;A<i.length;A++)h[A]=i[A];if(!t&&!e&&!n)return g;let b={values:g};if(t){let A=x.zeros([c.length],"int32"),S=A.data;for(let D=0;D<c.length;D++)S[D]=c[D];b.indices=A}if(e){let A=x.zeros([l.length],"int32"),S=A.data;for(let D=0;D<l.length;D++)S[D]=l[D];b.inverse=A}if(n){let A=x.zeros([m.length],"int32"),S=A.data;for(let D=0;D<m.length;D++)S[D]=m[D];b.counts=A}return b}function Sr(r,t,e){if(e){let n=Number(r[t*2]),o=Number(r[t*2+1]);return`${n},${o}`}return String(Number(r[t]))}function Us(r,t){return ke(r,t)}function $s(r,t){let e=r.dtype,n=M(e),o=wr(r),a=wr(t),u=new Set;for(let l=0;l<a.size;l++)u.add(Sr(a.data,l,n));let s=[];for(let l=0;l<o.size;l++){let m=Sr(o.data,l,n);u.has(m)&&s.push(l)}if(n){let l=x.zeros([s.length],e),m=l.data,d=o.data;for(let p=0;p<s.length;p++){let f=s[p];m[p*2]=d[f*2],m[p*2+1]=d[f*2+1]}return l}let i=x.zeros([s.length],e),c=i.data;for(let l=0;l<s.length;l++)c[l]=o.data[s[l]];return i}function ke(r,t){let e=Array.from(r.shape),n=r.size,o=M(r.dtype),a=new Set;for(let i=0;i<t.size;i++)a.add(Sr(t.data,i,o));let u=x.zeros(e,"bool"),s=u.data;for(let i=0;i<n;i++){let c=Sr(r.data,i,o);s[i]=a.has(c)?1:0}return u}function Rs(r,t){let e=r.dtype,n=M(e),o=wr(r),a=new Set;for(let c=0;c<t.size;c++)a.add(Sr(t.data,c,n));let u=[];for(let c=0;c<o.size;c++){let l=Sr(o.data,c,n);a.has(l)||u.push(c)}if(n){let c=x.zeros([u.length],e),l=c.data,m=o.data;for(let d=0;d<u.length;d++){let p=u[d];l[d*2]=m[p*2],l[d*2+1]=m[p*2+1]}return c}let s=x.zeros([u.length],e),i=s.data;for(let c=0;c<u.length;c++)i[c]=o.data[u[c]];return s}function ks(r,t){let e=r.dtype,n=M(e),o=wr(r),a=wr(t),u=new Set,s=new Set;for(let p=0;p<o.size;p++)u.add(Sr(o.data,p,n));for(let p=0;p<a.size;p++)s.add(Sr(a.data,p,n));let i=[],c=[];for(let p=0;p<o.size;p++){let f=Sr(o.data,p,n);s.has(f)||i.push(p)}for(let p=0;p<a.size;p++){let f=Sr(a.data,p,n);u.has(f)||c.push(p)}if(n){let p=[],f=o.data,y=a.data;for(let b of i)p.push({re:f[b*2],im:f[b*2+1]});for(let b of c)p.push({re:y[b*2],im:y[b*2+1]});p.sort((b,A)=>Re(b.re,b.im,A.re,A.im));let g=x.zeros([p.length],e),h=g.data;for(let b=0;b<p.length;b++)h[b*2]=p[b].re,h[b*2+1]=p[b].im;return g}let l=[];for(let p of i)l.push(Number(o.data[p]));for(let p of c)l.push(Number(a.data[p]));l.sort((p,f)=>isNaN(p)&&isNaN(f)?0:isNaN(p)?1:isNaN(f)?-1:p-f);let m=x.zeros([l.length],e),d=m.data;for(let p=0;p<l.length;p++)d[p]=l[p];return m}function qs(r,t){let e=r.dtype,n=M(e),o=wr(r),a=wr(t),u=new Set,s=[];if(n){let m=o.data,d=a.data;for(let y=0;y<o.size;y++){let g=m[y*2],h=m[y*2+1],b=`${g},${h}`;u.has(b)||(u.add(b),s.push({re:g,im:h}))}for(let y=0;y<a.size;y++){let g=d[y*2],h=d[y*2+1],b=`${g},${h}`;u.has(b)||(u.add(b),s.push({re:g,im:h}))}s.sort((y,g)=>Re(y.re,y.im,g.re,g.im));let p=x.zeros([s.length],e),f=p.data;for(let y=0;y<s.length;y++)f[y*2]=s[y].re,f[y*2+1]=s[y].im;return p}let i=[];for(let m=0;m<o.size;m++){let d=Number(o.data[m]),p=String(d);u.has(p)||(u.add(p),i.push(d))}for(let m=0;m<a.size;m++){let d=Number(a.data[m]),p=String(d);u.has(p)||(u.add(p),i.push(d))}i.sort((m,d)=>isNaN(m)&&isNaN(d)?0:isNaN(m)?1:isNaN(d)?-1:m-d);let c=x.zeros([i.length],e),l=c.data;for(let m=0;m<i.length;m++)l[m]=i[m];return c}function qe(r,t=1,e=-1){if(t<0)throw new Error(`order must be non-negative but got ${t}`);if(t===0)return r.copy();let n=Array.from(r.shape),o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);if(n[a]<t+1)throw new Error(`diff requires at least ${t+1} elements along axis ${e}, but got ${n[a]}`);let u=r;for(let s=0;s<t;s++)u=gy(u,a);return u}function gy(r,t){let e=Array.from(r.shape),n=e.length,o=e[t],a=[...e];a[t]=o-1;let u=r.dtype,s=M(u),i=B(u)?"float64":u,c=x.zeros(a,i),l=c.data,m=r.strides,d=c.size;for(let p=0;p<d;p++){let f=p,y=new Array(n);for(let S=n-1;S>=0;S--)y[S]=f%a[S],f=Math.floor(f/a[S]);let g=[...y],h=[...y];h[t]=g[t]+1;let b=0,A=0;for(let S=0;S<n;S++)b+=g[S]*m[S],A+=h[S]*m[S];if(s){let S=r.data,D=S[b*2],w=S[b*2+1],N=S[A*2],I=S[A*2+1];l[p*2]=N-D,l[p*2+1]=I-w}else{let S=(B(u),Number(r.data[b])),D=(B(u),Number(r.data[A]));l[p]=D-S}}return c}function Vs(r,t=null,e=null){let n=r.size,o=r.dtype,a=M(o),u=B(o)?"float64":o,s=Math.max(0,n-1),i=e?e.length:0,c=t?t.length:0,l=i+s+c,m=x.zeros([l],u),d=m.data,p=0;if(e)if(a)for(let f of e)d[p*2]=f,d[p*2+1]=0,p++;else for(let f of e)d[p++]=f;if(a){let f=r.data;for(let y=0;y<s;y++){let g=f[y*2],h=f[y*2+1],b=f[(y+1)*2],A=f[(y+1)*2+1];d[p*2]=b-g,d[p*2+1]=A-h,p++}}else for(let f=0;f<s;f++){let y=(B(o),Number(r.iget(f))),g=(B(o),Number(r.iget(f+1)));d[p++]=g-y}if(t)if(a)for(let f of t)d[p*2]=f,d[p*2+1]=0,p++;else for(let f of t)d[p++]=f;return m}function js(r,t=1,e=null){let o=Array.from(r.shape).length,a;if(e===null)a=Array.from({length:o},(i,c)=>c);else if(typeof e=="number"){let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);a=[i]}else a=e.map(i=>{let c=i<0?o+i:i;if(c<0||c>=o)throw new Error(`axis ${i} is out of bounds for array of dimension ${o}`);return c});let u;if(typeof t=="number")u=a.map(()=>t);else{if(t.length!==a.length)throw new Error("Number of spacings must match number of axes");u=t}let s=[];for(let i=0;i<a.length;i++)s.push(Ay(r,a[i],u[i]));return s.length===1?s[0]:s}function Ay(r,t,e){let n=Array.from(r.shape),o=n.length,a=n[t];if(a<2)throw new Error(`Shape of array along axis ${t} must be at least 2, but got ${a}`);let u=r.dtype,s=M(u),i=B(u)?"float64":u==="float32"?"float32":s?u:"float64",c=x.zeros(n,i),l=c.data,m=r.strides,d=e,p=2*d,f=r.size;for(let y=0;y<f;y++){let g=y,h=new Array(o);for(let A=o-1;A>=0;A--)h[A]=g%n[A],g=Math.floor(g/n[A]);let b=h[t];if(s){let A=r.data,S=l,D,w;if(b===0){let N=[...h];N[t]=1;let I=0;for(let T=0;T<o;T++)I+=N[T]*m[T];let z=A[y*2],F=A[y*2+1],_=A[I*2],E=A[I*2+1];D=(_-z)/d,w=(E-F)/d}else if(b===a-1){let N=[...h];N[t]=a-2;let I=0;for(let T=0;T<o;T++)I+=N[T]*m[T];let z=A[y*2],F=A[y*2+1],_=A[I*2],E=A[I*2+1];D=(z-_)/d,w=(F-E)/d}else{let N=[...h],I=[...h];N[t]=b+1,I[t]=b-1;let z=0,F=0;for(let k=0;k<o;k++)z+=N[k]*m[k],F+=I[k]*m[k];let _=A[z*2],E=A[z*2+1],T=A[F*2],C=A[F*2+1];D=(_-T)/p,w=(E-C)/p}S[y*2]=D,S[y*2+1]=w}else{let A;if(b===0){let S=[...h];S[t]=1;let D=0;for(let I=0;I<o;I++)D+=S[I]*m[I];let w=(B(u),Number(r.data[y]));A=((B(u),Number(r.data[D]))-w)/d}else if(b===a-1){let S=[...h];S[t]=a-2;let D=0;for(let I=0;I<o;I++)D+=S[I]*m[I];let w=(B(u),Number(r.data[y])),N=(B(u),Number(r.data[D]));A=(w-N)/d}else{let S=[...h],D=[...h];S[t]=b+1,D[t]=b-1;let w=0,N=0;for(let F=0;F<o;F++)w+=S[F]*m[F],N+=D[F]*m[F];let I=(B(u),Number(r.data[w])),z=(B(u),Number(r.data[N]));A=(I-z)/p}l[y]=A}}return c}function Ps(r,t,e=-1,n=-1,o=-1){let a=Array.from(r.shape),u=Array.from(t.shape),s=a.length,i=u.length,c=e<0?s+e:e,l=n<0?i+n:n;if(c<0||c>=s)throw new Error(`axisa ${e} is out of bounds for array of dimension ${s}`);if(l<0||l>=i)throw new Error(`axisb ${n} is out of bounds for array of dimension ${i}`);let m=a[c],d=u[l];if(m!==2&&m!==3)throw new Error(`incompatible dimensions for cross product (dimension must be 2 or 3, got ${m})`);if(d!==2&&d!==3)throw new Error(`incompatible dimensions for cross product (dimension must be 2 or 3, got ${d})`);let p=G(r.dtype,t.dtype),f=M(p),y=(b,A)=>{if(M(b.dtype)){let S=b.data;return[S[A*2],S[A*2+1]]}return[Number(b.iget(A)),0]},g=(b,A,S,D)=>[b*S-A*D,b*D+A*S],h=(b,A,S,D)=>[b-S,A-D];if(s===1&&i===1&&m===3&&d===3){let b=x.zeros([3],p);if(f){let A=b.data,[S,D]=y(r,0),[w,N]=y(r,1),[I,z]=y(r,2),[F,_]=y(t,0),[E,T]=y(t,1),[C,k]=y(t,2),[V,R]=g(w,N,C,k),[L,j]=g(I,z,E,T),[H,Q]=h(V,R,L,j),[Z,rr]=g(I,z,F,_),[tr,er]=g(S,D,C,k),[cr,Rt]=h(Z,rr,tr,er),[kt,qt]=g(S,D,E,T),[Vt,jt]=g(w,N,F,_),[Pt,Lt]=h(kt,qt,Vt,jt);A[0]=H,A[1]=Q,A[2]=cr,A[3]=Rt,A[4]=Pt,A[5]=Lt}else{let A=b.data,S=Number(r.iget(0)),D=Number(r.iget(1)),w=Number(r.iget(2)),N=Number(t.iget(0)),I=Number(t.iget(1)),z=Number(t.iget(2));A[0]=D*z-w*I,A[1]=w*N-S*z,A[2]=S*I-D*N}return b}if(s===1&&i===1&&m===2&&d===2){let b=x.zeros([],p);if(f){let A=b.data,[S,D]=y(r,0),[w,N]=y(r,1),[I,z]=y(t,0),[F,_]=y(t,1),[E,T]=g(S,D,F,_),[C,k]=g(w,N,I,z),[V,R]=h(E,T,C,k);A[0]=V,A[1]=R}else{let A=Number(r.iget(0)),S=Number(r.iget(1)),D=Number(t.iget(0)),w=Number(t.iget(1));b.data[0]=A*w-S*D}return b}if(s===1&&i===1){if(m===2&&d===3){let b=x.zeros([3],p);if(f){let A=b.data,[S,D]=y(r,0),[w,N]=y(r,1),[I,z]=y(t,0),[F,_]=y(t,1),[E,T]=y(t,2),[C,k]=g(w,N,E,T),[V,R]=g(S,D,E,T),L=-V,j=-R,[H,Q]=g(S,D,F,_),[Z,rr]=g(w,N,I,z),[tr,er]=h(H,Q,Z,rr);A[0]=C,A[1]=k,A[2]=L,A[3]=j,A[4]=tr,A[5]=er}else{let A=b.data,S=Number(r.iget(0)),D=Number(r.iget(1)),w=Number(t.iget(0)),N=Number(t.iget(1)),I=Number(t.iget(2));A[0]=D*I,A[1]=-S*I,A[2]=S*N-D*w}return b}else if(m===3&&d===2){let b=x.zeros([3],p);if(f){let A=b.data,[S,D]=y(r,0),[w,N]=y(r,1),[I,z]=y(r,2),[F,_]=y(t,0),[E,T]=y(t,1),[C,k]=g(I,z,E,T),V=-C,R=-k,[L,j]=g(I,z,F,_),[H,Q]=g(S,D,E,T),[Z,rr]=g(w,N,F,_),[tr,er]=h(H,Q,Z,rr);A[0]=V,A[1]=R,A[2]=L,A[3]=j,A[4]=tr,A[5]=er}else{let A=b.data,S=Number(r.iget(0)),D=Number(r.iget(1)),w=Number(r.iget(2)),N=Number(t.iget(0)),I=Number(t.iget(1));A[0]=-w*I,A[1]=w*N,A[2]=S*I-D*N}return b}}if(s===2&&i===2&&c===1&&l===1){let b=a[0];if(u[0]!==b)throw new Error(`Shape mismatch: a has ${b} vectors, b has ${u[0]} vectors`);if(m===3&&d===3){let A=x.zeros([b,3],p);if(f){let S=A.data;for(let D=0;D<b;D++){let[w,N]=y(r,D*3),[I,z]=y(r,D*3+1),[F,_]=y(r,D*3+2),[E,T]=y(t,D*3),[C,k]=y(t,D*3+1),[V,R]=y(t,D*3+2),[L,j]=g(I,z,V,R),[H,Q]=g(F,_,C,k),[Z,rr]=h(L,j,H,Q),[tr,er]=g(F,_,E,T),[cr,Rt]=g(w,N,V,R),[kt,qt]=h(tr,er,cr,Rt),[Vt,jt]=g(w,N,C,k),[Pt,Lt]=g(I,z,E,T),[Gf,Wf]=h(Vt,jt,Pt,Lt);S[D*3*2]=Z,S[D*3*2+1]=rr,S[(D*3+1)*2]=kt,S[(D*3+1)*2+1]=qt,S[(D*3+2)*2]=Gf,S[(D*3+2)*2+1]=Wf}}else{let S=A.data;for(let D=0;D<b;D++){let w=Number(r.iget(D*3)),N=Number(r.iget(D*3+1)),I=Number(r.iget(D*3+2)),z=Number(t.iget(D*3)),F=Number(t.iget(D*3+1)),_=Number(t.iget(D*3+2));S[D*3]=N*_-I*F,S[D*3+1]=I*z-w*_,S[D*3+2]=w*F-N*z}}return A}if(m===2&&d===2){let A=x.zeros([b],p);if(f){let S=A.data;for(let D=0;D<b;D++){let[w,N]=y(r,D*2),[I,z]=y(r,D*2+1),[F,_]=y(t,D*2),[E,T]=y(t,D*2+1),[C,k]=g(w,N,E,T),[V,R]=g(I,z,F,_),[L,j]=h(C,k,V,R);S[D*2]=L,S[D*2+1]=j}}else{let S=A.data;for(let D=0;D<b;D++){let w=Number(r.iget(D*2)),N=Number(r.iget(D*2+1)),I=Number(t.iget(D*2)),z=Number(t.iget(D*2+1));S[D]=w*z-N*I}}return A}}throw new Error(`cross product not implemented for arrays with shapes ${JSON.stringify(a)} and ${JSON.stringify(u)}`)}function Ls(r,t,e=0){q(r.dtype,"bincount","bincount requires integer input.");let n=r.data,o=r.size,a=0;for(let s=0;s<o;s++){let i=Number(n[s]);if(i<0||!Number.isInteger(i))throw new Error("'x' argument must contain non-negative integers");i>a&&(a=i)}let u=Math.max(a+1,e);if(t!==void 0){if(t.size!==o)throw new Error("weights array must have same length as x");let s=t.data,i=new Float64Array(u);for(let c=0;c<o;c++){let l=Number(n[c]);i[l]+=Number(s[c])}return x.fromData(i,[u],"float64")}else{let s=new Float64Array(u);for(let i=0;i<o;i++){let c=Number(n[i]);s[c]++}return x.fromData(s,[u],"float64")}}function Zs(r,t,e=!1){q(r.dtype,"digitize","digitize requires real numbers."),q(t.dtype,"digitize","digitize requires real numbers.");let n=r.data,o=t.data,a=r.size,u=t.size,s=new Float64Array(a),i=!0;u>1&&(i=Number(o[1])>=Number(o[0]));for(let c=0;c<a;c++){let l=Number(n[c]),m;if(i)e?m=hy(o,u,l):m=at(o,u,l);else if(e)for(m=0;m<u&&Number(o[m])>=l;)m++;else for(m=0;m<u&&Number(o[m])>l;)m++;s[c]=m}return x.fromData(s,[...r.shape],"float64")}function hy(r,t,e){let n=0,o=t;for(;n<o;){let a=n+o>>>1;Number(r[a])<e?n=a+1:o=a}return n}function at(r,t,e){let n=0,o=t;for(;n<o;){let a=n+o>>>1;Number(r[a])<=e?n=a+1:o=a}return n}function Gs(r,t=10,e,n=!1,o){q(r.dtype,"histogram","histogram requires real numbers."),typeof t!="number"&&q(t.dtype,"histogram","histogram requires real numbers.");let a=r.data,u=r.size,s;if(typeof t=="number"){let m,d;if(e)[m,d]=e;else{m=1/0,d=-1/0;for(let f=0;f<u;f++){let y=Number(a[f]);y<m&&(m=y),y>d&&(d=y)}m===d&&(m=m-.5,d=d+.5)}s=[];let p=(d-m)/t;for(let f=0;f<=t;f++)s.push(m+f*p)}else{let m=t.data;s=[];for(let d=0;d<t.size;d++)s.push(Number(m[d]))}let i=s.length-1,c=new Float64Array(i),l=o?.data;for(let m=0;m<u;m++){let d=Number(a[m]),p=l?Number(l[m]):1,f=at(s,s.length,d)-1;if(!(f<0)){if(f>=i)if(d===s[i])f=i-1;else continue;c[f]+=p}}if(n){let m=0;for(let d=0;d<i;d++)m+=c[d];for(let d=0;d<i;d++){let p=s[d+1]-s[d];c[d]=c[d]/(m*p)}}return{hist:x.fromData(c,[i],"float64"),bin_edges:x.fromData(new Float64Array(s),[s.length],"float64")}}function Ws(r,t,e=10,n,o=!1,a){q(r.dtype,"histogram2d","histogram2d requires real numbers."),q(t.dtype,"histogram2d","histogram2d requires real numbers.");let u=r.data,s=t.data,i=r.size;if(t.size!==i)throw new Error("x and y must have the same length");let c,l,m,d;if(typeof e=="number"?(m=e,d=e):Array.isArray(e)&&e.length===2?(e[0],m=e[0],d=e[1]):(m=10,d=10),typeof m=="number"){let h,b;if(n)[h,b]=n[0];else{h=1/0,b=-1/0;for(let S=0;S<i;S++){let D=Number(u[S]);D<h&&(h=D),D>b&&(b=D)}h===b&&(h-=.5,b+=.5)}c=[];let A=(b-h)/m;for(let S=0;S<=m;S++)c.push(h+S*A)}else{let h=m.data;c=[];for(let b=0;b<m.size;b++)c.push(Number(h[b]))}if(typeof d=="number"){let h,b;if(n)[h,b]=n[1];else{h=1/0,b=-1/0;for(let S=0;S<i;S++){let D=Number(s[S]);D<h&&(h=D),D>b&&(b=D)}h===b&&(h-=.5,b+=.5)}l=[];let A=(b-h)/d;for(let S=0;S<=d;S++)l.push(h+S*A)}else{let h=d.data;l=[];for(let b=0;b<d.size;b++)l.push(Number(h[b]))}let p=c.length-1,f=l.length-1,y=new Float64Array(p*f),g=a?.data;for(let h=0;h<i;h++){let b=Number(u[h]),A=Number(s[h]),S=g?Number(g[h]):1,D=at(c,c.length,b)-1,w=at(l,l.length,A)-1;if(D<0||D>=p)if(b===c[p]&&D===p)D=p-1;else continue;if(w<0||w>=f)if(A===l[f]&&w===f)w=f-1;else continue;y[D*f+w]+=S}if(o){let h=0;for(let b=0;b<y.length;b++)h+=y[b];for(let b=0;b<p;b++)for(let A=0;A<f;A++){let S=c[b+1]-c[b],D=l[A+1]-l[A],w=S*D;y[b*f+A]=y[b*f+A]/(h*w)}}return{hist:x.fromData(y,[p,f],"float64"),x_edges:x.fromData(new Float64Array(c),[c.length],"float64"),y_edges:x.fromData(new Float64Array(l),[l.length],"float64")}}function Ys(r,t=10,e,n=!1,o){q(r.dtype,"histogramdd","histogramdd requires real numbers.");let a=r.shape,u=r.data,s,i;if(a.length===1)s=a[0],i=1;else if(a.length===2)s=a[0],i=a[1];else throw new Error("sample must be 1D or 2D array");let c;if(typeof t=="number")c=new Array(i).fill(t);else if(c=t,c.length!==i)throw new Error("bins array length must match number of dimensions");let l=[];for(let h=0;h<i;h++){let b,A;if(e&&e[h])[b,A]=e[h];else{b=1/0,A=-1/0;for(let N=0;N<s;N++){let I=Number(i===1?u[N]:u[N*i+h]);I<b&&(b=I),I>A&&(A=I)}b===A&&(b-=.5,A+=.5)}let S=c[h],D=[],w=(A-b)/S;for(let N=0;N<=S;N++)D.push(b+N*w);l.push(D)}let m=c.slice(),d=m.reduce((h,b)=>h*b,1),p=new Float64Array(d),f=new Array(i);f[i-1]=1;for(let h=i-2;h>=0;h--)f[h]=f[h+1]*c[h+1];let y=o?.data;for(let h=0;h<s;h++){let b=y?Number(y[h]):1,A=0,S=!1;for(let D=0;D<i;D++){let w=Number(i===1?u[h]:u[h*i+D]),N=l[D],I=c[D],z=at(N,N.length,w)-1;if(z<0||z>=I)if(w===N[I]&&z===I)z=I-1;else{S=!0;break}A+=z*f[D]}S||(p[A]+=b)}if(n){let h=0;for(let A=0;A<d;A++)h+=p[A];let b=new Float64Array(d);for(let A=0;A<d;A++){let S=1,D=A;for(let w=0;w<i;w++){let N=Math.floor(D/f[w])%c[w],I=l[w];S*=I[N+1]-I[N]}b[A]=S}for(let A=0;A<d;A++)p[A]=p[A]/(h*b[A])}let g=l.map(h=>x.fromData(new Float64Array(h),[h.length],"float64"));return{hist:x.fromData(p,m,"float64"),edges:g}}function Ve(r,t,e="full"){let n=r.data,o=t.data,a=r.size,u=t.size,s=M(r.dtype)||M(t.dtype),i=a+u-1;if(s){let l=new Float64Array(i),m=new Float64Array(i),d=M(r.dtype),p=M(t.dtype);for(let y=0;y<i;y++){let g=0,h=0,b=y-u+1;for(let A=0;A<a;A++){let S=A-b;if(S>=0&&S<u){let D,w,N,I;d?(D=n[A*2],w=n[A*2+1]):(D=Number(n[A]),w=0),p?(N=o[S*2],I=o[S*2+1]):(N=Number(o[S]),I=0),g+=D*N+w*I,h+=w*N-D*I}}l[y]=g,m[y]=h}let f=(y,g,h,b=0)=>{let A=new Float64Array(h*2);for(let S=0;S<h;S++)A[S*2]=y[b+S],A[S*2+1]=g[b+S];return x.fromData(A,[h],"complex128")};if(e==="full")return f(l,m,i);if(e==="same"){let y=Math.floor((i-a)/2);return f(l,m,a,y)}else{let y=Math.max(a,u)-Math.min(a,u)+1,g=Math.min(a,u)-1;return f(l,m,y,g)}}let c=new Float64Array(i);for(let l=0;l<i;l++){let m=0,d=l-u+1;for(let p=0;p<a;p++){let f=p-d;f>=0&&f<u&&(m+=Number(n[p])*Number(o[f]))}c[l]=m}if(e==="full")return x.fromData(c,[i],"float64");if(e==="same"){let l=Math.floor((i-a)/2),m=new Float64Array(a);for(let d=0;d<a;d++)m[d]=c[l+d];return x.fromData(m,[a],"float64")}else{let l=Math.max(a,u)-Math.min(a,u)+1,m=Math.min(a,u)-1,d=new Float64Array(l);for(let p=0;p<l;p++)d[p]=c[m+p];return x.fromData(d,[l],"float64")}}function Hs(r,t,e="full"){let n=t.data,o=t.size,a=M(t.dtype),u;if(a){let s=new Float64Array(o*2);for(let i=0;i<o;i++){let c=o-1-i;s[i*2]=n[c*2],s[i*2+1]=n[c*2+1]}u=x.fromData(s,[o],t.dtype)}else{let s=new Float64Array(o);for(let i=0;i<o;i++)s[i]=Number(n[o-1-i]);u=x.fromData(s,[o],"float64")}if(a){let s=u.data;for(let i=0;i<o;i++)s[i*2+1]=-s[i*2+1]}return Ve(r,u,e)}function je(r,t,e=!0,n=!1,o){let a=r.shape,u=r.data,s=M(r.dtype)||t!==void 0&&M(t.dtype),i;if(o!==void 0?i=o:i=n?0:1,a.length===1)if(t!==void 0){let f=t.data,y=r.size,g=M(r.dtype),h=M(t.dtype);if(t.size!==y)throw new Error("m and y must have same length");if(s){let I=0,z=0,F=0,_=0;for(let Z=0;Z<y;Z++)g?(I+=u[Z*2],z+=u[Z*2+1]):I+=Number(u[Z]),h?(F+=f[Z*2],_+=f[Z*2+1]):F+=Number(f[Z]);I/=y,z/=y,F/=y,_/=y;let E=0,T=0,C=0,k=0,V=0,R=0,L=0,j=0;for(let Z=0;Z<y;Z++){let rr,tr,er,cr;g?(rr=u[Z*2]-I,tr=u[Z*2+1]-z):(rr=Number(u[Z])-I,tr=0),h?(er=f[Z*2]-F,cr=f[Z*2+1]-_):(er=Number(f[Z])-F,cr=0),E+=rr*rr+tr*tr,C+=er*er+cr*cr,V+=rr*er+tr*cr,R+=tr*er-rr*cr,L+=er*rr+cr*tr,j+=cr*rr-er*tr}let H=y-i;if(H<=0){let Z=new Float64Array(8);return Z.fill(NaN),x.fromData(Z,[2,2],"complex128")}E/=H,C/=H,V/=H,R/=H,L/=H,j/=H;let Q=new Float64Array(8);return Q[0]=E,Q[1]=T,Q[2]=V,Q[3]=R,Q[4]=L,Q[5]=j,Q[6]=C,Q[7]=k,x.fromData(Q,[2,2],"complex128")}let b=0,A=0;for(let I=0;I<y;I++)b+=Number(u[I]),A+=Number(f[I]);b/=y,A/=y;let S=0,D=0,w=0;for(let I=0;I<y;I++){let z=Number(u[I])-b,F=Number(f[I])-A;S+=z*z,D+=F*F,w+=z*F}let N=y-i;return N<=0?x.fromData(new Float64Array([NaN,NaN,NaN,NaN]),[2,2],"float64"):(S/=N,D/=N,w/=N,x.fromData(new Float64Array([S,w,w,D]),[2,2],"float64"))}else{let f=r.size;if(s){let b=0,A=0;for(let w=0;w<f;w++)b+=u[w*2],A+=u[w*2+1];b/=f,A/=f;let S=0;for(let w=0;w<f;w++){let N=u[w*2]-b,I=u[w*2+1]-A;S+=N*N+I*I}let D=f-i;return D<=0?x.fromData(new Float64Array([NaN,0]),[],"complex128"):(S/=D,x.fromData(new Float64Array([S,0]),[],"complex128"))}let y=0;for(let b=0;b<f;b++)y+=Number(u[b]);y/=f;let g=0;for(let b=0;b<f;b++){let A=Number(u[b])-y;g+=A*A}let h=f-i;return h<=0?x.fromData(new Float64Array([NaN]),[],"float64"):(g/=h,x.fromData(new Float64Array([g]),[],"float64"))}let c,l;e?(c=a[0],l=a[1]):(c=a[1],l=a[0]);let m=l-i;if(s){let f=new Float64Array(c),y=new Float64Array(c);for(let h=0;h<c;h++){let b=0,A=0;for(let S=0;S<l;S++){let D=e?h*l+S:S*c+h;b+=u[D*2],A+=u[D*2+1]}f[h]=b/l,y[h]=A/l}let g=new Float64Array(c*c*2);if(m<=0)return g.fill(NaN),x.fromData(g,[c,c],"complex128");for(let h=0;h<c;h++)for(let b=0;b<c;b++){let A=0,S=0;for(let w=0;w<l;w++){let N=e?h*l+w:w*c+h,I=e?b*l+w:w*c+b,z=u[N*2]-f[h],F=u[N*2+1]-y[h],_=u[I*2]-f[b],E=u[I*2+1]-y[b];A+=z*_+F*E,S+=F*_-z*E}let D=(h*c+b)*2;g[D]=A/m,g[D+1]=S/m}return x.fromData(g,[c,c],"complex128")}let d=new Float64Array(c);for(let f=0;f<c;f++){let y=0;for(let g=0;g<l;g++){let h=e?f*l+g:g*c+f;y+=Number(u[h])}d[f]=y/l}let p=new Float64Array(c*c);if(m<=0)return p.fill(NaN),x.fromData(p,[c,c],"float64");for(let f=0;f<c;f++)for(let y=f;y<c;y++){let g=0;for(let b=0;b<l;b++){let A=e?f*l+b:b*c+f,S=e?y*l+b:b*c+y,D=Number(u[A])-d[f],w=Number(u[S])-d[y];g+=D*w}let h=g/m;p[f*c+y]=h,p[y*c+f]=h}return x.fromData(p,[c,c],"float64")}function Js(r,t,e=!0){let n=M(r.dtype)||t!==void 0&&M(t.dtype);if(r.shape.length===1&&t===void 0)return n?x.fromData(new Float64Array([1,0]),[],"complex128"):x.fromData(new Float64Array([1]),[],"float64");let o=je(r,t,e,!1),a=o.data,s=o.shape[0];if(n){let c=new Float64Array(s*s*2);for(let l=0;l<s;l++)for(let m=0;m<s;m++){let d=a[(l*s+m)*2],p=a[(l*s+m)*2+1],f=a[(l*s+l)*2],y=a[(m*s+m)*2],g=(l*s+m)*2;if(f<=0||y<=0)c[g]=NaN,c[g+1]=NaN;else{let h=Math.sqrt(f*y);c[g]=d/h,c[g+1]=p/h}}return x.fromData(c,[s,s],"complex128")}let i=new Float64Array(s*s);for(let c=0;c<s;c++)for(let l=0;l<s;l++){let m=Number(a[c*s+l]),d=Number(a[c*s+c]),p=Number(a[l*s+l]);d<=0||p<=0?i[c*s+l]=NaN:i[c*s+l]=m/Math.sqrt(d*p)}return x.fromData(i,[s,s],"float64")}var v=class r{constructor(t,e){this._storage=t,this._base=e}get storage(){return this._storage}static _fromStorage(t,e){return new r(t,e)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get T(){return this.transpose()}get itemsize(){return yt(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){let e=this._storage.dtype,n=this.size;if(B(e)){let o=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let a=0;a<n;a++)this._storage.iset(a,o)}else if(e==="bool"){let o=t?1:0;for(let a=0;a<n;a++)this._storage.iset(a,o)}else{let o=Number(t);for(let a=0;a<n;a++)this._storage.iset(a,o)}}*[Symbol.iterator](){if(this.ndim===0)yield this._storage.iget(0);else if(this.ndim===1)for(let t=0;t<this.shape[0];t++)yield this._storage.iget(t);else for(let t=0;t<this.shape[0];t++)yield this.slice(String(t))}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let e=t.map((n,o)=>{let a=n;if(a<0&&(a=this.shape[o]+a),a<0||a>=this.shape[o])throw new Error(`Index ${n} is out of bounds for axis ${o} with size ${this.shape[o]}`);return a});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let n=t.map((a,u)=>{let s=a;if(s<0&&(s=this.shape[u]+s),s<0||s>=this.shape[u])throw new Error(`Index ${a} is out of bounds for axis ${u} with size ${this.shape[u]}`);return s}),o=this.dtype;if(M(o))this._storage.set(n,e);else if(B(o)){let a=e instanceof O?e.re:Number(e),u=typeof e=="bigint"?e:BigInt(Math.round(a));this._storage.set(n,u)}else if(o==="bool"){let u=(e instanceof O?e.re:Number(e))?1:0;this._storage.set(n,u)}else{let a=e instanceof O?e.re:Number(e);this._storage.set(n,a)}}copy(){return new r(this._storage.copy())}astype(t,e=!0){let n=this.dtype;if(n===t&&!e)return this;if(n===t&&e)return this.copy();let o=Array.from(this.shape),a=this.size,u=P(t);if(!u)throw new Error(`Cannot convert to dtype ${t}`);let s=new u(a),i=this.data;if(B(n)&&!B(t)){let l=i;if(t==="bool")for(let m=0;m<a;m++)s[m]=l[m]!==BigInt(0)?1:0;else for(let m=0;m<a;m++)s[m]=Number(l[m])}else if(!B(n)&&B(t)){let l=i;for(let m=0;m<a;m++)s[m]=BigInt(Math.round(Number(l[m])))}else if(t==="bool"){let l=i;for(let m=0;m<a;m++)s[m]=l[m]!==0?1:0}else if(n==="bool"&&!B(t)){let l=i;for(let m=0;m<a;m++)s[m]=l[m]}else if(!B(n)&&!B(t)){let l=i;for(let m=0;m<a;m++)s[m]=l[m]}else{let l=i;for(let m=0;m<a;m++)s[m]=l[m]}let c=x.fromData(s,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=vn(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=En(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=Tn(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=On(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=dt(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=Yt(this._storage,e);return r._fromStorage(n)}positive(){let t=Rn(this._storage);return r._fromStorage(t)}reciprocal(){let t=kn(this._storage);return r._fromStorage(t)}sqrt(){let t=Ko(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=ra(this._storage,e);return r._fromStorage(n)}exp(){let t=ta(this._storage);return r._fromStorage(t)}exp2(){let t=ea(this._storage);return r._fromStorage(t)}expm1(){let t=na(this._storage);return r._fromStorage(t)}log(){let t=oa(this._storage);return r._fromStorage(t)}log2(){let t=aa(this._storage);return r._fromStorage(t)}log10(){let t=sa(this._storage);return r._fromStorage(t)}log1p(){let t=ia(this._storage);return r._fromStorage(t)}logaddexp(t){let e=typeof t=="number"?t:t._storage,n=ua(this._storage,e);return r._fromStorage(n)}logaddexp2(t){let e=typeof t=="number"?t:t._storage,n=ca(this._storage,e);return r._fromStorage(n)}absolute(){let t=Cn(this._storage);return r._fromStorage(t)}negative(){let t=Un(this._storage);return r._fromStorage(t)}sign(){let t=$n(this._storage);return r._fromStorage(t)}around(t=0){let e=Ee(this._storage,t);return r._fromStorage(e)}round(t=0){return this.around(t)}ceil(){let t=Te(this._storage);return r._fromStorage(t)}fix(){let t=Oe(this._storage);return r._fromStorage(t)}floor(){let t=Ce(this._storage);return r._fromStorage(t)}rint(){let t=Ue(this._storage);return r._fromStorage(t)}trunc(){let t=$e(this._storage);return r._fromStorage(t)}sin(){let t=la(this._storage);return r._fromStorage(t)}cos(){let t=fa(this._storage);return r._fromStorage(t)}tan(){let t=ma(this._storage);return r._fromStorage(t)}arcsin(){let t=ya(this._storage);return r._fromStorage(t)}arccos(){let t=pa(this._storage);return r._fromStorage(t)}arctan(){let t=da(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=ga(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=Aa(this._storage,e);return r._fromStorage(n)}degrees(){let t=ba(this._storage);return r._fromStorage(t)}radians(){let t=ha(this._storage);return r._fromStorage(t)}sinh(){let t=Sa(this._storage);return r._fromStorage(t)}cosh(){let t=Da(this._storage);return r._fromStorage(t)}tanh(){let t=xa(this._storage);return r._fromStorage(t)}arcsinh(){let t=Na(this._storage);return r._fromStorage(t)}arccosh(){let t=wa(this._storage);return r._fromStorage(t)}arctanh(){let t=Ia(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=ro(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=to(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=eo(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=no(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=oo(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=ao(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=Ht(this._storage,o,e,n);return r._fromStorage(a)}allclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage;return so(this._storage,o,e,n)}bitwise_and(t){let e=typeof t=="number"?t:t._storage,n=Wa(this._storage,e);return r._fromStorage(n)}bitwise_or(t){let e=typeof t=="number"?t:t._storage,n=Ya(this._storage,e);return r._fromStorage(n)}bitwise_xor(t){let e=typeof t=="number"?t:t._storage,n=Ha(this._storage,e);return r._fromStorage(n)}bitwise_not(){let t=we(this._storage);return r._fromStorage(t)}invert(){let t=Ja(this._storage);return r._fromStorage(t)}left_shift(t){let e=typeof t=="number"?t:t._storage,n=Xa(this._storage,e);return r._fromStorage(n)}right_shift(t){let e=typeof t=="number"?t:t._storage,n=Qa(this._storage,e);return r._fromStorage(n)}logical_and(t){let e=typeof t=="number"?t:t._storage,n=es(this._storage,e);return r._fromStorage(n)}logical_or(t){let e=typeof t=="number"?t:t._storage,n=ns(this._storage,e);return r._fromStorage(n)}logical_not(){let t=os(this._storage);return r._fromStorage(t)}logical_xor(t){let e=typeof t=="number"?t:t._storage,n=as(this._storage,e);return r._fromStorage(n)}isfinite(){let t=ss(this._storage);return r._fromStorage(t)}isinf(){let t=is(this._storage);return r._fromStorage(t)}isnan(){let t=us(this._storage);return r._fromStorage(t)}isnat(){let t=cs(this._storage);return r._fromStorage(t)}copysign(t){let e=typeof t=="number"?t:t._storage,n=ls(this._storage,e);return r._fromStorage(n)}signbit(){let t=fs(this._storage);return r._fromStorage(t)}nextafter(t){let e=typeof t=="number"?t:t._storage,n=ms(this._storage,e);return r._fromStorage(n)}spacing(){let t=ys(this._storage);return r._fromStorage(t)}sum(t,e=!1){let n=Gr(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}mean(t,e=!1){let n=gt(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}max(t,e=!1){let n=Cr(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}min(t,e=!1){let n=Ur(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}prod(t,e=!1){let n=Jt(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}argmin(t){let e=Xt(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=Qt(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=Kt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=uo(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=re(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=te(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(ee(this._storage,t))}cumprod(t){return r._fromStorage(ne(this._storage,t))}ptp(t,e=!1){let n=oe(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}median(t,e=!1){let n=ae(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=se(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=Rr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=Wr(this._storage,e,t?.storage);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}nansum(t,e=!1){let n=At(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}nanprod(t,e=!1){let n=bt(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}nanmean(t,e=!1){let n=ht(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=$r(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=ie(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=Yr(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}nanmax(t,e=!1){let n=Hr(this._storage,t,e);return typeof n=="number"||n instanceof O?n:r._fromStorage(n)}nanargmin(t){let e=Jr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=Xr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(ue(this._storage,t))}nancumprod(t){return r._fromStorage(ce(this._storage,t))}nanmedian(t,e=!1){let n=St(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}sort(t=-1){return r._fromStorage(Ie(this._storage,t))}argsort(t=-1){return r._fromStorage(ze(this._storage,t))}partition(t,e=-1){return r._fromStorage(_e(this._storage,t,e))}argpartition(t,e=-1){return r._fromStorage(Fe(this._storage,t,e))}nonzero(){return zt(this._storage).map(e=>r._fromStorage(e))}argwhere(){return r._fromStorage(Me(this._storage))}searchsorted(t,e="left"){return r._fromStorage(Be(this._storage,t._storage,e))}diff(t=1,e=-1){return r._fromStorage(qe(this._storage,t,e))}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=nr(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Dt(this._storage);return r._fromStorage(t)}ravel(){let t=kr(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=Kr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=co(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=Qr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=lo(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=le(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=So(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=_a(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;Fa(this._storage,t,n)}iindex(t,e=0){let n;if(t instanceof r){n=[];for(let o=0;o<t.size;o++){let a=t.storage.iget(o),u=typeof a=="bigint"?Number(a):a instanceof O?a.re:a;n.push(u)}}else Array.isArray(t)&&t.length>0&&Array.isArray(t[0])?n=t.flat():n=t;return this.take(n,e)}bindex(t,e){return r._fromStorage(Se(t._storage,this._storage,e))}matmul(t){let e=pr(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=ye(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"||e instanceof O?e:r._fromStorage(e)}trace(){return Oo(this._storage)}inner(t){let e=Co(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"||e instanceof O?e:r._fromStorage(e)}outer(t){let e=pe(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=Uo(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"||n instanceof O?n:r._fromStorage(n)}cbrt(){let t=qn(this._storage);return r._fromStorage(t)}fabs(){let t=Vn(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=jn(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=Pn(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=Ln(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=Zn(this._storage,e);return r._fromStorage(n)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);let e=t.map((i,c)=>{let l=zn(i);return _n(l,this.shape[c])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});let n=[],o=[],a=this._storage.offset;for(let i=0;i<e.length;i++){let c=e[i],l=this._storage.strides[i];if(a+=c.start*l,!c.isIndex){let m;c.step>0?m=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):m=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(m),o.push(l*c.step)}}let u=x.fromData(this._storage.data,n,this._storage.dtype,o,a),s=this._base??this;return new r(u,s)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let t=this.shape,e=t.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let u=[];for(let s=0;s<t[a];s++)o[a]=s,u.push(n(o,a+1));return u};return n(new Array(e),0)}};function Dr(r,t=X){let e=x.zeros(r,t);return new v(e)}function Pe(r,t=X){let e=x.ones(r,t);return new v(e)}function Dy(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function Xs(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>Xs(t)):!1}function Qs(r){return Bn(r)?!0:Array.isArray(r)?r.some(t=>Qs(t)):!1}function xy(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function or(r,t){if(r instanceof v)return!t||r.dtype===t?r.copy():r.astype(t);let e=Xs(r),n=Qs(r),o=Dy(r),a=o.reduce((p,f)=>p*f,1),u=t;u||(n?u="complex128":e?u="int64":u=X);let s=M(u),i=P(u);if(!i)throw new Error(`Cannot create array with dtype ${u}`);let c=s?a*2:a,l=new i(c),m=xy(r);if(B(u)){let p=l;for(let f=0;f<a;f++){let y=m[f];p[f]=typeof y=="bigint"?y:BigInt(Math.round(Number(y)))}}else if(u==="bool"){let p=l;for(let f=0;f<a;f++)p[f]=m[f]?1:0}else if(s){let p=l;for(let f=0;f<a;f++){let y=m[f],g,h;y instanceof O?(g=y.re,h=y.im):typeof y=="object"&&y!==null&&"re"in y?(g=y.re,h=y.im??0):(g=Number(y),h=0),p[f*2]=g,p[f*2+1]=h}}else{let p=l;for(let f=0;f<a;f++){let y=m[f];p[f]=Number(y)}}let d=x.fromData(l,o,u);return new v(d)}function Ks(r,t,e=1,n=X){let o=r,a=t;if(t===void 0&&(o=0,a=r),a===void 0)throw new Error("stop is required");let u=Math.max(0,Math.ceil((a-o)/e)),s=P(n);if(!s)throw new Error(`Cannot create arange array with dtype ${n}`);let i=new s(u);if(B(n))for(let l=0;l<u;l++)i[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<u;l++)i[l]=o+l*e!==0?1:0;else for(let l=0;l<u;l++)i[l]=o+l*e;let c=x.fromData(i,[u],n);return new v(c)}function ri(r,t,e=50,n=X){if(e<0)throw new Error("num must be non-negative");if(e===0)return or([],n);if(e===1)return or([r],n);let o=P(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),u=(t-r)/(e-1);if(B(n))for(let i=0;i<e;i++)a[i]=BigInt(Math.round(r+i*u));else if(n==="bool")for(let i=0;i<e;i++)a[i]=r+i*u!==0?1:0;else for(let i=0;i<e;i++)a[i]=r+i*u;let s=x.fromData(a,[e],n);return new v(s)}function ti(r,t,e=50,n=10,o=X){if(e<0)throw new Error("num must be non-negative");if(e===0)return or([],o);if(e===1)return or([Math.pow(n,r)],o);let a=P(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let u=new a(e),s=(t-r)/(e-1);if(B(o))for(let c=0;c<e;c++){let l=r+c*s;u[c]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let c=0;c<e;c++){let l=r+c*s;u[c]=Math.pow(n,l)!==0?1:0}else for(let c=0;c<e;c++){let l=r+c*s;u[c]=Math.pow(n,l)}let i=x.fromData(u,[e],o);return new v(i)}function ei(r,t,e=50,n=X){if(e<0)throw new Error("num must be non-negative");if(r===0||t===0)throw new Error("Geometric sequence cannot include zero");if(e===0)return or([],n);if(e===1)return or([r],n);let o=Math.sign(r),a=Math.sign(t);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let u=P(n);if(!u)throw new Error(`Cannot create geomspace array with dtype ${n}`);let s=new u(e),i=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-i)/(e-1);if(B(n))for(let d=0;d<e;d++){let p=o*Math.exp(i+d*l);s[d]=BigInt(Math.round(p))}else if(n==="bool")for(let d=0;d<e;d++){let p=o*Math.exp(i+d*l);s[d]=p!==0?1:0}else for(let d=0;d<e;d++){let p=o*Math.exp(i+d*l);s[d]=p}let m=x.fromData(s,[e],n);return new v(m)}function Le(r,t,e=0,n=X){let o=t??r,a=Dr([r,o],n),u=a.data;if(B(n)){let s=u;for(let i=0;i<r;i++){let c=i+e;c>=0&&c<o&&(s[i*o+c]=BigInt(1))}}else{let s=u;for(let i=0;i<r;i++){let c=i+e;c>=0&&c<o&&(s[i*o+c]=1)}}return a}function Ze(r,t=X){return Dr(r,t)}function Ge(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=X);let o=P(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((i,c)=>i*c,1),u=new o(a);if(B(n)){let i=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));u.fill(i)}else n==="bool"?u.fill(t?1:0):u.fill(Number(t));let s=x.fromData(u,r,n);return new v(s)}function ni(r,t=X){return Le(r,r,0,t)}function st(r,t){return r instanceof v?!t||r.dtype===t?r:r.astype(t):or(r,t)}function oi(r){return r.copy()}function ai(r,t){return Dr(Array.from(r.shape),t??r.dtype)}function si(r,t){return Pe(Array.from(r.shape),t??r.dtype)}function ii(r,t){return Ze(Array.from(r.shape),t??r.dtype)}function ui(r,t,e){return Ge(Array.from(r.shape),t,e??r.dtype)}function ci(r,t){return st(r,t)}function li(r,t){let e=st(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function fi(r,t){return st(r,t).copy()}function We(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=Dr([n,n],r.dtype);for(let a=0;a<e;a++){let u=t>=0?a:a-t,s=t>=0?a+t:a;o.set([u,s],r.get([a]))}return o}else if(r.ndim===2){let[e,n]=r.shape,o,a,u;if(t>=0?(o=0,a=t,u=Math.min(e,n-t)):(o=-t,a=0,u=Math.min(e+t,n)),u<=0)return Dr([0],r.dtype);let s=P(r.dtype),i=new s(u);for(let l=0;l<u;l++){let m=r.get([o+l,a+l]);B(r.dtype)?i[l]=typeof m=="bigint"?m:BigInt(m):i[l]=m}let c=x.fromData(i,[u],r.dtype);return new v(c)}else throw new Error("Input must be 1-D or 2-D")}function mi(r,t=0){let e=r.flatten();return We(e,t)}function yi(r,t,e=X){let n=t.reduce((c,l)=>c*l,1),o=P(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),u=t.length,s=new Array(u).fill(0);for(let c=0;c<n;c++){let l=r(...s);B(e)?a[c]=typeof l=="bigint"?l:BigInt(Number(l)):e==="bool"?a[c]=l?1:0:a[c]=Number(l);for(let m=u-1;m>=0&&(s[m]++,!(s[m]<t[m]));m--)s[m]=0}let i=x.fromData(a,t,e);return new v(i)}function pi(...r){let t=[],e="xy";for(let s of r)s instanceof v?t.push(s):typeof s=="object"&&"indexing"in s&&(e=s.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(s=>s.size);e==="xy"&&t.length>=2&&(t=[t[1],t[0],...t.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,u=[];for(let s=0;s<t.length;s++){let i=t[s],c=i.size,l=new Array(a).fill(1);l[s]=c;let m=i.reshape(...l),d=Nt(m.storage,o),p=v._fromStorage(d.copy());u.push(p)}return e==="xy"&&u.length>=2&&([u[0],u[1]]=[u[1],u[0]]),u}function di(r,t,e=0,n=X){let o=t??r,a=Dr([r,o],n);for(let u=0;u<r;u++)for(let s=0;s<=u+e&&s<o;s++)s>=0&&a.set([u,s],1);return a}function gi(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],u=n.slice(0,-2).reduce((s,i)=>s*i,1);for(let s=0;s<u;s++)for(let i=0;i<o;i++)for(let c=0;c<a;c++)if(c>i+t){let l=[],m=s;for(let d=n.length-3;d>=0;d--)l.unshift(m%n[d]),m=Math.floor(m/n[d]);l.push(i,c),e.set(l,0)}return e}function Ai(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],u=n.slice(0,-2).reduce((s,i)=>s*i,1);for(let s=0;s<u;s++)for(let i=0;i<o;i++)for(let c=0;c<a;c++)if(c<i+t){let l=[],m=s;for(let d=n.length-3;d>=0;d--)l.unshift(m%n[d]),m=Math.floor(m/n[d]);l.push(i,c),e.set(l,0)}return e}function bi(r,t,e=!1){if(r.ndim!==1)throw new Error("Input must be 1-D");let n=r.size,o=t??n;if(o<0)throw new Error("N must be non-negative");let a=Dr([n,o],r.dtype);for(let u=0;u<n;u++){let s=r.get([u]);for(let i=0;i<o;i++){let c=e?i:o-1-i;a.set([u,i],Math.pow(s,c))}}return a}function hi(r,t=X,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let u=Ny(t),s=o.byteLength-a,i=Math.floor(s/u),c=e<0?i:Math.min(e,i);if(c<=0)return or([],t);let l=P(t);if(!l)throw new Error(`Unsupported dtype: ${t}`);let m=new l(o,a,c),d=x.fromData(m,[c],t);return new v(d)}function Si(r,t=X,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return or(n,t)}function Di(r,t=X,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return or(n,t)}function xi(r,t=X,e=-1,n=""){let o;n===""?o=r.trim().split(/\s+/):o=r.split(n);let a=[],u=0;for(let s of o){if(e>=0&&u>=e)break;let i=s.trim();i!==""&&(B(t)?a.push(BigInt(i)):a.push(parseFloat(i)),u++)}return or(a,t)}function Ny(r){switch(r){case"int8":case"uint8":case"bool":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;case"int64":case"uint64":case"float64":return 8;default:return 8}}function Ni(r){return r.sqrt()}function Ye(r,t){return r.power(t)}function wi(r){return r.exp()}function Ii(r){return r.exp2()}function zi(r){return r.expm1()}function _i(r){return r.log()}function Fi(r){return r.log2()}function Mi(r){return r.log10()}function Bi(r){return r.log1p()}function vi(r,t){return r.logaddexp(t)}function Ei(r,t){return r.logaddexp2(t)}function He(r){return r.absolute()}function Ti(r){return r.negative()}function Oi(r){return r.sign()}function Ci(r,t){return r.mod(t)}function Je(r,t){return r.divide(t)}function Ui(r,t){return r.floor_divide(t)}function $i(r){return r.positive()}function Ri(r){return r.reciprocal()}function ki(r,t){return r.dot(t)}function qi(r){return r.trace()}function Vi(r,t=0,e=0,n=1){let o=$o(r.storage,t,e,n);return v._fromStorage(o)}function ji(r,t){let e=ko(r.storage,t.storage);return v._fromStorage(e)}function Pi(r,t){return r.transpose(t)}function Li(r,t){return r.inner(t)}function Zi(r,t){return r.outer(t)}function Gi(r,t,e=2){return r.tensordot(t,e)}function Wi(r){return r.sin()}function Yi(r){return r.cos()}function Hi(r){return r.tan()}function Xe(r){return r.arcsin()}function Qe(r){return r.arccos()}function Ke(r){return r.arctan()}function rn(r,t){return r.arctan2(t)}function Ji(r,t){return r.hypot(t)}function Xi(r){return r.degrees()}function Qi(r){return r.radians()}function Ki(r){return r.radians()}function ru(r){return r.degrees()}function tu(r){return r.sinh()}function eu(r){return r.cosh()}function nu(r){return r.tanh()}function tn(r){return r.arcsinh()}function en(r){return r.arccosh()}function nn(r){return r.arctanh()}function ou(r,t,e){return r.swapaxes(t,e)}function au(r,t,e){return r.moveaxis(t,e)}function vr(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");let e=r.map(o=>o.storage),n=Mr(e,t);return v._fromStorage(n)}function su(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r.map(o=>o.storage),n=fo(e,t);return v._fromStorage(n)}function on(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=mo(t);return v._fromStorage(e)}function iu(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=fe(t);return v._fromStorage(e)}function uu(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=yo(t);return v._fromStorage(e)}function cu(r,t,e=0){return po(r.storage,t,e).map(o=>v._fromStorage(o,r.base??r))}function lu(r,t,e=0){return rt(r.storage,t,e).map(o=>v._fromStorage(o,r.base??r))}function fu(r,t){return Ao(r.storage,t).map(n=>v._fromStorage(n,r.base??r))}function mu(r,t){return bo(r.storage,t).map(n=>v._fromStorage(n,r.base??r))}function yu(r,t){let e=ho(r.storage,t);return v._fromStorage(e)}function pu(r,t,e){return r.repeat(t,e)}function du(r){return r.ravel()}function gu(r,t){return r.reshape(...t)}function Au(r,t){return r.squeeze(t)}function bu(r,t){return r.expand_dims(t)}function _t(r,t){let e=Do(r.storage,t);return v._fromStorage(e)}function hu(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return _t(r,1)}function Su(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return _t(r,0)}function Du(r,t=1,e=[0,1]){let n=xo(r.storage,t,e);return v._fromStorage(n)}function xu(r,t,e){let n=No(r.storage,t,e);return v._fromStorage(n)}function Nu(r,t,e=0){let n=wo(r.storage,t,e);return v._fromStorage(n,r.base??r)}function wu(...r){let t=r.map(o=>o.storage),n=Fo(t).map((o,a)=>o===t[a]?r[a]:v._fromStorage(o));return n.length===1?n[0]:n}function Iu(...r){let t=r.map(o=>o.storage),n=Mo(t).map((o,a)=>o===t[a]?r[a]:v._fromStorage(o));return n.length===1?n[0]:n}function zu(...r){let t=r.map(o=>o.storage),n=Bo(t).map((o,a)=>o===t[a]?r[a]:v._fromStorage(o));return n.length===1?n[0]:n}function _u(r,t){return Io(r.storage,t).map(n=>v._fromStorage(n,r.base??r))}function Fu(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=zo(t);return v._fromStorage(e)}function Mu(r){return on(r)}function Bu(r,t){let e=_o(r.storage,t);return v._fromStorage(e)}function vu(r,t,e){let n=t instanceof v?t:or(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return vr([o,a])}return vr([r,n],e)}function Eu(r,t,e){let n=r.dtype;if(e===void 0){let p=r.flatten(),y=(Array.isArray(t)?t:[t]).map(S=>S<0?p.size+S:S),g=[];for(let S=0;S<p.size;S++)y.includes(S)||g.push(S);let h=P(n),b=new h(g.length);for(let S=0;S<g.length;S++){let D=p.get([g[S]]);B(n)?b[S]=typeof D=="bigint"?D:BigInt(D):b[S]=D}let A=x.fromData(b,[g.length],n);return new v(A)}let o=r.shape,a=o.length,u=e<0?a+e:e;if(u<0||u>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let s=o[u],i=Array.isArray(t)?t:[t],c=new Set(i.map(p=>p<0?s+p:p)),l=[],m=0;for(let p=0;p<=s;p++)(c.has(p)||p===s)&&(p>m&&l.push([m,p]),m=p+1);if(l.length===0){let p=[...o];return p[u]=0,Dr(p,n)}let d=[];for(let[p,f]of l){let y=o.map(()=>":");y[u]=`${p}:${f}`,d.push(r.slice(...y))}return vr(d,u)}function Tu(r,t,e,n){let o=e instanceof v?e:or(e,r.dtype);if(n===void 0){let m=r.flatten(),d=o.flatten(),p=t<0?m.size+t:t;if(p<0||p>m.size)throw new Error(`index ${t} is out of bounds for array of size ${m.size}`);let f=p>0?m.slice(`0:${p}`):null,y=p<m.size?m.slice(`${p}:`):null,g=[];return f&&g.push(f),g.push(d),y&&g.push(y),vr(g)}let a=r.shape,u=a.length,s=n<0?u+n:n;if(s<0||s>=u)throw new Error(`axis ${n} is out of bounds for array of dimension ${u}`);let i=a[s],c=t<0?i+t:t;if(c<0||c>i)throw new Error(`index ${t} is out of bounds for axis ${n} with size ${i}`);let l=[];if(c>0){let m=a.map(()=>":");m[s]=`0:${c}`,l.push(r.slice(...m))}if(l.push(o),c<i){let m=a.map(()=>":");m[s]=`${c}:`,l.push(r.slice(...m))}return vr(l,s)}function Ou(r,t,e="constant",n=0){let o=r.shape,a=o.length,u=r.dtype,s;if(typeof t=="number"?s=o.map(()=>[t,t]):Array.isArray(t)&&typeof t[0]=="number"?s=o.map(()=>t):s=t,s.length!==a)throw new Error(`pad_width must have ${a} elements`);let i=o.map((y,g)=>y+s[g][0]+s[g][1]),c=i.reduce((y,g)=>y*g,1),l=P(u),m=new l(c),d=B(u);e==="constant"&&(d?m.fill(BigInt(n)):m.fill(n));let p=new Array(a).fill(0);for(let y=0;y<c;y++){let g=!0,h=[];for(let A=0;A<a;A++){let[S]=s[A],D=p[A]-S;if(D<0||D>=o[A]){g=!1;break}h.push(D)}let b;if(g)b=r.get(h);else if(e==="constant"){for(let A=a-1;A>=0&&(p[A]++,!(p[A]<i[A]));A--)p[A]=0;continue}else{let A=[];for(let S=0;S<a;S++){let[D]=s[S],w=p[S]-D,N=o[S];w<0?e==="edge"?w=0:e==="reflect"?(w=-w,w>=N&&(w=N-1)):e==="symmetric"?(w=-w-1,w>=N&&(w=N-1),w<0&&(w=0)):e==="wrap"&&(w=(w%N+N)%N):w>=N&&(e==="edge"?w=N-1:e==="reflect"?(w=2*N-w-2,w<0&&(w=0)):e==="symmetric"?(w=2*N-w-1,w<0&&(w=0)):e==="wrap"&&(w=w%N)),A.push(Math.max(0,Math.min(N-1,w)))}b=r.get(A)}d?m[y]=typeof b=="bigint"?b:BigInt(Number(b)):m[y]=Number(b);for(let A=a-1;A>=0&&(p[A]++,!(p[A]<i[A]));A--)p[A]=0}let f=x.fromData(m,i,u);return new v(f)}function Cu(r,t){let e=Nt(r.storage,t);return v._fromStorage(e,r.base??r)}function Uu(...r){let t=r.map(n=>n.storage);return za(t).map((n,o)=>v._fromStorage(n,r[o].base??r[o]))}function $u(...r){return Gt(...r)}function Ru(r,t,e){return r.take(t,e)}function ku(r,t,e){r.put(t,e)}function qu(r,t,e=0){return r.iindex(t,e)}function Vu(r,t,e){return r.bindex(t,e)}function ju(r,t,e){if(e!==void 0)throw new Error("copyto with where parameter is not yet implemented");let n=r.storage,o=r.shape,a=r.size,u=r.dtype;if(typeof t=="number"||typeof t=="bigint"){r.fill(t);return}let s=t.storage,i=t.shape,c=yr([i,o]);if(!c)throw new Error(`could not broadcast input array from shape (${i.join(",")}) into shape (${o.join(",")})`);if(c.length!==o.length||!c.every((m,d)=>m===o[d]))throw new Error(`could not broadcast input array from shape (${i.join(",")}) into shape (${o.join(",")})`);let l=Nt(s,o);if(B(u))for(let m=0;m<a;m++){let d=l.iget(m),p=typeof d=="bigint"?d:BigInt(Math.round(Number(d)));n.iset(m,p)}else if(u==="bool")for(let m=0;m<a;m++){let d=l.iget(m);n.iset(m,d?1:0)}else for(let m=0;m<a;m++){let d=l.iget(m);n.iset(m,Number(d))}}function Pu(r,t){let e=t.map(o=>o.storage),n=Ma(r.storage,e);return v._fromStorage(n)}function Lu(r,t,e=!1){return Ba(r.storage,t.storage,e)}function Zu(r,t){return io(r.storage,t.storage)}function an(r,t){return v._fromStorage(ee(r.storage,t))}function sn(r,t){return v._fromStorage(ne(r.storage,t))}function un(r,t,e=!1){return r.max(t,e)}function cn(r,t,e=!1){return r.min(t,e)}function Gu(r,t,e=!1){let n=oe(r.storage,t,e);return typeof n=="number"||n instanceof O?n:v._fromStorage(n)}function Wu(r,t,e=!1){let n=ae(r.storage,t,e);return typeof n=="number"?n:v._fromStorage(n)}function Yu(r,t,e,n=!1){let o=se(r.storage,t,e,n);return typeof o=="number"?o:v._fromStorage(o)}function Hu(r,t,e,n=!1){let o=Rr(r.storage,t,e,n);return typeof o=="number"?o:v._fromStorage(o)}function Ju(r,t,e,n=!1){let o=e?e.storage:void 0,a=Wr(r.storage,t,o,n);return typeof a=="number"||a instanceof O?a:v._fromStorage(a)}function Xu(r,t,e=!1){let n=At(r.storage,t,e);return typeof n=="number"||n instanceof O?n:v._fromStorage(n)}function Qu(r,t,e=!1){let n=bt(r.storage,t,e);return typeof n=="number"||n instanceof O?n:v._fromStorage(n)}function Ku(r,t,e=!1){let n=ht(r.storage,t,e);return typeof n=="number"||n instanceof O?n:v._fromStorage(n)}function rc(r,t,e=0,n=!1){let o=$r(r.storage,t,e,n);return typeof o=="number"?o:v._fromStorage(o)}function tc(r,t,e=0,n=!1){let o=ie(r.storage,t,e,n);return typeof o=="number"?o:v._fromStorage(o)}function ec(r,t,e=!1){let n=Yr(r.storage,t,e);return typeof n=="number"||n instanceof O?n:v._fromStorage(n)}function nc(r,t,e=!1){let n=Hr(r.storage,t,e);return typeof n=="number"||n instanceof O?n:v._fromStorage(n)}function oc(r,t){let e=Jr(r.storage,t);return typeof e=="number"?e:v._fromStorage(e)}function ac(r,t){let e=Xr(r.storage,t);return typeof e=="number"?e:v._fromStorage(e)}function sc(r,t){return v._fromStorage(ue(r.storage,t))}function ic(r,t){return v._fromStorage(ce(r.storage,t))}function uc(r,t,e=!1){let n=St(r.storage,t,e);return typeof n=="number"?n:v._fromStorage(n)}function cc(r){return r.cbrt()}function lc(r){return r.fabs()}function fc(r,t){return r.divmod(t)}function mc(r){return r.square()}function yc(r,t){return r.remainder(t)}function pc(r,t){return r.heaviside(t)}function dc(r,t){let e=typeof t=="number"?t:t.storage;return v._fromStorage(Gn(r.storage,e))}function gc(r,t){let e=typeof t=="number"?t:t.storage;return v._fromStorage(Wn(r.storage,e))}function Ac(r){let[t,e]=Yn(r.storage);return[v._fromStorage(t),v._fromStorage(e)]}function bc(r,t){let e=typeof t=="number"?t:t.storage;return v._fromStorage(Hn(r.storage,e))}function hc(r,t){let e=typeof t=="number"?t:t.storage;return v._fromStorage(Jn(r.storage,e))}function Sc(r,t){let e=typeof t=="number"?t:t.storage;return v._fromStorage(Xn(r.storage,e))}function Dc(r){let[t,e]=Qn(r.storage);return[v._fromStorage(t),v._fromStorage(e)]}function xc(r,t){return r.bitwise_and(t)}function Nc(r,t){return r.bitwise_or(t)}function wc(r,t){return r.bitwise_xor(t)}function Ic(r){return r.bitwise_not()}function zc(r){return r.invert()}function _c(r,t){return r.left_shift(t)}function Fc(r,t){return r.right_shift(t)}function Mc(r,t=-1,e="big"){let n=Ka(r.storage,t,e);return v._fromStorage(n)}function Bc(r,t=-1,e=-1,n="big"){let o=rs(r.storage,t,e,n);return v._fromStorage(o)}function vc(r,t){return r.logical_and(t)}function Ec(r,t){return r.logical_or(t)}function Tc(r){return r.logical_not()}function Oc(r,t){return r.logical_xor(t)}function Cc(r){return r.isfinite()}function Uc(r){return r.isinf()}function $c(r){return r.isnan()}function Rc(r){return r.isnat()}function kc(r,t){return r.copysign(t)}function qc(r){return r.signbit()}function Vc(r,t){return r.nextafter(t)}function jc(r){return r.spacing()}function Pc(r){return v._fromStorage(ps(r.storage))}function Lc(r){return ds(r.storage)}function Zc(r){return v._fromStorage(gs(r.storage))}function Gc(r){return As(r.storage)}function Wc(r){return v._fromStorage(zs(r.storage))}function Yc(r){return v._fromStorage(_s(r.storage))}function ln(r){return v._fromStorage(Fs(r.storage))}var Hc=ln;function Jc(r,t=!1){return v._fromStorage(Ms(r.storage,t))}function Xc(r){return v._fromStorage(bs(r.storage))}function Qc(r){return v._fromStorage(hs(r.storage))}function Kc(r){return Ss(r.storage)}function rl(r,t=100){return v._fromStorage(Ds(r.storage,t))}function tl(r){return xs(r)}function el(r){return Ns(r)}function nl(r,t){return ws(r,t)}function ol(r,t){return Is(r,t)}function al(r,...t){let e=t.map(o=>o.storage),n=Ro(r,...e);return typeof n=="number"||typeof n=="bigint"||n instanceof O?n:v._fromStorage(n)}var sl={cross:(r,t,e=-1,n=-1,o=-1,a)=>{let u=qo(r.storage,t.storage,e,n,o,a);return typeof u=="number"?u:v._fromStorage(u)},norm:(r,t=null,e=null,n=!1)=>{let o=Vo(r.storage,t,e,n);return typeof o=="number"?o:v._fromStorage(o)},vector_norm:(r,t=2,e,n=!1)=>{let o=Vr(r.storage,t,e,n);return typeof o=="number"?o:v._fromStorage(o)},matrix_norm:(r,t="fro",e=!1)=>{let n=Br(r.storage,t,e);return typeof n=="number"?n:v._fromStorage(n)},qr:(r,t="reduced")=>{let e=de(r.storage,t);return e instanceof x?v._fromStorage(e):"q"in e&&"r"in e?{q:v._fromStorage(e.q),r:v._fromStorage(e.r)}:{h:v._fromStorage(e.h),tau:v._fromStorage(e.tau)}},cholesky:(r,t=!1)=>v._fromStorage(jo(r.storage,t)),svd:(r,t=!0,e=!0)=>{let n=Po(r.storage,t,e);return"u"in n?{u:v._fromStorage(n.u),s:v._fromStorage(n.s),vt:v._fromStorage(n.vt)}:v._fromStorage(n)},det:r=>Lo(r.storage),inv:r=>v._fromStorage(xt(r.storage)),solve:(r,t)=>v._fromStorage(Zo(r.storage,t.storage)),lstsq:(r,t,e=null)=>{let n=Go(r.storage,t.storage,e);return{x:v._fromStorage(n.x),residuals:v._fromStorage(n.residuals),rank:n.rank,s:v._fromStorage(n.s)}},cond:(r,t=2)=>Wo(r.storage,t),matrix_rank:(r,t)=>Yo(r.storage,t),matrix_power:(r,t)=>v._fromStorage(Ho(r.storage,t)),pinv:(r,t=1e-15)=>v._fromStorage(Jo(r.storage,t)),eig:r=>{let t=be(r.storage);return{w:v._fromStorage(t.w),v:v._fromStorage(t.v)}},eigh:(r,t="L")=>{let e=he(r.storage,t);return{w:v._fromStorage(e.w),v:v._fromStorage(e.v)}},eigvals:r=>v._fromStorage(Xo(r.storage)),eigvalsh:(r,t="L")=>v._fromStorage(Qo(r.storage,t))};function il(r,t,e){return v._fromStorage(va(r.storage,t.storage,e))}function ul(r,t,e,n){Ea(r.storage,t.storage,e.storage,n)}function cl(r,t,e){let n=e instanceof v?e.storage:e;Ta(r.storage,t.storage,n)}function ll(r,t,e){return v._fromStorage(Se(r.storage,t.storage,e))}function fl(r,t,e=0){let n=r.map(a=>a.storage),o=t.map(a=>a.storage);return v._fromStorage(Oa(n,o,e))}function ml(r,t,e){Ca(r.storage,t.storage,e.storage)}function yl(r,t,e=!1){let n=typeof t=="number"?t:t.storage;La(r.storage,n,e)}function pl(r,t=2){return De(r,t).map(n=>v._fromStorage(n))}function dl(r){return Ua(r.storage).map(e=>v._fromStorage(e))}function gl(r,t=0,e){return xe(r,t,e).map(o=>v._fromStorage(o))}function Al(r,t=0){return $a(r.storage,t).map(n=>v._fromStorage(n))}function bl(r,t=0,e){return Ne(r,t,e).map(o=>v._fromStorage(o))}function hl(r,t=0){return Ra(r.storage,t).map(n=>v._fromStorage(n))}function Sl(r,t,e=0){return ka(r,(a,u)=>t(a,u).storage,e).map(a=>v._fromStorage(a))}function Dl(r,t="int32"){return v._fromStorage(qa(r,t))}function xl(...r){return Va(...r.map(e=>e.storage)).map(e=>v._fromStorage(e))}function Nl(r,t,e="raise"){let n=r.map(o=>o.storage);return v._fromStorage(ja(n,t,e))}function wl(r,t,e="C"){let n=r instanceof v?r.storage:r;return Pa(n,t,e).map(a=>v._fromStorage(a))}function Il(r,t=-1){return v._fromStorage(Ie(r.storage,t))}function zl(r,t=-1){return v._fromStorage(ze(r.storage,t))}function _l(r){let t=r.map(e=>e.storage);return v._fromStorage(Bs(t))}function Fl(r,t,e=-1){return v._fromStorage(_e(r.storage,t,e))}function Ml(r,t,e=-1){return v._fromStorage(Fe(r.storage,t,e))}function Bl(r){return v._fromStorage(vs(r.storage))}function vl(r){return zt(r.storage).map(e=>v._fromStorage(e))}function El(r){return v._fromStorage(Me(r.storage))}function Tl(r){return v._fromStorage(Es(r.storage))}function Ol(r,t,e){let n=Ts(r.storage,t?.storage,e?.storage);return Array.isArray(n)?n.map(o=>v._fromStorage(o)):v._fromStorage(n)}function Cl(r,t,e="left"){return v._fromStorage(Be(r.storage,t.storage,e))}function Ul(r,t){return v._fromStorage(Os(r.storage,t.storage))}function $l(r,t){let e=ve(r.storage,t);return typeof e=="number"?e:v._fromStorage(e)}function Ft(r,t=0){return v._fromStorage(Ee(r.storage,t))}function Rl(r){return v._fromStorage(Te(r.storage))}function kl(r){return v._fromStorage(Oe(r.storage))}function ql(r){return v._fromStorage(Ce(r.storage))}function Vl(r){return v._fromStorage(Ue(r.storage))}function jl(r){return v._fromStorage($e(r.storage))}function Pl(r,t=!1,e=!1,n=!1){let o=wr(r.storage,t,e,n);if(o instanceof x)return v._fromStorage(o);let a={values:v._fromStorage(o.values)};return o.indices&&(a.indices=v._fromStorage(o.indices)),o.inverse&&(a.inverse=v._fromStorage(o.inverse)),o.counts&&(a.counts=v._fromStorage(o.counts)),a}function Ll(r,t){return v._fromStorage(Us(r.storage,t.storage))}function Zl(r,t){return v._fromStorage($s(r.storage,t.storage))}function Gl(r,t){return v._fromStorage(ke(r.storage,t.storage))}function Wl(r,t){return v._fromStorage(Rs(r.storage,t.storage))}function Yl(r,t){return v._fromStorage(ks(r.storage,t.storage))}function Hl(r,t){return v._fromStorage(qs(r.storage,t.storage))}function Jl(r,t=1,e=-1){return v._fromStorage(qe(r.storage,t,e))}function Xl(r,t=null,e=null){return v._fromStorage(Vs(r.storage,t,e))}function Ql(r,t=1,e=null){let n=js(r.storage,t,e);return Array.isArray(n)?n.map(o=>v._fromStorage(o)):v._fromStorage(n)}function Kl(r,t,e=-1,n=-1,o=-1){return v._fromStorage(Ps(r.storage,t.storage,e,n,o))}function rf(r,t,e=0){return v._fromStorage(Ls(r.storage,t?.storage,e))}function tf(r,t,e=!1){return v._fromStorage(Zs(r.storage,t.storage,e))}function ef(r,t=10,e,n=!1,o){let a=Gs(r.storage,typeof t=="number"?t:t.storage,e,n,o?.storage);return[v._fromStorage(a.hist),v._fromStorage(a.bin_edges)]}function nf(r,t,e=10,n,o=!1,a){let u;typeof e=="number"?u=e:Array.isArray(e)&&e.length===2?typeof e[0]=="number"?u=e:u=[e[0].storage,e[1].storage]:u=10;let s=Ws(r.storage,t.storage,u,n,o,a?.storage);return[v._fromStorage(s.hist),v._fromStorage(s.x_edges),v._fromStorage(s.y_edges)]}function of(r,t=10,e,n=!1,o){let a=Ys(r.storage,t,e,n,o?.storage);return[v._fromStorage(a.hist),a.edges.map(u=>v._fromStorage(u))]}function af(r,t,e="full"){return v._fromStorage(Ve(r.storage,t.storage,e))}function sf(r,t,e="full"){return v._fromStorage(Hs(r.storage,t.storage,e))}function uf(r,t,e=!0,n=!1,o){return v._fromStorage(je(r.storage,t?.storage,e,n,o))}function cf(r,t,e=!0){return v._fromStorage(Js(r.storage,t?.storage,e))}var it=new Uint8Array([147,78,85,77,80,89]),Mt=["float64","float32","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];function fn(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}var wy={f8:"float64",f4:"float32",c16:"complex128",c8:"complex64",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},ut={float64:"<f8",float32:"<f4",complex128:"<c16",complex64:"<c8",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},lf={S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};function ff(r){if(r.startsWith("[")||r.startsWith("("))throw new xr(`Structured/compound dtypes are not supported: ${r}`);let t="",e=r;(r[0]==="<"||r[0]===">"||r[0]==="="||r[0]==="|")&&(t=r[0],e=r.slice(1));let n=e[0];if(n&&n in lf)throw new xr(`Unsupported dtype: ${lf[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=wy[e];if(!o)throw new xr(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Mt.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=fn(),u=t==="<"||t==="|"||t==="="&&a,s=t===">"||t==="="&&!a,i=parseInt(e.slice(1),10),c=i>1&&(s&&a||u&&!a);return{dtype:o,needsByteSwap:c,itemsize:i}}var xr=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},sr=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}};function ct(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Bt(t);return vt(t,e)}function Bt(r){if(r.length<10)throw new sr("File too small to be a valid NPY file");for(let c=0;c<it.length;c++)if(r[c]!==it[c])throw new sr("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new sr(`Unsupported NPY version: ${t}.${e}`);let n,o;t===1?(n=r[8]|r[9]<<8,o=10):(n=r[8]|r[9]<<8|r[10]<<16|r[11]<<24,o=12);let a=o+n;if(r.length<a)throw new sr("File truncated: header extends beyond file");let u=r.slice(o,a),s=new TextDecoder("utf-8").decode(u).trim(),i=Iy(s);return{version:{major:t,minor:e},header:i,dataOffset:a}}function vt(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:u}=ff(e.descr),s=e.shape.reduce((y,g)=>y*g,1),i=s*u,c=r.length-n;if(c<i)throw new sr(`File truncated: expected ${i} bytes of data, got ${c}`);let l=new ArrayBuffer(i);new Uint8Array(l).set(r.subarray(n,n+i));let d=zy(l,o,s,a,u),p=e.shape,f;if(e.fortran_order&&p.length>1){let y=[...p].reverse(),g=x.fromData(d,y,o);f=_y(g,y),p=e.shape}else f=x.fromData(d,[...p],o);return new v(f)}function Iy(r){let t=r.match(/'descr'\s*:\s*'([^']+)'/),e=r.match(/'fortran_order'\s*:\s*(True|False)/),n=r.match(/'shape'\s*:\s*\(([^)]*)\)/);if(!t||!e||!n)throw new sr(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",u=n[1].trim(),s;return u===""?s=[]:s=u.split(",").map(i=>i.trim()).filter(i=>i!=="").map(i=>{let c=parseInt(i,10);if(isNaN(c))throw new sr(`Invalid shape value: ${i}`);return c}),{descr:o,fortran_order:a,shape:s}}function zy(r,t,e,n,o){let a=P(t);if(!a)throw new sr(`Cannot create array for dtype: ${t}`);let u=M(t),s=u?e*2:e;if(!n)return new a(r,0,s);let i=new Uint8Array(r),c=new Uint8Array(r.byteLength);if(u){let l=o/2;for(let m=0;m<e*2;m++){let d=m*l;for(let p=0;p<l;p++)c[d+p]=i[d+l-1-p]}}else for(let l=0;l<e;l++){let m=l*o;for(let d=0;d<o;d++)c[m+d]=i[m+o-1-d]}return new a(c.buffer,0,s)}function _y(r,t){let e=t.length,n=r.size,o=r.dtype,a=P(o);if(!a)throw new sr(`Cannot create array for dtype: ${o}`);let u=new a(n),s=[...t].reverse(),i=mf(t),c=mf(s),l=new Array(e).fill(0);for(let m=0;m<n;m++){let d=m;for(let f=0;f<e;f++){let y=i[f];l[f]=Math.floor(d/y),d=d%y}let p=0;for(let f=0;f<e;f++)p+=l[e-1-f]*c[f];B(o),u[p]=r.iget(m)}return x.fromData(u,s,o)}function mf(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}function Pr(r){let t=r.shape,e=r.dtype,n=ut[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,u=12,i=(64-(u+a.length+1)%64)%64;a=a+" ".repeat(i)+`
2
+ `;let c=new TextEncoder().encode(a),l=c.length,m=r.size,d=yt(e),p=m*d,f=u+l+p,y=new Uint8Array(f);y.set(it,0),y[6]=3,y[7]=0,y[8]=l&255,y[9]=l>>8&255,y[10]=l>>16&255,y[11]=l>>24&255,y.set(c,u);let g=u+l;return Fy(r,y.subarray(g),d),y}function Fy(r,t,e){let n=r.dtype,o=r.size,a=fn(),u=B(n),s=M(n),i=r._storage;if(i.isCContiguous&&i.offset===0&&a){let l=i.data,m=new Uint8Array(l.buffer,l.byteOffset,o*e);t.set(m)}else{let l=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let m=0;m<o;m++){let d=i.iget(m),p=m*e;u?My(l,p,d,n==="uint64"):s?By(l,p,d,n):vy(l,p,d,n)}}}function My(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function By(r,t,e,n){n==="complex128"?(r.setFloat64(t,e.re,!0),r.setFloat64(t+8,e.im,!0)):(r.setFloat32(t,e.re,!0),r.setFloat32(t+4,e.im,!0))}function vy(r,t,e,n){switch(n){case"float64":r.setFloat64(t,e,!0);break;case"float32":r.setFloat32(t,e,!0);break;case"int32":r.setInt32(t,e,!0);break;case"int16":r.setInt16(t,e,!0);break;case"int8":r.setInt8(t,e);break;case"uint32":r.setUint32(t,e,!0);break;case"uint16":r.setUint16(t,e,!0);break;case"uint8":case"bool":r.setUint8(t,e);break;default:throw new Error(`Unsupported dtype for serialization: ${n}`)}}var Ey=(()=>{let r=new Uint32Array(256);for(let t=0;t<256;t++){let e=t;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;r[t]=e}return r})();function mn(r){let t=4294967295;for(let e=0;e<r.length;e++)t=Ey[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}async function yf(r){let t=df(r),e=new Map;for(let n of t){let o=await Ty(n);e.set(n.name,o)}return e}function pf(r){let t=df(r),e=new Map;for(let n of t){if(n.compressionMethod!==0)throw new Error(`Cannot read compressed entry synchronously: ${n.name}. Use readZip() (async) for DEFLATE-compressed files.`);e.set(n.name,n.compressedData)}return e}function df(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=[],o=-1;for(let c=t.length-22;c>=0;c--)if(e.getUint32(c,!0)===101010256){o=c;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),u=e.getUint16(o+10,!0),s=[],i=a;for(let c=0;c<u&&e.getUint32(i,!0)===33639248;c++){let m=e.getUint16(i+10,!0),d=e.getUint32(i+16,!0),p=e.getUint32(i+20,!0),f=e.getUint32(i+24,!0),y=e.getUint16(i+28,!0),g=e.getUint16(i+30,!0),h=e.getUint16(i+32,!0),b=e.getUint32(i+42,!0),A=t.slice(i+46,i+46+y),S=new TextDecoder("utf-8").decode(A);s.push({name:S,compressionMethod:m,crc32:d,compressedSize:p,uncompressedSize:f,localHeaderOffset:b}),i=i+46+y+g+h}for(let c of s){let l=c.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let d=e.getUint16(l+26,!0),p=e.getUint16(l+28,!0),f=l+30+d+p,y=t.slice(f,f+c.compressedSize);n.push({name:c.name,compressedData:y,compressionMethod:c.compressionMethod,crc32:c.crc32,compressedSize:c.compressedSize,uncompressedSize:c.uncompressedSize})}return n}async function Ty(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Oy(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Oy(r){if(typeof DecompressionStream>"u")throw new Error("DecompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new DecompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let u=a.reduce((c,l)=>c+l.length,0),s=new Uint8Array(u),i=0;for(let c of a)s.set(c,i),i+=c.length;return s}async function Et(r,t={}){let e=t.force??!1,n=await yf(r);return gf(n,e)}function Tt(r,t={}){let e=t.force??!1,n=pf(r);return gf(n,e)}function gf(r,t){let e=new Map,n=[],o=new Map;for(let[a,u]of r){if(!a.endsWith(".npy"))continue;let s=a.slice(0,-4);try{let i=ct(u);e.set(s,i)}catch(i){if(i instanceof xr&&t)n.push(s),o.set(s,i.message);else throw i}}return{arrays:e,skipped:n,errors:o}}async function dn(r,t={}){let e=await Et(r,t);return Object.fromEntries(e.arrays)}function gn(r,t={}){let e=Tt(r,t);return Object.fromEntries(e.arrays)}async function Af(r,t={}){let e=t.compress??!1,n=[];for(let[d,p]of r){let f=mn(p),y,g;e?(y=await Uy(p),y.length<p.length?g=8:(y=p,g=0)):(y=p,g=0),n.push({name:d,data:p,compressedData:y,crc:f,compressionMethod:g,offset:0})}let o=0;for(let d of n){let p=new TextEncoder().encode(d.name);o+=30+p.length+d.compressedData.length}let a=0;for(let d of n){let p=new TextEncoder().encode(d.name);a+=46+p.length}let s=o+a+22,i=new Uint8Array(s),c=new DataView(i.buffer),l=0;for(let d of n)d.offset=l,l=hf(i,c,l,d);let m=l;for(let d of n)l=Sf(i,c,l,d);return Df(c,l,n.length,a,m),i}function bf(r){let t=[];for(let[l,m]of r){let d=mn(m);t.push({name:l,data:m,compressedData:m,crc:d,compressionMethod:0,offset:0})}let e=0;for(let l of t){let m=new TextEncoder().encode(l.name);e+=30+m.length+l.compressedData.length}let n=0;for(let l of t){let m=new TextEncoder().encode(l.name);n+=46+m.length}let a=e+n+22,u=new Uint8Array(a),s=new DataView(u.buffer),i=0;for(let l of t)l.offset=i,i=hf(u,s,i,l);let c=i;for(let l of t)i=Sf(u,s,i,l);return Df(s,i,t.length,n,c),u}function hf(r,t,e,n){let o=new TextEncoder().encode(n.name);return t.setUint32(e,67324752,!0),e+=4,t.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,n.compressionMethod,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,33,!0),e+=2,t.setUint32(e,n.crc,!0),e+=4,t.setUint32(e,n.compressedData.length,!0),e+=4,t.setUint32(e,n.data.length,!0),e+=4,t.setUint16(e,o.length,!0),e+=2,t.setUint16(e,0,!0),e+=2,r.set(o,e),e+=o.length,r.set(n.compressedData,e),e+=n.compressedData.length,e}function Sf(r,t,e,n){let o=new TextEncoder().encode(n.name);return t.setUint32(e,33639248,!0),e+=4,t.setUint16(e,20,!0),e+=2,t.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,n.compressionMethod,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,33,!0),e+=2,t.setUint32(e,n.crc,!0),e+=4,t.setUint32(e,n.compressedData.length,!0),e+=4,t.setUint32(e,n.data.length,!0),e+=4,t.setUint16(e,o.length,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint32(e,0,!0),e+=4,t.setUint32(e,n.offset,!0),e+=4,r.set(o,e),e+=o.length,e}function Df(r,t,e,n,o){r.setUint32(t,101010256,!0),t+=4,r.setUint16(t,0,!0),t+=2,r.setUint16(t,0,!0),t+=2,r.setUint16(t,e,!0),t+=2,r.setUint16(t,e,!0),t+=2,r.setUint32(t,n,!0),t+=4,r.setUint32(t,o,!0),t+=4,r.setUint16(t,0,!0)}async function Uy(r){if(typeof CompressionStream>"u")throw new Error("CompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new CompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let u=a.reduce((c,l)=>c+l.length,0),s=new Uint8Array(u),i=0;for(let c of a)s.set(c,i),i+=c.length;return s}async function An(r,t={}){let e=xf(r);return Af(e,{compress:t.compress??!1})}function bn(r){let t=xf(r);return bf(t)}function xf(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=Pr(o);t.set(`arr_${n}.npy`,a)}return t}let e=r instanceof Map?r.entries():Object.entries(r);for(let[n,o]of e){if(typeof n!="string"||n.length===0)throw new Error("Array names must be non-empty strings");let a=Pr(o),u=n.endsWith(".npy")?n:`${n}.npy`;t.set(u,a)}return t}var gr=624,Ot=397,Vy=2567483615,hn=2147483648,Sn=2147483647,Ar={mt:new Uint32Array(gr),mti:gr+1};function If(r){let t=Ar.mt;t[0]=r>>>0;for(let e=1;e<gr;e++){let n=t[e-1]^t[e-1]>>>30;t[e]=Math.imul(1812433253,n)+e>>>0}Ar.mti=gr}function Nf(){let r=Ar.mt,t,e=[0,Vy];if(Ar.mti>=gr){let n;for(Ar.mti===gr+1&&If(5489),n=0;n<gr-Ot;n++)t=r[n]&hn|r[n+1]&Sn,r[n]=r[n+Ot]^t>>>1^e[t&1];for(;n<gr-1;n++)t=r[n]&hn|r[n+1]&Sn,r[n]=r[n+(Ot-gr)]^t>>>1^e[t&1];t=r[gr-1]&hn|r[0]&Sn,r[gr-1]=r[Ot-1]^t>>>1^e[t&1],Ar.mti=0}return t=r[Ar.mti++],t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^=t>>>18,t>>>0}function W(){let r=Nf()>>>5,t=Nf()>>>6;return(r*67108864+t)/9007199254740992}var jy=2468251765,Py=1492356589,Ly=1135663077,Zy=2337405405,Gy=3389127133,Wy=1232336661,In=16,Ct=4;function ir(r){return r>>>0}function Dn(r,t){return r=ir(ir(r)^t.val),t.val=ir(Math.imul(t.val,jy)),r=ir(Math.imul(r,t.val)),r=ir(r^r>>>In),r}function Yy(r,t){let e=ir(ir(Math.imul(Gy,ir(r)))-ir(Math.imul(Wy,ir(t))));return e=ir(e^e>>>In),e}function Hy(r){let t=[0,0,0,0],e=[r>>>0],n={val:Ly};for(let o=0;o<Ct;o++)o<e.length?t[o]=Dn(e[o],n):t[o]=Dn(0,n);for(let o=0;o<Ct;o++)for(let a=0;a<Ct;a++)if(o!==a){let u=Dn(t[o],n);t[a]=Yy(t[a],u)}return t}function Jy(r,t){let e=[],n=Zy;for(let o=0;o<t;o++){let a=r[o%Ct],u=ir(a^n);n=ir(Math.imul(n,Py)),u=ir(Math.imul(u,n)),u=ir(u^u>>>In),e.push(u)}return e}var Xy=BigInt("4865540595714422341"),Qy=BigInt("2549297995355413924"),Ky=Qy<<BigInt(64)|Xy,xn=BigInt("0xffffffffffffffff"),Nn=(BigInt(1)<<BigInt(128))-BigInt(1);function rp(r){let t=r>>BigInt(64),e=r&xn,n=(t^e)&xn,o=Number(r>>BigInt(122));return(n>>BigInt(o)|n<<BigInt(64-o))&xn}function wn(r,t){return r*Ky+t&Nn}function wf(r){let t=Hy(r),e=Jy(t,8),n=BigInt(e[0])|BigInt(e[1])<<BigInt(32),o=BigInt(e[2])|BigInt(e[3])<<BigInt(32),a=BigInt(e[4])|BigInt(e[5])<<BigInt(32),u=BigInt(e[6])|BigInt(e[7])<<BigInt(32),s=n<<BigInt(64)|o,i=(a<<BigInt(64)|u)<<BigInt(1);i=(i|BigInt(1))&Nn;let c=BigInt(0);return c=wn(c,i),c=c+s&Nn,c=wn(c,i),{state:c,inc:i}}function tp(r){return r.state=wn(r.state,r.inc),rp(r.state)}function ep(r){let e=tp(r)>>BigInt(11);return Number(e)/9007199254740992}var ft=class{constructor(t){if(t!==void 0)this._pcgState=wf(t);else{let e=Math.floor(Math.random()*4294967296);this._pcgState=wf(e)}}_randomFloat(){return ep(this._pcgState)}random(t){if(t===void 0)return this._randomFloat();let e=Array.isArray(t)?t:[t],n=e.reduce((u,s)=>u*s,1),o=x.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u++)a[u]=this._randomFloat();return o}integers(t,e,n){if(e===void 0&&(e=t,t=0),n===void 0)return Math.floor(this._randomFloat()*(e-t))+t;let o=Array.isArray(n)?n:[n],a=o.reduce((c,l)=>c*l,1),u=x.zeros(o,"int64"),s=u.data,i=e-t;for(let c=0;c<a;c++)s[c]=BigInt(Math.floor(this._randomFloat()*i)+t);return u}standard_normal(t){if(t===void 0)return Er(this._randomFloat.bind(this));let e=Array.isArray(t)?t:[t],n=e.reduce((u,s)=>u*s,1),o=x.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u+=2){let[s,i]=mt(this._randomFloat.bind(this));a[u]=s,u+1<n&&(a[u+1]=i)}return o}normal(t=0,e=1,n){if(n===void 0)return Er(this._randomFloat.bind(this))*e+t;let o=Array.isArray(n)?n:[n],a=o.reduce((i,c)=>i*c,1),u=x.zeros(o,"float64"),s=u.data;for(let i=0;i<a;i+=2){let[c,l]=mt(this._randomFloat.bind(this));s[i]=c*e+t,i+1<a&&(s[i+1]=l*e+t)}return u}uniform(t=0,e=1,n){if(n===void 0)return this._randomFloat()*(e-t)+t;let o=Array.isArray(n)?n:[n],a=o.reduce((c,l)=>c*l,1),u=x.zeros(o,"float64"),s=u.data,i=e-t;for(let c=0;c<a;c++)s[c]=this._randomFloat()*i+t;return u}choice(t,e,n=!0,o){return qf(t,e,n,o,this._randomFloat.bind(this))}permutation(t){return jf(t,this._randomFloat.bind(this))}shuffle(t){Lf(t,this._randomFloat.bind(this))}exponential(t=1,e){if(e===void 0)return-Math.log(1-this._randomFloat())*t;let n=Array.isArray(e)?e:[e],o=n.reduce((s,i)=>s*i,1),a=x.zeros(n,"float64"),u=a.data;for(let s=0;s<o;s++)u[s]=-Math.log(1-this._randomFloat())*t;return a}poisson(t=1,e){if(e===void 0)return Ut(t,this._randomFloat.bind(this));let n=Array.isArray(e)?e:[e],o=n.reduce((s,i)=>s*i,1),a=x.zeros(n,"int64"),u=a.data;for(let s=0;s<o;s++)u[s]=BigInt(Ut(t,this._randomFloat.bind(this)));return a}binomial(t,e,n){if(n===void 0)return $t(t,e,this._randomFloat.bind(this));let o=Array.isArray(n)?n:[n],a=o.reduce((i,c)=>i*c,1),u=x.zeros(o,"int64"),s=u.data;for(let i=0;i<a;i++)s[i]=BigInt($t(t,e,this._randomFloat.bind(this)));return u}};function zf(r){return new ft(r)}function _f(r){r==null&&(r=Math.floor(Date.now()^Math.random()*4294967296)),If(r>>>0)}function Ff(){return{mt:Array.from(Ar.mt),mti:Ar.mti}}function Mf(r){Ar.mt=new Uint32Array(r.mt),Ar.mti=r.mti}function Er(r){let t,e;do t=r(),e=r();while(t===0);return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e)}function mt(r){let t,e;do t=r(),e=r();while(t===0);let n=Math.sqrt(-2*Math.log(t)),o=2*Math.PI*e;return[n*Math.cos(o),n*Math.sin(o)]}function Ut(r,t){if(r<30){let e=Math.exp(-r),n=0,o=1;do n++,o*=t();while(o>e);return n-1}else{let e=Er(t);return Math.max(0,Math.round(r+Math.sqrt(r)*e))}}function $t(r,t,e){if(r*t<10&&r*(1-t)<10){let n=0;for(let o=0;o<r;o++)e()<t&&n++;return n}else{let n=r*t,o=Math.sqrt(r*t*(1-t)),a=Er(e);return Math.max(0,Math.min(r,Math.round(n+o*a)))}}function Bf(r){if(r===void 0)return W();let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=x.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=W();return n}function vf(...r){if(r.length===0)return W();let t=r.reduce((o,a)=>o*a,1),e=x.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o++)n[o]=W();return e}function Ef(...r){if(r.length===0)return Er(W);let t=r.reduce((o,a)=>o*a,1),e=x.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o+=2){let[a,u]=mt(W);n[o]=a,o+1<t&&(n[o+1]=u)}return e}function Tf(r,t,e,n="int64"){t==null&&(t=r,r=0);let o=t-r;if(e===void 0)return Math.floor(W()*o)+r;let a=Array.isArray(e)?e:[e],u=a.reduce((c,l)=>c*l,1),s=x.zeros(a,n),i=s.data;if(B(n)){let c=i;for(let l=0;l<u;l++)c[l]=BigInt(Math.floor(W()*o)+r)}else{let c=i;for(let l=0;l<u;l++)c[l]=Math.floor(W()*o)+r}return s}function Of(r=0,t=1,e){if(e===void 0)return W()*(t-r)+r;let n=Array.isArray(e)?e:[e],o=n.reduce((i,c)=>i*c,1),a=x.zeros(n,"float64"),u=a.data,s=t-r;for(let i=0;i<o;i++)u[i]=W()*s+r;return a}function Cf(r=0,t=1,e){if(e===void 0)return Er(W)*t+r;let n=Array.isArray(e)?e:[e],o=n.reduce((s,i)=>s*i,1),a=x.zeros(n,"float64"),u=a.data;for(let s=0;s<o;s+=2){let[i,c]=mt(W);u[s]=i*t+r,s+1<o&&(u[s+1]=c*t+r)}return a}function Uf(r){if(r===void 0)return Er(W);let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=x.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a+=2){let[u,s]=mt(W);o[a]=u,a+1<e&&(o[a+1]=s)}return n}function $f(r=1,t){if(t===void 0)return-Math.log(1-W())*r;let e=Array.isArray(t)?t:[t],n=e.reduce((u,s)=>u*s,1),o=x.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u++)a[u]=-Math.log(1-W())*r;return o}function Rf(r=1,t){if(t===void 0)return Ut(r,W);let e=Array.isArray(t)?t:[t],n=e.reduce((u,s)=>u*s,1),o=x.zeros(e,"int64"),a=o.data;for(let u=0;u<n;u++)a[u]=BigInt(Ut(r,W));return o}function kf(r,t,e){if(e===void 0)return $t(r,t,W);let n=Array.isArray(e)?e:[e],o=n.reduce((s,i)=>s*i,1),a=x.zeros(n,"int64"),u=a.data;for(let s=0;s<o;s++)u[s]=BigInt($t(r,t,W));return a}function qf(r,t,e=!0,n,o=W){let a;if(typeof r=="number")a=Array.from({length:r},(d,p)=>p);else{let d=r.size;a=[];for(let p=0;p<d;p++)a.push(Number(r.iget(p)))}let u=a.length;if(u===0)throw new Error("cannot take a sample from an empty sequence");let s;if(n!==void 0){if(Array.isArray(n))s=n;else{let p=n.size;s=[];for(let f=0;f<p;f++)s.push(Number(n.iget(f)))}if(s.length!==u)throw new Error("p and a must have the same size");let d=s.reduce((p,f)=>p+f,0);Math.abs(d-1)>1e-10&&(s=s.map(p=>p/d))}if(t===void 0){if(s){let d=o(),p=0;for(let f=0;f<u;f++)if(p+=s[f],d<p)return a[f];return a[u-1]}return a[Math.floor(o()*u)]}let i=Array.isArray(t)?t:[t],c=i.reduce((d,p)=>d*p,1);if(!e&&c>u)throw new Error("cannot take a larger sample than population when replace=false");let l=x.zeros(i,"float64"),m=l.data;if(e)if(s){let d=new Array(u);d[0]=s[0];for(let p=1;p<u;p++)d[p]=d[p-1]+s[p];for(let p=0;p<c;p++){let f=o(),y=0;for(;y<u-1&&f>=d[y];)y++;m[p]=a[y]}}else for(let d=0;d<c;d++)m[d]=a[Math.floor(o()*u)];else{let d=[...a],p=s?[...s]:void 0;for(let f=0;f<c;f++){let y;if(p){let g=p.reduce((A,S)=>A+S,0),h=o()*g,b=0;y=0;for(let A=0;A<d.length;A++)if(b+=p[A],h<b){y=A;break}y===0&&h>=b&&(y=d.length-1)}else y=Math.floor(o()*d.length);m[f]=d[y],d.splice(y,1),p&&p.splice(y,1)}}return l}function Vf(r,t,e=!0,n){return qf(r,t,e,n,W)}function jf(r,t=W){let e;if(typeof r=="number"){let o=new Float64Array(r);for(let a=0;a<r;a++)o[a]=a;e=x.fromData(o,[r],"float64")}else e=r.copy();let n=e.size;for(let o=n-1;o>0;o--){let a=Math.floor(t()*(o+1)),u=e.iget(o);e.iset(o,e.iget(a)),e.iset(a,u)}return e}function Pf(r){return jf(r,W)}function Lf(r,t=W){let e=r.size;for(let n=e-1;n>0;n--){let o=Math.floor(t()*(n+1)),a=r.iget(n);r.iset(n,r.iget(o)),r.iset(o,a)}}function Zf(r){Lf(r,W)}function mr(r){return r&&typeof r=="object"&&"_data"in r&&"_shape"in r?v._fromStorage(r):r}var op={seed:_f,random:r=>mr(Bf(r)),rand:(...r)=>mr(vf(...r)),randn:(...r)=>mr(Ef(...r)),randint:(r,t,e,n)=>mr(Tf(r,t,e,n)),uniform:(r,t,e)=>mr(Of(r,t,e)),normal:(r,t,e)=>mr(Cf(r,t,e)),standard_normal:r=>mr(Uf(r)),exponential:(r,t)=>mr($f(r,t)),poisson:(r,t)=>mr(Rf(r,t)),binomial:(r,t,e)=>mr(kf(r,t,e)),choice:(r,t,e,n)=>mr(Vf(r,t,e,n)),permutation:r=>mr(Pf(r)),shuffle:Zf,get_state:Ff,set_state:Mf,default_rng:zf,Generator:ft},ap="0.11.0";return Kf(sp);})();