numpy-ts 0.5.0 → 0.6.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,3 @@
1
- var Ar=Object.defineProperty;var Ze=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var _=(r,t)=>()=>(r&&(t=r(r=0)),t);var Hr=(r,t)=>{for(var e in t)Ar(r,e,{get:t[e],enumerable:!0})},Ge=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of We(t))!He.call(r,o)&&o!==e&&Ar(r,o,{get:()=>t[o],enumerable:!(n=Ze(t,o))||n.enumerable});return r};var Gr=r=>Ge(Ar({},"__esModule",{value:!0}),r);function Yr(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 Jr(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 c=e<0?t+e:e;if(c<0||c>=t)throw new Error(`Index ${e} is out of bounds for size ${t}`);return{start:c,stop:c+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 Xr=_(()=>{"use strict"});function B(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 Kr(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 Qr(r){return r==="float64"||r==="float32"}function w(r){return r==="int64"||r==="uint64"}function $(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(Qr(r)||Qr(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){let i=t;return i==="int32"||i==="int64"||i==="uint32"||i==="uint64"?"float64":"float32"}if(t==="float32"){let i=r;return i==="int32"||i==="int64"||i==="uint32"||i==="uint64"?"float64":"float32"}return"float32"}let e=r.startsWith("int"),n=t.startsWith("int"),o=r.startsWith("uint"),a=t.startsWith("uint"),c=i=>i.includes("64")?64:i.includes("32")?32:i.includes("16")?16:i.includes("8")?8:0,u=c(r),s=c(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&u===s){if(u===8)return"int16";if(u===16)return"int32";if(u===32)return"int64"}if(o&&n&&u===s){if(s===8)return"int16";if(s===16)return"int32";if(s===32)return"int64"}if(e&&n||o&&a){let i=Math.max(u,s);return e?i===64?"int64":i===32?"int32":i===16?"int16":"int8":i===64?"uint64":i===32?"uint32":i===16?"uint16":"uint8"}return e&&a?u>s?r:s===8?"int16":s===16?"int32":s===32?"int64":"float64":o&&n?s>u?t:u===8?"int16":u===16?"int32":u===32?"int64":"float64":"float64"}var v,C=_(()=>{"use strict";v="float64"});function R(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,P=_(()=>{"use strict";C();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,c=this._offset;for(let u=0;u<o;u++){let s=1;for(let l=u+1;l<o;l++)s*=e[l];let i=Math.floor(a/s);a=a%s,c+=i*n[u]}return this._data[c]}iset(t,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let c=t,u=this._offset;for(let s=0;s<a;s++){let i=1;for(let f=s+1;f<a;f++)i*=n[f];let l=Math.floor(c/i);c=c%i,u+=l*o[s]}this._data[u]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];return this._data[n]}set(t,e){let n=this._strides,o=this._offset;for(let a=0;a<t.length;a++)o+=t[a]*n[a];this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=B(e);if(!o)throw new Error(`Cannot copy array with dtype ${e}`);let a=new o(n);if(this.isCContiguous&&this._offset===0)if(w(e)){let c=this._data,u=a;for(let s=0;s<n;s++)u[s]=c[s]}else a.set(this._data);else if(w(e)){let c=a;for(let u=0;u<n;u++)c[u]=this.iget(u)}else for(let c=0;c<n;c++)a[c]=this.iget(c);return new r(a,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let c=o??r._computeStrides(e),u=a??0;return new r(t,e,c,u,n)}static zeros(t,e=v){let n=t.reduce((c,u)=>c*u,1),o=B(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((c,u)=>c*u,1),o=B(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return w(e)?a.fill(BigInt(1)):a.fill(1),new 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 rt(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let c=0;c<o;c++){let u=c<o-e?1:r[c-(o-e)],s=c<o-n?1:t[c-(o-n)];if(u===s)a[c]=u;else if(u===1)a[c]=s;else if(s===1)a[c]=u;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function Ye(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let c=0;c<n;c++){let u=o-n+c,s=r[c],i=e[u];if(s===i)a[u]=t[c];else if(s===1)a[u]=0;else throw new Error("Invalid broadcast")}return a}function ir(r,t){let e=Ye(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function V(r,t,e,n){let o=rt(r.shape,t.shape),a=ir(r,o),c=ir(t,o),u=$(r.dtype,t.dtype),s=D.zeros(o,u),i=s.data,l=s.size;if(w(u)){let f=i;for(let p=0;p<l;p++){let m=a.iget(p),y=c.iget(p),d=typeof m=="bigint"?m:BigInt(Math.round(m)),A=typeof y=="bigint"?y:BigInt(Math.round(y));n==="add"?f[p]=d+A:n==="subtract"?f[p]=d-A:n==="multiply"?f[p]=d*A:n==="divide"?f[p]=d/A:f[p]=BigInt(Math.round(e(Number(d),Number(A))))}}else{let f=w(r.dtype)||w(t.dtype);for(let p=0;p<l;p++){let m=a.iget(p),y=c.iget(p),d=Number(m),A=Number(y);i[p]=e(d,A)}}return s}function L(r,t,e){let n=rt(r.shape,t.shape),o=ir(r,n),a=ir(t,n),c=n.reduce((i,l)=>i*l,1),u=new Uint8Array(c),s=w(r.dtype)||w(t.dtype);for(let i=0;i<c;i++){let l=o.iget(i),f=a.iget(i),p=Number(l),m=Number(f);u[i]=e(p,m)?1:0}return D.fromData(u,n,"bool")}function M(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,u=e?n:n!=="float32"&&n!=="float64"?"float64":n,s=D.zeros(o,u),i=s.data,l=r.data;if(w(n))if(w(u)){let f=i;for(let p=0;p<a;p++){let m=Number(l[p]);f[p]=BigInt(Math.round(t(m)))}}else for(let f=0;f<a;f++)i[f]=t(Number(l[f]));else for(let f=0;f<a;f++)i[f]=t(Number(l[f]));return s}var H=_(()=>{"use strict";P();C()});function br(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function tt(r,t){return typeof t=="number"?Ke(r,t):br(r,t)?Je(r,t):V(r,t,(e,n)=>e+n,"add")}function Je(r,t){let e=$(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,c=t.data,u=n.data;if(w(e)){let s=u;if(!w(r.dtype)||!w(t.dtype))for(let l=0;l<o;l++){let f=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),p=typeof c[l]=="bigint"?c[l]:BigInt(Math.round(Number(c[l])));s[l]=f+p}else{let l=a,f=c;for(let p=0;p<o;p++)s[p]=l[p]+f[p]}}else if(w(r.dtype)||w(t.dtype))for(let i=0;i<o;i++){let l=typeof a[i]=="bigint"?Number(a[i]):a[i],f=typeof c[i]=="bigint"?Number(c[i]):c[i];u[i]=l+f}else for(let i=0;i<o;i++)u[i]=a[i]+c[i];return n}function et(r,t){return typeof t=="number"?rn(r,t):br(r,t)?Xe(r,t):V(r,t,(e,n)=>e-n,"subtract")}function Xe(r,t){let e=$(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,c=t.data,u=n.data;if(w(e)){let s=u;if(!w(r.dtype)||!w(t.dtype))for(let l=0;l<o;l++){let f=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),p=typeof c[l]=="bigint"?c[l]:BigInt(Math.round(Number(c[l])));s[l]=f-p}else{let l=a,f=c;for(let p=0;p<o;p++)s[p]=l[p]-f[p]}}else if(w(r.dtype)||w(t.dtype))for(let i=0;i<o;i++){let l=typeof a[i]=="bigint"?Number(a[i]):a[i],f=typeof c[i]=="bigint"?Number(c[i]):c[i];u[i]=l-f}else for(let i=0;i<o;i++)u[i]=a[i]-c[i];return n}function nt(r,t){return typeof t=="number"?tn(r,t):br(r,t)?Qe(r,t):V(r,t,(e,n)=>e*n,"multiply")}function Qe(r,t){let e=$(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,c=t.data,u=n.data;if(w(e)){let s=u;if(!w(r.dtype)||!w(t.dtype))for(let l=0;l<o;l++){let f=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),p=typeof c[l]=="bigint"?c[l]:BigInt(Math.round(Number(c[l])));s[l]=f*p}else{let l=a,f=c;for(let p=0;p<o;p++)s[p]=l[p]*f[p]}}else if(w(r.dtype)||w(t.dtype))for(let i=0;i<o;i++){let l=typeof a[i]=="bigint"?Number(a[i]):a[i],f=typeof c[i]=="bigint"?Number(c[i]):c[i];u[i]=l*f}else for(let i=0;i<o;i++)u[i]=a[i]*c[i];return n}function ot(r,t){if(typeof t=="number")return en(r,t);let e=r.dtype==="float64",n=t.dtype==="float64",o=r.dtype==="float32",a=t.dtype==="float32";if(e||n){let s=e?r:G(r,"float64"),i=n?t:G(t,"float64");return V(s,i,(l,f)=>l/f,"divide")}if(o||a){let s=o?r:G(r,"float32"),i=a?t:G(t,"float32");return V(s,i,(l,f)=>l/f,"divide")}let c=G(r,"float64"),u=G(t,"float64");return V(c,u,(s,i)=>s/i,"divide")}function G(r,t){let e=D.zeros(Array.from(r.shape),t),n=r.size,o=r.data,a=e.data;for(let c=0;c<n;c++)a[c]=Number(o[c]);return e}function Ke(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=D.zeros(n,e),u=c.data;if(w(e)){let s=o,i=u,l=BigInt(Math.round(t));for(let f=0;f<a;f++)i[f]=s[f]+l}else for(let s=0;s<a;s++)u[s]=Number(o[s])+t;return c}function rn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=D.zeros(n,e),u=c.data;if(w(e)){let s=o,i=u,l=BigInt(Math.round(t));for(let f=0;f<a;f++)i[f]=s[f]-l}else for(let s=0;s<a;s++)u[s]=Number(o[s])-t;return c}function tn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=D.zeros(n,e),u=c.data;if(w(e)){let s=o,i=u,l=BigInt(Math.round(t));for(let f=0;f<a;f++)i[f]=s[f]*l}else for(let s=0;s<a;s++)u[s]=Number(o[s])*t;return c}function en(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e!=="float32"&&e!=="float64"?"float64":e,s=D.zeros(n,u),i=s.data;if(w(e))for(let l=0;l<a;l++)i[l]=Number(o[l])/t;else for(let l=0;l<a;l++)i[l]=Number(o[l])/t;return s}function at(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),c=a.data;if(w(t)){let u=n,s=c;for(let i=0;i<o;i++){let l=u[i];s[i]=l<0n?-l:l}}else for(let u=0;u<o;u++)c[u]=Math.abs(Number(n[u]));return a}function st(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),c=a.data;if(w(t)){let u=n,s=c;for(let i=0;i<o;i++)s[i]=-u[i]}else for(let u=0;u<o;u++)c[u]=-Number(n[u]);return a}function it(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),c=a.data;if(w(t)){let u=n,s=c;for(let i=0;i<o;i++){let l=u[i];s[i]=l>0n?1n:l<0n?-1n:0n}}else for(let u=0;u<o;u++){let s=Number(n[u]);c[u]=s>0?1:s<0?-1:0}return a}function ut(r,t){return typeof t=="number"?nn(r,t):V(r,t,(e,n)=>(e%n+n)%n,"mod")}function nn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=D.zeros(n,e),u=c.data;if(w(e)){let s=o,i=u,l=BigInt(Math.round(t));for(let f=0;f<a;f++){let p=s[f];i[f]=(p%l+l)%l}}else for(let s=0;s<a;s++){let i=Number(o[s]);u[s]=(i%t+t)%t}return c}function ct(r,t){return typeof t=="number"?on(r,t):V(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function on(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=D.zeros(n,e),u=c.data;if(w(e)){let s=o,i=u,l=BigInt(Math.round(t));for(let f=0;f<a;f++)i[f]=s[f]/l}else for(let s=0;s<a;s++)u[s]=Math.floor(Number(o[s])/t);return c}function lt(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),c=a.data;for(let u=0;u<o;u++)c[u]=n[u];return a}function ft(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,c=t!=="float32"&&t!=="float64"?"float64":t,u=D.zeros(e,c),s=u.data;if(w(t))for(let i=0;i<o;i++)s[i]=1/Number(n[i]);else for(let i=0;i<o;i++)s[i]=1/Number(n[i]);return u}var pt=_(()=>{"use strict";P();C();H()});function yt(r,t){return typeof t=="number"?sn(r,t):L(r,t,(e,n)=>e>n)}function mt(r,t){return typeof t=="number"?un(r,t):L(r,t,(e,n)=>e>=n)}function dt(r,t){return typeof t=="number"?cn(r,t):L(r,t,(e,n)=>e<n)}function gt(r,t){return typeof t=="number"?ln(r,t):L(r,t,(e,n)=>e<=n)}function ht(r,t){return typeof t=="number"?fn(r,t):L(r,t,(e,n)=>e===n)}function At(r,t){return typeof t=="number"?pn(r,t):L(r,t,(e,n)=>e!==n)}function Sr(r,t,e=1e-5,n=1e-8){return typeof t=="number"?yn(r,t,e,n):L(r,t,(o,a)=>{let c=Math.abs(o-a),u=n+e*Math.abs(a);return c<=u})}function bt(r,t,e=1e-5,n=1e-8){let o=Sr(r,t,e,n),a=o.data;for(let c=0;c<o.size;c++)if(a[c]===0)return!1;return!0}function sn(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 un(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 cn(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 ln(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 fn(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(w(o)){let a=BigInt(Math.round(t)),c=n;for(let u=0;u<r.size;u++)e[u]=c[u]===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 pn(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 yn(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,c=r.dtype;if(w(c)){let u=a;for(let s=0;s<r.size;s++){let i=Number(u[s]),l=Math.abs(i-t),f=n+e*Math.abs(t);o[s]=l<=f?1:0}}else for(let u=0;u<r.size;u++){let s=Number(a[u]),i=Math.abs(s-t),l=n+e*Math.abs(t);o[u]=i<=l?1:0}return D.fromData(o,Array.from(r.shape),"bool")}var St=_(()=>{"use strict";P();C();H()});function E(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),c=Array.from(n).filter((s,i)=>i!==t),u=r;for(let s=c.length-1;s>=0;s--)a[s>=t?s+1:s]=u%c[s],u=Math.floor(u/c[s]);return a[t]=e,a}var Dt=_(()=>{"use strict"});function Q(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,c=r.size,u=r.data;if(t===void 0)if(w(n)){let y=u,d=BigInt(0);for(let A=0;A<c;A++)d+=y[A];return Number(d)}else{let y=0;for(let d=0;d<c;d++)y+=Number(u[d]);return y}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((y,d)=>d!==s);if(i.length===0)return Q(r);let l=D.zeros(i,n),f=l.data,p=o[s],m=i.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=f;for(let A=0;A<m;A++){let h=BigInt(0);for(let g=0;g<p;g++){let b=T(A,s,g,o),S=E(b,o);h+=y[S]}d[A]=h}}else for(let y=0;y<m;y++){let d=0;for(let A=0;A<p;A++){let h=T(y,s,A,o),g=E(h,o);d+=Number(u[g])}f[y]=d}if(e){let y=[...o];return y[s]=1,D.fromData(f,y,n)}return l}function Dr(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return Q(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 c=Q(r,t,e);if(typeof c=="number")return c/o[a];let u=o[a],s=n;(w(n)||n.startsWith("int")||n.startsWith("uint"))&&(s="float64");let i=D.zeros(Array.from(c.shape),s),l=i.data,f=c.data;if(w(n)){let p=f;for(let m=0;m<l.length;m++)l[m]=Number(p[m])/u}else for(let p=0;p<l.length;p++)l[p]=Number(f[p])/u;return i}function wr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,c=r.size,u=r.data;if(t===void 0){if(c===0)throw new Error("max of empty array");let y=u[0];for(let d=1;d<c;d++)u[d]>y&&(y=u[d]);return Number(y)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((y,d)=>d!==s);if(i.length===0)return wr(r);let l=D.zeros(i,n),f=l.data,p=o[s],m=i.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=f;for(let A=0;A<m;A++){let h=T(A,s,0,o),g=E(h,o),b=y[g];for(let S=1;S<p;S++){let x=T(A,s,S,o),N=E(x,o),O=y[N];O>b&&(b=O)}d[A]=b}}else for(let y=0;y<m;y++){let d=-1/0;for(let A=0;A<p;A++){let h=T(y,s,A,o),g=E(h,o),b=Number(u[g]);b>d&&(d=b)}f[y]=d}if(e){let y=[...o];return y[s]=1,D.fromData(f,y,n)}return l}function Nr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,c=r.size,u=r.data;if(t===void 0)if(w(n)){let y=u,d=BigInt(1);for(let A=0;A<c;A++)d*=y[A];return Number(d)}else{let y=1;for(let d=0;d<c;d++)y*=Number(u[d]);return y}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((y,d)=>d!==s);if(i.length===0)return Nr(r);let l=D.zeros(i,n),f=l.data,p=o[s],m=i.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=f;for(let A=0;A<m;A++){let h=BigInt(1);for(let g=0;g<p;g++){let b=T(A,s,g,o),S=E(b,o);h*=y[S]}d[A]=h}}else for(let y=0;y<m;y++){let d=1;for(let A=0;A<p;A++){let h=T(y,s,A,o),g=E(h,o);d*=Number(u[g])}f[y]=d}if(e){let y=[...o];return y[s]=1,D.fromData(f,y,n)}return l}function xr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,c=r.size,u=r.data;if(t===void 0){if(c===0)throw new Error("min of empty array");let y=u[0];for(let d=1;d<c;d++)u[d]<y&&(y=u[d]);return Number(y)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=Array.from(o).filter((y,d)=>d!==s);if(i.length===0)return xr(r);let l=D.zeros(i,n),f=l.data,p=o[s],m=i.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=f;for(let A=0;A<m;A++){let h=T(A,s,0,o),g=E(h,o),b=y[g];for(let S=1;S<p;S++){let x=T(A,s,S,o),N=E(x,o),O=y[N];O<b&&(b=O)}d[A]=b}}else for(let y=0;y<m;y++){let d=1/0;for(let A=0;A<p;A++){let h=T(y,s,A,o),g=E(h,o),b=Number(u[g]);b<d&&(d=b)}f[y]=d}if(e){let y=[...o];return y[s]=1,D.fromData(f,y,n)}return l}function Ir(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,c=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let m=c[0],y=0;for(let d=1;d<a;d++)c[d]<m&&(m=c[d],y=d);return y}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((m,y)=>y!==u);if(s.length===0)return Ir(r);let i=D.zeros(s,"int32"),l=i.data,f=n[u],p=s.reduce((m,y)=>m*y,1);if(w(e)){let m=c;for(let y=0;y<p;y++){let d=T(y,u,0,n),A=E(d,n),h=m[A],g=0;for(let b=1;b<f;b++){let S=T(y,u,b,n),x=E(S,n),N=m[x];N<h&&(h=N,g=b)}l[y]=g}}else for(let m=0;m<p;m++){let y=1/0,d=0;for(let A=0;A<f;A++){let h=T(m,u,A,n),g=E(h,n),b=Number(c[g]);b<y&&(y=b,d=A)}l[m]=d}return i}function zr(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,c=r.data;if(t===void 0){if(a===0)throw new Error("argmax of empty array");let m=c[0],y=0;for(let d=1;d<a;d++)c[d]>m&&(m=c[d],y=d);return y}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((m,y)=>y!==u);if(s.length===0)return zr(r);let i=D.zeros(s,"int32"),l=i.data,f=n[u],p=s.reduce((m,y)=>m*y,1);if(w(e)){let m=c;for(let y=0;y<p;y++){let d=T(y,u,0,n),A=E(d,n),h=m[A],g=0;for(let b=1;b<f;b++){let S=T(y,u,b,n),x=E(S,n),N=m[x];N>h&&(h=N,g=b)}l[y]=g}}else for(let m=0;m<p;m++){let y=-1/0,d=0;for(let A=0;A<f;A++){let h=T(m,u,A,n),g=E(h,n),b=Number(c[g]);b>y&&(y=b,d=A)}l[m]=d}return i}function Br(r,t,e=0,n=!1){let o=r.shape,a=o.length,c=r.size,u=r.data,s=Dr(r,t,n);if(t===void 0){let h=s,g=0;for(let b=0;b<c;b++){let S=Number(u[b])-h;g+=S*S}return g/(c-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 l=o[i],f=s,p=f.data,m=n?f.shape:Array.from(o).filter((h,g)=>g!==i),y=D.zeros(Array.from(m),"float64"),d=y.data,A=m.reduce((h,g)=>h*g,1);for(let h=0;h<A;h++){let g=0,b=Number(p[h]);for(let S=0;S<l;S++){let x=T(h,i,S,o),N=E(x,o),O=Number(u[N])-b;g+=O*O}d[h]=g/(l-e)}return y}function wt(r,t,e=0,n=!1){let o=Br(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=D.zeros(Array.from(o.shape),"float64"),c=o.data,u=a.data;for(let s=0;s<c.length;s++)u[s]=Math.sqrt(Number(c[s]));return a}function Ur(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,c=r.data;if(t===void 0){for(let m=0;m<a;m++)if(!c[m])return!1;return!0}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((m,y)=>y!==u);if(s.length===0)return Ur(r);let i=D.zeros(s,"bool"),l=i.data,f=n[u],p=s.reduce((m,y)=>m*y,1);for(let m=0;m<p;m++){let y=!0;for(let d=0;d<f;d++){let A=T(m,u,d,n),h=E(A,n);if(!c[h]){y=!1;break}}l[m]=y?1:0}if(e){let m=[...n];return m[u]=1,D.fromData(l,m,"bool")}return i}function _r(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,c=r.data;if(t===void 0){for(let m=0;m<a;m++)if(c[m])return!0;return!1}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((m,y)=>y!==u);if(s.length===0)return _r(r);let i=D.zeros(s,"bool"),l=i.data,f=n[u],p=s.reduce((m,y)=>m*y,1);for(let m=0;m<p;m++){let y=!1;for(let d=0;d<f;d++){let A=T(m,u,d,n),h=E(A,n);if(c[h]){y=!0;break}}l[m]=y?1:0}if(e){let m=[...n];return m[u]=1,D.fromData(l,m,"bool")}return i}var Nt=_(()=>{"use strict";P();C();Dt()});function Y(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let i=t.reduce((f,p,m)=>m===o?f:f*p,1),l=e/i;if(!Number.isInteger(l))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((f,p)=>p===o?l:f)}else a=t;if(a.reduce((i,l)=>i*l,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){let i=r.data;return D.fromData(i,a,n,R(a),0)}let s=r.copy().data;return D.fromData(s,a,n,R(a),0)}function Er(r){let t=r.size,e=r.dtype,n=B(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let u=r.data.slice(r.offset,r.offset+t);return D.fromData(u,[t],e,[1],0)}let o=new n(t),a=w(e);for(let c=0;c<t;c++){let u=r.iget(c);o[c]=u}return D.fromData(o,[t],e,[1],0)}function rr(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return D.fromData(n,[t],e,[1],0)}return Er(r)}function ur(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,c=r.dtype,u;if(t===void 0)u=Array.from({length:n},(f,p)=>n-1-p);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let f=new Set;for(let p of t){let m=p<0?n+p:p;if(m<0||m>=n)throw new Error(`axis ${p} is out of bounds for array of dimension ${n}`);if(f.has(m))throw new Error("repeated axis in transpose");f.add(m)}u=t.map(p=>p<0?n+p:p)}let s=u.map(f=>e[f]),i=Array.from(o),l=u.map(f=>i[f]);return D.fromData(a,s,c,l,r.offset)}function xt(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,c=r.dtype;if(t===void 0){let u=[],s=[];for(let i=0;i<n;i++)e[i]!==1&&(u.push(e[i]),s.push(o[i]));return u.length===0&&(u.push(1),s.push(1)),D.fromData(a,u,c,s,r.offset)}else{let u=t<0?n+t:t;if(u<0||u>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[u]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[u]})`);let s=[],i=[];for(let l=0;l<n;l++)l!==u&&(s.push(e[l]),i.push(o[l]));return D.fromData(a,s,c,i,r.offset)}}function K(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,c=r.dtype,u=t;if(u<0&&(u=n+t+1),u<0||u>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let s=[...Array.from(e)];s.splice(u,0,1);let i=[...Array.from(o)],l=u<n?o[u]*(e[u]||1):1;return i.splice(u,0,l),D.fromData(a,s,c,i,r.offset)}function It(r,t,e){let n=r.shape,o=n.length,a=r.strides,c=r.data,u=r.dtype,s=t<0?o+t:t,i=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${o}`);if(i<0||i>=o)throw new Error(`axis2 ${e} is out of bounds for array of dimension ${o}`);if(s===i)return D.fromData(c,Array.from(n),u,Array.from(a),r.offset);let l=Array.from(n),f=Array.from(a);return[l[s],l[i]]=[l[i],l[s]],[f[s],f[i]]=[f[i],f[s]],D.fromData(c,l,u,f,r.offset)}function zt(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 c=o.map(i=>{let l=i<0?n+i:i;if(l<0||l>=n)throw new Error(`source axis ${i} is out of bounds for array of dimension ${n}`);return l}),u=a.map(i=>{let l=i<0?n+i:i;if(l<0||l>=n)throw new Error(`destination axis ${i} is out of bounds for array of dimension ${n}`);return l});if(new Set(c).size!==c.length)throw new Error("repeated axis in source");if(new Set(u).size!==u.length)throw new Error("repeated axis in destination");let s=[];for(let i=0;i<n;i++)c.includes(i)||s.push(i);for(let i=0;i<c.length;i++){let l=u[i];s.splice(l,0,c[i])}return ur(r,s)}function Z(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 m=1;m<r.length;m++){let y=r[m];if(y.ndim!==n)throw new Error("all the input arrays must have same number of dimensions");for(let d=0;d<n;d++)if(d!==a&&y.shape[d]!==e.shape[d])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}let c=Array.from(e.shape),u=e.shape[a];for(let m=1;m<r.length;m++)u+=r[m].shape[a];c[a]=u;let s=c.reduce((m,y)=>m*y,1),i=B(o);if(!i)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new i(s),f=R(c),p=0;for(let m of r){let y=m.shape[a];gn(m,l,c,f,a,p,o),p+=y}return D.fromData(l,c,o)}function gn(r,t,e,n,o,a,c){let u=r.shape,s=u.length,i=r.size,l=c==="int64"||c==="uint64";if(o===0&&r.isCContiguous&&s>0){let p=a*n[0],m=r.data,y=r.offset,d=y+i;t.set(m.subarray(y,d),p);return}let f=new Array(s).fill(0);for(let p=0;p<i;p++){let m=r.iget(p),y=[...f];y[o]+=a;let d=0;for(let A=0;A<s;A++)d+=y[A]*n[A];t[d]=m;for(let A=s-1;A>=0&&(f[A]++,!(f[A]<u[A]));A--)f[A]=0}}function Bt(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let u=1;u<r.length;u++){let s=r[u];if(s.ndim!==o)throw new Error("all input arrays must have the same shape");for(let i=0;i<o;i++)if(s.shape[i]!==n[i])throw new Error("all input arrays must have the same shape")}let c=r.map(u=>K(u,a));return Z(c,a)}function Ut(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?Y(e,[1,e.shape[0]]):e);return Z(t,0)}function _t(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?Z(r,0):Z(r,1)}function Et(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?Y(K(Y(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?K(e,2):e);return Z(t,2)}function Tt(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 c=n[a],u;if(typeof t=="number"){if(c%t!==0)throw new Error("array split does not result in an equal division");let s=c/t;u=[];for(let i=1;i<t;i++)u.push(i*s)}else u=t;return Ot(r,u,a)}function cr(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 c=n[a],u;if(typeof t=="number"){let s=t,i=Math.floor(c/s),l=c%s;u=[];let f=0;for(let p=0;p<s-1;p++)f+=i+(p<l?1:0),u.push(f)}else u=t;return Ot(r,u,a)}function Ot(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],c=[];for(let u=0;u<a.length-1;u++){let s=a[u],i=a[u+1];if(s>i)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=i-s;let f=r.offset+s*r.strides[e];c.push(D.fromData(r.data,l,r.dtype,Array.from(r.strides),f))}return c}function $t(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return cr(r,t,0)}function Mt(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 cr(r,t,e)}function vt(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],c=Math.max(n,a.length),u=new Array(c).fill(1),s=new Array(c).fill(1);for(let g=0;g<n;g++)u[c-n+g]=e[g];for(let g=0;g<a.length;g++)s[c-a.length+g]=a[g];let i=u.map((g,b)=>g*s[b]),l=i.reduce((g,b)=>g*b,1),f=B(o);if(!f)throw new Error(`Cannot tile array with dtype ${o}`);let p=new f(l),m=R(i),y=r;n<c&&(y=Y(r,u));let d=o==="int64"||o==="uint64",A=y.strides,h=new Array(c).fill(0);for(let g=0;g<l;g++){let b=y.offset;for(let N=0;N<c;N++){let O=h[N]%u[N];b+=O*A[N]}let S=y.data[b],x=0;for(let N=0;N<c;N++)x+=h[N]*m[N];p[x]=S;for(let N=c-1;N>=0&&(h[N]++,!(h[N]<i[N]));N--)h[N]=0}return D.fromData(p,i,o)}function Ct(r,t,e){let n=r.shape,o=n.length,a=r.dtype,c=r.size;if(e===void 0){let g=c,b=Array.isArray(t)?t:new Array(g).fill(t);if(b.length!==g)throw new Error(`operands could not be broadcast together with shape (${g},) (${b.length},)`);let S=b.reduce((I,U)=>I+U,0),x=B(a);if(!x)throw new Error(`Cannot repeat array with dtype ${a}`);let N=new x(S),O=0;for(let I=0;I<g;I++){let U=r.iget(I),sr=b[I];for(let Wr=0;Wr<sr;Wr++)N[O++]=U}return D.fromData(N,[S],a)}let u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u],i=Array.isArray(t)?t:new Array(s).fill(t);if(i.length!==s)throw new Error(`operands could not be broadcast together with shape (${s},) (${i.length},)`);let l=Array.from(n);l[u]=i.reduce((g,b)=>g+b,0);let f=l.reduce((g,b)=>g*b,1),p=B(a);if(!p)throw new Error(`Cannot repeat array with dtype ${a}`);let m=new p(f),y=R(l),d=new Array(o).fill(0),A=a==="int64"||a==="uint64",h=[0];for(let g=0;g<s;g++)h.push(h[g]+i[g]);for(let g=0;g<c;g++){let b=r.iget(g),S=d[u],x=i[S],N=0;for(let U=0;U<o;U++)U!==u&&(N+=d[U]*y[U]);let O=y[u],I=h[S];for(let U=0;U<x;U++){let sr=N+(I+U)*O;m[sr]=b}for(let U=o-1;U>=0&&(d[U]++,!(d[U]<n[U]));U--)d[U]=0}return D.fromData(m,l,a)}var Tr=_(()=>{"use strict";P();C()});function hn(r,t,e,n,o,a,c,u,s,i,l,f,p,m){if(f===0)for(let h=0;h<n*o;h++)p[h]=0;else if(f!==1)for(let h=0;h<n*o;h++)p[h]=(p[h]??0)*f;let y=r==="row-major",d=t==="transpose",A=e==="transpose";if(y&&!d&&!A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[h*s+S]??0)*(i[S*l+g]??0);p[h*m+g]=(p[h*m+g]??0)+c*b}else if(y&&d&&!A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[S*s+h]??0)*(i[S*l+g]??0);p[h*m+g]=(p[h*m+g]??0)+c*b}else if(y&&!d&&A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[h*s+S]??0)*(i[g*l+S]??0);p[h*m+g]=(p[h*m+g]??0)+c*b}else if(y&&d&&A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[S*s+h]??0)*(i[g*l+S]??0);p[h*m+g]=(p[h*m+g]??0)+c*b}else if(!y&&!d&&!A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[S*s+h]??0)*(i[g*l+S]??0);p[g*m+h]=(p[g*m+h]??0)+c*b}else if(!y&&d&&!A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[h*s+S]??0)*(i[g*l+S]??0);p[g*m+h]=(p[g*m+h]??0)+c*b}else if(!y&&!d&&A)for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[S*s+h]??0)*(i[S*l+g]??0);p[g*m+h]=(p[g*m+h]??0)+c*b}else for(let h=0;h<n;h++)for(let g=0;g<o;g++){let b=0;for(let S=0;S<a;S++)b+=(u[h*s+S]??0)*(i[S*l+g]??0);p[g*m+h]=(p[g*m+h]??0)+c*b}}function Or(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 c=$(r.dtype,t.dtype),u=D.zeros([...t.shape],c);for(let s=0;s<t.size;s++){let i=t.data[s+t.offset];typeof o=="bigint"&&typeof i=="bigint"?u.data[s]=o*i:u.data[s]=Number(o)*Number(i)}return u}else{let c=$(r.dtype,t.dtype),u=D.zeros([...r.shape],c);for(let s=0;s<r.size;s++){let i=r.data[s+r.offset];typeof i=="bigint"&&typeof a=="bigint"?u.data[s]=i*a:u.data[s]=Number(i)*Number(a)}return u}}if(e===1&&n===1){if(r.shape[0]!==t.shape[0])throw new Error(`dot: incompatible shapes (${r.shape[0]},) and (${t.shape[0]},)`);let o=r.shape[0],a=0;for(let c=0;c<o;c++){let u=r.get(c),s=t.get(c);typeof u=="bigint"&&typeof s=="bigint"?a=Number(a)+Number(u*s):a+=Number(u)*Number(s)}return a}if(e===2&&n===2)return $r(r,t);if(e===2&&n===1){let[o,a]=r.shape,c=t.shape[0];if(a!==c)throw new Error(`dot: incompatible shapes (${o},${a}) and (${c},)`);let u=$(r.dtype,t.dtype),s=D.zeros([o],u);for(let i=0;i<o;i++){let l=0;for(let f=0;f<a;f++){let p=r.get(i,f),m=t.get(f);typeof p=="bigint"&&typeof m=="bigint"?l=Number(l)+Number(p*m):l+=Number(p)*Number(m)}s.set([i],l)}return s}if(e===1&&n===2){let o=r.shape[0],[a,c]=t.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${c})`);let u=$(r.dtype,t.dtype),s=D.zeros([c],u);for(let i=0;i<c;i++){let l=0;for(let f=0;f<o;f++){let p=r.get(f),m=t.get(f,i);typeof p=="bigint"&&typeof m=="bigint"?l=Number(l)+Number(p*m):l+=Number(p)*Number(m)}s.set([i],l)}return s}if(e>2&&n===1){let o=r.shape[e-1],a=t.shape[0];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and (${a},)`);let c=[...r.shape.slice(0,-1)],u=$(r.dtype,t.dtype),s=D.zeros(c,u),i=c.reduce((l,f)=>l*f,1);for(let l=0;l<i;l++){let f=0,p=l,m=[];for(let y=c.length-1;y>=0;y--)m[y]=p%c[y],p=Math.floor(p/c[y]);for(let y=0;y<o;y++){let d=[...m,y],A=r.get(...d),h=t.get(y);typeof A=="bigint"&&typeof h=="bigint"?f=Number(f)+Number(A*h):f+=Number(A)*Number(h)}s.set(m,f)}return s}if(e===1&&n>2){let o=r.shape[0],a=1,c=t.shape[a];if(o!==c)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(t.shape)}`);let u=[...t.shape.slice(0,a),...t.shape.slice(a+1)],s=$(r.dtype,t.dtype),i=D.zeros(u,s),l=u.reduce((f,p)=>f*p,1);for(let f=0;f<l;f++){let p=f,m=[];for(let h=u.length-1;h>=0;h--)m[h]=p%u[h],p=Math.floor(p/u[h]);let y=m.slice(0,a),d=m.slice(a),A=0;for(let h=0;h<o;h++){let g=r.get(h),b=[...y,h,...d],S=t.get(...b);typeof g=="bigint"&&typeof S=="bigint"?A=Number(A)+Number(g*S):A+=Number(g)*Number(S)}i.set(m,A)}return i}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 c=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],u=$(r.dtype,t.dtype),s=D.zeros(c,u),i=r.shape.slice(0,-1).reduce((m,y)=>m*y,1),l=t.shape.slice(0,-2).reduce((m,y)=>m*y,1),f=t.shape[n-1],p=o;for(let m=0;m<i;m++)for(let y=0;y<l;y++)for(let d=0;d<f;d++){let A=0;for(let g=0;g<p;g++){let b=m*p+g,S=r.data[b+r.offset],x=y*p*f+g*f+d,N=t.data[x+t.offset];typeof S=="bigint"&&typeof N=="bigint"?A=Number(A)+Number(S*N):A+=Number(S)*Number(N)}let h=m*l*f+y*f+d;s.data[h]=A}return s}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function $r(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 c=$(r.dtype,t.dtype),u=c.startsWith("int")||c.startsWith("uint")||c==="bool"?"float64":c;if(u!=="float64")throw new Error(`matmul currently only supports float64, got ${u}`);let s=r.dtype==="float64"?r.data:Float64Array.from(Array.from(r.data).map(Number)),i=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number));r.offset>0&&(s=s.subarray(r.offset)),t.offset>0&&(i=i.subarray(t.offset));let[l=0,f=0]=r.strides,[p=0,m=0]=t.strides,y=f>l,d=m>p,A=y?"transpose":"no-transpose",h=d?"transpose":"no-transpose",g,b;y?g=f:g=l,d?b=m:b=p;let S=D.zeros([e,a],"float64");return hn("row-major",A,h,e,a,n,1,s,g,i,b,0,S.data,a),S}function Pt(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 c=r.get(a,a);typeof c=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+c:o=(typeof o=="bigint"?Number(o):o)+c}return o}function Vt(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 Or(r,t);let c=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],u=$(r.dtype,t.dtype),s=D.zeros(c,u),i=e===1?1:r.shape.slice(0,-1).reduce((p,m)=>p*m,1),l=n===1?1:t.shape.slice(0,-1).reduce((p,m)=>p*m,1),f=o;for(let p=0;p<i;p++)for(let m=0;m<l;m++){let y=0;for(let A=0;A<f;A++){let h=e===1?A:p*f+A,g=n===1?A:m*f+A,b=r.data[h+r.offset],S=t.data[g+t.offset];typeof b=="bigint"&&typeof S=="bigint"?y=Number(y)+Number(b*S):y+=Number(b)*Number(S)}if(c.length===0)return y;let d=i===1?m:p*l+m;s.data[d]=y}return s}function Ft(r,t){let e=r.ndim===1?r:rr(r),n=t.ndim===1?t:rr(t),o=e.size,a=n.size,c=$(r.dtype,t.dtype),u=D.zeros([o,a],c);for(let s=0;s<o;s++)for(let i=0;i<a;i++){let l=e.get(s),f=n.get(i),p;typeof l=="bigint"&&typeof f=="bigint"?p=l*f:p=Number(l)*Number(f),u.set([s,i],p)}return u}function Rt(r,t,e){let n,o;if(typeof e=="number"){let p=e;if(p<0)throw new Error("tensordot: axes must be non-negative");if(p>r.ndim||p>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:p},(m,y)=>r.ndim-p+y),o=Array.from({length:p},(m,y)=>y)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let p=0;p<n.length;p++){let m=n[p],y=o[p];if(m<0||m>=r.ndim||y<0||y>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[m]!==t.shape[y])throw new Error(`tensordot: shape mismatch on axes ${m} and ${y}: ${r.shape[m]} != ${t.shape[y]}`)}let a=[],c=[];for(let p=0;p<r.ndim;p++)n.includes(p)||a.push(p);for(let p=0;p<t.ndim;p++)o.includes(p)||c.push(p);let u=[...a.map(p=>r.shape[p]),...c.map(p=>t.shape[p])];if(u.length===0){let p=0,m=n.map(y=>r.shape[y]).reduce((y,d)=>y*d,1);for(let y=0;y<m;y++){let d=y,A=new Array(n.length);for(let x=n.length-1;x>=0;x--){let N=n[x];A[x]=d%r.shape[N],d=Math.floor(d/r.shape[N])}let h=new Array(r.ndim),g=new Array(t.ndim);for(let x=0;x<n.length;x++)h[n[x]]=A[x];for(let x=0;x<o.length;x++)g[o[x]]=A[x];let b=r.get(...h),S=t.get(...g);typeof b=="bigint"&&typeof S=="bigint"?p=Number(p)+Number(b*S):p+=Number(b)*Number(S)}return p}let s=$(r.dtype,t.dtype),i=D.zeros(u,s),l=u.reduce((p,m)=>p*m,1),f=n.map(p=>r.shape[p]).reduce((p,m)=>p*m,1);for(let p=0;p<l;p++){let m=p,y=[];for(let g=u.length-1;g>=0;g--)y[g]=m%u[g],m=Math.floor(m/u[g]);let d=y.slice(0,a.length),A=y.slice(a.length),h=0;for(let g=0;g<f;g++){m=g;let b=[];for(let I=n.length-1;I>=0;I--){let U=n[I];b[I]=m%r.shape[U],m=Math.floor(m/r.shape[U])}let S=new Array(r.ndim),x=new Array(t.ndim);for(let I=0;I<a.length;I++)S[a[I]]=d[I];for(let I=0;I<c.length;I++)x[c[I]]=A[I];for(let I=0;I<n.length;I++)S[n[I]]=b[I],x[o[I]]=b[I];let N=r.get(...S),O=t.get(...x);typeof N=="bigint"&&typeof O=="bigint"?h=Number(h)+Number(N*O):h+=Number(N)*Number(O)}i.set(y,h)}return i}var Lt=_(()=>{"use strict";P();C();Tr()});function qt(r){return M(r,Math.sqrt,!1)}function jt(r,t){return typeof t=="number"?bn(r,t):V(r,t,Math.pow,"power")}function bn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,i=D.zeros(n,s),l=i.data;if(w(e))if(w(s)&&Number.isInteger(t)&&t>=0){let f=o,p=l;for(let m=0;m<a;m++)p[m]=f[m]**BigInt(t)}else for(let f=0;f<a;f++)l[f]=Math.pow(Number(o[f]),t);else for(let f=0;f<a;f++)l[f]=Math.pow(Number(o[f]),t);return i}var Zt=_(()=>{"use strict";P();H();C()});function Wt(r){return M(r,Math.sin,!1)}function Ht(r){return M(r,Math.cos,!1)}function Gt(r){return M(r,Math.tan,!1)}function Yt(r){return M(r,Math.asin,!1)}function Jt(r){return M(r,Math.acos,!1)}function Xt(r){return M(r,Math.atan,!1)}function Qt(r,t){return typeof t=="number"?wn(r,t):Dn(r,t)}function Dn(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,c=o==="float32"&&a==="float32"?"float32":"float64",u=D.zeros(e,c),s=u.data;for(let i=0;i<n;i++){let l=(w(o),Number(r.data[i])),f=(w(a),Number(t.data[i]));s[i]=Math.atan2(l,f)}return u}function wn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=e==="float32"?"float32":"float64",u=D.zeros(n,c),s=u.data;if(w(e))for(let i=0;i<a;i++)s[i]=Math.atan2(Number(o[i]),t);else for(let i=0;i<a;i++)s[i]=Math.atan2(Number(o[i]),t);return u}function Kt(r,t){return typeof t=="number"?xn(r,t):Nn(r,t)}function Nn(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,c=o==="float32"&&a==="float32"?"float32":"float64",u=D.zeros(e,c),s=u.data;for(let i=0;i<n;i++){let l=(w(o),Number(r.data[i])),f=(w(a),Number(t.data[i]));s[i]=Math.hypot(l,f)}return u}function xn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,c=e==="float32"?"float32":"float64",u=D.zeros(n,c),s=u.data;if(w(e))for(let i=0;i<a;i++)s[i]=Math.hypot(Number(o[i]),t);else for(let i=0;i<a;i++)s[i]=Math.hypot(Number(o[i]),t);return u}function re(r){let t=180/Math.PI;return M(r,e=>e*t,!1)}function te(r){let t=Math.PI/180;return M(r,e=>e*t,!1)}var ee=_(()=>{"use strict";P();H();C()});function ne(r){return M(r,Math.sinh,!1)}function oe(r){return M(r,Math.cosh,!1)}function ae(r){return M(r,Math.tanh,!1)}function se(r){return M(r,Math.asinh,!1)}function ie(r){return M(r,Math.acosh,!1)}function ue(r){return M(r,Math.atanh,!1)}var ce=_(()=>{"use strict";H()});function lr(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 c=a.length-t+n,u=c<0?1:a[c];if(u!==1){if(o===1)o=u;else if(o!==u)return null}}e[n]=o}return e}function Bn(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let c=0;c<n;c++){let u=o-n+c,s=r[c],i=e[u];if(s===i)a[u]=t[c];else if(s===1)a[u]=0;else throw new Error("Invalid broadcast")}return a}function tr(r,t){let e=Bn(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}var le=_(()=>{"use strict";P()});function fe(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=lr([Array.from(e),t]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);for(let c=0;c<o;c++)if(a[c]!==t[c])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);return tr(r,t)}function pe(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=lr(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=>tr(n,e))}function ye(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let y=r.size;for(let g of t){let b=g<0?y+g:g;if(b<0||b>=y)throw new Error(`index ${g} is out of bounds for axis 0 with size ${y}`)}let d=t.length,A=B(a);if(!A)throw new Error(`Cannot take from array with dtype ${a}`);let h=new A(d);for(let g=0;g<d;g++){let b=t[g];b<0&&(b=y+b);let S=r.iget(b);w(a),h[g]=S}return D.fromData(h,[d],a)}let c=e<0?o+e:e;if(c<0||c>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[c];for(let y of t){let d=y<0?u+y:y;if(d<0||d>=u)throw new Error(`index ${y} is out of bounds for axis ${c} with size ${u}`)}let s=Array.from(n);s[c]=t.length;let i=s.reduce((y,d)=>y*d,1),l=B(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let f=new l(i),p=R(s),m=new Array(o).fill(0);for(let y=0;y<i;y++){let d=[...m],A=m[c],h=t[A];h<0&&(h=u+h),d[c]=h;let g=r.get(...d),b=0;for(let S=0;S<o;S++)b+=m[S]*p[S];w(a),f[b]=g;for(let S=o-1;S>=0&&(m[S]++,!(m[S]<s[S]));S--)m[S]=0}return D.fromData(f,s,a)}function me(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 c=0;c<e.size;c++)a.push(e.iget(c));if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let c=[...a];a=[];for(let u=0;u<t.length;u++)a.push(c[u%c.length])}}for(let c=0;c<t.length;c++){let u=t[c];if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`index ${t[c]} is out of bounds for axis 0 with size ${n}`);let s=a[c];w(o)?typeof s!="bigint"&&(s=BigInt(Math.round(Number(s)))):typeof s=="bigint"&&(s=Number(s)),r.iset(u,s)}}function de(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(p=>Array.from(p.shape));a.unshift(Array.from(e));let c=lr(a);if(c===null)throw new Error("operands could not be broadcast together");let u=tr(r,c),s=t.map(p=>tr(p,c)),i=c.reduce((p,m)=>p*m,1),l=B(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let f=new l(i);for(let p=0;p<i;p++){let m=Number(u.iget(p));if(m<0||m>=n)throw new Error(`index ${m} is out of bounds for axis 0 with size ${n}`);let y=s[m].iget(p);w(o),f[p]=y}return D.fromData(f,c,o)}function ge(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),c=t.iget(o);if(e){let u=typeof a=="number"&&Number.isNaN(a),s=typeof c=="number"&&Number.isNaN(c);if(u&&s)continue}if(a!==c)return!1}return!0}var he=_(()=>{"use strict";P();C();le()});function fr(r,t=v){let e=D.zeros(r,t);return new z(e)}function Ae(r,t=v){let e=D.ones(r,t);return new z(e)}function _n(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function be(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>be(t)):!1}function En(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function q(r,t){if(r instanceof z)return!t||r.dtype===t?r.copy():r.astype(t);let e=be(r),n=_n(r),o=n.reduce((l,f)=>l*f,1),a=t;a||(e?a="int64":a=v);let c=B(a);if(!c)throw new Error(`Cannot create array with dtype ${a}`);let u=new c(o),s=En(r);if(w(a)){let l=u;for(let f=0;f<o;f++){let p=s[f];l[f]=typeof p=="bigint"?p:BigInt(Math.round(Number(p)))}}else if(a==="bool"){let l=u;for(let f=0;f<o;f++)l[f]=s[f]?1:0}else{let l=u;for(let f=0;f<o;f++){let p=s[f];l[f]=Number(p)}}let i=D.fromData(u,n,a);return new z(i)}function Tn(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 c=Math.max(0,Math.ceil((a-o)/e)),u=B(n);if(!u)throw new Error(`Cannot create arange array with dtype ${n}`);let s=new u(c);if(w(n))for(let l=0;l<c;l++)s[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<c;l++)s[l]=o+l*e!==0?1:0;else for(let l=0;l<c;l++)s[l]=o+l*e;let i=D.fromData(s,[c],n);return new z(i)}function On(r,t,e=50,n=v){if(e<0)throw new Error("num must be non-negative");if(e===0)return q([],n);if(e===1)return q([r],n);let o=B(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),c=(t-r)/(e-1);if(w(n))for(let s=0;s<e;s++)a[s]=BigInt(Math.round(r+s*c));else if(n==="bool")for(let s=0;s<e;s++)a[s]=r+s*c!==0?1:0;else for(let s=0;s<e;s++)a[s]=r+s*c;let u=D.fromData(a,[e],n);return new z(u)}function $n(r,t,e=50,n=10,o=v){if(e<0)throw new Error("num must be non-negative");if(e===0)return q([],o);if(e===1)return q([Math.pow(n,r)],o);let a=B(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let c=new a(e),u=(t-r)/(e-1);if(w(o))for(let i=0;i<e;i++){let l=r+i*u;c[i]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let i=0;i<e;i++){let l=r+i*u;c[i]=Math.pow(n,l)!==0?1:0}else for(let i=0;i<e;i++){let l=r+i*u;c[i]=Math.pow(n,l)}let s=D.fromData(c,[e],o);return new z(s)}function Mn(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 q([],n);if(e===1)return q([r],n);let o=Math.sign(r),a=Math.sign(t);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let c=B(n);if(!c)throw new Error(`Cannot create geomspace array with dtype ${n}`);let u=new c(e),s=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-s)/(e-1);if(w(n))for(let p=0;p<e;p++){let m=o*Math.exp(s+p*l);u[p]=BigInt(Math.round(m))}else if(n==="bool")for(let p=0;p<e;p++){let m=o*Math.exp(s+p*l);u[p]=m!==0?1:0}else for(let p=0;p<e;p++){let m=o*Math.exp(s+p*l);u[p]=m}let f=D.fromData(u,[e],n);return new z(f)}function Se(r,t,e=0,n=v){let o=t??r,a=fr([r,o],n),c=a.data;if(w(n)){let u=c;for(let s=0;s<r;s++){let i=s+e;i>=0&&i<o&&(u[s*o+i]=BigInt(1))}}else{let u=c;for(let s=0;s<r;s++){let i=s+e;i>=0&&i<o&&(u[s*o+i]=1)}}return a}function De(r,t=v){return fr(r,t)}function we(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=B(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((s,i)=>s*i,1),c=new o(a);if(w(n)){let s=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));c.fill(s)}else n==="bool"?c.fill(t?1:0):c.fill(Number(t));let u=D.fromData(c,r,n);return new z(u)}function vn(r,t=v){return Se(r,r,0,t)}function Cn(r,t){return r instanceof z?!t||r.dtype===t?r:r.astype(t):q(r,t)}function kn(r){return r.copy()}function Pn(r,t){return fr(Array.from(r.shape),t??r.dtype)}function Vn(r,t){return Ae(Array.from(r.shape),t??r.dtype)}function Fn(r,t){return De(Array.from(r.shape),t??r.dtype)}function Rn(r,t,e){return we(Array.from(r.shape),t,e??r.dtype)}function Ln(r){return r.sqrt()}function qn(r,t){return r.power(t)}function jn(r){return r.absolute()}function Zn(r){return r.negative()}function Wn(r){return r.sign()}function Hn(r,t){return r.mod(t)}function Gn(r,t){return r.floor_divide(t)}function Yn(r){return r.positive()}function Jn(r){return r.reciprocal()}function Xn(r,t){return r.dot(t)}function Qn(r){return r.trace()}function Kn(r,t){return r.transpose(t)}function ro(r,t){return r.inner(t)}function to(r,t){return r.outer(t)}function eo(r,t,e=2){return r.tensordot(t,e)}function no(r){return r.sin()}function oo(r){return r.cos()}function ao(r){return r.tan()}function so(r){return r.arcsin()}function io(r){return r.arccos()}function uo(r){return r.arctan()}function co(r,t){return r.arctan2(t)}function lo(r,t){return r.hypot(t)}function fo(r){return r.degrees()}function po(r){return r.radians()}function yo(r){return r.sinh()}function mo(r){return r.cosh()}function go(r){return r.tanh()}function ho(r){return r.arcsinh()}function Ao(r){return r.arccosh()}function bo(r){return r.arctanh()}function So(r,t,e){return r.swapaxes(t,e)}function Do(r,t,e){return r.moveaxis(t,e)}function wo(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=Z(e,t);return z._fromStorage(n)}function No(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=Bt(e,t);return z._fromStorage(n)}function xo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Ut(t);return z._fromStorage(e)}function Io(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=_t(t);return z._fromStorage(e)}function zo(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Et(t);return z._fromStorage(e)}function Bo(r,t,e=0){return Tt(r.storage,t,e).map(o=>z._fromStorage(o,r.base??r))}function Uo(r,t,e=0){return cr(r.storage,t,e).map(o=>z._fromStorage(o,r.base??r))}function _o(r,t){return $t(r.storage,t).map(n=>z._fromStorage(n,r.base??r))}function Eo(r,t){return Mt(r.storage,t).map(n=>z._fromStorage(n,r.base??r))}function To(r,t){let e=vt(r.storage,t);return z._fromStorage(e)}function Oo(r,t,e){return r.repeat(t,e)}function $o(r,t){let e=fe(r.storage,t);return z._fromStorage(e,r.base??r)}function Mo(...r){let t=r.map(n=>n.storage);return pe(t).map((n,o)=>z._fromStorage(n,r[o].base??r[o]))}function vo(r,t,e){return r.take(t,e)}function Co(r,t,e){r.put(t,e)}function ko(r,t){let e=t.map(o=>o.storage),n=de(r.storage,e);return z._fromStorage(n)}function Po(r,t,e=!1){return ge(r.storage,t.storage,e)}var z,Mr=_(()=>{"use strict";Xr();C();P();pt();St();Nt();Tr();Lt();Zt();ee();ce();he();z=class r{constructor(t,e){this._storage=t,this._base=e}get storage(){return this._storage}static _fromStorage(t,e){return new r(t,e)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let e=t.map((n,o)=>{let a=n;if(a<0&&(a=this.shape[o]+a),a<0||a>=this.shape[o])throw new Error(`Index ${n} is out of bounds for axis ${o} with size ${this.shape[o]}`);return a});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let n=t.map((c,u)=>{let s=c;if(s<0&&(s=this.shape[u]+s),s<0||s>=this.shape[u])throw new Error(`Index ${c} is out of bounds for axis ${u} with size ${this.shape[u]}`);return s}),o=this.dtype,a;w(o)?a=typeof e=="bigint"?e:BigInt(Math.round(e)):o==="bool"?a=e?1:0:a=Number(e),this._storage.set(n,a)}copy(){return new 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,c=B(t);if(!c)throw new Error(`Cannot convert to dtype ${t}`);let u=new c(a),s=this.data;if(w(n)&&!w(t)){let l=s;if(t==="bool")for(let f=0;f<a;f++)u[f]=l[f]!==BigInt(0)?1:0;else for(let f=0;f<a;f++)u[f]=Number(l[f])}else if(!w(n)&&w(t)){let l=s;for(let f=0;f<a;f++)u[f]=BigInt(Math.round(Number(l[f])))}else if(t==="bool"){let l=s;for(let f=0;f<a;f++)u[f]=l[f]!==0?1:0}else if(n==="bool"&&!w(t)){let l=s;for(let f=0;f<a;f++)u[f]=l[f]}else if(!w(n)&&!w(t)){let l=s;for(let f=0;f<a;f++)u[f]=l[f]}else{let l=s;for(let f=0;f<a;f++)u[f]=l[f]}let i=D.fromData(u,o,t);return new r(i)}add(t){let e=typeof t=="number"?t:t._storage,n=tt(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=et(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=nt(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=ot(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=ut(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=ct(this._storage,e);return r._fromStorage(n)}positive(){let t=lt(this._storage);return r._fromStorage(t)}reciprocal(){let t=ft(this._storage);return r._fromStorage(t)}sqrt(){let t=qt(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=jt(this._storage,e);return r._fromStorage(n)}absolute(){let t=at(this._storage);return r._fromStorage(t)}negative(){let t=st(this._storage);return r._fromStorage(t)}sign(){let t=it(this._storage);return r._fromStorage(t)}sin(){let t=Wt(this._storage);return r._fromStorage(t)}cos(){let t=Ht(this._storage);return r._fromStorage(t)}tan(){let t=Gt(this._storage);return r._fromStorage(t)}arcsin(){let t=Yt(this._storage);return r._fromStorage(t)}arccos(){let t=Jt(this._storage);return r._fromStorage(t)}arctan(){let t=Xt(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=Qt(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=Kt(this._storage,e);return r._fromStorage(n)}degrees(){let t=re(this._storage);return r._fromStorage(t)}radians(){let t=te(this._storage);return r._fromStorage(t)}sinh(){let t=ne(this._storage);return r._fromStorage(t)}cosh(){let t=oe(this._storage);return r._fromStorage(t)}tanh(){let t=ae(this._storage);return r._fromStorage(t)}arcsinh(){let t=se(this._storage);return r._fromStorage(t)}arccosh(){let t=ie(this._storage);return r._fromStorage(t)}arctanh(){let t=ue(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=yt(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=mt(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=dt(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=gt(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=ht(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=At(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=Sr(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 bt(this._storage,o,e,n)}sum(t,e=!1){let n=Q(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=Dr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=wr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=xr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=Nr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=Ir(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=zr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=Br(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=wt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=Ur(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=_r(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=Y(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Er(this._storage);return r._fromStorage(t)}ravel(){let t=rr(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=ur(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=xt(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=K(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=It(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=zt(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=Ct(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=ye(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;me(this._storage,t,n)}matmul(t){let e=$r(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=Or(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return Pt(this._storage)}inner(t){let e=Vt(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=Ft(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=Rt(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);let e=t.map((s,i)=>{let l=Yr(s);return Jr(l,this.shape[i])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});let n=[],o=[],a=this._storage.offset;for(let s=0;s<e.length;s++){let i=e[s],l=this._storage.strides[s];if(a+=i.start*l,!i.isIndex){let f;i.step>0?f=Math.max(0,Math.ceil((i.stop-i.start)/i.step)):f=Math.max(0,Math.ceil((i.start-i.stop)/Math.abs(i.step))),n.push(f),o.push(l*i.step)}}let c=D.fromData(this._storage.data,n,this._storage.dtype,o,a),u=this._base??this;return new r(c,u)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let t=this.shape,e=t.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let c=[];for(let u=0;u<t[a];u++)o[a]=u,c.push(n(o,a+1));return c};return n(new Array(e),0)}}});function Cr(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}function xe(r){if(r.startsWith("[")||r.startsWith("("))throw new F(`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 Ne)throw new F(`Unsupported dtype: ${Ne[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Vo[e];if(!o)throw new F(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${vr.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Cr(),c=t==="<"||t==="|"||t==="="&&a,u=t===">"||t==="="&&!a,s=parseInt(e.slice(1),10),i=s>1&&(u&&a||c&&!a);return{dtype:o,needsByteSwap:i,itemsize:s}}var er,vr,Vo,pr,Ne,F,k,nr=_(()=>{"use strict";er=new Uint8Array([147,78,85,77,80,89]),vr=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];Vo={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},pr={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},Ne={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};F=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},k=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}}});function W(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=kr(t);return Pr(t,e)}function kr(r){if(r.length<10)throw new k("File too small to be a valid NPY file");for(let i=0;i<er.length;i++)if(r[i]!==er[i])throw new k("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new k(`Unsupported NPY version: ${t}.${e}`);let n,o;t===1?(n=r[8]|r[9]<<8,o=10):(n=r[8]|r[9]<<8|r[10]<<16|r[11]<<24,o=12);let a=o+n;if(r.length<a)throw new k("File truncated: header extends beyond file");let c=r.slice(o,a),u=new TextDecoder("utf-8").decode(c).trim(),s=Fo(u);return{version:{major:t,minor:e},header:s,dataOffset:a}}function Pr(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:c}=xe(e.descr),u=e.shape.reduce((d,A)=>d*A,1),s=u*c,i=r.length-n;if(i<s)throw new k(`File truncated: expected ${s} bytes of data, got ${i}`);let l=new ArrayBuffer(s);new Uint8Array(l).set(r.subarray(n,n+s));let p=Ro(l,o,u,a,c),m=e.shape,y;if(e.fortran_order&&m.length>1){let d=[...m].reverse(),A=D.fromData(p,d,o);y=Lo(A,d),m=e.shape}else y=D.fromData(p,[...m],o);return new z(y)}function Fo(r){let t=r.match(/'descr'\s*:\s*'([^']+)'/),e=r.match(/'fortran_order'\s*:\s*(True|False)/),n=r.match(/'shape'\s*:\s*\(([^)]*)\)/);if(!t||!e||!n)throw new k(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",c=n[1].trim(),u;return c===""?u=[]:u=c.split(",").map(s=>s.trim()).filter(s=>s!=="").map(s=>{let i=parseInt(s,10);if(isNaN(i))throw new k(`Invalid shape value: ${s}`);return i}),{descr:o,fortran_order:a,shape:u}}function Ro(r,t,e,n,o){let a=B(t);if(!a)throw new k(`Cannot create array for dtype: ${t}`);if(!n)return new a(r,0,e);let c=new Uint8Array(r),u=new Uint8Array(r.byteLength);for(let s=0;s<e;s++){let i=s*o;for(let l=0;l<o;l++)u[i+l]=c[i+o-1-l]}return new a(u.buffer,0,e)}function Lo(r,t){let e=t.length,n=r.size,o=r.dtype,a=B(o);if(!a)throw new k(`Cannot create array for dtype: ${o}`);let c=new a(n),u=[...t].reverse(),s=Ie(t),i=Ie(u),l=new Array(e).fill(0);for(let f=0;f<n;f++){let p=f;for(let y=0;y<e;y++){let d=s[y];l[y]=Math.floor(p/d),p=p%d}let m=0;for(let y=0;y<e;y++)m+=l[e-1-y]*i[y];w(o),c[m]=r.iget(f)}return D.fromData(c,u,o)}function Ie(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 yr=_(()=>{"use strict";Mr();P();C();nr()});function j(r){let t=r.shape,e=r.dtype,n=pr[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,c=12,s=(64-(c+a.length+1)%64)%64;a=a+" ".repeat(s)+`
2
- `;let i=new TextEncoder().encode(a),l=i.length,f=r.size,p=Kr(e),m=f*p,y=c+l+m,d=new Uint8Array(y);d.set(er,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(i,c);let A=c+l;return qo(r,d.subarray(A),p),d}function qo(r,t,e){let n=r.dtype,o=r.size,a=Cr(),c=w(n),u=r._storage;if(u.isCContiguous&&u.offset===0&&a){let i=u.data,l=new Uint8Array(i.buffer,i.byteOffset,o*e);t.set(l)}else{let i=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let l=0;l<o;l++){let f=u.iget(l),p=l*e;c?jo(i,p,f,n==="uint64"):Zo(i,p,f,n)}}}function jo(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Zo(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 mr=_(()=>{"use strict";C();nr()});function Vr(r){let t=4294967295;for(let e=0;e<r.length;e++)t=Wo[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}var Wo,Fr=_(()=>{"use strict";Wo=(()=>{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 ze(r){let t=Ue(r),e=new Map;for(let n of t){let o=await Ho(n);e.set(n.name,o)}return e}function Be(r){let t=Ue(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 Ue(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=[],o=-1;for(let i=t.length-22;i>=0;i--)if(e.getUint32(i,!0)===101010256){o=i;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),c=e.getUint16(o+10,!0),u=[],s=a;for(let i=0;i<c&&e.getUint32(s,!0)===33639248;i++){let f=e.getUint16(s+10,!0),p=e.getUint32(s+16,!0),m=e.getUint32(s+20,!0),y=e.getUint32(s+24,!0),d=e.getUint16(s+28,!0),A=e.getUint16(s+30,!0),h=e.getUint16(s+32,!0),g=e.getUint32(s+42,!0),b=t.slice(s+46,s+46+d),S=new TextDecoder("utf-8").decode(b);u.push({name:S,compressionMethod:f,crc32:p,compressedSize:m,uncompressedSize:y,localHeaderOffset:g}),s=s+46+d+A+h}for(let i of u){let l=i.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let p=e.getUint16(l+26,!0),m=e.getUint16(l+28,!0),y=l+30+p+m,d=t.slice(y,y+i.compressedSize);n.push({name:i.name,compressedData:d,compressionMethod:i.compressionMethod,crc32:i.crc32,compressedSize:i.compressedSize,uncompressedSize:i.uncompressedSize})}return n}async function Ho(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Go(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Go(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:i,value:l}=await o.read();if(i)break;a.push(l)}let c=a.reduce((i,l)=>i+l.length,0),u=new Uint8Array(c),s=0;for(let i of a)u.set(i,s),s+=i.length;return u}var _e=_(()=>{"use strict";Fr()});var Te={};Hr(Te,{loadNpz:()=>qr,loadNpzSync:()=>jr,parseNpz:()=>X,parseNpzSync:()=>dr});async function X(r,t={}){let e=t.force??!1,n=await ze(r);return Ee(n,e)}function dr(r,t={}){let e=t.force??!1,n=Be(r);return Ee(n,e)}function Ee(r,t){let e=new Map,n=[],o=new Map;for(let[a,c]of r){if(!a.endsWith(".npy"))continue;let u=a.slice(0,-4);try{let s=W(c);e.set(u,s)}catch(s){if(s instanceof F&&t)n.push(u),o.set(u,s.message);else throw s}}return{arrays:e,skipped:n,errors:o}}async function qr(r,t={}){let e=await X(r,t);return Object.fromEntries(e.arrays)}function jr(r,t={}){let e=dr(r,t);return Object.fromEntries(e.arrays)}var gr=_(()=>{"use strict";yr();nr();_e()});async function Oe(r,t={}){let e=t.compress??!1,n=[];for(let[p,m]of r){let y=Vr(m),d,A;e?(d=await Jo(m),d.length<m.length?A=8:(d=m,A=0)):(d=m,A=0),n.push({name:p,data:m,compressedData:d,crc:y,compressionMethod:A,offset:0})}let o=0;for(let p of n){let m=new TextEncoder().encode(p.name);o+=30+m.length+p.compressedData.length}let a=0;for(let p of n){let m=new TextEncoder().encode(p.name);a+=46+m.length}let u=o+a+22,s=new Uint8Array(u),i=new DataView(s.buffer),l=0;for(let p of n)p.offset=l,l=Me(s,i,l,p);let f=l;for(let p of n)l=ve(s,i,l,p);return Ce(i,l,n.length,a,f),s}function $e(r){let t=[];for(let[l,f]of r){let p=Vr(f);t.push({name:l,data:f,compressedData:f,crc:p,compressionMethod:0,offset:0})}let e=0;for(let l of t){let f=new TextEncoder().encode(l.name);e+=30+f.length+l.compressedData.length}let n=0;for(let l of t){let f=new TextEncoder().encode(l.name);n+=46+f.length}let a=e+n+22,c=new Uint8Array(a),u=new DataView(c.buffer),s=0;for(let l of t)l.offset=s,s=Me(c,u,s,l);let i=s;for(let l of t)s=ve(c,u,s,l);return Ce(u,s,t.length,n,i),c}function Me(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 ve(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 Ce(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 Jo(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:i,value:l}=await o.read();if(i)break;a.push(l)}let c=a.reduce((i,l)=>i+l.length,0),u=new Uint8Array(c),s=0;for(let i of a)u.set(i,s),s+=i.length;return u}var ke=_(()=>{"use strict";Fr()});var Ve={};Hr(Ve,{serializeNpz:()=>ar,serializeNpzSync:()=>Zr});async function ar(r,t={}){let e=Pe(r);return Oe(e,{compress:t.compress??!1})}function Zr(r){let t=Pe(r);return $e(t)}function Pe(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=j(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=j(o),c=n.endsWith(".npy")?n:`${n}.npy`;t.set(c,a)}return t}var hr=_(()=>{"use strict";mr();ke()});yr();mr();gr();hr();import{readFileSync as Fe,writeFileSync as Re}from"node:fs";import{readFile as Le,writeFile as qe}from"node:fs/promises";Mr();yr();mr();nr();gr();hr();var ps="0.5.0";async function Xo(r){let t=await Le(r);return W(t)}function Qo(r){let t=Fe(r);return W(t)}async function Ko(r,t){let e=j(t);await qe(r,e)}function ra(r,t){let e=j(t);Re(r,e)}async function ta(r,t={}){let e=await Le(r);return X(e,t)}function ea(r,t={}){let e=Fe(r),{parseNpzSync:n}=(gr(),Gr(Te));return n(e,t)}async function je(r,t,e={}){let n=await ar(t,e);await qe(r,n)}function ws(r,t){let{serializeNpzSync:e}=(hr(),Gr(Ve)),n=e(t);Re(r,n)}async function Ns(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return Xo(r)}else{if(r.endsWith(".npz"))return ta(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function xs(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return Qo(r)}else{if(r.endsWith(".npz"))return ea(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function Is(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return Ko(r,t)}function zs(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return ra(r,t)}async function Bs(r,t){return r.endsWith(".npz")||(r=r+".npz"),je(r,t,{compress:!1})}async function Us(r,t){return r.endsWith(".npz")||(r=r+".npz"),je(r,t,{compress:!0})}export{pr as DTYPE_TO_DESCR,k as InvalidNpyError,z as NDArray,vr as SUPPORTED_DTYPES,F as UnsupportedDTypeError,ps as __version__,jn as absolute,Tn as arange,io as arccos,Ao as arccosh,so as arcsin,ho as arcsinh,uo as arctan,co as arctan2,bo as arctanh,q as array,Po as array_equal,Uo as array_split,Cn as asarray,Mo as broadcast_arrays,$o as broadcast_to,ko as choose,wo as concatenate,kn as copy,oo as cos,mo as cosh,fo as degrees,Xn as dot,zo as dstack,De as empty,Fn as empty_like,Se as eye,Gn as floor_divide,we as full,Rn as full_like,Mn as geomspace,Eo as hsplit,Io as hstack,lo as hypot,vn as identity,ro as inner,On as linspace,Ns as load,Xo as loadNpy,Qo as loadNpySync,qr as loadNpz,ta as loadNpzFile,ea as loadNpzFileSync,jr as loadNpzSync,xs as loadSync,$n as logspace,Hn as mod,Do as moveaxis,Zn as negative,Ae as ones,Vn as ones_like,to as outer,W as parseNpy,Pr as parseNpyData,kr as parseNpyHeader,X as parseNpz,dr as parseNpzSync,Yn as positive,qn as power,Co as put,po as radians,Jn as reciprocal,Oo as repeat,Is as save,Ko as saveNpy,ra as saveNpySync,je as saveNpz,ws as saveNpzSync,zs as saveSync,Bs as savez,Us as savez_compressed,j as serializeNpy,ar as serializeNpz,Zr as serializeNpzSync,Wn as sign,no as sin,yo as sinh,Bo as split,Ln as sqrt,No as stack,So as swapaxes,vo as take,ao as tan,go as tanh,eo as tensordot,To as tile,Qn as trace,Kn as transpose,_o as vsplit,xo as vstack,fr as zeros,Pn as zeros_like};
1
+ var Pr=Object.defineProperty;var Vn=Object.getOwnPropertyDescriptor;var Fn=Object.getOwnPropertyNames;var Rn=Object.prototype.hasOwnProperty;var $=(r,t)=>()=>(r&&(t=r(r=0)),t);var xt=(r,t)=>{for(var e in t)Pr(r,e,{get:t[e],enumerable:!0})},qn=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Fn(t))!Rn.call(r,o)&&o!==e&&Pr(r,o,{get:()=>t[o],enumerable:!(n=Vn(t,o))||n.enumerable});return r};var It=r=>qn(Pr({},"__esModule",{value:!0}),r);function zt(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 Bt(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 _t=$(()=>{"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 Ut(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 Et(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(Et(r)||Et(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,k=$(()=>{"use strict";v="float64"});function L(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}var D,F=$(()=>{"use strict";k();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 Tt(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 Ln(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 gr(r,t){let e=Ln(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=Tt(r.shape,t.shape),a=gr(r,o),i=gr(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 W(r,t,e){let n=Tt(r.shape,t.shape),o=gr(r,n),a=gr(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 K=$(()=>{"use strict";F();k()});function Vr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Ot(r,t){return typeof t=="number"?Gn(r,t):Vr(r,t)?jn(r,t):q(r,t,(e,n)=>e+n,"add")}function jn(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 $t(r,t){return typeof t=="number"?Hn(r,t):Vr(r,t)?Zn(r,t):q(r,t,(e,n)=>e-n,"subtract")}function Zn(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 vt(r,t){return typeof t=="number"?Yn(r,t):Vr(r,t)?Wn(r,t):q(r,t,(e,n)=>e*n,"multiply")}function Wn(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 Mt(r,t){if(typeof t=="number")return Jn(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:rr(r,"float64"),c=n?t:rr(t,"float64");return q(u,c,(l,y)=>l/y,"divide")}if(o||a){let u=o?r:rr(r,"float32"),c=a?t:rr(t,"float32");return q(u,c,(l,y)=>l/y,"divide")}let i=rr(r,"float64"),s=rr(t,"float64");return q(i,s,(u,c)=>u/c,"divide")}function rr(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 Gn(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 Hn(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 Yn(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 Jn(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 Ct(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 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]}else for(let s=0;s<o;s++)i[s]=-Number(n[s]);return a}function Pt(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 hr(r,t){return typeof t=="number"?Qn(r,t):q(r,t,(e,n)=>(e%n+n)%n,"mod")}function Qn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,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 Fr(r,t){return typeof t=="number"?Xn(r,t):q(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function Xn(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 Vt(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 Ft(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 Rt(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 Lt(r,t){let e=Fr(r,t),n=hr(r,t);return[e,n]}function jt(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 Zt(r,t){return hr(r,t)}function Wt(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 Gt=$(()=>{"use strict";F();k();K()});function Y(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 ro(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 G(r,t){let e=ro(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function Rr(...r){let t=Y(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 qr=$(()=>{"use strict";F()});function Ht(r,t){return typeof t=="number"?to(r,t):W(r,t,(e,n)=>e>n)}function Yt(r,t){return typeof t=="number"?eo(r,t):W(r,t,(e,n)=>e>=n)}function Jt(r,t){return typeof t=="number"?no(r,t):W(r,t,(e,n)=>e<n)}function Qt(r,t){return typeof t=="number"?oo(r,t):W(r,t,(e,n)=>e<=n)}function Xt(r,t){return typeof t=="number"?ao(r,t):W(r,t,(e,n)=>e===n)}function Kt(r,t){return typeof t=="number"?so(r,t):W(r,t,(e,n)=>e!==n)}function Lr(r,t,e=1e-5,n=1e-8){return typeof t=="number"?io(r,t,e,n):W(r,t,(o,a)=>{let i=Math.abs(o-a),s=n+e*Math.abs(a);return i<=s})}function re(r,t,e=1e-5,n=1e-8){let o=Lr(r,t,e,n),a=o.data;for(let i=0;i<o.size;i++)if(a[i]===0)return!1;return!0}function te(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=Y(e);if(n===null)return!1;let o=G(r,n),a=G(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 to(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 eo(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 no(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 oo(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 ao(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 so(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 io(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 ee=$(()=>{"use strict";F();k();K();qr()});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 ne=$(()=>{"use strict"});function ar(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 ar(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 Ar(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return ar(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=ar(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 br(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 br(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 jr(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 jr(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 Sr(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 Sr(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 Zr(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 Zr(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 Wr(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 Wr(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 Gr(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.size,s=r.data,u=Ar(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 oe(r,t,e=0,n=!1){let o=Gr(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 Hr(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 Hr(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 Yr(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 Yr(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 Jr(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 Qr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),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 Xr(r,t,e=!1){let n=br(r,t,e),o=Sr(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 Kr(r,t,e=!1){return tr(r,.5,t,e)}function rt(r,t,e,n=!1){return tr(r,t/100,e,n)}function tr(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 tr(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 Dr(r,t,e,n=!1){let o=r.shape,a=o.length,i=r.data;if(e===void 0)return Ar(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 Dr(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 Nr(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 Nr(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 wr(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 wr(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 xr(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 xr(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 sr(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 sr(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 tt(r,t,e=0,n=!1){let o=sr(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 Ir(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 Ir(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 zr(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 zr(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 Br(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 Br(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 et(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 nt(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 Er(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 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=[];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 ae=$(()=>{"use strict";F();k();ne()});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,L(a),0)}let u=r.copy().data;return D.fromData(u,a,n,L(a),0)}function Ur(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 ur(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return D.fromData(n,[t],e,[1],0)}return Ur(r)}function cr(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 se(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 ir(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 ie(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 ot(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 cr(r,u)}function J(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=L(i),f=0;for(let p of r){let m=p.shape[a];fo(p,l,i,y,a,f,o),f+=m}return D.fromData(l,i,o)}function fo(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 ue(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=>ir(s,a));return J(i,a)}function ce(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?R(e,[1,e.shape[0]]):e);return J(t,0)}function at(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?J(r,0):J(r,1)}function fe(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?R(ir(R(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?ir(e,2):e);return J(t,2)}function le(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 pe(r,s,a)}function fr(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 pe(r,s,a)}function pe(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 ye(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return fr(r,t,0)}function me(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 fr(r,t,e)}function de(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=L(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 ge(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 dr=0;dr<O;dr++)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=L(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 he(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 Ae(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=L(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 be(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=Ur(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 Se(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):ot(r,o,a)}function De(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return fr(r,t,2)}function Ne(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 at(t)}function we(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 xe(r){return r.map(t=>t.ndim===0?R(t,[1]):t)}function Ie(r){return r.map(t=>t.ndim===0?R(t,[1,1]):t.ndim===1?R(t,[1,t.shape[0]]):t)}function ze(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 st=$(()=>{"use strict";F();k()});function lo(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 ut(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 Q(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 Q(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 lo("row-major",g,A,e,a,n,1,u,h,c,b,0,S.data,a),S}function Ee(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 _e(r,t){return cr(r,t)}function Ue(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 ut(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 ct(r,t){let e=r.ndim===1?r:ur(r),n=t.ndim===1?t:ur(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 Te(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 Oe(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 $e(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=po(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 Q(A,h);if(S===z&&x===B&&b===w&&c.length===1&&c[0]===b){let E=_e(A);return Q(E,h)}if(b===z&&w===B&&S===x&&c.length===1&&c[0]===S){let E=_e(h);return Q(A,E)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&A.ndim===1&&h.ndim===1)return it(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 ct(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 it(t,a,c,i)}let l=Array.from(o).map(d=>i.get(d));if(l.length===0)return it(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=yo(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 dr of B)E.push(A.get(dr));let O=z.get(...E);w*=Number(O)}h+=w}f.set(g,h)}return f}function po(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 it(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 yo(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 ve(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 Me=$(()=>{"use strict";F();k();st()});function Ce(r){return C(r,Math.sqrt,!1)}function ke(r,t){return typeof t=="number"?go(r,t):q(r,t,Math.pow,"power")}function go(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 Pe=$(()=>{"use strict";F();K();k()});function Ve(r){return C(r,Math.sin,!1)}function Fe(r){return C(r,Math.cos,!1)}function Re(r){return C(r,Math.tan,!1)}function qe(r){return C(r,Math.asin,!1)}function Le(r){return C(r,Math.acos,!1)}function je(r){return C(r,Math.atan,!1)}function Ze(r,t){return typeof t=="number"?bo(r,t):Ao(r,t)}function Ao(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 bo(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 We(r,t){return typeof t=="number"?Do(r,t):So(r,t)}function So(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 Do(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 Ge(r){let t=180/Math.PI;return C(r,e=>e*t,!1)}function He(r){let t=Math.PI/180;return C(r,e=>e*t,!1)}var Ye=$(()=>{"use strict";F();K();k()});function Je(r){return C(r,Math.sinh,!1)}function Qe(r){return C(r,Math.cosh,!1)}function Xe(r){return C(r,Math.tanh,!1)}function Ke(r){return C(r,Math.asinh,!1)}function rn(r){return C(r,Math.acosh,!1)}function tn(r){return C(r,Math.atanh,!1)}var en=$(()=>{"use strict";K()});function ft(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=Y([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 G(r,t)}function nn(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=Y(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=>G(n,e))}function on(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=L(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 an(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 sn(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=Y(a);if(i===null)throw new Error("operands could not be broadcast together");let s=G(r,i),u=t.map(f=>G(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 un(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 cn=$(()=>{"use strict";F();k();qr()});function j(r,t=v){let e=D.zeros(r,t);return new I(e)}function fn(r,t=v){let e=D.ones(r,t);return new I(e)}function Io(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function ln(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>ln(t)):!1}function zo(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 I)return!t||r.dtype===t?r.copy():r.astype(t);let e=ln(r),n=Io(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=zo(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 Bo(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 _o(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=_(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 Eo(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);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 Uo(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 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 pn(r,t,e=0,n=v){let o=t??r,a=j([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 yn(r,t=v){return j(r,t)}function mn(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 To(r,t=v){return pn(r,r,0,t)}function Tr(r,t){return r instanceof I?!t||r.dtype===t?r:r.astype(t):P(r,t)}function Oo(r){return r.copy()}function $o(r,t){return j(Array.from(r.shape),t??r.dtype)}function vo(r,t){return fn(Array.from(r.shape),t??r.dtype)}function Mo(r,t){return yn(Array.from(r.shape),t??r.dtype)}function Co(r,t,e){return mn(Array.from(r.shape),t,e??r.dtype)}function ko(r,t){return Tr(r,t)}function Po(r,t){let e=Tr(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function Vo(r,t){return Tr(r,t).copy()}function dn(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=j([n,n],r.dtype);for(let a=0;a<e;a++){let i=t>=0?a:a-t,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 j([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 Fo(r,t=0){let e=r.flatten();return dn(e,t)}function Ro(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 qo(...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=ft(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 Lo(r,t,e=0,n=v){let o=t??r,a=j([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 jo(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 Zo(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 Wo(r,t,e=!1){if(r.ndim!==1)throw new Error("Input must be 1-D");let n=r.size,o=t??n;if(o<0)throw new Error("N must be non-negative");let a=j([n,o],r.dtype);for(let i=0;i<n;i++){let 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 Go(r,t=v,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let i=Qo(t),s=o.byteLength-a,u=Math.floor(s/i),c=e<0?u:Math.min(e,u);if(c<=0)return P([],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 Ho(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 Yo(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 Jo(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 P(a,t)}function Qo(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 Xo(r){return r.sqrt()}function Ko(r,t){return r.power(t)}function ra(r){return r.absolute()}function ta(r){return r.negative()}function ea(r){return r.sign()}function na(r,t){return r.mod(t)}function oa(r,t){return r.floor_divide(t)}function aa(r){return r.positive()}function sa(r){return r.reciprocal()}function ia(r,t){return r.dot(t)}function ua(r){return r.trace()}function ca(r,t=0,e=0,n=1){let o=Oe(r.storage,t,e,n);return I._fromStorage(o)}function fa(r,t){let e=ve(r.storage,t.storage);return I._fromStorage(e)}function la(r,t){return r.transpose(t)}function pa(r,t){return r.inner(t)}function ya(r,t){return r.outer(t)}function ma(r,t,e=2){return r.tensordot(t,e)}function da(r){return r.sin()}function ga(r){return r.cos()}function ha(r){return r.tan()}function Aa(r){return r.arcsin()}function ba(r){return r.arccos()}function Sa(r){return r.arctan()}function Da(r,t){return r.arctan2(t)}function Na(r,t){return r.hypot(t)}function wa(r){return r.degrees()}function xa(r){return r.radians()}function Ia(r){return r.radians()}function za(r){return r.degrees()}function Ba(r){return r.sinh()}function _a(r){return r.cosh()}function Ea(r){return r.tanh()}function Ua(r){return r.arcsinh()}function Ta(r){return r.arccosh()}function Oa(r){return r.arctanh()}function $a(r,t,e){return r.swapaxes(t,e)}function va(r,t,e){return r.moveaxis(t,e)}function er(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=J(e,t);return I._fromStorage(n)}function Ma(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=ue(e,t);return I._fromStorage(n)}function gn(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=ce(t);return I._fromStorage(e)}function Ca(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=at(t);return I._fromStorage(e)}function ka(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=fe(t);return I._fromStorage(e)}function Pa(r,t,e=0){return le(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function Va(r,t,e=0){return fr(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function Fa(r,t){return ye(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function Ra(r,t){return me(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function qa(r,t){let e=de(r.storage,t);return I._fromStorage(e)}function La(r,t,e){return r.repeat(t,e)}function ja(r){return r.ravel()}function Za(r,t){return r.reshape(...t)}function Wa(r,t){return r.squeeze(t)}function Ga(r,t){return r.expand_dims(t)}function lt(r,t){let e=he(r.storage,t);return I._fromStorage(e)}function Ha(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return lt(r,1)}function Ya(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return lt(r,0)}function Ja(r,t=1,e=[0,1]){let n=Ae(r.storage,t,e);return I._fromStorage(n)}function Qa(r,t,e){let n=be(r.storage,t,e);return I._fromStorage(n)}function Xa(r,t,e=0){let n=Se(r.storage,t,e);return I._fromStorage(n,r.base??r)}function Ka(...r){let t=r.map(o=>o.storage),n=xe(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function rs(...r){let t=r.map(o=>o.storage),n=Ie(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function ts(...r){let t=r.map(o=>o.storage),n=ze(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function es(r,t){return De(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function ns(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Ne(t);return I._fromStorage(e)}function os(r){return gn(r)}function as(r,t){let e=we(r.storage,t);return I._fromStorage(e)}function ss(r,t,e){let n=t instanceof I?t:P(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return er([o,a])}return er([r,n],e)}function is(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,j(p,n)}let f=[];for(let[p,m]of l){let d=o.map(()=>":");d[i]=`${p}:${m}`,f.push(r.slice(...d))}return er(f,i)}function us(r,t,e,n){let o=e instanceof I?e:P(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),er(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 er(l,s)}function cs(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 fs(r,t){let e=ft(r.storage,t);return I._fromStorage(e,r.base??r)}function ls(...r){let t=r.map(n=>n.storage);return nn(t).map((n,o)=>I._fromStorage(n,r[o].base??r[o]))}function ps(...r){return Rr(...r)}function ys(r,t,e){return r.take(t,e)}function ms(r,t,e){r.put(t,e)}function ds(r,t){let e=t.map(o=>o.storage),n=sn(r.storage,e);return I._fromStorage(n)}function gs(r,t,e=!1){return un(r.storage,t.storage,e)}function hs(r,t){return te(r.storage,t.storage)}function As(r,t){return I._fromStorage(Jr(r.storage,t))}function bs(r,t){return I._fromStorage(Qr(r.storage,t))}function Ss(r,t,e=!1){let n=Xr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ds(r,t,e=!1){let n=Kr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ns(r,t,e,n=!1){let o=rt(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function ws(r,t,e,n=!1){let o=tr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function xs(r,t,e,n=!1){let o=e?e.storage:void 0,a=Dr(r.storage,t,o,n);return typeof a=="number"?a:I._fromStorage(a)}function Is(r,t,e=!1){let n=Nr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function zs(r,t,e=!1){let n=wr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Bs(r,t,e=!1){let n=xr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function _s(r,t,e=0,n=!1){let o=sr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Es(r,t,e=0,n=!1){let o=tt(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Us(r,t,e=!1){let n=Ir(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Ts(r,t,e=!1){let n=zr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Os(r,t){let e=Br(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function $s(r,t){let e=_r(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function vs(r,t){return I._fromStorage(et(r.storage,t))}function Ms(r,t){return I._fromStorage(nt(r.storage,t))}function Cs(r,t,e=!1){let n=Er(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function ks(r){return r.cbrt()}function Ps(r){return r.fabs()}function Vs(r,t){return r.divmod(t)}function Fs(r){return r.square()}function Rs(r,t){return r.remainder(t)}function qs(r,t){return r.heaviside(t)}function Ls(r,...t){let e=t.map(o=>o.storage),n=$e(r,...e);return typeof n=="number"||typeof n=="bigint"?n:I._fromStorage(n)}var I,pt=$(()=>{"use strict";_t();k();F();Gt();ee();ae();st();Me();Pe();Ye();en();cn();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=Ot(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=$t(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=vt(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=Mt(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=hr(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=Fr(this._storage,e);return r._fromStorage(n)}positive(){let t=Vt(this._storage);return r._fromStorage(t)}reciprocal(){let t=Ft(this._storage);return r._fromStorage(t)}sqrt(){let t=Ce(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=ke(this._storage,e);return r._fromStorage(n)}absolute(){let t=Ct(this._storage);return r._fromStorage(t)}negative(){let t=kt(this._storage);return r._fromStorage(t)}sign(){let t=Pt(this._storage);return r._fromStorage(t)}sin(){let t=Ve(this._storage);return r._fromStorage(t)}cos(){let t=Fe(this._storage);return r._fromStorage(t)}tan(){let t=Re(this._storage);return r._fromStorage(t)}arcsin(){let t=qe(this._storage);return r._fromStorage(t)}arccos(){let t=Le(this._storage);return r._fromStorage(t)}arctan(){let t=je(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=Ze(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=We(this._storage,e);return r._fromStorage(n)}degrees(){let t=Ge(this._storage);return r._fromStorage(t)}radians(){let t=He(this._storage);return r._fromStorage(t)}sinh(){let t=Je(this._storage);return r._fromStorage(t)}cosh(){let t=Qe(this._storage);return r._fromStorage(t)}tanh(){let t=Xe(this._storage);return r._fromStorage(t)}arcsinh(){let t=Ke(this._storage);return r._fromStorage(t)}arccosh(){let t=rn(this._storage);return r._fromStorage(t)}arctanh(){let t=tn(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=Ht(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=Yt(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=Jt(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=Qt(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=Xt(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=Kt(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=Lr(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 re(this._storage,o,e,n)}sum(t,e=!1){let n=ar(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=Ar(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=br(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=Sr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=jr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=Zr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=Wr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=Gr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=oe(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=Hr(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=Yr(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(Jr(this._storage,t))}cumprod(t){return r._fromStorage(Qr(this._storage,t))}ptp(t,e=!1){let n=Xr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=Kr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=rt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=tr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=Dr(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=Nr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=wr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=xr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=sr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=tt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=Ir(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=zr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=Br(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=_r(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(nt(this._storage,t))}nanmedian(t,e=!1){let n=Er(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=Ur(this._storage);return r._fromStorage(t)}ravel(){let t=ur(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=cr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=se(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=ir(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=ie(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=ot(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=ge(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=on(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;an(this._storage,t,n)}matmul(t){let e=Q(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=ut(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return Ee(this._storage)}inner(t){let e=Ue(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=Te(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=Rt(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]=Lt(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=jt(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=Zt(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=Wt(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=zt(u);return Bt(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 mt(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}function An(r){if(r.startsWith("[")||r.startsWith("("))throw new Z(`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 hn)throw new Z(`Unsupported dtype: ${hn[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=js[e];if(!o)throw new Z(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${yt.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=mt(),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 lr,yt,js,Or,hn,Z,V,pr=$(()=>{"use strict";lr=new Uint8Array([147,78,85,77,80,89]),yt=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];js={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},Or={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},hn={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};Z=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},V=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}}});function X(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=dt(t);return gt(t,e)}function dt(r){if(r.length<10)throw new V("File too small to be a valid NPY file");for(let c=0;c<lr.length;c++)if(r[c]!==lr[c])throw new V("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new V(`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 V("File truncated: header extends beyond file");let i=r.slice(o,a),s=new TextDecoder("utf-8").decode(i).trim(),u=Zs(s);return{version:{major:t,minor:e},header:u,dataOffset:a}}function gt(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:i}=An(e.descr),s=e.shape.reduce((d,g)=>d*g,1),u=s*i,c=r.length-n;if(c<u)throw new V(`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=Ws(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=Gs(g,d),p=e.shape}else m=D.fromData(f,[...p],o);return new I(m)}function Zs(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 V(`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 V(`Invalid shape value: ${u}`);return c}),{descr:o,fortran_order:a,shape:s}}function Ws(r,t,e,n,o){let a=_(t);if(!a)throw new V(`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 Gs(r,t){let e=t.length,n=r.size,o=r.dtype,a=_(o);if(!a)throw new V(`Cannot create array for dtype: ${o}`);let i=new a(n),s=[...t].reverse(),u=bn(t),c=bn(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 bn(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 $r=$(()=>{"use strict";pt();F();k();pr()});function H(r){let t=r.shape,e=r.dtype,n=Or[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=Ut(e),p=y*f,m=i+l+p,d=new Uint8Array(m);d.set(lr,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 Hs(r,d.subarray(g),f),d}function Hs(r,t,e){let n=r.dtype,o=r.size,a=mt(),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?Ys(c,f,y,n==="uint64"):Js(c,f,y,n)}}}function Ys(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Js(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 vr=$(()=>{"use strict";k();pr()});function ht(r){let t=4294967295;for(let e=0;e<r.length;e++)t=Qs[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}var Qs,At=$(()=>{"use strict";Qs=(()=>{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 Sn(r){let t=Nn(r),e=new Map;for(let n of t){let o=await Xs(n);e.set(n.name,o)}return e}function Dn(r){let t=Nn(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 Nn(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 Xs(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Ks(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Ks(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 wn=$(()=>{"use strict";At()});var In={};xt(In,{loadNpz:()=>Dt,loadNpzSync:()=>Nt,parseNpz:()=>or,parseNpzSync:()=>Mr});async function or(r,t={}){let e=t.force??!1,n=await Sn(r);return xn(n,e)}function Mr(r,t={}){let e=t.force??!1,n=Dn(r);return xn(n,e)}function xn(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=X(i);e.set(s,u)}catch(u){if(u instanceof Z&&t)n.push(s),o.set(s,u.message);else throw u}}return{arrays:e,skipped:n,errors:o}}async function Dt(r,t={}){let e=await or(r,t);return Object.fromEntries(e.arrays)}function Nt(r,t={}){let e=Mr(r,t);return Object.fromEntries(e.arrays)}var Cr=$(()=>{"use strict";$r();pr();wn()});async function zn(r,t={}){let e=t.compress??!1,n=[];for(let[f,p]of r){let m=ht(p),d,g;e?(d=await ti(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=_n(u,c,l,f);let y=l;for(let f of n)l=En(u,c,l,f);return Un(c,l,n.length,a,y),u}function Bn(r){let t=[];for(let[l,y]of r){let f=ht(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=_n(i,s,u,l);let c=u;for(let l of t)u=En(i,s,u,l);return Un(s,u,t.length,n,c),i}function _n(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 En(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 Un(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 ti(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 Tn=$(()=>{"use strict";At()});var $n={};xt($n,{serializeNpz:()=>mr,serializeNpzSync:()=>wt});async function mr(r,t={}){let e=On(r);return zn(e,{compress:t.compress??!1})}function wt(r){let t=On(r);return Bn(t)}function On(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=H(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=H(o),i=n.endsWith(".npy")?n:`${n}.npy`;t.set(i,a)}return t}var kr=$(()=>{"use strict";vr();Tn()});$r();vr();Cr();kr();import{readFileSync as vn,writeFileSync as Mn}from"node:fs";import{readFile as Cn,writeFile as kn}from"node:fs/promises";pt();$r();vr();pr();Cr();kr();var Au="0.6.0";async function ei(r){let t=await Cn(r);return X(t)}function ni(r){let t=vn(r);return X(t)}async function oi(r,t){let e=H(t);await kn(r,e)}function ai(r,t){let e=H(t);Mn(r,e)}async function si(r,t={}){let e=await Cn(r);return or(e,t)}function ii(r,t={}){let e=vn(r),{parseNpzSync:n}=(Cr(),It(In));return n(e,t)}async function Pn(r,t,e={}){let n=await mr(t,e);await kn(r,n)}function _u(r,t){let{serializeNpzSync:e}=(kr(),It($n)),n=e(t);Mn(r,n)}async function Eu(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return ei(r)}else{if(r.endsWith(".npz"))return si(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function Uu(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return ni(r)}else{if(r.endsWith(".npz"))return ii(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function Tu(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return oi(r,t)}function Ou(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return ai(r,t)}async function $u(r,t){return r.endsWith(".npz")||(r=r+".npz"),Pn(r,t,{compress:!1})}async function vu(r,t){return r.endsWith(".npz")||(r=r+".npz"),Pn(r,t,{compress:!0})}export{Or as DTYPE_TO_DESCR,V as InvalidNpyError,I as NDArray,yt as SUPPORTED_DTYPES,Z as UnsupportedDTypeError,Au as __version__,ra as absolute,ss as append,Bo as arange,ba as arccos,Ta as arccosh,Aa as arcsin,Ua as arcsinh,Sa as arctan,Da as arctan2,Oa as arctanh,P as array,gs as array_equal,hs as array_equiv,Va as array_split,ko as asanyarray,Tr as asarray,Po as ascontiguousarray,Vo as asfortranarray,Ka as atleast_1d,rs as atleast_2d,ts as atleast_3d,xs as average,ls as broadcast_arrays,ps as broadcast_shapes,fs as broadcast_to,ks as cbrt,ds as choose,ns as column_stack,er as concatenate,Oo as copy,ga as cos,_a as cosh,bs as cumprod,As as cumsum,Ia as deg2rad,wa as degrees,is as delete,dn as diag,Fo as diagflat,ca as diagonal,Vs as divmod,ia as dot,es as dsplit,ka as dstack,Ls as einsum,yn as empty,Mo as empty_like,Ga as expand_dims,pn as eye,Ps as fabs,lt as flip,Ha as fliplr,Ya as flipud,oa as floor_divide,Go as frombuffer,Ho as fromfile,Ro as fromfunction,Yo as fromiter,Jo as fromstring,mn as full,Co as full_like,Uo as geomspace,qs as heaviside,Ra as hsplit,Ca as hstack,Na as hypot,To as identity,pa as inner,us as insert,fa as kron,_o as linspace,Eu as load,ei as loadNpy,ni as loadNpySync,Dt as loadNpz,si as loadNpzFile,ii as loadNpzFileSync,Nt as loadNpzSync,Uu as loadSync,Eo as logspace,Ds as median,qo as meshgrid,na as mod,va as moveaxis,$s as nanargmax,Os as nanargmin,Ms as nancumprod,vs as nancumsum,Ts as nanmax,Bs as nanmean,Cs as nanmedian,Us as nanmin,zs as nanprod,Es as nanstd,Is as nansum,_s as nanvar,ta as negative,fn as ones,vo as ones_like,ya as outer,cs as pad,X as parseNpy,gt as parseNpyData,dt as parseNpyHeader,or as parseNpz,Mr as parseNpzSync,Ns as percentile,aa as positive,Ko as power,Ss as ptp,ms as put,ws as quantile,za as rad2deg,xa as radians,ja as ravel,sa as reciprocal,Rs as remainder,La as repeat,Za as reshape,as as resize,Qa as roll,Xa as rollaxis,Ja as rot90,os as row_stack,Tu as save,oi as saveNpy,ai as saveNpySync,Pn as saveNpz,_u as saveNpzSync,Ou as saveSync,$u as savez,vu as savez_compressed,H as serializeNpy,mr as serializeNpz,wt as serializeNpzSync,ea as sign,da as sin,Ba as sinh,Pa as split,Xo as sqrt,Fs as square,Wa as squeeze,Ma as stack,$a as swapaxes,ys as take,ha as tan,Ea as tanh,ma as tensordot,qa as tile,ua as trace,la as transpose,Lo as tri,jo as tril,Zo as triu,Wo as vander,Fa as vsplit,gn as vstack,j as zeros,$o as zeros_like};
3
3
  //# sourceMappingURL=numpy-ts.node-io.mjs.map