@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.
package/dist/context.d.ts CHANGED
@@ -129,6 +129,14 @@ export declare class ComputeContext {
129
129
  readonly routeReady: Promise<void>;
130
130
  /** @internal Use {@link createCompute}. */
131
131
  constructor(device: GPUDevice, ownsDevice: boolean, fastMath?: boolean);
132
+ /**
133
+ * Settles once the context's kernels take the routes they will from then on. On the WebGL2 compatibility layer a
134
+ * context loads its sort route (a dynamic import) when it is made, and a sort built before it has loaded keeps the
135
+ * radix passes, which the layer runs on its CPU tier. `createCompute` resolves only after it, so its contexts are
136
+ * ready; a `ComputeFrame`'s context is made when the frame attaches: await this (or `frame.ready`) before building
137
+ * kernels on it (KB-COMPAT-READY1). Resolved at once on WebGPU; never rejects.
138
+ */
139
+ get ready(): Promise<void>;
132
140
  /** True after `dispose()`. */
133
141
  get disposed(): boolean;
134
142
  /** Where the work runs: `'webgpu'`, or `'cpu'` for the fallback (`createCompute({ backend })`). */
@@ -1,7 +1,7 @@
1
1
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
2
- import { n as r, t as i } from "./context-C75sQQra.js";
3
- import { a, m as o, n as s, p as c } from "./expr-DwFen60A.js";
4
- import { n as l, t as u } from "./array-DbI848Wf.js";
2
+ import { n as r, t as i } from "./context-CCvs3wkC.js";
3
+ import { a, m as o, n as s, p as c } from "./expr-t3jm8acM.js";
4
+ import { n as l, t as u } from "./array-C29noZq7.js";
5
5
  //#region src/cpu.ts
6
6
  var d = class {
7
7
  constructor(e, t) {
@@ -1,4 +1,4 @@
1
- import { t as e } from "./cpu-CdVdqP4I.js";
1
+ import { t as e } from "./cpu-D4UQwJ9L.js";
2
2
  //#region src/cpu-load.ts
3
3
  var t = () => new e();
4
4
  //#endregion
package/dist/cpu-wasm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
2
- import { n as r } from "./context-C75sQQra.js";
3
- import { m as i } from "./expr-DwFen60A.js";
4
- import { i as a, n as o, r as s, t as c } from "./cpu-CdVdqP4I.js";
2
+ import { n as r } from "./context-CCvs3wkC.js";
3
+ import { m as i } from "./expr-t3jm8acM.js";
4
+ import { i as a, n as o, r as s, t as c } from "./cpu-D4UQwJ9L.js";
5
5
  //#region src/cpu-wasm.ts
6
6
  var l = /* @__PURE__ */ "add.sub.mul.div.floorDiv.mod.pow.minimum.maximum.clip.atan2.hypot.neg.abs.sign.square.sqrt.exp.exp2.log.log2.sin.cos.tan.asin.acos.atan.sinh.cosh.tanh.degrees.radians.rsqrt.reciprocal.log1p.expm1.floor.ceil.trunc.round.lt.le.gt.ge.eq.ne.and.or.xor.not.isnan.isinf.isfinite.bitAnd.bitOr.bitXor.bitNot.shiftLeft.shiftRight.popcount.bitcast.astype.where".split("."), u = [
7
7
  "leaf",
package/dist/decomp.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
2
- import { n as r } from "./context-C75sQQra.js";
3
- import { n as i, r as a } from "./expr-DwFen60A.js";
2
+ import { n as r } from "./context-CCvs3wkC.js";
3
+ import { n as i, r as a } from "./expr-t3jm8acM.js";
4
4
  //#region src/decomp.ts
5
5
  async function o(e) {
6
6
  r(e);
package/dist/distance.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as e, r as t } from "./errors-CDgOgzCd.js";
2
- import { n } from "./expr-DwFen60A.js";
2
+ import { n } from "./expr-t3jm8acM.js";
3
3
  //#region ../shared/distance-exact.js
4
4
  var r = /* @__PURE__ */ new Float64Array(), i = /* @__PURE__ */ new Float64Array(), a = /* @__PURE__ */ new Int32Array(), o = /* @__PURE__ */ new Int32Array(), s = /* @__PURE__ */ new Int32Array(), c = /* @__PURE__ */ new Float64Array();
5
5
  function l(e) {
@@ -256,6 +256,7 @@ fn pmReduceTrig(a: f32) -> PmReduced {
256
256
  `],
257
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
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
+ preciseSinCos: [["pmTrig"], "fn preciseSinCos(x: f32) -> vec2f {\n let a = abs(x);\n if (pmExponent(x) == 255u) { let n = pmNan(x); return vec2f(n, n); }\n if (a < 0.000244140625) { return vec2f(x, 1.0); }\n let r = pmReduceTrig(a);\n let s = pmSinK(r.hi, r.lo); let c = pmCosK(r.hi, r.lo);\n let vs = select(select(select(-c, -s, r.q == 2u), c, r.q == 1u), s, r.q == 0u);\n let vc = select(select(select(s, -c, r.q == 2u), -s, r.q == 1u), c, r.q == 0u);\n return vec2f(pmWithSign(vs, x), vc);\n}\n"],
259
260
  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
261
  pmAtanK: [["pmBits"], `fn pmAtanK(u: f32) -> f32 {
261
262
  let w = u * u;
package/dist/fft.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as e, r as t } from "./errors-CDgOgzCd.js";
2
- import { n } from "./expr-DwFen60A.js";
3
- import { n as r, t as i } from "./array-DbI848Wf.js";
2
+ import { n } from "./expr-t3jm8acM.js";
3
+ import { n as r, t as i } from "./array-C29noZq7.js";
4
4
  //#region src/fft.ts
5
5
  var a = "struct Pass { n: u32, l: u32, lines: u32, inverse: u32 }\n@group(0) @binding(0) var<storage, read> reIn: array<f32>;\n@group(0) @binding(1) var<storage, read> imIn: array<f32>;\n@group(0) @binding(2) var<storage, read_write> reOut: array<f32>;\n@group(0) @binding(3) var<storage, read_write> imOut: array<f32>;\n@group(0) @binding(4) var<uniform> pass_: Pass;\n@group(0) @binding(5) var<storage, read> twiddle: array<vec2f>;\n@compute @workgroup_size(256)\nfn main(@builtin(workgroup_id) wid: vec3u, @builtin(num_workgroups) nwg: vec3u, @builtin(local_invocation_index) lid: u32) {\n let t = (wid.x + wid.y * nwg.x) * 256u + lid;\n let half = pass_.n / 2u;\n if (t >= half * pass_.lines) { return; }\n let line = t / half;\n let j = t % half;\n let base = line * pass_.n;\n let k = j % pass_.l;\n\n var w = twiddle[k * (half / pass_.l)];\n if (pass_.inverse == 1u) { w.y = -w.y; }\n let a = vec2f(reIn[base + j], imIn[base + j]);\n let b0 = vec2f(reIn[base + j + half], imIn[base + j + half]);\n let b = vec2f(w.x * b0.x - w.y * b0.y, w.x * b0.y + w.y * b0.x);\n let dest = base + 2u * j - k;\n reOut[dest] = a.x + b.x;\n imOut[dest] = a.y + b.y;\n reOut[dest + pass_.l] = a.x - b.x;\n imOut[dest + pass_.l] = a.y - b.y;\n}", o = (e) => e > 0 && !(e & e - 1);
6
6
  function s(t) {
package/dist/frame.d.ts CHANGED
@@ -39,6 +39,19 @@ export declare class ComputeFrame implements EnginePlugin {
39
39
  constructor(options?: ComputeFrameOptions);
40
40
  /** The compute context on the engine's device. */
41
41
  get gpu(): ComputeContext;
42
+ /**
43
+ * Settles once the frame's compute context takes its routes: see {@link ComputeContext.ready}. On the WebGL2
44
+ * compatibility layer await it after attaching and before building a sort on `frame.gpu`; resolved at once on WebGPU
45
+ * (KB-COMPAT-READY1).
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const frame = ComputeFrame.attach(engine);
50
+ * await frame.ready;
51
+ * const sorted = frame.gpu.sort(frame.gpu.zeros(1024));
52
+ * ```
53
+ */
54
+ get ready(): Promise<void>;
42
55
  /** The jobs, in run order. */
43
56
  get jobs(): readonly FrameJob[];
44
57
  /** @internal EnginePlugin hook. */
package/dist/frame.js CHANGED
@@ -1,10 +1,10 @@
1
- // @margo/core-built 0.1.0
1
+ // @margo/core-built 1.0.0
2
2
  import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
3
3
 
4
4
  import { n as e, r as t, t as n } from "./errors-CDgOgzCd.js";
5
- import { i as r, t as i } from "./context-C75sQQra.js";
5
+ import { i as r, t as i } from "./context-CCvs3wkC.js";
6
6
  //#region src/frame.ts
7
- var a = 0, o = class o {coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);
7
+ var a = 0, o = class o {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
8
8
  #e;
9
9
  #t;
10
10
  #n;
@@ -12,7 +12,7 @@ var a = 0, o = class o {coreRequirement=__margoCoreRequirement("0.1.0",import.me
12
12
  #i;
13
13
  #a;
14
14
  #o;
15
- static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));
15
+ static attach(e, t = {}) {__margoAssertCore(e,__margoCoreRequirement("1.0.0",import.meta.url));
16
16
  let n = new o(t);
17
17
  return e.use(n), n;
18
18
  }
@@ -27,6 +27,9 @@ var a = 0, o = class o {coreRequirement=__margoCoreRequirement("0.1.0",import.me
27
27
  if (!this.#r) throw n("state", "ComputeFrame is not attached; call ComputeFrame.attach(engine)", "compute");
28
28
  return this.#r;
29
29
  }
30
+ get ready() {
31
+ return this.gpu.ready;
32
+ }
30
33
  get jobs() {
31
34
  return this.#n;
32
35
  }
package/dist/graph.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as e, r as t } from "./errors-CDgOgzCd.js";
2
- import { n } from "./context-C75sQQra.js";
3
- import { a as r } from "./expr-DwFen60A.js";
2
+ import { n } from "./context-CCvs3wkC.js";
3
+ import { a as r } from "./expr-t3jm8acM.js";
4
4
  import { CsrMatrix as i, coo as a } from "./sparse.js";
5
5
  import { t as o } from "./usingCtx-igdMnAhr.js";
6
6
  //#region src/graph.ts
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, d as t, i as n, r, t as i, u as a } from "./context-C75sQQra.js";
2
- import { a as o, n as s, r as c, t as l } from "./expr-DwFen60A.js";
3
- import { t as u } from "./array-DbI848Wf.js";
1
+ import { a as e, d as t, i as n, r, t as i, u as a } from "./context-CCvs3wkC.js";
2
+ import { a as o, n as s, r as c, t as l } from "./expr-t3jm8acM.js";
3
+ import { t as u } from "./array-C29noZq7.js";
4
4
  export { n as BoundKernel, i as ComputeContext, l as Expr, u as GpuArray, e as Kernel, s as Operand, c as broadcastShapes, r as createCompute, a as encode, t as reflectWGSL, o as where };
package/dist/linalg.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { n as e, r as t } from "./errors-CDgOgzCd.js";
2
- import { m as n, n as r, p as i, r as a } from "./expr-DwFen60A.js";
3
- import { t as o } from "./array-DbI848Wf.js";
2
+ import { m as n, n as r, p as i, r as a } from "./expr-t3jm8acM.js";
3
+ import { t as o } from "./array-C29noZq7.js";
4
4
  //#region src/linalg.ts
5
5
  var s = 64;
6
6
  function c(e, t, n) {
package/dist/nn-extra.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as e, r as t } from "./errors-CDgOgzCd.js";
2
- import { a as n } from "./expr-DwFen60A.js";
2
+ import { a as n } from "./expr-t3jm8acM.js";
3
3
  import { Random as r } from "./random.js";
4
4
  import { Module as i, Tensor as a, dropout as o, parameter as s } from "./nn.js";
5
5
  import { concatenate as c, pad as l } from "./shape.js";
package/dist/nn.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { n as e, r as t } from "./errors-CDgOgzCd.js";
2
- import { n } from "./context-C75sQQra.js";
3
- import { a as r } from "./expr-DwFen60A.js";
4
- import { t as i } from "./array-DbI848Wf.js";
2
+ import { n } from "./context-CCvs3wkC.js";
3
+ import { a as r } from "./expr-t3jm8acM.js";
4
+ import { t as i } from "./array-C29noZq7.js";
5
5
  import { matmul as a } from "./linalg.js";
6
6
  import { Random as o } from "./random.js";
7
7
  import { t as s } from "./usingCtx-igdMnAhr.js";
@@ -0,0 +1,66 @@
1
+ //#region src/onnx-image.ts
2
+ async function e(e) {
3
+ let n = (...t) => t.every((t, n) => e[n] === t);
4
+ if (n(137, 80, 78, 71)) {
5
+ let { decodePNG: e } = await import("@margoengine/decoders/png");
6
+ return (t) => e(t);
7
+ }
8
+ if (n(255, 216, 255)) return (await import("@margoengine/decoders/jpeg")).decodeJPEG;
9
+ if (n(82, 73, 70, 70) && String.fromCharCode(...e.subarray(8, 12)) === "WEBP") return (await import("@margoengine/decoders/webp")).parseWebP;
10
+ if (n(66, 77)) return (await import("@margoengine/decoders/bmp")).parseBMP;
11
+ if (n(73, 73, 42, 0) || n(77, 77, 0, 42) || n(73, 73, 43, 0) || n(77, 77, 0, 43)) {
12
+ let [{ parseTIFF: n }, { loadTIFFCodecs: r }] = await Promise.all([import("@margoengine/decoders/tiff"), import("@margoengine/decoders/tiff-codecs")]), i = await r(e).catch((e) => {
13
+ if (t(e)) return {};
14
+ throw e;
15
+ });
16
+ return (e) => {
17
+ let t = n(e, { codecs: i });
18
+ if (t.format === "rgba8unorm") return t;
19
+ let r = Uint8Array.from(t.data, (e) => e > 0 ? Math.min(255, Math.round(e * 255)) : 0);
20
+ return {
21
+ width: t.width,
22
+ height: t.height,
23
+ data: r
24
+ };
25
+ };
26
+ }
27
+ if (e[0] === 80 && e[1] >= 49 && e[1] <= 54) return (await import("@margoengine/decoders/pnm")).parsePNM;
28
+ if (n(255, 79, 255, 81) || n(0, 0, 0, 12, 106, 80, 32, 32)) {
29
+ let { loadJPEG2000: e } = await import("@margoengine/decoders/jpeg2000"), t = await e();
30
+ return (e) => t(e);
31
+ }
32
+ }
33
+ function t(e) {
34
+ let t = e?.code;
35
+ return e instanceof RangeError || t === "failed" || t === "unsupported";
36
+ }
37
+ async function n(n, r) {
38
+ let i = r === "Grayscale" ? 1 : 3, a = {
39
+ data: /* @__PURE__ */ new Uint8Array(),
40
+ shape: [
41
+ 0,
42
+ 0,
43
+ i
44
+ ]
45
+ }, o = await e(n);
46
+ if (!o) return a;
47
+ let s;
48
+ try {
49
+ s = o(n);
50
+ } catch (e) {
51
+ if (t(e)) return a;
52
+ throw e;
53
+ }
54
+ let { width: c, height: l, data: u } = s, d = new Uint8Array(c * l * i), f = r === "BGR" ? 2 : 0;
55
+ for (let e = 0, t = 0; t < d.length; e += 4, t += i) i === 1 ? d[t] = (u[e] * 299 + u[e + 1] * 587 + u[e + 2] * 114 + 500) / 1e3 | 0 : (d[t] = u[e + f], d[t + 1] = u[e + 1], d[t + 2] = u[e + 2 - f]);
56
+ return {
57
+ data: d,
58
+ shape: [
59
+ l,
60
+ c,
61
+ i
62
+ ]
63
+ };
64
+ }
65
+ //#endregion
66
+ export { n as decodeImagePixels };
@@ -0,0 +1,10 @@
1
+ /** What ImageDecoder returns: bytes in height, width, channel order. */
2
+ export interface ImagePixels {
3
+ data: Uint8Array;
4
+ shape: [number, number, number];
5
+ }
6
+ /**
7
+ * Decodes one encoded image to `[height, width, 3]` (RGB or BGR) or `[height, width, 1]` (Grayscale) bytes, alpha
8
+ * dropped. A stream that cannot be decoded gives the empty matrix `[0, 0, channels]`, as the operator specifies.
9
+ */
10
+ export declare function decodeImagePixels(bytes: Uint8Array, format: string): Promise<ImagePixels>;
Binary file
@@ -0,0 +1,331 @@
1
+ import { r as e } from "./errors-CDgOgzCd.js";
2
+ //#region src/onnx-regex.ts
3
+ var t = 1e5, n = {
4
+ d: "09",
5
+ s: " \n\f\r ",
6
+ w: "09AZaz__"
7
+ }, r = {
8
+ alnum: "09AZaz",
9
+ alpha: "AZaz",
10
+ ascii: "\0",
11
+ blank: " ",
12
+ cntrl: "\0",
13
+ digit: "09",
14
+ graph: "!~",
15
+ lower: "az",
16
+ print: " ~",
17
+ punct: "!/:@[`{~",
18
+ space: " \r ",
19
+ upper: "AZ",
20
+ word: "09AZaz__",
21
+ xdigit: "09AFaf"
22
+ }, i = {
23
+ a: 7,
24
+ f: 12,
25
+ t: 9,
26
+ n: 10,
27
+ r: 13,
28
+ v: 11
29
+ }, a = (e) => `\\u{${e.toString(16)}}`;
30
+ function o(e, t, n) {
31
+ let r = RegExp(`^[${t ? "^" : ""}${e}]$`, n ? "iu" : "u");
32
+ return (e) => r.test(String.fromCodePoint(e));
33
+ }
34
+ function s(e) {
35
+ let t = "";
36
+ for (let n = 0; n < e.length; n += 2) t += `${a(e.charCodeAt(n))}-${a(e.charCodeAt(n + 1))}`;
37
+ return t;
38
+ }
39
+ var c = (e) => e >= 48 && e <= 57 || e >= 65 && e <= 90 || e >= 97 && e <= 122 || e === 95, l = class {
40
+ #e;
41
+ #t = 0;
42
+ #n = 0;
43
+ constructor(e) {
44
+ this.#e = Array.from(e);
45
+ }
46
+ fail(t) {
47
+ throw e(`ONNX RegexFullMatch pattern ${t} at character ${this.#t}; use RE2 syntax`, "compute");
48
+ }
49
+ #r(e = 0) {
50
+ return this.#e[this.#t + e];
51
+ }
52
+ #i() {
53
+ let e = this.#e[this.#t++];
54
+ return e === void 0 && this.fail("ends early"), e;
55
+ }
56
+ #a(e) {
57
+ return Array.from(e).every((e, t) => this.#r(t) === e) ? (this.#t += e.length, !0) : !1;
58
+ }
59
+ parse() {
60
+ let e = this.#o({
61
+ i: !1,
62
+ m: !1,
63
+ s: !1
64
+ });
65
+ return this.#t < this.#e.length && this.fail("has an unmatched )"), e;
66
+ }
67
+ #o(e) {
68
+ let t = { ...e }, n = [this.#s(t)];
69
+ for (; this.#a("|");) n.push(this.#s(t));
70
+ return n.length === 1 ? n[0] : {
71
+ op: "either",
72
+ items: n
73
+ };
74
+ }
75
+ #s(e) {
76
+ let t = [], n = !0;
77
+ for (; this.#r() !== void 0 && this.#r() !== "|" && this.#r() !== ")";) {
78
+ let r = this.#c();
79
+ if (r) {
80
+ let e = t.pop();
81
+ (!e || n) && this.fail("repeats nothing or repeats a repetition"), t.push({
82
+ op: "repeat",
83
+ item: e,
84
+ min: r[0],
85
+ max: r[1]
86
+ }), this.#a("?"), n = !0;
87
+ continue;
88
+ }
89
+ if (n = !1, this.#a("\\Q")) {
90
+ for (; this.#r() !== void 0 && !this.#a("\\E");) t.push(this.#l(this.#i().codePointAt(0), e));
91
+ continue;
92
+ }
93
+ let i = this.#u(e);
94
+ i ? t.push(i) : n = !0;
95
+ }
96
+ return {
97
+ op: "sequence",
98
+ items: t
99
+ };
100
+ }
101
+ #c() {
102
+ if (this.#a("*")) return [0, Infinity];
103
+ if (this.#a("+")) return [1, Infinity];
104
+ if (this.#a("?")) return [0, 1];
105
+ if (this.#r() !== "{") return null;
106
+ let e = /^\{(\d+)(,(\d*))?\}/.exec(this.#e.slice(this.#t, this.#t + 24).join(""));
107
+ if (!e) return null;
108
+ let t = Number(e[1]), n = e[2] === void 0 ? t : e[3] === "" ? Infinity : Number(e[3]);
109
+ return (t > 1e3 || n !== Infinity && n > 1e3 || n < t) && this.fail("has a repetition count outside 0..1000"), this.#t += e[0].length, [t, n];
110
+ }
111
+ #l(e, t) {
112
+ return {
113
+ op: "char",
114
+ test: t.i ? o(a(e), !1, !0) : (t) => t === e
115
+ };
116
+ }
117
+ #u(e) {
118
+ let t = this.#i();
119
+ if (t === ".") {
120
+ let t = e.s;
121
+ return {
122
+ op: "char",
123
+ test: (e) => t || e !== 10
124
+ };
125
+ }
126
+ if (t === "^") return {
127
+ op: "anchor",
128
+ at: e.m ? "line-start" : "text-start"
129
+ };
130
+ if (t === "$") return {
131
+ op: "anchor",
132
+ at: e.m ? "line-end" : "text-end"
133
+ };
134
+ if (t === "(") return this.#d(e);
135
+ if (t === "[") return {
136
+ op: "char",
137
+ test: this.#m(e)
138
+ };
139
+ if (t === "\\") {
140
+ if (this.#a("A")) return {
141
+ op: "anchor",
142
+ at: "text-start"
143
+ };
144
+ if (this.#a("z")) return {
145
+ op: "anchor",
146
+ at: "text-end"
147
+ };
148
+ if (this.#a("b")) return {
149
+ op: "anchor",
150
+ at: "word"
151
+ };
152
+ if (this.#a("B")) return {
153
+ op: "anchor",
154
+ at: "not-word"
155
+ };
156
+ let t = this.#f(e);
157
+ return t ? {
158
+ op: "char",
159
+ test: t
160
+ } : this.#l(this.#p(), e);
161
+ }
162
+ return this.#l(t.codePointAt(0), e);
163
+ }
164
+ #d(e) {
165
+ ++this.#n > 200 && this.fail("nests more than 200 groups");
166
+ let t = e;
167
+ if (this.#a("?")) {
168
+ if (this.#a("P<") || this.#r() === "<" && !"=!".includes(this.#r(1) ?? "=") && this.#a("<")) {
169
+ let e = "";
170
+ for (; this.#r() !== ">";) e += this.#i();
171
+ this.#t++, /^\w+$/.test(e) || this.fail("has a bad group name");
172
+ } else {
173
+ t = { ...e };
174
+ let n = !0;
175
+ for (;;) {
176
+ let r = this.#i();
177
+ if (r === ":") break;
178
+ if (r === ")") return Object.assign(e, t), this.#n--, null;
179
+ r === "-" && n ? n = !1 : r === "i" || r === "m" || r === "s" ? t[r] = n : r !== "U" && this.fail("has a group or flag RE2 does not support (no lookaround)");
180
+ }
181
+ }
182
+ }
183
+ let n = this.#o(t);
184
+ return this.#a(")") || this.fail("has an unclosed group"), this.#n--, n;
185
+ }
186
+ #f(e) {
187
+ let t = this.#r();
188
+ t === void 0 && this.fail("ends with a backslash");
189
+ let r = n[t.toLowerCase()];
190
+ if (r) return this.#t++, o(s(r), t !== t.toLowerCase(), e.i);
191
+ if (t !== "p" && t !== "P") return null;
192
+ this.#t++;
193
+ let i = this.#i();
194
+ if (i === "{") {
195
+ for (i = ""; this.#r() !== "}";) i += this.#i();
196
+ this.#t++;
197
+ }
198
+ /^\w+$/.test(i) || this.fail("has a bad Unicode class name");
199
+ for (let n of [i, `Script=${i}`]) try {
200
+ return o(`\\p{${n}}`, t === "P", e.i);
201
+ } catch (e) {
202
+ if (!(e instanceof SyntaxError)) throw e;
203
+ }
204
+ return this.fail(`names an unknown Unicode class ${i}`);
205
+ }
206
+ #p() {
207
+ let e = this.#i();
208
+ if (e in i) return i[e];
209
+ if (e === "x") {
210
+ let e = "";
211
+ if (this.#a("{")) {
212
+ for (; this.#r() !== "}";) e += this.#i();
213
+ this.#t++;
214
+ } else e = this.#i() + this.#i();
215
+ let t = /^[0-9a-f]+$/i.test(e) ? parseInt(e, 16) : Infinity;
216
+ return t > 1114111 && this.fail("has a bad hexadecimal escape"), t;
217
+ }
218
+ if (/[0-7]/.test(e)) {
219
+ e !== "0" && !/[0-7]/.test(this.#r() ?? "") && this.fail("uses a backreference");
220
+ let t = e;
221
+ for (; t.length < 3 && /[0-7]/.test(this.#r() ?? "");) t += this.#i();
222
+ return parseInt(t, 8);
223
+ }
224
+ let t = e.codePointAt(0);
225
+ return t < 128 && !/[0-9A-Za-z]/.test(e) ? t : this.fail(`has an unsupported escape \\${e}`);
226
+ }
227
+ #m(e) {
228
+ let t = this.#a("^"), n = [], i = "", c = !0;
229
+ for (; c || this.#r() !== "]";) {
230
+ if (c = !1, this.#r() === "[" && this.#r(1) === ":") {
231
+ let t = /^\[:(\^?)([a-z]+):\]/.exec(this.#e.slice(this.#t, this.#t + 12).join(""));
232
+ if (t) {
233
+ let i = r[t[2]];
234
+ i || this.fail(`names an unknown ASCII class ${t[2]}`), this.#t += t[0].length, n.push(o(s(i), t[1] === "^", e.i));
235
+ continue;
236
+ }
237
+ }
238
+ let t;
239
+ if (this.#a("\\")) {
240
+ let r = this.#f(e);
241
+ if (r) {
242
+ n.push(r);
243
+ continue;
244
+ }
245
+ t = this.#p();
246
+ } else t = this.#i().codePointAt(0);
247
+ if (this.#r() === "-" && this.#r(1) !== "]" && this.#r(1) !== void 0) {
248
+ this.#t++;
249
+ let e = this.#a("\\") ? this.#p() : this.#i().codePointAt(0);
250
+ e < t && this.fail("has a reversed range"), i += `${a(t)}-${a(e)}`;
251
+ } else i += a(t);
252
+ }
253
+ return this.#t++, i && n.push(o(i, !1, e.i)), (e) => n.some((t) => t(e)) !== t;
254
+ }
255
+ };
256
+ function u(e) {
257
+ return e.op === "sequence" ? e.items.every(u) : e.op === "repeat" && (e.max === 0 || u(e.item));
258
+ }
259
+ function d(n, r) {
260
+ let i = (n) => {
261
+ if (r.length >= t) throw e("ONNX RegexFullMatch pattern expands past 100000 instructions; lower its repetitions", "compute");
262
+ return r.push(n) - 1;
263
+ };
264
+ if (n.op === "char" || n.op === "anchor") i(n);
265
+ else if (n.op === "sequence") for (let e of n.items) d(e, r);
266
+ else if (n.op === "either") {
267
+ let e = {
268
+ op: "split",
269
+ to: []
270
+ };
271
+ i(e);
272
+ let t = [];
273
+ for (let a of n.items) {
274
+ e.to.push(r.length), d(a, r);
275
+ let n = {
276
+ op: "split",
277
+ to: []
278
+ };
279
+ i(n), t.push(n);
280
+ }
281
+ for (let e of t) e.to.push(r.length);
282
+ } else {
283
+ if (u(n)) return;
284
+ for (let e = 0; e < n.min; e++) d(n.item, r);
285
+ if (n.max === Infinity) {
286
+ let e = {
287
+ op: "split",
288
+ to: []
289
+ }, t = i(e);
290
+ e.to.push(r.length), d(n.item, r), i({
291
+ op: "split",
292
+ to: [t]
293
+ }), e.to.push(r.length);
294
+ } else {
295
+ let e = [];
296
+ for (let t = n.min; t < n.max; t++) {
297
+ let t = {
298
+ op: "split",
299
+ to: []
300
+ };
301
+ i(t), t.to.push(r.length), e.push(t), d(n.item, r);
302
+ }
303
+ for (let t of e) t.to.push(r.length);
304
+ }
305
+ }
306
+ }
307
+ function f(e) {
308
+ let t = [];
309
+ return d(new l(e).parse(), t), t.push({ op: "match" }), (e) => {
310
+ let n = Array.from(e, (e) => e.codePointAt(0)), r = new Int32Array(t.length).fill(-1), i = (e, t) => e === "text-start" ? t === 0 : e === "text-end" ? t === n.length : e === "line-start" ? t === 0 || n[t - 1] === 10 : e === "line-end" ? t === n.length || n[t] === 10 : (t > 0 && c(n[t - 1])) !== (t < n.length && c(n[t])) == (e === "word"), a = [0];
311
+ for (let e = 0;; e++) {
312
+ let o = [], s = a, c = !1;
313
+ for (; s.length;) {
314
+ let n = s.pop();
315
+ if (r[n] === e) continue;
316
+ r[n] = e;
317
+ let a = t[n];
318
+ a.op === "split" ? s.push(...a.to) : a.op === "anchor" ? i(a.at, e) && s.push(n + 1) : a.op === "char" ? o.push({
319
+ test: a.test,
320
+ next: n + 1
321
+ }) : c = !0;
322
+ }
323
+ if (e === n.length) return c;
324
+ a = [];
325
+ for (let { test: t, next: r } of o) t(n[e]) && a.push(r);
326
+ if (!a.length) return !1;
327
+ }
328
+ };
329
+ }
330
+ //#endregion
331
+ export { f as fullMatcher };
@@ -0,0 +1,2 @@
1
+ /** Compiles an RE2 pattern into a test of whether the whole string matches it. */
2
+ export declare function fullMatcher(pattern: string): (text: string) => boolean;
package/dist/onnx.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  /// <reference lib="esnext.disposable" preserve="true" />
2
- /** ONNX's portable web tensor storage types. Half/bfloat16 use raw Uint16 bits; int4 uses packed low nibble first. */
3
- export type OnnxDType = 'float32' | 'uint8' | 'int8' | 'uint16' | 'int16' | 'int32' | 'int64' | 'string' | 'bool' | 'float16' | 'float64' | 'uint32' | 'uint64' | 'bfloat16' | 'uint4' | 'int4';
2
+ /** ONNX's tensor storage types. Half, bfloat16 and the 8-bit floats use raw bits in Uint16 or Uint8 arrays; the 4-bit
3
+ * types pack two elements a byte and the 2-bit types four, first element in the low bits; the 6-bit floats are a
4
+ * little-endian bit stream. Complex values interleave
5
+ * real and imaginary parts. */
6
+ export type OnnxDType = 'float32' | 'uint8' | 'int8' | 'uint16' | 'int16' | 'int32' | 'int64' | 'string' | 'bool' | 'float16' | 'float64' | 'uint32' | 'uint64' | 'complex64' | 'complex128' | 'bfloat16' | 'float8e4m3fn' | 'float8e4m3fnuz' | 'float8e5m2' | 'float8e5m2fnuz' | 'uint4' | 'int4' | 'float4e2m1' | 'float8e8m0' | 'uint2' | 'int2' | 'float6e2m3' | 'float6e3m2';
4
7
  /** Host storage accepted and copied by an ONNX tensor. */
5
8
  export type OnnxData = Float32Array | Float64Array | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | readonly string[];
6
9
  /** Owned host tensor. Construction copies the supplied data; returned inference tensors outlive their model. */