numbl 0.4.0 → 0.4.2

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.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * "Effectively real" helpers.
3
+ *
4
+ * numbl's JIT cannot always prove at compile time that the result of an
5
+ * operation is real (e.g. `sqrt(1 - x.^2/2)` — the argument's sign is not
6
+ * statically provable, so `sqrt` lifts to the complex path). The result is
7
+ * a complex-typed tensor whose imaginary lane is entirely zero — an
8
+ * artifact of static typing, not a value the user asked to be complex.
9
+ *
10
+ * Value-sensitive builtins (`isreal`, `min`, `max`, `sort`, …) must treat
11
+ * such a tensor exactly as they would a real one: otherwise `min`/`max`
12
+ * silently switch to magnitude ordering and `isreal` reports `false`,
13
+ * diverging from the interpreter (`--opt 0`, which never creates the
14
+ * artifact) and from MATLAB on real data. These helpers detect the
15
+ * all-zero imaginary lane and drop it so the real code path runs.
16
+ */
17
+ import type { RuntimeValue } from "../runtime/index.js";
18
+ import { type RuntimeTensor } from "../runtime/types.js";
19
+ /** True when `imag` is absent or every element is exactly zero. */
20
+ export declare function imagAllZero(imag: ArrayLike<number> | undefined): boolean;
21
+ /** If `t` carries an all-zero imaginary lane, return a real view sharing
22
+ * its data; otherwise return `t` unchanged. */
23
+ export declare function stripZeroImagTensor(t: RuntimeTensor): RuntimeTensor;
24
+ /** Tensor-aware variant for the generic `RuntimeValue` channel. */
25
+ export declare function stripZeroImagValue(v: RuntimeValue): RuntimeValue;
@@ -189,5 +189,5 @@ export declare class Interpreter {
189
189
  };
190
190
  isHandleClass: (classInfo: ClassInfo) => boolean;
191
191
  evalInLocalScope: (codeArg: unknown, fileName?: string) => unknown;
192
- processArgumentsBlocks: (fn: FunctionDef, args: unknown[]) => unknown[];
192
+ processArgumentsBlocks: (fn: FunctionDef, args: unknown[]) => void;
193
193
  }
@@ -41,4 +41,16 @@ export declare function collectClassProperties(this: Interpreter, classInfo: Cla
41
41
  };
42
42
  export declare function isHandleClass(this: Interpreter, classInfo: ClassInfo): boolean;
43
43
  export declare function evalInLocalScope(this: Interpreter, codeArg: unknown, fileName?: string): unknown;
44
- export declare function processArgumentsBlocks(this: Interpreter, fn: FunctionDef, args: unknown[]): unknown[];
44
+ /**
45
+ * Apply `arguments`-block defaults and build name-value struct parameters,
46
+ * binding the results into the *current* function environment.
47
+ *
48
+ * Must be called with `this.env` already set to the function scope and the
49
+ * caller-supplied positional arguments already bound to their parameters.
50
+ * Default expressions are evaluated in that scope so they can reference
51
+ * earlier arguments (e.g. `mergeIdx = surfaceop.defaultIdx(dom)`), matching
52
+ * MATLAB. Entries are matched to parameters by name via `fn.params`, which
53
+ * also handles the constructor case where the output variable is prepended
54
+ * to `params` (shifting argument positions by one).
55
+ */
56
+ export declare function processArgumentsBlocks(this: Interpreter, fn: FunctionDef, args: unknown[]): void;
@@ -44,6 +44,7 @@ export * from "./tensor_ops/tensor_eye.js";
44
44
  export * from "./tensor_ops/tensor_fill_nd.js";
45
45
  export * from "./tensor_ops/tensor_fill_square.js";
46
46
  export * from "./tensor_ops/tensor_flip.js";
47
+ export * from "./tensor_ops/tensor_imag_all_zero.js";
47
48
  export * from "./tensor_ops/tensor_linspace.js";
48
49
  export * from "./tensor_ops/tensor_logical_real.js";
49
50
  export * from "./tensor_ops/tensor_logspace.js";
@@ -0,0 +1 @@
1
+ export function mtoc2_tensor_imag_all_zero(a: any): boolean;
@@ -5,8 +5,8 @@
5
5
  * plot(X1,Y1,LineSpec1,...), and Name-Value pairs like 'Color','r','LineWidth',2.
6
6
  */
7
7
  import { type RuntimeValue } from "./types.js";
8
- export type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, } from "../../graphics/types.js";
9
- import type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace } from "../../graphics/types.js";
8
+ export type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace, } from "../../graphics/types.js";
9
+ import type { PlotTrace, Plot3Trace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace } from "../../graphics/types.js";
10
10
  export interface ParsedLineSpec {
11
11
  color?: string;
12
12
  lineStyle?: string;
@@ -75,6 +75,20 @@ export declare function parseImagescArgs(args: RuntimeValue[]): ImagescTrace;
75
75
  * contour(..., Name, Value)
76
76
  */
77
77
  export declare function parseContourArgs(args: RuntimeValue[], filled: boolean): ContourTrace;
78
+ /** Result of computing contour geometry: the MATLAB contour matrix `C`
79
+ * (column-major `2 × n` data) plus the level list actually used. */
80
+ export interface ContourMatrix {
81
+ /** Column-major `2 × n` data for a `RTV.tensor(data, [2, n])`. */
82
+ data: number[];
83
+ n: number;
84
+ levelList: number[];
85
+ }
86
+ /** Compute the MATLAB contour matrix for a parsed contour trace via marching
87
+ * squares. Each marching-squares segment is emitted as its own two-vertex
88
+ * contour line (header `[level; 2]` followed by the two `[x; y]` vertices) —
89
+ * a valid contour matrix whose geometry matches MATLAB's connected polylines
90
+ * segment-for-segment. */
91
+ export declare function computeContourMatrix(trace: ContourTrace): ContourMatrix;
78
92
  /**
79
93
  * Parse mesh() arguments — same as surf but with different default rendering.
80
94
  */
@@ -237,3 +251,15 @@ export declare function parseHeatmapArgs(args: RuntimeValue[]): HeatmapTrace;
237
251
  * vectors, X and Y are expanded to a meshgrid.
238
252
  */
239
253
  export declare function parseQuiverArgs(args: RuntimeValue[]): QuiverTrace[];
254
+ /**
255
+ * Parse quiver3() arguments.
256
+ *
257
+ * Supported forms:
258
+ * quiver3(Z, U, V, W)
259
+ * quiver3(X, Y, Z, U, V, W)
260
+ * quiver3(..., scale) — scale: nonnegative number or 'off'
261
+ * quiver3(..., LineSpec)
262
+ * quiver3(..., LineSpec, 'filled')
263
+ * quiver3(..., Name, Value) — Color, LineStyle, LineWidth, ShowArrowHead, …
264
+ */
265
+ export declare function parseQuiver3Args(args: RuntimeValue[]): Quiver3Trace;
@@ -33,6 +33,9 @@ export declare function plotInstr(plotInstructions: PlotInstruction[], instr: {
33
33
  type: "close_all";
34
34
  } | {
35
35
  type: "clf";
36
+ } | {
37
+ type: "cla";
38
+ reset: boolean;
36
39
  } | {
37
40
  type: "set_subplot";
38
41
  rows: unknown;
@@ -66,6 +69,7 @@ export declare function viewCall(plotInstructions: PlotInstruction[], args: Runt
66
69
  export declare function plotCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
67
70
  export declare function plot3Call(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
68
71
  export declare function surfCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
72
+ export declare function surfaceCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
69
73
  export declare function imagescCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
70
74
  export declare function pcolorCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
71
75
  export declare function contourCall(plotInstructions: PlotInstruction[], args: RuntimeValue[], filled: boolean): void;
@@ -101,6 +105,7 @@ export declare function piechartCall(plotInstructions: PlotInstruction[], args:
101
105
  export declare function donutchartCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
102
106
  export declare function heatmapCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
103
107
  export declare function quiverCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
108
+ export declare function quiver3Call(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
104
109
  export declare function legendCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
105
110
  export declare function drawnow(plotInstructions: PlotInstruction[], options: ExecOptions): void;
106
111
  export declare function pause(seconds: unknown): void;
@@ -116,13 +116,16 @@ export declare class RuntimeClassInstance extends Refcounted {
116
116
  bindField(rt: RefcountRuntime, name: string, value: RuntimeValue): void;
117
117
  protected _destroy(rt: RefcountRuntime): void;
118
118
  }
119
- /** A 1-D array of class instances that all share the same class.
120
- * Created by default horzcat/vertcat when the class doesn't overload them. */
119
+ /** An array of class instances that all share the same class. Created by
120
+ * default horzcat/vertcat when the class doesn't overload them. `elements`
121
+ * are stored in column-major order; `shape` is the 2-D `[rows, cols]` size
122
+ * (defaults to a `1×N` row vector when omitted). */
121
123
  export declare class RuntimeClassInstanceArray extends Refcounted {
122
124
  readonly kind: "class_instance_array";
123
125
  className: string;
124
126
  elements: RuntimeClassInstance[];
125
- constructor(className: string, elements: RuntimeClassInstance[]);
127
+ shape: [number, number];
128
+ constructor(className: string, elements: RuntimeClassInstance[], shape?: [number, number]);
126
129
  protected _destroy(rt: RefcountRuntime): void;
127
130
  }
128
131
  export declare class RuntimeComplexNumber extends Refcounted {
@@ -1,2 +1,2 @@
1
1
  /** Numbl version, used for JIT disk cache invalidation. */
2
- export declare const NUMBL_VERSION = "0.4.0";
2
+ export declare const NUMBL_VERSION = "0.4.2";