numbl 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * "Effectively real" helpers.
3
+ *
4
+ * numbl's JIT cannot always prove at compile time that the result of an
5
+ * operation is real (e.g. `sqrt(1 - x.^2/2)` — the argument's sign is not
6
+ * statically provable, so `sqrt` lifts to the complex path). The result is
7
+ * a complex-typed tensor whose imaginary lane is entirely zero — an
8
+ * artifact of static typing, not a value the user asked to be complex.
9
+ *
10
+ * Value-sensitive builtins (`isreal`, `min`, `max`, `sort`, …) must treat
11
+ * such a tensor exactly as they would a real one: otherwise `min`/`max`
12
+ * silently switch to magnitude ordering and `isreal` reports `false`,
13
+ * diverging from the interpreter (`--opt 0`, which never creates the
14
+ * artifact) and from MATLAB on real data. These helpers detect the
15
+ * all-zero imaginary lane and drop it so the real code path runs.
16
+ */
17
+ import type { RuntimeValue } from "../runtime/index.js";
18
+ import { type RuntimeTensor } from "../runtime/types.js";
19
+ /** True when `imag` is absent or every element is exactly zero. */
20
+ export declare function imagAllZero(imag: ArrayLike<number> | undefined): boolean;
21
+ /** If `t` carries an all-zero imaginary lane, return a real view sharing
22
+ * its data; otherwise return `t` unchanged. */
23
+ export declare function stripZeroImagTensor(t: RuntimeTensor): RuntimeTensor;
24
+ /** Tensor-aware variant for the generic `RuntimeValue` channel. */
25
+ export declare function stripZeroImagValue(v: RuntimeValue): RuntimeValue;
@@ -44,6 +44,7 @@ export * from "./tensor_ops/tensor_eye.js";
44
44
  export * from "./tensor_ops/tensor_fill_nd.js";
45
45
  export * from "./tensor_ops/tensor_fill_square.js";
46
46
  export * from "./tensor_ops/tensor_flip.js";
47
+ export * from "./tensor_ops/tensor_imag_all_zero.js";
47
48
  export * from "./tensor_ops/tensor_linspace.js";
48
49
  export * from "./tensor_ops/tensor_logical_real.js";
49
50
  export * from "./tensor_ops/tensor_logspace.js";
@@ -0,0 +1 @@
1
+ export function mtoc2_tensor_imag_all_zero(a: any): boolean;
@@ -1,2 +1,2 @@
1
1
  /** Numbl version, used for JIT disk cache invalidation. */
2
- export declare const NUMBL_VERSION = "0.4.1";
2
+ export declare const NUMBL_VERSION = "0.4.2";