numpy-ts 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/common/ndarray-core.js +1 -1
- package/dist/esm/common/ops/formatting.js +4 -2
- package/dist/esm/common/ops/linalg.js +2 -2
- package/dist/esm/core/formatting.js +1 -1
- package/dist/esm/full/ndarray.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/numpy-ts.browser.js +7 -5
- package/dist/numpy-ts.node-io.cjs +7 -5
- package/dist/numpy-ts.node-io.cjs.map +4 -4
- package/dist/numpy-ts.node-io.mjs +7 -5
- package/dist/numpy-ts.node-io.mjs.map +4 -4
- package/dist/numpy-ts.node.cjs +7 -5
- package/dist/numpy-ts.node.cjs.map +4 -4
- package/dist/types/common/ops/formatting.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
"use strict";var Us=Object.defineProperty;var $N=Object.getOwnPropertyDescriptor;var kN=Object.getOwnPropertyNames;var RN=Object.prototype.hasOwnProperty;var qN=(r,t)=>{for(var e in t)Us(r,e,{get:t[e],enumerable:!0})},VN=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kN(t))!RN.call(r,o)&&o!==e&&Us(r,o,{get:()=>t[o],enumerable:!(n=$N(t,o))||n.enumerable});return r};var PN=r=>VN(Us({},"__esModule",{value:!0}),r);var Y1={};qN(Y1,{Complex:()=>U,DTYPE_TO_DESCR:()=>Is,InvalidNpyError:()=>hr,NDArray:()=>tr,NDArrayCore:()=>P,SUPPORTED_DTYPES:()=>Lc,UnsupportedDTypeError:()=>Wr,__version__:()=>F1,abs:()=>Kc,absolute:()=>Kc,acos:()=>ul,acosh:()=>ml,add:()=>Qd,all:()=>kg,allclose:()=>vt,amax:()=>Ze,amin:()=>Xe,angle:()=>Xb,any:()=>Rg,append:()=>ph,apply_along_axis:()=>Xd,apply_over_axes:()=>Kd,arange:()=>eA,arccos:()=>ul,arccosh:()=>ml,arcsin:()=>il,arcsinh:()=>fl,arctan:()=>cl,arctan2:()=>ll,arctanh:()=>pl,argmax:()=>Fg,argmin:()=>Mg,argpartition:()=>jh,argsort:()=>qh,argwhere:()=>Wh,around:()=>ol,array:()=>tA,array2string:()=>is,array_equal:()=>Ga,array_equiv:()=>Wa,array_repr:()=>us,array_split:()=>ra,array_str:()=>cs,asanyarray:()=>yA,asarray:()=>uA,asarray_chkfinite:()=>AA,ascontiguousarray:()=>dA,asfortranarray:()=>bA,asin:()=>il,asinh:()=>fl,atan:()=>cl,atan2:()=>ll,atanh:()=>pl,atleast_1d:()=>oa,atleast_2d:()=>aa,atleast_3d:()=>sa,average:()=>$g,base_repr:()=>as,binary_repr:()=>ss,bincount:()=>Jh,bindex:()=>kd,bitwise_and:()=>Vb,bitwise_count:()=>Yb,bitwise_invert:()=>Qc,bitwise_left_shift:()=>Hc,bitwise_not:()=>Qc,bitwise_or:()=>Pb,bitwise_right_shift:()=>rl,bitwise_xor:()=>jb,block:()=>vh,broadcast_arrays:()=>$a,broadcast_shapes:()=>ka,broadcast_to:()=>Bd,byteswap:()=>ds,can_cast:()=>bo,cbrt:()=>gb,ceil:()=>rh,choose:()=>Ed,clip:()=>Fb,column_stack:()=>_h,common_type:()=>Ns,compress:()=>Ud,concat:()=>sl,concatenate:()=>sl,conj:()=>tl,conjugate:()=>tl,convolve:()=>Qh,copy:()=>pA,copysign:()=>ag,copyto:()=>Pa,corrcoef:()=>r0,correlate:()=>Kh,cos:()=>n0,cosh:()=>f0,count_nonzero:()=>Sa,cov:()=>Hh,cross:()=>LA,cumprod:()=>nl,cumsum:()=>el,cumulative_prod:()=>nl,cumulative_sum:()=>el,deg2rad:()=>u0,degrees:()=>s0,delete:()=>al,delete_:()=>al,diag:()=>hA,diag_indices:()=>jd,diag_indices_from:()=>Ld,diagflat:()=>NA,diagonal:()=>TA,diff:()=>MA,digitize:()=>Xh,divide:()=>yb,divmod:()=>Nb,dot:()=>BA,dsplit:()=>na,dstack:()=>zh,ediff1d:()=>FA,einsum:()=>jo,einsum_path:()=>Lo,empty:()=>Hb,empty_like:()=>fA,equal:()=>pg,exp:()=>eb,exp2:()=>nb,expand_dims:()=>Nh,expm1:()=>ob,extract:()=>Zh,eye:()=>sA,fabs:()=>hb,fft:()=>M1,fill:()=>gs,fill_diagonal:()=>La,fix:()=>th,flatnonzero:()=>Yh,flatten:()=>Ah,flip:()=>Th,fliplr:()=>Oh,flipud:()=>Eh,float_power:()=>Sb,floor:()=>eh,floor_divide:()=>db,fmax:()=>Ob,fmin:()=>Eb,fmod:()=>wb,format_float_positional:()=>ns,format_float_scientific:()=>os,frexp:()=>Ib,frombuffer:()=>wA,fromfile:()=>vA,fromfunction:()=>IA,fromiter:()=>zA,fromregex:()=>G1,fromregexSync:()=>W1,fromstring:()=>_A,full:()=>rA,full_like:()=>mA,gcd:()=>zb,genfromtxt:()=>j1,genfromtxtSync:()=>L1,geomspace:()=>aA,get_printoptions:()=>ts,geterr:()=>Ja,gradient:()=>Ua,greater:()=>cg,greater_equal:()=>lg,heaviside:()=>Cb,histogram:()=>Ba,histogram2d:()=>Ta,histogram_bin_edges:()=>Ea,histogramdd:()=>Oa,hsplit:()=>ea,hstack:()=>Ih,hypot:()=>a0,i0:()=>qb,identity:()=>iA,iindex:()=>$d,imag:()=>Jb,in1d:()=>ah,indices:()=>qd,inner:()=>UA,insert:()=>yh,interp:()=>$b,intersect1d:()=>sh,invert:()=>Lb,isclose:()=>dg,iscomplex:()=>eg,iscomplexobj:()=>ba,isdtype:()=>Da,isfinite:()=>XA,isfortran:()=>ga,isin:()=>ih,isinf:()=>KA,isnan:()=>QA,isnat:()=>HA,isneginf:()=>rg,isposinf:()=>tg,isreal:()=>ng,isrealobj:()=>Aa,isscalar:()=>ha,issubdtype:()=>Cs,item:()=>ms,iterable:()=>Na,ix_:()=>ja,kron:()=>OA,lcm:()=>_b,ldexp:()=>vb,left_shift:()=>Hc,less:()=>fg,less_equal:()=>mg,lexsort:()=>Vh,linalg:()=>Xo,linspace:()=>nA,load:()=>T1,loadNpy:()=>MN,loadNpySync:()=>FN,loadNpz:()=>I1,loadNpzFile:()=>ON,loadNpzFileSync:()=>EN,loadNpzSync:()=>z1,loadSync:()=>O1,loadtxt:()=>R1,loadtxtSync:()=>q1,log:()=>ab,log10:()=>ib,log1p:()=>ub,log2:()=>sb,logaddexp:()=>cb,logaddexp2:()=>lb,logical_and:()=>WA,logical_not:()=>ZA,logical_or:()=>YA,logical_xor:()=>JA,logspace:()=>oA,mask_indices:()=>Jd,matmul:()=>GA,matrix_transpose:()=>qA,matvec:()=>PA,max:()=>Ze,maximum:()=>Bb,may_share_memory:()=>Ya,mean:()=>zg,median:()=>Og,meshgrid:()=>Jc,min:()=>Xe,min_scalar_type:()=>xs,minimum:()=>Tb,mintypecode:()=>ws,mod:()=>pb,modf:()=>Mb,moveaxis:()=>xh,multiply:()=>rb,nan_to_num:()=>Ub,nanargmax:()=>Zg,nanargmin:()=>Yg,nancumprod:()=>Xg,nancumsum:()=>Jg,nanmax:()=>Wg,nanmean:()=>Pg,nanmedian:()=>Kg,nanmin:()=>Gg,nanpercentile:()=>Hg,nanprod:()=>Vg,nanquantile:()=>Qg,nanstd:()=>Lg,nansum:()=>qg,nanvar:()=>jg,ndim:()=>ls,negative:()=>fb,nextafter:()=>ig,nonzero:()=>Gh,not_equal:()=>yg,ones:()=>Qb,ones_like:()=>lA,outer:()=>$A,packbits:()=>Gb,pad:()=>dh,parseNpy:()=>D1,parseNpyData:()=>C1,parseNpyHeader:()=>x1,parseNpz:()=>S1,parseNpzSync:()=>w1,parseTxt:()=>_1,partition:()=>Ph,percentile:()=>Eg,permute_dims:()=>VA,place:()=>qa,poly:()=>bg,polyadd:()=>Ag,polyder:()=>gg,polydiv:()=>hg,polyfit:()=>Ng,polyint:()=>Dg,polymul:()=>xg,polysub:()=>Cg,polyval:()=>Sg,positive:()=>bb,pow:()=>Xc,power:()=>Xc,printoptions:()=>es,prod:()=>_g,promote_types:()=>xa,ptp:()=>vg,put:()=>Tt,put_along_axis:()=>Ra,putmask:()=>Va,quantile:()=>Ug,rad2deg:()=>c0,radians:()=>i0,random:()=>v1,ravel:()=>gh,ravel_multi_index:()=>Vd,real:()=>Zb,real_if_close:()=>og,reciprocal:()=>Ab,remainder:()=>xb,repeat:()=>Bh,require:()=>gA,reshape:()=>bh,resize:()=>kh,result_type:()=>Ds,right_shift:()=>rl,rint:()=>nh,roll:()=>$h,rollaxis:()=>Ch,roots:()=>wg,rot90:()=>Uh,round:()=>ol,round_:()=>za,row_stack:()=>Qo,save:()=>E1,saveNpy:()=>BN,saveNpySync:()=>TN,saveNpz:()=>wl,saveNpzSync:()=>B1,saveSync:()=>U1,savetxt:()=>V1,savetxtSync:()=>P1,savez:()=>$1,savez_compressed:()=>k1,searchsorted:()=>Mt,select:()=>Rd,serializeNpy:()=>Kr,serializeNpz:()=>_s,serializeNpzSync:()=>vs,serializeTxt:()=>Ot,set_printoptions:()=>rs,setdiff1d:()=>uh,seterr:()=>Xa,setxor1d:()=>ch,shape:()=>yo,shares_memory:()=>Za,sign:()=>mb,signbit:()=>sg,sin:()=>e0,sinc:()=>Rb,sinh:()=>l0,size:()=>fs,sort:()=>Rh,sort_complex:()=>Lh,spacing:()=>ug,split:()=>Ho,sqrt:()=>tb,square:()=>Db,squeeze:()=>hh,stack:()=>Sh,std:()=>Tg,subtract:()=>Hd,sum:()=>Ig,swapaxes:()=>Dh,take:()=>Td,take_along_axis:()=>Od,tan:()=>o0,tanh:()=>m0,tensordot:()=>kA,tile:()=>Fh,tobytes:()=>ys,tofile:()=>As,tolist:()=>ps,trace:()=>et,transpose:()=>EA,trapezoid:()=>t0,tri:()=>DA,tril:()=>xA,tril_indices:()=>Gd,tril_indices_from:()=>Wd,trim_zeros:()=>fh,triu:()=>CA,triu_indices:()=>Yd,triu_indices_from:()=>Zd,true_divide:()=>Vo,trunc:()=>oh,typename:()=>Ss,union1d:()=>lh,unique:()=>_a,unique_all:()=>va,unique_counts:()=>Ma,unique_inverse:()=>Fa,unique_values:()=>mh,unpackbits:()=>Wb,unravel_index:()=>Pd,unstack:()=>Mh,unwrap:()=>kb,vander:()=>SA,var:()=>ya,variance:()=>Bg,vdot:()=>Go,vecdot:()=>RA,vecmat:()=>jA,view:()=>bs,vsplit:()=>ta,vstack:()=>wh,where:()=>Ca,zeros:()=>Kb,zeros_like:()=>cA});module.exports=PN(Y1);var Pr=require("node:fs"),jr=require("node:fs/promises");function Fo(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 Bo(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 er="float64";function K(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 Yr(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 Ur(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function Er(r){return r==="float64"||r==="float32"}function O(r){return r==="int64"||r==="uint64"}function B(r){return r==="complex64"||r==="complex128"}function L(r,t,e){if(B(r)){let n=e?` ${e}`:"";throw new TypeError(`ufunc '${t}' not supported for complex dtype '${r}'.${n}`)}}function $t(r){if(r==="complex128")return"float64";if(r==="complex64")return"float32";throw new Error(`${r} is not a complex dtype`)}function or(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(B(r)||B(t)){if(B(r)&&B(t))return r==="complex128"||t==="complex128"?"complex128":"complex64";let c=B(r)?r:t,l=B(r)?t:r;return c==="complex128"||l==="float64"||l==="int64"||l==="uint64"||l==="int32"||l==="uint32"?"complex128":"complex64"}if(Er(r)||Er(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,i=u(r),s=u(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&i===s){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(o&&n&&i===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(i,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?i>s?r:s===8?"int16":s===16?"int32":s===32?"int64":"float64":o&&n?s>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}var U=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 Il(r){return r instanceof U||typeof r=="object"&&r!==null&&"re"in r}var S=class r{constructor(t,e,n,o,a){this._isCContiguous=-1;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(){if(this._isCContiguous!==-1)return this._isCContiguous===1;let t=this._shape,e=this._strides,n=t.length,o;if(n===0)o=!0;else if(n===1)o=e[0]===1;else{o=!0;let a=1;for(let u=n-1;u>=0;u--){if(e[u]!==a){o=!1;break}a*=t[u]}}return this._isCContiguous=o?1:0,o}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=B(this._dtype),u;if(o===0)u=this._offset;else{let i=t;u=this._offset;for(let s=0;s<o;s++){let c=1;for(let f=s+1;f<o;f++)c*=e[f];let l=Math.floor(i/c);i=i%c,u+=l*n[s]}}if(a){let i=u*2,s=this._data[i],c=this._data[i+1];return new U(s,c)}return this._data[u]}iset(t,e){let n=this._shape,o=this._strides,a=n.length,u=B(this._dtype),i;if(a===0)i=this._offset;else{let s=t;i=this._offset;for(let c=0;c<a;c++){let l=1;for(let m=c+1;m<a;m++)l*=n[m];let f=Math.floor(s/l);s=s%l,i+=f*o[c]}}if(u){let s=i*2,c,l;e instanceof U?(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[s]=c,this._data[s+1]=l}else this._data[i]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];if(B(this._dtype)){let o=n*2,a=this._data[o],u=this._data[o+1];return new U(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(B(this._dtype)){let a=o*2,u,i;e instanceof U?(u=e.re,i=e.im):typeof e=="object"&&e!==null&&"re"in e?(u=e.re,i=e.im??0):(u=Number(e),i=0),this._data[a]=u,this._data[a+1]=i}else this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=B(e),a=K(e);if(!a)throw new Error(`Cannot copy array with dtype ${e}`);let u=o?n*2:n,i=new a(u);if(this.isCContiguous&&this._offset===0)if(O(e)){let s=this._data,c=i;for(let l=0;l<u;l++)c[l]=s[l]}else i.set(this._data.subarray(0,u));else if(O(e)){let s=i;for(let c=0;c<n;c++)s[c]=this.iget(c)}else if(o){let s=i;for(let c=0;c<n;c++){let l=this.iget(c);s[c*2]=l.re,s[c*2+1]=l.im}}else for(let s=0;s<n;s++)i[s]=this.iget(s);return new r(i,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let u=o??r._computeStrides(e),i=a??0;return new r(t,e,u,i,n)}static zeros(t,e=er){let n=t.reduce((s,c)=>s*c,1),o=B(e),a=K(e);if(!a)throw new Error(`Cannot create array with dtype ${e}`);let u=o?n*2:n,i=new a(u);return new r(i,t,r._computeStrides(t),0,e)}static ones(t,e=er){let n=t.reduce((s,c)=>s*c,1),o=B(e),a=K(e);if(!a)throw new Error(`Cannot create array with dtype ${e}`);let u=o?n*2:n,i=new a(u);if(O(e))i.fill(BigInt(1));else if(o){let s=i;for(let c=0;c<n;c++)s[c*2]=1,s[c*2+1]=0}else i.fill(1);return new r(i,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 lr(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}var P=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 itemsize(){return Yr(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){let e=this._storage.dtype,n=this.size;if(O(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 i=a;if(i<0&&(i=this.shape[u]+i),i<0||i>=this.shape[u])throw new Error(`Index ${a} is out of bounds for axis ${u} with size ${this.shape[u]}`);return i}),o=this.dtype;if(B(o))this._storage.set(n,e);else if(O(o)){let a=e instanceof U?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 U?e.re:Number(e))?1:0;this._storage.set(n,u)}else{let a=e instanceof U?e.re:Number(e);this._storage.set(n,a)}}iget(t){return this._storage.iget(t)}iset(t,e){this._storage.iset(t,e)}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=K(t);if(!u)throw new Error(`Cannot convert to dtype ${t}`);let i=new u(a),s=this.data;if(O(n)&&!O(t)){let l=s;if(t==="bool")for(let f=0;f<a;f++)i[f]=l[f]!==BigInt(0)?1:0;else for(let f=0;f<a;f++)i[f]=Number(l[f])}else if(!O(n)&&O(t)){let l=s;for(let f=0;f<a;f++)i[f]=BigInt(Math.round(Number(l[f])))}else if(t==="bool"){let l=s;for(let f=0;f<a;f++)i[f]=l[f]!==0?1:0}else if(n==="bool"&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else if(!O(n)&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else{let l=s;for(let f=0;f<a;f++)i[f]=l[f]}let c=S.fromData(i,o,t);return new r(c)}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=Fo(s);return Bo(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];if(a+=c.start*this._storage.strides[s],c.step===0)continue;let l=Math.max(0,Math.ceil((c.stop-c.start)/c.step));n.push(l),o.push(this._storage.strides[s]*c.step)}let u=S.fromData(this._storage.data,n,this._storage.dtype,o,a),i=this._base??this;return new r(u,i)}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 i=0;i<t[a];i++)o[a]=i,u.push(n(o,a+1));return u};return n(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){let n=this._storage.data,o=n.BYTES_PER_ELEMENT,a=this._storage.offset*o,u=this.size*o;return n.buffer.slice(a,a+u)}let e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){let e=t[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(t)}};function z(r){return r instanceof P||r&&typeof r=="object"&&"storage"in r&&r.storage instanceof S?r.storage:r}function M(r,t){return P.fromStorage(r,t)}function Nr(r,t){let e=t.base??t;return P.fromStorage(r,e)}function $r(r){return r.map(t=>M(t))}function ft(r,t){return r.map(e=>Nr(e,t))}function To(r){return[M(r[0]),M(r[1])]}function $s(r){return new P(r)}function jN(r){return!!(r instanceof P||r&&typeof r=="object"&&"storage"in r&&r.storage instanceof S)}function wr(r,t=er){let e=S.zeros(r,t);return new P(e)}function Oo(r,t=er){let e=S.ones(r,t);return new P(e)}function Eo(r,t=er){return wr(r,t)}function Uo(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=er);let o=K(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((s,c)=>s*c,1),u=new o(a);if(O(n)){let s=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));u.fill(s)}else n==="bool"?u.fill(t?1:0):u.fill(Number(t));let i=S.fromData(u,r,n);return new P(i)}function LN(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function zl(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>zl(t)):!1}function _l(r){return Il(r)?!0:Array.isArray(r)?r.some(t=>_l(t)):!1}function GN(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function Q(r,t){if(r instanceof P)return!t||r.dtype===t?r.copy():r.astype(t);let e=zl(r),n=_l(r),o=LN(r),a=o.reduce((p,y)=>p*y,1),u=t;u||(n?u="complex128":e?u="int64":u=er);let i=B(u),s=K(u);if(!s)throw new Error(`Cannot create array with dtype ${u}`);let c=i?a*2:a,l=new s(c),f=GN(r);if(O(u)){let p=l;for(let y=0;y<a;y++){let d=f[y];p[y]=typeof d=="bigint"?d:BigInt(Math.round(Number(d)))}}else if(u==="bool"){let p=l;for(let y=0;y<a;y++)p[y]=f[y]?1:0}else if(i){let p=l;for(let y=0;y<a;y++){let d=f[y],b,A;d instanceof U?(b=d.re,A=d.im):typeof d=="object"&&d!==null&&"re"in d?(b=d.re,A=d.im??0):(b=Number(d),A=0),p[y*2]=b,p[y*2+1]=A}}else{let p=l;for(let y=0;y<a;y++){let d=f[y];p[y]=Number(d)}}let m=S.fromData(l,o,u);return new P(m)}function ks(r,t,e=1,n=er){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)),i=K(n);if(!i)throw new Error(`Cannot create arange array with dtype ${n}`);let s=new i(u);if(O(n))for(let l=0;l<u;l++)s[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<u;l++)s[l]=o+l*e!==0?1:0;else for(let l=0;l<u;l++)s[l]=o+l*e;let c=S.fromData(s,[u],n);return new P(c)}function Rs(r,t,e=50,n=er){if(e<0)throw new Error("num must be non-negative");if(e===0)return Q([],n);if(e===1)return Q([r],n);let o=K(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),u=(t-r)/(e-1);if(O(n))for(let s=0;s<e;s++)a[s]=BigInt(Math.round(r+s*u));else if(n==="bool")for(let s=0;s<e;s++)a[s]=r+s*u!==0?1:0;else for(let s=0;s<e;s++)a[s]=r+s*u;let i=S.fromData(a,[e],n);return new P(i)}function qs(r,t,e=50,n=10,o=er){if(e<0)throw new Error("num must be non-negative");if(e===0)return Q([],o);if(e===1)return Q([Math.pow(n,r)],o);let a=K(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let u=new a(e),i=(t-r)/(e-1);if(O(o))for(let c=0;c<e;c++){let l=r+c*i;u[c]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let c=0;c<e;c++){let l=r+c*i;u[c]=Math.pow(n,l)!==0?1:0}else for(let c=0;c<e;c++){let l=r+c*i;u[c]=Math.pow(n,l)}let s=S.fromData(u,[e],o);return new P(s)}function Vs(r,t,e=50,n=er){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 Q([],n);if(e===1)return Q([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=K(n);if(!u)throw new Error(`Cannot create geomspace array with dtype ${n}`);let i=new u(e),s=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-s)/(e-1);if(O(n))for(let m=0;m<e;m++){let p=o*Math.exp(s+m*l);i[m]=BigInt(Math.round(p))}else if(n==="bool")for(let m=0;m<e;m++){let p=o*Math.exp(s+m*l);i[m]=p!==0?1:0}else for(let m=0;m<e;m++){let p=o*Math.exp(s+m*l);i[m]=p}let f=S.fromData(i,[e],n);return new P(f)}function $o(r,t,e=0,n=er){let o=t??r,a=wr([r,o],n),u=a.data;if(O(n)){let i=u;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(i[s*o+c]=BigInt(1))}}else{let i=u;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(i[s*o+c]=1)}}return a}function Ps(r,t=er){return $o(r,r,0,t)}function Qr(r,t){return jN(r)?!t||r.dtype===t?r:r.astype(t):Q(r,t)}function js(r,t){return wr(Array.from(r.shape),t??r.dtype)}function Ls(r,t){return Oo(Array.from(r.shape),t??r.dtype)}function Gs(r,t){return Eo(Array.from(r.shape),t??r.dtype)}function Ws(r,t,e){return Uo(Array.from(r.shape),t,e??r.dtype)}function Ys(r){return r.copy()}function Zs(r,t){return Qr(r,t)}function Js(r,t){return Qr(r,t).copy()}function Xs(r,t){return Qr(r,t).copy()}function Ks(r,t){let e=Qr(r,t),n=e.data;for(let o=0;o<n.length;o++){let a=n[o];if(!Number.isFinite(a))throw new Error("array must not contain infs or NaNs")}return e}function Qs(r,t,e){let n=r;return t&&t!==r.dtype&&(n=n.astype(t)),n}function WN(r){let t=r.data,e=S.fromData(t.slice(),[t.length],r.dtype);return $s(e)}function ko(r,t=0){let e=r.shape,n=r.data,o=r.dtype;if(e.length===1){let a=e[0],u=a+Math.abs(t),i=wr([u,u],o),s=i.data;for(let c=0;c<a;c++){let l=t>=0?c:c-t,f=t>=0?c+t:c;l>=0&&l<u&&f>=0&&f<u&&(s[l*u+f]=n[c])}return i}else if(e.length===2){let a=e[0],u=e[1],i=Math.min(t>=0?Math.min(a,u-t):Math.min(a+t,u),Math.max(0,t>=0?u-t:a+t));if(i<=0)return Q([],o);let s=[];for(let c=0;c<i;c++){let l=t>=0?c:c-t,f=t>=0?c+t:c;l>=0&&l<a&&f>=0&&f<u&&s.push(n[l*u+f])}return Q(s,o)}throw new Error("Input must be 1-D or 2-D")}function Hs(r,t=0){let e=WN(r);return ko(e,t)}function ri(r,t,e=0,n=er){let o=t??r,a=wr([r,o],n),u=a.data;for(let i=0;i<r;i++)for(let s=0;s<=Math.min(i+e,o-1);s++)s>=0&&(u[i*o+s]=1);return a}function ti(r,t=0){let e=r.shape;if(e.length<2)throw new Error("Input must be at least 2-D");let n=r.copy(),o=n.data,a=e[e.length-2],u=e[e.length-1],i=e.slice(0,-2).reduce((c,l)=>c*l,1),s=a*u;for(let c=0;c<i;c++){let l=c*s;for(let f=0;f<a;f++)for(let m=f+t+1;m<u;m++)o[l+f*u+m]=0}return n}function ei(r,t=0){let e=r.shape;if(e.length<2)throw new Error("Input must be at least 2-D");let n=r.copy(),o=n.data,a=e[e.length-2],u=e[e.length-1],i=e.slice(0,-2).reduce((c,l)=>c*l,1),s=a*u;for(let c=0;c<i;c++){let l=c*s;for(let f=0;f<a;f++)for(let m=0;m<Math.min(f+t,u);m++)o[l+f*u+m]=0}return n}function ni(r,t,e=!1){let n=r.size,o=t??n,a=r.data,u=wr([n,o],r.dtype),i=u.data;for(let s=0;s<n;s++){let c=a[s];for(let l=0;l<o;l++){let f=e?l:o-1-l;i[s*o+l]=Math.pow(c,f)}}return u}function oi(r,t=er,e=-1,n=0){let o=K(t);if(!o)throw new Error(`Unsupported dtype: ${t}`);let a;if(r instanceof ArrayBuffer){let i=n,s=e<0?(r.byteLength-i)/o.BYTES_PER_ELEMENT:e;a=new o(r,i,s)}else{let i=n,s=e<0?r.length:n+e,c=Array.from(r.slice(i,s));a=new o(c.length);for(let l=0;l<c.length;l++)a[l]=c[l]}let u=S.fromData(a,[a.length],t);return $s(u)}function ai(r,t,e=er){let n=t.reduce((c,l)=>c*l,1),o=K(e);if(!o)throw new Error(`Unsupported dtype: ${e}`);let a=new o(n),u=[],i=1;for(let c=t.length-1;c>=0;c--)u.unshift(i),i*=t[c];for(let c=0;c<n;c++){let l=[],f=c;for(let m=0;m<t.length;m++)l.push(Math.floor(f/u[m])),f=f%u[m];a[c]=r(...l)}let s=S.fromData(a,t,e);return $s(s)}function si(r,t=er,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return Q(n,t)}function ii(r,t=er,e=-1,n){let o=n??/\s+/,u=r.split(o).filter(s=>s.trim()!=="").map(s=>parseFloat(s.trim())),i=e>=0?u.slice(0,e):u;return Q(i,t)}function ui(r,t=er,e=-1,n=""){throw new Error("fromfile requires Node.js file system access")}function Zr(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 i=u<o-e?1:r[u-(o-e)],s=u<o-n?1:t[u-(o-n)];if(i===s)a[u]=i;else if(i===1)a[u]=s;else if(s===1)a[u]=i;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 YN(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let i=o-n+u,s=r[u],c=e[i];if(s===c)a[i]=t[u];else if(s===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function Ro(r,t){let e=YN(r.shape,r.strides,t);return S.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function sr(r,t,e,n){let o=or(r.dtype,t.dtype),a=r.shape,u=t.shape;if(a.length===u.length&&a.every((y,d)=>y===u[d])&&r.isCContiguous&&t.isCContiguous&&!O(r.dtype)&&!O(t.dtype)&&!O(o)){let y=r.size,d=S.zeros(Array.from(a),o),b=d.data,A=r.data,g=t.data,h=r.offset,N=t.offset;if(h===0&&N===0)for(let D=0;D<y;D++)b[D]=e(A[D],g[D]);else for(let D=0;D<y;D++)b[D]=e(A[h+D],g[N+D]);return d}let s=Zr(r.shape,t.shape),c=Ro(r,s),l=Ro(t,s),f=S.zeros(s,o),m=f.data,p=f.size;if(O(o)){let y=m;for(let d=0;d<p;d++){let b=c.iget(d),A=l.iget(d),g=b instanceof U?b.re:b,h=A instanceof U?A.re:A,N=typeof g=="bigint"?g:BigInt(Math.round(g)),D=typeof h=="bigint"?h:BigInt(Math.round(h));n==="add"?y[d]=N+D:n==="subtract"?y[d]=N-D:n==="multiply"?y[d]=N*D:n==="divide"?y[d]=N/D:y[d]=BigInt(Math.round(e(Number(N),Number(D))))}}else{let y=O(r.dtype)||O(t.dtype);for(let d=0;d<p;d++){let b=c.iget(d),A=l.iget(d),g=Number(b),h=Number(A);m[d]=e(g,h)}}return f}function Ir(r,t,e){let n=Zr(r.shape,t.shape),o=Ro(r,n),a=Ro(t,n),u=n.reduce((c,l)=>c*l,1),i=new Uint8Array(u),s=O(r.dtype)||O(t.dtype);for(let c=0;c<u;c++){let l=o.iget(c),f=a.iget(c),m=Number(l),p=Number(f);i[c]=e(m,p)?1:0}return S.fromData(i,n,"bool")}function ir(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,i=e?n:n!=="float32"&&n!=="float64"?"float64":n,s=S.zeros(o,i),c=s.data,l=r.data,f=r.offset,m=r.isCContiguous;if(O(n))if(O(i)){let p=c;if(m)for(let y=0;y<a;y++){let d=Number(l[f+y]);p[y]=BigInt(Math.round(t(d)))}else for(let y=0;y<a;y++)p[y]=BigInt(Math.round(t(Number(r.iget(y)))))}else if(m)for(let p=0;p<a;p++)c[p]=t(Number(l[f+p]));else for(let p=0;p<a;p++)c[p]=t(Number(r.iget(p)));else if(m)if(f===0)for(let p=0;p<a;p++)c[p]=t(Number(l[p]));else for(let p=0;p<a;p++)c[p]=t(Number(l[f+p]));else for(let p=0;p<a;p++)c[p]=t(Number(r.iget(p)));return s}function ci(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Dr(r,t){return[r[t*2],r[t*2+1]]}function br(r,t,e,n){r[t*2]=e,r[t*2+1]=n}function Bl(r,t){if(typeof t=="number")return vl(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return vl(r,e)}return ci(r,t)?ZN(r,t):sr(r,t,(e,n)=>e+n,"add")}function ZN(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=n.data,s=r.offset,c=t.offset;if(B(e)){let l=i,f=B(r.dtype),m=B(t.dtype);for(let p=0;p<o;p++){let[y,d]=f?Dr(a,s+p):[Number(a[s+p]),0],[b,A]=m?Dr(u,c+p):[Number(u[c+p]),0];br(l,p,y+b,d+A)}return n}if(O(e)){let l=i;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[s+m]=="bigint"?a[s+m]:BigInt(Math.round(Number(a[s+m]))),y=typeof u[c+m]=="bigint"?u[c+m]:BigInt(Math.round(Number(u[c+m])));l[m]=p+y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[s+y]+p[c+y]}}else if(O(r.dtype)||O(t.dtype))for(let f=0;f<o;f++){let m=typeof a[s+f]=="bigint"?Number(a[s+f]):a[s+f],p=typeof u[c+f]=="bigint"?Number(u[c+f]):u[c+f];i[f]=m+p}else if(s===0&&c===0)for(let f=0;f<o;f++)i[f]=a[f]+u[f];else for(let f=0;f<o;f++)i[f]=a[s+f]+u[c+f];return n}function Tl(r,t){if(typeof t=="number")return Ml(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return Ml(r,e)}return ci(r,t)?JN(r,t):sr(r,t,(e,n)=>e-n,"subtract")}function JN(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=n.data,s=r.offset,c=t.offset;if(B(e)){let l=i,f=B(r.dtype),m=B(t.dtype);for(let p=0;p<o;p++){let[y,d]=f?Dr(a,s+p):[Number(a[s+p]),0],[b,A]=m?Dr(u,c+p):[Number(u[c+p]),0];br(l,p,y-b,d-A)}return n}if(O(e)){let l=i;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[s+m]=="bigint"?a[s+m]:BigInt(Math.round(Number(a[s+m]))),y=typeof u[c+m]=="bigint"?u[c+m]:BigInt(Math.round(Number(u[c+m])));l[m]=p-y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[s+y]-p[c+y]}}else if(O(r.dtype)||O(t.dtype))for(let f=0;f<o;f++){let m=typeof a[s+f]=="bigint"?Number(a[s+f]):a[s+f],p=typeof u[c+f]=="bigint"?Number(u[c+f]):u[c+f];i[f]=m-p}else if(s===0&&c===0)for(let f=0;f<o;f++)i[f]=a[f]-u[f];else for(let f=0;f<o;f++)i[f]=a[s+f]-u[c+f];return n}function Ol(r,t){if(typeof t=="number")return Fl(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return Fl(r,e)}return ci(r,t)?XN(r,t):sr(r,t,(e,n)=>e*n,"multiply")}function XN(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=n.data,s=r.offset,c=t.offset;if(B(e)){let l=i,f=B(r.dtype),m=B(t.dtype);for(let p=0;p<o;p++){let[y,d]=f?Dr(a,s+p):[Number(a[s+p]),0],[b,A]=m?Dr(u,c+p):[Number(u[c+p]),0],g=y*b-d*A,h=y*A+d*b;br(l,p,g,h)}return n}if(O(e)){let l=i;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[s+m]=="bigint"?a[s+m]:BigInt(Math.round(Number(a[s+m]))),y=typeof u[c+m]=="bigint"?u[c+m]:BigInt(Math.round(Number(u[c+m])));l[m]=p*y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[s+y]*p[c+y]}}else if(O(r.dtype)||O(t.dtype))for(let f=0;f<o;f++){let m=typeof a[s+f]=="bigint"?Number(a[s+f]):a[s+f],p=typeof u[c+f]=="bigint"?Number(u[c+f]):u[c+f];i[f]=m*p}else if(s===0&&c===0)for(let f=0;f<o;f++)i[f]=a[f]*u[f];else for(let f=0;f<o;f++)i[f]=a[s+f]*u[c+f];return n}function El(r,t){if(typeof t=="number")return KN(r,t);let e=B(r.dtype),n=B(t.dtype);if(e||n){let l=or(r.dtype,t.dtype),f=S.zeros(Array.from(r.shape),l),m=f.data,p=r.size,y=r.data,d=t.data,b=r.offset,A=t.offset;for(let g=0;g<p;g++){let[h,N]=e?Dr(y,b+g):[Number(y[b+g]),0],[D,x]=n?Dr(d,A+g):[Number(d[A+g]),0],C=D*D+x*x,w=(h*D+N*x)/C,_=(N*D-h*x)/C;br(m,g,w,_)}return f}let o=r.dtype==="float64",a=t.dtype==="float64",u=r.dtype==="float32",i=t.dtype==="float32";if(o||a){let l=o?r:mt(r,"float64"),f=a?t:mt(t,"float64");return sr(l,f,(m,p)=>m/p,"divide")}if(u||i){let l=u?r:mt(r,"float32"),f=i?t:mt(t,"float32");return sr(l,f,(m,p)=>m/p,"divide")}let s=mt(r,"float64"),c=mt(t,"float64");return sr(s,c,(l,f)=>l/f,"divide")}function mt(r,t){let e=S.zeros(Array.from(r.shape),t),n=r.size,o=e.data;if(r.isCContiguous){let a=r.data,u=r.offset;for(let i=0;i<n;i++)o[i]=Number(a[u+i])}else for(let a=0;a<n;a++)o[a]=Number(r.iget(a));return e}function vl(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(B(e)){let l=o,f=c;if(i)for(let m=0;m<a;m++){let[p,y]=Dr(l,u+m);br(f,m,p+t,y)}else for(let m=0;m<a;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;br(f,m,y+t,d)}}else if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]+f}else for(let m=0;m<a;m++)l[m]=r.iget(m)+f}else if(i)if(u===0)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[u+l])+t;else for(let l=0;l<a;l++)c[l]=Number(r.iget(l))+t;return s}function Ml(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(B(e)){let l=o,f=c;if(i)for(let m=0;m<a;m++){let[p,y]=Dr(l,u+m);br(f,m,p-t,y)}else for(let m=0;m<a;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;br(f,m,y-t,d)}}else if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]-f}else for(let m=0;m<a;m++)l[m]=r.iget(m)-f}else if(i)for(let l=0;l<a;l++)c[l]=Number(o[u+l])-t;else for(let l=0;l<a;l++)c[l]=Number(r.iget(l))-t;return s}function Fl(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(B(e)){let l=o,f=c;if(i)for(let m=0;m<a;m++){let[p,y]=Dr(l,u+m);br(f,m,p*t,y*t)}else for(let m=0;m<a;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;br(f,m,y*t,d*t)}}else if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]*f}else for(let m=0;m<a;m++)l[m]=r.iget(m)*f}else if(i)if(u===0)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[u+l])*t;else for(let l=0;l<a;l++)c[l]=Number(r.iget(l))*t;return s}function KN(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous;if(B(e)){let m=S.zeros(n,e),p=m.data;if(i){let y=o;for(let d=0;d<a;d++){let[b,A]=Dr(y,u+d);br(p,d,b/t,A/t)}}else for(let y=0;y<a;y++){let d=r.iget(y),b=d.re??Number(d),A=d.im??0;br(p,y,b/t,A/t)}return m}let c=e!=="float32"&&e!=="float64"?"float64":e,l=S.zeros(n,c),f=l.data;if(i)for(let m=0;m<a;m++)f[m]=Number(o[u+m])/t;else for(let m=0;m<a;m++)f[m]=Number(r.iget(m))/t;return l}function Ul(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous;if(B(t)){let c=$t(t),l=S.zeros(e,c),f=l.data;if(u){let m=n;for(let p=0;p<o;p++){let y=m[(a+p)*2],d=m[(a+p)*2+1];f[p]=Math.sqrt(y*y+d*d)}}else for(let m=0;m<o;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;f[m]=Math.sqrt(y*y+d*d)}return l}let i=S.zeros(e,t),s=i.data;if(O(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++){let m=l[a+f];c[f]=m<0n?-m:m}}else for(let l=0;l<o;l++){let f=r.iget(l);c[l]=f<0n?-f:f}}else if(u)if(a===0)for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[a+c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(r.iget(c)));return i}function $l(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(B(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++){let[m,p]=Dr(l,a+f);br(c,f,-m,-p)}}else for(let l=0;l<o;l++){let f=r.iget(l),m=f.re??Number(f),p=f.im??0;br(c,l,-m,-p)}}else if(O(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++)c[f]=-l[a+f]}else for(let l=0;l<o;l++)c[l]=-r.iget(l)}else if(u)if(a===0)for(let c=0;c<o;c++)s[c]=-Number(n[c]);else for(let c=0;c<o;c++)s[c]=-Number(n[a+c]);else for(let c=0;c<o;c++)s[c]=-Number(r.iget(c));return i}function kl(r){L(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=r.offset,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(O(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++){let m=l[a+f];c[f]=m>0n?1n:m<0n?-1n:0n}}else for(let l=0;l<o;l++){let f=r.iget(l);c[l]=f>0n?1n:f<0n?-1n:0n}}else if(u)for(let c=0;c<o;c++){let l=Number(n[a+c]);s[c]=l>0?1:l<0?-1:0}else for(let c=0;c<o;c++){let l=Number(r.iget(c));s[c]=l>0?1:l<0?-1:0}return i}function qo(r,t){return L(r.dtype,"mod","Modulo is not defined for complex numbers."),typeof t!="number"&&L(t.dtype,"mod","Modulo is not defined for complex numbers."),typeof t=="number"?QN(r,t):sr(r,t,(e,n)=>(e%n+n)%n,"mod")}function QN(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++){let y=m[u+p];l[p]=(y%f+f)%f}}else for(let m=0;m<a;m++){let p=r.iget(m);l[m]=(p%f+f)%f}}else if(i)for(let l=0;l<a;l++){let f=Number(o[u+l]);c[l]=(f%t+t)%t}else for(let l=0;l<a;l++){let f=Number(r.iget(l));c[l]=(f%t+t)%t}return s}function li(r,t){return L(r.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof t!="number"&&L(t.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof t=="number"?HN(r,t):sr(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function HN(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]/f}else for(let m=0;m<a;m++)l[m]=r.iget(m)/f}else if(i)for(let l=0;l<a;l++)c[l]=Math.floor(Number(o[u+l])/t);else for(let l=0;l<a;l++)c[l]=Math.floor(Number(r.iget(l))/t);return s}function Rl(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(B(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++)c[f*2]=l[(a+f)*2],c[f*2+1]=l[(a+f)*2+1]}else for(let l=0;l<o;l++){let f=r.iget(l);c[l*2]=f.re??Number(f),c[l*2+1]=f.im??0}}else if(u)for(let c=0;c<o;c++)s[c]=n[a+c];else for(let c=0;c<o;c++)s[c]=r.iget(c);return i}function ql(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous;if(B(t)){let f=S.zeros(e,t),m=f.data;if(u){let p=n;for(let y=0;y<o;y++){let d=p[(a+y)*2],b=p[(a+y)*2+1],A=d*d+b*b;m[y*2]=d/A,m[y*2+1]=-b/A}}else for(let p=0;p<o;p++){let y=r.iget(p),d=y.re??Number(y),b=y.im??0,A=d*d+b*b;m[p*2]=d/A,m[p*2+1]=-b/A}return f}let s=t!=="float32"&&t!=="float64"?"float64":t,c=S.zeros(e,s),l=c.data;if(u)if(a===0)for(let f=0;f<o;f++)l[f]=1/Number(n[f]);else for(let f=0;f<o;f++)l[f]=1/Number(n[a+f]);else for(let f=0;f<o;f++)l[f]=1/Number(r.iget(f));return c}function Vl(r){let t=r.dtype;L(t,"cbrt","cbrt is not supported for complex numbers.");let e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,i=t!=="float32"&&t!=="float64"?"float64":t,s=S.zeros(e,i),c=s.data;if(r.isCContiguous)for(let l=0;l<o;l++)c[l]=Math.cbrt(Number(n[a+l]));else for(let l=0;l<o;l++)c[l]=Math.cbrt(Number(r.iget(l)));return s}function Pl(r){let t=r.dtype;L(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=r.offset,u=t==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data;if(r.isCContiguous)if(a===0)for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[a+c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(r.iget(c)));return i}function jl(r,t){let e=li(r,t),n=qo(r,t);return[e,n]}function Ll(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),u=a.data;if(B(t)){let i=n,s=u;for(let c=0;c<o;c++){let l=i[c*2],f=i[c*2+1];s[c*2]=l*l-f*f,s[c*2+1]=2*l*f}}else if(O(t)){let i=n,s=u;for(let c=0;c<o;c++)s[c]=i[c]*i[c]}else for(let i=0;i<o;i++){let s=Number(n[i]);u[i]=s*s}return a}function Gl(r,t){return qo(r,t)}function Wl(r,t){L(r.dtype,"heaviside","Heaviside step function is not defined for complex numbers."),typeof t!="number"&&L(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=S.zeros(n,a),i=u.data;if(typeof t=="number")for(let s=0;s<o;s++){let c=Number(r.iget(s));c<0?i[s]=0:c===0?i[s]=t:i[s]=1}else{let s=t.shape;if(n.every((c,l)=>c===s[l]))for(let c=0;c<o;c++){let l=Number(r.iget(c));l<0?i[c]=0:l===0?i[c]=Number(t.iget(c)):i[c]=1}else for(let c=0;c<o;c++){let l=Number(r.iget(c)),f=c%t.size;l<0?i[c]=0:l===0?i[c]=Number(t.iget(f)):i[c]=1}}return u}function Yl(r,t){let e=r.dtype;if(B(e)){let n=r.size,o=S.zeros(Array.from(r.shape),e),a=o.data;if(typeof t=="number")if(r.isCContiguous){let u=r.data,i=r.offset;for(let s=0;s<n;s++){let c=u[(i+s)*2],l=u[(i+s)*2+1],f=Math.hypot(c,l),m=Math.atan2(l,c),p=Math.pow(f,t),y=m*t;a[s*2]=p*Math.cos(y),a[s*2+1]=p*Math.sin(y)}}else for(let u=0;u<n;u++){let i=r.iget(u),s=Math.hypot(i.re,i.im),c=Math.atan2(i.im,i.re),l=Math.pow(s,t),f=c*t;a[u*2]=l*Math.cos(f),a[u*2+1]=l*Math.sin(f)}else{let u=B(t.dtype);if(r.isCContiguous&&t.isCContiguous){let i=r.data,s=r.offset,c=t.data,l=t.offset;for(let f=0;f<n;f++){let m=i[(s+f)*2],p=i[(s+f)*2+1],y,d;if(u){let C=c;y=C[(l+f)*2],d=C[(l+f)*2+1]}else y=Number(c[l+f]),d=0;let b=Math.hypot(m,p),A=Math.atan2(p,m),g=Math.log(b),h=A,N=y*g-d*h,D=y*h+d*g,x=Math.exp(N);a[f*2]=x*Math.cos(D),a[f*2+1]=x*Math.sin(D)}}else for(let i=0;i<n;i++){let s=r.iget(i),c,l;if(u){let g=t.iget(i);c=g.re,l=g.im}else c=Number(t.iget(i)),l=0;let f=Math.hypot(s.re,s.im),m=Math.atan2(s.im,s.re),p=Math.log(f),y=m,d=c*p-l*y,b=c*y+l*p,A=Math.exp(d);a[i*2]=A*Math.cos(b),a[i*2+1]=A*Math.sin(b)}}return o}if(typeof t=="number"){let n=S.zeros(Array.from(r.shape),"float64"),o=n.data,a=r.size;if(r.isCContiguous){let u=r.data,i=r.offset;for(let s=0;s<a;s++)o[s]=Math.pow(Number(u[i+s]),t)}else for(let u=0;u<a;u++)o[u]=Math.pow(Number(r.iget(u)),t);return n}return sr(r,t,(n,o)=>Math.pow(n,o),"float_power")}function Zl(r,t){if(L(r.dtype,"fmod","fmod is not defined for complex numbers."),typeof t!="number"&&L(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 sr(r,t,(e,n)=>e-Math.trunc(e/n)*n,"fmod")}function Jl(r){L(r.dtype,"frexp","frexp is not defined for complex numbers.");let t=S.zeros(Array.from(r.shape),"float64"),e=S.zeros(Array.from(r.shape),"int32"),n=t.data,o=e.data,a=r.size;for(let u=0;u<a;u++){let i=Number(r.iget(u));if(i===0||!isFinite(i))n[u]=i,o[u]=0;else{let s=Math.floor(Math.log2(Math.abs(i)))+1,c=i/Math.pow(2,s);n[u]=c,o[u]=s}}return[t,e]}function Xl(r,t){L(r.dtype,"gcd","GCD is only defined for integers."),typeof t!="number"&&L(t.dtype,"gcd","GCD is only defined for integers.");let e=(i,s)=>{for(i=Math.abs(Math.trunc(i)),s=Math.abs(Math.trunc(s));s!==0;){let c=s;s=i%s,i=c}return i};if(typeof t=="number"){let i=S.zeros(Array.from(r.shape),"int32"),s=i.data,c=r.size,l=Math.abs(Math.trunc(t));if(r.isCContiguous){let f=r.data,m=r.offset;for(let p=0;p<c;p++)s[p]=e(Number(f[m+p]),l)}else for(let f=0;f<c;f++)s[f]=e(Number(r.iget(f)),l);return i}let n=sr(r,t,e,"gcd"),o=S.zeros(Array.from(n.shape),"int32"),a=o.data,u=n.size;if(n.isCContiguous){let i=n.data,s=n.offset;for(let c=0;c<u;c++)a[c]=Math.round(Number(i[s+c]))}else for(let i=0;i<u;i++)a[i]=Math.round(Number(n.iget(i)));return o}function Kl(r,t){L(r.dtype,"lcm","LCM is only defined for integers."),typeof t!="number"&&L(t.dtype,"lcm","LCM is only defined for integers.");let e=(s,c)=>{for(s=Math.abs(Math.trunc(s)),c=Math.abs(Math.trunc(c));c!==0;){let l=c;c=s%c,s=l}return s},n=(s,c)=>(s=Math.abs(Math.trunc(s)),c=Math.abs(Math.trunc(c)),s===0||c===0?0:s*c/e(s,c));if(typeof t=="number"){let s=S.zeros(Array.from(r.shape),"int32"),c=s.data,l=r.size,f=Math.abs(Math.trunc(t));if(r.isCContiguous){let m=r.data,p=r.offset;for(let y=0;y<l;y++)c[y]=n(Number(m[p+y]),f)}else for(let m=0;m<l;m++)c[m]=n(Number(r.iget(m)),f);return s}let o=sr(r,t,n,"lcm"),a=S.zeros(Array.from(o.shape),"int32"),u=a.data,i=o.size;if(o.isCContiguous){let s=o.data,c=o.offset;for(let l=0;l<i;l++)u[l]=Math.round(Number(s[c+l]))}else for(let s=0;s<i;s++)u[s]=Math.round(Number(o.iget(s)));return a}function Ql(r,t){if(L(r.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof t!="number"&&L(t.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof t=="number"){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=Math.pow(2,t);for(let u=0;u<o;u++)n[u]=Number(r.iget(u))*a;return e}return sr(r,t,(e,n)=>e*Math.pow(2,n),"ldexp")}function Hl(r){L(r.dtype,"modf","modf is not defined for complex numbers.");let t=S.zeros(Array.from(r.shape),"float64"),e=S.zeros(Array.from(r.shape),"float64"),n=t.data,o=e.data,a=r.size;for(let u=0;u<a;u++){let i=Number(r.iget(u)),s=Math.trunc(i);o[u]=s,n[u]=i-s}return[t,e]}function rf(r,t,e){L(r.dtype,"clip","clip is not supported for complex numbers.");let n=r.dtype,o=Array.from(r.shape),a=r.size,u=S.zeros(o,n),i=u.data,s=t===null||typeof t=="number",c=e===null||typeof e=="number",l=t===null?-1/0:typeof t=="number"?t:null,f=e===null?1/0:typeof e=="number"?e:null,m=r.isCContiguous,p=r.data,y=r.offset,d=!s&&t.isCContiguous,b=s?null:t.data,A=s?0:t.offset,g=s?0:t.size,h=!c&&e.isCContiguous,N=c?null:e.data,D=c?0:e.offset,x=c?0:e.size;if(O(n)){let C=i;if(m&&(s||d)&&(c||h)){let w=p,_=b,I=N;for(let v=0;v<a;v++){let T=w[y+v],E=s?l===-1/0?T:BigInt(Math.round(l)):_[A+v%g],$=c?f===1/0?T:BigInt(Math.round(f)):I[D+v%x];T<E&&(T=E),T>$&&(T=$),C[v]=T}}else for(let w=0;w<a;w++){let _=r.iget(w),I=s?l===-1/0?_:BigInt(Math.round(l)):t.iget(w%t.size),v=c?f===1/0?_:BigInt(Math.round(f)):e.iget(w%e.size);_<I&&(_=I),_>v&&(_=v),C[w]=_}}else if(m&&(s||d)&&(c||h))for(let C=0;C<a;C++){let w=Number(p[y+C]),_=s?l:Number(b[A+C%g]),I=c?f:Number(N[D+C%x]);w<_&&(w=_),w>I&&(w=I),i[C]=w}else for(let C=0;C<a;C++){let w=Number(r.iget(C)),_=s?l:Number(t.iget(C%t.size)),I=c?f:Number(e.iget(C%e.size));w<_&&(w=_),w>I&&(w=I),i[C]=w}return u}function tf(r,t){if(L(r.dtype,"maximum","maximum is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"maximum","maximum is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]>l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);u[s]=isNaN(c)||isNaN(t)?NaN:Math.max(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)||isNaN(n)?NaN:Math.max(e,n),"maximum")}function ef(r,t){if(L(r.dtype,"minimum","minimum is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"minimum","minimum is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]<l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);u[s]=isNaN(c)||isNaN(t)?NaN:Math.min(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)||isNaN(n)?NaN:Math.min(e,n),"minimum")}function nf(r,t){if(L(r.dtype,"fmax","fmax is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"fmax","fmax is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]>l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);isNaN(c)?u[s]=t:isNaN(t)?u[s]=c:u[s]=Math.max(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)?n:isNaN(n)?e:Math.max(e,n),"fmax")}function of(r,t){if(L(r.dtype,"fmin","fmin is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"fmin","fmin is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]<l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);isNaN(c)?u[s]=t:isNaN(t)?u[s]=c:u[s]=Math.min(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)?n:isNaN(n)?e:Math.min(e,n),"fmin")}function af(r,t=0,e,n){L(r.dtype,"nan_to_num","nan_to_num is not supported for complex numbers.");let o=r.dtype,a=Array.from(r.shape),u=r.size,i=e!==void 0?e:Number.MAX_VALUE,s=n!==void 0?n:-Number.MAX_VALUE,c=S.zeros(a,o),l=c.data,f=r.data;if(O(o)){let m=l,p=f;for(let y=0;y<u;y++)m[y]=p[y]}else for(let m=0;m<u;m++){let p=Number(f[m]);isNaN(p)?l[m]=t:p===1/0?l[m]=i:p===-1/0?l[m]=s:l[m]=p}return c}function sf(r,t,e,n,o){L(r.dtype,"interp","interp is not supported for complex numbers."),L(t.dtype,"interp","interp is not supported for complex numbers."),L(e.dtype,"interp","interp is not supported for complex numbers.");let a=Array.from(r.shape),u=r.size,i=S.zeros(a,"float64"),s=i.data,c=r.data,l=t.data,f=e.data,m=t.size,p=n!==void 0?n:Number(f[0]),y=o!==void 0?o:Number(f[m-1]);for(let d=0;d<u;d++){let b=Number(c[d]);if(b<=Number(l[0])){s[d]=p;continue}if(b>=Number(l[m-1])){s[d]=y;continue}let A=0,g=m-1;for(;g-A>1;){let w=Math.floor((A+g)/2);Number(l[w])<=b?A=w:g=w}let h=Number(l[A]),N=Number(l[g]),D=Number(f[A]),x=Number(f[g]),C=(b-h)/(N-h);s[d]=D+C*(x-D)}return i}function uf(r,t=Math.PI,e=-1,n=2*Math.PI){L(r.dtype,"unwrap","unwrap is not supported for complex numbers.");let o=Array.from(r.shape),a=o.length;if(e<0&&(e+=a),e<0||e>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);if(a===1){let c=r.size,l=S.zeros(o,"float64"),f=l.data,m=r.data;if(c===0)return l;f[0]=Number(m[0]);let p=0;for(let y=1;y<c;y++){let d=Number(m[y-1]),b=Number(m[y]),A=b-d;A=(A+n/2)%n-n/2,A===-n/2&&b-d>0&&(A=n/2),Math.abs(A)>t&&(p-=Math.round((b-d-A)/n)*n),f[y]=b+p}return l}let u=S.zeros(o,"float64"),i=u.data,s=r.data;for(let c=0;c<r.size;c++)i[c]=Number(s[c]);if(a===2){let[c,l]=o;if(e===0)for(let f=0;f<l;f++){let m=0;for(let p=1;p<c;p++){let y=(p-1)*l+f,d=p*l+f,b=i[y],A=i[d],g=A-b;g=(g+n/2)%n-n/2,g===-n/2&&A-b>0&&(g=n/2),Math.abs(g)>t&&(m-=Math.round((A-b-g)/n)*n),i[d]=A+m}}else for(let f=0;f<c;f++){let m=0;for(let p=1;p<l;p++){let y=f*l+(p-1),d=f*l+p,b=i[y],A=i[d],g=A-b;g=(g+n/2)%n-n/2,g===-n/2&&A-b>0&&(g=n/2),Math.abs(g)>t&&(m-=Math.round((A-b-g)/n)*n),i[d]=A+m}}}return u}function cf(r){L(r.dtype,"sinc","sinc is not supported for complex numbers.");let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"float64"),o=n.data,a=r.data;for(let u=0;u<e;u++){let i=Number(a[u]);if(i===0)o[u]=1;else{let s=Math.PI*i;o[u]=Math.sin(s)/s}}return n}function lf(r){L(r.dtype,"i0","i0 is not supported for complex numbers.");let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"float64"),o=n.data,a=r.data;for(let u=0;u<e;u++){let i=Math.abs(Number(a[u]));o[u]=rD(i)}return n}function rD(r){let t=Math.abs(r);if(t<3.75){let e=r/3.75,n=e*e;return 1+n*(3.5156229+n*(3.0899424+n*(1.2067492+n*(.2659732+n*(.0360768+n*.0045813)))))}else{let e=3.75/t;return Math.exp(t)/Math.sqrt(t)*(.39894228+e*(.01328592+e*(.00225319+e*(-.00157565+e*(.00916281+e*(-.02057706+e*(.02635537+e*(-.01647633+e*.00392377))))))))}}function ff(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.sqrt(l*l+f*f),p=Math.sqrt((m+l)/2),y=(f>=0?1:-1)*Math.sqrt((m-l)/2);u[c*2]=p,u[c*2+1]=y}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.sqrt(c*c+l*l),m=Math.sqrt((f+c)/2),p=(l>=0?1:-1)*Math.sqrt((f-c)/2);u[i*2]=m,u[i*2+1]=p}return a}return ir(r,Math.sqrt,!1)}function mf(r,t){if(typeof t=="number")return nD(r,t);let e=B(r.dtype),n=B(t.dtype);return e||n?eD(r,t):sr(r,t,Math.pow,"power")}function eD(r,t){let e=B(r.dtype),n=B(t.dtype),o=r.dtype==="complex128"||t.dtype==="complex128"||t.dtype==="float64"?"complex128":"complex64",a=Array.from(r.shape),u=r.size,i=S.zeros(a,o),s=i.data,c=r.isCContiguous,l=t.isCContiguous,f=r.offset,m=t.offset;for(let p=0;p<u;p++){let y,d;if(e)if(c){let w=r.data;y=w[(f+p)*2],d=w[(f+p)*2+1]}else{let w=r.iget(p);y=w.re,d=w.im}else y=Number(r.iget(p)),d=0;let b,A;if(n)if(l){let w=t.data;b=w[(m+p)*2],A=w[(m+p)*2+1]}else{let w=t.iget(p);b=w.re,A=w.im}else b=Number(t.iget(p)),A=0;let g=Math.sqrt(y*y+d*d),h=Math.atan2(d,y),N=Math.log(g),D=b*N-A*h,x=b*h+A*N,C=Math.exp(D);s[p*2]=C*Math.cos(x),s[p*2+1]=C*Math.sin(x)}return i}function nD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous;if(B(e)){let p=S.zeros(n,e),y=p.data;if(i){let d=o;for(let b=0;b<a;b++){let A=d[(u+b)*2],g=d[(u+b)*2+1],h=Math.sqrt(A*A+g*g),N=Math.atan2(g,A),D=Math.pow(h,t),x=N*t;y[b*2]=D*Math.cos(x),y[b*2+1]=D*Math.sin(x)}}else for(let d=0;d<a;d++){let b=r.iget(d),A=b.re,g=b.im,h=Math.sqrt(A*A+g*g),N=Math.atan2(g,A),D=Math.pow(h,t),x=N*t;y[d*2]=D*Math.cos(x),y[d*2+1]=D*Math.sin(x)}return p}let l=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,f=S.zeros(n,l),m=f.data;if(O(e))if(O(l)&&Number.isInteger(t)&&t>=0)if(i){let p=o,y=m;for(let d=0;d<a;d++)y[d]=p[u+d]**BigInt(t)}else{let p=m;for(let y=0;y<a;y++)p[y]=r.iget(y)**BigInt(t)}else if(i)for(let p=0;p<a;p++)m[p]=Math.pow(Number(o[u+p]),t);else for(let p=0;p<a;p++)m[p]=Math.pow(Number(r.iget(p)),t);else if(i)for(let p=0;p<a;p++)m[p]=Math.pow(Number(o[u+p]),t);else for(let p=0;p<a;p++)m[p]=Math.pow(Number(r.iget(p)),t);return f}function pf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.exp(l);u[c*2]=m*Math.cos(f),u[c*2+1]=m*Math.sin(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.exp(c);u[i*2]=f*Math.cos(l),u[i*2+1]=f*Math.sin(l)}return a}return ir(r,Math.exp,!1)}function yf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=Math.LN2,u=S.zeros(e,t),i=u.data;if(o){let s=r.data,c=r.offset;for(let l=0;l<n;l++){let f=s[(c+l)*2],m=s[(c+l)*2+1],p=Math.exp(f*a),y=m*a;i[l*2]=p*Math.cos(y),i[l*2+1]=p*Math.sin(y)}}else for(let s=0;s<n;s++){let c=r.iget(s),l=c.re,f=c.im,m=Math.exp(l*a),p=f*a;i[s*2]=m*Math.cos(p),i[s*2+1]=m*Math.sin(p)}return u}return ir(r,e=>Math.pow(2,e),!1)}function df(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.exp(l);u[c*2]=m*Math.cos(f)-1,u[c*2+1]=m*Math.sin(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.exp(c);u[i*2]=f*Math.cos(l)-1,u[i*2+1]=f*Math.sin(l)}return a}return ir(r,Math.expm1,!1)}function bf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.sqrt(l*l+f*f),p=Math.atan2(f,l);u[c*2]=Math.log(m),u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.sqrt(c*c+l*l),m=Math.atan2(l,c);u[i*2]=Math.log(f),u[i*2+1]=m}return a}return ir(r,Math.log,!1)}function Af(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=1/Math.LN2,u=S.zeros(e,t),i=u.data;if(o){let s=r.data,c=r.offset;for(let l=0;l<n;l++){let f=s[(c+l)*2],m=s[(c+l)*2+1],p=Math.sqrt(f*f+m*m),y=Math.atan2(m,f);i[l*2]=Math.log(p)*a,i[l*2+1]=y*a}}else for(let s=0;s<n;s++){let c=r.iget(s),l=c.re,f=c.im,m=Math.sqrt(l*l+f*f),p=Math.atan2(f,l);i[s*2]=Math.log(m)*a,i[s*2+1]=p*a}return u}return ir(r,Math.log2,!1)}function gf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=1/Math.LN10,u=S.zeros(e,t),i=u.data;if(o){let s=r.data,c=r.offset;for(let l=0;l<n;l++){let f=s[(c+l)*2],m=s[(c+l)*2+1],p=Math.sqrt(f*f+m*m),y=Math.atan2(m,f);i[l*2]=Math.log(p)*a,i[l*2+1]=y*a}}else for(let s=0;s<n;s++){let c=r.iget(s),l=c.re,f=c.im,m=Math.sqrt(l*l+f*f),p=Math.atan2(f,l);i[s*2]=Math.log(m)*a,i[s*2+1]=p*a}return u}return ir(r,Math.log10,!1)}function hf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=1+l,p=Math.sqrt(m*m+f*f),y=Math.atan2(f,m);u[c*2]=Math.log(p),u[c*2+1]=y}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=1+c,m=Math.sqrt(f*f+l*l),p=Math.atan2(l,f);u[i*2]=Math.log(m),u[i*2+1]=p}return a}return ir(r,Math.log1p,!1)}function Nf(r,t){return L(r.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof t=="number"?aD(r,t):oD(r,t)}function oD(r,t){let e=Zr(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",i=S.zeros(e,u),s=i.data;for(let c=0;c<n;c++){let l=(O(o),Number(r.iget(c))),f=(O(a),Number(t.iget(c))),m=Math.max(l,f),p=Math.min(l,f);s[c]=m+Math.log1p(Math.exp(p-m))}return i}function aD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=r.isCContiguous,u=e==="float32"?"float32":"float64",i=S.zeros(n,u),s=i.data;if(a){let c=r.offset;for(let l=0;l<o;l++){let f=Number(r.data[c+l]),m=Math.max(f,t),p=Math.min(f,t);s[l]=m+Math.log1p(Math.exp(p-m))}}else for(let c=0;c<o;c++){let l=Number(r.iget(c)),f=Math.max(l,t),m=Math.min(l,t);s[c]=f+Math.log1p(Math.exp(m-f))}return i}function Df(r,t){return L(r.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof t=="number"?iD(r,t):sD(r,t)}function sD(r,t){let e=Zr(r.shape,t.shape),n=e.reduce((l,f)=>l*f,1),o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data,c=Math.LOG2E;for(let l=0;l<n;l++){let f=(O(o),Number(r.iget(l))),m=(O(a),Number(t.iget(l))),p=Math.max(f,m),y=Math.min(f,m);s[l]=p+Math.log1p(Math.pow(2,y-p))*c}return i}function iD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=r.isCContiguous,u=e==="float32"?"float32":"float64",i=S.zeros(n,u),s=i.data,c=Math.LOG2E;if(a){let l=r.offset;for(let f=0;f<o;f++){let m=Number(r.data[l+f]),p=Math.max(m,t),y=Math.min(m,t);s[f]=p+Math.log1p(Math.pow(2,y-p))*c}}else for(let l=0;l<o;l++){let f=Number(r.iget(l)),m=Math.max(f,t),p=Math.min(f,t);s[l]=m+Math.log1p(Math.pow(2,p-m))*c}return i}function kt(r,t){let e=typeof t=="number"?t:z(t);return M(Bl(z(r),e))}function Rt(r,t){let e=typeof t=="number"?t:z(t);return M(Tl(z(r),e))}function qt(r,t){let e=typeof t=="number"?t:z(t);return M(Ol(z(r),e))}function Vt(r){return M(ff(z(r)))}function Pt(r,t){let e=typeof t=="number"?t:z(t);return M(mf(z(r),e))}function jt(r){return M(pf(z(r)))}function Lt(r){return M(yf(z(r)))}function Gt(r){return M(df(z(r)))}function Wt(r){return M(bf(z(r)))}function Yt(r){return M(Af(z(r)))}function Zt(r){return M(gf(z(r)))}function Jt(r){return M(hf(z(r)))}function Xt(r,t){let e=typeof t=="number"?t:z(t);return M(Nf(z(r),e))}function Kt(r,t){let e=typeof t=="number"?t:z(t);return M(Df(z(r),e))}function Qt(r){return M(Ul(z(r)))}function Ht(r){return M($l(z(r)))}function re(r){return M(kl(z(r)))}function te(r,t){let e=typeof t=="number"?t:z(t);return M(qo(z(r),e))}function pt(r,t){let e=typeof t=="number"?t:z(t);return M(El(z(r),e))}var Vo=pt;function ee(r,t){let e=typeof t=="number"?t:z(t);return M(li(z(r),e))}function ne(r){return M(Rl(z(r)))}function oe(r){return M(ql(z(r)))}function ae(r){return M(Vl(z(r)))}function se(r){return M(Pl(z(r)))}function ie(r,t){let e=typeof t=="number"?t:z(t);return To(jl(z(r),e))}function ue(r){return M(Ll(z(r)))}function ce(r,t){let e=typeof t=="number"?t:z(t);return M(Gl(z(r),e))}function le(r,t){let e=typeof t=="number"?t:z(t);return M(Wl(z(r),e))}function fi(r,t){let e=typeof t=="number"?t:z(t);return M(Yl(z(r),e))}function mi(r,t){let e=typeof t=="number"?t:z(t);return M(Zl(z(r),e))}function pi(r){return To(Jl(z(r)))}function yi(r,t){let e=typeof t=="number"?t:z(t);return M(Xl(z(r),e))}function di(r,t){let e=typeof t=="number"?t:z(t);return M(Kl(z(r),e))}function bi(r,t){let e=typeof t=="number"?t:z(t);return M(Ql(z(r),e))}function Ai(r){return To(Hl(z(r)))}function fe(r,t,e){let n=t===null?null:typeof t=="number"?t:z(t),o=e===null?null:typeof e=="number"?e:z(e);return M(rf(z(r),n,o))}function gi(r,t){let e=typeof t=="number"?t:z(t);return M(tf(z(r),e))}function hi(r,t){let e=typeof t=="number"?t:z(t);return M(ef(z(r),e))}function Ni(r,t){let e=typeof t=="number"?t:z(t);return M(nf(z(r),e))}function Di(r,t){let e=typeof t=="number"?t:z(t);return M(of(z(r),e))}function xi(r,t=0,e,n){return M(af(z(r),t,e,n))}function Ci(r,t,e,n,o){return M(sf(z(r),z(t),z(e),n,o))}function Si(r,t=Math.PI,e=-1,n=2*Math.PI){return M(uf(z(r),t,e,n))}function wi(r){return M(cf(z(r)))}function Ii(r){return M(lf(z(r)))}function wf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1];u[c*2]=Math.sin(l)*Math.cosh(f),u[c*2+1]=Math.cos(l)*Math.sinh(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im;u[i*2]=Math.sin(c)*Math.cosh(l),u[i*2+1]=Math.cos(c)*Math.sinh(l)}return a}return ir(r,Math.sin,!1)}function If(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1];u[c*2]=Math.cos(l)*Math.cosh(f),u[c*2+1]=-Math.sin(l)*Math.sinh(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im;u[i*2]=Math.cos(c)*Math.cosh(l),u[i*2+1]=-Math.sin(c)*Math.sinh(l)}return a}return ir(r,Math.cos,!1)}function zf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.cos(2*l)+Math.cosh(2*f);u[c*2]=Math.sin(2*l)/m,u[c*2+1]=Math.sinh(2*f)/m}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.cos(2*c)+Math.cosh(2*l);u[i*2]=Math.sin(2*c)/f,u[i*2+1]=Math.sinh(2*l)/f}return a}return ir(r,Math.tan,!1)}function _f(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],[m,p]=xf(l,f);u[c*2]=m,u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),[c,l]=xf(s.re,s.im);u[i*2]=c,u[i*2+1]=l}return a}return ir(r,Math.asin,!1)}function xf(r,t){let e=-t,n=r,o=r*r-t*t,a=2*r*t,u=1-o,i=-a,s=Math.sqrt(u*u+i*i),c=Math.sqrt((s+u)/2),l=(i>=0?1:-1)*Math.sqrt((s-u)/2),f=e+c,m=n+l,p=Math.sqrt(f*f+m*m),y=Math.log(p),b=Math.atan2(m,f),A=-y;return Math.abs(t)<1e-15&&r>1&&(A=-A),[b,A]}function vf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],[m,p]=Cf(l,f);u[c*2]=m,u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),[c,l]=Cf(s.re,s.im);u[i*2]=c,u[i*2+1]=l}return a}return ir(r,Math.acos,!1)}function Cf(r,t){let e=r*r-t*t,n=2*r*t,o=1-e,a=-n,u=Math.sqrt(o*o+a*a),i=Math.sqrt((u+o)/2),c=-((a>=0?1:-1)*Math.sqrt((u-o)/2)),l=i,f=r+c,m=t+l,p=Math.sqrt(f*f+m*m),y=Math.log(p),b=Math.atan2(m,f),A=-y;return Math.abs(t)<1e-15&&r>1&&(A=-A),[b,A]}function Mf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],[m,p]=Sf(l,f);u[c*2]=m,u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),[c,l]=Sf(s.re,s.im);u[i*2]=c,u[i*2+1]=l}return a}return ir(r,Math.atan,!1)}function Sf(r,t){let e=-t,n=r,o=1-e,a=-n,u=1+e,i=n,s=u*u+i*i,c=(o*u+a*i)/s,l=(a*u-o*i)/s,f=Math.sqrt(c*c+l*l),m=Math.log(f);return[-Math.atan2(l,c)/2,m/2]}function Ff(r,t){return L(r.dtype,"arctan2","arctan2 is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"arctan2","arctan2 is only defined for real numbers."),typeof t=="number"?lD(r,t):cD(r,t)}function cD(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data,c=r.isCContiguous,l=t.isCContiguous;if(c&&l){let f=r.offset,m=t.offset;for(let p=0;p<n;p++){let y=Number(r.data[f+p]),d=Number(t.data[m+p]);s[p]=Math.atan2(y,d)}}else if(c){let f=r.offset;for(let m=0;m<n;m++){let p=Number(r.data[f+m]),y=Number(t.iget(m));s[m]=Math.atan2(p,y)}}else if(l){let f=t.offset;for(let m=0;m<n;m++){let p=Number(r.iget(m)),y=Number(t.data[f+m]);s[m]=Math.atan2(p,y)}}else for(let f=0;f<n;f++){let m=Number(r.iget(f)),p=Number(t.iget(f));s[f]=Math.atan2(m,p)}return i}function lD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=S.zeros(n,a),i=u.data;if(r.isCContiguous){let c=r.data,l=r.offset;if(O(e))for(let f=0;f<o;f++)i[f]=Math.atan2(Number(c[l+f]),t);else for(let f=0;f<o;f++)i[f]=Math.atan2(Number(c[l+f]),t)}else for(let c=0;c<o;c++)i[c]=Math.atan2(Number(r.iget(c)),t);return u}function Bf(r,t){return L(r.dtype,"hypot","hypot is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"hypot","hypot is only defined for real numbers."),typeof t=="number"?mD(r,t):fD(r,t)}function fD(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data,c=r.isCContiguous,l=t.isCContiguous;if(c&&l){let f=r.offset,m=t.offset;for(let p=0;p<n;p++){let y=Number(r.data[f+p]),d=Number(t.data[m+p]);s[p]=Math.hypot(y,d)}}else if(c){let f=r.offset;for(let m=0;m<n;m++){let p=Number(r.data[f+m]),y=Number(t.iget(m));s[m]=Math.hypot(p,y)}}else if(l){let f=t.offset;for(let m=0;m<n;m++){let p=Number(r.iget(m)),y=Number(t.data[f+m]);s[m]=Math.hypot(p,y)}}else for(let f=0;f<n;f++){let m=Number(r.iget(f)),p=Number(t.iget(f));s[f]=Math.hypot(m,p)}return i}function mD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=S.zeros(n,a),i=u.data;if(r.isCContiguous){let c=r.data,l=r.offset;if(O(e))for(let f=0;f<o;f++)i[f]=Math.hypot(Number(c[l+f]),t);else for(let f=0;f<o;f++)i[f]=Math.hypot(Number(c[l+f]),t)}else for(let c=0;c<o;c++)i[c]=Math.hypot(Number(r.iget(c)),t);return u}function zi(r){L(r.dtype,"degrees","degrees is only defined for real numbers.");let t=180/Math.PI;return ir(r,e=>e*t,!1)}function _i(r){L(r.dtype,"radians","radians is only defined for real numbers.");let t=Math.PI/180;return ir(r,e=>e*t,!1)}function Tf(r){return _i(r)}function Of(r){return zi(r)}function Ef(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1];u[i*2]=Math.sinh(s)*Math.cos(c),u[i*2+1]=Math.cosh(s)*Math.sin(c)}return a}return ir(r,Math.sinh,!1)}function Uf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1];u[i*2]=Math.cosh(s)*Math.cos(c),u[i*2+1]=Math.sinh(s)*Math.sin(c)}return a}return ir(r,Math.cosh,!1)}function $f(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=Math.cosh(2*s)+Math.cos(2*c);u[i*2]=Math.sinh(2*s)/l,u[i*2+1]=Math.sin(2*c)/l}return a}return ir(r,Math.tanh,!1)}function kf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=s*s-c*c,f=2*s*c,m=l+1,p=f,y=Math.sqrt(m*m+p*p),d=Math.sqrt((y+m)/2),b=(p>=0?1:-1)*Math.sqrt((y-m)/2),A=s+d,g=c+b,h=Math.sqrt(A*A+g*g);u[i*2]=Math.log(h),u[i*2+1]=Math.atan2(g,A)}return a}return ir(r,Math.asinh,!1)}function Rf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=s*s-c*c,f=2*s*c,m=l-1,p=f,y=Math.sqrt(m*m+p*p),d=Math.sqrt((y+m)/2),b=(p>=0?1:-1)*Math.sqrt((y-m)/2),A=s+d,g=c+b,h=Math.sqrt(A*A+g*g),N=Math.log(h),D=Math.atan2(g,A);Math.abs(c)<1e-15&&s<1&&(D=-D),u[i*2]=N,u[i*2+1]=D}return a}return ir(r,Math.acosh,!1)}function qf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=1+s,f=c,m=1-s,p=-c,y=m*m+p*p,d=(l*m+f*p)/y,b=(f*m-l*p)/y,A=Math.sqrt(d*d+b*b),g=Math.log(A),h=Math.atan2(b,d);u[i*2]=g/2,u[i*2+1]=h/2}return a}return ir(r,Math.atanh,!1)}function me(r){return M(wf(z(r)))}function pe(r){return M(If(z(r)))}function ye(r){return M(zf(z(r)))}function de(r){return M(_f(z(r)))}function be(r){return M(vf(z(r)))}function Ae(r){return M(Mf(z(r)))}function ge(r,t){let e=typeof t=="number"?t:z(t);return M(Ff(z(r),e))}function he(r,t){let e=typeof t=="number"?t:z(t);return M(Bf(z(r),e))}function Ne(r){return M(zi(z(r)))}function De(r){return M(_i(z(r)))}function vi(r){return M(Tf(z(r)))}function Mi(r){return M(Of(z(r)))}function xe(r){return M(Ef(z(r)))}function Ce(r){return M(Uf(z(r)))}function Se(r){return M($f(z(r)))}function we(r){return M(kf(z(r)))}function Ie(r){return M(Rf(z(r)))}function ze(r){return M(qf(z(r)))}function ur(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((f,m,p)=>p===o?f:f*m,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((f,m)=>m===o?l:f)}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 S.fromData(c,a,n,lr(a),0)}let s=r.copy().data;return S.fromData(s,a,n,lr(a),0)}function Hr(r){let t=r.size,e=r.dtype,n=K(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let i=r.data.slice(r.offset,r.offset+t);return S.fromData(i,[t],e,[1],0)}let o=new n(t),a=O(e);for(let u=0;u<t;u++){let i=r.iget(u);o[u]=i}return S.fromData(o,[t],e,[1],0)}function yt(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return S.fromData(n,[t],e,[1],0)}return Hr(r)}function Fi(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype,i;if(t===void 0)i=Array.from({length:n},(f,m)=>n-1-m);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let f=new Set;for(let m of t){let p=m<0?n+m:m;if(p<0||p>=n)throw new Error(`axis ${m} is out of bounds for array of dimension ${n}`);if(f.has(p))throw new Error("repeated axis in transpose");f.add(p)}i=t.map(m=>m<0?n+m:m)}let s=i.map(f=>e[f]),c=Array.from(o),l=i.map(f=>c[f]);return S.fromData(a,s,u,l,r.offset)}function Bi(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype;if(t===void 0){let i=[],s=[];for(let c=0;c<n;c++)e[c]!==1&&(i.push(e[c]),s.push(o[c]));return i.length===0&&(i.push(1),s.push(1)),S.fromData(a,i,u,s,r.offset)}else{let i=t<0?n+t:t;if(i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[i]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[i]})`);let s=[],c=[];for(let l=0;l<n;l++)l!==i&&(s.push(e[l]),c.push(o[l]));return S.fromData(a,s,u,c,r.offset)}}function _e(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype,i=t;if(i<0&&(i=n+t+1),i<0||i>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let s=[...Array.from(e)];s.splice(i,0,1);let c=[...Array.from(o)],l=i<n?o[i]*(e[i]||1):1;return c.splice(i,0,l),S.fromData(a,s,u,c,r.offset)}function Vf(r,t,e){let n=r.shape,o=n.length,a=r.strides,u=r.data,i=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 S.fromData(u,Array.from(n),i,Array.from(a),r.offset);let l=Array.from(n),f=Array.from(a);return[l[s],l[c]]=[l[c],l[s]],[f[s],f[c]]=[f[c],f[s]],S.fromData(u,l,i,f,r.offset)}function Ti(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}),i=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(i).size!==i.length)throw new Error("repeated axis in destination");let s=[];for(let c=0;c<n;c++)u.includes(c)||s.push(c);for(let c=0;c<u.length;c++){let l=i[c];s.splice(l,0,u[c])}return Fi(r,s)}function Jr(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 u=Array.from(e.shape),i=e.shape[a];for(let p=1;p<r.length;p++)i+=r[p].shape[a];u[a]=i;let s=u.reduce((p,y)=>p*y,1),c=K(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(s),f=lr(u),m=0;for(let p of r){let y=p.shape[a];dD(p,l,u,f,a,m,o),m+=y}return S.fromData(l,u,o)}function dD(r,t,e,n,o,a,u){let i=r.shape,s=i.length,c=r.size,l=u==="int64"||u==="uint64";if(o===0&&r.isCContiguous&&s>0){let p=a*n[0],y=r.data,d=r.offset,b=d+c;t.set(y.subarray(d,b),p);return}if(o===1&&s===2&&r.isCContiguous){let p=i[0],y=i[1],d=e[1],b=r.data,A=r.offset;for(let g=0;g<p;g++){let h=A+g*y,N=g*d+a;t.set(b.subarray(h,h+y),N)}return}let f=new Array(s).fill(0),m=a*n[o];for(let p=0;p<c;p++){let y=r.iget(p),d=m;for(let b=0;b<s;b++)d+=f[b]*n[b];t[d]=y;for(let b=s-1;b>=0&&(f[b]++,!(f[b]<i[b]));b--)f[b]=0}}function Pf(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 i=1;i<r.length;i++){let s=r[i];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 u=r.map(i=>_e(i,a));return Jr(u,a)}function jf(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?ur(e,[1,e.shape[0]]):e);return Jr(t,0)}function Oi(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?Jr(r,0):Jr(r,1)}function Lf(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?ur(_e(ur(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?_e(e,2):e);return Jr(t,2)}function Gf(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],i;if(typeof t=="number"){if(u%t!==0)throw new Error("array split does not result in an equal division");let s=u/t;i=[];for(let c=1;c<t;c++)i.push(c*s)}else i=t;return Wf(r,i,a)}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 u=n[a],i;if(typeof t=="number"){let s=t,c=Math.floor(u/s),l=u%s;i=[];let f=0;for(let m=0;m<s-1;m++)f+=c+(m<l?1:0),i.push(f)}else i=t;return Wf(r,i,a)}function Wf(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],u=[];for(let i=0;i<a.length-1;i++){let s=a[i],c=a[i+1];if(s>c)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=c-s;let f=r.offset+s*r.strides[e];u.push(S.fromData(r.data,l,r.dtype,Array.from(r.strides),f))}return u}function Yf(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return ve(r,t,0)}function Zf(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 ve(r,t,e)}function Jf(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],u=Math.max(n,a.length),i=new Array(u).fill(1),s=new Array(u).fill(1);for(let g=0;g<n;g++)i[u-n+g]=e[g];for(let g=0;g<a.length;g++)s[u-a.length+g]=a[g];let c=i.map((g,h)=>g*s[h]),l=c.reduce((g,h)=>g*h,1),f=K(o);if(!f)throw new Error(`Cannot tile array with dtype ${o}`);let m=new f(l),p=lr(c),y=r;n<u&&(y=ur(r,i));let d=o==="int64"||o==="uint64",b=y.strides,A=new Array(u).fill(0);for(let g=0;g<l;g++){let h=y.offset;for(let x=0;x<u;x++){let C=A[x]%i[x];h+=C*b[x]}let N=y.data[h],D=0;for(let x=0;x<u;x++)D+=A[x]*p[x];m[D]=N;for(let x=u-1;x>=0&&(A[x]++,!(A[x]<c[x]));x--)A[x]=0}return S.fromData(m,c,o)}function Xf(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=r.size;if(e===void 0){let g=u,h=Array.isArray(t)?t:new Array(g).fill(t);if(h.length!==g)throw new Error(`operands could not be broadcast together with shape (${g},) (${h.length},)`);let N=h.reduce((w,_)=>w+_,0),D=K(a);if(!D)throw new Error(`Cannot repeat array with dtype ${a}`);let x=new D(N),C=0;for(let w=0;w<g;w++){let _=r.iget(w),I=h[w];for(let v=0;v<I;v++)x[C++]=_}return S.fromData(x,[N],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 s=n[i],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[i]=c.reduce((g,h)=>g+h,0);let f=l.reduce((g,h)=>g*h,1),m=K(a);if(!m)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new m(f),y=lr(l),d=new Array(o).fill(0),b=a==="int64"||a==="uint64",A=[0];for(let g=0;g<s;g++)A.push(A[g]+c[g]);for(let g=0;g<u;g++){let h=r.iget(g),N=d[i],D=c[N],x=0;for(let _=0;_<o;_++)_!==i&&(x+=d[_]*y[_]);let C=y[i],w=A[N];for(let _=0;_<D;_++){let I=x+(w+_)*C;p[I]=h}for(let _=o-1;_>=0&&(d[_]++,!(d[_]<n[_]));_--)d[_]=0}return S.fromData(p,l,a)}function Kf(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},(m,p)=>p));else if(typeof t=="number"){let m=t<0?n+t:t;if(m<0||m>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);u=new Set([m])}else u=new Set(t.map(m=>{let p=m<0?n+m:m;if(p<0||p>=n)throw new Error(`axis ${m} is out of bounds for array of dimension ${n}`);return p}));let i=K(o);if(!i)throw new Error(`Cannot flip array with dtype ${o}`);let s=new i(a),c=O(o);if(n===1&&r.isCContiguous){let m=r.data,p=r.offset;for(let y=0;y<a;y++)s[y]=m[p+a-1-y];return S.fromData(s,[...e],o)}if(n===2&&r.isCContiguous){let m=e[0],p=e[1],y=r.data,d=r.offset;if(u.size===2){for(let b=0;b<a;b++)s[b]=y[d+a-1-b];return S.fromData(s,[...e],o)}if(u.size===1){if(u.has(0)){for(let b=0;b<m;b++){let A=d+(m-1-b)*p,g=b*p;for(let h=0;h<p;h++)s[g+h]=y[A+h]}return S.fromData(s,[...e],o)}else if(u.has(1)){for(let b=0;b<m;b++){let A=d+b*p,g=b*p;for(let h=0;h<p;h++)s[g+h]=y[A+p-1-h]}return S.fromData(s,[...e],o)}}}let l=new Array(n),f=new Array(n).fill(0);for(let m=0;m<a;m++){for(let d=0;d<n;d++)l[d]=u.has(d)?e[d]-1-f[d]:f[d];let p=r.offset;for(let d=0;d<n;d++)p+=l[d]*r.strides[d];let y=r.data[p];s[m]=y;for(let d=n-1;d>=0&&(f[d]++,!(f[d]<e[d]));d--)f[d]=0}return S.fromData(s,[...e],o)}function Qf(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],i=e[1]<0?o+e[1]:e[1];if(u<0||u>=o||i<0||i>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(u===i)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let s=K(a);if(!s)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[u],c[i]]=[c[i],c[u]]);let l=c.reduce((g,h)=>g*h,1),f=new s(l),m=O(a),p=r.data;if(o===2&&u===0&&i===1){let g=n[0],h=n[1];if(t===1){let N=h,D=g;if(m){let x=p,C=f;for(let w=0;w<N;w++){let _=w*D,I=h-1-w;for(let v=0;v<D;v++)C[_+v]=x[v*h+I]}}else{let x=p,C=f;for(let w=0;w<N;w++){let _=w*D,I=h-1-w;for(let v=0;v<D;v++)C[_+v]=x[v*h+I]}}}else if(t===2)if(m){let N=p,D=f;for(let x=0;x<g;x++){let C=x*h,w=(g-1-x)*h;for(let _=0;_<h;_++)D[C+_]=N[w+(h-1-_)]}}else{let N=p,D=f;for(let x=0;x<g;x++){let C=x*h,w=(g-1-x)*h;for(let _=0;_<h;_++)D[C+_]=N[w+(h-1-_)]}}else{let N=h,D=g;if(m){let x=p,C=f;for(let w=0;w<N;w++){let _=w*D;for(let I=0;I<D;I++)C[_+I]=x[(g-1-I)*h+w]}}else{let x=p,C=f;for(let w=0;w<N;w++){let _=w*D;for(let I=0;I<D;I++)C[_+I]=x[(g-1-I)*h+w]}}}return S.fromData(f,c,a)}let y=lr(c),d=lr(n),b=new Array(o).fill(0),A=new Array(o);for(let g=0;g<r.size;g++){for(let C=0;C<o;C++)A[C]=b[C];let h,N;t===1?(h=n[i]-1-b[i],N=b[u]):t===2?(h=n[u]-1-b[u],N=n[i]-1-b[i],A[u]=h,A[i]=N):(h=b[i],N=n[u]-1-b[u]),t!==2&&(A[u]=h,A[i]=N);let D=0;for(let C=0;C<o;C++)D+=A[C]*y[C];let x=0;for(let C=0;C<o;C++)x+=b[C]*d[C];if(m){let C=p,w=f;w[D]=C[x]}else{let C=p,w=f;w[D]=C[x]}for(let C=o-1;C>=0&&(b[C]++,!(b[C]<n[C]));C--)b[C]=0}return S.fromData(f,c,a)}function Hf(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=r.size;if(e===void 0){let y=Array.isArray(t)?t.reduce((h,N)=>h+N,0):t,d=Hr(r),b=K(a);if(!b)throw new Error(`Cannot roll array with dtype ${a}`);let A=new b(u),g=O(a);for(let h=0;h<u;h++){let N=((h-y)%u+u)%u,D=d.iget(N);A[h]=D}return S.fromData(A,[...n],a)}let i=Array.isArray(t)?t:[t],s=Array.isArray(e)?e:[e];if(i.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=K(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let f=new l(u),m=O(a),p=new Array(o).fill(0);for(let y=0;y<u;y++){let d=[...p];for(let g=0;g<c.length;g++){let h=c[g],N=n[h],D=i[g];d[h]=((d[h]-D)%N+N)%N}let b=r.offset;for(let g=0;g<o;g++)b+=d[g]*r.strides[g];let A=r.data[b];f[y]=A;for(let g=o-1;g>=0&&(p[g]++,!(p[g]<n[g]));g--)p[g]=0}return S.fromData(f,[...n],a)}function rm(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?S.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):Ti(r,o,a)}function tm(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return ve(r,t,2)}function em(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?ur(e,[e.shape[0],1]):e);return Oi(t)}function nm(r,t){let e=r.dtype,n=t.reduce((s,c)=>s*c,1),o=r.size,a=K(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let u=new a(n),i=O(e);for(let s=0;s<n;s++){let c=s%o,l=r.iget(c);u[s]=l}return S.fromData(u,t,e)}function om(r){return r.map(t=>t.ndim===0?ur(t,[1]):t)}function am(r){return r.map(t=>t.ndim===0?ur(t,[1,1]):t.ndim===1?ur(t,[1,t.shape[0]]):t)}function sm(r){return r.map(t=>t.ndim===0?ur(t,[1,1,1]):t.ndim===1?ur(t,[1,t.shape[0],1]):t.ndim===2?ur(t,[t.shape[0],t.shape[1],1]):t)}function im(r,t=0){let e=r.shape,n=e.length,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[o],u=[];for(let i=0;i<a;i++){let s=[];for(let f=0;f<n;f++)f===o?s.push({start:i,stop:i+1,step:1}):s.push({start:0,stop:e[f],step:1});let c=bD(r,s),l=Bi(c,o);u.push(l)}return u}function um(r,t=1){if(r.length===0)throw new Error("need at least one array to block");return r.length===1?r[0].copy():Jr(r,-1)}function bD(r,t){let e=r.shape,n=r.strides,o=r.offset,a=r.dtype,u=r.data,i=[],s=[];for(let c=0;c<e.length;c++){let l=t[c],{start:f,stop:m,step:p}=l,y=Math.ceil((m-f)/p);i.push(y),s.push(n[c]*p),o+=f*n[c]}return S.fromData(u,i,a,s,o)}function kr(r,t){if(r instanceof U||t instanceof U){let e=r instanceof U?r:new U(Number(r),0),n=t instanceof U?t:new U(Number(t),0);return e.mul(n)}return typeof r=="bigint"&&typeof t=="bigint"?Number(r*t):Number(r)*Number(t)}function AD(r,t,e,n,o,a,u,i,s){for(let c=0;c<e;c++)for(let l=0;l<a;l++)for(let f=0;f<u;f++){let m=0;for(let p=0;p<i;p++)m+=r[t+c*i+p]*n[o+l*i*u+p*u+f];s[c*a*u+l*u+f]=m}}function gD(r,t,e,n,o,a,u,i,s,c){for(let l=0;l<e;l++)for(let f=0;f<u;f++){let m=0;for(let p=0;p<s;p++){let y=n===1?p:l*s+p,d=i===1?p:f*s+p;m+=r[t+y]*o[a+d]}c[e===1?f:l*u+f]=m}}function hD(r,t,e,n,o,a,u,i,s,c,l,f){for(let y=0;y<e*n;y++)l[y]=0;let m=r==="transpose",p=t==="transpose";if(!m&&!p)for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[y*i+A]??0)*(s[A*c+d]??0);l[y*f+d]=a*b}else if(m&&!p)for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[A*i+y]??0)*(s[A*c+d]??0);l[y*f+d]=a*b}else if(!m&&p)for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[y*i+A]??0)*(s[d*c+A]??0);l[y*f+d]=a*b}else for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[A*i+y]??0)*(s[d*c+A]??0);l[y*f+d]=a*b}}function bt(r,t){let e=r.ndim,n=t.ndim,o=B(r.dtype)||B(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 kr(a,u);if(e===0){let i=or(r.dtype,t.dtype),s=S.zeros([...t.shape],i),c=(l,f)=>{let m=new Array(f.length),p=l;for(let y=f.length-1;y>=0;y--)m[y]=p%f[y],p=Math.floor(p/f[y]);return m};for(let l=0;l<t.size;l++){let f=c(l,t.shape),m=t.get(...f);s.set(f,kr(a,m))}return s}else{let i=or(r.dtype,t.dtype),s=S.zeros([...r.shape],i),c=(l,f)=>{let m=new Array(f.length),p=l;for(let y=f.length-1;y>=0;y--)m[y]=p%f[y],p=Math.floor(p/f[y]);return m};for(let l=0;l<r.size;l++){let f=c(l,r.shape),m=r.get(...f);s.set(f,kr(m,u))}return s}}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 i=0,s=0;for(let c=0;c<a;c++){let l=r.get(c),f=t.get(c),m=kr(l,f);m instanceof U?(i+=m.re,s+=m.im):i+=m}return new U(i,s)}let u=0;for(let i=0;i<a;i++){let s=r.get(i),c=t.get(i);typeof s=="bigint"&&typeof c=="bigint"?u=Number(u)+Number(s*c):u+=Number(s)*Number(c)}return u}if(e===2&&n===2)return Ar(r,t);if(e===2&&n===1){let[a,u]=r.shape,i=t.shape[0];if(u!==i)throw new Error(`dot: incompatible shapes (${a},${u}) and (${i},)`);let s=or(r.dtype,t.dtype),c=S.zeros([a],s);if(o)for(let l=0;l<a;l++){let f=0,m=0;for(let p=0;p<u;p++){let y=r.get(l,p),d=t.get(p),b=y instanceof U?y:new U(Number(y),0),A=d instanceof U?d:new U(Number(d),0);f+=b.re*A.re-b.im*A.im,m+=b.re*A.im+b.im*A.re}c.set([l],new U(f,m))}else for(let l=0;l<a;l++){let f=0;for(let m=0;m<u;m++){let p=r.get(l,m),y=t.get(m);typeof p=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(p*y):f+=Number(p)*Number(y)}c.set([l],f)}return c}if(e===1&&n===2){let a=r.shape[0],[u,i]=t.shape;if(a!==u)throw new Error(`dot: incompatible shapes (${a},) and (${u},${i})`);let s=or(r.dtype,t.dtype),c=S.zeros([i],s);if(o)for(let l=0;l<i;l++){let f=0,m=0;for(let p=0;p<a;p++){let y=r.get(p),d=t.get(p,l),b=y instanceof U?y:new U(Number(y),0),A=d instanceof U?d:new U(Number(d),0);f+=b.re*A.re-b.im*A.im,m+=b.re*A.im+b.im*A.re}c.set([l],new U(f,m))}else for(let l=0;l<i;l++){let f=0;for(let m=0;m<a;m++){let p=r.get(m),y=t.get(m,l);typeof p=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(p*y):f+=Number(p)*Number(y)}c.set([l],f)}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 i=[...r.shape.slice(0,-1)],s=or(r.dtype,t.dtype),c=S.zeros(i,s),l=i.reduce((f,m)=>f*m,1);if(o)for(let f=0;f<l;f++){let m=0,p=0,y=f,d=[];for(let b=i.length-1;b>=0;b--)d[b]=y%i[b],y=Math.floor(y/i[b]);for(let b=0;b<a;b++){let A=[...d,b],g=r.get(...A),h=t.get(b),N=g instanceof U?g:new U(Number(g),0),D=h instanceof U?h:new U(Number(h),0);m+=N.re*D.re-N.im*D.im,p+=N.re*D.im+N.im*D.re}c.set(d,new U(m,p))}else for(let f=0;f<l;f++){let m=0,p=f,y=[];for(let d=i.length-1;d>=0;d--)y[d]=p%i[d],p=Math.floor(p/i[d]);for(let d=0;d<a;d++){let b=[...y,d],A=r.get(...b),g=t.get(d);typeof A=="bigint"&&typeof g=="bigint"?m=Number(m)+Number(A*g):m+=Number(A)*Number(g)}c.set(y,m)}return c}if(e===1&&n>2){let a=r.shape[0],u=1,i=t.shape[u];if(a!==i)throw new Error(`dot: incompatible shapes (${a},) and ${JSON.stringify(t.shape)}`);let s=[...t.shape.slice(0,u),...t.shape.slice(u+1)],c=or(r.dtype,t.dtype),l=S.zeros(s,c),f=s.reduce((m,p)=>m*p,1);if(o)for(let m=0;m<f;m++){let p=m,y=[];for(let h=s.length-1;h>=0;h--)y[h]=p%s[h],p=Math.floor(p/s[h]);let d=y.slice(0,u),b=y.slice(u),A=0,g=0;for(let h=0;h<a;h++){let N=r.get(h),D=[...d,h,...b],x=t.get(...D),C=N instanceof U?N:new U(Number(N),0),w=x instanceof U?x:new U(Number(x),0);A+=C.re*w.re-C.im*w.im,g+=C.re*w.im+C.im*w.re}l.set(y,new U(A,g))}else for(let m=0;m<f;m++){let p=m,y=[];for(let g=s.length-1;g>=0;g--)y[g]=p%s[g],p=Math.floor(p/s[g]);let d=y.slice(0,u),b=y.slice(u),A=0;for(let g=0;g<a;g++){let h=r.get(g),N=[...d,g,...b],D=t.get(...N);typeof h=="bigint"&&typeof D=="bigint"?A=Number(A)+Number(h*D):A+=Number(h)*Number(D)}l.set(y,A)}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 i=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],s=or(r.dtype,t.dtype),c=S.zeros(i,s),l=r.shape.slice(0,-1).reduce((y,d)=>y*d,1),f=t.shape.slice(0,-2).reduce((y,d)=>y*d,1),m=t.shape[n-1],p=a;if(o)for(let y=0;y<l;y++)for(let d=0;d<f;d++)for(let b=0;b<m;b++){let A=0,g=0;for(let D=0;D<p;D++){let x=[],C=y;for(let $=r.shape.length-2;$>=0;$--)x.unshift(C%r.shape[$]),C=Math.floor(C/r.shape[$]);x.push(D);let w=r.get(...x),_=[],I=d;for(let $=t.shape.length-3;$>=0;$--)_.unshift(I%t.shape[$]),I=Math.floor(I/t.shape[$]);_.push(D,b);let v=t.get(..._),T=w instanceof U?w:new U(Number(w),0),E=v instanceof U?v:new U(Number(v),0);A+=T.re*E.re-T.im*E.im,g+=T.re*E.im+T.im*E.re}let h=y*f*m+d*m+b,N=c.data;N[h*2]=A,N[h*2+1]=g}else if(r.isCContiguous&&t.isCContiguous&&!O(r.dtype)&&!O(t.dtype))AD(r.data,r.offset,l,t.data,t.offset,f,m,p,c.data);else for(let y=0;y<l;y++)for(let d=0;d<f;d++)for(let b=0;b<m;b++){let A=0;for(let h=0;h<p;h++){let N=y*p+h,D=d*p*m+h*m+b,x=r.iget(N),C=t.iget(D);typeof x=="bigint"&&typeof C=="bigint"?A=Number(A)+Number(x*C):A+=Number(x)*Number(C)}let g=y*f*m+d*m+b;c.data[g]=A}return c}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function Ar(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=or(r.dtype,t.dtype);if(B(u)){let D=S.zeros([e,a],u),x=D.data;for(let C=0;C<e;C++)for(let w=0;w<a;w++){let _=0,I=0;for(let T=0;T<n;T++){let E=r.iget(C*n+T),$=t.iget(T*a+w);_+=E.re*$.re-E.im*$.im,I+=E.re*$.im+E.im*$.re}let v=C*a+w;x[v*2]=_,x[v*2+1]=I}return D}let i=u.startsWith("int")||u.startsWith("uint")||u==="bool"?"float64":u;if(i!=="float64")throw new Error(`matmul currently only supports float64, got ${i}`);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,f=0]=r.strides,[m=0,p=0]=t.strides,y=f>l,d=p>m,b=y?"transpose":"no-transpose",A=d?"transpose":"no-transpose",g,h;y?g=f:g=l,d?h=p:h=m;let N=S.zeros([e,a],"float64");return hD(b,A,e,a,n,1,s,g,c,h,N.data,a),N}function fm(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(B(r.dtype)){let a=0,u=0;for(let i=0;i<n;i++){let s=r.get(i,i);a+=s.re,u+=s.im}return new U(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 tt(r,t){return Fi(r,t)}function mm(r,t){let e=r.ndim,n=t.ndim,o=B(r.dtype)||B(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 bt(r,t);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],s=or(r.dtype,t.dtype),c=S.zeros(i,s),l=e===1?1:r.shape.slice(0,-1).reduce((p,y)=>p*y,1),f=n===1?1:t.shape.slice(0,-1).reduce((p,y)=>p*y,1),m=a;if(o)for(let p=0;p<l;p++)for(let y=0;y<f;y++){let d=0,b=0;for(let h=0;h<m;h++){let N,D;if(e===1)N=r.get(h);else{let w=[],_=p,I=r.shape.slice(0,-1);for(let v=I.length-1;v>=0;v--)w.unshift(_%I[v]),_=Math.floor(_/I[v]);w.push(h),N=r.get(...w)}if(n===1)D=t.get(h);else{let w=[],_=y,I=t.shape.slice(0,-1);for(let v=I.length-1;v>=0;v--)w.unshift(_%I[v]),_=Math.floor(_/I[v]);w.push(h),D=t.get(...w)}let x=N instanceof U?N:new U(Number(N),0),C=D instanceof U?D:new U(Number(D),0);d+=x.re*C.re-x.im*C.im,b+=x.re*C.im+x.im*C.re}if(i.length===0)return new U(d,b);let A=l===1?y:p*f+y,g=c.data;g[A*2]=d,g[A*2+1]=b}else if(r.isCContiguous&&t.isCContiguous&&!O(r.dtype)&&!O(t.dtype)){if(i.length===0){let p=r.data,y=t.data,d=r.offset,b=t.offset,A=0;for(let g=0;g<m;g++)A+=p[d+g]*y[b+g];return A}gD(r.data,r.offset,l,e,t.data,t.offset,f,n,m,c.data)}else for(let p=0;p<l;p++)for(let y=0;y<f;y++){let d=0;for(let A=0;A<m;A++){let g=e===1?A:p*m+A,h=n===1?A:y*m+A,N=r.iget(g),D=t.iget(h);typeof N=="bigint"&&typeof D=="bigint"?d=Number(d)+Number(N*D):d+=Number(N)*Number(D)}if(i.length===0)return d;let b=l===1?y:p*f+y;c.data[b]=d}return c}function $i(r,t){let e=r.ndim===1?r:yt(r),n=t.ndim===1?t:yt(t),o=e.size,a=n.size,u=or(r.dtype,t.dtype),i=S.zeros([o,a],u);for(let s=0;s<o;s++)for(let c=0;c<a;c++){let l=e.get(s),f=n.get(c),m=kr(l,f);i.set([s,c],m)}return i}function pm(r,t,e){let n,o;if(typeof e=="number"){let y=e;if(y<0)throw new Error("tensordot: axes must be non-negative");if(y>r.ndim||y>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:y},(d,b)=>r.ndim-y+b),o=Array.from({length:y},(d,b)=>b)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let y=0;y<n.length;y++){let d=n[y],b=o[y];if(d<0||d>=r.ndim||b<0||b>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[d]!==t.shape[b])throw new Error(`tensordot: shape mismatch on axes ${d} and ${b}: ${r.shape[d]} != ${t.shape[b]}`)}let a=[],u=[];for(let y=0;y<r.ndim;y++)n.includes(y)||a.push(y);for(let y=0;y<t.ndim;y++)o.includes(y)||u.push(y);let i=[...a.map(y=>r.shape[y]),...u.map(y=>t.shape[y])],s=or(r.dtype,t.dtype),c=B(s),l=y=>y instanceof U?{re:y.re,im:y.im}:{re:Number(y),im:0};if(i.length===0){let y=0,d=0,b=n.map(A=>r.shape[A]).reduce((A,g)=>A*g,1);for(let A=0;A<b;A++){let g=A,h=new Array(n.length);for(let w=n.length-1;w>=0;w--){let _=n[w];h[w]=g%r.shape[_],g=Math.floor(g/r.shape[_])}let N=new Array(r.ndim),D=new Array(t.ndim);for(let w=0;w<n.length;w++)N[n[w]]=h[w];for(let w=0;w<o.length;w++)D[o[w]]=h[w];let x=r.get(...N),C=t.get(...D);if(c){let w=l(x),_=l(C);y+=w.re*_.re-w.im*_.im,d+=w.re*_.im+w.im*_.re}else typeof x=="bigint"&&typeof C=="bigint"?y+=Number(x*C):y+=Number(x)*Number(C)}return c?new U(y,d):y}let f=S.zeros(i,s),m=i.reduce((y,d)=>y*d,1),p=n.map(y=>r.shape[y]).reduce((y,d)=>y*d,1);for(let y=0;y<m;y++){let d=y,b=[];for(let D=i.length-1;D>=0;D--)b[D]=d%i[D],d=Math.floor(d/i[D]);let A=b.slice(0,a.length),g=b.slice(a.length),h=0,N=0;for(let D=0;D<p;D++){d=D;let x=[];for(let v=n.length-1;v>=0;v--){let T=n[v];x[v]=d%r.shape[T],d=Math.floor(d/r.shape[T])}let C=new Array(r.ndim),w=new Array(t.ndim);for(let v=0;v<a.length;v++)C[a[v]]=A[v];for(let v=0;v<u.length;v++)w[u[v]]=g[v];for(let v=0;v<n.length;v++)C[n[v]]=x[v],w[o[v]]=x[v];let _=r.get(...C),I=t.get(...w);if(c){let v=l(_),T=l(I);h+=v.re*T.re-v.im*T.im,N+=v.re*T.im+v.im*T.re}else typeof _=="bigint"&&typeof I=="bigint"?h+=Number(_*I):h+=Number(_)*Number(I)}c?f.set(b,new U(h,N)):f.set(b,h)}return f}function ym(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,i=n<0?a+n:n;if(u<0||u>=a||i<0||i>=a)throw new Error("axis out of bounds");if(u===i)throw new Error("axis1 and axis2 cannot be the same");let s=o[u],c=o[i],l;t>=0?l=Math.max(0,Math.min(s,c-t)):l=Math.max(0,Math.min(s+t,c));let f=[];for(let d=0;d<a;d++)d!==u&&d!==i&&f.push(o[d]);f.push(l);let m=S.zeros(f,r.dtype),p=o.filter((d,b)=>b!==u&&b!==i),y=p.reduce((d,b)=>d*b,1);for(let d=0;d<y;d++){let b=d,A=[];for(let g=p.length-1;g>=0;g--)A.unshift(b%p[g]),b=Math.floor(b/p[g]);for(let g=0;g<l;g++){let h=new Array(a),N=0;for(let C=0;C<a;C++)C===u?h[C]=t>=0?g:g-t:C===i?h[C]=t>=0?g+t:g:h[C]=A[N++];let D=[...A,g],x=r.get(...h);m.set(D,x)}}return m}function dm(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=bm(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 u=new Map;for(let d=0;d<t.length;d++){let b=a[d],A=t[d];if(b.length!==A.ndim)throw new Error(`einsum: operand ${d} has ${A.ndim} dimensions but subscript '${b}' has ${b.length} indices`);for(let g=0;g<b.length;g++){let h=b[g],N=A.shape[g];if(u.has(h)){if(u.get(h)!==N)throw new Error(`einsum: size mismatch for index '${h}': ${u.get(h)} vs ${N}`)}else u.set(h,N)}}for(let d of o)if(!u.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let i=new Set(o),s=new Set;for(let d of a)for(let b of d)s.add(b);let c=[];for(let d of s)i.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,b]=a,[A,g]=t;if(d.length===2&&b.length===2&&o.length===2&&A.ndim===2&&g.ndim===2){let[h,N]=[d[0],d[1]],[D,x]=[b[0],b[1]],[C,w]=[o[0],o[1]];if(h===C&&x===w&&N===D&&c.length===1&&c[0]===N||h===C&&x===w&&N===D&&c.length===1&&c[0]===N)return Ar(A,g);if(N===C&&x===w&&h===D&&c.length===1&&c[0]===h){let _=tt(A);return Ar(_,g)}if(h===C&&D===w&&N===x&&c.length===1&&c[0]===N){let _=tt(g);return Ar(A,_)}}if(d.length===1&&b.length===1&&d===b&&o.length===0&&A.ndim===1&&g.ndim===1)return Ei(t,a,c,u);if(d&&b&&d.length===1&&b.length===1&&o.length===2&&o===d+b&&c.length===0&&A.ndim===1&&g.ndim===1)return $i(A,g)}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 Ei(t,a,c,u)}let l=Array.from(o).map(d=>u.get(d));if(l.length===0)return Ei(t,a,c,u);let f=t[0].dtype;for(let d=1;d<t.length;d++)f=or(f,t[d].dtype);let m=S.zeros(l,f),p=l.reduce((d,b)=>d*b,1),y=1;for(let d of c)y*=u.get(d);for(let d=0;d<p;d++){let b=ND(d,l),A=new Map;for(let h=0;h<o.length;h++)A.set(o[h],b[h]);let g=0;for(let h=0;h<y;h++){let N=h;for(let x=c.length-1;x>=0;x--){let C=c[x],w=u.get(C);A.set(C,N%w),N=Math.floor(N/w)}let D=1;for(let x=0;x<t.length;x++){let C=t[x],w=a[x],_=[];for(let v of w)_.push(A.get(v));let I=C.get(..._);D*=Number(I)}g+=D}m.set(b,g)}return m}function bm(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 Ei(r,t,e,n){let o=!1;for(let c of r)if(B(c.dtype)){o=!0;break}let a=c=>c instanceof U?{re:c.re,im:c.im}:{re:Number(c),im:0},u=1;for(let c of e)u*=n.get(c);let i=0,s=0;for(let c=0;c<u;c++){let l=new Map,f=c;for(let y=e.length-1;y>=0;y--){let d=e[y],b=n.get(d);l.set(d,f%b),f=Math.floor(f/b)}let m=1,p=0;for(let y=0;y<r.length;y++){let d=r[y],b=t[y],A=[];for(let h of b)A.push(l.get(h));let g=d.get(...A);if(o){let h=a(g),N=m*h.re-p*h.im,D=m*h.im+p*h.re;m=N,p=D}else m*=Number(g)}i+=m,s+=p}return o?new U(i,s):i}function ND(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 Am(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,u=or(r.dtype,t.dtype),i=Math.max(o,a),s=new Array(i),c=new Array(i).fill(1),l=new Array(i).fill(1);for(let y=0;y<o;y++)c[i-o+y]=e[y];for(let y=0;y<a;y++)l[i-a+y]=n[y];for(let y=0;y<i;y++)s[y]=c[y]*l[y];let f=S.zeros(s,u),m=e.reduce((y,d)=>y*d,1),p=n.reduce((y,d)=>y*d,1);for(let y=0;y<m;y++){let d=y,b=new Array(o);for(let h=o-1;h>=0;h--)b[h]=d%e[h],d=Math.floor(d/e[h]);let A=new Array(i).fill(0);for(let h=0;h<o;h++)A[i-o+h]=b[h];let g=r.get(...b);for(let h=0;h<p;h++){let N=h,D=new Array(a);for(let I=a-1;I>=0;I--)D[I]=N%n[I],N=Math.floor(N/n[I]);let x=new Array(i).fill(0);for(let I=0;I<a;I++)x[i-a+I]=D[I];let C=t.get(...D),w=new Array(i);for(let I=0;I<i;I++)w[I]=A[I]*l[I]+x[I];let _=kr(g,C);f.set(w,_)}}return f}function gm(r,t,e=-1,n=-1,o=-1,a){a!==void 0&&(e=a,n=a,o=a);let u=(w,_)=>w<0?_+w:w,i=u(e,r.ndim),s=u(n,t.ndim),c=or(r.dtype,t.dtype),l=B(c),f=(w,..._)=>{let I=w.get(..._);return I instanceof U?I:Number(I)},m=(w,_)=>{if(w instanceof U||_ instanceof U){let I=w instanceof U?w:new U(w,0),v=_ instanceof U?_:new U(_,0);return I.mul(v)}return w*_},p=(w,_)=>{if(w instanceof U||_ instanceof U){let I=w instanceof U?w:new U(w,0),v=_ instanceof U?_:new U(_,0);return I.sub(v)}return w-_};if(r.ndim===1&&t.ndim===1){let w=r.shape[0],_=t.shape[0];if(w===3&&_===3){let I=f(r,0),v=f(r,1),T=f(r,2),E=f(t,0),$=f(t,1),k=f(t,2),V=S.zeros([3],c);return V.set([0],p(m(v,k),m(T,$))),V.set([1],p(m(T,E),m(I,k))),V.set([2],p(m(I,$),m(v,E))),V}else if(w===2&&_===2){let I=f(r,0),v=f(r,1),T=f(t,0),E=f(t,1);return p(m(I,E),m(v,T))}else if(w===2&&_===3||w===3&&_===2){let I=f(r,0),v=f(r,1),T=w===3?f(r,2):l?new U(0,0):0,E=f(t,0),$=f(t,1),k=_===3?f(t,2):l?new U(0,0):0,V=S.zeros([3],c);return V.set([0],p(m(v,k),m(T,$))),V.set([1],p(m(T,E),m(I,k))),V.set([2],p(m(I,$),m(v,E))),V}else throw new Error(`cross: incompatible dimensions for cross product: ${w} and ${_}`)}let y=r.shape[i],d=t.shape[s];if(y!==2&&y!==3||d!==2&&d!==3)throw new Error(`cross: incompatible dimensions for cross product: ${y} and ${d}`);let b=y===2&&d===2?0:3,A=[...r.shape.slice(0,i),...r.shape.slice(i+1)],g=[...t.shape.slice(0,s),...t.shape.slice(s+1)];if(A.length!==g.length)throw new Error("cross: incompatible shapes for cross product");for(let w=0;w<A.length;w++)if(A[w]!==g[w])throw new Error("cross: incompatible shapes for cross product");let h=A,N=o<0?h.length+1+o:o,D;if(b===0?D=h:D=[...h.slice(0,N),b,...h.slice(N)],D.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");let x=S.zeros(D,c),C=h.reduce((w,_)=>w*_,1);for(let w=0;w<C;w++){let _=w,I=[];for(let X=h.length-1;X>=0;X--)I[X]=_%h[X],_=Math.floor(_/h[X]);let v=[...I.slice(0,i),0,...I.slice(i)],T=[...I.slice(0,s),0,...I.slice(s)],E=X=>(v[i]=X,f(r,...v)),$=X=>(T[s]=X,f(t,...T)),k=E(0),V=E(1),j=y===3?E(2):l?new U(0,0):0,R=$(0),Y=$(1),J=d===3?$(2):l?new U(0,0):0;if(b===0)x.set(I,p(m(k,Y),m(V,R)));else{let X=p(m(V,J),m(j,Y)),rr=p(m(j,R),m(k,J)),yr=p(m(k,Y),m(V,R)),nr=(dr,Or)=>{let UN=[...I.slice(0,N),dr,...I.slice(N)];x.set(UN,Or)};nr(0,X),nr(1,rr),nr(2,yr)}}return x}function dt(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:yt(r),l=c.size,f;if(t===1/0){f=0;for(let m=0;m<l;m++)f=Math.max(f,Math.abs(Number(c.get(m))))}else if(t===-1/0){f=1/0;for(let m=0;m<l;m++)f=Math.min(f,Math.abs(Number(c.get(m))))}else if(t===0){f=0;for(let m=0;m<l;m++)Number(c.get(m))!==0&&f++}else if(t===1){f=0;for(let m=0;m<l;m++)f+=Math.abs(Number(c.get(m)))}else if(t===2){f=0;for(let m=0;m<l;m++){let p=Number(c.get(m));f+=p*p}f=Math.sqrt(f)}else{f=0;for(let m=0;m<l;m++)f+=Math.pow(Math.abs(Number(c.get(m))),t);f=Math.pow(f,1/t)}if(n){let m=new Array(r.ndim).fill(1),p=S.zeros(m,"float64");return p.set(new Array(r.ndim).fill(0),f),p}return f}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 dt(r,t,null,!1);let u=S.zeros(a,"float64"),i=r.shape[o],s=a.reduce((c,l)=>c*l,1);for(let c=0;c<s;c++){let l=c,f=[];for(let y=a.length-1;y>=0;y--)f[y]=l%a[y],l=Math.floor(l/a[y]);let m=n?[...f.slice(0,o),0,...f.slice(o+1)]:[...f.slice(0,o),0,...f.slice(o)],p;if(t===1/0){p=0;for(let y=0;y<i;y++)m[o]=y,p=Math.max(p,Math.abs(Number(r.get(...m))))}else if(t===-1/0){p=1/0;for(let y=0;y<i;y++)m[o]=y,p=Math.min(p,Math.abs(Number(r.get(...m))))}else if(t===0){p=0;for(let y=0;y<i;y++)m[o]=y,Number(r.get(...m))!==0&&p++}else if(t===1){p=0;for(let y=0;y<i;y++)m[o]=y,p+=Math.abs(Number(r.get(...m)))}else if(t===2){p=0;for(let y=0;y<i;y++){m[o]=y;let d=Number(r.get(...m));p+=d*d}p=Math.sqrt(p)}else{p=0;for(let y=0;y<i;y++)m[o]=y,p+=Math.pow(Math.abs(Number(r.get(...m))),t);p=Math.pow(p,1/t)}u.set(f,p)}return u}function rt(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 i=0;i<o;i++){let s=Number(r.get(u,i));a+=s*s}a=Math.sqrt(a)}else if(t==="nuc"){let{s:u}=Xr(r);a=0;for(let i=0;i<u.size;i++)a+=Number(u.get(i))}else if(t===1){a=0;for(let u=0;u<o;u++){let i=0;for(let s=0;s<n;s++)i+=Math.abs(Number(r.get(s,u)));a=Math.max(a,i)}}else if(t===-1){a=1/0;for(let u=0;u<o;u++){let i=0;for(let s=0;s<n;s++)i+=Math.abs(Number(r.get(s,u)));a=Math.min(a,i)}}else if(t===1/0){a=0;for(let u=0;u<n;u++){let i=0;for(let s=0;s<o;s++)i+=Math.abs(Number(r.get(u,s)));a=Math.max(a,i)}}else if(t===-1/0){a=1/0;for(let u=0;u<n;u++){let i=0;for(let s=0;s<o;s++)i+=Math.abs(Number(r.get(u,s)));a=Math.min(a,i)}}else if(t===2){let{s:u}=Xr(r);a=Number(u.get(0))}else if(t===-2){let{s:u}=Xr(r);a=Number(u.get(u.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${t}`);if(e){let u=S.zeros([1,1],"float64");return u.set([0,0],a),u}return a}function hm(r,t=null,e=null,n=!1){if(t===null)return e===null?dt(r,2,null,n):typeof e=="number"?dt(r,2,e,n):rt(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 rt(r,t,n)}if(r.ndim===2&&e===null&&(t==="fro"||t==="nuc"))return rt(r,t,n);if(typeof t!="number"&&t!==null)throw new Error(`norm: ord '${t}' not valid for vector norm`);return dt(r,t??2,e,n)}function ki(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=S.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 u=[],i=[];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 b=0;for(let D=0;D<y;D++)b+=d[D]*d[D];if(b=Math.sqrt(b),b<1e-15){u.push(d),i.push(0);continue}let A=d[0]>=0?1:-1,g=d[0]+A*b,h=[1];for(let D=1;D<y;D++)h.push(d[D]/g);let N=A*g/b;i.push(N),u.push(h);for(let D=p;D<n;D++){let x=0;for(let C=0;C<y;C++)x+=h[C]*Number(a.get(p+C,D));for(let C=0;C<y;C++)a.set([p+C,D],Number(a.get(p+C,D))-N*h[C]*x)}}if(t==="raw"){let p=S.zeros([e,n],"float64");for(let d=0;d<e;d++)for(let b=0;b<n;b++)p.set([d,b],Number(a.get(d,b)));let y=S.zeros([o],"float64");for(let d=0;d<o;d++)y.set([d],i[d]);return{h:p,tau:y}}if(t==="r"){let p=S.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=S.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=u[p],d=i[p],b=e-p;for(let A=p;A<s;A++){let g=0;for(let h=0;h<b;h++)g+=y[h]*Number(c.get(p+h,A));for(let h=0;h<b;h++)c.set([p+h,A],Number(c.get(p+h,A))-d*y[h]*g)}}let l=S.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 f=t==="complete"?e:o,m=S.zeros([f,n],"float64");for(let p=0;p<f;p++)for(let y=0;y<n;y++)y>=p&&m.set([p,y],Number(a.get(p,y)));return{q:l,r:m}}function Nm(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=S.zeros([o,o],"float64");for(let u=0;u<o;u++)for(let i=0;i<=u;i++){let s=0;if(u===i){for(let l=0;l<i;l++)s+=Number(a.get(i,l))**2;let c=Number(r.get(i,i))-s;if(c<0)throw new Error("cholesky: matrix is not positive definite");a.set([i,i],Math.sqrt(c))}else{for(let l=0;l<i;l++)s+=Number(a.get(u,l))*Number(a.get(i,l));let c=Number(a.get(i,i));if(Math.abs(c)<1e-15)throw new Error("cholesky: matrix is not positive definite");a.set([u,i],(Number(r.get(u,i))-s)/c)}}if(t){let u=S.zeros([o,o],"float64");for(let i=0;i<o;i++)for(let s=i;s<o;s++)u.set([i,s],Number(a.get(s,i)));return u}return a}function Xr(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=S.zeros([e,e],"float64");for(let f=0;f<e;f++)for(let m=0;m<e;m++){let p=0;for(let y=0;y<t;y++)p+=Number(r.get(y,f))*Number(r.get(y,m));o.set([f,m],p)}let{values:a,vectors:u}=Ri(o),i=Array.from({length:e},(f,m)=>m);i.sort((f,m)=>a[m]-a[f]);let s=S.zeros([n],"float64");for(let f=0;f<n;f++){let m=a[i[f]];s.set([f],Math.sqrt(Math.max(0,m)))}let c=S.zeros([e,e],"float64");for(let f=0;f<e;f++)for(let m=0;m<e;m++)c.set([f,m],u[m][i[f]]);let l=S.zeros([t,t],"float64");for(let f=0;f<t;f++)for(let m=0;m<n;m++){let p=Number(s.get(m));if(p>1e-10){let y=0;for(let d=0;d<e;d++)y+=Number(r.get(f,d))*Number(c.get(m,d));l.set([f,m],y/p)}}if(t>n)for(let f=n;f<t;f++){let m=new Array(t).fill(0);m[f]=1;for(let y=0;y<f;y++){let d=0;for(let b=0;b<t;b++)d+=m[b]*Number(l.get(b,y));for(let b=0;b<t;b++)m[b]=m[b]-d*Number(l.get(b,y))}let p=0;for(let y=0;y<t;y++)p+=m[y]*m[y];if(p=Math.sqrt(p),p>1e-10)for(let y=0;y<t;y++)l.set([y,f],m[y]/p)}return{u:l,s,vt:c}}function Ri(r){let t=r.shape[0],e=100*t*t,n=1e-10,o=[];for(let i=0;i<t;i++){o.push([]);for(let s=0;s<t;s++)o[i].push(Number(r.get(i,s)))}let a=[];for(let i=0;i<t;i++){a.push([]);for(let s=0;s<t;s++)a[i].push(i===s?1:0)}for(let i=0;i<e;i++){let s=0,c=0,l=1;for(let h=0;h<t;h++)for(let N=h+1;N<t;N++)Math.abs(o[h][N])>s&&(s=Math.abs(o[h][N]),c=h,l=N);if(s<n)break;let f=o[c][c],m=o[l][l],p=o[c][l],y;Math.abs(f-m)<1e-15?y=Math.PI/4:y=.5*Math.atan2(2*p,m-f);let d=Math.cos(y),b=Math.sin(y),A=d*d*f+b*b*m-2*b*d*p,g=b*b*f+d*d*m+2*b*d*p;o[c][c]=A,o[l][l]=g,o[c][l]=0,o[l][c]=0;for(let h=0;h<t;h++)if(h!==c&&h!==l){let N=o[h][c],D=o[h][l];o[h][c]=d*N-b*D,o[c][h]=o[h][c],o[h][l]=b*N+d*D,o[l][h]=o[h][l]}for(let h=0;h<t;h++){let N=a[h][c],D=a[h][l];a[h][c]=d*N-b*D,a[h][l]=b*N+d*D}}let u=[];for(let i=0;i<t;i++)u.push(o[i][i]);return{values:u,vectors:a}}function qi(r,t=!0,e=!0){let n=Xr(r);if(!e)return n.s;if(!t){let[o,a]=r.shape,u=Math.min(o,a),i=S.zeros([o,u],"float64");for(let c=0;c<o;c++)for(let l=0;l<u;l++)i.set([c,l],Number(n.u.get(c,l)));let s=S.zeros([u,a],"float64");for(let c=0;c<u;c++)for(let l=0;l<a;l++)s.set([c,l],Number(n.vt.get(c,l)));return{u:i,s:n.s,vt:s}}return n}function Dm(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}=Po(r),i=a.data,s=u;for(let c=0;c<n;c++)s*=i[c*n+c];return s}function Po(r){let[t,e]=r.shape,n=t,o=e,a=S.zeros([n,o],"float64"),u=a.data,i=r.data;for(let l=0;l<n*o;l++)u[l]=Number(i[l]);let s=Array.from({length:n},(l,f)=>f),c=1;for(let l=0;l<Math.min(n,o);l++){let f=Math.abs(u[l*o+l]),m=l;for(let y=l+1;y<n;y++){let d=Math.abs(u[y*o+l]);d>f&&(f=d,m=y)}if(m!==l){for(let d=0;d<o;d++){let b=u[l*o+d];u[l*o+d]=u[m*o+d],u[m*o+d]=b}let y=s[l];s[l]=s[m],s[m]=y,c=-c}let p=u[l*o+l];if(Math.abs(p)>1e-15)for(let y=l+1;y<n;y++){let d=u[y*o+l]/p;u[y*o+l]=d;for(let b=l+1;b<o;b++)u[y*o+b]=u[y*o+b]-d*u[l*o+b]}}return{lu:a,piv:s,sign:c}}function Me(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}=Po(r),u=o.data,i=S.zeros([n,n],"float64"),s=i.data;for(let c=0;c<n;c++){let l=new Float64Array(n);for(let f=0;f<n;f++){let m=a[f]===c?1:0;for(let p=0;p<f;p++)m-=u[f*n+p]*l[p];l[f]=m}for(let f=n-1;f>=0;f--){let m=l[f];for(let y=f+1;y<n;y++)m-=u[f*n+y]*s[y*n+c];let p=u[f*n+f];if(Math.abs(p)<1e-15)throw new Error("inv: singular matrix");s[f*n+c]=m/p}}return i}function lm(r,t){let[e]=r.shape,n=e,{lu:o,piv:a}=Po(r),u=o.data,i=t.data,s=new Float64Array(n);for(let m=0;m<n;m++)s[m]=Number(i[a[m]]);let c=new Float64Array(n);for(let m=0;m<n;m++){let p=s[m];for(let y=0;y<m;y++)p-=u[m*n+y]*c[y];c[m]=p}let l=S.zeros([n],"float64"),f=l.data;for(let m=n-1;m>=0;m--){let p=c[m];for(let d=m+1;d<n;d++)p-=u[m*n+d]*f[d];let y=u[m*n+m];if(Math.abs(y)<1e-15)throw new Error("solve: singular matrix");f[m]=p/y}return l}function Vi(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 lm(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=S.zeros([o,a],"float64");for(let i=0;i<a;i++){let s=S.zeros([o],"float64");for(let l=0;l<o;l++)s.set([l],Number(t.get(l,i)));let c=lm(r,s);for(let l=0;l<o;l++)u.set([l,i],Number(c.get(l)))}return u}throw new Error(`solve: b must be 1D or 2D, got ${t.ndim}D`)}function xm(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:i}=Xr(r),s=Math.min(n,o),c=e??Math.max(n,o)*Number.EPSILON,f=Number(u.get(0))*c,m=0;for(let g=0;g<s;g++)Number(u.get(g))>f&&m++;let p=t.ndim===1?ur(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=S.zeros([o,y],"float64");for(let g=0;g<y;g++){let h=new Array(n).fill(0);for(let N=0;N<n;N++)for(let D=0;D<n;D++)h[N]+=Number(a.get(D,N))*Number(p.get(D,g));for(let N=0;N<o;N++){let D=0;for(let x=0;x<s;x++){let C=Number(u.get(x));C>f&&(D+=Number(i.get(x,N))*h[x]/C)}d.set([N,g],D)}}let b;if(n>o){b=S.zeros([y],"float64");for(let g=0;g<y;g++){let h=0;for(let N=0;N<n;N++){let D=0;for(let C=0;C<o;C++)D+=Number(r.get(N,C))*Number(d.get(C,g));let x=D-Number(p.get(N,g));h+=x*x}b.set([g],h)}}else b=S.zeros([0],"float64");return{x:t.ndim===1?ur(d,[o]):d,residuals:b,rank:m,s:u}}function Cm(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:i}=Xr(r),s=Math.min(e,n),c=Number(i.get(0)),l=Number(i.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=rt(r,t),a=Me(r),u=rt(a,t);return o*u}function Sm(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}=Xr(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 wm(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=S.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=Me(r),u=-t);let i=S.zeros([o,o],"float64");for(let c=0;c<o;c++)i.set([c,c],1);let s=S.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(;u>0;)u&1&&(i=Ar(i,s)),s=Ar(s,s),u>>=1;return i}function Im(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}=Xr(r),i=Math.min(e,n),c=Number(a.get(0))*t,l=S.zeros([n,e],"float64");for(let f=0;f<n;f++)for(let m=0;m<e;m++){let p=0;for(let y=0;y<i;y++){let d=Number(a.get(y));d>c&&(p+=Number(u.get(y,f))*Number(o.get(m,y))/d)}l.set([f,m],p)}return l}function Pi(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}=Ri(r),f=S.zeros([n],"float64"),m=S.zeros([n,n],"float64");for(let p=0;p<n;p++){f.set([p],c[p]);for(let y=0;y<n;y++)m.set([y,p],l[y][p])}return{w:f,v:m}}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}=DD(r),i=S.zeros([n],"float64"),s=S.zeros([n,n],"float64");for(let c=0;c<n;c++){i.set([c],a[c]);for(let l=0;l<n;l++)s.set([l,c],u[l][c])}return{w:i,v:s}}function DD(r){let t=r.shape[0],e=1e3,n=1e-10,o=S.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=S.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=ki(o,"reduced"),f=l.q,m=l.r;o=Ar(m,f),a=Ar(a,f)}let u=[];for(let s=0;s<t;s++)u.push(Number(o.get(s,s)));let i=[];for(let s=0;s<t;s++){i.push([]);for(let c=0;c<t;c++)i[s].push(Number(a.get(s,c)))}return{values:u,vectors:i}}function ji(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=S.zeros([o,o],"float64");for(let f=0;f<o;f++)for(let m=0;m<o;m++)t==="L"?f>=m&&(a.set([f,m],Number(r.get(f,m))),a.set([m,f],Number(r.get(f,m)))):m>=f&&(a.set([f,m],Number(r.get(f,m))),a.set([m,f],Number(r.get(f,m))));let{values:u,vectors:i}=Ri(a),s=Array.from({length:o},(f,m)=>m);s.sort((f,m)=>u[f]-u[m]);let c=S.zeros([o],"float64"),l=S.zeros([o,o],"float64");for(let f=0;f<o;f++){c.set([f],u[s[f]]);for(let m=0;m<o;m++)l.set([m,f],i[m][s[f]])}return{w:c,v:l}}function zm(r){let{w:t}=Pi(r);return t}function _m(r,t="L"){let{w:e}=ji(r,t);return e}function vm(r,t){let e=Hr(r),n=Hr(t),o=e.shape[0],a=n.shape[0];if(o!==a)throw new Error(`vdot: arrays must have same number of elements, got ${o} and ${a}`);if(B(r.dtype)||B(t.dtype)){let s=0,c=0;for(let l=0;l<o;l++){let f=e.get(l),m=n.get(l),p=f instanceof U?f.re:Number(f),y=f instanceof U?-f.im:0,d=m instanceof U?m.re:Number(m),b=m instanceof U?m.im:0;s+=p*d+y*b,c+=p*b-y*d}return Math.abs(c)<1e-15?s:new U(s,c)}let i=0;for(let s=0;s<o;s++){let c=e.get(s),l=n.get(s);typeof c=="bigint"&&typeof l=="bigint"?i=(typeof i=="bigint"?i:BigInt(i))+c*l:i=(typeof i=="bigint"?Number(i):i)+Number(c)*Number(l)}return i}function Mm(r,t,e=-1){let n=r.ndim,o=t.ndim,a=e<0?n+e:e,u=e<0?o+e:e;if(a<0||a>=n)throw new Error(`vecdot: axis ${e} out of bounds for array with ${n} dimensions`);if(u<0||u>=o)throw new Error(`vecdot: axis ${e} out of bounds for array with ${o} dimensions`);let i=r.shape[a],s=t.shape[u];if(i!==s)throw new Error(`vecdot: axis dimensions must match, got ${i} and ${s}`);if(n===1&&o===1)return bt(r,t);let c=[...r.shape.slice(0,a),...r.shape.slice(a+1)],l=[...t.shape.slice(0,u),...t.shape.slice(u+1)],f=i,m=B(r.dtype)||B(t.dtype),p=or(r.dtype,t.dtype),y=c.length>l.length?c:l;if(y.length===0){let A=m?new U(0,0):0;for(let g=0;g<f;g++){let h=r.get(g),N=t.get(g),D=kr(h,N);if(A instanceof U||D instanceof U){let x=A instanceof U?A:new U(Number(A),0),C=D instanceof U?D:new U(Number(D),0);A=x.add(C)}else typeof A=="bigint"||typeof D=="bigint"?A=BigInt(A)+BigInt(D):A=A+D}return A}let d=S.zeros(y,p),b=y.reduce((A,g)=>A*g,1);for(let A=0;A<b;A++){let g=[],h=A;for(let C=y.length-1;C>=0;C--)g.unshift(h%y[C]),h=Math.floor(h/y[C]);let N=[...g.slice(0,a),0,...g.slice(a)],D=[...g.slice(0,u),0,...g.slice(u)],x=m?new U(0,0):0;for(let C=0;C<f;C++){N[a]=C,D[u]=C;let w=r.get(...N),_=t.get(...D),I=kr(w,_);if(x instanceof U||I instanceof U){let v=x instanceof U?x:new U(Number(x),0),T=I instanceof U?I:new U(Number(I),0);x=v.add(T)}else typeof x=="bigint"||typeof I=="bigint"?x=BigInt(x)+BigInt(I):x=x+I}d.set(g,x)}return d}function Fm(r){if(r.ndim<2)throw new Error(`matrix_transpose: input must have at least 2 dimensions, got ${r.ndim}D`);let t=Array.from({length:r.ndim},(n,o)=>o),e=t.length-1;return t[e]=e-1,t[e-1]=e,tt(r,t)}function Bm(r,t){return tt(r,t)}function Tm(r,t){if(r.ndim<2)throw new Error(`matvec: x1 must have at least 2 dimensions, got ${r.ndim}D`);if(t.ndim<1)throw new Error(`matvec: x2 must have at least 1 dimension, got ${t.ndim}D`);let e=r.shape[r.ndim-2],n=r.shape[r.ndim-1],o=t.shape[t.ndim-1];if(n!==o)throw new Error(`matvec: last axis of x1 (${n}) must match last axis of x2 (${o})`);if(r.ndim===2&&t.ndim===1)return bt(r,t);let a=r.shape.slice(0,-2),u=t.shape.slice(0,-1),i=Math.max(a.length,u.length),s=[...Array(i-a.length).fill(1),...a],c=[...Array(i-u.length).fill(1),...u],l=[];for(let b=0;b<i;b++){let A=s[b],g=c[b];if(A!==1&&g!==1&&A!==g)throw new Error(`matvec: batch dimensions not broadcastable: ${a} vs ${u}`);l.push(Math.max(A,g))}let f=[...l,e],m=or(r.dtype,t.dtype),p=S.zeros(f,m),y=B(m),d=l.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=[],g=b;for(let D=l.length-1;D>=0;D--)A.unshift(g%l[D]),g=Math.floor(g/l[D]);let h=A.slice(-(a.length||1)).map((D,x)=>(a[x]??1)===1?0:D),N=A.slice(-(u.length||1)).map((D,x)=>(u[x]??1)===1?0:D);for(let D=0;D<e;D++){let x=y?new U(0,0):0;for(let w=0;w<n;w++){let _=[...h,D,w],I=[...N,w],v=r.get(..._),T=t.get(...I),E=kr(v,T);if(x instanceof U||E instanceof U){let $=x instanceof U?x:new U(Number(x),0),k=E instanceof U?E:new U(Number(E),0);x=$.add(k)}else typeof x=="bigint"||typeof E=="bigint"?x=BigInt(x)+BigInt(E):x=x+E}let C=[...A,D];p.set(C,x)}}return p}function Om(r,t){if(r.ndim<1)throw new Error(`vecmat: x1 must have at least 1 dimension, got ${r.ndim}D`);if(t.ndim<2)throw new Error(`vecmat: x2 must have at least 2 dimensions, got ${t.ndim}D`);let e=r.shape[r.ndim-1],n=t.shape[t.ndim-2],o=t.shape[t.ndim-1];if(e!==n)throw new Error(`vecmat: last axis of x1 (${e}) must match second-to-last axis of x2 (${n})`);if(r.ndim===1&&t.ndim===2)return bt(r,t);let a=r.shape.slice(0,-1),u=t.shape.slice(0,-2),i=Math.max(a.length,u.length),s=[...Array(i-a.length).fill(1),...a],c=[...Array(i-u.length).fill(1),...u],l=[];for(let b=0;b<i;b++){let A=s[b],g=c[b];if(A!==1&&g!==1&&A!==g)throw new Error(`vecmat: batch dimensions not broadcastable: ${a} vs ${u}`);l.push(Math.max(A,g))}let f=[...l,o],m=or(r.dtype,t.dtype),p=S.zeros(f,m),y=B(m),d=l.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=[],g=b;for(let D=l.length-1;D>=0;D--)A.unshift(g%l[D]),g=Math.floor(g/l[D]);let h=A.slice(-(a.length||1)).map((D,x)=>(a[x]??1)===1?0:D),N=A.slice(-(u.length||1)).map((D,x)=>(u[x]??1)===1?0:D);for(let D=0;D<o;D++){let x=y?new U(0,0):0;for(let w=0;w<e;w++){let _=[...h,w],I=[...N,w,D],v=r.get(..._),T=t.get(...I),E=kr(v,T);if(x instanceof U||E instanceof U){let $=x instanceof U?x:new U(Number(x),0),k=E instanceof U?E:new U(Number(E),0);x=$.add(k)}else typeof x=="bigint"||typeof E=="bigint"?x=BigInt(x)+BigInt(E):x=x+E}let C=[...A,D];p.set(C,x)}}return p}function Em(r){if(r.ndim!==2)throw new Error(`slogdet: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`slogdet: matrix must be square, got ${t}x${e}`);let n=t;if(n===0)return{sign:1,logabsdet:0};let{lu:o,sign:a}=Po(r),u=o.data,i=0,s=a;for(let c=0;c<n;c++){let l=u[c*n+c];if(l===0)return{sign:0,logabsdet:-1/0};l<0&&(s=-s),i+=Math.log(Math.abs(l))}return{sign:s,logabsdet:i}}function Um(r){return qi(r,!0,!1)}function $m(r){if(r.length<2)throw new Error("multi_dot: need at least 2 arrays");if(r.length===2)return Ar(r[0],r[1]);let t=r[0];for(let e=1;e<r.length;e++)t=Ar(t,r[e]);return t}function km(r,t=2){if(t<=0)throw new Error(`tensorinv: ind must be positive, got ${t}`);let e=r.shape,n=r.ndim;if(n<t)throw new Error(`tensorinv: array has ${n} dimensions, ind=${t} is too large`);let o=1;for(let c=0;c<t;c++)o*=e[c];let a=1;for(let c=t;c<n;c++)a*=e[c];if(o!==a)throw new Error(`tensorinv: product of first ${t} dimensions (${o}) must equal product of remaining dimensions (${a})`);let u=ur(r,[o,a]),i=Me(u),s=[...e.slice(t),...e.slice(0,t)];return ur(i,s)}function Rm(r,t,e){let n=r.shape,o=t.shape,a=r.ndim,u=t.ndim,i;e==null?i=Array.from({length:u},(h,N)=>a-u+N):i=e.map(h=>h<0?a+h:h);let s=[];for(let h=0;h<a;h++)i.includes(h)||s.push(h);let c=[...s,...i],l=tt(r,c),m=i.map(h=>n[h]).reduce((h,N)=>h*N,1),y=s.map(h=>n[h]).reduce((h,N)=>h*N,1),d=o.reduce((h,N)=>h*N,1);if(m!==d)throw new Error(`tensorsolve: dimensions don't match - sum dimensions product (${m}) != b total elements (${d})`);if(y!==m)throw new Error(`tensorsolve: non-square problem - other dimensions product (${y}) != sum dimensions product (${m})`);let b=ur(l,[y,m]),A=ur(t,[m]),g=Vi(b,A);return ur(g,[...o])}function qm(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=bm(n)):(n=r.slice(0,e),o=r.slice(e+2));let a=n.split(",").map(m=>m.trim());if(a.length!==t.length)throw new Error(`einsum_path: expected ${a.length} operands, got ${t.length}`);let u=t.map(m=>Array.isArray(m)?m:Array.from(m.shape)),i=new Map;for(let m=0;m<t.length;m++){let p=a[m],y=u[m];if(p.length!==y.length)throw new Error(`einsum_path: operand ${m} has ${y.length} dimensions but subscript '${p}' has ${p.length} indices`);for(let d=0;d<p.length;d++){let b=p[d],A=y[d];if(i.has(b)&&i.get(b)!==A)throw new Error(`einsum_path: size mismatch for index '${b}': ${i.get(b)} vs ${A}`);i.set(b,A)}}if(t.length===1){let m=[[0]];return[m,Ui(r,u,m,i)]}if(t.length===2){let m=[[0,1]];return[m,Ui(r,u,m,i)]}let s=[],c=[...a],l=[...u],f=t.map((m,p)=>p);for(;c.length>1;){let m=0,p=1,y=1/0;for(let A=0;A<c.length;A++)for(let g=A+1;g<c.length;g++){let h=xD(c[A],c[g],l[A],l[g],o,i);h<y&&(y=h,m=A,p=g)}s.push([f[m],f[p]]);let[d,b]=CD(c[m],c[p],l[m],l[p],o,i);c.splice(p,1),c.splice(m,1),l.splice(p,1),l.splice(m,1),f.splice(p,1),f.splice(m,1),c.push(d),l.push(b),f.push(-1)}return[s,Ui(r,u,s,i)]}function xD(r,t,e,n,o,a){let u=new Set(r),i=new Set(t),s=1;for(let c of u)s*=a.get(c)||1;for(let c of i)u.has(c)||(s*=a.get(c)||1);return s}function CD(r,t,e,n,o,a){let u=new Set([...r,...t]),i=new Map;for(let f of r)i.set(f,(i.get(f)||0)+1);for(let f of t)i.set(f,(i.get(f)||0)+1);let s=new Set(o),c=[];for(let f of u)(s.has(f)||i.get(f)===1)&&c.push(f);c.sort();let l=c.map(f=>a.get(f));return[c.join(""),l]}function Ui(r,t,e,n){let o=[];o.push(" Complete contraction: "+r),o.push(" Operand shapes: "+t.map(u=>`(${u.join(", ")})`).join(", ")),o.push(" Contraction path: "+JSON.stringify(e));let a=0;for(let u of t)a+=u.reduce((i,s)=>i*s,1);return o.push(" Estimated FLOPS: ~"+a.toExponential(2)),o.join(`
|
|
2
|
-
`)}function At(r,t){let e=bt(z(r),z(t));return typeof e=="number"||typeof e=="bigint"||e instanceof U?e:M(e)}function et(r){return fm(z(r))}function gt(r,t=0,e=0,n=1){return M(ym(z(r),t,e,n))}function Li(r,t){return M(Am(z(r),z(t)))}function ht(r,t){return Nr(tt(z(r),t),r)}function Nt(r,t){let e=mm(z(r),z(t));return typeof e=="number"||typeof e=="bigint"||e instanceof U?e:M(e)}function Dt(r,t){return M($i(z(r),z(t)))}function xt(r,t,e=2){let n=pm(z(r),z(t),e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function jo(r,...t){let e=t.map(o=>z(o)),n=dm(r,...e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Lo(r,...t){let e=t.map(n=>z(n));return qm(r,...e)}function Go(r,t){return vm(z(r),z(t))}function Wo(r,t,e=-1){let n=Mm(z(r),z(t),e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Yo(r){return Nr(Fm(z(r)),r)}function Zo(r,t){return Nr(Bm(z(r),t),r)}function Gi(r,t){return M(Tm(z(r),z(t)))}function Wi(r,t){return M(Om(z(r),z(t)))}function Jo(r,t,e=-1,n=-1,o=-1,a){let u=gm(z(r),z(t),e,n,o,a);return typeof u=="number"||u instanceof U?u:M(u)}function Fe(r,t){return M(Ar(z(r),z(t)))}var Xo={matmul:(r,t)=>M(Ar(z(r),z(t))),dot:(r,t)=>At(r,t),det:r=>Dm(z(r)),inv:r=>M(Me(z(r))),solve:(r,t)=>M(Vi(z(r),z(t))),lstsq:(r,t,e)=>{let n=xm(z(r),z(t),e);return{x:M(n.x),residuals:M(n.residuals),rank:n.rank,s:M(n.s)}},norm:(r,t,e,n)=>{let o=hm(z(r),t,e,n);return typeof o=="number"?o:M(o)},cond:(r,t)=>Cm(z(r),t),matrix_rank:(r,t)=>Sm(z(r),t),matrix_power:(r,t)=>M(wm(z(r),t)),pinv:(r,t)=>M(Im(z(r),t)),qr:(r,t)=>{let e=ki(z(r),t);return"h"in e&&"tau"in e?{h:M(e.h),tau:M(e.tau)}:"q"in e&&"r"in e?{q:M(e.q),r:M(e.r)}:M(e)},cholesky:(r,t)=>M(Nm(z(r),t)),svd:(r,t,e)=>{let n=qi(z(r),t,e);return"u"in n&&"s"in n&&"vt"in n?{u:M(n.u),s:M(n.s),vt:M(n.vt)}:M(n)},eig:r=>{let t=Pi(z(r));return{w:M(t.w),v:M(t.v)}},eigh:(r,t)=>{let e=ji(z(r),t);return{w:M(e.w),v:M(e.v)}},eigvals:r=>M(zm(z(r))),eigvalsh:(r,t)=>M(_m(z(r),t)),slogdet:r=>Em(z(r)),svdvals:r=>M(Um(z(r))),multi_dot:r=>M($m(r.map(t=>z(t)))),tensorinv:(r,t)=>M(km(z(r),t)),tensorsolve:(r,t,e)=>M(Rm(z(r),z(t),e)),vector_norm:(r,t,e,n)=>{let o=dt(z(r),t,e,n);return typeof o=="number"?o:M(o)},matrix_norm:(r,t,e)=>{let n=rt(z(r),t,e);return typeof n=="number"?n:M(n)},cross:(r,t,e,n,o,a)=>Jo(r,t,e,n,o,a),matrix_transpose:r=>Yo(r),permute_dims:(r,t)=>Zo(r,t),trace:r=>et(r),diagonal:(r,t,e,n)=>gt(r,t,e,n),outer:(r,t)=>Dt(r,t),inner:(r,t)=>Nt(r,t),tensordot:(r,t,e)=>xt(r,t,e),vecdot:(r,t,e)=>Wo(r,t,e),transpose:(r,t)=>ht(r,t)};function Be(r,t){return M(ur(z(r),t))}function Br(r){return M(Hr(z(r)))}function Te(r){return M(yt(z(r)))}function Oe(r,t){return Nr(Bi(z(r),t),r)}function Ee(r,t){return Nr(_e(z(r),t),r)}function Ue(r,t,e){return Nr(Vf(z(r),t,e),r)}function $e(r,t,e){return Nr(Ti(z(r),t,e),r)}function Yi(r,t,e=0){return Nr(rm(z(r),t,e),r)}function Ct(r,t=0){return M(Jr(r.map(e=>z(e)),t))}function Zi(r,t=0){return M(Pf(r.map(e=>z(e)),t))}function Ko(r){return M(jf(r.map(t=>z(t))))}function Ji(r){return M(Oi(r.map(t=>z(t))))}function Xi(r){return M(Lf(r.map(t=>z(t))))}function Ki(r){return M(em(r.map(t=>z(t))))}var Qo=Ko;function Qi(r){return M(um(r.map(t=>z(t))))}function Ho(r,t,e=0){return ft(Gf(z(r),t,e),r)}function ra(r,t,e=0){return ft(ve(z(r),t,e),r)}function ta(r,t){return ft(Yf(z(r),t),r)}function ea(r,t){return ft(Zf(z(r),t),r)}function na(r,t){return ft(tm(z(r),t),r)}function Hi(r,t=0){return $r(im(z(r),t))}function ru(r,t){return M(Jf(z(r),t))}function ke(r,t,e){return M(Xf(z(r),t,e))}function Re(r,t){return M(Kf(z(r),t))}function tu(r){return Re(r,1)}function eu(r){return Re(r,0)}function nu(r,t=1,e=[0,1]){return M(Qf(z(r),t,e))}function ou(r,t,e){return M(Hf(z(r),t,e))}function qe(r,t){return M(nm(z(r),t))}function oa(...r){let t=om(r.map(e=>z(e)));return t.length===1?M(t[0]):$r(t)}function aa(...r){let t=am(r.map(e=>z(e)));return t.length===1?M(t[0]):$r(t)}function sa(...r){let t=sm(r.map(e=>z(e)));return t.length===1?M(t[0]):$r(t)}function xr(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 Z(r,t,e){let n=e;for(let o=0;o<r.length;o++)n+=r[o]*t[o];return n}function W(r,t,e,n){let o=n.length,a=new Array(o),u=Array.from(n).filter((s,c)=>c!==t),i=r;for(let s=u.length-1;s>=0;s--)a[s>=t?s+1:s]=i%u[s],i=Math.floor(i/u[s]);return a[t]=e,a}function Ve(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0)if(B(n)){let A=0,g=0;if(l){let h=i;for(let N=0;N<u;N++)A+=h[(s+N)*2],g+=h[(s+N)*2+1]}else for(let h=0;h<u;h++){let N=r.iget(h);A+=N.re,g+=N.im}return new U(A,g)}else if(O(n)){let A=BigInt(0);if(l){let g=i;for(let h=0;h<u;h++)A+=g[s+h]}else for(let g=0;g<u;g++)A+=r.iget(g);return Number(A)}else{let A=0;if(l)if(s===0)for(let g=0;g<u;g++)A+=Number(i[g]);else for(let g=0;g<u;g++)A+=Number(i[s+g]);else for(let g=0;g<u;g++)A+=Number(r.iget(g));return A}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return Ve(r);let p=S.zeros(m,n),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(B(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=0,D=0;for(let x=0;x<d;x++){let C=W(h,f,x,o),w=Z(C,c,s);N+=A[w*2],D+=A[w*2+1]}g[h*2]=N,g[h*2+1]=D}}else if(O(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=BigInt(0);for(let D=0;D<d;D++){let x=W(h,f,D,o),C=Z(x,c,s);N+=A[C]}g[h]=N}}else for(let A=0;A<b;A++){let g=0;for(let h=0;h<d;h++){let N=W(A,f,h,o),D=Z(N,c,s);g+=Number(i[D])}y[A]=g}if(e){let A=[...o];return A[f]=1,S.fromData(y,A,n)}return p}function ma(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0){let m=Ve(r);return m instanceof U?new U(m.re/r.size,m.im/r.size):m/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=Ve(r,t,e);if(typeof u=="number")return u/o[a];if(u instanceof U)return new U(u.re/o[a],u.im/o[a]);let i=o[a],s=n;B(n)?s=n:(O(n)||n.startsWith("int")||n.startsWith("uint"))&&(s="float64");let c=S.zeros(Array.from(u.shape),s),l=c.data,f=u.data;if(B(n)){let m=f,p=l,y=u.size;for(let d=0;d<y;d++)p[d*2]=m[d*2]/i,p[d*2+1]=m[d*2+1]/i}else if(O(n)){let m=f;for(let p=0;p<l.length;p++)l[p]=Number(m[p])/i}else for(let m=0;m<l.length;m++)l[m]=Number(f[m])/i;return c}function St(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides;if(B(n)){let b=i;if(t===void 0){if(u===0)throw new Error("max of empty array");let C=b[s*2],w=b[s*2+1];for(let _=1;_<u;_++){let I=b[(s+_)*2],v=b[(s+_)*2+1];if(isNaN(I)||isNaN(v))return new U(NaN,NaN);(I>C||I===C&&v>w)&&(C=I,w=v)}return isNaN(C)||isNaN(w)?new U(NaN,NaN):new U(C,w)}let A=t;if(A<0&&(A=a+A),A<0||A>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let g=Array.from(o).filter((C,w)=>w!==A);if(g.length===0)return St(r);let h=S.zeros(g,n),N=h.data,D=o[A],x=g.reduce((C,w)=>C*w,1);for(let C=0;C<x;C++){let w=W(C,A,0,o),_=Z(w,c,s),I=b[_*2],v=b[_*2+1];for(let T=1;T<D;T++){let E=W(C,A,T,o),$=Z(E,c,s),k=b[$*2],V=b[$*2+1];if(isNaN(k)||isNaN(V)){I=NaN,v=NaN;break}(k>I||k===I&&V>v)&&(I=k,v=V)}N[C*2]=I,N[C*2+1]=v}if(e){let C=[...o];return C[A]=1,S.fromData(N,C,n)}return h}if(t===void 0){if(u===0)throw new Error("max of empty array");if(r.isCContiguous){let b=i[s];if(s===0)for(let A=1;A<u;A++)i[A]>b&&(b=i[A]);else for(let A=1;A<u;A++)i[s+A]>b&&(b=i[s+A]);return Number(b)}else{let b=r.iget(0);for(let A=1;A<u;A++){let g=r.iget(A);g>b&&(b=g)}return Number(b)}}let l=t;if(l<0&&(l=a+l),l<0||l>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let f=Array.from(o).filter((b,A)=>A!==l);if(f.length===0)return St(r);let m=S.zeros(f,n),p=m.data,y=o[l],d=f.reduce((b,A)=>b*A,1);if(O(n)){let b=i,A=p;for(let g=0;g<d;g++){let h=W(g,l,0,o),N=Z(h,c,s),D=b[N];for(let x=1;x<y;x++){let C=W(g,l,x,o),w=Z(C,c,s),_=b[w];_>D&&(D=_)}A[g]=D}}else for(let b=0;b<d;b++){let A=-1/0;for(let g=0;g<y;g++){let h=W(b,l,g,o),N=Z(h,c,s),D=Number(i[N]);D>A&&(A=D)}p[b]=A}if(e){let b=[...o];return b[l]=1,S.fromData(p,b,n)}return m}function au(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0)if(B(n)){let A=1,g=0;if(l){let h=i;for(let N=0;N<u;N++){let D=h[(s+N)*2],x=h[(s+N)*2+1],C=A*D-g*x,w=A*x+g*D;A=C,g=w}}else for(let h=0;h<u;h++){let N=r.iget(h),D=N.re,x=N.im,C=A*D-g*x,w=A*x+g*D;A=C,g=w}return new U(A,g)}else if(O(n)){let A=BigInt(1);if(l){let g=i;for(let h=0;h<u;h++)A*=g[s+h]}else for(let g=0;g<u;g++)A*=r.iget(g);return Number(A)}else{let A=1;if(l)if(s===0)for(let g=0;g<u;g++)A*=Number(i[g]);else for(let g=0;g<u;g++)A*=Number(i[s+g]);else for(let g=0;g<u;g++)A*=Number(r.iget(g));return A}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return au(r);let p=S.zeros(m,n),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(B(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=1,D=0;for(let x=0;x<d;x++){let C=W(h,f,x,o),w=Z(C,c,s),_=A[w*2],I=A[w*2+1],v=N*_-D*I,T=N*I+D*_;N=v,D=T}g[h*2]=N,g[h*2+1]=D}}else if(O(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=BigInt(1);for(let D=0;D<d;D++){let x=W(h,f,D,o),C=Z(x,c,s);N*=A[C]}g[h]=N}}else for(let A=0;A<b;A++){let g=1;for(let h=0;h<d;h++){let N=W(A,f,h,o),D=Z(N,c,s);g*=Number(i[D])}y[A]=g}if(e){let A=[...o];return A[f]=1,S.fromData(y,A,n)}return p}function wt(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides;if(B(n)){let b=i;if(t===void 0){if(u===0)throw new Error("min of empty array");let C=b[s*2],w=b[s*2+1];for(let _=1;_<u;_++){let I=b[(s+_)*2],v=b[(s+_)*2+1];if(isNaN(I)||isNaN(v))return new U(NaN,NaN);(I<C||I===C&&v<w)&&(C=I,w=v)}return isNaN(C)||isNaN(w)?new U(NaN,NaN):new U(C,w)}let A=t;if(A<0&&(A=a+A),A<0||A>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let g=Array.from(o).filter((C,w)=>w!==A);if(g.length===0)return wt(r);let h=S.zeros(g,n),N=h.data,D=o[A],x=g.reduce((C,w)=>C*w,1);for(let C=0;C<x;C++){let w=W(C,A,0,o),_=Z(w,c,s),I=b[_*2],v=b[_*2+1];for(let T=1;T<D;T++){let E=W(C,A,T,o),$=Z(E,c,s),k=b[$*2],V=b[$*2+1];if(isNaN(k)||isNaN(V)){I=NaN,v=NaN;break}(k<I||k===I&&V<v)&&(I=k,v=V)}N[C*2]=I,N[C*2+1]=v}if(e){let C=[...o];return C[A]=1,S.fromData(N,C,n)}return h}if(t===void 0){if(u===0)throw new Error("min of empty array");if(r.isCContiguous){let b=i[s];if(s===0)for(let A=1;A<u;A++)i[A]<b&&(b=i[A]);else for(let A=1;A<u;A++)i[s+A]<b&&(b=i[s+A]);return Number(b)}else{let b=r.iget(0);for(let A=1;A<u;A++){let g=r.iget(A);g<b&&(b=g)}return Number(b)}}let l=t;if(l<0&&(l=a+l),l<0||l>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let f=Array.from(o).filter((b,A)=>A!==l);if(f.length===0)return wt(r);let m=S.zeros(f,n),p=m.data,y=o[l],d=f.reduce((b,A)=>b*A,1);if(O(n)){let b=i,A=p;for(let g=0;g<d;g++){let h=W(g,l,0,o),N=Z(h,c,s),D=b[N];for(let x=1;x<y;x++){let C=W(g,l,x,o),w=Z(C,c,s),_=b[w];_<D&&(D=_)}A[g]=D}}else for(let b=0;b<d;b++){let A=1/0;for(let g=0;g<y;g++){let h=W(b,l,g,o),N=Z(h,c,s),D=Number(i[N]);D<A&&(A=D)}p[b]=A}if(e){let b=[...o];return b[l]=1,S.fromData(p,b,n)}return m}function zr(r,t,e,n){return r<e?-1:r>e?1:t<n?-1:t>n?1:0}function su(r,t){let e=r.dtype,n=B(e),o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0){if(u===0)throw new Error("argmin of empty array");if(n)if(l){let A=i,g=A[s*2],h=A[s*2+1],N=0;for(let D=1;D<u;D++){let x=A[(s+D)*2],C=A[(s+D)*2+1];zr(x,C,g,h)<0&&(g=x,h=C,N=D)}return N}else{let A=r.iget(0),g=A.re,h=A.im,N=0;for(let D=1;D<u;D++){let x=r.iget(D);zr(x.re,x.im,g,h)<0&&(g=x.re,h=x.im,N=D)}return N}if(l){let A=i[s],g=0;if(s===0)for(let h=1;h<u;h++)i[h]<A&&(A=i[h],g=h);else for(let h=1;h<u;h++)i[s+h]<A&&(A=i[s+h],g=h);return g}else{let A=r.iget(0),g=0;for(let h=1;h<u;h++){let N=r.iget(h);N<A&&(A=N,g=h)}return g}}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return su(r);let p=S.zeros(m,"int32"),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(n){let A=i;for(let g=0;g<b;g++){let h=W(g,f,0,o),N=Z(h,c,s),D=A[N*2],x=A[N*2+1],C=0;for(let w=1;w<d;w++){let _=W(g,f,w,o),I=Z(_,c,s),v=A[I*2],T=A[I*2+1];zr(v,T,D,x)<0&&(D=v,x=T,C=w)}y[g]=C}}else if(O(e)){let A=i;for(let g=0;g<b;g++){let h=W(g,f,0,o),N=Z(h,c,s),D=A[N],x=0;for(let C=1;C<d;C++){let w=W(g,f,C,o),_=Z(w,c,s),I=A[_];I<D&&(D=I,x=C)}y[g]=x}}else for(let A=0;A<b;A++){let g=1/0,h=0;for(let N=0;N<d;N++){let D=W(A,f,N,o),x=Z(D,c,s),C=Number(i[x]);C<g&&(g=C,h=N)}y[A]=h}return p}function iu(r,t){let e=r.dtype,n=B(e),o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0){if(u===0)throw new Error("argmax of empty array");if(n)if(l){let A=i,g=A[s*2],h=A[s*2+1],N=0;for(let D=1;D<u;D++){let x=A[(s+D)*2],C=A[(s+D)*2+1];zr(x,C,g,h)>0&&(g=x,h=C,N=D)}return N}else{let A=r.iget(0),g=A.re,h=A.im,N=0;for(let D=1;D<u;D++){let x=r.iget(D);zr(x.re,x.im,g,h)>0&&(g=x.re,h=x.im,N=D)}return N}if(l){let A=i[s],g=0;for(let h=1;h<u;h++)i[s+h]>A&&(A=i[s+h],g=h);return g}else{let A=r.iget(0),g=0;for(let h=1;h<u;h++){let N=r.iget(h);N>A&&(A=N,g=h)}return g}}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return iu(r);let p=S.zeros(m,"int32"),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(n){let A=i;for(let g=0;g<b;g++){let h=W(g,f,0,o),N=Z(h,c,s),D=A[N*2],x=A[N*2+1],C=0;for(let w=1;w<d;w++){let _=W(g,f,w,o),I=Z(_,c,s),v=A[I*2],T=A[I*2+1];zr(v,T,D,x)>0&&(D=v,x=T,C=w)}y[g]=C}}else if(O(e)){let A=i;for(let g=0;g<b;g++){let h=W(g,f,0,o),N=Z(h,c,s),D=A[N],x=0;for(let C=1;C<d;C++){let w=W(g,f,C,o),_=Z(w,c,s),I=A[_];I>D&&(D=I,x=C)}y[g]=x}}else for(let A=0;A<b;A++){let g=-1/0,h=0;for(let N=0;N<d;N++){let D=W(A,f,N,o),x=Z(D,c,s),C=Number(i[x]);C>g&&(g=C,h=N)}y[A]=h}return p}function uu(r,t,e=0,n=!1){let o=r.dtype,a=r.shape,u=a.length,i=r.size,s=r.data,c=r.offset,l=r.strides,f=ma(r,t,n),m=r.isCContiguous;if(t===void 0){if(B(o)){let C=f,w=0;if(m){let _=s;for(let I=0;I<i;I++){let v=_[(c+I)*2],T=_[(c+I)*2+1],E=v-C.re,$=T-C.im;w+=E*E+$*$}}else for(let _=0;_<i;_++){let I=r.iget(_),v=I.re-C.re,T=I.im-C.im;w+=v*v+T*T}return w/(i-e)}let D=f,x=0;if(m)for(let C=0;C<i;C++){let w=Number(s[c+C])-D;x+=w*w}else for(let C=0;C<i;C++){let w=Number(r.iget(C))-D;x+=w*w}return x/(i-e)}let p=t;if(p<0&&(p=u+p),p<0||p>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let y=a[p],d=f,b=d.data,A=n?d.shape:Array.from(a).filter((D,x)=>x!==p),g=S.zeros(Array.from(A),"float64"),h=g.data,N=A.reduce((D,x)=>D*x,1);if(B(o)){let D=s,x=b;for(let C=0;C<N;C++){let w=0,_=x[C*2],I=x[C*2+1];for(let v=0;v<y;v++){let T=W(C,p,v,a),E=Z(T,l,c),$=D[E*2],k=D[E*2+1],V=$-_,j=k-I;w+=V*V+j*j}h[C]=w/(y-e)}}else for(let D=0;D<N;D++){let x=0,C=Number(b[D]);for(let w=0;w<y;w++){let _=W(D,p,w,a),I=Z(_,l,c),v=Number(s[I])-C;x+=v*v}h[D]=x/(y-e)}return g}function Vm(r,t,e=0,n=!1){let o=uu(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=S.zeros(Array.from(o.shape),"float64"),u=o.data,i=a.data;for(let s=0;s<u.length;s++)i[s]=Math.sqrt(Number(u[s]));return a}function cu(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,u=r.data,i=r.offset,s=r.strides,c=r.isCContiguous;if(t===void 0){if(c){for(let b=0;b<a;b++)if(!u[i+b])return!1}else for(let b=0;b<a;b++)if(!r.iget(b))return!1;return!0}let l=t;if(l<0&&(l=o+l),l<0||l>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let f=Array.from(n).filter((b,A)=>A!==l);if(f.length===0)return cu(r);let m=S.zeros(f,"bool"),p=m.data,y=n[l],d=f.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=!0;for(let g=0;g<y;g++){let h=W(b,l,g,n),N=Z(h,s,i);if(!u[N]){A=!1;break}}p[b]=A?1:0}if(e){let b=[...n];return b[l]=1,S.fromData(p,b,"bool")}return m}function lu(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,u=r.data,i=r.offset,s=r.strides,c=r.isCContiguous;if(t===void 0){if(c){for(let b=0;b<a;b++)if(u[i+b])return!0}else for(let b=0;b<a;b++)if(r.iget(b))return!0;return!1}let l=t;if(l<0&&(l=o+l),l<0||l>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let f=Array.from(n).filter((b,A)=>A!==l);if(f.length===0)return lu(r);let m=S.zeros(f,"bool"),p=m.data,y=n[l],d=f.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=!1;for(let g=0;g<y;g++){let h=W(b,l,g,n),N=Z(h,s,i);if(u[N]){A=!0;break}}p[b]=A?1:0}if(e){let b=[...n];return b[l]=1,S.fromData(p,b,"bool")}return m}function Pm(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides,s=r.isCContiguous;if(B(e)){let b=a,A=r.size;if(t===void 0){let I=S.zeros([A],e),v=I.data,T=0,E=0;if(s)for(let $=0;$<A;$++)T+=b[(u+$)*2],E+=b[(u+$)*2+1],v[$*2]=T,v[$*2+1]=E;else for(let $=0;$<A;$++){let k=r.iget($);T+=k.re,E+=k.im,v[$*2]=T,v[$*2+1]=E}return I}let g=t;if(g<0&&(g=o+g),g<0||g>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let h=S.zeros([...n],e),N=h.data,D=n[g],x=[],C=1;for(let I=o-1;I>=0;I--)x.unshift(C),C*=n[I];let w=r.size,_=x[g];for(let I=0;I<w;I++){let v=Math.floor(I/_)%D,T=new Array(o),E=I;for(let k=o-1;k>=0;k--)T[k]=E%n[k],E=Math.floor(E/n[k]);let $=Z(T,i,u);v===0?(N[I*2]=b[$*2],N[I*2+1]=b[$*2+1]):(N[I*2]=N[(I-_)*2]+b[$*2],N[I*2+1]=N[(I-_)*2+1]+b[$*2+1])}return h}if(t===void 0){let b=r.size,A=new Float64Array(b),g=0;if(s)for(let h=0;h<b;h++)g+=Number(a[u+h]),A[h]=g;else for(let h=0;h<b;h++)g+=Number(r.iget(h)),A[h]=g;return S.fromData(A,[b],"float64")}let c=t;if(c<0&&(c=o+c),c<0||c>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let l=new Float64Array(r.size),f=n[c],m=[],p=1;for(let b=o-1;b>=0;b--)m.unshift(p),p*=n[b];let y=r.size,d=m[c];for(let b=0;b<y;b++){let A=Math.floor(b/d)%f,g=new Array(o),h=b;for(let D=o-1;D>=0;D--)g[D]=h%n[D],h=Math.floor(h/n[D]);let N=Z(g,i,u);A===0?l[b]=Number(a[N]):l[b]=l[b-d]+Number(a[N])}return S.fromData(l,[...n],"float64")}function jm(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides,s=r.isCContiguous;if(B(e)){let b=a,A=r.size;if(t===void 0){let I=S.zeros([A],e),v=I.data,T=1,E=0;if(s)for(let $=0;$<A;$++){let k=b[(u+$)*2],V=b[(u+$)*2+1],j=T*k-E*V,R=T*V+E*k;T=j,E=R,v[$*2]=T,v[$*2+1]=E}else for(let $=0;$<A;$++){let k=r.iget($),V=k.re,j=k.im,R=T*V-E*j,Y=T*j+E*V;T=R,E=Y,v[$*2]=T,v[$*2+1]=E}return I}let g=t;if(g<0&&(g=o+g),g<0||g>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let h=S.zeros([...n],e),N=h.data,D=n[g],x=[],C=1;for(let I=o-1;I>=0;I--)x.unshift(C),C*=n[I];let w=r.size,_=x[g];for(let I=0;I<w;I++){let v=Math.floor(I/_)%D,T=new Array(o),E=I;for(let k=o-1;k>=0;k--)T[k]=E%n[k],E=Math.floor(E/n[k]);let $=Z(T,i,u);if(v===0)N[I*2]=b[$*2],N[I*2+1]=b[$*2+1];else{let k=N[(I-_)*2],V=N[(I-_)*2+1],j=b[$*2],R=b[$*2+1];N[I*2]=k*j-V*R,N[I*2+1]=k*R+V*j}}return h}if(t===void 0){let b=r.size,A=new Float64Array(b),g=1;if(s)for(let h=0;h<b;h++)g*=Number(a[u+h]),A[h]=g;else for(let h=0;h<b;h++)g*=Number(r.iget(h)),A[h]=g;return S.fromData(A,[b],"float64")}let c=t;if(c<0&&(c=o+c),c<0||c>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let l=new Float64Array(r.size),f=n[c],m=[],p=1;for(let b=o-1;b>=0;b--)m.unshift(p),p*=n[b];let y=r.size,d=m[c];for(let b=0;b<y;b++){let A=Math.floor(b/d)%f,g=new Array(o),h=b;for(let D=o-1;D>=0;D--)g[D]=h%n[D],h=Math.floor(h/n[D]);let N=Z(g,i,u);A===0?l[b]=Number(a[N]):l[b]=l[b-d]*Number(a[N])}return S.fromData(l,[...n],"float64")}function Lm(r,t,e=!1){let n=r.dtype;if(B(n)){let f=St(r,t,e),m=wt(r,t,e);if(f instanceof U&&m instanceof U)return new U(f.re-m.re,f.im-m.im);let p=f,y=m,d=p.data,b=y.data,A=new Float64Array(p.size*2);for(let g=0;g<p.size;g++)A[g*2]=d[g*2]-b[g*2],A[g*2+1]=d[g*2+1]-b[g*2+1];return S.fromData(A,[...p.shape],n)}let o=St(r,t,e),a=wt(r,t,e);if(typeof o=="number"&&typeof a=="number")return o-a;let u=o,i=a,s=u.data,c=i.data,l=new Float64Array(u.size);for(let f=0;f<u.size;f++)l[f]=Number(s[f])-Number(c[f]);return S.fromData(l,[...u.shape],"float64")}function Gm(r,t,e=!1){return je(r,.5,t,e)}function Wm(r,t,e,n=!1){return je(r,t/100,e,n)}function je(r,t,e,n=!1){if(L(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,i=r.offset,s=r.strides;if(e===void 0){let d=[];if(r.isCContiguous)for(let x=0;x<r.size;x++)d.push(Number(u[i+x]));else for(let x=0;x<r.size;x++)d.push(Number(r.iget(x)));d.sort((x,C)=>x-C);let A=d.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)return d[h];let D=g-h;return d[h]*(1-D)+d[N]*D}let c=e;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let l=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return je(r,t);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=[];for(let D=0;D<m;D++){let x=W(d,c,D,o),C=Z(x,s,i);b.push(Number(u[C]))}b.sort((D,x)=>D-x);let A=b.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)p[d]=b[h];else{let D=g-h;p[d]=b[h]*(1-D)+b[N]*D}}let y=S.fromData(p,l,"float64");if(n){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function ia(r,t,e,n=!1){let o=r.dtype,a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(e===void 0)return ma(r,t,n);if(B(o)){let g=i,h=e.data,N=e.offset;if(t===void 0){let v=0,T=0,E=0;if(r.isCContiguous)for(let k=0;k<r.size;k++){let V=Number(h[N+k%e.size]),j=g[(s+k)*2],R=g[(s+k)*2+1];v+=j*V,T+=R*V,E+=V}else for(let k=0;k<r.size;k++){let V=Number(h[N+k%e.size]),j=r.iget(k);v+=j.re*V,T+=j.im*V,E+=V}return E===0?new U(NaN,NaN):new U(v/E,T/E)}let D=t;if(D<0&&(D=u+D),D<0||D>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let x=Array.from(a).filter((v,T)=>T!==D);if(x.length===0)return ia(r,void 0,e);let C=x.reduce((v,T)=>v*T,1),w=a[D],_=S.zeros(x,o),I=_.data;for(let v=0;v<C;v++){let T=0,E=0,$=0;for(let k=0;k<w;k++){let V=W(v,D,k,a),j=Z(V,c,s),R=Number(h[N+k%e.size]),Y=g[j*2],J=g[j*2+1];T+=Y*R,E+=J*R,$+=R}$===0?(I[v*2]=NaN,I[v*2+1]=NaN):(I[v*2]=T/$,I[v*2+1]=E/$)}if(n){let v=[...a];return v[D]=1,S.fromData(I,v,o)}return _}let l=e.offset;if(t===void 0){let g=0,h=0,N=e.data;if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=Number(N[l+x%e.size]);g+=Number(i[s+x])*C,h+=C}else for(let x=0;x<r.size;x++){let C=Number(N[l+x%e.size]);g+=Number(r.iget(x))*C,h+=C}return h===0?NaN:g/h}let f=t;if(f<0&&(f=u+f),f<0||f>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let m=Array.from(a).filter((g,h)=>h!==f);if(m.length===0)return ia(r,void 0,e);let p=m.reduce((g,h)=>g*h,1),y=a[f],d=e.data,b=new Float64Array(p);for(let g=0;g<p;g++){let h=0,N=0;for(let D=0;D<y;D++){let x=W(g,f,D,a),C=Z(x,c,s),w=Number(d[l+D%e.size]);h+=Number(i[C])*w,N+=w}b[g]=N===0?NaN:h/N}let A=S.fromData(b,m,"float64");if(n){let g=[...a];return g[f]=1,S.fromData(b,g,"float64")}return A}function ar(r,t){return isNaN(r)||isNaN(t)}function fu(r,t,e=!1){let n=r.dtype,o=B(n),a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(t===void 0){if(o){let g=i,h=0,N=0;if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=g[(s+x)*2],w=g[(s+x)*2+1];ar(C,w)||(h+=C,N+=w)}else for(let x=0;x<r.size;x++){let C=r.iget(x),w=C.re,_=C.im;ar(w,_)||(h+=w,N+=_)}return new U(h,N)}let b=0;if(r.isCContiguous)for(let g=0;g<r.size;g++){let h=Number(i[s+g]);isNaN(h)||(b+=h)}else for(let g=0;g<r.size;g++){let h=Number(r.iget(g));isNaN(h)||(b+=h)}return b}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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return fu(r);let m=f.reduce((b,A)=>b*A,1),p=a[l];if(o){let b=i,A=new Float64Array(m*2);for(let g=0;g<m;g++){let h=0,N=0;for(let D=0;D<p;D++){let x=W(g,l,D,a),C=Z(x,c,s),w=b[C*2],_=b[C*2+1];ar(w,_)||(h+=w,N+=_)}A[g*2]=h,A[g*2+1]=N}if(e){let g=[...a];return g[l]=1,S.fromData(A,g,n)}return S.fromData(A,f,n)}let y=new Float64Array(m);for(let b=0;b<m;b++){let A=0;for(let g=0;g<p;g++){let h=W(b,l,g,a),N=Z(h,c,s),D=Number(i[N]);isNaN(D)||(A+=D)}y[b]=A}let d=S.fromData(y,f,"float64");if(e){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function mu(r,t,e=!1){let n=r.dtype,o=B(n),a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(t===void 0){if(o){let g=i,h=1,N=0;if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=g[(s+x)*2],w=g[(s+x)*2+1];if(!ar(C,w)){let _=h*C-N*w,I=h*w+N*C;h=_,N=I}}else for(let x=0;x<r.size;x++){let C=r.iget(x),w=C.re,_=C.im;if(!ar(w,_)){let I=h*w-N*_,v=h*_+N*w;h=I,N=v}}return new U(h,N)}let b=1;if(r.isCContiguous)for(let g=0;g<r.size;g++){let h=Number(i[s+g]);isNaN(h)||(b*=h)}else for(let g=0;g<r.size;g++){let h=Number(r.iget(g));isNaN(h)||(b*=h)}return b}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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return mu(r);let m=f.reduce((b,A)=>b*A,1),p=a[l];if(o){let b=i,A=new Float64Array(m*2);for(let g=0;g<m;g++){let h=1,N=0;for(let D=0;D<p;D++){let x=W(g,l,D,a),C=Z(x,c,s),w=b[C*2],_=b[C*2+1];if(!ar(w,_)){let I=h*w-N*_,v=h*_+N*w;h=I,N=v}}A[g*2]=h,A[g*2+1]=N}if(e){let g=[...a];return g[l]=1,S.fromData(A,g,n)}return S.fromData(A,f,n)}let y=new Float64Array(m);for(let b=0;b<m;b++){let A=1;for(let g=0;g<p;g++){let h=W(b,l,g,a),N=Z(h,c,s),D=Number(i[N]);isNaN(D)||(A*=D)}y[b]=A}let d=S.fromData(y,f,"float64");if(e){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function pu(r,t,e=!1){let n=r.dtype,o=B(n),a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(t===void 0){if(o){let h=i,N=0,D=0,x=0;if(r.isCContiguous)for(let w=0;w<r.size;w++){let _=h[(s+w)*2],I=h[(s+w)*2+1];ar(_,I)||(N+=_,D+=I,x++)}else for(let w=0;w<r.size;w++){let _=r.iget(w),I=_.re,v=_.im;ar(I,v)||(N+=I,D+=v,x++)}return x===0?new U(NaN,NaN):new U(N/x,D/x)}let b=0,A=0;if(r.isCContiguous)for(let h=0;h<r.size;h++){let N=Number(i[s+h]);isNaN(N)||(b+=N,A++)}else for(let h=0;h<r.size;h++){let N=Number(r.iget(h));isNaN(N)||(b+=N,A++)}return A===0?NaN:b/A}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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return pu(r);let m=f.reduce((b,A)=>b*A,1),p=a[l];if(o){let b=i,A=new Float64Array(m*2);for(let g=0;g<m;g++){let h=0,N=0,D=0;for(let x=0;x<p;x++){let C=W(g,l,x,a),w=Z(C,c,s),_=b[w*2],I=b[w*2+1];ar(_,I)||(h+=_,N+=I,D++)}D===0?(A[g*2]=NaN,A[g*2+1]=NaN):(A[g*2]=h/D,A[g*2+1]=N/D)}if(e){let g=[...a];return g[l]=1,S.fromData(A,g,n)}return S.fromData(A,f,n)}let y=new Float64Array(m);for(let b=0;b<m;b++){let A=0,g=0;for(let h=0;h<p;h++){let N=W(b,l,h,a),D=Z(N,c,s),x=Number(i[D]);isNaN(x)||(A+=x,g++)}y[b]=g===0?NaN:A/g}let d=S.fromData(y,f,"float64");if(e){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function Pe(r,t,e=0,n=!1){let o=r.dtype,a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(B(o)){let b=i;if(t===void 0){let C=0,w=0,_=0,I=r.isCContiguous;if(I)for(let $=0;$<r.size;$++){let k=b[(s+$)*2],V=b[(s+$)*2+1];ar(k,V)||(C+=k,w+=V,_++)}else for(let $=0;$<r.size;$++){let k=r.iget($),V=k.re,j=k.im;ar(V,j)||(C+=V,w+=j,_++)}if(_-e<=0)return NaN;let v=C/_,T=w/_,E=0;if(I)for(let $=0;$<r.size;$++){let k=b[(s+$)*2],V=b[(s+$)*2+1];if(!ar(k,V)){let j=k-v,R=V-T;E+=j*j+R*R}}else for(let $=0;$<r.size;$++){let k=r.iget($),V=k.re,j=k.im;if(!ar(V,j)){let R=V-v,Y=j-T;E+=R*R+Y*Y}}return E/(_-e)}let A=t;if(A<0&&(A=u+A),A<0||A>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let g=Array.from(a).filter((C,w)=>w!==A);if(g.length===0)return Pe(r,void 0,e);let h=g.reduce((C,w)=>C*w,1),N=a[A],D=new Float64Array(h);for(let C=0;C<h;C++){let w=0,_=0,I=0;for(let $=0;$<N;$++){let k=W(C,A,$,a),V=Z(k,c,s),j=b[V*2],R=b[V*2+1];ar(j,R)||(w+=j,_+=R,I++)}if(I-e<=0){D[C]=NaN;continue}let v=w/I,T=_/I,E=0;for(let $=0;$<N;$++){let k=W(C,A,$,a),V=Z(k,c,s),j=b[V*2],R=b[V*2+1];if(!ar(j,R)){let Y=j-v,J=R-T;E+=Y*Y+J*J}}D[C]=E/(I-e)}let x=S.fromData(D,g,"float64");if(n){let C=[...a];return C[A]=1,S.fromData(D,C,"float64")}return x}if(t===void 0){let b=0,A=0,g=r.isCContiguous;if(g)for(let D=0;D<r.size;D++){let x=Number(i[s+D]);isNaN(x)||(b+=x,A++)}else for(let D=0;D<r.size;D++){let x=Number(r.iget(D));isNaN(x)||(b+=x,A++)}if(A-e<=0)return NaN;let h=b/A,N=0;if(g)for(let D=0;D<r.size;D++){let x=Number(i[s+D]);isNaN(x)||(N+=(x-h)**2)}else for(let D=0;D<r.size;D++){let x=Number(r.iget(D));isNaN(x)||(N+=(x-h)**2)}return N/(A-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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return Pe(r,void 0,e);let m=f.reduce((b,A)=>b*A,1),p=a[l],y=new Float64Array(m);for(let b=0;b<m;b++){let A=0,g=0;for(let D=0;D<p;D++){let x=W(b,l,D,a),C=Z(x,c,s),w=Number(i[C]);isNaN(w)||(A+=w,g++)}if(g-e<=0){y[b]=NaN;continue}let h=A/g,N=0;for(let D=0;D<p;D++){let x=W(b,l,D,a),C=Z(x,c,s),w=Number(i[C]);isNaN(w)||(N+=(w-h)**2)}y[b]=N/(g-e)}let d=S.fromData(y,f,"float64");if(n){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function Ym(r,t,e=0,n=!1){let o=Pe(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,u=new Float64Array(a.size);for(let i=0;i<a.size;i++)u[i]=Math.sqrt(Number(a.data[i]));return S.fromData(u,[...a.shape],"float64")}function ua(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.data,i=r.offset,s=r.strides;if(B(n)){let d=u;if(t===void 0){let x=1/0,C=1/0,w=!1;if(r.isCContiguous)for(let I=0;I<r.size;I++){let v=d[(i+I)*2],T=d[(i+I)*2+1];isNaN(v)||isNaN(T)||(w?(v<x||v===x&&T<C)&&(x=v,C=T):(x=v,C=T,w=!0))}else for(let I=0;I<r.size;I++){let v=r.iget(I),T=v.re,E=v.im;isNaN(T)||isNaN(E)||(w?(T<x||T===x&&E<C)&&(x=T,C=E):(x=T,C=E,w=!0))}return w?new U(x,C):new U(NaN,NaN)}let b=t;if(b<0&&(b=a+b),b<0||b>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let A=Array.from(o).filter((x,C)=>C!==b);if(A.length===0)return ua(r);let g=A.reduce((x,C)=>x*C,1),h=o[b],N=new Float64Array(g*2);for(let x=0;x<g;x++){let C=1/0,w=1/0,_=!1;for(let I=0;I<h;I++){let v=W(x,b,I,o),T=Z(v,s,i),E=d[T*2],$=d[T*2+1];isNaN(E)||isNaN($)||(_?(E<C||E===C&&$<w)&&(C=E,w=$):(C=E,w=$,_=!0))}N[x*2]=_?C:NaN,N[x*2+1]=_?w:NaN}let D=S.fromData(N,A,n);if(e){let x=[...o];return x[b]=1,S.fromData(N,x,n)}return D}if(t===void 0){let d=1/0;if(r.isCContiguous)for(let A=0;A<r.size;A++){let g=Number(u[i+A]);!isNaN(g)&&g<d&&(d=g)}else for(let A=0;A<r.size;A++){let g=Number(r.iget(A));!isNaN(g)&&g<d&&(d=g)}return d===1/0?NaN:d}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=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return ua(r);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=1/0;for(let A=0;A<m;A++){let g=W(d,c,A,o),h=Z(g,s,i),N=Number(u[h]);!isNaN(N)&&N<b&&(b=N)}p[d]=b===1/0?NaN:b}let y=S.fromData(p,l,"float64");if(e){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function ca(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.data,i=r.offset,s=r.strides;if(B(n)){let d=u;if(t===void 0){let x=-1/0,C=-1/0,w=!1;if(r.isCContiguous)for(let I=0;I<r.size;I++){let v=d[(i+I)*2],T=d[(i+I)*2+1];isNaN(v)||isNaN(T)||(w?(v>x||v===x&&T>C)&&(x=v,C=T):(x=v,C=T,w=!0))}else for(let I=0;I<r.size;I++){let v=r.iget(I),T=v.re,E=v.im;isNaN(T)||isNaN(E)||(w?(T>x||T===x&&E>C)&&(x=T,C=E):(x=T,C=E,w=!0))}return w?new U(x,C):new U(NaN,NaN)}let b=t;if(b<0&&(b=a+b),b<0||b>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let A=Array.from(o).filter((x,C)=>C!==b);if(A.length===0)return ca(r);let g=A.reduce((x,C)=>x*C,1),h=o[b],N=new Float64Array(g*2);for(let x=0;x<g;x++){let C=-1/0,w=-1/0,_=!1;for(let I=0;I<h;I++){let v=W(x,b,I,o),T=Z(v,s,i),E=d[T*2],$=d[T*2+1];isNaN(E)||isNaN($)||(_?(E>C||E===C&&$>w)&&(C=E,w=$):(C=E,w=$,_=!0))}N[x*2]=_?C:NaN,N[x*2+1]=_?w:NaN}let D=S.fromData(N,A,n);if(e){let x=[...o];return x[b]=1,S.fromData(N,x,n)}return D}if(t===void 0){let d=-1/0;if(r.isCContiguous)for(let A=0;A<r.size;A++){let g=Number(u[i+A]);!isNaN(g)&&g>d&&(d=g)}else for(let A=0;A<r.size;A++){let g=Number(r.iget(A));!isNaN(g)&&g>d&&(d=g)}return d===-1/0?NaN:d}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=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return ca(r);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=-1/0;for(let A=0;A<m;A++){let g=W(d,c,A,o),h=Z(g,s,i),N=Number(u[h]);!isNaN(N)&&N>b&&(b=N)}p[d]=b===-1/0?NaN:b}let y=S.fromData(p,l,"float64");if(e){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function la(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides;if(B(e)){let p=a;if(t===void 0){let h=1/0,N=1/0,D=-1;if(r.isCContiguous)for(let C=0;C<r.size;C++){let w=p[(u+C)*2],_=p[(u+C)*2+1];!ar(w,_)&&zr(w,_,h,N)<0&&(h=w,N=_,D=C)}else for(let C=0;C<r.size;C++){let w=r.iget(C),_=w.re,I=w.im;!ar(_,I)&&zr(_,I,h,N)<0&&(h=_,N=I,D=C)}return D}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 d=Array.from(n).filter((h,N)=>N!==y);if(d.length===0)return la(r);let b=d.reduce((h,N)=>h*N,1),A=n[y],g=new Int32Array(b);for(let h=0;h<b;h++){let N=1/0,D=1/0,x=0;for(let C=0;C<A;C++){let w=W(h,y,C,n),_=Z(w,i,u),I=p[_*2],v=p[_*2+1];!ar(I,v)&&zr(I,v,N,D)<0&&(N=I,D=v,x=C)}g[h]=x}return S.fromData(g,d,"int32")}if(t===void 0){let p=1/0,y=-1;if(r.isCContiguous)for(let b=0;b<r.size;b++){let A=Number(a[u+b]);!isNaN(A)&&A<p&&(p=A,y=b)}else for(let b=0;b<r.size;b++){let A=Number(r.iget(b));!isNaN(A)&&A<p&&(p=A,y=b)}return y}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 c=Array.from(n).filter((p,y)=>y!==s);if(c.length===0)return la(r);let l=c.reduce((p,y)=>p*y,1),f=n[s],m=new Int32Array(l);for(let p=0;p<l;p++){let y=1/0,d=0;for(let b=0;b<f;b++){let A=W(p,s,b,n),g=Z(A,i,u),h=Number(a[g]);!isNaN(h)&&h<y&&(y=h,d=b)}m[p]=d}return S.fromData(m,c,"int32")}function fa(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides;if(B(e)){let p=a;if(t===void 0){let h=-1/0,N=-1/0,D=-1;if(r.isCContiguous)for(let C=0;C<r.size;C++){let w=p[(u+C)*2],_=p[(u+C)*2+1];!ar(w,_)&&zr(w,_,h,N)>0&&(h=w,N=_,D=C)}else for(let C=0;C<r.size;C++){let w=r.iget(C),_=w.re,I=w.im;!ar(_,I)&&zr(_,I,h,N)>0&&(h=_,N=I,D=C)}return D}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 d=Array.from(n).filter((h,N)=>N!==y);if(d.length===0)return fa(r);let b=d.reduce((h,N)=>h*N,1),A=n[y],g=new Int32Array(b);for(let h=0;h<b;h++){let N=-1/0,D=-1/0,x=0;for(let C=0;C<A;C++){let w=W(h,y,C,n),_=Z(w,i,u),I=p[_*2],v=p[_*2+1];!ar(I,v)&&zr(I,v,N,D)>0&&(N=I,D=v,x=C)}g[h]=x}return S.fromData(g,d,"int32")}if(t===void 0){let p=-1/0,y=-1;if(r.isCContiguous)for(let b=0;b<r.size;b++){let A=Number(a[u+b]);!isNaN(A)&&A>p&&(p=A,y=b)}else for(let b=0;b<r.size;b++){let A=Number(r.iget(b));!isNaN(A)&&A>p&&(p=A,y=b)}return y}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 c=Array.from(n).filter((p,y)=>y!==s);if(c.length===0)return fa(r);let l=c.reduce((p,y)=>p*y,1),f=n[s],m=new Int32Array(l);for(let p=0;p<l;p++){let y=-1/0,d=0;for(let b=0;b<f;b++){let A=W(p,s,b,n),g=Z(A,i,u),h=Number(a[g]);!isNaN(h)&&h>y&&(y=h,d=b)}m[p]=d}return S.fromData(m,c,"int32")}function Zm(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset;if(B(e)){let d=a,b=r.size;if(t===void 0){let I=S.zeros([b],e),v=I.data,T=0,E=0;if(r.isCContiguous)for(let k=0;k<b;k++){let V=d[(u+k)*2],j=d[(u+k)*2+1];ar(V,j)||(T+=V,E+=j),v[k*2]=T,v[k*2+1]=E}else for(let k=0;k<b;k++){let V=r.iget(k),j=V.re,R=V.im;ar(j,R)||(T+=j,E+=R),v[k*2]=T,v[k*2+1]=E}return I}let A=t;if(A<0&&(A=o+A),A<0||A>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=S.zeros([...n],e),h=g.data,N=n[A],D=[],x=1;for(let I=o-1;I>=0;I--)D.unshift(x),x*=n[I];let C=r.size,w=D[A];if(r.isCContiguous)for(let I=0;I<C;I++){let v=d[(u+I)*2],T=d[(u+I)*2+1],E=Math.floor(I/w)%N,$=ar(v,T);E===0?(h[I*2]=$?0:v,h[I*2+1]=$?0:T):(h[I*2]=h[(I-w)*2]+($?0:v),h[I*2+1]=h[(I-w)*2+1]+($?0:T))}else for(let I=0;I<C;I++){let v=r.iget(I),T=v.re,E=v.im,$=Math.floor(I/w)%N,k=ar(T,E);$===0?(h[I*2]=k?0:T,h[I*2+1]=k?0:E):(h[I*2]=h[(I-w)*2]+(k?0:T),h[I*2+1]=h[(I-w)*2+1]+(k?0:E))}return g}if(t===void 0){let d=r.size,b=new Float64Array(d),A=0;if(r.isCContiguous)for(let h=0;h<d;h++){let N=Number(a[u+h]);isNaN(N)||(A+=N),b[h]=A}else for(let h=0;h<d;h++){let N=Number(r.iget(h));isNaN(N)||(A+=N),b[h]=A}return S.fromData(b,[d],"float64")}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 s=new Float64Array(r.size),c=n[i],l=[],f=1;for(let d=o-1;d>=0;d--)l.unshift(f),f*=n[d];let m=r.size,p=l[i];if(r.isCContiguous)for(let d=0;d<m;d++){let b=Number(a[u+d]);Math.floor(d/p)%c===0?s[d]=isNaN(b)?0:b:s[d]=s[d-p]+(isNaN(b)?0:b)}else for(let d=0;d<m;d++){let b=Number(r.iget(d));Math.floor(d/p)%c===0?s[d]=isNaN(b)?0:b:s[d]=s[d-p]+(isNaN(b)?0:b)}return S.fromData(s,[...n],"float64")}function Jm(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset;if(B(e)){let d=a,b=r.size;if(t===void 0){let I=S.zeros([b],e),v=I.data,T=1,E=0;if(r.isCContiguous)for(let k=0;k<b;k++){let V=d[(u+k)*2],j=d[(u+k)*2+1];if(!ar(V,j)){let R=T*V-E*j,Y=T*j+E*V;T=R,E=Y}v[k*2]=T,v[k*2+1]=E}else for(let k=0;k<b;k++){let V=r.iget(k),j=V.re,R=V.im;if(!ar(j,R)){let Y=T*j-E*R,J=T*R+E*j;T=Y,E=J}v[k*2]=T,v[k*2+1]=E}return I}let A=t;if(A<0&&(A=o+A),A<0||A>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=S.zeros([...n],e),h=g.data,N=n[A],D=[],x=1;for(let I=o-1;I>=0;I--)D.unshift(x),x*=n[I];let C=r.size,w=D[A];if(r.isCContiguous)for(let I=0;I<C;I++){let v=d[(u+I)*2],T=d[(u+I)*2+1],E=Math.floor(I/w)%N,$=ar(v,T);if(E===0)h[I*2]=$?1:v,h[I*2+1]=$?0:T;else{let k=h[(I-w)*2],V=h[(I-w)*2+1];$?(h[I*2]=k,h[I*2+1]=V):(h[I*2]=k*v-V*T,h[I*2+1]=k*T+V*v)}}else for(let I=0;I<C;I++){let v=r.iget(I),T=v.re,E=v.im,$=Math.floor(I/w)%N,k=ar(T,E);if($===0)h[I*2]=k?1:T,h[I*2+1]=k?0:E;else{let V=h[(I-w)*2],j=h[(I-w)*2+1];k?(h[I*2]=V,h[I*2+1]=j):(h[I*2]=V*T-j*E,h[I*2+1]=V*E+j*T)}}return g}if(t===void 0){let d=r.size,b=new Float64Array(d),A=1;if(r.isCContiguous)for(let h=0;h<d;h++){let N=Number(a[u+h]);isNaN(N)||(A*=N),b[h]=A}else for(let h=0;h<d;h++){let N=Number(r.iget(h));isNaN(N)||(A*=N),b[h]=A}return S.fromData(b,[d],"float64")}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 s=new Float64Array(r.size),c=n[i],l=[],f=1;for(let d=o-1;d>=0;d--)l.unshift(f),f*=n[d];let m=r.size,p=l[i];if(r.isCContiguous)for(let d=0;d<m;d++){let b=Number(a[u+d]);Math.floor(d/p)%c===0?s[d]=isNaN(b)?1:b:s[d]=s[d-p]*(isNaN(b)?1:b)}else for(let d=0;d<m;d++){let b=Number(r.iget(d));Math.floor(d/p)%c===0?s[d]=isNaN(b)?1:b:s[d]=s[d-p]*(isNaN(b)?1:b)}return S.fromData(s,[...n],"float64")}function yu(r,t,e=!1){L(r.dtype,"nanmedian","Complex numbers are not orderable.");let n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides;if(t===void 0){let y=[];if(r.isCContiguous)for(let g=0;g<r.size;g++){let h=Number(a[u+g]);isNaN(h)||y.push(h)}else for(let g=0;g<r.size;g++){let h=Number(r.iget(g));isNaN(h)||y.push(h)}if(y.length===0)return NaN;y.sort((g,h)=>g-h);let b=y.length,A=Math.floor(b/2);return b%2===0?(y[A-1]+y[A])/2:y[A]}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 c=Array.from(n).filter((y,d)=>d!==s);if(c.length===0)return yu(r);let l=c.reduce((y,d)=>y*d,1),f=n[s],m=new Float64Array(l);for(let y=0;y<l;y++){let d=[];for(let g=0;g<f;g++){let h=W(y,s,g,n),N=Z(h,i,u),D=Number(a[N]);isNaN(D)||d.push(D)}if(d.length===0){m[y]=NaN;continue}d.sort((g,h)=>g-h);let b=d.length,A=Math.floor(b/2);b%2===0?m[y]=(d[A-1]+d[A])/2:m[y]=d[A]}let p=S.fromData(m,c,"float64");if(e){let y=[...n];return y[s]=1,S.fromData(m,y,"float64")}return p}function pa(r,t,e,n=!1){if(L(r.dtype,"nanquantile","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,i=r.offset,s=r.strides;if(e===void 0){let d=[];if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=Number(u[i+x]);isNaN(C)||d.push(C)}else for(let x=0;x<r.size;x++){let C=Number(r.iget(x));isNaN(C)||d.push(C)}if(d.length===0)return NaN;d.sort((x,C)=>x-C);let A=d.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)return d[h];let D=g-h;return d[h]*(1-D)+d[N]*D}let c=e;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let l=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return pa(r,t);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=[];for(let D=0;D<m;D++){let x=W(d,c,D,o),C=Z(x,s,i),w=Number(u[C]);isNaN(w)||b.push(w)}if(b.length===0){p[d]=NaN;continue}b.sort((D,x)=>D-x);let A=b.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)p[d]=b[h];else{let D=g-h;p[d]=b[h]*(1-D)+b[N]*D}}let y=S.fromData(p,l,"float64");if(n){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function Xm(r,t,e,n=!1){return pa(r,t/100,e,n)}function Le(r,t,e){let n=Ve(z(r),t,e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Ge(r,t,e){let n=ma(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function We(r,t,e){let n=au(z(r),t,e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Ye(r,t,e){let n=St(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}var Ze=Ye;function Je(r,t,e){let n=wt(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}var Xe=Je;function Ke(r,t,e){let n=Lm(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function Qe(r,t){let e=su(z(r),t);return typeof e=="number"?e:M(e)}function He(r,t){let e=iu(z(r),t);return typeof e=="number"?e:M(e)}function nt(r,t,e,n){let o=uu(z(r),t,e,n);return typeof o=="number"?o:M(o)}var ya=nt;function rn(r,t,e,n){let o=Vm(z(r),t,e,n);return typeof o=="number"?o:M(o)}function tn(r,t,e){let n=Gm(z(r),t,e);return typeof n=="number"?n:M(n)}function en(r,t,e,n){let o=Wm(z(r),t,e,n);return typeof o=="number"?o:M(o)}function nn(r,t,e,n){let o=je(z(r),t,e,n);return typeof o=="number"?o:M(o)}function on(r,t,e,n){let o=e?z(e):void 0,a=ia(z(r),t,o,n);return typeof a=="number"||a instanceof U?a:M(a)}function an(r,t,e){let n=cu(z(r),t,e);return typeof n=="boolean"?n:M(n)}function sn(r,t,e){let n=lu(z(r),t,e);return typeof n=="boolean"?n:M(n)}function un(r,t){return M(Pm(z(r),t))}function cn(r,t){return M(jm(z(r),t))}function ln(r,t,e){let n=fu(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function fn(r,t,e){let n=mu(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function mn(r,t,e){let n=pu(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function pn(r,t,e,n){let o=Pe(z(r),t,e,n);return typeof o=="number"?o:M(o)}function yn(r,t,e,n){let o=Ym(z(r),t,e,n);return typeof o=="number"?o:M(o)}function dn(r,t,e){let n=ua(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function bn(r,t,e){let n=ca(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function An(r,t){let e=la(z(r),t);return typeof e=="number"?e:M(e)}function gn(r,t){let e=fa(z(r),t);return typeof e=="number"?e:M(e)}function hn(r,t){return M(Zm(z(r),t))}function Nn(r,t){return M(Jm(z(r),t))}function Dn(r,t,e){let n=yu(z(r),t,e);return typeof n=="number"?n:M(n)}function xn(r,t,e,n){let o=pa(z(r),t,e,n);return typeof o=="number"?o:M(o)}function Cn(r,t,e,n){let o=Xm(z(r),t,e,n);return typeof o=="number"?o:M(o)}function zt(r){return r!==0&&r!==0n}function Rr(r,t){let e=r[t*2],n=r[t*2+1];return e!==0||n!==0}function Sn(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Qm(r,t){return typeof t=="number"?zD(r,t):Sn(r,t)?ID(r,t):Ir(r,t,(e,n)=>zt(e)&&zt(n))}function ID(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.offset,u=t.offset,i=r.size,s=O(r.dtype),c=O(t.dtype),l=B(r.dtype),f=B(t.dtype);if(l||f)for(let m=0;m<i;m++){let p=l?Rr(n,a+m):n[a+m]!==0,y=f?Rr(o,u+m):o[u+m]!==0;e[m]=p&&y?1:0}else if(s||c)for(let m=0;m<i;m++){let p=s?n[a+m]!==0n:n[a+m]!==0,y=c?o[u+m]!==0n:o[u+m]!==0;e[m]=p&&y?1:0}else for(let m=0;m<i;m++)e[m]=n[a+m]!==0&&o[u+m]!==0?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function zD(r,t){let e=new Uint8Array(r.size),n=t!==0,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(B(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=Rr(i,u+s)&&n?1:0}else if(O(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=i[u+s]!==0n&&n?1:0}else if(u===0)for(let i=0;i<o;i++)e[i]=a[i]!==0&&n?1:0;else for(let i=0;i<o;i++)e[i]=a[u+i]!==0&&n?1:0}else if(B(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a);e[a]=(u.re!==0||u.im!==0)&&n?1:0}else if(O(r.dtype))for(let a=0;a<o;a++)e[a]=r.iget(a)!==0n&&n?1:0;else for(let a=0;a<o;a++)e[a]=Number(r.iget(a))!==0&&n?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function Hm(r,t){if(typeof t=="number")return Km(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return Km(r,e)}return Sn(r,t)?_D(r,t):Ir(r,t,(e,n)=>zt(e)||zt(n))}function _D(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.offset,u=t.offset,i=r.size,s=O(r.dtype),c=O(t.dtype),l=B(r.dtype),f=B(t.dtype);if(l||f)for(let m=0;m<i;m++){let p=l?Rr(n,a+m):n[a+m]!==0,y=f?Rr(o,u+m):o[u+m]!==0;e[m]=p||y?1:0}else if(s||c)for(let m=0;m<i;m++){let p=s?n[a+m]!==0n:n[a+m]!==0,y=c?o[u+m]!==0n:o[u+m]!==0;e[m]=p||y?1:0}else for(let m=0;m<i;m++)e[m]=n[a+m]!==0||o[u+m]!==0?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function Km(r,t){let e=new Uint8Array(r.size),n=t!==0,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(B(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=Rr(i,u+s)||n?1:0}else if(O(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=i[u+s]!==0n||n?1:0}else if(u===0)for(let i=0;i<o;i++)e[i]=a[i]!==0||n?1:0;else for(let i=0;i<o;i++)e[i]=a[u+i]!==0||n?1:0}else if(B(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a);e[a]=u.re!==0||u.im!==0||n?1:0}else if(O(r.dtype))for(let a=0;a<o;a++)e[a]=r.iget(a)!==0n||n?1:0;else for(let a=0;a<o;a++)e[a]=Number(r.iget(a))!==0||n?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function rp(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++)t[u]=Rr(a,o+u)?0:1}else if(O(r.dtype)){let a=n;for(let u=0;u<e;u++)t[u]=a[o+u]===0n?1:0}else if(o===0)for(let a=0;a<e;a++)t[a]=n[a]===0?1:0;else for(let a=0;a<e;a++)t[a]=n[o+a]===0?1:0}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n);t[n]=o.re===0&&o.im===0?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=r.iget(n)===0n?1:0;else for(let n=0;n<e;n++)t[n]=Number(r.iget(n))===0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function tp(r,t){return typeof t=="number"?MD(r,t):Sn(r,t)?vD(r,t):Ir(r,t,(e,n)=>zt(e)!==zt(n))}function vD(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.offset,u=t.offset,i=r.size,s=O(r.dtype),c=O(t.dtype),l=B(r.dtype),f=B(t.dtype);if(l||f)for(let m=0;m<i;m++){let p=l?Rr(n,a+m):n[a+m]!==0,y=f?Rr(o,u+m):o[u+m]!==0;e[m]=p!==y?1:0}else if(s||c)for(let m=0;m<i;m++){let p=s?n[a+m]!==0n:n[a+m]!==0,y=c?o[u+m]!==0n:o[u+m]!==0;e[m]=p!==y?1:0}else for(let m=0;m<i;m++){let p=n[a+m]!==0,y=o[u+m]!==0;e[m]=p!==y?1:0}return S.fromData(e,Array.from(r.shape),"bool")}function MD(r,t){let e=new Uint8Array(r.size),n=t!==0,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(B(r.dtype)){let i=a;for(let s=0;s<o;s++){let c=Rr(i,u+s);e[s]=c!==n?1:0}}else if(O(r.dtype)){let i=a;for(let s=0;s<o;s++){let c=i[u+s]!==0n;e[s]=c!==n?1:0}}else if(u===0)for(let i=0;i<o;i++){let s=a[i]!==0;e[i]=s!==n?1:0}else for(let i=0;i<o;i++){let s=a[u+i]!==0;e[i]=s!==n?1:0}}else if(B(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a),i=u.re!==0||u.im!==0;e[a]=i!==n?1:0}else if(O(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a)!==0n;e[a]=u!==n?1:0}else for(let a=0;a<o;a++){let u=Number(r.iget(a))!==0;e[a]=u!==n?1:0}return S.fromData(e,Array.from(r.shape),"bool")}function ep(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++){let i=a[(o+u)*2],s=a[(o+u)*2+1];t[u]=Number.isFinite(i)&&Number.isFinite(s)?1:0}}else if(O(r.dtype))for(let a=0;a<e;a++)t[a]=1;else if(o===0)for(let a=0;a<e;a++)t[a]=Number.isFinite(n[a])?1:0;else for(let a=0;a<e;a++){let u=n[o+a];t[a]=Number.isFinite(u)?1:0}}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n);t[n]=Number.isFinite(o.re)&&Number.isFinite(o.im)?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=1;else for(let n=0;n<e;n++)t[n]=Number.isFinite(Number(r.iget(n)))?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function np(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++){let i=a[(o+u)*2],s=a[(o+u)*2+1],c=!Number.isFinite(i)&&!Number.isNaN(i),l=!Number.isFinite(s)&&!Number.isNaN(s);t[u]=c||l?1:0}}else if(O(r.dtype))for(let a=0;a<e;a++)t[a]=0;else if(o===0)for(let a=0;a<e;a++){let u=n[a];t[a]=!Number.isFinite(u)&&!Number.isNaN(u)?1:0}else for(let a=0;a<e;a++){let u=n[o+a];t[a]=!Number.isFinite(u)&&!Number.isNaN(u)?1:0}}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n),a=!Number.isFinite(o.re)&&!Number.isNaN(o.re),u=!Number.isFinite(o.im)&&!Number.isNaN(o.im);t[n]=a||u?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=0;else for(let n=0;n<e;n++){let o=Number(r.iget(n));t[n]=!Number.isFinite(o)&&!Number.isNaN(o)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function op(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++){let i=a[(o+u)*2],s=a[(o+u)*2+1];t[u]=Number.isNaN(i)||Number.isNaN(s)?1:0}}else if(O(r.dtype))for(let a=0;a<e;a++)t[a]=0;else for(let a=0;a<e;a++)t[a]=Number.isNaN(n[o+a])?1:0}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n);t[n]=Number.isNaN(o.re)||Number.isNaN(o.im)?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=0;else for(let n=0;n<e;n++)t[n]=Number.isNaN(Number(r.iget(n)))?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function ap(r){let t=new Uint8Array(r.size);return S.fromData(t,Array.from(r.shape),"bool")}function sp(r,t){if(L(r.dtype,"copysign","copysign is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"copysign","copysign is only defined for real numbers."),typeof t=="number")return BD(r,t);if(Sn(r,t))return FD(r,t);let e=Zr(r.shape,t.shape),n=e.reduce((s,c)=>s*c,1),o=S.zeros(e,"float64"),a=o.data,u=da(r,e),i=da(t,e);for(let s=0;s<n;s++){let c=Number(u.iget(s)),l=Number(i.iget(s));a[s]=Math.sign(l)*Math.abs(c)}return o}function FD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=O(r.dtype),l=O(t.dtype);for(let f=0;f<o;f++){let m=c?Number(a[i+f]):a[i+f],p=l?Number(u[s+f]):u[s+f];n[f]=Math.sign(p)*Math.abs(m)}return e}function BD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=Math.sign(t);if(!r.isCContiguous){for(let s=0;s<o;s++)n[s]=a*Math.abs(Number(r.iget(s)));return e}let u=r.data,i=r.offset;if(O(r.dtype)){let s=u;for(let c=0;c<o;c++)n[c]=a*Math.abs(Number(s[i+c]))}else if(i===0)for(let s=0;s<o;s++)n[s]=a*Math.abs(u[s]);else for(let s=0;s<o;s++)n[s]=a*Math.abs(u[i+s]);return e}function ip(r){L(r.dtype,"signbit","signbit is only defined for real numbers.");let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(O(r.dtype)){let a=n;for(let u=0;u<e;u++)t[u]=a[o+u]<0n?1:0}else for(let a=0;a<e;a++){let u=n[o+a];t[a]=u<0||Object.is(u,-0)?1:0}}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=r.iget(n)<0n?1:0;else for(let n=0;n<e;n++){let o=Number(r.iget(n));t[n]=o<0||Object.is(o,-0)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function up(r,t){if(L(r.dtype,"nextafter","nextafter is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"nextafter","nextafter is only defined for real numbers."),typeof t=="number")return OD(r,t);if(Sn(r,t))return TD(r,t);let e=Zr(r.shape,t.shape),n=e.reduce((s,c)=>s*c,1),o=S.zeros(e,"float64"),a=o.data,u=da(r,e),i=da(t,e);for(let s=0;s<n;s++){let c=Number(u.iget(s)),l=Number(i.iget(s));a[s]=It(c,l)}return o}function TD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=O(r.dtype),l=O(t.dtype);for(let f=0;f<o;f++){let m=c?Number(a[i+f]):a[i+f],p=l?Number(u[s+f]):u[s+f];n[f]=It(m,p)}return e}function OD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(O(r.dtype)){let i=a;for(let s=0;s<o;s++)n[s]=It(Number(i[u+s]),t)}else for(let i=0;i<o;i++)n[i]=It(a[u+i],t)}else for(let a=0;a<o;a++)n[a]=It(Number(r.iget(a)),t);return e}function It(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 cp(r){L(r.dtype,"spacing","spacing is only defined for real numbers.");let t=S.zeros(Array.from(r.shape),"float64"),e=t.data,n=r.size;if(r.isCContiguous){let o=r.data,a=r.offset;if(O(r.dtype)){let u=o;for(let i=0;i<n;i++)e[i]=du(Number(u[a+i]))}else for(let u=0;u<n;u++)e[u]=du(o[a+u])}else for(let o=0;o<n;o++)e[o]=du(Number(r.iget(o)));return t}function du(r){if(Number.isNaN(r))return NaN;if(!Number.isFinite(r))return NaN;if(Math.abs(r)===0)return Number.MIN_VALUE;let e=It(r,1/0);return Math.abs(e-r)}function da(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,i=r.shape[a],s=t[u];if(i===s)o[u]=r.strides[a];else if(i===1)o[u]=0;else throw new Error("Invalid broadcast")}return S.fromData(r.data,Array.from(t),r.dtype,o,r.offset)}function lp(r){let t=r.dtype,e=r.size,n=new Uint8Array(e);if(B(t))if(r.isCContiguous){let o=r.offset,a=r.data;for(let u=0;u<e;u++)n[u]=a[(o+u)*2+1]!==0?1:0}else for(let o=0;o<e;o++){let a=r.iget(o);n[o]=a.im!==0?1:0}return S.fromData(n,Array.from(r.shape),"bool")}function fp(r){return B(r.dtype)}function mp(r){let t=r.dtype,e=r.size,n=new Uint8Array(e);if(B(t))if(r.isCContiguous){let o=r.offset,a=r.data;for(let u=0;u<e;u++)n[u]=a[(o+u)*2+1]===0?1:0}else for(let o=0;o<e;o++){let a=r.iget(o);n[o]=a.im===0?1:0}else n.fill(1);return S.fromData(n,Array.from(r.shape),"bool")}function pp(r){return!B(r.dtype)}function yp(r){L(r.dtype,"isneginf","This operation is not supported for complex values because it would be ambiguous.");let t=new Uint8Array(r.size),e=r.size;if(!O(r.dtype))if(r.isCContiguous){let n=r.data,o=r.offset;for(let a=0;a<e;a++){let u=n[o+a];t[a]=u===-1/0?1:0}}else for(let n=0;n<e;n++)t[n]=Number(r.iget(n))===-1/0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function dp(r){L(r.dtype,"isposinf","This operation is not supported for complex values because it would be ambiguous.");let t=new Uint8Array(r.size),e=r.size;if(!O(r.dtype))if(r.isCContiguous){let n=r.data,o=r.offset;for(let a=0;a<e;a++){let u=n[o+a];t[a]=u===1/0?1:0}}else for(let n=0;n<e;n++)t[n]=Number(r.iget(n))===1/0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function bp(r){return r.isFContiguous}function Ap(r,t=100){let e=r.dtype;if(B(e)){let n=r.size,a=t*(e==="complex64"?11920929e-14:2220446049250313e-31);if(r.isCContiguous){let u=r.data,i=r.offset,s=!0;for(let c=0;c<n;c++){let l=u[(i+c)*2+1];if(Math.abs(l)>a){s=!1;break}}if(s){let c=e==="complex64"?"float32":"float64",l=S.zeros(Array.from(r.shape),c),f=l.data;for(let m=0;m<n;m++)f[m]=u[(i+m)*2];return l}}else{let u=!0;for(let i=0;i<n;i++){let s=r.iget(i);if(Math.abs(s.im)>a){u=!1;break}}if(u){let i=e==="complex64"?"float32":"float64",s=S.zeros(Array.from(r.shape),i),c=s.data;for(let l=0;l<n;l++){let f=r.iget(l);c[l]=f.re}return s}}return r.copy()}return r.copy()}function gp(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"||typeof r=="string"}function hp(r){return r==null?!1:typeof r[Symbol.iterator]=="function"}function Np(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 Dp(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 qr(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,i=u<0?1:a[u];if(i!==1){if(o===1)o=i;else if(o!==i)return null}}e[n]=o}return e}function UD(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let i=o-n+u,s=r[u],c=e[i];if(s===c)a[i]=t[u];else if(s===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function _r(r,t){let e=UD(r.shape,r.strides,t);return S.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function ot(r,t){return[r[t*2],r[t*2+1]]}function xp(r,t){if(B(r.dtype))return ot(r.data,t);let e=r.iget(t);return e instanceof U?[e.re,e.im]:[Number(e),0]}function _t(r,t,e){let n=qr([Array.from(r.shape),Array.from(t.shape)]);if(!n)throw new Error("Cannot broadcast arrays together");let o=_r(r,n),a=_r(t,n),u=n.reduce((s,c)=>s*c,1),i=new Uint8Array(u);for(let s=0;s<u;s++){let[c,l]=xp(o,s),[f,m]=xp(a,s);i[s]=e(c,l,f,m)?1:0}return S.fromData(i,n,"bool")}function Cp(r,t){return typeof t=="number"?$D(r,t):B(r.dtype)||B(t.dtype)?_t(r,t,(e,n,o,a)=>e!==o?e>o:n>a):Ir(r,t,(e,n)=>e>n)}function Sp(r,t){return typeof t=="number"?kD(r,t):B(r.dtype)||B(t.dtype)?_t(r,t,(e,n,o,a)=>e!==o?e>=o:n>=a):Ir(r,t,(e,n)=>e>=n)}function wp(r,t){return typeof t=="number"?RD(r,t):B(r.dtype)||B(t.dtype)?_t(r,t,(e,n,o,a)=>e!==o?e<o:n<a):Ir(r,t,(e,n)=>e<n)}function Ip(r,t){return typeof t=="number"?qD(r,t):B(r.dtype)||B(t.dtype)?_t(r,t,(e,n,o,a)=>e!==o?e<=o:n<=a):Ir(r,t,(e,n)=>e<=n)}function zp(r,t){return typeof t=="number"?VD(r,t):B(r.dtype)||B(t.dtype)?_t(r,t,(e,n,o,a)=>e===o&&n===a):Ir(r,t,(e,n)=>e===n)}function _p(r,t){return typeof t=="number"?PD(r,t):B(r.dtype)||B(t.dtype)?_t(r,t,(e,n,o,a)=>e!==o||n!==a):Ir(r,t,(e,n)=>e!==n)}function bu(r,t,e=1e-5,n=1e-8){return typeof t=="number"?jD(r,t,e,n):Ir(r,t,(o,a)=>{let u=Math.abs(o-a),i=n+e*Math.abs(a);return u<=i})}function vp(r,t,e=1e-5,n=1e-8){let o=bu(r,t,e,n),a=o.data;for(let u=0;u<o.size;u++)if(a[u]===0)return!1;return!0}function Mp(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=qr(e);if(n===null)return!1;let o=_r(r,n),a=_r(t,n),u=n.length,i=n.reduce((l,f)=>l*f,1),s=O(o.dtype),c=O(a.dtype);for(let l=0;l<i;l++){let f=l,m=new Array(u);for(let d=u-1;d>=0;d--)m[d]=f%n[d],f=Math.floor(f/n[d]);let p=o.get(...m),y=a.get(...m);if(s||c){let d=typeof p=="bigint"?p:BigInt(Number(p)),b=typeof y=="bigint"?y:BigInt(Number(y));if(d!==b)return!1}else if(p!==y)return!1}return!0}function $D(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s>t:c>0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re>t:u.im>0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]>t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))>t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function kD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s>=t:c>=0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re>=t:u.im>=0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]>=t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))>=t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function RD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s<t:c<0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re<t:u.im<0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]<t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))<t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function qD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s<=t:c<=0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re<=t:u.im<=0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]<=t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))<=t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function VD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.dtype,a=r.isCContiguous;if(B(o))if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++){let[c,l]=ot(u,i+s);e[s]=c===t&&l===0?1:0}}else for(let u=0;u<n;u++){let i=r.iget(u);e[u]=i.re===t&&i.im===0?1:0}else if(O(o)){let u=BigInt(Math.round(t));if(a){let i=r.data,s=r.offset;for(let c=0;c<n;c++)e[c]=i[s+c]===u?1:0}else for(let i=0;i<n;i++)e[i]=r.iget(i)===u?1:0}else if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++)e[s]=u[i+s]===t?1:0}else for(let u=0;u<n;u++)e[u]=Number(r.iget(u))===t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function PD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.dtype,a=r.isCContiguous;if(B(o))if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++){let[c,l]=ot(u,i+s);e[s]=c!==t||l!==0?1:0}}else for(let u=0;u<n;u++){let i=r.iget(u);e[u]=i.re!==t||i.im!==0?1:0}else if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++)e[s]=u[i+s]!==t?1:0}else for(let u=0;u<n;u++)e[u]=Number(r.iget(u))!==t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function jD(r,t,e,n){let o=new Uint8Array(r.size),a=r.size,u=n+e*Math.abs(t);if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<a;c++){let l=Math.abs(Number(i[s+c])-t);o[c]=l<=u?1:0}}else for(let i=0;i<a;i++){let s=Math.abs(Number(r.iget(i))-t);o[i]=s<=u?1:0}return S.fromData(o,Array.from(r.shape),"bool")}function wn(r,t){let e=typeof t=="number"?t:z(t);return M(Qm(z(r),e))}function In(r,t){let e=typeof t=="number"?t:z(t);return M(Hm(z(r),e))}function zn(r){return M(rp(z(r)))}function _n(r,t){let e=typeof t=="number"?t:z(t);return M(tp(z(r),e))}function vn(r){return M(ep(z(r)))}function Mn(r){return M(np(z(r)))}function Fn(r){return M(op(z(r)))}function Bn(r){return M(ap(z(r)))}function Au(r){return M(yp(z(r)))}function gu(r){return M(dp(z(r)))}function hu(r){return M(lp(z(r)))}function ba(r){return fp(z(r))}function Nu(r){return M(mp(z(r)))}function Aa(r){return pp(z(r))}function Du(r,t){return M(Ap(z(r),t))}function ga(r){return bp(z(r))}function ha(r){return gp(r)}function Na(r){return hp(r)}function Da(r,t){return Np(r,t)}function xa(r,t){return Dp(r,t)}function Tn(r,t){let e=typeof t=="number"?t:z(t);return M(sp(z(r),e))}function On(r){return M(ip(z(r)))}function En(r,t){let e=typeof t=="number"?t:z(t);return M(up(z(r),e))}function Un(r){return M(cp(z(r)))}function $n(r,t){return M(Cp(z(r),typeof t=="number"?t:z(t)))}function kn(r,t){return M(Sp(z(r),typeof t=="number"?t:z(t)))}function Rn(r,t){return M(wp(z(r),typeof t=="number"?t:z(t)))}function qn(r,t){return M(Ip(z(r),typeof t=="number"?t:z(t)))}function Vn(r,t){return M(zp(z(r),typeof t=="number"?t:z(t)))}function Pn(r,t){return M(_p(z(r),typeof t=="number"?t:z(t)))}function jn(r,t,e=1e-5,n=1e-8){return M(bu(z(r),typeof t=="number"?t:z(t),e,n))}function vt(r,t,e=1e-5,n=1e-8){return vp(z(r),typeof t=="number"?t:z(t),e,n)}function gr(r,t,e){if(e){let n=r[t*2],o=r[t*2+1];return n!==0||o!==0}return!!r[t]}function at(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 Bp(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data,u=r.offset,i=r.strides;if(n===0)return r.copy();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 c=r.copy(),l=c.data,f=e[s],m=Array.from(e).filter((y,d)=>d!==s),p=m.length===0?1:m.reduce((y,d)=>y*d,1);if(B(o)){let y=a,d=l;for(let b=0;b<p;b++){let A=[];for(let g=0;g<f;g++){let h=W(b,s,g,e),N=Z(h,i,u);A.push({re:y[N*2],im:y[N*2+1],idx:g})}A.sort((g,h)=>at(g.re,g.im,h.re,h.im));for(let g=0;g<f;g++){let h=W(b,s,g,e),N=xr(h,e);d[N*2]=A[g].re,d[N*2+1]=A[g].im}}}else if(O(o)){let y=a,d=l;for(let b=0;b<p;b++){let A=[];for(let g=0;g<f;g++){let h=W(b,s,g,e),N=Z(h,i,u);A.push({value:y[N],idx:g})}A.sort((g,h)=>g.value<h.value?-1:g.value>h.value?1:0);for(let g=0;g<f;g++){let h=W(b,s,g,e),N=xr(h,e);d[N]=A[g].value}}}else for(let y=0;y<p;y++){let d=[];for(let b=0;b<f;b++){let A=W(y,s,b,e),g=Z(A,i,u);d.push(Number(a[g]))}d.sort((b,A)=>isNaN(b)&&isNaN(A)?0:isNaN(b)?1:isNaN(A)?-1:b-A);for(let b=0;b<f;b++){let A=W(y,s,b,e),g=xr(A,e);l[g]=d[b]}}return c}function Tp(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data,u=r.offset,i=r.strides;if(n===0)return S.zeros([0],"int32");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 c=S.zeros(Array.from(e),"int32"),l=c.data,f=e[s],m=Array.from(e).filter((y,d)=>d!==s),p=m.length===0?1:m.reduce((y,d)=>y*d,1);if(B(o)){let y=a;for(let d=0;d<p;d++){let b=[];for(let A=0;A<f;A++){let g=W(d,s,A,e),h=Z(g,i,u);b.push({re:y[h*2],im:y[h*2+1],idx:A})}b.sort((A,g)=>at(A.re,A.im,g.re,g.im));for(let A=0;A<f;A++){let g=W(d,s,A,e),h=xr(g,e);l[h]=b[A].idx}}}else if(O(o)){let y=a;for(let d=0;d<p;d++){let b=[];for(let A=0;A<f;A++){let g=W(d,s,A,e),h=Z(g,i,u);b.push({value:y[h],idx:A})}b.sort((A,g)=>A.value<g.value?-1:A.value>g.value?1:0);for(let A=0;A<f;A++){let g=W(d,s,A,e),h=xr(g,e);l[h]=b[A].idx}}}else for(let y=0;y<p;y++){let d=[];for(let b=0;b<f;b++){let A=W(y,s,b,e),g=Z(A,i,u);d.push({value:Number(a[g]),idx:b})}d.sort((b,A)=>isNaN(b.value)&&isNaN(A.value)?0:isNaN(b.value)?1:isNaN(A.value)?-1:b.value-A.value);for(let b=0;b<f;b++){let A=W(y,s,b,e),g=xr(A,e);l[g]=d[b].idx}}return c}function Op(r){if(r.length===0)return S.zeros([0],"int32");let e=r[0].size;for(let l of r){if(l.ndim!==1)throw new Error("keys must be 1D arrays");if(l.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let l=0;l<e;l++)n.push(l);let o=r.map(l=>B(l.dtype)),a=r.map(l=>l.isCContiguous),u=r.map(l=>l.data),i=r.map(l=>l.offset);n.sort((l,f)=>{for(let m=r.length-1;m>=0;m--)if(o[m]){let p,y,d,b;if(a[m]){let A=u[m],g=i[m];p=A[(g+l)*2],y=A[(g+l)*2+1],d=A[(g+f)*2],b=A[(g+f)*2+1]}else{let A=r[m].iget(l),g=r[m].iget(f);p=A.re,y=A.im,d=g.re,b=g.im}if(p<d)return-1;if(p>d)return 1;if(y<b)return-1;if(y>b)return 1}else{let p,y;if(a[m]){let d=u[m],b=i[m];p=Number(d[b+l]),y=Number(d[b+f])}else p=Number(r[m].iget(l)),y=Number(r[m].iget(f));if(isNaN(p)&&isNaN(y))continue;if(isNaN(p))return 1;if(isNaN(y)||p<y)return-1;if(p>y)return 1}return 0});let s=S.zeros([e],"int32"),c=s.data;for(let l=0;l<e;l++)c[l]=n[l];return s}function LD(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],i=r[n],s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++){let m=r[f],p=isNaN(m),y=isNaN(c);!p&&(y||m<=c)&&([r[l],r[f]]=[r[f],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function GD(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],i=r[n],s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++)r[f]<=c&&([r[l],r[f]]=[r[f],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function WD(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,i=r[n].value,s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++){let m=r[f].value,p=isNaN(m),y=isNaN(c);!p&&(y||m<=c)&&([r[l],r[f]]=[r[f],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function YD(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,i=r[n].value,s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++)r[f].value<=c&&([r[l],r[f]]=[r[f],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function Ep(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 i=n[u],s=t;if(s<0&&(s=i+s),s<0||s>=i)throw new Error(`kth(=${t}) out of bounds (${i})`);let c=r.copy(),l=c.data,f=Array.from(n).filter((p,y)=>y!==u),m=f.length===0?1:f.reduce((p,y)=>p*y,1);if(O(a)){let p=l;for(let y=0;y<m;y++){let d=[];for(let b=0;b<i;b++){let A=W(y,u,b,n),g=xr(A,n);d.push(p[g])}GD(d,s);for(let b=0;b<i;b++){let A=W(y,u,b,n),g=xr(A,n);p[g]=d[b]}}}else for(let p=0;p<m;p++){let y=[];for(let d=0;d<i;d++){let b=W(p,u,d,n),A=xr(b,n);y.push(Number(l[A]))}LD(y,s);for(let d=0;d<i;d++){let b=W(p,u,d,n),A=xr(b,n);l[A]=y[d]}}return c}function Up(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,u=r.data,i=r.offset,s=r.strides;if(o===0)return S.zeros([0],"int32");let c=e;if(c<0&&(c=o+c),c<0||c>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let l=n[c],f=t;if(f<0&&(f=l+f),f<0||f>=l)throw new Error(`kth(=${t}) out of bounds (${l})`);let m=S.zeros(Array.from(n),"int32"),p=m.data,y=Array.from(n).filter((b,A)=>A!==c),d=y.length===0?1:y.reduce((b,A)=>b*A,1);if(O(a)){let b=u;for(let A=0;A<d;A++){let g=[];for(let h=0;h<l;h++){let N=W(A,c,h,n),D=Z(N,s,i);g.push({value:b[D],idx:h})}YD(g,f);for(let h=0;h<l;h++){let N=W(A,c,h,n),D=xr(N,n);p[D]=g[h].idx}}}else for(let b=0;b<d;b++){let A=[];for(let g=0;g<l;g++){let h=W(b,c,g,n),N=Z(h,s,i);A.push({value:Number(u[N]),idx:g})}WD(A,f);for(let g=0;g<l;g++){let h=W(b,c,g,n),N=xr(h,n);p[N]=A[g].idx}}return m}function $p(r){let t=r.dtype,e=r.size,n=r.isCContiguous,o=r.data,a=r.offset;if(B(t)){let u=[];if(n){let c=o;for(let l=0;l<e;l++)u.push({re:c[(a+l)*2],im:c[(a+l)*2+1]})}else for(let c=0;c<e;c++){let l=r.iget(c);u.push({re:l.re,im:l.im})}u.sort((c,l)=>at(c.re,c.im,l.re,l.im));let i=S.zeros([e],"complex128"),s=i.data;for(let c=0;c<e;c++)s[c*2]=u[c].re,s[c*2+1]=u[c].im;return i}else{let u=[];if(n)for(let c=0;c<e;c++)u.push(Number(o[a+c]));else for(let c=0;c<e;c++)u.push(Number(r.iget(c)));u.sort((c,l)=>isNaN(c)&&isNaN(l)?0:isNaN(c)?1:isNaN(l)?-1:c-l);let i=S.zeros([e],"complex128"),s=i.data;for(let c=0;c<e;c++)s[c*2]=u[c],s[c*2+1]=0;return i}}function xu(r){let t=r.shape,e=t.length,n=r.size,o=B(r.dtype),a=r.isCContiguous,u=r.data,i=r.offset,s=[];for(let p=0;p<e;p++)s.push([]);let c=[],l=1;for(let p=e-1;p>=0;p--)c.unshift(l),l*=t[p];if(a){for(let p=0;p<n;p++)if(gr(u,i+p,o)){let y=p;for(let d=0;d<e;d++){let b=Math.floor(y/c[d]);y=y%c[d],s[d].push(b)}}}else for(let p=0;p<n;p++){let y=r.iget(p);if(o?y.re!==0||y.im!==0:!!y){let b=p;for(let A=0;A<e;A++){let g=Math.floor(b/c[A]);b=b%c[A],s[A].push(g)}}}let f=s[0]?.length??0,m=[];for(let p=0;p<e;p++){let y=S.zeros([f],"int32"),d=y.data;for(let b=0;b<f;b++)d[b]=s[p][b];m.push(y)}return m}function kp(r){let t=r.shape,e=t.length,n=r.size,o=B(r.dtype),a=r.isCContiguous,u=r.data,i=r.offset,s=[],c=[],l=1;for(let d=e-1;d>=0;d--)c.unshift(l),l*=t[d];if(a){for(let d=0;d<n;d++)if(gr(u,i+d,o)){let b=[],A=d;for(let g=0;g<e;g++){let h=Math.floor(A/c[g]);A=A%c[g],b.push(h)}s.push(b)}}else for(let d=0;d<n;d++){let b=r.iget(d);if(o?b.re!==0||b.im!==0:!!b){let g=[],h=d;for(let N=0;N<e;N++){let D=Math.floor(h/c[N]);h=h%c[N],g.push(D)}s.push(g)}}let f=s.length,m=e===0?[f,1]:[f,e],p=S.zeros(m,"int32"),y=p.data;for(let d=0;d<f;d++){let b=s[d];for(let A=0;A<(e===0?1:e);A++)y[d*(e===0?1:e)+A]=b[A]??0}return p}function Rp(r){let t=r.size,e=B(r.dtype),n=r.isCContiguous,o=r.data,a=r.offset,u=[];if(n)for(let c=0;c<t;c++)gr(o,a+c,e)&&u.push(c);else for(let c=0;c<t;c++){let l=r.iget(c);(e?l.re!==0||l.im!==0:l)&&u.push(c)}let i=S.zeros([u.length],"int32"),s=i.data;for(let c=0;c<u.length;c++)s[c]=u[c];return i}function qp(r,t,e){if(t===void 0&&e===void 0)return xu(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),i=R=>{let Y=Array(u).fill(1);for(let J=0;J<R.length;J++)Y[u-R.length+J]=R[J];return Y},s=i(n),c=i(o),l=i(a),f=[];for(let R=0;R<u;R++){let Y=[s[R],c[R],l[R]],J=Math.max(...Y);for(let X of Y)if(X!==1&&X!==J)throw new Error("operands could not be broadcast together");f.push(J)}let m=t.dtype,p=S.zeros(f,m),y=p.data,d=(R,Y)=>{let J=[],X=1;for(let rr=R.length-1;rr>=0;rr--)J.unshift(X),X*=R[rr];for(;J.length<Y.length;)J.unshift(0);for(let rr=0;rr<Y.length;rr++)Y[rr]===1&&f[rr]!==1&&(J[rr]=0);return J},b=d(n,s),A=d(o,c),g=d(a,l),h=[],N=1;for(let R=f.length-1;R>=0;R--)h.unshift(N),N*=f[R];let D=f.reduce((R,Y)=>R*Y,1),x=B(r.dtype),C=B(m),w=r.isCContiguous,_=r.data,I=r.offset,v=t.isCContiguous,T=t.data,E=t.offset,$=e.isCContiguous,k=e.data,V=e.offset;if(n.length===f.length&&o.length===f.length&&a.length===f.length&&n.every((R,Y)=>R===f[Y])&&o.every((R,Y)=>R===f[Y])&&a.every((R,Y)=>R===f[Y])&&w&&v&&$)if(C){let R=y,Y=T,J=k;for(let X=0;X<D;X++)gr(_,I+X,x)?(R[X*2]=Y[(E+X)*2],R[X*2+1]=Y[(E+X)*2+1]):(R[X*2]=J[(V+X)*2],R[X*2+1]=J[(V+X)*2+1])}else if(O(m)){let R=y,Y=T,J=k;for(let X=0;X<D;X++)gr(_,I+X,x)?R[X]=Y[E+X]:R[X]=J[V+X]}else for(let R=0;R<D;R++)gr(_,I+R,x)?y[R]=T[E+R]:y[R]=k[V+R];else for(let R=0;R<D;R++){let Y=R,J=0,X=0,rr=0;for(let nr=0;nr<u;nr++){let dr=Math.floor(Y/h[nr]);Y=Y%h[nr],J+=dr*b[nr],X+=dr*A[nr],rr+=dr*g[nr]}let yr;if(w)yr=gr(_,I+J,x);else{let nr=r.iget(J);yr=x?nr.re!==0||nr.im!==0:!!nr}if(yr)if(C)if(v){let nr=T;y[R*2]=nr[(E+X)*2],y[R*2+1]=nr[(E+X)*2+1]}else{let nr=t.iget(X);y[R*2]=nr.re,y[R*2+1]=nr.im}else v?y[R]=T[E+X]:y[R]=t.iget(X);else if(C)if($){let nr=k;y[R*2]=nr[(V+rr)*2],y[R*2+1]=nr[(V+rr)*2+1]}else{let nr=e.iget(rr);y[R*2]=nr.re,y[R*2+1]=nr.im}else $?y[R]=k[V+rr]:y[R]=e.iget(rr)}return p}function Vp(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.size,o=t.size,a=B(r.dtype),u=r.isCContiguous,i=r.data,s=r.offset,c=t.isCContiguous,l=t.data,f=t.offset,m=S.zeros([o],"int32"),p=m.data;if(a)if(u&&c){let y=i,d=l;for(let b=0;b<o;b++){let A=d[(f+b)*2],g=d[(f+b)*2+1],h=0,N=n;if(e==="left")for(;h<N;){let D=Math.floor((h+N)/2),x=y[(s+D)*2],C=y[(s+D)*2+1];at(x,C,A,g)<0?h=D+1:N=D}else for(;h<N;){let D=Math.floor((h+N)/2),x=y[(s+D)*2],C=y[(s+D)*2+1];at(x,C,A,g)<=0?h=D+1:N=D}p[b]=h}}else for(let y=0;y<o;y++){let d=t.iget(y),b=d.re,A=d.im,g=0,h=n;if(e==="left")for(;g<h;){let N=Math.floor((g+h)/2),D=r.iget(N);at(D.re,D.im,b,A)<0?g=N+1:h=N}else for(;g<h;){let N=Math.floor((g+h)/2),D=r.iget(N);at(D.re,D.im,b,A)<=0?g=N+1:h=N}p[y]=g}else if(u&&c)for(let y=0;y<o;y++){let d=Number(l[f+y]),b=0,A=n;if(e==="left")for(;b<A;){let g=Math.floor((b+A)/2);Number(i[s+g])<d?b=g+1:A=g}else for(;b<A;){let g=Math.floor((b+A)/2);Number(i[s+g])<=d?b=g+1:A=g}p[y]=b}else for(let y=0;y<o;y++){let d=Number(t.iget(y)),b=0,A=n;if(e==="left")for(;b<A;){let g=Math.floor((b+A)/2);Number(r.iget(g))<d?b=g+1:A=g}else for(;b<A;){let g=Math.floor((b+A)/2);Number(r.iget(g))<=d?b=g+1:A=g}p[y]=b}return m}function Pp(r,t){let e=t.dtype,n=B(r.dtype),o=B(e),a=Math.min(r.size,t.size),u=r.isCContiguous,i=r.data,s=r.offset,c=t.isCContiguous,l=t.data,f=t.offset,m=0;if(u)for(let b=0;b<a;b++)gr(i,s+b,n)&&m++;else for(let b=0;b<a;b++){let A=r.iget(b);(n?A.re!==0||A.im!==0:A)&&m++}let p=S.zeros([m],e),y=p.data,d=0;if(u&&c)if(O(e)){let b=y,A=l;for(let g=0;g<a;g++)gr(i,s+g,n)&&(b[d++]=A[f+g])}else if(o){let b=y,A=l;for(let g=0;g<a;g++)gr(i,s+g,n)&&(b[d*2]=A[(f+g)*2],b[d*2+1]=A[(f+g)*2+1],d++)}else for(let b=0;b<a;b++)gr(i,s+b,n)&&(y[d++]=l[f+b]);else{let b=u?A=>gr(i,s+A,n):A=>{let g=r.iget(A);if(n){let h=g;return h.re!==0||h.im!==0}return!!g};if(O(e)){let A=y;for(let g=0;g<a;g++)b(g)&&(A[d++]=t.iget(g))}else if(o){let A=y;for(let g=0;g<a;g++)if(b(g)){let h=t.iget(g);A[d*2]=h.re,A[d*2+1]=h.im,d++}}else for(let A=0;A<a;A++)b(A)&&(y[d++]=t.iget(A))}return p}function Cu(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size,u=r.offset,i=r.strides,s=B(r.dtype),c=r.isCContiguous;if(t===void 0){let b=0;if(c)for(let A=0;A<a;A++)gr(o,u+A,s)&&b++;else for(let A=0;A<a;A++){let g=r.iget(A);if(s){let h=g;(h.re!==0||h.im!==0)&&b++}else g!==0&&g!==BigInt(0)&&b++}return b}let l=t;if(l<0&&(l=n+l),l<0||l>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let f=Array.from(e).filter((b,A)=>A!==l);if(f.length===0)return Cu(r);let m=S.zeros(f,"int32"),p=m.data,y=e[l],d=f.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=0;for(let g=0;g<y;g++){let h=W(b,l,g,e),N=Z(h,i,u);gr(o,N,s)&&A++}p[b]=A}return m}function Ln(r,t=-1){return M(Bp(z(r),t))}function Gn(r,t=-1){return M(Tp(z(r),t))}function Su(r){return M(Op(r.map(t=>z(t))))}function Wn(r,t,e=-1){return M(Ep(z(r),t,e))}function Yn(r,t,e=-1){return M(Up(z(r),t,e))}function wu(r){return M($p(z(r)))}function Zn(r){return $r(xu(z(r)))}function Jn(r){return M(kp(z(r)))}function Iu(r){return M(Rp(z(r)))}function Ca(r,t,e){let n=qp(z(r),t?z(t):void 0,e?z(e):void 0);return Array.isArray(n)?$r(n):M(n)}function Mt(r,t,e="left"){return M(Vp(z(r),z(t),e))}function zu(r,t){return M(Pp(z(r),z(t)))}function Sa(r,t){let e=Cu(z(r),t);return typeof e=="number"?e:M(e)}function vr(r,t){if(!Ur(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 Xn(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Gp(r,t){return vr(r.dtype,"bitwise_and"),typeof t=="number"?XD(r,t):(vr(t.dtype,"bitwise_and"),Xn(r,t)?JD(r,t):sr(r,t,(e,n)=>e&n,"bitwise_and"))}function JD(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[i+m]=="bigint"?a[i+m]:BigInt(Math.round(Number(a[i+m]))),y=typeof u[s+m]=="bigint"?u[s+m]:BigInt(Math.round(Number(u[s+m])));l[m]=p&y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[i+y]&p[s+y]}}else for(let l=0;l<o;l++)c[l]=a[i+l]&u[s+l];return n}function XD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]&f;else for(let p=0;p<u;p++)l[p]=m[a+p]&f}else for(let m=0;m<u;m++)l[m]=r.iget(m)&f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]&t;else for(let l=0;l<u;l++)c[l]=o[a+l]&t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))&t;return s}function Wp(r,t){return vr(r.dtype,"bitwise_or"),typeof t=="number"?QD(r,t):(vr(t.dtype,"bitwise_or"),Xn(r,t)?KD(r,t):sr(r,t,(e,n)=>e|n,"bitwise_or"))}function KD(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[i+m]=="bigint"?a[i+m]:BigInt(Math.round(Number(a[i+m]))),y=typeof u[s+m]=="bigint"?u[s+m]:BigInt(Math.round(Number(u[s+m])));l[m]=p|y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[i+y]|p[s+y]}}else for(let l=0;l<o;l++)c[l]=a[i+l]|u[s+l];return n}function QD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]|f;else for(let p=0;p<u;p++)l[p]=m[a+p]|f}else for(let m=0;m<u;m++)l[m]=r.iget(m)|f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]|t;else for(let l=0;l<u;l++)c[l]=o[a+l]|t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))|t;return s}function Yp(r,t){return vr(r.dtype,"bitwise_xor"),typeof t=="number"?rx(r,t):(vr(t.dtype,"bitwise_xor"),Xn(r,t)?HD(r,t):sr(r,t,(e,n)=>e^n,"bitwise_xor"))}function HD(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[i+m]=="bigint"?a[i+m]:BigInt(Math.round(Number(a[i+m]))),y=typeof u[s+m]=="bigint"?u[s+m]:BigInt(Math.round(Number(u[s+m])));l[m]=p^y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[i+y]^p[s+y]}}else for(let l=0;l<o;l++)c[l]=a[i+l]^u[s+l];return n}function rx(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]^f;else for(let p=0;p<u;p++)l[p]=m[a+p]^f}else for(let m=0;m<u;m++)l[m]=r.iget(m)^f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]^t;else for(let l=0;l<u;l++)c[l]=o[a+l]^t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))^t;return s}function Mu(r){vr(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.offset,a=r.size,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(O(t)){let c=s;if(u){let l=n;if(o===0)for(let f=0;f<a;f++)c[f]=~l[f];else for(let f=0;f<a;f++)c[f]=~l[o+f]}else for(let l=0;l<a;l++)c[l]=~r.iget(l)}else if(u)if(o===0)for(let c=0;c<a;c++)s[c]=~n[c];else for(let c=0;c<a;c++)s[c]=~n[o+c];else for(let c=0;c<a;c++)s[c]=~Number(r.iget(c));return i}function Zp(r){return Mu(r)}function Jp(r,t){if(vr(r.dtype,"left_shift"),typeof t=="number")return jp(r,t);if(vr(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=Number(t.iget(0));return jp(r,e)}return Xn(r,t)?tx(r,t):sr(r,t,(e,n)=>e<<n,"left_shift")}function tx(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;for(let f=0;f<o;f++){let m=typeof a[i+f]=="bigint"?a[i+f]:BigInt(Math.round(Number(a[i+f]))),p=typeof u[s+f]=="bigint"?u[s+f]:BigInt(Math.round(Number(u[s+f])));l[f]=m<<p}}else for(let l=0;l<o;l++)c[l]=a[i+l]<<u[s+l];return n}function jp(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]<<f;else for(let p=0;p<u;p++)l[p]=m[a+p]<<f}else for(let m=0;m<u;m++)l[m]=r.iget(m)<<f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]<<t;else for(let l=0;l<u;l++)c[l]=o[a+l]<<t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))<<t;return s}function Xp(r,t){if(vr(r.dtype,"right_shift"),typeof t=="number")return Lp(r,t);if(vr(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=Number(t.iget(0));return Lp(r,e)}return Xn(r,t)?ex(r,t):sr(r,t,(e,n)=>e>>n,"right_shift")}function ex(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;for(let f=0;f<o;f++){let m=typeof a[i+f]=="bigint"?a[i+f]:BigInt(Math.round(Number(a[i+f]))),p=typeof u[s+f]=="bigint"?u[s+f]:BigInt(Math.round(Number(u[s+f])));l[f]=m>>p}}else for(let l=0;l<o;l++)c[l]=a[i+l]>>u[s+l];return n}function Lp(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]>>f;else for(let p=0;p<u;p++)l[p]=m[a+p]>>f}else for(let m=0;m<u;m++)l[m]=r.iget(m)>>f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]>>t;else for(let l=0;l<u;l++)c[l]=o[a+l]>>t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))>>t;return s}function Kp(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),i=[...n];i[t]=u;let s=S.zeros(i,"uint8"),c=s.data,l=r.offset,f=r.isCContiguous;if(o===1){for(let g=0;g<u;g++){let h=0;for(let N=0;N<8;N++){let D=g*8+N;if(D<a){let x=f?Number(r.data[l+D])!==0?1:0:Number(r.iget(D))!==0?1:0;e==="big"?h|=x<<7-N:h|=x<<N}}c[g]=h}return s}let m=n.slice(0,t),p=n.slice(t+1),y=m.reduce((g,h)=>g*h,1),d=p.reduce((g,h)=>g*h,1),b=wa(n),A=wa(i);for(let g=0;g<y;g++)for(let h=0;h<d;h++)for(let N=0;N<u;N++){let D=0;for(let _=0;_<8;_++){let I=N*8+_;if(I<a){let v=0,T=g;for(let k=0;k<t;k++){let V=k<t-1?m.slice(k+1).reduce((R,Y)=>R*Y,1):1,j=Math.floor(T/V);T%=V,v+=j*b[k]}v+=I*b[t];let E=h;for(let k=t+1;k<o;k++){let V=k<o-1?p.slice(k-t).reduce((R,Y)=>R*Y,1):1,j=Math.floor(E/V);E%=V,v+=j*b[k]}let $=f?Number(r.data[l+v])!==0?1:0:Number(r.iget(v))!==0?1:0;e==="big"?D|=$<<7-_:D|=$<<_}}let x=0,C=g;for(let _=0;_<t;_++){let I=_<t-1?m.slice(_+1).reduce((T,E)=>T*E,1):1,v=Math.floor(C/I);C%=I,x+=v*A[_]}x+=N*A[t];let w=h;for(let _=t+1;_<o;_++){let I=_<o-1?p.slice(_-t).reduce((T,E)=>T*E,1):1,v=Math.floor(w/I);w%=I,x+=v*A[_]}c[x]=D}return s}function Qp(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],i=u*8;e>=0&&(i=e);let s=[...o];s[t]=i;let c=S.zeros(s,"uint8"),l=c.data,f=r.offset,m=r.isCContiguous;if(a===1){for(let h=0;h<u;h++){let N=Number(m?r.data[f+h]:r.iget(h));for(let D=0;D<8;D++){let x=h*8+D;if(x>=i)break;n==="big"?l[x]=N>>7-D&1:l[x]=N>>D&1}}return c}let p=o.slice(0,t),y=o.slice(t+1),d=p.reduce((h,N)=>h*N,1),b=y.reduce((h,N)=>h*N,1),A=wa(o),g=wa(s);for(let h=0;h<d;h++)for(let N=0;N<b;N++)for(let D=0;D<u;D++){let x=0,C=h;for(let I=0;I<t;I++){let v=I<t-1?p.slice(I+1).reduce((E,$)=>E*$,1):1,T=Math.floor(C/v);C%=v,x+=T*A[I]}x+=D*A[t];let w=N;for(let I=t+1;I<a;I++){let v=I<a-1?y.slice(I-t).reduce((E,$)=>E*$,1):1,T=Math.floor(w/v);w%=v,x+=T*A[I]}let _=Number(m?r.data[f+x]:r.iget(x));for(let I=0;I<8;I++){let v=D*8+I;if(v>=i)break;let T=0;C=h;for(let E=0;E<t;E++){let $=E<t-1?p.slice(E+1).reduce((V,j)=>V*j,1):1,k=Math.floor(C/$);C%=$,T+=k*g[E]}T+=v*g[t],w=N;for(let E=t+1;E<a;E++){let $=E<a-1?y.slice(E-t).reduce((V,j)=>V*j,1):1,k=Math.floor(w/$);w%=$,T+=k*g[E]}n==="big"?l[T]=_>>7-I&1:l[T]=_>>I&1}}return c}function wa(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 Hp(r){let t=r.dtype;vr(t,"bitwise_count");let e=Array.from(r.shape),n=r.data,o=r.offset,a=r.size,u=r.isCContiguous,i=S.zeros(e,"uint8"),s=i.data;if(O(t))if(u){let c=n;if(o===0)for(let l=0;l<a;l++)s[l]=vu(c[l]);else for(let l=0;l<a;l++)s[l]=vu(c[o+l])}else for(let c=0;c<a;c++)s[c]=vu(r.iget(c));else if(u)if(o===0)for(let c=0;c<a;c++)s[c]=_u(n[c]);else for(let c=0;c<a;c++)s[c]=_u(n[o+c]);else for(let c=0;c<a;c++)s[c]=_u(Number(r.iget(c)));return i}function _u(r){r=r>>>0;let t=0;for(;r!==0;)r=r&r-1,t++;return t}function vu(r){r<0n&&(r=BigInt.asUintN(64,r));let t=0;for(;r!==0n;)r=r&r-1n,t++;return t}function Kn(r,t){let e=typeof t=="number"?t:z(t);return M(Gp(z(r),e))}function Qn(r,t){let e=typeof t=="number"?t:z(t);return M(Wp(z(r),e))}function Hn(r,t){let e=typeof t=="number"?t:z(t);return M(Yp(z(r),e))}function ro(r){return M(Mu(z(r)))}function to(r){return M(Zp(z(r)))}function eo(r,t){let e=typeof t=="number"?t:z(t);return M(Jp(z(r),e))}function no(r,t){let e=typeof t=="number"?t:z(t);return M(Xp(z(r),e))}function Fu(r,t,e){return M(Kp(z(r),t,e))}function Bu(r,t,e,n){return M(Qp(z(r),t,e,n))}function Tu(r){return M(Hp(z(r)))}function Ia(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 ry(r,t=0){L(r.dtype,"around","Rounding is not defined for complex numbers.");let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=S.zeros(n,a),i=u.data,s=Math.pow(10,t);if(r.isCContiguous){let c=r.data,l=r.offset;for(let f=0;f<o;f++){let m=Number(c[l+f]);i[f]=Ia(m*s)/s}}else for(let c=0;c<o;c++){let l=Number(r.iget(c));i[c]=Ia(l*s)/s}return u}function ty(r){L(r.dtype,"ceil","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.ceil(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.ceil(Number(r.iget(i)));return a}function ey(r){L(r.dtype,"fix","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.trunc(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.trunc(Number(r.iget(i)));return a}function ny(r){L(r.dtype,"floor","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.floor(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.floor(Number(r.iget(i)));return a}function oy(r){L(r.dtype,"rint","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Ia(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Ia(Number(r.iget(i)));return a}function ay(r){L(r.dtype,"trunc","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.trunc(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.trunc(Number(r.iget(i)));return a}function Ft(r,t=0){return M(ry(z(r),t))}var za=Ft;function oo(r){return M(ty(z(r)))}function ao(r){return M(ey(z(r)))}function so(r){return M(ny(z(r)))}function io(r){return M(oy(z(r)))}function uo(r){return M(ay(z(r)))}function Ou(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 ax(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 Cr(r,t=!1,e=!1,n=!1){let o=r.dtype,a=r.size,u=r.data,i=r.offset;if(B(o)){let N=u,D=[];for(let R=0;R<a;R++)D.push({re:N[(i+R)*2],im:N[(i+R)*2+1],index:R});D.sort((R,Y)=>Ou(R.re,R.im,Y.re,Y.im));let x=[],C=[],w=new Array(a),_=[],I,v,T=0;for(let R=0;R<D.length;R++){let{re:Y,im:J,index:X}=D[R];I===void 0||!ax(Y,J,I,v)?(I!==void 0&&_.push(T),x.push({re:Y,im:J}),C.push(X),T=1,I=Y,v=J):T++}T>0&&_.push(T);let E=new Map,$=-1;for(let R=0;R<x.length;R++){let{re:Y,im:J}=x[R];isNaN(Y)||isNaN(J)?$=R:E.set(`${Y},${J}`,R)}for(let R=0;R<a;R++){let Y=N[(i+R)*2],J=N[(i+R)*2+1];isNaN(Y)||isNaN(J)?w[R]=$:w[R]=E.get(`${Y},${J}`)}let k=S.zeros([x.length],o),V=k.data;for(let R=0;R<x.length;R++)V[R*2]=x[R].re,V[R*2+1]=x[R].im;if(!t&&!e&&!n)return k;let j={values:k};if(t){let R=S.zeros([C.length],"int32"),Y=R.data;for(let J=0;J<C.length;J++)Y[J]=C[J];j.indices=R}if(e){let R=S.zeros([w.length],"int32"),Y=R.data;for(let J=0;J<w.length;J++)Y[J]=w[J];j.inverse=R}if(n){let R=S.zeros([_.length],"int32"),Y=R.data;for(let J=0;J<_.length;J++)Y[J]=_[J];j.counts=R}return j}let s=[];for(let N=0;N<a;N++)s.push({value:Number(u[i+N]),index:N});s.sort((N,D)=>isNaN(N.value)&&isNaN(D.value)?0:isNaN(N.value)?1:isNaN(D.value)?-1:N.value-D.value);let c=[],l=[],f=new Array(a),m=[],p,y=0;for(let N=0;N<s.length;N++){let{value:D,index:x}=s[N];p===void 0||isNaN(D)&&!isNaN(p)||!isNaN(D)&&isNaN(p)||!isNaN(D)&&!isNaN(p)&&D!==p?(p!==void 0&&m.push(y),c.push(D),l.push(x),y=1,p=D):y++}y>0&&m.push(y);let d=new Map,b=-1;for(let N=0;N<c.length;N++){let D=c[N];isNaN(D)?b=N:d.set(D,N)}for(let N=0;N<a;N++){let D=Number(u[i+N]);isNaN(D)?f[N]=b:f[N]=d.get(D)}let A=S.zeros([c.length],o),g=A.data;for(let N=0;N<c.length;N++)g[N]=c[N];if(!t&&!e&&!n)return A;let h={values:A};if(t){let N=S.zeros([l.length],"int32"),D=N.data;for(let x=0;x<l.length;x++)D[x]=l[x];h.indices=N}if(e){let N=S.zeros([f.length],"int32"),D=N.data;for(let x=0;x<f.length;x++)D[x]=f[x];h.inverse=N}if(n){let N=S.zeros([m.length],"int32"),D=N.data;for(let x=0;x<m.length;x++)D[x]=m[x];h.counts=N}return h}function Vr(r,t,e,n=0){if(e){let o=Number(r[(n+t)*2]),a=Number(r[(n+t)*2+1]);return`${o},${a}`}return String(Number(r[n+t]))}function sy(r,t){return Eu(r,t)}function iy(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=Cr(t),u=new Set;for(let l=0;l<a.size;l++)u.add(Vr(a.data,l,n));let i=[];for(let l=0;l<o.size;l++){let f=Vr(o.data,l,n);u.has(f)&&i.push(l)}if(n){let l=S.zeros([i.length],e),f=l.data,m=o.data;for(let p=0;p<i.length;p++){let y=i[p];f[p*2]=m[y*2],f[p*2+1]=m[y*2+1]}return l}let s=S.zeros([i.length],e),c=s.data;for(let l=0;l<i.length;l++)c[l]=o.data[i[l]];return s}function Eu(r,t){let e=Array.from(r.shape),n=r.size,o=B(r.dtype),a=new Set;for(let s=0;s<t.size;s++)a.add(Vr(t.data,s,o,t.offset));let u=S.zeros(e,"bool"),i=u.data;for(let s=0;s<n;s++){let c=Vr(r.data,s,o,r.offset);i[s]=a.has(c)?1:0}return u}function uy(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=new Set;for(let c=0;c<t.size;c++)a.add(Vr(t.data,c,n,t.offset));let u=[];for(let c=0;c<o.size;c++){let l=Vr(o.data,c,n);a.has(l)||u.push(c)}if(n){let c=S.zeros([u.length],e),l=c.data,f=o.data;for(let m=0;m<u.length;m++){let p=u[m];l[m*2]=f[p*2],l[m*2+1]=f[p*2+1]}return c}let i=S.zeros([u.length],e),s=i.data;for(let c=0;c<u.length;c++)s[c]=o.data[u[c]];return i}function cy(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=Cr(t),u=new Set,i=new Set;for(let p=0;p<o.size;p++)u.add(Vr(o.data,p,n));for(let p=0;p<a.size;p++)i.add(Vr(a.data,p,n));let s=[],c=[];for(let p=0;p<o.size;p++){let y=Vr(o.data,p,n);i.has(y)||s.push(p)}for(let p=0;p<a.size;p++){let y=Vr(a.data,p,n);u.has(y)||c.push(p)}if(n){let p=[],y=o.data,d=a.data;for(let g of s)p.push({re:y[g*2],im:y[g*2+1]});for(let g of c)p.push({re:d[g*2],im:d[g*2+1]});p.sort((g,h)=>Ou(g.re,g.im,h.re,h.im));let b=S.zeros([p.length],e),A=b.data;for(let g=0;g<p.length;g++)A[g*2]=p[g].re,A[g*2+1]=p[g].im;return b}let l=[];for(let p of s)l.push(Number(o.data[p]));for(let p of c)l.push(Number(a.data[p]));l.sort((p,y)=>isNaN(p)&&isNaN(y)?0:isNaN(p)?1:isNaN(y)?-1:p-y);let f=S.zeros([l.length],e),m=f.data;for(let p=0;p<l.length;p++)m[p]=l[p];return f}function ly(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=Cr(t),u=new Set,i=[];if(n){let f=o.data,m=a.data;for(let d=0;d<o.size;d++){let b=f[d*2],A=f[d*2+1],g=`${b},${A}`;u.has(g)||(u.add(g),i.push({re:b,im:A}))}for(let d=0;d<a.size;d++){let b=m[d*2],A=m[d*2+1],g=`${b},${A}`;u.has(g)||(u.add(g),i.push({re:b,im:A}))}i.sort((d,b)=>Ou(d.re,d.im,b.re,b.im));let p=S.zeros([i.length],e),y=p.data;for(let d=0;d<i.length;d++)y[d*2]=i[d].re,y[d*2+1]=i[d].im;return p}let s=[];for(let f=0;f<o.size;f++){let m=Number(o.data[f]),p=String(m);u.has(p)||(u.add(p),s.push(m))}for(let f=0;f<a.size;f++){let m=Number(a.data[f]),p=String(m);u.has(p)||(u.add(p),s.push(m))}s.sort((f,m)=>isNaN(f)&&isNaN(m)?0:isNaN(f)?1:isNaN(m)?-1:f-m);let c=S.zeros([s.length],e),l=c.data;for(let f=0;f<s.length;f++)l[f]=s[f];return c}function fy(r,t="fb"){let e=r.dtype,n=r.data,o=r.size,a=r.offset,u=B(e);if(o===0)return S.zeros([0],e);let i=p=>{if(u){let y=n[(a+p)*2],d=n[(a+p)*2+1];return y===0&&d===0}return Number(n[a+p])===0},s=0;if(t==="f"||t==="fb")for(;s<o&&i(s);)s++;let c=o-1;if(t==="b"||t==="fb")for(;c>=s&&i(c);)c--;if(s>c)return S.zeros([0],e);let l=c-s+1;if(u){let p=S.zeros([l],e),y=p.data;for(let d=0;d<l;d++)y[d*2]=n[(a+s+d)*2],y[d*2+1]=n[(a+s+d)*2+1];return p}let f=S.zeros([l],e),m=f.data;for(let p=0;p<l;p++)m[p]=n[a+s+p];return f}function my(r){let e=Cr(r,!0,!0,!0);return{values:e.values,indices:e.indices,inverse_indices:e.inverse,counts:e.counts}}function py(r){let e=Cr(r,!1,!1,!0);return{values:e.values,counts:e.counts}}function yy(r){let e=Cr(r,!1,!0,!1);return{values:e.values,inverse_indices:e.inverse}}function dy(r){return Cr(r)}function _a(r,t=!1,e=!1,n=!1){let o=Cr(z(r),t,e,n);return"values"in o?{values:M(o.values),indices:o.indices?M(o.indices):void 0,inverse:o.inverse?M(o.inverse):void 0,counts:o.counts?M(o.counts):void 0}:M(o)}function Uu(r,t){return M(sy(z(r),z(t)))}function $u(r,t){return M(iy(z(r),z(t)))}function ku(r,t){return M(Eu(z(r),z(t)))}function Ru(r,t){return M(uy(z(r),z(t)))}function qu(r,t){return M(cy(z(r),z(t)))}function Vu(r,t){return M(ly(z(r),z(t)))}function Pu(r,t){return M(fy(z(r),t))}function va(r){let t=my(z(r));return{values:M(t.values),indices:M(t.indices),inverse_indices:M(t.inverse_indices),counts:M(t.counts)}}function Ma(r){let t=py(z(r));return{values:M(t.values),counts:M(t.counts)}}function Fa(r){let t=yy(z(r));return{values:M(t.values),inverse_indices:M(t.inverse_indices)}}function ju(r){return M(dy(z(r)))}function by(r,t,e=0){L(r.dtype,"bincount","bincount requires integer input.");let n=r.data,o=r.size,a=0;for(let i=0;i<o;i++){let s=Number(n[i]);if(s<0||!Number.isInteger(s))throw new Error("'x' argument must contain non-negative integers");s>a&&(a=s)}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 i=t.data,s=new Float64Array(u);for(let c=0;c<o;c++){let l=Number(n[c]);s[l]+=Number(i[c])}return S.fromData(s,[u],"float64")}else{let i=new Float64Array(u);for(let s=0;s<o;s++){let c=Number(n[s]);i[c]++}return S.fromData(i,[u],"float64")}}function Ay(r,t,e=!1){L(r.dtype,"digitize","digitize requires real numbers."),L(t.dtype,"digitize","digitize requires real numbers.");let n=r.data,o=t.data,a=r.size,u=t.size,i=new Float64Array(a),s=!0;u>1&&(s=Number(o[1])>=Number(o[0]));for(let c=0;c<a;c++){let l=Number(n[c]),f;if(s)e?f=ix(o,u,l):f=co(o,u,l);else if(e)for(f=0;f<u&&Number(o[f])>=l;)f++;else for(f=0;f<u&&Number(o[f])>l;)f++;i[c]=f}return S.fromData(i,[...r.shape],"float64")}function ix(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 co(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 gy(r,t=10,e,n=!1,o){L(r.dtype,"histogram","histogram requires real numbers."),typeof t!="number"&&L(t.dtype,"histogram","histogram requires real numbers.");let a=r.data,u=r.size,i;if(typeof t=="number"){let f,m;if(e)[f,m]=e;else{f=1/0,m=-1/0;for(let y=0;y<u;y++){let d=Number(a[y]);d<f&&(f=d),d>m&&(m=d)}f===m&&(f=f-.5,m=m+.5)}i=[];let p=(m-f)/t;for(let y=0;y<=t;y++)i.push(f+y*p)}else{let f=t.data;i=[];for(let m=0;m<t.size;m++)i.push(Number(f[m]))}let s=i.length-1,c=new Float64Array(s),l=o?.data;for(let f=0;f<u;f++){let m=Number(a[f]),p=l?Number(l[f]):1,y=co(i,i.length,m)-1;if(!(y<0)){if(y>=s)if(m===i[s])y=s-1;else continue;c[y]+=p}}if(n){let f=0;for(let m=0;m<s;m++)f+=c[m];for(let m=0;m<s;m++){let p=i[m+1]-i[m];c[m]=c[m]/(f*p)}}return{hist:S.fromData(c,[s],"float64"),bin_edges:S.fromData(new Float64Array(i),[i.length],"float64")}}function hy(r,t,e=10,n,o=!1,a){L(r.dtype,"histogram2d","histogram2d requires real numbers."),L(t.dtype,"histogram2d","histogram2d requires real numbers.");let u=r.data,i=t.data,s=r.size;if(t.size!==s)throw new Error("x and y must have the same length");let c,l,f,m;if(typeof e=="number"?(f=e,m=e):Array.isArray(e)&&e.length===2?(e[0],f=e[0],m=e[1]):(f=10,m=10),typeof f=="number"){let A,g;if(n)[A,g]=n[0];else{A=1/0,g=-1/0;for(let N=0;N<s;N++){let D=Number(u[N]);D<A&&(A=D),D>g&&(g=D)}A===g&&(A-=.5,g+=.5)}c=[];let h=(g-A)/f;for(let N=0;N<=f;N++)c.push(A+N*h)}else{let A=f.data;c=[];for(let g=0;g<f.size;g++)c.push(Number(A[g]))}if(typeof m=="number"){let A,g;if(n)[A,g]=n[1];else{A=1/0,g=-1/0;for(let N=0;N<s;N++){let D=Number(i[N]);D<A&&(A=D),D>g&&(g=D)}A===g&&(A-=.5,g+=.5)}l=[];let h=(g-A)/m;for(let N=0;N<=m;N++)l.push(A+N*h)}else{let A=m.data;l=[];for(let g=0;g<m.size;g++)l.push(Number(A[g]))}let p=c.length-1,y=l.length-1,d=new Float64Array(p*y),b=a?.data;for(let A=0;A<s;A++){let g=Number(u[A]),h=Number(i[A]),N=b?Number(b[A]):1,D=co(c,c.length,g)-1,x=co(l,l.length,h)-1;if(D<0||D>=p)if(g===c[p]&&D===p)D=p-1;else continue;if(x<0||x>=y)if(h===l[y]&&x===y)x=y-1;else continue;d[D*y+x]+=N}if(o){let A=0;for(let g=0;g<d.length;g++)A+=d[g];for(let g=0;g<p;g++)for(let h=0;h<y;h++){let N=c[g+1]-c[g],D=l[h+1]-l[h],x=N*D;d[g*y+h]=d[g*y+h]/(A*x)}}return{hist:S.fromData(d,[p,y],"float64"),x_edges:S.fromData(new Float64Array(c),[c.length],"float64"),y_edges:S.fromData(new Float64Array(l),[l.length],"float64")}}function Ny(r,t=10,e,n=!1,o){L(r.dtype,"histogramdd","histogramdd requires real numbers.");let a=r.shape,u=r.data,i,s;if(a.length===1)i=a[0],s=1;else if(a.length===2)i=a[0],s=a[1];else throw new Error("sample must be 1D or 2D array");let c;if(typeof t=="number")c=new Array(s).fill(t);else if(c=t,c.length!==s)throw new Error("bins array length must match number of dimensions");let l=[];for(let A=0;A<s;A++){let g,h;if(e&&e[A])[g,h]=e[A];else{g=1/0,h=-1/0;for(let C=0;C<i;C++){let w=Number(s===1?u[C]:u[C*s+A]);w<g&&(g=w),w>h&&(h=w)}g===h&&(g-=.5,h+=.5)}let N=c[A],D=[],x=(h-g)/N;for(let C=0;C<=N;C++)D.push(g+C*x);l.push(D)}let f=c.slice(),m=f.reduce((A,g)=>A*g,1),p=new Float64Array(m),y=new Array(s);y[s-1]=1;for(let A=s-2;A>=0;A--)y[A]=y[A+1]*c[A+1];let d=o?.data;for(let A=0;A<i;A++){let g=d?Number(d[A]):1,h=0,N=!1;for(let D=0;D<s;D++){let x=Number(s===1?u[A]:u[A*s+D]),C=l[D],w=c[D],_=co(C,C.length,x)-1;if(_<0||_>=w)if(x===C[w]&&_===w)_=w-1;else{N=!0;break}h+=_*y[D]}N||(p[h]+=g)}if(n){let A=0;for(let h=0;h<m;h++)A+=p[h];let g=new Float64Array(m);for(let h=0;h<m;h++){let N=1,D=h;for(let x=0;x<s;x++){let C=Math.floor(D/y[x])%c[x],w=l[x];N*=w[C+1]-w[C]}g[h]=N}for(let h=0;h<m;h++)p[h]=p[h]/(A*g[h])}let b=l.map(A=>S.fromData(new Float64Array(A),[A.length],"float64"));return{hist:S.fromData(p,f,"float64"),edges:b}}function Gu(r,t,e="full"){let n=r.data,o=t.data,a=r.size,u=t.size,i=B(r.dtype)||B(t.dtype),s=a+u-1;if(i){let l=new Float64Array(s),f=new Float64Array(s),m=B(r.dtype),p=B(t.dtype);for(let d=0;d<s;d++){let b=0,A=0,g=d-u+1;for(let h=0;h<a;h++){let N=h-g;if(N>=0&&N<u){let D,x,C,w;m?(D=n[h*2],x=n[h*2+1]):(D=Number(n[h]),x=0),p?(C=o[N*2],w=o[N*2+1]):(C=Number(o[N]),w=0),b+=D*C+x*w,A+=x*C-D*w}}l[d]=b,f[d]=A}let y=(d,b,A,g=0)=>{let h=new Float64Array(A*2);for(let N=0;N<A;N++)h[N*2]=d[g+N],h[N*2+1]=b[g+N];return S.fromData(h,[A],"complex128")};if(e==="full")return y(l,f,s);if(e==="same"){let d=Math.floor((s-a)/2);return y(l,f,a,d)}else{let d=Math.max(a,u)-Math.min(a,u)+1,b=Math.min(a,u)-1;return y(l,f,d,b)}}let c=new Float64Array(s);for(let l=0;l<s;l++){let f=0,m=l-u+1;for(let p=0;p<a;p++){let y=p-m;y>=0&&y<u&&(f+=Number(n[p])*Number(o[y]))}c[l]=f}if(e==="full")return S.fromData(c,[s],"float64");if(e==="same"){let l=Math.floor((s-a)/2),f=new Float64Array(a);for(let m=0;m<a;m++)f[m]=c[l+m];return S.fromData(f,[a],"float64")}else{let l=Math.max(a,u)-Math.min(a,u)+1,f=Math.min(a,u)-1,m=new Float64Array(l);for(let p=0;p<l;p++)m[p]=c[f+p];return S.fromData(m,[l],"float64")}}function Dy(r,t,e="full"){let n=t.data,o=t.size,a=B(t.dtype),u;if(a){let i=new Float64Array(o*2);for(let s=0;s<o;s++){let c=o-1-s;i[s*2]=n[c*2],i[s*2+1]=n[c*2+1]}u=S.fromData(i,[o],t.dtype)}else{let i=new Float64Array(o);for(let s=0;s<o;s++)i[s]=Number(n[o-1-s]);u=S.fromData(i,[o],"float64")}if(a){let i=u.data;for(let s=0;s<o;s++)i[s*2+1]=-i[s*2+1]}return Gu(r,u,e)}function Wu(r,t,e=!0,n=!1,o){let a=r.shape,u=r.data,i=B(r.dtype)||t!==void 0&&B(t.dtype),s;if(o!==void 0?s=o:s=n?0:1,a.length===1)if(t!==void 0){let y=t.data,d=r.size,b=B(r.dtype),A=B(t.dtype);if(t.size!==d)throw new Error("m and y must have same length");if(i){let w=0,_=0,I=0,v=0;for(let rr=0;rr<d;rr++)b?(w+=u[rr*2],_+=u[rr*2+1]):w+=Number(u[rr]),A?(I+=y[rr*2],v+=y[rr*2+1]):I+=Number(y[rr]);w/=d,_/=d,I/=d,v/=d;let T=0,E=0,$=0,k=0,V=0,j=0,R=0,Y=0;for(let rr=0;rr<d;rr++){let yr,nr,dr,Or;b?(yr=u[rr*2]-w,nr=u[rr*2+1]-_):(yr=Number(u[rr])-w,nr=0),A?(dr=y[rr*2]-I,Or=y[rr*2+1]-v):(dr=Number(y[rr])-I,Or=0),T+=yr*yr+nr*nr,$+=dr*dr+Or*Or,V+=yr*dr+nr*Or,j+=nr*dr-yr*Or,R+=dr*yr+Or*nr,Y+=Or*yr-dr*nr}let J=d-s;if(J<=0){let rr=new Float64Array(8);return rr.fill(NaN),S.fromData(rr,[2,2],"complex128")}T/=J,$/=J,V/=J,j/=J,R/=J,Y/=J;let X=new Float64Array(8);return X[0]=T,X[1]=E,X[2]=V,X[3]=j,X[4]=R,X[5]=Y,X[6]=$,X[7]=k,S.fromData(X,[2,2],"complex128")}let g=0,h=0;for(let w=0;w<d;w++)g+=Number(u[w]),h+=Number(y[w]);g/=d,h/=d;let N=0,D=0,x=0;for(let w=0;w<d;w++){let _=Number(u[w])-g,I=Number(y[w])-h;N+=_*_,D+=I*I,x+=_*I}let C=d-s;return C<=0?S.fromData(new Float64Array([NaN,NaN,NaN,NaN]),[2,2],"float64"):(N/=C,D/=C,x/=C,S.fromData(new Float64Array([N,x,x,D]),[2,2],"float64"))}else{let y=r.size;if(i){let g=0,h=0;for(let x=0;x<y;x++)g+=u[x*2],h+=u[x*2+1];g/=y,h/=y;let N=0;for(let x=0;x<y;x++){let C=u[x*2]-g,w=u[x*2+1]-h;N+=C*C+w*w}let D=y-s;return D<=0?S.fromData(new Float64Array([NaN,0]),[],"complex128"):(N/=D,S.fromData(new Float64Array([N,0]),[],"complex128"))}let d=0;for(let g=0;g<y;g++)d+=Number(u[g]);d/=y;let b=0;for(let g=0;g<y;g++){let h=Number(u[g])-d;b+=h*h}let A=y-s;return A<=0?S.fromData(new Float64Array([NaN]),[],"float64"):(b/=A,S.fromData(new Float64Array([b]),[],"float64"))}let c,l;e?(c=a[0],l=a[1]):(c=a[1],l=a[0]);let f=l-s;if(i){let y=new Float64Array(c),d=new Float64Array(c);for(let A=0;A<c;A++){let g=0,h=0;for(let N=0;N<l;N++){let D=e?A*l+N:N*c+A;g+=u[D*2],h+=u[D*2+1]}y[A]=g/l,d[A]=h/l}let b=new Float64Array(c*c*2);if(f<=0)return b.fill(NaN),S.fromData(b,[c,c],"complex128");for(let A=0;A<c;A++)for(let g=0;g<c;g++){let h=0,N=0;for(let x=0;x<l;x++){let C=e?A*l+x:x*c+A,w=e?g*l+x:x*c+g,_=u[C*2]-y[A],I=u[C*2+1]-d[A],v=u[w*2]-y[g],T=u[w*2+1]-d[g];h+=_*v+I*T,N+=I*v-_*T}let D=(A*c+g)*2;b[D]=h/f,b[D+1]=N/f}return S.fromData(b,[c,c],"complex128")}let m=new Float64Array(c);for(let y=0;y<c;y++){let d=0;for(let b=0;b<l;b++){let A=e?y*l+b:b*c+y;d+=Number(u[A])}m[y]=d/l}let p=new Float64Array(c*c);if(f<=0)return p.fill(NaN),S.fromData(p,[c,c],"float64");for(let y=0;y<c;y++)for(let d=y;d<c;d++){let b=0;for(let g=0;g<l;g++){let h=e?y*l+g:g*c+y,N=e?d*l+g:g*c+d,D=Number(u[h])-m[y],x=Number(u[N])-m[d];b+=D*x}let A=b/f;p[y*c+d]=A,p[d*c+y]=A}return S.fromData(p,[c,c],"float64")}function xy(r,t,e=!0){let n=B(r.dtype)||t!==void 0&&B(t.dtype);if(r.shape.length===1&&t===void 0)return n?S.fromData(new Float64Array([1,0]),[],"complex128"):S.fromData(new Float64Array([1]),[],"float64");let o=Wu(r,t,e,!1),a=o.data,i=o.shape[0];if(n){let c=new Float64Array(i*i*2);for(let l=0;l<i;l++)for(let f=0;f<i;f++){let m=a[(l*i+f)*2],p=a[(l*i+f)*2+1],y=a[(l*i+l)*2],d=a[(f*i+f)*2],b=(l*i+f)*2;if(y<=0||d<=0)c[b]=NaN,c[b+1]=NaN;else{let A=Math.sqrt(y*d);c[b]=m/A,c[b+1]=p/A}}return S.fromData(c,[i,i],"complex128")}let s=new Float64Array(i*i);for(let c=0;c<i;c++)for(let l=0;l<i;l++){let f=Number(a[c*i+l]),m=Number(a[c*i+c]),p=Number(a[l*i+l]);m<=0||p<=0?s[c*i+l]=NaN:s[c*i+l]=f/Math.sqrt(m*p)}return S.fromData(s,[i,i],"float64")}function Cy(r,t=10,e,n){L(r.dtype,"histogram_bin_edges","histogram_bin_edges requires real numbers.");let o=r.data,a=r.size,u,i;if(e)[u,i]=e;else{u=1/0,i=-1/0;for(let f=0;f<a;f++){let m=Number(o[f]);isNaN(m)||(m<u&&(u=m),m>i&&(i=m))}!isFinite(u)||!isFinite(i)?(u=0,i=1):u===i&&(u=u-.5,i=i+.5)}let s;typeof t=="number"?s=t:s=Lu(o,a,u,i,t),s=Math.max(1,Math.round(s));let c=new Float64Array(s+1),l=(i-u)/s;for(let f=0;f<=s;f++)c[f]=u+f*l;return S.fromData(c,[s+1],"float64")}function Lu(r,t,e,n,o){if(t===0)return 1;let a=n-e;if(a===0)return 1;let u=[],i=0;for(let d=0;d<t;d++){let b=Number(r[d]);isNaN(b)||(u.push(b),i+=b)}let s=u.length;if(s===0)return 1;let c=i/s,l=0;for(let d=0;d<s;d++){let b=u[d]-c;l+=b*b}let f=Math.sqrt(l/s);u.sort((d,b)=>d-b);let m=u[Math.floor(s*.25)]??0,y=(u[Math.floor(s*.75)]??0)-m;switch(o){case"sqrt":return Math.ceil(Math.sqrt(s));case"sturges":return Math.ceil(Math.log2(s)+1);case"rice":return Math.ceil(2*Math.pow(s,1/3));case"scott":{if(f===0)return 1;let d=3.5*f/Math.pow(s,1/3);return Math.ceil(a/d)}case"fd":{if(y===0)return Lu(r,t,e,n,"sturges");let d=2*y/Math.pow(s,1/3);return Math.ceil(a/d)}case"doane":{let d=ux(u,c,f),b=Math.sqrt(6*(s-2)/((s+1)*(s+3)));return Math.ceil(1+Math.log2(s)+Math.log2(1+Math.abs(d)/b))}case"stone":return Lu(r,t,e,n,"sturges");default:{let d=Math.ceil(Math.log2(s)+1),b=y===0?d:Math.ceil(a/(2*y/Math.pow(s,1/3)));return Math.max(d,b)}}}function ux(r,t,e){if(e===0)return 0;let n=r.length,o=0;for(let a=0;a<n;a++)o+=Math.pow((r[a]-t)/e,3);return o/n}function Sy(r,t,e=1,n=-1){L(r.dtype,"trapezoid","trapezoid requires real numbers."),t!==void 0&&L(t.dtype,"trapezoid","trapezoid requires real numbers.");let o=Array.from(r.shape),a=o.length;if(n<0&&(n=a+n),n<0||n>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let u=o[n];if(u<2)throw new Error("trapezoid requires at least 2 samples along axis");let i;if(t!==void 0){if(t.size!==u)throw new Error(`x array size (${t.size}) must match y axis size (${u})`);let d=t.data;i=new Float64Array(u);for(let b=0;b<u;b++)i[b]=Number(d[b])}else{i=new Float64Array(u);for(let d=0;d<u;d++)i[d]=d*e}let s=[...o];if(s.splice(n,1),a===1){let d=r.data,b=0;for(let A=0;A<u-1;A++){let g=Number(d[A]),h=Number(d[A+1]),N=i[A+1]-i[A];b+=.5*(g+h)*N}return b}let c=s.reduce((d,b)=>d*b,1),l=new Float64Array(c),f=new Array(a),m=1;for(let d=a-1;d>=0;d--)f[d]=m,m*=o[d];let p=new Array(s.length);m=1;for(let d=s.length-1;d>=0;d--)p[d]=m,m*=s[d];let y=r.data;for(let d=0;d<c;d++){let b=[],A=d;for(let D=0;D<s.length;D++){let x=Math.floor(A/p[D]);A%=p[D],b.push(x)}let g=[],h=0;for(let D=0;D<a;D++)D===n?g.push(0):(g.push(b[h]),h++);let N=0;for(let D=0;D<u-1;D++){g[n]=D;let x=0;for(let v=0;v<a;v++)x+=g[v]*f[v];g[n]=D+1;let C=0;for(let v=0;v<a;v++)C+=g[v]*f[v];let w=Number(y[x]),_=Number(y[C]),I=i[D+1]-i[D];N+=.5*(w+_)*I}l[d]=N}return s.length===0?l[0]:S.fromData(l,s,"float64")}function Yu(r,t,e){let n=t?z(t):void 0;return M(by(z(r),n,e))}function Zu(r,t,e){return M(Ay(z(r),z(t),e))}function Ba(r,t,e,n,o){let a=t instanceof P?z(t):t,u=o?z(o):void 0,i=gy(z(r),a,e,n,u);return[M(i.hist),M(i.bin_edges)]}function Ta(r,t,e,n,o,a){let u;if(Array.isArray(e)&&e.length===2){let c=e[0]instanceof P?z(e[0]):e[0],l=e[1]instanceof P?z(e[1]):e[1];u=[c,l]}else u=e;let i=a?z(a):void 0,s=hy(z(r),z(t),u,n,o,i);return[M(s.hist),M(s.x_edges),M(s.y_edges)]}function Oa(r,t,e,n,o){let a=o?z(o):void 0,u=Ny(z(r),t,e,n,a);return[M(u.hist),u.edges.map(i=>M(i))]}function Ju(r,t,e){return M(Gu(z(r),z(t),e))}function Xu(r,t,e){return M(Dy(z(r),z(t),e))}function Ku(r,t,e,n,o){return M(Wu(z(r),t?z(t):void 0,e,n,o))}function Qu(r,t,e){return M(xy(z(r),t?z(t):void 0,e))}function Ea(r,t,e,n){return M(Cy(z(r),t,e,n?z(n):void 0))}function Hu(r,t,e,n){let o=Sy(z(r),t?z(t):void 0,e,n);return typeof o=="number"?o:M(o)}function wy(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 i=0;i<t;i++)u=lx(u,a);return u}function lx(r,t){let e=Array.from(r.shape),n=e.length,o=e[t],a=[...e];a[t]=o-1;let u=r.dtype,i=B(u),s=O(u)?"float64":u,c=S.zeros(a,s),l=c.data,f=r.strides,m=c.size,p=r.offset;for(let y=0;y<m;y++){let d=y,b=new Array(n);for(let D=n-1;D>=0;D--)b[D]=d%a[D],d=Math.floor(d/a[D]);let A=[...b],g=[...b];g[t]=A[t]+1;let h=0,N=0;for(let D=0;D<n;D++)h+=A[D]*f[D],N+=g[D]*f[D];if(i){let D=r.data,x=D[(p+h)*2],C=D[(p+h)*2+1],w=D[(p+N)*2],_=D[(p+N)*2+1];l[y*2]=w-x,l[y*2+1]=_-C}else{let D=(O(u),Number(r.data[p+h])),x=(O(u),Number(r.data[p+N]));l[y]=x-D}}return c}function Iy(r,t=null,e=null){let n=r.size,o=r.dtype,a=B(o),u=O(o)?"float64":o,i=Math.max(0,n-1),s=e?e.length:0,c=t?t.length:0,l=s+i+c,f=S.zeros([l],u),m=f.data,p=0;if(e)if(a)for(let y of e)m[p*2]=y,m[p*2+1]=0,p++;else for(let y of e)m[p++]=y;if(a)for(let y=0;y<i;y++){let d=r.iget(y),b=r.iget(y+1);m[p*2]=b.re-d.re,m[p*2+1]=b.im-d.im,p++}else for(let y=0;y<i;y++){let d=(O(o),Number(r.iget(y))),b=(O(o),Number(r.iget(y+1)));m[p++]=b-d}if(t)if(a)for(let y of t)m[p*2]=y,m[p*2+1]=0,p++;else for(let y of t)m[p++]=y;return f}function zy(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 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 i=[];for(let s=0;s<a.length;s++)i.push(fx(r,a[s],u[s]));return i.length===1?i[0]:i}function fx(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,i=B(u),s=O(u)?"float64":u==="float32"?"float32":i?u:"float64",c=S.zeros(n,s),l=c.data,f=r.strides,m=e,p=2*m,y=r.size,d=r.offset;for(let b=0;b<y;b++){let A=b,g=new Array(o);for(let D=o-1;D>=0;D--)g[D]=A%n[D],A=Math.floor(A/n[D]);let h=d;for(let D=0;D<o;D++)h+=g[D]*f[D];let N=g[t];if(i){let D=r.data,x=l,C,w;if(N===0){let _=[...g];_[t]=1;let I=0;for(let k=0;k<o;k++)I+=_[k]*f[k];let v=D[h*2],T=D[h*2+1],E=D[(d+I)*2],$=D[(d+I)*2+1];C=(E-v)/m,w=($-T)/m}else if(N===a-1){let _=[...g];_[t]=a-2;let I=0;for(let k=0;k<o;k++)I+=_[k]*f[k];let v=D[h*2],T=D[h*2+1],E=D[(d+I)*2],$=D[(d+I)*2+1];C=(v-E)/m,w=(T-$)/m}else{let _=[...g],I=[...g];_[t]=N+1,I[t]=N-1;let v=0,T=0;for(let j=0;j<o;j++)v+=_[j]*f[j],T+=I[j]*f[j];let E=D[(d+v)*2],$=D[(d+v)*2+1],k=D[(d+T)*2],V=D[(d+T)*2+1];C=(E-k)/p,w=($-V)/p}x[b*2]=C,x[b*2+1]=w}else{let D;if(N===0){let x=[...g];x[t]=1;let C=0;for(let I=0;I<o;I++)C+=x[I]*f[I];let w=(O(u),Number(r.data[h]));D=((O(u),Number(r.data[d+C]))-w)/m}else if(N===a-1){let x=[...g];x[t]=a-2;let C=0;for(let I=0;I<o;I++)C+=x[I]*f[I];let w=(O(u),Number(r.data[h])),_=(O(u),Number(r.data[d+C]));D=(w-_)/m}else{let x=[...g],C=[...g];x[t]=N+1,C[t]=N-1;let w=0,_=0;for(let T=0;T<o;T++)w+=x[T]*f[T],_+=C[T]*f[T];let I=(O(u),Number(r.data[d+w])),v=(O(u),Number(r.data[d+_]));D=(I-v)/p}l[b]=D}}return c}function lo(r,t,e){return M(wy(z(r),t,e))}function rc(r,t,e){return M(Iy(z(r),t??null,e??null))}function Ua(r,t,e){let n=zy(z(r),t,e);return Array.isArray(n)?$r(n):M(n)}function _y(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(B(t)){let o=$t(t),a=S.zeros(e,o),u=a.data,i=r.data;for(let s=0;s<n;s++)u[s]=i[s*2];return a}return r.copy()}function vy(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(B(t)){let a=$t(t),u=S.zeros(e,a),i=u.data,s=r.data;for(let c=0;c<n;c++)i[c]=s[c*2+1];return u}let o=t==="float32"?"float32":"float64";return S.zeros(e,o)}function My(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(B(t)){let o=K(t),a=n*2,u=new o(a),i=r.data;for(let s=0;s<n;s++)u[s*2]=i[s*2],u[s*2+1]=-i[s*2+1];return S.fromData(u,e,t)}return r.copy()}function Fy(r,t=!1){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,"float64"),u=a.data;if(B(e)){let i=r.data;for(let s=0;s<o;s++){let c=i[s*2],l=i[s*2+1],f=Math.atan2(l,c);t&&(f=f*180/Math.PI),u[s]=f}}else for(let i=0;i<o;i++){let s=r.iget(i),l=(s instanceof U?s.re:Number(s))>=0?0:Math.PI;t&&(l=l*180/Math.PI),u[i]=l}return a}function tc(r){return M(_y(z(r)))}function ec(r){return M(vy(z(r)))}function fo(r){return M(My(z(r)))}function nc(r,t){return M(Fy(z(r),t))}function oc(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=qr([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 _r(r,t)}function By(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=qr(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=>_r(n,e))}function Ty(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let y=r.size;for(let g of t){let h=g<0?y+g:g;if(h<0||h>=y)throw new Error(`index ${g} is out of bounds for axis 0 with size ${y}`)}let d=t.length,b=K(a);if(!b)throw new Error(`Cannot take from array with dtype ${a}`);let A=new b(d);for(let g=0;g<d;g++){let h=t[g];h<0&&(h=y+h);let N=r.iget(h);O(a),A[g]=N}return S.fromData(A,[d],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 i=n[u];for(let y of t){let d=y<0?i+y:y;if(d<0||d>=i)throw new Error(`index ${y} is out of bounds for axis ${u} with size ${i}`)}let s=Array.from(n);s[u]=t.length;let c=s.reduce((y,d)=>y*d,1),l=K(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let f=new l(c),m=lr(s),p=new Array(o).fill(0);for(let y=0;y<c;y++){let d=[...p],b=p[u],A=t[b];A<0&&(A=i+A),d[u]=A;let g=r.get(...d),h=0;for(let N=0;N<o;N++)h+=p[N]*m[N];O(a),f[h]=g;for(let N=o-1;N>=0&&(p[N]++,!(p[N]<s[N]));N--)p[N]=0}return S.fromData(f,s,a)}function Oy(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 i=e.iget(u);a.push(i instanceof U?i.re:i)}if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let u=[...a];a=[];for(let i=0;i<t.length;i++)a.push(u[i%u.length])}}for(let u=0;u<t.length;u++){let i=t[u];if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`index ${t[u]} is out of bounds for axis 0 with size ${n}`);let s=a[u];O(o)?typeof s!="bigint"&&(s=BigInt(Math.round(Number(s)))):typeof s=="bigint"&&(s=Number(s)),r.iset(i,s)}}function Ey(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(m=>Array.from(m.shape));a.unshift(Array.from(e));let u=qr(a);if(u===null)throw new Error("operands could not be broadcast together");let i=_r(r,u),s=t.map(m=>_r(m,u)),c=u.reduce((m,p)=>m*p,1),l=K(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let f=new l(c);for(let m=0;m<c;m++){let p=Number(i.iget(m));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(m);O(o),f[m]=y}return S.fromData(f,u,o)}function Uy(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 i=typeof a=="number"&&Number.isNaN(a),s=typeof u=="number"&&Number.isNaN(u);if(i&&s)continue}if(a!==u)return!1}return!0}function $y(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 i=t.shape;if(i.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${i.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==u&&i[d]!==n[d]&&i[d]!==1&&n[d]!==1)throw new Error(`index ${i[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let s=Array.from(i),c=s.reduce((d,b)=>d*b,1),l=K(a);if(!l)throw new Error(`Cannot take_along_axis with dtype ${a}`);let f=new l(c),m=lr(n),p=lr(i),y=n[u];for(let d=0;d<c;d++){let b=new Array(o),A=d;for(let C=o-1;C>=0;C--)b[C]=A%s[C],A=Math.floor(A/s[C]);let g=0;for(let C=0;C<o;C++){let w=i[C]===1?0:b[C];g+=w*p[C]}let h=Number(t.iget(g));if(h<0&&(h=y+h),h<0||h>=y)throw new Error(`index ${h} is out of bounds for axis ${u} with size ${y}`);let N=[...b];N[u]=h;let D=0;for(let C=0;C<o;C++){let w=n[C]===1?0:N[C];D+=w*m[C]}let x=r.iget(D);O(a),f[d]=x}return S.fromData(f,s,a)}function ky(r,t,e,n){let o=r.shape,a=o.length,u=r.dtype,i=n<0?a+n:n;if(i<0||i>=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[i],f=lr(o),m=lr(s),p=lr(c),y=s.reduce((d,b)=>d*b,1);for(let d=0;d<y;d++){let b=new Array(a),A=d;for(let w=a-1;w>=0;w--)b[w]=A%s[w],A=Math.floor(A/s[w]);let g=0;for(let w=0;w<a;w++)g+=b[w]*m[w];let h=Number(t.iget(g));if(h<0&&(h=l+h),h<0||h>=l)throw new Error(`index ${h} is out of bounds for axis ${i} with size ${l}`);let N=0;for(let w=0;w<a;w++){let _=c[w]===1?0:b[w];N+=_*p[w]}let D=e.iget(N),x=[...b];x[i]=h;let C=0;for(let w=0;w<a;w++)C+=x[w]*f[w];O(u)?typeof D!="bigint"&&(D=BigInt(Math.round(Number(D)))):typeof D=="bigint"&&(D=Number(D)),r.iset(C,D)}}function Ry(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let i=0;i<e.size;i++){let s=e.iget(i);a.push(s instanceof U?s.re:s)}}let u=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[u%a.length];O(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),u++}}function qy(r,t,e){let n=t.shape,o=n.length,a=t.dtype,u=O(a);if(e===void 0){let N=Math.min(r.size,t.size),D=r.isCContiguous,x=r.data,C=r.offset,w=0;if(D)for(let E=0;E<N;E++)x[C+E]&&w++;else for(let E=0;E<N;E++)r.iget(E)&&w++;let _=K(a);if(!_)throw new Error(`Cannot compress with dtype ${a}`);let I=new _(w),v=0,T=t.isCContiguous;if(D&&T){let E=t.data,$=t.offset;if(u){let k=I,V=E;for(let j=0;j<N;j++)x[C+j]&&(k[v++]=V[$+j])}else{let k=I,V=E;for(let j=0;j<N;j++)x[C+j]&&(k[v++]=V[$+j])}}else for(let E=0;E<N;E++)(D?x[C+E]:r.iget(E))&&(I[v]=t.iget(E),v++);return S.fromData(I,[w],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 s=n[i],c=Math.min(r.size,s),l=[];for(let N=0;N<c;N++)r.iget(N)&&l.push(N);let f=l.length,m=[...n];m[i]=f;let p=m.reduce((N,D)=>N*D,1),y=K(a);if(!y)throw new Error(`Cannot compress with dtype ${a}`);let d=new y(p),b=n.slice(i+1).reduce((N,D)=>N*D,1),A=n.slice(0,i).reduce((N,D)=>N*D,1),g=0;if(t.isCContiguous){let N=t.data,D=t.offset;if(u){let x=d,C=N;for(let w=0;w<A;w++)for(let _=0;_<f;_++){let I=l[_];for(let v=0;v<b;v++){let T=w*s*b+I*b+v;x[g++]=C[D+T]}}}else{let x=d,C=N;for(let w=0;w<A;w++)for(let _=0;_<f;_++){let I=l[_];for(let v=0;v<b;v++){let T=w*s*b+I*b+v;x[g++]=C[D+T]}}}}else for(let N=0;N<A;N++)for(let D=0;D<f;D++){let x=l[D];for(let C=0;C<b;C++){let w=N*s*b+x*b+C;d[g++]=t.iget(w)}}return S.fromData(d,m,a)}function Vy(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(m=>Array.from(m.shape)),...t.map(m=>Array.from(m.shape))],o=qr(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,u=o.reduce((m,p)=>m*p,1),i=K(a);if(!i)throw new Error(`Cannot select with dtype ${a}`);let s=e;O(a)?s=typeof e=="bigint"?e:BigInt(e):s=typeof e=="bigint"?Number(e):e;let c=new i(u);for(let m=0;m<u;m++)O(a),c[m]=s;let l=r.map(m=>_r(m,o)),f=t.map(m=>_r(m,o));for(let m=0;m<u;m++)for(let p=0;p<r.length;p++)if(l[p].iget(m)){let y=f[p].iget(m);O(a),c[m]=y;break}return S.fromData(c,o,a)}function Py(r,t,e){let n=r.size,o=r.dtype,a=[];for(let i=0;i<e.size;i++){let s=e.iget(i);a.push(s instanceof U?s.re:s)}if(a.length===0)return;let u=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[u%a.length];O(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),u++}}function ac(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(S.fromData(new Int32Array(e),[r],"int32"));return n}function jy(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 ac(n,e)}function sc(r,t=0,e){let n=e??r,o=[],a=[];for(let u=0;u<r;u++)for(let i=0;i<=Math.min(u+t,n-1);i++)i>=0&&(o.push(u),a.push(i));return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(a),[a.length],"int32")]}function Ly(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return sc(e[0],t,e[1])}function ic(r,t=0,e){let n=e??r,o=[],a=[];for(let u=0;u<r;u++)for(let i=Math.max(u+t,0);i<n;i++)o.push(u),a.push(i);return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(a),[a.length],"int32")]}function Gy(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return ic(e[0],t,e[1])}function Wy(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 i=0;i<r;i++)for(let s=0;s<r;s++)n.get(i,s)&&(a.push(i),u.push(s));return[S.fromData(new Int32Array(a),[a.length],"int32"),S.fromData(new Int32Array(u),[u.length],"int32")]}function Yy(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((s,c)=>s*c,1),a=K(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let u=new a(o),i=r.reduce((s,c)=>s*c,1);for(let s=0;s<e;s++){let c=s*i;for(let l=0;l<i;l++){let f=new Array(e),m=l;for(let y=e-1;y>=0;y--)f[y]=m%r[y],m=Math.floor(m/r[y]);let p=f[s];t==="int64"?u[c+l]=BigInt(p):u[c+l]=p}}return S.fromData(u,n,t)}function Zy(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,u=o.dtype,i=new Array(t).fill(1);i[n]=a;let s=K(u);if(!s)throw new Error(`Cannot create ix_ with dtype ${u}`);let c=new s(a);for(let l=0;l<a;l++){let f=o.iget(l);O(u),c[l]=f}e.push(S.fromData(c,i,u))}return e}function Jy(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),i=1;for(let s=o-1;s>=0;s--)u[s]=i,i*=t[s];for(let s=0;s<n;s++){let c=0;for(let l=0;l<o;l++){let f=Number(r[l].iget(s)),m=t[l];if(e==="wrap")f=(f%m+m)%m;else if(e==="clip")f=Math.max(0,Math.min(f,m-1));else if(f<0||f>=m)throw new Error(`index ${f} is out of bounds for axis ${l} with size ${m}`);c+=f*u[l]}a[s]=c}return S.fromData(a,[n],"int32")}function Xy(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,i=t.reduce((l,f)=>l*f,1),s=new Array(n);if(e==="C"){let l=1;for(let f=n-1;f>=0;f--)s[f]=l,l*=t[f]}else{let l=1;for(let f=0;f<n;f++)s[f]=l,l*=t[f]}let c=[];for(let l=0;l<n;l++){let f=new Int32Array(u);c.push(S.fromData(f,a.length?a:[1],"int32"))}for(let l=0;l<u;l++){let f=o[l];if(f<0||f>=i)throw new Error(`index ${f} is out of bounds for array with size ${i}`);if(e==="C")for(let m=0;m<n;m++){let p=Math.floor(f/s[m]);f=f%s[m],c[m].data[l]=p%t[m]}else for(let m=n-1;m>=0;m--){let p=Math.floor(f/s[m]);f=f%s[m],c[m].data[l]=p%t[m]}}return typeof r=="number"?c.map(l=>{let f=l.iget(0);return S.fromData(new Int32Array([Number(f)]),[],"int32")}):c}function Ky(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 f=c;f<o;f++)l*=n[f];a+=l}}let u=r.size,i=Math.min(...n);e&&o===2&&(i=Math.max(n[0],n[1]));let s=r.isCContiguous;if(typeof t=="number")if(s){let c=r.data,l=r.offset;if(O(r.dtype)){let f=c,m=BigInt(Math.round(t));for(let p=0;p<i;p++){let y=p*a;if(y>=u)break;f[l+y]=m}}else for(let f=0;f<i;f++){let m=f*a;if(m>=u)break;c[l+m]=t}}else for(let c=0;c<i&&c*a<u;c++)r.iset(c*a,t);else{let c=t.size;if(s&&t.isCContiguous){let l=r.data,f=r.offset,m=t.data,p=t.offset;if(O(r.dtype)){let y=l,d=m;for(let b=0;b<i;b++){let A=b*a;if(A>=u)break;y[f+A]=d[p+b%c]}}else{let y=l,d=m;for(let b=0;b<i;b++){let A=b*a;if(A>=u)break;y[f+A]=d[p+b%c]}}}else for(let l=0;l<i&&l*a<u;l++)r.iset(l*a,t.iget(l%c))}}function Qy(r,t,e){let n=Array.from(r.shape),o=n.length;if(t<0&&(t+=o),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=[];for(let u=0;u<o;u++)u!==t&&a.push(n[u]);if(a.length===0){let u=e(r);if(typeof u=="number"){let i=S.zeros([1],r.dtype);return i.data[0]=u,i}return u}if(o===2){let[u,i]=n;if(t===0){let s=[];for(let l=0;l<i;l++){let f=new Float64Array(u);for(let p=0;p<u;p++)f[p]=Number(r.get(p,l));let m=S.fromData(f,[u],"float64");s.push(e(m))}let c=s[0];if(c===void 0)return S.zeros([0],"float64");if(typeof c=="number"){let l=S.zeros([i],"float64");for(let f=0;f<i;f++)l.data[f]=s[f];return l}else{let l=[c.size,i],f=S.zeros(l,"float64");for(let m=0;m<i;m++){let p=s[m];for(let y=0;y<p.size;y++)f.data[y*i+m]=Number(p.iget(y))}return f}}else{let s=[];for(let l=0;l<u;l++){let f=new Float64Array(i);for(let p=0;p<i;p++)f[p]=Number(r.get(l,p));let m=S.fromData(f,[i],"float64");s.push(e(m))}let c=s[0];if(c===void 0)return S.zeros([0],"float64");if(typeof c=="number"){let l=S.zeros([u],"float64");for(let f=0;f<u;f++)l.data[f]=s[f];return l}else{let l=[u,c.size],f=S.zeros(l,"float64");for(let m=0;m<u;m++){let p=s[m];for(let y=0;y<p.size;y++)f.data[m*p.size+y]=Number(p.iget(y))}return f}}}if(o===1){let u=e(r);if(typeof u=="number"){let i=S.zeros([1],"float64");return i.data[0]=u,i}return u}throw new Error(`apply_along_axis not fully implemented for ${o}D arrays. Only 1D and 2D arrays are supported.`)}function Hy(r,t,e){let n=r,o=r.shape.length;for(let a of e){let u=a<0?a+o:a;if(u<0||u>=o)throw new Error(`axis ${a} is out of bounds for array of dimension ${o}`);if(n=t(n,u),n.shape.length<o){let i=Array.from(n.shape);i.splice(u,0,1);let s=lr(i);n=new S(n.data,i,s,0,n.dtype)}}return n}function uc(r,t){return r.data.buffer===t.data.buffer}function rd(r,t){return uc(r,t)}var Gr={divide:"warn",over:"warn",under:"ignore",invalid:"warn"};function cc(){return{...Gr}}function td(r,t,e,n,o){let a=cc();return r!==void 0&&(Gr.divide=r,Gr.over=r,Gr.under=r,Gr.invalid=r),t!==void 0&&(Gr.divide=t),e!==void 0&&(Gr.over=e),n!==void 0&&(Gr.under=n),o!==void 0&&(Gr.invalid=o),a}function mo(r,t){return Nr(oc(z(r),t),r)}function $a(...r){let t=r.map(z);return By(t).map(e=>M(e))}function ka(...r){if(r.length===0)return[];if(r.length===1)return[...r[0]];let t=[...r[0]];for(let e=1;e<r.length;e++){let n=r[e],o=Math.max(t.length,n.length),a=[];for(let u=0;u<o;u++){let i=u<t.length?t[t.length-1-u]:1,s=u<n.length?n[n.length-1-u]:1;if(i===s)a.unshift(i);else if(i===1)a.unshift(s);else if(s===1)a.unshift(i);else throw new Error(`Cannot broadcast shapes: dimensions ${i} and ${s} are incompatible`)}t=a}return t}function Bt(r,t,e){return M(Ty(z(r),t,e))}function Tt(r,t,e){let n=Array.isArray(e)?z(Q(e)):z(e);Oy(z(r),t,n)}function lc(r,t,e){return M($y(z(r),z(t),e))}function Ra(r,t,e,n){ky(z(r),z(t),z(e),n)}function po(r,t){let e=t.map(z);return M(Ey(z(r),e))}function st(r,t,e){return M(qy(z(r),z(t),e))}function fc(r,t,e=0){let n;return t instanceof P?n=Array.from(t.data):Array.isArray(t[0])?n=t.flat():n=t,Bt(r,n,e)}function mc(r,t,e){return st(t,r,e)}function pc(r,t,e=0){let n=r.map(z),o=t.map(z);return M(Vy(n,o,e))}function qa(r,t,e){Py(z(r),z(t),z(e))}function Va(r,t,e){Ry(z(r),z(t),z(e))}function Pa(r,t){let e=z(r),n=r.shape,o=r.size,a=r.dtype;if(typeof t=="number"||typeof t=="bigint"){r.fill(t);return}let u=z(t),i=t.shape,s=qr([i,n]);if(!s)throw new Error(`could not broadcast input array from shape (${i.join(",")}) into shape (${n.join(",")})`);if(s.length!==n.length||!s.every((l,f)=>l===n[f]))throw new Error(`could not broadcast input array from shape (${i.join(",")}) into shape (${n.join(",")})`);let c=oc(u,n);if(O(a))for(let l=0;l<o;l++){let f=c.iget(l),m=typeof f=="bigint"?f:BigInt(Math.round(Number(f)));e.iset(l,m)}else if(a==="bool")for(let l=0;l<o;l++){let f=c.iget(l);e.iset(l,f?1:0)}else for(let l=0;l<o;l++){let f=c.iget(l);e.iset(l,Number(f))}}function yc(r,t="int32"){return M(Yy(r,t))}function ja(...r){let t=r.map(z);return Zy(...t).map(e=>M(e))}function dc(r,t,e="raise"){let n=r.map(z);return M(Jy(n,t,e))}function bc(r,t){let e=typeof r=="number"?z(Q([r])):z(r);return Xy(e,t).map(n=>M(n))}function Ac(r,t=2){return ac(r,t).map(e=>M(e))}function gc(r){return jy(z(r)).map(t=>M(t))}function La(r,t,e=!1){Ky(z(r),t,e)}function hc(r,t=0,e){return sc(r,t,e).map(n=>M(n))}function Nc(r,t=0){return Ly(z(r),t).map(e=>M(e))}function Dc(r,t=0,e){return ic(r,t,e).map(n=>M(n))}function xc(r,t=0){return Gy(z(r),t).map(e=>M(e))}function Cc(r,t,e=0){return Wy(r,(o,a)=>z(t(o,a)),e).map(o=>M(o))}function Ga(r,t,e=!1){return Uy(z(r),z(t),e)}function Wa(r,t){return Mp(z(r),z(t))}function Sc(r,t,e){let n=o=>{let a=r(M(o));return typeof a=="number"?a:z(a)};return M(Qy(z(e),t,n))}function wc(r,t,e){let n=(o,a)=>z(r(M(o),a));return M(Hy(z(t),n,e))}function Ya(r,t){return uc(z(r),z(t))}function Za(r,t){return rd(z(r),z(t))}var Ja=cc,Xa=td;var dx={threshold:1e3,edgeitems:3,precision:8,linewidth:75,floatmode:"maxprec",suppress:!0,separator:" ",prefix:"",suffix:"",nanstr:"nan",infstr:"inf",sign:"-",legacy:!1},cr={...dx};function ed(r){cr={...cr,...r}}function nd(){return{...cr}}function od(r){let t=null,e={_savedOptions:null,enter(){t={...cr},e._savedOptions=t,cr={...cr,...r}},exit(){t&&(cr=t,t=null,e._savedOptions=null)},apply(n){e.enter();try{return n()}finally{e.exit()}}};return e}function Ic(r,t=null,e=!0,n=!0,o="k",a="-",u=null,i=null,s=null){let c=t??cr.precision;if(!Number.isFinite(r))return Number.isNaN(r)?cr.nanstr:(r>0?"":"-")+cr.infstr;let l;if(e&&t===null?(l=r.toString(),n&&!l.includes(".")&&!l.includes("e")&&(l+=".0")):l=r.toFixed(c),s!==null){let f=l.indexOf(".");if(f!==-1){let m=l.length-f-1;m<s&&(l+="0".repeat(s-m))}else n&&(l+="."+"0".repeat(s))}if(o!=="k"&&l.includes(".")){if(o==="-"||o==="0"){let f=l.length;for(;f>0&&l[f-1]==="0";)f--;l=l.slice(0,f)}(o==="-"||o===".")&&l.endsWith(".")&&(l=l.slice(0,-1))}if(r>=0&&!Object.is(r,-0)&&(a==="+"?l="+"+l:a===" "&&(l=" "+l)),u!==null&&l.length<u&&(l=" ".repeat(u-l.length)+l),i!==null){let f=l.indexOf(".");if(f!==-1){let m=l.length-f-1;m<i&&(l+="0".repeat(i-m))}}return l}function ad(r,t=null,e=!0,n="k",o="-",a=null,u=2,i=null){let s=t??cr.precision;if(!Number.isFinite(r))return Number.isNaN(r)?cr.nanstr:(r>0?"":"-")+cr.infstr;let c=r.toExponential(s);if(i!==null){let d=c.indexOf("e"),b=c.slice(0,d),A=c.slice(d),g=b.indexOf(".");if(g!==-1){let h=b.length-g-1;h<i&&(c=b+"0".repeat(i-h)+A)}}if(n!=="k"){let d=c.indexOf("e"),b=c.slice(0,d),A=c.slice(d);b.includes(".")&&((n==="-"||n==="0")&&(b=b.replace(/0+$/,"")),(n==="-"||n===".")&&(b=b.replace(/\.$/,""))),c=b+A}let l=c.indexOf("e"),f=c.slice(0,l),m=c.slice(l+1),p=m[0]==="-"?"-":"+",y=m.replace(/^[+-]/,"");for(;y.length<u;)y="0"+y;return c=f+"e"+p+y,r>=0&&!Object.is(r,-0)&&(o==="+"?c="+"+c:o===" "&&(c=" "+c)),a!==null&&c.length<a&&(c=" ".repeat(a-c.length)+c),c}function sd(r,t=2,e=0){if(t<2||t>36)throw new Error("base must be between 2 and 36");r=Math.trunc(r);let n;if(r<0?n="-"+Math.abs(r).toString(t).toUpperCase():n=r.toString(t).toUpperCase(),e>0){let o="0".repeat(e);n.startsWith("-")?n="-"+o+n.slice(1):n=o+n}return n}function id(r,t=null){if(r=Math.trunc(r),t!==null&&r<0){if(r=Math.pow(2,t)+r,r<0)throw new Error("width too small for negative number");let o=r.toString(2);return o.length<t&&(o="0".repeat(t-o.length)+o),o}let e;return r<0?e="-"+Math.abs(r).toString(2):e=r.toString(2),t!==null&&e.length<t&&(e="0".repeat(t-e.length)+e),e}function Qa(r,t,e){if(r instanceof U){let n=Qa(r.re,"float64",e),o=Qa(Math.abs(r.im),"float64",e),a=r.im>=0?"+":"-";return`${n}${a}${o}j`}return typeof r=="boolean"?r?" True":"False":typeof r=="bigint"?r.toString():Number.isFinite(r)?t==="float32"||t==="float64"?e.suppress&&Math.abs(r)<1e-10&&r!==0?"0.":Ic(r,e.precision,!1,!0,"k",e.sign):r.toString():Number.isNaN(r)?e.nanstr:(r>0?"":"-")+e.infstr}function Ka(r,t,e,n){let o=r.shape,a=o.length;if(e===a){let p=0,y=r.strides;for(let b=0;b<a;b++)p+=t[b]*y[b];let d=r.iget(p);return Qa(d,r.dtype,n)}let u=o[e],i=n.threshold,s=n.edgeitems,l=o.reduce((p,y)=>p*y,1)>i&&u>2*s,f=[],m=[...t];if(l){for(let p=0;p<s;p++)m[e]=p,f.push(Ka(r,m,e+1,n));f.push("...");for(let p=u-s;p<u;p++)m[e]=p,f.push(Ka(r,m,e+1,n))}else for(let p=0;p<u;p++)m[e]=p,f.push(Ka(r,m,e+1,n));if(e===a-1)return"["+f.join(n.separator)+"]";{let y=`,
|
|
3
|
-
`+" ".repeat(e+1);return"["+f.join(y)+"]"}}function Ha(r,t=null,e=null,n=null,o=" ",a="",u="",i=null,s=null){let c={...cr,linewidth:t??cr.linewidth,precision:e??cr.precision,suppress:n??cr.suppress,separator:o,prefix:a,suffix:u,threshold:i??cr.threshold,edgeitems:s??cr.edgeitems};if(r.ndim===0){let f=r.iget(0);return Qa(f,r.dtype,c)}let l=Ka(r,new Array(r.ndim).fill(0),0,c);return c.prefix+l+c.suffix}function ud(r,t=null,e=null,n=null){let a="array("+Ha(r,t,e,n,", ");return r.dtype!=="float64"&&(a+=`, dtype='${r.dtype}'`),a+=")",a}function cd(r,t=null,e=null,n=null){return Ha(r,t,e,n)}var rs=ed,ts=nd,es=od,ns=Ic,os=ad,as=sd,ss=id;function is(r,t){return Ha(z(r),t?.max_line_width??null,t?.precision??null,t?.suppress_small??null,t?.separator??" ",t?.prefix??"",t?.suffix??"",t?.threshold??null,t?.edgeitems??null)}function us(r,t,e,n){return ud(z(r),t,e,n)}function cs(r,t,e){return cd(z(r),t,e)}function ls(r){if(r instanceof P)return r.ndim;if(typeof r=="number"||typeof r=="bigint"||typeof r=="boolean")return 0;if(Array.isArray(r)){let t=0,e=r;for(;Array.isArray(e)&&e.length>0;)t++,e=e[0];return t}return 0}function yo(r){if(r instanceof P)return r.shape;if(typeof r=="number"||typeof r=="bigint"||typeof r=="boolean")return[];if(Array.isArray(r)){let t=[],e=r;for(;Array.isArray(e)&&e.length>0;)t.push(e.length),e=e[0];return t}return[]}function fs(r){return r instanceof P?r.size:typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"?1:Array.isArray(r)?yo(r).reduce((e,n)=>e*n,1):1}function ms(r,...t){let e=r.storage,n=r.shape;if(t.length===0){if(r.size!==1)throw new Error("can only convert an array of size 1 to a scalar");return e.isCContiguous?e.data[e.offset]:e.iget(0)}if(t.length===1)return e.isCContiguous?e.data[e.offset+t[0]]:e.iget(t[0]);if(t.length!==n.length)throw new Error("incorrect number of indices for array");return e.get(...t)}function ps(r){let t=r.shape,e=r.storage,n=t.length;if(n===0)return e.iget(0);if(e.isCContiguous){let l=function(f,m){let p=t[m],y=s[m];if(m===n-1){let b=new Array(p);for(let A=0;A<p;A++)b[A]=u[i+f+A];return b}let d=new Array(p);for(let b=0;b<p;b++)d[b]=l(f+b*y,m+1);return d};var a=l;let u=e.data,i=e.offset;if(n===1){let f=t[0],m=new Array(f);for(let p=0;p<f;p++)m[p]=u[i+p];return m}let s=new Array(n),c=1;for(let f=n-1;f>=0;f--)s[f]=c,c*=t[f];return l(0,0)}if(n===1){let u=[];for(let i=0;i<t[0];i++)u.push(e.iget(i));return u}function o(u,i){if(i===n)return e.get(...u);let s=[];for(let c=0;c<t[i];c++)u[i]=c,s.push(o(u,i+1));return s}return o(new Array(n),0)}function ys(r,t="C"){let e=r.storage;t==="F"&&console.warn('tobytes with order="F" not fully implemented, returning C-order');let n=e.data,o=n.BYTES_PER_ELEMENT;if(e.isCContiguous){let i=n.byteOffset+e.offset*o,s=r.size*o;return new Uint8Array(n.buffer,i,s)}let u=r.copy().data;return new Uint8Array(u.buffer,u.byteOffset,r.size*o)}function ds(r,t=!1){let n=r.data.BYTES_PER_ELEMENT;if(n===1)return t?r:r.copy();let o=t?r:r.copy(),a=o.data,u=new Uint8Array(a.buffer,a.byteOffset,a.byteLength);for(let i=0;i<a.length;i++){let s=i*n;for(let c=0;c<n/2;c++){let l=u[s+c];u[s+c]=u[s+n-1-c],u[s+n-1-c]=l}}return o}function bs(r,t){if(!t||t===r.dtype)return r.copy();throw new Error("view with different dtype not fully implemented")}function As(r,t,e="",n=""){throw new Error("tofile requires Node.js file system access. Use serializeNpy for portable serialization.")}function gs(r,t){let e=r.storage,n=r.dtype,o=r.size;if(t instanceof U){if(!(n==="complex64"||n==="complex128"))throw new Error("Cannot fill non-complex array with complex value");if(e.isCContiguous){let u=e.data,i=e.offset;for(let s=0;s<o;s++)u[(i+s)*2]=t.re,u[(i+s)*2+1]=t.im}else for(let u=0;u<o;u++)e.iset(u,t)}else if(typeof t=="bigint")if(e.isCContiguous)e.data.fill(t,e.offset,e.offset+o);else for(let a=0;a<o;a++)e.iset(a,t);else{let a=typeof t=="boolean"?t?1:0:t;if(e.isCContiguous)e.data.fill(a,e.offset,e.offset+o);else for(let u=0;u<o;u++)e.iset(u,a)}}function zc(r,t,e){let n=t instanceof P?t:Q(Array.isArray(t)?t:[t]);if(e===void 0){let o=Br(r),a=Br(n);return Ct([o,a],0)}return Ct([r,n],e)}function hs(r,t,e){let n=Array.isArray(t)?t:[t],o=[...r.shape],a=r.storage;if(e===void 0){let A=Br(r),g=A.storage,h=[],N=new Set(n.map(D=>D<0?A.size+D:D));for(let D=0;D<A.size;D++)N.has(D)||h.push(g.iget(D));return Q(h,r.dtype)}let u=e<0?o.length+e:e,i=o[u],s=new Set(n.map(A=>A<0?i+A:A)),c=i-s.size,l=[...o];l[u]=c;let f=wr(l,r.dtype),m=f.storage,p=[],y=1;for(let A=o.length-1;A>=0;A--)p.unshift(y),y*=o[A];let d=[];y=1;for(let A=l.length-1;A>=0;A--)d.unshift(y),y*=l[A];let b=o.reduce((A,g)=>A*g,1);for(let A=0;A<b;A++){let g=[],h=A;for(let C=0;C<o.length;C++)g.push(Math.floor(h/p[C])),h=h%p[C];if(s.has(g[u]))continue;let N=0;for(let C of s)C<g[u]&&N++;let D=[...g];D[u]-=N;let x=0;for(let C=0;C<l.length;C++)x+=D[C]*d[C];m.iset(x,a.iget(A))}return f}function _c(r,t,e,n){let o=Array.isArray(t)?t:[t],a=e instanceof P?e:Q(Array.isArray(e)?e:[e]);if(n===void 0){let u=Br(r),i=Br(a),s=u.data,c=i.data,l=Array.from(s);if(o.length===1){let f=o[0],m=f<0?u.size+f:f,p=Array.from(c);l.splice(m,0,...p)}else{let f=o.map((m,p)=>({idx:m<0?u.size+m:m,valIdx:p})).sort((m,p)=>m.idx-p.idx);for(let m=0;m<f.length;m++){let{idx:p,valIdx:y}=f[m],d=c[y%c.length];l.splice(p+m,0,d)}}return Q(l,r.dtype)}throw new Error("insert along axis not fully implemented in standalone")}function vc(r,t,e="constant",n=0){let o=[...r.shape],a=o.length,u;typeof t=="number"?u=Array(a).fill([t,t]):Array.isArray(t)&&typeof t[0]=="number"?u=Array(a).fill(t):u=t;let i=o.map((d,b)=>d+u[b][0]+u[b][1]);if(e!=="constant")throw new Error(`pad mode '${e}' not fully implemented in standalone`);let s=wr(i,r.dtype),c=s.storage;if(n!==0)for(let d=0;d<s.size;d++)c.iset(d,n);let l=r.storage,f=[],m=1;for(let d=o.length-1;d>=0;d--)f.unshift(m),m*=o[d];let p=[];m=1;for(let d=i.length-1;d>=0;d--)p.unshift(m),m*=i[d];let y=o.reduce((d,b)=>d*b,1);for(let d=0;d<y;d++){let b=[],A=d;for(let h=0;h<o.length;h++)b.push(Math.floor(A/f[h])),A=A%f[h];let g=0;for(let h=0;h<i.length;h++)g+=(b[h]+u[h][0])*p[h];c.iset(g,l.iget(d))}return s}var Bc=["int8","int16","int32","int64"],Tc=["uint8","uint16","uint32","uint64"],fd=[...Bc,...Tc],Mc=["float32","float64"],Fc=["complex64","complex128"],Ax=[...fd,...Mc,...Fc],ld={bool:0,int8:1,uint8:2,int16:3,uint16:4,int32:5,uint32:6,int64:7,uint64:8,float32:9,float64:10,complex64:11,complex128:12};function bo(r,t,e="safe"){let n=r instanceof P?r.dtype:r;if(e==="no"||e==="equiv")return n===t;if(e==="unsafe")return!0;let o=ld[n]??-1,a=ld[t]??-1;if(e==="safe"){if(Ur(n)&&Er(t)){let u={int8:8,int16:16,int32:32,int64:64,uint8:8,uint16:16,uint32:32,uint64:64,bool:1,float32:0,float64:0,complex64:0,complex128:0},i={float32:24,float64:53,int8:0,int16:0,int32:0,int64:0,uint8:0,uint16:0,uint32:0,uint64:0,bool:0,complex64:24,complex128:53},s=u[n]??64,c=i[t]??0;return s<=c}return!!(Ur(n)&&B(t)||Er(n)&&B(t)||o<=a)}return e==="same_kind"?!!(Ur(n)&&Ur(t)||Er(n)&&Er(t)||B(n)&&B(t)||n==="bool"&&Ur(t)||n==="bool"&&t==="bool"||Er(n)&&B(t)):!1}function Ns(...r){if(r.length===0)return"float64";let t=!1,e=!1;for(let n of r){let o=n.dtype;B(o)?(t=!0,o==="complex128"&&(e=!0)):Er(o)?o==="float64"&&(e=!0):Ur(o)&&(o==="int64"||o==="uint64"||o==="int32"||o==="uint32")&&(e=!0)}return t?e?"complex128":"complex64":e?"float64":"float32"}function Ds(...r){if(r.length===0)return"float64";let t=r.map(a=>a instanceof P?a.dtype:a),e=t.some(B),n=t.some(Er),o=t.some(Ur);if(e){let a=t.some(s=>s==="float64"),u=t.some(s=>s==="complex128"),i=t.some(s=>s==="int64"||s==="uint64"||s==="int32"||s==="uint32");return u||a||i?"complex128":"complex64"}if(n){let a=t.some(u=>u==="float64");return o&&(t.some(i=>i==="int32"||i==="uint32"||i==="int64"||i==="uint64")||a)||a?"float64":"float32"}if(o){let a=t.some(c=>Bc.includes(c)),u=t.some(c=>Tc.includes(c)),i={bool:8,int8:8,uint8:8,int16:16,uint16:16,int32:32,uint32:32,int64:64,uint64:64,float32:0,float64:0,complex64:0,complex128:0},s=Math.max(...t.map(c=>i[c]??0));return a&&u?s>=32?"int64":s>=16?"int32":"int16":a?s>=64?"int64":s>=32?"int32":s>=16?"int16":"int8":s>=64?"uint64":s>=32?"uint32":s>=16?"uint16":"uint8"}return"bool"}function xs(r){return typeof r=="boolean"?"bool":typeof r=="bigint"?r>=0n?r<=255n?"uint8":r<=65535n?"uint16":r<=4294967295n?"uint32":"uint64":r>=-128n&&r<=127n?"int8":r>=-32768n&&r<=32767n?"int16":r>=-2147483648n&&r<=2147483647n?"int32":"int64":Number.isInteger(r)?r>=0?r<=255?"uint8":r<=65535?"uint16":r<=4294967295?"uint32":"int64":r>=-128&&r<=127?"int8":r>=-32768&&r<=32767?"int16":r>=-2147483648&&r<=2147483647?"int32":"int64":"float64"}function Cs(r,t){let e=r instanceof P?r.dtype:r;if(typeof t=="string")switch(t){case"number":case"numeric":return Ax.includes(e);case"integer":case"int":return fd.includes(e);case"signedinteger":return Bc.includes(e);case"unsignedinteger":return Tc.includes(e);case"floating":case"float":return Mc.includes(e);case"complexfloating":case"complex":return Fc.includes(e);case"inexact":return Mc.includes(e)||Fc.includes(e);default:return e===t}return e===t}function Ss(r){return r}function ws(r,t="GDFgdf",e="d"){let n={b:"int8",B:"uint8",h:"int16",H:"uint16",i:"int32",I:"uint32",l:"int64",L:"uint64",f:"float32",d:"float64",F:"complex64",D:"complex128",g:"float64",G:"complex128"},o={b:0,B:1,h:2,H:3,i:4,I:5,l:6,L:7,f:8,g:9.1,d:9,F:10,G:11.1,D:11};if(r.length===0)return e;let a=[];for(let s of r){let c=n[s];c&&a.push(c)}if(a.length===0)return e;let u=e,i=1/0;for(let s of t){let c=n[s];if(!c)continue;let l=o[s]??1/0,f=!0;for(let m of a)if(!bo(m,c,"safe")){f=!1;break}f&&l<i&&(i=l,u=s)}return u}function Sr(r){return r instanceof P?r:Q(r)}function Oc(r){let t=Sr(r),e=t.data,n=t.size;if(n===0)return Q([1]);let o=[1];for(let a=0;a<n;a++){let u=e[a],i=new Array(o.length+1).fill(0);for(let s=0;s<o.length;s++)i[s]+=o[s],i[s+1]-=o[s]*u;o=i}return Q(o)}function Ec(r,t){let e=Sr(r),n=Sr(t),o=e.data,a=n.data,u=Math.max(e.size,n.size),i=new Array(u).fill(0);for(let c=0;c<e.size;c++)i[u-e.size+c]+=o[c];for(let c=0;c<n.size;c++)i[u-n.size+c]+=a[c];let s=0;for(;s<i.length-1&&i[s]===0;)s++;return Q(i.slice(s))}function Uc(r,t=1){let e=Sr(r);for(let n=0;n<t;n++){let o=e.data,a=e.size;if(a<=1)return Q([0]);let u=[];for(let i=0;i<a-1;i++){let s=a-1-i;u.push(o[i]*s)}e=Q(u)}return e}function $c(r,t){let e=[...Sr(r).data],n=[...Sr(t).data];if(n.length===0||n.length===1&&n[0]===0)throw new Error("Division by zero polynomial");for(;e.length>1&&e[0]===0;)e.shift();for(;n.length>1&&n[0]===0;)n.shift();if(e.length<n.length)return[Q([0]),Q(e)];let o=[],a=[...e];for(;a.length>=n.length;){let u=a[0]/n[0];o.push(u);for(let i=0;i<n.length;i++)a[i]-=u*n[i];a.shift()}for(;a.length>1&&Math.abs(a[0])<1e-15;)a.shift();return[Q(o.length>0?o:[0]),Q(a.length>0?a:[0])]}function kc(r,t,e){let n=r.data,o=t.data,a=r.size;if(e>=a)throw new Error("polyfit: degree must be less than number of points");let u=[];for(let m=0;m<a;m++){let p=[];for(let y=e;y>=0;y--)p.push(Math.pow(n[m],y));u.push(p)}let i=[],s=[];for(let m=0;m<=e;m++){i.push([]);for(let y=0;y<=e;y++){let d=0;for(let b=0;b<a;b++)d+=u[b][m]*u[b][y];i[m].push(d)}let p=0;for(let y=0;y<a;y++)p+=u[y][m]*o[y];s.push(p)}let c=e+1,l=i.map((m,p)=>[...m,s[p]]);for(let m=0;m<c;m++){let p=m;for(let y=m+1;y<c;y++)Math.abs(l[y][m])>Math.abs(l[p][m])&&(p=y);[l[m],l[p]]=[l[p],l[m]];for(let y=m+1;y<c;y++){let d=l[y][m]/l[m][m];for(let b=m;b<=c;b++)l[y][b]-=d*l[m][b]}}let f=new Array(c).fill(0);for(let m=c-1;m>=0;m--){let p=l[m][c];for(let y=m+1;y<c;y++)p-=l[m][y]*f[y];f[m]=p/l[m][m]}return Q(f)}function Rc(r,t=1,e=0){let n=Sr(r),o=Array.isArray(e)?e:[e];for(let a=0;a<t;a++){let u=n.data,i=n.size,s=[];for(let l=0;l<i;l++){let f=i-l;s.push(u[l]/f)}let c=a<o.length?o[a]:0;s.push(c),n=Q(s)}return n}function qc(r,t){let e=Sr(r),n=Sr(t),o=e.data,a=n.data,u=e.size+n.size-1,i=new Array(u).fill(0);for(let s=0;s<e.size;s++)for(let c=0;c<n.size;c++)i[s+c]+=o[s]*a[c];return Q(i)}function Vc(r,t){let e=Sr(r),n=Sr(t),o=e.data,a=n.data,u=Math.max(e.size,n.size),i=new Array(u).fill(0);for(let c=0;c<e.size;c++)i[u-e.size+c]+=o[c];for(let c=0;c<n.size;c++)i[u-n.size+c]-=a[c];let s=0;for(;s<i.length-1&&i[s]===0;)s++;return Q(i.slice(s))}function Pc(r,t){let e=Sr(r),n=e.data;if(typeof t=="number"){let i=n[0];for(let s=1;s<e.size;s++)i=i*t+n[s];return i}let o=t instanceof P?t:Q(t),a=o.data,u=[];for(let i=0;i<o.size;i++){let s=a[i],c=n[0];for(let l=1;l<e.size;l++)c=c*s+n[l];u.push(c)}return Q(u)}function jc(r){let e=[...Sr(r).data];for(;e.length>1&&e[0]===0;)e.shift();let n=0;for(;e.length>1&&e[e.length-1]===0;)e.pop(),n++;let o=e.length-1;if(o+n===0)return md([],[]);let u=[],i=[];if(o===1)u.push(-e[1]/e[0]),i.push(0);else if(o===2){let f=e[0],m=e[1],p=e[2],y=m*m-4*f*p;if(y>=0){let d=Math.sqrt(y);u.push((-m+d)/(2*f),(-m-d)/(2*f)),i.push(0,0)}else{let d=Math.sqrt(-y);u.push(-m/(2*f),-m/(2*f)),i.push(d/(2*f),-d/(2*f))}}else if(o>=3){let f=gx(e,o);for(let m of f)u.push(m.re),i.push(m.im)}for(let f=0;f<n;f++)u.push(0),i.push(0);let s=u.map((f,m)=>m);s.sort((f,m)=>{let p=Math.sqrt(u[f]**2+i[f]**2),y=Math.sqrt(u[m]**2+i[m]**2);return Math.abs(p-y)>1e-10?y-p:Math.abs(u[f]-u[m])>1e-10?u[m]-u[f]:i[m]-i[f]});let c=s.map(f=>u[f]),l=s.map(f=>i[f]);return md(c,l)}function md(r,t){let e=r.length,n=new Float64Array(2*e);for(let a=0;a<e;a++)n[2*a]=r[a],n[2*a+1]=t[a];let o=S.fromData(n,[e],"complex128");return new P(o)}function gx(r,t){let e=Array.from({length:t},()=>new Array(t).fill(0)),n=r[0];for(let o=0;o<t;o++)e[0][o]=-r[o+1]/n;for(let o=1;o<t;o++)e[o][o-1]=1;return hx(e,t)}function hx(r,t){let e=[],o=t,a=0,u=100*t,i=t,s=0;for(;o>0&&a<u;){if(a++,o===i?s++:(s=0,i=o),o===1){e.push({re:r[0][0],im:0}),o=0;break}if(o===2){e.push(...pd(r[0][0],r[0][1],r[1][0],r[1][1])),o=0;break}let c=o-1;for(;c>0;){let y=Math.abs(r[c-1][c-1])+Math.abs(r[c][c]),d=222e-18*(y===0?1:y);if(Math.abs(r[c][c-1])<=d){r[c][c-1]=0;break}c--}let l=o-c;if(l===1){e.push({re:r[o-1][o-1],im:0}),o--;continue}if(l===2){e.push(...pd(r[o-2][o-2],r[o-2][o-1],r[o-1][o-2],r[o-1][o-1])),o-=2;continue}let f;if(s>0&&s%10===0)f=Math.abs(r[o-1][o-2])+Math.abs(r[o-2][o-3]);else{let y=r[o-2][o-2],d=r[o-2][o-1],b=r[o-1][o-2],A=r[o-1][o-1],g=y+A,h=y*A-d*b,N=g*g-4*h;if(N>=0){let D=Math.sqrt(N),x=(g+D)/2,C=(g-D)/2;f=Math.abs(x-A)<Math.abs(C-A)?x:C}else f=A}for(let y=c;y<o;y++)r[y][y]=r[y][y]-f;let m=[],p=[];for(let y=c;y<o-1;y++){let d=Math.hypot(r[y][y],r[y+1][y]),b=d===0?1:r[y][y]/d,A=d===0?0:r[y+1][y]/d;m.push(b),p.push(A);for(let g=y;g<o;g++){let h=r[y][g],N=r[y+1][g];r[y][g]=b*h+A*N,r[y+1][g]=-A*h+b*N}}for(let y=0;y<m.length;y++){let d=c+y,b=m[y],A=p[y],g=Math.min(d+2,o-1);for(let h=c;h<=g;h++){let N=r[h][d],D=r[h][d+1];r[h][d]=b*N+A*D,r[h][d+1]=-A*N+b*D}}for(let y=c;y<o;y++)r[y][y]=r[y][y]+f}if(o>0)for(let c=0;c<o;c++)e.push({re:r[c][c],im:0});return e}function pd(r,t,e,n){let o=r+n,a=r*n-t*e,u=o*o-4*a;if(u>=0){let i=Math.sqrt(u);return[{re:(o+i)/2,im:0},{re:(o-i)/2,im:0}]}else{let i=Math.sqrt(-u);return[{re:o/2,im:i/2},{re:o/2,im:-i/2}]}}var Ao=new Uint8Array([147,78,85,77,80,89]),Lc=["float64","float32","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];function Gc(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}var Nx={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"},Is={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"},yd={S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};function dd(r){if(r.startsWith("[")||r.startsWith("("))throw new Wr(`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 yd)throw new Wr(`Unsupported dtype: ${yd[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Nx[e];if(!o)throw new Wr(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Lc.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Gc(),u=t==="<"||t==="|"||t==="="&&a,i=t===">"||t==="="&&!a,s=parseInt(e.slice(1),10),c=s>1&&(i&&a||u&&!a);return{dtype:o,needsByteSwap:c,itemsize:s}}var Wr=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},hr=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}};function it(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Wc(t);return Yc(t,e)}function Wc(r){if(r.length<10)throw new hr("File too small to be a valid NPY file");for(let c=0;c<Ao.length;c++)if(r[c]!==Ao[c])throw new hr("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new hr(`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 hr("File truncated: header extends beyond file");let u=r.slice(o,a),i=new TextDecoder("utf-8").decode(u).trim(),s=Dx(i);return{version:{major:t,minor:e},header:s,dataOffset:a}}function Yc(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:u}=dd(e.descr),i=e.shape.reduce((d,b)=>d*b,1),s=i*u,c=r.length-n;if(c<s)throw new hr(`File truncated: expected ${s} bytes of data, got ${c}`);let l=new ArrayBuffer(s);new Uint8Array(l).set(r.subarray(n,n+s));let m=xx(l,o,i,a,u),p=e.shape,y;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),b=S.fromData(m,d,o);y=Cx(b,d),p=e.shape}else y=S.fromData(m,[...p],o);return new P(y)}function Dx(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 hr(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",u=n[1].trim(),i;return u===""?i=[]:i=u.split(",").map(s=>s.trim()).filter(s=>s!=="").map(s=>{let c=parseInt(s,10);if(isNaN(c))throw new hr(`Invalid shape value: ${s}`);return c}),{descr:o,fortran_order:a,shape:i}}function xx(r,t,e,n,o){let a=K(t);if(!a)throw new hr(`Cannot create array for dtype: ${t}`);let u=B(t),i=u?e*2:e;if(!n)return new a(r,0,i);let s=new Uint8Array(r),c=new Uint8Array(r.byteLength);if(u){let l=o/2;for(let f=0;f<e*2;f++){let m=f*l;for(let p=0;p<l;p++)c[m+p]=s[m+l-1-p]}}else for(let l=0;l<e;l++){let f=l*o;for(let m=0;m<o;m++)c[f+m]=s[f+o-1-m]}return new a(c.buffer,0,i)}function Cx(r,t){let e=t.length,n=r.size,o=r.dtype,a=K(o);if(!a)throw new hr(`Cannot create array for dtype: ${o}`);let u=new a(n),i=[...t].reverse(),s=bd(t),c=bd(i),l=new Array(e).fill(0);for(let f=0;f<n;f++){let m=f;for(let y=0;y<e;y++){let d=s[y];l[y]=Math.floor(m/d),m=m%d}let p=0;for(let y=0;y<e;y++)p+=l[e-1-y]*c[y];O(o),u[p]=r.iget(f)}return S.fromData(u,i,o)}function bd(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 Kr(r){let t=r.shape,e=r.dtype,n=Is[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,u=12,s=(64-(u+a.length+1)%64)%64;a=a+" ".repeat(s)+`
|
|
4
|
-
`;let c=new TextEncoder().encode(a),l=c.length,f=r.size,m=Yr(e),p=f*m,y=u+l+p,d=new Uint8Array(y);d.set(Ao,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,u);let b=u+l;return Sx(r,d.subarray(b),m),d}function Sx(r,t,e){let n=r.dtype,o=r.size,a=Gc(),u=O(n),i=B(n),s=r.storage;if(s.isCContiguous&&s.offset===0&&a){let l=s.data,f=new Uint8Array(l.buffer,l.byteOffset,o*e);t.set(f)}else{let l=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let f=0;f<o;f++){let m=s.iget(f),p=f*e;u?wx(l,p,m,n==="uint64"):i?Ix(l,p,m,n):zx(l,p,m,n)}}}function wx(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Ix(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 zx(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 _x=(()=>{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 Zc(r){let t=4294967295;for(let e=0;e<r.length;e++)t=_x[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}async function hd(r){let t=Dd(r),e=new Map;for(let n of t){let o=await vx(n);e.set(n.name,o)}return e}function Nd(r){let t=Dd(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 Dd(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),i=[],s=a;for(let c=0;c<u&&e.getUint32(s,!0)===33639248;c++){let f=e.getUint16(s+10,!0),m=e.getUint32(s+16,!0),p=e.getUint32(s+20,!0),y=e.getUint32(s+24,!0),d=e.getUint16(s+28,!0),b=e.getUint16(s+30,!0),A=e.getUint16(s+32,!0),g=e.getUint32(s+42,!0),h=t.slice(s+46,s+46+d),N=new TextDecoder("utf-8").decode(h);i.push({name:N,compressionMethod:f,crc32:m,compressedSize:p,uncompressedSize:y,localHeaderOffset:g}),s=s+46+d+b+A}for(let c of i){let l=c.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let m=e.getUint16(l+26,!0),p=e.getUint16(l+28,!0),y=l+30+m+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 vx(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Mx(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Mx(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),i=new Uint8Array(u),s=0;for(let c of a)i.set(c,s),s+=c.length;return i}async function ho(r,t={}){let e=t.force??!1,n=await hd(r);return xd(n,e)}function No(r,t={}){let e=t.force??!1,n=Nd(r);return xd(n,e)}function xd(r,t){let e=new Map,n=[],o=new Map;for(let[a,u]of r){if(!a.endsWith(".npy"))continue;let i=a.slice(0,-4);try{let s=it(u);e.set(i,s)}catch(s){if(s instanceof Wr&&t)n.push(i),o.set(i,s.message);else throw s}}return{arrays:e,skipped:n,errors:o}}async function Cd(r,t={}){let e=await ho(r,t);return Object.fromEntries(e.arrays)}function Sd(r,t={}){let e=No(r,t);return Object.fromEntries(e.arrays)}async function wd(r,t={}){let e=t.compress??!1,n=[];for(let[m,p]of r){let y=Zc(p),d,b;e?(d=await Bx(p),d.length<p.length?b=8:(d=p,b=0)):(d=p,b=0),n.push({name:m,data:p,compressedData:d,crc:y,compressionMethod:b,offset:0})}let o=0;for(let m of n){let p=new TextEncoder().encode(m.name);o+=30+p.length+m.compressedData.length}let a=0;for(let m of n){let p=new TextEncoder().encode(m.name);a+=46+p.length}let i=o+a+22,s=new Uint8Array(i),c=new DataView(s.buffer),l=0;for(let m of n)m.offset=l,l=zd(s,c,l,m);let f=l;for(let m of n)l=_d(s,c,l,m);return vd(c,l,n.length,a,f),s}function Id(r){let t=[];for(let[l,f]of r){let m=Zc(f);t.push({name:l,data:f,compressedData:f,crc:m,compressionMethod:0,offset:0})}let e=0;for(let l of t){let f=new TextEncoder().encode(l.name);e+=30+f.length+l.compressedData.length}let n=0;for(let l of t){let f=new TextEncoder().encode(l.name);n+=46+f.length}let a=e+n+22,u=new Uint8Array(a),i=new DataView(u.buffer),s=0;for(let l of t)l.offset=s,s=zd(u,i,s,l);let c=s;for(let l of t)s=_d(u,i,s,l);return vd(i,s,t.length,n,c),u}function zd(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 _d(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 vd(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 Bx(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),i=new Uint8Array(u),s=0;for(let c of a)i.set(c,s),s+=c.length;return i}async function _s(r,t={}){let e=Md(r);return wd(e,{compress:t.compress??!1})}function vs(r){let t=Md(r);return Id(t)}function Md(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=Kr(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=Kr(o),u=n.endsWith(".npy")?n:`${n}.npy`;t.set(u,a)}return t}function ut(r,t={}){let{delimiter:e,comments:n="#",skiprows:o=0,usecols:a,max_rows:u,dtype:i="float64",missing_values:s,filling_values:c}=t,l=r.split(/\r?\n/);if(o>0&&(l=l.slice(o)),l=l.filter(d=>{let b=d.trim();return!(b===""||n&&b.startsWith(n))}),u!==void 0&&u>0&&(l=l.slice(0,u)),l.length===0)return Q([],i);let f=[],m=new Set(s?Array.isArray(s)?s:[s]:[]),p=c!==void 0?c:i.includes("int")||i==="bool"?0:NaN;for(let d of l){let b;e===void 0?b=d.trim().split(/\s+/):b=d.split(e),a!==void 0&&(b=(Array.isArray(a)?a:[a]).map(h=>(h<0&&(h=b.length+h),b[h]??"")));let A=b.map(g=>{let h=g.trim();if(m.has(h)||h==="")return p;let N=parseFloat(h);return isNaN(N)?p:N});f.push(A)}let y=f[0]?.length??0;for(let d=1;d<f.length;d++)if(f[d].length!==y)throw new Error(`Inconsistent number of columns: row 0 has ${y} columns, row ${d} has ${f[d].length} columns`);return y===1?Q(f.map(d=>d[0]),i):Q(f,i)}function Do(r,t={}){let e={...t,missing_values:t.missing_values??["","nan","NaN","NA","N/A","-"],filling_values:t.filling_values??NaN};return ut(r,e)}function xo(r,t,e="float64"){let n=typeof t=="string"?new RegExp(t,"gm"):new RegExp(t.source,"gm"),o=[],a;for(;(a=n.exec(r))!==null;)if(a.length>1){let u=a.slice(1).map(i=>{let s=parseFloat(i);return isNaN(s)?0:s});o.push(u)}return o.length===0?Q([],e):o[0].length===1?Q(o.map(u=>u[0]),e):Q(o,e)}function Fd(r,t){let e=typeof r=="bigint"?Number(r):r,n=t.match(/^%([+-]?)(\d*)(?:\.(\d+))?([dfeEgGs])$/);if(!n)return String(e);let[,o,a,u,i]=n,s=u!==void 0?parseInt(u,10):void 0,c;switch(i){case"d":c=Math.round(e).toString();break;case"f":c=e.toFixed(s??6);break;case"e":c=e.toExponential(s??6).replace(/e([+-])(\d)$/,"e$10$2");break;case"E":c=e.toExponential(s??6).toUpperCase().replace(/E([+-])(\d)$/,"E$10$2");break;case"g":case"G":{let l=s??6,f=Math.floor(Math.log10(Math.abs(e)));f>=-4&&f<l?(c=e.toPrecision(l),c.includes(".")&&(c=c.replace(/\.?0+$/,""))):c=e.toExponential(l-1),i==="G"&&(c=c.toUpperCase());break}case"s":c=String(e);break;default:c=String(e)}if(a){let l=parseInt(a,10);if(c.length<l){let f=" ".repeat(l-c.length);o==="-"?c=c+f:c=f+c}}return o==="+"&&e>=0&&!c.startsWith("-")&&(c="+"+c),c}function Ot(r,t={}){let{fmt:e="%.18e",delimiter:n=" ",newline:o=`
|
|
5
|
-
`,header:a,footer:u,comments:i="# "}=t;if(r.ndim>2)throw new Error("savetxt: array must be 1D or 2D");let s=[];if(a!==void 0){let l=a.split(/\r?\n/);for(let f of l)f.startsWith(i.trimEnd())?s.push(f):s.push(i+f)}let c=r.toArray();if(r.ndim===1)for(let l of c)s.push(Fd(l,e));else for(let l of c){let f=l.map(m=>Fd(m,e));s.push(f.join(n))}if(u!==void 0){let l=u.split(/\r?\n/);for(let f of l)f.startsWith(i.trimEnd())?s.push(f):s.push(i+f)}return s.join(o)+o}var q=r=>{if(r instanceof tr)return r;let t=r.base?q(r.base):void 0;return tr.fromStorage(r.storage,t)},tr=class r extends P{constructor(t,e){super(t,e),this._base=e}static fromStorage(t,e){return new r(t,e)}get base(){return this._base??null}get T(){return this.transpose()}get itemsize(){return Yr(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){let e=this._storage.dtype,n=this.size;if(O(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 i=a;if(i<0&&(i=this.shape[u]+i),i<0||i>=this.shape[u])throw new Error(`Index ${a} is out of bounds for axis ${u} with size ${this.shape[u]}`);return i}),o=this.dtype;if(B(o))this._storage.set(n,e);else if(O(o)){let a=e instanceof U?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 U?e.re:Number(e))?1:0;this._storage.set(n,u)}else{let a=e instanceof U?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=K(t);if(!u)throw new Error(`Cannot convert to dtype ${t}`);let i=new u(a),s=this.data;if(O(n)&&!O(t)){let l=s;if(t==="bool")for(let f=0;f<a;f++)i[f]=l[f]!==BigInt(0)?1:0;else for(let f=0;f<a;f++)i[f]=Number(l[f])}else if(!O(n)&&O(t)){let l=s;for(let f=0;f<a;f++)i[f]=BigInt(Math.round(Number(l[f])))}else if(t==="bool"){let l=s;for(let f=0;f<a;f++)i[f]=l[f]!==0?1:0}else if(n==="bool"&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else if(!O(n)&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else{let l=s;for(let f=0;f<a;f++)i[f]=l[f]}let c=S.fromData(i,o,t);return new r(c)}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=Fo(s);return Bo(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 f;c.step>0?f=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):f=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(f),o.push(l*c.step)}}let u=S.fromData(this._storage.data,n,this._storage.dtype,o,a),i=this._base??this;return new r(u,i)}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}`)}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=Be(this,e).storage,a=n.data===this.data?this._base??this:void 0;return r.fromStorage(n,a)}ravel(){let t=Te(this).storage,n=t.data===this.data?this._base??this:void 0;return r.fromStorage(t,n)}put(t,e){let n=e instanceof r?e._storage:e;Tt(this,t,n)}compress(t,e){let n=t instanceof r?t:r.fromStorage(S.fromData(new Uint8Array(t.map(o=>o?1:0)),[t.length],"bool"));return q(st(n,this,e))}choose(t){return q(po(this,t))}clip(t,e){return q(fe(this,t,e))}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 U?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 q(st(t,this,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 i=0;i<t[a];i++)o[a]=i,u.push(n(o,a+1));return u};return n(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){let n=this._storage.data,o=n.BYTES_PER_ELEMENT,a=this._storage.offset*o,u=this.size*o;return n.buffer.slice(a,a+u)}let e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){let e=t[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(t)}byteswap(t=!1){let e=t?this:this.copy(),n=e._storage.data,o=n.BYTES_PER_ELEMENT;if(o===1)return e;let a=n.buffer,u=new DataView(a);for(let i=0;i<n.length;i++){let s=i*o;if(o===2){let c=u.getUint8(s),l=u.getUint8(s+1);u.setUint8(s,l),u.setUint8(s+1,c)}else if(o===4){let c=u.getUint8(s),l=u.getUint8(s+1),f=u.getUint8(s+2),m=u.getUint8(s+3);u.setUint8(s,m),u.setUint8(s+1,f),u.setUint8(s+2,l),u.setUint8(s+3,c)}else if(o===8){let c=u.getUint8(s),l=u.getUint8(s+1),f=u.getUint8(s+2),m=u.getUint8(s+3),p=u.getUint8(s+4),y=u.getUint8(s+5),d=u.getUint8(s+6),b=u.getUint8(s+7);u.setUint8(s,b),u.setUint8(s+1,d),u.setUint8(s+2,y),u.setUint8(s+3,p),u.setUint8(s+4,m),u.setUint8(s+5,f),u.setUint8(s+6,l),u.setUint8(s+7,c)}}return e}view(t){if(!t||t===this.dtype)return r.fromStorage(this._storage,this._base??this);let e=Yr(this.dtype),n=Yr(t);if(e!==n)throw new Error("When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.");let o=K(t);if(!o)throw new Error(`Unsupported dtype: ${t}`);let a=this._storage.data,u=a.byteOffset+this._storage.offset*e,i=new o(a.buffer,u,this.size),s=S.fromData(i,[...this.shape],t,[...this._storage.strides],0);return r.fromStorage(s,this._base??this)}tofile(t,e="",n=""){throw new Error('tofile() requires file system access. Use the node module: import { save } from "numpy-ts/node"')}round(t=0){return this.around(t)}conjugate(){return this.conj()}around(t=0){return q(Ft(this,t))}allclose(t,e=1e-5,n=1e-8){return vt(this,t,e,n)}isclose(t,e=1e-5,n=1e-8){return q(jn(this,t,e,n))}average(t,e){let n=on(this,e,t);return n instanceof P?q(n):n}dot(t){let e=At(this,t);return e instanceof P?q(e):e}trace(){return et(this)}inner(t){let e=Nt(this,t);return e instanceof P?q(e):e}tensordot(t,e=2){let n=xt(this,t,e);return n instanceof P?q(n):n}divmod(t){let e=ie(this,t);return[q(e[0]),q(e[1])]}searchsorted(t,e="left"){return q(Mt(this,t,e))}sqrt(){return q(Vt(this))}exp(){return q(jt(this))}exp2(){return q(Lt(this))}expm1(){return q(Gt(this))}log(){return q(Wt(this))}log2(){return q(Yt(this))}log10(){return q(Zt(this))}log1p(){return q(Jt(this))}absolute(){return q(Qt(this))}negative(){return q(Ht(this))}sign(){return q(re(this))}positive(){return q(ne(this))}reciprocal(){return q(oe(this))}ceil(){return q(oo(this))}fix(){return q(ao(this))}floor(){return q(so(this))}rint(){return q(io(this))}trunc(){return q(uo(this))}sin(){return q(me(this))}cos(){return q(pe(this))}tan(){return q(ye(this))}arcsin(){return q(de(this))}arccos(){return q(be(this))}arctan(){return q(Ae(this))}degrees(){return q(Ne(this))}radians(){return q(De(this))}sinh(){return q(xe(this))}cosh(){return q(Ce(this))}tanh(){return q(Se(this))}arcsinh(){return q(we(this))}arccosh(){return q(Ie(this))}arctanh(){return q(ze(this))}bitwise_not(){return q(ro(this))}invert(){return q(to(this))}logical_not(){return q(zn(this))}isfinite(){return q(vn(this))}isinf(){return q(Mn(this))}isnan(){return q(Fn(this))}isnat(){return q(Bn(this))}signbit(){return q(On(this))}spacing(){return q(Un(this))}cbrt(){return q(ae(this))}fabs(){return q(se(this))}square(){return q(ue(this))}conj(){return q(fo(this))}flatten(){return q(Br(this))}argwhere(){return q(Jn(this))}add(t){return q(kt(this,t))}subtract(t){return q(Rt(this,t))}multiply(t){return q(qt(this,t))}divide(t){return q(pt(this,t))}mod(t){return q(te(this,t))}floor_divide(t){return q(ee(this,t))}power(t){return q(Pt(this,t))}logaddexp(t){return q(Xt(this,t))}logaddexp2(t){return q(Kt(this,t))}arctan2(t){return q(ge(this,t))}hypot(t){return q(he(this,t))}greater(t){return q($n(this,t))}greater_equal(t){return q(kn(this,t))}less(t){return q(Rn(this,t))}less_equal(t){return q(qn(this,t))}equal(t){return q(Vn(this,t))}not_equal(t){return q(Pn(this,t))}bitwise_and(t){return q(Kn(this,t))}bitwise_or(t){return q(Qn(this,t))}bitwise_xor(t){return q(Hn(this,t))}left_shift(t){return q(eo(this,t))}right_shift(t){return q(no(this,t))}logical_and(t){return q(wn(this,t))}logical_or(t){return q(In(this,t))}logical_xor(t){return q(_n(this,t))}copysign(t){return q(Tn(this,t))}nextafter(t){return q(En(this,t))}remainder(t){return q(ce(this,t))}heaviside(t){return q(le(this,t))}matmul(t){return q(Fe(this,t))}outer(t){return q(Dt(this,t))}sum(t,e=!1){let n=Le(this,t,e);return n instanceof P?q(n):n}mean(t,e=!1){let n=Ge(this,t,e);return n instanceof P?q(n):n}prod(t,e=!1){let n=We(this,t,e);return n instanceof P?q(n):n}max(t,e=!1){let n=Ye(this,t,e);return n instanceof P?q(n):n}min(t,e=!1){let n=Je(this,t,e);return n instanceof P?q(n):n}ptp(t,e=!1){let n=Ke(this,t,e);return n instanceof P?q(n):n}nansum(t,e=!1){let n=ln(this,t,e);return n instanceof P?q(n):n}nanprod(t,e=!1){let n=fn(this,t,e);return n instanceof P?q(n):n}nanmean(t,e=!1){let n=mn(this,t,e);return n instanceof P?q(n):n}nanmin(t,e=!1){let n=dn(this,t,e);return n instanceof P?q(n):n}nanmax(t,e=!1){let n=bn(this,t,e);return n instanceof P?q(n):n}argmin(t){let e=Qe(this,t);return e instanceof P?q(e):e}argmax(t){let e=He(this,t);return e instanceof P?q(e):e}nanargmin(t){let e=An(this,t);return e instanceof P?q(e):e}nanargmax(t){let e=gn(this,t);return e instanceof P?q(e):e}var(t,e=0,n=!1){let o=nt(this,t,e,n);return o instanceof P?q(o):o}std(t,e=0,n=!1){let o=rn(this,t,e,n);return o instanceof P?q(o):o}nanvar(t,e=0,n=!1){let o=pn(this,t,e,n);return o instanceof P?q(o):o}nanstd(t,e=0,n=!1){let o=yn(this,t,e,n);return o instanceof P?q(o):o}all(t,e=!1){let n=an(this,t,e);return n instanceof P?q(n):n}any(t,e=!1){let n=sn(this,t,e);return n instanceof P?q(n):n}median(t,e=!1){let n=tn(this,t,e);return n instanceof P?q(n):n}nanmedian(t,e=!1){let n=Dn(this,t,e);return n instanceof P?q(n):n}percentile(t,e,n=!1){let o=en(this,t,e,n);return o instanceof P?q(o):o}quantile(t,e,n=!1){let o=nn(this,t,e,n);return o instanceof P?q(o):o}nanquantile(t,e,n=!1){let o=xn(this,t,e,n);return o instanceof P?q(o):o}nanpercentile(t,e,n=!1){let o=Cn(this,t,e,n);return o instanceof P?q(o):o}cumsum(t){return q(un(this,t))}cumprod(t){return q(cn(this,t))}nancumsum(t){return q(hn(this,t))}nancumprod(t){return q(Nn(this,t))}sort(t=-1){return q(Ln(this,t))}argsort(t=-1){return q(Gn(this,t))}partition(t,e=-1){return q(Wn(this,t,e))}argpartition(t,e=-1){return q(Yn(this,t,e))}diagonal(t=0,e=0,n=1){return q(gt(this,t,e,n))}resize(t){return q(qe(this,t))}diff(t=1,e=-1){return q(lo(this,t,e))}take(t,e){return q(Bt(this,t,e))}repeat(t,e){return q(ke(this,t,e))}transpose(t){return q(ht(this,t))}squeeze(t){return q(Oe(this,t))}expand_dims(t){return q(Ee(this,t))}swapaxes(t,e){return q(Ue(this,t,e))}moveaxis(t,e){return q($e(this,t,e))}nonzero(){return Zn(this).map(q)}};function Jc(...r){let t=[],e="xy";for(let i of r)i instanceof tr?t.push(i):typeof i=="object"&&"indexing"in i&&(e=i.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(i=>i.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 i=0;i<t.length;i++){let s=t[i],c=s.size,l=new Array(a).fill(1);l[i]=c;let f=s.reshape(...l),m=mo(f,o),p=tr.fromStorage(m.storage.copy());u.push(p)}return e==="xy"&&u.length>=2&&([u[0],u[1]]=[u[1],u[0]]),u}var F=r=>{if(r instanceof tr)return r;let t=r.base?F(r.base):void 0;return tr.fromStorage(r.storage,t)};function Bd(r,t){return F(mo(r,t))}function Td(r,t,e){return F(Bt(r,t,e))}function Od(r,t,e){return F(lc(r,t,e))}function Ed(r,t){return F(po(r,t))}function Ud(r,t,e){return F(st(r,t,e))}function $d(r,t,e=0){return F(fc(r,t,e))}function kd(r,t,e){return F(mc(r,t,e))}function Rd(r,t,e=0){return F(pc(r,t,e))}function qd(r,t="int32"){return F(yc(r,t))}function Vd(r,t,e="raise"){return F(dc(r,t,e))}function Pd(r,t){return bc(r,t).map(F)}function jd(r,t=2){return Ac(r,t).map(F)}function Ld(r){return gc(r).map(F)}function Gd(r,t=0,e){return hc(r,t,e).map(F)}function Wd(r,t=0){return Nc(r,t).map(F)}function Yd(r,t=0,e){return Dc(r,t,e).map(F)}function Zd(r,t=0){return xc(r,t).map(F)}function Jd(r,t,e=0){return Cc(r,t,e).map(F)}function Xd(r,t,e){return F(Sc(o=>r(F(o)),t,e))}function Kd(r,t,e){return F(wc((o,a)=>r(F(o),a),t,e))}function Qd(r,t){return F(kt(r,t))}function Hd(r,t){return F(Rt(r,t))}function rb(r,t){return F(qt(r,t))}function tb(r){return F(Vt(r))}function Xc(r,t){return F(Pt(r,t))}function eb(r){return F(jt(r))}function nb(r){return F(Lt(r))}function ob(r){return F(Gt(r))}function ab(r){return F(Wt(r))}function sb(r){return F(Yt(r))}function ib(r){return F(Zt(r))}function ub(r){return F(Jt(r))}function cb(r,t){return F(Xt(r,t))}function lb(r,t){return F(Kt(r,t))}function Kc(r){return F(Qt(r))}function fb(r){return F(Ht(r))}function mb(r){return F(re(r))}function pb(r,t){return F(te(r,t))}function yb(r,t){return F(pt(r,t))}function db(r,t){return F(ee(r,t))}function bb(r){return F(ne(r))}function Ab(r){return F(oe(r))}function gb(r){return F(ae(r))}function hb(r){return F(se(r))}function Nb(r,t){let e=ie(r,t);return[F(e[0]),F(e[1])]}function Db(r){return F(ue(r))}function xb(r,t){return F(ce(r,t))}function Cb(r,t){return F(le(r,t))}function Sb(r,t){return F(fi(r,t))}function wb(r,t){return F(mi(r,t))}function Ib(r){let t=pi(r);return[F(t[0]),F(t[1])]}function zb(r,t){return F(yi(r,t))}function _b(r,t){return F(di(r,t))}function vb(r,t){return F(bi(r,t))}function Mb(r){let t=Ai(r);return[F(t[0]),F(t[1])]}function Fb(r,t,e){return F(fe(r,t,e))}function Bb(r,t){return F(gi(r,t))}function Tb(r,t){return F(hi(r,t))}function Ob(r,t){return F(Ni(r,t))}function Eb(r,t){return F(Di(r,t))}function Ub(r,t=0,e,n){return F(xi(r,t,e,n))}function $b(r,t,e,n,o){return F(Ci(r,t,e,n,o))}function kb(r,t=Math.PI,e=-1,n=2*Math.PI){return F(Si(r,t,e,n))}function Rb(r){return F(wi(r))}function qb(r){return F(Ii(r))}function Vb(r,t){return F(Kn(r,t))}function Pb(r,t){return F(Qn(r,t))}function jb(r,t){return F(Hn(r,t))}function Qc(r){return F(ro(r))}function Lb(r){return F(to(r))}function Hc(r,t){return F(eo(r,t))}function rl(r,t){return F(no(r,t))}function Gb(r,t,e){return F(Fu(r,t,e))}function Wb(r,t,e,n){return F(Bu(r,t,e,n))}function Yb(r){return F(Tu(r))}function Zb(r){return F(tc(r))}function Jb(r){return F(ec(r))}function tl(r){return F(fo(r))}function Xb(r,t){return F(nc(r,t))}function Kb(r,t=er){return F(wr(r,t))}function Qb(r,t=er){return F(Oo(r,t))}function Hb(r,t=er){return F(Eo(r,t))}function rA(r,t,e){return F(Uo(r,t,e))}function tA(r,t){return F(Q(r,t))}function eA(r,t,e=1,n=er){return F(ks(r,t,e,n))}function nA(r,t,e=50,n=er){return F(Rs(r,t,e,n))}function oA(r,t,e=50,n=10,o=er){return F(qs(r,t,e,n,o))}function aA(r,t,e=50,n=er){return F(Vs(r,t,e,n))}function sA(r,t,e=0,n=er){return F($o(r,t,e,n))}function iA(r,t=er){return F(Ps(r,t))}function uA(r,t){return F(Qr(r,t))}function cA(r,t){return F(js(r,t))}function lA(r,t){return F(Ls(r,t))}function fA(r,t){return F(Gs(r,t))}function mA(r,t,e){return F(Ws(r,t,e))}function pA(r){return F(Ys(r))}function yA(r,t){return F(Zs(r,t))}function dA(r,t){return F(Js(r,t))}function bA(r,t){return F(Xs(r,t))}function AA(r,t){return F(Ks(r,t))}function gA(r,t,e){return F(Qs(r,t,e))}function hA(r,t=0){return F(ko(r,t))}function NA(r,t=0){return F(Hs(r,t))}function DA(r,t,e=0,n=er){return F(ri(r,t,e,n))}function xA(r,t=0){return F(ti(r,t))}function CA(r,t=0){return F(ei(r,t))}function SA(r,t,e=!1){return F(ni(r,t,e))}function wA(r,t=er,e=-1,n=0){return F(oi(r,t,e,n))}function IA(r,t,e=er){return F(ai(r,t,e))}function zA(r,t=er,e=-1){return F(si(r,t,e))}function _A(r,t=er,e=-1,n){return F(ii(r,t,e,n))}function vA(r,t=er,e=-1,n=""){return F(ui(r,t,e,n))}function MA(r,t,e){return F(lo(r,t,e))}function FA(r,t,e){return F(rc(r,t,e))}function BA(r,t){let e=At(r,t);return e instanceof P?F(e):e}function TA(r,t=0,e=0,n=1){return F(gt(r,t,e,n))}function OA(r,t){return F(Li(r,t))}function EA(r,t){return F(ht(r,t))}function UA(r,t){let e=Nt(r,t);return e instanceof P?F(e):e}function $A(r,t){return F(Dt(r,t))}function kA(r,t,e=2){let n=xt(r,t,e);return n instanceof P?F(n):n}function RA(r,t,e=-1){let n=Wo(r,t,e);return n instanceof P?F(n):n}function qA(r){return F(Yo(r))}function VA(r,t){return F(Zo(r,t))}function PA(r,t){return F(Gi(r,t))}function jA(r,t){return F(Wi(r,t))}function LA(r,t,e=-1,n=-1,o=-1,a){let u=Jo(r,t,e,n,o,a),i=or(r.dtype,t.dtype);if(u instanceof U){let c=K(i==="complex64"?"float32":"float64"),l=new c(2);return l[0]=u.re,l[1]=u.im,tr.fromStorage(S.fromData(l,[],i))}if(typeof u=="number"){if(B(i)){let f=K(i==="complex64"?"float32":"float64"),m=new f(2);return m[0]=u,m[1]=0,tr.fromStorage(S.fromData(m,[],i))}let s=K(i),c=new s(1);return c[0]=u,tr.fromStorage(S.fromData(c,[],i))}return F(u)}function GA(r,t){return F(Fe(r,t))}function WA(r,t){return F(wn(r,t))}function YA(r,t){return F(In(r,t))}function ZA(r){return F(zn(r))}function JA(r,t){return F(_n(r,t))}function XA(r){return F(vn(r))}function KA(r){return F(Mn(r))}function QA(r){return F(Fn(r))}function HA(r){return F(Bn(r))}function rg(r){return F(Au(r))}function tg(r){return F(gu(r))}function eg(r){return F(hu(r))}function ng(r){return F(Nu(r))}function og(r,t){return F(Du(r,t))}function ag(r,t){return F(Tn(r,t))}function sg(r){return F(On(r))}function ig(r,t){return F(En(r,t))}function ug(r){return F(Un(r))}function cg(r,t){return F($n(r,t))}function lg(r,t){return F(kn(r,t))}function fg(r,t){return F(Rn(r,t))}function mg(r,t){return F(qn(r,t))}function pg(r,t){return F(Vn(r,t))}function yg(r,t){return F(Pn(r,t))}function dg(r,t,e=1e-5,n=1e-8){return F(jn(r,t,e,n))}function bg(r){return F(Oc(r))}function Ag(r,t){return F(Ec(r,t))}function gg(r,t=1){return F(Uc(r,t))}function hg(r,t){let e=$c(r,t);return[F(e[0]),F(e[1])]}function Ng(r,t,e){return F(kc(r,t,e))}function Dg(r,t=1,e=0){return F(Rc(r,t,e))}function xg(r,t){return F(qc(r,t))}function Cg(r,t){return F(Vc(r,t))}function Sg(r,t){let e=Pc(r,t);return e instanceof P?F(e):e}function wg(r){return F(jc(r))}function Ig(r,t,e){let n=Le(r,t,e);return n instanceof P?F(n):n}function zg(r,t,e){let n=Ge(r,t,e);return n instanceof P?F(n):n}function _g(r,t,e){let n=We(r,t,e);return n instanceof P?F(n):n}function vg(r,t,e){let n=Ke(r,t,e);return n instanceof P?F(n):n}function Mg(r,t){let e=Qe(r,t);return e instanceof P?F(e):e}function Fg(r,t){let e=He(r,t);return e instanceof P?F(e):e}function Bg(r,t,e,n){let o=nt(r,t,e,n);return o instanceof P?F(o):o}function Tg(r,t,e,n){let o=rn(r,t,e,n);return o instanceof P?F(o):o}function Og(r,t,e){let n=tn(r,t,e);return n instanceof P?F(n):n}function Eg(r,t,e,n){let o=en(r,t,e,n);return o instanceof P?F(o):o}function Ug(r,t,e,n){let o=nn(r,t,e,n);return o instanceof P?F(o):o}function $g(r,t,e,n){let o=on(r,t,e,n);return o instanceof P?F(o):o}function kg(r,t,e){let n=an(r,t,e);return n instanceof P?F(n):n}function Rg(r,t,e){let n=sn(r,t,e);return n instanceof P?F(n):n}function el(r,t){return F(un(r,t))}function nl(r,t){return F(cn(r,t))}function qg(r,t,e){let n=ln(r,t,e);return n instanceof P?F(n):n}function Vg(r,t,e){let n=fn(r,t,e);return n instanceof P?F(n):n}function Pg(r,t,e){let n=mn(r,t,e);return n instanceof P?F(n):n}function jg(r,t,e,n){let o=pn(r,t,e,n);return o instanceof P?F(o):o}function Lg(r,t,e,n){let o=yn(r,t,e,n);return o instanceof P?F(o):o}function Gg(r,t,e){let n=dn(r,t,e);return n instanceof P?F(n):n}function Wg(r,t,e){let n=bn(r,t,e);return n instanceof P?F(n):n}function Yg(r,t){let e=An(r,t);return e instanceof P?F(e):e}function Zg(r,t){let e=gn(r,t);return e instanceof P?F(e):e}function Jg(r,t){return F(hn(r,t))}function Xg(r,t){return F(Nn(r,t))}function Kg(r,t,e){let n=Dn(r,t,e);return n instanceof P?F(n):n}function Qg(r,t,e,n){let o=xn(r,t,e,n);return o instanceof P?F(o):o}function Hg(r,t,e,n){let o=Cn(r,t,e,n);return o instanceof P?F(o):o}function ol(r,t=0){return F(Ft(r,t))}function rh(r){return F(oo(r))}function th(r){return F(ao(r))}function eh(r){return F(so(r))}function nh(r){return F(io(r))}function oh(r){return F(uo(r))}function ah(r,t){return F(Uu(r,t))}function sh(r,t){return F($u(r,t))}function ih(r,t){return F(ku(r,t))}function uh(r,t){return F(Ru(r,t))}function ch(r,t){return F(qu(r,t))}function lh(r,t){return F(Vu(r,t))}function fh(r,t){return F(Pu(r,t))}function mh(r){return F(ju(r))}function ph(r,t,e){return F(zc(r,t,e))}function al(r,t,e){return F(hs(r,t,e))}function yh(r,t,e,n){return F(_c(r,t,e,n))}function dh(r,t,e="constant",n=0){return F(vc(r,t,e,n))}function bh(r,t){return F(Be(r,t))}function Ah(r){return F(Br(r))}function gh(r){return F(Te(r))}function hh(r,t){return F(Oe(r,t))}function Nh(r,t){return F(Ee(r,t))}function Dh(r,t,e){return F(Ue(r,t,e))}function xh(r,t,e){return F($e(r,t,e))}function Ch(r,t,e=0){return F(Yi(r,t,e))}function sl(r,t=0){return F(Ct(r,t))}function Sh(r,t=0){return F(Zi(r,t))}function wh(r){return F(Ko(r))}function Ih(r){return F(Ji(r))}function zh(r){return F(Xi(r))}function _h(r){return F(Ki(r))}function vh(r){return F(Qi(r))}function Mh(r,t=0){return Hi(r,t).map(F)}function Fh(r,t){return F(ru(r,t))}function Bh(r,t,e){return F(ke(r,t,e))}function Th(r,t){return F(Re(r,t))}function Oh(r){return F(tu(r))}function Eh(r){return F(eu(r))}function Uh(r,t=1,e=[0,1]){return F(nu(r,t,e))}function $h(r,t,e){return F(ou(r,t,e))}function kh(r,t){return F(qe(r,t))}function Rh(r,t=-1){return F(Ln(r,t))}function qh(r,t=-1){return F(Gn(r,t))}function Vh(r){return F(Su(r))}function Ph(r,t,e=-1){return F(Wn(r,t,e))}function jh(r,t,e=-1){return F(Yn(r,t,e))}function Lh(r){return F(wu(r))}function Gh(r){return Zn(r).map(F)}function Wh(r){return F(Jn(r))}function Yh(r){return F(Iu(r))}function Zh(r,t){return F(zu(r,t))}function Jh(r,t,e){return F(Yu(r,t,e))}function Xh(r,t,e){return F(Zu(r,t,e))}function Kh(r,t,e){return F(Ju(r,t,e))}function Qh(r,t,e){return F(Xu(r,t,e))}function Hh(r,t,e,n,o){return F(Ku(r,t,e,n,o))}function r0(r,t,e){return F(Qu(r,t,e))}function t0(r,t,e,n){let o=Hu(r,t,e,n);return o instanceof P?F(o):o}function e0(r){return F(me(r))}function n0(r){return F(pe(r))}function o0(r){return F(ye(r))}function il(r){return F(de(r))}function ul(r){return F(be(r))}function cl(r){return F(Ae(r))}function ll(r,t){return F(ge(r,t))}function a0(r,t){return F(he(r,t))}function s0(r){return F(Ne(r))}function i0(r){return F(De(r))}function u0(r){return F(vi(r))}function c0(r){return F(Mi(r))}function l0(r){return F(xe(r))}function f0(r){return F(Ce(r))}function m0(r){return F(Se(r))}function fl(r){return F(we(r))}function ml(r){return F(Ie(r))}function pl(r){return F(ze(r))}var Tr=624,Ms=397,Kx=2567483615,yl=2147483648,dl=2147483647,Mr={mt:new Uint32Array(Tr),mti:Tr+1};function y0(r){let t=Mr.mt;t[0]=r>>>0;for(let e=1;e<Tr;e++){let n=t[e-1]^t[e-1]>>>30;t[e]=Math.imul(1812433253,n)+e>>>0}Mr.mti=Tr}function gl(){let r=Mr.mt,t,e=[0,Kx];if(Mr.mti>=Tr){let n;for(Mr.mti===Tr+1&&y0(5489),n=0;n<Tr-Ms;n++)t=r[n]&yl|r[n+1]&dl,r[n]=r[n+Ms]^t>>>1^e[t&1];for(;n<Tr-1;n++)t=r[n]&yl|r[n+1]&dl,r[n]=r[n+(Ms-Tr)]^t>>>1^e[t&1];t=r[Tr-1]&yl|r[0]&dl,r[Tr-1]=r[Ms-1]^t>>>1^e[t&1],Mr.mti=0}return t=r[Mr.mti++],t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^=t>>>18,t>>>0}function G(){let r=gl()>>>5,t=gl()>>>6;return(r*67108864+t)/9007199254740992}var Qx=2468251765,Hx=1492356589,r1=1135663077,t1=2337405405,e1=3389127133,n1=1232336661,Dl=16,Fs=4;function mr(r){return r>>>0}function bl(r,t){return r=mr(mr(r)^t.val),t.val=mr(Math.imul(t.val,Qx)),r=mr(Math.imul(r,t.val)),r=mr(r^r>>>Dl),r}function o1(r,t){let e=mr(mr(Math.imul(e1,mr(r)))-mr(Math.imul(n1,mr(t))));return e=mr(e^e>>>Dl),e}function a1(r){let t=[0,0,0,0],e=[r>>>0],n={val:r1};for(let o=0;o<Fs;o++)o<e.length?t[o]=bl(e[o],n):t[o]=bl(0,n);for(let o=0;o<Fs;o++)for(let a=0;a<Fs;a++)if(o!==a){let u=bl(t[o],n);t[a]=o1(t[a],u)}return t}function s1(r,t){let e=[],n=t1;for(let o=0;o<t;o++){let a=r[o%Fs],u=mr(a^n);n=mr(Math.imul(n,Hx)),u=mr(Math.imul(u,n)),u=mr(u^u>>>Dl),e.push(u)}return e}var i1=BigInt("4865540595714422341"),u1=BigInt("2549297995355413924"),c1=u1<<BigInt(64)|i1,Al=BigInt("0xffffffffffffffff"),hl=(BigInt(1)<<BigInt(128))-BigInt(1);function l1(r){let t=r>>BigInt(64),e=r&Al,n=(t^e)&Al,o=Number(r>>BigInt(122));return(n>>BigInt(o)|n<<BigInt(64-o))&Al}function Nl(r,t){return r*c1+t&hl}function p0(r){let t=a1(r),e=s1(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),i=n<<BigInt(64)|o,s=(a<<BigInt(64)|u)<<BigInt(1);s=(s|BigInt(1))&hl;let c=BigInt(0);return c=Nl(c,s),c=c+i&hl,c=Nl(c,s),{state:c,inc:s}}function f1(r){return r.state=Nl(r.state,r.inc),l1(r.state)}function m1(r){let e=f1(r)>>BigInt(11);return Number(e)/9007199254740992}var Co=class{constructor(t){if(t!==void 0)this._pcgState=p0(t);else{let e=Math.floor(Math.random()*4294967296);this._pcgState=p0(e)}}_randomFloat(){return m1(this._pcgState)}random(t){if(t===void 0)return this._randomFloat();let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.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=S.zeros(o,"int64"),i=u.data,s=e-t;for(let c=0;c<a;c++)i[c]=BigInt(Math.floor(this._randomFloat()*s)+t);return u}standard_normal(t){if(t===void 0)return Fr(this._randomFloat.bind(this));let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u+=2){let[i,s]=So(this._randomFloat.bind(this));a[u]=i,u+1<n&&(a[u+1]=s)}return o}normal(t=0,e=1,n){if(n===void 0)return Fr(this._randomFloat.bind(this))*e+t;let o=Array.isArray(n)?n:[n],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s+=2){let[c,l]=So(this._randomFloat.bind(this));i[s]=c*e+t,s+1<a&&(i[s+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=S.zeros(o,"float64"),i=u.data,s=e-t;for(let c=0;c<a;c++)i[c]=this._randomFloat()*s+t;return u}choice(t,e,n=!0,o){return I0(t,e,n,o,this._randomFloat.bind(this))}permutation(t){return _0(t,this._randomFloat.bind(this))}shuffle(t){M0(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((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=-Math.log(1-this._randomFloat())*t;return a}poisson(t=1,e){if(e===void 0)return ct(t,this._randomFloat.bind(this));let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"int64"),u=a.data;for(let i=0;i<o;i++)u[i]=BigInt(ct(t,this._randomFloat.bind(this)));return a}binomial(t,e,n){if(n===void 0)return wo(t,e,this._randomFloat.bind(this));let o=Array.isArray(n)?n:[n],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"int64"),i=u.data;for(let s=0;s<a;s++)i[s]=BigInt(wo(t,e,this._randomFloat.bind(this)));return u}};function d0(r){return new Co(r)}function b0(r){r==null&&(r=Math.floor(Date.now()^Math.random()*4294967296)),y0(r>>>0)}function A0(){return{mt:Array.from(Mr.mt),mti:Mr.mti}}function g0(r){Mr.mt=new Uint32Array(r.mt),Mr.mti=r.mti}function Fr(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 So(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 ct(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=Fr(t);return Math.max(0,Math.round(r+Math.sqrt(r)*e))}}function wo(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=Fr(e);return Math.max(0,Math.min(r,Math.round(n+o*a)))}}function Io(r){if(r===void 0)return G();let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=G();return n}function h0(...r){if(r.length===0)return G();let t=r.reduce((o,a)=>o*a,1),e=S.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o++)n[o]=G();return e}function N0(...r){if(r.length===0)return Fr(G);let t=r.reduce((o,a)=>o*a,1),e=S.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o+=2){let[a,u]=So(G);n[o]=a,o+1<t&&(n[o+1]=u)}return e}function xl(r,t,e,n="int64"){t==null&&(t=r,r=0);let o=t-r;if(e===void 0)return Math.floor(G()*o)+r;let a=Array.isArray(e)?e:[e],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,n),s=i.data;if(O(n)){let c=s;for(let l=0;l<u;l++)c[l]=BigInt(Math.floor(G()*o)+r)}else{let c=s;for(let l=0;l<u;l++)c[l]=Math.floor(G()*o)+r}return i}function D0(r=0,t=1,e){if(e===void 0)return G()*(t-r)+r;let n=Array.isArray(e)?e:[e],o=n.reduce((s,c)=>s*c,1),a=S.zeros(n,"float64"),u=a.data,i=t-r;for(let s=0;s<o;s++)u[s]=G()*i+r;return a}function x0(r=0,t=1,e){if(e===void 0)return Fr(G)*t+r;let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i+=2){let[s,c]=So(G);u[i]=s*t+r,i+1<o&&(u[i+1]=c*t+r)}return a}function C0(r){if(r===void 0)return Fr(G);let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a+=2){let[u,i]=So(G);o[a]=u,a+1<e&&(o[a+1]=i)}return n}function Cl(r=1,t){if(t===void 0)return-Math.log(1-G())*r;let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u++)a[u]=-Math.log(1-G())*r;return o}function S0(r=1,t){if(t===void 0)return ct(r,G);let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.zeros(e,"int64"),a=o.data;for(let u=0;u<n;u++)a[u]=BigInt(ct(r,G));return o}function w0(r,t,e){if(e===void 0)return wo(r,t,G);let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"int64"),u=a.data;for(let i=0;i<o;i++)u[i]=BigInt(wo(r,t,G));return a}function I0(r,t,e=!0,n,o=G){let a;if(typeof r=="number")a=Array.from({length:r},(m,p)=>p);else{let m=r.size;a=[];for(let p=0;p<m;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 i;if(n!==void 0){if(Array.isArray(n))i=n;else{let p=n.size;i=[];for(let y=0;y<p;y++)i.push(Number(n.iget(y)))}if(i.length!==u)throw new Error("p and a must have the same size");let m=i.reduce((p,y)=>p+y,0);Math.abs(m-1)>1e-10&&(i=i.map(p=>p/m))}if(t===void 0){if(i){let m=o(),p=0;for(let y=0;y<u;y++)if(p+=i[y],m<p)return a[y];return a[u-1]}return a[Math.floor(o()*u)]}let s=Array.isArray(t)?t:[t],c=s.reduce((m,p)=>m*p,1);if(!e&&c>u)throw new Error("cannot take a larger sample than population when replace=false");let l=S.zeros(s,"float64"),f=l.data;if(e)if(i){let m=new Array(u);m[0]=i[0];for(let p=1;p<u;p++)m[p]=m[p-1]+i[p];for(let p=0;p<c;p++){let y=o(),d=0;for(;d<u-1&&y>=m[d];)d++;f[p]=a[d]}}else for(let m=0;m<c;m++)f[m]=a[Math.floor(o()*u)];else{let m=[...a],p=i?[...i]:void 0;for(let y=0;y<c;y++){let d;if(p){let b=p.reduce((h,N)=>h+N,0),A=o()*b,g=0;d=0;for(let h=0;h<m.length;h++)if(g+=p[h],A<g){d=h;break}d===0&&A>=g&&(d=m.length-1)}else d=Math.floor(o()*m.length);f[y]=m[d],m.splice(d,1),p&&p.splice(d,1)}}return l}function z0(r,t,e=!0,n){return I0(r,t,e,n,G)}function _0(r,t=G){let e;if(typeof r=="number"){let o=new Float64Array(r);for(let a=0;a<r;a++)o[a]=a;e=S.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 v0(r){return _0(r,G)}function M0(r,t=G){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 F0(r){M0(r,G)}function B0(r){return Io(r)}function T0(r){return Io(r)}function O0(r){return Io(r)}function E0(r,t,e){return t===void 0&&(t=r,r=1),xl(r,t+1,e)}function U0(r){let t=new Uint8Array(r);for(let e=0;e<r;e++)t[e]=gl()&255;return t}var $0={name:"MT19937",state:Mr};function k0(){return $0}function R0(r){$0=r}function q0(r){return Cl(1,r)}function V0(r,t){if(r<=0)throw new Error("shape must be positive");return Bs(r,1,t)}function P0(r){if(r===void 0)return Math.tan(Math.PI*(G()-.5));let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=Math.tan(Math.PI*(G()-.5));return n}function j0(r,t){if(r<=0)throw new Error("df must be positive");let e=i=>{let s=Fr(i),c=pr(r/2,2,i);return s/Math.sqrt(c/r)};if(t===void 0)return e(G);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(G);return a}function pr(r,t,e){if(r<1){let a=e();return pr(1+r,t,e)*Math.pow(a,1/r)}let n=r-1/3,o=1/Math.sqrt(9*n);for(;;){let a,u;do a=Fr(e),u=1+o*a;while(u<=0);u=u*u*u;let i=e(),s=a*a;if(i<1-.0331*s*s||Math.log(i)<.5*s+n*(1-u+Math.log(u)))return n*u*t}}function Bs(r,t=1,e){if(r<=0)throw new Error("shape must be positive");if(t<=0)throw new Error("scale must be positive");if(e===void 0)return pr(r,t,G);let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=pr(r,t,G);return a}function L0(r,t,e){if(r<=0||t<=0)throw new Error("a and b must be positive");let n=s=>{let c=pr(r,1,s),l=pr(t,1,s);return c/(c+l)};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function G0(r=0,t=1,e){if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=s()-.5;return r-t*Math.sign(c)*Math.log(1-2*Math.abs(c))};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function W0(r=0,t=1,e){if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=s();return r+t*Math.log(c/(1-c))};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function Y0(r=0,t=1,e){if(t<=0)throw new Error("sigma must be positive");let n=s=>Math.exp(r+t*Fr(s));if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function Z0(r=0,t=1,e){if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=s();return r-t*Math.log(-Math.log(c))};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function J0(r,t){if(r<=0)throw new Error("a must be positive");let e=i=>{let s=i();return Math.pow(1-s,-1/r)-1};if(t===void 0)return e(G);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(G);return a}function X0(r,t){if(r<=0)throw new Error("a must be positive");let e=i=>{let s=i();return Math.pow(s,1/r)};if(t===void 0)return e(G);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(G);return a}function K0(r=1,t){if(r<=0)throw new Error("scale must be positive");let e=i=>{let s=i();return r*Math.sqrt(-2*Math.log(s))};if(t===void 0)return e(G);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(G);return a}function Q0(r,t,e,n){if(r>t||t>e||r===e)throw new Error("must have left <= mode <= right and left < right");let o=c=>{let l=c(),f=(t-r)/(e-r);return l<f?r+Math.sqrt(l*(e-r)*(t-r)):e-Math.sqrt((1-l)*(e-r)*(e-t))};if(n===void 0)return o(G);let a=Array.isArray(n)?n:[n],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"float64"),s=i.data;for(let c=0;c<u;c++)s[c]=o(G);return i}function H0(r,t,e){if(r<=0)throw new Error("mean must be positive");if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=Fr(s),l=c*c,f=r/(2*t),m=r+f*(r*l-Math.sqrt(4*r*t*l+r*r*l*l));return s()<=r/(r+m)?m:r*r/m};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function rN(r,t){if(r<=0)throw new Error("a must be positive");let e=i=>{let s=i();return Math.pow(-Math.log(1-s),1/r)};if(t===void 0)return e(G);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(G);return a}function tN(r,t){if(r<=0)throw new Error("df must be positive");return Bs(r/2,2,t)}function eN(r,t,e){if(r<=0)throw new Error("df must be positive");if(t<0)throw new Error("nonc must be non-negative");let n=s=>{if(t===0)return pr(r/2,2,s);let c=ct(t/2,s);return pr(r/2+c,2,s)};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function nN(r,t,e){if(r<=0)throw new Error("dfnum must be positive");if(t<=0)throw new Error("dfden must be positive");let n=s=>{let c=pr(r/2,2,s),l=pr(t/2,2,s);return c/r/(l/t)};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function oN(r,t,e,n){if(r<=0)throw new Error("dfnum must be positive");if(t<=0)throw new Error("dfden must be positive");if(e<0)throw new Error("nonc must be non-negative");let o=c=>{let l=pr(e===0?r/2:r/2+ct(e/2,c),2,c),f=pr(t/2,2,c);return l/r/(f/t)};if(n===void 0)return o(G);let a=Array.isArray(n)?n:[n],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"float64"),s=i.data;for(let c=0;c<u;c++)s[c]=o(G);return i}function aN(r,t){if(r<=0||r>1)throw new Error("p must be in (0, 1]");let e=i=>{if(r===1)return 1;let s=i();return Math.floor(Math.log(s)/Math.log(1-r))+1};if(t===void 0)return e(G);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"int64"),u=a.data;for(let i=0;i<o;i++)u[i]=BigInt(e(G));return a}function sN(r,t,e,n){if(r<0)throw new Error("ngood must be non-negative");if(t<0)throw new Error("nbad must be non-negative");if(e<0)throw new Error("nsample must be non-negative");if(e>r+t)throw new Error("nsample must be <= ngood + nbad");let o=c=>{let l=r,f=t,m=0,p=e;for(;p>0;){let y=l+f;if(y===0)break;c()<l/y?(m++,l--):f--,p--}return m};if(n===void 0)return o(G);let a=Array.isArray(n)?n:[n],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"int64"),s=i.data;for(let c=0;c<u;c++)s[c]=BigInt(o(G));return i}function iN(r,t){if(r<=0||r>=1)throw new Error("p must be in (0, 1)");let e=Math.log(1-r),n=s=>{let c=s(),l=s(),f=1-Math.exp(e*c);if(l>=f||l===0)return 1;let m=Math.log(l),p=Math.log(f);return m>=p?1:m>=2*p?2:Math.floor(1+m/p)};if(t===void 0)return n(G);let o=Array.isArray(t)?t:[t],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"int64"),i=u.data;for(let s=0;s<a;s++)i[s]=BigInt(n(G));return u}function uN(r,t,e){if(r<=0)throw new Error("n must be positive");if(t<=0||t>1)throw new Error("p must be in (0, 1]");let n=s=>{if(t===1)return 0;let c=pr(r,(1-t)/t,s);return ct(c,s)};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"int64"),i=u.data;for(let s=0;s<a;s++)i[s]=BigInt(n(G));return u}function cN(r,t){if(r<=1)throw new Error("a must be > 1");let e=r-1,n=Math.pow(2,e),o=c=>{for(;;){let l=1-c(),f=c(),m=Math.floor(Math.pow(l,-1/e)),p=Math.pow(1+1/m,e);if(f*m*(p-1)/(n-1)<=p/n)return m}};if(t===void 0)return o(G);let a=Array.isArray(t)?t:[t],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"int64"),s=i.data;for(let c=0;c<u;c++)s[c]=BigInt(o(G));return i}function lN(r,t,e){let n=Array.isArray(t)?t:Array.from({length:t.size},(p,y)=>Number(t.iget(y))),o=n.length;if(o===0)throw new Error("pvals must have at least one element");let a=n.reduce((p,y)=>p+y,0),u=n.map(p=>p/a),i=p=>{let y=new Array(o).fill(0),d=r,b=1;for(let A=0;A<o-1&&d>0;A++){let g=u[A]/b,h=wo(d,Math.min(1,Math.max(0,g)),p);y[A]=h,d-=h,b-=u[A]}return y[o-1]=d,y};if(e===void 0){let p=i(G),y=S.zeros([o],"int64"),d=y.data;for(let b=0;b<o;b++)d[b]=BigInt(p[b]);return y}let s=Array.isArray(e)?e:[e],c=s.reduce((p,y)=>p*y,1),l=[...s,o],f=S.zeros(l,"int64"),m=f.data;for(let p=0;p<c;p++){let y=i(G);for(let d=0;d<o;d++)m[p*o+d]=BigInt(y[d])}return f}function fN(r,t,e,n="warn",o=1e-8){let a=Array.isArray(r)?r:Array.from({length:r.size},(d,b)=>Number(r.iget(b))),u=a.length,i;if(Array.isArray(t))i=t;else{i=[];for(let d=0;d<u;d++){i.push([]);for(let b=0;b<u;b++)i[d].push(Number(t.iget(d*u+b)))}}let s=Array(u).fill(0).map(()=>Array(u).fill(0));for(let d=0;d<u;d++)for(let b=0;b<=d;b++){let A=i[d][b];for(let g=0;g<b;g++)A-=s[d][g]*s[b][g];if(d===b){if(A<-o){if(n==="raise")throw new Error("covariance matrix is not positive semi-definite");n==="warn"&&console.warn("covariance matrix is not positive semi-definite"),A=0}s[d][b]=Math.sqrt(Math.max(0,A))}else s[d][b]=s[b][b]!==0?A/s[b][b]:0}let c=d=>{let b=[];for(let g=0;g<u;g++)b.push(Fr(d));let A=[];for(let g=0;g<u;g++){let h=a[g];for(let N=0;N<=g;N++)h+=s[g][N]*b[N];A.push(h)}return A};if(e===void 0){let d=c(G),b=S.zeros([u],"float64"),A=b.data;for(let g=0;g<u;g++)A[g]=d[g];return b}let l=Array.isArray(e)?e:[e],f=l.reduce((d,b)=>d*b,1),m=[...l,u],p=S.zeros(m,"float64"),y=p.data;for(let d=0;d<f;d++){let b=c(G);for(let A=0;A<u;A++)y[d*u+A]=b[A]}return p}function mN(r,t){let e=Array.isArray(r)?r:Array.from({length:r.size},(l,f)=>Number(r.iget(f))),n=e.length;if(n<2)throw new Error("alpha must have at least 2 elements");for(let l of e)if(l<=0)throw new Error("all alpha values must be positive");let o=l=>{let f=[],m=0;for(let p=0;p<n;p++){let y=pr(e[p],1,l);f.push(y),m+=y}return f.map(p=>p/m)};if(t===void 0){let l=o(G),f=S.zeros([n],"float64"),m=f.data;for(let p=0;p<n;p++)m[p]=l[p];return f}let a=Array.isArray(t)?t:[t],u=a.reduce((l,f)=>l*f,1),i=[...a,n],s=S.zeros(i,"float64"),c=s.data;for(let l=0;l<u;l++){let f=o(G);for(let m=0;m<n;m++)c[l*n+m]=f[m]}return s}function pN(r,t,e){if(t<0)throw new Error("kappa must be non-negative");let n=s=>{if(t===0)return 2*Math.PI*s()-Math.PI;let c=1+Math.sqrt(1+4*t*t),l=(c-Math.sqrt(2*c))/(2*t),f=(1+l*l)/(2*l);for(;;){let m=s(),p=Math.cos(Math.PI*m),y=(1+f*p)/(f+p),d=t*(f-y),b=s();if(d*(2-d)>b||Math.log(d/b)+1-d>=0)return((s()>.5?Math.acos(y):-Math.acos(y))+r+Math.PI)%(2*Math.PI)-Math.PI}};if(e===void 0)return n(G);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(G);return u}function y1(r,t,e){let n=r.length;n!==0&&n!==1&&((n&n-1)===0?Ts(r,t,e):b1(r,t,e))}var zo=new Map;function d1(r,t){let e=`${r}_${t}`,n=zo.get(e);if(n)return n;let o=new Float64Array(r/2),a=new Float64Array(r/2),u=t?1:-1;for(let i=0;i<r/2;i++){let s=u*2*Math.PI*i/r;o[i]=Math.cos(s),a[i]=Math.sin(s)}if(n={cos:o,sin:a},zo.set(e,n),zo.size>100){let i=zo.keys().next().value;zo.delete(i)}return n}function Ts(r,t,e){let n=r.length,o=0;for(let i=0;i<n-1;i++){if(i<o){let c=r[i];r[i]=r[o],r[o]=c,c=t[i],t[i]=t[o],t[o]=c}let s=n>>1;for(;s<=o;)o-=s,s>>=1;o+=s}let{cos:a,sin:u}=d1(n,e);for(let i=2;i<=n;i*=2){let s=i>>1,c=n/i;for(let l=0;l<n;l+=i)for(let f=0,m=0;f<s;f++,m+=c){let p=a[m],y=u[m],d=l+f,b=l+f+s,A=r[d],g=t[d],h=r[b],N=t[b],D=p*h-y*N,x=p*N+y*h;r[d]=A+D,t[d]=g+x,r[b]=A-D,t[b]=g-x}}if(e){let i=1/n;for(let s=0;s<n;s++)r[s]=r[s]*i,t[s]=t[s]*i}}function b1(r,t,e){let n=r.length,o=1;for(;o<2*n-1;)o*=2;let a=e?1:-1,u=new Float64Array(n),i=new Float64Array(n);for(let m=0;m<n;m++){let p=a*Math.PI*m*m/n;u[m]=Math.cos(p),i[m]=Math.sin(p)}let s=new Float64Array(o),c=new Float64Array(o);for(let m=0;m<n;m++){let p=u[m],y=i[m];s[m]=r[m]*p-t[m]*y,c[m]=t[m]*p+r[m]*y}let l=new Float64Array(o),f=new Float64Array(o);l[0]=u[0],f[0]=-i[0];for(let m=1;m<n;m++)l[m]=u[m],f[m]=-i[m],l[o-m]=u[m],f[o-m]=-i[m];Ts(s,c,!1),Ts(l,f,!1);for(let m=0;m<o;m++){let p=s[m],y=c[m],d=l[m],b=f[m];s[m]=p*d-y*b,c[m]=p*b+y*d}Ts(s,c,!0);for(let m=0;m<n;m++){let p=s[m],y=c[m],d=u[m],b=i[m];r[m]=p*d-y*b,t[m]=y*d+p*b}if(e)for(let m=0;m<n;m++)r[m]=r[m]/n,t[m]=t[m]/n}function Et(r,t,e=-1,n="backward"){return Ut(r,t!==void 0?[t]:void 0,[e],n,!1)}function _o(r,t,e=-1,n="backward"){return Ut(r,t!==void 0?[t]:void 0,[e],n,!0)}function yN(r,t,e=[-2,-1],n="backward"){return Ut(r,t,e,n,!1)}function dN(r,t,e=[-2,-1],n="backward"){return Ut(r,t,e,n,!0)}function bN(r,t,e,n="backward"){return Ut(r,t,e,n,!1)}function AN(r,t,e,n="backward"){return Ut(r,t,e,n,!0)}function Ut(r,t,e,n="backward",o=!1){let a=Array.from(r.shape),u=a.length;if(r.size===0)return S.zeros(a,"complex128");if(u===0){let l=S.zeros([1],"complex128"),f=r.iget(0),m=f instanceof U?f.re:Number(f),p=f instanceof U?f.im:0,y=l.data;return y[0]=m,y[1]=p,S.fromData(l.data,[],"complex128")}let i;if(e===void 0)if(t===void 0)i=Array.from({length:u},(l,f)=>f);else{i=[];for(let l=0;l<t.length;l++)i.push(u-t.length+l)}else i=e.map(l=>l<0?u+l:l);let s=[...a];if(t!==void 0)for(let l=0;l<t.length;l++){let f=i[l];s[f]=t[l]}let c=vo(r);t!==void 0&&(c=A1(c,s,i));for(let l of i)c=h1(c,l,o,n);return c}function vo(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(t==="complex128"||t==="complex64"){let i=S.zeros(e,"complex128"),s=i.data,c=r.data;for(let l=0;l<n*2;l++)s[l]=c[l];return i}let o=S.zeros(e,"complex128"),a=o.data,u=r.data;if(t==="float64"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="float32"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int32"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int16"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int8"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="uint32"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="uint16"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="uint8"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int64"||t==="uint64"){let i=u;for(let s=0;s<n;s++)a[s*2]=Number(i[s])}else for(let i=0;i<n;i++)a[i*2]=Number(u[i]);return o}function A1(r,t,e){let n=Array.from(r.shape),o=r;for(let a of e){let u=n[a],i=t[a];u!==i&&(i>u?o=g1(o,a,i):o=Sl(o,a,i),n[a]=i)}return o}function g1(r,t,e){let n=Array.from(r.shape),o=n[t];n[t]=e;let a=S.zeros(n,"complex128"),u=a.data,i=r.data,s=n.slice(0,t).reduce((l,f)=>l*f,1),c=n.slice(t+1).reduce((l,f)=>l*f,1);for(let l=0;l<s;l++)for(let f=0;f<o;f++)for(let m=0;m<c;m++){let p=(l*o+f)*c+m,y=(l*e+f)*c+m;u[y*2]=i[p*2],u[y*2+1]=i[p*2+1]}return a}function Sl(r,t,e){let n=Array.from(r.shape),o=n[t];n[t]=e;let a=S.zeros(n,"complex128"),u=a.data,i=r.data,s=n.slice(0,t).reduce((l,f)=>l*f,1),c=n.slice(t+1).reduce((l,f)=>l*f,1);for(let l=0;l<s;l++)for(let f=0;f<e;f++)for(let m=0;m<c;m++){let p=(l*o+f)*c+m,y=(l*e+f)*c+m;u[y*2]=i[p*2],u[y*2+1]=i[p*2+1]}return a}function h1(r,t,e,n){let o=Array.from(r.shape),a=o[t];if(a===0)return r;let u=S.zeros(o,"complex128"),i=u.data,s=r.data,c=o.slice(0,t).reduce((p,y)=>p*y,1),l=o.slice(t+1).reduce((p,y)=>p*y,1),f=new Float64Array(a),m=new Float64Array(a);for(let p=0;p<c;p++)for(let y=0;y<l;y++){for(let d=0;d<a;d++){let b=(p*a+d)*l+y;f[d]=s[b*2],m[d]=s[b*2+1]}if(y1(f,m,e),n==="ortho"){let d=1/Math.sqrt(a);if(e){let b=Math.sqrt(a);for(let A=0;A<a;A++)f[A]=f[A]*b,m[A]=m[A]*b}else for(let b=0;b<a;b++)f[b]=f[b]*d,m[b]=m[b]*d}else if(n==="forward"&&!e){let d=1/a;for(let b=0;b<a;b++)f[b]=f[b]*d,m[b]=m[b]*d}else if(!(n==="backward"&&e)){if(n==="forward"&&e)for(let d=0;d<a;d++)f[d]=f[d]*a,m[d]=m[d]*a}for(let d=0;d<a;d++){let b=(p*a+d)*l+y;i[b*2]=f[d],i[b*2+1]=m[d]}}return u}function Es(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=t??o[u],s=Et(r,i,e,n),c=Math.floor(i/2)+1;return Sl(s,u,c)}function Mo(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=o[u],s=t??(i-1)*2,c=[...o];c[u]=s;let l=S.zeros(c,"complex128"),f=l.data,m=vo(r).data,p=o.slice(0,u).reduce((b,A)=>b*A,1),y=o.slice(u+1).reduce((b,A)=>b*A,1);for(let b=0;b<p;b++)for(let A=0;A<y;A++){for(let g=0;g<i;g++){let h=(b*i+g)*y+A,N=(b*s+g)*y+A;f[N*2]=m[h*2],f[N*2+1]=m[h*2+1]}for(let g=i;g<s;g++){let h=s-g,N=(b*i+h)*y+A,D=(b*s+g)*y+A;f[D*2]=m[N*2],f[D*2+1]=-m[N*2+1]}}let d=_o(l,s,e,n);return Os(d)}function gN(r,t,e=[-2,-1],n="backward"){let a=Array.from(r.shape).length,u=e[0]<0?a+e[0]:e[0],i=e[1]<0?a+e[1]:e[1],s=Et(r,t?t[0]:void 0,u,n),c=Array.from(s.shape),l=t?t[1]:c[i];s=Et(s,l,i,n);let f=Math.floor(l/2)+1;return Sl(s,i,f)}function hN(r,t,e=[-2,-1],n="backward"){let o=Array.from(r.shape),a=o.length,u=e[0]<0?a+e[0]:e[0],i=e[1]<0?a+e[1]:e[1],s=o[i],c=t?t[1]:(s-1)*2,l=t?t[0]:o[u],f=Mo(r,c,i,n);return f=_o(f,l,u,n),Os(f)}function NN(r,t,e,n="backward"){let a=Array.from(r.shape).length,u;if(e===void 0?u=Array.from({length:a},(l,f)=>f):u=e.map(l=>l<0?a+l:l),u.length===0)return vo(r);let i=r;for(let l=0;l<u.length-1;l++){let f=u[l],m=t?t[l]:void 0;i=Et(i,m,f,n)}let s=u[u.length-1],c=t?t[u.length-1]:void 0;return Es(i,c,s,n)}function DN(r,t,e,n="backward"){let o=Array.from(r.shape),a=o.length,u;if(e===void 0?u=Array.from({length:a},(f,m)=>m):u=e.map(f=>f<0?a+f:f),u.length===0)return Os(vo(r));let i=u[u.length-1],s=o[i],c=t?[...t]:u.map((f,m)=>m===u.length-1?(s-1)*2:o[f]),l=Mo(r,c[u.length-1],i,n);for(let f=u.length-2;f>=0;f--){let m=u[f];l=_o(l,c[f],m,n)}return Os(l)}function xN(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=o[u],s=t??(i-1)*2,c=SN(vo(r)),l=Mo(c,s,e,n),f=l.data;for(let m=0;m<l.size;m++)f[m]=f[m]*s;return l}function CN(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=t??o[u],s=Es(r,i,e,n),c=SN(s),l=c.data;for(let f=0;f<c.size*2;f++)l[f]=l[f]/i;return c}function SN(r){let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"complex128"),o=n.data,a=r.data;for(let u=0;u<e;u++)o[u*2]=a[u*2],o[u*2+1]=-a[u*2+1];return n}function Os(r){let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"float64"),o=n.data,a=r.data;for(let u=0;u<e;u++)o[u]=a[u*2];return n}function wN(r,t=1){let e=S.zeros([r],"float64"),n=e.data,o=Math.floor((r-1)/2)+1;for(let a=0;a<o;a++)n[a]=a/(r*t);for(let a=o;a<r;a++)n[a]=(a-r)/(r*t);return e}function IN(r,t=1){let e=Math.floor(r/2)+1,n=S.zeros([e],"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=a/(r*t);return n}function zN(r,t){let e=Array.from(r.shape),n=e.length,o;t===void 0?o=Array.from({length:n},(u,i)=>i):typeof t=="number"?o=[t<0?n+t:t]:o=t.map(u=>u<0?n+u:u);let a=e.map((u,i)=>o.includes(i)?Math.floor(e[i]/2):0);return vN(r,a)}function _N(r,t){let e=Array.from(r.shape),n=e.length,o;t===void 0?o=Array.from({length:n},(u,i)=>i):typeof t=="number"?o=[t<0?n+t:t]:o=t.map(u=>u<0?n+u:u);let a=e.map((u,i)=>o.includes(i)?-Math.floor(e[i]/2):0);return vN(r,a)}function vN(r,t){let e=Array.from(r.shape),n=r.dtype,o=r.size,a=S.zeros(e,n),u=n==="complex128"||n==="complex64",i=new Array(e.length);i[e.length-1]=1;for(let s=e.length-2;s>=0;s--)i[s]=i[s+1]*e[s+1];for(let s=0;s<o;s++){let c=new Array(e.length),l=s;for(let p=0;p<e.length;p++)c[p]=Math.floor(l/i[p]),l=l%i[p];let f=c.map((p,y)=>{let d=p+t[y],b=e[y];return d=(d%b+b)%b,d}),m=0;for(let p=0;p<e.length;p++)m+=f[p]*i[p];if(u){let p=r.data,y=a.data;y[m*2]=p[s*2],y[m*2+1]=p[s*2+1]}else{let p=r.iget(s);a.iset(m,p)}}return a}function lt(r){return tr.fromStorage(r.storage)}function D1(r){return lt(it(r))}var x1=Wc;function C1(r,t){return lt(Yc(r,t))}async function S1(r,t={}){let e=await ho(r,t),n=new Map;for(let[o,a]of e.arrays)n.set(o,lt(a));return{arrays:n,skipped:e.skipped,errors:e.errors}}function w1(r,t={}){let e=No(r,t),n=new Map;for(let[o,a]of e.arrays)n.set(o,lt(a));return{arrays:n,skipped:e.skipped,errors:e.errors}}async function I1(r,t={}){let e=await Cd(r,t),n={};for(let[o,a]of Object.entries(e))n[o]=lt(a);return n}function z1(r,t={}){let e=Sd(r,t),n={};for(let[o,a]of Object.entries(e))n[o]=lt(a);return n}function _1(r,t={}){return lt(ut(r,t))}function H(r){return r&&typeof r=="object"&&"_data"in r&&"_shape"in r?tr.fromStorage(r):r}var v1={seed:b0,get_state:A0,set_state:g0,get_bit_generator:k0,set_bit_generator:R0,default_rng:d0,Generator:Co,random:r=>H(Io(r)),rand:(...r)=>H(h0(...r)),randn:(...r)=>H(N0(...r)),randint:(r,t,e,n)=>H(xl(r,t,e,n)),random_sample:r=>H(B0(r)),ranf:r=>H(T0(r)),sample:r=>H(O0(r)),random_integers:(r,t,e)=>H(E0(r,t,e)),bytes:U0,uniform:(r,t,e)=>H(D0(r,t,e)),normal:(r,t,e)=>H(x0(r,t,e)),standard_normal:r=>H(C0(r)),exponential:(r,t)=>H(Cl(r,t)),standard_exponential:r=>H(q0(r)),gamma:(r,t,e)=>H(Bs(r,t,e)),standard_gamma:(r,t)=>H(V0(r,t)),beta:(r,t,e)=>H(L0(r,t,e)),chisquare:(r,t)=>H(tN(r,t)),noncentral_chisquare:(r,t,e)=>H(eN(r,t,e)),f:(r,t,e)=>H(nN(r,t,e)),noncentral_f:(r,t,e,n)=>H(oN(r,t,e,n)),standard_cauchy:r=>H(P0(r)),standard_t:(r,t)=>H(j0(r,t)),laplace:(r,t,e)=>H(G0(r,t,e)),logistic:(r,t,e)=>H(W0(r,t,e)),lognormal:(r,t,e)=>H(Y0(r,t,e)),gumbel:(r,t,e)=>H(Z0(r,t,e)),pareto:(r,t)=>H(J0(r,t)),power:(r,t)=>H(X0(r,t)),rayleigh:(r,t)=>H(K0(r,t)),triangular:(r,t,e,n)=>H(Q0(r,t,e,n)),wald:(r,t,e)=>H(H0(r,t,e)),weibull:(r,t)=>H(rN(r,t)),poisson:(r,t)=>H(S0(r,t)),binomial:(r,t,e)=>H(w0(r,t,e)),geometric:(r,t)=>H(aN(r,t)),hypergeometric:(r,t,e,n)=>H(sN(r,t,e,n)),logseries:(r,t)=>H(iN(r,t)),negative_binomial:(r,t,e)=>H(uN(r,t,e)),zipf:(r,t)=>H(cN(r,t)),multinomial:(r,t,e)=>H(lN(r,t,e)),multivariate_normal:(r,t,e,n,o)=>H(fN(r,t,e,n,o)),dirichlet:(r,t)=>H(mN(r,t)),vonmises:(r,t,e)=>H(pN(r,t,e)),choice:(r,t,e,n)=>H(z0(r,t,e,n)),permutation:r=>H(v0(r)),shuffle:F0};function fr(r){return r instanceof tr||r instanceof P?r.storage:r}var M1={fft:(r,t,e,n)=>tr.fromStorage(Et(fr(r),t,e,n)),ifft:(r,t,e,n)=>tr.fromStorage(_o(fr(r),t,e,n)),fft2:(r,t,e,n)=>tr.fromStorage(yN(fr(r),t,e,n)),ifft2:(r,t,e,n)=>tr.fromStorage(dN(fr(r),t,e,n)),fftn:(r,t,e,n)=>tr.fromStorage(bN(fr(r),t,e,n)),ifftn:(r,t,e,n)=>tr.fromStorage(AN(fr(r),t,e,n)),rfft:(r,t,e,n)=>tr.fromStorage(Es(fr(r),t,e,n)),irfft:(r,t,e,n)=>tr.fromStorage(Mo(fr(r),t,e,n)),rfft2:(r,t,e,n)=>tr.fromStorage(gN(fr(r),t,e,n)),irfft2:(r,t,e,n)=>tr.fromStorage(hN(fr(r),t,e,n)),rfftn:(r,t,e,n)=>tr.fromStorage(NN(fr(r),t,e,n)),irfftn:(r,t,e,n)=>tr.fromStorage(DN(fr(r),t,e,n)),hfft:(r,t,e,n)=>tr.fromStorage(xN(fr(r),t,e,n)),ihfft:(r,t,e,n)=>tr.fromStorage(CN(fr(r),t,e,n)),fftfreq:(r,t)=>tr.fromStorage(wN(r,t)),rfftfreq:(r,t)=>tr.fromStorage(IN(r,t)),fftshift:(r,t)=>tr.fromStorage(zN(fr(r),t)),ifftshift:(r,t)=>tr.fromStorage(_N(fr(r),t))},F1="0.13.0";function Lr(r){return tr.fromStorage(r.storage)}async function MN(r){let t=await(0,jr.readFile)(r);return Lr(it(t))}function FN(r){let t=(0,Pr.readFileSync)(r);return Lr(it(t))}async function BN(r,t){let e=Kr(t);await(0,jr.writeFile)(r,e)}function TN(r,t){let e=Kr(t);(0,Pr.writeFileSync)(r,e)}async function ON(r,t={}){let e=await(0,jr.readFile)(r),n=await ho(e,t),o=new Map;for(let[a,u]of n.arrays)o.set(a,Lr(u));return{arrays:o,skipped:n.skipped,errors:n.errors}}function EN(r,t={}){let e=(0,Pr.readFileSync)(r),n=No(e,t),o=new Map;for(let[a,u]of n.arrays)o.set(a,Lr(u));return{arrays:o,skipped:n.skipped,errors:n.errors}}async function wl(r,t,e={}){let n=await _s(t,e);await(0,jr.writeFile)(r,n)}function B1(r,t){let e=vs(t);(0,Pr.writeFileSync)(r,e)}async function T1(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return MN(r)}else{if(r.endsWith(".npz"))return ON(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function O1(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return FN(r)}else{if(r.endsWith(".npz"))return EN(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function E1(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return BN(r,t)}function U1(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return TN(r,t)}async function $1(r,t){return r.endsWith(".npz")||(r=r+".npz"),wl(r,t,{compress:!1})}async function k1(r,t){return r.endsWith(".npz")||(r=r+".npz"),wl(r,t,{compress:!0})}async function R1(r,t={}){let e=await(0,jr.readFile)(r,{encoding:t.encoding??"utf-8"});return Lr(ut(e,t))}function q1(r,t={}){let e=(0,Pr.readFileSync)(r,{encoding:t.encoding??"utf-8"});return Lr(ut(e,t))}async function V1(r,t,e={}){let n=Ot(t,e);await(0,jr.writeFile)(r,n,"utf-8")}function P1(r,t,e={}){let n=Ot(t,e);(0,Pr.writeFileSync)(r,n,"utf-8")}async function j1(r,t={}){let e=await(0,jr.readFile)(r,{encoding:t.encoding??"utf-8"});return Lr(Do(e,t))}function L1(r,t={}){let e=(0,Pr.readFileSync)(r,{encoding:t.encoding??"utf-8"});return Lr(Do(e,t))}async function G1(r,t,e="float64"){let n=await(0,jr.readFile)(r,{encoding:"utf-8"});return Lr(xo(n,t,e))}function W1(r,t,e="float64"){let n=(0,Pr.readFileSync)(r,{encoding:"utf-8"});return Lr(xo(n,t,e))}0&&(module.exports={Complex,DTYPE_TO_DESCR,InvalidNpyError,NDArray,NDArrayCore,SUPPORTED_DTYPES,UnsupportedDTypeError,__version__,abs,absolute,acos,acosh,add,all,allclose,amax,amin,angle,any,append,apply_along_axis,apply_over_axes,arange,arccos,arccosh,arcsin,arcsinh,arctan,arctan2,arctanh,argmax,argmin,argpartition,argsort,argwhere,around,array,array2string,array_equal,array_equiv,array_repr,array_split,array_str,asanyarray,asarray,asarray_chkfinite,ascontiguousarray,asfortranarray,asin,asinh,atan,atan2,atanh,atleast_1d,atleast_2d,atleast_3d,average,base_repr,binary_repr,bincount,bindex,bitwise_and,bitwise_count,bitwise_invert,bitwise_left_shift,bitwise_not,bitwise_or,bitwise_right_shift,bitwise_xor,block,broadcast_arrays,broadcast_shapes,broadcast_to,byteswap,can_cast,cbrt,ceil,choose,clip,column_stack,common_type,compress,concat,concatenate,conj,conjugate,convolve,copy,copysign,copyto,corrcoef,correlate,cos,cosh,count_nonzero,cov,cross,cumprod,cumsum,cumulative_prod,cumulative_sum,deg2rad,degrees,delete:null,delete_,diag,diag_indices,diag_indices_from,diagflat,diagonal,diff,digitize,divide,divmod,dot,dsplit,dstack,ediff1d,einsum,einsum_path,empty,empty_like,equal,exp,exp2,expand_dims,expm1,extract,eye,fabs,fft,fill,fill_diagonal,fix,flatnonzero,flatten,flip,fliplr,flipud,float_power,floor,floor_divide,fmax,fmin,fmod,format_float_positional,format_float_scientific,frexp,frombuffer,fromfile,fromfunction,fromiter,fromregex,fromregexSync,fromstring,full,full_like,gcd,genfromtxt,genfromtxtSync,geomspace,get_printoptions,geterr,gradient,greater,greater_equal,heaviside,histogram,histogram2d,histogram_bin_edges,histogramdd,hsplit,hstack,hypot,i0,identity,iindex,imag,in1d,indices,inner,insert,interp,intersect1d,invert,isclose,iscomplex,iscomplexobj,isdtype,isfinite,isfortran,isin,isinf,isnan,isnat,isneginf,isposinf,isreal,isrealobj,isscalar,issubdtype,item,iterable,ix_,kron,lcm,ldexp,left_shift,less,less_equal,lexsort,linalg,linspace,load,loadNpy,loadNpySync,loadNpz,loadNpzFile,loadNpzFileSync,loadNpzSync,loadSync,loadtxt,loadtxtSync,log,log10,log1p,log2,logaddexp,logaddexp2,logical_and,logical_not,logical_or,logical_xor,logspace,mask_indices,matmul,matrix_transpose,matvec,max,maximum,may_share_memory,mean,median,meshgrid,min,min_scalar_type,minimum,mintypecode,mod,modf,moveaxis,multiply,nan_to_num,nanargmax,nanargmin,nancumprod,nancumsum,nanmax,nanmean,nanmedian,nanmin,nanpercentile,nanprod,nanquantile,nanstd,nansum,nanvar,ndim,negative,nextafter,nonzero,not_equal,ones,ones_like,outer,packbits,pad,parseNpy,parseNpyData,parseNpyHeader,parseNpz,parseNpzSync,parseTxt,partition,percentile,permute_dims,place,poly,polyadd,polyder,polydiv,polyfit,polyint,polymul,polysub,polyval,positive,pow,power,printoptions,prod,promote_types,ptp,put,put_along_axis,putmask,quantile,rad2deg,radians,random,ravel,ravel_multi_index,real,real_if_close,reciprocal,remainder,repeat,require,reshape,resize,result_type,right_shift,rint,roll,rollaxis,roots,rot90,round,round_,row_stack,save,saveNpy,saveNpySync,saveNpz,saveNpzSync,saveSync,savetxt,savetxtSync,savez,savez_compressed,searchsorted,select,serializeNpy,serializeNpz,serializeNpzSync,serializeTxt,set_printoptions,setdiff1d,seterr,setxor1d,shape,shares_memory,sign,signbit,sin,sinc,sinh,size,sort,sort_complex,spacing,split,sqrt,square,squeeze,stack,std,subtract,sum,swapaxes,take,take_along_axis,tan,tanh,tensordot,tile,tobytes,tofile,tolist,trace,transpose,trapezoid,tri,tril,tril_indices,tril_indices_from,trim_zeros,triu,triu_indices,triu_indices_from,true_divide,trunc,typename,union1d,unique,unique_all,unique_counts,unique_inverse,unique_values,unpackbits,unravel_index,unstack,unwrap,vander,var:null,variance,vdot,vecdot,vecmat,view,vsplit,vstack,where,zeros,zeros_like});
|
|
1
|
+
"use strict";var qs=Object.defineProperty;var VN=Object.getOwnPropertyDescriptor;var PN=Object.getOwnPropertyNames;var jN=Object.prototype.hasOwnProperty;var LN=(r,t)=>{for(var e in t)qs(r,e,{get:t[e],enumerable:!0})},WN=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of PN(t))!jN.call(r,o)&&o!==e&&qs(r,o,{get:()=>t[o],enumerable:!(n=VN(t,o))||n.enumerable});return r};var GN=r=>WN(qs({},"__esModule",{value:!0}),r);var H1={};LN(H1,{Complex:()=>U,DTYPE_TO_DESCR:()=>Ms,InvalidNpyError:()=>hr,NDArray:()=>tr,NDArrayCore:()=>P,SUPPORTED_DTYPES:()=>Zc,UnsupportedDTypeError:()=>Gr,__version__:()=>$1,abs:()=>tl,absolute:()=>tl,acos:()=>ml,acosh:()=>bl,add:()=>eb,all:()=>Pg,allclose:()=>Mt,amax:()=>Qe,amin:()=>rn,angle:()=>rA,any:()=>jg,append:()=>Ah,apply_along_axis:()=>rb,apply_over_axes:()=>tb,arange:()=>sA,arccos:()=>ml,arccosh:()=>bl,arcsin:()=>fl,arcsinh:()=>dl,arctan:()=>pl,arctan2:()=>yl,arctanh:()=>Al,argmax:()=>Eg,argmin:()=>Og,argpartition:()=>Yh,argsort:()=>Lh,argwhere:()=>Jh,around:()=>ul,array:()=>aA,array2string:()=>ms,array_equal:()=>Ha,array_equiv:()=>rs,array_repr:()=>ps,array_split:()=>ua,array_str:()=>Et,asanyarray:()=>gA,asarray:()=>mA,asarray_chkfinite:()=>DA,ascontiguousarray:()=>hA,asfortranarray:()=>NA,asin:()=>fl,asinh:()=>dl,atan:()=>pl,atan2:()=>yl,atanh:()=>Al,atleast_1d:()=>ma,atleast_2d:()=>pa,atleast_3d:()=>ya,average:()=>Vg,base_repr:()=>ls,binary_repr:()=>fs,bincount:()=>Hh,bindex:()=>Pd,bitwise_and:()=>Wb,bitwise_count:()=>Kb,bitwise_invert:()=>el,bitwise_left_shift:()=>nl,bitwise_not:()=>el,bitwise_or:()=>Gb,bitwise_right_shift:()=>ol,bitwise_xor:()=>Yb,block:()=>Th,broadcast_arrays:()=>Wa,broadcast_shapes:()=>Ga,broadcast_to:()=>Ud,byteswap:()=>hs,can_cast:()=>No,cbrt:()=>xb,ceil:()=>oh,choose:()=>Rd,clip:()=>Eb,column_stack:()=>Bh,common_type:()=>Ss,compress:()=>qd,concat:()=>ll,concatenate:()=>ll,conj:()=>al,conjugate:()=>al,convolve:()=>e0,copy:()=>AA,copysign:()=>cg,copyto:()=>Ja,corrcoef:()=>o0,correlate:()=>t0,cos:()=>i0,cosh:()=>d0,count_nonzero:()=>Ba,cov:()=>n0,cross:()=>ZA,cumprod:()=>il,cumsum:()=>sl,cumulative_prod:()=>il,cumulative_sum:()=>sl,deg2rad:()=>m0,degrees:()=>l0,delete:()=>cl,delete_:()=>cl,diag:()=>CA,diag_indices:()=>Yd,diag_indices_from:()=>Zd,diagflat:()=>SA,diagonal:()=>$A,diff:()=>OA,digitize:()=>r0,divide:()=>gb,divmod:()=>Sb,dot:()=>UA,dsplit:()=>fa,dstack:()=>Fh,ediff1d:()=>EA,einsum:()=>Ko,einsum_path:()=>Qo,empty:()=>nA,empty_like:()=>dA,equal:()=>Ag,exp:()=>sb,exp2:()=>ib,expand_dims:()=>Sh,expm1:()=>ub,extract:()=>Qh,eye:()=>lA,fabs:()=>Cb,fft:()=>U1,fill:()=>xs,fill_diagonal:()=>Qa,fix:()=>ah,flatnonzero:()=>Kh,flatten:()=>Dh,flip:()=>$h,fliplr:()=>kh,flipud:()=>Rh,float_power:()=>_b,floor:()=>sh,floor_divide:()=>hb,fmax:()=>kb,fmin:()=>Rb,fmod:()=>vb,format_float_positional:()=>us,format_float_scientific:()=>cs,frexp:()=>Mb,frombuffer:()=>vA,fromfile:()=>TA,fromfunction:()=>MA,fromiter:()=>FA,fromregex:()=>K1,fromregexSync:()=>Q1,fromstring:()=>BA,full:()=>oA,full_like:()=>bA,gcd:()=>Fb,genfromtxt:()=>X1,genfromtxtSync:()=>J1,geomspace:()=>cA,get_printoptions:()=>ss,geterr:()=>ns,gradient:()=>La,greater:()=>pg,greater_equal:()=>yg,heaviside:()=>zb,histogram:()=>qa,histogram2d:()=>Va,histogram_bin_edges:()=>ja,histogramdd:()=>Pa,hsplit:()=>la,hstack:()=>Mh,hypot:()=>c0,i0:()=>Lb,identity:()=>fA,iindex:()=>Vd,imag:()=>Hb,in1d:()=>ch,indices:()=>Ld,inner:()=>qA,insert:()=>gh,interp:()=>Vb,intersect1d:()=>lh,invert:()=>Zb,isclose:()=>hg,iscomplex:()=>sg,iscomplexobj:()=>Sa,isdtype:()=>va,isfinite:()=>rg,isfortran:()=>Ia,isin:()=>fh,isinf:()=>tg,isnan:()=>eg,isnat:()=>ng,isneginf:()=>og,isposinf:()=>ag,isreal:()=>ig,isrealobj:()=>wa,isscalar:()=>za,issubdtype:()=>zs,item:()=>bs,iterable:()=>_a,ix_:()=>Ka,kron:()=>kA,lcm:()=>Bb,ldexp:()=>Tb,left_shift:()=>nl,less:()=>dg,less_equal:()=>bg,lexsort:()=>Wh,linalg:()=>oa,linspace:()=>iA,load:()=>R1,loadNpy:()=>ON,loadNpySync:()=>EN,loadNpz:()=>B1,loadNpzFile:()=>kN,loadNpzFileSync:()=>RN,loadNpzSync:()=>T1,loadSync:()=>q1,loadtxt:()=>W1,loadtxtSync:()=>G1,log:()=>cb,log10:()=>fb,log1p:()=>mb,log2:()=>lb,logaddexp:()=>pb,logaddexp2:()=>yb,logical_and:()=>JA,logical_not:()=>QA,logical_or:()=>KA,logical_xor:()=>HA,logspace:()=>uA,mask_indices:()=>Hd,matmul:()=>XA,matrix_transpose:()=>LA,matvec:()=>GA,max:()=>Qe,maximum:()=>Ub,may_share_memory:()=>ts,mean:()=>Fg,median:()=>kg,meshgrid:()=>Hc,min:()=>rn,min_scalar_type:()=>Is,minimum:()=>$b,mintypecode:()=>vs,mod:()=>Ab,modf:()=>Ob,moveaxis:()=>Ih,multiply:()=>ob,nan_to_num:()=>qb,nanargmax:()=>Qg,nanargmin:()=>Kg,nancumprod:()=>rh,nancumsum:()=>Hg,nanmax:()=>Jg,nanmean:()=>Gg,nanmedian:()=>th,nanmin:()=>Xg,nanpercentile:()=>nh,nanprod:()=>Wg,nanquantile:()=>eh,nanstd:()=>Zg,nansum:()=>Lg,nanvar:()=>Yg,ndim:()=>ys,negative:()=>db,nextafter:()=>fg,nonzero:()=>Xh,not_equal:()=>gg,ones:()=>eA,ones_like:()=>yA,outer:()=>VA,packbits:()=>Xb,pad:()=>hh,parseNpy:()=>z1,parseNpyData:()=>v1,parseNpyHeader:()=>_1,parseNpz:()=>M1,parseNpzSync:()=>F1,parseTxt:()=>O1,partition:()=>Gh,percentile:()=>Rg,permute_dims:()=>WA,place:()=>Za,poly:()=>Ng,polyadd:()=>Dg,polyder:()=>xg,polydiv:()=>Cg,polyfit:()=>Sg,polyint:()=>wg,polymul:()=>Ig,polysub:()=>zg,polyval:()=>_g,positive:()=>Nb,pow:()=>rl,power:()=>rl,printoptions:()=>is,prod:()=>Bg,promote_types:()=>Ma,ptp:()=>Tg,put:()=>Ot,put_along_axis:()=>Ya,putmask:()=>Xa,quantile:()=>qg,rad2deg:()=>p0,radians:()=>f0,random:()=>E1,ravel:()=>xh,ravel_multi_index:()=>Wd,real:()=>Qb,real_if_close:()=>ug,reciprocal:()=>Db,remainder:()=>Ib,repeat:()=>Uh,require:()=>xA,reshape:()=>Nh,resize:()=>Ph,result_type:()=>ws,right_shift:()=>ol,rint:()=>ih,roll:()=>Vh,rollaxis:()=>zh,roots:()=>vg,rot90:()=>qh,round:()=>ul,round_:()=>Ea,row_stack:()=>sa,save:()=>V1,saveNpy:()=>UN,saveNpySync:()=>$N,saveNpz:()=>vl,saveNpzSync:()=>k1,saveSync:()=>P1,savetxt:()=>Y1,savetxtSync:()=>Z1,savez:()=>j1,savez_compressed:()=>L1,searchsorted:()=>Ft,select:()=>jd,serializeNpy:()=>Kr,serializeNpz:()=>Bs,serializeNpzSync:()=>Ts,serializeTxt:()=>Ut,set_printoptions:()=>as,setdiff1d:()=>mh,seterr:()=>os,setxor1d:()=>ph,shape:()=>ho,shares_memory:()=>es,sign:()=>bb,signbit:()=>lg,sin:()=>s0,sinc:()=>jb,sinh:()=>y0,size:()=>ds,sort:()=>jh,sort_complex:()=>Zh,spacing:()=>mg,split:()=>ia,sqrt:()=>ab,square:()=>wb,squeeze:()=>Ch,stack:()=>_h,std:()=>$g,subtract:()=>nb,sum:()=>Mg,swapaxes:()=>wh,take:()=>$d,take_along_axis:()=>kd,tan:()=>u0,tanh:()=>b0,tensordot:()=>PA,tile:()=>Eh,tobytes:()=>gs,tofile:()=>Ds,tolist:()=>As,trace:()=>et,transpose:()=>RA,trapezoid:()=>a0,tri:()=>wA,tril:()=>IA,tril_indices:()=>Xd,tril_indices_from:()=>Jd,trim_zeros:()=>dh,triu:()=>zA,triu_indices:()=>Kd,triu_indices_from:()=>Qd,true_divide:()=>Xo,trunc:()=>uh,typename:()=>_s,union1d:()=>yh,unique:()=>Ua,unique_all:()=>$a,unique_counts:()=>ka,unique_inverse:()=>Ra,unique_values:()=>bh,unpackbits:()=>Jb,unravel_index:()=>Gd,unstack:()=>Oh,unwrap:()=>Pb,vander:()=>_A,var:()=>xa,variance:()=>Ug,vdot:()=>Ho,vecdot:()=>jA,vecmat:()=>YA,view:()=>Ns,vsplit:()=>ca,vstack:()=>vh,where:()=>Fa,zeros:()=>tA,zeros_like:()=>pA});module.exports=GN(H1);var Pr=require("node:fs"),jr=require("node:fs/promises");function Eo(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 Uo(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 er="float64";function K(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 Yr(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 Ur(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function Er(r){return r==="float64"||r==="float32"}function O(r){return r==="int64"||r==="uint64"}function B(r){return r==="complex64"||r==="complex128"}function L(r,t,e){if(B(r)){let n=e?` ${e}`:"";throw new TypeError(`ufunc '${t}' not supported for complex dtype '${r}'.${n}`)}}function Rt(r){if(r==="complex128")return"float64";if(r==="complex64")return"float32";throw new Error(`${r} is not a complex dtype`)}function or(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(B(r)||B(t)){if(B(r)&&B(t))return r==="complex128"||t==="complex128"?"complex128":"complex64";let c=B(r)?r:t,l=B(r)?t:r;return c==="complex128"||l==="float64"||l==="int64"||l==="uint64"||l==="int32"||l==="uint32"?"complex128":"complex64"}if(Er(r)||Er(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,i=u(r),s=u(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&i===s){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(o&&n&&i===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(i,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?i>s?r:s===8?"int16":s===16?"int32":s===32?"int64":"float64":o&&n?s>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}var U=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 Ml(r){return r instanceof U||typeof r=="object"&&r!==null&&"re"in r}var S=class r{constructor(t,e,n,o,a){this._isCContiguous=-1;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(){if(this._isCContiguous!==-1)return this._isCContiguous===1;let t=this._shape,e=this._strides,n=t.length,o;if(n===0)o=!0;else if(n===1)o=e[0]===1;else{o=!0;let a=1;for(let u=n-1;u>=0;u--){if(e[u]!==a){o=!1;break}a*=t[u]}}return this._isCContiguous=o?1:0,o}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=B(this._dtype),u;if(o===0)u=this._offset;else{let i=t;u=this._offset;for(let s=0;s<o;s++){let c=1;for(let f=s+1;f<o;f++)c*=e[f];let l=Math.floor(i/c);i=i%c,u+=l*n[s]}}if(a){let i=u*2,s=this._data[i],c=this._data[i+1];return new U(s,c)}return this._data[u]}iset(t,e){let n=this._shape,o=this._strides,a=n.length,u=B(this._dtype),i;if(a===0)i=this._offset;else{let s=t;i=this._offset;for(let c=0;c<a;c++){let l=1;for(let m=c+1;m<a;m++)l*=n[m];let f=Math.floor(s/l);s=s%l,i+=f*o[c]}}if(u){let s=i*2,c,l;e instanceof U?(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[s]=c,this._data[s+1]=l}else this._data[i]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];if(B(this._dtype)){let o=n*2,a=this._data[o],u=this._data[o+1];return new U(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(B(this._dtype)){let a=o*2,u,i;e instanceof U?(u=e.re,i=e.im):typeof e=="object"&&e!==null&&"re"in e?(u=e.re,i=e.im??0):(u=Number(e),i=0),this._data[a]=u,this._data[a+1]=i}else this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=B(e),a=K(e);if(!a)throw new Error(`Cannot copy array with dtype ${e}`);let u=o?n*2:n,i=new a(u);if(this.isCContiguous&&this._offset===0)if(O(e)){let s=this._data,c=i;for(let l=0;l<u;l++)c[l]=s[l]}else i.set(this._data.subarray(0,u));else if(O(e)){let s=i;for(let c=0;c<n;c++)s[c]=this.iget(c)}else if(o){let s=i;for(let c=0;c<n;c++){let l=this.iget(c);s[c*2]=l.re,s[c*2+1]=l.im}}else for(let s=0;s<n;s++)i[s]=this.iget(s);return new r(i,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let u=o??r._computeStrides(e),i=a??0;return new r(t,e,u,i,n)}static zeros(t,e=er){let n=t.reduce((s,c)=>s*c,1),o=B(e),a=K(e);if(!a)throw new Error(`Cannot create array with dtype ${e}`);let u=o?n*2:n,i=new a(u);return new r(i,t,r._computeStrides(t),0,e)}static ones(t,e=er){let n=t.reduce((s,c)=>s*c,1),o=B(e),a=K(e);if(!a)throw new Error(`Cannot create array with dtype ${e}`);let u=o?n*2:n,i=new a(u);if(O(e))i.fill(BigInt(1));else if(o){let s=i;for(let c=0;c<n;c++)s[c*2]=1,s[c*2+1]=0}else i.fill(1);return new r(i,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 lr(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}var YN={threshold:1e3,edgeitems:3,precision:8,linewidth:75,floatmode:"maxprec",suppress:!0,separator:" ",prefix:"",suffix:"",nanstr:"nan",infstr:"inf",sign:"-",legacy:!1},ur={...YN};function Tl(r){ur={...ur,...r}}function Ol(){return{...ur}}function El(r){let t=null,e={_savedOptions:null,enter(){t={...ur},e._savedOptions=t,ur={...ur,...r}},exit(){t&&(ur=t,t=null,e._savedOptions=null)},apply(n){e.enter();try{return n()}finally{e.exit()}}};return e}function Vt(r,t=null,e=!0,n=!0,o="k",a="-",u=null,i=null,s=null){let c=t??ur.precision;if(!Number.isFinite(r))return Number.isNaN(r)?ur.nanstr:(r>0?"":"-")+ur.infstr;let l;if(e&&t===null?(l=r.toString(),n&&!l.includes(".")&&!l.includes("e")&&(l+=".0")):l=r.toFixed(c),s!==null){let f=l.indexOf(".");if(f!==-1){let m=l.length-f-1;m<s&&(l+="0".repeat(s-m))}else n&&(l+="."+"0".repeat(s))}if(o!=="k"&&l.includes(".")){if(o==="."||o==="0"||o==="-"){let f=l.length;for(;f>0&&l[f-1]==="0";)f--;l=l.slice(0,f)}o==="0"&&l.endsWith(".")&&(l+="0"),o==="-"&&l.endsWith(".")&&(l=l.slice(0,-1))}if(r>=0&&!Object.is(r,-0)&&(a==="+"?l="+"+l:a===" "&&(l=" "+l)),u!==null&&l.length<u&&(l=" ".repeat(u-l.length)+l),i!==null){let f=l.indexOf(".");if(f!==-1){let m=l.length-f-1;m<i&&(l+="0".repeat(i-m))}}return l}function qt(r,t=null,e=!0,n="k",o="-",a=null,u=2,i=null){let s=t??ur.precision;if(!Number.isFinite(r))return Number.isNaN(r)?ur.nanstr:(r>0?"":"-")+ur.infstr;let c=r.toExponential(s);if(i!==null){let d=c.indexOf("e"),b=c.slice(0,d),A=c.slice(d),g=b.indexOf(".");if(g!==-1){let h=b.length-g-1;h<i&&(c=b+"0".repeat(i-h)+A)}}if(n!=="k"){let d=c.indexOf("e"),b=c.slice(0,d),A=c.slice(d);b.includes(".")&&((n==="."||n==="0"||n==="-")&&(b=b.replace(/0+$/,"")),n==="0"&&b.endsWith(".")&&(b+="0"),n==="-"&&(b=b.replace(/\.$/,""))),c=b+A}let l=c.indexOf("e"),f=c.slice(0,l),m=c.slice(l+1),p=m[0]==="-"?"-":"+",y=m.replace(/^[+-]/,"");for(;y.length<u;)y="0"+y;return c=f+"e"+p+y,r>=0&&!Object.is(r,-0)&&(o==="+"?c="+"+c:o===" "&&(c=" "+c)),a!==null&&c.length<a&&(c=" ".repeat(a-c.length)+c),c}function Ul(r,t=2,e=0){if(t<2||t>36)throw new Error("base must be between 2 and 36");r=Math.trunc(r);let n;if(r<0?n="-"+Math.abs(r).toString(t).toUpperCase():n=r.toString(t).toUpperCase(),e>0){let o="0".repeat(e);n.startsWith("-")?n="-"+o+n.slice(1):n=o+n}return n}function $l(r,t=null){if(r=Math.trunc(r),t!==null&&r<0){if(r=Math.pow(2,t)+r,r<0)throw new Error("width too small for negative number");let o=r.toString(2);return o.length<t&&(o="0".repeat(t-o.length)+o),o}let e;return r<0?e="-"+Math.abs(r).toString(2):e=r.toString(2),t!==null&&e.length<t&&(e="0".repeat(t-e.length)+e),e}function ko(r,t,e){if(r instanceof U){let n=ko(r.re,"float64",e),o=ko(Math.abs(r.im),"float64",e),a=r.im>=0?"+":"-";return`${n}${a}${o}j`}return typeof r=="boolean"?r?" True":"False":typeof r=="bigint"?r.toString():Number.isFinite(r)?t==="float32"||t==="float64"?e.suppress&&Math.abs(r)<1e-10&&r!==0?"0.":Vt(r,e.precision,!1,!0,"k",e.sign):r.toString():Number.isNaN(r)?e.nanstr:(r>0?"":"-")+e.infstr}function ZN(r,t){let e=[],n=r.shape,o=n.length,a=r.strides;function u(i,s){if(s===o){let m=0;for(let p=0;p<o;p++)m+=i[p]*a[p];e.push(r.iget(m));return}let c=n[s];if(n.reduce((m,p)=>m*p,1)>t.threshold&&c>2*t.edgeitems){for(let m=0;m<t.edgeitems;m++)i[s]=m,u(i,s+1);for(let m=c-t.edgeitems;m<c;m++)i[s]=m,u(i,s+1)}else for(let m=0;m<c;m++)i[s]=m,u(i,s+1)}return o>0?u(new Array(o).fill(0),0):e.push(r.iget(0)),e}function Fl(r,t){return r<0||Object.is(r,-0)?"-"+Math.abs(r).toString()+".":t==="+"?"+"+r.toString()+".":t===" "?" "+r.toString()+".":r.toString()+"."}function ft(r,t,e){let n=r.indexOf(".");if(n===-1)return r.padStart(t+(e>0?1+e:0));let o=r.slice(0,n),a=r.slice(n+1),u=o.padStart(t),i=e>0?a.padEnd(e):a;return u+"."+i}function Bl(r){let t=0,e=0;for(let n of r){let o=n.indexOf(".");o===-1?t=Math.max(t,n.length):(t=Math.max(t,o),e=Math.max(e,n.length-o-1))}return{maxLeft:t,maxRight:e}}function Vs(r,t){let e=r.filter(m=>Number.isFinite(m));if(e.length===0){let m=r.map(y=>Number.isNaN(y)?t.nanstr:(y>0?"":"-")+t.infstr),p=m.length>0?Math.max(...m.map(y=>y.length)):1;return y=>Number.isNaN(y)?t.nanstr.padStart(p):Number.isFinite(y)?y.toString().padStart(p):((y>0?"":"-")+t.infstr).padStart(p)}let n=t.suppress?e.map(m=>Math.abs(m)<1e-10&&m!==0?0:m):e,o=n.map(Math.abs).filter(m=>m>0),a=o.length>0?Math.max(...o):0,u=o.length>0?Math.min(...o):0;if(a>=1e16||u>0&&u<1e-4||u>0&&a/u>1e3){let m=n.map(h=>qt(h,t.precision,!1,".",t.sign)),p=0;for(let h of m){let N=h.indexOf("e"),D=N!==-1?h.slice(0,N):h,x=D.indexOf(".");x!==-1&&(p=Math.max(p,D.length-x-1))}let y=Math.max(p,0),d=Math.max(y,1),b=y===0?".":"k",A=n.map(h=>qt(h,d,!1,b,t.sign));for(let h of r)Number.isFinite(h)||A.push(Number.isNaN(h)?t.nanstr:(h>0?"":"-")+t.infstr);let g=Math.max(...A.map(h=>h.length));return h=>(t.suppress&&Math.abs(h)<1e-10&&h!==0&&Number.isFinite(h)&&(h=0),Number.isNaN(h)?t.nanstr.padStart(g):Number.isFinite(h)?qt(h,d,!1,b,t.sign).padStart(g):((h>0?"":"-")+t.infstr).padStart(g))}if(n.every(m=>Number.isInteger(m))){let m=n.map(d=>Fl(d,t.sign));for(let d of r)Number.isFinite(d)||m.push(Number.isNaN(d)?t.nanstr:(d>0?"":"-")+t.infstr);let{maxLeft:p,maxRight:y}=Bl(m);return d=>(t.suppress&&Math.abs(d)<1e-10&&d!==0&&Number.isFinite(d)&&(d=0),Number.isNaN(d)?ft(t.nanstr,p,y):Number.isFinite(d)?ft(Fl(d,t.sign),p,y):ft((d>0?"":"-")+t.infstr,p,y))}let c=n.map(m=>Vt(m,t.precision,!1,!0,".",t.sign));for(let m of r)Number.isFinite(m)||c.push(Number.isNaN(m)?t.nanstr:(m>0?"":"-")+t.infstr);let{maxLeft:l,maxRight:f}=Bl(c);return m=>(t.suppress&&Math.abs(m)<1e-10&&m!==0&&Number.isFinite(m)&&(m=0),Number.isNaN(m)?ft(t.nanstr,l,f):Number.isFinite(m)?ft(Vt(m,t.precision,!1,!0,".",t.sign),l,f):ft((m>0?"":"-")+t.infstr,l,f))}function XN(r,t){let e=r.dtype,n=ZN(r,t);if(n.length===0)return a=>ko(a,e,t);if(e==="bool")return a=>a?" True":"False";if(e==="int64"||e==="uint64"){let a=n.map(i=>i.toString()),u=Math.max(...a.map(i=>i.length));return i=>i.toString().padStart(u)}if(e.startsWith("int")||e.startsWith("uint")){let a=n.map(i=>i.toString()),u=Math.max(...a.map(i=>i.length));return i=>i.toString().padStart(u)}if(e==="complex64"||e==="complex128"){let a=n.map(c=>c.re),u=n.map(c=>Math.abs(c.im)),i=Vs(a,t),s=Vs(u,t);return c=>{let l=c,f=i(l.re),m=s(Math.abs(l.im)),p=l.im>=0?"+":"-";return`${f}${p}${m}j`}}let o=Vs(n,t);return a=>o(a)}function $o(r,t,e,n,o,a){let u=r.shape,i=u.length;if(e===i){let d=0,b=r.strides;for(let g=0;g<i;g++)d+=t[g]*b[g];let A=r.iget(d);return o(A)}let s=u[e],c=n.threshold,l=n.edgeitems,m=u.reduce((d,b)=>d*b,1)>c&&s>2*l,p=[],y=[...t];if(m){for(let d=0;d<l;d++)y[e]=d,p.push($o(r,y,e+1,n,o,a+1));p.push("...");for(let d=s-l;d<s;d++)y[e]=d,p.push($o(r,y,e+1,n,o,a+1))}else for(let d=0;d<s;d++)y[e]=d,p.push($o(r,y,e+1,n,o,a+1));if(e===i-1){let d="["+p.join(n.separator)+"]";if(a+d.length<n.linewidth)return d;let b=" ".repeat(a+1),A=n.linewidth-a-1,g=[],h="";for(let N=0;N<p.length;N++){let D=p[N];if(h==="")h=D;else{let x=h+n.separator+D;x.length<A?h=x:(g.push(h),h=D)}}return h&&g.push(h),"["+g.join(`
|
|
2
|
+
`+b)+"]"}else{let d=" ".repeat(a+1),b=i-e-2,A=`
|
|
3
|
+
`+`
|
|
4
|
+
`.repeat(Math.max(0,b))+d;return"["+p.join(A)+"]"}}function Ro(r,t=null,e=null,n=null,o=" ",a="",u="",i=null,s=null,c=null,l=null){let f={...ur,linewidth:t??ur.linewidth,precision:e??ur.precision,suppress:n??ur.suppress,separator:o,prefix:a,suffix:u,threshold:i??ur.threshold,edgeitems:s??ur.edgeitems,floatmode:c??ur.floatmode,sign:l??ur.sign};if(r.ndim===0){let d=r.iget(0);return ko(d,r.dtype,f)}let m=XN(r,f),p=f.prefix.length,y=$o(r,new Array(r.ndim).fill(0),0,f,m,p);return f.prefix+y+f.suffix}function kl(r,t=null,e=null,n=null){let a="array("+Ro(r,t,e,n,", ");return r.dtype!=="float64"&&(a+=`, dtype='${r.dtype}'`),a+=")",a}function qo(r,t=null,e=null,n=null){return Ro(r,t,e,n)}var P=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 itemsize(){return Yr(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){let e=this._storage.dtype,n=this.size;if(O(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 i=a;if(i<0&&(i=this.shape[u]+i),i<0||i>=this.shape[u])throw new Error(`Index ${a} is out of bounds for axis ${u} with size ${this.shape[u]}`);return i}),o=this.dtype;if(B(o))this._storage.set(n,e);else if(O(o)){let a=e instanceof U?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 U?e.re:Number(e))?1:0;this._storage.set(n,u)}else{let a=e instanceof U?e.re:Number(e);this._storage.set(n,a)}}iget(t){return this._storage.iget(t)}iset(t,e){this._storage.iset(t,e)}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=K(t);if(!u)throw new Error(`Cannot convert to dtype ${t}`);let i=new u(a),s=this.data;if(O(n)&&!O(t)){let l=s;if(t==="bool")for(let f=0;f<a;f++)i[f]=l[f]!==BigInt(0)?1:0;else for(let f=0;f<a;f++)i[f]=Number(l[f])}else if(!O(n)&&O(t)){let l=s;for(let f=0;f<a;f++)i[f]=BigInt(Math.round(Number(l[f])))}else if(t==="bool"){let l=s;for(let f=0;f<a;f++)i[f]=l[f]!==0?1:0}else if(n==="bool"&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else if(!O(n)&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else{let l=s;for(let f=0;f<a;f++)i[f]=l[f]}let c=S.fromData(i,o,t);return new r(c)}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=Eo(s);return Uo(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];if(a+=c.start*this._storage.strides[s],c.step===0)continue;let l=Math.max(0,Math.ceil((c.stop-c.start)/c.step));n.push(l),o.push(this._storage.strides[s]*c.step)}let u=S.fromData(this._storage.data,n,this._storage.dtype,o,a),i=this._base??this;return new r(u,i)}toString(){return qo(this._storage)}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 i=0;i<t[a];i++)o[a]=i,u.push(n(o,a+1));return u};return n(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){let n=this._storage.data,o=n.BYTES_PER_ELEMENT,a=this._storage.offset*o,u=this.size*o;return n.buffer.slice(a,a+u)}let e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){let e=t[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(t)}};function z(r){return r instanceof P||r&&typeof r=="object"&&"storage"in r&&r.storage instanceof S?r.storage:r}function M(r,t){return P.fromStorage(r,t)}function Nr(r,t){let e=t.base??t;return P.fromStorage(r,e)}function $r(r){return r.map(t=>M(t))}function mt(r,t){return r.map(e=>Nr(e,t))}function Vo(r){return[M(r[0]),M(r[1])]}function Ps(r){return new P(r)}function KN(r){return!!(r instanceof P||r&&typeof r=="object"&&"storage"in r&&r.storage instanceof S)}function wr(r,t=er){let e=S.zeros(r,t);return new P(e)}function Po(r,t=er){let e=S.ones(r,t);return new P(e)}function jo(r,t=er){return wr(r,t)}function Lo(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=er);let o=K(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((s,c)=>s*c,1),u=new o(a);if(O(n)){let s=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));u.fill(s)}else n==="bool"?u.fill(t?1:0):u.fill(Number(t));let i=S.fromData(u,r,n);return new P(i)}function QN(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function Rl(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>Rl(t)):!1}function ql(r){return Ml(r)?!0:Array.isArray(r)?r.some(t=>ql(t)):!1}function HN(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function Q(r,t){if(r instanceof P)return!t||r.dtype===t?r.copy():r.astype(t);let e=Rl(r),n=ql(r),o=QN(r),a=o.reduce((p,y)=>p*y,1),u=t;u||(n?u="complex128":e?u="int64":u=er);let i=B(u),s=K(u);if(!s)throw new Error(`Cannot create array with dtype ${u}`);let c=i?a*2:a,l=new s(c),f=HN(r);if(O(u)){let p=l;for(let y=0;y<a;y++){let d=f[y];p[y]=typeof d=="bigint"?d:BigInt(Math.round(Number(d)))}}else if(u==="bool"){let p=l;for(let y=0;y<a;y++)p[y]=f[y]?1:0}else if(i){let p=l;for(let y=0;y<a;y++){let d=f[y],b,A;d instanceof U?(b=d.re,A=d.im):typeof d=="object"&&d!==null&&"re"in d?(b=d.re,A=d.im??0):(b=Number(d),A=0),p[y*2]=b,p[y*2+1]=A}}else{let p=l;for(let y=0;y<a;y++){let d=f[y];p[y]=Number(d)}}let m=S.fromData(l,o,u);return new P(m)}function js(r,t,e=1,n=er){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)),i=K(n);if(!i)throw new Error(`Cannot create arange array with dtype ${n}`);let s=new i(u);if(O(n))for(let l=0;l<u;l++)s[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<u;l++)s[l]=o+l*e!==0?1:0;else for(let l=0;l<u;l++)s[l]=o+l*e;let c=S.fromData(s,[u],n);return new P(c)}function Ls(r,t,e=50,n=er){if(e<0)throw new Error("num must be non-negative");if(e===0)return Q([],n);if(e===1)return Q([r],n);let o=K(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),u=(t-r)/(e-1);if(O(n))for(let s=0;s<e;s++)a[s]=BigInt(Math.round(r+s*u));else if(n==="bool")for(let s=0;s<e;s++)a[s]=r+s*u!==0?1:0;else for(let s=0;s<e;s++)a[s]=r+s*u;let i=S.fromData(a,[e],n);return new P(i)}function Ws(r,t,e=50,n=10,o=er){if(e<0)throw new Error("num must be non-negative");if(e===0)return Q([],o);if(e===1)return Q([Math.pow(n,r)],o);let a=K(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let u=new a(e),i=(t-r)/(e-1);if(O(o))for(let c=0;c<e;c++){let l=r+c*i;u[c]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let c=0;c<e;c++){let l=r+c*i;u[c]=Math.pow(n,l)!==0?1:0}else for(let c=0;c<e;c++){let l=r+c*i;u[c]=Math.pow(n,l)}let s=S.fromData(u,[e],o);return new P(s)}function Gs(r,t,e=50,n=er){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 Q([],n);if(e===1)return Q([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=K(n);if(!u)throw new Error(`Cannot create geomspace array with dtype ${n}`);let i=new u(e),s=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-s)/(e-1);if(O(n))for(let m=0;m<e;m++){let p=o*Math.exp(s+m*l);i[m]=BigInt(Math.round(p))}else if(n==="bool")for(let m=0;m<e;m++){let p=o*Math.exp(s+m*l);i[m]=p!==0?1:0}else for(let m=0;m<e;m++){let p=o*Math.exp(s+m*l);i[m]=p}let f=S.fromData(i,[e],n);return new P(f)}function Wo(r,t,e=0,n=er){let o=t??r,a=wr([r,o],n),u=a.data;if(O(n)){let i=u;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(i[s*o+c]=BigInt(1))}}else{let i=u;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(i[s*o+c]=1)}}return a}function Ys(r,t=er){return Wo(r,r,0,t)}function Qr(r,t){return KN(r)?!t||r.dtype===t?r:r.astype(t):Q(r,t)}function Zs(r,t){return wr(Array.from(r.shape),t??r.dtype)}function Xs(r,t){return Po(Array.from(r.shape),t??r.dtype)}function Js(r,t){return jo(Array.from(r.shape),t??r.dtype)}function Ks(r,t,e){return Lo(Array.from(r.shape),t,e??r.dtype)}function Qs(r){return r.copy()}function Hs(r,t){return Qr(r,t)}function ri(r,t){return Qr(r,t).copy()}function ti(r,t){return Qr(r,t).copy()}function ei(r,t){let e=Qr(r,t),n=e.data;for(let o=0;o<n.length;o++){let a=n[o];if(!Number.isFinite(a))throw new Error("array must not contain infs or NaNs")}return e}function ni(r,t,e){let n=r;return t&&t!==r.dtype&&(n=n.astype(t)),n}function rD(r){let t=r.data,e=S.fromData(t.slice(),[t.length],r.dtype);return Ps(e)}function Go(r,t=0){let e=r.shape,n=r.data,o=r.dtype;if(e.length===1){let a=e[0],u=a+Math.abs(t),i=wr([u,u],o),s=i.data;for(let c=0;c<a;c++){let l=t>=0?c:c-t,f=t>=0?c+t:c;l>=0&&l<u&&f>=0&&f<u&&(s[l*u+f]=n[c])}return i}else if(e.length===2){let a=e[0],u=e[1],i=Math.min(t>=0?Math.min(a,u-t):Math.min(a+t,u),Math.max(0,t>=0?u-t:a+t));if(i<=0)return Q([],o);let s=[];for(let c=0;c<i;c++){let l=t>=0?c:c-t,f=t>=0?c+t:c;l>=0&&l<a&&f>=0&&f<u&&s.push(n[l*u+f])}return Q(s,o)}throw new Error("Input must be 1-D or 2-D")}function oi(r,t=0){let e=rD(r);return Go(e,t)}function ai(r,t,e=0,n=er){let o=t??r,a=wr([r,o],n),u=a.data;for(let i=0;i<r;i++)for(let s=0;s<=Math.min(i+e,o-1);s++)s>=0&&(u[i*o+s]=1);return a}function si(r,t=0){let e=r.shape;if(e.length<2)throw new Error("Input must be at least 2-D");let n=r.copy(),o=n.data,a=e[e.length-2],u=e[e.length-1],i=e.slice(0,-2).reduce((c,l)=>c*l,1),s=a*u;for(let c=0;c<i;c++){let l=c*s;for(let f=0;f<a;f++)for(let m=f+t+1;m<u;m++)o[l+f*u+m]=0}return n}function ii(r,t=0){let e=r.shape;if(e.length<2)throw new Error("Input must be at least 2-D");let n=r.copy(),o=n.data,a=e[e.length-2],u=e[e.length-1],i=e.slice(0,-2).reduce((c,l)=>c*l,1),s=a*u;for(let c=0;c<i;c++){let l=c*s;for(let f=0;f<a;f++)for(let m=0;m<Math.min(f+t,u);m++)o[l+f*u+m]=0}return n}function ui(r,t,e=!1){let n=r.size,o=t??n,a=r.data,u=wr([n,o],r.dtype),i=u.data;for(let s=0;s<n;s++){let c=a[s];for(let l=0;l<o;l++){let f=e?l:o-1-l;i[s*o+l]=Math.pow(c,f)}}return u}function ci(r,t=er,e=-1,n=0){let o=K(t);if(!o)throw new Error(`Unsupported dtype: ${t}`);let a;if(r instanceof ArrayBuffer){let i=n,s=e<0?(r.byteLength-i)/o.BYTES_PER_ELEMENT:e;a=new o(r,i,s)}else{let i=n,s=e<0?r.length:n+e,c=Array.from(r.slice(i,s));a=new o(c.length);for(let l=0;l<c.length;l++)a[l]=c[l]}let u=S.fromData(a,[a.length],t);return Ps(u)}function li(r,t,e=er){let n=t.reduce((c,l)=>c*l,1),o=K(e);if(!o)throw new Error(`Unsupported dtype: ${e}`);let a=new o(n),u=[],i=1;for(let c=t.length-1;c>=0;c--)u.unshift(i),i*=t[c];for(let c=0;c<n;c++){let l=[],f=c;for(let m=0;m<t.length;m++)l.push(Math.floor(f/u[m])),f=f%u[m];a[c]=r(...l)}let s=S.fromData(a,t,e);return Ps(s)}function fi(r,t=er,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return Q(n,t)}function mi(r,t=er,e=-1,n){let o=n??/\s+/,u=r.split(o).filter(s=>s.trim()!=="").map(s=>parseFloat(s.trim())),i=e>=0?u.slice(0,e):u;return Q(i,t)}function pi(r,t=er,e=-1,n=""){throw new Error("fromfile requires Node.js file system access")}function Zr(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 i=u<o-e?1:r[u-(o-e)],s=u<o-n?1:t[u-(o-n)];if(i===s)a[u]=i;else if(i===1)a[u]=s;else if(s===1)a[u]=i;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 tD(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let i=o-n+u,s=r[u],c=e[i];if(s===c)a[i]=t[u];else if(s===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function Yo(r,t){let e=tD(r.shape,r.strides,t);return S.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function sr(r,t,e,n){let o=or(r.dtype,t.dtype),a=r.shape,u=t.shape;if(a.length===u.length&&a.every((y,d)=>y===u[d])&&r.isCContiguous&&t.isCContiguous&&!O(r.dtype)&&!O(t.dtype)&&!O(o)){let y=r.size,d=S.zeros(Array.from(a),o),b=d.data,A=r.data,g=t.data,h=r.offset,N=t.offset;if(h===0&&N===0)for(let D=0;D<y;D++)b[D]=e(A[D],g[D]);else for(let D=0;D<y;D++)b[D]=e(A[h+D],g[N+D]);return d}let s=Zr(r.shape,t.shape),c=Yo(r,s),l=Yo(t,s),f=S.zeros(s,o),m=f.data,p=f.size;if(O(o)){let y=m;for(let d=0;d<p;d++){let b=c.iget(d),A=l.iget(d),g=b instanceof U?b.re:b,h=A instanceof U?A.re:A,N=typeof g=="bigint"?g:BigInt(Math.round(g)),D=typeof h=="bigint"?h:BigInt(Math.round(h));n==="add"?y[d]=N+D:n==="subtract"?y[d]=N-D:n==="multiply"?y[d]=N*D:n==="divide"?y[d]=N/D:y[d]=BigInt(Math.round(e(Number(N),Number(D))))}}else{let y=O(r.dtype)||O(t.dtype);for(let d=0;d<p;d++){let b=c.iget(d),A=l.iget(d),g=Number(b),h=Number(A);m[d]=e(g,h)}}return f}function Ir(r,t,e){let n=Zr(r.shape,t.shape),o=Yo(r,n),a=Yo(t,n),u=n.reduce((c,l)=>c*l,1),i=new Uint8Array(u),s=O(r.dtype)||O(t.dtype);for(let c=0;c<u;c++){let l=o.iget(c),f=a.iget(c),m=Number(l),p=Number(f);i[c]=e(m,p)?1:0}return S.fromData(i,n,"bool")}function ir(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,i=e?n:n!=="float32"&&n!=="float64"?"float64":n,s=S.zeros(o,i),c=s.data,l=r.data,f=r.offset,m=r.isCContiguous;if(O(n))if(O(i)){let p=c;if(m)for(let y=0;y<a;y++){let d=Number(l[f+y]);p[y]=BigInt(Math.round(t(d)))}else for(let y=0;y<a;y++)p[y]=BigInt(Math.round(t(Number(r.iget(y)))))}else if(m)for(let p=0;p<a;p++)c[p]=t(Number(l[f+p]));else for(let p=0;p<a;p++)c[p]=t(Number(r.iget(p)));else if(m)if(f===0)for(let p=0;p<a;p++)c[p]=t(Number(l[p]));else for(let p=0;p<a;p++)c[p]=t(Number(l[f+p]));else for(let p=0;p<a;p++)c[p]=t(Number(r.iget(p)));return s}function yi(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Dr(r,t){return[r[t*2],r[t*2+1]]}function br(r,t,e,n){r[t*2]=e,r[t*2+1]=n}function Ll(r,t){if(typeof t=="number")return Vl(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return Vl(r,e)}return yi(r,t)?eD(r,t):sr(r,t,(e,n)=>e+n,"add")}function eD(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=n.data,s=r.offset,c=t.offset;if(B(e)){let l=i,f=B(r.dtype),m=B(t.dtype);for(let p=0;p<o;p++){let[y,d]=f?Dr(a,s+p):[Number(a[s+p]),0],[b,A]=m?Dr(u,c+p):[Number(u[c+p]),0];br(l,p,y+b,d+A)}return n}if(O(e)){let l=i;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[s+m]=="bigint"?a[s+m]:BigInt(Math.round(Number(a[s+m]))),y=typeof u[c+m]=="bigint"?u[c+m]:BigInt(Math.round(Number(u[c+m])));l[m]=p+y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[s+y]+p[c+y]}}else if(O(r.dtype)||O(t.dtype))for(let f=0;f<o;f++){let m=typeof a[s+f]=="bigint"?Number(a[s+f]):a[s+f],p=typeof u[c+f]=="bigint"?Number(u[c+f]):u[c+f];i[f]=m+p}else if(s===0&&c===0)for(let f=0;f<o;f++)i[f]=a[f]+u[f];else for(let f=0;f<o;f++)i[f]=a[s+f]+u[c+f];return n}function Wl(r,t){if(typeof t=="number")return Pl(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return Pl(r,e)}return yi(r,t)?nD(r,t):sr(r,t,(e,n)=>e-n,"subtract")}function nD(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=n.data,s=r.offset,c=t.offset;if(B(e)){let l=i,f=B(r.dtype),m=B(t.dtype);for(let p=0;p<o;p++){let[y,d]=f?Dr(a,s+p):[Number(a[s+p]),0],[b,A]=m?Dr(u,c+p):[Number(u[c+p]),0];br(l,p,y-b,d-A)}return n}if(O(e)){let l=i;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[s+m]=="bigint"?a[s+m]:BigInt(Math.round(Number(a[s+m]))),y=typeof u[c+m]=="bigint"?u[c+m]:BigInt(Math.round(Number(u[c+m])));l[m]=p-y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[s+y]-p[c+y]}}else if(O(r.dtype)||O(t.dtype))for(let f=0;f<o;f++){let m=typeof a[s+f]=="bigint"?Number(a[s+f]):a[s+f],p=typeof u[c+f]=="bigint"?Number(u[c+f]):u[c+f];i[f]=m-p}else if(s===0&&c===0)for(let f=0;f<o;f++)i[f]=a[f]-u[f];else for(let f=0;f<o;f++)i[f]=a[s+f]-u[c+f];return n}function Gl(r,t){if(typeof t=="number")return jl(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return jl(r,e)}return yi(r,t)?oD(r,t):sr(r,t,(e,n)=>e*n,"multiply")}function oD(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=n.data,s=r.offset,c=t.offset;if(B(e)){let l=i,f=B(r.dtype),m=B(t.dtype);for(let p=0;p<o;p++){let[y,d]=f?Dr(a,s+p):[Number(a[s+p]),0],[b,A]=m?Dr(u,c+p):[Number(u[c+p]),0],g=y*b-d*A,h=y*A+d*b;br(l,p,g,h)}return n}if(O(e)){let l=i;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[s+m]=="bigint"?a[s+m]:BigInt(Math.round(Number(a[s+m]))),y=typeof u[c+m]=="bigint"?u[c+m]:BigInt(Math.round(Number(u[c+m])));l[m]=p*y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[s+y]*p[c+y]}}else if(O(r.dtype)||O(t.dtype))for(let f=0;f<o;f++){let m=typeof a[s+f]=="bigint"?Number(a[s+f]):a[s+f],p=typeof u[c+f]=="bigint"?Number(u[c+f]):u[c+f];i[f]=m*p}else if(s===0&&c===0)for(let f=0;f<o;f++)i[f]=a[f]*u[f];else for(let f=0;f<o;f++)i[f]=a[s+f]*u[c+f];return n}function Yl(r,t){if(typeof t=="number")return aD(r,t);let e=B(r.dtype),n=B(t.dtype);if(e||n){let l=or(r.dtype,t.dtype),f=S.zeros(Array.from(r.shape),l),m=f.data,p=r.size,y=r.data,d=t.data,b=r.offset,A=t.offset;for(let g=0;g<p;g++){let[h,N]=e?Dr(y,b+g):[Number(y[b+g]),0],[D,x]=n?Dr(d,A+g):[Number(d[A+g]),0],C=D*D+x*x,w=(h*D+N*x)/C,_=(N*D-h*x)/C;br(m,g,w,_)}return f}let o=r.dtype==="float64",a=t.dtype==="float64",u=r.dtype==="float32",i=t.dtype==="float32";if(o||a){let l=o?r:pt(r,"float64"),f=a?t:pt(t,"float64");return sr(l,f,(m,p)=>m/p,"divide")}if(u||i){let l=u?r:pt(r,"float32"),f=i?t:pt(t,"float32");return sr(l,f,(m,p)=>m/p,"divide")}let s=pt(r,"float64"),c=pt(t,"float64");return sr(s,c,(l,f)=>l/f,"divide")}function pt(r,t){let e=S.zeros(Array.from(r.shape),t),n=r.size,o=e.data;if(r.isCContiguous){let a=r.data,u=r.offset;for(let i=0;i<n;i++)o[i]=Number(a[u+i])}else for(let a=0;a<n;a++)o[a]=Number(r.iget(a));return e}function Vl(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(B(e)){let l=o,f=c;if(i)for(let m=0;m<a;m++){let[p,y]=Dr(l,u+m);br(f,m,p+t,y)}else for(let m=0;m<a;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;br(f,m,y+t,d)}}else if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]+f}else for(let m=0;m<a;m++)l[m]=r.iget(m)+f}else if(i)if(u===0)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[u+l])+t;else for(let l=0;l<a;l++)c[l]=Number(r.iget(l))+t;return s}function Pl(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(B(e)){let l=o,f=c;if(i)for(let m=0;m<a;m++){let[p,y]=Dr(l,u+m);br(f,m,p-t,y)}else for(let m=0;m<a;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;br(f,m,y-t,d)}}else if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]-f}else for(let m=0;m<a;m++)l[m]=r.iget(m)-f}else if(i)for(let l=0;l<a;l++)c[l]=Number(o[u+l])-t;else for(let l=0;l<a;l++)c[l]=Number(r.iget(l))-t;return s}function jl(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(B(e)){let l=o,f=c;if(i)for(let m=0;m<a;m++){let[p,y]=Dr(l,u+m);br(f,m,p*t,y*t)}else for(let m=0;m<a;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;br(f,m,y*t,d*t)}}else if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]*f}else for(let m=0;m<a;m++)l[m]=r.iget(m)*f}else if(i)if(u===0)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[u+l])*t;else for(let l=0;l<a;l++)c[l]=Number(r.iget(l))*t;return s}function aD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous;if(B(e)){let m=S.zeros(n,e),p=m.data;if(i){let y=o;for(let d=0;d<a;d++){let[b,A]=Dr(y,u+d);br(p,d,b/t,A/t)}}else for(let y=0;y<a;y++){let d=r.iget(y),b=d.re??Number(d),A=d.im??0;br(p,y,b/t,A/t)}return m}let c=e!=="float32"&&e!=="float64"?"float64":e,l=S.zeros(n,c),f=l.data;if(i)for(let m=0;m<a;m++)f[m]=Number(o[u+m])/t;else for(let m=0;m<a;m++)f[m]=Number(r.iget(m))/t;return l}function Zl(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous;if(B(t)){let c=Rt(t),l=S.zeros(e,c),f=l.data;if(u){let m=n;for(let p=0;p<o;p++){let y=m[(a+p)*2],d=m[(a+p)*2+1];f[p]=Math.sqrt(y*y+d*d)}}else for(let m=0;m<o;m++){let p=r.iget(m),y=p.re??Number(p),d=p.im??0;f[m]=Math.sqrt(y*y+d*d)}return l}let i=S.zeros(e,t),s=i.data;if(O(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++){let m=l[a+f];c[f]=m<0n?-m:m}}else for(let l=0;l<o;l++){let f=r.iget(l);c[l]=f<0n?-f:f}}else if(u)if(a===0)for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[a+c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(r.iget(c)));return i}function Xl(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(B(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++){let[m,p]=Dr(l,a+f);br(c,f,-m,-p)}}else for(let l=0;l<o;l++){let f=r.iget(l),m=f.re??Number(f),p=f.im??0;br(c,l,-m,-p)}}else if(O(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++)c[f]=-l[a+f]}else for(let l=0;l<o;l++)c[l]=-r.iget(l)}else if(u)if(a===0)for(let c=0;c<o;c++)s[c]=-Number(n[c]);else for(let c=0;c<o;c++)s[c]=-Number(n[a+c]);else for(let c=0;c<o;c++)s[c]=-Number(r.iget(c));return i}function Jl(r){L(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=r.offset,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(O(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++){let m=l[a+f];c[f]=m>0n?1n:m<0n?-1n:0n}}else for(let l=0;l<o;l++){let f=r.iget(l);c[l]=f>0n?1n:f<0n?-1n:0n}}else if(u)for(let c=0;c<o;c++){let l=Number(n[a+c]);s[c]=l>0?1:l<0?-1:0}else for(let c=0;c<o;c++){let l=Number(r.iget(c));s[c]=l>0?1:l<0?-1:0}return i}function Zo(r,t){return L(r.dtype,"mod","Modulo is not defined for complex numbers."),typeof t!="number"&&L(t.dtype,"mod","Modulo is not defined for complex numbers."),typeof t=="number"?sD(r,t):sr(r,t,(e,n)=>(e%n+n)%n,"mod")}function sD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++){let y=m[u+p];l[p]=(y%f+f)%f}}else for(let m=0;m<a;m++){let p=r.iget(m);l[m]=(p%f+f)%f}}else if(i)for(let l=0;l<a;l++){let f=Number(o[u+l]);c[l]=(f%t+t)%t}else for(let l=0;l<a;l++){let f=Number(r.iget(l));c[l]=(f%t+t)%t}return s}function di(r,t){return L(r.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof t!="number"&&L(t.dtype,"floor_divide","Floor division is not defined for complex numbers."),typeof t=="number"?iD(r,t):sr(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function iD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;for(let p=0;p<a;p++)l[p]=m[u+p]/f}else for(let m=0;m<a;m++)l[m]=r.iget(m)/f}else if(i)for(let l=0;l<a;l++)c[l]=Math.floor(Number(o[u+l])/t);else for(let l=0;l<a;l++)c[l]=Math.floor(Number(r.iget(l))/t);return s}function Kl(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(B(t)){let c=s;if(u){let l=n;for(let f=0;f<o;f++)c[f*2]=l[(a+f)*2],c[f*2+1]=l[(a+f)*2+1]}else for(let l=0;l<o;l++){let f=r.iget(l);c[l*2]=f.re??Number(f),c[l*2+1]=f.im??0}}else if(u)for(let c=0;c<o;c++)s[c]=n[a+c];else for(let c=0;c<o;c++)s[c]=r.iget(c);return i}function Ql(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,u=r.isCContiguous;if(B(t)){let f=S.zeros(e,t),m=f.data;if(u){let p=n;for(let y=0;y<o;y++){let d=p[(a+y)*2],b=p[(a+y)*2+1],A=d*d+b*b;m[y*2]=d/A,m[y*2+1]=-b/A}}else for(let p=0;p<o;p++){let y=r.iget(p),d=y.re??Number(y),b=y.im??0,A=d*d+b*b;m[p*2]=d/A,m[p*2+1]=-b/A}return f}let s=t!=="float32"&&t!=="float64"?"float64":t,c=S.zeros(e,s),l=c.data;if(u)if(a===0)for(let f=0;f<o;f++)l[f]=1/Number(n[f]);else for(let f=0;f<o;f++)l[f]=1/Number(n[a+f]);else for(let f=0;f<o;f++)l[f]=1/Number(r.iget(f));return c}function Hl(r){let t=r.dtype;L(t,"cbrt","cbrt is not supported for complex numbers.");let e=Array.from(r.shape),n=r.data,o=r.size,a=r.offset,i=t!=="float32"&&t!=="float64"?"float64":t,s=S.zeros(e,i),c=s.data;if(r.isCContiguous)for(let l=0;l<o;l++)c[l]=Math.cbrt(Number(n[a+l]));else for(let l=0;l<o;l++)c[l]=Math.cbrt(Number(r.iget(l)));return s}function rf(r){let t=r.dtype;L(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=r.offset,u=t==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data;if(r.isCContiguous)if(a===0)for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(n[a+c]));else for(let c=0;c<o;c++)s[c]=Math.abs(Number(r.iget(c)));return i}function tf(r,t){let e=di(r,t),n=Zo(r,t);return[e,n]}function ef(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),u=a.data;if(B(t)){let i=n,s=u;for(let c=0;c<o;c++){let l=i[c*2],f=i[c*2+1];s[c*2]=l*l-f*f,s[c*2+1]=2*l*f}}else if(O(t)){let i=n,s=u;for(let c=0;c<o;c++)s[c]=i[c]*i[c]}else for(let i=0;i<o;i++){let s=Number(n[i]);u[i]=s*s}return a}function nf(r,t){return Zo(r,t)}function of(r,t){L(r.dtype,"heaviside","Heaviside step function is not defined for complex numbers."),typeof t!="number"&&L(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=S.zeros(n,a),i=u.data;if(typeof t=="number")for(let s=0;s<o;s++){let c=Number(r.iget(s));c<0?i[s]=0:c===0?i[s]=t:i[s]=1}else{let s=t.shape;if(n.every((c,l)=>c===s[l]))for(let c=0;c<o;c++){let l=Number(r.iget(c));l<0?i[c]=0:l===0?i[c]=Number(t.iget(c)):i[c]=1}else for(let c=0;c<o;c++){let l=Number(r.iget(c)),f=c%t.size;l<0?i[c]=0:l===0?i[c]=Number(t.iget(f)):i[c]=1}}return u}function af(r,t){let e=r.dtype;if(B(e)){let n=r.size,o=S.zeros(Array.from(r.shape),e),a=o.data;if(typeof t=="number")if(r.isCContiguous){let u=r.data,i=r.offset;for(let s=0;s<n;s++){let c=u[(i+s)*2],l=u[(i+s)*2+1],f=Math.hypot(c,l),m=Math.atan2(l,c),p=Math.pow(f,t),y=m*t;a[s*2]=p*Math.cos(y),a[s*2+1]=p*Math.sin(y)}}else for(let u=0;u<n;u++){let i=r.iget(u),s=Math.hypot(i.re,i.im),c=Math.atan2(i.im,i.re),l=Math.pow(s,t),f=c*t;a[u*2]=l*Math.cos(f),a[u*2+1]=l*Math.sin(f)}else{let u=B(t.dtype);if(r.isCContiguous&&t.isCContiguous){let i=r.data,s=r.offset,c=t.data,l=t.offset;for(let f=0;f<n;f++){let m=i[(s+f)*2],p=i[(s+f)*2+1],y,d;if(u){let C=c;y=C[(l+f)*2],d=C[(l+f)*2+1]}else y=Number(c[l+f]),d=0;let b=Math.hypot(m,p),A=Math.atan2(p,m),g=Math.log(b),h=A,N=y*g-d*h,D=y*h+d*g,x=Math.exp(N);a[f*2]=x*Math.cos(D),a[f*2+1]=x*Math.sin(D)}}else for(let i=0;i<n;i++){let s=r.iget(i),c,l;if(u){let g=t.iget(i);c=g.re,l=g.im}else c=Number(t.iget(i)),l=0;let f=Math.hypot(s.re,s.im),m=Math.atan2(s.im,s.re),p=Math.log(f),y=m,d=c*p-l*y,b=c*y+l*p,A=Math.exp(d);a[i*2]=A*Math.cos(b),a[i*2+1]=A*Math.sin(b)}}return o}if(typeof t=="number"){let n=S.zeros(Array.from(r.shape),"float64"),o=n.data,a=r.size;if(r.isCContiguous){let u=r.data,i=r.offset;for(let s=0;s<a;s++)o[s]=Math.pow(Number(u[i+s]),t)}else for(let u=0;u<a;u++)o[u]=Math.pow(Number(r.iget(u)),t);return n}return sr(r,t,(n,o)=>Math.pow(n,o),"float_power")}function sf(r,t){if(L(r.dtype,"fmod","fmod is not defined for complex numbers."),typeof t!="number"&&L(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 sr(r,t,(e,n)=>e-Math.trunc(e/n)*n,"fmod")}function uf(r){L(r.dtype,"frexp","frexp is not defined for complex numbers.");let t=S.zeros(Array.from(r.shape),"float64"),e=S.zeros(Array.from(r.shape),"int32"),n=t.data,o=e.data,a=r.size;for(let u=0;u<a;u++){let i=Number(r.iget(u));if(i===0||!isFinite(i))n[u]=i,o[u]=0;else{let s=Math.floor(Math.log2(Math.abs(i)))+1,c=i/Math.pow(2,s);n[u]=c,o[u]=s}}return[t,e]}function cf(r,t){L(r.dtype,"gcd","GCD is only defined for integers."),typeof t!="number"&&L(t.dtype,"gcd","GCD is only defined for integers.");let e=(i,s)=>{for(i=Math.abs(Math.trunc(i)),s=Math.abs(Math.trunc(s));s!==0;){let c=s;s=i%s,i=c}return i};if(typeof t=="number"){let i=S.zeros(Array.from(r.shape),"int32"),s=i.data,c=r.size,l=Math.abs(Math.trunc(t));if(r.isCContiguous){let f=r.data,m=r.offset;for(let p=0;p<c;p++)s[p]=e(Number(f[m+p]),l)}else for(let f=0;f<c;f++)s[f]=e(Number(r.iget(f)),l);return i}let n=sr(r,t,e,"gcd"),o=S.zeros(Array.from(n.shape),"int32"),a=o.data,u=n.size;if(n.isCContiguous){let i=n.data,s=n.offset;for(let c=0;c<u;c++)a[c]=Math.round(Number(i[s+c]))}else for(let i=0;i<u;i++)a[i]=Math.round(Number(n.iget(i)));return o}function lf(r,t){L(r.dtype,"lcm","LCM is only defined for integers."),typeof t!="number"&&L(t.dtype,"lcm","LCM is only defined for integers.");let e=(s,c)=>{for(s=Math.abs(Math.trunc(s)),c=Math.abs(Math.trunc(c));c!==0;){let l=c;c=s%c,s=l}return s},n=(s,c)=>(s=Math.abs(Math.trunc(s)),c=Math.abs(Math.trunc(c)),s===0||c===0?0:s*c/e(s,c));if(typeof t=="number"){let s=S.zeros(Array.from(r.shape),"int32"),c=s.data,l=r.size,f=Math.abs(Math.trunc(t));if(r.isCContiguous){let m=r.data,p=r.offset;for(let y=0;y<l;y++)c[y]=n(Number(m[p+y]),f)}else for(let m=0;m<l;m++)c[m]=n(Number(r.iget(m)),f);return s}let o=sr(r,t,n,"lcm"),a=S.zeros(Array.from(o.shape),"int32"),u=a.data,i=o.size;if(o.isCContiguous){let s=o.data,c=o.offset;for(let l=0;l<i;l++)u[l]=Math.round(Number(s[c+l]))}else for(let s=0;s<i;s++)u[s]=Math.round(Number(o.iget(s)));return a}function ff(r,t){if(L(r.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof t!="number"&&L(t.dtype,"ldexp","ldexp is not defined for complex numbers."),typeof t=="number"){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=Math.pow(2,t);for(let u=0;u<o;u++)n[u]=Number(r.iget(u))*a;return e}return sr(r,t,(e,n)=>e*Math.pow(2,n),"ldexp")}function mf(r){L(r.dtype,"modf","modf is not defined for complex numbers.");let t=S.zeros(Array.from(r.shape),"float64"),e=S.zeros(Array.from(r.shape),"float64"),n=t.data,o=e.data,a=r.size;for(let u=0;u<a;u++){let i=Number(r.iget(u)),s=Math.trunc(i);o[u]=s,n[u]=i-s}return[t,e]}function pf(r,t,e){L(r.dtype,"clip","clip is not supported for complex numbers.");let n=r.dtype,o=Array.from(r.shape),a=r.size,u=S.zeros(o,n),i=u.data,s=t===null||typeof t=="number",c=e===null||typeof e=="number",l=t===null?-1/0:typeof t=="number"?t:null,f=e===null?1/0:typeof e=="number"?e:null,m=r.isCContiguous,p=r.data,y=r.offset,d=!s&&t.isCContiguous,b=s?null:t.data,A=s?0:t.offset,g=s?0:t.size,h=!c&&e.isCContiguous,N=c?null:e.data,D=c?0:e.offset,x=c?0:e.size;if(O(n)){let C=i;if(m&&(s||d)&&(c||h)){let w=p,_=b,I=N;for(let v=0;v<a;v++){let T=w[y+v],E=s?l===-1/0?T:BigInt(Math.round(l)):_[A+v%g],$=c?f===1/0?T:BigInt(Math.round(f)):I[D+v%x];T<E&&(T=E),T>$&&(T=$),C[v]=T}}else for(let w=0;w<a;w++){let _=r.iget(w),I=s?l===-1/0?_:BigInt(Math.round(l)):t.iget(w%t.size),v=c?f===1/0?_:BigInt(Math.round(f)):e.iget(w%e.size);_<I&&(_=I),_>v&&(_=v),C[w]=_}}else if(m&&(s||d)&&(c||h))for(let C=0;C<a;C++){let w=Number(p[y+C]),_=s?l:Number(b[A+C%g]),I=c?f:Number(N[D+C%x]);w<_&&(w=_),w>I&&(w=I),i[C]=w}else for(let C=0;C<a;C++){let w=Number(r.iget(C)),_=s?l:Number(t.iget(C%t.size)),I=c?f:Number(e.iget(C%e.size));w<_&&(w=_),w>I&&(w=I),i[C]=w}return u}function yf(r,t){if(L(r.dtype,"maximum","maximum is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"maximum","maximum is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]>l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);u[s]=isNaN(c)||isNaN(t)?NaN:Math.max(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)||isNaN(n)?NaN:Math.max(e,n),"maximum")}function df(r,t){if(L(r.dtype,"minimum","minimum is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"minimum","minimum is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]<l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);u[s]=isNaN(c)||isNaN(t)?NaN:Math.min(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)||isNaN(n)?NaN:Math.min(e,n),"minimum")}function bf(r,t){if(L(r.dtype,"fmax","fmax is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"fmax","fmax is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]>l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);isNaN(c)?u[s]=t:isNaN(t)?u[s]=c:u[s]=Math.max(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)?n:isNaN(n)?e:Math.max(e,n),"fmax")}function Af(r,t){if(L(r.dtype,"fmin","fmin is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"fmin","fmin is not supported for complex numbers."),typeof t=="number"){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,e),u=a.data,i=r.data;if(O(e)){let s=u,c=i,l=BigInt(Math.round(t));for(let f=0;f<o;f++)s[f]=c[f]<l?c[f]:l}else for(let s=0;s<o;s++){let c=Number(i[s]);isNaN(c)?u[s]=t:isNaN(t)?u[s]=c:u[s]=Math.min(c,t)}return a}return sr(r,t,(e,n)=>isNaN(e)?n:isNaN(n)?e:Math.min(e,n),"fmin")}function gf(r,t=0,e,n){L(r.dtype,"nan_to_num","nan_to_num is not supported for complex numbers.");let o=r.dtype,a=Array.from(r.shape),u=r.size,i=e!==void 0?e:Number.MAX_VALUE,s=n!==void 0?n:-Number.MAX_VALUE,c=S.zeros(a,o),l=c.data,f=r.data;if(O(o)){let m=l,p=f;for(let y=0;y<u;y++)m[y]=p[y]}else for(let m=0;m<u;m++){let p=Number(f[m]);isNaN(p)?l[m]=t:p===1/0?l[m]=i:p===-1/0?l[m]=s:l[m]=p}return c}function hf(r,t,e,n,o){L(r.dtype,"interp","interp is not supported for complex numbers."),L(t.dtype,"interp","interp is not supported for complex numbers."),L(e.dtype,"interp","interp is not supported for complex numbers.");let a=Array.from(r.shape),u=r.size,i=S.zeros(a,"float64"),s=i.data,c=r.data,l=t.data,f=e.data,m=t.size,p=n!==void 0?n:Number(f[0]),y=o!==void 0?o:Number(f[m-1]);for(let d=0;d<u;d++){let b=Number(c[d]);if(b<=Number(l[0])){s[d]=p;continue}if(b>=Number(l[m-1])){s[d]=y;continue}let A=0,g=m-1;for(;g-A>1;){let w=Math.floor((A+g)/2);Number(l[w])<=b?A=w:g=w}let h=Number(l[A]),N=Number(l[g]),D=Number(f[A]),x=Number(f[g]),C=(b-h)/(N-h);s[d]=D+C*(x-D)}return i}function Nf(r,t=Math.PI,e=-1,n=2*Math.PI){L(r.dtype,"unwrap","unwrap is not supported for complex numbers.");let o=Array.from(r.shape),a=o.length;if(e<0&&(e+=a),e<0||e>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);if(a===1){let c=r.size,l=S.zeros(o,"float64"),f=l.data,m=r.data;if(c===0)return l;f[0]=Number(m[0]);let p=0;for(let y=1;y<c;y++){let d=Number(m[y-1]),b=Number(m[y]),A=b-d;A=(A+n/2)%n-n/2,A===-n/2&&b-d>0&&(A=n/2),Math.abs(A)>t&&(p-=Math.round((b-d-A)/n)*n),f[y]=b+p}return l}let u=S.zeros(o,"float64"),i=u.data,s=r.data;for(let c=0;c<r.size;c++)i[c]=Number(s[c]);if(a===2){let[c,l]=o;if(e===0)for(let f=0;f<l;f++){let m=0;for(let p=1;p<c;p++){let y=(p-1)*l+f,d=p*l+f,b=i[y],A=i[d],g=A-b;g=(g+n/2)%n-n/2,g===-n/2&&A-b>0&&(g=n/2),Math.abs(g)>t&&(m-=Math.round((A-b-g)/n)*n),i[d]=A+m}}else for(let f=0;f<c;f++){let m=0;for(let p=1;p<l;p++){let y=f*l+(p-1),d=f*l+p,b=i[y],A=i[d],g=A-b;g=(g+n/2)%n-n/2,g===-n/2&&A-b>0&&(g=n/2),Math.abs(g)>t&&(m-=Math.round((A-b-g)/n)*n),i[d]=A+m}}}return u}function Df(r){L(r.dtype,"sinc","sinc is not supported for complex numbers.");let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"float64"),o=n.data,a=r.data;for(let u=0;u<e;u++){let i=Number(a[u]);if(i===0)o[u]=1;else{let s=Math.PI*i;o[u]=Math.sin(s)/s}}return n}function xf(r){L(r.dtype,"i0","i0 is not supported for complex numbers.");let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"float64"),o=n.data,a=r.data;for(let u=0;u<e;u++){let i=Math.abs(Number(a[u]));o[u]=uD(i)}return n}function uD(r){let t=Math.abs(r);if(t<3.75){let e=r/3.75,n=e*e;return 1+n*(3.5156229+n*(3.0899424+n*(1.2067492+n*(.2659732+n*(.0360768+n*.0045813)))))}else{let e=3.75/t;return Math.exp(t)/Math.sqrt(t)*(.39894228+e*(.01328592+e*(.00225319+e*(-.00157565+e*(.00916281+e*(-.02057706+e*(.02635537+e*(-.01647633+e*.00392377))))))))}}function Cf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.sqrt(l*l+f*f),p=Math.sqrt((m+l)/2),y=(f>=0?1:-1)*Math.sqrt((m-l)/2);u[c*2]=p,u[c*2+1]=y}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.sqrt(c*c+l*l),m=Math.sqrt((f+c)/2),p=(l>=0?1:-1)*Math.sqrt((f-c)/2);u[i*2]=m,u[i*2+1]=p}return a}return ir(r,Math.sqrt,!1)}function Sf(r,t){if(typeof t=="number")return fD(r,t);let e=B(r.dtype),n=B(t.dtype);return e||n?lD(r,t):sr(r,t,Math.pow,"power")}function lD(r,t){let e=B(r.dtype),n=B(t.dtype),o=r.dtype==="complex128"||t.dtype==="complex128"||t.dtype==="float64"?"complex128":"complex64",a=Array.from(r.shape),u=r.size,i=S.zeros(a,o),s=i.data,c=r.isCContiguous,l=t.isCContiguous,f=r.offset,m=t.offset;for(let p=0;p<u;p++){let y,d;if(e)if(c){let w=r.data;y=w[(f+p)*2],d=w[(f+p)*2+1]}else{let w=r.iget(p);y=w.re,d=w.im}else y=Number(r.iget(p)),d=0;let b,A;if(n)if(l){let w=t.data;b=w[(m+p)*2],A=w[(m+p)*2+1]}else{let w=t.iget(p);b=w.re,A=w.im}else b=Number(t.iget(p)),A=0;let g=Math.sqrt(y*y+d*d),h=Math.atan2(d,y),N=Math.log(g),D=b*N-A*h,x=b*h+A*N,C=Math.exp(D);s[p*2]=C*Math.cos(x),s[p*2+1]=C*Math.sin(x)}return i}function fD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=r.offset,i=r.isCContiguous;if(B(e)){let p=S.zeros(n,e),y=p.data;if(i){let d=o;for(let b=0;b<a;b++){let A=d[(u+b)*2],g=d[(u+b)*2+1],h=Math.sqrt(A*A+g*g),N=Math.atan2(g,A),D=Math.pow(h,t),x=N*t;y[b*2]=D*Math.cos(x),y[b*2+1]=D*Math.sin(x)}}else for(let d=0;d<a;d++){let b=r.iget(d),A=b.re,g=b.im,h=Math.sqrt(A*A+g*g),N=Math.atan2(g,A),D=Math.pow(h,t),x=N*t;y[d*2]=D*Math.cos(x),y[d*2+1]=D*Math.sin(x)}return p}let l=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,f=S.zeros(n,l),m=f.data;if(O(e))if(O(l)&&Number.isInteger(t)&&t>=0)if(i){let p=o,y=m;for(let d=0;d<a;d++)y[d]=p[u+d]**BigInt(t)}else{let p=m;for(let y=0;y<a;y++)p[y]=r.iget(y)**BigInt(t)}else if(i)for(let p=0;p<a;p++)m[p]=Math.pow(Number(o[u+p]),t);else for(let p=0;p<a;p++)m[p]=Math.pow(Number(r.iget(p)),t);else if(i)for(let p=0;p<a;p++)m[p]=Math.pow(Number(o[u+p]),t);else for(let p=0;p<a;p++)m[p]=Math.pow(Number(r.iget(p)),t);return f}function wf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.exp(l);u[c*2]=m*Math.cos(f),u[c*2+1]=m*Math.sin(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.exp(c);u[i*2]=f*Math.cos(l),u[i*2+1]=f*Math.sin(l)}return a}return ir(r,Math.exp,!1)}function If(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=Math.LN2,u=S.zeros(e,t),i=u.data;if(o){let s=r.data,c=r.offset;for(let l=0;l<n;l++){let f=s[(c+l)*2],m=s[(c+l)*2+1],p=Math.exp(f*a),y=m*a;i[l*2]=p*Math.cos(y),i[l*2+1]=p*Math.sin(y)}}else for(let s=0;s<n;s++){let c=r.iget(s),l=c.re,f=c.im,m=Math.exp(l*a),p=f*a;i[s*2]=m*Math.cos(p),i[s*2+1]=m*Math.sin(p)}return u}return ir(r,e=>Math.pow(2,e),!1)}function zf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.exp(l);u[c*2]=m*Math.cos(f)-1,u[c*2+1]=m*Math.sin(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.exp(c);u[i*2]=f*Math.cos(l)-1,u[i*2+1]=f*Math.sin(l)}return a}return ir(r,Math.expm1,!1)}function _f(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.sqrt(l*l+f*f),p=Math.atan2(f,l);u[c*2]=Math.log(m),u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.sqrt(c*c+l*l),m=Math.atan2(l,c);u[i*2]=Math.log(f),u[i*2+1]=m}return a}return ir(r,Math.log,!1)}function vf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=1/Math.LN2,u=S.zeros(e,t),i=u.data;if(o){let s=r.data,c=r.offset;for(let l=0;l<n;l++){let f=s[(c+l)*2],m=s[(c+l)*2+1],p=Math.sqrt(f*f+m*m),y=Math.atan2(m,f);i[l*2]=Math.log(p)*a,i[l*2+1]=y*a}}else for(let s=0;s<n;s++){let c=r.iget(s),l=c.re,f=c.im,m=Math.sqrt(l*l+f*f),p=Math.atan2(f,l);i[s*2]=Math.log(m)*a,i[s*2+1]=p*a}return u}return ir(r,Math.log2,!1)}function Mf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=1/Math.LN10,u=S.zeros(e,t),i=u.data;if(o){let s=r.data,c=r.offset;for(let l=0;l<n;l++){let f=s[(c+l)*2],m=s[(c+l)*2+1],p=Math.sqrt(f*f+m*m),y=Math.atan2(m,f);i[l*2]=Math.log(p)*a,i[l*2+1]=y*a}}else for(let s=0;s<n;s++){let c=r.iget(s),l=c.re,f=c.im,m=Math.sqrt(l*l+f*f),p=Math.atan2(f,l);i[s*2]=Math.log(m)*a,i[s*2+1]=p*a}return u}return ir(r,Math.log10,!1)}function Ff(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=1+l,p=Math.sqrt(m*m+f*f),y=Math.atan2(f,m);u[c*2]=Math.log(p),u[c*2+1]=y}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=1+c,m=Math.sqrt(f*f+l*l),p=Math.atan2(l,f);u[i*2]=Math.log(m),u[i*2+1]=p}return a}return ir(r,Math.log1p,!1)}function Bf(r,t){return L(r.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"logaddexp","logaddexp is not supported for complex numbers."),typeof t=="number"?pD(r,t):mD(r,t)}function mD(r,t){let e=Zr(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",i=S.zeros(e,u),s=i.data;for(let c=0;c<n;c++){let l=(O(o),Number(r.iget(c))),f=(O(a),Number(t.iget(c))),m=Math.max(l,f),p=Math.min(l,f);s[c]=m+Math.log1p(Math.exp(p-m))}return i}function pD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=r.isCContiguous,u=e==="float32"?"float32":"float64",i=S.zeros(n,u),s=i.data;if(a){let c=r.offset;for(let l=0;l<o;l++){let f=Number(r.data[c+l]),m=Math.max(f,t),p=Math.min(f,t);s[l]=m+Math.log1p(Math.exp(p-m))}}else for(let c=0;c<o;c++){let l=Number(r.iget(c)),f=Math.max(l,t),m=Math.min(l,t);s[c]=f+Math.log1p(Math.exp(m-f))}return i}function Tf(r,t){return L(r.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof t!="number"&&L(t.dtype,"logaddexp2","logaddexp2 is not supported for complex numbers."),typeof t=="number"?dD(r,t):yD(r,t)}function yD(r,t){let e=Zr(r.shape,t.shape),n=e.reduce((l,f)=>l*f,1),o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data,c=Math.LOG2E;for(let l=0;l<n;l++){let f=(O(o),Number(r.iget(l))),m=(O(a),Number(t.iget(l))),p=Math.max(f,m),y=Math.min(f,m);s[l]=p+Math.log1p(Math.pow(2,y-p))*c}return i}function dD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=r.isCContiguous,u=e==="float32"?"float32":"float64",i=S.zeros(n,u),s=i.data,c=Math.LOG2E;if(a){let l=r.offset;for(let f=0;f<o;f++){let m=Number(r.data[l+f]),p=Math.max(m,t),y=Math.min(m,t);s[f]=p+Math.log1p(Math.pow(2,y-p))*c}}else for(let l=0;l<o;l++){let f=Number(r.iget(l)),m=Math.max(f,t),p=Math.min(f,t);s[l]=m+Math.log1p(Math.pow(2,p-m))*c}return i}function Pt(r,t){let e=typeof t=="number"?t:z(t);return M(Ll(z(r),e))}function jt(r,t){let e=typeof t=="number"?t:z(t);return M(Wl(z(r),e))}function Lt(r,t){let e=typeof t=="number"?t:z(t);return M(Gl(z(r),e))}function Wt(r){return M(Cf(z(r)))}function Gt(r,t){let e=typeof t=="number"?t:z(t);return M(Sf(z(r),e))}function Yt(r){return M(wf(z(r)))}function Zt(r){return M(If(z(r)))}function Xt(r){return M(zf(z(r)))}function Jt(r){return M(_f(z(r)))}function Kt(r){return M(vf(z(r)))}function Qt(r){return M(Mf(z(r)))}function Ht(r){return M(Ff(z(r)))}function re(r,t){let e=typeof t=="number"?t:z(t);return M(Bf(z(r),e))}function te(r,t){let e=typeof t=="number"?t:z(t);return M(Tf(z(r),e))}function ee(r){return M(Zl(z(r)))}function ne(r){return M(Xl(z(r)))}function oe(r){return M(Jl(z(r)))}function ae(r,t){let e=typeof t=="number"?t:z(t);return M(Zo(z(r),e))}function yt(r,t){let e=typeof t=="number"?t:z(t);return M(Yl(z(r),e))}var Xo=yt;function se(r,t){let e=typeof t=="number"?t:z(t);return M(di(z(r),e))}function ie(r){return M(Kl(z(r)))}function ue(r){return M(Ql(z(r)))}function ce(r){return M(Hl(z(r)))}function le(r){return M(rf(z(r)))}function fe(r,t){let e=typeof t=="number"?t:z(t);return Vo(tf(z(r),e))}function me(r){return M(ef(z(r)))}function pe(r,t){let e=typeof t=="number"?t:z(t);return M(nf(z(r),e))}function ye(r,t){let e=typeof t=="number"?t:z(t);return M(of(z(r),e))}function bi(r,t){let e=typeof t=="number"?t:z(t);return M(af(z(r),e))}function Ai(r,t){let e=typeof t=="number"?t:z(t);return M(sf(z(r),e))}function gi(r){return Vo(uf(z(r)))}function hi(r,t){let e=typeof t=="number"?t:z(t);return M(cf(z(r),e))}function Ni(r,t){let e=typeof t=="number"?t:z(t);return M(lf(z(r),e))}function Di(r,t){let e=typeof t=="number"?t:z(t);return M(ff(z(r),e))}function xi(r){return Vo(mf(z(r)))}function de(r,t,e){let n=t===null?null:typeof t=="number"?t:z(t),o=e===null?null:typeof e=="number"?e:z(e);return M(pf(z(r),n,o))}function Ci(r,t){let e=typeof t=="number"?t:z(t);return M(yf(z(r),e))}function Si(r,t){let e=typeof t=="number"?t:z(t);return M(df(z(r),e))}function wi(r,t){let e=typeof t=="number"?t:z(t);return M(bf(z(r),e))}function Ii(r,t){let e=typeof t=="number"?t:z(t);return M(Af(z(r),e))}function zi(r,t=0,e,n){return M(gf(z(r),t,e,n))}function _i(r,t,e,n,o){return M(hf(z(r),z(t),z(e),n,o))}function vi(r,t=Math.PI,e=-1,n=2*Math.PI){return M(Nf(z(r),t,e,n))}function Mi(r){return M(Df(z(r)))}function Fi(r){return M(xf(z(r)))}function $f(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1];u[c*2]=Math.sin(l)*Math.cosh(f),u[c*2+1]=Math.cos(l)*Math.sinh(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im;u[i*2]=Math.sin(c)*Math.cosh(l),u[i*2+1]=Math.cos(c)*Math.sinh(l)}return a}return ir(r,Math.sin,!1)}function kf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1];u[c*2]=Math.cos(l)*Math.cosh(f),u[c*2+1]=-Math.sin(l)*Math.sinh(f)}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im;u[i*2]=Math.cos(c)*Math.cosh(l),u[i*2+1]=-Math.sin(c)*Math.sinh(l)}return a}return ir(r,Math.cos,!1)}function Rf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],m=Math.cos(2*l)+Math.cosh(2*f);u[c*2]=Math.sin(2*l)/m,u[c*2+1]=Math.sinh(2*f)/m}}else for(let i=0;i<n;i++){let s=r.iget(i),c=s.re,l=s.im,f=Math.cos(2*c)+Math.cosh(2*l);u[i*2]=Math.sin(2*c)/f,u[i*2+1]=Math.sinh(2*l)/f}return a}return ir(r,Math.tan,!1)}function qf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],[m,p]=Of(l,f);u[c*2]=m,u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),[c,l]=Of(s.re,s.im);u[i*2]=c,u[i*2+1]=l}return a}return ir(r,Math.asin,!1)}function Of(r,t){let e=-t,n=r,o=r*r-t*t,a=2*r*t,u=1-o,i=-a,s=Math.sqrt(u*u+i*i),c=Math.sqrt((s+u)/2),l=(i>=0?1:-1)*Math.sqrt((s-u)/2),f=e+c,m=n+l,p=Math.sqrt(f*f+m*m),y=Math.log(p),b=Math.atan2(m,f),A=-y;return Math.abs(t)<1e-15&&r>1&&(A=-A),[b,A]}function Vf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],[m,p]=Ef(l,f);u[c*2]=m,u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),[c,l]=Ef(s.re,s.im);u[i*2]=c,u[i*2+1]=l}return a}return ir(r,Math.acos,!1)}function Ef(r,t){let e=r*r-t*t,n=2*r*t,o=1-e,a=-n,u=Math.sqrt(o*o+a*a),i=Math.sqrt((u+o)/2),c=-((a>=0?1:-1)*Math.sqrt((u-o)/2)),l=i,f=r+c,m=t+l,p=Math.sqrt(f*f+m*m),y=Math.log(p),b=Math.atan2(m,f),A=-y;return Math.abs(t)<1e-15&&r>1&&(A=-A),[b,A]}function Pf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.isCContiguous,a=S.zeros(e,t),u=a.data;if(o){let i=r.data,s=r.offset;for(let c=0;c<n;c++){let l=i[(s+c)*2],f=i[(s+c)*2+1],[m,p]=Uf(l,f);u[c*2]=m,u[c*2+1]=p}}else for(let i=0;i<n;i++){let s=r.iget(i),[c,l]=Uf(s.re,s.im);u[i*2]=c,u[i*2+1]=l}return a}return ir(r,Math.atan,!1)}function Uf(r,t){let e=-t,n=r,o=1-e,a=-n,u=1+e,i=n,s=u*u+i*i,c=(o*u+a*i)/s,l=(a*u-o*i)/s,f=Math.sqrt(c*c+l*l),m=Math.log(f);return[-Math.atan2(l,c)/2,m/2]}function jf(r,t){return L(r.dtype,"arctan2","arctan2 is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"arctan2","arctan2 is only defined for real numbers."),typeof t=="number"?gD(r,t):AD(r,t)}function AD(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data,c=r.isCContiguous,l=t.isCContiguous;if(c&&l){let f=r.offset,m=t.offset;for(let p=0;p<n;p++){let y=Number(r.data[f+p]),d=Number(t.data[m+p]);s[p]=Math.atan2(y,d)}}else if(c){let f=r.offset;for(let m=0;m<n;m++){let p=Number(r.data[f+m]),y=Number(t.iget(m));s[m]=Math.atan2(p,y)}}else if(l){let f=t.offset;for(let m=0;m<n;m++){let p=Number(r.iget(m)),y=Number(t.data[f+m]);s[m]=Math.atan2(p,y)}}else for(let f=0;f<n;f++){let m=Number(r.iget(f)),p=Number(t.iget(f));s[f]=Math.atan2(m,p)}return i}function gD(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=S.zeros(n,a),i=u.data;if(r.isCContiguous){let c=r.data,l=r.offset;if(O(e))for(let f=0;f<o;f++)i[f]=Math.atan2(Number(c[l+f]),t);else for(let f=0;f<o;f++)i[f]=Math.atan2(Number(c[l+f]),t)}else for(let c=0;c<o;c++)i[c]=Math.atan2(Number(r.iget(c)),t);return u}function Lf(r,t){return L(r.dtype,"hypot","hypot is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"hypot","hypot is only defined for real numbers."),typeof t=="number"?ND(r,t):hD(r,t)}function hD(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",i=S.zeros(e,u),s=i.data,c=r.isCContiguous,l=t.isCContiguous;if(c&&l){let f=r.offset,m=t.offset;for(let p=0;p<n;p++){let y=Number(r.data[f+p]),d=Number(t.data[m+p]);s[p]=Math.hypot(y,d)}}else if(c){let f=r.offset;for(let m=0;m<n;m++){let p=Number(r.data[f+m]),y=Number(t.iget(m));s[m]=Math.hypot(p,y)}}else if(l){let f=t.offset;for(let m=0;m<n;m++){let p=Number(r.iget(m)),y=Number(t.data[f+m]);s[m]=Math.hypot(p,y)}}else for(let f=0;f<n;f++){let m=Number(r.iget(f)),p=Number(t.iget(f));s[f]=Math.hypot(m,p)}return i}function ND(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=S.zeros(n,a),i=u.data;if(r.isCContiguous){let c=r.data,l=r.offset;if(O(e))for(let f=0;f<o;f++)i[f]=Math.hypot(Number(c[l+f]),t);else for(let f=0;f<o;f++)i[f]=Math.hypot(Number(c[l+f]),t)}else for(let c=0;c<o;c++)i[c]=Math.hypot(Number(r.iget(c)),t);return u}function Bi(r){L(r.dtype,"degrees","degrees is only defined for real numbers.");let t=180/Math.PI;return ir(r,e=>e*t,!1)}function Ti(r){L(r.dtype,"radians","radians is only defined for real numbers.");let t=Math.PI/180;return ir(r,e=>e*t,!1)}function Wf(r){return Ti(r)}function Gf(r){return Bi(r)}function Yf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1];u[i*2]=Math.sinh(s)*Math.cos(c),u[i*2+1]=Math.cosh(s)*Math.sin(c)}return a}return ir(r,Math.sinh,!1)}function Zf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1];u[i*2]=Math.cosh(s)*Math.cos(c),u[i*2+1]=Math.sinh(s)*Math.sin(c)}return a}return ir(r,Math.cosh,!1)}function Xf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=Math.cosh(2*s)+Math.cos(2*c);u[i*2]=Math.sinh(2*s)/l,u[i*2+1]=Math.sin(2*c)/l}return a}return ir(r,Math.tanh,!1)}function Jf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=s*s-c*c,f=2*s*c,m=l+1,p=f,y=Math.sqrt(m*m+p*p),d=Math.sqrt((y+m)/2),b=(p>=0?1:-1)*Math.sqrt((y-m)/2),A=s+d,g=c+b,h=Math.sqrt(A*A+g*g);u[i*2]=Math.log(h),u[i*2+1]=Math.atan2(g,A)}return a}return ir(r,Math.asinh,!1)}function Kf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=s*s-c*c,f=2*s*c,m=l-1,p=f,y=Math.sqrt(m*m+p*p),d=Math.sqrt((y+m)/2),b=(p>=0?1:-1)*Math.sqrt((y-m)/2),A=s+d,g=c+b,h=Math.sqrt(A*A+g*g),N=Math.log(h),D=Math.atan2(g,A);Math.abs(c)<1e-15&&s<1&&(D=-D),u[i*2]=N,u[i*2+1]=D}return a}return ir(r,Math.acosh,!1)}function Qf(r){let t=r.dtype;if(B(t)){let e=Array.from(r.shape),n=r.size,o=r.data,a=S.zeros(e,t),u=a.data;for(let i=0;i<n;i++){let s=o[i*2],c=o[i*2+1],l=1+s,f=c,m=1-s,p=-c,y=m*m+p*p,d=(l*m+f*p)/y,b=(f*m-l*p)/y,A=Math.sqrt(d*d+b*b),g=Math.log(A),h=Math.atan2(b,d);u[i*2]=g/2,u[i*2+1]=h/2}return a}return ir(r,Math.atanh,!1)}function be(r){return M($f(z(r)))}function Ae(r){return M(kf(z(r)))}function ge(r){return M(Rf(z(r)))}function he(r){return M(qf(z(r)))}function Ne(r){return M(Vf(z(r)))}function De(r){return M(Pf(z(r)))}function xe(r,t){let e=typeof t=="number"?t:z(t);return M(jf(z(r),e))}function Ce(r,t){let e=typeof t=="number"?t:z(t);return M(Lf(z(r),e))}function Se(r){return M(Bi(z(r)))}function we(r){return M(Ti(z(r)))}function Oi(r){return M(Wf(z(r)))}function Ei(r){return M(Gf(z(r)))}function Ie(r){return M(Yf(z(r)))}function ze(r){return M(Zf(z(r)))}function _e(r){return M(Xf(z(r)))}function ve(r){return M(Jf(z(r)))}function Me(r){return M(Kf(z(r)))}function Fe(r){return M(Qf(z(r)))}function cr(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((f,m,p)=>p===o?f:f*m,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((f,m)=>m===o?l:f)}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 S.fromData(c,a,n,lr(a),0)}let s=r.copy().data;return S.fromData(s,a,n,lr(a),0)}function Hr(r){let t=r.size,e=r.dtype,n=K(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let i=r.data.slice(r.offset,r.offset+t);return S.fromData(i,[t],e,[1],0)}let o=new n(t),a=O(e);for(let u=0;u<t;u++){let i=r.iget(u);o[u]=i}return S.fromData(o,[t],e,[1],0)}function dt(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return S.fromData(n,[t],e,[1],0)}return Hr(r)}function Ui(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype,i;if(t===void 0)i=Array.from({length:n},(f,m)=>n-1-m);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let f=new Set;for(let m of t){let p=m<0?n+m:m;if(p<0||p>=n)throw new Error(`axis ${m} is out of bounds for array of dimension ${n}`);if(f.has(p))throw new Error("repeated axis in transpose");f.add(p)}i=t.map(m=>m<0?n+m:m)}let s=i.map(f=>e[f]),c=Array.from(o),l=i.map(f=>c[f]);return S.fromData(a,s,u,l,r.offset)}function $i(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype;if(t===void 0){let i=[],s=[];for(let c=0;c<n;c++)e[c]!==1&&(i.push(e[c]),s.push(o[c]));return i.length===0&&(i.push(1),s.push(1)),S.fromData(a,i,u,s,r.offset)}else{let i=t<0?n+t:t;if(i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[i]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[i]})`);let s=[],c=[];for(let l=0;l<n;l++)l!==i&&(s.push(e[l]),c.push(o[l]));return S.fromData(a,s,u,c,r.offset)}}function Be(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,u=r.dtype,i=t;if(i<0&&(i=n+t+1),i<0||i>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let s=[...Array.from(e)];s.splice(i,0,1);let c=[...Array.from(o)],l=i<n?o[i]*(e[i]||1):1;return c.splice(i,0,l),S.fromData(a,s,u,c,r.offset)}function Hf(r,t,e){let n=r.shape,o=n.length,a=r.strides,u=r.data,i=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 S.fromData(u,Array.from(n),i,Array.from(a),r.offset);let l=Array.from(n),f=Array.from(a);return[l[s],l[c]]=[l[c],l[s]],[f[s],f[c]]=[f[c],f[s]],S.fromData(u,l,i,f,r.offset)}function ki(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}),i=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(i).size!==i.length)throw new Error("repeated axis in destination");let s=[];for(let c=0;c<n;c++)u.includes(c)||s.push(c);for(let c=0;c<u.length;c++){let l=i[c];s.splice(l,0,u[c])}return Ui(r,s)}function Xr(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 u=Array.from(e.shape),i=e.shape[a];for(let p=1;p<r.length;p++)i+=r[p].shape[a];u[a]=i;let s=u.reduce((p,y)=>p*y,1),c=K(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(s),f=lr(u),m=0;for(let p of r){let y=p.shape[a];CD(p,l,u,f,a,m,o),m+=y}return S.fromData(l,u,o)}function CD(r,t,e,n,o,a,u){let i=r.shape,s=i.length,c=r.size,l=u==="int64"||u==="uint64";if(o===0&&r.isCContiguous&&s>0){let p=a*n[0],y=r.data,d=r.offset,b=d+c;t.set(y.subarray(d,b),p);return}if(o===1&&s===2&&r.isCContiguous){let p=i[0],y=i[1],d=e[1],b=r.data,A=r.offset;for(let g=0;g<p;g++){let h=A+g*y,N=g*d+a;t.set(b.subarray(h,h+y),N)}return}let f=new Array(s).fill(0),m=a*n[o];for(let p=0;p<c;p++){let y=r.iget(p),d=m;for(let b=0;b<s;b++)d+=f[b]*n[b];t[d]=y;for(let b=s-1;b>=0&&(f[b]++,!(f[b]<i[b]));b--)f[b]=0}}function rm(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 i=1;i<r.length;i++){let s=r[i];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 u=r.map(i=>Be(i,a));return Xr(u,a)}function tm(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?cr(e,[1,e.shape[0]]):e);return Xr(t,0)}function Ri(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?Xr(r,0):Xr(r,1)}function em(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?cr(Be(cr(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?Be(e,2):e);return Xr(t,2)}function nm(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],i;if(typeof t=="number"){if(u%t!==0)throw new Error("array split does not result in an equal division");let s=u/t;i=[];for(let c=1;c<t;c++)i.push(c*s)}else i=t;return om(r,i,a)}function Te(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],i;if(typeof t=="number"){let s=t,c=Math.floor(u/s),l=u%s;i=[];let f=0;for(let m=0;m<s-1;m++)f+=c+(m<l?1:0),i.push(f)}else i=t;return om(r,i,a)}function om(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],u=[];for(let i=0;i<a.length-1;i++){let s=a[i],c=a[i+1];if(s>c)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=c-s;let f=r.offset+s*r.strides[e];u.push(S.fromData(r.data,l,r.dtype,Array.from(r.strides),f))}return u}function am(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return Te(r,t,0)}function sm(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 Te(r,t,e)}function im(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],u=Math.max(n,a.length),i=new Array(u).fill(1),s=new Array(u).fill(1);for(let g=0;g<n;g++)i[u-n+g]=e[g];for(let g=0;g<a.length;g++)s[u-a.length+g]=a[g];let c=i.map((g,h)=>g*s[h]),l=c.reduce((g,h)=>g*h,1),f=K(o);if(!f)throw new Error(`Cannot tile array with dtype ${o}`);let m=new f(l),p=lr(c),y=r;n<u&&(y=cr(r,i));let d=o==="int64"||o==="uint64",b=y.strides,A=new Array(u).fill(0);for(let g=0;g<l;g++){let h=y.offset;for(let x=0;x<u;x++){let C=A[x]%i[x];h+=C*b[x]}let N=y.data[h],D=0;for(let x=0;x<u;x++)D+=A[x]*p[x];m[D]=N;for(let x=u-1;x>=0&&(A[x]++,!(A[x]<c[x]));x--)A[x]=0}return S.fromData(m,c,o)}function um(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=r.size;if(e===void 0){let g=u,h=Array.isArray(t)?t:new Array(g).fill(t);if(h.length!==g)throw new Error(`operands could not be broadcast together with shape (${g},) (${h.length},)`);let N=h.reduce((w,_)=>w+_,0),D=K(a);if(!D)throw new Error(`Cannot repeat array with dtype ${a}`);let x=new D(N),C=0;for(let w=0;w<g;w++){let _=r.iget(w),I=h[w];for(let v=0;v<I;v++)x[C++]=_}return S.fromData(x,[N],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 s=n[i],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[i]=c.reduce((g,h)=>g+h,0);let f=l.reduce((g,h)=>g*h,1),m=K(a);if(!m)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new m(f),y=lr(l),d=new Array(o).fill(0),b=a==="int64"||a==="uint64",A=[0];for(let g=0;g<s;g++)A.push(A[g]+c[g]);for(let g=0;g<u;g++){let h=r.iget(g),N=d[i],D=c[N],x=0;for(let _=0;_<o;_++)_!==i&&(x+=d[_]*y[_]);let C=y[i],w=A[N];for(let _=0;_<D;_++){let I=x+(w+_)*C;p[I]=h}for(let _=o-1;_>=0&&(d[_]++,!(d[_]<n[_]));_--)d[_]=0}return S.fromData(p,l,a)}function cm(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},(m,p)=>p));else if(typeof t=="number"){let m=t<0?n+t:t;if(m<0||m>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);u=new Set([m])}else u=new Set(t.map(m=>{let p=m<0?n+m:m;if(p<0||p>=n)throw new Error(`axis ${m} is out of bounds for array of dimension ${n}`);return p}));let i=K(o);if(!i)throw new Error(`Cannot flip array with dtype ${o}`);let s=new i(a),c=O(o);if(n===1&&r.isCContiguous){let m=r.data,p=r.offset;for(let y=0;y<a;y++)s[y]=m[p+a-1-y];return S.fromData(s,[...e],o)}if(n===2&&r.isCContiguous){let m=e[0],p=e[1],y=r.data,d=r.offset;if(u.size===2){for(let b=0;b<a;b++)s[b]=y[d+a-1-b];return S.fromData(s,[...e],o)}if(u.size===1){if(u.has(0)){for(let b=0;b<m;b++){let A=d+(m-1-b)*p,g=b*p;for(let h=0;h<p;h++)s[g+h]=y[A+h]}return S.fromData(s,[...e],o)}else if(u.has(1)){for(let b=0;b<m;b++){let A=d+b*p,g=b*p;for(let h=0;h<p;h++)s[g+h]=y[A+p-1-h]}return S.fromData(s,[...e],o)}}}let l=new Array(n),f=new Array(n).fill(0);for(let m=0;m<a;m++){for(let d=0;d<n;d++)l[d]=u.has(d)?e[d]-1-f[d]:f[d];let p=r.offset;for(let d=0;d<n;d++)p+=l[d]*r.strides[d];let y=r.data[p];s[m]=y;for(let d=n-1;d>=0&&(f[d]++,!(f[d]<e[d]));d--)f[d]=0}return S.fromData(s,[...e],o)}function lm(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],i=e[1]<0?o+e[1]:e[1];if(u<0||u>=o||i<0||i>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(u===i)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let s=K(a);if(!s)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[u],c[i]]=[c[i],c[u]]);let l=c.reduce((g,h)=>g*h,1),f=new s(l),m=O(a),p=r.data;if(o===2&&u===0&&i===1){let g=n[0],h=n[1];if(t===1){let N=h,D=g;if(m){let x=p,C=f;for(let w=0;w<N;w++){let _=w*D,I=h-1-w;for(let v=0;v<D;v++)C[_+v]=x[v*h+I]}}else{let x=p,C=f;for(let w=0;w<N;w++){let _=w*D,I=h-1-w;for(let v=0;v<D;v++)C[_+v]=x[v*h+I]}}}else if(t===2)if(m){let N=p,D=f;for(let x=0;x<g;x++){let C=x*h,w=(g-1-x)*h;for(let _=0;_<h;_++)D[C+_]=N[w+(h-1-_)]}}else{let N=p,D=f;for(let x=0;x<g;x++){let C=x*h,w=(g-1-x)*h;for(let _=0;_<h;_++)D[C+_]=N[w+(h-1-_)]}}else{let N=h,D=g;if(m){let x=p,C=f;for(let w=0;w<N;w++){let _=w*D;for(let I=0;I<D;I++)C[_+I]=x[(g-1-I)*h+w]}}else{let x=p,C=f;for(let w=0;w<N;w++){let _=w*D;for(let I=0;I<D;I++)C[_+I]=x[(g-1-I)*h+w]}}}return S.fromData(f,c,a)}let y=lr(c),d=lr(n),b=new Array(o).fill(0),A=new Array(o);for(let g=0;g<r.size;g++){for(let C=0;C<o;C++)A[C]=b[C];let h,N;t===1?(h=n[i]-1-b[i],N=b[u]):t===2?(h=n[u]-1-b[u],N=n[i]-1-b[i],A[u]=h,A[i]=N):(h=b[i],N=n[u]-1-b[u]),t!==2&&(A[u]=h,A[i]=N);let D=0;for(let C=0;C<o;C++)D+=A[C]*y[C];let x=0;for(let C=0;C<o;C++)x+=b[C]*d[C];if(m){let C=p,w=f;w[D]=C[x]}else{let C=p,w=f;w[D]=C[x]}for(let C=o-1;C>=0&&(b[C]++,!(b[C]<n[C]));C--)b[C]=0}return S.fromData(f,c,a)}function fm(r,t,e){let n=r.shape,o=n.length,a=r.dtype,u=r.size;if(e===void 0){let y=Array.isArray(t)?t.reduce((h,N)=>h+N,0):t,d=Hr(r),b=K(a);if(!b)throw new Error(`Cannot roll array with dtype ${a}`);let A=new b(u),g=O(a);for(let h=0;h<u;h++){let N=((h-y)%u+u)%u,D=d.iget(N);A[h]=D}return S.fromData(A,[...n],a)}let i=Array.isArray(t)?t:[t],s=Array.isArray(e)?e:[e];if(i.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=K(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let f=new l(u),m=O(a),p=new Array(o).fill(0);for(let y=0;y<u;y++){let d=[...p];for(let g=0;g<c.length;g++){let h=c[g],N=n[h],D=i[g];d[h]=((d[h]-D)%N+N)%N}let b=r.offset;for(let g=0;g<o;g++)b+=d[g]*r.strides[g];let A=r.data[b];f[y]=A;for(let g=o-1;g>=0&&(p[g]++,!(p[g]<n[g]));g--)p[g]=0}return S.fromData(f,[...n],a)}function mm(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?S.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):ki(r,o,a)}function pm(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return Te(r,t,2)}function ym(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?cr(e,[e.shape[0],1]):e);return Ri(t)}function dm(r,t){let e=r.dtype,n=t.reduce((s,c)=>s*c,1),o=r.size,a=K(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let u=new a(n),i=O(e);for(let s=0;s<n;s++){let c=s%o,l=r.iget(c);u[s]=l}return S.fromData(u,t,e)}function bm(r){return r.map(t=>t.ndim===0?cr(t,[1]):t)}function Am(r){return r.map(t=>t.ndim===0?cr(t,[1,1]):t.ndim===1?cr(t,[1,t.shape[0]]):t)}function gm(r){return r.map(t=>t.ndim===0?cr(t,[1,1,1]):t.ndim===1?cr(t,[1,t.shape[0],1]):t.ndim===2?cr(t,[t.shape[0],t.shape[1],1]):t)}function hm(r,t=0){let e=r.shape,n=e.length,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[o],u=[];for(let i=0;i<a;i++){let s=[];for(let f=0;f<n;f++)f===o?s.push({start:i,stop:i+1,step:1}):s.push({start:0,stop:e[f],step:1});let c=SD(r,s),l=$i(c,o);u.push(l)}return u}function Nm(r,t=1){if(r.length===0)throw new Error("need at least one array to block");return r.length===1?r[0].copy():Xr(r,-1)}function SD(r,t){let e=r.shape,n=r.strides,o=r.offset,a=r.dtype,u=r.data,i=[],s=[];for(let c=0;c<e.length;c++){let l=t[c],{start:f,stop:m,step:p}=l,y=Math.ceil((m-f)/p);i.push(y),s.push(n[c]*p),o+=f*n[c]}return S.fromData(u,i,a,s,o)}function kr(r,t){if(r instanceof U||t instanceof U){let e=r instanceof U?r:new U(Number(r),0),n=t instanceof U?t:new U(Number(t),0);return e.mul(n)}return typeof r=="bigint"&&typeof t=="bigint"?Number(r*t):Number(r)*Number(t)}function wD(r,t,e,n,o,a,u,i,s){for(let c=0;c<e;c++)for(let l=0;l<a;l++)for(let f=0;f<u;f++){let m=0;for(let p=0;p<i;p++)m+=r[t+c*i+p]*n[o+l*i*u+p*u+f];s[c*a*u+l*u+f]=m}}function ID(r,t,e,n,o,a,u,i,s,c){for(let l=0;l<e;l++)for(let f=0;f<u;f++){let m=0;for(let p=0;p<s;p++){let y=n===1?p:l*s+p,d=i===1?p:f*s+p;m+=r[t+y]*o[a+d]}c[e===1?f:l*u+f]=m}}function zD(r,t,e,n,o,a,u,i,s,c,l,f){for(let y=0;y<e*n;y++)l[y]=0;let m=r==="transpose",p=t==="transpose";if(!m&&!p)for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[y*i+A]??0)*(s[A*c+d]??0);l[y*f+d]=a*b}else if(m&&!p)for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[A*i+y]??0)*(s[A*c+d]??0);l[y*f+d]=a*b}else if(!m&&p)for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[y*i+A]??0)*(s[d*c+A]??0);l[y*f+d]=a*b}else for(let y=0;y<e;y++)for(let d=0;d<n;d++){let b=0;for(let A=0;A<o;A++)b+=(u[A*i+y]??0)*(s[d*c+A]??0);l[y*f+d]=a*b}}function At(r,t){let e=r.ndim,n=t.ndim,o=B(r.dtype)||B(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 kr(a,u);if(e===0){let i=or(r.dtype,t.dtype),s=S.zeros([...t.shape],i),c=(l,f)=>{let m=new Array(f.length),p=l;for(let y=f.length-1;y>=0;y--)m[y]=p%f[y],p=Math.floor(p/f[y]);return m};for(let l=0;l<t.size;l++){let f=c(l,t.shape),m=t.get(...f);s.set(f,kr(a,m))}return s}else{let i=or(r.dtype,t.dtype),s=S.zeros([...r.shape],i),c=(l,f)=>{let m=new Array(f.length),p=l;for(let y=f.length-1;y>=0;y--)m[y]=p%f[y],p=Math.floor(p/f[y]);return m};for(let l=0;l<r.size;l++){let f=c(l,r.shape),m=r.get(...f);s.set(f,kr(m,u))}return s}}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 i=0,s=0;for(let c=0;c<a;c++){let l=r.get(c),f=t.get(c),m=kr(l,f);m instanceof U?(i+=m.re,s+=m.im):i+=m}return new U(i,s)}let u=0;for(let i=0;i<a;i++){let s=r.get(i),c=t.get(i);typeof s=="bigint"&&typeof c=="bigint"?u=Number(u)+Number(s*c):u+=Number(s)*Number(c)}return u}if(e===2&&n===2)return Ar(r,t);if(e===2&&n===1){let[a,u]=r.shape,i=t.shape[0];if(u!==i)throw new Error(`dot: incompatible shapes (${a},${u}) and (${i},)`);let s=or(r.dtype,t.dtype),c=S.zeros([a],s);if(o)for(let l=0;l<a;l++){let f=0,m=0;for(let p=0;p<u;p++){let y=r.get(l,p),d=t.get(p),b=y instanceof U?y:new U(Number(y),0),A=d instanceof U?d:new U(Number(d),0);f+=b.re*A.re-b.im*A.im,m+=b.re*A.im+b.im*A.re}c.set([l],new U(f,m))}else for(let l=0;l<a;l++){let f=0;for(let m=0;m<u;m++){let p=r.get(l,m),y=t.get(m);typeof p=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(p*y):f+=Number(p)*Number(y)}c.set([l],f)}return c}if(e===1&&n===2){let a=r.shape[0],[u,i]=t.shape;if(a!==u)throw new Error(`dot: incompatible shapes (${a},) and (${u},${i})`);let s=or(r.dtype,t.dtype),c=S.zeros([i],s);if(o)for(let l=0;l<i;l++){let f=0,m=0;for(let p=0;p<a;p++){let y=r.get(p),d=t.get(p,l),b=y instanceof U?y:new U(Number(y),0),A=d instanceof U?d:new U(Number(d),0);f+=b.re*A.re-b.im*A.im,m+=b.re*A.im+b.im*A.re}c.set([l],new U(f,m))}else for(let l=0;l<i;l++){let f=0;for(let m=0;m<a;m++){let p=r.get(m),y=t.get(m,l);typeof p=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(p*y):f+=Number(p)*Number(y)}c.set([l],f)}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 i=[...r.shape.slice(0,-1)],s=or(r.dtype,t.dtype),c=S.zeros(i,s),l=i.reduce((f,m)=>f*m,1);if(o)for(let f=0;f<l;f++){let m=0,p=0,y=f,d=[];for(let b=i.length-1;b>=0;b--)d[b]=y%i[b],y=Math.floor(y/i[b]);for(let b=0;b<a;b++){let A=[...d,b],g=r.get(...A),h=t.get(b),N=g instanceof U?g:new U(Number(g),0),D=h instanceof U?h:new U(Number(h),0);m+=N.re*D.re-N.im*D.im,p+=N.re*D.im+N.im*D.re}c.set(d,new U(m,p))}else for(let f=0;f<l;f++){let m=0,p=f,y=[];for(let d=i.length-1;d>=0;d--)y[d]=p%i[d],p=Math.floor(p/i[d]);for(let d=0;d<a;d++){let b=[...y,d],A=r.get(...b),g=t.get(d);typeof A=="bigint"&&typeof g=="bigint"?m=Number(m)+Number(A*g):m+=Number(A)*Number(g)}c.set(y,m)}return c}if(e===1&&n>2){let a=r.shape[0],u=1,i=t.shape[u];if(a!==i)throw new Error(`dot: incompatible shapes (${a},) and ${JSON.stringify(t.shape)}`);let s=[...t.shape.slice(0,u),...t.shape.slice(u+1)],c=or(r.dtype,t.dtype),l=S.zeros(s,c),f=s.reduce((m,p)=>m*p,1);if(o)for(let m=0;m<f;m++){let p=m,y=[];for(let h=s.length-1;h>=0;h--)y[h]=p%s[h],p=Math.floor(p/s[h]);let d=y.slice(0,u),b=y.slice(u),A=0,g=0;for(let h=0;h<a;h++){let N=r.get(h),D=[...d,h,...b],x=t.get(...D),C=N instanceof U?N:new U(Number(N),0),w=x instanceof U?x:new U(Number(x),0);A+=C.re*w.re-C.im*w.im,g+=C.re*w.im+C.im*w.re}l.set(y,new U(A,g))}else for(let m=0;m<f;m++){let p=m,y=[];for(let g=s.length-1;g>=0;g--)y[g]=p%s[g],p=Math.floor(p/s[g]);let d=y.slice(0,u),b=y.slice(u),A=0;for(let g=0;g<a;g++){let h=r.get(g),N=[...d,g,...b],D=t.get(...N);typeof h=="bigint"&&typeof D=="bigint"?A=Number(A)+Number(h*D):A+=Number(h)*Number(D)}l.set(y,A)}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 i=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],s=or(r.dtype,t.dtype),c=S.zeros(i,s),l=r.shape.slice(0,-1).reduce((y,d)=>y*d,1),f=t.shape.slice(0,-2).reduce((y,d)=>y*d,1),m=t.shape[n-1],p=a;if(o)for(let y=0;y<l;y++)for(let d=0;d<f;d++)for(let b=0;b<m;b++){let A=0,g=0;for(let D=0;D<p;D++){let x=[],C=y;for(let $=r.shape.length-2;$>=0;$--)x.unshift(C%r.shape[$]),C=Math.floor(C/r.shape[$]);x.push(D);let w=r.get(...x),_=[],I=d;for(let $=t.shape.length-3;$>=0;$--)_.unshift(I%t.shape[$]),I=Math.floor(I/t.shape[$]);_.push(D,b);let v=t.get(..._),T=w instanceof U?w:new U(Number(w),0),E=v instanceof U?v:new U(Number(v),0);A+=T.re*E.re-T.im*E.im,g+=T.re*E.im+T.im*E.re}let h=y*f*m+d*m+b,N=c.data;N[h*2]=A,N[h*2+1]=g}else if(r.isCContiguous&&t.isCContiguous&&!O(r.dtype)&&!O(t.dtype))wD(r.data,r.offset,l,t.data,t.offset,f,m,p,c.data);else for(let y=0;y<l;y++)for(let d=0;d<f;d++)for(let b=0;b<m;b++){let A=0;for(let h=0;h<p;h++){let N=y*p+h,D=d*p*m+h*m+b,x=r.iget(N),C=t.iget(D);typeof x=="bigint"&&typeof C=="bigint"?A=Number(A)+Number(x*C):A+=Number(x)*Number(C)}let g=y*f*m+d*m+b;c.data[g]=A}return c}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function Ar(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=or(r.dtype,t.dtype);if(B(u)){let D=S.zeros([e,a],u),x=D.data;for(let C=0;C<e;C++)for(let w=0;w<a;w++){let _=0,I=0;for(let T=0;T<n;T++){let E=r.iget(C*n+T),$=t.iget(T*a+w);_+=E.re*$.re-E.im*$.im,I+=E.re*$.im+E.im*$.re}let v=C*a+w;x[v*2]=_,x[v*2+1]=I}return D}let i=u.startsWith("int")||u.startsWith("uint")||u==="bool"?"float64":u;if(i!=="float64")throw new Error(`matmul currently only supports float64, got ${i}`);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,f=0]=r.strides,[m=0,p=0]=t.strides,y=f>l,d=p>m,b=y?"transpose":"no-transpose",A=d?"transpose":"no-transpose",g,h;y?g=f:g=l,d?h=p:h=m;let N=S.zeros([e,a],"float64");return zD(b,A,e,a,n,1,s,g,c,h,N.data,a),N}function Cm(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(B(r.dtype)){let a=0,u=0;for(let i=0;i<n;i++){let s=r.get(i,i);a+=s.re,u+=s.im}return new U(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 tt(r,t){return Ui(r,t)}function Sm(r,t){let e=r.ndim,n=t.ndim,o=B(r.dtype)||B(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 At(r,t);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],s=or(r.dtype,t.dtype),c=S.zeros(i,s),l=e===1?1:r.shape.slice(0,-1).reduce((p,y)=>p*y,1),f=n===1?1:t.shape.slice(0,-1).reduce((p,y)=>p*y,1),m=a;if(o)for(let p=0;p<l;p++)for(let y=0;y<f;y++){let d=0,b=0;for(let h=0;h<m;h++){let N,D;if(e===1)N=r.get(h);else{let w=[],_=p,I=r.shape.slice(0,-1);for(let v=I.length-1;v>=0;v--)w.unshift(_%I[v]),_=Math.floor(_/I[v]);w.push(h),N=r.get(...w)}if(n===1)D=t.get(h);else{let w=[],_=y,I=t.shape.slice(0,-1);for(let v=I.length-1;v>=0;v--)w.unshift(_%I[v]),_=Math.floor(_/I[v]);w.push(h),D=t.get(...w)}let x=N instanceof U?N:new U(Number(N),0),C=D instanceof U?D:new U(Number(D),0);d+=x.re*C.re-x.im*C.im,b+=x.re*C.im+x.im*C.re}if(i.length===0)return new U(d,b);let A=l===1?y:p*f+y,g=c.data;g[A*2]=d,g[A*2+1]=b}else if(r.isCContiguous&&t.isCContiguous&&!O(r.dtype)&&!O(t.dtype)){if(i.length===0){let p=r.data,y=t.data,d=r.offset,b=t.offset,A=0;for(let g=0;g<m;g++)A+=p[d+g]*y[b+g];return A}ID(r.data,r.offset,l,e,t.data,t.offset,f,n,m,c.data)}else for(let p=0;p<l;p++)for(let y=0;y<f;y++){let d=0;for(let A=0;A<m;A++){let g=e===1?A:p*m+A,h=n===1?A:y*m+A,N=r.iget(g),D=t.iget(h);typeof N=="bigint"&&typeof D=="bigint"?d=Number(d)+Number(N*D):d+=Number(N)*Number(D)}if(i.length===0)return d;let b=l===1?y:p*f+y;c.data[b]=d}return c}function Pi(r,t){let e=r.ndim===1?r:dt(r),n=t.ndim===1?t:dt(t),o=e.size,a=n.size,u=or(r.dtype,t.dtype),i=S.zeros([o,a],u);for(let s=0;s<o;s++)for(let c=0;c<a;c++){let l=e.get(s),f=n.get(c),m=kr(l,f);i.set([s,c],m)}return i}function wm(r,t,e){let n,o;if(typeof e=="number"){let y=e;if(y<0)throw new Error("tensordot: axes must be non-negative");if(y>r.ndim||y>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:y},(d,b)=>r.ndim-y+b),o=Array.from({length:y},(d,b)=>b)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let y=0;y<n.length;y++){let d=n[y],b=o[y];if(d<0||d>=r.ndim||b<0||b>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[d]!==t.shape[b])throw new Error(`tensordot: shape mismatch on axes ${d} and ${b}: ${r.shape[d]} != ${t.shape[b]}`)}let a=[],u=[];for(let y=0;y<r.ndim;y++)n.includes(y)||a.push(y);for(let y=0;y<t.ndim;y++)o.includes(y)||u.push(y);let i=[...a.map(y=>r.shape[y]),...u.map(y=>t.shape[y])],s=or(r.dtype,t.dtype),c=B(s),l=y=>y instanceof U?{re:y.re,im:y.im}:{re:Number(y),im:0};if(i.length===0){let y=0,d=0,b=n.map(A=>r.shape[A]).reduce((A,g)=>A*g,1);for(let A=0;A<b;A++){let g=A,h=new Array(n.length);for(let w=n.length-1;w>=0;w--){let _=n[w];h[w]=g%r.shape[_],g=Math.floor(g/r.shape[_])}let N=new Array(r.ndim),D=new Array(t.ndim);for(let w=0;w<n.length;w++)N[n[w]]=h[w];for(let w=0;w<o.length;w++)D[o[w]]=h[w];let x=r.get(...N),C=t.get(...D);if(c){let w=l(x),_=l(C);y+=w.re*_.re-w.im*_.im,d+=w.re*_.im+w.im*_.re}else typeof x=="bigint"&&typeof C=="bigint"?y+=Number(x*C):y+=Number(x)*Number(C)}return c?new U(y,d):y}let f=S.zeros(i,s),m=i.reduce((y,d)=>y*d,1),p=n.map(y=>r.shape[y]).reduce((y,d)=>y*d,1);for(let y=0;y<m;y++){let d=y,b=[];for(let D=i.length-1;D>=0;D--)b[D]=d%i[D],d=Math.floor(d/i[D]);let A=b.slice(0,a.length),g=b.slice(a.length),h=0,N=0;for(let D=0;D<p;D++){d=D;let x=[];for(let v=n.length-1;v>=0;v--){let T=n[v];x[v]=d%r.shape[T],d=Math.floor(d/r.shape[T])}let C=new Array(r.ndim),w=new Array(t.ndim);for(let v=0;v<a.length;v++)C[a[v]]=A[v];for(let v=0;v<u.length;v++)w[u[v]]=g[v];for(let v=0;v<n.length;v++)C[n[v]]=x[v],w[o[v]]=x[v];let _=r.get(...C),I=t.get(...w);if(c){let v=l(_),T=l(I);h+=v.re*T.re-v.im*T.im,N+=v.re*T.im+v.im*T.re}else typeof _=="bigint"&&typeof I=="bigint"?h+=Number(_*I):h+=Number(_)*Number(I)}c?f.set(b,new U(h,N)):f.set(b,h)}return f}function Im(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,i=n<0?a+n:n;if(u<0||u>=a||i<0||i>=a)throw new Error("axis out of bounds");if(u===i)throw new Error("axis1 and axis2 cannot be the same");let s=o[u],c=o[i],l;t>=0?l=Math.max(0,Math.min(s,c-t)):l=Math.max(0,Math.min(s+t,c));let f=[];for(let d=0;d<a;d++)d!==u&&d!==i&&f.push(o[d]);f.push(l);let m=S.zeros(f,r.dtype),p=o.filter((d,b)=>b!==u&&b!==i),y=p.reduce((d,b)=>d*b,1);for(let d=0;d<y;d++){let b=d,A=[];for(let g=p.length-1;g>=0;g--)A.unshift(b%p[g]),b=Math.floor(b/p[g]);for(let g=0;g<l;g++){let h=new Array(a),N=0;for(let C=0;C<a;C++)C===u?h[C]=t>=0?g:g-t:C===i?h[C]=t>=0?g+t:g:h[C]=A[N++];let D=[...A,g],x=r.get(...h);m.set(D,x)}}return m}function zm(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=_m(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 u=new Map;for(let d=0;d<t.length;d++){let b=a[d],A=t[d];if(b.length!==A.ndim)throw new Error(`einsum: operand ${d} has ${A.ndim} dimensions but subscript '${b}' has ${b.length} indices`);for(let g=0;g<b.length;g++){let h=b[g],N=A.shape[g];if(u.has(h)){if(u.get(h)!==N)throw new Error(`einsum: size mismatch for index '${h}': ${u.get(h)} vs ${N}`)}else u.set(h,N)}}for(let d of o)if(!u.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let i=new Set(o),s=new Set;for(let d of a)for(let b of d)s.add(b);let c=[];for(let d of s)i.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,b]=a,[A,g]=t;if(d.length===2&&b.length===2&&o.length===2&&A.ndim===2&&g.ndim===2){let[h,N]=[d[0],d[1]],[D,x]=[b[0],b[1]],[C,w]=[o[0],o[1]];if(h===C&&x===w&&N===D&&c.length===1&&c[0]===N||h===C&&x===w&&N===D&&c.length===1&&c[0]===N)return Ar(A,g);if(N===C&&x===w&&h===D&&c.length===1&&c[0]===h){let _=tt(A);return Ar(_,g)}if(h===C&&D===w&&N===x&&c.length===1&&c[0]===N){let _=tt(g);return Ar(A,_)}}if(d.length===1&&b.length===1&&d===b&&o.length===0&&A.ndim===1&&g.ndim===1)return qi(t,a,c,u);if(d&&b&&d.length===1&&b.length===1&&o.length===2&&o===d+b&&c.length===0&&A.ndim===1&&g.ndim===1)return Pi(A,g)}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 qi(t,a,c,u)}let l=Array.from(o).map(d=>u.get(d));if(l.length===0)return qi(t,a,c,u);let f=t[0].dtype;for(let d=1;d<t.length;d++)f=or(f,t[d].dtype);let m=S.zeros(l,f),p=l.reduce((d,b)=>d*b,1),y=1;for(let d of c)y*=u.get(d);for(let d=0;d<p;d++){let b=_D(d,l),A=new Map;for(let h=0;h<o.length;h++)A.set(o[h],b[h]);let g=0;for(let h=0;h<y;h++){let N=h;for(let x=c.length-1;x>=0;x--){let C=c[x],w=u.get(C);A.set(C,N%w),N=Math.floor(N/w)}let D=1;for(let x=0;x<t.length;x++){let C=t[x],w=a[x],_=[];for(let v of w)_.push(A.get(v));let I=C.get(..._);D*=Number(I)}g+=D}m.set(b,g)}return m}function _m(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 qi(r,t,e,n){let o=!1;for(let c of r)if(B(c.dtype)){o=!0;break}let a=c=>c instanceof U?{re:c.re,im:c.im}:{re:Number(c),im:0},u=1;for(let c of e)u*=n.get(c);let i=0,s=0;for(let c=0;c<u;c++){let l=new Map,f=c;for(let y=e.length-1;y>=0;y--){let d=e[y],b=n.get(d);l.set(d,f%b),f=Math.floor(f/b)}let m=1,p=0;for(let y=0;y<r.length;y++){let d=r[y],b=t[y],A=[];for(let h of b)A.push(l.get(h));let g=d.get(...A);if(o){let h=a(g),N=m*h.re-p*h.im,D=m*h.im+p*h.re;m=N,p=D}else m*=Number(g)}i+=m,s+=p}return o?new U(i,s):i}function _D(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 vm(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,u=or(r.dtype,t.dtype),i=Math.max(o,a),s=new Array(i),c=new Array(i).fill(1),l=new Array(i).fill(1);for(let y=0;y<o;y++)c[i-o+y]=e[y];for(let y=0;y<a;y++)l[i-a+y]=n[y];for(let y=0;y<i;y++)s[y]=c[y]*l[y];let f=S.zeros(s,u),m=e.reduce((y,d)=>y*d,1),p=n.reduce((y,d)=>y*d,1);for(let y=0;y<m;y++){let d=y,b=new Array(o);for(let h=o-1;h>=0;h--)b[h]=d%e[h],d=Math.floor(d/e[h]);let A=new Array(i).fill(0);for(let h=0;h<o;h++)A[i-o+h]=b[h];let g=r.get(...b);for(let h=0;h<p;h++){let N=h,D=new Array(a);for(let I=a-1;I>=0;I--)D[I]=N%n[I],N=Math.floor(N/n[I]);let x=new Array(i).fill(0);for(let I=0;I<a;I++)x[i-a+I]=D[I];let C=t.get(...D),w=new Array(i);for(let I=0;I<i;I++)w[I]=A[I]*l[I]+x[I];let _=kr(g,C);f.set(w,_)}}return f}function Mm(r,t,e=-1,n=-1,o=-1,a){a!==void 0&&(e=a,n=a,o=a);let u=(w,_)=>w<0?_+w:w,i=u(e,r.ndim),s=u(n,t.ndim),c=or(r.dtype,t.dtype),l=B(c),f=(w,..._)=>{let I=w.get(..._);return I instanceof U?I:Number(I)},m=(w,_)=>{if(w instanceof U||_ instanceof U){let I=w instanceof U?w:new U(w,0),v=_ instanceof U?_:new U(_,0);return I.mul(v)}return w*_},p=(w,_)=>{if(w instanceof U||_ instanceof U){let I=w instanceof U?w:new U(w,0),v=_ instanceof U?_:new U(_,0);return I.sub(v)}return w-_};if(r.ndim===1&&t.ndim===1){let w=r.shape[0],_=t.shape[0];if(w===3&&_===3){let I=f(r,0),v=f(r,1),T=f(r,2),E=f(t,0),$=f(t,1),k=f(t,2),V=S.zeros([3],c);return V.set([0],p(m(v,k),m(T,$))),V.set([1],p(m(T,E),m(I,k))),V.set([2],p(m(I,$),m(v,E))),V}else if(w===2&&_===2){let I=f(r,0),v=f(r,1),T=f(t,0),E=f(t,1);return p(m(I,E),m(v,T))}else if(w===2&&_===3||w===3&&_===2){let I=f(r,0),v=f(r,1),T=w===3?f(r,2):l?new U(0,0):0,E=f(t,0),$=f(t,1),k=_===3?f(t,2):l?new U(0,0):0,V=S.zeros([3],c);return V.set([0],p(m(v,k),m(T,$))),V.set([1],p(m(T,E),m(I,k))),V.set([2],p(m(I,$),m(v,E))),V}else throw new Error(`cross: incompatible dimensions for cross product: ${w} and ${_}`)}let y=r.shape[i],d=t.shape[s];if(y!==2&&y!==3||d!==2&&d!==3)throw new Error(`cross: incompatible dimensions for cross product: ${y} and ${d}`);let b=y===2&&d===2?0:3,A=[...r.shape.slice(0,i),...r.shape.slice(i+1)],g=[...t.shape.slice(0,s),...t.shape.slice(s+1)];if(A.length!==g.length)throw new Error("cross: incompatible shapes for cross product");for(let w=0;w<A.length;w++)if(A[w]!==g[w])throw new Error("cross: incompatible shapes for cross product");let h=A,N=o<0?h.length+1+o:o,D;if(b===0?D=h:D=[...h.slice(0,N),b,...h.slice(N)],D.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");let x=S.zeros(D,c),C=h.reduce((w,_)=>w*_,1);for(let w=0;w<C;w++){let _=w,I=[];for(let J=h.length-1;J>=0;J--)I[J]=_%h[J],_=Math.floor(_/h[J]);let v=[...I.slice(0,i),0,...I.slice(i)],T=[...I.slice(0,s),0,...I.slice(s)],E=J=>(v[i]=J,f(r,...v)),$=J=>(T[s]=J,f(t,...T)),k=E(0),V=E(1),j=y===3?E(2):l?new U(0,0):0,R=$(0),Y=$(1),X=d===3?$(2):l?new U(0,0):0;if(b===0)x.set(I,p(m(k,Y),m(V,R)));else{let J=p(m(V,X),m(j,Y)),rr=p(m(j,R),m(k,X)),yr=p(m(k,Y),m(V,R)),nr=(dr,Or)=>{let qN=[...I.slice(0,N),dr,...I.slice(N)];x.set(qN,Or)};nr(0,J),nr(1,rr),nr(2,yr)}}return x}function bt(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:dt(r),l=c.size,f;if(t===1/0){f=0;for(let m=0;m<l;m++)f=Math.max(f,Math.abs(Number(c.get(m))))}else if(t===-1/0){f=1/0;for(let m=0;m<l;m++)f=Math.min(f,Math.abs(Number(c.get(m))))}else if(t===0){f=0;for(let m=0;m<l;m++)Number(c.get(m))!==0&&f++}else if(t===1){f=0;for(let m=0;m<l;m++)f+=Math.abs(Number(c.get(m)))}else if(t===2){f=0;for(let m=0;m<l;m++){let p=Number(c.get(m));f+=p*p}f=Math.sqrt(f)}else{f=0;for(let m=0;m<l;m++)f+=Math.pow(Math.abs(Number(c.get(m))),t);f=Math.pow(f,1/t)}if(n){let m=new Array(r.ndim).fill(1),p=S.zeros(m,"float64");return p.set(new Array(r.ndim).fill(0),f),p}return f}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 bt(r,t,null,!1);let u=S.zeros(a,"float64"),i=r.shape[o],s=a.reduce((c,l)=>c*l,1);for(let c=0;c<s;c++){let l=c,f=[];for(let y=a.length-1;y>=0;y--)f[y]=l%a[y],l=Math.floor(l/a[y]);let m=n?[...f.slice(0,o),0,...f.slice(o+1)]:[...f.slice(0,o),0,...f.slice(o)],p;if(t===1/0){p=0;for(let y=0;y<i;y++)m[o]=y,p=Math.max(p,Math.abs(Number(r.get(...m))))}else if(t===-1/0){p=1/0;for(let y=0;y<i;y++)m[o]=y,p=Math.min(p,Math.abs(Number(r.get(...m))))}else if(t===0){p=0;for(let y=0;y<i;y++)m[o]=y,Number(r.get(...m))!==0&&p++}else if(t===1){p=0;for(let y=0;y<i;y++)m[o]=y,p+=Math.abs(Number(r.get(...m)))}else if(t===2){p=0;for(let y=0;y<i;y++){m[o]=y;let d=Number(r.get(...m));p+=d*d}p=Math.sqrt(p)}else{p=0;for(let y=0;y<i;y++)m[o]=y,p+=Math.pow(Math.abs(Number(r.get(...m))),t);p=Math.pow(p,1/t)}u.set(f,p)}return u}function rt(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 i=0;i<o;i++){let s=Number(r.get(u,i));a+=s*s}a=Math.sqrt(a)}else if(t==="nuc"){let{s:u}=Jr(r);a=0;for(let i=0;i<u.size;i++)a+=Number(u.get(i))}else if(t===1){a=0;for(let u=0;u<o;u++){let i=0;for(let s=0;s<n;s++)i+=Math.abs(Number(r.get(s,u)));a=Math.max(a,i)}}else if(t===-1){a=1/0;for(let u=0;u<o;u++){let i=0;for(let s=0;s<n;s++)i+=Math.abs(Number(r.get(s,u)));a=Math.min(a,i)}}else if(t===1/0){a=0;for(let u=0;u<n;u++){let i=0;for(let s=0;s<o;s++)i+=Math.abs(Number(r.get(u,s)));a=Math.max(a,i)}}else if(t===-1/0){a=1/0;for(let u=0;u<n;u++){let i=0;for(let s=0;s<o;s++)i+=Math.abs(Number(r.get(u,s)));a=Math.min(a,i)}}else if(t===2){let{s:u}=Jr(r);a=Number(u.get(0))}else if(t===-2){let{s:u}=Jr(r);a=Number(u.get(u.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${t}`);if(e){let u=S.zeros([1,1],"float64");return u.set([0,0],a),u}return a}function Fm(r,t=null,e=null,n=!1){if(t===null)return e===null?bt(r,2,null,n):typeof e=="number"?bt(r,2,e,n):rt(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 rt(r,t,n)}if(r.ndim===2&&e===null&&(t==="fro"||t==="nuc"))return rt(r,t,n);if(typeof t!="number"&&t!==null)throw new Error(`norm: ord '${t}' not valid for vector norm`);return bt(r,t??2,e,n)}function ji(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=S.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 u=[],i=[];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 b=0;for(let D=0;D<y;D++)b+=d[D]*d[D];if(b=Math.sqrt(b),b<1e-15){u.push(d),i.push(0);continue}let A=d[0]>=0?1:-1,g=d[0]+A*b,h=[1];for(let D=1;D<y;D++)h.push(d[D]/g);let N=A*g/b;i.push(N),u.push(h);for(let D=p;D<n;D++){let x=0;for(let C=0;C<y;C++)x+=h[C]*Number(a.get(p+C,D));for(let C=0;C<y;C++)a.set([p+C,D],Number(a.get(p+C,D))-N*h[C]*x)}}if(t==="raw"){let p=S.zeros([e,n],"float64");for(let d=0;d<e;d++)for(let b=0;b<n;b++)p.set([d,b],Number(a.get(d,b)));let y=S.zeros([o],"float64");for(let d=0;d<o;d++)y.set([d],i[d]);return{h:p,tau:y}}if(t==="r"){let p=S.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=S.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=u[p],d=i[p],b=e-p;for(let A=p;A<s;A++){let g=0;for(let h=0;h<b;h++)g+=y[h]*Number(c.get(p+h,A));for(let h=0;h<b;h++)c.set([p+h,A],Number(c.get(p+h,A))-d*y[h]*g)}}let l=S.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 f=t==="complete"?e:o,m=S.zeros([f,n],"float64");for(let p=0;p<f;p++)for(let y=0;y<n;y++)y>=p&&m.set([p,y],Number(a.get(p,y)));return{q:l,r:m}}function Bm(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=S.zeros([o,o],"float64");for(let u=0;u<o;u++)for(let i=0;i<=u;i++){let s=0;if(u===i){for(let l=0;l<i;l++)s+=Number(a.get(i,l))**2;let c=Number(r.get(i,i))-s;if(c<0)throw new Error("cholesky: matrix is not positive definite");a.set([i,i],Math.sqrt(c))}else{for(let l=0;l<i;l++)s+=Number(a.get(u,l))*Number(a.get(i,l));let c=Number(a.get(i,i));if(Math.abs(c)<1e-15)throw new Error("cholesky: matrix is not positive definite");a.set([u,i],(Number(r.get(u,i))-s)/c)}}if(t){let u=S.zeros([o,o],"float64");for(let i=0;i<o;i++)for(let s=i;s<o;s++)u.set([i,s],Number(a.get(s,i)));return u}return a}function Jr(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=S.zeros([e,e],"float64");for(let f=0;f<e;f++)for(let m=0;m<e;m++){let p=0;for(let y=0;y<t;y++)p+=Number(r.get(y,f))*Number(r.get(y,m));o.set([f,m],p)}let{values:a,vectors:u}=Li(o),i=Array.from({length:e},(f,m)=>m);i.sort((f,m)=>a[m]-a[f]);let s=S.zeros([n],"float64");for(let f=0;f<n;f++){let m=a[i[f]];s.set([f],Math.sqrt(Math.max(0,m)))}let c=S.zeros([e,e],"float64");for(let f=0;f<e;f++)for(let m=0;m<e;m++)c.set([f,m],u[m][i[f]]);let l=S.zeros([t,t],"float64");for(let f=0;f<t;f++)for(let m=0;m<n;m++){let p=Number(s.get(m));if(p>1e-10){let y=0;for(let d=0;d<e;d++)y+=Number(r.get(f,d))*Number(c.get(m,d));l.set([f,m],y/p)}}if(t>n)for(let f=n;f<t;f++){let m=new Array(t).fill(0);m[f]=1;for(let y=0;y<f;y++){let d=0;for(let b=0;b<t;b++)d+=m[b]*Number(l.get(b,y));for(let b=0;b<t;b++)m[b]=m[b]-d*Number(l.get(b,y))}let p=0;for(let y=0;y<t;y++)p+=m[y]*m[y];if(p=Math.sqrt(p),p>1e-10)for(let y=0;y<t;y++)l.set([y,f],m[y]/p)}return{u:l,s,vt:c}}function Li(r){let t=r.shape[0],e=100*t*t,n=1e-10,o=[];for(let i=0;i<t;i++){o.push([]);for(let s=0;s<t;s++)o[i].push(Number(r.get(i,s)))}let a=[];for(let i=0;i<t;i++){a.push([]);for(let s=0;s<t;s++)a[i].push(i===s?1:0)}for(let i=0;i<e;i++){let s=0,c=0,l=1;for(let h=0;h<t;h++)for(let N=h+1;N<t;N++)Math.abs(o[h][N])>s&&(s=Math.abs(o[h][N]),c=h,l=N);if(s<n)break;let f=o[c][c],m=o[l][l],p=o[c][l],y;Math.abs(f-m)<1e-15?y=Math.PI/4:y=.5*Math.atan2(2*p,m-f);let d=Math.cos(y),b=Math.sin(y),A=d*d*f+b*b*m-2*b*d*p,g=b*b*f+d*d*m+2*b*d*p;o[c][c]=A,o[l][l]=g,o[c][l]=0,o[l][c]=0;for(let h=0;h<t;h++)if(h!==c&&h!==l){let N=o[h][c],D=o[h][l];o[h][c]=d*N-b*D,o[c][h]=o[h][c],o[h][l]=b*N+d*D,o[l][h]=o[h][l]}for(let h=0;h<t;h++){let N=a[h][c],D=a[h][l];a[h][c]=d*N-b*D,a[h][l]=b*N+d*D}}let u=[];for(let i=0;i<t;i++)u.push(o[i][i]);return{values:u,vectors:a}}function Wi(r,t=!0,e=!0){let n=Jr(r);if(!e)return n.s;if(!t){let[o,a]=r.shape,u=Math.min(o,a),i=S.zeros([o,u],"float64");for(let c=0;c<o;c++)for(let l=0;l<u;l++)i.set([c,l],Number(n.u.get(c,l)));let s=S.zeros([u,a],"float64");for(let c=0;c<u;c++)for(let l=0;l<a;l++)s.set([c,l],Number(n.vt.get(c,l)));return{u:i,s:n.s,vt:s}}return n}function Tm(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}=Jo(r),i=a.data,s=u;for(let c=0;c<n;c++)s*=i[c*n+c];return s}function Jo(r){let[t,e]=r.shape,n=t,o=e,a=S.zeros([n,o],"float64"),u=a.data,i=r.data;for(let l=0;l<n*o;l++)u[l]=Number(i[l]);let s=Array.from({length:n},(l,f)=>f),c=1;for(let l=0;l<Math.min(n,o);l++){let f=Math.abs(u[l*o+l]),m=l;for(let y=l+1;y<n;y++){let d=Math.abs(u[y*o+l]);d>f&&(f=d,m=y)}if(m!==l){for(let d=0;d<o;d++){let b=u[l*o+d];u[l*o+d]=u[m*o+d],u[m*o+d]=b}let y=s[l];s[l]=s[m],s[m]=y,c=-c}let p=u[l*o+l];if(Math.abs(p)>1e-15)for(let y=l+1;y<n;y++){let d=u[y*o+l]/p;u[y*o+l]=d;for(let b=l+1;b<o;b++)u[y*o+b]=u[y*o+b]-d*u[l*o+b]}}return{lu:a,piv:s,sign:c}}function Oe(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}=Jo(r),u=o.data,i=S.zeros([n,n],"float64"),s=i.data;for(let c=0;c<n;c++){let l=new Float64Array(n);for(let f=0;f<n;f++){let m=a[f]===c?1:0;for(let p=0;p<f;p++)m-=u[f*n+p]*l[p];l[f]=m}for(let f=n-1;f>=0;f--){let m=l[f];for(let y=f+1;y<n;y++)m-=u[f*n+y]*s[y*n+c];let p=u[f*n+f];if(Math.abs(p)<1e-15)throw new Error("inv: singular matrix");s[f*n+c]=m/p}}return i}function xm(r,t){let[e]=r.shape,n=e,{lu:o,piv:a}=Jo(r),u=o.data,i=t.data,s=new Float64Array(n);for(let m=0;m<n;m++)s[m]=Number(i[a[m]]);let c=new Float64Array(n);for(let m=0;m<n;m++){let p=s[m];for(let y=0;y<m;y++)p-=u[m*n+y]*c[y];c[m]=p}let l=S.zeros([n],"float64"),f=l.data;for(let m=n-1;m>=0;m--){let p=c[m];for(let d=m+1;d<n;d++)p-=u[m*n+d]*f[d];let y=u[m*n+m];if(Math.abs(y)<1e-15)throw new Error("solve: singular matrix");f[m]=p/y}return l}function Gi(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 xm(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=S.zeros([o,a],"float64");for(let i=0;i<a;i++){let s=S.zeros([o],"float64");for(let l=0;l<o;l++)s.set([l],Number(t.get(l,i)));let c=xm(r,s);for(let l=0;l<o;l++)u.set([l,i],Number(c.get(l)))}return u}throw new Error(`solve: b must be 1D or 2D, got ${t.ndim}D`)}function Om(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:i}=Jr(r),s=Math.min(n,o),c=e??Math.max(n,o)*Number.EPSILON,f=Number(u.get(0))*c,m=0;for(let g=0;g<s;g++)Number(u.get(g))>f&&m++;let p=t.ndim===1?cr(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=S.zeros([o,y],"float64");for(let g=0;g<y;g++){let h=new Array(n).fill(0);for(let N=0;N<n;N++)for(let D=0;D<n;D++)h[N]+=Number(a.get(D,N))*Number(p.get(D,g));for(let N=0;N<o;N++){let D=0;for(let x=0;x<s;x++){let C=Number(u.get(x));C>f&&(D+=Number(i.get(x,N))*h[x]/C)}d.set([N,g],D)}}let b;if(n>o){b=S.zeros([y],"float64");for(let g=0;g<y;g++){let h=0;for(let N=0;N<n;N++){let D=0;for(let C=0;C<o;C++)D+=Number(r.get(N,C))*Number(d.get(C,g));let x=D-Number(p.get(N,g));h+=x*x}b.set([g],h)}}else b=S.zeros([0],"float64");return{x:t.ndim===1?cr(d,[o]):d,residuals:b,rank:m,s:u}}function Em(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:i}=Jr(r),s=Math.min(e,n),c=Number(i.get(0)),l=Number(i.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=rt(r,t),a=Oe(r),u=rt(a,t);return o*u}function Um(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}=Jr(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 $m(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=S.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=Oe(r),u=-t);let i=S.zeros([o,o],"float64");for(let c=0;c<o;c++)i.set([c,c],1);let s=S.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(;u>0;)u&1&&(i=Ar(i,s)),s=Ar(s,s),u>>=1;return i}function km(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}=Jr(r),i=Math.min(e,n),c=Number(a.get(0))*t,l=S.zeros([n,e],"float64");for(let f=0;f<n;f++)for(let m=0;m<e;m++){let p=0;for(let y=0;y<i;y++){let d=Number(a.get(y));d>c&&(p+=Number(u.get(y,f))*Number(o.get(m,y))/d)}l.set([f,m],p)}return l}function Yi(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 l=0;l<n;l++)for(let f=l+1;f<n;f++)if(Math.abs(Number(r.get(l,f))-Number(r.get(f,l)))>1e-10){o=!1;break r}if(o){let{values:l,vectors:f}=Li(r),m=S.zeros([n],"float64"),p=S.zeros([n,n],"float64");for(let y=0;y<n;y++){m.set([y],l[y]);for(let d=0;d<n;d++)p.set([d,y],f[d][y])}return{w:m,v:p}}let{values:a,vectors:u,hasComplexEigenvalues:i}=vD(r);i&&console.warn("numpy-ts: eig() detected complex eigenvalues which cannot be represented. Results are real approximations and may be inaccurate. For symmetric matrices, use eigh() instead.");let s=S.zeros([n],"float64"),c=S.zeros([n,n],"float64");for(let l=0;l<n;l++){s.set([l],a[l]);for(let f=0;f<n;f++)c.set([f,l],u[f][l])}return{w:s,v:c}}function vD(r){let t=r.shape[0],e=1e3,n=1e-10,o=S.zeros([t,t],"float64");for(let c=0;c<t;c++)for(let l=0;l<t;l++)o.set([c,l],Number(r.get(c,l)));let a=S.zeros([t,t],"float64");for(let c=0;c<t;c++)a.set([c,c],1);for(let c=0;c<e;c++){let l=0;for(let y=0;y<t;y++)for(let d=0;d<t;d++)y!==d&&(l+=Number(o.get(y,d))**2);if(Math.sqrt(l)<n*t)break;let f=ji(o,"reduced"),m=f.q,p=f.r;o=Ar(p,m),a=Ar(a,m)}let u=!1;for(let c=0;c<t-1;c++){let l=Math.abs(Number(o.get(c+1,c))),f=Math.abs(Number(o.get(c,c))),m=Math.abs(Number(o.get(c+1,c+1))),p=Math.max(f,m,1e-10);if(l/p>1e-6){u=!0;break}}let i=[];for(let c=0;c<t;c++)i.push(Number(o.get(c,c)));let s=[];for(let c=0;c<t;c++){s.push([]);for(let l=0;l<t;l++)s[c].push(Number(a.get(c,l)))}return{values:i,vectors:s,hasComplexEigenvalues:u}}function Zi(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=S.zeros([o,o],"float64");for(let f=0;f<o;f++)for(let m=0;m<o;m++)t==="L"?f>=m&&(a.set([f,m],Number(r.get(f,m))),a.set([m,f],Number(r.get(f,m)))):m>=f&&(a.set([f,m],Number(r.get(f,m))),a.set([m,f],Number(r.get(f,m))));let{values:u,vectors:i}=Li(a),s=Array.from({length:o},(f,m)=>m);s.sort((f,m)=>u[f]-u[m]);let c=S.zeros([o],"float64"),l=S.zeros([o,o],"float64");for(let f=0;f<o;f++){c.set([f],u[s[f]]);for(let m=0;m<o;m++)l.set([m,f],i[m][s[f]])}return{w:c,v:l}}function Rm(r){let{w:t}=Yi(r);return t}function qm(r,t="L"){let{w:e}=Zi(r,t);return e}function Vm(r,t){let e=Hr(r),n=Hr(t),o=e.shape[0],a=n.shape[0];if(o!==a)throw new Error(`vdot: arrays must have same number of elements, got ${o} and ${a}`);if(B(r.dtype)||B(t.dtype)){let s=0,c=0;for(let l=0;l<o;l++){let f=e.get(l),m=n.get(l),p=f instanceof U?f.re:Number(f),y=f instanceof U?-f.im:0,d=m instanceof U?m.re:Number(m),b=m instanceof U?m.im:0;s+=p*d+y*b,c+=p*b-y*d}return Math.abs(c)<1e-15?s:new U(s,c)}let i=0;for(let s=0;s<o;s++){let c=e.get(s),l=n.get(s);typeof c=="bigint"&&typeof l=="bigint"?i=(typeof i=="bigint"?i:BigInt(i))+c*l:i=(typeof i=="bigint"?Number(i):i)+Number(c)*Number(l)}return i}function Pm(r,t,e=-1){let n=r.ndim,o=t.ndim,a=e<0?n+e:e,u=e<0?o+e:e;if(a<0||a>=n)throw new Error(`vecdot: axis ${e} out of bounds for array with ${n} dimensions`);if(u<0||u>=o)throw new Error(`vecdot: axis ${e} out of bounds for array with ${o} dimensions`);let i=r.shape[a],s=t.shape[u];if(i!==s)throw new Error(`vecdot: axis dimensions must match, got ${i} and ${s}`);if(n===1&&o===1)return At(r,t);let c=[...r.shape.slice(0,a),...r.shape.slice(a+1)],l=[...t.shape.slice(0,u),...t.shape.slice(u+1)],f=i,m=B(r.dtype)||B(t.dtype),p=or(r.dtype,t.dtype),y=c.length>l.length?c:l;if(y.length===0){let A=m?new U(0,0):0;for(let g=0;g<f;g++){let h=r.get(g),N=t.get(g),D=kr(h,N);if(A instanceof U||D instanceof U){let x=A instanceof U?A:new U(Number(A),0),C=D instanceof U?D:new U(Number(D),0);A=x.add(C)}else typeof A=="bigint"||typeof D=="bigint"?A=BigInt(A)+BigInt(D):A=A+D}return A}let d=S.zeros(y,p),b=y.reduce((A,g)=>A*g,1);for(let A=0;A<b;A++){let g=[],h=A;for(let C=y.length-1;C>=0;C--)g.unshift(h%y[C]),h=Math.floor(h/y[C]);let N=[...g.slice(0,a),0,...g.slice(a)],D=[...g.slice(0,u),0,...g.slice(u)],x=m?new U(0,0):0;for(let C=0;C<f;C++){N[a]=C,D[u]=C;let w=r.get(...N),_=t.get(...D),I=kr(w,_);if(x instanceof U||I instanceof U){let v=x instanceof U?x:new U(Number(x),0),T=I instanceof U?I:new U(Number(I),0);x=v.add(T)}else typeof x=="bigint"||typeof I=="bigint"?x=BigInt(x)+BigInt(I):x=x+I}d.set(g,x)}return d}function jm(r){if(r.ndim<2)throw new Error(`matrix_transpose: input must have at least 2 dimensions, got ${r.ndim}D`);let t=Array.from({length:r.ndim},(n,o)=>o),e=t.length-1;return t[e]=e-1,t[e-1]=e,tt(r,t)}function Lm(r,t){return tt(r,t)}function Wm(r,t){if(r.ndim<2)throw new Error(`matvec: x1 must have at least 2 dimensions, got ${r.ndim}D`);if(t.ndim<1)throw new Error(`matvec: x2 must have at least 1 dimension, got ${t.ndim}D`);let e=r.shape[r.ndim-2],n=r.shape[r.ndim-1],o=t.shape[t.ndim-1];if(n!==o)throw new Error(`matvec: last axis of x1 (${n}) must match last axis of x2 (${o})`);if(r.ndim===2&&t.ndim===1)return At(r,t);let a=r.shape.slice(0,-2),u=t.shape.slice(0,-1),i=Math.max(a.length,u.length),s=[...Array(i-a.length).fill(1),...a],c=[...Array(i-u.length).fill(1),...u],l=[];for(let b=0;b<i;b++){let A=s[b],g=c[b];if(A!==1&&g!==1&&A!==g)throw new Error(`matvec: batch dimensions not broadcastable: ${a} vs ${u}`);l.push(Math.max(A,g))}let f=[...l,e],m=or(r.dtype,t.dtype),p=S.zeros(f,m),y=B(m),d=l.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=[],g=b;for(let D=l.length-1;D>=0;D--)A.unshift(g%l[D]),g=Math.floor(g/l[D]);let h=A.slice(-(a.length||1)).map((D,x)=>(a[x]??1)===1?0:D),N=A.slice(-(u.length||1)).map((D,x)=>(u[x]??1)===1?0:D);for(let D=0;D<e;D++){let x=y?new U(0,0):0;for(let w=0;w<n;w++){let _=[...h,D,w],I=[...N,w],v=r.get(..._),T=t.get(...I),E=kr(v,T);if(x instanceof U||E instanceof U){let $=x instanceof U?x:new U(Number(x),0),k=E instanceof U?E:new U(Number(E),0);x=$.add(k)}else typeof x=="bigint"||typeof E=="bigint"?x=BigInt(x)+BigInt(E):x=x+E}let C=[...A,D];p.set(C,x)}}return p}function Gm(r,t){if(r.ndim<1)throw new Error(`vecmat: x1 must have at least 1 dimension, got ${r.ndim}D`);if(t.ndim<2)throw new Error(`vecmat: x2 must have at least 2 dimensions, got ${t.ndim}D`);let e=r.shape[r.ndim-1],n=t.shape[t.ndim-2],o=t.shape[t.ndim-1];if(e!==n)throw new Error(`vecmat: last axis of x1 (${e}) must match second-to-last axis of x2 (${n})`);if(r.ndim===1&&t.ndim===2)return At(r,t);let a=r.shape.slice(0,-1),u=t.shape.slice(0,-2),i=Math.max(a.length,u.length),s=[...Array(i-a.length).fill(1),...a],c=[...Array(i-u.length).fill(1),...u],l=[];for(let b=0;b<i;b++){let A=s[b],g=c[b];if(A!==1&&g!==1&&A!==g)throw new Error(`vecmat: batch dimensions not broadcastable: ${a} vs ${u}`);l.push(Math.max(A,g))}let f=[...l,o],m=or(r.dtype,t.dtype),p=S.zeros(f,m),y=B(m),d=l.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=[],g=b;for(let D=l.length-1;D>=0;D--)A.unshift(g%l[D]),g=Math.floor(g/l[D]);let h=A.slice(-(a.length||1)).map((D,x)=>(a[x]??1)===1?0:D),N=A.slice(-(u.length||1)).map((D,x)=>(u[x]??1)===1?0:D);for(let D=0;D<o;D++){let x=y?new U(0,0):0;for(let w=0;w<e;w++){let _=[...h,w],I=[...N,w,D],v=r.get(..._),T=t.get(...I),E=kr(v,T);if(x instanceof U||E instanceof U){let $=x instanceof U?x:new U(Number(x),0),k=E instanceof U?E:new U(Number(E),0);x=$.add(k)}else typeof x=="bigint"||typeof E=="bigint"?x=BigInt(x)+BigInt(E):x=x+E}let C=[...A,D];p.set(C,x)}}return p}function Ym(r){if(r.ndim!==2)throw new Error(`slogdet: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`slogdet: matrix must be square, got ${t}x${e}`);let n=t;if(n===0)return{sign:1,logabsdet:0};let{lu:o,sign:a}=Jo(r),u=o.data,i=0,s=a;for(let c=0;c<n;c++){let l=u[c*n+c];if(l===0)return{sign:0,logabsdet:-1/0};l<0&&(s=-s),i+=Math.log(Math.abs(l))}return{sign:s,logabsdet:i}}function Zm(r){return Wi(r,!0,!1)}function Xm(r){if(r.length<2)throw new Error("multi_dot: need at least 2 arrays");if(r.length===2)return Ar(r[0],r[1]);let t=r[0];for(let e=1;e<r.length;e++)t=Ar(t,r[e]);return t}function Jm(r,t=2){if(t<=0)throw new Error(`tensorinv: ind must be positive, got ${t}`);let e=r.shape,n=r.ndim;if(n<t)throw new Error(`tensorinv: array has ${n} dimensions, ind=${t} is too large`);let o=1;for(let c=0;c<t;c++)o*=e[c];let a=1;for(let c=t;c<n;c++)a*=e[c];if(o!==a)throw new Error(`tensorinv: product of first ${t} dimensions (${o}) must equal product of remaining dimensions (${a})`);let u=cr(r,[o,a]),i=Oe(u),s=[...e.slice(t),...e.slice(0,t)];return cr(i,s)}function Km(r,t,e){let n=r.shape,o=t.shape,a=r.ndim,u=t.ndim,i;e==null?i=Array.from({length:u},(h,N)=>a-u+N):i=e.map(h=>h<0?a+h:h);let s=[];for(let h=0;h<a;h++)i.includes(h)||s.push(h);let c=[...s,...i],l=tt(r,c),m=i.map(h=>n[h]).reduce((h,N)=>h*N,1),y=s.map(h=>n[h]).reduce((h,N)=>h*N,1),d=o.reduce((h,N)=>h*N,1);if(m!==d)throw new Error(`tensorsolve: dimensions don't match - sum dimensions product (${m}) != b total elements (${d})`);if(y!==m)throw new Error(`tensorsolve: non-square problem - other dimensions product (${y}) != sum dimensions product (${m})`);let b=cr(l,[y,m]),A=cr(t,[m]),g=Gi(b,A);return cr(g,[...o])}function Qm(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=_m(n)):(n=r.slice(0,e),o=r.slice(e+2));let a=n.split(",").map(m=>m.trim());if(a.length!==t.length)throw new Error(`einsum_path: expected ${a.length} operands, got ${t.length}`);let u=t.map(m=>Array.isArray(m)?m:Array.from(m.shape)),i=new Map;for(let m=0;m<t.length;m++){let p=a[m],y=u[m];if(p.length!==y.length)throw new Error(`einsum_path: operand ${m} has ${y.length} dimensions but subscript '${p}' has ${p.length} indices`);for(let d=0;d<p.length;d++){let b=p[d],A=y[d];if(i.has(b)&&i.get(b)!==A)throw new Error(`einsum_path: size mismatch for index '${b}': ${i.get(b)} vs ${A}`);i.set(b,A)}}if(t.length===1){let m=[[0]];return[m,Vi(r,u,m,i)]}if(t.length===2){let m=[[0,1]];return[m,Vi(r,u,m,i)]}let s=[],c=[...a],l=[...u],f=t.map((m,p)=>p);for(;c.length>1;){let m=0,p=1,y=1/0;for(let A=0;A<c.length;A++)for(let g=A+1;g<c.length;g++){let h=MD(c[A],c[g],l[A],l[g],o,i);h<y&&(y=h,m=A,p=g)}s.push([f[m],f[p]]);let[d,b]=FD(c[m],c[p],l[m],l[p],o,i);c.splice(p,1),c.splice(m,1),l.splice(p,1),l.splice(m,1),f.splice(p,1),f.splice(m,1),c.push(d),l.push(b),f.push(-1)}return[s,Vi(r,u,s,i)]}function MD(r,t,e,n,o,a){let u=new Set(r),i=new Set(t),s=1;for(let c of u)s*=a.get(c)||1;for(let c of i)u.has(c)||(s*=a.get(c)||1);return s}function FD(r,t,e,n,o,a){let u=new Set([...r,...t]),i=new Map;for(let f of r)i.set(f,(i.get(f)||0)+1);for(let f of t)i.set(f,(i.get(f)||0)+1);let s=new Set(o),c=[];for(let f of u)(s.has(f)||i.get(f)===1)&&c.push(f);c.sort();let l=c.map(f=>a.get(f));return[c.join(""),l]}function Vi(r,t,e,n){let o=[];o.push(" Complete contraction: "+r),o.push(" Operand shapes: "+t.map(u=>`(${u.join(", ")})`).join(", ")),o.push(" Contraction path: "+JSON.stringify(e));let a=0;for(let u of t)a+=u.reduce((i,s)=>i*s,1);return o.push(" Estimated FLOPS: ~"+a.toExponential(2)),o.join(`
|
|
5
|
+
`)}function gt(r,t){let e=At(z(r),z(t));return typeof e=="number"||typeof e=="bigint"||e instanceof U?e:M(e)}function et(r){return Cm(z(r))}function ht(r,t=0,e=0,n=1){return M(Im(z(r),t,e,n))}function Xi(r,t){return M(vm(z(r),z(t)))}function Nt(r,t){return Nr(tt(z(r),t),r)}function Dt(r,t){let e=Sm(z(r),z(t));return typeof e=="number"||typeof e=="bigint"||e instanceof U?e:M(e)}function xt(r,t){return M(Pi(z(r),z(t)))}function Ct(r,t,e=2){let n=wm(z(r),z(t),e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Ko(r,...t){let e=t.map(o=>z(o)),n=zm(r,...e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Qo(r,...t){let e=t.map(n=>z(n));return Qm(r,...e)}function Ho(r,t){return Vm(z(r),z(t))}function ra(r,t,e=-1){let n=Pm(z(r),z(t),e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function ta(r){return Nr(jm(z(r)),r)}function ea(r,t){return Nr(Lm(z(r),t),r)}function Ji(r,t){return M(Wm(z(r),z(t)))}function Ki(r,t){return M(Gm(z(r),z(t)))}function na(r,t,e=-1,n=-1,o=-1,a){let u=Mm(z(r),z(t),e,n,o,a);return typeof u=="number"||u instanceof U?u:M(u)}function Ee(r,t){return M(Ar(z(r),z(t)))}var oa={matmul:(r,t)=>M(Ar(z(r),z(t))),dot:(r,t)=>gt(r,t),det:r=>Tm(z(r)),inv:r=>M(Oe(z(r))),solve:(r,t)=>M(Gi(z(r),z(t))),lstsq:(r,t,e)=>{let n=Om(z(r),z(t),e);return{x:M(n.x),residuals:M(n.residuals),rank:n.rank,s:M(n.s)}},norm:(r,t,e,n)=>{let o=Fm(z(r),t,e,n);return typeof o=="number"?o:M(o)},cond:(r,t)=>Em(z(r),t),matrix_rank:(r,t)=>Um(z(r),t),matrix_power:(r,t)=>M($m(z(r),t)),pinv:(r,t)=>M(km(z(r),t)),qr:(r,t)=>{let e=ji(z(r),t);return"h"in e&&"tau"in e?{h:M(e.h),tau:M(e.tau)}:"q"in e&&"r"in e?{q:M(e.q),r:M(e.r)}:M(e)},cholesky:(r,t)=>M(Bm(z(r),t)),svd:(r,t,e)=>{let n=Wi(z(r),t,e);return"u"in n&&"s"in n&&"vt"in n?{u:M(n.u),s:M(n.s),vt:M(n.vt)}:M(n)},eig:r=>{let t=Yi(z(r));return{w:M(t.w),v:M(t.v)}},eigh:(r,t)=>{let e=Zi(z(r),t);return{w:M(e.w),v:M(e.v)}},eigvals:r=>M(Rm(z(r))),eigvalsh:(r,t)=>M(qm(z(r),t)),slogdet:r=>Ym(z(r)),svdvals:r=>M(Zm(z(r))),multi_dot:r=>M(Xm(r.map(t=>z(t)))),tensorinv:(r,t)=>M(Jm(z(r),t)),tensorsolve:(r,t,e)=>M(Km(z(r),z(t),e)),vector_norm:(r,t,e,n)=>{let o=bt(z(r),t,e,n);return typeof o=="number"?o:M(o)},matrix_norm:(r,t,e)=>{let n=rt(z(r),t,e);return typeof n=="number"?n:M(n)},cross:(r,t,e,n,o,a)=>na(r,t,e,n,o,a),matrix_transpose:r=>ta(r),permute_dims:(r,t)=>ea(r,t),trace:r=>et(r),diagonal:(r,t,e,n)=>ht(r,t,e,n),outer:(r,t)=>xt(r,t),inner:(r,t)=>Dt(r,t),tensordot:(r,t,e)=>Ct(r,t,e),vecdot:(r,t,e)=>ra(r,t,e),transpose:(r,t)=>Nt(r,t)};function Ue(r,t){return M(cr(z(r),t))}function Br(r){return M(Hr(z(r)))}function $e(r){return M(dt(z(r)))}function ke(r,t){return Nr($i(z(r),t),r)}function Re(r,t){return Nr(Be(z(r),t),r)}function qe(r,t,e){return Nr(Hf(z(r),t,e),r)}function Ve(r,t,e){return Nr(ki(z(r),t,e),r)}function Qi(r,t,e=0){return Nr(mm(z(r),t,e),r)}function St(r,t=0){return M(Xr(r.map(e=>z(e)),t))}function Hi(r,t=0){return M(rm(r.map(e=>z(e)),t))}function aa(r){return M(tm(r.map(t=>z(t))))}function ru(r){return M(Ri(r.map(t=>z(t))))}function tu(r){return M(em(r.map(t=>z(t))))}function eu(r){return M(ym(r.map(t=>z(t))))}var sa=aa;function nu(r){return M(Nm(r.map(t=>z(t))))}function ia(r,t,e=0){return mt(nm(z(r),t,e),r)}function ua(r,t,e=0){return mt(Te(z(r),t,e),r)}function ca(r,t){return mt(am(z(r),t),r)}function la(r,t){return mt(sm(z(r),t),r)}function fa(r,t){return mt(pm(z(r),t),r)}function ou(r,t=0){return $r(hm(z(r),t))}function au(r,t){return M(im(z(r),t))}function Pe(r,t,e){return M(um(z(r),t,e))}function je(r,t){return M(cm(z(r),t))}function su(r){return je(r,1)}function iu(r){return je(r,0)}function uu(r,t=1,e=[0,1]){return M(lm(z(r),t,e))}function cu(r,t,e){return M(fm(z(r),t,e))}function Le(r,t){return M(dm(z(r),t))}function ma(...r){let t=bm(r.map(e=>z(e)));return t.length===1?M(t[0]):$r(t)}function pa(...r){let t=Am(r.map(e=>z(e)));return t.length===1?M(t[0]):$r(t)}function ya(...r){let t=gm(r.map(e=>z(e)));return t.length===1?M(t[0]):$r(t)}function xr(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 Z(r,t,e){let n=e;for(let o=0;o<r.length;o++)n+=r[o]*t[o];return n}function G(r,t,e,n){let o=n.length,a=new Array(o),u=Array.from(n).filter((s,c)=>c!==t),i=r;for(let s=u.length-1;s>=0;s--)a[s>=t?s+1:s]=i%u[s],i=Math.floor(i/u[s]);return a[t]=e,a}function We(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0)if(B(n)){let A=0,g=0;if(l){let h=i;for(let N=0;N<u;N++)A+=h[(s+N)*2],g+=h[(s+N)*2+1]}else for(let h=0;h<u;h++){let N=r.iget(h);A+=N.re,g+=N.im}return new U(A,g)}else if(O(n)){let A=BigInt(0);if(l){let g=i;for(let h=0;h<u;h++)A+=g[s+h]}else for(let g=0;g<u;g++)A+=r.iget(g);return Number(A)}else{let A=0;if(l)if(s===0)for(let g=0;g<u;g++)A+=Number(i[g]);else for(let g=0;g<u;g++)A+=Number(i[s+g]);else for(let g=0;g<u;g++)A+=Number(r.iget(g));return A}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return We(r);let p=S.zeros(m,n),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(B(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=0,D=0;for(let x=0;x<d;x++){let C=G(h,f,x,o),w=Z(C,c,s);N+=A[w*2],D+=A[w*2+1]}g[h*2]=N,g[h*2+1]=D}}else if(O(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=BigInt(0);for(let D=0;D<d;D++){let x=G(h,f,D,o),C=Z(x,c,s);N+=A[C]}g[h]=N}}else for(let A=0;A<b;A++){let g=0;for(let h=0;h<d;h++){let N=G(A,f,h,o),D=Z(N,c,s);g+=Number(i[D])}y[A]=g}if(e){let A=[...o];return A[f]=1,S.fromData(y,A,n)}return p}function Na(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0){let m=We(r);return m instanceof U?new U(m.re/r.size,m.im/r.size):m/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=We(r,t,e);if(typeof u=="number")return u/o[a];if(u instanceof U)return new U(u.re/o[a],u.im/o[a]);let i=o[a],s=n;B(n)?s=n:(O(n)||n.startsWith("int")||n.startsWith("uint"))&&(s="float64");let c=S.zeros(Array.from(u.shape),s),l=c.data,f=u.data;if(B(n)){let m=f,p=l,y=u.size;for(let d=0;d<y;d++)p[d*2]=m[d*2]/i,p[d*2+1]=m[d*2+1]/i}else if(O(n)){let m=f;for(let p=0;p<l.length;p++)l[p]=Number(m[p])/i}else for(let m=0;m<l.length;m++)l[m]=Number(f[m])/i;return c}function wt(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides;if(B(n)){let b=i;if(t===void 0){if(u===0)throw new Error("max of empty array");let C=b[s*2],w=b[s*2+1];for(let _=1;_<u;_++){let I=b[(s+_)*2],v=b[(s+_)*2+1];if(isNaN(I)||isNaN(v))return new U(NaN,NaN);(I>C||I===C&&v>w)&&(C=I,w=v)}return isNaN(C)||isNaN(w)?new U(NaN,NaN):new U(C,w)}let A=t;if(A<0&&(A=a+A),A<0||A>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let g=Array.from(o).filter((C,w)=>w!==A);if(g.length===0)return wt(r);let h=S.zeros(g,n),N=h.data,D=o[A],x=g.reduce((C,w)=>C*w,1);for(let C=0;C<x;C++){let w=G(C,A,0,o),_=Z(w,c,s),I=b[_*2],v=b[_*2+1];for(let T=1;T<D;T++){let E=G(C,A,T,o),$=Z(E,c,s),k=b[$*2],V=b[$*2+1];if(isNaN(k)||isNaN(V)){I=NaN,v=NaN;break}(k>I||k===I&&V>v)&&(I=k,v=V)}N[C*2]=I,N[C*2+1]=v}if(e){let C=[...o];return C[A]=1,S.fromData(N,C,n)}return h}if(t===void 0){if(u===0)throw new Error("max of empty array");if(r.isCContiguous){let b=i[s];if(s===0)for(let A=1;A<u;A++)i[A]>b&&(b=i[A]);else for(let A=1;A<u;A++)i[s+A]>b&&(b=i[s+A]);return Number(b)}else{let b=r.iget(0);for(let A=1;A<u;A++){let g=r.iget(A);g>b&&(b=g)}return Number(b)}}let l=t;if(l<0&&(l=a+l),l<0||l>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let f=Array.from(o).filter((b,A)=>A!==l);if(f.length===0)return wt(r);let m=S.zeros(f,n),p=m.data,y=o[l],d=f.reduce((b,A)=>b*A,1);if(O(n)){let b=i,A=p;for(let g=0;g<d;g++){let h=G(g,l,0,o),N=Z(h,c,s),D=b[N];for(let x=1;x<y;x++){let C=G(g,l,x,o),w=Z(C,c,s),_=b[w];_>D&&(D=_)}A[g]=D}}else for(let b=0;b<d;b++){let A=-1/0;for(let g=0;g<y;g++){let h=G(b,l,g,o),N=Z(h,c,s),D=Number(i[N]);D>A&&(A=D)}p[b]=A}if(e){let b=[...o];return b[l]=1,S.fromData(p,b,n)}return m}function lu(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0)if(B(n)){let A=1,g=0;if(l){let h=i;for(let N=0;N<u;N++){let D=h[(s+N)*2],x=h[(s+N)*2+1],C=A*D-g*x,w=A*x+g*D;A=C,g=w}}else for(let h=0;h<u;h++){let N=r.iget(h),D=N.re,x=N.im,C=A*D-g*x,w=A*x+g*D;A=C,g=w}return new U(A,g)}else if(O(n)){let A=BigInt(1);if(l){let g=i;for(let h=0;h<u;h++)A*=g[s+h]}else for(let g=0;g<u;g++)A*=r.iget(g);return Number(A)}else{let A=1;if(l)if(s===0)for(let g=0;g<u;g++)A*=Number(i[g]);else for(let g=0;g<u;g++)A*=Number(i[s+g]);else for(let g=0;g<u;g++)A*=Number(r.iget(g));return A}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return lu(r);let p=S.zeros(m,n),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(B(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=1,D=0;for(let x=0;x<d;x++){let C=G(h,f,x,o),w=Z(C,c,s),_=A[w*2],I=A[w*2+1],v=N*_-D*I,T=N*I+D*_;N=v,D=T}g[h*2]=N,g[h*2+1]=D}}else if(O(n)){let A=i,g=y;for(let h=0;h<b;h++){let N=BigInt(1);for(let D=0;D<d;D++){let x=G(h,f,D,o),C=Z(x,c,s);N*=A[C]}g[h]=N}}else for(let A=0;A<b;A++){let g=1;for(let h=0;h<d;h++){let N=G(A,f,h,o),D=Z(N,c,s);g*=Number(i[D])}y[A]=g}if(e){let A=[...o];return A[f]=1,S.fromData(y,A,n)}return p}function It(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides;if(B(n)){let b=i;if(t===void 0){if(u===0)throw new Error("min of empty array");let C=b[s*2],w=b[s*2+1];for(let _=1;_<u;_++){let I=b[(s+_)*2],v=b[(s+_)*2+1];if(isNaN(I)||isNaN(v))return new U(NaN,NaN);(I<C||I===C&&v<w)&&(C=I,w=v)}return isNaN(C)||isNaN(w)?new U(NaN,NaN):new U(C,w)}let A=t;if(A<0&&(A=a+A),A<0||A>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let g=Array.from(o).filter((C,w)=>w!==A);if(g.length===0)return It(r);let h=S.zeros(g,n),N=h.data,D=o[A],x=g.reduce((C,w)=>C*w,1);for(let C=0;C<x;C++){let w=G(C,A,0,o),_=Z(w,c,s),I=b[_*2],v=b[_*2+1];for(let T=1;T<D;T++){let E=G(C,A,T,o),$=Z(E,c,s),k=b[$*2],V=b[$*2+1];if(isNaN(k)||isNaN(V)){I=NaN,v=NaN;break}(k<I||k===I&&V<v)&&(I=k,v=V)}N[C*2]=I,N[C*2+1]=v}if(e){let C=[...o];return C[A]=1,S.fromData(N,C,n)}return h}if(t===void 0){if(u===0)throw new Error("min of empty array");if(r.isCContiguous){let b=i[s];if(s===0)for(let A=1;A<u;A++)i[A]<b&&(b=i[A]);else for(let A=1;A<u;A++)i[s+A]<b&&(b=i[s+A]);return Number(b)}else{let b=r.iget(0);for(let A=1;A<u;A++){let g=r.iget(A);g<b&&(b=g)}return Number(b)}}let l=t;if(l<0&&(l=a+l),l<0||l>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let f=Array.from(o).filter((b,A)=>A!==l);if(f.length===0)return It(r);let m=S.zeros(f,n),p=m.data,y=o[l],d=f.reduce((b,A)=>b*A,1);if(O(n)){let b=i,A=p;for(let g=0;g<d;g++){let h=G(g,l,0,o),N=Z(h,c,s),D=b[N];for(let x=1;x<y;x++){let C=G(g,l,x,o),w=Z(C,c,s),_=b[w];_<D&&(D=_)}A[g]=D}}else for(let b=0;b<d;b++){let A=1/0;for(let g=0;g<y;g++){let h=G(b,l,g,o),N=Z(h,c,s),D=Number(i[N]);D<A&&(A=D)}p[b]=A}if(e){let b=[...o];return b[l]=1,S.fromData(p,b,n)}return m}function zr(r,t,e,n){return r<e?-1:r>e?1:t<n?-1:t>n?1:0}function fu(r,t){let e=r.dtype,n=B(e),o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0){if(u===0)throw new Error("argmin of empty array");if(n)if(l){let A=i,g=A[s*2],h=A[s*2+1],N=0;for(let D=1;D<u;D++){let x=A[(s+D)*2],C=A[(s+D)*2+1];zr(x,C,g,h)<0&&(g=x,h=C,N=D)}return N}else{let A=r.iget(0),g=A.re,h=A.im,N=0;for(let D=1;D<u;D++){let x=r.iget(D);zr(x.re,x.im,g,h)<0&&(g=x.re,h=x.im,N=D)}return N}if(l){let A=i[s],g=0;if(s===0)for(let h=1;h<u;h++)i[h]<A&&(A=i[h],g=h);else for(let h=1;h<u;h++)i[s+h]<A&&(A=i[s+h],g=h);return g}else{let A=r.iget(0),g=0;for(let h=1;h<u;h++){let N=r.iget(h);N<A&&(A=N,g=h)}return g}}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return fu(r);let p=S.zeros(m,"int32"),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(n){let A=i;for(let g=0;g<b;g++){let h=G(g,f,0,o),N=Z(h,c,s),D=A[N*2],x=A[N*2+1],C=0;for(let w=1;w<d;w++){let _=G(g,f,w,o),I=Z(_,c,s),v=A[I*2],T=A[I*2+1];zr(v,T,D,x)<0&&(D=v,x=T,C=w)}y[g]=C}}else if(O(e)){let A=i;for(let g=0;g<b;g++){let h=G(g,f,0,o),N=Z(h,c,s),D=A[N],x=0;for(let C=1;C<d;C++){let w=G(g,f,C,o),_=Z(w,c,s),I=A[_];I<D&&(D=I,x=C)}y[g]=x}}else for(let A=0;A<b;A++){let g=1/0,h=0;for(let N=0;N<d;N++){let D=G(A,f,N,o),x=Z(D,c,s),C=Number(i[x]);C<g&&(g=C,h=N)}y[A]=h}return p}function mu(r,t){let e=r.dtype,n=B(e),o=r.shape,a=o.length,u=r.size,i=r.data,s=r.offset,c=r.strides,l=r.isCContiguous;if(t===void 0){if(u===0)throw new Error("argmax of empty array");if(n)if(l){let A=i,g=A[s*2],h=A[s*2+1],N=0;for(let D=1;D<u;D++){let x=A[(s+D)*2],C=A[(s+D)*2+1];zr(x,C,g,h)>0&&(g=x,h=C,N=D)}return N}else{let A=r.iget(0),g=A.re,h=A.im,N=0;for(let D=1;D<u;D++){let x=r.iget(D);zr(x.re,x.im,g,h)>0&&(g=x.re,h=x.im,N=D)}return N}if(l){let A=i[s],g=0;for(let h=1;h<u;h++)i[s+h]>A&&(A=i[s+h],g=h);return g}else{let A=r.iget(0),g=0;for(let h=1;h<u;h++){let N=r.iget(h);N>A&&(A=N,g=h)}return g}}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 m=Array.from(o).filter((A,g)=>g!==f);if(m.length===0)return mu(r);let p=S.zeros(m,"int32"),y=p.data,d=o[f],b=m.reduce((A,g)=>A*g,1);if(n){let A=i;for(let g=0;g<b;g++){let h=G(g,f,0,o),N=Z(h,c,s),D=A[N*2],x=A[N*2+1],C=0;for(let w=1;w<d;w++){let _=G(g,f,w,o),I=Z(_,c,s),v=A[I*2],T=A[I*2+1];zr(v,T,D,x)>0&&(D=v,x=T,C=w)}y[g]=C}}else if(O(e)){let A=i;for(let g=0;g<b;g++){let h=G(g,f,0,o),N=Z(h,c,s),D=A[N],x=0;for(let C=1;C<d;C++){let w=G(g,f,C,o),_=Z(w,c,s),I=A[_];I>D&&(D=I,x=C)}y[g]=x}}else for(let A=0;A<b;A++){let g=-1/0,h=0;for(let N=0;N<d;N++){let D=G(A,f,N,o),x=Z(D,c,s),C=Number(i[x]);C>g&&(g=C,h=N)}y[A]=h}return p}function pu(r,t,e=0,n=!1){let o=r.dtype,a=r.shape,u=a.length,i=r.size,s=r.data,c=r.offset,l=r.strides,f=Na(r,t,n),m=r.isCContiguous;if(t===void 0){if(B(o)){let C=f,w=0;if(m){let _=s;for(let I=0;I<i;I++){let v=_[(c+I)*2],T=_[(c+I)*2+1],E=v-C.re,$=T-C.im;w+=E*E+$*$}}else for(let _=0;_<i;_++){let I=r.iget(_),v=I.re-C.re,T=I.im-C.im;w+=v*v+T*T}return w/(i-e)}let D=f,x=0;if(m)for(let C=0;C<i;C++){let w=Number(s[c+C])-D;x+=w*w}else for(let C=0;C<i;C++){let w=Number(r.iget(C))-D;x+=w*w}return x/(i-e)}let p=t;if(p<0&&(p=u+p),p<0||p>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let y=a[p],d=f,b=d.data,A=n?d.shape:Array.from(a).filter((D,x)=>x!==p),g=S.zeros(Array.from(A),"float64"),h=g.data,N=A.reduce((D,x)=>D*x,1);if(B(o)){let D=s,x=b;for(let C=0;C<N;C++){let w=0,_=x[C*2],I=x[C*2+1];for(let v=0;v<y;v++){let T=G(C,p,v,a),E=Z(T,l,c),$=D[E*2],k=D[E*2+1],V=$-_,j=k-I;w+=V*V+j*j}h[C]=w/(y-e)}}else for(let D=0;D<N;D++){let x=0,C=Number(b[D]);for(let w=0;w<y;w++){let _=G(D,p,w,a),I=Z(_,l,c),v=Number(s[I])-C;x+=v*v}h[D]=x/(y-e)}return g}function Hm(r,t,e=0,n=!1){let o=pu(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=S.zeros(Array.from(o.shape),"float64"),u=o.data,i=a.data;for(let s=0;s<u.length;s++)i[s]=Math.sqrt(Number(u[s]));return a}function yu(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,u=r.data,i=r.offset,s=r.strides,c=r.isCContiguous;if(t===void 0){if(c){for(let b=0;b<a;b++)if(!u[i+b])return!1}else for(let b=0;b<a;b++)if(!r.iget(b))return!1;return!0}let l=t;if(l<0&&(l=o+l),l<0||l>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let f=Array.from(n).filter((b,A)=>A!==l);if(f.length===0)return yu(r);let m=S.zeros(f,"bool"),p=m.data,y=n[l],d=f.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=!0;for(let g=0;g<y;g++){let h=G(b,l,g,n),N=Z(h,s,i);if(!u[N]){A=!1;break}}p[b]=A?1:0}if(e){let b=[...n];return b[l]=1,S.fromData(p,b,"bool")}return m}function du(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,u=r.data,i=r.offset,s=r.strides,c=r.isCContiguous;if(t===void 0){if(c){for(let b=0;b<a;b++)if(u[i+b])return!0}else for(let b=0;b<a;b++)if(r.iget(b))return!0;return!1}let l=t;if(l<0&&(l=o+l),l<0||l>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let f=Array.from(n).filter((b,A)=>A!==l);if(f.length===0)return du(r);let m=S.zeros(f,"bool"),p=m.data,y=n[l],d=f.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=!1;for(let g=0;g<y;g++){let h=G(b,l,g,n),N=Z(h,s,i);if(u[N]){A=!0;break}}p[b]=A?1:0}if(e){let b=[...n];return b[l]=1,S.fromData(p,b,"bool")}return m}function rp(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides,s=r.isCContiguous;if(B(e)){let b=a,A=r.size;if(t===void 0){let I=S.zeros([A],e),v=I.data,T=0,E=0;if(s)for(let $=0;$<A;$++)T+=b[(u+$)*2],E+=b[(u+$)*2+1],v[$*2]=T,v[$*2+1]=E;else for(let $=0;$<A;$++){let k=r.iget($);T+=k.re,E+=k.im,v[$*2]=T,v[$*2+1]=E}return I}let g=t;if(g<0&&(g=o+g),g<0||g>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let h=S.zeros([...n],e),N=h.data,D=n[g],x=[],C=1;for(let I=o-1;I>=0;I--)x.unshift(C),C*=n[I];let w=r.size,_=x[g];for(let I=0;I<w;I++){let v=Math.floor(I/_)%D,T=new Array(o),E=I;for(let k=o-1;k>=0;k--)T[k]=E%n[k],E=Math.floor(E/n[k]);let $=Z(T,i,u);v===0?(N[I*2]=b[$*2],N[I*2+1]=b[$*2+1]):(N[I*2]=N[(I-_)*2]+b[$*2],N[I*2+1]=N[(I-_)*2+1]+b[$*2+1])}return h}if(t===void 0){let b=r.size,A=new Float64Array(b),g=0;if(s)for(let h=0;h<b;h++)g+=Number(a[u+h]),A[h]=g;else for(let h=0;h<b;h++)g+=Number(r.iget(h)),A[h]=g;return S.fromData(A,[b],"float64")}let c=t;if(c<0&&(c=o+c),c<0||c>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let l=new Float64Array(r.size),f=n[c],m=[],p=1;for(let b=o-1;b>=0;b--)m.unshift(p),p*=n[b];let y=r.size,d=m[c];for(let b=0;b<y;b++){let A=Math.floor(b/d)%f,g=new Array(o),h=b;for(let D=o-1;D>=0;D--)g[D]=h%n[D],h=Math.floor(h/n[D]);let N=Z(g,i,u);A===0?l[b]=Number(a[N]):l[b]=l[b-d]+Number(a[N])}return S.fromData(l,[...n],"float64")}function tp(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides,s=r.isCContiguous;if(B(e)){let b=a,A=r.size;if(t===void 0){let I=S.zeros([A],e),v=I.data,T=1,E=0;if(s)for(let $=0;$<A;$++){let k=b[(u+$)*2],V=b[(u+$)*2+1],j=T*k-E*V,R=T*V+E*k;T=j,E=R,v[$*2]=T,v[$*2+1]=E}else for(let $=0;$<A;$++){let k=r.iget($),V=k.re,j=k.im,R=T*V-E*j,Y=T*j+E*V;T=R,E=Y,v[$*2]=T,v[$*2+1]=E}return I}let g=t;if(g<0&&(g=o+g),g<0||g>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let h=S.zeros([...n],e),N=h.data,D=n[g],x=[],C=1;for(let I=o-1;I>=0;I--)x.unshift(C),C*=n[I];let w=r.size,_=x[g];for(let I=0;I<w;I++){let v=Math.floor(I/_)%D,T=new Array(o),E=I;for(let k=o-1;k>=0;k--)T[k]=E%n[k],E=Math.floor(E/n[k]);let $=Z(T,i,u);if(v===0)N[I*2]=b[$*2],N[I*2+1]=b[$*2+1];else{let k=N[(I-_)*2],V=N[(I-_)*2+1],j=b[$*2],R=b[$*2+1];N[I*2]=k*j-V*R,N[I*2+1]=k*R+V*j}}return h}if(t===void 0){let b=r.size,A=new Float64Array(b),g=1;if(s)for(let h=0;h<b;h++)g*=Number(a[u+h]),A[h]=g;else for(let h=0;h<b;h++)g*=Number(r.iget(h)),A[h]=g;return S.fromData(A,[b],"float64")}let c=t;if(c<0&&(c=o+c),c<0||c>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let l=new Float64Array(r.size),f=n[c],m=[],p=1;for(let b=o-1;b>=0;b--)m.unshift(p),p*=n[b];let y=r.size,d=m[c];for(let b=0;b<y;b++){let A=Math.floor(b/d)%f,g=new Array(o),h=b;for(let D=o-1;D>=0;D--)g[D]=h%n[D],h=Math.floor(h/n[D]);let N=Z(g,i,u);A===0?l[b]=Number(a[N]):l[b]=l[b-d]*Number(a[N])}return S.fromData(l,[...n],"float64")}function ep(r,t,e=!1){let n=r.dtype;if(B(n)){let f=wt(r,t,e),m=It(r,t,e);if(f instanceof U&&m instanceof U)return new U(f.re-m.re,f.im-m.im);let p=f,y=m,d=p.data,b=y.data,A=new Float64Array(p.size*2);for(let g=0;g<p.size;g++)A[g*2]=d[g*2]-b[g*2],A[g*2+1]=d[g*2+1]-b[g*2+1];return S.fromData(A,[...p.shape],n)}let o=wt(r,t,e),a=It(r,t,e);if(typeof o=="number"&&typeof a=="number")return o-a;let u=o,i=a,s=u.data,c=i.data,l=new Float64Array(u.size);for(let f=0;f<u.size;f++)l[f]=Number(s[f])-Number(c[f]);return S.fromData(l,[...u.shape],"float64")}function np(r,t,e=!1){return Ye(r,.5,t,e)}function op(r,t,e,n=!1){return Ye(r,t/100,e,n)}function Ye(r,t,e,n=!1){if(L(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,i=r.offset,s=r.strides;if(e===void 0){let d=[];if(r.isCContiguous)for(let x=0;x<r.size;x++)d.push(Number(u[i+x]));else for(let x=0;x<r.size;x++)d.push(Number(r.iget(x)));d.sort((x,C)=>x-C);let A=d.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)return d[h];let D=g-h;return d[h]*(1-D)+d[N]*D}let c=e;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let l=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return Ye(r,t);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=[];for(let D=0;D<m;D++){let x=G(d,c,D,o),C=Z(x,s,i);b.push(Number(u[C]))}b.sort((D,x)=>D-x);let A=b.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)p[d]=b[h];else{let D=g-h;p[d]=b[h]*(1-D)+b[N]*D}}let y=S.fromData(p,l,"float64");if(n){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function da(r,t,e,n=!1){let o=r.dtype,a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(e===void 0)return Na(r,t,n);if(B(o)){let g=i,h=e.data,N=e.offset;if(t===void 0){let v=0,T=0,E=0;if(r.isCContiguous)for(let k=0;k<r.size;k++){let V=Number(h[N+k%e.size]),j=g[(s+k)*2],R=g[(s+k)*2+1];v+=j*V,T+=R*V,E+=V}else for(let k=0;k<r.size;k++){let V=Number(h[N+k%e.size]),j=r.iget(k);v+=j.re*V,T+=j.im*V,E+=V}return E===0?new U(NaN,NaN):new U(v/E,T/E)}let D=t;if(D<0&&(D=u+D),D<0||D>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let x=Array.from(a).filter((v,T)=>T!==D);if(x.length===0)return da(r,void 0,e);let C=x.reduce((v,T)=>v*T,1),w=a[D],_=S.zeros(x,o),I=_.data;for(let v=0;v<C;v++){let T=0,E=0,$=0;for(let k=0;k<w;k++){let V=G(v,D,k,a),j=Z(V,c,s),R=Number(h[N+k%e.size]),Y=g[j*2],X=g[j*2+1];T+=Y*R,E+=X*R,$+=R}$===0?(I[v*2]=NaN,I[v*2+1]=NaN):(I[v*2]=T/$,I[v*2+1]=E/$)}if(n){let v=[...a];return v[D]=1,S.fromData(I,v,o)}return _}let l=e.offset;if(t===void 0){let g=0,h=0,N=e.data;if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=Number(N[l+x%e.size]);g+=Number(i[s+x])*C,h+=C}else for(let x=0;x<r.size;x++){let C=Number(N[l+x%e.size]);g+=Number(r.iget(x))*C,h+=C}return h===0?NaN:g/h}let f=t;if(f<0&&(f=u+f),f<0||f>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let m=Array.from(a).filter((g,h)=>h!==f);if(m.length===0)return da(r,void 0,e);let p=m.reduce((g,h)=>g*h,1),y=a[f],d=e.data,b=new Float64Array(p);for(let g=0;g<p;g++){let h=0,N=0;for(let D=0;D<y;D++){let x=G(g,f,D,a),C=Z(x,c,s),w=Number(d[l+D%e.size]);h+=Number(i[C])*w,N+=w}b[g]=N===0?NaN:h/N}let A=S.fromData(b,m,"float64");if(n){let g=[...a];return g[f]=1,S.fromData(b,g,"float64")}return A}function ar(r,t){return isNaN(r)||isNaN(t)}function bu(r,t,e=!1){let n=r.dtype,o=B(n),a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(t===void 0){if(o){let g=i,h=0,N=0;if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=g[(s+x)*2],w=g[(s+x)*2+1];ar(C,w)||(h+=C,N+=w)}else for(let x=0;x<r.size;x++){let C=r.iget(x),w=C.re,_=C.im;ar(w,_)||(h+=w,N+=_)}return new U(h,N)}let b=0;if(r.isCContiguous)for(let g=0;g<r.size;g++){let h=Number(i[s+g]);isNaN(h)||(b+=h)}else for(let g=0;g<r.size;g++){let h=Number(r.iget(g));isNaN(h)||(b+=h)}return b}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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return bu(r);let m=f.reduce((b,A)=>b*A,1),p=a[l];if(o){let b=i,A=new Float64Array(m*2);for(let g=0;g<m;g++){let h=0,N=0;for(let D=0;D<p;D++){let x=G(g,l,D,a),C=Z(x,c,s),w=b[C*2],_=b[C*2+1];ar(w,_)||(h+=w,N+=_)}A[g*2]=h,A[g*2+1]=N}if(e){let g=[...a];return g[l]=1,S.fromData(A,g,n)}return S.fromData(A,f,n)}let y=new Float64Array(m);for(let b=0;b<m;b++){let A=0;for(let g=0;g<p;g++){let h=G(b,l,g,a),N=Z(h,c,s),D=Number(i[N]);isNaN(D)||(A+=D)}y[b]=A}let d=S.fromData(y,f,"float64");if(e){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function Au(r,t,e=!1){let n=r.dtype,o=B(n),a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(t===void 0){if(o){let g=i,h=1,N=0;if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=g[(s+x)*2],w=g[(s+x)*2+1];if(!ar(C,w)){let _=h*C-N*w,I=h*w+N*C;h=_,N=I}}else for(let x=0;x<r.size;x++){let C=r.iget(x),w=C.re,_=C.im;if(!ar(w,_)){let I=h*w-N*_,v=h*_+N*w;h=I,N=v}}return new U(h,N)}let b=1;if(r.isCContiguous)for(let g=0;g<r.size;g++){let h=Number(i[s+g]);isNaN(h)||(b*=h)}else for(let g=0;g<r.size;g++){let h=Number(r.iget(g));isNaN(h)||(b*=h)}return b}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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return Au(r);let m=f.reduce((b,A)=>b*A,1),p=a[l];if(o){let b=i,A=new Float64Array(m*2);for(let g=0;g<m;g++){let h=1,N=0;for(let D=0;D<p;D++){let x=G(g,l,D,a),C=Z(x,c,s),w=b[C*2],_=b[C*2+1];if(!ar(w,_)){let I=h*w-N*_,v=h*_+N*w;h=I,N=v}}A[g*2]=h,A[g*2+1]=N}if(e){let g=[...a];return g[l]=1,S.fromData(A,g,n)}return S.fromData(A,f,n)}let y=new Float64Array(m);for(let b=0;b<m;b++){let A=1;for(let g=0;g<p;g++){let h=G(b,l,g,a),N=Z(h,c,s),D=Number(i[N]);isNaN(D)||(A*=D)}y[b]=A}let d=S.fromData(y,f,"float64");if(e){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function gu(r,t,e=!1){let n=r.dtype,o=B(n),a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(t===void 0){if(o){let h=i,N=0,D=0,x=0;if(r.isCContiguous)for(let w=0;w<r.size;w++){let _=h[(s+w)*2],I=h[(s+w)*2+1];ar(_,I)||(N+=_,D+=I,x++)}else for(let w=0;w<r.size;w++){let _=r.iget(w),I=_.re,v=_.im;ar(I,v)||(N+=I,D+=v,x++)}return x===0?new U(NaN,NaN):new U(N/x,D/x)}let b=0,A=0;if(r.isCContiguous)for(let h=0;h<r.size;h++){let N=Number(i[s+h]);isNaN(N)||(b+=N,A++)}else for(let h=0;h<r.size;h++){let N=Number(r.iget(h));isNaN(N)||(b+=N,A++)}return A===0?NaN:b/A}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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return gu(r);let m=f.reduce((b,A)=>b*A,1),p=a[l];if(o){let b=i,A=new Float64Array(m*2);for(let g=0;g<m;g++){let h=0,N=0,D=0;for(let x=0;x<p;x++){let C=G(g,l,x,a),w=Z(C,c,s),_=b[w*2],I=b[w*2+1];ar(_,I)||(h+=_,N+=I,D++)}D===0?(A[g*2]=NaN,A[g*2+1]=NaN):(A[g*2]=h/D,A[g*2+1]=N/D)}if(e){let g=[...a];return g[l]=1,S.fromData(A,g,n)}return S.fromData(A,f,n)}let y=new Float64Array(m);for(let b=0;b<m;b++){let A=0,g=0;for(let h=0;h<p;h++){let N=G(b,l,h,a),D=Z(N,c,s),x=Number(i[D]);isNaN(x)||(A+=x,g++)}y[b]=g===0?NaN:A/g}let d=S.fromData(y,f,"float64");if(e){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function Ge(r,t,e=0,n=!1){let o=r.dtype,a=r.shape,u=a.length,i=r.data,s=r.offset,c=r.strides;if(B(o)){let b=i;if(t===void 0){let C=0,w=0,_=0,I=r.isCContiguous;if(I)for(let $=0;$<r.size;$++){let k=b[(s+$)*2],V=b[(s+$)*2+1];ar(k,V)||(C+=k,w+=V,_++)}else for(let $=0;$<r.size;$++){let k=r.iget($),V=k.re,j=k.im;ar(V,j)||(C+=V,w+=j,_++)}if(_-e<=0)return NaN;let v=C/_,T=w/_,E=0;if(I)for(let $=0;$<r.size;$++){let k=b[(s+$)*2],V=b[(s+$)*2+1];if(!ar(k,V)){let j=k-v,R=V-T;E+=j*j+R*R}}else for(let $=0;$<r.size;$++){let k=r.iget($),V=k.re,j=k.im;if(!ar(V,j)){let R=V-v,Y=j-T;E+=R*R+Y*Y}}return E/(_-e)}let A=t;if(A<0&&(A=u+A),A<0||A>=u)throw new Error(`axis ${t} is out of bounds for array of dimension ${u}`);let g=Array.from(a).filter((C,w)=>w!==A);if(g.length===0)return Ge(r,void 0,e);let h=g.reduce((C,w)=>C*w,1),N=a[A],D=new Float64Array(h);for(let C=0;C<h;C++){let w=0,_=0,I=0;for(let $=0;$<N;$++){let k=G(C,A,$,a),V=Z(k,c,s),j=b[V*2],R=b[V*2+1];ar(j,R)||(w+=j,_+=R,I++)}if(I-e<=0){D[C]=NaN;continue}let v=w/I,T=_/I,E=0;for(let $=0;$<N;$++){let k=G(C,A,$,a),V=Z(k,c,s),j=b[V*2],R=b[V*2+1];if(!ar(j,R)){let Y=j-v,X=R-T;E+=Y*Y+X*X}}D[C]=E/(I-e)}let x=S.fromData(D,g,"float64");if(n){let C=[...a];return C[A]=1,S.fromData(D,C,"float64")}return x}if(t===void 0){let b=0,A=0,g=r.isCContiguous;if(g)for(let D=0;D<r.size;D++){let x=Number(i[s+D]);isNaN(x)||(b+=x,A++)}else for(let D=0;D<r.size;D++){let x=Number(r.iget(D));isNaN(x)||(b+=x,A++)}if(A-e<=0)return NaN;let h=b/A,N=0;if(g)for(let D=0;D<r.size;D++){let x=Number(i[s+D]);isNaN(x)||(N+=(x-h)**2)}else for(let D=0;D<r.size;D++){let x=Number(r.iget(D));isNaN(x)||(N+=(x-h)**2)}return N/(A-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 f=Array.from(a).filter((b,A)=>A!==l);if(f.length===0)return Ge(r,void 0,e);let m=f.reduce((b,A)=>b*A,1),p=a[l],y=new Float64Array(m);for(let b=0;b<m;b++){let A=0,g=0;for(let D=0;D<p;D++){let x=G(b,l,D,a),C=Z(x,c,s),w=Number(i[C]);isNaN(w)||(A+=w,g++)}if(g-e<=0){y[b]=NaN;continue}let h=A/g,N=0;for(let D=0;D<p;D++){let x=G(b,l,D,a),C=Z(x,c,s),w=Number(i[C]);isNaN(w)||(N+=(w-h)**2)}y[b]=N/(g-e)}let d=S.fromData(y,f,"float64");if(n){let b=[...a];return b[l]=1,S.fromData(y,b,"float64")}return d}function ap(r,t,e=0,n=!1){let o=Ge(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,u=new Float64Array(a.size);for(let i=0;i<a.size;i++)u[i]=Math.sqrt(Number(a.data[i]));return S.fromData(u,[...a.shape],"float64")}function ba(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.data,i=r.offset,s=r.strides;if(B(n)){let d=u;if(t===void 0){let x=1/0,C=1/0,w=!1;if(r.isCContiguous)for(let I=0;I<r.size;I++){let v=d[(i+I)*2],T=d[(i+I)*2+1];isNaN(v)||isNaN(T)||(w?(v<x||v===x&&T<C)&&(x=v,C=T):(x=v,C=T,w=!0))}else for(let I=0;I<r.size;I++){let v=r.iget(I),T=v.re,E=v.im;isNaN(T)||isNaN(E)||(w?(T<x||T===x&&E<C)&&(x=T,C=E):(x=T,C=E,w=!0))}return w?new U(x,C):new U(NaN,NaN)}let b=t;if(b<0&&(b=a+b),b<0||b>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let A=Array.from(o).filter((x,C)=>C!==b);if(A.length===0)return ba(r);let g=A.reduce((x,C)=>x*C,1),h=o[b],N=new Float64Array(g*2);for(let x=0;x<g;x++){let C=1/0,w=1/0,_=!1;for(let I=0;I<h;I++){let v=G(x,b,I,o),T=Z(v,s,i),E=d[T*2],$=d[T*2+1];isNaN(E)||isNaN($)||(_?(E<C||E===C&&$<w)&&(C=E,w=$):(C=E,w=$,_=!0))}N[x*2]=_?C:NaN,N[x*2+1]=_?w:NaN}let D=S.fromData(N,A,n);if(e){let x=[...o];return x[b]=1,S.fromData(N,x,n)}return D}if(t===void 0){let d=1/0;if(r.isCContiguous)for(let A=0;A<r.size;A++){let g=Number(u[i+A]);!isNaN(g)&&g<d&&(d=g)}else for(let A=0;A<r.size;A++){let g=Number(r.iget(A));!isNaN(g)&&g<d&&(d=g)}return d===1/0?NaN:d}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=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return ba(r);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=1/0;for(let A=0;A<m;A++){let g=G(d,c,A,o),h=Z(g,s,i),N=Number(u[h]);!isNaN(N)&&N<b&&(b=N)}p[d]=b===1/0?NaN:b}let y=S.fromData(p,l,"float64");if(e){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function Aa(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,u=r.data,i=r.offset,s=r.strides;if(B(n)){let d=u;if(t===void 0){let x=-1/0,C=-1/0,w=!1;if(r.isCContiguous)for(let I=0;I<r.size;I++){let v=d[(i+I)*2],T=d[(i+I)*2+1];isNaN(v)||isNaN(T)||(w?(v>x||v===x&&T>C)&&(x=v,C=T):(x=v,C=T,w=!0))}else for(let I=0;I<r.size;I++){let v=r.iget(I),T=v.re,E=v.im;isNaN(T)||isNaN(E)||(w?(T>x||T===x&&E>C)&&(x=T,C=E):(x=T,C=E,w=!0))}return w?new U(x,C):new U(NaN,NaN)}let b=t;if(b<0&&(b=a+b),b<0||b>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let A=Array.from(o).filter((x,C)=>C!==b);if(A.length===0)return Aa(r);let g=A.reduce((x,C)=>x*C,1),h=o[b],N=new Float64Array(g*2);for(let x=0;x<g;x++){let C=-1/0,w=-1/0,_=!1;for(let I=0;I<h;I++){let v=G(x,b,I,o),T=Z(v,s,i),E=d[T*2],$=d[T*2+1];isNaN(E)||isNaN($)||(_?(E>C||E===C&&$>w)&&(C=E,w=$):(C=E,w=$,_=!0))}N[x*2]=_?C:NaN,N[x*2+1]=_?w:NaN}let D=S.fromData(N,A,n);if(e){let x=[...o];return x[b]=1,S.fromData(N,x,n)}return D}if(t===void 0){let d=-1/0;if(r.isCContiguous)for(let A=0;A<r.size;A++){let g=Number(u[i+A]);!isNaN(g)&&g>d&&(d=g)}else for(let A=0;A<r.size;A++){let g=Number(r.iget(A));!isNaN(g)&&g>d&&(d=g)}return d===-1/0?NaN:d}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=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return Aa(r);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=-1/0;for(let A=0;A<m;A++){let g=G(d,c,A,o),h=Z(g,s,i),N=Number(u[h]);!isNaN(N)&&N>b&&(b=N)}p[d]=b===-1/0?NaN:b}let y=S.fromData(p,l,"float64");if(e){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function ga(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides;if(B(e)){let p=a;if(t===void 0){let h=1/0,N=1/0,D=-1;if(r.isCContiguous)for(let C=0;C<r.size;C++){let w=p[(u+C)*2],_=p[(u+C)*2+1];!ar(w,_)&&zr(w,_,h,N)<0&&(h=w,N=_,D=C)}else for(let C=0;C<r.size;C++){let w=r.iget(C),_=w.re,I=w.im;!ar(_,I)&&zr(_,I,h,N)<0&&(h=_,N=I,D=C)}return D}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 d=Array.from(n).filter((h,N)=>N!==y);if(d.length===0)return ga(r);let b=d.reduce((h,N)=>h*N,1),A=n[y],g=new Int32Array(b);for(let h=0;h<b;h++){let N=1/0,D=1/0,x=0;for(let C=0;C<A;C++){let w=G(h,y,C,n),_=Z(w,i,u),I=p[_*2],v=p[_*2+1];!ar(I,v)&&zr(I,v,N,D)<0&&(N=I,D=v,x=C)}g[h]=x}return S.fromData(g,d,"int32")}if(t===void 0){let p=1/0,y=-1;if(r.isCContiguous)for(let b=0;b<r.size;b++){let A=Number(a[u+b]);!isNaN(A)&&A<p&&(p=A,y=b)}else for(let b=0;b<r.size;b++){let A=Number(r.iget(b));!isNaN(A)&&A<p&&(p=A,y=b)}return y}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 c=Array.from(n).filter((p,y)=>y!==s);if(c.length===0)return ga(r);let l=c.reduce((p,y)=>p*y,1),f=n[s],m=new Int32Array(l);for(let p=0;p<l;p++){let y=1/0,d=0;for(let b=0;b<f;b++){let A=G(p,s,b,n),g=Z(A,i,u),h=Number(a[g]);!isNaN(h)&&h<y&&(y=h,d=b)}m[p]=d}return S.fromData(m,c,"int32")}function ha(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides;if(B(e)){let p=a;if(t===void 0){let h=-1/0,N=-1/0,D=-1;if(r.isCContiguous)for(let C=0;C<r.size;C++){let w=p[(u+C)*2],_=p[(u+C)*2+1];!ar(w,_)&&zr(w,_,h,N)>0&&(h=w,N=_,D=C)}else for(let C=0;C<r.size;C++){let w=r.iget(C),_=w.re,I=w.im;!ar(_,I)&&zr(_,I,h,N)>0&&(h=_,N=I,D=C)}return D}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 d=Array.from(n).filter((h,N)=>N!==y);if(d.length===0)return ha(r);let b=d.reduce((h,N)=>h*N,1),A=n[y],g=new Int32Array(b);for(let h=0;h<b;h++){let N=-1/0,D=-1/0,x=0;for(let C=0;C<A;C++){let w=G(h,y,C,n),_=Z(w,i,u),I=p[_*2],v=p[_*2+1];!ar(I,v)&&zr(I,v,N,D)>0&&(N=I,D=v,x=C)}g[h]=x}return S.fromData(g,d,"int32")}if(t===void 0){let p=-1/0,y=-1;if(r.isCContiguous)for(let b=0;b<r.size;b++){let A=Number(a[u+b]);!isNaN(A)&&A>p&&(p=A,y=b)}else for(let b=0;b<r.size;b++){let A=Number(r.iget(b));!isNaN(A)&&A>p&&(p=A,y=b)}return y}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 c=Array.from(n).filter((p,y)=>y!==s);if(c.length===0)return ha(r);let l=c.reduce((p,y)=>p*y,1),f=n[s],m=new Int32Array(l);for(let p=0;p<l;p++){let y=-1/0,d=0;for(let b=0;b<f;b++){let A=G(p,s,b,n),g=Z(A,i,u),h=Number(a[g]);!isNaN(h)&&h>y&&(y=h,d=b)}m[p]=d}return S.fromData(m,c,"int32")}function sp(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset;if(B(e)){let d=a,b=r.size;if(t===void 0){let I=S.zeros([b],e),v=I.data,T=0,E=0;if(r.isCContiguous)for(let k=0;k<b;k++){let V=d[(u+k)*2],j=d[(u+k)*2+1];ar(V,j)||(T+=V,E+=j),v[k*2]=T,v[k*2+1]=E}else for(let k=0;k<b;k++){let V=r.iget(k),j=V.re,R=V.im;ar(j,R)||(T+=j,E+=R),v[k*2]=T,v[k*2+1]=E}return I}let A=t;if(A<0&&(A=o+A),A<0||A>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=S.zeros([...n],e),h=g.data,N=n[A],D=[],x=1;for(let I=o-1;I>=0;I--)D.unshift(x),x*=n[I];let C=r.size,w=D[A];if(r.isCContiguous)for(let I=0;I<C;I++){let v=d[(u+I)*2],T=d[(u+I)*2+1],E=Math.floor(I/w)%N,$=ar(v,T);E===0?(h[I*2]=$?0:v,h[I*2+1]=$?0:T):(h[I*2]=h[(I-w)*2]+($?0:v),h[I*2+1]=h[(I-w)*2+1]+($?0:T))}else for(let I=0;I<C;I++){let v=r.iget(I),T=v.re,E=v.im,$=Math.floor(I/w)%N,k=ar(T,E);$===0?(h[I*2]=k?0:T,h[I*2+1]=k?0:E):(h[I*2]=h[(I-w)*2]+(k?0:T),h[I*2+1]=h[(I-w)*2+1]+(k?0:E))}return g}if(t===void 0){let d=r.size,b=new Float64Array(d),A=0;if(r.isCContiguous)for(let h=0;h<d;h++){let N=Number(a[u+h]);isNaN(N)||(A+=N),b[h]=A}else for(let h=0;h<d;h++){let N=Number(r.iget(h));isNaN(N)||(A+=N),b[h]=A}return S.fromData(b,[d],"float64")}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 s=new Float64Array(r.size),c=n[i],l=[],f=1;for(let d=o-1;d>=0;d--)l.unshift(f),f*=n[d];let m=r.size,p=l[i];if(r.isCContiguous)for(let d=0;d<m;d++){let b=Number(a[u+d]);Math.floor(d/p)%c===0?s[d]=isNaN(b)?0:b:s[d]=s[d-p]+(isNaN(b)?0:b)}else for(let d=0;d<m;d++){let b=Number(r.iget(d));Math.floor(d/p)%c===0?s[d]=isNaN(b)?0:b:s[d]=s[d-p]+(isNaN(b)?0:b)}return S.fromData(s,[...n],"float64")}function ip(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.data,u=r.offset;if(B(e)){let d=a,b=r.size;if(t===void 0){let I=S.zeros([b],e),v=I.data,T=1,E=0;if(r.isCContiguous)for(let k=0;k<b;k++){let V=d[(u+k)*2],j=d[(u+k)*2+1];if(!ar(V,j)){let R=T*V-E*j,Y=T*j+E*V;T=R,E=Y}v[k*2]=T,v[k*2+1]=E}else for(let k=0;k<b;k++){let V=r.iget(k),j=V.re,R=V.im;if(!ar(j,R)){let Y=T*j-E*R,X=T*R+E*j;T=Y,E=X}v[k*2]=T,v[k*2+1]=E}return I}let A=t;if(A<0&&(A=o+A),A<0||A>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let g=S.zeros([...n],e),h=g.data,N=n[A],D=[],x=1;for(let I=o-1;I>=0;I--)D.unshift(x),x*=n[I];let C=r.size,w=D[A];if(r.isCContiguous)for(let I=0;I<C;I++){let v=d[(u+I)*2],T=d[(u+I)*2+1],E=Math.floor(I/w)%N,$=ar(v,T);if(E===0)h[I*2]=$?1:v,h[I*2+1]=$?0:T;else{let k=h[(I-w)*2],V=h[(I-w)*2+1];$?(h[I*2]=k,h[I*2+1]=V):(h[I*2]=k*v-V*T,h[I*2+1]=k*T+V*v)}}else for(let I=0;I<C;I++){let v=r.iget(I),T=v.re,E=v.im,$=Math.floor(I/w)%N,k=ar(T,E);if($===0)h[I*2]=k?1:T,h[I*2+1]=k?0:E;else{let V=h[(I-w)*2],j=h[(I-w)*2+1];k?(h[I*2]=V,h[I*2+1]=j):(h[I*2]=V*T-j*E,h[I*2+1]=V*E+j*T)}}return g}if(t===void 0){let d=r.size,b=new Float64Array(d),A=1;if(r.isCContiguous)for(let h=0;h<d;h++){let N=Number(a[u+h]);isNaN(N)||(A*=N),b[h]=A}else for(let h=0;h<d;h++){let N=Number(r.iget(h));isNaN(N)||(A*=N),b[h]=A}return S.fromData(b,[d],"float64")}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 s=new Float64Array(r.size),c=n[i],l=[],f=1;for(let d=o-1;d>=0;d--)l.unshift(f),f*=n[d];let m=r.size,p=l[i];if(r.isCContiguous)for(let d=0;d<m;d++){let b=Number(a[u+d]);Math.floor(d/p)%c===0?s[d]=isNaN(b)?1:b:s[d]=s[d-p]*(isNaN(b)?1:b)}else for(let d=0;d<m;d++){let b=Number(r.iget(d));Math.floor(d/p)%c===0?s[d]=isNaN(b)?1:b:s[d]=s[d-p]*(isNaN(b)?1:b)}return S.fromData(s,[...n],"float64")}function hu(r,t,e=!1){L(r.dtype,"nanmedian","Complex numbers are not orderable.");let n=r.shape,o=n.length,a=r.data,u=r.offset,i=r.strides;if(t===void 0){let y=[];if(r.isCContiguous)for(let g=0;g<r.size;g++){let h=Number(a[u+g]);isNaN(h)||y.push(h)}else for(let g=0;g<r.size;g++){let h=Number(r.iget(g));isNaN(h)||y.push(h)}if(y.length===0)return NaN;y.sort((g,h)=>g-h);let b=y.length,A=Math.floor(b/2);return b%2===0?(y[A-1]+y[A])/2:y[A]}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 c=Array.from(n).filter((y,d)=>d!==s);if(c.length===0)return hu(r);let l=c.reduce((y,d)=>y*d,1),f=n[s],m=new Float64Array(l);for(let y=0;y<l;y++){let d=[];for(let g=0;g<f;g++){let h=G(y,s,g,n),N=Z(h,i,u),D=Number(a[N]);isNaN(D)||d.push(D)}if(d.length===0){m[y]=NaN;continue}d.sort((g,h)=>g-h);let b=d.length,A=Math.floor(b/2);b%2===0?m[y]=(d[A-1]+d[A])/2:m[y]=d[A]}let p=S.fromData(m,c,"float64");if(e){let y=[...n];return y[s]=1,S.fromData(m,y,"float64")}return p}function Da(r,t,e,n=!1){if(L(r.dtype,"nanquantile","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,i=r.offset,s=r.strides;if(e===void 0){let d=[];if(r.isCContiguous)for(let x=0;x<r.size;x++){let C=Number(u[i+x]);isNaN(C)||d.push(C)}else for(let x=0;x<r.size;x++){let C=Number(r.iget(x));isNaN(C)||d.push(C)}if(d.length===0)return NaN;d.sort((x,C)=>x-C);let A=d.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)return d[h];let D=g-h;return d[h]*(1-D)+d[N]*D}let c=e;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let l=Array.from(o).filter((d,b)=>b!==c);if(l.length===0)return Da(r,t);let f=l.reduce((d,b)=>d*b,1),m=o[c],p=new Float64Array(f);for(let d=0;d<f;d++){let b=[];for(let D=0;D<m;D++){let x=G(d,c,D,o),C=Z(x,s,i),w=Number(u[C]);isNaN(w)||b.push(w)}if(b.length===0){p[d]=NaN;continue}b.sort((D,x)=>D-x);let A=b.length,g=t*(A-1),h=Math.floor(g),N=Math.ceil(g);if(h===N)p[d]=b[h];else{let D=g-h;p[d]=b[h]*(1-D)+b[N]*D}}let y=S.fromData(p,l,"float64");if(n){let d=[...o];return d[c]=1,S.fromData(p,d,"float64")}return y}function up(r,t,e,n=!1){return Da(r,t/100,e,n)}function Ze(r,t,e){let n=We(z(r),t,e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Xe(r,t,e){let n=Na(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function Je(r,t,e){let n=lu(z(r),t,e);return typeof n=="number"||typeof n=="bigint"||n instanceof U?n:M(n)}function Ke(r,t,e){let n=wt(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}var Qe=Ke;function He(r,t,e){let n=It(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}var rn=He;function tn(r,t,e){let n=ep(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function en(r,t){let e=fu(z(r),t);return typeof e=="number"?e:M(e)}function nn(r,t){let e=mu(z(r),t);return typeof e=="number"?e:M(e)}function nt(r,t,e,n){let o=pu(z(r),t,e,n);return typeof o=="number"?o:M(o)}var xa=nt;function on(r,t,e,n){let o=Hm(z(r),t,e,n);return typeof o=="number"?o:M(o)}function an(r,t,e){let n=np(z(r),t,e);return typeof n=="number"?n:M(n)}function sn(r,t,e,n){let o=op(z(r),t,e,n);return typeof o=="number"?o:M(o)}function un(r,t,e,n){let o=Ye(z(r),t,e,n);return typeof o=="number"?o:M(o)}function cn(r,t,e,n){let o=e?z(e):void 0,a=da(z(r),t,o,n);return typeof a=="number"||a instanceof U?a:M(a)}function ln(r,t,e){let n=yu(z(r),t,e);return typeof n=="boolean"?n:M(n)}function fn(r,t,e){let n=du(z(r),t,e);return typeof n=="boolean"?n:M(n)}function mn(r,t){return M(rp(z(r),t))}function pn(r,t){return M(tp(z(r),t))}function yn(r,t,e){let n=bu(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function dn(r,t,e){let n=Au(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function bn(r,t,e){let n=gu(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function An(r,t,e,n){let o=Ge(z(r),t,e,n);return typeof o=="number"?o:M(o)}function gn(r,t,e,n){let o=ap(z(r),t,e,n);return typeof o=="number"?o:M(o)}function hn(r,t,e){let n=ba(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function Nn(r,t,e){let n=Aa(z(r),t,e);return typeof n=="number"||n instanceof U?n:M(n)}function Dn(r,t){let e=ga(z(r),t);return typeof e=="number"?e:M(e)}function xn(r,t){let e=ha(z(r),t);return typeof e=="number"?e:M(e)}function Cn(r,t){return M(sp(z(r),t))}function Sn(r,t){return M(ip(z(r),t))}function wn(r,t,e){let n=hu(z(r),t,e);return typeof n=="number"?n:M(n)}function In(r,t,e,n){let o=Da(z(r),t,e,n);return typeof o=="number"?o:M(o)}function zn(r,t,e,n){let o=up(z(r),t,e,n);return typeof o=="number"?o:M(o)}function _t(r){return r!==0&&r!==0n}function Rr(r,t){let e=r[t*2],n=r[t*2+1];return e!==0||n!==0}function _n(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function lp(r,t){return typeof t=="number"?ED(r,t):_n(r,t)?OD(r,t):Ir(r,t,(e,n)=>_t(e)&&_t(n))}function OD(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.offset,u=t.offset,i=r.size,s=O(r.dtype),c=O(t.dtype),l=B(r.dtype),f=B(t.dtype);if(l||f)for(let m=0;m<i;m++){let p=l?Rr(n,a+m):n[a+m]!==0,y=f?Rr(o,u+m):o[u+m]!==0;e[m]=p&&y?1:0}else if(s||c)for(let m=0;m<i;m++){let p=s?n[a+m]!==0n:n[a+m]!==0,y=c?o[u+m]!==0n:o[u+m]!==0;e[m]=p&&y?1:0}else for(let m=0;m<i;m++)e[m]=n[a+m]!==0&&o[u+m]!==0?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function ED(r,t){let e=new Uint8Array(r.size),n=t!==0,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(B(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=Rr(i,u+s)&&n?1:0}else if(O(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=i[u+s]!==0n&&n?1:0}else if(u===0)for(let i=0;i<o;i++)e[i]=a[i]!==0&&n?1:0;else for(let i=0;i<o;i++)e[i]=a[u+i]!==0&&n?1:0}else if(B(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a);e[a]=(u.re!==0||u.im!==0)&&n?1:0}else if(O(r.dtype))for(let a=0;a<o;a++)e[a]=r.iget(a)!==0n&&n?1:0;else for(let a=0;a<o;a++)e[a]=Number(r.iget(a))!==0&&n?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function fp(r,t){if(typeof t=="number")return cp(r,t);if(t.size===1&&!B(t.dtype)&&r.dtype===t.dtype){let e=Number(t.iget(0));return cp(r,e)}return _n(r,t)?UD(r,t):Ir(r,t,(e,n)=>_t(e)||_t(n))}function UD(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.offset,u=t.offset,i=r.size,s=O(r.dtype),c=O(t.dtype),l=B(r.dtype),f=B(t.dtype);if(l||f)for(let m=0;m<i;m++){let p=l?Rr(n,a+m):n[a+m]!==0,y=f?Rr(o,u+m):o[u+m]!==0;e[m]=p||y?1:0}else if(s||c)for(let m=0;m<i;m++){let p=s?n[a+m]!==0n:n[a+m]!==0,y=c?o[u+m]!==0n:o[u+m]!==0;e[m]=p||y?1:0}else for(let m=0;m<i;m++)e[m]=n[a+m]!==0||o[u+m]!==0?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function cp(r,t){let e=new Uint8Array(r.size),n=t!==0,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(B(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=Rr(i,u+s)||n?1:0}else if(O(r.dtype)){let i=a;for(let s=0;s<o;s++)e[s]=i[u+s]!==0n||n?1:0}else if(u===0)for(let i=0;i<o;i++)e[i]=a[i]!==0||n?1:0;else for(let i=0;i<o;i++)e[i]=a[u+i]!==0||n?1:0}else if(B(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a);e[a]=u.re!==0||u.im!==0||n?1:0}else if(O(r.dtype))for(let a=0;a<o;a++)e[a]=r.iget(a)!==0n||n?1:0;else for(let a=0;a<o;a++)e[a]=Number(r.iget(a))!==0||n?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function mp(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++)t[u]=Rr(a,o+u)?0:1}else if(O(r.dtype)){let a=n;for(let u=0;u<e;u++)t[u]=a[o+u]===0n?1:0}else if(o===0)for(let a=0;a<e;a++)t[a]=n[a]===0?1:0;else for(let a=0;a<e;a++)t[a]=n[o+a]===0?1:0}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n);t[n]=o.re===0&&o.im===0?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=r.iget(n)===0n?1:0;else for(let n=0;n<e;n++)t[n]=Number(r.iget(n))===0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function pp(r,t){return typeof t=="number"?kD(r,t):_n(r,t)?$D(r,t):Ir(r,t,(e,n)=>_t(e)!==_t(n))}function $D(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.offset,u=t.offset,i=r.size,s=O(r.dtype),c=O(t.dtype),l=B(r.dtype),f=B(t.dtype);if(l||f)for(let m=0;m<i;m++){let p=l?Rr(n,a+m):n[a+m]!==0,y=f?Rr(o,u+m):o[u+m]!==0;e[m]=p!==y?1:0}else if(s||c)for(let m=0;m<i;m++){let p=s?n[a+m]!==0n:n[a+m]!==0,y=c?o[u+m]!==0n:o[u+m]!==0;e[m]=p!==y?1:0}else for(let m=0;m<i;m++){let p=n[a+m]!==0,y=o[u+m]!==0;e[m]=p!==y?1:0}return S.fromData(e,Array.from(r.shape),"bool")}function kD(r,t){let e=new Uint8Array(r.size),n=t!==0,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(B(r.dtype)){let i=a;for(let s=0;s<o;s++){let c=Rr(i,u+s);e[s]=c!==n?1:0}}else if(O(r.dtype)){let i=a;for(let s=0;s<o;s++){let c=i[u+s]!==0n;e[s]=c!==n?1:0}}else if(u===0)for(let i=0;i<o;i++){let s=a[i]!==0;e[i]=s!==n?1:0}else for(let i=0;i<o;i++){let s=a[u+i]!==0;e[i]=s!==n?1:0}}else if(B(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a),i=u.re!==0||u.im!==0;e[a]=i!==n?1:0}else if(O(r.dtype))for(let a=0;a<o;a++){let u=r.iget(a)!==0n;e[a]=u!==n?1:0}else for(let a=0;a<o;a++){let u=Number(r.iget(a))!==0;e[a]=u!==n?1:0}return S.fromData(e,Array.from(r.shape),"bool")}function yp(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++){let i=a[(o+u)*2],s=a[(o+u)*2+1];t[u]=Number.isFinite(i)&&Number.isFinite(s)?1:0}}else if(O(r.dtype))for(let a=0;a<e;a++)t[a]=1;else if(o===0)for(let a=0;a<e;a++)t[a]=Number.isFinite(n[a])?1:0;else for(let a=0;a<e;a++){let u=n[o+a];t[a]=Number.isFinite(u)?1:0}}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n);t[n]=Number.isFinite(o.re)&&Number.isFinite(o.im)?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=1;else for(let n=0;n<e;n++)t[n]=Number.isFinite(Number(r.iget(n)))?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function dp(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++){let i=a[(o+u)*2],s=a[(o+u)*2+1],c=!Number.isFinite(i)&&!Number.isNaN(i),l=!Number.isFinite(s)&&!Number.isNaN(s);t[u]=c||l?1:0}}else if(O(r.dtype))for(let a=0;a<e;a++)t[a]=0;else if(o===0)for(let a=0;a<e;a++){let u=n[a];t[a]=!Number.isFinite(u)&&!Number.isNaN(u)?1:0}else for(let a=0;a<e;a++){let u=n[o+a];t[a]=!Number.isFinite(u)&&!Number.isNaN(u)?1:0}}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n),a=!Number.isFinite(o.re)&&!Number.isNaN(o.re),u=!Number.isFinite(o.im)&&!Number.isNaN(o.im);t[n]=a||u?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=0;else for(let n=0;n<e;n++){let o=Number(r.iget(n));t[n]=!Number.isFinite(o)&&!Number.isNaN(o)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function bp(r){let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(B(r.dtype)){let a=n;for(let u=0;u<e;u++){let i=a[(o+u)*2],s=a[(o+u)*2+1];t[u]=Number.isNaN(i)||Number.isNaN(s)?1:0}}else if(O(r.dtype))for(let a=0;a<e;a++)t[a]=0;else for(let a=0;a<e;a++)t[a]=Number.isNaN(n[o+a])?1:0}else if(B(r.dtype))for(let n=0;n<e;n++){let o=r.iget(n);t[n]=Number.isNaN(o.re)||Number.isNaN(o.im)?1:0}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=0;else for(let n=0;n<e;n++)t[n]=Number.isNaN(Number(r.iget(n)))?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function Ap(r){let t=new Uint8Array(r.size);return S.fromData(t,Array.from(r.shape),"bool")}function gp(r,t){if(L(r.dtype,"copysign","copysign is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"copysign","copysign is only defined for real numbers."),typeof t=="number")return qD(r,t);if(_n(r,t))return RD(r,t);let e=Zr(r.shape,t.shape),n=e.reduce((s,c)=>s*c,1),o=S.zeros(e,"float64"),a=o.data,u=Ca(r,e),i=Ca(t,e);for(let s=0;s<n;s++){let c=Number(u.iget(s)),l=Number(i.iget(s));a[s]=Math.sign(l)*Math.abs(c)}return o}function RD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=O(r.dtype),l=O(t.dtype);for(let f=0;f<o;f++){let m=c?Number(a[i+f]):a[i+f],p=l?Number(u[s+f]):u[s+f];n[f]=Math.sign(p)*Math.abs(m)}return e}function qD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=Math.sign(t);if(!r.isCContiguous){for(let s=0;s<o;s++)n[s]=a*Math.abs(Number(r.iget(s)));return e}let u=r.data,i=r.offset;if(O(r.dtype)){let s=u;for(let c=0;c<o;c++)n[c]=a*Math.abs(Number(s[i+c]))}else if(i===0)for(let s=0;s<o;s++)n[s]=a*Math.abs(u[s]);else for(let s=0;s<o;s++)n[s]=a*Math.abs(u[i+s]);return e}function hp(r){L(r.dtype,"signbit","signbit is only defined for real numbers.");let t=new Uint8Array(r.size),e=r.size;if(r.isCContiguous){let n=r.data,o=r.offset;if(O(r.dtype)){let a=n;for(let u=0;u<e;u++)t[u]=a[o+u]<0n?1:0}else for(let a=0;a<e;a++){let u=n[o+a];t[a]=u<0||Object.is(u,-0)?1:0}}else if(O(r.dtype))for(let n=0;n<e;n++)t[n]=r.iget(n)<0n?1:0;else for(let n=0;n<e;n++){let o=Number(r.iget(n));t[n]=o<0||Object.is(o,-0)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function Np(r,t){if(L(r.dtype,"nextafter","nextafter is only defined for real numbers."),typeof t!="number"&&L(t.dtype,"nextafter","nextafter is only defined for real numbers."),typeof t=="number")return PD(r,t);if(_n(r,t))return VD(r,t);let e=Zr(r.shape,t.shape),n=e.reduce((s,c)=>s*c,1),o=S.zeros(e,"float64"),a=o.data,u=Ca(r,e),i=Ca(t,e);for(let s=0;s<n;s++){let c=Number(u.iget(s)),l=Number(i.iget(s));a[s]=zt(c,l)}return o}function VD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=O(r.dtype),l=O(t.dtype);for(let f=0;f<o;f++){let m=c?Number(a[i+f]):a[i+f],p=l?Number(u[s+f]):u[s+f];n[f]=zt(m,p)}return e}function PD(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size;if(r.isCContiguous){let a=r.data,u=r.offset;if(O(r.dtype)){let i=a;for(let s=0;s<o;s++)n[s]=zt(Number(i[u+s]),t)}else for(let i=0;i<o;i++)n[i]=zt(a[u+i],t)}else for(let a=0;a<o;a++)n[a]=zt(Number(r.iget(a)),t);return e}function zt(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 Dp(r){L(r.dtype,"spacing","spacing is only defined for real numbers.");let t=S.zeros(Array.from(r.shape),"float64"),e=t.data,n=r.size;if(r.isCContiguous){let o=r.data,a=r.offset;if(O(r.dtype)){let u=o;for(let i=0;i<n;i++)e[i]=Nu(Number(u[a+i]))}else for(let u=0;u<n;u++)e[u]=Nu(o[a+u])}else for(let o=0;o<n;o++)e[o]=Nu(Number(r.iget(o)));return t}function Nu(r){if(Number.isNaN(r))return NaN;if(!Number.isFinite(r))return NaN;if(Math.abs(r)===0)return Number.MIN_VALUE;let e=zt(r,1/0);return Math.abs(e-r)}function Ca(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,i=r.shape[a],s=t[u];if(i===s)o[u]=r.strides[a];else if(i===1)o[u]=0;else throw new Error("Invalid broadcast")}return S.fromData(r.data,Array.from(t),r.dtype,o,r.offset)}function xp(r){let t=r.dtype,e=r.size,n=new Uint8Array(e);if(B(t))if(r.isCContiguous){let o=r.offset,a=r.data;for(let u=0;u<e;u++)n[u]=a[(o+u)*2+1]!==0?1:0}else for(let o=0;o<e;o++){let a=r.iget(o);n[o]=a.im!==0?1:0}return S.fromData(n,Array.from(r.shape),"bool")}function Cp(r){return B(r.dtype)}function Sp(r){let t=r.dtype,e=r.size,n=new Uint8Array(e);if(B(t))if(r.isCContiguous){let o=r.offset,a=r.data;for(let u=0;u<e;u++)n[u]=a[(o+u)*2+1]===0?1:0}else for(let o=0;o<e;o++){let a=r.iget(o);n[o]=a.im===0?1:0}else n.fill(1);return S.fromData(n,Array.from(r.shape),"bool")}function wp(r){return!B(r.dtype)}function Ip(r){L(r.dtype,"isneginf","This operation is not supported for complex values because it would be ambiguous.");let t=new Uint8Array(r.size),e=r.size;if(!O(r.dtype))if(r.isCContiguous){let n=r.data,o=r.offset;for(let a=0;a<e;a++){let u=n[o+a];t[a]=u===-1/0?1:0}}else for(let n=0;n<e;n++)t[n]=Number(r.iget(n))===-1/0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function zp(r){L(r.dtype,"isposinf","This operation is not supported for complex values because it would be ambiguous.");let t=new Uint8Array(r.size),e=r.size;if(!O(r.dtype))if(r.isCContiguous){let n=r.data,o=r.offset;for(let a=0;a<e;a++){let u=n[o+a];t[a]=u===1/0?1:0}}else for(let n=0;n<e;n++)t[n]=Number(r.iget(n))===1/0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function _p(r){return r.isFContiguous}function vp(r,t=100){let e=r.dtype;if(B(e)){let n=r.size,a=t*(e==="complex64"?11920929e-14:2220446049250313e-31);if(r.isCContiguous){let u=r.data,i=r.offset,s=!0;for(let c=0;c<n;c++){let l=u[(i+c)*2+1];if(Math.abs(l)>a){s=!1;break}}if(s){let c=e==="complex64"?"float32":"float64",l=S.zeros(Array.from(r.shape),c),f=l.data;for(let m=0;m<n;m++)f[m]=u[(i+m)*2];return l}}else{let u=!0;for(let i=0;i<n;i++){let s=r.iget(i);if(Math.abs(s.im)>a){u=!1;break}}if(u){let i=e==="complex64"?"float32":"float64",s=S.zeros(Array.from(r.shape),i),c=s.data;for(let l=0;l<n;l++){let f=r.iget(l);c[l]=f.re}return s}}return r.copy()}return r.copy()}function Mp(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"||typeof r=="string"}function Fp(r){return r==null?!1:typeof r[Symbol.iterator]=="function"}function Bp(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 Tp(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 qr(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,i=u<0?1:a[u];if(i!==1){if(o===1)o=i;else if(o!==i)return null}}e[n]=o}return e}function LD(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let i=o-n+u,s=r[u],c=e[i];if(s===c)a[i]=t[u];else if(s===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function _r(r,t){let e=LD(r.shape,r.strides,t);return S.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function ot(r,t){return[r[t*2],r[t*2+1]]}function Op(r,t){if(B(r.dtype))return ot(r.data,t);let e=r.iget(t);return e instanceof U?[e.re,e.im]:[Number(e),0]}function vt(r,t,e){let n=qr([Array.from(r.shape),Array.from(t.shape)]);if(!n)throw new Error("Cannot broadcast arrays together");let o=_r(r,n),a=_r(t,n),u=n.reduce((s,c)=>s*c,1),i=new Uint8Array(u);for(let s=0;s<u;s++){let[c,l]=Op(o,s),[f,m]=Op(a,s);i[s]=e(c,l,f,m)?1:0}return S.fromData(i,n,"bool")}function Ep(r,t){return typeof t=="number"?WD(r,t):B(r.dtype)||B(t.dtype)?vt(r,t,(e,n,o,a)=>e!==o?e>o:n>a):Ir(r,t,(e,n)=>e>n)}function Up(r,t){return typeof t=="number"?GD(r,t):B(r.dtype)||B(t.dtype)?vt(r,t,(e,n,o,a)=>e!==o?e>=o:n>=a):Ir(r,t,(e,n)=>e>=n)}function $p(r,t){return typeof t=="number"?YD(r,t):B(r.dtype)||B(t.dtype)?vt(r,t,(e,n,o,a)=>e!==o?e<o:n<a):Ir(r,t,(e,n)=>e<n)}function kp(r,t){return typeof t=="number"?ZD(r,t):B(r.dtype)||B(t.dtype)?vt(r,t,(e,n,o,a)=>e!==o?e<=o:n<=a):Ir(r,t,(e,n)=>e<=n)}function Rp(r,t){return typeof t=="number"?XD(r,t):B(r.dtype)||B(t.dtype)?vt(r,t,(e,n,o,a)=>e===o&&n===a):Ir(r,t,(e,n)=>e===n)}function qp(r,t){return typeof t=="number"?JD(r,t):B(r.dtype)||B(t.dtype)?vt(r,t,(e,n,o,a)=>e!==o||n!==a):Ir(r,t,(e,n)=>e!==n)}function Du(r,t,e=1e-5,n=1e-8){return typeof t=="number"?KD(r,t,e,n):Ir(r,t,(o,a)=>{let u=Math.abs(o-a),i=n+e*Math.abs(a);return u<=i})}function Vp(r,t,e=1e-5,n=1e-8){let o=Du(r,t,e,n),a=o.data;for(let u=0;u<o.size;u++)if(a[u]===0)return!1;return!0}function Pp(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=qr(e);if(n===null)return!1;let o=_r(r,n),a=_r(t,n),u=n.length,i=n.reduce((l,f)=>l*f,1),s=O(o.dtype),c=O(a.dtype);for(let l=0;l<i;l++){let f=l,m=new Array(u);for(let d=u-1;d>=0;d--)m[d]=f%n[d],f=Math.floor(f/n[d]);let p=o.get(...m),y=a.get(...m);if(s||c){let d=typeof p=="bigint"?p:BigInt(Number(p)),b=typeof y=="bigint"?y:BigInt(Number(y));if(d!==b)return!1}else if(p!==y)return!1}return!0}function WD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s>t:c>0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re>t:u.im>0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]>t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))>t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function GD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s>=t:c>=0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re>=t:u.im>=0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]>=t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))>=t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function YD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s<t:c<0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re<t:u.im<0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]<t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))<t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function ZD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.isCContiguous;if(B(r.dtype))if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++){let[s,c]=ot(a,u+i);e[i]=(s!==t?s<=t:c<=0)?1:0}}else for(let a=0;a<n;a++){let u=r.iget(a);e[a]=(u.re!==t?u.re<=t:u.im<=0)?1:0}else if(o){let a=r.data,u=r.offset;for(let i=0;i<n;i++)e[i]=a[u+i]<=t?1:0}else for(let a=0;a<n;a++)e[a]=Number(r.iget(a))<=t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function XD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.dtype,a=r.isCContiguous;if(B(o))if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++){let[c,l]=ot(u,i+s);e[s]=c===t&&l===0?1:0}}else for(let u=0;u<n;u++){let i=r.iget(u);e[u]=i.re===t&&i.im===0?1:0}else if(O(o)){let u=BigInt(Math.round(t));if(a){let i=r.data,s=r.offset;for(let c=0;c<n;c++)e[c]=i[s+c]===u?1:0}else for(let i=0;i<n;i++)e[i]=r.iget(i)===u?1:0}else if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++)e[s]=u[i+s]===t?1:0}else for(let u=0;u<n;u++)e[u]=Number(r.iget(u))===t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function JD(r,t){let e=new Uint8Array(r.size),n=r.size,o=r.dtype,a=r.isCContiguous;if(B(o))if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++){let[c,l]=ot(u,i+s);e[s]=c!==t||l!==0?1:0}}else for(let u=0;u<n;u++){let i=r.iget(u);e[u]=i.re!==t||i.im!==0?1:0}else if(a){let u=r.data,i=r.offset;for(let s=0;s<n;s++)e[s]=u[i+s]!==t?1:0}else for(let u=0;u<n;u++)e[u]=Number(r.iget(u))!==t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function KD(r,t,e,n){let o=new Uint8Array(r.size),a=r.size,u=n+e*Math.abs(t);if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<a;c++){let l=Math.abs(Number(i[s+c])-t);o[c]=l<=u?1:0}}else for(let i=0;i<a;i++){let s=Math.abs(Number(r.iget(i))-t);o[i]=s<=u?1:0}return S.fromData(o,Array.from(r.shape),"bool")}function vn(r,t){let e=typeof t=="number"?t:z(t);return M(lp(z(r),e))}function Mn(r,t){let e=typeof t=="number"?t:z(t);return M(fp(z(r),e))}function Fn(r){return M(mp(z(r)))}function Bn(r,t){let e=typeof t=="number"?t:z(t);return M(pp(z(r),e))}function Tn(r){return M(yp(z(r)))}function On(r){return M(dp(z(r)))}function En(r){return M(bp(z(r)))}function Un(r){return M(Ap(z(r)))}function xu(r){return M(Ip(z(r)))}function Cu(r){return M(zp(z(r)))}function Su(r){return M(xp(z(r)))}function Sa(r){return Cp(z(r))}function wu(r){return M(Sp(z(r)))}function wa(r){return wp(z(r))}function Iu(r,t){return M(vp(z(r),t))}function Ia(r){return _p(z(r))}function za(r){return Mp(r)}function _a(r){return Fp(r)}function va(r,t){return Bp(r,t)}function Ma(r,t){return Tp(r,t)}function $n(r,t){let e=typeof t=="number"?t:z(t);return M(gp(z(r),e))}function kn(r){return M(hp(z(r)))}function Rn(r,t){let e=typeof t=="number"?t:z(t);return M(Np(z(r),e))}function qn(r){return M(Dp(z(r)))}function Vn(r,t){return M(Ep(z(r),typeof t=="number"?t:z(t)))}function Pn(r,t){return M(Up(z(r),typeof t=="number"?t:z(t)))}function jn(r,t){return M($p(z(r),typeof t=="number"?t:z(t)))}function Ln(r,t){return M(kp(z(r),typeof t=="number"?t:z(t)))}function Wn(r,t){return M(Rp(z(r),typeof t=="number"?t:z(t)))}function Gn(r,t){return M(qp(z(r),typeof t=="number"?t:z(t)))}function Yn(r,t,e=1e-5,n=1e-8){return M(Du(z(r),typeof t=="number"?t:z(t),e,n))}function Mt(r,t,e=1e-5,n=1e-8){return Vp(z(r),typeof t=="number"?t:z(t),e,n)}function gr(r,t,e){if(e){let n=r[t*2],o=r[t*2+1];return n!==0||o!==0}return!!r[t]}function at(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 Lp(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data,u=r.offset,i=r.strides;if(n===0)return r.copy();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 c=r.copy(),l=c.data,f=e[s],m=Array.from(e).filter((y,d)=>d!==s),p=m.length===0?1:m.reduce((y,d)=>y*d,1);if(B(o)){let y=a,d=l;for(let b=0;b<p;b++){let A=[];for(let g=0;g<f;g++){let h=G(b,s,g,e),N=Z(h,i,u);A.push({re:y[N*2],im:y[N*2+1],idx:g})}A.sort((g,h)=>at(g.re,g.im,h.re,h.im));for(let g=0;g<f;g++){let h=G(b,s,g,e),N=xr(h,e);d[N*2]=A[g].re,d[N*2+1]=A[g].im}}}else if(O(o)){let y=a,d=l;for(let b=0;b<p;b++){let A=[];for(let g=0;g<f;g++){let h=G(b,s,g,e),N=Z(h,i,u);A.push({value:y[N],idx:g})}A.sort((g,h)=>g.value<h.value?-1:g.value>h.value?1:0);for(let g=0;g<f;g++){let h=G(b,s,g,e),N=xr(h,e);d[N]=A[g].value}}}else for(let y=0;y<p;y++){let d=[];for(let b=0;b<f;b++){let A=G(y,s,b,e),g=Z(A,i,u);d.push(Number(a[g]))}d.sort((b,A)=>isNaN(b)&&isNaN(A)?0:isNaN(b)?1:isNaN(A)?-1:b-A);for(let b=0;b<f;b++){let A=G(y,s,b,e),g=xr(A,e);l[g]=d[b]}}return c}function Wp(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data,u=r.offset,i=r.strides;if(n===0)return S.zeros([0],"int32");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 c=S.zeros(Array.from(e),"int32"),l=c.data,f=e[s],m=Array.from(e).filter((y,d)=>d!==s),p=m.length===0?1:m.reduce((y,d)=>y*d,1);if(B(o)){let y=a;for(let d=0;d<p;d++){let b=[];for(let A=0;A<f;A++){let g=G(d,s,A,e),h=Z(g,i,u);b.push({re:y[h*2],im:y[h*2+1],idx:A})}b.sort((A,g)=>at(A.re,A.im,g.re,g.im));for(let A=0;A<f;A++){let g=G(d,s,A,e),h=xr(g,e);l[h]=b[A].idx}}}else if(O(o)){let y=a;for(let d=0;d<p;d++){let b=[];for(let A=0;A<f;A++){let g=G(d,s,A,e),h=Z(g,i,u);b.push({value:y[h],idx:A})}b.sort((A,g)=>A.value<g.value?-1:A.value>g.value?1:0);for(let A=0;A<f;A++){let g=G(d,s,A,e),h=xr(g,e);l[h]=b[A].idx}}}else for(let y=0;y<p;y++){let d=[];for(let b=0;b<f;b++){let A=G(y,s,b,e),g=Z(A,i,u);d.push({value:Number(a[g]),idx:b})}d.sort((b,A)=>isNaN(b.value)&&isNaN(A.value)?0:isNaN(b.value)?1:isNaN(A.value)?-1:b.value-A.value);for(let b=0;b<f;b++){let A=G(y,s,b,e),g=xr(A,e);l[g]=d[b].idx}}return c}function Gp(r){if(r.length===0)return S.zeros([0],"int32");let e=r[0].size;for(let l of r){if(l.ndim!==1)throw new Error("keys must be 1D arrays");if(l.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let l=0;l<e;l++)n.push(l);let o=r.map(l=>B(l.dtype)),a=r.map(l=>l.isCContiguous),u=r.map(l=>l.data),i=r.map(l=>l.offset);n.sort((l,f)=>{for(let m=r.length-1;m>=0;m--)if(o[m]){let p,y,d,b;if(a[m]){let A=u[m],g=i[m];p=A[(g+l)*2],y=A[(g+l)*2+1],d=A[(g+f)*2],b=A[(g+f)*2+1]}else{let A=r[m].iget(l),g=r[m].iget(f);p=A.re,y=A.im,d=g.re,b=g.im}if(p<d)return-1;if(p>d)return 1;if(y<b)return-1;if(y>b)return 1}else{let p,y;if(a[m]){let d=u[m],b=i[m];p=Number(d[b+l]),y=Number(d[b+f])}else p=Number(r[m].iget(l)),y=Number(r[m].iget(f));if(isNaN(p)&&isNaN(y))continue;if(isNaN(p))return 1;if(isNaN(y)||p<y)return-1;if(p>y)return 1}return 0});let s=S.zeros([e],"int32"),c=s.data;for(let l=0;l<e;l++)c[l]=n[l];return s}function QD(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],i=r[n],s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++){let m=r[f],p=isNaN(m),y=isNaN(c);!p&&(y||m<=c)&&([r[l],r[f]]=[r[f],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function HD(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],i=r[n],s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++)r[f]<=c&&([r[l],r[f]]=[r[f],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function rx(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,i=r[n].value,s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++){let m=r[f].value,p=isNaN(m),y=isNaN(c);!p&&(y||m<=c)&&([r[l],r[f]]=[r[f],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function tx(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,i=r[n].value,s;a<=u&&u<=i||i<=u&&u<=a?s=o:u<=a&&a<=i||i<=a&&a<=u?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let f=e;f<n;f++)r[f].value<=c&&([r[l],r[f]]=[r[f],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function Yp(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 i=n[u],s=t;if(s<0&&(s=i+s),s<0||s>=i)throw new Error(`kth(=${t}) out of bounds (${i})`);let c=r.copy(),l=c.data,f=Array.from(n).filter((p,y)=>y!==u),m=f.length===0?1:f.reduce((p,y)=>p*y,1);if(O(a)){let p=l;for(let y=0;y<m;y++){let d=[];for(let b=0;b<i;b++){let A=G(y,u,b,n),g=xr(A,n);d.push(p[g])}HD(d,s);for(let b=0;b<i;b++){let A=G(y,u,b,n),g=xr(A,n);p[g]=d[b]}}}else for(let p=0;p<m;p++){let y=[];for(let d=0;d<i;d++){let b=G(p,u,d,n),A=xr(b,n);y.push(Number(l[A]))}QD(y,s);for(let d=0;d<i;d++){let b=G(p,u,d,n),A=xr(b,n);l[A]=y[d]}}return c}function Zp(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,u=r.data,i=r.offset,s=r.strides;if(o===0)return S.zeros([0],"int32");let c=e;if(c<0&&(c=o+c),c<0||c>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let l=n[c],f=t;if(f<0&&(f=l+f),f<0||f>=l)throw new Error(`kth(=${t}) out of bounds (${l})`);let m=S.zeros(Array.from(n),"int32"),p=m.data,y=Array.from(n).filter((b,A)=>A!==c),d=y.length===0?1:y.reduce((b,A)=>b*A,1);if(O(a)){let b=u;for(let A=0;A<d;A++){let g=[];for(let h=0;h<l;h++){let N=G(A,c,h,n),D=Z(N,s,i);g.push({value:b[D],idx:h})}tx(g,f);for(let h=0;h<l;h++){let N=G(A,c,h,n),D=xr(N,n);p[D]=g[h].idx}}}else for(let b=0;b<d;b++){let A=[];for(let g=0;g<l;g++){let h=G(b,c,g,n),N=Z(h,s,i);A.push({value:Number(u[N]),idx:g})}rx(A,f);for(let g=0;g<l;g++){let h=G(b,c,g,n),N=xr(h,n);p[N]=A[g].idx}}return m}function Xp(r){let t=r.dtype,e=r.size,n=r.isCContiguous,o=r.data,a=r.offset;if(B(t)){let u=[];if(n){let c=o;for(let l=0;l<e;l++)u.push({re:c[(a+l)*2],im:c[(a+l)*2+1]})}else for(let c=0;c<e;c++){let l=r.iget(c);u.push({re:l.re,im:l.im})}u.sort((c,l)=>at(c.re,c.im,l.re,l.im));let i=S.zeros([e],"complex128"),s=i.data;for(let c=0;c<e;c++)s[c*2]=u[c].re,s[c*2+1]=u[c].im;return i}else{let u=[];if(n)for(let c=0;c<e;c++)u.push(Number(o[a+c]));else for(let c=0;c<e;c++)u.push(Number(r.iget(c)));u.sort((c,l)=>isNaN(c)&&isNaN(l)?0:isNaN(c)?1:isNaN(l)?-1:c-l);let i=S.zeros([e],"complex128"),s=i.data;for(let c=0;c<e;c++)s[c*2]=u[c],s[c*2+1]=0;return i}}function zu(r){let t=r.shape,e=t.length,n=r.size,o=B(r.dtype),a=r.isCContiguous,u=r.data,i=r.offset,s=[];for(let p=0;p<e;p++)s.push([]);let c=[],l=1;for(let p=e-1;p>=0;p--)c.unshift(l),l*=t[p];if(a){for(let p=0;p<n;p++)if(gr(u,i+p,o)){let y=p;for(let d=0;d<e;d++){let b=Math.floor(y/c[d]);y=y%c[d],s[d].push(b)}}}else for(let p=0;p<n;p++){let y=r.iget(p);if(o?y.re!==0||y.im!==0:!!y){let b=p;for(let A=0;A<e;A++){let g=Math.floor(b/c[A]);b=b%c[A],s[A].push(g)}}}let f=s[0]?.length??0,m=[];for(let p=0;p<e;p++){let y=S.zeros([f],"int32"),d=y.data;for(let b=0;b<f;b++)d[b]=s[p][b];m.push(y)}return m}function Jp(r){let t=r.shape,e=t.length,n=r.size,o=B(r.dtype),a=r.isCContiguous,u=r.data,i=r.offset,s=[],c=[],l=1;for(let d=e-1;d>=0;d--)c.unshift(l),l*=t[d];if(a){for(let d=0;d<n;d++)if(gr(u,i+d,o)){let b=[],A=d;for(let g=0;g<e;g++){let h=Math.floor(A/c[g]);A=A%c[g],b.push(h)}s.push(b)}}else for(let d=0;d<n;d++){let b=r.iget(d);if(o?b.re!==0||b.im!==0:!!b){let g=[],h=d;for(let N=0;N<e;N++){let D=Math.floor(h/c[N]);h=h%c[N],g.push(D)}s.push(g)}}let f=s.length,m=e===0?[f,1]:[f,e],p=S.zeros(m,"int32"),y=p.data;for(let d=0;d<f;d++){let b=s[d];for(let A=0;A<(e===0?1:e);A++)y[d*(e===0?1:e)+A]=b[A]??0}return p}function Kp(r){let t=r.size,e=B(r.dtype),n=r.isCContiguous,o=r.data,a=r.offset,u=[];if(n)for(let c=0;c<t;c++)gr(o,a+c,e)&&u.push(c);else for(let c=0;c<t;c++){let l=r.iget(c);(e?l.re!==0||l.im!==0:l)&&u.push(c)}let i=S.zeros([u.length],"int32"),s=i.data;for(let c=0;c<u.length;c++)s[c]=u[c];return i}function Qp(r,t,e){if(t===void 0&&e===void 0)return zu(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),i=R=>{let Y=Array(u).fill(1);for(let X=0;X<R.length;X++)Y[u-R.length+X]=R[X];return Y},s=i(n),c=i(o),l=i(a),f=[];for(let R=0;R<u;R++){let Y=[s[R],c[R],l[R]],X=Math.max(...Y);for(let J of Y)if(J!==1&&J!==X)throw new Error("operands could not be broadcast together");f.push(X)}let m=t.dtype,p=S.zeros(f,m),y=p.data,d=(R,Y)=>{let X=[],J=1;for(let rr=R.length-1;rr>=0;rr--)X.unshift(J),J*=R[rr];for(;X.length<Y.length;)X.unshift(0);for(let rr=0;rr<Y.length;rr++)Y[rr]===1&&f[rr]!==1&&(X[rr]=0);return X},b=d(n,s),A=d(o,c),g=d(a,l),h=[],N=1;for(let R=f.length-1;R>=0;R--)h.unshift(N),N*=f[R];let D=f.reduce((R,Y)=>R*Y,1),x=B(r.dtype),C=B(m),w=r.isCContiguous,_=r.data,I=r.offset,v=t.isCContiguous,T=t.data,E=t.offset,$=e.isCContiguous,k=e.data,V=e.offset;if(n.length===f.length&&o.length===f.length&&a.length===f.length&&n.every((R,Y)=>R===f[Y])&&o.every((R,Y)=>R===f[Y])&&a.every((R,Y)=>R===f[Y])&&w&&v&&$)if(C){let R=y,Y=T,X=k;for(let J=0;J<D;J++)gr(_,I+J,x)?(R[J*2]=Y[(E+J)*2],R[J*2+1]=Y[(E+J)*2+1]):(R[J*2]=X[(V+J)*2],R[J*2+1]=X[(V+J)*2+1])}else if(O(m)){let R=y,Y=T,X=k;for(let J=0;J<D;J++)gr(_,I+J,x)?R[J]=Y[E+J]:R[J]=X[V+J]}else for(let R=0;R<D;R++)gr(_,I+R,x)?y[R]=T[E+R]:y[R]=k[V+R];else for(let R=0;R<D;R++){let Y=R,X=0,J=0,rr=0;for(let nr=0;nr<u;nr++){let dr=Math.floor(Y/h[nr]);Y=Y%h[nr],X+=dr*b[nr],J+=dr*A[nr],rr+=dr*g[nr]}let yr;if(w)yr=gr(_,I+X,x);else{let nr=r.iget(X);yr=x?nr.re!==0||nr.im!==0:!!nr}if(yr)if(C)if(v){let nr=T;y[R*2]=nr[(E+J)*2],y[R*2+1]=nr[(E+J)*2+1]}else{let nr=t.iget(J);y[R*2]=nr.re,y[R*2+1]=nr.im}else v?y[R]=T[E+J]:y[R]=t.iget(J);else if(C)if($){let nr=k;y[R*2]=nr[(V+rr)*2],y[R*2+1]=nr[(V+rr)*2+1]}else{let nr=e.iget(rr);y[R*2]=nr.re,y[R*2+1]=nr.im}else $?y[R]=k[V+rr]:y[R]=e.iget(rr)}return p}function Hp(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.size,o=t.size,a=B(r.dtype),u=r.isCContiguous,i=r.data,s=r.offset,c=t.isCContiguous,l=t.data,f=t.offset,m=S.zeros([o],"int32"),p=m.data;if(a)if(u&&c){let y=i,d=l;for(let b=0;b<o;b++){let A=d[(f+b)*2],g=d[(f+b)*2+1],h=0,N=n;if(e==="left")for(;h<N;){let D=Math.floor((h+N)/2),x=y[(s+D)*2],C=y[(s+D)*2+1];at(x,C,A,g)<0?h=D+1:N=D}else for(;h<N;){let D=Math.floor((h+N)/2),x=y[(s+D)*2],C=y[(s+D)*2+1];at(x,C,A,g)<=0?h=D+1:N=D}p[b]=h}}else for(let y=0;y<o;y++){let d=t.iget(y),b=d.re,A=d.im,g=0,h=n;if(e==="left")for(;g<h;){let N=Math.floor((g+h)/2),D=r.iget(N);at(D.re,D.im,b,A)<0?g=N+1:h=N}else for(;g<h;){let N=Math.floor((g+h)/2),D=r.iget(N);at(D.re,D.im,b,A)<=0?g=N+1:h=N}p[y]=g}else if(u&&c)for(let y=0;y<o;y++){let d=Number(l[f+y]),b=0,A=n;if(e==="left")for(;b<A;){let g=Math.floor((b+A)/2);Number(i[s+g])<d?b=g+1:A=g}else for(;b<A;){let g=Math.floor((b+A)/2);Number(i[s+g])<=d?b=g+1:A=g}p[y]=b}else for(let y=0;y<o;y++){let d=Number(t.iget(y)),b=0,A=n;if(e==="left")for(;b<A;){let g=Math.floor((b+A)/2);Number(r.iget(g))<d?b=g+1:A=g}else for(;b<A;){let g=Math.floor((b+A)/2);Number(r.iget(g))<=d?b=g+1:A=g}p[y]=b}return m}function ry(r,t){let e=t.dtype,n=B(r.dtype),o=B(e),a=Math.min(r.size,t.size),u=r.isCContiguous,i=r.data,s=r.offset,c=t.isCContiguous,l=t.data,f=t.offset,m=0;if(u)for(let b=0;b<a;b++)gr(i,s+b,n)&&m++;else for(let b=0;b<a;b++){let A=r.iget(b);(n?A.re!==0||A.im!==0:A)&&m++}let p=S.zeros([m],e),y=p.data,d=0;if(u&&c)if(O(e)){let b=y,A=l;for(let g=0;g<a;g++)gr(i,s+g,n)&&(b[d++]=A[f+g])}else if(o){let b=y,A=l;for(let g=0;g<a;g++)gr(i,s+g,n)&&(b[d*2]=A[(f+g)*2],b[d*2+1]=A[(f+g)*2+1],d++)}else for(let b=0;b<a;b++)gr(i,s+b,n)&&(y[d++]=l[f+b]);else{let b=u?A=>gr(i,s+A,n):A=>{let g=r.iget(A);if(n){let h=g;return h.re!==0||h.im!==0}return!!g};if(O(e)){let A=y;for(let g=0;g<a;g++)b(g)&&(A[d++]=t.iget(g))}else if(o){let A=y;for(let g=0;g<a;g++)if(b(g)){let h=t.iget(g);A[d*2]=h.re,A[d*2+1]=h.im,d++}}else for(let A=0;A<a;A++)b(A)&&(y[d++]=t.iget(A))}return p}function _u(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size,u=r.offset,i=r.strides,s=B(r.dtype),c=r.isCContiguous;if(t===void 0){let b=0;if(c)for(let A=0;A<a;A++)gr(o,u+A,s)&&b++;else for(let A=0;A<a;A++){let g=r.iget(A);if(s){let h=g;(h.re!==0||h.im!==0)&&b++}else g!==0&&g!==BigInt(0)&&b++}return b}let l=t;if(l<0&&(l=n+l),l<0||l>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let f=Array.from(e).filter((b,A)=>A!==l);if(f.length===0)return _u(r);let m=S.zeros(f,"int32"),p=m.data,y=e[l],d=f.reduce((b,A)=>b*A,1);for(let b=0;b<d;b++){let A=0;for(let g=0;g<y;g++){let h=G(b,l,g,e),N=Z(h,i,u);gr(o,N,s)&&A++}p[b]=A}return m}function Zn(r,t=-1){return M(Lp(z(r),t))}function Xn(r,t=-1){return M(Wp(z(r),t))}function vu(r){return M(Gp(r.map(t=>z(t))))}function Jn(r,t,e=-1){return M(Yp(z(r),t,e))}function Kn(r,t,e=-1){return M(Zp(z(r),t,e))}function Mu(r){return M(Xp(z(r)))}function Qn(r){return $r(zu(z(r)))}function Hn(r){return M(Jp(z(r)))}function Fu(r){return M(Kp(z(r)))}function Fa(r,t,e){let n=Qp(z(r),t?z(t):void 0,e?z(e):void 0);return Array.isArray(n)?$r(n):M(n)}function Ft(r,t,e="left"){return M(Hp(z(r),z(t),e))}function Bu(r,t){return M(ry(z(r),z(t)))}function Ba(r,t){let e=_u(z(r),t);return typeof e=="number"?e:M(e)}function vr(r,t){if(!Ur(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 ro(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function ny(r,t){return vr(r.dtype,"bitwise_and"),typeof t=="number"?ox(r,t):(vr(t.dtype,"bitwise_and"),ro(r,t)?nx(r,t):sr(r,t,(e,n)=>e&n,"bitwise_and"))}function nx(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[i+m]=="bigint"?a[i+m]:BigInt(Math.round(Number(a[i+m]))),y=typeof u[s+m]=="bigint"?u[s+m]:BigInt(Math.round(Number(u[s+m])));l[m]=p&y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[i+y]&p[s+y]}}else for(let l=0;l<o;l++)c[l]=a[i+l]&u[s+l];return n}function ox(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]&f;else for(let p=0;p<u;p++)l[p]=m[a+p]&f}else for(let m=0;m<u;m++)l[m]=r.iget(m)&f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]&t;else for(let l=0;l<u;l++)c[l]=o[a+l]&t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))&t;return s}function oy(r,t){return vr(r.dtype,"bitwise_or"),typeof t=="number"?sx(r,t):(vr(t.dtype,"bitwise_or"),ro(r,t)?ax(r,t):sr(r,t,(e,n)=>e|n,"bitwise_or"))}function ax(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[i+m]=="bigint"?a[i+m]:BigInt(Math.round(Number(a[i+m]))),y=typeof u[s+m]=="bigint"?u[s+m]:BigInt(Math.round(Number(u[s+m])));l[m]=p|y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[i+y]|p[s+y]}}else for(let l=0;l<o;l++)c[l]=a[i+l]|u[s+l];return n}function sx(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]|f;else for(let p=0;p<u;p++)l[p]=m[a+p]|f}else for(let m=0;m<u;m++)l[m]=r.iget(m)|f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]|t;else for(let l=0;l<u;l++)c[l]=o[a+l]|t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))|t;return s}function ay(r,t){return vr(r.dtype,"bitwise_xor"),typeof t=="number"?ux(r,t):(vr(t.dtype,"bitwise_xor"),ro(r,t)?ix(r,t):sr(r,t,(e,n)=>e^n,"bitwise_xor"))}function ix(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;if(!O(r.dtype)||!O(t.dtype))for(let m=0;m<o;m++){let p=typeof a[i+m]=="bigint"?a[i+m]:BigInt(Math.round(Number(a[i+m]))),y=typeof u[s+m]=="bigint"?u[s+m]:BigInt(Math.round(Number(u[s+m])));l[m]=p^y}else{let m=a,p=u;for(let y=0;y<o;y++)l[y]=m[i+y]^p[s+y]}}else for(let l=0;l<o;l++)c[l]=a[i+l]^u[s+l];return n}function ux(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]^f;else for(let p=0;p<u;p++)l[p]=m[a+p]^f}else for(let m=0;m<u;m++)l[m]=r.iget(m)^f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]^t;else for(let l=0;l<u;l++)c[l]=o[a+l]^t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))^t;return s}function Eu(r){vr(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.offset,a=r.size,u=r.isCContiguous,i=S.zeros(e,t),s=i.data;if(O(t)){let c=s;if(u){let l=n;if(o===0)for(let f=0;f<a;f++)c[f]=~l[f];else for(let f=0;f<a;f++)c[f]=~l[o+f]}else for(let l=0;l<a;l++)c[l]=~r.iget(l)}else if(u)if(o===0)for(let c=0;c<a;c++)s[c]=~n[c];else for(let c=0;c<a;c++)s[c]=~n[o+c];else for(let c=0;c<a;c++)s[c]=~Number(r.iget(c));return i}function sy(r){return Eu(r)}function iy(r,t){if(vr(r.dtype,"left_shift"),typeof t=="number")return ty(r,t);if(vr(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=Number(t.iget(0));return ty(r,e)}return ro(r,t)?cx(r,t):sr(r,t,(e,n)=>e<<n,"left_shift")}function cx(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;for(let f=0;f<o;f++){let m=typeof a[i+f]=="bigint"?a[i+f]:BigInt(Math.round(Number(a[i+f]))),p=typeof u[s+f]=="bigint"?u[s+f]:BigInt(Math.round(Number(u[s+f])));l[f]=m<<p}}else for(let l=0;l<o;l++)c[l]=a[i+l]<<u[s+l];return n}function ty(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]<<f;else for(let p=0;p<u;p++)l[p]=m[a+p]<<f}else for(let m=0;m<u;m++)l[m]=r.iget(m)<<f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]<<t;else for(let l=0;l<u;l++)c[l]=o[a+l]<<t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))<<t;return s}function uy(r,t){if(vr(r.dtype,"right_shift"),typeof t=="number")return ey(r,t);if(vr(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=Number(t.iget(0));return ey(r,e)}return ro(r,t)?lx(r,t):sr(r,t,(e,n)=>e>>n,"right_shift")}function lx(r,t){let e=or(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,u=t.data,i=r.offset,s=t.offset,c=n.data;if(O(e)){let l=c;for(let f=0;f<o;f++){let m=typeof a[i+f]=="bigint"?a[i+f]:BigInt(Math.round(Number(a[i+f]))),p=typeof u[s+f]=="bigint"?u[s+f]:BigInt(Math.round(Number(u[s+f])));l[f]=m>>p}}else for(let l=0;l<o;l++)c[l]=a[i+l]>>u[s+l];return n}function ey(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.offset,u=r.size,i=r.isCContiguous,s=S.zeros(n,e),c=s.data;if(O(e)){let l=c,f=BigInt(Math.round(t));if(i){let m=o;if(a===0)for(let p=0;p<u;p++)l[p]=m[p]>>f;else for(let p=0;p<u;p++)l[p]=m[a+p]>>f}else for(let m=0;m<u;m++)l[m]=r.iget(m)>>f}else if(i)if(a===0)for(let l=0;l<u;l++)c[l]=o[l]>>t;else for(let l=0;l<u;l++)c[l]=o[a+l]>>t;else for(let l=0;l<u;l++)c[l]=Number(r.iget(l))>>t;return s}function cy(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),i=[...n];i[t]=u;let s=S.zeros(i,"uint8"),c=s.data,l=r.offset,f=r.isCContiguous;if(o===1){for(let g=0;g<u;g++){let h=0;for(let N=0;N<8;N++){let D=g*8+N;if(D<a){let x=f?Number(r.data[l+D])!==0?1:0:Number(r.iget(D))!==0?1:0;e==="big"?h|=x<<7-N:h|=x<<N}}c[g]=h}return s}let m=n.slice(0,t),p=n.slice(t+1),y=m.reduce((g,h)=>g*h,1),d=p.reduce((g,h)=>g*h,1),b=Ta(n),A=Ta(i);for(let g=0;g<y;g++)for(let h=0;h<d;h++)for(let N=0;N<u;N++){let D=0;for(let _=0;_<8;_++){let I=N*8+_;if(I<a){let v=0,T=g;for(let k=0;k<t;k++){let V=k<t-1?m.slice(k+1).reduce((R,Y)=>R*Y,1):1,j=Math.floor(T/V);T%=V,v+=j*b[k]}v+=I*b[t];let E=h;for(let k=t+1;k<o;k++){let V=k<o-1?p.slice(k-t).reduce((R,Y)=>R*Y,1):1,j=Math.floor(E/V);E%=V,v+=j*b[k]}let $=f?Number(r.data[l+v])!==0?1:0:Number(r.iget(v))!==0?1:0;e==="big"?D|=$<<7-_:D|=$<<_}}let x=0,C=g;for(let _=0;_<t;_++){let I=_<t-1?m.slice(_+1).reduce((T,E)=>T*E,1):1,v=Math.floor(C/I);C%=I,x+=v*A[_]}x+=N*A[t];let w=h;for(let _=t+1;_<o;_++){let I=_<o-1?p.slice(_-t).reduce((T,E)=>T*E,1):1,v=Math.floor(w/I);w%=I,x+=v*A[_]}c[x]=D}return s}function ly(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],i=u*8;e>=0&&(i=e);let s=[...o];s[t]=i;let c=S.zeros(s,"uint8"),l=c.data,f=r.offset,m=r.isCContiguous;if(a===1){for(let h=0;h<u;h++){let N=Number(m?r.data[f+h]:r.iget(h));for(let D=0;D<8;D++){let x=h*8+D;if(x>=i)break;n==="big"?l[x]=N>>7-D&1:l[x]=N>>D&1}}return c}let p=o.slice(0,t),y=o.slice(t+1),d=p.reduce((h,N)=>h*N,1),b=y.reduce((h,N)=>h*N,1),A=Ta(o),g=Ta(s);for(let h=0;h<d;h++)for(let N=0;N<b;N++)for(let D=0;D<u;D++){let x=0,C=h;for(let I=0;I<t;I++){let v=I<t-1?p.slice(I+1).reduce((E,$)=>E*$,1):1,T=Math.floor(C/v);C%=v,x+=T*A[I]}x+=D*A[t];let w=N;for(let I=t+1;I<a;I++){let v=I<a-1?y.slice(I-t).reduce((E,$)=>E*$,1):1,T=Math.floor(w/v);w%=v,x+=T*A[I]}let _=Number(m?r.data[f+x]:r.iget(x));for(let I=0;I<8;I++){let v=D*8+I;if(v>=i)break;let T=0;C=h;for(let E=0;E<t;E++){let $=E<t-1?p.slice(E+1).reduce((V,j)=>V*j,1):1,k=Math.floor(C/$);C%=$,T+=k*g[E]}T+=v*g[t],w=N;for(let E=t+1;E<a;E++){let $=E<a-1?y.slice(E-t).reduce((V,j)=>V*j,1):1,k=Math.floor(w/$);w%=$,T+=k*g[E]}n==="big"?l[T]=_>>7-I&1:l[T]=_>>I&1}}return c}function Ta(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 fy(r){let t=r.dtype;vr(t,"bitwise_count");let e=Array.from(r.shape),n=r.data,o=r.offset,a=r.size,u=r.isCContiguous,i=S.zeros(e,"uint8"),s=i.data;if(O(t))if(u){let c=n;if(o===0)for(let l=0;l<a;l++)s[l]=Ou(c[l]);else for(let l=0;l<a;l++)s[l]=Ou(c[o+l])}else for(let c=0;c<a;c++)s[c]=Ou(r.iget(c));else if(u)if(o===0)for(let c=0;c<a;c++)s[c]=Tu(n[c]);else for(let c=0;c<a;c++)s[c]=Tu(n[o+c]);else for(let c=0;c<a;c++)s[c]=Tu(Number(r.iget(c)));return i}function Tu(r){r=r>>>0;let t=0;for(;r!==0;)r=r&r-1,t++;return t}function Ou(r){r<0n&&(r=BigInt.asUintN(64,r));let t=0;for(;r!==0n;)r=r&r-1n,t++;return t}function to(r,t){let e=typeof t=="number"?t:z(t);return M(ny(z(r),e))}function eo(r,t){let e=typeof t=="number"?t:z(t);return M(oy(z(r),e))}function no(r,t){let e=typeof t=="number"?t:z(t);return M(ay(z(r),e))}function oo(r){return M(Eu(z(r)))}function ao(r){return M(sy(z(r)))}function so(r,t){let e=typeof t=="number"?t:z(t);return M(iy(z(r),e))}function io(r,t){let e=typeof t=="number"?t:z(t);return M(uy(z(r),e))}function Uu(r,t,e){return M(cy(z(r),t,e))}function $u(r,t,e,n){return M(ly(z(r),t,e,n))}function ku(r){return M(fy(z(r)))}function Oa(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 my(r,t=0){L(r.dtype,"around","Rounding is not defined for complex numbers.");let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",u=S.zeros(n,a),i=u.data,s=Math.pow(10,t);if(r.isCContiguous){let c=r.data,l=r.offset;for(let f=0;f<o;f++){let m=Number(c[l+f]);i[f]=Oa(m*s)/s}}else for(let c=0;c<o;c++){let l=Number(r.iget(c));i[c]=Oa(l*s)/s}return u}function py(r){L(r.dtype,"ceil","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.ceil(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.ceil(Number(r.iget(i)));return a}function yy(r){L(r.dtype,"fix","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.trunc(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.trunc(Number(r.iget(i)));return a}function dy(r){L(r.dtype,"floor","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.floor(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.floor(Number(r.iget(i)));return a}function by(r){L(r.dtype,"rint","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Oa(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Oa(Number(r.iget(i)));return a}function Ay(r){L(r.dtype,"trunc","Rounding is not defined for complex numbers.");let t=r.dtype,e=Array.from(r.shape),n=r.size,o=t==="float32"?"float32":"float64",a=S.zeros(e,o),u=a.data;if(r.isCContiguous){let i=r.data,s=r.offset;for(let c=0;c<n;c++)u[c]=Math.trunc(Number(i[s+c]))}else for(let i=0;i<n;i++)u[i]=Math.trunc(Number(r.iget(i)));return a}function Bt(r,t=0){return M(my(z(r),t))}var Ea=Bt;function uo(r){return M(py(z(r)))}function co(r){return M(yy(z(r)))}function lo(r){return M(dy(z(r)))}function fo(r){return M(by(z(r)))}function mo(r){return M(Ay(z(r)))}function Ru(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 px(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 Cr(r,t=!1,e=!1,n=!1){let o=r.dtype,a=r.size,u=r.data,i=r.offset;if(B(o)){let N=u,D=[];for(let R=0;R<a;R++)D.push({re:N[(i+R)*2],im:N[(i+R)*2+1],index:R});D.sort((R,Y)=>Ru(R.re,R.im,Y.re,Y.im));let x=[],C=[],w=new Array(a),_=[],I,v,T=0;for(let R=0;R<D.length;R++){let{re:Y,im:X,index:J}=D[R];I===void 0||!px(Y,X,I,v)?(I!==void 0&&_.push(T),x.push({re:Y,im:X}),C.push(J),T=1,I=Y,v=X):T++}T>0&&_.push(T);let E=new Map,$=-1;for(let R=0;R<x.length;R++){let{re:Y,im:X}=x[R];isNaN(Y)||isNaN(X)?$=R:E.set(`${Y},${X}`,R)}for(let R=0;R<a;R++){let Y=N[(i+R)*2],X=N[(i+R)*2+1];isNaN(Y)||isNaN(X)?w[R]=$:w[R]=E.get(`${Y},${X}`)}let k=S.zeros([x.length],o),V=k.data;for(let R=0;R<x.length;R++)V[R*2]=x[R].re,V[R*2+1]=x[R].im;if(!t&&!e&&!n)return k;let j={values:k};if(t){let R=S.zeros([C.length],"int32"),Y=R.data;for(let X=0;X<C.length;X++)Y[X]=C[X];j.indices=R}if(e){let R=S.zeros([w.length],"int32"),Y=R.data;for(let X=0;X<w.length;X++)Y[X]=w[X];j.inverse=R}if(n){let R=S.zeros([_.length],"int32"),Y=R.data;for(let X=0;X<_.length;X++)Y[X]=_[X];j.counts=R}return j}let s=[];for(let N=0;N<a;N++)s.push({value:Number(u[i+N]),index:N});s.sort((N,D)=>isNaN(N.value)&&isNaN(D.value)?0:isNaN(N.value)?1:isNaN(D.value)?-1:N.value-D.value);let c=[],l=[],f=new Array(a),m=[],p,y=0;for(let N=0;N<s.length;N++){let{value:D,index:x}=s[N];p===void 0||isNaN(D)&&!isNaN(p)||!isNaN(D)&&isNaN(p)||!isNaN(D)&&!isNaN(p)&&D!==p?(p!==void 0&&m.push(y),c.push(D),l.push(x),y=1,p=D):y++}y>0&&m.push(y);let d=new Map,b=-1;for(let N=0;N<c.length;N++){let D=c[N];isNaN(D)?b=N:d.set(D,N)}for(let N=0;N<a;N++){let D=Number(u[i+N]);isNaN(D)?f[N]=b:f[N]=d.get(D)}let A=S.zeros([c.length],o),g=A.data;for(let N=0;N<c.length;N++)g[N]=c[N];if(!t&&!e&&!n)return A;let h={values:A};if(t){let N=S.zeros([l.length],"int32"),D=N.data;for(let x=0;x<l.length;x++)D[x]=l[x];h.indices=N}if(e){let N=S.zeros([f.length],"int32"),D=N.data;for(let x=0;x<f.length;x++)D[x]=f[x];h.inverse=N}if(n){let N=S.zeros([m.length],"int32"),D=N.data;for(let x=0;x<m.length;x++)D[x]=m[x];h.counts=N}return h}function Vr(r,t,e,n=0){if(e){let o=Number(r[(n+t)*2]),a=Number(r[(n+t)*2+1]);return`${o},${a}`}return String(Number(r[n+t]))}function gy(r,t){return qu(r,t)}function hy(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=Cr(t),u=new Set;for(let l=0;l<a.size;l++)u.add(Vr(a.data,l,n));let i=[];for(let l=0;l<o.size;l++){let f=Vr(o.data,l,n);u.has(f)&&i.push(l)}if(n){let l=S.zeros([i.length],e),f=l.data,m=o.data;for(let p=0;p<i.length;p++){let y=i[p];f[p*2]=m[y*2],f[p*2+1]=m[y*2+1]}return l}let s=S.zeros([i.length],e),c=s.data;for(let l=0;l<i.length;l++)c[l]=o.data[i[l]];return s}function qu(r,t){let e=Array.from(r.shape),n=r.size,o=B(r.dtype),a=new Set;for(let s=0;s<t.size;s++)a.add(Vr(t.data,s,o,t.offset));let u=S.zeros(e,"bool"),i=u.data;for(let s=0;s<n;s++){let c=Vr(r.data,s,o,r.offset);i[s]=a.has(c)?1:0}return u}function Ny(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=new Set;for(let c=0;c<t.size;c++)a.add(Vr(t.data,c,n,t.offset));let u=[];for(let c=0;c<o.size;c++){let l=Vr(o.data,c,n);a.has(l)||u.push(c)}if(n){let c=S.zeros([u.length],e),l=c.data,f=o.data;for(let m=0;m<u.length;m++){let p=u[m];l[m*2]=f[p*2],l[m*2+1]=f[p*2+1]}return c}let i=S.zeros([u.length],e),s=i.data;for(let c=0;c<u.length;c++)s[c]=o.data[u[c]];return i}function Dy(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=Cr(t),u=new Set,i=new Set;for(let p=0;p<o.size;p++)u.add(Vr(o.data,p,n));for(let p=0;p<a.size;p++)i.add(Vr(a.data,p,n));let s=[],c=[];for(let p=0;p<o.size;p++){let y=Vr(o.data,p,n);i.has(y)||s.push(p)}for(let p=0;p<a.size;p++){let y=Vr(a.data,p,n);u.has(y)||c.push(p)}if(n){let p=[],y=o.data,d=a.data;for(let g of s)p.push({re:y[g*2],im:y[g*2+1]});for(let g of c)p.push({re:d[g*2],im:d[g*2+1]});p.sort((g,h)=>Ru(g.re,g.im,h.re,h.im));let b=S.zeros([p.length],e),A=b.data;for(let g=0;g<p.length;g++)A[g*2]=p[g].re,A[g*2+1]=p[g].im;return b}let l=[];for(let p of s)l.push(Number(o.data[p]));for(let p of c)l.push(Number(a.data[p]));l.sort((p,y)=>isNaN(p)&&isNaN(y)?0:isNaN(p)?1:isNaN(y)?-1:p-y);let f=S.zeros([l.length],e),m=f.data;for(let p=0;p<l.length;p++)m[p]=l[p];return f}function xy(r,t){let e=r.dtype,n=B(e),o=Cr(r),a=Cr(t),u=new Set,i=[];if(n){let f=o.data,m=a.data;for(let d=0;d<o.size;d++){let b=f[d*2],A=f[d*2+1],g=`${b},${A}`;u.has(g)||(u.add(g),i.push({re:b,im:A}))}for(let d=0;d<a.size;d++){let b=m[d*2],A=m[d*2+1],g=`${b},${A}`;u.has(g)||(u.add(g),i.push({re:b,im:A}))}i.sort((d,b)=>Ru(d.re,d.im,b.re,b.im));let p=S.zeros([i.length],e),y=p.data;for(let d=0;d<i.length;d++)y[d*2]=i[d].re,y[d*2+1]=i[d].im;return p}let s=[];for(let f=0;f<o.size;f++){let m=Number(o.data[f]),p=String(m);u.has(p)||(u.add(p),s.push(m))}for(let f=0;f<a.size;f++){let m=Number(a.data[f]),p=String(m);u.has(p)||(u.add(p),s.push(m))}s.sort((f,m)=>isNaN(f)&&isNaN(m)?0:isNaN(f)?1:isNaN(m)?-1:f-m);let c=S.zeros([s.length],e),l=c.data;for(let f=0;f<s.length;f++)l[f]=s[f];return c}function Cy(r,t="fb"){let e=r.dtype,n=r.data,o=r.size,a=r.offset,u=B(e);if(o===0)return S.zeros([0],e);let i=p=>{if(u){let y=n[(a+p)*2],d=n[(a+p)*2+1];return y===0&&d===0}return Number(n[a+p])===0},s=0;if(t==="f"||t==="fb")for(;s<o&&i(s);)s++;let c=o-1;if(t==="b"||t==="fb")for(;c>=s&&i(c);)c--;if(s>c)return S.zeros([0],e);let l=c-s+1;if(u){let p=S.zeros([l],e),y=p.data;for(let d=0;d<l;d++)y[d*2]=n[(a+s+d)*2],y[d*2+1]=n[(a+s+d)*2+1];return p}let f=S.zeros([l],e),m=f.data;for(let p=0;p<l;p++)m[p]=n[a+s+p];return f}function Sy(r){let e=Cr(r,!0,!0,!0);return{values:e.values,indices:e.indices,inverse_indices:e.inverse,counts:e.counts}}function wy(r){let e=Cr(r,!1,!1,!0);return{values:e.values,counts:e.counts}}function Iy(r){let e=Cr(r,!1,!0,!1);return{values:e.values,inverse_indices:e.inverse}}function zy(r){return Cr(r)}function Ua(r,t=!1,e=!1,n=!1){let o=Cr(z(r),t,e,n);return"values"in o?{values:M(o.values),indices:o.indices?M(o.indices):void 0,inverse:o.inverse?M(o.inverse):void 0,counts:o.counts?M(o.counts):void 0}:M(o)}function Vu(r,t){return M(gy(z(r),z(t)))}function Pu(r,t){return M(hy(z(r),z(t)))}function ju(r,t){return M(qu(z(r),z(t)))}function Lu(r,t){return M(Ny(z(r),z(t)))}function Wu(r,t){return M(Dy(z(r),z(t)))}function Gu(r,t){return M(xy(z(r),z(t)))}function Yu(r,t){return M(Cy(z(r),t))}function $a(r){let t=Sy(z(r));return{values:M(t.values),indices:M(t.indices),inverse_indices:M(t.inverse_indices),counts:M(t.counts)}}function ka(r){let t=wy(z(r));return{values:M(t.values),counts:M(t.counts)}}function Ra(r){let t=Iy(z(r));return{values:M(t.values),inverse_indices:M(t.inverse_indices)}}function Zu(r){return M(zy(z(r)))}function _y(r,t,e=0){L(r.dtype,"bincount","bincount requires integer input.");let n=r.data,o=r.size,a=0;for(let i=0;i<o;i++){let s=Number(n[i]);if(s<0||!Number.isInteger(s))throw new Error("'x' argument must contain non-negative integers");s>a&&(a=s)}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 i=t.data,s=new Float64Array(u);for(let c=0;c<o;c++){let l=Number(n[c]);s[l]+=Number(i[c])}return S.fromData(s,[u],"float64")}else{let i=new Float64Array(u);for(let s=0;s<o;s++){let c=Number(n[s]);i[c]++}return S.fromData(i,[u],"float64")}}function vy(r,t,e=!1){L(r.dtype,"digitize","digitize requires real numbers."),L(t.dtype,"digitize","digitize requires real numbers.");let n=r.data,o=t.data,a=r.size,u=t.size,i=new Float64Array(a),s=!0;u>1&&(s=Number(o[1])>=Number(o[0]));for(let c=0;c<a;c++){let l=Number(n[c]),f;if(s)e?f=dx(o,u,l):f=po(o,u,l);else if(e)for(f=0;f<u&&Number(o[f])>=l;)f++;else for(f=0;f<u&&Number(o[f])>l;)f++;i[c]=f}return S.fromData(i,[...r.shape],"float64")}function dx(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 po(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 My(r,t=10,e,n=!1,o){L(r.dtype,"histogram","histogram requires real numbers."),typeof t!="number"&&L(t.dtype,"histogram","histogram requires real numbers.");let a=r.data,u=r.size,i;if(typeof t=="number"){let f,m;if(e)[f,m]=e;else{f=1/0,m=-1/0;for(let y=0;y<u;y++){let d=Number(a[y]);d<f&&(f=d),d>m&&(m=d)}f===m&&(f=f-.5,m=m+.5)}i=[];let p=(m-f)/t;for(let y=0;y<=t;y++)i.push(f+y*p)}else{let f=t.data;i=[];for(let m=0;m<t.size;m++)i.push(Number(f[m]))}let s=i.length-1,c=new Float64Array(s),l=o?.data;for(let f=0;f<u;f++){let m=Number(a[f]),p=l?Number(l[f]):1,y=po(i,i.length,m)-1;if(!(y<0)){if(y>=s)if(m===i[s])y=s-1;else continue;c[y]+=p}}if(n){let f=0;for(let m=0;m<s;m++)f+=c[m];for(let m=0;m<s;m++){let p=i[m+1]-i[m];c[m]=c[m]/(f*p)}}return{hist:S.fromData(c,[s],"float64"),bin_edges:S.fromData(new Float64Array(i),[i.length],"float64")}}function Fy(r,t,e=10,n,o=!1,a){L(r.dtype,"histogram2d","histogram2d requires real numbers."),L(t.dtype,"histogram2d","histogram2d requires real numbers.");let u=r.data,i=t.data,s=r.size;if(t.size!==s)throw new Error("x and y must have the same length");let c,l,f,m;if(typeof e=="number"?(f=e,m=e):Array.isArray(e)&&e.length===2?(e[0],f=e[0],m=e[1]):(f=10,m=10),typeof f=="number"){let A,g;if(n)[A,g]=n[0];else{A=1/0,g=-1/0;for(let N=0;N<s;N++){let D=Number(u[N]);D<A&&(A=D),D>g&&(g=D)}A===g&&(A-=.5,g+=.5)}c=[];let h=(g-A)/f;for(let N=0;N<=f;N++)c.push(A+N*h)}else{let A=f.data;c=[];for(let g=0;g<f.size;g++)c.push(Number(A[g]))}if(typeof m=="number"){let A,g;if(n)[A,g]=n[1];else{A=1/0,g=-1/0;for(let N=0;N<s;N++){let D=Number(i[N]);D<A&&(A=D),D>g&&(g=D)}A===g&&(A-=.5,g+=.5)}l=[];let h=(g-A)/m;for(let N=0;N<=m;N++)l.push(A+N*h)}else{let A=m.data;l=[];for(let g=0;g<m.size;g++)l.push(Number(A[g]))}let p=c.length-1,y=l.length-1,d=new Float64Array(p*y),b=a?.data;for(let A=0;A<s;A++){let g=Number(u[A]),h=Number(i[A]),N=b?Number(b[A]):1,D=po(c,c.length,g)-1,x=po(l,l.length,h)-1;if(D<0||D>=p)if(g===c[p]&&D===p)D=p-1;else continue;if(x<0||x>=y)if(h===l[y]&&x===y)x=y-1;else continue;d[D*y+x]+=N}if(o){let A=0;for(let g=0;g<d.length;g++)A+=d[g];for(let g=0;g<p;g++)for(let h=0;h<y;h++){let N=c[g+1]-c[g],D=l[h+1]-l[h],x=N*D;d[g*y+h]=d[g*y+h]/(A*x)}}return{hist:S.fromData(d,[p,y],"float64"),x_edges:S.fromData(new Float64Array(c),[c.length],"float64"),y_edges:S.fromData(new Float64Array(l),[l.length],"float64")}}function By(r,t=10,e,n=!1,o){L(r.dtype,"histogramdd","histogramdd requires real numbers.");let a=r.shape,u=r.data,i,s;if(a.length===1)i=a[0],s=1;else if(a.length===2)i=a[0],s=a[1];else throw new Error("sample must be 1D or 2D array");let c;if(typeof t=="number")c=new Array(s).fill(t);else if(c=t,c.length!==s)throw new Error("bins array length must match number of dimensions");let l=[];for(let A=0;A<s;A++){let g,h;if(e&&e[A])[g,h]=e[A];else{g=1/0,h=-1/0;for(let C=0;C<i;C++){let w=Number(s===1?u[C]:u[C*s+A]);w<g&&(g=w),w>h&&(h=w)}g===h&&(g-=.5,h+=.5)}let N=c[A],D=[],x=(h-g)/N;for(let C=0;C<=N;C++)D.push(g+C*x);l.push(D)}let f=c.slice(),m=f.reduce((A,g)=>A*g,1),p=new Float64Array(m),y=new Array(s);y[s-1]=1;for(let A=s-2;A>=0;A--)y[A]=y[A+1]*c[A+1];let d=o?.data;for(let A=0;A<i;A++){let g=d?Number(d[A]):1,h=0,N=!1;for(let D=0;D<s;D++){let x=Number(s===1?u[A]:u[A*s+D]),C=l[D],w=c[D],_=po(C,C.length,x)-1;if(_<0||_>=w)if(x===C[w]&&_===w)_=w-1;else{N=!0;break}h+=_*y[D]}N||(p[h]+=g)}if(n){let A=0;for(let h=0;h<m;h++)A+=p[h];let g=new Float64Array(m);for(let h=0;h<m;h++){let N=1,D=h;for(let x=0;x<s;x++){let C=Math.floor(D/y[x])%c[x],w=l[x];N*=w[C+1]-w[C]}g[h]=N}for(let h=0;h<m;h++)p[h]=p[h]/(A*g[h])}let b=l.map(A=>S.fromData(new Float64Array(A),[A.length],"float64"));return{hist:S.fromData(p,f,"float64"),edges:b}}function Ju(r,t,e="full"){let n=r.data,o=t.data,a=r.size,u=t.size,i=B(r.dtype)||B(t.dtype),s=a+u-1;if(i){let l=new Float64Array(s),f=new Float64Array(s),m=B(r.dtype),p=B(t.dtype);for(let d=0;d<s;d++){let b=0,A=0,g=d-u+1;for(let h=0;h<a;h++){let N=h-g;if(N>=0&&N<u){let D,x,C,w;m?(D=n[h*2],x=n[h*2+1]):(D=Number(n[h]),x=0),p?(C=o[N*2],w=o[N*2+1]):(C=Number(o[N]),w=0),b+=D*C+x*w,A+=x*C-D*w}}l[d]=b,f[d]=A}let y=(d,b,A,g=0)=>{let h=new Float64Array(A*2);for(let N=0;N<A;N++)h[N*2]=d[g+N],h[N*2+1]=b[g+N];return S.fromData(h,[A],"complex128")};if(e==="full")return y(l,f,s);if(e==="same"){let d=Math.floor((s-a)/2);return y(l,f,a,d)}else{let d=Math.max(a,u)-Math.min(a,u)+1,b=Math.min(a,u)-1;return y(l,f,d,b)}}let c=new Float64Array(s);for(let l=0;l<s;l++){let f=0,m=l-u+1;for(let p=0;p<a;p++){let y=p-m;y>=0&&y<u&&(f+=Number(n[p])*Number(o[y]))}c[l]=f}if(e==="full")return S.fromData(c,[s],"float64");if(e==="same"){let l=Math.floor((s-a)/2),f=new Float64Array(a);for(let m=0;m<a;m++)f[m]=c[l+m];return S.fromData(f,[a],"float64")}else{let l=Math.max(a,u)-Math.min(a,u)+1,f=Math.min(a,u)-1,m=new Float64Array(l);for(let p=0;p<l;p++)m[p]=c[f+p];return S.fromData(m,[l],"float64")}}function Ty(r,t,e="full"){let n=t.data,o=t.size,a=B(t.dtype),u;if(a){let i=new Float64Array(o*2);for(let s=0;s<o;s++){let c=o-1-s;i[s*2]=n[c*2],i[s*2+1]=n[c*2+1]}u=S.fromData(i,[o],t.dtype)}else{let i=new Float64Array(o);for(let s=0;s<o;s++)i[s]=Number(n[o-1-s]);u=S.fromData(i,[o],"float64")}if(a){let i=u.data;for(let s=0;s<o;s++)i[s*2+1]=-i[s*2+1]}return Ju(r,u,e)}function Ku(r,t,e=!0,n=!1,o){let a=r.shape,u=r.data,i=B(r.dtype)||t!==void 0&&B(t.dtype),s;if(o!==void 0?s=o:s=n?0:1,a.length===1)if(t!==void 0){let y=t.data,d=r.size,b=B(r.dtype),A=B(t.dtype);if(t.size!==d)throw new Error("m and y must have same length");if(i){let w=0,_=0,I=0,v=0;for(let rr=0;rr<d;rr++)b?(w+=u[rr*2],_+=u[rr*2+1]):w+=Number(u[rr]),A?(I+=y[rr*2],v+=y[rr*2+1]):I+=Number(y[rr]);w/=d,_/=d,I/=d,v/=d;let T=0,E=0,$=0,k=0,V=0,j=0,R=0,Y=0;for(let rr=0;rr<d;rr++){let yr,nr,dr,Or;b?(yr=u[rr*2]-w,nr=u[rr*2+1]-_):(yr=Number(u[rr])-w,nr=0),A?(dr=y[rr*2]-I,Or=y[rr*2+1]-v):(dr=Number(y[rr])-I,Or=0),T+=yr*yr+nr*nr,$+=dr*dr+Or*Or,V+=yr*dr+nr*Or,j+=nr*dr-yr*Or,R+=dr*yr+Or*nr,Y+=Or*yr-dr*nr}let X=d-s;if(X<=0){let rr=new Float64Array(8);return rr.fill(NaN),S.fromData(rr,[2,2],"complex128")}T/=X,$/=X,V/=X,j/=X,R/=X,Y/=X;let J=new Float64Array(8);return J[0]=T,J[1]=E,J[2]=V,J[3]=j,J[4]=R,J[5]=Y,J[6]=$,J[7]=k,S.fromData(J,[2,2],"complex128")}let g=0,h=0;for(let w=0;w<d;w++)g+=Number(u[w]),h+=Number(y[w]);g/=d,h/=d;let N=0,D=0,x=0;for(let w=0;w<d;w++){let _=Number(u[w])-g,I=Number(y[w])-h;N+=_*_,D+=I*I,x+=_*I}let C=d-s;return C<=0?S.fromData(new Float64Array([NaN,NaN,NaN,NaN]),[2,2],"float64"):(N/=C,D/=C,x/=C,S.fromData(new Float64Array([N,x,x,D]),[2,2],"float64"))}else{let y=r.size;if(i){let g=0,h=0;for(let x=0;x<y;x++)g+=u[x*2],h+=u[x*2+1];g/=y,h/=y;let N=0;for(let x=0;x<y;x++){let C=u[x*2]-g,w=u[x*2+1]-h;N+=C*C+w*w}let D=y-s;return D<=0?S.fromData(new Float64Array([NaN,0]),[],"complex128"):(N/=D,S.fromData(new Float64Array([N,0]),[],"complex128"))}let d=0;for(let g=0;g<y;g++)d+=Number(u[g]);d/=y;let b=0;for(let g=0;g<y;g++){let h=Number(u[g])-d;b+=h*h}let A=y-s;return A<=0?S.fromData(new Float64Array([NaN]),[],"float64"):(b/=A,S.fromData(new Float64Array([b]),[],"float64"))}let c,l;e?(c=a[0],l=a[1]):(c=a[1],l=a[0]);let f=l-s;if(i){let y=new Float64Array(c),d=new Float64Array(c);for(let A=0;A<c;A++){let g=0,h=0;for(let N=0;N<l;N++){let D=e?A*l+N:N*c+A;g+=u[D*2],h+=u[D*2+1]}y[A]=g/l,d[A]=h/l}let b=new Float64Array(c*c*2);if(f<=0)return b.fill(NaN),S.fromData(b,[c,c],"complex128");for(let A=0;A<c;A++)for(let g=0;g<c;g++){let h=0,N=0;for(let x=0;x<l;x++){let C=e?A*l+x:x*c+A,w=e?g*l+x:x*c+g,_=u[C*2]-y[A],I=u[C*2+1]-d[A],v=u[w*2]-y[g],T=u[w*2+1]-d[g];h+=_*v+I*T,N+=I*v-_*T}let D=(A*c+g)*2;b[D]=h/f,b[D+1]=N/f}return S.fromData(b,[c,c],"complex128")}let m=new Float64Array(c);for(let y=0;y<c;y++){let d=0;for(let b=0;b<l;b++){let A=e?y*l+b:b*c+y;d+=Number(u[A])}m[y]=d/l}let p=new Float64Array(c*c);if(f<=0)return p.fill(NaN),S.fromData(p,[c,c],"float64");for(let y=0;y<c;y++)for(let d=y;d<c;d++){let b=0;for(let g=0;g<l;g++){let h=e?y*l+g:g*c+y,N=e?d*l+g:g*c+d,D=Number(u[h])-m[y],x=Number(u[N])-m[d];b+=D*x}let A=b/f;p[y*c+d]=A,p[d*c+y]=A}return S.fromData(p,[c,c],"float64")}function Oy(r,t,e=!0){let n=B(r.dtype)||t!==void 0&&B(t.dtype);if(r.shape.length===1&&t===void 0)return n?S.fromData(new Float64Array([1,0]),[],"complex128"):S.fromData(new Float64Array([1]),[],"float64");let o=Ku(r,t,e,!1),a=o.data,i=o.shape[0];if(n){let c=new Float64Array(i*i*2);for(let l=0;l<i;l++)for(let f=0;f<i;f++){let m=a[(l*i+f)*2],p=a[(l*i+f)*2+1],y=a[(l*i+l)*2],d=a[(f*i+f)*2],b=(l*i+f)*2;if(y<=0||d<=0)c[b]=NaN,c[b+1]=NaN;else{let A=Math.sqrt(y*d);c[b]=m/A,c[b+1]=p/A}}return S.fromData(c,[i,i],"complex128")}let s=new Float64Array(i*i);for(let c=0;c<i;c++)for(let l=0;l<i;l++){let f=Number(a[c*i+l]),m=Number(a[c*i+c]),p=Number(a[l*i+l]);m<=0||p<=0?s[c*i+l]=NaN:s[c*i+l]=f/Math.sqrt(m*p)}return S.fromData(s,[i,i],"float64")}function Ey(r,t=10,e,n){L(r.dtype,"histogram_bin_edges","histogram_bin_edges requires real numbers.");let o=r.data,a=r.size,u,i;if(e)[u,i]=e;else{u=1/0,i=-1/0;for(let f=0;f<a;f++){let m=Number(o[f]);isNaN(m)||(m<u&&(u=m),m>i&&(i=m))}!isFinite(u)||!isFinite(i)?(u=0,i=1):u===i&&(u=u-.5,i=i+.5)}let s;typeof t=="number"?s=t:s=Xu(o,a,u,i,t),s=Math.max(1,Math.round(s));let c=new Float64Array(s+1),l=(i-u)/s;for(let f=0;f<=s;f++)c[f]=u+f*l;return S.fromData(c,[s+1],"float64")}function Xu(r,t,e,n,o){if(t===0)return 1;let a=n-e;if(a===0)return 1;let u=[],i=0;for(let d=0;d<t;d++){let b=Number(r[d]);isNaN(b)||(u.push(b),i+=b)}let s=u.length;if(s===0)return 1;let c=i/s,l=0;for(let d=0;d<s;d++){let b=u[d]-c;l+=b*b}let f=Math.sqrt(l/s);u.sort((d,b)=>d-b);let m=u[Math.floor(s*.25)]??0,y=(u[Math.floor(s*.75)]??0)-m;switch(o){case"sqrt":return Math.ceil(Math.sqrt(s));case"sturges":return Math.ceil(Math.log2(s)+1);case"rice":return Math.ceil(2*Math.pow(s,1/3));case"scott":{if(f===0)return 1;let d=3.5*f/Math.pow(s,1/3);return Math.ceil(a/d)}case"fd":{if(y===0)return Xu(r,t,e,n,"sturges");let d=2*y/Math.pow(s,1/3);return Math.ceil(a/d)}case"doane":{let d=bx(u,c,f),b=Math.sqrt(6*(s-2)/((s+1)*(s+3)));return Math.ceil(1+Math.log2(s)+Math.log2(1+Math.abs(d)/b))}case"stone":return Xu(r,t,e,n,"sturges");default:{let d=Math.ceil(Math.log2(s)+1),b=y===0?d:Math.ceil(a/(2*y/Math.pow(s,1/3)));return Math.max(d,b)}}}function bx(r,t,e){if(e===0)return 0;let n=r.length,o=0;for(let a=0;a<n;a++)o+=Math.pow((r[a]-t)/e,3);return o/n}function Uy(r,t,e=1,n=-1){L(r.dtype,"trapezoid","trapezoid requires real numbers."),t!==void 0&&L(t.dtype,"trapezoid","trapezoid requires real numbers.");let o=Array.from(r.shape),a=o.length;if(n<0&&(n=a+n),n<0||n>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let u=o[n];if(u<2)throw new Error("trapezoid requires at least 2 samples along axis");let i;if(t!==void 0){if(t.size!==u)throw new Error(`x array size (${t.size}) must match y axis size (${u})`);let d=t.data;i=new Float64Array(u);for(let b=0;b<u;b++)i[b]=Number(d[b])}else{i=new Float64Array(u);for(let d=0;d<u;d++)i[d]=d*e}let s=[...o];if(s.splice(n,1),a===1){let d=r.data,b=0;for(let A=0;A<u-1;A++){let g=Number(d[A]),h=Number(d[A+1]),N=i[A+1]-i[A];b+=.5*(g+h)*N}return b}let c=s.reduce((d,b)=>d*b,1),l=new Float64Array(c),f=new Array(a),m=1;for(let d=a-1;d>=0;d--)f[d]=m,m*=o[d];let p=new Array(s.length);m=1;for(let d=s.length-1;d>=0;d--)p[d]=m,m*=s[d];let y=r.data;for(let d=0;d<c;d++){let b=[],A=d;for(let D=0;D<s.length;D++){let x=Math.floor(A/p[D]);A%=p[D],b.push(x)}let g=[],h=0;for(let D=0;D<a;D++)D===n?g.push(0):(g.push(b[h]),h++);let N=0;for(let D=0;D<u-1;D++){g[n]=D;let x=0;for(let v=0;v<a;v++)x+=g[v]*f[v];g[n]=D+1;let C=0;for(let v=0;v<a;v++)C+=g[v]*f[v];let w=Number(y[x]),_=Number(y[C]),I=i[D+1]-i[D];N+=.5*(w+_)*I}l[d]=N}return s.length===0?l[0]:S.fromData(l,s,"float64")}function Qu(r,t,e){let n=t?z(t):void 0;return M(_y(z(r),n,e))}function Hu(r,t,e){return M(vy(z(r),z(t),e))}function qa(r,t,e,n,o){let a=t instanceof P?z(t):t,u=o?z(o):void 0,i=My(z(r),a,e,n,u);return[M(i.hist),M(i.bin_edges)]}function Va(r,t,e,n,o,a){let u;if(Array.isArray(e)&&e.length===2){let c=e[0]instanceof P?z(e[0]):e[0],l=e[1]instanceof P?z(e[1]):e[1];u=[c,l]}else u=e;let i=a?z(a):void 0,s=Fy(z(r),z(t),u,n,o,i);return[M(s.hist),M(s.x_edges),M(s.y_edges)]}function Pa(r,t,e,n,o){let a=o?z(o):void 0,u=By(z(r),t,e,n,a);return[M(u.hist),u.edges.map(i=>M(i))]}function rc(r,t,e){return M(Ju(z(r),z(t),e))}function tc(r,t,e){return M(Ty(z(r),z(t),e))}function ec(r,t,e,n,o){return M(Ku(z(r),t?z(t):void 0,e,n,o))}function nc(r,t,e){return M(Oy(z(r),t?z(t):void 0,e))}function ja(r,t,e,n){return M(Ey(z(r),t,e,n?z(n):void 0))}function oc(r,t,e,n){let o=Uy(z(r),t?z(t):void 0,e,n);return typeof o=="number"?o:M(o)}function $y(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 i=0;i<t;i++)u=gx(u,a);return u}function gx(r,t){let e=Array.from(r.shape),n=e.length,o=e[t],a=[...e];a[t]=o-1;let u=r.dtype,i=B(u),s=O(u)?"float64":u,c=S.zeros(a,s),l=c.data,f=r.strides,m=c.size,p=r.offset;for(let y=0;y<m;y++){let d=y,b=new Array(n);for(let D=n-1;D>=0;D--)b[D]=d%a[D],d=Math.floor(d/a[D]);let A=[...b],g=[...b];g[t]=A[t]+1;let h=0,N=0;for(let D=0;D<n;D++)h+=A[D]*f[D],N+=g[D]*f[D];if(i){let D=r.data,x=D[(p+h)*2],C=D[(p+h)*2+1],w=D[(p+N)*2],_=D[(p+N)*2+1];l[y*2]=w-x,l[y*2+1]=_-C}else{let D=(O(u),Number(r.data[p+h])),x=(O(u),Number(r.data[p+N]));l[y]=x-D}}return c}function ky(r,t=null,e=null){let n=r.size,o=r.dtype,a=B(o),u=O(o)?"float64":o,i=Math.max(0,n-1),s=e?e.length:0,c=t?t.length:0,l=s+i+c,f=S.zeros([l],u),m=f.data,p=0;if(e)if(a)for(let y of e)m[p*2]=y,m[p*2+1]=0,p++;else for(let y of e)m[p++]=y;if(a)for(let y=0;y<i;y++){let d=r.iget(y),b=r.iget(y+1);m[p*2]=b.re-d.re,m[p*2+1]=b.im-d.im,p++}else for(let y=0;y<i;y++){let d=(O(o),Number(r.iget(y))),b=(O(o),Number(r.iget(y+1)));m[p++]=b-d}if(t)if(a)for(let y of t)m[p*2]=y,m[p*2+1]=0,p++;else for(let y of t)m[p++]=y;return f}function Ry(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 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 i=[];for(let s=0;s<a.length;s++)i.push(hx(r,a[s],u[s]));return i.length===1?i[0]:i}function hx(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,i=B(u),s=O(u)?"float64":u==="float32"?"float32":i?u:"float64",c=S.zeros(n,s),l=c.data,f=r.strides,m=e,p=2*m,y=r.size,d=r.offset;for(let b=0;b<y;b++){let A=b,g=new Array(o);for(let D=o-1;D>=0;D--)g[D]=A%n[D],A=Math.floor(A/n[D]);let h=d;for(let D=0;D<o;D++)h+=g[D]*f[D];let N=g[t];if(i){let D=r.data,x=l,C,w;if(N===0){let _=[...g];_[t]=1;let I=0;for(let k=0;k<o;k++)I+=_[k]*f[k];let v=D[h*2],T=D[h*2+1],E=D[(d+I)*2],$=D[(d+I)*2+1];C=(E-v)/m,w=($-T)/m}else if(N===a-1){let _=[...g];_[t]=a-2;let I=0;for(let k=0;k<o;k++)I+=_[k]*f[k];let v=D[h*2],T=D[h*2+1],E=D[(d+I)*2],$=D[(d+I)*2+1];C=(v-E)/m,w=(T-$)/m}else{let _=[...g],I=[...g];_[t]=N+1,I[t]=N-1;let v=0,T=0;for(let j=0;j<o;j++)v+=_[j]*f[j],T+=I[j]*f[j];let E=D[(d+v)*2],$=D[(d+v)*2+1],k=D[(d+T)*2],V=D[(d+T)*2+1];C=(E-k)/p,w=($-V)/p}x[b*2]=C,x[b*2+1]=w}else{let D;if(N===0){let x=[...g];x[t]=1;let C=0;for(let I=0;I<o;I++)C+=x[I]*f[I];let w=(O(u),Number(r.data[h]));D=((O(u),Number(r.data[d+C]))-w)/m}else if(N===a-1){let x=[...g];x[t]=a-2;let C=0;for(let I=0;I<o;I++)C+=x[I]*f[I];let w=(O(u),Number(r.data[h])),_=(O(u),Number(r.data[d+C]));D=(w-_)/m}else{let x=[...g],C=[...g];x[t]=N+1,C[t]=N-1;let w=0,_=0;for(let T=0;T<o;T++)w+=x[T]*f[T],_+=C[T]*f[T];let I=(O(u),Number(r.data[d+w])),v=(O(u),Number(r.data[d+_]));D=(I-v)/p}l[b]=D}}return c}function yo(r,t,e){return M($y(z(r),t,e))}function ac(r,t,e){return M(ky(z(r),t??null,e??null))}function La(r,t,e){let n=Ry(z(r),t,e);return Array.isArray(n)?$r(n):M(n)}function qy(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(B(t)){let o=Rt(t),a=S.zeros(e,o),u=a.data,i=r.data;for(let s=0;s<n;s++)u[s]=i[s*2];return a}return r.copy()}function Vy(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(B(t)){let a=Rt(t),u=S.zeros(e,a),i=u.data,s=r.data;for(let c=0;c<n;c++)i[c]=s[c*2+1];return u}let o=t==="float32"?"float32":"float64";return S.zeros(e,o)}function Py(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(B(t)){let o=K(t),a=n*2,u=new o(a),i=r.data;for(let s=0;s<n;s++)u[s*2]=i[s*2],u[s*2+1]=-i[s*2+1];return S.fromData(u,e,t)}return r.copy()}function jy(r,t=!1){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=S.zeros(n,"float64"),u=a.data;if(B(e)){let i=r.data;for(let s=0;s<o;s++){let c=i[s*2],l=i[s*2+1],f=Math.atan2(l,c);t&&(f=f*180/Math.PI),u[s]=f}}else for(let i=0;i<o;i++){let s=r.iget(i),l=(s instanceof U?s.re:Number(s))>=0?0:Math.PI;t&&(l=l*180/Math.PI),u[i]=l}return a}function sc(r){return M(qy(z(r)))}function ic(r){return M(Vy(z(r)))}function bo(r){return M(Py(z(r)))}function uc(r,t){return M(jy(z(r),t))}function cc(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=qr([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 _r(r,t)}function Ly(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=qr(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=>_r(n,e))}function Wy(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let y=r.size;for(let g of t){let h=g<0?y+g:g;if(h<0||h>=y)throw new Error(`index ${g} is out of bounds for axis 0 with size ${y}`)}let d=t.length,b=K(a);if(!b)throw new Error(`Cannot take from array with dtype ${a}`);let A=new b(d);for(let g=0;g<d;g++){let h=t[g];h<0&&(h=y+h);let N=r.iget(h);O(a),A[g]=N}return S.fromData(A,[d],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 i=n[u];for(let y of t){let d=y<0?i+y:y;if(d<0||d>=i)throw new Error(`index ${y} is out of bounds for axis ${u} with size ${i}`)}let s=Array.from(n);s[u]=t.length;let c=s.reduce((y,d)=>y*d,1),l=K(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let f=new l(c),m=lr(s),p=new Array(o).fill(0);for(let y=0;y<c;y++){let d=[...p],b=p[u],A=t[b];A<0&&(A=i+A),d[u]=A;let g=r.get(...d),h=0;for(let N=0;N<o;N++)h+=p[N]*m[N];O(a),f[h]=g;for(let N=o-1;N>=0&&(p[N]++,!(p[N]<s[N]));N--)p[N]=0}return S.fromData(f,s,a)}function Gy(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 i=e.iget(u);a.push(i instanceof U?i.re:i)}if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let u=[...a];a=[];for(let i=0;i<t.length;i++)a.push(u[i%u.length])}}for(let u=0;u<t.length;u++){let i=t[u];if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`index ${t[u]} is out of bounds for axis 0 with size ${n}`);let s=a[u];O(o)?typeof s!="bigint"&&(s=BigInt(Math.round(Number(s)))):typeof s=="bigint"&&(s=Number(s)),r.iset(i,s)}}function Yy(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(m=>Array.from(m.shape));a.unshift(Array.from(e));let u=qr(a);if(u===null)throw new Error("operands could not be broadcast together");let i=_r(r,u),s=t.map(m=>_r(m,u)),c=u.reduce((m,p)=>m*p,1),l=K(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let f=new l(c);for(let m=0;m<c;m++){let p=Number(i.iget(m));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(m);O(o),f[m]=y}return S.fromData(f,u,o)}function Zy(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 i=typeof a=="number"&&Number.isNaN(a),s=typeof u=="number"&&Number.isNaN(u);if(i&&s)continue}if(a!==u)return!1}return!0}function Xy(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 i=t.shape;if(i.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${i.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==u&&i[d]!==n[d]&&i[d]!==1&&n[d]!==1)throw new Error(`index ${i[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let s=Array.from(i),c=s.reduce((d,b)=>d*b,1),l=K(a);if(!l)throw new Error(`Cannot take_along_axis with dtype ${a}`);let f=new l(c),m=lr(n),p=lr(i),y=n[u];for(let d=0;d<c;d++){let b=new Array(o),A=d;for(let C=o-1;C>=0;C--)b[C]=A%s[C],A=Math.floor(A/s[C]);let g=0;for(let C=0;C<o;C++){let w=i[C]===1?0:b[C];g+=w*p[C]}let h=Number(t.iget(g));if(h<0&&(h=y+h),h<0||h>=y)throw new Error(`index ${h} is out of bounds for axis ${u} with size ${y}`);let N=[...b];N[u]=h;let D=0;for(let C=0;C<o;C++){let w=n[C]===1?0:N[C];D+=w*m[C]}let x=r.iget(D);O(a),f[d]=x}return S.fromData(f,s,a)}function Jy(r,t,e,n){let o=r.shape,a=o.length,u=r.dtype,i=n<0?a+n:n;if(i<0||i>=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[i],f=lr(o),m=lr(s),p=lr(c),y=s.reduce((d,b)=>d*b,1);for(let d=0;d<y;d++){let b=new Array(a),A=d;for(let w=a-1;w>=0;w--)b[w]=A%s[w],A=Math.floor(A/s[w]);let g=0;for(let w=0;w<a;w++)g+=b[w]*m[w];let h=Number(t.iget(g));if(h<0&&(h=l+h),h<0||h>=l)throw new Error(`index ${h} is out of bounds for axis ${i} with size ${l}`);let N=0;for(let w=0;w<a;w++){let _=c[w]===1?0:b[w];N+=_*p[w]}let D=e.iget(N),x=[...b];x[i]=h;let C=0;for(let w=0;w<a;w++)C+=x[w]*f[w];O(u)?typeof D!="bigint"&&(D=BigInt(Math.round(Number(D)))):typeof D=="bigint"&&(D=Number(D)),r.iset(C,D)}}function Ky(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let i=0;i<e.size;i++){let s=e.iget(i);a.push(s instanceof U?s.re:s)}}let u=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[u%a.length];O(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),u++}}function Qy(r,t,e){let n=t.shape,o=n.length,a=t.dtype,u=O(a);if(e===void 0){let N=Math.min(r.size,t.size),D=r.isCContiguous,x=r.data,C=r.offset,w=0;if(D)for(let E=0;E<N;E++)x[C+E]&&w++;else for(let E=0;E<N;E++)r.iget(E)&&w++;let _=K(a);if(!_)throw new Error(`Cannot compress with dtype ${a}`);let I=new _(w),v=0,T=t.isCContiguous;if(D&&T){let E=t.data,$=t.offset;if(u){let k=I,V=E;for(let j=0;j<N;j++)x[C+j]&&(k[v++]=V[$+j])}else{let k=I,V=E;for(let j=0;j<N;j++)x[C+j]&&(k[v++]=V[$+j])}}else for(let E=0;E<N;E++)(D?x[C+E]:r.iget(E))&&(I[v]=t.iget(E),v++);return S.fromData(I,[w],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 s=n[i],c=Math.min(r.size,s),l=[];for(let N=0;N<c;N++)r.iget(N)&&l.push(N);let f=l.length,m=[...n];m[i]=f;let p=m.reduce((N,D)=>N*D,1),y=K(a);if(!y)throw new Error(`Cannot compress with dtype ${a}`);let d=new y(p),b=n.slice(i+1).reduce((N,D)=>N*D,1),A=n.slice(0,i).reduce((N,D)=>N*D,1),g=0;if(t.isCContiguous){let N=t.data,D=t.offset;if(u){let x=d,C=N;for(let w=0;w<A;w++)for(let _=0;_<f;_++){let I=l[_];for(let v=0;v<b;v++){let T=w*s*b+I*b+v;x[g++]=C[D+T]}}}else{let x=d,C=N;for(let w=0;w<A;w++)for(let _=0;_<f;_++){let I=l[_];for(let v=0;v<b;v++){let T=w*s*b+I*b+v;x[g++]=C[D+T]}}}}else for(let N=0;N<A;N++)for(let D=0;D<f;D++){let x=l[D];for(let C=0;C<b;C++){let w=N*s*b+x*b+C;d[g++]=t.iget(w)}}return S.fromData(d,m,a)}function Hy(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(m=>Array.from(m.shape)),...t.map(m=>Array.from(m.shape))],o=qr(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,u=o.reduce((m,p)=>m*p,1),i=K(a);if(!i)throw new Error(`Cannot select with dtype ${a}`);let s=e;O(a)?s=typeof e=="bigint"?e:BigInt(e):s=typeof e=="bigint"?Number(e):e;let c=new i(u);for(let m=0;m<u;m++)O(a),c[m]=s;let l=r.map(m=>_r(m,o)),f=t.map(m=>_r(m,o));for(let m=0;m<u;m++)for(let p=0;p<r.length;p++)if(l[p].iget(m)){let y=f[p].iget(m);O(a),c[m]=y;break}return S.fromData(c,o,a)}function rd(r,t,e){let n=r.size,o=r.dtype,a=[];for(let i=0;i<e.size;i++){let s=e.iget(i);a.push(s instanceof U?s.re:s)}if(a.length===0)return;let u=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[u%a.length];O(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),u++}}function lc(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(S.fromData(new Int32Array(e),[r],"int32"));return n}function td(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 lc(n,e)}function fc(r,t=0,e){let n=e??r,o=[],a=[];for(let u=0;u<r;u++)for(let i=0;i<=Math.min(u+t,n-1);i++)i>=0&&(o.push(u),a.push(i));return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(a),[a.length],"int32")]}function ed(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return fc(e[0],t,e[1])}function mc(r,t=0,e){let n=e??r,o=[],a=[];for(let u=0;u<r;u++)for(let i=Math.max(u+t,0);i<n;i++)o.push(u),a.push(i);return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(a),[a.length],"int32")]}function nd(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return mc(e[0],t,e[1])}function od(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 i=0;i<r;i++)for(let s=0;s<r;s++)n.get(i,s)&&(a.push(i),u.push(s));return[S.fromData(new Int32Array(a),[a.length],"int32"),S.fromData(new Int32Array(u),[u.length],"int32")]}function ad(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((s,c)=>s*c,1),a=K(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let u=new a(o),i=r.reduce((s,c)=>s*c,1);for(let s=0;s<e;s++){let c=s*i;for(let l=0;l<i;l++){let f=new Array(e),m=l;for(let y=e-1;y>=0;y--)f[y]=m%r[y],m=Math.floor(m/r[y]);let p=f[s];t==="int64"?u[c+l]=BigInt(p):u[c+l]=p}}return S.fromData(u,n,t)}function sd(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,u=o.dtype,i=new Array(t).fill(1);i[n]=a;let s=K(u);if(!s)throw new Error(`Cannot create ix_ with dtype ${u}`);let c=new s(a);for(let l=0;l<a;l++){let f=o.iget(l);O(u),c[l]=f}e.push(S.fromData(c,i,u))}return e}function id(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),i=1;for(let s=o-1;s>=0;s--)u[s]=i,i*=t[s];for(let s=0;s<n;s++){let c=0;for(let l=0;l<o;l++){let f=Number(r[l].iget(s)),m=t[l];if(e==="wrap")f=(f%m+m)%m;else if(e==="clip")f=Math.max(0,Math.min(f,m-1));else if(f<0||f>=m)throw new Error(`index ${f} is out of bounds for axis ${l} with size ${m}`);c+=f*u[l]}a[s]=c}return S.fromData(a,[n],"int32")}function ud(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,i=t.reduce((l,f)=>l*f,1),s=new Array(n);if(e==="C"){let l=1;for(let f=n-1;f>=0;f--)s[f]=l,l*=t[f]}else{let l=1;for(let f=0;f<n;f++)s[f]=l,l*=t[f]}let c=[];for(let l=0;l<n;l++){let f=new Int32Array(u);c.push(S.fromData(f,a.length?a:[1],"int32"))}for(let l=0;l<u;l++){let f=o[l];if(f<0||f>=i)throw new Error(`index ${f} is out of bounds for array with size ${i}`);if(e==="C")for(let m=0;m<n;m++){let p=Math.floor(f/s[m]);f=f%s[m],c[m].data[l]=p%t[m]}else for(let m=n-1;m>=0;m--){let p=Math.floor(f/s[m]);f=f%s[m],c[m].data[l]=p%t[m]}}return typeof r=="number"?c.map(l=>{let f=l.iget(0);return S.fromData(new Int32Array([Number(f)]),[],"int32")}):c}function cd(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 f=c;f<o;f++)l*=n[f];a+=l}}let u=r.size,i=Math.min(...n);e&&o===2&&(i=Math.max(n[0],n[1]));let s=r.isCContiguous;if(typeof t=="number")if(s){let c=r.data,l=r.offset;if(O(r.dtype)){let f=c,m=BigInt(Math.round(t));for(let p=0;p<i;p++){let y=p*a;if(y>=u)break;f[l+y]=m}}else for(let f=0;f<i;f++){let m=f*a;if(m>=u)break;c[l+m]=t}}else for(let c=0;c<i&&c*a<u;c++)r.iset(c*a,t);else{let c=t.size;if(s&&t.isCContiguous){let l=r.data,f=r.offset,m=t.data,p=t.offset;if(O(r.dtype)){let y=l,d=m;for(let b=0;b<i;b++){let A=b*a;if(A>=u)break;y[f+A]=d[p+b%c]}}else{let y=l,d=m;for(let b=0;b<i;b++){let A=b*a;if(A>=u)break;y[f+A]=d[p+b%c]}}}else for(let l=0;l<i&&l*a<u;l++)r.iset(l*a,t.iget(l%c))}}function ld(r,t,e){let n=Array.from(r.shape),o=n.length;if(t<0&&(t+=o),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=[];for(let u=0;u<o;u++)u!==t&&a.push(n[u]);if(a.length===0){let u=e(r);if(typeof u=="number"){let i=S.zeros([1],r.dtype);return i.data[0]=u,i}return u}if(o===2){let[u,i]=n;if(t===0){let s=[];for(let l=0;l<i;l++){let f=new Float64Array(u);for(let p=0;p<u;p++)f[p]=Number(r.get(p,l));let m=S.fromData(f,[u],"float64");s.push(e(m))}let c=s[0];if(c===void 0)return S.zeros([0],"float64");if(typeof c=="number"){let l=S.zeros([i],"float64");for(let f=0;f<i;f++)l.data[f]=s[f];return l}else{let l=[c.size,i],f=S.zeros(l,"float64");for(let m=0;m<i;m++){let p=s[m];for(let y=0;y<p.size;y++)f.data[y*i+m]=Number(p.iget(y))}return f}}else{let s=[];for(let l=0;l<u;l++){let f=new Float64Array(i);for(let p=0;p<i;p++)f[p]=Number(r.get(l,p));let m=S.fromData(f,[i],"float64");s.push(e(m))}let c=s[0];if(c===void 0)return S.zeros([0],"float64");if(typeof c=="number"){let l=S.zeros([u],"float64");for(let f=0;f<u;f++)l.data[f]=s[f];return l}else{let l=[u,c.size],f=S.zeros(l,"float64");for(let m=0;m<u;m++){let p=s[m];for(let y=0;y<p.size;y++)f.data[m*p.size+y]=Number(p.iget(y))}return f}}}if(o===1){let u=e(r);if(typeof u=="number"){let i=S.zeros([1],"float64");return i.data[0]=u,i}return u}throw new Error(`apply_along_axis not fully implemented for ${o}D arrays. Only 1D and 2D arrays are supported.`)}function fd(r,t,e){let n=r,o=r.shape.length;for(let a of e){let u=a<0?a+o:a;if(u<0||u>=o)throw new Error(`axis ${a} is out of bounds for array of dimension ${o}`);if(n=t(n,u),n.shape.length<o){let i=Array.from(n.shape);i.splice(u,0,1);let s=lr(i);n=new S(n.data,i,s,0,n.dtype)}}return n}function pc(r,t){return r.data.buffer===t.data.buffer}function md(r,t){return pc(r,t)}var Wr={divide:"warn",over:"warn",under:"ignore",invalid:"warn"};function yc(){return{...Wr}}function pd(r,t,e,n,o){let a=yc();return r!==void 0&&(Wr.divide=r,Wr.over=r,Wr.under=r,Wr.invalid=r),t!==void 0&&(Wr.divide=t),e!==void 0&&(Wr.over=e),n!==void 0&&(Wr.under=n),o!==void 0&&(Wr.invalid=o),a}function Ao(r,t){return Nr(cc(z(r),t),r)}function Wa(...r){let t=r.map(z);return Ly(t).map(e=>M(e))}function Ga(...r){if(r.length===0)return[];if(r.length===1)return[...r[0]];let t=[...r[0]];for(let e=1;e<r.length;e++){let n=r[e],o=Math.max(t.length,n.length),a=[];for(let u=0;u<o;u++){let i=u<t.length?t[t.length-1-u]:1,s=u<n.length?n[n.length-1-u]:1;if(i===s)a.unshift(i);else if(i===1)a.unshift(s);else if(s===1)a.unshift(i);else throw new Error(`Cannot broadcast shapes: dimensions ${i} and ${s} are incompatible`)}t=a}return t}function Tt(r,t,e){return M(Wy(z(r),t,e))}function Ot(r,t,e){let n=Array.isArray(e)?z(Q(e)):z(e);Gy(z(r),t,n)}function dc(r,t,e){return M(Xy(z(r),z(t),e))}function Ya(r,t,e,n){Jy(z(r),z(t),z(e),n)}function go(r,t){let e=t.map(z);return M(Yy(z(r),e))}function st(r,t,e){return M(Qy(z(r),z(t),e))}function bc(r,t,e=0){let n;return t instanceof P?n=Array.from(t.data):Array.isArray(t[0])?n=t.flat():n=t,Tt(r,n,e)}function Ac(r,t,e){return st(t,r,e)}function gc(r,t,e=0){let n=r.map(z),o=t.map(z);return M(Hy(n,o,e))}function Za(r,t,e){rd(z(r),z(t),z(e))}function Xa(r,t,e){Ky(z(r),z(t),z(e))}function Ja(r,t){let e=z(r),n=r.shape,o=r.size,a=r.dtype;if(typeof t=="number"||typeof t=="bigint"){r.fill(t);return}let u=z(t),i=t.shape,s=qr([i,n]);if(!s)throw new Error(`could not broadcast input array from shape (${i.join(",")}) into shape (${n.join(",")})`);if(s.length!==n.length||!s.every((l,f)=>l===n[f]))throw new Error(`could not broadcast input array from shape (${i.join(",")}) into shape (${n.join(",")})`);let c=cc(u,n);if(O(a))for(let l=0;l<o;l++){let f=c.iget(l),m=typeof f=="bigint"?f:BigInt(Math.round(Number(f)));e.iset(l,m)}else if(a==="bool")for(let l=0;l<o;l++){let f=c.iget(l);e.iset(l,f?1:0)}else for(let l=0;l<o;l++){let f=c.iget(l);e.iset(l,Number(f))}}function hc(r,t="int32"){return M(ad(r,t))}function Ka(...r){let t=r.map(z);return sd(...t).map(e=>M(e))}function Nc(r,t,e="raise"){let n=r.map(z);return M(id(n,t,e))}function Dc(r,t){let e=typeof r=="number"?z(Q([r])):z(r);return ud(e,t).map(n=>M(n))}function xc(r,t=2){return lc(r,t).map(e=>M(e))}function Cc(r){return td(z(r)).map(t=>M(t))}function Qa(r,t,e=!1){cd(z(r),t,e)}function Sc(r,t=0,e){return fc(r,t,e).map(n=>M(n))}function wc(r,t=0){return ed(z(r),t).map(e=>M(e))}function Ic(r,t=0,e){return mc(r,t,e).map(n=>M(n))}function zc(r,t=0){return nd(z(r),t).map(e=>M(e))}function _c(r,t,e=0){return od(r,(o,a)=>z(t(o,a)),e).map(o=>M(o))}function Ha(r,t,e=!1){return Zy(z(r),z(t),e)}function rs(r,t){return Pp(z(r),z(t))}function vc(r,t,e){let n=o=>{let a=r(M(o));return typeof a=="number"?a:z(a)};return M(ld(z(e),t,n))}function Mc(r,t,e){let n=(o,a)=>z(r(M(o),a));return M(fd(z(t),n,e))}function ts(r,t){return pc(z(r),z(t))}function es(r,t){return md(z(r),z(t))}var ns=yc,os=pd;var as=Tl,ss=Ol,is=El,us=Vt,cs=qt,ls=Ul,fs=$l;function ms(r,t){return Ro(z(r),t?.max_line_width??null,t?.precision??null,t?.suppress_small??null,t?.separator??" ",t?.prefix??"",t?.suffix??"",t?.threshold??null,t?.edgeitems??null,t?.floatmode??null,t?.sign??null)}function ps(r,t,e,n){return kl(z(r),t,e,n)}function Et(r,t,e){return qo(z(r),t,e)}function ys(r){if(r instanceof P)return r.ndim;if(typeof r=="number"||typeof r=="bigint"||typeof r=="boolean")return 0;if(Array.isArray(r)){let t=0,e=r;for(;Array.isArray(e)&&e.length>0;)t++,e=e[0];return t}return 0}function ho(r){if(r instanceof P)return r.shape;if(typeof r=="number"||typeof r=="bigint"||typeof r=="boolean")return[];if(Array.isArray(r)){let t=[],e=r;for(;Array.isArray(e)&&e.length>0;)t.push(e.length),e=e[0];return t}return[]}function ds(r){return r instanceof P?r.size:typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"?1:Array.isArray(r)?ho(r).reduce((e,n)=>e*n,1):1}function bs(r,...t){let e=r.storage,n=r.shape;if(t.length===0){if(r.size!==1)throw new Error("can only convert an array of size 1 to a scalar");return e.isCContiguous?e.data[e.offset]:e.iget(0)}if(t.length===1)return e.isCContiguous?e.data[e.offset+t[0]]:e.iget(t[0]);if(t.length!==n.length)throw new Error("incorrect number of indices for array");return e.get(...t)}function As(r){let t=r.shape,e=r.storage,n=t.length;if(n===0)return e.iget(0);if(e.isCContiguous){let l=function(f,m){let p=t[m],y=s[m];if(m===n-1){let b=new Array(p);for(let A=0;A<p;A++)b[A]=u[i+f+A];return b}let d=new Array(p);for(let b=0;b<p;b++)d[b]=l(f+b*y,m+1);return d};var a=l;let u=e.data,i=e.offset;if(n===1){let f=t[0],m=new Array(f);for(let p=0;p<f;p++)m[p]=u[i+p];return m}let s=new Array(n),c=1;for(let f=n-1;f>=0;f--)s[f]=c,c*=t[f];return l(0,0)}if(n===1){let u=[];for(let i=0;i<t[0];i++)u.push(e.iget(i));return u}function o(u,i){if(i===n)return e.get(...u);let s=[];for(let c=0;c<t[i];c++)u[i]=c,s.push(o(u,i+1));return s}return o(new Array(n),0)}function gs(r,t="C"){let e=r.storage;t==="F"&&console.warn('tobytes with order="F" not fully implemented, returning C-order');let n=e.data,o=n.BYTES_PER_ELEMENT;if(e.isCContiguous){let i=n.byteOffset+e.offset*o,s=r.size*o;return new Uint8Array(n.buffer,i,s)}let u=r.copy().data;return new Uint8Array(u.buffer,u.byteOffset,r.size*o)}function hs(r,t=!1){let n=r.data.BYTES_PER_ELEMENT;if(n===1)return t?r:r.copy();let o=t?r:r.copy(),a=o.data,u=new Uint8Array(a.buffer,a.byteOffset,a.byteLength);for(let i=0;i<a.length;i++){let s=i*n;for(let c=0;c<n/2;c++){let l=u[s+c];u[s+c]=u[s+n-1-c],u[s+n-1-c]=l}}return o}function Ns(r,t){if(!t||t===r.dtype)return r.copy();throw new Error("view with different dtype not fully implemented")}function Ds(r,t,e="",n=""){throw new Error("tofile requires Node.js file system access. Use serializeNpy for portable serialization.")}function xs(r,t){let e=r.storage,n=r.dtype,o=r.size;if(t instanceof U){if(!(n==="complex64"||n==="complex128"))throw new Error("Cannot fill non-complex array with complex value");if(e.isCContiguous){let u=e.data,i=e.offset;for(let s=0;s<o;s++)u[(i+s)*2]=t.re,u[(i+s)*2+1]=t.im}else for(let u=0;u<o;u++)e.iset(u,t)}else if(typeof t=="bigint")if(e.isCContiguous)e.data.fill(t,e.offset,e.offset+o);else for(let a=0;a<o;a++)e.iset(a,t);else{let a=typeof t=="boolean"?t?1:0:t;if(e.isCContiguous)e.data.fill(a,e.offset,e.offset+o);else for(let u=0;u<o;u++)e.iset(u,a)}}function Fc(r,t,e){let n=t instanceof P?t:Q(Array.isArray(t)?t:[t]);if(e===void 0){let o=Br(r),a=Br(n);return St([o,a],0)}return St([r,n],e)}function Cs(r,t,e){let n=Array.isArray(t)?t:[t],o=[...r.shape],a=r.storage;if(e===void 0){let A=Br(r),g=A.storage,h=[],N=new Set(n.map(D=>D<0?A.size+D:D));for(let D=0;D<A.size;D++)N.has(D)||h.push(g.iget(D));return Q(h,r.dtype)}let u=e<0?o.length+e:e,i=o[u],s=new Set(n.map(A=>A<0?i+A:A)),c=i-s.size,l=[...o];l[u]=c;let f=wr(l,r.dtype),m=f.storage,p=[],y=1;for(let A=o.length-1;A>=0;A--)p.unshift(y),y*=o[A];let d=[];y=1;for(let A=l.length-1;A>=0;A--)d.unshift(y),y*=l[A];let b=o.reduce((A,g)=>A*g,1);for(let A=0;A<b;A++){let g=[],h=A;for(let C=0;C<o.length;C++)g.push(Math.floor(h/p[C])),h=h%p[C];if(s.has(g[u]))continue;let N=0;for(let C of s)C<g[u]&&N++;let D=[...g];D[u]-=N;let x=0;for(let C=0;C<l.length;C++)x+=D[C]*d[C];m.iset(x,a.iget(A))}return f}function Bc(r,t,e,n){let o=Array.isArray(t)?t:[t],a=e instanceof P?e:Q(Array.isArray(e)?e:[e]);if(n===void 0){let u=Br(r),i=Br(a),s=u.data,c=i.data,l=Array.from(s);if(o.length===1){let f=o[0],m=f<0?u.size+f:f,p=Array.from(c);l.splice(m,0,...p)}else{let f=o.map((m,p)=>({idx:m<0?u.size+m:m,valIdx:p})).sort((m,p)=>m.idx-p.idx);for(let m=0;m<f.length;m++){let{idx:p,valIdx:y}=f[m],d=c[y%c.length];l.splice(p+m,0,d)}}return Q(l,r.dtype)}throw new Error("insert along axis not fully implemented in standalone")}function Tc(r,t,e="constant",n=0){let o=[...r.shape],a=o.length,u;typeof t=="number"?u=Array(a).fill([t,t]):Array.isArray(t)&&typeof t[0]=="number"?u=Array(a).fill(t):u=t;let i=o.map((d,b)=>d+u[b][0]+u[b][1]);if(e!=="constant")throw new Error(`pad mode '${e}' not fully implemented in standalone`);let s=wr(i,r.dtype),c=s.storage;if(n!==0)for(let d=0;d<s.size;d++)c.iset(d,n);let l=r.storage,f=[],m=1;for(let d=o.length-1;d>=0;d--)f.unshift(m),m*=o[d];let p=[];m=1;for(let d=i.length-1;d>=0;d--)p.unshift(m),m*=i[d];let y=o.reduce((d,b)=>d*b,1);for(let d=0;d<y;d++){let b=[],A=d;for(let h=0;h<o.length;h++)b.push(Math.floor(A/f[h])),A=A%f[h];let g=0;for(let h=0;h<i.length;h++)g+=(b[h]+u[h][0])*p[h];c.iset(g,l.iget(d))}return s}var Uc=["int8","int16","int32","int64"],$c=["uint8","uint16","uint32","uint64"],dd=[...Uc,...$c],Oc=["float32","float64"],Ec=["complex64","complex128"],Cx=[...dd,...Oc,...Ec],yd={bool:0,int8:1,uint8:2,int16:3,uint16:4,int32:5,uint32:6,int64:7,uint64:8,float32:9,float64:10,complex64:11,complex128:12};function No(r,t,e="safe"){let n=r instanceof P?r.dtype:r;if(e==="no"||e==="equiv")return n===t;if(e==="unsafe")return!0;let o=yd[n]??-1,a=yd[t]??-1;if(e==="safe"){if(Ur(n)&&Er(t)){let u={int8:8,int16:16,int32:32,int64:64,uint8:8,uint16:16,uint32:32,uint64:64,bool:1,float32:0,float64:0,complex64:0,complex128:0},i={float32:24,float64:53,int8:0,int16:0,int32:0,int64:0,uint8:0,uint16:0,uint32:0,uint64:0,bool:0,complex64:24,complex128:53},s=u[n]??64,c=i[t]??0;return s<=c}return!!(Ur(n)&&B(t)||Er(n)&&B(t)||o<=a)}return e==="same_kind"?!!(Ur(n)&&Ur(t)||Er(n)&&Er(t)||B(n)&&B(t)||n==="bool"&&Ur(t)||n==="bool"&&t==="bool"||Er(n)&&B(t)):!1}function Ss(...r){if(r.length===0)return"float64";let t=!1,e=!1;for(let n of r){let o=n.dtype;B(o)?(t=!0,o==="complex128"&&(e=!0)):Er(o)?o==="float64"&&(e=!0):Ur(o)&&(o==="int64"||o==="uint64"||o==="int32"||o==="uint32")&&(e=!0)}return t?e?"complex128":"complex64":e?"float64":"float32"}function ws(...r){if(r.length===0)return"float64";let t=r.map(a=>a instanceof P?a.dtype:a),e=t.some(B),n=t.some(Er),o=t.some(Ur);if(e){let a=t.some(s=>s==="float64"),u=t.some(s=>s==="complex128"),i=t.some(s=>s==="int64"||s==="uint64"||s==="int32"||s==="uint32");return u||a||i?"complex128":"complex64"}if(n){let a=t.some(u=>u==="float64");return o&&(t.some(i=>i==="int32"||i==="uint32"||i==="int64"||i==="uint64")||a)||a?"float64":"float32"}if(o){let a=t.some(c=>Uc.includes(c)),u=t.some(c=>$c.includes(c)),i={bool:8,int8:8,uint8:8,int16:16,uint16:16,int32:32,uint32:32,int64:64,uint64:64,float32:0,float64:0,complex64:0,complex128:0},s=Math.max(...t.map(c=>i[c]??0));return a&&u?s>=32?"int64":s>=16?"int32":"int16":a?s>=64?"int64":s>=32?"int32":s>=16?"int16":"int8":s>=64?"uint64":s>=32?"uint32":s>=16?"uint16":"uint8"}return"bool"}function Is(r){return typeof r=="boolean"?"bool":typeof r=="bigint"?r>=0n?r<=255n?"uint8":r<=65535n?"uint16":r<=4294967295n?"uint32":"uint64":r>=-128n&&r<=127n?"int8":r>=-32768n&&r<=32767n?"int16":r>=-2147483648n&&r<=2147483647n?"int32":"int64":Number.isInteger(r)?r>=0?r<=255?"uint8":r<=65535?"uint16":r<=4294967295?"uint32":"int64":r>=-128&&r<=127?"int8":r>=-32768&&r<=32767?"int16":r>=-2147483648&&r<=2147483647?"int32":"int64":"float64"}function zs(r,t){let e=r instanceof P?r.dtype:r;if(typeof t=="string")switch(t){case"number":case"numeric":return Cx.includes(e);case"integer":case"int":return dd.includes(e);case"signedinteger":return Uc.includes(e);case"unsignedinteger":return $c.includes(e);case"floating":case"float":return Oc.includes(e);case"complexfloating":case"complex":return Ec.includes(e);case"inexact":return Oc.includes(e)||Ec.includes(e);default:return e===t}return e===t}function _s(r){return r}function vs(r,t="GDFgdf",e="d"){let n={b:"int8",B:"uint8",h:"int16",H:"uint16",i:"int32",I:"uint32",l:"int64",L:"uint64",f:"float32",d:"float64",F:"complex64",D:"complex128",g:"float64",G:"complex128"},o={b:0,B:1,h:2,H:3,i:4,I:5,l:6,L:7,f:8,g:9.1,d:9,F:10,G:11.1,D:11};if(r.length===0)return e;let a=[];for(let s of r){let c=n[s];c&&a.push(c)}if(a.length===0)return e;let u=e,i=1/0;for(let s of t){let c=n[s];if(!c)continue;let l=o[s]??1/0,f=!0;for(let m of a)if(!No(m,c,"safe")){f=!1;break}f&&l<i&&(i=l,u=s)}return u}function Sr(r){return r instanceof P?r:Q(r)}function kc(r){let t=Sr(r),e=t.data,n=t.size;if(n===0)return Q([1]);let o=[1];for(let a=0;a<n;a++){let u=e[a],i=new Array(o.length+1).fill(0);for(let s=0;s<o.length;s++)i[s]+=o[s],i[s+1]-=o[s]*u;o=i}return Q(o)}function Rc(r,t){let e=Sr(r),n=Sr(t),o=e.data,a=n.data,u=Math.max(e.size,n.size),i=new Array(u).fill(0);for(let c=0;c<e.size;c++)i[u-e.size+c]+=o[c];for(let c=0;c<n.size;c++)i[u-n.size+c]+=a[c];let s=0;for(;s<i.length-1&&i[s]===0;)s++;return Q(i.slice(s))}function qc(r,t=1){let e=Sr(r);for(let n=0;n<t;n++){let o=e.data,a=e.size;if(a<=1)return Q([0]);let u=[];for(let i=0;i<a-1;i++){let s=a-1-i;u.push(o[i]*s)}e=Q(u)}return e}function Vc(r,t){let e=[...Sr(r).data],n=[...Sr(t).data];if(n.length===0||n.length===1&&n[0]===0)throw new Error("Division by zero polynomial");for(;e.length>1&&e[0]===0;)e.shift();for(;n.length>1&&n[0]===0;)n.shift();if(e.length<n.length)return[Q([0]),Q(e)];let o=[],a=[...e];for(;a.length>=n.length;){let u=a[0]/n[0];o.push(u);for(let i=0;i<n.length;i++)a[i]-=u*n[i];a.shift()}for(;a.length>1&&Math.abs(a[0])<1e-15;)a.shift();return[Q(o.length>0?o:[0]),Q(a.length>0?a:[0])]}function Pc(r,t,e){let n=r.data,o=t.data,a=r.size;if(e>=a)throw new Error("polyfit: degree must be less than number of points");let u=[];for(let m=0;m<a;m++){let p=[];for(let y=e;y>=0;y--)p.push(Math.pow(n[m],y));u.push(p)}let i=[],s=[];for(let m=0;m<=e;m++){i.push([]);for(let y=0;y<=e;y++){let d=0;for(let b=0;b<a;b++)d+=u[b][m]*u[b][y];i[m].push(d)}let p=0;for(let y=0;y<a;y++)p+=u[y][m]*o[y];s.push(p)}let c=e+1,l=i.map((m,p)=>[...m,s[p]]);for(let m=0;m<c;m++){let p=m;for(let y=m+1;y<c;y++)Math.abs(l[y][m])>Math.abs(l[p][m])&&(p=y);[l[m],l[p]]=[l[p],l[m]];for(let y=m+1;y<c;y++){let d=l[y][m]/l[m][m];for(let b=m;b<=c;b++)l[y][b]-=d*l[m][b]}}let f=new Array(c).fill(0);for(let m=c-1;m>=0;m--){let p=l[m][c];for(let y=m+1;y<c;y++)p-=l[m][y]*f[y];f[m]=p/l[m][m]}return Q(f)}function jc(r,t=1,e=0){let n=Sr(r),o=Array.isArray(e)?e:[e];for(let a=0;a<t;a++){let u=n.data,i=n.size,s=[];for(let l=0;l<i;l++){let f=i-l;s.push(u[l]/f)}let c=a<o.length?o[a]:0;s.push(c),n=Q(s)}return n}function Lc(r,t){let e=Sr(r),n=Sr(t),o=e.data,a=n.data,u=e.size+n.size-1,i=new Array(u).fill(0);for(let s=0;s<e.size;s++)for(let c=0;c<n.size;c++)i[s+c]+=o[s]*a[c];return Q(i)}function Wc(r,t){let e=Sr(r),n=Sr(t),o=e.data,a=n.data,u=Math.max(e.size,n.size),i=new Array(u).fill(0);for(let c=0;c<e.size;c++)i[u-e.size+c]+=o[c];for(let c=0;c<n.size;c++)i[u-n.size+c]-=a[c];let s=0;for(;s<i.length-1&&i[s]===0;)s++;return Q(i.slice(s))}function Gc(r,t){let e=Sr(r),n=e.data;if(typeof t=="number"){let i=n[0];for(let s=1;s<e.size;s++)i=i*t+n[s];return i}let o=t instanceof P?t:Q(t),a=o.data,u=[];for(let i=0;i<o.size;i++){let s=a[i],c=n[0];for(let l=1;l<e.size;l++)c=c*s+n[l];u.push(c)}return Q(u)}function Yc(r){let e=[...Sr(r).data];for(;e.length>1&&e[0]===0;)e.shift();let n=0;for(;e.length>1&&e[e.length-1]===0;)e.pop(),n++;let o=e.length-1;if(o+n===0)return bd([],[]);let u=[],i=[];if(o===1)u.push(-e[1]/e[0]),i.push(0);else if(o===2){let f=e[0],m=e[1],p=e[2],y=m*m-4*f*p;if(y>=0){let d=Math.sqrt(y);u.push((-m+d)/(2*f),(-m-d)/(2*f)),i.push(0,0)}else{let d=Math.sqrt(-y);u.push(-m/(2*f),-m/(2*f)),i.push(d/(2*f),-d/(2*f))}}else if(o>=3){let f=Sx(e,o);for(let m of f)u.push(m.re),i.push(m.im)}for(let f=0;f<n;f++)u.push(0),i.push(0);let s=u.map((f,m)=>m);s.sort((f,m)=>{let p=Math.sqrt(u[f]**2+i[f]**2),y=Math.sqrt(u[m]**2+i[m]**2);return Math.abs(p-y)>1e-10?y-p:Math.abs(u[f]-u[m])>1e-10?u[m]-u[f]:i[m]-i[f]});let c=s.map(f=>u[f]),l=s.map(f=>i[f]);return bd(c,l)}function bd(r,t){let e=r.length,n=new Float64Array(2*e);for(let a=0;a<e;a++)n[2*a]=r[a],n[2*a+1]=t[a];let o=S.fromData(n,[e],"complex128");return new P(o)}function Sx(r,t){let e=Array.from({length:t},()=>new Array(t).fill(0)),n=r[0];for(let o=0;o<t;o++)e[0][o]=-r[o+1]/n;for(let o=1;o<t;o++)e[o][o-1]=1;return wx(e,t)}function wx(r,t){let e=[],o=t,a=0,u=100*t,i=t,s=0;for(;o>0&&a<u;){if(a++,o===i?s++:(s=0,i=o),o===1){e.push({re:r[0][0],im:0}),o=0;break}if(o===2){e.push(...Ad(r[0][0],r[0][1],r[1][0],r[1][1])),o=0;break}let c=o-1;for(;c>0;){let y=Math.abs(r[c-1][c-1])+Math.abs(r[c][c]),d=222e-18*(y===0?1:y);if(Math.abs(r[c][c-1])<=d){r[c][c-1]=0;break}c--}let l=o-c;if(l===1){e.push({re:r[o-1][o-1],im:0}),o--;continue}if(l===2){e.push(...Ad(r[o-2][o-2],r[o-2][o-1],r[o-1][o-2],r[o-1][o-1])),o-=2;continue}let f;if(s>0&&s%10===0)f=Math.abs(r[o-1][o-2])+Math.abs(r[o-2][o-3]);else{let y=r[o-2][o-2],d=r[o-2][o-1],b=r[o-1][o-2],A=r[o-1][o-1],g=y+A,h=y*A-d*b,N=g*g-4*h;if(N>=0){let D=Math.sqrt(N),x=(g+D)/2,C=(g-D)/2;f=Math.abs(x-A)<Math.abs(C-A)?x:C}else f=A}for(let y=c;y<o;y++)r[y][y]=r[y][y]-f;let m=[],p=[];for(let y=c;y<o-1;y++){let d=Math.hypot(r[y][y],r[y+1][y]),b=d===0?1:r[y][y]/d,A=d===0?0:r[y+1][y]/d;m.push(b),p.push(A);for(let g=y;g<o;g++){let h=r[y][g],N=r[y+1][g];r[y][g]=b*h+A*N,r[y+1][g]=-A*h+b*N}}for(let y=0;y<m.length;y++){let d=c+y,b=m[y],A=p[y],g=Math.min(d+2,o-1);for(let h=c;h<=g;h++){let N=r[h][d],D=r[h][d+1];r[h][d]=b*N+A*D,r[h][d+1]=-A*N+b*D}}for(let y=c;y<o;y++)r[y][y]=r[y][y]+f}if(o>0)for(let c=0;c<o;c++)e.push({re:r[c][c],im:0});return e}function Ad(r,t,e,n){let o=r+n,a=r*n-t*e,u=o*o-4*a;if(u>=0){let i=Math.sqrt(u);return[{re:(o+i)/2,im:0},{re:(o-i)/2,im:0}]}else{let i=Math.sqrt(-u);return[{re:o/2,im:i/2},{re:o/2,im:-i/2}]}}var Do=new Uint8Array([147,78,85,77,80,89]),Zc=["float64","float32","complex128","complex64","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];function Xc(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}var Ix={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"},Ms={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"},gd={S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};function hd(r){if(r.startsWith("[")||r.startsWith("("))throw new Gr(`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 gd)throw new Gr(`Unsupported dtype: ${gd[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Ix[e];if(!o)throw new Gr(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Zc.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Xc(),u=t==="<"||t==="|"||t==="="&&a,i=t===">"||t==="="&&!a,s=parseInt(e.slice(1),10),c=s>1&&(i&&a||u&&!a);return{dtype:o,needsByteSwap:c,itemsize:s}}var Gr=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},hr=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}};function it(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Jc(t);return Kc(t,e)}function Jc(r){if(r.length<10)throw new hr("File too small to be a valid NPY file");for(let c=0;c<Do.length;c++)if(r[c]!==Do[c])throw new hr("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new hr(`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 hr("File truncated: header extends beyond file");let u=r.slice(o,a),i=new TextDecoder("utf-8").decode(u).trim(),s=zx(i);return{version:{major:t,minor:e},header:s,dataOffset:a}}function Kc(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:u}=hd(e.descr),i=e.shape.reduce((d,b)=>d*b,1),s=i*u,c=r.length-n;if(c<s)throw new hr(`File truncated: expected ${s} bytes of data, got ${c}`);let l=new ArrayBuffer(s);new Uint8Array(l).set(r.subarray(n,n+s));let m=_x(l,o,i,a,u),p=e.shape,y;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),b=S.fromData(m,d,o);y=vx(b,d),p=e.shape}else y=S.fromData(m,[...p],o);return new P(y)}function zx(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 hr(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",u=n[1].trim(),i;return u===""?i=[]:i=u.split(",").map(s=>s.trim()).filter(s=>s!=="").map(s=>{let c=parseInt(s,10);if(isNaN(c))throw new hr(`Invalid shape value: ${s}`);return c}),{descr:o,fortran_order:a,shape:i}}function _x(r,t,e,n,o){let a=K(t);if(!a)throw new hr(`Cannot create array for dtype: ${t}`);let u=B(t),i=u?e*2:e;if(!n)return new a(r,0,i);let s=new Uint8Array(r),c=new Uint8Array(r.byteLength);if(u){let l=o/2;for(let f=0;f<e*2;f++){let m=f*l;for(let p=0;p<l;p++)c[m+p]=s[m+l-1-p]}}else for(let l=0;l<e;l++){let f=l*o;for(let m=0;m<o;m++)c[f+m]=s[f+o-1-m]}return new a(c.buffer,0,i)}function vx(r,t){let e=t.length,n=r.size,o=r.dtype,a=K(o);if(!a)throw new hr(`Cannot create array for dtype: ${o}`);let u=new a(n),i=[...t].reverse(),s=Nd(t),c=Nd(i),l=new Array(e).fill(0);for(let f=0;f<n;f++){let m=f;for(let y=0;y<e;y++){let d=s[y];l[y]=Math.floor(m/d),m=m%d}let p=0;for(let y=0;y<e;y++)p+=l[e-1-y]*c[y];O(o),u[p]=r.iget(f)}return S.fromData(u,i,o)}function Nd(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 Kr(r){let t=r.shape,e=r.dtype,n=Ms[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,u=12,s=(64-(u+a.length+1)%64)%64;a=a+" ".repeat(s)+`
|
|
6
|
+
`;let c=new TextEncoder().encode(a),l=c.length,f=r.size,m=Yr(e),p=f*m,y=u+l+p,d=new Uint8Array(y);d.set(Do,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,u);let b=u+l;return Mx(r,d.subarray(b),m),d}function Mx(r,t,e){let n=r.dtype,o=r.size,a=Xc(),u=O(n),i=B(n),s=r.storage;if(s.isCContiguous&&s.offset===0&&a){let l=s.data,f=new Uint8Array(l.buffer,l.byteOffset,o*e);t.set(f)}else{let l=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let f=0;f<o;f++){let m=s.iget(f),p=f*e;u?Fx(l,p,m,n==="uint64"):i?Bx(l,p,m,n):Tx(l,p,m,n)}}}function Fx(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Bx(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 Tx(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 Ox=(()=>{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 Qc(r){let t=4294967295;for(let e=0;e<r.length;e++)t=Ox[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}async function Cd(r){let t=wd(r),e=new Map;for(let n of t){let o=await Ex(n);e.set(n.name,o)}return e}function Sd(r){let t=wd(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 wd(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),i=[],s=a;for(let c=0;c<u&&e.getUint32(s,!0)===33639248;c++){let f=e.getUint16(s+10,!0),m=e.getUint32(s+16,!0),p=e.getUint32(s+20,!0),y=e.getUint32(s+24,!0),d=e.getUint16(s+28,!0),b=e.getUint16(s+30,!0),A=e.getUint16(s+32,!0),g=e.getUint32(s+42,!0),h=t.slice(s+46,s+46+d),N=new TextDecoder("utf-8").decode(h);i.push({name:N,compressionMethod:f,crc32:m,compressedSize:p,uncompressedSize:y,localHeaderOffset:g}),s=s+46+d+b+A}for(let c of i){let l=c.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let m=e.getUint16(l+26,!0),p=e.getUint16(l+28,!0),y=l+30+m+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 Ex(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Ux(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Ux(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),i=new Uint8Array(u),s=0;for(let c of a)i.set(c,s),s+=c.length;return i}async function Co(r,t={}){let e=t.force??!1,n=await Cd(r);return Id(n,e)}function So(r,t={}){let e=t.force??!1,n=Sd(r);return Id(n,e)}function Id(r,t){let e=new Map,n=[],o=new Map;for(let[a,u]of r){if(!a.endsWith(".npy"))continue;let i=a.slice(0,-4);try{let s=it(u);e.set(i,s)}catch(s){if(s instanceof Gr&&t)n.push(i),o.set(i,s.message);else throw s}}return{arrays:e,skipped:n,errors:o}}async function zd(r,t={}){let e=await Co(r,t);return Object.fromEntries(e.arrays)}function _d(r,t={}){let e=So(r,t);return Object.fromEntries(e.arrays)}async function vd(r,t={}){let e=t.compress??!1,n=[];for(let[m,p]of r){let y=Qc(p),d,b;e?(d=await kx(p),d.length<p.length?b=8:(d=p,b=0)):(d=p,b=0),n.push({name:m,data:p,compressedData:d,crc:y,compressionMethod:b,offset:0})}let o=0;for(let m of n){let p=new TextEncoder().encode(m.name);o+=30+p.length+m.compressedData.length}let a=0;for(let m of n){let p=new TextEncoder().encode(m.name);a+=46+p.length}let i=o+a+22,s=new Uint8Array(i),c=new DataView(s.buffer),l=0;for(let m of n)m.offset=l,l=Fd(s,c,l,m);let f=l;for(let m of n)l=Bd(s,c,l,m);return Td(c,l,n.length,a,f),s}function Md(r){let t=[];for(let[l,f]of r){let m=Qc(f);t.push({name:l,data:f,compressedData:f,crc:m,compressionMethod:0,offset:0})}let e=0;for(let l of t){let f=new TextEncoder().encode(l.name);e+=30+f.length+l.compressedData.length}let n=0;for(let l of t){let f=new TextEncoder().encode(l.name);n+=46+f.length}let a=e+n+22,u=new Uint8Array(a),i=new DataView(u.buffer),s=0;for(let l of t)l.offset=s,s=Fd(u,i,s,l);let c=s;for(let l of t)s=Bd(u,i,s,l);return Td(i,s,t.length,n,c),u}function Fd(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 Bd(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 Td(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 kx(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),i=new Uint8Array(u),s=0;for(let c of a)i.set(c,s),s+=c.length;return i}async function Bs(r,t={}){let e=Od(r);return vd(e,{compress:t.compress??!1})}function Ts(r){let t=Od(r);return Md(t)}function Od(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=Kr(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=Kr(o),u=n.endsWith(".npy")?n:`${n}.npy`;t.set(u,a)}return t}function ut(r,t={}){let{delimiter:e,comments:n="#",skiprows:o=0,usecols:a,max_rows:u,dtype:i="float64",missing_values:s,filling_values:c}=t,l=r.split(/\r?\n/);if(o>0&&(l=l.slice(o)),l=l.filter(d=>{let b=d.trim();return!(b===""||n&&b.startsWith(n))}),u!==void 0&&u>0&&(l=l.slice(0,u)),l.length===0)return Q([],i);let f=[],m=new Set(s?Array.isArray(s)?s:[s]:[]),p=c!==void 0?c:i.includes("int")||i==="bool"?0:NaN;for(let d of l){let b;e===void 0?b=d.trim().split(/\s+/):b=d.split(e),a!==void 0&&(b=(Array.isArray(a)?a:[a]).map(h=>(h<0&&(h=b.length+h),b[h]??"")));let A=b.map(g=>{let h=g.trim();if(m.has(h)||h==="")return p;let N=parseFloat(h);return isNaN(N)?p:N});f.push(A)}let y=f[0]?.length??0;for(let d=1;d<f.length;d++)if(f[d].length!==y)throw new Error(`Inconsistent number of columns: row 0 has ${y} columns, row ${d} has ${f[d].length} columns`);return y===1?Q(f.map(d=>d[0]),i):Q(f,i)}function wo(r,t={}){let e={...t,missing_values:t.missing_values??["","nan","NaN","NA","N/A","-"],filling_values:t.filling_values??NaN};return ut(r,e)}function Io(r,t,e="float64"){let n=typeof t=="string"?new RegExp(t,"gm"):new RegExp(t.source,"gm"),o=[],a;for(;(a=n.exec(r))!==null;)if(a.length>1){let u=a.slice(1).map(i=>{let s=parseFloat(i);return isNaN(s)?0:s});o.push(u)}return o.length===0?Q([],e):o[0].length===1?Q(o.map(u=>u[0]),e):Q(o,e)}function Ed(r,t){let e=typeof r=="bigint"?Number(r):r,n=t.match(/^%([+-]?)(\d*)(?:\.(\d+))?([dfeEgGs])$/);if(!n)return String(e);let[,o,a,u,i]=n,s=u!==void 0?parseInt(u,10):void 0,c;switch(i){case"d":c=Math.round(e).toString();break;case"f":c=e.toFixed(s??6);break;case"e":c=e.toExponential(s??6).replace(/e([+-])(\d)$/,"e$10$2");break;case"E":c=e.toExponential(s??6).toUpperCase().replace(/E([+-])(\d)$/,"E$10$2");break;case"g":case"G":{let l=s??6,f=Math.floor(Math.log10(Math.abs(e)));f>=-4&&f<l?(c=e.toPrecision(l),c.includes(".")&&(c=c.replace(/\.?0+$/,""))):c=e.toExponential(l-1),i==="G"&&(c=c.toUpperCase());break}case"s":c=String(e);break;default:c=String(e)}if(a){let l=parseInt(a,10);if(c.length<l){let f=" ".repeat(l-c.length);o==="-"?c=c+f:c=f+c}}return o==="+"&&e>=0&&!c.startsWith("-")&&(c="+"+c),c}function Ut(r,t={}){let{fmt:e="%.18e",delimiter:n=" ",newline:o=`
|
|
7
|
+
`,header:a,footer:u,comments:i="# "}=t;if(r.ndim>2)throw new Error("savetxt: array must be 1D or 2D");let s=[];if(a!==void 0){let l=a.split(/\r?\n/);for(let f of l)f.startsWith(i.trimEnd())?s.push(f):s.push(i+f)}let c=r.toArray();if(r.ndim===1)for(let l of c)s.push(Ed(l,e));else for(let l of c){let f=l.map(m=>Ed(m,e));s.push(f.join(n))}if(u!==void 0){let l=u.split(/\r?\n/);for(let f of l)f.startsWith(i.trimEnd())?s.push(f):s.push(i+f)}return s.join(o)+o}var q=r=>{if(r instanceof tr)return r;let t=r.base?q(r.base):void 0;return tr.fromStorage(r.storage,t)},tr=class r extends P{constructor(t,e){super(t,e),this._base=e}static fromStorage(t,e){return new r(t,e)}get base(){return this._base??null}get T(){return this.transpose()}get itemsize(){return Yr(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){let e=this._storage.dtype,n=this.size;if(O(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 i=a;if(i<0&&(i=this.shape[u]+i),i<0||i>=this.shape[u])throw new Error(`Index ${a} is out of bounds for axis ${u} with size ${this.shape[u]}`);return i}),o=this.dtype;if(B(o))this._storage.set(n,e);else if(O(o)){let a=e instanceof U?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 U?e.re:Number(e))?1:0;this._storage.set(n,u)}else{let a=e instanceof U?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=K(t);if(!u)throw new Error(`Cannot convert to dtype ${t}`);let i=new u(a),s=this.data;if(O(n)&&!O(t)){let l=s;if(t==="bool")for(let f=0;f<a;f++)i[f]=l[f]!==BigInt(0)?1:0;else for(let f=0;f<a;f++)i[f]=Number(l[f])}else if(!O(n)&&O(t)){let l=s;for(let f=0;f<a;f++)i[f]=BigInt(Math.round(Number(l[f])))}else if(t==="bool"){let l=s;for(let f=0;f<a;f++)i[f]=l[f]!==0?1:0}else if(n==="bool"&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else if(!O(n)&&!O(t)){let l=s;for(let f=0;f<a;f++)i[f]=l[f]}else{let l=s;for(let f=0;f<a;f++)i[f]=l[f]}let c=S.fromData(i,o,t);return new r(c)}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=Eo(s);return Uo(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 f;c.step>0?f=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):f=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(f),o.push(l*c.step)}}let u=S.fromData(this._storage.data,n,this._storage.dtype,o,a),i=this._base??this;return new r(u,i)}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}`)}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=Ue(this,e).storage,a=n.data===this.data?this._base??this:void 0;return r.fromStorage(n,a)}ravel(){let t=$e(this).storage,n=t.data===this.data?this._base??this:void 0;return r.fromStorage(t,n)}put(t,e){let n=e instanceof r?e._storage:e;Ot(this,t,n)}compress(t,e){let n=t instanceof r?t:r.fromStorage(S.fromData(new Uint8Array(t.map(o=>o?1:0)),[t.length],"bool"));return q(st(n,this,e))}choose(t){return q(go(this,t))}clip(t,e){return q(de(this,t,e))}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 U?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 q(st(t,this,e))}toString(){return Et(this)}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 i=0;i<t[a];i++)o[a]=i,u.push(n(o,a+1));return u};return n(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){let n=this._storage.data,o=n.BYTES_PER_ELEMENT,a=this._storage.offset*o,u=this.size*o;return n.buffer.slice(a,a+u)}let e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){let e=t[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(t)}byteswap(t=!1){let e=t?this:this.copy(),n=e._storage.data,o=n.BYTES_PER_ELEMENT;if(o===1)return e;let a=n.buffer,u=new DataView(a);for(let i=0;i<n.length;i++){let s=i*o;if(o===2){let c=u.getUint8(s),l=u.getUint8(s+1);u.setUint8(s,l),u.setUint8(s+1,c)}else if(o===4){let c=u.getUint8(s),l=u.getUint8(s+1),f=u.getUint8(s+2),m=u.getUint8(s+3);u.setUint8(s,m),u.setUint8(s+1,f),u.setUint8(s+2,l),u.setUint8(s+3,c)}else if(o===8){let c=u.getUint8(s),l=u.getUint8(s+1),f=u.getUint8(s+2),m=u.getUint8(s+3),p=u.getUint8(s+4),y=u.getUint8(s+5),d=u.getUint8(s+6),b=u.getUint8(s+7);u.setUint8(s,b),u.setUint8(s+1,d),u.setUint8(s+2,y),u.setUint8(s+3,p),u.setUint8(s+4,m),u.setUint8(s+5,f),u.setUint8(s+6,l),u.setUint8(s+7,c)}}return e}view(t){if(!t||t===this.dtype)return r.fromStorage(this._storage,this._base??this);let e=Yr(this.dtype),n=Yr(t);if(e!==n)throw new Error("When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.");let o=K(t);if(!o)throw new Error(`Unsupported dtype: ${t}`);let a=this._storage.data,u=a.byteOffset+this._storage.offset*e,i=new o(a.buffer,u,this.size),s=S.fromData(i,[...this.shape],t,[...this._storage.strides],0);return r.fromStorage(s,this._base??this)}tofile(t,e="",n=""){throw new Error('tofile() requires file system access. Use the node module: import { save } from "numpy-ts/node"')}round(t=0){return this.around(t)}conjugate(){return this.conj()}around(t=0){return q(Bt(this,t))}allclose(t,e=1e-5,n=1e-8){return Mt(this,t,e,n)}isclose(t,e=1e-5,n=1e-8){return q(Yn(this,t,e,n))}average(t,e){let n=cn(this,e,t);return n instanceof P?q(n):n}dot(t){let e=gt(this,t);return e instanceof P?q(e):e}trace(){return et(this)}inner(t){let e=Dt(this,t);return e instanceof P?q(e):e}tensordot(t,e=2){let n=Ct(this,t,e);return n instanceof P?q(n):n}divmod(t){let e=fe(this,t);return[q(e[0]),q(e[1])]}searchsorted(t,e="left"){return q(Ft(this,t,e))}sqrt(){return q(Wt(this))}exp(){return q(Yt(this))}exp2(){return q(Zt(this))}expm1(){return q(Xt(this))}log(){return q(Jt(this))}log2(){return q(Kt(this))}log10(){return q(Qt(this))}log1p(){return q(Ht(this))}absolute(){return q(ee(this))}negative(){return q(ne(this))}sign(){return q(oe(this))}positive(){return q(ie(this))}reciprocal(){return q(ue(this))}ceil(){return q(uo(this))}fix(){return q(co(this))}floor(){return q(lo(this))}rint(){return q(fo(this))}trunc(){return q(mo(this))}sin(){return q(be(this))}cos(){return q(Ae(this))}tan(){return q(ge(this))}arcsin(){return q(he(this))}arccos(){return q(Ne(this))}arctan(){return q(De(this))}degrees(){return q(Se(this))}radians(){return q(we(this))}sinh(){return q(Ie(this))}cosh(){return q(ze(this))}tanh(){return q(_e(this))}arcsinh(){return q(ve(this))}arccosh(){return q(Me(this))}arctanh(){return q(Fe(this))}bitwise_not(){return q(oo(this))}invert(){return q(ao(this))}logical_not(){return q(Fn(this))}isfinite(){return q(Tn(this))}isinf(){return q(On(this))}isnan(){return q(En(this))}isnat(){return q(Un(this))}signbit(){return q(kn(this))}spacing(){return q(qn(this))}cbrt(){return q(ce(this))}fabs(){return q(le(this))}square(){return q(me(this))}conj(){return q(bo(this))}flatten(){return q(Br(this))}argwhere(){return q(Hn(this))}add(t){return q(Pt(this,t))}subtract(t){return q(jt(this,t))}multiply(t){return q(Lt(this,t))}divide(t){return q(yt(this,t))}mod(t){return q(ae(this,t))}floor_divide(t){return q(se(this,t))}power(t){return q(Gt(this,t))}logaddexp(t){return q(re(this,t))}logaddexp2(t){return q(te(this,t))}arctan2(t){return q(xe(this,t))}hypot(t){return q(Ce(this,t))}greater(t){return q(Vn(this,t))}greater_equal(t){return q(Pn(this,t))}less(t){return q(jn(this,t))}less_equal(t){return q(Ln(this,t))}equal(t){return q(Wn(this,t))}not_equal(t){return q(Gn(this,t))}bitwise_and(t){return q(to(this,t))}bitwise_or(t){return q(eo(this,t))}bitwise_xor(t){return q(no(this,t))}left_shift(t){return q(so(this,t))}right_shift(t){return q(io(this,t))}logical_and(t){return q(vn(this,t))}logical_or(t){return q(Mn(this,t))}logical_xor(t){return q(Bn(this,t))}copysign(t){return q($n(this,t))}nextafter(t){return q(Rn(this,t))}remainder(t){return q(pe(this,t))}heaviside(t){return q(ye(this,t))}matmul(t){return q(Ee(this,t))}outer(t){return q(xt(this,t))}sum(t,e=!1){let n=Ze(this,t,e);return n instanceof P?q(n):n}mean(t,e=!1){let n=Xe(this,t,e);return n instanceof P?q(n):n}prod(t,e=!1){let n=Je(this,t,e);return n instanceof P?q(n):n}max(t,e=!1){let n=Ke(this,t,e);return n instanceof P?q(n):n}min(t,e=!1){let n=He(this,t,e);return n instanceof P?q(n):n}ptp(t,e=!1){let n=tn(this,t,e);return n instanceof P?q(n):n}nansum(t,e=!1){let n=yn(this,t,e);return n instanceof P?q(n):n}nanprod(t,e=!1){let n=dn(this,t,e);return n instanceof P?q(n):n}nanmean(t,e=!1){let n=bn(this,t,e);return n instanceof P?q(n):n}nanmin(t,e=!1){let n=hn(this,t,e);return n instanceof P?q(n):n}nanmax(t,e=!1){let n=Nn(this,t,e);return n instanceof P?q(n):n}argmin(t){let e=en(this,t);return e instanceof P?q(e):e}argmax(t){let e=nn(this,t);return e instanceof P?q(e):e}nanargmin(t){let e=Dn(this,t);return e instanceof P?q(e):e}nanargmax(t){let e=xn(this,t);return e instanceof P?q(e):e}var(t,e=0,n=!1){let o=nt(this,t,e,n);return o instanceof P?q(o):o}std(t,e=0,n=!1){let o=on(this,t,e,n);return o instanceof P?q(o):o}nanvar(t,e=0,n=!1){let o=An(this,t,e,n);return o instanceof P?q(o):o}nanstd(t,e=0,n=!1){let o=gn(this,t,e,n);return o instanceof P?q(o):o}all(t,e=!1){let n=ln(this,t,e);return n instanceof P?q(n):n}any(t,e=!1){let n=fn(this,t,e);return n instanceof P?q(n):n}median(t,e=!1){let n=an(this,t,e);return n instanceof P?q(n):n}nanmedian(t,e=!1){let n=wn(this,t,e);return n instanceof P?q(n):n}percentile(t,e,n=!1){let o=sn(this,t,e,n);return o instanceof P?q(o):o}quantile(t,e,n=!1){let o=un(this,t,e,n);return o instanceof P?q(o):o}nanquantile(t,e,n=!1){let o=In(this,t,e,n);return o instanceof P?q(o):o}nanpercentile(t,e,n=!1){let o=zn(this,t,e,n);return o instanceof P?q(o):o}cumsum(t){return q(mn(this,t))}cumprod(t){return q(pn(this,t))}nancumsum(t){return q(Cn(this,t))}nancumprod(t){return q(Sn(this,t))}sort(t=-1){return q(Zn(this,t))}argsort(t=-1){return q(Xn(this,t))}partition(t,e=-1){return q(Jn(this,t,e))}argpartition(t,e=-1){return q(Kn(this,t,e))}diagonal(t=0,e=0,n=1){return q(ht(this,t,e,n))}resize(t){return q(Le(this,t))}diff(t=1,e=-1){return q(yo(this,t,e))}take(t,e){return q(Tt(this,t,e))}repeat(t,e){return q(Pe(this,t,e))}transpose(t){return q(Nt(this,t))}squeeze(t){return q(ke(this,t))}expand_dims(t){return q(Re(this,t))}swapaxes(t,e){return q(qe(this,t,e))}moveaxis(t,e){return q(Ve(this,t,e))}nonzero(){return Qn(this).map(q)}};function Hc(...r){let t=[],e="xy";for(let i of r)i instanceof tr?t.push(i):typeof i=="object"&&"indexing"in i&&(e=i.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(i=>i.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 i=0;i<t.length;i++){let s=t[i],c=s.size,l=new Array(a).fill(1);l[i]=c;let f=s.reshape(...l),m=Ao(f,o),p=tr.fromStorage(m.storage.copy());u.push(p)}return e==="xy"&&u.length>=2&&([u[0],u[1]]=[u[1],u[0]]),u}var F=r=>{if(r instanceof tr)return r;let t=r.base?F(r.base):void 0;return tr.fromStorage(r.storage,t)};function Ud(r,t){return F(Ao(r,t))}function $d(r,t,e){return F(Tt(r,t,e))}function kd(r,t,e){return F(dc(r,t,e))}function Rd(r,t){return F(go(r,t))}function qd(r,t,e){return F(st(r,t,e))}function Vd(r,t,e=0){return F(bc(r,t,e))}function Pd(r,t,e){return F(Ac(r,t,e))}function jd(r,t,e=0){return F(gc(r,t,e))}function Ld(r,t="int32"){return F(hc(r,t))}function Wd(r,t,e="raise"){return F(Nc(r,t,e))}function Gd(r,t){return Dc(r,t).map(F)}function Yd(r,t=2){return xc(r,t).map(F)}function Zd(r){return Cc(r).map(F)}function Xd(r,t=0,e){return Sc(r,t,e).map(F)}function Jd(r,t=0){return wc(r,t).map(F)}function Kd(r,t=0,e){return Ic(r,t,e).map(F)}function Qd(r,t=0){return zc(r,t).map(F)}function Hd(r,t,e=0){return _c(r,t,e).map(F)}function rb(r,t,e){return F(vc(o=>r(F(o)),t,e))}function tb(r,t,e){return F(Mc((o,a)=>r(F(o),a),t,e))}function eb(r,t){return F(Pt(r,t))}function nb(r,t){return F(jt(r,t))}function ob(r,t){return F(Lt(r,t))}function ab(r){return F(Wt(r))}function rl(r,t){return F(Gt(r,t))}function sb(r){return F(Yt(r))}function ib(r){return F(Zt(r))}function ub(r){return F(Xt(r))}function cb(r){return F(Jt(r))}function lb(r){return F(Kt(r))}function fb(r){return F(Qt(r))}function mb(r){return F(Ht(r))}function pb(r,t){return F(re(r,t))}function yb(r,t){return F(te(r,t))}function tl(r){return F(ee(r))}function db(r){return F(ne(r))}function bb(r){return F(oe(r))}function Ab(r,t){return F(ae(r,t))}function gb(r,t){return F(yt(r,t))}function hb(r,t){return F(se(r,t))}function Nb(r){return F(ie(r))}function Db(r){return F(ue(r))}function xb(r){return F(ce(r))}function Cb(r){return F(le(r))}function Sb(r,t){let e=fe(r,t);return[F(e[0]),F(e[1])]}function wb(r){return F(me(r))}function Ib(r,t){return F(pe(r,t))}function zb(r,t){return F(ye(r,t))}function _b(r,t){return F(bi(r,t))}function vb(r,t){return F(Ai(r,t))}function Mb(r){let t=gi(r);return[F(t[0]),F(t[1])]}function Fb(r,t){return F(hi(r,t))}function Bb(r,t){return F(Ni(r,t))}function Tb(r,t){return F(Di(r,t))}function Ob(r){let t=xi(r);return[F(t[0]),F(t[1])]}function Eb(r,t,e){return F(de(r,t,e))}function Ub(r,t){return F(Ci(r,t))}function $b(r,t){return F(Si(r,t))}function kb(r,t){return F(wi(r,t))}function Rb(r,t){return F(Ii(r,t))}function qb(r,t=0,e,n){return F(zi(r,t,e,n))}function Vb(r,t,e,n,o){return F(_i(r,t,e,n,o))}function Pb(r,t=Math.PI,e=-1,n=2*Math.PI){return F(vi(r,t,e,n))}function jb(r){return F(Mi(r))}function Lb(r){return F(Fi(r))}function Wb(r,t){return F(to(r,t))}function Gb(r,t){return F(eo(r,t))}function Yb(r,t){return F(no(r,t))}function el(r){return F(oo(r))}function Zb(r){return F(ao(r))}function nl(r,t){return F(so(r,t))}function ol(r,t){return F(io(r,t))}function Xb(r,t,e){return F(Uu(r,t,e))}function Jb(r,t,e,n){return F($u(r,t,e,n))}function Kb(r){return F(ku(r))}function Qb(r){return F(sc(r))}function Hb(r){return F(ic(r))}function al(r){return F(bo(r))}function rA(r,t){return F(uc(r,t))}function tA(r,t=er){return F(wr(r,t))}function eA(r,t=er){return F(Po(r,t))}function nA(r,t=er){return F(jo(r,t))}function oA(r,t,e){return F(Lo(r,t,e))}function aA(r,t){return F(Q(r,t))}function sA(r,t,e=1,n=er){return F(js(r,t,e,n))}function iA(r,t,e=50,n=er){return F(Ls(r,t,e,n))}function uA(r,t,e=50,n=10,o=er){return F(Ws(r,t,e,n,o))}function cA(r,t,e=50,n=er){return F(Gs(r,t,e,n))}function lA(r,t,e=0,n=er){return F(Wo(r,t,e,n))}function fA(r,t=er){return F(Ys(r,t))}function mA(r,t){return F(Qr(r,t))}function pA(r,t){return F(Zs(r,t))}function yA(r,t){return F(Xs(r,t))}function dA(r,t){return F(Js(r,t))}function bA(r,t,e){return F(Ks(r,t,e))}function AA(r){return F(Qs(r))}function gA(r,t){return F(Hs(r,t))}function hA(r,t){return F(ri(r,t))}function NA(r,t){return F(ti(r,t))}function DA(r,t){return F(ei(r,t))}function xA(r,t,e){return F(ni(r,t,e))}function CA(r,t=0){return F(Go(r,t))}function SA(r,t=0){return F(oi(r,t))}function wA(r,t,e=0,n=er){return F(ai(r,t,e,n))}function IA(r,t=0){return F(si(r,t))}function zA(r,t=0){return F(ii(r,t))}function _A(r,t,e=!1){return F(ui(r,t,e))}function vA(r,t=er,e=-1,n=0){return F(ci(r,t,e,n))}function MA(r,t,e=er){return F(li(r,t,e))}function FA(r,t=er,e=-1){return F(fi(r,t,e))}function BA(r,t=er,e=-1,n){return F(mi(r,t,e,n))}function TA(r,t=er,e=-1,n=""){return F(pi(r,t,e,n))}function OA(r,t,e){return F(yo(r,t,e))}function EA(r,t,e){return F(ac(r,t,e))}function UA(r,t){let e=gt(r,t);return e instanceof P?F(e):e}function $A(r,t=0,e=0,n=1){return F(ht(r,t,e,n))}function kA(r,t){return F(Xi(r,t))}function RA(r,t){return F(Nt(r,t))}function qA(r,t){let e=Dt(r,t);return e instanceof P?F(e):e}function VA(r,t){return F(xt(r,t))}function PA(r,t,e=2){let n=Ct(r,t,e);return n instanceof P?F(n):n}function jA(r,t,e=-1){let n=ra(r,t,e);return n instanceof P?F(n):n}function LA(r){return F(ta(r))}function WA(r,t){return F(ea(r,t))}function GA(r,t){return F(Ji(r,t))}function YA(r,t){return F(Ki(r,t))}function ZA(r,t,e=-1,n=-1,o=-1,a){let u=na(r,t,e,n,o,a),i=or(r.dtype,t.dtype);if(u instanceof U){let c=K(i==="complex64"?"float32":"float64"),l=new c(2);return l[0]=u.re,l[1]=u.im,tr.fromStorage(S.fromData(l,[],i))}if(typeof u=="number"){if(B(i)){let f=K(i==="complex64"?"float32":"float64"),m=new f(2);return m[0]=u,m[1]=0,tr.fromStorage(S.fromData(m,[],i))}let s=K(i),c=new s(1);return c[0]=u,tr.fromStorage(S.fromData(c,[],i))}return F(u)}function XA(r,t){return F(Ee(r,t))}function JA(r,t){return F(vn(r,t))}function KA(r,t){return F(Mn(r,t))}function QA(r){return F(Fn(r))}function HA(r,t){return F(Bn(r,t))}function rg(r){return F(Tn(r))}function tg(r){return F(On(r))}function eg(r){return F(En(r))}function ng(r){return F(Un(r))}function og(r){return F(xu(r))}function ag(r){return F(Cu(r))}function sg(r){return F(Su(r))}function ig(r){return F(wu(r))}function ug(r,t){return F(Iu(r,t))}function cg(r,t){return F($n(r,t))}function lg(r){return F(kn(r))}function fg(r,t){return F(Rn(r,t))}function mg(r){return F(qn(r))}function pg(r,t){return F(Vn(r,t))}function yg(r,t){return F(Pn(r,t))}function dg(r,t){return F(jn(r,t))}function bg(r,t){return F(Ln(r,t))}function Ag(r,t){return F(Wn(r,t))}function gg(r,t){return F(Gn(r,t))}function hg(r,t,e=1e-5,n=1e-8){return F(Yn(r,t,e,n))}function Ng(r){return F(kc(r))}function Dg(r,t){return F(Rc(r,t))}function xg(r,t=1){return F(qc(r,t))}function Cg(r,t){let e=Vc(r,t);return[F(e[0]),F(e[1])]}function Sg(r,t,e){return F(Pc(r,t,e))}function wg(r,t=1,e=0){return F(jc(r,t,e))}function Ig(r,t){return F(Lc(r,t))}function zg(r,t){return F(Wc(r,t))}function _g(r,t){let e=Gc(r,t);return e instanceof P?F(e):e}function vg(r){return F(Yc(r))}function Mg(r,t,e){let n=Ze(r,t,e);return n instanceof P?F(n):n}function Fg(r,t,e){let n=Xe(r,t,e);return n instanceof P?F(n):n}function Bg(r,t,e){let n=Je(r,t,e);return n instanceof P?F(n):n}function Tg(r,t,e){let n=tn(r,t,e);return n instanceof P?F(n):n}function Og(r,t){let e=en(r,t);return e instanceof P?F(e):e}function Eg(r,t){let e=nn(r,t);return e instanceof P?F(e):e}function Ug(r,t,e,n){let o=nt(r,t,e,n);return o instanceof P?F(o):o}function $g(r,t,e,n){let o=on(r,t,e,n);return o instanceof P?F(o):o}function kg(r,t,e){let n=an(r,t,e);return n instanceof P?F(n):n}function Rg(r,t,e,n){let o=sn(r,t,e,n);return o instanceof P?F(o):o}function qg(r,t,e,n){let o=un(r,t,e,n);return o instanceof P?F(o):o}function Vg(r,t,e,n){let o=cn(r,t,e,n);return o instanceof P?F(o):o}function Pg(r,t,e){let n=ln(r,t,e);return n instanceof P?F(n):n}function jg(r,t,e){let n=fn(r,t,e);return n instanceof P?F(n):n}function sl(r,t){return F(mn(r,t))}function il(r,t){return F(pn(r,t))}function Lg(r,t,e){let n=yn(r,t,e);return n instanceof P?F(n):n}function Wg(r,t,e){let n=dn(r,t,e);return n instanceof P?F(n):n}function Gg(r,t,e){let n=bn(r,t,e);return n instanceof P?F(n):n}function Yg(r,t,e,n){let o=An(r,t,e,n);return o instanceof P?F(o):o}function Zg(r,t,e,n){let o=gn(r,t,e,n);return o instanceof P?F(o):o}function Xg(r,t,e){let n=hn(r,t,e);return n instanceof P?F(n):n}function Jg(r,t,e){let n=Nn(r,t,e);return n instanceof P?F(n):n}function Kg(r,t){let e=Dn(r,t);return e instanceof P?F(e):e}function Qg(r,t){let e=xn(r,t);return e instanceof P?F(e):e}function Hg(r,t){return F(Cn(r,t))}function rh(r,t){return F(Sn(r,t))}function th(r,t,e){let n=wn(r,t,e);return n instanceof P?F(n):n}function eh(r,t,e,n){let o=In(r,t,e,n);return o instanceof P?F(o):o}function nh(r,t,e,n){let o=zn(r,t,e,n);return o instanceof P?F(o):o}function ul(r,t=0){return F(Bt(r,t))}function oh(r){return F(uo(r))}function ah(r){return F(co(r))}function sh(r){return F(lo(r))}function ih(r){return F(fo(r))}function uh(r){return F(mo(r))}function ch(r,t){return F(Vu(r,t))}function lh(r,t){return F(Pu(r,t))}function fh(r,t){return F(ju(r,t))}function mh(r,t){return F(Lu(r,t))}function ph(r,t){return F(Wu(r,t))}function yh(r,t){return F(Gu(r,t))}function dh(r,t){return F(Yu(r,t))}function bh(r){return F(Zu(r))}function Ah(r,t,e){return F(Fc(r,t,e))}function cl(r,t,e){return F(Cs(r,t,e))}function gh(r,t,e,n){return F(Bc(r,t,e,n))}function hh(r,t,e="constant",n=0){return F(Tc(r,t,e,n))}function Nh(r,t){return F(Ue(r,t))}function Dh(r){return F(Br(r))}function xh(r){return F($e(r))}function Ch(r,t){return F(ke(r,t))}function Sh(r,t){return F(Re(r,t))}function wh(r,t,e){return F(qe(r,t,e))}function Ih(r,t,e){return F(Ve(r,t,e))}function zh(r,t,e=0){return F(Qi(r,t,e))}function ll(r,t=0){return F(St(r,t))}function _h(r,t=0){return F(Hi(r,t))}function vh(r){return F(aa(r))}function Mh(r){return F(ru(r))}function Fh(r){return F(tu(r))}function Bh(r){return F(eu(r))}function Th(r){return F(nu(r))}function Oh(r,t=0){return ou(r,t).map(F)}function Eh(r,t){return F(au(r,t))}function Uh(r,t,e){return F(Pe(r,t,e))}function $h(r,t){return F(je(r,t))}function kh(r){return F(su(r))}function Rh(r){return F(iu(r))}function qh(r,t=1,e=[0,1]){return F(uu(r,t,e))}function Vh(r,t,e){return F(cu(r,t,e))}function Ph(r,t){return F(Le(r,t))}function jh(r,t=-1){return F(Zn(r,t))}function Lh(r,t=-1){return F(Xn(r,t))}function Wh(r){return F(vu(r))}function Gh(r,t,e=-1){return F(Jn(r,t,e))}function Yh(r,t,e=-1){return F(Kn(r,t,e))}function Zh(r){return F(Mu(r))}function Xh(r){return Qn(r).map(F)}function Jh(r){return F(Hn(r))}function Kh(r){return F(Fu(r))}function Qh(r,t){return F(Bu(r,t))}function Hh(r,t,e){return F(Qu(r,t,e))}function r0(r,t,e){return F(Hu(r,t,e))}function t0(r,t,e){return F(rc(r,t,e))}function e0(r,t,e){return F(tc(r,t,e))}function n0(r,t,e,n,o){return F(ec(r,t,e,n,o))}function o0(r,t,e){return F(nc(r,t,e))}function a0(r,t,e,n){let o=oc(r,t,e,n);return o instanceof P?F(o):o}function s0(r){return F(be(r))}function i0(r){return F(Ae(r))}function u0(r){return F(ge(r))}function fl(r){return F(he(r))}function ml(r){return F(Ne(r))}function pl(r){return F(De(r))}function yl(r,t){return F(xe(r,t))}function c0(r,t){return F(Ce(r,t))}function l0(r){return F(Se(r))}function f0(r){return F(we(r))}function m0(r){return F(Oi(r))}function p0(r){return F(Ei(r))}function y0(r){return F(Ie(r))}function d0(r){return F(ze(r))}function b0(r){return F(_e(r))}function dl(r){return F(ve(r))}function bl(r){return F(Me(r))}function Al(r){return F(Fe(r))}var Tr=624,Os=397,n1=2567483615,gl=2147483648,hl=2147483647,Mr={mt:new Uint32Array(Tr),mti:Tr+1};function g0(r){let t=Mr.mt;t[0]=r>>>0;for(let e=1;e<Tr;e++){let n=t[e-1]^t[e-1]>>>30;t[e]=Math.imul(1812433253,n)+e>>>0}Mr.mti=Tr}function xl(){let r=Mr.mt,t,e=[0,n1];if(Mr.mti>=Tr){let n;for(Mr.mti===Tr+1&&g0(5489),n=0;n<Tr-Os;n++)t=r[n]&gl|r[n+1]&hl,r[n]=r[n+Os]^t>>>1^e[t&1];for(;n<Tr-1;n++)t=r[n]&gl|r[n+1]&hl,r[n]=r[n+(Os-Tr)]^t>>>1^e[t&1];t=r[Tr-1]&gl|r[0]&hl,r[Tr-1]=r[Os-1]^t>>>1^e[t&1],Mr.mti=0}return t=r[Mr.mti++],t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^=t>>>18,t>>>0}function W(){let r=xl()>>>5,t=xl()>>>6;return(r*67108864+t)/9007199254740992}var o1=2468251765,a1=1492356589,s1=1135663077,i1=2337405405,u1=3389127133,c1=1232336661,wl=16,Es=4;function mr(r){return r>>>0}function Nl(r,t){return r=mr(mr(r)^t.val),t.val=mr(Math.imul(t.val,o1)),r=mr(Math.imul(r,t.val)),r=mr(r^r>>>wl),r}function l1(r,t){let e=mr(mr(Math.imul(u1,mr(r)))-mr(Math.imul(c1,mr(t))));return e=mr(e^e>>>wl),e}function f1(r){let t=[0,0,0,0],e=[r>>>0],n={val:s1};for(let o=0;o<Es;o++)o<e.length?t[o]=Nl(e[o],n):t[o]=Nl(0,n);for(let o=0;o<Es;o++)for(let a=0;a<Es;a++)if(o!==a){let u=Nl(t[o],n);t[a]=l1(t[a],u)}return t}function m1(r,t){let e=[],n=i1;for(let o=0;o<t;o++){let a=r[o%Es],u=mr(a^n);n=mr(Math.imul(n,a1)),u=mr(Math.imul(u,n)),u=mr(u^u>>>wl),e.push(u)}return e}var p1=BigInt("4865540595714422341"),y1=BigInt("2549297995355413924"),d1=y1<<BigInt(64)|p1,Dl=BigInt("0xffffffffffffffff"),Cl=(BigInt(1)<<BigInt(128))-BigInt(1);function b1(r){let t=r>>BigInt(64),e=r&Dl,n=(t^e)&Dl,o=Number(r>>BigInt(122));return(n>>BigInt(o)|n<<BigInt(64-o))&Dl}function Sl(r,t){return r*d1+t&Cl}function A0(r){let t=f1(r),e=m1(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),i=n<<BigInt(64)|o,s=(a<<BigInt(64)|u)<<BigInt(1);s=(s|BigInt(1))&Cl;let c=BigInt(0);return c=Sl(c,s),c=c+i&Cl,c=Sl(c,s),{state:c,inc:s}}function A1(r){return r.state=Sl(r.state,r.inc),b1(r.state)}function g1(r){let e=A1(r)>>BigInt(11);return Number(e)/9007199254740992}var zo=class{constructor(t){if(t!==void 0)this._pcgState=A0(t);else{let e=Math.floor(Math.random()*4294967296);this._pcgState=A0(e)}}_randomFloat(){return g1(this._pcgState)}random(t){if(t===void 0)return this._randomFloat();let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.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=S.zeros(o,"int64"),i=u.data,s=e-t;for(let c=0;c<a;c++)i[c]=BigInt(Math.floor(this._randomFloat()*s)+t);return u}standard_normal(t){if(t===void 0)return Fr(this._randomFloat.bind(this));let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u+=2){let[i,s]=_o(this._randomFloat.bind(this));a[u]=i,u+1<n&&(a[u+1]=s)}return o}normal(t=0,e=1,n){if(n===void 0)return Fr(this._randomFloat.bind(this))*e+t;let o=Array.isArray(n)?n:[n],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s+=2){let[c,l]=_o(this._randomFloat.bind(this));i[s]=c*e+t,s+1<a&&(i[s+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=S.zeros(o,"float64"),i=u.data,s=e-t;for(let c=0;c<a;c++)i[c]=this._randomFloat()*s+t;return u}choice(t,e,n=!0,o){return M0(t,e,n,o,this._randomFloat.bind(this))}permutation(t){return B0(t,this._randomFloat.bind(this))}shuffle(t){O0(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((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=-Math.log(1-this._randomFloat())*t;return a}poisson(t=1,e){if(e===void 0)return ct(t,this._randomFloat.bind(this));let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"int64"),u=a.data;for(let i=0;i<o;i++)u[i]=BigInt(ct(t,this._randomFloat.bind(this)));return a}binomial(t,e,n){if(n===void 0)return vo(t,e,this._randomFloat.bind(this));let o=Array.isArray(n)?n:[n],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"int64"),i=u.data;for(let s=0;s<a;s++)i[s]=BigInt(vo(t,e,this._randomFloat.bind(this)));return u}};function h0(r){return new zo(r)}function N0(r){r==null&&(r=Math.floor(Date.now()^Math.random()*4294967296)),g0(r>>>0)}function D0(){return{mt:Array.from(Mr.mt),mti:Mr.mti}}function x0(r){Mr.mt=new Uint32Array(r.mt),Mr.mti=r.mti}function Fr(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 _o(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 ct(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=Fr(t);return Math.max(0,Math.round(r+Math.sqrt(r)*e))}}function vo(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=Fr(e);return Math.max(0,Math.min(r,Math.round(n+o*a)))}}function Mo(r){if(r===void 0)return W();let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=W();return n}function C0(...r){if(r.length===0)return W();let t=r.reduce((o,a)=>o*a,1),e=S.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o++)n[o]=W();return e}function S0(...r){if(r.length===0)return Fr(W);let t=r.reduce((o,a)=>o*a,1),e=S.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o+=2){let[a,u]=_o(W);n[o]=a,o+1<t&&(n[o+1]=u)}return e}function Il(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),i=S.zeros(a,n),s=i.data;if(O(n)){let c=s;for(let l=0;l<u;l++)c[l]=BigInt(Math.floor(W()*o)+r)}else{let c=s;for(let l=0;l<u;l++)c[l]=Math.floor(W()*o)+r}return i}function w0(r=0,t=1,e){if(e===void 0)return W()*(t-r)+r;let n=Array.isArray(e)?e:[e],o=n.reduce((s,c)=>s*c,1),a=S.zeros(n,"float64"),u=a.data,i=t-r;for(let s=0;s<o;s++)u[s]=W()*i+r;return a}function I0(r=0,t=1,e){if(e===void 0)return Fr(W)*t+r;let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i+=2){let[s,c]=_o(W);u[i]=s*t+r,i+1<o&&(u[i+1]=c*t+r)}return a}function z0(r){if(r===void 0)return Fr(W);let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a+=2){let[u,i]=_o(W);o[a]=u,a+1<e&&(o[a+1]=i)}return n}function zl(r=1,t){if(t===void 0)return-Math.log(1-W())*r;let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.zeros(e,"float64"),a=o.data;for(let u=0;u<n;u++)a[u]=-Math.log(1-W())*r;return o}function _0(r=1,t){if(t===void 0)return ct(r,W);let e=Array.isArray(t)?t:[t],n=e.reduce((u,i)=>u*i,1),o=S.zeros(e,"int64"),a=o.data;for(let u=0;u<n;u++)a[u]=BigInt(ct(r,W));return o}function v0(r,t,e){if(e===void 0)return vo(r,t,W);let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"int64"),u=a.data;for(let i=0;i<o;i++)u[i]=BigInt(vo(r,t,W));return a}function M0(r,t,e=!0,n,o=W){let a;if(typeof r=="number")a=Array.from({length:r},(m,p)=>p);else{let m=r.size;a=[];for(let p=0;p<m;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 i;if(n!==void 0){if(Array.isArray(n))i=n;else{let p=n.size;i=[];for(let y=0;y<p;y++)i.push(Number(n.iget(y)))}if(i.length!==u)throw new Error("p and a must have the same size");let m=i.reduce((p,y)=>p+y,0);Math.abs(m-1)>1e-10&&(i=i.map(p=>p/m))}if(t===void 0){if(i){let m=o(),p=0;for(let y=0;y<u;y++)if(p+=i[y],m<p)return a[y];return a[u-1]}return a[Math.floor(o()*u)]}let s=Array.isArray(t)?t:[t],c=s.reduce((m,p)=>m*p,1);if(!e&&c>u)throw new Error("cannot take a larger sample than population when replace=false");let l=S.zeros(s,"float64"),f=l.data;if(e)if(i){let m=new Array(u);m[0]=i[0];for(let p=1;p<u;p++)m[p]=m[p-1]+i[p];for(let p=0;p<c;p++){let y=o(),d=0;for(;d<u-1&&y>=m[d];)d++;f[p]=a[d]}}else for(let m=0;m<c;m++)f[m]=a[Math.floor(o()*u)];else{let m=[...a],p=i?[...i]:void 0;for(let y=0;y<c;y++){let d;if(p){let b=p.reduce((h,N)=>h+N,0),A=o()*b,g=0;d=0;for(let h=0;h<m.length;h++)if(g+=p[h],A<g){d=h;break}d===0&&A>=g&&(d=m.length-1)}else d=Math.floor(o()*m.length);f[y]=m[d],m.splice(d,1),p&&p.splice(d,1)}}return l}function F0(r,t,e=!0,n){return M0(r,t,e,n,W)}function B0(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=S.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 T0(r){return B0(r,W)}function O0(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 E0(r){O0(r,W)}function U0(r){return Mo(r)}function $0(r){return Mo(r)}function k0(r){return Mo(r)}function R0(r,t,e){return t===void 0&&(t=r,r=1),Il(r,t+1,e)}function q0(r){let t=new Uint8Array(r);for(let e=0;e<r;e++)t[e]=xl()&255;return t}var V0={name:"MT19937",state:Mr};function P0(){return V0}function j0(r){V0=r}function L0(r){return zl(1,r)}function W0(r,t){if(r<=0)throw new Error("shape must be positive");return Us(r,1,t)}function G0(r){if(r===void 0)return Math.tan(Math.PI*(W()-.5));let t=Array.isArray(r)?r:[r],e=t.reduce((a,u)=>a*u,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=Math.tan(Math.PI*(W()-.5));return n}function Y0(r,t){if(r<=0)throw new Error("df must be positive");let e=i=>{let s=Fr(i),c=pr(r/2,2,i);return s/Math.sqrt(c/r)};if(t===void 0)return e(W);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(W);return a}function pr(r,t,e){if(r<1){let a=e();return pr(1+r,t,e)*Math.pow(a,1/r)}let n=r-1/3,o=1/Math.sqrt(9*n);for(;;){let a,u;do a=Fr(e),u=1+o*a;while(u<=0);u=u*u*u;let i=e(),s=a*a;if(i<1-.0331*s*s||Math.log(i)<.5*s+n*(1-u+Math.log(u)))return n*u*t}}function Us(r,t=1,e){if(r<=0)throw new Error("shape must be positive");if(t<=0)throw new Error("scale must be positive");if(e===void 0)return pr(r,t,W);let n=Array.isArray(e)?e:[e],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=pr(r,t,W);return a}function Z0(r,t,e){if(r<=0||t<=0)throw new Error("a and b must be positive");let n=s=>{let c=pr(r,1,s),l=pr(t,1,s);return c/(c+l)};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function X0(r=0,t=1,e){if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=s()-.5;return r-t*Math.sign(c)*Math.log(1-2*Math.abs(c))};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function J0(r=0,t=1,e){if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=s();return r+t*Math.log(c/(1-c))};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function K0(r=0,t=1,e){if(t<=0)throw new Error("sigma must be positive");let n=s=>Math.exp(r+t*Fr(s));if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function Q0(r=0,t=1,e){if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=s();return r-t*Math.log(-Math.log(c))};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function H0(r,t){if(r<=0)throw new Error("a must be positive");let e=i=>{let s=i();return Math.pow(1-s,-1/r)-1};if(t===void 0)return e(W);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(W);return a}function rN(r,t){if(r<=0)throw new Error("a must be positive");let e=i=>{let s=i();return Math.pow(s,1/r)};if(t===void 0)return e(W);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(W);return a}function tN(r=1,t){if(r<=0)throw new Error("scale must be positive");let e=i=>{let s=i();return r*Math.sqrt(-2*Math.log(s))};if(t===void 0)return e(W);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(W);return a}function eN(r,t,e,n){if(r>t||t>e||r===e)throw new Error("must have left <= mode <= right and left < right");let o=c=>{let l=c(),f=(t-r)/(e-r);return l<f?r+Math.sqrt(l*(e-r)*(t-r)):e-Math.sqrt((1-l)*(e-r)*(e-t))};if(n===void 0)return o(W);let a=Array.isArray(n)?n:[n],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"float64"),s=i.data;for(let c=0;c<u;c++)s[c]=o(W);return i}function nN(r,t,e){if(r<=0)throw new Error("mean must be positive");if(t<=0)throw new Error("scale must be positive");let n=s=>{let c=Fr(s),l=c*c,f=r/(2*t),m=r+f*(r*l-Math.sqrt(4*r*t*l+r*r*l*l));return s()<=r/(r+m)?m:r*r/m};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function oN(r,t){if(r<=0)throw new Error("a must be positive");let e=i=>{let s=i();return Math.pow(-Math.log(1-s),1/r)};if(t===void 0)return e(W);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"float64"),u=a.data;for(let i=0;i<o;i++)u[i]=e(W);return a}function aN(r,t){if(r<=0)throw new Error("df must be positive");return Us(r/2,2,t)}function sN(r,t,e){if(r<=0)throw new Error("df must be positive");if(t<0)throw new Error("nonc must be non-negative");let n=s=>{if(t===0)return pr(r/2,2,s);let c=ct(t/2,s);return pr(r/2+c,2,s)};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function iN(r,t,e){if(r<=0)throw new Error("dfnum must be positive");if(t<=0)throw new Error("dfden must be positive");let n=s=>{let c=pr(r/2,2,s),l=pr(t/2,2,s);return c/r/(l/t)};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function uN(r,t,e,n){if(r<=0)throw new Error("dfnum must be positive");if(t<=0)throw new Error("dfden must be positive");if(e<0)throw new Error("nonc must be non-negative");let o=c=>{let l=pr(e===0?r/2:r/2+ct(e/2,c),2,c),f=pr(t/2,2,c);return l/r/(f/t)};if(n===void 0)return o(W);let a=Array.isArray(n)?n:[n],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"float64"),s=i.data;for(let c=0;c<u;c++)s[c]=o(W);return i}function cN(r,t){if(r<=0||r>1)throw new Error("p must be in (0, 1]");let e=i=>{if(r===1)return 1;let s=i();return Math.floor(Math.log(s)/Math.log(1-r))+1};if(t===void 0)return e(W);let n=Array.isArray(t)?t:[t],o=n.reduce((i,s)=>i*s,1),a=S.zeros(n,"int64"),u=a.data;for(let i=0;i<o;i++)u[i]=BigInt(e(W));return a}function lN(r,t,e,n){if(r<0)throw new Error("ngood must be non-negative");if(t<0)throw new Error("nbad must be non-negative");if(e<0)throw new Error("nsample must be non-negative");if(e>r+t)throw new Error("nsample must be <= ngood + nbad");let o=c=>{let l=r,f=t,m=0,p=e;for(;p>0;){let y=l+f;if(y===0)break;c()<l/y?(m++,l--):f--,p--}return m};if(n===void 0)return o(W);let a=Array.isArray(n)?n:[n],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"int64"),s=i.data;for(let c=0;c<u;c++)s[c]=BigInt(o(W));return i}function fN(r,t){if(r<=0||r>=1)throw new Error("p must be in (0, 1)");let e=Math.log(1-r),n=s=>{let c=s(),l=s(),f=1-Math.exp(e*c);if(l>=f||l===0)return 1;let m=Math.log(l),p=Math.log(f);return m>=p?1:m>=2*p?2:Math.floor(1+m/p)};if(t===void 0)return n(W);let o=Array.isArray(t)?t:[t],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"int64"),i=u.data;for(let s=0;s<a;s++)i[s]=BigInt(n(W));return u}function mN(r,t,e){if(r<=0)throw new Error("n must be positive");if(t<=0||t>1)throw new Error("p must be in (0, 1]");let n=s=>{if(t===1)return 0;let c=pr(r,(1-t)/t,s);return ct(c,s)};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"int64"),i=u.data;for(let s=0;s<a;s++)i[s]=BigInt(n(W));return u}function pN(r,t){if(r<=1)throw new Error("a must be > 1");let e=r-1,n=Math.pow(2,e),o=c=>{for(;;){let l=1-c(),f=c(),m=Math.floor(Math.pow(l,-1/e)),p=Math.pow(1+1/m,e);if(f*m*(p-1)/(n-1)<=p/n)return m}};if(t===void 0)return o(W);let a=Array.isArray(t)?t:[t],u=a.reduce((c,l)=>c*l,1),i=S.zeros(a,"int64"),s=i.data;for(let c=0;c<u;c++)s[c]=BigInt(o(W));return i}function yN(r,t,e){let n=Array.isArray(t)?t:Array.from({length:t.size},(p,y)=>Number(t.iget(y))),o=n.length;if(o===0)throw new Error("pvals must have at least one element");let a=n.reduce((p,y)=>p+y,0),u=n.map(p=>p/a),i=p=>{let y=new Array(o).fill(0),d=r,b=1;for(let A=0;A<o-1&&d>0;A++){let g=u[A]/b,h=vo(d,Math.min(1,Math.max(0,g)),p);y[A]=h,d-=h,b-=u[A]}return y[o-1]=d,y};if(e===void 0){let p=i(W),y=S.zeros([o],"int64"),d=y.data;for(let b=0;b<o;b++)d[b]=BigInt(p[b]);return y}let s=Array.isArray(e)?e:[e],c=s.reduce((p,y)=>p*y,1),l=[...s,o],f=S.zeros(l,"int64"),m=f.data;for(let p=0;p<c;p++){let y=i(W);for(let d=0;d<o;d++)m[p*o+d]=BigInt(y[d])}return f}function dN(r,t,e,n="warn",o=1e-8){let a=Array.isArray(r)?r:Array.from({length:r.size},(d,b)=>Number(r.iget(b))),u=a.length,i;if(Array.isArray(t))i=t;else{i=[];for(let d=0;d<u;d++){i.push([]);for(let b=0;b<u;b++)i[d].push(Number(t.iget(d*u+b)))}}let s=Array(u).fill(0).map(()=>Array(u).fill(0));for(let d=0;d<u;d++)for(let b=0;b<=d;b++){let A=i[d][b];for(let g=0;g<b;g++)A-=s[d][g]*s[b][g];if(d===b){if(A<-o){if(n==="raise")throw new Error("covariance matrix is not positive semi-definite");n==="warn"&&console.warn("covariance matrix is not positive semi-definite"),A=0}s[d][b]=Math.sqrt(Math.max(0,A))}else s[d][b]=s[b][b]!==0?A/s[b][b]:0}let c=d=>{let b=[];for(let g=0;g<u;g++)b.push(Fr(d));let A=[];for(let g=0;g<u;g++){let h=a[g];for(let N=0;N<=g;N++)h+=s[g][N]*b[N];A.push(h)}return A};if(e===void 0){let d=c(W),b=S.zeros([u],"float64"),A=b.data;for(let g=0;g<u;g++)A[g]=d[g];return b}let l=Array.isArray(e)?e:[e],f=l.reduce((d,b)=>d*b,1),m=[...l,u],p=S.zeros(m,"float64"),y=p.data;for(let d=0;d<f;d++){let b=c(W);for(let A=0;A<u;A++)y[d*u+A]=b[A]}return p}function bN(r,t){let e=Array.isArray(r)?r:Array.from({length:r.size},(l,f)=>Number(r.iget(f))),n=e.length;if(n<2)throw new Error("alpha must have at least 2 elements");for(let l of e)if(l<=0)throw new Error("all alpha values must be positive");let o=l=>{let f=[],m=0;for(let p=0;p<n;p++){let y=pr(e[p],1,l);f.push(y),m+=y}return f.map(p=>p/m)};if(t===void 0){let l=o(W),f=S.zeros([n],"float64"),m=f.data;for(let p=0;p<n;p++)m[p]=l[p];return f}let a=Array.isArray(t)?t:[t],u=a.reduce((l,f)=>l*f,1),i=[...a,n],s=S.zeros(i,"float64"),c=s.data;for(let l=0;l<u;l++){let f=o(W);for(let m=0;m<n;m++)c[l*n+m]=f[m]}return s}function AN(r,t,e){if(t<0)throw new Error("kappa must be non-negative");let n=s=>{if(t===0)return 2*Math.PI*s()-Math.PI;let c=1+Math.sqrt(1+4*t*t),l=(c-Math.sqrt(2*c))/(2*t),f=(1+l*l)/(2*l);for(;;){let m=s(),p=Math.cos(Math.PI*m),y=(1+f*p)/(f+p),d=t*(f-y),b=s();if(d*(2-d)>b||Math.log(d/b)+1-d>=0)return((s()>.5?Math.acos(y):-Math.acos(y))+r+Math.PI)%(2*Math.PI)-Math.PI}};if(e===void 0)return n(W);let o=Array.isArray(e)?e:[e],a=o.reduce((s,c)=>s*c,1),u=S.zeros(o,"float64"),i=u.data;for(let s=0;s<a;s++)i[s]=n(W);return u}function N1(r,t,e){let n=r.length;n!==0&&n!==1&&((n&n-1)===0?$s(r,t,e):x1(r,t,e))}var Fo=new Map;function D1(r,t){let e=`${r}_${t}`,n=Fo.get(e);if(n)return n;let o=new Float64Array(r/2),a=new Float64Array(r/2),u=t?1:-1;for(let i=0;i<r/2;i++){let s=u*2*Math.PI*i/r;o[i]=Math.cos(s),a[i]=Math.sin(s)}if(n={cos:o,sin:a},Fo.set(e,n),Fo.size>100){let i=Fo.keys().next().value;Fo.delete(i)}return n}function $s(r,t,e){let n=r.length,o=0;for(let i=0;i<n-1;i++){if(i<o){let c=r[i];r[i]=r[o],r[o]=c,c=t[i],t[i]=t[o],t[o]=c}let s=n>>1;for(;s<=o;)o-=s,s>>=1;o+=s}let{cos:a,sin:u}=D1(n,e);for(let i=2;i<=n;i*=2){let s=i>>1,c=n/i;for(let l=0;l<n;l+=i)for(let f=0,m=0;f<s;f++,m+=c){let p=a[m],y=u[m],d=l+f,b=l+f+s,A=r[d],g=t[d],h=r[b],N=t[b],D=p*h-y*N,x=p*N+y*h;r[d]=A+D,t[d]=g+x,r[b]=A-D,t[b]=g-x}}if(e){let i=1/n;for(let s=0;s<n;s++)r[s]=r[s]*i,t[s]=t[s]*i}}function x1(r,t,e){let n=r.length,o=1;for(;o<2*n-1;)o*=2;let a=e?1:-1,u=new Float64Array(n),i=new Float64Array(n);for(let m=0;m<n;m++){let p=a*Math.PI*m*m/n;u[m]=Math.cos(p),i[m]=Math.sin(p)}let s=new Float64Array(o),c=new Float64Array(o);for(let m=0;m<n;m++){let p=u[m],y=i[m];s[m]=r[m]*p-t[m]*y,c[m]=t[m]*p+r[m]*y}let l=new Float64Array(o),f=new Float64Array(o);l[0]=u[0],f[0]=-i[0];for(let m=1;m<n;m++)l[m]=u[m],f[m]=-i[m],l[o-m]=u[m],f[o-m]=-i[m];$s(s,c,!1),$s(l,f,!1);for(let m=0;m<o;m++){let p=s[m],y=c[m],d=l[m],b=f[m];s[m]=p*d-y*b,c[m]=p*b+y*d}$s(s,c,!0);for(let m=0;m<n;m++){let p=s[m],y=c[m],d=u[m],b=i[m];r[m]=p*d-y*b,t[m]=y*d+p*b}if(e)for(let m=0;m<n;m++)r[m]=r[m]/n,t[m]=t[m]/n}function $t(r,t,e=-1,n="backward"){return kt(r,t!==void 0?[t]:void 0,[e],n,!1)}function Bo(r,t,e=-1,n="backward"){return kt(r,t!==void 0?[t]:void 0,[e],n,!0)}function gN(r,t,e=[-2,-1],n="backward"){return kt(r,t,e,n,!1)}function hN(r,t,e=[-2,-1],n="backward"){return kt(r,t,e,n,!0)}function NN(r,t,e,n="backward"){return kt(r,t,e,n,!1)}function DN(r,t,e,n="backward"){return kt(r,t,e,n,!0)}function kt(r,t,e,n="backward",o=!1){let a=Array.from(r.shape),u=a.length;if(r.size===0)return S.zeros(a,"complex128");if(u===0){let l=S.zeros([1],"complex128"),f=r.iget(0),m=f instanceof U?f.re:Number(f),p=f instanceof U?f.im:0,y=l.data;return y[0]=m,y[1]=p,S.fromData(l.data,[],"complex128")}let i;if(e===void 0)if(t===void 0)i=Array.from({length:u},(l,f)=>f);else{i=[];for(let l=0;l<t.length;l++)i.push(u-t.length+l)}else i=e.map(l=>l<0?u+l:l);let s=[...a];if(t!==void 0)for(let l=0;l<t.length;l++){let f=i[l];s[f]=t[l]}let c=To(r);t!==void 0&&(c=C1(c,s,i));for(let l of i)c=w1(c,l,o,n);return c}function To(r){let t=r.dtype,e=Array.from(r.shape),n=r.size;if(t==="complex128"||t==="complex64"){let i=S.zeros(e,"complex128"),s=i.data,c=r.data;for(let l=0;l<n*2;l++)s[l]=c[l];return i}let o=S.zeros(e,"complex128"),a=o.data,u=r.data;if(t==="float64"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="float32"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int32"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int16"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int8"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="uint32"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="uint16"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="uint8"){let i=u;for(let s=0;s<n;s++)a[s*2]=i[s]}else if(t==="int64"||t==="uint64"){let i=u;for(let s=0;s<n;s++)a[s*2]=Number(i[s])}else for(let i=0;i<n;i++)a[i*2]=Number(u[i]);return o}function C1(r,t,e){let n=Array.from(r.shape),o=r;for(let a of e){let u=n[a],i=t[a];u!==i&&(i>u?o=S1(o,a,i):o=_l(o,a,i),n[a]=i)}return o}function S1(r,t,e){let n=Array.from(r.shape),o=n[t];n[t]=e;let a=S.zeros(n,"complex128"),u=a.data,i=r.data,s=n.slice(0,t).reduce((l,f)=>l*f,1),c=n.slice(t+1).reduce((l,f)=>l*f,1);for(let l=0;l<s;l++)for(let f=0;f<o;f++)for(let m=0;m<c;m++){let p=(l*o+f)*c+m,y=(l*e+f)*c+m;u[y*2]=i[p*2],u[y*2+1]=i[p*2+1]}return a}function _l(r,t,e){let n=Array.from(r.shape),o=n[t];n[t]=e;let a=S.zeros(n,"complex128"),u=a.data,i=r.data,s=n.slice(0,t).reduce((l,f)=>l*f,1),c=n.slice(t+1).reduce((l,f)=>l*f,1);for(let l=0;l<s;l++)for(let f=0;f<e;f++)for(let m=0;m<c;m++){let p=(l*o+f)*c+m,y=(l*e+f)*c+m;u[y*2]=i[p*2],u[y*2+1]=i[p*2+1]}return a}function w1(r,t,e,n){let o=Array.from(r.shape),a=o[t];if(a===0)return r;let u=S.zeros(o,"complex128"),i=u.data,s=r.data,c=o.slice(0,t).reduce((p,y)=>p*y,1),l=o.slice(t+1).reduce((p,y)=>p*y,1),f=new Float64Array(a),m=new Float64Array(a);for(let p=0;p<c;p++)for(let y=0;y<l;y++){for(let d=0;d<a;d++){let b=(p*a+d)*l+y;f[d]=s[b*2],m[d]=s[b*2+1]}if(N1(f,m,e),n==="ortho"){let d=1/Math.sqrt(a);if(e){let b=Math.sqrt(a);for(let A=0;A<a;A++)f[A]=f[A]*b,m[A]=m[A]*b}else for(let b=0;b<a;b++)f[b]=f[b]*d,m[b]=m[b]*d}else if(n==="forward"&&!e){let d=1/a;for(let b=0;b<a;b++)f[b]=f[b]*d,m[b]=m[b]*d}else if(!(n==="backward"&&e)){if(n==="forward"&&e)for(let d=0;d<a;d++)f[d]=f[d]*a,m[d]=m[d]*a}for(let d=0;d<a;d++){let b=(p*a+d)*l+y;i[b*2]=f[d],i[b*2+1]=m[d]}}return u}function Rs(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=t??o[u],s=$t(r,i,e,n),c=Math.floor(i/2)+1;return _l(s,u,c)}function Oo(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=o[u],s=t??(i-1)*2,c=[...o];c[u]=s;let l=S.zeros(c,"complex128"),f=l.data,m=To(r).data,p=o.slice(0,u).reduce((b,A)=>b*A,1),y=o.slice(u+1).reduce((b,A)=>b*A,1);for(let b=0;b<p;b++)for(let A=0;A<y;A++){for(let g=0;g<i;g++){let h=(b*i+g)*y+A,N=(b*s+g)*y+A;f[N*2]=m[h*2],f[N*2+1]=m[h*2+1]}for(let g=i;g<s;g++){let h=s-g,N=(b*i+h)*y+A,D=(b*s+g)*y+A;f[D*2]=m[N*2],f[D*2+1]=-m[N*2+1]}}let d=Bo(l,s,e,n);return ks(d)}function xN(r,t,e=[-2,-1],n="backward"){let a=Array.from(r.shape).length,u=e[0]<0?a+e[0]:e[0],i=e[1]<0?a+e[1]:e[1],s=$t(r,t?t[0]:void 0,u,n),c=Array.from(s.shape),l=t?t[1]:c[i];s=$t(s,l,i,n);let f=Math.floor(l/2)+1;return _l(s,i,f)}function CN(r,t,e=[-2,-1],n="backward"){let o=Array.from(r.shape),a=o.length,u=e[0]<0?a+e[0]:e[0],i=e[1]<0?a+e[1]:e[1],s=o[i],c=t?t[1]:(s-1)*2,l=t?t[0]:o[u],f=Oo(r,c,i,n);return f=Bo(f,l,u,n),ks(f)}function SN(r,t,e,n="backward"){let a=Array.from(r.shape).length,u;if(e===void 0?u=Array.from({length:a},(l,f)=>f):u=e.map(l=>l<0?a+l:l),u.length===0)return To(r);let i=r;for(let l=0;l<u.length-1;l++){let f=u[l],m=t?t[l]:void 0;i=$t(i,m,f,n)}let s=u[u.length-1],c=t?t[u.length-1]:void 0;return Rs(i,c,s,n)}function wN(r,t,e,n="backward"){let o=Array.from(r.shape),a=o.length,u;if(e===void 0?u=Array.from({length:a},(f,m)=>m):u=e.map(f=>f<0?a+f:f),u.length===0)return ks(To(r));let i=u[u.length-1],s=o[i],c=t?[...t]:u.map((f,m)=>m===u.length-1?(s-1)*2:o[f]),l=Oo(r,c[u.length-1],i,n);for(let f=u.length-2;f>=0;f--){let m=u[f];l=Bo(l,c[f],m,n)}return ks(l)}function IN(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=o[u],s=t??(i-1)*2,c=_N(To(r)),l=Oo(c,s,e,n),f=l.data;for(let m=0;m<l.size;m++)f[m]=f[m]*s;return l}function zN(r,t,e=-1,n="backward"){let o=Array.from(r.shape),a=o.length,u=e<0?a+e:e,i=t??o[u],s=Rs(r,i,e,n),c=_N(s),l=c.data;for(let f=0;f<c.size*2;f++)l[f]=l[f]/i;return c}function _N(r){let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"complex128"),o=n.data,a=r.data;for(let u=0;u<e;u++)o[u*2]=a[u*2],o[u*2+1]=-a[u*2+1];return n}function ks(r){let t=Array.from(r.shape),e=r.size,n=S.zeros(t,"float64"),o=n.data,a=r.data;for(let u=0;u<e;u++)o[u]=a[u*2];return n}function vN(r,t=1){let e=S.zeros([r],"float64"),n=e.data,o=Math.floor((r-1)/2)+1;for(let a=0;a<o;a++)n[a]=a/(r*t);for(let a=o;a<r;a++)n[a]=(a-r)/(r*t);return e}function MN(r,t=1){let e=Math.floor(r/2)+1,n=S.zeros([e],"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=a/(r*t);return n}function FN(r,t){let e=Array.from(r.shape),n=e.length,o;t===void 0?o=Array.from({length:n},(u,i)=>i):typeof t=="number"?o=[t<0?n+t:t]:o=t.map(u=>u<0?n+u:u);let a=e.map((u,i)=>o.includes(i)?Math.floor(e[i]/2):0);return TN(r,a)}function BN(r,t){let e=Array.from(r.shape),n=e.length,o;t===void 0?o=Array.from({length:n},(u,i)=>i):typeof t=="number"?o=[t<0?n+t:t]:o=t.map(u=>u<0?n+u:u);let a=e.map((u,i)=>o.includes(i)?-Math.floor(e[i]/2):0);return TN(r,a)}function TN(r,t){let e=Array.from(r.shape),n=r.dtype,o=r.size,a=S.zeros(e,n),u=n==="complex128"||n==="complex64",i=new Array(e.length);i[e.length-1]=1;for(let s=e.length-2;s>=0;s--)i[s]=i[s+1]*e[s+1];for(let s=0;s<o;s++){let c=new Array(e.length),l=s;for(let p=0;p<e.length;p++)c[p]=Math.floor(l/i[p]),l=l%i[p];let f=c.map((p,y)=>{let d=p+t[y],b=e[y];return d=(d%b+b)%b,d}),m=0;for(let p=0;p<e.length;p++)m+=f[p]*i[p];if(u){let p=r.data,y=a.data;y[m*2]=p[s*2],y[m*2+1]=p[s*2+1]}else{let p=r.iget(s);a.iset(m,p)}}return a}function lt(r){return tr.fromStorage(r.storage)}function z1(r){return lt(it(r))}var _1=Jc;function v1(r,t){return lt(Kc(r,t))}async function M1(r,t={}){let e=await Co(r,t),n=new Map;for(let[o,a]of e.arrays)n.set(o,lt(a));return{arrays:n,skipped:e.skipped,errors:e.errors}}function F1(r,t={}){let e=So(r,t),n=new Map;for(let[o,a]of e.arrays)n.set(o,lt(a));return{arrays:n,skipped:e.skipped,errors:e.errors}}async function B1(r,t={}){let e=await zd(r,t),n={};for(let[o,a]of Object.entries(e))n[o]=lt(a);return n}function T1(r,t={}){let e=_d(r,t),n={};for(let[o,a]of Object.entries(e))n[o]=lt(a);return n}function O1(r,t={}){return lt(ut(r,t))}function H(r){return r&&typeof r=="object"&&"_data"in r&&"_shape"in r?tr.fromStorage(r):r}var E1={seed:N0,get_state:D0,set_state:x0,get_bit_generator:P0,set_bit_generator:j0,default_rng:h0,Generator:zo,random:r=>H(Mo(r)),rand:(...r)=>H(C0(...r)),randn:(...r)=>H(S0(...r)),randint:(r,t,e,n)=>H(Il(r,t,e,n)),random_sample:r=>H(U0(r)),ranf:r=>H($0(r)),sample:r=>H(k0(r)),random_integers:(r,t,e)=>H(R0(r,t,e)),bytes:q0,uniform:(r,t,e)=>H(w0(r,t,e)),normal:(r,t,e)=>H(I0(r,t,e)),standard_normal:r=>H(z0(r)),exponential:(r,t)=>H(zl(r,t)),standard_exponential:r=>H(L0(r)),gamma:(r,t,e)=>H(Us(r,t,e)),standard_gamma:(r,t)=>H(W0(r,t)),beta:(r,t,e)=>H(Z0(r,t,e)),chisquare:(r,t)=>H(aN(r,t)),noncentral_chisquare:(r,t,e)=>H(sN(r,t,e)),f:(r,t,e)=>H(iN(r,t,e)),noncentral_f:(r,t,e,n)=>H(uN(r,t,e,n)),standard_cauchy:r=>H(G0(r)),standard_t:(r,t)=>H(Y0(r,t)),laplace:(r,t,e)=>H(X0(r,t,e)),logistic:(r,t,e)=>H(J0(r,t,e)),lognormal:(r,t,e)=>H(K0(r,t,e)),gumbel:(r,t,e)=>H(Q0(r,t,e)),pareto:(r,t)=>H(H0(r,t)),power:(r,t)=>H(rN(r,t)),rayleigh:(r,t)=>H(tN(r,t)),triangular:(r,t,e,n)=>H(eN(r,t,e,n)),wald:(r,t,e)=>H(nN(r,t,e)),weibull:(r,t)=>H(oN(r,t)),poisson:(r,t)=>H(_0(r,t)),binomial:(r,t,e)=>H(v0(r,t,e)),geometric:(r,t)=>H(cN(r,t)),hypergeometric:(r,t,e,n)=>H(lN(r,t,e,n)),logseries:(r,t)=>H(fN(r,t)),negative_binomial:(r,t,e)=>H(mN(r,t,e)),zipf:(r,t)=>H(pN(r,t)),multinomial:(r,t,e)=>H(yN(r,t,e)),multivariate_normal:(r,t,e,n,o)=>H(dN(r,t,e,n,o)),dirichlet:(r,t)=>H(bN(r,t)),vonmises:(r,t,e)=>H(AN(r,t,e)),choice:(r,t,e,n)=>H(F0(r,t,e,n)),permutation:r=>H(T0(r)),shuffle:E0};function fr(r){return r instanceof tr||r instanceof P?r.storage:r}var U1={fft:(r,t,e,n)=>tr.fromStorage($t(fr(r),t,e,n)),ifft:(r,t,e,n)=>tr.fromStorage(Bo(fr(r),t,e,n)),fft2:(r,t,e,n)=>tr.fromStorage(gN(fr(r),t,e,n)),ifft2:(r,t,e,n)=>tr.fromStorage(hN(fr(r),t,e,n)),fftn:(r,t,e,n)=>tr.fromStorage(NN(fr(r),t,e,n)),ifftn:(r,t,e,n)=>tr.fromStorage(DN(fr(r),t,e,n)),rfft:(r,t,e,n)=>tr.fromStorage(Rs(fr(r),t,e,n)),irfft:(r,t,e,n)=>tr.fromStorage(Oo(fr(r),t,e,n)),rfft2:(r,t,e,n)=>tr.fromStorage(xN(fr(r),t,e,n)),irfft2:(r,t,e,n)=>tr.fromStorage(CN(fr(r),t,e,n)),rfftn:(r,t,e,n)=>tr.fromStorage(SN(fr(r),t,e,n)),irfftn:(r,t,e,n)=>tr.fromStorage(wN(fr(r),t,e,n)),hfft:(r,t,e,n)=>tr.fromStorage(IN(fr(r),t,e,n)),ihfft:(r,t,e,n)=>tr.fromStorage(zN(fr(r),t,e,n)),fftfreq:(r,t)=>tr.fromStorage(vN(r,t)),rfftfreq:(r,t)=>tr.fromStorage(MN(r,t)),fftshift:(r,t)=>tr.fromStorage(FN(fr(r),t)),ifftshift:(r,t)=>tr.fromStorage(BN(fr(r),t))},$1="0.13.1";function Lr(r){return tr.fromStorage(r.storage)}async function ON(r){let t=await(0,jr.readFile)(r);return Lr(it(t))}function EN(r){let t=(0,Pr.readFileSync)(r);return Lr(it(t))}async function UN(r,t){let e=Kr(t);await(0,jr.writeFile)(r,e)}function $N(r,t){let e=Kr(t);(0,Pr.writeFileSync)(r,e)}async function kN(r,t={}){let e=await(0,jr.readFile)(r),n=await Co(e,t),o=new Map;for(let[a,u]of n.arrays)o.set(a,Lr(u));return{arrays:o,skipped:n.skipped,errors:n.errors}}function RN(r,t={}){let e=(0,Pr.readFileSync)(r),n=So(e,t),o=new Map;for(let[a,u]of n.arrays)o.set(a,Lr(u));return{arrays:o,skipped:n.skipped,errors:n.errors}}async function vl(r,t,e={}){let n=await Bs(t,e);await(0,jr.writeFile)(r,n)}function k1(r,t){let e=Ts(t);(0,Pr.writeFileSync)(r,e)}async function R1(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return ON(r)}else{if(r.endsWith(".npz"))return kN(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function q1(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return EN(r)}else{if(r.endsWith(".npz"))return RN(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function V1(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return UN(r,t)}function P1(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return $N(r,t)}async function j1(r,t){return r.endsWith(".npz")||(r=r+".npz"),vl(r,t,{compress:!1})}async function L1(r,t){return r.endsWith(".npz")||(r=r+".npz"),vl(r,t,{compress:!0})}async function W1(r,t={}){let e=await(0,jr.readFile)(r,{encoding:t.encoding??"utf-8"});return Lr(ut(e,t))}function G1(r,t={}){let e=(0,Pr.readFileSync)(r,{encoding:t.encoding??"utf-8"});return Lr(ut(e,t))}async function Y1(r,t,e={}){let n=Ut(t,e);await(0,jr.writeFile)(r,n,"utf-8")}function Z1(r,t,e={}){let n=Ut(t,e);(0,Pr.writeFileSync)(r,n,"utf-8")}async function X1(r,t={}){let e=await(0,jr.readFile)(r,{encoding:t.encoding??"utf-8"});return Lr(wo(e,t))}function J1(r,t={}){let e=(0,Pr.readFileSync)(r,{encoding:t.encoding??"utf-8"});return Lr(wo(e,t))}async function K1(r,t,e="float64"){let n=await(0,jr.readFile)(r,{encoding:"utf-8"});return Lr(Io(n,t,e))}function Q1(r,t,e="float64"){let n=(0,Pr.readFileSync)(r,{encoding:"utf-8"});return Lr(Io(n,t,e))}0&&(module.exports={Complex,DTYPE_TO_DESCR,InvalidNpyError,NDArray,NDArrayCore,SUPPORTED_DTYPES,UnsupportedDTypeError,__version__,abs,absolute,acos,acosh,add,all,allclose,amax,amin,angle,any,append,apply_along_axis,apply_over_axes,arange,arccos,arccosh,arcsin,arcsinh,arctan,arctan2,arctanh,argmax,argmin,argpartition,argsort,argwhere,around,array,array2string,array_equal,array_equiv,array_repr,array_split,array_str,asanyarray,asarray,asarray_chkfinite,ascontiguousarray,asfortranarray,asin,asinh,atan,atan2,atanh,atleast_1d,atleast_2d,atleast_3d,average,base_repr,binary_repr,bincount,bindex,bitwise_and,bitwise_count,bitwise_invert,bitwise_left_shift,bitwise_not,bitwise_or,bitwise_right_shift,bitwise_xor,block,broadcast_arrays,broadcast_shapes,broadcast_to,byteswap,can_cast,cbrt,ceil,choose,clip,column_stack,common_type,compress,concat,concatenate,conj,conjugate,convolve,copy,copysign,copyto,corrcoef,correlate,cos,cosh,count_nonzero,cov,cross,cumprod,cumsum,cumulative_prod,cumulative_sum,deg2rad,degrees,delete:null,delete_,diag,diag_indices,diag_indices_from,diagflat,diagonal,diff,digitize,divide,divmod,dot,dsplit,dstack,ediff1d,einsum,einsum_path,empty,empty_like,equal,exp,exp2,expand_dims,expm1,extract,eye,fabs,fft,fill,fill_diagonal,fix,flatnonzero,flatten,flip,fliplr,flipud,float_power,floor,floor_divide,fmax,fmin,fmod,format_float_positional,format_float_scientific,frexp,frombuffer,fromfile,fromfunction,fromiter,fromregex,fromregexSync,fromstring,full,full_like,gcd,genfromtxt,genfromtxtSync,geomspace,get_printoptions,geterr,gradient,greater,greater_equal,heaviside,histogram,histogram2d,histogram_bin_edges,histogramdd,hsplit,hstack,hypot,i0,identity,iindex,imag,in1d,indices,inner,insert,interp,intersect1d,invert,isclose,iscomplex,iscomplexobj,isdtype,isfinite,isfortran,isin,isinf,isnan,isnat,isneginf,isposinf,isreal,isrealobj,isscalar,issubdtype,item,iterable,ix_,kron,lcm,ldexp,left_shift,less,less_equal,lexsort,linalg,linspace,load,loadNpy,loadNpySync,loadNpz,loadNpzFile,loadNpzFileSync,loadNpzSync,loadSync,loadtxt,loadtxtSync,log,log10,log1p,log2,logaddexp,logaddexp2,logical_and,logical_not,logical_or,logical_xor,logspace,mask_indices,matmul,matrix_transpose,matvec,max,maximum,may_share_memory,mean,median,meshgrid,min,min_scalar_type,minimum,mintypecode,mod,modf,moveaxis,multiply,nan_to_num,nanargmax,nanargmin,nancumprod,nancumsum,nanmax,nanmean,nanmedian,nanmin,nanpercentile,nanprod,nanquantile,nanstd,nansum,nanvar,ndim,negative,nextafter,nonzero,not_equal,ones,ones_like,outer,packbits,pad,parseNpy,parseNpyData,parseNpyHeader,parseNpz,parseNpzSync,parseTxt,partition,percentile,permute_dims,place,poly,polyadd,polyder,polydiv,polyfit,polyint,polymul,polysub,polyval,positive,pow,power,printoptions,prod,promote_types,ptp,put,put_along_axis,putmask,quantile,rad2deg,radians,random,ravel,ravel_multi_index,real,real_if_close,reciprocal,remainder,repeat,require,reshape,resize,result_type,right_shift,rint,roll,rollaxis,roots,rot90,round,round_,row_stack,save,saveNpy,saveNpySync,saveNpz,saveNpzSync,saveSync,savetxt,savetxtSync,savez,savez_compressed,searchsorted,select,serializeNpy,serializeNpz,serializeNpzSync,serializeTxt,set_printoptions,setdiff1d,seterr,setxor1d,shape,shares_memory,sign,signbit,sin,sinc,sinh,size,sort,sort_complex,spacing,split,sqrt,square,squeeze,stack,std,subtract,sum,swapaxes,take,take_along_axis,tan,tanh,tensordot,tile,tobytes,tofile,tolist,trace,transpose,trapezoid,tri,tril,tril_indices,tril_indices_from,trim_zeros,triu,triu_indices,triu_indices_from,true_divide,trunc,typename,union1d,unique,unique_all,unique_counts,unique_inverse,unique_values,unpackbits,unravel_index,unstack,unwrap,vander,var:null,variance,vdot,vecdot,vecmat,view,vsplit,vstack,where,zeros,zeros_like});
|
|
6
8
|
//# sourceMappingURL=numpy-ts.node-io.cjs.map
|