numpy-ts 0.8.0 → 0.10.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.
- package/README.md +33 -27
- package/dist/numpy-ts.browser.js +2 -2
- package/dist/numpy-ts.esm.js +2 -2
- package/dist/numpy-ts.node-io.cjs +3 -3
- package/dist/numpy-ts.node-io.cjs.map +4 -4
- package/dist/numpy-ts.node-io.mjs +3 -3
- package/dist/numpy-ts.node-io.mjs.map +4 -4
- package/dist/numpy-ts.node.cjs +2 -2
- package/dist/numpy-ts.node.cjs.map +4 -4
- package/dist/types/core/ndarray.d.ts +887 -0
- package/dist/types/index.d.ts +40 -1
- package/dist/types/ops/advanced.d.ts +7 -0
- package/dist/types/ops/arithmetic.d.ts +49 -0
- package/dist/types/ops/exponential.d.ts +79 -1
- package/dist/types/ops/gradient.d.ts +57 -0
- package/dist/types/ops/linalg.d.ts +220 -0
- package/dist/types/ops/logic.d.ts +201 -0
- package/dist/types/ops/random.d.ts +136 -0
- package/dist/types/ops/rounding.d.ts +36 -0
- package/dist/types/ops/sets.d.ts +38 -0
- package/dist/types/ops/sorting.d.ts +8 -0
- package/dist/types/ops/statistics.d.ts +108 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var tt=Object.defineProperty;var qo=Object.getOwnPropertyDescriptor;var jo=Object.getOwnPropertyNames;var Wo=Object.prototype.hasOwnProperty;var C=(r,t)=>()=>(r&&(t=r(r=0)),t);var Kt=(r,t)=>{for(var e in t)tt(r,e,{get:t[e],enumerable:!0})},Zo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of jo(t))!Wo.call(r,o)&&o!==e&&tt(r,o,{get:()=>t[o],enumerable:!(n=qo(t,o))||n.enumerable});return r};var re=r=>Zo(tt({},"__esModule",{value:!0}),r);function te(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 ee(r,t){let{start:e,stop:n}=r,{step:o,isIndex:a}=r;if(a){if(e===null)throw new Error("Index cannot be null");let s=e<0?t+e:e;if(s<0||s>=t)throw new Error(`Index ${e} is out of bounds for size ${t}`);return{start:s,stop:s+1,step:1,isIndex:!0}}return o>0?(e===null&&(e=0),n===null&&(n=t)):(e===null&&(e=t-1),n===null&&(n=-t-1)),e<0&&(e=t+e),n<0&&(n=t+n),e=Math.max(0,Math.min(e,t)),n=Math.max(-1,Math.min(n,t)),{start:e,stop:n,step:o,isIndex:!1}}var ne=C(()=>{"use strict"});function O(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function ae(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 se(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function oe(r){return r==="float64"||r==="float32"}function x(r){return r==="int64"||r==="uint64"}function k(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(oe(r)||oe(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){let c=t;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}if(t==="float32"){let c=r;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}return"float32"}let e=r.startsWith("int"),n=t.startsWith("int"),o=r.startsWith("uint"),a=t.startsWith("uint"),s=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,i=s(r),u=s(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&i===u){if(i===8)return"int16";if(i===16)return"int32";if(i===32)return"int64"}if(o&&n&&i===u){if(u===8)return"int16";if(u===16)return"int32";if(u===32)return"int64"}if(e&&n||o&&a){let c=Math.max(i,u);return e?c===64?"int64":c===32?"int32":c===16?"int16":"int8":c===64?"uint64":c===32?"uint32":c===16?"uint16":"uint8"}return e&&a?i>u?r:u===8?"int16":u===16?"int32":u===32?"int64":"float64":o&&n?u>i?t:i===8?"int16":i===16?"int32":i===32?"int64":"float64":"float64"}var P,q=C(()=>{"use strict";P="float64"});function j(r){let t=new Array(r.length),e=1;for(let n=r.length-1;n>=0;n--)t[n]=e,e*=r[n];return t}var D,W=C(()=>{"use strict";q();D=class r{constructor(t,e,n,o,a){this._data=t,this._shape=e,this._strides=n,this._offset=o,this._dtype=a}get shape(){return this._shape}get ndim(){return this._shape.length}get size(){return this._shape.reduce((t,e)=>t*e,1)}get dtype(){return this._dtype}get data(){return this._data}get strides(){return this._strides}get offset(){return this._offset}get isCContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=n-1;a>=0;a--){if(e[a]!==o)return!1;o*=t[a]}return!0}get isFContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=0;a<n;a++){if(e[a]!==o)return!1;o*=t[a]}return!0}iget(t){let e=this._shape,n=this._strides,o=e.length;if(o===0)return this._data[this._offset];let a=t,s=this._offset;for(let i=0;i<o;i++){let u=1;for(let f=i+1;f<o;f++)u*=e[f];let c=Math.floor(a/u);a=a%u,s+=c*n[i]}return this._data[s]}iset(t,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let s=t,i=this._offset;for(let u=0;u<a;u++){let c=1;for(let p=u+1;p<a;p++)c*=n[p];let f=Math.floor(s/c);s=s%c,i+=f*o[u]}this._data[i]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];return this._data[n]}set(t,e){let n=this._strides,o=this._offset;for(let a=0;a<t.length;a++)o+=t[a]*n[a];this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=O(e);if(!o)throw new Error(`Cannot copy array with dtype ${e}`);let a=new o(n);if(this.isCContiguous&&this._offset===0)if(x(e)){let s=this._data,i=a;for(let u=0;u<n;u++)i[u]=s[u]}else a.set(this._data);else if(x(e)){let s=a;for(let i=0;i<n;i++)s[i]=this.iget(i)}else for(let s=0;s<n;s++)a[s]=this.iget(s);return new r(a,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let s=o??r._computeStrides(e),i=a??0;return new r(t,e,s,i,n)}static zeros(t,e=P){let n=t.reduce((s,i)=>s*i,1),o=O(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return new r(a,t,r._computeStrides(t),0,e)}static ones(t,e=P){let n=t.reduce((s,i)=>s*i,1),o=O(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return x(e)?a.fill(BigInt(1)):a.fill(1),new r(a,t,r._computeStrides(t),0,e)}static _computeStrides(t){let e=new Array(t.length),n=1;for(let o=t.length-1;o>=0;o--)e[o]=n,n*=t[o];return e}}});function ie(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let s=0;s<o;s++){let i=s<o-e?1:r[s-(o-e)],u=s<o-n?1:t[s-(o-n)];if(i===u)a[s]=i;else if(i===1)a[s]=u;else if(u===1)a[s]=i;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function Go(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let s=0;s<n;s++){let i=o-n+s,u=r[s],c=e[i];if(u===c)a[i]=t[s];else if(u===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function Br(r,t){let e=Go(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function L(r,t,e,n){let o=ie(r.shape,t.shape),a=Br(r,o),s=Br(t,o),i=k(r.dtype,t.dtype),u=D.zeros(o,i),c=u.data,f=u.size;if(x(i)){let p=c;for(let l=0;l<f;l++){let y=a.iget(l),m=s.iget(l),d=typeof y=="bigint"?y:BigInt(Math.round(y)),g=typeof m=="bigint"?m:BigInt(Math.round(m));n==="add"?p[l]=d+g:n==="subtract"?p[l]=d-g:n==="multiply"?p[l]=d*g:n==="divide"?p[l]=d/g:p[l]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let p=x(r.dtype)||x(t.dtype);for(let l=0;l<f;l++){let y=a.iget(l),m=s.iget(l),d=Number(y),g=Number(m);c[l]=e(d,g)}}return u}function K(r,t,e){let n=ie(r.shape,t.shape),o=Br(r,n),a=Br(t,n),s=n.reduce((c,f)=>c*f,1),i=new Uint8Array(s),u=x(r.dtype)||x(t.dtype);for(let c=0;c<s;c++){let f=o.iget(c),p=a.iget(c),l=Number(f),y=Number(p);i[c]=e(l,y)?1:0}return D.fromData(i,n,"bool")}function F(r,t,e=!0){let n=r.dtype,o=Array.from(r.shape),a=r.size,i=e?n:n!=="float32"&&n!=="float64"?"float64":n,u=D.zeros(o,i),c=u.data,f=r.data;if(x(n))if(x(i)){let p=c;for(let l=0;l<a;l++){let y=Number(f[l]);p[l]=BigInt(Math.round(t(y)))}}else for(let p=0;p<a;p++)c[p]=t(Number(f[p]));else for(let p=0;p<a;p++)c[p]=t(Number(f[p]));return u}var er=C(()=>{"use strict";W();q()});function et(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function ue(r,t){return typeof t=="number"?Xo(r,t):et(r,t)?Ho(r,t):L(r,t,(e,n)=>e+n,"add")}function Ho(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p+l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]+p[l]}}else if(x(r.dtype)||x(t.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],p=typeof s[c]=="bigint"?Number(s[c]):s[c];i[c]=f+p}else for(let c=0;c<o;c++)i[c]=a[c]+s[c];return n}function ce(r,t){return typeof t=="number"?Qo(r,t):et(r,t)?Yo(r,t):L(r,t,(e,n)=>e-n,"subtract")}function Yo(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p-l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]-p[l]}}else if(x(r.dtype)||x(t.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],p=typeof s[c]=="bigint"?Number(s[c]):s[c];i[c]=f-p}else for(let c=0;c<o;c++)i[c]=a[c]-s[c];return n}function fe(r,t){return typeof t=="number"?Ko(r,t):et(r,t)?Jo(r,t):L(r,t,(e,n)=>e*n,"multiply")}function Jo(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p*l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]*p[l]}}else if(x(r.dtype)||x(t.dtype))for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?Number(a[c]):a[c],p=typeof s[c]=="bigint"?Number(s[c]):s[c];i[c]=f*p}else for(let c=0;c<o;c++)i[c]=a[c]*s[c];return n}function le(r,t){if(typeof t=="number")return ra(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:sr(r,"float64"),c=n?t:sr(t,"float64");return L(u,c,(f,p)=>f/p,"divide")}if(o||a){let u=o?r:sr(r,"float32"),c=a?t:sr(t,"float32");return L(u,c,(f,p)=>f/p,"divide")}let s=sr(r,"float64"),i=sr(t,"float64");return L(s,i,(u,c)=>u/c,"divide")}function sr(r,t){let e=D.zeros(Array.from(r.shape),t),n=r.size,o=r.data,a=e.data;for(let s=0;s<n;s++)a[s]=Number(o[s]);return e}function Xo(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]+f}else for(let u=0;u<a;u++)i[u]=Number(o[u])+t;return s}function Qo(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]-f}else for(let u=0;u<a;u++)i[u]=Number(o[u])-t;return s}function Ko(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]*f}else for(let u=0;u<a;u++)i[u]=Number(o[u])*t;return s}function ra(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e!=="float32"&&e!=="float64"?"float64":e,u=D.zeros(n,i),c=u.data;if(x(e))for(let f=0;f<a;f++)c[f]=Number(o[f])/t;else for(let f=0;f<a;f++)c[f]=Number(o[f])/t;return u}function pe(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++){let f=i[c];u[c]=f<0n?-f:f}}else for(let i=0;i<o;i++)s[i]=Math.abs(Number(n[i]));return a}function ye(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++)u[c]=-i[c]}else for(let i=0;i<o;i++)s[i]=-Number(n[i]);return a}function me(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++){let f=i[c];u[c]=f>0n?1n:f<0n?-1n:0n}}else for(let i=0;i<o;i++){let u=Number(n[i]);s[i]=u>0?1:u<0?-1:0}return a}function Er(r,t){return typeof t=="number"?ta(r,t):L(r,t,(e,n)=>(e%n+n)%n,"mod")}function ta(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++){let l=u[p];c[p]=(l%f+f)%f}}else for(let u=0;u<a;u++){let c=Number(o[u]);i[u]=(c%t+t)%t}return s}function nt(r,t){return typeof t=="number"?ea(r,t):L(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function ea(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]/f}else for(let u=0;u<a;u++)i[u]=Math.floor(Number(o[u])/t);return s}function de(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;for(let i=0;i<o;i++)s[i]=n[i];return a}function ge(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,s=t!=="float32"&&t!=="float64"?"float64":t,i=D.zeros(e,s),u=i.data;if(x(t))for(let c=0;c<o;c++)u[c]=1/Number(n[c]);else for(let c=0;c<o;c++)u[c]=1/Number(n[c]);return i}function Ae(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,s=t!=="float32"&&t!=="float64"?"float64":t,i=D.zeros(e,s),u=i.data;for(let c=0;c<o;c++)u[c]=Math.cbrt(Number(n[c]));return i}function he(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",s=D.zeros(e,a),i=s.data;for(let u=0;u<o;u++)i[u]=Math.abs(Number(n[u]));return s}function be(r,t){let e=nt(r,t),n=Er(r,t);return[e,n]}function Se(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++)u[c]=i[c]*i[c]}else for(let i=0;i<o;i++){let u=Number(n[i]);s[i]=u*u}return a}function De(r,t){return Er(r,t)}function xe(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",s=D.zeros(n,a),i=s.data;if(typeof t=="number")for(let u=0;u<o;u++){let c=Number(r.data[u]);c<0?i[u]=0:c===0?i[u]=t:i[u]=1}else{let u=t.data,c=t.shape;if(n.every((f,p)=>f===c[p]))for(let f=0;f<o;f++){let p=Number(r.data[f]);p<0?i[f]=0:p===0?i[f]=Number(u[f]):i[f]=1}else for(let f=0;f<o;f++){let p=Number(r.data[f]),l=f%t.size;p<0?i[f]=0:p===0?i[f]=Number(u[l]):i[f]=1}}return s}var Ne=C(()=>{"use strict";W();q();er()});function rr(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);let t=Math.max(...r.map(n=>n.length)),e=new Array(t);for(let n=0;n<t;n++){let o=1;for(let a of r){let s=a.length-t+n,i=s<0?1:a[s];if(i!==1){if(o===1)o=i;else if(o!==i)return null}}e[n]=o}return e}function oa(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let s=0;s<n;s++){let i=o-n+s,u=r[s],c=e[i];if(u===c)a[i]=t[s];else if(u===1)a[i]=0;else throw new Error("Invalid broadcast")}return a}function J(r,t){let e=oa(r.shape,r.strides,t);return D.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function ot(...r){let t=rr(r);if(t===null){let e=r.map(n=>`(${n.join(",")})`).join(" ");throw new Error(`shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between ${e}`)}return t}var at=C(()=>{"use strict";W()});function we(r,t){return typeof t=="number"?aa(r,t):K(r,t,(e,n)=>e>n)}function Ie(r,t){return typeof t=="number"?sa(r,t):K(r,t,(e,n)=>e>=n)}function ze(r,t){return typeof t=="number"?ia(r,t):K(r,t,(e,n)=>e<n)}function _e(r,t){return typeof t=="number"?ua(r,t):K(r,t,(e,n)=>e<=n)}function Be(r,t){return typeof t=="number"?ca(r,t):K(r,t,(e,n)=>e===n)}function Ee(r,t){return typeof t=="number"?fa(r,t):K(r,t,(e,n)=>e!==n)}function st(r,t,e=1e-5,n=1e-8){return typeof t=="number"?la(r,t,e,n):K(r,t,(o,a)=>{let s=Math.abs(o-a),i=n+e*Math.abs(a);return s<=i})}function Te(r,t,e=1e-5,n=1e-8){let o=st(r,t,e,n),a=o.data;for(let s=0;s<o.size;s++)if(a[s]===0)return!1;return!0}function Ue(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=rr(e);if(n===null)return!1;let o=J(r,n),a=J(t,n),s=n.length,i=n.reduce((f,p)=>f*p,1),u=x(o.dtype),c=x(a.dtype);for(let f=0;f<i;f++){let p=f,l=new Array(s);for(let d=s-1;d>=0;d--)l[d]=p%n[d],p=Math.floor(p/n[d]);let y=o.get(...l),m=a.get(...l);if(u||c){let d=typeof y=="bigint"?y:BigInt(Number(y)),g=typeof m=="bigint"?m:BigInt(Number(m));if(d!==g)return!1}else if(y!==m)return!1}return!0}function aa(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 sa(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 ia(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 ua(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 ca(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(x(o)){let a=BigInt(Math.round(t)),s=n;for(let i=0;i<r.size;i++)e[i]=s[i]===a?1:0}else for(let a=0;a<r.size;a++)e[a]=n[a]===t?1:0;return D.fromData(e,Array.from(r.shape),"bool")}function fa(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 la(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,s=r.dtype;if(x(s)){let i=a;for(let u=0;u<r.size;u++){let c=Number(i[u]),f=Math.abs(c-t),p=n+e*Math.abs(t);o[u]=f<=p?1:0}}else for(let i=0;i<r.size;i++){let u=Number(a[i]),c=Math.abs(u-t),f=n+e*Math.abs(t);o[i]=c<=f?1:0}return D.fromData(o,Array.from(r.shape),"bool")}var ve=C(()=>{"use strict";W();q();er();at()});function U(r,t){let e=0,n=1;for(let o=r.length-1;o>=0;o--)e+=r[o]*n,n*=t[o];return e}function v(r,t,e,n){let o=n.length,a=new Array(o),s=Array.from(n).filter((u,c)=>c!==t),i=r;for(let u=s.length-1;u>=0;u--)a[u>=t?u+1:u]=i%s[u],i=Math.floor(i/s[u]);return a[t]=e,a}var it=C(()=>{"use strict"});function pr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0)if(x(n)){let m=i,d=BigInt(0);for(let g=0;g<s;g++)d+=m[g];return Number(d)}else{let m=0;for(let d=0;d<s;d++)m+=Number(i[d]);return m}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==u);if(c.length===0)return pr(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=BigInt(0);for(let A=0;A<l;A++){let b=v(g,u,A,o),S=U(b,o);h+=m[S]}d[g]=h}}else for(let m=0;m<y;m++){let d=0;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o);d+=Number(i[A])}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function Tr(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return pr(r)/r.size;let a=t;if(a<0&&(a=o.length+a),a<0||a>=o.length)throw new Error(`axis ${t} is out of bounds for array of dimension ${o.length}`);let s=pr(r,t,e);if(typeof s=="number")return s/o[a];let i=o[a],u=n;(x(n)||n.startsWith("int")||n.startsWith("uint"))&&(u="float64");let c=D.zeros(Array.from(s.shape),u),f=c.data,p=s.data;if(x(n)){let l=p;for(let y=0;y<f.length;y++)f[y]=Number(l[y])/i}else for(let l=0;l<f.length;l++)f[l]=Number(p[l])/i;return c}function Ur(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0){if(s===0)throw new Error("max of empty array");let m=i[0];for(let d=1;d<s;d++)i[d]>m&&(m=i[d]);return Number(m)}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==u);if(c.length===0)return Ur(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=v(g,u,0,o),A=U(h,o),b=m[A];for(let S=1;S<l;S++){let N=v(g,u,S,o),w=U(N,o),I=m[w];I>b&&(b=I)}d[g]=b}}else for(let m=0;m<y;m++){let d=-1/0;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o),b=Number(i[A]);b>d&&(d=b)}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function ut(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0)if(x(n)){let m=i,d=BigInt(1);for(let g=0;g<s;g++)d*=m[g];return Number(d)}else{let m=1;for(let d=0;d<s;d++)m*=Number(i[d]);return m}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==u);if(c.length===0)return ut(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=BigInt(1);for(let A=0;A<l;A++){let b=v(g,u,A,o),S=U(b,o);h*=m[S]}d[g]=h}}else for(let m=0;m<y;m++){let d=1;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o);d*=Number(i[A])}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function vr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,s=r.size,i=r.data;if(t===void 0){if(s===0)throw new Error("min of empty array");let m=i[0];for(let d=1;d<s;d++)i[d]<m&&(m=i[d]);return Number(m)}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((m,d)=>d!==u);if(c.length===0)return vr(r);let f=D.zeros(c,n),p=f.data,l=o[u],y=c.reduce((m,d)=>m*d,1);if(x(n)){let m=i,d=p;for(let g=0;g<y;g++){let h=v(g,u,0,o),A=U(h,o),b=m[A];for(let S=1;S<l;S++){let N=v(g,u,S,o),w=U(N,o),I=m[w];I<b&&(b=I)}d[g]=b}}else for(let m=0;m<y;m++){let d=1/0;for(let g=0;g<l;g++){let h=v(m,u,g,o),A=U(h,o),b=Number(i[A]);b<d&&(d=b)}p[m]=d}if(e){let m=[...o];return m[u]=1,D.fromData(p,m,n)}return f}function ct(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let y=s[0],m=0;for(let d=1;d<a;d++)s[d]<y&&(y=s[d],m=d);return m}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return ct(r);let c=D.zeros(u,"int32"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);if(x(e)){let y=s;for(let m=0;m<l;m++){let d=v(m,i,0,n),g=U(d,n),h=y[g],A=0;for(let b=1;b<p;b++){let S=v(m,i,b,n),N=U(S,n),w=y[N];w<h&&(h=w,A=b)}f[m]=A}}else for(let y=0;y<l;y++){let m=1/0,d=0;for(let g=0;g<p;g++){let h=v(y,i,g,n),A=U(h,n),b=Number(s[A]);b<m&&(m=b,d=g)}f[y]=d}return c}function ft(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){if(a===0)throw new Error("argmax of empty array");let y=s[0],m=0;for(let d=1;d<a;d++)s[d]>y&&(y=s[d],m=d);return m}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return ft(r);let c=D.zeros(u,"int32"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);if(x(e)){let y=s;for(let m=0;m<l;m++){let d=v(m,i,0,n),g=U(d,n),h=y[g],A=0;for(let b=1;b<p;b++){let S=v(m,i,b,n),N=U(S,n),w=y[N];w>h&&(h=w,A=b)}f[m]=A}}else for(let y=0;y<l;y++){let m=-1/0,d=0;for(let g=0;g<p;g++){let h=v(y,i,g,n),A=U(h,n),b=Number(s[A]);b>m&&(m=b,d=g)}f[y]=d}return c}function lt(r,t,e=0,n=!1){let o=r.shape,a=o.length,s=r.size,i=r.data,u=Tr(r,t,n);if(t===void 0){let h=u,A=0;for(let b=0;b<s;b++){let S=Number(i[b])-h;A+=S*S}return A/(s-e)}let c=t;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let f=o[c],p=u,l=p.data,y=n?p.shape:Array.from(o).filter((h,A)=>A!==c),m=D.zeros(Array.from(y),"float64"),d=m.data,g=y.reduce((h,A)=>h*A,1);for(let h=0;h<g;h++){let A=0,b=Number(l[h]);for(let S=0;S<f;S++){let N=v(h,c,S,o),w=U(N,o),I=Number(i[w])-b;A+=I*I}d[h]=A/(f-e)}return m}function Oe(r,t,e=0,n=!1){let o=lt(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=D.zeros(Array.from(o.shape),"float64"),s=o.data,i=a.data;for(let u=0;u<s.length;u++)i[u]=Math.sqrt(Number(s[u]));return a}function pt(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){for(let y=0;y<a;y++)if(!s[y])return!1;return!0}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return pt(r);let c=D.zeros(u,"bool"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);for(let y=0;y<l;y++){let m=!0;for(let d=0;d<p;d++){let g=v(y,i,d,n),h=U(g,n);if(!s[h]){m=!1;break}}f[y]=m?1:0}if(e){let y=[...n];return y[i]=1,D.fromData(f,y,"bool")}return c}function yt(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,s=r.data;if(t===void 0){for(let y=0;y<a;y++)if(s[y])return!0;return!1}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((y,m)=>m!==i);if(u.length===0)return yt(r);let c=D.zeros(u,"bool"),f=c.data,p=n[i],l=u.reduce((y,m)=>y*m,1);for(let y=0;y<l;y++){let m=!1;for(let d=0;d<p;d++){let g=v(y,i,d,n),h=U(g,n);if(s[h]){m=!0;break}}f[y]=m?1:0}if(e){let y=[...n];return y[i]=1,D.fromData(f,y,"bool")}return c}function mt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=0;for(let d=0;d<l;d++)m+=Number(o[d]),y[d]=m;return D.fromData(y,[l],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++)Math.floor(l/p)%i===0?s[l]=Number(o[l]):s[l]=s[l-p]+Number(o[l]);return D.fromData(s,[...e],"float64")}function dt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=1;for(let d=0;d<l;d++)m*=Number(o[d]),y[d]=m;return D.fromData(y,[l],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++)Math.floor(l/p)%i===0?s[l]=Number(o[l]):s[l]=s[l-p]*Number(o[l]);return D.fromData(s,[...e],"float64")}function gt(r,t,e=!1){let n=Ur(r,t,e),o=vr(r,t,e);if(typeof n=="number"&&typeof o=="number")return n-o;let a=n,s=o,i=a.data,u=s.data,c=new Float64Array(a.size);for(let f=0;f<a.size;f++)c[f]=Number(i[f])-Number(u[f]);return D.fromData(c,[...a.shape],"float64")}function At(r,t,e=!1){return ir(r,.5,t,e)}function ht(r,t,e,n=!1){return ir(r,t/100,e,n)}function ir(r,t,e,n=!1){if(t<0||t>1)throw new Error("Quantile must be between 0 and 1");let o=r.shape,a=o.length,s=r.data;if(e===void 0){let y=[];for(let b=0;b<r.size;b++)y.push(Number(s[b]));y.sort((b,S)=>b-S);let m=y.length,d=t*(m-1),g=Math.floor(d),h=Math.ceil(d);if(g===h)return y[g];let A=d-g;return y[g]*(1-A)+y[h]*A}let i=e;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((y,m)=>m!==i);if(u.length===0)return ir(r,t);let c=u.reduce((y,m)=>y*m,1),f=o[i],p=new Float64Array(c);for(let y=0;y<c;y++){let m=[];for(let b=0;b<f;b++){let S=v(y,i,b,o),N=U(S,o);m.push(Number(s[N]))}m.sort((b,S)=>b-S);let d=m.length,g=t*(d-1),h=Math.floor(g),A=Math.ceil(g);if(h===A)p[y]=m[h];else{let b=g-h;p[y]=m[h]*(1-b)+m[A]*b}}let l=D.fromData(p,u,"float64");if(n){let y=[...o];return y[i]=1,D.fromData(p,y,"float64")}return l}function Or(r,t,e,n=!1){let o=r.shape,a=o.length,s=r.data;if(e===void 0)return Tr(r,t,n);if(t===void 0){let m=0,d=0,g=e.data;for(let h=0;h<r.size;h++){let A=Number(g[h%e.size]);m+=Number(s[h])*A,d+=A}return d===0?NaN:m/d}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((m,d)=>d!==i);if(u.length===0)return Or(r,void 0,e);let c=u.reduce((m,d)=>m*d,1),f=o[i],p=e.data,l=new Float64Array(c);for(let m=0;m<c;m++){let d=0,g=0;for(let h=0;h<f;h++){let A=v(m,i,h,o),b=U(A,o),S=Number(p[h%e.size]);d+=Number(s[b])*S,g+=S}l[m]=g===0?NaN:d/g}let y=D.fromData(l,u,"float64");if(n){let m=[...o];return m[i]=1,D.fromData(l,m,"float64")}return y}function $r(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=0;for(let y=0;y<r.size;y++){let m=Number(a[y]);isNaN(m)||(l+=m)}return l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return $r(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=0;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);isNaN(h)||(y+=h)}f[l]=y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Mr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=1;for(let y=0;y<r.size;y++){let m=Number(a[y]);isNaN(m)||(l*=m)}return l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Mr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=1;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);isNaN(h)||(y*=h)}f[l]=y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Cr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=0,y=0;for(let m=0;m<r.size;m++){let d=Number(a[m]);isNaN(d)||(l+=d,y++)}return y===0?NaN:l/y}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Cr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=0,m=0;for(let d=0;d<c;d++){let g=v(l,s,d,n),h=U(g,n),A=Number(a[h]);isNaN(A)||(y+=A,m++)}f[l]=m===0?NaN:y/m}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function yr(r,t,e=0,n=!1){let o=r.shape,a=o.length,s=r.data;if(t===void 0){let y=0,m=0;for(let h=0;h<r.size;h++){let A=Number(s[h]);isNaN(A)||(y+=A,m++)}if(m-e<=0)return NaN;let d=y/m,g=0;for(let h=0;h<r.size;h++){let A=Number(s[h]);isNaN(A)||(g+=(A-d)**2)}return g/(m-e)}let i=t;if(i<0&&(i=a+i),i<0||i>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let u=Array.from(o).filter((y,m)=>m!==i);if(u.length===0)return yr(r,void 0,e);let c=u.reduce((y,m)=>y*m,1),f=o[i],p=new Float64Array(c);for(let y=0;y<c;y++){let m=0,d=0;for(let A=0;A<f;A++){let b=v(y,i,A,o),S=U(b,o),N=Number(s[S]);isNaN(N)||(m+=N,d++)}if(d-e<=0){p[y]=NaN;continue}let g=m/d,h=0;for(let A=0;A<f;A++){let b=v(y,i,A,o),S=U(b,o),N=Number(s[S]);isNaN(N)||(h+=(N-g)**2)}p[y]=h/(d-e)}let l=D.fromData(p,u,"float64");if(n){let y=[...o];return y[i]=1,D.fromData(p,y,"float64")}return l}function bt(r,t,e=0,n=!1){let o=yr(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=o,s=new Float64Array(a.size);for(let i=0;i<a.size;i++)s[i]=Math.sqrt(Number(a.data[i]));return D.fromData(s,[...a.shape],"float64")}function kr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=1/0;for(let y=0;y<r.size;y++){let m=Number(a[y]);!isNaN(m)&&m<l&&(l=m)}return l===1/0?NaN:l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return kr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=1/0;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);!isNaN(h)&&h<y&&(y=h)}f[l]=y===1/0?NaN:y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Pr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=-1/0;for(let y=0;y<r.size;y++){let m=Number(a[y]);!isNaN(m)&&m>l&&(l=m)}return l===-1/0?NaN:l}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Pr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=-1/0;for(let m=0;m<c;m++){let d=v(l,s,m,n),g=U(d,n),h=Number(a[g]);!isNaN(h)&&h>y&&(y=h)}f[l]=y===-1/0?NaN:y}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}function Vr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=1/0,p=-1;for(let l=0;l<r.size;l++){let y=Number(o[l]);!isNaN(y)&&y<f&&(f=y,p=l)}return p}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=Array.from(e).filter((f,p)=>p!==a);if(s.length===0)return Vr(r);let i=s.reduce((f,p)=>f*p,1),u=e[a],c=new Int32Array(i);for(let f=0;f<i;f++){let p=1/0,l=0;for(let y=0;y<u;y++){let m=v(f,a,y,e),d=U(m,e),g=Number(o[d]);!isNaN(g)&&g<p&&(p=g,l=y)}c[f]=l}return D.fromData(c,s,"int32")}function Fr(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=-1/0,p=-1;for(let l=0;l<r.size;l++){let y=Number(o[l]);!isNaN(y)&&y>f&&(f=y,p=l)}return p}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=Array.from(e).filter((f,p)=>p!==a);if(s.length===0)return Fr(r);let i=s.reduce((f,p)=>f*p,1),u=e[a],c=new Int32Array(i);for(let f=0;f<i;f++){let p=-1/0,l=0;for(let y=0;y<u;y++){let m=v(f,a,y,e),d=U(m,e),g=Number(o[d]);!isNaN(g)&&g>p&&(p=g,l=y)}c[f]=l}return D.fromData(c,s,"int32")}function St(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=0;for(let d=0;d<l;d++){let g=Number(o[d]);isNaN(g)||(m+=g),y[d]=m}return D.fromData(y,[l],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++){let y=Number(o[l]);Math.floor(l/p)%i===0?s[l]=isNaN(y)?0:y:s[l]=s[l-p]+(isNaN(y)?0:y)}return D.fromData(s,[...e],"float64")}function Dt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=r.size,y=new Float64Array(l),m=1;for(let d=0;d<l;d++){let g=Number(o[d]);isNaN(g)||(m*=g),y[d]=m}return D.fromData(y,[l],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let s=new Float64Array(r.size),i=e[a],u=[],c=1;for(let l=n-1;l>=0;l--)u.unshift(c),c*=e[l];let f=r.size,p=u[a];for(let l=0;l<f;l++){let y=Number(o[l]);Math.floor(l/p)%i===0?s[l]=isNaN(y)?1:y:s[l]=s[l-p]*(isNaN(y)?1:y)}return D.fromData(s,[...e],"float64")}function Rr(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let l=[];for(let d=0;d<r.size;d++){let g=Number(a[d]);isNaN(g)||l.push(g)}if(l.length===0)return NaN;l.sort((d,g)=>d-g);let y=l.length,m=Math.floor(y/2);return y%2===0?(l[m-1]+l[m])/2:l[m]}let s=t;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let i=Array.from(n).filter((l,y)=>y!==s);if(i.length===0)return Rr(r);let u=i.reduce((l,y)=>l*y,1),c=n[s],f=new Float64Array(u);for(let l=0;l<u;l++){let y=[];for(let g=0;g<c;g++){let h=v(l,s,g,n),A=U(h,n),b=Number(a[A]);isNaN(b)||y.push(b)}if(y.length===0){f[l]=NaN;continue}y.sort((g,h)=>g-h);let m=y.length,d=Math.floor(m/2);m%2===0?f[l]=(y[d-1]+y[d])/2:f[l]=y[d]}let p=D.fromData(f,i,"float64");if(e){let l=[...n];return l[s]=1,D.fromData(f,l,"float64")}return p}var $e=C(()=>{"use strict";W();q();it()});function G(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((p,l,y)=>y===o?p:p*l,1),f=e/c;if(!Number.isInteger(f))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((p,l)=>l===o?f:p)}else a=t;if(a.reduce((c,f)=>c*f,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){let c=r.data;return D.fromData(c,a,n,j(a),0)}let u=r.copy().data;return D.fromData(u,a,n,j(a),0)}function Lr(r){let t=r.size,e=r.dtype,n=O(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let i=r.data.slice(r.offset,r.offset+t);return D.fromData(i,[t],e,[1],0)}let o=new n(t),a=x(e);for(let s=0;s<t;s++){let i=r.iget(s);o[s]=i}return D.fromData(o,[t],e,[1],0)}function dr(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return D.fromData(n,[t],e,[1],0)}return Lr(r)}function gr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,s=r.dtype,i;if(t===void 0)i=Array.from({length:n},(p,l)=>n-1-l);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let p=new Set;for(let l of t){let y=l<0?n+l:l;if(y<0||y>=n)throw new Error(`axis ${l} is out of bounds for array of dimension ${n}`);if(p.has(y))throw new Error("repeated axis in transpose");p.add(y)}i=t.map(l=>l<0?n+l:l)}let u=i.map(p=>e[p]),c=Array.from(o),f=i.map(p=>c[p]);return D.fromData(a,u,s,f,r.offset)}function Me(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,s=r.dtype;if(t===void 0){let i=[],u=[];for(let c=0;c<n;c++)e[c]!==1&&(i.push(e[c]),u.push(o[c]));return i.length===0&&(i.push(1),u.push(1)),D.fromData(a,i,s,u,r.offset)}else{let i=t<0?n+t:t;if(i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[i]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[i]})`);let u=[],c=[];for(let f=0;f<n;f++)f!==i&&(u.push(e[f]),c.push(o[f]));return D.fromData(a,u,s,c,r.offset)}}function mr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,s=r.dtype,i=t;if(i<0&&(i=n+t+1),i<0||i>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let u=[...Array.from(e)];u.splice(i,0,1);let c=[...Array.from(o)],f=i<n?o[i]*(e[i]||1):1;return c.splice(i,0,f),D.fromData(a,u,s,c,r.offset)}function Ce(r,t,e){let n=r.shape,o=n.length,a=r.strides,s=r.data,i=r.dtype,u=t<0?o+t:t,c=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${o}`);if(c<0||c>=o)throw new Error(`axis2 ${e} is out of bounds for array of dimension ${o}`);if(u===c)return D.fromData(s,Array.from(n),i,Array.from(a),r.offset);let f=Array.from(n),p=Array.from(a);return[f[u],f[c]]=[f[c],f[u]],[p[u],p[c]]=[p[c],p[u]],D.fromData(s,f,i,p,r.offset)}function xt(r,t,e){let n=r.ndim,o=Array.isArray(t)?t:[t],a=Array.isArray(e)?e:[e];if(o.length!==a.length)throw new Error("source and destination must have the same number of elements");let s=o.map(c=>{let f=c<0?n+c:c;if(f<0||f>=n)throw new Error(`source axis ${c} is out of bounds for array of dimension ${n}`);return f}),i=a.map(c=>{let f=c<0?n+c:c;if(f<0||f>=n)throw new Error(`destination axis ${c} is out of bounds for array of dimension ${n}`);return f});if(new Set(s).size!==s.length)throw new Error("repeated axis in source");if(new Set(i).size!==i.length)throw new Error("repeated axis in destination");let u=[];for(let c=0;c<n;c++)s.includes(c)||u.push(c);for(let c=0;c<s.length;c++){let f=i[c];u.splice(f,0,s[c])}return gr(r,u)}function nr(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();let e=r[0],n=e.ndim,o=e.dtype,a=t<0?n+t:t;if(a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);for(let y=1;y<r.length;y++){let m=r[y];if(m.ndim!==n)throw new Error("all the input arrays must have same number of dimensions");for(let d=0;d<n;d++)if(d!==a&&m.shape[d]!==e.shape[d])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}let s=Array.from(e.shape),i=e.shape[a];for(let y=1;y<r.length;y++)i+=r[y].shape[a];s[a]=i;let u=s.reduce((y,m)=>y*m,1),c=O(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let f=new c(u),p=j(s),l=0;for(let y of r){let m=y.shape[a];ma(y,f,s,p,a,l,o),l+=m}return D.fromData(f,s,o)}function ma(r,t,e,n,o,a,s){let i=r.shape,u=i.length,c=r.size,f=s==="int64"||s==="uint64";if(o===0&&r.isCContiguous&&u>0){let y=a*n[0],m=r.data,d=r.offset,g=d+c;t.set(m.subarray(d,g),y);return}if(o===1&&u===2&&r.isCContiguous){let y=i[0],m=i[1],d=e[1],g=r.data,h=r.offset;for(let A=0;A<y;A++){let b=h+A*m,S=A*d+a;t.set(g.subarray(b,b+m),S)}return}let p=new Array(u).fill(0),l=a*n[o];for(let y=0;y<c;y++){let m=r.iget(y),d=l;for(let g=0;g<u;g++)d+=p[g]*n[g];t[d]=m;for(let g=u-1;g>=0&&(p[g]++,!(p[g]<i[g]));g--)p[g]=0}}function ke(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let i=1;i<r.length;i++){let u=r[i];if(u.ndim!==o)throw new Error("all input arrays must have the same shape");for(let c=0;c<o;c++)if(u.shape[c]!==n[c])throw new Error("all input arrays must have the same shape")}let s=r.map(i=>mr(i,a));return nr(s,a)}function Pe(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(e,[1,e.shape[0]]):e);return nr(t,0)}function Nt(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?nr(r,0):nr(r,1)}function Ve(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(mr(G(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?mr(e,2):e);return nr(t,2)}function Fe(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[a],i;if(typeof t=="number"){if(s%t!==0)throw new Error("array split does not result in an equal division");let u=s/t;i=[];for(let c=1;c<t;c++)i.push(c*u)}else i=t;return Re(r,i,a)}function Ar(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[a],i;if(typeof t=="number"){let u=t,c=Math.floor(s/u),f=s%u;i=[];let p=0;for(let l=0;l<u-1;l++)p+=c+(l<f?1:0),i.push(p)}else i=t;return Re(r,i,a)}function Re(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],s=[];for(let i=0;i<a.length-1;i++){let u=a[i],c=a[i+1];if(u>c)throw new Error("split indices must be in ascending order");let f=Array.from(n);f[e]=c-u;let p=r.offset+u*r.strides[e];s.push(D.fromData(r.data,f,r.dtype,Array.from(r.strides),p))}return s}function Le(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return Ar(r,t,0)}function qe(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 Ar(r,t,e)}function je(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],s=Math.max(n,a.length),i=new Array(s).fill(1),u=new Array(s).fill(1);for(let A=0;A<n;A++)i[s-n+A]=e[A];for(let A=0;A<a.length;A++)u[s-a.length+A]=a[A];let c=i.map((A,b)=>A*u[b]),f=c.reduce((A,b)=>A*b,1),p=O(o);if(!p)throw new Error(`Cannot tile array with dtype ${o}`);let l=new p(f),y=j(c),m=r;n<s&&(m=G(r,i));let d=o==="int64"||o==="uint64",g=m.strides,h=new Array(s).fill(0);for(let A=0;A<f;A++){let b=m.offset;for(let w=0;w<s;w++){let I=h[w]%i[w];b+=I*g[w]}let S=m.data[b],N=0;for(let w=0;w<s;w++)N+=h[w]*y[w];l[N]=S;for(let w=s-1;w>=0&&(h[w]++,!(h[w]<c[w]));w--)h[w]=0}return D.fromData(l,c,o)}function We(r,t,e){let n=r.shape,o=n.length,a=r.dtype,s=r.size;if(e===void 0){let A=s,b=Array.isArray(t)?t:new Array(A).fill(t);if(b.length!==A)throw new Error(`operands could not be broadcast together with shape (${A},) (${b.length},)`);let S=b.reduce((z,B)=>z+B,0),N=O(a);if(!N)throw new Error(`Cannot repeat array with dtype ${a}`);let w=new N(S),I=0;for(let z=0;z<A;z++){let B=r.iget(z),E=b[z];for(let T=0;T<E;T++)w[I++]=B}return D.fromData(w,[S],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i],c=Array.isArray(t)?t:new Array(u).fill(t);if(c.length!==u)throw new Error(`operands could not be broadcast together with shape (${u},) (${c.length},)`);let f=Array.from(n);f[i]=c.reduce((A,b)=>A+b,0);let p=f.reduce((A,b)=>A*b,1),l=O(a);if(!l)throw new Error(`Cannot repeat array with dtype ${a}`);let y=new l(p),m=j(f),d=new Array(o).fill(0),g=a==="int64"||a==="uint64",h=[0];for(let A=0;A<u;A++)h.push(h[A]+c[A]);for(let A=0;A<s;A++){let b=r.iget(A),S=d[i],N=c[S],w=0;for(let B=0;B<o;B++)B!==i&&(w+=d[B]*m[B]);let I=m[i],z=h[S];for(let B=0;B<N;B++){let E=w+(z+B)*I;y[E]=b}for(let B=o-1;B>=0&&(d[B]++,!(d[B]<n[B]));B--)d[B]=0}return D.fromData(y,f,a)}function Ze(r,t){let e=r.shape,n=e.length,o=r.dtype,a=r.size,s;if(t===void 0)s=new Set(Array.from({length:n},(l,y)=>y));else if(typeof t=="number"){let l=t<0?n+t:t;if(l<0||l>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);s=new Set([l])}else s=new Set(t.map(l=>{let y=l<0?n+l:l;if(y<0||y>=n)throw new Error(`axis ${l} is out of bounds for array of dimension ${n}`);return y}));let i=O(o);if(!i)throw new Error(`Cannot flip array with dtype ${o}`);let u=new i(a),c=x(o);if(n===1&&r.isCContiguous){let l=r.data,y=r.offset;for(let m=0;m<a;m++)u[m]=l[y+a-1-m];return D.fromData(u,[...e],o)}if(n===2&&r.isCContiguous){let l=e[0],y=e[1],m=r.data,d=r.offset;if(s.size===2){for(let g=0;g<a;g++)u[g]=m[d+a-1-g];return D.fromData(u,[...e],o)}if(s.size===1){if(s.has(0)){for(let g=0;g<l;g++){let h=d+(l-1-g)*y,A=g*y;for(let b=0;b<y;b++)u[A+b]=m[h+b]}return D.fromData(u,[...e],o)}else if(s.has(1)){for(let g=0;g<l;g++){let h=d+g*y,A=g*y;for(let b=0;b<y;b++)u[A+b]=m[h+y-1-b]}return D.fromData(u,[...e],o)}}}let f=new Array(n),p=new Array(n).fill(0);for(let l=0;l<a;l++){for(let d=0;d<n;d++)f[d]=s.has(d)?e[d]-1-p[d]:p[d];let y=r.offset;for(let d=0;d<n;d++)y+=f[d]*r.strides[d];let m=r.data[y];u[l]=m;for(let d=n-1;d>=0&&(p[d]++,!(p[d]<e[d]));d--)p[d]=0}return D.fromData(u,[...e],o)}function Ge(r,t=1,e=[0,1]){let n=r.shape,o=n.length,a=r.dtype;if(o<2)throw new Error("Input must be at least 2-D");let s=e[0]<0?o+e[0]:e[0],i=e[1]<0?o+e[1]:e[1];if(s<0||s>=o||i<0||i>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(s===i)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let u=O(a);if(!u)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[s],c[i]]=[c[i],c[s]]);let f=c.reduce((g,h)=>g*h,1),p=new u(f),l=j(c),y=x(a),m=new Array(o).fill(0),d=new Array(o);for(let g=0;g<r.size;g++){for(let N=0;N<o;N++)d[N]=m[N];let h,A;t===1?(h=n[i]-1-m[i],A=m[s]):t===2?(h=n[s]-1-m[s],A=n[i]-1-m[i],d[s]=h,d[i]=A):(h=m[i],A=n[s]-1-m[s]),t!==2&&(d[s]=h,d[i]=A);let b=0;for(let N=0;N<o;N++)b+=d[N]*l[N];let S=r.iget(g);p[b]=S;for(let N=o-1;N>=0&&(m[N]++,!(m[N]<n[N]));N--)m[N]=0}return D.fromData(p,c,a)}function He(r,t,e){let n=r.shape,o=n.length,a=r.dtype,s=r.size;if(e===void 0){let m=Array.isArray(t)?t.reduce((b,S)=>b+S,0):t,d=Lr(r),g=O(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let h=new g(s),A=x(a);for(let b=0;b<s;b++){let S=((b-m)%s+s)%s,N=d.iget(S);h[b]=N}return D.fromData(h,[...n],a)}let i=Array.isArray(t)?t:[t],u=Array.isArray(e)?e:[e];if(i.length!==u.length)throw new Error("shift and axis must have the same length");let c=u.map(m=>{let d=m<0?o+m:m;if(d<0||d>=o)throw new Error(`axis ${m} is out of bounds for array of dimension ${o}`);return d}),f=O(a);if(!f)throw new Error(`Cannot roll array with dtype ${a}`);let p=new f(s),l=x(a),y=new Array(o).fill(0);for(let m=0;m<s;m++){let d=[...y];for(let A=0;A<c.length;A++){let b=c[A],S=n[b],N=i[A];d[b]=((d[b]-N)%S+S)%S}let g=r.offset;for(let A=0;A<o;A++)g+=d[A]*r.strides[A];let h=r.data[g];p[m]=h;for(let A=o-1;A>=0&&(y[A]++,!(y[A]<n[A]));A--)y[A]=0}return D.fromData(p,[...n],a)}function Ye(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):xt(r,o,a)}function Je(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return Ar(r,t,2)}function Xe(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(e,[e.shape[0],1]):e);return Nt(t)}function Qe(r,t){let e=r.dtype,n=t.reduce((u,c)=>u*c,1),o=r.size,a=O(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let s=new a(n),i=x(e);for(let u=0;u<n;u++){let c=u%o,f=r.iget(c);s[u]=f}return D.fromData(s,t,e)}function Ke(r){return r.map(t=>t.ndim===0?G(t,[1]):t)}function rn(r){return r.map(t=>t.ndim===0?G(t,[1,1]):t.ndim===1?G(t,[1,t.shape[0]]):t)}function tn(r){return r.map(t=>t.ndim===0?G(t,[1,1,1]):t.ndim===1?G(t,[1,t.shape[0],1]):t.ndim===2?G(t,[t.shape[0],t.shape[1],1]):t)}var wt=C(()=>{"use strict";W();q()});function da(r,t,e,n,o,a,s,i,u,c,f,p,l,y){if(p===0)for(let h=0;h<n*o;h++)l[h]=0;else if(p!==1)for(let h=0;h<n*o;h++)l[h]=(l[h]??0)*p;let m=r==="row-major",d=t==="transpose",g=e==="transpose";if(m&&!d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[h*u+S]??0)*(c[S*f+A]??0);l[h*y+A]=(l[h*y+A]??0)+s*b}else if(m&&d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[S*u+h]??0)*(c[S*f+A]??0);l[h*y+A]=(l[h*y+A]??0)+s*b}else if(m&&!d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[h*u+S]??0)*(c[A*f+S]??0);l[h*y+A]=(l[h*y+A]??0)+s*b}else if(m&&d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[S*u+h]??0)*(c[A*f+S]??0);l[h*y+A]=(l[h*y+A]??0)+s*b}else if(!m&&!d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[S*u+h]??0)*(c[A*f+S]??0);l[A*y+h]=(l[A*y+h]??0)+s*b}else if(!m&&d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[h*u+S]??0)*(c[A*f+S]??0);l[A*y+h]=(l[A*y+h]??0)+s*b}else if(!m&&!d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[S*u+h]??0)*(c[S*f+A]??0);l[A*y+h]=(l[A*y+h]??0)+s*b}else for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let S=0;S<a;S++)b+=(i[h*u+S]??0)*(c[S*f+A]??0);l[A*y+h]=(l[A*y+h]??0)+s*b}}function zt(r,t){let e=r.ndim,n=t.ndim;if(e===0||n===0){let o=e===0?r.get():null,a=n===0?t.get():null;if(e===0&&n===0)return typeof o=="bigint"&&typeof a=="bigint"?o*a:Number(o)*Number(a);if(e===0){let s=k(r.dtype,t.dtype),i=D.zeros([...t.shape],s);for(let u=0;u<t.size;u++){let c=t.data[u+t.offset];typeof o=="bigint"&&typeof c=="bigint"?i.data[u]=o*c:i.data[u]=Number(o)*Number(c)}return i}else{let s=k(r.dtype,t.dtype),i=D.zeros([...r.shape],s);for(let u=0;u<r.size;u++){let c=r.data[u+r.offset];typeof c=="bigint"&&typeof a=="bigint"?i.data[u]=c*a:i.data[u]=Number(c)*Number(a)}return i}}if(e===1&&n===1){if(r.shape[0]!==t.shape[0])throw new Error(`dot: incompatible shapes (${r.shape[0]},) and (${t.shape[0]},)`);let o=r.shape[0],a=0;for(let s=0;s<o;s++){let i=r.get(s),u=t.get(s);typeof i=="bigint"&&typeof u=="bigint"?a=Number(a)+Number(i*u):a+=Number(i)*Number(u)}return a}if(e===2&&n===2)return or(r,t);if(e===2&&n===1){let[o,a]=r.shape,s=t.shape[0];if(a!==s)throw new Error(`dot: incompatible shapes (${o},${a}) and (${s},)`);let i=k(r.dtype,t.dtype),u=D.zeros([o],i);for(let c=0;c<o;c++){let f=0;for(let p=0;p<a;p++){let l=r.get(c,p),y=t.get(p);typeof l=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(l*y):f+=Number(l)*Number(y)}u.set([c],f)}return u}if(e===1&&n===2){let o=r.shape[0],[a,s]=t.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${s})`);let i=k(r.dtype,t.dtype),u=D.zeros([s],i);for(let c=0;c<s;c++){let f=0;for(let p=0;p<o;p++){let l=r.get(p),y=t.get(p,c);typeof l=="bigint"&&typeof y=="bigint"?f=Number(f)+Number(l*y):f+=Number(l)*Number(y)}u.set([c],f)}return u}if(e>2&&n===1){let o=r.shape[e-1],a=t.shape[0];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and (${a},)`);let s=[...r.shape.slice(0,-1)],i=k(r.dtype,t.dtype),u=D.zeros(s,i),c=s.reduce((f,p)=>f*p,1);for(let f=0;f<c;f++){let p=0,l=f,y=[];for(let m=s.length-1;m>=0;m--)y[m]=l%s[m],l=Math.floor(l/s[m]);for(let m=0;m<o;m++){let d=[...y,m],g=r.get(...d),h=t.get(m);typeof g=="bigint"&&typeof h=="bigint"?p=Number(p)+Number(g*h):p+=Number(g)*Number(h)}u.set(y,p)}return u}if(e===1&&n>2){let o=r.shape[0],a=1,s=t.shape[a];if(o!==s)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(t.shape)}`);let i=[...t.shape.slice(0,a),...t.shape.slice(a+1)],u=k(r.dtype,t.dtype),c=D.zeros(i,u),f=i.reduce((p,l)=>p*l,1);for(let p=0;p<f;p++){let l=p,y=[];for(let h=i.length-1;h>=0;h--)y[h]=l%i[h],l=Math.floor(l/i[h]);let m=y.slice(0,a),d=y.slice(a),g=0;for(let h=0;h<o;h++){let A=r.get(h),b=[...m,h,...d],S=t.get(...b);typeof A=="bigint"&&typeof S=="bigint"?g=Number(g)+Number(A*S):g+=Number(A)*Number(S)}c.set(y,g)}return c}if(e>=2&&n>=2&&!(e===2&&n===2)){let o=r.shape[e-1],a=t.shape[n-2];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and ${JSON.stringify(t.shape)}`);let s=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],i=k(r.dtype,t.dtype),u=D.zeros(s,i),c=r.shape.slice(0,-1).reduce((y,m)=>y*m,1),f=t.shape.slice(0,-2).reduce((y,m)=>y*m,1),p=t.shape[n-1],l=o;for(let y=0;y<c;y++)for(let m=0;m<f;m++)for(let d=0;d<p;d++){let g=0;for(let A=0;A<l;A++){let b=y*l+A,S=r.data[b+r.offset],N=m*l*p+A*p+d,w=t.data[N+t.offset];typeof S=="bigint"&&typeof w=="bigint"?g=Number(g)+Number(S*w):g+=Number(S)*Number(w)}let h=y*f*p+m*p+d;u.data[h]=g}return u}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function or(r,t){if(r.ndim!==2||t.ndim!==2)throw new Error("matmul requires 2D arrays");let[e=0,n=0]=r.shape,[o=0,a=0]=t.shape;if(n!==o)throw new Error(`matmul shape mismatch: (${e},${n}) @ (${o},${a})`);let s=k(r.dtype,t.dtype),i=s.startsWith("int")||s.startsWith("uint")||s==="bool"?"float64":s;if(i!=="float64")throw new Error(`matmul currently only supports float64, got ${i}`);let u=r.dtype==="float64"?r.data:Float64Array.from(Array.from(r.data).map(Number)),c=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number));r.offset>0&&(u=u.subarray(r.offset)),t.offset>0&&(c=c.subarray(t.offset));let[f=0,p=0]=r.strides,[l=0,y=0]=t.strides,m=p>f,d=y>l,g=m?"transpose":"no-transpose",h=d?"transpose":"no-transpose",A,b;m?A=p:A=f,d?b=y:b=l;let S=D.zeros([e,a],"float64");return da("row-major",g,h,e,a,n,1,u,A,c,b,0,S.data,a),S}function on(r){if(r.ndim!==2)throw new Error(`trace requires 2D array, got ${r.ndim}D`);let[t=0,e=0]=r.shape,n=Math.min(t,e),o=0;for(let a=0;a<n;a++){let s=r.get(a,a);typeof s=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+s:o=(typeof o=="bigint"?Number(o):o)+s}return o}function nn(r,t){return gr(r,t)}function an(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 zt(r,t);let s=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],i=k(r.dtype,t.dtype),u=D.zeros(s,i),c=e===1?1:r.shape.slice(0,-1).reduce((l,y)=>l*y,1),f=n===1?1:t.shape.slice(0,-1).reduce((l,y)=>l*y,1),p=o;for(let l=0;l<c;l++)for(let y=0;y<f;y++){let m=0;for(let g=0;g<p;g++){let h=e===1?g:l*p+g,A=n===1?g:y*p+g,b=r.data[h+r.offset],S=t.data[A+t.offset];typeof b=="bigint"&&typeof S=="bigint"?m=Number(m)+Number(b*S):m+=Number(b)*Number(S)}if(s.length===0)return m;let d=c===1?y:l*f+y;u.data[d]=m}return u}function _t(r,t){let e=r.ndim===1?r:dr(r),n=t.ndim===1?t:dr(t),o=e.size,a=n.size,s=k(r.dtype,t.dtype),i=D.zeros([o,a],s);for(let u=0;u<o;u++)for(let c=0;c<a;c++){let f=e.get(u),p=n.get(c),l;typeof f=="bigint"&&typeof p=="bigint"?l=f*p:l=Number(f)*Number(p),i.set([u,c],l)}return i}function sn(r,t,e){let n,o;if(typeof e=="number"){let l=e;if(l<0)throw new Error("tensordot: axes must be non-negative");if(l>r.ndim||l>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:l},(y,m)=>r.ndim-l+m),o=Array.from({length:l},(y,m)=>m)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let l=0;l<n.length;l++){let y=n[l],m=o[l];if(y<0||y>=r.ndim||m<0||m>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[y]!==t.shape[m])throw new Error(`tensordot: shape mismatch on axes ${y} and ${m}: ${r.shape[y]} != ${t.shape[m]}`)}let a=[],s=[];for(let l=0;l<r.ndim;l++)n.includes(l)||a.push(l);for(let l=0;l<t.ndim;l++)o.includes(l)||s.push(l);let i=[...a.map(l=>r.shape[l]),...s.map(l=>t.shape[l])];if(i.length===0){let l=0,y=n.map(m=>r.shape[m]).reduce((m,d)=>m*d,1);for(let m=0;m<y;m++){let d=m,g=new Array(n.length);for(let N=n.length-1;N>=0;N--){let w=n[N];g[N]=d%r.shape[w],d=Math.floor(d/r.shape[w])}let h=new Array(r.ndim),A=new Array(t.ndim);for(let N=0;N<n.length;N++)h[n[N]]=g[N];for(let N=0;N<o.length;N++)A[o[N]]=g[N];let b=r.get(...h),S=t.get(...A);typeof b=="bigint"&&typeof S=="bigint"?l=Number(l)+Number(b*S):l+=Number(b)*Number(S)}return l}let u=k(r.dtype,t.dtype),c=D.zeros(i,u),f=i.reduce((l,y)=>l*y,1),p=n.map(l=>r.shape[l]).reduce((l,y)=>l*y,1);for(let l=0;l<f;l++){let y=l,m=[];for(let A=i.length-1;A>=0;A--)m[A]=y%i[A],y=Math.floor(y/i[A]);let d=m.slice(0,a.length),g=m.slice(a.length),h=0;for(let A=0;A<p;A++){y=A;let b=[];for(let z=n.length-1;z>=0;z--){let B=n[z];b[z]=y%r.shape[B],y=Math.floor(y/r.shape[B])}let S=new Array(r.ndim),N=new Array(t.ndim);for(let z=0;z<a.length;z++)S[a[z]]=d[z];for(let z=0;z<s.length;z++)N[s[z]]=g[z];for(let z=0;z<n.length;z++)S[n[z]]=b[z],N[o[z]]=b[z];let w=r.get(...S),I=t.get(...N);typeof w=="bigint"&&typeof I=="bigint"?h=Number(h)+Number(w*I):h+=Number(w)*Number(I)}c.set(m,h)}return c}function un(r,t=0,e=0,n=1){let o=r.shape,a=o.length;if(a<2)throw new Error("diagonal requires an array of at least two dimensions");let s=e<0?a+e:e,i=n<0?a+n:n;if(s<0||s>=a||i<0||i>=a)throw new Error("axis out of bounds");if(s===i)throw new Error("axis1 and axis2 cannot be the same");let u=o[s],c=o[i],f;t>=0?f=Math.max(0,Math.min(u,c-t)):f=Math.max(0,Math.min(u+t,c));let p=[];for(let d=0;d<a;d++)d!==s&&d!==i&&p.push(o[d]);p.push(f);let l=D.zeros(p,r.dtype),y=o.filter((d,g)=>g!==s&&g!==i),m=y.reduce((d,g)=>d*g,1);for(let d=0;d<m;d++){let g=d,h=[];for(let A=y.length-1;A>=0;A--)h.unshift(g%y[A]),g=Math.floor(g/y[A]);for(let A=0;A<f;A++){let b=new Array(a),S=0;for(let I=0;I<a;I++)I===s?b[I]=t>=0?A:A-t:I===i?b[I]=t>=0?A+t:A:b[I]=h[S++];let N=[...h,A],w=r.get(...b);l.set(N,w)}}return l}function cn(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=ga(n)):(n=r.slice(0,e),o=r.slice(e+2));let a=n.split(",").map(d=>d.trim());if(a.length!==t.length)throw new Error(`einsum: expected ${a.length} operands, got ${t.length}`);let s=new Map;for(let d=0;d<t.length;d++){let g=a[d],h=t[d];if(g.length!==h.ndim)throw new Error(`einsum: operand ${d} has ${h.ndim} dimensions but subscript '${g}' has ${g.length} indices`);for(let A=0;A<g.length;A++){let b=g[A],S=h.shape[A];if(s.has(b)){if(s.get(b)!==S)throw new Error(`einsum: size mismatch for index '${b}': ${s.get(b)} vs ${S}`)}else s.set(b,S)}}for(let d of o)if(!s.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let i=new Set(o),u=new Set;for(let d of a)for(let g of d)u.add(g);let c=[];for(let d of u)i.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,g]=a,[h,A]=t;if(d.length===2&&g.length===2&&o.length===2&&h.ndim===2&&A.ndim===2){let[b,S]=[d[0],d[1]],[N,w]=[g[0],g[1]],[I,z]=[o[0],o[1]];if(b===I&&w===z&&S===N&&c.length===1&&c[0]===S||b===I&&w===z&&S===N&&c.length===1&&c[0]===S)return or(h,A);if(S===I&&w===z&&b===N&&c.length===1&&c[0]===b){let B=nn(h);return or(B,A)}if(b===I&&N===z&&S===w&&c.length===1&&c[0]===S){let B=nn(A);return or(h,B)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&h.ndim===1&&A.ndim===1)return It(t,a,c,s);if(d&&g&&d.length===1&&g.length===1&&o.length===2&&o===d+g&&c.length===0&&h.ndim===1&&A.ndim===1)return _t(h,A)}if(t.length===1&&a[0].length===2&&o.length===0){let d=a[0];if(d[0]===d[1]&&t[0].ndim===2)return It(t,a,c,s)}let f=Array.from(o).map(d=>s.get(d));if(f.length===0)return It(t,a,c,s);let p=t[0].dtype;for(let d=1;d<t.length;d++)p=k(p,t[d].dtype);let l=D.zeros(f,p),y=f.reduce((d,g)=>d*g,1),m=1;for(let d of c)m*=s.get(d);for(let d=0;d<y;d++){let g=Aa(d,f),h=new Map;for(let b=0;b<o.length;b++)h.set(o[b],g[b]);let A=0;for(let b=0;b<m;b++){let S=b;for(let w=c.length-1;w>=0;w--){let I=c[w],z=s.get(I);h.set(I,S%z),S=Math.floor(S/z)}let N=1;for(let w=0;w<t.length;w++){let I=t[w],z=a[w],B=[];for(let T of z)B.push(h.get(T));let E=I.get(...B);N*=Number(E)}A+=N}l.set(g,A)}return l}function ga(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 s of e)o*=n.get(s);let a=0;for(let s=0;s<o;s++){let i=new Map,u=s;for(let f=e.length-1;f>=0;f--){let p=e[f],l=n.get(p);i.set(p,u%l),u=Math.floor(u/l)}let c=1;for(let f=0;f<r.length;f++){let p=r[f],l=t[f],y=[];for(let d of l)y.push(i.get(d));let m=p.get(...y);c*=Number(m)}a+=c}return a}function Aa(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 fn(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,s=k(r.dtype,t.dtype),i=Math.max(o,a),u=new Array(i),c=new Array(i).fill(1),f=new Array(i).fill(1);for(let m=0;m<o;m++)c[i-o+m]=e[m];for(let m=0;m<a;m++)f[i-a+m]=n[m];for(let m=0;m<i;m++)u[m]=c[m]*f[m];let p=D.zeros(u,s),l=e.reduce((m,d)=>m*d,1),y=n.reduce((m,d)=>m*d,1);for(let m=0;m<l;m++){let d=m,g=new Array(o);for(let b=o-1;b>=0;b--)g[b]=d%e[b],d=Math.floor(d/e[b]);let h=new Array(i).fill(0);for(let b=0;b<o;b++)h[i-o+b]=g[b];let A=r.get(...g);for(let b=0;b<y;b++){let S=b,N=new Array(a);for(let E=a-1;E>=0;E--)N[E]=S%n[E],S=Math.floor(S/n[E]);let w=new Array(i).fill(0);for(let E=0;E<a;E++)w[i-a+E]=N[E];let I=t.get(...N),z=new Array(i);for(let E=0;E<i;E++)z[E]=h[E]*f[E]+w[E];let B=typeof A=="bigint"||typeof I=="bigint"?BigInt(Number(A))*BigInt(Number(I)):Number(A)*Number(I);p.set(z,B)}}return p}var ln=C(()=>{"use strict";W();q();wt()});function pn(r){return F(r,Math.sqrt,!1)}function yn(r,t){return typeof t=="number"?ba(r,t):L(r,t,Math.pow,"power")}function ba(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,u=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,c=D.zeros(n,u),f=c.data;if(x(e))if(x(u)&&Number.isInteger(t)&&t>=0){let p=o,l=f;for(let y=0;y<a;y++)l[y]=p[y]**BigInt(t)}else for(let p=0;p<a;p++)f[p]=Math.pow(Number(o[p]),t);else for(let p=0;p<a;p++)f[p]=Math.pow(Number(o[p]),t);return c}var mn=C(()=>{"use strict";W();er();q()});function dn(r){return F(r,Math.sin,!1)}function gn(r){return F(r,Math.cos,!1)}function An(r){return F(r,Math.tan,!1)}function hn(r){return F(r,Math.asin,!1)}function bn(r){return F(r,Math.acos,!1)}function Sn(r){return F(r,Math.atan,!1)}function Dn(r,t){return typeof t=="number"?xa(r,t):Da(r,t)}function Da(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,s=o==="float32"&&a==="float32"?"float32":"float64",i=D.zeros(e,s),u=i.data;for(let c=0;c<n;c++){let f=(x(o),Number(r.data[c])),p=(x(a),Number(t.data[c]));u[c]=Math.atan2(f,p)}return i}function xa(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e==="float32"?"float32":"float64",i=D.zeros(n,s),u=i.data;if(x(e))for(let c=0;c<a;c++)u[c]=Math.atan2(Number(o[c]),t);else for(let c=0;c<a;c++)u[c]=Math.atan2(Number(o[c]),t);return i}function xn(r,t){return typeof t=="number"?wa(r,t):Na(r,t)}function Na(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,s=o==="float32"&&a==="float32"?"float32":"float64",i=D.zeros(e,s),u=i.data;for(let c=0;c<n;c++){let f=(x(o),Number(r.data[c])),p=(x(a),Number(t.data[c]));u[c]=Math.hypot(f,p)}return i}function wa(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e==="float32"?"float32":"float64",i=D.zeros(n,s),u=i.data;if(x(e))for(let c=0;c<a;c++)u[c]=Math.hypot(Number(o[c]),t);else for(let c=0;c<a;c++)u[c]=Math.hypot(Number(o[c]),t);return i}function Nn(r){let t=180/Math.PI;return F(r,e=>e*t,!1)}function wn(r){let t=Math.PI/180;return F(r,e=>e*t,!1)}var In=C(()=>{"use strict";W();er();q()});function zn(r){return F(r,Math.sinh,!1)}function _n(r){return F(r,Math.cosh,!1)}function Bn(r){return F(r,Math.tanh,!1)}function En(r){return F(r,Math.asinh,!1)}function Tn(r){return F(r,Math.acosh,!1)}function Un(r){return F(r,Math.atanh,!1)}var vn=C(()=>{"use strict";er()});function Bt(r,t){let e=r.shape,n=e.length,o=t.length;if(o<n)throw new Error("input operand has more dimensions than allowed by the axis remapping");let a=rr([Array.from(e),t]);if(a===null)throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);for(let s=0;s<o;s++)if(a[s]!==t[s])throw new Error(`operands could not be broadcast together with shape (${e.join(",")}) (${t.join(",")})`);return J(r,t)}function On(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=rr(t);if(e===null)throw new Error(`operands could not be broadcast together with shapes ${t.map(n=>`(${n.join(",")})`).join(" ")}`);return r.map(n=>J(n,e))}function $n(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let m=r.size;for(let A of t){let b=A<0?m+A:A;if(b<0||b>=m)throw new Error(`index ${A} is out of bounds for axis 0 with size ${m}`)}let d=t.length,g=O(a);if(!g)throw new Error(`Cannot take from array with dtype ${a}`);let h=new g(d);for(let A=0;A<d;A++){let b=t[A];b<0&&(b=m+b);let S=r.iget(b);x(a),h[A]=S}return D.fromData(h,[d],a)}let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[s];for(let m of t){let d=m<0?i+m:m;if(d<0||d>=i)throw new Error(`index ${m} is out of bounds for axis ${s} with size ${i}`)}let u=Array.from(n);u[s]=t.length;let c=u.reduce((m,d)=>m*d,1),f=O(a);if(!f)throw new Error(`Cannot take from array with dtype ${a}`);let p=new f(c),l=j(u),y=new Array(o).fill(0);for(let m=0;m<c;m++){let d=[...y],g=y[s],h=t[g];h<0&&(h=i+h),d[s]=h;let A=r.get(...d),b=0;for(let S=0;S<o;S++)b+=y[S]*l[S];x(a),p[b]=A;for(let S=o-1;S>=0&&(y[S]++,!(y[S]<u[S]));S--)y[S]=0}return D.fromData(p,u,a)}function Mn(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=new Array(t.length).fill(e);else{a=[];for(let s=0;s<e.size;s++)a.push(e.iget(s));if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let s=[...a];a=[];for(let i=0;i<t.length;i++)a.push(s[i%s.length])}}for(let s=0;s<t.length;s++){let i=t[s];if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`index ${t[s]} is out of bounds for axis 0 with size ${n}`);let u=a[s];x(o)?typeof u!="bigint"&&(u=BigInt(Math.round(Number(u)))):typeof u=="bigint"&&(u=Number(u)),r.iset(i,u)}}function Cn(r,t){if(t.length===0)throw new Error("choices cannot be empty");let e=r.shape,n=t.length,o=t[0].dtype,a=t.map(l=>Array.from(l.shape));a.unshift(Array.from(e));let s=rr(a);if(s===null)throw new Error("operands could not be broadcast together");let i=J(r,s),u=t.map(l=>J(l,s)),c=s.reduce((l,y)=>l*y,1),f=O(o);if(!f)throw new Error(`Cannot choose with dtype ${o}`);let p=new f(c);for(let l=0;l<c;l++){let y=Number(i.iget(l));if(y<0||y>=n)throw new Error(`index ${y} is out of bounds for axis 0 with size ${n}`);let m=u[y].iget(l);x(o),p[l]=m}return D.fromData(p,s,o)}function kn(r,t,e=!1){if(r.ndim!==t.ndim)return!1;for(let o=0;o<r.ndim;o++)if(r.shape[o]!==t.shape[o])return!1;let n=r.size;for(let o=0;o<n;o++){let a=r.iget(o),s=t.iget(o);if(e){let i=typeof a=="number"&&Number.isNaN(a),u=typeof s=="number"&&Number.isNaN(s);if(i&&u)continue}if(a!==s)return!1}return!0}function Pn(r,t,e){let n=r.shape,o=n.length,a=r.dtype,s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=t.shape;if(i.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${i.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==s&&i[d]!==n[d]&&i[d]!==1&&n[d]!==1)throw new Error(`index ${i[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let u=Array.from(i),c=u.reduce((d,g)=>d*g,1),f=O(a);if(!f)throw new Error(`Cannot take_along_axis with dtype ${a}`);let p=new f(c),l=j(n),y=j(i),m=n[s];for(let d=0;d<c;d++){let g=new Array(o),h=d;for(let I=o-1;I>=0;I--)g[I]=h%u[I],h=Math.floor(h/u[I]);let A=0;for(let I=0;I<o;I++){let z=i[I]===1?0:g[I];A+=z*y[I]}let b=Number(t.iget(A));if(b<0&&(b=m+b),b<0||b>=m)throw new Error(`index ${b} is out of bounds for axis ${s} with size ${m}`);let S=[...g];S[s]=b;let N=0;for(let I=0;I<o;I++){let z=n[I]===1?0:S[I];N+=z*l[I]}let w=r.iget(N);x(a),p[d]=w}return D.fromData(p,u,a)}function Vn(r,t,e,n){let o=r.shape,a=o.length,s=r.dtype,i=n<0?a+n:n;if(i<0||i>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let u=t.shape,c=e.shape;if(u.length!==a||c.length!==a)throw new Error("indices, arr, and values must have same ndim");let f=o[i],p=j(o),l=j(u),y=j(c),m=u.reduce((d,g)=>d*g,1);for(let d=0;d<m;d++){let g=new Array(a),h=d;for(let z=a-1;z>=0;z--)g[z]=h%u[z],h=Math.floor(h/u[z]);let A=0;for(let z=0;z<a;z++)A+=g[z]*l[z];let b=Number(t.iget(A));if(b<0&&(b=f+b),b<0||b>=f)throw new Error(`index ${b} is out of bounds for axis ${i} with size ${f}`);let S=0;for(let z=0;z<a;z++){let B=c[z]===1?0:g[z];S+=B*y[z]}let N=e.iget(S),w=[...g];w[i]=b;let I=0;for(let z=0;z<a;z++)I+=w[z]*p[z];x(s)?typeof N!="bigint"&&(N=BigInt(Math.round(Number(N)))):typeof N=="bigint"&&(N=Number(N)),r.iset(I,N)}}function Fn(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i))}let s=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[s%a.length];x(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),s++}}function Rn(r,t,e){let n=t.shape,o=n.length,a=t.dtype,s=t.data,i=x(a);if(e===void 0){let A=0,b=Math.min(r.size,t.size);for(let I=0;I<b;I++)r.iget(I)&&A++;let S=O(a);if(!S)throw new Error(`Cannot compress with dtype ${a}`);let N=new S(A),w=0;for(let I=0;I<b;I++)r.iget(I)&&(N[w]=s[I],w++);return D.fromData(N,[A],a)}let u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let c=n[u],f=Math.min(r.size,c),p=[];for(let A=0;A<f;A++)r.iget(A)&&p.push(A);let l=p.length,y=[...n];y[u]=l;let m=y.reduce((A,b)=>A*b,1),d=O(a);if(!d)throw new Error(`Cannot compress with dtype ${a}`);let g=new d(m),h=j(n);if(u===0){let A=h[0],b=n.slice(1).reduce((N,w)=>N*w,1),S=0;for(let N=0;N<l;N++){let I=p[N]*A;if(i){let z=s,B=g;for(let E=0;E<b;E++)B[S++]=z[I+E]}else{let z=s,B=g;for(let E=0;E<b;E++)B[S++]=z[I+E]}}}else{let A=n.slice(0,u).reduce((N,w)=>N*w,1),b=n.slice(u+1).reduce((N,w)=>N*w,1),S=0;for(let N=0;N<A;N++)for(let w=0;w<l;w++){let I=p[w],z=0,B=N;for(let E=u-1;E>=0;E--){let T=B%n[E];B=Math.floor(B/n[E]),z+=T*h[E]}if(z+=I*h[u],i){let E=s,T=g;for(let $=0;$<b;$++)T[S++]=E[z+$]}else{let E=s,T=g;for(let $=0;$<b;$++)T[S++]=E[z+$]}}}return D.fromData(g,y,a)}function Ln(r,t,e=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");let n=[...r.map(l=>Array.from(l.shape)),...t.map(l=>Array.from(l.shape))],o=rr(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,s=o.reduce((l,y)=>l*y,1),i=O(a);if(!i)throw new Error(`Cannot select with dtype ${a}`);let u=e;x(a)?u=typeof e=="bigint"?e:BigInt(e):u=typeof e=="bigint"?Number(e):e;let c=new i(s);for(let l=0;l<s;l++)x(a),c[l]=u;let f=r.map(l=>J(l,o)),p=t.map(l=>J(l,o));for(let l=0;l<s;l++)for(let y=0;y<r.length;y++)if(f[y].iget(l)){let m=p[y].iget(l);x(a),c[l]=m;break}return D.fromData(c,o,a)}function qn(r,t,e){let n=r.size,o=r.dtype,a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i));if(a.length===0)return;let s=0;for(let i=0;i<n;i++)if(t.iget(i)){let c=a[s%a.length];x(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(i,c),s++}}function Et(r,t=2){if(t<1)throw new Error("ndim must be at least 1");let e=new Int32Array(r);for(let o=0;o<r;o++)e[o]=o;let n=[];for(let o=0;o<t;o++)n.push(D.fromData(new Int32Array(e),[r],"int32"));return n}function jn(r){let t=r.shape,e=t.length;if(e<2)throw new Error("array must be at least 2-D");let n=t[0];for(let o=1;o<e;o++)if(t[o]!==n)throw new Error("All dimensions of input must be equal");return Et(n,e)}function Tt(r,t=0,e){let n=e??r,o=[],a=[];for(let s=0;s<r;s++)for(let i=0;i<=Math.min(s+t,n-1);i++)i>=0&&(o.push(s),a.push(i));return[D.fromData(new Int32Array(o),[o.length],"int32"),D.fromData(new Int32Array(a),[a.length],"int32")]}function Wn(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return Tt(e[0],t,e[1])}function Ut(r,t=0,e){let n=e??r,o=[],a=[];for(let s=0;s<r;s++)for(let i=Math.max(s+t,0);i<n;i++)o.push(s),a.push(i);return[D.fromData(new Int32Array(o),[o.length],"int32"),D.fromData(new Int32Array(a),[a.length],"int32")]}function Zn(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return Ut(e[0],t,e[1])}function Gn(r,t,e=0){let n=t(r,e),o=n.shape;if(o.length!==2||o[0]!==r||o[1]!==r)throw new Error("mask_func must return n x n array");let a=[],s=[];for(let i=0;i<r;i++)for(let u=0;u<r;u++)n.get(i,u)&&(a.push(i),s.push(u));return[D.fromData(new Int32Array(a),[a.length],"int32"),D.fromData(new Int32Array(s),[s.length],"int32")]}function Hn(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((u,c)=>u*c,1),a=O(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let s=new a(o),i=r.reduce((u,c)=>u*c,1);for(let u=0;u<e;u++){let c=u*i;for(let f=0;f<i;f++){let p=new Array(e),l=f;for(let m=e-1;m>=0;m--)p[m]=l%r[m],l=Math.floor(l/r[m]);let y=p[u];t==="int64"?s[c+f]=BigInt(y):s[c+f]=y}}return D.fromData(s,n,t)}function Yn(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,s=o.dtype,i=new Array(t).fill(1);i[n]=a;let u=O(s);if(!u)throw new Error(`Cannot create ix_ with dtype ${s}`);let c=new u(a);for(let f=0;f<a;f++){let p=o.iget(f);x(s),c[f]=p}e.push(D.fromData(c,i,s))}return e}function Jn(r,t,e="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");let n=r[0].size,o=t.length,a=new Int32Array(n),s=new Array(o),i=1;for(let u=o-1;u>=0;u--)s[u]=i,i*=t[u];for(let u=0;u<n;u++){let c=0;for(let f=0;f<o;f++){let p=Number(r[f].iget(u)),l=t[f];if(e==="wrap")p=(p%l+l)%l;else if(e==="clip")p=Math.max(0,Math.min(p,l-1));else if(p<0||p>=l)throw new Error(`index ${p} is out of bounds for axis ${f} with size ${l}`);c+=p*s[f]}a[u]=c}return D.fromData(a,[n],"int32")}function Xn(r,t,e="C"){let n=t.length,o,a;if(typeof r=="number")o=[r],a=[];else{o=[];for(let f=0;f<r.size;f++)o.push(Number(r.iget(f)));a=Array.from(r.shape)}let s=o.length,i=t.reduce((f,p)=>f*p,1),u=new Array(n);if(e==="C"){let f=1;for(let p=n-1;p>=0;p--)u[p]=f,f*=t[p]}else{let f=1;for(let p=0;p<n;p++)u[p]=f,f*=t[p]}let c=[];for(let f=0;f<n;f++){let p=new Int32Array(s);c.push(D.fromData(p,a.length?a:[1],"int32"))}for(let f=0;f<s;f++){let p=o[f];if(p<0||p>=i)throw new Error(`index ${p} is out of bounds for array with size ${i}`);if(e==="C")for(let l=0;l<n;l++){let y=Math.floor(p/u[l]);p=p%u[l],c[l].data[f]=y%t[l]}else for(let l=n-1;l>=0;l--){let y=Math.floor(p/u[l]);p=p%u[l],c[l].data[f]=y%t[l]}}return typeof r=="number"?c.map(f=>{let p=f.iget(0);return D.fromData(new Int32Array([Number(p)]),[],"int32")}):c}var Qn=C(()=>{"use strict";W();q();at()});function Y(r,t){if(!se(r)&&r!=="bool")throw new TypeError(`ufunc '${t}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function hr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function to(r,t){return Y(r.dtype,"bitwise_and"),typeof t=="number"?Ea(r,t):(Y(t.dtype,"bitwise_and"),hr(r,t)?Ba(r,t):L(r,t,(e,n)=>e&n,"bitwise_and"))}function Ba(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p&l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]&p[l]}}else for(let u=0;u<o;u++)i[u]=a[u]&s[u];return n}function Ea(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]&f}else for(let u=0;u<a;u++)i[u]=o[u]&t;return s}function eo(r,t){return Y(r.dtype,"bitwise_or"),typeof t=="number"?Ua(r,t):(Y(t.dtype,"bitwise_or"),hr(r,t)?Ta(r,t):L(r,t,(e,n)=>e|n,"bitwise_or"))}function Ta(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p|l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]|p[l]}}else for(let u=0;u<o;u++)i[u]=a[u]|s[u];return n}function Ua(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]|f}else for(let u=0;u<a;u++)i[u]=o[u]|t;return s}function no(r,t){return Y(r.dtype,"bitwise_xor"),typeof t=="number"?Oa(r,t):(Y(t.dtype,"bitwise_xor"),hr(r,t)?va(r,t):L(r,t,(e,n)=>e^n,"bitwise_xor"))}function va(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;if(!x(r.dtype)||!x(t.dtype))for(let f=0;f<o;f++){let p=typeof a[f]=="bigint"?a[f]:BigInt(Math.round(Number(a[f]))),l=typeof s[f]=="bigint"?s[f]:BigInt(Math.round(Number(s[f])));u[f]=p^l}else{let f=a,p=s;for(let l=0;l<o;l++)u[l]=f[l]^p[l]}}else for(let u=0;u<o;u++)i[u]=a[u]^s[u];return n}function Oa(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]^f}else for(let u=0;u<a;u++)i[u]=o[u]^t;return s}function vt(r){Y(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=D.zeros(e,t),s=a.data;if(x(t)){let i=n,u=s;for(let c=0;c<o;c++)u[c]=~i[c]}else for(let i=0;i<o;i++)s[i]=~n[i];return a}function oo(r){return vt(r)}function ao(r,t){if(Y(r.dtype,"left_shift"),typeof t=="number")return Kn(r,t);if(Y(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=x(t.dtype)?Number(t.data[0]):t.data[0];return Kn(r,e)}return hr(r,t)?$a(r,t):L(r,t,(e,n)=>e<<n,"left_shift")}function $a(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),p=typeof s[c]=="bigint"?s[c]:BigInt(Math.round(Number(s[c])));u[c]=f<<p}}else for(let u=0;u<o;u++)i[u]=a[u]<<s[u];return n}function Kn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]<<f}else for(let u=0;u<a;u++)i[u]=o[u]<<t;return s}function so(r,t){if(Y(r.dtype,"right_shift"),typeof t=="number")return ro(r,t);if(Y(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=x(t.dtype)?Number(t.data[0]):t.data[0];return ro(r,e)}return hr(r,t)?Ma(r,t):L(r,t,(e,n)=>e>>n,"right_shift")}function Ma(r,t){let e=k(r.dtype,t.dtype),n=D.zeros(Array.from(r.shape),e),o=r.size,a=r.data,s=t.data,i=n.data;if(x(e)){let u=i;for(let c=0;c<o;c++){let f=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),p=typeof s[c]=="bigint"?s[c]:BigInt(Math.round(Number(s[c])));u[c]=f>>p}}else for(let u=0;u<o;u++)i[u]=a[u]>>s[u];return n}function ro(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=D.zeros(n,e),i=s.data;if(x(e)){let u=o,c=i,f=BigInt(Math.round(t));for(let p=0;p<a;p++)c[p]=u[p]>>f}else for(let u=0;u<a;u++)i[u]=o[u]>>t;return s}function io(r,t=-1,e="big"){let n=Array.from(r.shape),o=n.length;if(t<0&&(t=o+t),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=n[t],s=Math.ceil(a/8),i=[...n];i[t]=s;let u=D.zeros(i,"uint8"),c=u.data;if(o===1){for(let g=0;g<s;g++){let h=0;for(let A=0;A<8;A++){let b=g*8+A;if(b<a){let S=Number(r.data[b])!==0?1:0;e==="big"?h|=S<<7-A:h|=S<<A}}c[g]=h}return u}let f=n.slice(0,t),p=n.slice(t+1),l=f.reduce((g,h)=>g*h,1),y=p.reduce((g,h)=>g*h,1),m=qr(n),d=qr(i);for(let g=0;g<l;g++)for(let h=0;h<y;h++)for(let A=0;A<s;A++){let b=0;for(let I=0;I<8;I++){let z=A*8+I;if(z<a){let B=0,E=g;for(let M=0;M<t;M++){let R=M<t-1?f.slice(M+1).reduce((Kr,rt)=>Kr*rt,1):1,H=Math.floor(E/R);E%=R,B+=H*m[M]}B+=z*m[t];let T=h;for(let M=t+1;M<o;M++){let R=M<o-1?p.slice(M-t).reduce((Kr,rt)=>Kr*rt,1):1,H=Math.floor(T/R);T%=R,B+=H*m[M]}let $=Number(r.data[B])!==0?1:0;e==="big"?b|=$<<7-I:b|=$<<I}}let S=0,N=g;for(let I=0;I<t;I++){let z=I<t-1?f.slice(I+1).reduce((E,T)=>E*T,1):1,B=Math.floor(N/z);N%=z,S+=B*d[I]}S+=A*d[t];let w=h;for(let I=t+1;I<o;I++){let z=I<o-1?p.slice(I-t).reduce((E,T)=>E*T,1):1,B=Math.floor(w/z);w%=z,S+=B*d[I]}c[S]=b}return u}function uo(r,t=-1,e=-1,n="big"){if(r.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");let o=Array.from(r.shape),a=o.length;if(t<0&&(t=a+t),t<0||t>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let s=o[t],i=s*8;e>=0&&(i=e);let u=[...o];u[t]=i;let c=D.zeros(u,"uint8"),f=c.data;if(a===1){for(let h=0;h<s;h++){let A=Number(r.data[h]);for(let b=0;b<8;b++){let S=h*8+b;if(S>=i)break;n==="big"?f[S]=A>>7-b&1:f[S]=A>>b&1}}return c}let p=o.slice(0,t),l=o.slice(t+1),y=p.reduce((h,A)=>h*A,1),m=l.reduce((h,A)=>h*A,1),d=qr(o),g=qr(u);for(let h=0;h<y;h++)for(let A=0;A<m;A++)for(let b=0;b<s;b++){let S=0,N=h;for(let z=0;z<t;z++){let B=z<t-1?p.slice(z+1).reduce((T,$)=>T*$,1):1,E=Math.floor(N/B);N%=B,S+=E*d[z]}S+=b*d[t];let w=A;for(let z=t+1;z<a;z++){let B=z<a-1?l.slice(z-t).reduce((T,$)=>T*$,1):1,E=Math.floor(w/B);w%=B,S+=E*d[z]}let I=Number(r.data[S]);for(let z=0;z<8;z++){let B=b*8+z;if(B>=i)break;let E=0;N=h;for(let T=0;T<t;T++){let $=T<t-1?p.slice(T+1).reduce((R,H)=>R*H,1):1,M=Math.floor(N/$);N%=$,E+=M*g[T]}E+=B*g[t],w=A;for(let T=t+1;T<a;T++){let $=T<a-1?l.slice(T-t).reduce((R,H)=>R*H,1):1,M=Math.floor(w/$);w%=$,E+=M*g[T]}n==="big"?f[E]=I>>7-z&1:f[E]=I>>z&1}}return c}function qr(r){let t=r.length,e=new Array(t),n=1;for(let o=t-1;o>=0;o--)e[o]=n,n*=r[o];return e}var co=C(()=>{"use strict";W();q();er()});function Ot(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return r.copy();let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=r.copy(),u=i.data,c=e[s],f=Array.from(e).filter((l,y)=>y!==s),p=f.length===0?1:f.reduce((l,y)=>l*y,1);if(x(o)){let l=a,y=u;for(let m=0;m<p;m++){let d=[];for(let g=0;g<c;g++){let h=v(m,s,g,e),A=U(h,e);d.push({value:l[A],idx:g})}d.sort((g,h)=>g.value<h.value?-1:g.value>h.value?1:0);for(let g=0;g<c;g++){let h=v(m,s,g,e),A=U(h,e);y[A]=d[g].value}}}else for(let l=0;l<p;l++){let y=[];for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);y.push(Number(a[g]))}y.sort((m,d)=>isNaN(m)&&isNaN(d)?0:isNaN(m)?1:isNaN(d)?-1:m-d);for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);u[g]=y[m]}}return i}function $t(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return D.zeros([0],"int32");let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=D.zeros(Array.from(e),"int32"),u=i.data,c=e[s],f=Array.from(e).filter((l,y)=>y!==s),p=f.length===0?1:f.reduce((l,y)=>l*y,1);if(x(o)){let l=a;for(let y=0;y<p;y++){let m=[];for(let d=0;d<c;d++){let g=v(y,s,d,e),h=U(g,e);m.push({value:l[h],idx:d})}m.sort((d,g)=>d.value<g.value?-1:d.value>g.value?1:0);for(let d=0;d<c;d++){let g=v(y,s,d,e),h=U(g,e);u[h]=m[d].idx}}}else for(let l=0;l<p;l++){let y=[];for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);y.push({value:Number(a[g]),idx:m})}y.sort((m,d)=>isNaN(m.value)&&isNaN(d.value)?0:isNaN(m.value)?1:isNaN(d.value)?-1:m.value-d.value);for(let m=0;m<c;m++){let d=v(l,s,m,e),g=U(d,e);u[g]=y[m].idx}}return i}function fo(r){if(r.length===0)return D.zeros([0],"int32");let e=r[0].size;for(let s of r){if(s.ndim!==1)throw new Error("keys must be 1D arrays");if(s.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let s=0;s<e;s++)n.push(s);n.sort((s,i)=>{for(let u=r.length-1;u>=0;u--){let f=r[u].data,p=Number(f[s]),l=Number(f[i]);if(!(isNaN(p)&&isNaN(l))){if(isNaN(p))return 1;if(isNaN(l)||p<l)return-1;if(p>l)return 1}}return 0});let o=D.zeros([e],"int32"),a=o.data;for(let s=0;s<e;s++)a[s]=n[s];return o}function ka(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],s=r[o],i=r[n],u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u];[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++){let l=r[p],y=isNaN(l),m=isNaN(c);!y&&(m||l<=c)&&([r[f],r[p]]=[r[p],r[f]],f++)}if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function Pa(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],s=r[o],i=r[n],u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u];[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++)r[p]<=c&&([r[f],r[p]]=[r[p],r[f]],f++);if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function Va(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,s=r[o].value,i=r[n].value,u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u].value;[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++){let l=r[p].value,y=isNaN(l),m=isNaN(c);!y&&(m||l<=c)&&([r[f],r[p]]=[r[p],r[f]],f++)}if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function Fa(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,s=r[o].value,i=r[n].value,u;a<=s&&s<=i||i<=s&&s<=a?u=o:s<=a&&a<=i||i<=a&&a<=s?u=e:u=n;let c=r[u].value;[r[u],r[n]]=[r[n],r[u]];let f=e;for(let p=e;p<n;p++)r[p].value<=c&&([r[f],r[p]]=[r[p],r[f]],f++);if([r[f],r[n]]=[r[n],r[f]],f===t)return;f<t?e=f+1:n=f-1}}function Mt(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype;if(o===0)return r.copy();let s=e;if(s<0&&(s=o+s),s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[s],u=t;if(u<0&&(u=i+u),u<0||u>=i)throw new Error(`kth(=${t}) out of bounds (${i})`);let c=r.copy(),f=c.data,p=Array.from(n).filter((y,m)=>m!==s),l=p.length===0?1:p.reduce((y,m)=>y*m,1);if(x(a)){let y=f;for(let m=0;m<l;m++){let d=[];for(let g=0;g<i;g++){let h=v(m,s,g,n),A=U(h,n);d.push(y[A])}Pa(d,u);for(let g=0;g<i;g++){let h=v(m,s,g,n),A=U(h,n);y[A]=d[g]}}}else for(let y=0;y<l;y++){let m=[];for(let d=0;d<i;d++){let g=v(y,s,d,n),h=U(g,n);m.push(Number(f[h]))}ka(m,u);for(let d=0;d<i;d++){let g=v(y,s,d,n),h=U(g,n);f[h]=m[d]}}return c}function Ct(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,s=r.data;if(o===0)return D.zeros([0],"int32");let i=e;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i],c=t;if(c<0&&(c=u+c),c<0||c>=u)throw new Error(`kth(=${t}) out of bounds (${u})`);let f=D.zeros(Array.from(n),"int32"),p=f.data,l=Array.from(n).filter((m,d)=>d!==i),y=l.length===0?1:l.reduce((m,d)=>m*d,1);if(x(a)){let m=s;for(let d=0;d<y;d++){let g=[];for(let h=0;h<u;h++){let A=v(d,i,h,n),b=U(A,n);g.push({value:m[b],idx:h})}Fa(g,c);for(let h=0;h<u;h++){let A=v(d,i,h,n),b=U(A,n);p[b]=g[h].idx}}}else for(let m=0;m<y;m++){let d=[];for(let g=0;g<u;g++){let h=v(m,i,g,n),A=U(h,n);d.push({value:Number(s[A]),idx:g})}Va(d,c);for(let g=0;g<u;g++){let h=v(m,i,g,n),A=U(h,n);p[A]=d[g].idx}}return f}function lo(r){let t=r.dtype,e=r.size,n=r.data,o=[];for(let i=0;i<e;i++)o.push(Number(n[i]));o.sort((i,u)=>isNaN(i)&&isNaN(u)?0:isNaN(i)?1:isNaN(u)?-1:i-u);let a=D.zeros([e],t),s=a.data;for(let i=0;i<e;i++)s[i]=o[i];return a}function jr(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=[];for(let f=0;f<e;f++)a.push([]);let s=[],i=1;for(let f=e-1;f>=0;f--)s.unshift(i),i*=t[f];for(let f=0;f<o;f++)if(n[f]){let p=f;for(let l=0;l<e;l++){let y=Math.floor(p/s[l]);p=p%s[l],a[l].push(y)}}let u=a[0]?.length??0,c=[];for(let f=0;f<e;f++){let p=D.zeros([u],"int32"),l=p.data;for(let y=0;y<u;y++)l[y]=a[f][y];c.push(p)}return c}function po(r){let t=r.data,e=r.size,n=[];for(let s=0;s<e;s++)t[s]&&n.push(s);let o=D.zeros([n.length],"int32"),a=o.data;for(let s=0;s<n.length;s++)a[s]=n[s];return o}function yo(r,t,e){if(t===void 0&&e===void 0)return jr(r);if(t===void 0||e===void 0)throw new Error("either both or neither of x and y should be given");let n=r.shape,o=t.shape,a=e.shape,s=Math.max(n.length,o.length,a.length),i=B=>{let E=Array(s).fill(1);for(let T=0;T<B.length;T++)E[s-B.length+T]=B[T];return E},u=i(n),c=i(o),f=i(a),p=[];for(let B=0;B<s;B++){let E=[u[B],c[B],f[B]],T=Math.max(...E);for(let $ of E)if($!==1&&$!==T)throw new Error("operands could not be broadcast together");p.push(T)}let l=t.dtype,y=D.zeros(p,l),m=y.data,d=r.data,g=t.data,h=e.data,A=(B,E)=>{let T=[],$=1;for(let M=B.length-1;M>=0;M--)T.unshift($),$*=B[M];for(;T.length<E.length;)T.unshift(0);for(let M=0;M<E.length;M++)E[M]===1&&p[M]!==1&&(T[M]=0);return T},b=A(n,u),S=A(o,c),N=A(a,f),w=[],I=1;for(let B=p.length-1;B>=0;B--)w.unshift(I),I*=p[B];let z=p.reduce((B,E)=>B*E,1);for(let B=0;B<z;B++){let E=B,T=0,$=0,M=0;for(let R=0;R<s;R++){let H=Math.floor(E/w[R]);E=E%w[R],T+=H*b[R],$+=H*S[R],M+=H*N[R]}d[T]?m[B]=g[$]:m[B]=h[M]}return y}function kt(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.data,o=r.size,a=t.data,s=t.size,i=D.zeros([s],"int32"),u=i.data;for(let c=0;c<s;c++){let f=Number(a[c]),p=0,l=o;if(e==="left")for(;p<l;){let y=Math.floor((p+l)/2);Number(n[y])<f?p=y+1:l=y}else for(;p<l;){let y=Math.floor((p+l)/2);Number(n[y])<=f?p=y+1:l=y}u[c]=p}return i}function mo(r,t){let e=r.data,n=t.data,o=t.dtype,a=Math.min(r.size,t.size),s=0;for(let f=0;f<a;f++)e[f]&&s++;let i=D.zeros([s],o),u=i.data,c=0;if(x(o)){let f=n,p=u;for(let l=0;l<a;l++)e[l]&&(p[c++]=f[l])}else for(let f=0;f<a;f++)e[f]&&(u[c++]=n[f]);return i}function Pt(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size;if(t===void 0){let l=0;for(let y=0;y<a;y++)o[y]&&l++;return l}let s=t;if(s<0&&(s=n+s),s<0||s>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,y)=>y!==s);if(i.length===0)return Pt(r);let u=D.zeros(i,"int32"),c=u.data,f=e[s],p=i.reduce((l,y)=>l*y,1);for(let l=0;l<p;l++){let y=0;for(let m=0;m<f;m++){let d=v(l,s,m,e),g=U(d,e);o[g]&&y++}c[l]=y}return u}var go=C(()=>{"use strict";W();q();it()});function X(r,t=P){let e=D.zeros(r,t);return new _(e)}function Ao(r,t=P){let e=D.ones(r,t);return new _(e)}function La(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function ho(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>ho(t)):!1}function qa(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function V(r,t){if(r instanceof _)return!t||r.dtype===t?r.copy():r.astype(t);let e=ho(r),n=La(r),o=n.reduce((f,p)=>f*p,1),a=t;a||(e?a="int64":a=P);let s=O(a);if(!s)throw new Error(`Cannot create array with dtype ${a}`);let i=new s(o),u=qa(r);if(x(a)){let f=i;for(let p=0;p<o;p++){let l=u[p];f[p]=typeof l=="bigint"?l:BigInt(Math.round(Number(l)))}}else if(a==="bool"){let f=i;for(let p=0;p<o;p++)f[p]=u[p]?1:0}else{let f=i;for(let p=0;p<o;p++){let l=u[p];f[p]=Number(l)}}let c=D.fromData(i,n,a);return new _(c)}function ja(r,t,e=1,n=P){let o=r,a=t;if(t===void 0&&(o=0,a=r),a===void 0)throw new Error("stop is required");let s=Math.max(0,Math.ceil((a-o)/e)),i=O(n);if(!i)throw new Error(`Cannot create arange array with dtype ${n}`);let u=new i(s);if(x(n))for(let f=0;f<s;f++)u[f]=BigInt(Math.round(o+f*e));else if(n==="bool")for(let f=0;f<s;f++)u[f]=o+f*e!==0?1:0;else for(let f=0;f<s;f++)u[f]=o+f*e;let c=D.fromData(u,[s],n);return new _(c)}function Wa(r,t,e=50,n=P){if(e<0)throw new Error("num must be non-negative");if(e===0)return V([],n);if(e===1)return V([r],n);let o=O(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),s=(t-r)/(e-1);if(x(n))for(let u=0;u<e;u++)a[u]=BigInt(Math.round(r+u*s));else if(n==="bool")for(let u=0;u<e;u++)a[u]=r+u*s!==0?1:0;else for(let u=0;u<e;u++)a[u]=r+u*s;let i=D.fromData(a,[e],n);return new _(i)}function Za(r,t,e=50,n=10,o=P){if(e<0)throw new Error("num must be non-negative");if(e===0)return V([],o);if(e===1)return V([Math.pow(n,r)],o);let a=O(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let s=new a(e),i=(t-r)/(e-1);if(x(o))for(let c=0;c<e;c++){let f=r+c*i;s[c]=BigInt(Math.round(Math.pow(n,f)))}else if(o==="bool")for(let c=0;c<e;c++){let f=r+c*i;s[c]=Math.pow(n,f)!==0?1:0}else for(let c=0;c<e;c++){let f=r+c*i;s[c]=Math.pow(n,f)}let u=D.fromData(s,[e],o);return new _(u)}function Ga(r,t,e=50,n=P){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 V([],n);if(e===1)return V([r],n);let o=Math.sign(r),a=Math.sign(t);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let s=O(n);if(!s)throw new Error(`Cannot create geomspace array with dtype ${n}`);let i=new s(e),u=Math.log(Math.abs(r)),f=(Math.log(Math.abs(t))-u)/(e-1);if(x(n))for(let l=0;l<e;l++){let y=o*Math.exp(u+l*f);i[l]=BigInt(Math.round(y))}else if(n==="bool")for(let l=0;l<e;l++){let y=o*Math.exp(u+l*f);i[l]=y!==0?1:0}else for(let l=0;l<e;l++){let y=o*Math.exp(u+l*f);i[l]=y}let p=D.fromData(i,[e],n);return new _(p)}function bo(r,t,e=0,n=P){let o=t??r,a=X([r,o],n),s=a.data;if(x(n)){let i=s;for(let u=0;u<r;u++){let c=u+e;c>=0&&c<o&&(i[u*o+c]=BigInt(1))}}else{let i=s;for(let u=0;u<r;u++){let c=u+e;c>=0&&c<o&&(i[u*o+c]=1)}}return a}function So(r,t=P){return X(r,t)}function Do(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=P);let o=O(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((u,c)=>u*c,1),s=new o(a);if(x(n)){let u=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));s.fill(u)}else n==="bool"?s.fill(t?1:0):s.fill(Number(t));let i=D.fromData(s,r,n);return new _(i)}function Ha(r,t=P){return bo(r,r,0,t)}function Wr(r,t){return r instanceof _?!t||r.dtype===t?r:r.astype(t):V(r,t)}function Ya(r){return r.copy()}function Ja(r,t){return X(Array.from(r.shape),t??r.dtype)}function Xa(r,t){return Ao(Array.from(r.shape),t??r.dtype)}function Qa(r,t){return So(Array.from(r.shape),t??r.dtype)}function Ka(r,t,e){return Do(Array.from(r.shape),t,e??r.dtype)}function rs(r,t){return Wr(r,t)}function ts(r,t){let e=Wr(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function es(r,t){return Wr(r,t).copy()}function xo(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=X([n,n],r.dtype);for(let a=0;a<e;a++){let s=t>=0?a:a-t,i=t>=0?a+t:a;o.set([s,i],r.get([a]))}return o}else if(r.ndim===2){let[e,n]=r.shape,o,a,s;if(t>=0?(o=0,a=t,s=Math.min(e,n-t)):(o=-t,a=0,s=Math.min(e+t,n)),s<=0)return X([0],r.dtype);let i=O(r.dtype),u=new i(s);for(let f=0;f<s;f++){let p=r.get([o+f,a+f]);x(r.dtype)?u[f]=typeof p=="bigint"?p:BigInt(p):u[f]=p}let c=D.fromData(u,[s],r.dtype);return new _(c)}else throw new Error("Input must be 1-D or 2-D")}function ns(r,t=0){let e=r.flatten();return xo(e,t)}function os(r,t,e=P){let n=t.reduce((c,f)=>c*f,1),o=O(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),s=t.length,i=new Array(s).fill(0);for(let c=0;c<n;c++){let f=r(...i);x(e)?a[c]=typeof f=="bigint"?f:BigInt(Number(f)):e==="bool"?a[c]=f?1:0:a[c]=Number(f);for(let p=s-1;p>=0&&(i[p]++,!(i[p]<t[p]));p--)i[p]=0}let u=D.fromData(a,t,e);return new _(u)}function as(...r){let t=[],e="xy";for(let i of r)i instanceof _?t.push(i):typeof i=="object"&&"indexing"in i&&(e=i.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(i=>i.size);e==="xy"&&t.length>=2&&(t=[t[1],t[0],...t.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,s=[];for(let i=0;i<t.length;i++){let u=t[i],c=u.size,f=new Array(a).fill(1);f[i]=c;let p=u.reshape(...f),l=Bt(p.storage,o),y=_._fromStorage(l.copy());s.push(y)}return e==="xy"&&s.length>=2&&([s[0],s[1]]=[s[1],s[0]]),s}function ss(r,t,e=0,n=P){let o=t??r,a=X([r,o],n);for(let s=0;s<r;s++)for(let i=0;i<=s+e&&i<o;i++)i>=0&&a.set([s,i],1);return a}function is(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],s=n.slice(0,-2).reduce((i,u)=>i*u,1);for(let i=0;i<s;i++)for(let u=0;u<o;u++)for(let c=0;c<a;c++)if(c>u+t){let f=[],p=i;for(let l=n.length-3;l>=0;l--)f.unshift(p%n[l]),p=Math.floor(p/n[l]);f.push(u,c),e.set(f,0)}return e}function us(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],s=n.slice(0,-2).reduce((i,u)=>i*u,1);for(let i=0;i<s;i++)for(let u=0;u<o;u++)for(let c=0;c<a;c++)if(c<u+t){let f=[],p=i;for(let l=n.length-3;l>=0;l--)f.unshift(p%n[l]),p=Math.floor(p/n[l]);f.push(u,c),e.set(f,0)}return e}function cs(r,t,e=!1){if(r.ndim!==1)throw new Error("Input must be 1-D");let n=r.size,o=t??n;if(o<0)throw new Error("N must be non-negative");let a=X([n,o],r.dtype);for(let s=0;s<n;s++){let i=r.get([s]);for(let u=0;u<o;u++){let c=e?u:o-1-u;a.set([s,u],Math.pow(i,c))}}return a}function fs(r,t=P,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let s=ms(t),i=o.byteLength-a,u=Math.floor(i/s),c=e<0?u:Math.min(e,u);if(c<=0)return V([],t);let f=O(t);if(!f)throw new Error(`Unsupported dtype: ${t}`);let p=new f(o,a,c),l=D.fromData(p,[c],t);return new _(l)}function ls(r,t=P,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return V(n,t)}function ps(r,t=P,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return V(n,t)}function ys(r,t=P,e=-1,n=""){let o;n===""?o=r.trim().split(/\s+/):o=r.split(n);let a=[],s=0;for(let i of o){if(e>=0&&s>=e)break;let u=i.trim();u!==""&&(x(t)?a.push(BigInt(u)):a.push(parseFloat(u)),s++)}return V(a,t)}function ms(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 ds(r){return r.sqrt()}function gs(r,t){return r.power(t)}function As(r){return r.absolute()}function hs(r){return r.negative()}function bs(r){return r.sign()}function Ss(r,t){return r.mod(t)}function Ds(r,t){return r.floor_divide(t)}function xs(r){return r.positive()}function Ns(r){return r.reciprocal()}function ws(r,t){return r.dot(t)}function Is(r){return r.trace()}function zs(r,t=0,e=0,n=1){let o=un(r.storage,t,e,n);return _._fromStorage(o)}function _s(r,t){let e=fn(r.storage,t.storage);return _._fromStorage(e)}function Bs(r,t){return r.transpose(t)}function Es(r,t){return r.inner(t)}function Ts(r,t){return r.outer(t)}function Us(r,t,e=2){return r.tensordot(t,e)}function vs(r){return r.sin()}function Os(r){return r.cos()}function $s(r){return r.tan()}function Ms(r){return r.arcsin()}function Cs(r){return r.arccos()}function ks(r){return r.arctan()}function Ps(r,t){return r.arctan2(t)}function Vs(r,t){return r.hypot(t)}function Fs(r){return r.degrees()}function Rs(r){return r.radians()}function Ls(r){return r.radians()}function qs(r){return r.degrees()}function js(r){return r.sinh()}function Ws(r){return r.cosh()}function Zs(r){return r.tanh()}function Gs(r){return r.arcsinh()}function Hs(r){return r.arccosh()}function Ys(r){return r.arctanh()}function Js(r,t,e){return r.swapaxes(t,e)}function Xs(r,t,e){return r.moveaxis(t,e)}function ur(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");let e=r.map(o=>o.storage),n=nr(e,t);return _._fromStorage(n)}function Qs(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=ke(e,t);return _._fromStorage(n)}function No(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Pe(t);return _._fromStorage(e)}function Ks(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Nt(t);return _._fromStorage(e)}function ri(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Ve(t);return _._fromStorage(e)}function ti(r,t,e=0){return Fe(r.storage,t,e).map(o=>_._fromStorage(o,r.base??r))}function ei(r,t,e=0){return Ar(r.storage,t,e).map(o=>_._fromStorage(o,r.base??r))}function ni(r,t){return Le(r.storage,t).map(n=>_._fromStorage(n,r.base??r))}function oi(r,t){return qe(r.storage,t).map(n=>_._fromStorage(n,r.base??r))}function ai(r,t){let e=je(r.storage,t);return _._fromStorage(e)}function si(r,t,e){return r.repeat(t,e)}function ii(r){return r.ravel()}function ui(r,t){return r.reshape(...t)}function ci(r,t){return r.squeeze(t)}function fi(r,t){return r.expand_dims(t)}function Vt(r,t){let e=Ze(r.storage,t);return _._fromStorage(e)}function li(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Vt(r,1)}function pi(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Vt(r,0)}function yi(r,t=1,e=[0,1]){let n=Ge(r.storage,t,e);return _._fromStorage(n)}function mi(r,t,e){let n=He(r.storage,t,e);return _._fromStorage(n)}function di(r,t,e=0){let n=Ye(r.storage,t,e);return _._fromStorage(n,r.base??r)}function gi(...r){let t=r.map(o=>o.storage),n=Ke(t).map((o,a)=>o===t[a]?r[a]:_._fromStorage(o));return n.length===1?n[0]:n}function Ai(...r){let t=r.map(o=>o.storage),n=rn(t).map((o,a)=>o===t[a]?r[a]:_._fromStorage(o));return n.length===1?n[0]:n}function hi(...r){let t=r.map(o=>o.storage),n=tn(t).map((o,a)=>o===t[a]?r[a]:_._fromStorage(o));return n.length===1?n[0]:n}function bi(r,t){return Je(r.storage,t).map(n=>_._fromStorage(n,r.base??r))}function Si(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Xe(t);return _._fromStorage(e)}function Di(r){return No(r)}function xi(r,t){let e=Qe(r.storage,t);return _._fromStorage(e)}function Ni(r,t,e){let n=t instanceof _?t:V(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return ur([o,a])}return ur([r,n],e)}function wi(r,t,e){let n=r.dtype;if(e===void 0){let y=r.flatten(),d=(Array.isArray(t)?t:[t]).map(S=>S<0?y.size+S:S),g=[];for(let S=0;S<y.size;S++)d.includes(S)||g.push(S);let h=O(n),A=new h(g.length);for(let S=0;S<g.length;S++){let N=y.get([g[S]]);x(n)?A[S]=typeof N=="bigint"?N:BigInt(N):A[S]=N}let b=D.fromData(A,[g.length],n);return new _(b)}let o=r.shape,a=o.length,s=e<0?a+e:e;if(s<0||s>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let i=o[s],u=Array.isArray(t)?t:[t],c=new Set(u.map(y=>y<0?i+y:y)),f=[],p=0;for(let y=0;y<=i;y++)(c.has(y)||y===i)&&(y>p&&f.push([p,y]),p=y+1);if(f.length===0){let y=[...o];return y[s]=0,X(y,n)}let l=[];for(let[y,m]of f){let d=o.map(()=>":");d[s]=`${y}:${m}`,l.push(r.slice(...d))}return ur(l,s)}function Ii(r,t,e,n){let o=e instanceof _?e:V(e,r.dtype);if(n===void 0){let p=r.flatten(),l=o.flatten(),y=t<0?p.size+t:t;if(y<0||y>p.size)throw new Error(`index ${t} is out of bounds for array of size ${p.size}`);let m=y>0?p.slice(`0:${y}`):null,d=y<p.size?p.slice(`${y}:`):null,g=[];return m&&g.push(m),g.push(l),d&&g.push(d),ur(g)}let a=r.shape,s=a.length,i=n<0?s+n:n;if(i<0||i>=s)throw new Error(`axis ${n} is out of bounds for array of dimension ${s}`);let u=a[i],c=t<0?u+t:t;if(c<0||c>u)throw new Error(`index ${t} is out of bounds for axis ${n} with size ${u}`);let f=[];if(c>0){let p=a.map(()=>":");p[i]=`0:${c}`,f.push(r.slice(...p))}if(f.push(o),c<u){let p=a.map(()=>":");p[i]=`${c}:`,f.push(r.slice(...p))}return ur(f,i)}function zi(r,t,e="constant",n=0){let o=r.shape,a=o.length,s=r.dtype,i;if(typeof t=="number"?i=o.map(()=>[t,t]):Array.isArray(t)&&typeof t[0]=="number"?i=o.map(()=>t):i=t,i.length!==a)throw new Error(`pad_width must have ${a} elements`);let u=o.map((d,g)=>d+i[g][0]+i[g][1]),c=u.reduce((d,g)=>d*g,1),f=O(s),p=new f(c),l=x(s);e==="constant"&&(l?p.fill(BigInt(n)):p.fill(n));let y=new Array(a).fill(0);for(let d=0;d<c;d++){let g=!0,h=[];for(let b=0;b<a;b++){let[S]=i[b],N=y[b]-S;if(N<0||N>=o[b]){g=!1;break}h.push(N)}let A;if(g)A=r.get(h);else if(e==="constant"){for(let b=a-1;b>=0&&(y[b]++,!(y[b]<u[b]));b--)y[b]=0;continue}else{let b=[];for(let S=0;S<a;S++){let[N]=i[S],w=y[S]-N,I=o[S];w<0?e==="edge"?w=0:e==="reflect"?(w=-w,w>=I&&(w=I-1)):e==="symmetric"?(w=-w-1,w>=I&&(w=I-1),w<0&&(w=0)):e==="wrap"&&(w=(w%I+I)%I):w>=I&&(e==="edge"?w=I-1:e==="reflect"?(w=2*I-w-2,w<0&&(w=0)):e==="symmetric"?(w=2*I-w-1,w<0&&(w=0)):e==="wrap"&&(w=w%I)),b.push(Math.max(0,Math.min(I-1,w)))}A=r.get(b)}l?p[d]=typeof A=="bigint"?A:BigInt(Number(A)):p[d]=Number(A);for(let b=a-1;b>=0&&(y[b]++,!(y[b]<u[b]));b--)y[b]=0}let m=D.fromData(p,u,s);return new _(m)}function _i(r,t){let e=Bt(r.storage,t);return _._fromStorage(e,r.base??r)}function Bi(...r){let t=r.map(n=>n.storage);return On(t).map((n,o)=>_._fromStorage(n,r[o].base??r[o]))}function Ei(...r){return ot(...r)}function Ti(r,t,e){return r.take(t,e)}function Ui(r,t,e){r.put(t,e)}function vi(r,t){let e=t.map(o=>o.storage),n=Cn(r.storage,e);return _._fromStorage(n)}function Oi(r,t,e=!1){return kn(r.storage,t.storage,e)}function $i(r,t){return Ue(r.storage,t.storage)}function Mi(r,t){return _._fromStorage(mt(r.storage,t))}function Ci(r,t){return _._fromStorage(dt(r.storage,t))}function ki(r,t,e=!1){let n=gt(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Pi(r,t,e=!1){let n=At(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Vi(r,t,e,n=!1){let o=ht(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Fi(r,t,e,n=!1){let o=ir(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Ri(r,t,e,n=!1){let o=e?e.storage:void 0,a=Or(r.storage,t,o,n);return typeof a=="number"?a:_._fromStorage(a)}function Li(r,t,e=!1){let n=$r(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function qi(r,t,e=!1){let n=Mr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function ji(r,t,e=!1){let n=Cr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Wi(r,t,e=0,n=!1){let o=yr(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Zi(r,t,e=0,n=!1){let o=bt(r.storage,t,e,n);return typeof o=="number"?o:_._fromStorage(o)}function Gi(r,t,e=!1){let n=kr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Hi(r,t,e=!1){let n=Pr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function Yi(r,t){let e=Vr(r.storage,t);return typeof e=="number"?e:_._fromStorage(e)}function Ji(r,t){let e=Fr(r.storage,t);return typeof e=="number"?e:_._fromStorage(e)}function Xi(r,t){return _._fromStorage(St(r.storage,t))}function Qi(r,t){return _._fromStorage(Dt(r.storage,t))}function Ki(r,t,e=!1){let n=Rr(r.storage,t,e);return typeof n=="number"?n:_._fromStorage(n)}function ru(r){return r.cbrt()}function tu(r){return r.fabs()}function eu(r,t){return r.divmod(t)}function nu(r){return r.square()}function ou(r,t){return r.remainder(t)}function au(r,t){return r.heaviside(t)}function su(r,t){return r.bitwise_and(t)}function iu(r,t){return r.bitwise_or(t)}function uu(r,t){return r.bitwise_xor(t)}function cu(r){return r.bitwise_not()}function fu(r){return r.invert()}function lu(r,t){return r.left_shift(t)}function pu(r,t){return r.right_shift(t)}function yu(r,t=-1,e="big"){let n=io(r.storage,t,e);return _._fromStorage(n)}function mu(r,t=-1,e=-1,n="big"){let o=uo(r.storage,t,e,n);return _._fromStorage(o)}function du(r,...t){let e=t.map(o=>o.storage),n=cn(r,...e);return typeof n=="number"||typeof n=="bigint"?n:_._fromStorage(n)}function gu(r,t,e){return _._fromStorage(Pn(r.storage,t.storage,e))}function Au(r,t,e,n){Vn(r.storage,t.storage,e.storage,n)}function hu(r,t,e){let n=e instanceof _?e.storage:e;Fn(r.storage,t.storage,n)}function bu(r,t,e){return _._fromStorage(Rn(r.storage,t.storage,e))}function Su(r,t,e=0){let n=r.map(a=>a.storage),o=t.map(a=>a.storage);return _._fromStorage(Ln(n,o,e))}function Du(r,t,e){qn(r.storage,t.storage,e.storage)}function xu(r,t=2){return Et(r,t).map(n=>_._fromStorage(n))}function Nu(r){return jn(r.storage).map(e=>_._fromStorage(e))}function wu(r,t=0,e){return Tt(r,t,e).map(o=>_._fromStorage(o))}function Iu(r,t=0){return Wn(r.storage,t).map(n=>_._fromStorage(n))}function zu(r,t=0,e){return Ut(r,t,e).map(o=>_._fromStorage(o))}function _u(r,t=0){return Zn(r.storage,t).map(n=>_._fromStorage(n))}function Bu(r,t,e=0){return Gn(r,(a,s)=>t(a,s).storage,e).map(a=>_._fromStorage(a))}function Eu(r,t="int32"){return _._fromStorage(Hn(r,t))}function Tu(...r){return Yn(...r.map(e=>e.storage)).map(e=>_._fromStorage(e))}function Uu(r,t,e="raise"){let n=r.map(o=>o.storage);return _._fromStorage(Jn(n,t,e))}function vu(r,t,e="C"){let n=r instanceof _?r.storage:r;return Xn(n,t,e).map(a=>_._fromStorage(a))}function Ou(r,t=-1){return _._fromStorage(Ot(r.storage,t))}function $u(r,t=-1){return _._fromStorage($t(r.storage,t))}function Mu(r){let t=r.map(e=>e.storage);return _._fromStorage(fo(t))}function Cu(r,t,e=-1){return _._fromStorage(Mt(r.storage,t,e))}function ku(r,t,e=-1){return _._fromStorage(Ct(r.storage,t,e))}function Pu(r){return _._fromStorage(lo(r.storage))}function Vu(r){return jr(r.storage).map(e=>_._fromStorage(e))}function Fu(r){return _._fromStorage(po(r.storage))}function Ru(r,t,e){let n=yo(r.storage,t?.storage,e?.storage);return Array.isArray(n)?n.map(o=>_._fromStorage(o)):_._fromStorage(n)}function Lu(r,t,e="left"){return _._fromStorage(kt(r.storage,t.storage,e))}function qu(r,t){return _._fromStorage(mo(r.storage,t.storage))}function ju(r,t){let e=Pt(r.storage,t);return typeof e=="number"?e:_._fromStorage(e)}var _,Zr=C(()=>{"use strict";ne();q();W();Ne();ve();$e();wt();ln();mn();In();vn();Qn();co();go();_=class r{constructor(t,e){this._storage=t,this._base=e}get storage(){return this._storage}static _fromStorage(t,e){return new r(t,e)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let e=t.map((n,o)=>{let a=n;if(a<0&&(a=this.shape[o]+a),a<0||a>=this.shape[o])throw new Error(`Index ${n} is out of bounds for axis ${o} with size ${this.shape[o]}`);return a});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let n=t.map((s,i)=>{let u=s;if(u<0&&(u=this.shape[i]+u),u<0||u>=this.shape[i])throw new Error(`Index ${s} is out of bounds for axis ${i} with size ${this.shape[i]}`);return u}),o=this.dtype,a;x(o)?a=typeof e=="bigint"?e:BigInt(Math.round(e)):o==="bool"?a=e?1:0:a=Number(e),this._storage.set(n,a)}copy(){return new r(this._storage.copy())}astype(t,e=!0){let n=this.dtype;if(n===t&&!e)return this;if(n===t&&e)return this.copy();let o=Array.from(this.shape),a=this.size,s=O(t);if(!s)throw new Error(`Cannot convert to dtype ${t}`);let i=new s(a),u=this.data;if(x(n)&&!x(t)){let f=u;if(t==="bool")for(let p=0;p<a;p++)i[p]=f[p]!==BigInt(0)?1:0;else for(let p=0;p<a;p++)i[p]=Number(f[p])}else if(!x(n)&&x(t)){let f=u;for(let p=0;p<a;p++)i[p]=BigInt(Math.round(Number(f[p])))}else if(t==="bool"){let f=u;for(let p=0;p<a;p++)i[p]=f[p]!==0?1:0}else if(n==="bool"&&!x(t)){let f=u;for(let p=0;p<a;p++)i[p]=f[p]}else if(!x(n)&&!x(t)){let f=u;for(let p=0;p<a;p++)i[p]=f[p]}else{let f=u;for(let p=0;p<a;p++)i[p]=f[p]}let c=D.fromData(i,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=ue(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=ce(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=fe(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=le(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=Er(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=nt(this._storage,e);return r._fromStorage(n)}positive(){let t=de(this._storage);return r._fromStorage(t)}reciprocal(){let t=ge(this._storage);return r._fromStorage(t)}sqrt(){let t=pn(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=yn(this._storage,e);return r._fromStorage(n)}absolute(){let t=pe(this._storage);return r._fromStorage(t)}negative(){let t=ye(this._storage);return r._fromStorage(t)}sign(){let t=me(this._storage);return r._fromStorage(t)}sin(){let t=dn(this._storage);return r._fromStorage(t)}cos(){let t=gn(this._storage);return r._fromStorage(t)}tan(){let t=An(this._storage);return r._fromStorage(t)}arcsin(){let t=hn(this._storage);return r._fromStorage(t)}arccos(){let t=bn(this._storage);return r._fromStorage(t)}arctan(){let t=Sn(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=Dn(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=xn(this._storage,e);return r._fromStorage(n)}degrees(){let t=Nn(this._storage);return r._fromStorage(t)}radians(){let t=wn(this._storage);return r._fromStorage(t)}sinh(){let t=zn(this._storage);return r._fromStorage(t)}cosh(){let t=_n(this._storage);return r._fromStorage(t)}tanh(){let t=Bn(this._storage);return r._fromStorage(t)}arcsinh(){let t=En(this._storage);return r._fromStorage(t)}arccosh(){let t=Tn(this._storage);return r._fromStorage(t)}arctanh(){let t=Un(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=we(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=Ie(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=ze(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=_e(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=Be(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=Ee(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=st(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 Te(this._storage,o,e,n)}bitwise_and(t){let e=typeof t=="number"?t:t._storage,n=to(this._storage,e);return r._fromStorage(n)}bitwise_or(t){let e=typeof t=="number"?t:t._storage,n=eo(this._storage,e);return r._fromStorage(n)}bitwise_xor(t){let e=typeof t=="number"?t:t._storage,n=no(this._storage,e);return r._fromStorage(n)}bitwise_not(){let t=vt(this._storage);return r._fromStorage(t)}invert(){let t=oo(this._storage);return r._fromStorage(t)}left_shift(t){let e=typeof t=="number"?t:t._storage,n=ao(this._storage,e);return r._fromStorage(n)}right_shift(t){let e=typeof t=="number"?t:t._storage,n=so(this._storage,e);return r._fromStorage(n)}sum(t,e=!1){let n=pr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=Tr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=Ur(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=vr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=ut(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=ct(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=ft(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=lt(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=pt(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=yt(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(mt(this._storage,t))}cumprod(t){return r._fromStorage(dt(this._storage,t))}ptp(t,e=!1){let n=gt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=At(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=ht(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=ir(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=Or(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=$r(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=Mr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=Cr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=yr(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=bt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=kr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=Pr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=Vr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=Fr(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(St(this._storage,t))}nancumprod(t){return r._fromStorage(Dt(this._storage,t))}nanmedian(t,e=!1){let n=Rr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}sort(t=-1){return r._fromStorage(Ot(this._storage,t))}argsort(t=-1){return r._fromStorage($t(this._storage,t))}partition(t,e=-1){return r._fromStorage(Mt(this._storage,t,e))}argpartition(t,e=-1){return r._fromStorage(Ct(this._storage,t,e))}nonzero(){return jr(this._storage).map(e=>r._fromStorage(e))}searchsorted(t,e="left"){return r._fromStorage(kt(this._storage,t._storage,e))}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=G(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=Lr(this._storage);return r._fromStorage(t)}ravel(){let t=dr(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=gr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=Me(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=mr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=Ce(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=xt(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=We(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=$n(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;Mn(this._storage,t,n)}matmul(t){let e=or(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=zt(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return on(this._storage)}inner(t){let e=an(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=_t(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=sn(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=Ae(this._storage);return r._fromStorage(t)}fabs(){let t=he(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=be(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=Se(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=De(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=xe(this._storage,e);return r._fromStorage(n)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);let e=t.map((u,c)=>{let f=te(u);return ee(f,this.shape[c])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});let n=[],o=[],a=this._storage.offset;for(let u=0;u<e.length;u++){let c=e[u],f=this._storage.strides[u];if(a+=c.start*f,!c.isIndex){let p;c.step>0?p=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):p=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(p),o.push(f*c.step)}}let s=D.fromData(this._storage.data,n,this._storage.dtype,o,a),i=this._base??this;return new r(s,i)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let t=this.shape,e=t.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let s=[];for(let i=0;i<t[a];i++)o[a]=i,s.push(n(o,a+1));return s};return n(new Array(e),0)}}});function Rt(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}function Io(r){if(r.startsWith("[")||r.startsWith("("))throw new Q(`Structured/compound dtypes are not supported: ${r}`);let t="",e=r;(r[0]==="<"||r[0]===">"||r[0]==="="||r[0]==="|")&&(t=r[0],e=r.slice(1));let n=e[0];if(n&&n in wo)throw new Q(`Unsupported dtype: ${wo[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Wu[e];if(!o)throw new Q(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Ft.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=Rt(),s=t==="<"||t==="|"||t==="="&&a,i=t===">"||t==="="&&!a,u=parseInt(e.slice(1),10),c=u>1&&(i&&a||s&&!a);return{dtype:o,needsByteSwap:c,itemsize:u}}var br,Ft,Wu,Gr,wo,Q,Z,Sr=C(()=>{"use strict";br=new Uint8Array([147,78,85,77,80,89]),Ft=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];Wu={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},Gr={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},wo={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};Q=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},Z=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}}});function ar(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Lt(t);return qt(t,e)}function Lt(r){if(r.length<10)throw new Z("File too small to be a valid NPY file");for(let c=0;c<br.length;c++)if(r[c]!==br[c])throw new Z("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new Z(`Unsupported NPY version: ${t}.${e}`);let n,o;t===1?(n=r[8]|r[9]<<8,o=10):(n=r[8]|r[9]<<8|r[10]<<16|r[11]<<24,o=12);let a=o+n;if(r.length<a)throw new Z("File truncated: header extends beyond file");let s=r.slice(o,a),i=new TextDecoder("utf-8").decode(s).trim(),u=Zu(i);return{version:{major:t,minor:e},header:u,dataOffset:a}}function qt(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:s}=Io(e.descr),i=e.shape.reduce((d,g)=>d*g,1),u=i*s,c=r.length-n;if(c<u)throw new Z(`File truncated: expected ${u} bytes of data, got ${c}`);let f=new ArrayBuffer(u);new Uint8Array(f).set(r.subarray(n,n+u));let l=Gu(f,o,i,a,s),y=e.shape,m;if(e.fortran_order&&y.length>1){let d=[...y].reverse(),g=D.fromData(l,d,o);m=Hu(g,d),y=e.shape}else m=D.fromData(l,[...y],o);return new _(m)}function Zu(r){let t=r.match(/'descr'\s*:\s*'([^']+)'/),e=r.match(/'fortran_order'\s*:\s*(True|False)/),n=r.match(/'shape'\s*:\s*\(([^)]*)\)/);if(!t||!e||!n)throw new Z(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",s=n[1].trim(),i;return s===""?i=[]:i=s.split(",").map(u=>u.trim()).filter(u=>u!=="").map(u=>{let c=parseInt(u,10);if(isNaN(c))throw new Z(`Invalid shape value: ${u}`);return c}),{descr:o,fortran_order:a,shape:i}}function Gu(r,t,e,n,o){let a=O(t);if(!a)throw new Z(`Cannot create array for dtype: ${t}`);if(!n)return new a(r,0,e);let s=new Uint8Array(r),i=new Uint8Array(r.byteLength);for(let u=0;u<e;u++){let c=u*o;for(let f=0;f<o;f++)i[c+f]=s[c+o-1-f]}return new a(i.buffer,0,e)}function Hu(r,t){let e=t.length,n=r.size,o=r.dtype,a=O(o);if(!a)throw new Z(`Cannot create array for dtype: ${o}`);let s=new a(n),i=[...t].reverse(),u=zo(t),c=zo(i),f=new Array(e).fill(0);for(let p=0;p<n;p++){let l=p;for(let m=0;m<e;m++){let d=u[m];f[m]=Math.floor(l/d),l=l%d}let y=0;for(let m=0;m<e;m++)y+=f[e-1-m]*c[m];x(o),s[y]=r.iget(p)}return D.fromData(s,i,o)}function zo(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 Hr=C(()=>{"use strict";Zr();W();q();Sr()});function tr(r){let t=r.shape,e=r.dtype,n=Gr[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,s=12,u=(64-(s+a.length+1)%64)%64;a=a+" ".repeat(u)+`
|
|
2
|
-
`;let c=new TextEncoder().encode(a),f=c.length,p=r.size,l=ae(e),y=p*l,m=s+f+y,d=new Uint8Array(m);d.set(br,0),d[6]=3,d[7]=0,d[8]=f&255,d[9]=f>>8&255,d[10]=f>>16&255,d[11]=f>>24&255,d.set(c,s);let g=s+f;return Yu(r,d.subarray(g),l),d}function Yu(r,t,e){let n=r.dtype,o=r.size,a=Rt(),s=x(n),i=r._storage;if(i.isCContiguous&&i.offset===0&&a){let c=i.data,f=new Uint8Array(c.buffer,c.byteOffset,o*e);t.set(f)}else{let c=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let f=0;f<o;f++){let p=i.iget(f),l=f*e;s?Ju(c,l,p,n==="uint64"):Xu(c,l,p,n)}}}function Ju(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Xu(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 Yr=C(()=>{"use strict";q();Sr()});function jt(r){let t=4294967295;for(let e=0;e<r.length;e++)t=Qu[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}var Qu,Wt=C(()=>{"use strict";Qu=(()=>{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 _o(r){let t=Eo(r),e=new Map;for(let n of t){let o=await Ku(n);e.set(n.name,o)}return e}function Bo(r){let t=Eo(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 Eo(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=[],o=-1;for(let c=t.length-22;c>=0;c--)if(e.getUint32(c,!0)===101010256){o=c;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),s=e.getUint16(o+10,!0),i=[],u=a;for(let c=0;c<s&&e.getUint32(u,!0)===33639248;c++){let p=e.getUint16(u+10,!0),l=e.getUint32(u+16,!0),y=e.getUint32(u+20,!0),m=e.getUint32(u+24,!0),d=e.getUint16(u+28,!0),g=e.getUint16(u+30,!0),h=e.getUint16(u+32,!0),A=e.getUint32(u+42,!0),b=t.slice(u+46,u+46+d),S=new TextDecoder("utf-8").decode(b);i.push({name:S,compressionMethod:p,crc32:l,compressedSize:y,uncompressedSize:m,localHeaderOffset:A}),u=u+46+d+g+h}for(let c of i){let f=c.localHeaderOffset;if(e.getUint32(f,!0)!==67324752)throw new Error(`Invalid local file header at offset ${f}`);let l=e.getUint16(f+26,!0),y=e.getUint16(f+28,!0),m=f+30+l+y,d=t.slice(m,m+c.compressedSize);n.push({name:c.name,compressedData:d,compressionMethod:c.compressionMethod,crc32:c.crc32,compressedSize:c.compressedSize,uncompressedSize:c.uncompressedSize})}return n}async function Ku(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await rc(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function rc(r){if(typeof DecompressionStream>"u")throw new Error("DecompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new DecompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:f}=await o.read();if(c)break;a.push(f)}let s=a.reduce((c,f)=>c+f.length,0),i=new Uint8Array(s),u=0;for(let c of a)i.set(c,u),u+=c.length;return i}var To=C(()=>{"use strict";Wt()});var vo={};Kt(vo,{loadNpz:()=>Ht,loadNpzSync:()=>Yt,parseNpz:()=>fr,parseNpzSync:()=>Jr});async function fr(r,t={}){let e=t.force??!1,n=await _o(r);return Uo(n,e)}function Jr(r,t={}){let e=t.force??!1,n=Bo(r);return Uo(n,e)}function Uo(r,t){let e=new Map,n=[],o=new Map;for(let[a,s]of r){if(!a.endsWith(".npy"))continue;let i=a.slice(0,-4);try{let u=ar(s);e.set(i,u)}catch(u){if(u instanceof Q&&t)n.push(i),o.set(i,u.message);else throw u}}return{arrays:e,skipped:n,errors:o}}async function Ht(r,t={}){let e=await fr(r,t);return Object.fromEntries(e.arrays)}function Yt(r,t={}){let e=Jr(r,t);return Object.fromEntries(e.arrays)}var Xr=C(()=>{"use strict";Hr();Sr();To()});async function Oo(r,t={}){let e=t.compress??!1,n=[];for(let[l,y]of r){let m=jt(y),d,g;e?(d=await ec(y),d.length<y.length?g=8:(d=y,g=0)):(d=y,g=0),n.push({name:l,data:y,compressedData:d,crc:m,compressionMethod:g,offset:0})}let o=0;for(let l of n){let y=new TextEncoder().encode(l.name);o+=30+y.length+l.compressedData.length}let a=0;for(let l of n){let y=new TextEncoder().encode(l.name);a+=46+y.length}let i=o+a+22,u=new Uint8Array(i),c=new DataView(u.buffer),f=0;for(let l of n)l.offset=f,f=Mo(u,c,f,l);let p=f;for(let l of n)f=Co(u,c,f,l);return ko(c,f,n.length,a,p),u}function $o(r){let t=[];for(let[f,p]of r){let l=jt(p);t.push({name:f,data:p,compressedData:p,crc:l,compressionMethod:0,offset:0})}let e=0;for(let f of t){let p=new TextEncoder().encode(f.name);e+=30+p.length+f.compressedData.length}let n=0;for(let f of t){let p=new TextEncoder().encode(f.name);n+=46+p.length}let a=e+n+22,s=new Uint8Array(a),i=new DataView(s.buffer),u=0;for(let f of t)f.offset=u,u=Mo(s,i,u,f);let c=u;for(let f of t)u=Co(s,i,u,f);return ko(i,u,t.length,n,c),s}function Mo(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 Co(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 ko(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 ec(r){if(typeof CompressionStream>"u")throw new Error("CompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new CompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:f}=await o.read();if(c)break;a.push(f)}let s=a.reduce((c,f)=>c+f.length,0),i=new Uint8Array(s),u=0;for(let c of a)i.set(c,u),u+=c.length;return i}var Po=C(()=>{"use strict";Wt()});var Fo={};Kt(Fo,{serializeNpz:()=>xr,serializeNpzSync:()=>Jt});async function xr(r,t={}){let e=Vo(r);return Oo(e,{compress:t.compress??!1})}function Jt(r){let t=Vo(r);return $o(t)}function Vo(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=tr(o);t.set(`arr_${n}.npy`,a)}return t}let e=r instanceof Map?r.entries():Object.entries(r);for(let[n,o]of e){if(typeof n!="string"||n.length===0)throw new Error("Array names must be non-empty strings");let a=tr(o),s=n.endsWith(".npy")?n:`${n}.npy`;t.set(s,a)}return t}var Qr=C(()=>{"use strict";Yr();Po()});Hr();Yr();Xr();Qr();import{readFileSync as zr,writeFileSync as Xt}from"node:fs";import{readFile as _r,writeFile as Qt}from"node:fs/promises";Zr();function lr(r,t={}){let{delimiter:e,comments:n="#",skiprows:o=0,usecols:a,max_rows:s,dtype:i="float64",missing_values:u,filling_values:c}=t,f=r.split(/\r?\n/);if(o>0&&(f=f.slice(o)),f=f.filter(d=>{let g=d.trim();return!(g===""||n&&g.startsWith(n))}),s!==void 0&&s>0&&(f=f.slice(0,s)),f.length===0)return V([],i);let p=[],l=new Set(u?Array.isArray(u)?u:[u]:[]),y=c!==void 0?c:i.includes("int")||i==="bool"?0:NaN;for(let d of f){let g;e===void 0?g=d.trim().split(/\s+/):g=d.split(e),a!==void 0&&(g=(Array.isArray(a)?a:[a]).map(b=>(b<0&&(b=g.length+b),g[b]??"")));let h=g.map(A=>{let b=A.trim();if(l.has(b)||b==="")return y;let S=parseFloat(b);return isNaN(S)?y:S});p.push(h)}let m=p[0]?.length??0;for(let d=1;d<p.length;d++)if(p[d].length!==m)throw new Error(`Inconsistent number of columns: row 0 has ${m} columns, row ${d} has ${p[d].length} columns`);return m===1?V(p.map(d=>d[0]),i):V(p,i)}function Nr(r,t={}){let e={...t,missing_values:t.missing_values??["","nan","NaN","NA","N/A","-"],filling_values:t.filling_values??NaN};return lr(r,e)}function wr(r,t,e="float64"){let n=typeof t=="string"?new RegExp(t,"gm"):new RegExp(t.source,"gm"),o=[],a;for(;(a=n.exec(r))!==null;)if(a.length>1){let s=a.slice(1).map(i=>{let u=parseFloat(i);return isNaN(u)?0:u});o.push(s)}return o.length===0?V([],e):o[0].length===1?V(o.map(s=>s[0]),e):V(o,e)}function Ro(r,t){let e=typeof r=="bigint"?Number(r):r,n=t.match(/^%([+-]?)(\d*)(?:\.(\d+))?([dfeEgGs])$/);if(!n)return String(e);let[,o,a,s,i]=n,u=s!==void 0?parseInt(s,10):void 0,c;switch(i){case"d":c=Math.round(e).toString();break;case"f":c=e.toFixed(u??6);break;case"e":c=e.toExponential(u??6).replace(/e([+-])(\d)$/,"e$10$2");break;case"E":c=e.toExponential(u??6).toUpperCase().replace(/E([+-])(\d)$/,"E$10$2");break;case"g":case"G":{let f=u??6,p=Math.floor(Math.log10(Math.abs(e)));p>=-4&&p<f?(c=e.toPrecision(f),c.includes(".")&&(c=c.replace(/\.?0+$/,""))):c=e.toExponential(f-1),i==="G"&&(c=c.toUpperCase());break}case"s":c=String(e);break;default:c=String(e)}if(a){let f=parseInt(a,10);if(c.length<f){let p=" ".repeat(f-c.length);o==="-"?c=c+p:c=p+c}}return o==="+"&&e>=0&&!c.startsWith("-")&&(c="+"+c),c}function Ir(r,t={}){let{fmt:e="%.18e",delimiter:n=" ",newline:o=`
|
|
3
|
-
`,header:a,footer:s,comments:i="# "}=t;if(r.ndim>2)throw new Error("savetxt: array must be 1D or 2D");let u=[];if(a!==void 0){let f=a.split(/\r?\n/);for(let p of f)p.startsWith(i.trimEnd())?u.push(p):u.push(i+p)}let c=r.toArray();if(r.ndim===1)for(let f of c)u.push(Ro(f,e));else for(let f of c){let p=f.map(l=>Ro(l,e));u.push(p.join(n))}if(s!==void 0){let f=s.split(/\r?\n/);for(let p of f)p.startsWith(i.trimEnd())?u.push(p):u.push(i+p)}return u.join(o)+o}Zr();Hr();Yr();Sr();Xr();Qr();var Mf="0.8.0";async function nc(r){let t=await _r(r);return ar(t)}function oc(r){let t=zr(r);return ar(t)}async function ac(r,t){let e=tr(t);await Qt(r,e)}function sc(r,t){let e=tr(t);Xt(r,e)}async function ic(r,t={}){let e=await _r(r);return fr(e,t)}function uc(r,t={}){let e=zr(r),{parseNpzSync:n}=(Xr(),re(vo));return n(e,t)}async function Lo(r,t,e={}){let n=await xr(t,e);await Qt(r,n)}function Zf(r,t){let{serializeNpzSync:e}=(Qr(),re(Fo)),n=e(t);Xt(r,n)}async function Gf(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return nc(r)}else{if(r.endsWith(".npz"))return ic(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function Hf(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return oc(r)}else{if(r.endsWith(".npz"))return uc(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function Yf(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return ac(r,t)}function Jf(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return sc(r,t)}async function Xf(r,t){return r.endsWith(".npz")||(r=r+".npz"),Lo(r,t,{compress:!1})}async function Qf(r,t){return r.endsWith(".npz")||(r=r+".npz"),Lo(r,t,{compress:!0})}async function Kf(r,t={}){let e=await _r(r,{encoding:t.encoding??"utf-8"});return lr(e,t)}function rl(r,t={}){let e=zr(r,{encoding:t.encoding??"utf-8"});return lr(e,t)}async function tl(r,t,e={}){let n=Ir(t,e);await Qt(r,n,"utf-8")}function el(r,t,e={}){let n=Ir(t,e);Xt(r,n,"utf-8")}async function nl(r,t={}){let e=await _r(r,{encoding:t.encoding??"utf-8"});return Nr(e,t)}function ol(r,t={}){let e=zr(r,{encoding:t.encoding??"utf-8"});return Nr(e,t)}async function al(r,t,e="float64"){let n=await _r(r,{encoding:"utf-8"});return wr(n,t,e)}function sl(r,t,e="float64"){let n=zr(r,{encoding:"utf-8"});return wr(n,t,e)}export{Gr as DTYPE_TO_DESCR,Z as InvalidNpyError,_ as NDArray,Ft as SUPPORTED_DTYPES,Q as UnsupportedDTypeError,Mf as __version__,As as absolute,Ni as append,ja as arange,Cs as arccos,Hs as arccosh,Ms as arcsin,Gs as arcsinh,ks as arctan,Ps as arctan2,Ys as arctanh,ku as argpartition,$u as argsort,V as array,Oi as array_equal,$i as array_equiv,ei as array_split,rs as asanyarray,Wr as asarray,ts as ascontiguousarray,es as asfortranarray,gi as atleast_1d,Ai as atleast_2d,hi as atleast_3d,Ri as average,su as bitwise_and,cu as bitwise_not,iu as bitwise_or,uu as bitwise_xor,Bi as broadcast_arrays,Ei as broadcast_shapes,_i as broadcast_to,ru as cbrt,vi as choose,Si as column_stack,bu as compress,ur as concatenate,Ya as copy,Os as cos,Ws as cosh,ju as count_nonzero,Ci as cumprod,Mi as cumsum,Ls as deg2rad,Fs as degrees,wi as delete,xo as diag,xu as diag_indices,Nu as diag_indices_from,ns as diagflat,zs as diagonal,eu as divmod,ws as dot,bi as dsplit,ri as dstack,du as einsum,So as empty,Qa as empty_like,fi as expand_dims,qu as extract,bo as eye,tu as fabs,Fu as flatnonzero,Vt as flip,li as fliplr,pi as flipud,Ds as floor_divide,fs as frombuffer,ls as fromfile,os as fromfunction,ps as fromiter,al as fromregex,sl as fromregexSync,ys as fromstring,Do as full,Ka as full_like,nl as genfromtxt,ol as genfromtxtSync,Ga as geomspace,au as heaviside,oi as hsplit,Ks as hstack,Vs as hypot,Ha as identity,Eu as indices,Es as inner,Ii as insert,fu as invert,Tu as ix_,_s as kron,lu as left_shift,Mu as lexsort,Wa as linspace,Gf as load,nc as loadNpy,oc as loadNpySync,Ht as loadNpz,ic as loadNpzFile,uc as loadNpzFileSync,Yt as loadNpzSync,Hf as loadSync,Kf as loadtxt,rl as loadtxtSync,Za as logspace,Bu as mask_indices,Pi as median,as as meshgrid,Ss as mod,Xs as moveaxis,Ji as nanargmax,Yi as nanargmin,Qi as nancumprod,Xi as nancumsum,Hi as nanmax,ji as nanmean,Ki as nanmedian,Gi as nanmin,qi as nanprod,Zi as nanstd,Li as nansum,Wi as nanvar,hs as negative,Vu as nonzero,Ao as ones,Xa as ones_like,Ts as outer,yu as packbits,zi as pad,ar as parseNpy,qt as parseNpyData,Lt as parseNpyHeader,fr as parseNpz,Jr as parseNpzSync,lr as parseTxt,Cu as partition,Vi as percentile,Du as place,xs as positive,gs as power,ki as ptp,Ui as put,Au as put_along_axis,hu as putmask,Fi as quantile,qs as rad2deg,Rs as radians,ii as ravel,Uu as ravel_multi_index,Ns as reciprocal,ou as remainder,si as repeat,ui as reshape,xi as resize,pu as right_shift,mi as roll,di as rollaxis,yi as rot90,Di as row_stack,Yf as save,ac as saveNpy,sc as saveNpySync,Lo as saveNpz,Zf as saveNpzSync,Jf as saveSync,tl as savetxt,el as savetxtSync,Xf as savez,Qf as savez_compressed,Lu as searchsorted,Su as select,tr as serializeNpy,xr as serializeNpz,Jt as serializeNpzSync,Ir as serializeTxt,bs as sign,vs as sin,js as sinh,Ou as sort,Pu as sort_complex,ti as split,ds as sqrt,nu as square,ci as squeeze,Qs as stack,Js as swapaxes,Ti as take,gu as take_along_axis,$s as tan,Zs as tanh,Us as tensordot,ai as tile,Is as trace,Bs as transpose,ss as tri,is as tril,wu as tril_indices,Iu as tril_indices_from,us as triu,zu as triu_indices,_u as triu_indices_from,mu as unpackbits,vu as unravel_index,cs as vander,ni as vsplit,No as vstack,Ru as where,X as zeros,Ja as zeros_like};
|
|
1
|
+
var Bt=Object.defineProperty;var Gi=Object.getOwnPropertyDescriptor;var Zi=Object.getOwnPropertyNames;var Hi=Object.prototype.hasOwnProperty;var k=(r,t)=>()=>(r&&(t=r(r=0)),t);var He=(r,t)=>{for(var e in t)Bt(r,e,{get:t[e],enumerable:!0})},Yi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Zi(t))!Hi.call(r,o)&&o!==e&&Bt(r,o,{get:()=>t[o],enumerable:!(n=Gi(t,o))||n.enumerable});return r};var Ye=r=>Yi(Bt({},"__esModule",{value:!0}),r);function Je(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 Xe(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 Qe=k(()=>{"use strict"});function T(r){switch(r){case"float64":return Float64Array;case"float32":return Float32Array;case"int64":return BigInt64Array;case"int32":return Int32Array;case"int16":return Int16Array;case"int8":return Int8Array;case"uint64":return BigUint64Array;case"uint32":return Uint32Array;case"uint16":return Uint16Array;case"uint8":return Uint8Array;case"bool":return Uint8Array;default:throw new Error(`Unknown dtype: ${r}`)}}function Hr(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 rn(r){return r==="int64"||r==="int32"||r==="int16"||r==="int8"||r==="uint64"||r==="uint32"||r==="uint16"||r==="uint8"}function Ke(r){return r==="float64"||r==="float32"}function w(r){return r==="int64"||r==="uint64"}function C(r,t){if(r===t)return r;if(r==="bool")return t;if(t==="bool")return r;if(Ke(r)||Ke(t)){if(r==="float64"||t==="float64")return"float64";if(r==="float32"){let c=t;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}if(t==="float32"){let c=r;return c==="int32"||c==="int64"||c==="uint32"||c==="uint64"?"float64":"float32"}return"float32"}let e=r.startsWith("int"),n=t.startsWith("int"),o=r.startsWith("uint"),a=t.startsWith("uint"),i=c=>c.includes("64")?64:c.includes("32")?32:c.includes("16")?16:c.includes("8")?8:0,u=i(r),s=i(t);if(r==="int64"&&t==="uint64"||r==="uint64"&&t==="int64")return"float64";if(e&&a&&u===s){if(u===8)return"int16";if(u===16)return"int32";if(u===32)return"int64"}if(o&&n&&u===s){if(s===8)return"int16";if(s===16)return"int32";if(s===32)return"int64"}if(e&&n||o&&a){let c=Math.max(u,s);return e?c===64?"int64":c===32?"int32":c===16?"int16":"int8":c===64?"uint64":c===32?"uint32":c===16?"uint16":"uint8"}return e&&a?u>s?r:s===8?"int16":s===16?"int32":s===32?"int64":"float64":o&&n?s>u?t:u===8?"int16":u===16?"int32":u===32?"int64":"float64":"float64"}var j,W=k(()=>{"use strict";j="float64"});function H(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 S,R=k(()=>{"use strict";W();S=class r{constructor(t,e,n,o,a){this._data=t,this._shape=e,this._strides=n,this._offset=o,this._dtype=a}get shape(){return this._shape}get ndim(){return this._shape.length}get size(){return this._shape.reduce((t,e)=>t*e,1)}get dtype(){return this._dtype}get data(){return this._data}get strides(){return this._strides}get offset(){return this._offset}get isCContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=n-1;a>=0;a--){if(e[a]!==o)return!1;o*=t[a]}return!0}get isFContiguous(){let t=this._shape,e=this._strides,n=t.length;if(n===0)return!0;if(n===1)return e[0]===1;let o=1;for(let a=0;a<n;a++){if(e[a]!==o)return!1;o*=t[a]}return!0}iget(t){let e=this._shape,n=this._strides,o=e.length;if(o===0)return this._data[this._offset];let a=t,i=this._offset;for(let u=0;u<o;u++){let s=1;for(let l=u+1;l<o;l++)s*=e[l];let c=Math.floor(a/s);a=a%s,i+=c*n[u]}return this._data[i]}iset(t,e){let n=this._shape,o=this._strides,a=n.length;if(a===0){this._data[this._offset]=e;return}let i=t,u=this._offset;for(let s=0;s<a;s++){let c=1;for(let m=s+1;m<a;m++)c*=n[m];let l=Math.floor(i/c);i=i%c,u+=l*o[s]}this._data[u]=e}get(...t){let e=this._strides,n=this._offset;for(let o=0;o<t.length;o++)n+=t[o]*e[o];return this._data[n]}set(t,e){let n=this._strides,o=this._offset;for(let a=0;a<t.length;a++)o+=t[a]*n[a];this._data[o]=e}copy(){let t=Array.from(this._shape),e=this._dtype,n=this.size,o=T(e);if(!o)throw new Error(`Cannot copy array with dtype ${e}`);let a=new o(n);if(this.isCContiguous&&this._offset===0)if(w(e)){let i=this._data,u=a;for(let s=0;s<n;s++)u[s]=i[s]}else a.set(this._data);else if(w(e)){let i=a;for(let u=0;u<n;u++)i[u]=this.iget(u)}else for(let i=0;i<n;i++)a[i]=this.iget(i);return new r(a,t,r._computeStrides(t),0,e)}static fromData(t,e,n,o,a){let i=o??r._computeStrides(e),u=a??0;return new r(t,e,i,u,n)}static zeros(t,e=j){let n=t.reduce((i,u)=>i*u,1),o=T(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return new r(a,t,r._computeStrides(t),0,e)}static ones(t,e=j){let n=t.reduce((i,u)=>i*u,1),o=T(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n);return 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 or(r){if(r.length===0)return[];if(r.length===1)return Array.from(r[0]);let t=Math.max(...r.map(n=>n.length)),e=new Array(t);for(let n=0;n<t;n++){let o=1;for(let a of r){let i=a.length-t+n,u=i<0?1:a[i];if(u!==1){if(o===1)o=u;else if(o!==u)return null}}e[n]=o}return e}function Ji(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let i=0;i<n;i++){let u=o-n+i,s=r[i],c=e[u];if(s===c)a[u]=t[i];else if(s===1)a[u]=0;else throw new Error("Invalid broadcast")}return a}function ar(r,t){let e=Ji(r.shape,r.strides,t);return S.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function vt(...r){let t=or(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 Yr=k(()=>{"use strict";R()});function lr(r,t){let e=r.length,n=t.length,o=Math.max(e,n),a=new Array(o);for(let i=0;i<o;i++){let u=i<o-e?1:r[i-(o-e)],s=i<o-n?1:t[i-(o-n)];if(u===s)a[i]=u;else if(u===1)a[i]=s;else if(s===1)a[i]=u;else throw new Error(`operands could not be broadcast together with shapes ${JSON.stringify(Array.from(r))} ${JSON.stringify(Array.from(t))}`)}return a}function Xi(r,t,e){let n=r.length,o=e.length,a=new Array(o).fill(0);for(let i=0;i<n;i++){let u=o-n+i,s=r[i],c=e[u];if(s===c)a[u]=t[i];else if(s===1)a[u]=0;else throw new Error("Invalid broadcast")}return a}function Jr(r,t){let e=Xi(r.shape,r.strides,t);return S.fromData(r.data,Array.from(t),r.dtype,e,r.offset)}function P(r,t,e,n){let o=lr(r.shape,t.shape),a=Jr(r,o),i=Jr(t,o),u=C(r.dtype,t.dtype),s=S.zeros(o,u),c=s.data,l=s.size;if(w(u)){let m=c;for(let f=0;f<l;f++){let p=a.iget(f),y=i.iget(f),d=typeof p=="bigint"?p:BigInt(Math.round(p)),g=typeof y=="bigint"?y:BigInt(Math.round(y));n==="add"?m[f]=d+g:n==="subtract"?m[f]=d-g:n==="multiply"?m[f]=d*g:n==="divide"?m[f]=d/g:m[f]=BigInt(Math.round(e(Number(d),Number(g))))}}else{let m=w(r.dtype)||w(t.dtype);for(let f=0;f<l;f++){let p=a.iget(f),y=i.iget(f),d=Number(p),g=Number(y);c[f]=e(d,g)}}return s}function Q(r,t,e){let n=lr(r.shape,t.shape),o=Jr(r,n),a=Jr(t,n),i=n.reduce((c,l)=>c*l,1),u=new Uint8Array(i),s=w(r.dtype)||w(t.dtype);for(let c=0;c<i;c++){let l=o.iget(c),m=a.iget(c),f=Number(l),p=Number(m);u[c]=e(f,p)?1:0}return S.fromData(u,n,"bool")}function V(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=S.zeros(o,u),c=s.data,l=r.data;if(w(n))if(w(u)){let m=c;for(let f=0;f<a;f++){let p=Number(l[f]);m[f]=BigInt(Math.round(t(p)))}}else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));else for(let m=0;m<a;m++)c[m]=t(Number(l[m]));return s}var sr=k(()=>{"use strict";R();W()});function Et(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function tn(r,t){return typeof t=="number"?tu(r,t):Et(r,t)?Qi(r,t):P(r,t,(e,n)=>e+n,"add")}function Qi(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=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 m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m+f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]+m[f]}}else if(w(r.dtype)||w(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];u[c]=l+m}else for(let c=0;c<o;c++)u[c]=a[c]+i[c];return n}function en(r,t){return typeof t=="number"?eu(r,t):Et(r,t)?Ki(r,t):P(r,t,(e,n)=>e-n,"subtract")}function Ki(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=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 m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m-f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]-m[f]}}else if(w(r.dtype)||w(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];u[c]=l-m}else for(let c=0;c<o;c++)u[c]=a[c]-i[c];return n}function nn(r,t){return typeof t=="number"?nu(r,t):Et(r,t)?ru(r,t):P(r,t,(e,n)=>e*n,"multiply")}function ru(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=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 m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m*f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]*m[f]}}else if(w(r.dtype)||w(t.dtype))for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?Number(a[c]):a[c],m=typeof i[c]=="bigint"?Number(i[c]):i[c];u[c]=l*m}else for(let c=0;c<o;c++)u[c]=a[c]*i[c];return n}function on(r,t){if(typeof t=="number")return ou(r,t);let e=r.dtype==="float64",n=t.dtype==="float64",o=r.dtype==="float32",a=t.dtype==="float32";if(e||n){let s=e?r:br(r,"float64"),c=n?t:br(t,"float64");return P(s,c,(l,m)=>l/m,"divide")}if(o||a){let s=o?r:br(r,"float32"),c=a?t:br(t,"float32");return P(s,c,(l,m)=>l/m,"divide")}let i=br(r,"float64"),u=br(t,"float64");return P(i,u,(s,c)=>s/c,"divide")}function br(r,t){let e=S.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 tu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]+l}else for(let s=0;s<a;s++)u[s]=Number(o[s])+t;return i}function eu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]-l}else for(let s=0;s<a;s++)u[s]=Number(o[s])-t;return i}function nu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]*l}else for(let s=0;s<a;s++)u[s]=Number(o[s])*t;return i}function ou(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=S.zeros(n,u),c=s.data;if(w(e))for(let l=0;l<a;l++)c[l]=Number(o[l])/t;else for(let l=0;l<a;l++)c[l]=Number(o[l])/t;return s}function an(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),i=a.data;if(w(t)){let u=n,s=i;for(let c=0;c<o;c++){let l=u[c];s[c]=l<0n?-l:l}}else for(let u=0;u<o;u++)i[u]=Math.abs(Number(n[u]));return a}function sn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),i=a.data;if(w(t)){let u=n,s=i;for(let c=0;c<o;c++)s[c]=-u[c]}else for(let u=0;u<o;u++)i[u]=-Number(n[u]);return a}function un(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),i=a.data;if(w(t)){let u=n,s=i;for(let c=0;c<o;c++){let l=u[c];s[c]=l>0n?1n:l<0n?-1n:0n}}else for(let u=0;u<o;u++){let s=Number(n[u]);i[u]=s>0?1:s<0?-1:0}return a}function Xr(r,t){return typeof t=="number"?au(r,t):P(r,t,(e,n)=>(e%n+n)%n,"mod")}function au(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++){let f=s[m];c[m]=(f%l+l)%l}}else for(let s=0;s<a;s++){let c=Number(o[s]);u[s]=(c%t+t)%t}return i}function Ot(r,t){return typeof t=="number"?su(r,t):P(r,t,(e,n)=>Math.floor(e/n),"floor_divide")}function su(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]/l}else for(let s=0;s<a;s++)u[s]=Math.floor(Number(o[s])/t);return i}function cn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),i=a.data;for(let u=0;u<o;u++)i[u]=n[u];return a}function ln(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,i=t!=="float32"&&t!=="float64"?"float64":t,u=S.zeros(e,i),s=u.data;if(w(t))for(let c=0;c<o;c++)s[c]=1/Number(n[c]);else for(let c=0;c<o;c++)s[c]=1/Number(n[c]);return u}function fn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,i=t!=="float32"&&t!=="float64"?"float64":t,u=S.zeros(e,i),s=u.data;for(let c=0;c<o;c++)s[c]=Math.cbrt(Number(n[c]));return u}function mn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=S.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.abs(Number(n[s]));return i}function pn(r,t){let e=Ot(r,t),n=Xr(r,t);return[e,n]}function yn(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),i=a.data;if(w(t)){let u=n,s=i;for(let c=0;c<o;c++)s[c]=u[c]*u[c]}else for(let u=0;u<o;u++){let s=Number(n[u]);i[u]=s*s}return a}function dn(r,t){return Xr(r,t)}function gn(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=S.zeros(n,a),u=i.data;if(typeof t=="number")for(let s=0;s<o;s++){let c=Number(r.data[s]);c<0?u[s]=0:c===0?u[s]=t:u[s]=1}else{let s=t.data,c=t.shape;if(n.every((l,m)=>l===c[m]))for(let l=0;l<o;l++){let m=Number(r.data[l]);m<0?u[l]=0:m===0?u[l]=Number(s[l]):u[l]=1}else for(let l=0;l<o;l++){let m=Number(r.data[l]),f=l%t.size;m<0?u[l]=0:m===0?u[l]=Number(s[f]):u[l]=1}}return i}function bn(r,t){if(typeof t=="number"){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size;for(let i=0;i<a;i++)n[i]=Math.pow(Number(o[i]),t);return e}return P(r,t,(e,n)=>Math.pow(e,n),"float_power")}function An(r,t){if(typeof t=="number"){let e=r.copy(),n=e.data,o=r.size;for(let a=0;a<o;a++){let i=Number(n[a]);n[a]=i-Math.trunc(i/t)*t}return e}return P(r,t,(e,n)=>e-Math.trunc(e/n)*n,"fmod")}function hn(r){let t=S.zeros(Array.from(r.shape),"float64"),e=S.zeros(Array.from(r.shape),"int32"),n=t.data,o=e.data,a=r.data,i=r.size;for(let u=0;u<i;u++){let s=Number(a[u]);if(s===0||!isFinite(s))n[u]=s,o[u]=0;else{let c=Math.floor(Math.log2(Math.abs(s)))+1,l=s/Math.pow(2,c);n[u]=l,o[u]=c}}return[t,e]}function Sn(r,t){let e=(s,c)=>{for(s=Math.abs(Math.trunc(s)),c=Math.abs(Math.trunc(c));c!==0;){let l=c;c=s%c,s=l}return s};if(typeof t=="number"){let s=S.zeros(Array.from(r.shape),"int32"),c=s.data,l=r.data,m=r.size,f=Math.abs(Math.trunc(t));for(let p=0;p<m;p++)c[p]=e(Number(l[p]),f);return s}let n=P(r,t,e,"gcd"),o=S.zeros(Array.from(n.shape),"int32"),a=o.data,i=n.data,u=n.size;for(let s=0;s<u;s++)a[s]=Math.round(Number(i[s]));return o}function Nn(r,t){let e=(c,l)=>{for(c=Math.abs(Math.trunc(c)),l=Math.abs(Math.trunc(l));l!==0;){let m=l;l=c%l,c=m}return c},n=(c,l)=>(c=Math.abs(Math.trunc(c)),l=Math.abs(Math.trunc(l)),c===0||l===0?0:c*l/e(c,l));if(typeof t=="number"){let c=S.zeros(Array.from(r.shape),"int32"),l=c.data,m=r.data,f=r.size,p=Math.abs(Math.trunc(t));for(let y=0;y<f;y++)l[y]=n(Number(m[y]),p);return c}let o=P(r,t,n,"lcm"),a=S.zeros(Array.from(o.shape),"int32"),i=a.data,u=o.data,s=o.size;for(let c=0;c<s;c++)i[c]=Math.round(Number(u[c]));return a}function Dn(r,t){if(typeof t=="number"){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size,i=Math.pow(2,t);for(let u=0;u<a;u++)n[u]=Number(o[u])*i;return e}return P(r,t,(e,n)=>e*Math.pow(2,n),"ldexp")}function xn(r){let t=S.zeros(Array.from(r.shape),"float64"),e=S.zeros(Array.from(r.shape),"float64"),n=t.data,o=e.data,a=r.data,i=r.size;for(let u=0;u<i;u++){let s=Number(a[u]),c=Math.trunc(s);o[u]=c,n[u]=s-c}return[t,e]}var wn=k(()=>{"use strict";R();W();sr()});function zn(r,t){return typeof t=="number"?uu(r,t):Q(r,t,(e,n)=>e>n)}function In(r,t){return typeof t=="number"?cu(r,t):Q(r,t,(e,n)=>e>=n)}function _n(r,t){return typeof t=="number"?lu(r,t):Q(r,t,(e,n)=>e<n)}function Bn(r,t){return typeof t=="number"?fu(r,t):Q(r,t,(e,n)=>e<=n)}function vn(r,t){return typeof t=="number"?mu(r,t):Q(r,t,(e,n)=>e===n)}function En(r,t){return typeof t=="number"?pu(r,t):Q(r,t,(e,n)=>e!==n)}function Mt(r,t,e=1e-5,n=1e-8){return typeof t=="number"?yu(r,t,e,n):Q(r,t,(o,a)=>{let i=Math.abs(o-a),u=n+e*Math.abs(a);return i<=u})}function On(r,t,e=1e-5,n=1e-8){let o=Mt(r,t,e,n),a=o.data;for(let i=0;i<o.size;i++)if(a[i]===0)return!1;return!0}function Mn(r,t){let e=[Array.from(r.shape),Array.from(t.shape)],n=or(e);if(n===null)return!1;let o=ar(r,n),a=ar(t,n),i=n.length,u=n.reduce((l,m)=>l*m,1),s=w(o.dtype),c=w(a.dtype);for(let l=0;l<u;l++){let m=l,f=new Array(i);for(let d=i-1;d>=0;d--)f[d]=m%n[d],m=Math.floor(m/n[d]);let p=o.get(...f),y=a.get(...f);if(s||c){let d=typeof p=="bigint"?p:BigInt(Number(p)),g=typeof y=="bigint"?y:BigInt(Number(y));if(d!==g)return!1}else if(p!==y)return!1}return!0}function uu(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 S.fromData(e,Array.from(r.shape),"bool")}function cu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]>=t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function lu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]<t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function fu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]<=t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function mu(r,t){let e=new Uint8Array(r.size),n=r.data,o=r.dtype;if(w(o)){let a=BigInt(Math.round(t)),i=n;for(let u=0;u<r.size;u++)e[u]=i[u]===a?1:0}else for(let a=0;a<r.size;a++)e[a]=n[a]===t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function pu(r,t){let e=new Uint8Array(r.size),n=r.data;for(let o=0;o<r.size;o++)e[o]=n[o]!==t?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function yu(r,t,e,n){let o=new Uint8Array(r.size),a=r.data,i=r.dtype;if(w(i)){let u=a;for(let s=0;s<r.size;s++){let c=Number(u[s]),l=Math.abs(c-t),m=n+e*Math.abs(t);o[s]=l<=m?1:0}}else for(let u=0;u<r.size;u++){let s=Number(a[u]),c=Math.abs(s-t),l=n+e*Math.abs(t);o[u]=c<=l?1:0}return S.fromData(o,Array.from(r.shape),"bool")}var Tn=k(()=>{"use strict";R();W();sr();Yr()});function O(r,t){let e=0,n=1;for(let o=r.length-1;o>=0;o--)e+=r[o]*n,n*=t[o];return e}function M(r,t,e,n){let o=n.length,a=new Array(o),i=Array.from(n).filter((s,c)=>c!==t),u=r;for(let s=i.length-1;s>=0;s--)a[s>=t?s+1:s]=u%i[s],u=Math.floor(u/i[s]);return a[t]=e,a}var Tt=k(()=>{"use strict"});function _r(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0)if(w(n)){let y=u,d=BigInt(0);for(let g=0;g<i;g++)d+=y[g];return Number(d)}else{let y=0;for(let d=0;d<i;d++)y+=Number(u[d]);return y}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return _r(r);let l=S.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=m;for(let g=0;g<p;g++){let h=BigInt(0);for(let A=0;A<f;A++){let b=M(g,s,A,o),N=O(b,o);h+=y[N]}d[g]=h}}else for(let y=0;y<p;y++){let d=0;for(let g=0;g<f;g++){let h=M(y,s,g,o),A=O(h,o);d+=Number(u[A])}m[y]=d}if(e){let y=[...o];return y[s]=1,S.fromData(m,y,n)}return l}function Qr(r,t,e=!1){let n=r.dtype,o=r.shape;if(t===void 0)return _r(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=_r(r,t,e);if(typeof i=="number")return i/o[a];let u=o[a],s=n;(w(n)||n.startsWith("int")||n.startsWith("uint"))&&(s="float64");let c=S.zeros(Array.from(i.shape),s),l=c.data,m=i.data;if(w(n)){let f=m;for(let p=0;p<l.length;p++)l[p]=Number(f[p])/u}else for(let f=0;f<l.length;f++)l[f]=Number(m[f])/u;return c}function Kr(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0){if(i===0)throw new Error("max of empty array");let y=u[0];for(let d=1;d<i;d++)u[d]>y&&(y=u[d]);return Number(y)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return Kr(r);let l=S.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=m;for(let g=0;g<p;g++){let h=M(g,s,0,o),A=O(h,o),b=y[A];for(let N=1;N<f;N++){let D=M(g,s,N,o),x=O(D,o),z=y[x];z>b&&(b=z)}d[g]=b}}else for(let y=0;y<p;y++){let d=-1/0;for(let g=0;g<f;g++){let h=M(y,s,g,o),A=O(h,o),b=Number(u[A]);b>d&&(d=b)}m[y]=d}if(e){let y=[...o];return y[s]=1,S.fromData(m,y,n)}return l}function Ut(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0)if(w(n)){let y=u,d=BigInt(1);for(let g=0;g<i;g++)d*=y[g];return Number(d)}else{let y=1;for(let d=0;d<i;d++)y*=Number(u[d]);return y}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return Ut(r);let l=S.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=m;for(let g=0;g<p;g++){let h=BigInt(1);for(let A=0;A<f;A++){let b=M(g,s,A,o),N=O(b,o);h*=y[N]}d[g]=h}}else for(let y=0;y<p;y++){let d=1;for(let g=0;g<f;g++){let h=M(y,s,g,o),A=O(h,o);d*=Number(u[A])}m[y]=d}if(e){let y=[...o];return y[s]=1,S.fromData(m,y,n)}return l}function rt(r,t,e=!1){let n=r.dtype,o=r.shape,a=o.length,i=r.size,u=r.data;if(t===void 0){if(i===0)throw new Error("min of empty array");let y=u[0];for(let d=1;d<i;d++)u[d]<y&&(y=u[d]);return Number(y)}let s=t;if(s<0&&(s=a+s),s<0||s>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let c=Array.from(o).filter((y,d)=>d!==s);if(c.length===0)return rt(r);let l=S.zeros(c,n),m=l.data,f=o[s],p=c.reduce((y,d)=>y*d,1);if(w(n)){let y=u,d=m;for(let g=0;g<p;g++){let h=M(g,s,0,o),A=O(h,o),b=y[A];for(let N=1;N<f;N++){let D=M(g,s,N,o),x=O(D,o),z=y[x];z<b&&(b=z)}d[g]=b}}else for(let y=0;y<p;y++){let d=1/0;for(let g=0;g<f;g++){let h=M(y,s,g,o),A=O(h,o),b=Number(u[A]);b<d&&(d=b)}m[y]=d}if(e){let y=[...o];return y[s]=1,S.fromData(m,y,n)}return l}function $t(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmin of empty array");let p=i[0],y=0;for(let d=1;d<a;d++)i[d]<p&&(p=i[d],y=d);return y}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return $t(r);let c=S.zeros(s,"int32"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);if(w(e)){let p=i;for(let y=0;y<f;y++){let d=M(y,u,0,n),g=O(d,n),h=p[g],A=0;for(let b=1;b<m;b++){let N=M(y,u,b,n),D=O(N,n),x=p[D];x<h&&(h=x,A=b)}l[y]=A}}else for(let p=0;p<f;p++){let y=1/0,d=0;for(let g=0;g<m;g++){let h=M(p,u,g,n),A=O(h,n),b=Number(i[A]);b<y&&(y=b,d=g)}l[p]=d}return c}function kt(r,t){let e=r.dtype,n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){if(a===0)throw new Error("argmax of empty array");let p=i[0],y=0;for(let d=1;d<a;d++)i[d]>p&&(p=i[d],y=d);return y}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return kt(r);let c=S.zeros(s,"int32"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);if(w(e)){let p=i;for(let y=0;y<f;y++){let d=M(y,u,0,n),g=O(d,n),h=p[g],A=0;for(let b=1;b<m;b++){let N=M(y,u,b,n),D=O(N,n),x=p[D];x>h&&(h=x,A=b)}l[y]=A}}else for(let p=0;p<f;p++){let y=-1/0,d=0;for(let g=0;g<m;g++){let h=M(p,u,g,n),A=O(h,n),b=Number(i[A]);b>y&&(y=b,d=g)}l[p]=d}return c}function Ct(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.size,u=r.data,s=Qr(r,t,n);if(t===void 0){let h=s,A=0;for(let b=0;b<i;b++){let N=Number(u[b])-h;A+=N*N}return A/(i-e)}let c=t;if(c<0&&(c=a+c),c<0||c>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let l=o[c],m=s,f=m.data,p=n?m.shape:Array.from(o).filter((h,A)=>A!==c),y=S.zeros(Array.from(p),"float64"),d=y.data,g=p.reduce((h,A)=>h*A,1);for(let h=0;h<g;h++){let A=0,b=Number(f[h]);for(let N=0;N<l;N++){let D=M(h,c,N,o),x=O(D,o),z=Number(u[x])-b;A+=z*z}d[h]=A/(l-e)}return y}function Un(r,t,e=0,n=!1){let o=Ct(r,t,e,n);if(typeof o=="number")return Math.sqrt(o);let a=S.zeros(Array.from(o.shape),"float64"),i=o.data,u=a.data;for(let s=0;s<i.length;s++)u[s]=Math.sqrt(Number(i[s]));return a}function Ft(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(!i[p])return!1;return!0}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return Ft(r);let c=S.zeros(s,"bool"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);for(let p=0;p<f;p++){let y=!0;for(let d=0;d<m;d++){let g=M(p,u,d,n),h=O(g,n);if(!i[h]){y=!1;break}}l[p]=y?1:0}if(e){let p=[...n];return p[u]=1,S.fromData(l,p,"bool")}return c}function Vt(r,t,e=!1){let n=r.shape,o=n.length,a=r.size,i=r.data;if(t===void 0){for(let p=0;p<a;p++)if(i[p])return!0;return!1}let u=t;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let s=Array.from(n).filter((p,y)=>y!==u);if(s.length===0)return Vt(r);let c=S.zeros(s,"bool"),l=c.data,m=n[u],f=s.reduce((p,y)=>p*y,1);for(let p=0;p<f;p++){let y=!1;for(let d=0;d<m;d++){let g=M(p,u,d,n),h=O(g,n);if(i[h]){y=!0;break}}l[p]=y?1:0}if(e){let p=[...n];return p[u]=1,S.fromData(l,p,"bool")}return c}function Pt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=0;for(let d=0;d<f;d++)y+=Number(o[d]),p[d]=y;return S.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++)Math.floor(f/m)%u===0?i[f]=Number(o[f]):i[f]=i[f-m]+Number(o[f]);return S.fromData(i,[...e],"float64")}function qt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=1;for(let d=0;d<f;d++)y*=Number(o[d]),p[d]=y;return S.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++)Math.floor(f/m)%u===0?i[f]=Number(o[f]):i[f]=i[f-m]*Number(o[f]);return S.fromData(i,[...e],"float64")}function jt(r,t,e=!1){let n=Kr(r,t,e),o=rt(r,t,e);if(typeof n=="number"&&typeof o=="number")return n-o;let a=n,i=o,u=a.data,s=i.data,c=new Float64Array(a.size);for(let l=0;l<a.size;l++)c[l]=Number(u[l])-Number(s[l]);return S.fromData(c,[...a.shape],"float64")}function Rt(r,t,e=!1){return Ar(r,.5,t,e)}function Lt(r,t,e,n=!1){return Ar(r,t/100,e,n)}function Ar(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,N)=>b-N);let y=p.length,d=t*(y-1),g=Math.floor(d),h=Math.ceil(d);if(g===h)return p[g];let A=d-g;return p[g]*(1-A)+p[h]*A}let u=e;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${e} is out of bounds for array of dimension ${a}`);let s=Array.from(o).filter((p,y)=>y!==u);if(s.length===0)return Ar(r,t);let c=s.reduce((p,y)=>p*y,1),l=o[u],m=new Float64Array(c);for(let p=0;p<c;p++){let y=[];for(let b=0;b<l;b++){let N=M(p,u,b,o),D=O(N,o);y.push(Number(i[D]))}y.sort((b,N)=>b-N);let d=y.length,g=t*(d-1),h=Math.floor(g),A=Math.ceil(g);if(h===A)m[p]=y[h];else{let b=g-h;m[p]=y[h]*(1-b)+y[A]*b}}let f=S.fromData(m,s,"float64");if(n){let p=[...o];return p[u]=1,S.fromData(m,p,"float64")}return f}function tt(r,t,e,n=!1){let o=r.shape,a=o.length,i=r.data;if(e===void 0)return Qr(r,t,n);if(t===void 0){let y=0,d=0,g=e.data;for(let h=0;h<r.size;h++){let A=Number(g[h%e.size]);y+=Number(i[h])*A,d+=A}return d===0?NaN:y/d}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let s=Array.from(o).filter((y,d)=>d!==u);if(s.length===0)return tt(r,void 0,e);let c=s.reduce((y,d)=>y*d,1),l=o[u],m=e.data,f=new Float64Array(c);for(let y=0;y<c;y++){let d=0,g=0;for(let h=0;h<l;h++){let A=M(y,u,h,o),b=O(A,o),N=Number(m[h%e.size]);d+=Number(i[b])*N,g+=N}f[y]=g===0?NaN:d/g}let p=S.fromData(f,s,"float64");if(n){let y=[...o];return y[u]=1,S.fromData(f,y,"float64")}return p}function et(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=0;for(let p=0;p<r.size;p++){let y=Number(a[p]);isNaN(y)||(f+=y)}return f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return et(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=0;for(let y=0;y<c;y++){let d=M(f,i,y,n),g=O(d,n),h=Number(a[g]);isNaN(h)||(p+=h)}l[f]=p}let m=S.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,S.fromData(l,f,"float64")}return m}function nt(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=1;for(let p=0;p<r.size;p++){let y=Number(a[p]);isNaN(y)||(f*=y)}return f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return nt(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=1;for(let y=0;y<c;y++){let d=M(f,i,y,n),g=O(d,n),h=Number(a[g]);isNaN(h)||(p*=h)}l[f]=p}let m=S.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,S.fromData(l,f,"float64")}return m}function ot(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=0,p=0;for(let y=0;y<r.size;y++){let d=Number(a[y]);isNaN(d)||(f+=d,p++)}return p===0?NaN:f/p}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return ot(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=0,y=0;for(let d=0;d<c;d++){let g=M(f,i,d,n),h=O(g,n),A=Number(a[h]);isNaN(A)||(p+=A,y++)}l[f]=y===0?NaN:p/y}let m=S.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,S.fromData(l,f,"float64")}return m}function Br(r,t,e=0,n=!1){let o=r.shape,a=o.length,i=r.data;if(t===void 0){let p=0,y=0;for(let h=0;h<r.size;h++){let A=Number(i[h]);isNaN(A)||(p+=A,y++)}if(y-e<=0)return NaN;let d=p/y,g=0;for(let h=0;h<r.size;h++){let A=Number(i[h]);isNaN(A)||(g+=(A-d)**2)}return g/(y-e)}let u=t;if(u<0&&(u=a+u),u<0||u>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let s=Array.from(o).filter((p,y)=>y!==u);if(s.length===0)return Br(r,void 0,e);let c=s.reduce((p,y)=>p*y,1),l=o[u],m=new Float64Array(c);for(let p=0;p<c;p++){let y=0,d=0;for(let A=0;A<l;A++){let b=M(p,u,A,o),N=O(b,o),D=Number(i[N]);isNaN(D)||(y+=D,d++)}if(d-e<=0){m[p]=NaN;continue}let g=y/d,h=0;for(let A=0;A<l;A++){let b=M(p,u,A,o),N=O(b,o),D=Number(i[N]);isNaN(D)||(h+=(D-g)**2)}m[p]=h/(d-e)}let f=S.fromData(m,s,"float64");if(n){let p=[...o];return p[u]=1,S.fromData(m,p,"float64")}return f}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=o,i=new Float64Array(a.size);for(let u=0;u<a.size;u++)i[u]=Math.sqrt(Number(a.data[u]));return S.fromData(i,[...a.shape],"float64")}function at(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=1/0;for(let p=0;p<r.size;p++){let y=Number(a[p]);!isNaN(y)&&y<f&&(f=y)}return f===1/0?NaN:f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return at(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=1/0;for(let y=0;y<c;y++){let d=M(f,i,y,n),g=O(d,n),h=Number(a[g]);!isNaN(h)&&h<p&&(p=h)}l[f]=p===1/0?NaN:p}let m=S.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,S.fromData(l,f,"float64")}return m}function st(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=-1/0;for(let p=0;p<r.size;p++){let y=Number(a[p]);!isNaN(y)&&y>f&&(f=y)}return f===-1/0?NaN:f}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return st(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=-1/0;for(let y=0;y<c;y++){let d=M(f,i,y,n),g=O(d,n),h=Number(a[g]);!isNaN(h)&&h>p&&(p=h)}l[f]=p===-1/0?NaN:p}let m=S.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,S.fromData(l,f,"float64")}return m}function it(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=1/0,m=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p<l&&(l=p,m=f)}return m}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,m)=>m!==a);if(i.length===0)return it(r);let u=i.reduce((l,m)=>l*m,1),s=e[a],c=new Int32Array(u);for(let l=0;l<u;l++){let m=1/0,f=0;for(let p=0;p<s;p++){let y=M(l,a,p,e),d=O(y,e),g=Number(o[d]);!isNaN(g)&&g<m&&(m=g,f=p)}c[l]=f}return S.fromData(c,i,"int32")}function ut(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let l=-1/0,m=-1;for(let f=0;f<r.size;f++){let p=Number(o[f]);!isNaN(p)&&p>l&&(l=p,m=f)}return m}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=Array.from(e).filter((l,m)=>m!==a);if(i.length===0)return ut(r);let u=i.reduce((l,m)=>l*m,1),s=e[a],c=new Int32Array(u);for(let l=0;l<u;l++){let m=-1/0,f=0;for(let p=0;p<s;p++){let y=M(l,a,p,e),d=O(y,e),g=Number(o[d]);!isNaN(g)&&g>m&&(m=g,f=p)}c[l]=f}return S.fromData(c,i,"int32")}function Gt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=0;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(y+=g),p[d]=y}return S.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/m)%u===0?i[f]=isNaN(p)?0:p:i[f]=i[f-m]+(isNaN(p)?0:p)}return S.fromData(i,[...e],"float64")}function Zt(r,t){let e=r.shape,n=e.length,o=r.data;if(t===void 0){let f=r.size,p=new Float64Array(f),y=1;for(let d=0;d<f;d++){let g=Number(o[d]);isNaN(g)||(y*=g),p[d]=y}return S.fromData(p,[f],"float64")}let a=t;if(a<0&&(a=n+a),a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let i=new Float64Array(r.size),u=e[a],s=[],c=1;for(let f=n-1;f>=0;f--)s.unshift(c),c*=e[f];let l=r.size,m=s[a];for(let f=0;f<l;f++){let p=Number(o[f]);Math.floor(f/m)%u===0?i[f]=isNaN(p)?1:p:i[f]=i[f-m]*(isNaN(p)?1:p)}return S.fromData(i,[...e],"float64")}function ct(r,t,e=!1){let n=r.shape,o=n.length,a=r.data;if(t===void 0){let f=[];for(let d=0;d<r.size;d++){let g=Number(a[d]);isNaN(g)||f.push(g)}if(f.length===0)return NaN;f.sort((d,g)=>d-g);let p=f.length,y=Math.floor(p/2);return p%2===0?(f[y-1]+f[y])/2:f[y]}let i=t;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let u=Array.from(n).filter((f,p)=>p!==i);if(u.length===0)return ct(r);let s=u.reduce((f,p)=>f*p,1),c=n[i],l=new Float64Array(s);for(let f=0;f<s;f++){let p=[];for(let g=0;g<c;g++){let h=M(f,i,g,n),A=O(h,n),b=Number(a[A]);isNaN(b)||p.push(b)}if(p.length===0){l[f]=NaN;continue}p.sort((g,h)=>g-h);let y=p.length,d=Math.floor(y/2);y%2===0?l[f]=(p[d-1]+p[d])/2:l[f]=p[d]}let m=S.fromData(l,u,"float64");if(e){let f=[...n];return f[i]=1,S.fromData(l,f,"float64")}return m}var $n=k(()=>{"use strict";R();W();Tt()});function G(r,t){let e=r.size,n=r.dtype,o=t.indexOf(-1),a;if(o!==-1){let c=t.reduce((m,f,p)=>p===o?m:m*f,1),l=e/c;if(!Number.isInteger(l))throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(t)}`);a=t.map((m,f)=>f===o?l:m)}else a=t;if(a.reduce((c,l)=>c*l,1)!==e)throw new Error(`cannot reshape array of size ${e} into shape ${JSON.stringify(a)}`);if(r.isCContiguous){let c=r.data;return S.fromData(c,a,n,H(a),0)}let s=r.copy().data;return S.fromData(s,a,n,H(a),0)}function lt(r){let t=r.size,e=r.dtype,n=T(e);if(!n)throw new Error(`Cannot flatten array with dtype ${e}`);if(r.isCContiguous){let u=r.data.slice(r.offset,r.offset+t);return S.fromData(u,[t],e,[1],0)}let o=new n(t),a=w(e);for(let i=0;i<t;i++){let u=r.iget(i);o[i]=u}return S.fromData(o,[t],e,[1],0)}function hr(r){let t=r.size,e=r.dtype;if(r.isCContiguous){let n=r.data;return S.fromData(n,[t],e,[1],0)}return lt(r)}function Er(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype,u;if(t===void 0)u=Array.from({length:n},(m,f)=>n-1-f);else{if(t.length!==n)throw new Error(`axes must have length ${n}, got ${t.length}`);let m=new Set;for(let f of t){let p=f<0?n+f:f;if(p<0||p>=n)throw new Error(`axis ${f} is out of bounds for array of dimension ${n}`);if(m.has(p))throw new Error("repeated axis in transpose");m.add(p)}u=t.map(f=>f<0?n+f:f)}let s=u.map(m=>e[m]),c=Array.from(o),l=u.map(m=>c[m]);return S.fromData(a,s,i,l,r.offset)}function kn(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype;if(t===void 0){let u=[],s=[];for(let c=0;c<n;c++)e[c]!==1&&(u.push(e[c]),s.push(o[c]));return u.length===0&&(u.push(1),s.push(1)),S.fromData(a,u,i,s,r.offset)}else{let u=t<0?n+t:t;if(u<0||u>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);if(e[u]!==1)throw new Error(`cannot select an axis which has size not equal to one (axis ${t} has size ${e[u]})`);let s=[],c=[];for(let l=0;l<n;l++)l!==u&&(s.push(e[l]),c.push(o[l]));return S.fromData(a,s,i,c,r.offset)}}function vr(r,t){let e=r.shape,n=e.length,o=r.strides,a=r.data,i=r.dtype,u=t;if(u<0&&(u=n+t+1),u<0||u>n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n+1}`);let s=[...Array.from(e)];s.splice(u,0,1);let c=[...Array.from(o)],l=u<n?o[u]*(e[u]||1):1;return c.splice(u,0,l),S.fromData(a,s,i,c,r.offset)}function Cn(r,t,e){let n=r.shape,o=n.length,a=r.strides,i=r.data,u=r.dtype,s=t<0?o+t:t,c=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis1 ${t} is out of bounds for array of dimension ${o}`);if(c<0||c>=o)throw new Error(`axis2 ${e} is out of bounds for array of dimension ${o}`);if(s===c)return S.fromData(i,Array.from(n),u,Array.from(a),r.offset);let l=Array.from(n),m=Array.from(a);return[l[s],l[c]]=[l[c],l[s]],[m[s],m[c]]=[m[c],m[s]],S.fromData(i,l,u,m,r.offset)}function Ht(r,t,e){let n=r.ndim,o=Array.isArray(t)?t:[t],a=Array.isArray(e)?e:[e];if(o.length!==a.length)throw new Error("source and destination must have the same number of elements");let i=o.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`source axis ${c} is out of bounds for array of dimension ${n}`);return l}),u=a.map(c=>{let l=c<0?n+c:c;if(l<0||l>=n)throw new Error(`destination axis ${c} is out of bounds for array of dimension ${n}`);return l});if(new Set(i).size!==i.length)throw new Error("repeated axis in source");if(new Set(u).size!==u.length)throw new Error("repeated axis in destination");let s=[];for(let c=0;c<n;c++)i.includes(c)||s.push(c);for(let c=0;c<i.length;c++){let l=u[c];s.splice(l,0,i[c])}return Er(r,s)}function pr(r,t=0){if(r.length===0)throw new Error("need at least one array to concatenate");if(r.length===1)return r[0].copy();let e=r[0],n=e.ndim,o=e.dtype,a=t<0?n+t:t;if(a<0||a>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);for(let p=1;p<r.length;p++){let y=r[p];if(y.ndim!==n)throw new Error("all the input arrays must have same number of dimensions");for(let d=0;d<n;d++)if(d!==a&&y.shape[d]!==e.shape[d])throw new Error("all the input array dimensions except for the concatenation axis must match exactly")}let i=Array.from(e.shape),u=e.shape[a];for(let p=1;p<r.length;p++)u+=r[p].shape[a];i[a]=u;let s=i.reduce((p,y)=>p*y,1),c=T(o);if(!c)throw new Error(`Cannot concatenate arrays with dtype ${o}`);let l=new c(s),m=H(i),f=0;for(let p of r){let y=p.shape[a];bu(p,l,i,m,a,f,o),f+=y}return S.fromData(l,i,o)}function bu(r,t,e,n,o,a,i){let u=r.shape,s=u.length,c=r.size,l=i==="int64"||i==="uint64";if(o===0&&r.isCContiguous&&s>0){let p=a*n[0],y=r.data,d=r.offset,g=d+c;t.set(y.subarray(d,g),p);return}if(o===1&&s===2&&r.isCContiguous){let p=u[0],y=u[1],d=e[1],g=r.data,h=r.offset;for(let A=0;A<p;A++){let b=h+A*y,N=A*d+a;t.set(g.subarray(b,b+y),N)}return}let m=new Array(s).fill(0),f=a*n[o];for(let p=0;p<c;p++){let y=r.iget(p),d=f;for(let g=0;g<s;g++)d+=m[g]*n[g];t[d]=y;for(let g=s-1;g>=0&&(m[g]++,!(m[g]<u[g]));g--)m[g]=0}}function Fn(r,t=0){if(r.length===0)throw new Error("need at least one array to stack");let e=r[0],n=e.shape,o=e.ndim,a=t<0?o+1+t:t;if(a<0||a>o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o+1}`);for(let u=1;u<r.length;u++){let s=r[u];if(s.ndim!==o)throw new Error("all input arrays must have the same shape");for(let c=0;c<o;c++)if(s.shape[c]!==n[c])throw new Error("all input arrays must have the same shape")}let i=r.map(u=>vr(u,a));return pr(i,a)}function Vn(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(e,[1,e.shape[0]]):e);return pr(t,0)}function Yt(r){if(r.length===0)throw new Error("need at least one array to stack");return r.every(e=>e.ndim===1)?pr(r,0):pr(r,1)}function Pn(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(vr(G(e,[1,e.shape[0]]),2),[1,e.shape[0],1]):e.ndim===2?vr(e,2):e);return pr(t,2)}function qn(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[a],u;if(typeof t=="number"){if(i%t!==0)throw new Error("array split does not result in an equal division");let s=i/t;u=[];for(let c=1;c<t;c++)u.push(c*s)}else u=t;return jn(r,u,a)}function Or(r,t,e=0){let n=r.shape,o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let i=n[a],u;if(typeof t=="number"){let s=t,c=Math.floor(i/s),l=i%s;u=[];let m=0;for(let f=0;f<s-1;f++)m+=c+(f<l?1:0),u.push(m)}else u=t;return jn(r,u,a)}function jn(r,t,e){let n=r.shape,o=n[e],a=[0,...t,o],i=[];for(let u=0;u<a.length-1;u++){let s=a[u],c=a[u+1];if(s>c)throw new Error("split indices must be in ascending order");let l=Array.from(n);l[e]=c-s;let m=r.offset+s*r.strides[e];i.push(S.fromData(r.data,l,r.dtype,Array.from(r.strides),m))}return i}function Rn(r,t){if(r.ndim<2)throw new Error("vsplit only works on arrays of 2 or more dimensions");return Or(r,t,0)}function Ln(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 Or(r,t,e)}function Wn(r,t){let e=r.shape,n=e.length,o=r.dtype,a=Array.isArray(t)?t:[t],i=Math.max(n,a.length),u=new Array(i).fill(1),s=new Array(i).fill(1);for(let A=0;A<n;A++)u[i-n+A]=e[A];for(let A=0;A<a.length;A++)s[i-a.length+A]=a[A];let c=u.map((A,b)=>A*s[b]),l=c.reduce((A,b)=>A*b,1),m=T(o);if(!m)throw new Error(`Cannot tile array with dtype ${o}`);let f=new m(l),p=H(c),y=r;n<i&&(y=G(r,u));let d=o==="int64"||o==="uint64",g=y.strides,h=new Array(i).fill(0);for(let A=0;A<l;A++){let b=y.offset;for(let x=0;x<i;x++){let z=h[x]%u[x];b+=z*g[x]}let N=y.data[b],D=0;for(let x=0;x<i;x++)D+=h[x]*p[x];f[D]=N;for(let x=i-1;x>=0&&(h[x]++,!(h[x]<c[x]));x--)h[x]=0}return S.fromData(f,c,o)}function Gn(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let A=i,b=Array.isArray(t)?t:new Array(A).fill(t);if(b.length!==A)throw new Error(`operands could not be broadcast together with shape (${A},) (${b.length},)`);let N=b.reduce((_,B)=>_+B,0),D=T(a);if(!D)throw new Error(`Cannot repeat array with dtype ${a}`);let x=new D(N),z=0;for(let _=0;_<A;_++){let B=r.iget(_),v=b[_];for(let E=0;E<v;E++)x[z++]=B}return S.fromData(x,[N],a)}let u=e<0?o+e:e;if(u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u],c=Array.isArray(t)?t:new Array(s).fill(t);if(c.length!==s)throw new Error(`operands could not be broadcast together with shape (${s},) (${c.length},)`);let l=Array.from(n);l[u]=c.reduce((A,b)=>A+b,0);let m=l.reduce((A,b)=>A*b,1),f=T(a);if(!f)throw new Error(`Cannot repeat array with dtype ${a}`);let p=new f(m),y=H(l),d=new Array(o).fill(0),g=a==="int64"||a==="uint64",h=[0];for(let A=0;A<s;A++)h.push(h[A]+c[A]);for(let A=0;A<i;A++){let b=r.iget(A),N=d[u],D=c[N],x=0;for(let B=0;B<o;B++)B!==u&&(x+=d[B]*y[B]);let z=y[u],_=h[N];for(let B=0;B<D;B++){let v=x+(_+B)*z;p[v]=b}for(let B=o-1;B>=0&&(d[B]++,!(d[B]<n[B]));B--)d[B]=0}return S.fromData(p,l,a)}function Zn(r,t){let e=r.shape,n=e.length,o=r.dtype,a=r.size,i;if(t===void 0)i=new Set(Array.from({length:n},(f,p)=>p));else if(typeof t=="number"){let f=t<0?n+t:t;if(f<0||f>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);i=new Set([f])}else i=new Set(t.map(f=>{let p=f<0?n+f:f;if(p<0||p>=n)throw new Error(`axis ${f} is out of bounds for array of dimension ${n}`);return p}));let u=T(o);if(!u)throw new Error(`Cannot flip array with dtype ${o}`);let s=new u(a),c=w(o);if(n===1&&r.isCContiguous){let f=r.data,p=r.offset;for(let y=0;y<a;y++)s[y]=f[p+a-1-y];return S.fromData(s,[...e],o)}if(n===2&&r.isCContiguous){let f=e[0],p=e[1],y=r.data,d=r.offset;if(i.size===2){for(let g=0;g<a;g++)s[g]=y[d+a-1-g];return S.fromData(s,[...e],o)}if(i.size===1){if(i.has(0)){for(let g=0;g<f;g++){let h=d+(f-1-g)*p,A=g*p;for(let b=0;b<p;b++)s[A+b]=y[h+b]}return S.fromData(s,[...e],o)}else if(i.has(1)){for(let g=0;g<f;g++){let h=d+g*p,A=g*p;for(let b=0;b<p;b++)s[A+b]=y[h+p-1-b]}return S.fromData(s,[...e],o)}}}let l=new Array(n),m=new Array(n).fill(0);for(let f=0;f<a;f++){for(let d=0;d<n;d++)l[d]=i.has(d)?e[d]-1-m[d]:m[d];let p=r.offset;for(let d=0;d<n;d++)p+=l[d]*r.strides[d];let y=r.data[p];s[f]=y;for(let d=n-1;d>=0&&(m[d]++,!(m[d]<e[d]));d--)m[d]=0}return S.fromData(s,[...e],o)}function Hn(r,t=1,e=[0,1]){let n=r.shape,o=n.length,a=r.dtype;if(o<2)throw new Error("Input must be at least 2-D");let i=e[0]<0?o+e[0]:e[0],u=e[1]<0?o+e[1]:e[1];if(i<0||i>=o||u<0||u>=o)throw new Error(`Axes are out of bounds for array of dimension ${o}`);if(i===u)throw new Error("Axes must be different");if(t=(t%4+4)%4,t===0)return r.copy();let s=T(a);if(!s)throw new Error(`Cannot rotate array with dtype ${a}`);let c=[...n];(t===1||t===3)&&([c[i],c[u]]=[c[u],c[i]]);let l=c.reduce((g,h)=>g*h,1),m=new s(l),f=H(c),p=w(a),y=new Array(o).fill(0),d=new Array(o);for(let g=0;g<r.size;g++){for(let D=0;D<o;D++)d[D]=y[D];let h,A;t===1?(h=n[u]-1-y[u],A=y[i]):t===2?(h=n[i]-1-y[i],A=n[u]-1-y[u],d[i]=h,d[u]=A):(h=y[u],A=n[i]-1-y[i]),t!==2&&(d[i]=h,d[u]=A);let b=0;for(let D=0;D<o;D++)b+=d[D]*f[D];let N=r.iget(g);m[b]=N;for(let D=o-1;D>=0&&(y[D]++,!(y[D]<n[D]));D--)y[D]=0}return S.fromData(m,c,a)}function Yn(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=r.size;if(e===void 0){let y=Array.isArray(t)?t.reduce((b,N)=>b+N,0):t,d=lt(r),g=T(a);if(!g)throw new Error(`Cannot roll array with dtype ${a}`);let h=new g(i),A=w(a);for(let b=0;b<i;b++){let N=((b-y)%i+i)%i,D=d.iget(N);h[b]=D}return S.fromData(h,[...n],a)}let u=Array.isArray(t)?t:[t],s=Array.isArray(e)?e:[e];if(u.length!==s.length)throw new Error("shift and axis must have the same length");let c=s.map(y=>{let d=y<0?o+y:y;if(d<0||d>=o)throw new Error(`axis ${y} is out of bounds for array of dimension ${o}`);return d}),l=T(a);if(!l)throw new Error(`Cannot roll array with dtype ${a}`);let m=new l(i),f=w(a),p=new Array(o).fill(0);for(let y=0;y<i;y++){let d=[...p];for(let A=0;A<c.length;A++){let b=c[A],N=n[b],D=u[A];d[b]=((d[b]-D)%N+N)%N}let g=r.offset;for(let A=0;A<o;A++)g+=d[A]*r.strides[A];let h=r.data[g];m[y]=h;for(let A=o-1;A>=0&&(p[A]++,!(p[A]<n[A]));A--)p[A]=0}return S.fromData(m,[...n],a)}function Jn(r,t,e=0){let n=r.ndim,o=t<0?n+t:t;if(o<0||o>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let a=e<0?n+e:e;if(a<0||a>n)throw new Error(`start ${e} is out of bounds`);return o<a&&a--,o===a?S.fromData(r.data,Array.from(r.shape),r.dtype,Array.from(r.strides),r.offset):Ht(r,o,a)}function Xn(r,t){if(r.ndim<3)throw new Error("dsplit only works on arrays of 3 or more dimensions");return Or(r,t,2)}function Qn(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(e=>e.ndim===1?G(e,[e.shape[0],1]):e);return Yt(t)}function Kn(r,t){let e=r.dtype,n=t.reduce((s,c)=>s*c,1),o=r.size,a=T(e);if(!a)throw new Error(`Cannot resize array with dtype ${e}`);let i=new a(n),u=w(e);for(let s=0;s<n;s++){let c=s%o,l=r.iget(c);i[s]=l}return S.fromData(i,t,e)}function ro(r){return r.map(t=>t.ndim===0?G(t,[1]):t)}function to(r){return r.map(t=>t.ndim===0?G(t,[1,1]):t.ndim===1?G(t,[1,t.shape[0]]):t)}function eo(r){return r.map(t=>t.ndim===0?G(t,[1,1,1]):t.ndim===1?G(t,[1,t.shape[0],1]):t.ndim===2?G(t,[t.shape[0],t.shape[1],1]):t)}var Jt=k(()=>{"use strict";R();W()});function Au(r,t,e,n,o,a,i,u,s,c,l,m,f,p){if(m===0)for(let h=0;h<n*o;h++)f[h]=0;else if(m!==1)for(let h=0;h<n*o;h++)f[h]=(f[h]??0)*m;let y=r==="row-major",d=t==="transpose",g=e==="transpose";if(y&&!d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[h*s+N]??0)*(c[N*l+A]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else if(y&&d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[N*s+h]??0)*(c[N*l+A]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else if(y&&!d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[h*s+N]??0)*(c[A*l+N]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else if(y&&d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[N*s+h]??0)*(c[A*l+N]??0);f[h*p+A]=(f[h*p+A]??0)+i*b}else if(!y&&!d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[N*s+h]??0)*(c[A*l+N]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else if(!y&&d&&!g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[h*s+N]??0)*(c[A*l+N]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else if(!y&&!d&&g)for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[N*s+h]??0)*(c[N*l+A]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}else for(let h=0;h<n;h++)for(let A=0;A<o;A++){let b=0;for(let N=0;N<a;N++)b+=(u[h*s+N]??0)*(c[N*l+A]??0);f[A*p+h]=(f[A*p+h]??0)+i*b}}function Qt(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=C(r.dtype,t.dtype),u=S.zeros([...t.shape],i);for(let s=0;s<t.size;s++){let c=t.data[s+t.offset];typeof o=="bigint"&&typeof c=="bigint"?u.data[s]=o*c:u.data[s]=Number(o)*Number(c)}return u}else{let i=C(r.dtype,t.dtype),u=S.zeros([...r.shape],i);for(let s=0;s<r.size;s++){let c=r.data[s+r.offset];typeof c=="bigint"&&typeof a=="bigint"?u.data[s]=c*a:u.data[s]=Number(c)*Number(a)}return u}}if(e===1&&n===1){if(r.shape[0]!==t.shape[0])throw new Error(`dot: incompatible shapes (${r.shape[0]},) and (${t.shape[0]},)`);let o=r.shape[0],a=0;for(let i=0;i<o;i++){let u=r.get(i),s=t.get(i);typeof u=="bigint"&&typeof s=="bigint"?a=Number(a)+Number(u*s):a+=Number(u)*Number(s)}return a}if(e===2&&n===2)return rr(r,t);if(e===2&&n===1){let[o,a]=r.shape,i=t.shape[0];if(a!==i)throw new Error(`dot: incompatible shapes (${o},${a}) and (${i},)`);let u=C(r.dtype,t.dtype),s=S.zeros([o],u);for(let c=0;c<o;c++){let l=0;for(let m=0;m<a;m++){let f=r.get(c,m),p=t.get(m);typeof f=="bigint"&&typeof p=="bigint"?l=Number(l)+Number(f*p):l+=Number(f)*Number(p)}s.set([c],l)}return s}if(e===1&&n===2){let o=r.shape[0],[a,i]=t.shape;if(o!==a)throw new Error(`dot: incompatible shapes (${o},) and (${a},${i})`);let u=C(r.dtype,t.dtype),s=S.zeros([i],u);for(let c=0;c<i;c++){let l=0;for(let m=0;m<o;m++){let f=r.get(m),p=t.get(m,c);typeof f=="bigint"&&typeof p=="bigint"?l=Number(l)+Number(f*p):l+=Number(f)*Number(p)}s.set([c],l)}return s}if(e>2&&n===1){let o=r.shape[e-1],a=t.shape[0];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and (${a},)`);let i=[...r.shape.slice(0,-1)],u=C(r.dtype,t.dtype),s=S.zeros(i,u),c=i.reduce((l,m)=>l*m,1);for(let l=0;l<c;l++){let m=0,f=l,p=[];for(let y=i.length-1;y>=0;y--)p[y]=f%i[y],f=Math.floor(f/i[y]);for(let y=0;y<o;y++){let d=[...p,y],g=r.get(...d),h=t.get(y);typeof g=="bigint"&&typeof h=="bigint"?m=Number(m)+Number(g*h):m+=Number(g)*Number(h)}s.set(p,m)}return s}if(e===1&&n>2){let o=r.shape[0],a=1,i=t.shape[a];if(o!==i)throw new Error(`dot: incompatible shapes (${o},) and ${JSON.stringify(t.shape)}`);let u=[...t.shape.slice(0,a),...t.shape.slice(a+1)],s=C(r.dtype,t.dtype),c=S.zeros(u,s),l=u.reduce((m,f)=>m*f,1);for(let m=0;m<l;m++){let f=m,p=[];for(let h=u.length-1;h>=0;h--)p[h]=f%u[h],f=Math.floor(f/u[h]);let y=p.slice(0,a),d=p.slice(a),g=0;for(let h=0;h<o;h++){let A=r.get(h),b=[...y,h,...d],N=t.get(...b);typeof A=="bigint"&&typeof N=="bigint"?g=Number(g)+Number(A*N):g+=Number(A)*Number(N)}c.set(p,g)}return c}if(e>=2&&n>=2&&!(e===2&&n===2)){let o=r.shape[e-1],a=t.shape[n-2];if(o!==a)throw new Error(`dot: incompatible shapes ${JSON.stringify(r.shape)} and ${JSON.stringify(t.shape)}`);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-2),t.shape[n-1]],u=C(r.dtype,t.dtype),s=S.zeros(i,u),c=r.shape.slice(0,-1).reduce((p,y)=>p*y,1),l=t.shape.slice(0,-2).reduce((p,y)=>p*y,1),m=t.shape[n-1],f=o;for(let p=0;p<c;p++)for(let y=0;y<l;y++)for(let d=0;d<m;d++){let g=0;for(let A=0;A<f;A++){let b=p*f+A,N=r.data[b+r.offset],D=y*f*m+A*m+d,x=t.data[D+t.offset];typeof N=="bigint"&&typeof x=="bigint"?g=Number(g)+Number(N*x):g+=Number(N)*Number(x)}let h=p*l*m+y*m+d;s.data[h]=g}return s}throw new Error(`dot: unexpected combination of dimensions ${e}D \xB7 ${n}D`)}function rr(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=C(r.dtype,t.dtype),u=i.startsWith("int")||i.startsWith("uint")||i==="bool"?"float64":i;if(u!=="float64")throw new Error(`matmul currently only supports float64, got ${u}`);let s=r.dtype==="float64"?r.data:Float64Array.from(Array.from(r.data).map(Number)),c=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number));r.offset>0&&(s=s.subarray(r.offset)),t.offset>0&&(c=c.subarray(t.offset));let[l=0,m=0]=r.strides,[f=0,p=0]=t.strides,y=m>l,d=p>f,g=y?"transpose":"no-transpose",h=d?"transpose":"no-transpose",A,b;y?A=m:A=l,d?b=p:b=f;let N=S.zeros([e,a],"float64");return Au("row-major",g,h,e,a,n,1,s,A,c,b,0,N.data,a),N}function so(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 oo(r,t){return Er(r,t)}function io(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 Qt(r,t);let i=[...r.shape.slice(0,-1),...t.shape.slice(0,-1)],u=C(r.dtype,t.dtype),s=S.zeros(i,u),c=e===1?1:r.shape.slice(0,-1).reduce((f,p)=>f*p,1),l=n===1?1:t.shape.slice(0,-1).reduce((f,p)=>f*p,1),m=o;for(let f=0;f<c;f++)for(let p=0;p<l;p++){let y=0;for(let g=0;g<m;g++){let h=e===1?g:f*m+g,A=n===1?g:p*m+g,b=r.data[h+r.offset],N=t.data[A+t.offset];typeof b=="bigint"&&typeof N=="bigint"?y=Number(y)+Number(b*N):y+=Number(b)*Number(N)}if(i.length===0)return y;let d=c===1?p:f*l+p;s.data[d]=y}return s}function Kt(r,t){let e=r.ndim===1?r:hr(r),n=t.ndim===1?t:hr(t),o=e.size,a=n.size,i=C(r.dtype,t.dtype),u=S.zeros([o,a],i);for(let s=0;s<o;s++)for(let c=0;c<a;c++){let l=e.get(s),m=n.get(c),f;typeof l=="bigint"&&typeof m=="bigint"?f=l*m:f=Number(l)*Number(m),u.set([s,c],f)}return u}function uo(r,t,e){let n,o;if(typeof e=="number"){let f=e;if(f<0)throw new Error("tensordot: axes must be non-negative");if(f>r.ndim||f>t.ndim)throw new Error("tensordot: axes exceeds array dimensions");n=Array.from({length:f},(p,y)=>r.ndim-f+y),o=Array.from({length:f},(p,y)=>y)}else if([n,o]=e,n.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let f=0;f<n.length;f++){let p=n[f],y=o[f];if(p<0||p>=r.ndim||y<0||y>=t.ndim)throw new Error("tensordot: axis out of bounds");if(r.shape[p]!==t.shape[y])throw new Error(`tensordot: shape mismatch on axes ${p} and ${y}: ${r.shape[p]} != ${t.shape[y]}`)}let a=[],i=[];for(let f=0;f<r.ndim;f++)n.includes(f)||a.push(f);for(let f=0;f<t.ndim;f++)o.includes(f)||i.push(f);let u=[...a.map(f=>r.shape[f]),...i.map(f=>t.shape[f])];if(u.length===0){let f=0,p=n.map(y=>r.shape[y]).reduce((y,d)=>y*d,1);for(let y=0;y<p;y++){let d=y,g=new Array(n.length);for(let D=n.length-1;D>=0;D--){let x=n[D];g[D]=d%r.shape[x],d=Math.floor(d/r.shape[x])}let h=new Array(r.ndim),A=new Array(t.ndim);for(let D=0;D<n.length;D++)h[n[D]]=g[D];for(let D=0;D<o.length;D++)A[o[D]]=g[D];let b=r.get(...h),N=t.get(...A);typeof b=="bigint"&&typeof N=="bigint"?f=Number(f)+Number(b*N):f+=Number(b)*Number(N)}return f}let s=C(r.dtype,t.dtype),c=S.zeros(u,s),l=u.reduce((f,p)=>f*p,1),m=n.map(f=>r.shape[f]).reduce((f,p)=>f*p,1);for(let f=0;f<l;f++){let p=f,y=[];for(let A=u.length-1;A>=0;A--)y[A]=p%u[A],p=Math.floor(p/u[A]);let d=y.slice(0,a.length),g=y.slice(a.length),h=0;for(let A=0;A<m;A++){p=A;let b=[];for(let _=n.length-1;_>=0;_--){let B=n[_];b[_]=p%r.shape[B],p=Math.floor(p/r.shape[B])}let N=new Array(r.ndim),D=new Array(t.ndim);for(let _=0;_<a.length;_++)N[a[_]]=d[_];for(let _=0;_<i.length;_++)D[i[_]]=g[_];for(let _=0;_<n.length;_++)N[n[_]]=b[_],D[o[_]]=b[_];let x=r.get(...N),z=t.get(...D);typeof x=="bigint"&&typeof z=="bigint"?h=Number(h)+Number(x*z):h+=Number(x)*Number(z)}c.set(y,h)}return c}function co(r,t=0,e=0,n=1){let o=r.shape,a=o.length;if(a<2)throw new Error("diagonal requires an array of at least two dimensions");let i=e<0?a+e:e,u=n<0?a+n:n;if(i<0||i>=a||u<0||u>=a)throw new Error("axis out of bounds");if(i===u)throw new Error("axis1 and axis2 cannot be the same");let s=o[i],c=o[u],l;t>=0?l=Math.max(0,Math.min(s,c-t)):l=Math.max(0,Math.min(s+t,c));let m=[];for(let d=0;d<a;d++)d!==i&&d!==u&&m.push(o[d]);m.push(l);let f=S.zeros(m,r.dtype),p=o.filter((d,g)=>g!==i&&g!==u),y=p.reduce((d,g)=>d*g,1);for(let d=0;d<y;d++){let g=d,h=[];for(let A=p.length-1;A>=0;A--)h.unshift(g%p[A]),g=Math.floor(g/p[A]);for(let A=0;A<l;A++){let b=new Array(a),N=0;for(let z=0;z<a;z++)z===i?b[z]=t>=0?A:A-t:z===u?b[z]=t>=0?A+t:A:b[z]=h[N++];let D=[...h,A],x=r.get(...b);f.set(D,x)}}return f}function lo(r,...t){let e=r.indexOf("->"),n,o;e===-1?(n=r,o=hu(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],h=t[d];if(g.length!==h.ndim)throw new Error(`einsum: operand ${d} has ${h.ndim} dimensions but subscript '${g}' has ${g.length} indices`);for(let A=0;A<g.length;A++){let b=g[A],N=h.shape[A];if(i.has(b)){if(i.get(b)!==N)throw new Error(`einsum: size mismatch for index '${b}': ${i.get(b)} vs ${N}`)}else i.set(b,N)}}for(let d of o)if(!i.has(d))throw new Error(`einsum: output subscript contains unknown index '${d}'`);let u=new Set(o),s=new Set;for(let d of a)for(let g of d)s.add(g);let c=[];for(let d of s)u.has(d)||c.push(d);if(t.length===2&&a.length===2){let[d,g]=a,[h,A]=t;if(d.length===2&&g.length===2&&o.length===2&&h.ndim===2&&A.ndim===2){let[b,N]=[d[0],d[1]],[D,x]=[g[0],g[1]],[z,_]=[o[0],o[1]];if(b===z&&x===_&&N===D&&c.length===1&&c[0]===N||b===z&&x===_&&N===D&&c.length===1&&c[0]===N)return rr(h,A);if(N===z&&x===_&&b===D&&c.length===1&&c[0]===b){let B=oo(h);return rr(B,A)}if(b===z&&D===_&&N===x&&c.length===1&&c[0]===N){let B=oo(A);return rr(h,B)}}if(d.length===1&&g.length===1&&d===g&&o.length===0&&h.ndim===1&&A.ndim===1)return Xt(t,a,c,i);if(d&&g&&d.length===1&&g.length===1&&o.length===2&&o===d+g&&c.length===0&&h.ndim===1&&A.ndim===1)return Kt(h,A)}if(t.length===1&&a[0].length===2&&o.length===0){let d=a[0];if(d[0]===d[1]&&t[0].ndim===2)return Xt(t,a,c,i)}let l=Array.from(o).map(d=>i.get(d));if(l.length===0)return Xt(t,a,c,i);let m=t[0].dtype;for(let d=1;d<t.length;d++)m=C(m,t[d].dtype);let f=S.zeros(l,m),p=l.reduce((d,g)=>d*g,1),y=1;for(let d of c)y*=i.get(d);for(let d=0;d<p;d++){let g=Su(d,l),h=new Map;for(let b=0;b<o.length;b++)h.set(o[b],g[b]);let A=0;for(let b=0;b<y;b++){let N=b;for(let x=c.length-1;x>=0;x--){let z=c[x],_=i.get(z);h.set(z,N%_),N=Math.floor(N/_)}let D=1;for(let x=0;x<t.length;x++){let z=t[x],_=a[x],B=[];for(let E of _)B.push(h.get(E));let v=z.get(...B);D*=Number(v)}A+=D}f.set(g,A)}return f}function hu(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 Xt(r,t,e,n){let o=1;for(let i of e)o*=n.get(i);let a=0;for(let i=0;i<o;i++){let u=new Map,s=i;for(let l=e.length-1;l>=0;l--){let m=e[l],f=n.get(m);u.set(m,s%f),s=Math.floor(s/f)}let c=1;for(let l=0;l<r.length;l++){let m=r[l],f=t[l],p=[];for(let d of f)p.push(u.get(d));let y=m.get(...p);c*=Number(y)}a+=c}return a}function Su(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 fo(r,t){let e=r.shape,n=t.shape,o=e.length,a=n.length,i=C(r.dtype,t.dtype),u=Math.max(o,a),s=new Array(u),c=new Array(u).fill(1),l=new Array(u).fill(1);for(let y=0;y<o;y++)c[u-o+y]=e[y];for(let y=0;y<a;y++)l[u-a+y]=n[y];for(let y=0;y<u;y++)s[y]=c[y]*l[y];let m=S.zeros(s,i),f=e.reduce((y,d)=>y*d,1),p=n.reduce((y,d)=>y*d,1);for(let y=0;y<f;y++){let d=y,g=new Array(o);for(let b=o-1;b>=0;b--)g[b]=d%e[b],d=Math.floor(d/e[b]);let h=new Array(u).fill(0);for(let b=0;b<o;b++)h[u-o+b]=g[b];let A=r.get(...g);for(let b=0;b<p;b++){let N=b,D=new Array(a);for(let v=a-1;v>=0;v--)D[v]=N%n[v],N=Math.floor(N/n[v]);let x=new Array(u).fill(0);for(let v=0;v<a;v++)x[u-a+v]=D[v];let z=t.get(...D),_=new Array(u);for(let v=0;v<u;v++)_[v]=h[v]*l[v]+x[v];let B=typeof A=="bigint"||typeof z=="bigint"?BigInt(Number(A))*BigInt(Number(z)):Number(A)*Number(z);m.set(_,B)}}return m}function mo(r,t,e=-1,n=-1,o=-1,a){a!==void 0&&(e=a,n=a,o=a);let i=(b,N)=>b<0?N+b:b,u=i(e,r.ndim),s=i(n,t.ndim);if(r.ndim===1&&t.ndim===1){let b=r.shape[0],N=t.shape[0];if(b===3&&N===3){let D=Number(r.get(0)),x=Number(r.get(1)),z=Number(r.get(2)),_=Number(t.get(0)),B=Number(t.get(1)),v=Number(t.get(2)),E=S.zeros([3],"float64");return E.set([0],x*v-z*B),E.set([1],z*_-D*v),E.set([2],D*B-x*_),E}else if(b===2&&N===2){let D=Number(r.get(0)),x=Number(r.get(1)),z=Number(t.get(0)),_=Number(t.get(1));return D*_-x*z}else if(b===2&&N===3||b===3&&N===2){let D=Number(r.get(0)),x=Number(r.get(1)),z=b===3?Number(r.get(2)):0,_=Number(t.get(0)),B=Number(t.get(1)),v=N===3?Number(t.get(2)):0,E=S.zeros([3],"float64");return E.set([0],x*v-z*B),E.set([1],z*_-D*v),E.set([2],D*B-x*_),E}else throw new Error(`cross: incompatible dimensions for cross product: ${b} and ${N}`)}let c=r.shape[u],l=t.shape[s];if(c!==2&&c!==3||l!==2&&l!==3)throw new Error(`cross: incompatible dimensions for cross product: ${c} and ${l}`);let m=c===2&&l===2?0:3,f=[...r.shape.slice(0,u),...r.shape.slice(u+1)],p=[...t.shape.slice(0,s),...t.shape.slice(s+1)];if(f.length!==p.length)throw new Error("cross: incompatible shapes for cross product");for(let b=0;b<f.length;b++)if(f[b]!==p[b])throw new Error("cross: incompatible shapes for cross product");let y=f,d=o<0?y.length+1+o:o,g;if(m===0?g=y:g=[...y.slice(0,d),m,...y.slice(d)],g.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");let h=S.zeros(g,"float64"),A=y.reduce((b,N)=>b*N,1);for(let b=0;b<A;b++){let N=b,D=[];for(let Z=y.length-1;Z>=0;Z--)D[Z]=N%y[Z],N=Math.floor(N/y[Z]);let x=[...D.slice(0,u),0,...D.slice(u)],z=[...D.slice(0,s),0,...D.slice(s)],_=Z=>(x[u]=Z,Number(r.get(...x))),B=Z=>(z[s]=Z,Number(t.get(...z))),v=_(0),E=_(1),U=c===3?_(2):0,$=B(0),q=B(1),J=l===3?B(2):0;if(m===0)h.set(D,v*q-E*$);else{let Z=E*J-U*q,Ir=U*$-v*J,ji=v*q-E*$,_t=(Ri,Li)=>{let Wi=[...D.slice(0,d),Ri,...D.slice(d)];h.set(Wi,Li)};_t(0,Z),_t(1,Ir),_t(2,ji)}}return h}function Sr(r,t=2,e,n=!1){if(typeof t!="number")throw new Error("vector_norm: ord must be a number");if(e==null){let c=r.ndim===1?r:hr(r),l=c.size,m;if(t===1/0){m=0;for(let f=0;f<l;f++)m=Math.max(m,Math.abs(Number(c.get(f))))}else if(t===-1/0){m=1/0;for(let f=0;f<l;f++)m=Math.min(m,Math.abs(Number(c.get(f))))}else if(t===0){m=0;for(let f=0;f<l;f++)Number(c.get(f))!==0&&m++}else if(t===1){m=0;for(let f=0;f<l;f++)m+=Math.abs(Number(c.get(f)))}else if(t===2){m=0;for(let f=0;f<l;f++){let p=Number(c.get(f));m+=p*p}m=Math.sqrt(m)}else{m=0;for(let f=0;f<l;f++)m+=Math.pow(Math.abs(Number(c.get(f))),t);m=Math.pow(m,1/t)}if(n){let f=new Array(r.ndim).fill(1),p=S.zeros(f,"float64");return p.set(new Array(r.ndim).fill(0),m),p}return m}let o=e<0?r.ndim+e:e;if(o<0||o>=r.ndim)throw new Error(`vector_norm: axis ${e} out of bounds for array with ${r.ndim} dimensions`);let a=n?[...r.shape.slice(0,o),1,...r.shape.slice(o+1)]:[...r.shape.slice(0,o),...r.shape.slice(o+1)];if(a.length===0)return Sr(r,t,null,!1);let i=S.zeros(a,"float64"),u=r.shape[o],s=a.reduce((c,l)=>c*l,1);for(let c=0;c<s;c++){let l=c,m=[];for(let y=a.length-1;y>=0;y--)m[y]=l%a[y],l=Math.floor(l/a[y]);let f=n?[...m.slice(0,o),0,...m.slice(o+1)]:[...m.slice(0,o),0,...m.slice(o)],p;if(t===1/0){p=0;for(let y=0;y<u;y++)f[o]=y,p=Math.max(p,Math.abs(Number(r.get(...f))))}else if(t===-1/0){p=1/0;for(let y=0;y<u;y++)f[o]=y,p=Math.min(p,Math.abs(Number(r.get(...f))))}else if(t===0){p=0;for(let y=0;y<u;y++)f[o]=y,Number(r.get(...f))!==0&&p++}else if(t===1){p=0;for(let y=0;y<u;y++)f[o]=y,p+=Math.abs(Number(r.get(...f)))}else if(t===2){p=0;for(let y=0;y<u;y++){f[o]=y;let d=Number(r.get(...f));p+=d*d}p=Math.sqrt(p)}else{p=0;for(let y=0;y<u;y++)f[o]=y,p+=Math.pow(Math.abs(Number(r.get(...f))),t);p=Math.pow(p,1/t)}i.set(m,p)}return i}function yr(r,t="fro",e=!1){if(r.ndim!==2)throw new Error(`matrix_norm: input must be 2D, got ${r.ndim}D`);let[n,o]=r.shape,a;if(t==="fro"){a=0;for(let i=0;i<n;i++)for(let u=0;u<o;u++){let s=Number(r.get(i,u));a+=s*s}a=Math.sqrt(a)}else if(t==="nuc"){let{s:i}=fr(r);a=0;for(let u=0;u<i.size;u++)a+=Number(i.get(u))}else if(t===1){a=0;for(let i=0;i<o;i++){let u=0;for(let s=0;s<n;s++)u+=Math.abs(Number(r.get(s,i)));a=Math.max(a,u)}}else if(t===-1){a=1/0;for(let i=0;i<o;i++){let u=0;for(let s=0;s<n;s++)u+=Math.abs(Number(r.get(s,i)));a=Math.min(a,u)}}else if(t===1/0){a=0;for(let i=0;i<n;i++){let u=0;for(let s=0;s<o;s++)u+=Math.abs(Number(r.get(i,s)));a=Math.max(a,u)}}else if(t===-1/0){a=1/0;for(let i=0;i<n;i++){let u=0;for(let s=0;s<o;s++)u+=Math.abs(Number(r.get(i,s)));a=Math.min(a,u)}}else if(t===2){let{s:i}=fr(r);a=Number(i.get(0))}else if(t===-2){let{s:i}=fr(r);a=Number(i.get(i.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${t}`);if(e){let i=S.zeros([1,1],"float64");return i.set([0,0],a),i}return a}function po(r,t=null,e=null,n=!1){if(t===null)return e===null?Sr(r,2,null,n):typeof e=="number"?Sr(r,2,e,n):yr(r,"fro",n);if(Array.isArray(e)){if(e.length!==2)throw new Error("norm: axis must be a 2-tuple for matrix norms");let o=e[0]<0?r.ndim+e[0]:e[0],a=e[1]<0?r.ndim+e[1]:e[1];if(r.ndim!==2||o!==0&&o!==1||a!==0&&a!==1||o===a)throw new Error("norm: complex axis specification not yet supported");return yr(r,t,n)}if(r.ndim===2&&e===null&&(t==="fro"||t==="nuc"))return yr(r,t,n);if(typeof t!="number"&&t!==null)throw new Error(`norm: ord '${t}' not valid for vector norm`);return Sr(r,t??2,e,n)}function re(r,t="reduced"){if(r.ndim!==2)throw new Error(`qr: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape,o=Math.min(e,n),a=S.zeros([e,n],"float64");for(let p=0;p<e;p++)for(let y=0;y<n;y++)a.set([p,y],Number(r.get(p,y)));let i=[],u=[];for(let p=0;p<o;p++){let y=e-p,d=[];for(let D=p;D<e;D++)d.push(Number(a.get(D,p)));let g=0;for(let D=0;D<y;D++)g+=d[D]*d[D];if(g=Math.sqrt(g),g<1e-15){i.push(d),u.push(0);continue}let h=d[0]>=0?1:-1,A=d[0]+h*g,b=[1];for(let D=1;D<y;D++)b.push(d[D]/A);let N=h*A/g;u.push(N),i.push(b);for(let D=p;D<n;D++){let x=0;for(let z=0;z<y;z++)x+=b[z]*Number(a.get(p+z,D));for(let z=0;z<y;z++)a.set([p+z,D],Number(a.get(p+z,D))-N*b[z]*x)}}if(t==="raw"){let p=S.zeros([e,n],"float64");for(let d=0;d<e;d++)for(let g=0;g<n;g++)p.set([d,g],Number(a.get(d,g)));let y=S.zeros([o],"float64");for(let d=0;d<o;d++)y.set([d],u[d]);return{h:p,tau:y}}if(t==="r"){let p=S.zeros([o,n],"float64");for(let y=0;y<o;y++)for(let d=y;d<n;d++)p.set([y,d],Number(a.get(y,d)));return p}let s=t==="complete"?e:o,c=S.zeros([e,s],"float64");for(let p=0;p<Math.min(e,s);p++)c.set([p,p],1);for(let p=o-1;p>=0;p--){let y=i[p],d=u[p],g=e-p;for(let h=p;h<s;h++){let A=0;for(let b=0;b<g;b++)A+=y[b]*Number(c.get(p+b,h));for(let b=0;b<g;b++)c.set([p+b,h],Number(c.get(p+b,h))-d*y[b]*A)}}let l=S.zeros([e,s],"float64");for(let p=0;p<e;p++)for(let y=0;y<s;y++)l.set([p,y],Number(c.get(p,y)));let m=t==="complete"?e:o,f=S.zeros([m,n],"float64");for(let p=0;p<m;p++)for(let y=0;y<n;y++)y>=p&&f.set([p,y],Number(a.get(p,y)));return{q:l,r:f}}function yo(r,t=!1){if(r.ndim!==2)throw new Error(`cholesky: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`cholesky: matrix must be square, got ${e}x${n}`);let o=e,a=S.zeros([o,o],"float64");for(let i=0;i<o;i++)for(let u=0;u<=i;u++){let s=0;if(i===u){for(let l=0;l<u;l++)s+=Number(a.get(u,l))**2;let c=Number(r.get(u,u))-s;if(c<0)throw new Error("cholesky: matrix is not positive definite");a.set([u,u],Math.sqrt(c))}else{for(let l=0;l<u;l++)s+=Number(a.get(i,l))*Number(a.get(u,l));let c=Number(a.get(u,u));if(Math.abs(c)<1e-15)throw new Error("cholesky: matrix is not positive definite");a.set([i,u],(Number(r.get(i,u))-s)/c)}}if(t){let i=S.zeros([o,o],"float64");for(let u=0;u<o;u++)for(let s=u;s<o;s++)i.set([u,s],Number(a.get(s,u)));return i}return a}function fr(r){if(r.ndim!==2)throw new Error(`svd: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape,n=Math.min(t,e),o=S.zeros([e,e],"float64");for(let m=0;m<e;m++)for(let f=0;f<e;f++){let p=0;for(let y=0;y<t;y++)p+=Number(r.get(y,m))*Number(r.get(y,f));o.set([m,f],p)}let{values:a,vectors:i}=te(o),u=Array.from({length:e},(m,f)=>f);u.sort((m,f)=>a[f]-a[m]);let s=S.zeros([n],"float64");for(let m=0;m<n;m++){let f=a[u[m]];s.set([m],Math.sqrt(Math.max(0,f)))}let c=S.zeros([e,e],"float64");for(let m=0;m<e;m++)for(let f=0;f<e;f++)c.set([m,f],i[f][u[m]]);let l=S.zeros([t,t],"float64");for(let m=0;m<t;m++)for(let f=0;f<n;f++){let p=Number(s.get(f));if(p>1e-10){let y=0;for(let d=0;d<e;d++)y+=Number(r.get(m,d))*Number(c.get(f,d));l.set([m,f],y/p)}}if(t>n)for(let m=n;m<t;m++){let f=new Array(t).fill(0);f[m]=1;for(let y=0;y<m;y++){let d=0;for(let g=0;g<t;g++)d+=f[g]*Number(l.get(g,y));for(let g=0;g<t;g++)f[g]=f[g]-d*Number(l.get(g,y))}let p=0;for(let y=0;y<t;y++)p+=f[y]*f[y];if(p=Math.sqrt(p),p>1e-10)for(let y=0;y<t;y++)l.set([y,m],f[y]/p)}return{u:l,s,vt:c}}function te(r){let t=r.shape[0],e=100*t*t,n=1e-10,o=[];for(let u=0;u<t;u++){o.push([]);for(let s=0;s<t;s++)o[u].push(Number(r.get(u,s)))}let a=[];for(let u=0;u<t;u++){a.push([]);for(let s=0;s<t;s++)a[u].push(u===s?1:0)}for(let u=0;u<e;u++){let s=0,c=0,l=1;for(let b=0;b<t;b++)for(let N=b+1;N<t;N++)Math.abs(o[b][N])>s&&(s=Math.abs(o[b][N]),c=b,l=N);if(s<n)break;let m=o[c][c],f=o[l][l],p=o[c][l],y;Math.abs(m-f)<1e-15?y=Math.PI/4:y=.5*Math.atan2(2*p,f-m);let d=Math.cos(y),g=Math.sin(y),h=d*d*m+g*g*f-2*g*d*p,A=g*g*m+d*d*f+2*g*d*p;o[c][c]=h,o[l][l]=A,o[c][l]=0,o[l][c]=0;for(let b=0;b<t;b++)if(b!==c&&b!==l){let N=o[b][c],D=o[b][l];o[b][c]=d*N-g*D,o[c][b]=o[b][c],o[b][l]=g*N+d*D,o[l][b]=o[b][l]}for(let b=0;b<t;b++){let N=a[b][c],D=a[b][l];a[b][c]=d*N-g*D,a[b][l]=g*N+d*D}}let i=[];for(let u=0;u<t;u++)i.push(o[u][u]);return{values:i,vectors:a}}function go(r,t=!0,e=!0){let n=fr(r);if(!e)return n.s;if(!t){let[o,a]=r.shape,i=Math.min(o,a),u=S.zeros([o,i],"float64");for(let c=0;c<o;c++)for(let l=0;l<i;l++)u.set([c,l],Number(n.u.get(c,l)));let s=S.zeros([i,a],"float64");for(let c=0;c<i;c++)for(let l=0;l<a;l++)s.set([c,l],Number(n.vt.get(c,l)));return{u,s:n.s,vt:s}}return n}function bo(r){if(r.ndim!==2)throw new Error(`det: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`det: matrix must be square, got ${t}x${e}`);let n=t;if(n===0)return 1;let o=r.data;if(n===1)return Number(o[0]);if(n===2)return Number(o[0])*Number(o[3])-Number(o[1])*Number(o[2]);let{lu:a,sign:i}=ee(r),u=a.data,s=i;for(let c=0;c<n;c++)s*=u[c*n+c];return s}function ee(r){let[t,e]=r.shape,n=t,o=e,a=S.zeros([n,o],"float64"),i=a.data,u=r.data;for(let l=0;l<n*o;l++)i[l]=Number(u[l]);let s=Array.from({length:n},(l,m)=>m),c=1;for(let l=0;l<Math.min(n,o);l++){let m=Math.abs(i[l*o+l]),f=l;for(let y=l+1;y<n;y++){let d=Math.abs(i[y*o+l]);d>m&&(m=d,f=y)}if(f!==l){for(let d=0;d<o;d++){let g=i[l*o+d];i[l*o+d]=i[f*o+d],i[f*o+d]=g}let y=s[l];s[l]=s[f],s[f]=y,c=-c}let p=i[l*o+l];if(Math.abs(p)>1e-15)for(let y=l+1;y<n;y++){let d=i[y*o+l]/p;i[y*o+l]=d;for(let g=l+1;g<o;g++)i[y*o+g]=i[y*o+g]-d*i[l*o+g]}}return{lu:a,piv:s,sign:c}}function ft(r){if(r.ndim!==2)throw new Error(`inv: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`inv: matrix must be square, got ${t}x${e}`);let n=t,{lu:o,piv:a}=ee(r),i=o.data,u=S.zeros([n,n],"float64"),s=u.data;for(let c=0;c<n;c++){let l=new Float64Array(n);for(let m=0;m<n;m++){let f=a[m]===c?1:0;for(let p=0;p<m;p++)f-=i[m*n+p]*l[p];l[m]=f}for(let m=n-1;m>=0;m--){let f=l[m];for(let y=m+1;y<n;y++)f-=i[m*n+y]*s[y*n+c];let p=i[m*n+m];if(Math.abs(p)<1e-15)throw new Error("inv: singular matrix");s[m*n+c]=f/p}}return u}function ao(r,t){let[e]=r.shape,n=e,{lu:o,piv:a}=ee(r),i=o.data,u=t.data,s=new Float64Array(n);for(let f=0;f<n;f++)s[f]=Number(u[a[f]]);let c=new Float64Array(n);for(let f=0;f<n;f++){let p=s[f];for(let y=0;y<f;y++)p-=i[f*n+y]*c[y];c[f]=p}let l=S.zeros([n],"float64"),m=l.data;for(let f=n-1;f>=0;f--){let p=c[f];for(let d=f+1;d<n;d++)p-=i[f*n+d]*m[d];let y=i[f*n+f];if(Math.abs(y)<1e-15)throw new Error("solve: singular matrix");m[f]=p/y}return l}function Ao(r,t){if(r.ndim!==2)throw new Error(`solve: coefficient matrix must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`solve: coefficient matrix must be square, got ${e}x${n}`);let o=e;if(t.ndim===1){if(t.shape[0]!==o)throw new Error(`solve: incompatible shapes (${e},${n}) and (${t.shape[0]},)`);return ao(r,t)}if(t.ndim===2){if(t.shape[0]!==o)throw new Error(`solve: incompatible shapes (${e},${n}) and (${t.shape[0]},${t.shape[1]})`);let a=t.shape[1],i=S.zeros([o,a],"float64");for(let u=0;u<a;u++){let s=S.zeros([o],"float64");for(let l=0;l<o;l++)s.set([l],Number(t.get(l,u)));let c=ao(r,s);for(let l=0;l<o;l++)i.set([l,u],Number(c.get(l)))}return i}throw new Error(`solve: b must be 1D or 2D, got ${t.ndim}D`)}function ho(r,t,e=null){if(r.ndim!==2)throw new Error(`lstsq: coefficient matrix must be 2D, got ${r.ndim}D`);let[n,o]=r.shape,{u:a,s:i,vt:u}=fr(r),s=Math.min(n,o),c=e??Math.max(n,o)*Number.EPSILON,m=Number(i.get(0))*c,f=0;for(let A=0;A<s;A++)Number(i.get(A))>m&&f++;let p=t.ndim===1?G(t,[t.size,1]):t,y=p.shape[1];if(p.shape[0]!==n)throw new Error(`lstsq: incompatible shapes (${n},${o}) and (${t.shape.join(",")})`);let d=S.zeros([o,y],"float64");for(let A=0;A<y;A++){let b=new Array(n).fill(0);for(let N=0;N<n;N++)for(let D=0;D<n;D++)b[N]+=Number(a.get(D,N))*Number(p.get(D,A));for(let N=0;N<o;N++){let D=0;for(let x=0;x<s;x++){let z=Number(i.get(x));z>m&&(D+=Number(u.get(x,N))*b[x]/z)}d.set([N,A],D)}}let g;if(n>o){g=S.zeros([y],"float64");for(let A=0;A<y;A++){let b=0;for(let N=0;N<n;N++){let D=0;for(let z=0;z<o;z++)D+=Number(r.get(N,z))*Number(d.get(z,A));let x=D-Number(p.get(N,A));b+=x*x}g.set([A],b)}}else g=S.zeros([0],"float64");return{x:t.ndim===1?G(d,[o]):d,residuals:g,rank:f,s:i}}function So(r,t=2){if(r.ndim!==2)throw new Error(`cond: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(t===2||t===-2){let{s:u}=fr(r),s=Math.min(e,n),c=Number(u.get(0)),l=Number(u.get(s-1));return t===2?l>0?c/l:1/0:c>0?l/c:0}if(e!==n)throw new Error(`cond: matrix must be square for p=${t}`);let o=yr(r,t),a=ft(r),i=yr(a,t);return o*i}function No(r,t){if(r.ndim===0)return Number(r.get())!==0?1:0;if(r.ndim===1){for(let i=0;i<r.size;i++)if(Number(r.get(i))!==0)return 1;return 0}if(r.ndim!==2)throw new Error(`matrix_rank: input must be at most 2D, got ${r.ndim}D`);let{s:e}=fr(r),n=Number(e.get(0)),o=t??n*Math.max(r.shape[0],r.shape[1])*Number.EPSILON,a=0;for(let i=0;i<e.size;i++)Number(e.get(i))>o&&a++;return a}function Do(r,t){if(r.ndim!==2)throw new Error(`matrix_power: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`matrix_power: matrix must be square, got ${e}x${n}`);let o=e;if(!Number.isInteger(t))throw new Error("matrix_power: exponent must be an integer");if(t===0){let c=S.zeros([o,o],"float64");for(let l=0;l<o;l++)c.set([l,l],1);return c}let a=r,i=t;t<0&&(a=ft(r),i=-t);let u=S.zeros([o,o],"float64");for(let c=0;c<o;c++)u.set([c,c],1);let s=S.zeros([o,o],"float64");for(let c=0;c<o;c++)for(let l=0;l<o;l++)s.set([c,l],Number(a.get(c,l)));for(;i>0;)i&1&&(u=rr(u,s)),s=rr(s,s),i>>=1;return u}function xo(r,t=1e-15){if(r.ndim!==2)throw new Error(`pinv: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape,{u:o,s:a,vt:i}=fr(r),u=Math.min(e,n),c=Number(a.get(0))*t,l=S.zeros([n,e],"float64");for(let m=0;m<n;m++)for(let f=0;f<e;f++){let p=0;for(let y=0;y<u;y++){let d=Number(a.get(y));d>c&&(p+=Number(i.get(y,m))*Number(o.get(f,y))/d)}l.set([m,f],p)}return l}function ne(r){if(r.ndim!==2)throw new Error(`eig: input must be 2D, got ${r.ndim}D`);let[t,e]=r.shape;if(t!==e)throw new Error(`eig: matrix must be square, got ${t}x${e}`);let n=t,o=!0;r:for(let c=0;c<n;c++)for(let l=c+1;l<n;l++)if(Math.abs(Number(r.get(c,l))-Number(r.get(l,c)))>1e-10){o=!1;break r}if(o){let{values:c,vectors:l}=te(r),m=S.zeros([n],"float64"),f=S.zeros([n,n],"float64");for(let p=0;p<n;p++){m.set([p],c[p]);for(let y=0;y<n;y++)f.set([y,p],l[y][p])}return{w:m,v:f}}console.warn("numpy-ts: eig() called on non-symmetric matrix. Complex eigenvalues are not supported; results may be inaccurate. For symmetric matrices, use eigh() instead.");let{values:a,vectors:i}=Nu(r),u=S.zeros([n],"float64"),s=S.zeros([n,n],"float64");for(let c=0;c<n;c++){u.set([c],a[c]);for(let l=0;l<n;l++)s.set([l,c],i[l][c])}return{w:u,v:s}}function Nu(r){let t=r.shape[0],e=1e3,n=1e-10,o=S.zeros([t,t],"float64");for(let s=0;s<t;s++)for(let c=0;c<t;c++)o.set([s,c],Number(r.get(s,c)));let a=S.zeros([t,t],"float64");for(let s=0;s<t;s++)a.set([s,s],1);for(let s=0;s<e;s++){let c=0;for(let p=0;p<t;p++)for(let y=0;y<t;y++)p!==y&&(c+=Number(o.get(p,y))**2);if(Math.sqrt(c)<n*t)break;let l=re(o,"reduced"),m=l.q,f=l.r;o=rr(f,m),a=rr(a,m)}let i=[];for(let s=0;s<t;s++)i.push(Number(o.get(s,s)));let u=[];for(let s=0;s<t;s++){u.push([]);for(let c=0;c<t;c++)u[s].push(Number(a.get(s,c)))}return{values:i,vectors:u}}function oe(r,t="L"){if(r.ndim!==2)throw new Error(`eigh: input must be 2D, got ${r.ndim}D`);let[e,n]=r.shape;if(e!==n)throw new Error(`eigh: matrix must be square, got ${e}x${n}`);let o=e,a=S.zeros([o,o],"float64");for(let m=0;m<o;m++)for(let f=0;f<o;f++)t==="L"?m>=f&&(a.set([m,f],Number(r.get(m,f))),a.set([f,m],Number(r.get(m,f)))):f>=m&&(a.set([m,f],Number(r.get(m,f))),a.set([f,m],Number(r.get(m,f))));let{values:i,vectors:u}=te(a),s=Array.from({length:o},(m,f)=>f);s.sort((m,f)=>i[m]-i[f]);let c=S.zeros([o],"float64"),l=S.zeros([o,o],"float64");for(let m=0;m<o;m++){c.set([m],i[s[m]]);for(let f=0;f<o;f++)l.set([f,m],u[f][s[m]])}return{w:c,v:l}}function wo(r){let{w:t}=ne(r);return t}function zo(r,t="L"){let{w:e}=oe(r,t);return e}var Io=k(()=>{"use strict";R();W();Jt()});function _o(r){return V(r,Math.sqrt,!1)}function Bo(r,t){return typeof t=="number"?xu(r,t):P(r,t,Math.pow,"power")}function xu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,s=e!=="float32"&&e!=="float64"&&(t<0||!Number.isInteger(t))?"float64":e,c=S.zeros(n,s),l=c.data;if(w(e))if(w(s)&&Number.isInteger(t)&&t>=0){let m=o,f=l;for(let p=0;p<a;p++)f[p]=m[p]**BigInt(t)}else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);else for(let m=0;m<a;m++)l[m]=Math.pow(Number(o[m]),t);return c}function vo(r){return V(r,Math.exp,!1)}function Eo(r){return V(r,t=>Math.pow(2,t),!1)}function Oo(r){return V(r,Math.expm1,!1)}function Mo(r){return V(r,Math.log,!1)}function To(r){return V(r,Math.log2,!1)}function Uo(r){return V(r,Math.log10,!1)}function $o(r){return V(r,Math.log1p,!1)}function ko(r,t){return typeof t=="number"?zu(r,t):wu(r,t)}function wu(r,t){let e=lr(r.shape,t.shape),n=e.reduce((c,l)=>c*l,1),o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=S.zeros(e,i),s=u.data;for(let c=0;c<n;c++){let l=(w(o),Number(r.iget(c))),m=(w(a),Number(t.iget(c))),f=Math.max(l,m),p=Math.min(l,m);s[c]=f+Math.log1p(Math.exp(p-f))}return u}function zu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=S.zeros(n,a),u=i.data;for(let s=0;s<o;s++){let c=(w(e),Number(r.data[s])),l=Math.max(c,t),m=Math.min(c,t);u[s]=l+Math.log1p(Math.exp(m-l))}return i}function Co(r,t){return typeof t=="number"?_u(r,t):Iu(r,t)}function Iu(r,t){let e=lr(r.shape,t.shape),n=e.reduce((l,m)=>l*m,1),o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=S.zeros(e,i),s=u.data,c=Math.LOG2E;for(let l=0;l<n;l++){let m=(w(o),Number(r.iget(l))),f=(w(a),Number(t.iget(l))),p=Math.max(m,f),y=Math.min(m,f);s[l]=p+Math.log1p(Math.pow(2,y-p))*c}return u}function _u(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.size,a=e==="float32"?"float32":"float64",i=S.zeros(n,a),u=i.data,s=Math.LOG2E;for(let c=0;c<o;c++){let l=(w(e),Number(r.data[c])),m=Math.max(l,t),f=Math.min(l,t);u[c]=m+Math.log1p(Math.pow(2,f-m))*s}return i}var Fo=k(()=>{"use strict";R();sr();W()});function Vo(r){return V(r,Math.sin,!1)}function Po(r){return V(r,Math.cos,!1)}function qo(r){return V(r,Math.tan,!1)}function jo(r){return V(r,Math.asin,!1)}function Ro(r){return V(r,Math.acos,!1)}function Lo(r){return V(r,Math.atan,!1)}function Wo(r,t){return typeof t=="number"?Eu(r,t):vu(r,t)}function vu(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=S.zeros(e,i),s=u.data;for(let c=0;c<n;c++){let l=(w(o),Number(r.data[c])),m=(w(a),Number(t.data[c]));s[c]=Math.atan2(l,m)}return u}function Eu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",u=S.zeros(n,i),s=u.data;if(w(e))for(let c=0;c<a;c++)s[c]=Math.atan2(Number(o[c]),t);else for(let c=0;c<a;c++)s[c]=Math.atan2(Number(o[c]),t);return u}function Go(r,t){return typeof t=="number"?Mu(r,t):Ou(r,t)}function Ou(r,t){let e=Array.from(r.shape),n=r.size,o=r.dtype,a=t.dtype,i=o==="float32"&&a==="float32"?"float32":"float64",u=S.zeros(e,i),s=u.data;for(let c=0;c<n;c++){let l=(w(o),Number(r.data[c])),m=(w(a),Number(t.data[c]));s[c]=Math.hypot(l,m)}return u}function Mu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",u=S.zeros(n,i),s=u.data;if(w(e))for(let c=0;c<a;c++)s[c]=Math.hypot(Number(o[c]),t);else for(let c=0;c<a;c++)s[c]=Math.hypot(Number(o[c]),t);return u}function Zo(r){let t=180/Math.PI;return V(r,e=>e*t,!1)}function Ho(r){let t=Math.PI/180;return V(r,e=>e*t,!1)}var Yo=k(()=>{"use strict";R();sr();W()});function Jo(r){return V(r,Math.sinh,!1)}function Xo(r){return V(r,Math.cosh,!1)}function Qo(r){return V(r,Math.tanh,!1)}function Ko(r){return V(r,Math.asinh,!1)}function ra(r){return V(r,Math.acosh,!1)}function ta(r){return V(r,Math.atanh,!1)}var ea=k(()=>{"use strict";sr()});function mt(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=or([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 ar(r,t)}function na(r){if(r.length===0)return[];if(r.length===1)return[r[0]];let t=r.map(n=>Array.from(n.shape)),e=or(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=>ar(n,e))}function oa(r,t,e){let n=r.shape,o=n.length,a=r.dtype;if(e===void 0){let y=r.size;for(let A of t){let b=A<0?y+A:A;if(b<0||b>=y)throw new Error(`index ${A} is out of bounds for axis 0 with size ${y}`)}let d=t.length,g=T(a);if(!g)throw new Error(`Cannot take from array with dtype ${a}`);let h=new g(d);for(let A=0;A<d;A++){let b=t[A];b<0&&(b=y+b);let N=r.iget(b);w(a),h[A]=N}return S.fromData(h,[d],a)}let i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i];for(let y of t){let d=y<0?u+y:y;if(d<0||d>=u)throw new Error(`index ${y} is out of bounds for axis ${i} with size ${u}`)}let s=Array.from(n);s[i]=t.length;let c=s.reduce((y,d)=>y*d,1),l=T(a);if(!l)throw new Error(`Cannot take from array with dtype ${a}`);let m=new l(c),f=H(s),p=new Array(o).fill(0);for(let y=0;y<c;y++){let d=[...p],g=p[i],h=t[g];h<0&&(h=u+h),d[i]=h;let A=r.get(...d),b=0;for(let N=0;N<o;N++)b+=p[N]*f[N];w(a),m[b]=A;for(let N=o-1;N>=0&&(p[N]++,!(p[N]<s[N]));N--)p[N]=0}return S.fromData(m,s,a)}function aa(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=new Array(t.length).fill(e);else{a=[];for(let i=0;i<e.size;i++)a.push(e.iget(i));if(a.length===1)a=new Array(t.length).fill(a[0]);else if(a.length!==t.length){let i=[...a];a=[];for(let u=0;u<t.length;u++)a.push(i[u%i.length])}}for(let i=0;i<t.length;i++){let u=t[i];if(u<0&&(u=n+u),u<0||u>=n)throw new Error(`index ${t[i]} is out of bounds for axis 0 with size ${n}`);let s=a[i];w(o)?typeof s!="bigint"&&(s=BigInt(Math.round(Number(s)))):typeof s=="bigint"&&(s=Number(s)),r.iset(u,s)}}function sa(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=or(a);if(i===null)throw new Error("operands could not be broadcast together");let u=ar(r,i),s=t.map(f=>ar(f,i)),c=i.reduce((f,p)=>f*p,1),l=T(o);if(!l)throw new Error(`Cannot choose with dtype ${o}`);let m=new l(c);for(let f=0;f<c;f++){let p=Number(u.iget(f));if(p<0||p>=n)throw new Error(`index ${p} is out of bounds for axis 0 with size ${n}`);let y=s[p].iget(f);w(o),m[f]=y}return S.fromData(m,i,o)}function ia(r,t,e=!1){if(r.ndim!==t.ndim)return!1;for(let o=0;o<r.ndim;o++)if(r.shape[o]!==t.shape[o])return!1;let n=r.size;for(let o=0;o<n;o++){let a=r.iget(o),i=t.iget(o);if(e){let u=typeof a=="number"&&Number.isNaN(a),s=typeof i=="number"&&Number.isNaN(i);if(u&&s)continue}if(a!==i)return!1}return!0}function ua(r,t,e){let n=r.shape,o=n.length,a=r.dtype,i=e<0?o+e:e;if(i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=t.shape;if(u.length!==o)throw new Error(`indices and arr must have the same number of dimensions, got ${u.length} vs ${o}`);for(let d=0;d<o;d++)if(d!==i&&u[d]!==n[d]&&u[d]!==1&&n[d]!==1)throw new Error(`index ${u[d]} is out of bounds for size ${n[d]} in dimension ${d}`);let s=Array.from(u),c=s.reduce((d,g)=>d*g,1),l=T(a);if(!l)throw new Error(`Cannot take_along_axis with dtype ${a}`);let m=new l(c),f=H(n),p=H(u),y=n[i];for(let d=0;d<c;d++){let g=new Array(o),h=d;for(let z=o-1;z>=0;z--)g[z]=h%s[z],h=Math.floor(h/s[z]);let A=0;for(let z=0;z<o;z++){let _=u[z]===1?0:g[z];A+=_*p[z]}let b=Number(t.iget(A));if(b<0&&(b=y+b),b<0||b>=y)throw new Error(`index ${b} is out of bounds for axis ${i} with size ${y}`);let N=[...g];N[i]=b;let D=0;for(let z=0;z<o;z++){let _=n[z]===1?0:N[z];D+=_*f[z]}let x=r.iget(D);w(a),m[d]=x}return S.fromData(m,s,a)}function ca(r,t,e,n){let o=r.shape,a=o.length,i=r.dtype,u=n<0?a+n:n;if(u<0||u>=a)throw new Error(`axis ${n} is out of bounds for array of dimension ${a}`);let s=t.shape,c=e.shape;if(s.length!==a||c.length!==a)throw new Error("indices, arr, and values must have same ndim");let l=o[u],m=H(o),f=H(s),p=H(c),y=s.reduce((d,g)=>d*g,1);for(let d=0;d<y;d++){let g=new Array(a),h=d;for(let _=a-1;_>=0;_--)g[_]=h%s[_],h=Math.floor(h/s[_]);let A=0;for(let _=0;_<a;_++)A+=g[_]*f[_];let b=Number(t.iget(A));if(b<0&&(b=l+b),b<0||b>=l)throw new Error(`index ${b} is out of bounds for axis ${u} with size ${l}`);let N=0;for(let _=0;_<a;_++){let B=c[_]===1?0:g[_];N+=B*p[_]}let D=e.iget(N),x=[...g];x[u]=b;let z=0;for(let _=0;_<a;_++)z+=x[_]*m[_];w(i)?typeof D!="bigint"&&(D=BigInt(Math.round(Number(D)))):typeof D=="bigint"&&(D=Number(D)),r.iset(z,D)}}function la(r,t,e){let n=r.size,o=r.dtype,a;if(typeof e=="number"||typeof e=="bigint")a=[e];else{a=[];for(let u=0;u<e.size;u++)a.push(e.iget(u))}let i=0;for(let u=0;u<n;u++)if(t.iget(u)){let c=a[i%a.length];w(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(u,c),i++}}function fa(r,t,e){let n=t.shape,o=n.length,a=t.dtype,i=t.data,u=w(a);if(e===void 0){let A=0,b=Math.min(r.size,t.size);for(let z=0;z<b;z++)r.iget(z)&&A++;let N=T(a);if(!N)throw new Error(`Cannot compress with dtype ${a}`);let D=new N(A),x=0;for(let z=0;z<b;z++)r.iget(z)&&(D[x]=i[z],x++);return S.fromData(D,[A],a)}let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let c=n[s],l=Math.min(r.size,c),m=[];for(let A=0;A<l;A++)r.iget(A)&&m.push(A);let f=m.length,p=[...n];p[s]=f;let y=p.reduce((A,b)=>A*b,1),d=T(a);if(!d)throw new Error(`Cannot compress with dtype ${a}`);let g=new d(y),h=H(n);if(s===0){let A=h[0],b=n.slice(1).reduce((D,x)=>D*x,1),N=0;for(let D=0;D<f;D++){let z=m[D]*A;if(u){let _=i,B=g;for(let v=0;v<b;v++)B[N++]=_[z+v]}else{let _=i,B=g;for(let v=0;v<b;v++)B[N++]=_[z+v]}}}else{let A=n.slice(0,s).reduce((D,x)=>D*x,1),b=n.slice(s+1).reduce((D,x)=>D*x,1),N=0;for(let D=0;D<A;D++)for(let x=0;x<f;x++){let z=m[x],_=0,B=D;for(let v=s-1;v>=0;v--){let E=B%n[v];B=Math.floor(B/n[v]),_+=E*h[v]}if(_+=z*h[s],u){let v=i,E=g;for(let U=0;U<b;U++)E[N++]=v[_+U]}else{let v=i,E=g;for(let U=0;U<b;U++)E[N++]=v[_+U]}}}return S.fromData(g,p,a)}function ma(r,t,e=0){if(r.length!==t.length)throw new Error("condlist and choicelist must have same length");if(r.length===0)throw new Error("condlist and choicelist cannot be empty");let n=[...r.map(f=>Array.from(f.shape)),...t.map(f=>Array.from(f.shape))],o=or(n);if(o===null)throw new Error("condlist and choicelist arrays could not be broadcast together");let a=t[0].dtype,i=o.reduce((f,p)=>f*p,1),u=T(a);if(!u)throw new Error(`Cannot select with dtype ${a}`);let s=e;w(a)?s=typeof e=="bigint"?e:BigInt(e):s=typeof e=="bigint"?Number(e):e;let c=new u(i);for(let f=0;f<i;f++)w(a),c[f]=s;let l=r.map(f=>ar(f,o)),m=t.map(f=>ar(f,o));for(let f=0;f<i;f++)for(let p=0;p<r.length;p++)if(l[p].iget(f)){let y=m[p].iget(f);w(a),c[f]=y;break}return S.fromData(c,o,a)}function pa(r,t,e){let n=r.size,o=r.dtype,a=[];for(let u=0;u<e.size;u++)a.push(e.iget(u));if(a.length===0)return;let i=0;for(let u=0;u<n;u++)if(t.iget(u)){let c=a[i%a.length];w(o)?typeof c!="bigint"&&(c=BigInt(Math.round(Number(c)))):typeof c=="bigint"&&(c=Number(c)),r.iset(u,c),i++}}function ae(r,t=2){if(t<1)throw new Error("ndim must be at least 1");let e=new Int32Array(r);for(let o=0;o<r;o++)e[o]=o;let n=[];for(let o=0;o<t;o++)n.push(S.fromData(new Int32Array(e),[r],"int32"));return n}function ya(r){let t=r.shape,e=t.length;if(e<2)throw new Error("array must be at least 2-D");let n=t[0];for(let o=1;o<e;o++)if(t[o]!==n)throw new Error("All dimensions of input must be equal");return ae(n,e)}function se(r,t=0,e){let n=e??r,o=[],a=[];for(let i=0;i<r;i++)for(let u=0;u<=Math.min(i+t,n-1);u++)u>=0&&(o.push(i),a.push(u));return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(a),[a.length],"int32")]}function da(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return se(e[0],t,e[1])}function ie(r,t=0,e){let n=e??r,o=[],a=[];for(let i=0;i<r;i++)for(let u=Math.max(i+t,0);u<n;u++)o.push(i),a.push(u);return[S.fromData(new Int32Array(o),[o.length],"int32"),S.fromData(new Int32Array(a),[a.length],"int32")]}function ga(r,t=0){let e=r.shape;if(e.length!==2)throw new Error("array must be 2-D");return ie(e[0],t,e[1])}function ba(r,t,e=0){let n=t(r,e),o=n.shape;if(o.length!==2||o[0]!==r||o[1]!==r)throw new Error("mask_func must return n x n array");let a=[],i=[];for(let u=0;u<r;u++)for(let s=0;s<r;s++)n.get(u,s)&&(a.push(u),i.push(s));return[S.fromData(new Int32Array(a),[a.length],"int32"),S.fromData(new Int32Array(i),[i.length],"int32")]}function Aa(r,t="int32"){let e=r.length,n=[e,...r],o=n.reduce((s,c)=>s*c,1),a=T(t);if(!a)throw new Error(`Cannot create indices with dtype ${t}`);let i=new a(o),u=r.reduce((s,c)=>s*c,1);for(let s=0;s<e;s++){let c=s*u;for(let l=0;l<u;l++){let m=new Array(e),f=l;for(let y=e-1;y>=0;y--)m[y]=f%r[y],f=Math.floor(f/r[y]);let p=m[s];t==="int64"?i[c+l]=BigInt(p):i[c+l]=p}}return S.fromData(i,n,t)}function ha(...r){let t=r.length,e=[];for(let n=0;n<t;n++){let o=r[n],a=o.size,i=o.dtype,u=new Array(t).fill(1);u[n]=a;let s=T(i);if(!s)throw new Error(`Cannot create ix_ with dtype ${i}`);let c=new s(a);for(let l=0;l<a;l++){let m=o.iget(l);w(i),c[l]=m}e.push(S.fromData(c,u,i))}return e}function Sa(r,t,e="raise"){if(r.length!==t.length)throw new Error("multi_index length must equal dims length");if(r.length===0)throw new Error("multi_index cannot be empty");let n=r[0].size,o=t.length,a=new Int32Array(n),i=new Array(o),u=1;for(let s=o-1;s>=0;s--)i[s]=u,u*=t[s];for(let s=0;s<n;s++){let c=0;for(let l=0;l<o;l++){let m=Number(r[l].iget(s)),f=t[l];if(e==="wrap")m=(m%f+f)%f;else if(e==="clip")m=Math.max(0,Math.min(m,f-1));else if(m<0||m>=f)throw new Error(`index ${m} is out of bounds for axis ${l} with size ${f}`);c+=m*i[l]}a[s]=c}return S.fromData(a,[n],"int32")}function Na(r,t,e="C"){let n=t.length,o,a;if(typeof r=="number")o=[r],a=[];else{o=[];for(let l=0;l<r.size;l++)o.push(Number(r.iget(l)));a=Array.from(r.shape)}let i=o.length,u=t.reduce((l,m)=>l*m,1),s=new Array(n);if(e==="C"){let l=1;for(let m=n-1;m>=0;m--)s[m]=l,l*=t[m]}else{let l=1;for(let m=0;m<n;m++)s[m]=l,l*=t[m]}let c=[];for(let l=0;l<n;l++){let m=new Int32Array(i);c.push(S.fromData(m,a.length?a:[1],"int32"))}for(let l=0;l<i;l++){let m=o[l];if(m<0||m>=u)throw new Error(`index ${m} is out of bounds for array with size ${u}`);if(e==="C")for(let f=0;f<n;f++){let p=Math.floor(m/s[f]);m=m%s[f],c[f].data[l]=p%t[f]}else for(let f=n-1;f>=0;f--){let p=Math.floor(m/s[f]);m=m%s[f],c[f].data[l]=p%t[f]}}return typeof r=="number"?c.map(l=>{let m=l.iget(0);return S.fromData(new Int32Array([Number(m)]),[],"int32")}):c}function Da(r,t,e=!1){let n=r.shape,o=n.length;if(o<2)throw new Error("array must be at least 2-d");let a;if(o===2)a=n[1]+1;else{a=1;for(let c=1;c<o;c++){let l=1;for(let m=c;m<o;m++)l*=n[m];a+=l}}let i=r.data,u=r.size,s=Math.min(...n);if(e&&o===2&&(s=Math.max(n[0],n[1])),typeof t=="number")for(let c=0;c<s&&c*a<u;c++){let l=c*a;if(l<u)i[l]=t;else break}else{let c=t.data,l=t.size;for(let m=0;m<s&&m*a<u;m++){let f=m*a;if(f<u)i[f]=c[m%l];else break}}}var xa=k(()=>{"use strict";R();W();Yr()});function tr(r,t){if(!rn(r)&&r!=="bool")throw new TypeError(`ufunc '${t}' not supported for the input types, and the inputs could not be safely coerced to any supported types`)}function Mr(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function Ia(r,t){return tr(r.dtype,"bitwise_and"),typeof t=="number"?Cu(r,t):(tr(t.dtype,"bitwise_and"),Mr(r,t)?ku(r,t):P(r,t,(e,n)=>e&n,"bitwise_and"))}function ku(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=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 m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m&f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]&m[f]}}else for(let s=0;s<o;s++)u[s]=a[s]&i[s];return n}function Cu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]&l}else for(let s=0;s<a;s++)u[s]=o[s]&t;return i}function _a(r,t){return tr(r.dtype,"bitwise_or"),typeof t=="number"?Vu(r,t):(tr(t.dtype,"bitwise_or"),Mr(r,t)?Fu(r,t):P(r,t,(e,n)=>e|n,"bitwise_or"))}function Fu(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=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 m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m|f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]|m[f]}}else for(let s=0;s<o;s++)u[s]=a[s]|i[s];return n}function Vu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]|l}else for(let s=0;s<a;s++)u[s]=o[s]|t;return i}function Ba(r,t){return tr(r.dtype,"bitwise_xor"),typeof t=="number"?qu(r,t):(tr(t.dtype,"bitwise_xor"),Mr(r,t)?Pu(r,t):P(r,t,(e,n)=>e^n,"bitwise_xor"))}function Pu(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=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 m=typeof a[l]=="bigint"?a[l]:BigInt(Math.round(Number(a[l]))),f=typeof i[l]=="bigint"?i[l]:BigInt(Math.round(Number(i[l])));s[l]=m^f}else{let l=a,m=i;for(let f=0;f<o;f++)s[f]=l[f]^m[f]}}else for(let s=0;s<o;s++)u[s]=a[s]^i[s];return n}function qu(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]^l}else for(let s=0;s<a;s++)u[s]=o[s]^t;return i}function ue(r){tr(r.dtype,"bitwise_not");let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=S.zeros(e,t),i=a.data;if(w(t)){let u=n,s=i;for(let c=0;c<o;c++)s[c]=~u[c]}else for(let u=0;u<o;u++)i[u]=~n[u];return a}function va(r){return ue(r)}function Ea(r,t){if(tr(r.dtype,"left_shift"),typeof t=="number")return wa(r,t);if(tr(t.dtype,"left_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=w(t.dtype)?Number(t.data[0]):t.data[0];return wa(r,e)}return Mr(r,t)?ju(r,t):P(r,t,(e,n)=>e<<n,"left_shift")}function ju(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(w(e)){let s=u;for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),m=typeof i[c]=="bigint"?i[c]:BigInt(Math.round(Number(i[c])));s[c]=l<<m}}else for(let s=0;s<o;s++)u[s]=a[s]<<i[s];return n}function wa(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]<<l}else for(let s=0;s<a;s++)u[s]=o[s]<<t;return i}function Oa(r,t){if(tr(r.dtype,"right_shift"),typeof t=="number")return za(r,t);if(tr(t.dtype,"right_shift"),t.size===1||t.ndim===1&&t.shape[0]===1){let e=w(t.dtype)?Number(t.data[0]):t.data[0];return za(r,e)}return Mr(r,t)?Ru(r,t):P(r,t,(e,n)=>e>>n,"right_shift")}function Ru(r,t){let e=C(r.dtype,t.dtype),n=S.zeros(Array.from(r.shape),e),o=r.size,a=r.data,i=t.data,u=n.data;if(w(e)){let s=u;for(let c=0;c<o;c++){let l=typeof a[c]=="bigint"?a[c]:BigInt(Math.round(Number(a[c]))),m=typeof i[c]=="bigint"?i[c]:BigInt(Math.round(Number(i[c])));s[c]=l>>m}}else for(let s=0;s<o;s++)u[s]=a[s]>>i[s];return n}function za(r,t){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=S.zeros(n,e),u=i.data;if(w(e)){let s=o,c=u,l=BigInt(Math.round(t));for(let m=0;m<a;m++)c[m]=s[m]>>l}else for(let s=0;s<a;s++)u[s]=o[s]>>t;return i}function Ma(r,t=-1,e="big"){let n=Array.from(r.shape),o=n.length;if(t<0&&(t=o+t),t<0||t>=o)throw new Error(`axis ${t} is out of bounds for array of dimension ${o}`);let a=n[t],i=Math.ceil(a/8),u=[...n];u[t]=i;let s=S.zeros(u,"uint8"),c=s.data;if(o===1){for(let g=0;g<i;g++){let h=0;for(let A=0;A<8;A++){let b=g*8+A;if(b<a){let N=Number(r.data[b])!==0?1:0;e==="big"?h|=N<<7-A:h|=N<<A}}c[g]=h}return s}let l=n.slice(0,t),m=n.slice(t+1),f=l.reduce((g,h)=>g*h,1),p=m.reduce((g,h)=>g*h,1),y=pt(n),d=pt(u);for(let g=0;g<f;g++)for(let h=0;h<p;h++)for(let A=0;A<i;A++){let b=0;for(let z=0;z<8;z++){let _=A*8+z;if(_<a){let B=0,v=g;for(let $=0;$<t;$++){let q=$<t-1?l.slice($+1).reduce((Z,Ir)=>Z*Ir,1):1,J=Math.floor(v/q);v%=q,B+=J*y[$]}B+=_*y[t];let E=h;for(let $=t+1;$<o;$++){let q=$<o-1?m.slice($-t).reduce((Z,Ir)=>Z*Ir,1):1,J=Math.floor(E/q);E%=q,B+=J*y[$]}let U=Number(r.data[B])!==0?1:0;e==="big"?b|=U<<7-z:b|=U<<z}}let N=0,D=g;for(let z=0;z<t;z++){let _=z<t-1?l.slice(z+1).reduce((v,E)=>v*E,1):1,B=Math.floor(D/_);D%=_,N+=B*d[z]}N+=A*d[t];let x=h;for(let z=t+1;z<o;z++){let _=z<o-1?m.slice(z-t).reduce((v,E)=>v*E,1):1,B=Math.floor(x/_);x%=_,N+=B*d[z]}c[N]=b}return s}function Ta(r,t=-1,e=-1,n="big"){if(r.dtype!=="uint8")throw new TypeError("Expected an input array of unsigned byte data type");let o=Array.from(r.shape),a=o.length;if(t<0&&(t=a+t),t<0||t>=a)throw new Error(`axis ${t} is out of bounds for array of dimension ${a}`);let i=o[t],u=i*8;e>=0&&(u=e);let s=[...o];s[t]=u;let c=S.zeros(s,"uint8"),l=c.data;if(a===1){for(let h=0;h<i;h++){let A=Number(r.data[h]);for(let b=0;b<8;b++){let N=h*8+b;if(N>=u)break;n==="big"?l[N]=A>>7-b&1:l[N]=A>>b&1}}return c}let m=o.slice(0,t),f=o.slice(t+1),p=m.reduce((h,A)=>h*A,1),y=f.reduce((h,A)=>h*A,1),d=pt(o),g=pt(s);for(let h=0;h<p;h++)for(let A=0;A<y;A++)for(let b=0;b<i;b++){let N=0,D=h;for(let _=0;_<t;_++){let B=_<t-1?m.slice(_+1).reduce((E,U)=>E*U,1):1,v=Math.floor(D/B);D%=B,N+=v*d[_]}N+=b*d[t];let x=A;for(let _=t+1;_<a;_++){let B=_<a-1?f.slice(_-t).reduce((E,U)=>E*U,1):1,v=Math.floor(x/B);x%=B,N+=v*d[_]}let z=Number(r.data[N]);for(let _=0;_<8;_++){let B=b*8+_;if(B>=u)break;let v=0;D=h;for(let E=0;E<t;E++){let U=E<t-1?m.slice(E+1).reduce((q,J)=>q*J,1):1,$=Math.floor(D/U);D%=U,v+=$*g[E]}v+=B*g[t],x=A;for(let E=t+1;E<a;E++){let U=E<a-1?f.slice(E-t).reduce((q,J)=>q*J,1):1,$=Math.floor(x/U);x%=U,v+=$*g[E]}n==="big"?l[v]=z>>7-_&1:l[v]=z>>_&1}}return c}function pt(r){let t=r.length,e=new Array(t),n=1;for(let o=t-1;o>=0;o--)e[o]=n,n*=r[o];return e}var Ua=k(()=>{"use strict";R();W();sr()});function Nr(r){return r!==0&&r!==0n}function Ur(r,t){return r.isCContiguous&&t.isCContiguous&&r.shape.length===t.shape.length&&r.shape.every((e,n)=>e===t.shape[n])}function ka(r,t){return typeof t=="number"?Gu(r,t):Ur(r,t)?Wu(r,t):Q(r,t,(e,n)=>Nr(e)&&Nr(n))}function Wu(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.size,i=w(r.dtype),u=w(t.dtype);if(i||u)for(let s=0;s<a;s++){let c=i?n[s]!==0n:n[s]!==0,l=u?o[s]!==0n:o[s]!==0;e[s]=c&&l?1:0}else for(let s=0;s<a;s++)e[s]=n[s]!==0&&o[s]!==0?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function Gu(r,t){let e=new Uint8Array(r.size),n=r.data,o=t!==0,a=r.size;if(w(r.dtype)){let i=n;for(let u=0;u<a;u++)e[u]=i[u]!==0n&&o?1:0}else for(let i=0;i<a;i++)e[i]=n[i]!==0&&o?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function Ca(r,t){return typeof t=="number"?Hu(r,t):Ur(r,t)?Zu(r,t):Q(r,t,(e,n)=>Nr(e)||Nr(n))}function Zu(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.size,i=w(r.dtype),u=w(t.dtype);if(i||u)for(let s=0;s<a;s++){let c=i?n[s]!==0n:n[s]!==0,l=u?o[s]!==0n:o[s]!==0;e[s]=c||l?1:0}else for(let s=0;s<a;s++)e[s]=n[s]!==0||o[s]!==0?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function Hu(r,t){let e=new Uint8Array(r.size),n=r.data,o=t!==0,a=r.size;if(w(r.dtype)){let i=n;for(let u=0;u<a;u++)e[u]=i[u]!==0n||o?1:0}else for(let i=0;i<a;i++)e[i]=n[i]!==0||o?1:0;return S.fromData(e,Array.from(r.shape),"bool")}function Fa(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(w(r.dtype)){let o=e;for(let a=0;a<n;a++)t[a]=o[a]===0n?1:0}else for(let o=0;o<n;o++)t[o]=e[o]===0?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function Va(r,t){return typeof t=="number"?Ju(r,t):Ur(r,t)?Yu(r,t):Q(r,t,(e,n)=>Nr(e)!==Nr(n))}function Yu(r,t){let e=new Uint8Array(r.size),n=r.data,o=t.data,a=r.size,i=w(r.dtype),u=w(t.dtype);if(i||u)for(let s=0;s<a;s++){let c=i?n[s]!==0n:n[s]!==0,l=u?o[s]!==0n:o[s]!==0;e[s]=c!==l?1:0}else for(let s=0;s<a;s++){let c=n[s]!==0,l=o[s]!==0;e[s]=c!==l?1:0}return S.fromData(e,Array.from(r.shape),"bool")}function Ju(r,t){let e=new Uint8Array(r.size),n=r.data,o=t!==0,a=r.size;if(w(r.dtype)){let i=n;for(let u=0;u<a;u++){let s=i[u]!==0n;e[u]=s!==o?1:0}}else for(let i=0;i<a;i++){let u=n[i]!==0;e[i]=u!==o?1:0}return S.fromData(e,Array.from(r.shape),"bool")}function Pa(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(w(r.dtype))for(let o=0;o<n;o++)t[o]=1;else for(let o=0;o<n;o++){let a=e[o];t[o]=Number.isFinite(a)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function qa(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(w(r.dtype))for(let o=0;o<n;o++)t[o]=0;else for(let o=0;o<n;o++){let a=e[o];t[o]=!Number.isFinite(a)&&!Number.isNaN(a)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function ja(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(w(r.dtype))for(let o=0;o<n;o++)t[o]=0;else for(let o=0;o<n;o++)t[o]=Number.isNaN(e[o])?1:0;return S.fromData(t,Array.from(r.shape),"bool")}function Ra(r){let t=new Uint8Array(r.size);return S.fromData(t,Array.from(r.shape),"bool")}function La(r,t){if(typeof t=="number")return Qu(r,t);if(Ur(r,t))return Xu(r,t);let e=lr(r.shape,t.shape),n=e.reduce((s,c)=>s*c,1),o=S.zeros(e,"float64"),a=o.data,i=yt(r,e),u=yt(t,e);for(let s=0;s<n;s++){let c=Number(i.iget(s)),l=Number(u.iget(s));a[s]=Math.sign(l)*Math.abs(c)}return o}function Xu(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,i=t.data,u=w(r.dtype),s=w(t.dtype);for(let c=0;c<o;c++){let l=u?Number(a[c]):a[c],m=s?Number(i[c]):i[c];n[c]=Math.sign(m)*Math.abs(l)}return e}function Qu(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size,i=Math.sign(t);if(w(r.dtype)){let u=o;for(let s=0;s<a;s++)n[s]=i*Math.abs(Number(u[s]))}else for(let u=0;u<a;u++)n[u]=i*Math.abs(o[u]);return e}function Wa(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(w(r.dtype)){let o=e;for(let a=0;a<n;a++)t[a]=o[a]<0n?1:0}else for(let o=0;o<n;o++){let a=e[o];t[o]=a<0||Object.is(a,-0)?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function Ga(r,t){if(typeof t=="number")return rc(r,t);if(Ur(r,t))return Ku(r,t);let e=lr(r.shape,t.shape),n=e.reduce((s,c)=>s*c,1),o=S.zeros(e,"float64"),a=o.data,i=yt(r,e),u=yt(t,e);for(let s=0;s<n;s++){let c=Number(i.iget(s)),l=Number(u.iget(s));a[s]=Tr(c,l)}return o}function Ku(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.size,a=r.data,i=t.data,u=w(r.dtype),s=w(t.dtype);for(let c=0;c<o;c++){let l=u?Number(a[c]):a[c],m=s?Number(i[c]):i[c];n[c]=Tr(l,m)}return e}function rc(r,t){let e=S.zeros(Array.from(r.shape),"float64"),n=e.data,o=r.data,a=r.size;if(w(r.dtype)){let i=o;for(let u=0;u<a;u++)n[u]=Tr(Number(i[u]),t)}else for(let i=0;i<a;i++)n[i]=Tr(o[i],t);return e}function Tr(r,t){if(Number.isNaN(r)||Number.isNaN(t))return NaN;if(r===t)return t;if(r===0)return t>0?Number.MIN_VALUE:-Number.MIN_VALUE;let e=new ArrayBuffer(8),n=new Float64Array(e),o=new BigInt64Array(e);n[0]=r;let a=o[0];return r>0&&t>r||r<0&&t>r?a=a+1n:a=a-1n,o[0]=a,n[0]}function Za(r){let t=S.zeros(Array.from(r.shape),"float64"),e=t.data,n=r.data,o=r.size;if(w(r.dtype)){let a=n;for(let i=0;i<o;i++)e[i]=$a(Number(a[i]))}else for(let a=0;a<o;a++)e[a]=$a(n[a]);return t}function $a(r){if(Number.isNaN(r))return NaN;if(!Number.isFinite(r))return NaN;if(Math.abs(r)===0)return Number.MIN_VALUE;let e=Tr(r,1/0);return Math.abs(e-r)}function yt(r,t){let e=r.shape.length,n=t.length,o=new Array(n).fill(0);for(let a=0;a<e;a++){let i=n-e+a,u=r.shape[a],s=t[i];if(u===s)o[i]=r.strides[a];else if(u===1)o[i]=0;else throw new Error("Invalid broadcast")}return S.fromData(r.data,Array.from(t),r.dtype,o,r.offset)}function Ha(r){let t=new Uint8Array(r.size);return S.fromData(t,Array.from(r.shape),"bool")}function Ya(r){return!1}function Ja(r){let t=new Uint8Array(r.size).fill(1);return S.fromData(t,Array.from(r.shape),"bool")}function Xa(r){return!0}function Qa(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(!w(r.dtype))for(let o=0;o<n;o++){let a=e[o];t[o]=a===-1/0?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function Ka(r){let t=new Uint8Array(r.size),e=r.data,n=r.size;if(!w(r.dtype))for(let o=0;o<n;o++){let a=e[o];t[o]=a===1/0?1:0}return S.fromData(t,Array.from(r.shape),"bool")}function rs(r){return r.isFContiguous}function ts(r,t=100){return r.copy()}function es(r){return typeof r=="number"||typeof r=="bigint"||typeof r=="boolean"||typeof r=="string"}function ns(r){return r==null?!1:typeof r[Symbol.iterator]=="function"}function os(r,t){let n={b:["bool"],i:["int8","int16","int32","int64"],u:["uint8","uint16","uint32","uint64"],f:["float32","float64"]}[t];return n?n.includes(r):!1}function as(r,t){let e=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"],n=e.indexOf(r),o=e.indexOf(t);return n<=o?r:t}var ss=k(()=>{"use strict";R();W();sr();sr()});function ce(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return r.copy();let i=t;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let u=r.copy(),s=u.data,c=e[i],l=Array.from(e).filter((f,p)=>p!==i),m=l.length===0?1:l.reduce((f,p)=>f*p,1);if(w(o)){let f=a,p=s;for(let y=0;y<m;y++){let d=[];for(let g=0;g<c;g++){let h=M(y,i,g,e),A=O(h,e);d.push({value:f[A],idx:g})}d.sort((g,h)=>g.value<h.value?-1:g.value>h.value?1:0);for(let g=0;g<c;g++){let h=M(y,i,g,e),A=O(h,e);p[A]=d[g].value}}}else for(let f=0;f<m;f++){let p=[];for(let y=0;y<c;y++){let d=M(f,i,y,e),g=O(d,e);p.push(Number(a[g]))}p.sort((y,d)=>isNaN(y)&&isNaN(d)?0:isNaN(y)?1:isNaN(d)?-1:y-d);for(let y=0;y<c;y++){let d=M(f,i,y,e),g=O(d,e);s[g]=p[y]}}return u}function le(r,t=-1){let e=r.shape,n=e.length,o=r.dtype,a=r.data;if(n===0)return S.zeros([0],"int32");let i=t;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let u=S.zeros(Array.from(e),"int32"),s=u.data,c=e[i],l=Array.from(e).filter((f,p)=>p!==i),m=l.length===0?1:l.reduce((f,p)=>f*p,1);if(w(o)){let f=a;for(let p=0;p<m;p++){let y=[];for(let d=0;d<c;d++){let g=M(p,i,d,e),h=O(g,e);y.push({value:f[h],idx:d})}y.sort((d,g)=>d.value<g.value?-1:d.value>g.value?1:0);for(let d=0;d<c;d++){let g=M(p,i,d,e),h=O(g,e);s[h]=y[d].idx}}}else for(let f=0;f<m;f++){let p=[];for(let y=0;y<c;y++){let d=M(f,i,y,e),g=O(d,e);p.push({value:Number(a[g]),idx:y})}p.sort((y,d)=>isNaN(y.value)&&isNaN(d.value)?0:isNaN(y.value)?1:isNaN(d.value)?-1:y.value-d.value);for(let y=0;y<c;y++){let d=M(f,i,y,e),g=O(d,e);s[g]=p[y].idx}}return u}function is(r){if(r.length===0)return S.zeros([0],"int32");let e=r[0].size;for(let i of r){if(i.ndim!==1)throw new Error("keys must be 1D arrays");if(i.size!==e)throw new Error("all keys must have the same length")}let n=[];for(let i=0;i<e;i++)n.push(i);n.sort((i,u)=>{for(let s=r.length-1;s>=0;s--){let l=r[s].data,m=Number(l[i]),f=Number(l[u]);if(!(isNaN(m)&&isNaN(f))){if(isNaN(m))return 1;if(isNaN(f)||m<f)return-1;if(m>f)return 1}}return 0});let o=S.zeros([e],"int32"),a=o.data;for(let i=0;i<e;i++)a[i]=n[i];return o}function ec(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],i=r[o],u=r[n],s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++){let f=r[m],p=isNaN(f),y=isNaN(c);!p&&(y||f<=c)&&([r[l],r[m]]=[r[m],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function nc(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e],i=r[o],u=r[n],s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s];[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++)r[m]<=c&&([r[l],r[m]]=[r[m],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function oc(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,i=r[o].value,u=r[n].value,s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++){let f=r[m].value,p=isNaN(f),y=isNaN(c);!p&&(y||f<=c)&&([r[l],r[m]]=[r[m],r[l]],l++)}if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function ac(r,t){let e=0,n=r.length-1;for(;e<n;){let o=Math.floor((e+n)/2),a=r[e].value,i=r[o].value,u=r[n].value,s;a<=i&&i<=u||u<=i&&i<=a?s=o:i<=a&&a<=u||u<=a&&a<=i?s=e:s=n;let c=r[s].value;[r[s],r[n]]=[r[n],r[s]];let l=e;for(let m=e;m<n;m++)r[m].value<=c&&([r[l],r[m]]=[r[m],r[l]],l++);if([r[l],r[n]]=[r[n],r[l]],l===t)return;l<t?e=l+1:n=l-1}}function fe(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype;if(o===0)return r.copy();let i=e;if(i<0&&(i=o+i),i<0||i>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let u=n[i],s=t;if(s<0&&(s=u+s),s<0||s>=u)throw new Error(`kth(=${t}) out of bounds (${u})`);let c=r.copy(),l=c.data,m=Array.from(n).filter((p,y)=>y!==i),f=m.length===0?1:m.reduce((p,y)=>p*y,1);if(w(a)){let p=l;for(let y=0;y<f;y++){let d=[];for(let g=0;g<u;g++){let h=M(y,i,g,n),A=O(h,n);d.push(p[A])}nc(d,s);for(let g=0;g<u;g++){let h=M(y,i,g,n),A=O(h,n);p[A]=d[g]}}}else for(let p=0;p<f;p++){let y=[];for(let d=0;d<u;d++){let g=M(p,i,d,n),h=O(g,n);y.push(Number(l[h]))}ec(y,s);for(let d=0;d<u;d++){let g=M(p,i,d,n),h=O(g,n);l[h]=y[d]}}return c}function me(r,t,e=-1){let n=r.shape,o=n.length,a=r.dtype,i=r.data;if(o===0)return S.zeros([0],"int32");let u=e;if(u<0&&(u=o+u),u<0||u>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);let s=n[u],c=t;if(c<0&&(c=s+c),c<0||c>=s)throw new Error(`kth(=${t}) out of bounds (${s})`);let l=S.zeros(Array.from(n),"int32"),m=l.data,f=Array.from(n).filter((y,d)=>d!==u),p=f.length===0?1:f.reduce((y,d)=>y*d,1);if(w(a)){let y=i;for(let d=0;d<p;d++){let g=[];for(let h=0;h<s;h++){let A=M(d,u,h,n),b=O(A,n);g.push({value:y[b],idx:h})}ac(g,c);for(let h=0;h<s;h++){let A=M(d,u,h,n),b=O(A,n);m[b]=g[h].idx}}}else for(let y=0;y<p;y++){let d=[];for(let g=0;g<s;g++){let h=M(y,u,g,n),A=O(h,n);d.push({value:Number(i[A]),idx:g})}oc(d,c);for(let g=0;g<s;g++){let h=M(y,u,g,n),A=O(h,n);m[A]=d[g].idx}}return l}function us(r){let t=r.dtype,e=r.size,n=r.data,o=[];for(let u=0;u<e;u++)o.push(Number(n[u]));o.sort((u,s)=>isNaN(u)&&isNaN(s)?0:isNaN(u)?1:isNaN(s)?-1:u-s);let a=S.zeros([e],t),i=a.data;for(let u=0;u<e;u++)i[u]=o[u];return a}function dt(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=[];for(let l=0;l<e;l++)a.push([]);let i=[],u=1;for(let l=e-1;l>=0;l--)i.unshift(u),u*=t[l];for(let l=0;l<o;l++)if(n[l]){let m=l;for(let f=0;f<e;f++){let p=Math.floor(m/i[f]);m=m%i[f],a[f].push(p)}}let s=a[0]?.length??0,c=[];for(let l=0;l<e;l++){let m=S.zeros([s],"int32"),f=m.data;for(let p=0;p<s;p++)f[p]=a[l][p];c.push(m)}return c}function pe(r){let t=r.shape,e=t.length,n=r.data,o=r.size,a=[],i=[],u=1;for(let f=e-1;f>=0;f--)i.unshift(u),u*=t[f];for(let f=0;f<o;f++)if(n[f]){let p=[],y=f;for(let d=0;d<e;d++){let g=Math.floor(y/i[d]);y=y%i[d],p.push(g)}a.push(p)}let s=a.length,c=e===0?[s,1]:[s,e],l=S.zeros(c,"int32"),m=l.data;for(let f=0;f<s;f++){let p=a[f];for(let y=0;y<(e===0?1:e);y++)m[f*(e===0?1:e)+y]=p[y]??0}return l}function cs(r){let t=r.data,e=r.size,n=[];for(let i=0;i<e;i++)t[i]&&n.push(i);let o=S.zeros([n.length],"int32"),a=o.data;for(let i=0;i<n.length;i++)a[i]=n[i];return o}function ls(r,t,e){if(t===void 0&&e===void 0)return dt(r);if(t===void 0||e===void 0)throw new Error("either both or neither of x and y should be given");let n=r.shape,o=t.shape,a=e.shape,i=Math.max(n.length,o.length,a.length),u=B=>{let v=Array(i).fill(1);for(let E=0;E<B.length;E++)v[i-B.length+E]=B[E];return v},s=u(n),c=u(o),l=u(a),m=[];for(let B=0;B<i;B++){let v=[s[B],c[B],l[B]],E=Math.max(...v);for(let U of v)if(U!==1&&U!==E)throw new Error("operands could not be broadcast together");m.push(E)}let f=t.dtype,p=S.zeros(m,f),y=p.data,d=r.data,g=t.data,h=e.data,A=(B,v)=>{let E=[],U=1;for(let $=B.length-1;$>=0;$--)E.unshift(U),U*=B[$];for(;E.length<v.length;)E.unshift(0);for(let $=0;$<v.length;$++)v[$]===1&&m[$]!==1&&(E[$]=0);return E},b=A(n,s),N=A(o,c),D=A(a,l),x=[],z=1;for(let B=m.length-1;B>=0;B--)x.unshift(z),z*=m[B];let _=m.reduce((B,v)=>B*v,1);for(let B=0;B<_;B++){let v=B,E=0,U=0,$=0;for(let q=0;q<i;q++){let J=Math.floor(v/x[q]);v=v%x[q],E+=J*b[q],U+=J*N[q],$+=J*D[q]}d[E]?y[B]=g[U]:y[B]=h[$]}return p}function ye(r,t,e="left"){if(r.ndim!==1)throw new Error("storage must be 1D");let n=r.data,o=r.size,a=t.data,i=t.size,u=S.zeros([i],"int32"),s=u.data;for(let c=0;c<i;c++){let l=Number(a[c]),m=0,f=o;if(e==="left")for(;m<f;){let p=Math.floor((m+f)/2);Number(n[p])<l?m=p+1:f=p}else for(;m<f;){let p=Math.floor((m+f)/2);Number(n[p])<=l?m=p+1:f=p}s[c]=m}return u}function fs(r,t){let e=r.data,n=t.data,o=t.dtype,a=Math.min(r.size,t.size),i=0;for(let l=0;l<a;l++)e[l]&&i++;let u=S.zeros([i],o),s=u.data,c=0;if(w(o)){let l=n,m=s;for(let f=0;f<a;f++)e[f]&&(m[c++]=l[f])}else for(let l=0;l<a;l++)e[l]&&(s[c++]=n[l]);return u}function de(r,t){let e=r.shape,n=e.length,o=r.data,a=r.size;if(t===void 0){let f=0;for(let p=0;p<a;p++)o[p]&&f++;return f}let i=t;if(i<0&&(i=n+i),i<0||i>=n)throw new Error(`axis ${t} is out of bounds for array of dimension ${n}`);let u=Array.from(e).filter((f,p)=>p!==i);if(u.length===0)return de(r);let s=S.zeros(u,"int32"),c=s.data,l=e[i],m=u.reduce((f,p)=>f*p,1);for(let f=0;f<m;f++){let p=0;for(let y=0;y<l;y++){let d=M(f,i,y,e),g=O(d,e);o[g]&&p++}c[f]=p}return s}var ms=k(()=>{"use strict";R();W();Tt()});function ps(r){if(!isFinite(r))return r;let t=Math.floor(r),e=r-t;return Math.abs(e-.5)<1e-10?t%2===0?t:t+1:Math.round(r)}function ge(r,t=0){let e=r.dtype,n=Array.from(r.shape),o=r.data,a=r.size,i=e==="float32"?"float32":"float64",u=S.zeros(n,i),s=u.data,c=Math.pow(10,t);for(let l=0;l<a;l++){let m=Number(o[l]);s[l]=ps(m*c)/c}return u}function be(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=S.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.ceil(Number(n[s]));return i}function Ae(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=S.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.trunc(Number(n[s]));return i}function he(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=S.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.floor(Number(n[s]));return i}function Se(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=S.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=ps(Number(n[s]));return i}function Ne(r){let t=r.dtype,e=Array.from(r.shape),n=r.data,o=r.size,a=t==="float32"?"float32":"float64",i=S.zeros(e,a),u=i.data;for(let s=0;s<o;s++)u[s]=Math.trunc(Number(n[s]));return i}var ys=k(()=>{"use strict";R()});function ir(r,t=!1,e=!1,n=!1){let o=r.dtype,a=r.size,i=r.data,u=[];for(let b=0;b<a;b++)u.push({value:Number(i[b]),index:b});u.sort((b,N)=>isNaN(b.value)&&isNaN(N.value)?0:isNaN(b.value)?1:isNaN(N.value)?-1:b.value-N.value);let s=[],c=[],l=new Array(a),m=[],f,p=0;for(let b=0;b<u.length;b++){let{value:N,index:D}=u[b];f===void 0||isNaN(N)&&!isNaN(f)||!isNaN(N)&&isNaN(f)||!isNaN(N)&&!isNaN(f)&&N!==f?(f!==void 0&&m.push(p),s.push(N),c.push(D),p=1,f=N):p++}p>0&&m.push(p);let y=new Map,d=-1;for(let b=0;b<s.length;b++){let N=s[b];isNaN(N)?d=b:y.set(N,b)}for(let b=0;b<a;b++){let N=Number(i[b]);isNaN(N)?l[b]=d:l[b]=y.get(N)}let g=S.zeros([s.length],o),h=g.data;for(let b=0;b<s.length;b++)h[b]=s[b];if(!t&&!e&&!n)return g;let A={values:g};if(t){let b=S.zeros([c.length],"int32"),N=b.data;for(let D=0;D<c.length;D++)N[D]=c[D];A.indices=b}if(e){let b=S.zeros([l.length],"int32"),N=b.data;for(let D=0;D<l.length;D++)N[D]=l[D];A.inverse=b}if(n){let b=S.zeros([m.length],"int32"),N=b.data;for(let D=0;D<m.length;D++)N[D]=m[D];A.counts=b}return A}function ds(r,t){return De(r,t)}function gs(r,t){let e=r.dtype,n=ir(r),o=ir(t),a=new Set;for(let c=0;c<o.size;c++)a.add(Number(o.data[c]));let i=[];for(let c=0;c<n.size;c++){let l=Number(n.data[c]);a.has(l)&&i.push(l)}i.sort((c,l)=>c-l);let u=S.zeros([i.length],e),s=u.data;for(let c=0;c<i.length;c++)s[c]=i[c];return u}function De(r,t){let e=Array.from(r.shape),n=r.size,o=new Set;for(let s=0;s<t.size;s++)o.add(Number(t.data[s]));let a=S.zeros(e,"bool"),i=a.data,u=r.data;for(let s=0;s<n;s++){let c=Number(u[s]);i[s]=o.has(c)?1:0}return a}function bs(r,t){let e=r.dtype,n=ir(r),o=new Set;for(let s=0;s<t.size;s++)o.add(Number(t.data[s]));let a=[];for(let s=0;s<n.size;s++){let c=Number(n.data[s]);o.has(c)||a.push(c)}let i=S.zeros([a.length],e),u=i.data;for(let s=0;s<a.length;s++)u[s]=a[s];return i}function As(r,t){let e=r.dtype,n=ir(r),o=ir(t),a=new Set,i=new Set;for(let l=0;l<n.size;l++)a.add(Number(n.data[l]));for(let l=0;l<o.size;l++)i.add(Number(o.data[l]));let u=[];for(let l of a)i.has(l)||u.push(l);for(let l of i)a.has(l)||u.push(l);u.sort((l,m)=>l-m);let s=S.zeros([u.length],e),c=s.data;for(let l=0;l<u.length;l++)c[l]=u[l];return s}function hs(r,t){let e=r.dtype,n=ir(r),o=ir(t),a=new Set;for(let c=0;c<n.size;c++)a.add(Number(n.data[c]));for(let c=0;c<o.size;c++)a.add(Number(o.data[c]));let i=Array.from(a);i.sort((c,l)=>c-l);let u=S.zeros([i.length],e),s=u.data;for(let c=0;c<i.length;c++)s[c]=i[c];return u}var Ss=k(()=>{"use strict";R()});function xe(r,t=1,e=-1){if(t<0)throw new Error(`order must be non-negative but got ${t}`);if(t===0)return r.copy();let n=Array.from(r.shape),o=n.length,a=e<0?o+e:e;if(a<0||a>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);if(n[a]<t+1)throw new Error(`diff requires at least ${t+1} elements along axis ${e}, but got ${n[a]}`);let i=r;for(let u=0;u<t;u++)i=cc(i,a);return i}function cc(r,t){let e=Array.from(r.shape),n=e.length,o=e[t],a=[...e];a[t]=o-1;let i=r.dtype,u=w(i)?"float64":i,s=S.zeros(a,u),c=s.data,l=r.strides,m=s.size;for(let f=0;f<m;f++){let p=f,y=new Array(n);for(let D=n-1;D>=0;D--)y[D]=p%a[D],p=Math.floor(p/a[D]);let d=[...y],g=[...y];g[t]=d[t]+1;let h=0,A=0;for(let D=0;D<n;D++)h+=d[D]*l[D],A+=g[D]*l[D];let b=(w(i),Number(r.data[h])),N=(w(i),Number(r.data[A]));c[f]=N-b}return s}function Ns(r,t=null,e=null){let n=r.size,o=r.dtype,a=w(o)?"float64":o,i=Math.max(0,n-1),u=e?e.length:0,s=t?t.length:0,c=u+i+s,l=S.zeros([c],a),m=l.data,f=0;if(e)for(let p of e)m[f++]=p;for(let p=0;p<i;p++){let y=(w(o),Number(r.iget(p))),d=(w(o),Number(r.iget(p+1)));m[f++]=d-y}if(t)for(let p of t)m[f++]=p;return l}function Ds(r,t=1,e=null){let o=Array.from(r.shape).length,a;if(e===null)a=Array.from({length:o},(s,c)=>c);else if(typeof e=="number"){let s=e<0?o+e:e;if(s<0||s>=o)throw new Error(`axis ${e} is out of bounds for array of dimension ${o}`);a=[s]}else a=e.map(s=>{let c=s<0?o+s:s;if(c<0||c>=o)throw new Error(`axis ${s} is out of bounds for array of dimension ${o}`);return c});let i;if(typeof t=="number")i=a.map(()=>t);else{if(t.length!==a.length)throw new Error("Number of spacings must match number of axes");i=t}let u=[];for(let s=0;s<a.length;s++)u.push(lc(r,a[s],i[s]));return u.length===1?u[0]:u}function lc(r,t,e){let n=Array.from(r.shape),o=n.length,a=n[t];if(a<2)throw new Error(`Shape of array along axis ${t} must be at least 2, but got ${a}`);let i=r.dtype,u=w(i)?"float64":i==="float32"?"float32":"float64",s=S.zeros(n,u),c=s.data,l=r.strides,m=e,f=2*m,p=r.size;for(let y=0;y<p;y++){let d=y,g=new Array(o);for(let b=o-1;b>=0;b--)g[b]=d%n[b],d=Math.floor(d/n[b]);let h=g[t],A;if(h===0){let b=[...g];b[t]=1;let N=0;for(let z=0;z<o;z++)N+=b[z]*l[z];let D=(w(i),Number(r.data[y]));A=((w(i),Number(r.data[N]))-D)/m}else if(h===a-1){let b=[...g];b[t]=a-2;let N=0;for(let z=0;z<o;z++)N+=b[z]*l[z];let D=(w(i),Number(r.data[y])),x=(w(i),Number(r.data[N]));A=(D-x)/m}else{let b=[...g],N=[...g];b[t]=h+1,N[t]=h-1;let D=0,x=0;for(let B=0;B<o;B++)D+=b[B]*l[B],x+=N[B]*l[B];let z=(w(i),Number(r.data[D])),_=(w(i),Number(r.data[x]));A=(z-_)/f}c[y]=A}return s}function xs(r,t,e=-1,n=-1,o=-1){let a=Array.from(r.shape),i=Array.from(t.shape),u=a.length,s=i.length,c=e<0?u+e:e,l=n<0?s+n:n;if(c<0||c>=u)throw new Error(`axisa ${e} is out of bounds for array of dimension ${u}`);if(l<0||l>=s)throw new Error(`axisb ${n} is out of bounds for array of dimension ${s}`);let m=a[c],f=i[l];if(m!==2&&m!==3)throw new Error(`incompatible dimensions for cross product (dimension must be 2 or 3, got ${m})`);if(f!==2&&f!==3)throw new Error(`incompatible dimensions for cross product (dimension must be 2 or 3, got ${f})`);let p=C(r.dtype,t.dtype);if(u===1&&s===1&&m===3&&f===3){let y=S.zeros([3],p),d=y.data,g=Number(r.iget(0)),h=Number(r.iget(1)),A=Number(r.iget(2)),b=Number(t.iget(0)),N=Number(t.iget(1)),D=Number(t.iget(2));return d[0]=h*D-A*N,d[1]=A*b-g*D,d[2]=g*N-h*b,y}if(u===1&&s===1&&m===2&&f===2){let y=S.zeros([],p),d=Number(r.iget(0)),g=Number(r.iget(1)),h=Number(t.iget(0)),A=Number(t.iget(1));return y.data[0]=d*A-g*h,y}if(u===1&&s===1){if(m===2&&f===3){let y=S.zeros([3],p),d=y.data,g=Number(r.iget(0)),h=Number(r.iget(1)),A=Number(t.iget(0)),b=Number(t.iget(1)),N=Number(t.iget(2));return d[0]=h*N,d[1]=-g*N,d[2]=g*b-h*A,y}else if(m===3&&f===2){let y=S.zeros([3],p),d=y.data,g=Number(r.iget(0)),h=Number(r.iget(1)),A=Number(r.iget(2)),b=Number(t.iget(0)),N=Number(t.iget(1));return d[0]=-A*N,d[1]=A*b,d[2]=g*N-h*b,y}}if(u===2&&s===2&&c===1&&l===1){let y=a[0];if(i[0]!==y)throw new Error(`Shape mismatch: a has ${y} vectors, b has ${i[0]} vectors`);if(m===3&&f===3){let d=S.zeros([y,3],p),g=d.data;for(let h=0;h<y;h++){let A=Number(r.iget(h*3)),b=Number(r.iget(h*3+1)),N=Number(r.iget(h*3+2)),D=Number(t.iget(h*3)),x=Number(t.iget(h*3+1)),z=Number(t.iget(h*3+2));g[h*3]=b*z-N*x,g[h*3+1]=N*D-A*z,g[h*3+2]=A*x-b*D}return d}if(m===2&&f===2){let d=S.zeros([y],p),g=d.data;for(let h=0;h<y;h++){let A=Number(r.iget(h*2)),b=Number(r.iget(h*2+1)),N=Number(t.iget(h*2)),D=Number(t.iget(h*2+1));g[h]=A*D-b*N}return d}}throw new Error(`cross product not implemented for arrays with shapes ${JSON.stringify(a)} and ${JSON.stringify(i)}`)}var ws=k(()=>{"use strict";R();W()});function zs(r,t,e=0){let n=r.data,o=r.size,a=0;for(let u=0;u<o;u++){let s=Number(n[u]);if(s<0||!Number.isInteger(s))throw new Error("'x' argument must contain non-negative integers");s>a&&(a=s)}let i=Math.max(a+1,e);if(t!==void 0){if(t.size!==o)throw new Error("weights array must have same length as x");let u=t.data,s=new Float64Array(i);for(let c=0;c<o;c++){let l=Number(n[c]);s[l]+=Number(u[c])}return S.fromData(s,[i],"float64")}else{let u=new Float64Array(i);for(let s=0;s<o;s++){let c=Number(n[s]);u[c]++}return S.fromData(u,[i],"float64")}}function Is(r,t,e=!1){let n=r.data,o=t.data,a=r.size,i=t.size,u=new Float64Array(a),s=!0;i>1&&(s=Number(o[1])>=Number(o[0]));for(let c=0;c<a;c++){let l=Number(n[c]),m;if(s)e?m=mc(o,i,l):m=$r(o,i,l);else if(e)for(m=0;m<i&&Number(o[m])>=l;)m++;else for(m=0;m<i&&Number(o[m])>l;)m++;u[c]=m}return S.fromData(u,[...r.shape],"float64")}function mc(r,t,e){let n=0,o=t;for(;n<o;){let a=n+o>>>1;Number(r[a])<e?n=a+1:o=a}return n}function $r(r,t,e){let n=0,o=t;for(;n<o;){let a=n+o>>>1;Number(r[a])<=e?n=a+1:o=a}return n}function _s(r,t=10,e,n=!1,o){let a=r.data,i=r.size,u;if(typeof t=="number"){let m,f;if(e)[m,f]=e;else{m=1/0,f=-1/0;for(let y=0;y<i;y++){let d=Number(a[y]);d<m&&(m=d),d>f&&(f=d)}m===f&&(m=m-.5,f=f+.5)}u=[];let p=(f-m)/t;for(let y=0;y<=t;y++)u.push(m+y*p)}else{let m=t.data;u=[];for(let f=0;f<t.size;f++)u.push(Number(m[f]))}let s=u.length-1,c=new Float64Array(s),l=o?.data;for(let m=0;m<i;m++){let f=Number(a[m]),p=l?Number(l[m]):1,y=$r(u,u.length,f)-1;if(!(y<0)){if(y>=s)if(f===u[s])y=s-1;else continue;c[y]+=p}}if(n){let m=0;for(let f=0;f<s;f++)m+=c[f];for(let f=0;f<s;f++){let p=u[f+1]-u[f];c[f]=c[f]/(m*p)}}return{hist:S.fromData(c,[s],"float64"),bin_edges:S.fromData(new Float64Array(u),[u.length],"float64")}}function Bs(r,t,e=10,n,o=!1,a){let i=r.data,u=t.data,s=r.size;if(t.size!==s)throw new Error("x and y must have the same length");let c,l,m,f;if(typeof e=="number"?(m=e,f=e):Array.isArray(e)&&e.length===2?(e[0],m=e[0],f=e[1]):(m=10,f=10),typeof m=="number"){let h,A;if(n)[h,A]=n[0];else{h=1/0,A=-1/0;for(let N=0;N<s;N++){let D=Number(i[N]);D<h&&(h=D),D>A&&(A=D)}h===A&&(h-=.5,A+=.5)}c=[];let b=(A-h)/m;for(let N=0;N<=m;N++)c.push(h+N*b)}else{let h=m.data;c=[];for(let A=0;A<m.size;A++)c.push(Number(h[A]))}if(typeof f=="number"){let h,A;if(n)[h,A]=n[1];else{h=1/0,A=-1/0;for(let N=0;N<s;N++){let D=Number(u[N]);D<h&&(h=D),D>A&&(A=D)}h===A&&(h-=.5,A+=.5)}l=[];let b=(A-h)/f;for(let N=0;N<=f;N++)l.push(h+N*b)}else{let h=f.data;l=[];for(let A=0;A<f.size;A++)l.push(Number(h[A]))}let p=c.length-1,y=l.length-1,d=new Float64Array(p*y),g=a?.data;for(let h=0;h<s;h++){let A=Number(i[h]),b=Number(u[h]),N=g?Number(g[h]):1,D=$r(c,c.length,A)-1,x=$r(l,l.length,b)-1;if(D<0||D>=p)if(A===c[p]&&D===p)D=p-1;else continue;if(x<0||x>=y)if(b===l[y]&&x===y)x=y-1;else continue;d[D*y+x]+=N}if(o){let h=0;for(let A=0;A<d.length;A++)h+=d[A];for(let A=0;A<p;A++)for(let b=0;b<y;b++){let N=c[A+1]-c[A],D=l[b+1]-l[b],x=N*D;d[A*y+b]=d[A*y+b]/(h*x)}}return{hist:S.fromData(d,[p,y],"float64"),x_edges:S.fromData(new Float64Array(c),[c.length],"float64"),y_edges:S.fromData(new Float64Array(l),[l.length],"float64")}}function vs(r,t=10,e,n=!1,o){let a=r.shape,i=r.data,u,s;if(a.length===1)u=a[0],s=1;else if(a.length===2)u=a[0],s=a[1];else throw new Error("sample must be 1D or 2D array");let c;if(typeof t=="number")c=new Array(s).fill(t);else if(c=t,c.length!==s)throw new Error("bins array length must match number of dimensions");let l=[];for(let h=0;h<s;h++){let A,b;if(e&&e[h])[A,b]=e[h];else{A=1/0,b=-1/0;for(let z=0;z<u;z++){let _=Number(s===1?i[z]:i[z*s+h]);_<A&&(A=_),_>b&&(b=_)}A===b&&(A-=.5,b+=.5)}let N=c[h],D=[],x=(b-A)/N;for(let z=0;z<=N;z++)D.push(A+z*x);l.push(D)}let m=c.slice(),f=m.reduce((h,A)=>h*A,1),p=new Float64Array(f),y=new Array(s);y[s-1]=1;for(let h=s-2;h>=0;h--)y[h]=y[h+1]*c[h+1];let d=o?.data;for(let h=0;h<u;h++){let A=d?Number(d[h]):1,b=0,N=!1;for(let D=0;D<s;D++){let x=Number(s===1?i[h]:i[h*s+D]),z=l[D],_=c[D],B=$r(z,z.length,x)-1;if(B<0||B>=_)if(x===z[_]&&B===_)B=_-1;else{N=!0;break}b+=B*y[D]}N||(p[b]+=A)}if(n){let h=0;for(let b=0;b<f;b++)h+=p[b];let A=new Float64Array(f);for(let b=0;b<f;b++){let N=1,D=b;for(let x=0;x<s;x++){let z=Math.floor(D/y[x])%c[x],_=l[x];N*=_[z+1]-_[z]}A[b]=N}for(let b=0;b<f;b++)p[b]=p[b]/(h*A[b])}let g=l.map(h=>S.fromData(new Float64Array(h),[h.length],"float64"));return{hist:S.fromData(p,m,"float64"),edges:g}}function we(r,t,e="full"){let n=r.data,o=t.data,a=r.size,i=t.size,u=a+i-1,s=new Float64Array(u);for(let c=0;c<u;c++){let l=0,m=c-i+1;for(let f=0;f<a;f++){let p=f-m;p>=0&&p<i&&(l+=Number(n[f])*Number(o[p]))}s[c]=l}if(e==="full")return S.fromData(s,[u],"float64");if(e==="same"){let c=Math.floor((u-a)/2),l=new Float64Array(a);for(let m=0;m<a;m++)l[m]=s[c+m];return S.fromData(l,[a],"float64")}else{let c=Math.max(a,i)-Math.min(a,i)+1,l=Math.min(a,i)-1,m=new Float64Array(c);for(let f=0;f<c;f++)m[f]=s[l+f];return S.fromData(m,[c],"float64")}}function Es(r,t,e="full"){let n=t.data,o=t.size,a=new Float64Array(o);for(let u=0;u<o;u++)a[u]=Number(n[o-1-u]);let i=S.fromData(a,[o],"float64");return we(r,i,e)}function ze(r,t,e=!0,n=!1,o){let a=r.shape,i=r.data,u;if(o!==void 0?u=o:u=n?0:1,a.length===1)if(t!==void 0){let p=t.data,y=r.size;if(t.size!==y)throw new Error("m and y must have same length");let d=0,g=0;for(let D=0;D<y;D++)d+=Number(i[D]),g+=Number(p[D]);d/=y,g/=y;let h=0,A=0,b=0;for(let D=0;D<y;D++){let x=Number(i[D])-d,z=Number(p[D])-g;h+=x*x,A+=z*z,b+=x*z}let N=y-u;return N<=0?S.fromData(new Float64Array([NaN,NaN,NaN,NaN]),[2,2],"float64"):(h/=N,A/=N,b/=N,S.fromData(new Float64Array([h,b,b,A]),[2,2],"float64"))}else{let p=r.size,y=0;for(let h=0;h<p;h++)y+=Number(i[h]);y/=p;let d=0;for(let h=0;h<p;h++){let A=Number(i[h])-y;d+=A*A}let g=p-u;return g<=0?S.fromData(new Float64Array([NaN]),[],"float64"):(d/=g,S.fromData(new Float64Array([d]),[],"float64"))}let s,c;e?(s=a[0],c=a[1]):(s=a[1],c=a[0]);let l=new Float64Array(s);for(let p=0;p<s;p++){let y=0;for(let d=0;d<c;d++){let g=e?p*c+d:d*s+p;y+=Number(i[g])}l[p]=y/c}let m=new Float64Array(s*s),f=c-u;if(f<=0)return m.fill(NaN),S.fromData(m,[s,s],"float64");for(let p=0;p<s;p++)for(let y=p;y<s;y++){let d=0;for(let h=0;h<c;h++){let A=e?p*c+h:h*s+p,b=e?y*c+h:h*s+y,N=Number(i[A])-l[p],D=Number(i[b])-l[y];d+=N*D}let g=d/f;m[p*s+y]=g,m[y*s+p]=g}return S.fromData(m,[s,s],"float64")}function Os(r,t,e=!0){if(r.shape.length===1&&t===void 0)return S.fromData(new Float64Array([1]),[],"float64");let n=ze(r,t,e,!1),o=n.data,i=n.shape[0],u=new Float64Array(i*i);for(let s=0;s<i;s++)for(let c=0;c<i;c++){let l=Number(o[s*i+c]),m=Number(o[s*i+s]),f=Number(o[c*i+c]);m<=0||f<=0?u[s*i+c]=NaN:u[s*i+c]=l/Math.sqrt(m*f)}return S.fromData(u,[i,i],"float64")}var Ms=k(()=>{"use strict";R()});function ur(r,t=j){let e=S.zeros(r,t);return new I(e)}function Ts(r,t=j){let e=S.ones(r,t);return new I(e)}function yc(r){let t=[],e=r;for(;Array.isArray(e);)t.push(e.length),e=e[0];return t}function Us(r){return typeof r=="bigint"?!0:Array.isArray(r)?r.some(t=>Us(t)):!1}function dc(r){let t=[];function e(n){Array.isArray(n)?n.forEach(o=>e(o)):t.push(n)}return e(r),t}function L(r,t){if(r instanceof I)return!t||r.dtype===t?r.copy():r.astype(t);let e=Us(r),n=yc(r),o=n.reduce((l,m)=>l*m,1),a=t;a||(e?a="int64":a=j);let i=T(a);if(!i)throw new Error(`Cannot create array with dtype ${a}`);let u=new i(o),s=dc(r);if(w(a)){let l=u;for(let m=0;m<o;m++){let f=s[m];l[m]=typeof f=="bigint"?f:BigInt(Math.round(Number(f)))}}else if(a==="bool"){let l=u;for(let m=0;m<o;m++)l[m]=s[m]?1:0}else{let l=u;for(let m=0;m<o;m++){let f=s[m];l[m]=Number(f)}}let c=S.fromData(u,n,a);return new I(c)}function gc(r,t,e=1,n=j){let o=r,a=t;if(t===void 0&&(o=0,a=r),a===void 0)throw new Error("stop is required");let i=Math.max(0,Math.ceil((a-o)/e)),u=T(n);if(!u)throw new Error(`Cannot create arange array with dtype ${n}`);let s=new u(i);if(w(n))for(let l=0;l<i;l++)s[l]=BigInt(Math.round(o+l*e));else if(n==="bool")for(let l=0;l<i;l++)s[l]=o+l*e!==0?1:0;else for(let l=0;l<i;l++)s[l]=o+l*e;let c=S.fromData(s,[i],n);return new I(c)}function bc(r,t,e=50,n=j){if(e<0)throw new Error("num must be non-negative");if(e===0)return L([],n);if(e===1)return L([r],n);let o=T(n);if(!o)throw new Error(`Cannot create linspace array with dtype ${n}`);let a=new o(e),i=(t-r)/(e-1);if(w(n))for(let s=0;s<e;s++)a[s]=BigInt(Math.round(r+s*i));else if(n==="bool")for(let s=0;s<e;s++)a[s]=r+s*i!==0?1:0;else for(let s=0;s<e;s++)a[s]=r+s*i;let u=S.fromData(a,[e],n);return new I(u)}function Ac(r,t,e=50,n=10,o=j){if(e<0)throw new Error("num must be non-negative");if(e===0)return L([],o);if(e===1)return L([Math.pow(n,r)],o);let a=T(o);if(!a)throw new Error(`Cannot create logspace array with dtype ${o}`);let i=new a(e),u=(t-r)/(e-1);if(w(o))for(let c=0;c<e;c++){let l=r+c*u;i[c]=BigInt(Math.round(Math.pow(n,l)))}else if(o==="bool")for(let c=0;c<e;c++){let l=r+c*u;i[c]=Math.pow(n,l)!==0?1:0}else for(let c=0;c<e;c++){let l=r+c*u;i[c]=Math.pow(n,l)}let s=S.fromData(i,[e],o);return new I(s)}function hc(r,t,e=50,n=j){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 L([],n);if(e===1)return L([r],n);let o=Math.sign(r),a=Math.sign(t);if(o!==a)throw new Error("Geometric sequence cannot contain both positive and negative values");let i=T(n);if(!i)throw new Error(`Cannot create geomspace array with dtype ${n}`);let u=new i(e),s=Math.log(Math.abs(r)),l=(Math.log(Math.abs(t))-s)/(e-1);if(w(n))for(let f=0;f<e;f++){let p=o*Math.exp(s+f*l);u[f]=BigInt(Math.round(p))}else if(n==="bool")for(let f=0;f<e;f++){let p=o*Math.exp(s+f*l);u[f]=p!==0?1:0}else for(let f=0;f<e;f++){let p=o*Math.exp(s+f*l);u[f]=p}let m=S.fromData(u,[e],n);return new I(m)}function $s(r,t,e=0,n=j){let o=t??r,a=ur([r,o],n),i=a.data;if(w(n)){let u=i;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(u[s*o+c]=BigInt(1))}}else{let u=i;for(let s=0;s<r;s++){let c=s+e;c>=0&&c<o&&(u[s*o+c]=1)}}return a}function ks(r,t=j){return ur(r,t)}function Cs(r,t,e){let n=e;n||(typeof t=="bigint"?n="int64":typeof t=="boolean"?n="bool":Number.isInteger(t)?n="int32":n=j);let o=T(n);if(!o)throw new Error(`Cannot create full array with dtype ${n}`);let a=r.reduce((s,c)=>s*c,1),i=new o(a);if(w(n)){let s=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));i.fill(s)}else n==="bool"?i.fill(t?1:0):i.fill(Number(t));let u=S.fromData(i,r,n);return new I(u)}function Sc(r,t=j){return $s(r,r,0,t)}function gt(r,t){return r instanceof I?!t||r.dtype===t?r:r.astype(t):L(r,t)}function Nc(r){return r.copy()}function Dc(r,t){return ur(Array.from(r.shape),t??r.dtype)}function xc(r,t){return Ts(Array.from(r.shape),t??r.dtype)}function wc(r,t){return ks(Array.from(r.shape),t??r.dtype)}function zc(r,t,e){return Cs(Array.from(r.shape),t,e??r.dtype)}function Ic(r,t){return gt(r,t)}function _c(r,t){let e=gt(r,t);return e.flags.C_CONTIGUOUS?e:e.copy()}function Bc(r,t){return gt(r,t).copy()}function Fs(r,t=0){if(r.ndim===1){let e=r.size,n=e+Math.abs(t),o=ur([n,n],r.dtype);for(let a=0;a<e;a++){let i=t>=0?a:a-t,u=t>=0?a+t:a;o.set([i,u],r.get([a]))}return o}else if(r.ndim===2){let[e,n]=r.shape,o,a,i;if(t>=0?(o=0,a=t,i=Math.min(e,n-t)):(o=-t,a=0,i=Math.min(e+t,n)),i<=0)return ur([0],r.dtype);let u=T(r.dtype),s=new u(i);for(let l=0;l<i;l++){let m=r.get([o+l,a+l]);w(r.dtype)?s[l]=typeof m=="bigint"?m:BigInt(m):s[l]=m}let c=S.fromData(s,[i],r.dtype);return new I(c)}else throw new Error("Input must be 1-D or 2-D")}function vc(r,t=0){let e=r.flatten();return Fs(e,t)}function Ec(r,t,e=j){let n=t.reduce((c,l)=>c*l,1),o=T(e);if(!o)throw new Error(`Cannot create array with dtype ${e}`);let a=new o(n),i=t.length,u=new Array(i).fill(0);for(let c=0;c<n;c++){let l=r(...u);w(e)?a[c]=typeof l=="bigint"?l:BigInt(Number(l)):e==="bool"?a[c]=l?1:0:a[c]=Number(l);for(let m=i-1;m>=0&&(u[m]++,!(u[m]<t[m]));m--)u[m]=0}let s=S.fromData(a,t,e);return new I(s)}function Oc(...r){let t=[],e="xy";for(let u of r)u instanceof I?t.push(u):typeof u=="object"&&"indexing"in u&&(e=u.indexing||"xy");if(t.length===0)return[];if(t.length===1)return[t[0].copy()];let n=t.map(u=>u.size);e==="xy"&&t.length>=2&&(t=[t[1],t[0],...t.slice(2)],[n[0],n[1]]=[n[1],n[0]]);let o=n,a=o.length,i=[];for(let u=0;u<t.length;u++){let s=t[u],c=s.size,l=new Array(a).fill(1);l[u]=c;let m=s.reshape(...l),f=mt(m.storage,o),p=I._fromStorage(f.copy());i.push(p)}return e==="xy"&&i.length>=2&&([i[0],i[1]]=[i[1],i[0]]),i}function Mc(r,t,e=0,n=j){let o=t??r,a=ur([r,o],n);for(let i=0;i<r;i++)for(let u=0;u<=i+e&&u<o;u++)u>=0&&a.set([i,u],1);return a}function Tc(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],i=n.slice(0,-2).reduce((u,s)=>u*s,1);for(let u=0;u<i;u++)for(let s=0;s<o;s++)for(let c=0;c<a;c++)if(c>s+t){let l=[],m=u;for(let f=n.length-3;f>=0;f--)l.unshift(m%n[f]),m=Math.floor(m/n[f]);l.push(s,c),e.set(l,0)}return e}function Uc(r,t=0){if(r.ndim<2)throw new Error("Input must have at least 2 dimensions");let e=r.copy(),n=e.shape,o=n[n.length-2],a=n[n.length-1],i=n.slice(0,-2).reduce((u,s)=>u*s,1);for(let u=0;u<i;u++)for(let s=0;s<o;s++)for(let c=0;c<a;c++)if(c<s+t){let l=[],m=u;for(let f=n.length-3;f>=0;f--)l.unshift(m%n[f]),m=Math.floor(m/n[f]);l.push(s,c),e.set(l,0)}return e}function $c(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=ur([n,o],r.dtype);for(let i=0;i<n;i++){let u=r.get([i]);for(let s=0;s<o;s++){let c=e?s:o-1-s;a.set([i,s],Math.pow(u,c))}}return a}function kc(r,t=j,e=-1,n=0){let o,a=n;r instanceof ArrayBuffer?o=r:(o=r.buffer,a+=r.byteOffset);let i=Pc(t),u=o.byteLength-a,s=Math.floor(u/i),c=e<0?s:Math.min(e,s);if(c<=0)return L([],t);let l=T(t);if(!l)throw new Error(`Unsupported dtype: ${t}`);let m=new l(o,a,c),f=S.fromData(m,[c],t);return new I(f)}function Cc(r,t=j,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return L(n,t)}function Fc(r,t=j,e=-1){let n=[],o=0;for(let a of r){if(e>=0&&o>=e)break;n.push(a),o++}return L(n,t)}function Vc(r,t=j,e=-1,n=""){let o;n===""?o=r.trim().split(/\s+/):o=r.split(n);let a=[],i=0;for(let u of o){if(e>=0&&i>=e)break;let s=u.trim();s!==""&&(w(t)?a.push(BigInt(s)):a.push(parseFloat(s)),i++)}return L(a,t)}function Pc(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 qc(r){return r.sqrt()}function Vs(r,t){return r.power(t)}function jc(r){return r.exp()}function Rc(r){return r.exp2()}function Lc(r){return r.expm1()}function Wc(r){return r.log()}function Gc(r){return r.log2()}function Zc(r){return r.log10()}function Hc(r){return r.log1p()}function Yc(r,t){return r.logaddexp(t)}function Jc(r,t){return r.logaddexp2(t)}function Ps(r){return r.absolute()}function Xc(r){return r.negative()}function Qc(r){return r.sign()}function Kc(r,t){return r.mod(t)}function qs(r,t){return r.divide(t)}function rl(r,t){return r.floor_divide(t)}function tl(r){return r.positive()}function el(r){return r.reciprocal()}function nl(r,t){return r.dot(t)}function ol(r){return r.trace()}function al(r,t=0,e=0,n=1){let o=co(r.storage,t,e,n);return I._fromStorage(o)}function sl(r,t){let e=fo(r.storage,t.storage);return I._fromStorage(e)}function il(r,t){return r.transpose(t)}function ul(r,t){return r.inner(t)}function cl(r,t){return r.outer(t)}function ll(r,t,e=2){return r.tensordot(t,e)}function fl(r){return r.sin()}function ml(r){return r.cos()}function pl(r){return r.tan()}function js(r){return r.arcsin()}function Rs(r){return r.arccos()}function Ls(r){return r.arctan()}function Ws(r,t){return r.arctan2(t)}function yl(r,t){return r.hypot(t)}function dl(r){return r.degrees()}function gl(r){return r.radians()}function bl(r){return r.radians()}function Al(r){return r.degrees()}function hl(r){return r.sinh()}function Sl(r){return r.cosh()}function Nl(r){return r.tanh()}function Gs(r){return r.arcsinh()}function Zs(r){return r.arccosh()}function Hs(r){return r.arctanh()}function Dl(r,t,e){return r.swapaxes(t,e)}function xl(r,t,e){return r.moveaxis(t,e)}function Dr(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=pr(e,t);return I._fromStorage(n)}function wl(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=Fn(e,t);return I._fromStorage(n)}function Ys(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Vn(t);return I._fromStorage(e)}function zl(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Yt(t);return I._fromStorage(e)}function Il(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Pn(t);return I._fromStorage(e)}function _l(r,t,e=0){return qn(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function Bl(r,t,e=0){return Or(r.storage,t,e).map(o=>I._fromStorage(o,r.base??r))}function vl(r,t){return Rn(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function El(r,t){return Ln(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function Ol(r,t){let e=Wn(r.storage,t);return I._fromStorage(e)}function Ml(r,t,e){return r.repeat(t,e)}function Tl(r){return r.ravel()}function Ul(r,t){return r.reshape(...t)}function $l(r,t){return r.squeeze(t)}function kl(r,t){return r.expand_dims(t)}function Ie(r,t){let e=Zn(r.storage,t);return I._fromStorage(e)}function Cl(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Ie(r,1)}function Fl(r){if(r.ndim<2)throw new Error("Input must be at least 2-D");return Ie(r,0)}function Vl(r,t=1,e=[0,1]){let n=Hn(r.storage,t,e);return I._fromStorage(n)}function Pl(r,t,e){let n=Yn(r.storage,t,e);return I._fromStorage(n)}function ql(r,t,e=0){let n=Jn(r.storage,t,e);return I._fromStorage(n,r.base??r)}function jl(...r){let t=r.map(o=>o.storage),n=ro(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function Rl(...r){let t=r.map(o=>o.storage),n=to(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function Ll(...r){let t=r.map(o=>o.storage),n=eo(t).map((o,a)=>o===t[a]?r[a]:I._fromStorage(o));return n.length===1?n[0]:n}function Wl(r,t){return Xn(r.storage,t).map(n=>I._fromStorage(n,r.base??r))}function Gl(r){if(r.length===0)throw new Error("need at least one array to stack");let t=r.map(n=>n.storage),e=Qn(t);return I._fromStorage(e)}function Zl(r){return Ys(r)}function Hl(r,t){let e=Kn(r.storage,t);return I._fromStorage(e)}function Yl(r,t,e){let n=t instanceof I?t:L(t,r.dtype);if(e===void 0){let o=r.flatten(),a=n.flatten();return Dr([o,a])}return Dr([r,n],e)}function Jl(r,t,e){let n=r.dtype;if(e===void 0){let p=r.flatten(),d=(Array.isArray(t)?t:[t]).map(N=>N<0?p.size+N:N),g=[];for(let N=0;N<p.size;N++)d.includes(N)||g.push(N);let h=T(n),A=new h(g.length);for(let N=0;N<g.length;N++){let D=p.get([g[N]]);w(n)?A[N]=typeof D=="bigint"?D:BigInt(D):A[N]=D}let b=S.fromData(A,[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 u=o[i],s=Array.isArray(t)?t:[t],c=new Set(s.map(p=>p<0?u+p:p)),l=[],m=0;for(let p=0;p<=u;p++)(c.has(p)||p===u)&&(p>m&&l.push([m,p]),m=p+1);if(l.length===0){let p=[...o];return p[i]=0,ur(p,n)}let f=[];for(let[p,y]of l){let d=o.map(()=>":");d[i]=`${p}:${y}`,f.push(r.slice(...d))}return Dr(f,i)}function Xl(r,t,e,n){let o=e instanceof I?e:L(e,r.dtype);if(n===void 0){let m=r.flatten(),f=o.flatten(),p=t<0?m.size+t:t;if(p<0||p>m.size)throw new Error(`index ${t} is out of bounds for array of size ${m.size}`);let y=p>0?m.slice(`0:${p}`):null,d=p<m.size?m.slice(`${p}:`):null,g=[];return y&&g.push(y),g.push(f),d&&g.push(d),Dr(g)}let a=r.shape,i=a.length,u=n<0?i+n:n;if(u<0||u>=i)throw new Error(`axis ${n} is out of bounds for array of dimension ${i}`);let s=a[u],c=t<0?s+t:t;if(c<0||c>s)throw new Error(`index ${t} is out of bounds for axis ${n} with size ${s}`);let l=[];if(c>0){let m=a.map(()=>":");m[u]=`0:${c}`,l.push(r.slice(...m))}if(l.push(o),c<s){let m=a.map(()=>":");m[u]=`${c}:`,l.push(r.slice(...m))}return Dr(l,u)}function Ql(r,t,e="constant",n=0){let o=r.shape,a=o.length,i=r.dtype,u;if(typeof t=="number"?u=o.map(()=>[t,t]):Array.isArray(t)&&typeof t[0]=="number"?u=o.map(()=>t):u=t,u.length!==a)throw new Error(`pad_width must have ${a} elements`);let s=o.map((d,g)=>d+u[g][0]+u[g][1]),c=s.reduce((d,g)=>d*g,1),l=T(i),m=new l(c),f=w(i);e==="constant"&&(f?m.fill(BigInt(n)):m.fill(n));let p=new Array(a).fill(0);for(let d=0;d<c;d++){let g=!0,h=[];for(let b=0;b<a;b++){let[N]=u[b],D=p[b]-N;if(D<0||D>=o[b]){g=!1;break}h.push(D)}let A;if(g)A=r.get(h);else if(e==="constant"){for(let b=a-1;b>=0&&(p[b]++,!(p[b]<s[b]));b--)p[b]=0;continue}else{let b=[];for(let N=0;N<a;N++){let[D]=u[N],x=p[N]-D,z=o[N];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)))}A=r.get(b)}f?m[d]=typeof A=="bigint"?A:BigInt(Number(A)):m[d]=Number(A);for(let b=a-1;b>=0&&(p[b]++,!(p[b]<s[b]));b--)p[b]=0}let y=S.fromData(m,s,i);return new I(y)}function Kl(r,t){let e=mt(r.storage,t);return I._fromStorage(e,r.base??r)}function rf(...r){let t=r.map(n=>n.storage);return na(t).map((n,o)=>I._fromStorage(n,r[o].base??r[o]))}function tf(...r){return vt(...r)}function ef(r,t,e){return r.take(t,e)}function nf(r,t,e){r.put(t,e)}function of(r,t,e){if(e!==void 0)throw new Error("copyto with where parameter is not yet implemented");let n=r.storage,o=r.shape,a=r.size,i=r.dtype;if(typeof t=="number"||typeof t=="bigint"){r.fill(t);return}let u=t.storage,s=t.shape,c=or([s,o]);if(!c)throw new Error(`could not broadcast input array from shape (${s.join(",")}) into shape (${o.join(",")})`);if(c.length!==o.length||!c.every((m,f)=>m===o[f]))throw new Error(`could not broadcast input array from shape (${s.join(",")}) into shape (${o.join(",")})`);let l=mt(u,o);if(w(i))for(let m=0;m<a;m++){let f=l.iget(m),p=typeof f=="bigint"?f:BigInt(Math.round(Number(f)));n.iset(m,p)}else if(i==="bool")for(let m=0;m<a;m++){let f=l.iget(m);n.iset(m,f?1:0)}else for(let m=0;m<a;m++){let f=l.iget(m);n.iset(m,Number(f))}}function af(r,t){let e=t.map(o=>o.storage),n=sa(r.storage,e);return I._fromStorage(n)}function sf(r,t,e=!1){return ia(r.storage,t.storage,e)}function uf(r,t){return Mn(r.storage,t.storage)}function Js(r,t){return I._fromStorage(Pt(r.storage,t))}function Xs(r,t){return I._fromStorage(qt(r.storage,t))}function Qs(r,t,e=!1){return r.max(t,e)}function Ks(r,t,e=!1){return r.min(t,e)}function cf(r,t,e=!1){let n=jt(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function lf(r,t,e=!1){let n=Rt(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function ff(r,t,e,n=!1){let o=Lt(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function mf(r,t,e,n=!1){let o=Ar(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function pf(r,t,e,n=!1){let o=e?e.storage:void 0,a=tt(r.storage,t,o,n);return typeof a=="number"?a:I._fromStorage(a)}function yf(r,t,e=!1){let n=et(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function df(r,t,e=!1){let n=nt(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function gf(r,t,e=!1){let n=ot(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function bf(r,t,e=0,n=!1){let o=Br(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function Af(r,t,e=0,n=!1){let o=Wt(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)}function hf(r,t,e=!1){let n=at(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Sf(r,t,e=!1){let n=st(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function Nf(r,t){let e=it(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function Df(r,t){let e=ut(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function xf(r,t){return I._fromStorage(Gt(r.storage,t))}function wf(r,t){return I._fromStorage(Zt(r.storage,t))}function zf(r,t,e=!1){let n=ct(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)}function If(r){return r.cbrt()}function _f(r){return r.fabs()}function Bf(r,t){return r.divmod(t)}function vf(r){return r.square()}function Ef(r,t){return r.remainder(t)}function Of(r,t){return r.heaviside(t)}function Mf(r,t){let e=typeof t=="number"?t:t.storage;return I._fromStorage(bn(r.storage,e))}function Tf(r,t){let e=typeof t=="number"?t:t.storage;return I._fromStorage(An(r.storage,e))}function Uf(r){let[t,e]=hn(r.storage);return[I._fromStorage(t),I._fromStorage(e)]}function $f(r,t){let e=typeof t=="number"?t:t.storage;return I._fromStorage(Sn(r.storage,e))}function kf(r,t){let e=typeof t=="number"?t:t.storage;return I._fromStorage(Nn(r.storage,e))}function Cf(r,t){let e=typeof t=="number"?t:t.storage;return I._fromStorage(Dn(r.storage,e))}function Ff(r){let[t,e]=xn(r.storage);return[I._fromStorage(t),I._fromStorage(e)]}function Vf(r,t){return r.bitwise_and(t)}function Pf(r,t){return r.bitwise_or(t)}function qf(r,t){return r.bitwise_xor(t)}function jf(r){return r.bitwise_not()}function Rf(r){return r.invert()}function Lf(r,t){return r.left_shift(t)}function Wf(r,t){return r.right_shift(t)}function Gf(r,t=-1,e="big"){let n=Ma(r.storage,t,e);return I._fromStorage(n)}function Zf(r,t=-1,e=-1,n="big"){let o=Ta(r.storage,t,e,n);return I._fromStorage(o)}function Hf(r,t){return r.logical_and(t)}function Yf(r,t){return r.logical_or(t)}function Jf(r){return r.logical_not()}function Xf(r,t){return r.logical_xor(t)}function Qf(r){return r.isfinite()}function Kf(r){return r.isinf()}function rm(r){return r.isnan()}function tm(r){return r.isnat()}function em(r,t){return r.copysign(t)}function nm(r){return r.signbit()}function om(r,t){return r.nextafter(t)}function am(r){return r.spacing()}function sm(r){return I._fromStorage(Ha(r.storage))}function im(r){return Ya(r.storage)}function um(r){return I._fromStorage(Ja(r.storage))}function cm(r){return Xa(r.storage)}function lm(r){return I._fromStorage(Qa(r.storage))}function fm(r){return I._fromStorage(Ka(r.storage))}function mm(r){return rs(r.storage)}function pm(r,t=100){return I._fromStorage(ts(r.storage,t))}function ym(r){return es(r)}function dm(r){return ns(r)}function gm(r,t){return os(r,t)}function bm(r,t){return as(r,t)}function Am(r,...t){let e=t.map(o=>o.storage),n=lo(r,...e);return typeof n=="number"||typeof n=="bigint"?n:I._fromStorage(n)}function Sm(r,t,e){return I._fromStorage(ua(r.storage,t.storage,e))}function Nm(r,t,e,n){ca(r.storage,t.storage,e.storage,n)}function Dm(r,t,e){let n=e instanceof I?e.storage:e;la(r.storage,t.storage,n)}function xm(r,t,e){return I._fromStorage(fa(r.storage,t.storage,e))}function wm(r,t,e=0){let n=r.map(a=>a.storage),o=t.map(a=>a.storage);return I._fromStorage(ma(n,o,e))}function zm(r,t,e){pa(r.storage,t.storage,e.storage)}function Im(r,t,e=!1){let n=typeof t=="number"?t:t.storage;Da(r.storage,n,e)}function _m(r,t=2){return ae(r,t).map(n=>I._fromStorage(n))}function Bm(r){return ya(r.storage).map(e=>I._fromStorage(e))}function vm(r,t=0,e){return se(r,t,e).map(o=>I._fromStorage(o))}function Em(r,t=0){return da(r.storage,t).map(n=>I._fromStorage(n))}function Om(r,t=0,e){return ie(r,t,e).map(o=>I._fromStorage(o))}function Mm(r,t=0){return ga(r.storage,t).map(n=>I._fromStorage(n))}function Tm(r,t,e=0){return ba(r,(a,i)=>t(a,i).storage,e).map(a=>I._fromStorage(a))}function Um(r,t="int32"){return I._fromStorage(Aa(r,t))}function $m(...r){return ha(...r.map(e=>e.storage)).map(e=>I._fromStorage(e))}function km(r,t,e="raise"){let n=r.map(o=>o.storage);return I._fromStorage(Sa(n,t,e))}function Cm(r,t,e="C"){let n=r instanceof I?r.storage:r;return Na(n,t,e).map(a=>I._fromStorage(a))}function Fm(r,t=-1){return I._fromStorage(ce(r.storage,t))}function Vm(r,t=-1){return I._fromStorage(le(r.storage,t))}function Pm(r){let t=r.map(e=>e.storage);return I._fromStorage(is(t))}function qm(r,t,e=-1){return I._fromStorage(fe(r.storage,t,e))}function jm(r,t,e=-1){return I._fromStorage(me(r.storage,t,e))}function Rm(r){return I._fromStorage(us(r.storage))}function Lm(r){return dt(r.storage).map(e=>I._fromStorage(e))}function Wm(r){return I._fromStorage(pe(r.storage))}function Gm(r){return I._fromStorage(cs(r.storage))}function Zm(r,t,e){let n=ls(r.storage,t?.storage,e?.storage);return Array.isArray(n)?n.map(o=>I._fromStorage(o)):I._fromStorage(n)}function Hm(r,t,e="left"){return I._fromStorage(ye(r.storage,t.storage,e))}function Ym(r,t){return I._fromStorage(fs(r.storage,t.storage))}function Jm(r,t){let e=de(r.storage,t);return typeof e=="number"?e:I._fromStorage(e)}function _e(r,t=0){return I._fromStorage(ge(r.storage,t))}function Xm(r){return I._fromStorage(be(r.storage))}function Qm(r){return I._fromStorage(Ae(r.storage))}function Km(r){return I._fromStorage(he(r.storage))}function rp(r){return I._fromStorage(Se(r.storage))}function tp(r){return I._fromStorage(Ne(r.storage))}function ep(r,t=!1,e=!1,n=!1){let o=ir(r.storage,t,e,n);if(o instanceof S)return I._fromStorage(o);let a={values:I._fromStorage(o.values)};return o.indices&&(a.indices=I._fromStorage(o.indices)),o.inverse&&(a.inverse=I._fromStorage(o.inverse)),o.counts&&(a.counts=I._fromStorage(o.counts)),a}function np(r,t){return I._fromStorage(ds(r.storage,t.storage))}function op(r,t){return I._fromStorage(gs(r.storage,t.storage))}function ap(r,t){return I._fromStorage(De(r.storage,t.storage))}function sp(r,t){return I._fromStorage(bs(r.storage,t.storage))}function ip(r,t){return I._fromStorage(As(r.storage,t.storage))}function up(r,t){return I._fromStorage(hs(r.storage,t.storage))}function cp(r,t=1,e=-1){return I._fromStorage(xe(r.storage,t,e))}function lp(r,t=null,e=null){return I._fromStorage(Ns(r.storage,t,e))}function fp(r,t=1,e=null){let n=Ds(r.storage,t,e);return Array.isArray(n)?n.map(o=>I._fromStorage(o)):I._fromStorage(n)}function mp(r,t,e=-1,n=-1,o=-1){return I._fromStorage(xs(r.storage,t.storage,e,n,o))}function pp(r,t,e=0){return I._fromStorage(zs(r.storage,t?.storage,e))}function yp(r,t,e=!1){return I._fromStorage(Is(r.storage,t.storage,e))}function dp(r,t=10,e,n=!1,o){let a=_s(r.storage,typeof t=="number"?t:t.storage,e,n,o?.storage);return[I._fromStorage(a.hist),I._fromStorage(a.bin_edges)]}function gp(r,t,e=10,n,o=!1,a){let i;typeof e=="number"?i=e:Array.isArray(e)&&e.length===2?typeof e[0]=="number"?i=e:i=[e[0].storage,e[1].storage]:i=10;let u=Bs(r.storage,t.storage,i,n,o,a?.storage);return[I._fromStorage(u.hist),I._fromStorage(u.x_edges),I._fromStorage(u.y_edges)]}function bp(r,t=10,e,n=!1,o){let a=vs(r.storage,t,e,n,o?.storage);return[I._fromStorage(a.hist),a.edges.map(i=>I._fromStorage(i))]}function Ap(r,t,e="full"){return I._fromStorage(we(r.storage,t.storage,e))}function hp(r,t,e="full"){return I._fromStorage(Es(r.storage,t.storage,e))}function Sp(r,t,e=!0,n=!1,o){return I._fromStorage(ze(r.storage,t?.storage,e,n,o))}function Np(r,t,e=!0){return I._fromStorage(Os(r.storage,t?.storage,e))}var I,hm,kr=k(()=>{"use strict";Qe();W();R();Yr();wn();Tn();$n();Jt();Io();Fo();Yo();ea();xa();Ua();ss();ms();ys();Ss();ws();Ms();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(){return this.transpose()}get itemsize(){return Hr(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){let e=this._storage.dtype,n=this.size;if(w(e)){let o=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let a=0;a<n;a++)this._storage.iset(a,o)}else if(e==="bool"){let o=t?1:0;for(let a=0;a<n;a++)this._storage.iset(a,o)}else{let o=Number(t);for(let a=0;a<n;a++)this._storage.iset(a,o)}}*[Symbol.iterator](){if(this.ndim===0)yield this._storage.iget(0);else if(this.ndim===1)for(let t=0;t<this.shape[0];t++)yield this._storage.iget(t);else for(let t=0;t<this.shape[0];t++)yield this.slice(String(t))}get(t){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let e=t.map((n,o)=>{let a=n;if(a<0&&(a=this.shape[o]+a),a<0||a>=this.shape[o])throw new Error(`Index ${n} is out of bounds for axis ${o} with size ${this.shape[o]}`);return a});return this._storage.get(...e)}set(t,e){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);let n=t.map((i,u)=>{let s=i;if(s<0&&(s=this.shape[u]+s),s<0||s>=this.shape[u])throw new Error(`Index ${i} is out of bounds for axis ${u} with size ${this.shape[u]}`);return s}),o=this.dtype,a;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,i=T(t);if(!i)throw new Error(`Cannot convert to dtype ${t}`);let u=new i(a),s=this.data;if(w(n)&&!w(t)){let l=s;if(t==="bool")for(let m=0;m<a;m++)u[m]=l[m]!==BigInt(0)?1:0;else for(let m=0;m<a;m++)u[m]=Number(l[m])}else if(!w(n)&&w(t)){let l=s;for(let m=0;m<a;m++)u[m]=BigInt(Math.round(Number(l[m])))}else if(t==="bool"){let l=s;for(let m=0;m<a;m++)u[m]=l[m]!==0?1:0}else if(n==="bool"&&!w(t)){let l=s;for(let m=0;m<a;m++)u[m]=l[m]}else if(!w(n)&&!w(t)){let l=s;for(let m=0;m<a;m++)u[m]=l[m]}else{let l=s;for(let m=0;m<a;m++)u[m]=l[m]}let c=S.fromData(u,o,t);return new r(c)}add(t){let e=typeof t=="number"?t:t._storage,n=tn(this._storage,e);return r._fromStorage(n)}subtract(t){let e=typeof t=="number"?t:t._storage,n=en(this._storage,e);return r._fromStorage(n)}multiply(t){let e=typeof t=="number"?t:t._storage,n=nn(this._storage,e);return r._fromStorage(n)}divide(t){let e=typeof t=="number"?t:t._storage,n=on(this._storage,e);return r._fromStorage(n)}mod(t){let e=typeof t=="number"?t:t._storage,n=Xr(this._storage,e);return r._fromStorage(n)}floor_divide(t){let e=typeof t=="number"?t:t._storage,n=Ot(this._storage,e);return r._fromStorage(n)}positive(){let t=cn(this._storage);return r._fromStorage(t)}reciprocal(){let t=ln(this._storage);return r._fromStorage(t)}sqrt(){let t=_o(this._storage);return r._fromStorage(t)}power(t){let e=typeof t=="number"?t:t._storage,n=Bo(this._storage,e);return r._fromStorage(n)}exp(){let t=vo(this._storage);return r._fromStorage(t)}exp2(){let t=Eo(this._storage);return r._fromStorage(t)}expm1(){let t=Oo(this._storage);return r._fromStorage(t)}log(){let t=Mo(this._storage);return r._fromStorage(t)}log2(){let t=To(this._storage);return r._fromStorage(t)}log10(){let t=Uo(this._storage);return r._fromStorage(t)}log1p(){let t=$o(this._storage);return r._fromStorage(t)}logaddexp(t){let e=typeof t=="number"?t:t._storage,n=ko(this._storage,e);return r._fromStorage(n)}logaddexp2(t){let e=typeof t=="number"?t:t._storage,n=Co(this._storage,e);return r._fromStorage(n)}absolute(){let t=an(this._storage);return r._fromStorage(t)}negative(){let t=sn(this._storage);return r._fromStorage(t)}sign(){let t=un(this._storage);return r._fromStorage(t)}around(t=0){let e=ge(this._storage,t);return r._fromStorage(e)}round(t=0){return this.around(t)}ceil(){let t=be(this._storage);return r._fromStorage(t)}fix(){let t=Ae(this._storage);return r._fromStorage(t)}floor(){let t=he(this._storage);return r._fromStorage(t)}rint(){let t=Se(this._storage);return r._fromStorage(t)}trunc(){let t=Ne(this._storage);return r._fromStorage(t)}sin(){let t=Vo(this._storage);return r._fromStorage(t)}cos(){let t=Po(this._storage);return r._fromStorage(t)}tan(){let t=qo(this._storage);return r._fromStorage(t)}arcsin(){let t=jo(this._storage);return r._fromStorage(t)}arccos(){let t=Ro(this._storage);return r._fromStorage(t)}arctan(){let t=Lo(this._storage);return r._fromStorage(t)}arctan2(t){let e=typeof t=="number"?t:t._storage,n=Wo(this._storage,e);return r._fromStorage(n)}hypot(t){let e=typeof t=="number"?t:t._storage,n=Go(this._storage,e);return r._fromStorage(n)}degrees(){let t=Zo(this._storage);return r._fromStorage(t)}radians(){let t=Ho(this._storage);return r._fromStorage(t)}sinh(){let t=Jo(this._storage);return r._fromStorage(t)}cosh(){let t=Xo(this._storage);return r._fromStorage(t)}tanh(){let t=Qo(this._storage);return r._fromStorage(t)}arcsinh(){let t=Ko(this._storage);return r._fromStorage(t)}arccosh(){let t=ra(this._storage);return r._fromStorage(t)}arctanh(){let t=ta(this._storage);return r._fromStorage(t)}greater(t){let e=typeof t=="number"?t:t._storage,n=zn(this._storage,e);return r._fromStorage(n)}greater_equal(t){let e=typeof t=="number"?t:t._storage,n=In(this._storage,e);return r._fromStorage(n)}less(t){let e=typeof t=="number"?t:t._storage,n=_n(this._storage,e);return r._fromStorage(n)}less_equal(t){let e=typeof t=="number"?t:t._storage,n=Bn(this._storage,e);return r._fromStorage(n)}equal(t){let e=typeof t=="number"?t:t._storage,n=vn(this._storage,e);return r._fromStorage(n)}not_equal(t){let e=typeof t=="number"?t:t._storage,n=En(this._storage,e);return r._fromStorage(n)}isclose(t,e=1e-5,n=1e-8){let o=typeof t=="number"?t:t._storage,a=Mt(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 On(this._storage,o,e,n)}bitwise_and(t){let e=typeof t=="number"?t:t._storage,n=Ia(this._storage,e);return r._fromStorage(n)}bitwise_or(t){let e=typeof t=="number"?t:t._storage,n=_a(this._storage,e);return r._fromStorage(n)}bitwise_xor(t){let e=typeof t=="number"?t:t._storage,n=Ba(this._storage,e);return r._fromStorage(n)}bitwise_not(){let t=ue(this._storage);return r._fromStorage(t)}invert(){let t=va(this._storage);return r._fromStorage(t)}left_shift(t){let e=typeof t=="number"?t:t._storage,n=Ea(this._storage,e);return r._fromStorage(n)}right_shift(t){let e=typeof t=="number"?t:t._storage,n=Oa(this._storage,e);return r._fromStorage(n)}logical_and(t){let e=typeof t=="number"?t:t._storage,n=ka(this._storage,e);return r._fromStorage(n)}logical_or(t){let e=typeof t=="number"?t:t._storage,n=Ca(this._storage,e);return r._fromStorage(n)}logical_not(){let t=Fa(this._storage);return r._fromStorage(t)}logical_xor(t){let e=typeof t=="number"?t:t._storage,n=Va(this._storage,e);return r._fromStorage(n)}isfinite(){let t=Pa(this._storage);return r._fromStorage(t)}isinf(){let t=qa(this._storage);return r._fromStorage(t)}isnan(){let t=ja(this._storage);return r._fromStorage(t)}isnat(){let t=Ra(this._storage);return r._fromStorage(t)}copysign(t){let e=typeof t=="number"?t:t._storage,n=La(this._storage,e);return r._fromStorage(n)}signbit(){let t=Wa(this._storage);return r._fromStorage(t)}nextafter(t){let e=typeof t=="number"?t:t._storage,n=Ga(this._storage,e);return r._fromStorage(n)}spacing(){let t=Za(this._storage);return r._fromStorage(t)}sum(t,e=!1){let n=_r(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}mean(t,e=!1){let n=Qr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}max(t,e=!1){let n=Kr(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}min(t,e=!1){let n=rt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}prod(t,e=!1){let n=Ut(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}argmin(t){let e=$t(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}argmax(t){let e=kt(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}var(t,e=0,n=!1){let o=Ct(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}std(t,e=0,n=!1){let o=Un(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}all(t,e=!1){let n=Ft(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}any(t,e=!1){let n=Vt(this._storage,t,e);return typeof n=="boolean"?n:r._fromStorage(n)}cumsum(t){return r._fromStorage(Pt(this._storage,t))}cumprod(t){return r._fromStorage(qt(this._storage,t))}ptp(t,e=!1){let n=jt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}median(t,e=!1){let n=Rt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}percentile(t,e,n=!1){let o=Lt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}quantile(t,e,n=!1){let o=Ar(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}average(t,e){let n=tt(this._storage,e,t?.storage);return typeof n=="number"?n:r._fromStorage(n)}nansum(t,e=!1){let n=et(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanprod(t,e=!1){let n=nt(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmean(t,e=!1){let n=ot(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanvar(t,e=0,n=!1){let o=Br(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanstd(t,e=0,n=!1){let o=Wt(this._storage,t,e,n);return typeof o=="number"?o:r._fromStorage(o)}nanmin(t,e=!1){let n=at(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanmax(t,e=!1){let n=st(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}nanargmin(t){let e=it(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nanargmax(t){let e=ut(this._storage,t);return typeof e=="number"?e:r._fromStorage(e)}nancumsum(t){return r._fromStorage(Gt(this._storage,t))}nancumprod(t){return r._fromStorage(Zt(this._storage,t))}nanmedian(t,e=!1){let n=ct(this._storage,t,e);return typeof n=="number"?n:r._fromStorage(n)}sort(t=-1){return r._fromStorage(ce(this._storage,t))}argsort(t=-1){return r._fromStorage(le(this._storage,t))}partition(t,e=-1){return r._fromStorage(fe(this._storage,t,e))}argpartition(t,e=-1){return r._fromStorage(me(this._storage,t,e))}nonzero(){return dt(this._storage).map(e=>r._fromStorage(e))}argwhere(){return r._fromStorage(pe(this._storage))}searchsorted(t,e="left"){return r._fromStorage(ye(this._storage,t._storage,e))}diff(t=1,e=-1){return r._fromStorage(xe(this._storage,t,e))}reshape(...t){let e=t.length===1&&Array.isArray(t[0])?t[0]:t,n=G(this._storage,e),a=n.data===this.data?this._base??this:void 0;return r._fromStorage(n,a)}flatten(){let t=lt(this._storage);return r._fromStorage(t)}ravel(){let t=hr(this._storage),n=t.data===this.data?this._base??this:void 0;return r._fromStorage(t,n)}transpose(t){let e=Er(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}squeeze(t){let e=kn(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}expand_dims(t){let e=vr(this._storage,t),n=this._base??this;return r._fromStorage(e,n)}swapaxes(t,e){let n=Cn(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}moveaxis(t,e){let n=Ht(this._storage,t,e),o=this._base??this;return r._fromStorage(n,o)}repeat(t,e){let n=Gn(this._storage,t,e);return r._fromStorage(n)}take(t,e){let n=oa(this._storage,t,e);return r._fromStorage(n)}put(t,e){let n=e instanceof r?e._storage:e;aa(this._storage,t,n)}matmul(t){let e=rr(this._storage,t._storage);return r._fromStorage(e)}dot(t){let e=Qt(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}trace(){return so(this._storage)}inner(t){let e=io(this._storage,t._storage);return typeof e=="number"||typeof e=="bigint"?e:r._fromStorage(e)}outer(t){let e=Kt(this._storage,t._storage);return r._fromStorage(e)}tensordot(t,e=2){let n=uo(this._storage,t._storage,e);return typeof n=="number"||typeof n=="bigint"?n:r._fromStorage(n)}cbrt(){let t=fn(this._storage);return r._fromStorage(t)}fabs(){let t=mn(this._storage);return r._fromStorage(t)}divmod(t){let e=typeof t=="number"?t:t._storage,[n,o]=pn(this._storage,e);return[r._fromStorage(n),r._fromStorage(o)]}square(){let t=yn(this._storage);return r._fromStorage(t)}remainder(t){let e=typeof t=="number"?t:t._storage,n=dn(this._storage,e);return r._fromStorage(n)}heaviside(t){let e=typeof t=="number"?t:t._storage,n=gn(this._storage,e);return r._fromStorage(n)}slice(...t){if(t.length===0)return this;if(t.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${t.length} were indexed`);let e=t.map((s,c)=>{let l=Je(s);return Xe(l,this.shape[c])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});let n=[],o=[],a=this._storage.offset;for(let s=0;s<e.length;s++){let c=e[s],l=this._storage.strides[s];if(a+=c.start*l,!c.isIndex){let m;c.step>0?m=Math.max(0,Math.ceil((c.stop-c.start)/c.step)):m=Math.max(0,Math.ceil((c.start-c.stop)/Math.abs(c.step))),n.push(m),o.push(l*c.step)}}let i=S.fromData(this._storage.data,n,this._storage.dtype,o,a),u=this._base??this;return new r(i,u)}row(t){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(t),":")}col(t){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(t))}rows(t,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${t}:${e}`,":")}cols(t,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${t}:${e}`)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);let t=this.shape,e=t.length,n=(o,a)=>{if(a===e)return this._storage.get(...o);let i=[];for(let u=0;u<t[a];u++)o[a]=u,i.push(n(o,a+1));return i};return n(new Array(e),0)}};hm={cross:(r,t,e=-1,n=-1,o=-1,a)=>{let i=mo(r.storage,t.storage,e,n,o,a);return typeof i=="number"?i:I._fromStorage(i)},norm:(r,t=null,e=null,n=!1)=>{let o=po(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)},vector_norm:(r,t=2,e,n=!1)=>{let o=Sr(r.storage,t,e,n);return typeof o=="number"?o:I._fromStorage(o)},matrix_norm:(r,t="fro",e=!1)=>{let n=yr(r.storage,t,e);return typeof n=="number"?n:I._fromStorage(n)},qr:(r,t="reduced")=>{let e=re(r.storage,t);return e instanceof S?I._fromStorage(e):"q"in e&&"r"in e?{q:I._fromStorage(e.q),r:I._fromStorage(e.r)}:{h:I._fromStorage(e.h),tau:I._fromStorage(e.tau)}},cholesky:(r,t=!1)=>I._fromStorage(yo(r.storage,t)),svd:(r,t=!0,e=!0)=>{let n=go(r.storage,t,e);return"u"in n?{u:I._fromStorage(n.u),s:I._fromStorage(n.s),vt:I._fromStorage(n.vt)}:I._fromStorage(n)},det:r=>bo(r.storage),inv:r=>I._fromStorage(ft(r.storage)),solve:(r,t)=>I._fromStorage(Ao(r.storage,t.storage)),lstsq:(r,t,e=null)=>{let n=ho(r.storage,t.storage,e);return{x:I._fromStorage(n.x),residuals:I._fromStorage(n.residuals),rank:n.rank,s:I._fromStorage(n.s)}},cond:(r,t=2)=>So(r.storage,t),matrix_rank:(r,t)=>No(r.storage,t),matrix_power:(r,t)=>I._fromStorage(Do(r.storage,t)),pinv:(r,t=1e-15)=>I._fromStorage(xo(r.storage,t)),eig:r=>{let t=ne(r.storage);return{w:I._fromStorage(t.w),v:I._fromStorage(t.v)}},eigh:(r,t="L")=>{let e=oe(r.storage,t);return{w:I._fromStorage(e.w),v:I._fromStorage(e.v)}},eigvals:r=>I._fromStorage(wo(r.storage)),eigvalsh:(r,t="L")=>I._fromStorage(zo(r.storage,t))}});function ve(){let r=new ArrayBuffer(2);return new DataView(r).setInt16(0,256,!0),new Int16Array(r)[0]===256}function ti(r){if(r.startsWith("[")||r.startsWith("("))throw new cr(`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 ri)throw new cr(`Unsupported dtype: ${ri[n]} (${r}). Use the 'force' parameter to skip arrays with unsupported dtypes.`);let o=Dp[e];if(!o)throw new cr(`Unknown or unsupported dtype descriptor: ${r}. Supported types: ${Be.join(", ")}. Use the 'force' parameter to skip arrays with unsupported dtypes.`);let a=ve(),i=t==="<"||t==="|"||t==="="&&a,u=t===">"||t==="="&&!a,s=parseInt(e.slice(1),10),c=s>1&&(u&&a||i&&!a);return{dtype:o,needsByteSwap:c,itemsize:s}}var Cr,Be,Dp,bt,ri,cr,X,Fr=k(()=>{"use strict";Cr=new Uint8Array([147,78,85,77,80,89]),Be=["float64","float32","int64","int32","int16","int8","uint64","uint32","uint16","uint8","bool"];Dp={f8:"float64",f4:"float32",i8:"int64",i4:"int32",i2:"int16",i1:"int8",u8:"uint64",u4:"uint32",u2:"uint16",u1:"uint8",b1:"bool"},bt={float64:"<f8",float32:"<f4",int64:"<i8",int32:"<i4",int16:"<i2",int8:"|i1",uint64:"<u8",uint32:"<u4",uint16:"<u2",uint8:"|u1",bool:"|b1"},ri={c:"complex numbers",S:"byte strings",U:"Unicode strings",O:"Python objects",V:"structured arrays (void)",M:"datetime64",m:"timedelta64"};cr=class extends Error{constructor(t){super(t),this.name="UnsupportedDTypeError"}},X=class extends Error{constructor(t){super(t),this.name="InvalidNpyError"}}});function dr(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=Ee(t);return Oe(t,e)}function Ee(r){if(r.length<10)throw new X("File too small to be a valid NPY file");for(let c=0;c<Cr.length;c++)if(r[c]!==Cr[c])throw new X("Invalid NPY magic number");let t=r[6],e=r[7];if(t!==1&&t!==2&&t!==3)throw new X(`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 X("File truncated: header extends beyond file");let i=r.slice(o,a),u=new TextDecoder("utf-8").decode(i).trim(),s=xp(u);return{version:{major:t,minor:e},header:s,dataOffset:a}}function Oe(r,t){let{header:e,dataOffset:n}=t,{dtype:o,needsByteSwap:a,itemsize:i}=ti(e.descr),u=e.shape.reduce((d,g)=>d*g,1),s=u*i,c=r.length-n;if(c<s)throw new X(`File truncated: expected ${s} bytes of data, got ${c}`);let l=new ArrayBuffer(s);new Uint8Array(l).set(r.subarray(n,n+s));let f=wp(l,o,u,a,i),p=e.shape,y;if(e.fortran_order&&p.length>1){let d=[...p].reverse(),g=S.fromData(f,d,o);y=zp(g,d),p=e.shape}else y=S.fromData(f,[...p],o);return new I(y)}function xp(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 X(`Failed to parse NPY header: ${r}`);let o=t[1],a=e[1]==="True",i=n[1].trim(),u;return i===""?u=[]:u=i.split(",").map(s=>s.trim()).filter(s=>s!=="").map(s=>{let c=parseInt(s,10);if(isNaN(c))throw new X(`Invalid shape value: ${s}`);return c}),{descr:o,fortran_order:a,shape:u}}function wp(r,t,e,n,o){let a=T(t);if(!a)throw new X(`Cannot create array for dtype: ${t}`);if(!n)return new a(r,0,e);let i=new Uint8Array(r),u=new Uint8Array(r.byteLength);for(let s=0;s<e;s++){let c=s*o;for(let l=0;l<o;l++)u[c+l]=i[c+o-1-l]}return new a(u.buffer,0,e)}function zp(r,t){let e=t.length,n=r.size,o=r.dtype,a=T(o);if(!a)throw new X(`Cannot create array for dtype: ${o}`);let i=new a(n),u=[...t].reverse(),s=ei(t),c=ei(u),l=new Array(e).fill(0);for(let m=0;m<n;m++){let f=m;for(let y=0;y<e;y++){let d=s[y];l[y]=Math.floor(f/d),f=f%d}let p=0;for(let y=0;y<e;y++)p+=l[e-1-y]*c[y];w(o),i[p]=r.iget(m)}return S.fromData(i,u,o)}function ei(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 At=k(()=>{"use strict";kr();R();W();Fr()});function mr(r){let t=r.shape,e=r.dtype,n=bt[e],o=t.length===0?"()":t.length===1?`(${t[0]},)`:`(${t.join(", ")})`,a=`{'descr': '${n}', 'fortran_order': False, 'shape': ${o}, }`,i=12,s=(64-(i+a.length+1)%64)%64;a=a+" ".repeat(s)+`
|
|
2
|
+
`;let c=new TextEncoder().encode(a),l=c.length,m=r.size,f=Hr(e),p=m*f,y=i+l+p,d=new Uint8Array(y);d.set(Cr,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 Ip(r,d.subarray(g),f),d}function Ip(r,t,e){let n=r.dtype,o=r.size,a=ve(),i=w(n),u=r._storage;if(u.isCContiguous&&u.offset===0&&a){let c=u.data,l=new Uint8Array(c.buffer,c.byteOffset,o*e);t.set(l)}else{let c=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let l=0;l<o;l++){let m=u.iget(l),f=l*e;i?_p(c,f,m,n==="uint64"):Bp(c,f,m,n)}}}function _p(r,t,e,n){n?r.setBigUint64(t,e,!0):r.setBigInt64(t,e,!0)}function Bp(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 ht=k(()=>{"use strict";W();Fr()});function Me(r){let t=4294967295;for(let e=0;e<r.length;e++)t=vp[(t^r[e])&255]^t>>>8;return(t^4294967295)>>>0}var vp,Te=k(()=>{"use strict";vp=(()=>{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 ni(r){let t=ai(r),e=new Map;for(let n of t){let o=await Ep(n);e.set(n.name,o)}return e}function oi(r){let t=ai(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 ai(r){let t=r instanceof ArrayBuffer?new Uint8Array(r):r,e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=[],o=-1;for(let c=t.length-22;c>=0;c--)if(e.getUint32(c,!0)===101010256){o=c;break}if(o===-1)throw new Error("Invalid ZIP file: end of central directory not found");let a=e.getUint32(o+16,!0),i=e.getUint16(o+10,!0),u=[],s=a;for(let c=0;c<i&&e.getUint32(s,!0)===33639248;c++){let m=e.getUint16(s+10,!0),f=e.getUint32(s+16,!0),p=e.getUint32(s+20,!0),y=e.getUint32(s+24,!0),d=e.getUint16(s+28,!0),g=e.getUint16(s+30,!0),h=e.getUint16(s+32,!0),A=e.getUint32(s+42,!0),b=t.slice(s+46,s+46+d),N=new TextDecoder("utf-8").decode(b);u.push({name:N,compressionMethod:m,crc32:f,compressedSize:p,uncompressedSize:y,localHeaderOffset:A}),s=s+46+d+g+h}for(let c of u){let l=c.localHeaderOffset;if(e.getUint32(l,!0)!==67324752)throw new Error(`Invalid local file header at offset ${l}`);let f=e.getUint16(l+26,!0),p=e.getUint16(l+28,!0),y=l+30+f+p,d=t.slice(y,y+c.compressedSize);n.push({name:c.name,compressedData:d,compressionMethod:c.compressionMethod,crc32:c.crc32,compressedSize:c.compressedSize,uncompressedSize:c.uncompressedSize})}return n}async function Ep(r){if(r.compressionMethod===0)return r.compressedData;if(r.compressionMethod===8)return await Op(r.compressedData);throw new Error(`Unsupported compression method: ${r.compressionMethod}`)}async function Op(r){if(typeof DecompressionStream>"u")throw new Error("DecompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new DecompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let i=a.reduce((c,l)=>c+l.length,0),u=new Uint8Array(i),s=0;for(let c of a)u.set(c,s),s+=c.length;return u}var si=k(()=>{"use strict";Te()});var ui={};He(ui,{loadNpz:()=>ke,loadNpzSync:()=>Ce,parseNpz:()=>wr,parseNpzSync:()=>St});async function wr(r,t={}){let e=t.force??!1,n=await ni(r);return ii(n,e)}function St(r,t={}){let e=t.force??!1,n=oi(r);return ii(n,e)}function ii(r,t){let e=new Map,n=[],o=new Map;for(let[a,i]of r){if(!a.endsWith(".npy"))continue;let u=a.slice(0,-4);try{let s=dr(i);e.set(u,s)}catch(s){if(s instanceof cr&&t)n.push(u),o.set(u,s.message);else throw s}}return{arrays:e,skipped:n,errors:o}}async function ke(r,t={}){let e=await wr(r,t);return Object.fromEntries(e.arrays)}function Ce(r,t={}){let e=St(r,t);return Object.fromEntries(e.arrays)}var Nt=k(()=>{"use strict";At();Fr();si()});async function ci(r,t={}){let e=t.compress??!1,n=[];for(let[f,p]of r){let y=Me(p),d,g;e?(d=await Tp(p),d.length<p.length?g=8:(d=p,g=0)):(d=p,g=0),n.push({name:f,data:p,compressedData:d,crc:y,compressionMethod:g,offset:0})}let o=0;for(let f of n){let p=new TextEncoder().encode(f.name);o+=30+p.length+f.compressedData.length}let a=0;for(let f of n){let p=new TextEncoder().encode(f.name);a+=46+p.length}let u=o+a+22,s=new Uint8Array(u),c=new DataView(s.buffer),l=0;for(let f of n)f.offset=l,l=fi(s,c,l,f);let m=l;for(let f of n)l=mi(s,c,l,f);return pi(c,l,n.length,a,m),s}function li(r){let t=[];for(let[l,m]of r){let f=Me(m);t.push({name:l,data:m,compressedData:m,crc:f,compressionMethod:0,offset:0})}let e=0;for(let l of t){let m=new TextEncoder().encode(l.name);e+=30+m.length+l.compressedData.length}let n=0;for(let l of t){let m=new TextEncoder().encode(l.name);n+=46+m.length}let a=e+n+22,i=new Uint8Array(a),u=new DataView(i.buffer),s=0;for(let l of t)l.offset=s,s=fi(i,u,s,l);let c=s;for(let l of t)s=mi(i,u,s,l);return pi(u,s,t.length,n,c),i}function fi(r,t,e,n){let o=new TextEncoder().encode(n.name);return t.setUint32(e,67324752,!0),e+=4,t.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,n.compressionMethod,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,33,!0),e+=2,t.setUint32(e,n.crc,!0),e+=4,t.setUint32(e,n.compressedData.length,!0),e+=4,t.setUint32(e,n.data.length,!0),e+=4,t.setUint16(e,o.length,!0),e+=2,t.setUint16(e,0,!0),e+=2,r.set(o,e),e+=o.length,r.set(n.compressedData,e),e+=n.compressedData.length,e}function mi(r,t,e,n){let o=new TextEncoder().encode(n.name);return t.setUint32(e,33639248,!0),e+=4,t.setUint16(e,20,!0),e+=2,t.setUint16(e,n.compressionMethod===8?20:10,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,n.compressionMethod,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,33,!0),e+=2,t.setUint32(e,n.crc,!0),e+=4,t.setUint32(e,n.compressedData.length,!0),e+=4,t.setUint32(e,n.data.length,!0),e+=4,t.setUint16(e,o.length,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint16(e,0,!0),e+=2,t.setUint32(e,0,!0),e+=4,t.setUint32(e,n.offset,!0),e+=4,r.set(o,e),e+=o.length,e}function pi(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 Tp(r){if(typeof CompressionStream>"u")throw new Error("CompressionStream is not available. This environment does not support the Compression Streams API. Please use a modern browser or Node.js 18+.");let t=new CompressionStream("deflate-raw"),e=new Uint8Array(r.length);e.set(r);let n=t.writable.getWriter();n.write(e),n.close();let o=t.readable.getReader(),a=[];for(;;){let{done:c,value:l}=await o.read();if(c)break;a.push(l)}let i=a.reduce((c,l)=>c+l.length,0),u=new Uint8Array(i),s=0;for(let c of a)u.set(c,s),s+=c.length;return u}var yi=k(()=>{"use strict";Te()});var gi={};He(gi,{serializeNpz:()=>Pr,serializeNpzSync:()=>Fe});async function Pr(r,t={}){let e=di(r);return ci(e,{compress:t.compress??!1})}function Fe(r){let t=di(r);return li(t)}function di(r){let t=new Map;if(Array.isArray(r)){for(let n=0;n<r.length;n++){let o=r[n],a=mr(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=mr(o),i=n.endsWith(".npy")?n:`${n}.npy`;t.set(i,a)}return t}var Dt=k(()=>{"use strict";ht();yi()});At();ht();Nt();Dt();import{readFileSync as Gr,writeFileSync as Ge}from"node:fs";import{readFile as Zr,writeFile as Ze}from"node:fs/promises";kr();function zr(r,t={}){let{delimiter:e,comments:n="#",skiprows:o=0,usecols:a,max_rows:i,dtype:u="float64",missing_values:s,filling_values:c}=t,l=r.split(/\r?\n/);if(o>0&&(l=l.slice(o)),l=l.filter(d=>{let g=d.trim();return!(g===""||n&&g.startsWith(n))}),i!==void 0&&i>0&&(l=l.slice(0,i)),l.length===0)return L([],u);let m=[],f=new Set(s?Array.isArray(s)?s:[s]:[]),p=c!==void 0?c:u.includes("int")||u==="bool"?0:NaN;for(let d of l){let g;e===void 0?g=d.trim().split(/\s+/):g=d.split(e),a!==void 0&&(g=(Array.isArray(a)?a:[a]).map(b=>(b<0&&(b=g.length+b),g[b]??"")));let h=g.map(A=>{let b=A.trim();if(f.has(b)||b==="")return p;let N=parseFloat(b);return isNaN(N)?p:N});m.push(h)}let y=m[0]?.length??0;for(let d=1;d<m.length;d++)if(m[d].length!==y)throw new Error(`Inconsistent number of columns: row 0 has ${y} columns, row ${d} has ${m[d].length} columns`);return y===1?L(m.map(d=>d[0]),u):L(m,u)}function qr(r,t={}){let e={...t,missing_values:t.missing_values??["","nan","NaN","NA","N/A","-"],filling_values:t.filling_values??NaN};return zr(r,e)}function jr(r,t,e="float64"){let n=typeof t=="string"?new RegExp(t,"gm"):new RegExp(t.source,"gm"),o=[],a;for(;(a=n.exec(r))!==null;)if(a.length>1){let i=a.slice(1).map(u=>{let s=parseFloat(u);return isNaN(s)?0:s});o.push(i)}return o.length===0?L([],e):o[0].length===1?L(o.map(i=>i[0]),e):L(o,e)}function bi(r,t){let e=typeof r=="bigint"?Number(r):r,n=t.match(/^%([+-]?)(\d*)(?:\.(\d+))?([dfeEgGs])$/);if(!n)return String(e);let[,o,a,i,u]=n,s=i!==void 0?parseInt(i,10):void 0,c;switch(u){case"d":c=Math.round(e).toString();break;case"f":c=e.toFixed(s??6);break;case"e":c=e.toExponential(s??6).replace(/e([+-])(\d)$/,"e$10$2");break;case"E":c=e.toExponential(s??6).toUpperCase().replace(/E([+-])(\d)$/,"E$10$2");break;case"g":case"G":{let l=s??6,m=Math.floor(Math.log10(Math.abs(e)));m>=-4&&m<l?(c=e.toPrecision(l),c.includes(".")&&(c=c.replace(/\.?0+$/,""))):c=e.toExponential(l-1),u==="G"&&(c=c.toUpperCase());break}case"s":c=String(e);break;default:c=String(e)}if(a){let l=parseInt(a,10);if(c.length<l){let m=" ".repeat(l-c.length);o==="-"?c=c+m:c=m+c}}return o==="+"&&e>=0&&!c.startsWith("-")&&(c="+"+c),c}function Rr(r,t={}){let{fmt:e="%.18e",delimiter:n=" ",newline:o=`
|
|
3
|
+
`,header:a,footer:i,comments:u="# "}=t;if(r.ndim>2)throw new Error("savetxt: array must be 1D or 2D");let s=[];if(a!==void 0){let l=a.split(/\r?\n/);for(let m of l)m.startsWith(u.trimEnd())?s.push(m):s.push(u+m)}let c=r.toArray();if(r.ndim===1)for(let l of c)s.push(bi(l,e));else for(let l of c){let m=l.map(f=>bi(f,e));s.push(m.join(n))}if(i!==void 0){let l=i.split(/\r?\n/);for(let m of l)m.startsWith(u.trimEnd())?s.push(m):s.push(u+m)}return s.join(o)+o}kr();At();ht();Fr();Nt();Dt();R();W();var er=624,xt=397,Up=2567483615,Ve=2147483648,Pe=2147483647,nr={mt:new Uint32Array(er),mti:er+1};function Si(r){let t=nr.mt;t[0]=r>>>0;for(let e=1;e<er;e++){let n=t[e-1]^t[e-1]>>>30;t[e]=Math.imul(1812433253,n)+e>>>0}nr.mti=er}function Ai(){let r=nr.mt,t,e=[0,Up];if(nr.mti>=er){let n;for(nr.mti===er+1&&Si(5489),n=0;n<er-xt;n++)t=r[n]&Ve|r[n+1]&Pe,r[n]=r[n+xt]^t>>>1^e[t&1];for(;n<er-1;n++)t=r[n]&Ve|r[n+1]&Pe,r[n]=r[n+(xt-er)]^t>>>1^e[t&1];t=r[er-1]&Ve|r[0]&Pe,r[er-1]=r[xt-1]^t>>>1^e[t&1],nr.mti=0}return t=r[nr.mti++],t^=t>>>11,t^=t<<7&2636928640,t^=t<<15&4022730752,t^=t>>>18,t>>>0}function F(){let r=Ai()>>>5,t=Ai()>>>6;return(r*67108864+t)/9007199254740992}var $p=2468251765,kp=1492356589,Cp=1135663077,Fp=2337405405,Vp=3389127133,Pp=1232336661,We=16,wt=4;function Y(r){return r>>>0}function qe(r,t){return r=Y(Y(r)^t.val),t.val=Y(Math.imul(t.val,$p)),r=Y(Math.imul(r,t.val)),r=Y(r^r>>>We),r}function qp(r,t){let e=Y(Y(Math.imul(Vp,Y(r)))-Y(Math.imul(Pp,Y(t))));return e=Y(e^e>>>We),e}function jp(r){let t=[0,0,0,0],e=[r>>>0],n={val:Cp};for(let o=0;o<wt;o++)o<e.length?t[o]=qe(e[o],n):t[o]=qe(0,n);for(let o=0;o<wt;o++)for(let a=0;a<wt;a++)if(o!==a){let i=qe(t[o],n);t[a]=qp(t[a],i)}return t}function Rp(r,t){let e=[],n=Fp;for(let o=0;o<t;o++){let a=r[o%wt],i=Y(a^n);n=Y(Math.imul(n,kp)),i=Y(Math.imul(i,n)),i=Y(i^i>>>We),e.push(i)}return e}var Lp=BigInt("4865540595714422341"),Wp=BigInt("2549297995355413924"),Gp=Wp<<BigInt(64)|Lp,je=BigInt("0xffffffffffffffff"),Re=(BigInt(1)<<BigInt(128))-BigInt(1);function Zp(r){let t=r>>BigInt(64),e=r&je,n=(t^e)&je,o=Number(r>>BigInt(122));return(n>>BigInt(o)|n<<BigInt(64-o))&je}function Le(r,t){return r*Gp+t&Re}function hi(r){let t=jp(r),e=Rp(t,8),n=BigInt(e[0])|BigInt(e[1])<<BigInt(32),o=BigInt(e[2])|BigInt(e[3])<<BigInt(32),a=BigInt(e[4])|BigInt(e[5])<<BigInt(32),i=BigInt(e[6])|BigInt(e[7])<<BigInt(32),u=n<<BigInt(64)|o,s=(a<<BigInt(64)|i)<<BigInt(1);s=(s|BigInt(1))ℜlet c=BigInt(0);return c=Le(c,s),c=c+u&Re,c=Le(c,s),{state:c,inc:s}}function Hp(r){return r.state=Le(r.state,r.inc),Zp(r.state)}function Yp(r){let e=Hp(r)>>BigInt(11);return Number(e)/9007199254740992}var Lr=class{constructor(t){if(t!==void 0)this._pcgState=hi(t);else{let e=Math.floor(Math.random()*4294967296);this._pcgState=hi(e)}}_randomFloat(){return Yp(this._pcgState)}random(t){if(t===void 0)return this._randomFloat();let e=Array.isArray(t)?t:[t],n=e.reduce((i,u)=>i*u,1),o=S.zeros(e,"float64"),a=o.data;for(let i=0;i<n;i++)a[i]=this._randomFloat();return o}integers(t,e,n){if(e===void 0&&(e=t,t=0),n===void 0)return Math.floor(this._randomFloat()*(e-t))+t;let o=Array.isArray(n)?n:[n],a=o.reduce((c,l)=>c*l,1),i=S.zeros(o,"int64"),u=i.data,s=e-t;for(let c=0;c<a;c++)u[c]=BigInt(Math.floor(this._randomFloat()*s)+t);return i}standard_normal(t){if(t===void 0)return gr(this._randomFloat.bind(this));let e=Array.isArray(t)?t:[t],n=e.reduce((i,u)=>i*u,1),o=S.zeros(e,"float64"),a=o.data;for(let i=0;i<n;i+=2){let[u,s]=Wr(this._randomFloat.bind(this));a[i]=u,i+1<n&&(a[i+1]=s)}return o}normal(t=0,e=1,n){if(n===void 0)return gr(this._randomFloat.bind(this))*e+t;let o=Array.isArray(n)?n:[n],a=o.reduce((s,c)=>s*c,1),i=S.zeros(o,"float64"),u=i.data;for(let s=0;s<a;s+=2){let[c,l]=Wr(this._randomFloat.bind(this));u[s]=c*e+t,s+1<a&&(u[s+1]=l*e+t)}return i}uniform(t=0,e=1,n){if(n===void 0)return this._randomFloat()*(e-t)+t;let o=Array.isArray(n)?n:[n],a=o.reduce((c,l)=>c*l,1),i=S.zeros(o,"float64"),u=i.data,s=e-t;for(let c=0;c<a;c++)u[c]=this._randomFloat()*s+t;return i}choice(t,e,n=!0,o){return $i(t,e,n,o,this._randomFloat.bind(this))}permutation(t){return Ci(t,this._randomFloat.bind(this))}shuffle(t){Vi(t,this._randomFloat.bind(this))}exponential(t=1,e){if(e===void 0)return-Math.log(1-this._randomFloat())*t;let n=Array.isArray(e)?e:[e],o=n.reduce((u,s)=>u*s,1),a=S.zeros(n,"float64"),i=a.data;for(let u=0;u<o;u++)i[u]=-Math.log(1-this._randomFloat())*t;return a}poisson(t=1,e){if(e===void 0)return zt(t,this._randomFloat.bind(this));let n=Array.isArray(e)?e:[e],o=n.reduce((u,s)=>u*s,1),a=S.zeros(n,"int64"),i=a.data;for(let u=0;u<o;u++)i[u]=BigInt(zt(t,this._randomFloat.bind(this)));return a}binomial(t,e,n){if(n===void 0)return It(t,e,this._randomFloat.bind(this));let o=Array.isArray(n)?n:[n],a=o.reduce((s,c)=>s*c,1),i=S.zeros(o,"int64"),u=i.data;for(let s=0;s<a;s++)u[s]=BigInt(It(t,e,this._randomFloat.bind(this)));return i}};function Ni(r){return new Lr(r)}function Di(r){r==null&&(r=Math.floor(Date.now()^Math.random()*4294967296)),Si(r>>>0)}function xi(){return{mt:Array.from(nr.mt),mti:nr.mti}}function wi(r){nr.mt=new Uint32Array(r.mt),nr.mti=r.mti}function gr(r){let t,e;do t=r(),e=r();while(t===0);return Math.sqrt(-2*Math.log(t))*Math.cos(2*Math.PI*e)}function Wr(r){let t,e;do t=r(),e=r();while(t===0);let n=Math.sqrt(-2*Math.log(t)),o=2*Math.PI*e;return[n*Math.cos(o),n*Math.sin(o)]}function zt(r,t){if(r<30){let e=Math.exp(-r),n=0,o=1;do n++,o*=t();while(o>e);return n-1}else{let e=gr(t);return Math.max(0,Math.round(r+Math.sqrt(r)*e))}}function It(r,t,e){if(r*t<10&&r*(1-t)<10){let n=0;for(let o=0;o<r;o++)e()<t&&n++;return n}else{let n=r*t,o=Math.sqrt(r*t*(1-t)),a=gr(e);return Math.max(0,Math.min(r,Math.round(n+o*a)))}}function zi(r){if(r===void 0)return F();let t=Array.isArray(r)?r:[r],e=t.reduce((a,i)=>a*i,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a++)o[a]=F();return n}function Ii(...r){if(r.length===0)return F();let t=r.reduce((o,a)=>o*a,1),e=S.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o++)n[o]=F();return e}function _i(...r){if(r.length===0)return gr(F);let t=r.reduce((o,a)=>o*a,1),e=S.zeros(r,"float64"),n=e.data;for(let o=0;o<t;o+=2){let[a,i]=Wr(F);n[o]=a,o+1<t&&(n[o+1]=i)}return e}function Bi(r,t,e,n="int64"){t==null&&(t=r,r=0);let o=t-r;if(e===void 0)return Math.floor(F()*o)+r;let a=Array.isArray(e)?e:[e],i=a.reduce((c,l)=>c*l,1),u=S.zeros(a,n),s=u.data;if(w(n)){let c=s;for(let l=0;l<i;l++)c[l]=BigInt(Math.floor(F()*o)+r)}else{let c=s;for(let l=0;l<i;l++)c[l]=Math.floor(F()*o)+r}return u}function vi(r=0,t=1,e){if(e===void 0)return F()*(t-r)+r;let n=Array.isArray(e)?e:[e],o=n.reduce((s,c)=>s*c,1),a=S.zeros(n,"float64"),i=a.data,u=t-r;for(let s=0;s<o;s++)i[s]=F()*u+r;return a}function Ei(r=0,t=1,e){if(e===void 0)return gr(F)*t+r;let n=Array.isArray(e)?e:[e],o=n.reduce((u,s)=>u*s,1),a=S.zeros(n,"float64"),i=a.data;for(let u=0;u<o;u+=2){let[s,c]=Wr(F);i[u]=s*t+r,u+1<o&&(i[u+1]=c*t+r)}return a}function Oi(r){if(r===void 0)return gr(F);let t=Array.isArray(r)?r:[r],e=t.reduce((a,i)=>a*i,1),n=S.zeros(t,"float64"),o=n.data;for(let a=0;a<e;a+=2){let[i,u]=Wr(F);o[a]=i,a+1<e&&(o[a+1]=u)}return n}function Mi(r=1,t){if(t===void 0)return-Math.log(1-F())*r;let e=Array.isArray(t)?t:[t],n=e.reduce((i,u)=>i*u,1),o=S.zeros(e,"float64"),a=o.data;for(let i=0;i<n;i++)a[i]=-Math.log(1-F())*r;return o}function Ti(r=1,t){if(t===void 0)return zt(r,F);let e=Array.isArray(t)?t:[t],n=e.reduce((i,u)=>i*u,1),o=S.zeros(e,"int64"),a=o.data;for(let i=0;i<n;i++)a[i]=BigInt(zt(r,F));return o}function Ui(r,t,e){if(e===void 0)return It(r,t,F);let n=Array.isArray(e)?e:[e],o=n.reduce((u,s)=>u*s,1),a=S.zeros(n,"int64"),i=a.data;for(let u=0;u<o;u++)i[u]=BigInt(It(r,t,F));return a}function $i(r,t,e=!0,n,o=F){let a;if(typeof r=="number")a=Array.from({length:r},(f,p)=>p);else{let f=r.size;a=[];for(let p=0;p<f;p++)a.push(Number(r.iget(p)))}let i=a.length;if(i===0)throw new Error("cannot take a sample from an empty sequence");let u;if(n!==void 0){if(Array.isArray(n))u=n;else{let p=n.size;u=[];for(let y=0;y<p;y++)u.push(Number(n.iget(y)))}if(u.length!==i)throw new Error("p and a must have the same size");let f=u.reduce((p,y)=>p+y,0);Math.abs(f-1)>1e-10&&(u=u.map(p=>p/f))}if(t===void 0){if(u){let f=o(),p=0;for(let y=0;y<i;y++)if(p+=u[y],f<p)return a[y];return a[i-1]}return a[Math.floor(o()*i)]}let s=Array.isArray(t)?t:[t],c=s.reduce((f,p)=>f*p,1);if(!e&&c>i)throw new Error("cannot take a larger sample than population when replace=false");let l=S.zeros(s,"float64"),m=l.data;if(e)if(u){let f=new Array(i);f[0]=u[0];for(let p=1;p<i;p++)f[p]=f[p-1]+u[p];for(let p=0;p<c;p++){let y=o(),d=0;for(;d<i-1&&y>=f[d];)d++;m[p]=a[d]}}else for(let f=0;f<c;f++)m[f]=a[Math.floor(o()*i)];else{let f=[...a],p=u?[...u]:void 0;for(let y=0;y<c;y++){let d;if(p){let g=p.reduce((b,N)=>b+N,0),h=o()*g,A=0;d=0;for(let b=0;b<f.length;b++)if(A+=p[b],h<A){d=b;break}d===0&&h>=A&&(d=f.length-1)}else d=Math.floor(o()*f.length);m[y]=f[d],f.splice(d,1),p&&p.splice(d,1)}}return l}function ki(r,t,e=!0,n){return $i(r,t,e,n,F)}function Ci(r,t=F){let e;if(typeof r=="number"){let o=new Float64Array(r);for(let a=0;a<r;a++)o[a]=a;e=S.fromData(o,[r],"float64")}else e=r.copy();let n=e.size;for(let o=n-1;o>0;o--){let a=Math.floor(t()*(o+1)),i=e.iget(o);e.iset(o,e.iget(a)),e.iset(a,i)}return e}function Fi(r){return Ci(r,F)}function Vi(r,t=F){let e=r.size;for(let n=e-1;n>0;n--){let o=Math.floor(t()*(n+1)),a=r.iget(n);r.iset(n,r.iget(o)),r.iset(o,a)}}function Pi(r){Vi(r,F)}kr();function K(r){return r&&typeof r=="object"&&"_data"in r&&"_shape"in r?I._fromStorage(r):r}var qd={seed:Di,random:r=>K(zi(r)),rand:(...r)=>K(Ii(...r)),randn:(...r)=>K(_i(...r)),randint:(r,t,e,n)=>K(Bi(r,t,e,n)),uniform:(r,t,e)=>K(vi(r,t,e)),normal:(r,t,e)=>K(Ei(r,t,e)),standard_normal:r=>K(Oi(r)),exponential:(r,t)=>K(Mi(r,t)),poisson:(r,t)=>K(Ti(r,t)),binomial:(r,t,e)=>K(Ui(r,t,e)),choice:(r,t,e,n)=>K(ki(r,t,e,n)),permutation:r=>K(Fi(r)),shuffle:Pi,get_state:xi,set_state:wi,default_rng:Ni,Generator:Lr},jd="0.10.0";async function Xp(r){let t=await Zr(r);return dr(t)}function Qp(r){let t=Gr(r);return dr(t)}async function Kp(r,t){let e=mr(t);await Ze(r,e)}function ry(r,t){let e=mr(t);Ge(r,e)}async function ty(r,t={}){let e=await Zr(r);return wr(e,t)}function ey(r,t={}){let e=Gr(r),{parseNpzSync:n}=(Nt(),Ye(ui));return n(e,t)}async function qi(r,t,e={}){let n=await Pr(t,e);await Ze(r,n)}function Kd(r,t){let{serializeNpzSync:e}=(Dt(),Ye(gi)),n=e(t);Ge(r,n)}async function rg(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return Xp(r)}else{if(r.endsWith(".npz"))return ty(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}function tg(r,t={}){if(r.endsWith(".npy")){if(t.allowNpy===!1)throw new Error("Loading .npy files is disabled (allowNpy: false)");return Qp(r)}else{if(r.endsWith(".npz"))return ey(r,t);throw new Error(`Unknown file extension. Expected .npy or .npz, got: ${r}`)}}async function eg(r,t){if(!r.endsWith(".npy"))throw new Error(`save() is for .npy files. Use saveNpz() for .npz files. Got: ${r}`);return Kp(r,t)}function ng(r,t){if(!r.endsWith(".npy"))throw new Error(`saveSync() is for .npy files. Use saveNpzSync() for .npz files. Got: ${r}`);return ry(r,t)}async function og(r,t){return r.endsWith(".npz")||(r=r+".npz"),qi(r,t,{compress:!1})}async function ag(r,t){return r.endsWith(".npz")||(r=r+".npz"),qi(r,t,{compress:!0})}async function sg(r,t={}){let e=await Zr(r,{encoding:t.encoding??"utf-8"});return zr(e,t)}function ig(r,t={}){let e=Gr(r,{encoding:t.encoding??"utf-8"});return zr(e,t)}async function ug(r,t,e={}){let n=Rr(t,e);await Ze(r,n,"utf-8")}function cg(r,t,e={}){let n=Rr(t,e);Ge(r,n,"utf-8")}async function lg(r,t={}){let e=await Zr(r,{encoding:t.encoding??"utf-8"});return qr(e,t)}function fg(r,t={}){let e=Gr(r,{encoding:t.encoding??"utf-8"});return qr(e,t)}async function mg(r,t,e="float64"){let n=await Zr(r,{encoding:"utf-8"});return jr(n,t,e)}function pg(r,t,e="float64"){let n=Gr(r,{encoding:"utf-8"});return jr(n,t,e)}export{bt as DTYPE_TO_DESCR,X as InvalidNpyError,I as NDArray,Be as SUPPORTED_DTYPES,cr as UnsupportedDTypeError,jd as __version__,Ps as abs,Ps as absolute,Rs as acos,Zs as acosh,Qs as amax,Ks as amin,Yl as append,gc as arange,Rs as arccos,Zs as arccosh,js as arcsin,Gs as arcsinh,Ls as arctan,Ws as arctan2,Hs as arctanh,jm as argpartition,Vm as argsort,Wm as argwhere,_e as around,L as array,sf as array_equal,uf as array_equiv,Bl as array_split,Ic as asanyarray,gt as asarray,_c as ascontiguousarray,Bc as asfortranarray,js as asin,Gs as asinh,Ls as atan,Ws as atan2,Hs as atanh,jl as atleast_1d,Rl as atleast_2d,Ll as atleast_3d,pf as average,pp as bincount,Vf as bitwise_and,jf as bitwise_not,Pf as bitwise_or,qf as bitwise_xor,rf as broadcast_arrays,tf as broadcast_shapes,Kl as broadcast_to,If as cbrt,Xm as ceil,af as choose,Gl as column_stack,xm as compress,Dr as concatenate,hp as convolve,Nc as copy,em as copysign,of as copyto,Np as corrcoef,Ap as correlate,ml as cos,Sl as cosh,Jm as count_nonzero,Sp as cov,mp as cross,Xs as cumprod,Js as cumsum,Xs as cumulative_prod,Js as cumulative_sum,bl as deg2rad,dl as degrees,Jl as delete,Fs as diag,_m as diag_indices,Bm as diag_indices_from,vc as diagflat,al as diagonal,cp as diff,yp as digitize,qs as divide,Bf as divmod,nl as dot,Wl as dsplit,Il as dstack,lp as ediff1d,Am as einsum,ks as empty,wc as empty_like,jc as exp,Rc as exp2,kl as expand_dims,Lc as expm1,Ym as extract,$s as eye,_f as fabs,Im as fill_diagonal,Qm as fix,Gm as flatnonzero,Ie as flip,Cl as fliplr,Fl as flipud,Mf as float_power,Km as floor,rl as floor_divide,Tf as fmod,Uf as frexp,kc as frombuffer,Cc as fromfile,Ec as fromfunction,Fc as fromiter,mg as fromregex,pg as fromregexSync,Vc as fromstring,Cs as full,zc as full_like,$f as gcd,lg as genfromtxt,fg as genfromtxtSync,hc as geomspace,fp as gradient,Of as heaviside,dp as histogram,gp as histogram2d,bp as histogramdd,El as hsplit,zl as hstack,yl as hypot,Sc as identity,np as in1d,Um as indices,ul as inner,Xl as insert,op as intersect1d,Rf as invert,sm as iscomplex,im as iscomplexobj,gm as isdtype,Qf as isfinite,mm as isfortran,ap as isin,Kf as isinf,rm as isnan,tm as isnat,lm as isneginf,fm as isposinf,um as isreal,cm as isrealobj,ym as isscalar,dm as iterable,$m as ix_,sl as kron,kf as lcm,Cf as ldexp,Lf as left_shift,Pm as lexsort,hm as linalg,bc as linspace,rg as load,Xp as loadNpy,Qp as loadNpySync,ke as loadNpz,ty as loadNpzFile,ey as loadNpzFileSync,Ce as loadNpzSync,tg as loadSync,sg as loadtxt,ig as loadtxtSync,Wc as log,Zc as log10,Hc as log1p,Gc as log2,Yc as logaddexp,Jc as logaddexp2,Hf as logical_and,Jf as logical_not,Yf as logical_or,Xf as logical_xor,Ac as logspace,Tm as mask_indices,Qs as max,lf as median,Oc as meshgrid,Ks as min,Kc as mod,Ff as modf,xl as moveaxis,Df as nanargmax,Nf as nanargmin,wf as nancumprod,xf as nancumsum,Sf as nanmax,gf as nanmean,zf as nanmedian,hf as nanmin,df as nanprod,Af as nanstd,yf as nansum,bf as nanvar,Xc as negative,om as nextafter,Lm as nonzero,Ts as ones,xc as ones_like,cl as outer,Gf as packbits,Ql as pad,dr as parseNpy,Oe as parseNpyData,Ee as parseNpyHeader,wr as parseNpz,St as parseNpzSync,zr as parseTxt,qm as partition,ff as percentile,zm as place,tl as positive,Vs as pow,Vs as power,bm as promote_types,cf as ptp,nf as put,Nm as put_along_axis,Dm as putmask,mf as quantile,Al as rad2deg,gl as radians,qd as random,Tl as ravel,km as ravel_multi_index,pm as real_if_close,el as reciprocal,Ef as remainder,Ml as repeat,Ul as reshape,Hl as resize,Wf as right_shift,rp as rint,Pl as roll,ql as rollaxis,Vl as rot90,_e as round,_e as round_,Zl as row_stack,eg as save,Kp as saveNpy,ry as saveNpySync,qi as saveNpz,Kd as saveNpzSync,ng as saveSync,ug as savetxt,cg as savetxtSync,og as savez,ag as savez_compressed,Hm as searchsorted,wm as select,mr as serializeNpy,Pr as serializeNpz,Fe as serializeNpzSync,Rr as serializeTxt,sp as setdiff1d,ip as setxor1d,Qc as sign,nm as signbit,fl as sin,hl as sinh,Fm as sort,Rm as sort_complex,am as spacing,_l as split,qc as sqrt,vf as square,$l as squeeze,wl as stack,Dl as swapaxes,ef as take,Sm as take_along_axis,pl as tan,Nl as tanh,ll as tensordot,Ol as tile,ol as trace,il as transpose,Mc as tri,Tc as tril,vm as tril_indices,Em as tril_indices_from,Uc as triu,Om as triu_indices,Mm as triu_indices_from,qs as true_divide,tp as trunc,up as union1d,ep as unique,Zf as unpackbits,Cm as unravel_index,$c as vander,vl as vsplit,Ys as vstack,Zm as where,ur as zeros,Dc as zeros_like};
|
|
4
4
|
//# sourceMappingURL=numpy-ts.node-io.mjs.map
|