numbl 0.1.7 → 0.3.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.
Files changed (108) hide show
  1. package/binding.gyp +59 -3
  2. package/dist-cli/cli.js +22538 -7936
  3. package/dist-lib/lib.js +34682 -20852
  4. package/dist-lib/numbl-core/executeCode.d.ts +13 -0
  5. package/dist-lib/numbl-core/fileIOAdapter.d.ts +2 -0
  6. package/dist-lib/numbl-core/helpers/reduction-helpers.d.ts +7 -2
  7. package/dist-lib/numbl-core/interpreter/builtins/datetime.d.ts +39 -0
  8. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +1 -0
  9. package/dist-lib/numbl-core/interpreter/builtins/time-system.d.ts +1 -0
  10. package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +96 -5
  11. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +41 -3
  12. package/dist-lib/numbl-core/interpreter/types.d.ts +1 -1
  13. package/dist-lib/numbl-core/jit/c/abi.d.ts +90 -0
  14. package/dist-lib/numbl-core/jit/c/assemble.d.ts +56 -0
  15. package/dist-lib/numbl-core/jit/c/classify.d.ts +70 -0
  16. package/dist-lib/numbl-core/jit/c/compile.d.ts +37 -0
  17. package/dist-lib/numbl-core/jit/c/context.d.ts +152 -0
  18. package/dist-lib/numbl-core/jit/c/emit/assign.d.ts +20 -0
  19. package/dist-lib/numbl-core/jit/c/emit/complexScalar.d.ts +18 -0
  20. package/dist-lib/numbl-core/jit/c/emit/fused.d.ts +42 -0
  21. package/dist-lib/numbl-core/jit/c/emit/helpers.d.ts +40 -0
  22. package/dist-lib/numbl-core/jit/c/emit/index.d.ts +14 -0
  23. package/dist-lib/numbl-core/jit/c/emit/scalar.d.ts +23 -0
  24. package/dist-lib/numbl-core/jit/c/emit/stmt.d.ts +25 -0
  25. package/dist-lib/numbl-core/jit/c/emit/tensor.d.ts +127 -0
  26. package/dist-lib/numbl-core/jit/c/emit/userCall.d.ts +58 -0
  27. package/dist-lib/numbl-core/jit/c/epilogue.d.ts +26 -0
  28. package/dist-lib/numbl-core/jit/c/feasibility.d.ts +44 -0
  29. package/dist-lib/numbl-core/jit/c/prelude.d.ts +37 -0
  30. package/dist-lib/numbl-core/jit/c/visit.d.ts +63 -0
  31. package/dist-lib/numbl-core/jit/e1/complexKernelEmit.d.ts +46 -0
  32. package/dist-lib/numbl-core/jit/e1/hash.d.ts +10 -0
  33. package/dist-lib/numbl-core/jit/e1/install.d.ts +13 -0
  34. package/dist-lib/numbl-core/jit/e1/kernelEmit.d.ts +54 -0
  35. package/dist-lib/numbl-core/jit/e1/multiReductionKernel.d.ts +66 -0
  36. package/dist-lib/numbl-core/jit/e1/openmpFlag.d.ts +13 -0
  37. package/dist-lib/numbl-core/jit/e1/scalarFnKernel.d.ts +44 -0
  38. package/dist-lib/numbl-core/jit/e2/assignKernel.d.ts +34 -0
  39. package/dist-lib/numbl-core/jit/e2/astToJitExpr.d.ts +25 -0
  40. package/dist-lib/numbl-core/jit/e2/cache.d.ts +80 -0
  41. package/dist-lib/numbl-core/jit/e2/chainKernelEmit.d.ts +55 -0
  42. package/dist-lib/numbl-core/jit/e2/classify.d.ts +119 -0
  43. package/dist-lib/numbl-core/jit/e2/compileFn.d.ts +16 -0
  44. package/dist-lib/numbl-core/jit/e2/complexChainKernelEmit.d.ts +79 -0
  45. package/dist-lib/numbl-core/jit/e2/emitShared.d.ts +71 -0
  46. package/dist-lib/numbl-core/jit/e2/install.d.ts +11 -0
  47. package/dist-lib/numbl-core/jit/e2/liveness.d.ts +29 -0
  48. package/dist-lib/numbl-core/jit/e2/loopKernel.d.ts +49 -0
  49. package/dist-lib/numbl-core/jit/e2/loopKernelEmit.d.ts +75 -0
  50. package/dist-lib/numbl-core/jit/e2/multiReductionDriver.d.ts +24 -0
  51. package/dist-lib/numbl-core/jit/e2/reductionKernelEmit.d.ts +72 -0
  52. package/dist-lib/numbl-core/jit/e2/scalarFnDriver.d.ts +29 -0
  53. package/dist-lib/numbl-core/jit/fusedChainHelpers.d.ts +65 -0
  54. package/dist-lib/numbl-core/jit/fusedScalarEmit.d.ts +69 -0
  55. package/dist-lib/numbl-core/jit/fusion.d.ts +71 -0
  56. package/dist-lib/numbl-core/jit/fusionOps.d.ts +25 -0
  57. package/dist-lib/numbl-core/jit/heavyOps.d.ts +15 -0
  58. package/dist-lib/numbl-core/{interpreter/jit → jit}/index.d.ts +2 -2
  59. package/dist-lib/numbl-core/jit/jitBailSafety.d.ts +41 -0
  60. package/dist-lib/numbl-core/{interpreter/jit → jit}/jitLoop.d.ts +2 -2
  61. package/dist-lib/numbl-core/{interpreter/jit → jit}/jitLoopAnalysis.d.ts +6 -1
  62. package/dist-lib/numbl-core/jit/jitLower.d.ts +122 -0
  63. package/dist-lib/numbl-core/jit/jitLowerExpr.d.ts +27 -0
  64. package/dist-lib/numbl-core/jit/jitLowerStmt.d.ts +9 -0
  65. package/dist-lib/numbl-core/{interpreter/jit → jit}/jitLowerTypes.d.ts +7 -3
  66. package/dist-lib/numbl-core/jit/jitTopLevel.d.ts +22 -0
  67. package/dist-lib/numbl-core/{interpreter/jit → jit}/jitTypes.d.ts +133 -1
  68. package/dist-lib/numbl-core/{interpreter/jit → jit/js}/jitCodegen.d.ts +2 -2
  69. package/dist-lib/numbl-core/{interpreter/jit → jit/js}/jitCodegenHoist.d.ts +19 -1
  70. package/dist-lib/numbl-core/{interpreter/jit → jit/js}/jitHelpers.d.ts +15 -3
  71. package/dist-lib/numbl-core/{interpreter/jit → jit/js}/jitHelpersIndex.d.ts +7 -0
  72. package/dist-lib/numbl-core/jit/js/jitHelpersTensor.d.ts +34 -0
  73. package/dist-lib/numbl-core/jit/js/jsFusedCodegen.d.ts +17 -0
  74. package/dist-lib/numbl-core/jit/js/jsMultiReduction.d.ts +70 -0
  75. package/dist-lib/numbl-core/jit/scalarEmit.d.ts +58 -0
  76. package/dist-lib/numbl-core/lexer/types.d.ts +2 -1
  77. package/dist-lib/numbl-core/native/lapack-bridge.d.ts +39 -1
  78. package/dist-lib/numbl-core/ops/bessel.d.ts +18 -0
  79. package/dist-lib/numbl-core/ops/comparison.d.ts +11 -0
  80. package/dist-lib/numbl-core/ops/complexBinaryElemwise.d.ts +10 -0
  81. package/dist-lib/numbl-core/ops/complexUnaryElemwise.d.ts +8 -0
  82. package/dist-lib/numbl-core/ops/dispatch.d.ts +26 -0
  83. package/dist-lib/numbl-core/ops/index.d.ts +8 -0
  84. package/dist-lib/numbl-core/ops/opCodes.d.ts +70 -0
  85. package/dist-lib/numbl-core/ops/realBinaryElemwise.d.ts +8 -0
  86. package/dist-lib/numbl-core/ops/realUnaryElemwise.d.ts +5 -0
  87. package/dist-lib/numbl-core/ops/reduce.d.ts +6 -0
  88. package/dist-lib/numbl-core/parser/types.d.ts +6 -0
  89. package/dist-lib/numbl-core/runtime/alloc.d.ts +23 -0
  90. package/dist-lib/numbl-core/runtime/runtime.d.ts +1 -0
  91. package/dist-lib/numbl-core/version.d.ts +1 -1
  92. package/native/jit_runtime/jit_runtime.c +261 -0
  93. package/native/jit_runtime/jit_runtime.h +204 -0
  94. package/native/numbl_addon.cpp +62 -1
  95. package/native/ops/bessel.c +572 -0
  96. package/native/ops/comparison.c +150 -0
  97. package/native/ops/complex_binary_elemwise.c +192 -0
  98. package/native/ops/complex_unary_elemwise.c +152 -0
  99. package/native/ops/numbl_ops.c +66 -0
  100. package/native/ops/numbl_ops.h +262 -0
  101. package/native/ops/real_binary_elemwise.c +85 -0
  102. package/native/ops/real_unary_elemwise.c +104 -0
  103. package/native/ops/reduce.c +162 -0
  104. package/native/ops_napi.cpp +320 -0
  105. package/package.json +8 -9
  106. package/dist-lib/numbl-core/interpreter/jit/jitHelpersTensor.d.ts +0 -28
  107. package/dist-lib/numbl-core/interpreter/jit/jitLower.d.ts +0 -23
  108. /package/dist-lib/numbl-core/{interpreter/jit → jit/js}/jitHelpersComplex.d.ts +0 -0
@@ -0,0 +1,70 @@
1
+ /**
2
+ * JS-side multi-reduction block emission.
3
+ *
4
+ * Detection + dispatch for scalar Assigns of the form
5
+ *
6
+ * acc = <expr tree with >=2 reductions over a single tensor Var>
7
+ *
8
+ * On match, the JS codegen emits a block that runs a single-pass
9
+ * reduction loop (either an inline JS loop, or a compiled C kernel
10
+ * under --opt e1), stashes each reduction result in a local, and then
11
+ * emits the Assign's RHS with each reduction Call substituted by the
12
+ * local that holds its value. The RHS-substitution contract lives in
13
+ * `jitCodegen._multiReductionSubst`, which this module installs and
14
+ * clears around the `emitExpr` call the caller provides.
15
+ *
16
+ * Limited to:
17
+ * - sum / prod / max / min / mean (short-circuit any/all excluded)
18
+ * - a single tensor Var argument to every reduction
19
+ * - all reductions read the same tensor name
20
+ * - the tensor is real-typed
21
+ * - at least two reductions in the RHS
22
+ *
23
+ * NaN semantics for max/min are matched to MATLAB omit-NaN behaviour:
24
+ * IEEE unordered compare already skips NaN, and an `any_non_nan` flag
25
+ * drives the all-NaN → NaN fallback.
26
+ */
27
+ import type { JitExpr, JitStmt } from "../jitTypes.js";
28
+ import { type MultiReduceOp } from "../e1/multiReductionKernel.js";
29
+ export interface MultiReductionMatch {
30
+ /** The scalar Assign being emitted (target + original RHS). */
31
+ stmt: JitStmt & {
32
+ tag: "Assign";
33
+ };
34
+ /** The tensor variable name all reductions read. */
35
+ tensorName: string;
36
+ /** Distinct ops that actually appear, in first-occurrence order. Used
37
+ * to size the kernel's output buffer and decide which accumulators
38
+ * to declare on the JS fallback path. */
39
+ ops: MultiReduceOp[];
40
+ /** Every reduction Call node found in the RHS, paired with its op.
41
+ * The JS emitter builds a substitution map from each Call to the
42
+ * local that holds its result. */
43
+ sites: {
44
+ call: JitExpr & {
45
+ tag: "Call";
46
+ };
47
+ op: MultiReduceOp;
48
+ }[];
49
+ }
50
+ /** Try to match the multi-reduction pattern on a single statement. */
51
+ export declare function tryMatchMultiReduction(stmt: JitStmt): MultiReductionMatch | null;
52
+ /**
53
+ * Emit the multi-reduction block. Writes into `lines`.
54
+ *
55
+ * The block:
56
+ * 1. Aliases `<tensorName>.data` to a local and reads its length.
57
+ * 2. Under e1, compiles/dispatches a single-pass C kernel that fills
58
+ * a Float64Array scratch with the accumulator values, with an
59
+ * inline JS fallback at small `n`. Under non-e1, emits just the
60
+ * JS loop.
61
+ * 3. Post-loop: `mean = sum / n`, and a NaN fixup for max/min when
62
+ * every input element was NaN.
63
+ * 4. Installs `_multiReductionSubst` pointing each reduction Call at
64
+ * its local, emits the Assign's RHS via the caller-provided
65
+ * `emitExpr`, and writes the final `<target> = <rhs>;`.
66
+ */
67
+ export declare function emitMultiReductionBlock(lines: string[], indent: string, match: MultiReductionMatch, mangleName: (n: string) => string, emitExprWithSubst: (expr: JitExpr, subst: Map<JitExpr, string>) => string, experimental: string | undefined, par: boolean): void;
68
+ /** Reset per-function counter so generated names stay stable between
69
+ * compiles of the same IR. Called from `generateJS`. */
70
+ export declare function resetMultiReductionState(): 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;
@@ -68,7 +68,8 @@ export declare enum Token {
68
68
  Ellipsis = 66,
69
69
  Newline = 67,
70
70
  Section = 68,
71
- Error = 69
71
+ Error = 69,
72
+ Directive = 70
72
73
  }
73
74
  export interface SpannedToken {
74
75
  token: Token;
@@ -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 = 3;
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;
@@ -439,6 +439,44 @@ export interface LapackBridge {
439
439
  re: Float64Array;
440
440
  im?: Float64Array;
441
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;
442
480
  }
443
481
  export declare function setLapackBridge(bridge: LapackBridge): void;
444
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,5 @@
1
+ /**
2
+ * Pure-TS implementation of real unary element-wise ops.
3
+ * Mirrors native/ops/real_unary_elemwise.c.
4
+ */
5
+ export declare function tsRealUnaryElemwise(op: number, n: number, a: Float64Array, 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 {};
@@ -147,6 +147,7 @@ export declare class Runtime {
147
147
  /** Scalar power that returns complex for negative base with fractional exponent */
148
148
  pow(a: number, b: number): number | RuntimeComplexNumber;
149
149
  share(v: unknown): RuntimeValue;
150
+ get displayResults(): boolean;
150
151
  displayResult(v: unknown): void;
151
152
  displayAssign(name: string, v: unknown): void;
152
153
  getConstant(name: string): RuntimeValue;
@@ -1,2 +1,2 @@
1
1
  /** Numbl version, used for JIT disk cache invalidation. */
2
- export declare const NUMBL_VERSION = "0.1.7";
2
+ export declare const NUMBL_VERSION = "0.3.0";