@margoengine/compute 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,23 @@
1
1
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
2
- import { a as r, d as i, f as a, i as o, l as s, n as c, p as l, s as u, t as d, u as f } from "./expr-DwFen60A.js";
3
- import { n as p, r as m, t as h } from "./array-DbI848Wf.js";
2
+ import { a as r, d as i, f as a, i as o, l as s, n as c, p as l, s as u, t as d, u as f } from "./expr-t3jm8acM.js";
3
+ import { n as p, r as m, t as h } from "./array-C29noZq7.js";
4
4
  function g(e) {
5
5
  return e?.adapterInfo?.vendor === "margo-webgl2" ? "webgl2" : "native";
6
6
  }
7
7
  function _(e, t) {
8
8
  return g(e) === "webgl2" ? t() : void 0;
9
9
  }
10
+ function v(e) {
11
+ return e ? e.then(() => void 0, () => void 0) : Promise.resolve();
12
+ }
10
13
  //#endregion
11
14
  //#region ../shared/f16.js
12
- var v = /* @__PURE__ */ new Float32Array(1), y = new Uint32Array(v.buffer);
13
- function b(e) {
14
- v[0] = e;
15
- let t = Math.abs(e) - Math.abs(v[0]);
16
- (t > 0 || t < 0) && !(y[0] & 1) && (y[0] += t > 0 ? 1 : -1);
17
- let n = y[0], r = n >>> 16 & 32768, i = n >>> 23 & 255, a = n & 8388607;
15
+ var y = /* @__PURE__ */ new Float32Array(1), b = new Uint32Array(y.buffer);
16
+ function x(e) {
17
+ y[0] = e;
18
+ let t = Math.abs(e) - Math.abs(y[0]);
19
+ (t > 0 || t < 0) && !(b[0] & 1) && (b[0] += t > 0 ? 1 : -1);
20
+ let n = b[0], r = n >>> 16 & 32768, i = n >>> 23 & 255, a = n & 8388607;
18
21
  if (i === 255) return r | 31744 | (a ? 512 : 0);
19
22
  let o = i - 127 + 15;
20
23
  if (o >= 31) return r | 31744;
@@ -28,19 +31,19 @@ function b(e) {
28
31
  }
29
32
  //#endregion
30
33
  //#region src/wgsl.ts
31
- var x = /* @__PURE__ */ new Set([
34
+ var S = /* @__PURE__ */ new Set([
32
35
  "f32",
33
36
  "i32",
34
37
  "u32",
35
38
  "f16",
36
39
  "bool"
37
- ]), S = {
40
+ ]), C = {
38
41
  f: "f32",
39
42
  i: "i32",
40
43
  u: "u32",
41
44
  h: "f16"
42
45
  };
43
- function C(e) {
46
+ function w(e) {
44
47
  let t = "", n = 0;
45
48
  for (let r = 0; r < e.length; r++) {
46
49
  let i = e[r], a = e[r + 1];
@@ -51,7 +54,7 @@ function C(e) {
51
54
  }
52
55
  return t;
53
56
  }
54
- function w(e) {
57
+ function T(e) {
55
58
  let t = [], n = 0, r = 0;
56
59
  for (let i = 0; i < e.length; i++) {
57
60
  let a = e[i];
@@ -60,14 +63,14 @@ function w(e) {
60
63
  let i = e.slice(r).trim();
61
64
  return i && t.push(i), t;
62
65
  }
63
- var T = (e, t) => Math.ceil(t / e) * e;
64
- function E(e) {
66
+ var E = (e, t) => Math.ceil(t / e) * e;
67
+ function D(e) {
65
68
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
66
69
  for (let n of e.matchAll(/\balias\s+(\w+)\s*=\s*([^;]+);/g)) t.set(n[1], n[2].trim());
67
70
  for (let t of e.matchAll(/\b(?:const|override)\s+(\w+)\s*(?::\s*\w+\s*)?=\s*([^;]+);/g)) r.set(t[1], t[2].trim());
68
71
  for (let t of e.matchAll(/\bstruct\s+(\w+)\s*\{([^}]*)\}/g)) {
69
72
  let e = [];
70
- for (let n of w(t[2])) {
73
+ for (let n of T(t[2])) {
71
74
  let t = /^((?:@\w+(?:\([^)]*\))?\s*)*)(\w+)\s*:\s*(.+)$/s.exec(n);
72
75
  if (!t) continue;
73
76
  let r = t[1], i = /@align\(\s*(\d+)\s*\)/.exec(r), a = /@size\(\s*(\d+)\s*\)/.exec(r);
@@ -86,29 +89,29 @@ function E(e) {
86
89
  constants: r
87
90
  };
88
91
  }
89
- function D(e, t, n = /* @__PURE__ */ new Set()) {
92
+ function O(e, t, n = /* @__PURE__ */ new Set()) {
90
93
  let r = e.trim(), i = /^(0[xX][0-9a-fA-F]+|\d+)[iu]?$/.exec(r);
91
94
  if (i) return Number(i[1]);
92
- if (/^\w+$/.test(r) && t.constants.has(r) && !n.has(r)) return n.add(r), D(t.constants.get(r), t, n);
95
+ if (/^\w+$/.test(r) && t.constants.has(r) && !n.has(r)) return n.add(r), O(t.constants.get(r), t, n);
93
96
  }
94
- function O(e) {
97
+ function k(e) {
95
98
  let t = e.trim(), n = t.indexOf("<");
96
99
  return n < 0 ? {
97
100
  base: t,
98
101
  args: []
99
102
  } : {
100
103
  base: t.slice(0, n).trim(),
101
- args: w(t.slice(n + 1, t.lastIndexOf(">")))
104
+ args: T(t.slice(n + 1, t.lastIndexOf(">")))
102
105
  };
103
106
  }
104
- function k(e, t, n = 0) {
107
+ function A(e, t, n = 0) {
105
108
  if (n > 32) return;
106
109
  let r = e.trim();
107
110
  for (; t.aliases.has(r);) r = t.aliases.get(r);
108
111
  let i = /^(vec[234]|mat[234]x[234])([fiuh])$/.exec(r);
109
- i && (r = `${i[1]}<${S[i[2]]}>`);
110
- let { base: a, args: o } = O(r);
111
- if (x.has(a)) {
112
+ i && (r = `${i[1]}<${C[i[2]]}>`);
113
+ let { base: a, args: o } = k(r);
114
+ if (S.has(a)) {
112
115
  if (a === "bool") return;
113
116
  let e = a === "f16" ? 2 : 4;
114
117
  return {
@@ -120,7 +123,7 @@ function k(e, t, n = 0) {
120
123
  };
121
124
  }
122
125
  if (a === "atomic") {
123
- let e = k(o[0] ?? "", t, n + 1);
126
+ let e = A(o[0] ?? "", t, n + 1);
124
127
  return e && {
125
128
  ...e,
126
129
  name: r,
@@ -129,7 +132,7 @@ function k(e, t, n = 0) {
129
132
  }
130
133
  let s = /^vec([234])$/.exec(a);
131
134
  if (s) {
132
- let e = Number(s[1]), i = k(o[0] ?? "", t, n + 1);
135
+ let e = Number(s[1]), i = A(o[0] ?? "", t, n + 1);
133
136
  if (!i || i.kind !== "scalar") return;
134
137
  let a = i.size;
135
138
  return {
@@ -143,9 +146,9 @@ function k(e, t, n = 0) {
143
146
  }
144
147
  let c = /^mat([234])x([234])$/.exec(a);
145
148
  if (c) {
146
- let e = Number(c[1]), i = Number(c[2]), a = k(`vec${i}<${o[0]}>`, t, n + 1);
149
+ let e = Number(c[1]), i = Number(c[2]), a = A(`vec${i}<${o[0]}>`, t, n + 1);
147
150
  if (!a) return;
148
- let s = T(a.align, a.size);
151
+ let s = E(a.align, a.size);
149
152
  return {
150
153
  name: r,
151
154
  kind: "matrix",
@@ -158,9 +161,9 @@ function k(e, t, n = 0) {
158
161
  };
159
162
  }
160
163
  if (a === "array") {
161
- let e = k(o[0] ?? "", t, n + 1);
164
+ let e = A(o[0] ?? "", t, n + 1);
162
165
  if (!e) return;
163
- let i = T(e.align, e.size), a = o[1] === void 0 ? 0 : D(o[1], t);
166
+ let i = E(e.align, e.size), a = o[1] === void 0 ? 0 : O(o[1], t);
164
167
  return a === void 0 ? void 0 : {
165
168
  name: r,
166
169
  kind: "array",
@@ -175,10 +178,10 @@ function k(e, t, n = 0) {
175
178
  if (l) {
176
179
  let e = 0, r = 1, i = [];
177
180
  for (let a of l) {
178
- let o = k(a.type, t, n + 1);
181
+ let o = A(a.type, t, n + 1);
179
182
  if (!o) return;
180
183
  let s = a.align ?? o.align;
181
- e = T(s, e), i.push({
184
+ e = E(s, e), i.push({
182
185
  name: a.name,
183
186
  offset: e,
184
187
  layout: o
@@ -188,25 +191,25 @@ function k(e, t, n = 0) {
188
191
  name: a,
189
192
  kind: "struct",
190
193
  align: r,
191
- size: T(r, e),
194
+ size: E(r, e),
192
195
  members: i
193
196
  };
194
197
  }
195
198
  }
196
- var A = {
199
+ var j = {
197
200
  "1d": "1d",
198
201
  "2d": "2d",
199
202
  "2d_array": "2d-array",
200
203
  "3d": "3d",
201
204
  cube: "cube",
202
205
  cube_array: "cube-array"
203
- }, j = {
206
+ }, ee = {
204
207
  f32: "float",
205
208
  i32: "sint",
206
209
  u32: "uint"
207
210
  };
208
- function ee(e) {
209
- let { base: t, args: n } = O(e), r = /^texture_storage_(1d|2d|2d_array|3d)$/.exec(t);
211
+ function te(e) {
212
+ let { base: t, args: n } = k(e), r = /^texture_storage_(1d|2d|2d_array|3d)$/.exec(t);
210
213
  if (r) {
211
214
  let e = {
212
215
  read: "read-only",
@@ -214,30 +217,30 @@ function ee(e) {
214
217
  read_write: "read-write"
215
218
  }[n[1] ?? "write"];
216
219
  return {
217
- viewDimension: A[r[1]],
220
+ viewDimension: j[r[1]],
218
221
  format: n[0],
219
222
  access: e
220
223
  };
221
224
  }
222
225
  let i = /^texture_depth_(multisampled_)?(2d|2d_array|cube|cube_array)$/.exec(t);
223
226
  if (i) return {
224
- viewDimension: A[i[2]],
227
+ viewDimension: j[i[2]],
225
228
  sampleType: "depth",
226
229
  multisampled: !!i[1]
227
230
  };
228
231
  let a = /^texture_(multisampled_)?(1d|2d|2d_array|3d|cube|cube_array)$/.exec(t);
229
232
  if (a) return {
230
- viewDimension: A[a[2]],
231
- sampleType: j[n[0] ?? "f32"] ?? "float",
233
+ viewDimension: j[a[2]],
234
+ sampleType: ee[n[0] ?? "f32"] ?? "float",
232
235
  multisampled: !!a[1]
233
236
  };
234
237
  }
235
- function te(e) {
236
- let n = C(e), r = E(n), i = [], a = [];
238
+ function ne(e) {
239
+ let n = w(e), r = D(n), i = [], a = [];
237
240
  for (let e of n.matchAll(/((?:@\w+\s*(?:\([^)]*\))?\s*)+)var\s*(?:<\s*([\w\s,]+)\s*>)?\s*(\w+)\s*:\s*([^;=]+?)\s*;/g)) {
238
241
  let n = e[1], a = /@group\(\s*([^)]+)\)/.exec(n), o = /@binding\(\s*([^)]+)\)/.exec(n);
239
242
  if (!a || !o) continue;
240
- let s = D(a[1], r), c = D(o[1], r);
243
+ let s = O(a[1], r), c = O(o[1], r);
241
244
  if (s === void 0 || c === void 0) throw t(`Kernel binding ${e[3]} has a group or binding that is not a constant integer`, "compute");
242
245
  let l = (e[2] ?? "").split(",").map((e) => e.trim()), u = e[3], d = e[4].trim();
243
246
  if (l[0] === "uniform") i.push({
@@ -246,7 +249,7 @@ function te(e) {
246
249
  binding: c,
247
250
  resource: "uniform",
248
251
  type: d,
249
- layout: k(d, r)
252
+ layout: A(d, r)
250
253
  });
251
254
  else if (l[0] === "storage") i.push({
252
255
  name: u,
@@ -254,7 +257,7 @@ function te(e) {
254
257
  binding: c,
255
258
  resource: l[1] === "read_write" ? "storage" : "read-only-storage",
256
259
  type: d,
257
- layout: k(d, r)
260
+ layout: A(d, r)
258
261
  });
259
262
  else if (/^sampler(_comparison)?$/.test(d)) i.push({
260
263
  name: u,
@@ -265,7 +268,7 @@ function te(e) {
265
268
  sampler: d === "sampler" ? "filtering" : "comparison"
266
269
  });
267
270
  else {
268
- let e = ee(d);
271
+ let e = te(d);
269
272
  if (!e) throw t(`Kernel binding ${u} has a type the kernel cannot bind: ${d}`, "compute");
270
273
  i.push({
271
274
  name: u,
@@ -280,7 +283,7 @@ function te(e) {
280
283
  for (let e of n.matchAll(/@compute\s*((?:@\w+\s*(?:\([^)]*\))?\s*)*)fn\s+(\w+)|((?:@\w+\s*(?:\([^)]*\))?\s*)+)fn\s+(\w+)/g)) {
281
284
  let n = e[1] ?? e[3] ?? "", i = e[2] ?? e[4];
282
285
  if (e[3] !== void 0 && !/@compute\b/.test(n)) continue;
283
- let o = /@workgroup_size\(([^)]*)\)/.exec(n), s = o ? w(o[1]).map((e) => D(e, r)) : [1];
286
+ let o = /@workgroup_size\(([^)]*)\)/.exec(n), s = o ? T(o[1]).map((e) => O(e, r)) : [1];
284
287
  if (s.some((e) => e === void 0)) throw t(`Kernel entry point ${i} has a workgroup size that is not a constant integer`, "compute");
285
288
  a.push({
286
289
  name: i,
@@ -301,7 +304,7 @@ function M(n, r, i, a, o) {
301
304
  let s = typeof a == "boolean" ? Number(a) : a;
302
305
  if (typeof s != "number") throw t(`Uniform ${o} needs a number, got ${typeof a}`, "compute");
303
306
  if (i === "f32") n.setFloat32(r, s, !0);
304
- else if (i === "f16") n.setUint16(r, b(s), !0);
307
+ else if (i === "f16") n.setUint16(r, x(s), !0);
305
308
  else {
306
309
  let [t, a] = i === "i32" ? [-2147483648, 2147483647] : [0, 4294967295];
307
310
  if (!Number.isInteger(s) || s < t || s > a) throw e(`Uniform ${o} needs an integer from ${t} to ${a}, got ${s}`, "compute");
@@ -343,11 +346,11 @@ function M(n, r, i, a, o) {
343
346
  }
344
347
  }
345
348
  }
346
- function ne(e, t = 0) {
349
+ function re(e, t = 0) {
347
350
  return e.kind === "array" && e.count === 0 ? e.stride * t : e.size;
348
351
  }
349
- function re(e, t, n = "value") {
350
- let r = e.kind === "array" && e.count === 0 ? t.length : 0, i = new Uint8Array(T(16, Math.max(ne(e, r), 4)));
352
+ function ie(e, t, n = "value") {
353
+ let r = e.kind === "array" && e.count === 0 ? t.length : 0, i = new Uint8Array(E(16, Math.max(re(e, r), 4)));
351
354
  return M(new DataView(i.buffer), 0, e, t, n), i;
352
355
  }
353
356
  var N = 1024, P = "fn blockIndex(wid: vec3u, nwg: vec3u) -> u32 { return wid.x + wid.y * nwg.x; }", F = "struct Params { n: u32, inf: u32, a: u32, b: u32 }";
@@ -376,7 +379,7 @@ function I(e, n) {
376
379
  };
377
380
  }
378
381
  }
379
- function ie(e, t, n, r = 256) {
382
+ function ae(e, t, n, r = 256) {
380
383
  let i = e.dtype, a = N / r;
381
384
  return `${e.enables}${e.declarations}${F}
382
385
  ${P}
@@ -424,7 +427,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
424
427
  if (lid == ${r - 1}u) { sums[g] = partial[${r - 1}]; }
425
428
  }`;
426
429
  }
427
- function ae(e, t) {
430
+ function oe(e, t) {
428
431
  return `${e === "f16" ? "enable f16;\n" : ""}${F}
429
432
  ${P}
430
433
  @group(0) @binding(0) var<storage, read_write> data: array<${e}>;
@@ -442,7 +445,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
442
445
  }
443
446
  }`;
444
447
  }
445
- function oe(e, t, n, r) {
448
+ function se(e, t, n, r) {
446
449
  let i = e.dtype, a = e.next;
447
450
  return `${e.enables}${e.declarations}${F}
448
451
  ${P}
@@ -507,7 +510,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
507
510
  if (lid == 255u) { sumFlags[g] = partialFlags[255]; sumValues[g] = partialValues[255]; }
508
511
  }`;
509
512
  }
510
- function se(e, t) {
513
+ function ce(e, t) {
511
514
  return `${e === "f16" ? "enable f16;\n" : ""}${F}
512
515
  ${P}
513
516
  @group(0) @binding(0) var<storage, read_write> data: array<${e}>;
@@ -526,7 +529,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
526
529
  }
527
530
  }`;
528
531
  }
529
- function ce(e, t, n) {
532
+ function le(e, t, n) {
530
533
  let r = t === "f16" || e.some((e) => e.type === "f16"), i = e.map((e, t) => `@group(0) @binding(${t + 1}) var<storage, read> in_${e.name}: array<${e.type}>;`).join("\n"), a = e.map((e) => `${e.name}: ${e.type}`).join(", "), o = e.map((e) => `in_${e.name}[i]`).join(", "), s = /\breturn\b/.test(n) ? n : `return ${t}(${n});`;
531
534
  return `${r ? "enable f16;\n" : ""}${F}
532
535
  ${P}
@@ -541,7 +544,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
541
544
  out[i] = f(i, params.n${o ? ", " + o : ""});
542
545
  }`;
543
546
  }
544
- function le(e) {
547
+ function ue(e) {
545
548
  switch (e) {
546
549
  case "f32": return "let bits = bitcast<u32>(v); return select(bits | 0x80000000u, ~bits, (bits & 0x80000000u) != 0u);";
547
550
  case "f16": return "let bits = bitcast<u32>(f32(v)); return select(bits | 0x80000000u, ~bits, (bits & 0x80000000u) != 0u);";
@@ -549,14 +552,14 @@ function le(e) {
549
552
  case "u32": return "return v;";
550
553
  }
551
554
  }
552
- function ue(e) {
555
+ function de(e) {
553
556
  return `${e.enables}${e.declarations}${F}
554
557
  ${P}
555
558
  @group(0) @binding(${e.next}) var<storage, read_write> keys: array<u32>;
556
559
  @group(0) @binding(${e.next + 1}) var<storage, read_write> order: array<u32>;
557
560
  @group(0) @binding(${e.next + 2}) var<uniform> params: Params;
558
561
  ${e.fn}
559
- fn toKey(v: ${e.dtype}) -> u32 { ${le(e.dtype)} }
562
+ fn toKey(v: ${e.dtype}) -> u32 { ${ue(e.dtype)} }
560
563
  @compute @workgroup_size(256)
561
564
  fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u, @builtin(local_invocation_index) lid: u32) {
562
565
  let i = blockIndex(wid, nwg) * 256u + lid;
@@ -567,7 +570,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
567
570
  if (params.b == 1u) { order[i] = i; }
568
571
  }`;
569
572
  }
570
- function de(e) {
573
+ function fe(e) {
571
574
  return `${e === "f16" ? "enable f16;\n" : ""}${F}
572
575
  ${P}
573
576
  @group(0) @binding(0) var<storage, read> keys: array<u32>;
@@ -583,7 +586,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
583
586
  dst[i] = fromKey(k);
584
587
  }`;
585
588
  }
586
- var fe = "struct Radix { n: u32, shift: u32, blocks: u32, values: u32 }", pe = (e) => `${fe}
589
+ var pe = "struct Radix { n: u32, shift: u32, blocks: u32, values: u32 }", me = (e) => `${pe}
587
590
  ${P}
588
591
  @group(0) @binding(0) var<storage, read> keysIn: array<u32>;
589
592
  @group(0) @binding(1) var<storage, read> valuesIn: array<u32>;
@@ -643,7 +646,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
643
646
  for (var d = 0u; d < lid; d++) { start += atomicLoad(&histogram[d]); }
644
647
  starts[g * 16u + lid] = start;
645
648
  }
646
- }`, me = (e) => `${fe}
649
+ }`, he = (e) => `${pe}
647
650
  ${P}
648
651
  @group(0) @binding(0) var<storage, read> keysLocal: array<u32>;
649
652
  @group(0) @binding(1) var<storage, read> valuesLocal: array<u32>;
@@ -661,15 +664,15 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
661
664
  let dest = offsets[digit * radix.blocks + g] + lid - starts[g * 16u + digit];
662
665
  keysOut[dest] = key;
663
666
  if (radix.values == 1u) { valuesOut[dest] = valuesLocal[g * ${e}u + lid]; }
664
- }`, he = 4096;
665
- function ge(e, t) {
667
+ }`, ge = 4096;
668
+ function _e(e, t) {
666
669
  let n = t ? "localCounts" : "counts";
667
670
  return `${e.enables}${e.declarations}struct Bins { n: u32, bins: u32, pad0: u32, pad1: u32 }
668
671
  ${P}
669
672
  @group(0) @binding(${e.next}) var<storage, read_write> counts: array<atomic<u32>>;
670
673
  @group(0) @binding(${e.next + 1}) var<storage, read> range: array<f32>;
671
674
  @group(0) @binding(${e.next + 2}) var<uniform> params: Bins;
672
- ${t ? `var<workgroup> localCounts: array<atomic<u32>, ${he}>;` : ""}
675
+ ${t ? `var<workgroup> localCounts: array<atomic<u32>, ${ge}>;` : ""}
673
676
  ${e.fn}
674
677
  @compute @workgroup_size(256)
675
678
  fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u, @builtin(local_invocation_index) lid: u32) {
@@ -694,15 +697,15 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
694
697
  }
695
698
  //#endregion
696
699
  //#region src/reduce.ts
697
- var L = "struct Params { n: u32, inf: u32, len: u32, inner: u32 }", R = "fn blockIndex(wid: vec3u, nwg: vec3u) -> u32 { return wid.x + wid.y * nwg.x; }", _e = 4096;
700
+ var L = "struct Params { n: u32, inf: u32, len: u32, inner: u32 }", R = "fn blockIndex(wid: vec3u, nwg: vec3u) -> u32 { return wid.x + wid.y * nwg.x; }", ve = 4096;
698
701
  function z(t, n) {
699
702
  if (t === void 0) return Array.from({ length: n }, (e, t) => t);
700
703
  let r = (typeof t == "number" ? [t] : [...t]).map((e) => p(e, n));
701
704
  if (new Set(r).size !== r.length) throw e(`Reduction axes repeat: [${String(t)}]`, "compute");
702
705
  return r.sort((e, t) => e - t);
703
706
  }
704
- var ve = (e, t, n) => n ? e.map((e, n) => t.includes(n) ? 1 : e) : e.filter((e, n) => !t.includes(n));
705
- function ye(e, t, n, r = 256) {
707
+ var ye = (e, t, n) => n ? e.map((e, n) => t.includes(n) ? 1 : e) : e.filter((e, n) => !t.includes(n));
708
+ function be(e, t, n, r = 256) {
706
709
  let i = e.dtype, a = N / r;
707
710
  return `${e.enables}${e.declarations}${L}
708
711
  ${R}
@@ -729,7 +732,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
729
732
  if (lid == 0u) { dst[g] = partial[0]; }
730
733
  }`;
731
734
  }
732
- function be(e, t, n, r) {
735
+ function xe(e, t, n, r) {
733
736
  let i = e.dtype, a = `${e.enables}${e.declarations}${L}
734
737
  ${R}
735
738
  @group(0) @binding(${e.next}) var<storage, read_write> dst: array<${i}>;
@@ -772,17 +775,17 @@ function V(e, n, r, i = {}) {
772
775
  "min",
773
776
  "max"
774
777
  ].includes(r)) throw t(`Unknown reduce op ${r}; use sum, product, min, max or { combine, identity }`, "compute");
775
- let a = z(i.axis, n.ndim), o = !!i.keepdims, s = ve(n.shape, a, o), { combine: l, identity: u } = I(r, n.dtype);
776
- if (a.length === n.ndim) return xe(e, n, l, u, s);
778
+ let a = z(i.axis, n.ndim), o = !!i.keepdims, s = ye(n.shape, a, o), { combine: l, identity: u } = I(r, n.dtype);
779
+ if (a.length === n.ndim) return Se(e, n, l, u, s);
777
780
  let d = n, f = [...n.shape], p = [];
778
781
  for (let t = a.length - 1; t >= 0; t--) {
779
782
  let r = a[t], i = t === 0, o = f.filter((e, t) => t !== r), c = e.empty(i ? s : o, n.dtype);
780
- Se(e, d, r, f, l, u, c), i || p.push(c), d = c, f = o;
783
+ Ce(e, d, r, f, l, u, c), i || p.push(c), d = c, f = o;
781
784
  }
782
785
  for (let e of p) e.dispose();
783
786
  return d;
784
787
  }
785
- function xe(e, t, n, r, i) {
788
+ function Se(e, t, n, r, i) {
786
789
  let a = t.size;
787
790
  if (a === 0) {
788
791
  let n = e.empty(i, t.dtype), a = `${t.dtype === "f16" ? "enable f16;\n" : ""}${L}
@@ -811,7 +814,7 @@ function xe(e, t, n, r, i) {
811
814
  do {
812
815
  let a = Math.ceil(c / N), f = [], p = o(s, 0, e.maxStorage(1), f);
813
816
  l.push(...f), d = e.empty(a === 1 ? i : [a], t.dtype), u.push({
814
- program: e.program(e.kernelRoute?.level(p, n, r) ?? ye(p, n, r, e.tuned.reduce), void 0, "reduce"),
817
+ program: e.program(e.kernelRoute?.level(p, n, r) ?? be(p, n, r, e.tuned.reduce), void 0, "reduce"),
815
818
  resources: {
816
819
  ...p.resources,
817
820
  dst: d,
@@ -829,12 +832,12 @@ function xe(e, t, n, r, i) {
829
832
  for (let e of l) e.dispose();
830
833
  return d;
831
834
  }
832
- function Se(e, t, n, r, i, a, s) {
835
+ function Ce(e, t, n, r, i, a, s) {
833
836
  let c = r[n], l = r.slice(n + 1).reduce((e, t) => e * t, 1), u = s.size;
834
837
  if (u === 0) return;
835
- let d = [], f = o(t, 0, e.maxStorage(1), d), p = u >= _e || c <= 64;
838
+ let d = [], f = o(t, 0, e.maxStorage(1), d), p = u >= ve || c <= 64;
836
839
  e.submit([{
837
- program: e.program((p ? void 0 : e.kernelRoute?.axis(f, i, a)) ?? be(f, i, a, p), void 0, "reduce.axis"),
840
+ program: e.program((p ? void 0 : e.kernelRoute?.axis(f, i, a)) ?? xe(f, i, a, p), void 0, "reduce.axis"),
838
841
  resources: {
839
842
  ...f.resources,
840
843
  dst: s,
@@ -849,33 +852,33 @@ function Se(e, t, n, r, i, a, s) {
849
852
  }]);
850
853
  for (let e of d) e.dispose();
851
854
  }
852
- var Ce = (e, t) => t.reduce((t, n) => t * e[n], 1);
853
- function we(e, t, n = {}) {
854
- let r = Ce(t.shape, z(n.axis, t.ndim));
855
- return Te(V(e, l(t.dtype) && t.dtype === "f32" ? t : t.astype("f32"), "sum", n), r ? 1 / r : NaN);
855
+ var we = (e, t) => t.reduce((t, n) => t * e[n], 1);
856
+ function Te(e, t, n = {}) {
857
+ let r = we(t.shape, z(n.axis, t.ndim));
858
+ return Ee(V(e, l(t.dtype) && t.dtype === "f32" ? t : t.astype("f32"), "sum", n), r ? 1 / r : NaN);
856
859
  }
857
- function Te(e, t) {
860
+ function Ee(e, t) {
858
861
  let n = e.mul(t).eval();
859
862
  return e.dispose(), n;
860
863
  }
861
- function Ee(t, n, r = {}) {
864
+ function De(t, n, r = {}) {
862
865
  let i = r.ddof ?? 0;
863
866
  if (!Number.isFinite(i) || i < 0) throw e(`ddof must be a number of at least 0, got ${i}`, "compute");
864
- let a = n.dtype === "f32" ? n : n.astype("f32"), o = we(t, a, {
867
+ let a = n.dtype === "f32" ? n : n.astype("f32"), o = Te(t, a, {
865
868
  axis: r.axis,
866
869
  keepdims: !0
867
- }), s = Ce(n.shape, z(r.axis, n.ndim)), c = V(t, a.sub(o).square(), "sum", r);
868
- return o.dispose(), Te(c, s - i > 0 ? 1 / (s - i) : NaN);
870
+ }), s = we(n.shape, z(r.axis, n.ndim)), c = V(t, a.sub(o).square(), "sum", r);
871
+ return o.dispose(), Ee(c, s - i > 0 ? 1 / (s - i) : NaN);
869
872
  }
870
- function De(e, t, n = {}) {
871
- let r = Ee(e, t, n), i = r.sqrt().eval();
873
+ function Oe(e, t, n = {}) {
874
+ let r = De(e, t, n), i = r.sqrt().eval();
872
875
  return r.dispose(), i;
873
876
  }
874
- function Oe(e, t, n = {}) {
877
+ function ke(e, t, n = {}) {
875
878
  let i = t.dtype === "f32" ? t : t.astype("f32"), a = V(e, r(i.isnan(), 0, i), "sum", n), o = V(e, i.isnan().not(), "sum", n), s = a.div(o).eval();
876
879
  return a.dispose(), o.dispose(), s;
877
880
  }
878
- function ke(e, t, n) {
881
+ function Ae(e, t, n) {
879
882
  let r = e.dtype, i = t === "min" ? "<" : ">", a = n === "level" ? "fn load(i: u32) -> Pair { return Pair(vals[i], idx[i]); }" : "fn load(i: u32) -> Pair { return Pair(value(i), i); }", o = `${e.enables}${e.declarations}${L}
880
883
  ${R}
881
884
  struct Pair { v: ${r}, i: u32 }
@@ -926,7 +929,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
926
929
  if (lid == 0u) { outValues[g] = partial[0].v; outIndices[g] = partial[0].i; }
927
930
  }`;
928
931
  }
929
- function Ae(n, r, i, a = {}) {
932
+ function je(n, r, i, a = {}) {
930
933
  if (n.check(), !(r instanceof c)) throw t(`arg${i} takes a GpuArray or an Expr`, "compute");
931
934
  if (r.size === 0) throw e(`arg${i} of an empty array has no answer`, "compute");
932
935
  let s = [], l = r.dtype;
@@ -948,7 +951,7 @@ function Ae(n, r, i, a = {}) {
948
951
  vals: c,
949
952
  idx: u
950
953
  }), d.push({
951
- program: n.program(ke(m, i, f ? "flat" : "level"), void 0, `arg${i}`),
954
+ program: n.program(Ae(m, i, f ? "flat" : "level"), void 0, `arg${i}`),
952
955
  resources: _,
953
956
  workgroups: n.grid(a)
954
957
  }), c && s.push(c), u && s.push(u), c = h, u = g, t = a, f = !1;
@@ -957,9 +960,9 @@ function Ae(n, r, i, a = {}) {
957
960
  for (let e of s) e.dispose();
958
961
  return u;
959
962
  }
960
- let u = p(a.axis, r.ndim), d = r.shape[u], f = r.shape.slice(u + 1).reduce((e, t) => e * t, 1), m = ve(r.shape, [u], !!a.keepdims), h = m.reduce((e, t) => e * t, 1), g = h >= _e || d <= 64, _ = o(r, 0, n.maxStorage(2), s), v = n.empty([h], l), y = n.empty(m, "u32");
963
+ let u = p(a.axis, r.ndim), d = r.shape[u], f = r.shape.slice(u + 1).reduce((e, t) => e * t, 1), m = ye(r.shape, [u], !!a.keepdims), h = m.reduce((e, t) => e * t, 1), g = h >= ve || d <= 64, _ = o(r, 0, n.maxStorage(2), s), v = n.empty([h], l), y = n.empty(m, "u32");
961
964
  n.submit([{
962
- program: n.program(ke(_, i, g ? "thread" : "group"), void 0, `arg${i}.axis`),
965
+ program: n.program(Ae(_, i, g ? "thread" : "group"), void 0, `arg${i}.axis`),
963
966
  resources: {
964
967
  ..._.resources,
965
968
  outValues: v,
@@ -979,7 +982,7 @@ function Ae(n, r, i, a = {}) {
979
982
  //#endregion
980
983
  //#region src/select.ts
981
984
  var H = "fn blockIndex(wid: vec3u, nwg: vec3u) -> u32 { return wid.x + wid.y * nwg.x; }";
982
- function je(e) {
985
+ function Me(e) {
983
986
  if (!(e instanceof c)) throw t("Indices must be a GpuArray or an Expr", "compute");
984
987
  if (l(e.dtype)) throw t("Indices must be integers; astype('i32') first", "compute");
985
988
  return e instanceof h && e.dtype === "i32" && e.contiguous && e.offset === 0 ? {
@@ -990,9 +993,9 @@ function je(e) {
990
993
  owned: !0
991
994
  };
992
995
  }
993
- function Me(n, r, i, a = {}) {
996
+ function Ne(n, r, i, a = {}) {
994
997
  if (n.check(), !(r instanceof c)) throw t("take reads a GpuArray or an Expr", "compute");
995
- let { array: s, owned: l } = je(i), u = a.mode ?? "clip";
998
+ let { array: s, owned: l } = Me(i), u = a.mode ?? "clip";
996
999
  if (u !== "clip" && u !== "wrap") throw t(`take mode must be 'clip' or 'wrap', got ${String(u)}`, "compute");
997
1000
  let d = a.axis === void 0 ? void 0 : p(a.axis, r.ndim), f = d === void 0 ? r.size : r.shape[d], m = d === void 0 ? 1 : r.shape.slice(d + 1).reduce((e, t) => e * t, 1), h = d === void 0 ? s.shape : [
998
1001
  ...r.shape.slice(0, d),
@@ -1043,11 +1046,11 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
1043
1046
  }
1044
1047
  return l && s.dispose(), g;
1045
1048
  }
1046
- function Ne(e, t) {
1049
+ function Pe(e, t) {
1047
1050
  let n = (e) => e.kind === "leaf" ? e.array.storage === t.storage : e.kind === "op" && e.args.some(n);
1048
1051
  return n(e.node());
1049
1052
  }
1050
- function Pe(n, r, i, l, u = {}) {
1053
+ function Fe(n, r, i, l, u = {}) {
1051
1054
  if (n.check(), !(r instanceof h)) throw t("scatter writes into a GpuArray", "compute");
1052
1055
  if (r.check(n), !r.contiguous || r.offset) throw t("scatter needs a contiguous target; scatter into the array the view came from", "compute");
1053
1056
  let d = u.op ?? "set";
@@ -1058,12 +1061,12 @@ function Pe(n, r, i, l, u = {}) {
1058
1061
  "max"
1059
1062
  ].includes(d)) throw t(`scatter op must be set, add, min or max, got ${d}`, "compute");
1060
1063
  if (r.dtype === "f16" && d !== "set") throw t("scatter add/min/max needs a 32-bit target; use 'f32'", "compute");
1061
- let { array: f, owned: p } = je(i), m = f.size, g = typeof l == "number";
1064
+ let { array: f, owned: p } = Me(i), m = f.size, g = typeof l == "number";
1062
1065
  if (!g && !(l instanceof c)) throw t("scatter values must be a number, a GpuArray or an Expr", "compute");
1063
1066
  if (!g && l.size !== m && l.size !== 1) throw e(`scatter has ${m} indices but ${l.size} values; pass one value or one per index`, "compute");
1064
1067
  if (m > 0) {
1065
1068
  let e = r.dtype, t = [], i = g ? void 0 : l.astype(e);
1066
- if (i && Ne(i, r)) {
1069
+ if (i && Pe(i, r)) {
1067
1070
  let e = i.eval();
1068
1071
  t.push(e), i = e;
1069
1072
  }
@@ -1110,10 +1113,10 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
1110
1113
  }
1111
1114
  return p && f.dispose(), r;
1112
1115
  }
1113
- function Fe(t, n, r) {
1116
+ function Ie(t, n, r) {
1114
1117
  let i = r?.length;
1115
1118
  if (!Number.isInteger(i) || i < 0) throw e("bincount needs length (the number of bins, one past the largest value) as a whole number", "compute");
1116
- return Pe(t, t.zeros([i], r.weights ? "f32" : "u32"), n, r.weights ?? 1, { op: "add" });
1119
+ return Fe(t, t.zeros([i], r.weights ? "f32" : "u32"), n, r.weights ?? 1, { op: "add" });
1117
1120
  }
1118
1121
  function U(n, r, i) {
1119
1122
  if (n.check(), !(r instanceof c) || !(i instanceof c)) throw t("compact takes an input and a mask (GpuArrays or Exprs)", "compute");
@@ -1124,7 +1127,7 @@ function U(n, r, i) {
1124
1127
  count: l
1125
1128
  };
1126
1129
  let u = i.ne(0).eval(), d = n.empty([a], "u32"), f = [u, d], p = [];
1127
- Be(n, u, d, a, p, f);
1130
+ Ve(n, u, d, a, p, f);
1128
1131
  let m = o(r, 0, n.maxStorage(4), f), h = `${m.enables}${m.declarations}${H}
1129
1132
  @group(0) @binding(${m.next}) var<storage, read> flags: array<u32>;
1130
1133
  @group(0) @binding(${m.next + 1}) var<storage, read> offsets: array<u32>;
@@ -1162,13 +1165,13 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
1162
1165
  count: l
1163
1166
  };
1164
1167
  }
1165
- function Ie(e, t, n) {
1168
+ function Le(e, t, n) {
1166
1169
  return U(e, t, n);
1167
1170
  }
1168
1171
  async function W(e, t, n) {
1169
1172
  return (await t.read({ signal: n }))[0];
1170
1173
  }
1171
- async function Le(e, t, n, r = {}) {
1174
+ async function Re(e, t, n, r = {}) {
1172
1175
  let i = U(e, t, n);
1173
1176
  try {
1174
1177
  let n = await W(e, i.count, r.signal), a = e.empty([n], t.dtype);
@@ -1183,10 +1186,10 @@ async function Le(e, t, n, r = {}) {
1183
1186
  i.values.dispose(), i.count.dispose();
1184
1187
  }
1185
1188
  }
1186
- async function Re(e, t, n = {}) {
1189
+ async function ze(e, t, n = {}) {
1187
1190
  let r = e.arange(0, t.size, 1, "u32");
1188
1191
  try {
1189
- return await Le(e, r, t, n);
1192
+ return await Re(e, r, t, n);
1190
1193
  } finally {
1191
1194
  r.dispose();
1192
1195
  }
@@ -1197,7 +1200,7 @@ var G = 2139095040;
1197
1200
  function K(e, t, n, r, i, a, s, c) {
1198
1201
  let { combine: l, identity: u } = I(i, n.dtype), d = Math.ceil(r / N), f = e.empty([d], n.dtype), p = o(t, 0, e.maxStorage(2), c);
1199
1202
  if (c.push(f), s.push({
1200
- program: e.program(e.kernelRoute?.scan(p, l, u) ?? ie(p, l, u, e.tuned.scan), void 0, "scan"),
1203
+ program: e.program(e.kernelRoute?.scan(p, l, u) ?? ae(p, l, u, e.tuned.scan), void 0, "scan"),
1201
1204
  resources: {
1202
1205
  ...p.resources,
1203
1206
  dst: n,
@@ -1213,7 +1216,7 @@ function K(e, t, n, r, i, a, s, c) {
1213
1216
  }), d === 1) return;
1214
1217
  let m = e.empty([d], n.dtype);
1215
1218
  c.push(m), K(e, f, m, d, i, !0, s, c), s.push({
1216
- program: e.program(ae(n.dtype, l), void 0, "scan.add"),
1219
+ program: e.program(oe(n.dtype, l), void 0, "scan.add"),
1217
1220
  resources: {
1218
1221
  data: n,
1219
1222
  sums: m,
@@ -1230,7 +1233,7 @@ function K(e, t, n, r, i, a, s, c) {
1230
1233
  function q(e, t, n, r, i, a, s, c, l) {
1231
1234
  let { combine: u, identity: d } = I(s, i.dtype), f = Math.ceil(a / N), p = e.empty([a], "u32"), m = e.empty([f], "u32"), h = e.empty([f], i.dtype), g = o(t, 0, e.maxStorage(5), l), _ = n ? void 0 : e.empty([1], "u32");
1232
1235
  if (l.push(p, m, h), _ && l.push(_), c.push({
1233
- program: e.program(oe(g, u, d, !n), void 0, "scan.segmented"),
1236
+ program: e.program(se(g, u, d, !n), void 0, "scan.segmented"),
1234
1237
  resources: {
1235
1238
  ...g.resources,
1236
1239
  flagsIn: n ?? _,
@@ -1249,7 +1252,7 @@ function q(e, t, n, r, i, a, s, c, l) {
1249
1252
  }), f === 1) return;
1250
1253
  let v = e.empty([f], i.dtype);
1251
1254
  l.push(v), q(e, h, m, 0, v, f, s, c, l), c.push({
1252
- program: e.program(se(i.dtype, u), void 0, "scan.segmented.add"),
1255
+ program: e.program(ce(i.dtype, u), void 0, "scan.segmented.add"),
1253
1256
  resources: {
1254
1257
  data: i,
1255
1258
  seen: p,
@@ -1264,7 +1267,7 @@ function q(e, t, n, r, i, a, s, c, l) {
1264
1267
  workgroups: e.grid(f)
1265
1268
  });
1266
1269
  }
1267
- function ze(e, t, n, r, i) {
1270
+ function Be(e, t, n, r, i) {
1268
1271
  let { identity: a } = I(i, t.dtype), o = `${t.dtype === "f16" ? "enable f16;\n" : ""}struct Params { n: u32, inf: u32, a: u32, b: u32 }
1269
1272
  @group(0) @binding(0) var<storage, read> inclusive: array<${t.dtype}>;
1270
1273
  @group(0) @binding(1) var<storage, read> flags: array<u32>;
@@ -1294,7 +1297,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
1294
1297
  workgroups: e.grid(Math.ceil(t.size / 256))
1295
1298
  }]), s;
1296
1299
  }
1297
- function Be(e, t, n, r, i, a) {
1300
+ function Ve(e, t, n, r, i, a) {
1298
1301
  K(e, t, n, r, "sum", !0, i, a);
1299
1302
  }
1300
1303
  function J(e, n, r = {}) {
@@ -1310,13 +1313,13 @@ function J(e, n, r = {}) {
1310
1313
  let u = p(r.axis, n.ndim), d = [...n.shape.keys()].filter((e) => e !== u).concat(u), f = d.map((e, t) => d.indexOf(t)), m = n instanceof c && "transpose" in n ? n : n.eval(), h = m.transpose(...d), g = n.shape[u], _ = e.empty(h.shape, n.dtype);
1311
1314
  o > 0 && (q(e, h, void 0, g, _, o, i, l, s), e.submit(l));
1312
1315
  let v = _;
1313
- a && o > 0 && (v = ze(e, _, void 0, g, i), _.dispose());
1316
+ a && o > 0 && (v = Be(e, _, void 0, g, i), _.dispose());
1314
1317
  let y = v.transpose(...f).eval();
1315
1318
  v.dispose(), m !== n && m.dispose();
1316
1319
  for (let e of s) e.dispose();
1317
1320
  return y;
1318
1321
  }
1319
- function Ve(e, n, r, i = {}) {
1322
+ function He(e, n, r, i = {}) {
1320
1323
  if (e.check(), !(n instanceof c) || !(r instanceof c)) throw t("segmentedScan takes values and flags as GpuArrays or Exprs", "compute");
1321
1324
  if (n.size !== r.size) throw t(`segmentedScan values (${n.size}) and flags (${r.size}) differ in size`, "compute");
1322
1325
  let a = i.op ?? "sum", o = n.size, s = e.empty([o], n.dtype);
@@ -1326,12 +1329,12 @@ function Ve(e, n, r, i = {}) {
1326
1329
  for (let e of u) e.dispose();
1327
1330
  return s;
1328
1331
  }
1329
- let f = ze(e, s, l, 0, a);
1332
+ let f = Be(e, s, l, 0, a);
1330
1333
  s.dispose();
1331
1334
  for (let e of u) e.dispose();
1332
1335
  return f;
1333
1336
  }
1334
- async function He(e, n, r, i = {}) {
1337
+ async function Ue(e, n, r, i = {}) {
1335
1338
  if (e.check(), n.size !== r.size) throw t(`reduceByKey keys (${n.size}) and values (${r.size}) differ in size`, "compute");
1336
1339
  let a = n.size;
1337
1340
  if (a === 0) return {
@@ -1352,7 +1355,7 @@ async function He(e, n, r, i = {}) {
1352
1355
  0,
1353
1356
  (a - 1) * 4
1354
1357
  ]]), d.write([1], 0), f.write([1], a - 1);
1355
- let p = Ve(e, r, d, { op: i.op }), m = U(e, s, d), h = U(e, p, f), g = await W(e, m.count, i.signal), _ = e.empty([g], n.dtype), v = e.empty([g], r.dtype);
1358
+ let p = He(e, r, d, { op: i.op }), m = U(e, s, d), h = U(e, p, f), g = await W(e, m.count, i.signal), _ = e.empty([g], n.dtype), v = e.empty([g], r.dtype);
1356
1359
  e.submit([], [[
1357
1360
  m.values.buffer,
1358
1361
  0,
@@ -1400,7 +1403,7 @@ function X(n, r, i, a) {
1400
1403
  };
1401
1404
  let x = [], S = [], C = o(r, 0, n.maxStorage(2), h);
1402
1405
  if (x.push({
1403
- program: n.program(ue(C), void 0, "sort.keys"),
1406
+ program: n.program(de(C), void 0, "sort.keys"),
1404
1407
  resources: {
1405
1408
  ...C.resources,
1406
1409
  keys: _,
@@ -1451,7 +1454,7 @@ function X(n, r, i, a) {
1451
1454
  scratch: h
1452
1455
  };
1453
1456
  }
1454
- let w = g(p), T = g(m ? p : 1), E = g(16 * d), D = g(16 * d), O = g(16 * d), k = n.program(n.kernelRoute?.radixLocal ?? pe(u), void 0, "sort.local"), A = n.program(me(u), void 0, "sort.scatter"), j = n.grid(d);
1457
+ let w = g(p), T = g(m ? p : 1), E = g(16 * d), D = g(16 * d), O = g(16 * d), k = n.program(n.kernelRoute?.radixLocal ?? me(u), void 0, "sort.local"), A = n.program(he(u), void 0, "sort.scatter"), j = n.grid(d);
1455
1458
  for (let e = 0; e < l; e += 4) {
1456
1459
  let t = new Uint32Array([
1457
1460
  s,
@@ -1471,7 +1474,7 @@ function X(n, r, i, a) {
1471
1474
  radix: t
1472
1475
  },
1473
1476
  workgroups: j
1474
- }), Be(n, E, D, 16 * d, x, h), x.push({
1477
+ }), Ve(n, E, D, 16 * d, x, h), x.push({
1475
1478
  program: A,
1476
1479
  resources: {
1477
1480
  keysLocal: w,
@@ -1494,7 +1497,7 @@ function X(n, r, i, a) {
1494
1497
  function Z(e, t, n = {}) {
1495
1498
  let r = X(e, t, void 0, n), i = t.size, a = e.empty([i], t.dtype);
1496
1499
  i > 0 && e.submit([{
1497
- program: e.program(de(t.dtype), void 0, "sort.values"),
1500
+ program: e.program(fe(t.dtype), void 0, "sort.values"),
1498
1501
  resources: {
1499
1502
  keys: r.keys,
1500
1503
  dst: a,
@@ -1510,7 +1513,7 @@ function Z(e, t, n = {}) {
1510
1513
  for (let e of r.scratch) e.dispose();
1511
1514
  return a;
1512
1515
  }
1513
- function Ue(e, t, n = {}) {
1516
+ function We(e, t, n = {}) {
1514
1517
  let r = X(e, t, "index", n), i = t.size, a = e.empty([i], "u32");
1515
1518
  e.submit([], [[
1516
1519
  r.values.buffer,
@@ -1522,12 +1525,12 @@ function Ue(e, t, n = {}) {
1522
1525
  for (let e of r.scratch) e.dispose();
1523
1526
  return a;
1524
1527
  }
1525
- function We(n, r, i, a = {}) {
1528
+ function Ge(n, r, i, a = {}) {
1526
1529
  if (!(i instanceof c)) throw t("sortByKey values must be a GpuArray or an Expr", "compute");
1527
1530
  if (r.size !== i.size) throw e(`sortByKey keys (${r.size}) and values (${i.size}) differ in size`, "compute");
1528
1531
  let o = i.eval(), s = X(n, r, o, a), l = r.size, u = n.empty([l], r.dtype), d = n.empty([l], i.dtype);
1529
1532
  l > 0 && n.submit([{
1530
- program: n.program(de(r.dtype), void 0, "sort.values"),
1533
+ program: n.program(fe(r.dtype), void 0, "sort.values"),
1531
1534
  resources: {
1532
1535
  keys: s.keys,
1533
1536
  dst: u,
@@ -1552,9 +1555,9 @@ function We(n, r, i, a = {}) {
1552
1555
  values: d
1553
1556
  };
1554
1557
  }
1555
- function Ge(t, n, r, i = {}) {
1558
+ function Ke(t, n, r, i = {}) {
1556
1559
  if (!Number.isInteger(r) || r < 0 || r > n.size) throw e(`topk k must be a whole number from 0 to ${n.size}, got ${r}`, "compute");
1557
- let a = Ue(t, n, { descending: i.largest ?? !0 }), o = t.empty([r], "u32");
1560
+ let a = We(t, n, { descending: i.largest ?? !0 }), o = t.empty([r], "u32");
1558
1561
  return t.submit([], [[
1559
1562
  a.buffer,
1560
1563
  0,
@@ -1566,7 +1569,7 @@ function Ge(t, n, r, i = {}) {
1566
1569
  indices: o
1567
1570
  };
1568
1571
  }
1569
- function Ke(t, n, r) {
1572
+ function qe(t, n, r) {
1570
1573
  let i = typeof r == "number" ? [r] : [...r];
1571
1574
  for (let t of i) if (!(t >= 0 && t <= 1)) throw e(`Quantiles must be in [0, 1], got ${t}`, "compute");
1572
1575
  let a = n.size;
@@ -1580,7 +1583,7 @@ function Ke(t, n, r) {
1580
1583
  ]) e.dispose();
1581
1584
  return typeof r == "number" ? p.transfer([]) : p;
1582
1585
  }
1583
- async function qe(e, t, n = {}) {
1586
+ async function Je(e, t, n = {}) {
1584
1587
  let r = t.size;
1585
1588
  if (r === 0) return {
1586
1589
  values: e.empty([0], t.dtype),
@@ -1635,7 +1638,7 @@ async function qe(e, t, n = {}) {
1635
1638
  }
1636
1639
  //#endregion
1637
1640
  //#region src/histogram.ts
1638
- var Je = (e) => `${e === "f16" ? "enable f16;\n" : ""}struct Given { lo: f32, hi: f32, bins: u32, given: u32 }
1641
+ var Ye = (e) => `${e === "f16" ? "enable f16;\n" : ""}struct Given { lo: f32, hi: f32, bins: u32, given: u32 }
1639
1642
  @group(0) @binding(0) var<storage, read> low: array<${e}>;
1640
1643
  @group(0) @binding(1) var<storage, read> high: array<${e}>;
1641
1644
  @group(0) @binding(2) var<storage, read_write> range: array<f32>;
@@ -1650,7 +1653,7 @@ fn main(@builtin(global_invocation_id) id: vec3u) {
1650
1653
  if (id.x == 0u) { range[0] = lo; range[1] = hi; }
1651
1654
  if (id.x <= given.bins) { edges[id.x] = lo + (hi - lo) * f32(id.x) / f32(given.bins); }
1652
1655
  }`;
1653
- function Ye(n, r, i = {}) {
1656
+ function Xe(n, r, i = {}) {
1654
1657
  if (n.check(), !(r instanceof c)) throw t("histogram takes a GpuArray or an Expr", "compute");
1655
1658
  let a = r.size, s = i.bins ?? 64;
1656
1659
  if (!Number.isInteger(s) || s < 1) throw e(`Histogram bins must be a whole number of at least 1, got ${s}`, "compute");
@@ -1661,7 +1664,7 @@ function Ye(n, r, i = {}) {
1661
1664
  } else a === 0 && (l = [0, 1]);
1662
1665
  let u = n.empty([s], "u32"), d = n.empty([s + 1], "f32"), f = n.empty([2], "f32"), p = l ? n.empty([1], "f32") : V(n, r, "min"), m = l ? p : V(n, r, "max"), h = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(16));
1663
1666
  if (h.setFloat32(0, l?.[0] ?? 0, !0), h.setFloat32(4, l?.[1] ?? 0, !0), h.setUint32(8, s, !0), h.setUint32(12, +!!l, !0), n.submit([{
1664
- program: n.program(Je(l ? "f32" : r.dtype), void 0, "histogram.range"),
1667
+ program: n.program(Ye(l ? "f32" : r.dtype), void 0, "histogram.range"),
1665
1668
  resources: {
1666
1669
  low: p,
1667
1670
  high: m,
@@ -1677,7 +1680,7 @@ function Ye(n, r, i = {}) {
1677
1680
  }]), a > 0) {
1678
1681
  let e = [], t = o(r, 0, n.maxStorage(2), e);
1679
1682
  n.submit([{
1680
- program: n.program(ge(t, s <= he), void 0, "histogram"),
1683
+ program: n.program(_e(t, s <= ge), void 0, "histogram"),
1681
1684
  resources: {
1682
1685
  ...t.resources,
1683
1686
  counts: u,
@@ -1700,7 +1703,7 @@ function Ye(n, r, i = {}) {
1700
1703
  }
1701
1704
  //#endregion
1702
1705
  //#region src/kernel.ts
1703
- function Xe(n, r, i) {
1706
+ function Ze(n, r, i) {
1704
1707
  if (i.indirect) {
1705
1708
  let t = i.indirect instanceof h ? i.indirect.buffer : i.indirect, n = (i.indirectOffset ?? 0) * 4 + (i.indirect instanceof h ? i.indirect.offset * 4 : 0);
1706
1709
  if (!Number.isInteger(n) || n < 0) throw e("indirectOffset must be a whole number of elements", "compute");
@@ -1725,7 +1728,7 @@ function Xe(n, r, i) {
1725
1728
  for (let t of o) if (!Number.isInteger(t) || t < 0 || t > s) throw e(`Kernel run of ${o.join(" x ")} workgroups is over ${s} per dimension; spread the work over y and z`, "compute");
1726
1729
  return { workgroups: o };
1727
1730
  }
1728
- var Ze = class {
1731
+ var Qe = class {
1729
1732
  #e;
1730
1733
  #t;
1731
1734
  #n = !1;
@@ -1737,7 +1740,7 @@ var Ze = class {
1737
1740
  }
1738
1741
  run(e, t) {
1739
1742
  this.#r();
1740
- let n = Xe(this.#e, this.workgroupSize, t);
1743
+ let n = Ze(this.#e, this.workgroupSize, t);
1741
1744
  return (n.indirect || n.workgroups.every((e) => e > 0)) && this.#e.submit([{
1742
1745
  program: this.#t,
1743
1746
  resources: { ...e },
@@ -1745,7 +1748,7 @@ var Ze = class {
1745
1748
  }]), this;
1746
1749
  }
1747
1750
  bind(e) {
1748
- return this.#r(), new Qe(this.#e, this.#t, e);
1751
+ return this.#r(), new $e(this.#e, this.#t, e);
1749
1752
  }
1750
1753
  indirectArgs(e = [
1751
1754
  0,
@@ -1760,7 +1763,7 @@ var Ze = class {
1760
1763
  [Symbol.dispose]() {
1761
1764
  this.dispose();
1762
1765
  }
1763
- }, Qe = class {
1766
+ }, $e = class {
1764
1767
  #e;
1765
1768
  #t;
1766
1769
  #n;
@@ -1802,7 +1805,7 @@ var Ze = class {
1802
1805
  encode(e, t) {
1803
1806
  if (this.#a) throw n("disposed", "BoundKernel disposed; bind the kernel again", "compute");
1804
1807
  for (let e of Object.values(this.#n)) e instanceof h && e.check(this.#e);
1805
- let r = Xe(this.#e, this.#t.entry.workgroupSize, t);
1808
+ let r = Ze(this.#e, this.#t.entry.workgroupSize, t);
1806
1809
  if (r.workgroups && !r.workgroups.every((e) => e > 0)) return;
1807
1810
  let i = "beginComputePass" in e, a = i ? e.beginComputePass({ label: this.#t.label }) : e;
1808
1811
  a.setPipeline(this.#t.pipeline), this.#i.forEach((e, t) => a.setBindGroup(t, e)), r.indirect ? a.dispatchWorkgroupsIndirect(r.indirect.buffer, r.indirect.offset) : a.dispatchWorkgroups(...r.workgroups), i && a.end();
@@ -1826,7 +1829,7 @@ var Ze = class {
1826
1829
  };
1827
1830
  //#endregion
1828
1831
  //#region src/context.ts
1829
- function $e(n, r) {
1832
+ function et(n, r) {
1830
1833
  for (let [i, a] of Object.entries(n)) {
1831
1834
  if (![
1832
1835
  "reduce",
@@ -1843,7 +1846,7 @@ function $e(n, r) {
1843
1846
  if (a > r) throw e(`Tuned ${i} of ${a} threads is over this device's limit of ${r}; measure again on it`, "compute");
1844
1847
  }
1845
1848
  }
1846
- var et = 512, tt = (e) => {
1849
+ var tt = 512, nt = (e) => {
1847
1850
  let t = {
1848
1851
  binding: e.binding,
1849
1852
  visibility: GPUShaderStage.COMPUTE
@@ -1885,17 +1888,23 @@ function $(e, t) {
1885
1888
  t.addEventListener("abort", i, { once: !0 }), e.then(n, r).finally(() => t.removeEventListener("abort", i));
1886
1889
  })) : e;
1887
1890
  }
1888
- var nt = class {
1891
+ var rt = class {
1889
1892
  #e;
1890
1893
  #t;
1891
1894
  #n;
1892
1895
  #r;
1893
1896
  #i;
1894
1897
  #a;
1898
+ #o;
1895
1899
  constructor(e, t, n = !1) {
1896
- this.#e = /* @__PURE__ */ new Set(), this.#t = /* @__PURE__ */ new Map(), this.#n = /* @__PURE__ */ new Set(), this.#r = [], this.#i = !1, this.tuned = {}, this.device = e, this.ownsDevice = t, this.lost = e.lost, this.fastMath = n, this.routeReady = (_(e, () => import("./compat-YK57ZCbA.js")) ?? Promise.resolve(void 0)).then((e) => {
1900
+ this.#e = /* @__PURE__ */ new Set(), this.#t = /* @__PURE__ */ new Map(), this.#n = /* @__PURE__ */ new Set(), this.#r = [], this.#i = !1, this.tuned = {}, this.device = e, this.ownsDevice = t, this.lost = e.lost, this.fastMath = n;
1901
+ let r = _(e, () => import("./compat-YK57ZCbA.js"));
1902
+ this.routeReady = (r ?? Promise.resolve(void 0)).then((e) => {
1897
1903
  this.sortRoute = e?.sortShader;
1898
- });
1904
+ }), this.#a = r ? v(this.routeReady) : Promise.resolve();
1905
+ }
1906
+ get ready() {
1907
+ return this.#a;
1899
1908
  }
1900
1909
  get disposed() {
1901
1910
  return this.#i;
@@ -1912,7 +1921,7 @@ var nt = class {
1912
1921
  check() {
1913
1922
  if (this.#i) throw n("disposed", "ComputeContext disposed; create a new one with createCompute()", "compute");
1914
1923
  }
1915
- #o(e) {
1924
+ #s(e) {
1916
1925
  if (!u.includes(e)) throw t(`dtype must be 'f32', 'f16', 'i32' or 'u32', got ${String(e)}`, "compute");
1917
1926
  if (e === "f16" && !this.f16) throw n("unsupported", "This GPU has no shader-f16 feature; use 'f32' arrays", "compute");
1918
1927
  }
@@ -1923,7 +1932,7 @@ var nt = class {
1923
1932
  });
1924
1933
  }
1925
1934
  empty(e, t, n = 0) {
1926
- this.check(), this.#o(t);
1935
+ this.check(), this.#s(t);
1927
1936
  let r = new h(this, t, e, void 0, n);
1928
1937
  return this.#e.add(r), r;
1929
1938
  }
@@ -1952,23 +1961,23 @@ var nt = class {
1952
1961
  }
1953
1962
  full(e, t, n) {
1954
1963
  let r = typeof e == "number" ? [e] : e;
1955
- return this.#s(r).astype("f32").mul(0).add(t).astype(n ?? "f32").eval();
1964
+ return this.#c(r).astype("f32").mul(0).add(t).astype(n ?? "f32").eval();
1956
1965
  }
1957
1966
  arange(t, n, r = 1, i) {
1958
1967
  if (n === void 0 && ([t, n] = [0, t]), !Number.isFinite(t) || !Number.isFinite(n) || !Number.isFinite(r) || r === 0) throw e(`arange needs finite start and stop and a non-zero step, got ${t}, ${n}, ${r}`, "compute");
1959
- let a = Math.max(0, Math.ceil((n - t) / r)), o = Number.isInteger(t) && Number.isInteger(r), s = i ?? (o ? t >= 0 && r > 0 ? "u32" : "i32" : "f32"), c = this.#s([a]);
1968
+ let a = Math.max(0, Math.ceil((n - t) / r)), o = Number.isInteger(t) && Number.isInteger(r), s = i ?? (o ? t >= 0 && r > 0 ? "u32" : "i32" : "f32"), c = this.#c([a]);
1960
1969
  return (o && s !== "f32" && s !== "f16" ? c.astype("i32").mul(r).add(t) : c.astype("f32").mul(r).add(t)).astype(s).eval();
1961
1970
  }
1962
1971
  linspace(t, n, r = 50) {
1963
1972
  if (!Number.isInteger(r) || r < 0) throw e(`linspace num must be a whole number, got ${r}`, "compute");
1964
1973
  let i = r > 1 ? (n - t) / (r - 1) : 0;
1965
- return this.#s([r]).astype("f32").mul(i).add(t).eval();
1974
+ return this.#c([r]).astype("f32").mul(i).add(t).eval();
1966
1975
  }
1967
1976
  eye(e, t) {
1968
- let n = this.#s([e, e]);
1977
+ let n = this.#c([e, e]);
1969
1978
  return n.floorDiv(e).eq(n.mod(e)).astype(t ?? "f32").eval();
1970
1979
  }
1971
- #s(e) {
1980
+ #c(e) {
1972
1981
  return this.check(), new d(this, {
1973
1982
  kind: "index",
1974
1983
  dtype: "u32",
@@ -2044,17 +2053,17 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2044
2053
  }
2045
2054
  kernel(e, n = {}) {
2046
2055
  if (this.check(), typeof e != "string") throw t("gpu.kernel takes WGSL source text", "compute");
2047
- return new Ze(this, this.program(e, n.entryPoint, n.label));
2056
+ return new Qe(this, this.program(e, n.entryPoint, n.label));
2048
2057
  }
2049
2058
  program(e, n, r) {
2050
2059
  let i = `${n ?? ""}\n${e}`, a = this.#t.get(i);
2051
2060
  if (a) return this.#t.delete(i), this.#t.set(i, a), a;
2052
- let o = te(e);
2061
+ let o = ne(e);
2053
2062
  if (!o.entryPoints.length) throw t("Kernel WGSL has no @compute entry point", "compute");
2054
2063
  let s = n === void 0 ? o.entryPoints[0] : o.entryPoints.find((e) => e.name === n);
2055
2064
  if (!s || n === void 0 && o.entryPoints.length > 1) throw t(`Kernel entry point ${n ?? "(none given)"} not found; pass entryPoint, one of ${o.entryPoints.map((e) => e.name).join(", ")}`, "compute");
2056
2065
  let c = Math.max(-1, ...o.bindings.map((e) => e.group)) + 1, l = r ?? s.name, u = this.scoped(() => {
2057
- let t = Array.from({ length: c }, (e, t) => this.device.createBindGroupLayout({ entries: o.bindings.filter((e) => e.group === t).map(tt) }));
2066
+ let t = Array.from({ length: c }, (e, t) => this.device.createBindGroupLayout({ entries: o.bindings.filter((e) => e.group === t).map(nt) }));
2058
2067
  return {
2059
2068
  pipeline: this.device.createComputePipeline({
2060
2069
  label: l,
@@ -2073,7 +2082,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2073
2082
  label: l
2074
2083
  };
2075
2084
  });
2076
- return this.#t.set(i, u), this.#t.size > et && this.#t.delete(this.#t.keys().next().value), u;
2085
+ return this.#t.set(i, u), this.#t.size > tt && this.#t.delete(this.#t.keys().next().value), u;
2077
2086
  }
2078
2087
  scoped(e) {
2079
2088
  this.device.pushErrorScope("validation"), this.device.pushErrorScope("out-of-memory"), this.device.pushErrorScope("internal");
@@ -2102,7 +2111,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2102
2111
  }));
2103
2112
  }
2104
2113
  encode(e, t) {
2105
- let n = [], r = this.#a && this.device.features.has("timestamp-query") && t.length > 0 ? this.device.createQuerySet({
2114
+ let n = [], r = this.#o && this.device.features.has("timestamp-query") && t.length > 0 ? this.device.createQuerySet({
2106
2115
  type: "timestamp",
2107
2116
  count: t.length * 2
2108
2117
  }) : void 0;
@@ -2121,7 +2130,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2121
2130
  size: i,
2122
2131
  usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
2123
2132
  });
2124
- e.resolveQuerySet(r, 0, t.length * 2, a, 0), e.copyBufferToBuffer(a, 0, o, 0, i), n.push(a), this.#n.add(o), this.#a.push({
2133
+ e.resolveQuerySet(r, 0, t.length * 2, a, 0), e.copyBufferToBuffer(a, 0, o, 0, i), n.push(a), this.#n.add(o), this.#o.push({
2125
2134
  staging: o,
2126
2135
  queries: r,
2127
2136
  labels: t.map((e) => e.program.label)
@@ -2173,7 +2182,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2173
2182
  return t.set(e), t;
2174
2183
  }
2175
2184
  if (!e.layout) throw t(`Kernel binding ${e.name} has a type (${e.type}) the kernel cannot lay out; pass bytes`, "compute");
2176
- return re(e.layout, n, e.name);
2185
+ return ie(e.layout, n, e.name);
2177
2186
  }
2178
2187
  grid(t) {
2179
2188
  let n = this.device.limits.maxComputeWorkgroupsPerDimension;
@@ -2191,7 +2200,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2191
2200
  ];
2192
2201
  }
2193
2202
  async readBytes(e, t, r, i) {
2194
- if (this.check(), Q(i), r === 0) return await this.#c(), /* @__PURE__ */ new ArrayBuffer(0);
2203
+ if (this.check(), Q(i), r === 0) return await this.#l(), /* @__PURE__ */ new ArrayBuffer(0);
2195
2204
  let a = t & -4, o = Math.ceil((t + r) / 4) * 4, s = this.device.createBuffer({
2196
2205
  size: o - a,
2197
2206
  usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
@@ -2201,14 +2210,14 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2201
2210
  i?.addEventListener("abort", c, { once: !0 });
2202
2211
  try {
2203
2212
  let n = this.device.createCommandEncoder();
2204
- return n.copyBufferToBuffer(e, a, s, 0, o - a), this.device.queue.submit([n.finish()]), await this.#c(), await s.mapAsync(GPUMapMode.READ), s.getMappedRange().slice(t - a, t - a + r);
2213
+ return n.copyBufferToBuffer(e, a, s, 0, o - a), this.device.queue.submit([n.finish()]), await this.#l(), await s.mapAsync(GPUMapMode.READ), s.getMappedRange().slice(t - a, t - a + r);
2205
2214
  } catch (e) {
2206
2215
  throw this.#i ? n("disposed", "ComputeContext disposed during a read; keep it alive until reads finish", "compute") : (Q(i), e);
2207
2216
  } finally {
2208
2217
  i?.removeEventListener("abort", c), this.#n.delete(s), s.destroy();
2209
2218
  }
2210
2219
  }
2211
- async #c() {
2220
+ async #l() {
2212
2221
  this.device.pushErrorScope("validation");
2213
2222
  let e = [...this.#r, {
2214
2223
  kind: "validation error",
@@ -2219,19 +2228,19 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2219
2228
  if (r >= 0) throw n("failed", `GPU ${e[r].kind}: ${t[r].message.trim()}; fix the kernel WGSL or its bindings (or use smaller arrays)`, "compute");
2220
2229
  }
2221
2230
  async done(e = {}) {
2222
- this.check(), Q(e.signal), await this.#c(), await $(this.device.queue.onSubmittedWorkDone(), e.signal);
2231
+ this.check(), Q(e.signal), await this.#l(), await $(this.device.queue.onSubmittedWorkDone(), e.signal);
2223
2232
  }
2224
2233
  async profile(e, t = {}) {
2225
- if (this.check(), this.#a) throw n("state", "profile() is already running; await it before profiling again", "compute");
2226
- this.#a = [];
2234
+ if (this.check(), this.#o) throw n("state", "profile() is already running; await it before profiling again", "compute");
2235
+ this.#o = [];
2227
2236
  let r = [];
2228
2237
  try {
2229
2238
  try {
2230
2239
  await e();
2231
2240
  } finally {
2232
- r = this.#a, this.#a = void 0;
2241
+ r = this.#o, this.#o = void 0;
2233
2242
  }
2234
- return await this.#c(), (await $(Promise.all(r.map(async ({ staging: e, labels: t }) => {
2243
+ return await this.#l(), (await $(Promise.all(r.map(async ({ staging: e, labels: t }) => {
2235
2244
  await e.mapAsync(GPUMapMode.READ);
2236
2245
  let n = new BigUint64Array(e.getMappedRange().slice(0));
2237
2246
  return t.map((e, t) => ({
@@ -2264,7 +2273,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2264
2273
  if (s.some((e) => e.shape.length !== l.length || e.shape.some((e, t) => e !== l[t]))) throw e(`gpu.map inputs must share one shape, got ${s.map((e) => `[${e.shape.join(", ")}]`).join(", ")}`, "compute");
2265
2274
  let d = i.dtype ?? s[0].dtype, f = this.empty(l, d);
2266
2275
  if (u > 0) {
2267
- let e = ce(o.map((e, t) => ({
2276
+ let e = le(o.map((e, t) => ({
2268
2277
  name: e,
2269
2278
  type: s[t].dtype
2270
2279
  })), d, r), t = {
@@ -2300,19 +2309,19 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2300
2309
  return V(this, e, "max", t);
2301
2310
  }
2302
2311
  mean(e, t) {
2303
- return we(this, e, t);
2312
+ return Te(this, e, t);
2304
2313
  }
2305
2314
  var(e, t) {
2306
- return Ee(this, e, t);
2315
+ return De(this, e, t);
2307
2316
  }
2308
2317
  std(e, t) {
2309
- return De(this, e, t);
2318
+ return Oe(this, e, t);
2310
2319
  }
2311
2320
  argmin(e, t) {
2312
- return Ae(this, e, "min", t);
2321
+ return je(this, e, "min", t);
2313
2322
  }
2314
2323
  argmax(e, t) {
2315
- return Ae(this, e, "max", t);
2324
+ return je(this, e, "max", t);
2316
2325
  }
2317
2326
  all(e, t) {
2318
2327
  return V(this, e.ne(0), "min", t);
@@ -2333,7 +2342,7 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2333
2342
  return V(this, r(e.isnan(), -Infinity, e), "max", t);
2334
2343
  }
2335
2344
  nanmean(e, t) {
2336
- return Oe(this, e, t);
2345
+ return ke(this, e, t);
2337
2346
  }
2338
2347
  scan(e, t = {}) {
2339
2348
  return J(this, e, t);
@@ -2348,52 +2357,52 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2348
2357
  });
2349
2358
  }
2350
2359
  segmentedScan(e, t, n = {}) {
2351
- return Ve(this, e, t, n);
2360
+ return He(this, e, t, n);
2352
2361
  }
2353
2362
  reduceByKey(e, t, n = {}) {
2354
- return He(this, e, t, n);
2363
+ return Ue(this, e, t, n);
2355
2364
  }
2356
2365
  sort(e, t = {}) {
2357
2366
  return Z(this, e, t);
2358
2367
  }
2359
2368
  argsort(e, t = {}) {
2360
- return Ue(this, e, t);
2369
+ return We(this, e, t);
2361
2370
  }
2362
2371
  sortByKey(e, t, n = {}) {
2363
- return We(this, e, t, n);
2372
+ return Ge(this, e, t, n);
2364
2373
  }
2365
2374
  topk(e, t, n = {}) {
2366
- return Ge(this, e, t, n);
2375
+ return Ke(this, e, t, n);
2367
2376
  }
2368
2377
  quantile(e, t) {
2369
- return Ke(this, e, t);
2378
+ return qe(this, e, t);
2370
2379
  }
2371
2380
  median(e) {
2372
- return Ke(this, e, .5);
2381
+ return qe(this, e, .5);
2373
2382
  }
2374
2383
  unique(e, t = {}) {
2375
- return qe(this, e, t);
2384
+ return Je(this, e, t);
2376
2385
  }
2377
2386
  take(e, t, n = {}) {
2378
- return Me(this, e, t, n);
2387
+ return Ne(this, e, t, n);
2379
2388
  }
2380
2389
  scatter(e, t, n, r = {}) {
2381
- return Pe(this, e, t, n, r);
2390
+ return Fe(this, e, t, n, r);
2382
2391
  }
2383
2392
  bincount(e, t) {
2384
- return Fe(this, e, t);
2393
+ return Ie(this, e, t);
2385
2394
  }
2386
2395
  compact(e, t) {
2387
- return Ie(this, e, t);
2396
+ return Le(this, e, t);
2388
2397
  }
2389
2398
  filter(e, t, n = {}) {
2390
- return Le(this, e, t, n);
2399
+ return Re(this, e, t, n);
2391
2400
  }
2392
2401
  nonzero(e, t = {}) {
2393
- return Re(this, e, t);
2402
+ return ze(this, e, t);
2394
2403
  }
2395
2404
  histogram(e, t = {}) {
2396
- return Ye(this, e, t);
2405
+ return Xe(this, e, t);
2397
2406
  }
2398
2407
  dispose() {
2399
2408
  if (!this.#i) {
@@ -2406,44 +2415,44 @@ fn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u,
2406
2415
  [Symbol.dispose]() {
2407
2416
  this.dispose();
2408
2417
  }
2409
- }, rt = async (e) => {
2410
- let { cpuContext: t } = await import("./cpu-load-aTmfphVu.js");
2418
+ }, it = async (e) => {
2419
+ let { cpuContext: t } = await import("./cpu-load-XFcM1TXj.js");
2411
2420
  return Q(e), t();
2412
2421
  };
2413
- async function it(e) {
2422
+ async function at(e) {
2414
2423
  return await e.routeReady, e;
2415
2424
  }
2416
- async function at(e = {}) {
2425
+ async function ot(e = {}) {
2417
2426
  Q(e.signal);
2418
2427
  let r = e.backend ?? "auto";
2419
2428
  if (r !== "auto" && r !== "webgpu" && r !== "cpu") throw t(`createCompute backend must be 'auto', 'webgpu' or 'cpu', got ${String(r)}`, "compute");
2420
2429
  if (e.fastMath !== void 0 && typeof e.fastMath != "boolean") throw t(`createCompute fastMath must be true or false, got ${String(e.fastMath)}`, "compute");
2421
2430
  let i = e.tuned ?? {};
2422
- $e(i, 1024);
2431
+ et(i, 1024);
2423
2432
  let a = e.fastMath === !0, o = (e, t) => {
2424
2433
  try {
2425
- $e(i, e.limits.maxComputeInvocationsPerWorkgroup);
2434
+ et(i, e.limits.maxComputeInvocationsPerWorkgroup);
2426
2435
  } catch (n) {
2427
2436
  throw t && e.destroy(), n;
2428
2437
  }
2429
- let n = new nt(e, t, a);
2438
+ let n = new rt(e, t, a);
2430
2439
  return n.tuned = i, n;
2431
2440
  };
2432
- if (e.device) return it(o(e.device, !1));
2441
+ if (e.device) return at(o(e.device, !1));
2433
2442
  if (e.engine) {
2434
2443
  let t = e.engine.gpu;
2435
2444
  if (!t) throw n("unsupported", "Engine has no WebGPU device (WebGL2 fallback); create the context without an engine", "compute");
2436
- return it(o(t, !1));
2445
+ return at(o(t, !1));
2437
2446
  }
2438
- if (r === "cpu") return rt(e.signal);
2447
+ if (r === "cpu") return it(e.signal);
2439
2448
  let s = globalThis.navigator, c = s?.gpu;
2440
2449
  if (!c) {
2441
- if (r === "auto") return rt(e.signal);
2450
+ if (r === "auto") return it(e.signal);
2442
2451
  throw n("unsupported", "WebGPU unavailable; use a runtime with WebGPU, or backend: 'cpu'", "compute");
2443
2452
  }
2444
2453
  let l = e.powerPreference ?? (/Win/.test(s?.userAgent ?? "") ? void 0 : "high-performance"), u = await $(c.requestAdapter(l ? { powerPreference: l } : {}), e.signal);
2445
2454
  if (!u) {
2446
- if (r === "auto") return rt(e.signal);
2455
+ if (r === "auto") return it(e.signal);
2447
2456
  throw n("unsupported", "WebGPU adapter unavailable; check that the GPU is enabled, or use backend: 'cpu'", "compute");
2448
2457
  }
2449
2458
  let d = await u.requestDevice({
@@ -2464,7 +2473,7 @@ async function at(e = {}) {
2464
2473
  }
2465
2474
  });
2466
2475
  if (e.signal?.aborted) throw d.destroy(), e.signal.reason;
2467
- return it(o(d, !0));
2476
+ return at(o(d, !0));
2468
2477
  }
2469
2478
  //#endregion
2470
- export { Ze as a, me as c, te as d, Qe as i, ie as l, Q as n, ye as o, at as r, pe as s, nt as t, re as u };
2479
+ export { Qe as a, he as c, ne as d, $e as i, ae as l, Q as n, be as o, ot as r, me as s, rt as t, ie as u };