numbl 0.4.5 → 0.4.6

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 (31) hide show
  1. package/dist-cli/cli.js +6175 -4286
  2. package/dist-lib/graphics/types.d.ts +1 -0
  3. package/dist-lib/lib.d.ts +2 -0
  4. package/dist-lib/lib.js +1992 -5205
  5. package/dist-lib/numbl-core/executors/plugins.d.ts +9 -0
  6. package/dist-lib/numbl-core/helpers/marching-cubes-tables.d.ts +10 -0
  7. package/dist-lib/numbl-core/helpers/marching-cubes.d.ts +46 -0
  8. package/dist-lib/numbl-core/interpreter/builtins/array-construction.d.ts +7 -1
  9. package/dist-lib/numbl-core/interpreter/builtins/geometry.d.ts +10 -0
  10. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +1 -0
  11. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +1 -0
  12. package/dist-lib/numbl-core/interpreter/interpreterExec.d.ts +11 -0
  13. package/dist-lib/numbl-core/jit/builtins/runtime/snippets.c.gen.d.ts +4 -0
  14. package/dist-lib/numbl-core/jit/builtins/runtime/snippets.gen.d.ts +0 -2
  15. package/dist-lib/numbl-core/jit/codegen/runtime.d.ts +2 -0
  16. package/dist-lib/numbl-core/native/geometry-bridge.d.ts +29 -0
  17. package/dist-lib/numbl-core/native/qhull-browser.d.ts +15 -0
  18. package/dist-lib/numbl-core/native/qhull-node.d.ts +13 -0
  19. package/dist-lib/numbl-core/runtime/plotUtils.d.ts +18 -0
  20. package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +1 -0
  21. package/dist-lib/numbl-core/version.d.ts +1 -1
  22. package/dist-plot-viewer/assets/index-D4grNz8m.js +4504 -0
  23. package/dist-plot-viewer/index.html +1 -1
  24. package/dist-site-viewer/assets/index-B2mCFC55.js +4826 -0
  25. package/dist-site-viewer/assets/numbl-worker-DWZE29ck.js +5116 -0
  26. package/dist-site-viewer/assets/qhull-DM50poqF.wasm +0 -0
  27. package/dist-site-viewer/index.html +1 -1
  28. package/package.json +2 -1
  29. package/dist-plot-viewer/assets/index-CPiPZdGN.js +0 -4504
  30. package/dist-site-viewer/assets/index-Y_Z9U6zO.js +0 -4826
  31. package/dist-site-viewer/assets/numbl-worker-CdHI6Ort.js +0 -12088
@@ -10,6 +10,15 @@
10
10
  * registered executor.
11
11
  */
12
12
  import type { Registry } from "./registry.js";
13
+ import type { Executor } from "./types.js";
14
+ /** The three C-JIT executors, registered at Node bootstrap. */
15
+ export interface CJitExecutors {
16
+ topLevel: Executor;
17
+ loop: Executor;
18
+ call: Executor;
19
+ }
20
+ /** Register the C-JIT executors. Called once at Node bootstrap. */
21
+ export declare function registerCJitExecutors(execs: CJitExecutors): void;
13
22
  /** Optimization mode label.
14
23
  *
15
24
  * - `"0"` — pure AST interpreter, no executors registered.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Marching-cubes lookup tables (Paul Bourke / Lorensen-Cline).
3
+ *
4
+ * Vendored verbatim from mikolalysenko/isosurface (MIT). Generated from
5
+ * lib/marchingcubes.js; do not edit by hand.
6
+ */
7
+ export declare const edgeTable: Uint32Array<ArrayBuffer>;
8
+ export declare const triTable: number[][];
9
+ export declare const cubeVerts: number[][];
10
+ export declare const edgeIndex: number[][];
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Marching cubes over a regular scalar grid, plus the MATLAB `isosurface`
3
+ * argument parsing. Backs the `isosurface` builtin.
4
+ *
5
+ * The 256-case lookup tables are vendored in `marching-cubes-tables.ts`
6
+ * (MIT, mikolalysenko/isosurface — Paul Bourke's classic table). The loop
7
+ * here adds the two things that library lacks for our use:
8
+ * - vertices interpolated from arbitrary X/Y/Z coordinate arrays (so it is
9
+ * correct for ndgrid, meshgrid, vector, and implicit grids), and
10
+ * - cross-cell vertex sharing (keyed by grid-edge identity), which MATLAB
11
+ * produces by default and which downstream code (e.g. triangle adjacency)
12
+ * relies on.
13
+ */
14
+ import type { RuntimeValue } from "../runtime/types.js";
15
+ export interface IsoMesh {
16
+ /** Physical vertex coordinates, one `[x, y, z]` per vertex. */
17
+ vertices: number[][];
18
+ /** Triangles as 0-based vertex-index triples. */
19
+ faces: number[][];
20
+ /** Per-vertex scalar color data (present only when a colors array is given). */
21
+ colors?: number[];
22
+ }
23
+ type ScalarFn = (i: number, j: number, k: number) => number;
24
+ type CoordFn = (i: number, j: number, k: number) => [number, number, number];
25
+ /**
26
+ * Extract the isosurface of `getVal` at `iso` over an `m×n×p` grid.
27
+ * `getCoord` maps a grid corner to its physical position; `getColor` (if
28
+ * given) supplies a scalar field interpolated onto the surface vertices.
29
+ */
30
+ export declare function marchingCubes(dims: [number, number, number], getVal: ScalarFn, getCoord: CoordFn, iso: number, opts?: {
31
+ share?: boolean;
32
+ getColor?: ScalarFn;
33
+ }): IsoMesh;
34
+ /**
35
+ * Parse `isosurface(...)` arguments and compute the mesh.
36
+ *
37
+ * Forms (by numeric-argument count, after stripping 'verbose'/'noshare'):
38
+ * 1: isosurface(V) 4: isosurface(X,Y,Z,V)
39
+ * 2: isosurface(V,iso) 5: isosurface(X,Y,Z,V,iso)
40
+ * 3: isosurface(V,iso,colors) 6: isosurface(X,Y,Z,V,iso,colors)
41
+ *
42
+ * When the isovalue is omitted it is chosen automatically (see autoIsovalue) —
43
+ * an approximation that does not match MATLAB's exact histogram heuristic.
44
+ */
45
+ export declare function isosurfaceFromArgs(args: RuntimeValue[]): IsoMesh;
46
+ export {};
@@ -1,4 +1,10 @@
1
1
  /**
2
2
  * Array construction builtins: zeros, ones, nan/NaN, eye, linspace, logspace.
3
3
  */
4
- export {};
4
+ import type { RuntimeValue } from "../../runtime/types.js";
5
+ import type { JitType } from "../../jitTypes.js";
6
+ /** Drop a trailing class-name spec from the JIT arg types (used in `match`
7
+ * so the size cases still apply when a class string is present). */
8
+ export declare function stripClassNameTypes(argTypes: JitType[]): JitType[];
9
+ /** Drop a trailing class-name spec from the runtime args (used in `apply`). */
10
+ export declare function stripClassNameArgs(args: RuntimeValue[]): RuntimeValue[];
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Interpreter IBuiltins for computational geometry functions: delaunay,
3
+ * delaunayn, inpolygon.
4
+ *
5
+ * delaunay/delaunayn are backed by the qhull WASM module, installed as the
6
+ * Delaunay backend at startup (see geometry-bridge.ts and the qhull-node /
7
+ * qhull-browser loaders). The backend must be installed before these builtins
8
+ * run; otherwise they throw.
9
+ */
10
+ export {};
@@ -28,6 +28,7 @@ import "./time-system.js";
28
28
  import "./datetime.js";
29
29
  import "./sparse.js";
30
30
  import "./special-math.js";
31
+ import "./geometry.js";
31
32
  import "./misc.js";
32
33
  import "./dictionary.js";
33
34
  import "./help-text.js";
@@ -119,6 +119,7 @@ export declare class Interpreter {
119
119
  evalBinary: (expr: Extract<Expr, {
120
120
  type: "Binary";
121
121
  }>) => unknown;
122
+ evalCondition: (expr: Expr) => unknown;
122
123
  evalUnary: (expr: Extract<Expr, {
123
124
  type: "Unary";
124
125
  }>) => unknown;
@@ -20,6 +20,17 @@ export declare function evalArgs(this: Interpreter, argExprs: Expr[]): unknown[]
20
20
  export declare function evalBinary(this: Interpreter, expr: Extract<Expr, {
21
21
  type: "Binary";
22
22
  }>): unknown;
23
+ /**
24
+ * Evaluate an `if`/`while`/`elseif` condition.
25
+ *
26
+ * MATLAB short-circuits the element-wise `&` and `|` operators when they
27
+ * appear at the top of a conditional expression and the left operand is
28
+ * scalar — e.g. `if nargin<4 | isempty(x)` must NOT evaluate `isempty(x)`
29
+ * when `nargin<4` (otherwise `x` may be undefined). Outside this context
30
+ * `&`/`|` evaluate both operands element-wise, so the special handling
31
+ * lives here rather than in `evalBinary`.
32
+ */
33
+ export declare function evalCondition(this: Interpreter, expr: Expr): unknown;
23
34
  export declare function evalUnary(this: Interpreter, expr: Extract<Expr, {
24
35
  type: "Unary";
25
36
  }>): unknown;
@@ -0,0 +1,4 @@
1
+ /** C snippet bodies, keyed by basename (e.g. `disp_double.h`).
2
+ * C-JIT only (`--opt 2`, Node). Registered at bootstrap via
3
+ * `setCSnippets` so the browser bundle never pulls it in. */
4
+ export declare const C_SNIPPETS: Record<string, string>;
@@ -72,8 +72,6 @@ export * from "./tensor_ops/tensor_var.js";
72
72
  export * from "./tensor_ops/tensor_zeros_nd.js";
73
73
  export * from "./tensor_ops/tensor_zeros_square.js";
74
74
  export * from "./text/strcmp.js";
75
- /** C snippet bodies, keyed by basename (e.g. `disp_double.h`). */
76
- export declare const C_SNIPPETS: Record<string, string>;
77
75
  /** JS snippet bodies (with `export` keywords stripped), keyed by
78
76
  * basename (e.g. `disp_double.js`). Inlined into emitted JS. The
79
77
  * functions may reference host hooks (`$write`, …) as free
@@ -14,6 +14,8 @@
14
14
  * pulls dependencies in first.
15
15
  */
16
16
  import type { Builtin } from "../builtins/registry.js";
17
+ /** Register the C runtime-snippet table. Called once at Node bootstrap. */
18
+ export declare function setCSnippets(snippets: Record<string, string>): void;
17
19
  /** Minimal Workspace shape consulted at emit time. Importing the
18
20
  * concrete Workspace class would create a cycle (workspace ↔ codegen);
19
21
  * the structural type below captures exactly what codegen needs. */
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Geometry bridge — a module-level singleton that holds the Delaunay
3
+ * triangulation backend.
4
+ *
5
+ * Startup (CLI, browser worker, test-runner) loads the qhull WASM module
6
+ * (exact, robust to cospherical/coplanar input) and installs it here. The
7
+ * builtins require it: if no backend is set, delaunay/delaunayn throw.
8
+ *
9
+ * Usage (startup):
10
+ * import { setDelaunayBackend } from './numbl-core/native/geometry-bridge.js';
11
+ * const qhull = await loadQhull();
12
+ * setDelaunayBackend((points, dim) => qhull.delaunay(points, dim).facets);
13
+ *
14
+ * Usage (builtin):
15
+ * import { getDelaunayBackend } from '../native/geometry-bridge.js';
16
+ * const backend = getDelaunayBackend();
17
+ * if (!backend) throw ...;
18
+ * const cells = backend(points, dim);
19
+ */
20
+ /**
21
+ * Compute a Delaunay triangulation of `points` (an array of dim-dimensional
22
+ * tuples). Returns an array of simplices, each a list of `dim+1` 0-based input
23
+ * point indices.
24
+ */
25
+ export type DelaunayBackend = (points: number[][], dim: number) => number[][];
26
+ /** Install (or clear, with null) the Delaunay backend. */
27
+ export declare function setDelaunayBackend(fn: DelaunayBackend | null): void;
28
+ /** Get the current Delaunay backend, or null if none is installed. */
29
+ export declare function getDelaunayBackend(): DelaunayBackend | null;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Browser/worker loader for the qhull WASM Delaunay backend.
3
+ *
4
+ * The CLI installs the backend in cli.ts (reading the `.wasm` from disk). In
5
+ * the browser there is no filesystem, so we let Vite emit the `.wasm` as an
6
+ * asset (`?url`), fetch its bytes, and pass them to the emscripten module as
7
+ * `wasmBinary` — this avoids relying on the glue locating the binary next to
8
+ * itself at runtime.
9
+ *
10
+ * `ensureQhullBackend()` is idempotent and best-effort: on any failure it
11
+ * resolves anyway (so it never crashes the worker), but then no backend is
12
+ * installed and a later `delaunay`/`delaunayn` call throws (see geometry.ts).
13
+ */
14
+ /** Load and install the qhull backend (once). Safe to await before every run. */
15
+ export declare function ensureQhullBackend(): Promise<void>;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Node loader for the qhull WASM Delaunay backend.
3
+ *
4
+ * In Node the emscripten module reads its `.wasm` from disk on its own, so no
5
+ * asset wiring is needed (unlike the browser; see qhull-browser.ts). This is
6
+ * used by the CLI, the vitest setup, and is re-exported from the library entry
7
+ * (lib.ts) so programmatic consumers can install the backend before calling
8
+ * `delaunay` / `delaunayn`.
9
+ *
10
+ * Idempotent: the first call starts loading and caches the promise.
11
+ */
12
+ /** Load the qhull WASM module and install it as the Delaunay backend (once). */
13
+ export declare function loadQhullNodeBackend(): Promise<void>;
@@ -77,6 +77,24 @@ export declare function parsePatchArgs(args: RuntimeValue[]): PatchTrace;
77
77
  * fill(ax, ___)
78
78
  */
79
79
  export declare function parseFillArgs(args: RuntimeValue[]): PatchTrace[];
80
+ /**
81
+ * Parse trimesh() arguments into a canonical PatchTrace.
82
+ *
83
+ * trimesh draws a triangular mesh and (per the MATLAB docs) returns a patch
84
+ * object, so it maps onto the PatchTrace model: the connectivity matrix T
85
+ * supplies the faces (one triangle per row, 1-based vertex indices) and the
86
+ * x/y[/z] vectors supply the vertices.
87
+ *
88
+ * Supported forms:
89
+ * trimesh(T, x, y) — 2-D triangular mesh
90
+ * trimesh(T, x, y, z) — 3-D triangular mesh
91
+ * trimesh(T, x, y, z, c) — c is per-vertex color data
92
+ * trimesh(TO) — triangulation object (struct exposing
93
+ * ConnectivityList + Points)
94
+ * trimesh(___, Name, Value) — patch properties
95
+ * trimesh(ax, ___) — leading axes handle (ignored)
96
+ */
97
+ export declare function parseTriMeshArgs(args: RuntimeValue[]): PatchTrace;
80
98
  /**
81
99
  * Parse surf() arguments.
82
100
  *
@@ -73,6 +73,7 @@ export declare function plotCall(plotInstructions: PlotInstruction[], args: Runt
73
73
  export declare function plot3Call(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
74
74
  export declare function lineCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
75
75
  export declare function patchCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
76
+ export declare function trimeshCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
76
77
  export declare function fillCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
77
78
  export declare function surfCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
78
79
  export declare function surfaceCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
@@ -1,2 +1,2 @@
1
1
  /** Numbl version, used for JIT disk cache invalidation. */
2
- export declare const NUMBL_VERSION = "0.4.5";
2
+ export declare const NUMBL_VERSION = "0.4.6";