graphwise 1.8.1 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/{adjacency-map-D-Ul7V1r.js → adjacency-map-BtKzcuJq.js} +1 -1
  2. package/dist/{adjacency-map-D-Ul7V1r.js.map → adjacency-map-BtKzcuJq.js.map} +1 -1
  3. package/dist/{adjacency-map-B6wPtmaq.cjs → adjacency-map-JqBnMNkF.cjs} +1 -1
  4. package/dist/{adjacency-map-B6wPtmaq.cjs.map → adjacency-map-JqBnMNkF.cjs.map} +1 -1
  5. package/dist/async/index.cjs +2 -2
  6. package/dist/async/index.js +2 -2
  7. package/dist/expansion/index.cjs +1 -1
  8. package/dist/expansion/index.js +1 -1
  9. package/dist/{expansion-sldRognt.js → expansion-ClDhlMK8.js} +4 -4
  10. package/dist/{expansion-sldRognt.js.map → expansion-ClDhlMK8.js.map} +1 -1
  11. package/dist/{expansion-FkmEYlrQ.cjs → expansion-DaTroIyv.cjs} +4 -4
  12. package/dist/{expansion-FkmEYlrQ.cjs.map → expansion-DaTroIyv.cjs.map} +1 -1
  13. package/dist/extraction/index.cjs +1 -1
  14. package/dist/extraction/index.js +1 -1
  15. package/dist/gpu/csr.d.ts +29 -30
  16. package/dist/gpu/csr.d.ts.map +1 -1
  17. package/dist/gpu/dispatch.d.ts +31 -0
  18. package/dist/gpu/dispatch.d.ts.map +1 -0
  19. package/dist/gpu/dispatch.unit.test.d.ts +5 -0
  20. package/dist/gpu/dispatch.unit.test.d.ts.map +1 -0
  21. package/dist/gpu/index.cjs +15 -410
  22. package/dist/gpu/index.d.ts +3 -1
  23. package/dist/gpu/index.d.ts.map +1 -1
  24. package/dist/gpu/index.js +2 -400
  25. package/dist/gpu/kernels/bfs/kernel.d.ts +59 -0
  26. package/dist/gpu/kernels/bfs/kernel.d.ts.map +1 -0
  27. package/dist/gpu/kernels/bfs/logic.d.ts +47 -0
  28. package/dist/gpu/kernels/bfs/logic.d.ts.map +1 -0
  29. package/dist/gpu/kernels/bfs/logic.unit.test.d.ts +2 -0
  30. package/dist/gpu/kernels/bfs/logic.unit.test.d.ts.map +1 -0
  31. package/dist/gpu/kernels/degree-histogram/kernel.d.ts +32 -0
  32. package/dist/gpu/kernels/degree-histogram/kernel.d.ts.map +1 -0
  33. package/dist/gpu/kernels/degree-histogram/logic.d.ts +45 -0
  34. package/dist/gpu/kernels/degree-histogram/logic.d.ts.map +1 -0
  35. package/dist/gpu/kernels/degree-histogram/logic.unit.test.d.ts +2 -0
  36. package/dist/gpu/kernels/degree-histogram/logic.unit.test.d.ts.map +1 -0
  37. package/dist/gpu/kernels/jaccard/kernel.d.ts +40 -0
  38. package/dist/gpu/kernels/jaccard/kernel.d.ts.map +1 -0
  39. package/dist/gpu/kernels/jaccard/logic.d.ts +43 -0
  40. package/dist/gpu/kernels/jaccard/logic.d.ts.map +1 -0
  41. package/dist/gpu/kernels/jaccard/logic.unit.test.d.ts +2 -0
  42. package/dist/gpu/kernels/jaccard/logic.unit.test.d.ts.map +1 -0
  43. package/dist/gpu/kernels/pagerank/kernel.d.ts +44 -0
  44. package/dist/gpu/kernels/pagerank/kernel.d.ts.map +1 -0
  45. package/dist/gpu/kernels/pagerank/logic.d.ts +50 -0
  46. package/dist/gpu/kernels/pagerank/logic.d.ts.map +1 -0
  47. package/dist/gpu/kernels/pagerank/logic.unit.test.d.ts +2 -0
  48. package/dist/gpu/kernels/pagerank/logic.unit.test.d.ts.map +1 -0
  49. package/dist/gpu/kernels/spmv/kernel.d.ts +43 -0
  50. package/dist/gpu/kernels/spmv/kernel.d.ts.map +1 -0
  51. package/dist/gpu/kernels/spmv/logic.d.ts +31 -0
  52. package/dist/gpu/kernels/spmv/logic.d.ts.map +1 -0
  53. package/dist/gpu/kernels/spmv/logic.unit.test.d.ts +2 -0
  54. package/dist/gpu/kernels/spmv/logic.unit.test.d.ts.map +1 -0
  55. package/dist/gpu/operations.d.ts +76 -0
  56. package/dist/gpu/operations.d.ts.map +1 -0
  57. package/dist/gpu/operations.unit.test.d.ts +5 -0
  58. package/dist/gpu/operations.unit.test.d.ts.map +1 -0
  59. package/dist/gpu/root.d.ts +53 -0
  60. package/dist/gpu/root.d.ts.map +1 -0
  61. package/dist/gpu/root.unit.test.d.ts +2 -0
  62. package/dist/gpu/root.unit.test.d.ts.map +1 -0
  63. package/dist/gpu/types.d.ts +3 -8
  64. package/dist/gpu/types.d.ts.map +1 -1
  65. package/dist/gpu-CHiCN0wa.js +16945 -0
  66. package/dist/gpu-CHiCN0wa.js.map +1 -0
  67. package/dist/gpu-Y6owRVMi.cjs +17028 -0
  68. package/dist/gpu-Y6owRVMi.cjs.map +1 -0
  69. package/dist/graph/index.cjs +1 -1
  70. package/dist/graph/index.js +1 -1
  71. package/dist/index/index.cjs +18 -15
  72. package/dist/index/index.js +10 -10
  73. package/dist/{jaccard-Yddrtt5D.js → jaccard-3rCdilwm.js} +2 -2
  74. package/dist/{jaccard-Yddrtt5D.js.map → jaccard-3rCdilwm.js.map} +1 -1
  75. package/dist/{jaccard-Bmd1IEFO.cjs → jaccard-Bys9_dGW.cjs} +2 -2
  76. package/dist/{jaccard-Bmd1IEFO.cjs.map → jaccard-Bys9_dGW.cjs.map} +1 -1
  77. package/dist/{kmeans-D3yX5QFs.cjs → kmeans-B8x9D1kt.cjs} +1 -1
  78. package/dist/{kmeans-D3yX5QFs.cjs.map → kmeans-B8x9D1kt.cjs.map} +1 -1
  79. package/dist/{kmeans-DVCe61Me.js → kmeans-DKkL9rAN.js} +1 -1
  80. package/dist/{kmeans-DVCe61Me.js.map → kmeans-DKkL9rAN.js.map} +1 -1
  81. package/dist/{ops-4nmI-pwk.cjs → ops-djAsQQSh.cjs} +2 -2
  82. package/dist/{ops-4nmI-pwk.cjs.map → ops-djAsQQSh.cjs.map} +1 -1
  83. package/dist/{ops-Zsu4ecEG.js → ops-upIi6JIi.js} +2 -2
  84. package/dist/{ops-Zsu4ecEG.js.map → ops-upIi6JIi.js.map} +1 -1
  85. package/dist/{priority-queue-ChVLoG6T.cjs → priority-queue-BIiD1L0k.cjs} +1 -1
  86. package/dist/{priority-queue-ChVLoG6T.cjs.map → priority-queue-BIiD1L0k.cjs.map} +1 -1
  87. package/dist/{priority-queue-DqCuFTR8.js → priority-queue-CFDd5cBg.js} +1 -1
  88. package/dist/{priority-queue-DqCuFTR8.js.map → priority-queue-CFDd5cBg.js.map} +1 -1
  89. package/dist/ranking/index.cjs +2 -2
  90. package/dist/ranking/index.js +2 -2
  91. package/dist/ranking/mi/index.cjs +2 -2
  92. package/dist/ranking/mi/index.js +2 -2
  93. package/dist/{ranking-mUm9rV-C.js → ranking-3ez5m67U.js} +2 -2
  94. package/dist/{ranking-mUm9rV-C.js.map → ranking-3ez5m67U.js.map} +1 -1
  95. package/dist/{ranking-riRrEVAR.cjs → ranking-DVvajgUZ.cjs} +2 -2
  96. package/dist/{ranking-riRrEVAR.cjs.map → ranking-DVvajgUZ.cjs.map} +1 -1
  97. package/dist/seeds/index.cjs +1 -1
  98. package/dist/seeds/index.js +1 -1
  99. package/dist/structures/index.cjs +1 -1
  100. package/dist/structures/index.js +1 -1
  101. package/dist/utils/index.cjs +1 -1
  102. package/dist/utils/index.js +1 -1
  103. package/dist/{utils-CcIrKAEb.js → utils-BodeE2Mo.js} +1 -1
  104. package/dist/{utils-CcIrKAEb.js.map → utils-BodeE2Mo.js.map} +1 -1
  105. package/dist/{utils-CpyzmzIF.cjs → utils-CDtCcsyF.cjs} +1 -1
  106. package/dist/{utils-CpyzmzIF.cjs.map → utils-CDtCcsyF.cjs.map} +1 -1
  107. package/package.json +3 -1
  108. package/dist/gpu/context.d.ts +0 -118
  109. package/dist/gpu/context.d.ts.map +0 -1
  110. package/dist/gpu/context.unit.test.d.ts +0 -2
  111. package/dist/gpu/context.unit.test.d.ts.map +0 -1
  112. package/dist/gpu/index.cjs.map +0 -1
  113. package/dist/gpu/index.js.map +0 -1
package/dist/gpu/index.js CHANGED
@@ -1,400 +1,2 @@
1
- //#region src/gpu/types.ts
2
- /**
3
- * Error thrown when GPU backend is requested but unavailable.
4
- */
5
- var GPUNotAvailableError = class extends Error {
6
- constructor(reason) {
7
- super(`WebGPU not available: ${reason}`);
8
- this.name = "GPUNotAvailableError";
9
- }
10
- };
11
- //#endregion
12
- //#region src/gpu/csr.ts
13
- /**
14
- * Convert a ReadableGraph to CSR format.
15
- *
16
- * For undirected graphs, each edge is stored twice (once in each direction).
17
- * For directed graphs, edges are stored in the out-direction by default.
18
- *
19
- * @param graph - The graph to convert
20
- * @param direction - Edge direction to include (default: 'out' for directed, 'both' for undirected)
21
- * @returns CSR representation with index mapping
22
- */
23
- function graphToCSR(graph, direction = graph.directed ? "out" : "both") {
24
- const nodeToIndex = /* @__PURE__ */ new Map();
25
- const indexToNode = [];
26
- for (const nodeId of graph.nodeIds()) {
27
- const index = indexToNode.length;
28
- nodeToIndex.set(nodeId, index);
29
- indexToNode.push(nodeId);
30
- }
31
- const nodeCount = indexToNode.length;
32
- const degrees = new Uint32Array(nodeCount);
33
- for (const nodeId of graph.nodeIds()) {
34
- const srcIndex = nodeToIndex.get(nodeId);
35
- if (srcIndex === void 0) continue;
36
- degrees[srcIndex] = graph.degree(nodeId, direction);
37
- }
38
- let totalEdges = 0;
39
- for (let i = 0; i < nodeCount; i++) totalEdges += degrees[i] ?? 0;
40
- const rowOffsets = new Uint32Array(nodeCount + 1);
41
- for (let i = 0; i < nodeCount; i++) rowOffsets[i + 1] = (rowOffsets[i] ?? 0) + (degrees[i] ?? 0);
42
- const colIndices = new Uint32Array(totalEdges);
43
- const values = new Float32Array(totalEdges);
44
- for (const nodeId of graph.nodeIds()) {
45
- const srcIndex = nodeToIndex.get(nodeId);
46
- if (srcIndex === void 0) continue;
47
- const baseOffset = rowOffsets[srcIndex] ?? 0;
48
- let localOffset = 0;
49
- for (const neighbourId of graph.neighbours(nodeId, direction)) {
50
- const dstIndex = nodeToIndex.get(neighbourId);
51
- if (dstIndex === void 0) continue;
52
- const edgeIdx = baseOffset + localOffset;
53
- colIndices[edgeIdx] = dstIndex;
54
- values[edgeIdx] = graph.getEdge(nodeId, neighbourId)?.weight ?? 1;
55
- localOffset++;
56
- }
57
- }
58
- return {
59
- csr: {
60
- rowOffsets,
61
- colIndices,
62
- values,
63
- nodeCount,
64
- edgeCount: graph.directed ? graph.edgeCount : graph.edgeCount * 2
65
- },
66
- indexMap: {
67
- nodeToIndex,
68
- indexToNode
69
- }
70
- };
71
- }
72
- /**
73
- * Create GPU buffers from a CSR matrix.
74
- *
75
- * Buffers are created with:
76
- * - rowOffsets/colIndices: STORAGE | COPY_DST
77
- * - values: STORAGE | COPY_DST (if present)
78
- *
79
- * @param device - GPU device to create buffers on
80
- * @param csr - CSR matrix to upload
81
- * @returns GPU buffer group
82
- */
83
- function csrToGPUBuffers(device, csr) {
84
- const rowOffsetsBuffer = device.createBuffer({
85
- size: csr.rowOffsets.byteLength,
86
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
87
- mappedAtCreation: false
88
- });
89
- device.queue.writeBuffer(rowOffsetsBuffer, 0, csr.rowOffsets);
90
- const colIndicesBuffer = device.createBuffer({
91
- size: csr.colIndices.byteLength,
92
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
93
- mappedAtCreation: false
94
- });
95
- device.queue.writeBuffer(colIndicesBuffer, 0, csr.colIndices);
96
- let valuesBuffer;
97
- if (csr.values !== void 0) {
98
- valuesBuffer = device.createBuffer({
99
- size: csr.values.byteLength,
100
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST,
101
- mappedAtCreation: false
102
- });
103
- device.queue.writeBuffer(valuesBuffer, 0, csr.values);
104
- }
105
- if (valuesBuffer !== void 0) return {
106
- rowOffsets: rowOffsetsBuffer,
107
- colIndices: colIndicesBuffer,
108
- values: valuesBuffer,
109
- nodeCount: csr.nodeCount,
110
- edgeCount: csr.edgeCount
111
- };
112
- return {
113
- rowOffsets: rowOffsetsBuffer,
114
- colIndices: colIndicesBuffer,
115
- nodeCount: csr.nodeCount,
116
- edgeCount: csr.edgeCount
117
- };
118
- }
119
- /**
120
- * Create a result buffer for reading compute output.
121
- *
122
- * @param device - GPU device
123
- * @param byteLength - Size of the buffer in bytes
124
- * @returns GPU buffer configured for map reading
125
- */
126
- function createResultBuffer(device, byteLength) {
127
- return device.createBuffer({
128
- size: byteLength,
129
- usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.MAP_READ
130
- });
131
- }
132
- /**
133
- * Read data from a GPU buffer to CPU.
134
- *
135
- * @param device - GPU device
136
- * @param buffer - Buffer to read from
137
- * @returns ArrayBuffer containing the buffer data
138
- */
139
- async function readBufferToCPU(device, buffer) {
140
- await buffer.mapAsync(GPUMapMode.READ);
141
- const data = buffer.getMappedRange().slice(0);
142
- buffer.unmap();
143
- return data;
144
- }
145
- //#endregion
146
- //#region src/gpu/detect.ts
147
- /**
148
- * Detect WebGPU availability in the current environment.
149
- *
150
- * Checks for:
151
- * - Browser: navigator.gpu
152
- * - Node.js: global GPU constructor (Node.js 21+ with --experimental-webgpu)
153
- * - Deno: global GPU constructor
154
- *
155
- * @returns Detection result with availability status and reason
156
- */
157
- function detectWebGPU() {
158
- if (typeof navigator !== "undefined" && "gpu" in navigator) return { available: true };
159
- if (typeof globalThis !== "undefined" && "GPU" in globalThis) return { available: true };
160
- const reasons = [];
161
- if (typeof navigator === "undefined" && typeof globalThis === "undefined") reasons.push("no global scope detected");
162
- else if (typeof navigator !== "undefined" && !("gpu" in navigator)) reasons.push("navigator.gpu not present (browser may not support WebGPU)");
163
- else if (typeof globalThis !== "undefined" && !("GPU" in globalThis)) reasons.push("global GPU not present (Node.js requires v21+ with --experimental-webgpu flag)");
164
- return {
165
- available: false,
166
- reason: reasons.length > 0 ? reasons.join("; ") : "unknown environment"
167
- };
168
- }
169
- /**
170
- * Check if WebGPU is available (convenience function).
171
- *
172
- * @returns true if WebGPU is available, false otherwise
173
- */
174
- function isWebGPUAvailable() {
175
- return detectWebGPU().available;
176
- }
177
- /**
178
- * Assert that WebGPU is available, throwing an error if not.
179
- *
180
- * @throws Error if WebGPU is not available
181
- */
182
- function assertWebGPUAvailable() {
183
- const result = detectWebGPU();
184
- if (!result.available) throw new Error(`WebGPU required but not available: ${result.reason ?? "unknown reason"}`);
185
- }
186
- //#endregion
187
- //#region src/gpu/context.ts
188
- /**
189
- * GPU context management for WebGPU compute operations.
190
- *
191
- * Provides device acquisition, buffer pooling, and shader compilation
192
- * with caching for efficient GPU resource management.
193
- */
194
- /**
195
- * Type guard to check if an object has a WebGPU-compatible requestAdapter method.
196
- */
197
- function hasRequestAdapter(obj) {
198
- if (typeof obj !== "object" || obj === null) return false;
199
- if (!("requestAdapter" in obj)) return false;
200
- const descriptor = Object.getOwnPropertyDescriptor(obj, "requestAdapter");
201
- return descriptor !== void 0 && typeof descriptor.value === "function";
202
- }
203
- /**
204
- * Manages GPU device, buffers, and compiled shaders.
205
- *
206
- * Use the singleton pattern via getGPUContext() for most use cases,
207
- * or create separate contexts for isolated GPU resource pools.
208
- */
209
- var GPUContext = class {
210
- device = null;
211
- shaderCache = /* @__PURE__ */ new Map();
212
- bufferPool = [];
213
- destroyedBuffers = /* @__PURE__ */ new WeakSet();
214
- /**
215
- * Check if this context has an acquired GPU device.
216
- */
217
- get isReady() {
218
- return this.device !== null;
219
- }
220
- /**
221
- * Get the GPU device, throwing if not acquired.
222
- */
223
- getDevice() {
224
- if (this.device === null) throw new Error("GPUContext not initialised. Call acquireDevice() first.");
225
- return this.device;
226
- }
227
- /**
228
- * Acquire a GPU device from the adapter.
229
- *
230
- * @param options - Context creation options
231
- * @returns true if device was acquired successfully
232
- * @throws Error if WebGPU is unavailable or device request fails
233
- */
234
- async acquireDevice(options = {}) {
235
- const detection = detectWebGPU();
236
- if (!detection.available) throw new Error(`WebGPU unavailable: ${detection.reason ?? "unknown reason"}`);
237
- let adapter = null;
238
- const adapterOpts = options.powerPreference !== void 0 ? { powerPreference: options.powerPreference } : {};
239
- if (typeof navigator !== "undefined" && "gpu" in navigator) adapter = await navigator.gpu.requestAdapter(adapterOpts);
240
- if (adapter === null && typeof globalThis !== "undefined" && "GPU" in globalThis) {
241
- const gpuDescriptor = Object.getOwnPropertyDescriptor(globalThis, "gpu");
242
- if (gpuDescriptor !== void 0 && hasRequestAdapter(gpuDescriptor.value)) adapter = await gpuDescriptor.value.requestAdapter(adapterOpts);
243
- }
244
- if (adapter === null) throw new Error("No GPU adapter found");
245
- this.device = await adapter.requestDevice();
246
- this.device.lost.then((info) => {
247
- console.error(`GPU device lost: ${info.message}`);
248
- this.device = null;
249
- this.clearCache();
250
- });
251
- return true;
252
- }
253
- /**
254
- * Compile a WGSL shader, using cache if available.
255
- *
256
- * @param code - WGSL shader code
257
- * @param key - Optional cache key (defaults to code hash)
258
- * @returns Compiled shader module
259
- */
260
- compileShader(code, key) {
261
- const cacheKey = key ?? this.hashCode(code);
262
- const cached = this.shaderCache.get(cacheKey);
263
- if (cached?.code === code) return cached.module;
264
- const module = this.getDevice().createShaderModule({ code });
265
- this.shaderCache.set(cacheKey, {
266
- module,
267
- code
268
- });
269
- return module;
270
- }
271
- /**
272
- * Create a GPU buffer, optionally reusing from pool.
273
- *
274
- * @param size - Buffer size in bytes
275
- * @param usage - Buffer usage flags
276
- * @returns GPU buffer
277
- */
278
- createBuffer(size, usage) {
279
- for (let i = 0; i < this.bufferPool.length; i++) {
280
- const buffer = this.bufferPool[i];
281
- if (buffer !== void 0 && !this.destroyedBuffers.has(buffer) && buffer.size >= size && (buffer.usage & usage) === usage) {
282
- this.bufferPool.splice(i, 1);
283
- return buffer;
284
- }
285
- }
286
- return this.getDevice().createBuffer({
287
- size,
288
- usage
289
- });
290
- }
291
- /**
292
- * Return a buffer to the pool for reuse.
293
- *
294
- * @param buffer - Buffer to recycle
295
- */
296
- recycleBuffer(buffer) {
297
- if (!this.destroyedBuffers.has(buffer)) this.bufferPool.push(buffer);
298
- }
299
- /**
300
- * Mark a buffer as destroyed (call before GPUBuffer.destroy()).
301
- *
302
- * @param buffer - Buffer to mark as destroyed
303
- */
304
- markDestroyed(buffer) {
305
- this.destroyedBuffers.add(buffer);
306
- }
307
- /**
308
- * Create a compute pipeline from shader code.
309
- *
310
- * @param code - WGSL compute shader code
311
- * @param entryPoint - Entry point function name
312
- * @returns Compute pipeline
313
- */
314
- createComputePipeline(code, entryPoint = "main") {
315
- const device = this.getDevice();
316
- const module = this.compileShader(code);
317
- return device.createComputePipeline({
318
- layout: "auto",
319
- compute: {
320
- module,
321
- entryPoint
322
- }
323
- });
324
- }
325
- /**
326
- * Create a compute pipeline asynchronously (preferred for performance).
327
- *
328
- * @param code - WGSL compute shader code
329
- * @param entryPoint - Entry point function name
330
- * @returns Promise resolving to compute pipeline
331
- */
332
- async createComputePipelineAsync(code, entryPoint = "main") {
333
- const device = this.getDevice();
334
- const module = this.compileShader(code);
335
- return device.createComputePipelineAsync({
336
- layout: "auto",
337
- compute: {
338
- module,
339
- entryPoint
340
- }
341
- });
342
- }
343
- /**
344
- * Clear all cached resources.
345
- */
346
- clearCache() {
347
- this.shaderCache.clear();
348
- for (const buffer of this.bufferPool) buffer.destroy();
349
- this.bufferPool.length = 0;
350
- }
351
- /**
352
- * Destroy the context and release all resources.
353
- */
354
- destroy() {
355
- this.clearCache();
356
- if (this.device !== null) {
357
- this.device.destroy();
358
- this.device = null;
359
- }
360
- }
361
- /**
362
- * Simple string hash for cache keys.
363
- */
364
- hashCode(str) {
365
- let hash = 0;
366
- for (let i = 0; i < str.length; i++) {
367
- const char = str.charCodeAt(i);
368
- hash = (hash << 5) - hash + char | 0;
369
- }
370
- return hash.toString(16);
371
- }
372
- };
373
- var defaultContext = null;
374
- /**
375
- * Get or create the default GPU context.
376
- *
377
- * This is a lazy singleton - the device is not acquired until
378
- * acquireDevice() is called.
379
- *
380
- * @param options - Context creation options
381
- * @returns GPU context instance
382
- */
383
- function getGPUContext(options) {
384
- if (defaultContext === null || (options?.forceNew ?? false)) defaultContext = new GPUContext();
385
- return defaultContext;
386
- }
387
- /**
388
- * Create a new isolated GPU context.
389
- *
390
- * Use this when you need separate resource pools or device management.
391
- *
392
- * @returns New GPU context instance
393
- */
394
- function createGPUContext() {
395
- return new GPUContext();
396
- }
397
- //#endregion
398
- export { GPUContext, GPUNotAvailableError, assertWebGPUAvailable, createGPUContext, createResultBuffer, csrToGPUBuffers, detectWebGPU, getGPUContext, graphToCSR, isWebGPUAvailable, readBufferToCPU };
399
-
400
- //# sourceMappingURL=index.js.map
1
+ import { a as gpuSpmv, c as initGPUFromDevice, d as isWebGPUAvailable, f as csrToTypedBuffers, i as gpuPageRank, l as assertWebGPUAvailable, m as GPUNotAvailableError, n as gpuDegreeHistogram, o as withBackend, p as graphToCSR, r as gpuJaccardBatch, s as initGPU, t as gpuBfsLevels, u as detectWebGPU } from "../gpu-CHiCN0wa.js";
2
+ export { GPUNotAvailableError, assertWebGPUAvailable, csrToTypedBuffers, detectWebGPU, gpuBfsLevels, gpuDegreeHistogram, gpuJaccardBatch, gpuPageRank, gpuSpmv, graphToCSR, initGPU, initGPUFromDevice, isWebGPUAvailable, withBackend };
@@ -0,0 +1,59 @@
1
+ import { d, StorageFlag, TgpuBuffer } from 'typegpu';
2
+ import { TypedBufferGroup } from '../../csr';
3
+ import { GraphwiseGPURoot } from '../../root';
4
+ /**
5
+ * Bind group layout for BFS kernel.
6
+ */
7
+ declare const BFSLayout: import('typegpu').TgpuBindGroupLayout<{
8
+ rowOffsets: {
9
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
10
+ };
11
+ colIndices: {
12
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
13
+ };
14
+ frontier: {
15
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
16
+ };
17
+ frontierSize: {
18
+ uniform: d.U32;
19
+ };
20
+ visited: {
21
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
22
+ access: "mutable";
23
+ };
24
+ levels: {
25
+ storage: (elementCount: number) => d.WgslArray<d.I32>;
26
+ access: "mutable";
27
+ };
28
+ nextFrontier: {
29
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
30
+ access: "mutable";
31
+ };
32
+ nextFrontierSize: {
33
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
34
+ access: "mutable";
35
+ };
36
+ currentLevel: {
37
+ uniform: d.U32;
38
+ };
39
+ nodeCount: {
40
+ uniform: d.U32;
41
+ };
42
+ }>;
43
+ /**
44
+ * Dispatch one BFS level on GPU.
45
+ *
46
+ * @param root - TypeGPU root instance
47
+ * @param csrBuffers - CSR matrix as typed buffers
48
+ * @param frontier - Current frontier nodes (u32 array)
49
+ * @param frontierSize - Number of nodes in current frontier
50
+ * @param visited - Visited flags (u32 array, mutable)
51
+ * @param levels - Level assignments (i32 array, mutable)
52
+ * @param nextFrontier - Output next frontier (u32 array, mutable)
53
+ * @param nextFrontierSize - Output next frontier size (u32 array, mutable)
54
+ * @param currentLevel - Current BFS level (0-indexed)
55
+ * @param nodeCount - Total number of nodes
56
+ */
57
+ export declare function dispatchBfsLevel(root: GraphwiseGPURoot, csrBuffers: TypedBufferGroup, frontier: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, frontierSize: number, visited: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, levels: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.i32>>> & StorageFlag, nextFrontier: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, nextFrontierSize: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, currentLevel: number, nodeCount: number): void;
58
+ export { BFSLayout };
59
+ //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/bfs/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAa,EAAE,CAAC,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWb,CAAC;AA6CH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,gBAAgB,EAC5B,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAC/D,WAAW,EACZ,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,EAC7E,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,EAC5E,YAAY,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACnE,WAAW,EACZ,gBAAgB,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACvE,WAAW,EACZ,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GACf,IAAI,CAyBN;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Pure CPU implementation of level-synchronous BFS.
3
+ *
4
+ * Processes one BFS level per iteration:
5
+ * - For each node in the current frontier:
6
+ * - For each neighbour:
7
+ * - If not yet visited, mark visited, add to next frontier, set level
8
+ *
9
+ * This is the CPU reference implementation extracted from the WGSL kernel.
10
+ *
11
+ * @module gpu/kernels/bfs/logic
12
+ */
13
+ /**
14
+ * Result of a BFS traversal.
15
+ */
16
+ export interface BfsResult {
17
+ /** Level (distance from source) for each node. -1 if unreachable. */
18
+ readonly levels: Int32Array;
19
+ /** Number of BFS levels (maximum distance + 1). */
20
+ readonly depth: number;
21
+ /** Number of nodes reached. */
22
+ readonly nodesReached: number;
23
+ }
24
+ /**
25
+ * Process one BFS level: expand frontier and return next frontier.
26
+ * This mirrors one dispatch of the GPU kernel.
27
+ *
28
+ * @param rowOffsets - CSR row offsets
29
+ * @param colIndices - CSR column indices
30
+ * @param frontier - Current frontier node indices
31
+ * @param visited - Visited flags (mutated in place)
32
+ * @param levels - Level assignments (mutated in place)
33
+ * @param currentLevel - Current BFS level
34
+ * @returns Next frontier node indices
35
+ */
36
+ export declare function bfsLevel(rowOffsets: Uint32Array, colIndices: Uint32Array, frontier: readonly number[], visited: Uint8Array, levels: Int32Array, currentLevel: number): number[];
37
+ /**
38
+ * Full BFS from a source node.
39
+ *
40
+ * @param rowOffsets - CSR row offsets
41
+ * @param colIndices - CSR column indices
42
+ * @param nodeCount - Number of nodes
43
+ * @param source - Source node index
44
+ * @returns BFS result with levels and statistics
45
+ */
46
+ export declare function bfs(rowOffsets: Uint32Array, colIndices: Uint32Array, nodeCount: number, source: number): BfsResult;
47
+ //# sourceMappingURL=logic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/bfs/logic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,qEAAqE;IACrE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CACvB,UAAU,EAAE,WAAW,EACvB,UAAU,EAAE,WAAW,EACvB,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,UAAU,EAClB,YAAY,EAAE,MAAM,GAClB,MAAM,EAAE,CAoBV;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAClB,UAAU,EAAE,WAAW,EACvB,UAAU,EAAE,WAAW,EACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACZ,SAAS,CAwCX"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logic.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.unit.test.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/bfs/logic.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import { d, StorageFlag, TgpuBuffer } from 'typegpu';
2
+ import { TypedBufferGroup } from '../../csr';
3
+ import { GraphwiseGPURoot } from '../../root';
4
+ /**
5
+ * Bind group layout for degree kernel.
6
+ */
7
+ declare const DegreeLayout: import('typegpu').TgpuBindGroupLayout<{
8
+ rowOffsets: {
9
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
10
+ };
11
+ degrees: {
12
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
13
+ access: "mutable";
14
+ };
15
+ nodeCount: {
16
+ uniform: d.U32;
17
+ };
18
+ }>;
19
+ /**
20
+ * Dispatch degree computation on GPU.
21
+ *
22
+ * Note: This computes per-node degrees. Histogram aggregation should be
23
+ * done on CPU or with a separate reduction kernel.
24
+ *
25
+ * @param root - TypeGPU root instance
26
+ * @param csrBuffers - CSR matrix as typed buffers
27
+ * @param degrees - Output degree array (u32, mutable)
28
+ * @param nodeCount - Number of nodes
29
+ */
30
+ export declare function dispatchDegreeHistogram(root: GraphwiseGPURoot, csrBuffers: TypedBufferGroup, degrees: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, nodeCount: number): void;
31
+ export { DegreeLayout };
32
+ //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/degree-histogram/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAa,EAAE,CAAC,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,QAAA,MAAM,YAAY;;;;;;;;;;;EAIhB,CAAC;AAuBH;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACtC,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,gBAAgB,EAC5B,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,EAC7E,SAAS,EAAE,MAAM,GACf,IAAI,CAYN;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Pure CPU implementation of degree histogram computation.
3
+ *
4
+ * Computes degree statistics from CSR format:
5
+ * - Degree per node from rowOffsets
6
+ * - Histogram of degree frequencies
7
+ * - Max, total, and mean degree
8
+ *
9
+ * This is the CPU reference implementation extracted from the WGSL kernel.
10
+ *
11
+ * @module gpu/kernels/degree-histogram/logic
12
+ */
13
+ /**
14
+ * Degree statistics for a graph.
15
+ */
16
+ export interface DegreeStats {
17
+ /** Degree for each node (length: nodeCount) */
18
+ readonly degrees: Uint32Array;
19
+ /** Histogram of degree frequencies (length: maxDegree + 1) */
20
+ readonly histogram: Uint32Array;
21
+ /** Maximum degree in the graph */
22
+ readonly maxDegree: number;
23
+ /** Sum of all degrees */
24
+ readonly totalDegree: number;
25
+ /** Mean degree (totalDegree / nodeCount) */
26
+ readonly meanDegree: number;
27
+ }
28
+ /**
29
+ * Compute the degree of a single node from CSR row offsets.
30
+ *
31
+ * @param rowOffsets - CSR row offset array (length: nodeCount + 1)
32
+ * @param node - Node index
33
+ * @returns Degree (number of neighbours) for this node
34
+ */
35
+ export declare function computeDegree(rowOffsets: Uint32Array, node: number): number;
36
+ /**
37
+ * Build degree histogram and statistics from CSR row offsets.
38
+ *
39
+ * @param rowOffsets - CSR row offset array (length: nodeCount + 1)
40
+ * @param nodeCount - Number of nodes
41
+ * @param histogramSize - Size of histogram array (default: auto-computed as maxDegree + 1)
42
+ * @returns Degree statistics including histogram
43
+ */
44
+ export declare function buildDegreeStats(rowOffsets: Uint32Array, nodeCount: number, histogramSize?: number): DegreeStats;
45
+ //# sourceMappingURL=logic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/degree-histogram/logic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,kCAAkC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yBAAyB;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI3E;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,UAAU,EAAE,WAAW,EACvB,SAAS,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,MAAM,GACpB,WAAW,CAmCb"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=logic.unit.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.unit.test.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/degree-histogram/logic.unit.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ import { d, StorageFlag, TgpuBuffer } from 'typegpu';
2
+ import { TypedBufferGroup } from '../../csr';
3
+ import { GraphwiseGPURoot } from '../../root';
4
+ /**
5
+ * Bind group layout for Jaccard kernel.
6
+ */
7
+ declare const JaccardLayout: import('typegpu').TgpuBindGroupLayout<{
8
+ rowOffsets: {
9
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
10
+ };
11
+ colIndices: {
12
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
13
+ };
14
+ pairsU: {
15
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
16
+ };
17
+ pairsV: {
18
+ storage: (elementCount: number) => d.WgslArray<d.U32>;
19
+ };
20
+ results: {
21
+ storage: (elementCount: number) => d.WgslArray<d.F32>;
22
+ access: "mutable";
23
+ };
24
+ pairCount: {
25
+ uniform: d.U32;
26
+ };
27
+ }>;
28
+ /**
29
+ * Dispatch batch Jaccard on GPU.
30
+ *
31
+ * @param root - TypeGPU root instance
32
+ * @param csrBuffers - CSR matrix as typed buffers
33
+ * @param pairsU - First node of each pair (u32 array)
34
+ * @param pairsV - Second node of each pair (u32 array)
35
+ * @param results - Output Jaccard coefficients (f32 array, mutable)
36
+ * @param pairCount - Number of pairs to compute
37
+ */
38
+ export declare function dispatchJaccard(root: GraphwiseGPURoot, csrBuffers: TypedBufferGroup, pairsU: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, pairsV: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.u32>>> & StorageFlag, results: TgpuBuffer<ReturnType<typeof d.arrayOf<typeof d.f32>>> & StorageFlag, pairCount: number): void;
39
+ export { JaccardLayout };
40
+ //# sourceMappingURL=kernel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../../../../src/gpu/kernels/jaccard/kernel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAa,EAAE,CAAC,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;EAOjB,CAAC;AA8EH;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,gBAAgB,EAC5B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,EAC5E,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,EAC5E,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,EAC7E,SAAS,EAAE,MAAM,GACf,IAAI,CAeN;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}