@danielsimonjr/mathts-functions 0.69.2 → 0.70.1

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 (220) hide show
  1. package/README.md +66 -1
  2. package/dist/algebra/decomposition/lup.d.ts.map +1 -1
  3. package/dist/algebra/decomposition/qr.d.ts.map +1 -1
  4. package/dist/algebra/simplify/util.d.ts.map +1 -1
  5. package/dist/algebra/simplifyConstant.d.ts +3 -4
  6. package/dist/algebra/simplifyConstant.d.ts.map +1 -1
  7. package/dist/algebra/solver/lsolve.d.ts.map +1 -1
  8. package/dist/algebra/solver/usolve.d.ts.map +1 -1
  9. package/dist/arithmetic/ceil.d.ts.map +1 -1
  10. package/dist/arithmetic/fix.d.ts.map +1 -1
  11. package/dist/arithmetic/floor.d.ts.map +1 -1
  12. package/dist/arithmetic/norm.d.ts.map +1 -1
  13. package/dist/arithmetic/round.d.ts.map +1 -1
  14. package/dist/arithmetic/sign.d.ts +2 -2
  15. package/dist/arithmetic/sign.d.ts.map +1 -1
  16. package/dist/arithmetic/snap-to-round.d.ts +36 -0
  17. package/dist/arithmetic/snap-to-round.d.ts.map +1 -0
  18. package/dist/arithmetic/xgcd.d.ts +6 -6
  19. package/dist/arithmetic/xgcd.d.ts.map +1 -1
  20. package/dist/cas/layer3.d.ts.map +1 -1
  21. package/dist/cas/rational-integrate.d.ts.map +1 -1
  22. package/dist/cas/render-coeff-times.d.ts +7 -0
  23. package/dist/cas/render-coeff-times.d.ts.map +1 -0
  24. package/dist/cas-integration.d.ts.map +1 -1
  25. package/dist/config-api.d.ts +47 -5
  26. package/dist/config-api.d.ts.map +1 -1
  27. package/dist/descriptive-stats.d.ts +4 -0
  28. package/dist/descriptive-stats.d.ts.map +1 -1
  29. package/dist/factories/index.d.ts +3 -0
  30. package/dist/factories/index.d.ts.map +1 -1
  31. package/dist/factories/scope.d.ts +8 -0
  32. package/dist/factories/scope.d.ts.map +1 -1
  33. package/dist/fit-scalar.d.ts +49 -0
  34. package/dist/fit-scalar.d.ts.map +1 -0
  35. package/dist/front-export.d.ts +81 -0
  36. package/dist/front-export.d.ts.map +1 -0
  37. package/dist/geometry/alpha-shape.d.ts.map +1 -1
  38. package/dist/geometry/circumcircle.d.ts +16 -0
  39. package/dist/geometry/circumcircle.d.ts.map +1 -0
  40. package/dist/geometry/geometry-extra.d.ts.map +1 -1
  41. package/dist/geometry/voronoi.d.ts.map +1 -1
  42. package/dist/gpu/elementwise-gpu.d.ts +2 -0
  43. package/dist/gpu/elementwise-gpu.d.ts.map +1 -1
  44. package/dist/index.d.ts +19 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +24998 -25385
  47. package/dist/matrix/column.d.ts.map +1 -1
  48. package/dist/matrix/complex-to-interleaved.d.ts +7 -0
  49. package/dist/matrix/complex-to-interleaved.d.ts.map +1 -0
  50. package/dist/matrix/fft.d.ts.map +1 -1
  51. package/dist/matrix/from-vectors.d.ts +45 -0
  52. package/dist/matrix/from-vectors.d.ts.map +1 -0
  53. package/dist/matrix/ifft.d.ts.map +1 -1
  54. package/dist/matrix/mapSlices.d.ts.map +1 -1
  55. package/dist/matrix/matrixFromColumns.d.ts.map +1 -1
  56. package/dist/matrix/matrixFromRows.d.ts.map +1 -1
  57. package/dist/matrix/native-accel.d.ts.map +1 -1
  58. package/dist/matrix/partitionSelect.d.ts +1 -0
  59. package/dist/matrix/partitionSelect.d.ts.map +1 -1
  60. package/dist/matrix/row.d.ts.map +1 -1
  61. package/dist/matrix/slice-2d.d.ts +16 -0
  62. package/dist/matrix/slice-2d.d.ts.map +1 -0
  63. package/dist/matrix/sort.d.ts +1 -1
  64. package/dist/matrix/sort.d.ts.map +1 -1
  65. package/dist/matrix/sparse-csc-tail.d.ts +21 -0
  66. package/dist/matrix/sparse-csc-tail.d.ts.map +1 -0
  67. package/dist/ml/dbscan-knn.d.ts +6 -0
  68. package/dist/ml/dbscan-knn.d.ts.map +1 -1
  69. package/dist/ml/ols.d.ts.map +1 -1
  70. package/dist/ml/regularized-regression.d.ts.map +1 -1
  71. package/dist/numbertheory/extra.d.ts.map +1 -1
  72. package/dist/numeric/bfgs.d.ts.map +1 -1
  73. package/dist/numeric/control-equations.d.ts +0 -47
  74. package/dist/numeric/control-equations.d.ts.map +1 -1
  75. package/dist/numeric/eigsh.d.ts.map +1 -1
  76. package/dist/numeric/fsolve.d.ts.map +1 -1
  77. package/dist/numeric/hermite.d.ts +22 -0
  78. package/dist/numeric/hermite.d.ts.map +1 -0
  79. package/dist/numeric/krylov.d.ts.map +1 -1
  80. package/dist/numeric/numeric-jacobian.d.ts +65 -7
  81. package/dist/numeric/numeric-jacobian.d.ts.map +1 -1
  82. package/dist/numeric/open-root-finders.d.ts.map +1 -1
  83. package/dist/numeric/solveDAE.d.ts.map +1 -1
  84. package/dist/numeric/solveDDE.d.ts.map +1 -1
  85. package/dist/numeric/solveODE.d.ts.map +1 -1
  86. package/dist/numeric/svds.d.ts.map +1 -1
  87. package/dist/numeric-equivalence.d.ts +110 -0
  88. package/dist/numeric-equivalence.d.ts.map +1 -0
  89. package/dist/numeric-extra.d.ts.map +1 -1
  90. package/dist/optimization-extra.d.ts +33 -10
  91. package/dist/optimization-extra.d.ts.map +1 -1
  92. package/dist/pareto-front.d.ts +165 -0
  93. package/dist/pareto-front.d.ts.map +1 -0
  94. package/dist/plain/number/probability.d.ts +9 -3
  95. package/dist/plain/number/probability.d.ts.map +1 -1
  96. package/dist/probability/bigint-binomial.d.ts +34 -0
  97. package/dist/probability/bigint-binomial.d.ts.map +1 -0
  98. package/dist/probability/combinations.d.ts.map +1 -1
  99. package/dist/probability/combinationsWithRep.d.ts.map +1 -1
  100. package/dist/scalar-batch-parallel.d.ts +71 -0
  101. package/dist/scalar-batch-parallel.d.ts.map +1 -0
  102. package/dist/scalar-batch-task-CZd6LPg9.js +2587 -0
  103. package/dist/scalar-batch-task.d.ts +40 -0
  104. package/dist/scalar-batch-task.d.ts.map +1 -0
  105. package/dist/scalar-batch.worker.js +34 -0
  106. package/dist/scalar-compile.d.ts +227 -0
  107. package/dist/scalar-compile.d.ts.map +1 -0
  108. package/dist/scalar-dimension.d.ts +54 -0
  109. package/dist/scalar-dimension.d.ts.map +1 -0
  110. package/dist/scalar-eval.d.ts +7 -0
  111. package/dist/scalar-eval.d.ts.map +1 -1
  112. package/dist/scalar-mutate.d.ts +70 -0
  113. package/dist/scalar-mutate.d.ts.map +1 -0
  114. package/dist/scalar-node-bridge.d.ts +30 -0
  115. package/dist/scalar-node-bridge.d.ts.map +1 -0
  116. package/dist/scalar-search.d.ts +176 -0
  117. package/dist/scalar-search.d.ts.map +1 -0
  118. package/dist/set/flatten-pair.d.ts +16 -0
  119. package/dist/set/flatten-pair.d.ts.map +1 -0
  120. package/dist/set/setSymDifference.d.ts.map +1 -1
  121. package/dist/set/setUnion.d.ts.map +1 -1
  122. package/dist/signal-filter-extra.d.ts.map +1 -1
  123. package/dist/special/niche.d.ts.map +1 -1
  124. package/dist/statistics/extreme.d.ts +23 -0
  125. package/dist/statistics/extreme.d.ts.map +1 -0
  126. package/dist/statistics/max.d.ts.map +1 -1
  127. package/dist/statistics/median.d.ts +1 -1
  128. package/dist/statistics/median.d.ts.map +1 -1
  129. package/dist/statistics/min.d.ts.map +1 -1
  130. package/dist/statistics/prod.d.ts.map +1 -1
  131. package/dist/stats/inference-extra2.d.ts.map +1 -1
  132. package/dist/string/print.d.ts.map +1 -1
  133. package/dist/type/local/Decimal.d.ts +0 -3
  134. package/dist/type/local/Decimal.d.ts.map +1 -1
  135. package/dist/type/matrix/ImmutableDenseMatrix.d.ts +10 -0
  136. package/dist/type/matrix/ImmutableDenseMatrix.d.ts.map +1 -1
  137. package/dist/type/matrix/MatrixIndex.d.ts +22 -1
  138. package/dist/type/matrix/MatrixIndex.d.ts.map +1 -1
  139. package/dist/type/matrix/utils/matAlgo13xDD.d.ts.map +1 -1
  140. package/dist/type/matrix/utils/matAlgo14xDs.d.ts.map +1 -1
  141. package/dist/type/matrix/utils/matrixAlgorithmSuite.d.ts.map +1 -1
  142. package/dist/typed/aggregate-restart.d.ts +14 -0
  143. package/dist/typed/aggregate-restart.d.ts.map +1 -0
  144. package/dist/typed/algebra.d.ts +4 -0
  145. package/dist/typed/algebra.d.ts.map +1 -1
  146. package/dist/typed/arithmetic.d.ts.map +1 -1
  147. package/dist/typed/cas.d.ts +2 -1
  148. package/dist/typed/cas.d.ts.map +1 -1
  149. package/dist/typed/centrality-restarts.d.ts +13 -0
  150. package/dist/typed/centrality-restarts.d.ts.map +1 -0
  151. package/dist/typed/combinatorics.d.ts.map +1 -1
  152. package/dist/typed/dist-objects.d.ts.map +1 -1
  153. package/dist/typed/distributions.d.ts +8 -13
  154. package/dist/typed/distributions.d.ts.map +1 -1
  155. package/dist/typed/euclid.d.ts +6 -0
  156. package/dist/typed/euclid.d.ts.map +1 -0
  157. package/dist/typed/factorization/finite-field.d.ts.map +1 -1
  158. package/dist/typed/factorization/index.d.ts.map +1 -1
  159. package/dist/typed/factorization/integer-poly.d.ts +7 -0
  160. package/dist/typed/factorization/integer-poly.d.ts.map +1 -1
  161. package/dist/typed/factorization/kronecker-factor.d.ts.map +1 -1
  162. package/dist/typed/factorization/render-univariate.d.ts +11 -0
  163. package/dist/typed/factorization/render-univariate.d.ts.map +1 -0
  164. package/dist/typed/factorization/zassenhaus.d.ts +9 -0
  165. package/dist/typed/factorization/zassenhaus.d.ts.map +1 -1
  166. package/dist/typed/fused.d.ts.map +1 -1
  167. package/dist/typed/geometry.d.ts +2 -2
  168. package/dist/typed/geometry.d.ts.map +1 -1
  169. package/dist/typed/graph.d.ts +2 -7
  170. package/dist/typed/graph.d.ts.map +1 -1
  171. package/dist/typed/hypothesis.d.ts.map +1 -1
  172. package/dist/typed/index.d.ts +1 -0
  173. package/dist/typed/index.d.ts.map +1 -1
  174. package/dist/typed/interpolation.d.ts +6 -7
  175. package/dist/typed/interpolation.d.ts.map +1 -1
  176. package/dist/typed/matrix-ops.d.ts.map +1 -1
  177. package/dist/typed/normal-equations-solve.d.ts +8 -0
  178. package/dist/typed/normal-equations-solve.d.ts.map +1 -0
  179. package/dist/typed/numeric.d.ts +5 -1
  180. package/dist/typed/numeric.d.ts.map +1 -1
  181. package/dist/typed/parallel-map.d.ts +11 -0
  182. package/dist/typed/parallel-map.d.ts.map +1 -1
  183. package/dist/typed/polynomial-ideal.d.ts +6 -0
  184. package/dist/typed/polynomial-ideal.d.ts.map +1 -1
  185. package/dist/typed/set.d.ts.map +1 -1
  186. package/dist/typed/signal.d.ts +6 -6
  187. package/dist/typed/signal.d.ts.map +1 -1
  188. package/dist/typed/special.d.ts +22 -26
  189. package/dist/typed/special.d.ts.map +1 -1
  190. package/dist/typed/statistics.d.ts +19 -2
  191. package/dist/typed/statistics.d.ts.map +1 -1
  192. package/dist/typed/string-derivative.d.ts +19 -0
  193. package/dist/typed/string-derivative.d.ts.map +1 -0
  194. package/dist/typed/string.d.ts +3 -3
  195. package/dist/typed/string.d.ts.map +1 -1
  196. package/dist/typed/unit.d.ts.map +1 -1
  197. package/dist/utils/isPrime.d.ts +15 -0
  198. package/dist/utils/isPrime.d.ts.map +1 -1
  199. package/dist/utils/print.d.ts +5 -0
  200. package/dist/utils/print.d.ts.map +1 -1
  201. package/dist/utils/typed-impl.d.ts +11 -0
  202. package/dist/utils/typed-impl.d.ts.map +1 -0
  203. package/dist/wasm/WasmLoader.d.ts +3 -21
  204. package/dist/wasm/WasmLoader.d.ts.map +1 -1
  205. package/dist/wasm/bridges/common.d.ts +18 -2
  206. package/dist/wasm/bridges/common.d.ts.map +1 -1
  207. package/dist/wasm/mathts-as.wasm +0 -0
  208. package/dist/wasm/poly/wasm-bridge.d.ts +11 -0
  209. package/dist/wasm/poly/wasm-bridge.d.ts.map +1 -1
  210. package/dist/wasm/sort/wasm-bridge.d.ts +0 -10
  211. package/dist/wasm/sort/wasm-bridge.d.ts.map +1 -1
  212. package/dist/wasm/special/scalars.d.ts +49 -0
  213. package/dist/wasm/special/scalars.d.ts.map +1 -1
  214. package/dist/wasm/special/wasm-bridge.d.ts +11 -12
  215. package/dist/wasm/special/wasm-bridge.d.ts.map +1 -1
  216. package/dist/wasm/wasm-manifest.json +1 -1
  217. package/package.json +8 -8
  218. package/types/index.d.ts +1 -1
  219. package/dist/wasm/integrity.d.ts +0 -16
  220. package/dist/wasm/integrity.d.ts.map +0 -1
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Sampling comparison of two scalar trees.
3
+ *
4
+ * Samples random points in a caller-supplied domain, evaluates both trees with
5
+ * {@link compileScalar}, and compares with {@link nearlyEqual} from core.
6
+ * **Numerical agreement alone never proves symbolic equivalence.** A
7
+ * `consistent` verdict is evidence, not proof.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ import type { ScalarNode } from '@danielsimonjr/mathts-expression';
12
+ import type { SeededRng } from '@danielsimonjr/mathts-core';
13
+ /**
14
+ * Thrown for invalid options (bad domain, tolerances, RNG, samples, and so on).
15
+ * Does not wrap {@link ScalarEvalError} from bad trees.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { numericallyEquivalent, NumericEquivalenceError, scalar } from '@danielsimonjr/mathts-functions';
20
+ * import { createSeededRng } from '@danielsimonjr/mathts-core';
21
+ * try {
22
+ * numericallyEquivalent(scalar.symbol('x'), scalar.symbol('x'), {
23
+ * domain: {},
24
+ * rng: createSeededRng(0),
25
+ * });
26
+ * } catch (e) {
27
+ * e instanceof NumericEquivalenceError; // true — missing domain for x
28
+ * }
29
+ * ```
30
+ */
31
+ export declare class NumericEquivalenceError extends Error {
32
+ constructor(message: string);
33
+ }
34
+ /**
35
+ * Options for {@link numericallyEquivalent}.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import type { NumericEquivalenceOptions } from '@danielsimonjr/mathts-functions';
40
+ * import { createSeededRng } from '@danielsimonjr/mathts-core';
41
+ * const opts: NumericEquivalenceOptions = {
42
+ * domain: { x: [0, 1] },
43
+ * rng: createSeededRng(42),
44
+ * };
45
+ * ```
46
+ */
47
+ export interface NumericEquivalenceOptions {
48
+ /** Per-symbol sampling box `[lo, hi)` (half-open unless `lo === hi`). */
49
+ readonly domain: Readonly<Record<string, readonly [number, number]>>;
50
+ /** Sample count when there is at least one free symbol (default 64). */
51
+ readonly samples?: number;
52
+ /** Required stream; the implementation calls `next()` only. */
53
+ readonly rng: SeededRng;
54
+ /** Relative tolerance (default `1e-9`). */
55
+ readonly relTol?: number;
56
+ /** Absolute tolerance (default `1e-12`). */
57
+ readonly absTol?: number;
58
+ /** When true, test whether `a` and `b` agree up to a single scale factor. */
59
+ readonly upToConstant?: boolean;
60
+ /** Symbol names to sample log-uniformly on a strictly positive box. */
61
+ readonly logUniform?: readonly string[];
62
+ }
63
+ /**
64
+ * Result of {@link numericallyEquivalent}.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { numericallyEquivalent, scalar } from '@danielsimonjr/mathts-functions';
69
+ * import { createSeededRng } from '@danielsimonjr/mathts-core';
70
+ * const r = numericallyEquivalent(scalar.number(1), scalar.number(1), {
71
+ * domain: {},
72
+ * rng: createSeededRng(0),
73
+ * });
74
+ * r.verdict; // 'consistent'
75
+ * ```
76
+ */
77
+ export type NumericEquivalence = {
78
+ readonly verdict: 'consistent';
79
+ readonly samplesUsed: number;
80
+ readonly constant?: number;
81
+ } | {
82
+ readonly verdict: 'counterexample';
83
+ readonly at: Readonly<Record<string, number>>;
84
+ readonly a: number;
85
+ readonly b: number;
86
+ } | {
87
+ readonly verdict: 'inconclusive';
88
+ readonly reason: 'too-few-valid-samples';
89
+ };
90
+ /**
91
+ * Compare two scalar trees by random sampling in a domain.
92
+ *
93
+ * **Numerical agreement alone never proves symbolic equivalence.** A
94
+ * `consistent` verdict is evidence, not proof.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import { numericallyEquivalent, scalar } from '@danielsimonjr/mathts-functions';
99
+ * import { createSeededRng } from '@danielsimonjr/mathts-core';
100
+ * const rng = createSeededRng(1);
101
+ * const lhs = scalar.op('+', [
102
+ * scalar.op('^', [scalar.call('sin', scalar.symbol('x')), scalar.number(2)]),
103
+ * scalar.op('^', [scalar.call('cos', scalar.symbol('x')), scalar.number(2)]),
104
+ * ]);
105
+ * const r = numericallyEquivalent(lhs, scalar.number(1), { domain: { x: [0, 1] }, rng });
106
+ * r.verdict === 'consistent'; // evidence only — not a proof of identity
107
+ * ```
108
+ */
109
+ export declare function numericallyEquivalent(a: ScalarNode, b: ScalarNode, options: NumericEquivalenceOptions): NumericEquivalence;
110
+ //# sourceMappingURL=numeric-equivalence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric-equivalence.d.ts","sourceRoot":"","sources":["../src/numeric-equivalence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAEnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAO5D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACrE,wEAAwE;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC;IACxB,2CAA2C;IAC3C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,uEAAuE;IACvE,QAAQ,CAAC,UAAU,CAA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M,CAQxC;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAOxC;AAED,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CASxC;AAuBD,wCAAwC;AACxC,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAEvC;AAED,wCAAwC;AACxC,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,EAAE,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAsB3D"}
@@ -9,17 +9,32 @@ export interface OptimizeResult {
9
9
  converged: boolean;
10
10
  }
11
11
  /**
12
- * Nelder–Mead downhill-simplex minimization of `f: ℝⁿ → ℝ` from `x0`. Derivative-free.
13
- * Matches `scipy.optimize.minimize(method='Nelder-Mead')` to the requested tolerance.
12
+ * Options for {@link nelderMead}. Defaults use a relative simplex step and relative
13
+ * convergence test (SciPy-style); set `stepRule` / `tolRule` to `'absolute'` for the
14
+ * contract used by {@link minimize}.
14
15
  */
15
- export declare function nelderMead(f: (x: number[]) => number, x0: readonly number[], opts?: {
16
+ export interface NelderMeadOptions {
16
17
  maxIter?: number;
17
18
  tol?: number;
18
19
  step?: number;
19
- }): OptimizeResult;
20
+ /** `'relative'` (default): perturb each coordinate by `step * x_j` (or `step` at zero). */
21
+ stepRule?: 'relative' | 'absolute';
22
+ /** `'relative'` (default): `|f_worst−f_best| ≤ tol·(|f_best|+tol)`. `'absolute'`: max vertex spread `< tol`. */
23
+ tolRule?: 'relative' | 'absolute';
24
+ }
25
+ /**
26
+ * Nelder–Mead downhill-simplex minimization of `f: ℝⁿ → ℝ` from `x0`. Derivative-free.
27
+ * Matches `scipy.optimize.minimize(method='Nelder-Mead')` to the requested tolerance.
28
+ *
29
+ * @example
30
+ * nelderMead((x) => (x[0] - 1) ** 2, [2]) // => { x: ~[1], … }; relative step 0.05 by default
31
+ */
32
+ export declare function nelderMead(f: (x: number[]) => number, x0: readonly number[], opts?: NelderMeadOptions): OptimizeResult;
20
33
  /**
21
34
  * Gradient-descent minimization with optional backtracking line search. `grad` may
22
- * be supplied; otherwise a central-difference gradient is used.
35
+ * be supplied; otherwise a central-difference gradient with constant step `1e-6`
36
+ * is used ({@link centralDifferenceGradient}). That step is not the
37
+ * `max(1, |x_i|) · cbrt(eps)` step `bfgs` uses.
23
38
  */
24
39
  export declare function gradientDescent(f: (x: number[]) => number, x0: readonly number[], opts?: {
25
40
  grad?: (x: number[]) => number[];
@@ -37,13 +52,21 @@ export interface LMResult {
37
52
  iterations: number;
38
53
  converged: boolean;
39
54
  }
55
+ /** Options for {@link levenbergMarquardt}. */
56
+ export interface LMOptions {
57
+ maxIter?: number;
58
+ tol?: number;
59
+ /**
60
+ * Analytic Jacobian `J` with `J[i][j] = ∂r_i/∂x_j`. When omitted, a forward
61
+ * difference via {@link numericJacobian} is used (`h = 1e-7`).
62
+ */
63
+ jacobian?: (x: number[]) => number[][];
64
+ }
40
65
  /**
41
66
  * Levenberg–Marquardt nonlinear least squares: minimize ½‖r(x)‖² for a vector
42
- * residual `r`. Numeric Jacobian; damped normal equations `(JᵀJ + λI)δ = Jᵀr`
67
+ * residual `r`. Uses `opts.jacobian` when provided, otherwise a forward-difference
68
+ * {@link numericJacobian} (`h = 1e-7`). Damped normal equations `(JᵀJ + λI)δ = Jᵀr`
43
69
  * solved via the matrix `inv`. Mirrors `scipy.optimize.least_squares(method='lm')`.
44
70
  */
45
- export declare function levenbergMarquardt(residual: (x: number[]) => number[], x0: readonly number[], opts?: {
46
- maxIter?: number;
47
- tol?: number;
48
- }): LMResult;
71
+ export declare function levenbergMarquardt(residual: (x: number[]) => number[], x0: readonly number[], opts?: LMOptions): LMResult;
49
72
  //# sourceMappingURL=optimization-extra.d.ts.map
@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MAAM,EAAE,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,8CAA8C;AAC9C,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,EAAE,CAAC;CACxC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,EACnC,EAAE,EAAE,SAAS,MAAM,EAAE,EACrB,IAAI,GAAE,SAAc,GACnB,QAAQ,CA4EV"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Pareto hall of fame, log-loss scores, and model selection.
3
+ *
4
+ * `scoreFront` on the log scale walks the array in the order given. It does not sort
5
+ * and it does not drop rows. The first row scores `0`. Each later row with `loss > 0`
6
+ * scores `-Math.log(loss / previousLoss) / (complexity - previousComplexity)`.
7
+ * `loss <= 0` scores `+Infinity`. A zero complexity gap is IEEE division (`NaN` or an
8
+ * infinity); there is no special case. On the linear scale every score is `null`, and a
9
+ * zero loss does not become `+Infinity`. Any other `lossScale` throws `ParetoFrontError`.
10
+ *
11
+ * `selectFrontModel` defaults to `best` with factor `1.5`. `accuracy` is the minimum
12
+ * loss. `score` is the maximum score. `best` keeps rows with `loss <= 1.5 * min(loss)`
13
+ * and then takes the maximum score. If every score is `null`, `score` and `best` both
14
+ * fall back to `accuracy`. A mix of `null` and numeric scores throws. Ties: lower
15
+ * complexity, then the earlier input index. `NaN` is worse than every other score,
16
+ * including `-Infinity`. The return value is the same object as the chosen row.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+ /**
21
+ * One hall-of-fame row. `item` is opaque and is not inspected.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { paretoFront } from '@danielsimonjr/mathts-functions';
26
+ * const front = paretoFront([
27
+ * { loss: 0.5, complexity: 1, item: 'A' },
28
+ * { loss: 0.1, complexity: 3, item: 'D-front' },
29
+ * ]);
30
+ * front.map((r) => r.item).join(','); // 'A,D-front'
31
+ * ```
32
+ */
33
+ export interface FrontCandidate<T = unknown> {
34
+ readonly loss: number;
35
+ readonly complexity: number;
36
+ readonly item: T;
37
+ }
38
+ /**
39
+ * A {@link FrontCandidate} plus a log-scale score.
40
+ * `null` means the linear loss scale, where no score column is stored.
41
+ * A numeric score may be `+Infinity`, `-Infinity`, or `NaN` (a zero complexity gap).
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import { paretoFront, scoreFront } from '@danielsimonjr/mathts-functions';
46
+ * const front = paretoFront([{ loss: 0.5, complexity: 1, item: 'A' }]);
47
+ * scoreFront(front)[0]!.score; // 0 (log scale)
48
+ * scoreFront(front, { lossScale: 'linear' })[0]!.score; // null
49
+ * ```
50
+ */
51
+ export interface ScoredCandidate<T = unknown> extends FrontCandidate<T> {
52
+ readonly score: number | null;
53
+ }
54
+ /**
55
+ * Thrown by {@link scoreFront} and {@link selectFrontModel} for an empty
56
+ * selection, a bad mode, a bad loss scale, or a mixed score column.
57
+ * `paretoFront` does not throw.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import { selectFrontModel, ParetoFrontError } from '@danielsimonjr/mathts-functions';
62
+ * try {
63
+ * selectFrontModel([]);
64
+ * } catch (e) {
65
+ * e instanceof ParetoFrontError && e.message; // 'selectFrontModel: empty front'
66
+ * }
67
+ * ```
68
+ */
69
+ export declare class ParetoFrontError extends Error {
70
+ constructor(message: string);
71
+ }
72
+ /**
73
+ * Hall of fame: one survivor per complexity, sorted by complexity ascending.
74
+ *
75
+ * A candidate whose `loss` or `complexity` is not finite (`NaN`, `+Infinity`,
76
+ * `-Infinity`) is dropped. That is a documented choice; callers are assumed
77
+ * to supply finite losses before scoring.
78
+ *
79
+ * Among finite candidates with `===` complexity (`-0` and `0` are the same),
80
+ * keep the strictly smallest loss. If two losses are equal, keep the earlier
81
+ * input. The survivor is then kept only when its loss is **strictly** smaller
82
+ * than the loss of every survivor of lower complexity. The lowest complexity
83
+ * is always kept. A simpler row is never removed because a more complex row
84
+ * is better.
85
+ *
86
+ * Returns a new array of new wrapper objects. `item` is the input reference.
87
+ * The input array and objects are not mutated.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { paretoFront } from '@danielsimonjr/mathts-functions';
92
+ * const front = paretoFront([
93
+ * { loss: 0.5, complexity: 1, item: 'A' },
94
+ * { loss: 0.5, complexity: 2, item: 'B-tie' },
95
+ * { loss: 0.2, complexity: 4, item: 'C-dominated' },
96
+ * { loss: 0.1, complexity: 3, item: 'D-front' },
97
+ * { loss: Number.NaN, complexity: 1, item: 'drop' },
98
+ * ]);
99
+ * front.length; // 2 — non-finite row dropped; paretoFront never throws
100
+ * paretoFront([]).length; // 0
101
+ * ```
102
+ */
103
+ export declare function paretoFront<T>(candidates: readonly FrontCandidate<T>[]): FrontCandidate<T>[];
104
+ /**
105
+ * Log-loss scores, in array order. Does not sort and does not drop rows.
106
+ *
107
+ * `lossScale` defaults to `'log'`. On `'log'`, the first row scores `0`.
108
+ * Each later row scores `-Math.log(loss / previousLoss) / (complexity - previousComplexity)`
109
+ * when `loss > 0`. When `loss <= 0` (zero **or** negative), the score is `+Infinity`.
110
+ * A zero complexity gap is left to IEEE division (`NaN`, `+Infinity`, or `-Infinity`);
111
+ * there is no special case. On `'linear'`, every score is `null` and a zero loss
112
+ * does **not** become `+Infinity`.
113
+ *
114
+ * Any other `lossScale` throws `ParetoFrontError`
115
+ * (`scoreFront: lossScale must be 'log' or 'linear'`).
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { paretoFront, scoreFront } from '@danielsimonjr/mathts-functions';
120
+ * const front = paretoFront([
121
+ * { loss: 0.5, complexity: 1, item: 'A' },
122
+ * { loss: 0.1, complexity: 3, item: 'D-front' },
123
+ * ]);
124
+ * scoreFront(front)[0]!.score; // 0
125
+ * scoreFront(front, { lossScale: 'linear' })[0]!.score; // null
126
+ * ```
127
+ */
128
+ export declare function scoreFront<T>(front: readonly FrontCandidate<T>[], options?: {
129
+ lossScale?: 'log' | 'linear';
130
+ }): ScoredCandidate<T>[];
131
+ /**
132
+ * Pick a champion row from a scored front. `mode` defaults to `'best'`.
133
+ *
134
+ * `'accuracy'` is the minimum loss. `'score'` is the maximum score.
135
+ * `'best'` keeps rows with `loss <= bestLossFactor * min(loss)` (`bestLossFactor`
136
+ * defaults to `1.5`) and then takes the maximum score among them.
137
+ * If every `score` is `null`, `'score'` and `'best'` both fall back to `'accuracy'`
138
+ * (as when the score column is absent on the linear scale).
139
+ *
140
+ * Ties on the chosen metric: lower complexity wins, then the earlier input index.
141
+ * Score order treats `NaN` as worse than every other score, including `-Infinity`.
142
+ * Two `+Infinity` scores, or two `NaN` scores, tie and use complexity, then input order.
143
+ *
144
+ * Returns the **same object reference** as the chosen element of `scored`.
145
+ * Throws `ParetoFrontError` on an empty list, a non-finite loss or complexity,
146
+ * a non-finite `bestLossFactor`, a mode other than the three names, a mix of
147
+ * `null` and numeric scores, or a `'best'` filter that keeps no row.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { paretoFront, scoreFront, selectFrontModel } from '@danielsimonjr/mathts-functions';
152
+ * const front = paretoFront([
153
+ * { loss: 0.5, complexity: 1, item: 'A' },
154
+ * { loss: 0.1, complexity: 3, item: 'D-front' },
155
+ * ]);
156
+ * const scored = scoreFront(front);
157
+ * selectFrontModel(scored, 'accuracy').item; // 'D-front'
158
+ * selectFrontModel(scored, 'best').item; // 'D-front'
159
+ * selectFrontModel(scoreFront(front, { lossScale: 'linear' }), 'score').item; // null-score → accuracy fallback
160
+ * ```
161
+ */
162
+ export declare function selectFrontModel<T>(scored: readonly ScoredCandidate<T>[], mode?: 'accuracy' | 'score' | 'best', options?: {
163
+ bestLossFactor?: number;
164
+ }): ScoredCandidate<T>;
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AU,GAAG,OAAO,GAAG,MAAM,EACpC,OAAO,CAAC,EAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GACpC,eAAe,CAAC,CAAC,CAAC,CA8CpB"}
@@ -17,10 +17,16 @@ export declare const lgammaG: number;
17
17
  export declare const lgammaN: number;
18
18
  export declare const lgammaSeries: number[];
19
19
  /**
20
- * Return the natural logarithm of the gamma function of `n`.
20
+ * Return the natural logarithm of the gamma function of `n` (mathjs real-only contract).
21
21
  *
22
- * A negative `n` gives NaN, and 0 gives Infinity. A non-finite `n` is returned unchanged.
23
- * Values below 0.5 use the reflection formula. Other values use the Lanczos method.
22
+ * Every negative `n` returns `NaN` (including non-positive integers — not `+Infinity`).
23
+ * `0` returns `Infinity`. Non-finite `n` is returned unchanged. Values in `(0, 0.5)` use
24
+ * Euler's reflection with bare `sin(πn)` (positive on that interval). Lanczos `g = 5`
25
+ * applies for `n ≥ 0.5`. This is **not** `log|Γ(n)|`.
26
+ *
27
+ * For `log|Γ(x)|` with `+Infinity` at non-positive integer poles and finite values at
28
+ * negative non-integers (e.g. `lgamma(-0.5) = ln(2√π)`), use the typed `lgamma` export
29
+ * (`_lgamma` in `wasm/special/scalars.ts`).
24
30
  */
25
31
  export declare function lgammaNumber(n: number): number;
26
32
  export declare namespace lgammaNumber {
@@ -1 +1 @@
1
- {"version":3,"file":"probability.d.ts","sourceRoot":"","sources":["../../../src/plain/number/probability.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAkD7C;yBAlDe,WAAW;;;AAuD3B,eAAO,MAAM,MAAM,EAAE,MAAkB,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE,MAAM,EAM1B,CAAC;AAKF,eAAO,MAAM,SAAS,EAAE,MAA+B,CAAC;AAExD,eAAO,MAAM,OAAO,EAAE,MAAU,CAAC;AACjC,eAAO,MAAM,OAAO,EAAE,MAAU,CAAC;AAEjC,eAAO,MAAM,YAAY,EAAE,MAAM,EAGhC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAuB9C;yBAvBe,YAAY"}
1
+ {"version":3,"file":"probability.d.ts","sourceRoot":"","sources":["../../../src/plain/number/probability.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAkD7C;yBAlDe,WAAW;;;AAuD3B,eAAO,MAAM,MAAM,EAAE,MAAkB,CAAC;AAExC,eAAO,MAAM,MAAM,EAAE,MAAM,EAM1B,CAAC;AAKF,eAAO,MAAM,SAAS,EAAE,MAA+B,CAAC;AAExD,eAAO,MAAM,OAAO,EAAE,MAAU,CAAC;AACjC,eAAO,MAAM,OAAO,EAAE,MAAU,CAAC;AAEjC,eAAO,MAAM,YAAY,EAAE,MAAM,EAGhC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAuB9C;yBAvBe,YAAY"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shared BigNumber binomial product `C(total, choose)` via the short multiplicative
3
+ * loop (per-step `times` then `dividedBy` for exact integer arithmetic).
4
+ *
5
+ * Not exported from the package barrel; factory handlers keep their own validation.
6
+ */
7
+ /** Structural BigNumber shape used by legacy mathjs factory handlers. */
8
+ export interface BigNumberBinomialType {
9
+ constructor: BigNumberBinomialConstructor;
10
+ minus(n: BigNumberBinomialType | number): BigNumberBinomialType;
11
+ plus(n: BigNumberBinomialType | number): BigNumberBinomialType;
12
+ times(n: BigNumberBinomialType | number): BigNumberBinomialType;
13
+ dividedBy(n: BigNumberBinomialType | number): BigNumberBinomialType;
14
+ lt(n: BigNumberBinomialType | number): boolean;
15
+ gt(n: BigNumberBinomialType | number): boolean;
16
+ lte(n: BigNumberBinomialType | number): boolean;
17
+ gte(n: BigNumberBinomialType | number): boolean;
18
+ isInteger(): boolean;
19
+ }
20
+ interface BigNumberBinomialConstructor {
21
+ new (value: number): BigNumberBinomialType;
22
+ }
23
+ /** True when `n` is a non-negative integer BigNumber. */
24
+ export declare function isPositiveInteger(n: BigNumberBinomialType): boolean;
25
+ /**
26
+ * Binomial coefficient `C(total, choose)`. Same branch as the former factory
27
+ * loops: if `choose < total - choose`, iterate `i = 1 .. total - choose`
28
+ * multiplying `(choose + i) / i`; otherwise iterate `i = 1 .. choose`
29
+ * multiplying `(total - choose + i) / i`. Per-step order is
30
+ * `result.times(...).dividedBy(i)` so integer BigNumbers stay exact.
31
+ */
32
+ export declare function binomialProductBigNumber<T extends BigNumberBinomialType>(total: T, choose: T): T;
33
+ export {};
34
+ //# sourceMappingURL=bigint-binomial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bigint-binomial.d.ts","sourceRoot":"","sources":["../../src/probability/bigint-binomial.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,4BAA4B,CAAC;IAC1C,KAAK,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,qBAAqB,CAAC;IAChE,IAAI,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,qBAAqB,CAAC;IAC/D,KAAK,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,qBAAqB,CAAC;IAChE,SAAS,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,qBAAqB,CAAC;IACpE,EAAE,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,EAAE,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,OAAO,CAAC;IAC/C,GAAG,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,OAAO,CAAC;IAChD,GAAG,CAAC,CAAC,EAAE,qBAAqB,GAAG,MAAM,GAAG,OAAO,CAAC;IAChD,SAAS,IAAI,OAAO,CAAC;CACtB;AAED,UAAU,4BAA4B;IACpC,KAAK,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAAC;CAC5C;AAED,yDAAyD;AACzD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,qBAAqB,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAehG"}
@@ -1 +1 @@
1
- {"version":3,"file":"combinations.d.ts","sourceRoot":"","sources":["../../src/probability/combinations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAoB/D,UAAU,wBAAwB;IAChC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,kBAAkB,wFA6D9B,CAAC"}
1
+ {"version":3,"file":"combinations.d.ts","sourceRoot":"","sources":["../../src/probability/combinations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAO/D,UAAU,wBAAwB;IAChC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,kBAAkB,wFA2C9B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"combinationsWithRep.d.ts","sourceRoot":"","sources":["../../src/probability/combinationsWithRep.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAmB/D,UAAU,+BAA+B;IACvC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,yBAAyB,+FA8ErC,CAAC"}
1
+ {"version":3,"file":"combinationsWithRep.d.ts","sourceRoot":"","sources":["../../src/probability/combinationsWithRep.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAO/D,UAAU,+BAA+B;IACvC,KAAK,EAAE,aAAa,CAAC;CACtB;AAKD,eAAO,MAAM,yBAAyB,+FAgErC,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Evaluates many scalar trees over shared columns, on worker threads when asked to (M14).
3
+ *
4
+ * The caller opts in with `parallel`; without it every tree runs through
5
+ * {@link compileScalar} on the caller thread. With it, populations over at least
6
+ * {@link SCALAR_PARALLEL_MIN_ROWS} rows are compiled to tapes here and the tapes are
7
+ * evaluated by `scalar-batch.worker.js` through {@link WorkerPool.execute}, with a
8
+ * timeout that always applies. Both paths run the same `evaluateScalarTape`, so the values
9
+ * agree bit for bit.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import type { ScalarNode } from '@danielsimonjr/mathts-expression';
14
+ import { WorkerPool } from '@danielsimonjr/mathts-parallel';
15
+ import { type CompileScalarOptions, type ScalarBatchResult } from './scalar-compile.js';
16
+ /**
17
+ * Smallest row count that is sent to workers. 100 is the `n` from which the M3 tape beats
18
+ * the per-row interpreter in every run of the `scalar` benchmark (`docs/BENCHMARK_RESULTS.md`,
19
+ * section "`evaluateScalar` vs `compileScalar` (M3 batch evaluator) - 2026-10-25"). That
20
+ * table compares the two evaluators on the caller thread; it did not time a worker round
21
+ * trip, so this is the plan's floor for using the pool and not a measured break-even. The
22
+ * pool is opt-in, and nothing here claims a speed-up.
23
+ */
24
+ export declare const SCALAR_PARALLEL_MIN_ROWS = 100;
25
+ /** Timeout applied to every worker call when the caller does not choose one. */
26
+ export declare const DEFAULT_SCALAR_PARALLEL_TIMEOUT_MS = 30000;
27
+ /** URL of the built worker, a sibling of the module that contains this code. */
28
+ export declare function resolveScalarBatchWorkerScript(): string;
29
+ /** Starts the pool that {@link evaluateScalarPopulation} uses when it is not given one. */
30
+ export declare function createScalarBatchPool(): WorkerPool;
31
+ /** How to run a population on workers. */
32
+ export interface ScalarPopulationParallelOptions {
33
+ /**
34
+ * Milliseconds a worker call may take, queueing included, before it is cancelled, the
35
+ * worker replaced and the evaluation rejected. Must be positive: `0` would switch the
36
+ * pool's timeout off. Default 30000.
37
+ */
38
+ readonly timeoutMs?: number;
39
+ /** A pool to use, which the caller owns and terminates. Default: one for the call. */
40
+ readonly pool?: Pick<WorkerPool, 'execute'>;
41
+ }
42
+ export interface ScalarPopulationEvalItem {
43
+ /** Returned unchanged with the result. */
44
+ readonly index: number;
45
+ readonly node: ScalarNode;
46
+ readonly params?: ArrayLike<number>;
47
+ }
48
+ export interface EvaluateScalarPopulationOptions extends CompileScalarOptions {
49
+ readonly columns: readonly Float64Array[];
50
+ readonly items: readonly ScalarPopulationEvalItem[];
51
+ readonly parallel?: ScalarPopulationParallelOptions;
52
+ }
53
+ export interface ScalarPopulationEvalResult {
54
+ readonly index: number;
55
+ readonly batch: ScalarBatchResult;
56
+ }
57
+ /** Positive, finite timeout, or a `RangeError`: a zero would silently disable the guard. */
58
+ export declare function resolveParallelTimeout(timeoutMs: number | undefined): number;
59
+ /**
60
+ * Evaluates every item over `columns`, in the order given.
61
+ *
62
+ * Without `parallel`, or with fewer than {@link SCALAR_PARALLEL_MIN_ROWS} rows, each tree
63
+ * runs on the caller thread and no pool is touched. Otherwise the trees are compiled here,
64
+ * split into consecutive chunks, evaluated by the workers, and put back in item order by
65
+ * position. A pool that was not passed in is created for the call and terminated after it.
66
+ *
67
+ * @throws {RangeError} `parallel.timeoutMs` is not a positive finite number.
68
+ * @throws A worker error, a timeout, or a tree that cannot be compiled.
69
+ */
70
+ export declare function evaluateScalarPopulation(options: EvaluateScalarPopulationOptions): Promise<ScalarPopulationEvalResult[]>;
71
+ //# sourceMappingURL=scalar-batch-parallel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar-batch-parallel.d.ts","sourceRoot":"","sources":["../src/scalar-batch-parallel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,UAA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