numpy-ts 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{parseSlice as d,normalizeSlice as c}from"./slicing";import{getTypedArrayConstructor as m,getDTypeSize as b,isBigIntDType as y,isComplexDType as A}from"./dtype";import{Complex as f}from"./complex";import{ArrayStorage as p}from"./storage";class l{constructor(t,r){this._storage=t,this._base=r}get storage(){return this._storage}static fromStorage(t,r){return new l(t,r)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get itemsize(){return b(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){const r=this._storage.dtype,i=this.size;if(y(r)){const n=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let e=0;e<i;e++)this._storage.iset(e,n)}else if(r==="bool"){const n=t?1:0;for(let e=0;e<i;e++)this._storage.iset(e,n)}else{const n=Number(t);for(let e=0;e<i;e++)this._storage.iset(e,n)}}*[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`);const r=t.map((i,n)=>{let e=i;if(e<0&&(e=this.shape[n]+e),e<0||e>=this.shape[n])throw new Error(`Index ${i} is out of bounds for axis ${n} with size ${this.shape[n]}`);return e});return this._storage.get(...r)}set(t,r){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);const i=t.map((e,a)=>{let o=e;if(o<0&&(o=this.shape[a]+o),o<0||o>=this.shape[a])throw new Error(`Index ${e} is out of bounds for axis ${a} with size ${this.shape[a]}`);return o}),n=this.dtype;if(A(n))this._storage.set(i,r);else if(y(n)){const e=r instanceof f?r.re:Number(r),a=typeof r=="bigint"?r:BigInt(Math.round(e));this._storage.set(i,a)}else if(n==="bool"){const a=(r instanceof f?r.re:Number(r))?1:0;this._storage.set(i,a)}else{const e=r instanceof f?r.re:Number(r);this._storage.set(i,e)}}iget(t){return this._storage.iget(t)}iset(t,r){this._storage.iset(t,r)}copy(){return new l(this._storage.copy())}astype(t,r=!0){const i=this.dtype;if(i===t&&!r)return this;if(i===t&&r)return this.copy();const n=Array.from(this.shape),e=this.size,a=m(t);if(!a)throw new Error(`Cannot convert to dtype ${t}`);const o=new a(e),g=this.data;if(y(i)&&!y(t)){const h=g;if(t==="bool")for(let s=0;s<e;s++)o[s]=h[s]!==BigInt(0)?1:0;else for(let s=0;s<e;s++)o[s]=Number(h[s])}else if(!y(i)&&y(t)){const h=g;for(let s=0;s<e;s++)o[s]=BigInt(Math.round(Number(h[s])))}else if(t==="bool"){const h=g;for(let s=0;s<e;s++)o[s]=h[s]!==0?1:0}else if(i==="bool"&&!y(t)){const h=g;for(let s=0;s<e;s++)o[s]=h[s]}else if(!y(i)&&!y(t)){const h=g;for(let s=0;s<e;s++)o[s]=h[s]}else{const h=g;for(let s=0;s<e;s++)o[s]=h[s]}const u=p.fromData(o,n,t);return new l(u)}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`);const r=t.map((g,u)=>{const h=d(g);return c(h,this.shape[u])});for(;r.length<this.ndim;)r.push({start:0,stop:this.shape[r.length],step:1,isIndex:!1});const i=[],n=[];let e=this._storage.offset;for(let g=0;g<r.length;g++){const u=r[g];if(e+=u.start*this._storage.strides[g],u.step===0)continue;const h=Math.max(0,Math.ceil((u.stop-u.start)/u.step));i.push(h),n.push(this._storage.strides[g]*u.step)}const a=p.fromData(this._storage.data,i,this._storage.dtype,n,e),o=this._base??this;return new l(a,o)}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);const t=this.shape,r=t.length,i=(n,e)=>{if(e===r)return this._storage.get(...n);const a=[];for(let o=0;o<t[e];o++)n[e]=o,a.push(i(n,e+1));return a};return i(new Array(r),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const i=this._storage.data,n=i.BYTES_PER_ELEMENT,e=this._storage.offset*n,a=this.size*n;return i.buffer.slice(e,e+a)}const r=this.copy()._storage.data;return r.buffer.slice(0,this.size*r.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){const r=t[0];if(r<0||r>=this.size)throw new Error(`index ${r} is out of bounds for size ${this.size}`);return this._storage.iget(r)}return this.get(t)}}export{l as NDArrayCore};
1
+ import{parseSlice as c,normalizeSlice as d}from"./slicing";import{getTypedArrayConstructor as m,getDTypeSize as b,isBigIntDType as y,isComplexDType as A}from"./dtype";import{Complex as f}from"./complex";import{ArrayStorage as p}from"./storage";import{array_str as _}from"./ops/formatting";class l{constructor(t,r){this._storage=t,this._base=r}get storage(){return this._storage}static fromStorage(t,r){return new l(t,r)}get shape(){return this._storage.shape}get ndim(){return this._storage.ndim}get size(){return this._storage.size}get dtype(){return this._storage.dtype}get data(){return this._storage.data}get strides(){return this._storage.strides}get flags(){return{C_CONTIGUOUS:this._storage.isCContiguous,F_CONTIGUOUS:this._storage.isFContiguous,OWNDATA:this._base===void 0}}get base(){return this._base??null}get itemsize(){return b(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(t){const r=this._storage.dtype,i=this.size;if(y(r)){const n=typeof t=="bigint"?t:BigInt(Math.round(Number(t)));for(let e=0;e<i;e++)this._storage.iset(e,n)}else if(r==="bool"){const n=t?1:0;for(let e=0;e<i;e++)this._storage.iset(e,n)}else{const n=Number(t);for(let e=0;e<i;e++)this._storage.iset(e,n)}}*[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`);const r=t.map((i,n)=>{let e=i;if(e<0&&(e=this.shape[n]+e),e<0||e>=this.shape[n])throw new Error(`Index ${i} is out of bounds for axis ${n} with size ${this.shape[n]}`);return e});return this._storage.get(...r)}set(t,r){if(t.length!==this.ndim)throw new Error(`Index has ${t.length} dimensions, but array has ${this.ndim} dimensions`);const i=t.map((e,a)=>{let o=e;if(o<0&&(o=this.shape[a]+o),o<0||o>=this.shape[a])throw new Error(`Index ${e} is out of bounds for axis ${a} with size ${this.shape[a]}`);return o}),n=this.dtype;if(A(n))this._storage.set(i,r);else if(y(n)){const e=r instanceof f?r.re:Number(r),a=typeof r=="bigint"?r:BigInt(Math.round(e));this._storage.set(i,a)}else if(n==="bool"){const a=(r instanceof f?r.re:Number(r))?1:0;this._storage.set(i,a)}else{const e=r instanceof f?r.re:Number(r);this._storage.set(i,e)}}iget(t){return this._storage.iget(t)}iset(t,r){this._storage.iset(t,r)}copy(){return new l(this._storage.copy())}astype(t,r=!0){const i=this.dtype;if(i===t&&!r)return this;if(i===t&&r)return this.copy();const n=Array.from(this.shape),e=this.size,a=m(t);if(!a)throw new Error(`Cannot convert to dtype ${t}`);const o=new a(e),g=this.data;if(y(i)&&!y(t)){const h=g;if(t==="bool")for(let s=0;s<e;s++)o[s]=h[s]!==BigInt(0)?1:0;else for(let s=0;s<e;s++)o[s]=Number(h[s])}else if(!y(i)&&y(t)){const h=g;for(let s=0;s<e;s++)o[s]=BigInt(Math.round(Number(h[s])))}else if(t==="bool"){const h=g;for(let s=0;s<e;s++)o[s]=h[s]!==0?1:0}else if(i==="bool"&&!y(t)){const h=g;for(let s=0;s<e;s++)o[s]=h[s]}else if(!y(i)&&!y(t)){const h=g;for(let s=0;s<e;s++)o[s]=h[s]}else{const h=g;for(let s=0;s<e;s++)o[s]=h[s]}const u=p.fromData(o,n,t);return new l(u)}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`);const r=t.map((g,u)=>{const h=c(g);return d(h,this.shape[u])});for(;r.length<this.ndim;)r.push({start:0,stop:this.shape[r.length],step:1,isIndex:!1});const i=[],n=[];let e=this._storage.offset;for(let g=0;g<r.length;g++){const u=r[g];if(e+=u.start*this._storage.strides[g],u.step===0)continue;const h=Math.max(0,Math.ceil((u.stop-u.start)/u.step));i.push(h),n.push(this._storage.strides[g]*u.step)}const a=p.fromData(this._storage.data,i,this._storage.dtype,n,e),o=this._base??this;return new l(a,o)}toString(){return _(this._storage)}toArray(){if(this.ndim===0)return this._storage.iget(0);const t=this.shape,r=t.length,i=(n,e)=>{if(e===r)return this._storage.get(...n);const a=[];for(let o=0;o<t[e];o++)n[e]=o,a.push(i(n,e+1));return a};return i(new Array(r),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const i=this._storage.data,n=i.BYTES_PER_ELEMENT,e=this._storage.offset*n,a=this.size*n;return i.buffer.slice(e,e+a)}const r=this.copy()._storage.data;return r.buffer.slice(0,this.size*r.BYTES_PER_ELEMENT)}item(...t){if(t.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(t.length===1){const r=t[0];if(r<0||r>=this.size)throw new Error(`index ${r} is out of bounds for size ${this.size}`);return this._storage.iget(r)}return this.get(t)}}export{l as NDArrayCore};
@@ -1,2 +1,4 @@
1
- import{Complex as T}from"../complex";const w={threshold:1e3,edgeitems:3,precision:8,linewidth:75,floatmode:"maxprec",suppress:!0,separator:" ",prefix:"",suffix:"",nanstr:"nan",infstr:"inf",sign:"-",legacy:!1};let f={...w};function M(n){f={...f,...n}}function C(){return{...f}}function $(n){let i=null;const e={_savedOptions:null,enter(){i={...f},e._savedOptions=i,f={...f,...n}},exit(){i&&(f=i,i=null,e._savedOptions=null)},apply(t){e.enter();try{return t()}finally{e.exit()}}};return e}function I(n,i=null,e=!0,t=!0,s="k",a="-",g=null,m=null,b=null){const l=i??f.precision;if(!Number.isFinite(n))return Number.isNaN(n)?f.nanstr:(n>0?"":"-")+f.infstr;let r;if(e&&i===null?(r=n.toString(),t&&!r.includes(".")&&!r.includes("e")&&(r+=".0")):r=n.toFixed(l),b!==null){const o=r.indexOf(".");if(o!==-1){const p=r.length-o-1;p<b&&(r+="0".repeat(b-p))}else t&&(r+="."+"0".repeat(b))}if(s!=="k"&&r.includes(".")){if(s==="-"||s==="0"){let o=r.length;for(;o>0&&r[o-1]==="0";)o--;r=r.slice(0,o)}(s==="-"||s===".")&&r.endsWith(".")&&(r=r.slice(0,-1))}if(n>=0&&!Object.is(n,-0)&&(a==="+"?r="+"+r:a===" "&&(r=" "+r)),g!==null&&r.length<g&&(r=" ".repeat(g-r.length)+r),m!==null){const o=r.indexOf(".");if(o!==-1){const p=r.length-o-1;p<m&&(r+="0".repeat(m-p))}}return r}function j(n,i=null,e=!0,t="k",s="-",a=null,g=2,m=null){const b=i??f.precision;if(!Number.isFinite(n))return Number.isNaN(n)?f.nanstr:(n>0?"":"-")+f.infstr;let l=n.toExponential(b);if(m!==null){const x=l.indexOf("e"),c=l.slice(0,x),O=l.slice(x),S=c.indexOf(".");if(S!==-1){const P=c.length-S-1;P<m&&(l=c+"0".repeat(m-P)+O)}}if(t!=="k"){const x=l.indexOf("e");let c=l.slice(0,x);const O=l.slice(x);c.includes(".")&&((t==="-"||t==="0")&&(c=c.replace(/0+$/,"")),(t==="-"||t===".")&&(c=c.replace(/\.$/,""))),l=c+O}const r=l.indexOf("e"),o=l.slice(0,r);let p=l.slice(r+1);const u=p[0]==="-"?"-":"+";let d=p.replace(/^[+-]/,"");for(;d.length<g;)d="0"+d;return l=o+"e"+u+d,n>=0&&!Object.is(n,-0)&&(s==="+"?l="+"+l:s===" "&&(l=" "+l)),a!==null&&l.length<a&&(l=" ".repeat(a-l.length)+l),l}function F(n,i=2,e=0){if(i<2||i>36)throw new Error("base must be between 2 and 36");n=Math.trunc(n);let t;if(n<0?t="-"+Math.abs(n).toString(i).toUpperCase():t=n.toString(i).toUpperCase(),e>0){const s="0".repeat(e);t.startsWith("-")?t="-"+s+t.slice(1):t=s+t}return t}function _(n,i=null){if(n=Math.trunc(n),i!==null&&n<0){if(n=Math.pow(2,i)+n,n<0)throw new Error("width too small for negative number");let s=n.toString(2);return s.length<i&&(s="0".repeat(i-s.length)+s),s}let e;return n<0?e="-"+Math.abs(n).toString(2):e=n.toString(2),i!==null&&e.length<i&&(e="0".repeat(i-e.length)+e),e}function h(n,i,e){if(n instanceof T){const t=h(n.re,"float64",e),s=h(Math.abs(n.im),"float64",e),a=n.im>=0?"+":"-";return`${t}${a}${s}j`}return typeof n=="boolean"?n?" True":"False":typeof n=="bigint"?n.toString():Number.isFinite(n)?i==="float32"||i==="float64"?e.suppress&&Math.abs(n)<1e-10&&n!==0?"0.":I(n,e.precision,!1,!0,"k",e.sign):n.toString():Number.isNaN(n)?e.nanstr:(n>0?"":"-")+e.infstr}function y(n,i,e,t){const s=n.shape,a=s.length;if(e===a){let u=0;const d=n.strides;for(let c=0;c<a;c++)u+=i[c]*d[c];const x=n.iget(u);return h(x,n.dtype,t)}const g=s[e],m=t.threshold,b=t.edgeitems,r=s.reduce((u,d)=>u*d,1)>m&&g>2*b,o=[],p=[...i];if(r){for(let u=0;u<b;u++)p[e]=u,o.push(y(n,p,e+1,t));o.push("...");for(let u=g-b;u<g;u++)p[e]=u,o.push(y(n,p,e+1,t))}else for(let u=0;u<g;u++)p[e]=u,o.push(y(n,p,e+1,t));if(e===a-1)return"["+o.join(t.separator)+"]";{const d=`,
2
- `+" ".repeat(e+1);return"["+o.join(d)+"]"}}function N(n,i=null,e=null,t=null,s=" ",a="",g="",m=null,b=null){const l={...f,linewidth:i??f.linewidth,precision:e??f.precision,suppress:t??f.suppress,separator:s,prefix:a,suffix:g,threshold:m??f.threshold,edgeitems:b??f.edgeitems};if(n.ndim===0){const o=n.iget(0);return h(o,n.dtype,l)}const r=y(n,new Array(n.ndim).fill(0),0,l);return l.prefix+r+l.suffix}function z(n,i=null,e=null,t=null){let a="array("+N(n,i,e,t,", ");return n.dtype!=="float64"&&(a+=`, dtype='${n.dtype}'`),a+=")",a}function q(n,i=null,e=null,t=null){return N(n,i,e,t)}export{N as array2string,z as array_repr,q as array_str,F as base_repr,_ as binary_repr,I as format_float_positional,j as format_float_scientific,C as get_printoptions,$ as printoptions,M as set_printoptions};
1
+ import{Complex as z}from"../complex";const D={threshold:1e3,edgeitems:3,precision:8,linewidth:75,floatmode:"maxprec",suppress:!0,separator:" ",prefix:"",suffix:"",nanstr:"nan",infstr:"inf",sign:"-",legacy:!1};let x={...D};function q(n){x={...x,...n}}function E(){return{...x}}function R(n){let t=null;const e={_savedOptions:null,enter(){t={...x},e._savedOptions=t,x={...x,...n}},exit(){t&&(x=t,t=null,e._savedOptions=null)},apply(r){e.enter();try{return r()}finally{e.exit()}}};return e}function C(n,t=null,e=!0,r=!0,a="k",o="-",g=null,f=null,h=null){const u=t??x.precision;if(!Number.isFinite(n))return Number.isNaN(n)?x.nanstr:(n>0?"":"-")+x.infstr;let s;if(e&&t===null?(s=n.toString(),r&&!s.includes(".")&&!s.includes("e")&&(s+=".0")):s=n.toFixed(u),h!==null){const p=s.indexOf(".");if(p!==-1){const i=s.length-p-1;i<h&&(s+="0".repeat(h-i))}else r&&(s+="."+"0".repeat(h))}if(a!=="k"&&s.includes(".")){if(a==="."||a==="0"||a==="-"){let p=s.length;for(;p>0&&s[p-1]==="0";)p--;s=s.slice(0,p)}a==="0"&&s.endsWith(".")&&(s+="0"),a==="-"&&s.endsWith(".")&&(s=s.slice(0,-1))}if(n>=0&&!Object.is(n,-0)&&(o==="+"?s="+"+s:o===" "&&(s=" "+s)),g!==null&&s.length<g&&(s=" ".repeat(g-s.length)+s),f!==null){const p=s.indexOf(".");if(p!==-1){const i=s.length-p-1;i<f&&(s+="0".repeat(f-i))}}return s}function w(n,t=null,e=!0,r="k",a="-",o=null,g=2,f=null){const h=t??x.precision;if(!Number.isFinite(n))return Number.isNaN(n)?x.nanstr:(n>0?"":"-")+x.infstr;let u=n.toExponential(h);if(f!==null){const l=u.indexOf("e"),d=u.slice(0,l),S=u.slice(l),N=d.indexOf(".");if(N!==-1){const c=d.length-N-1;c<f&&(u=d+"0".repeat(f-c)+S)}}if(r!=="k"){const l=u.indexOf("e");let d=u.slice(0,l);const S=u.slice(l);d.includes(".")&&((r==="."||r==="0"||r==="-")&&(d=d.replace(/0+$/,"")),r==="0"&&d.endsWith(".")&&(d+="0"),r==="-"&&(d=d.replace(/\.$/,""))),u=d+S}const s=u.indexOf("e"),p=u.slice(0,s);let i=u.slice(s+1);const m=i[0]==="-"?"-":"+";let b=i.replace(/^[+-]/,"");for(;b.length<g;)b="0"+b;return u=p+"e"+m+b,n>=0&&!Object.is(n,-0)&&(a==="+"?u="+"+u:a===" "&&(u=" "+u)),o!==null&&u.length<o&&(u=" ".repeat(o-u.length)+u),u}function U(n,t=2,e=0){if(t<2||t>36)throw new Error("base must be between 2 and 36");n=Math.trunc(n);let r;if(n<0?r="-"+Math.abs(n).toString(t).toUpperCase():r=n.toString(t).toUpperCase(),e>0){const a="0".repeat(e);r.startsWith("-")?r="-"+a+r.slice(1):r=a+r}return r}function B(n,t=null){if(n=Math.trunc(n),t!==null&&n<0){if(n=Math.pow(2,t)+n,n<0)throw new Error("width too small for negative number");let a=n.toString(2);return a.length<t&&(a="0".repeat(t-a.length)+a),a}let e;return n<0?e="-"+Math.abs(n).toString(2):e=n.toString(2),t!==null&&e.length<t&&(e="0".repeat(t-e.length)+e),e}function P(n,t,e){if(n instanceof z){const r=P(n.re,"float64",e),a=P(Math.abs(n.im),"float64",e),o=n.im>=0?"+":"-";return`${r}${o}${a}j`}return typeof n=="boolean"?n?" True":"False":typeof n=="bigint"?n.toString():Number.isFinite(n)?t==="float32"||t==="float64"?e.suppress&&Math.abs(n)<1e-10&&n!==0?"0.":C(n,e.precision,!1,!0,"k",e.sign):n.toString():Number.isNaN(n)?e.nanstr:(n>0?"":"-")+e.infstr}function $(n,t){const e=[],r=n.shape,a=r.length,o=n.strides;function g(f,h){if(h===a){let i=0;for(let m=0;m<a;m++)i+=f[m]*o[m];e.push(n.iget(i));return}const u=r[h];if(r.reduce((i,m)=>i*m,1)>t.threshold&&u>2*t.edgeitems){for(let i=0;i<t.edgeitems;i++)f[h]=i,g(f,h+1);for(let i=u-t.edgeitems;i<u;i++)f[h]=i,g(f,h+1)}else for(let i=0;i<u;i++)f[h]=i,g(f,h+1)}return a>0?g(new Array(a).fill(0),0):e.push(n.iget(0)),e}function T(n,t){return n<0||Object.is(n,-0)?"-"+Math.abs(n).toString()+".":t==="+"?"+"+n.toString()+".":t===" "?" "+n.toString()+".":n.toString()+"."}function M(n,t,e){const r=n.indexOf(".");if(r===-1)return n.padStart(t+(e>0?1+e:0));const a=n.slice(0,r),o=n.slice(r+1),g=a.padStart(t),f=e>0?o.padEnd(e):o;return g+"."+f}function W(n){let t=0,e=0;for(const r of n){const a=r.indexOf(".");a===-1?t=Math.max(t,r.length):(t=Math.max(t,a),e=Math.max(e,r.length-a-1))}return{maxLeft:t,maxRight:e}}function A(n,t){const e=n.filter(i=>Number.isFinite(i));if(e.length===0){const i=n.map(b=>Number.isNaN(b)?t.nanstr:(b>0?"":"-")+t.infstr),m=i.length>0?Math.max(...i.map(b=>b.length)):1;return b=>Number.isNaN(b)?t.nanstr.padStart(m):Number.isFinite(b)?b.toString().padStart(m):((b>0?"":"-")+t.infstr).padStart(m)}const r=t.suppress?e.map(i=>Math.abs(i)<1e-10&&i!==0?0:i):e,a=r.map(Math.abs).filter(i=>i>0),o=a.length>0?Math.max(...a):0,g=a.length>0?Math.min(...a):0;if(o>=1e16||g>0&&g<1e-4||g>0&&o/g>1e3){const i=r.map(c=>w(c,t.precision,!1,".",t.sign));let m=0;for(const c of i){const y=c.indexOf("e"),O=y!==-1?c.slice(0,y):c,F=O.indexOf(".");F!==-1&&(m=Math.max(m,O.length-F-1))}const b=Math.max(m,0),l=Math.max(b,1),d=b===0?".":"k",S=r.map(c=>w(c,l,!1,d,t.sign));for(const c of n)Number.isFinite(c)||S.push(Number.isNaN(c)?t.nanstr:(c>0?"":"-")+t.infstr);const N=Math.max(...S.map(c=>c.length));return c=>(t.suppress&&Math.abs(c)<1e-10&&c!==0&&Number.isFinite(c)&&(c=0),Number.isNaN(c)?t.nanstr.padStart(N):Number.isFinite(c)?w(c,l,!1,d,t.sign).padStart(N):((c>0?"":"-")+t.infstr).padStart(N))}if(r.every(i=>Number.isInteger(i))){const i=r.map(l=>T(l,t.sign));for(const l of n)Number.isFinite(l)||i.push(Number.isNaN(l)?t.nanstr:(l>0?"":"-")+t.infstr);const{maxLeft:m,maxRight:b}=W(i);return l=>(t.suppress&&Math.abs(l)<1e-10&&l!==0&&Number.isFinite(l)&&(l=0),Number.isNaN(l)?M(t.nanstr,m,b):Number.isFinite(l)?M(T(l,t.sign),m,b):M((l>0?"":"-")+t.infstr,m,b))}const u=r.map(i=>C(i,t.precision,!1,!0,".",t.sign));for(const i of n)Number.isFinite(i)||u.push(Number.isNaN(i)?t.nanstr:(i>0?"":"-")+t.infstr);const{maxLeft:s,maxRight:p}=W(u);return i=>(t.suppress&&Math.abs(i)<1e-10&&i!==0&&Number.isFinite(i)&&(i=0),Number.isNaN(i)?M(t.nanstr,s,p):Number.isFinite(i)?M(C(i,t.precision,!1,!0,".",t.sign),s,p):M((i>0?"":"-")+t.infstr,s,p))}function j(n,t){const e=n.dtype,r=$(n,t);if(r.length===0)return o=>P(o,e,t);if(e==="bool")return o=>o?" True":"False";if(e==="int64"||e==="uint64"){const o=r.map(f=>f.toString()),g=Math.max(...o.map(f=>f.length));return f=>f.toString().padStart(g)}if(e.startsWith("int")||e.startsWith("uint")){const o=r.map(f=>f.toString()),g=Math.max(...o.map(f=>f.length));return f=>f.toString().padStart(g)}if(e==="complex64"||e==="complex128"){const o=r.map(u=>u.re),g=r.map(u=>Math.abs(u.im)),f=A(o,t),h=A(g,t);return u=>{const s=u,p=f(s.re),i=h(Math.abs(s.im)),m=s.im>=0?"+":"-";return`${p}${m}${i}j`}}const a=A(r,t);return o=>a(o)}function I(n,t,e,r,a,o){const g=n.shape,f=g.length;if(e===f){let l=0;const d=n.strides;for(let N=0;N<f;N++)l+=t[N]*d[N];const S=n.iget(l);return a(S)}const h=g[e],u=r.threshold,s=r.edgeitems,i=g.reduce((l,d)=>l*d,1)>u&&h>2*s,m=[],b=[...t];if(i){for(let l=0;l<s;l++)b[e]=l,m.push(I(n,b,e+1,r,a,o+1));m.push("...");for(let l=h-s;l<h;l++)b[e]=l,m.push(I(n,b,e+1,r,a,o+1))}else for(let l=0;l<h;l++)b[e]=l,m.push(I(n,b,e+1,r,a,o+1));if(e===f-1){const l="["+m.join(r.separator)+"]";if(o+l.length<r.linewidth)return l;const d=" ".repeat(o+1),S=r.linewidth-o-1,N=[];let c="";for(let y=0;y<m.length;y++){const O=m[y];if(c==="")c=O;else{const F=c+r.separator+O;F.length<S?c=F:(N.push(c),c=O)}}return c&&N.push(c),"["+N.join(`
2
+ `+d)+"]"}else{const l=" ".repeat(o+1),d=f-e-2,S=`
3
+ `+`
4
+ `.repeat(Math.max(0,d))+l;return"["+m.join(S)+"]"}}function k(n,t=null,e=null,r=null,a=" ",o="",g="",f=null,h=null,u=null,s=null){const p={...x,linewidth:t??x.linewidth,precision:e??x.precision,suppress:r??x.suppress,separator:a,prefix:o,suffix:g,threshold:f??x.threshold,edgeitems:h??x.edgeitems,floatmode:u??x.floatmode,sign:s??x.sign};if(n.ndim===0){const l=n.iget(0);return P(l,n.dtype,p)}const i=j(n,p),m=p.prefix.length,b=I(n,new Array(n.ndim).fill(0),0,p,i,m);return p.prefix+b+p.suffix}function G(n,t=null,e=null,r=null){let o="array("+k(n,t,e,r,", ");return n.dtype!=="float64"&&(o+=`, dtype='${n.dtype}'`),o+=")",o}function H(n,t=null,e=null,r=null){return k(n,t,e,r)}export{k as array2string,G as array_repr,H as array_str,U as base_repr,B as binary_repr,C as format_float_positional,w as format_float_scientific,E as get_printoptions,R as printoptions,q as set_printoptions};
@@ -1,2 +1,2 @@
1
- import{ArrayStorage as z}from"../storage";import{promoteDTypes as V,isComplexDType as k,isBigIntDType as J}from"../dtype";import{Complex as I}from"../complex";import*as R from"./shape";function T(t,e){if(t instanceof I||e instanceof I){const g=t instanceof I?t:new I(Number(t),0),p=e instanceof I?e:new I(Number(e),0);return g.mul(p)}return typeof t=="bigint"&&typeof e=="bigint"?Number(t*e):Number(t)*Number(e)}function ce(t,e,g,p,o,c,f,a,h){for(let s=0;s<g;s++)for(let i=0;i<c;i++)for(let l=0;l<f;l++){let n=0;for(let m=0;m<a;m++)n+=t[e+s*a+m]*p[o+i*a*f+m*f+l];h[s*c*f+i*f+l]=n}}function me(t,e,g,p,o,c,f,a,h,s){for(let i=0;i<g;i++)for(let l=0;l<f;l++){let n=0;for(let m=0;m<h;m++){const r=p===1?m:i*h+m,u=a===1?m:l*h+m;n+=t[e+r]*o[c+u]}s[g===1?l:i*f+l]=n}}function fe(t,e,g,p,o,c,f,a,h,s,i,l){for(let r=0;r<g*p;r++)i[r]=0;const n=t==="transpose",m=e==="transpose";if(!n&&!m)for(let r=0;r<g;r++)for(let u=0;u<p;u++){let b=0;for(let y=0;y<o;y++)b+=(f[r*a+y]??0)*(h[y*s+u]??0);i[r*l+u]=c*b}else if(n&&!m)for(let r=0;r<g;r++)for(let u=0;u<p;u++){let b=0;for(let y=0;y<o;y++)b+=(f[y*a+r]??0)*(h[y*s+u]??0);i[r*l+u]=c*b}else if(!n&&m)for(let r=0;r<g;r++)for(let u=0;u<p;u++){let b=0;for(let y=0;y<o;y++)b+=(f[r*a+y]??0)*(h[u*s+y]??0);i[r*l+u]=c*b}else for(let r=0;r<g;r++)for(let u=0;u<p;u++){let b=0;for(let y=0;y<o;y++)b+=(f[y*a+r]??0)*(h[u*s+y]??0);i[r*l+u]=c*b}}function X(t,e){const g=t.ndim,p=e.ndim,o=k(t.dtype)||k(e.dtype);if(g===0||p===0){const c=g===0?t.get():null,f=p===0?e.get():null;if(g===0&&p===0)return T(c,f);if(g===0){const a=V(t.dtype,e.dtype),h=z.zeros([...e.shape],a),s=(i,l)=>{const n=new Array(l.length);let m=i;for(let r=l.length-1;r>=0;r--)n[r]=m%l[r],m=Math.floor(m/l[r]);return n};for(let i=0;i<e.size;i++){const l=s(i,e.shape),n=e.get(...l);h.set(l,T(c,n))}return h}else{const a=V(t.dtype,e.dtype),h=z.zeros([...t.shape],a),s=(i,l)=>{const n=new Array(l.length);let m=i;for(let r=l.length-1;r>=0;r--)n[r]=m%l[r],m=Math.floor(m/l[r]);return n};for(let i=0;i<t.size;i++){const l=s(i,t.shape),n=t.get(...l);h.set(l,T(n,f))}return h}}if(g===1&&p===1){if(t.shape[0]!==e.shape[0])throw new Error(`dot: incompatible shapes (${t.shape[0]},) and (${e.shape[0]},)`);const c=t.shape[0];if(o){let a=0,h=0;for(let s=0;s<c;s++){const i=t.get(s),l=e.get(s),n=T(i,l);n instanceof I?(a+=n.re,h+=n.im):a+=n}return new I(a,h)}let f=0;for(let a=0;a<c;a++){const h=t.get(a),s=e.get(a);typeof h=="bigint"&&typeof s=="bigint"?f=Number(f)+Number(h*s):f+=Number(h)*Number(s)}return f}if(g===2&&p===2)return B(t,e);if(g===2&&p===1){const[c,f]=t.shape,a=e.shape[0];if(f!==a)throw new Error(`dot: incompatible shapes (${c},${f}) and (${a},)`);const h=V(t.dtype,e.dtype),s=z.zeros([c],h);if(o)for(let i=0;i<c;i++){let l=0,n=0;for(let m=0;m<f;m++){const r=t.get(i,m),u=e.get(m),b=r instanceof I?r:new I(Number(r),0),y=u instanceof I?u:new I(Number(u),0);l+=b.re*y.re-b.im*y.im,n+=b.re*y.im+b.im*y.re}s.set([i],new I(l,n))}else for(let i=0;i<c;i++){let l=0;for(let n=0;n<f;n++){const m=t.get(i,n),r=e.get(n);typeof m=="bigint"&&typeof r=="bigint"?l=Number(l)+Number(m*r):l+=Number(m)*Number(r)}s.set([i],l)}return s}if(g===1&&p===2){const c=t.shape[0],[f,a]=e.shape;if(c!==f)throw new Error(`dot: incompatible shapes (${c},) and (${f},${a})`);const h=V(t.dtype,e.dtype),s=z.zeros([a],h);if(o)for(let i=0;i<a;i++){let l=0,n=0;for(let m=0;m<c;m++){const r=t.get(m),u=e.get(m,i),b=r instanceof I?r:new I(Number(r),0),y=u instanceof I?u:new I(Number(u),0);l+=b.re*y.re-b.im*y.im,n+=b.re*y.im+b.im*y.re}s.set([i],new I(l,n))}else for(let i=0;i<a;i++){let l=0;for(let n=0;n<c;n++){const m=t.get(n),r=e.get(n,i);typeof m=="bigint"&&typeof r=="bigint"?l=Number(l)+Number(m*r):l+=Number(m)*Number(r)}s.set([i],l)}return s}if(g>2&&p===1){const c=t.shape[g-1],f=e.shape[0];if(c!==f)throw new Error(`dot: incompatible shapes ${JSON.stringify(t.shape)} and (${f},)`);const a=[...t.shape.slice(0,-1)],h=V(t.dtype,e.dtype),s=z.zeros(a,h),i=a.reduce((l,n)=>l*n,1);if(o)for(let l=0;l<i;l++){let n=0,m=0,r=l;const u=[];for(let b=a.length-1;b>=0;b--)u[b]=r%a[b],r=Math.floor(r/a[b]);for(let b=0;b<c;b++){const y=[...u,b],w=t.get(...y),d=e.get(b),x=w instanceof I?w:new I(Number(w),0),A=d instanceof I?d:new I(Number(d),0);n+=x.re*A.re-x.im*A.im,m+=x.re*A.im+x.im*A.re}s.set(u,new I(n,m))}else for(let l=0;l<i;l++){let n=0,m=l;const r=[];for(let u=a.length-1;u>=0;u--)r[u]=m%a[u],m=Math.floor(m/a[u]);for(let u=0;u<c;u++){const b=[...r,u],y=t.get(...b),w=e.get(u);typeof y=="bigint"&&typeof w=="bigint"?n=Number(n)+Number(y*w):n+=Number(y)*Number(w)}s.set(r,n)}return s}if(g===1&&p>2){const c=t.shape[0],f=1,a=e.shape[f];if(c!==a)throw new Error(`dot: incompatible shapes (${c},) and ${JSON.stringify(e.shape)}`);const h=[...e.shape.slice(0,f),...e.shape.slice(f+1)],s=V(t.dtype,e.dtype),i=z.zeros(h,s),l=h.reduce((n,m)=>n*m,1);if(o)for(let n=0;n<l;n++){let m=n;const r=[];for(let d=h.length-1;d>=0;d--)r[d]=m%h[d],m=Math.floor(m/h[d]);const u=r.slice(0,f),b=r.slice(f);let y=0,w=0;for(let d=0;d<c;d++){const x=t.get(d),A=[...u,d,...b],S=e.get(...A),v=x instanceof I?x:new I(Number(x),0),N=S instanceof I?S:new I(Number(S),0);y+=v.re*N.re-v.im*N.im,w+=v.re*N.im+v.im*N.re}i.set(r,new I(y,w))}else for(let n=0;n<l;n++){let m=n;const r=[];for(let w=h.length-1;w>=0;w--)r[w]=m%h[w],m=Math.floor(m/h[w]);const u=r.slice(0,f),b=r.slice(f);let y=0;for(let w=0;w<c;w++){const d=t.get(w),x=[...u,w,...b],A=e.get(...x);typeof d=="bigint"&&typeof A=="bigint"?y=Number(y)+Number(d*A):y+=Number(d)*Number(A)}i.set(r,y)}return i}if(g>=2&&p>=2&&!(g===2&&p===2)){const c=t.shape[g-1],f=e.shape[p-2];if(c!==f)throw new Error(`dot: incompatible shapes ${JSON.stringify(t.shape)} and ${JSON.stringify(e.shape)}`);const a=[...t.shape.slice(0,-1),...e.shape.slice(0,-2),e.shape[p-1]],h=V(t.dtype,e.dtype),s=z.zeros(a,h),i=t.shape.slice(0,-1).reduce((r,u)=>r*u,1),l=e.shape.slice(0,-2).reduce((r,u)=>r*u,1),n=e.shape[p-1],m=c;if(o)for(let r=0;r<i;r++)for(let u=0;u<l;u++)for(let b=0;b<n;b++){let y=0,w=0;for(let A=0;A<m;A++){const S=[];let v=r;for(let j=t.shape.length-2;j>=0;j--)S.unshift(v%t.shape[j]),v=Math.floor(v/t.shape[j]);S.push(A);const N=t.get(...S),M=[];let $=u;for(let j=e.shape.length-3;j>=0;j--)M.unshift($%e.shape[j]),$=Math.floor($/e.shape[j]);M.push(A,b);const D=e.get(...M),E=N instanceof I?N:new I(Number(N),0),C=D instanceof I?D:new I(Number(D),0);y+=E.re*C.re-E.im*C.im,w+=E.re*C.im+E.im*C.re}const d=r*l*n+u*n+b,x=s.data;x[d*2]=y,x[d*2+1]=w}else if(t.isCContiguous&&e.isCContiguous&&!J(t.dtype)&&!J(e.dtype))ce(t.data,t.offset,i,e.data,e.offset,l,n,m,s.data);else for(let r=0;r<i;r++)for(let u=0;u<l;u++)for(let b=0;b<n;b++){let y=0;for(let d=0;d<m;d++){const x=r*m+d,A=u*m*n+d*n+b,S=t.iget(x),v=e.iget(A);typeof S=="bigint"&&typeof v=="bigint"?y=Number(y)+Number(S*v):y+=Number(S)*Number(v)}const w=r*l*n+u*n+b;s.data[w]=y}return s}throw new Error(`dot: unexpected combination of dimensions ${g}D \xB7 ${p}D`)}function B(t,e){if(t.ndim!==2||e.ndim!==2)throw new Error("matmul requires 2D arrays");const[g=0,p=0]=t.shape,[o=0,c=0]=e.shape;if(p!==o)throw new Error(`matmul shape mismatch: (${g},${p}) @ (${o},${c})`);const f=V(t.dtype,e.dtype);if(k(f)){const A=z.zeros([g,c],f),S=A.data;for(let v=0;v<g;v++)for(let N=0;N<c;N++){let M=0,$=0;for(let E=0;E<p;E++){const C=t.iget(v*p+E),j=e.iget(E*c+N);M+=C.re*j.re-C.im*j.im,$+=C.re*j.im+C.im*j.re}const D=v*c+N;S[D*2]=M,S[D*2+1]=$}return A}const a=f.startsWith("int")||f.startsWith("uint")||f==="bool"?"float64":f;if(a!=="float64")throw new Error(`matmul currently only supports float64, got ${a}`);let h=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number)),s=e.dtype==="float64"?e.data:Float64Array.from(Array.from(e.data).map(Number));t.offset>0&&(h=h.subarray(t.offset)),e.offset>0&&(s=s.subarray(e.offset));const[i=0,l=0]=t.strides,[n=0,m=0]=e.strides,r=l>i,u=m>n,b=r?"transpose":"no-transpose",y=u?"transpose":"no-transpose";let w,d;r?w=l:w=i,u?d=m:d=n;const x=z.zeros([g,c],"float64");return fe(b,y,g,c,p,1,h,w,s,d,x.data,c),x}function $e(t){if(t.ndim!==2)throw new Error(`trace requires 2D array, got ${t.ndim}D`);const[e=0,g=0]=t.shape,p=Math.min(e,g);if(k(t.dtype)){let c=0,f=0;for(let a=0;a<p;a++){const h=t.get(a,a);c+=h.re,f+=h.im}return new I(c,f)}let o=0;for(let c=0;c<p;c++){const f=t.get(c,c);typeof f=="bigint"?o=(typeof o=="bigint"?o:BigInt(o))+f:o=(typeof o=="bigint"?Number(o):o)+f}return o}function L(t,e){return R.transpose(t,e)}function Me(t,e){const g=t.ndim,p=e.ndim,o=k(t.dtype)||k(e.dtype),c=t.shape[g-1],f=e.shape[p-1];if(c!==f)throw new Error(`inner: incompatible shapes - last dimensions ${c} and ${f} don't match`);if(g===1&&p===1)return X(t,e);const a=[...t.shape.slice(0,-1),...e.shape.slice(0,-1)],h=V(t.dtype,e.dtype),s=z.zeros(a,h),i=g===1?1:t.shape.slice(0,-1).reduce((m,r)=>m*r,1),l=p===1?1:e.shape.slice(0,-1).reduce((m,r)=>m*r,1),n=c;if(o)for(let m=0;m<i;m++)for(let r=0;r<l;r++){let u=0,b=0;for(let d=0;d<n;d++){let x,A;if(g===1)x=t.get(d);else{const N=[];let M=m;const $=t.shape.slice(0,-1);for(let D=$.length-1;D>=0;D--)N.unshift(M%$[D]),M=Math.floor(M/$[D]);N.push(d),x=t.get(...N)}if(p===1)A=e.get(d);else{const N=[];let M=r;const $=e.shape.slice(0,-1);for(let D=$.length-1;D>=0;D--)N.unshift(M%$[D]),M=Math.floor(M/$[D]);N.push(d),A=e.get(...N)}const S=x instanceof I?x:new I(Number(x),0),v=A instanceof I?A:new I(Number(A),0);u+=S.re*v.re-S.im*v.im,b+=S.re*v.im+S.im*v.re}if(a.length===0)return new I(u,b);const y=i===1?r:m*l+r,w=s.data;w[y*2]=u,w[y*2+1]=b}else if(t.isCContiguous&&e.isCContiguous&&!J(t.dtype)&&!J(e.dtype)){if(a.length===0){const m=t.data,r=e.data,u=t.offset,b=e.offset;let y=0;for(let w=0;w<n;w++)y+=m[u+w]*r[b+w];return y}me(t.data,t.offset,i,g,e.data,e.offset,l,p,n,s.data)}else for(let m=0;m<i;m++)for(let r=0;r<l;r++){let u=0;for(let y=0;y<n;y++){const w=g===1?y:m*n+y,d=p===1?y:r*n+y,x=t.iget(w),A=e.iget(d);typeof x=="bigint"&&typeof A=="bigint"?u=Number(u)+Number(x*A):u+=Number(x)*Number(A)}if(a.length===0)return u;const b=i===1?r:m*l+r;s.data[b]=u}return s}function pe(t,e){const g=t.ndim===1?t:R.ravel(t),p=e.ndim===1?e:R.ravel(e),o=g.size,c=p.size,f=V(t.dtype,e.dtype),a=z.zeros([o,c],f);for(let h=0;h<o;h++)for(let s=0;s<c;s++){const i=g.get(h),l=p.get(s),n=T(i,l);a.set([h,s],n)}return a}function De(t,e,g){let p,o;if(typeof g=="number"){const r=g;if(r<0)throw new Error("tensordot: axes must be non-negative");if(r>t.ndim||r>e.ndim)throw new Error("tensordot: axes exceeds array dimensions");p=Array.from({length:r},(u,b)=>t.ndim-r+b),o=Array.from({length:r},(u,b)=>b)}else if([p,o]=g,p.length!==o.length)throw new Error("tensordot: axes lists must have same length");for(let r=0;r<p.length;r++){const u=p[r],b=o[r];if(u<0||u>=t.ndim||b<0||b>=e.ndim)throw new Error("tensordot: axis out of bounds");if(t.shape[u]!==e.shape[b])throw new Error(`tensordot: shape mismatch on axes ${u} and ${b}: ${t.shape[u]} != ${e.shape[b]}`)}const c=[],f=[];for(let r=0;r<t.ndim;r++)p.includes(r)||c.push(r);for(let r=0;r<e.ndim;r++)o.includes(r)||f.push(r);const a=[...c.map(r=>t.shape[r]),...f.map(r=>e.shape[r])],h=V(t.dtype,e.dtype),s=k(h),i=r=>r instanceof I?{re:r.re,im:r.im}:{re:Number(r),im:0};if(a.length===0){let r=0,u=0;const b=p.map(y=>t.shape[y]).reduce((y,w)=>y*w,1);for(let y=0;y<b;y++){let w=y;const d=new Array(p.length);for(let N=p.length-1;N>=0;N--){const M=p[N];d[N]=w%t.shape[M],w=Math.floor(w/t.shape[M])}const x=new Array(t.ndim),A=new Array(e.ndim);for(let N=0;N<p.length;N++)x[p[N]]=d[N];for(let N=0;N<o.length;N++)A[o[N]]=d[N];const S=t.get(...x),v=e.get(...A);if(s){const N=i(S),M=i(v);r+=N.re*M.re-N.im*M.im,u+=N.re*M.im+N.im*M.re}else typeof S=="bigint"&&typeof v=="bigint"?r+=Number(S*v):r+=Number(S)*Number(v)}return s?new I(r,u):r}const l=z.zeros(a,h),n=a.reduce((r,u)=>r*u,1),m=p.map(r=>t.shape[r]).reduce((r,u)=>r*u,1);for(let r=0;r<n;r++){let u=r;const b=[];for(let A=a.length-1;A>=0;A--)b[A]=u%a[A],u=Math.floor(u/a[A]);const y=b.slice(0,c.length),w=b.slice(c.length);let d=0,x=0;for(let A=0;A<m;A++){u=A;const S=[];for(let D=p.length-1;D>=0;D--){const E=p[D];S[D]=u%t.shape[E],u=Math.floor(u/t.shape[E])}const v=new Array(t.ndim),N=new Array(e.ndim);for(let D=0;D<c.length;D++)v[c[D]]=y[D];for(let D=0;D<f.length;D++)N[f[D]]=w[D];for(let D=0;D<p.length;D++)v[p[D]]=S[D],N[o[D]]=S[D];const M=t.get(...v),$=e.get(...N);if(s){const D=i(M),E=i($);d+=D.re*E.re-D.im*E.im,x+=D.re*E.im+D.im*E.re}else typeof M=="bigint"&&typeof $=="bigint"?d+=Number(M*$):d+=Number(M)*Number($)}s?l.set(b,new I(d,x)):l.set(b,d)}return l}function ze(t,e=0,g=0,p=1){const o=t.shape,c=o.length;if(c<2)throw new Error("diagonal requires an array of at least two dimensions");const f=g<0?c+g:g,a=p<0?c+p:p;if(f<0||f>=c||a<0||a>=c)throw new Error("axis out of bounds");if(f===a)throw new Error("axis1 and axis2 cannot be the same");const h=o[f],s=o[a];let i;e>=0?i=Math.max(0,Math.min(h,s-e)):i=Math.max(0,Math.min(h+e,s));const l=[];for(let u=0;u<c;u++)u!==f&&u!==a&&l.push(o[u]);l.push(i);const n=z.zeros(l,t.dtype),m=o.filter((u,b)=>b!==f&&b!==a),r=m.reduce((u,b)=>u*b,1);for(let u=0;u<r;u++){let b=u;const y=[];for(let w=m.length-1;w>=0;w--)y.unshift(b%m[w]),b=Math.floor(b/m[w]);for(let w=0;w<i;w++){const d=new Array(c);let x=0;for(let v=0;v<c;v++)v===f?d[v]=e>=0?w:w-e:v===a?d[v]=e>=0?w+e:w:d[v]=y[x++];const A=[...y,w],S=t.get(...d);n.set(A,S)}}return n}function Ce(t,...e){const g=t.indexOf("->");let p,o;g===-1?(p=t,o=ne(p)):(p=t.slice(0,g),o=t.slice(g+2));const c=p.split(",").map(u=>u.trim());if(c.length!==e.length)throw new Error(`einsum: expected ${c.length} operands, got ${e.length}`);const f=new Map;for(let u=0;u<e.length;u++){const b=c[u],y=e[u];if(b.length!==y.ndim)throw new Error(`einsum: operand ${u} has ${y.ndim} dimensions but subscript '${b}' has ${b.length} indices`);for(let w=0;w<b.length;w++){const d=b[w],x=y.shape[w];if(f.has(d)){if(f.get(d)!==x)throw new Error(`einsum: size mismatch for index '${d}': ${f.get(d)} vs ${x}`)}else f.set(d,x)}}for(const u of o)if(!f.has(u))throw new Error(`einsum: output subscript contains unknown index '${u}'`);const a=new Set(o),h=new Set;for(const u of c)for(const b of u)h.add(b);const s=[];for(const u of h)a.has(u)||s.push(u);if(e.length===2&&c.length===2){const[u,b]=c,[y,w]=e;if(u.length===2&&b.length===2&&o.length===2&&y.ndim===2&&w.ndim===2){const[d,x]=[u[0],u[1]],[A,S]=[b[0],b[1]],[v,N]=[o[0],o[1]];if(d===v&&S===N&&x===A&&s.length===1&&s[0]===x||d===v&&S===N&&x===A&&s.length===1&&s[0]===x)return B(y,w);if(x===v&&S===N&&d===A&&s.length===1&&s[0]===d){const M=L(y);return B(M,w)}if(d===v&&A===N&&x===S&&s.length===1&&s[0]===x){const M=L(w);return B(y,M)}}if(u.length===1&&b.length===1&&u===b&&o.length===0&&y.ndim===1&&w.ndim===1)return Y(e,c,s,f);if(u&&b&&u.length===1&&b.length===1&&o.length===2&&o===u+b&&s.length===0&&y.ndim===1&&w.ndim===1)return pe(y,w)}if(e.length===1&&c[0].length===2&&o.length===0){const u=c[0];if(u[0]===u[1]&&e[0].ndim===2)return Y(e,c,s,f)}const i=Array.from(o).map(u=>f.get(u));if(i.length===0)return Y(e,c,s,f);let l=e[0].dtype;for(let u=1;u<e.length;u++)l=V(l,e[u].dtype);const n=z.zeros(i,l),m=i.reduce((u,b)=>u*b,1);let r=1;for(const u of s)r*=f.get(u);for(let u=0;u<m;u++){const b=he(u,i),y=new Map;for(let d=0;d<o.length;d++)y.set(o[d],b[d]);let w=0;for(let d=0;d<r;d++){let x=d;for(let S=s.length-1;S>=0;S--){const v=s[S],N=f.get(v);y.set(v,x%N),x=Math.floor(x/N)}let A=1;for(let S=0;S<e.length;S++){const v=e[S],N=c[S],M=[];for(const D of N)M.push(y.get(D));const $=v.get(...M);A*=Number($)}w+=A}n.set(b,w)}return n}function ne(t){const e=new Map,g=t.split(",");for(const o of g)for(const c of o.trim())e.set(c,(e.get(c)||0)+1);const p=[];for(const[o,c]of e)c===1&&p.push(o);return p.sort().join("")}function Y(t,e,g,p){let o=!1;for(const s of t)if(k(s.dtype)){o=!0;break}const c=s=>s instanceof I?{re:s.re,im:s.im}:{re:Number(s),im:0};let f=1;for(const s of g)f*=p.get(s);let a=0,h=0;for(let s=0;s<f;s++){const i=new Map;let l=s;for(let r=g.length-1;r>=0;r--){const u=g[r],b=p.get(u);i.set(u,l%b),l=Math.floor(l/b)}let n=1,m=0;for(let r=0;r<t.length;r++){const u=t[r],b=e[r],y=[];for(const d of b)y.push(i.get(d));const w=u.get(...y);if(o){const d=c(w),x=n*d.re-m*d.im,A=n*d.im+m*d.re;n=x,m=A}else n*=Number(w)}a+=n,h+=m}return o?new I(a,h):a}function he(t,e){const g=new Array(e.length);let p=t;for(let o=e.length-1;o>=0;o--)g[o]=p%e[o],p=Math.floor(p/e[o]);return g}function Ee(t,e){const g=t.shape,p=e.shape,o=g.length,c=p.length,f=V(t.dtype,e.dtype),a=Math.max(o,c),h=new Array(a),s=new Array(a).fill(1),i=new Array(a).fill(1);for(let r=0;r<o;r++)s[a-o+r]=g[r];for(let r=0;r<c;r++)i[a-c+r]=p[r];for(let r=0;r<a;r++)h[r]=s[r]*i[r];const l=z.zeros(h,f),n=g.reduce((r,u)=>r*u,1),m=p.reduce((r,u)=>r*u,1);for(let r=0;r<n;r++){let u=r;const b=new Array(o);for(let d=o-1;d>=0;d--)b[d]=u%g[d],u=Math.floor(u/g[d]);const y=new Array(a).fill(0);for(let d=0;d<o;d++)y[a-o+d]=b[d];const w=t.get(...b);for(let d=0;d<m;d++){let x=d;const A=new Array(c);for(let $=c-1;$>=0;$--)A[$]=x%p[$],x=Math.floor(x/p[$]);const S=new Array(a).fill(0);for(let $=0;$<c;$++)S[a-c+$]=A[$];const v=e.get(...A),N=new Array(a);for(let $=0;$<a;$++)N[$]=y[$]*i[$]+S[$];const M=T(w,v);l.set(N,M)}}return l}function je(t,e,g=-1,p=-1,o=-1,c){c!==void 0&&(g=c,p=c,o=c);const f=(N,M)=>N<0?M+N:N,a=f(g,t.ndim),h=f(p,e.ndim),s=V(t.dtype,e.dtype),i=k(s),l=(N,...M)=>{const $=N.get(...M);return $ instanceof I?$:Number($)},n=(N,M)=>{if(N instanceof I||M instanceof I){const $=N instanceof I?N:new I(N,0),D=M instanceof I?M:new I(M,0);return $.mul(D)}return N*M},m=(N,M)=>{if(N instanceof I||M instanceof I){const $=N instanceof I?N:new I(N,0),D=M instanceof I?M:new I(M,0);return $.sub(D)}return N-M};if(t.ndim===1&&e.ndim===1){const N=t.shape[0],M=e.shape[0];if(N===3&&M===3){const $=l(t,0),D=l(t,1),E=l(t,2),C=l(e,0),j=l(e,1),F=l(e,2),q=z.zeros([3],s);return q.set([0],m(n(D,F),n(E,j))),q.set([1],m(n(E,C),n($,F))),q.set([2],m(n($,j),n(D,C))),q}else if(N===2&&M===2){const $=l(t,0),D=l(t,1),E=l(e,0),C=l(e,1);return m(n($,C),n(D,E))}else if(N===2&&M===3||N===3&&M===2){const $=l(t,0),D=l(t,1),E=N===3?l(t,2):i?new I(0,0):0,C=l(e,0),j=l(e,1),F=M===3?l(e,2):i?new I(0,0):0,q=z.zeros([3],s);return q.set([0],m(n(D,F),n(E,j))),q.set([1],m(n(E,C),n($,F))),q.set([2],m(n($,j),n(D,C))),q}else throw new Error(`cross: incompatible dimensions for cross product: ${N} and ${M}`)}const r=t.shape[a],u=e.shape[h];if(r!==2&&r!==3||u!==2&&u!==3)throw new Error(`cross: incompatible dimensions for cross product: ${r} and ${u}`);const b=r===2&&u===2?0:3,y=[...t.shape.slice(0,a),...t.shape.slice(a+1)],w=[...e.shape.slice(0,h),...e.shape.slice(h+1)];if(y.length!==w.length)throw new Error("cross: incompatible shapes for cross product");for(let N=0;N<y.length;N++)if(y[N]!==w[N])throw new Error("cross: incompatible shapes for cross product");const d=y,x=o<0?d.length+1+o:o;let A;if(b===0?A=d:A=[...d.slice(0,x),b,...d.slice(x)],A.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");const S=z.zeros(A,s),v=d.reduce((N,M)=>N*M,1);for(let N=0;N<v;N++){let M=N;const $=[];for(let _=d.length-1;_>=0;_--)$[_]=M%d[_],M=Math.floor(M/d[_]);const D=[...$.slice(0,a),0,...$.slice(a)],E=[...$.slice(0,h),0,...$.slice(h)],C=_=>(D[a]=_,l(t,...D)),j=_=>(E[h]=_,l(e,...E)),F=C(0),q=C(1),te=r===3?C(2):i?new I(0,0):0,U=j(0),G=j(1),re=u===3?j(2):i?new I(0,0):0;if(b===0)S.set($,m(n(F,G),n(q,U)));else{const _=m(n(q,re),n(te,G)),se=m(n(te,U),n(F,re)),ie=m(n(F,G),n(q,U)),H=(le,ae)=>{const ue=[...$.slice(0,x),le,...$.slice(x)];S.set(ue,ae)};H(0,_),H(1,se),H(2,ie)}}return S}function W(t,e=2,g,p=!1){if(typeof e!="number")throw new Error("vector_norm: ord must be a number");if(g==null){const s=t.ndim===1?t:R.ravel(t),i=s.size;let l;if(e===1/0){l=0;for(let n=0;n<i;n++)l=Math.max(l,Math.abs(Number(s.get(n))))}else if(e===-1/0){l=1/0;for(let n=0;n<i;n++)l=Math.min(l,Math.abs(Number(s.get(n))))}else if(e===0){l=0;for(let n=0;n<i;n++)Number(s.get(n))!==0&&l++}else if(e===1){l=0;for(let n=0;n<i;n++)l+=Math.abs(Number(s.get(n)))}else if(e===2){l=0;for(let n=0;n<i;n++){const m=Number(s.get(n));l+=m*m}l=Math.sqrt(l)}else{l=0;for(let n=0;n<i;n++)l+=Math.pow(Math.abs(Number(s.get(n))),e);l=Math.pow(l,1/e)}if(p){const n=new Array(t.ndim).fill(1),m=z.zeros(n,"float64");return m.set(new Array(t.ndim).fill(0),l),m}return l}const o=g<0?t.ndim+g:g;if(o<0||o>=t.ndim)throw new Error(`vector_norm: axis ${g} out of bounds for array with ${t.ndim} dimensions`);const c=p?[...t.shape.slice(0,o),1,...t.shape.slice(o+1)]:[...t.shape.slice(0,o),...t.shape.slice(o+1)];if(c.length===0)return W(t,e,null,!1);const f=z.zeros(c,"float64"),a=t.shape[o],h=c.reduce((s,i)=>s*i,1);for(let s=0;s<h;s++){let i=s;const l=[];for(let r=c.length-1;r>=0;r--)l[r]=i%c[r],i=Math.floor(i/c[r]);const n=p?[...l.slice(0,o),0,...l.slice(o+1)]:[...l.slice(0,o),0,...l.slice(o)];let m;if(e===1/0){m=0;for(let r=0;r<a;r++)n[o]=r,m=Math.max(m,Math.abs(Number(t.get(...n))))}else if(e===-1/0){m=1/0;for(let r=0;r<a;r++)n[o]=r,m=Math.min(m,Math.abs(Number(t.get(...n))))}else if(e===0){m=0;for(let r=0;r<a;r++)n[o]=r,Number(t.get(...n))!==0&&m++}else if(e===1){m=0;for(let r=0;r<a;r++)n[o]=r,m+=Math.abs(Number(t.get(...n)))}else if(e===2){m=0;for(let r=0;r<a;r++){n[o]=r;const u=Number(t.get(...n));m+=u*u}m=Math.sqrt(m)}else{m=0;for(let r=0;r<a;r++)n[o]=r,m+=Math.pow(Math.abs(Number(t.get(...n))),e);m=Math.pow(m,1/e)}f.set(l,m)}return f}function P(t,e="fro",g=!1){if(t.ndim!==2)throw new Error(`matrix_norm: input must be 2D, got ${t.ndim}D`);const[p,o]=t.shape;let c;if(e==="fro"){c=0;for(let f=0;f<p;f++)for(let a=0;a<o;a++){const h=Number(t.get(f,a));c+=h*h}c=Math.sqrt(c)}else if(e==="nuc"){const{s:f}=O(t);c=0;for(let a=0;a<f.size;a++)c+=Number(f.get(a))}else if(e===1){c=0;for(let f=0;f<o;f++){let a=0;for(let h=0;h<p;h++)a+=Math.abs(Number(t.get(h,f)));c=Math.max(c,a)}}else if(e===-1){c=1/0;for(let f=0;f<o;f++){let a=0;for(let h=0;h<p;h++)a+=Math.abs(Number(t.get(h,f)));c=Math.min(c,a)}}else if(e===1/0){c=0;for(let f=0;f<p;f++){let a=0;for(let h=0;h<o;h++)a+=Math.abs(Number(t.get(f,h)));c=Math.max(c,a)}}else if(e===-1/0){c=1/0;for(let f=0;f<p;f++){let a=0;for(let h=0;h<o;h++)a+=Math.abs(Number(t.get(f,h)));c=Math.min(c,a)}}else if(e===2){const{s:f}=O(t);c=Number(f.get(0))}else if(e===-2){const{s:f}=O(t);c=Number(f.get(f.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${e}`);if(g){const f=z.zeros([1,1],"float64");return f.set([0,0],c),f}return c}function Ve(t,e=null,g=null,p=!1){if(e===null)return g===null?W(t,2,null,p):typeof g=="number"?W(t,2,g,p):P(t,"fro",p);if(Array.isArray(g)){if(g.length!==2)throw new Error("norm: axis must be a 2-tuple for matrix norms");const o=g[0]<0?t.ndim+g[0]:g[0],c=g[1]<0?t.ndim+g[1]:g[1];if(t.ndim!==2||o!==0&&o!==1||c!==0&&c!==1||o===c)throw new Error("norm: complex axis specification not yet supported");return P(t,e,p)}if(t.ndim===2&&g===null&&(e==="fro"||e==="nuc"))return P(t,e,p);if(typeof e!="number"&&e!==null)throw new Error(`norm: ord '${e}' not valid for vector norm`);return W(t,e??2,g,p)}function ge(t,e="reduced"){if(t.ndim!==2)throw new Error(`qr: input must be 2D, got ${t.ndim}D`);const[g,p]=t.shape,o=Math.min(g,p),c=z.zeros([g,p],"float64");for(let m=0;m<g;m++)for(let r=0;r<p;r++)c.set([m,r],Number(t.get(m,r)));const f=[],a=[];for(let m=0;m<o;m++){const r=g-m,u=[];for(let A=m;A<g;A++)u.push(Number(c.get(A,m)));let b=0;for(let A=0;A<r;A++)b+=u[A]*u[A];if(b=Math.sqrt(b),b<1e-15){f.push(u),a.push(0);continue}const y=u[0]>=0?1:-1,w=u[0]+y*b,d=[1];for(let A=1;A<r;A++)d.push(u[A]/w);const x=y*w/b;a.push(x),f.push(d);for(let A=m;A<p;A++){let S=0;for(let v=0;v<r;v++)S+=d[v]*Number(c.get(m+v,A));for(let v=0;v<r;v++)c.set([m+v,A],Number(c.get(m+v,A))-x*d[v]*S)}}if(e==="raw"){const m=z.zeros([g,p],"float64");for(let u=0;u<g;u++)for(let b=0;b<p;b++)m.set([u,b],Number(c.get(u,b)));const r=z.zeros([o],"float64");for(let u=0;u<o;u++)r.set([u],a[u]);return{h:m,tau:r}}if(e==="r"){const m=z.zeros([o,p],"float64");for(let r=0;r<o;r++)for(let u=r;u<p;u++)m.set([r,u],Number(c.get(r,u)));return m}const h=e==="complete"?g:o,s=z.zeros([g,h],"float64");for(let m=0;m<Math.min(g,h);m++)s.set([m,m],1);for(let m=o-1;m>=0;m--){const r=f[m],u=a[m],b=g-m;for(let y=m;y<h;y++){let w=0;for(let d=0;d<b;d++)w+=r[d]*Number(s.get(m+d,y));for(let d=0;d<b;d++)s.set([m+d,y],Number(s.get(m+d,y))-u*r[d]*w)}}const i=z.zeros([g,h],"float64");for(let m=0;m<g;m++)for(let r=0;r<h;r++)i.set([m,r],Number(s.get(m,r)));const l=e==="complete"?g:o,n=z.zeros([l,p],"float64");for(let m=0;m<l;m++)for(let r=0;r<p;r++)r>=m&&n.set([m,r],Number(c.get(m,r)));return{q:i,r:n}}function ke(t,e=!1){if(t.ndim!==2)throw new Error(`cholesky: input must be 2D, got ${t.ndim}D`);const[g,p]=t.shape;if(g!==p)throw new Error(`cholesky: matrix must be square, got ${g}x${p}`);const o=g,c=z.zeros([o,o],"float64");for(let f=0;f<o;f++)for(let a=0;a<=f;a++){let h=0;if(f===a){for(let i=0;i<a;i++)h+=Number(c.get(a,i))**2;const s=Number(t.get(a,a))-h;if(s<0)throw new Error("cholesky: matrix is not positive definite");c.set([a,a],Math.sqrt(s))}else{for(let i=0;i<a;i++)h+=Number(c.get(f,i))*Number(c.get(a,i));const s=Number(c.get(a,a));if(Math.abs(s)<1e-15)throw new Error("cholesky: matrix is not positive definite");c.set([f,a],(Number(t.get(f,a))-h)/s)}}if(e){const f=z.zeros([o,o],"float64");for(let a=0;a<o;a++)for(let h=a;h<o;h++)f.set([a,h],Number(c.get(h,a)));return f}return c}function O(t){if(t.ndim!==2)throw new Error(`svd: input must be 2D, got ${t.ndim}D`);const[e,g]=t.shape,p=Math.min(e,g),o=z.zeros([g,g],"float64");for(let l=0;l<g;l++)for(let n=0;n<g;n++){let m=0;for(let r=0;r<e;r++)m+=Number(t.get(r,l))*Number(t.get(r,n));o.set([l,n],m)}const{values:c,vectors:f}=Z(o),a=Array.from({length:g},(l,n)=>n);a.sort((l,n)=>c[n]-c[l]);const h=z.zeros([p],"float64");for(let l=0;l<p;l++){const n=c[a[l]];h.set([l],Math.sqrt(Math.max(0,n)))}const s=z.zeros([g,g],"float64");for(let l=0;l<g;l++)for(let n=0;n<g;n++)s.set([l,n],f[n][a[l]]);const i=z.zeros([e,e],"float64");for(let l=0;l<e;l++)for(let n=0;n<p;n++){const m=Number(h.get(n));if(m>1e-10){let r=0;for(let u=0;u<g;u++)r+=Number(t.get(l,u))*Number(s.get(n,u));i.set([l,n],r/m)}}if(e>p)for(let l=p;l<e;l++){const n=new Array(e).fill(0);n[l]=1;for(let r=0;r<l;r++){let u=0;for(let b=0;b<e;b++)u+=n[b]*Number(i.get(b,r));for(let b=0;b<e;b++)n[b]=n[b]-u*Number(i.get(b,r))}let m=0;for(let r=0;r<e;r++)m+=n[r]*n[r];if(m=Math.sqrt(m),m>1e-10)for(let r=0;r<e;r++)i.set([r,l],n[r]/m)}return{u:i,s:h,vt:s}}function Z(t){const e=t.shape[0],g=100*e*e,p=1e-10,o=[];for(let a=0;a<e;a++){o.push([]);for(let h=0;h<e;h++)o[a].push(Number(t.get(a,h)))}const c=[];for(let a=0;a<e;a++){c.push([]);for(let h=0;h<e;h++)c[a].push(a===h?1:0)}for(let a=0;a<g;a++){let h=0,s=0,i=1;for(let d=0;d<e;d++)for(let x=d+1;x<e;x++)Math.abs(o[d][x])>h&&(h=Math.abs(o[d][x]),s=d,i=x);if(h<p)break;const l=o[s][s],n=o[i][i],m=o[s][i];let r;Math.abs(l-n)<1e-15?r=Math.PI/4:r=.5*Math.atan2(2*m,n-l);const u=Math.cos(r),b=Math.sin(r),y=u*u*l+b*b*n-2*b*u*m,w=b*b*l+u*u*n+2*b*u*m;o[s][s]=y,o[i][i]=w,o[s][i]=0,o[i][s]=0;for(let d=0;d<e;d++)if(d!==s&&d!==i){const x=o[d][s],A=o[d][i];o[d][s]=u*x-b*A,o[s][d]=o[d][s],o[d][i]=b*x+u*A,o[i][d]=o[d][i]}for(let d=0;d<e;d++){const x=c[d][s],A=c[d][i];c[d][s]=u*x-b*A,c[d][i]=b*x+u*A}}const f=[];for(let a=0;a<e;a++)f.push(o[a][a]);return{values:f,vectors:c}}function be(t,e=!0,g=!0){const p=O(t);if(!g)return p.s;if(!e){const[o,c]=t.shape,f=Math.min(o,c),a=z.zeros([o,f],"float64");for(let s=0;s<o;s++)for(let i=0;i<f;i++)a.set([s,i],Number(p.u.get(s,i)));const h=z.zeros([f,c],"float64");for(let s=0;s<f;s++)for(let i=0;i<c;i++)h.set([s,i],Number(p.vt.get(s,i)));return{u:a,s:p.s,vt:h}}return p}function Fe(t){if(t.ndim!==2)throw new Error(`det: input must be 2D, got ${t.ndim}D`);const[e,g]=t.shape;if(e!==g)throw new Error(`det: matrix must be square, got ${e}x${g}`);const p=e;if(p===0)return 1;const o=t.data;if(p===1)return Number(o[0]);if(p===2)return Number(o[0])*Number(o[3])-Number(o[1])*Number(o[2]);const{lu:c,sign:f}=Q(t),a=c.data;let h=f;for(let s=0;s<p;s++)h*=a[s*p+s];return h}function Q(t){const[e,g]=t.shape,p=e,o=g,c=z.zeros([p,o],"float64"),f=c.data,a=t.data;for(let i=0;i<p*o;i++)f[i]=Number(a[i]);const h=Array.from({length:p},(i,l)=>l);let s=1;for(let i=0;i<Math.min(p,o);i++){let l=Math.abs(f[i*o+i]),n=i;for(let r=i+1;r<p;r++){const u=Math.abs(f[r*o+i]);u>l&&(l=u,n=r)}if(n!==i){for(let u=0;u<o;u++){const b=f[i*o+u];f[i*o+u]=f[n*o+u],f[n*o+u]=b}const r=h[i];h[i]=h[n],h[n]=r,s=-s}const m=f[i*o+i];if(Math.abs(m)>1e-15)for(let r=i+1;r<p;r++){const u=f[r*o+i]/m;f[r*o+i]=u;for(let b=i+1;b<o;b++)f[r*o+b]=f[r*o+b]-u*f[i*o+b]}}return{lu:c,piv:h,sign:s}}function K(t){if(t.ndim!==2)throw new Error(`inv: input must be 2D, got ${t.ndim}D`);const[e,g]=t.shape;if(e!==g)throw new Error(`inv: matrix must be square, got ${e}x${g}`);const p=e,{lu:o,piv:c}=Q(t),f=o.data,a=z.zeros([p,p],"float64"),h=a.data;for(let s=0;s<p;s++){const i=new Float64Array(p);for(let l=0;l<p;l++){let n=c[l]===s?1:0;for(let m=0;m<l;m++)n-=f[l*p+m]*i[m];i[l]=n}for(let l=p-1;l>=0;l--){let n=i[l];for(let r=l+1;r<p;r++)n-=f[l*p+r]*h[r*p+s];const m=f[l*p+l];if(Math.abs(m)<1e-15)throw new Error("inv: singular matrix");h[l*p+s]=n/m}}return a}function oe(t,e){const[g]=t.shape,p=g,{lu:o,piv:c}=Q(t),f=o.data,a=e.data,h=new Float64Array(p);for(let n=0;n<p;n++)h[n]=Number(a[c[n]]);const s=new Float64Array(p);for(let n=0;n<p;n++){let m=h[n];for(let r=0;r<n;r++)m-=f[n*p+r]*s[r];s[n]=m}const i=z.zeros([p],"float64"),l=i.data;for(let n=p-1;n>=0;n--){let m=s[n];for(let u=n+1;u<p;u++)m-=f[n*p+u]*l[u];const r=f[n*p+n];if(Math.abs(r)<1e-15)throw new Error("solve: singular matrix");l[n]=m/r}return i}function de(t,e){if(t.ndim!==2)throw new Error(`solve: coefficient matrix must be 2D, got ${t.ndim}D`);const[g,p]=t.shape;if(g!==p)throw new Error(`solve: coefficient matrix must be square, got ${g}x${p}`);const o=g;if(e.ndim===1){if(e.shape[0]!==o)throw new Error(`solve: incompatible shapes (${g},${p}) and (${e.shape[0]},)`);return oe(t,e)}if(e.ndim===2){if(e.shape[0]!==o)throw new Error(`solve: incompatible shapes (${g},${p}) and (${e.shape[0]},${e.shape[1]})`);const c=e.shape[1],f=z.zeros([o,c],"float64");for(let a=0;a<c;a++){const h=z.zeros([o],"float64");for(let i=0;i<o;i++)h.set([i],Number(e.get(i,a)));const s=oe(t,h);for(let i=0;i<o;i++)f.set([i,a],Number(s.get(i)))}return f}throw new Error(`solve: b must be 1D or 2D, got ${e.ndim}D`)}function qe(t,e,g=null){if(t.ndim!==2)throw new Error(`lstsq: coefficient matrix must be 2D, got ${t.ndim}D`);const[p,o]=t.shape,{u:c,s:f,vt:a}=O(t),h=Math.min(p,o),s=g??Math.max(p,o)*Number.EPSILON,l=Number(f.get(0))*s;let n=0;for(let w=0;w<h;w++)Number(f.get(w))>l&&n++;const m=e.ndim===1?R.reshape(e,[e.size,1]):e,r=m.shape[1];if(m.shape[0]!==p)throw new Error(`lstsq: incompatible shapes (${p},${o}) and (${e.shape.join(",")})`);const u=z.zeros([o,r],"float64");for(let w=0;w<r;w++){const d=new Array(p).fill(0);for(let x=0;x<p;x++)for(let A=0;A<p;A++)d[x]+=Number(c.get(A,x))*Number(m.get(A,w));for(let x=0;x<o;x++){let A=0;for(let S=0;S<h;S++){const v=Number(f.get(S));v>l&&(A+=Number(a.get(S,x))*d[S]/v)}u.set([x,w],A)}}let b;if(p>o){b=z.zeros([r],"float64");for(let w=0;w<r;w++){let d=0;for(let x=0;x<p;x++){let A=0;for(let v=0;v<o;v++)A+=Number(t.get(x,v))*Number(u.get(v,w));const S=A-Number(m.get(x,w));d+=S*S}b.set([w],d)}}else b=z.zeros([0],"float64");return{x:e.ndim===1?R.reshape(u,[o]):u,residuals:b,rank:n,s:f}}function Re(t,e=2){if(t.ndim!==2)throw new Error(`cond: input must be 2D, got ${t.ndim}D`);const[g,p]=t.shape;if(e===2||e===-2){const{s:a}=O(t),h=Math.min(g,p),s=Number(a.get(0)),i=Number(a.get(h-1));return e===2?i>0?s/i:1/0:s>0?i/s:0}if(g!==p)throw new Error(`cond: matrix must be square for p=${e}`);const o=P(t,e),c=K(t),f=P(c,e);return o*f}function _e(t,e){if(t.ndim===0)return Number(t.get())!==0?1:0;if(t.ndim===1){for(let f=0;f<t.size;f++)if(Number(t.get(f))!==0)return 1;return 0}if(t.ndim!==2)throw new Error(`matrix_rank: input must be at most 2D, got ${t.ndim}D`);const{s:g}=O(t),p=Number(g.get(0)),o=e??p*Math.max(t.shape[0],t.shape[1])*Number.EPSILON;let c=0;for(let f=0;f<g.size;f++)Number(g.get(f))>o&&c++;return c}function Be(t,e){if(t.ndim!==2)throw new Error(`matrix_power: input must be 2D, got ${t.ndim}D`);const[g,p]=t.shape;if(g!==p)throw new Error(`matrix_power: matrix must be square, got ${g}x${p}`);const o=g;if(!Number.isInteger(e))throw new Error("matrix_power: exponent must be an integer");if(e===0){const s=z.zeros([o,o],"float64");for(let i=0;i<o;i++)s.set([i,i],1);return s}let c=t,f=e;e<0&&(c=K(t),f=-e);let a=z.zeros([o,o],"float64");for(let s=0;s<o;s++)a.set([s,s],1);let h=z.zeros([o,o],"float64");for(let s=0;s<o;s++)for(let i=0;i<o;i++)h.set([s,i],Number(c.get(s,i)));for(;f>0;)f&1&&(a=B(a,h)),h=B(h,h),f>>=1;return a}function Te(t,e=1e-15){if(t.ndim!==2)throw new Error(`pinv: input must be 2D, got ${t.ndim}D`);const[g,p]=t.shape,{u:o,s:c,vt:f}=O(t),a=Math.min(g,p),s=Number(c.get(0))*e,i=z.zeros([p,g],"float64");for(let l=0;l<p;l++)for(let n=0;n<g;n++){let m=0;for(let r=0;r<a;r++){const u=Number(c.get(r));u>s&&(m+=Number(f.get(r,l))*Number(o.get(n,r))/u)}i.set([l,n],m)}return i}function ye(t){if(t.ndim!==2)throw new Error(`eig: input must be 2D, got ${t.ndim}D`);const[e,g]=t.shape;if(e!==g)throw new Error(`eig: matrix must be square, got ${e}x${g}`);const p=e;let o=!0;e:for(let s=0;s<p;s++)for(let i=s+1;i<p;i++)if(Math.abs(Number(t.get(s,i))-Number(t.get(i,s)))>1e-10){o=!1;break e}if(o){const{values:s,vectors:i}=Z(t),l=z.zeros([p],"float64"),n=z.zeros([p,p],"float64");for(let m=0;m<p;m++){l.set([m],s[m]);for(let r=0;r<p;r++)n.set([r,m],i[r][m])}return{w:l,v:n}}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.");const{values:c,vectors:f}=we(t),a=z.zeros([p],"float64"),h=z.zeros([p,p],"float64");for(let s=0;s<p;s++){a.set([s],c[s]);for(let i=0;i<p;i++)h.set([i,s],f[i][s])}return{w:a,v:h}}function we(t){const e=t.shape[0],g=1e3,p=1e-10;let o=z.zeros([e,e],"float64");for(let h=0;h<e;h++)for(let s=0;s<e;s++)o.set([h,s],Number(t.get(h,s)));let c=z.zeros([e,e],"float64");for(let h=0;h<e;h++)c.set([h,h],1);for(let h=0;h<g;h++){let s=0;for(let m=0;m<e;m++)for(let r=0;r<e;r++)m!==r&&(s+=Number(o.get(m,r))**2);if(Math.sqrt(s)<p*e)break;const i=ge(o,"reduced"),l=i.q,n=i.r;o=B(n,l),c=B(c,l)}const f=[];for(let h=0;h<e;h++)f.push(Number(o.get(h,h)));const a=[];for(let h=0;h<e;h++){a.push([]);for(let s=0;s<e;s++)a[h].push(Number(c.get(h,s)))}return{values:f,vectors:a}}function Ae(t,e="L"){if(t.ndim!==2)throw new Error(`eigh: input must be 2D, got ${t.ndim}D`);const[g,p]=t.shape;if(g!==p)throw new Error(`eigh: matrix must be square, got ${g}x${p}`);const o=g,c=z.zeros([o,o],"float64");for(let l=0;l<o;l++)for(let n=0;n<o;n++)e==="L"?l>=n&&(c.set([l,n],Number(t.get(l,n))),c.set([n,l],Number(t.get(l,n)))):n>=l&&(c.set([l,n],Number(t.get(l,n))),c.set([n,l],Number(t.get(l,n))));const{values:f,vectors:a}=Z(c),h=Array.from({length:o},(l,n)=>n);h.sort((l,n)=>f[l]-f[n]);const s=z.zeros([o],"float64"),i=z.zeros([o,o],"float64");for(let l=0;l<o;l++){s.set([l],f[h[l]]);for(let n=0;n<o;n++)i.set([n,l],a[n][h[l]])}return{w:s,v:i}}function Oe(t){const{w:e}=ye(t);return e}function Le(t,e="L"){const{w:g}=Ae(t,e);return g}function Pe(t,e){const g=R.flatten(t),p=R.flatten(e),o=g.shape[0],c=p.shape[0];if(o!==c)throw new Error(`vdot: arrays must have same number of elements, got ${o} and ${c}`);if(k(t.dtype)||k(e.dtype)){let h=0,s=0;for(let i=0;i<o;i++){const l=g.get(i),n=p.get(i),m=l instanceof I?l.re:Number(l),r=l instanceof I?-l.im:0,u=n instanceof I?n.re:Number(n),b=n instanceof I?n.im:0;h+=m*u+r*b,s+=m*b-r*u}return Math.abs(s)<1e-15?h:new I(h,s)}let a=0;for(let h=0;h<o;h++){const s=g.get(h),i=p.get(h);typeof s=="bigint"&&typeof i=="bigint"?a=(typeof a=="bigint"?a:BigInt(a))+s*i:a=(typeof a=="bigint"?Number(a):a)+Number(s)*Number(i)}return a}function Je(t,e,g=-1){const p=t.ndim,o=e.ndim,c=g<0?p+g:g,f=g<0?o+g:g;if(c<0||c>=p)throw new Error(`vecdot: axis ${g} out of bounds for array with ${p} dimensions`);if(f<0||f>=o)throw new Error(`vecdot: axis ${g} out of bounds for array with ${o} dimensions`);const a=t.shape[c],h=e.shape[f];if(a!==h)throw new Error(`vecdot: axis dimensions must match, got ${a} and ${h}`);if(p===1&&o===1)return X(t,e);const s=[...t.shape.slice(0,c),...t.shape.slice(c+1)],i=[...e.shape.slice(0,f),...e.shape.slice(f+1)],l=a,n=k(t.dtype)||k(e.dtype),m=V(t.dtype,e.dtype),r=s.length>i.length?s:i;if(r.length===0){let y=n?new I(0,0):0;for(let w=0;w<l;w++){const d=t.get(w),x=e.get(w),A=T(d,x);if(y instanceof I||A instanceof I){const S=y instanceof I?y:new I(Number(y),0),v=A instanceof I?A:new I(Number(A),0);y=S.add(v)}else typeof y=="bigint"||typeof A=="bigint"?y=BigInt(y)+BigInt(A):y=y+A}return y}const u=z.zeros(r,m),b=r.reduce((y,w)=>y*w,1);for(let y=0;y<b;y++){const w=[];let d=y;for(let v=r.length-1;v>=0;v--)w.unshift(d%r[v]),d=Math.floor(d/r[v]);const x=[...w.slice(0,c),0,...w.slice(c)],A=[...w.slice(0,f),0,...w.slice(f)];let S=n?new I(0,0):0;for(let v=0;v<l;v++){x[c]=v,A[f]=v;const N=t.get(...x),M=e.get(...A),$=T(N,M);if(S instanceof I||$ instanceof I){const D=S instanceof I?S:new I(Number(S),0),E=$ instanceof I?$:new I(Number($),0);S=D.add(E)}else typeof S=="bigint"||typeof $=="bigint"?S=BigInt(S)+BigInt($):S=S+$}u.set(w,S)}return u}function Xe(t){if(t.ndim<2)throw new Error(`matrix_transpose: input must have at least 2 dimensions, got ${t.ndim}D`);const e=Array.from({length:t.ndim},(p,o)=>o),g=e.length-1;return e[g]=g-1,e[g-1]=g,L(t,e)}function We(t,e){return L(t,e)}function Qe(t,e){if(t.ndim<2)throw new Error(`matvec: x1 must have at least 2 dimensions, got ${t.ndim}D`);if(e.ndim<1)throw new Error(`matvec: x2 must have at least 1 dimension, got ${e.ndim}D`);const g=t.shape[t.ndim-2],p=t.shape[t.ndim-1],o=e.shape[e.ndim-1];if(p!==o)throw new Error(`matvec: last axis of x1 (${p}) must match last axis of x2 (${o})`);if(t.ndim===2&&e.ndim===1)return X(t,e);const c=t.shape.slice(0,-2),f=e.shape.slice(0,-1),a=Math.max(c.length,f.length),h=[...Array(a-c.length).fill(1),...c],s=[...Array(a-f.length).fill(1),...f],i=[];for(let b=0;b<a;b++){const y=h[b],w=s[b];if(y!==1&&w!==1&&y!==w)throw new Error(`matvec: batch dimensions not broadcastable: ${c} vs ${f}`);i.push(Math.max(y,w))}const l=[...i,g],n=V(t.dtype,e.dtype),m=z.zeros(l,n),r=k(n),u=i.reduce((b,y)=>b*y,1);for(let b=0;b<u;b++){const y=[];let w=b;for(let A=i.length-1;A>=0;A--)y.unshift(w%i[A]),w=Math.floor(w/i[A]);const d=y.slice(-(c.length||1)).map((A,S)=>(c[S]??1)===1?0:A),x=y.slice(-(f.length||1)).map((A,S)=>(f[S]??1)===1?0:A);for(let A=0;A<g;A++){let S=r?new I(0,0):0;for(let N=0;N<p;N++){const M=[...d,A,N],$=[...x,N],D=t.get(...M),E=e.get(...$),C=T(D,E);if(S instanceof I||C instanceof I){const j=S instanceof I?S:new I(Number(S),0),F=C instanceof I?C:new I(Number(C),0);S=j.add(F)}else typeof S=="bigint"||typeof C=="bigint"?S=BigInt(S)+BigInt(C):S=S+C}const v=[...y,A];m.set(v,S)}}return m}function Ue(t,e){if(t.ndim<1)throw new Error(`vecmat: x1 must have at least 1 dimension, got ${t.ndim}D`);if(e.ndim<2)throw new Error(`vecmat: x2 must have at least 2 dimensions, got ${e.ndim}D`);const g=t.shape[t.ndim-1],p=e.shape[e.ndim-2],o=e.shape[e.ndim-1];if(g!==p)throw new Error(`vecmat: last axis of x1 (${g}) must match second-to-last axis of x2 (${p})`);if(t.ndim===1&&e.ndim===2)return X(t,e);const c=t.shape.slice(0,-1),f=e.shape.slice(0,-2),a=Math.max(c.length,f.length),h=[...Array(a-c.length).fill(1),...c],s=[...Array(a-f.length).fill(1),...f],i=[];for(let b=0;b<a;b++){const y=h[b],w=s[b];if(y!==1&&w!==1&&y!==w)throw new Error(`vecmat: batch dimensions not broadcastable: ${c} vs ${f}`);i.push(Math.max(y,w))}const l=[...i,o],n=V(t.dtype,e.dtype),m=z.zeros(l,n),r=k(n),u=i.reduce((b,y)=>b*y,1);for(let b=0;b<u;b++){const y=[];let w=b;for(let A=i.length-1;A>=0;A--)y.unshift(w%i[A]),w=Math.floor(w/i[A]);const d=y.slice(-(c.length||1)).map((A,S)=>(c[S]??1)===1?0:A),x=y.slice(-(f.length||1)).map((A,S)=>(f[S]??1)===1?0:A);for(let A=0;A<o;A++){let S=r?new I(0,0):0;for(let N=0;N<g;N++){const M=[...d,N],$=[...x,N,A],D=t.get(...M),E=e.get(...$),C=T(D,E);if(S instanceof I||C instanceof I){const j=S instanceof I?S:new I(Number(S),0),F=C instanceof I?C:new I(Number(C),0);S=j.add(F)}else typeof S=="bigint"||typeof C=="bigint"?S=BigInt(S)+BigInt(C):S=S+C}const v=[...y,A];m.set(v,S)}}return m}function Ge(t){if(t.ndim!==2)throw new Error(`slogdet: input must be 2D, got ${t.ndim}D`);const[e,g]=t.shape;if(e!==g)throw new Error(`slogdet: matrix must be square, got ${e}x${g}`);const p=e;if(p===0)return{sign:1,logabsdet:0};const{lu:o,sign:c}=Q(t),f=o.data;let a=0,h=c;for(let s=0;s<p;s++){const i=f[s*p+s];if(i===0)return{sign:0,logabsdet:-1/0};i<0&&(h=-h),a+=Math.log(Math.abs(i))}return{sign:h,logabsdet:a}}function He(t){return be(t,!0,!1)}function Ye(t){if(t.length<2)throw new Error("multi_dot: need at least 2 arrays");if(t.length===2)return B(t[0],t[1]);let e=t[0];for(let g=1;g<t.length;g++)e=B(e,t[g]);return e}function Ze(t,e=2){if(e<=0)throw new Error(`tensorinv: ind must be positive, got ${e}`);const g=t.shape,p=t.ndim;if(p<e)throw new Error(`tensorinv: array has ${p} dimensions, ind=${e} is too large`);let o=1;for(let s=0;s<e;s++)o*=g[s];let c=1;for(let s=e;s<p;s++)c*=g[s];if(o!==c)throw new Error(`tensorinv: product of first ${e} dimensions (${o}) must equal product of remaining dimensions (${c})`);const f=R.reshape(t,[o,c]),a=K(f),h=[...g.slice(e),...g.slice(0,e)];return R.reshape(a,h)}function Ke(t,e,g){const p=t.shape,o=e.shape,c=t.ndim,f=e.ndim;let a;g==null?a=Array.from({length:f},(d,x)=>c-f+x):a=g.map(d=>d<0?c+d:d);const h=[];for(let d=0;d<c;d++)a.includes(d)||h.push(d);const s=[...h,...a],i=L(t,s),n=a.map(d=>p[d]).reduce((d,x)=>d*x,1),r=h.map(d=>p[d]).reduce((d,x)=>d*x,1),u=o.reduce((d,x)=>d*x,1);if(n!==u)throw new Error(`tensorsolve: dimensions don't match - sum dimensions product (${n}) != b total elements (${u})`);if(r!==n)throw new Error(`tensorsolve: non-square problem - other dimensions product (${r}) != sum dimensions product (${n})`);const b=R.reshape(i,[r,n]),y=R.reshape(e,[n]),w=de(b,y);return R.reshape(w,[...o])}function et(t,...e){const g=t.indexOf("->");let p,o;g===-1?(p=t,o=ne(p)):(p=t.slice(0,g),o=t.slice(g+2));const c=p.split(",").map(n=>n.trim());if(c.length!==e.length)throw new Error(`einsum_path: expected ${c.length} operands, got ${e.length}`);const f=e.map(n=>Array.isArray(n)?n:Array.from(n.shape)),a=new Map;for(let n=0;n<e.length;n++){const m=c[n],r=f[n];if(m.length!==r.length)throw new Error(`einsum_path: operand ${n} has ${r.length} dimensions but subscript '${m}' has ${m.length} indices`);for(let u=0;u<m.length;u++){const b=m[u],y=r[u];if(a.has(b)&&a.get(b)!==y)throw new Error(`einsum_path: size mismatch for index '${b}': ${a.get(b)} vs ${y}`);a.set(b,y)}}if(e.length===1){const n=[[0]];return[n,ee(t,f,n,a)]}if(e.length===2){const n=[[0,1]];return[n,ee(t,f,n,a)]}const h=[],s=[...c],i=[...f],l=e.map((n,m)=>m);for(;s.length>1;){let n=0,m=1,r=1/0;for(let y=0;y<s.length;y++)for(let w=y+1;w<s.length;w++){const d=xe(s[y],s[w],i[y],i[w],o,a);d<r&&(r=d,n=y,m=w)}h.push([l[n],l[m]]);const[u,b]=Se(s[n],s[m],i[n],i[m],o,a);s.splice(m,1),s.splice(n,1),i.splice(m,1),i.splice(n,1),l.splice(m,1),l.splice(n,1),s.push(u),i.push(b),l.push(-1)}return[h,ee(t,f,h,a)]}function xe(t,e,g,p,o,c){const f=new Set(t),a=new Set(e);let h=1;for(const s of f)h*=c.get(s)||1;for(const s of a)f.has(s)||(h*=c.get(s)||1);return h}function Se(t,e,g,p,o,c){const f=new Set([...t,...e]),a=new Map;for(const l of t)a.set(l,(a.get(l)||0)+1);for(const l of e)a.set(l,(a.get(l)||0)+1);const h=new Set(o),s=[];for(const l of f)(h.has(l)||a.get(l)===1)&&s.push(l);s.sort();const i=s.map(l=>c.get(l));return[s.join(""),i]}function ee(t,e,g,p){const o=[];o.push(" Complete contraction: "+t),o.push(" Operand shapes: "+e.map(f=>`(${f.join(", ")})`).join(", ")),o.push(" Contraction path: "+JSON.stringify(g));let c=0;for(const f of e)c+=f.reduce((a,h)=>a*h,1);return o.push(" Estimated FLOPS: ~"+c.toExponential(2)),o.join(`
2
- `)}export{ke as cholesky,Re as cond,je as cross,Fe as det,ze as diagonal,X as dot,ye as eig,Ae as eigh,Oe as eigvals,Le as eigvalsh,Ce as einsum,et as einsum_path,Me as inner,K as inv,Ee as kron,qe as lstsq,B as matmul,P as matrix_norm,Be as matrix_power,_e as matrix_rank,Xe as matrix_transpose,Qe as matvec,Ye as multi_dot,Ve as norm,pe as outer,We as permute_dims,Te as pinv,ge as qr,Ge as slogdet,de as solve,be as svd,He as svdvals,De as tensordot,Ze as tensorinv,Ke as tensorsolve,$e as trace,L as transpose,Pe as vdot,Je as vecdot,Ue as vecmat,W as vector_norm};
1
+ import{ArrayStorage as z}from"../storage";import{promoteDTypes as V,isComplexDType as k,isBigIntDType as J}from"../dtype";import{Complex as I}from"../complex";import*as R from"./shape";function T(t,e){if(t instanceof I||e instanceof I){const h=t instanceof I?t:new I(Number(t),0),p=e instanceof I?e:new I(Number(e),0);return h.mul(p)}return typeof t=="bigint"&&typeof e=="bigint"?Number(t*e):Number(t)*Number(e)}function ce(t,e,h,p,i,u,f,c,g){for(let o=0;o<h;o++)for(let s=0;s<u;s++)for(let l=0;l<f;l++){let n=0;for(let m=0;m<c;m++)n+=t[e+o*c+m]*p[i+s*c*f+m*f+l];g[o*u*f+s*f+l]=n}}function me(t,e,h,p,i,u,f,c,g,o){for(let s=0;s<h;s++)for(let l=0;l<f;l++){let n=0;for(let m=0;m<g;m++){const r=p===1?m:s*g+m,a=c===1?m:l*g+m;n+=t[e+r]*i[u+a]}o[h===1?l:s*f+l]=n}}function fe(t,e,h,p,i,u,f,c,g,o,s,l){for(let r=0;r<h*p;r++)s[r]=0;const n=t==="transpose",m=e==="transpose";if(!n&&!m)for(let r=0;r<h;r++)for(let a=0;a<p;a++){let b=0;for(let y=0;y<i;y++)b+=(f[r*c+y]??0)*(g[y*o+a]??0);s[r*l+a]=u*b}else if(n&&!m)for(let r=0;r<h;r++)for(let a=0;a<p;a++){let b=0;for(let y=0;y<i;y++)b+=(f[y*c+r]??0)*(g[y*o+a]??0);s[r*l+a]=u*b}else if(!n&&m)for(let r=0;r<h;r++)for(let a=0;a<p;a++){let b=0;for(let y=0;y<i;y++)b+=(f[r*c+y]??0)*(g[a*o+y]??0);s[r*l+a]=u*b}else for(let r=0;r<h;r++)for(let a=0;a<p;a++){let b=0;for(let y=0;y<i;y++)b+=(f[y*c+r]??0)*(g[a*o+y]??0);s[r*l+a]=u*b}}function X(t,e){const h=t.ndim,p=e.ndim,i=k(t.dtype)||k(e.dtype);if(h===0||p===0){const u=h===0?t.get():null,f=p===0?e.get():null;if(h===0&&p===0)return T(u,f);if(h===0){const c=V(t.dtype,e.dtype),g=z.zeros([...e.shape],c),o=(s,l)=>{const n=new Array(l.length);let m=s;for(let r=l.length-1;r>=0;r--)n[r]=m%l[r],m=Math.floor(m/l[r]);return n};for(let s=0;s<e.size;s++){const l=o(s,e.shape),n=e.get(...l);g.set(l,T(u,n))}return g}else{const c=V(t.dtype,e.dtype),g=z.zeros([...t.shape],c),o=(s,l)=>{const n=new Array(l.length);let m=s;for(let r=l.length-1;r>=0;r--)n[r]=m%l[r],m=Math.floor(m/l[r]);return n};for(let s=0;s<t.size;s++){const l=o(s,t.shape),n=t.get(...l);g.set(l,T(n,f))}return g}}if(h===1&&p===1){if(t.shape[0]!==e.shape[0])throw new Error(`dot: incompatible shapes (${t.shape[0]},) and (${e.shape[0]},)`);const u=t.shape[0];if(i){let c=0,g=0;for(let o=0;o<u;o++){const s=t.get(o),l=e.get(o),n=T(s,l);n instanceof I?(c+=n.re,g+=n.im):c+=n}return new I(c,g)}let f=0;for(let c=0;c<u;c++){const g=t.get(c),o=e.get(c);typeof g=="bigint"&&typeof o=="bigint"?f=Number(f)+Number(g*o):f+=Number(g)*Number(o)}return f}if(h===2&&p===2)return B(t,e);if(h===2&&p===1){const[u,f]=t.shape,c=e.shape[0];if(f!==c)throw new Error(`dot: incompatible shapes (${u},${f}) and (${c},)`);const g=V(t.dtype,e.dtype),o=z.zeros([u],g);if(i)for(let s=0;s<u;s++){let l=0,n=0;for(let m=0;m<f;m++){const r=t.get(s,m),a=e.get(m),b=r instanceof I?r:new I(Number(r),0),y=a instanceof I?a:new I(Number(a),0);l+=b.re*y.re-b.im*y.im,n+=b.re*y.im+b.im*y.re}o.set([s],new I(l,n))}else for(let s=0;s<u;s++){let l=0;for(let n=0;n<f;n++){const m=t.get(s,n),r=e.get(n);typeof m=="bigint"&&typeof r=="bigint"?l=Number(l)+Number(m*r):l+=Number(m)*Number(r)}o.set([s],l)}return o}if(h===1&&p===2){const u=t.shape[0],[f,c]=e.shape;if(u!==f)throw new Error(`dot: incompatible shapes (${u},) and (${f},${c})`);const g=V(t.dtype,e.dtype),o=z.zeros([c],g);if(i)for(let s=0;s<c;s++){let l=0,n=0;for(let m=0;m<u;m++){const r=t.get(m),a=e.get(m,s),b=r instanceof I?r:new I(Number(r),0),y=a instanceof I?a:new I(Number(a),0);l+=b.re*y.re-b.im*y.im,n+=b.re*y.im+b.im*y.re}o.set([s],new I(l,n))}else for(let s=0;s<c;s++){let l=0;for(let n=0;n<u;n++){const m=t.get(n),r=e.get(n,s);typeof m=="bigint"&&typeof r=="bigint"?l=Number(l)+Number(m*r):l+=Number(m)*Number(r)}o.set([s],l)}return o}if(h>2&&p===1){const u=t.shape[h-1],f=e.shape[0];if(u!==f)throw new Error(`dot: incompatible shapes ${JSON.stringify(t.shape)} and (${f},)`);const c=[...t.shape.slice(0,-1)],g=V(t.dtype,e.dtype),o=z.zeros(c,g),s=c.reduce((l,n)=>l*n,1);if(i)for(let l=0;l<s;l++){let n=0,m=0,r=l;const a=[];for(let b=c.length-1;b>=0;b--)a[b]=r%c[b],r=Math.floor(r/c[b]);for(let b=0;b<u;b++){const y=[...a,b],w=t.get(...y),d=e.get(b),x=w instanceof I?w:new I(Number(w),0),A=d instanceof I?d:new I(Number(d),0);n+=x.re*A.re-x.im*A.im,m+=x.re*A.im+x.im*A.re}o.set(a,new I(n,m))}else for(let l=0;l<s;l++){let n=0,m=l;const r=[];for(let a=c.length-1;a>=0;a--)r[a]=m%c[a],m=Math.floor(m/c[a]);for(let a=0;a<u;a++){const b=[...r,a],y=t.get(...b),w=e.get(a);typeof y=="bigint"&&typeof w=="bigint"?n=Number(n)+Number(y*w):n+=Number(y)*Number(w)}o.set(r,n)}return o}if(h===1&&p>2){const u=t.shape[0],f=1,c=e.shape[f];if(u!==c)throw new Error(`dot: incompatible shapes (${u},) and ${JSON.stringify(e.shape)}`);const g=[...e.shape.slice(0,f),...e.shape.slice(f+1)],o=V(t.dtype,e.dtype),s=z.zeros(g,o),l=g.reduce((n,m)=>n*m,1);if(i)for(let n=0;n<l;n++){let m=n;const r=[];for(let d=g.length-1;d>=0;d--)r[d]=m%g[d],m=Math.floor(m/g[d]);const a=r.slice(0,f),b=r.slice(f);let y=0,w=0;for(let d=0;d<u;d++){const x=t.get(d),A=[...a,d,...b],S=e.get(...A),v=x instanceof I?x:new I(Number(x),0),N=S instanceof I?S:new I(Number(S),0);y+=v.re*N.re-v.im*N.im,w+=v.re*N.im+v.im*N.re}s.set(r,new I(y,w))}else for(let n=0;n<l;n++){let m=n;const r=[];for(let w=g.length-1;w>=0;w--)r[w]=m%g[w],m=Math.floor(m/g[w]);const a=r.slice(0,f),b=r.slice(f);let y=0;for(let w=0;w<u;w++){const d=t.get(w),x=[...a,w,...b],A=e.get(...x);typeof d=="bigint"&&typeof A=="bigint"?y=Number(y)+Number(d*A):y+=Number(d)*Number(A)}s.set(r,y)}return s}if(h>=2&&p>=2&&!(h===2&&p===2)){const u=t.shape[h-1],f=e.shape[p-2];if(u!==f)throw new Error(`dot: incompatible shapes ${JSON.stringify(t.shape)} and ${JSON.stringify(e.shape)}`);const c=[...t.shape.slice(0,-1),...e.shape.slice(0,-2),e.shape[p-1]],g=V(t.dtype,e.dtype),o=z.zeros(c,g),s=t.shape.slice(0,-1).reduce((r,a)=>r*a,1),l=e.shape.slice(0,-2).reduce((r,a)=>r*a,1),n=e.shape[p-1],m=u;if(i)for(let r=0;r<s;r++)for(let a=0;a<l;a++)for(let b=0;b<n;b++){let y=0,w=0;for(let A=0;A<m;A++){const S=[];let v=r;for(let j=t.shape.length-2;j>=0;j--)S.unshift(v%t.shape[j]),v=Math.floor(v/t.shape[j]);S.push(A);const N=t.get(...S),M=[];let $=a;for(let j=e.shape.length-3;j>=0;j--)M.unshift($%e.shape[j]),$=Math.floor($/e.shape[j]);M.push(A,b);const D=e.get(...M),C=N instanceof I?N:new I(Number(N),0),E=D instanceof I?D:new I(Number(D),0);y+=C.re*E.re-C.im*E.im,w+=C.re*E.im+C.im*E.re}const d=r*l*n+a*n+b,x=o.data;x[d*2]=y,x[d*2+1]=w}else if(t.isCContiguous&&e.isCContiguous&&!J(t.dtype)&&!J(e.dtype))ce(t.data,t.offset,s,e.data,e.offset,l,n,m,o.data);else for(let r=0;r<s;r++)for(let a=0;a<l;a++)for(let b=0;b<n;b++){let y=0;for(let d=0;d<m;d++){const x=r*m+d,A=a*m*n+d*n+b,S=t.iget(x),v=e.iget(A);typeof S=="bigint"&&typeof v=="bigint"?y=Number(y)+Number(S*v):y+=Number(S)*Number(v)}const w=r*l*n+a*n+b;o.data[w]=y}return o}throw new Error(`dot: unexpected combination of dimensions ${h}D \xB7 ${p}D`)}function B(t,e){if(t.ndim!==2||e.ndim!==2)throw new Error("matmul requires 2D arrays");const[h=0,p=0]=t.shape,[i=0,u=0]=e.shape;if(p!==i)throw new Error(`matmul shape mismatch: (${h},${p}) @ (${i},${u})`);const f=V(t.dtype,e.dtype);if(k(f)){const A=z.zeros([h,u],f),S=A.data;for(let v=0;v<h;v++)for(let N=0;N<u;N++){let M=0,$=0;for(let C=0;C<p;C++){const E=t.iget(v*p+C),j=e.iget(C*u+N);M+=E.re*j.re-E.im*j.im,$+=E.re*j.im+E.im*j.re}const D=v*u+N;S[D*2]=M,S[D*2+1]=$}return A}const c=f.startsWith("int")||f.startsWith("uint")||f==="bool"?"float64":f;if(c!=="float64")throw new Error(`matmul currently only supports float64, got ${c}`);let g=t.dtype==="float64"?t.data:Float64Array.from(Array.from(t.data).map(Number)),o=e.dtype==="float64"?e.data:Float64Array.from(Array.from(e.data).map(Number));t.offset>0&&(g=g.subarray(t.offset)),e.offset>0&&(o=o.subarray(e.offset));const[s=0,l=0]=t.strides,[n=0,m=0]=e.strides,r=l>s,a=m>n,b=r?"transpose":"no-transpose",y=a?"transpose":"no-transpose";let w,d;r?w=l:w=s,a?d=m:d=n;const x=z.zeros([h,u],"float64");return fe(b,y,h,u,p,1,g,w,o,d,x.data,u),x}function $e(t){if(t.ndim!==2)throw new Error(`trace requires 2D array, got ${t.ndim}D`);const[e=0,h=0]=t.shape,p=Math.min(e,h);if(k(t.dtype)){let u=0,f=0;for(let c=0;c<p;c++){const g=t.get(c,c);u+=g.re,f+=g.im}return new I(u,f)}let i=0;for(let u=0;u<p;u++){const f=t.get(u,u);typeof f=="bigint"?i=(typeof i=="bigint"?i:BigInt(i))+f:i=(typeof i=="bigint"?Number(i):i)+f}return i}function L(t,e){return R.transpose(t,e)}function Me(t,e){const h=t.ndim,p=e.ndim,i=k(t.dtype)||k(e.dtype),u=t.shape[h-1],f=e.shape[p-1];if(u!==f)throw new Error(`inner: incompatible shapes - last dimensions ${u} and ${f} don't match`);if(h===1&&p===1)return X(t,e);const c=[...t.shape.slice(0,-1),...e.shape.slice(0,-1)],g=V(t.dtype,e.dtype),o=z.zeros(c,g),s=h===1?1:t.shape.slice(0,-1).reduce((m,r)=>m*r,1),l=p===1?1:e.shape.slice(0,-1).reduce((m,r)=>m*r,1),n=u;if(i)for(let m=0;m<s;m++)for(let r=0;r<l;r++){let a=0,b=0;for(let d=0;d<n;d++){let x,A;if(h===1)x=t.get(d);else{const N=[];let M=m;const $=t.shape.slice(0,-1);for(let D=$.length-1;D>=0;D--)N.unshift(M%$[D]),M=Math.floor(M/$[D]);N.push(d),x=t.get(...N)}if(p===1)A=e.get(d);else{const N=[];let M=r;const $=e.shape.slice(0,-1);for(let D=$.length-1;D>=0;D--)N.unshift(M%$[D]),M=Math.floor(M/$[D]);N.push(d),A=e.get(...N)}const S=x instanceof I?x:new I(Number(x),0),v=A instanceof I?A:new I(Number(A),0);a+=S.re*v.re-S.im*v.im,b+=S.re*v.im+S.im*v.re}if(c.length===0)return new I(a,b);const y=s===1?r:m*l+r,w=o.data;w[y*2]=a,w[y*2+1]=b}else if(t.isCContiguous&&e.isCContiguous&&!J(t.dtype)&&!J(e.dtype)){if(c.length===0){const m=t.data,r=e.data,a=t.offset,b=e.offset;let y=0;for(let w=0;w<n;w++)y+=m[a+w]*r[b+w];return y}me(t.data,t.offset,s,h,e.data,e.offset,l,p,n,o.data)}else for(let m=0;m<s;m++)for(let r=0;r<l;r++){let a=0;for(let y=0;y<n;y++){const w=h===1?y:m*n+y,d=p===1?y:r*n+y,x=t.iget(w),A=e.iget(d);typeof x=="bigint"&&typeof A=="bigint"?a=Number(a)+Number(x*A):a+=Number(x)*Number(A)}if(c.length===0)return a;const b=s===1?r:m*l+r;o.data[b]=a}return o}function pe(t,e){const h=t.ndim===1?t:R.ravel(t),p=e.ndim===1?e:R.ravel(e),i=h.size,u=p.size,f=V(t.dtype,e.dtype),c=z.zeros([i,u],f);for(let g=0;g<i;g++)for(let o=0;o<u;o++){const s=h.get(g),l=p.get(o),n=T(s,l);c.set([g,o],n)}return c}function De(t,e,h){let p,i;if(typeof h=="number"){const r=h;if(r<0)throw new Error("tensordot: axes must be non-negative");if(r>t.ndim||r>e.ndim)throw new Error("tensordot: axes exceeds array dimensions");p=Array.from({length:r},(a,b)=>t.ndim-r+b),i=Array.from({length:r},(a,b)=>b)}else if([p,i]=h,p.length!==i.length)throw new Error("tensordot: axes lists must have same length");for(let r=0;r<p.length;r++){const a=p[r],b=i[r];if(a<0||a>=t.ndim||b<0||b>=e.ndim)throw new Error("tensordot: axis out of bounds");if(t.shape[a]!==e.shape[b])throw new Error(`tensordot: shape mismatch on axes ${a} and ${b}: ${t.shape[a]} != ${e.shape[b]}`)}const u=[],f=[];for(let r=0;r<t.ndim;r++)p.includes(r)||u.push(r);for(let r=0;r<e.ndim;r++)i.includes(r)||f.push(r);const c=[...u.map(r=>t.shape[r]),...f.map(r=>e.shape[r])],g=V(t.dtype,e.dtype),o=k(g),s=r=>r instanceof I?{re:r.re,im:r.im}:{re:Number(r),im:0};if(c.length===0){let r=0,a=0;const b=p.map(y=>t.shape[y]).reduce((y,w)=>y*w,1);for(let y=0;y<b;y++){let w=y;const d=new Array(p.length);for(let N=p.length-1;N>=0;N--){const M=p[N];d[N]=w%t.shape[M],w=Math.floor(w/t.shape[M])}const x=new Array(t.ndim),A=new Array(e.ndim);for(let N=0;N<p.length;N++)x[p[N]]=d[N];for(let N=0;N<i.length;N++)A[i[N]]=d[N];const S=t.get(...x),v=e.get(...A);if(o){const N=s(S),M=s(v);r+=N.re*M.re-N.im*M.im,a+=N.re*M.im+N.im*M.re}else typeof S=="bigint"&&typeof v=="bigint"?r+=Number(S*v):r+=Number(S)*Number(v)}return o?new I(r,a):r}const l=z.zeros(c,g),n=c.reduce((r,a)=>r*a,1),m=p.map(r=>t.shape[r]).reduce((r,a)=>r*a,1);for(let r=0;r<n;r++){let a=r;const b=[];for(let A=c.length-1;A>=0;A--)b[A]=a%c[A],a=Math.floor(a/c[A]);const y=b.slice(0,u.length),w=b.slice(u.length);let d=0,x=0;for(let A=0;A<m;A++){a=A;const S=[];for(let D=p.length-1;D>=0;D--){const C=p[D];S[D]=a%t.shape[C],a=Math.floor(a/t.shape[C])}const v=new Array(t.ndim),N=new Array(e.ndim);for(let D=0;D<u.length;D++)v[u[D]]=y[D];for(let D=0;D<f.length;D++)N[f[D]]=w[D];for(let D=0;D<p.length;D++)v[p[D]]=S[D],N[i[D]]=S[D];const M=t.get(...v),$=e.get(...N);if(o){const D=s(M),C=s($);d+=D.re*C.re-D.im*C.im,x+=D.re*C.im+D.im*C.re}else typeof M=="bigint"&&typeof $=="bigint"?d+=Number(M*$):d+=Number(M)*Number($)}o?l.set(b,new I(d,x)):l.set(b,d)}return l}function ze(t,e=0,h=0,p=1){const i=t.shape,u=i.length;if(u<2)throw new Error("diagonal requires an array of at least two dimensions");const f=h<0?u+h:h,c=p<0?u+p:p;if(f<0||f>=u||c<0||c>=u)throw new Error("axis out of bounds");if(f===c)throw new Error("axis1 and axis2 cannot be the same");const g=i[f],o=i[c];let s;e>=0?s=Math.max(0,Math.min(g,o-e)):s=Math.max(0,Math.min(g+e,o));const l=[];for(let a=0;a<u;a++)a!==f&&a!==c&&l.push(i[a]);l.push(s);const n=z.zeros(l,t.dtype),m=i.filter((a,b)=>b!==f&&b!==c),r=m.reduce((a,b)=>a*b,1);for(let a=0;a<r;a++){let b=a;const y=[];for(let w=m.length-1;w>=0;w--)y.unshift(b%m[w]),b=Math.floor(b/m[w]);for(let w=0;w<s;w++){const d=new Array(u);let x=0;for(let v=0;v<u;v++)v===f?d[v]=e>=0?w:w-e:v===c?d[v]=e>=0?w+e:w:d[v]=y[x++];const A=[...y,w],S=t.get(...d);n.set(A,S)}}return n}function Ee(t,...e){const h=t.indexOf("->");let p,i;h===-1?(p=t,i=ne(p)):(p=t.slice(0,h),i=t.slice(h+2));const u=p.split(",").map(a=>a.trim());if(u.length!==e.length)throw new Error(`einsum: expected ${u.length} operands, got ${e.length}`);const f=new Map;for(let a=0;a<e.length;a++){const b=u[a],y=e[a];if(b.length!==y.ndim)throw new Error(`einsum: operand ${a} has ${y.ndim} dimensions but subscript '${b}' has ${b.length} indices`);for(let w=0;w<b.length;w++){const d=b[w],x=y.shape[w];if(f.has(d)){if(f.get(d)!==x)throw new Error(`einsum: size mismatch for index '${d}': ${f.get(d)} vs ${x}`)}else f.set(d,x)}}for(const a of i)if(!f.has(a))throw new Error(`einsum: output subscript contains unknown index '${a}'`);const c=new Set(i),g=new Set;for(const a of u)for(const b of a)g.add(b);const o=[];for(const a of g)c.has(a)||o.push(a);if(e.length===2&&u.length===2){const[a,b]=u,[y,w]=e;if(a.length===2&&b.length===2&&i.length===2&&y.ndim===2&&w.ndim===2){const[d,x]=[a[0],a[1]],[A,S]=[b[0],b[1]],[v,N]=[i[0],i[1]];if(d===v&&S===N&&x===A&&o.length===1&&o[0]===x||d===v&&S===N&&x===A&&o.length===1&&o[0]===x)return B(y,w);if(x===v&&S===N&&d===A&&o.length===1&&o[0]===d){const M=L(y);return B(M,w)}if(d===v&&A===N&&x===S&&o.length===1&&o[0]===x){const M=L(w);return B(y,M)}}if(a.length===1&&b.length===1&&a===b&&i.length===0&&y.ndim===1&&w.ndim===1)return Y(e,u,o,f);if(a&&b&&a.length===1&&b.length===1&&i.length===2&&i===a+b&&o.length===0&&y.ndim===1&&w.ndim===1)return pe(y,w)}if(e.length===1&&u[0].length===2&&i.length===0){const a=u[0];if(a[0]===a[1]&&e[0].ndim===2)return Y(e,u,o,f)}const s=Array.from(i).map(a=>f.get(a));if(s.length===0)return Y(e,u,o,f);let l=e[0].dtype;for(let a=1;a<e.length;a++)l=V(l,e[a].dtype);const n=z.zeros(s,l),m=s.reduce((a,b)=>a*b,1);let r=1;for(const a of o)r*=f.get(a);for(let a=0;a<m;a++){const b=he(a,s),y=new Map;for(let d=0;d<i.length;d++)y.set(i[d],b[d]);let w=0;for(let d=0;d<r;d++){let x=d;for(let S=o.length-1;S>=0;S--){const v=o[S],N=f.get(v);y.set(v,x%N),x=Math.floor(x/N)}let A=1;for(let S=0;S<e.length;S++){const v=e[S],N=u[S],M=[];for(const D of N)M.push(y.get(D));const $=v.get(...M);A*=Number($)}w+=A}n.set(b,w)}return n}function ne(t){const e=new Map,h=t.split(",");for(const i of h)for(const u of i.trim())e.set(u,(e.get(u)||0)+1);const p=[];for(const[i,u]of e)u===1&&p.push(i);return p.sort().join("")}function Y(t,e,h,p){let i=!1;for(const o of t)if(k(o.dtype)){i=!0;break}const u=o=>o instanceof I?{re:o.re,im:o.im}:{re:Number(o),im:0};let f=1;for(const o of h)f*=p.get(o);let c=0,g=0;for(let o=0;o<f;o++){const s=new Map;let l=o;for(let r=h.length-1;r>=0;r--){const a=h[r],b=p.get(a);s.set(a,l%b),l=Math.floor(l/b)}let n=1,m=0;for(let r=0;r<t.length;r++){const a=t[r],b=e[r],y=[];for(const d of b)y.push(s.get(d));const w=a.get(...y);if(i){const d=u(w),x=n*d.re-m*d.im,A=n*d.im+m*d.re;n=x,m=A}else n*=Number(w)}c+=n,g+=m}return i?new I(c,g):c}function he(t,e){const h=new Array(e.length);let p=t;for(let i=e.length-1;i>=0;i--)h[i]=p%e[i],p=Math.floor(p/e[i]);return h}function Ce(t,e){const h=t.shape,p=e.shape,i=h.length,u=p.length,f=V(t.dtype,e.dtype),c=Math.max(i,u),g=new Array(c),o=new Array(c).fill(1),s=new Array(c).fill(1);for(let r=0;r<i;r++)o[c-i+r]=h[r];for(let r=0;r<u;r++)s[c-u+r]=p[r];for(let r=0;r<c;r++)g[r]=o[r]*s[r];const l=z.zeros(g,f),n=h.reduce((r,a)=>r*a,1),m=p.reduce((r,a)=>r*a,1);for(let r=0;r<n;r++){let a=r;const b=new Array(i);for(let d=i-1;d>=0;d--)b[d]=a%h[d],a=Math.floor(a/h[d]);const y=new Array(c).fill(0);for(let d=0;d<i;d++)y[c-i+d]=b[d];const w=t.get(...b);for(let d=0;d<m;d++){let x=d;const A=new Array(u);for(let $=u-1;$>=0;$--)A[$]=x%p[$],x=Math.floor(x/p[$]);const S=new Array(c).fill(0);for(let $=0;$<u;$++)S[c-u+$]=A[$];const v=e.get(...A),N=new Array(c);for(let $=0;$<c;$++)N[$]=y[$]*s[$]+S[$];const M=T(w,v);l.set(N,M)}}return l}function je(t,e,h=-1,p=-1,i=-1,u){u!==void 0&&(h=u,p=u,i=u);const f=(N,M)=>N<0?M+N:N,c=f(h,t.ndim),g=f(p,e.ndim),o=V(t.dtype,e.dtype),s=k(o),l=(N,...M)=>{const $=N.get(...M);return $ instanceof I?$:Number($)},n=(N,M)=>{if(N instanceof I||M instanceof I){const $=N instanceof I?N:new I(N,0),D=M instanceof I?M:new I(M,0);return $.mul(D)}return N*M},m=(N,M)=>{if(N instanceof I||M instanceof I){const $=N instanceof I?N:new I(N,0),D=M instanceof I?M:new I(M,0);return $.sub(D)}return N-M};if(t.ndim===1&&e.ndim===1){const N=t.shape[0],M=e.shape[0];if(N===3&&M===3){const $=l(t,0),D=l(t,1),C=l(t,2),E=l(e,0),j=l(e,1),F=l(e,2),q=z.zeros([3],o);return q.set([0],m(n(D,F),n(C,j))),q.set([1],m(n(C,E),n($,F))),q.set([2],m(n($,j),n(D,E))),q}else if(N===2&&M===2){const $=l(t,0),D=l(t,1),C=l(e,0),E=l(e,1);return m(n($,E),n(D,C))}else if(N===2&&M===3||N===3&&M===2){const $=l(t,0),D=l(t,1),C=N===3?l(t,2):s?new I(0,0):0,E=l(e,0),j=l(e,1),F=M===3?l(e,2):s?new I(0,0):0,q=z.zeros([3],o);return q.set([0],m(n(D,F),n(C,j))),q.set([1],m(n(C,E),n($,F))),q.set([2],m(n($,j),n(D,E))),q}else throw new Error(`cross: incompatible dimensions for cross product: ${N} and ${M}`)}const r=t.shape[c],a=e.shape[g];if(r!==2&&r!==3||a!==2&&a!==3)throw new Error(`cross: incompatible dimensions for cross product: ${r} and ${a}`);const b=r===2&&a===2?0:3,y=[...t.shape.slice(0,c),...t.shape.slice(c+1)],w=[...e.shape.slice(0,g),...e.shape.slice(g+1)];if(y.length!==w.length)throw new Error("cross: incompatible shapes for cross product");for(let N=0;N<y.length;N++)if(y[N]!==w[N])throw new Error("cross: incompatible shapes for cross product");const d=y,x=i<0?d.length+1+i:i;let A;if(b===0?A=d:A=[...d.slice(0,x),b,...d.slice(x)],A.length===0)throw new Error("cross: unexpected scalar result from higher-dimensional input");const S=z.zeros(A,o),v=d.reduce((N,M)=>N*M,1);for(let N=0;N<v;N++){let M=N;const $=[];for(let _=d.length-1;_>=0;_--)$[_]=M%d[_],M=Math.floor(M/d[_]);const D=[...$.slice(0,c),0,...$.slice(c)],C=[...$.slice(0,g),0,...$.slice(g)],E=_=>(D[c]=_,l(t,...D)),j=_=>(C[g]=_,l(e,...C)),F=E(0),q=E(1),te=r===3?E(2):s?new I(0,0):0,U=j(0),G=j(1),re=a===3?j(2):s?new I(0,0):0;if(b===0)S.set($,m(n(F,G),n(q,U)));else{const _=m(n(q,re),n(te,G)),se=m(n(te,U),n(F,re)),ie=m(n(F,G),n(q,U)),H=(le,ae)=>{const ue=[...$.slice(0,x),le,...$.slice(x)];S.set(ue,ae)};H(0,_),H(1,se),H(2,ie)}}return S}function W(t,e=2,h,p=!1){if(typeof e!="number")throw new Error("vector_norm: ord must be a number");if(h==null){const o=t.ndim===1?t:R.ravel(t),s=o.size;let l;if(e===1/0){l=0;for(let n=0;n<s;n++)l=Math.max(l,Math.abs(Number(o.get(n))))}else if(e===-1/0){l=1/0;for(let n=0;n<s;n++)l=Math.min(l,Math.abs(Number(o.get(n))))}else if(e===0){l=0;for(let n=0;n<s;n++)Number(o.get(n))!==0&&l++}else if(e===1){l=0;for(let n=0;n<s;n++)l+=Math.abs(Number(o.get(n)))}else if(e===2){l=0;for(let n=0;n<s;n++){const m=Number(o.get(n));l+=m*m}l=Math.sqrt(l)}else{l=0;for(let n=0;n<s;n++)l+=Math.pow(Math.abs(Number(o.get(n))),e);l=Math.pow(l,1/e)}if(p){const n=new Array(t.ndim).fill(1),m=z.zeros(n,"float64");return m.set(new Array(t.ndim).fill(0),l),m}return l}const i=h<0?t.ndim+h:h;if(i<0||i>=t.ndim)throw new Error(`vector_norm: axis ${h} out of bounds for array with ${t.ndim} dimensions`);const u=p?[...t.shape.slice(0,i),1,...t.shape.slice(i+1)]:[...t.shape.slice(0,i),...t.shape.slice(i+1)];if(u.length===0)return W(t,e,null,!1);const f=z.zeros(u,"float64"),c=t.shape[i],g=u.reduce((o,s)=>o*s,1);for(let o=0;o<g;o++){let s=o;const l=[];for(let r=u.length-1;r>=0;r--)l[r]=s%u[r],s=Math.floor(s/u[r]);const n=p?[...l.slice(0,i),0,...l.slice(i+1)]:[...l.slice(0,i),0,...l.slice(i)];let m;if(e===1/0){m=0;for(let r=0;r<c;r++)n[i]=r,m=Math.max(m,Math.abs(Number(t.get(...n))))}else if(e===-1/0){m=1/0;for(let r=0;r<c;r++)n[i]=r,m=Math.min(m,Math.abs(Number(t.get(...n))))}else if(e===0){m=0;for(let r=0;r<c;r++)n[i]=r,Number(t.get(...n))!==0&&m++}else if(e===1){m=0;for(let r=0;r<c;r++)n[i]=r,m+=Math.abs(Number(t.get(...n)))}else if(e===2){m=0;for(let r=0;r<c;r++){n[i]=r;const a=Number(t.get(...n));m+=a*a}m=Math.sqrt(m)}else{m=0;for(let r=0;r<c;r++)n[i]=r,m+=Math.pow(Math.abs(Number(t.get(...n))),e);m=Math.pow(m,1/e)}f.set(l,m)}return f}function P(t,e="fro",h=!1){if(t.ndim!==2)throw new Error(`matrix_norm: input must be 2D, got ${t.ndim}D`);const[p,i]=t.shape;let u;if(e==="fro"){u=0;for(let f=0;f<p;f++)for(let c=0;c<i;c++){const g=Number(t.get(f,c));u+=g*g}u=Math.sqrt(u)}else if(e==="nuc"){const{s:f}=O(t);u=0;for(let c=0;c<f.size;c++)u+=Number(f.get(c))}else if(e===1){u=0;for(let f=0;f<i;f++){let c=0;for(let g=0;g<p;g++)c+=Math.abs(Number(t.get(g,f)));u=Math.max(u,c)}}else if(e===-1){u=1/0;for(let f=0;f<i;f++){let c=0;for(let g=0;g<p;g++)c+=Math.abs(Number(t.get(g,f)));u=Math.min(u,c)}}else if(e===1/0){u=0;for(let f=0;f<p;f++){let c=0;for(let g=0;g<i;g++)c+=Math.abs(Number(t.get(f,g)));u=Math.max(u,c)}}else if(e===-1/0){u=1/0;for(let f=0;f<p;f++){let c=0;for(let g=0;g<i;g++)c+=Math.abs(Number(t.get(f,g)));u=Math.min(u,c)}}else if(e===2){const{s:f}=O(t);u=Number(f.get(0))}else if(e===-2){const{s:f}=O(t);u=Number(f.get(f.size-1))}else throw new Error(`matrix_norm: invalid ord value: ${e}`);if(h){const f=z.zeros([1,1],"float64");return f.set([0,0],u),f}return u}function Ve(t,e=null,h=null,p=!1){if(e===null)return h===null?W(t,2,null,p):typeof h=="number"?W(t,2,h,p):P(t,"fro",p);if(Array.isArray(h)){if(h.length!==2)throw new Error("norm: axis must be a 2-tuple for matrix norms");const i=h[0]<0?t.ndim+h[0]:h[0],u=h[1]<0?t.ndim+h[1]:h[1];if(t.ndim!==2||i!==0&&i!==1||u!==0&&u!==1||i===u)throw new Error("norm: complex axis specification not yet supported");return P(t,e,p)}if(t.ndim===2&&h===null&&(e==="fro"||e==="nuc"))return P(t,e,p);if(typeof e!="number"&&e!==null)throw new Error(`norm: ord '${e}' not valid for vector norm`);return W(t,e??2,h,p)}function ge(t,e="reduced"){if(t.ndim!==2)throw new Error(`qr: input must be 2D, got ${t.ndim}D`);const[h,p]=t.shape,i=Math.min(h,p),u=z.zeros([h,p],"float64");for(let m=0;m<h;m++)for(let r=0;r<p;r++)u.set([m,r],Number(t.get(m,r)));const f=[],c=[];for(let m=0;m<i;m++){const r=h-m,a=[];for(let A=m;A<h;A++)a.push(Number(u.get(A,m)));let b=0;for(let A=0;A<r;A++)b+=a[A]*a[A];if(b=Math.sqrt(b),b<1e-15){f.push(a),c.push(0);continue}const y=a[0]>=0?1:-1,w=a[0]+y*b,d=[1];for(let A=1;A<r;A++)d.push(a[A]/w);const x=y*w/b;c.push(x),f.push(d);for(let A=m;A<p;A++){let S=0;for(let v=0;v<r;v++)S+=d[v]*Number(u.get(m+v,A));for(let v=0;v<r;v++)u.set([m+v,A],Number(u.get(m+v,A))-x*d[v]*S)}}if(e==="raw"){const m=z.zeros([h,p],"float64");for(let a=0;a<h;a++)for(let b=0;b<p;b++)m.set([a,b],Number(u.get(a,b)));const r=z.zeros([i],"float64");for(let a=0;a<i;a++)r.set([a],c[a]);return{h:m,tau:r}}if(e==="r"){const m=z.zeros([i,p],"float64");for(let r=0;r<i;r++)for(let a=r;a<p;a++)m.set([r,a],Number(u.get(r,a)));return m}const g=e==="complete"?h:i,o=z.zeros([h,g],"float64");for(let m=0;m<Math.min(h,g);m++)o.set([m,m],1);for(let m=i-1;m>=0;m--){const r=f[m],a=c[m],b=h-m;for(let y=m;y<g;y++){let w=0;for(let d=0;d<b;d++)w+=r[d]*Number(o.get(m+d,y));for(let d=0;d<b;d++)o.set([m+d,y],Number(o.get(m+d,y))-a*r[d]*w)}}const s=z.zeros([h,g],"float64");for(let m=0;m<h;m++)for(let r=0;r<g;r++)s.set([m,r],Number(o.get(m,r)));const l=e==="complete"?h:i,n=z.zeros([l,p],"float64");for(let m=0;m<l;m++)for(let r=0;r<p;r++)r>=m&&n.set([m,r],Number(u.get(m,r)));return{q:s,r:n}}function ke(t,e=!1){if(t.ndim!==2)throw new Error(`cholesky: input must be 2D, got ${t.ndim}D`);const[h,p]=t.shape;if(h!==p)throw new Error(`cholesky: matrix must be square, got ${h}x${p}`);const i=h,u=z.zeros([i,i],"float64");for(let f=0;f<i;f++)for(let c=0;c<=f;c++){let g=0;if(f===c){for(let s=0;s<c;s++)g+=Number(u.get(c,s))**2;const o=Number(t.get(c,c))-g;if(o<0)throw new Error("cholesky: matrix is not positive definite");u.set([c,c],Math.sqrt(o))}else{for(let s=0;s<c;s++)g+=Number(u.get(f,s))*Number(u.get(c,s));const o=Number(u.get(c,c));if(Math.abs(o)<1e-15)throw new Error("cholesky: matrix is not positive definite");u.set([f,c],(Number(t.get(f,c))-g)/o)}}if(e){const f=z.zeros([i,i],"float64");for(let c=0;c<i;c++)for(let g=c;g<i;g++)f.set([c,g],Number(u.get(g,c)));return f}return u}function O(t){if(t.ndim!==2)throw new Error(`svd: input must be 2D, got ${t.ndim}D`);const[e,h]=t.shape,p=Math.min(e,h),i=z.zeros([h,h],"float64");for(let l=0;l<h;l++)for(let n=0;n<h;n++){let m=0;for(let r=0;r<e;r++)m+=Number(t.get(r,l))*Number(t.get(r,n));i.set([l,n],m)}const{values:u,vectors:f}=Z(i),c=Array.from({length:h},(l,n)=>n);c.sort((l,n)=>u[n]-u[l]);const g=z.zeros([p],"float64");for(let l=0;l<p;l++){const n=u[c[l]];g.set([l],Math.sqrt(Math.max(0,n)))}const o=z.zeros([h,h],"float64");for(let l=0;l<h;l++)for(let n=0;n<h;n++)o.set([l,n],f[n][c[l]]);const s=z.zeros([e,e],"float64");for(let l=0;l<e;l++)for(let n=0;n<p;n++){const m=Number(g.get(n));if(m>1e-10){let r=0;for(let a=0;a<h;a++)r+=Number(t.get(l,a))*Number(o.get(n,a));s.set([l,n],r/m)}}if(e>p)for(let l=p;l<e;l++){const n=new Array(e).fill(0);n[l]=1;for(let r=0;r<l;r++){let a=0;for(let b=0;b<e;b++)a+=n[b]*Number(s.get(b,r));for(let b=0;b<e;b++)n[b]=n[b]-a*Number(s.get(b,r))}let m=0;for(let r=0;r<e;r++)m+=n[r]*n[r];if(m=Math.sqrt(m),m>1e-10)for(let r=0;r<e;r++)s.set([r,l],n[r]/m)}return{u:s,s:g,vt:o}}function Z(t){const e=t.shape[0],h=100*e*e,p=1e-10,i=[];for(let c=0;c<e;c++){i.push([]);for(let g=0;g<e;g++)i[c].push(Number(t.get(c,g)))}const u=[];for(let c=0;c<e;c++){u.push([]);for(let g=0;g<e;g++)u[c].push(c===g?1:0)}for(let c=0;c<h;c++){let g=0,o=0,s=1;for(let d=0;d<e;d++)for(let x=d+1;x<e;x++)Math.abs(i[d][x])>g&&(g=Math.abs(i[d][x]),o=d,s=x);if(g<p)break;const l=i[o][o],n=i[s][s],m=i[o][s];let r;Math.abs(l-n)<1e-15?r=Math.PI/4:r=.5*Math.atan2(2*m,n-l);const a=Math.cos(r),b=Math.sin(r),y=a*a*l+b*b*n-2*b*a*m,w=b*b*l+a*a*n+2*b*a*m;i[o][o]=y,i[s][s]=w,i[o][s]=0,i[s][o]=0;for(let d=0;d<e;d++)if(d!==o&&d!==s){const x=i[d][o],A=i[d][s];i[d][o]=a*x-b*A,i[o][d]=i[d][o],i[d][s]=b*x+a*A,i[s][d]=i[d][s]}for(let d=0;d<e;d++){const x=u[d][o],A=u[d][s];u[d][o]=a*x-b*A,u[d][s]=b*x+a*A}}const f=[];for(let c=0;c<e;c++)f.push(i[c][c]);return{values:f,vectors:u}}function be(t,e=!0,h=!0){const p=O(t);if(!h)return p.s;if(!e){const[i,u]=t.shape,f=Math.min(i,u),c=z.zeros([i,f],"float64");for(let o=0;o<i;o++)for(let s=0;s<f;s++)c.set([o,s],Number(p.u.get(o,s)));const g=z.zeros([f,u],"float64");for(let o=0;o<f;o++)for(let s=0;s<u;s++)g.set([o,s],Number(p.vt.get(o,s)));return{u:c,s:p.s,vt:g}}return p}function Fe(t){if(t.ndim!==2)throw new Error(`det: input must be 2D, got ${t.ndim}D`);const[e,h]=t.shape;if(e!==h)throw new Error(`det: matrix must be square, got ${e}x${h}`);const p=e;if(p===0)return 1;const i=t.data;if(p===1)return Number(i[0]);if(p===2)return Number(i[0])*Number(i[3])-Number(i[1])*Number(i[2]);const{lu:u,sign:f}=Q(t),c=u.data;let g=f;for(let o=0;o<p;o++)g*=c[o*p+o];return g}function Q(t){const[e,h]=t.shape,p=e,i=h,u=z.zeros([p,i],"float64"),f=u.data,c=t.data;for(let s=0;s<p*i;s++)f[s]=Number(c[s]);const g=Array.from({length:p},(s,l)=>l);let o=1;for(let s=0;s<Math.min(p,i);s++){let l=Math.abs(f[s*i+s]),n=s;for(let r=s+1;r<p;r++){const a=Math.abs(f[r*i+s]);a>l&&(l=a,n=r)}if(n!==s){for(let a=0;a<i;a++){const b=f[s*i+a];f[s*i+a]=f[n*i+a],f[n*i+a]=b}const r=g[s];g[s]=g[n],g[n]=r,o=-o}const m=f[s*i+s];if(Math.abs(m)>1e-15)for(let r=s+1;r<p;r++){const a=f[r*i+s]/m;f[r*i+s]=a;for(let b=s+1;b<i;b++)f[r*i+b]=f[r*i+b]-a*f[s*i+b]}}return{lu:u,piv:g,sign:o}}function K(t){if(t.ndim!==2)throw new Error(`inv: input must be 2D, got ${t.ndim}D`);const[e,h]=t.shape;if(e!==h)throw new Error(`inv: matrix must be square, got ${e}x${h}`);const p=e,{lu:i,piv:u}=Q(t),f=i.data,c=z.zeros([p,p],"float64"),g=c.data;for(let o=0;o<p;o++){const s=new Float64Array(p);for(let l=0;l<p;l++){let n=u[l]===o?1:0;for(let m=0;m<l;m++)n-=f[l*p+m]*s[m];s[l]=n}for(let l=p-1;l>=0;l--){let n=s[l];for(let r=l+1;r<p;r++)n-=f[l*p+r]*g[r*p+o];const m=f[l*p+l];if(Math.abs(m)<1e-15)throw new Error("inv: singular matrix");g[l*p+o]=n/m}}return c}function oe(t,e){const[h]=t.shape,p=h,{lu:i,piv:u}=Q(t),f=i.data,c=e.data,g=new Float64Array(p);for(let n=0;n<p;n++)g[n]=Number(c[u[n]]);const o=new Float64Array(p);for(let n=0;n<p;n++){let m=g[n];for(let r=0;r<n;r++)m-=f[n*p+r]*o[r];o[n]=m}const s=z.zeros([p],"float64"),l=s.data;for(let n=p-1;n>=0;n--){let m=o[n];for(let a=n+1;a<p;a++)m-=f[n*p+a]*l[a];const r=f[n*p+n];if(Math.abs(r)<1e-15)throw new Error("solve: singular matrix");l[n]=m/r}return s}function de(t,e){if(t.ndim!==2)throw new Error(`solve: coefficient matrix must be 2D, got ${t.ndim}D`);const[h,p]=t.shape;if(h!==p)throw new Error(`solve: coefficient matrix must be square, got ${h}x${p}`);const i=h;if(e.ndim===1){if(e.shape[0]!==i)throw new Error(`solve: incompatible shapes (${h},${p}) and (${e.shape[0]},)`);return oe(t,e)}if(e.ndim===2){if(e.shape[0]!==i)throw new Error(`solve: incompatible shapes (${h},${p}) and (${e.shape[0]},${e.shape[1]})`);const u=e.shape[1],f=z.zeros([i,u],"float64");for(let c=0;c<u;c++){const g=z.zeros([i],"float64");for(let s=0;s<i;s++)g.set([s],Number(e.get(s,c)));const o=oe(t,g);for(let s=0;s<i;s++)f.set([s,c],Number(o.get(s)))}return f}throw new Error(`solve: b must be 1D or 2D, got ${e.ndim}D`)}function qe(t,e,h=null){if(t.ndim!==2)throw new Error(`lstsq: coefficient matrix must be 2D, got ${t.ndim}D`);const[p,i]=t.shape,{u,s:f,vt:c}=O(t),g=Math.min(p,i),o=h??Math.max(p,i)*Number.EPSILON,l=Number(f.get(0))*o;let n=0;for(let w=0;w<g;w++)Number(f.get(w))>l&&n++;const m=e.ndim===1?R.reshape(e,[e.size,1]):e,r=m.shape[1];if(m.shape[0]!==p)throw new Error(`lstsq: incompatible shapes (${p},${i}) and (${e.shape.join(",")})`);const a=z.zeros([i,r],"float64");for(let w=0;w<r;w++){const d=new Array(p).fill(0);for(let x=0;x<p;x++)for(let A=0;A<p;A++)d[x]+=Number(u.get(A,x))*Number(m.get(A,w));for(let x=0;x<i;x++){let A=0;for(let S=0;S<g;S++){const v=Number(f.get(S));v>l&&(A+=Number(c.get(S,x))*d[S]/v)}a.set([x,w],A)}}let b;if(p>i){b=z.zeros([r],"float64");for(let w=0;w<r;w++){let d=0;for(let x=0;x<p;x++){let A=0;for(let v=0;v<i;v++)A+=Number(t.get(x,v))*Number(a.get(v,w));const S=A-Number(m.get(x,w));d+=S*S}b.set([w],d)}}else b=z.zeros([0],"float64");return{x:e.ndim===1?R.reshape(a,[i]):a,residuals:b,rank:n,s:f}}function Re(t,e=2){if(t.ndim!==2)throw new Error(`cond: input must be 2D, got ${t.ndim}D`);const[h,p]=t.shape;if(e===2||e===-2){const{s:c}=O(t),g=Math.min(h,p),o=Number(c.get(0)),s=Number(c.get(g-1));return e===2?s>0?o/s:1/0:o>0?s/o:0}if(h!==p)throw new Error(`cond: matrix must be square for p=${e}`);const i=P(t,e),u=K(t),f=P(u,e);return i*f}function _e(t,e){if(t.ndim===0)return Number(t.get())!==0?1:0;if(t.ndim===1){for(let f=0;f<t.size;f++)if(Number(t.get(f))!==0)return 1;return 0}if(t.ndim!==2)throw new Error(`matrix_rank: input must be at most 2D, got ${t.ndim}D`);const{s:h}=O(t),p=Number(h.get(0)),i=e??p*Math.max(t.shape[0],t.shape[1])*Number.EPSILON;let u=0;for(let f=0;f<h.size;f++)Number(h.get(f))>i&&u++;return u}function Be(t,e){if(t.ndim!==2)throw new Error(`matrix_power: input must be 2D, got ${t.ndim}D`);const[h,p]=t.shape;if(h!==p)throw new Error(`matrix_power: matrix must be square, got ${h}x${p}`);const i=h;if(!Number.isInteger(e))throw new Error("matrix_power: exponent must be an integer");if(e===0){const o=z.zeros([i,i],"float64");for(let s=0;s<i;s++)o.set([s,s],1);return o}let u=t,f=e;e<0&&(u=K(t),f=-e);let c=z.zeros([i,i],"float64");for(let o=0;o<i;o++)c.set([o,o],1);let g=z.zeros([i,i],"float64");for(let o=0;o<i;o++)for(let s=0;s<i;s++)g.set([o,s],Number(u.get(o,s)));for(;f>0;)f&1&&(c=B(c,g)),g=B(g,g),f>>=1;return c}function Te(t,e=1e-15){if(t.ndim!==2)throw new Error(`pinv: input must be 2D, got ${t.ndim}D`);const[h,p]=t.shape,{u:i,s:u,vt:f}=O(t),c=Math.min(h,p),o=Number(u.get(0))*e,s=z.zeros([p,h],"float64");for(let l=0;l<p;l++)for(let n=0;n<h;n++){let m=0;for(let r=0;r<c;r++){const a=Number(u.get(r));a>o&&(m+=Number(f.get(r,l))*Number(i.get(n,r))/a)}s.set([l,n],m)}return s}function ye(t){if(t.ndim!==2)throw new Error(`eig: input must be 2D, got ${t.ndim}D`);const[e,h]=t.shape;if(e!==h)throw new Error(`eig: matrix must be square, got ${e}x${h}`);const p=e;let i=!0;e:for(let s=0;s<p;s++)for(let l=s+1;l<p;l++)if(Math.abs(Number(t.get(s,l))-Number(t.get(l,s)))>1e-10){i=!1;break e}if(i){const{values:s,vectors:l}=Z(t),n=z.zeros([p],"float64"),m=z.zeros([p,p],"float64");for(let r=0;r<p;r++){n.set([r],s[r]);for(let a=0;a<p;a++)m.set([a,r],l[a][r])}return{w:n,v:m}}const{values:u,vectors:f,hasComplexEigenvalues:c}=we(t);c&&console.warn("numpy-ts: eig() detected complex eigenvalues which cannot be represented. Results are real approximations and may be inaccurate. For symmetric matrices, use eigh() instead.");const g=z.zeros([p],"float64"),o=z.zeros([p,p],"float64");for(let s=0;s<p;s++){g.set([s],u[s]);for(let l=0;l<p;l++)o.set([l,s],f[l][s])}return{w:g,v:o}}function we(t){const e=t.shape[0],h=1e3,p=1e-10;let i=z.zeros([e,e],"float64");for(let o=0;o<e;o++)for(let s=0;s<e;s++)i.set([o,s],Number(t.get(o,s)));let u=z.zeros([e,e],"float64");for(let o=0;o<e;o++)u.set([o,o],1);for(let o=0;o<h;o++){let s=0;for(let r=0;r<e;r++)for(let a=0;a<e;a++)r!==a&&(s+=Number(i.get(r,a))**2);if(Math.sqrt(s)<p*e)break;const l=ge(i,"reduced"),n=l.q,m=l.r;i=B(m,n),u=B(u,n)}let f=!1;for(let o=0;o<e-1;o++){const s=Math.abs(Number(i.get(o+1,o))),l=Math.abs(Number(i.get(o,o))),n=Math.abs(Number(i.get(o+1,o+1))),m=Math.max(l,n,1e-10);if(s/m>1e-6){f=!0;break}}const c=[];for(let o=0;o<e;o++)c.push(Number(i.get(o,o)));const g=[];for(let o=0;o<e;o++){g.push([]);for(let s=0;s<e;s++)g[o].push(Number(u.get(o,s)))}return{values:c,vectors:g,hasComplexEigenvalues:f}}function Ae(t,e="L"){if(t.ndim!==2)throw new Error(`eigh: input must be 2D, got ${t.ndim}D`);const[h,p]=t.shape;if(h!==p)throw new Error(`eigh: matrix must be square, got ${h}x${p}`);const i=h,u=z.zeros([i,i],"float64");for(let l=0;l<i;l++)for(let n=0;n<i;n++)e==="L"?l>=n&&(u.set([l,n],Number(t.get(l,n))),u.set([n,l],Number(t.get(l,n)))):n>=l&&(u.set([l,n],Number(t.get(l,n))),u.set([n,l],Number(t.get(l,n))));const{values:f,vectors:c}=Z(u),g=Array.from({length:i},(l,n)=>n);g.sort((l,n)=>f[l]-f[n]);const o=z.zeros([i],"float64"),s=z.zeros([i,i],"float64");for(let l=0;l<i;l++){o.set([l],f[g[l]]);for(let n=0;n<i;n++)s.set([n,l],c[n][g[l]])}return{w:o,v:s}}function Oe(t){const{w:e}=ye(t);return e}function Le(t,e="L"){const{w:h}=Ae(t,e);return h}function Pe(t,e){const h=R.flatten(t),p=R.flatten(e),i=h.shape[0],u=p.shape[0];if(i!==u)throw new Error(`vdot: arrays must have same number of elements, got ${i} and ${u}`);if(k(t.dtype)||k(e.dtype)){let g=0,o=0;for(let s=0;s<i;s++){const l=h.get(s),n=p.get(s),m=l instanceof I?l.re:Number(l),r=l instanceof I?-l.im:0,a=n instanceof I?n.re:Number(n),b=n instanceof I?n.im:0;g+=m*a+r*b,o+=m*b-r*a}return Math.abs(o)<1e-15?g:new I(g,o)}let c=0;for(let g=0;g<i;g++){const o=h.get(g),s=p.get(g);typeof o=="bigint"&&typeof s=="bigint"?c=(typeof c=="bigint"?c:BigInt(c))+o*s:c=(typeof c=="bigint"?Number(c):c)+Number(o)*Number(s)}return c}function Je(t,e,h=-1){const p=t.ndim,i=e.ndim,u=h<0?p+h:h,f=h<0?i+h:h;if(u<0||u>=p)throw new Error(`vecdot: axis ${h} out of bounds for array with ${p} dimensions`);if(f<0||f>=i)throw new Error(`vecdot: axis ${h} out of bounds for array with ${i} dimensions`);const c=t.shape[u],g=e.shape[f];if(c!==g)throw new Error(`vecdot: axis dimensions must match, got ${c} and ${g}`);if(p===1&&i===1)return X(t,e);const o=[...t.shape.slice(0,u),...t.shape.slice(u+1)],s=[...e.shape.slice(0,f),...e.shape.slice(f+1)],l=c,n=k(t.dtype)||k(e.dtype),m=V(t.dtype,e.dtype),r=o.length>s.length?o:s;if(r.length===0){let y=n?new I(0,0):0;for(let w=0;w<l;w++){const d=t.get(w),x=e.get(w),A=T(d,x);if(y instanceof I||A instanceof I){const S=y instanceof I?y:new I(Number(y),0),v=A instanceof I?A:new I(Number(A),0);y=S.add(v)}else typeof y=="bigint"||typeof A=="bigint"?y=BigInt(y)+BigInt(A):y=y+A}return y}const a=z.zeros(r,m),b=r.reduce((y,w)=>y*w,1);for(let y=0;y<b;y++){const w=[];let d=y;for(let v=r.length-1;v>=0;v--)w.unshift(d%r[v]),d=Math.floor(d/r[v]);const x=[...w.slice(0,u),0,...w.slice(u)],A=[...w.slice(0,f),0,...w.slice(f)];let S=n?new I(0,0):0;for(let v=0;v<l;v++){x[u]=v,A[f]=v;const N=t.get(...x),M=e.get(...A),$=T(N,M);if(S instanceof I||$ instanceof I){const D=S instanceof I?S:new I(Number(S),0),C=$ instanceof I?$:new I(Number($),0);S=D.add(C)}else typeof S=="bigint"||typeof $=="bigint"?S=BigInt(S)+BigInt($):S=S+$}a.set(w,S)}return a}function Xe(t){if(t.ndim<2)throw new Error(`matrix_transpose: input must have at least 2 dimensions, got ${t.ndim}D`);const e=Array.from({length:t.ndim},(p,i)=>i),h=e.length-1;return e[h]=h-1,e[h-1]=h,L(t,e)}function We(t,e){return L(t,e)}function Qe(t,e){if(t.ndim<2)throw new Error(`matvec: x1 must have at least 2 dimensions, got ${t.ndim}D`);if(e.ndim<1)throw new Error(`matvec: x2 must have at least 1 dimension, got ${e.ndim}D`);const h=t.shape[t.ndim-2],p=t.shape[t.ndim-1],i=e.shape[e.ndim-1];if(p!==i)throw new Error(`matvec: last axis of x1 (${p}) must match last axis of x2 (${i})`);if(t.ndim===2&&e.ndim===1)return X(t,e);const u=t.shape.slice(0,-2),f=e.shape.slice(0,-1),c=Math.max(u.length,f.length),g=[...Array(c-u.length).fill(1),...u],o=[...Array(c-f.length).fill(1),...f],s=[];for(let b=0;b<c;b++){const y=g[b],w=o[b];if(y!==1&&w!==1&&y!==w)throw new Error(`matvec: batch dimensions not broadcastable: ${u} vs ${f}`);s.push(Math.max(y,w))}const l=[...s,h],n=V(t.dtype,e.dtype),m=z.zeros(l,n),r=k(n),a=s.reduce((b,y)=>b*y,1);for(let b=0;b<a;b++){const y=[];let w=b;for(let A=s.length-1;A>=0;A--)y.unshift(w%s[A]),w=Math.floor(w/s[A]);const d=y.slice(-(u.length||1)).map((A,S)=>(u[S]??1)===1?0:A),x=y.slice(-(f.length||1)).map((A,S)=>(f[S]??1)===1?0:A);for(let A=0;A<h;A++){let S=r?new I(0,0):0;for(let N=0;N<p;N++){const M=[...d,A,N],$=[...x,N],D=t.get(...M),C=e.get(...$),E=T(D,C);if(S instanceof I||E instanceof I){const j=S instanceof I?S:new I(Number(S),0),F=E instanceof I?E:new I(Number(E),0);S=j.add(F)}else typeof S=="bigint"||typeof E=="bigint"?S=BigInt(S)+BigInt(E):S=S+E}const v=[...y,A];m.set(v,S)}}return m}function Ue(t,e){if(t.ndim<1)throw new Error(`vecmat: x1 must have at least 1 dimension, got ${t.ndim}D`);if(e.ndim<2)throw new Error(`vecmat: x2 must have at least 2 dimensions, got ${e.ndim}D`);const h=t.shape[t.ndim-1],p=e.shape[e.ndim-2],i=e.shape[e.ndim-1];if(h!==p)throw new Error(`vecmat: last axis of x1 (${h}) must match second-to-last axis of x2 (${p})`);if(t.ndim===1&&e.ndim===2)return X(t,e);const u=t.shape.slice(0,-1),f=e.shape.slice(0,-2),c=Math.max(u.length,f.length),g=[...Array(c-u.length).fill(1),...u],o=[...Array(c-f.length).fill(1),...f],s=[];for(let b=0;b<c;b++){const y=g[b],w=o[b];if(y!==1&&w!==1&&y!==w)throw new Error(`vecmat: batch dimensions not broadcastable: ${u} vs ${f}`);s.push(Math.max(y,w))}const l=[...s,i],n=V(t.dtype,e.dtype),m=z.zeros(l,n),r=k(n),a=s.reduce((b,y)=>b*y,1);for(let b=0;b<a;b++){const y=[];let w=b;for(let A=s.length-1;A>=0;A--)y.unshift(w%s[A]),w=Math.floor(w/s[A]);const d=y.slice(-(u.length||1)).map((A,S)=>(u[S]??1)===1?0:A),x=y.slice(-(f.length||1)).map((A,S)=>(f[S]??1)===1?0:A);for(let A=0;A<i;A++){let S=r?new I(0,0):0;for(let N=0;N<h;N++){const M=[...d,N],$=[...x,N,A],D=t.get(...M),C=e.get(...$),E=T(D,C);if(S instanceof I||E instanceof I){const j=S instanceof I?S:new I(Number(S),0),F=E instanceof I?E:new I(Number(E),0);S=j.add(F)}else typeof S=="bigint"||typeof E=="bigint"?S=BigInt(S)+BigInt(E):S=S+E}const v=[...y,A];m.set(v,S)}}return m}function Ge(t){if(t.ndim!==2)throw new Error(`slogdet: input must be 2D, got ${t.ndim}D`);const[e,h]=t.shape;if(e!==h)throw new Error(`slogdet: matrix must be square, got ${e}x${h}`);const p=e;if(p===0)return{sign:1,logabsdet:0};const{lu:i,sign:u}=Q(t),f=i.data;let c=0,g=u;for(let o=0;o<p;o++){const s=f[o*p+o];if(s===0)return{sign:0,logabsdet:-1/0};s<0&&(g=-g),c+=Math.log(Math.abs(s))}return{sign:g,logabsdet:c}}function He(t){return be(t,!0,!1)}function Ye(t){if(t.length<2)throw new Error("multi_dot: need at least 2 arrays");if(t.length===2)return B(t[0],t[1]);let e=t[0];for(let h=1;h<t.length;h++)e=B(e,t[h]);return e}function Ze(t,e=2){if(e<=0)throw new Error(`tensorinv: ind must be positive, got ${e}`);const h=t.shape,p=t.ndim;if(p<e)throw new Error(`tensorinv: array has ${p} dimensions, ind=${e} is too large`);let i=1;for(let o=0;o<e;o++)i*=h[o];let u=1;for(let o=e;o<p;o++)u*=h[o];if(i!==u)throw new Error(`tensorinv: product of first ${e} dimensions (${i}) must equal product of remaining dimensions (${u})`);const f=R.reshape(t,[i,u]),c=K(f),g=[...h.slice(e),...h.slice(0,e)];return R.reshape(c,g)}function Ke(t,e,h){const p=t.shape,i=e.shape,u=t.ndim,f=e.ndim;let c;h==null?c=Array.from({length:f},(d,x)=>u-f+x):c=h.map(d=>d<0?u+d:d);const g=[];for(let d=0;d<u;d++)c.includes(d)||g.push(d);const o=[...g,...c],s=L(t,o),n=c.map(d=>p[d]).reduce((d,x)=>d*x,1),r=g.map(d=>p[d]).reduce((d,x)=>d*x,1),a=i.reduce((d,x)=>d*x,1);if(n!==a)throw new Error(`tensorsolve: dimensions don't match - sum dimensions product (${n}) != b total elements (${a})`);if(r!==n)throw new Error(`tensorsolve: non-square problem - other dimensions product (${r}) != sum dimensions product (${n})`);const b=R.reshape(s,[r,n]),y=R.reshape(e,[n]),w=de(b,y);return R.reshape(w,[...i])}function et(t,...e){const h=t.indexOf("->");let p,i;h===-1?(p=t,i=ne(p)):(p=t.slice(0,h),i=t.slice(h+2));const u=p.split(",").map(n=>n.trim());if(u.length!==e.length)throw new Error(`einsum_path: expected ${u.length} operands, got ${e.length}`);const f=e.map(n=>Array.isArray(n)?n:Array.from(n.shape)),c=new Map;for(let n=0;n<e.length;n++){const m=u[n],r=f[n];if(m.length!==r.length)throw new Error(`einsum_path: operand ${n} has ${r.length} dimensions but subscript '${m}' has ${m.length} indices`);for(let a=0;a<m.length;a++){const b=m[a],y=r[a];if(c.has(b)&&c.get(b)!==y)throw new Error(`einsum_path: size mismatch for index '${b}': ${c.get(b)} vs ${y}`);c.set(b,y)}}if(e.length===1){const n=[[0]];return[n,ee(t,f,n,c)]}if(e.length===2){const n=[[0,1]];return[n,ee(t,f,n,c)]}const g=[],o=[...u],s=[...f],l=e.map((n,m)=>m);for(;o.length>1;){let n=0,m=1,r=1/0;for(let y=0;y<o.length;y++)for(let w=y+1;w<o.length;w++){const d=xe(o[y],o[w],s[y],s[w],i,c);d<r&&(r=d,n=y,m=w)}g.push([l[n],l[m]]);const[a,b]=Se(o[n],o[m],s[n],s[m],i,c);o.splice(m,1),o.splice(n,1),s.splice(m,1),s.splice(n,1),l.splice(m,1),l.splice(n,1),o.push(a),s.push(b),l.push(-1)}return[g,ee(t,f,g,c)]}function xe(t,e,h,p,i,u){const f=new Set(t),c=new Set(e);let g=1;for(const o of f)g*=u.get(o)||1;for(const o of c)f.has(o)||(g*=u.get(o)||1);return g}function Se(t,e,h,p,i,u){const f=new Set([...t,...e]),c=new Map;for(const l of t)c.set(l,(c.get(l)||0)+1);for(const l of e)c.set(l,(c.get(l)||0)+1);const g=new Set(i),o=[];for(const l of f)(g.has(l)||c.get(l)===1)&&o.push(l);o.sort();const s=o.map(l=>u.get(l));return[o.join(""),s]}function ee(t,e,h,p){const i=[];i.push(" Complete contraction: "+t),i.push(" Operand shapes: "+e.map(f=>`(${f.join(", ")})`).join(", ")),i.push(" Contraction path: "+JSON.stringify(h));let u=0;for(const f of e)u+=f.reduce((c,g)=>c*g,1);return i.push(" Estimated FLOPS: ~"+u.toExponential(2)),i.join(`
2
+ `)}export{ke as cholesky,Re as cond,je as cross,Fe as det,ze as diagonal,X as dot,ye as eig,Ae as eigh,Oe as eigvals,Le as eigvalsh,Ee as einsum,et as einsum_path,Me as inner,K as inv,Ce as kron,qe as lstsq,B as matmul,P as matrix_norm,Be as matrix_power,_e as matrix_rank,Xe as matrix_transpose,Qe as matvec,Ye as multi_dot,Ve as norm,pe as outer,We as permute_dims,Te as pinv,ge as qr,Ge as slogdet,de as solve,be as svd,He as svdvals,De as tensordot,Ze as tensorinv,Ke as tensorsolve,$e as trace,L as transpose,Pe as vdot,Je as vecdot,Ue as vecmat,W as vector_norm};
@@ -1 +1 @@
1
- import*as t from"../common/ops/formatting";import{toStorage as o}from"./types";const l=t.set_printoptions,m=t.get_printoptions,_=t.printoptions,u=t.format_float_positional,f=t.format_float_scientific,x=t.base_repr,c=t.binary_repr;function g(e,r){return t.array2string(o(e),r?.max_line_width??null,r?.precision??null,r?.suppress_small??null,r?.separator??" ",r?.prefix??"",r?.suffix??"",r?.threshold??null,r?.edgeitems??null)}function b(e,r,n,i){return t.array_repr(o(e),r,n,i)}function y(e,r,n){return t.array_str(o(e),r,n)}export{g as array2string,b as array_repr,y as array_str,x as base_repr,c as binary_repr,u as format_float_positional,f as format_float_scientific,m as get_printoptions,_ as printoptions,l as set_printoptions};
1
+ import*as t from"../common/ops/formatting";import{toStorage as o}from"./types";const l=t.set_printoptions,m=t.get_printoptions,u=t.printoptions,_=t.format_float_positional,f=t.format_float_scientific,x=t.base_repr,c=t.binary_repr;function g(e,r){return t.array2string(o(e),r?.max_line_width??null,r?.precision??null,r?.suppress_small??null,r?.separator??" ",r?.prefix??"",r?.suffix??"",r?.threshold??null,r?.edgeitems??null,r?.floatmode??null,r?.sign??null)}function b(e,r,n,a){return t.array_repr(o(e),r,n,a)}function y(e,r,n){return t.array_str(o(e),r,n)}export{g as array2string,b as array_repr,y as array_str,x as base_repr,c as binary_repr,_ as format_float_positional,f as format_float_scientific,m as get_printoptions,u as printoptions,l as set_printoptions};
@@ -1 +1 @@
1
- import{parseSlice as z,normalizeSlice as v}from"../common/slicing";import{getTypedArrayConstructor as x,getDTypeSize as p,isBigIntDType as A,isComplexDType as E}from"../common/dtype";import{Complex as g}from"../common/complex";import{ArrayStorage as N}from"../common/storage";import{NDArrayCore as y}from"../common/ndarray-core";import*as n from"../core";const s=f=>{if(f instanceof c)return f;const r=f.base?s(f.base):void 0;return c.fromStorage(f.storage,r)};class c extends y{constructor(r,e){super(r,e),this._base=e}static fromStorage(r,e){return new c(r,e)}get base(){return this._base??null}get T(){return this.transpose()}get itemsize(){return p(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(r){const e=this._storage.dtype,t=this.size;if(A(e)){const a=typeof r=="bigint"?r:BigInt(Math.round(Number(r)));for(let i=0;i<t;i++)this._storage.iset(i,a)}else if(e==="bool"){const a=r?1:0;for(let i=0;i<t;i++)this._storage.iset(i,a)}else{const a=Number(r);for(let i=0;i<t;i++)this._storage.iset(i,a)}}*[Symbol.iterator](){if(this.ndim===0)yield this._storage.iget(0);else if(this.ndim===1)for(let r=0;r<this.shape[0];r++)yield this._storage.iget(r);else for(let r=0;r<this.shape[0];r++)yield this.slice(String(r))}get(r){if(r.length!==this.ndim)throw new Error(`Index has ${r.length} dimensions, but array has ${this.ndim} dimensions`);const e=r.map((t,a)=>{let i=t;if(i<0&&(i=this.shape[a]+i),i<0||i>=this.shape[a])throw new Error(`Index ${t} is out of bounds for axis ${a} with size ${this.shape[a]}`);return i});return this._storage.get(...e)}set(r,e){if(r.length!==this.ndim)throw new Error(`Index has ${r.length} dimensions, but array has ${this.ndim} dimensions`);const t=r.map((i,o)=>{let m=i;if(m<0&&(m=this.shape[o]+m),m<0||m>=this.shape[o])throw new Error(`Index ${i} is out of bounds for axis ${o} with size ${this.shape[o]}`);return m}),a=this.dtype;if(E(a))this._storage.set(t,e);else if(A(a)){const i=e instanceof g?e.re:Number(e),o=typeof e=="bigint"?e:BigInt(Math.round(i));this._storage.set(t,o)}else if(a==="bool"){const o=(e instanceof g?e.re:Number(e))?1:0;this._storage.set(t,o)}else{const i=e instanceof g?e.re:Number(e);this._storage.set(t,i)}}copy(){return new c(this._storage.copy())}astype(r,e=!0){const t=this.dtype;if(t===r&&!e)return this;if(t===r&&e)return this.copy();const a=Array.from(this.shape),i=this.size,o=x(r);if(!o)throw new Error(`Cannot convert to dtype ${r}`);const m=new o(i),u=this.data;if(A(t)&&!A(r)){const l=u;if(r==="bool")for(let h=0;h<i;h++)m[h]=l[h]!==BigInt(0)?1:0;else for(let h=0;h<i;h++)m[h]=Number(l[h])}else if(!A(t)&&A(r)){const l=u;for(let h=0;h<i;h++)m[h]=BigInt(Math.round(Number(l[h])))}else if(r==="bool"){const l=u;for(let h=0;h<i;h++)m[h]=l[h]!==0?1:0}else if(t==="bool"&&!A(r)){const l=u;for(let h=0;h<i;h++)m[h]=l[h]}else if(!A(t)&&!A(r)){const l=u;for(let h=0;h<i;h++)m[h]=l[h]}else{const l=u;for(let h=0;h<i;h++)m[h]=l[h]}const b=N.fromData(m,a,r);return new c(b)}slice(...r){if(r.length===0)return this;if(r.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${r.length} were indexed`);const e=r.map((u,b)=>{const l=z(u);return v(l,this.shape[b])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});const t=[],a=[];let i=this._storage.offset;for(let u=0;u<e.length;u++){const b=e[u],l=this._storage.strides[u];if(i+=b.start*l,!b.isIndex){let h;b.step>0?h=Math.max(0,Math.ceil((b.stop-b.start)/b.step)):h=Math.max(0,Math.ceil((b.start-b.stop)/Math.abs(b.step))),t.push(h),a.push(l*b.step)}}const o=N.fromData(this._storage.data,t,this._storage.dtype,a,i),m=this._base??this;return new c(o,m)}row(r){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(r),":")}col(r){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(r))}rows(r,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${r}:${e}`,":")}cols(r,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${r}:${e}`)}reshape(...r){const e=r.length===1&&Array.isArray(r[0])?r[0]:r,t=n.reshape(this,e).storage,i=t.data===this.data?this._base??this:void 0;return c.fromStorage(t,i)}ravel(){const r=n.ravel(this).storage,t=r.data===this.data?this._base??this:void 0;return c.fromStorage(r,t)}put(r,e){const t=e instanceof c?e._storage:e;n.put(this,r,t)}compress(r,e){const t=r instanceof c?r:c.fromStorage(N.fromData(new Uint8Array(r.map(a=>a?1:0)),[r.length],"bool"));return s(n.compress(t,this,e))}choose(r){return s(n.choose(this,r))}clip(r,e){return s(n.clip(this,r,e))}iindex(r,e=0){let t;if(r instanceof c){t=[];for(let a=0;a<r.size;a++){const i=r.storage.iget(a),o=typeof i=="bigint"?Number(i):i instanceof g?i.re:i;t.push(o)}}else Array.isArray(r)&&r.length>0&&Array.isArray(r[0])?t=r.flat():t=r;return this.take(t,e)}bindex(r,e){return s(n.compress(r,this,e))}toString(){return`NDArray(shape=${JSON.stringify(this.shape)}, dtype=${this.dtype})`}toArray(){if(this.ndim===0)return this._storage.iget(0);const r=this.shape,e=r.length,t=(a,i)=>{if(i===e)return this._storage.get(...a);const o=[];for(let m=0;m<r[i];m++)a[i]=m,o.push(t(a,i+1));return o};return t(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const t=this._storage.data,a=t.BYTES_PER_ELEMENT,i=this._storage.offset*a,o=this.size*a;return t.buffer.slice(i,i+o)}const e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...r){if(r.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(r.length===1){const e=r[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(r)}byteswap(r=!1){const e=r?this:this.copy(),t=e._storage.data,a=t.BYTES_PER_ELEMENT;if(a===1)return e;const i=t.buffer,o=new DataView(i);for(let m=0;m<t.length;m++){const u=m*a;if(a===2){const b=o.getUint8(u),l=o.getUint8(u+1);o.setUint8(u,l),o.setUint8(u+1,b)}else if(a===4){const b=o.getUint8(u),l=o.getUint8(u+1),h=o.getUint8(u+2),D=o.getUint8(u+3);o.setUint8(u,D),o.setUint8(u+1,h),o.setUint8(u+2,l),o.setUint8(u+3,b)}else if(a===8){const b=o.getUint8(u),l=o.getUint8(u+1),h=o.getUint8(u+2),D=o.getUint8(u+3),d=o.getUint8(u+4),w=o.getUint8(u+5),_=o.getUint8(u+6),U=o.getUint8(u+7);o.setUint8(u,U),o.setUint8(u+1,_),o.setUint8(u+2,w),o.setUint8(u+3,d),o.setUint8(u+4,D),o.setUint8(u+5,h),o.setUint8(u+6,l),o.setUint8(u+7,b)}}return e}view(r){if(!r||r===this.dtype)return c.fromStorage(this._storage,this._base??this);const e=p(this.dtype),t=p(r);if(e!==t)throw new Error("When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.");const a=x(r);if(!a)throw new Error(`Unsupported dtype: ${r}`);const i=this._storage.data,o=i.byteOffset+this._storage.offset*e,m=new a(i.buffer,o,this.size),u=N.fromData(m,[...this.shape],r,[...this._storage.strides],0);return c.fromStorage(u,this._base??this)}tofile(r,e="",t=""){throw new Error('tofile() requires file system access. Use the node module: import { save } from "numpy-ts/node"')}round(r=0){return this.around(r)}conjugate(){return this.conj()}around(r=0){return s(n.around(this,r))}allclose(r,e=1e-5,t=1e-8){return n.allclose(this,r,e,t)}isclose(r,e=1e-5,t=1e-8){return s(n.isclose(this,r,e,t))}average(r,e){const t=n.average(this,e,r);return t instanceof y?s(t):t}dot(r){const e=n.dot(this,r);return e instanceof y?s(e):e}trace(){return n.trace(this)}inner(r){const e=n.inner(this,r);return e instanceof y?s(e):e}tensordot(r,e=2){const t=n.tensordot(this,r,e);return t instanceof y?s(t):t}divmod(r){const e=n.divmod(this,r);return[s(e[0]),s(e[1])]}searchsorted(r,e="left"){return s(n.searchsorted(this,r,e))}sqrt(){return s(n.sqrt(this))}exp(){return s(n.exp(this))}exp2(){return s(n.exp2(this))}expm1(){return s(n.expm1(this))}log(){return s(n.log(this))}log2(){return s(n.log2(this))}log10(){return s(n.log10(this))}log1p(){return s(n.log1p(this))}absolute(){return s(n.absolute(this))}negative(){return s(n.negative(this))}sign(){return s(n.sign(this))}positive(){return s(n.positive(this))}reciprocal(){return s(n.reciprocal(this))}ceil(){return s(n.ceil(this))}fix(){return s(n.fix(this))}floor(){return s(n.floor(this))}rint(){return s(n.rint(this))}trunc(){return s(n.trunc(this))}sin(){return s(n.sin(this))}cos(){return s(n.cos(this))}tan(){return s(n.tan(this))}arcsin(){return s(n.arcsin(this))}arccos(){return s(n.arccos(this))}arctan(){return s(n.arctan(this))}degrees(){return s(n.degrees(this))}radians(){return s(n.radians(this))}sinh(){return s(n.sinh(this))}cosh(){return s(n.cosh(this))}tanh(){return s(n.tanh(this))}arcsinh(){return s(n.arcsinh(this))}arccosh(){return s(n.arccosh(this))}arctanh(){return s(n.arctanh(this))}bitwise_not(){return s(n.bitwise_not(this))}invert(){return s(n.invert(this))}logical_not(){return s(n.logical_not(this))}isfinite(){return s(n.isfinite(this))}isinf(){return s(n.isinf(this))}isnan(){return s(n.isnan(this))}isnat(){return s(n.isnat(this))}signbit(){return s(n.signbit(this))}spacing(){return s(n.spacing(this))}cbrt(){return s(n.cbrt(this))}fabs(){return s(n.fabs(this))}square(){return s(n.square(this))}conj(){return s(n.conj(this))}flatten(){return s(n.flatten(this))}argwhere(){return s(n.argwhere(this))}add(r){return s(n.add(this,r))}subtract(r){return s(n.subtract(this,r))}multiply(r){return s(n.multiply(this,r))}divide(r){return s(n.divide(this,r))}mod(r){return s(n.mod(this,r))}floor_divide(r){return s(n.floor_divide(this,r))}power(r){return s(n.power(this,r))}logaddexp(r){return s(n.logaddexp(this,r))}logaddexp2(r){return s(n.logaddexp2(this,r))}arctan2(r){return s(n.arctan2(this,r))}hypot(r){return s(n.hypot(this,r))}greater(r){return s(n.greater(this,r))}greater_equal(r){return s(n.greater_equal(this,r))}less(r){return s(n.less(this,r))}less_equal(r){return s(n.less_equal(this,r))}equal(r){return s(n.equal(this,r))}not_equal(r){return s(n.not_equal(this,r))}bitwise_and(r){return s(n.bitwise_and(this,r))}bitwise_or(r){return s(n.bitwise_or(this,r))}bitwise_xor(r){return s(n.bitwise_xor(this,r))}left_shift(r){return s(n.left_shift(this,r))}right_shift(r){return s(n.right_shift(this,r))}logical_and(r){return s(n.logical_and(this,r))}logical_or(r){return s(n.logical_or(this,r))}logical_xor(r){return s(n.logical_xor(this,r))}copysign(r){return s(n.copysign(this,r))}nextafter(r){return s(n.nextafter(this,r))}remainder(r){return s(n.remainder(this,r))}heaviside(r){return s(n.heaviside(this,r))}matmul(r){return s(n.matmul(this,r))}outer(r){return s(n.outer(this,r))}sum(r,e=!1){const t=n.sum(this,r,e);return t instanceof y?s(t):t}mean(r,e=!1){const t=n.mean(this,r,e);return t instanceof y?s(t):t}prod(r,e=!1){const t=n.prod(this,r,e);return t instanceof y?s(t):t}max(r,e=!1){const t=n.max(this,r,e);return t instanceof y?s(t):t}min(r,e=!1){const t=n.min(this,r,e);return t instanceof y?s(t):t}ptp(r,e=!1){const t=n.ptp(this,r,e);return t instanceof y?s(t):t}nansum(r,e=!1){const t=n.nansum(this,r,e);return t instanceof y?s(t):t}nanprod(r,e=!1){const t=n.nanprod(this,r,e);return t instanceof y?s(t):t}nanmean(r,e=!1){const t=n.nanmean(this,r,e);return t instanceof y?s(t):t}nanmin(r,e=!1){const t=n.nanmin(this,r,e);return t instanceof y?s(t):t}nanmax(r,e=!1){const t=n.nanmax(this,r,e);return t instanceof y?s(t):t}argmin(r){const e=n.argmin(this,r);return e instanceof y?s(e):e}argmax(r){const e=n.argmax(this,r);return e instanceof y?s(e):e}nanargmin(r){const e=n.nanargmin(this,r);return e instanceof y?s(e):e}nanargmax(r){const e=n.nanargmax(this,r);return e instanceof y?s(e):e}var(r,e=0,t=!1){const a=n.variance(this,r,e,t);return a instanceof y?s(a):a}std(r,e=0,t=!1){const a=n.std(this,r,e,t);return a instanceof y?s(a):a}nanvar(r,e=0,t=!1){const a=n.nanvar(this,r,e,t);return a instanceof y?s(a):a}nanstd(r,e=0,t=!1){const a=n.nanstd(this,r,e,t);return a instanceof y?s(a):a}all(r,e=!1){const t=n.all(this,r,e);return t instanceof y?s(t):t}any(r,e=!1){const t=n.any(this,r,e);return t instanceof y?s(t):t}median(r,e=!1){const t=n.median(this,r,e);return t instanceof y?s(t):t}nanmedian(r,e=!1){const t=n.nanmedian(this,r,e);return t instanceof y?s(t):t}percentile(r,e,t=!1){const a=n.percentile(this,r,e,t);return a instanceof y?s(a):a}quantile(r,e,t=!1){const a=n.quantile(this,r,e,t);return a instanceof y?s(a):a}nanquantile(r,e,t=!1){const a=n.nanquantile(this,r,e,t);return a instanceof y?s(a):a}nanpercentile(r,e,t=!1){const a=n.nanpercentile(this,r,e,t);return a instanceof y?s(a):a}cumsum(r){return s(n.cumsum(this,r))}cumprod(r){return s(n.cumprod(this,r))}nancumsum(r){return s(n.nancumsum(this,r))}nancumprod(r){return s(n.nancumprod(this,r))}sort(r=-1){return s(n.sort(this,r))}argsort(r=-1){return s(n.argsort(this,r))}partition(r,e=-1){return s(n.partition(this,r,e))}argpartition(r,e=-1){return s(n.argpartition(this,r,e))}diagonal(r=0,e=0,t=1){return s(n.diagonal(this,r,e,t))}resize(r){return s(n.resize(this,r))}diff(r=1,e=-1){return s(n.diff(this,r,e))}take(r,e){return s(n.take(this,r,e))}repeat(r,e){return s(n.repeat(this,r,e))}transpose(r){return s(n.transpose(this,r))}squeeze(r){return s(n.squeeze(this,r))}expand_dims(r){return s(n.expand_dims(this,r))}swapaxes(r,e){return s(n.swapaxes(this,r,e))}moveaxis(r,e){return s(n.moveaxis(this,r,e))}nonzero(){return n.nonzero(this).map(s)}}function q(...f){let r=[],e="xy";for(const m of f)m instanceof c?r.push(m):typeof m=="object"&&"indexing"in m&&(e=m.indexing||"xy");if(r.length===0)return[];if(r.length===1)return[r[0].copy()];const t=r.map(m=>m.size);e==="xy"&&r.length>=2&&(r=[r[1],r[0],...r.slice(2)],[t[0],t[1]]=[t[1],t[0]]);const a=t,i=a.length,o=[];for(let m=0;m<r.length;m++){const u=r[m],b=u.size,l=new Array(i).fill(1);l[m]=b;const h=u.reshape(...l),D=n.broadcast_to(h,a),d=c.fromStorage(D.storage.copy());o.push(d)}return e==="xy"&&o.length>=2&&([o[0],o[1]]=[o[1],o[0]]),o}export{c as NDArray,q as meshgrid};
1
+ import{parseSlice as z,normalizeSlice as v}from"../common/slicing";import{getTypedArrayConstructor as x,getDTypeSize as p,isBigIntDType as A,isComplexDType as E}from"../common/dtype";import{Complex as g}from"../common/complex";import{ArrayStorage as N}from"../common/storage";import{NDArrayCore as y}from"../common/ndarray-core";import*as n from"../core";const s=f=>{if(f instanceof c)return f;const r=f.base?s(f.base):void 0;return c.fromStorage(f.storage,r)};class c extends y{constructor(r,e){super(r,e),this._base=e}static fromStorage(r,e){return new c(r,e)}get base(){return this._base??null}get T(){return this.transpose()}get itemsize(){return p(this._storage.dtype)}get nbytes(){return this.size*this.itemsize}fill(r){const e=this._storage.dtype,t=this.size;if(A(e)){const a=typeof r=="bigint"?r:BigInt(Math.round(Number(r)));for(let i=0;i<t;i++)this._storage.iset(i,a)}else if(e==="bool"){const a=r?1:0;for(let i=0;i<t;i++)this._storage.iset(i,a)}else{const a=Number(r);for(let i=0;i<t;i++)this._storage.iset(i,a)}}*[Symbol.iterator](){if(this.ndim===0)yield this._storage.iget(0);else if(this.ndim===1)for(let r=0;r<this.shape[0];r++)yield this._storage.iget(r);else for(let r=0;r<this.shape[0];r++)yield this.slice(String(r))}get(r){if(r.length!==this.ndim)throw new Error(`Index has ${r.length} dimensions, but array has ${this.ndim} dimensions`);const e=r.map((t,a)=>{let i=t;if(i<0&&(i=this.shape[a]+i),i<0||i>=this.shape[a])throw new Error(`Index ${t} is out of bounds for axis ${a} with size ${this.shape[a]}`);return i});return this._storage.get(...e)}set(r,e){if(r.length!==this.ndim)throw new Error(`Index has ${r.length} dimensions, but array has ${this.ndim} dimensions`);const t=r.map((i,o)=>{let m=i;if(m<0&&(m=this.shape[o]+m),m<0||m>=this.shape[o])throw new Error(`Index ${i} is out of bounds for axis ${o} with size ${this.shape[o]}`);return m}),a=this.dtype;if(E(a))this._storage.set(t,e);else if(A(a)){const i=e instanceof g?e.re:Number(e),o=typeof e=="bigint"?e:BigInt(Math.round(i));this._storage.set(t,o)}else if(a==="bool"){const o=(e instanceof g?e.re:Number(e))?1:0;this._storage.set(t,o)}else{const i=e instanceof g?e.re:Number(e);this._storage.set(t,i)}}copy(){return new c(this._storage.copy())}astype(r,e=!0){const t=this.dtype;if(t===r&&!e)return this;if(t===r&&e)return this.copy();const a=Array.from(this.shape),i=this.size,o=x(r);if(!o)throw new Error(`Cannot convert to dtype ${r}`);const m=new o(i),u=this.data;if(A(t)&&!A(r)){const l=u;if(r==="bool")for(let h=0;h<i;h++)m[h]=l[h]!==BigInt(0)?1:0;else for(let h=0;h<i;h++)m[h]=Number(l[h])}else if(!A(t)&&A(r)){const l=u;for(let h=0;h<i;h++)m[h]=BigInt(Math.round(Number(l[h])))}else if(r==="bool"){const l=u;for(let h=0;h<i;h++)m[h]=l[h]!==0?1:0}else if(t==="bool"&&!A(r)){const l=u;for(let h=0;h<i;h++)m[h]=l[h]}else if(!A(t)&&!A(r)){const l=u;for(let h=0;h<i;h++)m[h]=l[h]}else{const l=u;for(let h=0;h<i;h++)m[h]=l[h]}const b=N.fromData(m,a,r);return new c(b)}slice(...r){if(r.length===0)return this;if(r.length>this.ndim)throw new Error(`Too many indices for array: array is ${this.ndim}-dimensional, but ${r.length} were indexed`);const e=r.map((u,b)=>{const l=z(u);return v(l,this.shape[b])});for(;e.length<this.ndim;)e.push({start:0,stop:this.shape[e.length],step:1,isIndex:!1});const t=[],a=[];let i=this._storage.offset;for(let u=0;u<e.length;u++){const b=e[u],l=this._storage.strides[u];if(i+=b.start*l,!b.isIndex){let h;b.step>0?h=Math.max(0,Math.ceil((b.stop-b.start)/b.step)):h=Math.max(0,Math.ceil((b.start-b.stop)/Math.abs(b.step))),t.push(h),a.push(l*b.step)}}const o=N.fromData(this._storage.data,t,this._storage.dtype,a,i),m=this._base??this;return new c(o,m)}row(r){if(this.ndim<2)throw new Error("row() requires at least 2 dimensions");return this.slice(String(r),":")}col(r){if(this.ndim<2)throw new Error("col() requires at least 2 dimensions");return this.slice(":",String(r))}rows(r,e){if(this.ndim<2)throw new Error("rows() requires at least 2 dimensions");return this.slice(`${r}:${e}`,":")}cols(r,e){if(this.ndim<2)throw new Error("cols() requires at least 2 dimensions");return this.slice(":",`${r}:${e}`)}reshape(...r){const e=r.length===1&&Array.isArray(r[0])?r[0]:r,t=n.reshape(this,e).storage,i=t.data===this.data?this._base??this:void 0;return c.fromStorage(t,i)}ravel(){const r=n.ravel(this).storage,t=r.data===this.data?this._base??this:void 0;return c.fromStorage(r,t)}put(r,e){const t=e instanceof c?e._storage:e;n.put(this,r,t)}compress(r,e){const t=r instanceof c?r:c.fromStorage(N.fromData(new Uint8Array(r.map(a=>a?1:0)),[r.length],"bool"));return s(n.compress(t,this,e))}choose(r){return s(n.choose(this,r))}clip(r,e){return s(n.clip(this,r,e))}iindex(r,e=0){let t;if(r instanceof c){t=[];for(let a=0;a<r.size;a++){const i=r.storage.iget(a),o=typeof i=="bigint"?Number(i):i instanceof g?i.re:i;t.push(o)}}else Array.isArray(r)&&r.length>0&&Array.isArray(r[0])?t=r.flat():t=r;return this.take(t,e)}bindex(r,e){return s(n.compress(r,this,e))}toString(){return n.array_str(this)}toArray(){if(this.ndim===0)return this._storage.iget(0);const r=this.shape,e=r.length,t=(a,i)=>{if(i===e)return this._storage.get(...a);const o=[];for(let m=0;m<r[i];m++)a[i]=m,o.push(t(a,i+1));return o};return t(new Array(e),0)}tolist(){return this.toArray()}tobytes(){if(this._storage.isCContiguous){const t=this._storage.data,a=t.BYTES_PER_ELEMENT,i=this._storage.offset*a,o=this.size*a;return t.buffer.slice(i,i+o)}const e=this.copy()._storage.data;return e.buffer.slice(0,this.size*e.BYTES_PER_ELEMENT)}item(...r){if(r.length===0){if(this.size!==1)throw new Error("can only convert an array of size 1 to a Python scalar");return this._storage.iget(0)}if(r.length===1){const e=r[0];if(e<0||e>=this.size)throw new Error(`index ${e} is out of bounds for size ${this.size}`);return this._storage.iget(e)}return this.get(r)}byteswap(r=!1){const e=r?this:this.copy(),t=e._storage.data,a=t.BYTES_PER_ELEMENT;if(a===1)return e;const i=t.buffer,o=new DataView(i);for(let m=0;m<t.length;m++){const u=m*a;if(a===2){const b=o.getUint8(u),l=o.getUint8(u+1);o.setUint8(u,l),o.setUint8(u+1,b)}else if(a===4){const b=o.getUint8(u),l=o.getUint8(u+1),h=o.getUint8(u+2),D=o.getUint8(u+3);o.setUint8(u,D),o.setUint8(u+1,h),o.setUint8(u+2,l),o.setUint8(u+3,b)}else if(a===8){const b=o.getUint8(u),l=o.getUint8(u+1),h=o.getUint8(u+2),D=o.getUint8(u+3),d=o.getUint8(u+4),w=o.getUint8(u+5),_=o.getUint8(u+6),U=o.getUint8(u+7);o.setUint8(u,U),o.setUint8(u+1,_),o.setUint8(u+2,w),o.setUint8(u+3,d),o.setUint8(u+4,D),o.setUint8(u+5,h),o.setUint8(u+6,l),o.setUint8(u+7,b)}}return e}view(r){if(!r||r===this.dtype)return c.fromStorage(this._storage,this._base??this);const e=p(this.dtype),t=p(r);if(e!==t)throw new Error("When changing to a larger dtype, its size must be a divisor of the total size in bytes of the last axis of the array.");const a=x(r);if(!a)throw new Error(`Unsupported dtype: ${r}`);const i=this._storage.data,o=i.byteOffset+this._storage.offset*e,m=new a(i.buffer,o,this.size),u=N.fromData(m,[...this.shape],r,[...this._storage.strides],0);return c.fromStorage(u,this._base??this)}tofile(r,e="",t=""){throw new Error('tofile() requires file system access. Use the node module: import { save } from "numpy-ts/node"')}round(r=0){return this.around(r)}conjugate(){return this.conj()}around(r=0){return s(n.around(this,r))}allclose(r,e=1e-5,t=1e-8){return n.allclose(this,r,e,t)}isclose(r,e=1e-5,t=1e-8){return s(n.isclose(this,r,e,t))}average(r,e){const t=n.average(this,e,r);return t instanceof y?s(t):t}dot(r){const e=n.dot(this,r);return e instanceof y?s(e):e}trace(){return n.trace(this)}inner(r){const e=n.inner(this,r);return e instanceof y?s(e):e}tensordot(r,e=2){const t=n.tensordot(this,r,e);return t instanceof y?s(t):t}divmod(r){const e=n.divmod(this,r);return[s(e[0]),s(e[1])]}searchsorted(r,e="left"){return s(n.searchsorted(this,r,e))}sqrt(){return s(n.sqrt(this))}exp(){return s(n.exp(this))}exp2(){return s(n.exp2(this))}expm1(){return s(n.expm1(this))}log(){return s(n.log(this))}log2(){return s(n.log2(this))}log10(){return s(n.log10(this))}log1p(){return s(n.log1p(this))}absolute(){return s(n.absolute(this))}negative(){return s(n.negative(this))}sign(){return s(n.sign(this))}positive(){return s(n.positive(this))}reciprocal(){return s(n.reciprocal(this))}ceil(){return s(n.ceil(this))}fix(){return s(n.fix(this))}floor(){return s(n.floor(this))}rint(){return s(n.rint(this))}trunc(){return s(n.trunc(this))}sin(){return s(n.sin(this))}cos(){return s(n.cos(this))}tan(){return s(n.tan(this))}arcsin(){return s(n.arcsin(this))}arccos(){return s(n.arccos(this))}arctan(){return s(n.arctan(this))}degrees(){return s(n.degrees(this))}radians(){return s(n.radians(this))}sinh(){return s(n.sinh(this))}cosh(){return s(n.cosh(this))}tanh(){return s(n.tanh(this))}arcsinh(){return s(n.arcsinh(this))}arccosh(){return s(n.arccosh(this))}arctanh(){return s(n.arctanh(this))}bitwise_not(){return s(n.bitwise_not(this))}invert(){return s(n.invert(this))}logical_not(){return s(n.logical_not(this))}isfinite(){return s(n.isfinite(this))}isinf(){return s(n.isinf(this))}isnan(){return s(n.isnan(this))}isnat(){return s(n.isnat(this))}signbit(){return s(n.signbit(this))}spacing(){return s(n.spacing(this))}cbrt(){return s(n.cbrt(this))}fabs(){return s(n.fabs(this))}square(){return s(n.square(this))}conj(){return s(n.conj(this))}flatten(){return s(n.flatten(this))}argwhere(){return s(n.argwhere(this))}add(r){return s(n.add(this,r))}subtract(r){return s(n.subtract(this,r))}multiply(r){return s(n.multiply(this,r))}divide(r){return s(n.divide(this,r))}mod(r){return s(n.mod(this,r))}floor_divide(r){return s(n.floor_divide(this,r))}power(r){return s(n.power(this,r))}logaddexp(r){return s(n.logaddexp(this,r))}logaddexp2(r){return s(n.logaddexp2(this,r))}arctan2(r){return s(n.arctan2(this,r))}hypot(r){return s(n.hypot(this,r))}greater(r){return s(n.greater(this,r))}greater_equal(r){return s(n.greater_equal(this,r))}less(r){return s(n.less(this,r))}less_equal(r){return s(n.less_equal(this,r))}equal(r){return s(n.equal(this,r))}not_equal(r){return s(n.not_equal(this,r))}bitwise_and(r){return s(n.bitwise_and(this,r))}bitwise_or(r){return s(n.bitwise_or(this,r))}bitwise_xor(r){return s(n.bitwise_xor(this,r))}left_shift(r){return s(n.left_shift(this,r))}right_shift(r){return s(n.right_shift(this,r))}logical_and(r){return s(n.logical_and(this,r))}logical_or(r){return s(n.logical_or(this,r))}logical_xor(r){return s(n.logical_xor(this,r))}copysign(r){return s(n.copysign(this,r))}nextafter(r){return s(n.nextafter(this,r))}remainder(r){return s(n.remainder(this,r))}heaviside(r){return s(n.heaviside(this,r))}matmul(r){return s(n.matmul(this,r))}outer(r){return s(n.outer(this,r))}sum(r,e=!1){const t=n.sum(this,r,e);return t instanceof y?s(t):t}mean(r,e=!1){const t=n.mean(this,r,e);return t instanceof y?s(t):t}prod(r,e=!1){const t=n.prod(this,r,e);return t instanceof y?s(t):t}max(r,e=!1){const t=n.max(this,r,e);return t instanceof y?s(t):t}min(r,e=!1){const t=n.min(this,r,e);return t instanceof y?s(t):t}ptp(r,e=!1){const t=n.ptp(this,r,e);return t instanceof y?s(t):t}nansum(r,e=!1){const t=n.nansum(this,r,e);return t instanceof y?s(t):t}nanprod(r,e=!1){const t=n.nanprod(this,r,e);return t instanceof y?s(t):t}nanmean(r,e=!1){const t=n.nanmean(this,r,e);return t instanceof y?s(t):t}nanmin(r,e=!1){const t=n.nanmin(this,r,e);return t instanceof y?s(t):t}nanmax(r,e=!1){const t=n.nanmax(this,r,e);return t instanceof y?s(t):t}argmin(r){const e=n.argmin(this,r);return e instanceof y?s(e):e}argmax(r){const e=n.argmax(this,r);return e instanceof y?s(e):e}nanargmin(r){const e=n.nanargmin(this,r);return e instanceof y?s(e):e}nanargmax(r){const e=n.nanargmax(this,r);return e instanceof y?s(e):e}var(r,e=0,t=!1){const a=n.variance(this,r,e,t);return a instanceof y?s(a):a}std(r,e=0,t=!1){const a=n.std(this,r,e,t);return a instanceof y?s(a):a}nanvar(r,e=0,t=!1){const a=n.nanvar(this,r,e,t);return a instanceof y?s(a):a}nanstd(r,e=0,t=!1){const a=n.nanstd(this,r,e,t);return a instanceof y?s(a):a}all(r,e=!1){const t=n.all(this,r,e);return t instanceof y?s(t):t}any(r,e=!1){const t=n.any(this,r,e);return t instanceof y?s(t):t}median(r,e=!1){const t=n.median(this,r,e);return t instanceof y?s(t):t}nanmedian(r,e=!1){const t=n.nanmedian(this,r,e);return t instanceof y?s(t):t}percentile(r,e,t=!1){const a=n.percentile(this,r,e,t);return a instanceof y?s(a):a}quantile(r,e,t=!1){const a=n.quantile(this,r,e,t);return a instanceof y?s(a):a}nanquantile(r,e,t=!1){const a=n.nanquantile(this,r,e,t);return a instanceof y?s(a):a}nanpercentile(r,e,t=!1){const a=n.nanpercentile(this,r,e,t);return a instanceof y?s(a):a}cumsum(r){return s(n.cumsum(this,r))}cumprod(r){return s(n.cumprod(this,r))}nancumsum(r){return s(n.nancumsum(this,r))}nancumprod(r){return s(n.nancumprod(this,r))}sort(r=-1){return s(n.sort(this,r))}argsort(r=-1){return s(n.argsort(this,r))}partition(r,e=-1){return s(n.partition(this,r,e))}argpartition(r,e=-1){return s(n.argpartition(this,r,e))}diagonal(r=0,e=0,t=1){return s(n.diagonal(this,r,e,t))}resize(r){return s(n.resize(this,r))}diff(r=1,e=-1){return s(n.diff(this,r,e))}take(r,e){return s(n.take(this,r,e))}repeat(r,e){return s(n.repeat(this,r,e))}transpose(r){return s(n.transpose(this,r))}squeeze(r){return s(n.squeeze(this,r))}expand_dims(r){return s(n.expand_dims(this,r))}swapaxes(r,e){return s(n.swapaxes(this,r,e))}moveaxis(r,e){return s(n.moveaxis(this,r,e))}nonzero(){return n.nonzero(this).map(s)}}function q(...f){let r=[],e="xy";for(const m of f)m instanceof c?r.push(m):typeof m=="object"&&"indexing"in m&&(e=m.indexing||"xy");if(r.length===0)return[];if(r.length===1)return[r[0].copy()];const t=r.map(m=>m.size);e==="xy"&&r.length>=2&&(r=[r[1],r[0],...r.slice(2)],[t[0],t[1]]=[t[1],t[0]]);const a=t,i=a.length,o=[];for(let m=0;m<r.length;m++){const u=r[m],b=u.size,l=new Array(i).fill(1);l[m]=b;const h=u.reshape(...l),D=n.broadcast_to(h,a),d=c.fromStorage(D.storage.copy());o.push(d)}return e==="xy"&&o.length>=2&&([o[0],o[1]]=[o[1],o[0]]),o}export{c as NDArray,q as meshgrid};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{Complex as J}from"./common/complex";import{NDArray as Q}from"./full";import{NDArrayCore as X}from"./common/ndarray-core";import{zeros as $,ones as rr,empty as er,full as ar,array as nr,arange as tr,linspace as or,logspace as sr,geomspace as mr,eye as ir,identity as ur,asarray as pr,zeros_like as fr,ones_like as br,empty_like as lr,full_like as dr,copy as cr,asanyarray as yr,asarray_chkfinite as _r,ascontiguousarray as gr,asfortranarray as xr,require as hr,diag as Nr,diagflat as Ar,frombuffer as wr,fromfile as zr,fromfunction as Sr,fromiter as vr,fromstring as Dr,meshgrid as kr,tri as Cr,tril as Tr,triu as Or,vander as Ir}from"./full";import{add as Pr,subtract as Rr,multiply as Er,divide as Mr,true_divide as jr,floor_divide as Ur,mod as Hr,sqrt as Lr,power as Br,exp as Vr,exp2 as Gr,expm1 as Yr,log as Fr,log2 as Jr,log10 as Kr,log1p as Qr,logaddexp as Wr,logaddexp2 as Xr,absolute as Zr,negative as $r,sign as re,positive as ee,reciprocal as ae,cbrt as ne,fabs as te,divmod as oe,square as se,remainder as me,heaviside as ie,float_power as ue,fmod as pe,frexp as fe,gcd as be,lcm as le,ldexp as de,modf as ce,clip as ye,maximum as _e,minimum as ge,fmax as xe,fmin as he,nan_to_num as Ne,interp as Ae,unwrap as we,sinc as ze,i0 as Se}from"./full";import{power as De,absolute as ke}from"./full";import{sin as Te,cos as Oe,tan as Ie,arcsin as qe,arccos as Pe,arctan as Re,arctan2 as Ee,hypot as Me,degrees as je,radians as Ue,deg2rad as He,rad2deg as Le,sinh as Be,cosh as Ve,tanh as Ge,arcsinh as Ye,arccosh as Fe,arctanh as Je}from"./full";import{arcsin as Qe,arccos as We,arctan as Xe,arctan2 as Ze,arcsinh as $e,arccosh as ra,arctanh as ea}from"./full";import{dot as na,trace as ta,diagonal as oa,kron as sa,transpose as ma,inner as ia,outer as ua,tensordot as pa,einsum as fa,einsum_path as ba,vdot as la,vecdot as da,matrix_transpose as ca,permute_dims as ya,matvec as _a,vecmat as ga,cross as xa,matmul as ha,linalg as Na}from"./full";import{reshape as wa,flatten as za,ravel as Sa,squeeze as va,expand_dims as Da,swapaxes as ka,moveaxis as Ca,rollaxis as Ta,concatenate as Oa,stack as Ia,vstack as qa,hstack as Pa,dstack as Ra,column_stack as Ea,row_stack as Ma,block as ja,split as Ua,array_split as Ha,vsplit as La,hsplit as Ba,dsplit as Va,unstack as Ga,tile as Ya,repeat as Fa,flip as Ja,fliplr as Ka,flipud as Qa,rot90 as Wa,roll as Xa,resize as Za,atleast_1d as $a,atleast_2d as rn,atleast_3d as en,append as an,delete_ as nn,delete_ as tn,insert as on,pad as sn}from"./full";import{concatenate as un}from"./full";import{sum as fn,mean as bn,prod as ln,amax as dn,amin as cn,ptp as yn,argmin as _n,argmax as gn,std as xn,variance as hn,var_ as Nn,median as An,percentile as wn,quantile as zn,average as Sn,all as vn,any as Dn,cumsum as kn,cumprod as Cn,nansum as Tn,nanprod as On,nanmean as In,nanvar as qn,nanstd as Pn,nanmin as Rn,nanmax as En,nanargmin as Mn,nanargmax as jn,nancumsum as Un,nancumprod as Hn,nanmedian as Ln,nanquantile as Bn,nanpercentile as Vn}from"./full";import{amax as Yn,amin as Fn,cumsum as Jn,cumprod as Kn}from"./full";import{logical_and as Wn,logical_or as Xn,logical_not as Zn,logical_xor as $n,isfinite as rt,isinf as et,isnan as at,isnat as nt,isneginf as tt,isposinf as ot,iscomplex as st,iscomplexobj as mt,isreal as it,isrealobj as ut,real_if_close as pt,isfortran as ft,isscalar as bt,iterable as lt,isdtype as dt,promote_types as ct,copysign as yt,signbit as _t,nextafter as gt,spacing as xt,greater as ht,greater_equal as Nt,less as At,less_equal as wt,equal as zt,not_equal as St,isclose as vt,allclose as Dt}from"./full";import{sort as Ct,argsort as Tt,lexsort as Ot,partition as It,argpartition as qt,sort_complex as Pt,nonzero as Rt,argwhere as Et,flatnonzero as Mt,where as jt,searchsorted as Ut,extract as Ht,count_nonzero as Lt}from"./full";import{bitwise_and as Vt,bitwise_or as Gt,bitwise_xor as Yt,bitwise_not as Ft,invert as Jt,left_shift as Kt,right_shift as Qt,packbits as Wt,unpackbits as Xt,bitwise_count as Zt}from"./full";import{bitwise_not as ro,left_shift as eo,right_shift as ao}from"./full";import{around as to,round_ as oo,ceil as so,fix as mo,floor as io,rint as uo,trunc as po}from"./full";import{around as bo}from"./full";import{unique as co,in1d as yo,intersect1d as _o,isin as go,setdiff1d as xo,setxor1d as ho,union1d as No,trim_zeros as Ao,unique_all as wo,unique_counts as zo,unique_inverse as So,unique_values as vo}from"./full";import{bincount as ko,digitize as Co,histogram as To,histogram2d as Oo,histogramdd as Io,correlate as qo,convolve as Po,cov as Ro,corrcoef as Eo,histogram_bin_edges as Mo,trapezoid as jo}from"./full";import{diff as Ho,ediff1d as Lo,gradient as Bo}from"./full";import{real as Go,imag as Yo,conj as Fo,angle as Jo}from"./full";import{conj as Qo}from"./full";import{broadcast_to as Xo,broadcast_arrays as Zo,broadcast_shapes as $o,take as rs,put as es,iindex as as,bindex as ns,copyto as ts,choose as os,array_equal as ss,array_equiv as ms,take_along_axis as is,put_along_axis as us,putmask as ps,compress as fs,select as bs,place as ls,fill_diagonal as ds,diag_indices as cs,diag_indices_from as ys,tril_indices as _s,tril_indices_from as gs,triu_indices as xs,triu_indices_from as hs,mask_indices as Ns,indices as As,ix_ as ws,ravel_multi_index as zs,unravel_index as Ss,fill as vs,item as Ds,tolist as ks,tobytes as Cs,byteswap as Ts,view as Os,tofile as Is}from"./full";import{apply_along_axis as Ps,apply_over_axes as Rs,may_share_memory as Es,shares_memory as Ms,ndim as js,shape as Us,size as Hs,geterr as Ls,seterr as Bs}from"./full";import{array2string as Gs,array_repr as Ys,array_str as Fs,base_repr as Js,binary_repr as Ks,format_float_positional as Qs,format_float_scientific as Ws,get_printoptions as Xs,set_printoptions as Zs,printoptions as $s}from"./full";import{can_cast as em,common_type as am,result_type as nm,min_scalar_type as tm,issubdtype as om,typename as sm,mintypecode as mm}from"./full";import{poly as um,polyadd as pm,polyder as fm,polydiv as bm,polyfit as lm,polyint as dm,polymul as cm,polysub as ym,polyval as _m,roots as gm}from"./full";import{UnsupportedDTypeError as hm,InvalidNpyError as Nm,SUPPORTED_DTYPES as Am,DTYPE_TO_DESCR as wm}from"./io/npy/format";import{serializeNpy as Sm}from"./io/npy/serializer";import{serializeNpz as Dm,serializeNpzSync as km}from"./io/npz/serializer";import{serializeTxt as Tm}from"./io/txt/serializer";import{parseNpy as b,parseNpyHeader as l,parseNpyData as d}from"./io/npy/parser";import{parseNpz as c,parseNpzSync as y,loadNpz as _,loadNpzSync as g}from"./io/npz/parser";import{parseTxt as x,genfromtxt as h,fromregex as N}from"./io/txt/parser";function p(r){return s.fromStorage(r.storage)}function v(r){return p(b(r))}const D=l;function k(r,e){return p(d(r,e))}async function C(r,e={}){const a=await c(r,e),t=new Map;for(const[u,f]of a.arrays)t.set(u,p(f));return{arrays:t,skipped:a.skipped,errors:a.errors}}function T(r,e={}){const a=y(r,e),t=new Map;for(const[u,f]of a.arrays)t.set(u,p(f));return{arrays:t,skipped:a.skipped,errors:a.errors}}async function O(r,e={}){const a=await _(r,e),t={};for(const[u,f]of Object.entries(a))t[u]=p(f);return t}function I(r,e={}){const a=g(r,e),t={};for(const[u,f]of Object.entries(a))t[u]=p(f);return t}function q(r,e={}){return p(x(r,e))}function P(r,e={}){return p(h(r,e))}function R(r,e,a="float64"){return p(N(r,e,a))}import*as n from"./common/ops/random";import{NDArray as s}from"./full";function o(r){return r&&typeof r=="object"&&"_data"in r&&"_shape"in r?s.fromStorage(r):r}const L={seed:n.seed,get_state:n.get_state,set_state:n.set_state,get_bit_generator:n.get_bit_generator,set_bit_generator:n.set_bit_generator,default_rng:n.default_rng,Generator:n.Generator,random:r=>o(n.random(r)),rand:(...r)=>o(n.rand(...r)),randn:(...r)=>o(n.randn(...r)),randint:(r,e,a,t)=>o(n.randint(r,e,a,t)),random_sample:r=>o(n.random_sample(r)),ranf:r=>o(n.ranf(r)),sample:r=>o(n.sample(r)),random_integers:(r,e,a)=>o(n.random_integers(r,e,a)),bytes:n.bytes,uniform:(r,e,a)=>o(n.uniform(r,e,a)),normal:(r,e,a)=>o(n.normal(r,e,a)),standard_normal:r=>o(n.standard_normal(r)),exponential:(r,e)=>o(n.exponential(r,e)),standard_exponential:r=>o(n.standard_exponential(r)),gamma:(r,e,a)=>o(n.gamma(r,e,a)),standard_gamma:(r,e)=>o(n.standard_gamma(r,e)),beta:(r,e,a)=>o(n.beta(r,e,a)),chisquare:(r,e)=>o(n.chisquare(r,e)),noncentral_chisquare:(r,e,a)=>o(n.noncentral_chisquare(r,e,a)),f:(r,e,a)=>o(n.f(r,e,a)),noncentral_f:(r,e,a,t)=>o(n.noncentral_f(r,e,a,t)),standard_cauchy:r=>o(n.standard_cauchy(r)),standard_t:(r,e)=>o(n.standard_t(r,e)),laplace:(r,e,a)=>o(n.laplace(r,e,a)),logistic:(r,e,a)=>o(n.logistic(r,e,a)),lognormal:(r,e,a)=>o(n.lognormal(r,e,a)),gumbel:(r,e,a)=>o(n.gumbel(r,e,a)),pareto:(r,e)=>o(n.pareto(r,e)),power:(r,e)=>o(n.power(r,e)),rayleigh:(r,e)=>o(n.rayleigh(r,e)),triangular:(r,e,a,t)=>o(n.triangular(r,e,a,t)),wald:(r,e,a)=>o(n.wald(r,e,a)),weibull:(r,e)=>o(n.weibull(r,e)),poisson:(r,e)=>o(n.poisson(r,e)),binomial:(r,e,a)=>o(n.binomial(r,e,a)),geometric:(r,e)=>o(n.geometric(r,e)),hypergeometric:(r,e,a,t)=>o(n.hypergeometric(r,e,a,t)),logseries:(r,e)=>o(n.logseries(r,e)),negative_binomial:(r,e,a)=>o(n.negative_binomial(r,e,a)),zipf:(r,e)=>o(n.zipf(r,e)),multinomial:(r,e,a)=>o(n.multinomial(r,e,a)),multivariate_normal:(r,e,a,t,u)=>o(n.multivariate_normal(r,e,a,t,u)),dirichlet:(r,e)=>o(n.dirichlet(r,e)),vonmises:(r,e,a)=>o(n.vonmises(r,e,a)),choice:(r,e,a,t)=>o(n.choice(r,e,a,t)),permutation:r=>o(n.permutation(r)),shuffle:n.shuffle};import*as m from"./common/ops/fft";import{NDArrayCore as A}from"./common/ndarray-core";function i(r){return r instanceof s||r instanceof A?r.storage:r}const V={fft:(r,e,a,t)=>s.fromStorage(m.fft(i(r),e,a,t)),ifft:(r,e,a,t)=>s.fromStorage(m.ifft(i(r),e,a,t)),fft2:(r,e,a,t)=>s.fromStorage(m.fft2(i(r),e,a,t)),ifft2:(r,e,a,t)=>s.fromStorage(m.ifft2(i(r),e,a,t)),fftn:(r,e,a,t)=>s.fromStorage(m.fftn(i(r),e,a,t)),ifftn:(r,e,a,t)=>s.fromStorage(m.ifftn(i(r),e,a,t)),rfft:(r,e,a,t)=>s.fromStorage(m.rfft(i(r),e,a,t)),irfft:(r,e,a,t)=>s.fromStorage(m.irfft(i(r),e,a,t)),rfft2:(r,e,a,t)=>s.fromStorage(m.rfft2(i(r),e,a,t)),irfft2:(r,e,a,t)=>s.fromStorage(m.irfft2(i(r),e,a,t)),rfftn:(r,e,a,t)=>s.fromStorage(m.rfftn(i(r),e,a,t)),irfftn:(r,e,a,t)=>s.fromStorage(m.irfftn(i(r),e,a,t)),hfft:(r,e,a,t)=>s.fromStorage(m.hfft(i(r),e,a,t)),ihfft:(r,e,a,t)=>s.fromStorage(m.ihfft(i(r),e,a,t)),fftfreq:(r,e)=>s.fromStorage(m.fftfreq(r,e)),rfftfreq:(r,e)=>s.fromStorage(m.rfftfreq(r,e)),fftshift:(r,e)=>s.fromStorage(m.fftshift(i(r),e)),ifftshift:(r,e)=>s.fromStorage(m.ifftshift(i(r),e))},G="0.13.0";export{J as Complex,wm as DTYPE_TO_DESCR,Nm as InvalidNpyError,Q as NDArray,X as NDArrayCore,Am as SUPPORTED_DTYPES,hm as UnsupportedDTypeError,G as __version__,ke as abs,Zr as absolute,We as acos,ra as acosh,Pr as add,vn as all,Dt as allclose,dn as amax,cn as amin,Jo as angle,Dn as any,an as append,Ps as apply_along_axis,Rs as apply_over_axes,tr as arange,Pe as arccos,Fe as arccosh,qe as arcsin,Ye as arcsinh,Re as arctan,Ee as arctan2,Je as arctanh,gn as argmax,_n as argmin,qt as argpartition,Tt as argsort,Et as argwhere,to as around,nr as array,Gs as array2string,ss as array_equal,ms as array_equiv,Ys as array_repr,Ha as array_split,Fs as array_str,yr as asanyarray,pr as asarray,_r as asarray_chkfinite,gr as ascontiguousarray,xr as asfortranarray,Qe as asin,$e as asinh,Xe as atan,Ze as atan2,ea as atanh,$a as atleast_1d,rn as atleast_2d,en as atleast_3d,Sn as average,Js as base_repr,Ks as binary_repr,ko as bincount,ns as bindex,Vt as bitwise_and,Zt as bitwise_count,ro as bitwise_invert,eo as bitwise_left_shift,Ft as bitwise_not,Gt as bitwise_or,ao as bitwise_right_shift,Yt as bitwise_xor,ja as block,Zo as broadcast_arrays,$o as broadcast_shapes,Xo as broadcast_to,Ts as byteswap,em as can_cast,ne as cbrt,so as ceil,os as choose,ye as clip,Ea as column_stack,am as common_type,fs as compress,un as concat,Oa as concatenate,Fo as conj,Qo as conjugate,Po as convolve,cr as copy,yt as copysign,ts as copyto,Eo as corrcoef,qo as correlate,Oe as cos,Ve as cosh,Lt as count_nonzero,Ro as cov,xa as cross,Cn as cumprod,kn as cumsum,Kn as cumulative_prod,Jn as cumulative_sum,He as deg2rad,je as degrees,tn as delete,nn as delete_,Nr as diag,cs as diag_indices,ys as diag_indices_from,Ar as diagflat,oa as diagonal,Ho as diff,Co as digitize,Mr as divide,oe as divmod,na as dot,Va as dsplit,Ra as dstack,Lo as ediff1d,fa as einsum,ba as einsum_path,er as empty,lr as empty_like,zt as equal,Vr as exp,Gr as exp2,Da as expand_dims,Yr as expm1,Ht as extract,ir as eye,te as fabs,V as fft,vs as fill,ds as fill_diagonal,mo as fix,Mt as flatnonzero,za as flatten,Ja as flip,Ka as fliplr,Qa as flipud,ue as float_power,io as floor,Ur as floor_divide,xe as fmax,he as fmin,pe as fmod,Qs as format_float_positional,Ws as format_float_scientific,fe as frexp,wr as frombuffer,zr as fromfile,Sr as fromfunction,vr as fromiter,R as fromregex,Dr as fromstring,ar as full,dr as full_like,be as gcd,P as genfromtxt,mr as geomspace,Xs as get_printoptions,Ls as geterr,Bo as gradient,ht as greater,Nt as greater_equal,ie as heaviside,To as histogram,Oo as histogram2d,Mo as histogram_bin_edges,Io as histogramdd,Ba as hsplit,Pa as hstack,Me as hypot,Se as i0,ur as identity,as as iindex,Yo as imag,yo as in1d,As as indices,ia as inner,on as insert,Ae as interp,_o as intersect1d,Jt as invert,vt as isclose,st as iscomplex,mt as iscomplexobj,dt as isdtype,rt as isfinite,ft as isfortran,go as isin,et as isinf,at as isnan,nt as isnat,tt as isneginf,ot as isposinf,it as isreal,ut as isrealobj,bt as isscalar,om as issubdtype,Ds as item,lt as iterable,ws as ix_,sa as kron,le as lcm,de as ldexp,Kt as left_shift,At as less,wt as less_equal,Ot as lexsort,Na as linalg,or as linspace,O as loadNpz,I as loadNpzSync,Fr as log,Kr as log10,Qr as log1p,Jr as log2,Wr as logaddexp,Xr as logaddexp2,Wn as logical_and,Zn as logical_not,Xn as logical_or,$n as logical_xor,sr as logspace,Ns as mask_indices,ha as matmul,ca as matrix_transpose,_a as matvec,Yn as max,_e as maximum,Es as may_share_memory,bn as mean,An as median,kr as meshgrid,Fn as min,tm as min_scalar_type,ge as minimum,mm as mintypecode,Hr as mod,ce as modf,Ca as moveaxis,Er as multiply,Ne as nan_to_num,jn as nanargmax,Mn as nanargmin,Hn as nancumprod,Un as nancumsum,En as nanmax,In as nanmean,Ln as nanmedian,Rn as nanmin,Vn as nanpercentile,On as nanprod,Bn as nanquantile,Pn as nanstd,Tn as nansum,qn as nanvar,js as ndim,$r as negative,gt as nextafter,Rt as nonzero,St as not_equal,rr as ones,br as ones_like,ua as outer,Wt as packbits,sn as pad,v as parseNpy,k as parseNpyData,D as parseNpyHeader,C as parseNpz,T as parseNpzSync,q as parseTxt,It as partition,wn as percentile,ya as permute_dims,ls as place,um as poly,pm as polyadd,fm as polyder,bm as polydiv,lm as polyfit,dm as polyint,cm as polymul,ym as polysub,_m as polyval,ee as positive,De as pow,Br as power,$s as printoptions,ln as prod,ct as promote_types,yn as ptp,es as put,us as put_along_axis,ps as putmask,zn as quantile,Le as rad2deg,Ue as radians,L as random,Sa as ravel,zs as ravel_multi_index,Go as real,pt as real_if_close,ae as reciprocal,me as remainder,Fa as repeat,hr as require,wa as reshape,Za as resize,nm as result_type,Qt as right_shift,uo as rint,Xa as roll,Ta as rollaxis,gm as roots,Wa as rot90,bo as round,oo as round_,Ma as row_stack,Ut as searchsorted,bs as select,Sm as serializeNpy,Dm as serializeNpz,km as serializeNpzSync,Tm as serializeTxt,Zs as set_printoptions,xo as setdiff1d,Bs as seterr,ho as setxor1d,Us as shape,Ms as shares_memory,re as sign,_t as signbit,Te as sin,ze as sinc,Be as sinh,Hs as size,Ct as sort,Pt as sort_complex,xt as spacing,Ua as split,Lr as sqrt,se as square,va as squeeze,Ia as stack,xn as std,Rr as subtract,fn as sum,ka as swapaxes,rs as take,is as take_along_axis,Ie as tan,Ge as tanh,pa as tensordot,Ya as tile,Cs as tobytes,Is as tofile,ks as tolist,ta as trace,ma as transpose,jo as trapezoid,Cr as tri,Tr as tril,_s as tril_indices,gs as tril_indices_from,Ao as trim_zeros,Or as triu,xs as triu_indices,hs as triu_indices_from,jr as true_divide,po as trunc,sm as typename,No as union1d,co as unique,wo as unique_all,zo as unique_counts,So as unique_inverse,vo as unique_values,Xt as unpackbits,Ss as unravel_index,Ga as unstack,we as unwrap,Ir as vander,Nn as var,hn as variance,la as vdot,da as vecdot,ga as vecmat,Os as view,La as vsplit,qa as vstack,jt as where,$ as zeros,fr as zeros_like};
1
+ import{Complex as J}from"./common/complex";import{NDArray as Q}from"./full";import{NDArrayCore as X}from"./common/ndarray-core";import{zeros as $,ones as rr,empty as er,full as ar,array as nr,arange as tr,linspace as or,logspace as sr,geomspace as mr,eye as ir,identity as ur,asarray as pr,zeros_like as fr,ones_like as br,empty_like as lr,full_like as dr,copy as cr,asanyarray as yr,asarray_chkfinite as _r,ascontiguousarray as gr,asfortranarray as xr,require as hr,diag as Nr,diagflat as Ar,frombuffer as wr,fromfile as zr,fromfunction as Sr,fromiter as vr,fromstring as Dr,meshgrid as kr,tri as Cr,tril as Tr,triu as Or,vander as Ir}from"./full";import{add as Pr,subtract as Rr,multiply as Er,divide as Mr,true_divide as jr,floor_divide as Ur,mod as Hr,sqrt as Lr,power as Br,exp as Vr,exp2 as Gr,expm1 as Yr,log as Fr,log2 as Jr,log10 as Kr,log1p as Qr,logaddexp as Wr,logaddexp2 as Xr,absolute as Zr,negative as $r,sign as re,positive as ee,reciprocal as ae,cbrt as ne,fabs as te,divmod as oe,square as se,remainder as me,heaviside as ie,float_power as ue,fmod as pe,frexp as fe,gcd as be,lcm as le,ldexp as de,modf as ce,clip as ye,maximum as _e,minimum as ge,fmax as xe,fmin as he,nan_to_num as Ne,interp as Ae,unwrap as we,sinc as ze,i0 as Se}from"./full";import{power as De,absolute as ke}from"./full";import{sin as Te,cos as Oe,tan as Ie,arcsin as qe,arccos as Pe,arctan as Re,arctan2 as Ee,hypot as Me,degrees as je,radians as Ue,deg2rad as He,rad2deg as Le,sinh as Be,cosh as Ve,tanh as Ge,arcsinh as Ye,arccosh as Fe,arctanh as Je}from"./full";import{arcsin as Qe,arccos as We,arctan as Xe,arctan2 as Ze,arcsinh as $e,arccosh as ra,arctanh as ea}from"./full";import{dot as na,trace as ta,diagonal as oa,kron as sa,transpose as ma,inner as ia,outer as ua,tensordot as pa,einsum as fa,einsum_path as ba,vdot as la,vecdot as da,matrix_transpose as ca,permute_dims as ya,matvec as _a,vecmat as ga,cross as xa,matmul as ha,linalg as Na}from"./full";import{reshape as wa,flatten as za,ravel as Sa,squeeze as va,expand_dims as Da,swapaxes as ka,moveaxis as Ca,rollaxis as Ta,concatenate as Oa,stack as Ia,vstack as qa,hstack as Pa,dstack as Ra,column_stack as Ea,row_stack as Ma,block as ja,split as Ua,array_split as Ha,vsplit as La,hsplit as Ba,dsplit as Va,unstack as Ga,tile as Ya,repeat as Fa,flip as Ja,fliplr as Ka,flipud as Qa,rot90 as Wa,roll as Xa,resize as Za,atleast_1d as $a,atleast_2d as rn,atleast_3d as en,append as an,delete_ as nn,delete_ as tn,insert as on,pad as sn}from"./full";import{concatenate as un}from"./full";import{sum as fn,mean as bn,prod as ln,amax as dn,amin as cn,ptp as yn,argmin as _n,argmax as gn,std as xn,variance as hn,var_ as Nn,median as An,percentile as wn,quantile as zn,average as Sn,all as vn,any as Dn,cumsum as kn,cumprod as Cn,nansum as Tn,nanprod as On,nanmean as In,nanvar as qn,nanstd as Pn,nanmin as Rn,nanmax as En,nanargmin as Mn,nanargmax as jn,nancumsum as Un,nancumprod as Hn,nanmedian as Ln,nanquantile as Bn,nanpercentile as Vn}from"./full";import{amax as Yn,amin as Fn,cumsum as Jn,cumprod as Kn}from"./full";import{logical_and as Wn,logical_or as Xn,logical_not as Zn,logical_xor as $n,isfinite as rt,isinf as et,isnan as at,isnat as nt,isneginf as tt,isposinf as ot,iscomplex as st,iscomplexobj as mt,isreal as it,isrealobj as ut,real_if_close as pt,isfortran as ft,isscalar as bt,iterable as lt,isdtype as dt,promote_types as ct,copysign as yt,signbit as _t,nextafter as gt,spacing as xt,greater as ht,greater_equal as Nt,less as At,less_equal as wt,equal as zt,not_equal as St,isclose as vt,allclose as Dt}from"./full";import{sort as Ct,argsort as Tt,lexsort as Ot,partition as It,argpartition as qt,sort_complex as Pt,nonzero as Rt,argwhere as Et,flatnonzero as Mt,where as jt,searchsorted as Ut,extract as Ht,count_nonzero as Lt}from"./full";import{bitwise_and as Vt,bitwise_or as Gt,bitwise_xor as Yt,bitwise_not as Ft,invert as Jt,left_shift as Kt,right_shift as Qt,packbits as Wt,unpackbits as Xt,bitwise_count as Zt}from"./full";import{bitwise_not as ro,left_shift as eo,right_shift as ao}from"./full";import{around as to,round_ as oo,ceil as so,fix as mo,floor as io,rint as uo,trunc as po}from"./full";import{around as bo}from"./full";import{unique as co,in1d as yo,intersect1d as _o,isin as go,setdiff1d as xo,setxor1d as ho,union1d as No,trim_zeros as Ao,unique_all as wo,unique_counts as zo,unique_inverse as So,unique_values as vo}from"./full";import{bincount as ko,digitize as Co,histogram as To,histogram2d as Oo,histogramdd as Io,correlate as qo,convolve as Po,cov as Ro,corrcoef as Eo,histogram_bin_edges as Mo,trapezoid as jo}from"./full";import{diff as Ho,ediff1d as Lo,gradient as Bo}from"./full";import{real as Go,imag as Yo,conj as Fo,angle as Jo}from"./full";import{conj as Qo}from"./full";import{broadcast_to as Xo,broadcast_arrays as Zo,broadcast_shapes as $o,take as rs,put as es,iindex as as,bindex as ns,copyto as ts,choose as os,array_equal as ss,array_equiv as ms,take_along_axis as is,put_along_axis as us,putmask as ps,compress as fs,select as bs,place as ls,fill_diagonal as ds,diag_indices as cs,diag_indices_from as ys,tril_indices as _s,tril_indices_from as gs,triu_indices as xs,triu_indices_from as hs,mask_indices as Ns,indices as As,ix_ as ws,ravel_multi_index as zs,unravel_index as Ss,fill as vs,item as Ds,tolist as ks,tobytes as Cs,byteswap as Ts,view as Os,tofile as Is}from"./full";import{apply_along_axis as Ps,apply_over_axes as Rs,may_share_memory as Es,shares_memory as Ms,ndim as js,shape as Us,size as Hs,geterr as Ls,seterr as Bs}from"./full";import{array2string as Gs,array_repr as Ys,array_str as Fs,base_repr as Js,binary_repr as Ks,format_float_positional as Qs,format_float_scientific as Ws,get_printoptions as Xs,set_printoptions as Zs,printoptions as $s}from"./full";import{can_cast as em,common_type as am,result_type as nm,min_scalar_type as tm,issubdtype as om,typename as sm,mintypecode as mm}from"./full";import{poly as um,polyadd as pm,polyder as fm,polydiv as bm,polyfit as lm,polyint as dm,polymul as cm,polysub as ym,polyval as _m,roots as gm}from"./full";import{UnsupportedDTypeError as hm,InvalidNpyError as Nm,SUPPORTED_DTYPES as Am,DTYPE_TO_DESCR as wm}from"./io/npy/format";import{serializeNpy as Sm}from"./io/npy/serializer";import{serializeNpz as Dm,serializeNpzSync as km}from"./io/npz/serializer";import{serializeTxt as Tm}from"./io/txt/serializer";import{parseNpy as b,parseNpyHeader as l,parseNpyData as d}from"./io/npy/parser";import{parseNpz as c,parseNpzSync as y,loadNpz as _,loadNpzSync as g}from"./io/npz/parser";import{parseTxt as x,genfromtxt as h,fromregex as N}from"./io/txt/parser";function p(r){return s.fromStorage(r.storage)}function v(r){return p(b(r))}const D=l;function k(r,e){return p(d(r,e))}async function C(r,e={}){const a=await c(r,e),t=new Map;for(const[u,f]of a.arrays)t.set(u,p(f));return{arrays:t,skipped:a.skipped,errors:a.errors}}function T(r,e={}){const a=y(r,e),t=new Map;for(const[u,f]of a.arrays)t.set(u,p(f));return{arrays:t,skipped:a.skipped,errors:a.errors}}async function O(r,e={}){const a=await _(r,e),t={};for(const[u,f]of Object.entries(a))t[u]=p(f);return t}function I(r,e={}){const a=g(r,e),t={};for(const[u,f]of Object.entries(a))t[u]=p(f);return t}function q(r,e={}){return p(x(r,e))}function P(r,e={}){return p(h(r,e))}function R(r,e,a="float64"){return p(N(r,e,a))}import*as n from"./common/ops/random";import{NDArray as s}from"./full";function o(r){return r&&typeof r=="object"&&"_data"in r&&"_shape"in r?s.fromStorage(r):r}const L={seed:n.seed,get_state:n.get_state,set_state:n.set_state,get_bit_generator:n.get_bit_generator,set_bit_generator:n.set_bit_generator,default_rng:n.default_rng,Generator:n.Generator,random:r=>o(n.random(r)),rand:(...r)=>o(n.rand(...r)),randn:(...r)=>o(n.randn(...r)),randint:(r,e,a,t)=>o(n.randint(r,e,a,t)),random_sample:r=>o(n.random_sample(r)),ranf:r=>o(n.ranf(r)),sample:r=>o(n.sample(r)),random_integers:(r,e,a)=>o(n.random_integers(r,e,a)),bytes:n.bytes,uniform:(r,e,a)=>o(n.uniform(r,e,a)),normal:(r,e,a)=>o(n.normal(r,e,a)),standard_normal:r=>o(n.standard_normal(r)),exponential:(r,e)=>o(n.exponential(r,e)),standard_exponential:r=>o(n.standard_exponential(r)),gamma:(r,e,a)=>o(n.gamma(r,e,a)),standard_gamma:(r,e)=>o(n.standard_gamma(r,e)),beta:(r,e,a)=>o(n.beta(r,e,a)),chisquare:(r,e)=>o(n.chisquare(r,e)),noncentral_chisquare:(r,e,a)=>o(n.noncentral_chisquare(r,e,a)),f:(r,e,a)=>o(n.f(r,e,a)),noncentral_f:(r,e,a,t)=>o(n.noncentral_f(r,e,a,t)),standard_cauchy:r=>o(n.standard_cauchy(r)),standard_t:(r,e)=>o(n.standard_t(r,e)),laplace:(r,e,a)=>o(n.laplace(r,e,a)),logistic:(r,e,a)=>o(n.logistic(r,e,a)),lognormal:(r,e,a)=>o(n.lognormal(r,e,a)),gumbel:(r,e,a)=>o(n.gumbel(r,e,a)),pareto:(r,e)=>o(n.pareto(r,e)),power:(r,e)=>o(n.power(r,e)),rayleigh:(r,e)=>o(n.rayleigh(r,e)),triangular:(r,e,a,t)=>o(n.triangular(r,e,a,t)),wald:(r,e,a)=>o(n.wald(r,e,a)),weibull:(r,e)=>o(n.weibull(r,e)),poisson:(r,e)=>o(n.poisson(r,e)),binomial:(r,e,a)=>o(n.binomial(r,e,a)),geometric:(r,e)=>o(n.geometric(r,e)),hypergeometric:(r,e,a,t)=>o(n.hypergeometric(r,e,a,t)),logseries:(r,e)=>o(n.logseries(r,e)),negative_binomial:(r,e,a)=>o(n.negative_binomial(r,e,a)),zipf:(r,e)=>o(n.zipf(r,e)),multinomial:(r,e,a)=>o(n.multinomial(r,e,a)),multivariate_normal:(r,e,a,t,u)=>o(n.multivariate_normal(r,e,a,t,u)),dirichlet:(r,e)=>o(n.dirichlet(r,e)),vonmises:(r,e,a)=>o(n.vonmises(r,e,a)),choice:(r,e,a,t)=>o(n.choice(r,e,a,t)),permutation:r=>o(n.permutation(r)),shuffle:n.shuffle};import*as m from"./common/ops/fft";import{NDArrayCore as A}from"./common/ndarray-core";function i(r){return r instanceof s||r instanceof A?r.storage:r}const V={fft:(r,e,a,t)=>s.fromStorage(m.fft(i(r),e,a,t)),ifft:(r,e,a,t)=>s.fromStorage(m.ifft(i(r),e,a,t)),fft2:(r,e,a,t)=>s.fromStorage(m.fft2(i(r),e,a,t)),ifft2:(r,e,a,t)=>s.fromStorage(m.ifft2(i(r),e,a,t)),fftn:(r,e,a,t)=>s.fromStorage(m.fftn(i(r),e,a,t)),ifftn:(r,e,a,t)=>s.fromStorage(m.ifftn(i(r),e,a,t)),rfft:(r,e,a,t)=>s.fromStorage(m.rfft(i(r),e,a,t)),irfft:(r,e,a,t)=>s.fromStorage(m.irfft(i(r),e,a,t)),rfft2:(r,e,a,t)=>s.fromStorage(m.rfft2(i(r),e,a,t)),irfft2:(r,e,a,t)=>s.fromStorage(m.irfft2(i(r),e,a,t)),rfftn:(r,e,a,t)=>s.fromStorage(m.rfftn(i(r),e,a,t)),irfftn:(r,e,a,t)=>s.fromStorage(m.irfftn(i(r),e,a,t)),hfft:(r,e,a,t)=>s.fromStorage(m.hfft(i(r),e,a,t)),ihfft:(r,e,a,t)=>s.fromStorage(m.ihfft(i(r),e,a,t)),fftfreq:(r,e)=>s.fromStorage(m.fftfreq(r,e)),rfftfreq:(r,e)=>s.fromStorage(m.rfftfreq(r,e)),fftshift:(r,e)=>s.fromStorage(m.fftshift(i(r),e)),ifftshift:(r,e)=>s.fromStorage(m.ifftshift(i(r),e))},G="0.13.1";export{J as Complex,wm as DTYPE_TO_DESCR,Nm as InvalidNpyError,Q as NDArray,X as NDArrayCore,Am as SUPPORTED_DTYPES,hm as UnsupportedDTypeError,G as __version__,ke as abs,Zr as absolute,We as acos,ra as acosh,Pr as add,vn as all,Dt as allclose,dn as amax,cn as amin,Jo as angle,Dn as any,an as append,Ps as apply_along_axis,Rs as apply_over_axes,tr as arange,Pe as arccos,Fe as arccosh,qe as arcsin,Ye as arcsinh,Re as arctan,Ee as arctan2,Je as arctanh,gn as argmax,_n as argmin,qt as argpartition,Tt as argsort,Et as argwhere,to as around,nr as array,Gs as array2string,ss as array_equal,ms as array_equiv,Ys as array_repr,Ha as array_split,Fs as array_str,yr as asanyarray,pr as asarray,_r as asarray_chkfinite,gr as ascontiguousarray,xr as asfortranarray,Qe as asin,$e as asinh,Xe as atan,Ze as atan2,ea as atanh,$a as atleast_1d,rn as atleast_2d,en as atleast_3d,Sn as average,Js as base_repr,Ks as binary_repr,ko as bincount,ns as bindex,Vt as bitwise_and,Zt as bitwise_count,ro as bitwise_invert,eo as bitwise_left_shift,Ft as bitwise_not,Gt as bitwise_or,ao as bitwise_right_shift,Yt as bitwise_xor,ja as block,Zo as broadcast_arrays,$o as broadcast_shapes,Xo as broadcast_to,Ts as byteswap,em as can_cast,ne as cbrt,so as ceil,os as choose,ye as clip,Ea as column_stack,am as common_type,fs as compress,un as concat,Oa as concatenate,Fo as conj,Qo as conjugate,Po as convolve,cr as copy,yt as copysign,ts as copyto,Eo as corrcoef,qo as correlate,Oe as cos,Ve as cosh,Lt as count_nonzero,Ro as cov,xa as cross,Cn as cumprod,kn as cumsum,Kn as cumulative_prod,Jn as cumulative_sum,He as deg2rad,je as degrees,tn as delete,nn as delete_,Nr as diag,cs as diag_indices,ys as diag_indices_from,Ar as diagflat,oa as diagonal,Ho as diff,Co as digitize,Mr as divide,oe as divmod,na as dot,Va as dsplit,Ra as dstack,Lo as ediff1d,fa as einsum,ba as einsum_path,er as empty,lr as empty_like,zt as equal,Vr as exp,Gr as exp2,Da as expand_dims,Yr as expm1,Ht as extract,ir as eye,te as fabs,V as fft,vs as fill,ds as fill_diagonal,mo as fix,Mt as flatnonzero,za as flatten,Ja as flip,Ka as fliplr,Qa as flipud,ue as float_power,io as floor,Ur as floor_divide,xe as fmax,he as fmin,pe as fmod,Qs as format_float_positional,Ws as format_float_scientific,fe as frexp,wr as frombuffer,zr as fromfile,Sr as fromfunction,vr as fromiter,R as fromregex,Dr as fromstring,ar as full,dr as full_like,be as gcd,P as genfromtxt,mr as geomspace,Xs as get_printoptions,Ls as geterr,Bo as gradient,ht as greater,Nt as greater_equal,ie as heaviside,To as histogram,Oo as histogram2d,Mo as histogram_bin_edges,Io as histogramdd,Ba as hsplit,Pa as hstack,Me as hypot,Se as i0,ur as identity,as as iindex,Yo as imag,yo as in1d,As as indices,ia as inner,on as insert,Ae as interp,_o as intersect1d,Jt as invert,vt as isclose,st as iscomplex,mt as iscomplexobj,dt as isdtype,rt as isfinite,ft as isfortran,go as isin,et as isinf,at as isnan,nt as isnat,tt as isneginf,ot as isposinf,it as isreal,ut as isrealobj,bt as isscalar,om as issubdtype,Ds as item,lt as iterable,ws as ix_,sa as kron,le as lcm,de as ldexp,Kt as left_shift,At as less,wt as less_equal,Ot as lexsort,Na as linalg,or as linspace,O as loadNpz,I as loadNpzSync,Fr as log,Kr as log10,Qr as log1p,Jr as log2,Wr as logaddexp,Xr as logaddexp2,Wn as logical_and,Zn as logical_not,Xn as logical_or,$n as logical_xor,sr as logspace,Ns as mask_indices,ha as matmul,ca as matrix_transpose,_a as matvec,Yn as max,_e as maximum,Es as may_share_memory,bn as mean,An as median,kr as meshgrid,Fn as min,tm as min_scalar_type,ge as minimum,mm as mintypecode,Hr as mod,ce as modf,Ca as moveaxis,Er as multiply,Ne as nan_to_num,jn as nanargmax,Mn as nanargmin,Hn as nancumprod,Un as nancumsum,En as nanmax,In as nanmean,Ln as nanmedian,Rn as nanmin,Vn as nanpercentile,On as nanprod,Bn as nanquantile,Pn as nanstd,Tn as nansum,qn as nanvar,js as ndim,$r as negative,gt as nextafter,Rt as nonzero,St as not_equal,rr as ones,br as ones_like,ua as outer,Wt as packbits,sn as pad,v as parseNpy,k as parseNpyData,D as parseNpyHeader,C as parseNpz,T as parseNpzSync,q as parseTxt,It as partition,wn as percentile,ya as permute_dims,ls as place,um as poly,pm as polyadd,fm as polyder,bm as polydiv,lm as polyfit,dm as polyint,cm as polymul,ym as polysub,_m as polyval,ee as positive,De as pow,Br as power,$s as printoptions,ln as prod,ct as promote_types,yn as ptp,es as put,us as put_along_axis,ps as putmask,zn as quantile,Le as rad2deg,Ue as radians,L as random,Sa as ravel,zs as ravel_multi_index,Go as real,pt as real_if_close,ae as reciprocal,me as remainder,Fa as repeat,hr as require,wa as reshape,Za as resize,nm as result_type,Qt as right_shift,uo as rint,Xa as roll,Ta as rollaxis,gm as roots,Wa as rot90,bo as round,oo as round_,Ma as row_stack,Ut as searchsorted,bs as select,Sm as serializeNpy,Dm as serializeNpz,km as serializeNpzSync,Tm as serializeTxt,Zs as set_printoptions,xo as setdiff1d,Bs as seterr,ho as setxor1d,Us as shape,Ms as shares_memory,re as sign,_t as signbit,Te as sin,ze as sinc,Be as sinh,Hs as size,Ct as sort,Pt as sort_complex,xt as spacing,Ua as split,Lr as sqrt,se as square,va as squeeze,Ia as stack,xn as std,Rr as subtract,fn as sum,ka as swapaxes,rs as take,is as take_along_axis,Ie as tan,Ge as tanh,pa as tensordot,Ya as tile,Cs as tobytes,Is as tofile,ks as tolist,ta as trace,ma as transpose,jo as trapezoid,Cr as tri,Tr as tril,_s as tril_indices,gs as tril_indices_from,Ao as trim_zeros,Or as triu,xs as triu_indices,hs as triu_indices_from,jr as true_divide,po as trunc,sm as typename,No as union1d,co as unique,wo as unique_all,zo as unique_counts,So as unique_inverse,vo as unique_values,Xt as unpackbits,Ss as unravel_index,Ga as unstack,we as unwrap,Ir as vander,Nn as var,hn as variance,la as vdot,da as vecdot,ga as vecmat,Os as view,La as vsplit,qa as vstack,jt as where,$ as zeros,fr as zeros_like};