numpy-ts 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- function st(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 it(r,t){let{start:e,stop:n}=r,{step:o,isIndex:a}=r;if(a){if(e===null)throw new Error("Index cannot be null");let i=e<0?t+e:e;if(i<0||i>=t)throw new Error(`Index ${e} is out of bounds for size ${t}`);return{start:i,stop:i+1,step:1,isIndex:!0}}return o>0?(e===null&&(e=0),n===null&&(n=t)):(e===null&&(e=t-1),n===null&&(n=-t-1)),e<0&&(e=t+e),n<0&&(n=t+n),e=Math.max(0,Math.min(e,t)),n=Math.max(-1,Math.min(n,t)),{start:e,stop:n,step:o,isIndex:!1}}var $="float64";function _(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function ct(r){switch(r){case"float64":case"int64":case"uint64":return 8;case"float32":case"int32":case"uint32":return 4;case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${r}`)}}function ut(r){return r==="float64"||r==="float32"}function N(r){return r==="int64"||r==="uint64"}function v(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(ut(r)||ut(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){let c=t;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}if(t==="float32"){let c=r;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}return"float32"}let e=r.startsWith("int"),n=t.startsWith("int"),o=r.startsWith("uint"),a=t.startsWith("uint"),i=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,s=i(r),u=i(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&s===u){if(s===8)return"int16";if(s===16)return"int32";if(s===32)return"int64"}if(o&&n&&s===u){if(u===8)return"int16";if(u===16)return"int32";if(u===32)return"int64"}if(e&&n||o&&a){let c=Math.max(s,u);return e?c===64?"int64":c===32?"int32":c===16?"int16":"int8":c===64?"uint64":c===32?"uint32":c===16?"uint16":"uint8"}return e&&a?s>u?r:u===8?"int16":u===16?"int32":u===32?"int64":"float64":o&&n?u>s?t:s===8?"int16":s===16?"int32":s===32?"int64":"float64":"float64"}var D=class r{constructor(t,e,n,o,a){this._data=t,this._shape=e,this._strides=n,this._offset=o,this._dtype=a}get shape(){return this._shape}get ndim(){return this._shape.length}get size(){return this._shape.reduce((t,e)=>t*e,1)}get dtype(){return this._dtype}get data(){return this._data}get strides(){return this._strides}get offset(){return this._offset}get isCContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=n-1;a>=0;a--){if(e[a]!==o)return!1;o*=t[a]}return!0}get isFContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=0;a<n;a++){if(e[a]!==o)return!1;o*=t[a]}return!0}iget(t){let e=this._shape,n=this._strides,o=e.length;if(o===0)return this._data[this._offset];let a=t,i=this._offset;for(let s=0;s<o;s++){let u=1;for(let l=s+1;l<o;l++)u*=e[l];let c=Math.floor(a/u);a=a%u,i+=c*n[s]}return this._data[i]}iset(t,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let i=t,s=this._offset;for(let u=0;u<a;u++){let c=1;for(let m=u+1;m<a;m++)c*=n[m];let l=Math.floor(i/c);i=i%c,s+=l*o[u]}this._data[s]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];return this._data[n]}set(t,e){let n=this._strides,o=this._offset;for(let a=0;a<t.length;a++)o+=t[a]*n[a];this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=_(e);if(!o)throw new Error(`Cannot copy array with dtype ${e}`);let a=new o(n);if(this.isCContiguous&&this._offset===0)if(N(e)){let i=this._data,s=a;for(let u=0;u<n;u++)s[u]=i[u]}else a.set(this._data);else if(N(e)){let i=a;for(let s=0;s<n;s++)i[s]=this.iget(s)}else for(let i=0;i<n;i++)a[i]=this.iget(i);return new r(a,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let i=o??r._computeStrides(e),s=a??0;return new r(t,e,i,s,n)}static zeros(t,e=$){let n=t.reduce((i,s)=>i*s,1),o=_(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return new r(a,t,r._computeStrides(t),0,e)}static ones(t,e=$){let n=t.reduce((i,s)=>i*s,1),o=_(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return N(e)?a.fill(BigInt(1)):a.fill(1),new r(a,t,r._computeStrides(t),0,e)}static _computeStrides(t){let e=new Array(t.length),n=1;for(let o=t.length-1;o>=0;o--)e[o]=n,n*=t[o];return e}};function F(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 ft(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let i=0;i<o;i++){let s=i<o-e?1:r[i-(o-e)],u=i<o-n?1:t[i-(o-n)];if(s===u)a[i]=s;else if(s===1)a[i]=u;else if(u===1)a[i]=s;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function nn(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let i=0;i<n;i++){let s=o-n+i,u=r[i],c=e[s];if(u===c)a[s]=t[i];else if(u===1)a[s]=0;else throw new Error("Invalid broadcast")}return a}function ur(r,t){let e=nn(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function P(r,t,e,n){let o=ft(r.shape,t.shape),a=ur(r,o),i=ur(t,o),s=v(r.dtype,t.dtype),u=D.zeros(o,s),c=u.data,l=u.size;if(N(s)){let m=c;for(let f=0;f<l;f++){let p=a.iget(f),y=i.iget(f),d=typeof p=="bigint"?p:BigInt(Math.round(p)),g=typeof y=="bigint"?y:BigInt(Math.round(y));n==="add"?m[f]=d+g:n==="subtract"?m[f]=d-g:n==="multiply"?m[f]=d*g:n==="divide"?m[f]=d/g:m[f]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let m=N(r.dtype)||N(t.dtype);for(let f=0;f<l;f++){let p=a.iget(f),y=i.iget(f),d=Number(p),g=Number(y);c[f]=e(d,g)}}return u}function L(r,t,e){let n=ft(r.shape,t.shape),o=ur(r,n),a=ur(t,n),i=n.reduce((c,l)=>c*l,1),s=new Uint8Array(i),u=N(r.dtype)||N(t.dtype);for(let c=0;c<i;c++){let l=o.iget(c),m=a.iget(c),f=Number(l),p=Number(m);s[c]=e(f,p)?1:0}return D.fromData(s,n,"bool")}function M(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,s=e?n:n!=="float32"&&n!=="float64"?"float64":n,u=D.zeros(o,s),c=u.data,l=r.data;if(N(n))if(N(s)){let m=c;for(let f=0;f<a;f++){let p=Number(l[f]);m[f]=BigInt(Math.round(t(p)))}}else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));return u}function zr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function lt(r,t){return typeof t=="number"?un(r,t):zr(r,t)?on(r,t):P(r,t,(e,n)=>e+n,"add")}function on(r,t){let e=v(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,s=n.data;if(N(e)){let u=s;if(!N(r.dtype)||!N(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));u[l]=m+f}else{let l=a,m=i;for(let f=0;f<o;f++)u[f]=l[f]+m[f]}}else if(N(r.dtype)||N(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];s[c]=l+m}else for(let c=0;c<o;c++)s[c]=a[c]+i[c];return n}function pt(r,t){return typeof t=="number"?cn(r,t):zr(r,t)?an(r,t):P(r,t,(e,n)=>e-n,"subtract")}function an(r,t){let e=v(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,s=n.data;if(N(e)){let u=s;if(!N(r.dtype)||!N(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));u[l]=m-f}else{let l=a,m=i;for(let f=0;f<o;f++)u[f]=l[f]-m[f]}}else if(N(r.dtype)||N(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];s[c]=l-m}else for(let c=0;c<o;c++)s[c]=a[c]-i[c];return n}function mt(r,t){return typeof t=="number"?fn(r,t):zr(r,t)?sn(r,t):P(r,t,(e,n)=>e*n,"multiply")}function sn(r,t){let e=v(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,s=n.data;if(N(e)){let u=s;if(!N(r.dtype)||!N(t.dtype))for(let l=0;l<o;l++){let m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));u[l]=m*f}else{let l=a,m=i;for(let f=0;f<o;f++)u[f]=l[f]*m[f]}}else if(N(r.dtype)||N(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];s[c]=l*m}else for(let c=0;c<o;c++)s[c]=a[c]*i[c];return n}function yt(r,t){if(typeof t=="number")return ln(r,t);let e=r.dtype==="float64",n=t.dtype==="float64",o=r.dtype==="float32",a=t.dtype==="float32";if(e||n){let u=e?r:Y(r,"float64"),c=n?t:Y(t,"float64");return P(u,c,(l,m)=>l/m,"divide")}if(o||a){let u=o?r:Y(r,"float32"),c=a?t:Y(t,"float32");return P(u,c,(l,m)=>l/m,"divide")}let i=Y(r,"float64"),s=Y(t,"float64");return P(i,s,(u,c)=>u/c,"divide")}function Y(r,t){let e=D.zeros(Array.from(r.shape),t),n=r.size,o=r.data,a=e.data;for(let i=0;i<n;i++)a[i]=Number(o[i]);return e}function un(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=D.zeros(n,e),s=i.data;if(N(e)){let u=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=u[m]+l}else for(let u=0;u<a;u++)s[u]=Number(o[u])+t;return i}function cn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=D.zeros(n,e),s=i.data;if(N(e)){let u=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=u[m]-l}else for(let u=0;u<a;u++)s[u]=Number(o[u])-t;return i}function fn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=D.zeros(n,e),s=i.data;if(N(e)){let u=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=u[m]*l}else for(let u=0;u<a;u++)s[u]=Number(o[u])*t;return i}function ln(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e!=="float32"&&e!=="float64"?"float64":e,u=D.zeros(n,s),c=u.data;if(N(e))for(let l=0;l<a;l++)c[l]=Number(o[l])/t;else for(let l=0;l<a;l++)c[l]=Number(o[l])/t;return u}function dt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),i=a.data;if(N(t)){let s=n,u=i;for(let c=0;c<o;c++){let l=s[c];u[c]=l<0n?-l:l}}else for(let s=0;s<o;s++)i[s]=Math.abs(Number(n[s]));return a}function gt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),i=a.data;if(N(t)){let s=n,u=i;for(let c=0;c<o;c++)u[c]=-s[c]}else for(let s=0;s<o;s++)i[s]=-Number(n[s]);return a}function ht(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),i=a.data;if(N(t)){let s=n,u=i;for(let c=0;c<o;c++){let l=s[c];u[c]=l>0n?1n:l<0n?-1n:0n}}else for(let s=0;s<o;s++){let u=Number(n[s]);i[s]=u>0?1:u<0?-1:0}return a}function cr(r,t){return typeof t=="number"?pn(r,t):P(r,t,(e,n)=>(e%n+n)%n,"mod")}function pn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=D.zeros(n,e),s=i.data;if(N(e)){let u=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++){let f=u[m];c[m]=(f%l+l)%l}}else for(let u=0;u<a;u++){let c=Number(o[u]);s[u]=(c%t+t)%t}return i}function Br(r,t){return typeof t=="number"?mn(r,t):P(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function mn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=D.zeros(n,e),s=i.data;if(N(e)){let u=o,c=s,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=u[m]/l}else for(let u=0;u<a;u++)s[u]=Math.floor(Number(o[u])/t);return i}function At(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),i=a.data;for(let s=0;s<o;s++)i[s]=n[s];return a}function bt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,i=t!=="float32"&&t!=="float64"?"float64":t,s=D.zeros(e,i),u=s.data;if(N(t))for(let c=0;c<o;c++)u[c]=1/Number(n[c]);else for(let c=0;c<o;c++)u[c]=1/Number(n[c]);return s}function St(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,i=t!=="float32"&&t!=="float64"?"float64":t,s=D.zeros(e,i),u=s.data;for(let c=0;c<o;c++)u[c]=Math.cbrt(Number(n[c]));return s}function Dt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=D.zeros(e,a),s=i.data;for(let u=0;u<o;u++)s[u]=Math.abs(Number(n[u]));return i}function Nt(r,t){let e=Br(r,t),n=cr(r,t);return[e,n]}function wt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),i=a.data;if(N(t)){let s=n,u=i;for(let c=0;c<o;c++)u[c]=s[c]*s[c]}else for(let s=0;s<o;s++){let u=Number(n[s]);i[s]=u*u}return a}function xt(r,t){return cr(r,t)}function It(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=D.zeros(n,a),s=i.data;if(typeof t=="number")for(let u=0;u<o;u++){let c=Number(r.data[u]);c<0?s[u]=0:c===0?s[u]=t:s[u]=1}else{let u=t.data,c=t.shape;if(n.every((l,m)=>l===c[m]))for(let l=0;l<o;l++){let m=Number(r.data[l]);m<0?s[l]=0:m===0?s[l]=Number(u[l]):s[l]=1}else for(let l=0;l<o;l++){let m=Number(r.data[l]),f=l%t.size;m<0?s[l]=0:m===0?s[l]=Number(u[f]):s[l]=1}}return i}function Z(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);let t=Math.max(...r.map(n=>n.length)),e=new Array(t);for(let n=0;n<t;n++){let o=1;for(let a of r){let i=a.length-t+n,s=i<0?1:a[i];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[n]=o}return e}function dn(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let i=0;i<n;i++){let s=o-n+i,u=r[i],c=e[s];if(u===c)a[s]=t[i];else if(u===1)a[s]=0;else throw new Error("Invalid broadcast")}return a}function j(r,t){let e=dn(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function _r(...r){let t=Z(r);if(t===null){let e=r.map(n=>`(${n.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return t}function zt(r,t){return typeof t=="number"?gn(r,t):L(r,t,(e,n)=>e>n)}function Bt(r,t){return typeof t=="number"?hn(r,t):L(r,t,(e,n)=>e>=n)}function _t(r,t){return typeof t=="number"?An(r,t):L(r,t,(e,n)=>e<n)}function Et(r,t){return typeof t=="number"?bn(r,t):L(r,t,(e,n)=>e<=n)}function Ut(r,t){return typeof t=="number"?Sn(r,t):L(r,t,(e,n)=>e===n)}function Tt(r,t){return typeof t=="number"?Dn(r,t):L(r,t,(e,n)=>e!==n)}function Er(r,t,e=1e-5,n=1e-8){return typeof t=="number"?Nn(r,t,e,n):L(r,t,(o,a)=>{let i=Math.abs(o-a),s=n+e*Math.abs(a);return i<=s})}function Ot(r,t,e=1e-5,n=1e-8){let o=Er(r,t,e,n),a=o.data;for(let i=0;i<o.size;i++)if(a[i]===0)return!1;return!0}function $t(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=Z(e);if(n===null)return!1;let o=j(r,n),a=j(t,n),i=n.length,s=n.reduce((l,m)=>l*m,1),u=N(o.dtype),c=N(a.dtype);for(let l=0;l<s;l++){let m=l,f=new Array(i);for(let d=i-1;d>=0;d--)f[d]=m%n[d],m=Math.floor(m/n[d]);let p=o.get(...f),y=a.get(...f);if(u||c){let d=typeof p=="bigint"?p:BigInt(Number(p)),g=typeof y=="bigint"?y:BigInt(Number(y));if(d!==g)return!1}else if(p!==y)return!1}return!0}function gn(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]>t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function hn(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]>=t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function An(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]<t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function bn(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]<=t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function Sn(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(N(o)){let a=BigInt(Math.round(t)),i=n;for(let s=0;s<r.size;s++)e[s]=i[s]===a?1:0}else for(let a=0;a<r.size;a++)e[a]=n[a]===t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function Dn(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]!==t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function Nn(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,i=r.dtype;if(N(i)){let s=a;for(let u=0;u<r.size;u++){let c=Number(s[u]),l=Math.abs(c-t),m=n+e*Math.abs(t);o[u]=l<=m?1:0}}else for(let s=0;s<r.size;s++){let u=Number(a[s]),c=Math.abs(u-t),l=n+e*Math.abs(t);o[s]=c<=l?1:0}return D.fromData(o,Array.from(r.shape),"bool")}function U(r,t){let e=0,n=1;for(let o=r.length-1;o>=0;o--)e+=r[o]*n,n*=t[o];return e}function T(r,t,e,n){let o=n.length,a=new Array(o),i=Array.from(n).filter((u,c)=>c!==t),s=r;for(let u=i.length-1;u>=0;u--)a[u>=t?u+1:u]=s%i[u],s=Math.floor(s/i[u]);return a[t]=e,a}function X(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,s=r.data;if(t===void 0)if(N(n)){let y=s,d=BigInt(0);for(let g=0;g<i;g++)d+=y[g];return Number(d)}else{let y=0;for(let d=0;d<i;d++)y+=Number(s[d]);return y}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==u);if(c.length===0)return X(r);let l=D.zeros(c,n),m=l.data,f=o[u],p=c.reduce((y,d)=>y*d,1);if(N(n)){let y=s,d=m;for(let g=0;g<p;g++){let A=BigInt(0);for(let h=0;h<f;h++){let b=T(g,u,h,o),S=U(b,o);A+=y[S]}d[g]=A}}else for(let y=0;y<p;y++){let d=0;for(let g=0;g<f;g++){let A=T(y,u,g,o),h=U(A,o);d+=Number(s[h])}m[y]=d}if(e){let y=[...o];return y[u]=1,D.fromData(m,y,n)}return l}function fr(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return X(r)/r.size;let a=t;if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error(`axis ${t} is out of bounds for array of dimension ${o.length}`);let i=X(r,t,e);if(typeof i=="number")return i/o[a];let s=o[a],u=n;(N(n)||n.startsWith("int")||n.startsWith("uint"))&&(u="float64");let c=D.zeros(Array.from(i.shape),u),l=c.data,m=i.data;if(N(n)){let f=m;for(let p=0;p<l.length;p++)l[p]=Number(f[p])/s}else for(let f=0;f<l.length;f++)l[f]=Number(m[f])/s;return c}function lr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,s=r.data;if(t===void 0){if(i===0)throw new Error("max of empty array");let y=s[0];for(let d=1;d<i;d++)s[d]>y&&(y=s[d]);return Number(y)}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==u);if(c.length===0)return lr(r);let l=D.zeros(c,n),m=l.data,f=o[u],p=c.reduce((y,d)=>y*d,1);if(N(n)){let y=s,d=m;for(let g=0;g<p;g++){let A=T(g,u,0,o),h=U(A,o),b=y[h];for(let S=1;S<f;S++){let w=T(g,u,S,o),x=U(w,o),z=y[x];z>b&&(b=z)}d[g]=b}}else for(let y=0;y<p;y++){let d=-1/0;for(let g=0;g<f;g++){let A=T(y,u,g,o),h=U(A,o),b=Number(s[h]);b>d&&(d=b)}m[y]=d}if(e){let y=[...o];return y[u]=1,D.fromData(m,y,n)}return l}function Ur(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,s=r.data;if(t===void 0)if(N(n)){let y=s,d=BigInt(1);for(let g=0;g<i;g++)d*=y[g];return Number(d)}else{let y=1;for(let d=0;d<i;d++)y*=Number(s[d]);return y}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==u);if(c.length===0)return Ur(r);let l=D.zeros(c,n),m=l.data,f=o[u],p=c.reduce((y,d)=>y*d,1);if(N(n)){let y=s,d=m;for(let g=0;g<p;g++){let A=BigInt(1);for(let h=0;h<f;h++){let b=T(g,u,h,o),S=U(b,o);A*=y[S]}d[g]=A}}else for(let y=0;y<p;y++){let d=1;for(let g=0;g<f;g++){let A=T(y,u,g,o),h=U(A,o);d*=Number(s[h])}m[y]=d}if(e){let y=[...o];return y[u]=1,D.fromData(m,y,n)}return l}function pr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,s=r.data;if(t===void 0){if(i===0)throw new Error("min of empty array");let y=s[0];for(let d=1;d<i;d++)s[d]<y&&(y=s[d]);return Number(y)}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==u);if(c.length===0)return pr(r);let l=D.zeros(c,n),m=l.data,f=o[u],p=c.reduce((y,d)=>y*d,1);if(N(n)){let y=s,d=m;for(let g=0;g<p;g++){let A=T(g,u,0,o),h=U(A,o),b=y[h];for(let S=1;S<f;S++){let w=T(g,u,S,o),x=U(w,o),z=y[x];z<b&&(b=z)}d[g]=b}}else for(let y=0;y<p;y++){let d=1/0;for(let g=0;g<f;g++){let A=T(y,u,g,o),h=U(A,o),b=Number(s[h]);b<d&&(d=b)}m[y]=d}if(e){let y=[...o];return y[u]=1,D.fromData(m,y,n)}return l}function Tr(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let p=i[0],y=0;for(let d=1;d<a;d++)i[d]<p&&(p=i[d],y=d);return y}let 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 u=Array.from(n).filter((p,y)=>y!==s);if(u.length===0)return Tr(r);let c=D.zeros(u,"int32"),l=c.data,m=n[s],f=u.reduce((p,y)=>p*y,1);if(N(e)){let p=i;for(let y=0;y<f;y++){let d=T(y,s,0,n),g=U(d,n),A=p[g],h=0;for(let b=1;b<m;b++){let S=T(y,s,b,n),w=U(S,n),x=p[w];x<A&&(A=x,h=b)}l[y]=h}}else for(let p=0;p<f;p++){let y=1/0,d=0;for(let g=0;g<m;g++){let A=T(p,s,g,n),h=U(A,n),b=Number(i[h]);b<y&&(y=b,d=g)}l[p]=d}return c}function Or(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmax of empty array");let p=i[0],y=0;for(let d=1;d<a;d++)i[d]>p&&(p=i[d],y=d);return y}let 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 u=Array.from(n).filter((p,y)=>y!==s);if(u.length===0)return Or(r);let c=D.zeros(u,"int32"),l=c.data,m=n[s],f=u.reduce((p,y)=>p*y,1);if(N(e)){let p=i;for(let y=0;y<f;y++){let d=T(y,s,0,n),g=U(d,n),A=p[g],h=0;for(let b=1;b<m;b++){let S=T(y,s,b,n),w=U(S,n),x=p[w];x>A&&(A=x,h=b)}l[y]=h}}else for(let p=0;p<f;p++){let y=-1/0,d=0;for(let g=0;g<m;g++){let A=T(p,s,g,n),h=U(A,n),b=Number(i[h]);b>y&&(y=b,d=g)}l[p]=d}return c}function $r(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.size,s=r.data,u=fr(r,t,n);if(t===void 0){let A=u,h=0;for(let b=0;b<i;b++){let S=Number(s[b])-A;h+=S*S}return h/(i-e)}let c=t;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let l=o[c],m=u,f=m.data,p=n?m.shape:Array.from(o).filter((A,h)=>h!==c),y=D.zeros(Array.from(p),"float64"),d=y.data,g=p.reduce((A,h)=>A*h,1);for(let A=0;A<g;A++){let h=0,b=Number(f[A]);for(let S=0;S<l;S++){let w=T(A,c,S,o),x=U(w,o),z=Number(s[x])-b;h+=z*z}d[A]=h/(l-e)}return y}function vt(r,t,e=0,n=!1){let o=$r(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=D.zeros(Array.from(o.shape),"float64"),i=o.data,s=a.data;for(let u=0;u<i.length;u++)s[u]=Math.sqrt(Number(i[u]));return a}function vr(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(!i[p])return!1;return!0}let 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 u=Array.from(n).filter((p,y)=>y!==s);if(u.length===0)return vr(r);let c=D.zeros(u,"bool"),l=c.data,m=n[s],f=u.reduce((p,y)=>p*y,1);for(let p=0;p<f;p++){let y=!0;for(let d=0;d<m;d++){let g=T(p,s,d,n),A=U(g,n);if(!i[A]){y=!1;break}}l[p]=y?1:0}if(e){let p=[...n];return p[s]=1,D.fromData(l,p,"bool")}return c}function Mr(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(i[p])return!0;return!1}let 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 u=Array.from(n).filter((p,y)=>y!==s);if(u.length===0)return Mr(r);let c=D.zeros(u,"bool"),l=c.data,m=n[s],f=u.reduce((p,y)=>p*y,1);for(let p=0;p<f;p++){let y=!1;for(let d=0;d<m;d++){let g=T(p,s,d,n),A=U(g,n);if(i[A]){y=!0;break}}l[p]=y?1:0}if(e){let p=[...n];return p[s]=1,D.fromData(l,p,"bool")}return c}function Cr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=0;for(let d=0;d<f;d++)y+=Number(o[d]),p[d]=y;return D.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),s=e[a],u=[],c=1;for(let f=n-1;f>=0;f--)u.unshift(c),c*=e[f];let l=r.size,m=u[a];for(let f=0;f<l;f++)Math.floor(f/m)%s===0?i[f]=Number(o[f]):i[f]=i[f-m]+Number(o[f]);return D.fromData(i,[...e],"float64")}function kr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=1;for(let d=0;d<f;d++)y*=Number(o[d]),p[d]=y;return D.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),s=e[a],u=[],c=1;for(let f=n-1;f>=0;f--)u.unshift(c),c*=e[f];let l=r.size,m=u[a];for(let f=0;f<l;f++)Math.floor(f/m)%s===0?i[f]=Number(o[f]):i[f]=i[f-m]*Number(o[f]);return D.fromData(i,[...e],"float64")}function Vr(r,t,e=!1){let n=lr(r,t,e),o=pr(r,t,e);if(typeof n=="number"&&typeof o=="number")return n-o;let a=n,i=o,s=a.data,u=i.data,c=new Float64Array(a.size);for(let l=0;l<a.size;l++)c[l]=Number(s[l])-Number(u[l]);return D.fromData(c,[...a.shape],"float64")}function Pr(r,t,e=!1){return G(r,.5,t,e)}function Fr(r,t,e,n=!1){return G(r,t/100,e,n)}function G(r,t,e,n=!1){if(t<0||t>1)throw new Error("Quantile must be between 0 and 1");let o=r.shape,a=o.length,i=r.data;if(e===void 0){let p=[];for(let b=0;b<r.size;b++)p.push(Number(i[b]));p.sort((b,S)=>b-S);let y=p.length,d=t*(y-1),g=Math.floor(d),A=Math.ceil(d);if(g===A)return p[g];let h=d-g;return p[g]*(1-h)+p[A]*h}let s=e;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((p,y)=>y!==s);if(u.length===0)return G(r,t);let c=u.reduce((p,y)=>p*y,1),l=o[s],m=new Float64Array(c);for(let p=0;p<c;p++){let y=[];for(let b=0;b<l;b++){let S=T(p,s,b,o),w=U(S,o);y.push(Number(i[w]))}y.sort((b,S)=>b-S);let d=y.length,g=t*(d-1),A=Math.floor(g),h=Math.ceil(g);if(A===h)m[p]=y[A];else{let b=g-A;m[p]=y[A]*(1-b)+y[h]*b}}let f=D.fromData(m,u,"float64");if(n){let p=[...o];return p[s]=1,D.fromData(m,p,"float64")}return f}function mr(r,t,e,n=!1){let o=r.shape,a=o.length,i=r.data;if(e===void 0)return fr(r,t,n);if(t===void 0){let y=0,d=0,g=e.data;for(let A=0;A<r.size;A++){let h=Number(g[A%e.size]);y+=Number(i[A])*h,d+=h}return d===0?NaN:y/d}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((y,d)=>d!==s);if(u.length===0)return mr(r,void 0,e);let c=u.reduce((y,d)=>y*d,1),l=o[s],m=e.data,f=new Float64Array(c);for(let y=0;y<c;y++){let d=0,g=0;for(let A=0;A<l;A++){let h=T(y,s,A,o),b=U(h,o),S=Number(m[A%e.size]);d+=Number(i[b])*S,g+=S}f[y]=g===0?NaN:d/g}let p=D.fromData(f,u,"float64");if(n){let y=[...o];return y[s]=1,D.fromData(f,y,"float64")}return p}function yr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=0;for(let p=0;p<r.size;p++){let y=Number(a[p]);isNaN(y)||(f+=y)}return f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((f,p)=>p!==i);if(s.length===0)return yr(r);let u=s.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(u);for(let f=0;f<u;f++){let p=0;for(let y=0;y<c;y++){let d=T(f,i,y,n),g=U(d,n),A=Number(a[g]);isNaN(A)||(p+=A)}l[f]=p}let m=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return m}function dr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=1;for(let p=0;p<r.size;p++){let y=Number(a[p]);isNaN(y)||(f*=y)}return f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((f,p)=>p!==i);if(s.length===0)return dr(r);let u=s.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(u);for(let f=0;f<u;f++){let p=1;for(let y=0;y<c;y++){let d=T(f,i,y,n),g=U(d,n),A=Number(a[g]);isNaN(A)||(p*=A)}l[f]=p}let m=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return m}function gr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=0,p=0;for(let y=0;y<r.size;y++){let d=Number(a[y]);isNaN(d)||(f+=d,p++)}return p===0?NaN:f/p}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((f,p)=>p!==i);if(s.length===0)return gr(r);let u=s.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(u);for(let f=0;f<u;f++){let p=0,y=0;for(let d=0;d<c;d++){let g=T(f,i,d,n),A=U(g,n),h=Number(a[A]);isNaN(h)||(p+=h,y++)}l[f]=y===0?NaN:p/y}let m=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return m}function K(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.data;if(t===void 0){let p=0,y=0;for(let A=0;A<r.size;A++){let h=Number(i[A]);isNaN(h)||(p+=h,y++)}if(y-e<=0)return NaN;let d=p/y,g=0;for(let A=0;A<r.size;A++){let h=Number(i[A]);isNaN(h)||(g+=(h-d)**2)}return g/(y-e)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((p,y)=>y!==s);if(u.length===0)return K(r,void 0,e);let c=u.reduce((p,y)=>p*y,1),l=o[s],m=new Float64Array(c);for(let p=0;p<c;p++){let y=0,d=0;for(let h=0;h<l;h++){let b=T(p,s,h,o),S=U(b,o),w=Number(i[S]);isNaN(w)||(y+=w,d++)}if(d-e<=0){m[p]=NaN;continue}let g=y/d,A=0;for(let h=0;h<l;h++){let b=T(p,s,h,o),S=U(b,o),w=Number(i[S]);isNaN(w)||(A+=(w-g)**2)}m[p]=A/(d-e)}let f=D.fromData(m,u,"float64");if(n){let p=[...o];return p[s]=1,D.fromData(m,p,"float64")}return f}function Rr(r,t,e=0,n=!1){let o=K(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,i=new Float64Array(a.size);for(let s=0;s<a.size;s++)i[s]=Math.sqrt(Number(a.data[s]));return D.fromData(i,[...a.shape],"float64")}function hr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=1/0;for(let p=0;p<r.size;p++){let y=Number(a[p]);!isNaN(y)&&y<f&&(f=y)}return f===1/0?NaN:f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((f,p)=>p!==i);if(s.length===0)return hr(r);let u=s.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(u);for(let f=0;f<u;f++){let p=1/0;for(let y=0;y<c;y++){let d=T(f,i,y,n),g=U(d,n),A=Number(a[g]);!isNaN(A)&&A<p&&(p=A)}l[f]=p===1/0?NaN:p}let m=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return m}function Ar(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=-1/0;for(let p=0;p<r.size;p++){let y=Number(a[p]);!isNaN(y)&&y>f&&(f=y)}return f===-1/0?NaN:f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((f,p)=>p!==i);if(s.length===0)return Ar(r);let u=s.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(u);for(let f=0;f<u;f++){let p=-1/0;for(let y=0;y<c;y++){let d=T(f,i,y,n),g=U(d,n),A=Number(a[g]);!isNaN(A)&&A>p&&(p=A)}l[f]=p===-1/0?NaN:p}let m=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return m}function br(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=1/0,m=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p<l&&(l=p,m=f)}return m}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,m)=>m!==a);if(i.length===0)return br(r);let s=i.reduce((l,m)=>l*m,1),u=e[a],c=new Int32Array(s);for(let l=0;l<s;l++){let m=1/0,f=0;for(let p=0;p<u;p++){let y=T(l,a,p,e),d=U(y,e),g=Number(o[d]);!isNaN(g)&&g<m&&(m=g,f=p)}c[l]=f}return D.fromData(c,i,"int32")}function Sr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=-1/0,m=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p>l&&(l=p,m=f)}return m}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,m)=>m!==a);if(i.length===0)return Sr(r);let s=i.reduce((l,m)=>l*m,1),u=e[a],c=new Int32Array(s);for(let l=0;l<s;l++){let m=-1/0,f=0;for(let p=0;p<u;p++){let y=T(l,a,p,e),d=U(y,e),g=Number(o[d]);!isNaN(g)&&g>m&&(m=g,f=p)}c[l]=f}return D.fromData(c,i,"int32")}function qr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=0;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(y+=g),p[d]=y}return D.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),s=e[a],u=[],c=1;for(let f=n-1;f>=0;f--)u.unshift(c),c*=e[f];let l=r.size,m=u[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/m)%s===0?i[f]=isNaN(p)?0:p:i[f]=i[f-m]+(isNaN(p)?0:p)}return D.fromData(i,[...e],"float64")}function Lr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=1;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(y*=g),p[d]=y}return D.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),s=e[a],u=[],c=1;for(let f=n-1;f>=0;f--)u.unshift(c),c*=e[f];let l=r.size,m=u[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/m)%s===0?i[f]=isNaN(p)?1:p:i[f]=i[f-m]*(isNaN(p)?1:p)}return D.fromData(i,[...e],"float64")}function Dr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=[];for(let d=0;d<r.size;d++){let g=Number(a[d]);isNaN(g)||f.push(g)}if(f.length===0)return NaN;f.sort((d,g)=>d-g);let p=f.length,y=Math.floor(p/2);return p%2===0?(f[y-1]+f[y])/2:f[y]}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((f,p)=>p!==i);if(s.length===0)return Dr(r);let u=s.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(u);for(let f=0;f<u;f++){let p=[];for(let g=0;g<c;g++){let A=T(f,i,g,n),h=U(A,n),b=Number(a[h]);isNaN(b)||p.push(b)}if(p.length===0){l[f]=NaN;continue}p.sort((g,A)=>g-A);let y=p.length,d=Math.floor(y/2);y%2===0?l[f]=(p[d-1]+p[d])/2:l[f]=p[d]}let m=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return m}function V(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((m,f,p)=>p===o?m:m*f,1),l=e/c;if(!Number.isInteger(l))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((m,f)=>f===o?l:m)}else a=t;if(a.reduce((c,l)=>c*l,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){let c=r.data;return D.fromData(c,a,n,F(a),0)}let u=r.copy().data;return D.fromData(u,a,n,F(a),0)}function Nr(r){let t=r.size,e=r.dtype,n=_(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let s=r.data.slice(r.offset,r.offset+t);return D.fromData(s,[t],e,[1],0)}let o=new n(t),a=N(e);for(let i=0;i<t;i++){let s=r.iget(i);o[i]=s}return D.fromData(o,[t],e,[1],0)}function tr(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return D.fromData(n,[t],e,[1],0)}return Nr(r)}function er(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype,s;if(t===void 0)s=Array.from({length:n},(m,f)=>n-1-f);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let m=new Set;for(let f of t){let p=f<0?n+f:f;if(p<0||p>=n)throw new Error(`axis ${f} is out of bounds for array of dimension ${n}`);if(m.has(p))throw new Error("repeated axis in transpose");m.add(p)}s=t.map(f=>f<0?n+f:f)}let u=s.map(m=>e[m]),c=Array.from(o),l=s.map(m=>c[m]);return D.fromData(a,u,i,l,r.offset)}function Mt(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype;if(t===void 0){let s=[],u=[];for(let c=0;c<n;c++)e[c]!==1&&(s.push(e[c]),u.push(o[c]));return s.length===0&&(s.push(1),u.push(1)),D.fromData(a,s,i,u,r.offset)}else{let s=t<0?n+t:t;if(s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[s]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[s]})`);let u=[],c=[];for(let l=0;l<n;l++)l!==s&&(u.push(e[l]),c.push(o[l]));return D.fromData(a,u,i,c,r.offset)}}function rr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype,s=t;if(s<0&&(s=n+t+1),s<0||s>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let u=[...Array.from(e)];u.splice(s,0,1);let c=[...Array.from(o)],l=s<n?o[s]*(e[s]||1):1;return c.splice(s,0,l),D.fromData(a,u,i,c,r.offset)}function Ct(r,t,e){let n=r.shape,o=n.length,a=r.strides,i=r.data,s=r.dtype,u=t<0?o+t:t,c=e<0?o+e:e;if(u<0||u>=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(u===c)return D.fromData(i,Array.from(n),s,Array.from(a),r.offset);let l=Array.from(n),m=Array.from(a);return[l[u],l[c]]=[l[c],l[u]],[m[u],m[c]]=[m[c],m[u]],D.fromData(i,l,s,m,r.offset)}function jr(r,t,e){let n=r.ndim,o=Array.isArray(t)?t:[t],a=Array.isArray(e)?e:[e];if(o.length!==a.length)throw new Error("source and destination must have the same number of elements");let i=o.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`source axis ${c} is out of bounds for array of dimension ${n}`);return l}),s=a.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`destination axis ${c} is out of bounds for array of dimension ${n}`);return l});if(new Set(i).size!==i.length)throw new Error("repeated axis in source");if(new Set(s).size!==s.length)throw new Error("repeated axis in destination");let u=[];for(let c=0;c<n;c++)i.includes(c)||u.push(c);for(let c=0;c<i.length;c++){let l=s[c];u.splice(l,0,i[c])}return er(r,u)}function W(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();let e=r[0],n=e.ndim,o=e.dtype,a=t<0?n+t:t;if(a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);for(let p=1;p<r.length;p++){let y=r[p];if(y.ndim!==n)throw new Error("all the input arrays must have same number of dimensions");for(let d=0;d<n;d++)if(d!==a&&y.shape[d]!==e.shape[d])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}let i=Array.from(e.shape),s=e.shape[a];for(let p=1;p<r.length;p++)s+=r[p].shape[a];i[a]=s;let u=i.reduce((p,y)=>p*y,1),c=_(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(u),m=F(i),f=0;for(let p of r){let y=p.shape[a];In(p,l,i,m,a,f,o),f+=y}return D.fromData(l,i,o)}function In(r,t,e,n,o,a,i){let s=r.shape,u=s.length,c=r.size,l=i==="int64"||i==="uint64";if(o===0&&r.isCContiguous&&u>0){let p=a*n[0],y=r.data,d=r.offset,g=d+c;t.set(y.subarray(d,g),p);return}if(o===1&&u===2&&r.isCContiguous){let p=s[0],y=s[1],d=e[1],g=r.data,A=r.offset;for(let h=0;h<p;h++){let b=A+h*y,S=h*d+a;t.set(g.subarray(b,b+y),S)}return}let m=new Array(u).fill(0),f=a*n[o];for(let p=0;p<c;p++){let y=r.iget(p),d=f;for(let g=0;g<u;g++)d+=m[g]*n[g];t[d]=y;for(let g=u-1;g>=0&&(m[g]++,!(m[g]<s[g]));g--)m[g]=0}}function kt(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let s=1;s<r.length;s++){let u=r[s];if(u.ndim!==o)throw new Error("all input arrays must have the same shape");for(let c=0;c<o;c++)if(u.shape[c]!==n[c])throw new Error("all input arrays must have the same shape")}let i=r.map(s=>rr(s,a));return W(i,a)}function Vt(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?V(e,[1,e.shape[0]]):e);return W(t,0)}function Zr(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?W(r,0):W(r,1)}function Pt(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?V(rr(V(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?rr(e,2):e);return W(t,2)}function Ft(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[a],s;if(typeof t=="number"){if(i%t!==0)throw new Error("array split does not result in an equal division");let u=i/t;s=[];for(let c=1;c<t;c++)s.push(c*u)}else s=t;return Rt(r,s,a)}function nr(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[a],s;if(typeof t=="number"){let u=t,c=Math.floor(i/u),l=i%u;s=[];let m=0;for(let f=0;f<u-1;f++)m+=c+(f<l?1:0),s.push(m)}else s=t;return Rt(r,s,a)}function Rt(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],i=[];for(let s=0;s<a.length-1;s++){let u=a[s],c=a[s+1];if(u>c)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=c-u;let m=r.offset+u*r.strides[e];i.push(D.fromData(r.data,l,r.dtype,Array.from(r.strides),m))}return i}function qt(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return nr(r,t,0)}function Lt(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 nr(r,t,e)}function jt(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],i=Math.max(n,a.length),s=new Array(i).fill(1),u=new Array(i).fill(1);for(let h=0;h<n;h++)s[i-n+h]=e[h];for(let h=0;h<a.length;h++)u[i-a.length+h]=a[h];let c=s.map((h,b)=>h*u[b]),l=c.reduce((h,b)=>h*b,1),m=_(o);if(!m)throw new Error(`Cannot tile array with dtype ${o}`);let f=new m(l),p=F(c),y=r;n<i&&(y=V(r,s));let d=o==="int64"||o==="uint64",g=y.strides,A=new Array(i).fill(0);for(let h=0;h<l;h++){let b=y.offset;for(let x=0;x<i;x++){let z=A[x]%s[x];b+=z*g[x]}let S=y.data[b],w=0;for(let x=0;x<i;x++)w+=A[x]*p[x];f[w]=S;for(let x=i-1;x>=0&&(A[x]++,!(A[x]<c[x]));x--)A[x]=0}return D.fromData(f,c,o)}function Zt(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let h=i,b=Array.isArray(t)?t:new Array(h).fill(t);if(b.length!==h)throw new Error(`operands could not be broadcast together with shape (${h},) (${b.length},)`);let S=b.reduce((B,E)=>B+E,0),w=_(a);if(!w)throw new Error(`Cannot repeat array with dtype ${a}`);let x=new w(S),z=0;for(let B=0;B<h;B++){let E=r.iget(B),O=b[B];for(let ir=0;ir<O;ir++)x[z++]=E}return D.fromData(x,[S],a)}let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[s],c=Array.isArray(t)?t:new Array(u).fill(t);if(c.length!==u)throw new Error(`operands could not be broadcast together with shape (${u},) (${c.length},)`);let l=Array.from(n);l[s]=c.reduce((h,b)=>h+b,0);let m=l.reduce((h,b)=>h*b,1),f=_(a);if(!f)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new f(m),y=F(l),d=new Array(o).fill(0),g=a==="int64"||a==="uint64",A=[0];for(let h=0;h<u;h++)A.push(A[h]+c[h]);for(let h=0;h<i;h++){let b=r.iget(h),S=d[s],w=c[S],x=0;for(let E=0;E<o;E++)E!==s&&(x+=d[E]*y[E]);let z=y[s],B=A[S];for(let E=0;E<w;E++){let O=x+(B+E)*z;p[O]=b}for(let E=o-1;E>=0&&(d[E]++,!(d[E]<n[E]));E--)d[E]=0}return D.fromData(p,l,a)}function Wt(r,t){let e=r.shape,n=e.length,o=r.dtype,a=r.size,i;if(t===void 0)i=new Set(Array.from({length:n},(f,p)=>p));else if(typeof t=="number"){let f=t<0?n+t:t;if(f<0||f>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);i=new Set([f])}else i=new Set(t.map(f=>{let p=f<0?n+f:f;if(p<0||p>=n)throw new Error(`axis ${f} is out of bounds for array of dimension ${n}`);return p}));let s=_(o);if(!s)throw new Error(`Cannot flip array with dtype ${o}`);let u=new s(a),c=N(o);if(n===1&&r.isCContiguous){let f=r.data,p=r.offset;for(let y=0;y<a;y++)u[y]=f[p+a-1-y];return D.fromData(u,[...e],o)}if(n===2&&r.isCContiguous){let f=e[0],p=e[1],y=r.data,d=r.offset;if(i.size===2){for(let g=0;g<a;g++)u[g]=y[d+a-1-g];return D.fromData(u,[...e],o)}if(i.size===1){if(i.has(0)){for(let g=0;g<f;g++){let A=d+(f-1-g)*p,h=g*p;for(let b=0;b<p;b++)u[h+b]=y[A+b]}return D.fromData(u,[...e],o)}else if(i.has(1)){for(let g=0;g<f;g++){let A=d+g*p,h=g*p;for(let b=0;b<p;b++)u[h+b]=y[A+p-1-b]}return D.fromData(u,[...e],o)}}}let l=new Array(n),m=new Array(n).fill(0);for(let f=0;f<a;f++){for(let d=0;d<n;d++)l[d]=i.has(d)?e[d]-1-m[d]:m[d];let p=r.offset;for(let d=0;d<n;d++)p+=l[d]*r.strides[d];let y=r.data[p];u[f]=y;for(let d=n-1;d>=0&&(m[d]++,!(m[d]<e[d]));d--)m[d]=0}return D.fromData(u,[...e],o)}function Ht(r,t=1,e=[0,1]){let n=r.shape,o=n.length,a=r.dtype;if(o<2)throw new Error("Input must be at least 2-D");let i=e[0]<0?o+e[0]:e[0],s=e[1]<0?o+e[1]:e[1];if(i<0||i>=o||s<0||s>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(i===s)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let u=_(a);if(!u)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[i],c[s]]=[c[s],c[i]]);let l=c.reduce((g,A)=>g*A,1),m=new u(l),f=F(c),p=N(a),y=new Array(o).fill(0),d=new Array(o);for(let g=0;g<r.size;g++){for(let w=0;w<o;w++)d[w]=y[w];let A,h;t===1?(A=n[s]-1-y[s],h=y[i]):t===2?(A=n[i]-1-y[i],h=n[s]-1-y[s],d[i]=A,d[s]=h):(A=y[s],h=n[i]-1-y[i]),t!==2&&(d[i]=A,d[s]=h);let b=0;for(let w=0;w<o;w++)b+=d[w]*f[w];let S=r.iget(g);m[b]=S;for(let w=o-1;w>=0&&(y[w]++,!(y[w]<n[w]));w--)y[w]=0}return D.fromData(m,c,a)}function Yt(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let y=Array.isArray(t)?t.reduce((b,S)=>b+S,0):t,d=Nr(r),g=_(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let A=new g(i),h=N(a);for(let b=0;b<i;b++){let S=((b-y)%i+i)%i,w=d.iget(S);A[b]=w}return D.fromData(A,[...n],a)}let s=Array.isArray(t)?t:[t],u=Array.isArray(e)?e:[e];if(s.length!==u.length)throw new Error("shift and axis must have the same length");let c=u.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=_(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let m=new l(i),f=N(a),p=new Array(o).fill(0);for(let y=0;y<i;y++){let d=[...p];for(let h=0;h<c.length;h++){let b=c[h],S=n[b],w=s[h];d[b]=((d[b]-w)%S+S)%S}let g=r.offset;for(let h=0;h<o;h++)g+=d[h]*r.strides[h];let A=r.data[g];m[y]=A;for(let h=o-1;h>=0&&(p[h]++,!(p[h]<n[h]));h--)p[h]=0}return D.fromData(m,[...n],a)}function Gt(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?D.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):jr(r,o,a)}function Jt(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return nr(r,t,2)}function Qt(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?V(e,[e.shape[0],1]):e);return Zr(t)}function Xt(r,t){let e=r.dtype,n=t.reduce((u,c)=>u*c,1),o=r.size,a=_(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let i=new a(n),s=N(e);for(let u=0;u<n;u++){let c=u%o,l=r.iget(c);i[u]=l}return D.fromData(i,t,e)}function Kt(r){return r.map(t=>t.ndim===0?V(t,[1]):t)}function re(r){return r.map(t=>t.ndim===0?V(t,[1,1]):t.ndim===1?V(t,[1,t.shape[0]]):t)}function te(r){return r.map(t=>t.ndim===0?V(t,[1,1,1]):t.ndim===1?V(t,[1,t.shape[0],1]):t.ndim===2?V(t,[t.shape[0],t.shape[1],1]):t)}function zn(r,t,e,n,o,a,i,s,u,c,l,m,f,p){if(m===0)for(let A=0;A<n*o;A++)f[A]=0;else if(m!==1)for(let A=0;A<n*o;A++)f[A]=(f[A]??0)*m;let y=r==="row-major",d=t==="transpose",g=e==="transpose";if(y&&!d&&!g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[A*u+S]??0)*(c[S*l+h]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else if(y&&d&&!g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[S*u+A]??0)*(c[S*l+h]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else if(y&&!d&&g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[A*u+S]??0)*(c[h*l+S]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else if(y&&d&&g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[S*u+A]??0)*(c[h*l+S]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else if(!y&&!d&&!g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[S*u+A]??0)*(c[h*l+S]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else if(!y&&d&&!g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[A*u+S]??0)*(c[h*l+S]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else if(!y&&!d&&g)for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[S*u+A]??0)*(c[S*l+h]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else for(let A=0;A<n;A++)for(let h=0;h<o;h++){let b=0;for(let S=0;S<a;S++)b+=(s[A*u+S]??0)*(c[S*l+h]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}}function Hr(r,t){let e=r.ndim,n=t.ndim;if(e===0||n===0){let o=e===0?r.get():null,a=n===0?t.get():null;if(e===0&&n===0)return typeof o=="bigint"&&typeof a=="bigint"?o*a:Number(o)*Number(a);if(e===0){let i=v(r.dtype,t.dtype),s=D.zeros([...t.shape],i);for(let u=0;u<t.size;u++){let c=t.data[u+t.offset];typeof o=="bigint"&&typeof c=="bigint"?s.data[u]=o*c:s.data[u]=Number(o)*Number(c)}return s}else{let i=v(r.dtype,t.dtype),s=D.zeros([...r.shape],i);for(let u=0;u<r.size;u++){let c=r.data[u+r.offset];typeof c=="bigint"&&typeof a=="bigint"?s.data[u]=c*a:s.data[u]=Number(c)*Number(a)}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 o=r.shape[0],a=0;for(let i=0;i<o;i++){let s=r.get(i),u=t.get(i);typeof s=="bigint"&&typeof u=="bigint"?a=Number(a)+Number(s*u):a+=Number(s)*Number(u)}return a}if(e===2&&n===2)return H(r,t);if(e===2&&n===1){let[o,a]=r.shape,i=t.shape[0];if(a!==i)throw new Error(`dot: incompatible shapes (${o},${a}) and (${i},)`);let s=v(r.dtype,t.dtype),u=D.zeros([o],s);for(let c=0;c<o;c++){let l=0;for(let m=0;m<a;m++){let f=r.get(c,m),p=t.get(m);typeof f=="bigint"&&typeof p=="bigint"?l=Number(l)+Number(f*p):l+=Number(f)*Number(p)}u.set([c],l)}return u}if(e===1&&n===2){let o=r.shape[0],[a,i]=t.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${i})`);let s=v(r.dtype,t.dtype),u=D.zeros([i],s);for(let c=0;c<i;c++){let l=0;for(let m=0;m<o;m++){let f=r.get(m),p=t.get(m,c);typeof f=="bigint"&&typeof p=="bigint"?l=Number(l)+Number(f*p):l+=Number(f)*Number(p)}u.set([c],l)}return u}if(e>2&&n===1){let o=r.shape[e-1],a=t.shape[0];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and (${a},)`);let i=[...r.shape.slice(0,-1)],s=v(r.dtype,t.dtype),u=D.zeros(i,s),c=i.reduce((l,m)=>l*m,1);for(let l=0;l<c;l++){let m=0,f=l,p=[];for(let y=i.length-1;y>=0;y--)p[y]=f%i[y],f=Math.floor(f/i[y]);for(let y=0;y<o;y++){let d=[...p,y],g=r.get(...d),A=t.get(y);typeof g=="bigint"&&typeof A=="bigint"?m=Number(m)+Number(g*A):m+=Number(g)*Number(A)}u.set(p,m)}return u}if(e===1&&n>2){let o=r.shape[0],a=1,i=t.shape[a];if(o!==i)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(t.shape)}`);let s=[...t.shape.slice(0,a),...t.shape.slice(a+1)],u=v(r.dtype,t.dtype),c=D.zeros(s,u),l=s.reduce((m,f)=>m*f,1);for(let m=0;m<l;m++){let f=m,p=[];for(let A=s.length-1;A>=0;A--)p[A]=f%s[A],f=Math.floor(f/s[A]);let y=p.slice(0,a),d=p.slice(a),g=0;for(let A=0;A<o;A++){let h=r.get(A),b=[...y,A,...d],S=t.get(...b);typeof h=="bigint"&&typeof S=="bigint"?g=Number(g)+Number(h*S):g+=Number(h)*Number(S)}c.set(p,g)}return c}if(e>=2&&n>=2&&!(e===2&&n===2)){let o=r.shape[e-1],a=t.shape[n-2];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and ${JSON.stringify(t.shape)}`);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],s=v(r.dtype,t.dtype),u=D.zeros(i,s),c=r.shape.slice(0,-1).reduce((p,y)=>p*y,1),l=t.shape.slice(0,-2).reduce((p,y)=>p*y,1),m=t.shape[n-1],f=o;for(let p=0;p<c;p++)for(let y=0;y<l;y++)for(let d=0;d<m;d++){let g=0;for(let h=0;h<f;h++){let b=p*f+h,S=r.data[b+r.offset],w=y*f*m+h*m+d,x=t.data[w+t.offset];typeof S=="bigint"&&typeof x=="bigint"?g=Number(g)+Number(S*x):g+=Number(S)*Number(x)}let A=p*l*m+y*m+d;u.data[A]=g}return u}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function H(r,t){if(r.ndim!==2||t.ndim!==2)throw new Error("matmul requires 2D arrays");let[e=0,n=0]=r.shape,[o=0,a=0]=t.shape;if(n!==o)throw new Error(`matmul shape mismatch: (${e},${n}) @ (${o},${a})`);let i=v(r.dtype,t.dtype),s=i.startsWith("int")||i.startsWith("uint")||i==="bool"?"float64":i;if(s!=="float64")throw new Error(`matmul currently only supports float64, got ${s}`);let u=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&&(u=u.subarray(r.offset)),t.offset>0&&(c=c.subarray(t.offset));let[l=0,m=0]=r.strides,[f=0,p=0]=t.strides,y=m>l,d=p>f,g=y?"transpose":"no-transpose",A=d?"transpose":"no-transpose",h,b;y?h=m:h=l,d?b=p:b=f;let S=D.zeros([e,a],"float64");return zn("row-major",g,A,e,a,n,1,u,h,c,b,0,S.data,a),S}function oe(r){if(r.ndim!==2)throw new Error(`trace requires 2D array, got ${r.ndim}D`);let[t=0,e=0]=r.shape,n=Math.min(t,e),o=0;for(let a=0;a<n;a++){let i=r.get(a,a);typeof i=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+i:o=(typeof o=="bigint"?Number(o):o)+i}return o}function ne(r,t){return er(r,t)}function ae(r,t){let e=r.ndim,n=t.ndim,o=r.shape[e-1],a=t.shape[n-1];if(o!==a)throw new Error(`inner: incompatible shapes - last dimensions ${o} and ${a} don't match`);if(e===1&&n===1)return Hr(r,t);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],s=v(r.dtype,t.dtype),u=D.zeros(i,s),c=e===1?1:r.shape.slice(0,-1).reduce((f,p)=>f*p,1),l=n===1?1:t.shape.slice(0,-1).reduce((f,p)=>f*p,1),m=o;for(let f=0;f<c;f++)for(let p=0;p<l;p++){let y=0;for(let g=0;g<m;g++){let A=e===1?g:f*m+g,h=n===1?g:p*m+g,b=r.data[A+r.offset],S=t.data[h+t.offset];typeof b=="bigint"&&typeof S=="bigint"?y=Number(y)+Number(b*S):y+=Number(b)*Number(S)}if(i.length===0)return y;let d=c===1?p:f*l+p;u.data[d]=y}return u}function Yr(r,t){let e=r.ndim===1?r:tr(r),n=t.ndim===1?t:tr(t),o=e.size,a=n.size,i=v(r.dtype,t.dtype),s=D.zeros([o,a],i);for(let u=0;u<o;u++)for(let c=0;c<a;c++){let l=e.get(u),m=n.get(c),f;typeof l=="bigint"&&typeof m=="bigint"?f=l*m:f=Number(l)*Number(m),s.set([u,c],f)}return s}function se(r,t,e){let n,o;if(typeof e=="number"){let f=e;if(f<0)throw new Error("tensordot: axes must be non-negative");if(f>r.ndim||f>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:f},(p,y)=>r.ndim-f+y),o=Array.from({length:f},(p,y)=>y)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let f=0;f<n.length;f++){let p=n[f],y=o[f];if(p<0||p>=r.ndim||y<0||y>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[p]!==t.shape[y])throw new Error(`tensordot: shape mismatch on axes ${p} and ${y}: ${r.shape[p]} != ${t.shape[y]}`)}let a=[],i=[];for(let f=0;f<r.ndim;f++)n.includes(f)||a.push(f);for(let f=0;f<t.ndim;f++)o.includes(f)||i.push(f);let s=[...a.map(f=>r.shape[f]),...i.map(f=>t.shape[f])];if(s.length===0){let f=0,p=n.map(y=>r.shape[y]).reduce((y,d)=>y*d,1);for(let y=0;y<p;y++){let d=y,g=new Array(n.length);for(let w=n.length-1;w>=0;w--){let x=n[w];g[w]=d%r.shape[x],d=Math.floor(d/r.shape[x])}let A=new Array(r.ndim),h=new Array(t.ndim);for(let w=0;w<n.length;w++)A[n[w]]=g[w];for(let w=0;w<o.length;w++)h[o[w]]=g[w];let b=r.get(...A),S=t.get(...h);typeof b=="bigint"&&typeof S=="bigint"?f=Number(f)+Number(b*S):f+=Number(b)*Number(S)}return f}let u=v(r.dtype,t.dtype),c=D.zeros(s,u),l=s.reduce((f,p)=>f*p,1),m=n.map(f=>r.shape[f]).reduce((f,p)=>f*p,1);for(let f=0;f<l;f++){let p=f,y=[];for(let h=s.length-1;h>=0;h--)y[h]=p%s[h],p=Math.floor(p/s[h]);let d=y.slice(0,a.length),g=y.slice(a.length),A=0;for(let h=0;h<m;h++){p=h;let b=[];for(let B=n.length-1;B>=0;B--){let E=n[B];b[B]=p%r.shape[E],p=Math.floor(p/r.shape[E])}let S=new Array(r.ndim),w=new Array(t.ndim);for(let B=0;B<a.length;B++)S[a[B]]=d[B];for(let B=0;B<i.length;B++)w[i[B]]=g[B];for(let B=0;B<n.length;B++)S[n[B]]=b[B],w[o[B]]=b[B];let x=r.get(...S),z=t.get(...w);typeof x=="bigint"&&typeof z=="bigint"?A=Number(A)+Number(x*z):A+=Number(x)*Number(z)}c.set(y,A)}return c}function ie(r,t=0,e=0,n=1){let o=r.shape,a=o.length;if(a<2)throw new Error("diagonal requires an array of at least two dimensions");let i=e<0?a+e:e,s=n<0?a+n:n;if(i<0||i>=a||s<0||s>=a)throw new Error("axis out of bounds");if(i===s)throw new Error("axis1 and axis2 cannot be the same");let u=o[i],c=o[s],l;t>=0?l=Math.max(0,Math.min(u,c-t)):l=Math.max(0,Math.min(u+t,c));let m=[];for(let d=0;d<a;d++)d!==i&&d!==s&&m.push(o[d]);m.push(l);let f=D.zeros(m,r.dtype),p=o.filter((d,g)=>g!==i&&g!==s),y=p.reduce((d,g)=>d*g,1);for(let d=0;d<y;d++){let g=d,A=[];for(let h=p.length-1;h>=0;h--)A.unshift(g%p[h]),g=Math.floor(g/p[h]);for(let h=0;h<l;h++){let b=new Array(a),S=0;for(let z=0;z<a;z++)z===i?b[z]=t>=0?h:h-t:z===s?b[z]=t>=0?h+t:h:b[z]=A[S++];let w=[...A,h],x=r.get(...b);f.set(w,x)}}return f}function ue(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=Bn(n)):(n=r.slice(0,e),o=r.slice(e+2));let a=n.split(",").map(d=>d.trim());if(a.length!==t.length)throw new Error(`einsum: expected ${a.length} operands, got ${t.length}`);let i=new Map;for(let d=0;d<t.length;d++){let g=a[d],A=t[d];if(g.length!==A.ndim)throw new Error(`einsum: operand ${d} has ${A.ndim} dimensions but subscript '${g}' has ${g.length} indices`);for(let h=0;h<g.length;h++){let b=g[h],S=A.shape[h];if(i.has(b)){if(i.get(b)!==S)throw new Error(`einsum: size mismatch for index '${b}': ${i.get(b)} vs ${S}`)}else i.set(b,S)}}for(let d of o)if(!i.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let s=new Set(o),u=new Set;for(let d of a)for(let g of d)u.add(g);let c=[];for(let d of u)s.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,g]=a,[A,h]=t;if(d.length===2&&g.length===2&&o.length===2&&A.ndim===2&&h.ndim===2){let[b,S]=[d[0],d[1]],[w,x]=[g[0],g[1]],[z,B]=[o[0],o[1]];if(b===z&&x===B&&S===w&&c.length===1&&c[0]===S||b===z&&x===B&&S===w&&c.length===1&&c[0]===S)return H(A,h);if(S===z&&x===B&&b===w&&c.length===1&&c[0]===b){let E=ne(A);return H(E,h)}if(b===z&&w===B&&S===x&&c.length===1&&c[0]===S){let E=ne(h);return H(A,E)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&A.ndim===1&&h.ndim===1)return Wr(t,a,c,i);if(d&&g&&d.length===1&&g.length===1&&o.length===2&&o===d+g&&c.length===0&&A.ndim===1&&h.ndim===1)return Yr(A,h)}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 Wr(t,a,c,i)}let l=Array.from(o).map(d=>i.get(d));if(l.length===0)return Wr(t,a,c,i);let m=t[0].dtype;for(let d=1;d<t.length;d++)m=v(m,t[d].dtype);let f=D.zeros(l,m),p=l.reduce((d,g)=>d*g,1),y=1;for(let d of c)y*=i.get(d);for(let d=0;d<p;d++){let g=_n(d,l),A=new Map;for(let b=0;b<o.length;b++)A.set(o[b],g[b]);let h=0;for(let b=0;b<y;b++){let S=b;for(let x=c.length-1;x>=0;x--){let z=c[x],B=i.get(z);A.set(z,S%B),S=Math.floor(S/B)}let w=1;for(let x=0;x<t.length;x++){let z=t[x],B=a[x],E=[];for(let ir of B)E.push(A.get(ir));let O=z.get(...E);w*=Number(O)}h+=w}f.set(g,h)}return f}function Bn(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 Wr(r,t,e,n){let o=1;for(let i of e)o*=n.get(i);let a=0;for(let i=0;i<o;i++){let s=new Map,u=i;for(let l=e.length-1;l>=0;l--){let m=e[l],f=n.get(m);s.set(m,u%f),u=Math.floor(u/f)}let c=1;for(let l=0;l<r.length;l++){let m=r[l],f=t[l],p=[];for(let d of f)p.push(s.get(d));let y=m.get(...p);c*=Number(y)}a+=c}return a}function _n(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 ce(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,i=v(r.dtype,t.dtype),s=Math.max(o,a),u=new Array(s),c=new Array(s).fill(1),l=new Array(s).fill(1);for(let y=0;y<o;y++)c[s-o+y]=e[y];for(let y=0;y<a;y++)l[s-a+y]=n[y];for(let y=0;y<s;y++)u[y]=c[y]*l[y];let m=D.zeros(u,i),f=e.reduce((y,d)=>y*d,1),p=n.reduce((y,d)=>y*d,1);for(let y=0;y<f;y++){let d=y,g=new Array(o);for(let b=o-1;b>=0;b--)g[b]=d%e[b],d=Math.floor(d/e[b]);let A=new Array(s).fill(0);for(let b=0;b<o;b++)A[s-o+b]=g[b];let h=r.get(...g);for(let b=0;b<p;b++){let S=b,w=new Array(a);for(let O=a-1;O>=0;O--)w[O]=S%n[O],S=Math.floor(S/n[O]);let x=new Array(s).fill(0);for(let O=0;O<a;O++)x[s-a+O]=w[O];let z=t.get(...w),B=new Array(s);for(let O=0;O<s;O++)B[O]=A[O]*l[O]+x[O];let E=typeof h=="bigint"||typeof z=="bigint"?BigInt(Number(h))*BigInt(Number(z)):Number(h)*Number(z);m.set(B,E)}}return m}function fe(r){return M(r,Math.sqrt,!1)}function le(r,t){return typeof t=="number"?Un(r,t):P(r,t,Math.pow,"power")}function Un(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,c=D.zeros(n,u),l=c.data;if(N(e))if(N(u)&&Number.isInteger(t)&&t>=0){let m=o,f=l;for(let p=0;p<a;p++)f[p]=m[p]**BigInt(t)}else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);return c}function pe(r){return M(r,Math.sin,!1)}function me(r){return M(r,Math.cos,!1)}function ye(r){return M(r,Math.tan,!1)}function de(r){return M(r,Math.asin,!1)}function ge(r){return M(r,Math.acos,!1)}function he(r){return M(r,Math.atan,!1)}function Ae(r,t){return typeof t=="number"?$n(r,t):On(r,t)}function On(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",s=D.zeros(e,i),u=s.data;for(let c=0;c<n;c++){let l=(N(o),Number(r.data[c])),m=(N(a),Number(t.data[c]));u[c]=Math.atan2(l,m)}return s}function $n(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",s=D.zeros(n,i),u=s.data;if(N(e))for(let c=0;c<a;c++)u[c]=Math.atan2(Number(o[c]),t);else for(let c=0;c<a;c++)u[c]=Math.atan2(Number(o[c]),t);return s}function be(r,t){return typeof t=="number"?Mn(r,t):vn(r,t)}function vn(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",s=D.zeros(e,i),u=s.data;for(let c=0;c<n;c++){let l=(N(o),Number(r.data[c])),m=(N(a),Number(t.data[c]));u[c]=Math.hypot(l,m)}return s}function Mn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",s=D.zeros(n,i),u=s.data;if(N(e))for(let c=0;c<a;c++)u[c]=Math.hypot(Number(o[c]),t);else for(let c=0;c<a;c++)u[c]=Math.hypot(Number(o[c]),t);return s}function Se(r){let t=180/Math.PI;return M(r,e=>e*t,!1)}function De(r){let t=Math.PI/180;return M(r,e=>e*t,!1)}function Ne(r){return M(r,Math.sinh,!1)}function we(r){return M(r,Math.cosh,!1)}function xe(r){return M(r,Math.tanh,!1)}function Ie(r){return M(r,Math.asinh,!1)}function ze(r){return M(r,Math.acosh,!1)}function Be(r){return M(r,Math.atanh,!1)}function Gr(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=Z([Array.from(e),t]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);for(let i=0;i<o;i++)if(a[i]!==t[i])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);return j(r,t)}function _e(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=Z(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=>j(n,e))}function Ee(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let y=r.size;for(let h of t){let b=h<0?y+h:h;if(b<0||b>=y)throw new Error(`index ${h} is out of bounds for axis 0 with size ${y}`)}let d=t.length,g=_(a);if(!g)throw new Error(`Cannot take from array with dtype ${a}`);let A=new g(d);for(let h=0;h<d;h++){let b=t[h];b<0&&(b=y+b);let S=r.iget(b);N(a),A[h]=S}return D.fromData(A,[d],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[i];for(let y of t){let d=y<0?s+y:y;if(d<0||d>=s)throw new Error(`index ${y} is out of bounds for axis ${i} with size ${s}`)}let u=Array.from(n);u[i]=t.length;let c=u.reduce((y,d)=>y*d,1),l=_(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let m=new l(c),f=F(u),p=new Array(o).fill(0);for(let y=0;y<c;y++){let d=[...p],g=p[i],A=t[g];A<0&&(A=s+A),d[i]=A;let h=r.get(...d),b=0;for(let S=0;S<o;S++)b+=p[S]*f[S];N(a),m[b]=h;for(let S=o-1;S>=0&&(p[S]++,!(p[S]<u[S]));S--)p[S]=0}return D.fromData(m,u,a)}function Ue(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=new Array(t.length).fill(e);else{a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i));if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let i=[...a];a=[];for(let s=0;s<t.length;s++)a.push(i[s%i.length])}}for(let i=0;i<t.length;i++){let s=t[i];if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`index ${t[i]} is out of bounds for axis 0 with size ${n}`);let u=a[i];N(o)?typeof u!="bigint"&&(u=BigInt(Math.round(Number(u)))):typeof u=="bigint"&&(u=Number(u)),r.iset(s,u)}}function Te(r,t){if(t.length===0)throw new Error("choices cannot be empty");let e=r.shape,n=t.length,o=t[0].dtype,a=t.map(f=>Array.from(f.shape));a.unshift(Array.from(e));let i=Z(a);if(i===null)throw new Error("operands could not be broadcast together");let s=j(r,i),u=t.map(f=>j(f,i)),c=i.reduce((f,p)=>f*p,1),l=_(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let m=new l(c);for(let f=0;f<c;f++){let p=Number(s.iget(f));if(p<0||p>=n)throw new Error(`index ${p} is out of bounds for axis 0 with size ${n}`);let y=u[p].iget(f);N(o),m[f]=y}return D.fromData(m,i,o)}function Oe(r,t,e=!1){if(r.ndim!==t.ndim)return!1;for(let o=0;o<r.ndim;o++)if(r.shape[o]!==t.shape[o])return!1;let n=r.size;for(let o=0;o<n;o++){let a=r.iget(o),i=t.iget(o);if(e){let s=typeof a=="number"&&Number.isNaN(a),u=typeof i=="number"&&Number.isNaN(i);if(s&&u)continue}if(a!==i)return!1}return!0}var I=class r{constructor(t,e){this._storage=t,this._base=e}get storage(){return this._storage}static _fromStorage(t,e){return new r(t,e)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let e=t.map((n,o)=>{let a=n;if(a<0&&(a=this.shape[o]+a),a<0||a>=this.shape[o])throw new Error(`Index ${n} is out of bounds for axis ${o} with size ${this.shape[o]}`);return a});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let n=t.map((i,s)=>{let u=i;if(u<0&&(u=this.shape[s]+u),u<0||u>=this.shape[s])throw new Error(`Index ${i} is out of bounds for axis ${s} with size ${this.shape[s]}`);return u}),o=this.dtype,a;N(o)?a=typeof e=="bigint"?e:BigInt(Math.round(e)):o==="bool"?a=e?1:0:a=Number(e),this._storage.set(n,a)}copy(){return new r(this._storage.copy())}astype(t,e=!0){let n=this.dtype;if(n===t&&!e)return this;if(n===t&&e)return this.copy();let o=Array.from(this.shape),a=this.size,i=_(t);if(!i)throw new Error(`Cannot convert to dtype ${t}`);let s=new i(a),u=this.data;if(N(n)&&!N(t)){let l=u;if(t==="bool")for(let m=0;m<a;m++)s[m]=l[m]!==BigInt(0)?1:0;else for(let m=0;m<a;m++)s[m]=Number(l[m])}else if(!N(n)&&N(t)){let l=u;for(let m=0;m<a;m++)s[m]=BigInt(Math.round(Number(l[m])))}else if(t==="bool"){let l=u;for(let m=0;m<a;m++)s[m]=l[m]!==0?1:0}else if(n==="bool"&&!N(t)){let l=u;for(let m=0;m<a;m++)s[m]=l[m]}else if(!N(n)&&!N(t)){let l=u;for(let m=0;m<a;m++)s[m]=l[m]}else{let l=u;for(let m=0;m<a;m++)s[m]=l[m]}let c=D.fromData(s,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=lt(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=pt(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=mt(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=yt(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=cr(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=Br(this._storage,e);return r._fromStorage(n)}positive(){let t=At(this._storage);return r._fromStorage(t)}reciprocal(){let t=bt(this._storage);return r._fromStorage(t)}sqrt(){let t=fe(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=le(this._storage,e);return r._fromStorage(n)}absolute(){let t=dt(this._storage);return r._fromStorage(t)}negative(){let t=gt(this._storage);return r._fromStorage(t)}sign(){let t=ht(this._storage);return r._fromStorage(t)}sin(){let t=pe(this._storage);return r._fromStorage(t)}cos(){let t=me(this._storage);return r._fromStorage(t)}tan(){let t=ye(this._storage);return r._fromStorage(t)}arcsin(){let t=de(this._storage);return r._fromStorage(t)}arccos(){let t=ge(this._storage);return r._fromStorage(t)}arctan(){let t=he(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=Ae(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=be(this._storage,e);return r._fromStorage(n)}degrees(){let t=Se(this._storage);return r._fromStorage(t)}radians(){let t=De(this._storage);return r._fromStorage(t)}sinh(){let t=Ne(this._storage);return r._fromStorage(t)}cosh(){let t=we(this._storage);return r._fromStorage(t)}tanh(){let t=xe(this._storage);return r._fromStorage(t)}arcsinh(){let t=Ie(this._storage);return r._fromStorage(t)}arccosh(){let t=ze(this._storage);return r._fromStorage(t)}arctanh(){let t=Be(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=zt(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=Bt(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=_t(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=Et(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=Ut(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=Tt(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=Er(this._storage,o,e,n);return r._fromStorage(a)}allclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage;return Ot(this._storage,o,e,n)}sum(t,e=!1){let n=X(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=fr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=lr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=pr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=Ur(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=Tr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=Or(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=$r(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=vt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=vr(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=Mr(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(Cr(this._storage,t))}cumprod(t){return r._fromStorage(kr(this._storage,t))}ptp(t,e=!1){let n=Vr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=Pr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=Fr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=G(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=mr(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=yr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=dr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=gr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=K(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=Rr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=hr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=Ar(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=br(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=Sr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(qr(this._storage,t))}nancumprod(t){return r._fromStorage(Lr(this._storage,t))}nanmedian(t,e=!1){let n=Dr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=V(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Nr(this._storage);return r._fromStorage(t)}ravel(){let t=tr(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=er(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=Mt(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=rr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=Ct(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=jr(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=Zt(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=Ee(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;Ue(this._storage,t,n)}matmul(t){let e=H(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=Hr(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return oe(this._storage)}inner(t){let e=ae(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=Yr(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=se(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=St(this._storage);return r._fromStorage(t)}fabs(){let t=Dt(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=Nt(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=wt(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=xt(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=It(this._storage,e);return r._fromStorage(n)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);let e=t.map((u,c)=>{let l=st(u);return it(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 u=0;u<e.length;u++){let c=e[u],l=this._storage.strides[u];if(a+=c.start*l,!c.isIndex){let m;c.step>0?m=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):m=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(m),o.push(l*c.step)}}let i=D.fromData(this._storage.data,n,this._storage.dtype,o,a),s=this._base??this;return new r(i,s)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let t=this.shape,e=t.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let i=[];for(let s=0;s<t[a];s++)o[a]=s,i.push(n(o,a+1));return i};return n(new Array(e),0)}};function R(r,t=$){let e=D.zeros(r,t);return new I(e)}function $e(r,t=$){let e=D.ones(r,t);return new I(e)}function Pn(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function ve(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>ve(t)):!1}function Fn(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function C(r,t){if(r instanceof I)return!t||r.dtype===t?r.copy():r.astype(t);let e=ve(r),n=Pn(r),o=n.reduce((l,m)=>l*m,1),a=t;a||(e?a="int64":a=$);let i=_(a);if(!i)throw new Error(`Cannot create array with dtype ${a}`);let s=new i(o),u=Fn(r);if(N(a)){let l=s;for(let m=0;m<o;m++){let f=u[m];l[m]=typeof f=="bigint"?f:BigInt(Math.round(Number(f)))}}else if(a==="bool"){let l=s;for(let m=0;m<o;m++)l[m]=u[m]?1:0}else{let l=s;for(let m=0;m<o;m++){let f=u[m];l[m]=Number(f)}}let c=D.fromData(s,n,a);return new I(c)}function Rn(r,t,e=1,n=$){let o=r,a=t;if(t===void 0&&(o=0,a=r),a===void 0)throw new Error("stop is required");let i=Math.max(0,Math.ceil((a-o)/e)),s=_(n);if(!s)throw new Error(`Cannot create arange array with dtype ${n}`);let u=new s(i);if(N(n))for(let l=0;l<i;l++)u[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<i;l++)u[l]=o+l*e!==0?1:0;else for(let l=0;l<i;l++)u[l]=o+l*e;let c=D.fromData(u,[i],n);return new I(c)}function qn(r,t,e=50,n=$){if(e<0)throw new Error("num must be non-negative");if(e===0)return C([],n);if(e===1)return C([r],n);let o=_(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),i=(t-r)/(e-1);if(N(n))for(let u=0;u<e;u++)a[u]=BigInt(Math.round(r+u*i));else if(n==="bool")for(let u=0;u<e;u++)a[u]=r+u*i!==0?1:0;else for(let u=0;u<e;u++)a[u]=r+u*i;let s=D.fromData(a,[e],n);return new I(s)}function Ln(r,t,e=50,n=10,o=$){if(e<0)throw new Error("num must be non-negative");if(e===0)return C([],o);if(e===1)return C([Math.pow(n,r)],o);let a=_(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let i=new a(e),s=(t-r)/(e-1);if(N(o))for(let c=0;c<e;c++){let l=r+c*s;i[c]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let c=0;c<e;c++){let l=r+c*s;i[c]=Math.pow(n,l)!==0?1:0}else for(let c=0;c<e;c++){let l=r+c*s;i[c]=Math.pow(n,l)}let u=D.fromData(i,[e],o);return new I(u)}function jn(r,t,e=50,n=$){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 C([],n);if(e===1)return C([r],n);let o=Math.sign(r),a=Math.sign(t);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let i=_(n);if(!i)throw new Error(`Cannot create geomspace array with dtype ${n}`);let s=new i(e),u=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-u)/(e-1);if(N(n))for(let f=0;f<e;f++){let p=o*Math.exp(u+f*l);s[f]=BigInt(Math.round(p))}else if(n==="bool")for(let f=0;f<e;f++){let p=o*Math.exp(u+f*l);s[f]=p!==0?1:0}else for(let f=0;f<e;f++){let p=o*Math.exp(u+f*l);s[f]=p}let m=D.fromData(s,[e],n);return new I(m)}function Me(r,t,e=0,n=$){let o=t??r,a=R([r,o],n),i=a.data;if(N(n)){let s=i;for(let u=0;u<r;u++){let c=u+e;c>=0&&c<o&&(s[u*o+c]=BigInt(1))}}else{let s=i;for(let u=0;u<r;u++){let c=u+e;c>=0&&c<o&&(s[u*o+c]=1)}}return a}function Ce(r,t=$){return R(r,t)}function ke(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=$);let o=_(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((u,c)=>u*c,1),i=new o(a);if(N(n)){let u=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));i.fill(u)}else n==="bool"?i.fill(t?1:0):i.fill(Number(t));let s=D.fromData(i,r,n);return new I(s)}function Zn(r,t=$){return Me(r,r,0,t)}function wr(r,t){return r instanceof I?!t||r.dtype===t?r:r.astype(t):C(r,t)}function Wn(r){return r.copy()}function Hn(r,t){return R(Array.from(r.shape),t??r.dtype)}function Yn(r,t){return $e(Array.from(r.shape),t??r.dtype)}function Gn(r,t){return Ce(Array.from(r.shape),t??r.dtype)}function Jn(r,t,e){return ke(Array.from(r.shape),t,e??r.dtype)}function Qn(r,t){return wr(r,t)}function Xn(r,t){let e=wr(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function Kn(r,t){return wr(r,t).copy()}function Ve(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=R([n,n],r.dtype);for(let a=0;a<e;a++){let i=t>=0?a:a-t,s=t>=0?a+t:a;o.set([i,s],r.get([a]))}return o}else if(r.ndim===2){let[e,n]=r.shape,o,a,i;if(t>=0?(o=0,a=t,i=Math.min(e,n-t)):(o=-t,a=0,i=Math.min(e+t,n)),i<=0)return R([0],r.dtype);let s=_(r.dtype),u=new s(i);for(let l=0;l<i;l++){let m=r.get([o+l,a+l]);N(r.dtype)?u[l]=typeof m=="bigint"?m:BigInt(m):u[l]=m}let c=D.fromData(u,[i],r.dtype);return new I(c)}else throw new Error("Input must be 1-D or 2-D")}function ro(r,t=0){let e=r.flatten();return Ve(e,t)}function to(r,t,e=$){let n=t.reduce((c,l)=>c*l,1),o=_(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),i=t.length,s=new Array(i).fill(0);for(let c=0;c<n;c++){let l=r(...s);N(e)?a[c]=typeof l=="bigint"?l:BigInt(Number(l)):e==="bool"?a[c]=l?1:0:a[c]=Number(l);for(let m=i-1;m>=0&&(s[m]++,!(s[m]<t[m]));m--)s[m]=0}let u=D.fromData(a,t,e);return new I(u)}function eo(...r){let t=[],e="xy";for(let s of r)s instanceof I?t.push(s):typeof s=="object"&&"indexing"in s&&(e=s.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(s=>s.size);e==="xy"&&t.length>=2&&(t=[t[1],t[0],...t.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,i=[];for(let s=0;s<t.length;s++){let u=t[s],c=u.size,l=new Array(a).fill(1);l[s]=c;let m=u.reshape(...l),f=Gr(m.storage,o),p=I._fromStorage(f.copy());i.push(p)}return e==="xy"&&i.length>=2&&([i[0],i[1]]=[i[1],i[0]]),i}function no(r,t,e=0,n=$){let o=t??r,a=R([r,o],n);for(let i=0;i<r;i++)for(let s=0;s<=i+e&&s<o;s++)s>=0&&a.set([i,s],1);return a}function oo(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],i=n.slice(0,-2).reduce((s,u)=>s*u,1);for(let s=0;s<i;s++)for(let u=0;u<o;u++)for(let c=0;c<a;c++)if(c>u+t){let l=[],m=s;for(let f=n.length-3;f>=0;f--)l.unshift(m%n[f]),m=Math.floor(m/n[f]);l.push(u,c),e.set(l,0)}return e}function ao(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],i=n.slice(0,-2).reduce((s,u)=>s*u,1);for(let s=0;s<i;s++)for(let u=0;u<o;u++)for(let c=0;c<a;c++)if(c<u+t){let l=[],m=s;for(let f=n.length-3;f>=0;f--)l.unshift(m%n[f]),m=Math.floor(m/n[f]);l.push(u,c),e.set(l,0)}return e}function so(r,t,e=!1){if(r.ndim!==1)throw new Error("Input must be 1-D");let n=r.size,o=t??n;if(o<0)throw new Error("N must be non-negative");let a=R([n,o],r.dtype);for(let i=0;i<n;i++){let s=r.get([i]);for(let u=0;u<o;u++){let c=e?u:o-1-u;a.set([i,u],Math.pow(s,c))}}return a}function io(r,t=$,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let i=lo(t),s=o.byteLength-a,u=Math.floor(s/i),c=e<0?u:Math.min(e,u);if(c<=0)return C([],t);let l=_(t);if(!l)throw new Error(`Unsupported dtype: ${t}`);let m=new l(o,a,c),f=D.fromData(m,[c],t);return new I(f)}function uo(r,t=$,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return C(n,t)}function co(r,t=$,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return C(n,t)}function fo(r,t=$,e=-1,n=""){let o;n===""?o=r.trim().split(/\s+/):o=r.split(n);let a=[],i=0;for(let s of o){if(e>=0&&i>=e)break;let u=s.trim();u!==""&&(N(t)?a.push(BigInt(u)):a.push(parseFloat(u)),i++)}return C(a,t)}function lo(r){switch(r){case"int8":case"uint8":case"bool":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;case"int64":case"uint64":case"float64":return 8;default:return 8}}function po(r){return r.sqrt()}function mo(r,t){return r.power(t)}function yo(r){return r.absolute()}function go(r){return r.negative()}function ho(r){return r.sign()}function Ao(r,t){return r.mod(t)}function bo(r,t){return r.floor_divide(t)}function So(r){return r.positive()}function Do(r){return r.reciprocal()}function No(r,t){return r.dot(t)}function wo(r){return r.trace()}function xo(r,t=0,e=0,n=1){let o=ie(r.storage,t,e,n);return I._fromStorage(o)}function Io(r,t){let e=ce(r.storage,t.storage);return I._fromStorage(e)}function zo(r,t){return r.transpose(t)}function Bo(r,t){return r.inner(t)}function _o(r,t){return r.outer(t)}function Eo(r,t,e=2){return r.tensordot(t,e)}function Uo(r){return r.sin()}function To(r){return r.cos()}function Oo(r){return r.tan()}function $o(r){return r.arcsin()}function vo(r){return r.arccos()}function Mo(r){return r.arctan()}function Co(r,t){return r.arctan2(t)}function ko(r,t){return r.hypot(t)}function Vo(r){return r.degrees()}function Po(r){return r.radians()}function Fo(r){return r.radians()}function Ro(r){return r.degrees()}function qo(r){return r.sinh()}function Lo(r){return r.cosh()}function jo(r){return r.tanh()}function Zo(r){return r.arcsinh()}function Wo(r){return r.arccosh()}function Ho(r){return r.arctanh()}function Yo(r,t,e){return r.swapaxes(t,e)}function Go(r,t,e){return r.moveaxis(t,e)}function J(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");let e=r.map(o=>o.storage),n=W(e,t);return I._fromStorage(n)}function Jo(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r.map(o=>o.storage),n=kt(e,t);return I._fromStorage(n)}function Pe(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Vt(t);return I._fromStorage(e)}function Qo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Zr(t);return I._fromStorage(e)}function Xo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Pt(t);return I._fromStorage(e)}function Ko(r,t,e=0){return Ft(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function ra(r,t,e=0){return nr(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function ta(r,t){return qt(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function ea(r,t){return Lt(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function na(r,t){let e=jt(r.storage,t);return I._fromStorage(e)}function oa(r,t,e){return r.repeat(t,e)}function aa(r){return r.ravel()}function sa(r,t){return r.reshape(...t)}function ia(r,t){return r.squeeze(t)}function ua(r,t){return r.expand_dims(t)}function Jr(r,t){let e=Wt(r.storage,t);return I._fromStorage(e)}function ca(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Jr(r,1)}function fa(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Jr(r,0)}function la(r,t=1,e=[0,1]){let n=Ht(r.storage,t,e);return I._fromStorage(n)}function pa(r,t,e){let n=Yt(r.storage,t,e);return I._fromStorage(n)}function ma(r,t,e=0){let n=Gt(r.storage,t,e);return I._fromStorage(n,r.base??r)}function ya(...r){let t=r.map(o=>o.storage),n=Kt(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function da(...r){let t=r.map(o=>o.storage),n=re(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function ga(...r){let t=r.map(o=>o.storage),n=te(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function ha(r,t){return Jt(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function Aa(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Qt(t);return I._fromStorage(e)}function ba(r){return Pe(r)}function Sa(r,t){let e=Xt(r.storage,t);return I._fromStorage(e)}function Da(r,t,e){let n=t instanceof I?t:C(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return J([o,a])}return J([r,n],e)}function Na(r,t,e){let n=r.dtype;if(e===void 0){let p=r.flatten(),d=(Array.isArray(t)?t:[t]).map(S=>S<0?p.size+S:S),g=[];for(let S=0;S<p.size;S++)d.includes(S)||g.push(S);let A=_(n),h=new A(g.length);for(let S=0;S<g.length;S++){let w=p.get([g[S]]);N(n)?h[S]=typeof w=="bigint"?w:BigInt(w):h[S]=w}let b=D.fromData(h,[g.length],n);return new I(b)}let o=r.shape,a=o.length,i=e<0?a+e:e;if(i<0||i>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let s=o[i],u=Array.isArray(t)?t:[t],c=new Set(u.map(p=>p<0?s+p:p)),l=[],m=0;for(let p=0;p<=s;p++)(c.has(p)||p===s)&&(p>m&&l.push([m,p]),m=p+1);if(l.length===0){let p=[...o];return p[i]=0,R(p,n)}let f=[];for(let[p,y]of l){let d=o.map(()=>":");d[i]=`${p}:${y}`,f.push(r.slice(...d))}return J(f,i)}function wa(r,t,e,n){let o=e instanceof I?e:C(e,r.dtype);if(n===void 0){let m=r.flatten(),f=o.flatten(),p=t<0?m.size+t:t;if(p<0||p>m.size)throw new Error(`index ${t} is out of bounds for array of size ${m.size}`);let y=p>0?m.slice(`0:${p}`):null,d=p<m.size?m.slice(`${p}:`):null,g=[];return y&&g.push(y),g.push(f),d&&g.push(d),J(g)}let a=r.shape,i=a.length,s=n<0?i+n:n;if(s<0||s>=i)throw new Error(`axis ${n} is out of bounds for array of dimension ${i}`);let u=a[s],c=t<0?u+t:t;if(c<0||c>u)throw new Error(`index ${t} is out of bounds for axis ${n} with size ${u}`);let l=[];if(c>0){let m=a.map(()=>":");m[s]=`0:${c}`,l.push(r.slice(...m))}if(l.push(o),c<u){let m=a.map(()=>":");m[s]=`${c}:`,l.push(r.slice(...m))}return J(l,s)}function xa(r,t,e="constant",n=0){let o=r.shape,a=o.length,i=r.dtype,s;if(typeof t=="number"?s=o.map(()=>[t,t]):Array.isArray(t)&&typeof t[0]=="number"?s=o.map(()=>t):s=t,s.length!==a)throw new Error(`pad_width must have ${a} elements`);let u=o.map((d,g)=>d+s[g][0]+s[g][1]),c=u.reduce((d,g)=>d*g,1),l=_(i),m=new l(c),f=N(i);e==="constant"&&(f?m.fill(BigInt(n)):m.fill(n));let p=new Array(a).fill(0);for(let d=0;d<c;d++){let g=!0,A=[];for(let b=0;b<a;b++){let[S]=s[b],w=p[b]-S;if(w<0||w>=o[b]){g=!1;break}A.push(w)}let h;if(g)h=r.get(A);else if(e==="constant"){for(let b=a-1;b>=0&&(p[b]++,!(p[b]<u[b]));b--)p[b]=0;continue}else{let b=[];for(let S=0;S<a;S++){let[w]=s[S],x=p[S]-w,z=o[S];x<0?e==="edge"?x=0:e==="reflect"?(x=-x,x>=z&&(x=z-1)):e==="symmetric"?(x=-x-1,x>=z&&(x=z-1),x<0&&(x=0)):e==="wrap"&&(x=(x%z+z)%z):x>=z&&(e==="edge"?x=z-1:e==="reflect"?(x=2*z-x-2,x<0&&(x=0)):e==="symmetric"?(x=2*z-x-1,x<0&&(x=0)):e==="wrap"&&(x=x%z)),b.push(Math.max(0,Math.min(z-1,x)))}h=r.get(b)}f?m[d]=typeof h=="bigint"?h:BigInt(Number(h)):m[d]=Number(h);for(let b=a-1;b>=0&&(p[b]++,!(p[b]<u[b]));b--)p[b]=0}let y=D.fromData(m,u,i);return new I(y)}function Ia(r,t){let e=Gr(r.storage,t);return I._fromStorage(e,r.base??r)}function za(...r){let t=r.map(n=>n.storage);return _e(t).map((n,o)=>I._fromStorage(n,r[o].base??r[o]))}function Ba(...r){return _r(...r)}function _a(r,t,e){return r.take(t,e)}function Ea(r,t,e){r.put(t,e)}function Ua(r,t){let e=t.map(o=>o.storage),n=Te(r.storage,e);return I._fromStorage(n)}function Ta(r,t,e=!1){return Oe(r.storage,t.storage,e)}function Oa(r,t){return $t(r.storage,t.storage)}function $a(r,t){return I._fromStorage(Cr(r.storage,t))}function va(r,t){return I._fromStorage(kr(r.storage,t))}function Ma(r,t,e=!1){let n=Vr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ca(r,t,e=!1){let n=Pr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function ka(r,t,e,n=!1){let o=Fr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Va(r,t,e,n=!1){let o=G(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Pa(r,t,e,n=!1){let o=e?e.storage:void 0,a=mr(r.storage,t,o,n);return typeof a=="number"?a:I._fromStorage(a)}function Fa(r,t,e=!1){let n=yr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ra(r,t,e=!1){let n=dr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function qa(r,t,e=!1){let n=gr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function La(r,t,e=0,n=!1){let o=K(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function ja(r,t,e=0,n=!1){let o=Rr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Za(r,t,e=!1){let n=hr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Wa(r,t,e=!1){let n=Ar(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ha(r,t){let e=br(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function Ya(r,t){let e=Sr(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function Ga(r,t){return I._fromStorage(qr(r.storage,t))}function Ja(r,t){return I._fromStorage(Lr(r.storage,t))}function Qa(r,t,e=!1){let n=Dr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Xa(r){return r.cbrt()}function Ka(r){return r.fabs()}function rs(r,t){return r.divmod(t)}function ts(r){return r.square()}function es(r,t){return r.remainder(t)}function ns(r,t){return r.heaviside(t)}function os(r,...t){let e=t.map(o=>o.storage),n=ue(r,...e);return typeof n=="number"||typeof n=="bigint"?n:I._fromStorage(n)}var or=new Uint8Array([147,78,85,77,80,89]),Qr=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];function Xr(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}var as={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},xr={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},Fe={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};function Re(r){if(r.startsWith("[")||r.startsWith("("))throw new q(`Structured/compound dtypes are not supported: ${r}`);let t="",e=r;(r[0]==="<"||r[0]===">"||r[0]==="="||r[0]==="|")&&(t=r[0],e=r.slice(1));let n=e[0];if(n&&n in Fe)throw new q(`Unsupported dtype: ${Fe[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=as[e];if(!o)throw new q(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Qr.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Xr(),i=t==="<"||t==="|"||t==="="&&a,s=t===">"||t==="="&&!a,u=parseInt(e.slice(1),10),c=u>1&&(s&&a||i&&!a);return{dtype:o,needsByteSwap:c,itemsize:u}}var q=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},k=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}};function Ir(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Kr(t);return rt(t,e)}function Kr(r){if(r.length<10)throw new k("File too small to be a valid NPY file");for(let c=0;c<or.length;c++)if(r[c]!==or[c])throw new k("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new k(`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 k("File truncated: header extends beyond file");let i=r.slice(o,a),s=new TextDecoder("utf-8").decode(i).trim(),u=ss(s);return{version:{major:t,minor:e},header:u,dataOffset:a}}function rt(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:i}=Re(e.descr),s=e.shape.reduce((d,g)=>d*g,1),u=s*i,c=r.length-n;if(c<u)throw new k(`File truncated: expected ${u} bytes of data, got ${c}`);let l=new ArrayBuffer(u);new Uint8Array(l).set(r.subarray(n,n+u));let f=is(l,o,s,a,i),p=e.shape,y;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),g=D.fromData(f,d,o);y=us(g,d),p=e.shape}else y=D.fromData(f,[...p],o);return new I(y)}function ss(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 k(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",i=n[1].trim(),s;return i===""?s=[]:s=i.split(",").map(u=>u.trim()).filter(u=>u!=="").map(u=>{let c=parseInt(u,10);if(isNaN(c))throw new k(`Invalid shape value: ${u}`);return c}),{descr:o,fortran_order:a,shape:s}}function is(r,t,e,n,o){let a=_(t);if(!a)throw new k(`Cannot create array for dtype: ${t}`);if(!n)return new a(r,0,e);let i=new Uint8Array(r),s=new Uint8Array(r.byteLength);for(let u=0;u<e;u++){let c=u*o;for(let l=0;l<o;l++)s[c+l]=i[c+o-1-l]}return new a(s.buffer,0,e)}function us(r,t){let e=t.length,n=r.size,o=r.dtype,a=_(o);if(!a)throw new k(`Cannot create array for dtype: ${o}`);let i=new a(n),s=[...t].reverse(),u=qe(t),c=qe(s),l=new Array(e).fill(0);for(let m=0;m<n;m++){let f=m;for(let y=0;y<e;y++){let d=u[y];l[y]=Math.floor(f/d),f=f%d}let p=0;for(let y=0;y<e;y++)p+=l[e-1-y]*c[y];N(o),i[p]=r.iget(m)}return D.fromData(i,s,o)}function qe(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 ar(r){let t=r.shape,e=r.dtype,n=xr[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,i=12,u=(64-(i+a.length+1)%64)%64;a=a+" ".repeat(u)+`
2
- `;let c=new TextEncoder().encode(a),l=c.length,m=r.size,f=ct(e),p=m*f,y=i+l+p,d=new Uint8Array(y);d.set(or,0),d[6]=3,d[7]=0,d[8]=l&255,d[9]=l>>8&255,d[10]=l>>16&255,d[11]=l>>24&255,d.set(c,i);let g=i+l;return cs(r,d.subarray(g),f),d}function cs(r,t,e){let n=r.dtype,o=r.size,a=Xr(),i=N(n),s=r._storage;if(s.isCContiguous&&s.offset===0&&a){let c=s.data,l=new Uint8Array(c.buffer,c.byteOffset,o*e);t.set(l)}else{let c=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let l=0;l<o;l++){let m=s.iget(l),f=l*e;i?fs(c,f,m,n==="uint64"):ls(c,f,m,n)}}}function fs(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function ls(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 ps=(()=>{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 tt(r){let t=4294967295;for(let e=0;e<r.length;e++)t=ps[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}async function Le(r){let t=Ze(r),e=new Map;for(let n of t){let o=await ms(n);e.set(n.name,o)}return e}function je(r){let t=Ze(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 Ze(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=[],o=-1;for(let c=t.length-22;c>=0;c--)if(e.getUint32(c,!0)===101010256){o=c;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),i=e.getUint16(o+10,!0),s=[],u=a;for(let c=0;c<i&&e.getUint32(u,!0)===33639248;c++){let m=e.getUint16(u+10,!0),f=e.getUint32(u+16,!0),p=e.getUint32(u+20,!0),y=e.getUint32(u+24,!0),d=e.getUint16(u+28,!0),g=e.getUint16(u+30,!0),A=e.getUint16(u+32,!0),h=e.getUint32(u+42,!0),b=t.slice(u+46,u+46+d),S=new TextDecoder("utf-8").decode(b);s.push({name:S,compressionMethod:m,crc32:f,compressedSize:p,uncompressedSize:y,localHeaderOffset:h}),u=u+46+d+g+A}for(let c of s){let l=c.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let f=e.getUint16(l+26,!0),p=e.getUint16(l+28,!0),y=l+30+f+p,d=t.slice(y,y+c.compressedSize);n.push({name:c.name,compressedData:d,compressionMethod:c.compressionMethod,crc32:c.crc32,compressedSize:c.compressedSize,uncompressedSize:c.uncompressedSize})}return n}async function ms(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await ys(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function ys(r){if(typeof DecompressionStream>"u")throw new Error("DecompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new DecompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let i=a.reduce((c,l)=>c+l.length,0),s=new Uint8Array(i),u=0;for(let c of a)s.set(c,u),u+=c.length;return s}async function ot(r,t={}){let e=t.force??!1,n=await Le(r);return We(n,e)}function at(r,t={}){let e=t.force??!1,n=je(r);return We(n,e)}function We(r,t){let e=new Map,n=[],o=new Map;for(let[a,i]of r){if(!a.endsWith(".npy"))continue;let s=a.slice(0,-4);try{let u=Ir(i);e.set(s,u)}catch(u){if(u instanceof q&&t)n.push(s),o.set(s,u.message);else throw u}}return{arrays:e,skipped:n,errors:o}}async function He(r,t={}){let e=await ot(r,t);return Object.fromEntries(e.arrays)}function Ye(r,t={}){let e=at(r,t);return Object.fromEntries(e.arrays)}async function Ge(r,t={}){let e=t.compress??!1,n=[];for(let[f,p]of r){let y=tt(p),d,g;e?(d=await gs(p),d.length<p.length?g=8:(d=p,g=0)):(d=p,g=0),n.push({name:f,data:p,compressedData:d,crc:y,compressionMethod:g,offset:0})}let o=0;for(let f of n){let p=new TextEncoder().encode(f.name);o+=30+p.length+f.compressedData.length}let a=0;for(let f of n){let p=new TextEncoder().encode(f.name);a+=46+p.length}let s=o+a+22,u=new Uint8Array(s),c=new DataView(u.buffer),l=0;for(let f of n)f.offset=l,l=Qe(u,c,l,f);let m=l;for(let f of n)l=Xe(u,c,l,f);return Ke(c,l,n.length,a,m),u}function Je(r){let t=[];for(let[l,m]of r){let f=tt(m);t.push({name:l,data:m,compressedData:m,crc:f,compressionMethod:0,offset:0})}let e=0;for(let l of t){let m=new TextEncoder().encode(l.name);e+=30+m.length+l.compressedData.length}let n=0;for(let l of t){let m=new TextEncoder().encode(l.name);n+=46+m.length}let a=e+n+22,i=new Uint8Array(a),s=new DataView(i.buffer),u=0;for(let l of t)l.offset=u,u=Qe(i,s,u,l);let c=u;for(let l of t)u=Xe(i,s,u,l);return Ke(s,u,t.length,n,c),i}function Qe(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 Xe(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 Ke(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 gs(r){if(typeof CompressionStream>"u")throw new Error("CompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new CompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let i=a.reduce((c,l)=>c+l.length,0),s=new Uint8Array(i),u=0;for(let c of a)s.set(c,u),u+=c.length;return s}async function rn(r,t={}){let e=en(r);return Ge(e,{compress:t.compress??!1})}function tn(r){let t=en(r);return Je(t)}function en(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=ar(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=ar(o),i=n.endsWith(".npy")?n:`${n}.npy`;t.set(i,a)}return t}var _i="0.6.0";export{xr as DTYPE_TO_DESCR,k as InvalidNpyError,I as NDArray,Qr as SUPPORTED_DTYPES,q as UnsupportedDTypeError,_i as __version__,yo as absolute,Da as append,Rn as arange,vo as arccos,Wo as arccosh,$o as arcsin,Zo as arcsinh,Mo as arctan,Co as arctan2,Ho as arctanh,C as array,Ta as array_equal,Oa as array_equiv,ra as array_split,Qn as asanyarray,wr as asarray,Xn as ascontiguousarray,Kn as asfortranarray,ya as atleast_1d,da as atleast_2d,ga as atleast_3d,Pa as average,za as broadcast_arrays,Ba as broadcast_shapes,Ia as broadcast_to,Xa as cbrt,Ua as choose,Aa as column_stack,J as concatenate,Wn as copy,To as cos,Lo as cosh,va as cumprod,$a as cumsum,Fo as deg2rad,Vo as degrees,Na as delete,Ve as diag,ro as diagflat,xo as diagonal,rs as divmod,No as dot,ha as dsplit,Xo as dstack,os as einsum,Ce as empty,Gn as empty_like,ua as expand_dims,Me as eye,Ka as fabs,Jr as flip,ca as fliplr,fa as flipud,bo as floor_divide,io as frombuffer,uo as fromfile,to as fromfunction,co as fromiter,fo as fromstring,ke as full,Jn as full_like,jn as geomspace,ns as heaviside,ea as hsplit,Qo as hstack,ko as hypot,Zn as identity,Bo as inner,wa as insert,Io as kron,qn as linspace,He as loadNpz,Ye as loadNpzSync,Ln as logspace,Ca as median,eo as meshgrid,Ao as mod,Go as moveaxis,Ya as nanargmax,Ha as nanargmin,Ja as nancumprod,Ga as nancumsum,Wa as nanmax,qa as nanmean,Qa as nanmedian,Za as nanmin,Ra as nanprod,ja as nanstd,Fa as nansum,La as nanvar,go as negative,$e as ones,Yn as ones_like,_o as outer,xa as pad,Ir as parseNpy,rt as parseNpyData,Kr as parseNpyHeader,ot as parseNpz,at as parseNpzSync,ka as percentile,So as positive,mo as power,Ma as ptp,Ea as put,Va as quantile,Ro as rad2deg,Po as radians,aa as ravel,Do as reciprocal,es as remainder,oa as repeat,sa as reshape,Sa as resize,pa as roll,ma as rollaxis,la as rot90,ba as row_stack,ar as serializeNpy,rn as serializeNpz,tn as serializeNpzSync,ho as sign,Uo as sin,qo as sinh,Ko as split,po as sqrt,ts as square,ia as squeeze,Jo as stack,Yo as swapaxes,_a as take,Oo as tan,jo as tanh,Eo as tensordot,na as tile,wo as trace,zo as transpose,no as tri,oo as tril,ao as triu,so as vander,ta as vsplit,Pe as vstack,R as zeros,Hn as zeros_like};
1
+ function bt(t){if(!t.includes(":")){if(t.includes("."))throw new Error(`Invalid slice index: "${t}" (must be integer)`);let a=parseInt(t,10);if(isNaN(a))throw new Error(`Invalid slice index: "${t}"`);return{start:a,stop:null,step:1,isIndex:!0}}let r=t.split(":");if(r.length>3)throw new Error(`Invalid slice notation: "${t}" (too many colons)`);let e=r[0]===""?null:parseInt(r[0],10),n=r[1]===""||r[1]===void 0?null:parseInt(r[1],10),o=r[2]===""||r[2]===void 0?1:parseInt(r[2],10);if(e!==null&&isNaN(e))throw new Error(`Invalid start index in slice: "${t}"`);if(n!==null&&isNaN(n))throw new Error(`Invalid stop index in slice: "${t}"`);if(isNaN(o))throw new Error(`Invalid step in slice: "${t}"`);if(o===0)throw new Error("Slice step cannot be zero");return{start:e,stop:n,step:o,isIndex:!1}}function St(t,r){let{start:e,stop:n}=t,{step:o,isIndex:a}=t;if(a){if(e===null)throw new Error("Index cannot be null");let u=e<0?r+e:e;if(u<0||u>=r)throw new Error(`Index ${e} is out of bounds for size ${r}`);return{start:u,stop:u+1,step:1,isIndex:!0}}return o>0?(e===null&&(e=0),n===null&&(n=r)):(e===null&&(e=r-1),n===null&&(n=-r-1)),e<0&&(e=r+e),n<0&&(n=r+n),e=Math.max(0,Math.min(e,r)),n=Math.max(-1,Math.min(n,r)),{start:e,stop:n,step:o,isIndex:!1}}var M="float64";function U(t){switch(t){case"float64":return Float64Array;case"float32":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${t}`)}}function Nt(t){switch(t){case"float64":case"int64":case"uint64":return 8;case"float32":case"int32":case"uint32":return 4;case"int16":case"uint16":return 2;case"int8":case"uint8":case"bool":return 1;default:throw new Error(`Unknown dtype: ${t}`)}}function wt(t){return t==="int64"||t==="int32"||t==="int16"||t==="int8"||t==="uint64"||t==="uint32"||t==="uint16"||t==="uint8"}function Dt(t){return t==="float64"||t==="float32"}function w(t){return t==="int64"||t==="uint64"}function v(t,r){if(t===r)return t;if(t==="bool")return r;if(r==="bool")return t;if(Dt(t)||Dt(r)){if(t==="float64"||r==="float64")return"float64";if(t==="float32"){let c=r;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}if(r==="float32"){let c=t;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}return"float32"}let e=t.startsWith("int"),n=r.startsWith("int"),o=t.startsWith("uint"),a=r.startsWith("uint"),u=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,s=u(t),i=u(r);if(t==="int64"&&r==="uint64"||t==="uint64"&&r==="int64")return"float64";if(e&&a&&s===i){if(s===8)return"int16";if(s===16)return"int32";if(s===32)return"int64"}if(o&&n&&s===i){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(e&&n||o&&a){let c=Math.max(s,i);return e?c===64?"int64":c===32?"int32":c===16?"int16":"int8":c===64?"uint64":c===32?"uint32":c===16?"uint16":"uint8"}return e&&a?s>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":o&&n?i>s?r:s===8?"int16":s===16?"int32":s===32?"int64":"float64":"float64"}var D=class t{constructor(r,e,n,o,a){this._data=r,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((r,e)=>r*e,1)}get dtype(){return this._dtype}get data(){return this._data}get strides(){return this._strides}get offset(){return this._offset}get isCContiguous(){let r=this._shape,e=this._strides,n=r.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=n-1;a>=0;a--){if(e[a]!==o)return!1;o*=r[a]}return!0}get isFContiguous(){let r=this._shape,e=this._strides,n=r.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*=r[a]}return!0}iget(r){let e=this._shape,n=this._strides,o=e.length;if(o===0)return this._data[this._offset];let a=r,u=this._offset;for(let s=0;s<o;s++){let i=1;for(let f=s+1;f<o;f++)i*=e[f];let c=Math.floor(a/i);a=a%i,u+=c*n[s]}return this._data[u]}iset(r,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let u=r,s=this._offset;for(let i=0;i<a;i++){let c=1;for(let y=i+1;y<a;y++)c*=n[y];let f=Math.floor(u/c);u=u%c,s+=f*o[i]}this._data[s]=e}get(...r){let e=this._strides,n=this._offset;for(let o=0;o<r.length;o++)n+=r[o]*e[o];return this._data[n]}set(r,e){let n=this._strides,o=this._offset;for(let a=0;a<r.length;a++)o+=r[a]*n[a];this._data[o]=e}copy(){let r=Array.from(this._shape),e=this._dtype,n=this.size,o=U(e);if(!o)throw new Error(`Cannot copy array with dtype ${e}`);let a=new o(n);if(this.isCContiguous&&this._offset===0)if(w(e)){let u=this._data,s=a;for(let i=0;i<n;i++)s[i]=u[i]}else a.set(this._data);else if(w(e)){let u=a;for(let s=0;s<n;s++)u[s]=this.iget(s)}else for(let u=0;u<n;u++)a[u]=this.iget(u);return new t(a,r,t._computeStrides(r),0,e)}static fromData(r,e,n,o,a){let u=o??t._computeStrides(e),s=a??0;return new t(r,e,u,s,n)}static zeros(r,e=M){let n=r.reduce((u,s)=>u*s,1),o=U(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return new t(a,r,t._computeStrides(r),0,e)}static ones(r,e=M){let n=r.reduce((u,s)=>u*s,1),o=U(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return w(e)?a.fill(BigInt(1)):a.fill(1),new t(a,r,t._computeStrides(r),0,e)}static _computeStrides(r){let e=new Array(r.length),n=1;for(let o=r.length-1;o>=0;o--)e[o]=n,n*=r[o];return e}};function P(t){let r=new Array(t.length),e=1;for(let n=t.length-1;n>=0;n--)r[n]=e,e*=t[n];return r}function xt(t,r){let e=t.length,n=r.length,o=Math.max(e,n),a=new Array(o);for(let u=0;u<o;u++){let s=u<o-e?1:t[u-(o-e)],i=u<o-n?1:r[u-(o-n)];if(s===i)a[u]=s;else if(s===1)a[u]=i;else if(i===1)a[u]=s;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(t))} ${JSON.stringify(Array.from(r))}`)}return a}function Ln(t,r,e){let n=t.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let s=o-n+u,i=t[u],c=e[s];if(i===c)a[s]=r[u];else if(i===1)a[s]=0;else throw new Error("Invalid broadcast")}return a}function mr(t,r){let e=Ln(t.shape,t.strides,r);return D.fromData(t.data,Array.from(r),t.dtype,e,t.offset)}function V(t,r,e,n){let o=xt(t.shape,r.shape),a=mr(t,o),u=mr(r,o),s=v(t.dtype,r.dtype),i=D.zeros(o,s),c=i.data,f=i.size;if(w(s)){let y=c;for(let l=0;l<f;l++){let p=a.iget(l),m=u.iget(l),d=typeof p=="bigint"?p:BigInt(Math.round(p)),g=typeof m=="bigint"?m:BigInt(Math.round(m));n==="add"?y[l]=d+g:n==="subtract"?y[l]=d-g:n==="multiply"?y[l]=d*g:n==="divide"?y[l]=d/g:y[l]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let y=w(t.dtype)||w(r.dtype);for(let l=0;l<f;l++){let p=a.iget(l),m=u.iget(l),d=Number(p),g=Number(m);c[l]=e(d,g)}}return i}function G(t,r,e){let n=xt(t.shape,r.shape),o=mr(t,n),a=mr(r,n),u=n.reduce((c,f)=>c*f,1),s=new Uint8Array(u),i=w(t.dtype)||w(r.dtype);for(let c=0;c<u;c++){let f=o.iget(c),y=a.iget(c),l=Number(f),p=Number(y);s[c]=e(l,p)?1:0}return D.fromData(s,n,"bool")}function k(t,r,e=!0){let n=t.dtype,o=Array.from(t.shape),a=t.size,s=e?n:n!=="float32"&&n!=="float64"?"float64":n,i=D.zeros(o,s),c=i.data,f=t.data;if(w(n))if(w(s)){let y=c;for(let l=0;l<a;l++){let p=Number(f[l]);y[l]=BigInt(Math.round(r(p)))}}else for(let y=0;y<a;y++)c[y]=r(Number(f[y]));else for(let y=0;y<a;y++)c[y]=r(Number(f[y]));return i}function Mr(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((e,n)=>e===r.shape[n])}function It(t,r){return typeof r=="number"?Wn(t,r):Mr(t,r)?qn(t,r):V(t,r,(e,n)=>e+n,"add")}function qn(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;if(!w(t.dtype)||!w(r.dtype))for(let f=0;f<o;f++){let y=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof u[f]=="bigint"?u[f]:BigInt(Math.round(Number(u[f])));i[f]=y+l}else{let f=a,y=u;for(let l=0;l<o;l++)i[l]=f[l]+y[l]}}else if(w(t.dtype)||w(r.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],y=typeof u[c]=="bigint"?Number(u[c]):u[c];s[c]=f+y}else for(let c=0;c<o;c++)s[c]=a[c]+u[c];return n}function zt(t,r){return typeof r=="number"?Hn(t,r):Mr(t,r)?jn(t,r):V(t,r,(e,n)=>e-n,"subtract")}function jn(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;if(!w(t.dtype)||!w(r.dtype))for(let f=0;f<o;f++){let y=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof u[f]=="bigint"?u[f]:BigInt(Math.round(Number(u[f])));i[f]=y-l}else{let f=a,y=u;for(let l=0;l<o;l++)i[l]=f[l]-y[l]}}else if(w(t.dtype)||w(r.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],y=typeof u[c]=="bigint"?Number(u[c]):u[c];s[c]=f-y}else for(let c=0;c<o;c++)s[c]=a[c]-u[c];return n}function _t(t,r){return typeof r=="number"?Yn(t,r):Mr(t,r)?Zn(t,r):V(t,r,(e,n)=>e*n,"multiply")}function Zn(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;if(!w(t.dtype)||!w(r.dtype))for(let f=0;f<o;f++){let y=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof u[f]=="bigint"?u[f]:BigInt(Math.round(Number(u[f])));i[f]=y*l}else{let f=a,y=u;for(let l=0;l<o;l++)i[l]=f[l]*y[l]}}else if(w(t.dtype)||w(r.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],y=typeof u[c]=="bigint"?Number(u[c]):u[c];s[c]=f*y}else for(let c=0;c<o;c++)s[c]=a[c]*u[c];return n}function Bt(t,r){if(typeof r=="number")return Gn(t,r);let e=t.dtype==="float64",n=r.dtype==="float64",o=t.dtype==="float32",a=r.dtype==="float32";if(e||n){let i=e?t:rr(t,"float64"),c=n?r:rr(r,"float64");return V(i,c,(f,y)=>f/y,"divide")}if(o||a){let i=o?t:rr(t,"float32"),c=a?r:rr(r,"float32");return V(i,c,(f,y)=>f/y,"divide")}let u=rr(t,"float64"),s=rr(r,"float64");return V(u,s,(i,c)=>i/c,"divide")}function rr(t,r){let e=D.zeros(Array.from(t.shape),r),n=t.size,o=t.data,a=e.data;for(let u=0;u<n;u++)a[u]=Number(o[u]);return e}function Wn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]+f}else for(let i=0;i<a;i++)s[i]=Number(o[i])+r;return u}function Hn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]-f}else for(let i=0;i<a;i++)s[i]=Number(o[i])-r;return u}function Yn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]*f}else for(let i=0;i<a;i++)s[i]=Number(o[i])*r;return u}function Gn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,s=e!=="float32"&&e!=="float64"?"float64":e,i=D.zeros(n,s),c=i.data;if(w(e))for(let f=0;f<a;f++)c[f]=Number(o[f])/r;else for(let f=0;f<a;f++)c[f]=Number(o[f])/r;return i}function Et(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=D.zeros(e,r),u=a.data;if(w(r)){let s=n,i=u;for(let c=0;c<o;c++){let f=s[c];i[c]=f<0n?-f:f}}else for(let s=0;s<o;s++)u[s]=Math.abs(Number(n[s]));return a}function Ut(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=D.zeros(e,r),u=a.data;if(w(r)){let s=n,i=u;for(let c=0;c<o;c++)i[c]=-s[c]}else for(let s=0;s<o;s++)u[s]=-Number(n[s]);return a}function Tt(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=D.zeros(e,r),u=a.data;if(w(r)){let s=n,i=u;for(let c=0;c<o;c++){let f=s[c];i[c]=f>0n?1n:f<0n?-1n:0n}}else for(let s=0;s<o;s++){let i=Number(n[s]);u[s]=i>0?1:i<0?-1:0}return a}function dr(t,r){return typeof r=="number"?Jn(t,r):V(t,r,(e,n)=>(e%n+n)%n,"mod")}function Jn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++){let l=i[y];c[y]=(l%f+f)%f}}else for(let i=0;i<a;i++){let c=Number(o[i]);s[i]=(c%r+r)%r}return u}function Cr(t,r){return typeof r=="number"?Xn(t,r):V(t,r,(e,n)=>Math.floor(e/n),"floor_divide")}function Xn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]/f}else for(let i=0;i<a;i++)s[i]=Math.floor(Number(o[i])/r);return u}function Ot(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=D.zeros(e,r),u=a.data;for(let s=0;s<o;s++)u[s]=n[s];return a}function $t(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,u=r!=="float32"&&r!=="float64"?"float64":r,s=D.zeros(e,u),i=s.data;if(w(r))for(let c=0;c<o;c++)i[c]=1/Number(n[c]);else for(let c=0;c<o;c++)i[c]=1/Number(n[c]);return s}function vt(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,u=r!=="float32"&&r!=="float64"?"float64":r,s=D.zeros(e,u),i=s.data;for(let c=0;c<o;c++)i[c]=Math.cbrt(Number(n[c]));return s}function Mt(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=r==="float32"?"float32":"float64",u=D.zeros(e,a),s=u.data;for(let i=0;i<o;i++)s[i]=Math.abs(Number(n[i]));return u}function Ct(t,r){let e=Cr(t,r),n=dr(t,r);return[e,n]}function kt(t){let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=D.zeros(e,r),u=a.data;if(w(r)){let s=n,i=u;for(let c=0;c<o;c++)i[c]=s[c]*s[c]}else for(let s=0;s<o;s++){let i=Number(n[s]);u[s]=i*i}return a}function Vt(t,r){return dr(t,r)}function Ft(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.size,a=e==="float32"?"float32":"float64",u=D.zeros(n,a),s=u.data;if(typeof r=="number")for(let i=0;i<o;i++){let c=Number(t.data[i]);c<0?s[i]=0:c===0?s[i]=r:s[i]=1}else{let i=r.data,c=r.shape;if(n.every((f,y)=>f===c[y]))for(let f=0;f<o;f++){let y=Number(t.data[f]);y<0?s[f]=0:y===0?s[f]=Number(i[f]):s[f]=1}else for(let f=0;f<o;f++){let y=Number(t.data[f]),l=f%r.size;y<0?s[f]=0:y===0?s[f]=Number(i[l]):s[f]=1}}return u}function J(t){if(t.length===0)return[];if(t.length===1)return Array.from(t[0]);let r=Math.max(...t.map(n=>n.length)),e=new Array(r);for(let n=0;n<r;n++){let o=1;for(let a of t){let u=a.length-r+n,s=u<0?1:a[u];if(s!==1){if(o===1)o=s;else if(o!==s)return null}}e[n]=o}return e}function Kn(t,r,e){let n=t.length,o=e.length,a=new Array(o).fill(0);for(let u=0;u<n;u++){let s=o-n+u,i=t[u],c=e[s];if(i===c)a[s]=r[u];else if(i===1)a[s]=0;else throw new Error("Invalid broadcast")}return a}function Z(t,r){let e=Kn(t.shape,t.strides,r);return D.fromData(t.data,Array.from(r),t.dtype,e,t.offset)}function kr(...t){let r=J(t);if(r===null){let e=t.map(n=>`(${n.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return r}function Pt(t,r){return typeof r=="number"?ro(t,r):G(t,r,(e,n)=>e>n)}function Rt(t,r){return typeof r=="number"?to(t,r):G(t,r,(e,n)=>e>=n)}function Lt(t,r){return typeof r=="number"?eo(t,r):G(t,r,(e,n)=>e<n)}function qt(t,r){return typeof r=="number"?no(t,r):G(t,r,(e,n)=>e<=n)}function jt(t,r){return typeof r=="number"?oo(t,r):G(t,r,(e,n)=>e===n)}function Zt(t,r){return typeof r=="number"?ao(t,r):G(t,r,(e,n)=>e!==n)}function Vr(t,r,e=1e-5,n=1e-8){return typeof r=="number"?so(t,r,e,n):G(t,r,(o,a)=>{let u=Math.abs(o-a),s=n+e*Math.abs(a);return u<=s})}function Wt(t,r,e=1e-5,n=1e-8){let o=Vr(t,r,e,n),a=o.data;for(let u=0;u<o.size;u++)if(a[u]===0)return!1;return!0}function Ht(t,r){let e=[Array.from(t.shape),Array.from(r.shape)],n=J(e);if(n===null)return!1;let o=Z(t,n),a=Z(r,n),u=n.length,s=n.reduce((f,y)=>f*y,1),i=w(o.dtype),c=w(a.dtype);for(let f=0;f<s;f++){let y=f,l=new Array(u);for(let d=u-1;d>=0;d--)l[d]=y%n[d],y=Math.floor(y/n[d]);let p=o.get(...l),m=a.get(...l);if(i||c){let d=typeof p=="bigint"?p:BigInt(Number(p)),g=typeof m=="bigint"?m:BigInt(Number(m));if(d!==g)return!1}else if(p!==m)return!1}return!0}function ro(t,r){let e=new Uint8Array(t.size),n=t.data;for(let o=0;o<t.size;o++)e[o]=n[o]>r?1:0;return D.fromData(e,Array.from(t.shape),"bool")}function to(t,r){let e=new Uint8Array(t.size),n=t.data;for(let o=0;o<t.size;o++)e[o]=n[o]>=r?1:0;return D.fromData(e,Array.from(t.shape),"bool")}function eo(t,r){let e=new Uint8Array(t.size),n=t.data;for(let o=0;o<t.size;o++)e[o]=n[o]<r?1:0;return D.fromData(e,Array.from(t.shape),"bool")}function no(t,r){let e=new Uint8Array(t.size),n=t.data;for(let o=0;o<t.size;o++)e[o]=n[o]<=r?1:0;return D.fromData(e,Array.from(t.shape),"bool")}function oo(t,r){let e=new Uint8Array(t.size),n=t.data,o=t.dtype;if(w(o)){let a=BigInt(Math.round(r)),u=n;for(let s=0;s<t.size;s++)e[s]=u[s]===a?1:0}else for(let a=0;a<t.size;a++)e[a]=n[a]===r?1:0;return D.fromData(e,Array.from(t.shape),"bool")}function ao(t,r){let e=new Uint8Array(t.size),n=t.data;for(let o=0;o<t.size;o++)e[o]=n[o]!==r?1:0;return D.fromData(e,Array.from(t.shape),"bool")}function so(t,r,e,n){let o=new Uint8Array(t.size),a=t.data,u=t.dtype;if(w(u)){let s=a;for(let i=0;i<t.size;i++){let c=Number(s[i]),f=Math.abs(c-r),y=n+e*Math.abs(r);o[i]=f<=y?1:0}}else for(let s=0;s<t.size;s++){let i=Number(a[s]),c=Math.abs(i-r),f=n+e*Math.abs(r);o[s]=c<=f?1:0}return D.fromData(o,Array.from(t.shape),"bool")}function O(t,r){let e=0,n=1;for(let o=t.length-1;o>=0;o--)e+=t[o]*n,n*=r[o];return e}function $(t,r,e,n){let o=n.length,a=new Array(o),u=Array.from(n).filter((i,c)=>c!==r),s=t;for(let i=u.length-1;i>=0;i--)a[i>=r?i+1:i]=s%u[i],s=Math.floor(s/u[i]);return a[r]=e,a}function or(t,r,e=!1){let n=t.dtype,o=t.shape,a=o.length,u=t.size,s=t.data;if(r===void 0)if(w(n)){let m=s,d=BigInt(0);for(let g=0;g<u;g++)d+=m[g];return Number(d)}else{let m=0;for(let d=0;d<u;d++)m+=Number(s[d]);return m}let i=r;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==i);if(c.length===0)return or(t);let f=D.zeros(c,n),y=f.data,l=o[i],p=c.reduce((m,d)=>m*d,1);if(w(n)){let m=s,d=y;for(let g=0;g<p;g++){let h=BigInt(0);for(let A=0;A<l;A++){let b=$(g,i,A,o),S=O(b,o);h+=m[S]}d[g]=h}}else for(let m=0;m<p;m++){let d=0;for(let g=0;g<l;g++){let h=$(m,i,g,o),A=O(h,o);d+=Number(s[A])}y[m]=d}if(e){let m=[...o];return m[i]=1,D.fromData(y,m,n)}return f}function gr(t,r,e=!1){let n=t.dtype,o=t.shape;if(r===void 0)return or(t)/t.size;let a=r;if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error(`axis ${r} is out of bounds for array of dimension ${o.length}`);let u=or(t,r,e);if(typeof u=="number")return u/o[a];let s=o[a],i=n;(w(n)||n.startsWith("int")||n.startsWith("uint"))&&(i="float64");let c=D.zeros(Array.from(u.shape),i),f=c.data,y=u.data;if(w(n)){let l=y;for(let p=0;p<f.length;p++)f[p]=Number(l[p])/s}else for(let l=0;l<f.length;l++)f[l]=Number(y[l])/s;return c}function Ar(t,r,e=!1){let n=t.dtype,o=t.shape,a=o.length,u=t.size,s=t.data;if(r===void 0){if(u===0)throw new Error("max of empty array");let m=s[0];for(let d=1;d<u;d++)s[d]>m&&(m=s[d]);return Number(m)}let i=r;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==i);if(c.length===0)return Ar(t);let f=D.zeros(c,n),y=f.data,l=o[i],p=c.reduce((m,d)=>m*d,1);if(w(n)){let m=s,d=y;for(let g=0;g<p;g++){let h=$(g,i,0,o),A=O(h,o),b=m[A];for(let S=1;S<l;S++){let N=$(g,i,S,o),x=O(N,o),I=m[x];I>b&&(b=I)}d[g]=b}}else for(let m=0;m<p;m++){let d=-1/0;for(let g=0;g<l;g++){let h=$(m,i,g,o),A=O(h,o),b=Number(s[A]);b>d&&(d=b)}y[m]=d}if(e){let m=[...o];return m[i]=1,D.fromData(y,m,n)}return f}function Fr(t,r,e=!1){let n=t.dtype,o=t.shape,a=o.length,u=t.size,s=t.data;if(r===void 0)if(w(n)){let m=s,d=BigInt(1);for(let g=0;g<u;g++)d*=m[g];return Number(d)}else{let m=1;for(let d=0;d<u;d++)m*=Number(s[d]);return m}let i=r;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==i);if(c.length===0)return Fr(t);let f=D.zeros(c,n),y=f.data,l=o[i],p=c.reduce((m,d)=>m*d,1);if(w(n)){let m=s,d=y;for(let g=0;g<p;g++){let h=BigInt(1);for(let A=0;A<l;A++){let b=$(g,i,A,o),S=O(b,o);h*=m[S]}d[g]=h}}else for(let m=0;m<p;m++){let d=1;for(let g=0;g<l;g++){let h=$(m,i,g,o),A=O(h,o);d*=Number(s[A])}y[m]=d}if(e){let m=[...o];return m[i]=1,D.fromData(y,m,n)}return f}function hr(t,r,e=!1){let n=t.dtype,o=t.shape,a=o.length,u=t.size,s=t.data;if(r===void 0){if(u===0)throw new Error("min of empty array");let m=s[0];for(let d=1;d<u;d++)s[d]<m&&(m=s[d]);return Number(m)}let i=r;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==i);if(c.length===0)return hr(t);let f=D.zeros(c,n),y=f.data,l=o[i],p=c.reduce((m,d)=>m*d,1);if(w(n)){let m=s,d=y;for(let g=0;g<p;g++){let h=$(g,i,0,o),A=O(h,o),b=m[A];for(let S=1;S<l;S++){let N=$(g,i,S,o),x=O(N,o),I=m[x];I<b&&(b=I)}d[g]=b}}else for(let m=0;m<p;m++){let d=1/0;for(let g=0;g<l;g++){let h=$(m,i,g,o),A=O(h,o),b=Number(s[A]);b<d&&(d=b)}y[m]=d}if(e){let m=[...o];return m[i]=1,D.fromData(y,m,n)}return f}function Pr(t,r){let e=t.dtype,n=t.shape,o=n.length,a=t.size,u=t.data;if(r===void 0){if(a===0)throw new Error("argmin of empty array");let p=u[0],m=0;for(let d=1;d<a;d++)u[d]<p&&(p=u[d],m=d);return m}let s=r;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((p,m)=>m!==s);if(i.length===0)return Pr(t);let c=D.zeros(i,"int32"),f=c.data,y=n[s],l=i.reduce((p,m)=>p*m,1);if(w(e)){let p=u;for(let m=0;m<l;m++){let d=$(m,s,0,n),g=O(d,n),h=p[g],A=0;for(let b=1;b<y;b++){let S=$(m,s,b,n),N=O(S,n),x=p[N];x<h&&(h=x,A=b)}f[m]=A}}else for(let p=0;p<l;p++){let m=1/0,d=0;for(let g=0;g<y;g++){let h=$(p,s,g,n),A=O(h,n),b=Number(u[A]);b<m&&(m=b,d=g)}f[p]=d}return c}function Rr(t,r){let e=t.dtype,n=t.shape,o=n.length,a=t.size,u=t.data;if(r===void 0){if(a===0)throw new Error("argmax of empty array");let p=u[0],m=0;for(let d=1;d<a;d++)u[d]>p&&(p=u[d],m=d);return m}let s=r;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((p,m)=>m!==s);if(i.length===0)return Rr(t);let c=D.zeros(i,"int32"),f=c.data,y=n[s],l=i.reduce((p,m)=>p*m,1);if(w(e)){let p=u;for(let m=0;m<l;m++){let d=$(m,s,0,n),g=O(d,n),h=p[g],A=0;for(let b=1;b<y;b++){let S=$(m,s,b,n),N=O(S,n),x=p[N];x>h&&(h=x,A=b)}f[m]=A}}else for(let p=0;p<l;p++){let m=-1/0,d=0;for(let g=0;g<y;g++){let h=$(p,s,g,n),A=O(h,n),b=Number(u[A]);b>m&&(m=b,d=g)}f[p]=d}return c}function Lr(t,r,e=0,n=!1){let o=t.shape,a=o.length,u=t.size,s=t.data,i=gr(t,r,n);if(r===void 0){let h=i,A=0;for(let b=0;b<u;b++){let S=Number(s[b])-h;A+=S*S}return A/(u-e)}let c=r;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let f=o[c],y=i,l=y.data,p=n?y.shape:Array.from(o).filter((h,A)=>A!==c),m=D.zeros(Array.from(p),"float64"),d=m.data,g=p.reduce((h,A)=>h*A,1);for(let h=0;h<g;h++){let A=0,b=Number(l[h]);for(let S=0;S<f;S++){let N=$(h,c,S,o),x=O(N,o),I=Number(s[x])-b;A+=I*I}d[h]=A/(f-e)}return m}function Yt(t,r,e=0,n=!1){let o=Lr(t,r,e,n);if(typeof o=="number")return Math.sqrt(o);let a=D.zeros(Array.from(o.shape),"float64"),u=o.data,s=a.data;for(let i=0;i<u.length;i++)s[i]=Math.sqrt(Number(u[i]));return a}function qr(t,r,e=!1){let n=t.shape,o=n.length,a=t.size,u=t.data;if(r===void 0){for(let p=0;p<a;p++)if(!u[p])return!1;return!0}let s=r;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((p,m)=>m!==s);if(i.length===0)return qr(t);let c=D.zeros(i,"bool"),f=c.data,y=n[s],l=i.reduce((p,m)=>p*m,1);for(let p=0;p<l;p++){let m=!0;for(let d=0;d<y;d++){let g=$(p,s,d,n),h=O(g,n);if(!u[h]){m=!1;break}}f[p]=m?1:0}if(e){let p=[...n];return p[s]=1,D.fromData(f,p,"bool")}return c}function jr(t,r,e=!1){let n=t.shape,o=n.length,a=t.size,u=t.data;if(r===void 0){for(let p=0;p<a;p++)if(u[p])return!0;return!1}let s=r;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((p,m)=>m!==s);if(i.length===0)return jr(t);let c=D.zeros(i,"bool"),f=c.data,y=n[s],l=i.reduce((p,m)=>p*m,1);for(let p=0;p<l;p++){let m=!1;for(let d=0;d<y;d++){let g=$(p,s,d,n),h=O(g,n);if(u[h]){m=!0;break}}f[p]=m?1:0}if(e){let p=[...n];return p[s]=1,D.fromData(f,p,"bool")}return c}function Zr(t,r){let e=t.shape,n=e.length,o=t.data;if(r===void 0){let l=t.size,p=new Float64Array(l),m=0;for(let d=0;d<l;d++)m+=Number(o[d]),p[d]=m;return D.fromData(p,[l],"float64")}let a=r;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);let u=new Float64Array(t.size),s=e[a],i=[],c=1;for(let l=n-1;l>=0;l--)i.unshift(c),c*=e[l];let f=t.size,y=i[a];for(let l=0;l<f;l++)Math.floor(l/y)%s===0?u[l]=Number(o[l]):u[l]=u[l-y]+Number(o[l]);return D.fromData(u,[...e],"float64")}function Wr(t,r){let e=t.shape,n=e.length,o=t.data;if(r===void 0){let l=t.size,p=new Float64Array(l),m=1;for(let d=0;d<l;d++)m*=Number(o[d]),p[d]=m;return D.fromData(p,[l],"float64")}let a=r;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);let u=new Float64Array(t.size),s=e[a],i=[],c=1;for(let l=n-1;l>=0;l--)i.unshift(c),c*=e[l];let f=t.size,y=i[a];for(let l=0;l<f;l++)Math.floor(l/y)%s===0?u[l]=Number(o[l]):u[l]=u[l-y]*Number(o[l]);return D.fromData(u,[...e],"float64")}function Hr(t,r,e=!1){let n=Ar(t,r,e),o=hr(t,r,e);if(typeof n=="number"&&typeof o=="number")return n-o;let a=n,u=o,s=a.data,i=u.data,c=new Float64Array(a.size);for(let f=0;f<a.size;f++)c[f]=Number(s[f])-Number(i[f]);return D.fromData(c,[...a.shape],"float64")}function Yr(t,r,e=!1){return tr(t,.5,r,e)}function Gr(t,r,e,n=!1){return tr(t,r/100,e,n)}function tr(t,r,e,n=!1){if(r<0||r>1)throw new Error("Quantile must be between 0 and 1");let o=t.shape,a=o.length,u=t.data;if(e===void 0){let p=[];for(let b=0;b<t.size;b++)p.push(Number(u[b]));p.sort((b,S)=>b-S);let m=p.length,d=r*(m-1),g=Math.floor(d),h=Math.ceil(d);if(g===h)return p[g];let A=d-g;return p[g]*(1-A)+p[h]*A}let s=e;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((p,m)=>m!==s);if(i.length===0)return tr(t,r);let c=i.reduce((p,m)=>p*m,1),f=o[s],y=new Float64Array(c);for(let p=0;p<c;p++){let m=[];for(let b=0;b<f;b++){let S=$(p,s,b,o),N=O(S,o);m.push(Number(u[N]))}m.sort((b,S)=>b-S);let d=m.length,g=r*(d-1),h=Math.floor(g),A=Math.ceil(g);if(h===A)y[p]=m[h];else{let b=g-h;y[p]=m[h]*(1-b)+m[A]*b}}let l=D.fromData(y,i,"float64");if(n){let p=[...o];return p[s]=1,D.fromData(y,p,"float64")}return l}function br(t,r,e,n=!1){let o=t.shape,a=o.length,u=t.data;if(e===void 0)return gr(t,r,n);if(r===void 0){let m=0,d=0,g=e.data;for(let h=0;h<t.size;h++){let A=Number(g[h%e.size]);m+=Number(u[h])*A,d+=A}return d===0?NaN:m/d}let s=r;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((m,d)=>d!==s);if(i.length===0)return br(t,void 0,e);let c=i.reduce((m,d)=>m*d,1),f=o[s],y=e.data,l=new Float64Array(c);for(let m=0;m<c;m++){let d=0,g=0;for(let h=0;h<f;h++){let A=$(m,s,h,o),b=O(A,o),S=Number(y[h%e.size]);d+=Number(u[b])*S,g+=S}l[m]=g===0?NaN:d/g}let p=D.fromData(l,i,"float64");if(n){let m=[...o];return m[s]=1,D.fromData(l,m,"float64")}return p}function Sr(t,r,e=!1){let n=t.shape,o=n.length,a=t.data;if(r===void 0){let l=0;for(let p=0;p<t.size;p++){let m=Number(a[p]);isNaN(m)||(l+=m)}return l}let u=r;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((l,p)=>p!==u);if(s.length===0)return Sr(t);let i=s.reduce((l,p)=>l*p,1),c=n[u],f=new Float64Array(i);for(let l=0;l<i;l++){let p=0;for(let m=0;m<c;m++){let d=$(l,u,m,n),g=O(d,n),h=Number(a[g]);isNaN(h)||(p+=h)}f[l]=p}let y=D.fromData(f,s,"float64");if(e){let l=[...n];return l[u]=1,D.fromData(f,l,"float64")}return y}function Dr(t,r,e=!1){let n=t.shape,o=n.length,a=t.data;if(r===void 0){let l=1;for(let p=0;p<t.size;p++){let m=Number(a[p]);isNaN(m)||(l*=m)}return l}let u=r;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((l,p)=>p!==u);if(s.length===0)return Dr(t);let i=s.reduce((l,p)=>l*p,1),c=n[u],f=new Float64Array(i);for(let l=0;l<i;l++){let p=1;for(let m=0;m<c;m++){let d=$(l,u,m,n),g=O(d,n),h=Number(a[g]);isNaN(h)||(p*=h)}f[l]=p}let y=D.fromData(f,s,"float64");if(e){let l=[...n];return l[u]=1,D.fromData(f,l,"float64")}return y}function Nr(t,r,e=!1){let n=t.shape,o=n.length,a=t.data;if(r===void 0){let l=0,p=0;for(let m=0;m<t.size;m++){let d=Number(a[m]);isNaN(d)||(l+=d,p++)}return p===0?NaN:l/p}let u=r;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((l,p)=>p!==u);if(s.length===0)return Nr(t);let i=s.reduce((l,p)=>l*p,1),c=n[u],f=new Float64Array(i);for(let l=0;l<i;l++){let p=0,m=0;for(let d=0;d<c;d++){let g=$(l,u,d,n),h=O(g,n),A=Number(a[h]);isNaN(A)||(p+=A,m++)}f[l]=m===0?NaN:p/m}let y=D.fromData(f,s,"float64");if(e){let l=[...n];return l[u]=1,D.fromData(f,l,"float64")}return y}function ar(t,r,e=0,n=!1){let o=t.shape,a=o.length,u=t.data;if(r===void 0){let p=0,m=0;for(let h=0;h<t.size;h++){let A=Number(u[h]);isNaN(A)||(p+=A,m++)}if(m-e<=0)return NaN;let d=p/m,g=0;for(let h=0;h<t.size;h++){let A=Number(u[h]);isNaN(A)||(g+=(A-d)**2)}return g/(m-e)}let s=r;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((p,m)=>m!==s);if(i.length===0)return ar(t,void 0,e);let c=i.reduce((p,m)=>p*m,1),f=o[s],y=new Float64Array(c);for(let p=0;p<c;p++){let m=0,d=0;for(let A=0;A<f;A++){let b=$(p,s,A,o),S=O(b,o),N=Number(u[S]);isNaN(N)||(m+=N,d++)}if(d-e<=0){y[p]=NaN;continue}let g=m/d,h=0;for(let A=0;A<f;A++){let b=$(p,s,A,o),S=O(b,o),N=Number(u[S]);isNaN(N)||(h+=(N-g)**2)}y[p]=h/(d-e)}let l=D.fromData(y,i,"float64");if(n){let p=[...o];return p[s]=1,D.fromData(y,p,"float64")}return l}function Jr(t,r,e=0,n=!1){let o=ar(t,r,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,u=new Float64Array(a.size);for(let s=0;s<a.size;s++)u[s]=Math.sqrt(Number(a.data[s]));return D.fromData(u,[...a.shape],"float64")}function wr(t,r,e=!1){let n=t.shape,o=n.length,a=t.data;if(r===void 0){let l=1/0;for(let p=0;p<t.size;p++){let m=Number(a[p]);!isNaN(m)&&m<l&&(l=m)}return l===1/0?NaN:l}let u=r;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((l,p)=>p!==u);if(s.length===0)return wr(t);let i=s.reduce((l,p)=>l*p,1),c=n[u],f=new Float64Array(i);for(let l=0;l<i;l++){let p=1/0;for(let m=0;m<c;m++){let d=$(l,u,m,n),g=O(d,n),h=Number(a[g]);!isNaN(h)&&h<p&&(p=h)}f[l]=p===1/0?NaN:p}let y=D.fromData(f,s,"float64");if(e){let l=[...n];return l[u]=1,D.fromData(f,l,"float64")}return y}function xr(t,r,e=!1){let n=t.shape,o=n.length,a=t.data;if(r===void 0){let l=-1/0;for(let p=0;p<t.size;p++){let m=Number(a[p]);!isNaN(m)&&m>l&&(l=m)}return l===-1/0?NaN:l}let u=r;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((l,p)=>p!==u);if(s.length===0)return xr(t);let i=s.reduce((l,p)=>l*p,1),c=n[u],f=new Float64Array(i);for(let l=0;l<i;l++){let p=-1/0;for(let m=0;m<c;m++){let d=$(l,u,m,n),g=O(d,n),h=Number(a[g]);!isNaN(h)&&h>p&&(p=h)}f[l]=p===-1/0?NaN:p}let y=D.fromData(f,s,"float64");if(e){let l=[...n];return l[u]=1,D.fromData(f,l,"float64")}return y}function Ir(t,r){let e=t.shape,n=e.length,o=t.data;if(r===void 0){let f=1/0,y=-1;for(let l=0;l<t.size;l++){let p=Number(o[l]);!isNaN(p)&&p<f&&(f=p,y=l)}return y}let a=r;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);let u=Array.from(e).filter((f,y)=>y!==a);if(u.length===0)return Ir(t);let s=u.reduce((f,y)=>f*y,1),i=e[a],c=new Int32Array(s);for(let f=0;f<s;f++){let y=1/0,l=0;for(let p=0;p<i;p++){let m=$(f,a,p,e),d=O(m,e),g=Number(o[d]);!isNaN(g)&&g<y&&(y=g,l=p)}c[f]=l}return D.fromData(c,u,"int32")}function zr(t,r){let e=t.shape,n=e.length,o=t.data;if(r===void 0){let f=-1/0,y=-1;for(let l=0;l<t.size;l++){let p=Number(o[l]);!isNaN(p)&&p>f&&(f=p,y=l)}return y}let a=r;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);let u=Array.from(e).filter((f,y)=>y!==a);if(u.length===0)return zr(t);let s=u.reduce((f,y)=>f*y,1),i=e[a],c=new Int32Array(s);for(let f=0;f<s;f++){let y=-1/0,l=0;for(let p=0;p<i;p++){let m=$(f,a,p,e),d=O(m,e),g=Number(o[d]);!isNaN(g)&&g>y&&(y=g,l=p)}c[f]=l}return D.fromData(c,u,"int32")}function Xr(t,r){let e=t.shape,n=e.length,o=t.data;if(r===void 0){let l=t.size,p=new Float64Array(l),m=0;for(let d=0;d<l;d++){let g=Number(o[d]);isNaN(g)||(m+=g),p[d]=m}return D.fromData(p,[l],"float64")}let a=r;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);let u=new Float64Array(t.size),s=e[a],i=[],c=1;for(let l=n-1;l>=0;l--)i.unshift(c),c*=e[l];let f=t.size,y=i[a];for(let l=0;l<f;l++){let p=Number(o[l]);Math.floor(l/y)%s===0?u[l]=isNaN(p)?0:p:u[l]=u[l-y]+(isNaN(p)?0:p)}return D.fromData(u,[...e],"float64")}function Qr(t,r){let e=t.shape,n=e.length,o=t.data;if(r===void 0){let l=t.size,p=new Float64Array(l),m=1;for(let d=0;d<l;d++){let g=Number(o[d]);isNaN(g)||(m*=g),p[d]=m}return D.fromData(p,[l],"float64")}let a=r;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);let u=new Float64Array(t.size),s=e[a],i=[],c=1;for(let l=n-1;l>=0;l--)i.unshift(c),c*=e[l];let f=t.size,y=i[a];for(let l=0;l<f;l++){let p=Number(o[l]);Math.floor(l/y)%s===0?u[l]=isNaN(p)?1:p:u[l]=u[l-y]*(isNaN(p)?1:p)}return D.fromData(u,[...e],"float64")}function _r(t,r,e=!1){let n=t.shape,o=n.length,a=t.data;if(r===void 0){let l=[];for(let d=0;d<t.size;d++){let g=Number(a[d]);isNaN(g)||l.push(g)}if(l.length===0)return NaN;l.sort((d,g)=>d-g);let p=l.length,m=Math.floor(p/2);return p%2===0?(l[m-1]+l[m])/2:l[m]}let u=r;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((l,p)=>p!==u);if(s.length===0)return _r(t);let i=s.reduce((l,p)=>l*p,1),c=n[u],f=new Float64Array(i);for(let l=0;l<i;l++){let p=[];for(let g=0;g<c;g++){let h=$(l,u,g,n),A=O(h,n),b=Number(a[A]);isNaN(b)||p.push(b)}if(p.length===0){f[l]=NaN;continue}p.sort((g,h)=>g-h);let m=p.length,d=Math.floor(m/2);m%2===0?f[l]=(p[d-1]+p[d])/2:f[l]=p[d]}let y=D.fromData(f,s,"float64");if(e){let l=[...n];return l[u]=1,D.fromData(f,l,"float64")}return y}function q(t,r){let e=t.size,n=t.dtype,o=r.indexOf(-1),a;if(o!==-1){let c=r.reduce((y,l,p)=>p===o?y:y*l,1),f=e/c;if(!Number.isInteger(f))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(r)}`);a=r.map((y,l)=>l===o?f:y)}else a=r;if(a.reduce((c,f)=>c*f,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(t.isCContiguous){let c=t.data;return D.fromData(c,a,n,P(a),0)}let i=t.copy().data;return D.fromData(i,a,n,P(a),0)}function Br(t){let r=t.size,e=t.dtype,n=U(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(t.isCContiguous){let s=t.data.slice(t.offset,t.offset+r);return D.fromData(s,[r],e,[1],0)}let o=new n(r),a=w(e);for(let u=0;u<r;u++){let s=t.iget(u);o[u]=s}return D.fromData(o,[r],e,[1],0)}function ir(t){let r=t.size,e=t.dtype;if(t.isCContiguous){let n=t.data;return D.fromData(n,[r],e,[1],0)}return Br(t)}function ur(t,r){let e=t.shape,n=e.length,o=t.strides,a=t.data,u=t.dtype,s;if(r===void 0)s=Array.from({length:n},(y,l)=>n-1-l);else{if(r.length!==n)throw new Error(`axes must have length ${n}, got ${r.length}`);let y=new Set;for(let l of r){let p=l<0?n+l:l;if(p<0||p>=n)throw new Error(`axis ${l} is out of bounds for array of dimension ${n}`);if(y.has(p))throw new Error("repeated axis in transpose");y.add(p)}s=r.map(l=>l<0?n+l:l)}let i=s.map(y=>e[y]),c=Array.from(o),f=s.map(y=>c[y]);return D.fromData(a,i,u,f,t.offset)}function Gt(t,r){let e=t.shape,n=e.length,o=t.strides,a=t.data,u=t.dtype;if(r===void 0){let s=[],i=[];for(let c=0;c<n;c++)e[c]!==1&&(s.push(e[c]),i.push(o[c]));return s.length===0&&(s.push(1),i.push(1)),D.fromData(a,s,u,i,t.offset)}else{let s=r<0?n+r:r;if(s<0||s>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);if(e[s]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${r} has size ${e[s]})`);let i=[],c=[];for(let f=0;f<n;f++)f!==s&&(i.push(e[f]),c.push(o[f]));return D.fromData(a,i,u,c,t.offset)}}function sr(t,r){let e=t.shape,n=e.length,o=t.strides,a=t.data,u=t.dtype,s=r;if(s<0&&(s=n+r+1),s<0||s>n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n+1}`);let i=[...Array.from(e)];i.splice(s,0,1);let c=[...Array.from(o)],f=s<n?o[s]*(e[s]||1):1;return c.splice(s,0,f),D.fromData(a,i,u,c,t.offset)}function Jt(t,r,e){let n=t.shape,o=n.length,a=t.strides,u=t.data,s=t.dtype,i=r<0?o+r:r,c=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis1 ${r} is out of bounds for array of dimension ${o}`);if(c<0||c>=o)throw new Error(`axis2 ${e} is out of bounds for array of dimension ${o}`);if(i===c)return D.fromData(u,Array.from(n),s,Array.from(a),t.offset);let f=Array.from(n),y=Array.from(a);return[f[i],f[c]]=[f[c],f[i]],[y[i],y[c]]=[y[c],y[i]],D.fromData(u,f,s,y,t.offset)}function Kr(t,r,e){let n=t.ndim,o=Array.isArray(r)?r:[r],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 f=c<0?n+c:c;if(f<0||f>=n)throw new Error(`source axis ${c} is out of bounds for array of dimension ${n}`);return f}),s=a.map(c=>{let f=c<0?n+c:c;if(f<0||f>=n)throw new Error(`destination axis ${c} is out of bounds for array of dimension ${n}`);return f});if(new Set(u).size!==u.length)throw new Error("repeated axis in source");if(new Set(s).size!==s.length)throw new Error("repeated axis in destination");let i=[];for(let c=0;c<n;c++)u.includes(c)||i.push(c);for(let c=0;c<u.length;c++){let f=s[c];i.splice(f,0,u[c])}return ur(t,i)}function Q(t,r=0){if(t.length===0)throw new Error("need at least one array to concatenate");if(t.length===1)return t[0].copy();let e=t[0],n=e.ndim,o=e.dtype,a=r<0?n+r:r;if(a<0||a>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);for(let p=1;p<t.length;p++){let m=t[p];if(m.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&&m.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),s=e.shape[a];for(let p=1;p<t.length;p++)s+=t[p].shape[a];u[a]=s;let i=u.reduce((p,m)=>p*m,1),c=U(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let f=new c(i),y=P(u),l=0;for(let p of t){let m=p.shape[a];co(p,f,u,y,a,l,o),l+=m}return D.fromData(f,u,o)}function co(t,r,e,n,o,a,u){let s=t.shape,i=s.length,c=t.size,f=u==="int64"||u==="uint64";if(o===0&&t.isCContiguous&&i>0){let p=a*n[0],m=t.data,d=t.offset,g=d+c;r.set(m.subarray(d,g),p);return}if(o===1&&i===2&&t.isCContiguous){let p=s[0],m=s[1],d=e[1],g=t.data,h=t.offset;for(let A=0;A<p;A++){let b=h+A*m,S=A*d+a;r.set(g.subarray(b,b+m),S)}return}let y=new Array(i).fill(0),l=a*n[o];for(let p=0;p<c;p++){let m=t.iget(p),d=l;for(let g=0;g<i;g++)d+=y[g]*n[g];r[d]=m;for(let g=i-1;g>=0&&(y[g]++,!(y[g]<s[g]));g--)y[g]=0}}function Xt(t,r=0){if(t.length===0)throw new Error("need at least one array to stack");let e=t[0],n=e.shape,o=e.ndim,a=r<0?o+1+r:r;if(a<0||a>o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o+1}`);for(let s=1;s<t.length;s++){let i=t[s];if(i.ndim!==o)throw new Error("all input arrays must have the same shape");for(let c=0;c<o;c++)if(i.shape[c]!==n[c])throw new Error("all input arrays must have the same shape")}let u=t.map(s=>sr(s,a));return Q(u,a)}function Qt(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(e=>e.ndim===1?q(e,[1,e.shape[0]]):e);return Q(r,0)}function rt(t){if(t.length===0)throw new Error("need at least one array to stack");return t.every(e=>e.ndim===1)?Q(t,0):Q(t,1)}function Kt(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(e=>e.ndim===1?q(sr(q(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?sr(e,2):e);return Q(r,2)}function re(t,r,e=0){let n=t.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[a],s;if(typeof r=="number"){if(u%r!==0)throw new Error("array split does not result in an equal division");let i=u/r;s=[];for(let c=1;c<r;c++)s.push(c*i)}else s=r;return te(t,s,a)}function cr(t,r,e=0){let n=t.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[a],s;if(typeof r=="number"){let i=r,c=Math.floor(u/i),f=u%i;s=[];let y=0;for(let l=0;l<i-1;l++)y+=c+(l<f?1:0),s.push(y)}else s=r;return te(t,s,a)}function te(t,r,e){let n=t.shape,o=n[e],a=[0,...r,o],u=[];for(let s=0;s<a.length-1;s++){let i=a[s],c=a[s+1];if(i>c)throw new Error("split indices must be in ascending order");let f=Array.from(n);f[e]=c-i;let y=t.offset+i*t.strides[e];u.push(D.fromData(t.data,f,t.dtype,Array.from(t.strides),y))}return u}function ee(t,r){if(t.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return cr(t,r,0)}function ne(t,r){if(t.ndim<1)throw new Error("hsplit only works on arrays of 1 or more dimensions");let e=t.ndim===1?0:1;return cr(t,r,e)}function oe(t,r){let e=t.shape,n=e.length,o=t.dtype,a=Array.isArray(r)?r:[r],u=Math.max(n,a.length),s=new Array(u).fill(1),i=new Array(u).fill(1);for(let A=0;A<n;A++)s[u-n+A]=e[A];for(let A=0;A<a.length;A++)i[u-a.length+A]=a[A];let c=s.map((A,b)=>A*i[b]),f=c.reduce((A,b)=>A*b,1),y=U(o);if(!y)throw new Error(`Cannot tile array with dtype ${o}`);let l=new y(f),p=P(c),m=t;n<u&&(m=q(t,s));let d=o==="int64"||o==="uint64",g=m.strides,h=new Array(u).fill(0);for(let A=0;A<f;A++){let b=m.offset;for(let x=0;x<u;x++){let I=h[x]%s[x];b+=I*g[x]}let S=m.data[b],N=0;for(let x=0;x<u;x++)N+=h[x]*p[x];l[N]=S;for(let x=u-1;x>=0&&(h[x]++,!(h[x]<c[x]));x--)h[x]=0}return D.fromData(l,c,o)}function ae(t,r,e){let n=t.shape,o=n.length,a=t.dtype,u=t.size;if(e===void 0){let A=u,b=Array.isArray(r)?r:new Array(A).fill(r);if(b.length!==A)throw new Error(`operands could not be broadcast together with shape (${A},) (${b.length},)`);let S=b.reduce((z,B)=>z+B,0),N=U(a);if(!N)throw new Error(`Cannot repeat array with dtype ${a}`);let x=new N(S),I=0;for(let z=0;z<A;z++){let B=t.iget(z),E=b[z];for(let T=0;T<E;T++)x[I++]=B}return D.fromData(x,[S],a)}let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[s],c=Array.isArray(r)?r:new Array(i).fill(r);if(c.length!==i)throw new Error(`operands could not be broadcast together with shape (${i},) (${c.length},)`);let f=Array.from(n);f[s]=c.reduce((A,b)=>A+b,0);let y=f.reduce((A,b)=>A*b,1),l=U(a);if(!l)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new l(y),m=P(f),d=new Array(o).fill(0),g=a==="int64"||a==="uint64",h=[0];for(let A=0;A<i;A++)h.push(h[A]+c[A]);for(let A=0;A<u;A++){let b=t.iget(A),S=d[s],N=c[S],x=0;for(let B=0;B<o;B++)B!==s&&(x+=d[B]*m[B]);let I=m[s],z=h[S];for(let B=0;B<N;B++){let E=x+(z+B)*I;p[E]=b}for(let B=o-1;B>=0&&(d[B]++,!(d[B]<n[B]));B--)d[B]=0}return D.fromData(p,f,a)}function se(t,r){let e=t.shape,n=e.length,o=t.dtype,a=t.size,u;if(r===void 0)u=new Set(Array.from({length:n},(l,p)=>p));else if(typeof r=="number"){let l=r<0?n+r:r;if(l<0||l>=n)throw new Error(`axis ${r} is out of bounds for array of dimension ${n}`);u=new Set([l])}else u=new Set(r.map(l=>{let p=l<0?n+l:l;if(p<0||p>=n)throw new Error(`axis ${l} is out of bounds for array of dimension ${n}`);return p}));let s=U(o);if(!s)throw new Error(`Cannot flip array with dtype ${o}`);let i=new s(a),c=w(o);if(n===1&&t.isCContiguous){let l=t.data,p=t.offset;for(let m=0;m<a;m++)i[m]=l[p+a-1-m];return D.fromData(i,[...e],o)}if(n===2&&t.isCContiguous){let l=e[0],p=e[1],m=t.data,d=t.offset;if(u.size===2){for(let g=0;g<a;g++)i[g]=m[d+a-1-g];return D.fromData(i,[...e],o)}if(u.size===1){if(u.has(0)){for(let g=0;g<l;g++){let h=d+(l-1-g)*p,A=g*p;for(let b=0;b<p;b++)i[A+b]=m[h+b]}return D.fromData(i,[...e],o)}else if(u.has(1)){for(let g=0;g<l;g++){let h=d+g*p,A=g*p;for(let b=0;b<p;b++)i[A+b]=m[h+p-1-b]}return D.fromData(i,[...e],o)}}}let f=new Array(n),y=new Array(n).fill(0);for(let l=0;l<a;l++){for(let d=0;d<n;d++)f[d]=u.has(d)?e[d]-1-y[d]:y[d];let p=t.offset;for(let d=0;d<n;d++)p+=f[d]*t.strides[d];let m=t.data[p];i[l]=m;for(let d=n-1;d>=0&&(y[d]++,!(y[d]<e[d]));d--)y[d]=0}return D.fromData(i,[...e],o)}function ie(t,r=1,e=[0,1]){let n=t.shape,o=n.length,a=t.dtype;if(o<2)throw new Error("Input must be at least 2-D");let u=e[0]<0?o+e[0]:e[0],s=e[1]<0?o+e[1]:e[1];if(u<0||u>=o||s<0||s>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(u===s)throw new Error("Axes must be different");if(r=(r%4+4)%4,r===0)return t.copy();let i=U(a);if(!i)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(r===1||r===3)&&([c[u],c[s]]=[c[s],c[u]]);let f=c.reduce((g,h)=>g*h,1),y=new i(f),l=P(c),p=w(a),m=new Array(o).fill(0),d=new Array(o);for(let g=0;g<t.size;g++){for(let N=0;N<o;N++)d[N]=m[N];let h,A;r===1?(h=n[s]-1-m[s],A=m[u]):r===2?(h=n[u]-1-m[u],A=n[s]-1-m[s],d[u]=h,d[s]=A):(h=m[s],A=n[u]-1-m[u]),r!==2&&(d[u]=h,d[s]=A);let b=0;for(let N=0;N<o;N++)b+=d[N]*l[N];let S=t.iget(g);y[b]=S;for(let N=o-1;N>=0&&(m[N]++,!(m[N]<n[N]));N--)m[N]=0}return D.fromData(y,c,a)}function ue(t,r,e){let n=t.shape,o=n.length,a=t.dtype,u=t.size;if(e===void 0){let m=Array.isArray(r)?r.reduce((b,S)=>b+S,0):r,d=Br(t),g=U(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let h=new g(u),A=w(a);for(let b=0;b<u;b++){let S=((b-m)%u+u)%u,N=d.iget(S);h[b]=N}return D.fromData(h,[...n],a)}let s=Array.isArray(r)?r:[r],i=Array.isArray(e)?e:[e];if(s.length!==i.length)throw new Error("shift and axis must have the same length");let c=i.map(m=>{let d=m<0?o+m:m;if(d<0||d>=o)throw new Error(`axis ${m} is out of bounds for array of dimension ${o}`);return d}),f=U(a);if(!f)throw new Error(`Cannot roll array with dtype ${a}`);let y=new f(u),l=w(a),p=new Array(o).fill(0);for(let m=0;m<u;m++){let d=[...p];for(let A=0;A<c.length;A++){let b=c[A],S=n[b],N=s[A];d[b]=((d[b]-N)%S+S)%S}let g=t.offset;for(let A=0;A<o;A++)g+=d[A]*t.strides[A];let h=t.data[g];y[m]=h;for(let A=o-1;A>=0&&(p[A]++,!(p[A]<n[A]));A--)p[A]=0}return D.fromData(y,[...n],a)}function ce(t,r,e=0){let n=t.ndim,o=r<0?n+r:r;if(o<0||o>=n)throw new Error(`axis ${r} 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?D.fromData(t.data,Array.from(t.shape),t.dtype,Array.from(t.strides),t.offset):Kr(t,o,a)}function fe(t,r){if(t.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return cr(t,r,2)}function le(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(e=>e.ndim===1?q(e,[e.shape[0],1]):e);return rt(r)}function ye(t,r){let e=t.dtype,n=r.reduce((i,c)=>i*c,1),o=t.size,a=U(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let u=new a(n),s=w(e);for(let i=0;i<n;i++){let c=i%o,f=t.iget(c);u[i]=f}return D.fromData(u,r,e)}function pe(t){return t.map(r=>r.ndim===0?q(r,[1]):r)}function me(t){return t.map(r=>r.ndim===0?q(r,[1,1]):r.ndim===1?q(r,[1,r.shape[0]]):r)}function de(t){return t.map(r=>r.ndim===0?q(r,[1,1,1]):r.ndim===1?q(r,[1,r.shape[0],1]):r.ndim===2?q(r,[r.shape[0],r.shape[1],1]):r)}function fo(t,r,e,n,o,a,u,s,i,c,f,y,l,p){if(y===0)for(let h=0;h<n*o;h++)l[h]=0;else if(y!==1)for(let h=0;h<n*o;h++)l[h]=(l[h]??0)*y;let m=t==="row-major",d=r==="transpose",g=e==="transpose";if(m&&!d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[h*i+S]??0)*(c[S*f+A]??0);l[h*p+A]=(l[h*p+A]??0)+u*b}else if(m&&d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[S*i+h]??0)*(c[S*f+A]??0);l[h*p+A]=(l[h*p+A]??0)+u*b}else if(m&&!d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[h*i+S]??0)*(c[A*f+S]??0);l[h*p+A]=(l[h*p+A]??0)+u*b}else if(m&&d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[S*i+h]??0)*(c[A*f+S]??0);l[h*p+A]=(l[h*p+A]??0)+u*b}else if(!m&&!d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[S*i+h]??0)*(c[A*f+S]??0);l[A*p+h]=(l[A*p+h]??0)+u*b}else if(!m&&d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[h*i+S]??0)*(c[A*f+S]??0);l[A*p+h]=(l[A*p+h]??0)+u*b}else if(!m&&!d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[S*i+h]??0)*(c[S*f+A]??0);l[A*p+h]=(l[A*p+h]??0)+u*b}else for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(s[h*i+S]??0)*(c[S*f+A]??0);l[A*p+h]=(l[A*p+h]??0)+u*b}}function et(t,r){let e=t.ndim,n=r.ndim;if(e===0||n===0){let o=e===0?t.get():null,a=n===0?r.get():null;if(e===0&&n===0)return typeof o=="bigint"&&typeof a=="bigint"?o*a:Number(o)*Number(a);if(e===0){let u=v(t.dtype,r.dtype),s=D.zeros([...r.shape],u);for(let i=0;i<r.size;i++){let c=r.data[i+r.offset];typeof o=="bigint"&&typeof c=="bigint"?s.data[i]=o*c:s.data[i]=Number(o)*Number(c)}return s}else{let u=v(t.dtype,r.dtype),s=D.zeros([...t.shape],u);for(let i=0;i<t.size;i++){let c=t.data[i+t.offset];typeof c=="bigint"&&typeof a=="bigint"?s.data[i]=c*a:s.data[i]=Number(c)*Number(a)}return s}}if(e===1&&n===1){if(t.shape[0]!==r.shape[0])throw new Error(`dot: incompatible shapes (${t.shape[0]},) and (${r.shape[0]},)`);let o=t.shape[0],a=0;for(let u=0;u<o;u++){let s=t.get(u),i=r.get(u);typeof s=="bigint"&&typeof i=="bigint"?a=Number(a)+Number(s*i):a+=Number(s)*Number(i)}return a}if(e===2&&n===2)return K(t,r);if(e===2&&n===1){let[o,a]=t.shape,u=r.shape[0];if(a!==u)throw new Error(`dot: incompatible shapes (${o},${a}) and (${u},)`);let s=v(t.dtype,r.dtype),i=D.zeros([o],s);for(let c=0;c<o;c++){let f=0;for(let y=0;y<a;y++){let l=t.get(c,y),p=r.get(y);typeof l=="bigint"&&typeof p=="bigint"?f=Number(f)+Number(l*p):f+=Number(l)*Number(p)}i.set([c],f)}return i}if(e===1&&n===2){let o=t.shape[0],[a,u]=r.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${u})`);let s=v(t.dtype,r.dtype),i=D.zeros([u],s);for(let c=0;c<u;c++){let f=0;for(let y=0;y<o;y++){let l=t.get(y),p=r.get(y,c);typeof l=="bigint"&&typeof p=="bigint"?f=Number(f)+Number(l*p):f+=Number(l)*Number(p)}i.set([c],f)}return i}if(e>2&&n===1){let o=t.shape[e-1],a=r.shape[0];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(t.shape)} and (${a},)`);let u=[...t.shape.slice(0,-1)],s=v(t.dtype,r.dtype),i=D.zeros(u,s),c=u.reduce((f,y)=>f*y,1);for(let f=0;f<c;f++){let y=0,l=f,p=[];for(let m=u.length-1;m>=0;m--)p[m]=l%u[m],l=Math.floor(l/u[m]);for(let m=0;m<o;m++){let d=[...p,m],g=t.get(...d),h=r.get(m);typeof g=="bigint"&&typeof h=="bigint"?y=Number(y)+Number(g*h):y+=Number(g)*Number(h)}i.set(p,y)}return i}if(e===1&&n>2){let o=t.shape[0],a=1,u=r.shape[a];if(o!==u)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(r.shape)}`);let s=[...r.shape.slice(0,a),...r.shape.slice(a+1)],i=v(t.dtype,r.dtype),c=D.zeros(s,i),f=s.reduce((y,l)=>y*l,1);for(let y=0;y<f;y++){let l=y,p=[];for(let h=s.length-1;h>=0;h--)p[h]=l%s[h],l=Math.floor(l/s[h]);let m=p.slice(0,a),d=p.slice(a),g=0;for(let h=0;h<o;h++){let A=t.get(h),b=[...m,h,...d],S=r.get(...b);typeof A=="bigint"&&typeof S=="bigint"?g=Number(g)+Number(A*S):g+=Number(A)*Number(S)}c.set(p,g)}return c}if(e>=2&&n>=2&&!(e===2&&n===2)){let o=t.shape[e-1],a=r.shape[n-2];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(t.shape)} and ${JSON.stringify(r.shape)}`);let u=[...t.shape.slice(0,-1),...r.shape.slice(0,-2),r.shape[n-1]],s=v(t.dtype,r.dtype),i=D.zeros(u,s),c=t.shape.slice(0,-1).reduce((p,m)=>p*m,1),f=r.shape.slice(0,-2).reduce((p,m)=>p*m,1),y=r.shape[n-1],l=o;for(let p=0;p<c;p++)for(let m=0;m<f;m++)for(let d=0;d<y;d++){let g=0;for(let A=0;A<l;A++){let b=p*l+A,S=t.data[b+t.offset],N=m*l*y+A*y+d,x=r.data[N+r.offset];typeof S=="bigint"&&typeof x=="bigint"?g=Number(g)+Number(S*x):g+=Number(S)*Number(x)}let h=p*f*y+m*y+d;i.data[h]=g}return i}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function K(t,r){if(t.ndim!==2||r.ndim!==2)throw new Error("matmul requires 2D arrays");let[e=0,n=0]=t.shape,[o=0,a=0]=r.shape;if(n!==o)throw new Error(`matmul shape mismatch: (${e},${n}) @ (${o},${a})`);let u=v(t.dtype,r.dtype),s=u.startsWith("int")||u.startsWith("uint")||u==="bool"?"float64":u;if(s!=="float64")throw new Error(`matmul currently only supports float64, got ${s}`);let i=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number)),c=r.dtype==="float64"?r.data:Float64Array.from(Array.from(r.data).map(Number));t.offset>0&&(i=i.subarray(t.offset)),r.offset>0&&(c=c.subarray(r.offset));let[f=0,y=0]=t.strides,[l=0,p=0]=r.strides,m=y>f,d=p>l,g=m?"transpose":"no-transpose",h=d?"transpose":"no-transpose",A,b;m?A=y:A=f,d?b=p:b=l;let S=D.zeros([e,a],"float64");return fo("row-major",g,h,e,a,n,1,i,A,c,b,0,S.data,a),S}function he(t){if(t.ndim!==2)throw new Error(`trace requires 2D array, got ${t.ndim}D`);let[r=0,e=0]=t.shape,n=Math.min(r,e),o=0;for(let a=0;a<n;a++){let u=t.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 Ae(t,r){return ur(t,r)}function be(t,r){let e=t.ndim,n=r.ndim,o=t.shape[e-1],a=r.shape[n-1];if(o!==a)throw new Error(`inner: incompatible shapes - last dimensions ${o} and ${a} don't match`);if(e===1&&n===1)return et(t,r);let u=[...t.shape.slice(0,-1),...r.shape.slice(0,-1)],s=v(t.dtype,r.dtype),i=D.zeros(u,s),c=e===1?1:t.shape.slice(0,-1).reduce((l,p)=>l*p,1),f=n===1?1:r.shape.slice(0,-1).reduce((l,p)=>l*p,1),y=o;for(let l=0;l<c;l++)for(let p=0;p<f;p++){let m=0;for(let g=0;g<y;g++){let h=e===1?g:l*y+g,A=n===1?g:p*y+g,b=t.data[h+t.offset],S=r.data[A+r.offset];typeof b=="bigint"&&typeof S=="bigint"?m=Number(m)+Number(b*S):m+=Number(b)*Number(S)}if(u.length===0)return m;let d=c===1?p:l*f+p;i.data[d]=m}return i}function nt(t,r){let e=t.ndim===1?t:ir(t),n=r.ndim===1?r:ir(r),o=e.size,a=n.size,u=v(t.dtype,r.dtype),s=D.zeros([o,a],u);for(let i=0;i<o;i++)for(let c=0;c<a;c++){let f=e.get(i),y=n.get(c),l;typeof f=="bigint"&&typeof y=="bigint"?l=f*y:l=Number(f)*Number(y),s.set([i,c],l)}return s}function Se(t,r,e){let n,o;if(typeof e=="number"){let l=e;if(l<0)throw new Error("tensordot: axes must be non-negative");if(l>t.ndim||l>r.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:l},(p,m)=>t.ndim-l+m),o=Array.from({length:l},(p,m)=>m)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let l=0;l<n.length;l++){let p=n[l],m=o[l];if(p<0||p>=t.ndim||m<0||m>=r.ndim)throw new Error("tensordot: axis out of bounds");if(t.shape[p]!==r.shape[m])throw new Error(`tensordot: shape mismatch on axes ${p} and ${m}: ${t.shape[p]} != ${r.shape[m]}`)}let a=[],u=[];for(let l=0;l<t.ndim;l++)n.includes(l)||a.push(l);for(let l=0;l<r.ndim;l++)o.includes(l)||u.push(l);let s=[...a.map(l=>t.shape[l]),...u.map(l=>r.shape[l])];if(s.length===0){let l=0,p=n.map(m=>t.shape[m]).reduce((m,d)=>m*d,1);for(let m=0;m<p;m++){let d=m,g=new Array(n.length);for(let N=n.length-1;N>=0;N--){let x=n[N];g[N]=d%t.shape[x],d=Math.floor(d/t.shape[x])}let h=new Array(t.ndim),A=new Array(r.ndim);for(let N=0;N<n.length;N++)h[n[N]]=g[N];for(let N=0;N<o.length;N++)A[o[N]]=g[N];let b=t.get(...h),S=r.get(...A);typeof b=="bigint"&&typeof S=="bigint"?l=Number(l)+Number(b*S):l+=Number(b)*Number(S)}return l}let i=v(t.dtype,r.dtype),c=D.zeros(s,i),f=s.reduce((l,p)=>l*p,1),y=n.map(l=>t.shape[l]).reduce((l,p)=>l*p,1);for(let l=0;l<f;l++){let p=l,m=[];for(let A=s.length-1;A>=0;A--)m[A]=p%s[A],p=Math.floor(p/s[A]);let d=m.slice(0,a.length),g=m.slice(a.length),h=0;for(let A=0;A<y;A++){p=A;let b=[];for(let z=n.length-1;z>=0;z--){let B=n[z];b[z]=p%t.shape[B],p=Math.floor(p/t.shape[B])}let S=new Array(t.ndim),N=new Array(r.ndim);for(let z=0;z<a.length;z++)S[a[z]]=d[z];for(let z=0;z<u.length;z++)N[u[z]]=g[z];for(let z=0;z<n.length;z++)S[n[z]]=b[z],N[o[z]]=b[z];let x=t.get(...S),I=r.get(...N);typeof x=="bigint"&&typeof I=="bigint"?h=Number(h)+Number(x*I):h+=Number(x)*Number(I)}c.set(m,h)}return c}function De(t,r=0,e=0,n=1){let o=t.shape,a=o.length;if(a<2)throw new Error("diagonal requires an array of at least two dimensions");let u=e<0?a+e:e,s=n<0?a+n:n;if(u<0||u>=a||s<0||s>=a)throw new Error("axis out of bounds");if(u===s)throw new Error("axis1 and axis2 cannot be the same");let i=o[u],c=o[s],f;r>=0?f=Math.max(0,Math.min(i,c-r)):f=Math.max(0,Math.min(i+r,c));let y=[];for(let d=0;d<a;d++)d!==u&&d!==s&&y.push(o[d]);y.push(f);let l=D.zeros(y,t.dtype),p=o.filter((d,g)=>g!==u&&g!==s),m=p.reduce((d,g)=>d*g,1);for(let d=0;d<m;d++){let g=d,h=[];for(let A=p.length-1;A>=0;A--)h.unshift(g%p[A]),g=Math.floor(g/p[A]);for(let A=0;A<f;A++){let b=new Array(a),S=0;for(let I=0;I<a;I++)I===u?b[I]=r>=0?A:A-r:I===s?b[I]=r>=0?A+r:A:b[I]=h[S++];let N=[...h,A],x=t.get(...b);l.set(N,x)}}return l}function Ne(t,...r){let e=t.indexOf("->"),n,o;e===-1?(n=t,o=lo(n)):(n=t.slice(0,e),o=t.slice(e+2));let a=n.split(",").map(d=>d.trim());if(a.length!==r.length)throw new Error(`einsum: expected ${a.length} operands, got ${r.length}`);let u=new Map;for(let d=0;d<r.length;d++){let g=a[d],h=r[d];if(g.length!==h.ndim)throw new Error(`einsum: operand ${d} has ${h.ndim} dimensions but subscript '${g}' has ${g.length} indices`);for(let A=0;A<g.length;A++){let b=g[A],S=h.shape[A];if(u.has(b)){if(u.get(b)!==S)throw new Error(`einsum: size mismatch for index '${b}': ${u.get(b)} vs ${S}`)}else u.set(b,S)}}for(let d of o)if(!u.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let s=new Set(o),i=new Set;for(let d of a)for(let g of d)i.add(g);let c=[];for(let d of i)s.has(d)||c.push(d);if(r.length===2&&a.length===2){let[d,g]=a,[h,A]=r;if(d.length===2&&g.length===2&&o.length===2&&h.ndim===2&&A.ndim===2){let[b,S]=[d[0],d[1]],[N,x]=[g[0],g[1]],[I,z]=[o[0],o[1]];if(b===I&&x===z&&S===N&&c.length===1&&c[0]===S||b===I&&x===z&&S===N&&c.length===1&&c[0]===S)return K(h,A);if(S===I&&x===z&&b===N&&c.length===1&&c[0]===b){let B=Ae(h);return K(B,A)}if(b===I&&N===z&&S===x&&c.length===1&&c[0]===S){let B=Ae(A);return K(h,B)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&h.ndim===1&&A.ndim===1)return tt(r,a,c,u);if(d&&g&&d.length===1&&g.length===1&&o.length===2&&o===d+g&&c.length===0&&h.ndim===1&&A.ndim===1)return nt(h,A)}if(r.length===1&&a[0].length===2&&o.length===0){let d=a[0];if(d[0]===d[1]&&r[0].ndim===2)return tt(r,a,c,u)}let f=Array.from(o).map(d=>u.get(d));if(f.length===0)return tt(r,a,c,u);let y=r[0].dtype;for(let d=1;d<r.length;d++)y=v(y,r[d].dtype);let l=D.zeros(f,y),p=f.reduce((d,g)=>d*g,1),m=1;for(let d of c)m*=u.get(d);for(let d=0;d<p;d++){let g=yo(d,f),h=new Map;for(let b=0;b<o.length;b++)h.set(o[b],g[b]);let A=0;for(let b=0;b<m;b++){let S=b;for(let x=c.length-1;x>=0;x--){let I=c[x],z=u.get(I);h.set(I,S%z),S=Math.floor(S/z)}let N=1;for(let x=0;x<r.length;x++){let I=r[x],z=a[x],B=[];for(let T of z)B.push(h.get(T));let E=I.get(...B);N*=Number(E)}A+=N}l.set(g,A)}return l}function lo(t){let r=new Map,e=t.split(",");for(let o of e)for(let a of o.trim())r.set(a,(r.get(a)||0)+1);let n=[];for(let[o,a]of r)a===1&&n.push(o);return n.sort().join("")}function tt(t,r,e,n){let o=1;for(let u of e)o*=n.get(u);let a=0;for(let u=0;u<o;u++){let s=new Map,i=u;for(let f=e.length-1;f>=0;f--){let y=e[f],l=n.get(y);s.set(y,i%l),i=Math.floor(i/l)}let c=1;for(let f=0;f<t.length;f++){let y=t[f],l=r[f],p=[];for(let d of l)p.push(s.get(d));let m=y.get(...p);c*=Number(m)}a+=c}return a}function yo(t,r){let e=new Array(r.length),n=t;for(let o=r.length-1;o>=0;o--)e[o]=n%r[o],n=Math.floor(n/r[o]);return e}function we(t,r){let e=t.shape,n=r.shape,o=e.length,a=n.length,u=v(t.dtype,r.dtype),s=Math.max(o,a),i=new Array(s),c=new Array(s).fill(1),f=new Array(s).fill(1);for(let m=0;m<o;m++)c[s-o+m]=e[m];for(let m=0;m<a;m++)f[s-a+m]=n[m];for(let m=0;m<s;m++)i[m]=c[m]*f[m];let y=D.zeros(i,u),l=e.reduce((m,d)=>m*d,1),p=n.reduce((m,d)=>m*d,1);for(let m=0;m<l;m++){let d=m,g=new Array(o);for(let b=o-1;b>=0;b--)g[b]=d%e[b],d=Math.floor(d/e[b]);let h=new Array(s).fill(0);for(let b=0;b<o;b++)h[s-o+b]=g[b];let A=t.get(...g);for(let b=0;b<p;b++){let S=b,N=new Array(a);for(let E=a-1;E>=0;E--)N[E]=S%n[E],S=Math.floor(S/n[E]);let x=new Array(s).fill(0);for(let E=0;E<a;E++)x[s-a+E]=N[E];let I=r.get(...N),z=new Array(s);for(let E=0;E<s;E++)z[E]=h[E]*f[E]+x[E];let B=typeof A=="bigint"||typeof I=="bigint"?BigInt(Number(A))*BigInt(Number(I)):Number(A)*Number(I);y.set(z,B)}}return y}function xe(t){return k(t,Math.sqrt,!1)}function Ie(t,r){return typeof r=="number"?mo(t,r):V(t,r,Math.pow,"power")}function mo(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,i=e!=="float32"&&e!=="float64"&&(r<0||!Number.isInteger(r))?"float64":e,c=D.zeros(n,i),f=c.data;if(w(e))if(w(i)&&Number.isInteger(r)&&r>=0){let y=o,l=f;for(let p=0;p<a;p++)l[p]=y[p]**BigInt(r)}else for(let y=0;y<a;y++)f[y]=Math.pow(Number(o[y]),r);else for(let y=0;y<a;y++)f[y]=Math.pow(Number(o[y]),r);return c}function ze(t){return k(t,Math.sin,!1)}function _e(t){return k(t,Math.cos,!1)}function Be(t){return k(t,Math.tan,!1)}function Ee(t){return k(t,Math.asin,!1)}function Ue(t){return k(t,Math.acos,!1)}function Te(t){return k(t,Math.atan,!1)}function Oe(t,r){return typeof r=="number"?ho(t,r):Ao(t,r)}function Ao(t,r){let e=Array.from(t.shape),n=t.size,o=t.dtype,a=r.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",s=D.zeros(e,u),i=s.data;for(let c=0;c<n;c++){let f=(w(o),Number(t.data[c])),y=(w(a),Number(r.data[c]));i[c]=Math.atan2(f,y)}return s}function ho(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=e==="float32"?"float32":"float64",s=D.zeros(n,u),i=s.data;if(w(e))for(let c=0;c<a;c++)i[c]=Math.atan2(Number(o[c]),r);else for(let c=0;c<a;c++)i[c]=Math.atan2(Number(o[c]),r);return s}function $e(t,r){return typeof r=="number"?So(t,r):bo(t,r)}function bo(t,r){let e=Array.from(t.shape),n=t.size,o=t.dtype,a=r.dtype,u=o==="float32"&&a==="float32"?"float32":"float64",s=D.zeros(e,u),i=s.data;for(let c=0;c<n;c++){let f=(w(o),Number(t.data[c])),y=(w(a),Number(r.data[c]));i[c]=Math.hypot(f,y)}return s}function So(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=e==="float32"?"float32":"float64",s=D.zeros(n,u),i=s.data;if(w(e))for(let c=0;c<a;c++)i[c]=Math.hypot(Number(o[c]),r);else for(let c=0;c<a;c++)i[c]=Math.hypot(Number(o[c]),r);return s}function ve(t){let r=180/Math.PI;return k(t,e=>e*r,!1)}function Me(t){let r=Math.PI/180;return k(t,e=>e*r,!1)}function Ce(t){return k(t,Math.sinh,!1)}function ke(t){return k(t,Math.cosh,!1)}function Ve(t){return k(t,Math.tanh,!1)}function Fe(t){return k(t,Math.asinh,!1)}function Pe(t){return k(t,Math.acosh,!1)}function Re(t){return k(t,Math.atanh,!1)}function ot(t,r){let e=t.shape,n=e.length,o=r.length;if(o<n)throw new Error("input operand has more dimensions than allowed by the axis remapping");let a=J([Array.from(e),r]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${r.join(",")})`);for(let u=0;u<o;u++)if(a[u]!==r[u])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${r.join(",")})`);return Z(t,r)}function Le(t){if(t.length===0)return[];if(t.length===1)return[t[0]];let r=t.map(n=>Array.from(n.shape)),e=J(r);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${r.map(n=>`(${n.join(",")})`).join(" ")}`);return t.map(n=>Z(n,e))}function qe(t,r,e){let n=t.shape,o=n.length,a=t.dtype;if(e===void 0){let m=t.size;for(let A of r){let b=A<0?m+A:A;if(b<0||b>=m)throw new Error(`index ${A} is out of bounds for axis 0 with size ${m}`)}let d=r.length,g=U(a);if(!g)throw new Error(`Cannot take from array with dtype ${a}`);let h=new g(d);for(let A=0;A<d;A++){let b=r[A];b<0&&(b=m+b);let S=t.iget(b);w(a),h[A]=S}return D.fromData(h,[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 s=n[u];for(let m of r){let d=m<0?s+m:m;if(d<0||d>=s)throw new Error(`index ${m} is out of bounds for axis ${u} with size ${s}`)}let i=Array.from(n);i[u]=r.length;let c=i.reduce((m,d)=>m*d,1),f=U(a);if(!f)throw new Error(`Cannot take from array with dtype ${a}`);let y=new f(c),l=P(i),p=new Array(o).fill(0);for(let m=0;m<c;m++){let d=[...p],g=p[u],h=r[g];h<0&&(h=s+h),d[u]=h;let A=t.get(...d),b=0;for(let S=0;S<o;S++)b+=p[S]*l[S];w(a),y[b]=A;for(let S=o-1;S>=0&&(p[S]++,!(p[S]<i[S]));S--)p[S]=0}return D.fromData(y,i,a)}function je(t,r,e){let n=t.size,o=t.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=new Array(r.length).fill(e);else{a=[];for(let u=0;u<e.size;u++)a.push(e.iget(u));if(a.length===1)a=new Array(r.length).fill(a[0]);else if(a.length!==r.length){let u=[...a];a=[];for(let s=0;s<r.length;s++)a.push(u[s%u.length])}}for(let u=0;u<r.length;u++){let s=r[u];if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`index ${r[u]} is out of bounds for axis 0 with size ${n}`);let i=a[u];w(o)?typeof i!="bigint"&&(i=BigInt(Math.round(Number(i)))):typeof i=="bigint"&&(i=Number(i)),t.iset(s,i)}}function Ze(t,r){if(r.length===0)throw new Error("choices cannot be empty");let e=t.shape,n=r.length,o=r[0].dtype,a=r.map(l=>Array.from(l.shape));a.unshift(Array.from(e));let u=J(a);if(u===null)throw new Error("operands could not be broadcast together");let s=Z(t,u),i=r.map(l=>Z(l,u)),c=u.reduce((l,p)=>l*p,1),f=U(o);if(!f)throw new Error(`Cannot choose with dtype ${o}`);let y=new f(c);for(let l=0;l<c;l++){let p=Number(s.iget(l));if(p<0||p>=n)throw new Error(`index ${p} is out of bounds for axis 0 with size ${n}`);let m=i[p].iget(l);w(o),y[l]=m}return D.fromData(y,u,o)}function We(t,r,e=!1){if(t.ndim!==r.ndim)return!1;for(let o=0;o<t.ndim;o++)if(t.shape[o]!==r.shape[o])return!1;let n=t.size;for(let o=0;o<n;o++){let a=t.iget(o),u=r.iget(o);if(e){let s=typeof a=="number"&&Number.isNaN(a),i=typeof u=="number"&&Number.isNaN(u);if(s&&i)continue}if(a!==u)return!1}return!0}function He(t,r,e){let n=t.shape,o=n.length,a=t.dtype,u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=r.shape;if(s.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${s.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==u&&s[d]!==n[d]&&s[d]!==1&&n[d]!==1)throw new Error(`index ${s[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let i=Array.from(s),c=i.reduce((d,g)=>d*g,1),f=U(a);if(!f)throw new Error(`Cannot take_along_axis with dtype ${a}`);let y=new f(c),l=P(n),p=P(s),m=n[u];for(let d=0;d<c;d++){let g=new Array(o),h=d;for(let I=o-1;I>=0;I--)g[I]=h%i[I],h=Math.floor(h/i[I]);let A=0;for(let I=0;I<o;I++){let z=s[I]===1?0:g[I];A+=z*p[I]}let b=Number(r.iget(A));if(b<0&&(b=m+b),b<0||b>=m)throw new Error(`index ${b} is out of bounds for axis ${u} with size ${m}`);let S=[...g];S[u]=b;let N=0;for(let I=0;I<o;I++){let z=n[I]===1?0:S[I];N+=z*l[I]}let x=t.iget(N);w(a),y[d]=x}return D.fromData(y,i,a)}function Ye(t,r,e,n){let o=t.shape,a=o.length,u=t.dtype,s=n<0?a+n:n;if(s<0||s>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let i=r.shape,c=e.shape;if(i.length!==a||c.length!==a)throw new Error("indices, arr, and values must have same ndim");let f=o[s],y=P(o),l=P(i),p=P(c),m=i.reduce((d,g)=>d*g,1);for(let d=0;d<m;d++){let g=new Array(a),h=d;for(let z=a-1;z>=0;z--)g[z]=h%i[z],h=Math.floor(h/i[z]);let A=0;for(let z=0;z<a;z++)A+=g[z]*l[z];let b=Number(r.iget(A));if(b<0&&(b=f+b),b<0||b>=f)throw new Error(`index ${b} is out of bounds for axis ${s} with size ${f}`);let S=0;for(let z=0;z<a;z++){let B=c[z]===1?0:g[z];S+=B*p[z]}let N=e.iget(S),x=[...g];x[s]=b;let I=0;for(let z=0;z<a;z++)I+=x[z]*y[z];w(u)?typeof N!="bigint"&&(N=BigInt(Math.round(Number(N)))):typeof N=="bigint"&&(N=Number(N)),t.iset(I,N)}}function Ge(t,r,e){let n=t.size,o=t.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let s=0;s<e.size;s++)a.push(e.iget(s))}let u=0;for(let s=0;s<n;s++)if(r.iget(s)){let c=a[u%a.length];w(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),t.iset(s,c),u++}}function Je(t,r,e){let n=r.shape,o=n.length,a=r.dtype,u=r.data,s=w(a);if(e===void 0){let A=0,b=Math.min(t.size,r.size);for(let I=0;I<b;I++)t.iget(I)&&A++;let S=U(a);if(!S)throw new Error(`Cannot compress with dtype ${a}`);let N=new S(A),x=0;for(let I=0;I<b;I++)t.iget(I)&&(N[x]=u[I],x++);return D.fromData(N,[A],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let c=n[i],f=Math.min(t.size,c),y=[];for(let A=0;A<f;A++)t.iget(A)&&y.push(A);let l=y.length,p=[...n];p[i]=l;let m=p.reduce((A,b)=>A*b,1),d=U(a);if(!d)throw new Error(`Cannot compress with dtype ${a}`);let g=new d(m),h=P(n);if(i===0){let A=h[0],b=n.slice(1).reduce((N,x)=>N*x,1),S=0;for(let N=0;N<l;N++){let I=y[N]*A;if(s){let z=u,B=g;for(let E=0;E<b;E++)B[S++]=z[I+E]}else{let z=u,B=g;for(let E=0;E<b;E++)B[S++]=z[I+E]}}}else{let A=n.slice(0,i).reduce((N,x)=>N*x,1),b=n.slice(i+1).reduce((N,x)=>N*x,1),S=0;for(let N=0;N<A;N++)for(let x=0;x<l;x++){let I=y[x],z=0,B=N;for(let E=i-1;E>=0;E--){let T=B%n[E];B=Math.floor(B/n[E]),z+=T*h[E]}if(z+=I*h[i],s){let E=u,T=g;for(let C=0;C<b;C++)T[S++]=E[z+C]}else{let E=u,T=g;for(let C=0;C<b;C++)T[S++]=E[z+C]}}}return D.fromData(g,p,a)}function Xe(t,r,e=0){if(t.length!==r.length)throw new Error("condlist and choicelist must have same length");if(t.length===0)throw new Error("condlist and choicelist cannot be empty");let n=[...t.map(l=>Array.from(l.shape)),...r.map(l=>Array.from(l.shape))],o=J(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=r[0].dtype,u=o.reduce((l,p)=>l*p,1),s=U(a);if(!s)throw new Error(`Cannot select with dtype ${a}`);let i=e;w(a)?i=typeof e=="bigint"?e:BigInt(e):i=typeof e=="bigint"?Number(e):e;let c=new s(u);for(let l=0;l<u;l++)w(a),c[l]=i;let f=t.map(l=>Z(l,o)),y=r.map(l=>Z(l,o));for(let l=0;l<u;l++)for(let p=0;p<t.length;p++)if(f[p].iget(l)){let m=y[p].iget(l);w(a),c[l]=m;break}return D.fromData(c,o,a)}function Qe(t,r,e){let n=t.size,o=t.dtype,a=[];for(let s=0;s<e.size;s++)a.push(e.iget(s));if(a.length===0)return;let u=0;for(let s=0;s<n;s++)if(r.iget(s)){let c=a[u%a.length];w(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),t.iset(s,c),u++}}function at(t,r=2){if(r<1)throw new Error("ndim must be at least 1");let e=new Int32Array(t);for(let o=0;o<t;o++)e[o]=o;let n=[];for(let o=0;o<r;o++)n.push(D.fromData(new Int32Array(e),[t],"int32"));return n}function Ke(t){let r=t.shape,e=r.length;if(e<2)throw new Error("array must be at least 2-D");let n=r[0];for(let o=1;o<e;o++)if(r[o]!==n)throw new Error("All dimensions of input must be equal");return at(n,e)}function st(t,r=0,e){let n=e??t,o=[],a=[];for(let u=0;u<t;u++)for(let s=0;s<=Math.min(u+r,n-1);s++)s>=0&&(o.push(u),a.push(s));return[D.fromData(new Int32Array(o),[o.length],"int32"),D.fromData(new Int32Array(a),[a.length],"int32")]}function rn(t,r=0){let e=t.shape;if(e.length!==2)throw new Error("array must be 2-D");return st(e[0],r,e[1])}function it(t,r=0,e){let n=e??t,o=[],a=[];for(let u=0;u<t;u++)for(let s=Math.max(u+r,0);s<n;s++)o.push(u),a.push(s);return[D.fromData(new Int32Array(o),[o.length],"int32"),D.fromData(new Int32Array(a),[a.length],"int32")]}function tn(t,r=0){let e=t.shape;if(e.length!==2)throw new Error("array must be 2-D");return it(e[0],r,e[1])}function en(t,r,e=0){let n=r(t,e),o=n.shape;if(o.length!==2||o[0]!==t||o[1]!==t)throw new Error("mask_func must return n x n array");let a=[],u=[];for(let s=0;s<t;s++)for(let i=0;i<t;i++)n.get(s,i)&&(a.push(s),u.push(i));return[D.fromData(new Int32Array(a),[a.length],"int32"),D.fromData(new Int32Array(u),[u.length],"int32")]}function nn(t,r="int32"){let e=t.length,n=[e,...t],o=n.reduce((i,c)=>i*c,1),a=U(r);if(!a)throw new Error(`Cannot create indices with dtype ${r}`);let u=new a(o),s=t.reduce((i,c)=>i*c,1);for(let i=0;i<e;i++){let c=i*s;for(let f=0;f<s;f++){let y=new Array(e),l=f;for(let m=e-1;m>=0;m--)y[m]=l%t[m],l=Math.floor(l/t[m]);let p=y[i];r==="int64"?u[c+f]=BigInt(p):u[c+f]=p}}return D.fromData(u,n,r)}function on(...t){let r=t.length,e=[];for(let n=0;n<r;n++){let o=t[n],a=o.size,u=o.dtype,s=new Array(r).fill(1);s[n]=a;let i=U(u);if(!i)throw new Error(`Cannot create ix_ with dtype ${u}`);let c=new i(a);for(let f=0;f<a;f++){let y=o.iget(f);w(u),c[f]=y}e.push(D.fromData(c,s,u))}return e}function an(t,r,e="raise"){if(t.length!==r.length)throw new Error("multi_index length must equal dims length");if(t.length===0)throw new Error("multi_index cannot be empty");let n=t[0].size,o=r.length,a=new Int32Array(n),u=new Array(o),s=1;for(let i=o-1;i>=0;i--)u[i]=s,s*=r[i];for(let i=0;i<n;i++){let c=0;for(let f=0;f<o;f++){let y=Number(t[f].iget(i)),l=r[f];if(e==="wrap")y=(y%l+l)%l;else if(e==="clip")y=Math.max(0,Math.min(y,l-1));else if(y<0||y>=l)throw new Error(`index ${y} is out of bounds for axis ${f} with size ${l}`);c+=y*u[f]}a[i]=c}return D.fromData(a,[n],"int32")}function sn(t,r,e="C"){let n=r.length,o,a;if(typeof t=="number")o=[t],a=[];else{o=[];for(let f=0;f<t.size;f++)o.push(Number(t.iget(f)));a=Array.from(t.shape)}let u=o.length,s=r.reduce((f,y)=>f*y,1),i=new Array(n);if(e==="C"){let f=1;for(let y=n-1;y>=0;y--)i[y]=f,f*=r[y]}else{let f=1;for(let y=0;y<n;y++)i[y]=f,f*=r[y]}let c=[];for(let f=0;f<n;f++){let y=new Int32Array(u);c.push(D.fromData(y,a.length?a:[1],"int32"))}for(let f=0;f<u;f++){let y=o[f];if(y<0||y>=s)throw new Error(`index ${y} is out of bounds for array with size ${s}`);if(e==="C")for(let l=0;l<n;l++){let p=Math.floor(y/i[l]);y=y%i[l],c[l].data[f]=p%r[l]}else for(let l=n-1;l>=0;l--){let p=Math.floor(y/i[l]);y=y%i[l],c[l].data[f]=p%r[l]}}return typeof t=="number"?c.map(f=>{let y=f.iget(0);return D.fromData(new Int32Array([Number(y)]),[],"int32")}):c}function j(t,r){if(!wt(t)&&t!=="bool")throw new TypeError(`ufunc '${r}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function fr(t,r){return t.isCContiguous&&r.isCContiguous&&t.shape.length===r.shape.length&&t.shape.every((e,n)=>e===r.shape[n])}function fn(t,r){return j(t.dtype,"bitwise_and"),typeof r=="number"?Io(t,r):(j(r.dtype,"bitwise_and"),fr(t,r)?xo(t,r):V(t,r,(e,n)=>e&n,"bitwise_and"))}function xo(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;if(!w(t.dtype)||!w(r.dtype))for(let f=0;f<o;f++){let y=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof u[f]=="bigint"?u[f]:BigInt(Math.round(Number(u[f])));i[f]=y&l}else{let f=a,y=u;for(let l=0;l<o;l++)i[l]=f[l]&y[l]}}else for(let i=0;i<o;i++)s[i]=a[i]&u[i];return n}function Io(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]&f}else for(let i=0;i<a;i++)s[i]=o[i]&r;return u}function ln(t,r){return j(t.dtype,"bitwise_or"),typeof r=="number"?_o(t,r):(j(r.dtype,"bitwise_or"),fr(t,r)?zo(t,r):V(t,r,(e,n)=>e|n,"bitwise_or"))}function zo(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;if(!w(t.dtype)||!w(r.dtype))for(let f=0;f<o;f++){let y=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof u[f]=="bigint"?u[f]:BigInt(Math.round(Number(u[f])));i[f]=y|l}else{let f=a,y=u;for(let l=0;l<o;l++)i[l]=f[l]|y[l]}}else for(let i=0;i<o;i++)s[i]=a[i]|u[i];return n}function _o(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]|f}else for(let i=0;i<a;i++)s[i]=o[i]|r;return u}function yn(t,r){return j(t.dtype,"bitwise_xor"),typeof r=="number"?Eo(t,r):(j(r.dtype,"bitwise_xor"),fr(t,r)?Bo(t,r):V(t,r,(e,n)=>e^n,"bitwise_xor"))}function Bo(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;if(!w(t.dtype)||!w(r.dtype))for(let f=0;f<o;f++){let y=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof u[f]=="bigint"?u[f]:BigInt(Math.round(Number(u[f])));i[f]=y^l}else{let f=a,y=u;for(let l=0;l<o;l++)i[l]=f[l]^y[l]}}else for(let i=0;i<o;i++)s[i]=a[i]^u[i];return n}function Eo(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]^f}else for(let i=0;i<a;i++)s[i]=o[i]^r;return u}function ut(t){j(t.dtype,"bitwise_not");let r=t.dtype,e=Array.from(t.shape),n=t.data,o=t.size,a=D.zeros(e,r),u=a.data;if(w(r)){let s=n,i=u;for(let c=0;c<o;c++)i[c]=~s[c]}else for(let s=0;s<o;s++)u[s]=~n[s];return a}function pn(t){return ut(t)}function mn(t,r){if(j(t.dtype,"left_shift"),typeof r=="number")return un(t,r);if(j(r.dtype,"left_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){let e=w(r.dtype)?Number(r.data[0]):r.data[0];return un(t,e)}return fr(t,r)?Uo(t,r):V(t,r,(e,n)=>e<<n,"left_shift")}function Uo(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),y=typeof u[c]=="bigint"?u[c]:BigInt(Math.round(Number(u[c])));i[c]=f<<y}}else for(let i=0;i<o;i++)s[i]=a[i]<<u[i];return n}function un(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]<<f}else for(let i=0;i<a;i++)s[i]=o[i]<<r;return u}function dn(t,r){if(j(t.dtype,"right_shift"),typeof r=="number")return cn(t,r);if(j(r.dtype,"right_shift"),r.size===1||r.ndim===1&&r.shape[0]===1){let e=w(r.dtype)?Number(r.data[0]):r.data[0];return cn(t,e)}return fr(t,r)?To(t,r):V(t,r,(e,n)=>e>>n,"right_shift")}function To(t,r){let e=v(t.dtype,r.dtype),n=D.zeros(Array.from(t.shape),e),o=t.size,a=t.data,u=r.data,s=n.data;if(w(e)){let i=s;for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),y=typeof u[c]=="bigint"?u[c]:BigInt(Math.round(Number(u[c])));i[c]=f>>y}}else for(let i=0;i<o;i++)s[i]=a[i]>>u[i];return n}function cn(t,r){let e=t.dtype,n=Array.from(t.shape),o=t.data,a=t.size,u=D.zeros(n,e),s=u.data;if(w(e)){let i=o,c=s,f=BigInt(Math.round(r));for(let y=0;y<a;y++)c[y]=i[y]>>f}else for(let i=0;i<a;i++)s[i]=o[i]>>r;return u}function gn(t,r=-1,e="big"){let n=Array.from(t.shape),o=n.length;if(r<0&&(r=o+r),r<0||r>=o)throw new Error(`axis ${r} is out of bounds for array of dimension ${o}`);let a=n[r],u=Math.ceil(a/8),s=[...n];s[r]=u;let i=D.zeros(s,"uint8"),c=i.data;if(o===1){for(let g=0;g<u;g++){let h=0;for(let A=0;A<8;A++){let b=g*8+A;if(b<a){let S=Number(t.data[b])!==0?1:0;e==="big"?h|=S<<7-A:h|=S<<A}}c[g]=h}return i}let f=n.slice(0,r),y=n.slice(r+1),l=f.reduce((g,h)=>g*h,1),p=y.reduce((g,h)=>g*h,1),m=Er(n),d=Er(s);for(let g=0;g<l;g++)for(let h=0;h<p;h++)for(let A=0;A<u;A++){let b=0;for(let I=0;I<8;I++){let z=A*8+I;if(z<a){let B=0,E=g;for(let F=0;F<r;F++){let W=F<r-1?f.slice(F+1).reduce(($r,vr)=>$r*vr,1):1,X=Math.floor(E/W);E%=W,B+=X*m[F]}B+=z*m[r];let T=h;for(let F=r+1;F<o;F++){let W=F<o-1?y.slice(F-r).reduce(($r,vr)=>$r*vr,1):1,X=Math.floor(T/W);T%=W,B+=X*m[F]}let C=Number(t.data[B])!==0?1:0;e==="big"?b|=C<<7-I:b|=C<<I}}let S=0,N=g;for(let I=0;I<r;I++){let z=I<r-1?f.slice(I+1).reduce((E,T)=>E*T,1):1,B=Math.floor(N/z);N%=z,S+=B*d[I]}S+=A*d[r];let x=h;for(let I=r+1;I<o;I++){let z=I<o-1?y.slice(I-r).reduce((E,T)=>E*T,1):1,B=Math.floor(x/z);x%=z,S+=B*d[I]}c[S]=b}return i}function An(t,r=-1,e=-1,n="big"){if(t.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");let o=Array.from(t.shape),a=o.length;if(r<0&&(r=a+r),r<0||r>=a)throw new Error(`axis ${r} is out of bounds for array of dimension ${a}`);let u=o[r],s=u*8;e>=0&&(s=e);let i=[...o];i[r]=s;let c=D.zeros(i,"uint8"),f=c.data;if(a===1){for(let h=0;h<u;h++){let A=Number(t.data[h]);for(let b=0;b<8;b++){let S=h*8+b;if(S>=s)break;n==="big"?f[S]=A>>7-b&1:f[S]=A>>b&1}}return c}let y=o.slice(0,r),l=o.slice(r+1),p=y.reduce((h,A)=>h*A,1),m=l.reduce((h,A)=>h*A,1),d=Er(o),g=Er(i);for(let h=0;h<p;h++)for(let A=0;A<m;A++)for(let b=0;b<u;b++){let S=0,N=h;for(let z=0;z<r;z++){let B=z<r-1?y.slice(z+1).reduce((T,C)=>T*C,1):1,E=Math.floor(N/B);N%=B,S+=E*d[z]}S+=b*d[r];let x=A;for(let z=r+1;z<a;z++){let B=z<a-1?l.slice(z-r).reduce((T,C)=>T*C,1):1,E=Math.floor(x/B);x%=B,S+=E*d[z]}let I=Number(t.data[S]);for(let z=0;z<8;z++){let B=b*8+z;if(B>=s)break;let E=0;N=h;for(let T=0;T<r;T++){let C=T<r-1?y.slice(T+1).reduce((W,X)=>W*X,1):1,F=Math.floor(N/C);N%=C,E+=F*g[T]}E+=B*g[r],x=A;for(let T=r+1;T<a;T++){let C=T<a-1?l.slice(T-r).reduce((W,X)=>W*X,1):1,F=Math.floor(x/C);x%=C,E+=F*g[T]}n==="big"?f[E]=I>>7-z&1:f[E]=I>>z&1}}return c}function Er(t){let r=t.length,e=new Array(r),n=1;for(let o=r-1;o>=0;o--)e[o]=n,n*=t[o];return e}var _=class t{constructor(r,e){this._storage=r,this._base=e}get storage(){return this._storage}static _fromStorage(r,e){return new t(r,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(r){if(r.length!==this.ndim)throw new Error(`Index has ${r.length} dimensions, but array has ${this.ndim} dimensions`);let e=r.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(r,e){if(r.length!==this.ndim)throw new Error(`Index has ${r.length} dimensions, but array has ${this.ndim} dimensions`);let n=r.map((u,s)=>{let i=u;if(i<0&&(i=this.shape[s]+i),i<0||i>=this.shape[s])throw new Error(`Index ${u} is out of bounds for axis ${s} with size ${this.shape[s]}`);return i}),o=this.dtype,a;w(o)?a=typeof e=="bigint"?e:BigInt(Math.round(e)):o==="bool"?a=e?1:0:a=Number(e),this._storage.set(n,a)}copy(){return new t(this._storage.copy())}astype(r,e=!0){let n=this.dtype;if(n===r&&!e)return this;if(n===r&&e)return this.copy();let o=Array.from(this.shape),a=this.size,u=U(r);if(!u)throw new Error(`Cannot convert to dtype ${r}`);let s=new u(a),i=this.data;if(w(n)&&!w(r)){let f=i;if(r==="bool")for(let y=0;y<a;y++)s[y]=f[y]!==BigInt(0)?1:0;else for(let y=0;y<a;y++)s[y]=Number(f[y])}else if(!w(n)&&w(r)){let f=i;for(let y=0;y<a;y++)s[y]=BigInt(Math.round(Number(f[y])))}else if(r==="bool"){let f=i;for(let y=0;y<a;y++)s[y]=f[y]!==0?1:0}else if(n==="bool"&&!w(r)){let f=i;for(let y=0;y<a;y++)s[y]=f[y]}else if(!w(n)&&!w(r)){let f=i;for(let y=0;y<a;y++)s[y]=f[y]}else{let f=i;for(let y=0;y<a;y++)s[y]=f[y]}let c=D.fromData(s,o,r);return new t(c)}add(r){let e=typeof r=="number"?r:r._storage,n=It(this._storage,e);return t._fromStorage(n)}subtract(r){let e=typeof r=="number"?r:r._storage,n=zt(this._storage,e);return t._fromStorage(n)}multiply(r){let e=typeof r=="number"?r:r._storage,n=_t(this._storage,e);return t._fromStorage(n)}divide(r){let e=typeof r=="number"?r:r._storage,n=Bt(this._storage,e);return t._fromStorage(n)}mod(r){let e=typeof r=="number"?r:r._storage,n=dr(this._storage,e);return t._fromStorage(n)}floor_divide(r){let e=typeof r=="number"?r:r._storage,n=Cr(this._storage,e);return t._fromStorage(n)}positive(){let r=Ot(this._storage);return t._fromStorage(r)}reciprocal(){let r=$t(this._storage);return t._fromStorage(r)}sqrt(){let r=xe(this._storage);return t._fromStorage(r)}power(r){let e=typeof r=="number"?r:r._storage,n=Ie(this._storage,e);return t._fromStorage(n)}absolute(){let r=Et(this._storage);return t._fromStorage(r)}negative(){let r=Ut(this._storage);return t._fromStorage(r)}sign(){let r=Tt(this._storage);return t._fromStorage(r)}sin(){let r=ze(this._storage);return t._fromStorage(r)}cos(){let r=_e(this._storage);return t._fromStorage(r)}tan(){let r=Be(this._storage);return t._fromStorage(r)}arcsin(){let r=Ee(this._storage);return t._fromStorage(r)}arccos(){let r=Ue(this._storage);return t._fromStorage(r)}arctan(){let r=Te(this._storage);return t._fromStorage(r)}arctan2(r){let e=typeof r=="number"?r:r._storage,n=Oe(this._storage,e);return t._fromStorage(n)}hypot(r){let e=typeof r=="number"?r:r._storage,n=$e(this._storage,e);return t._fromStorage(n)}degrees(){let r=ve(this._storage);return t._fromStorage(r)}radians(){let r=Me(this._storage);return t._fromStorage(r)}sinh(){let r=Ce(this._storage);return t._fromStorage(r)}cosh(){let r=ke(this._storage);return t._fromStorage(r)}tanh(){let r=Ve(this._storage);return t._fromStorage(r)}arcsinh(){let r=Fe(this._storage);return t._fromStorage(r)}arccosh(){let r=Pe(this._storage);return t._fromStorage(r)}arctanh(){let r=Re(this._storage);return t._fromStorage(r)}greater(r){let e=typeof r=="number"?r:r._storage,n=Pt(this._storage,e);return t._fromStorage(n)}greater_equal(r){let e=typeof r=="number"?r:r._storage,n=Rt(this._storage,e);return t._fromStorage(n)}less(r){let e=typeof r=="number"?r:r._storage,n=Lt(this._storage,e);return t._fromStorage(n)}less_equal(r){let e=typeof r=="number"?r:r._storage,n=qt(this._storage,e);return t._fromStorage(n)}equal(r){let e=typeof r=="number"?r:r._storage,n=jt(this._storage,e);return t._fromStorage(n)}not_equal(r){let e=typeof r=="number"?r:r._storage,n=Zt(this._storage,e);return t._fromStorage(n)}isclose(r,e=1e-5,n=1e-8){let o=typeof r=="number"?r:r._storage,a=Vr(this._storage,o,e,n);return t._fromStorage(a)}allclose(r,e=1e-5,n=1e-8){let o=typeof r=="number"?r:r._storage;return Wt(this._storage,o,e,n)}bitwise_and(r){let e=typeof r=="number"?r:r._storage,n=fn(this._storage,e);return t._fromStorage(n)}bitwise_or(r){let e=typeof r=="number"?r:r._storage,n=ln(this._storage,e);return t._fromStorage(n)}bitwise_xor(r){let e=typeof r=="number"?r:r._storage,n=yn(this._storage,e);return t._fromStorage(n)}bitwise_not(){let r=ut(this._storage);return t._fromStorage(r)}invert(){let r=pn(this._storage);return t._fromStorage(r)}left_shift(r){let e=typeof r=="number"?r:r._storage,n=mn(this._storage,e);return t._fromStorage(n)}right_shift(r){let e=typeof r=="number"?r:r._storage,n=dn(this._storage,e);return t._fromStorage(n)}sum(r,e=!1){let n=or(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}mean(r,e=!1){let n=gr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}max(r,e=!1){let n=Ar(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}min(r,e=!1){let n=hr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}prod(r,e=!1){let n=Fr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}argmin(r){let e=Pr(this._storage,r);return typeof e=="number"?e:t._fromStorage(e)}argmax(r){let e=Rr(this._storage,r);return typeof e=="number"?e:t._fromStorage(e)}var(r,e=0,n=!1){let o=Lr(this._storage,r,e,n);return typeof o=="number"?o:t._fromStorage(o)}std(r,e=0,n=!1){let o=Yt(this._storage,r,e,n);return typeof o=="number"?o:t._fromStorage(o)}all(r,e=!1){let n=qr(this._storage,r,e);return typeof n=="boolean"?n:t._fromStorage(n)}any(r,e=!1){let n=jr(this._storage,r,e);return typeof n=="boolean"?n:t._fromStorage(n)}cumsum(r){return t._fromStorage(Zr(this._storage,r))}cumprod(r){return t._fromStorage(Wr(this._storage,r))}ptp(r,e=!1){let n=Hr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}median(r,e=!1){let n=Yr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}percentile(r,e,n=!1){let o=Gr(this._storage,r,e,n);return typeof o=="number"?o:t._fromStorage(o)}quantile(r,e,n=!1){let o=tr(this._storage,r,e,n);return typeof o=="number"?o:t._fromStorage(o)}average(r,e){let n=br(this._storage,e,r?.storage);return typeof n=="number"?n:t._fromStorage(n)}nansum(r,e=!1){let n=Sr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}nanprod(r,e=!1){let n=Dr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}nanmean(r,e=!1){let n=Nr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}nanvar(r,e=0,n=!1){let o=ar(this._storage,r,e,n);return typeof o=="number"?o:t._fromStorage(o)}nanstd(r,e=0,n=!1){let o=Jr(this._storage,r,e,n);return typeof o=="number"?o:t._fromStorage(o)}nanmin(r,e=!1){let n=wr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}nanmax(r,e=!1){let n=xr(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}nanargmin(r){let e=Ir(this._storage,r);return typeof e=="number"?e:t._fromStorage(e)}nanargmax(r){let e=zr(this._storage,r);return typeof e=="number"?e:t._fromStorage(e)}nancumsum(r){return t._fromStorage(Xr(this._storage,r))}nancumprod(r){return t._fromStorage(Qr(this._storage,r))}nanmedian(r,e=!1){let n=_r(this._storage,r,e);return typeof n=="number"?n:t._fromStorage(n)}reshape(...r){let e=r.length===1&&Array.isArray(r[0])?r[0]:r,n=q(this._storage,e),a=n.data===this.data?this._base??this:void 0;return t._fromStorage(n,a)}flatten(){let r=Br(this._storage);return t._fromStorage(r)}ravel(){let r=ir(this._storage),n=r.data===this.data?this._base??this:void 0;return t._fromStorage(r,n)}transpose(r){let e=ur(this._storage,r),n=this._base??this;return t._fromStorage(e,n)}squeeze(r){let e=Gt(this._storage,r),n=this._base??this;return t._fromStorage(e,n)}expand_dims(r){let e=sr(this._storage,r),n=this._base??this;return t._fromStorage(e,n)}swapaxes(r,e){let n=Jt(this._storage,r,e),o=this._base??this;return t._fromStorage(n,o)}moveaxis(r,e){let n=Kr(this._storage,r,e),o=this._base??this;return t._fromStorage(n,o)}repeat(r,e){let n=ae(this._storage,r,e);return t._fromStorage(n)}take(r,e){let n=qe(this._storage,r,e);return t._fromStorage(n)}put(r,e){let n=e instanceof t?e._storage:e;je(this._storage,r,n)}matmul(r){let e=K(this._storage,r._storage);return t._fromStorage(e)}dot(r){let e=et(this._storage,r._storage);return typeof e=="number"||typeof e=="bigint"?e:t._fromStorage(e)}trace(){return he(this._storage)}inner(r){let e=be(this._storage,r._storage);return typeof e=="number"||typeof e=="bigint"?e:t._fromStorage(e)}outer(r){let e=nt(this._storage,r._storage);return t._fromStorage(e)}tensordot(r,e=2){let n=Se(this._storage,r._storage,e);return typeof n=="number"||typeof n=="bigint"?n:t._fromStorage(n)}cbrt(){let r=vt(this._storage);return t._fromStorage(r)}fabs(){let r=Mt(this._storage);return t._fromStorage(r)}divmod(r){let e=typeof r=="number"?r:r._storage,[n,o]=Ct(this._storage,e);return[t._fromStorage(n),t._fromStorage(o)]}square(){let r=kt(this._storage);return t._fromStorage(r)}remainder(r){let e=typeof r=="number"?r:r._storage,n=Vt(this._storage,e);return t._fromStorage(n)}heaviside(r){let e=typeof r=="number"?r:r._storage,n=Ft(this._storage,e);return t._fromStorage(n)}slice(...r){if(r.length===0)return this;if(r.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${r.length} were indexed`);let e=r.map((i,c)=>{let f=bt(i);return St(f,this.shape[c])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});let n=[],o=[],a=this._storage.offset;for(let i=0;i<e.length;i++){let c=e[i],f=this._storage.strides[i];if(a+=c.start*f,!c.isIndex){let y;c.step>0?y=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):y=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(y),o.push(f*c.step)}}let u=D.fromData(this._storage.data,n,this._storage.dtype,o,a),s=this._base??this;return new t(u,s)}row(r){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(r),":")}col(r){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(r))}rows(r,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${r}:${e}`,":")}cols(r,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${r}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let r=this.shape,e=r.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let u=[];for(let s=0;s<r[a];s++)o[a]=s,u.push(n(o,a+1));return u};return n(new Array(e),0)}};function H(t,r=M){let e=D.zeros(t,r);return new _(e)}function hn(t,r=M){let e=D.ones(t,r);return new _(e)}function $o(t){let r=[],e=t;for(;Array.isArray(e);)r.push(e.length),e=e[0];return r}function bn(t){return typeof t=="bigint"?!0:Array.isArray(t)?t.some(r=>bn(r)):!1}function vo(t){let r=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):r.push(n)}return e(t),r}function R(t,r){if(t instanceof _)return!r||t.dtype===r?t.copy():t.astype(r);let e=bn(t),n=$o(t),o=n.reduce((f,y)=>f*y,1),a=r;a||(e?a="int64":a=M);let u=U(a);if(!u)throw new Error(`Cannot create array with dtype ${a}`);let s=new u(o),i=vo(t);if(w(a)){let f=s;for(let y=0;y<o;y++){let l=i[y];f[y]=typeof l=="bigint"?l:BigInt(Math.round(Number(l)))}}else if(a==="bool"){let f=s;for(let y=0;y<o;y++)f[y]=i[y]?1:0}else{let f=s;for(let y=0;y<o;y++){let l=i[y];f[y]=Number(l)}}let c=D.fromData(s,n,a);return new _(c)}function Mo(t,r,e=1,n=M){let o=t,a=r;if(r===void 0&&(o=0,a=t),a===void 0)throw new Error("stop is required");let u=Math.max(0,Math.ceil((a-o)/e)),s=U(n);if(!s)throw new Error(`Cannot create arange array with dtype ${n}`);let i=new s(u);if(w(n))for(let f=0;f<u;f++)i[f]=BigInt(Math.round(o+f*e));else if(n==="bool")for(let f=0;f<u;f++)i[f]=o+f*e!==0?1:0;else for(let f=0;f<u;f++)i[f]=o+f*e;let c=D.fromData(i,[u],n);return new _(c)}function Co(t,r,e=50,n=M){if(e<0)throw new Error("num must be non-negative");if(e===0)return R([],n);if(e===1)return R([t],n);let o=U(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),u=(r-t)/(e-1);if(w(n))for(let i=0;i<e;i++)a[i]=BigInt(Math.round(t+i*u));else if(n==="bool")for(let i=0;i<e;i++)a[i]=t+i*u!==0?1:0;else for(let i=0;i<e;i++)a[i]=t+i*u;let s=D.fromData(a,[e],n);return new _(s)}function ko(t,r,e=50,n=10,o=M){if(e<0)throw new Error("num must be non-negative");if(e===0)return R([],o);if(e===1)return R([Math.pow(n,t)],o);let a=U(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let u=new a(e),s=(r-t)/(e-1);if(w(o))for(let c=0;c<e;c++){let f=t+c*s;u[c]=BigInt(Math.round(Math.pow(n,f)))}else if(o==="bool")for(let c=0;c<e;c++){let f=t+c*s;u[c]=Math.pow(n,f)!==0?1:0}else for(let c=0;c<e;c++){let f=t+c*s;u[c]=Math.pow(n,f)}let i=D.fromData(u,[e],o);return new _(i)}function Vo(t,r,e=50,n=M){if(e<0)throw new Error("num must be non-negative");if(t===0||r===0)throw new Error("Geometric sequence cannot include zero");if(e===0)return R([],n);if(e===1)return R([t],n);let o=Math.sign(t),a=Math.sign(r);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let u=U(n);if(!u)throw new Error(`Cannot create geomspace array with dtype ${n}`);let s=new u(e),i=Math.log(Math.abs(t)),f=(Math.log(Math.abs(r))-i)/(e-1);if(w(n))for(let l=0;l<e;l++){let p=o*Math.exp(i+l*f);s[l]=BigInt(Math.round(p))}else if(n==="bool")for(let l=0;l<e;l++){let p=o*Math.exp(i+l*f);s[l]=p!==0?1:0}else for(let l=0;l<e;l++){let p=o*Math.exp(i+l*f);s[l]=p}let y=D.fromData(s,[e],n);return new _(y)}function Sn(t,r,e=0,n=M){let o=r??t,a=H([t,o],n),u=a.data;if(w(n)){let s=u;for(let i=0;i<t;i++){let c=i+e;c>=0&&c<o&&(s[i*o+c]=BigInt(1))}}else{let s=u;for(let i=0;i<t;i++){let c=i+e;c>=0&&c<o&&(s[i*o+c]=1)}}return a}function Dn(t,r=M){return H(t,r)}function Nn(t,r,e){let n=e;n||(typeof r=="bigint"?n="int64":typeof r=="boolean"?n="bool":Number.isInteger(r)?n="int32":n=M);let o=U(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=t.reduce((i,c)=>i*c,1),u=new o(a);if(w(n)){let i=typeof r=="bigint"?r:BigInt(Math.round(Number(r)));u.fill(i)}else n==="bool"?u.fill(r?1:0):u.fill(Number(r));let s=D.fromData(u,t,n);return new _(s)}function Fo(t,r=M){return Sn(t,t,0,r)}function Ur(t,r){return t instanceof _?!r||t.dtype===r?t:t.astype(r):R(t,r)}function Po(t){return t.copy()}function Ro(t,r){return H(Array.from(t.shape),r??t.dtype)}function Lo(t,r){return hn(Array.from(t.shape),r??t.dtype)}function qo(t,r){return Dn(Array.from(t.shape),r??t.dtype)}function jo(t,r,e){return Nn(Array.from(t.shape),r,e??t.dtype)}function Zo(t,r){return Ur(t,r)}function Wo(t,r){let e=Ur(t,r);return e.flags.C_CONTIGUOUS?e:e.copy()}function Ho(t,r){return Ur(t,r).copy()}function wn(t,r=0){if(t.ndim===1){let e=t.size,n=e+Math.abs(r),o=H([n,n],t.dtype);for(let a=0;a<e;a++){let u=r>=0?a:a-r,s=r>=0?a+r:a;o.set([u,s],t.get([a]))}return o}else if(t.ndim===2){let[e,n]=t.shape,o,a,u;if(r>=0?(o=0,a=r,u=Math.min(e,n-r)):(o=-r,a=0,u=Math.min(e+r,n)),u<=0)return H([0],t.dtype);let s=U(t.dtype),i=new s(u);for(let f=0;f<u;f++){let y=t.get([o+f,a+f]);w(t.dtype)?i[f]=typeof y=="bigint"?y:BigInt(y):i[f]=y}let c=D.fromData(i,[u],t.dtype);return new _(c)}else throw new Error("Input must be 1-D or 2-D")}function Yo(t,r=0){let e=t.flatten();return wn(e,r)}function Go(t,r,e=M){let n=r.reduce((c,f)=>c*f,1),o=U(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),u=r.length,s=new Array(u).fill(0);for(let c=0;c<n;c++){let f=t(...s);w(e)?a[c]=typeof f=="bigint"?f:BigInt(Number(f)):e==="bool"?a[c]=f?1:0:a[c]=Number(f);for(let y=u-1;y>=0&&(s[y]++,!(s[y]<r[y]));y--)s[y]=0}let i=D.fromData(a,r,e);return new _(i)}function Jo(...t){let r=[],e="xy";for(let s of t)s instanceof _?r.push(s):typeof s=="object"&&"indexing"in s&&(e=s.indexing||"xy");if(r.length===0)return[];if(r.length===1)return[r[0].copy()];let n=r.map(s=>s.size);e==="xy"&&r.length>=2&&(r=[r[1],r[0],...r.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,u=[];for(let s=0;s<r.length;s++){let i=r[s],c=i.size,f=new Array(a).fill(1);f[s]=c;let y=i.reshape(...f),l=ot(y.storage,o),p=_._fromStorage(l.copy());u.push(p)}return e==="xy"&&u.length>=2&&([u[0],u[1]]=[u[1],u[0]]),u}function Xo(t,r,e=0,n=M){let o=r??t,a=H([t,o],n);for(let u=0;u<t;u++)for(let s=0;s<=u+e&&s<o;s++)s>=0&&a.set([u,s],1);return a}function Qo(t,r=0){if(t.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=t.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],u=n.slice(0,-2).reduce((s,i)=>s*i,1);for(let s=0;s<u;s++)for(let i=0;i<o;i++)for(let c=0;c<a;c++)if(c>i+r){let f=[],y=s;for(let l=n.length-3;l>=0;l--)f.unshift(y%n[l]),y=Math.floor(y/n[l]);f.push(i,c),e.set(f,0)}return e}function Ko(t,r=0){if(t.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=t.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],u=n.slice(0,-2).reduce((s,i)=>s*i,1);for(let s=0;s<u;s++)for(let i=0;i<o;i++)for(let c=0;c<a;c++)if(c<i+r){let f=[],y=s;for(let l=n.length-3;l>=0;l--)f.unshift(y%n[l]),y=Math.floor(y/n[l]);f.push(i,c),e.set(f,0)}return e}function ra(t,r,e=!1){if(t.ndim!==1)throw new Error("Input must be 1-D");let n=t.size,o=r??n;if(o<0)throw new Error("N must be non-negative");let a=H([n,o],t.dtype);for(let u=0;u<n;u++){let s=t.get([u]);for(let i=0;i<o;i++){let c=e?i:o-1-i;a.set([u,i],Math.pow(s,c))}}return a}function ta(t,r=M,e=-1,n=0){let o,a=n;t instanceof ArrayBuffer?o=t:(o=t.buffer,a+=t.byteOffset);let u=aa(r),s=o.byteLength-a,i=Math.floor(s/u),c=e<0?i:Math.min(e,i);if(c<=0)return R([],r);let f=U(r);if(!f)throw new Error(`Unsupported dtype: ${r}`);let y=new f(o,a,c),l=D.fromData(y,[c],r);return new _(l)}function ea(t,r=M,e=-1){let n=[],o=0;for(let a of t){if(e>=0&&o>=e)break;n.push(a),o++}return R(n,r)}function na(t,r=M,e=-1){let n=[],o=0;for(let a of t){if(e>=0&&o>=e)break;n.push(a),o++}return R(n,r)}function oa(t,r=M,e=-1,n=""){let o;n===""?o=t.trim().split(/\s+/):o=t.split(n);let a=[],u=0;for(let s of o){if(e>=0&&u>=e)break;let i=s.trim();i!==""&&(w(r)?a.push(BigInt(i)):a.push(parseFloat(i)),u++)}return R(a,r)}function aa(t){switch(t){case"int8":case"uint8":case"bool":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;case"int64":case"uint64":case"float64":return 8;default:return 8}}function sa(t){return t.sqrt()}function ia(t,r){return t.power(r)}function ua(t){return t.absolute()}function ca(t){return t.negative()}function fa(t){return t.sign()}function la(t,r){return t.mod(r)}function ya(t,r){return t.floor_divide(r)}function pa(t){return t.positive()}function ma(t){return t.reciprocal()}function da(t,r){return t.dot(r)}function ga(t){return t.trace()}function Aa(t,r=0,e=0,n=1){let o=De(t.storage,r,e,n);return _._fromStorage(o)}function ha(t,r){let e=we(t.storage,r.storage);return _._fromStorage(e)}function ba(t,r){return t.transpose(r)}function Sa(t,r){return t.inner(r)}function Da(t,r){return t.outer(r)}function Na(t,r,e=2){return t.tensordot(r,e)}function wa(t){return t.sin()}function xa(t){return t.cos()}function Ia(t){return t.tan()}function za(t){return t.arcsin()}function _a(t){return t.arccos()}function Ba(t){return t.arctan()}function Ea(t,r){return t.arctan2(r)}function Ua(t,r){return t.hypot(r)}function Ta(t){return t.degrees()}function Oa(t){return t.radians()}function $a(t){return t.radians()}function va(t){return t.degrees()}function Ma(t){return t.sinh()}function Ca(t){return t.cosh()}function ka(t){return t.tanh()}function Va(t){return t.arcsinh()}function Fa(t){return t.arccosh()}function Pa(t){return t.arctanh()}function Ra(t,r,e){return t.swapaxes(r,e)}function La(t,r,e){return t.moveaxis(r,e)}function er(t,r=0){if(t.length===0)throw new Error("need at least one array to concatenate");let e=t.map(o=>o.storage),n=Q(e,r);return _._fromStorage(n)}function qa(t,r=0){if(t.length===0)throw new Error("need at least one array to stack");let e=t.map(o=>o.storage),n=Xt(e,r);return _._fromStorage(n)}function xn(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(n=>n.storage),e=Qt(r);return _._fromStorage(e)}function ja(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(n=>n.storage),e=rt(r);return _._fromStorage(e)}function Za(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(n=>n.storage),e=Kt(r);return _._fromStorage(e)}function Wa(t,r,e=0){return re(t.storage,r,e).map(o=>_._fromStorage(o,t.base??t))}function Ha(t,r,e=0){return cr(t.storage,r,e).map(o=>_._fromStorage(o,t.base??t))}function Ya(t,r){return ee(t.storage,r).map(n=>_._fromStorage(n,t.base??t))}function Ga(t,r){return ne(t.storage,r).map(n=>_._fromStorage(n,t.base??t))}function Ja(t,r){let e=oe(t.storage,r);return _._fromStorage(e)}function Xa(t,r,e){return t.repeat(r,e)}function Qa(t){return t.ravel()}function Ka(t,r){return t.reshape(...r)}function rs(t,r){return t.squeeze(r)}function ts(t,r){return t.expand_dims(r)}function ct(t,r){let e=se(t.storage,r);return _._fromStorage(e)}function es(t){if(t.ndim<2)throw new Error("Input must be at least 2-D");return ct(t,1)}function ns(t){if(t.ndim<2)throw new Error("Input must be at least 2-D");return ct(t,0)}function os(t,r=1,e=[0,1]){let n=ie(t.storage,r,e);return _._fromStorage(n)}function as(t,r,e){let n=ue(t.storage,r,e);return _._fromStorage(n)}function ss(t,r,e=0){let n=ce(t.storage,r,e);return _._fromStorage(n,t.base??t)}function is(...t){let r=t.map(o=>o.storage),n=pe(r).map((o,a)=>o===r[a]?t[a]:_._fromStorage(o));return n.length===1?n[0]:n}function us(...t){let r=t.map(o=>o.storage),n=me(r).map((o,a)=>o===r[a]?t[a]:_._fromStorage(o));return n.length===1?n[0]:n}function cs(...t){let r=t.map(o=>o.storage),n=de(r).map((o,a)=>o===r[a]?t[a]:_._fromStorage(o));return n.length===1?n[0]:n}function fs(t,r){return fe(t.storage,r).map(n=>_._fromStorage(n,t.base??t))}function ls(t){if(t.length===0)throw new Error("need at least one array to stack");let r=t.map(n=>n.storage),e=le(r);return _._fromStorage(e)}function ys(t){return xn(t)}function ps(t,r){let e=ye(t.storage,r);return _._fromStorage(e)}function ms(t,r,e){let n=r instanceof _?r:R(r,t.dtype);if(e===void 0){let o=t.flatten(),a=n.flatten();return er([o,a])}return er([t,n],e)}function ds(t,r,e){let n=t.dtype;if(e===void 0){let p=t.flatten(),d=(Array.isArray(r)?r:[r]).map(S=>S<0?p.size+S:S),g=[];for(let S=0;S<p.size;S++)d.includes(S)||g.push(S);let h=U(n),A=new h(g.length);for(let S=0;S<g.length;S++){let N=p.get([g[S]]);w(n)?A[S]=typeof N=="bigint"?N:BigInt(N):A[S]=N}let b=D.fromData(A,[g.length],n);return new _(b)}let o=t.shape,a=o.length,u=e<0?a+e:e;if(u<0||u>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let s=o[u],i=Array.isArray(r)?r:[r],c=new Set(i.map(p=>p<0?s+p:p)),f=[],y=0;for(let p=0;p<=s;p++)(c.has(p)||p===s)&&(p>y&&f.push([y,p]),y=p+1);if(f.length===0){let p=[...o];return p[u]=0,H(p,n)}let l=[];for(let[p,m]of f){let d=o.map(()=>":");d[u]=`${p}:${m}`,l.push(t.slice(...d))}return er(l,u)}function gs(t,r,e,n){let o=e instanceof _?e:R(e,t.dtype);if(n===void 0){let y=t.flatten(),l=o.flatten(),p=r<0?y.size+r:r;if(p<0||p>y.size)throw new Error(`index ${r} is out of bounds for array of size ${y.size}`);let m=p>0?y.slice(`0:${p}`):null,d=p<y.size?y.slice(`${p}:`):null,g=[];return m&&g.push(m),g.push(l),d&&g.push(d),er(g)}let a=t.shape,u=a.length,s=n<0?u+n:n;if(s<0||s>=u)throw new Error(`axis ${n} is out of bounds for array of dimension ${u}`);let i=a[s],c=r<0?i+r:r;if(c<0||c>i)throw new Error(`index ${r} is out of bounds for axis ${n} with size ${i}`);let f=[];if(c>0){let y=a.map(()=>":");y[s]=`0:${c}`,f.push(t.slice(...y))}if(f.push(o),c<i){let y=a.map(()=>":");y[s]=`${c}:`,f.push(t.slice(...y))}return er(f,s)}function As(t,r,e="constant",n=0){let o=t.shape,a=o.length,u=t.dtype,s;if(typeof r=="number"?s=o.map(()=>[r,r]):Array.isArray(r)&&typeof r[0]=="number"?s=o.map(()=>r):s=r,s.length!==a)throw new Error(`pad_width must have ${a} elements`);let i=o.map((d,g)=>d+s[g][0]+s[g][1]),c=i.reduce((d,g)=>d*g,1),f=U(u),y=new f(c),l=w(u);e==="constant"&&(l?y.fill(BigInt(n)):y.fill(n));let p=new Array(a).fill(0);for(let d=0;d<c;d++){let g=!0,h=[];for(let b=0;b<a;b++){let[S]=s[b],N=p[b]-S;if(N<0||N>=o[b]){g=!1;break}h.push(N)}let A;if(g)A=t.get(h);else if(e==="constant"){for(let b=a-1;b>=0&&(p[b]++,!(p[b]<i[b]));b--)p[b]=0;continue}else{let b=[];for(let S=0;S<a;S++){let[N]=s[S],x=p[S]-N,I=o[S];x<0?e==="edge"?x=0:e==="reflect"?(x=-x,x>=I&&(x=I-1)):e==="symmetric"?(x=-x-1,x>=I&&(x=I-1),x<0&&(x=0)):e==="wrap"&&(x=(x%I+I)%I):x>=I&&(e==="edge"?x=I-1:e==="reflect"?(x=2*I-x-2,x<0&&(x=0)):e==="symmetric"?(x=2*I-x-1,x<0&&(x=0)):e==="wrap"&&(x=x%I)),b.push(Math.max(0,Math.min(I-1,x)))}A=t.get(b)}l?y[d]=typeof A=="bigint"?A:BigInt(Number(A)):y[d]=Number(A);for(let b=a-1;b>=0&&(p[b]++,!(p[b]<i[b]));b--)p[b]=0}let m=D.fromData(y,i,u);return new _(m)}function hs(t,r){let e=ot(t.storage,r);return _._fromStorage(e,t.base??t)}function bs(...t){let r=t.map(n=>n.storage);return Le(r).map((n,o)=>_._fromStorage(n,t[o].base??t[o]))}function Ss(...t){return kr(...t)}function Ds(t,r,e){return t.take(r,e)}function Ns(t,r,e){t.put(r,e)}function ws(t,r){let e=r.map(o=>o.storage),n=Ze(t.storage,e);return _._fromStorage(n)}function xs(t,r,e=!1){return We(t.storage,r.storage,e)}function Is(t,r){return Ht(t.storage,r.storage)}function zs(t,r){return _._fromStorage(Zr(t.storage,r))}function _s(t,r){return _._fromStorage(Wr(t.storage,r))}function Bs(t,r,e=!1){let n=Hr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Es(t,r,e=!1){let n=Yr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Us(t,r,e,n=!1){let o=Gr(t.storage,r,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Ts(t,r,e,n=!1){let o=tr(t.storage,r,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Os(t,r,e,n=!1){let o=e?e.storage:void 0,a=br(t.storage,r,o,n);return typeof a=="number"?a:_._fromStorage(a)}function $s(t,r,e=!1){let n=Sr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function vs(t,r,e=!1){let n=Dr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Ms(t,r,e=!1){let n=Nr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Cs(t,r,e=0,n=!1){let o=ar(t.storage,r,e,n);return typeof o=="number"?o:_._fromStorage(o)}function ks(t,r,e=0,n=!1){let o=Jr(t.storage,r,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Vs(t,r,e=!1){let n=wr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Fs(t,r,e=!1){let n=xr(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Ps(t,r){let e=Ir(t.storage,r);return typeof e=="number"?e:_._fromStorage(e)}function Rs(t,r){let e=zr(t.storage,r);return typeof e=="number"?e:_._fromStorage(e)}function Ls(t,r){return _._fromStorage(Xr(t.storage,r))}function qs(t,r){return _._fromStorage(Qr(t.storage,r))}function js(t,r,e=!1){let n=_r(t.storage,r,e);return typeof n=="number"?n:_._fromStorage(n)}function Zs(t){return t.cbrt()}function Ws(t){return t.fabs()}function Hs(t,r){return t.divmod(r)}function Ys(t){return t.square()}function Gs(t,r){return t.remainder(r)}function Js(t,r){return t.heaviside(r)}function Xs(t,r){return t.bitwise_and(r)}function Qs(t,r){return t.bitwise_or(r)}function Ks(t,r){return t.bitwise_xor(r)}function ri(t){return t.bitwise_not()}function ti(t){return t.invert()}function ei(t,r){return t.left_shift(r)}function ni(t,r){return t.right_shift(r)}function oi(t,r=-1,e="big"){let n=gn(t.storage,r,e);return _._fromStorage(n)}function ai(t,r=-1,e=-1,n="big"){let o=An(t.storage,r,e,n);return _._fromStorage(o)}function si(t,...r){let e=r.map(o=>o.storage),n=Ne(t,...e);return typeof n=="number"||typeof n=="bigint"?n:_._fromStorage(n)}function ii(t,r,e){return _._fromStorage(He(t.storage,r.storage,e))}function ui(t,r,e,n){Ye(t.storage,r.storage,e.storage,n)}function ci(t,r,e){let n=e instanceof _?e.storage:e;Ge(t.storage,r.storage,n)}function fi(t,r,e){return _._fromStorage(Je(t.storage,r.storage,e))}function li(t,r,e=0){let n=t.map(a=>a.storage),o=r.map(a=>a.storage);return _._fromStorage(Xe(n,o,e))}function yi(t,r,e){Qe(t.storage,r.storage,e.storage)}function pi(t,r=2){return at(t,r).map(n=>_._fromStorage(n))}function mi(t){return Ke(t.storage).map(e=>_._fromStorage(e))}function di(t,r=0,e){return st(t,r,e).map(o=>_._fromStorage(o))}function gi(t,r=0){return rn(t.storage,r).map(n=>_._fromStorage(n))}function Ai(t,r=0,e){return it(t,r,e).map(o=>_._fromStorage(o))}function hi(t,r=0){return tn(t.storage,r).map(n=>_._fromStorage(n))}function bi(t,r,e=0){return en(t,(a,u)=>r(a,u).storage,e).map(a=>_._fromStorage(a))}function Si(t,r="int32"){return _._fromStorage(nn(t,r))}function Di(...t){return on(...t.map(e=>e.storage)).map(e=>_._fromStorage(e))}function Ni(t,r,e="raise"){let n=t.map(o=>o.storage);return _._fromStorage(an(n,r,e))}function wi(t,r,e="C"){let n=t instanceof _?t.storage:t;return sn(n,r,e).map(a=>_._fromStorage(a))}var lr=new Uint8Array([147,78,85,77,80,89]),ft=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];function lt(){let t=new ArrayBuffer(2);return new DataView(t).setInt16(0,256,!0),new Int16Array(t)[0]===256}var xi={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},Tr={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},In={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};function zn(t){if(t.startsWith("[")||t.startsWith("("))throw new Y(`Structured/compound dtypes are not supported: ${t}`);let r="",e=t;(t[0]==="<"||t[0]===">"||t[0]==="="||t[0]==="|")&&(r=t[0],e=t.slice(1));let n=e[0];if(n&&n in In)throw new Y(`Unsupported dtype: ${In[n]} (${t}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=xi[e];if(!o)throw new Y(`Unknown or unsupported dtype descriptor: ${t}. Supported types: ${ft.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=lt(),u=r==="<"||r==="|"||r==="="&&a,s=r===">"||r==="="&&!a,i=parseInt(e.slice(1),10),c=i>1&&(s&&a||u&&!a);return{dtype:o,needsByteSwap:c,itemsize:i}}var Y=class extends Error{constructor(r){super(r),this.name="UnsupportedDTypeError"}},L=class extends Error{constructor(r){super(r),this.name="InvalidNpyError"}};function Or(t){let r=t instanceof ArrayBuffer?new Uint8Array(t):t,e=yt(r);return pt(r,e)}function yt(t){if(t.length<10)throw new L("File too small to be a valid NPY file");for(let c=0;c<lr.length;c++)if(t[c]!==lr[c])throw new L("Invalid NPY magic number");let r=t[6],e=t[7];if(r!==1&&r!==2&&r!==3)throw new L(`Unsupported NPY version: ${r}.${e}`);let n,o;r===1?(n=t[8]|t[9]<<8,o=10):(n=t[8]|t[9]<<8|t[10]<<16|t[11]<<24,o=12);let a=o+n;if(t.length<a)throw new L("File truncated: header extends beyond file");let u=t.slice(o,a),s=new TextDecoder("utf-8").decode(u).trim(),i=Ii(s);return{version:{major:r,minor:e},header:i,dataOffset:a}}function pt(t,r){let{header:e,dataOffset:n}=r,{dtype:o,needsByteSwap:a,itemsize:u}=zn(e.descr),s=e.shape.reduce((d,g)=>d*g,1),i=s*u,c=t.length-n;if(c<i)throw new L(`File truncated: expected ${i} bytes of data, got ${c}`);let f=new ArrayBuffer(i);new Uint8Array(f).set(t.subarray(n,n+i));let l=zi(f,o,s,a,u),p=e.shape,m;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),g=D.fromData(l,d,o);m=_i(g,d),p=e.shape}else m=D.fromData(l,[...p],o);return new _(m)}function Ii(t){let r=t.match(/'descr'\s*:\s*'([^']+)'/),e=t.match(/'fortran_order'\s*:\s*(True|False)/),n=t.match(/'shape'\s*:\s*\(([^)]*)\)/);if(!r||!e||!n)throw new L(`Failed to parse NPY header: ${t}`);let o=r[1],a=e[1]==="True",u=n[1].trim(),s;return u===""?s=[]:s=u.split(",").map(i=>i.trim()).filter(i=>i!=="").map(i=>{let c=parseInt(i,10);if(isNaN(c))throw new L(`Invalid shape value: ${i}`);return c}),{descr:o,fortran_order:a,shape:s}}function zi(t,r,e,n,o){let a=U(r);if(!a)throw new L(`Cannot create array for dtype: ${r}`);if(!n)return new a(t,0,e);let u=new Uint8Array(t),s=new Uint8Array(t.byteLength);for(let i=0;i<e;i++){let c=i*o;for(let f=0;f<o;f++)s[c+f]=u[c+o-1-f]}return new a(s.buffer,0,e)}function _i(t,r){let e=r.length,n=t.size,o=t.dtype,a=U(o);if(!a)throw new L(`Cannot create array for dtype: ${o}`);let u=new a(n),s=[...r].reverse(),i=_n(r),c=_n(s),f=new Array(e).fill(0);for(let y=0;y<n;y++){let l=y;for(let m=0;m<e;m++){let d=i[m];f[m]=Math.floor(l/d),l=l%d}let p=0;for(let m=0;m<e;m++)p+=f[e-1-m]*c[m];w(o),u[p]=t.iget(y)}return D.fromData(u,s,o)}function _n(t){let r=new Array(t.length),e=1;for(let n=t.length-1;n>=0;n--)r[n]=e,e*=t[n];return r}function yr(t){let r=t.shape,e=t.dtype,n=Tr[e],o=r.length===0?"()":r.length===1?`(${r[0]},)`:`(${r.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,u=12,i=(64-(u+a.length+1)%64)%64;a=a+" ".repeat(i)+`
2
+ `;let c=new TextEncoder().encode(a),f=c.length,y=t.size,l=Nt(e),p=y*l,m=u+f+p,d=new Uint8Array(m);d.set(lr,0),d[6]=3,d[7]=0,d[8]=f&255,d[9]=f>>8&255,d[10]=f>>16&255,d[11]=f>>24&255,d.set(c,u);let g=u+f;return Bi(t,d.subarray(g),l),d}function Bi(t,r,e){let n=t.dtype,o=t.size,a=lt(),u=w(n),s=t._storage;if(s.isCContiguous&&s.offset===0&&a){let c=s.data,f=new Uint8Array(c.buffer,c.byteOffset,o*e);r.set(f)}else{let c=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let f=0;f<o;f++){let y=s.iget(f),l=f*e;u?Ei(c,l,y,n==="uint64"):Ui(c,l,y,n)}}}function Ei(t,r,e,n){n?t.setBigUint64(r,e,!0):t.setBigInt64(r,e,!0)}function Ui(t,r,e,n){switch(n){case"float64":t.setFloat64(r,e,!0);break;case"float32":t.setFloat32(r,e,!0);break;case"int32":t.setInt32(r,e,!0);break;case"int16":t.setInt16(r,e,!0);break;case"int8":t.setInt8(r,e);break;case"uint32":t.setUint32(r,e,!0);break;case"uint16":t.setUint16(r,e,!0);break;case"uint8":case"bool":t.setUint8(r,e);break;default:throw new Error(`Unsupported dtype for serialization: ${n}`)}}var Ti=(()=>{let t=new Uint32Array(256);for(let r=0;r<256;r++){let e=r;for(let n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;t[r]=e}return t})();function mt(t){let r=4294967295;for(let e=0;e<t.length;e++)r=Ti[(r^t[e])&255]^r>>>8;return(r^4294967295)>>>0}async function Bn(t){let r=Un(t),e=new Map;for(let n of r){let o=await Oi(n);e.set(n.name,o)}return e}function En(t){let r=Un(t),e=new Map;for(let n of r){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 Un(t){let r=t instanceof ArrayBuffer?new Uint8Array(t):t,e=new DataView(r.buffer,r.byteOffset,r.byteLength),n=[],o=-1;for(let c=r.length-22;c>=0;c--)if(e.getUint32(c,!0)===101010256){o=c;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),u=e.getUint16(o+10,!0),s=[],i=a;for(let c=0;c<u&&e.getUint32(i,!0)===33639248;c++){let y=e.getUint16(i+10,!0),l=e.getUint32(i+16,!0),p=e.getUint32(i+20,!0),m=e.getUint32(i+24,!0),d=e.getUint16(i+28,!0),g=e.getUint16(i+30,!0),h=e.getUint16(i+32,!0),A=e.getUint32(i+42,!0),b=r.slice(i+46,i+46+d),S=new TextDecoder("utf-8").decode(b);s.push({name:S,compressionMethod:y,crc32:l,compressedSize:p,uncompressedSize:m,localHeaderOffset:A}),i=i+46+d+g+h}for(let c of s){let f=c.localHeaderOffset;if(e.getUint32(f,!0)!==67324752)throw new Error(`Invalid local file header at offset ${f}`);let l=e.getUint16(f+26,!0),p=e.getUint16(f+28,!0),m=f+30+l+p,d=r.slice(m,m+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 Oi(t){if(t.compressionMethod===0)return t.compressedData;if(t.compressionMethod===8)return await $i(t.compressedData);throw new Error(`Unsupported compression method: ${t.compressionMethod}`)}async function $i(t){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 r=new DecompressionStream("deflate-raw"),e=new Uint8Array(t.length);e.set(t);let n=r.writable.getWriter();n.write(e),n.close();let o=r.readable.getReader(),a=[];for(;;){let{done:c,value:f}=await o.read();if(c)break;a.push(f)}let u=a.reduce((c,f)=>c+f.length,0),s=new Uint8Array(u),i=0;for(let c of a)s.set(c,i),i+=c.length;return s}async function At(t,r={}){let e=r.force??!1,n=await Bn(t);return Tn(n,e)}function ht(t,r={}){let e=r.force??!1,n=En(t);return Tn(n,e)}function Tn(t,r){let e=new Map,n=[],o=new Map;for(let[a,u]of t){if(!a.endsWith(".npy"))continue;let s=a.slice(0,-4);try{let i=Or(u);e.set(s,i)}catch(i){if(i instanceof Y&&r)n.push(s),o.set(s,i.message);else throw i}}return{arrays:e,skipped:n,errors:o}}async function On(t,r={}){let e=await At(t,r);return Object.fromEntries(e.arrays)}function $n(t,r={}){let e=ht(t,r);return Object.fromEntries(e.arrays)}async function vn(t,r={}){let e=r.compress??!1,n=[];for(let[l,p]of t){let m=mt(p),d,g;e?(d=await Mi(p),d.length<p.length?g=8:(d=p,g=0)):(d=p,g=0),n.push({name:l,data:p,compressedData:d,crc:m,compressionMethod:g,offset:0})}let o=0;for(let l of n){let p=new TextEncoder().encode(l.name);o+=30+p.length+l.compressedData.length}let a=0;for(let l of n){let p=new TextEncoder().encode(l.name);a+=46+p.length}let s=o+a+22,i=new Uint8Array(s),c=new DataView(i.buffer),f=0;for(let l of n)l.offset=f,f=Cn(i,c,f,l);let y=f;for(let l of n)f=kn(i,c,f,l);return Vn(c,f,n.length,a,y),i}function Mn(t){let r=[];for(let[f,y]of t){let l=mt(y);r.push({name:f,data:y,compressedData:y,crc:l,compressionMethod:0,offset:0})}let e=0;for(let f of r){let y=new TextEncoder().encode(f.name);e+=30+y.length+f.compressedData.length}let n=0;for(let f of r){let y=new TextEncoder().encode(f.name);n+=46+y.length}let a=e+n+22,u=new Uint8Array(a),s=new DataView(u.buffer),i=0;for(let f of r)f.offset=i,i=Cn(u,s,i,f);let c=i;for(let f of r)i=kn(u,s,i,f);return Vn(s,i,r.length,n,c),u}function Cn(t,r,e,n){let o=new TextEncoder().encode(n.name);return r.setUint32(e,67324752,!0),e+=4,r.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,n.compressionMethod,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,33,!0),e+=2,r.setUint32(e,n.crc,!0),e+=4,r.setUint32(e,n.compressedData.length,!0),e+=4,r.setUint32(e,n.data.length,!0),e+=4,r.setUint16(e,o.length,!0),e+=2,r.setUint16(e,0,!0),e+=2,t.set(o,e),e+=o.length,t.set(n.compressedData,e),e+=n.compressedData.length,e}function kn(t,r,e,n){let o=new TextEncoder().encode(n.name);return r.setUint32(e,33639248,!0),e+=4,r.setUint16(e,20,!0),e+=2,r.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,n.compressionMethod,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,33,!0),e+=2,r.setUint32(e,n.crc,!0),e+=4,r.setUint32(e,n.compressedData.length,!0),e+=4,r.setUint32(e,n.data.length,!0),e+=4,r.setUint16(e,o.length,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint16(e,0,!0),e+=2,r.setUint32(e,0,!0),e+=4,r.setUint32(e,n.offset,!0),e+=4,t.set(o,e),e+=o.length,e}function Vn(t,r,e,n,o){t.setUint32(r,101010256,!0),r+=4,t.setUint16(r,0,!0),r+=2,t.setUint16(r,0,!0),r+=2,t.setUint16(r,e,!0),r+=2,t.setUint16(r,e,!0),r+=2,t.setUint32(r,n,!0),r+=4,t.setUint32(r,o,!0),r+=4,t.setUint16(r,0,!0)}async function Mi(t){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 r=new CompressionStream("deflate-raw"),e=new Uint8Array(t.length);e.set(t);let n=r.writable.getWriter();n.write(e),n.close();let o=r.readable.getReader(),a=[];for(;;){let{done:c,value:f}=await o.read();if(c)break;a.push(f)}let u=a.reduce((c,f)=>c+f.length,0),s=new Uint8Array(u),i=0;for(let c of a)s.set(c,i),i+=c.length;return s}async function Fn(t,r={}){let e=Rn(t);return vn(e,{compress:r.compress??!1})}function Pn(t){let r=Rn(t);return Mn(r)}function Rn(t){let r=new Map;if(Array.isArray(t)){for(let n=0;n<t.length;n++){let o=t[n],a=yr(o);r.set(`arr_${n}.npy`,a)}return r}let e=t instanceof Map?t.entries():Object.entries(t);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=yr(o),u=n.endsWith(".npy")?n:`${n}.npy`;r.set(u,a)}return r}var Xu="0.7.0";export{Tr as DTYPE_TO_DESCR,L as InvalidNpyError,_ as NDArray,ft as SUPPORTED_DTYPES,Y as UnsupportedDTypeError,Xu as __version__,ua as absolute,ms as append,Mo as arange,_a as arccos,Fa as arccosh,za as arcsin,Va as arcsinh,Ba as arctan,Ea as arctan2,Pa as arctanh,R as array,xs as array_equal,Is as array_equiv,Ha as array_split,Zo as asanyarray,Ur as asarray,Wo as ascontiguousarray,Ho as asfortranarray,is as atleast_1d,us as atleast_2d,cs as atleast_3d,Os as average,Xs as bitwise_and,ri as bitwise_not,Qs as bitwise_or,Ks as bitwise_xor,bs as broadcast_arrays,Ss as broadcast_shapes,hs as broadcast_to,Zs as cbrt,ws as choose,ls as column_stack,fi as compress,er as concatenate,Po as copy,xa as cos,Ca as cosh,_s as cumprod,zs as cumsum,$a as deg2rad,Ta as degrees,ds as delete,wn as diag,pi as diag_indices,mi as diag_indices_from,Yo as diagflat,Aa as diagonal,Hs as divmod,da as dot,fs as dsplit,Za as dstack,si as einsum,Dn as empty,qo as empty_like,ts as expand_dims,Sn as eye,Ws as fabs,ct as flip,es as fliplr,ns as flipud,ya as floor_divide,ta as frombuffer,ea as fromfile,Go as fromfunction,na as fromiter,oa as fromstring,Nn as full,jo as full_like,Vo as geomspace,Js as heaviside,Ga as hsplit,ja as hstack,Ua as hypot,Fo as identity,Si as indices,Sa as inner,gs as insert,ti as invert,Di as ix_,ha as kron,ei as left_shift,Co as linspace,On as loadNpz,$n as loadNpzSync,ko as logspace,bi as mask_indices,Es as median,Jo as meshgrid,la as mod,La as moveaxis,Rs as nanargmax,Ps as nanargmin,qs as nancumprod,Ls as nancumsum,Fs as nanmax,Ms as nanmean,js as nanmedian,Vs as nanmin,vs as nanprod,ks as nanstd,$s as nansum,Cs as nanvar,ca as negative,hn as ones,Lo as ones_like,Da as outer,oi as packbits,As as pad,Or as parseNpy,pt as parseNpyData,yt as parseNpyHeader,At as parseNpz,ht as parseNpzSync,Us as percentile,yi as place,pa as positive,ia as power,Bs as ptp,Ns as put,ui as put_along_axis,ci as putmask,Ts as quantile,va as rad2deg,Oa as radians,Qa as ravel,Ni as ravel_multi_index,ma as reciprocal,Gs as remainder,Xa as repeat,Ka as reshape,ps as resize,ni as right_shift,as as roll,ss as rollaxis,os as rot90,ys as row_stack,li as select,yr as serializeNpy,Fn as serializeNpz,Pn as serializeNpzSync,fa as sign,wa as sin,Ma as sinh,Wa as split,sa as sqrt,Ys as square,rs as squeeze,qa as stack,Ra as swapaxes,Ds as take,ii as take_along_axis,Ia as tan,ka as tanh,Na as tensordot,Ja as tile,ga as trace,ba as transpose,Xo as tri,Qo as tril,di as tril_indices,gi as tril_indices_from,Ko as triu,Ai as triu_indices,hi as triu_indices_from,ai as unpackbits,wi as unravel_index,ra as vander,Ya as vsplit,xn as vstack,H as zeros,Ro as zeros_like};