@margoengine/compute 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +736 -3
- package/dist/array-DbI848Wf.js +166 -0
- package/dist/array.d.ts +109 -0
- package/dist/autodiff.d.ts +22 -0
- package/dist/autodiff.js +143 -0
- package/dist/autotune.d.ts +100 -0
- package/dist/autotune.js +179 -0
- package/dist/compat-YK57ZCbA.js +4 -0
- package/dist/compat.d.ts +2 -0
- package/dist/context-C75sQQra.js +2470 -0
- package/dist/context.d.ts +368 -0
- package/dist/cpu-CdVdqP4I.js +871 -0
- package/dist/cpu-kernel.wasm +0 -0
- package/dist/cpu-load-aTmfphVu.js +5 -0
- package/dist/cpu-load.d.ts +3 -0
- package/dist/cpu-runtime.d.ts +8 -0
- package/dist/cpu-wasm.d.ts +42 -0
- package/dist/cpu-wasm.js +161 -0
- package/dist/cpu.d.ts +138 -0
- package/dist/decomp-kernel.wasm +0 -0
- package/dist/decomp.d.ts +42 -0
- package/dist/decomp.js +158 -0
- package/dist/distance.d.ts +85 -0
- package/dist/distance.js +256 -0
- package/dist/dtype.d.ts +36 -0
- package/dist/errors-CDgOgzCd.js +7 -0
- package/dist/expr-DwFen60A.js +995 -0
- package/dist/expr.d.ts +196 -0
- package/dist/fft.d.ts +33 -0
- package/dist/fft.js +168 -0
- package/dist/frame.d.ts +63 -0
- package/dist/frame.js +82 -0
- package/dist/graph.d.ts +75 -0
- package/dist/graph.js +174 -0
- package/dist/histogram.d.ts +17 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +4 -0
- package/dist/kernel.d.ts +65 -0
- package/dist/linalg.d.ts +21 -0
- package/dist/linalg.js +149 -0
- package/dist/nn-extra.d.ts +130 -0
- package/dist/nn-extra.js +322 -0
- package/dist/nn.d.ts +385 -0
- package/dist/nn.js +704 -0
- package/dist/onnx-kernel.wasm +0 -0
- package/dist/onnx.d.ts +164 -0
- package/dist/onnx.js +817 -0
- package/dist/quant.d.ts +59 -0
- package/dist/quant.js +242 -0
- package/dist/random.d.ts +64 -0
- package/dist/random.js +150 -0
- package/dist/reduce.d.ts +34 -0
- package/dist/scan.d.ts +26 -0
- package/dist/select.d.ts +38 -0
- package/dist/shaders.d.ts +80 -0
- package/dist/shape.d.ts +23 -0
- package/dist/shape.js +134 -0
- package/dist/signal.d.ts +29 -0
- package/dist/signal.js +178 -0
- package/dist/sort.d.ts +38 -0
- package/dist/sparse.d.ts +136 -0
- package/dist/sparse.js +273 -0
- package/dist/stream.d.ts +39 -0
- package/dist/stream.js +100 -0
- package/dist/subgroups.d.ts +27 -0
- package/dist/subgroups.js +191 -0
- package/dist/usingCtx-igdMnAhr.js +57 -0
- package/dist/wgsl.d.ts +68 -0
- package/package.json +144 -6
|
@@ -0,0 +1,995 @@
|
|
|
1
|
+
import { n as e, r as t } from "./errors-CDgOgzCd.js";
|
|
2
|
+
//#region src/dtype.ts
|
|
3
|
+
var n = [
|
|
4
|
+
"f32",
|
|
5
|
+
"f16",
|
|
6
|
+
"i32",
|
|
7
|
+
"u32"
|
|
8
|
+
], r = (e) => e === "f16" ? 2 : 4, i = (e) => e === "f32" || e === "f16", a = globalThis.Float16Array;
|
|
9
|
+
function o(e) {
|
|
10
|
+
switch (e) {
|
|
11
|
+
case "f32": return Float32Array;
|
|
12
|
+
case "i32": return Int32Array;
|
|
13
|
+
case "u32": return Uint32Array;
|
|
14
|
+
case "f16":
|
|
15
|
+
if (!a) throw t("f16 data needs Float16Array; read it as f32 with astype(\"f32\")", "compute");
|
|
16
|
+
return a;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function s(e) {
|
|
20
|
+
if (a && e instanceof a) return "f16";
|
|
21
|
+
if (e instanceof Float32Array || e instanceof Float64Array) return "f32";
|
|
22
|
+
if (e instanceof Int32Array || e instanceof Int16Array || e instanceof Int8Array) return "i32";
|
|
23
|
+
if (e instanceof Uint32Array || e instanceof Uint16Array || e instanceof Uint8Array || e instanceof Uint8ClampedArray) return "u32";
|
|
24
|
+
if (ArrayBuffer.isView(e)) throw t("Compute arrays take number TypedArrays, not BigInt arrays or DataView", "compute");
|
|
25
|
+
return "f32";
|
|
26
|
+
}
|
|
27
|
+
function c(e, t) {
|
|
28
|
+
let n = o(t);
|
|
29
|
+
return e instanceof n && e.buffer instanceof ArrayBuffer ? e : n.from(e);
|
|
30
|
+
}
|
|
31
|
+
function l(e, t) {
|
|
32
|
+
return e === t ? e : e === "f32" || t === "f32" ? "f32" : e === "f16" || t === "f16" ? "f16" : "i32";
|
|
33
|
+
}
|
|
34
|
+
function u(e, t) {
|
|
35
|
+
return i(t) ? t : Number.isInteger(e) ? t === "u32" && e < 0 ? "i32" : t : "f32";
|
|
36
|
+
}
|
|
37
|
+
function d(e, t) {
|
|
38
|
+
let n = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(4));
|
|
39
|
+
return t === "f32" || t === "f16" ? n.setFloat32(0, e, !0) : t === "i32" ? n.setInt32(0, e, !0) : n.setUint32(0, e >>> 0, !0), n.getUint32(0, !0);
|
|
40
|
+
}
|
|
41
|
+
function f(e, t) {
|
|
42
|
+
return t === "u32" ? e : t === "f16" ? `f16(bitcast<f32>(${e}))` : `bitcast<${t}>(${e})`;
|
|
43
|
+
}
|
|
44
|
+
var p = /* @__PURE__ */ Object.freeze({
|
|
45
|
+
twoOverPi: [
|
|
46
|
+
0,
|
|
47
|
+
2734261102,
|
|
48
|
+
1313084713,
|
|
49
|
+
4230436817,
|
|
50
|
+
4113882560,
|
|
51
|
+
3680671129,
|
|
52
|
+
1011060801,
|
|
53
|
+
4266746795
|
|
54
|
+
],
|
|
55
|
+
halfPiFixed: 3373259426,
|
|
56
|
+
halfPi: [1.5707963705062866, -4.371138828673793e-8],
|
|
57
|
+
quarterPi: [.7853981852531433, -2.1855694143368964e-8],
|
|
58
|
+
pi: [3.1415927410125732, -8.742277657347586e-8],
|
|
59
|
+
ln2: [.693145751953125, 1428606765330187e-21],
|
|
60
|
+
ln2Pair: [.6931471824645996, -1.9046542121259336e-9],
|
|
61
|
+
log2e: [1.4426950216293335, 1.925963033500011e-8],
|
|
62
|
+
sin: [
|
|
63
|
+
-.1666666716337204,
|
|
64
|
+
.008333379402756691,
|
|
65
|
+
-.00019853089179378003,
|
|
66
|
+
2833021881087916e-21
|
|
67
|
+
],
|
|
68
|
+
cos: [
|
|
69
|
+
.0416666679084301,
|
|
70
|
+
-.0013888980029150844,
|
|
71
|
+
2482202216924634e-20,
|
|
72
|
+
-2.8881245839329495e-7
|
|
73
|
+
],
|
|
74
|
+
atan: [
|
|
75
|
+
-.3333333432674408,
|
|
76
|
+
.20000059902668,
|
|
77
|
+
-.14286741614341736,
|
|
78
|
+
.11114691942930222,
|
|
79
|
+
-.09025663882493973,
|
|
80
|
+
.06947030127048492,
|
|
81
|
+
-.03550770878791809
|
|
82
|
+
],
|
|
83
|
+
asin: [
|
|
84
|
+
.1666666716337204,
|
|
85
|
+
.07499949634075165,
|
|
86
|
+
.044659871608018875,
|
|
87
|
+
.03011295571923256,
|
|
88
|
+
.024605773389339447,
|
|
89
|
+
.007497195154428482,
|
|
90
|
+
.03466988354921341
|
|
91
|
+
],
|
|
92
|
+
sinh: [
|
|
93
|
+
.1666666716337204,
|
|
94
|
+
.00833326205611229,
|
|
95
|
+
.00019874409190379083,
|
|
96
|
+
20846018742304295e-22,
|
|
97
|
+
6.411173671949655e-7,
|
|
98
|
+
-2.0997923400045693e-7
|
|
99
|
+
],
|
|
100
|
+
cosh: [
|
|
101
|
+
.0416666679084301,
|
|
102
|
+
.0013888796092942357,
|
|
103
|
+
2482521813362837e-20,
|
|
104
|
+
2.506288865333772e-7,
|
|
105
|
+
1.1460320692435744e-8
|
|
106
|
+
],
|
|
107
|
+
tanh: [
|
|
108
|
+
-.3333333432674408,
|
|
109
|
+
.1333339512348175,
|
|
110
|
+
-.05398104339838028,
|
|
111
|
+
.021990614011883736,
|
|
112
|
+
-.009435489773750305,
|
|
113
|
+
.004868379328399897,
|
|
114
|
+
-.0023415694013237953
|
|
115
|
+
],
|
|
116
|
+
expm1: [
|
|
117
|
+
.5,
|
|
118
|
+
.1666666567325592,
|
|
119
|
+
.04166649281978607,
|
|
120
|
+
.008333546109497547,
|
|
121
|
+
.0013932319125160575,
|
|
122
|
+
.00019761594012379646
|
|
123
|
+
],
|
|
124
|
+
log: [
|
|
125
|
+
.6666666269302368,
|
|
126
|
+
.40000975131988525,
|
|
127
|
+
.28498485684394836,
|
|
128
|
+
.24286234378814697
|
|
129
|
+
]
|
|
130
|
+
}), m = (e) => {
|
|
131
|
+
let t = String(e);
|
|
132
|
+
for (let n = 1; n <= 9; n++) {
|
|
133
|
+
let r = e.toPrecision(n);
|
|
134
|
+
if (Math.fround(Number(r)) === e) {
|
|
135
|
+
t = r;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return /[.e]/.test(t) ? t : `${t}.0`;
|
|
140
|
+
}, h = (e, t) => {
|
|
141
|
+
let n = m(t[t.length - 1]);
|
|
142
|
+
for (let r = t.length - 2; r >= 0; r--) n = `(${e} * ${n} + ${m(t[r])})`;
|
|
143
|
+
return n;
|
|
144
|
+
}, g = (e) => `0x${e.toString(16)}u`, _, v = () => _ ??= {
|
|
145
|
+
pmBits: [[], `fn pmExponent(x: f32) -> u32 { return (bitcast<u32>(x) >> 23u) & 0xffu; }
|
|
146
|
+
fn pmNegative(x: f32) -> bool { return (bitcast<u32>(x) >> 31u) == 1u; }
|
|
147
|
+
fn pmIsNan(x: f32) -> bool { return (bitcast<u32>(x) & 0x7fffffffu) > 0x7f800000u; }
|
|
148
|
+
fn pmIsZero(x: f32) -> bool { return (bitcast<u32>(x) & 0x7fffffffu) == 0u; }
|
|
149
|
+
fn pmNan(x: f32) -> f32 { return bitcast<f32>(bitcast<u32>(x) | 0x7fc00000u); }
|
|
150
|
+
fn pmInfinity(negative: bool, x: f32) -> f32 { return bitcast<f32>((bitcast<u32>(x) & 0u) | select(0x7f800000u, 0xff800000u, negative)); }
|
|
151
|
+
fn pmWithSign(v: f32, x: f32) -> f32 { return select(v, -v, pmNegative(x)); }
|
|
152
|
+
fn pmSplit(v: f32) -> vec2f { let h = bitcast<f32>(bitcast<u32>(v) & 0xfffff000u); return vec2f(h, v - h); }
|
|
153
|
+
fn pmHide(v: f32) -> f32 {
|
|
154
|
+
let b = bitcast<u32>(v);
|
|
155
|
+
let e = (b >> 23u) & 0xffu;
|
|
156
|
+
let m = i32((b & 0x7fffffu) | select(0x800000u, 0u, e == 0u));
|
|
157
|
+
return ldexp(f32(select(m, -m, (b >> 31u) == 1u)), max(i32(e), 1) - 150);
|
|
158
|
+
}
|
|
159
|
+
fn pmFastTwoSum(a: f32, b: f32) -> vec2f { let s = a + b; return vec2f(s, pmHide(b - pmHide(pmHide(s) - a))); }
|
|
160
|
+
fn pmProductError(a: f32, b: f32, p: f32) -> f32 {
|
|
161
|
+
let x = pmSplit(a); let y = pmSplit(b);
|
|
162
|
+
return pmHide((((pmHide(x.x * y.x) - p) + pmHide(x.x * y.y)) + pmHide(x.y * y.x)) + pmHide(x.y * y.y));
|
|
163
|
+
}
|
|
164
|
+
const PM_PIO2_HI: f32 = ${m(p.halfPi[0])};
|
|
165
|
+
const PM_PIO2_LO: f32 = ${m(p.halfPi[1])};
|
|
166
|
+
const PM_PIO4_HI: f32 = ${m(p.quarterPi[0])};
|
|
167
|
+
const PM_PIO4_LO: f32 = ${m(p.quarterPi[1])};
|
|
168
|
+
const PM_PI_HI: f32 = ${m(p.pi[0])};
|
|
169
|
+
const PM_PI_LO: f32 = ${m(p.pi[1])};
|
|
170
|
+
const PM_LN2_HI: f32 = ${m(p.ln2[0])};
|
|
171
|
+
const PM_LN2_LO: f32 = ${m(p.ln2[1])};
|
|
172
|
+
const PM_LN2: f32 = ${m(p.ln2Pair[0])};
|
|
173
|
+
const PM_LN2_TAIL: f32 = ${m(p.ln2Pair[1])};
|
|
174
|
+
const PM_LOG2E: f32 = ${m(p.log2e[0])};
|
|
175
|
+
const PM_LOG2E_LO: f32 = ${m(p.log2e[1])};
|
|
176
|
+
`],
|
|
177
|
+
preciseDiv: [["pmBits"], "fn preciseDiv(a: f32, b: f32) -> f32 {\n let q = a / b;\n if (pmExponent(a) == 255u || pmExponent(b) == 255u || pmExponent(q) == 255u || pmExponent(q) == 0u) { return q; }\n let p = pmHide(q * b);\n let r = (a - p) - pmProductError(q, b, p);\n return q + pmHide(r / b);\n}\n"],
|
|
178
|
+
preciseSqrt: [["pmBits"], "fn pmSqrt2(a: f32) -> vec2f {\n let s = sqrt(a);\n if (a <= 0.0 || pmIsNan(a) || pmExponent(a) == 255u || pmExponent(s) == 0u) { return vec2f(s, 0.0); }\n let p = pmHide(s * s);\n let r = (a - p) - pmProductError(s, s, p);\n return pmFastTwoSum(s, r / (2.0 * s));\n}\nfn preciseSqrt(a: f32) -> f32 { return pmSqrt2(a).x; }\n"],
|
|
179
|
+
pmReduce: [["pmBits"], `fn pmTwoOverPi(i: u32) -> u32 {
|
|
180
|
+
switch i {
|
|
181
|
+
${p.twoOverPi.map((e, t) => ` case ${t}u: { return ${g(e)}; }`).join("\n")}
|
|
182
|
+
default: { return 0u; }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
fn pmMul24x32(m: u32, v: u32) -> vec2u {
|
|
186
|
+
let ml = m & 0xfffu; let mh = m >> 12u; let vl = v & 0xffffu; let vh = v >> 16u;
|
|
187
|
+
let p0 = ml * vl; let p1 = ml * vh; let p2 = mh * vl; let p3 = mh * vh;
|
|
188
|
+
var lo = p0;
|
|
189
|
+
var hi = (p1 >> 16u) + (p2 >> 20u) + (p3 >> 4u);
|
|
190
|
+
var t = lo + (p1 << 16u); hi = hi + select(0u, 1u, t < lo); lo = t;
|
|
191
|
+
t = lo + (p2 << 12u); hi = hi + select(0u, 1u, t < lo); lo = t;
|
|
192
|
+
t = lo + (p3 << 28u); hi = hi + select(0u, 1u, t < lo); lo = t;
|
|
193
|
+
return vec2u(hi, lo);
|
|
194
|
+
}
|
|
195
|
+
fn pmMul32(a: u32, b: u32) -> vec2u {
|
|
196
|
+
let al = a & 0xffffu; let ah = a >> 16u; let bl = b & 0xffffu; let bh = b >> 16u;
|
|
197
|
+
let ll = al * bl; let lh = al * bh; let hl = ah * bl; let hh = ah * bh;
|
|
198
|
+
let mid = (ll >> 16u) + (lh & 0xffffu) + (hl & 0xffffu);
|
|
199
|
+
return vec2u(hh + (lh >> 16u) + (hl >> 16u) + (mid >> 16u), (ll & 0xffffu) | (mid << 16u));
|
|
200
|
+
}
|
|
201
|
+
struct PmReduced { hi: f32, lo: f32, q: u32 }
|
|
202
|
+
fn pmReduce(a: f32) -> PmReduced {
|
|
203
|
+
let u = bitcast<u32>(a);
|
|
204
|
+
let e = i32(u >> 23u) - 150;
|
|
205
|
+
let m = (u & 0x7fffffu) | 0x800000u;
|
|
206
|
+
let t = u32(e + 30);
|
|
207
|
+
let w = t >> 5u; let s = t & 31u; let r = 32u - s;
|
|
208
|
+
let A = pmTwoOverPi(w); let B = pmTwoOverPi(w + 1u); let C = pmTwoOverPi(w + 2u); let D = pmTwoOverPi(w + 3u);
|
|
209
|
+
let v0 = select((A << s) | (B >> r), A, s == 0u);
|
|
210
|
+
let v1 = select((B << s) | (C >> r), B, s == 0u);
|
|
211
|
+
let v2 = select((C << s) | (D >> r), C, s == 0u);
|
|
212
|
+
let P0 = pmMul24x32(m, v0); let P1 = pmMul24x32(m, v1); let P2 = pmMul24x32(m, v2);
|
|
213
|
+
let p0 = P2.y;
|
|
214
|
+
let p1 = P1.y + P2.x;
|
|
215
|
+
let p2 = P0.y + P1.x + select(0u, 1u, p1 < P1.y);
|
|
216
|
+
var q = p2 >> 30u;
|
|
217
|
+
var hi = (p2 << 2u) | (p1 >> 30u);
|
|
218
|
+
var lo = (p1 << 2u) | (p0 >> 30u);
|
|
219
|
+
let neg = (hi >> 31u) == 1u;
|
|
220
|
+
if (neg) { q = q + 1u; lo = ~lo + 1u; hi = ~hi + select(0u, 1u, lo == 0u); }
|
|
221
|
+
let L = pmMul32(lo, ${p.halfPiFixed}u); let H = pmMul32(hi, ${p.halfPiFixed}u);
|
|
222
|
+
let g1 = H.y + L.x;
|
|
223
|
+
let g2 = H.x + select(0u, 1u, g1 < H.y);
|
|
224
|
+
var n: u32; var top: u32; var low: u32;
|
|
225
|
+
if (g2 != 0u) {
|
|
226
|
+
n = countLeadingZeros(g2);
|
|
227
|
+
top = select((g2 << n) | (g1 >> (32u - n)), g2, n == 0u);
|
|
228
|
+
low = g1 << n;
|
|
229
|
+
} else {
|
|
230
|
+
let z = countLeadingZeros(g1);
|
|
231
|
+
n = 32u + z;
|
|
232
|
+
top = select(g1 << z, 0u, z == 32u);
|
|
233
|
+
low = 0u;
|
|
234
|
+
}
|
|
235
|
+
let hi24 = top >> 8u;
|
|
236
|
+
let next = ((top & 0xffu) << 16u) | (low >> 16u);
|
|
237
|
+
let sign = select(1.0, -1.0, neg);
|
|
238
|
+
return PmReduced(sign * ldexp(f32(hi24), -23 - i32(n)), sign * ldexp(f32(next), -47 - i32(n)), q & 3u);
|
|
239
|
+
}
|
|
240
|
+
`],
|
|
241
|
+
pmTrig: [["pmReduce", "pmBits"], `fn pmSinK(h: f32, l: f32) -> f32 {
|
|
242
|
+
let w = h * h;
|
|
243
|
+
let p = ${h("w", p.sin)};
|
|
244
|
+
return h + pmHide(l * (1.0 - 0.5 * w) + (h * w) * p);
|
|
245
|
+
}
|
|
246
|
+
fn pmCosK(h: f32, l: f32) -> f32 {
|
|
247
|
+
let w = pmHide(h * h); let hw = 0.5 * w; let t = pmFastTwoSum(1.0, -hw);
|
|
248
|
+
let ew = pmProductError(h, h, w);
|
|
249
|
+
let p = ${h("w", p.cos)};
|
|
250
|
+
return t.x + pmHide((t.y - 0.5 * ew) + ((w * w) * p - h * l));
|
|
251
|
+
}
|
|
252
|
+
fn pmReduceTrig(a: f32) -> PmReduced {
|
|
253
|
+
if (a <= 0.78125) { return PmReduced(a, 0.0, 0u); }
|
|
254
|
+
return pmReduce(a);
|
|
255
|
+
}
|
|
256
|
+
`],
|
|
257
|
+
preciseSin: [["pmTrig"], "fn preciseSin(x: f32) -> f32 {\n let a = abs(x);\n if (pmExponent(x) == 255u) { return pmNan(x); }\n if (a < 0.000244140625) { return x; }\n let r = pmReduceTrig(a);\n let s = pmSinK(r.hi, r.lo); let c = pmCosK(r.hi, r.lo);\n let v = select(select(select(-c, -s, r.q == 2u), c, r.q == 1u), s, r.q == 0u);\n return pmWithSign(v, x);\n}\n"],
|
|
258
|
+
preciseCos: [["pmTrig"], "fn preciseCos(x: f32) -> f32 {\n let a = abs(x);\n if (pmExponent(x) == 255u) { return pmNan(x); }\n if (a < 0.000244140625) { return 1.0; }\n let r = pmReduceTrig(a);\n let s = pmSinK(r.hi, r.lo); let c = pmCosK(r.hi, r.lo);\n return select(select(select(s, -c, r.q == 2u), -s, r.q == 1u), c, r.q == 0u);\n}\n"],
|
|
259
|
+
preciseTan: [["pmTrig", "preciseDiv"], "fn preciseTan(x: f32) -> f32 {\n let a = abs(x);\n if (pmExponent(x) == 255u) { return pmNan(x); }\n if (a < 0.000244140625) { return x; }\n let r = pmReduceTrig(a);\n let s = pmSinK(r.hi, r.lo); let c = pmCosK(r.hi, r.lo);\n var v: f32;\n if ((r.q & 1u) == 0u) { v = preciseDiv(s, c); } else { v = -preciseDiv(c, s); }\n return pmWithSign(v, x);\n}\n"],
|
|
260
|
+
pmAtanK: [["pmBits"], `fn pmAtanK(u: f32) -> f32 {
|
|
261
|
+
let w = u * u;
|
|
262
|
+
let p = ${h("w", p.atan)};
|
|
263
|
+
return u + pmHide((u * w) * p);
|
|
264
|
+
}
|
|
265
|
+
`],
|
|
266
|
+
preciseAtan: [["pmAtanK", "preciseDiv"], "fn preciseAtan(x: f32) -> f32 {\n let a = abs(x);\n if (pmIsNan(x)) { return x; }\n var r: f32;\n if (a <= 0.5) { r = pmAtanK(a); }\n else if (a <= 2.0) { r = PM_PIO4_HI + pmHide(pmAtanK(preciseDiv(a - 1.0, a + 1.0)) + PM_PIO4_LO); }\n else { r = PM_PIO2_HI + pmHide(PM_PIO2_LO - pmAtanK(preciseDiv(1.0, a))); }\n return pmWithSign(r, x);\n}\n"],
|
|
267
|
+
preciseAtan2: [["pmAtanK", "preciseDiv"], "fn preciseAtan2(y: f32, x: f32) -> f32 {\n if (pmIsNan(x) || pmIsNan(y)) { return pmNan(x + y); }\n var ax = abs(x); var ay = abs(y);\n var t: f32;\n if (pmExponent(ax) == 255u && pmExponent(ay) == 255u) { t = PM_PIO4_HI; }\n else {\n if (ax > 4.253529586511731e37 || ay > 4.253529586511731e37) { ax = ax * 0.25; ay = ay * 0.25; }\n let big = max(ax, ay); let small = min(ax, ay);\n if (big == 0.0) { t = 0.0; }\n else if (small <= 0.5 * big) {\n let k = pmAtanK(preciseDiv(small, big));\n t = select(k, PM_PIO2_HI + pmHide(PM_PIO2_LO - k), ay > ax);\n } else { t = PM_PIO4_HI + pmHide(pmAtanK(preciseDiv(ay - ax, ay + ax)) + PM_PIO4_LO); }\n }\n if (pmNegative(x) && (!pmIsZero(x) || pmIsZero(y))) { t = PM_PI_HI + pmHide(PM_PI_LO - t); }\n return pmWithSign(t, y);\n}\n"],
|
|
268
|
+
pmAsin: [["preciseSqrt", "pmBits"], `fn pmAsinK(x: f32) -> f32 {
|
|
269
|
+
let w = x * x;
|
|
270
|
+
let p = ${h("w", p.asin)};
|
|
271
|
+
return (x * w) * p;
|
|
272
|
+
}
|
|
273
|
+
fn pmAsinTail(a: f32) -> vec2f {
|
|
274
|
+
let z = 0.5 * (1.0 - a);
|
|
275
|
+
let s = pmSqrt2(z);
|
|
276
|
+
return vec2f(2.0 * s.x, 2.0 * (s.y + pmAsinK(s.x)));
|
|
277
|
+
}
|
|
278
|
+
`],
|
|
279
|
+
preciseAsin: [["pmAsin"], "fn preciseAsin(x: f32) -> f32 {\n let a = abs(x);\n if (pmIsNan(x) || a > 1.0) { return pmNan(x); }\n if (a < 0.000244140625) { return x; }\n var r: f32;\n if (a < 0.5) { r = a + pmAsinK(a); }\n else { let t = pmAsinTail(a); r = PM_PIO2_HI - pmHide(t.x - pmHide(PM_PIO2_LO - t.y)); }\n return pmWithSign(r, x);\n}\n"],
|
|
280
|
+
preciseAcos: [["pmAsin"], "fn preciseAcos(x: f32) -> f32 {\n let a = abs(x);\n if (pmIsNan(x) || a > 1.0) { return pmNan(x); }\n if (a < 0.5) { return PM_PIO2_HI - pmHide(x - pmHide(PM_PIO2_LO - pmAsinK(x))); }\n let t = pmAsinTail(a);\n if (pmNegative(x)) { return PM_PI_HI - pmHide(t.x - pmHide(PM_PI_LO - t.y)); }\n return t.x + t.y;\n}\n"],
|
|
281
|
+
pmExp: [["pmBits"], `fn pmExpm1P(r: f32) -> f32 { return ${h("r", p.expm1)}; }
|
|
282
|
+
fn pmExpm1K(r: f32) -> f32 { return r + pmHide((r * r) * pmExpm1P(r)); }
|
|
283
|
+
fn pmReduceLn2(x: f32) -> vec4f {
|
|
284
|
+
let k = round(x * PM_LOG2E);
|
|
285
|
+
let hi = pmHide(x - k * PM_LN2_HI);
|
|
286
|
+
let lo = -k * PM_LN2_LO;
|
|
287
|
+
return vec4f(k, hi + lo, hi, lo);
|
|
288
|
+
}
|
|
289
|
+
fn pmScale(v: f32, k: i32) -> f32 { let h = k / 2; return ldexp(pmHide(ldexp(v, k - h)), h); }
|
|
290
|
+
`],
|
|
291
|
+
preciseExp: [["pmExp"], "fn preciseExp(x: f32) -> f32 {\n if (pmIsNan(x)) { return x; }\n if (x > 88.72284) { return pmInfinity(false, x); }\n if (x < -103.97208) { return 0.0; }\n if (abs(x) < 2.9802322387695312e-8) { return 1.0 + x; }\n let k = pmReduceLn2(x);\n return pmScale(1.0 + pmHide(pmExpm1K(k.y)), i32(k.x));\n}\n"],
|
|
292
|
+
preciseExp2: [["pmExp"], "fn preciseExp2(x: f32) -> f32 {\n if (pmIsNan(x)) { return x; }\n if (x >= 128.0) { return pmInfinity(false, x); }\n if (x < -150.0) { return 0.0; }\n let k = round(x);\n return pmScale(1.0 + pmHide(pmExpm1K((x - k) * PM_LN2)), i32(k));\n}\n"],
|
|
293
|
+
preciseExpm1: [["preciseExp"], "fn preciseExpm1(x: f32) -> f32 {\n if (pmIsNan(x)) { return x; }\n if (x > 88.72284) { return pmInfinity(false, x); }\n let a = abs(x);\n if (a < 2.9802322387695312e-8) { return x; }\n if (a <= 0.3465735) { return pmExpm1K(x); }\n if (x < -17.0) { return preciseExp(x) - 1.0; }\n let k = pmReduceLn2(x);\n if (k.x > 24.0) { return preciseExp(x) - 1.0; }\n let T = (k.y * k.y) * pmExpm1P(k.y);\n let p = ldexp(1.0, i32(k.x));\n if (k.x > 0.0) { return pmHide((p - 1.0) + pmHide(p * k.z)) + pmHide(p * (k.w + T)); }\n return pmHide(p * (k.z + (k.w + T))) + (p - 1.0);\n}\n"],
|
|
294
|
+
preciseSinh: [["preciseExpm1", "preciseDiv"], `fn preciseSinh(x: f32) -> f32 {
|
|
295
|
+
let a = abs(x);
|
|
296
|
+
if (pmIsNan(x)) { return x; }
|
|
297
|
+
if (a < 0.000244140625) { return x; }
|
|
298
|
+
var r: f32;
|
|
299
|
+
if (a <= 1.0) { let w = a * a; r = a + pmHide((a * w) * ${h("w", p.sinh)}); }
|
|
300
|
+
else if (a > 88.72284) { let t = preciseExp(0.5 * a); r = pmHide(0.5 * t) * t; }
|
|
301
|
+
else if (a > 9.0) { r = 0.5 * preciseExp(a); }
|
|
302
|
+
else { let e = preciseExpm1(a); r = 0.5 * (e + preciseDiv(e, e + 1.0)); }
|
|
303
|
+
return pmWithSign(r, x);
|
|
304
|
+
}
|
|
305
|
+
`],
|
|
306
|
+
preciseCosh: [["preciseExp", "preciseDiv"], `fn preciseCosh(x: f32) -> f32 {
|
|
307
|
+
let a = abs(x);
|
|
308
|
+
if (pmIsNan(x)) { return x; }
|
|
309
|
+
if (a < 0.000244140625) { return 1.0; }
|
|
310
|
+
if (a <= 1.0) { let w = a * a; return 1.0 + pmHide((w * w) * ${h("w", p.cosh)} + 0.5 * w); }
|
|
311
|
+
if (a > 88.72284) { let t = preciseExp(0.5 * a); return pmHide(0.5 * t) * t; }
|
|
312
|
+
let t = preciseExp(a);
|
|
313
|
+
return 0.5 * (t + preciseDiv(1.0, t));
|
|
314
|
+
}
|
|
315
|
+
`],
|
|
316
|
+
preciseTanh: [["preciseExpm1", "preciseDiv"], `fn preciseTanh(x: f32) -> f32 {
|
|
317
|
+
let a = abs(x);
|
|
318
|
+
if (pmIsNan(x)) { return x; }
|
|
319
|
+
if (a < 0.000244140625) { return x; }
|
|
320
|
+
if (a > 9.1) { return pmWithSign(1.0, x); }
|
|
321
|
+
if (a <= 0.55) { let w = a * a; return pmWithSign(a + pmHide((a * w) * ${h("w", p.tanh)}), x); }
|
|
322
|
+
let e = preciseExpm1(2.0 * a);
|
|
323
|
+
return pmWithSign(preciseDiv(e, e + 2.0), x);
|
|
324
|
+
}
|
|
325
|
+
`],
|
|
326
|
+
pmLog: [["preciseDiv"], `struct PmLogK { s: f32, R: f32, hfsq: f32, t: f32 }
|
|
327
|
+
fn pmLogK(f: f32) -> PmLogK {
|
|
328
|
+
let s = preciseDiv(f, 2.0 + f);
|
|
329
|
+
let z = s * s;
|
|
330
|
+
let R = z * ${h("z", p.log)};
|
|
331
|
+
let hfsq = (0.5 * f) * f;
|
|
332
|
+
return PmLogK(s, R, hfsq, s * (hfsq + R));
|
|
333
|
+
}
|
|
334
|
+
fn pmDecompose(x: f32) -> vec2f {
|
|
335
|
+
var u = bitcast<u32>(x);
|
|
336
|
+
var e = i32(u >> 23u) - 127;
|
|
337
|
+
if (e == -127) { let z = countLeadingZeros(u) - 8u; u = u << z; e = -126 - i32(z); }
|
|
338
|
+
var m = bitcast<f32>((u & 0x7fffffu) | 0x3f800000u);
|
|
339
|
+
if (m > 1.4142135) { m = 0.5 * m; e = e + 1; }
|
|
340
|
+
return vec2f(f32(e), m - 1.0);
|
|
341
|
+
}
|
|
342
|
+
fn pmLogSpecial(x: f32) -> u32 {
|
|
343
|
+
if (pmIsNan(x) || (pmNegative(x) && !pmIsZero(x))) { return 1u; }
|
|
344
|
+
if (pmIsZero(x)) { return 2u; }
|
|
345
|
+
if (pmExponent(x) == 255u) { return 3u; }
|
|
346
|
+
return 0u;
|
|
347
|
+
}
|
|
348
|
+
fn pmLogSpecialValue(kind: u32, x: f32) -> f32 {
|
|
349
|
+
return select(select(x, pmInfinity(true, x), kind == 2u), pmNan(x), kind == 1u);
|
|
350
|
+
}
|
|
351
|
+
`],
|
|
352
|
+
preciseLog: [["pmLog"], "fn preciseLog(x: f32) -> f32 {\n let special = pmLogSpecial(x);\n if (special != 0u) { return pmLogSpecialValue(special, x); }\n let d = pmDecompose(x);\n let k = pmLogK(d.y);\n return d.x * PM_LN2_HI + pmHide(d.y - pmHide(k.hfsq - (k.t + d.x * PM_LN2_LO)));\n}\n"],
|
|
353
|
+
preciseLog2: [["pmLog"], "fn preciseLog2(x: f32) -> f32 {\n let special = pmLogSpecial(x);\n if (special != 0u) { return pmLogSpecialValue(special, x); }\n let d = pmDecompose(x);\n let k = pmLogK(d.y);\n let ah = pmHide(d.y * PM_LOG2E);\n let al = pmProductError(d.y, PM_LOG2E, ah);\n let tail = (al + d.y * PM_LOG2E_LO) - (k.hfsq - k.t) * PM_LOG2E;\n return pmHide(d.x + ah) + pmHide(tail);\n}\n"],
|
|
354
|
+
preciseLog1p: [["preciseLog"], "fn preciseLog1p(x: f32) -> f32 {\n if (pmIsNan(x) || x < -1.0) { return pmNan(x); }\n if (x == -1.0) { return pmInfinity(true, x); }\n if (pmExponent(x) == 255u) { return x; }\n let u = 1.0 + x;\n if (u == 1.0) { return x; }\n let c = select(pmFastTwoSum(x, 1.0).y, pmFastTwoSum(1.0, x).y, abs(x) <= 1.0);\n return preciseLog(u) + preciseDiv(c, u);\n}\n"],
|
|
355
|
+
precisePow: [["pmLog", "pmExp"], `fn pmLog2Pair(x: f32) -> vec2f {
|
|
356
|
+
let d = pmDecompose(x);
|
|
357
|
+
let e = d.x; let f = d.y;
|
|
358
|
+
let k = pmLogK(f);
|
|
359
|
+
let q = pmHide(f * f);
|
|
360
|
+
let hh = 0.5 * q;
|
|
361
|
+
let hl = 0.5 * pmProductError(f, f, q);
|
|
362
|
+
let d2 = pmFastTwoSum(2.0, f); let dh = d2.x; let dl = d2.y;
|
|
363
|
+
let sd = pmHide(k.s * dh);
|
|
364
|
+
let rho = pmHide(f - sd) - pmProductError(k.s, dh, sd);
|
|
365
|
+
let sl = (rho - k.s * dl) / dh;
|
|
366
|
+
let th = pmHide(k.s * hh);
|
|
367
|
+
let z = pmHide(k.s * k.s);
|
|
368
|
+
let zl = pmProductError(k.s, k.s, z) + (2.0 * k.s) * sl;
|
|
369
|
+
let w = pmFastTwoSum(${m(Math.fround(2 / 3))}, ${m(Math.fround(2 / 3 - Math.fround(2 / 3)))} + z * ${h("z", [
|
|
370
|
+
2 / 5,
|
|
371
|
+
2 / 7,
|
|
372
|
+
2 / 9,
|
|
373
|
+
2 / 11,
|
|
374
|
+
2 / 13,
|
|
375
|
+
2 / 15
|
|
376
|
+
].map((e) => Math.fround(e)))});
|
|
377
|
+
let rh = pmHide(z * w.x);
|
|
378
|
+
let rl = (pmProductError(z, w.x, rh) + z * w.y) + zl * w.x;
|
|
379
|
+
let uh = pmHide(k.s * rh);
|
|
380
|
+
let u = pmFastTwoSum(th, uh);
|
|
381
|
+
let tl = (((pmProductError(k.s, hh, th) + k.s * hl) + sl * hh) + ((pmProductError(k.s, rh, uh) + k.s * rl) + sl * rh)) + u.y;
|
|
382
|
+
let ah = pmHide(f * PM_LOG2E); let al = pmProductError(f, PM_LOG2E, ah);
|
|
383
|
+
let bh = pmHide(hh * PM_LOG2E); let bl = pmProductError(hh, PM_LOG2E, bh);
|
|
384
|
+
let ch = pmHide(u.x * PM_LOG2E); let cl = pmProductError(u.x, PM_LOG2E, ch);
|
|
385
|
+
let s1 = pmFastTwoSum(e, ah); let s2 = pmFastTwoSum(s1.x, -bh); let s3 = pmFastTwoSum(s2.x, ch);
|
|
386
|
+
let small = ((f - hh) + u.x) * PM_LOG2E_LO;
|
|
387
|
+
let tail = (((s1.y + s2.y) + s3.y) + ((al - bl) + cl)) + ((tl - hl) * PM_LOG2E + small);
|
|
388
|
+
return pmFastTwoSum(s3.x, tail);
|
|
389
|
+
}
|
|
390
|
+
fn pmIsOdd(y: f32) -> bool { return abs(y) < 16777216.0 && floor(y) == y && (i32(y) & 1) == 1; }
|
|
391
|
+
fn precisePow(x: f32, y: f32) -> f32 {
|
|
392
|
+
if (pmIsNan(y)) { return y; }
|
|
393
|
+
if (y == 0.0) { return 1.0; }
|
|
394
|
+
if (pmIsNan(x)) { return x; }
|
|
395
|
+
let ax = abs(x); let ay = abs(y);
|
|
396
|
+
if (pmExponent(ay) == 255u) {
|
|
397
|
+
if (ax == 1.0) { return pmNan(x); }
|
|
398
|
+
return select(0.0, pmInfinity(false, x), (ax > 1.0) == (y > 0.0));
|
|
399
|
+
}
|
|
400
|
+
let negative = pmNegative(x) && pmIsOdd(y);
|
|
401
|
+
if (pmExponent(ax) == 255u) { return select(select(0.0, -0.0, negative), pmInfinity(negative, x), y > 0.0); }
|
|
402
|
+
if (pmIsZero(ax)) { return select(pmInfinity(negative, x), select(0.0, -0.0, negative), y > 0.0); }
|
|
403
|
+
if (pmNegative(x) && floor(y) != y) { return pmNan(x); }
|
|
404
|
+
let L = pmLog2Pair(ax);
|
|
405
|
+
let ph = pmHide(y * L.x);
|
|
406
|
+
let pl = pmProductError(y, L.x, ph) + y * L.y;
|
|
407
|
+
if (ph > 128.0 || (ph == 128.0 && pl >= 0.0)) { return pmInfinity(negative, x); }
|
|
408
|
+
if (ph < -151.0) { return select(0.0, -0.0, negative); }
|
|
409
|
+
let k = round(ph);
|
|
410
|
+
let f = (ph - k) + pl;
|
|
411
|
+
let r = pmHide(f * PM_LN2);
|
|
412
|
+
let rl = pmProductError(f, PM_LN2, r) + f * PM_LN2_TAIL;
|
|
413
|
+
let v = pmScale(1.0 + pmHide(pmExpm1K(r) + rl), i32(k));
|
|
414
|
+
return select(v, -v, negative);
|
|
415
|
+
}
|
|
416
|
+
`]
|
|
417
|
+
}, y = /* @__PURE__ */ Object.freeze([
|
|
418
|
+
"preciseDiv",
|
|
419
|
+
"preciseSqrt",
|
|
420
|
+
"preciseSin",
|
|
421
|
+
"preciseCos",
|
|
422
|
+
"preciseTan",
|
|
423
|
+
"preciseAtan",
|
|
424
|
+
"preciseAtan2",
|
|
425
|
+
"preciseAsin",
|
|
426
|
+
"preciseAcos",
|
|
427
|
+
"preciseExp",
|
|
428
|
+
"preciseExp2",
|
|
429
|
+
"preciseExpm1",
|
|
430
|
+
"preciseSinh",
|
|
431
|
+
"preciseCosh",
|
|
432
|
+
"preciseTanh",
|
|
433
|
+
"preciseLog",
|
|
434
|
+
"preciseLog2",
|
|
435
|
+
"preciseLog1p",
|
|
436
|
+
"precisePow"
|
|
437
|
+
]);
|
|
438
|
+
function b(e) {
|
|
439
|
+
let t = [], n = /* @__PURE__ */ new Set(), r = (e) => {
|
|
440
|
+
if (n.has(e)) return;
|
|
441
|
+
let i = v()[e];
|
|
442
|
+
if (!i) throw RangeError(`Unknown precise maths function ${e}; use one of ${y.join(", ")}`);
|
|
443
|
+
n.add(e);
|
|
444
|
+
for (let e of i[0]) r(e);
|
|
445
|
+
t.push(i[1]);
|
|
446
|
+
};
|
|
447
|
+
for (let t of e) r(t);
|
|
448
|
+
return t.join("");
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/expr.ts
|
|
452
|
+
function x(t, n) {
|
|
453
|
+
let r = Math.max(t.length, n.length), i = [];
|
|
454
|
+
for (let a = 0; a < r; a++) {
|
|
455
|
+
let o = t[t.length - r + a] ?? 1, s = n[n.length - r + a] ?? 1;
|
|
456
|
+
if (o !== s && o !== 1 && s !== 1) throw e(`Shapes [${t.join(", ")}] and [${n.join(", ")}] do not broadcast; reshape one of them`, "compute");
|
|
457
|
+
i.push(o === 1 ? s : o);
|
|
458
|
+
}
|
|
459
|
+
return i;
|
|
460
|
+
}
|
|
461
|
+
var S = (e) => e.kind === "leaf" ? e.array.shape : e.kind === "scalar" ? [] : e.shape, C = /* @__PURE__ */ new Set([
|
|
462
|
+
"div",
|
|
463
|
+
"pow",
|
|
464
|
+
"sqrt",
|
|
465
|
+
"rsqrt",
|
|
466
|
+
"exp",
|
|
467
|
+
"exp2",
|
|
468
|
+
"log",
|
|
469
|
+
"log2",
|
|
470
|
+
"log1p",
|
|
471
|
+
"expm1",
|
|
472
|
+
"sin",
|
|
473
|
+
"cos",
|
|
474
|
+
"tan",
|
|
475
|
+
"asin",
|
|
476
|
+
"acos",
|
|
477
|
+
"atan",
|
|
478
|
+
"atan2",
|
|
479
|
+
"sinh",
|
|
480
|
+
"cosh",
|
|
481
|
+
"tanh",
|
|
482
|
+
"reciprocal",
|
|
483
|
+
"hypot",
|
|
484
|
+
"degrees",
|
|
485
|
+
"radians"
|
|
486
|
+
]), w = /* @__PURE__ */ new Set([
|
|
487
|
+
"bitAnd",
|
|
488
|
+
"bitOr",
|
|
489
|
+
"bitXor",
|
|
490
|
+
"bitNot",
|
|
491
|
+
"shiftLeft",
|
|
492
|
+
"shiftRight",
|
|
493
|
+
"popcount"
|
|
494
|
+
]), T = /* @__PURE__ */ new Set([
|
|
495
|
+
"lt",
|
|
496
|
+
"le",
|
|
497
|
+
"gt",
|
|
498
|
+
"ge",
|
|
499
|
+
"eq",
|
|
500
|
+
"ne",
|
|
501
|
+
"and",
|
|
502
|
+
"or",
|
|
503
|
+
"xor",
|
|
504
|
+
"not",
|
|
505
|
+
"isnan",
|
|
506
|
+
"isinf",
|
|
507
|
+
"isfinite"
|
|
508
|
+
]), E = class n {
|
|
509
|
+
get size() {
|
|
510
|
+
return this.shape.reduce((e, t) => e * t, 1);
|
|
511
|
+
}
|
|
512
|
+
get ndim() {
|
|
513
|
+
return this.shape.length;
|
|
514
|
+
}
|
|
515
|
+
op(e, r, a) {
|
|
516
|
+
let o = (r.find((e) => e instanceof n) ?? this).dtype;
|
|
517
|
+
for (let e of r) e instanceof n && (o = l(o, e.dtype));
|
|
518
|
+
for (let e of r) typeof e == "number" && (o = l(o, u(e, o)));
|
|
519
|
+
if (w.has(e) && i(o)) throw t(`${e} needs integer arrays; astype('i32') or astype('u32') first`, "compute");
|
|
520
|
+
let s = r.map((r) => {
|
|
521
|
+
if (typeof r == "number") return {
|
|
522
|
+
kind: "scalar",
|
|
523
|
+
value: r,
|
|
524
|
+
dtype: o
|
|
525
|
+
};
|
|
526
|
+
if (!(r instanceof n)) throw t(`Operand of ${e} must be a number, a GpuArray or an Expr`, "compute");
|
|
527
|
+
if (r.context !== this.context) throw t(`Operand of ${e} belongs to another compute context; create it with this context`, "compute");
|
|
528
|
+
return r.node();
|
|
529
|
+
}), c = s.map(S).reduce((e, t) => x(e, t), []), d = a ?? (T.has(e) ? "u32" : C.has(e) && !i(o) ? "f32" : o);
|
|
530
|
+
return new D(this.context, {
|
|
531
|
+
kind: "op",
|
|
532
|
+
op: e,
|
|
533
|
+
args: s,
|
|
534
|
+
dtype: d,
|
|
535
|
+
shape: c
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
add(e) {
|
|
539
|
+
return this.op("add", [this, e]);
|
|
540
|
+
}
|
|
541
|
+
sub(e) {
|
|
542
|
+
return this.op("sub", [this, e]);
|
|
543
|
+
}
|
|
544
|
+
mul(e) {
|
|
545
|
+
return this.op("mul", [this, e]);
|
|
546
|
+
}
|
|
547
|
+
div(e) {
|
|
548
|
+
return this.op("div", [this, e]);
|
|
549
|
+
}
|
|
550
|
+
floorDiv(e) {
|
|
551
|
+
return this.op("floorDiv", [this, e]);
|
|
552
|
+
}
|
|
553
|
+
mod(e) {
|
|
554
|
+
return this.op("mod", [this, e]);
|
|
555
|
+
}
|
|
556
|
+
pow(e) {
|
|
557
|
+
return this.op("pow", [this, e]);
|
|
558
|
+
}
|
|
559
|
+
minimum(e) {
|
|
560
|
+
return this.op("minimum", [this, e]);
|
|
561
|
+
}
|
|
562
|
+
maximum(e) {
|
|
563
|
+
return this.op("maximum", [this, e]);
|
|
564
|
+
}
|
|
565
|
+
clip(e, t) {
|
|
566
|
+
return this.op("clip", [
|
|
567
|
+
this,
|
|
568
|
+
e,
|
|
569
|
+
t
|
|
570
|
+
]);
|
|
571
|
+
}
|
|
572
|
+
atan2(e) {
|
|
573
|
+
return this.op("atan2", [this, e]);
|
|
574
|
+
}
|
|
575
|
+
hypot(e) {
|
|
576
|
+
return this.op("hypot", [this, e]);
|
|
577
|
+
}
|
|
578
|
+
neg() {
|
|
579
|
+
return this.op("neg", [this]);
|
|
580
|
+
}
|
|
581
|
+
abs() {
|
|
582
|
+
return this.op("abs", [this]);
|
|
583
|
+
}
|
|
584
|
+
sign() {
|
|
585
|
+
return this.op("sign", [this]);
|
|
586
|
+
}
|
|
587
|
+
square() {
|
|
588
|
+
return this.op("square", [this]);
|
|
589
|
+
}
|
|
590
|
+
sqrt() {
|
|
591
|
+
return this.op("sqrt", [this]);
|
|
592
|
+
}
|
|
593
|
+
rsqrt() {
|
|
594
|
+
return this.op("rsqrt", [this]);
|
|
595
|
+
}
|
|
596
|
+
reciprocal() {
|
|
597
|
+
return this.op("reciprocal", [this]);
|
|
598
|
+
}
|
|
599
|
+
exp() {
|
|
600
|
+
return this.op("exp", [this]);
|
|
601
|
+
}
|
|
602
|
+
exp2() {
|
|
603
|
+
return this.op("exp2", [this]);
|
|
604
|
+
}
|
|
605
|
+
expm1() {
|
|
606
|
+
return this.op("expm1", [this]);
|
|
607
|
+
}
|
|
608
|
+
log() {
|
|
609
|
+
return this.op("log", [this]);
|
|
610
|
+
}
|
|
611
|
+
log2() {
|
|
612
|
+
return this.op("log2", [this]);
|
|
613
|
+
}
|
|
614
|
+
log1p() {
|
|
615
|
+
return this.op("log1p", [this]);
|
|
616
|
+
}
|
|
617
|
+
sin() {
|
|
618
|
+
return this.op("sin", [this]);
|
|
619
|
+
}
|
|
620
|
+
cos() {
|
|
621
|
+
return this.op("cos", [this]);
|
|
622
|
+
}
|
|
623
|
+
tan() {
|
|
624
|
+
return this.op("tan", [this]);
|
|
625
|
+
}
|
|
626
|
+
asin() {
|
|
627
|
+
return this.op("asin", [this]);
|
|
628
|
+
}
|
|
629
|
+
acos() {
|
|
630
|
+
return this.op("acos", [this]);
|
|
631
|
+
}
|
|
632
|
+
atan() {
|
|
633
|
+
return this.op("atan", [this]);
|
|
634
|
+
}
|
|
635
|
+
sinh() {
|
|
636
|
+
return this.op("sinh", [this]);
|
|
637
|
+
}
|
|
638
|
+
cosh() {
|
|
639
|
+
return this.op("cosh", [this]);
|
|
640
|
+
}
|
|
641
|
+
tanh() {
|
|
642
|
+
return this.op("tanh", [this]);
|
|
643
|
+
}
|
|
644
|
+
degrees() {
|
|
645
|
+
return this.op("degrees", [this]);
|
|
646
|
+
}
|
|
647
|
+
radians() {
|
|
648
|
+
return this.op("radians", [this]);
|
|
649
|
+
}
|
|
650
|
+
floor() {
|
|
651
|
+
return this.op("floor", [this]);
|
|
652
|
+
}
|
|
653
|
+
ceil() {
|
|
654
|
+
return this.op("ceil", [this]);
|
|
655
|
+
}
|
|
656
|
+
round() {
|
|
657
|
+
return this.op("round", [this]);
|
|
658
|
+
}
|
|
659
|
+
trunc() {
|
|
660
|
+
return this.op("trunc", [this]);
|
|
661
|
+
}
|
|
662
|
+
lt(e) {
|
|
663
|
+
return this.op("lt", [this, e]);
|
|
664
|
+
}
|
|
665
|
+
le(e) {
|
|
666
|
+
return this.op("le", [this, e]);
|
|
667
|
+
}
|
|
668
|
+
gt(e) {
|
|
669
|
+
return this.op("gt", [this, e]);
|
|
670
|
+
}
|
|
671
|
+
ge(e) {
|
|
672
|
+
return this.op("ge", [this, e]);
|
|
673
|
+
}
|
|
674
|
+
eq(e) {
|
|
675
|
+
return this.op("eq", [this, e]);
|
|
676
|
+
}
|
|
677
|
+
ne(e) {
|
|
678
|
+
return this.op("ne", [this, e]);
|
|
679
|
+
}
|
|
680
|
+
and(e) {
|
|
681
|
+
return this.op("and", [this, e]);
|
|
682
|
+
}
|
|
683
|
+
or(e) {
|
|
684
|
+
return this.op("or", [this, e]);
|
|
685
|
+
}
|
|
686
|
+
xor(e) {
|
|
687
|
+
return this.op("xor", [this, e]);
|
|
688
|
+
}
|
|
689
|
+
not() {
|
|
690
|
+
return this.op("not", [this]);
|
|
691
|
+
}
|
|
692
|
+
isnan() {
|
|
693
|
+
return this.op("isnan", [this]);
|
|
694
|
+
}
|
|
695
|
+
isinf() {
|
|
696
|
+
return this.op("isinf", [this]);
|
|
697
|
+
}
|
|
698
|
+
isfinite() {
|
|
699
|
+
return this.op("isfinite", [this]);
|
|
700
|
+
}
|
|
701
|
+
bitAnd(e) {
|
|
702
|
+
return this.op("bitAnd", [this, e]);
|
|
703
|
+
}
|
|
704
|
+
bitOr(e) {
|
|
705
|
+
return this.op("bitOr", [this, e]);
|
|
706
|
+
}
|
|
707
|
+
bitXor(e) {
|
|
708
|
+
return this.op("bitXor", [this, e]);
|
|
709
|
+
}
|
|
710
|
+
bitNot() {
|
|
711
|
+
return this.op("bitNot", [this]);
|
|
712
|
+
}
|
|
713
|
+
shiftLeft(e) {
|
|
714
|
+
return this.op("shiftLeft", [this, e]);
|
|
715
|
+
}
|
|
716
|
+
shiftRight(e) {
|
|
717
|
+
return this.op("shiftRight", [this, e]);
|
|
718
|
+
}
|
|
719
|
+
popcount() {
|
|
720
|
+
return this.op("popcount", [this]);
|
|
721
|
+
}
|
|
722
|
+
bitcast(e) {
|
|
723
|
+
if (this.dtype === "f16") throw t("bitcast needs a 32-bit type; astype f16 to f32 first", "compute");
|
|
724
|
+
return this.op("bitcast", [this], e);
|
|
725
|
+
}
|
|
726
|
+
astype(e) {
|
|
727
|
+
return this.op("astype", [this], e);
|
|
728
|
+
}
|
|
729
|
+
eval() {
|
|
730
|
+
return this.context.evaluate(this);
|
|
731
|
+
}
|
|
732
|
+
async read(e) {
|
|
733
|
+
let t = this.eval();
|
|
734
|
+
try {
|
|
735
|
+
return await t.read(e);
|
|
736
|
+
} finally {
|
|
737
|
+
t.dispose();
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
async item(t) {
|
|
741
|
+
if (this.size !== 1) throw e(`item() needs exactly one element, the shape is [${this.shape.join(", ")}]; reduce it first`, "compute");
|
|
742
|
+
return (await this.read(t))[0];
|
|
743
|
+
}
|
|
744
|
+
sum(e) {
|
|
745
|
+
return this.context.sum(this, e);
|
|
746
|
+
}
|
|
747
|
+
prod(e) {
|
|
748
|
+
return this.context.prod(this, e);
|
|
749
|
+
}
|
|
750
|
+
min(e) {
|
|
751
|
+
return this.context.min(this, e);
|
|
752
|
+
}
|
|
753
|
+
max(e) {
|
|
754
|
+
return this.context.max(this, e);
|
|
755
|
+
}
|
|
756
|
+
mean(e) {
|
|
757
|
+
return this.context.mean(this, e);
|
|
758
|
+
}
|
|
759
|
+
var(e) {
|
|
760
|
+
return this.context.var(this, e);
|
|
761
|
+
}
|
|
762
|
+
std(e) {
|
|
763
|
+
return this.context.std(this, e);
|
|
764
|
+
}
|
|
765
|
+
argmin(e) {
|
|
766
|
+
return this.context.argmin(this, e);
|
|
767
|
+
}
|
|
768
|
+
argmax(e) {
|
|
769
|
+
return this.context.argmax(this, e);
|
|
770
|
+
}
|
|
771
|
+
all(e) {
|
|
772
|
+
return this.context.all(this, e);
|
|
773
|
+
}
|
|
774
|
+
any(e) {
|
|
775
|
+
return this.context.any(this, e);
|
|
776
|
+
}
|
|
777
|
+
}, D = class extends E {
|
|
778
|
+
#e;
|
|
779
|
+
constructor(e, t) {
|
|
780
|
+
super(), this.context = e, this.#e = t;
|
|
781
|
+
}
|
|
782
|
+
get dtype() {
|
|
783
|
+
return this.#e.dtype;
|
|
784
|
+
}
|
|
785
|
+
get shape() {
|
|
786
|
+
return this.#e.shape;
|
|
787
|
+
}
|
|
788
|
+
node() {
|
|
789
|
+
return this.#e;
|
|
790
|
+
}
|
|
791
|
+
}, O = "xyzw", k = (e) => {
|
|
792
|
+
let t = Array(e.length), n = 1;
|
|
793
|
+
for (let r = e.length - 1; r >= 0; r--) t[r] = n, n *= e[r];
|
|
794
|
+
return t;
|
|
795
|
+
}, A = {
|
|
796
|
+
pow: "precisePow",
|
|
797
|
+
atan2: "preciseAtan2",
|
|
798
|
+
sqrt: "preciseSqrt",
|
|
799
|
+
exp: "preciseExp",
|
|
800
|
+
exp2: "preciseExp2",
|
|
801
|
+
expm1: "preciseExpm1",
|
|
802
|
+
log: "preciseLog",
|
|
803
|
+
log2: "preciseLog2",
|
|
804
|
+
log1p: "preciseLog1p",
|
|
805
|
+
sin: "preciseSin",
|
|
806
|
+
cos: "preciseCos",
|
|
807
|
+
tan: "preciseTan",
|
|
808
|
+
asin: "preciseAsin",
|
|
809
|
+
acos: "preciseAcos",
|
|
810
|
+
atan: "preciseAtan",
|
|
811
|
+
sinh: "preciseSinh",
|
|
812
|
+
cosh: "preciseCosh",
|
|
813
|
+
tanh: "preciseTanh"
|
|
814
|
+
};
|
|
815
|
+
function j(e, n, r, a, o) {
|
|
816
|
+
let [s, c, l] = n, u = `${r}(0)`, d = (e) => `select(0u, 1u, ${e})`, f = (e) => i(r) ? e : `f32(${e})`, p = o && A[e];
|
|
817
|
+
if (p) {
|
|
818
|
+
o.add(p);
|
|
819
|
+
let t = (e) => r === "f32" ? e : `f32(${e})`, i = `${p}(${n.slice(0, e === "pow" || e === "atan2" ? 2 : 1).map((e) => `operandF32(${t(e)})`).join(", ")})`;
|
|
820
|
+
return a === "f32" ? i : `${a}(${i})`;
|
|
821
|
+
}
|
|
822
|
+
switch (e) {
|
|
823
|
+
case "add": return `(${s} + ${c})`;
|
|
824
|
+
case "sub": return `(${s} - ${c})`;
|
|
825
|
+
case "mul": return `(${s} * ${c})`;
|
|
826
|
+
case "div": return `(${f(s)} / ${f(c)})`;
|
|
827
|
+
case "floorDiv": return i(r) ? `floor(${s} / ${c})` : r === "u32" ? `select(0u, ${s} / ${c}, ${c} != 0u)` : `select(0i, (${s} / ${c}) - select(0i, 1i, (${s} % ${c} != 0i) && ((${s} < 0i) != (${c} < 0i))), ${c} != 0i)`;
|
|
828
|
+
case "mod": return i(r) ? `(${s} - ${c} * floor(${s} / ${c}))` : r === "u32" ? `select(0u, ${s} % ${c}, ${c} != 0u)` : `select(0i, ((${s} % ${c}) + ${c}) % ${c}, ${c} != 0i)`;
|
|
829
|
+
case "pow": return `pow(${f(s)}, ${f(c)})`;
|
|
830
|
+
case "minimum": return `min(${s}, ${c})`;
|
|
831
|
+
case "maximum": return `max(${s}, ${c})`;
|
|
832
|
+
case "clip": return `clamp(${s}, ${c}, ${l})`;
|
|
833
|
+
case "atan2": return `atan2(${f(s)}, ${f(c)})`;
|
|
834
|
+
case "hypot": return `length(vec2(${f(s)}, ${f(c)}))`;
|
|
835
|
+
case "neg": return r === "u32" ? `(0u - ${s})` : `(-${s})`;
|
|
836
|
+
case "abs": return `abs(${s})`;
|
|
837
|
+
case "sign": return r === "u32" ? `select(0u, 1u, ${s} > 0u)` : `sign(${s})`;
|
|
838
|
+
case "square": return `(${s} * ${s})`;
|
|
839
|
+
case "sqrt":
|
|
840
|
+
case "exp":
|
|
841
|
+
case "exp2":
|
|
842
|
+
case "log":
|
|
843
|
+
case "log2":
|
|
844
|
+
case "sin":
|
|
845
|
+
case "cos":
|
|
846
|
+
case "tan":
|
|
847
|
+
case "asin":
|
|
848
|
+
case "acos":
|
|
849
|
+
case "atan":
|
|
850
|
+
case "sinh":
|
|
851
|
+
case "cosh":
|
|
852
|
+
case "tanh":
|
|
853
|
+
case "degrees":
|
|
854
|
+
case "radians": return `${e}(${f(s)})`;
|
|
855
|
+
case "rsqrt": return `inverseSqrt(${f(s)})`;
|
|
856
|
+
case "reciprocal": return `(1.0 / ${f(s)})`;
|
|
857
|
+
case "log1p": {
|
|
858
|
+
let e = f(s), t = `(1.0 + ${e})`, n = `bitcast<u32>(${t})`, r = `(ldexp(f32(i32((${n} & 0x7fffffu) | 0x800000u)), i32((${n} >> 23u) & 0xffu) - 150i) - 1.0)`;
|
|
859
|
+
return `select(${e} * log(${t}) / ${r}, ${e}, ${r} == 0.0)`;
|
|
860
|
+
}
|
|
861
|
+
case "expm1": {
|
|
862
|
+
let e = f(s), t = `exp(${e})`;
|
|
863
|
+
return `select(select(select((${t} - 1.0) * ${e} / log(${t}), ${e}, ${t} == 1.0), -1.0, ${e} < -80.0), ${t}, ${e} > 80.0)`;
|
|
864
|
+
}
|
|
865
|
+
case "floor":
|
|
866
|
+
case "ceil":
|
|
867
|
+
case "round":
|
|
868
|
+
case "trunc": return i(r) ? `${e}(${s})` : s;
|
|
869
|
+
case "lt": return d(`${s} < ${c}`);
|
|
870
|
+
case "le": return d(`${s} <= ${c}`);
|
|
871
|
+
case "gt": return d(`${s} > ${c}`);
|
|
872
|
+
case "ge": return d(`${s} >= ${c}`);
|
|
873
|
+
case "eq": return d(`${s} == ${c}`);
|
|
874
|
+
case "ne": return d(`${s} != ${c}`);
|
|
875
|
+
case "and": return d(`(${s} != ${u}) && (${c} != ${u})`);
|
|
876
|
+
case "or": return d(`(${s} != ${u}) || (${c} != ${u})`);
|
|
877
|
+
case "xor": return d(`(${s} != ${u}) != (${c} != ${u})`);
|
|
878
|
+
case "not": return d(`${s} == ${u}`);
|
|
879
|
+
case "isnan":
|
|
880
|
+
case "isinf":
|
|
881
|
+
case "isfinite": {
|
|
882
|
+
if (!i(r)) return e === "isfinite" ? "1u" : "0u";
|
|
883
|
+
let t = r === "f16" ? `(bitcast<u32>(f32(${s})) & 0x7fffffffu)` : `(bitcast<u32>(${s}) & 0x7fffffffu)`;
|
|
884
|
+
return d(e === "isnan" ? `${t} > 0x7f800000u` : e === "isinf" ? `${t} == 0x7f800000u` : `${t} < 0x7f800000u`);
|
|
885
|
+
}
|
|
886
|
+
case "bitAnd":
|
|
887
|
+
case "bitOr":
|
|
888
|
+
case "bitXor":
|
|
889
|
+
case "bitNot":
|
|
890
|
+
case "shiftLeft":
|
|
891
|
+
case "shiftRight":
|
|
892
|
+
case "popcount":
|
|
893
|
+
if (i(r)) throw t(`${e} needs integer arrays; astype('i32') or astype('u32') first`, "compute");
|
|
894
|
+
return e === "bitAnd" ? `(${s} & ${c})` : e === "bitOr" ? `(${s} | ${c})` : e === "bitXor" ? `(${s} ^ ${c})` : e === "bitNot" ? `(~${s})` : e === "shiftLeft" ? `(${s} << (u32(${c}) & 31u))` : e === "shiftRight" ? `(${s} >> (u32(${c}) & 31u))` : `${r}(countOneBits(${s}))`;
|
|
895
|
+
case "bitcast": return `bitcast<${a}>(${s})`;
|
|
896
|
+
case "astype": return `${a}(${s})`;
|
|
897
|
+
case "where": return `select(${l}, ${c}, ${s} != ${u})`;
|
|
898
|
+
default: throw t(`Unknown element-wise operation ${e}`, "compute");
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function M(t, n, r, i) {
|
|
902
|
+
let a = t.node(), o = t.shape, s = (e, t = /* @__PURE__ */ new Set()) => {
|
|
903
|
+
if (e.kind === "leaf") t.add(e.array.storage);
|
|
904
|
+
else if (e.kind === "op") for (let n of e.args) s(n, t);
|
|
905
|
+
return t;
|
|
906
|
+
}, c = (n) => {
|
|
907
|
+
if (n.kind !== "op" || s(n).size <= r) return n;
|
|
908
|
+
let a = n.args.map(c), o = {
|
|
909
|
+
...n,
|
|
910
|
+
args: a
|
|
911
|
+
};
|
|
912
|
+
for (; s(o).size > r;) {
|
|
913
|
+
let n = o.args.map((e, t) => [t, e.kind === "op" ? s(e).size : 0]).sort((e, t) => t[1] - e[1])[0];
|
|
914
|
+
if (!n || n[1] === 0) throw e(`Expression reads more than ${r} buffers in one operation; evaluate parts of it first`, "compute");
|
|
915
|
+
let a = o.args[n[0]], c = t.context.evaluate(new D(t.context, a));
|
|
916
|
+
i.push(c);
|
|
917
|
+
let l = [...o.args];
|
|
918
|
+
l[n[0]] = {
|
|
919
|
+
kind: "leaf",
|
|
920
|
+
array: c
|
|
921
|
+
}, o = {
|
|
922
|
+
...o,
|
|
923
|
+
args: l
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
return o;
|
|
927
|
+
};
|
|
928
|
+
a = c(a);
|
|
929
|
+
let u = /* @__PURE__ */ new Map(), p = {}, m = [], h = [], g = /* @__PURE__ */ new Map(), _ = "", v = n, y = !1, x = t.context.fastMath ? void 0 : /* @__PURE__ */ new Set(), S = k(o), C = (e, t, n) => t === n ? e : `${n}(${e})`, w = (e) => {
|
|
930
|
+
let n = g.get(e);
|
|
931
|
+
if (n !== void 0) return n;
|
|
932
|
+
let r;
|
|
933
|
+
if (e.kind === "leaf") {
|
|
934
|
+
let n = e.array, i = u.get(n.storage);
|
|
935
|
+
i || (i = `src${u.size}`, u.set(n.storage, i), _ += `@group(0) @binding(${v++}) var<storage, read> ${i}: array<${n.dtype}>;
|
|
936
|
+
`, n.check(t.context), p[i] = { buffer: n.storage.buffer });
|
|
937
|
+
let a = o.length, s = n.contiguous && n.shape.length === a && n.shape.every((e, t) => e === o[t]), c;
|
|
938
|
+
if (s) c = n.offset ? `(i + ${n.offset}u)` : "i";
|
|
939
|
+
else {
|
|
940
|
+
let e = n.strides.some((e) => e < 0), t = e ? "i" : "u", r = n.offset ? [`${n.offset}${t}`] : [];
|
|
941
|
+
for (let i = 0; i < n.shape.length; i++) {
|
|
942
|
+
let s = a - n.shape.length + i;
|
|
943
|
+
if (n.shape[i] === 1 || n.strides[i] === 0) continue;
|
|
944
|
+
let c = s === 0 ? `(i / ${S[0]}u)` : `((i / ${S[s]}u) % ${o[s]}u)`;
|
|
945
|
+
e && (c = `i32${c}`), r.push(n.strides[i] === 1 ? c : `${c} * ${n.strides[i]}${t}`);
|
|
946
|
+
}
|
|
947
|
+
c = r.length ? e ? `u32(${r.join(" + ")})` : r.join(" + ") : "0u";
|
|
948
|
+
}
|
|
949
|
+
r = `${i}[${c}]`;
|
|
950
|
+
} else if (e.kind === "scalar") {
|
|
951
|
+
let t = m.length;
|
|
952
|
+
m.push(d(e.value, e.dtype)), r = f(`fused[${t >> 2}].${O[t & 3]}`, e.dtype);
|
|
953
|
+
} else if (e.kind === "index") r = "i";
|
|
954
|
+
else if (e.op === "where") {
|
|
955
|
+
let [t, n, i] = e.args;
|
|
956
|
+
r = `select(${C(w(i), N(i), e.dtype)}, ${C(w(n), N(n), e.dtype)}, ${w(t)} != ${N(t)}(0))`;
|
|
957
|
+
} else {
|
|
958
|
+
let t = e.args.map(N).reduce(l);
|
|
959
|
+
r = j(e.op, e.args.map((e) => C(w(e), N(e), t)), t, e.dtype, x);
|
|
960
|
+
}
|
|
961
|
+
let i = N(e);
|
|
962
|
+
i === "f16" && (y = !0);
|
|
963
|
+
let a = `v${g.size}`;
|
|
964
|
+
return h.push(`let ${a}: ${i} = ${r};`), g.set(e, a), a;
|
|
965
|
+
}, T = w(a), E = Math.max(1, Math.ceil(m.length / 4)), A = new Uint32Array(E * 4);
|
|
966
|
+
A.set(m), _ += `@group(0) @binding(${v++}) var<uniform> fused: array<vec4u, ${E}>;\n`, p.fused = A;
|
|
967
|
+
let M = `${x?.size ? `${b([...x])}
|
|
968
|
+
fn operandF32(v: f32) -> f32 {
|
|
969
|
+
if ((bitcast<u32>(v) & 0x7f800000u) == 0x7f800000u) { return v; }
|
|
970
|
+
return pmHide(v);
|
|
971
|
+
}
|
|
972
|
+
` : ""}fn value(i: u32) -> ${t.dtype} {\n ${h.join("\n ")}\n return ${T};\n}`;
|
|
973
|
+
return {
|
|
974
|
+
enables: y ? "enable f16;\n" : "",
|
|
975
|
+
declarations: _,
|
|
976
|
+
fn: M,
|
|
977
|
+
resources: p,
|
|
978
|
+
next: v,
|
|
979
|
+
dtype: t.dtype,
|
|
980
|
+
shape: o,
|
|
981
|
+
key: `${_}\n${M}`
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
var N = (e) => e.kind === "leaf" ? e.array.dtype : e.dtype;
|
|
985
|
+
function P(e, n, r) {
|
|
986
|
+
if (!(e instanceof E)) throw t("where needs a condition array or expression", "compute");
|
|
987
|
+
let i = (e, t) => typeof e == "number" ? u(e, t instanceof E ? t.dtype : "f32") : e.dtype, a = l(i(n, r), i(r, n));
|
|
988
|
+
return e.op("where", [
|
|
989
|
+
e,
|
|
990
|
+
n,
|
|
991
|
+
r
|
|
992
|
+
], a);
|
|
993
|
+
}
|
|
994
|
+
//#endregion
|
|
995
|
+
export { P as a, o as c, s as d, f, c as h, M as i, d as l, l as m, E as n, b as o, i as p, x as r, n as s, D as t, r as u };
|