numbl 0.1.1 → 0.1.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.
- package/README.md +1 -1
- package/dist-cli/cli.js +6063 -2321
- package/dist-lib/graphics/types.d.ts +262 -0
- package/dist-lib/lib.d.ts +19 -0
- package/dist-lib/lib.js +53709 -0
- package/dist-lib/numbl-core/diagnostics/errors.d.ts +8 -0
- package/dist-lib/numbl-core/diagnostics/index.d.ts +27 -0
- package/dist-lib/numbl-core/executeCode.d.ts +70 -0
- package/dist-lib/numbl-core/externalAccessDirective.d.ts +6 -0
- package/dist-lib/numbl-core/fileIOAdapter.d.ts +61 -0
- package/dist-lib/numbl-core/functionResolve.d.ts +59 -0
- package/dist-lib/numbl-core/helpers/arithmetic.d.ts +47 -0
- package/dist-lib/numbl-core/helpers/bessel.d.ts +40 -0
- package/dist-lib/numbl-core/helpers/check-helpers.d.ts +50 -0
- package/dist-lib/numbl-core/helpers/constants.d.ts +6 -0
- package/dist-lib/numbl-core/helpers/dummy.d.ts +5 -0
- package/dist-lib/numbl-core/helpers/erf.d.ts +5 -0
- package/dist-lib/numbl-core/helpers/linsolve.d.ts +26 -0
- package/dist-lib/numbl-core/helpers/ode-rk.d.ts +83 -0
- package/dist-lib/numbl-core/helpers/prng.d.ts +17 -0
- package/dist-lib/numbl-core/helpers/reduction/cumulative.d.ts +8 -0
- package/dist-lib/numbl-core/helpers/reduction/min-max.d.ts +5 -0
- package/dist-lib/numbl-core/helpers/reduction-helpers.d.ts +58 -0
- package/dist-lib/numbl-core/helpers/registry.d.ts +7 -0
- package/dist-lib/numbl-core/helpers/shape-utils.d.ts +7 -0
- package/dist-lib/numbl-core/helpers/sparse-arithmetic.d.ts +16 -0
- package/dist-lib/numbl-core/helpers/string.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/arithmetic.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/array-construction.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/array-extras.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/array-manipulation.d.ts +7 -0
- package/dist-lib/numbl-core/interpreter/builtins/cell-struct.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/complex.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/dictionary.d.ts +15 -0
- package/dist-lib/numbl-core/interpreter/builtins/fft.d.ts +7 -0
- package/dist-lib/numbl-core/interpreter/builtins/help-text.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +34 -0
- package/dist-lib/numbl-core/interpreter/builtins/introspection.d.ts +6 -0
- package/dist-lib/numbl-core/interpreter/builtins/linear-algebra.d.ts +9 -0
- package/dist-lib/numbl-core/interpreter/builtins/math.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/misc.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/numerical.d.ts +10 -0
- package/dist-lib/numbl-core/interpreter/builtins/predicates.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/prng.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/reductions.d.ts +6 -0
- package/dist-lib/numbl-core/interpreter/builtins/set-operations.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/sparse.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/special-math.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/string-extras.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/strings.d.ts +7 -0
- package/dist-lib/numbl-core/interpreter/builtins/time-system.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/type-constructors.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +109 -0
- package/dist-lib/numbl-core/interpreter/builtins/utility.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/builtins/validation.d.ts +4 -0
- package/dist-lib/numbl-core/interpreter/interpreter.d.ts +146 -0
- package/dist-lib/numbl-core/interpreter/interpreterExec.d.ts +51 -0
- package/dist-lib/numbl-core/interpreter/interpreterFunctions.d.ts +41 -0
- package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +18 -0
- package/dist-lib/numbl-core/interpreter/jit/index.d.ts +7 -0
- package/dist-lib/numbl-core/interpreter/jit/jitCodegen.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/jit/jitHelpers.d.ts +5 -0
- package/dist-lib/numbl-core/interpreter/jit/jitLoop.d.ts +25 -0
- package/dist-lib/numbl-core/interpreter/jit/jitLoopAnalysis.d.ts +25 -0
- package/dist-lib/numbl-core/interpreter/jit/jitLower.d.ts +20 -0
- package/dist-lib/numbl-core/interpreter/jit/jitTypes.d.ts +168 -0
- package/dist-lib/numbl-core/interpreter/types.d.ts +77 -0
- package/dist-lib/numbl-core/jsUserFunctions.d.ts +25 -0
- package/dist-lib/numbl-core/lexer/helpers.d.ts +15 -0
- package/dist-lib/numbl-core/lexer/index.d.ts +4 -0
- package/dist-lib/numbl-core/lexer/keywords.d.ts +3 -0
- package/dist-lib/numbl-core/lexer/token-config.d.ts +94 -0
- package/dist-lib/numbl-core/lexer/tokenizer.d.ts +9 -0
- package/dist-lib/numbl-core/lexer/types.d.ts +78 -0
- package/dist-lib/numbl-core/lowering/classInfo.d.ts +36 -0
- package/dist-lib/numbl-core/lowering/constants.d.ts +4 -0
- package/dist-lib/numbl-core/lowering/errors.d.ts +17 -0
- package/dist-lib/numbl-core/lowering/index.d.ts +3 -0
- package/dist-lib/numbl-core/lowering/itemTypes.d.ts +87 -0
- package/dist-lib/numbl-core/lowering/loweringContext.d.ts +206 -0
- package/dist-lib/numbl-core/native/bridge-resolve.d.ts +14 -0
- package/dist-lib/numbl-core/native/lapack-bridge.d.ts +387 -0
- package/dist-lib/numbl-core/native/ts-lapack-bridge.d.ts +9 -0
- package/dist-lib/numbl-core/parser/ArgumentsParser.d.ts +28 -0
- package/dist-lib/numbl-core/parser/ClassParser.d.ts +18 -0
- package/dist-lib/numbl-core/parser/CommandParser.d.ts +31 -0
- package/dist-lib/numbl-core/parser/ControlFlowParser.d.ts +16 -0
- package/dist-lib/numbl-core/parser/ExpressionParser.d.ts +32 -0
- package/dist-lib/numbl-core/parser/FunctionParser.d.ts +10 -0
- package/dist-lib/numbl-core/parser/Parser.d.ts +17 -0
- package/dist-lib/numbl-core/parser/ParserBase.d.ts +35 -0
- package/dist-lib/numbl-core/parser/StatementParser.d.ts +13 -0
- package/dist-lib/numbl-core/parser/errors.d.ts +15 -0
- package/dist-lib/numbl-core/parser/index.d.ts +7 -0
- package/dist-lib/numbl-core/parser/types.d.ts +316 -0
- package/dist-lib/numbl-core/runtime/compare.d.ts +5 -0
- package/dist-lib/numbl-core/runtime/constructors.d.ts +35 -0
- package/dist-lib/numbl-core/runtime/convert.d.ts +10 -0
- package/dist-lib/numbl-core/runtime/display.d.ts +6 -0
- package/dist-lib/numbl-core/runtime/error.d.ts +73 -0
- package/dist-lib/numbl-core/runtime/index.d.ts +12 -0
- package/dist-lib/numbl-core/runtime/indexing.d.ts +10 -0
- package/dist-lib/numbl-core/runtime/plotUtils.d.ts +215 -0
- package/dist-lib/numbl-core/runtime/runtime.d.ts +314 -0
- package/dist-lib/numbl-core/runtime/runtimeDispatch.d.ts +27 -0
- package/dist-lib/numbl-core/runtime/runtimeHelpers.d.ts +31 -0
- package/dist-lib/numbl-core/runtime/runtimeIndexing.d.ts +28 -0
- package/dist-lib/numbl-core/runtime/runtimeMemberAccess.d.ts +26 -0
- package/dist-lib/numbl-core/runtime/runtimeOperators.d.ts +24 -0
- package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +99 -0
- package/dist-lib/numbl-core/runtime/sentinels.d.ts +4 -0
- package/dist-lib/numbl-core/runtime/specialBuiltinNames.d.ts +2 -0
- package/dist-lib/numbl-core/runtime/specialBuiltins.d.ts +13 -0
- package/dist-lib/numbl-core/runtime/struct-access.d.ts +6 -0
- package/dist-lib/numbl-core/runtime/syncChannel.d.ts +1 -0
- package/dist-lib/numbl-core/runtime/tensor-construction.d.ts +10 -0
- package/dist-lib/numbl-core/runtime/types.d.ts +110 -0
- package/dist-lib/numbl-core/runtime/utils.d.ts +20 -0
- package/dist-lib/numbl-core/stdlib-bundle.d.ts +3 -0
- package/dist-lib/numbl-core/systemAdapter.d.ts +23 -0
- package/dist-lib/numbl-core/version.d.ts +2 -0
- package/dist-lib/numbl-core/workspace/index.d.ts +4 -0
- package/dist-lib/numbl-core/workspace/types.d.ts +16 -0
- package/dist-lib/ts-lapack/src/BLAS/daxpy.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dcopy.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/ddot.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dgemm.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dgemm_optimized.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dgemv.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dger.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dnrm2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/drot.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dscal.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dswap.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dtrmm.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dtrmv.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/dtrsm.d.ts +1 -0
- package/dist-lib/ts-lapack/src/BLAS/idamax.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dbdsqr.d.ts +10 -0
- package/dist-lib/ts-lapack/src/SRC/dgebak.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgebal.d.ts +5 -0
- package/dist-lib/ts-lapack/src/SRC/dgebd2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgebrd.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgeev.d.ts +3 -0
- package/dist-lib/ts-lapack/src/SRC/dgehd2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgehrd.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgelq2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgelqf.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgeqr2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgeqrf.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgeqrf_optimized.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgesvd.d.ts +28 -0
- package/dist-lib/ts-lapack/src/SRC/dgetrf.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgetrf2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dgetri.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dhseqr.d.ts +32 -0
- package/dist-lib/ts-lapack/src/SRC/dlabrd.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlacpy.d.ts +18 -0
- package/dist-lib/ts-lapack/src/SRC/dladiv.d.ts +9 -0
- package/dist-lib/ts-lapack/src/SRC/dlaexc.d.ts +21 -0
- package/dist-lib/ts-lapack/src/SRC/dlahqr.d.ts +24 -0
- package/dist-lib/ts-lapack/src/SRC/dlahr2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlaln2.d.ts +5 -0
- package/dist-lib/ts-lapack/src/SRC/dlamch.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlange.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlanv2.d.ts +12 -0
- package/dist-lib/ts-lapack/src/SRC/dlapy2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlaqr1.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlaqr30.d.ts +81 -0
- package/dist-lib/ts-lapack/src/SRC/dlaqr5.d.ts +38 -0
- package/dist-lib/ts-lapack/src/SRC/dlarf.d.ts +18 -0
- package/dist-lib/ts-lapack/src/SRC/dlarf1f.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlarfb.d.ts +25 -0
- package/dist-lib/ts-lapack/src/SRC/dlarfg.d.ts +4 -0
- package/dist-lib/ts-lapack/src/SRC/dlarft.d.ts +20 -0
- package/dist-lib/ts-lapack/src/SRC/dlarfx.d.ts +17 -0
- package/dist-lib/ts-lapack/src/SRC/dlartg.d.ts +5 -0
- package/dist-lib/ts-lapack/src/SRC/dlas2.d.ts +4 -0
- package/dist-lib/ts-lapack/src/SRC/dlascl.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlaset.d.ts +19 -0
- package/dist-lib/ts-lapack/src/SRC/dlasr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlassq.d.ts +18 -0
- package/dist-lib/ts-lapack/src/SRC/dlasv2.d.ts +8 -0
- package/dist-lib/ts-lapack/src/SRC/dlaswp.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dlasy2.d.ts +5 -0
- package/dist-lib/ts-lapack/src/SRC/dorg2r.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorgbr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorghr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorgl2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorglq.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorgqr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorgqr_optimized.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dorm2r.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dormhr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dormqr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dpotf2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dtrevc3.d.ts +27 -0
- package/dist-lib/ts-lapack/src/SRC/dtrexc.d.ts +24 -0
- package/dist-lib/ts-lapack/src/SRC/dtrti2.d.ts +1 -0
- package/dist-lib/ts-lapack/src/SRC/dtrtri.d.ts +1 -0
- package/dist-lib/ts-lapack/src/utils/constants.d.ts +28 -0
- package/dist-lib/ts-lapack/src/utils/iladlc.d.ts +1 -0
- package/dist-lib/ts-lapack/src/utils/iladlr.d.ts +1 -0
- package/dist-lib/ts-lapack/src/utils/ilaenv.d.ts +1 -0
- package/dist-lib/ts-lapack/src/utils/xerbla.d.ts +1 -0
- package/dist-plot-viewer/assets/index-BjKyNJgj.js +4426 -0
- package/dist-plot-viewer/index.html +1 -1
- package/package.json +12 -2
- package/dist-plot-viewer/assets/index-BMYdzDaW.js +0 -4426
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aggregate compilation error — collects multiple errors from parsing/lowering
|
|
3
|
+
* across workspace files so that all errors can be reported at once.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CompilationErrors extends Error {
|
|
6
|
+
errors: Error[];
|
|
7
|
+
constructor(errors: Error[]);
|
|
8
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error diagnostic utilities for extracting structured error info
|
|
3
|
+
* with source context (snippets). Used by both the CLI and the web worker.
|
|
4
|
+
*/
|
|
5
|
+
import { type CallFrame } from "../runtime/error.js";
|
|
6
|
+
import type { WorkspaceFile } from "../workspace/index.js";
|
|
7
|
+
interface DiagnosticInfo {
|
|
8
|
+
message: string;
|
|
9
|
+
errorType: "syntax" | "semantic" | "runtime" | "unknown";
|
|
10
|
+
file: string | null;
|
|
11
|
+
line: number | null;
|
|
12
|
+
snippet: string | null;
|
|
13
|
+
callStack?: CallFrame[] | null;
|
|
14
|
+
}
|
|
15
|
+
/** Look up source text for a given filename. */
|
|
16
|
+
export declare function getSourceForFile(file: string, mainFileName: string, mainSource: string, wsFiles: WorkspaceFile[] | undefined): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Extract structured diagnostic info from any error, returning an array.
|
|
19
|
+
* For CompilationErrors, returns one DiagnosticInfo per inner error.
|
|
20
|
+
* For all other errors, returns a single-element array.
|
|
21
|
+
*/
|
|
22
|
+
export declare function diagnoseErrors(error: unknown, mainSource: string, mainFileName: string, wsFiles?: WorkspaceFile[]): DiagnosticInfo[];
|
|
23
|
+
/** Format multiple DiagnosticInfo as a human-readable string for console output. */
|
|
24
|
+
export declare function formatDiagnostics(infos: DiagnosticInfo[], getSource?: (file: string) => string | null): string;
|
|
25
|
+
/** Format a DiagnosticInfo as a human-readable string for console output. */
|
|
26
|
+
export declare function formatDiagnostic(info: DiagnosticInfo, getSource?: (file: string) => string | null): string;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point for code execution.
|
|
3
|
+
*
|
|
4
|
+
* Parses source, sets up the LoweringContext and Runtime,
|
|
5
|
+
* creates an Interpreter, and runs the AST.
|
|
6
|
+
*/
|
|
7
|
+
import type { RuntimeValue } from "./runtime/index.js";
|
|
8
|
+
import type { PlotInstruction } from "../graphics/types.js";
|
|
9
|
+
import type { FileIOAdapter } from "./fileIOAdapter.js";
|
|
10
|
+
import type { SystemAdapter } from "./systemAdapter.js";
|
|
11
|
+
import type { WorkspaceFile } from "../numbl-core/workspace/index.js";
|
|
12
|
+
import type { NativeBridge } from "./workspace/index.js";
|
|
13
|
+
export interface ExecOptions {
|
|
14
|
+
onOutput?: (text: string) => void;
|
|
15
|
+
onDrawnow?: (plotInstructions: PlotInstruction[]) => void;
|
|
16
|
+
displayResults?: boolean;
|
|
17
|
+
maxIterations?: number;
|
|
18
|
+
initialVariableValues?: Record<string, RuntimeValue>;
|
|
19
|
+
/** Optional callback for verbose compilation logging. */
|
|
20
|
+
log?: (message: string) => void;
|
|
21
|
+
/** Enable profiling of builtin function calls. */
|
|
22
|
+
profile?: boolean;
|
|
23
|
+
/** Called each time a JIT function is compiled, with a description and the generated JS. */
|
|
24
|
+
onJitCompile?: (description: string, jsCode: string) => void;
|
|
25
|
+
/** Initial hold state for plotting (persisted across REPL executions). */
|
|
26
|
+
initialHoldState?: boolean;
|
|
27
|
+
/** Override or add builtins for this execution only. */
|
|
28
|
+
customBuiltins?: Record<string, (nargout: number, args: any[]) => any>;
|
|
29
|
+
/** Platform-specific file I/O adapter (e.g. Node.js fs). */
|
|
30
|
+
fileIO?: FileIOAdapter;
|
|
31
|
+
/** Platform-specific system adapter (env vars, cwd, platform info). */
|
|
32
|
+
system?: SystemAdapter;
|
|
33
|
+
/** Synchronous callback for the `input()` builtin. Displays prompt, returns user's line. */
|
|
34
|
+
onInput?: (prompt: string) => string;
|
|
35
|
+
/** Optimization level for interpreter (0 = none, >=1 = JIT scalar functions). */
|
|
36
|
+
optimization?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface BuiltinProfileEntry {
|
|
39
|
+
totalTimeMs: number;
|
|
40
|
+
callCount: number;
|
|
41
|
+
}
|
|
42
|
+
export interface BuiltinProfileBreakdown {
|
|
43
|
+
/** Calls from the registry fallback (rt.builtins). */
|
|
44
|
+
fallback: BuiltinProfileEntry;
|
|
45
|
+
/** Calls from the interpreter (IBuiltin.resolve → apply). */
|
|
46
|
+
interp: BuiltinProfileEntry;
|
|
47
|
+
/** Calls from JIT-compiled code (ib_* helpers). */
|
|
48
|
+
jit: BuiltinProfileEntry;
|
|
49
|
+
}
|
|
50
|
+
export interface ProfileData {
|
|
51
|
+
executionTimeMs: number;
|
|
52
|
+
jitCompileTimeMs: number;
|
|
53
|
+
builtins: Record<string, BuiltinProfileBreakdown>;
|
|
54
|
+
dispatches: Record<string, BuiltinProfileEntry>;
|
|
55
|
+
}
|
|
56
|
+
export interface ExecResult {
|
|
57
|
+
output: string[];
|
|
58
|
+
generatedJS: string;
|
|
59
|
+
plotInstructions: PlotInstruction[];
|
|
60
|
+
returnValue: RuntimeValue;
|
|
61
|
+
variableValues: Record<string, RuntimeValue>;
|
|
62
|
+
holdState: boolean;
|
|
63
|
+
profileData?: ProfileData;
|
|
64
|
+
dispatchUnknownCounts?: Record<string, number>;
|
|
65
|
+
/** Updated search paths (set when addpath/rmpath was called). */
|
|
66
|
+
searchPaths?: string[];
|
|
67
|
+
/** Updated workspace files (set when addpath/rmpath was called). */
|
|
68
|
+
workspaceFiles?: WorkspaceFile[];
|
|
69
|
+
}
|
|
70
|
+
export declare function executeCode(source: string, options?: ExecOptions, workspaceFiles?: WorkspaceFile[], mainFileName?: string, searchPaths?: string[], nativeBridge?: NativeBridge): ExecResult;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-agnostic file I/O adapter interface.
|
|
3
|
+
*
|
|
4
|
+
* numbl-core defines this interface but never imports Node.js fs.
|
|
5
|
+
* Concrete implementations (e.g. NodeFileIOAdapter) are injected
|
|
6
|
+
* from the CLI or other host environments via ExecOptions.fileIO.
|
|
7
|
+
*/
|
|
8
|
+
export interface FileIOAdapter {
|
|
9
|
+
/** Open a file, returns an integer file identifier (fid). */
|
|
10
|
+
fopen(filename: string, permission: string): number;
|
|
11
|
+
/** Close a file (or 'all'). Returns 0 on success, -1 on error. */
|
|
12
|
+
fclose(fid: number | "all"): number;
|
|
13
|
+
/** Read one line, stripping the newline. Returns -1 at EOF. */
|
|
14
|
+
fgetl(fid: number): string | number;
|
|
15
|
+
/** Read one line, keeping the newline. Returns -1 at EOF. */
|
|
16
|
+
fgets(fid: number): string | number;
|
|
17
|
+
/** Read an entire file as a string. */
|
|
18
|
+
fileread(filename: string): string;
|
|
19
|
+
/** Returns 1 if at EOF, 0 otherwise. */
|
|
20
|
+
feof(fid: number): number;
|
|
21
|
+
/** Returns the error message string for the last operation on fid. */
|
|
22
|
+
ferror(fid: number): string;
|
|
23
|
+
/** Write a string to a file descriptor (used by fprintf). */
|
|
24
|
+
fwrite(fid: number, text: string): void;
|
|
25
|
+
/** Read raw bytes from a file. Returns the bytes actually read (may be fewer than count at EOF). Optional. */
|
|
26
|
+
freadBytes?(fid: number, count: number): Uint8Array;
|
|
27
|
+
/** Write raw bytes to a file. Returns number of bytes written. Optional. */
|
|
28
|
+
fwriteBytes?(fid: number, data: Uint8Array): number;
|
|
29
|
+
/** Seek to a position in a file. origin: -1=bof, 0=cof, 1=eof. Returns 0 on success, -1 on error. Optional. */
|
|
30
|
+
fseek?(fid: number, offset: number, origin: number): number;
|
|
31
|
+
/** Return current file position. Optional. */
|
|
32
|
+
ftell?(fid: number): number;
|
|
33
|
+
/** Scan a directory for workspace files (.m, .js, .wasm). Optional. */
|
|
34
|
+
scanDirectory?(dirPath: string): import("../numbl-core/workspace/index.js").WorkspaceFile[];
|
|
35
|
+
/** Resolve a path to absolute. Optional. */
|
|
36
|
+
resolvePath?(dirPath: string): string;
|
|
37
|
+
/** Check whether a path exists and whether it is a file or directory. Optional. */
|
|
38
|
+
existsPath?(path: string): "file" | "dir" | null;
|
|
39
|
+
/** Create a directory (and parents). Returns true on success. Optional. */
|
|
40
|
+
mkdir?(dirPath: string): boolean;
|
|
41
|
+
/** Download a URL to a file. Optional. */
|
|
42
|
+
websave?(url: string, filename: string): void;
|
|
43
|
+
/** Fetch content from a URL and return as a string. Optional. */
|
|
44
|
+
webread?(url: string): string;
|
|
45
|
+
/** Delete files matching a pattern (supports globs). Optional. */
|
|
46
|
+
deleteFile?(pattern: string): void;
|
|
47
|
+
/** Remove a directory. If recursive is true, remove contents first. Returns true on success. Optional. */
|
|
48
|
+
rmdir?(dirPath: string, recursive: boolean): boolean;
|
|
49
|
+
/** Extract a ZIP file to an output folder. Returns list of extracted file paths. Optional. */
|
|
50
|
+
unzip?(zipfilename: string, outputfolder: string): string[];
|
|
51
|
+
/** Return the temporary directory path. Optional. */
|
|
52
|
+
tempdir?(): string;
|
|
53
|
+
/** List directory entries. Returns array of {name, folder, bytes, isdir, mtimeMs}. Optional. */
|
|
54
|
+
listDir?(dirPath: string): {
|
|
55
|
+
name: string;
|
|
56
|
+
folder: string;
|
|
57
|
+
bytes: number;
|
|
58
|
+
isdir: boolean;
|
|
59
|
+
mtimeMs: number;
|
|
60
|
+
}[];
|
|
61
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified function resolution.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for resolving a function name + arg types + call site
|
|
5
|
+
* to a definitive target. Used by both codegen (compile-time) and JIT (runtime).
|
|
6
|
+
*/
|
|
7
|
+
import type { FunctionIndex } from "./lowering/loweringContext.js";
|
|
8
|
+
import type { CallSite } from "./runtime/runtimeHelpers.js";
|
|
9
|
+
import type { ItemType } from "./lowering/itemTypes.js";
|
|
10
|
+
export type ResolvedTarget = {
|
|
11
|
+
kind: "classMethod";
|
|
12
|
+
className: string;
|
|
13
|
+
methodName: string;
|
|
14
|
+
compileArgTypes: ItemType[];
|
|
15
|
+
stripInstance: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "localFunction";
|
|
18
|
+
name: string;
|
|
19
|
+
argTypes: ItemType[];
|
|
20
|
+
source: {
|
|
21
|
+
from: "main";
|
|
22
|
+
} | {
|
|
23
|
+
from: "classFile";
|
|
24
|
+
className: string;
|
|
25
|
+
methodScope?: string;
|
|
26
|
+
} | {
|
|
27
|
+
from: "workspaceFile";
|
|
28
|
+
wsName: string;
|
|
29
|
+
} | {
|
|
30
|
+
from: "privateFile";
|
|
31
|
+
callerFile: string;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
kind: "privateFunction";
|
|
35
|
+
name: string;
|
|
36
|
+
argTypes: ItemType[];
|
|
37
|
+
callerFile: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "workspaceFunction";
|
|
40
|
+
name: string;
|
|
41
|
+
argTypes: ItemType[];
|
|
42
|
+
} | {
|
|
43
|
+
kind: "workspaceClassConstructor";
|
|
44
|
+
className: string;
|
|
45
|
+
argTypes: ItemType[];
|
|
46
|
+
} | {
|
|
47
|
+
kind: "builtin";
|
|
48
|
+
name: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Definitively resolve a function name to a single target using the FunctionIndex.
|
|
52
|
+
* Returns null only if the function is truly not found.
|
|
53
|
+
*
|
|
54
|
+
* @param name - Function name to resolve
|
|
55
|
+
* @param argTypes - Argument types (may include undefined for unknown)
|
|
56
|
+
* @param callSite - Where the call originates
|
|
57
|
+
* @param index - The upfront function index
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveFunction(name: string, argTypes: ItemType[], callSite: CallSite, index: FunctionIndex): ResolvedTarget | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arithmetic, comparison, and related internal helpers.
|
|
3
|
+
*/
|
|
4
|
+
import { type RuntimeValue } from "../runtime/types.js";
|
|
5
|
+
/** Add two RuntimeValues */
|
|
6
|
+
export declare function mAdd(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
7
|
+
/** Subtract two RuntimeValues */
|
|
8
|
+
export declare function mSub(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
9
|
+
/** Multiply two RuntimeValues (matrix multiply for 2D tensors, scalar otherwise) */
|
|
10
|
+
export declare function mMul(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
11
|
+
/** Element-wise multiply */
|
|
12
|
+
export declare function mElemMul(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
13
|
+
/** Divide */
|
|
14
|
+
export declare function mDiv(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
15
|
+
/** Element-wise divide */
|
|
16
|
+
export declare function mElemDiv(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
17
|
+
/** Left division (mldivide): a \ b — for scalars b/a, for matrices solve a*x = b */
|
|
18
|
+
export declare function mLeftDiv(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
19
|
+
/** Element-wise left division (ldivide): a .\ b = b ./ a */
|
|
20
|
+
export declare function mElemLeftDiv(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
21
|
+
/** Power */
|
|
22
|
+
export declare function mPow(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
23
|
+
/** Element-wise power */
|
|
24
|
+
export declare function mElemPow(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
25
|
+
/** Negation */
|
|
26
|
+
export declare function mNeg(v: RuntimeValue): RuntimeValue;
|
|
27
|
+
/** Transpose (non-conjugate for complex scalars and tensors) */
|
|
28
|
+
export declare function mTranspose(v: RuntimeValue): RuntimeValue;
|
|
29
|
+
/** Conjugate transpose (Hermitian transpose) - transposes and conjugates */
|
|
30
|
+
export declare function mConjugateTranspose(v: RuntimeValue): RuntimeValue;
|
|
31
|
+
export declare function mEqual(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
32
|
+
export declare function mNotEqual(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
33
|
+
export declare function mLess(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
34
|
+
export declare function mLessEqual(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
35
|
+
export declare function mGreater(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
36
|
+
export declare function mGreaterEqual(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
37
|
+
/**
|
|
38
|
+
* Check if two shapes are compatible for broadcasting and compute the output shape.
|
|
39
|
+
* Broadcasting: dimensions must be equal or one of them must be 1.
|
|
40
|
+
* Returns null if shapes are incompatible, otherwise returns the broadcast shape.
|
|
41
|
+
*/
|
|
42
|
+
export declare function getBroadcastShape(shapeA: number[], shapeB: number[]): number[] | null;
|
|
43
|
+
/**
|
|
44
|
+
* Iterate over all elements of a broadcast result in column-major order,
|
|
45
|
+
* calling `visit(aIdx, bIdx, outIdx)` for each output element.
|
|
46
|
+
*/
|
|
47
|
+
export declare function broadcastIterate(aShape: number[], bShape: number[], outShape: number[], visit: (aIdx: number, bIdx: number, outIdx: number) => void): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bessel function implementations (pure numeric, no runtime dependencies).
|
|
3
|
+
*
|
|
4
|
+
* Provides besselj, bessely, besseli, besselk for real-valued arguments.
|
|
5
|
+
*/
|
|
6
|
+
export declare function lanczosGamma(x: number): number;
|
|
7
|
+
export declare function besselj(nu: number, x: number): number;
|
|
8
|
+
export declare function bessely(nu: number, x: number): number;
|
|
9
|
+
export declare function besseli(nu: number, x: number): number;
|
|
10
|
+
export declare function besselk(nu: number, x: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Airy function of the first kind, Ai(x).
|
|
13
|
+
*/
|
|
14
|
+
export declare function airyAi(x: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Derivative of Airy function of the first kind, Ai'(x).
|
|
17
|
+
*/
|
|
18
|
+
export declare function airyAiPrime(x: number): number;
|
|
19
|
+
/**
|
|
20
|
+
* Airy function of the second kind, Bi(x).
|
|
21
|
+
*/
|
|
22
|
+
export declare function airyBi(x: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Derivative of Airy function of the second kind, Bi'(x).
|
|
25
|
+
*/
|
|
26
|
+
export declare function airyBiPrime(x: number): number;
|
|
27
|
+
interface CR {
|
|
28
|
+
re: number;
|
|
29
|
+
im: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Compute all four complex Airy functions at once: Ai(z), Ai'(z), Bi(z), Bi'(z).
|
|
33
|
+
*/
|
|
34
|
+
export declare function airyAllComplex(zr: number, zi: number): {
|
|
35
|
+
ai: CR;
|
|
36
|
+
aip: CR;
|
|
37
|
+
bi: CR;
|
|
38
|
+
bip: CR;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for writing builtin check functions.
|
|
3
|
+
* These make check implementations shorter and easier to read.
|
|
4
|
+
*/
|
|
5
|
+
import { type FloatXArrayType } from "../runtime/types.js";
|
|
6
|
+
import { RTV, RuntimeValue } from "../runtime/index.js";
|
|
7
|
+
/** Ensure data is Float64Array (needed by LAPACK bridges). */
|
|
8
|
+
export declare function toF64(data: FloatXArrayType): Float64Array;
|
|
9
|
+
/**
|
|
10
|
+
* Extract and normalize a string argument at runtime.
|
|
11
|
+
* Strips surrounding quotes and lowercases the result.
|
|
12
|
+
* Works with both raw string args and RuntimeChar/RuntimeString values.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseStringArgLower(arg: unknown): string;
|
|
15
|
+
/**
|
|
16
|
+
* Parse runtime economy-mode argument (0 or 'econ') used by qr, svd, etc.
|
|
17
|
+
* Returns true for economy mode, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseEconArgRuntime(arg: RuntimeValue | undefined): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Build a (possibly complex) eigenvector matrix from LAPACK's packed real format.
|
|
22
|
+
*
|
|
23
|
+
* For complex conjugate eigenvalue pairs, LAPACK stores eigenvectors as:
|
|
24
|
+
* Column j: real part
|
|
25
|
+
* Column j+1: imaginary part
|
|
26
|
+
* Eigenvector for eigenvalue j is V(:,j) + i*V(:,j+1)
|
|
27
|
+
* Eigenvector for eigenvalue j+1 is V(:,j) - i*V(:,j+1)
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildEigenvectorMatrix(packedV: Float64Array, wi: Float64Array, n: number, hasComplex: boolean): import("../runtime/types.js").RuntimeTensor;
|
|
30
|
+
/**
|
|
31
|
+
* Build a tensor, attaching the imaginary part only when it contains non-zero values.
|
|
32
|
+
* Replaces the repeated `hasComplex ? RTV.tensor(re, shape, im) : RTV.tensor(re, shape)` pattern.
|
|
33
|
+
*/
|
|
34
|
+
export declare function maybeComplexTensor(re: FloatXArrayType | Float64Array, shape: number[], im: FloatXArrayType | Float64Array | undefined): ReturnType<typeof RTV.tensor>;
|
|
35
|
+
/**
|
|
36
|
+
* Build a diagonal matrix from a vector of values (column-major).
|
|
37
|
+
* For square matrices pass just n; for rectangular pass [rows, cols].
|
|
38
|
+
* Optionally includes an imaginary diagonal.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildDiagMatrix(realVals: Float64Array | FloatXArrayType, imagVals: Float64Array | FloatXArrayType | undefined, size: number | [number, number]): ReturnType<typeof RTV.tensor>;
|
|
41
|
+
/**
|
|
42
|
+
* In-place Gauss-Jordan elimination with partial pivoting on a column-major
|
|
43
|
+
* augmented matrix [A | B] of size `rows × totalCols`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function gaussJordanEliminate(aug: FloatXArrayType, rows: number, totalCols: number): void;
|
|
46
|
+
/**
|
|
47
|
+
* Call a registered builtin from within another builtin's apply().
|
|
48
|
+
* Convenience wrapper that includes the caller name in error messages.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applyBuiltin(caller: string, name: string, args: RuntimeValue[], nargout: number): RuntimeValue;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const erfScalar: (x: number) => number;
|
|
2
|
+
export declare const erfcScalar: (x: number) => number;
|
|
3
|
+
export declare const erfinvScalar: (x: number) => number;
|
|
4
|
+
export declare const erfcinvScalar: (x: number) => number;
|
|
5
|
+
export declare const erfcxScalar: (x: number) => number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* linsolve(A, B) — solve the linear system A * X = B.
|
|
3
|
+
*
|
|
4
|
+
* If A is square (m × m), uses LU factorisation (dgesv / dgetrf+solve).
|
|
5
|
+
* If A is non-square, uses QR / LQ factorisation (dgels / dgeqrf+solve):
|
|
6
|
+
* overdetermined (m > n): least-squares solution minimising ||A*X - B||₂
|
|
7
|
+
* underdetermined (m < n): minimum-norm solution minimising ||X||₂
|
|
8
|
+
*
|
|
9
|
+
* Both the native LAPACK addon and the ts-lapack TypeScript fallback are
|
|
10
|
+
* supported; the native addon is preferred when available.
|
|
11
|
+
*/
|
|
12
|
+
import { FloatXArrayType } from "../runtime/types.js";
|
|
13
|
+
/**
|
|
14
|
+
* Dispatch linsolve to the native addon (preferred) or ts-lapack fallback.
|
|
15
|
+
* Returns null only when neither bridge exposes `linsolve` (should not happen
|
|
16
|
+
* in practice since ts-lapack always has it).
|
|
17
|
+
*/
|
|
18
|
+
export declare function linsolveLapack(A: FloatXArrayType, m: number, n: number, B: FloatXArrayType, nrhs: number): Float64Array | null;
|
|
19
|
+
/**
|
|
20
|
+
* Dispatch complex linsolve to the native addon (preferred) or ts-lapack fallback.
|
|
21
|
+
* The ts-lapack fallback throws — native addon is required for complex linsolve.
|
|
22
|
+
*/
|
|
23
|
+
export declare function linsolveComplexLapack(ARe: FloatXArrayType, AIm: FloatXArrayType, m: number, n: number, BRe: FloatXArrayType, BIm: FloatXArrayType, nrhs: number): {
|
|
24
|
+
re: Float64Array;
|
|
25
|
+
im: Float64Array;
|
|
26
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adaptive explicit Runge-Kutta ODE solvers.
|
|
3
|
+
*
|
|
4
|
+
* Algorithm and coefficients follow the scipy RK45 implementation.
|
|
5
|
+
* See: https://github.com/scipy/scipy/blob/main/scipy/integrate/_ivp/rk.py
|
|
6
|
+
*
|
|
7
|
+
* Pure numerical code — no runtime types.
|
|
8
|
+
*/
|
|
9
|
+
export interface RKTableau {
|
|
10
|
+
name: string;
|
|
11
|
+
order: number;
|
|
12
|
+
errorOrder: number;
|
|
13
|
+
nStages: number;
|
|
14
|
+
/** Nodes c_i, length nStages */
|
|
15
|
+
C: number[];
|
|
16
|
+
/** RK coefficients a_{s,j}, nStages rows, lower-triangular */
|
|
17
|
+
A: number[][];
|
|
18
|
+
/** Higher-order weights, length nStages */
|
|
19
|
+
B: number[];
|
|
20
|
+
/** Error coefficients E = bhat - b, length nStages + 1 */
|
|
21
|
+
E: number[];
|
|
22
|
+
/** Dense output polynomial coefficients, (nStages+1) x nInterp */
|
|
23
|
+
P: number[][];
|
|
24
|
+
/** Number of interpolation polynomial columns */
|
|
25
|
+
nInterp: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Dormand-Prince 5(4) pair — used by ode45.
|
|
29
|
+
*
|
|
30
|
+
* Error controlled assuming 4th-order accuracy; steps taken with
|
|
31
|
+
* 5th-order formula (local extrapolation). Quartic interpolation
|
|
32
|
+
* polynomial from Shampine [2].
|
|
33
|
+
*/
|
|
34
|
+
export declare const dormandPrince45: RKTableau;
|
|
35
|
+
/**
|
|
36
|
+
* Bogacki-Shampine 3(2) pair — used by ode23.
|
|
37
|
+
*
|
|
38
|
+
* Error controlled assuming 2nd-order accuracy; steps taken with
|
|
39
|
+
* 3rd-order formula (local extrapolation). Cubic Hermite polynomial
|
|
40
|
+
* for the dense output.
|
|
41
|
+
*/
|
|
42
|
+
export declare const bogackiShampine23: RKTableau;
|
|
43
|
+
export interface StepData {
|
|
44
|
+
tOld: number;
|
|
45
|
+
tNew: number;
|
|
46
|
+
h: number;
|
|
47
|
+
yOld: number[];
|
|
48
|
+
yNew: number[];
|
|
49
|
+
/** Q = K^T P, dimensions neq x nInterp */
|
|
50
|
+
Q: number[][];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Evaluate the dense output polynomial at fractional position x in [0,1].
|
|
54
|
+
*
|
|
55
|
+
* Matches scipy RkDenseOutput._call_impl:
|
|
56
|
+
* y = y_old + h * Q @ [x, x^2, ..., x^nInterp]
|
|
57
|
+
*/
|
|
58
|
+
export declare function denseOutputEval(yOld: number[], Q: number[][], h: number, x: number): number[];
|
|
59
|
+
export interface OdeOptions {
|
|
60
|
+
relTol: number;
|
|
61
|
+
absTol: number;
|
|
62
|
+
maxStep: number;
|
|
63
|
+
initialStep: number;
|
|
64
|
+
events?: (t: number, y: number[]) => [number[], boolean[], number[]];
|
|
65
|
+
}
|
|
66
|
+
export interface OdeResult {
|
|
67
|
+
t: number[];
|
|
68
|
+
y: number[][];
|
|
69
|
+
te: number[];
|
|
70
|
+
ye: number[][];
|
|
71
|
+
ie: number[];
|
|
72
|
+
steps: StepData[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Solve y' = f(t,y) using an adaptive embedded Runge-Kutta method.
|
|
76
|
+
*
|
|
77
|
+
* Step control follows scipy RungeKutta._step_impl exactly.
|
|
78
|
+
*/
|
|
79
|
+
export declare function solveRK(tableau: RKTableau, f: (t: number, y: number[]) => number[], tspan: number[], y0: number[], opts: Partial<OdeOptions>): OdeResult;
|
|
80
|
+
export declare function interpolateAtPoints(result: OdeResult, tRequested: number[]): {
|
|
81
|
+
t: number[];
|
|
82
|
+
y: number[][];
|
|
83
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seedable PRNG (xoshiro128**) for random number generation
|
|
3
|
+
*/
|
|
4
|
+
import { RuntimeValue } from "../runtime/index.js";
|
|
5
|
+
export declare function setRngShuffle(): void;
|
|
6
|
+
export declare function setRngSeed(seed: number): void;
|
|
7
|
+
export declare function seedRng(seed: number): void;
|
|
8
|
+
/** Return a random float in [0, 1) using seeded or unseeded PRNG */
|
|
9
|
+
export declare function rngRandom(): number;
|
|
10
|
+
export declare function boxMullerRandom(): number;
|
|
11
|
+
/** Return the current RNG state as a struct {Type, Seed, State} */
|
|
12
|
+
export declare function getRngStateStruct(): RuntimeValue;
|
|
13
|
+
/** Restore RNG state from a struct previously returned by rng() */
|
|
14
|
+
export declare function restoreRngState(s: {
|
|
15
|
+
kind: "struct";
|
|
16
|
+
fields: Map<string, RuntimeValue>;
|
|
17
|
+
}): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cumulative and difference builtins: cumsum, cumprod, cummax, cummin, diff.
|
|
3
|
+
*/
|
|
4
|
+
import { RuntimeValue } from "../../runtime/index.js";
|
|
5
|
+
/** Generic cumulative operation along a specified or default dimension.
|
|
6
|
+
* Supports cumsum(A), cumsum(A, dim), etc. for arbitrary N-D arrays. */
|
|
7
|
+
export declare function cumOp(name: string, args: RuntimeValue[], accumFn: (acc: number, val: number) => number, initial?: number, complexAccumFn?: (accRe: number, accIm: number, valRe: number, valIm: number) => [number, number]): RuntimeValue;
|
|
8
|
+
export declare function diffOnce(v: RuntimeValue, dim?: number): RuntimeValue;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* min/max builtin functions.
|
|
3
|
+
*/
|
|
4
|
+
import { RuntimeValue } from "../../runtime/index.js";
|
|
5
|
+
export declare function minMaxImpl(name: string, args: RuntimeValue[], nargout: number, initial: number, isBetter: (candidate: number, current: number) => boolean, twoArgFn: (a: number, b: number) => number): RuntimeValue | RuntimeValue[];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for reduction operations: dimension iteration, type checks,
|
|
3
|
+
* reduction factories, sparse helpers, and logical/complex scan utilities.
|
|
4
|
+
*/
|
|
5
|
+
import { RuntimeValue } from "../runtime/index.js";
|
|
6
|
+
import { type RuntimeTensor, type RuntimeSparseMatrix } from "../runtime/types.js";
|
|
7
|
+
/** Iterate over all 1-D fibers along `dim` (1-based).
|
|
8
|
+
* For each fiber, calls `callback(outIndex, srcIndices)` where
|
|
9
|
+
* `srcIndices` is an array of flat indices into the source data.
|
|
10
|
+
* Returns `{ resultShape, totalElems }` (resultShape is squeezed).
|
|
11
|
+
* Returns null if dim exceeds the tensor's rank. */
|
|
12
|
+
export declare function forEachSlice(shape: number[], dim: number, callback: (outIdx: number, srcIndices: number[]) => void): {
|
|
13
|
+
resultShape: number[];
|
|
14
|
+
totalElems: number;
|
|
15
|
+
} | null;
|
|
16
|
+
/** Return 1-based dim to reduce along (first non-singleton), or 0 for "reduce to scalar". */
|
|
17
|
+
export declare function firstReduceDim(shape: number[]): number;
|
|
18
|
+
/** Return a deep copy of a tensor (data + shape + optional imag). */
|
|
19
|
+
export declare function copyTensor(v: RuntimeTensor): RuntimeValue;
|
|
20
|
+
/**
|
|
21
|
+
* Complex product reduction. Can't use the independent real/imag approach
|
|
22
|
+
* because (a+bi)(c+di) = (ac-bd)+(ad+bc)i mixes both parts.
|
|
23
|
+
*/
|
|
24
|
+
export declare function complexProd(v: RuntimeTensor, dim?: number): RuntimeValue;
|
|
25
|
+
/** Scan tensor elements for logical reduction (any/all).
|
|
26
|
+
* mode 'any': returns true if any element is nonzero.
|
|
27
|
+
* mode 'all': returns true if all elements are nonzero (true for empty). */
|
|
28
|
+
export declare function scanLogical(data: ArrayLike<number>, imag: ArrayLike<number> | undefined, mode: "any" | "all"): boolean;
|
|
29
|
+
/** Reduce a tensor along a dimension using a logical test (any/all). */
|
|
30
|
+
export declare function logicalAlongDim(v: RuntimeTensor, dim: number, mode: "any" | "all"): RuntimeValue;
|
|
31
|
+
/** Sum a sparse matrix along dim 1 (columns) or dim 2 (rows).
|
|
32
|
+
* Returns sparse for dim=1, dense tensor for dim=2. */
|
|
33
|
+
export declare function sparseSum(v: RuntimeSparseMatrix, dim: number): RuntimeValue;
|
|
34
|
+
/** any/all on sparse matrix along a dimension.
|
|
35
|
+
* Returns sparse for dim=1, dense for dim=2. */
|
|
36
|
+
export declare function sparseAnyAll(v: RuntimeSparseMatrix, dim: number, mode: "any" | "all"): RuntimeValue;
|
|
37
|
+
/** Type check for reductions that return Num without dim arg, Tensor with dim arg. */
|
|
38
|
+
/** Strip trailing 'omitnan'/'includenan' from args. Returns cleaned args and flag. */
|
|
39
|
+
export declare function parseNanFlag(args: RuntimeValue[]): {
|
|
40
|
+
args: RuntimeValue[];
|
|
41
|
+
omitNaN: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** Filter NaN values from a Float64Array, returning a new (possibly shorter) array. */
|
|
44
|
+
export declare function filterNaN(arr: ArrayLike<number>): Float64Array;
|
|
45
|
+
export type ReductionKernel = {
|
|
46
|
+
reduceAll: (v: RuntimeTensor) => RuntimeValue;
|
|
47
|
+
reduceDim: (v: RuntimeTensor, dim: number) => RuntimeValue;
|
|
48
|
+
};
|
|
49
|
+
/** Create an accumulator-based reduction kernel (sum, mean, etc.) */
|
|
50
|
+
export declare function accumKernel(reduceFn: (acc: number, val: number) => number, initial: number, finalizeFn?: (acc: number, count: number) => number): ReductionKernel;
|
|
51
|
+
/** Create a slice-based reduction kernel (median, mode, etc.) */
|
|
52
|
+
export declare function sliceKernel(sliceFn: (slice: ArrayLike<number>) => number): ReductionKernel;
|
|
53
|
+
/** Create an accumulator kernel that skips NaN values. */
|
|
54
|
+
export declare function accumKernelOmitNaN(reduceFn: (acc: number, val: number) => number, initial: number, finalizeFn?: (acc: number, count: number) => number): ReductionKernel;
|
|
55
|
+
/** Create a slice kernel that filters NaN before applying the function. */
|
|
56
|
+
export declare function sliceKernelOmitNaN(sliceFn: (slice: ArrayLike<number>) => number): ReductionKernel;
|
|
57
|
+
/** Helper: extract all numeric values from a RuntimeValue as a plain array. */
|
|
58
|
+
export declare function toNumArray(v: RuntimeValue, name: string): number[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builtin name registry: tracks which names are recognized as builtins.
|
|
3
|
+
*/
|
|
4
|
+
/** Register additional builtin names so isBuiltin() recognizes them. */
|
|
5
|
+
export declare function registerExtraBuiltinNames(names: Iterable<string>): void;
|
|
6
|
+
export declare function isBuiltin(name: string): boolean;
|
|
7
|
+
export declare function getAllBuiltinNames(): string[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared shape/size argument parsing and value coercion for builtins.
|
|
3
|
+
*/
|
|
4
|
+
import { type RuntimeValue } from "../runtime/index.js";
|
|
5
|
+
import { type RuntimeTensor } from "../runtime/types.js";
|
|
6
|
+
/** Promote a scalar (number, logical, complex) to a 1×1 tensor. Tensors pass through. */
|
|
7
|
+
export declare function coerceToTensor(v: RuntimeValue, name: string): RuntimeTensor;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sparse matrix arithmetic operations (with complex support).
|
|
3
|
+
*/
|
|
4
|
+
import { type RuntimeValue, type RuntimeSparseMatrix, type RuntimeTensor } from "../runtime/types.js";
|
|
5
|
+
/** Convert a sparse matrix to dense. */
|
|
6
|
+
declare function sparseToDense(S: RuntimeSparseMatrix): RuntimeTensor;
|
|
7
|
+
export declare function sparseNeg(S: RuntimeSparseMatrix): RuntimeSparseMatrix;
|
|
8
|
+
export declare function sparseTranspose(S: RuntimeSparseMatrix): RuntimeSparseMatrix;
|
|
9
|
+
export declare function sparseConjugateTranspose(S: RuntimeSparseMatrix): RuntimeSparseMatrix;
|
|
10
|
+
export declare function mAddSparse(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
11
|
+
export declare function mSubSparse(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
12
|
+
export declare function mMulSparse(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
13
|
+
export declare function mElemMulSparse(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
14
|
+
export declare function mElemDivSparse(a: RuntimeValue, b: RuntimeValue): RuntimeValue;
|
|
15
|
+
/** Convert sparse to dense RuntimeTensor (exported for use in arithmetic dispatch). */
|
|
16
|
+
export { sparseToDense };
|