@graphty/webgpu-graph-algorithms 0.6.13 → 0.6.15

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.
Files changed (95) hide show
  1. package/README.md +52 -52
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{context-Bi6AhScG.js → context-oXphO3yj.js} +36 -28
  4. package/dist/chunks/context-oXphO3yj.js.map +1 -0
  5. package/dist/node.js +1 -1
  6. package/dist/src/accelerator.d.ts +3 -2
  7. package/dist/src/accelerator.d.ts.map +1 -1
  8. package/dist/src/accelerator.js +48 -4
  9. package/dist/src/accelerator.js.map +1 -1
  10. package/dist/src/algorithms/betweenness.d.ts +70 -0
  11. package/dist/src/algorithms/betweenness.d.ts.map +1 -0
  12. package/dist/src/algorithms/betweenness.js +538 -0
  13. package/dist/src/algorithms/betweenness.js.map +1 -0
  14. package/dist/src/algorithms/closeness.d.ts +15 -5
  15. package/dist/src/algorithms/closeness.d.ts.map +1 -1
  16. package/dist/src/algorithms/closeness.js +112 -26
  17. package/dist/src/algorithms/closeness.js.map +1 -1
  18. package/dist/src/constants.d.ts +8 -0
  19. package/dist/src/constants.d.ts.map +1 -1
  20. package/dist/src/constants.js +8 -0
  21. package/dist/src/constants.js.map +1 -1
  22. package/dist/src/index.d.ts +4 -2
  23. package/dist/src/index.d.ts.map +1 -1
  24. package/dist/src/index.js +1 -0
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/kernels.d.ts +12 -6
  27. package/dist/src/kernels.d.ts.map +1 -1
  28. package/dist/src/kernels.js +153 -7
  29. package/dist/src/kernels.js.map +1 -1
  30. package/dist/src/primitives/frontier.d.ts +2 -0
  31. package/dist/src/primitives/frontier.d.ts.map +1 -1
  32. package/dist/src/primitives/frontier.js +2 -0
  33. package/dist/src/primitives/frontier.js.map +1 -1
  34. package/dist/src/types/accelerator.d.ts +11 -7
  35. package/dist/src/types/accelerator.d.ts.map +1 -1
  36. package/dist/src/types/algorithms.d.ts +4 -0
  37. package/dist/src/types/algorithms.d.ts.map +1 -1
  38. package/dist/src/types/betweenness.d.ts +35 -0
  39. package/dist/src/types/betweenness.d.ts.map +1 -0
  40. package/dist/src/types/betweenness.js +7 -0
  41. package/dist/src/types/betweenness.js.map +1 -0
  42. package/dist/src/wgsl/bc-backward.wgsl.d.ts +15 -0
  43. package/dist/src/wgsl/bc-backward.wgsl.d.ts.map +1 -0
  44. package/dist/src/wgsl/bc-backward.wgsl.js +34 -0
  45. package/dist/src/wgsl/bc-backward.wgsl.js.map +1 -0
  46. package/dist/src/wgsl/bc-edge-gather.wgsl.d.ts +12 -0
  47. package/dist/src/wgsl/bc-edge-gather.wgsl.d.ts.map +1 -0
  48. package/dist/src/wgsl/bc-edge-gather.wgsl.js +36 -0
  49. package/dist/src/wgsl/bc-edge-gather.wgsl.js.map +1 -0
  50. package/dist/src/wgsl/bc-finalize.wgsl.d.ts +21 -0
  51. package/dist/src/wgsl/bc-finalize.wgsl.d.ts.map +1 -0
  52. package/dist/src/wgsl/bc-finalize.wgsl.js +47 -0
  53. package/dist/src/wgsl/bc-finalize.wgsl.js.map +1 -0
  54. package/dist/src/wgsl/bc-forward-edge.wgsl.d.ts +15 -0
  55. package/dist/src/wgsl/bc-forward-edge.wgsl.d.ts.map +1 -0
  56. package/dist/src/wgsl/bc-forward-edge.wgsl.js +76 -0
  57. package/dist/src/wgsl/bc-forward-edge.wgsl.js.map +1 -0
  58. package/dist/src/wgsl/bc-forward.wgsl.d.ts +23 -0
  59. package/dist/src/wgsl/bc-forward.wgsl.d.ts.map +1 -0
  60. package/dist/src/wgsl/bc-forward.wgsl.js +106 -0
  61. package/dist/src/wgsl/bc-forward.wgsl.js.map +1 -0
  62. package/dist/src/wgsl/bc-gather.wgsl.d.ts +9 -0
  63. package/dist/src/wgsl/bc-gather.wgsl.d.ts.map +1 -0
  64. package/dist/src/wgsl/bc-gather.wgsl.js +20 -0
  65. package/dist/src/wgsl/bc-gather.wgsl.js.map +1 -0
  66. package/dist/src/wgsl/closeness-reduce.wgsl.d.ts +4 -1
  67. package/dist/src/wgsl/closeness-reduce.wgsl.d.ts.map +1 -1
  68. package/dist/src/wgsl/closeness-reduce.wgsl.js +8 -4
  69. package/dist/src/wgsl/closeness-reduce.wgsl.js.map +1 -1
  70. package/dist/src/wgsl/closeness-sweep.wgsl.d.ts +4 -2
  71. package/dist/src/wgsl/closeness-sweep.wgsl.d.ts.map +1 -1
  72. package/dist/src/wgsl/closeness-sweep.wgsl.js +12 -2
  73. package/dist/src/wgsl/closeness-sweep.wgsl.js.map +1 -1
  74. package/dist/webgpu-graph-algorithms.js +1037 -168
  75. package/dist/webgpu-graph-algorithms.js.map +1 -1
  76. package/package.json +5 -5
  77. package/src/accelerator.ts +75 -7
  78. package/src/algorithms/betweenness.ts +739 -0
  79. package/src/algorithms/closeness.ts +124 -32
  80. package/src/constants.ts +8 -0
  81. package/src/index.ts +8 -0
  82. package/src/kernels.ts +169 -10
  83. package/src/primitives/frontier.ts +4 -0
  84. package/src/types/accelerator.ts +18 -6
  85. package/src/types/algorithms.ts +5 -0
  86. package/src/types/betweenness.ts +38 -0
  87. package/src/wgsl/bc-backward.wgsl.ts +33 -0
  88. package/src/wgsl/bc-edge-gather.wgsl.ts +35 -0
  89. package/src/wgsl/bc-finalize.wgsl.ts +46 -0
  90. package/src/wgsl/bc-forward-edge.wgsl.ts +75 -0
  91. package/src/wgsl/bc-forward.wgsl.ts +105 -0
  92. package/src/wgsl/bc-gather.wgsl.ts +19 -0
  93. package/src/wgsl/closeness-reduce.wgsl.ts +8 -4
  94. package/src/wgsl/closeness-sweep.wgsl.ts +12 -2
  95. package/dist/chunks/context-Bi6AhScG.js.map +0 -1
package/dist/node.js CHANGED
@@ -1,4 +1,4 @@
1
- import { W as WebGpuGraphError, G as GpuContext } from "./chunks/context-Bi6AhScG.js";
1
+ import { W as WebGpuGraphError, G as GpuContext } from "./chunks/context-oXphO3yj.js";
2
2
  const INSTALL_HINT = "install the optional peer dependency webgpu@0.4.0";
3
3
  const instances = /* @__PURE__ */ new Map();
4
4
  function isDawnModule(loaded) {
@@ -19,8 +19,9 @@ import { type AcceleratorOptions, type GpuAccelerator } from "./types/accelerato
19
19
  * Spec 3.3 createAccelerator, verbatim: the object implementing AlgorithmAccelerator & LayoutAccelerator
20
20
  * structurally; P3's forceAtlas2, release and dispose, P5's fruchtermanReingold and springElectrical (the same
21
21
  * `{ ...o, ...options.layout }` shape as forceAtlas2) plus P7's seven algorithm members and P8's four traversal
22
- * members, each a delegation to its algorithm with `ctx.assertReady()` first. The accelerator's algorithm defaults are not consulted by any of
23
- * them: only `betweenness` has any, and it belongs to P9. One per call (the app creates one and injects
22
+ * members and the two betweenness members, each a delegation to its algorithm with `ctx.assertReady()` first. Only
23
+ * the betweenness members consult the accelerator's algorithm defaults (`algorithms.betweenness` supplies `sources` /
24
+ * `k` when a call names neither). One per call (the app creates one and injects
24
25
  * it, spec 2.4); `kind` is "webgpu"; `options` is a frozen deep copy; `forceAtlas2(o)` is
25
26
  * `createForceAtlas2(ctx, { ...o, ...options.layout })`, so the GPU tuning given here wins over anything the
26
27
  * CPU-typed option object carries (spec 3.3: tuning never comes from the caller of the accelerator method);
@@ -1 +1 @@
1
- {"version":3,"file":"accelerator.d.ts","sourceRoot":"","sources":["../../src/accelerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,EACH,KAAK,kBAAkB,EAEvB,KAAK,cAAc,EAGtB,MAAM,wBAAwB,CAAC;AAiFhC;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc,CA4K/F"}
1
+ {"version":3,"file":"accelerator.d.ts","sourceRoot":"","sources":["../../src/accelerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/C,OAAO,EACH,KAAK,kBAAkB,EAIvB,KAAK,cAAc,EAEtB,MAAM,wBAAwB,CAAC;AA2GhC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc,CAmN/F"}
@@ -14,6 +14,7 @@
14
14
  * algorithm members arrive one per shipped algorithm from P9.
15
15
  */
16
16
  import { bellmanFord } from "./algorithms/bellman-ford.js";
17
+ import { betweennessCentrality, edgeBetweennessCentrality } from "./algorithms/betweenness.js";
17
18
  import { breadthFirstSearch } from "./algorithms/bfs.js";
18
19
  import { closenessCentrality } from "./algorithms/closeness.js";
19
20
  import { connectedComponents } from "./algorithms/components.js";
@@ -36,6 +37,25 @@ function copyBetweenness(defaults) {
36
37
  }
37
38
  return Object.freeze(copy);
38
39
  }
40
+ /**
41
+ * A betweenness call's options with the accelerator's `algorithms.betweenness` defaults applied: the defaults supply
42
+ * `sources` / `k` only when the call names neither, so a call's own sampling always wins whole. The defaults serve
43
+ * graphs of every size, so they are fitted to this one: a default `sources` list keeps only the indices below
44
+ * `nodeCount` (and then wins over a default `k`), and a default `k` of `nodeCount` or more runs every vertex.
45
+ * @param defaults - the frozen defaults, if any
46
+ * @param options - the call's options
47
+ * @param nodeCount - the snapshot's vertex count
48
+ * @returns the options the driver runs with
49
+ */
50
+ function withBetweennessDefaults(defaults, options, nodeCount) {
51
+ if (defaults === undefined || options?.sources !== undefined || options?.k !== undefined) {
52
+ return options;
53
+ }
54
+ if (defaults.sources !== undefined) {
55
+ return { ...options, sources: defaults.sources.filter((v) => v < nodeCount) };
56
+ }
57
+ return { ...options, k: defaults.k !== undefined && defaults.k < nodeCount ? defaults.k : undefined };
58
+ }
39
59
  /**
40
60
  * Frozen copy of the algorithms record, one level deeper for `betweenness`.
41
61
  * @param algorithms - the caller's record
@@ -73,8 +93,9 @@ function freezeOptions(options) {
73
93
  * Spec 3.3 createAccelerator, verbatim: the object implementing AlgorithmAccelerator & LayoutAccelerator
74
94
  * structurally; P3's forceAtlas2, release and dispose, P5's fruchtermanReingold and springElectrical (the same
75
95
  * `{ ...o, ...options.layout }` shape as forceAtlas2) plus P7's seven algorithm members and P8's four traversal
76
- * members, each a delegation to its algorithm with `ctx.assertReady()` first. The accelerator's algorithm defaults are not consulted by any of
77
- * them: only `betweenness` has any, and it belongs to P9. One per call (the app creates one and injects
96
+ * members and the two betweenness members, each a delegation to its algorithm with `ctx.assertReady()` first. Only
97
+ * the betweenness members consult the accelerator's algorithm defaults (`algorithms.betweenness` supplies `sources` /
98
+ * `k` when a call names neither). One per call (the app creates one and injects
78
99
  * it, spec 2.4); `kind` is "webgpu"; `options` is a frozen deep copy; `forceAtlas2(o)` is
79
100
  * `createForceAtlas2(ctx, { ...o, ...options.layout })`, so the GPU tuning given here wins over anything the
80
101
  * CPU-typed option object carries (spec 3.3: tuning never comes from the caller of the accelerator method);
@@ -227,12 +248,35 @@ export function createAccelerator(ctx, options) {
227
248
  ctx.assertReady();
228
249
  return await bellmanFord(ctx, gs, source, o);
229
250
  },
251
+ /**
252
+ * Betweenness centrality on the device (spec 8.4): exact, or sampled through `sources` / `k` (the call's own,
253
+ * else the accelerator's `algorithms.betweenness` defaults), the unscaled sum over the sources run.
254
+ * `endpoints: true` is refused.
255
+ * @param gs - the snapshot
256
+ * @param o - the seam's `BetweennessAcceleratorOptions`
257
+ * @returns the f32 scores with `sourcesUsed` and `sigmaOverflow`
258
+ */
259
+ async betweennessCentrality(gs, o) {
260
+ ctx.assertReady();
261
+ return await betweennessCentrality(ctx, gs, withBetweennessDefaults(frozen.algorithms?.betweenness, o, gs.nodeCount));
262
+ },
263
+ /**
264
+ * Edge betweenness on the device (spec 8.4): one score per edge, arcs summed and halved when undirected; sampling
265
+ * and defaults as `betweennessCentrality`.
266
+ * @param gs - the snapshot
267
+ * @param o - the seam's `BetweennessAcceleratorOptions`
268
+ * @returns the f32 per-edge scores with `sourcesUsed` and `sigmaOverflow`
269
+ */
270
+ async edgeBetweennessCentrality(gs, o) {
271
+ ctx.assertReady();
272
+ return await edgeBetweennessCentrality(ctx, gs, withBetweennessDefaults(frozen.algorithms?.betweenness, o, gs.nodeCount));
273
+ },
230
274
  /**
231
275
  * Closeness centrality on the device (spec 8.4; P8-T13): the bit-parallel multi-source sweep, or one `sssp`
232
276
  * per source when `weighted`. `maxIterations` / `tolerance` are refused when defined (P8 PD-25).
233
277
  * @param gs - the snapshot
234
- * @param o - the seam's placeholder `HitsOptionsLike` (`weighted`)
235
- * @returns the f32 scores with `precision: "f32"` (spec 9.7)
278
+ * @param o - `weighted`, and a sampled run's `sources` (undirected snapshots only)
279
+ * @returns the f32 scores with `precision: "f32"` (spec 9.7) and `sourcesUsed`
236
280
  */
237
281
  async closenessCentrality(gs, o) {
238
282
  ctx.assertReady();
@@ -1 +1 @@
1
- {"version":3,"file":"accelerator.js","sourceRoot":"","sources":["../../src/accelerator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,sBAAsB,EAAE,M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
+ * Betweenness and edge betweenness on the device (design 8.4 "Betweenness (A7)", 3.3 lines 811-812, 9.7): Brandes'
3
+ * algorithm as McLaughlin-Bader run it, k sources at a time.
4
+ *
5
+ * A source batch keeps four `n x k` arrays -- `depthK`, `sigmaK` (u32 shortest-path counts), `deltaK` (f32
6
+ * dependencies) and the claim log `S` -- plus `ends`, the level boundaries into the log. Every array is indexed by
7
+ * `s * n + v`, and a log entry IS that index, so one u32 names a `(vertex, source)` pair: `4 n k` bytes can never
8
+ * reach 2^32 because each array is one storage binding. The forward pass is a tagged breadth-first search: every
9
+ * level is `bc-finalize` (the boundary: `ends[level + 1] = stackTop`, `done` on an empty level) and then ONE forward
10
+ * dispatch, either `bc-forward` (block-mapped over the level's range of the log) or `bc-forward-edge` (every edge of
11
+ * the `edgeList` view for every source), both claiming, counting and appending with the same rules. Levels are
12
+ * recorded `MAX_LEVELS_PER_SUBMIT` per submit with one small readback (the counters block and the `ends` prefix), and
13
+ * the log's `ends` is known on the host when the forward phase ends, so the backward pass is planned exactly: one
14
+ * `bc-backward` dispatch per level from the deepest to depth 1, each writing `delta[s][w]` once by pulling over the
15
+ * successors; then `bc-gather` adds each vertex's k dependencies into `bc` (and `bc-edge-gather` each arc's k terms
16
+ * into `arcScores`). Nothing accumulates a float through an atomic, so the scores are bitwise reproducible.
17
+ *
18
+ * The batch size k is planned from the device limits at 16 bytes per (node, source) -- the three arrays design 4.7
19
+ * counts plus the 4-byte log entry it omits -- as `min(floor(maxStorageBufferBindingSize / 4n), floor(0.25 x
20
+ * maxBufferSize / 16n), 64)`, at least 1 (`planBatchSize`); a graph whose single source does not fit one binding is
21
+ * E_TOO_LARGE. The forward form is chosen per batch: the first batch runs `bc-forward`; a later one runs the
22
+ * edge-parallel form when the previous batch's level count -- the MAXIMUM depth over its sources, the only depth
23
+ * figure the host has, which over-estimates the median of design 8.4's rule and so errs toward the frontier form --
24
+ * is below `BC_EDGE_PARALLEL_GAMMA x log2(n)`.
25
+ *
26
+ * The host applies the CPU package's convention after the readback (`@graphty/algorithms` betweenness.ts): the vertex
27
+ * scores are halved on an undirected snapshot (the gather counts each unordered pair from both ends); the edge scores
28
+ * are folded with `foldArcs(s, perArc, "sum")` and halved the same way, because an undirected edge's two arcs carry
29
+ * the pairs that cross it in each direction. Over every source both arcs hold the same sum, but over a sample they do
30
+ * not: on the path 0-1-2 with the one source 2, arc 1->0 collects 1 and arc 0->1 collects 0, so keeping either arc
31
+ * alone would lose the pairs crossing the other way. `normalized`
32
+ * divides both by `(n - 1)(n - 2)` directed or half that undirected, when positive. A sampled run (`sources` or `k`)
33
+ * is the UNSCALED sum over the sources run, reported beside `sourcesUsed`. `endpoints: true` is refused: the CPU's
34
+ * endpoints branch (`algorithms/src/algorithms/centrality/betweenness.ts`, `predecessors.length === 0 && w !==
35
+ * source`) can never fire for a vertex on the Brandes stack, so there is no behaviour to be in parity with.
36
+ * Betweenness is breadth-first on both packages; weights are ignored. Parallel edges are distinct shortest paths
37
+ * here (each arc adds to sigma), where the CPU package refuses them or, with `allowParallelEdges`, collapses them to
38
+ * one: on a multigraph the two packages' scores differ.
39
+ */
40
+ import { type GraphSnapshot } from "@graphty/graph-format";
41
+ import { type GpuContext } from "../context.js";
42
+ import { type BetweennessAcceleratorOptions } from "../types/accelerator.js";
43
+ import { type GpuBetweennessResult, type GpuEdgeScoresResult } from "../types/betweenness.js";
44
+ import { type GpuRunOptions } from "../types/run.js";
45
+ /**
46
+ * Betweenness centrality on the device (spec 3.3 line 811, design 8.4): Brandes' algorithm, k sources per batch.
47
+ * Exact over every vertex by default; `sources` or `k` gives the SAMPLED form, whose scores are the unscaled sum over
48
+ * the sources run (`sourcesUsed` beside them; multiply by `n / sourcesUsed` for the estimator of the full sum). The
49
+ * CPU package's convention: halved on an undirected snapshot, `normalized` divides by `(n - 1)(n - 2)` directed or
50
+ * half that undirected. Weights are ignored (breadth-first on both packages). `endpoints: true` is E_UNSUPPORTED.
51
+ * `sigmaOverflow` is true when some pair has more than 2^32 shortest paths: the scores are then wrong.
52
+ * @param ctx - the context whose device runs the kernels
53
+ * @param s - the snapshot (uploaded through ctx.residency, or found there)
54
+ * @param options - `normalized`, `endpoints`, `sources`, `k`, plus dest (a Float32Array of length n) / signal / onProgress (sources done, sources total)
55
+ * @returns the f32 scores, `iterations` (the source batches run), `converged: true`, `sourcesUsed`, `sigmaOverflow`
56
+ */
57
+ export declare function betweennessCentrality(ctx: GpuContext, s: GraphSnapshot, options?: BetweennessAcceleratorOptions & GpuRunOptions): Promise<GpuBetweennessResult>;
58
+ /**
59
+ * Edge betweenness centrality on the device (spec 3.3 line 812, design 8.4): the per-arc terms of the same batches,
60
+ * folded to one score per edge with `foldArcs(s, perArc, "sum")` and halved on an undirected snapshot (the two arcs
61
+ * carry the pairs crossing the edge in each direction, so their sum counts each unordered pair twice; this is the CPU
62
+ * package's number, and it holds for a sample too). `normalized`, sampling, `endpoints` and `sigmaOverflow` as in
63
+ * `betweennessCentrality`.
64
+ * @param ctx - the context whose device runs the kernels
65
+ * @param s - the snapshot (uploaded through ctx.residency, or found there)
66
+ * @param options - as `betweennessCentrality`, dest a Float32Array of length edgeCount
67
+ * @returns the f32 per-edge scores, `sourcesUsed`, `sigmaOverflow`
68
+ */
69
+ export declare function edgeBetweennessCentrality(ctx: GpuContext, s: GraphSnapshot, options?: BetweennessAcceleratorOptions & GpuRunOptions): Promise<GpuEdgeScoresResult>;
70
+ //# sourceMappingURL=betweenness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"betweenness.d.ts","sourceRoot":"","sources":["../../../src/algorithms/betweenness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAsB,KAAK,aAAa,EAAY,MAAM,uBAAuB,CAAC;AASzF,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAShD,OAAO,EAAE,KAAK,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9F,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgoBrD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACjC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,aAAa,EAChB,OAAO,CAAC,EAAE,6BAA6B,GAAG,aAAa,GACxD,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CACrC,GAAG,EAAE,UAAU,EACf,CAAC,EAAE,aAAa,EAChB,OAAO,CAAC,EAAE,6BAA6B,GAAG,aAAa,GACxD,OAAO,CAAC,mBAAmB,CAAC,CAE9B"}