numbl 0.4.5 → 0.4.7

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 (64) hide show
  1. package/dist-cli/cli.js +8500 -4468
  2. package/dist-graphics/graphics/FigureView.d.ts +6 -0
  3. package/dist-graphics/graphics/SurfView.d.ts +18 -0
  4. package/dist-graphics/graphics/axisLimits.d.ts +23 -0
  5. package/dist-graphics/graphics/drawPlot.d.ts +2 -0
  6. package/dist-graphics/graphics/exportFigureHdf5.d.ts +21 -0
  7. package/dist-graphics/graphics/figureHashTransport.d.ts +24 -0
  8. package/dist-graphics/graphics/figureHdf5Schema.d.ts +19 -0
  9. package/dist-graphics/graphics/figureUpload.d.ts +45 -0
  10. package/dist-graphics/graphics/figuresReducer.d.ts +86 -0
  11. package/dist-graphics/graphics/importFigureHdf5.d.ts +9 -0
  12. package/dist-graphics/graphics/openInFigureViewer.d.ts +26 -0
  13. package/dist-graphics/graphics/plotHelpers.d.ts +6 -0
  14. package/dist-graphics/graphics/plotLegend.d.ts +2 -0
  15. package/dist-graphics/graphics/plotMarkers.d.ts +2 -0
  16. package/dist-graphics/graphics/restoreNaNs.d.ts +2 -0
  17. package/dist-graphics/graphics/surfColormap.d.ts +2 -0
  18. package/dist-graphics/graphics/types.d.ts +423 -0
  19. package/dist-graphics/graphics/uihtmlSrcDoc.d.ts +23 -0
  20. package/dist-graphics/graphics-lib.d.ts +21 -0
  21. package/dist-graphics/index.js +35334 -0
  22. package/dist-lib/graphics/types.d.ts +1 -0
  23. package/dist-lib/lib.d.ts +2 -0
  24. package/dist-lib/lib.js +4336 -5416
  25. package/dist-lib/numbl-core/executors/plugins.d.ts +9 -0
  26. package/dist-lib/numbl-core/helpers/marching-cubes-tables.d.ts +10 -0
  27. package/dist-lib/numbl-core/helpers/marching-cubes.d.ts +46 -0
  28. package/dist-lib/numbl-core/interpreter/builtins/array-construction.d.ts +7 -1
  29. package/dist-lib/numbl-core/interpreter/builtins/gallery.d.ts +7 -0
  30. package/dist-lib/numbl-core/interpreter/builtins/geometry.d.ts +10 -0
  31. package/dist-lib/numbl-core/interpreter/builtins/graph.d.ts +29 -0
  32. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +3 -0
  33. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +6 -0
  34. package/dist-lib/numbl-core/interpreter/interpreterExec.d.ts +25 -1
  35. package/dist-lib/numbl-core/interpreter/interpreterFunctions.d.ts +6 -0
  36. package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +4 -0
  37. package/dist-lib/numbl-core/interpreter/types.d.ts +13 -0
  38. package/dist-lib/numbl-core/jit/builtins/runtime/snippets.c.gen.d.ts +4 -0
  39. package/dist-lib/numbl-core/jit/builtins/runtime/snippets.gen.d.ts +0 -2
  40. package/dist-lib/numbl-core/jit/codegen/runtime.d.ts +2 -0
  41. package/dist-lib/numbl-core/lowering/classInfo.d.ts +19 -2
  42. package/dist-lib/numbl-core/native/geometry-bridge.d.ts +39 -0
  43. package/dist-lib/numbl-core/native/qhull-browser.d.ts +15 -0
  44. package/dist-lib/numbl-core/native/qhull-node.d.ts +13 -0
  45. package/dist-lib/numbl-core/parser/ArgumentsParser.d.ts +6 -1
  46. package/dist-lib/numbl-core/runtime/constructors.d.ts +2 -1
  47. package/dist-lib/numbl-core/runtime/plotUtils.d.ts +18 -0
  48. package/dist-lib/numbl-core/runtime/runtime.d.ts +2 -1
  49. package/dist-lib/numbl-core/runtime/runtimeMemberAccess.d.ts +1 -1
  50. package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +1 -0
  51. package/dist-lib/numbl-core/version.d.ts +1 -1
  52. package/dist-plot-viewer/assets/hdf5_hl-C9YUKPMe.js +24296 -0
  53. package/dist-plot-viewer/assets/index-YeXWXIxH.js +4504 -0
  54. package/dist-plot-viewer/index.html +1 -1
  55. package/dist-site-viewer/assets/hdf5_hl-C9YUKPMe.js +24296 -0
  56. package/dist-site-viewer/assets/index-RucHpf4b.js +4826 -0
  57. package/dist-site-viewer/assets/numbl-worker-IO39kohI.js +5228 -0
  58. package/dist-site-viewer/assets/qhull-DM50poqF.wasm +0 -0
  59. package/dist-site-viewer/index.html +1 -1
  60. package/native/lapack_svd.cpp +50 -0
  61. package/package.json +22 -2
  62. package/dist-plot-viewer/assets/index-CPiPZdGN.js +0 -4504
  63. package/dist-site-viewer/assets/index-Y_Z9U6zO.js +0 -4826
  64. 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,7 @@
1
+ /**
2
+ * gallery — families of test matrices.
3
+ *
4
+ * Currently implements the 'tridiag' family (sparse tridiagonal matrices),
5
+ * which is the variant exercised by library code such as M-M.E.S.S.
6
+ */
7
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Interpreter IBuiltins for computational geometry functions: delaunay,
3
+ * delaunayn, convhull, convhulln, inpolygon.
4
+ *
5
+ * delaunay/delaunayn/convhull/convhulln are backed by the qhull WASM module,
6
+ * installed 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 {};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Undirected graph object (`graph`) and a subset of its methods.
3
+ *
4
+ * MATLAB's `graph` is a value class representing an undirected graph. Here a
5
+ * graph is a class_instance with className="graph" and three internal fields:
6
+ * _n number of nodes
7
+ * _A symmetric weighted adjacency as a RuntimeSparseMatrix
8
+ * _weighted whether the graph carries edge weights
9
+ *
10
+ * Supported constructors:
11
+ * graph() empty graph
12
+ * graph(A) adjacency matrix (A must be symmetric)
13
+ * graph(A, 'omitselfloops') drop the diagonal
14
+ * graph(A, 'upper' | 'lower') read one triangle of A
15
+ * graph(s, t) edge list (unweighted)
16
+ * graph(s, t, w) edge list (weighted)
17
+ * graph(s, t, w, num) edge list, num nodes
18
+ *
19
+ * Supported methods (called as functions, e.g. conncomp(G)):
20
+ * conncomp(G) / [bins, sizes] = conncomp(G) connected components
21
+ * laplacian(G) graph Laplacian (unweighted)
22
+ * addedge(G, s, t [, w]) add edges, returns a new graph
23
+ * numnodes(G), numedges(G) counts
24
+ * degree(G) per-node degree (column vector)
25
+ *
26
+ * Note: laplacian ignores edge weights (uses the binary adjacency and the
27
+ * node-degree count), matching MATLAB.
28
+ */
29
+ export {};
@@ -27,7 +27,10 @@ import "./cell-struct.js";
27
27
  import "./time-system.js";
28
28
  import "./datetime.js";
29
29
  import "./sparse.js";
30
+ import "./graph.js";
31
+ import "./gallery.js";
30
32
  import "./special-math.js";
33
+ import "./geometry.js";
31
34
  import "./misc.js";
32
35
  import "./dictionary.js";
33
36
  import "./help-text.js";
@@ -34,6 +34,10 @@ export declare class Interpreter {
34
34
  workspaceEnv: Environment | undefined;
35
35
  /** @internal The caller's environment — for evalin/assignin('caller', ...) */
36
36
  callerEnv: Environment | undefined;
37
+ /** @internal Call-site variable names for the next user-function call, set
38
+ * by `evalFuncCall` and consumed by `callUserFunction` to support
39
+ * `inputname`. One-shot: cleared as soon as it is consumed. */
40
+ pendingInputNames: string[] | undefined;
37
41
  /** @internal Stack of [base, dimIndex, numIndices] for resolving `end` keyword in indexing. */
38
42
  endContextStack: Array<{
39
43
  base: unknown;
@@ -119,6 +123,7 @@ export declare class Interpreter {
119
123
  evalBinary: (expr: Extract<Expr, {
120
124
  type: "Binary";
121
125
  }>) => unknown;
126
+ evalCondition: (expr: Expr) => unknown;
122
127
  evalUnary: (expr: Extract<Expr, {
123
128
  type: "Unary";
124
129
  }>) => unknown;
@@ -156,6 +161,7 @@ export declare class Interpreter {
156
161
  switchMatch: (switchVal: unknown, caseVal: unknown) => boolean;
157
162
  isOutputExpr: (expr: Expr) => boolean;
158
163
  callFunction: (name: string, args: unknown[], nargout: number) => unknown;
164
+ declaredNargin: (name: string) => number | undefined;
159
165
  interpretTarget: (target: ResolvedTarget, args: unknown[], nargout: number) => unknown;
160
166
  interpretLocalFunction: (target: Extract<ResolvedTarget, {
161
167
  kind: "localFunction";
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { Stmt, Expr, LValue } from "../parser/types.js";
6
6
  import type { RuntimeValue } from "../runtime/types.js";
7
- import { type ControlSignal } from "./types.js";
7
+ import { Environment, type ControlSignal } from "./types.js";
8
8
  import type { Interpreter } from "./interpreter.js";
9
9
  export declare function execStmt(this: Interpreter, stmt: Stmt): ControlSignal | null;
10
10
  export declare function execStmts(this: Interpreter, stmts: Stmt[]): ControlSignal | null;
@@ -16,10 +16,34 @@ export declare function execStmts(this: Interpreter, stmts: Stmt[]): ControlSign
16
16
  export declare function execBlockStmts(this: Interpreter, stmts: Stmt[]): ControlSignal | null;
17
17
  export declare function evalExpr(this: Interpreter, expr: Expr): unknown;
18
18
  export declare function evalExprNargout(this: Interpreter, expr: Expr, nargout: number): unknown;
19
+ /** Compute the call-site variable names for `inputname`, aligned to the
20
+ * argument expressions. Entry i is the name of the variable passed as
21
+ * argument i+1, or '' if that argument is not a plain workspace variable.
22
+ *
23
+ * Per MATLAB: an argument that uses cell `{}` or dot `.` indexing produces
24
+ * a comma-separated list, making the position of every following argument
25
+ * dynamic — so that argument and all subsequent ones report ''. Plain
26
+ * literals, expressions, and paren-indexing report '' only for themselves.
27
+ *
28
+ * The returned array may be shorter than the flattened arg count (when an
29
+ * argument expanded to a CSL); callers treat out-of-range indices as ''.
30
+ */
31
+ export declare function computeInputNames(argExprs: Expr[], callerEnv: Environment): string[];
19
32
  export declare function evalArgs(this: Interpreter, argExprs: Expr[]): unknown[];
20
33
  export declare function evalBinary(this: Interpreter, expr: Extract<Expr, {
21
34
  type: "Binary";
22
35
  }>): unknown;
36
+ /**
37
+ * Evaluate an `if`/`while`/`elseif` condition.
38
+ *
39
+ * MATLAB short-circuits the element-wise `&` and `|` operators when they
40
+ * appear at the top of a conditional expression and the left operand is
41
+ * scalar — e.g. `if nargin<4 | isempty(x)` must NOT evaluate `isempty(x)`
42
+ * when `nargin<4` (otherwise `x` may be undefined). Outside this context
43
+ * `&`/`|` evaluate both operands element-wise, so the special handling
44
+ * lives here rather than in `evalBinary`.
45
+ */
46
+ export declare function evalCondition(this: Interpreter, expr: Expr): unknown;
23
47
  export declare function evalUnary(this: Interpreter, expr: Extract<Expr, {
24
48
  type: "Unary";
25
49
  }>): unknown;
@@ -8,6 +8,12 @@ import type { ClassInfo } from "../lowering/classInfo.js";
8
8
  import { Environment, type FunctionDef } from "./types.js";
9
9
  import type { Interpreter } from "./interpreter.js";
10
10
  export declare function callFunction(this: Interpreter, name: string, args: unknown[], nargout: number): unknown;
11
+ /** Declared input count of the user function a `@name` handle points to,
12
+ * resolved the same way a call to `name` would resolve. Returns undefined
13
+ * when the target is a builtin or otherwise has no resolvable user-function
14
+ * AST (caller falls back to probing / 0). Used to populate
15
+ * `nargin(@name)`. */
16
+ export declare function declaredNargin(this: Interpreter, name: string): number | undefined;
11
17
  export declare function interpretTarget(this: Interpreter, target: ResolvedTarget, args: unknown[], nargout: number): unknown;
12
18
  export declare function interpretJsUserFunction(this: Interpreter, target: Extract<ResolvedTarget, {
13
19
  kind: "jsUserFunction";
@@ -25,6 +25,10 @@ export interface InterpreterContext {
25
25
  kind: "function" | "jsfunction" | "class";
26
26
  source: string;
27
27
  } | undefined;
28
+ /** Public (GetAccess public) property names of a class, including inherited
29
+ * ones, in declaration order. Returns undefined if `className` is not a
30
+ * known class. Backs `properties(obj)`. */
31
+ classPublicProperties: (className: string) => string[] | undefined;
28
32
  }
29
33
  export declare const FALL_THROUGH: unique symbol;
30
34
  export type InterpreterSpecialBuiltinHandler = (ctx: InterpreterContext, args: unknown[], nargout: number) => unknown | typeof FALL_THROUGH;
@@ -41,12 +41,25 @@ export declare class Environment {
41
41
  set persistentNames(v: Set<string>);
42
42
  /** Function ID for persistent variable storage */
43
43
  persistentFuncId: string | undefined;
44
+ /** Call-site variable names of this frame's arguments, for `inputname`.
45
+ * Entry i is the name of the variable passed as argument i+1, or '' if
46
+ * that argument was not a plain variable. Undefined when the call did
47
+ * not originate from an interpreted call expression (e.g. feval, JIT).
48
+ * Read directly off the executing frame — the interpreter has only
49
+ * function-level scoping, so `this.env` is the frame while a body runs. */
50
+ inputArgNames: string[] | undefined;
44
51
  /** Back-reference to the runtime (needed for global/persistent access) */
45
52
  rt: Runtime | null;
46
53
  /** Set when a `@nestedFn` handle has been created that captures this env
47
54
  * (or an ancestor). Tells the function-exit cleanup that clearing this
48
55
  * env would strand the handle's closure, so locals must be left alive. */
49
56
  nestedHandleCreated: boolean;
57
+ /** For a nested-function frame: the names of this function's own formal
58
+ * input/output arguments. These are always local — a write must never be
59
+ * redirected to a same-named variable in the parent, even before the
60
+ * output has been assigned. (MATLAB scopes a nested function's formal
61
+ * arguments to that function; only other variables are shared.) */
62
+ nestedLocalNames: Set<string> | undefined;
50
63
  constructor(parent?: Environment | undefined);
51
64
  get(name: string): RuntimeValue | undefined;
52
65
  /** Set variable — for nested scopes, writes to parent if variable
@@ -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. */
@@ -18,9 +18,10 @@ export interface ClassInfo {
18
18
  methodNames: Set<string>;
19
19
  staticMethodNames: Set<string>;
20
20
  constructorName: string | null;
21
- ast: Stmt & {
21
+ ast: (Stmt & {
22
22
  type: "ClassDef";
23
- };
23
+ }) | null;
24
+ isOldStyle?: boolean;
24
25
  inferiorClasses: string[];
25
26
  externalMethodFiles: Map<string, {
26
27
  fileName: string;
@@ -34,3 +35,19 @@ export interface ClassInfo {
34
35
  export declare function extractClassInfo(classDef: Stmt & {
35
36
  type: "ClassDef";
36
37
  }, qualifiedName: string, fileName: string, source: string): ClassInfo;
38
+ /**
39
+ * Build ClassInfo for an old-style (pre-classdef) `@ClassName` folder class.
40
+ * There is no classdef AST: the constructor is the `@Name/Name.m` plain
41
+ * function (which calls `obj = class(struct, 'Name')`), and every other `.m`
42
+ * in the folder is an external method dispatched on instances. Fields are
43
+ * dynamic (defined by the constructor's struct), so there are no declared
44
+ * property names.
45
+ */
46
+ export declare function makeOldStyleClassInfo(qualifiedName: string, baseName: string, constructorFile: {
47
+ fileName: string;
48
+ source: string;
49
+ }, methodFiles: {
50
+ name: string;
51
+ fileName: string;
52
+ source: string;
53
+ }[]): ClassInfo;
@@ -0,0 +1,39 @@
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
+ /**
27
+ * Compute the convex hull of `points` (an array of dim-dimensional tuples).
28
+ * Returns an array of simplicial facets, each a list of `dim` 0-based input
29
+ * point indices (edges in 2-D, triangles in 3-D).
30
+ */
31
+ export type ConvexHullBackend = (points: number[][], dim: number) => number[][];
32
+ /** Install (or clear, with null) the Delaunay backend. */
33
+ export declare function setDelaunayBackend(fn: DelaunayBackend | null): void;
34
+ /** Get the current Delaunay backend, or null if none is installed. */
35
+ export declare function getDelaunayBackend(): DelaunayBackend | null;
36
+ /** Install (or clear, with null) the convex-hull backend. */
37
+ export declare function setConvexHullBackend(fn: ConvexHullBackend | null): void;
38
+ /** Get the current convex-hull backend, or null if none is installed. */
39
+ export declare function getConvexHullBackend(): ConvexHullBackend | 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>;
@@ -14,7 +14,12 @@ export declare class ArgumentsParser extends ControlFlowParser {
14
14
  */
15
15
  private parseArgDimensions;
16
16
  /**
17
- * Parse validator list: {mustBeNumeric, mustBePositive}
17
+ * Parse validator list: {mustBeNumeric, mustBePositive}. Validators may be
18
+ * full function calls with arguments, e.g.
19
+ * `{mustBeMember(x,["a","b"]), mustBeInRange(x,0,7)}`. The validator bodies
20
+ * are not enforced at runtime, so we capture the top-level validator name
21
+ * tokens and skip past any nested `(...)`, `[...]`, `{...}` so parsing
22
+ * resumes correctly at the default value (`= expr`) or end of line.
18
23
  */
19
24
  private parseArgValidators;
20
25
  /**
@@ -2,7 +2,7 @@
2
2
  * RuntimeValue constructor helpers (the RTV namespace).
3
3
  */
4
4
  import { ItemType } from "../lowering/itemTypes.js";
5
- import { type RuntimeNumber, RuntimeTensor, type RuntimeString, RuntimeChar, type RuntimeLogical, RuntimeCell, RuntimeStruct, RuntimeFunction, RuntimeClassInstance, RuntimeComplexNumber, RuntimeDummyHandle, RuntimeGraphicsHandle, RuntimeStructArray, RuntimeSparseMatrix, RuntimeDictionary, type RuntimeValue } from "./types.js";
5
+ import { type RuntimeNumber, RuntimeTensor, type RuntimeString, RuntimeChar, type RuntimeLogical, RuntimeCell, RuntimeStruct, RuntimeFunction, RuntimeClassInstance, RuntimeClassInstanceArray, RuntimeComplexNumber, RuntimeDummyHandle, RuntimeGraphicsHandle, RuntimeStructArray, RuntimeSparseMatrix, RuntimeDictionary, type RuntimeValue } from "./types.js";
6
6
  export declare const RTV: {
7
7
  num(value: number): RuntimeNumber;
8
8
  tensor(data: Float64Array | number[], shape: number[], imag?: Float64Array | number[]): RuntimeTensor;
@@ -23,6 +23,7 @@ export declare const RTV: {
23
23
  struct(fields: Map<string, RuntimeValue> | Record<string, RuntimeValue>): RuntimeStruct;
24
24
  func(name: string, impl: "builtin" | "user", captures?: RuntimeValue[]): RuntimeFunction;
25
25
  classInstance(className: string, propertyNames: string[], isHandleClass?: boolean, defaults?: Map<string, RuntimeValue>): RuntimeClassInstance;
26
+ classInstanceArray(className: string, elements: RuntimeClassInstance[], shape?: [number, number]): RuntimeClassInstanceArray;
26
27
  complex(re: number, im: number): RuntimeComplexNumber;
27
28
  dummyHandle(): RuntimeDummyHandle;
28
29
  graphicsHandle(trace: Record<string, unknown>, traceType: string): RuntimeGraphicsHandle;
@@ -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
  *
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import { type RuntimeValue, type RuntimeLogical, type RuntimeTensor, type RuntimeStruct, type RuntimeString, type RuntimeFunction, RuntimeError, type CallFrame } from "../runtime/index.js";
14
14
  import { RefScope } from "./refcount.js";
15
- import { RuntimeChar, RuntimeCell, type RuntimeComplexNumber, type RuntimeClassInstance } from "../runtime/types.js";
15
+ import { RuntimeChar, RuntimeCell, RuntimeClassInstanceArray, type RuntimeComplexNumber, type RuntimeClassInstance } from "../runtime/types.js";
16
16
  import { type ItemType } from "../lowering/itemTypes.js";
17
17
  import type { PlotInstruction } from "../../graphics/types.js";
18
18
  import type { ExecOptions } from "../executeCode.js";
@@ -84,6 +84,7 @@ export declare class Runtime {
84
84
  struct(fields: Map<string, RuntimeValue> | Record<string, RuntimeValue>): RuntimeStruct;
85
85
  func(name: string, impl: "builtin" | "user", captures?: RuntimeValue[]): RuntimeFunction;
86
86
  classInstance(className: string, propertyNames: string[], isHandleClass?: boolean, defaults?: Map<string, RuntimeValue>): RuntimeClassInstance;
87
+ classInstanceArray(className: string, elements: RuntimeClassInstance[], shape?: [number, number]): RuntimeClassInstanceArray;
87
88
  complex(re: number, im: number): RuntimeComplexNumber;
88
89
  dummyHandle(): import("../runtime/types.js").RuntimeDummyHandle;
89
90
  graphicsHandle(trace: Record<string, unknown>, traceType: string): import("../runtime/types.js").RuntimeGraphicsHandle;
@@ -4,7 +4,7 @@
4
4
  import { type RuntimeValue } from "../runtime/index.js";
5
5
  import type { Runtime } from "./runtime.js";
6
6
  export declare function getMember(rt: Runtime, base: unknown, name: string): unknown;
7
- export declare function getMemberDynamic(base: unknown, nameExpr: unknown): RuntimeValue;
7
+ export declare function getMemberDynamic(rt: Runtime, base: unknown, nameExpr: unknown): RuntimeValue;
8
8
  export declare function getMemberOrEmpty(base: unknown, name: string): RuntimeValue;
9
9
  export declare function setMemberReturn(rt: Runtime, base: unknown, name: string, rhs: unknown): unknown;
10
10
  export declare function setMemberDynamicReturn(rt: Runtime, base: unknown, nameExpr: unknown, rhs: unknown): RuntimeValue;
@@ -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.7";