@openfluke/welvet 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # @openfluke/welvet - LOOM TypeScript/WASM Bindings
2
+
3
+ **Wrapper for Embedding Loom Via External (WASM) Toolchain**
4
+
5
+ High-performance neural network library with **full training in browser/Node.js** via WebAssembly. Zero external dependencies—just import and go.
6
+
7
+ > **v0.3.0 Update**: Now includes a **Universal Test Suite** (2298 tests) with 100% parity across Browser and Node.js environments.
2
8
 
3
- **Wrapper for Embedding Loom Via External (WASM) Toolchain**
4
-
5
- High-performance neural network library with **full training in browser/Node.js** via WebAssembly. Zero external dependencies—just import and go.
6
9
 
7
10
  ## Framework Comparison
8
11
 
@@ -217,26 +220,34 @@ Tests **5 architectures × 3 depths × 5 training modes** (75 tests total):
217
220
  - **Modes:** NormalBP, StepBP, Tween, TweenChain, StepTweenChain
218
221
 
219
222
  ## Complete Test Suite
220
-
221
- The `universal_test.ts` example demonstrates all framework capabilities:
222
-
223
- ```bash
224
- cd example
225
- bun run universal_test.ts
226
- ```
227
-
228
- **Test Coverage:**
229
- - 12 Layer Types × 6 Data Types (72 tests)
230
- - Network Grafting
231
- - ✅ K-Means Clustering & Correlation Analysis
232
- - ✅ Optimizers (SGD, AdamW, RMSprop)
233
- - Ensemble Features
234
- - ✅ Observer Pattern (Adaptation Tracking)
235
- - ✅ Introspection API
236
- - Step & Tween API
237
- - Advanced Layers (Embedding, Residual)
238
-
239
- See [`example/universal_test.ts`](./example/universal_test.ts) for the complete test implementation.
223
+
224
+ The `universal_test.ts` example demonstrates all framework capabilities with **100% parity** to the Go/C core.
225
+
226
+ ### Running in Browser (v0.3.0+)
227
+
228
+ The universal test suite now runs directly in the browser with a full DOM report:
229
+
230
+ ```bash
231
+ cd typescript
232
+ python3 serve.py
233
+ # Open http://localhost:8081
234
+ ```
235
+
236
+ ### Running in Node/Bun
237
+
238
+ ```bash
239
+ cd example
240
+ bun run universal_test.ts
241
+ ```
242
+
243
+ **Test Coverage (2298 Tests):**
244
+ - ✅ **Serialization**: 12 Layer Types × 15 Data Types (2100 combinations)
245
+ - ✅ **In-Memory WASM**: SafeTensors without filesystem (144 tests)
246
+ - ✅ **Advanced Math**: K-Means, Correlation, Grafting, Ensembles
247
+ - ✅ **GPU Parity**: Determinism checks for forward/backward passes
248
+ - ✅ **Core**: Architecture generation, combinators, sequential layers
249
+
250
+ See [`example/universal_test.ts`](./example/universal_test.ts) for the complete test implementation.
240
251
 
241
252
  ## Layer Types
242
253
 
File without changes
File without changes
package/dist/index.d.ts CHANGED
@@ -5,23 +5,28 @@
5
5
  * Provides the same API in both Node.js and browser environments.
6
6
  */
7
7
  import { Network, GraftResult, KMeansResult, CorrelationResult, EnsembleMatch, AdaptationTracker } from "./types.js";
8
- import { loadLoomWASM } from "./loader.js";
9
8
  import { loadLoomWASMBrowser } from "./loader.browser.js";
10
9
  export * from "./types.js";
11
- export { loadLoomWASM, loadLoomWASMBrowser };
10
+ export { loadLoomWASMBrowser };
11
+ export declare function loadLoomWASM(): Promise<void>;
12
12
  /**
13
- * Initialize WASM for Node.js environment
13
+ * Initialize WASM
14
+ * Auto-detects environment (Browser vs Node.js)
14
15
  */
15
- export declare function init(): Promise<void>;
16
+ export declare function init(wasmUrl?: string): Promise<void>;
16
17
  /**
17
18
  * Initialize WASM for Browser environment
18
19
  */
19
- export declare function initBrowser(): Promise<void>;
20
+ export declare function initBrowser(wasmUrl?: string): Promise<void>;
20
21
  /**
21
22
  * Create a network from JSON config
22
23
  * Wrapper around the global createLoomNetwork function exposed by WASM
23
24
  */
24
25
  export declare function createNetwork(config: object | string): Network;
26
+ /**
27
+ * Load a network from JSON string and ID
28
+ */
29
+ export declare function loadNetwork(jsonString: string, modelID: string): Network;
25
30
  /**
26
31
  * Create a network handle for grafting
27
32
  */
@@ -53,6 +58,7 @@ declare const _default: {
53
58
  init: typeof init;
54
59
  initBrowser: typeof initBrowser;
55
60
  createNetwork: typeof createNetwork;
61
+ loadNetwork: typeof loadNetwork;
56
62
  createKHandle: typeof createKHandle;
57
63
  graft: typeof graft;
58
64
  kmeans: typeof kmeans;
package/dist/index.js CHANGED
@@ -4,21 +4,29 @@
4
4
  * Direct wrapper around Loom WASM that mirrors main.go exports exactly.
5
5
  * Provides the same API in both Node.js and browser environments.
6
6
  */
7
- import { loadLoomWASM } from "./loader.js";
8
7
  import { loadLoomWASMBrowser } from "./loader.browser.js";
9
8
  export * from "./types.js";
10
- export { loadLoomWASM, loadLoomWASMBrowser };
9
+ export { loadLoomWASMBrowser };
10
+ export async function loadLoomWASM() {
11
+ const mod = await import("./loader.js");
12
+ await mod.loadLoomWASM();
13
+ }
11
14
  /**
12
- * Initialize WASM for Node.js environment
15
+ * Initialize WASM
16
+ * Auto-detects environment (Browser vs Node.js)
13
17
  */
14
- export async function init() {
15
- await loadLoomWASM();
18
+ export async function init(wasmUrl) {
19
+ // Check for browser environment (needs window and document for loader.browser.ts)
20
+ if (typeof window !== "undefined" && typeof document !== "undefined") {
21
+ return initBrowser(wasmUrl);
22
+ }
23
+ return loadLoomWASM();
16
24
  }
17
25
  /**
18
26
  * Initialize WASM for Browser environment
19
27
  */
20
- export async function initBrowser() {
21
- await loadLoomWASMBrowser();
28
+ export async function initBrowser(wasmUrl) {
29
+ await loadLoomWASMBrowser(wasmUrl);
22
30
  }
23
31
  /**
24
32
  * Create a network from JSON config
@@ -30,6 +38,12 @@ export function createNetwork(config) {
30
38
  : JSON.stringify(config);
31
39
  return createLoomNetwork(jsonConfig);
32
40
  }
41
+ /**
42
+ * Load a network from JSON string and ID
43
+ */
44
+ export function loadNetwork(jsonString, modelID) {
45
+ return loadLoomNetwork(jsonString, modelID);
46
+ }
33
47
  /**
34
48
  * Create a network handle for grafting
35
49
  */
@@ -86,6 +100,7 @@ export default {
86
100
  init,
87
101
  initBrowser,
88
102
  createNetwork,
103
+ loadNetwork,
89
104
  createKHandle,
90
105
  graft,
91
106
  kmeans,
@@ -2,4 +2,4 @@
2
2
  * LOOM WASM Browser Loader
3
3
  * Browser-only version without Node.js dependencies
4
4
  */
5
- export declare function loadLoomWASMBrowser(): Promise<void>;
5
+ export declare function loadLoomWASMBrowser(wasmUrl?: string): Promise<void>;
@@ -2,7 +2,7 @@
2
2
  * LOOM WASM Browser Loader
3
3
  * Browser-only version without Node.js dependencies
4
4
  */
5
- export async function loadLoomWASMBrowser() {
5
+ export async function loadLoomWASMBrowser(wasmUrl) {
6
6
  // For browser environments - load wasm_exec.js first if not already loaded
7
7
  if (typeof globalThis.Go === "undefined") {
8
8
  // Load wasm_exec.js dynamically from /dist/
@@ -14,7 +14,7 @@ export async function loadLoomWASMBrowser() {
14
14
  document.head.appendChild(script);
15
15
  });
16
16
  }
17
- const response = await fetch("/dist/main.wasm");
17
+ const response = await fetch(wasmUrl || "/dist/main.wasm");
18
18
  const wasmBuffer = await response.arrayBuffer();
19
19
  // @ts-ignore - Go is defined by wasm_exec.js
20
20
  const go = new Go();
package/dist/loader.d.ts CHANGED
File without changes
package/dist/loader.js CHANGED
@@ -2,12 +2,13 @@
2
2
  * LOOM WASM Loader
3
3
  * Loads and initializes the LOOM WebAssembly module (Node.js only)
4
4
  */
5
- import { readFileSync } from "fs";
6
- import { fileURLToPath } from "url";
7
- import { dirname, join } from "path";
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = dirname(__filename);
5
+ // Node.js only loader - using dynamic imports to allow bundling for browser (where this file is not used but might be analyzed)
10
6
  export async function loadLoomWASM() {
7
+ const fs = await import("fs");
8
+ const url = await import("url");
9
+ const path = await import("path");
10
+ const __filename = url.fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
11
12
  // __dirname points to:
12
13
  // - dist/ → in production
13
14
  // - src/ → when running via Bun, ts-node, or example files
@@ -19,16 +20,16 @@ export async function loadLoomWASM() {
19
20
  else {
20
21
  // Running from src/ or example/
21
22
  // Point to project’s dist/ directory
22
- root = join(__dirname, "..", "dist");
23
+ root = path.join(__dirname, "..", "dist");
23
24
  }
24
25
  // Load wasm_exec.js
25
- const wasmExecPath = join(root, "wasm_exec.js");
26
- const wasmExecCode = readFileSync(wasmExecPath, "utf-8");
26
+ const wasmExecPath = path.join(root, "wasm_exec.js");
27
+ const wasmExecCode = fs.readFileSync(wasmExecPath, "utf-8");
27
28
  // Execute wasm_exec.js to get the Go runtime
28
29
  eval(wasmExecCode);
29
30
  // Load main.wasm
30
- const wasmPath = join(root, "main.wasm");
31
- const wasmBuffer = readFileSync(wasmPath);
31
+ const wasmPath = path.join(root, "main.wasm");
32
+ const wasmBuffer = fs.readFileSync(wasmPath);
32
33
  // @ts-ignore - Go runtime from wasm_exec.js
33
34
  const go = new Go();
34
35
  const { instance } = await WebAssembly.instantiate(wasmBuffer, go.importObject);
package/dist/main.wasm CHANGED
Binary file
package/dist/types.d.ts CHANGED
@@ -157,6 +157,7 @@ export interface TweenState {
157
157
  */
158
158
  declare global {
159
159
  function createLoomNetwork(jsonConfig: string): Network;
160
+ function loadLoomNetwork(jsonString: string, modelID: string): Network;
160
161
  function createAdaptationTracker(windowMs: number, totalMs: number): AdaptationTracker;
161
162
  function createNetworkForGraft(jsonConfig: string): number;
162
163
  function graftNetworks(idsJSON: string, combineMode: string): string;
package/dist/types.js CHANGED
File without changes
package/dist/wasm_exec.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfluke/welvet",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript/JavaScript bindings for LOOM neural network framework with WebAssembly support - GPU-accelerated machine learning in the browser",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",