@danielsimonjr/mathts-functions 0.64.3 → 0.66.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 (402) hide show
  1. package/dist/algebra/decomposition/lup.d.ts +1 -1
  2. package/dist/algebra/decomposition/lup.d.ts.map +1 -1
  3. package/dist/algebra/decomposition/qr.d.ts +1 -1
  4. package/dist/algebra/decomposition/qr.d.ts.map +1 -1
  5. package/dist/algebra/decomposition/schur.d.ts +1 -1
  6. package/dist/algebra/decomposition/schur.d.ts.map +1 -1
  7. package/dist/algebra/decomposition/slu.d.ts +1 -1
  8. package/dist/algebra/decomposition/slu.d.ts.map +1 -1
  9. package/dist/algebra/leafCount.d.ts +1 -1
  10. package/dist/algebra/leafCount.d.ts.map +1 -1
  11. package/dist/algebra/lyap.d.ts +1 -1
  12. package/dist/algebra/lyap.d.ts.map +1 -1
  13. package/dist/algebra/polynomialRoot.d.ts +1 -1
  14. package/dist/algebra/polynomialRoot.d.ts.map +1 -1
  15. package/dist/algebra/rationalize.d.ts +1 -1
  16. package/dist/algebra/rationalize.d.ts.map +1 -1
  17. package/dist/algebra/resolve.d.ts +1 -1
  18. package/dist/algebra/resolve.d.ts.map +1 -1
  19. package/dist/algebra/simplifyCore.d.ts +1 -1
  20. package/dist/algebra/simplifyCore.d.ts.map +1 -1
  21. package/dist/algebra/solver/lsolve.d.ts +1 -1
  22. package/dist/algebra/solver/lsolve.d.ts.map +1 -1
  23. package/dist/algebra/solver/lsolveAll.d.ts +2 -2
  24. package/dist/algebra/solver/lsolveAll.d.ts.map +1 -1
  25. package/dist/algebra/solver/lusolve.d.ts +1 -1
  26. package/dist/algebra/solver/lusolve.d.ts.map +1 -1
  27. package/dist/algebra/solver/usolve.d.ts +1 -1
  28. package/dist/algebra/solver/usolve.d.ts.map +1 -1
  29. package/dist/algebra/solver/usolveAll.d.ts +2 -2
  30. package/dist/algebra/solver/usolveAll.d.ts.map +1 -1
  31. package/dist/algebra/sparse/csAmd.d.ts.map +1 -1
  32. package/dist/algebra/sparse/csCounts.d.ts.map +1 -1
  33. package/dist/algebra/sylvester.d.ts +1 -1
  34. package/dist/algebra/sylvester.d.ts.map +1 -1
  35. package/dist/algebra/symbolicEqual.d.ts +1 -1
  36. package/dist/algebra/symbolicEqual.d.ts.map +1 -1
  37. package/dist/arithmetic/abs.d.ts +1 -1
  38. package/dist/arithmetic/abs.d.ts.map +1 -1
  39. package/dist/arithmetic/addScalar.d.ts +1 -1
  40. package/dist/arithmetic/addScalar.d.ts.map +1 -1
  41. package/dist/arithmetic/cbrt.d.ts +1 -1
  42. package/dist/arithmetic/cbrt.d.ts.map +1 -1
  43. package/dist/arithmetic/ceil.d.ts +2 -2
  44. package/dist/arithmetic/ceil.d.ts.map +1 -1
  45. package/dist/arithmetic/cube.d.ts +1 -1
  46. package/dist/arithmetic/cube.d.ts.map +1 -1
  47. package/dist/arithmetic/divide.d.ts +2 -1
  48. package/dist/arithmetic/divide.d.ts.map +1 -1
  49. package/dist/arithmetic/divideScalar.d.ts +1 -1
  50. package/dist/arithmetic/divideScalar.d.ts.map +1 -1
  51. package/dist/arithmetic/exp.d.ts +1 -1
  52. package/dist/arithmetic/exp.d.ts.map +1 -1
  53. package/dist/arithmetic/expm1.d.ts +1 -1
  54. package/dist/arithmetic/expm1.d.ts.map +1 -1
  55. package/dist/arithmetic/fix.d.ts +2 -2
  56. package/dist/arithmetic/fix.d.ts.map +1 -1
  57. package/dist/arithmetic/floor.d.ts +2 -2
  58. package/dist/arithmetic/floor.d.ts.map +1 -1
  59. package/dist/arithmetic/gcd.d.ts.map +1 -1
  60. package/dist/arithmetic/hypot.d.ts.map +1 -1
  61. package/dist/arithmetic/log.d.ts +1 -1
  62. package/dist/arithmetic/log.d.ts.map +1 -1
  63. package/dist/arithmetic/log10.d.ts +1 -1
  64. package/dist/arithmetic/log10.d.ts.map +1 -1
  65. package/dist/arithmetic/log1p.d.ts +1 -1
  66. package/dist/arithmetic/log1p.d.ts.map +1 -1
  67. package/dist/arithmetic/log2.d.ts +1 -1
  68. package/dist/arithmetic/log2.d.ts.map +1 -1
  69. package/dist/arithmetic/mod.d.ts +1 -1
  70. package/dist/arithmetic/mod.d.ts.map +1 -1
  71. package/dist/arithmetic/multiplyScalar.d.ts +1 -1
  72. package/dist/arithmetic/multiplyScalar.d.ts.map +1 -1
  73. package/dist/arithmetic/norm.d.ts.map +1 -1
  74. package/dist/arithmetic/nthRoot.d.ts.map +1 -1
  75. package/dist/arithmetic/pow.d.ts +1 -1
  76. package/dist/arithmetic/pow.d.ts.map +1 -1
  77. package/dist/arithmetic/round.d.ts +1 -1
  78. package/dist/arithmetic/round.d.ts.map +1 -1
  79. package/dist/arithmetic/sign.d.ts +1 -1
  80. package/dist/arithmetic/sign.d.ts.map +1 -1
  81. package/dist/arithmetic/sqrt.d.ts +1 -1
  82. package/dist/arithmetic/sqrt.d.ts.map +1 -1
  83. package/dist/arithmetic/square.d.ts +1 -1
  84. package/dist/arithmetic/square.d.ts.map +1 -1
  85. package/dist/arithmetic/subtract.d.ts +1 -1
  86. package/dist/arithmetic/subtract.d.ts.map +1 -1
  87. package/dist/arithmetic/subtractScalar.d.ts +1 -1
  88. package/dist/arithmetic/subtractScalar.d.ts.map +1 -1
  89. package/dist/arithmetic/unaryMinus.d.ts +1 -1
  90. package/dist/arithmetic/unaryMinus.d.ts.map +1 -1
  91. package/dist/arithmetic/unaryPlus.d.ts +1 -1
  92. package/dist/arithmetic/unaryPlus.d.ts.map +1 -1
  93. package/dist/bitwise/bitAnd.d.ts +1 -1
  94. package/dist/bitwise/bitAnd.d.ts.map +1 -1
  95. package/dist/bitwise/bitNot.d.ts +1 -1
  96. package/dist/bitwise/bitNot.d.ts.map +1 -1
  97. package/dist/bitwise/bitOr.d.ts +1 -1
  98. package/dist/bitwise/bitOr.d.ts.map +1 -1
  99. package/dist/bitwise/bitXor.d.ts +1 -1
  100. package/dist/bitwise/bitXor.d.ts.map +1 -1
  101. package/dist/bitwise/leftShift.d.ts +1 -1
  102. package/dist/bitwise/leftShift.d.ts.map +1 -1
  103. package/dist/bitwise/rightArithShift.d.ts +1 -1
  104. package/dist/bitwise/rightArithShift.d.ts.map +1 -1
  105. package/dist/bitwise/rightLogShift.d.ts +1 -1
  106. package/dist/bitwise/rightLogShift.d.ts.map +1 -1
  107. package/dist/bitwise/useMatrixForArrayScalar.d.ts.map +1 -1
  108. package/dist/{chunk-UMUT2YEC.js → chunk-5A2EZLXV.js} +77 -181
  109. package/dist/combinatorics/bellNumbers.d.ts +1 -1
  110. package/dist/combinatorics/bellNumbers.d.ts.map +1 -1
  111. package/dist/combinatorics/catalan.d.ts +1 -1
  112. package/dist/combinatorics/catalan.d.ts.map +1 -1
  113. package/dist/combinatorics/composition.d.ts +1 -1
  114. package/dist/combinatorics/composition.d.ts.map +1 -1
  115. package/dist/combinatorics/stirlingS2.d.ts +1 -1
  116. package/dist/combinatorics/stirlingS2.d.ts.map +1 -1
  117. package/dist/complex/arg.d.ts +1 -1
  118. package/dist/complex/arg.d.ts.map +1 -1
  119. package/dist/complex/conj.d.ts +1 -1
  120. package/dist/complex/conj.d.ts.map +1 -1
  121. package/dist/complex/im.d.ts +1 -1
  122. package/dist/complex/im.d.ts.map +1 -1
  123. package/dist/complex/re.d.ts +1 -1
  124. package/dist/complex/re.d.ts.map +1 -1
  125. package/dist/core/function/typed.d.ts +11 -1
  126. package/dist/core/function/typed.d.ts.map +1 -1
  127. package/dist/factories/evaluate.d.ts +48 -6
  128. package/dist/factories/evaluate.d.ts.map +1 -1
  129. package/dist/factories/index.d.ts +184 -184
  130. package/dist/factories/index.d.ts.map +1 -1
  131. package/dist/geometry/distance.d.ts +1 -1
  132. package/dist/geometry/distance.d.ts.map +1 -1
  133. package/dist/geometry/intersect.d.ts +1 -1
  134. package/dist/geometry/intersect.d.ts.map +1 -1
  135. package/dist/index.d.ts +4 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +500 -1993
  138. package/dist/logical/and.d.ts +1 -1
  139. package/dist/logical/and.d.ts.map +1 -1
  140. package/dist/logical/not.d.ts +1 -1
  141. package/dist/logical/not.d.ts.map +1 -1
  142. package/dist/logical/or.d.ts +1 -1
  143. package/dist/logical/or.d.ts.map +1 -1
  144. package/dist/logical/xor.d.ts +1 -1
  145. package/dist/logical/xor.d.ts.map +1 -1
  146. package/dist/matrix/column.d.ts +2 -1
  147. package/dist/matrix/column.d.ts.map +1 -1
  148. package/dist/matrix/concat.d.ts +1 -1
  149. package/dist/matrix/concat.d.ts.map +1 -1
  150. package/dist/matrix/count.d.ts +1 -1
  151. package/dist/matrix/count.d.ts.map +1 -1
  152. package/dist/matrix/cross.d.ts +1 -1
  153. package/dist/matrix/cross.d.ts.map +1 -1
  154. package/dist/matrix/ctranspose.d.ts +1 -1
  155. package/dist/matrix/ctranspose.d.ts.map +1 -1
  156. package/dist/matrix/det.d.ts +2 -1
  157. package/dist/matrix/det.d.ts.map +1 -1
  158. package/dist/matrix/diag.d.ts +1 -1
  159. package/dist/matrix/diag.d.ts.map +1 -1
  160. package/dist/matrix/diff.d.ts.map +1 -1
  161. package/dist/matrix/dot.d.ts +1 -1
  162. package/dist/matrix/dot.d.ts.map +1 -1
  163. package/dist/matrix/eigs/complexEigs.d.ts.map +1 -1
  164. package/dist/matrix/eigs/realSymmetric.d.ts.map +1 -1
  165. package/dist/matrix/eigs.d.ts +2 -1
  166. package/dist/matrix/eigs.d.ts.map +1 -1
  167. package/dist/matrix/fft.d.ts +1 -1
  168. package/dist/matrix/fft.d.ts.map +1 -1
  169. package/dist/matrix/filter.d.ts +1 -1
  170. package/dist/matrix/filter.d.ts.map +1 -1
  171. package/dist/matrix/flatten.d.ts +1 -1
  172. package/dist/matrix/flatten.d.ts.map +1 -1
  173. package/dist/matrix/forEach.d.ts +1 -1
  174. package/dist/matrix/forEach.d.ts.map +1 -1
  175. package/dist/matrix/getMatrixDataType.d.ts +1 -1
  176. package/dist/matrix/getMatrixDataType.d.ts.map +1 -1
  177. package/dist/matrix/identity.d.ts +1 -1
  178. package/dist/matrix/identity.d.ts.map +1 -1
  179. package/dist/matrix/ifft.d.ts +2 -1
  180. package/dist/matrix/ifft.d.ts.map +1 -1
  181. package/dist/matrix/inv.d.ts +2 -1
  182. package/dist/matrix/inv.d.ts.map +1 -1
  183. package/dist/matrix/kron.d.ts +2 -1
  184. package/dist/matrix/kron.d.ts.map +1 -1
  185. package/dist/matrix/map.d.ts +1 -1
  186. package/dist/matrix/map.d.ts.map +1 -1
  187. package/dist/matrix/matrixFromColumns.d.ts +2 -1
  188. package/dist/matrix/matrixFromColumns.d.ts.map +1 -1
  189. package/dist/matrix/matrixFromRows.d.ts +2 -1
  190. package/dist/matrix/matrixFromRows.d.ts.map +1 -1
  191. package/dist/matrix/ones.d.ts +1 -1
  192. package/dist/matrix/ones.d.ts.map +1 -1
  193. package/dist/matrix/partitionSelect.d.ts +2 -1
  194. package/dist/matrix/partitionSelect.d.ts.map +1 -1
  195. package/dist/matrix/range.d.ts +1 -1
  196. package/dist/matrix/range.d.ts.map +1 -1
  197. package/dist/matrix/reshape.d.ts +1 -1
  198. package/dist/matrix/reshape.d.ts.map +1 -1
  199. package/dist/matrix/resize.d.ts +1 -1
  200. package/dist/matrix/resize.d.ts.map +1 -1
  201. package/dist/matrix/row.d.ts +2 -1
  202. package/dist/matrix/row.d.ts.map +1 -1
  203. package/dist/matrix/size.d.ts +1 -1
  204. package/dist/matrix/size.d.ts.map +1 -1
  205. package/dist/matrix/sqrtm.d.ts +2 -1
  206. package/dist/matrix/sqrtm.d.ts.map +1 -1
  207. package/dist/matrix/squeeze.d.ts +1 -1
  208. package/dist/matrix/squeeze.d.ts.map +1 -1
  209. package/dist/matrix/subset.d.ts +1 -1
  210. package/dist/matrix/subset.d.ts.map +1 -1
  211. package/dist/matrix/trace.d.ts +1 -1
  212. package/dist/matrix/trace.d.ts.map +1 -1
  213. package/dist/matrix/transpose.d.ts +1 -1
  214. package/dist/matrix/transpose.d.ts.map +1 -1
  215. package/dist/matrix/utils/zerosAndOnes.d.ts +1 -1
  216. package/dist/matrix/utils/zerosAndOnes.d.ts.map +1 -1
  217. package/dist/matrix/zeros.d.ts +1 -1
  218. package/dist/matrix/zeros.d.ts.map +1 -1
  219. package/dist/numeric/gauss-legendre4.d.ts +75 -0
  220. package/dist/numeric/gauss-legendre4.d.ts.map +1 -0
  221. package/dist/numeric/propagate-uncertainty.d.ts +46 -0
  222. package/dist/numeric/propagate-uncertainty.d.ts.map +1 -0
  223. package/dist/numeric/rational-nullspace.d.ts +45 -0
  224. package/dist/numeric/rational-nullspace.d.ts.map +1 -0
  225. package/dist/numeric/solveODE.d.ts +2 -2
  226. package/dist/numeric/solveODE.d.ts.map +1 -1
  227. package/dist/probability/bernoulli.d.ts +1 -1
  228. package/dist/probability/bernoulli.d.ts.map +1 -1
  229. package/dist/probability/combinations.d.ts +1 -1
  230. package/dist/probability/combinations.d.ts.map +1 -1
  231. package/dist/probability/combinationsWithRep.d.ts +1 -1
  232. package/dist/probability/combinationsWithRep.d.ts.map +1 -1
  233. package/dist/probability/factorial.d.ts +1 -1
  234. package/dist/probability/factorial.d.ts.map +1 -1
  235. package/dist/probability/gamma.d.ts +1 -1
  236. package/dist/probability/gamma.d.ts.map +1 -1
  237. package/dist/probability/kldivergence.d.ts +1 -1
  238. package/dist/probability/kldivergence.d.ts.map +1 -1
  239. package/dist/probability/lgamma.d.ts +1 -1
  240. package/dist/probability/lgamma.d.ts.map +1 -1
  241. package/dist/probability/multinomial.d.ts +1 -1
  242. package/dist/probability/multinomial.d.ts.map +1 -1
  243. package/dist/probability/permutations.d.ts +1 -1
  244. package/dist/probability/permutations.d.ts.map +1 -1
  245. package/dist/probability/pickRandom.d.ts +1 -1
  246. package/dist/probability/pickRandom.d.ts.map +1 -1
  247. package/dist/probability/random.d.ts +2 -2
  248. package/dist/probability/random.d.ts.map +1 -1
  249. package/dist/probability/randomInt.d.ts +1 -1
  250. package/dist/probability/randomInt.d.ts.map +1 -1
  251. package/dist/relational/compare.d.ts +2 -2
  252. package/dist/relational/compare.d.ts.map +1 -1
  253. package/dist/relational/compareNatural.d.ts +1 -1
  254. package/dist/relational/compareNatural.d.ts.map +1 -1
  255. package/dist/relational/deepEqual.d.ts +1 -1
  256. package/dist/relational/deepEqual.d.ts.map +1 -1
  257. package/dist/relational/equal.d.ts +2 -2
  258. package/dist/relational/equal.d.ts.map +1 -1
  259. package/dist/relational/equalScalar.d.ts +1 -1
  260. package/dist/relational/equalScalar.d.ts.map +1 -1
  261. package/dist/relational/equalText.d.ts +1 -1
  262. package/dist/relational/equalText.d.ts.map +1 -1
  263. package/dist/relational/larger.d.ts +2 -2
  264. package/dist/relational/larger.d.ts.map +1 -1
  265. package/dist/relational/largerEq.d.ts +2 -2
  266. package/dist/relational/largerEq.d.ts.map +1 -1
  267. package/dist/relational/smaller.d.ts +2 -2
  268. package/dist/relational/smaller.d.ts.map +1 -1
  269. package/dist/relational/smallerEq.d.ts +2 -2
  270. package/dist/relational/smallerEq.d.ts.map +1 -1
  271. package/dist/relational/unequal.d.ts +2 -2
  272. package/dist/relational/unequal.d.ts.map +1 -1
  273. package/dist/set/setCartesian.d.ts +1 -1
  274. package/dist/set/setCartesian.d.ts.map +1 -1
  275. package/dist/set/setDifference.d.ts +1 -1
  276. package/dist/set/setDifference.d.ts.map +1 -1
  277. package/dist/set/setIntersect.d.ts +1 -1
  278. package/dist/set/setIntersect.d.ts.map +1 -1
  279. package/dist/set/setSymDifference.d.ts +1 -1
  280. package/dist/set/setSymDifference.d.ts.map +1 -1
  281. package/dist/set/setUnion.d.ts +1 -1
  282. package/dist/set/setUnion.d.ts.map +1 -1
  283. package/dist/signal/freqz.d.ts +2 -1
  284. package/dist/signal/freqz.d.ts.map +1 -1
  285. package/dist/signal/zpk2tf.d.ts +2 -1
  286. package/dist/signal/zpk2tf.d.ts.map +1 -1
  287. package/dist/special/erf.d.ts +1 -1
  288. package/dist/special/erf.d.ts.map +1 -1
  289. package/dist/special/zeta.d.ts +1 -1
  290. package/dist/special/zeta.d.ts.map +1 -1
  291. package/dist/statistics/corr.d.ts +1 -1
  292. package/dist/statistics/corr.d.ts.map +1 -1
  293. package/dist/statistics/cumsum.d.ts +1 -1
  294. package/dist/statistics/cumsum.d.ts.map +1 -1
  295. package/dist/statistics/mad.d.ts +1 -1
  296. package/dist/statistics/mad.d.ts.map +1 -1
  297. package/dist/statistics/max.d.ts +1 -1
  298. package/dist/statistics/max.d.ts.map +1 -1
  299. package/dist/statistics/mean.d.ts +1 -1
  300. package/dist/statistics/mean.d.ts.map +1 -1
  301. package/dist/statistics/median.d.ts +1 -1
  302. package/dist/statistics/median.d.ts.map +1 -1
  303. package/dist/statistics/min.d.ts +1 -1
  304. package/dist/statistics/min.d.ts.map +1 -1
  305. package/dist/statistics/mode.d.ts +1 -1
  306. package/dist/statistics/mode.d.ts.map +1 -1
  307. package/dist/statistics/prod.d.ts +1 -1
  308. package/dist/statistics/prod.d.ts.map +1 -1
  309. package/dist/statistics/quantileSeq.d.ts +1 -1
  310. package/dist/statistics/quantileSeq.d.ts.map +1 -1
  311. package/dist/statistics/std.d.ts +1 -1
  312. package/dist/statistics/std.d.ts.map +1 -1
  313. package/dist/statistics/sum.d.ts +1 -1
  314. package/dist/statistics/sum.d.ts.map +1 -1
  315. package/dist/statistics/variance.d.ts +1 -1
  316. package/dist/statistics/variance.d.ts.map +1 -1
  317. package/dist/string/bin.d.ts +1 -1
  318. package/dist/string/bin.d.ts.map +1 -1
  319. package/dist/string/format.d.ts +1 -1
  320. package/dist/string/format.d.ts.map +1 -1
  321. package/dist/string/hex.d.ts +1 -1
  322. package/dist/string/hex.d.ts.map +1 -1
  323. package/dist/string/oct.d.ts +1 -1
  324. package/dist/string/oct.d.ts.map +1 -1
  325. package/dist/string/print.d.ts +1 -1
  326. package/dist/string/print.d.ts.map +1 -1
  327. package/dist/trigonometry/acos.d.ts +1 -1
  328. package/dist/trigonometry/acos.d.ts.map +1 -1
  329. package/dist/trigonometry/asin.d.ts +1 -1
  330. package/dist/trigonometry/asin.d.ts.map +1 -1
  331. package/dist/trigonometry/atan.d.ts +1 -1
  332. package/dist/trigonometry/atan.d.ts.map +1 -1
  333. package/dist/trigonometry/atan2.d.ts +1 -1
  334. package/dist/trigonometry/atan2.d.ts.map +1 -1
  335. package/dist/trigonometry/cos.d.ts +1 -1
  336. package/dist/trigonometry/cos.d.ts.map +1 -1
  337. package/dist/trigonometry/sin.d.ts +1 -1
  338. package/dist/trigonometry/sin.d.ts.map +1 -1
  339. package/dist/trigonometry/tan.d.ts +1 -1
  340. package/dist/trigonometry/tan.d.ts.map +1 -1
  341. package/dist/type/matrix/function/index.d.ts +1 -1
  342. package/dist/type/matrix/function/index.d.ts.map +1 -1
  343. package/dist/type/unit/function/createUnit.d.ts +1 -1
  344. package/dist/type/unit/function/createUnit.d.ts.map +1 -1
  345. package/dist/type/unit/function/splitUnit.d.ts +1 -1
  346. package/dist/type/unit/function/splitUnit.d.ts.map +1 -1
  347. package/dist/type/unit/function/unit.d.ts +1 -1
  348. package/dist/type/unit/function/unit.d.ts.map +1 -1
  349. package/dist/type/unit/physicalConstants.d.ts +4 -7
  350. package/dist/type/unit/physicalConstants.d.ts.map +1 -1
  351. package/dist/typed/algebra.d.ts +14 -5
  352. package/dist/typed/algebra.d.ts.map +1 -1
  353. package/dist/typed/arithmetic.d.ts.map +1 -1
  354. package/dist/typed/geometry.d.ts +2 -6
  355. package/dist/typed/geometry.d.ts.map +1 -1
  356. package/dist/typed/hypothesis.d.ts +13 -0
  357. package/dist/typed/hypothesis.d.ts.map +1 -1
  358. package/dist/typed/numeric.d.ts +3 -1
  359. package/dist/typed/numeric.d.ts.map +1 -1
  360. package/dist/typed/signal.d.ts +1 -1
  361. package/dist/typed/signal.d.ts.map +1 -1
  362. package/dist/unit/to.d.ts +1 -1
  363. package/dist/unit/to.d.ts.map +1 -1
  364. package/dist/unit/toBest.d.ts +1 -1
  365. package/dist/unit/toBest.d.ts.map +1 -1
  366. package/dist/utils/bignumber/bitwise.d.ts +1 -0
  367. package/dist/utils/bignumber/bitwise.d.ts.map +1 -1
  368. package/dist/utils/clone.d.ts +1 -1
  369. package/dist/utils/clone.d.ts.map +1 -1
  370. package/dist/utils/hasNumericValue.d.ts +1 -1
  371. package/dist/utils/hasNumericValue.d.ts.map +1 -1
  372. package/dist/utils/isInteger.d.ts +1 -1
  373. package/dist/utils/isInteger.d.ts.map +1 -1
  374. package/dist/utils/isNaN.d.ts +1 -1
  375. package/dist/utils/isNaN.d.ts.map +1 -1
  376. package/dist/utils/isNegative.d.ts +1 -1
  377. package/dist/utils/isNegative.d.ts.map +1 -1
  378. package/dist/utils/isPositive.d.ts +1 -1
  379. package/dist/utils/isPositive.d.ts.map +1 -1
  380. package/dist/utils/isPrime.d.ts +1 -1
  381. package/dist/utils/isPrime.d.ts.map +1 -1
  382. package/dist/utils/isZero.d.ts +1 -1
  383. package/dist/utils/isZero.d.ts.map +1 -1
  384. package/dist/utils/typeOf.d.ts +1 -1
  385. package/dist/utils/typeOf.d.ts.map +1 -1
  386. package/dist/wasm/WasmLoader.d.ts +28 -210
  387. package/dist/wasm/WasmLoader.d.ts.map +1 -1
  388. package/dist/wasm/bitwise/wasm-bridge.d.ts.map +1 -1
  389. package/dist/wasm/bridges/common.d.ts +2 -0
  390. package/dist/wasm/bridges/common.d.ts.map +1 -1
  391. package/dist/wasm/elementwise/wasm-bridge.d.ts.map +1 -1
  392. package/dist/wasm/interpolation/wasm-bridge.d.ts.map +1 -1
  393. package/dist/wasm/mathts-as.wasm +0 -0
  394. package/dist/wasm/policy.d.ts +37 -0
  395. package/dist/wasm/policy.d.ts.map +1 -0
  396. package/dist/wasm/poly/wasm-bridge.d.ts.map +1 -1
  397. package/dist/wasm/signal/wasm-bridge.d.ts.map +1 -1
  398. package/dist/wasm/sort/wasm-bridge.d.ts.map +1 -1
  399. package/dist/wasm/special/wasm-bridge.d.ts.map +1 -1
  400. package/dist/wasm/wasm-manifest.json +1 -1
  401. package/dist/{wasm-bridge-C44GQ3DS.js → wasm-bridge-74YOKWIS.js} +1 -1
  402. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -6,14 +6,16 @@ import {
6
6
  asReadReturnedI32,
7
7
  getWasm,
8
8
  isAsWasm,
9
+ isWasmLoaded,
10
+ loadWasm,
9
11
  makeUnaryArrayDispatch,
10
12
  runChainPtr,
11
13
  runUnaryPtr,
12
14
  sortF64Dispatch,
13
- wasmLoader,
15
+ wasmPolicyAllows,
14
16
  withAsF64,
15
17
  withAsI32
16
- } from "./chunk-UMUT2YEC.js";
18
+ } from "./chunk-5A2EZLXV.js";
17
19
 
18
20
  // src/typed/index.ts
19
21
  var typed_exports = {};
@@ -22,6 +24,10 @@ __export(typed_exports, {
22
24
  CENTRALITY_WORKER_THRESHOLD: () => CENTRALITY_WORKER_THRESHOLD,
23
25
  DIST_WORKER_THRESHOLD: () => DIST_WORKER_THRESHOLD,
24
26
  GAUSS_WORKER_THRESHOLD: () => GAUSS_WORKER_THRESHOLD,
27
+ GL4ConvergenceError: () => GL4ConvergenceError,
28
+ GL4_A: () => GL4_A,
29
+ GL4_B: () => GL4_B,
30
+ GL4_C: () => GL4_C,
25
31
  GPU_ELEMENTWISE_OPS: () => GPU_ELEMENTWISE_OPS,
26
32
  GPU_MIN_ELEMENTS: () => GPU_MIN_ELEMENTS2,
27
33
  GPU_REDUCE_OPS: () => GPU_REDUCE_OPS,
@@ -204,6 +210,7 @@ __export(typed_exports, {
204
210
  gammaPDF: () => gammaPDF,
205
211
  gammainc: () => gammainc,
206
212
  gammaincp: () => gammaincp,
213
+ gaussLegendre4: () => gaussLegendre4,
207
214
  gaussQuad: () => gaussQuad,
208
215
  gcd: () => gcd,
209
216
  geometricPMF: () => geometricPMF,
@@ -395,6 +402,7 @@ __export(typed_exports, {
395
402
  random: () => random,
396
403
  randomInt: () => randomInt,
397
404
  rank: () => rank,
405
+ rationalNullspace: () => rationalNullspace,
398
406
  rayleighDist: () => rayleighDist,
399
407
  rbfInterpolate: () => rbfInterpolate,
400
408
  re: () => re,
@@ -1342,7 +1350,7 @@ var WASM_ELEMENTWISE_THRESHOLD = 1024;
1342
1350
  var kernelName = (op) => `array_${op}_ptr`;
1343
1351
  function elementwiseUnaryDispatch(op, xs) {
1344
1352
  const n = xs.length;
1345
- if (n < WASM_ELEMENTWISE_THRESHOLD) return null;
1353
+ if (n < WASM_ELEMENTWISE_THRESHOLD || !wasmPolicyAllows(kernelName(op), n)) return null;
1346
1354
  const wasm = getWasm();
1347
1355
  if (!wasm) return null;
1348
1356
  const fn = wasm[kernelName(op)];
@@ -1353,6 +1361,7 @@ function elementwiseUnaryDispatch(op, xs) {
1353
1361
  function elementwiseChainDispatch(ops, xs) {
1354
1362
  const n = xs.length;
1355
1363
  if (ops.length === 0 || n < WASM_ELEMENTWISE_THRESHOLD) return null;
1364
+ if (!wasmPolicyAllows("fused_chain", n)) return null;
1356
1365
  const wasm = getWasm();
1357
1366
  if (!wasm) return null;
1358
1367
  const mem = wasm.memory;
@@ -1680,6 +1689,8 @@ var pow = mathTyped2("pow", {
1680
1689
  // Dual numbers (forward-mode AD): constant or variable exponent.
1681
1690
  "Dual, number": (a, b) => a.powConst(b),
1682
1691
  "Dual, Dual": (a, b) => a.pow(b),
1692
+ // Dimensional power, including physics-mode `e^2` (elementary charge squared).
1693
+ "Unit, number": (a, b) => a.pow(b),
1683
1694
  // Matrix power A^n for a square 2-D array and non-negative integer n, via binary
1684
1695
  // exponentiation on the native DenseMatrix backend (accelerated matmul, B2). Element-
1685
1696
  // wise power is `dotPow`; negative/fractional matrix powers need eigendecomposition —
@@ -3681,7 +3692,7 @@ function chirpZTransformJS(samples, m, phiStartRe, phiStartIm, phiStepRe, phiSte
3681
3692
  }
3682
3693
  function applyWindowDispatch(samples, windowName) {
3683
3694
  const wt = windowTypeCode(windowName);
3684
- const wasm = getWasm();
3695
+ const wasm = wasmPolicyAllows("apply_window_f64", samples.length) ? getWasm() : null;
3685
3696
  if (wasm && isAsWasm(wasm)) {
3686
3697
  try {
3687
3698
  const out = withAsF64(wasm, [samples], (mod3, [h]) => {
@@ -3700,7 +3711,7 @@ function applyWindowDispatch(samples, windowName) {
3700
3711
  function welchPSDDispatch(samples, frameLength, overlap, windowName) {
3701
3712
  const n = samples.length;
3702
3713
  const wt = windowTypeCode(windowName);
3703
- if (n >= WASM_SIGNAL_THRESHOLD && n >= frameLength) {
3714
+ if (n >= WASM_SIGNAL_THRESHOLD && n >= frameLength && wasmPolicyAllows("welch_psd_f64", n)) {
3704
3715
  const wasm = getWasm();
3705
3716
  if (wasm && isAsWasm(wasm)) {
3706
3717
  try {
@@ -3726,7 +3737,7 @@ function welchPSDDispatch(samples, frameLength, overlap, windowName) {
3726
3737
  }
3727
3738
  function bartlettPSDDispatch(samples, frameLength) {
3728
3739
  const n = samples.length;
3729
- if (n >= WASM_SIGNAL_THRESHOLD && n >= frameLength) {
3740
+ if (n >= WASM_SIGNAL_THRESHOLD && n >= frameLength && wasmPolicyAllows("bartlett_psd_f64", n)) {
3730
3741
  const wasm = getWasm();
3731
3742
  if (wasm && isAsWasm(wasm)) {
3732
3743
  try {
@@ -3747,7 +3758,7 @@ function bartlettPSDDispatch(samples, frameLength) {
3747
3758
  }
3748
3759
  function goertzelDispatch(samples, targetFreq, sampleRate) {
3749
3760
  const n = samples.length;
3750
- if (n >= WASM_SIGNAL_THRESHOLD) {
3761
+ if (n >= WASM_SIGNAL_THRESHOLD && wasmPolicyAllows("goertzel_f64", n)) {
3751
3762
  const wasm = getWasm();
3752
3763
  if (wasm && isAsWasm(wasm)) {
3753
3764
  try {
@@ -3769,7 +3780,7 @@ function goertzelDispatch(samples, targetFreq, sampleRate) {
3769
3780
  }
3770
3781
  function chirpZTransformDispatch(samples, m, phiStartRe, phiStartIm, phiStepRe, phiStepIm) {
3771
3782
  const n = samples.length;
3772
- if (Math.max(n, m) >= WASM_SIGNAL_THRESHOLD) {
3783
+ if (Math.max(n, m) >= WASM_SIGNAL_THRESHOLD && wasmPolicyAllows("chirp_z_transform_f64", Math.max(n, m))) {
3773
3784
  const wasm = getWasm();
3774
3785
  if (wasm && isAsWasm(wasm)) {
3775
3786
  try {
@@ -3931,7 +3942,6 @@ function idwtPeriodization(approx, detail, wavelet) {
3931
3942
  }
3932
3943
 
3933
3944
  // src/typed/signal.ts
3934
- var WASM_THRESHOLD = 64;
3935
3945
  function isPowerOf22(n) {
3936
3946
  return n > 0 && (n & n - 1) === 0;
3937
3947
  }
@@ -4212,23 +4222,6 @@ function unwrapPhase(phase) {
4212
4222
  }
4213
4223
  function dct(x) {
4214
4224
  const N2 = x.length;
4215
- if (N2 >= WASM_THRESHOLD) {
4216
- const wasm = wasmLoader.getModule();
4217
- if (wasm) {
4218
- try {
4219
- const inAlloc = wasmLoader.allocateFloat64Array(x);
4220
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4221
- try {
4222
- wasm.dct_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4223
- return Array.from(outAlloc.array);
4224
- } finally {
4225
- wasmLoader.free(inAlloc.ptr);
4226
- wasmLoader.free(outAlloc.ptr);
4227
- }
4228
- } catch {
4229
- }
4230
- }
4231
- }
4232
4225
  const result = new Array(N2);
4233
4226
  for (let k = 0; k < N2; k++) {
4234
4227
  let sum3 = 0;
@@ -4241,23 +4234,6 @@ function dct(x) {
4241
4234
  }
4242
4235
  function idct(X) {
4243
4236
  const N2 = X.length;
4244
- if (N2 >= WASM_THRESHOLD) {
4245
- const wasm = wasmLoader.getModule();
4246
- if (wasm) {
4247
- try {
4248
- const inAlloc = wasmLoader.allocateFloat64Array(X);
4249
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4250
- try {
4251
- wasm.idct_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4252
- return Array.from(outAlloc.array);
4253
- } finally {
4254
- wasmLoader.free(inAlloc.ptr);
4255
- wasmLoader.free(outAlloc.ptr);
4256
- }
4257
- } catch {
4258
- }
4259
- }
4260
- }
4261
4237
  const result = new Array(N2);
4262
4238
  for (let n = 0; n < N2; n++) {
4263
4239
  let sum3 = X[0] * Math.sqrt(1 / N2);
@@ -4270,23 +4246,6 @@ function idct(X) {
4270
4246
  }
4271
4247
  function dst(x) {
4272
4248
  const N2 = x.length;
4273
- if (N2 >= WASM_THRESHOLD) {
4274
- const wasm = wasmLoader.getModule();
4275
- if (wasm) {
4276
- try {
4277
- const inAlloc = wasmLoader.allocateFloat64Array(x);
4278
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4279
- try {
4280
- wasm.dst_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4281
- return Array.from(outAlloc.array);
4282
- } finally {
4283
- wasmLoader.free(inAlloc.ptr);
4284
- wasmLoader.free(outAlloc.ptr);
4285
- }
4286
- } catch {
4287
- }
4288
- }
4289
- }
4290
4249
  const result = new Array(N2);
4291
4250
  for (let k = 0; k < N2; k++) {
4292
4251
  let sum3 = 0;
@@ -4299,23 +4258,6 @@ function dst(x) {
4299
4258
  }
4300
4259
  function idst(X) {
4301
4260
  const N2 = X.length;
4302
- if (N2 >= WASM_THRESHOLD) {
4303
- const wasm = wasmLoader.getModule();
4304
- if (wasm) {
4305
- try {
4306
- const inAlloc = wasmLoader.allocateFloat64Array(X);
4307
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4308
- try {
4309
- wasm.idst_wasm(inAlloc.ptr, outAlloc.ptr, N2);
4310
- return Array.from(outAlloc.array);
4311
- } finally {
4312
- wasmLoader.free(inAlloc.ptr);
4313
- wasmLoader.free(outAlloc.ptr);
4314
- }
4315
- } catch {
4316
- }
4317
- }
4318
- }
4319
4261
  const result = new Array(N2);
4320
4262
  for (let n = 0; n < N2; n++) {
4321
4263
  let sum3 = 0;
@@ -4332,28 +4274,6 @@ function dwt(x, wavelet = "haar") {
4332
4274
  if (n < 2) throw new Error("dwt: signal must have at least 2 samples");
4333
4275
  const half = Math.floor(n / 2);
4334
4276
  if (wavelet === "haar" || wavelet === "db1") {
4335
- if (n >= WASM_THRESHOLD && n % 2 === 0) {
4336
- const wasm = wasmLoader.getModule();
4337
- if (wasm) {
4338
- try {
4339
- const inAlloc = wasmLoader.allocateFloat64Array(x);
4340
- const approxAlloc = wasmLoader.allocateFloat64ArrayEmpty(half);
4341
- const detailAlloc = wasmLoader.allocateFloat64ArrayEmpty(half);
4342
- try {
4343
- wasm.dwt_wasm(inAlloc.ptr, approxAlloc.ptr, detailAlloc.ptr, n);
4344
- return {
4345
- approx: Array.from(approxAlloc.array),
4346
- detail: Array.from(detailAlloc.array)
4347
- };
4348
- } finally {
4349
- wasmLoader.free(inAlloc.ptr);
4350
- wasmLoader.free(approxAlloc.ptr);
4351
- wasmLoader.free(detailAlloc.ptr);
4352
- }
4353
- } catch {
4354
- }
4355
- }
4356
- }
4357
4277
  const approx = new Array(half);
4358
4278
  const detail = new Array(half);
4359
4279
  const s = 1 / Math.SQRT2;
@@ -4469,30 +4389,6 @@ function invFourier(F, omega, t) {
4469
4389
  function hilbertTransform(x) {
4470
4390
  const n = x.length;
4471
4391
  const N2 = nextPowerOf2(n);
4472
- if (N2 >= WASM_THRESHOLD) {
4473
- const wasm = wasmLoader.getModule();
4474
- if (wasm) {
4475
- try {
4476
- const paddedInput = new Array(N2).fill(0);
4477
- for (let i = 0; i < n; i++) paddedInput[i] = x[i];
4478
- const zeros4 = new Array(N2).fill(0);
4479
- const inReAlloc = wasmLoader.allocateFloat64Array(paddedInput);
4480
- const inImAlloc = wasmLoader.allocateFloat64Array(zeros4);
4481
- const outReAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4482
- const outImAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
4483
- try {
4484
- wasm.hilbert_wasm(inReAlloc.ptr, inImAlloc.ptr, outReAlloc.ptr, outImAlloc.ptr, N2);
4485
- return Array.from(outImAlloc.array.slice(0, n));
4486
- } finally {
4487
- wasmLoader.free(inReAlloc.ptr);
4488
- wasmLoader.free(inImAlloc.ptr);
4489
- wasmLoader.free(outReAlloc.ptr);
4490
- wasmLoader.free(outImAlloc.ptr);
4491
- }
4492
- } catch {
4493
- }
4494
- }
4495
- }
4496
4392
  const real = new Float64Array(N2);
4497
4393
  const imag = new Float64Array(N2);
4498
4394
  for (let i = 0; i < n; i++) real[i] = x[i];
@@ -4519,39 +4415,6 @@ async function spectrogram(x, opts) {
4519
4415
  const winType = opts?.window ?? "hann";
4520
4416
  const nfft = nextPowerOf2(windowSize);
4521
4417
  const nFreqs = nfft / 2 + 1;
4522
- if (x.length >= WASM_THRESHOLD && (winType === "hann" || winType === "hanning")) {
4523
- const wasm = wasmLoader.getModule();
4524
- if (wasm) {
4525
- try {
4526
- const numFrames = Math.floor((x.length - windowSize) / hopSize) + 1;
4527
- if (numFrames > 0) {
4528
- const inAlloc = wasmLoader.allocateFloat64Array(x);
4529
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(numFrames * nFreqs);
4530
- try {
4531
- const frames = wasm.spectrogram_wasm(
4532
- inAlloc.ptr,
4533
- outAlloc.ptr,
4534
- x.length,
4535
- windowSize,
4536
- hopSize
4537
- );
4538
- const magnitude2 = [];
4539
- const times2 = [];
4540
- const frequencies2 = Array.from({ length: nFreqs }, (_, i) => i / nfft);
4541
- for (let f = 0; f < frames; f++) {
4542
- magnitude2.push(Array.from(outAlloc.array.slice(f * nFreqs, (f + 1) * nFreqs)));
4543
- times2.push(f * hopSize + windowSize / 2);
4544
- }
4545
- return { magnitude: magnitude2, frequencies: frequencies2, times: times2 };
4546
- } finally {
4547
- wasmLoader.free(inAlloc.ptr);
4548
- wasmLoader.free(outAlloc.ptr);
4549
- }
4550
- }
4551
- } catch {
4552
- }
4553
- }
4554
- }
4555
4418
  const win = windowFunction(windowSize, winType);
4556
4419
  const magnitude = [];
4557
4420
  const times = [];
@@ -4609,26 +4472,6 @@ async function spectrogram(x, opts) {
4609
4472
  function periodogram(x, opts) {
4610
4473
  const nfft = opts?.nfft ?? nextPowerOf2(x.length);
4611
4474
  const winType = opts?.window ?? "hann";
4612
- if (x.length >= WASM_THRESHOLD && (winType === "hann" || winType === "hanning") && nfft === nextPowerOf2(x.length)) {
4613
- const wasm = wasmLoader.getModule();
4614
- if (wasm) {
4615
- try {
4616
- const nFreqs2 = nfft / 2 + 1;
4617
- const inAlloc = wasmLoader.allocateFloat64Array(x);
4618
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(nFreqs2);
4619
- try {
4620
- wasm.periodogram_wasm(inAlloc.ptr, outAlloc.ptr, x.length);
4621
- const psd2 = Array.from(outAlloc.array);
4622
- const frequencies2 = Array.from({ length: nFreqs2 }, (_, i) => i / nfft);
4623
- return { psd: psd2, frequencies: frequencies2 };
4624
- } finally {
4625
- wasmLoader.free(inAlloc.ptr);
4626
- wasmLoader.free(outAlloc.ptr);
4627
- }
4628
- } catch {
4629
- }
4630
- }
4631
- }
4632
4475
  const win = windowFunction(x.length, winType);
4633
4476
  let winPower = 0;
4634
4477
  for (let i = 0; i < x.length; i++) winPower += win[i] * win[i];
@@ -4686,25 +4529,6 @@ function _sincFilter(order, cutoff, type) {
4686
4529
  function _convolve(x, h) {
4687
4530
  const n = x.length;
4688
4531
  const m = h.length;
4689
- if (n >= WASM_THRESHOLD) {
4690
- const wasm = wasmLoader.getModule();
4691
- if (wasm) {
4692
- try {
4693
- const inAlloc = wasmLoader.allocateFloat64Array(x);
4694
- const coeffAlloc = wasmLoader.allocateFloat64Array(h);
4695
- const outAlloc = wasmLoader.allocateFloat64ArrayEmpty(n);
4696
- try {
4697
- wasm.fir_filter_wasm(inAlloc.ptr, coeffAlloc.ptr, outAlloc.ptr, n, m);
4698
- return Array.from(outAlloc.array);
4699
- } finally {
4700
- wasmLoader.free(inAlloc.ptr);
4701
- wasmLoader.free(coeffAlloc.ptr);
4702
- wasmLoader.free(outAlloc.ptr);
4703
- }
4704
- } catch {
4705
- }
4706
- }
4707
- }
4708
4532
  const offset = Math.floor(m / 2);
4709
4533
  const result = new Array(n).fill(0);
4710
4534
  for (let i = 0; i < n; i++) {
@@ -4917,10 +4741,11 @@ var UNARY_OPS = {
4917
4741
  };
4918
4742
  function runBinaryBitwiseWasm(op, a, b) {
4919
4743
  if (a.length !== b.length) return null;
4744
+ const names = BINARY_OPS[op];
4745
+ if (!wasmPolicyAllows(names.as, a.length)) return null;
4920
4746
  const wasm = getWasm();
4921
4747
  if (!wasm || !isAsWasm(wasm)) return null;
4922
4748
  const n = a.length;
4923
- const names = BINARY_OPS[op];
4924
4749
  try {
4925
4750
  return withAsI32(wasm, [a, b, new Int32Array(n)], (mod3, [ha, hb, hr]) => {
4926
4751
  mod3[names.as](ha, hb, hr);
@@ -4931,10 +4756,11 @@ function runBinaryBitwiseWasm(op, a, b) {
4931
4756
  }
4932
4757
  }
4933
4758
  function runUnaryBitwiseWasm(op, a) {
4759
+ const names = UNARY_OPS[op];
4760
+ if (!wasmPolicyAllows(names.as, a.length)) return null;
4934
4761
  const wasm = getWasm();
4935
4762
  if (!wasm || !isAsWasm(wasm)) return null;
4936
4763
  const n = a.length;
4937
- const names = UNARY_OPS[op];
4938
4764
  try {
4939
4765
  return withAsI32(wasm, [a, new Int32Array(n)], (mod3, [ha, hr]) => {
4940
4766
  mod3[names.as](ha, hr);
@@ -6657,7 +6483,7 @@ var besselJ1Dispatch = makeUnaryArrayDispatch({
6657
6483
  });
6658
6484
  function besselOrderDispatch(order, xs, asName, js) {
6659
6485
  const n = xs.length;
6660
- if (n >= WASM_SPECIAL_THRESHOLD) {
6486
+ if (n >= WASM_SPECIAL_THRESHOLD && wasmPolicyAllows(asName, n)) {
6661
6487
  const wasm = getWasm();
6662
6488
  if (wasm && isAsWasm(wasm)) {
6663
6489
  try {
@@ -6919,7 +6745,7 @@ function ellipticPiIncompleteScalar(n, phi, m) {
6919
6745
  }
6920
6746
  function multiArrayDispatch(name254, inputs, js) {
6921
6747
  const n = inputs[0].length;
6922
- if (n >= WASM_SPECIAL_THRESHOLD) {
6748
+ if (n >= WASM_SPECIAL_THRESHOLD && wasmPolicyAllows(name254, n)) {
6923
6749
  const wasm = getWasm();
6924
6750
  if (wasm && isAsWasm(wasm)) {
6925
6751
  try {
@@ -8573,8 +8399,6 @@ var typedDistributions = {
8573
8399
 
8574
8400
  // src/typed/geometry.ts
8575
8401
  import { computePool as computePool7 } from "@danielsimonjr/mathts-parallel";
8576
- var GEOMETRY_WASM_THRESHOLD = 32;
8577
- var HULL3D_WASM_THRESHOLD = 1024;
8578
8402
  function angle2D(v1, v2) {
8579
8403
  const dot9 = v1[0] * v2[0] + v1[1] * v2[1];
8580
8404
  const mag1 = Math.sqrt(v1[0] ** 2 + v1[1] ** 2);
@@ -8925,49 +8749,6 @@ function voronoiDiagram(points, bounds) {
8925
8749
  "voronoiDiagram: bounds must be a [xMin, yMin, xMax, yMax] tuple (the clipping box)"
8926
8750
  );
8927
8751
  }
8928
- const n = points.length;
8929
- if (n >= GEOMETRY_WASM_THRESHOLD) {
8930
- const wasm = wasmLoader.getModule();
8931
- if (wasm) {
8932
- try {
8933
- const flat = new Float64Array(n * 2);
8934
- for (let i = 0; i < n; i++) {
8935
- flat[i * 2] = points[i][0];
8936
- flat[i * 2 + 1] = points[i][1];
8937
- }
8938
- const ptsAlloc = wasmLoader.allocateFloat64Array(flat);
8939
- const boundsAlloc = wasmLoader.allocateFloat64Array(new Float64Array(bounds));
8940
- const maxVerts = 2 * n;
8941
- const maxEdges = 6 * n;
8942
- const vertsAlloc = wasmLoader.allocateFloat64ArrayEmpty(maxVerts * 2);
8943
- const edgesAlloc = wasmLoader.allocateInt32ArrayEmpty(maxEdges * 2);
8944
- try {
8945
- const packed = wasm.voronoi_wasm(
8946
- ptsAlloc.ptr,
8947
- n,
8948
- boundsAlloc.ptr,
8949
- vertsAlloc.ptr,
8950
- edgesAlloc.ptr,
8951
- maxVerts,
8952
- maxEdges
8953
- );
8954
- const numVerts = packed & 65535;
8955
- const vertices2 = [];
8956
- for (let i = 0; i < numVerts; i++) {
8957
- vertices2.push([vertsAlloc.array[i * 2], vertsAlloc.array[i * 2 + 1]]);
8958
- }
8959
- const regions2 = Array.from({ length: n }, () => []);
8960
- return { vertices: vertices2, regions: regions2 };
8961
- } finally {
8962
- wasmLoader.free(ptsAlloc.ptr);
8963
- wasmLoader.free(boundsAlloc.ptr);
8964
- wasmLoader.free(vertsAlloc.ptr);
8965
- wasmLoader.free(edgesAlloc.ptr);
8966
- }
8967
- } catch {
8968
- }
8969
- }
8970
- }
8971
8752
  const triangles = delaunayTriangulation(points);
8972
8753
  const vertices = [];
8973
8754
  const triCircumcenters = /* @__PURE__ */ new Map();
@@ -9045,46 +8826,6 @@ function distanceNDSq(a, b) {
9045
8826
  function nearestNeighbor(points, query) {
9046
8827
  const n = points.length;
9047
8828
  if (n === 0) return null;
9048
- const dims = points[0].length;
9049
- if (n >= GEOMETRY_WASM_THRESHOLD) {
9050
- const wasm = wasmLoader.getModule();
9051
- if (wasm) {
9052
- try {
9053
- const flat = new Float64Array(n * dims);
9054
- for (let i = 0; i < n; i++) {
9055
- for (let d = 0; d < dims; d++) {
9056
- flat[i * dims + d] = points[i][d];
9057
- }
9058
- }
9059
- const ptsAlloc = wasmLoader.allocateFloat64Array(flat);
9060
- const stride = 3 + dims;
9061
- const treeAlloc = wasmLoader.allocateFloat64ArrayEmpty(n * stride);
9062
- const queryAlloc = wasmLoader.allocateFloat64Array(new Float64Array(query));
9063
- try {
9064
- const treeSize = wasm.kdtree_build_wasm(ptsAlloc.ptr, n, dims, treeAlloc.ptr);
9065
- const nearestIdx = wasm.kdtree_nearest_wasm(
9066
- treeAlloc.ptr,
9067
- queryAlloc.ptr,
9068
- dims,
9069
- treeSize
9070
- );
9071
- if (nearestIdx >= 0 && nearestIdx < n) {
9072
- const pt = points[nearestIdx];
9073
- let distSq = 0;
9074
- for (let d = 0; d < dims; d++) {
9075
- distSq += (pt[d] - query[d]) ** 2;
9076
- }
9077
- return { point: pt, index: nearestIdx, distance: Math.sqrt(distSq) };
9078
- }
9079
- } finally {
9080
- wasmLoader.free(ptsAlloc.ptr);
9081
- wasmLoader.free(treeAlloc.ptr);
9082
- wasmLoader.free(queryAlloc.ptr);
9083
- }
9084
- } catch {
9085
- }
9086
- }
9087
- }
9088
8829
  const root2 = kdTree(points);
9089
8830
  return kdTreeNearest(root2, query);
9090
8831
  }
@@ -9093,45 +8834,6 @@ function convexHull3D(points) {
9093
8834
  if (n < 4) {
9094
8835
  throw new Error("convexHull3D: at least 4 non-coplanar points are required");
9095
8836
  }
9096
- if (n >= HULL3D_WASM_THRESHOLD) {
9097
- const wasm = wasmLoader.getModule();
9098
- if (wasm) {
9099
- try {
9100
- const flat = new Float64Array(n * 3);
9101
- for (let i = 0; i < n; i++) {
9102
- flat[i * 3] = points[i][0];
9103
- flat[i * 3 + 1] = points[i][1];
9104
- flat[i * 3 + 2] = points[i][2];
9105
- }
9106
- const ptsAlloc = wasmLoader.allocateFloat64Array(flat);
9107
- const maxFaces = 4 * n;
9108
- const facesAlloc = wasmLoader.allocateInt32ArrayEmpty(maxFaces * 3);
9109
- try {
9110
- const nFaces = wasm.convex_hull_3d_wasm(ptsAlloc.ptr, n, facesAlloc.ptr, maxFaces);
9111
- if (nFaces === -1) {
9112
- throw new Error("convexHull3D: WASM output buffer overflow \u2014 retrying with JS");
9113
- }
9114
- if (nFaces === 0) {
9115
- throw new Error("convexHull3D: degenerate input (all points co-planar or collinear)");
9116
- }
9117
- const result = [];
9118
- for (let i = 0; i < nFaces; i++) {
9119
- result.push([
9120
- facesAlloc.array[i * 3],
9121
- facesAlloc.array[i * 3 + 1],
9122
- facesAlloc.array[i * 3 + 2]
9123
- ]);
9124
- }
9125
- return result;
9126
- } finally {
9127
- wasmLoader.free(ptsAlloc.ptr);
9128
- wasmLoader.free(facesAlloc.ptr);
9129
- }
9130
- } catch (err) {
9131
- if (err instanceof Error && err.message.includes("degenerate")) throw err;
9132
- }
9133
- }
9134
- }
9135
8837
  return convexHull3DJS(points);
9136
8838
  }
9137
8839
  function convexHull3DJS(points) {
@@ -9309,7 +9011,7 @@ function polyDivModJS(num2, den) {
9309
9011
  }
9310
9012
  function polyMulDispatch(a, b) {
9311
9013
  const bigEnough = a.length >= WASM_POLY_THRESHOLD || b.length >= WASM_POLY_THRESHOLD;
9312
- if (bigEnough) {
9014
+ if (bigEnough && wasmPolicyAllows("poly_mul_f64", Math.max(a.length, b.length))) {
9313
9015
  const wasm = getWasm();
9314
9016
  if (wasm && isAsWasm(wasm)) {
9315
9017
  try {
@@ -9328,7 +9030,7 @@ function polyMulDispatch(a, b) {
9328
9030
  function polyDivModDispatch(num2, den) {
9329
9031
  if (den.length === 0) throw new Error("Division by zero polynomial");
9330
9032
  const bigEnough = num2.length >= WASM_POLY_THRESHOLD;
9331
- if (bigEnough) {
9033
+ if (bigEnough && wasmPolicyAllows("poly_div_mod_f64", num2.length)) {
9332
9034
  const wasm = getWasm();
9333
9035
  if (wasm && isAsWasm(wasm)) {
9334
9036
  try {
@@ -9431,7 +9133,7 @@ function discriminantJS(p) {
9431
9133
  }
9432
9134
  function resultantDispatch(p, q) {
9433
9135
  const bigEnough = p.length >= WASM_POLY_THRESHOLD || q.length >= WASM_POLY_THRESHOLD;
9434
- if (bigEnough) {
9136
+ if (bigEnough && wasmPolicyAllows("poly_resultant_f64", Math.max(p.length, q.length))) {
9435
9137
  const wasm = getWasm();
9436
9138
  if (wasm && isAsWasm(wasm)) {
9437
9139
  try {
@@ -9449,7 +9151,7 @@ function resultantDispatch(p, q) {
9449
9151
  }
9450
9152
  function discriminantDispatch(p) {
9451
9153
  const bigEnough = p.length >= WASM_POLY_THRESHOLD;
9452
- if (bigEnough) {
9154
+ if (bigEnough && wasmPolicyAllows("poly_discriminant_f64", p.length)) {
9453
9155
  const wasm = getWasm();
9454
9156
  if (wasm && isAsWasm(wasm)) {
9455
9157
  try {
@@ -9562,7 +9264,7 @@ function legendreFitJSFallback(xs, ys, degree3) {
9562
9264
  }
9563
9265
  function fitDispatch(xs, ys, degree3, asName, jsFallback) {
9564
9266
  if (xs.length !== ys.length) throw new Error("xs and ys must have the same length");
9565
- if (xs.length >= WASM_POLY_FIT_THRESHOLD) {
9267
+ if (xs.length >= WASM_POLY_FIT_THRESHOLD && wasmPolicyAllows(asName, xs.length)) {
9566
9268
  const wasm = getWasm();
9567
9269
  if (wasm && isAsWasm(wasm)) {
9568
9270
  try {
@@ -11402,6 +11104,9 @@ function polyder(coeffs, n = 1) {
11402
11104
  return result;
11403
11105
  }
11404
11106
  function polynomialGCD(a, b) {
11107
+ if (a.every(Number.isSafeInteger) && b.every(Number.isSafeInteger)) {
11108
+ return integerPolynomialGCD(a, b);
11109
+ }
11405
11110
  let r0 = trimPoly([...a]);
11406
11111
  let r1 = trimPoly([...b]);
11407
11112
  while (r1.length > 1 || r1[0] !== 0) {
@@ -11415,9 +11120,15 @@ function polynomialGCD(a, b) {
11415
11120
  }
11416
11121
  return r0;
11417
11122
  }
11123
+ function integerPolynomialGCD(a, b) {
11124
+ const g = polyGcdZ(a.map(BigInt), b.map(BigInt));
11125
+ if (g.length === 0) return [0];
11126
+ const lead = Number(g[g.length - 1]);
11127
+ return g.map((c) => Number(c) / lead);
11128
+ }
11418
11129
  function polynomialLCM(a, b) {
11419
- const gcd2 = polynomialGCD(a, b);
11420
- const [quotient] = polyDivMod(polymul(a, b), gcd2);
11130
+ const gcd3 = polynomialGCD(a, b);
11131
+ const [quotient] = polyDivMod(polymul(a, b), gcd3);
11421
11132
  const leading = quotient[quotient.length - 1];
11422
11133
  if (leading !== 0 && leading !== 1) {
11423
11134
  return quotient.map((c) => c / leading);
@@ -12583,7 +12294,7 @@ function tridiagSolveJS(diag2, lower, upper, rhs) {
12583
12294
  }
12584
12295
  function tridiagSolveDispatch(diag2, lower, upper, rhs) {
12585
12296
  const n = diag2.length;
12586
- if (n >= WASM_TRIDIAG_THRESHOLD) {
12297
+ if (n >= WASM_TRIDIAG_THRESHOLD && wasmPolicyAllows("tridiag_solve_f64", n)) {
12587
12298
  const wasm = getWasm();
12588
12299
  if (wasm && isAsWasm(wasm)) {
12589
12300
  try {
@@ -12624,7 +12335,7 @@ function dividedDifferenceJS(xs, ys) {
12624
12335
  }
12625
12336
  function dividedDifferenceDispatch(xs, ys) {
12626
12337
  const n = xs.length;
12627
- if (n >= WASM_INTERP_THRESHOLD) {
12338
+ if (n >= WASM_INTERP_THRESHOLD && wasmPolicyAllows("divided_difference_f64", n)) {
12628
12339
  const wasm = getWasm();
12629
12340
  if (wasm && isAsWasm(wasm)) {
12630
12341
  try {
@@ -13221,7 +12932,6 @@ function factory(name254, dependencies254, create, meta) {
13221
12932
 
13222
12933
  // src/numeric/solveODE.ts
13223
12934
  import { DenseMatrix as DenseMatrix3, lu, luSolve } from "@danielsimonjr/mathts-matrix";
13224
- var WASM_ODE_THRESHOLD = 10;
13225
12935
  var name = "solveODE";
13226
12936
  var dependencies = [
13227
12937
  "typed",
@@ -14092,6 +13802,8 @@ function radauSolve(f, tspan, y0raw, options = {}) {
14092
13802
  var createSolveODE = /* @__PURE__ */ factory(
14093
13803
  name,
14094
13804
  dependencies,
13805
+ // The deps are untyped (`any`), so the result is declared: without it the export
13806
+ // inherits `any` from `typed(...)` instead of being a TypedFunction like the rest.
14095
13807
  ({
14096
13808
  typed: typed3,
14097
13809
  add: add5,
@@ -14109,143 +13821,6 @@ var createSolveODE = /* @__PURE__ */ factory(
14109
13821
  bignumber: bignumber2,
14110
13822
  unaryMinus: unaryMinus2
14111
13823
  }) => {
14112
- function _isPlainNumberArray(y0) {
14113
- if (!Array.isArray(y0) || y0.length < WASM_ODE_THRESHOLD) return false;
14114
- for (let i = 0; i < y0.length; i++) {
14115
- if (typeof y0[i] !== "number") return false;
14116
- }
14117
- return true;
14118
- }
14119
- function _rkWasmLoop(f, tspan, y0, options, butcherTableau) {
14120
- const wasm = wasmLoader.getModule();
14121
- if (!wasm) return null;
14122
- const dim = y0.length;
14123
- const a = butcherTableau.a;
14124
- const c = butcherTableau.c;
14125
- const b = butcherTableau.b;
14126
- const bp = butcherTableau.bp;
14127
- const numStages = c.length;
14128
- const t0 = tspan[0];
14129
- const tf = tspan[1];
14130
- const isForwards = tf > t0;
14131
- const tol = options.tol ? options.tol : 1e-4;
14132
- const minDelta = options.minDelta ? options.minDelta : 0.2;
14133
- const maxDelta = options.maxDelta ? options.maxDelta : 5;
14134
- const maxIter = options.maxIter ? options.maxIter : 1e4;
14135
- let h;
14136
- if (options.firstStep) {
14137
- h = isForwards ? options.firstStep : -options.firstStep;
14138
- } else {
14139
- const f0 = f(t0, y0);
14140
- const d0 = _rmsNorm(y0);
14141
- const d1 = _rmsNorm(Array.isArray(f0) ? f0 : [f0]);
14142
- const h0 = d0 < 1e-5 || d1 < 1e-5 ? 1e-6 : 0.01 * (d0 / d1);
14143
- const hMag = Math.min(h0, Math.abs(tf - t0));
14144
- h = isForwards ? hMag : -hMag;
14145
- }
14146
- const maxStepVal = options.maxStep;
14147
- const minStepVal = options.minStep;
14148
- const deltaB = new Float64Array(numStages);
14149
- for (let i = 0; i < numStages; i++) {
14150
- deltaB[i] = b[i] - bp[i];
14151
- }
14152
- const yAlloc = wasmLoader.allocateFloat64Array(y0);
14153
- const yNewAlloc = wasmLoader.allocateFloat64ArrayEmpty(dim);
14154
- const errorAlloc = wasmLoader.allocateFloat64ArrayEmpty(dim);
14155
- const tempAlloc = wasmLoader.allocateFloat64ArrayEmpty(dim);
14156
- const stageAlloc = wasmLoader.allocateFloat64ArrayEmpty(numStages * dim);
14157
- try {
14158
- let readVec2 = function(alloc) {
14159
- const arr10 = new Float64Array(wasm.memory.buffer, alloc.ptr, dim);
14160
- const result = new Array(dim);
14161
- for (let i = 0; i < dim; i++) {
14162
- result[i] = arr10[i];
14163
- }
14164
- return result;
14165
- }, writeVec2 = function(alloc, data) {
14166
- const arr10 = new Float64Array(wasm.memory.buffer, alloc.ptr, dim);
14167
- for (let i = 0; i < dim; i++) {
14168
- arr10[i] = data[i];
14169
- }
14170
- }, writeStage2 = function(stageIdx, data) {
14171
- const offset = stageIdx * dim;
14172
- const arr10 = new Float64Array(wasm.memory.buffer, stageAlloc.ptr, numStages * dim);
14173
- for (let i = 0; i < dim; i++) {
14174
- arr10[offset + i] = data[i];
14175
- }
14176
- }, trimStepNum2 = function(tn, tfn, hn) {
14177
- const next = tn + hn;
14178
- if (isForwards ? next > tfn : next < tfn) {
14179
- return tfn - tn;
14180
- }
14181
- return hn;
14182
- }, ongoing2 = function(tn, tfn) {
14183
- return isForwards ? tn < tfn : tn > tfn;
14184
- };
14185
- var readVec = readVec2, writeVec = writeVec2, writeStage = writeStage2, trimStepNum = trimStepNum2, ongoing = ongoing2;
14186
- const t = [t0];
14187
- const y = [y0.slice()];
14188
- let n = 0;
14189
- let iter = 0;
14190
- while (ongoing2(t[n], tf)) {
14191
- h = trimStepNum2(t[n], tf, h);
14192
- writeVec2(yAlloc, y[n]);
14193
- const k0 = f(t[n], y[n]);
14194
- writeStage2(0, k0);
14195
- for (let s = 1; s < numStages; s++) {
14196
- wasm.vectorCopy(yAlloc.ptr, dim, tempAlloc.ptr);
14197
- for (let j = 0; j < a[s].length; j++) {
14198
- const aCoeff = a[s][j];
14199
- if (aCoeff === 0) continue;
14200
- const kjPtr = stageAlloc.ptr + j * dim * 8;
14201
- wasm.vectorScale(kjPtr, h * aCoeff, dim, yNewAlloc.ptr);
14202
- wasm.vectorAdd(tempAlloc.ptr, yNewAlloc.ptr, dim, tempAlloc.ptr);
14203
- }
14204
- const tStage = t[n] + c[s] * h;
14205
- const yStage = readVec2(tempAlloc);
14206
- const ks = f(tStage, yStage);
14207
- writeStage2(s, ks);
14208
- }
14209
- wasm.vectorCopy(yAlloc.ptr, dim, yNewAlloc.ptr);
14210
- new Float64Array(wasm.memory.buffer, errorAlloc.ptr, dim).fill(0);
14211
- for (let s = 0; s < numStages; s++) {
14212
- const ksPtr = stageAlloc.ptr + s * dim * 8;
14213
- if (b[s] !== 0) {
14214
- wasm.vectorScale(ksPtr, h * b[s], dim, tempAlloc.ptr);
14215
- wasm.vectorAdd(yNewAlloc.ptr, tempAlloc.ptr, dim, yNewAlloc.ptr);
14216
- }
14217
- if (deltaB[s] !== 0) {
14218
- wasm.vectorScale(ksPtr, deltaB[s], dim, tempAlloc.ptr);
14219
- wasm.vectorAdd(errorAlloc.ptr, tempAlloc.ptr, dim, errorAlloc.ptr);
14220
- }
14221
- }
14222
- const TE = wasm.maxError(errorAlloc.ptr, dim);
14223
- if (TE < tol && tol / TE > 1 / 4) {
14224
- t.push(t[n] + h);
14225
- y.push(readVec2(yNewAlloc));
14226
- n++;
14227
- }
14228
- const delta = wasm.computeStepAdjustment(TE, tol, 5, minDelta, maxDelta);
14229
- h = h * delta;
14230
- if (maxStepVal !== void 0 && Math.abs(h) > maxStepVal) {
14231
- h = isForwards ? maxStepVal : -maxStepVal;
14232
- } else if (minStepVal !== void 0 && Math.abs(h) < minStepVal) {
14233
- h = isForwards ? minStepVal : -minStepVal;
14234
- }
14235
- iter++;
14236
- if (iter > maxIter) {
14237
- throw new Error("Maximum number of iterations reached, try changing options");
14238
- }
14239
- }
14240
- return { t, y };
14241
- } finally {
14242
- wasmLoader.free(yAlloc.ptr);
14243
- wasmLoader.free(yNewAlloc.ptr);
14244
- wasmLoader.free(errorAlloc.ptr);
14245
- wasmLoader.free(tempAlloc.ptr);
14246
- wasmLoader.free(stageAlloc.ptr);
14247
- }
14248
- }
14249
13824
  function _rk(butcherTableau) {
14250
13825
  return function(f, tspan, y0, options) {
14251
13826
  const wrongTSpan = !(tspan.length === 2 && (tspan.every(isNumOrBig) || tspan.every(isUnit)));
@@ -14274,13 +13849,6 @@ var createSolveODE = /* @__PURE__ */ factory(
14274
13849
  throw new Error('Inconsistent type of "t" dependant variables');
14275
13850
  }
14276
13851
  const hasBigNumbers = [t0, tf, ...y0, maxStep, minStep].some(isBigNumber);
14277
- if (!hasBigNumbers && !tspan.some(isUnit) && _isPlainNumberArray(y0)) {
14278
- try {
14279
- const wasmResult = _rkWasmLoop(f, tspan, y0, options, butcherTableau);
14280
- if (wasmResult !== null) return wasmResult;
14281
- } catch {
14282
- }
14283
- }
14284
13852
  const steps = 1;
14285
13853
  const tol = options.tol ? options.tol : 1e-4;
14286
13854
  const minDelta = options.minDelta ? options.minDelta : 0.2;
@@ -14556,6 +14124,109 @@ function quad(f, a, b, opts) {
14556
14124
  return panel(a, b, 0);
14557
14125
  }
14558
14126
 
14127
+ // src/numeric/rational-nullspace.ts
14128
+ import { Fraction as Fraction2, isFraction as isFraction2 } from "@danielsimonjr/mathts-core";
14129
+ function gcd2(a, b) {
14130
+ let x = a < 0n ? -a : a;
14131
+ let y = b < 0n ? -b : b;
14132
+ while (y !== 0n) {
14133
+ const t = y;
14134
+ y = x % y;
14135
+ x = t;
14136
+ }
14137
+ return x;
14138
+ }
14139
+ function lcm2(a, b) {
14140
+ if (a === 0n || b === 0n) return 0n;
14141
+ return a / gcd2(a, b) * b;
14142
+ }
14143
+ function entryToFraction(value, row2, col) {
14144
+ if (isFraction2(value)) return value;
14145
+ if (typeof value !== "number" || !Number.isFinite(value)) {
14146
+ throw new TypeError(
14147
+ `rationalNullspace: entry [${row2}, ${col}] must be a finite number or a Fraction`
14148
+ );
14149
+ }
14150
+ return Number.isInteger(value) ? new Fraction2(value, 1) : Fraction2.fromNumber(value);
14151
+ }
14152
+ function integerize(vec) {
14153
+ let scale4 = 1n;
14154
+ for (const f of vec) {
14155
+ if (f.numerator !== 0n) scale4 = lcm2(scale4, f.denominator);
14156
+ }
14157
+ const ints = vec.map((f) => f.numerator * scale4 / f.denominator);
14158
+ let content2 = 0n;
14159
+ for (const x of ints) {
14160
+ if (x !== 0n) content2 = gcd2(content2, x);
14161
+ }
14162
+ if (content2 === 0n) content2 = 1n;
14163
+ const reduced = ints.map((x) => x / content2);
14164
+ const first = reduced.find((x) => x !== 0n) ?? 0n;
14165
+ const sign3 = first < 0n ? -1n : 1n;
14166
+ return reduced.map((x) => new Fraction2(sign3 * x, 1n));
14167
+ }
14168
+ function rref(matrix2) {
14169
+ const rows = matrix2.length;
14170
+ const cols = rows === 0 ? 0 : matrix2[0].length;
14171
+ const pivotCols = [];
14172
+ let r = 0;
14173
+ for (let c = 0; c < cols && r < rows; c++) {
14174
+ let pivotRow = -1;
14175
+ for (let i = r; i < rows; i++) {
14176
+ if (matrix2[i][c].numerator !== 0n) {
14177
+ pivotRow = i;
14178
+ break;
14179
+ }
14180
+ }
14181
+ if (pivotRow === -1) continue;
14182
+ if (pivotRow !== r) {
14183
+ const swap = matrix2[r];
14184
+ matrix2[r] = matrix2[pivotRow];
14185
+ matrix2[pivotRow] = swap;
14186
+ }
14187
+ const pivot = matrix2[r][c];
14188
+ for (let j = 0; j < cols; j++) matrix2[r][j] = matrix2[r][j].div(pivot);
14189
+ for (let i = 0; i < rows; i++) {
14190
+ if (i === r || matrix2[i][c].numerator === 0n) continue;
14191
+ const factor2 = matrix2[i][c];
14192
+ for (let j = 0; j < cols; j++) {
14193
+ matrix2[i][j] = matrix2[i][j].sub(factor2.mul(matrix2[r][j]));
14194
+ }
14195
+ }
14196
+ pivotCols.push(c);
14197
+ r++;
14198
+ }
14199
+ return pivotCols;
14200
+ }
14201
+ function rationalNullspace(matrix2) {
14202
+ if (matrix2.length === 0) return { basis: [], rank: 0 };
14203
+ const cols = matrix2[0].length;
14204
+ for (let i = 0; i < matrix2.length; i++) {
14205
+ if (!Array.isArray(matrix2[i]) || matrix2[i].length !== cols) {
14206
+ throw new TypeError(
14207
+ `rationalNullspace: row ${i} has length ${matrix2[i]?.length ?? "n/a"}; expected ${cols}`
14208
+ );
14209
+ }
14210
+ }
14211
+ const reduced = matrix2.map((row2, i) => row2.map((value, j) => entryToFraction(value, i, j)));
14212
+ const pivotCols = rref(reduced);
14213
+ const pivotSet = new Set(pivotCols);
14214
+ const basis = [];
14215
+ const zero = new Fraction2(0n, 1n);
14216
+ const one = new Fraction2(1n, 1n);
14217
+ for (let free = 0; free < cols; free++) {
14218
+ if (pivotSet.has(free)) continue;
14219
+ const vec = new Array(cols);
14220
+ for (let j = 0; j < cols; j++) vec[j] = zero;
14221
+ vec[free] = one;
14222
+ for (let i = 0; i < pivotCols.length; i++) {
14223
+ vec[pivotCols[i]] = zero.sub(reduced[i][free]);
14224
+ }
14225
+ basis.push(integerize(vec));
14226
+ }
14227
+ return { basis, rank: pivotCols.length };
14228
+ }
14229
+
14559
14230
  // src/numeric/solveParabolicPDE.ts
14560
14231
  function asSpaceFn(c, dflt) {
14561
14232
  if (c === void 0) return () => dflt;
@@ -15121,8 +14792,126 @@ function solveDDE(f, tspan, history, delays, options = {}) {
15121
14792
  };
15122
14793
  }
15123
14794
 
14795
+ // src/numeric/gauss-legendre4.ts
14796
+ var SQRT3_OVER_6 = Math.sqrt(3) / 6;
14797
+ var GL4_C = [0.5 - SQRT3_OVER_6, 0.5 + SQRT3_OVER_6];
14798
+ var GL4_A = [
14799
+ [0.25, 0.25 - SQRT3_OVER_6],
14800
+ [0.25 + SQRT3_OVER_6, 0.25]
14801
+ ];
14802
+ var GL4_B = [0.5, 0.5];
14803
+ var GL4ConvergenceError = class extends Error {
14804
+ constructor(message = "Picard iteration did not converge") {
14805
+ super(message);
14806
+ this.name = "GL4ConvergenceError";
14807
+ }
14808
+ };
14809
+ function assertFiniteVector(label, v) {
14810
+ for (let i = 0; i < v.length; i++) {
14811
+ if (!Number.isFinite(v[i])) {
14812
+ throw new TypeError(`${label}[${i}] must be a finite number`);
14813
+ }
14814
+ }
14815
+ }
14816
+ function gaussLegendre4(f, y0, tspan, options) {
14817
+ if (y0.length === 0) {
14818
+ throw new TypeError("y0 must be a non-empty vector");
14819
+ }
14820
+ assertFiniteVector("y0", y0);
14821
+ const t0 = tspan[0];
14822
+ const t1 = tspan[1];
14823
+ if (!Number.isFinite(t0) || !Number.isFinite(t1)) {
14824
+ throw new TypeError("tspan entries must be finite numbers");
14825
+ }
14826
+ const picardTol = options?.picardTol ?? 1e-12;
14827
+ const picardMaxIter = options?.picardMaxIter ?? 64;
14828
+ if (!(picardTol > 0) || !Number.isFinite(picardTol)) {
14829
+ throw new TypeError("picardTol must be a positive finite number");
14830
+ }
14831
+ if (!Number.isInteger(picardMaxIter) || picardMaxIter < 1) {
14832
+ throw new TypeError("picardMaxIter must be a positive integer");
14833
+ }
14834
+ if (t0 === t1) {
14835
+ return { t: [t0], y: [y0.slice()] };
14836
+ }
14837
+ const span = t1 - t0;
14838
+ let nSteps;
14839
+ if (options?.steps !== void 0) {
14840
+ nSteps = options.steps;
14841
+ if (!Number.isInteger(nSteps) || nSteps < 1) {
14842
+ throw new TypeError("steps must be a positive integer");
14843
+ }
14844
+ } else if (options?.h !== void 0) {
14845
+ const hAbs = options.h;
14846
+ if (!(hAbs > 0) || !Number.isFinite(hAbs)) {
14847
+ throw new TypeError("h must be a positive finite number");
14848
+ }
14849
+ nSteps = Math.max(1, Math.ceil(Math.abs(span) / hAbs));
14850
+ } else {
14851
+ nSteps = 100;
14852
+ }
14853
+ const h = span / nSteps;
14854
+ const n = y0.length;
14855
+ const c0 = GL4_C[0];
14856
+ const c1 = GL4_C[1];
14857
+ const a00 = GL4_A[0][0];
14858
+ const a01 = GL4_A[0][1];
14859
+ const a10 = GL4_A[1][0];
14860
+ const a11 = GL4_A[1][1];
14861
+ const b0 = GL4_B[0];
14862
+ const b1 = GL4_B[1];
14863
+ const t = [t0];
14864
+ const y = [y0.slice()];
14865
+ let tn = t0;
14866
+ let yn = y0.slice();
14867
+ for (let step = 0; step < nSteps; step++) {
14868
+ let Y0 = yn.slice();
14869
+ let Y1 = yn.slice();
14870
+ let converged = false;
14871
+ const next = new Array(n);
14872
+ for (let iter = 0; iter < picardMaxIter; iter++) {
14873
+ const k0 = f(tn + c0 * h, Y0);
14874
+ const k1 = f(tn + c1 * h, Y1);
14875
+ if (k0.length !== n || k1.length !== n) {
14876
+ throw new TypeError(`f must return a vector of length ${n}`);
14877
+ }
14878
+ assertFiniteVector("f(t, y)", k0);
14879
+ assertFiniteVector("f(t, y)", k1);
14880
+ let maxDiff = 0;
14881
+ const nY0 = new Array(n);
14882
+ const nY1 = new Array(n);
14883
+ for (let i = 0; i < n; i++) {
14884
+ nY0[i] = yn[i] + h * (a00 * k0[i] + a01 * k1[i]);
14885
+ nY1[i] = yn[i] + h * (a10 * k0[i] + a11 * k1[i]);
14886
+ const d0 = Math.abs(nY0[i] - Y0[i]);
14887
+ const d1 = Math.abs(nY1[i] - Y1[i]);
14888
+ if (d0 > maxDiff) maxDiff = d0;
14889
+ if (d1 > maxDiff) maxDiff = d1;
14890
+ }
14891
+ Y0 = nY0;
14892
+ Y1 = nY1;
14893
+ if (maxDiff <= picardTol) {
14894
+ for (let i = 0; i < n; i++) {
14895
+ next[i] = yn[i] + h * (b0 * k0[i] + b1 * k1[i]);
14896
+ }
14897
+ converged = true;
14898
+ break;
14899
+ }
14900
+ }
14901
+ if (!converged) {
14902
+ throw new GL4ConvergenceError(
14903
+ `Picard iteration did not converge within ${picardMaxIter} iterations (step h=${h})`
14904
+ );
14905
+ }
14906
+ tn += h;
14907
+ yn = next;
14908
+ t.push(tn);
14909
+ y.push(yn.slice());
14910
+ }
14911
+ return { t, y };
14912
+ }
14913
+
15124
14914
  // src/typed/numeric.ts
15125
- var NUMERIC_WASM_THRESHOLD = 16;
15126
14915
  function findRoot(f, a, b, opts) {
15127
14916
  const tol = opts?.tol ?? 1e-12;
15128
14917
  const maxIter = opts?.maxIter ?? 100;
@@ -15312,27 +15101,6 @@ function globalMinimize(f, bounds, opts) {
15312
15101
  function leastSquares(A, b) {
15313
15102
  const m = A.length;
15314
15103
  const n = A[0].length;
15315
- if (m >= NUMERIC_WASM_THRESHOLD) {
15316
- const wasm = wasmLoader.getModule();
15317
- if (wasm) {
15318
- try {
15319
- const flatA = new Float64Array(m * n);
15320
- for (let i = 0; i < m; i++) for (let j = 0; j < n; j++) flatA[i * n + j] = A[i][j];
15321
- const aAlloc = wasmLoader.allocateFloat64Array(flatA);
15322
- const bAlloc = wasmLoader.allocateFloat64Array(new Float64Array(b));
15323
- const xAlloc = wasmLoader.allocateFloat64Array(new Float64Array(n));
15324
- try {
15325
- wasm.least_squares_wasm(aAlloc.ptr, bAlloc.ptr, m, n, xAlloc.ptr);
15326
- return Array.from(xAlloc.array);
15327
- } finally {
15328
- wasmLoader.free(aAlloc.ptr);
15329
- wasmLoader.free(bAlloc.ptr);
15330
- wasmLoader.free(xAlloc.ptr);
15331
- }
15332
- } catch {
15333
- }
15334
- }
15335
- }
15336
15104
  const AtA = Array.from({ length: n }, () => new Array(n).fill(0));
15337
15105
  for (let i = 0; i < n; i++) {
15338
15106
  for (let j = 0; j < n; j++) {
@@ -15475,28 +15243,6 @@ function pchip(xs, ys, x) {
15475
15243
  }
15476
15244
  function bezierCurve(controlPoints, t) {
15477
15245
  if (controlPoints.length === 0) throw new Error("bezierCurve: need at least 1 control point");
15478
- const nPts = controlPoints.length;
15479
- const dims = controlPoints[0].length;
15480
- if (nPts >= NUMERIC_WASM_THRESHOLD) {
15481
- const wasm = wasmLoader.getModule();
15482
- if (wasm) {
15483
- try {
15484
- const flat = new Float64Array(nPts * dims);
15485
- for (let i = 0; i < nPts; i++)
15486
- for (let d = 0; d < dims; d++) flat[i * dims + d] = controlPoints[i][d];
15487
- const ctrlAlloc = wasmLoader.allocateFloat64Array(flat);
15488
- const resultAlloc = wasmLoader.allocateFloat64Array(new Float64Array(dims));
15489
- try {
15490
- wasm.bezier_eval_wasm(ctrlAlloc.ptr, nPts, dims, t, resultAlloc.ptr);
15491
- return Array.from(resultAlloc.array);
15492
- } finally {
15493
- wasmLoader.free(ctrlAlloc.ptr);
15494
- wasmLoader.free(resultAlloc.ptr);
15495
- }
15496
- } catch {
15497
- }
15498
- }
15499
- }
15500
15246
  let points = controlPoints.map((p) => p.slice());
15501
15247
  while (points.length > 1) {
15502
15248
  const next = [];
@@ -15546,23 +15292,6 @@ function bspline(controlPoints, degree3, t) {
15546
15292
  }
15547
15293
  function loess(xs, ys, x, bandwidth = 0.3) {
15548
15294
  const n = xs.length;
15549
- if (n >= NUMERIC_WASM_THRESHOLD) {
15550
- const wasm = wasmLoader.getModule();
15551
- if (wasm) {
15552
- try {
15553
- const xsAlloc = wasmLoader.allocateFloat64Array(new Float64Array(xs));
15554
- const ysAlloc = wasmLoader.allocateFloat64Array(new Float64Array(ys));
15555
- try {
15556
- const result = wasm.loess_wasm(xsAlloc.ptr, ysAlloc.ptr, n, x, bandwidth);
15557
- return result;
15558
- } finally {
15559
- wasmLoader.free(xsAlloc.ptr);
15560
- wasmLoader.free(ysAlloc.ptr);
15561
- }
15562
- } catch {
15563
- }
15564
- }
15565
- }
15566
15295
  const k = Math.max(2, Math.ceil(bandwidth * n));
15567
15296
  const dists = xs.map((xi, i) => ({ dist: Math.abs(xi - x), i }));
15568
15297
  dists.sort((a2, b2) => a2.dist - b2.dist);
@@ -15589,63 +15318,6 @@ function loess(xs, ys, x, bandwidth = 0.3) {
15589
15318
  return a + b * x;
15590
15319
  }
15591
15320
  function griddata(points, values, xi, yi) {
15592
- const n = points.length;
15593
- if (n >= NUMERIC_WASM_THRESHOLD) {
15594
- const wasm = wasmLoader.getModule();
15595
- if (wasm) {
15596
- try {
15597
- const flatPts = new Float64Array(n * 2);
15598
- for (let i = 0; i < n; i++) {
15599
- flatPts[i * 2] = points[i][0];
15600
- flatPts[i * 2 + 1] = points[i][1];
15601
- }
15602
- const ni = xi.length * yi.length;
15603
- const flatXi = new Float64Array(ni);
15604
- const flatYi = new Float64Array(ni);
15605
- let idx = 0;
15606
- for (let j = 0; j < yi.length; j++) {
15607
- for (let i = 0; i < xi.length; i++) {
15608
- flatXi[idx] = xi[i];
15609
- flatYi[idx] = yi[j];
15610
- idx++;
15611
- }
15612
- }
15613
- const ptsAlloc = wasmLoader.allocateFloat64Array(flatPts);
15614
- const valsAlloc = wasmLoader.allocateFloat64Array(new Float64Array(values));
15615
- const xiAlloc = wasmLoader.allocateFloat64Array(flatXi);
15616
- const yiAlloc = wasmLoader.allocateFloat64Array(flatYi);
15617
- const resultAlloc = wasmLoader.allocateFloat64Array(new Float64Array(ni));
15618
- try {
15619
- wasm.griddata_wasm(
15620
- ptsAlloc.ptr,
15621
- valsAlloc.ptr,
15622
- n,
15623
- xiAlloc.ptr,
15624
- yiAlloc.ptr,
15625
- ni,
15626
- resultAlloc.ptr
15627
- );
15628
- const result2d = [];
15629
- let k = 0;
15630
- for (let j = 0; j < yi.length; j++) {
15631
- const row2 = [];
15632
- for (let i = 0; i < xi.length; i++) {
15633
- row2.push(resultAlloc.array[k++]);
15634
- }
15635
- result2d.push(row2);
15636
- }
15637
- return result2d;
15638
- } finally {
15639
- wasmLoader.free(ptsAlloc.ptr);
15640
- wasmLoader.free(valsAlloc.ptr);
15641
- wasmLoader.free(xiAlloc.ptr);
15642
- wasmLoader.free(yiAlloc.ptr);
15643
- wasmLoader.free(resultAlloc.ptr);
15644
- }
15645
- } catch {
15646
- }
15647
- }
15648
- }
15649
15321
  const result = [];
15650
15322
  const p = 2;
15651
15323
  for (let j = 0; j < yi.length; j++) {
@@ -15677,41 +15349,6 @@ function griddata(points, values, xi, yi) {
15677
15349
  function rbfInterpolate(points, values, xi, kernel = "gaussian") {
15678
15350
  const n = points.length;
15679
15351
  const dim = points[0].length;
15680
- if (kernel === "gaussian" && n >= NUMERIC_WASM_THRESHOLD) {
15681
- const wasm = wasmLoader.getModule();
15682
- if (wasm) {
15683
- try {
15684
- const ni = xi.length;
15685
- const flatPts = new Float64Array(n * dim);
15686
- for (let i = 0; i < n; i++)
15687
- for (let d = 0; d < dim; d++) flatPts[i * dim + d] = points[i][d];
15688
- const flatXi = new Float64Array(ni * dim);
15689
- for (let i = 0; i < ni; i++) for (let d = 0; d < dim; d++) flatXi[i * dim + d] = xi[i][d];
15690
- const ptsAlloc = wasmLoader.allocateFloat64Array(flatPts);
15691
- const valsAlloc = wasmLoader.allocateFloat64Array(new Float64Array(values));
15692
- const xiAlloc = wasmLoader.allocateFloat64Array(flatXi);
15693
- const resultAlloc = wasmLoader.allocateFloat64Array(new Float64Array(ni));
15694
- try {
15695
- wasm.rbf_interp_wasm(
15696
- ptsAlloc.ptr,
15697
- valsAlloc.ptr,
15698
- n,
15699
- dim,
15700
- xiAlloc.ptr,
15701
- ni,
15702
- resultAlloc.ptr
15703
- );
15704
- return Array.from(resultAlloc.array);
15705
- } finally {
15706
- wasmLoader.free(ptsAlloc.ptr);
15707
- wasmLoader.free(valsAlloc.ptr);
15708
- wasmLoader.free(xiAlloc.ptr);
15709
- wasmLoader.free(resultAlloc.ptr);
15710
- }
15711
- } catch {
15712
- }
15713
- }
15714
- }
15715
15352
  let sumDist = 0;
15716
15353
  let count2 = 0;
15717
15354
  for (let i = 0; i < Math.min(n, 50); i++) {
@@ -15963,40 +15600,9 @@ function solveODESystem(f, y0, tspan, opts) {
15963
15600
  const k2 = f(t + h / 2, vadd(y, k1, h / 2));
15964
15601
  const k3 = f(t + h / 2, vadd(y, k2, h / 2));
15965
15602
  const k4 = f(t + h, vadd(y, k3, h));
15966
- let yNew;
15967
- const wasmMod = n >= 4 ? wasmLoader.getModule() : null;
15968
- if (wasmMod) {
15969
- try {
15970
- const yArr = new Float64Array(y);
15971
- const kPacked = new Float64Array(4 * n);
15972
- for (let i = 0; i < n; i++) {
15973
- kPacked[i] = k1[i];
15974
- kPacked[n + i] = k2[i];
15975
- kPacked[2 * n + i] = k3[i];
15976
- kPacked[3 * n + i] = k4[i];
15977
- }
15978
- const yAlloc = wasmLoader.allocateFloat64Array(yArr);
15979
- const kAlloc = wasmLoader.allocateFloat64Array(kPacked);
15980
- const rAlloc = wasmLoader.allocateFloat64Array(new Float64Array(n));
15981
- try {
15982
- wasmMod.ode_system_rk4_step_wasm(yAlloc.ptr, kAlloc.ptr, h, n, rAlloc.ptr);
15983
- yNew = Array.from(rAlloc.array);
15984
- } finally {
15985
- wasmLoader.free(yAlloc.ptr);
15986
- wasmLoader.free(kAlloc.ptr);
15987
- wasmLoader.free(rAlloc.ptr);
15988
- }
15989
- } catch {
15990
- yNew = new Array(n);
15991
- for (let i = 0; i < n; i++) {
15992
- yNew[i] = y[i] + h / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]);
15993
- }
15994
- }
15995
- } else {
15996
- yNew = new Array(n);
15997
- for (let i = 0; i < n; i++) {
15998
- yNew[i] = y[i] + h / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]);
15999
- }
15603
+ const yNew = new Array(n);
15604
+ for (let i = 0; i < n; i++) {
15605
+ yNew[i] = y[i] + h / 6 * (k1[i] + 2 * k2[i] + 2 * k3[i] + k4[i]);
16000
15606
  }
16001
15607
  t += h;
16002
15608
  y = yNew;
@@ -16153,23 +15759,6 @@ function rank(A, tol = 1e-10) {
16153
15759
  const m = A.length;
16154
15760
  if (m === 0) return 0;
16155
15761
  const n = A[0].length;
16156
- if (m >= NUMERIC_WASM_THRESHOLD) {
16157
- const wasm = wasmLoader.getModule();
16158
- if (wasm) {
16159
- try {
16160
- const flat = new Float64Array(m * n);
16161
- for (let i = 0; i < m; i++) for (let j = 0; j < n; j++) flat[i * n + j] = A[i][j];
16162
- const aAlloc = wasmLoader.allocateFloat64Array(flat);
16163
- try {
16164
- const result = wasm.matrix_rank_wasm(aAlloc.ptr, m, n, tol);
16165
- return result;
16166
- } finally {
16167
- wasmLoader.free(aAlloc.ptr);
16168
- }
16169
- } catch {
16170
- }
16171
- }
16172
- }
16173
15762
  const M = A.map((row2) => row2.slice());
16174
15763
  let r = 0;
16175
15764
  for (let col = 0; col < n && r < m; col++) {
@@ -19305,7 +18894,7 @@ async function mannWhitneyTest(sample1, sample2, opts) {
19305
18894
  if (nTotal >= WASM_SORT_THRESHOLD) {
19306
18895
  const vals = new Float64Array(nTotal);
19307
18896
  for (let k = 0; k < nTotal; k++) vals[k] = combined[k].value;
19308
- const { argsortF64Dispatch: argsortF64Dispatch2 } = await import("./wasm-bridge-C44GQ3DS.js");
18897
+ const { argsortF64Dispatch: argsortF64Dispatch2 } = await import("./wasm-bridge-74YOKWIS.js");
19309
18898
  const idx = argsortF64Dispatch2(vals);
19310
18899
  const sortedCombined = new Array(nTotal);
19311
18900
  for (let k = 0; k < nTotal; k++) sortedCombined[k] = combined[idx[k]];
@@ -20186,12 +19775,12 @@ function rowReduce(A, tol = 1e-10) {
20186
19775
  return M;
20187
19776
  }
20188
19777
  function matrixRank(A, tol = 1e-10) {
20189
- const rref = rowReduce(A, tol);
19778
+ const rref2 = rowReduce(A, tol);
20190
19779
  let r = 0;
20191
- for (let i = 0; i < rref.length; i++) {
19780
+ for (let i = 0; i < rref2.length; i++) {
20192
19781
  let nonzero = false;
20193
- for (let j = 0; j < rref[i].length; j++) {
20194
- if (Math.abs(rref[i][j]) > tol) {
19782
+ for (let j = 0; j < rref2[i].length; j++) {
19783
+ if (Math.abs(rref2[i][j]) > tol) {
20195
19784
  nonzero = true;
20196
19785
  break;
20197
19786
  }
@@ -20531,11 +20120,11 @@ async function jordanForm(A) {
20531
20120
  return { J, P: P2 };
20532
20121
  }
20533
20122
  function matrixRankInternal(A, tol) {
20534
- const rref = rowReduce(A, tol);
20123
+ const rref2 = rowReduce(A, tol);
20535
20124
  let r = 0;
20536
- for (let i = 0; i < rref.length; i++) {
20537
- for (let j = 0; j < rref[i].length; j++) {
20538
- if (Math.abs(rref[i][j]) > tol) {
20125
+ for (let i = 0; i < rref2.length; i++) {
20126
+ for (let j = 0; j < rref2[i].length; j++) {
20127
+ if (Math.abs(rref2[i][j]) > tol) {
20539
20128
  r++;
20540
20129
  break;
20541
20130
  }
@@ -20595,11 +20184,11 @@ async function buildJordanBlocks(A, lambda, algebraicMult, geoMult, n, tol) {
20595
20184
  return blocks;
20596
20185
  }
20597
20186
  function findKernelVector(A, n, tol) {
20598
- const rref = rowReduce(A, tol);
20187
+ const rref2 = rowReduce(A, tol);
20599
20188
  const pivotCols = /* @__PURE__ */ new Set();
20600
20189
  for (let i = 0; i < n; i++) {
20601
20190
  for (let j = 0; j < n; j++) {
20602
- if (Math.abs(rref[i][j]) > tol) {
20191
+ if (Math.abs(rref2[i][j]) > tol) {
20603
20192
  pivotCols.add(j);
20604
20193
  break;
20605
20194
  }
@@ -20621,8 +20210,8 @@ function findKernelVector(A, n, tol) {
20621
20210
  v[freeCol] = 1;
20622
20211
  for (let i = 0; i < n; i++) {
20623
20212
  for (let j = 0; j < n; j++) {
20624
- if (Math.abs(rref[i][j]) > tol) {
20625
- v[j] = -rref[i][freeCol];
20213
+ if (Math.abs(rref2[i][j]) > tol) {
20214
+ v[j] = -rref2[i][freeCol];
20626
20215
  break;
20627
20216
  }
20628
20217
  }
@@ -20755,7 +20344,7 @@ import { enableGpu, disableGpu, isGpuEnabled as isGpuEnabled3, GPU_MIN_ELEMENTS
20755
20344
 
20756
20345
  // src/typed/relational.ts
20757
20346
  import naturalSort from "javascript-natural-sort";
20758
- import { mathTyped as mathTyped14, Complex as Complex6, BigNumber as BigNumber6, Fraction as Fraction2 } from "@danielsimonjr/mathts-core";
20347
+ import { mathTyped as mathTyped14, Complex as Complex6, BigNumber as BigNumber6, Fraction as Fraction3 } from "@danielsimonjr/mathts-core";
20759
20348
  var REL_TOL = 1e-12;
20760
20349
  var ABS_TOL = 1e-15;
20761
20350
  function numbersNearlyEqual(x, y) {
@@ -20779,7 +20368,7 @@ function typeNameOf(x) {
20779
20368
  if (typeof x === "string") return "string";
20780
20369
  if (x instanceof Complex6) return "Complex";
20781
20370
  if (x instanceof BigNumber6) return "BigNumber";
20782
- if (x instanceof Fraction2) return "Fraction";
20371
+ if (x instanceof Fraction3) return "Fraction";
20783
20372
  if (Array.isArray(x)) return "Array";
20784
20373
  if (typeof x === "object") return "Object";
20785
20374
  return typeof x;
@@ -20917,7 +20506,7 @@ function _numericCompare(x, y) {
20917
20506
  let ny;
20918
20507
  if (x instanceof BigNumber6) {
20919
20508
  nx = x.toNumber();
20920
- } else if (x instanceof Fraction2) {
20509
+ } else if (x instanceof Fraction3) {
20921
20510
  nx = x.valueOf();
20922
20511
  } else if (typeof x === "bigint") {
20923
20512
  nx = Number(x);
@@ -20926,7 +20515,7 @@ function _numericCompare(x, y) {
20926
20515
  }
20927
20516
  if (y instanceof BigNumber6) {
20928
20517
  ny = y.toNumber();
20929
- } else if (y instanceof Fraction2) {
20518
+ } else if (y instanceof Fraction3) {
20930
20519
  ny = y.valueOf();
20931
20520
  } else if (typeof y === "bigint") {
20932
20521
  ny = Number(y);
@@ -21346,7 +20935,7 @@ import {
21346
20935
  } from "@danielsimonjr/mathts-expression";
21347
20936
  import {
21348
20937
  Complex as Complex9,
21349
- Fraction as Fraction4,
20938
+ Fraction as Fraction5,
21350
20939
  I,
21351
20940
  PHI,
21352
20941
  SQRT2,
@@ -21354,11 +20943,12 @@ import {
21354
20943
  LN2 as LN22,
21355
20944
  LN10,
21356
20945
  LOG2E,
21357
- LOG10E
20946
+ LOG10E,
20947
+ Unit as Unit2
21358
20948
  } from "@danielsimonjr/mathts-core";
21359
20949
 
21360
20950
  // src/factories/scope.ts
21361
- import { mathTyped as mathTyped18, Complex as Complex7, Fraction as Fraction3, BigNumber as BigNumber8 } from "@danielsimonjr/mathts-core";
20951
+ import { mathTyped as mathTyped18, Complex as Complex7, Fraction as Fraction4, BigNumber as BigNumber8 } from "@danielsimonjr/mathts-core";
21362
20952
 
21363
20953
  // src/typed/typed-bridge.ts
21364
20954
  import { registerNativeTypes } from "@danielsimonjr/mathts-core";
@@ -21473,7 +21063,7 @@ var factoryScope = {
21473
21063
  // Class constructors (uppercase) — factories use `new BigNumber(...)` etc.
21474
21064
  Complex: Complex7,
21475
21065
  BigNumber: BigNumber8,
21476
- Fraction: Fraction3,
21066
+ Fraction: Fraction4,
21477
21067
  // Matrix bridge classes
21478
21068
  DenseMatrix: MathJSDenseMatrix,
21479
21069
  SparseMatrix: MathJSSparseMatrix,
@@ -21487,7 +21077,7 @@ var factoryScope = {
21487
21077
  if (typeof x === "number") return BigNumber8.fromNumber(x);
21488
21078
  return BigNumber8.fromNumber(Number(x.valueOf()));
21489
21079
  },
21490
- fraction: (n, d) => new Fraction3(n, d ?? 1),
21080
+ fraction: (n, d) => new Fraction4(n, d ?? 1),
21491
21081
  number: Number,
21492
21082
  // Matrix helper factories
21493
21083
  createDenseMatrix: (data) => new MathJSDenseMatrix(data),
@@ -22013,7 +21603,7 @@ var dependencies10 = ["typed", "BigNumber", "complex", "Fraction"];
22013
21603
  var createSign = /* @__PURE__ */ factory(
22014
21604
  name10,
22015
21605
  dependencies10,
22016
- ({ typed: typed3, BigNumber: BigNumber9, complex: complex3, Fraction: Fraction5 }) => {
21606
+ ({ typed: typed3, BigNumber: BigNumber9, complex: complex3, Fraction: Fraction6 }) => {
22017
21607
  return typed3(name10, {
22018
21608
  number: signNumber,
22019
21609
  Complex: function(x) {
@@ -22026,7 +21616,7 @@ var createSign = /* @__PURE__ */ factory(
22026
21616
  return x > 0n ? 1n : x < 0n ? -1n : 0n;
22027
21617
  },
22028
21618
  Fraction: function(x) {
22029
- return x.n === 0n ? new Fraction5(0) : new Fraction5(x.s);
21619
+ return x.n === 0n ? new Fraction6(0) : new Fraction6(x.s);
22030
21620
  },
22031
21621
  // deep map collection, skip zeros since sign(0) = 0
22032
21622
  "Array | Matrix": typed3.referToSelf(
@@ -23164,22 +22754,6 @@ var createLgamma = /* @__PURE__ */ factory(
23164
22754
  ];
23165
22755
  return typed3(name30, {
23166
22756
  Array: function(arr10) {
23167
- const wasm = wasmLoader.getModule();
23168
- if (wasm && arr10.length >= 100 && arr10.every((x) => typeof x === "number")) {
23169
- try {
23170
- const input = new Float64Array(arr10);
23171
- const inputAlloc = wasmLoader.allocateFloat64Array(input);
23172
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(arr10.length);
23173
- try {
23174
- wasm.lgammaArray(inputAlloc.ptr, arr10.length, resultAlloc.ptr);
23175
- return Array.from(resultAlloc.array);
23176
- } finally {
23177
- wasmLoader.free(inputAlloc.ptr);
23178
- wasmLoader.free(resultAlloc.ptr);
23179
- }
23180
- } catch {
23181
- }
23182
- }
23183
22757
  return arr10.map((x) => lgammaNumber(x));
23184
22758
  },
23185
22759
  number: lgammaNumber,
@@ -23516,27 +23090,7 @@ var createErf = /* @__PURE__ */ factory(
23516
23090
  return typed3("name", {
23517
23091
  number: erfNumber,
23518
23092
  "Array | Matrix": typed3.referToSelf(
23519
- (self) => (n) => {
23520
- if (Array.isArray(n) && n.length >= 100 && n.every((x) => typeof x === "number")) {
23521
- const wasm = wasmLoader.getModule();
23522
- if (wasm) {
23523
- try {
23524
- const input = new Float64Array(n);
23525
- const inputAlloc = wasmLoader.allocateFloat64Array(input);
23526
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(n.length);
23527
- try {
23528
- wasm.erfArray(inputAlloc.ptr, n.length, resultAlloc.ptr);
23529
- return Array.from(resultAlloc.array);
23530
- } finally {
23531
- wasmLoader.free(inputAlloc.ptr);
23532
- wasmLoader.free(resultAlloc.ptr);
23533
- }
23534
- } catch {
23535
- }
23536
- }
23537
- }
23538
- return deepMap(n, self);
23539
- }
23093
+ (self) => (n) => deepMap(n, self)
23540
23094
  )
23541
23095
  // TODO: For complex numbers, use the approximation for the Faddeeva function
23542
23096
  // from "More Efficient Computation of the Complex Error Function" (AMS)
@@ -24808,15 +24362,6 @@ function improveErrorMessage(err, fnName, value) {
24808
24362
  }
24809
24363
 
24810
24364
  // src/statistics/prod.ts
24811
- var WASM_PROD_THRESHOLD = 100;
24812
- function isFlatNumberArray(arr10) {
24813
- for (let i = 0; i < arr10.length; i++) {
24814
- if (typeof arr10[i] !== "number") {
24815
- return false;
24816
- }
24817
- }
24818
- return true;
24819
- }
24820
24365
  var name76 = "prod";
24821
24366
  var dependencies76 = ["typed", "config", "multiplyScalar", "numeric", "parseNumberWithConfig"];
24822
24367
  var createProd = /* @__PURE__ */ factory(
@@ -24844,22 +24389,6 @@ var createProd = /* @__PURE__ */ factory(
24844
24389
  }
24845
24390
  });
24846
24391
  function _prod(array) {
24847
- if (Array.isArray(array) && array.length >= WASM_PROD_THRESHOLD) {
24848
- if (isFlatNumberArray(array)) {
24849
- const wasm = wasmLoader.getModule();
24850
- if (wasm) {
24851
- try {
24852
- const alloc = wasmLoader.allocateFloat64Array(array);
24853
- try {
24854
- return wasm.statsProd(alloc.ptr, array.length);
24855
- } finally {
24856
- wasmLoader.free(alloc.ptr);
24857
- }
24858
- } catch {
24859
- }
24860
- }
24861
- }
24862
- }
24863
24392
  let prod2;
24864
24393
  deepForEach(array, function(value) {
24865
24394
  try {
@@ -25045,27 +24574,6 @@ var createParseNumberWithConfig = /* @__PURE__ */ factory(
25045
24574
  );
25046
24575
 
25047
24576
  // src/matrix/transpose.ts
25048
- var WASM_TRANSPOSE_THRESHOLD = 100;
25049
- function isPlainNumberMatrix(matrix2) {
25050
- for (let i = 0; i < matrix2.length; i++) {
25051
- const row2 = matrix2[i];
25052
- for (let j = 0; j < row2.length; j++) {
25053
- if (typeof row2[j] !== "number") {
25054
- return false;
25055
- }
25056
- }
25057
- }
25058
- return true;
25059
- }
25060
- function flattenToFloat64(matrix2, rows, cols) {
25061
- const result = new Float64Array(rows * cols);
25062
- for (let i = 0; i < rows; i++) {
25063
- for (let j = 0; j < cols; j++) {
25064
- result[i * cols + j] = matrix2[i][j];
25065
- }
25066
- }
25067
- return result;
25068
- }
25069
24577
  var name84 = "transpose";
25070
24578
  var dependencies84 = ["typed", "matrix"];
25071
24579
  var createTranspose = /* @__PURE__ */ factory(
@@ -25113,34 +24621,6 @@ var createTranspose = /* @__PURE__ */ factory(
25113
24621
  }
25114
24622
  function _denseTranspose(m, rows, columns) {
25115
24623
  const data = m._data;
25116
- const wasm = wasmLoader.getModule();
25117
- if (wasm && rows * columns >= WASM_TRANSPOSE_THRESHOLD && isPlainNumberMatrix(data)) {
25118
- try {
25119
- const flat = flattenToFloat64(data, rows, columns);
25120
- const input = wasmLoader.allocateFloat64Array(flat);
25121
- const output = wasmLoader.allocateFloat64ArrayEmpty(rows * columns);
25122
- try {
25123
- wasm.transpose(input.ptr, rows, columns, output.ptr);
25124
- const transposed2 = [];
25125
- for (let j = 0; j < columns; j++) {
25126
- const row2 = [];
25127
- for (let i = 0; i < rows; i++) {
25128
- row2[i] = output.array[j * rows + i];
25129
- }
25130
- transposed2[j] = row2;
25131
- }
25132
- return m.createDenseMatrix({
25133
- data: transposed2,
25134
- size: [columns, rows],
25135
- datatype: m._datatype
25136
- });
25137
- } finally {
25138
- wasmLoader.free(input.ptr);
25139
- wasmLoader.free(output.ptr);
25140
- }
25141
- } catch {
25142
- }
25143
- }
25144
24624
  const transposed = [];
25145
24625
  let transposedRow;
25146
24626
  for (let j = 0; j < columns; j++) {
@@ -25465,38 +24945,6 @@ var createDiag = /* @__PURE__ */ factory(
25465
24945
  );
25466
24946
 
25467
24947
  // src/matrix/kron.ts
25468
- var WASM_KRON_THRESHOLD = 64;
25469
- function isPlainNumber2D(arr10) {
25470
- for (let i = 0; i < arr10.length; i++) {
25471
- const row2 = arr10[i];
25472
- for (let j = 0; j < row2.length; j++) {
25473
- if (typeof row2[j] !== "number") {
25474
- return false;
25475
- }
25476
- }
25477
- }
25478
- return true;
25479
- }
25480
- function flatten2D(arr10, rows, cols) {
25481
- const result = new Float64Array(rows * cols);
25482
- for (let i = 0; i < rows; i++) {
25483
- for (let j = 0; j < cols; j++) {
25484
- result[i * cols + j] = arr10[i][j];
25485
- }
25486
- }
25487
- return result;
25488
- }
25489
- function unflatten2D(flat, rows, cols) {
25490
- const result = [];
25491
- for (let i = 0; i < rows; i++) {
25492
- const row2 = [];
25493
- for (let j = 0; j < cols; j++) {
25494
- row2.push(flat[i * cols + j]);
25495
- }
25496
- result.push(row2);
25497
- }
25498
- return result;
25499
- }
25500
24948
  var name90 = "kron";
25501
24949
  var dependencies90 = ["typed", "matrix", "multiplyScalar"];
25502
24950
  var createKron = /* @__PURE__ */ factory(
@@ -25527,37 +24975,6 @@ var createKron = /* @__PURE__ */ factory(
25527
24975
  while (bdim++ < d) b = [b];
25528
24976
  }
25529
24977
  if (d === 1) return _kron1d(a, b);
25530
- if (d === 2) {
25531
- const aSize = arraySize(a);
25532
- const bSize = arraySize(b);
25533
- const aRows = aSize[0];
25534
- const aCols = aSize[1];
25535
- const bRows = bSize[0];
25536
- const bCols = bSize[1];
25537
- const totalElements = aRows * aCols * bRows * bCols;
25538
- const wasm = wasmLoader.getModule();
25539
- if (wasm && totalElements >= WASM_KRON_THRESHOLD && isPlainNumber2D(a) && isPlainNumber2D(b)) {
25540
- try {
25541
- const aFlat = flatten2D(a, aRows, aCols);
25542
- const bFlat = flatten2D(b, bRows, bCols);
25543
- const aAlloc = wasmLoader.allocateFloat64Array(aFlat);
25544
- const bAlloc = wasmLoader.allocateFloat64Array(bFlat);
25545
- const resultRows = aRows * bRows;
25546
- const resultCols = aCols * bCols;
25547
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(resultRows * resultCols);
25548
- try {
25549
- wasm.laKron(aAlloc.ptr, aRows, aCols, bAlloc.ptr, bRows, bCols);
25550
- const resultFlat = new Float64Array(resultAlloc.array);
25551
- return unflatten2D(resultFlat, resultRows, resultCols);
25552
- } finally {
25553
- wasmLoader.free(aAlloc.ptr);
25554
- wasmLoader.free(bAlloc.ptr);
25555
- wasmLoader.free(resultAlloc.ptr);
25556
- }
25557
- } catch {
25558
- }
25559
- }
25560
- }
25561
24978
  return a.flatMap(
25562
24979
  (aSlice) => b.map((bSlice) => _kron(aSlice, bSlice, d - 1))
25563
24980
  );
@@ -25962,8 +25379,7 @@ var createTrace = /* @__PURE__ */ factory(
25962
25379
  );
25963
25380
 
25964
25381
  // src/matrix/det.ts
25965
- var WASM_DET_THRESHOLD = 25;
25966
- function isPlainNumberMatrix2(matrix2) {
25382
+ function isPlainNumberMatrix(matrix2) {
25967
25383
  for (let i = 0; i < matrix2.length; i++) {
25968
25384
  const row2 = matrix2[i];
25969
25385
  for (let j = 0; j < row2.length; j++) {
@@ -25974,15 +25390,6 @@ function isPlainNumberMatrix2(matrix2) {
25974
25390
  }
25975
25391
  return true;
25976
25392
  }
25977
- function flattenToFloat642(matrix2, rows, cols) {
25978
- const result = new Float64Array(rows * cols);
25979
- for (let i = 0; i < rows; i++) {
25980
- for (let j = 0; j < cols; j++) {
25981
- result[i * cols + j] = matrix2[i][j];
25982
- }
25983
- }
25984
- return result;
25985
- }
25986
25393
  var name96 = "det";
25987
25394
  var dependencies96 = [
25988
25395
  "typed",
@@ -26045,22 +25452,6 @@ var createDet = /* @__PURE__ */ factory(
26045
25452
  }
26046
25453
  });
26047
25454
  function _det(matrix3, rows, _cols) {
26048
- const wasm = wasmLoader.getModule();
26049
- if (wasm && rows * rows >= WASM_DET_THRESHOLD && isPlainNumberMatrix2(matrix3)) {
26050
- try {
26051
- const flat = flattenToFloat642(matrix3, rows, rows);
26052
- const a = wasmLoader.allocateFloat64Array(flat);
26053
- const work = wasmLoader.allocateFloat64ArrayEmpty(rows * rows);
26054
- try {
26055
- const result = wasm.laDet(a.ptr, rows, work.ptr);
26056
- return result;
26057
- } finally {
26058
- wasmLoader.free(a.ptr);
26059
- wasmLoader.free(work.ptr);
26060
- }
26061
- } catch {
26062
- }
26063
- }
26064
25455
  if (rows === 1) {
26065
25456
  return clone(matrix3[0][0]);
26066
25457
  } else if (rows === 2) {
@@ -26068,12 +25459,12 @@ var createDet = /* @__PURE__ */ factory(
26068
25459
  multiply2(matrix3[0][0], matrix3[1][1]),
26069
25460
  multiply2(matrix3[1][0], matrix3[0][1])
26070
25461
  );
26071
- } else if (rows === 3 && isPlainNumberMatrix2(matrix3)) {
25462
+ } else if (rows === 3 && isPlainNumberMatrix(matrix3)) {
26072
25463
  const a = matrix3[0][0], b = matrix3[0][1], c = matrix3[0][2];
26073
25464
  const d = matrix3[1][0], e = matrix3[1][1], f = matrix3[1][2];
26074
25465
  const g = matrix3[2][0], h = matrix3[2][1], i = matrix3[2][2];
26075
25466
  return a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
26076
- } else if (rows === 4 && isPlainNumberMatrix2(matrix3)) {
25467
+ } else if (rows === 4 && isPlainNumberMatrix(matrix3)) {
26077
25468
  const a00 = matrix3[0][0], a01 = matrix3[0][1];
26078
25469
  const a02 = matrix3[0][2], a03 = matrix3[0][3];
26079
25470
  const a10 = matrix3[1][0], a11 = matrix3[1][1];
@@ -26306,42 +25697,12 @@ function csTdfs(j, k, w, head, next, post, stack) {
26306
25697
  }
26307
25698
 
26308
25699
  // src/algebra/sparse/csAmd.ts
26309
- var WASM_AMD_THRESHOLD = 100;
26310
25700
  var name98 = "csAmd";
26311
25701
  var dependencies98 = ["add", "multiply", "transpose"];
26312
25702
  var createCsAmd = /* @__PURE__ */ factory(
26313
25703
  name98,
26314
25704
  dependencies98,
26315
25705
  ({ add: add5, multiply: multiply2, transpose: transpose5 }) => {
26316
- function _tryWasmAmd(a, n) {
26317
- const wasm = wasmLoader.getModule();
26318
- if (!wasm || !a._ptr || !a._index) return null;
26319
- const nnz = a._ptr[n];
26320
- if (nnz < WASM_AMD_THRESHOLD) return null;
26321
- try {
26322
- const colPtr = new Int32Array(a._ptr);
26323
- const rowIdx = new Int32Array(a._index);
26324
- const colPtrAlloc = wasmLoader.allocateInt32Array(colPtr);
26325
- const rowIdxAlloc = wasmLoader.allocateInt32Array(rowIdx);
26326
- const permAlloc = wasmLoader.allocateInt32ArrayEmpty(n);
26327
- const workAlloc = wasmLoader.allocateInt32ArrayEmpty(8 * (n + 1));
26328
- try {
26329
- wasm.amd(colPtrAlloc.ptr, rowIdxAlloc.ptr, n, permAlloc.ptr, workAlloc.ptr);
26330
- const perm = new Array(n);
26331
- for (let i = 0; i < n; i++) {
26332
- perm[i] = permAlloc.array[i];
26333
- }
26334
- return perm;
26335
- } finally {
26336
- wasmLoader.free(colPtrAlloc.ptr);
26337
- wasmLoader.free(rowIdxAlloc.ptr);
26338
- wasmLoader.free(permAlloc.ptr);
26339
- wasmLoader.free(workAlloc.ptr);
26340
- }
26341
- } catch {
26342
- }
26343
- return null;
26344
- }
26345
25706
  return function csAmd2(order, a) {
26346
25707
  if (!a || order <= 0 || order > 3) {
26347
25708
  return null;
@@ -26349,8 +25710,6 @@ var createCsAmd = /* @__PURE__ */ factory(
26349
25710
  const asize = a._size;
26350
25711
  const m = asize[0];
26351
25712
  const n = asize[1];
26352
- const wasmResult = _tryWasmAmd(a, n);
26353
- if (wasmResult !== null) return wasmResult;
26354
25713
  let lemax = 0;
26355
25714
  let dense = Math.max(16, 10 * Math.sqrt(n));
26356
25715
  dense = Math.min(n - 2, dense);
@@ -26720,50 +26079,12 @@ function csLeaf(i, j, w, first, maxfirst, prevleaf, ancestor) {
26720
26079
  }
26721
26080
 
26722
26081
  // src/algebra/sparse/csCounts.ts
26723
- var WASM_COUNTS_THRESHOLD = 50;
26724
26082
  var name99 = "csCounts";
26725
26083
  var dependencies99 = ["transpose"];
26726
26084
  var createCsCounts = /* @__PURE__ */ factory(
26727
26085
  name99,
26728
26086
  dependencies99,
26729
26087
  ({ transpose: transpose5 }) => {
26730
- function _tryWasmCounts(a, parent, post, n) {
26731
- const wasm = wasmLoader.getModule();
26732
- if (!wasm || n < WASM_COUNTS_THRESHOLD || !a._index || !a._ptr) return null;
26733
- try {
26734
- const indexAlloc = wasmLoader.allocateInt32Array(new Int32Array(a._index));
26735
- const ptrAlloc = wasmLoader.allocateInt32Array(new Int32Array(a._ptr));
26736
- const parentAlloc = wasmLoader.allocateInt32Array(new Int32Array(parent));
26737
- const postAlloc = wasmLoader.allocateInt32Array(new Int32Array(post));
26738
- const colCountAlloc = wasmLoader.allocateInt32ArrayEmpty(n);
26739
- const workAlloc = wasmLoader.allocateInt32ArrayEmpty(3 * n);
26740
- try {
26741
- wasm.symbolicCholesky(
26742
- indexAlloc.ptr,
26743
- ptrAlloc.ptr,
26744
- n,
26745
- parentAlloc.ptr,
26746
- postAlloc.ptr,
26747
- colCountAlloc.ptr,
26748
- workAlloc.ptr
26749
- );
26750
- const colcount = new Array(n);
26751
- for (let i = 0; i < n; i++) {
26752
- colcount[i] = colCountAlloc.array[i];
26753
- }
26754
- return colcount;
26755
- } finally {
26756
- wasmLoader.free(indexAlloc.ptr);
26757
- wasmLoader.free(ptrAlloc.ptr);
26758
- wasmLoader.free(parentAlloc.ptr);
26759
- wasmLoader.free(postAlloc.ptr);
26760
- wasmLoader.free(colCountAlloc.ptr);
26761
- wasmLoader.free(workAlloc.ptr);
26762
- }
26763
- } catch {
26764
- }
26765
- return null;
26766
- }
26767
26088
  return function csCounts2(a, parent, post, ata) {
26768
26089
  if (!a || !parent || !post) {
26769
26090
  return null;
@@ -26771,10 +26092,6 @@ var createCsCounts = /* @__PURE__ */ factory(
26771
26092
  const asize = a._size;
26772
26093
  const m = asize[0];
26773
26094
  const n = asize[1];
26774
- if (!ata) {
26775
- const wasmResult = _tryWasmCounts(a, parent, post, n);
26776
- if (wasmResult !== null) return wasmResult;
26777
- }
26778
26095
  let i, j, k, J, p, p0, p1;
26779
26096
  const s = 4 * n + (ata ? n + m + 1 : 0);
26780
26097
  const w = [];
@@ -27239,42 +26556,6 @@ function createSolveValidation({ DenseMatrix: DenseMatrix7 }) {
27239
26556
  }
27240
26557
 
27241
26558
  // src/algebra/solver/lsolve.ts
27242
- var WASM_LSOLVE_THRESHOLD = 16;
27243
- function isPlainNumberMatrix3(matrix2) {
27244
- for (let i = 0; i < matrix2.length; i++) {
27245
- const row2 = matrix2[i];
27246
- for (let j = 0; j < row2.length; j++) {
27247
- if (typeof row2[j] !== "number") {
27248
- return false;
27249
- }
27250
- }
27251
- }
27252
- return true;
27253
- }
27254
- function isPlainNumberVector(vec) {
27255
- for (let i = 0; i < vec.length; i++) {
27256
- if (typeof vec[i][0] !== "number") {
27257
- return false;
27258
- }
27259
- }
27260
- return true;
27261
- }
27262
- function flattenToFloat643(matrix2, rows, cols) {
27263
- const result = new Float64Array(rows * cols);
27264
- for (let i = 0; i < rows; i++) {
27265
- for (let j = 0; j < cols; j++) {
27266
- result[i * cols + j] = matrix2[i][j];
27267
- }
27268
- }
27269
- return result;
27270
- }
27271
- function vectorToFloat64(vec) {
27272
- const result = new Float64Array(vec.length);
27273
- for (let i = 0; i < vec.length; i++) {
27274
- result[i] = vec[i][0];
27275
- }
27276
- return result;
27277
- }
27278
26559
  var name102 = "lsolve";
27279
26560
  var dependencies102 = [
27280
26561
  "typed",
@@ -27319,38 +26600,6 @@ var createLsolve = /* @__PURE__ */ factory(
27319
26600
  const rows = m._size[0];
27320
26601
  const columns = m._size[1];
27321
26602
  const mdata = m._data;
27322
- const wasm = wasmLoader.getModule();
27323
- if (wasm && rows === columns && rows * rows >= WASM_LSOLVE_THRESHOLD && isPlainNumberMatrix3(mdata) && isPlainNumberVector(bdata)) {
27324
- try {
27325
- const lFlat = flattenToFloat643(mdata, rows, columns);
27326
- const bFlat = vectorToFloat64(bdata);
27327
- const lAlloc = wasmLoader.allocateFloat64Array(lFlat);
27328
- const bAlloc = wasmLoader.allocateFloat64Array(bFlat);
27329
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows);
27330
- try {
27331
- const success = wasm.laLsolve(lAlloc.ptr, bAlloc.ptr, rows, resultAlloc.ptr);
27332
- if (success === 0) {
27333
- throw new Error("Linear system cannot be solved since matrix is singular");
27334
- }
27335
- const x2 = [];
27336
- for (let i = 0; i < rows; i++) {
27337
- x2[i] = [resultAlloc.array[i]];
27338
- }
27339
- return new DenseMatrix7({
27340
- data: x2,
27341
- size: [rows, 1]
27342
- });
27343
- } finally {
27344
- wasmLoader.free(lAlloc.ptr);
27345
- wasmLoader.free(bAlloc.ptr);
27346
- wasmLoader.free(resultAlloc.ptr);
27347
- }
27348
- } catch (e) {
27349
- if (e instanceof Error && e.message.includes("singular")) {
27350
- throw e;
27351
- }
27352
- }
27353
- }
27354
26603
  const x = [];
27355
26604
  for (let j = 0; j < columns; j++) {
27356
26605
  const bj = bdata[j][0] || 0;
@@ -27564,42 +26813,6 @@ var createLsolveAll = /* @__PURE__ */ factory(
27564
26813
  );
27565
26814
 
27566
26815
  // src/algebra/solver/usolve.ts
27567
- var WASM_USOLVE_THRESHOLD = 16;
27568
- function isPlainNumberMatrix4(matrix2) {
27569
- for (let i = 0; i < matrix2.length; i++) {
27570
- const row2 = matrix2[i];
27571
- for (let j = 0; j < row2.length; j++) {
27572
- if (typeof row2[j] !== "number") {
27573
- return false;
27574
- }
27575
- }
27576
- }
27577
- return true;
27578
- }
27579
- function isPlainNumberVector2(vec) {
27580
- for (let i = 0; i < vec.length; i++) {
27581
- if (typeof vec[i][0] !== "number") {
27582
- return false;
27583
- }
27584
- }
27585
- return true;
27586
- }
27587
- function flattenToFloat644(matrix2, rows, cols) {
27588
- const result = new Float64Array(rows * cols);
27589
- for (let i = 0; i < rows; i++) {
27590
- for (let j = 0; j < cols; j++) {
27591
- result[i * cols + j] = matrix2[i][j];
27592
- }
27593
- }
27594
- return result;
27595
- }
27596
- function vectorToFloat642(vec) {
27597
- const result = new Float64Array(vec.length);
27598
- for (let i = 0; i < vec.length; i++) {
27599
- result[i] = vec[i][0];
27600
- }
27601
- return result;
27602
- }
27603
26816
  var name104 = "usolve";
27604
26817
  var dependencies104 = [
27605
26818
  "typed",
@@ -27644,38 +26857,6 @@ var createUsolve = /* @__PURE__ */ factory(
27644
26857
  const rows = m._size[0];
27645
26858
  const columns = m._size[1];
27646
26859
  const mdata = m._data;
27647
- const wasm = wasmLoader.getModule();
27648
- if (wasm && rows === columns && rows * rows >= WASM_USOLVE_THRESHOLD && isPlainNumberMatrix4(mdata) && isPlainNumberVector2(bdata)) {
27649
- try {
27650
- const uFlat = flattenToFloat644(mdata, rows, columns);
27651
- const bFlat = vectorToFloat642(bdata);
27652
- const uAlloc = wasmLoader.allocateFloat64Array(uFlat);
27653
- const bAlloc = wasmLoader.allocateFloat64Array(bFlat);
27654
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows);
27655
- try {
27656
- const success = wasm.laUsolve(uAlloc.ptr, bAlloc.ptr, rows, resultAlloc.ptr);
27657
- if (success === 0) {
27658
- throw new Error("Linear system cannot be solved since matrix is singular");
27659
- }
27660
- const x2 = [];
27661
- for (let i = 0; i < rows; i++) {
27662
- x2[i] = [resultAlloc.array[i]];
27663
- }
27664
- return new DenseMatrix7({
27665
- data: x2,
27666
- size: [rows, 1]
27667
- });
27668
- } finally {
27669
- wasmLoader.free(uAlloc.ptr);
27670
- wasmLoader.free(bAlloc.ptr);
27671
- wasmLoader.free(resultAlloc.ptr);
27672
- }
27673
- } catch (e) {
27674
- if (e instanceof Error && e.message.includes("singular")) {
27675
- throw e;
27676
- }
27677
- }
27678
- }
27679
26860
  const x = [];
27680
26861
  for (let j = columns - 1; j >= 0; j--) {
27681
26862
  const bj = bdata[j][0] || 0;
@@ -27911,7 +27092,7 @@ var createCbrt = /* @__PURE__ */ factory(
27911
27092
  matrix: matrix2,
27912
27093
  Complex: Complex13,
27913
27094
  BigNumber: BigNumber9,
27914
- Fraction: Fraction5
27095
+ Fraction: Fraction6
27915
27096
  }) => {
27916
27097
  return typed3(name106, {
27917
27098
  number: cbrtNumber,
@@ -27969,7 +27150,7 @@ var createCbrt = /* @__PURE__ */ factory(
27969
27150
  if (isBigNumber(value)) {
27970
27151
  return new BigNumber9(1).div(3);
27971
27152
  } else if (isFraction(value)) {
27972
- return new Fraction5(1, 3);
27153
+ return new Fraction6(1, 3);
27973
27154
  } else {
27974
27155
  return 1 / 3;
27975
27156
  }
@@ -28410,7 +27591,7 @@ var dependencies112 = ["typed", "config", "matrix", "BigNumber", "?Fraction"];
28410
27591
  var createXgcd = /* @__PURE__ */ factory(
28411
27592
  name112,
28412
27593
  dependencies112,
28413
- ({ typed: typed3, config: config2, matrix: matrix2, BigNumber: BigNumber9, Fraction: Fraction5 }) => {
27594
+ ({ typed: typed3, config: config2, matrix: matrix2, BigNumber: BigNumber9, Fraction: Fraction6 }) => {
28414
27595
  const typedSignatures = {
28415
27596
  "number, number": function(a, b) {
28416
27597
  const res = xgcdNumber(a, b);
@@ -28418,7 +27599,7 @@ var createXgcd = /* @__PURE__ */ factory(
28418
27599
  },
28419
27600
  "BigNumber, BigNumber": _xgcdBigNumber
28420
27601
  };
28421
- if (Fraction5) {
27602
+ if (Fraction6) {
28422
27603
  typedSignatures["Fraction, Fraction"] = _xgcdFraction;
28423
27604
  }
28424
27605
  return typed3(name112, typedSignatures);
@@ -28456,14 +27637,14 @@ var createXgcd = /* @__PURE__ */ factory(
28456
27637
  return config2.matrix === "Array" ? res : matrix2(res);
28457
27638
  }
28458
27639
  function _xgcdFraction(a, b) {
28459
- if (!Fraction5) {
27640
+ if (!Fraction6) {
28460
27641
  throw new Error("Fraction is not available");
28461
27642
  }
28462
27643
  let t;
28463
27644
  let q;
28464
27645
  let r;
28465
- const zero = new Fraction5(0);
28466
- const one = new Fraction5(1);
27646
+ const zero = new Fraction6(0);
27647
+ const one = new Fraction6(1);
28467
27648
  let x = zero;
28468
27649
  let lastx = one;
28469
27650
  let y = one;
@@ -28645,27 +27826,6 @@ var createConcat = /* @__PURE__ */ factory(
28645
27826
  );
28646
27827
 
28647
27828
  // src/matrix/inv.ts
28648
- var WASM_INV_THRESHOLD = 16;
28649
- function isPlainNumberMatrix5(matrix2) {
28650
- for (let i = 0; i < matrix2.length; i++) {
28651
- const row2 = matrix2[i];
28652
- for (let j = 0; j < row2.length; j++) {
28653
- if (typeof row2[j] !== "number") {
28654
- return false;
28655
- }
28656
- }
28657
- }
28658
- return true;
28659
- }
28660
- function flattenToFloat645(matrix2, rows, cols) {
28661
- const result = new Float64Array(rows * cols);
28662
- for (let i = 0; i < rows; i++) {
28663
- for (let j = 0; j < cols; j++) {
28664
- result[i * cols + j] = matrix2[i][j];
28665
- }
28666
- }
28667
- return result;
28668
- }
28669
27829
  var name116 = "inv";
28670
27830
  var dependencies116 = [
28671
27831
  "typed",
@@ -28734,38 +27894,6 @@ var createInv = /* @__PURE__ */ factory(
28734
27894
  });
28735
27895
  function _inv4(mat, rows, cols) {
28736
27896
  let r, s, f, value, temp;
28737
- const wasm = wasmLoader.getModule();
28738
- if (wasm && rows >= 3 && rows * rows >= WASM_INV_THRESHOLD && isPlainNumberMatrix5(mat)) {
28739
- try {
28740
- const flat = flattenToFloat645(mat, rows, rows);
28741
- const input = wasmLoader.allocateFloat64Array(flat);
28742
- const result = wasmLoader.allocateFloat64ArrayEmpty(rows * rows);
28743
- const work = wasmLoader.allocateFloat64ArrayEmpty(rows * 2 * rows);
28744
- try {
28745
- const success = wasm.laInv(input.ptr, rows, result.ptr, work.ptr);
28746
- if (success === 0) {
28747
- throw Error("Cannot calculate inverse, determinant is zero");
28748
- }
28749
- const invMatrix = [];
28750
- for (let i = 0; i < rows; i++) {
28751
- const row2 = [];
28752
- for (let j = 0; j < rows; j++) {
28753
- row2[j] = result.array[i * rows + j];
28754
- }
28755
- invMatrix[i] = row2;
28756
- }
28757
- return invMatrix;
28758
- } finally {
28759
- wasmLoader.free(input.ptr);
28760
- wasmLoader.free(result.ptr);
28761
- wasmLoader.free(work.ptr);
28762
- }
28763
- } catch (e) {
28764
- if (e instanceof Error && e.message.includes("determinant is zero")) {
28765
- throw e;
28766
- }
28767
- }
28768
- }
28769
27897
  if (rows === 1) {
28770
27898
  value = mat[0][0];
28771
27899
  if (value === 0) {
@@ -29250,7 +28378,7 @@ var createBernoulli = /* @__PURE__ */ factory(
29250
28378
  isInteger: _isInteger,
29251
28379
  number: number2,
29252
28380
  BigNumber: BigNumber9,
29253
- Fraction: Fraction5
28381
+ Fraction: Fraction6
29254
28382
  }) => {
29255
28383
  const numberCache = [void 0];
29256
28384
  const fractionCache = [void 0];
@@ -29267,7 +28395,7 @@ var createBernoulli = /* @__PURE__ */ factory(
29267
28395
  ),
29268
28396
  "bigint | Fraction": (index) => _bernoulli(
29269
28397
  number2(index),
29270
- (n) => new Fraction5(n),
28398
+ (n) => new Fraction6(n),
29271
28399
  fractionCache,
29272
28400
  (a, b) => a.add(b),
29273
28401
  (a, b) => a.mul(b),
@@ -29826,6 +28954,8 @@ var dependencies127 = ["typed", "add", "multiply", "Complex", "number"];
29826
28954
  var createZpk2tf = /* @__PURE__ */ factory(
29827
28955
  name127,
29828
28956
  dependencies127,
28957
+ // The deps are untyped (`any`), so the result is declared: without it the export
28958
+ // inherits `any` from `typed(...)` instead of being a TypedFunction like the rest.
29829
28959
  ({ typed: typed3, add: add5, multiply: multiply2, Complex: Complex13, number: number2 }) => {
29830
28960
  return typed3(name127, {
29831
28961
  "Array,Array,number": function(z, p, k) {
@@ -29885,7 +29015,7 @@ import { _switch as _switch2 } from "@danielsimonjr/mathts-core/internal";
29885
29015
 
29886
29016
  // src/statistics/cumsum.ts
29887
29017
  import { neumaierCumsum as neumaierCumsum2 } from "@danielsimonjr/mathts-core";
29888
- function isFlatNumberArray2(arr10) {
29018
+ function isFlatNumberArray(arr10) {
29889
29019
  for (let i = 0; i < arr10.length; i++) {
29890
29020
  if (typeof arr10[i] !== "number") {
29891
29021
  return false;
@@ -29932,7 +29062,7 @@ var createCumSum = /* @__PURE__ */ factory(
29932
29062
  if (array.length === 0) {
29933
29063
  return [];
29934
29064
  }
29935
- if (isFlatNumberArray2(array)) {
29065
+ if (isFlatNumberArray(array)) {
29936
29066
  const result = new Array(array.length);
29937
29067
  neumaierCumsum2(array, result);
29938
29068
  return result;
@@ -29984,7 +29114,7 @@ var createCumSum = /* @__PURE__ */ factory(
29984
29114
 
29985
29115
  // src/statistics/sum.ts
29986
29116
  import { pairwiseSum as pairwiseSum2 } from "@danielsimonjr/mathts-core";
29987
- function isFlatNumberArray3(arr10) {
29117
+ function isFlatNumberArray2(arr10) {
29988
29118
  for (let i = 0; i < arr10.length; i++) {
29989
29119
  if (typeof arr10[i] !== "number") {
29990
29120
  return false;
@@ -30016,7 +29146,7 @@ var createSum = /* @__PURE__ */ factory(
30016
29146
  }
30017
29147
  });
30018
29148
  function _sum(array) {
30019
- if (Array.isArray(array) && isFlatNumberArray3(array)) {
29149
+ if (Array.isArray(array) && isFlatNumberArray2(array)) {
30020
29150
  return pairwiseSum2(array);
30021
29151
  }
30022
29152
  let sum3;
@@ -30824,7 +29954,6 @@ var createMatAlgo10xSids = /* @__PURE__ */ factory(
30824
29954
  );
30825
29955
 
30826
29956
  // src/arithmetic/gcd.ts
30827
- var WASM_GCD_ARRAY_THRESHOLD = 50;
30828
29957
  var name140 = "gcd";
30829
29958
  var dependencies140 = [
30830
29959
  "typed",
@@ -30898,14 +30027,9 @@ var createGcd = /* @__PURE__ */ factory(
30898
30027
  ),
30899
30028
  Array: typed3.referToSelf((self) => (array) => {
30900
30029
  if (array.length === 1 && Array.isArray(array[0]) && is1d(array[0])) {
30901
- const flat = array[0];
30902
- const wasmResult = _tryWasmGcdArray(flat);
30903
- if (wasmResult !== null) return wasmResult;
30904
- return self(...flat);
30030
+ return self(...array[0]);
30905
30031
  }
30906
30032
  if (is1d(array)) {
30907
- const wasmResult = _tryWasmGcdArray(array);
30908
- if (wasmResult !== null) return wasmResult;
30909
30033
  return self(...array);
30910
30034
  }
30911
30035
  throw new Error("gcd() supports only 1d matrices!");
@@ -30915,27 +30039,6 @@ var createGcd = /* @__PURE__ */ factory(
30915
30039
  })
30916
30040
  }
30917
30041
  );
30918
- function _tryWasmGcdArray(array) {
30919
- if (array.length < WASM_GCD_ARRAY_THRESHOLD) return null;
30920
- const wasm = wasmLoader.getModule();
30921
- if (!wasm) return null;
30922
- const n = array.length;
30923
- const data = new Float64Array(n);
30924
- for (let i = 0; i < n; i++) {
30925
- if (typeof array[i] !== "number" || !isInteger(array[i])) {
30926
- return null;
30927
- }
30928
- data[i] = array[i];
30929
- }
30930
- const alloc = wasmLoader.allocateFloat64Array(data);
30931
- try {
30932
- return wasm.gcdArray(alloc.ptr, n);
30933
- } catch {
30934
- return null;
30935
- } finally {
30936
- wasmLoader.free(alloc.ptr);
30937
- }
30938
- }
30939
30042
  function _gcdNumber(a, b) {
30940
30043
  if (!isInteger(a) || !isInteger(b)) {
30941
30044
  throw new Error("Parameters in function gcd must be integer numbers");
@@ -32137,7 +31240,7 @@ var createCompare = /* @__PURE__ */ factory(
32137
31240
  equalScalar: equalScalar3,
32138
31241
  matrix: matrix2,
32139
31242
  BigNumber: BigNumber9,
32140
- Fraction: Fraction5,
31243
+ Fraction: Fraction6,
32141
31244
  DenseMatrix: DenseMatrix7,
32142
31245
  concat: concat3
32143
31246
  }) => {
@@ -32165,7 +31268,7 @@ var createCompare = /* @__PURE__ */ factory(
32165
31268
  return x === y ? 0n : x > y ? 1n : -1n;
32166
31269
  },
32167
31270
  "Fraction, Fraction": function(x, y) {
32168
- return new Fraction5(x.compare(y));
31271
+ return new Fraction6(x.compare(y));
32169
31272
  },
32170
31273
  "Complex, Complex": function() {
32171
31274
  throw new TypeError("No ordering relation is defined for complex numbers");
@@ -32841,8 +31944,8 @@ var createInvmod = /* @__PURE__ */ factory(
32841
31944
  if (equal2(b, 0)) throw new Error("Divisor must be non zero");
32842
31945
  const res = xgcd2(a, b);
32843
31946
  const resVal = res.valueOf();
32844
- const [gcd2, invValue] = resVal;
32845
- if (!equal2(gcd2, 1)) return NaN;
31947
+ const [gcd3, invValue] = resVal;
31948
+ if (!equal2(gcd3, 1)) return NaN;
32846
31949
  let inv3 = mod3(invValue, b);
32847
31950
  if (smaller2(inv3, 0)) inv3 = add5(inv3, b);
32848
31951
  return inv3;
@@ -32988,15 +32091,6 @@ var createComposition = /* @__PURE__ */ factory(
32988
32091
  );
32989
32092
 
32990
32093
  // src/matrix/partitionSelect.ts
32991
- var WASM_PARTITION_SELECT_THRESHOLD = 100;
32992
- function isFlatNumberArray4(arr10) {
32993
- for (let i = 0; i < arr10.length; i++) {
32994
- if (typeof arr10[i] !== "number") {
32995
- return false;
32996
- }
32997
- }
32998
- return true;
32999
- }
33000
32094
  var name171 = "partitionSelect";
33001
32095
  var dependencies171 = ["typed", "isNumeric", "isNaN", "compare"];
33002
32096
  var createPartitionSelect = /* @__PURE__ */ factory(
@@ -33042,29 +32136,6 @@ var createPartitionSelect = /* @__PURE__ */ factory(
33042
32136
  return arr10[i];
33043
32137
  }
33044
32138
  }
33045
- const wasm = wasmLoader.getModule();
33046
- if (wasm && arr10.length >= WASM_PARTITION_SELECT_THRESHOLD && isFlatNumberArray4(arr10)) {
33047
- const isAsc = compare3 === asc;
33048
- const isDesc = compare3 === desc;
33049
- if (isAsc || isDesc) {
33050
- try {
33051
- const effectiveK = isDesc ? arr10.length - 1 - k : k;
33052
- const data = wasmLoader.allocateFloat64Array(arr10);
33053
- const work = wasmLoader.allocateFloat64ArrayEmpty(arr10.length);
33054
- try {
33055
- const result = wasm.partitionSelect(data.ptr, arr10.length, effectiveK, work.ptr);
33056
- for (let i = 0; i < arr10.length; i++) {
33057
- arr10[i] = work.array[i];
33058
- }
33059
- return result;
33060
- } finally {
33061
- wasmLoader.free(data.ptr);
33062
- wasmLoader.free(work.ptr);
33063
- }
33064
- } catch {
33065
- }
33066
- }
33067
- }
33068
32139
  let from = 0;
33069
32140
  let to3 = arr10.length - 1;
33070
32141
  while (from < to3) {
@@ -33215,9 +32286,9 @@ var createPinv = /* @__PURE__ */ factory(
33215
32286
  return M;
33216
32287
  }
33217
32288
  function _rankFact(mat, rows, cols) {
33218
- const rref = _rref(mat, rows, cols);
33219
- const C = mat.map((row2) => row2.filter((_, j) => j < rows && !_isZero(dot9(rref[j], rref[j]))));
33220
- const F = rref.filter((_, i) => !_isZero(dot9(rref[i], rref[i])));
32289
+ const rref2 = _rref(mat, rows, cols);
32290
+ const C = mat.map((row2) => row2.filter((_, j) => j < rows && !_isZero(dot9(rref2[j], rref2[j]))));
32291
+ const F = rref2.filter((_, i) => !_isZero(dot9(rref2[i], rref2[i])));
33221
32292
  return { C, F };
33222
32293
  }
33223
32294
  function _isZero(x) {
@@ -33233,27 +32304,6 @@ var createPinv = /* @__PURE__ */ factory(
33233
32304
  );
33234
32305
 
33235
32306
  // src/algebra/decomposition/qr.ts
33236
- var WASM_QR_THRESHOLD = 16;
33237
- function isPlainNumberMatrix6(matrix2) {
33238
- for (let i = 0; i < matrix2.length; i++) {
33239
- const row2 = matrix2[i];
33240
- for (let j = 0; j < row2.length; j++) {
33241
- if (typeof row2[j] !== "number") {
33242
- return false;
33243
- }
33244
- }
33245
- }
33246
- return true;
33247
- }
33248
- function flattenToFloat646(matrix2, rows, cols) {
33249
- const result = new Float64Array(rows * cols);
33250
- for (let i = 0; i < rows; i++) {
33251
- for (let j = 0; j < cols; j++) {
33252
- result[i * cols + j] = matrix2[i][j];
33253
- }
33254
- }
33255
- return result;
33256
- }
33257
32307
  var name173 = "qr";
33258
32308
  var dependencies173 = [
33259
32309
  "typed",
@@ -33313,44 +32363,6 @@ var createQr = /* @__PURE__ */ factory(
33313
32363
  function _denseQRimpl(m) {
33314
32364
  const rows = m._size[0];
33315
32365
  const cols = m._size[1];
33316
- const wasm = wasmLoader.getModule();
33317
- if (wasm && rows * cols >= WASM_QR_THRESHOLD && isPlainNumberMatrix6(m._data)) {
33318
- try {
33319
- const flat = flattenToFloat646(m._data, rows, cols);
33320
- const aAlloc = wasmLoader.allocateFloat64Array(flat);
33321
- const qAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows * rows);
33322
- try {
33323
- wasm.qrDecomposition(aAlloc.ptr, rows, cols, qAlloc.ptr);
33324
- const Rdata2 = [];
33325
- for (let i2 = 0; i2 < rows; i2++) {
33326
- Rdata2[i2] = [];
33327
- for (let j2 = 0; j2 < cols; j2++) {
33328
- Rdata2[i2][j2] = aAlloc.array[i2 * cols + j2];
33329
- }
33330
- }
33331
- const Qdata2 = [];
33332
- for (let i2 = 0; i2 < rows; i2++) {
33333
- Qdata2[i2] = [];
33334
- for (let j2 = 0; j2 < rows; j2++) {
33335
- Qdata2[i2][j2] = qAlloc.array[i2 * rows + j2];
33336
- }
33337
- }
33338
- const Q3 = matrix2(Qdata2);
33339
- const R2 = matrix2(Rdata2);
33340
- return {
33341
- Q: Q3,
33342
- R: R2,
33343
- toString: function() {
33344
- return "Q: " + this.Q.toString() + "\nR: " + this.R.toString();
33345
- }
33346
- };
33347
- } finally {
33348
- wasmLoader.free(aAlloc.ptr);
33349
- wasmLoader.free(qAlloc.ptr);
33350
- }
33351
- } catch {
33352
- }
33353
- }
33354
32366
  const Q2 = identity2([rows], "dense");
33355
32367
  const Qdata = Q2._data;
33356
32368
  const R = m.clone();
@@ -33843,15 +32855,6 @@ var createEqualText = /* @__PURE__ */ factory(
33843
32855
  );
33844
32856
 
33845
32857
  // src/statistics/max.ts
33846
- var WASM_MAX_THRESHOLD = 100;
33847
- function isFlatNumberArray5(arr10) {
33848
- for (let i = 0; i < arr10.length; i++) {
33849
- if (typeof arr10[i] !== "number") {
33850
- return false;
33851
- }
33852
- }
33853
- return true;
33854
- }
33855
32858
  var name178 = "max";
33856
32859
  var dependencies178 = ["typed", "config", "numeric", "larger", "isNaN"];
33857
32860
  var createMax = /* @__PURE__ */ factory(
@@ -33882,22 +32885,6 @@ var createMax = /* @__PURE__ */ factory(
33882
32885
  }
33883
32886
  }
33884
32887
  function _max(array) {
33885
- if (Array.isArray(array) && array.length >= WASM_MAX_THRESHOLD) {
33886
- if (isFlatNumberArray5(array)) {
33887
- const wasm = wasmLoader.getModule();
33888
- if (wasm) {
33889
- try {
33890
- const alloc = wasmLoader.allocateFloat64Array(array);
33891
- try {
33892
- return wasm.statsMax(alloc.ptr, array.length);
33893
- } finally {
33894
- wasmLoader.free(alloc.ptr);
33895
- }
33896
- } catch {
33897
- }
33898
- }
33899
- }
33900
- }
33901
32888
  let res;
33902
32889
  deepForEach(array, function(value) {
33903
32890
  try {
@@ -33922,15 +32909,6 @@ var createMax = /* @__PURE__ */ factory(
33922
32909
  );
33923
32910
 
33924
32911
  // src/statistics/min.ts
33925
- var WASM_MIN_THRESHOLD = 100;
33926
- function isFlatNumberArray6(arr10) {
33927
- for (let i = 0; i < arr10.length; i++) {
33928
- if (typeof arr10[i] !== "number") {
33929
- return false;
33930
- }
33931
- }
33932
- return true;
33933
- }
33934
32912
  var name179 = "min";
33935
32913
  var dependencies179 = ["typed", "config", "numeric", "smaller", "isNaN"];
33936
32914
  var createMin = /* @__PURE__ */ factory(
@@ -33961,22 +32939,6 @@ var createMin = /* @__PURE__ */ factory(
33961
32939
  }
33962
32940
  }
33963
32941
  function _min(array) {
33964
- if (Array.isArray(array) && array.length >= WASM_MIN_THRESHOLD) {
33965
- if (isFlatNumberArray6(array)) {
33966
- const wasm = wasmLoader.getModule();
33967
- if (wasm) {
33968
- try {
33969
- const alloc = wasmLoader.allocateFloat64Array(array);
33970
- try {
33971
- return wasm.statsMin(alloc.ptr, array.length);
33972
- } finally {
33973
- wasmLoader.free(alloc.ptr);
33974
- }
33975
- } catch {
33976
- }
33977
- }
33978
- }
33979
- }
33980
32942
  let min2;
33981
32943
  deepForEach(array, function(value) {
33982
32944
  try {
@@ -34092,7 +33054,6 @@ var createNullish = /* @__PURE__ */ factory(
34092
33054
  );
34093
33055
 
34094
33056
  // src/arithmetic/hypot.ts
34095
- var WASM_HYPOT_THRESHOLD = 50;
34096
33057
  var name181 = "hypot";
34097
33058
  var dependencies181 = [
34098
33059
  "typed",
@@ -34122,28 +33083,7 @@ var createHypot = /* @__PURE__ */ factory(
34122
33083
  Array: _hypot,
34123
33084
  Matrix: (M) => _hypot(flatten2(M.toArray(), true))
34124
33085
  });
34125
- function _tryWasmHypot(args) {
34126
- if (args.length < WASM_HYPOT_THRESHOLD) return null;
34127
- const wasm = wasmLoader.getModule();
34128
- if (!wasm) return null;
34129
- const n = args.length;
34130
- const data = new Float64Array(n);
34131
- for (let i = 0; i < n; i++) {
34132
- if (typeof args[i] !== "number") return null;
34133
- data[i] = args[i];
34134
- }
34135
- const alloc = wasmLoader.allocateFloat64Array(data);
34136
- try {
34137
- return wasm.hypotArray(alloc.ptr, n);
34138
- } catch {
34139
- return null;
34140
- } finally {
34141
- wasmLoader.free(alloc.ptr);
34142
- }
34143
- }
34144
33086
  function _hypot(args) {
34145
- const wasmResult = _tryWasmHypot(args);
34146
- if (wasmResult !== null) return wasmResult;
34147
33087
  let result = 0;
34148
33088
  let largest = 0;
34149
33089
  for (let i = 0; i < args.length; i++) {
@@ -34472,8 +33412,6 @@ var createDistance = /* @__PURE__ */ factory(
34472
33412
  return sqrt2(result);
34473
33413
  }
34474
33414
  function _distancePairwise(a) {
34475
- const wasmResult = _tryWasmPairwise(a);
34476
- if (wasmResult !== null) return wasmResult;
34477
33415
  const result = [];
34478
33416
  let pointA = [];
34479
33417
  let pointB = [];
@@ -34491,37 +33429,6 @@ var createDistance = /* @__PURE__ */ factory(
34491
33429
  }
34492
33430
  return result;
34493
33431
  }
34494
- function _tryWasmPairwise(a) {
34495
- const wasm = wasmLoader.getModule();
34496
- if (!wasm) return null;
34497
- const numPoints = a.length;
34498
- const dims = a[0].length;
34499
- for (let i = 0; i < numPoints; i++) {
34500
- for (let d = 0; d < dims; d++) {
34501
- if (typeof a[i][d] !== "number") return null;
34502
- }
34503
- }
34504
- const p1Alloc = wasmLoader.allocateFloat64ArrayEmpty(dims);
34505
- const p2Alloc = wasmLoader.allocateFloat64ArrayEmpty(dims);
34506
- try {
34507
- const result = [];
34508
- for (let i = 0; i < numPoints - 1; i++) {
34509
- for (let d = 0; d < dims; d++) {
34510
- p1Alloc.array[d] = a[i][d];
34511
- }
34512
- for (let j = i + 1; j < numPoints; j++) {
34513
- for (let d = 0; d < dims; d++) {
34514
- p2Alloc.array[d] = a[j][d];
34515
- }
34516
- result.push(wasm.distanceND(p1Alloc.ptr, p2Alloc.ptr, dims));
34517
- }
34518
- }
34519
- return result;
34520
- } finally {
34521
- wasmLoader.free(p1Alloc.ptr);
34522
- wasmLoader.free(p2Alloc.ptr);
34523
- }
34524
- }
34525
33432
  }
34526
33433
  );
34527
33434
 
@@ -36497,33 +35404,33 @@ var dependencies203 = ["typed", "Unit"];
36497
35404
  var createCreateUnit = /* @__PURE__ */ factory(
36498
35405
  name203,
36499
35406
  dependencies203,
36500
- ({ typed: typed3, Unit: Unit2 }) => {
35407
+ ({ typed: typed3, Unit: Unit3 }) => {
36501
35408
  return typed3(name203, {
36502
35409
  // General function signature. First parameter is an object where each property is the definition of a new unit. The object keys are the unit names and the values are the definitions. The values can be objects, strings, or Units. If a property is an empty object or an empty string, a new base unit is created. The second parameter is the options.
36503
35410
  "Object, Object": function(obj, options) {
36504
- return Unit2.createUnit(obj, options);
35411
+ return Unit3.createUnit(obj, options);
36505
35412
  },
36506
35413
  // Same as above but without the options.
36507
35414
  Object: function(obj) {
36508
- return Unit2.createUnit(obj, {});
35415
+ return Unit3.createUnit(obj, {});
36509
35416
  },
36510
35417
  // Shortcut method for creating one unit.
36511
35418
  "string, Unit | string | Object, Object": function(name254, def, options) {
36512
35419
  const obj = {};
36513
35420
  obj[name254] = def;
36514
- return Unit2.createUnit(obj, options);
35421
+ return Unit3.createUnit(obj, options);
36515
35422
  },
36516
35423
  // Same as above but without the options.
36517
35424
  "string, Unit | string | Object": function(name254, def) {
36518
35425
  const obj = {};
36519
35426
  obj[name254] = def;
36520
- return Unit2.createUnit(obj, {});
35427
+ return Unit3.createUnit(obj, {});
36521
35428
  },
36522
35429
  // Without a definition, creates a base unit.
36523
35430
  string: function(name254) {
36524
35431
  const obj = {};
36525
35432
  obj[name254] = {};
36526
- return Unit2.createUnit(obj, {});
35433
+ return Unit3.createUnit(obj, {});
36527
35434
  }
36528
35435
  });
36529
35436
  }
@@ -36535,22 +35442,22 @@ var dependencies204 = ["typed", "Unit"];
36535
35442
  var createUnitFunction = /* @__PURE__ */ factory(
36536
35443
  name204,
36537
35444
  dependencies204,
36538
- ({ typed: typed3, Unit: Unit2 }) => {
35445
+ ({ typed: typed3, Unit: Unit3 }) => {
36539
35446
  return typed3(name204, {
36540
35447
  Unit: function(x) {
36541
35448
  return x.clone();
36542
35449
  },
36543
35450
  string: function(x) {
36544
- if (Unit2.isValuelessUnit(x)) {
36545
- return new Unit2(null, x);
35451
+ if (Unit3.isValuelessUnit(x)) {
35452
+ return new Unit3(null, x);
36546
35453
  }
36547
- return Unit2.parse(x, { allowNoUnits: true });
35454
+ return Unit3.parse(x, { allowNoUnits: true });
36548
35455
  },
36549
35456
  "number | BigNumber | Fraction | Complex, string | Unit": function(value, unit2) {
36550
- return new Unit2(value, unit2);
35457
+ return new Unit3(value, unit2);
36551
35458
  },
36552
35459
  "number | BigNumber | Fraction": function(value) {
36553
- return new Unit2(value);
35460
+ return new Unit3(value);
36554
35461
  },
36555
35462
  "Array | Matrix": typed3.referToSelf(
36556
35463
  (self) => (x) => deepMap(x, self)
@@ -37158,11 +36065,14 @@ var createDiff = /* @__PURE__ */ factory(
37158
36065
  return _recursive(arr10, dim);
37159
36066
  }
37160
36067
  },
37161
- // typed-function's runtime `referTo` is single-call variadic
37162
- // (`referTo(...signatures, callback)`); the imported TypedFunction interface
37163
- // models it curried, so narrow to the real contract via `unknown`.
37164
- "Array, BigNumber": typed3.referTo("Array,number", (selfAn) => (arr10, dim) => selfAn(arr10, number2(dim))),
37165
- "Matrix, BigNumber": typed3.referTo("Matrix,number", (selfMn) => (arr10, dim) => selfMn(arr10, number2(dim)))
36068
+ "Array, BigNumber": typed3.referTo(
36069
+ "Array,number",
36070
+ (selfAn) => (arr10, dim) => selfAn(arr10, number2(dim))
36071
+ ),
36072
+ "Matrix, BigNumber": typed3.referTo(
36073
+ "Matrix,number",
36074
+ (selfMn) => (arr10, dim) => selfMn(arr10, number2(dim))
36075
+ )
37166
36076
  });
37167
36077
  function _recursive(arr10, dim) {
37168
36078
  if (isMatrix(arr10)) {
@@ -37219,7 +36129,6 @@ var createDiff = /* @__PURE__ */ factory(
37219
36129
  );
37220
36130
 
37221
36131
  // src/matrix/sqrtm.ts
37222
- var WASM_SQRTM_THRESHOLD = 16;
37223
36132
  var name211 = "sqrtm";
37224
36133
  var dependencies211 = [
37225
36134
  "typed",
@@ -37240,62 +36149,6 @@ var createSqrtm = /* @__PURE__ */ factory(
37240
36149
  ({ typed: typed3, abs: abs2, add: add5, multiply: multiply2, map: map3, sqrt: sqrt2, subtract: subtract3, inv: inv3, size: size2, max: max2, identity: identity2 }) => {
37241
36150
  const _maxIterations = 1e3;
37242
36151
  const _tolerance = 1e-6;
37243
- function _tryWasmSqrtm(A, n) {
37244
- const wasm = wasmLoader.getModule();
37245
- if (!wasm || n * n < WASM_SQRTM_THRESHOLD) return null;
37246
- const data = isMatrix(A) ? A._data : A;
37247
- if (!data || !Array.isArray(data)) return null;
37248
- try {
37249
- const flat = new Float64Array(n * n);
37250
- for (let i = 0; i < n; i++) {
37251
- const row2 = data[i];
37252
- if (!Array.isArray(row2)) return null;
37253
- for (let j = 0; j < n; j++) {
37254
- const val = row2[j];
37255
- if (typeof val !== "number") return null;
37256
- flat[i * n + j] = val;
37257
- }
37258
- }
37259
- const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
37260
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(n * n);
37261
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(5 * n * n);
37262
- try {
37263
- const status = wasm.sqrtm(
37264
- matrixAlloc.ptr,
37265
- n,
37266
- resultAlloc.ptr,
37267
- _tolerance,
37268
- _maxIterations,
37269
- workAlloc.ptr
37270
- );
37271
- if (status > 0) {
37272
- const result = [];
37273
- for (let i = 0; i < n; i++) {
37274
- const row2 = [];
37275
- for (let j = 0; j < n; j++) {
37276
- row2[j] = resultAlloc.array[i * n + j];
37277
- }
37278
- result[i] = row2;
37279
- }
37280
- if (isMatrix(A)) {
37281
- const matA = A;
37282
- return matA.createDenseMatrix({
37283
- data: result,
37284
- size: [n, n],
37285
- datatype: matA._datatype
37286
- });
37287
- }
37288
- return result;
37289
- }
37290
- } finally {
37291
- wasmLoader.free(matrixAlloc.ptr);
37292
- wasmLoader.free(resultAlloc.ptr);
37293
- wasmLoader.free(workAlloc.ptr);
37294
- }
37295
- } catch {
37296
- }
37297
- return null;
37298
- }
37299
36152
  function _denmanBeavers(A) {
37300
36153
  let error;
37301
36154
  let iterations = 0;
@@ -37328,8 +36181,6 @@ var createSqrtm = /* @__PURE__ */ factory(
37328
36181
  const rows = sizeArray[0];
37329
36182
  const cols = sizeArray[1];
37330
36183
  if (rows === cols) {
37331
- const wasmResult = _tryWasmSqrtm(A, rows);
37332
- if (wasmResult !== null) return wasmResult;
37333
36184
  return _denmanBeavers(A);
37334
36185
  } else {
37335
36186
  throw new RangeError(
@@ -37348,27 +36199,6 @@ var createSqrtm = /* @__PURE__ */ factory(
37348
36199
  );
37349
36200
 
37350
36201
  // src/algebra/decomposition/lup.ts
37351
- var WASM_LUP_THRESHOLD = 16;
37352
- function isPlainNumberMatrix7(matrix2) {
37353
- for (let i = 0; i < matrix2.length; i++) {
37354
- const row2 = matrix2[i];
37355
- for (let j = 0; j < row2.length; j++) {
37356
- if (typeof row2[j] !== "number") {
37357
- return false;
37358
- }
37359
- }
37360
- }
37361
- return true;
37362
- }
37363
- function flattenToFloat647(matrix2, rows, cols) {
37364
- const result = new Float64Array(rows * cols);
37365
- for (let i = 0; i < rows; i++) {
37366
- for (let j = 0; j < cols; j++) {
37367
- result[i * cols + j] = matrix2[i][j];
37368
- }
37369
- }
37370
- return result;
37371
- }
37372
36202
  var name212 = "lup";
37373
36203
  var dependencies212 = [
37374
36204
  "typed",
@@ -37424,66 +36254,6 @@ var createLup = /* @__PURE__ */ factory(
37424
36254
  const rows = m._size[0];
37425
36255
  const columns = m._size[1];
37426
36256
  let n = Math.min(rows, columns);
37427
- const wasm = wasmLoader.getModule();
37428
- if (wasm && rows === columns && rows * rows >= WASM_LUP_THRESHOLD && isPlainNumberMatrix7(m._data)) {
37429
- try {
37430
- const flat = flattenToFloat647(m._data, rows, columns);
37431
- const aAlloc = wasmLoader.allocateFloat64Array(flat);
37432
- const permAlloc = wasmLoader.allocateInt32ArrayEmpty(rows);
37433
- try {
37434
- const result = wasm.luDecomposition(aAlloc.ptr, rows, permAlloc.ptr);
37435
- if (result !== 0) {
37436
- throw new Error("Matrix is singular and cannot be decomposed");
37437
- }
37438
- const ldata2 = [];
37439
- const udata2 = [];
37440
- for (let i2 = 0; i2 < rows; i2++) {
37441
- ldata2[i2] = [];
37442
- udata2[i2] = [];
37443
- for (let j2 = 0; j2 < columns; j2++) {
37444
- const val = aAlloc.array[i2 * columns + j2];
37445
- if (i2 > j2) {
37446
- ldata2[i2][j2] = val;
37447
- udata2[i2][j2] = 0;
37448
- } else if (i2 === j2) {
37449
- ldata2[i2][j2] = 1;
37450
- udata2[i2][j2] = val;
37451
- } else {
37452
- ldata2[i2][j2] = 0;
37453
- udata2[i2][j2] = val;
37454
- }
37455
- }
37456
- }
37457
- const p2 = [];
37458
- for (let i2 = 0; i2 < rows; i2++) {
37459
- p2[i2] = permAlloc.array[i2];
37460
- }
37461
- const l2 = new DenseMatrix7({
37462
- data: ldata2,
37463
- size: [rows, n]
37464
- });
37465
- const u2 = new DenseMatrix7({
37466
- data: udata2,
37467
- size: [n, columns]
37468
- });
37469
- return {
37470
- L: l2,
37471
- U: u2,
37472
- p: p2,
37473
- toString: function() {
37474
- return "L: " + this.L.toString() + "\nU: " + this.U.toString() + "\nP: " + this.p;
37475
- }
37476
- };
37477
- } finally {
37478
- wasmLoader.free(aAlloc.ptr);
37479
- wasmLoader.free(permAlloc.ptr);
37480
- }
37481
- } catch (e) {
37482
- if (e instanceof Error && e.message.includes("singular")) {
37483
- throw e;
37484
- }
37485
- }
37486
- }
37487
36257
  const data = clone(m._data);
37488
36258
  const ldata = [];
37489
36259
  const lsize = [rows, n];
@@ -38367,8 +37137,6 @@ var createIntersect = /* @__PURE__ */ factory(
38367
37137
  return x.length === 4 && isNumeric2(x[0]) && isNumeric2(x[1]) && isNumeric2(x[2]) && isNumeric2(x[3]);
38368
37138
  }
38369
37139
  function _intersect2d(p1a, p1b, p2a, p2b) {
38370
- const wasmResult = _tryWasmIntersect2d(p1a, p1b, p2a, p2b);
38371
- if (wasmResult !== void 0) return wasmResult;
38372
37140
  const o1 = p1a;
38373
37141
  const o2 = p2a;
38374
37142
  const d1 = subtract3(o1, p1b);
@@ -38394,34 +37162,6 @@ var createIntersect = /* @__PURE__ */ factory(
38394
37162
  );
38395
37163
  return add5(multiply2(d1, t), o1);
38396
37164
  }
38397
- function _tryWasmIntersect2d(p1a, p1b, p2a, p2b) {
38398
- const wasm = wasmLoader.getModule();
38399
- if (!wasm) return void 0;
38400
- if (typeof p1a[0] !== "number" || typeof p1a[1] !== "number" || typeof p1b[0] !== "number" || typeof p1b[1] !== "number" || typeof p2a[0] !== "number" || typeof p2a[1] !== "number" || typeof p2b[0] !== "number" || typeof p2b[1] !== "number") {
38401
- return void 0;
38402
- }
38403
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(3);
38404
- try {
38405
- wasm.intersect2DInfiniteLines(
38406
- p1a[0],
38407
- p1a[1],
38408
- p1b[0],
38409
- p1b[1],
38410
- p2a[0],
38411
- p2a[1],
38412
- p2b[0],
38413
- p2b[1],
38414
- resultAlloc.ptr
38415
- );
38416
- const exists = resultAlloc.array[2];
38417
- if (exists === 0) {
38418
- return null;
38419
- }
38420
- return [resultAlloc.array[0], resultAlloc.array[1]];
38421
- } finally {
38422
- wasmLoader.free(resultAlloc.ptr);
38423
- }
38424
- }
38425
37165
  function _intersect3dHelper(a, b, c, d, e, f, g, h, i, j, k, l) {
38426
37166
  const add1 = multiplyScalar2(
38427
37167
  subtract3(a, b),
@@ -38503,15 +37243,6 @@ var createIntersect = /* @__PURE__ */ factory(
38503
37243
  );
38504
37244
 
38505
37245
  // src/statistics/mean.ts
38506
- var WASM_MEAN_THRESHOLD = 100;
38507
- function isFlatNumberArray7(arr10) {
38508
- for (let i = 0; i < arr10.length; i++) {
38509
- if (typeof arr10[i] !== "number") {
38510
- return false;
38511
- }
38512
- }
38513
- return true;
38514
- }
38515
37246
  var name219 = "mean";
38516
37247
  var dependencies219 = ["typed", "add", "divide"];
38517
37248
  var createMean = /* @__PURE__ */ factory(
@@ -38542,22 +37273,6 @@ var createMean = /* @__PURE__ */ factory(
38542
37273
  }
38543
37274
  }
38544
37275
  function _mean2(array) {
38545
- if (Array.isArray(array) && array.length >= WASM_MEAN_THRESHOLD) {
38546
- if (isFlatNumberArray7(array)) {
38547
- const wasm = wasmLoader.getModule();
38548
- if (wasm) {
38549
- try {
38550
- const alloc = wasmLoader.allocateFloat64Array(array);
38551
- try {
38552
- return wasm.statsMean(alloc.ptr, array.length);
38553
- } finally {
38554
- wasmLoader.free(alloc.ptr);
38555
- }
38556
- } catch {
38557
- }
38558
- }
38559
- }
38560
- }
38561
37276
  let sum3;
38562
37277
  let num2 = 0;
38563
37278
  deepForEach(array, function(value) {
@@ -38642,7 +37357,7 @@ var createMedian = /* @__PURE__ */ factory(
38642
37357
 
38643
37358
  // src/statistics/variance.ts
38644
37359
  import { sumSquaredDeviations as sumSquaredDeviations2 } from "@danielsimonjr/mathts-core";
38645
- function isFlatNumberArray8(arr10) {
37360
+ function isFlatNumberArray3(arr10) {
38646
37361
  for (let i = 0; i < arr10.length; i++) {
38647
37362
  if (typeof arr10[i] !== "number") {
38648
37363
  return false;
@@ -38687,7 +37402,7 @@ var createVariance = /* @__PURE__ */ factory(
38687
37402
  if (array.length === 0) {
38688
37403
  throw new SyntaxError("Function variance requires one or more parameters (0 provided)");
38689
37404
  }
38690
- if (Array.isArray(array) && isFlatNumberArray8(array)) {
37405
+ if (Array.isArray(array) && isFlatNumberArray3(array)) {
38691
37406
  const nn = array.length;
38692
37407
  const ssd = sumSquaredDeviations2(array);
38693
37408
  switch (normalization) {
@@ -39015,12 +37730,13 @@ var createMultinomial = /* @__PURE__ */ factory(
39015
37730
  );
39016
37731
 
39017
37732
  // src/signal/freqz.ts
39018
- var WASM_FREQZ_THRESHOLD = 32;
39019
37733
  var name225 = "freqz";
39020
37734
  var dependencies225 = ["typed", "add", "multiply", "Complex", "divide", "matrix"];
39021
37735
  var createFreqz = /* @__PURE__ */ factory(
39022
37736
  name225,
39023
37737
  dependencies225,
37738
+ // The deps are untyped (`any`), so the result is declared: without it the export
37739
+ // inherits `any` from `typed(...)` instead of being a TypedFunction like the rest.
39024
37740
  ({ typed: typed3, add: add5, multiply: multiply2, Complex: Complex13, divide: divide2, matrix: matrix2 }) => {
39025
37741
  return typed3(name225, {
39026
37742
  "Array, Array": function(b, a) {
@@ -39068,47 +37784,7 @@ var createFreqz = /* @__PURE__ */ factory(
39068
37784
  };
39069
37785
  }
39070
37786
  });
39071
- function _tryWasmFreqz(b, a, w) {
39072
- const wasm = wasmLoader.getModule();
39073
- if (!wasm || w.length < WASM_FREQZ_THRESHOLD) return null;
39074
- try {
39075
- const bAlloc = wasmLoader.allocateFloat64Array(b);
39076
- const aAlloc = wasmLoader.allocateFloat64Array(a);
39077
- const wAlloc = wasmLoader.allocateFloat64Array(w);
39078
- const hRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(w.length);
39079
- const hImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(w.length);
39080
- try {
39081
- wasm.freqz(
39082
- bAlloc.ptr,
39083
- b.length,
39084
- aAlloc.ptr,
39085
- a.length,
39086
- wAlloc.ptr,
39087
- w.length,
39088
- hRealAlloc.ptr,
39089
- hImagAlloc.ptr
39090
- );
39091
- const h = [];
39092
- for (let i = 0; i < w.length; i++) {
39093
- h.push(Complex13(hRealAlloc.array[i], hImagAlloc.array[i]));
39094
- }
39095
- return { h, w };
39096
- } finally {
39097
- wasmLoader.free(bAlloc.ptr);
39098
- wasmLoader.free(aAlloc.ptr);
39099
- wasmLoader.free(wAlloc.ptr);
39100
- wasmLoader.free(hRealAlloc.ptr);
39101
- wasmLoader.free(hImagAlloc.ptr);
39102
- }
39103
- } catch {
39104
- }
39105
- return null;
39106
- }
39107
37787
  function _freqz(b, a, w) {
39108
- const wasmResult = _tryWasmFreqz(b, a, w);
39109
- if (wasmResult !== null) {
39110
- return wasmResult;
39111
- }
39112
37788
  const num2 = [];
39113
37789
  const den = [];
39114
37790
  for (let i = 0; i < w.length; i++) {
@@ -40220,16 +38896,6 @@ var createIndex = /* @__PURE__ */ factory(
40220
38896
  );
40221
38897
 
40222
38898
  // src/matrix/eigs/complexEigs.ts
40223
- var WASM_EIGS_THRESHOLD = 16;
40224
- function flattenToFloat648(matrix2, rows, cols) {
40225
- const result = new Float64Array(rows * cols);
40226
- for (let i = 0; i < rows; i++) {
40227
- for (let j = 0; j < cols; j++) {
40228
- result[i * cols + j] = matrix2[i][j];
40229
- }
40230
- }
40231
- return result;
40232
- }
40233
38899
  function createComplexEigs({
40234
38900
  addScalar: addScalar2,
40235
38901
  subtract: subtract3,
@@ -40255,54 +38921,6 @@ function createComplexEigs({
40255
38921
  dot: dot9
40256
38922
  }) {
40257
38923
  function complexEigs(arr10, N2, prec, type, findVectors = true) {
40258
- if (!findVectors && type === "number" && N2 * N2 >= WASM_EIGS_THRESHOLD) {
40259
- const wasm = wasmLoader.getModule();
40260
- if (wasm) {
40261
- try {
40262
- const flat = flattenToFloat648(arr10, N2, N2);
40263
- const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
40264
- const eigenvaluesRealAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
40265
- const eigenvaluesImagAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
40266
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2 * N2);
40267
- try {
40268
- const iterations = wasm.qrAlgorithm(
40269
- matrixAlloc.ptr,
40270
- N2,
40271
- eigenvaluesRealAlloc.ptr,
40272
- eigenvaluesImagAlloc.ptr,
40273
- workAlloc.ptr,
40274
- 1e3,
40275
- // maxIterations
40276
- typeof prec === "number" ? prec : 1e-12
40277
- );
40278
- if (iterations >= 0) {
40279
- const values2 = [];
40280
- for (let i = 0; i < N2; i++) {
40281
- const re3 = eigenvaluesRealAlloc.array[i];
40282
- const im3 = eigenvaluesImagAlloc.array[i];
40283
- if (Math.abs(im3) < 1e-14) {
40284
- values2.push(re3);
40285
- } else {
40286
- values2.push(complex3(re3, im3));
40287
- }
40288
- }
40289
- values2.sort((a, b) => {
40290
- const absA = typeof a === "number" ? Math.abs(a) : Math.sqrt(a.re ** 2 + a.im ** 2);
40291
- const absB = typeof b === "number" ? Math.abs(b) : Math.sqrt(b.re ** 2 + b.im ** 2);
40292
- return absA - absB;
40293
- });
40294
- return { values: values2 };
40295
- }
40296
- } finally {
40297
- wasmLoader.free(matrixAlloc.ptr);
40298
- wasmLoader.free(eigenvaluesRealAlloc.ptr);
40299
- wasmLoader.free(eigenvaluesImagAlloc.ptr);
40300
- wasmLoader.free(workAlloc.ptr);
40301
- }
40302
- } catch {
40303
- }
40304
- }
40305
- }
40306
38924
  const R = balance(arr10, N2, prec, type, findVectors);
40307
38925
  reduceToHessenberg(arr10, N2, prec, type, findVectors, R);
40308
38926
  const { values, C } = iterateUntilTriangular(arr10, N2, prec, type, findVectors);
@@ -40713,16 +39331,6 @@ function createComplexEigs({
40713
39331
  }
40714
39332
 
40715
39333
  // src/matrix/eigs/realSymmetric.ts
40716
- var WASM_EIGS_THRESHOLD2 = 16;
40717
- function flattenToFloat649(matrix2, rows, cols) {
40718
- const result = new Float64Array(rows * cols);
40719
- for (let i = 0; i < rows; i++) {
40720
- for (let j = 0; j < cols; j++) {
40721
- result[i * cols + j] = matrix2[i][j];
40722
- }
40723
- }
40724
- return result;
40725
- }
40726
39334
  function createRealSymmetric({
40727
39335
  config: config2,
40728
39336
  addScalar: addScalar2,
@@ -40760,62 +39368,6 @@ function createRealSymmetric({
40760
39368
  }
40761
39369
  function diag2(x, precision, computeVectors) {
40762
39370
  const N2 = x.length;
40763
- const wasm = wasmLoader.getModule();
40764
- if (wasm && N2 * N2 >= WASM_EIGS_THRESHOLD2) {
40765
- try {
40766
- const flat = flattenToFloat649(x, N2, N2);
40767
- const matrixAlloc = wasmLoader.allocateFloat64Array(flat);
40768
- const eigenvaluesAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2);
40769
- const eigenvectorsAlloc = computeVectors ? wasmLoader.allocateFloat64ArrayEmpty(N2 * N2) : { ptr: 0, array: new Float64Array(0) };
40770
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(N2 * N2);
40771
- try {
40772
- const iterations = wasm.eigsSymmetric(
40773
- matrixAlloc.ptr,
40774
- N2,
40775
- eigenvaluesAlloc.ptr,
40776
- eigenvectorsAlloc.ptr,
40777
- workAlloc.ptr,
40778
- 1e3,
40779
- // maxIterations
40780
- precision
40781
- );
40782
- if (iterations >= 0) {
40783
- const values = Array(N2);
40784
- for (let i = 0; i < N2; i++) {
40785
- values[i] = eigenvaluesAlloc.array[i];
40786
- }
40787
- if (!computeVectors) {
40788
- const sortedValues = values.map((v, i) => ({ v, i })).sort((a, b) => Math.abs(a.v) - Math.abs(b.v)).map((x2) => x2.v);
40789
- return { values: sortedValues };
40790
- }
40791
- const eigenvectors = [];
40792
- const sortedIndices = values.map((v, i) => ({ v, i })).sort((a, b) => Math.abs(a.v) - Math.abs(b.v)).map((x2) => x2.i);
40793
- for (const origIdx of sortedIndices) {
40794
- const vector = Array(N2);
40795
- for (let i = 0; i < N2; i++) {
40796
- vector[i] = eigenvectorsAlloc.array[i * N2 + origIdx];
40797
- }
40798
- eigenvectors.push({
40799
- value: values[origIdx],
40800
- vector
40801
- });
40802
- }
40803
- return {
40804
- values: sortedIndices.map((i) => values[i]),
40805
- eigenvectors
40806
- };
40807
- }
40808
- } finally {
40809
- wasmLoader.free(matrixAlloc.ptr);
40810
- wasmLoader.free(eigenvaluesAlloc.ptr);
40811
- if (computeVectors) {
40812
- wasmLoader.free(eigenvectorsAlloc.ptr);
40813
- }
40814
- wasmLoader.free(workAlloc.ptr);
40815
- }
40816
- } catch {
40817
- }
40818
- }
40819
39371
  const e0 = Math.abs(precision / N2);
40820
39372
  let psi;
40821
39373
  let Sij;
@@ -41338,42 +39890,6 @@ function csIpvec(p, b) {
41338
39890
  }
41339
39891
 
41340
39892
  // src/algebra/solver/lusolve.ts
41341
- var WASM_LUSOLVE_THRESHOLD = 16;
41342
- function isPlainNumberMatrix8(matrix2) {
41343
- for (let i = 0; i < matrix2.length; i++) {
41344
- const row2 = matrix2[i];
41345
- for (let j = 0; j < row2.length; j++) {
41346
- if (typeof row2[j] !== "number") {
41347
- return false;
41348
- }
41349
- }
41350
- }
41351
- return true;
41352
- }
41353
- function isPlainNumberVector3(vec) {
41354
- for (let i = 0; i < vec.length; i++) {
41355
- if (typeof vec[i][0] !== "number") {
41356
- return false;
41357
- }
41358
- }
41359
- return true;
41360
- }
41361
- function flattenToFloat6410(matrix2, rows, cols) {
41362
- const result = new Float64Array(rows * cols);
41363
- for (let i = 0; i < rows; i++) {
41364
- for (let j = 0; j < cols; j++) {
41365
- result[i * cols + j] = matrix2[i][j];
41366
- }
41367
- }
41368
- return result;
41369
- }
41370
- function vectorToFloat643(vec) {
41371
- const result = new Float64Array(vec.length);
41372
- for (let i = 0; i < vec.length; i++) {
41373
- result[i] = vec[i][0];
41374
- }
41375
- return result;
41376
- }
41377
39893
  var name238 = "lusolve";
41378
39894
  var dependencies238 = ["typed", "matrix", "lup", "slu", "usolve", "lsolve", "DenseMatrix"];
41379
39895
  var createLusolve = /* @__PURE__ */ factory(
@@ -41385,102 +39901,12 @@ var createLusolve = /* @__PURE__ */ factory(
41385
39901
  });
41386
39902
  return typed3(name238, {
41387
39903
  "Array, Array | Matrix": function(a, b) {
41388
- const rows = a.length;
41389
- const columns = a[0]?.length || 0;
41390
- const wasm = wasmLoader.getModule();
41391
- if (wasm && rows === columns && rows * rows >= WASM_LUSOLVE_THRESHOLD && isPlainNumberMatrix8(a)) {
41392
- const aMatrix2 = matrix2(a);
41393
- const bMatrix = solveValidation(aMatrix2, b, true);
41394
- const bdata = bMatrix._data;
41395
- if (isPlainNumberVector3(bdata) && bdata.length === rows) {
41396
- try {
41397
- const aFlat = flattenToFloat6410(a, rows, columns);
41398
- const bFlat = vectorToFloat643(bdata);
41399
- const aAlloc = wasmLoader.allocateFloat64Array(aFlat);
41400
- const bAlloc = wasmLoader.allocateFloat64Array(bFlat);
41401
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows);
41402
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows * rows);
41403
- try {
41404
- const success = wasm.laSolve(
41405
- aAlloc.ptr,
41406
- bAlloc.ptr,
41407
- rows,
41408
- resultAlloc.ptr,
41409
- workAlloc.ptr
41410
- );
41411
- if (success === 0) {
41412
- throw new Error("Linear system cannot be solved since matrix is singular");
41413
- }
41414
- const x2 = [];
41415
- for (let i = 0; i < rows; i++) {
41416
- x2[i] = [resultAlloc.array[i]];
41417
- }
41418
- return x2;
41419
- } finally {
41420
- wasmLoader.free(aAlloc.ptr);
41421
- wasmLoader.free(bAlloc.ptr);
41422
- wasmLoader.free(resultAlloc.ptr);
41423
- wasmLoader.free(workAlloc.ptr);
41424
- }
41425
- } catch (e) {
41426
- if (e instanceof Error && e.message.includes("singular")) {
41427
- throw e;
41428
- }
41429
- }
41430
- }
41431
- }
41432
39904
  const aMatrix = matrix2(a);
41433
39905
  const d = lup2(aMatrix);
41434
39906
  const x = _lusolve(d.L, d.U, d.p, null, b);
41435
39907
  return x.valueOf();
41436
39908
  },
41437
39909
  "DenseMatrix, Array | Matrix": function(a, b) {
41438
- const rows = a._size[0];
41439
- const columns = a._size[1];
41440
- const wasm = wasmLoader.getModule();
41441
- if (wasm && rows === columns && rows * rows >= WASM_LUSOLVE_THRESHOLD && isPlainNumberMatrix8(a._data)) {
41442
- const bMatrix = solveValidation(a, b, true);
41443
- const bdata = bMatrix._data;
41444
- if (isPlainNumberVector3(bdata) && bdata.length === rows) {
41445
- try {
41446
- const aFlat = flattenToFloat6410(a._data, rows, columns);
41447
- const bFlat = vectorToFloat643(bdata);
41448
- const aAlloc = wasmLoader.allocateFloat64Array(aFlat);
41449
- const bAlloc = wasmLoader.allocateFloat64Array(bFlat);
41450
- const resultAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows);
41451
- const workAlloc = wasmLoader.allocateFloat64ArrayEmpty(rows * rows);
41452
- try {
41453
- const success = wasm.laSolve(
41454
- aAlloc.ptr,
41455
- bAlloc.ptr,
41456
- rows,
41457
- resultAlloc.ptr,
41458
- workAlloc.ptr
41459
- );
41460
- if (success === 0) {
41461
- throw new Error("Linear system cannot be solved since matrix is singular");
41462
- }
41463
- const x = [];
41464
- for (let i = 0; i < rows; i++) {
41465
- x[i] = [resultAlloc.array[i]];
41466
- }
41467
- return new DenseMatrix7({
41468
- data: x,
41469
- size: [rows, 1]
41470
- });
41471
- } finally {
41472
- wasmLoader.free(aAlloc.ptr);
41473
- wasmLoader.free(bAlloc.ptr);
41474
- wasmLoader.free(resultAlloc.ptr);
41475
- wasmLoader.free(workAlloc.ptr);
41476
- }
41477
- } catch (e) {
41478
- if (e instanceof Error && e.message.includes("singular")) {
41479
- throw e;
41480
- }
41481
- }
41482
- }
41483
- }
41484
39910
  const d = lup2(a);
41485
39911
  return _lusolve(d.L, d.U, d.p, null, b);
41486
39912
  },
@@ -41603,15 +40029,6 @@ var createCorr = /* @__PURE__ */ factory(
41603
40029
  );
41604
40030
 
41605
40031
  // src/statistics/mad.ts
41606
- var WASM_MAD_THRESHOLD = 500;
41607
- function isPlainNumberArray2(arr10) {
41608
- for (let i = 0; i < arr10.length; i++) {
41609
- if (typeof arr10[i] !== "number") {
41610
- return false;
41611
- }
41612
- }
41613
- return true;
41614
- }
41615
40032
  var name240 = "mad";
41616
40033
  var dependencies240 = ["typed", "abs", "map", "median", "subtract"];
41617
40034
  var createMad = /* @__PURE__ */ factory(
@@ -41631,19 +40048,6 @@ var createMad = /* @__PURE__ */ factory(
41631
40048
  if (flat.length === 0) {
41632
40049
  throw new Error("Cannot calculate median absolute deviation (mad) of an empty array");
41633
40050
  }
41634
- const wasm = wasmLoader.getModule();
41635
- if (wasm && flat.length >= WASM_MAD_THRESHOLD && isPlainNumberArray2(flat)) {
41636
- try {
41637
- const aAlloc = wasmLoader.allocateFloat64Array(flat);
41638
- try {
41639
- const result = wasm.statsMad(aAlloc.ptr, flat.length);
41640
- return result;
41641
- } finally {
41642
- wasmLoader.free(aAlloc.ptr);
41643
- }
41644
- } catch {
41645
- }
41646
- }
41647
40051
  try {
41648
40052
  const med = median2(flat);
41649
40053
  return median2(
@@ -43146,7 +41550,6 @@ var createDerivative = /* @__PURE__ */ factory(
43146
41550
 
43147
41551
  // src/arithmetic/norm.ts
43148
41552
  import { norm2 as norm23 } from "@danielsimonjr/mathts-core";
43149
- var WASM_NORM_THRESHOLD = 100;
43150
41553
  var name245 = "norm";
43151
41554
  var dependencies245 = [
43152
41555
  "typed",
@@ -43205,39 +41608,6 @@ var createNorm = /* @__PURE__ */ factory(
43205
41608
  return _norm(x, p);
43206
41609
  }
43207
41610
  });
43208
- function _tryWasmVectorNorm(x, p) {
43209
- const size2 = x.size();
43210
- if (size2.length !== 1 || size2[0] < WASM_NORM_THRESHOLD) return null;
43211
- const wasm = wasmLoader.getModule();
43212
- if (!wasm) return null;
43213
- const arr10 = x.toArray();
43214
- const n = arr10.length;
43215
- const data = new Float64Array(n);
43216
- for (let i = 0; i < n; i++) {
43217
- if (typeof arr10[i] !== "number") return null;
43218
- data[i] = arr10[i];
43219
- }
43220
- const alloc = wasmLoader.allocateFloat64Array(data);
43221
- try {
43222
- if (p === 1) {
43223
- return wasm.norm1(alloc.ptr, n);
43224
- }
43225
- if (p === 2) {
43226
- return wasm.norm2(alloc.ptr, n);
43227
- }
43228
- if (p === Number.POSITIVE_INFINITY || p === "inf") {
43229
- return wasm.normInf(alloc.ptr, n);
43230
- }
43231
- if (typeof p === "number" && !isNaN(p) && p !== 0) {
43232
- return wasm.normP(alloc.ptr, n, p);
43233
- }
43234
- return null;
43235
- } catch {
43236
- return null;
43237
- } finally {
43238
- wasmLoader.free(alloc.ptr);
43239
- }
43240
- }
43241
41611
  function _vectorNormPlusInfinity(x) {
43242
41612
  let pinf = 0;
43243
41613
  x.forEach(function(value) {
@@ -43259,8 +41629,6 @@ var createNorm = /* @__PURE__ */ factory(
43259
41629
  return ninf || 0;
43260
41630
  }
43261
41631
  function _vectorNorm(x, p) {
43262
- const wasmResult = _tryWasmVectorNorm(x, p);
43263
- if (wasmResult !== null) return wasmResult;
43264
41632
  if (p === Number.POSITIVE_INFINITY || p === "inf") {
43265
41633
  return _vectorNormPlusInfinity(x);
43266
41634
  }
@@ -44021,7 +42389,7 @@ var createRotationMatrix = /* @__PURE__ */ factory(
44021
42389
 
44022
42390
  // src/algebra/decomposition/schur.ts
44023
42391
  import { matrixSchur, DenseMatrix as NativeDenseMatrix } from "@danielsimonjr/mathts-matrix";
44024
- function isPlainNumberMatrix9(matrix2) {
42392
+ function isPlainNumberMatrix2(matrix2) {
44025
42393
  for (let i = 0; i < matrix2.length; i++) {
44026
42394
  const row2 = matrix2[i];
44027
42395
  for (let j = 0; j < row2.length; j++) {
@@ -44051,7 +42419,7 @@ var createSchur = /* @__PURE__ */ factory(
44051
42419
  }
44052
42420
  });
44053
42421
  function _schur(data) {
44054
- if (!isPlainNumberMatrix9(data)) {
42422
+ if (!isPlainNumberMatrix2(data)) {
44055
42423
  throw new TypeError("schur: only real (number) matrices are supported");
44056
42424
  }
44057
42425
  const n = data.length;
@@ -44477,9 +42845,9 @@ function unitFactory(name254, valueStr, unitStr) {
44477
42845
  return factory(
44478
42846
  name254,
44479
42847
  dependencies254,
44480
- ({ config: config2, Unit: Unit2, BigNumber: BigNumber9 }) => {
42848
+ ({ config: config2, Unit: Unit3, BigNumber: BigNumber9 }) => {
44481
42849
  const value = config2.number === "BigNumber" ? new BigNumber9(valueStr) : parseFloat(valueStr);
44482
- const unit2 = new Unit2(value, unitStr);
42850
+ const unit2 = new Unit3(value, unitStr);
44483
42851
  unit2.fixPrefix = true;
44484
42852
  return unit2;
44485
42853
  }
@@ -45422,18 +43790,64 @@ var mathScope = {
45422
43790
  }
45423
43791
  }
45424
43792
  var parse = factoryScope.parse;
45425
- var evaluate = createEvaluate(parse, mathScope);
45426
- function compileExpr(expr) {
45427
- return _compileExpression(parse, mathScope, expr);
43793
+ var _evaluate = createEvaluate(parse, mathScope);
43794
+ var ELEMENTARY_CHARGE_COULOMB = 1602176634e-28;
43795
+ function elementaryChargeUnit() {
43796
+ return new Unit2(ELEMENTARY_CHARGE_COULOMB, "C");
43797
+ }
43798
+ function isMapScope(scope) {
43799
+ const candidate = scope;
43800
+ return typeof candidate.has === "function" && typeof candidate.get === "function" && typeof candidate.set === "function";
43801
+ }
43802
+ function physicsScope(scope) {
43803
+ const charge = elementaryChargeUnit();
43804
+ if (scope == null) return { e: charge };
43805
+ if (isMapScope(scope)) {
43806
+ if (scope.has("e")) return scope;
43807
+ return {
43808
+ has(key2) {
43809
+ return key2 === "e" || scope.has(key2);
43810
+ },
43811
+ get(key2) {
43812
+ return key2 === "e" ? charge : scope.get(key2);
43813
+ },
43814
+ set(key2, value) {
43815
+ scope.set(key2, value);
43816
+ }
43817
+ };
43818
+ }
43819
+ if (Object.prototype.hasOwnProperty.call(scope, "e")) return scope;
43820
+ return { e: charge, ...scope };
43821
+ }
43822
+ function evaluate(exprOrExprs, scope, options) {
43823
+ const bound = options?.physics === true ? physicsScope(scope) : scope;
43824
+ const inner = options?.unsafe === true ? { unsafe: true } : void 0;
43825
+ if (Array.isArray(exprOrExprs)) return _evaluate(exprOrExprs, bound, inner);
43826
+ return _evaluate(exprOrExprs, bound, inner);
43827
+ }
43828
+ function compileExpr(expr, options) {
43829
+ const compiled = _compileExpression(
43830
+ parse,
43831
+ mathScope,
43832
+ expr,
43833
+ options?.unsafe === true ? { unsafe: true } : void 0
43834
+ );
43835
+ if (options?.physics !== true) return compiled;
43836
+ return {
43837
+ evaluate(scope) {
43838
+ return compiled.evaluate(physicsScope(scope));
43839
+ }
43840
+ };
45428
43841
  }
45429
- function parser() {
43842
+ function parser(options) {
45430
43843
  const scope = {};
43844
+ const callOptions = options?.physics === true || options?.unsafe === true ? { physics: options.physics, unsafe: options.unsafe } : void 0;
45431
43845
  return {
45432
43846
  /** The live scope object — assignments during `evaluate` land here. */
45433
43847
  scope,
45434
43848
  /** Evaluate an expression against the retained scope. */
45435
43849
  evaluate(expr) {
45436
- return evaluate(expr, scope);
43850
+ return evaluate(expr, scope, callOptions);
45437
43851
  },
45438
43852
  /** Read a retained variable. */
45439
43853
  get(name254) {
@@ -45468,7 +43882,7 @@ function reviver(_key, value) {
45468
43882
  case "Complex":
45469
43883
  return Complex9.fromJSON(tagged);
45470
43884
  case "Fraction":
45471
- return Fraction4.fromJSON(tagged);
43885
+ return Fraction5.fromJSON(tagged);
45472
43886
  case "number":
45473
43887
  if (tagged.value === "Infinity") return Infinity;
45474
43888
  if (tagged.value === "-Infinity") return -Infinity;
@@ -47007,6 +45421,89 @@ function config(options) {
47007
45421
  return { ...shared };
47008
45422
  }
47009
45423
 
45424
+ // src/numeric/propagate-uncertainty.ts
45425
+ function asFiniteNumber(label, value) {
45426
+ if (typeof value !== "number" || !Number.isFinite(value)) {
45427
+ throw new TypeError(`${label} is not a finite number`);
45428
+ }
45429
+ return value;
45430
+ }
45431
+ function partialDerivative2(expr, name254, values) {
45432
+ const node = derivative2(expr, name254);
45433
+ return asFiniteNumber(`partial of "${expr}" with respect to "${name254}"`, node.evaluate(values));
45434
+ }
45435
+ function propagateUncertainty(expr, values, sigmas, options) {
45436
+ if (typeof expr !== "string" || expr.length === 0) {
45437
+ throw new TypeError("expr must be a non-empty string");
45438
+ }
45439
+ if (values === null || typeof values !== "object") {
45440
+ throw new TypeError("values must be an object of finite numbers");
45441
+ }
45442
+ const names = Object.keys(values);
45443
+ const point = {};
45444
+ for (const name254 of names) {
45445
+ point[name254] = asFiniteNumber(`values.${name254}`, values[name254]);
45446
+ }
45447
+ const covariance = options?.covariance;
45448
+ if (covariance !== void 0 && sigmas !== void 0) {
45449
+ throw new TypeError("pass either sigmas or covariance, not both");
45450
+ }
45451
+ if (sigmas !== void 0 && (sigmas === null || typeof sigmas !== "object")) {
45452
+ throw new TypeError("sigmas must be an object of finite numbers");
45453
+ }
45454
+ const partials = {};
45455
+ const gradient2 = [];
45456
+ for (const name254 of names) {
45457
+ const d = partialDerivative2(expr, name254, point);
45458
+ partials[name254] = d;
45459
+ gradient2.push(d);
45460
+ }
45461
+ const value = asFiniteNumber(`value of "${expr}"`, evaluate(expr, point));
45462
+ let variance2;
45463
+ if (covariance !== void 0) {
45464
+ const n = names.length;
45465
+ if (covariance.length !== n) {
45466
+ throw new TypeError(`covariance must be ${n}\xD7${n} to match values`);
45467
+ }
45468
+ variance2 = 0;
45469
+ for (let i = 0; i < n; i++) {
45470
+ const row2 = covariance[i];
45471
+ if (row2 === void 0 || row2.length !== n) {
45472
+ throw new TypeError(`covariance must be ${n}\xD7${n} to match values`);
45473
+ }
45474
+ let acc = 0;
45475
+ for (let j = 0; j < n; j++) {
45476
+ const sij = asFiniteNumber(`covariance[${i}][${j}]`, row2[j]);
45477
+ acc += sij * gradient2[j];
45478
+ }
45479
+ variance2 += gradient2[i] * acc;
45480
+ }
45481
+ } else {
45482
+ variance2 = 0;
45483
+ if (sigmas !== void 0) {
45484
+ for (const key2 of Object.keys(sigmas)) {
45485
+ if (!Object.prototype.hasOwnProperty.call(point, key2)) {
45486
+ throw new TypeError(`sigmas.${key2} has no matching value`);
45487
+ }
45488
+ }
45489
+ for (let i = 0; i < names.length; i++) {
45490
+ const name254 = names[i];
45491
+ if (!Object.prototype.hasOwnProperty.call(sigmas, name254)) continue;
45492
+ const sigma = asFiniteNumber(`sigmas.${name254}`, sigmas[name254]);
45493
+ if (sigma < 0) {
45494
+ throw new RangeError(`sigmas.${name254} must be >= 0`);
45495
+ }
45496
+ variance2 += (gradient2[i] * sigma) ** 2;
45497
+ }
45498
+ }
45499
+ }
45500
+ if (variance2 < 0) {
45501
+ if (variance2 > -1e-12) variance2 = 0;
45502
+ else throw new RangeError("covariance produced a negative variance");
45503
+ }
45504
+ return { value, sigma: Math.sqrt(variance2), partials };
45505
+ }
45506
+
47010
45507
  // src/help.ts
47011
45508
  import { createHelpClass, embeddedDocs } from "@danielsimonjr/mathts-expression";
47012
45509
  var savedConfig = {};
@@ -51320,8 +49817,8 @@ function intToRatPoly(p) {
51320
49817
  }
51321
49818
  function ratPolyToInt(p) {
51322
49819
  if (p.length === 0) return { poly: [], den: 1n };
51323
- let lcm2 = 1n;
51324
- const gcd2 = (a, b) => {
49820
+ let lcm3 = 1n;
49821
+ const gcd3 = (a, b) => {
51325
49822
  let x = a < 0n ? -a : a;
51326
49823
  let y = b < 0n ? -b : b;
51327
49824
  while (y !== 0n) {
@@ -51332,10 +49829,10 @@ function ratPolyToInt(p) {
51332
49829
  return x;
51333
49830
  };
51334
49831
  for (const r of p) {
51335
- const g = gcd2(lcm2, r.den);
51336
- lcm2 = lcm2 / g * r.den;
49832
+ const g = gcd3(lcm3, r.den);
49833
+ lcm3 = lcm3 / g * r.den;
51337
49834
  }
51338
- return { poly: trim(p.map((r) => r.num * lcm2 / r.den)), den: lcm2 };
49835
+ return { poly: trim(p.map((r) => r.num * lcm3 / r.den)), den: lcm3 };
51339
49836
  }
51340
49837
  function rpAdd(a, b) {
51341
49838
  const n = Math.max(a.length, b.length);
@@ -57139,6 +55636,10 @@ export {
57139
55636
  DIST_WORKER_THRESHOLD,
57140
55637
  EARTH_RADIUS_KM,
57141
55638
  GAUSS_WORKER_THRESHOLD,
55639
+ GL4ConvergenceError,
55640
+ GL4_A,
55641
+ GL4_B,
55642
+ GL4_C,
57142
55643
  GPU_ELEMENTWISE_OPS,
57143
55644
  GPU_MIN_ELEMENTS2 as GPU_MIN_ELEMENTS,
57144
55645
  GPU_REDUCE_OPS,
@@ -57561,6 +56062,7 @@ export {
57561
56062
  gammainc,
57562
56063
  gammaincp,
57563
56064
  gasConstant,
56065
+ gaussLegendre4,
57564
56066
  gaussQuad,
57565
56067
  gaussianKDE,
57566
56068
  gaussianProcessRegression,
@@ -57661,6 +56163,7 @@ export {
57661
56163
  isNumeric,
57662
56164
  isPositive,
57663
56165
  isPrime2 as isPrime,
56166
+ isWasmLoaded,
57664
56167
  isZero3 as isZero,
57665
56168
  istft,
57666
56169
  jacobiCN,
@@ -57726,6 +56229,7 @@ export {
57726
56229
  linregress,
57727
56230
  linsolve,
57728
56231
  ljungBox,
56232
+ loadWasm,
57729
56233
  loess,
57730
56234
  log,
57731
56235
  log10,
@@ -57901,6 +56405,7 @@ export {
57901
56405
  permutationTest,
57902
56406
  permutations,
57903
56407
  permutationsGen,
56408
+ physicsScope,
57904
56409
  pickRandom,
57905
56410
  piecewise,
57906
56411
  pinv,
@@ -57940,6 +56445,7 @@ export {
57940
56445
  procrustes,
57941
56446
  prod,
57942
56447
  projectVector,
56448
+ propagateUncertainty,
57943
56449
  proportionCI,
57944
56450
  proportionZTest,
57945
56451
  protonMass,
@@ -57968,6 +56474,7 @@ export {
57968
56474
  range,
57969
56475
  rank,
57970
56476
  rankdata,
56477
+ rationalNullspace,
57971
56478
  rationalize,
57972
56479
  rayPlaneIntersect,
57973
56480
  rayTriangleIntersect,