numbl 0.1.6 → 0.2.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/binding.gyp +53 -2
- package/dist-cli/cli.js +38743 -24679
- package/dist-lib/lib.js +43424 -30466
- package/dist-lib/numbl-core/executeCode.d.ts +22 -0
- package/dist-lib/numbl-core/helpers/bessel.d.ts +9 -0
- package/dist-lib/numbl-core/helpers/reduction-helpers.d.ts +7 -2
- package/dist-lib/numbl-core/interpreter/builtins/datetime.d.ts +39 -0
- package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +1 -0
- package/dist-lib/numbl-core/interpreter/builtins/time-system.d.ts +1 -0
- package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +100 -5
- package/dist-lib/numbl-core/interpreter/interpreter.d.ts +41 -3
- package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +2 -0
- package/dist-lib/numbl-core/interpreter/types.d.ts +16 -7
- package/dist-lib/numbl-core/jit/c/abi.d.ts +90 -0
- package/dist-lib/numbl-core/jit/c/assemble.d.ts +56 -0
- package/dist-lib/numbl-core/jit/c/classify.d.ts +70 -0
- package/dist-lib/numbl-core/jit/c/compile.d.ts +37 -0
- package/dist-lib/numbl-core/jit/c/context.d.ts +152 -0
- package/dist-lib/numbl-core/jit/c/emit/assign.d.ts +20 -0
- package/dist-lib/numbl-core/jit/c/emit/complexScalar.d.ts +18 -0
- package/dist-lib/numbl-core/jit/c/emit/fused.d.ts +42 -0
- package/dist-lib/numbl-core/jit/c/emit/helpers.d.ts +40 -0
- package/dist-lib/numbl-core/jit/c/emit/index.d.ts +14 -0
- package/dist-lib/numbl-core/jit/c/emit/scalar.d.ts +23 -0
- package/dist-lib/numbl-core/jit/c/emit/stmt.d.ts +25 -0
- package/dist-lib/numbl-core/jit/c/emit/tensor.d.ts +127 -0
- package/dist-lib/numbl-core/jit/c/emit/userCall.d.ts +58 -0
- package/dist-lib/numbl-core/jit/c/epilogue.d.ts +26 -0
- package/dist-lib/numbl-core/jit/c/feasibility.d.ts +44 -0
- package/dist-lib/numbl-core/jit/c/hybrid.d.ts +42 -0
- package/dist-lib/numbl-core/jit/c/install.d.ts +15 -0
- package/dist-lib/numbl-core/jit/c/parityError.d.ts +26 -0
- package/dist-lib/numbl-core/jit/c/prelude.d.ts +37 -0
- package/dist-lib/numbl-core/jit/c/registry.d.ts +51 -0
- package/dist-lib/numbl-core/jit/c/visit.d.ts +63 -0
- package/dist-lib/numbl-core/jit/e1/install.d.ts +13 -0
- package/dist-lib/numbl-core/jit/e1/kernelEmit.d.ts +54 -0
- package/dist-lib/numbl-core/jit/e1/openmpFlag.d.ts +13 -0
- package/dist-lib/numbl-core/jit/e1/scalarFnKernel.d.ts +44 -0
- package/dist-lib/numbl-core/jit/fusedChainHelpers.d.ts +65 -0
- package/dist-lib/numbl-core/jit/fusedScalarEmit.d.ts +61 -0
- package/dist-lib/numbl-core/jit/fusion.d.ts +71 -0
- package/dist-lib/numbl-core/jit/fusionOps.d.ts +25 -0
- package/dist-lib/numbl-core/{interpreter/jit → jit}/index.d.ts +2 -2
- package/dist-lib/numbl-core/jit/jitBailSafety.d.ts +41 -0
- package/dist-lib/numbl-core/{interpreter/jit → jit}/jitLoop.d.ts +2 -2
- package/dist-lib/numbl-core/{interpreter/jit → jit}/jitLoopAnalysis.d.ts +13 -1
- package/dist-lib/numbl-core/jit/jitLower.d.ts +122 -0
- package/dist-lib/numbl-core/jit/jitLowerExpr.d.ts +27 -0
- package/dist-lib/numbl-core/jit/jitLowerStmt.d.ts +9 -0
- package/dist-lib/numbl-core/jit/jitLowerTypes.d.ts +29 -0
- package/dist-lib/numbl-core/jit/jitTopLevel.d.ts +22 -0
- package/dist-lib/numbl-core/jit/jitTypes.d.ts +394 -0
- package/dist-lib/numbl-core/jit/js/jitCodegen.d.ts +7 -0
- package/dist-lib/numbl-core/jit/js/jitCodegenHoist.d.ts +70 -0
- package/dist-lib/numbl-core/jit/js/jitHelpers.d.ts +34 -0
- package/dist-lib/numbl-core/jit/js/jitHelpersComplex.d.ts +21 -0
- package/dist-lib/numbl-core/jit/js/jitHelpersIndex.d.ts +33 -0
- package/dist-lib/numbl-core/jit/js/jitHelpersTensor.d.ts +34 -0
- package/dist-lib/numbl-core/jit/js/jsFusedCodegen.d.ts +17 -0
- package/dist-lib/numbl-core/jit/scalarEmit.d.ts +58 -0
- package/dist-lib/numbl-core/lexer/types.d.ts +2 -1
- package/dist-lib/numbl-core/native/lapack-bridge.d.ts +46 -1
- package/dist-lib/numbl-core/ops/bessel.d.ts +18 -0
- package/dist-lib/numbl-core/ops/comparison.d.ts +11 -0
- package/dist-lib/numbl-core/ops/complexBinaryElemwise.d.ts +10 -0
- package/dist-lib/numbl-core/ops/complexUnaryElemwise.d.ts +8 -0
- package/dist-lib/numbl-core/ops/dispatch.d.ts +26 -0
- package/dist-lib/numbl-core/ops/index.d.ts +8 -0
- package/dist-lib/numbl-core/ops/opCodes.d.ts +70 -0
- package/dist-lib/numbl-core/ops/realBinaryElemwise.d.ts +8 -0
- package/dist-lib/numbl-core/ops/realUnaryElemwise.d.ts +5 -0
- package/dist-lib/numbl-core/ops/reduce.d.ts +6 -0
- package/dist-lib/numbl-core/parser/types.d.ts +6 -0
- package/dist-lib/numbl-core/runtime/alloc.d.ts +23 -0
- package/dist-lib/numbl-core/runtime/constructors.d.ts +2 -1
- package/dist-lib/numbl-core/runtime/error.d.ts +3 -0
- package/dist-lib/numbl-core/runtime/index.d.ts +1 -1
- package/dist-lib/numbl-core/runtime/runtime.d.ts +15 -2
- package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +11 -0
- package/dist-lib/numbl-core/runtime/types.d.ts +16 -1
- package/dist-lib/numbl-core/runtime/utils.d.ts +3 -1
- package/dist-lib/numbl-core/version.d.ts +1 -1
- package/dist-plot-viewer/assets/{index-vtrJ8bml.js → index-GiUNnMQg.js} +1 -1
- package/dist-plot-viewer/index.html +1 -1
- package/native/elemwise.cpp +134 -0
- package/native/jit_runtime/jit_runtime.c +261 -0
- package/native/jit_runtime/jit_runtime.h +204 -0
- package/native/numbl_addon.cpp +55 -1
- package/native/numbl_addon_common.h +1 -0
- package/native/ops/bessel.c +572 -0
- package/native/ops/comparison.c +150 -0
- package/native/ops/complex_binary_elemwise.c +192 -0
- package/native/ops/complex_unary_elemwise.c +152 -0
- package/native/ops/numbl_ops.c +66 -0
- package/native/ops/numbl_ops.h +262 -0
- package/native/ops/real_binary_elemwise.c +85 -0
- package/native/ops/real_unary_elemwise.c +104 -0
- package/native/ops/reduce.c +162 -0
- package/native/ops_napi.cpp +320 -0
- package/package.json +11 -10
- package/dist-lib/numbl-core/interpreter/jit/jitCodegen.d.ts +0 -5
- package/dist-lib/numbl-core/interpreter/jit/jitHelpers.d.ts +0 -14
- package/dist-lib/numbl-core/interpreter/jit/jitLower.d.ts +0 -20
- package/dist-lib/numbl-core/interpreter/jit/jitTypes.d.ts +0 -168
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JIT runtime helpers assembly point.
|
|
3
|
+
*
|
|
4
|
+
* This module assembles the $h helpers object from focused sub-modules:
|
|
5
|
+
* - jitHelpersComplex.ts — complex number arithmetic
|
|
6
|
+
* - jitHelpersIndex.ts — tensor indexing (generic, fast-path, hoisted)
|
|
7
|
+
* - jitHelpersTensor.ts — tensor binary/unary ops, concat, COW
|
|
8
|
+
*
|
|
9
|
+
* The $h object is passed to every JIT-compiled function. V8 inline
|
|
10
|
+
* caches require a stable hidden class, so buildPerRuntimeJitHelpers()
|
|
11
|
+
* creates a fresh snapshot via a single spread expression.
|
|
12
|
+
*/
|
|
13
|
+
export { re, im, mkc, cAdd, cSub, cMul, cDiv, cNeg, cConj, cAngle, cTruthy, } from "./jitHelpersComplex.js";
|
|
14
|
+
export { bce, idx1, idx2, idxN, idx1r, idx2r, idx3r, idx1r_h, idx2r_h, idx3r_h, set1r_h, set2r_h, set3r_h, setRange1r_h, setCol2r_h, subarrayCopy1r, subarrayCopy1rRow, } from "./jitHelpersIndex.js";
|
|
15
|
+
export { makeTensor, tensorBinaryOp, tensorCompareOp, tensorUnary, tensorNeg, vconcatGrow1r, unshare, shareTensor, asTensor, tDouble, tSum, tAdd, tSub, tMul, tDiv, tPow, tEq, tNeq, tLt, tLe, tGt, tGe, } from "./jitHelpersTensor.js";
|
|
16
|
+
export { JitBailToInterpreter } from "./jitHelpersIndex.js";
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when a function handle called from JIT code returns a type
|
|
19
|
+
* different from what the JIT expected (determined by probing at compile
|
|
20
|
+
* time). The loop runner catches this and falls back to interpretation.
|
|
21
|
+
*/
|
|
22
|
+
export declare class JitFuncHandleBailError extends Error {
|
|
23
|
+
readonly fnName: string;
|
|
24
|
+
readonly expectedType: string;
|
|
25
|
+
readonly actualType: string;
|
|
26
|
+
constructor(fnName: string, expectedType: string, actualType: string);
|
|
27
|
+
}
|
|
28
|
+
export declare const jitHelpers: Record<string, unknown>;
|
|
29
|
+
import type { IBuiltin } from "../../interpreter/builtins/index.js";
|
|
30
|
+
/**
|
|
31
|
+
* Build a per-runtime jitHelpers snapshot. Uses a single spread expression
|
|
32
|
+
* for a fresh V8 hidden class (critical for inline-cache performance).
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildPerRuntimeJitHelpers(jsUserFunctions: ReadonlyMap<string, IBuiltin>): Record<string, any>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Complex number arithmetic helpers for JIT-compiled code.
|
|
3
|
+
* These are pure functions used by the $h helpers object.
|
|
4
|
+
*/
|
|
5
|
+
import type { RuntimeComplexNumber } from "../../runtime/types.js";
|
|
6
|
+
export declare function re(v: unknown): number;
|
|
7
|
+
export declare function im(v: unknown): number;
|
|
8
|
+
export declare function mkc(r: number, i: number): number | RuntimeComplexNumber;
|
|
9
|
+
export declare function cAdd(a: unknown, b: unknown): number | RuntimeComplexNumber;
|
|
10
|
+
export declare function cSub(a: unknown, b: unknown): number | RuntimeComplexNumber;
|
|
11
|
+
export declare function cMul(a: unknown, b: unknown): number | RuntimeComplexNumber;
|
|
12
|
+
/**
|
|
13
|
+
* Complex division using Smith's method to avoid overflow/underflow.
|
|
14
|
+
* Handles division by zero consistently with MATLAB (produces Inf, not NaN).
|
|
15
|
+
*/
|
|
16
|
+
export declare function cDiv(a: unknown, b: unknown): number | RuntimeComplexNumber;
|
|
17
|
+
export declare function cNeg(a: unknown): number | RuntimeComplexNumber;
|
|
18
|
+
export declare function cConj(a: unknown): number | RuntimeComplexNumber;
|
|
19
|
+
export declare function cAngle(a: unknown): number;
|
|
20
|
+
/** Complex truthiness: nonzero if either real or imag part is nonzero. */
|
|
21
|
+
export declare function cTruthy(v: unknown): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tensor indexing helpers for JIT-compiled code.
|
|
3
|
+
*
|
|
4
|
+
* Three tiers of helpers, from most general to most specialized:
|
|
5
|
+
* 1. Generic (idx1, idx2, idxN) — handle any base type, real or complex
|
|
6
|
+
* 2. Real-tensor fast path (idx1r, idx2r, idx3r) — skip type/imag checks
|
|
7
|
+
* 3. Hoisted-base (idx*r_h, set*r_h) — take pre-extracted data/len/shape
|
|
8
|
+
*
|
|
9
|
+
* All helpers use 1-based MATLAB indexing and include per-dimension bounds
|
|
10
|
+
* checks to ensure consistency with the interpreter.
|
|
11
|
+
*/
|
|
12
|
+
import { type FloatXArrayType, type RuntimeTensor } from "../../runtime/types.js";
|
|
13
|
+
export declare class JitBailToInterpreter extends Error {
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
constructor(reason: string);
|
|
16
|
+
}
|
|
17
|
+
export declare function bce(): never;
|
|
18
|
+
export declare function idx1(base: unknown, i: number): unknown;
|
|
19
|
+
export declare function idx2(base: unknown, ri: number, ci: number): unknown;
|
|
20
|
+
export declare function idxN(base: unknown, indices: number[]): unknown;
|
|
21
|
+
export declare function idx1r(base: RuntimeTensor, i: number): number;
|
|
22
|
+
export declare function idx2r(base: RuntimeTensor, ri: number, ci: number): number;
|
|
23
|
+
export declare function idx3r(base: RuntimeTensor, i1: number, i2: number, i3: number): number;
|
|
24
|
+
export declare function idx1r_h(data: FloatXArrayType, len: number, i: number): number;
|
|
25
|
+
export declare function idx2r_h(data: FloatXArrayType, len: number, rows: number, ri: number, ci: number): number;
|
|
26
|
+
export declare function idx3r_h(data: FloatXArrayType, len: number, d0: number, d1: number, i1: number, i2: number, i3: number): number;
|
|
27
|
+
export declare function set1r_h(data: FloatXArrayType, len: number, i: number, v: number): void;
|
|
28
|
+
export declare function set2r_h(data: FloatXArrayType, len: number, rows: number, ri: number, ci: number, v: number): void;
|
|
29
|
+
export declare function set3r_h(data: FloatXArrayType, len: number, d0: number, d1: number, i1: number, i2: number, i3: number, v: number): void;
|
|
30
|
+
export declare function setRange1r_h(dstData: FloatXArrayType, dstLen: number, dstStart: number, dstEnd: number, srcData: FloatXArrayType, srcLen: number, srcStart: number, srcEnd: number): void;
|
|
31
|
+
export declare function subarrayCopy1r(srcData: FloatXArrayType, srcLen: number, start: number, end: number): RuntimeTensor;
|
|
32
|
+
export declare function subarrayCopy1rRow(srcData: FloatXArrayType, srcLen: number, start: number, end: number): RuntimeTensor;
|
|
33
|
+
export declare function setCol2r_h(dstData: FloatXArrayType, dstRows: number, dstLen: number, col: number, srcData: FloatXArrayType, srcLen: number): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tensor operation helpers for JIT-compiled code.
|
|
3
|
+
* Handles element-wise binary/unary ops, comparison ops, concat, and
|
|
4
|
+
* tensor coercion for struct-array field access.
|
|
5
|
+
*/
|
|
6
|
+
import { type FloatXArrayType, type RuntimeTensor } from "../../runtime/types.js";
|
|
7
|
+
import type { RuntimeComplexNumber } from "../../runtime/types.js";
|
|
8
|
+
export declare function makeTensor(data: FloatXArrayType, imag: FloatXArrayType | undefined, shape: number[]): RuntimeTensor;
|
|
9
|
+
/** Bump rc on a tensor (no-op for non-tensor values). Used for var-to-var
|
|
10
|
+
* JIT assignments so the aliased tensor is no longer eligible for
|
|
11
|
+
* in-place buffer reuse. */
|
|
12
|
+
export declare function shareTensor(v: unknown): unknown;
|
|
13
|
+
type ScalarVal = number | RuntimeComplexNumber;
|
|
14
|
+
export declare function tensorBinaryOp(a: unknown, b: unknown, realOp: (x: number, y: number) => number, complexOp: (a: ScalarVal, b: ScalarVal) => ScalarVal): RuntimeTensor | ScalarVal;
|
|
15
|
+
export declare function tensorCompareOp(a: unknown, b: unknown, cmp: (x: number, y: number) => boolean): RuntimeTensor;
|
|
16
|
+
export declare function tensorUnary(dest: unknown, a: RuntimeTensor, fn: (x: number) => number): RuntimeTensor;
|
|
17
|
+
export declare function tensorNeg(dest: unknown, a: RuntimeTensor): RuntimeTensor;
|
|
18
|
+
export declare function tDouble(v: unknown): unknown;
|
|
19
|
+
export declare function tSum(v: unknown): unknown;
|
|
20
|
+
export declare function vconcatGrow1r(base: unknown, v: number): RuntimeTensor;
|
|
21
|
+
export declare function unshare(t: unknown): RuntimeTensor;
|
|
22
|
+
export declare function asTensor(v: unknown): RuntimeTensor;
|
|
23
|
+
export declare const tAdd: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor | ScalarVal;
|
|
24
|
+
export declare const tSub: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor | ScalarVal;
|
|
25
|
+
export declare const tMul: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor | ScalarVal;
|
|
26
|
+
export declare const tDiv: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor | ScalarVal;
|
|
27
|
+
export declare const tPow: (_dest: unknown, a: unknown, b: unknown) => RuntimeTensor | ScalarVal;
|
|
28
|
+
export declare const tEq: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor;
|
|
29
|
+
export declare const tNeq: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor;
|
|
30
|
+
export declare const tLt: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor;
|
|
31
|
+
export declare const tLe: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor;
|
|
32
|
+
export declare const tGt: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor;
|
|
33
|
+
export declare const tGe: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fused per-element loop emission for the JS-JIT.
|
|
3
|
+
*
|
|
4
|
+
* Given a FusibleChain (from fusion.ts), emits a single block-scoped
|
|
5
|
+
* JavaScript `for` loop that evaluates all the chain's tensor assigns
|
|
6
|
+
* as inline scalar expressions per element — no $h.tAdd / $h.tMul
|
|
7
|
+
* helper calls, no intermediate tensor allocations.
|
|
8
|
+
*
|
|
9
|
+
* Tensor var references become either:
|
|
10
|
+
* - `__<name>_data[__i]` for input params / pre-existing tensors
|
|
11
|
+
* - `__f_<name>` for chain-produced intermediates (scalar local)
|
|
12
|
+
*
|
|
13
|
+
* The optional trailing reduction is absorbed as an inline accumulator
|
|
14
|
+
* inside the same loop.
|
|
15
|
+
*/
|
|
16
|
+
import type { FusibleChain } from "../fusion.js";
|
|
17
|
+
export declare function emitJsFusedChain(lines: string[], indent: string, chain: FusibleChain, allTensorVars: ReadonlySet<string>, paramTensors: ReadonlySet<string>, outputTensorNames: ReadonlySet<string>, _localTensorNames: ReadonlySet<string>, mangle: (n: string) => string, experimental?: string): void;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared scalar-expression emission used by both the JS-JIT and C-JIT
|
|
3
|
+
* backends.
|
|
4
|
+
*
|
|
5
|
+
* The value-form switches for scalar Binary/Unary and the truthiness
|
|
6
|
+
* walker have identical IR traversal between the two backends — only
|
|
7
|
+
* the leaf syntax (operator spelling, coercion rules) differs. A
|
|
8
|
+
* backend supplies a `ScalarOpTarget` describing how to spell each op,
|
|
9
|
+
* and the shared functions below handle the dispatch.
|
|
10
|
+
*
|
|
11
|
+
* Complex-scalar and tensor ops are *not* covered here — those remain
|
|
12
|
+
* backend-specific (JS uses `$h.cAdd` etc.; C-JIT bails on complex).
|
|
13
|
+
*/
|
|
14
|
+
import { BinaryOperation, UnaryOperation } from "../parser/types.js";
|
|
15
|
+
import type { JitExpr } from "./jitTypes.js";
|
|
16
|
+
export interface ScalarOpTarget {
|
|
17
|
+
binAdd(l: string, r: string): string;
|
|
18
|
+
binSub(l: string, r: string): string;
|
|
19
|
+
binMul(l: string, r: string): string;
|
|
20
|
+
binDiv(l: string, r: string): string;
|
|
21
|
+
binPow(l: string, r: string): string;
|
|
22
|
+
binEq(l: string, r: string): string;
|
|
23
|
+
binNe(l: string, r: string): string;
|
|
24
|
+
binLt(l: string, r: string): string;
|
|
25
|
+
binLe(l: string, r: string): string;
|
|
26
|
+
binGt(l: string, r: string): string;
|
|
27
|
+
binGe(l: string, r: string): string;
|
|
28
|
+
binAnd(l: string, r: string): string;
|
|
29
|
+
binOr(l: string, r: string): string;
|
|
30
|
+
unaryPlus(operand: string): string;
|
|
31
|
+
unaryMinus(operand: string): string;
|
|
32
|
+
unaryNot(operand: string): string;
|
|
33
|
+
toTruthy(valueExpr: string): string;
|
|
34
|
+
condEq(l: string, r: string): string;
|
|
35
|
+
condNe(l: string, r: string): string;
|
|
36
|
+
condLt(l: string, r: string): string;
|
|
37
|
+
condLe(l: string, r: string): string;
|
|
38
|
+
condGt(l: string, r: string): string;
|
|
39
|
+
condGe(l: string, r: string): string;
|
|
40
|
+
condNot(truthyExpr: string): string;
|
|
41
|
+
condAnd(l: string, r: string): string;
|
|
42
|
+
condOr(l: string, r: string): string;
|
|
43
|
+
}
|
|
44
|
+
/** Dispatch a scalar Binary op to the target. Throws on unsupported ops. */
|
|
45
|
+
export declare function emitScalarBinaryOp(op: BinaryOperation, left: string, right: string, target: ScalarOpTarget): string;
|
|
46
|
+
/** Dispatch a scalar Unary op to the target. Transpose is scalar-identity. */
|
|
47
|
+
export declare function emitScalarUnaryOp(op: UnaryOperation, operand: string, target: ScalarOpTarget): string;
|
|
48
|
+
/**
|
|
49
|
+
* Emit a condition expression for `if` / `while` / `&&` / `||` operands.
|
|
50
|
+
*
|
|
51
|
+
* Recurses through nested comparison / logical operators so that the
|
|
52
|
+
* whole condition emits as a native boolean/condition expression rather
|
|
53
|
+
* than being wrapped in a trailing `!= 0` on every nested result.
|
|
54
|
+
*
|
|
55
|
+
* `emitValue` is the backend's value-form expression emitter — it is
|
|
56
|
+
* called for the leaf operands of comparisons and for the fallback path.
|
|
57
|
+
*/
|
|
58
|
+
export declare function emitScalarTruthiness(expr: JitExpr, emitValue: (e: JitExpr) => string, target: ScalarOpTarget): string;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* Expected native addon version. Bump this whenever the C++ addon API changes
|
|
19
19
|
* (must match ADDON_VERSION in numbl_addon.cpp).
|
|
20
20
|
*/
|
|
21
|
-
export declare const NATIVE_ADDON_EXPECTED_VERSION =
|
|
21
|
+
export declare const NATIVE_ADDON_EXPECTED_VERSION = 8;
|
|
22
22
|
export interface LapackBridge {
|
|
23
23
|
/** Returns the native addon's version number. */
|
|
24
24
|
addonVersion?(): number;
|
|
@@ -432,6 +432,51 @@ export interface LapackBridge {
|
|
|
432
432
|
re: Float64Array;
|
|
433
433
|
im?: Float64Array;
|
|
434
434
|
};
|
|
435
|
+
/** Complex-scalar * (real or complex) tensor element-wise op.
|
|
436
|
+
* op: 0=add, 1=sub, 2=mul, 3=div.
|
|
437
|
+
* Pass null for arrIm to treat the tensor as purely real. */
|
|
438
|
+
elemwiseComplexScalar?(scalarRe: number, scalarIm: number, arrRe: Float64Array, arrIm: Float64Array | null, op: number, scalarOnLeft: boolean): {
|
|
439
|
+
re: Float64Array;
|
|
440
|
+
im?: Float64Array;
|
|
441
|
+
};
|
|
442
|
+
/** Real binary elemwise: out[i] = a[i] OP b[i]. op codes per OpRealBin. */
|
|
443
|
+
tensorOpRealBinary?(op: number, n: number, a: Float64Array, b: Float64Array, out: Float64Array): void;
|
|
444
|
+
/** Real scalar-tensor binary elemwise. */
|
|
445
|
+
tensorOpRealScalarBinary?(op: number, n: number, scalar: number, arr: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
|
|
446
|
+
/** Complex binary elemwise (split storage). aIm/bIm may be null. */
|
|
447
|
+
tensorOpComplexBinary?(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, bRe: Float64Array, bIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array): void;
|
|
448
|
+
/** Complex scalar-tensor binary elemwise. arrIm may be null. */
|
|
449
|
+
tensorOpComplexScalarBinary?(op: number, n: number, sRe: number, sIm: number, arrRe: Float64Array, arrIm: Float64Array | null, scalarOnLeft: boolean, outRe: Float64Array, outIm: Float64Array): void;
|
|
450
|
+
/** Real unary elemwise: out[i] = OP(a[i]). op codes per OpUnary. */
|
|
451
|
+
tensorOpRealUnary?(op: number, n: number, a: Float64Array, out: Float64Array): void;
|
|
452
|
+
/** Complex unary elemwise (split storage). aIm may be null. ABS unsupported. */
|
|
453
|
+
tensorOpComplexUnary?(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array): void;
|
|
454
|
+
/** Complex absolute value (real-valued output). aIm may be null. */
|
|
455
|
+
tensorOpComplexAbs?(n: number, aRe: Float64Array, aIm: Float64Array | null, out: Float64Array): void;
|
|
456
|
+
/** Real comparison: out[i] = (a[i] OP b[i]) ? 1 : 0. */
|
|
457
|
+
tensorOpRealComparison?(op: number, n: number, a: Float64Array, b: Float64Array, out: Float64Array): void;
|
|
458
|
+
/** Real scalar-tensor comparison. */
|
|
459
|
+
tensorOpRealScalarComparison?(op: number, n: number, scalar: number, arr: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
|
|
460
|
+
/** Complex comparison. EQ/NE use both parts; LT/LE/GT/GE use real parts. */
|
|
461
|
+
tensorOpComplexComparison?(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, bRe: Float64Array, bIm: Float64Array | null, out: Float64Array): void;
|
|
462
|
+
/** Complex scalar-tensor comparison. */
|
|
463
|
+
tensorOpComplexScalarComparison?(op: number, n: number, sRe: number, sIm: number, arrRe: Float64Array, arrIm: Float64Array | null, scalarOnLeft: boolean, out: Float64Array): void;
|
|
464
|
+
/** Flat real reduction (output is a 1-element Float64Array). */
|
|
465
|
+
tensorOpRealFlatReduce?(op: number, n: number, a: Float64Array, out: Float64Array): void;
|
|
466
|
+
/** Flat complex reduction. outIm may be null for ANY/ALL. */
|
|
467
|
+
tensorOpComplexFlatReduce?(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array | null): void;
|
|
468
|
+
/**
|
|
469
|
+
* Real Bessel tensor op: out[i] = besselX(nu, z[i]).
|
|
470
|
+
* op codes per OpBessel. scale: 0 unscaled, 1 scaled.
|
|
471
|
+
*/
|
|
472
|
+
tensorOpBesselReal?(op: number, nu: number, n: number, z: Float64Array, scale: number, out: Float64Array): void;
|
|
473
|
+
/**
|
|
474
|
+
* Hankel function tensor op (complex output, real input).
|
|
475
|
+
* kKind: 1 → J + i*Y; 2 → J - i*Y.
|
|
476
|
+
*/
|
|
477
|
+
tensorOpBesselH?(kKind: number, nu: number, n: number, z: Float64Array, scale: number, outRe: Float64Array, outIm: Float64Array): void;
|
|
478
|
+
/** Dump op-code enum values as a stable string (drift detection). */
|
|
479
|
+
tensorOpDumpCodes?(): string;
|
|
435
480
|
}
|
|
436
481
|
export declare function setLapackBridge(bridge: LapackBridge): void;
|
|
437
482
|
export declare function getLapackBridge(): LapackBridge | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TS implementation of Bessel tensor ops.
|
|
3
|
+
* Mirrors native/ops/bessel.c — fallback when the native addon is unavailable.
|
|
4
|
+
*
|
|
5
|
+
* Delegates the per-element math to src/numbl-core/helpers/bessel.ts so both
|
|
6
|
+
* the scalar interpreter path and the tensor path share the same algorithm.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* out[i] = bessel<OP>(nu, z[i]). scale mirrors the behavior of numbl_bessel_real.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tsBesselReal(op: number, nu: number, n: number, z: Float64Array, scale: number, out: Float64Array): void;
|
|
12
|
+
/**
|
|
13
|
+
* Hankel function for real z:
|
|
14
|
+
* kKind=1 → out[i] = J_nu(z[i]) + i * Y_nu(z[i])
|
|
15
|
+
* kKind=2 → out[i] = J_nu(z[i]) - i * Y_nu(z[i])
|
|
16
|
+
* scaled=1 multiplies by exp(-i*z) (k=1) or exp(+i*z) (k=2).
|
|
17
|
+
*/
|
|
18
|
+
export declare function tsBesselH(kKind: number, nu: number, n: number, z: Float64Array, scale: number, outRe: Float64Array, outIm: Float64Array): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TS implementation of comparison ops.
|
|
3
|
+
* Mirrors native/ops/comparison.c.
|
|
4
|
+
*
|
|
5
|
+
* Output is 0.0 / 1.0 stored in a Float64Array (numbl's logical-tensor
|
|
6
|
+
* convention — caller wraps the result with _isLogical = true).
|
|
7
|
+
*/
|
|
8
|
+
export declare function tsRealComparison(op: number, n: number, a: Float64Array, b: Float64Array, out: Float64Array): void;
|
|
9
|
+
export declare function tsRealScalarComparison(op: number, n: number, scalar: number, arr: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
|
|
10
|
+
export declare function tsComplexComparison(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, bRe: Float64Array, bIm: Float64Array | null, out: Float64Array): void;
|
|
11
|
+
export declare function tsComplexScalarComparison(op: number, n: number, sRe: number, sIm: number, arrRe: Float64Array, arrIm: Float64Array | null, scalarOnLeft: boolean, out: Float64Array): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TS implementation of complex binary element-wise ops, split storage.
|
|
3
|
+
* Mirrors native/ops/complex_binary_elemwise.c.
|
|
4
|
+
*
|
|
5
|
+
* Caller-allocated input/output buffers; never copies.
|
|
6
|
+
* aIm/bIm/arrIm may be null → treat as zero.
|
|
7
|
+
* outIm is always required (caller allocates even if result might be real).
|
|
8
|
+
*/
|
|
9
|
+
export declare function tsComplexBinaryElemwise(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, bRe: Float64Array, bIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array): void;
|
|
10
|
+
export declare function tsComplexScalarBinaryElemwise(op: number, n: number, sRe: number, sIm: number, arrRe: Float64Array, arrIm: Float64Array | null, scalarOnLeft: boolean, outRe: Float64Array, outIm: Float64Array): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TS implementation of complex unary element-wise ops, split storage.
|
|
3
|
+
* Mirrors native/ops/complex_unary_elemwise.c.
|
|
4
|
+
*
|
|
5
|
+
* ABS is intentionally unsupported (use tsComplexAbs — real-valued output).
|
|
6
|
+
*/
|
|
7
|
+
export declare function tsComplexUnaryElemwise(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array): void;
|
|
8
|
+
export declare function tsComplexAbs(n: number, aRe: Float64Array, aIm: Float64Array | null, out: Float64Array): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tensor-ops dispatcher: chooses native bridge or pure-TS fallback.
|
|
3
|
+
*
|
|
4
|
+
* All entry points have identical signatures across native and TS impls.
|
|
5
|
+
* Caller owns input AND output memory; functions never allocate output.
|
|
6
|
+
*
|
|
7
|
+
* Selection happens once on first use per category and is cached
|
|
8
|
+
* (the bridge identity is captured at module load via getLapackBridge()).
|
|
9
|
+
*/
|
|
10
|
+
export declare const tensorOps: {
|
|
11
|
+
realBinaryElemwise(op: number, n: number, a: Float64Array, b: Float64Array, out: Float64Array): void;
|
|
12
|
+
realScalarBinaryElemwise(op: number, n: number, scalar: number, arr: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
|
|
13
|
+
complexBinaryElemwise(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, bRe: Float64Array, bIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array): void;
|
|
14
|
+
complexScalarBinaryElemwise(op: number, n: number, sRe: number, sIm: number, arrRe: Float64Array, arrIm: Float64Array | null, scalarOnLeft: boolean, outRe: Float64Array, outIm: Float64Array): void;
|
|
15
|
+
realUnaryElemwise(op: number, n: number, a: Float64Array, out: Float64Array): void;
|
|
16
|
+
complexUnaryElemwise(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array): void;
|
|
17
|
+
complexAbs(n: number, aRe: Float64Array, aIm: Float64Array | null, out: Float64Array): void;
|
|
18
|
+
realComparison(op: number, n: number, a: Float64Array, b: Float64Array, out: Float64Array): void;
|
|
19
|
+
realScalarComparison(op: number, n: number, scalar: number, arr: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
|
|
20
|
+
complexComparison(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, bRe: Float64Array, bIm: Float64Array | null, out: Float64Array): void;
|
|
21
|
+
complexScalarComparison(op: number, n: number, sRe: number, sIm: number, arrRe: Float64Array, arrIm: Float64Array | null, scalarOnLeft: boolean, out: Float64Array): void;
|
|
22
|
+
realFlatReduce(op: number, n: number, a: Float64Array, out: Float64Array): void;
|
|
23
|
+
complexFlatReduce(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array | null): void;
|
|
24
|
+
besselReal(op: number, nu: number, n: number, z: Float64Array, scale: number, out: Float64Array): void;
|
|
25
|
+
besselH(kKind: number, nu: number, n: number, z: Float64Array, scale: number, outRe: Float64Array, outIm: Float64Array): void;
|
|
26
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tensor-ops layer: pointer-based, op-code dispatched, native + TS parity.
|
|
3
|
+
*
|
|
4
|
+
* Every op has identical signatures across native (C) and TS implementations.
|
|
5
|
+
* Caller owns input AND output memory; ops never allocate output.
|
|
6
|
+
*/
|
|
7
|
+
export { tensorOps } from "./dispatch.js";
|
|
8
|
+
export { OpRealBin, OpComplexBin, OpUnary, OpCmp, OpReduce, OpBessel, } from "./opCodes.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Op-code enums for the tensor-ops layer.
|
|
3
|
+
*
|
|
4
|
+
* SINGLE SOURCE OF TRUTH on the TS side. Mirrors native/ops/numbl_ops.h.
|
|
5
|
+
* Drift detection: src/__tests__/op-codes-sync.test.ts compares this file's
|
|
6
|
+
* values against numbl_dump_op_codes() at CI time.
|
|
7
|
+
*/
|
|
8
|
+
/** Real binary element-wise ops. */
|
|
9
|
+
export declare const OpRealBin: {
|
|
10
|
+
readonly ADD: 0;
|
|
11
|
+
readonly SUB: 1;
|
|
12
|
+
readonly MUL: 2;
|
|
13
|
+
readonly DIV: 3;
|
|
14
|
+
};
|
|
15
|
+
/** Complex binary element-wise ops. */
|
|
16
|
+
export declare const OpComplexBin: {
|
|
17
|
+
readonly ADD: 0;
|
|
18
|
+
readonly SUB: 1;
|
|
19
|
+
readonly MUL: 2;
|
|
20
|
+
readonly DIV: 3;
|
|
21
|
+
};
|
|
22
|
+
/** Flat reduction ops. */
|
|
23
|
+
export declare const OpReduce: {
|
|
24
|
+
readonly SUM: 0;
|
|
25
|
+
readonly PROD: 1;
|
|
26
|
+
readonly MAX: 2;
|
|
27
|
+
readonly MIN: 3;
|
|
28
|
+
readonly ANY: 4;
|
|
29
|
+
readonly ALL: 5;
|
|
30
|
+
readonly MEAN: 6;
|
|
31
|
+
};
|
|
32
|
+
/** Comparison ops (logical output). */
|
|
33
|
+
export declare const OpCmp: {
|
|
34
|
+
readonly EQ: 0;
|
|
35
|
+
readonly NE: 1;
|
|
36
|
+
readonly LT: 2;
|
|
37
|
+
readonly LE: 3;
|
|
38
|
+
readonly GT: 4;
|
|
39
|
+
readonly GE: 5;
|
|
40
|
+
};
|
|
41
|
+
/** Bessel function ops (real input). H-variants are in numbl_bessel_h (complex output). */
|
|
42
|
+
export declare const OpBessel: {
|
|
43
|
+
readonly J: 0;
|
|
44
|
+
readonly Y: 1;
|
|
45
|
+
readonly I: 2;
|
|
46
|
+
readonly K: 3;
|
|
47
|
+
};
|
|
48
|
+
/** Unary element-wise ops (shared numbering for real + complex). */
|
|
49
|
+
export declare const OpUnary: {
|
|
50
|
+
readonly EXP: 0;
|
|
51
|
+
readonly LOG: 1;
|
|
52
|
+
readonly LOG2: 2;
|
|
53
|
+
readonly LOG10: 3;
|
|
54
|
+
readonly SQRT: 4;
|
|
55
|
+
readonly ABS: 5;
|
|
56
|
+
readonly FLOOR: 6;
|
|
57
|
+
readonly CEIL: 7;
|
|
58
|
+
readonly ROUND: 8;
|
|
59
|
+
readonly TRUNC: 9;
|
|
60
|
+
readonly SIN: 10;
|
|
61
|
+
readonly COS: 11;
|
|
62
|
+
readonly TAN: 12;
|
|
63
|
+
readonly ASIN: 13;
|
|
64
|
+
readonly ACOS: 14;
|
|
65
|
+
readonly ATAN: 15;
|
|
66
|
+
readonly SINH: 16;
|
|
67
|
+
readonly COSH: 17;
|
|
68
|
+
readonly TANH: 18;
|
|
69
|
+
readonly SIGN: 19;
|
|
70
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TS implementation of real binary element-wise ops.
|
|
3
|
+
* Mirrors native/ops/real_binary_elemwise.c.
|
|
4
|
+
*
|
|
5
|
+
* Caller-allocated input/output buffers; never copies.
|
|
6
|
+
*/
|
|
7
|
+
export declare function tsRealBinaryElemwise(op: number, n: number, a: Float64Array, b: Float64Array, out: Float64Array): void;
|
|
8
|
+
export declare function tsRealScalarBinaryElemwise(op: number, n: number, scalar: number, arr: Float64Array, scalarOnLeft: boolean, out: Float64Array): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TS flat reductions. Mirrors native/ops/reduce.c.
|
|
3
|
+
* Caller-allocated input and output (1-element).
|
|
4
|
+
*/
|
|
5
|
+
export declare function tsRealFlatReduce(op: number, n: number, a: Float64Array, out: Float64Array): void;
|
|
6
|
+
export declare function tsComplexFlatReduce(op: number, n: number, aRe: Float64Array, aIm: Float64Array | null, outRe: Float64Array, outIm: Float64Array | null): void;
|
|
@@ -310,6 +310,12 @@ export type Stmt = {
|
|
|
310
310
|
superClass: string | null;
|
|
311
311
|
members: ClassMember[];
|
|
312
312
|
span: Span;
|
|
313
|
+
} | {
|
|
314
|
+
/** Magic comment directive, e.g. `%!numbl:assert_jit` or `%!numbl:assert_jit c`. */
|
|
315
|
+
type: "Directive";
|
|
316
|
+
directive: string;
|
|
317
|
+
args: string[];
|
|
318
|
+
span: Span;
|
|
313
319
|
};
|
|
314
320
|
export interface AbstractSyntaxTree {
|
|
315
321
|
body: Stmt[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allocate an UNINITIALIZED typed array — skips the zero-fill that
|
|
3
|
+
* `new Float64Array(n)` / `new FloatXArray(n)` perform by default.
|
|
4
|
+
*
|
|
5
|
+
* On Node, `Buffer.allocUnsafe` returns un-zeroed memory; wrapping it
|
|
6
|
+
* in a TypedArray view costs ~10× less than the zero-fill for a 16 MB
|
|
7
|
+
* buffer (~45 µs vs ~470 µs at N=2M doubles).
|
|
8
|
+
*
|
|
9
|
+
* SAFETY CONTRACT (very important):
|
|
10
|
+
* The caller MUST write every element before reading it. Any element
|
|
11
|
+
* that is read before being written will contain arbitrary stale bytes
|
|
12
|
+
* from recently-freed memory. If you cannot guarantee full coverage,
|
|
13
|
+
* use `new Float64Array(n)` / `new FloatXArray(n)` instead.
|
|
14
|
+
*
|
|
15
|
+
* In non-Node environments (browser, Deno without node-compat, …) where
|
|
16
|
+
* `Buffer` is unavailable, we fall back to the zero-filling constructor
|
|
17
|
+
* — still correct, just slower.
|
|
18
|
+
*/
|
|
19
|
+
import { FloatXArray } from "./types.js";
|
|
20
|
+
type FloatXInstance = InstanceType<typeof FloatXArray>;
|
|
21
|
+
export declare function uninitFloat64(n: number): Float64Array<ArrayBuffer>;
|
|
22
|
+
export declare function uninitFloatX(n: number): FloatXInstance;
|
|
23
|
+
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* RuntimeValue constructor helpers (the MV namespace).
|
|
3
3
|
*/
|
|
4
4
|
import { ItemType } from "../lowering/itemTypes.js";
|
|
5
|
-
import { type RuntimeNumber, type RuntimeTensor, type RuntimeString, type RuntimeChar, type RuntimeLogical, type RuntimeCell, type RuntimeStruct, type RuntimeFunction, type RuntimeClassInstance, type RuntimeComplexNumber, type RuntimeDummyHandle, type RuntimeStructArray, type RuntimeSparseMatrix, type RuntimeDictionary, type RuntimeValue, type FloatXArrayType } from "./types.js";
|
|
5
|
+
import { type RuntimeNumber, type RuntimeTensor, type RuntimeString, type RuntimeChar, type RuntimeLogical, type RuntimeCell, type RuntimeStruct, type RuntimeFunction, type RuntimeClassInstance, type RuntimeComplexNumber, type RuntimeDummyHandle, type RuntimeGraphicsHandle, type RuntimeStructArray, type RuntimeSparseMatrix, type RuntimeDictionary, type RuntimeValue, type FloatXArrayType } from "./types.js";
|
|
6
6
|
export declare const RTV: {
|
|
7
7
|
num(value: number): RuntimeNumber;
|
|
8
8
|
tensor(data: FloatXArrayType | number[], shape: number[], imag?: FloatXArrayType | number[]): RuntimeTensor;
|
|
@@ -25,6 +25,7 @@ export declare const RTV: {
|
|
|
25
25
|
classInstance(className: string, propertyNames: string[], isHandleClass?: boolean, defaults?: Map<string, RuntimeValue>): RuntimeClassInstance;
|
|
26
26
|
complex(re: number, im: number): RuntimeComplexNumber;
|
|
27
27
|
dummyHandle(): RuntimeDummyHandle;
|
|
28
|
+
graphicsHandle(trace: Record<string, unknown>, traceType: string): RuntimeGraphicsHandle;
|
|
28
29
|
structArray(fieldNames: string[], elements: RuntimeStruct[]): RuntimeStructArray;
|
|
29
30
|
sparseMatrix(m: number, n: number, ir: Int32Array, jc: Int32Array, pr: Float64Array, pi?: Float64Array): RuntimeSparseMatrix;
|
|
30
31
|
dictionary(entries?: Map<string, {
|
|
@@ -13,6 +13,9 @@ export type CallFrame = {
|
|
|
13
13
|
/** Trimmed source text at callerLine (populated during error enrichment) */
|
|
14
14
|
callerSourceLine?: string;
|
|
15
15
|
};
|
|
16
|
+
export declare class CancellationError extends Error {
|
|
17
|
+
constructor();
|
|
18
|
+
}
|
|
16
19
|
export declare class RuntimeError extends Error {
|
|
17
20
|
/** Source span where the error occurred (carries file name + per-file offsets) */
|
|
18
21
|
span: Span | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { RuntimeValue, RuntimeTensor, RuntimeString, RuntimeLogical, RuntimeCell, RuntimeStruct, RuntimeFunction, RuntimeDictionary, } from "./types.js";
|
|
2
|
-
export { RuntimeError, offsetToLine, offsetToColumn } from "./error.js";
|
|
2
|
+
export { RuntimeError, CancellationError, offsetToLine, offsetToColumn, } from "./error.js";
|
|
3
3
|
export type { CallFrame } from "./error.js";
|
|
4
4
|
export { tensorSize2D, numel, colMajorIndex, shareRuntimeValue, } from "./utils.js";
|
|
5
5
|
export { toNumber, toBool, toString } from "./convert.js";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* runtimeDispatch.ts, and helper types/utilities in runtimeHelpers.ts.
|
|
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
|
-
import { RuntimeChar, RuntimeCell, type RuntimeComplexNumber } from "../runtime/types.js";
|
|
14
|
+
import { RuntimeChar, RuntimeCell, type RuntimeComplexNumber, type RuntimeClassInstance } from "../runtime/types.js";
|
|
15
15
|
import { type ItemType } from "../lowering/itemTypes.js";
|
|
16
16
|
import type { PlotInstruction } from "../../graphics/types.js";
|
|
17
17
|
import type { ExecOptions } from "../executeCode.js";
|
|
@@ -25,9 +25,14 @@ export declare class Runtime {
|
|
|
25
25
|
plotInstructions: PlotInstruction[];
|
|
26
26
|
variableValues: Record<string, RuntimeValue>;
|
|
27
27
|
holdState: boolean;
|
|
28
|
+
private cancelFlag;
|
|
28
29
|
$line: number;
|
|
29
30
|
$file: string | null;
|
|
30
31
|
$callStack: CallFrame[];
|
|
32
|
+
_cleanupScopes: RuntimeFunction[][];
|
|
33
|
+
pushCleanupScope(): void;
|
|
34
|
+
registerCleanup(fn: RuntimeFunction): void;
|
|
35
|
+
popAndRunCleanups(callFn: (fn: RuntimeFunction) => void): void;
|
|
31
36
|
COLON: symbol;
|
|
32
37
|
END: symbol;
|
|
33
38
|
RTV: {
|
|
@@ -44,9 +49,10 @@ export declare class Runtime {
|
|
|
44
49
|
cell(data: RuntimeValue[], shape: number[]): RuntimeCell;
|
|
45
50
|
struct(fields: Map<string, RuntimeValue> | Record<string, RuntimeValue>): RuntimeStruct;
|
|
46
51
|
func(name: string, impl: "builtin" | "user", captures?: RuntimeValue[]): RuntimeFunction;
|
|
47
|
-
classInstance(className: string, propertyNames: string[], isHandleClass?: boolean, defaults?: Map<string, RuntimeValue>):
|
|
52
|
+
classInstance(className: string, propertyNames: string[], isHandleClass?: boolean, defaults?: Map<string, RuntimeValue>): RuntimeClassInstance;
|
|
48
53
|
complex(re: number, im: number): RuntimeComplexNumber;
|
|
49
54
|
dummyHandle(): import("../runtime/types.js").RuntimeDummyHandle;
|
|
55
|
+
graphicsHandle(trace: Record<string, unknown>, traceType: string): import("../runtime/types.js").RuntimeGraphicsHandle;
|
|
50
56
|
structArray(fieldNames: string[], elements: RuntimeStruct[]): import("../runtime/types.js").RuntimeStructArray;
|
|
51
57
|
sparseMatrix(m: number, n: number, ir: Int32Array, jc: Int32Array, pr: Float64Array, pi?: Float64Array): import("../runtime/types.js").RuntimeSparseMatrix;
|
|
52
58
|
dictionary(entries?: Map<string, {
|
|
@@ -104,6 +110,8 @@ export declare class Runtime {
|
|
|
104
110
|
totalTimeMs: number;
|
|
105
111
|
}>;
|
|
106
112
|
constructor(options: ExecOptions, initialVariableValues?: Record<string, RuntimeValue> | undefined);
|
|
113
|
+
/** Throw CancellationError if the cancel flag has been set. */
|
|
114
|
+
checkCancel(): void;
|
|
107
115
|
private initBuiltins;
|
|
108
116
|
profileEnter(key: string): void;
|
|
109
117
|
profileLeave(): void;
|
|
@@ -139,6 +147,7 @@ export declare class Runtime {
|
|
|
139
147
|
/** Scalar power that returns complex for negative base with fractional exponent */
|
|
140
148
|
pow(a: number, b: number): number | RuntimeComplexNumber;
|
|
141
149
|
share(v: unknown): RuntimeValue;
|
|
150
|
+
get displayResults(): boolean;
|
|
142
151
|
displayResult(v: unknown): void;
|
|
143
152
|
displayAssign(name: string, v: unknown): void;
|
|
144
153
|
getConstant(name: string): RuntimeValue;
|
|
@@ -191,6 +200,8 @@ export declare class Runtime {
|
|
|
191
200
|
buildNameValueStruct(nvArgs: unknown[], defaults: Record<string, unknown>): RuntimeStruct;
|
|
192
201
|
horzcat(elems: unknown[]): unknown;
|
|
193
202
|
vertcat(rows: unknown[]): unknown;
|
|
203
|
+
/** Check if any class instance in the values has a given method. */
|
|
204
|
+
private _classHasMethod;
|
|
194
205
|
switchMatch(control: unknown, caseVal: unknown): boolean;
|
|
195
206
|
getFuncHandle(name: string): RuntimeFunction;
|
|
196
207
|
makeUserFuncHandle(jsFn: (...args: unknown[]) => unknown, nargin?: number): RuntimeFunction;
|
|
@@ -317,6 +328,8 @@ export declare class Runtime {
|
|
|
317
328
|
piechart_call(args: RuntimeValue[]): void;
|
|
318
329
|
donutchart_call(args: RuntimeValue[]): void;
|
|
319
330
|
heatmap_call(args: RuntimeValue[]): void;
|
|
331
|
+
streamline_call(args: RuntimeValue[]): RuntimeValue;
|
|
332
|
+
stream2_call(args: RuntimeValue[]): RuntimeValue;
|
|
320
333
|
view_call(args: RuntimeValue[]): void;
|
|
321
334
|
legend_call(args: RuntimeValue[]): void;
|
|
322
335
|
drawnow(): void;
|
|
@@ -103,3 +103,14 @@ export declare function heatmapCall(plotInstructions: PlotInstruction[], args: R
|
|
|
103
103
|
export declare function legendCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): void;
|
|
104
104
|
export declare function drawnow(plotInstructions: PlotInstruction[], options: ExecOptions): void;
|
|
105
105
|
export declare function pause(seconds: unknown): void;
|
|
106
|
+
/**
|
|
107
|
+
* streamline(X,Y,U,V,startX,startY) — compute and plot 2D streamlines.
|
|
108
|
+
* streamline(verts) — plot from pre-computed cell array of vertex matrices.
|
|
109
|
+
* Returns a dummy graphics handle.
|
|
110
|
+
*/
|
|
111
|
+
export declare function streamlineCall(plotInstructions: PlotInstruction[], args: RuntimeValue[]): RuntimeValue;
|
|
112
|
+
/**
|
|
113
|
+
* stream2(X,Y,U,V,startX,startY) — compute 2D streamline vertices.
|
|
114
|
+
* Returns a cell array of Nx2 vertex matrices.
|
|
115
|
+
*/
|
|
116
|
+
export declare function stream2Call(args: RuntimeValue[]): RuntimeValue;
|