@numero-uno-jpn/rstats 0.15.3 → 0.16.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 (285) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/README.ja.md +40 -33
  3. package/README.md +36 -28
  4. package/dist/chunks/chunk-2D2IQWUQ.js +2 -0
  5. package/dist/chunks/chunk-5UQCRBAG.js +2 -0
  6. package/dist/chunks/chunk-6CSTWA5E.js +2 -0
  7. package/dist/chunks/chunk-72Y3HZID.js +2 -0
  8. package/dist/chunks/chunk-BG2KLEHM.js +2 -0
  9. package/dist/chunks/chunk-CMEKBNHQ.js +2 -0
  10. package/dist/chunks/chunk-FLJNSXSW.js +2 -0
  11. package/dist/chunks/chunk-GM53LWSR.js +2 -0
  12. package/dist/chunks/chunk-JBCA56ZS.js +3 -0
  13. package/dist/chunks/chunk-K3RJAD2T.js +2 -0
  14. package/dist/chunks/chunk-KAZRWIB5.js +2 -0
  15. package/dist/chunks/chunk-KBVVIMXX.js +3 -0
  16. package/dist/chunks/chunk-N3SIFCZX.js +2 -0
  17. package/dist/chunks/chunk-QNNL7AZ3.js +2 -0
  18. package/dist/chunks/chunk-SC6CV4Z3.js +2 -0
  19. package/dist/chunks/chunk-SYWOBOTR.js +2 -0
  20. package/dist/chunks/chunk-URIO5LY5.js +2 -0
  21. package/dist/chunks/chunk-VTUGG2SV.js +2 -0
  22. package/dist/chunks/chunk-W26LRYOJ.js +2 -0
  23. package/dist/chunks/chunk-XHETEYVC.js +2 -0
  24. package/dist/chunks/{chunk-VLUL2HFW.js → chunk-YRZWONZB.js} +1 -1
  25. package/dist/chunks/chunk-ZGABZMWX.js +2 -0
  26. package/dist/data/grouping.js +20 -5
  27. package/dist/descriptive/basic.js +90 -8
  28. package/dist/descriptive/cov.js +12 -4
  29. package/dist/descriptive/dataFrames.d.ts +4 -2
  30. package/dist/descriptive/dataFrames.js +56 -18
  31. package/dist/descriptive/factanal.js +16 -7
  32. package/dist/descriptive/hist.d.ts +8 -5
  33. package/dist/descriptive/hist.js +71 -31
  34. package/dist/descriptive/missing.js +3 -1
  35. package/dist/descriptive/moments.js +72 -19
  36. package/dist/descriptive/omega.d.ts +1 -1
  37. package/dist/descriptive/omega.js +68 -9
  38. package/dist/descriptive/pivot.d.ts +21 -9
  39. package/dist/descriptive/pivot.js +161 -35
  40. package/dist/descriptive/quantile.js +2 -1
  41. package/dist/descriptive/rank.js +4 -1
  42. package/dist/descriptive/table.d.ts +3 -2
  43. package/dist/descriptive/table.js +24 -9
  44. package/dist/descriptive.js +2 -2
  45. package/dist/distributions/arcsine.js +19 -2
  46. package/dist/distributions/beta.js +24 -4
  47. package/dist/distributions/binomial.js +37 -14
  48. package/dist/distributions/bvnorm.js +11 -2
  49. package/dist/distributions/cauchy.js +12 -4
  50. package/dist/distributions/chisq.js +7 -3
  51. package/dist/distributions/exponential.js +5 -0
  52. package/dist/distributions/f.js +32 -17
  53. package/dist/distributions/gamma.js +27 -3
  54. package/dist/distributions/geometric.js +49 -13
  55. package/dist/distributions/hypergeometric.d.ts +5 -1
  56. package/dist/distributions/hypergeometric.js +93 -6
  57. package/dist/distributions/invgamma.js +2 -1
  58. package/dist/distributions/laplace.js +27 -6
  59. package/dist/distributions/logistic.js +4 -1
  60. package/dist/distributions/lognormal.js +8 -2
  61. package/dist/distributions/multinomial.js +54 -11
  62. package/dist/distributions/nbeta.js +62 -11
  63. package/dist/distributions/nchisq.js +30 -6
  64. package/dist/distributions/negbinomial.js +94 -17
  65. package/dist/distributions/normal.js +9 -4
  66. package/dist/distributions/nt.js +392 -17
  67. package/dist/distributions/pareto.js +4 -1
  68. package/dist/distributions/poisson.js +28 -3
  69. package/dist/distributions/signrank.js +7 -4
  70. package/dist/distributions/summary.js +450 -60
  71. package/dist/distributions/triangular.js +10 -5
  72. package/dist/distributions/tukey.js +5 -2
  73. package/dist/distributions/weibull.js +10 -0
  74. package/dist/distributions/wilcox.d.ts +9 -3
  75. package/dist/distributions/wilcox.js +155 -26
  76. package/dist/distributions.js +2 -2
  77. package/dist/htest/agreement.d.ts +3 -2
  78. package/dist/htest/agreement.js +76 -14
  79. package/dist/htest/ansariTest.d.ts +6 -1
  80. package/dist/htest/ansariTest.js +75 -8
  81. package/dist/htest/aov.d.ts +1 -1
  82. package/dist/htest/aov.js +48 -34
  83. package/dist/htest/binomTest.d.ts +5 -0
  84. package/dist/htest/binomTest.js +41 -17
  85. package/dist/htest/brunnerMunzelTest.d.ts +4 -3
  86. package/dist/htest/brunnerMunzelTest.js +7 -5
  87. package/dist/htest/chisqTest.d.ts +2 -1
  88. package/dist/htest/chisqTest.js +130 -43
  89. package/dist/htest/cor.d.ts +2 -1
  90. package/dist/htest/cor.js +17 -19
  91. package/dist/htest/core/ansari.d.ts +9 -0
  92. package/dist/htest/core/ansari.js +21 -1
  93. package/dist/htest/core/kolmogorov.d.ts +25 -0
  94. package/dist/htest/core/kolmogorov.js +123 -0
  95. package/dist/htest/core/mantelhaen.js +6 -4
  96. package/dist/htest/core/shapiro.d.ts +1 -1
  97. package/dist/htest/core/shapiro.js +5 -1
  98. package/dist/htest/dunnett.js +14 -5
  99. package/dist/htest/effectSize.d.ts +2 -0
  100. package/dist/htest/effectSize.js +91 -29
  101. package/dist/htest/fisherTest.d.ts +2 -2
  102. package/dist/htest/fisherTest.js +36 -18
  103. package/dist/htest/groups.d.ts +7 -0
  104. package/dist/htest/groups.js +21 -4
  105. package/dist/htest/ksTest.d.ts +3 -1
  106. package/dist/htest/ksTest.js +23 -2
  107. package/dist/htest/leveneTest.js +19 -3
  108. package/dist/htest/mantelhaenTest.js +125 -25
  109. package/dist/htest/mcnemarTest.js +32 -11
  110. package/dist/htest/multipleComparisons.d.ts +8 -1
  111. package/dist/htest/multipleComparisons.js +44 -21
  112. package/dist/htest/normalityTests.js +44 -10
  113. package/dist/htest/onewayTest.js +96 -5
  114. package/dist/htest/pAdjust.d.ts +3 -2
  115. package/dist/htest/pAdjust.js +38 -6
  116. package/dist/htest/pairwise.d.ts +1 -1
  117. package/dist/htest/pairwise.js +17 -15
  118. package/dist/htest/poissonTest.d.ts +1 -1
  119. package/dist/htest/poissonTest.js +111 -59
  120. package/dist/htest/polycor.js +27 -7
  121. package/dist/htest/power.d.ts +11 -1
  122. package/dist/htest/power.js +112 -8
  123. package/dist/htest/propTest.js +21 -4
  124. package/dist/htest/pwr.js +121 -24
  125. package/dist/htest/rankTests.js +29 -5
  126. package/dist/htest/tTest.js +44 -21
  127. package/dist/htest/trendTests.d.ts +7 -3
  128. package/dist/htest/trendTests.js +114 -20
  129. package/dist/htest/types.d.ts +5 -0
  130. package/dist/htest/types.js +7 -0
  131. package/dist/htest/varTest.js +45 -14
  132. package/dist/htest/wilcoxTest.js +114 -21
  133. package/dist/integrate/quadpack.js +27 -5
  134. package/dist/internal/covmat.d.ts +5 -0
  135. package/dist/internal/covmat.js +20 -0
  136. package/dist/internal/ddexp.d.ts +15 -1
  137. package/dist/internal/ddexp.js +59 -6
  138. package/dist/internal/discrete.d.ts +14 -0
  139. package/dist/internal/discrete.js +78 -5
  140. package/dist/internal/extremes.d.ts +9 -0
  141. package/dist/internal/extremes.js +24 -0
  142. package/dist/internal/fround.js +13 -4
  143. package/dist/internal/integer.d.ts +9 -0
  144. package/dist/internal/integer.js +12 -0
  145. package/dist/internal/invert.js +15 -2
  146. package/dist/internal/scaledInverse.d.ts +10 -0
  147. package/dist/internal/scaledInverse.js +22 -0
  148. package/dist/internal/seq.js +15 -2
  149. package/dist/internal/summary.d.ts +90 -0
  150. package/dist/internal/summary.js +458 -39
  151. package/dist/internal/uniroot.d.ts +7 -0
  152. package/dist/internal/uniroot.js +28 -3
  153. package/dist/linalg/basic.d.ts +3 -1
  154. package/dist/linalg/basic.js +51 -7
  155. package/dist/linalg/chol.js +4 -1
  156. package/dist/linalg/dot.d.ts +29 -0
  157. package/dist/linalg/dot.js +132 -0
  158. package/dist/linalg/eigen.d.ts +6 -1
  159. package/dist/linalg/eigen.js +71 -14
  160. package/dist/linalg/expm.d.ts +3 -2
  161. package/dist/linalg/expm.js +109 -15
  162. package/dist/linalg/kappa.js +58 -10
  163. package/dist/linalg/lu.d.ts +2 -1
  164. package/dist/linalg/lu.js +35 -5
  165. package/dist/linalg/matrix.d.ts +14 -0
  166. package/dist/linalg/matrix.js +24 -0
  167. package/dist/linalg/ops.js +60 -13
  168. package/dist/linalg/qr.d.ts +2 -1
  169. package/dist/linalg/qr.js +91 -23
  170. package/dist/linalg/schur.js +11 -3
  171. package/dist/linalg/solve.d.ts +6 -1
  172. package/dist/linalg/solve.js +147 -26
  173. package/dist/linalg/svd.d.ts +9 -2
  174. package/dist/linalg/svd.js +29 -11
  175. package/dist/linalg.js +2 -2
  176. package/dist/mixed.js +4 -4
  177. package/dist/models/anovaSequential.d.ts +16 -1
  178. package/dist/models/anovaSequential.js +124 -25
  179. package/dist/models/aovEz.js +140 -30
  180. package/dist/models/aovStrata.js +55 -22
  181. package/dist/models/carAnova.d.ts +1 -1
  182. package/dist/models/carAnova.js +83 -32
  183. package/dist/models/coxph.js +148 -66
  184. package/dist/models/estimable.d.ts +15 -0
  185. package/dist/models/estimable.js +68 -0
  186. package/dist/models/formula.d.ts +1 -1
  187. package/dist/models/formula.js +26 -8
  188. package/dist/models/glm.d.ts +35 -5
  189. package/dist/models/glm.js +398 -55
  190. package/dist/models/glmAnova.js +84 -13
  191. package/dist/models/glmConfint.d.ts +1 -1
  192. package/dist/models/glmConfint.js +115 -27
  193. package/dist/models/glmFamily.d.ts +10 -0
  194. package/dist/models/glmFamily.js +244 -40
  195. package/dist/models/lm.d.ts +12 -1
  196. package/dist/models/lm.js +235 -36
  197. package/dist/models/lmer.d.ts +20 -1
  198. package/dist/models/lmer.js +109 -27
  199. package/dist/models/lmerAnova.js +37 -4
  200. package/dist/models/lmerHypotheses.d.ts +6 -2
  201. package/dist/models/lmerHypotheses.js +14 -2
  202. package/dist/models/lmerTest.d.ts +9 -2
  203. package/dist/models/lmerTest.js +64 -19
  204. package/dist/models/mauchly.d.ts +4 -1
  205. package/dist/models/mauchly.js +34 -13
  206. package/dist/models/mixedStructure.js +6 -0
  207. package/dist/models/modelFrame.js +8 -2
  208. package/dist/models/modelMatrix.d.ts +3 -1
  209. package/dist/models/modelMatrix.js +40 -15
  210. package/dist/models/scaledTables.d.ts +8 -0
  211. package/dist/models/scaledTables.js +6 -0
  212. package/dist/models/survival.d.ts +6 -1
  213. package/dist/models/survival.js +67 -27
  214. package/dist/models/tiedTimes.d.ts +2 -0
  215. package/dist/models/tiedTimes.js +34 -0
  216. package/dist/numerics/deriv.d.ts +1 -1
  217. package/dist/numerics/deriv.js +64 -8
  218. package/dist/numerics/integrate.d.ts +9 -1
  219. package/dist/numerics/integrate.js +103 -16
  220. package/dist/numerics/interp.d.ts +8 -2
  221. package/dist/numerics/interp.js +352 -50
  222. package/dist/numerics/ode.js +55 -1
  223. package/dist/numerics.js +2 -2
  224. package/dist/optim/localmin.js +4 -0
  225. package/dist/optim/optim.d.ts +3 -1
  226. package/dist/optim/optim.js +80 -8
  227. package/dist/random/beta.js +53 -4
  228. package/dist/random/binomial.d.ts +14 -3
  229. package/dist/random/binomial.js +59 -24
  230. package/dist/random/continuous.js +33 -5
  231. package/dist/random/extra.js +42 -9
  232. package/dist/random/gamma.d.ts +4 -1
  233. package/dist/random/gamma.js +36 -8
  234. package/dist/random/hyper.js +9 -6
  235. package/dist/random/mt.js +17 -2
  236. package/dist/random/poisson.js +26 -3
  237. package/dist/random/r2dtable.d.ts +8 -1
  238. package/dist/random/r2dtable.js +24 -3
  239. package/dist/random/rank.d.ts +2 -0
  240. package/dist/random/rank.js +44 -4
  241. package/dist/random/sample.d.ts +12 -2
  242. package/dist/random/sample.js +57 -20
  243. package/dist/random/streams.js +4 -2
  244. package/dist/rstats.js +14 -14
  245. package/dist/special/besselIK.d.ts +12 -0
  246. package/dist/special/besselIK.js +168 -23
  247. package/dist/special/besselJY.d.ts +11 -1
  248. package/dist/special/besselJY.js +127 -19
  249. package/dist/special/besselSeries.d.ts +27 -0
  250. package/dist/special/besselSeries.js +45 -2
  251. package/dist/special/beta.js +4 -1
  252. package/dist/special/choose.js +17 -8
  253. package/dist/special/dd.js +122 -18
  254. package/dist/special/extra.js +14 -2
  255. package/dist/special/gamma.js +11 -2
  256. package/dist/special/incbet.js +30 -4
  257. package/dist/special/incbetTemme.d.ts +7 -0
  258. package/dist/special/incbetTemme.js +45 -12
  259. package/dist/special/loader.d.ts +1 -1
  260. package/dist/special/loader.js +117 -20
  261. package/dist/special/log1pmx.js +4 -0
  262. package/dist/special.js +2 -2
  263. package/dist/tests.js +11 -11
  264. package/llms.txt +12 -6
  265. package/package.json +1 -1
  266. package/dist/chunks/chunk-3THFTB36.js +0 -2
  267. package/dist/chunks/chunk-3TSWYE5L.js +0 -2
  268. package/dist/chunks/chunk-3WPU6LGK.js +0 -2
  269. package/dist/chunks/chunk-5ITR67MB.js +0 -2
  270. package/dist/chunks/chunk-5NRFU6F6.js +0 -2
  271. package/dist/chunks/chunk-E2LCSVQV.js +0 -2
  272. package/dist/chunks/chunk-FCNVTIPJ.js +0 -2
  273. package/dist/chunks/chunk-FKAKALOZ.js +0 -2
  274. package/dist/chunks/chunk-HD73UKPT.js +0 -2
  275. package/dist/chunks/chunk-IUULP3LE.js +0 -2
  276. package/dist/chunks/chunk-JQG3YQOC.js +0 -2
  277. package/dist/chunks/chunk-KT66SB7R.js +0 -2
  278. package/dist/chunks/chunk-MAUAOQG3.js +0 -2
  279. package/dist/chunks/chunk-MDYE7QP2.js +0 -2
  280. package/dist/chunks/chunk-NM3Z2UBQ.js +0 -2
  281. package/dist/chunks/chunk-PMJI5QO6.js +0 -3
  282. package/dist/chunks/chunk-UF7KOTHF.js +0 -3
  283. package/dist/chunks/chunk-UOE57JGT.js +0 -2
  284. package/dist/chunks/chunk-USPEBXSR.js +0 -2
  285. package/dist/chunks/chunk-ZIX7NYQF.js +0 -2
@@ -9,14 +9,29 @@
9
9
  // sum runs unscaled while it stays finite (so its results are unchanged), and once it would overflow it continues on
10
10
  // the values scaled by a power of 2 (exact) and is scaled back at the end. A mean whose sum overflows a double is the
11
11
  // mean of the scaled values, scaled back (R averages x[i] / n in that case, which gives the mean without overflow).
12
+ //
13
+ // Moments (deviations, variances, covariances, sums of squares) follow these rules, so that no statistic depends on
14
+ // the units of the data:
15
+ // 1. Scale first, centre afterwards: the data are divided by a power of 2, 2^-k, that brings the largest absolute
16
+ // value into [1, 2) (exact), and the mean, deviations and cross-products are computed on the scaled values. A
17
+ // deviation x - mean can then neither overflow (values near both ends of the range) nor underflow.
18
+ // 2. Quantities without units (t, F, chi-squared, correlations, effect sizes, ratios, degrees of freedom, p-values)
19
+ // are computed in the scaled coordinates.
20
+ // 3. Quantities with units are scaled back only for output: means, differences, standard errors and intervals by
21
+ // 2^k, sums of squares and variances by 2^2k (ldexp). Nothing without units is computed from scaled-back values.
22
+ // 4. In the ordinary range the results are those of the unscaled formulas (scaling by a power of 2 changes no bit).
23
+ // See centered, groupMoments, pairedDifferences, standardize and scaleToUnit.
12
24
  import { ddAdd, ddDivNum, ddMul, ddSub } from "../special/dd.js";
25
+ import { isDoubleDouble } from "../special/dd.js";
26
+ import { roundScaled, splitDouble } from "../linalg/dot.js";
13
27
  export function wideSum() {
14
28
  return { s: [0, 0], shift: 0 };
15
29
  }
16
30
  /**
17
31
  * Power of 2 by which the sums of n finite values are scaled once they overflow: the scaled sum stays below 2^992,
18
32
  * so that it can also be divided in double-double (whose splitting overflows above about 2^996). Values below
19
- * 2^(shift - 1022) lose bits when scaled, which cannot matter next to a sum beyond the double range
33
+ * 2^(shift - 1022) lose bits when scaled, which matters only where the large values later cancel (sum() and
34
+ * meanDD() bound such losses and then sum exactly, #374 and #473)
20
35
  */
21
36
  function overflowShift(n) {
22
37
  return 32 + Math.ceil(Math.log2(Math.max(n, 1)));
@@ -44,6 +59,20 @@ export function ldexp(v, k) {
44
59
  const a = Math.trunc(k / 2);
45
60
  return v * 2 ** a * 2 ** (k - a);
46
61
  }
62
+ /** v 2^k for any integer k (beyond the +-2046 of ldexp), in steps of at most 2^1000 */
63
+ export function ldexpWide(v, k) {
64
+ let x = v;
65
+ let r = k;
66
+ while (r > 1000) {
67
+ x *= 2 ** 1000;
68
+ r -= 1000;
69
+ }
70
+ while (r < -1000) {
71
+ x *= 2 ** -1000;
72
+ r += 1000;
73
+ }
74
+ return x * 2 ** r;
75
+ }
47
76
  /** Sum of values that are not all finite, as in double arithmetic (NaN propagates, Inf and -Inf give NaN) */
48
77
  function nonFiniteSum(x) {
49
78
  let s = 0;
@@ -58,23 +87,93 @@ export function meanDD(x) {
58
87
  // With Inf present the double-double sum becomes NaN; the mean is the (infinite or NaN) sum divided by n
59
88
  if (!x.every(Number.isFinite))
60
89
  return [nonFiniteSum(x) / n, 0];
61
- const acc = wideSum();
62
- for (const v of x)
63
- wideSumAdd(acc, v, n);
64
- if (acc.shift !== 0) {
65
- // The sum overflows a double: the mean of the values scaled by a power of 2, scaled back
66
- const k = overflowShift(n);
67
- const f = 2 ** -k;
68
- const m = meanDD(x.map((v) => v * f));
69
- return [ldexp(m[0], k), ldexp(m[1], k)];
70
- }
71
- const s = acc.s;
90
+ if (!isDoubleDouble()) {
91
+ const acc = wideSum();
92
+ for (const v of x)
93
+ wideSumAdd(acc, v, n);
94
+ return acc.shift !== 0 ? scaledMean(x) : meanFromSum(x, acc.s);
95
+ }
96
+ // The sum loses a third band of magnitudes as sum() did (#374): mean([1e308, 1e100, 1, -1e308, -1e100]) was 0 and
97
+ // mean([1e20, 1e3, 1e-10, -1e20, -1e3]) 2.0009e-11 (#473). With the bound on what the sum lost, the mean is formed
98
+ // exactly where that could move it across a rounding boundary; otherwise it has the bits of the double-double steps
99
+ const b = boundedSum(x);
100
+ const m = b.shift !== 0 ? scaledMean(x) : meanFromSum(x, [b.hi, b.lo]);
101
+ if (b.lost > 0 && mayMissMean(b, m, n))
102
+ return exactMean(x);
103
+ return m;
104
+ }
105
+ /** The mean of values whose sum overflows a double: the mean of the values scaled by a power of 2, scaled back */
106
+ function scaledMean(x) {
107
+ const k = overflowShift(x.length);
108
+ const f = 2 ** -k;
109
+ const m = meanDD(x.map((v) => v * f));
110
+ return [ldexp(m[0], k), ldexp(m[1], k)];
111
+ }
112
+ /**
113
+ * Whether the true mean may round to another double than m[0]: it lies within lost (1 + n 2^-52) / n of s / n for the
114
+ * double-double sum s = (hi + lo) 2^shift (plus the error of the division), and m lies within abs(m - s / n) of it.
115
+ * Computed in units of 2^shift; with shift != 0 also where m is near the subnormals there
116
+ */
117
+ function mayMissMean(b, m, n) {
118
+ const r = m[0];
119
+ if (!Number.isFinite(r))
120
+ return true;
121
+ const rs = ldexp(r, -b.shift);
122
+ if (b.shift !== 0 && Math.abs(rs) < 2 ** -1000)
123
+ return true;
124
+ const q = ddDivNum([b.hi, b.lo], n);
125
+ const d = ddSub([rs, ldexp(m[1], -b.shift)], q);
126
+ const bound = ((b.lost * (1 + n * 2 ** -52)) / n + Math.abs(d[0] + d[1]) + Math.abs(q[0]) * 2 ** -100) * (1 + 2 ** -50);
127
+ return mayRoundOtherwise(rs, ldexp(m[1], -b.shift), rs, bound, 0);
128
+ }
129
+ /**
130
+ * The mean of finite values from their exact sum (integers times 2^-1074 in BigInt): the quotient by n to 128 bits
131
+ * beyond its leading bit, with a sticky bit for a remainder, rounded once for the high part and once more for the low
132
+ */
133
+ function exactMean(x) {
134
+ let low = Infinity;
135
+ const parts = [];
136
+ for (const v of x) {
137
+ if (v === 0)
138
+ continue;
139
+ const p = splitDouble(v);
140
+ parts.push(p);
141
+ if (p[1] < low)
142
+ low = p[1];
143
+ }
144
+ let acc = 0n;
145
+ for (const [m, e] of parts)
146
+ acc += m << BigInt(e - low);
147
+ if (acc === 0n)
148
+ return [0, 0];
149
+ const nb = BigInt(x.length);
150
+ const extra = 128 + x.length.toString(2).length;
151
+ const num = acc << BigInt(extra);
152
+ let q = num / nb;
153
+ let e = low - extra;
154
+ if (num % nb !== 0n) {
155
+ q = 2n * q + (acc < 0n ? -1n : 1n);
156
+ e -= 1;
157
+ }
158
+ const hi = roundScaled(q, e);
159
+ if (!Number.isFinite(hi) || hi === 0)
160
+ return [hi, 0];
161
+ const [mh, eh] = splitDouble(hi);
162
+ return [hi, roundScaled(q - (mh << BigInt(eh - e)), e)];
163
+ }
164
+ /** The double-double mean from the double-double sum s of x (finite, not overflowing): s / n corrected by the deviations */
165
+ function meanFromSum(x, s) {
166
+ const n = x.length;
72
167
  const m = ddDivNum(s, n);
73
168
  if (!Number.isFinite(m[0]))
74
169
  return [s[0] / n, 0];
75
170
  let t = [0, 0];
76
171
  for (const v of x)
77
172
  t = ddAdd(t, ddSub([v, 0], m));
173
+ // A deviation v - m beyond the double range (values near both ends of it) leaves the correction infinite: m, the
174
+ // double-double quotient of the exact sum, is kept
175
+ if (!Number.isFinite(t[0]))
176
+ return m;
78
177
  return ddAdd(m, ddDivNum(t, n));
79
178
  }
80
179
  export function mean(x) {
@@ -84,39 +183,186 @@ export function mean(x) {
84
183
  export function variance(x) {
85
184
  return covariance(x, x);
86
185
  }
186
+ /**
187
+ * Sample standard deviation from the scaled deviations: sqrt(sum d^2 / (n - 1)) in the coordinates 2^-k, times 2^k.
188
+ * The same bits as sqrt(variance(x)) where the variance is a normal number (the square root of 4^k y is 2^k sqrt(y)),
189
+ * and the right value where it overflows or underflows (sd of c(-1e308, -1e308, -1e308, -1e308, 1.5e308) is 1.118e308
190
+ * while its variance is 1.25e616). x contains no NaN
191
+ */
192
+ export function standardDeviation(x) {
193
+ const n = x.length;
194
+ if (n < 2)
195
+ return NaN;
196
+ const c = centered(x);
197
+ if (c === undefined)
198
+ return NaN;
199
+ return ldexp(Math.sqrt(ddDivNum(crossSum(c.d, c.d), n - 1)[0]), c.k);
200
+ }
87
201
  /** Unbiased covariance. x and y have the same length and contain no NaN */
88
202
  export function covariance(x, y) {
89
203
  const n = x.length;
90
204
  if (n < 2)
91
205
  return NaN;
92
- const mx = meanDD(x);
93
- const my = x === y ? mx : meanDD(y);
94
- if (!Number.isFinite(mx[0]) || !Number.isFinite(my[0]))
206
+ const cx = centered(x);
207
+ const cy = x === y ? cx : centered(y);
208
+ if (cx === undefined || cy === undefined)
95
209
  return NaN;
96
- // Scale the deviations by a power of 2 to be near 1 before multiplying (so products of values around 1e200 do not
97
- // overflow and products around 1e-200 do not underflow to 0; powers of 2 add no rounding error)
98
- const dx = x.map((v) => ddSub([v, 0], mx));
99
- const dy = x === y ? dx : y.map((v) => ddSub([v, 0], my));
100
- const kx = scaleExponent(dx);
101
- const ky = x === y ? kx : scaleExponent(dy);
102
- const fx = 2 ** -kx;
103
- const fy = 2 ** -ky;
210
+ const s = crossSum(cx.d, cy.d);
211
+ // Scaled back by 2^(kx + ky) at once: by 2^kx first could overflow (or underflow) where 2^ky would bring it back,
212
+ // and cov(x, y) would then differ from cov(y, x)
213
+ return ldexp(ddDivNum(s, n - 1)[0], cx.k + cy.k);
214
+ }
215
+ /** Binary exponent k that brings the largest finite absolute value into [1, 2) (0 when there is none) */
216
+ function unitExponent(groups) {
217
+ let m = 0;
218
+ for (const g of groups)
219
+ for (const v of g)
220
+ if (Number.isFinite(v))
221
+ m = Math.max(m, Math.abs(v));
222
+ return m === 0 ? 0 : Math.floor(Math.log2(m));
223
+ }
224
+ /** sum a[i] b[i] in double-double */
225
+ function crossSum(a, b) {
104
226
  let s = [0, 0];
105
- for (let i = 0; i < n; i++) {
106
- const a = [dx[i][0] * fx, dx[i][1] * fx];
107
- const b = [dy[i][0] * fy, dy[i][1] * fy];
108
- s = ddAdd(s, ddMul(a, b));
227
+ for (let i = 0; i < a.length; i++)
228
+ s = ddAdd(s, ddMul(a[i], b[i]));
229
+ return s;
230
+ }
231
+ /**
232
+ * The deviations from the mean of x scaled by 2^-k (the scaling first, see the rules above), in double-double, with k
233
+ * and the scaled mean. undefined when x has an infinite value (the mean is not finite)
234
+ */
235
+ export function centered(x) {
236
+ if (!x.every(Number.isFinite))
237
+ return undefined;
238
+ const k = unitExponent([x]);
239
+ const xs = k === 0 ? x : x.map((v) => ldexp(v, -k));
240
+ const mean = meanDD(xs);
241
+ return { d: xs.map((v) => ddSub([v, 0], mean)), k, mean };
242
+ }
243
+ /**
244
+ * (x - mean) / sd, from the scaled deviations (no overflow or underflow at any scale). NaN values when the standard
245
+ * deviation is 0 or x has fewer than 2 values or an infinite one
246
+ */
247
+ export function standardize(x) {
248
+ const c = x.length < 2 ? undefined : centered(x);
249
+ if (c === undefined)
250
+ return x.map(() => NaN);
251
+ const sd = Math.sqrt(ddDivNum(crossSum(c.d, c.d), x.length - 1)[0]);
252
+ return c.d.map((v) => (sd > 0 ? v[0] / sd : NaN));
253
+ }
254
+ export function groupMoments(groups) {
255
+ const { groups: scaled, k } = scaleToUnit(groups);
256
+ const n = scaled.map((g) => g.length);
257
+ const all = scaled.flat();
258
+ const grand = all.length === 0 ? [NaN, 0] : meanDD(all);
259
+ const mean = [];
260
+ const ss = [];
261
+ const variance = [];
262
+ let ssb = [0, 0];
263
+ let ssw = [0, 0];
264
+ for (const g of scaled) {
265
+ if (g.length === 0) {
266
+ mean.push(NaN);
267
+ ss.push(NaN);
268
+ variance.push(NaN);
269
+ continue;
270
+ }
271
+ const m = meanDD(g);
272
+ let s = [0, 0];
273
+ for (const v of g) {
274
+ const e = ddSub([v, 0], m);
275
+ s = ddAdd(s, ddMul(e, e));
276
+ }
277
+ const d = ddSub(m, grand);
278
+ ssb = ddAdd(ssb, ddMul(ddMul(d, d), [g.length, 0]));
279
+ ssw = ddAdd(ssw, s);
280
+ mean.push(m[0]);
281
+ ss.push(s[0]);
282
+ // divided in double-double, as variance() does
283
+ variance.push(g.length > 1 ? ddDivNum(s, g.length - 1)[0] : NaN);
284
+ }
285
+ return {
286
+ k,
287
+ groups: scaled,
288
+ n,
289
+ mean,
290
+ ss,
291
+ variance,
292
+ grandMean: grand[0],
293
+ ssBetween: ssb[0],
294
+ ssWithin: ssw[0],
295
+ };
296
+ }
297
+ /** x - y for paired values, both scaled by one 2^-k first (so the differences cannot overflow), with k */
298
+ export function pairedDifferences(x, y) {
299
+ const { groups, k } = scaleToUnit([x, y]);
300
+ const [a, b] = groups;
301
+ return { d: a.map((v, i) => v - b[i]), k };
302
+ }
303
+ /**
304
+ * Satterthwaite's degrees of freedom (sum w)^2 / sum(w^2 / df) of a sum of independent variance estimates w with
305
+ * degrees of freedom df. The w are scaled by a power of 2 first (no rounding), so the squares neither overflow nor
306
+ * underflow when the w do not; the ratio does not depend on the units of the data. The form of irr's icc (the same
307
+ * order of operations); tTest, cohensD and gamesHowellTest use R's forms below and this only where those are not finite
308
+ */
309
+ export function satterthwaiteDf(w, df) {
310
+ let m = 0;
311
+ for (const v of w)
312
+ m = Math.max(m, Math.abs(v));
313
+ const k = m === 0 || !Number.isFinite(m) ? 0 : Math.floor(Math.log2(m));
314
+ let num = 0;
315
+ let den = 0;
316
+ for (let i = 0; i < w.length; i++) {
317
+ const a = ldexp(w[i], -k);
318
+ num += a;
319
+ den += (a * a) / df[i];
109
320
  }
110
- const v = ddDivNum(s, n - 1)[0];
111
- // Multiply by 2^(kx + ky) in two steps (a single step can overflow or underflow to 0)
112
- return v * 2 ** kx * 2 ** ky;
321
+ return (num * num) / den;
113
322
  }
114
- /** Binary exponent of the largest absolute deviation (0 if it is 0) */
115
- function scaleExponent(d) {
323
+ /** An even exponent 2j with max abs(w) / 2^2j in [1, 4) (0 for all w 0 or a non-finite one): sqrt then scales exactly */
324
+ function evenExponent(w) {
116
325
  let m = 0;
117
- for (const v of d)
118
- m = Math.max(m, Math.abs(v[0]));
119
- return m === 0 || !Number.isFinite(m) ? 0 : Math.max(-1022, Math.floor(Math.log2(m)));
326
+ for (const v of w)
327
+ m = Math.max(m, Math.abs(v));
328
+ if (m === 0 || !Number.isFinite(m))
329
+ return 0;
330
+ const e = Math.floor(Math.log2(m));
331
+ return e - (((e % 2) + 2) % 2);
332
+ }
333
+ /**
334
+ * Welch's degrees of freedom in the form of R's t.test and effectsize: se^4 / sum(se_i^4 / df_i) with se_i = sqrt(w_i)
335
+ * and se = sqrt(sum se_i^2), on the w scaled by an even power of 2 (exact, also through sqrt, so the same bits as R
336
+ * wherever R's terms are in range, and no overflow). {@link satterthwaiteDf} where that is not finite and positive
337
+ * (revision of review 2)
338
+ */
339
+ export function satterthwaiteDfSe(w, df) {
340
+ const k = evenExponent(w);
341
+ let s2 = 0;
342
+ let den = 0;
343
+ for (let i = 0; i < w.length; i++) {
344
+ const se = Math.sqrt(ldexp(w[i], -k));
345
+ s2 += se ** 2;
346
+ den += se ** 4 / df[i];
347
+ }
348
+ const r = Math.sqrt(s2) ** 4 / den;
349
+ return Number.isFinite(r) && r > 0 ? r : satterthwaiteDf(w, df);
350
+ }
351
+ /**
352
+ * Welch's degrees of freedom in the form of PMCMRplus's gamesHowellTest: A^2 / sum(s2_i^2 / (n_i^2 (n_i - 1))) with
353
+ * A = sum s2_i / n_i, for the group variances s2 and sizes n, scaled as {@link satterthwaiteDfSe} (revision of review 2)
354
+ */
355
+ export function satterthwaiteDfPM(s2, n) {
356
+ const k = evenExponent(s2);
357
+ let a = 0;
358
+ let den = 0;
359
+ for (let i = 0; i < s2.length; i++) {
360
+ const v = ldexp(s2[i], -k);
361
+ a += v / n[i];
362
+ den += v ** 2 / (n[i] ** 2 * (n[i] - 1));
363
+ }
364
+ const r = a ** 2 / den;
365
+ return Number.isFinite(r) && r > 0 ? r : satterthwaiteDf(s2.map((v, i) => v / n[i]), n.map((m) => m - 1));
120
366
  }
121
367
  /**
122
368
  * Sum (accumulated in double-double without overflow, then rounded; ±Infinity beyond the double range). With
@@ -125,10 +371,124 @@ function scaleExponent(d) {
125
371
  export function sum(x) {
126
372
  if (!x.every(Number.isFinite))
127
373
  return nonFiniteSum(x);
128
- const acc = wideSum();
129
- for (const v of x)
130
- wideSumAdd(acc, v, x.length);
131
- return wideSumValue(acc);
374
+ if (!isDoubleDouble()) {
375
+ const acc = wideSum();
376
+ for (const v of x)
377
+ wideSumAdd(acc, v, x.length);
378
+ return wideSumValue(acc);
379
+ }
380
+ // The double-double keeps two components, so a third band of magnitudes is rounded away when it is added to the
381
+ // low one: with the bands later cancelling, sum([1e308, 1e100, 1, -1e308, -1e100]) was 0 and
382
+ // sum([1e20, 1e3, 1e-10, -1e20, -1e3]) 1.0004e-10 (#374). The value is that of wideSumAdd; only where the lost amount
383
+ // could move it across a rounding boundary is the sum formed exactly instead (rare: the losses are zero or about
384
+ // 2^-106 of the partial sums)
385
+ const { hi, lo, shift, lost } = boundedSum(x);
386
+ const r = hi + lo;
387
+ if (lost > 0 && mayRoundOtherwise(hi, lo, r, lost * (1 + x.length * 2 ** -52), shift))
388
+ return exactSum(x);
389
+ return ldexp(r, shift);
390
+ }
391
+ /**
392
+ * The double-double sum of finite values with the steps of wideSumAdd (ddAdd of [v, 0]) written out, so that its
393
+ * value (hi + lo) 2^shift has the same bits, and an upper bound `lost` (in units of 2^shift) on what those steps
394
+ * rounded away (#374)
395
+ */
396
+ function boundedSum(x) {
397
+ const n = x.length;
398
+ let hi = 0;
399
+ let lo = 0;
400
+ let shift = 0;
401
+ let f = 1;
402
+ let lost = 0;
403
+ for (const x0 of x) {
404
+ let v = x0;
405
+ if (shift !== 0) {
406
+ v = x0 * f;
407
+ // (a value below 2^(shift - 1022) is rounded onto the subnormals when scaled)
408
+ if (v / f !== x0)
409
+ lost += 2 ** -1074;
410
+ }
411
+ let s1 = hi + v;
412
+ let bb2 = s1 - hi;
413
+ let e3 = hi - (s1 - bb2) + (v - bb2);
414
+ let u7 = e3 + (lo + 0);
415
+ let s8 = s1 + u7;
416
+ let e9 = u7 - (s8 - s1);
417
+ let s11 = s8 + (e9 + 0);
418
+ let e12 = e9 + 0 - (s11 - s8);
419
+ if (shift === 0 && !(Number.isFinite(s1) && Number.isFinite(s11) && Number.isFinite(e12))) {
420
+ // the sum would overflow: from here on, the values scaled by 2^-shift (as wideSumAdd)
421
+ shift = overflowShift(n);
422
+ f = 2 ** -shift;
423
+ const h = hi * f;
424
+ const l = lo * f;
425
+ if (h / f !== hi)
426
+ lost += 2 ** -1074;
427
+ if (l / f !== lo)
428
+ lost += 2 ** -1074;
429
+ hi = h;
430
+ lo = l;
431
+ v = x0 * f;
432
+ if (v / f !== x0)
433
+ lost += 2 ** -1074;
434
+ s1 = hi + v;
435
+ bb2 = s1 - hi;
436
+ e3 = hi - (s1 - bb2) + (v - bb2);
437
+ u7 = e3 + (lo + 0);
438
+ s8 = s1 + u7;
439
+ e9 = u7 - (s8 - s1);
440
+ s11 = s8 + (e9 + 0);
441
+ e12 = e9 + 0 - (s11 - s8);
442
+ }
443
+ // the rounding of u7 = e3 + lo is the step that loses; the next two are exact where |s1| >= |u7| or s1 = 0
444
+ const bb = u7 - e3;
445
+ lost += Math.abs(e3 - (u7 - bb) + (lo - bb));
446
+ if (Math.abs(u7) > Math.abs(s1) && s1 !== 0)
447
+ lost += (Math.abs(u7) + Math.abs(s1)) * 2 ** -51;
448
+ hi = s11;
449
+ lo = e12;
450
+ }
451
+ return { hi, lo, shift, lost };
452
+ }
453
+ /**
454
+ * Whether a true sum within lost of hi + lo (in units of 2^shift) may round to another double than r = fl(hi + lo):
455
+ * lost reaches the distance from hi + lo to the nearest rounding boundary of r (half the gap below a power of 2, as a
456
+ * bound). With shift != 0 also where scaling back may round again (a result near the subnormals)
457
+ */
458
+ function mayRoundOtherwise(hi, lo, r, lost, shift) {
459
+ if (!Number.isFinite(r))
460
+ return true;
461
+ const a = Math.abs(r);
462
+ if (shift !== 0 && a < 2 ** -1000)
463
+ return true;
464
+ const offset = Math.abs(hi - r + lo); // exact: r = fl(hi + lo) with |lo| at most half an ulp of hi
465
+ let gap;
466
+ if (a < 2 ** -1022)
467
+ gap = 2 ** -1074;
468
+ else {
469
+ const [m, e] = splitDouble(a);
470
+ gap = 2 ** e;
471
+ if (m === 1n << 52n)
472
+ gap /= 2;
473
+ }
474
+ return lost >= gap / 2 - offset;
475
+ }
476
+ /** The sum of finite values formed exactly (integers times 2^-1074 in BigInt) and rounded once */
477
+ function exactSum(x) {
478
+ let low = Infinity;
479
+ const parts = [];
480
+ for (const v of x) {
481
+ if (v === 0)
482
+ continue;
483
+ const p = splitDouble(v);
484
+ parts.push(p);
485
+ if (p[1] < low)
486
+ low = p[1];
487
+ }
488
+ let acc = 0n;
489
+ for (const [m, e] of parts)
490
+ acc += m << BigInt(e - low);
491
+ return roundScaled(acc, low);
132
492
  }
133
493
  /**
134
494
  * Ranks (ties get the average rank, R's rank(ties.method = "average")). x contains no NaN.
@@ -184,3 +544,62 @@ export function completePairs(x, y) {
184
544
  }
185
545
  return [a, b];
186
546
  }
547
+ const MIN_NORMAL = 2 ** -1022;
548
+ /**
549
+ * d^2 / e, as for a Pearson chi-squared term. When d^2 overflows (or loses precision below the normal range) although
550
+ * the quotient is representable, it is formed as (d / sqrt(e))^2 instead
551
+ */
552
+ export function squareOver(d, e) {
553
+ const d2 = d * d;
554
+ if (d2 < Infinity && (d2 >= MIN_NORMAL || d === 0))
555
+ return d2 / e;
556
+ const z = d / Math.sqrt(e);
557
+ return z * z;
558
+ }
559
+ /**
560
+ * a b / n, as for an expected count from two margins. When the product overflows, underflows or is subnormal (with a
561
+ * and b not 0), the three are scaled to [1, 2) by powers of 2 and the exponents added back at the end
562
+ */
563
+ export function productOver(a, b, n) {
564
+ const ab = a * b;
565
+ if (a === 0 || b === 0 || !Number.isFinite(a) || !Number.isFinite(b) || !Number.isFinite(n))
566
+ return ab / n;
567
+ if (Math.abs(ab) >= MIN_NORMAL && Math.abs(ab) < Infinity)
568
+ return ab / n;
569
+ const ka = unitExponent([[a]]);
570
+ const kb = unitExponent([[b]]);
571
+ const kn = unitExponent([[n]]);
572
+ return ldexp((ldexp(a, -ka) * ldexp(b, -kb)) / ldexp(n, -kn), ka + kb - kn);
573
+ }
574
+ /**
575
+ * Data scaled by a power of 2, 2^-k, so that the largest finite absolute value is in [1, 2) (k = 0 when there is
576
+ * none). The scaling adds no rounding error, so statistics that do not depend on the units (t, F, chi-squared,
577
+ * ratios of variances, degrees of freedom) come out as from the original data, but their squares and variances
578
+ * can no longer overflow or underflow. Quantities with units are multiplied back by 2^k (see ldexp)
579
+ */
580
+ export function scaleToUnit(groups) {
581
+ const k = unitExponent(groups);
582
+ return { groups: groups.map((g) => (k === 0 ? Array.from(g) : g.map((v) => ldexp(v, -k)))), k };
583
+ }
584
+ /**
585
+ * Euclidean norm sqrt(sum x_i^2): the plain sum where it is in range (so the value is unchanged there), otherwise from
586
+ * the values divided by the largest |x_i| (as BLAS's dnrm2), so that squares of values around 1e200 or 1e-200 neither
587
+ * overflow nor underflow
588
+ */
589
+ export function norm2(x) {
590
+ let s = 0;
591
+ for (const v of x)
592
+ s += v * v;
593
+ if (s < Infinity && s >= MIN_NORMAL)
594
+ return Math.sqrt(s);
595
+ let m = 0;
596
+ for (const v of x)
597
+ m = Math.max(m, Math.abs(v));
598
+ // all 0, or an infinite value (NaN if there is also a NaN)
599
+ if (!(m > 0 && m < Infinity))
600
+ return Number.isNaN(s) ? NaN : m;
601
+ let t = 0;
602
+ for (const v of x)
603
+ t += (v / m) ** 2;
604
+ return m * Math.sqrt(t);
605
+ }
@@ -9,3 +9,10 @@ export interface UnirootOptions {
9
9
  export declare const UNIROOT_TOL: number;
10
10
  /** f(lower) and f(upper) must differ in sign. Returns one root */
11
11
  export declare function uniroot(f: (x: number) => number, lower: number, upper: number, opts?: UnirootOptions): number;
12
+ /**
13
+ * Root in psi > 0 of a function monotone in psi (an odds ratio), given whether it lies below 1: solved in u = log psi
14
+ * to the precision of the doubles, from a bracket widened from u = 0 by doubling. 0 or Infinity when f does not change
15
+ * sign within the doubles. (R's fisher.test solves on psi in [0, 1] or 1/psi in [eps, 1] with the absolute tolerance
16
+ * eps^0.25, which leaves its estimates 1e-6 off and its limits up to several percent, or at the end 1/eps)
17
+ */
18
+ export declare function logScaleRoot(f: (psi: number) => number, belowOne: boolean): number;
@@ -1,7 +1,7 @@
1
1
  // Univariate root finding for internal callers (the confidence limits and estimates of fisherTest, wilcoxTest and
2
- // mantelhaenTest): a thin wrapper around the public uniroot (src/numerics/integrate.ts, Brent's method with R's
3
- // conventions), returning just the root.
4
- import { uniroot as unirootFull } from "../numerics/integrate.js";
2
+ // mantelhaenTest): a thin wrapper around the public uniroot's body unirootCore (src/numerics/integrate.ts, Brent's method with R's
3
+ // conventions), returning just the root, and the root of an odds ratio on the log scale (logScaleRoot).
4
+ import { unirootCore as unirootFull } from "../numerics/integrate.js";
5
5
  export const UNIROOT_TOL = Math.pow(Number.EPSILON, 0.25);
6
6
  /** f(lower) and f(upper) must differ in sign. Returns one root */
7
7
  export function uniroot(f, lower, upper, opts = {}) {
@@ -12,3 +12,28 @@ export function uniroot(f, lower, upper, opts = {}) {
12
12
  options.fUpper = opts.fUpper;
13
13
  return unirootFull(f, lower, upper, options).root;
14
14
  }
15
+ /**
16
+ * Root in psi > 0 of a function monotone in psi (an odds ratio), given whether it lies below 1: solved in u = log psi
17
+ * to the precision of the doubles, from a bracket widened from u = 0 by doubling. 0 or Infinity when f does not change
18
+ * sign within the doubles. (R's fisher.test solves on psi in [0, 1] or 1/psi in [eps, 1] with the absolute tolerance
19
+ * eps^0.25, which leaves its estimates 1e-6 off and its limits up to several percent, or at the end 1/eps)
20
+ */
21
+ export function logScaleRoot(f, belowOne) {
22
+ const g = (u) => f(Math.exp(u));
23
+ let a = 0;
24
+ let ga = g(0);
25
+ let b = belowOne ? -1 : 1;
26
+ let gb = g(b);
27
+ while (gb !== 0 && Math.sign(gb) === Math.sign(ga)) {
28
+ if (Math.abs(b) > 745)
29
+ return belowOne ? 0 : Infinity;
30
+ a = b;
31
+ ga = gb;
32
+ b *= 2;
33
+ gb = g(b);
34
+ }
35
+ if (gb === 0)
36
+ return Math.exp(b);
37
+ const root = a < b ? uniroot(g, a, b, { tol: 2 ** -50, fLower: ga, fUpper: gb }) : uniroot(g, b, a, { tol: 2 ** -50, fLower: gb, fUpper: ga });
38
+ return Math.exp(root);
39
+ }
@@ -124,6 +124,8 @@ export declare function forwardsolve(l: MatrixInput, x: MatrixInput, options?: B
124
124
  export declare function forwardsolve(l: MatrixInput, x: VectorOrMatrix, options?: BacksolveOptions): number[] | number[][];
125
125
  /**
126
126
  * Solve op(A) X = B, overwriting B with X (dtrsm with SIDE = 'L', DIAG = 'N').
127
- * Only the upper-left n x n triangle of A is used. B has n rows
127
+ * Only the upper-left n x n triangle of A is used. B has n rows. Coefficients of exactly 0 are skipped: an overflowed
128
+ * component stands for a finite value, and 0 * Infinity = NaN spoiled the components that do not depend on it
129
+ * (backsolve(diag(1e-308, 2), c(1, 2)) gave NaN, Infinity; R too)
128
130
  */
129
131
  export declare function trsm(A: Mat, n: number, B: Mat, upper: boolean, trans: boolean): void;