numbl 0.4.11 → 0.4.13

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 (30) hide show
  1. package/dist-browser/browser.js +1 -1
  2. package/dist-browser/numbl-core/fileIOAdapter.d.ts +4 -0
  3. package/dist-browser/numbl-core/native/lapack-bridge.d.ts +1 -1
  4. package/dist-browser/numbl-core/native/wasm-lapack-bridge.d.ts +114 -0
  5. package/dist-browser/numbl-core/native/wasm-lapack-browser.d.ts +34 -0
  6. package/dist-browser/numbl-core/runtime/datetime-format.d.ts +10 -0
  7. package/dist-browser/numbl-core/runtime/display.d.ts +5 -1
  8. package/dist-browser/numbl-core/runtime/index.d.ts +1 -1
  9. package/dist-browser/numbl-core/version.d.ts +1 -1
  10. package/dist-browser/vfs/BrowserFileIOAdapter.d.ts +1 -0
  11. package/dist-cli/cli.js +434 -131
  12. package/dist-lib/cli-fileio.d.ts +62 -0
  13. package/dist-lib/cli-scan.d.ts +6 -0
  14. package/dist-lib/cli-system.d.ts +13 -0
  15. package/dist-lib/lib.js +368 -73
  16. package/dist-lib/node.d.ts +30 -0
  17. package/dist-lib/node.js +829 -0
  18. package/dist-lib/numbl-core/fileIOAdapter.d.ts +4 -0
  19. package/dist-lib/numbl-core/native/lapack-bridge.d.ts +1 -1
  20. package/dist-lib/numbl-core/native/wasm-lapack-bridge.d.ts +114 -0
  21. package/dist-lib/numbl-core/native/wasm-lapack-browser.d.ts +34 -0
  22. package/dist-lib/numbl-core/runtime/datetime-format.d.ts +10 -0
  23. package/dist-lib/numbl-core/runtime/display.d.ts +5 -1
  24. package/dist-lib/numbl-core/runtime/index.d.ts +1 -1
  25. package/dist-lib/numbl-core/version.d.ts +1 -1
  26. package/dist-lib/vfs/BrowserFileIOAdapter.d.ts +1 -0
  27. package/dist-site-viewer/assets/{index-fhKbvuOM.js → index-C2ItFYSf.js} +322 -322
  28. package/dist-site-viewer/assets/{numbl-worker-BFP9xj5e.js → numbl-worker-CtfdLxJh.js} +114 -102
  29. package/dist-site-viewer/index.html +1 -1
  30. package/package.json +6 -2
@@ -73,6 +73,10 @@ export interface FileIOAdapter {
73
73
  fileattrib?(path: string): FileAttribInfo | null;
74
74
  /** Extract a ZIP file to an output folder. Returns list of extracted file paths. Optional. */
75
75
  unzip?(zipfilename: string, outputfolder: string): string[];
76
+ /** Create a ZIP file from files/folders (paths resolved relative to
77
+ * rootDir; folders are added recursively; simple globs in the last
78
+ * path component are expanded). Returns the entry names written. Optional. */
79
+ zip?(zipfilename: string, filenames: string[], rootDir: string): string[];
76
80
  /** Return the temporary directory path. Optional. */
77
81
  tempdir?(): string;
78
82
  /** Return the numbl user/config directory path. Optional. */
@@ -29,7 +29,7 @@ export interface LapackBridge {
29
29
  * @returns Inverted matrix as a allocFloat64Array in column-major order.
30
30
  * @throws Error if the matrix is singular.
31
31
  */
32
- inv(data: Float64Array, n: number): Float64Array;
32
+ inv?(data: Float64Array, n: number): Float64Array;
33
33
  /**
34
34
  * Invert an n×n complex matrix stored in column-major order (MATLAB/LAPACK convention).
35
35
  * Complex matrices are stored with separate real and imaginary parts.
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Optional WASM linear-algebra accelerator bridge.
3
+ *
4
+ * numbl can offload heavy LAPACK/BLAS kernels to an externally-hosted
5
+ * WebAssembly module (e.g. libFLAME/BLIS compiled to wasm, served from
6
+ * GitHub Pages). This is the *platform-agnostic core*: it operates on an
7
+ * already-instantiated wasm `exports` object, so it has no `fetch` /
8
+ * `WebAssembly.instantiate` dependency and runs identically under Node and
9
+ * the browser. The browser worker owns the fetch + instantiate step and
10
+ * hands the exports here (see the browser loader); Node bundling can reuse
11
+ * the same functions later.
12
+ *
13
+ * Two seams are installed from one instantiated module (see
14
+ * `installWasmLapackBridge`):
15
+ * 1. `setLapackBridge()` — covers the *interpreter* path (opt 0), which
16
+ * already resolves per-op via `getEffectiveBridge` and falls back to
17
+ * ts-lapack for any op the bridge omits.
18
+ * 2. `globalThis.$matmulAccel` — the hook the JS-JIT matmul runtime
19
+ * snippet consults (opt 1, the browser IDE default), which otherwise
20
+ * runs a naive JS triple-loop that never touches the bridge.
21
+ *
22
+ * Trust model: numbl instantiates only the module's *wasm* (never remote
23
+ * JS) with a numbl-controlled import object, and does all marshaling here,
24
+ * so the accelerator is sandboxed — it cannot reach the DOM or network.
25
+ *
26
+ * v1 exposes real f64 `matmul` only. The ABI and manifest are versioned so
27
+ * more ops (svd/qr/lu/…) can be added without breaking older endpoints.
28
+ */
29
+ import { type LapackBridge } from "./lapack-bridge.js";
30
+ /** Bumped when the wasm ABI (export names / signatures) changes
31
+ * incompatibly. An endpoint manifest must advertise the same major. */
32
+ export declare const ACCELERATOR_ABI = 1;
33
+ /** Below this many multiply-adds (`m*n*k`) the JS loop beats the cost of
34
+ * marshaling into and out of the wasm heap, so the accelerator declines
35
+ * and the caller uses its own loop. Tuned conservatively; small matmuls
36
+ * dominate typical MATLAB code and should never pay the copy tax. */
37
+ export declare const WASM_MATMUL_MIN_WORK = 100000;
38
+ /** Manifest served alongside the wasm (`numbl-bridge.json`). Describes
39
+ * which ops/precisions the endpoint provides so numbl can negotiate
40
+ * capabilities and fall back per-op for anything absent. */
41
+ export interface AcceleratorManifest {
42
+ /** Wasm ABI major version. Must equal `ACCELERATOR_ABI` to load. */
43
+ abi: number;
44
+ /** Human-readable endpoint name (for diagnostics). */
45
+ name?: string;
46
+ /** Whether the module uses wasm threads (SharedArrayBuffer). v1: false. */
47
+ threads?: boolean;
48
+ /** Advertised operations. Only `matmul` is understood in v1. */
49
+ ops: {
50
+ matmul?: {
51
+ precision: string[];
52
+ complex?: boolean;
53
+ };
54
+ };
55
+ /** Wasm binary filename, resolved relative to the manifest URL. */
56
+ wasm: string;
57
+ }
58
+ /** The subset of a wasm module's exports the v1 ABI requires. A conforming
59
+ * module exports its linear `memory`, a bump/allocator pair, and the
60
+ * column-major real gemm. All pointers are byte offsets into `memory`. */
61
+ export interface WasmLapackExports {
62
+ memory: WebAssembly.Memory;
63
+ numbl_malloc(nbytes: number): number;
64
+ numbl_free(ptr: number): void;
65
+ /** C(m×n) = A(m×k) · B(k×n), all column-major f64, in `memory`. */
66
+ numbl_matmul_f64_colmajor(aPtr: number, bPtr: number, cPtr: number, m: number, k: number, n: number): void;
67
+ }
68
+ /** Signature shared by `LapackBridge.matmul` and the `$matmulAccel` hook. */
69
+ export type MatmulFn = (a: Float64Array, m: number, k: number, b: Float64Array, n: number) => Float64Array;
70
+ /**
71
+ * Validate a fetched manifest. Returns the typed manifest or throws with a
72
+ * specific reason (so the loader can log and fall back to ts-lapack).
73
+ */
74
+ export declare function validateManifest(raw: unknown): AcceleratorManifest;
75
+ /**
76
+ * Build a real-f64 matmul closure over an instantiated wasm module. Copies
77
+ * the (column-major) inputs into the wasm heap, runs the kernel, and copies
78
+ * the result out into a fresh `Float64Array`.
79
+ *
80
+ * Memory-growth safe: heap views are constructed *after* every `malloc`
81
+ * (which may grow and detach `memory.buffer`) and the result view is taken
82
+ * *after* the kernel call.
83
+ */
84
+ export declare function makeWasmMatmul(exports: WasmLapackExports): MatmulFn;
85
+ /**
86
+ * Assemble a (partial) `LapackBridge` from an instantiated module, exposing
87
+ * only the ops the manifest advertises. Ops the bridge omits resolve to
88
+ * ts-lapack via `getEffectiveBridge`.
89
+ */
90
+ export declare function buildLapackBridgeFromWasm(exports: WasmLapackExports, manifest: AcceleratorManifest): LapackBridge;
91
+ /**
92
+ * Install/remove the JS-JIT matmul accelerator hook (`globalThis.$matmulAccel`)
93
+ * that `mtoc2_tensor_mtimes_real` consults. Pass `null` to uninstall.
94
+ */
95
+ export declare function setMatmulAccelerator(fn: ((a: Float64Array, m: number, k: number, b: Float64Array, n: number) => Float64Array | null | undefined) | null): void;
96
+ /** Current matmul accelerator hook, or undefined if none is installed. */
97
+ export declare function getMatmulAccelerator(): ((a: Float64Array, m: number, k: number, b: Float64Array, n: number) => Float64Array | null | undefined) | undefined;
98
+ /**
99
+ * Install both seams from one instantiated module:
100
+ * - registers a partial `LapackBridge` (interpreter / opt 0), and
101
+ * - installs the `$matmulAccel` hook (JS-JIT / opt 1) when the module
102
+ * provides matmul.
103
+ *
104
+ * The `$matmulAccel` wrapper is best-effort: it declines (returns `null`)
105
+ * for small matmuls and on any error, so the JS loop remains the fallback.
106
+ * The interpreter-path `bridge.matmul` is NOT wrapped — it propagates
107
+ * errors like any other bridge (matching native-addon semantics).
108
+ */
109
+ /** Remove both seams (e.g. when the user disables the accelerator). Leaves
110
+ * the interpreter and JS-JIT on ts-lapack / the JS loop. */
111
+ export declare function uninstallWasmLapackBridge(): void;
112
+ export declare function installWasmLapackBridge(exports: WasmLapackExports, manifest: AcceleratorManifest): {
113
+ matmul: boolean;
114
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Browser/worker loader for the optional WASM linear-algebra accelerator.
3
+ *
4
+ * Mirrors `qhull-browser.ts`: fetch the endpoint's manifest, fetch and
5
+ * instantiate its wasm, and install it via `installWasmLapackBridge`. numbl
6
+ * instantiates the wasm itself (no remote JS is executed) with a
7
+ * numbl-controlled import object, so the accelerator is sandboxed.
8
+ *
9
+ * Best-effort: any failure resolves to `false` (nothing installed → the
10
+ * interpreter/JIT keep using ts-lapack / the JS loop). Idempotent per URL —
11
+ * a repeat call for the same URL returns the in-flight/settled promise.
12
+ *
13
+ * `fetchImpl` / `instantiate` / `cache` are injectable so the whole
14
+ * orchestration is unit-testable without a wasm toolchain.
15
+ */
16
+ /** Persistent byte cache (e.g. IndexedDB) for wasm binaries, keyed by URL.
17
+ * Optional; failures must be non-fatal. */
18
+ export interface WasmByteCache {
19
+ get(key: string): Promise<Uint8Array | null>;
20
+ put(key: string, bytes: Uint8Array): Promise<void>;
21
+ }
22
+ export interface LoadWasmLapackDeps {
23
+ fetchImpl?: typeof fetch;
24
+ /** Instantiate wasm bytes; defaults to `WebAssembly.instantiate`. */
25
+ instantiate?: (bytes: BufferSource, imports: WebAssembly.Imports) => Promise<WebAssembly.Instance>;
26
+ cache?: WasmByteCache;
27
+ }
28
+ /**
29
+ * Ensure the accelerator for `url` is loaded and installed. Pass `null` (or
30
+ * empty) to uninstall. Returns a promise for whether matmul got installed.
31
+ */
32
+ export declare function ensureWasmLapackBridge(url: string | null, deps?: LoadWasmLapackDeps): Promise<boolean>;
33
+ /** Test-only: reset the module-level idempotency cache. */
34
+ export declare function _resetWasmLapackLoaderForTests(): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Formatter for datetime `Format` patterns — the Unicode-LDML-style tokens
3
+ * MATLAB uses (e.g. "yyyy-MM-dd'T'HH:mm:ss'Z'").
4
+ *
5
+ * Supported tokens: y/u (year), M (month; MMM abbreviated name, MMMM full
6
+ * name), d (day of month), H (hour 0–23), h (hour 1–12), m (minute),
7
+ * s (second), S (fractional-second digits), a (AM/PM). Text between single
8
+ * quotes is emitted literally; '' is an escaped single quote.
9
+ */
10
+ export declare function formatDatetimePattern(pattern: string, year: number, month: number, day: number, hour: number, minute: number, second: number): string;
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Value display/formatting.
3
3
  */
4
- import { type RuntimeValue } from "./types.js";
4
+ import { type RuntimeClassInstance, type RuntimeValue } from "./types.js";
5
5
  /** Format a value for display */
6
6
  export declare function displayValue(v: RuntimeValue): string;
7
+ /** Format a datetime or duration instance for display / char conversion.
8
+ * Returns null when the instance lacks the expected fields (or is some
9
+ * other class), letting the generic class-instance display run. */
10
+ export declare function formatDatetimeOrDuration(v: RuntimeClassInstance): string | null;
@@ -5,7 +5,7 @@ export type { CallFrame } from "./error.js";
5
5
  export { tensorSize2D, numel, colMajorIndex } from "./utils.js";
6
6
  export { toNumber, toBool, toString } from "./convert.js";
7
7
  export { valuesAreEqual } from "./compare.js";
8
- export { displayValue } from "./display.js";
8
+ export { displayValue, formatDatetimeOrDuration } from "./display.js";
9
9
  export { RTV } from "./constructors.js";
10
10
  export { mAdd, mSub, mMul, mElemMul, mDiv, mElemDiv, mPow, mElemPow, mNeg, mTranspose, mConjugateTranspose, mEqual, mNotEqual, mLess, mLessEqual, mGreater, mGreaterEqual, } from "../helpers/arithmetic.js";
11
11
  export { COLON_INDEX, indexIntoRTValue as mIndex, storeIntoRTValueIndex as mIndexStore, charToNumericTensor, numericTensorToChar, } from "./indexing.js";
@@ -1,2 +1,2 @@
1
1
  /** Numbl version, used for JIT disk cache invalidation. */
2
- export declare const NUMBL_VERSION = "0.4.11";
2
+ export declare const NUMBL_VERSION = "0.4.13";
@@ -43,6 +43,7 @@ export declare class BrowserFileIOAdapter implements FileIOAdapter {
43
43
  websave(url: string, filename: string, options?: WebOptions): void;
44
44
  webread(url: string, options?: WebOptions): string;
45
45
  unzip(zipfilename: string, outputfolder: string): string[];
46
+ zip(zipfilename: string, filenames: string[], rootDir: string): string[];
46
47
  /** Get the VFS changes for syncing back to the main thread. */
47
48
  getChanges(): VfsChanges;
48
49
  private getEntry;