numpy-ts 0.6.0 → 0.8.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,3 +1,4 @@
1
- "use strict";var Gr=Object.defineProperty;var ss=Object.getOwnPropertyDescriptor;var is=Object.getOwnPropertyNames;var us=Object.prototype.hasOwnProperty;var $=(r,t)=>()=>(r&&(t=r(r=0)),t);var Hr=(r,t)=>{for(var e in t)Gr(r,e,{get:t[e],enumerable:!0})},cs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of is(t))!us.call(r,o)&&o!==e&&Gr(r,o,{get:()=>t[o],enumerable:!(n=ss(t,o))||n.enumerable});return r};var Yr=r=>cs(Gr({},"__esModule",{value:!0}),r);function Mt(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 Ct(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 kt=$(()=>{"use strict"});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 Vt(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 Pt(r){return r==="float64"||r==="float32"}function N(r){return r==="int64"||r==="uint64"}function M(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(Pt(r)||Pt(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 v,V=$(()=>{"use strict";v="float64"});function Z(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}var D,F=$(()=>{"use strict";V();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 y=u+1;y<a;y++)c*=n[y];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=v){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=v){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 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 fs(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 Dr(r,t){let e=fs(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function q(r,t,e,n){let o=Ft(r.shape,t.shape),a=Dr(r,o),i=Dr(t,o),s=M(r.dtype,t.dtype),u=D.zeros(o,s),c=u.data,l=u.size;if(N(s)){let y=c;for(let f=0;f<l;f++){let p=a.iget(f),m=i.iget(f),d=typeof p=="bigint"?p:BigInt(Math.round(p)),g=typeof m=="bigint"?m:BigInt(Math.round(m));n==="add"?y[f]=d+g:n==="subtract"?y[f]=d-g:n==="multiply"?y[f]=d*g:n==="divide"?y[f]=d/g:y[f]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let y=N(r.dtype)||N(t.dtype);for(let f=0;f<l;f++){let p=a.iget(f),m=i.iget(f),d=Number(p),g=Number(m);c[f]=e(d,g)}}return u}function G(r,t,e){let n=Ft(r.shape,t.shape),o=Dr(r,n),a=Dr(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),y=a.iget(c),f=Number(l),p=Number(y);s[c]=e(f,p)?1:0}return D.fromData(s,n,"bool")}function C(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 y=c;for(let f=0;f<a;f++){let p=Number(l[f]);y[f]=BigInt(Math.round(t(p)))}}else for(let y=0;y<a;y++)c[y]=t(Number(l[y]));else for(let y=0;y<a;y++)c[y]=t(Number(l[y]));return u}var tr=$(()=>{"use strict";F();V()});function Jr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Rt(r,t){return typeof t=="number"?ms(r,t):Jr(r,t)?ls(r,t):q(r,t,(e,n)=>e+n,"add")}function ls(r,t){let e=M(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 y=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]=y+f}else{let l=a,y=i;for(let f=0;f<o;f++)u[f]=l[f]+y[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],y=typeof i[c]=="bigint"?Number(i[c]):i[c];s[c]=l+y}else for(let c=0;c<o;c++)s[c]=a[c]+i[c];return n}function qt(r,t){return typeof t=="number"?ds(r,t):Jr(r,t)?ps(r,t):q(r,t,(e,n)=>e-n,"subtract")}function ps(r,t){let e=M(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 y=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]=y-f}else{let l=a,y=i;for(let f=0;f<o;f++)u[f]=l[f]-y[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],y=typeof i[c]=="bigint"?Number(i[c]):i[c];s[c]=l-y}else for(let c=0;c<o;c++)s[c]=a[c]-i[c];return n}function Lt(r,t){return typeof t=="number"?gs(r,t):Jr(r,t)?ys(r,t):q(r,t,(e,n)=>e*n,"multiply")}function ys(r,t){let e=M(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 y=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]=y*f}else{let l=a,y=i;for(let f=0;f<o;f++)u[f]=l[f]*y[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],y=typeof i[c]=="bigint"?Number(i[c]):i[c];s[c]=l*y}else for(let c=0;c<o;c++)s[c]=a[c]*i[c];return n}function jt(r,t){if(typeof t=="number")return hs(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:er(r,"float64"),c=n?t:er(t,"float64");return q(u,c,(l,y)=>l/y,"divide")}if(o||a){let u=o?r:er(r,"float32"),c=a?t:er(t,"float32");return q(u,c,(l,y)=>l/y,"divide")}let i=er(r,"float64"),s=er(t,"float64");return q(i,s,(u,c)=>u/c,"divide")}function er(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 ms(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 y=0;y<a;y++)c[y]=u[y]+l}else for(let u=0;u<a;u++)s[u]=Number(o[u])+t;return i}function ds(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 y=0;y<a;y++)c[y]=u[y]-l}else for(let u=0;u<a;u++)s[u]=Number(o[u])-t;return i}function gs(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 y=0;y<a;y++)c[y]=u[y]*l}else for(let u=0;u<a;u++)s[u]=Number(o[u])*t;return i}function hs(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 Zt(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 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]}else for(let s=0;s<o;s++)i[s]=-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++){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 Nr(r,t){return typeof t=="number"?As(r,t):q(r,t,(e,n)=>(e%n+n)%n,"mod")}function As(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 y=0;y<a;y++){let f=u[y];c[y]=(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 Qr(r,t){return typeof t=="number"?bs(r,t):q(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function bs(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 y=0;y<a;y++)c[y]=u[y]/l}else for(let u=0;u<a;u++)s[u]=Math.floor(Number(o[u])/t);return i}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;for(let s=0;s<o;s++)i[s]=n[s];return a}function Yt(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 Jt(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 Qt(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 Xt(r,t){let e=Qr(r,t),n=Nr(r,t);return[e,n]}function Kt(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 re(r,t){return Nr(r,t)}function te(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,y)=>l===c[y]))for(let l=0;l<o;l++){let y=Number(r.data[l]);y<0?s[l]=0:y===0?s[l]=Number(u[l]):s[l]=1}else for(let l=0;l<o;l++){let y=Number(r.data[l]),f=l%t.size;y<0?s[l]=0:y===0?s[l]=Number(u[f]):s[l]=1}}return i}var ee=$(()=>{"use strict";F();V();tr()});function J(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 Ds(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 H(r,t){let e=Ds(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function Xr(...r){let t=J(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}var Kr=$(()=>{"use strict";F()});function ne(r,t){return typeof t=="number"?Ns(r,t):G(r,t,(e,n)=>e>n)}function oe(r,t){return typeof t=="number"?ws(r,t):G(r,t,(e,n)=>e>=n)}function ae(r,t){return typeof t=="number"?xs(r,t):G(r,t,(e,n)=>e<n)}function se(r,t){return typeof t=="number"?Is(r,t):G(r,t,(e,n)=>e<=n)}function ie(r,t){return typeof t=="number"?zs(r,t):G(r,t,(e,n)=>e===n)}function ue(r,t){return typeof t=="number"?Bs(r,t):G(r,t,(e,n)=>e!==n)}function rt(r,t,e=1e-5,n=1e-8){return typeof t=="number"?_s(r,t,e,n):G(r,t,(o,a)=>{let i=Math.abs(o-a),s=n+e*Math.abs(a);return i<=s})}function ce(r,t,e=1e-5,n=1e-8){let o=rt(r,t,e,n),a=o.data;for(let i=0;i<o.size;i++)if(a[i]===0)return!1;return!0}function fe(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=J(e);if(n===null)return!1;let o=H(r,n),a=H(t,n),i=n.length,s=n.reduce((l,y)=>l*y,1),u=N(o.dtype),c=N(a.dtype);for(let l=0;l<s;l++){let y=l,f=new Array(i);for(let d=i-1;d>=0;d--)f[d]=y%n[d],y=Math.floor(y/n[d]);let p=o.get(...f),m=a.get(...f);if(u||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 Ns(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 ws(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 xs(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 Is(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 zs(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 Bs(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 _s(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),y=n+e*Math.abs(t);o[u]=l<=y?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")}var le=$(()=>{"use strict";F();V();tr();Kr()});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}var pe=$(()=>{"use strict"});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 m=s,d=BigInt(0);for(let g=0;g<i;g++)d+=m[g];return Number(d)}else{let m=0;for(let d=0;d<i;d++)m+=Number(s[d]);return m}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((m,d)=>d!==u);if(c.length===0)return ur(r);let l=D.zeros(c,n),y=l.data,f=o[u],p=c.reduce((m,d)=>m*d,1);if(N(n)){let m=s,d=y;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+=m[S]}d[g]=A}}else for(let m=0;m<p;m++){let d=0;for(let g=0;g<f;g++){let A=T(m,u,g,o),h=U(A,o);d+=Number(s[h])}y[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(y,m,n)}return l}function wr(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return ur(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=ur(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,y=i.data;if(N(n)){let f=y;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(y[f])/s;return c}function xr(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 m=s[0];for(let d=1;d<i;d++)s[d]>m&&(m=s[d]);return Number(m)}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((m,d)=>d!==u);if(c.length===0)return xr(r);let l=D.zeros(c,n),y=l.data,f=o[u],p=c.reduce((m,d)=>m*d,1);if(N(n)){let m=s,d=y;for(let g=0;g<p;g++){let A=T(g,u,0,o),h=U(A,o),b=m[h];for(let S=1;S<f;S++){let w=T(g,u,S,o),x=U(w,o),z=m[x];z>b&&(b=z)}d[g]=b}}else for(let m=0;m<p;m++){let d=-1/0;for(let g=0;g<f;g++){let A=T(m,u,g,o),h=U(A,o),b=Number(s[h]);b>d&&(d=b)}y[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(y,m,n)}return l}function tt(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 m=s,d=BigInt(1);for(let g=0;g<i;g++)d*=m[g];return Number(d)}else{let m=1;for(let d=0;d<i;d++)m*=Number(s[d]);return m}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((m,d)=>d!==u);if(c.length===0)return tt(r);let l=D.zeros(c,n),y=l.data,f=o[u],p=c.reduce((m,d)=>m*d,1);if(N(n)){let m=s,d=y;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*=m[S]}d[g]=A}}else for(let m=0;m<p;m++){let d=1;for(let g=0;g<f;g++){let A=T(m,u,g,o),h=U(A,o);d*=Number(s[h])}y[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(y,m,n)}return l}function Ir(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 m=s[0];for(let d=1;d<i;d++)s[d]<m&&(m=s[d]);return Number(m)}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((m,d)=>d!==u);if(c.length===0)return Ir(r);let l=D.zeros(c,n),y=l.data,f=o[u],p=c.reduce((m,d)=>m*d,1);if(N(n)){let m=s,d=y;for(let g=0;g<p;g++){let A=T(g,u,0,o),h=U(A,o),b=m[h];for(let S=1;S<f;S++){let w=T(g,u,S,o),x=U(w,o),z=m[x];z<b&&(b=z)}d[g]=b}}else for(let m=0;m<p;m++){let d=1/0;for(let g=0;g<f;g++){let A=T(m,u,g,o),h=U(A,o),b=Number(s[h]);b<d&&(d=b)}y[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(y,m,n)}return l}function et(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let p=i[0],m=0;for(let d=1;d<a;d++)i[d]<p&&(p=i[d],m=d);return m}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,m)=>m!==s);if(u.length===0)return et(r);let c=D.zeros(u,"int32"),l=c.data,y=n[s],f=u.reduce((p,m)=>p*m,1);if(N(e)){let p=i;for(let m=0;m<f;m++){let d=T(m,s,0,n),g=U(d,n),A=p[g],h=0;for(let b=1;b<y;b++){let S=T(m,s,b,n),w=U(S,n),x=p[w];x<A&&(A=x,h=b)}l[m]=h}}else for(let p=0;p<f;p++){let m=1/0,d=0;for(let g=0;g<y;g++){let A=T(p,s,g,n),h=U(A,n),b=Number(i[h]);b<m&&(m=b,d=g)}l[p]=d}return c}function nt(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],m=0;for(let d=1;d<a;d++)i[d]>p&&(p=i[d],m=d);return m}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,m)=>m!==s);if(u.length===0)return nt(r);let c=D.zeros(u,"int32"),l=c.data,y=n[s],f=u.reduce((p,m)=>p*m,1);if(N(e)){let p=i;for(let m=0;m<f;m++){let d=T(m,s,0,n),g=U(d,n),A=p[g],h=0;for(let b=1;b<y;b++){let S=T(m,s,b,n),w=U(S,n),x=p[w];x>A&&(A=x,h=b)}l[m]=h}}else for(let p=0;p<f;p++){let m=-1/0,d=0;for(let g=0;g<y;g++){let A=T(p,s,g,n),h=U(A,n),b=Number(i[h]);b>m&&(m=b,d=g)}l[p]=d}return c}function ot(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.size,s=r.data,u=wr(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],y=u,f=y.data,p=n?y.shape:Array.from(o).filter((A,h)=>h!==c),m=D.zeros(Array.from(p),"float64"),d=m.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 m}function ye(r,t,e=0,n=!1){let o=ot(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 at(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(!i[p])return!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,m)=>m!==s);if(u.length===0)return at(r);let c=D.zeros(u,"bool"),l=c.data,y=n[s],f=u.reduce((p,m)=>p*m,1);for(let p=0;p<f;p++){let m=!0;for(let d=0;d<y;d++){let g=T(p,s,d,n),A=U(g,n);if(!i[A]){m=!1;break}}l[p]=m?1:0}if(e){let p=[...n];return p[s]=1,D.fromData(l,p,"bool")}return c}function st(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,m)=>m!==s);if(u.length===0)return st(r);let c=D.zeros(u,"bool"),l=c.data,y=n[s],f=u.reduce((p,m)=>p*m,1);for(let p=0;p<f;p++){let m=!1;for(let d=0;d<y;d++){let g=T(p,s,d,n),A=U(g,n);if(i[A]){m=!0;break}}l[p]=m?1:0}if(e){let p=[...n];return p[s]=1,D.fromData(l,p,"bool")}return c}function it(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),m=0;for(let d=0;d<f;d++)m+=Number(o[d]),p[d]=m;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,y=u[a];for(let f=0;f<l;f++)Math.floor(f/y)%s===0?i[f]=Number(o[f]):i[f]=i[f-y]+Number(o[f]);return D.fromData(i,[...e],"float64")}function ut(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),m=1;for(let d=0;d<f;d++)m*=Number(o[d]),p[d]=m;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,y=u[a];for(let f=0;f<l;f++)Math.floor(f/y)%s===0?i[f]=Number(o[f]):i[f]=i[f-y]*Number(o[f]);return D.fromData(i,[...e],"float64")}function ct(r,t,e=!1){let n=xr(r,t,e),o=Ir(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 ft(r,t,e=!1){return nr(r,.5,t,e)}function lt(r,t,e,n=!1){return nr(r,t/100,e,n)}function nr(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 m=p.length,d=t*(m-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,m)=>m!==s);if(u.length===0)return nr(r,t);let c=u.reduce((p,m)=>p*m,1),l=o[s],y=new Float64Array(c);for(let p=0;p<c;p++){let m=[];for(let b=0;b<l;b++){let S=T(p,s,b,o),w=U(S,o);m.push(Number(i[w]))}m.sort((b,S)=>b-S);let d=m.length,g=t*(d-1),A=Math.floor(g),h=Math.ceil(g);if(A===h)y[p]=m[A];else{let b=g-A;y[p]=m[A]*(1-b)+m[h]*b}}let f=D.fromData(y,u,"float64");if(n){let p=[...o];return p[s]=1,D.fromData(y,p,"float64")}return f}function zr(r,t,e,n=!1){let o=r.shape,a=o.length,i=r.data;if(e===void 0)return wr(r,t,n);if(t===void 0){let m=0,d=0,g=e.data;for(let A=0;A<r.size;A++){let h=Number(g[A%e.size]);m+=Number(i[A])*h,d+=h}return d===0?NaN:m/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((m,d)=>d!==s);if(u.length===0)return zr(r,void 0,e);let c=u.reduce((m,d)=>m*d,1),l=o[s],y=e.data,f=new Float64Array(c);for(let m=0;m<c;m++){let d=0,g=0;for(let A=0;A<l;A++){let h=T(m,s,A,o),b=U(h,o),S=Number(y[A%e.size]);d+=Number(i[b])*S,g+=S}f[m]=g===0?NaN:d/g}let p=D.fromData(f,u,"float64");if(n){let m=[...o];return m[s]=1,D.fromData(f,m,"float64")}return p}function Br(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 m=Number(a[p]);isNaN(m)||(f+=m)}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 Br(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 m=0;m<c;m++){let d=T(f,i,m,n),g=U(d,n),A=Number(a[g]);isNaN(A)||(p+=A)}l[f]=p}let y=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return y}function _r(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 m=Number(a[p]);isNaN(m)||(f*=m)}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 _r(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 m=0;m<c;m++){let d=T(f,i,m,n),g=U(d,n),A=Number(a[g]);isNaN(A)||(p*=A)}l[f]=p}let y=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return y}function Er(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 m=0;m<r.size;m++){let d=Number(a[m]);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 Er(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,m=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,m++)}l[f]=m===0?NaN:p/m}let y=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return y}function cr(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.data;if(t===void 0){let p=0,m=0;for(let A=0;A<r.size;A++){let h=Number(i[A]);isNaN(h)||(p+=h,m++)}if(m-e<=0)return NaN;let d=p/m,g=0;for(let A=0;A<r.size;A++){let h=Number(i[A]);isNaN(h)||(g+=(h-d)**2)}return g/(m-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,m)=>m!==s);if(u.length===0)return cr(r,void 0,e);let c=u.reduce((p,m)=>p*m,1),l=o[s],y=new Float64Array(c);for(let p=0;p<c;p++){let m=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)||(m+=w,d++)}if(d-e<=0){y[p]=NaN;continue}let g=m/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)}y[p]=A/(d-e)}let f=D.fromData(y,u,"float64");if(n){let p=[...o];return p[s]=1,D.fromData(y,p,"float64")}return f}function pt(r,t,e=0,n=!1){let o=cr(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 Ur(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 m=Number(a[p]);!isNaN(m)&&m<f&&(f=m)}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 Ur(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 m=0;m<c;m++){let d=T(f,i,m,n),g=U(d,n),A=Number(a[g]);!isNaN(A)&&A<p&&(p=A)}l[f]=p===1/0?NaN:p}let y=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return y}function Tr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=-1/0;for(let p=0;p<r.size;p++){let m=Number(a[p]);!isNaN(m)&&m>f&&(f=m)}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 Tr(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 m=0;m<c;m++){let d=T(f,i,m,n),g=U(d,n),A=Number(a[g]);!isNaN(A)&&A>p&&(p=A)}l[f]=p===-1/0?NaN:p}let y=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return y}function Or(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=1/0,y=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p<l&&(l=p,y=f)}return y}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,y)=>y!==a);if(i.length===0)return Or(r);let s=i.reduce((l,y)=>l*y,1),u=e[a],c=new Int32Array(s);for(let l=0;l<s;l++){let y=1/0,f=0;for(let p=0;p<u;p++){let m=T(l,a,p,e),d=U(m,e),g=Number(o[d]);!isNaN(g)&&g<y&&(y=g,f=p)}c[l]=f}return D.fromData(c,i,"int32")}function $r(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=-1/0,y=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p>l&&(l=p,y=f)}return y}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,y)=>y!==a);if(i.length===0)return $r(r);let s=i.reduce((l,y)=>l*y,1),u=e[a],c=new Int32Array(s);for(let l=0;l<s;l++){let y=-1/0,f=0;for(let p=0;p<u;p++){let m=T(l,a,p,e),d=U(m,e),g=Number(o[d]);!isNaN(g)&&g>y&&(y=g,f=p)}c[l]=f}return D.fromData(c,i,"int32")}function yt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),m=0;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(m+=g),p[d]=m}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,y=u[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/y)%s===0?i[f]=isNaN(p)?0:p:i[f]=i[f-y]+(isNaN(p)?0:p)}return D.fromData(i,[...e],"float64")}function mt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),m=1;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(m*=g),p[d]=m}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,y=u[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/y)%s===0?i[f]=isNaN(p)?1:p:i[f]=i[f-y]*(isNaN(p)?1:p)}return D.fromData(i,[...e],"float64")}function vr(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,m=Math.floor(p/2);return p%2===0?(f[m-1]+f[m])/2:f[m]}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 vr(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 m=p.length,d=Math.floor(m/2);m%2===0?l[f]=(p[d-1]+p[d])/2:l[f]=p[d]}let y=D.fromData(l,s,"float64");if(e){let f=[...n];return f[i]=1,D.fromData(l,f,"float64")}return y}var me=$(()=>{"use strict";F();V();pe()});function R(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((y,f,p)=>p===o?y:y*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((y,f)=>f===o?l:y)}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,Z(a),0)}let u=r.copy().data;return D.fromData(u,a,n,Z(a),0)}function Mr(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 lr(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return D.fromData(n,[t],e,[1],0)}return Mr(r)}function pr(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},(y,f)=>n-1-f);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let y=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(y.has(p))throw new Error("repeated axis in transpose");y.add(p)}s=t.map(f=>f<0?n+f:f)}let u=s.map(y=>e[y]),c=Array.from(o),l=s.map(y=>c[y]);return D.fromData(a,u,i,l,r.offset)}function de(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 fr(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 ge(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),y=Array.from(a);return[l[u],l[c]]=[l[c],l[u]],[y[u],y[c]]=[y[c],y[u]],D.fromData(i,l,s,y,r.offset)}function dt(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 pr(r,u)}function Q(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 m=r[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 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,m)=>p*m,1),c=_(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(u),y=Z(i),f=0;for(let p of r){let m=p.shape[a];Ts(p,l,i,y,a,f,o),f+=m}return D.fromData(l,i,o)}function Ts(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],m=r.data,d=r.offset,g=d+c;t.set(m.subarray(d,g),p);return}if(o===1&&u===2&&r.isCContiguous){let p=s[0],m=s[1],d=e[1],g=r.data,A=r.offset;for(let h=0;h<p;h++){let b=A+h*m,S=h*d+a;t.set(g.subarray(b,b+m),S)}return}let y=new Array(u).fill(0),f=a*n[o];for(let p=0;p<c;p++){let m=r.iget(p),d=f;for(let g=0;g<u;g++)d+=y[g]*n[g];t[d]=m;for(let g=u-1;g>=0&&(y[g]++,!(y[g]<s[g]));g--)y[g]=0}}function he(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=>fr(s,a));return Q(i,a)}function Ae(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?R(e,[1,e.shape[0]]):e);return Q(t,0)}function gt(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?Q(r,0):Q(r,1)}function be(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?R(fr(R(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?fr(e,2):e);return Q(t,2)}function Se(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 De(r,s,a)}function yr(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 y=0;for(let f=0;f<u-1;f++)y+=c+(f<l?1:0),s.push(y)}else s=t;return De(r,s,a)}function De(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 y=r.offset+u*r.strides[e];i.push(D.fromData(r.data,l,r.dtype,Array.from(r.strides),y))}return i}function Ne(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return yr(r,t,0)}function we(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 yr(r,t,e)}function xe(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),y=_(o);if(!y)throw new Error(`Cannot tile array with dtype ${o}`);let f=new y(l),p=Z(c),m=r;n<i&&(m=R(r,s));let d=o==="int64"||o==="uint64",g=m.strides,A=new Array(i).fill(0);for(let h=0;h<l;h++){let b=m.offset;for(let x=0;x<i;x++){let z=A[x]%s[x];b+=z*g[x]}let S=m.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 Ie(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 Sr=0;Sr<O;Sr++)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 y=l.reduce((h,b)=>h*b,1),f=_(a);if(!f)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new f(y),m=Z(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]*m[E]);let z=m[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 ze(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 m=0;m<a;m++)u[m]=f[p+a-1-m];return D.fromData(u,[...e],o)}if(n===2&&r.isCContiguous){let f=e[0],p=e[1],m=r.data,d=r.offset;if(i.size===2){for(let g=0;g<a;g++)u[g]=m[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]=m[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]=m[A+p-1-b]}return D.fromData(u,[...e],o)}}}let l=new Array(n),y=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-y[d]:y[d];let p=r.offset;for(let d=0;d<n;d++)p+=l[d]*r.strides[d];let m=r.data[p];u[f]=m;for(let d=n-1;d>=0&&(y[d]++,!(y[d]<e[d]));d--)y[d]=0}return D.fromData(u,[...e],o)}function Be(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),y=new u(l),f=Z(c),p=N(a),m=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]=m[w];let A,h;t===1?(A=n[s]-1-m[s],h=m[i]):t===2?(A=n[i]-1-m[i],h=n[s]-1-m[s],d[i]=A,d[s]=h):(A=m[s],h=n[i]-1-m[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);y[b]=S;for(let w=o-1;w>=0&&(m[w]++,!(m[w]<n[w]));w--)m[w]=0}return D.fromData(y,c,a)}function _e(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let m=Array.isArray(t)?t.reduce((b,S)=>b+S,0):t,d=Mr(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-m)%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(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}),l=_(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let y=new l(i),f=N(a),p=new Array(o).fill(0);for(let m=0;m<i;m++){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];y[m]=A;for(let h=o-1;h>=0&&(p[h]++,!(p[h]<n[h]));h--)p[h]=0}return D.fromData(y,[...n],a)}function Ee(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):dt(r,o,a)}function Ue(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return yr(r,t,2)}function Te(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?R(e,[e.shape[0],1]):e);return gt(t)}function Oe(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 $e(r){return r.map(t=>t.ndim===0?R(t,[1]):t)}function ve(r){return r.map(t=>t.ndim===0?R(t,[1,1]):t.ndim===1?R(t,[1,t.shape[0]]):t)}function Me(r){return r.map(t=>t.ndim===0?R(t,[1,1,1]):t.ndim===1?R(t,[1,t.shape[0],1]):t.ndim===2?R(t,[t.shape[0],t.shape[1],1]):t)}var ht=$(()=>{"use strict";F();V()});function Os(r,t,e,n,o,a,i,s,u,c,l,y,f,p){if(y===0)for(let A=0;A<n*o;A++)f[A]=0;else if(y!==1)for(let A=0;A<n*o;A++)f[A]=(f[A]??0)*y;let m=r==="row-major",d=t==="transpose",g=e==="transpose";if(m&&!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(m&&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(m&&!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(m&&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(!m&&!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(!m&&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(!m&&!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 bt(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=M(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=M(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 X(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=M(r.dtype,t.dtype),u=D.zeros([o],s);for(let c=0;c<o;c++){let l=0;for(let y=0;y<a;y++){let f=r.get(c,y),p=t.get(y);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=M(r.dtype,t.dtype),u=D.zeros([i],s);for(let c=0;c<i;c++){let l=0;for(let y=0;y<o;y++){let f=r.get(y),p=t.get(y,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=M(r.dtype,t.dtype),u=D.zeros(i,s),c=i.reduce((l,y)=>l*y,1);for(let l=0;l<c;l++){let y=0,f=l,p=[];for(let m=i.length-1;m>=0;m--)p[m]=f%i[m],f=Math.floor(f/i[m]);for(let m=0;m<o;m++){let d=[...p,m],g=r.get(...d),A=t.get(m);typeof g=="bigint"&&typeof A=="bigint"?y=Number(y)+Number(g*A):y+=Number(g)*Number(A)}u.set(p,y)}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=M(r.dtype,t.dtype),c=D.zeros(s,u),l=s.reduce((y,f)=>y*f,1);for(let y=0;y<l;y++){let f=y,p=[];for(let A=s.length-1;A>=0;A--)p[A]=f%s[A],f=Math.floor(f/s[A]);let m=p.slice(0,a),d=p.slice(a),g=0;for(let A=0;A<o;A++){let h=r.get(A),b=[...m,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=M(r.dtype,t.dtype),u=D.zeros(i,s),c=r.shape.slice(0,-1).reduce((p,m)=>p*m,1),l=t.shape.slice(0,-2).reduce((p,m)=>p*m,1),y=t.shape[n-1],f=o;for(let p=0;p<c;p++)for(let m=0;m<l;m++)for(let d=0;d<y;d++){let g=0;for(let h=0;h<f;h++){let b=p*f+h,S=r.data[b+r.offset],w=m*f*y+h*y+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*y+m*y+d;u.data[A]=g}return u}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function X(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=M(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,y=0]=r.strides,[f=0,p=0]=t.strides,m=y>l,d=p>f,g=m?"transpose":"no-transpose",A=d?"transpose":"no-transpose",h,b;m?h=y:h=l,d?b=p:b=f;let S=D.zeros([e,a],"float64");return Os("row-major",g,A,e,a,n,1,u,h,c,b,0,S.data,a),S}function Pe(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 ke(r,t){return pr(r,t)}function Ve(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 bt(r,t);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],s=M(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),y=o;for(let f=0;f<c;f++)for(let p=0;p<l;p++){let m=0;for(let g=0;g<y;g++){let A=e===1?g:f*y+g,h=n===1?g:p*y+g,b=r.data[A+r.offset],S=t.data[h+t.offset];typeof b=="bigint"&&typeof S=="bigint"?m=Number(m)+Number(b*S):m+=Number(b)*Number(S)}if(i.length===0)return m;let d=c===1?p:f*l+p;u.data[d]=m}return u}function St(r,t){let e=r.ndim===1?r:lr(r),n=t.ndim===1?t:lr(t),o=e.size,a=n.size,i=M(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),y=n.get(c),f;typeof l=="bigint"&&typeof y=="bigint"?f=l*y:f=Number(l)*Number(y),s.set([u,c],f)}return s}function Fe(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,m)=>r.ndim-f+m),o=Array.from({length:f},(p,m)=>m)}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],m=o[f];if(p<0||p>=r.ndim||m<0||m>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[p]!==t.shape[m])throw new Error(`tensordot: shape mismatch on axes ${p} and ${m}: ${r.shape[p]} != ${t.shape[m]}`)}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(m=>r.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 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=M(r.dtype,t.dtype),c=D.zeros(s,u),l=s.reduce((f,p)=>f*p,1),y=n.map(f=>r.shape[f]).reduce((f,p)=>f*p,1);for(let f=0;f<l;f++){let p=f,m=[];for(let h=s.length-1;h>=0;h--)m[h]=p%s[h],p=Math.floor(p/s[h]);let d=m.slice(0,a.length),g=m.slice(a.length),A=0;for(let h=0;h<y;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(m,A)}return c}function Re(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 y=[];for(let d=0;d<a;d++)d!==i&&d!==s&&y.push(o[d]);y.push(l);let f=D.zeros(y,r.dtype),p=o.filter((d,g)=>g!==i&&g!==s),m=p.reduce((d,g)=>d*g,1);for(let d=0;d<m;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 qe(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=$s(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 X(A,h);if(S===z&&x===B&&b===w&&c.length===1&&c[0]===b){let E=ke(A);return X(E,h)}if(b===z&&w===B&&S===x&&c.length===1&&c[0]===S){let E=ke(h);return X(A,E)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&A.ndim===1&&h.ndim===1)return At(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 St(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 At(t,a,c,i)}let l=Array.from(o).map(d=>i.get(d));if(l.length===0)return At(t,a,c,i);let y=t[0].dtype;for(let d=1;d<t.length;d++)y=M(y,t[d].dtype);let f=D.zeros(l,y),p=l.reduce((d,g)=>d*g,1),m=1;for(let d of c)m*=i.get(d);for(let d=0;d<p;d++){let g=vs(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<m;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 Sr of B)E.push(A.get(Sr));let O=z.get(...E);w*=Number(O)}h+=w}f.set(g,h)}return f}function $s(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 At(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 y=e[l],f=n.get(y);s.set(y,u%f),u=Math.floor(u/f)}let c=1;for(let l=0;l<r.length;l++){let y=r[l],f=t[l],p=[];for(let d of f)p.push(s.get(d));let m=y.get(...p);c*=Number(m)}a+=c}return a}function vs(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 Le(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,i=M(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 m=0;m<o;m++)c[s-o+m]=e[m];for(let m=0;m<a;m++)l[s-a+m]=n[m];for(let m=0;m<s;m++)u[m]=c[m]*l[m];let y=D.zeros(u,i),f=e.reduce((m,d)=>m*d,1),p=n.reduce((m,d)=>m*d,1);for(let m=0;m<f;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 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);y.set(B,E)}}return y}var je=$(()=>{"use strict";F();V();ht()});function Ze(r){return C(r,Math.sqrt,!1)}function We(r,t){return typeof t=="number"?Cs(r,t):q(r,t,Math.pow,"power")}function Cs(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 y=o,f=l;for(let p=0;p<a;p++)f[p]=y[p]**BigInt(t)}else for(let y=0;y<a;y++)l[y]=Math.pow(Number(o[y]),t);else for(let y=0;y<a;y++)l[y]=Math.pow(Number(o[y]),t);return c}var Ge=$(()=>{"use strict";F();tr();V()});function He(r){return C(r,Math.sin,!1)}function Ye(r){return C(r,Math.cos,!1)}function Je(r){return C(r,Math.tan,!1)}function Qe(r){return C(r,Math.asin,!1)}function Xe(r){return C(r,Math.acos,!1)}function Ke(r){return C(r,Math.atan,!1)}function rn(r,t){return typeof t=="number"?Vs(r,t):Ps(r,t)}function Ps(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])),y=(N(a),Number(t.data[c]));u[c]=Math.atan2(l,y)}return s}function Vs(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 tn(r,t){return typeof t=="number"?Rs(r,t):Fs(r,t)}function Fs(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])),y=(N(a),Number(t.data[c]));u[c]=Math.hypot(l,y)}return s}function Rs(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 en(r){let t=180/Math.PI;return C(r,e=>e*t,!1)}function nn(r){let t=Math.PI/180;return C(r,e=>e*t,!1)}var on=$(()=>{"use strict";F();tr();V()});function an(r){return C(r,Math.sinh,!1)}function sn(r){return C(r,Math.cosh,!1)}function un(r){return C(r,Math.tanh,!1)}function cn(r){return C(r,Math.asinh,!1)}function fn(r){return C(r,Math.acosh,!1)}function ln(r){return C(r,Math.atanh,!1)}var pn=$(()=>{"use strict";tr()});function Dt(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=J([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 H(r,t)}function yn(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=J(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=>H(n,e))}function mn(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let m=r.size;for(let h of t){let b=h<0?m+h:h;if(b<0||b>=m)throw new Error(`index ${h} is out of bounds for axis 0 with size ${m}`)}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=m+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 m of t){let d=m<0?s+m:m;if(d<0||d>=s)throw new Error(`index ${m} is out of bounds for axis ${i} with size ${s}`)}let u=Array.from(n);u[i]=t.length;let c=u.reduce((m,d)=>m*d,1),l=_(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let y=new l(c),f=Z(u),p=new Array(o).fill(0);for(let m=0;m<c;m++){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),y[b]=h;for(let S=o-1;S>=0&&(p[S]++,!(p[S]<u[S]));S--)p[S]=0}return D.fromData(y,u,a)}function dn(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 gn(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=J(a);if(i===null)throw new Error("operands could not be broadcast together");let s=H(r,i),u=t.map(f=>H(f,i)),c=i.reduce((f,p)=>f*p,1),l=_(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let y=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 m=u[p].iget(f);N(o),y[f]=m}return D.fromData(y,i,o)}function hn(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 An=$(()=>{"use strict";F();V();Kr()});function L(r,t=v){let e=D.zeros(r,t);return new I(e)}function Nt(r,t=v){let e=D.ones(r,t);return new I(e)}function Zs(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function bn(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>bn(t)):!1}function Ws(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function k(r,t){if(r instanceof I)return!t||r.dtype===t?r.copy():r.astype(t);let e=bn(r),n=Zs(r),o=n.reduce((l,y)=>l*y,1),a=t;a||(e?a="int64":a=v);let i=_(a);if(!i)throw new Error(`Cannot create array with dtype ${a}`);let s=new i(o),u=Ws(r);if(N(a)){let l=s;for(let y=0;y<o;y++){let f=u[y];l[y]=typeof f=="bigint"?f:BigInt(Math.round(Number(f)))}}else if(a==="bool"){let l=s;for(let y=0;y<o;y++)l[y]=u[y]?1:0}else{let l=s;for(let y=0;y<o;y++){let f=u[y];l[y]=Number(f)}}let c=D.fromData(s,n,a);return new I(c)}function Sn(r,t,e=1,n=v){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 Dn(r,t,e=50,n=v){if(e<0)throw new Error("num must be non-negative");if(e===0)return k([],n);if(e===1)return k([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 Nn(r,t,e=50,n=10,o=v){if(e<0)throw new Error("num must be non-negative");if(e===0)return k([],o);if(e===1)return k([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 wn(r,t,e=50,n=v){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 k([],n);if(e===1)return k([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 y=D.fromData(s,[e],n);return new I(y)}function wt(r,t,e=0,n=v){let o=t??r,a=L([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 xt(r,t=v){return L(r,t)}function It(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=v);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 xn(r,t=v){return wt(r,r,0,t)}function mr(r,t){return r instanceof I?!t||r.dtype===t?r:r.astype(t):k(r,t)}function In(r){return r.copy()}function zn(r,t){return L(Array.from(r.shape),t??r.dtype)}function Bn(r,t){return Nt(Array.from(r.shape),t??r.dtype)}function _n(r,t){return xt(Array.from(r.shape),t??r.dtype)}function En(r,t,e){return It(Array.from(r.shape),t,e??r.dtype)}function Un(r,t){return mr(r,t)}function Tn(r,t){let e=mr(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function On(r,t){return mr(r,t).copy()}function zt(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=L([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 L([0],r.dtype);let s=_(r.dtype),u=new s(i);for(let l=0;l<i;l++){let y=r.get([o+l,a+l]);N(r.dtype)?u[l]=typeof y=="bigint"?y:BigInt(y):u[l]=y}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 $n(r,t=0){let e=r.flatten();return zt(e,t)}function vn(r,t,e=v){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 y=i-1;y>=0&&(s[y]++,!(s[y]<t[y]));y--)s[y]=0}let u=D.fromData(a,t,e);return new I(u)}function Mn(...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 y=u.reshape(...l),f=Dt(y.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 Cn(r,t,e=0,n=v){let o=t??r,a=L([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 kn(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=[],y=s;for(let f=n.length-3;f>=0;f--)l.unshift(y%n[f]),y=Math.floor(y/n[f]);l.push(u,c),e.set(l,0)}return e}function Pn(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=[],y=s;for(let f=n.length-3;f>=0;f--)l.unshift(y%n[f]),y=Math.floor(y/n[f]);l.push(u,c),e.set(l,0)}return e}function Vn(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=L([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 Fn(r,t=v,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let i=Gs(t),s=o.byteLength-a,u=Math.floor(s/i),c=e<0?u:Math.min(e,u);if(c<=0)return k([],t);let l=_(t);if(!l)throw new Error(`Unsupported dtype: ${t}`);let y=new l(o,a,c),f=D.fromData(y,[c],t);return new I(f)}function Rn(r,t=v,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return k(n,t)}function qn(r,t=v,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return k(n,t)}function Ln(r,t=v,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 k(a,t)}function Gs(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 jn(r){return r.sqrt()}function Zn(r,t){return r.power(t)}function Wn(r){return r.absolute()}function Gn(r){return r.negative()}function Hn(r){return r.sign()}function Yn(r,t){return r.mod(t)}function Jn(r,t){return r.floor_divide(t)}function Qn(r){return r.positive()}function Xn(r){return r.reciprocal()}function Kn(r,t){return r.dot(t)}function ro(r){return r.trace()}function to(r,t=0,e=0,n=1){let o=Re(r.storage,t,e,n);return I._fromStorage(o)}function eo(r,t){let e=Le(r.storage,t.storage);return I._fromStorage(e)}function no(r,t){return r.transpose(t)}function oo(r,t){return r.inner(t)}function ao(r,t){return r.outer(t)}function so(r,t,e=2){return r.tensordot(t,e)}function io(r){return r.sin()}function uo(r){return r.cos()}function co(r){return r.tan()}function fo(r){return r.arcsin()}function lo(r){return r.arccos()}function po(r){return r.arctan()}function yo(r,t){return r.arctan2(t)}function mo(r,t){return r.hypot(t)}function go(r){return r.degrees()}function ho(r){return r.radians()}function Ao(r){return r.radians()}function bo(r){return r.degrees()}function So(r){return r.sinh()}function Do(r){return r.cosh()}function No(r){return r.tanh()}function wo(r){return r.arcsinh()}function xo(r){return r.arccosh()}function Io(r){return r.arctanh()}function zo(r,t,e){return r.swapaxes(t,e)}function Bo(r,t,e){return r.moveaxis(t,e)}function K(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=Q(e,t);return I._fromStorage(n)}function _o(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=he(e,t);return I._fromStorage(n)}function Bt(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Ae(t);return I._fromStorage(e)}function Eo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=gt(t);return I._fromStorage(e)}function Uo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=be(t);return I._fromStorage(e)}function To(r,t,e=0){return Se(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function Oo(r,t,e=0){return yr(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function $o(r,t){return Ne(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function vo(r,t){return we(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function Mo(r,t){let e=xe(r.storage,t);return I._fromStorage(e)}function Co(r,t,e){return r.repeat(t,e)}function ko(r){return r.ravel()}function Po(r,t){return r.reshape(...t)}function Vo(r,t){return r.squeeze(t)}function Fo(r,t){return r.expand_dims(t)}function Cr(r,t){let e=ze(r.storage,t);return I._fromStorage(e)}function Ro(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Cr(r,1)}function qo(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Cr(r,0)}function Lo(r,t=1,e=[0,1]){let n=Be(r.storage,t,e);return I._fromStorage(n)}function jo(r,t,e){let n=_e(r.storage,t,e);return I._fromStorage(n)}function Zo(r,t,e=0){let n=Ee(r.storage,t,e);return I._fromStorage(n,r.base??r)}function Wo(...r){let t=r.map(o=>o.storage),n=$e(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function Go(...r){let t=r.map(o=>o.storage),n=ve(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function Ho(...r){let t=r.map(o=>o.storage),n=Me(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function Yo(r,t){return Ue(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function Jo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Te(t);return I._fromStorage(e)}function Qo(r){return Bt(r)}function Xo(r,t){let e=Oe(r.storage,t);return I._fromStorage(e)}function Ko(r,t,e){let n=t instanceof I?t:k(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return K([o,a])}return K([r,n],e)}function ra(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=[],y=0;for(let p=0;p<=s;p++)(c.has(p)||p===s)&&(p>y&&l.push([y,p]),y=p+1);if(l.length===0){let p=[...o];return p[i]=0,L(p,n)}let f=[];for(let[p,m]of l){let d=o.map(()=>":");d[i]=`${p}:${m}`,f.push(r.slice(...d))}return K(f,i)}function ta(r,t,e,n){let o=e instanceof I?e:k(e,r.dtype);if(n===void 0){let y=r.flatten(),f=o.flatten(),p=t<0?y.size+t:t;if(p<0||p>y.size)throw new Error(`index ${t} 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(f),d&&g.push(d),K(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 y=a.map(()=>":");y[s]=`0:${c}`,l.push(r.slice(...y))}if(l.push(o),c<u){let y=a.map(()=>":");y[s]=`${c}:`,l.push(r.slice(...y))}return K(l,s)}function ea(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),y=new l(c),f=N(i);e==="constant"&&(f?y.fill(BigInt(n)):y.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?y[d]=typeof h=="bigint"?h:BigInt(Number(h)):y[d]=Number(h);for(let b=a-1;b>=0&&(p[b]++,!(p[b]<u[b]));b--)p[b]=0}let m=D.fromData(y,u,i);return new I(m)}function na(r,t){let e=Dt(r.storage,t);return I._fromStorage(e,r.base??r)}function oa(...r){let t=r.map(n=>n.storage);return yn(t).map((n,o)=>I._fromStorage(n,r[o].base??r[o]))}function aa(...r){return Xr(...r)}function sa(r,t,e){return r.take(t,e)}function ia(r,t,e){r.put(t,e)}function ua(r,t){let e=t.map(o=>o.storage),n=gn(r.storage,e);return I._fromStorage(n)}function ca(r,t,e=!1){return hn(r.storage,t.storage,e)}function fa(r,t){return fe(r.storage,t.storage)}function la(r,t){return I._fromStorage(it(r.storage,t))}function pa(r,t){return I._fromStorage(ut(r.storage,t))}function ya(r,t,e=!1){let n=ct(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function ma(r,t,e=!1){let n=ft(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function da(r,t,e,n=!1){let o=lt(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function ga(r,t,e,n=!1){let o=nr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function ha(r,t,e,n=!1){let o=e?e.storage:void 0,a=zr(r.storage,t,o,n);return typeof a=="number"?a:I._fromStorage(a)}function Aa(r,t,e=!1){let n=Br(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function ba(r,t,e=!1){let n=_r(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Sa(r,t,e=!1){let n=Er(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Da(r,t,e=0,n=!1){let o=cr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Na(r,t,e=0,n=!1){let o=pt(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function wa(r,t,e=!1){let n=Ur(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function xa(r,t,e=!1){let n=Tr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ia(r,t){let e=Or(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function za(r,t){let e=$r(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function Ba(r,t){return I._fromStorage(yt(r.storage,t))}function _a(r,t){return I._fromStorage(mt(r.storage,t))}function Ea(r,t,e=!1){let n=vr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ua(r){return r.cbrt()}function Ta(r){return r.fabs()}function Oa(r,t){return r.divmod(t)}function $a(r){return r.square()}function va(r,t){return r.remainder(t)}function Ma(r,t){return r.heaviside(t)}function Ca(r,...t){let e=t.map(o=>o.storage),n=qe(r,...e);return typeof n=="number"||typeof n=="bigint"?n:I._fromStorage(n)}var I,_t=$(()=>{"use strict";kt();V();F();ee();le();me();ht();je();Ge();on();pn();An();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 y=0;y<a;y++)s[y]=l[y]!==BigInt(0)?1:0;else for(let y=0;y<a;y++)s[y]=Number(l[y])}else if(!N(n)&&N(t)){let l=u;for(let y=0;y<a;y++)s[y]=BigInt(Math.round(Number(l[y])))}else if(t==="bool"){let l=u;for(let y=0;y<a;y++)s[y]=l[y]!==0?1:0}else if(n==="bool"&&!N(t)){let l=u;for(let y=0;y<a;y++)s[y]=l[y]}else if(!N(n)&&!N(t)){let l=u;for(let y=0;y<a;y++)s[y]=l[y]}else{let l=u;for(let y=0;y<a;y++)s[y]=l[y]}let c=D.fromData(s,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=Rt(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=qt(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=Lt(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=jt(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=Nr(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=Qr(this._storage,e);return r._fromStorage(n)}positive(){let t=Ht(this._storage);return r._fromStorage(t)}reciprocal(){let t=Yt(this._storage);return r._fromStorage(t)}sqrt(){let t=Ze(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=We(this._storage,e);return r._fromStorage(n)}absolute(){let t=Zt(this._storage);return r._fromStorage(t)}negative(){let t=Wt(this._storage);return r._fromStorage(t)}sign(){let t=Gt(this._storage);return r._fromStorage(t)}sin(){let t=He(this._storage);return r._fromStorage(t)}cos(){let t=Ye(this._storage);return r._fromStorage(t)}tan(){let t=Je(this._storage);return r._fromStorage(t)}arcsin(){let t=Qe(this._storage);return r._fromStorage(t)}arccos(){let t=Xe(this._storage);return r._fromStorage(t)}arctan(){let t=Ke(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=rn(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=tn(this._storage,e);return r._fromStorage(n)}degrees(){let t=en(this._storage);return r._fromStorage(t)}radians(){let t=nn(this._storage);return r._fromStorage(t)}sinh(){let t=an(this._storage);return r._fromStorage(t)}cosh(){let t=sn(this._storage);return r._fromStorage(t)}tanh(){let t=un(this._storage);return r._fromStorage(t)}arcsinh(){let t=cn(this._storage);return r._fromStorage(t)}arccosh(){let t=fn(this._storage);return r._fromStorage(t)}arctanh(){let t=ln(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=ne(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=oe(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=ae(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=se(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=ie(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=ue(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=rt(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 ce(this._storage,o,e,n)}sum(t,e=!1){let n=ur(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=wr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=xr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=Ir(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=tt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=et(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=nt(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=ot(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=ye(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=at(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=st(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(it(this._storage,t))}cumprod(t){return r._fromStorage(ut(this._storage,t))}ptp(t,e=!1){let n=ct(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=ft(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=lt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=nr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=zr(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=Br(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=_r(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=Er(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=cr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=pt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=Ur(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=Tr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=Or(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=$r(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(yt(this._storage,t))}nancumprod(t){return r._fromStorage(mt(this._storage,t))}nanmedian(t,e=!1){let n=vr(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=R(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Mr(this._storage);return r._fromStorage(t)}ravel(){let t=lr(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=pr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=de(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=fr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=ge(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=dt(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=Ie(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=mn(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;dn(this._storage,t,n)}matmul(t){let e=X(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=bt(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return Pe(this._storage)}inner(t){let e=Ve(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=St(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=Fe(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=Jt(this._storage);return r._fromStorage(t)}fabs(){let t=Qt(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=Xt(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=Kt(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=re(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=te(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=Mt(u);return Ct(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 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(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 Et(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}function Pa(r){if(r.startsWith("[")||r.startsWith("("))throw new j(`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 ka)throw new j(`Unsupported dtype: ${ka[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Hs[e];if(!o)throw new j(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${kr.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Et(),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 dr,kr,Hs,gr,ka,j,P,hr=$(()=>{"use strict";dr=new Uint8Array([147,78,85,77,80,89]),kr=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];Hs={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},gr={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},ka={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};j=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},P=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}}});function Y(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Pr(t);return Vr(t,e)}function Pr(r){if(r.length<10)throw new P("File too small to be a valid NPY file");for(let c=0;c<dr.length;c++)if(r[c]!==dr[c])throw new P("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new P(`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 P("File truncated: header extends beyond file");let i=r.slice(o,a),s=new TextDecoder("utf-8").decode(i).trim(),u=Ys(s);return{version:{major:t,minor:e},header:u,dataOffset:a}}function Vr(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:i}=Pa(e.descr),s=e.shape.reduce((d,g)=>d*g,1),u=s*i,c=r.length-n;if(c<u)throw new P(`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=Js(l,o,s,a,i),p=e.shape,m;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),g=D.fromData(f,d,o);m=Qs(g,d),p=e.shape}else m=D.fromData(f,[...p],o);return new I(m)}function Ys(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 P(`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 P(`Invalid shape value: ${u}`);return c}),{descr:o,fortran_order:a,shape:s}}function Js(r,t,e,n,o){let a=_(t);if(!a)throw new P(`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 Qs(r,t){let e=t.length,n=r.size,o=r.dtype,a=_(o);if(!a)throw new P(`Cannot create array for dtype: ${o}`);let i=new a(n),s=[...t].reverse(),u=Va(t),c=Va(s),l=new Array(e).fill(0);for(let y=0;y<n;y++){let f=y;for(let m=0;m<e;m++){let d=u[m];l[m]=Math.floor(f/d),f=f%d}let p=0;for(let m=0;m<e;m++)p+=l[e-1-m]*c[m];N(o),i[p]=r.iget(y)}return D.fromData(i,s,o)}function Va(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}var Fr=$(()=>{"use strict";_t();F();V();hr()});function W(r){let t=r.shape,e=r.dtype,n=gr[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,y=r.size,f=Vt(e),p=y*f,m=i+l+p,d=new Uint8Array(m);d.set(dr,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 Xs(r,d.subarray(g),f),d}function Xs(r,t,e){let n=r.dtype,o=r.size,a=Et(),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 y=s.iget(l),f=l*e;i?Ks(c,f,y,n==="uint64"):ri(c,f,y,n)}}}function Ks(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function ri(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 Rr=$(()=>{"use strict";V();hr()});function Ut(r){let t=4294967295;for(let e=0;e<r.length;e++)t=ti[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}var ti,Tt=$(()=>{"use strict";ti=(()=>{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})()});async function Fa(r){let t=qa(r),e=new Map;for(let n of t){let o=await ei(n);e.set(n.name,o)}return e}function Ra(r){let t=qa(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 qa(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 y=e.getUint16(u+10,!0),f=e.getUint32(u+16,!0),p=e.getUint32(u+20,!0),m=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:y,crc32:f,compressedSize:p,uncompressedSize:m,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),m=l+30+f+p,d=t.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 ei(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await ni(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function ni(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}var La=$(()=>{"use strict";Tt()});var Za={};Hr(Za,{loadNpz:()=>qr,loadNpzSync:()=>Lr,parseNpz:()=>rr,parseNpzSync:()=>br});async function rr(r,t={}){let e=t.force??!1,n=await Fa(r);return ja(n,e)}function br(r,t={}){let e=t.force??!1,n=Ra(r);return ja(n,e)}function ja(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=Y(i);e.set(s,u)}catch(u){if(u instanceof j&&t)n.push(s),o.set(s,u.message);else throw u}}return{arrays:e,skipped:n,errors:o}}async function qr(r,t={}){let e=await rr(r,t);return Object.fromEntries(e.arrays)}function Lr(r,t={}){let e=br(r,t);return Object.fromEntries(e.arrays)}var jr=$(()=>{"use strict";Fr();hr();La()});async function Wa(r,t={}){let e=t.compress??!1,n=[];for(let[f,p]of r){let m=Ut(p),d,g;e?(d=await ai(p),d.length<p.length?g=8:(d=p,g=0)):(d=p,g=0),n.push({name:f,data:p,compressedData:d,crc:m,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=Ha(u,c,l,f);let y=l;for(let f of n)l=Ya(u,c,l,f);return Ja(c,l,n.length,a,y),u}function Ga(r){let t=[];for(let[l,y]of r){let f=Ut(y);t.push({name:l,data:y,compressedData:y,crc:f,compressionMethod:0,offset:0})}let e=0;for(let l of t){let y=new TextEncoder().encode(l.name);e+=30+y.length+l.compressedData.length}let n=0;for(let l of t){let y=new TextEncoder().encode(l.name);n+=46+y.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=Ha(i,s,u,l);let c=u;for(let l of t)u=Ya(i,s,u,l);return Ja(s,u,t.length,n,c),i}function Ha(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 Ya(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 Ja(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 ai(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}var Qa=$(()=>{"use strict";Tt()});var Ka={};Hr(Ka,{serializeNpz:()=>ar,serializeNpzSync:()=>Zr});async function ar(r,t={}){let e=Xa(r);return Wa(e,{compress:t.compress??!1})}function Zr(r){let t=Xa(r);return Ga(t)}function Xa(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=W(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=W(o),i=n.endsWith(".npy")?n:`${n}.npy`;t.set(i,a)}return t}var Wr=$(()=>{"use strict";Rr();Qa()});var mi={};Hr(mi,{DTYPE_TO_DESCR:()=>gr,InvalidNpyError:()=>P,NDArray:()=>I,SUPPORTED_DTYPES:()=>kr,UnsupportedDTypeError:()=>j,__version__:()=>si,absolute:()=>Wn,append:()=>Ko,arange:()=>Sn,arccos:()=>lo,arccosh:()=>xo,arcsin:()=>fo,arcsinh:()=>wo,arctan:()=>po,arctan2:()=>yo,arctanh:()=>Io,array:()=>k,array_equal:()=>ca,array_equiv:()=>fa,array_split:()=>Oo,asanyarray:()=>Un,asarray:()=>mr,ascontiguousarray:()=>Tn,asfortranarray:()=>On,atleast_1d:()=>Wo,atleast_2d:()=>Go,atleast_3d:()=>Ho,average:()=>ha,broadcast_arrays:()=>oa,broadcast_shapes:()=>aa,broadcast_to:()=>na,cbrt:()=>Ua,choose:()=>ua,column_stack:()=>Jo,concatenate:()=>K,copy:()=>In,cos:()=>uo,cosh:()=>Do,cumprod:()=>pa,cumsum:()=>la,deg2rad:()=>Ao,degrees:()=>go,delete:()=>ra,diag:()=>zt,diagflat:()=>$n,diagonal:()=>to,divmod:()=>Oa,dot:()=>Kn,dsplit:()=>Yo,dstack:()=>Uo,einsum:()=>Ca,empty:()=>xt,empty_like:()=>_n,expand_dims:()=>Fo,eye:()=>wt,fabs:()=>Ta,flip:()=>Cr,fliplr:()=>Ro,flipud:()=>qo,floor_divide:()=>Jn,frombuffer:()=>Fn,fromfile:()=>Rn,fromfunction:()=>vn,fromiter:()=>qn,fromstring:()=>Ln,full:()=>It,full_like:()=>En,geomspace:()=>wn,heaviside:()=>Ma,hsplit:()=>vo,hstack:()=>Eo,hypot:()=>mo,identity:()=>xn,inner:()=>oo,insert:()=>ta,kron:()=>eo,linspace:()=>Dn,load:()=>ui,loadNpy:()=>rs,loadNpySync:()=>ts,loadNpz:()=>qr,loadNpzFile:()=>os,loadNpzFileSync:()=>as,loadNpzSync:()=>Lr,loadSync:()=>ci,logspace:()=>Nn,median:()=>ma,meshgrid:()=>Mn,mod:()=>Yn,moveaxis:()=>Bo,nanargmax:()=>za,nanargmin:()=>Ia,nancumprod:()=>_a,nancumsum:()=>Ba,nanmax:()=>xa,nanmean:()=>Sa,nanmedian:()=>Ea,nanmin:()=>wa,nanprod:()=>ba,nanstd:()=>Na,nansum:()=>Aa,nanvar:()=>Da,negative:()=>Gn,ones:()=>Nt,ones_like:()=>Bn,outer:()=>ao,pad:()=>ea,parseNpy:()=>Y,parseNpyData:()=>Vr,parseNpyHeader:()=>Pr,parseNpz:()=>rr,parseNpzSync:()=>br,percentile:()=>da,positive:()=>Qn,power:()=>Zn,ptp:()=>ya,put:()=>ia,quantile:()=>ga,rad2deg:()=>bo,radians:()=>ho,ravel:()=>ko,reciprocal:()=>Xn,remainder:()=>va,repeat:()=>Co,reshape:()=>Po,resize:()=>Xo,roll:()=>jo,rollaxis:()=>Zo,rot90:()=>Lo,row_stack:()=>Qo,save:()=>fi,saveNpy:()=>es,saveNpySync:()=>ns,saveNpz:()=>vt,saveNpzSync:()=>ii,saveSync:()=>li,savez:()=>pi,savez_compressed:()=>yi,serializeNpy:()=>W,serializeNpz:()=>ar,serializeNpzSync:()=>Zr,sign:()=>Hn,sin:()=>io,sinh:()=>So,split:()=>To,sqrt:()=>jn,square:()=>$a,squeeze:()=>Vo,stack:()=>_o,swapaxes:()=>zo,take:()=>sa,tan:()=>co,tanh:()=>No,tensordot:()=>so,tile:()=>Mo,trace:()=>ro,transpose:()=>no,tri:()=>Cn,tril:()=>kn,triu:()=>Pn,vander:()=>Vn,vsplit:()=>$o,vstack:()=>Bt,zeros:()=>L,zeros_like:()=>zn});module.exports=Yr(mi);var sr=require("node:fs"),ir=require("node:fs/promises");Fr();Rr();jr();Wr();_t();Fr();Rr();hr();jr();Wr();var si="0.6.0";async function rs(r){let t=await(0,ir.readFile)(r);return Y(t)}function ts(r){let t=(0,sr.readFileSync)(r);return Y(t)}async function es(r,t){let e=W(t);await(0,ir.writeFile)(r,e)}function ns(r,t){let e=W(t);(0,sr.writeFileSync)(r,e)}async function os(r,t={}){let e=await(0,ir.readFile)(r);return rr(e,t)}function as(r,t={}){let e=(0,sr.readFileSync)(r),{parseNpzSync:n}=(jr(),Yr(Za));return n(e,t)}async function vt(r,t,e={}){let n=await ar(t,e);await(0,ir.writeFile)(r,n)}function ii(r,t){let{serializeNpzSync:e}=(Wr(),Yr(Ka)),n=e(t);(0,sr.writeFileSync)(r,n)}async function ui(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return rs(r)}else{if(r.endsWith(".npz"))return os(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function ci(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return ts(r)}else{if(r.endsWith(".npz"))return as(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function fi(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return es(r,t)}function li(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return ns(r,t)}async function pi(r,t){return r.endsWith(".npz")||(r=r+".npz"),vt(r,t,{compress:!1})}async function yi(r,t){return r.endsWith(".npz")||(r=r+".npz"),vt(r,t,{compress:!0})}0&&(module.exports={DTYPE_TO_DESCR,InvalidNpyError,NDArray,SUPPORTED_DTYPES,UnsupportedDTypeError,__version__,absolute,append,arange,arccos,arccosh,arcsin,arcsinh,arctan,arctan2,arctanh,array,array_equal,array_equiv,array_split,asanyarray,asarray,ascontiguousarray,asfortranarray,atleast_1d,atleast_2d,atleast_3d,average,broadcast_arrays,broadcast_shapes,broadcast_to,cbrt,choose,column_stack,concatenate,copy,cos,cosh,cumprod,cumsum,deg2rad,degrees,delete:null,diag,diagflat,diagonal,divmod,dot,dsplit,dstack,einsum,empty,empty_like,expand_dims,eye,fabs,flip,fliplr,flipud,floor_divide,frombuffer,fromfile,fromfunction,fromiter,fromstring,full,full_like,geomspace,heaviside,hsplit,hstack,hypot,identity,inner,insert,kron,linspace,load,loadNpy,loadNpySync,loadNpz,loadNpzFile,loadNpzFileSync,loadNpzSync,loadSync,logspace,median,meshgrid,mod,moveaxis,nanargmax,nanargmin,nancumprod,nancumsum,nanmax,nanmean,nanmedian,nanmin,nanprod,nanstd,nansum,nanvar,negative,ones,ones_like,outer,pad,parseNpy,parseNpyData,parseNpyHeader,parseNpz,parseNpzSync,percentile,positive,power,ptp,put,quantile,rad2deg,radians,ravel,reciprocal,remainder,repeat,reshape,resize,roll,rollaxis,rot90,row_stack,save,saveNpy,saveNpySync,saveNpz,saveNpzSync,saveSync,savez,savez_compressed,serializeNpy,serializeNpz,serializeNpzSync,sign,sin,sinh,split,sqrt,square,squeeze,stack,swapaxes,take,tan,tanh,tensordot,tile,trace,transpose,tri,tril,triu,vander,vsplit,vstack,zeros,zeros_like});
1
+ "use strict";var ut=Object.defineProperty;var Gi=Object.getOwnPropertyDescriptor;var Hi=Object.getOwnPropertyNames;var Yi=Object.prototype.hasOwnProperty;var C=(r,t)=>()=>(r&&(t=r(r=0)),t);var ct=(r,t)=>{for(var e in t)ut(r,e,{get:t[e],enumerable:!0})},Ji=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Hi(t))!Yi.call(r,o)&&o!==e&&ut(r,o,{get:()=>t[o],enumerable:!(n=Gi(t,o))||n.enumerable});return r};var ft=r=>Ji(ut({},"__esModule",{value:!0}),r);function se(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 ie(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 s=e<0?t+e:e;if(s<0||s>=t)throw new Error(`Index ${e} is out of bounds for size ${t}`);return{start:s,stop:s+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 ue=C(()=>{"use strict"});function O(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 fe(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 le(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function ce(r){return r==="float64"||r==="float32"}function x(r){return r==="int64"||r==="uint64"}function k(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(ce(r)||ce(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"),s=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,i=s(r),u=s(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&i===u){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(o&&n&&i===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(i,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?i>u?r:u===8?"int16":u===16?"int32":u===32?"int64":"float64":o&&n?u>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}var V,q=C(()=>{"use strict";V="float64"});function j(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}var D,W=C(()=>{"use strict";q();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,s=this._offset;for(let i=0;i<o;i++){let u=1;for(let f=i+1;f<o;f++)u*=e[f];let c=Math.floor(a/u);a=a%u,s+=c*n[i]}return this._data[s]}iset(t,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let s=t,i=this._offset;for(let u=0;u<a;u++){let c=1;for(let p=u+1;p<a;p++)c*=n[p];let f=Math.floor(s/c);s=s%c,i+=f*o[u]}this._data[i]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];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=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(x(e)){let s=this._data,i=a;for(let u=0;u<n;u++)i[u]=s[u]}else a.set(this._data);else if(x(e)){let s=a;for(let i=0;i<n;i++)s[i]=this.iget(i)}else for(let s=0;s<n;s++)a[s]=this.iget(s);return new r(a,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let s=o??r._computeStrides(e),i=a??0;return new r(t,e,s,i,n)}static zeros(t,e=V){let n=t.reduce((s,i)=>s*i,1),o=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=V){let n=t.reduce((s,i)=>s*i,1),o=O(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return x(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 pe(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let s=0;s<o;s++){let i=s<o-e?1:r[s-(o-e)],u=s<o-n?1:t[s-(o-n)];if(i===u)a[s]=i;else if(i===1)a[s]=u;else if(u===1)a[s]=i;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function Xi(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let s=0;s<n;s++){let i=o-n+s,u=r[s],c=e[i];if(u===c)a[i]=t[s];else if(u===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function Ur(r,t){let e=Xi(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function L(r,t,e,n){let o=pe(r.shape,t.shape),a=Ur(r,o),s=Ur(t,o),i=k(r.dtype,t.dtype),u=D.zeros(o,i),c=u.data,f=u.size;if(x(i)){let p=c;for(let l=0;l<f;l++){let y=a.iget(l),m=s.iget(l),d=typeof y=="bigint"?y:BigInt(Math.round(y)),g=typeof m=="bigint"?m:BigInt(Math.round(m));n==="add"?p[l]=d+g:n==="subtract"?p[l]=d-g:n==="multiply"?p[l]=d*g:n==="divide"?p[l]=d/g:p[l]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let p=x(r.dtype)||x(t.dtype);for(let l=0;l<f;l++){let y=a.iget(l),m=s.iget(l),d=Number(y),g=Number(m);c[l]=e(d,g)}}return u}function er(r,t,e){let n=pe(r.shape,t.shape),o=Ur(r,n),a=Ur(t,n),s=n.reduce((c,f)=>c*f,1),i=new Uint8Array(s),u=x(r.dtype)||x(t.dtype);for(let c=0;c<s;c++){let f=o.iget(c),p=a.iget(c),l=Number(f),y=Number(p);i[c]=e(l,y)?1:0}return D.fromData(i,n,"bool")}function F(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,i=e?n:n!=="float32"&&n!=="float64"?"float64":n,u=D.zeros(o,i),c=u.data,f=r.data;if(x(n))if(x(i)){let p=c;for(let l=0;l<a;l++){let y=Number(f[l]);p[l]=BigInt(Math.round(t(y)))}}else for(let p=0;p<a;p++)c[p]=t(Number(f[p]));else for(let p=0;p<a;p++)c[p]=t(Number(f[p]));return u}var ar=C(()=>{"use strict";W();q()});function lt(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function ye(r,t){return typeof t=="number"?tu(r,t):lt(r,t)?Qi(r,t):L(r,t,(e,n)=>e+n,"add")}function Qi(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p+l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]+p[l]}}else if(x(r.dtype)||x(t.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],p=typeof s[c]=="bigint"?Number(s[c]):s[c];i[c]=f+p}else for(let c=0;c<o;c++)i[c]=a[c]+s[c];return n}function me(r,t){return typeof t=="number"?eu(r,t):lt(r,t)?Ki(r,t):L(r,t,(e,n)=>e-n,"subtract")}function Ki(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p-l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]-p[l]}}else if(x(r.dtype)||x(t.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],p=typeof s[c]=="bigint"?Number(s[c]):s[c];i[c]=f-p}else for(let c=0;c<o;c++)i[c]=a[c]-s[c];return n}function de(r,t){return typeof t=="number"?nu(r,t):lt(r,t)?ru(r,t):L(r,t,(e,n)=>e*n,"multiply")}function ru(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p*l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]*p[l]}}else if(x(r.dtype)||x(t.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],p=typeof s[c]=="bigint"?Number(s[c]):s[c];i[c]=f*p}else for(let c=0;c<o;c++)i[c]=a[c]*s[c];return n}function ge(r,t){if(typeof t=="number")return ou(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:lr(r,"float64"),c=n?t:lr(t,"float64");return L(u,c,(f,p)=>f/p,"divide")}if(o||a){let u=o?r:lr(r,"float32"),c=a?t:lr(t,"float32");return L(u,c,(f,p)=>f/p,"divide")}let s=lr(r,"float64"),i=lr(t,"float64");return L(s,i,(u,c)=>u/c,"divide")}function lr(r,t){let e=D.zeros(Array.from(r.shape),t),n=r.size,o=r.data,a=e.data;for(let s=0;s<n;s++)a[s]=Number(o[s]);return e}function tu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]+f}else for(let u=0;u<a;u++)i[u]=Number(o[u])+t;return s}function eu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]-f}else for(let u=0;u<a;u++)i[u]=Number(o[u])-t;return s}function nu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]*f}else for(let u=0;u<a;u++)i[u]=Number(o[u])*t;return s}function ou(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e!=="float32"&&e!=="float64"?"float64":e,u=D.zeros(n,i),c=u.data;if(x(e))for(let f=0;f<a;f++)c[f]=Number(o[f])/t;else for(let f=0;f<a;f++)c[f]=Number(o[f])/t;return u}function Ae(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++){let f=i[c];u[c]=f<0n?-f:f}}else for(let i=0;i<o;i++)s[i]=Math.abs(Number(n[i]));return a}function he(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++)u[c]=-i[c]}else for(let i=0;i<o;i++)s[i]=-Number(n[i]);return a}function be(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++){let f=i[c];u[c]=f>0n?1n:f<0n?-1n:0n}}else for(let i=0;i<o;i++){let u=Number(n[i]);s[i]=u>0?1:u<0?-1:0}return a}function vr(r,t){return typeof t=="number"?au(r,t):L(r,t,(e,n)=>(e%n+n)%n,"mod")}function au(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++){let l=u[p];c[p]=(l%f+f)%f}}else for(let u=0;u<a;u++){let c=Number(o[u]);i[u]=(c%t+t)%t}return s}function pt(r,t){return typeof t=="number"?su(r,t):L(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function su(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]/f}else for(let u=0;u<a;u++)i[u]=Math.floor(Number(o[u])/t);return s}function Se(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;for(let i=0;i<o;i++)s[i]=n[i];return a}function De(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,s=t!=="float32"&&t!=="float64"?"float64":t,i=D.zeros(e,s),u=i.data;if(x(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 i}function xe(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,s=t!=="float32"&&t!=="float64"?"float64":t,i=D.zeros(e,s),u=i.data;for(let c=0;c<o;c++)u[c]=Math.cbrt(Number(n[c]));return i}function Ne(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",s=D.zeros(e,a),i=s.data;for(let u=0;u<o;u++)i[u]=Math.abs(Number(n[u]));return s}function we(r,t){let e=pt(r,t),n=vr(r,t);return[e,n]}function Ie(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++)u[c]=i[c]*i[c]}else for(let i=0;i<o;i++){let u=Number(n[i]);s[i]=u*u}return a}function ze(r,t){return vr(r,t)}function _e(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",s=D.zeros(n,a),i=s.data;if(typeof t=="number")for(let u=0;u<o;u++){let c=Number(r.data[u]);c<0?i[u]=0:c===0?i[u]=t:i[u]=1}else{let u=t.data,c=t.shape;if(n.every((f,p)=>f===c[p]))for(let f=0;f<o;f++){let p=Number(r.data[f]);p<0?i[f]=0:p===0?i[f]=Number(u[f]):i[f]=1}else for(let f=0;f<o;f++){let p=Number(r.data[f]),l=f%t.size;p<0?i[f]=0:p===0?i[f]=Number(u[l]):i[f]=1}}return s}var Be=C(()=>{"use strict";W();q();ar()});function nr(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 s=a.length-t+n,i=s<0?1:a[s];if(i!==1){if(o===1)o=i;else if(o!==i)return null}}e[n]=o}return e}function uu(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let s=0;s<n;s++){let i=o-n+s,u=r[s],c=e[i];if(u===c)a[i]=t[s];else if(u===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function J(r,t){let e=uu(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function yt(...r){let t=nr(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}var mt=C(()=>{"use strict";W()});function Ee(r,t){return typeof t=="number"?cu(r,t):er(r,t,(e,n)=>e>n)}function Te(r,t){return typeof t=="number"?fu(r,t):er(r,t,(e,n)=>e>=n)}function Ue(r,t){return typeof t=="number"?lu(r,t):er(r,t,(e,n)=>e<n)}function ve(r,t){return typeof t=="number"?pu(r,t):er(r,t,(e,n)=>e<=n)}function Oe(r,t){return typeof t=="number"?yu(r,t):er(r,t,(e,n)=>e===n)}function $e(r,t){return typeof t=="number"?mu(r,t):er(r,t,(e,n)=>e!==n)}function dt(r,t,e=1e-5,n=1e-8){return typeof t=="number"?du(r,t,e,n):er(r,t,(o,a)=>{let s=Math.abs(o-a),i=n+e*Math.abs(a);return s<=i})}function Me(r,t,e=1e-5,n=1e-8){let o=dt(r,t,e,n),a=o.data;for(let s=0;s<o.size;s++)if(a[s]===0)return!1;return!0}function Ce(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=nr(e);if(n===null)return!1;let o=J(r,n),a=J(t,n),s=n.length,i=n.reduce((f,p)=>f*p,1),u=x(o.dtype),c=x(a.dtype);for(let f=0;f<i;f++){let p=f,l=new Array(s);for(let d=s-1;d>=0;d--)l[d]=p%n[d],p=Math.floor(p/n[d]);let y=o.get(...l),m=a.get(...l);if(u||c){let d=typeof y=="bigint"?y:BigInt(Number(y)),g=typeof m=="bigint"?m:BigInt(Number(m));if(d!==g)return!1}else if(y!==m)return!1}return!0}function cu(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 fu(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 lu(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 pu(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 yu(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(x(o)){let a=BigInt(Math.round(t)),s=n;for(let i=0;i<r.size;i++)e[i]=s[i]===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 mu(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 du(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,s=r.dtype;if(x(s)){let i=a;for(let u=0;u<r.size;u++){let c=Number(i[u]),f=Math.abs(c-t),p=n+e*Math.abs(t);o[u]=f<=p?1:0}}else for(let i=0;i<r.size;i++){let u=Number(a[i]),c=Math.abs(u-t),f=n+e*Math.abs(t);o[i]=c<=f?1:0}return D.fromData(o,Array.from(r.shape),"bool")}var ke=C(()=>{"use strict";W();q();ar();mt()});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 v(r,t,e,n){let o=n.length,a=new Array(o),s=Array.from(n).filter((u,c)=>c!==t),i=r;for(let u=s.length-1;u>=0;u--)a[u>=t?u+1:u]=i%s[u],i=Math.floor(i/s[u]);return a[t]=e,a}var gt=C(()=>{"use strict"});function gr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0)if(x(n)){let m=i,d=BigInt(0);for(let g=0;g<s;g++)d+=m[g];return Number(d)}else{let m=0;for(let d=0;d<s;d++)m+=Number(i[d]);return m}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((m,d)=>d!==u);if(c.length===0)return gr(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=BigInt(0);for(let A=0;A<l;A++){let b=v(g,u,A,o),S=U(b,o);h+=m[S]}d[g]=h}}else for(let m=0;m<y;m++){let d=0;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o);d+=Number(i[A])}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function Or(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return gr(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 s=gr(r,t,e);if(typeof s=="number")return s/o[a];let i=o[a],u=n;(x(n)||n.startsWith("int")||n.startsWith("uint"))&&(u="float64");let c=D.zeros(Array.from(s.shape),u),f=c.data,p=s.data;if(x(n)){let l=p;for(let y=0;y<f.length;y++)f[y]=Number(l[y])/i}else for(let l=0;l<f.length;l++)f[l]=Number(p[l])/i;return c}function $r(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0){if(s===0)throw new Error("max of empty array");let m=i[0];for(let d=1;d<s;d++)i[d]>m&&(m=i[d]);return Number(m)}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((m,d)=>d!==u);if(c.length===0)return $r(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=v(g,u,0,o),A=U(h,o),b=m[A];for(let S=1;S<l;S++){let N=v(g,u,S,o),w=U(N,o),I=m[w];I>b&&(b=I)}d[g]=b}}else for(let m=0;m<y;m++){let d=-1/0;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o),b=Number(i[A]);b>d&&(d=b)}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function At(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0)if(x(n)){let m=i,d=BigInt(1);for(let g=0;g<s;g++)d*=m[g];return Number(d)}else{let m=1;for(let d=0;d<s;d++)m*=Number(i[d]);return m}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((m,d)=>d!==u);if(c.length===0)return At(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=BigInt(1);for(let A=0;A<l;A++){let b=v(g,u,A,o),S=U(b,o);h*=m[S]}d[g]=h}}else for(let m=0;m<y;m++){let d=1;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o);d*=Number(i[A])}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function Mr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0){if(s===0)throw new Error("min of empty array");let m=i[0];for(let d=1;d<s;d++)i[d]<m&&(m=i[d]);return Number(m)}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((m,d)=>d!==u);if(c.length===0)return Mr(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=v(g,u,0,o),A=U(h,o),b=m[A];for(let S=1;S<l;S++){let N=v(g,u,S,o),w=U(N,o),I=m[w];I<b&&(b=I)}d[g]=b}}else for(let m=0;m<y;m++){let d=1/0;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o),b=Number(i[A]);b<d&&(d=b)}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function ht(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let y=s[0],m=0;for(let d=1;d<a;d++)s[d]<y&&(y=s[d],m=d);return m}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return ht(r);let c=D.zeros(u,"int32"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);if(x(e)){let y=s;for(let m=0;m<l;m++){let d=v(m,i,0,n),g=U(d,n),h=y[g],A=0;for(let b=1;b<p;b++){let S=v(m,i,b,n),N=U(S,n),w=y[N];w<h&&(h=w,A=b)}f[m]=A}}else for(let y=0;y<l;y++){let m=1/0,d=0;for(let g=0;g<p;g++){let h=v(y,i,g,n),A=U(h,n),b=Number(s[A]);b<m&&(m=b,d=g)}f[y]=d}return c}function bt(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){if(a===0)throw new Error("argmax of empty array");let y=s[0],m=0;for(let d=1;d<a;d++)s[d]>y&&(y=s[d],m=d);return m}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return bt(r);let c=D.zeros(u,"int32"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);if(x(e)){let y=s;for(let m=0;m<l;m++){let d=v(m,i,0,n),g=U(d,n),h=y[g],A=0;for(let b=1;b<p;b++){let S=v(m,i,b,n),N=U(S,n),w=y[N];w>h&&(h=w,A=b)}f[m]=A}}else for(let y=0;y<l;y++){let m=-1/0,d=0;for(let g=0;g<p;g++){let h=v(y,i,g,n),A=U(h,n),b=Number(s[A]);b>m&&(m=b,d=g)}f[y]=d}return c}function St(r,t,e=0,n=!1){let o=r.shape,a=o.length,s=r.size,i=r.data,u=Or(r,t,n);if(t===void 0){let h=u,A=0;for(let b=0;b<s;b++){let S=Number(i[b])-h;A+=S*S}return A/(s-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 f=o[c],p=u,l=p.data,y=n?p.shape:Array.from(o).filter((h,A)=>A!==c),m=D.zeros(Array.from(y),"float64"),d=m.data,g=y.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=v(h,c,S,o),w=U(N,o),I=Number(i[w])-b;A+=I*I}d[h]=A/(f-e)}return m}function Pe(r,t,e=0,n=!1){let o=St(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=D.zeros(Array.from(o.shape),"float64"),s=o.data,i=a.data;for(let u=0;u<s.length;u++)i[u]=Math.sqrt(Number(s[u]));return a}function Dt(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){for(let y=0;y<a;y++)if(!s[y])return!1;return!0}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return Dt(r);let c=D.zeros(u,"bool"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);for(let y=0;y<l;y++){let m=!0;for(let d=0;d<p;d++){let g=v(y,i,d,n),h=U(g,n);if(!s[h]){m=!1;break}}f[y]=m?1:0}if(e){let y=[...n];return y[i]=1,D.fromData(f,y,"bool")}return c}function xt(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){for(let y=0;y<a;y++)if(s[y])return!0;return!1}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return xt(r);let c=D.zeros(u,"bool"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);for(let y=0;y<l;y++){let m=!1;for(let d=0;d<p;d++){let g=v(y,i,d,n),h=U(g,n);if(s[h]){m=!0;break}}f[y]=m?1:0}if(e){let y=[...n];return y[i]=1,D.fromData(f,y,"bool")}return c}function Nt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=0;for(let d=0;d<l;d++)m+=Number(o[d]),y[d]=m;return D.fromData(y,[l],"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 s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++)Math.floor(l/p)%i===0?s[l]=Number(o[l]):s[l]=s[l-p]+Number(o[l]);return D.fromData(s,[...e],"float64")}function wt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=1;for(let d=0;d<l;d++)m*=Number(o[d]),y[d]=m;return D.fromData(y,[l],"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 s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++)Math.floor(l/p)%i===0?s[l]=Number(o[l]):s[l]=s[l-p]*Number(o[l]);return D.fromData(s,[...e],"float64")}function It(r,t,e=!1){let n=$r(r,t,e),o=Mr(r,t,e);if(typeof n=="number"&&typeof o=="number")return n-o;let a=n,s=o,i=a.data,u=s.data,c=new Float64Array(a.size);for(let f=0;f<a.size;f++)c[f]=Number(i[f])-Number(u[f]);return D.fromData(c,[...a.shape],"float64")}function zt(r,t,e=!1){return pr(r,.5,t,e)}function _t(r,t,e,n=!1){return pr(r,t/100,e,n)}function pr(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,s=r.data;if(e===void 0){let y=[];for(let b=0;b<r.size;b++)y.push(Number(s[b]));y.sort((b,S)=>b-S);let m=y.length,d=t*(m-1),g=Math.floor(d),h=Math.ceil(d);if(g===h)return y[g];let A=d-g;return y[g]*(1-A)+y[h]*A}let i=e;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((y,m)=>m!==i);if(u.length===0)return pr(r,t);let c=u.reduce((y,m)=>y*m,1),f=o[i],p=new Float64Array(c);for(let y=0;y<c;y++){let m=[];for(let b=0;b<f;b++){let S=v(y,i,b,o),N=U(S,o);m.push(Number(s[N]))}m.sort((b,S)=>b-S);let d=m.length,g=t*(d-1),h=Math.floor(g),A=Math.ceil(g);if(h===A)p[y]=m[h];else{let b=g-h;p[y]=m[h]*(1-b)+m[A]*b}}let l=D.fromData(p,u,"float64");if(n){let y=[...o];return y[i]=1,D.fromData(p,y,"float64")}return l}function Cr(r,t,e,n=!1){let o=r.shape,a=o.length,s=r.data;if(e===void 0)return Or(r,t,n);if(t===void 0){let m=0,d=0,g=e.data;for(let h=0;h<r.size;h++){let A=Number(g[h%e.size]);m+=Number(s[h])*A,d+=A}return d===0?NaN:m/d}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((m,d)=>d!==i);if(u.length===0)return Cr(r,void 0,e);let c=u.reduce((m,d)=>m*d,1),f=o[i],p=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=v(m,i,h,o),b=U(A,o),S=Number(p[h%e.size]);d+=Number(s[b])*S,g+=S}l[m]=g===0?NaN:d/g}let y=D.fromData(l,u,"float64");if(n){let m=[...o];return m[i]=1,D.fromData(l,m,"float64")}return y}function kr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=0;for(let y=0;y<r.size;y++){let m=Number(a[y]);isNaN(m)||(l+=m)}return l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return kr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=0;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);isNaN(h)||(y+=h)}f[l]=y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Pr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=1;for(let y=0;y<r.size;y++){let m=Number(a[y]);isNaN(m)||(l*=m)}return l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Pr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=1;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);isNaN(h)||(y*=h)}f[l]=y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Vr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=0,y=0;for(let m=0;m<r.size;m++){let d=Number(a[m]);isNaN(d)||(l+=d,y++)}return y===0?NaN:l/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 i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Vr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=0,m=0;for(let d=0;d<c;d++){let g=v(l,s,d,n),h=U(g,n),A=Number(a[h]);isNaN(A)||(y+=A,m++)}f[l]=m===0?NaN:y/m}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Ar(r,t,e=0,n=!1){let o=r.shape,a=o.length,s=r.data;if(t===void 0){let y=0,m=0;for(let h=0;h<r.size;h++){let A=Number(s[h]);isNaN(A)||(y+=A,m++)}if(m-e<=0)return NaN;let d=y/m,g=0;for(let h=0;h<r.size;h++){let A=Number(s[h]);isNaN(A)||(g+=(A-d)**2)}return g/(m-e)}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((y,m)=>m!==i);if(u.length===0)return Ar(r,void 0,e);let c=u.reduce((y,m)=>y*m,1),f=o[i],p=new Float64Array(c);for(let y=0;y<c;y++){let m=0,d=0;for(let A=0;A<f;A++){let b=v(y,i,A,o),S=U(b,o),N=Number(s[S]);isNaN(N)||(m+=N,d++)}if(d-e<=0){p[y]=NaN;continue}let g=m/d,h=0;for(let A=0;A<f;A++){let b=v(y,i,A,o),S=U(b,o),N=Number(s[S]);isNaN(N)||(h+=(N-g)**2)}p[y]=h/(d-e)}let l=D.fromData(p,u,"float64");if(n){let y=[...o];return y[i]=1,D.fromData(p,y,"float64")}return l}function Bt(r,t,e=0,n=!1){let o=Ar(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,s=new Float64Array(a.size);for(let i=0;i<a.size;i++)s[i]=Math.sqrt(Number(a.data[i]));return D.fromData(s,[...a.shape],"float64")}function Fr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=1/0;for(let y=0;y<r.size;y++){let m=Number(a[y]);!isNaN(m)&&m<l&&(l=m)}return l===1/0?NaN:l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Fr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=1/0;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);!isNaN(h)&&h<y&&(y=h)}f[l]=y===1/0?NaN:y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Rr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=-1/0;for(let y=0;y<r.size;y++){let m=Number(a[y]);!isNaN(m)&&m>l&&(l=m)}return l===-1/0?NaN:l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Rr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=-1/0;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);!isNaN(h)&&h>y&&(y=h)}f[l]=y===-1/0?NaN:y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Lr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=1/0,p=-1;for(let l=0;l<r.size;l++){let y=Number(o[l]);!isNaN(y)&&y<f&&(f=y,p=l)}return p}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 s=Array.from(e).filter((f,p)=>p!==a);if(s.length===0)return Lr(r);let i=s.reduce((f,p)=>f*p,1),u=e[a],c=new Int32Array(i);for(let f=0;f<i;f++){let p=1/0,l=0;for(let y=0;y<u;y++){let m=v(f,a,y,e),d=U(m,e),g=Number(o[d]);!isNaN(g)&&g<p&&(p=g,l=y)}c[f]=l}return D.fromData(c,s,"int32")}function qr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=-1/0,p=-1;for(let l=0;l<r.size;l++){let y=Number(o[l]);!isNaN(y)&&y>f&&(f=y,p=l)}return p}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 s=Array.from(e).filter((f,p)=>p!==a);if(s.length===0)return qr(r);let i=s.reduce((f,p)=>f*p,1),u=e[a],c=new Int32Array(i);for(let f=0;f<i;f++){let p=-1/0,l=0;for(let y=0;y<u;y++){let m=v(f,a,y,e),d=U(m,e),g=Number(o[d]);!isNaN(g)&&g>p&&(p=g,l=y)}c[f]=l}return D.fromData(c,s,"int32")}function Et(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=0;for(let d=0;d<l;d++){let g=Number(o[d]);isNaN(g)||(m+=g),y[d]=m}return D.fromData(y,[l],"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 s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++){let y=Number(o[l]);Math.floor(l/p)%i===0?s[l]=isNaN(y)?0:y:s[l]=s[l-p]+(isNaN(y)?0:y)}return D.fromData(s,[...e],"float64")}function Tt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=1;for(let d=0;d<l;d++){let g=Number(o[d]);isNaN(g)||(m*=g),y[d]=m}return D.fromData(y,[l],"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 s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++){let y=Number(o[l]);Math.floor(l/p)%i===0?s[l]=isNaN(y)?1:y:s[l]=s[l-p]*(isNaN(y)?1:y)}return D.fromData(s,[...e],"float64")}function jr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=[];for(let d=0;d<r.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 y=l.length,m=Math.floor(y/2);return y%2===0?(l[m-1]+l[m])/2:l[m]}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return jr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=[];for(let g=0;g<c;g++){let h=v(l,s,g,n),A=U(h,n),b=Number(a[A]);isNaN(b)||y.push(b)}if(y.length===0){f[l]=NaN;continue}y.sort((g,h)=>g-h);let m=y.length,d=Math.floor(m/2);m%2===0?f[l]=(y[d-1]+y[d])/2:f[l]=y[d]}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}var Ve=C(()=>{"use strict";W();q();gt()});function G(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((p,l,y)=>y===o?p:p*l,1),f=e/c;if(!Number.isInteger(f))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((p,l)=>l===o?f:p)}else a=t;if(a.reduce((c,f)=>c*f,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,j(a),0)}let u=r.copy().data;return D.fromData(u,a,n,j(a),0)}function Wr(r){let t=r.size,e=r.dtype,n=O(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let i=r.data.slice(r.offset,r.offset+t);return D.fromData(i,[t],e,[1],0)}let o=new n(t),a=x(e);for(let s=0;s<t;s++){let i=r.iget(s);o[s]=i}return D.fromData(o,[t],e,[1],0)}function br(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return D.fromData(n,[t],e,[1],0)}return Wr(r)}function Sr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,s=r.dtype,i;if(t===void 0)i=Array.from({length:n},(p,l)=>n-1-l);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let p=new Set;for(let l of t){let y=l<0?n+l:l;if(y<0||y>=n)throw new Error(`axis ${l} is out of bounds for array of dimension ${n}`);if(p.has(y))throw new Error("repeated axis in transpose");p.add(y)}i=t.map(l=>l<0?n+l:l)}let u=i.map(p=>e[p]),c=Array.from(o),f=i.map(p=>c[p]);return D.fromData(a,u,s,f,r.offset)}function Fe(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,s=r.dtype;if(t===void 0){let i=[],u=[];for(let c=0;c<n;c++)e[c]!==1&&(i.push(e[c]),u.push(o[c]));return i.length===0&&(i.push(1),u.push(1)),D.fromData(a,i,s,u,r.offset)}else{let i=t<0?n+t:t;if(i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[i]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[i]})`);let u=[],c=[];for(let f=0;f<n;f++)f!==i&&(u.push(e[f]),c.push(o[f]));return D.fromData(a,u,s,c,r.offset)}}function hr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,s=r.dtype,i=t;if(i<0&&(i=n+t+1),i<0||i>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let u=[...Array.from(e)];u.splice(i,0,1);let c=[...Array.from(o)],f=i<n?o[i]*(e[i]||1):1;return c.splice(i,0,f),D.fromData(a,u,s,c,r.offset)}function Re(r,t,e){let n=r.shape,o=n.length,a=r.strides,s=r.data,i=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(s,Array.from(n),i,Array.from(a),r.offset);let f=Array.from(n),p=Array.from(a);return[f[u],f[c]]=[f[c],f[u]],[p[u],p[c]]=[p[c],p[u]],D.fromData(s,f,i,p,r.offset)}function Ut(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 s=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}),i=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(s).size!==s.length)throw new Error("repeated axis in source");if(new Set(i).size!==i.length)throw new Error("repeated axis in destination");let u=[];for(let c=0;c<n;c++)s.includes(c)||u.push(c);for(let c=0;c<s.length;c++){let f=i[c];u.splice(f,0,s[c])}return Sr(r,u)}function sr(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 y=1;y<r.length;y++){let m=r[y];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 s=Array.from(e.shape),i=e.shape[a];for(let y=1;y<r.length;y++)i+=r[y].shape[a];s[a]=i;let u=s.reduce((y,m)=>y*m,1),c=O(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let f=new c(u),p=j(s),l=0;for(let y of r){let m=y.shape[a];hu(y,f,s,p,a,l,o),l+=m}return D.fromData(f,s,o)}function hu(r,t,e,n,o,a,s){let i=r.shape,u=i.length,c=r.size,f=s==="int64"||s==="uint64";if(o===0&&r.isCContiguous&&u>0){let y=a*n[0],m=r.data,d=r.offset,g=d+c;t.set(m.subarray(d,g),y);return}if(o===1&&u===2&&r.isCContiguous){let y=i[0],m=i[1],d=e[1],g=r.data,h=r.offset;for(let A=0;A<y;A++){let b=h+A*m,S=A*d+a;t.set(g.subarray(b,b+m),S)}return}let p=new Array(u).fill(0),l=a*n[o];for(let y=0;y<c;y++){let m=r.iget(y),d=l;for(let g=0;g<u;g++)d+=p[g]*n[g];t[d]=m;for(let g=u-1;g>=0&&(p[g]++,!(p[g]<i[g]));g--)p[g]=0}}function Le(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let i=1;i<r.length;i++){let u=r[i];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 s=r.map(i=>hr(i,a));return sr(s,a)}function qe(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(e,[1,e.shape[0]]):e);return sr(t,0)}function vt(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?sr(r,0):sr(r,1)}function je(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(hr(G(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?hr(e,2):e);return sr(t,2)}function We(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 s=n[a],i;if(typeof t=="number"){if(s%t!==0)throw new Error("array split does not result in an equal division");let u=s/t;i=[];for(let c=1;c<t;c++)i.push(c*u)}else i=t;return Ze(r,i,a)}function Dr(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 s=n[a],i;if(typeof t=="number"){let u=t,c=Math.floor(s/u),f=s%u;i=[];let p=0;for(let l=0;l<u-1;l++)p+=c+(l<f?1:0),i.push(p)}else i=t;return Ze(r,i,a)}function Ze(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],s=[];for(let i=0;i<a.length-1;i++){let u=a[i],c=a[i+1];if(u>c)throw new Error("split indices must be in ascending order");let f=Array.from(n);f[e]=c-u;let p=r.offset+u*r.strides[e];s.push(D.fromData(r.data,f,r.dtype,Array.from(r.strides),p))}return s}function Ge(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return Dr(r,t,0)}function He(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 Dr(r,t,e)}function Ye(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],s=Math.max(n,a.length),i=new Array(s).fill(1),u=new Array(s).fill(1);for(let A=0;A<n;A++)i[s-n+A]=e[A];for(let A=0;A<a.length;A++)u[s-a.length+A]=a[A];let c=i.map((A,b)=>A*u[b]),f=c.reduce((A,b)=>A*b,1),p=O(o);if(!p)throw new Error(`Cannot tile array with dtype ${o}`);let l=new p(f),y=j(c),m=r;n<s&&(m=G(r,i));let d=o==="int64"||o==="uint64",g=m.strides,h=new Array(s).fill(0);for(let A=0;A<f;A++){let b=m.offset;for(let w=0;w<s;w++){let I=h[w]%i[w];b+=I*g[w]}let S=m.data[b],N=0;for(let w=0;w<s;w++)N+=h[w]*y[w];l[N]=S;for(let w=s-1;w>=0&&(h[w]++,!(h[w]<c[w]));w--)h[w]=0}return D.fromData(l,c,o)}function Je(r,t,e){let n=r.shape,o=n.length,a=r.dtype,s=r.size;if(e===void 0){let A=s,b=Array.isArray(t)?t:new Array(A).fill(t);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=O(a);if(!N)throw new Error(`Cannot repeat array with dtype ${a}`);let w=new N(S),I=0;for(let z=0;z<A;z++){let B=r.iget(z),E=b[z];for(let T=0;T<E;T++)w[I++]=B}return D.fromData(w,[S],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i],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 f=Array.from(n);f[i]=c.reduce((A,b)=>A+b,0);let p=f.reduce((A,b)=>A*b,1),l=O(a);if(!l)throw new Error(`Cannot repeat array with dtype ${a}`);let y=new l(p),m=j(f),d=new Array(o).fill(0),g=a==="int64"||a==="uint64",h=[0];for(let A=0;A<u;A++)h.push(h[A]+c[A]);for(let A=0;A<s;A++){let b=r.iget(A),S=d[i],N=c[S],w=0;for(let B=0;B<o;B++)B!==i&&(w+=d[B]*m[B]);let I=m[i],z=h[S];for(let B=0;B<N;B++){let E=w+(z+B)*I;y[E]=b}for(let B=o-1;B>=0&&(d[B]++,!(d[B]<n[B]));B--)d[B]=0}return D.fromData(y,f,a)}function Xe(r,t){let e=r.shape,n=e.length,o=r.dtype,a=r.size,s;if(t===void 0)s=new Set(Array.from({length:n},(l,y)=>y));else if(typeof t=="number"){let l=t<0?n+t:t;if(l<0||l>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);s=new Set([l])}else s=new Set(t.map(l=>{let y=l<0?n+l:l;if(y<0||y>=n)throw new Error(`axis ${l} is out of bounds for array of dimension ${n}`);return y}));let i=O(o);if(!i)throw new Error(`Cannot flip array with dtype ${o}`);let u=new i(a),c=x(o);if(n===1&&r.isCContiguous){let l=r.data,y=r.offset;for(let m=0;m<a;m++)u[m]=l[y+a-1-m];return D.fromData(u,[...e],o)}if(n===2&&r.isCContiguous){let l=e[0],y=e[1],m=r.data,d=r.offset;if(s.size===2){for(let g=0;g<a;g++)u[g]=m[d+a-1-g];return D.fromData(u,[...e],o)}if(s.size===1){if(s.has(0)){for(let g=0;g<l;g++){let h=d+(l-1-g)*y,A=g*y;for(let b=0;b<y;b++)u[A+b]=m[h+b]}return D.fromData(u,[...e],o)}else if(s.has(1)){for(let g=0;g<l;g++){let h=d+g*y,A=g*y;for(let b=0;b<y;b++)u[A+b]=m[h+y-1-b]}return D.fromData(u,[...e],o)}}}let f=new Array(n),p=new Array(n).fill(0);for(let l=0;l<a;l++){for(let d=0;d<n;d++)f[d]=s.has(d)?e[d]-1-p[d]:p[d];let y=r.offset;for(let d=0;d<n;d++)y+=f[d]*r.strides[d];let m=r.data[y];u[l]=m;for(let d=n-1;d>=0&&(p[d]++,!(p[d]<e[d]));d--)p[d]=0}return D.fromData(u,[...e],o)}function Qe(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 s=e[0]<0?o+e[0]:e[0],i=e[1]<0?o+e[1]:e[1];if(s<0||s>=o||i<0||i>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(s===i)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let u=O(a);if(!u)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[s],c[i]]=[c[i],c[s]]);let f=c.reduce((g,h)=>g*h,1),p=new u(f),l=j(c),y=x(a),m=new Array(o).fill(0),d=new Array(o);for(let g=0;g<r.size;g++){for(let N=0;N<o;N++)d[N]=m[N];let h,A;t===1?(h=n[i]-1-m[i],A=m[s]):t===2?(h=n[s]-1-m[s],A=n[i]-1-m[i],d[s]=h,d[i]=A):(h=m[i],A=n[s]-1-m[s]),t!==2&&(d[s]=h,d[i]=A);let b=0;for(let N=0;N<o;N++)b+=d[N]*l[N];let S=r.iget(g);p[b]=S;for(let N=o-1;N>=0&&(m[N]++,!(m[N]<n[N]));N--)m[N]=0}return D.fromData(p,c,a)}function Ke(r,t,e){let n=r.shape,o=n.length,a=r.dtype,s=r.size;if(e===void 0){let m=Array.isArray(t)?t.reduce((b,S)=>b+S,0):t,d=Wr(r),g=O(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let h=new g(s),A=x(a);for(let b=0;b<s;b++){let S=((b-m)%s+s)%s,N=d.iget(S);h[b]=N}return D.fromData(h,[...n],a)}let i=Array.isArray(t)?t:[t],u=Array.isArray(e)?e:[e];if(i.length!==u.length)throw new Error("shift and axis must have the same length");let c=u.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=O(a);if(!f)throw new Error(`Cannot roll array with dtype ${a}`);let p=new f(s),l=x(a),y=new Array(o).fill(0);for(let m=0;m<s;m++){let d=[...y];for(let A=0;A<c.length;A++){let b=c[A],S=n[b],N=i[A];d[b]=((d[b]-N)%S+S)%S}let g=r.offset;for(let A=0;A<o;A++)g+=d[A]*r.strides[A];let h=r.data[g];p[m]=h;for(let A=o-1;A>=0&&(y[A]++,!(y[A]<n[A]));A--)y[A]=0}return D.fromData(p,[...n],a)}function rn(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):Ut(r,o,a)}function tn(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return Dr(r,t,2)}function en(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(e,[e.shape[0],1]):e);return vt(t)}function nn(r,t){let e=r.dtype,n=t.reduce((u,c)=>u*c,1),o=r.size,a=O(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let s=new a(n),i=x(e);for(let u=0;u<n;u++){let c=u%o,f=r.iget(c);s[u]=f}return D.fromData(s,t,e)}function on(r){return r.map(t=>t.ndim===0?G(t,[1]):t)}function an(r){return r.map(t=>t.ndim===0?G(t,[1,1]):t.ndim===1?G(t,[1,t.shape[0]]):t)}function sn(r){return r.map(t=>t.ndim===0?G(t,[1,1,1]):t.ndim===1?G(t,[1,t.shape[0],1]):t.ndim===2?G(t,[t.shape[0],t.shape[1],1]):t)}var Ot=C(()=>{"use strict";W();q()});function bu(r,t,e,n,o,a,s,i,u,c,f,p,l,y){if(p===0)for(let h=0;h<n*o;h++)l[h]=0;else if(p!==1)for(let h=0;h<n*o;h++)l[h]=(l[h]??0)*p;let m=r==="row-major",d=t==="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+=(i[h*u+S]??0)*(c[S*f+A]??0);l[h*y+A]=(l[h*y+A]??0)+s*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+=(i[S*u+h]??0)*(c[S*f+A]??0);l[h*y+A]=(l[h*y+A]??0)+s*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+=(i[h*u+S]??0)*(c[A*f+S]??0);l[h*y+A]=(l[h*y+A]??0)+s*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+=(i[S*u+h]??0)*(c[A*f+S]??0);l[h*y+A]=(l[h*y+A]??0)+s*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+=(i[S*u+h]??0)*(c[A*f+S]??0);l[A*y+h]=(l[A*y+h]??0)+s*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+=(i[h*u+S]??0)*(c[A*f+S]??0);l[A*y+h]=(l[A*y+h]??0)+s*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+=(i[S*u+h]??0)*(c[S*f+A]??0);l[A*y+h]=(l[A*y+h]??0)+s*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+=(i[h*u+S]??0)*(c[S*f+A]??0);l[A*y+h]=(l[A*y+h]??0)+s*b}}function Mt(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 s=k(r.dtype,t.dtype),i=D.zeros([...t.shape],s);for(let u=0;u<t.size;u++){let c=t.data[u+t.offset];typeof o=="bigint"&&typeof c=="bigint"?i.data[u]=o*c:i.data[u]=Number(o)*Number(c)}return i}else{let s=k(r.dtype,t.dtype),i=D.zeros([...r.shape],s);for(let u=0;u<r.size;u++){let c=r.data[u+r.offset];typeof c=="bigint"&&typeof a=="bigint"?i.data[u]=c*a:i.data[u]=Number(c)*Number(a)}return i}}if(e===1&&n===1){if(r.shape[0]!==t.shape[0])throw new Error(`dot: incompatible shapes (${r.shape[0]},) and (${t.shape[0]},)`);let o=r.shape[0],a=0;for(let s=0;s<o;s++){let i=r.get(s),u=t.get(s);typeof i=="bigint"&&typeof u=="bigint"?a=Number(a)+Number(i*u):a+=Number(i)*Number(u)}return a}if(e===2&&n===2)return ir(r,t);if(e===2&&n===1){let[o,a]=r.shape,s=t.shape[0];if(a!==s)throw new Error(`dot: incompatible shapes (${o},${a}) and (${s},)`);let i=k(r.dtype,t.dtype),u=D.zeros([o],i);for(let c=0;c<o;c++){let f=0;for(let p=0;p<a;p++){let l=r.get(c,p),y=t.get(p);typeof l=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(l*y):f+=Number(l)*Number(y)}u.set([c],f)}return u}if(e===1&&n===2){let o=r.shape[0],[a,s]=t.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${s})`);let i=k(r.dtype,t.dtype),u=D.zeros([s],i);for(let c=0;c<s;c++){let f=0;for(let p=0;p<o;p++){let l=r.get(p),y=t.get(p,c);typeof l=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(l*y):f+=Number(l)*Number(y)}u.set([c],f)}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 s=[...r.shape.slice(0,-1)],i=k(r.dtype,t.dtype),u=D.zeros(s,i),c=s.reduce((f,p)=>f*p,1);for(let f=0;f<c;f++){let p=0,l=f,y=[];for(let m=s.length-1;m>=0;m--)y[m]=l%s[m],l=Math.floor(l/s[m]);for(let m=0;m<o;m++){let d=[...y,m],g=r.get(...d),h=t.get(m);typeof g=="bigint"&&typeof h=="bigint"?p=Number(p)+Number(g*h):p+=Number(g)*Number(h)}u.set(y,p)}return u}if(e===1&&n>2){let o=r.shape[0],a=1,s=t.shape[a];if(o!==s)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(t.shape)}`);let i=[...t.shape.slice(0,a),...t.shape.slice(a+1)],u=k(r.dtype,t.dtype),c=D.zeros(i,u),f=i.reduce((p,l)=>p*l,1);for(let p=0;p<f;p++){let l=p,y=[];for(let h=i.length-1;h>=0;h--)y[h]=l%i[h],l=Math.floor(l/i[h]);let m=y.slice(0,a),d=y.slice(a),g=0;for(let h=0;h<o;h++){let A=r.get(h),b=[...m,h,...d],S=t.get(...b);typeof A=="bigint"&&typeof S=="bigint"?g=Number(g)+Number(A*S):g+=Number(A)*Number(S)}c.set(y,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 s=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],i=k(r.dtype,t.dtype),u=D.zeros(s,i),c=r.shape.slice(0,-1).reduce((y,m)=>y*m,1),f=t.shape.slice(0,-2).reduce((y,m)=>y*m,1),p=t.shape[n-1],l=o;for(let y=0;y<c;y++)for(let m=0;m<f;m++)for(let d=0;d<p;d++){let g=0;for(let A=0;A<l;A++){let b=y*l+A,S=r.data[b+r.offset],N=m*l*p+A*p+d,w=t.data[N+t.offset];typeof S=="bigint"&&typeof w=="bigint"?g=Number(g)+Number(S*w):g+=Number(S)*Number(w)}let h=y*f*p+m*p+d;u.data[h]=g}return u}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function ir(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 s=k(r.dtype,t.dtype),i=s.startsWith("int")||s.startsWith("uint")||s==="bool"?"float64":s;if(i!=="float64")throw new Error(`matmul currently only supports float64, got ${i}`);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[f=0,p=0]=r.strides,[l=0,y=0]=t.strides,m=p>f,d=y>l,g=m?"transpose":"no-transpose",h=d?"transpose":"no-transpose",A,b;m?A=p:A=f,d?b=y:b=l;let S=D.zeros([e,a],"float64");return bu("row-major",g,h,e,a,n,1,u,A,c,b,0,S.data,a),S}function fn(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 s=r.get(a,a);typeof s=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+s:o=(typeof o=="bigint"?Number(o):o)+s}return o}function cn(r,t){return Sr(r,t)}function ln(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 Mt(r,t);let s=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],i=k(r.dtype,t.dtype),u=D.zeros(s,i),c=e===1?1:r.shape.slice(0,-1).reduce((l,y)=>l*y,1),f=n===1?1:t.shape.slice(0,-1).reduce((l,y)=>l*y,1),p=o;for(let l=0;l<c;l++)for(let y=0;y<f;y++){let m=0;for(let g=0;g<p;g++){let h=e===1?g:l*p+g,A=n===1?g:y*p+g,b=r.data[h+r.offset],S=t.data[A+t.offset];typeof b=="bigint"&&typeof S=="bigint"?m=Number(m)+Number(b*S):m+=Number(b)*Number(S)}if(s.length===0)return m;let d=c===1?y:l*f+y;u.data[d]=m}return u}function Ct(r,t){let e=r.ndim===1?r:br(r),n=t.ndim===1?t:br(t),o=e.size,a=n.size,s=k(r.dtype,t.dtype),i=D.zeros([o,a],s);for(let u=0;u<o;u++)for(let c=0;c<a;c++){let f=e.get(u),p=n.get(c),l;typeof f=="bigint"&&typeof p=="bigint"?l=f*p:l=Number(f)*Number(p),i.set([u,c],l)}return i}function pn(r,t,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>r.ndim||l>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:l},(y,m)=>r.ndim-l+m),o=Array.from({length:l},(y,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 y=n[l],m=o[l];if(y<0||y>=r.ndim||m<0||m>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[y]!==t.shape[m])throw new Error(`tensordot: shape mismatch on axes ${y} and ${m}: ${r.shape[y]} != ${t.shape[m]}`)}let a=[],s=[];for(let l=0;l<r.ndim;l++)n.includes(l)||a.push(l);for(let l=0;l<t.ndim;l++)o.includes(l)||s.push(l);let i=[...a.map(l=>r.shape[l]),...s.map(l=>t.shape[l])];if(i.length===0){let l=0,y=n.map(m=>r.shape[m]).reduce((m,d)=>m*d,1);for(let m=0;m<y;m++){let d=m,g=new Array(n.length);for(let N=n.length-1;N>=0;N--){let w=n[N];g[N]=d%r.shape[w],d=Math.floor(d/r.shape[w])}let h=new Array(r.ndim),A=new Array(t.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=r.get(...h),S=t.get(...A);typeof b=="bigint"&&typeof S=="bigint"?l=Number(l)+Number(b*S):l+=Number(b)*Number(S)}return l}let u=k(r.dtype,t.dtype),c=D.zeros(i,u),f=i.reduce((l,y)=>l*y,1),p=n.map(l=>r.shape[l]).reduce((l,y)=>l*y,1);for(let l=0;l<f;l++){let y=l,m=[];for(let A=i.length-1;A>=0;A--)m[A]=y%i[A],y=Math.floor(y/i[A]);let d=m.slice(0,a.length),g=m.slice(a.length),h=0;for(let A=0;A<p;A++){y=A;let b=[];for(let z=n.length-1;z>=0;z--){let B=n[z];b[z]=y%r.shape[B],y=Math.floor(y/r.shape[B])}let S=new Array(r.ndim),N=new Array(t.ndim);for(let z=0;z<a.length;z++)S[a[z]]=d[z];for(let z=0;z<s.length;z++)N[s[z]]=g[z];for(let z=0;z<n.length;z++)S[n[z]]=b[z],N[o[z]]=b[z];let w=r.get(...S),I=t.get(...N);typeof w=="bigint"&&typeof I=="bigint"?h=Number(h)+Number(w*I):h+=Number(w)*Number(I)}c.set(m,h)}return c}function yn(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 s=e<0?a+e:e,i=n<0?a+n:n;if(s<0||s>=a||i<0||i>=a)throw new Error("axis out of bounds");if(s===i)throw new Error("axis1 and axis2 cannot be the same");let u=o[s],c=o[i],f;t>=0?f=Math.max(0,Math.min(u,c-t)):f=Math.max(0,Math.min(u+t,c));let p=[];for(let d=0;d<a;d++)d!==s&&d!==i&&p.push(o[d]);p.push(f);let l=D.zeros(p,r.dtype),y=o.filter((d,g)=>g!==s&&g!==i),m=y.reduce((d,g)=>d*g,1);for(let d=0;d<m;d++){let g=d,h=[];for(let A=y.length-1;A>=0;A--)h.unshift(g%y[A]),g=Math.floor(g/y[A]);for(let A=0;A<f;A++){let b=new Array(a),S=0;for(let I=0;I<a;I++)I===s?b[I]=t>=0?A:A-t:I===i?b[I]=t>=0?A+t:A:b[I]=h[S++];let N=[...h,A],w=r.get(...b);l.set(N,w)}}return l}function mn(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=Su(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 s=new Map;for(let d=0;d<t.length;d++){let g=a[d],h=t[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(s.has(b)){if(s.get(b)!==S)throw new Error(`einsum: size mismatch for index '${b}': ${s.get(b)} vs ${S}`)}else s.set(b,S)}}for(let d of o)if(!s.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let i=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)i.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,g]=a,[h,A]=t;if(d.length===2&&g.length===2&&o.length===2&&h.ndim===2&&A.ndim===2){let[b,S]=[d[0],d[1]],[N,w]=[g[0],g[1]],[I,z]=[o[0],o[1]];if(b===I&&w===z&&S===N&&c.length===1&&c[0]===S||b===I&&w===z&&S===N&&c.length===1&&c[0]===S)return ir(h,A);if(S===I&&w===z&&b===N&&c.length===1&&c[0]===b){let B=cn(h);return ir(B,A)}if(b===I&&N===z&&S===w&&c.length===1&&c[0]===S){let B=cn(A);return ir(h,B)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&h.ndim===1&&A.ndim===1)return $t(t,a,c,s);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 Ct(h,A)}if(t.length===1&&a[0].length===2&&o.length===0){let d=a[0];if(d[0]===d[1]&&t[0].ndim===2)return $t(t,a,c,s)}let f=Array.from(o).map(d=>s.get(d));if(f.length===0)return $t(t,a,c,s);let p=t[0].dtype;for(let d=1;d<t.length;d++)p=k(p,t[d].dtype);let l=D.zeros(f,p),y=f.reduce((d,g)=>d*g,1),m=1;for(let d of c)m*=s.get(d);for(let d=0;d<y;d++){let g=Du(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 w=c.length-1;w>=0;w--){let I=c[w],z=s.get(I);h.set(I,S%z),S=Math.floor(S/z)}let N=1;for(let w=0;w<t.length;w++){let I=t[w],z=a[w],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 Su(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 $t(r,t,e,n){let o=1;for(let s of e)o*=n.get(s);let a=0;for(let s=0;s<o;s++){let i=new Map,u=s;for(let f=e.length-1;f>=0;f--){let p=e[f],l=n.get(p);i.set(p,u%l),u=Math.floor(u/l)}let c=1;for(let f=0;f<r.length;f++){let p=r[f],l=t[f],y=[];for(let d of l)y.push(i.get(d));let m=p.get(...y);c*=Number(m)}a+=c}return a}function Du(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 dn(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,s=k(r.dtype,t.dtype),i=Math.max(o,a),u=new Array(i),c=new Array(i).fill(1),f=new Array(i).fill(1);for(let m=0;m<o;m++)c[i-o+m]=e[m];for(let m=0;m<a;m++)f[i-a+m]=n[m];for(let m=0;m<i;m++)u[m]=c[m]*f[m];let p=D.zeros(u,s),l=e.reduce((m,d)=>m*d,1),y=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(i).fill(0);for(let b=0;b<o;b++)h[i-o+b]=g[b];let A=r.get(...g);for(let b=0;b<y;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 w=new Array(i).fill(0);for(let E=0;E<a;E++)w[i-a+E]=N[E];let I=t.get(...N),z=new Array(i);for(let E=0;E<i;E++)z[E]=h[E]*f[E]+w[E];let B=typeof A=="bigint"||typeof I=="bigint"?BigInt(Number(A))*BigInt(Number(I)):Number(A)*Number(I);p.set(z,B)}}return p}var gn=C(()=>{"use strict";W();q();Ot()});function An(r){return F(r,Math.sqrt,!1)}function hn(r,t){return typeof t=="number"?Nu(r,t):L(r,t,Math.pow,"power")}function Nu(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),f=c.data;if(x(e))if(x(u)&&Number.isInteger(t)&&t>=0){let p=o,l=f;for(let y=0;y<a;y++)l[y]=p[y]**BigInt(t)}else for(let p=0;p<a;p++)f[p]=Math.pow(Number(o[p]),t);else for(let p=0;p<a;p++)f[p]=Math.pow(Number(o[p]),t);return c}var bn=C(()=>{"use strict";W();ar();q()});function Sn(r){return F(r,Math.sin,!1)}function Dn(r){return F(r,Math.cos,!1)}function xn(r){return F(r,Math.tan,!1)}function Nn(r){return F(r,Math.asin,!1)}function wn(r){return F(r,Math.acos,!1)}function In(r){return F(r,Math.atan,!1)}function zn(r,t){return typeof t=="number"?zu(r,t):Iu(r,t)}function Iu(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,s=o==="float32"&&a==="float32"?"float32":"float64",i=D.zeros(e,s),u=i.data;for(let c=0;c<n;c++){let f=(x(o),Number(r.data[c])),p=(x(a),Number(t.data[c]));u[c]=Math.atan2(f,p)}return i}function zu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e==="float32"?"float32":"float64",i=D.zeros(n,s),u=i.data;if(x(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 i}function _n(r,t){return typeof t=="number"?Bu(r,t):_u(r,t)}function _u(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,s=o==="float32"&&a==="float32"?"float32":"float64",i=D.zeros(e,s),u=i.data;for(let c=0;c<n;c++){let f=(x(o),Number(r.data[c])),p=(x(a),Number(t.data[c]));u[c]=Math.hypot(f,p)}return i}function Bu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e==="float32"?"float32":"float64",i=D.zeros(n,s),u=i.data;if(x(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 i}function Bn(r){let t=180/Math.PI;return F(r,e=>e*t,!1)}function En(r){let t=Math.PI/180;return F(r,e=>e*t,!1)}var Tn=C(()=>{"use strict";W();ar();q()});function Un(r){return F(r,Math.sinh,!1)}function vn(r){return F(r,Math.cosh,!1)}function On(r){return F(r,Math.tanh,!1)}function $n(r){return F(r,Math.asinh,!1)}function Mn(r){return F(r,Math.acosh,!1)}function Cn(r){return F(r,Math.atanh,!1)}var kn=C(()=>{"use strict";ar()});function kt(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=nr([Array.from(e),t]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);for(let s=0;s<o;s++)if(a[s]!==t[s])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);return J(r,t)}function Pn(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=nr(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 Vn(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let m=r.size;for(let A of t){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=t.length,g=O(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=t[A];b<0&&(b=m+b);let S=r.iget(b);x(a),h[A]=S}return D.fromData(h,[d],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];for(let m of t){let d=m<0?i+m:m;if(d<0||d>=i)throw new Error(`index ${m} is out of bounds for axis ${s} with size ${i}`)}let u=Array.from(n);u[s]=t.length;let c=u.reduce((m,d)=>m*d,1),f=O(a);if(!f)throw new Error(`Cannot take from array with dtype ${a}`);let p=new f(c),l=j(u),y=new Array(o).fill(0);for(let m=0;m<c;m++){let d=[...y],g=y[s],h=t[g];h<0&&(h=i+h),d[s]=h;let A=r.get(...d),b=0;for(let S=0;S<o;S++)b+=y[S]*l[S];x(a),p[b]=A;for(let S=o-1;S>=0&&(y[S]++,!(y[S]<u[S]));S--)y[S]=0}return D.fromData(p,u,a)}function Fn(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 s=0;s<e.size;s++)a.push(e.iget(s));if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let s=[...a];a=[];for(let i=0;i<t.length;i++)a.push(s[i%s.length])}}for(let s=0;s<t.length;s++){let i=t[s];if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`index ${t[s]} is out of bounds for axis 0 with size ${n}`);let u=a[s];x(o)?typeof u!="bigint"&&(u=BigInt(Math.round(Number(u)))):typeof u=="bigint"&&(u=Number(u)),r.iset(i,u)}}function Rn(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(l=>Array.from(l.shape));a.unshift(Array.from(e));let s=nr(a);if(s===null)throw new Error("operands could not be broadcast together");let i=J(r,s),u=t.map(l=>J(l,s)),c=s.reduce((l,y)=>l*y,1),f=O(o);if(!f)throw new Error(`Cannot choose with dtype ${o}`);let p=new f(c);for(let l=0;l<c;l++){let y=Number(i.iget(l));if(y<0||y>=n)throw new Error(`index ${y} is out of bounds for axis 0 with size ${n}`);let m=u[y].iget(l);x(o),p[l]=m}return D.fromData(p,s,o)}function Ln(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),s=t.iget(o);if(e){let i=typeof a=="number"&&Number.isNaN(a),u=typeof s=="number"&&Number.isNaN(s);if(i&&u)continue}if(a!==s)return!1}return!0}function qn(r,t,e){let n=r.shape,o=n.length,a=r.dtype,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=t.shape;if(i.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${i.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==s&&i[d]!==n[d]&&i[d]!==1&&n[d]!==1)throw new Error(`index ${i[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let u=Array.from(i),c=u.reduce((d,g)=>d*g,1),f=O(a);if(!f)throw new Error(`Cannot take_along_axis with dtype ${a}`);let p=new f(c),l=j(n),y=j(i),m=n[s];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%u[I],h=Math.floor(h/u[I]);let A=0;for(let I=0;I<o;I++){let z=i[I]===1?0:g[I];A+=z*y[I]}let b=Number(t.iget(A));if(b<0&&(b=m+b),b<0||b>=m)throw new Error(`index ${b} is out of bounds for axis ${s} with size ${m}`);let S=[...g];S[s]=b;let N=0;for(let I=0;I<o;I++){let z=n[I]===1?0:S[I];N+=z*l[I]}let w=r.iget(N);x(a),p[d]=w}return D.fromData(p,u,a)}function jn(r,t,e,n){let o=r.shape,a=o.length,s=r.dtype,i=n<0?a+n:n;if(i<0||i>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let u=t.shape,c=e.shape;if(u.length!==a||c.length!==a)throw new Error("indices, arr, and values must have same ndim");let f=o[i],p=j(o),l=j(u),y=j(c),m=u.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%u[z],h=Math.floor(h/u[z]);let A=0;for(let z=0;z<a;z++)A+=g[z]*l[z];let b=Number(t.iget(A));if(b<0&&(b=f+b),b<0||b>=f)throw new Error(`index ${b} is out of bounds for axis ${i} with size ${f}`);let S=0;for(let z=0;z<a;z++){let B=c[z]===1?0:g[z];S+=B*y[z]}let N=e.iget(S),w=[...g];w[i]=b;let I=0;for(let z=0;z<a;z++)I+=w[z]*p[z];x(s)?typeof N!="bigint"&&(N=BigInt(Math.round(Number(N)))):typeof N=="bigint"&&(N=Number(N)),r.iset(I,N)}}function Wn(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i))}let s=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[s%a.length];x(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),s++}}function Zn(r,t,e){let n=t.shape,o=n.length,a=t.dtype,s=t.data,i=x(a);if(e===void 0){let A=0,b=Math.min(r.size,t.size);for(let I=0;I<b;I++)r.iget(I)&&A++;let S=O(a);if(!S)throw new Error(`Cannot compress with dtype ${a}`);let N=new S(A),w=0;for(let I=0;I<b;I++)r.iget(I)&&(N[w]=s[I],w++);return D.fromData(N,[A],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 c=n[u],f=Math.min(r.size,c),p=[];for(let A=0;A<f;A++)r.iget(A)&&p.push(A);let l=p.length,y=[...n];y[u]=l;let m=y.reduce((A,b)=>A*b,1),d=O(a);if(!d)throw new Error(`Cannot compress with dtype ${a}`);let g=new d(m),h=j(n);if(u===0){let A=h[0],b=n.slice(1).reduce((N,w)=>N*w,1),S=0;for(let N=0;N<l;N++){let I=p[N]*A;if(i){let z=s,B=g;for(let E=0;E<b;E++)B[S++]=z[I+E]}else{let z=s,B=g;for(let E=0;E<b;E++)B[S++]=z[I+E]}}}else{let A=n.slice(0,u).reduce((N,w)=>N*w,1),b=n.slice(u+1).reduce((N,w)=>N*w,1),S=0;for(let N=0;N<A;N++)for(let w=0;w<l;w++){let I=p[w],z=0,B=N;for(let E=u-1;E>=0;E--){let T=B%n[E];B=Math.floor(B/n[E]),z+=T*h[E]}if(z+=I*h[u],i){let E=s,T=g;for(let $=0;$<b;$++)T[S++]=E[z+$]}else{let E=s,T=g;for(let $=0;$<b;$++)T[S++]=E[z+$]}}}return D.fromData(g,y,a)}function Gn(r,t,e=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");let n=[...r.map(l=>Array.from(l.shape)),...t.map(l=>Array.from(l.shape))],o=nr(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,s=o.reduce((l,y)=>l*y,1),i=O(a);if(!i)throw new Error(`Cannot select with dtype ${a}`);let u=e;x(a)?u=typeof e=="bigint"?e:BigInt(e):u=typeof e=="bigint"?Number(e):e;let c=new i(s);for(let l=0;l<s;l++)x(a),c[l]=u;let f=r.map(l=>J(l,o)),p=t.map(l=>J(l,o));for(let l=0;l<s;l++)for(let y=0;y<r.length;y++)if(f[y].iget(l)){let m=p[y].iget(l);x(a),c[l]=m;break}return D.fromData(c,o,a)}function Hn(r,t,e){let n=r.size,o=r.dtype,a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i));if(a.length===0)return;let s=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[s%a.length];x(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),s++}}function Pt(r,t=2){if(t<1)throw new Error("ndim must be at least 1");let e=new Int32Array(r);for(let o=0;o<r;o++)e[o]=o;let n=[];for(let o=0;o<t;o++)n.push(D.fromData(new Int32Array(e),[r],"int32"));return n}function Yn(r){let t=r.shape,e=t.length;if(e<2)throw new Error("array must be at least 2-D");let n=t[0];for(let o=1;o<e;o++)if(t[o]!==n)throw new Error("All dimensions of input must be equal");return Pt(n,e)}function Vt(r,t=0,e){let n=e??r,o=[],a=[];for(let s=0;s<r;s++)for(let i=0;i<=Math.min(s+t,n-1);i++)i>=0&&(o.push(s),a.push(i));return[D.fromData(new Int32Array(o),[o.length],"int32"),D.fromData(new Int32Array(a),[a.length],"int32")]}function Jn(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return Vt(e[0],t,e[1])}function Ft(r,t=0,e){let n=e??r,o=[],a=[];for(let s=0;s<r;s++)for(let i=Math.max(s+t,0);i<n;i++)o.push(s),a.push(i);return[D.fromData(new Int32Array(o),[o.length],"int32"),D.fromData(new Int32Array(a),[a.length],"int32")]}function Xn(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return Ft(e[0],t,e[1])}function Qn(r,t,e=0){let n=t(r,e),o=n.shape;if(o.length!==2||o[0]!==r||o[1]!==r)throw new Error("mask_func must return n x n array");let a=[],s=[];for(let i=0;i<r;i++)for(let u=0;u<r;u++)n.get(i,u)&&(a.push(i),s.push(u));return[D.fromData(new Int32Array(a),[a.length],"int32"),D.fromData(new Int32Array(s),[s.length],"int32")]}function Kn(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((u,c)=>u*c,1),a=O(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let s=new a(o),i=r.reduce((u,c)=>u*c,1);for(let u=0;u<e;u++){let c=u*i;for(let f=0;f<i;f++){let p=new Array(e),l=f;for(let m=e-1;m>=0;m--)p[m]=l%r[m],l=Math.floor(l/r[m]);let y=p[u];t==="int64"?s[c+f]=BigInt(y):s[c+f]=y}}return D.fromData(s,n,t)}function ro(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,s=o.dtype,i=new Array(t).fill(1);i[n]=a;let u=O(s);if(!u)throw new Error(`Cannot create ix_ with dtype ${s}`);let c=new u(a);for(let f=0;f<a;f++){let p=o.iget(f);x(s),c[f]=p}e.push(D.fromData(c,i,s))}return e}function to(r,t,e="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");let n=r[0].size,o=t.length,a=new Int32Array(n),s=new Array(o),i=1;for(let u=o-1;u>=0;u--)s[u]=i,i*=t[u];for(let u=0;u<n;u++){let c=0;for(let f=0;f<o;f++){let p=Number(r[f].iget(u)),l=t[f];if(e==="wrap")p=(p%l+l)%l;else if(e==="clip")p=Math.max(0,Math.min(p,l-1));else if(p<0||p>=l)throw new Error(`index ${p} is out of bounds for axis ${f} with size ${l}`);c+=p*s[f]}a[u]=c}return D.fromData(a,[n],"int32")}function eo(r,t,e="C"){let n=t.length,o,a;if(typeof r=="number")o=[r],a=[];else{o=[];for(let f=0;f<r.size;f++)o.push(Number(r.iget(f)));a=Array.from(r.shape)}let s=o.length,i=t.reduce((f,p)=>f*p,1),u=new Array(n);if(e==="C"){let f=1;for(let p=n-1;p>=0;p--)u[p]=f,f*=t[p]}else{let f=1;for(let p=0;p<n;p++)u[p]=f,f*=t[p]}let c=[];for(let f=0;f<n;f++){let p=new Int32Array(s);c.push(D.fromData(p,a.length?a:[1],"int32"))}for(let f=0;f<s;f++){let p=o[f];if(p<0||p>=i)throw new Error(`index ${p} is out of bounds for array with size ${i}`);if(e==="C")for(let l=0;l<n;l++){let y=Math.floor(p/u[l]);p=p%u[l],c[l].data[f]=y%t[l]}else for(let l=n-1;l>=0;l--){let y=Math.floor(p/u[l]);p=p%u[l],c[l].data[f]=y%t[l]}}return typeof r=="number"?c.map(f=>{let p=f.iget(0);return D.fromData(new Int32Array([Number(p)]),[],"int32")}):c}var no=C(()=>{"use strict";W();q();mt()});function Y(r,t){if(!le(r)&&r!=="bool")throw new TypeError(`ufunc '${t}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function xr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function so(r,t){return Y(r.dtype,"bitwise_and"),typeof t=="number"?Ou(r,t):(Y(t.dtype,"bitwise_and"),xr(r,t)?vu(r,t):L(r,t,(e,n)=>e&n,"bitwise_and"))}function vu(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p&l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]&p[l]}}else for(let u=0;u<o;u++)i[u]=a[u]&s[u];return n}function Ou(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]&f}else for(let u=0;u<a;u++)i[u]=o[u]&t;return s}function io(r,t){return Y(r.dtype,"bitwise_or"),typeof t=="number"?Mu(r,t):(Y(t.dtype,"bitwise_or"),xr(r,t)?$u(r,t):L(r,t,(e,n)=>e|n,"bitwise_or"))}function $u(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p|l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]|p[l]}}else for(let u=0;u<o;u++)i[u]=a[u]|s[u];return n}function Mu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]|f}else for(let u=0;u<a;u++)i[u]=o[u]|t;return s}function uo(r,t){return Y(r.dtype,"bitwise_xor"),typeof t=="number"?ku(r,t):(Y(t.dtype,"bitwise_xor"),xr(r,t)?Cu(r,t):L(r,t,(e,n)=>e^n,"bitwise_xor"))}function Cu(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p^l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]^p[l]}}else for(let u=0;u<o;u++)i[u]=a[u]^s[u];return n}function ku(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]^f}else for(let u=0;u<a;u++)i[u]=o[u]^t;return s}function Rt(r){Y(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++)u[c]=~i[c]}else for(let i=0;i<o;i++)s[i]=~n[i];return a}function co(r){return Rt(r)}function fo(r,t){if(Y(r.dtype,"left_shift"),typeof t=="number")return oo(r,t);if(Y(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=x(t.dtype)?Number(t.data[0]):t.data[0];return oo(r,e)}return xr(r,t)?Pu(r,t):L(r,t,(e,n)=>e<<n,"left_shift")}function Pu(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),p=typeof s[c]=="bigint"?s[c]:BigInt(Math.round(Number(s[c])));u[c]=f<<p}}else for(let u=0;u<o;u++)i[u]=a[u]<<s[u];return n}function oo(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]<<f}else for(let u=0;u<a;u++)i[u]=o[u]<<t;return s}function lo(r,t){if(Y(r.dtype,"right_shift"),typeof t=="number")return ao(r,t);if(Y(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=x(t.dtype)?Number(t.data[0]):t.data[0];return ao(r,e)}return xr(r,t)?Vu(r,t):L(r,t,(e,n)=>e>>n,"right_shift")}function Vu(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),p=typeof s[c]=="bigint"?s[c]:BigInt(Math.round(Number(s[c])));u[c]=f>>p}}else for(let u=0;u<o;u++)i[u]=a[u]>>s[u];return n}function ao(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]>>f}else for(let u=0;u<a;u++)i[u]=o[u]>>t;return s}function po(r,t=-1,e="big"){let n=Array.from(r.shape),o=n.length;if(t<0&&(t=o+t),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=n[t],s=Math.ceil(a/8),i=[...n];i[t]=s;let u=D.zeros(i,"uint8"),c=u.data;if(o===1){for(let g=0;g<s;g++){let h=0;for(let A=0;A<8;A++){let b=g*8+A;if(b<a){let S=Number(r.data[b])!==0?1:0;e==="big"?h|=S<<7-A:h|=S<<A}}c[g]=h}return u}let f=n.slice(0,t),p=n.slice(t+1),l=f.reduce((g,h)=>g*h,1),y=p.reduce((g,h)=>g*h,1),m=Zr(n),d=Zr(i);for(let g=0;g<l;g++)for(let h=0;h<y;h++)for(let A=0;A<s;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 M=0;M<t;M++){let R=M<t-1?f.slice(M+1).reduce((st,it)=>st*it,1):1,H=Math.floor(E/R);E%=R,B+=H*m[M]}B+=z*m[t];let T=h;for(let M=t+1;M<o;M++){let R=M<o-1?p.slice(M-t).reduce((st,it)=>st*it,1):1,H=Math.floor(T/R);T%=R,B+=H*m[M]}let $=Number(r.data[B])!==0?1:0;e==="big"?b|=$<<7-I:b|=$<<I}}let S=0,N=g;for(let I=0;I<t;I++){let z=I<t-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[t];let w=h;for(let I=t+1;I<o;I++){let z=I<o-1?p.slice(I-t).reduce((E,T)=>E*T,1):1,B=Math.floor(w/z);w%=z,S+=B*d[I]}c[S]=b}return u}function yo(r,t=-1,e=-1,n="big"){if(r.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");let o=Array.from(r.shape),a=o.length;if(t<0&&(t=a+t),t<0||t>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let s=o[t],i=s*8;e>=0&&(i=e);let u=[...o];u[t]=i;let c=D.zeros(u,"uint8"),f=c.data;if(a===1){for(let h=0;h<s;h++){let A=Number(r.data[h]);for(let b=0;b<8;b++){let S=h*8+b;if(S>=i)break;n==="big"?f[S]=A>>7-b&1:f[S]=A>>b&1}}return c}let p=o.slice(0,t),l=o.slice(t+1),y=p.reduce((h,A)=>h*A,1),m=l.reduce((h,A)=>h*A,1),d=Zr(o),g=Zr(u);for(let h=0;h<y;h++)for(let A=0;A<m;A++)for(let b=0;b<s;b++){let S=0,N=h;for(let z=0;z<t;z++){let B=z<t-1?p.slice(z+1).reduce((T,$)=>T*$,1):1,E=Math.floor(N/B);N%=B,S+=E*d[z]}S+=b*d[t];let w=A;for(let z=t+1;z<a;z++){let B=z<a-1?l.slice(z-t).reduce((T,$)=>T*$,1):1,E=Math.floor(w/B);w%=B,S+=E*d[z]}let I=Number(r.data[S]);for(let z=0;z<8;z++){let B=b*8+z;if(B>=i)break;let E=0;N=h;for(let T=0;T<t;T++){let $=T<t-1?p.slice(T+1).reduce((R,H)=>R*H,1):1,M=Math.floor(N/$);N%=$,E+=M*g[T]}E+=B*g[t],w=A;for(let T=t+1;T<a;T++){let $=T<a-1?l.slice(T-t).reduce((R,H)=>R*H,1):1,M=Math.floor(w/$);w%=$,E+=M*g[T]}n==="big"?f[E]=I>>7-z&1:f[E]=I>>z&1}}return c}function Zr(r){let t=r.length,e=new Array(t),n=1;for(let o=t-1;o>=0;o--)e[o]=n,n*=r[o];return e}var mo=C(()=>{"use strict";W();q();ar()});function Lt(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return r.copy();let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=r.copy(),u=i.data,c=e[s],f=Array.from(e).filter((l,y)=>y!==s),p=f.length===0?1:f.reduce((l,y)=>l*y,1);if(x(o)){let l=a,y=u;for(let m=0;m<p;m++){let d=[];for(let g=0;g<c;g++){let h=v(m,s,g,e),A=U(h,e);d.push({value:l[A],idx:g})}d.sort((g,h)=>g.value<h.value?-1:g.value>h.value?1:0);for(let g=0;g<c;g++){let h=v(m,s,g,e),A=U(h,e);y[A]=d[g].value}}}else for(let l=0;l<p;l++){let y=[];for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);y.push(Number(a[g]))}y.sort((m,d)=>isNaN(m)&&isNaN(d)?0:isNaN(m)?1:isNaN(d)?-1:m-d);for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);u[g]=y[m]}}return i}function qt(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return D.zeros([0],"int32");let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=D.zeros(Array.from(e),"int32"),u=i.data,c=e[s],f=Array.from(e).filter((l,y)=>y!==s),p=f.length===0?1:f.reduce((l,y)=>l*y,1);if(x(o)){let l=a;for(let y=0;y<p;y++){let m=[];for(let d=0;d<c;d++){let g=v(y,s,d,e),h=U(g,e);m.push({value:l[h],idx:d})}m.sort((d,g)=>d.value<g.value?-1:d.value>g.value?1:0);for(let d=0;d<c;d++){let g=v(y,s,d,e),h=U(g,e);u[h]=m[d].idx}}}else for(let l=0;l<p;l++){let y=[];for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);y.push({value:Number(a[g]),idx:m})}y.sort((m,d)=>isNaN(m.value)&&isNaN(d.value)?0:isNaN(m.value)?1:isNaN(d.value)?-1:m.value-d.value);for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);u[g]=y[m].idx}}return i}function go(r){if(r.length===0)return D.zeros([0],"int32");let e=r[0].size;for(let s of r){if(s.ndim!==1)throw new Error("keys must be 1D arrays");if(s.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let s=0;s<e;s++)n.push(s);n.sort((s,i)=>{for(let u=r.length-1;u>=0;u--){let f=r[u].data,p=Number(f[s]),l=Number(f[i]);if(!(isNaN(p)&&isNaN(l))){if(isNaN(p))return 1;if(isNaN(l)||p<l)return-1;if(p>l)return 1}}return 0});let o=D.zeros([e],"int32"),a=o.data;for(let s=0;s<e;s++)a[s]=n[s];return o}function Ru(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],s=r[o],i=r[n],u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u];[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++){let l=r[p],y=isNaN(l),m=isNaN(c);!y&&(m||l<=c)&&([r[f],r[p]]=[r[p],r[f]],f++)}if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function Lu(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],s=r[o],i=r[n],u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u];[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++)r[p]<=c&&([r[f],r[p]]=[r[p],r[f]],f++);if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function qu(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,s=r[o].value,i=r[n].value,u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u].value;[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++){let l=r[p].value,y=isNaN(l),m=isNaN(c);!y&&(m||l<=c)&&([r[f],r[p]]=[r[p],r[f]],f++)}if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function ju(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,s=r[o].value,i=r[n].value,u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u].value;[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++)r[p].value<=c&&([r[f],r[p]]=[r[p],r[f]],f++);if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function jt(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype;if(o===0)return r.copy();let s=e;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[s],u=t;if(u<0&&(u=i+u),u<0||u>=i)throw new Error(`kth(=${t}) out of bounds (${i})`);let c=r.copy(),f=c.data,p=Array.from(n).filter((y,m)=>m!==s),l=p.length===0?1:p.reduce((y,m)=>y*m,1);if(x(a)){let y=f;for(let m=0;m<l;m++){let d=[];for(let g=0;g<i;g++){let h=v(m,s,g,n),A=U(h,n);d.push(y[A])}Lu(d,u);for(let g=0;g<i;g++){let h=v(m,s,g,n),A=U(h,n);y[A]=d[g]}}}else for(let y=0;y<l;y++){let m=[];for(let d=0;d<i;d++){let g=v(y,s,d,n),h=U(g,n);m.push(Number(f[h]))}Ru(m,u);for(let d=0;d<i;d++){let g=v(y,s,d,n),h=U(g,n);f[h]=m[d]}}return c}function Wt(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,s=r.data;if(o===0)return D.zeros([0],"int32");let i=e;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i],c=t;if(c<0&&(c=u+c),c<0||c>=u)throw new Error(`kth(=${t}) out of bounds (${u})`);let f=D.zeros(Array.from(n),"int32"),p=f.data,l=Array.from(n).filter((m,d)=>d!==i),y=l.length===0?1:l.reduce((m,d)=>m*d,1);if(x(a)){let m=s;for(let d=0;d<y;d++){let g=[];for(let h=0;h<u;h++){let A=v(d,i,h,n),b=U(A,n);g.push({value:m[b],idx:h})}ju(g,c);for(let h=0;h<u;h++){let A=v(d,i,h,n),b=U(A,n);p[b]=g[h].idx}}}else for(let m=0;m<y;m++){let d=[];for(let g=0;g<u;g++){let h=v(m,i,g,n),A=U(h,n);d.push({value:Number(s[A]),idx:g})}qu(d,c);for(let g=0;g<u;g++){let h=v(m,i,g,n),A=U(h,n);p[A]=d[g].idx}}return f}function Ao(r){let t=r.dtype,e=r.size,n=r.data,o=[];for(let i=0;i<e;i++)o.push(Number(n[i]));o.sort((i,u)=>isNaN(i)&&isNaN(u)?0:isNaN(i)?1:isNaN(u)?-1:i-u);let a=D.zeros([e],t),s=a.data;for(let i=0;i<e;i++)s[i]=o[i];return a}function Gr(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=[];for(let f=0;f<e;f++)a.push([]);let s=[],i=1;for(let f=e-1;f>=0;f--)s.unshift(i),i*=t[f];for(let f=0;f<o;f++)if(n[f]){let p=f;for(let l=0;l<e;l++){let y=Math.floor(p/s[l]);p=p%s[l],a[l].push(y)}}let u=a[0]?.length??0,c=[];for(let f=0;f<e;f++){let p=D.zeros([u],"int32"),l=p.data;for(let y=0;y<u;y++)l[y]=a[f][y];c.push(p)}return c}function ho(r){let t=r.data,e=r.size,n=[];for(let s=0;s<e;s++)t[s]&&n.push(s);let o=D.zeros([n.length],"int32"),a=o.data;for(let s=0;s<n.length;s++)a[s]=n[s];return o}function bo(r,t,e){if(t===void 0&&e===void 0)return Gr(r);if(t===void 0||e===void 0)throw new Error("either both or neither of x and y should be given");let n=r.shape,o=t.shape,a=e.shape,s=Math.max(n.length,o.length,a.length),i=B=>{let E=Array(s).fill(1);for(let T=0;T<B.length;T++)E[s-B.length+T]=B[T];return E},u=i(n),c=i(o),f=i(a),p=[];for(let B=0;B<s;B++){let E=[u[B],c[B],f[B]],T=Math.max(...E);for(let $ of E)if($!==1&&$!==T)throw new Error("operands could not be broadcast together");p.push(T)}let l=t.dtype,y=D.zeros(p,l),m=y.data,d=r.data,g=t.data,h=e.data,A=(B,E)=>{let T=[],$=1;for(let M=B.length-1;M>=0;M--)T.unshift($),$*=B[M];for(;T.length<E.length;)T.unshift(0);for(let M=0;M<E.length;M++)E[M]===1&&p[M]!==1&&(T[M]=0);return T},b=A(n,u),S=A(o,c),N=A(a,f),w=[],I=1;for(let B=p.length-1;B>=0;B--)w.unshift(I),I*=p[B];let z=p.reduce((B,E)=>B*E,1);for(let B=0;B<z;B++){let E=B,T=0,$=0,M=0;for(let R=0;R<s;R++){let H=Math.floor(E/w[R]);E=E%w[R],T+=H*b[R],$+=H*S[R],M+=H*N[R]}d[T]?m[B]=g[$]:m[B]=h[M]}return y}function Zt(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.data,o=r.size,a=t.data,s=t.size,i=D.zeros([s],"int32"),u=i.data;for(let c=0;c<s;c++){let f=Number(a[c]),p=0,l=o;if(e==="left")for(;p<l;){let y=Math.floor((p+l)/2);Number(n[y])<f?p=y+1:l=y}else for(;p<l;){let y=Math.floor((p+l)/2);Number(n[y])<=f?p=y+1:l=y}u[c]=p}return i}function So(r,t){let e=r.data,n=t.data,o=t.dtype,a=Math.min(r.size,t.size),s=0;for(let f=0;f<a;f++)e[f]&&s++;let i=D.zeros([s],o),u=i.data,c=0;if(x(o)){let f=n,p=u;for(let l=0;l<a;l++)e[l]&&(p[c++]=f[l])}else for(let f=0;f<a;f++)e[f]&&(u[c++]=n[f]);return i}function Gt(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size;if(t===void 0){let l=0;for(let y=0;y<a;y++)o[y]&&l++;return l}let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,y)=>y!==s);if(i.length===0)return Gt(r);let u=D.zeros(i,"int32"),c=u.data,f=e[s],p=i.reduce((l,y)=>l*y,1);for(let l=0;l<p;l++){let y=0;for(let m=0;m<f;m++){let d=v(l,s,m,e),g=U(d,e);o[g]&&y++}c[l]=y}return u}var Do=C(()=>{"use strict";W();q();gt()});function X(r,t=V){let e=D.zeros(r,t);return new _(e)}function Ht(r,t=V){let e=D.ones(r,t);return new _(e)}function Zu(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function xo(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>xo(t)):!1}function Gu(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function P(r,t){if(r instanceof _)return!t||r.dtype===t?r.copy():r.astype(t);let e=xo(r),n=Zu(r),o=n.reduce((f,p)=>f*p,1),a=t;a||(e?a="int64":a=V);let s=O(a);if(!s)throw new Error(`Cannot create array with dtype ${a}`);let i=new s(o),u=Gu(r);if(x(a)){let f=i;for(let p=0;p<o;p++){let l=u[p];f[p]=typeof l=="bigint"?l:BigInt(Math.round(Number(l)))}}else if(a==="bool"){let f=i;for(let p=0;p<o;p++)f[p]=u[p]?1:0}else{let f=i;for(let p=0;p<o;p++){let l=u[p];f[p]=Number(l)}}let c=D.fromData(i,n,a);return new _(c)}function No(r,t,e=1,n=V){let o=r,a=t;if(t===void 0&&(o=0,a=r),a===void 0)throw new Error("stop is required");let s=Math.max(0,Math.ceil((a-o)/e)),i=O(n);if(!i)throw new Error(`Cannot create arange array with dtype ${n}`);let u=new i(s);if(x(n))for(let f=0;f<s;f++)u[f]=BigInt(Math.round(o+f*e));else if(n==="bool")for(let f=0;f<s;f++)u[f]=o+f*e!==0?1:0;else for(let f=0;f<s;f++)u[f]=o+f*e;let c=D.fromData(u,[s],n);return new _(c)}function wo(r,t,e=50,n=V){if(e<0)throw new Error("num must be non-negative");if(e===0)return P([],n);if(e===1)return P([r],n);let o=O(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),s=(t-r)/(e-1);if(x(n))for(let u=0;u<e;u++)a[u]=BigInt(Math.round(r+u*s));else if(n==="bool")for(let u=0;u<e;u++)a[u]=r+u*s!==0?1:0;else for(let u=0;u<e;u++)a[u]=r+u*s;let i=D.fromData(a,[e],n);return new _(i)}function Io(r,t,e=50,n=10,o=V){if(e<0)throw new Error("num must be non-negative");if(e===0)return P([],o);if(e===1)return P([Math.pow(n,r)],o);let a=O(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let s=new a(e),i=(t-r)/(e-1);if(x(o))for(let c=0;c<e;c++){let f=r+c*i;s[c]=BigInt(Math.round(Math.pow(n,f)))}else if(o==="bool")for(let c=0;c<e;c++){let f=r+c*i;s[c]=Math.pow(n,f)!==0?1:0}else for(let c=0;c<e;c++){let f=r+c*i;s[c]=Math.pow(n,f)}let u=D.fromData(s,[e],o);return new _(u)}function zo(r,t,e=50,n=V){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 P([],n);if(e===1)return P([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 s=O(n);if(!s)throw new Error(`Cannot create geomspace array with dtype ${n}`);let i=new s(e),u=Math.log(Math.abs(r)),f=(Math.log(Math.abs(t))-u)/(e-1);if(x(n))for(let l=0;l<e;l++){let y=o*Math.exp(u+l*f);i[l]=BigInt(Math.round(y))}else if(n==="bool")for(let l=0;l<e;l++){let y=o*Math.exp(u+l*f);i[l]=y!==0?1:0}else for(let l=0;l<e;l++){let y=o*Math.exp(u+l*f);i[l]=y}let p=D.fromData(i,[e],n);return new _(p)}function Yt(r,t,e=0,n=V){let o=t??r,a=X([r,o],n),s=a.data;if(x(n)){let i=s;for(let u=0;u<r;u++){let c=u+e;c>=0&&c<o&&(i[u*o+c]=BigInt(1))}}else{let i=s;for(let u=0;u<r;u++){let c=u+e;c>=0&&c<o&&(i[u*o+c]=1)}}return a}function Jt(r,t=V){return X(r,t)}function Xt(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=V);let o=O(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((u,c)=>u*c,1),s=new o(a);if(x(n)){let u=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));s.fill(u)}else n==="bool"?s.fill(t?1:0):s.fill(Number(t));let i=D.fromData(s,r,n);return new _(i)}function _o(r,t=V){return Yt(r,r,0,t)}function Nr(r,t){return r instanceof _?!t||r.dtype===t?r:r.astype(t):P(r,t)}function Bo(r){return r.copy()}function Eo(r,t){return X(Array.from(r.shape),t??r.dtype)}function To(r,t){return Ht(Array.from(r.shape),t??r.dtype)}function Uo(r,t){return Jt(Array.from(r.shape),t??r.dtype)}function vo(r,t,e){return Xt(Array.from(r.shape),t,e??r.dtype)}function Oo(r,t){return Nr(r,t)}function $o(r,t){let e=Nr(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function Mo(r,t){return Nr(r,t).copy()}function Qt(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=X([n,n],r.dtype);for(let a=0;a<e;a++){let s=t>=0?a:a-t,i=t>=0?a+t:a;o.set([s,i],r.get([a]))}return o}else if(r.ndim===2){let[e,n]=r.shape,o,a,s;if(t>=0?(o=0,a=t,s=Math.min(e,n-t)):(o=-t,a=0,s=Math.min(e+t,n)),s<=0)return X([0],r.dtype);let i=O(r.dtype),u=new i(s);for(let f=0;f<s;f++){let p=r.get([o+f,a+f]);x(r.dtype)?u[f]=typeof p=="bigint"?p:BigInt(p):u[f]=p}let c=D.fromData(u,[s],r.dtype);return new _(c)}else throw new Error("Input must be 1-D or 2-D")}function Co(r,t=0){let e=r.flatten();return Qt(e,t)}function ko(r,t,e=V){let n=t.reduce((c,f)=>c*f,1),o=O(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),s=t.length,i=new Array(s).fill(0);for(let c=0;c<n;c++){let f=r(...i);x(e)?a[c]=typeof f=="bigint"?f:BigInt(Number(f)):e==="bool"?a[c]=f?1:0:a[c]=Number(f);for(let p=s-1;p>=0&&(i[p]++,!(i[p]<t[p]));p--)i[p]=0}let u=D.fromData(a,t,e);return new _(u)}function Po(...r){let t=[],e="xy";for(let i of r)i instanceof _?t.push(i):typeof i=="object"&&"indexing"in i&&(e=i.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(i=>i.size);e==="xy"&&t.length>=2&&(t=[t[1],t[0],...t.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,s=[];for(let i=0;i<t.length;i++){let u=t[i],c=u.size,f=new Array(a).fill(1);f[i]=c;let p=u.reshape(...f),l=kt(p.storage,o),y=_._fromStorage(l.copy());s.push(y)}return e==="xy"&&s.length>=2&&([s[0],s[1]]=[s[1],s[0]]),s}function Vo(r,t,e=0,n=V){let o=t??r,a=X([r,o],n);for(let s=0;s<r;s++)for(let i=0;i<=s+e&&i<o;i++)i>=0&&a.set([s,i],1);return a}function Fo(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],s=n.slice(0,-2).reduce((i,u)=>i*u,1);for(let i=0;i<s;i++)for(let u=0;u<o;u++)for(let c=0;c<a;c++)if(c>u+t){let f=[],p=i;for(let l=n.length-3;l>=0;l--)f.unshift(p%n[l]),p=Math.floor(p/n[l]);f.push(u,c),e.set(f,0)}return e}function Ro(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],s=n.slice(0,-2).reduce((i,u)=>i*u,1);for(let i=0;i<s;i++)for(let u=0;u<o;u++)for(let c=0;c<a;c++)if(c<u+t){let f=[],p=i;for(let l=n.length-3;l>=0;l--)f.unshift(p%n[l]),p=Math.floor(p/n[l]);f.push(u,c),e.set(f,0)}return e}function Lo(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=X([n,o],r.dtype);for(let s=0;s<n;s++){let i=r.get([s]);for(let u=0;u<o;u++){let c=e?u:o-1-u;a.set([s,u],Math.pow(i,c))}}return a}function qo(r,t=V,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let s=Hu(t),i=o.byteLength-a,u=Math.floor(i/s),c=e<0?u:Math.min(e,u);if(c<=0)return P([],t);let f=O(t);if(!f)throw new Error(`Unsupported dtype: ${t}`);let p=new f(o,a,c),l=D.fromData(p,[c],t);return new _(l)}function jo(r,t=V,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return P(n,t)}function Wo(r,t=V,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return P(n,t)}function Zo(r,t=V,e=-1,n=""){let o;n===""?o=r.trim().split(/\s+/):o=r.split(n);let a=[],s=0;for(let i of o){if(e>=0&&s>=e)break;let u=i.trim();u!==""&&(x(t)?a.push(BigInt(u)):a.push(parseFloat(u)),s++)}return P(a,t)}function Hu(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 Go(r){return r.sqrt()}function Ho(r,t){return r.power(t)}function Yo(r){return r.absolute()}function Jo(r){return r.negative()}function Xo(r){return r.sign()}function Qo(r,t){return r.mod(t)}function Ko(r,t){return r.floor_divide(t)}function ra(r){return r.positive()}function ta(r){return r.reciprocal()}function ea(r,t){return r.dot(t)}function na(r){return r.trace()}function oa(r,t=0,e=0,n=1){let o=yn(r.storage,t,e,n);return _._fromStorage(o)}function aa(r,t){let e=dn(r.storage,t.storage);return _._fromStorage(e)}function sa(r,t){return r.transpose(t)}function ia(r,t){return r.inner(t)}function ua(r,t){return r.outer(t)}function ca(r,t,e=2){return r.tensordot(t,e)}function fa(r){return r.sin()}function la(r){return r.cos()}function pa(r){return r.tan()}function ya(r){return r.arcsin()}function ma(r){return r.arccos()}function da(r){return r.arctan()}function ga(r,t){return r.arctan2(t)}function Aa(r,t){return r.hypot(t)}function ha(r){return r.degrees()}function ba(r){return r.radians()}function Sa(r){return r.radians()}function Da(r){return r.degrees()}function xa(r){return r.sinh()}function Na(r){return r.cosh()}function wa(r){return r.tanh()}function Ia(r){return r.arcsinh()}function za(r){return r.arccosh()}function _a(r){return r.arctanh()}function Ba(r,t,e){return r.swapaxes(t,e)}function Ea(r,t,e){return r.moveaxis(t,e)}function ur(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=sr(e,t);return _._fromStorage(n)}function Ta(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=Le(e,t);return _._fromStorage(n)}function Kt(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=qe(t);return _._fromStorage(e)}function Ua(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 _._fromStorage(e)}function va(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=je(t);return _._fromStorage(e)}function Oa(r,t,e=0){return We(r.storage,t,e).map(o=>_._fromStorage(o,r.base??r))}function $a(r,t,e=0){return Dr(r.storage,t,e).map(o=>_._fromStorage(o,r.base??r))}function Ma(r,t){return Ge(r.storage,t).map(n=>_._fromStorage(n,r.base??r))}function Ca(r,t){return He(r.storage,t).map(n=>_._fromStorage(n,r.base??r))}function ka(r,t){let e=Ye(r.storage,t);return _._fromStorage(e)}function Pa(r,t,e){return r.repeat(t,e)}function Va(r){return r.ravel()}function Fa(r,t){return r.reshape(...t)}function Ra(r,t){return r.squeeze(t)}function La(r,t){return r.expand_dims(t)}function Hr(r,t){let e=Xe(r.storage,t);return _._fromStorage(e)}function qa(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Hr(r,1)}function ja(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Hr(r,0)}function Wa(r,t=1,e=[0,1]){let n=Qe(r.storage,t,e);return _._fromStorage(n)}function Za(r,t,e){let n=Ke(r.storage,t,e);return _._fromStorage(n)}function Ga(r,t,e=0){let n=rn(r.storage,t,e);return _._fromStorage(n,r.base??r)}function Ha(...r){let t=r.map(o=>o.storage),n=on(t).map((o,a)=>o===t[a]?r[a]:_._fromStorage(o));return n.length===1?n[0]:n}function Ya(...r){let t=r.map(o=>o.storage),n=an(t).map((o,a)=>o===t[a]?r[a]:_._fromStorage(o));return n.length===1?n[0]:n}function Ja(...r){let t=r.map(o=>o.storage),n=sn(t).map((o,a)=>o===t[a]?r[a]:_._fromStorage(o));return n.length===1?n[0]:n}function Xa(r,t){return tn(r.storage,t).map(n=>_._fromStorage(n,r.base??r))}function Qa(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=en(t);return _._fromStorage(e)}function Ka(r){return Kt(r)}function rs(r,t){let e=nn(r.storage,t);return _._fromStorage(e)}function ts(r,t,e){let n=t instanceof _?t:P(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return ur([o,a])}return ur([r,n],e)}function es(r,t,e){let n=r.dtype;if(e===void 0){let y=r.flatten(),d=(Array.isArray(t)?t:[t]).map(S=>S<0?y.size+S:S),g=[];for(let S=0;S<y.size;S++)d.includes(S)||g.push(S);let h=O(n),A=new h(g.length);for(let S=0;S<g.length;S++){let N=y.get([g[S]]);x(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=r.shape,a=o.length,s=e<0?a+e:e;if(s<0||s>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let i=o[s],u=Array.isArray(t)?t:[t],c=new Set(u.map(y=>y<0?i+y:y)),f=[],p=0;for(let y=0;y<=i;y++)(c.has(y)||y===i)&&(y>p&&f.push([p,y]),p=y+1);if(f.length===0){let y=[...o];return y[s]=0,X(y,n)}let l=[];for(let[y,m]of f){let d=o.map(()=>":");d[s]=`${y}:${m}`,l.push(r.slice(...d))}return ur(l,s)}function ns(r,t,e,n){let o=e instanceof _?e:P(e,r.dtype);if(n===void 0){let p=r.flatten(),l=o.flatten(),y=t<0?p.size+t:t;if(y<0||y>p.size)throw new Error(`index ${t} is out of bounds for array of size ${p.size}`);let m=y>0?p.slice(`0:${y}`):null,d=y<p.size?p.slice(`${y}:`):null,g=[];return m&&g.push(m),g.push(l),d&&g.push(d),ur(g)}let a=r.shape,s=a.length,i=n<0?s+n:n;if(i<0||i>=s)throw new Error(`axis ${n} is out of bounds for array of dimension ${s}`);let u=a[i],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 f=[];if(c>0){let p=a.map(()=>":");p[i]=`0:${c}`,f.push(r.slice(...p))}if(f.push(o),c<u){let p=a.map(()=>":");p[i]=`${c}:`,f.push(r.slice(...p))}return ur(f,i)}function os(r,t,e="constant",n=0){let o=r.shape,a=o.length,s=r.dtype,i;if(typeof t=="number"?i=o.map(()=>[t,t]):Array.isArray(t)&&typeof t[0]=="number"?i=o.map(()=>t):i=t,i.length!==a)throw new Error(`pad_width must have ${a} elements`);let u=o.map((d,g)=>d+i[g][0]+i[g][1]),c=u.reduce((d,g)=>d*g,1),f=O(s),p=new f(c),l=x(s);e==="constant"&&(l?p.fill(BigInt(n)):p.fill(n));let y=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]=i[b],N=y[b]-S;if(N<0||N>=o[b]){g=!1;break}h.push(N)}let A;if(g)A=r.get(h);else if(e==="constant"){for(let b=a-1;b>=0&&(y[b]++,!(y[b]<u[b]));b--)y[b]=0;continue}else{let b=[];for(let S=0;S<a;S++){let[N]=i[S],w=y[S]-N,I=o[S];w<0?e==="edge"?w=0:e==="reflect"?(w=-w,w>=I&&(w=I-1)):e==="symmetric"?(w=-w-1,w>=I&&(w=I-1),w<0&&(w=0)):e==="wrap"&&(w=(w%I+I)%I):w>=I&&(e==="edge"?w=I-1:e==="reflect"?(w=2*I-w-2,w<0&&(w=0)):e==="symmetric"?(w=2*I-w-1,w<0&&(w=0)):e==="wrap"&&(w=w%I)),b.push(Math.max(0,Math.min(I-1,w)))}A=r.get(b)}l?p[d]=typeof A=="bigint"?A:BigInt(Number(A)):p[d]=Number(A);for(let b=a-1;b>=0&&(y[b]++,!(y[b]<u[b]));b--)y[b]=0}let m=D.fromData(p,u,s);return new _(m)}function as(r,t){let e=kt(r.storage,t);return _._fromStorage(e,r.base??r)}function ss(...r){let t=r.map(n=>n.storage);return Pn(t).map((n,o)=>_._fromStorage(n,r[o].base??r[o]))}function is(...r){return yt(...r)}function us(r,t,e){return r.take(t,e)}function cs(r,t,e){r.put(t,e)}function fs(r,t){let e=t.map(o=>o.storage),n=Rn(r.storage,e);return _._fromStorage(n)}function ls(r,t,e=!1){return Ln(r.storage,t.storage,e)}function ps(r,t){return Ce(r.storage,t.storage)}function ys(r,t){return _._fromStorage(Nt(r.storage,t))}function ms(r,t){return _._fromStorage(wt(r.storage,t))}function ds(r,t,e=!1){let n=It(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function gs(r,t,e=!1){let n=zt(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function As(r,t,e,n=!1){let o=_t(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function hs(r,t,e,n=!1){let o=pr(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function bs(r,t,e,n=!1){let o=e?e.storage:void 0,a=Cr(r.storage,t,o,n);return typeof a=="number"?a:_._fromStorage(a)}function Ss(r,t,e=!1){let n=kr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Ds(r,t,e=!1){let n=Pr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function xs(r,t,e=!1){let n=Vr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Ns(r,t,e=0,n=!1){let o=Ar(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function ws(r,t,e=0,n=!1){let o=Bt(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Is(r,t,e=!1){let n=Fr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function zs(r,t,e=!1){let n=Rr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function _s(r,t){let e=Lr(r.storage,t);return typeof e=="number"?e:_._fromStorage(e)}function Bs(r,t){let e=qr(r.storage,t);return typeof e=="number"?e:_._fromStorage(e)}function Es(r,t){return _._fromStorage(Et(r.storage,t))}function Ts(r,t){return _._fromStorage(Tt(r.storage,t))}function Us(r,t,e=!1){let n=jr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function vs(r){return r.cbrt()}function Os(r){return r.fabs()}function $s(r,t){return r.divmod(t)}function Ms(r){return r.square()}function Cs(r,t){return r.remainder(t)}function ks(r,t){return r.heaviside(t)}function Ps(r,t){return r.bitwise_and(t)}function Vs(r,t){return r.bitwise_or(t)}function Fs(r,t){return r.bitwise_xor(t)}function Rs(r){return r.bitwise_not()}function Ls(r){return r.invert()}function qs(r,t){return r.left_shift(t)}function js(r,t){return r.right_shift(t)}function Ws(r,t=-1,e="big"){let n=po(r.storage,t,e);return _._fromStorage(n)}function Zs(r,t=-1,e=-1,n="big"){let o=yo(r.storage,t,e,n);return _._fromStorage(o)}function Gs(r,...t){let e=t.map(o=>o.storage),n=mn(r,...e);return typeof n=="number"||typeof n=="bigint"?n:_._fromStorage(n)}function Hs(r,t,e){return _._fromStorage(qn(r.storage,t.storage,e))}function Ys(r,t,e,n){jn(r.storage,t.storage,e.storage,n)}function Js(r,t,e){let n=e instanceof _?e.storage:e;Wn(r.storage,t.storage,n)}function Xs(r,t,e){return _._fromStorage(Zn(r.storage,t.storage,e))}function Qs(r,t,e=0){let n=r.map(a=>a.storage),o=t.map(a=>a.storage);return _._fromStorage(Gn(n,o,e))}function Ks(r,t,e){Hn(r.storage,t.storage,e.storage)}function ri(r,t=2){return Pt(r,t).map(n=>_._fromStorage(n))}function ti(r){return Yn(r.storage).map(e=>_._fromStorage(e))}function ei(r,t=0,e){return Vt(r,t,e).map(o=>_._fromStorage(o))}function ni(r,t=0){return Jn(r.storage,t).map(n=>_._fromStorage(n))}function oi(r,t=0,e){return Ft(r,t,e).map(o=>_._fromStorage(o))}function ai(r,t=0){return Xn(r.storage,t).map(n=>_._fromStorage(n))}function si(r,t,e=0){return Qn(r,(a,s)=>t(a,s).storage,e).map(a=>_._fromStorage(a))}function ii(r,t="int32"){return _._fromStorage(Kn(r,t))}function ui(...r){return ro(...r.map(e=>e.storage)).map(e=>_._fromStorage(e))}function ci(r,t,e="raise"){let n=r.map(o=>o.storage);return _._fromStorage(to(n,t,e))}function fi(r,t,e="C"){let n=r instanceof _?r.storage:r;return eo(n,t,e).map(a=>_._fromStorage(a))}function li(r,t=-1){return _._fromStorage(Lt(r.storage,t))}function pi(r,t=-1){return _._fromStorage(qt(r.storage,t))}function yi(r){let t=r.map(e=>e.storage);return _._fromStorage(go(t))}function mi(r,t,e=-1){return _._fromStorage(jt(r.storage,t,e))}function di(r,t,e=-1){return _._fromStorage(Wt(r.storage,t,e))}function gi(r){return _._fromStorage(Ao(r.storage))}function Ai(r){return Gr(r.storage).map(e=>_._fromStorage(e))}function hi(r){return _._fromStorage(ho(r.storage))}function bi(r,t,e){let n=bo(r.storage,t?.storage,e?.storage);return Array.isArray(n)?n.map(o=>_._fromStorage(o)):_._fromStorage(n)}function Si(r,t,e="left"){return _._fromStorage(Zt(r.storage,t.storage,e))}function Di(r,t){return _._fromStorage(So(r.storage,t.storage))}function xi(r,t){let e=Gt(r.storage,t);return typeof e=="number"?e:_._fromStorage(e)}var _,Yr=C(()=>{"use strict";ue();q();W();Be();ke();Ve();Ot();gn();bn();Tn();kn();no();mo();Do();_=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((s,i)=>{let u=s;if(u<0&&(u=this.shape[i]+u),u<0||u>=this.shape[i])throw new Error(`Index ${s} is out of bounds for axis ${i} with size ${this.shape[i]}`);return u}),o=this.dtype,a;x(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,s=O(t);if(!s)throw new Error(`Cannot convert to dtype ${t}`);let i=new s(a),u=this.data;if(x(n)&&!x(t)){let f=u;if(t==="bool")for(let p=0;p<a;p++)i[p]=f[p]!==BigInt(0)?1:0;else for(let p=0;p<a;p++)i[p]=Number(f[p])}else if(!x(n)&&x(t)){let f=u;for(let p=0;p<a;p++)i[p]=BigInt(Math.round(Number(f[p])))}else if(t==="bool"){let f=u;for(let p=0;p<a;p++)i[p]=f[p]!==0?1:0}else if(n==="bool"&&!x(t)){let f=u;for(let p=0;p<a;p++)i[p]=f[p]}else if(!x(n)&&!x(t)){let f=u;for(let p=0;p<a;p++)i[p]=f[p]}else{let f=u;for(let p=0;p<a;p++)i[p]=f[p]}let c=D.fromData(i,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=ye(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=me(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=de(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=ge(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=vr(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=pt(this._storage,e);return r._fromStorage(n)}positive(){let t=Se(this._storage);return r._fromStorage(t)}reciprocal(){let t=De(this._storage);return r._fromStorage(t)}sqrt(){let t=An(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=hn(this._storage,e);return r._fromStorage(n)}absolute(){let t=Ae(this._storage);return r._fromStorage(t)}negative(){let t=he(this._storage);return r._fromStorage(t)}sign(){let t=be(this._storage);return r._fromStorage(t)}sin(){let t=Sn(this._storage);return r._fromStorage(t)}cos(){let t=Dn(this._storage);return r._fromStorage(t)}tan(){let t=xn(this._storage);return r._fromStorage(t)}arcsin(){let t=Nn(this._storage);return r._fromStorage(t)}arccos(){let t=wn(this._storage);return r._fromStorage(t)}arctan(){let t=In(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=zn(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=_n(this._storage,e);return r._fromStorage(n)}degrees(){let t=Bn(this._storage);return r._fromStorage(t)}radians(){let t=En(this._storage);return r._fromStorage(t)}sinh(){let t=Un(this._storage);return r._fromStorage(t)}cosh(){let t=vn(this._storage);return r._fromStorage(t)}tanh(){let t=On(this._storage);return r._fromStorage(t)}arcsinh(){let t=$n(this._storage);return r._fromStorage(t)}arccosh(){let t=Mn(this._storage);return r._fromStorage(t)}arctanh(){let t=Cn(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=Ee(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=Te(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=Ue(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=ve(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=Oe(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=$e(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=dt(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 Me(this._storage,o,e,n)}bitwise_and(t){let e=typeof t=="number"?t:t._storage,n=so(this._storage,e);return r._fromStorage(n)}bitwise_or(t){let e=typeof t=="number"?t:t._storage,n=io(this._storage,e);return r._fromStorage(n)}bitwise_xor(t){let e=typeof t=="number"?t:t._storage,n=uo(this._storage,e);return r._fromStorage(n)}bitwise_not(){let t=Rt(this._storage);return r._fromStorage(t)}invert(){let t=co(this._storage);return r._fromStorage(t)}left_shift(t){let e=typeof t=="number"?t:t._storage,n=fo(this._storage,e);return r._fromStorage(n)}right_shift(t){let e=typeof t=="number"?t:t._storage,n=lo(this._storage,e);return r._fromStorage(n)}sum(t,e=!1){let n=gr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=Or(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=$r(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=Mr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=At(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=ht(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=bt(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=St(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=Pe(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=Dt(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=xt(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(Nt(this._storage,t))}cumprod(t){return r._fromStorage(wt(this._storage,t))}ptp(t,e=!1){let n=It(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=zt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=_t(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=pr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=Cr(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=kr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=Pr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=Vr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=Ar(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=Bt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=Fr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=Rr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=Lr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=qr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(Et(this._storage,t))}nancumprod(t){return r._fromStorage(Tt(this._storage,t))}nanmedian(t,e=!1){let n=jr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}sort(t=-1){return r._fromStorage(Lt(this._storage,t))}argsort(t=-1){return r._fromStorage(qt(this._storage,t))}partition(t,e=-1){return r._fromStorage(jt(this._storage,t,e))}argpartition(t,e=-1){return r._fromStorage(Wt(this._storage,t,e))}nonzero(){return Gr(this._storage).map(e=>r._fromStorage(e))}searchsorted(t,e="left"){return r._fromStorage(Zt(this._storage,t._storage,e))}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=G(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Wr(this._storage);return r._fromStorage(t)}ravel(){let t=br(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=Sr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=Fe(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=hr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=Re(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=Ut(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=Je(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=Vn(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;Fn(this._storage,t,n)}matmul(t){let e=ir(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=Mt(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return fn(this._storage)}inner(t){let e=ln(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=Ct(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=pn(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=xe(this._storage);return r._fromStorage(t)}fabs(){let t=Ne(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=we(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=Ie(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=ze(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=_e(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 f=se(u);return ie(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 u=0;u<e.length;u++){let c=e[u],f=this._storage.strides[u];if(a+=c.start*f,!c.isIndex){let p;c.step>0?p=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):p=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(p),o.push(f*c.step)}}let s=D.fromData(this._storage.data,n,this._storage.dtype,o,a),i=this._base??this;return new r(s,i)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}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 s=[];for(let i=0;i<t[a];i++)o[a]=i,s.push(n(o,a+1));return s};return n(new Array(e),0)}}});function re(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}function wi(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 Ni)throw new Q(`Unsupported dtype: ${Ni[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Yu[e];if(!o)throw new Q(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Jr.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=re(),s=t==="<"||t==="|"||t==="="&&a,i=t===">"||t==="="&&!a,u=parseInt(e.slice(1),10),c=u>1&&(i&&a||s&&!a);return{dtype:o,needsByteSwap:c,itemsize:u}}var wr,Jr,Yu,Ir,Ni,Q,Z,zr=C(()=>{"use strict";wr=new Uint8Array([147,78,85,77,80,89]),Jr=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];Yu={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},Ir={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},Ni={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};Q=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},Z=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}}});function or(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Xr(t);return Qr(t,e)}function Xr(r){if(r.length<10)throw new Z("File too small to be a valid NPY file");for(let c=0;c<wr.length;c++)if(r[c]!==wr[c])throw new Z("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new Z(`Unsupported NPY version: ${t}.${e}`);let n,o;t===1?(n=r[8]|r[9]<<8,o=10):(n=r[8]|r[9]<<8|r[10]<<16|r[11]<<24,o=12);let a=o+n;if(r.length<a)throw new Z("File truncated: header extends beyond file");let s=r.slice(o,a),i=new TextDecoder("utf-8").decode(s).trim(),u=Ju(i);return{version:{major:t,minor:e},header:u,dataOffset:a}}function Qr(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:s}=wi(e.descr),i=e.shape.reduce((d,g)=>d*g,1),u=i*s,c=r.length-n;if(c<u)throw new Z(`File truncated: expected ${u} bytes of data, got ${c}`);let f=new ArrayBuffer(u);new Uint8Array(f).set(r.subarray(n,n+u));let l=Xu(f,o,i,a,s),y=e.shape,m;if(e.fortran_order&&y.length>1){let d=[...y].reverse(),g=D.fromData(l,d,o);m=Qu(g,d),y=e.shape}else m=D.fromData(l,[...y],o);return new _(m)}function Ju(r){let t=r.match(/'descr'\s*:\s*'([^']+)'/),e=r.match(/'fortran_order'\s*:\s*(True|False)/),n=r.match(/'shape'\s*:\s*\(([^)]*)\)/);if(!t||!e||!n)throw new Z(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",s=n[1].trim(),i;return s===""?i=[]:i=s.split(",").map(u=>u.trim()).filter(u=>u!=="").map(u=>{let c=parseInt(u,10);if(isNaN(c))throw new Z(`Invalid shape value: ${u}`);return c}),{descr:o,fortran_order:a,shape:i}}function Xu(r,t,e,n,o){let a=O(t);if(!a)throw new Z(`Cannot create array for dtype: ${t}`);if(!n)return new a(r,0,e);let s=new Uint8Array(r),i=new Uint8Array(r.byteLength);for(let u=0;u<e;u++){let c=u*o;for(let f=0;f<o;f++)i[c+f]=s[c+o-1-f]}return new a(i.buffer,0,e)}function Qu(r,t){let e=t.length,n=r.size,o=r.dtype,a=O(o);if(!a)throw new Z(`Cannot create array for dtype: ${o}`);let s=new a(n),i=[...t].reverse(),u=Ii(t),c=Ii(i),f=new Array(e).fill(0);for(let p=0;p<n;p++){let l=p;for(let m=0;m<e;m++){let d=u[m];f[m]=Math.floor(l/d),l=l%d}let y=0;for(let m=0;m<e;m++)y+=f[e-1-m]*c[m];x(o),s[y]=r.iget(p)}return D.fromData(s,i,o)}function Ii(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}var Kr=C(()=>{"use strict";Yr();W();q();zr()});function tr(r){let t=r.shape,e=r.dtype,n=Ir[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,s=12,u=(64-(s+a.length+1)%64)%64;a=a+" ".repeat(u)+`
2
+ `;let c=new TextEncoder().encode(a),f=c.length,p=r.size,l=fe(e),y=p*l,m=s+f+y,d=new Uint8Array(m);d.set(wr,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,s);let g=s+f;return Ku(r,d.subarray(g),l),d}function Ku(r,t,e){let n=r.dtype,o=r.size,a=re(),s=x(n),i=r._storage;if(i.isCContiguous&&i.offset===0&&a){let c=i.data,f=new Uint8Array(c.buffer,c.byteOffset,o*e);t.set(f)}else{let c=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let f=0;f<o;f++){let p=i.iget(f),l=f*e;s?rc(c,l,p,n==="uint64"):tc(c,l,p,n)}}}function rc(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function tc(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 rt=C(()=>{"use strict";q();zr()});function te(r){let t=4294967295;for(let e=0;e<r.length;e++)t=ec[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}var ec,ee=C(()=>{"use strict";ec=(()=>{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})()});async function zi(r){let t=Bi(r),e=new Map;for(let n of t){let o=await nc(n);e.set(n.name,o)}return e}function _i(r){let t=Bi(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 Bi(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),s=e.getUint16(o+10,!0),i=[],u=a;for(let c=0;c<s&&e.getUint32(u,!0)===33639248;c++){let p=e.getUint16(u+10,!0),l=e.getUint32(u+16,!0),y=e.getUint32(u+20,!0),m=e.getUint32(u+24,!0),d=e.getUint16(u+28,!0),g=e.getUint16(u+30,!0),h=e.getUint16(u+32,!0),A=e.getUint32(u+42,!0),b=t.slice(u+46,u+46+d),S=new TextDecoder("utf-8").decode(b);i.push({name:S,compressionMethod:p,crc32:l,compressedSize:y,uncompressedSize:m,localHeaderOffset:A}),u=u+46+d+g+h}for(let c of i){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),y=e.getUint16(f+28,!0),m=f+30+l+y,d=t.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 nc(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await oc(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function oc(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:f}=await o.read();if(c)break;a.push(f)}let s=a.reduce((c,f)=>c+f.length,0),i=new Uint8Array(s),u=0;for(let c of a)i.set(c,u),u+=c.length;return i}var Ei=C(()=>{"use strict";ee()});var Ui={};ct(Ui,{loadNpz:()=>tt,loadNpzSync:()=>et,parseNpz:()=>cr,parseNpzSync:()=>Br});async function cr(r,t={}){let e=t.force??!1,n=await zi(r);return Ti(n,e)}function Br(r,t={}){let e=t.force??!1,n=_i(r);return Ti(n,e)}function Ti(r,t){let e=new Map,n=[],o=new Map;for(let[a,s]of r){if(!a.endsWith(".npy"))continue;let i=a.slice(0,-4);try{let u=or(s);e.set(i,u)}catch(u){if(u instanceof Q&&t)n.push(i),o.set(i,u.message);else throw u}}return{arrays:e,skipped:n,errors:o}}async function tt(r,t={}){let e=await cr(r,t);return Object.fromEntries(e.arrays)}function et(r,t={}){let e=Br(r,t);return Object.fromEntries(e.arrays)}var nt=C(()=>{"use strict";Kr();zr();Ei()});async function vi(r,t={}){let e=t.compress??!1,n=[];for(let[l,y]of r){let m=te(y),d,g;e?(d=await sc(y),d.length<y.length?g=8:(d=y,g=0)):(d=y,g=0),n.push({name:l,data:y,compressedData:d,crc:m,compressionMethod:g,offset:0})}let o=0;for(let l of n){let y=new TextEncoder().encode(l.name);o+=30+y.length+l.compressedData.length}let a=0;for(let l of n){let y=new TextEncoder().encode(l.name);a+=46+y.length}let i=o+a+22,u=new Uint8Array(i),c=new DataView(u.buffer),f=0;for(let l of n)l.offset=f,f=$i(u,c,f,l);let p=f;for(let l of n)f=Mi(u,c,f,l);return Ci(c,f,n.length,a,p),u}function Oi(r){let t=[];for(let[f,p]of r){let l=te(p);t.push({name:f,data:p,compressedData:p,crc:l,compressionMethod:0,offset:0})}let e=0;for(let f of t){let p=new TextEncoder().encode(f.name);e+=30+p.length+f.compressedData.length}let n=0;for(let f of t){let p=new TextEncoder().encode(f.name);n+=46+p.length}let a=e+n+22,s=new Uint8Array(a),i=new DataView(s.buffer),u=0;for(let f of t)f.offset=u,u=$i(s,i,u,f);let c=u;for(let f of t)u=Mi(s,i,u,f);return Ci(i,u,t.length,n,c),s}function $i(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 Mi(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 Ci(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 sc(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:f}=await o.read();if(c)break;a.push(f)}let s=a.reduce((c,f)=>c+f.length,0),i=new Uint8Array(s),u=0;for(let c of a)i.set(c,u),u+=c.length;return i}var ki=C(()=>{"use strict";ee()});var Vi={};ct(Vi,{serializeNpz:()=>mr,serializeNpzSync:()=>ot});async function mr(r,t={}){let e=Pi(r);return vi(e,{compress:t.compress??!1})}function ot(r){let t=Pi(r);return Oi(t)}function Pi(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=tr(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=tr(o),s=n.endsWith(".npy")?n:`${n}.npy`;t.set(s,a)}return t}var at=C(()=>{"use strict";rt();ki()});var Nc={};ct(Nc,{DTYPE_TO_DESCR:()=>Ir,InvalidNpyError:()=>Z,NDArray:()=>_,SUPPORTED_DTYPES:()=>Jr,UnsupportedDTypeError:()=>Q,__version__:()=>ic,absolute:()=>Yo,append:()=>ts,arange:()=>No,arccos:()=>ma,arccosh:()=>za,arcsin:()=>ya,arcsinh:()=>Ia,arctan:()=>da,arctan2:()=>ga,arctanh:()=>_a,argpartition:()=>di,argsort:()=>pi,array:()=>P,array_equal:()=>ls,array_equiv:()=>ps,array_split:()=>$a,asanyarray:()=>Oo,asarray:()=>Nr,ascontiguousarray:()=>$o,asfortranarray:()=>Mo,atleast_1d:()=>Ha,atleast_2d:()=>Ya,atleast_3d:()=>Ja,average:()=>bs,bitwise_and:()=>Ps,bitwise_not:()=>Rs,bitwise_or:()=>Vs,bitwise_xor:()=>Fs,broadcast_arrays:()=>ss,broadcast_shapes:()=>is,broadcast_to:()=>as,cbrt:()=>vs,choose:()=>fs,column_stack:()=>Qa,compress:()=>Xs,concatenate:()=>ur,copy:()=>Bo,cos:()=>la,cosh:()=>Na,count_nonzero:()=>xi,cumprod:()=>ms,cumsum:()=>ys,deg2rad:()=>Sa,degrees:()=>ha,delete:()=>es,diag:()=>Qt,diag_indices:()=>ri,diag_indices_from:()=>ti,diagflat:()=>Co,diagonal:()=>oa,divmod:()=>$s,dot:()=>ea,dsplit:()=>Xa,dstack:()=>va,einsum:()=>Gs,empty:()=>Jt,empty_like:()=>Uo,expand_dims:()=>La,extract:()=>Di,eye:()=>Yt,fabs:()=>Os,flatnonzero:()=>hi,flip:()=>Hr,fliplr:()=>qa,flipud:()=>ja,floor_divide:()=>Ko,frombuffer:()=>qo,fromfile:()=>jo,fromfunction:()=>ko,fromiter:()=>Wo,fromregex:()=>Dc,fromregexSync:()=>xc,fromstring:()=>Zo,full:()=>Xt,full_like:()=>vo,genfromtxt:()=>bc,genfromtxtSync:()=>Sc,geomspace:()=>zo,heaviside:()=>ks,hsplit:()=>Ca,hstack:()=>Ua,hypot:()=>Aa,identity:()=>_o,indices:()=>ii,inner:()=>ia,insert:()=>ns,invert:()=>Ls,ix_:()=>ui,kron:()=>aa,left_shift:()=>qs,lexsort:()=>yi,linspace:()=>wo,load:()=>cc,loadNpy:()=>Ri,loadNpySync:()=>Li,loadNpz:()=>tt,loadNpzFile:()=>Wi,loadNpzFileSync:()=>Zi,loadNpzSync:()=>et,loadSync:()=>fc,loadtxt:()=>dc,loadtxtSync:()=>gc,logspace:()=>Io,mask_indices:()=>si,median:()=>gs,meshgrid:()=>Po,mod:()=>Qo,moveaxis:()=>Ea,nanargmax:()=>Bs,nanargmin:()=>_s,nancumprod:()=>Ts,nancumsum:()=>Es,nanmax:()=>zs,nanmean:()=>xs,nanmedian:()=>Us,nanmin:()=>Is,nanprod:()=>Ds,nanstd:()=>ws,nansum:()=>Ss,nanvar:()=>Ns,negative:()=>Jo,nonzero:()=>Ai,ones:()=>Ht,ones_like:()=>To,outer:()=>ua,packbits:()=>Ws,pad:()=>os,parseNpy:()=>or,parseNpyData:()=>Qr,parseNpyHeader:()=>Xr,parseNpz:()=>cr,parseNpzSync:()=>Br,parseTxt:()=>fr,partition:()=>mi,percentile:()=>As,place:()=>Ks,positive:()=>ra,power:()=>Ho,ptp:()=>ds,put:()=>cs,put_along_axis:()=>Ys,putmask:()=>Js,quantile:()=>hs,rad2deg:()=>Da,radians:()=>ba,ravel:()=>Va,ravel_multi_index:()=>ci,reciprocal:()=>ta,remainder:()=>Cs,repeat:()=>Pa,reshape:()=>Fa,resize:()=>rs,right_shift:()=>js,roll:()=>Za,rollaxis:()=>Ga,rot90:()=>Wa,row_stack:()=>Ka,save:()=>lc,saveNpy:()=>qi,saveNpySync:()=>ji,saveNpz:()=>ae,saveNpzSync:()=>uc,saveSync:()=>pc,savetxt:()=>Ac,savetxtSync:()=>hc,savez:()=>yc,savez_compressed:()=>mc,searchsorted:()=>Si,select:()=>Qs,serializeNpy:()=>tr,serializeNpz:()=>mr,serializeNpzSync:()=>ot,serializeTxt:()=>dr,sign:()=>Xo,sin:()=>fa,sinh:()=>xa,sort:()=>li,sort_complex:()=>gi,split:()=>Oa,sqrt:()=>Go,square:()=>Ms,squeeze:()=>Ra,stack:()=>Ta,swapaxes:()=>Ba,take:()=>us,take_along_axis:()=>Hs,tan:()=>pa,tanh:()=>wa,tensordot:()=>ca,tile:()=>ka,trace:()=>na,transpose:()=>sa,tri:()=>Vo,tril:()=>Fo,tril_indices:()=>ei,tril_indices_from:()=>ni,triu:()=>Ro,triu_indices:()=>oi,triu_indices_from:()=>ai,unpackbits:()=>Zs,unravel_index:()=>fi,vander:()=>Lo,vsplit:()=>Ma,vstack:()=>Kt,where:()=>bi,zeros:()=>X,zeros_like:()=>Eo});module.exports=ft(Nc);var K=require("node:fs"),rr=require("node:fs/promises");Kr();rt();nt();at();Yr();function fr(r,t={}){let{delimiter:e,comments:n="#",skiprows:o=0,usecols:a,max_rows:s,dtype:i="float64",missing_values:u,filling_values:c}=t,f=r.split(/\r?\n/);if(o>0&&(f=f.slice(o)),f=f.filter(d=>{let g=d.trim();return!(g===""||n&&g.startsWith(n))}),s!==void 0&&s>0&&(f=f.slice(0,s)),f.length===0)return P([],i);let p=[],l=new Set(u?Array.isArray(u)?u:[u]:[]),y=c!==void 0?c:i.includes("int")||i==="bool"?0:NaN;for(let d of f){let g;e===void 0?g=d.trim().split(/\s+/):g=d.split(e),a!==void 0&&(g=(Array.isArray(a)?a:[a]).map(b=>(b<0&&(b=g.length+b),g[b]??"")));let h=g.map(A=>{let b=A.trim();if(l.has(b)||b==="")return y;let S=parseFloat(b);return isNaN(S)?y:S});p.push(h)}let m=p[0]?.length??0;for(let d=1;d<p.length;d++)if(p[d].length!==m)throw new Error(`Inconsistent number of columns: row 0 has ${m} columns, row ${d} has ${p[d].length} columns`);return m===1?P(p.map(d=>d[0]),i):P(p,i)}function Er(r,t={}){let e={...t,missing_values:t.missing_values??["","nan","NaN","NA","N/A","-"],filling_values:t.filling_values??NaN};return fr(r,e)}function Tr(r,t,e="float64"){let n=typeof t=="string"?new RegExp(t,"gm"):new RegExp(t.source,"gm"),o=[],a;for(;(a=n.exec(r))!==null;)if(a.length>1){let s=a.slice(1).map(i=>{let u=parseFloat(i);return isNaN(u)?0:u});o.push(s)}return o.length===0?P([],e):o[0].length===1?P(o.map(s=>s[0]),e):P(o,e)}function Fi(r,t){let e=typeof r=="bigint"?Number(r):r,n=t.match(/^%([+-]?)(\d*)(?:\.(\d+))?([dfeEgGs])$/);if(!n)return String(e);let[,o,a,s,i]=n,u=s!==void 0?parseInt(s,10):void 0,c;switch(i){case"d":c=Math.round(e).toString();break;case"f":c=e.toFixed(u??6);break;case"e":c=e.toExponential(u??6).replace(/e([+-])(\d)$/,"e$10$2");break;case"E":c=e.toExponential(u??6).toUpperCase().replace(/E([+-])(\d)$/,"E$10$2");break;case"g":case"G":{let f=u??6,p=Math.floor(Math.log10(Math.abs(e)));p>=-4&&p<f?(c=e.toPrecision(f),c.includes(".")&&(c=c.replace(/\.?0+$/,""))):c=e.toExponential(f-1),i==="G"&&(c=c.toUpperCase());break}case"s":c=String(e);break;default:c=String(e)}if(a){let f=parseInt(a,10);if(c.length<f){let p=" ".repeat(f-c.length);o==="-"?c=c+p:c=p+c}}return o==="+"&&e>=0&&!c.startsWith("-")&&(c="+"+c),c}function dr(r,t={}){let{fmt:e="%.18e",delimiter:n=" ",newline:o=`
3
+ `,header:a,footer:s,comments:i="# "}=t;if(r.ndim>2)throw new Error("savetxt: array must be 1D or 2D");let u=[];if(a!==void 0){let f=a.split(/\r?\n/);for(let p of f)p.startsWith(i.trimEnd())?u.push(p):u.push(i+p)}let c=r.toArray();if(r.ndim===1)for(let f of c)u.push(Fi(f,e));else for(let f of c){let p=f.map(l=>Fi(l,e));u.push(p.join(n))}if(s!==void 0){let f=s.split(/\r?\n/);for(let p of f)p.startsWith(i.trimEnd())?u.push(p):u.push(i+p)}return u.join(o)+o}Yr();Kr();rt();zr();nt();at();var ic="0.8.0";async function Ri(r){let t=await(0,rr.readFile)(r);return or(t)}function Li(r){let t=(0,K.readFileSync)(r);return or(t)}async function qi(r,t){let e=tr(t);await(0,rr.writeFile)(r,e)}function ji(r,t){let e=tr(t);(0,K.writeFileSync)(r,e)}async function Wi(r,t={}){let e=await(0,rr.readFile)(r);return cr(e,t)}function Zi(r,t={}){let e=(0,K.readFileSync)(r),{parseNpzSync:n}=(nt(),ft(Ui));return n(e,t)}async function ae(r,t,e={}){let n=await mr(t,e);await(0,rr.writeFile)(r,n)}function uc(r,t){let{serializeNpzSync:e}=(at(),ft(Vi)),n=e(t);(0,K.writeFileSync)(r,n)}async function cc(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return Ri(r)}else{if(r.endsWith(".npz"))return Wi(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function fc(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return Li(r)}else{if(r.endsWith(".npz"))return Zi(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function lc(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return qi(r,t)}function pc(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return ji(r,t)}async function yc(r,t){return r.endsWith(".npz")||(r=r+".npz"),ae(r,t,{compress:!1})}async function mc(r,t){return r.endsWith(".npz")||(r=r+".npz"),ae(r,t,{compress:!0})}async function dc(r,t={}){let e=await(0,rr.readFile)(r,{encoding:t.encoding??"utf-8"});return fr(e,t)}function gc(r,t={}){let e=(0,K.readFileSync)(r,{encoding:t.encoding??"utf-8"});return fr(e,t)}async function Ac(r,t,e={}){let n=dr(t,e);await(0,rr.writeFile)(r,n,"utf-8")}function hc(r,t,e={}){let n=dr(t,e);(0,K.writeFileSync)(r,n,"utf-8")}async function bc(r,t={}){let e=await(0,rr.readFile)(r,{encoding:t.encoding??"utf-8"});return Er(e,t)}function Sc(r,t={}){let e=(0,K.readFileSync)(r,{encoding:t.encoding??"utf-8"});return Er(e,t)}async function Dc(r,t,e="float64"){let n=await(0,rr.readFile)(r,{encoding:"utf-8"});return Tr(n,t,e)}function xc(r,t,e="float64"){let n=(0,K.readFileSync)(r,{encoding:"utf-8"});return Tr(n,t,e)}0&&(module.exports={DTYPE_TO_DESCR,InvalidNpyError,NDArray,SUPPORTED_DTYPES,UnsupportedDTypeError,__version__,absolute,append,arange,arccos,arccosh,arcsin,arcsinh,arctan,arctan2,arctanh,argpartition,argsort,array,array_equal,array_equiv,array_split,asanyarray,asarray,ascontiguousarray,asfortranarray,atleast_1d,atleast_2d,atleast_3d,average,bitwise_and,bitwise_not,bitwise_or,bitwise_xor,broadcast_arrays,broadcast_shapes,broadcast_to,cbrt,choose,column_stack,compress,concatenate,copy,cos,cosh,count_nonzero,cumprod,cumsum,deg2rad,degrees,delete:null,diag,diag_indices,diag_indices_from,diagflat,diagonal,divmod,dot,dsplit,dstack,einsum,empty,empty_like,expand_dims,extract,eye,fabs,flatnonzero,flip,fliplr,flipud,floor_divide,frombuffer,fromfile,fromfunction,fromiter,fromregex,fromregexSync,fromstring,full,full_like,genfromtxt,genfromtxtSync,geomspace,heaviside,hsplit,hstack,hypot,identity,indices,inner,insert,invert,ix_,kron,left_shift,lexsort,linspace,load,loadNpy,loadNpySync,loadNpz,loadNpzFile,loadNpzFileSync,loadNpzSync,loadSync,loadtxt,loadtxtSync,logspace,mask_indices,median,meshgrid,mod,moveaxis,nanargmax,nanargmin,nancumprod,nancumsum,nanmax,nanmean,nanmedian,nanmin,nanprod,nanstd,nansum,nanvar,negative,nonzero,ones,ones_like,outer,packbits,pad,parseNpy,parseNpyData,parseNpyHeader,parseNpz,parseNpzSync,parseTxt,partition,percentile,place,positive,power,ptp,put,put_along_axis,putmask,quantile,rad2deg,radians,ravel,ravel_multi_index,reciprocal,remainder,repeat,reshape,resize,right_shift,roll,rollaxis,rot90,row_stack,save,saveNpy,saveNpySync,saveNpz,saveNpzSync,saveSync,savetxt,savetxtSync,savez,savez_compressed,searchsorted,select,serializeNpy,serializeNpz,serializeNpzSync,serializeTxt,sign,sin,sinh,sort,sort_complex,split,sqrt,square,squeeze,stack,swapaxes,take,take_along_axis,tan,tanh,tensordot,tile,trace,transpose,tri,tril,tril_indices,tril_indices_from,triu,triu_indices,triu_indices_from,unpackbits,unravel_index,vander,vsplit,vstack,where,zeros,zeros_like});
3
4
  //# sourceMappingURL=numpy-ts.node-io.cjs.map