@cortex-js/compute-engine 0.53.0 → 0.53.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/compute-engine.esm.js +719 -59
  2. package/dist/compute-engine.min.esm.js +519 -47
  3. package/dist/{compute-engine.min.umd.js → compute-engine.min.umd.cjs} +525 -53
  4. package/dist/{compute-engine.umd.js → compute-engine.umd.cjs} +719 -59
  5. package/dist/math-json.esm.js +2 -2
  6. package/dist/math-json.min.esm.js +2 -2
  7. package/dist/{math-json.min.umd.js → math-json.min.umd.cjs} +2 -2
  8. package/dist/{math-json.umd.js → math-json.umd.cjs} +2 -2
  9. package/dist/types/common/ansi-codes.d.ts +1 -1
  10. package/dist/types/common/configuration-change.d.ts +1 -1
  11. package/dist/types/common/fuzzy-string-match.d.ts +1 -1
  12. package/dist/types/common/grapheme-splitter.d.ts +1 -1
  13. package/dist/types/common/interruptible.d.ts +1 -1
  14. package/dist/types/common/one-of.d.ts +1 -1
  15. package/dist/types/common/signals.d.ts +1 -1
  16. package/dist/types/common/type/ast-nodes.d.ts +1 -1
  17. package/dist/types/common/type/boxed-type.d.ts +1 -1
  18. package/dist/types/common/type/lexer.d.ts +1 -1
  19. package/dist/types/common/type/parse.d.ts +1 -1
  20. package/dist/types/common/type/parser.d.ts +1 -1
  21. package/dist/types/common/type/primitive.d.ts +1 -1
  22. package/dist/types/common/type/reduce.d.ts +1 -1
  23. package/dist/types/common/type/serialize.d.ts +1 -1
  24. package/dist/types/common/type/subtype.d.ts +1 -1
  25. package/dist/types/common/type/type-builder.d.ts +1 -1
  26. package/dist/types/common/type/types.d.ts +1 -1
  27. package/dist/types/common/type/utils.d.ts +1 -1
  28. package/dist/types/common/utils.d.ts +1 -1
  29. package/dist/types/compute-engine/assume.d.ts +1 -1
  30. package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
  31. package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
  32. package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
  33. package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
  34. package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
  35. package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
  36. package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
  37. package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
  38. package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
  39. package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
  40. package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
  41. package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
  42. package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
  43. package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
  44. package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
  45. package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
  46. package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
  47. package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
  48. package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
  49. package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
  50. package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
  51. package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
  52. package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
  53. package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
  54. package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
  55. package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
  56. package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
  57. package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
  58. package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
  59. package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
  60. package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
  61. package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
  62. package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
  63. package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
  64. package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
  65. package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
  66. package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
  67. package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
  68. package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
  69. package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
  70. package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
  71. package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
  72. package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
  73. package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
  74. package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
  75. package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
  76. package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
  77. package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
  78. package/dist/types/compute-engine/collection-utils.d.ts +1 -1
  79. package/dist/types/compute-engine/compilation/base-compiler.d.ts +1 -1
  80. package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
  81. package/dist/types/compute-engine/compilation/glsl-target.d.ts +1 -1
  82. package/dist/types/compute-engine/compilation/gpu-target.d.ts +68 -1
  83. package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
  84. package/dist/types/compute-engine/compilation/javascript-target.d.ts +1 -1
  85. package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
  86. package/dist/types/compute-engine/compilation/types.d.ts +9 -1
  87. package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
  88. package/dist/types/compute-engine/cost-function.d.ts +1 -1
  89. package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
  90. package/dist/types/compute-engine/engine-cache.d.ts +1 -1
  91. package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
  92. package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
  93. package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
  94. package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
  95. package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
  96. package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
  97. package/dist/types/compute-engine/engine-latex-dictionary-state.d.ts +1 -1
  98. package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
  99. package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
  100. package/dist/types/compute-engine/engine-parse-entrypoint.d.ts +1 -1
  101. package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
  102. package/dist/types/compute-engine/engine-scope.d.ts +1 -1
  103. package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
  104. package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
  105. package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
  106. package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
  107. package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
  108. package/dist/types/compute-engine/free-functions.d.ts +1 -1
  109. package/dist/types/compute-engine/function-utils.d.ts +1 -1
  110. package/dist/types/compute-engine/global-types.d.ts +1 -1
  111. package/dist/types/compute-engine/index.d.ts +1 -1
  112. package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
  113. package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
  114. package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
  115. package/dist/types/compute-engine/interval/index.d.ts +1 -1
  116. package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
  117. package/dist/types/compute-engine/interval/types.d.ts +1 -1
  118. package/dist/types/compute-engine/interval/util.d.ts +1 -1
  119. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
  120. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
  121. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
  122. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
  123. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
  124. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
  125. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
  126. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
  127. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
  128. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
  129. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
  130. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
  131. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
  132. package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
  133. package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
  134. package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
  135. package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
  136. package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
  137. package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
  138. package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
  139. package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
  140. package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
  141. package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
  142. package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
  143. package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
  144. package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
  145. package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
  146. package/dist/types/compute-engine/library/calculus.d.ts +1 -1
  147. package/dist/types/compute-engine/library/collections.d.ts +1 -1
  148. package/dist/types/compute-engine/library/colors.d.ts +1 -1
  149. package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
  150. package/dist/types/compute-engine/library/complex.d.ts +1 -1
  151. package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
  152. package/dist/types/compute-engine/library/core.d.ts +1 -1
  153. package/dist/types/compute-engine/library/fractals.d.ts +1 -1
  154. package/dist/types/compute-engine/library/library.d.ts +1 -1
  155. package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
  156. package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
  157. package/dist/types/compute-engine/library/logic.d.ts +1 -1
  158. package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
  159. package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
  160. package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
  161. package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
  162. package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
  163. package/dist/types/compute-engine/library/sets.d.ts +1 -1
  164. package/dist/types/compute-engine/library/statistics.d.ts +1 -1
  165. package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
  166. package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
  167. package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
  168. package/dist/types/compute-engine/library/units.d.ts +1 -1
  169. package/dist/types/compute-engine/library/utils.d.ts +1 -1
  170. package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
  171. package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
  172. package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
  173. package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
  174. package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
  175. package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
  176. package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
  177. package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
  178. package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
  179. package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +2 -2
  180. package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
  181. package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
  182. package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
  183. package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
  184. package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
  185. package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
  186. package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
  187. package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
  188. package/dist/types/compute-engine/numerics/types.d.ts +1 -1
  189. package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
  190. package/dist/types/compute-engine/oeis.d.ts +1 -1
  191. package/dist/types/compute-engine/sequence.d.ts +1 -1
  192. package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
  193. package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
  194. package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
  195. package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
  196. package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
  197. package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
  198. package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
  199. package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
  200. package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
  201. package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
  202. package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
  203. package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
  204. package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
  205. package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
  206. package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
  207. package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
  208. package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
  209. package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
  210. package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
  211. package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
  212. package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
  213. package/dist/types/compute-engine/types-definitions.d.ts +1 -1
  214. package/dist/types/compute-engine/types-engine.d.ts +1 -1
  215. package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
  216. package/dist/types/compute-engine/types-expression.d.ts +1 -1
  217. package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
  218. package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
  219. package/dist/types/compute-engine/types-serialization.d.ts +1 -1
  220. package/dist/types/compute-engine/types.d.ts +1 -1
  221. package/dist/types/compute-engine.d.ts +1 -1
  222. package/dist/types/math-json/symbols.d.ts +1 -1
  223. package/dist/types/math-json/types.d.ts +1 -1
  224. package/dist/types/math-json/utils.d.ts +1 -1
  225. package/dist/types/math-json.d.ts +2 -2
  226. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- /** Compute Engine 0.53.0 */
1
+ /** Compute Engine 0.53.1 */
2
2
 
3
3
  // node_modules/complex-esm/dist/src/complex.js
4
4
  var cosh = Math.cosh || function(x) {
@@ -11083,7 +11083,7 @@ function parseWhereExpression(parser, lhs, until) {
11083
11083
  condition: (p) => {
11084
11084
  if (until?.condition?.(p)) return true;
11085
11085
  const saved = p.index;
11086
- p.skipSpace();
11086
+ p.skipVisualSpace();
11087
11087
  const isComma = p.peek === ",";
11088
11088
  p.index = saved;
11089
11089
  return isComma;
@@ -11091,11 +11091,11 @@ function parseWhereExpression(parser, lhs, until) {
11091
11091
  };
11092
11092
  const bindings = [];
11093
11093
  do {
11094
- parser.skipSpace();
11094
+ parser.skipVisualSpace();
11095
11095
  const binding = parser.parseExpression(bindingTerminator);
11096
11096
  if (!binding) break;
11097
11097
  bindings.push(binding);
11098
- parser.skipSpace();
11098
+ parser.skipVisualSpace();
11099
11099
  } while (parser.match(","));
11100
11100
  if (bindings.length === 0) return null;
11101
11101
  const block = [];
@@ -11594,14 +11594,11 @@ function* factorial3(n) {
11594
11594
  let loop = n;
11595
11595
  let sum2 = n;
11596
11596
  let val = n;
11597
- let counter = 0;
11598
11597
  while (loop > 2) {
11599
11598
  loop -= BigInt(2);
11600
11599
  sum2 += loop;
11601
11600
  val *= sum2;
11602
- counter += 1;
11603
- if (counter % 5e4 === 0 || counter > 1e4 && counter % 500 === 0)
11604
- yield val;
11601
+ yield val;
11605
11602
  }
11606
11603
  return val;
11607
11604
  }
@@ -16670,13 +16667,14 @@ function gcd3(a, b) {
16670
16667
  function lcm3(a, b) {
16671
16668
  return a.mul(b).div(gcd3(a, b));
16672
16669
  }
16673
- function factorial23(ce, n) {
16670
+ function* factorial23(ce, n) {
16674
16671
  if (!n.isInteger() || n.isNegative()) return ce._BIGNUM_NAN;
16675
16672
  if (n.lessThan(1)) return ce._BIGNUM_ONE;
16676
16673
  let result = n;
16677
16674
  while (n.greaterThan(2)) {
16678
16675
  n = n.minus(2);
16679
16676
  result = result.mul(n);
16677
+ yield result;
16680
16678
  }
16681
16679
  return result;
16682
16680
  }
@@ -20193,24 +20191,30 @@ var COLLECTIONS_LIBRARY = {
20193
20191
  if (initial.type.matches("real") && collection.type.matches(ce.type("collection<real>"))) {
20194
20192
  const compiled = ce._compile(fn);
20195
20193
  if (compiled.calling !== "lambda" || !compiled.run) return void 0;
20196
- let accumulator2 = initial.re;
20197
- let first2 = true;
20198
- for (const item of collection.each()) {
20199
- if (first2) accumulator2 = item.re;
20200
- else accumulator2 = compiled.run(accumulator2, item.re);
20201
- first2 = false;
20202
- }
20203
- return ce.box(accumulator2);
20194
+ return run(
20195
+ (function* () {
20196
+ let accumulator = initial.re;
20197
+ let first = true;
20198
+ for (const item of collection.each()) {
20199
+ if (first) accumulator = item.re;
20200
+ else accumulator = compiled.run(accumulator, item.re);
20201
+ first = false;
20202
+ yield;
20203
+ }
20204
+ return ce.box(accumulator);
20205
+ })(),
20206
+ ce._timeRemaining
20207
+ );
20204
20208
  }
20205
20209
  const f = applicable(fn);
20206
- let accumulator = initial;
20207
- let first = true;
20208
- for (const item of collection.each()) {
20209
- if (first) accumulator = item;
20210
- else accumulator = f([accumulator, item]) ?? ce.Nothing;
20211
- first = false;
20212
- }
20213
- return accumulator;
20210
+ return run(
20211
+ reduceCollection(
20212
+ collection,
20213
+ (acc, x) => f([acc, x]) ?? ce.Nothing,
20214
+ initial
20215
+ ),
20216
+ ce._timeRemaining
20217
+ );
20214
20218
  }
20215
20219
  },
20216
20220
  Join: {
@@ -21435,12 +21439,10 @@ function tally(collection) {
21435
21439
  }
21436
21440
  function* reduceCollection(collection, fn, initial) {
21437
21441
  let acc = initial;
21438
- let counter = 0;
21439
21442
  for (const x of collection.each()) {
21440
21443
  const result = fn(acc, x);
21441
21444
  if (result === null) return void 0;
21442
- counter += 1;
21443
- if (counter % 1e3 === 0) yield acc;
21445
+ yield acc;
21444
21446
  acc = result;
21445
21447
  }
21446
21448
  return acc;
@@ -22859,12 +22861,10 @@ function* reduceBigOp(body, indexes, fn, initial) {
22859
22861
  const indexingSets = normalizeIndexingSets(indexes);
22860
22862
  const cartesianArray = indexingSetCartesianProduct(indexingSets);
22861
22863
  let result = initial;
22862
- let counter = 0;
22863
22864
  for (const element of cartesianArray) {
22864
22865
  indexingSets.forEach((x, i) => ce.assign(x.index, element[i]));
22865
22866
  result = fn(result, body) ?? void 0;
22866
- counter += 1;
22867
- if (counter % 1e3 === 0) yield result;
22867
+ yield result;
22868
22868
  if (result === void 0) break;
22869
22869
  }
22870
22870
  return result ?? void 0;
@@ -22931,7 +22931,6 @@ function* reduceElementIndexingSets(body, indexes, fn, initial, returnReason = f
22931
22931
  return initial;
22932
22932
  }
22933
22933
  let result = initial;
22934
- let counter = 0;
22935
22934
  while (true) {
22936
22935
  for (let i = 0; i < elementDomains.length; i++) {
22937
22936
  ce.assign(
@@ -22940,8 +22939,7 @@ function* reduceElementIndexingSets(body, indexes, fn, initial, returnReason = f
22940
22939
  );
22941
22940
  }
22942
22941
  result = fn(result, body) ?? void 0;
22943
- counter++;
22944
- if (counter % 1e3 === 0) yield result;
22942
+ yield result;
22945
22943
  if (result === void 0) break;
22946
22944
  let dim = elementDomains.length - 1;
22947
22945
  while (dim >= 0) {
@@ -23911,7 +23909,8 @@ var ARITHMETIC_LIBRARY = [
23911
23909
  ce._timeRemaining
23912
23910
  )
23913
23911
  );
23914
- } catch {
23912
+ } catch (e) {
23913
+ if (e instanceof CancellationError) throw e;
23915
23914
  return void 0;
23916
23915
  }
23917
23916
  },
@@ -23930,7 +23929,8 @@ var ARITHMETIC_LIBRARY = [
23930
23929
  signal
23931
23930
  )
23932
23931
  );
23933
- } catch {
23932
+ } catch (e) {
23933
+ if (e instanceof CancellationError) throw e;
23934
23934
  return void 0;
23935
23935
  }
23936
23936
  }
@@ -23948,7 +23948,7 @@ var ARITHMETIC_LIBRARY = [
23948
23948
  if (n === null) return void 0;
23949
23949
  const ce = x.engine;
23950
23950
  if (bignumPreferred(ce))
23951
- return ce.number(factorial23(ce, ce.bignum(n)));
23951
+ return ce.number(run(factorial23(ce, ce.bignum(n)), ce._timeRemaining));
23952
23952
  return ce.number(factorial22(n));
23953
23953
  }
23954
23954
  },
@@ -33539,7 +33539,7 @@ function* runLoop(body, collection, ce) {
33539
33539
  if (isFunction2(result, "Break")) return result.op1;
33540
33540
  if (result.operator === "Return") return result;
33541
33541
  i2 += 1;
33542
- if (i2 % 1e3 === 0) yield result;
33542
+ yield result;
33543
33543
  if (i2 > ce.iterationLimit)
33544
33544
  throw new CancellationError({ cause: "iteration-limit-exceeded" });
33545
33545
  }
@@ -33551,7 +33551,7 @@ function* runLoop(body, collection, ce) {
33551
33551
  if (isFunction2(result, "Break")) return result.op1;
33552
33552
  if (result.operator === "Return") return result;
33553
33553
  i += 1;
33554
- if (i % 1e3 === 0) yield result;
33554
+ yield result;
33555
33555
  if (i > ce.iterationLimit)
33556
33556
  throw new CancellationError({ cause: "iteration-limit-exceeded" });
33557
33557
  }
@@ -48911,9 +48911,11 @@ function withDeadline(engine, fn) {
48911
48911
  return () => {
48912
48912
  if (engine._deadline === void 0) {
48913
48913
  engine._deadline = Date.now() + engine.timeLimit;
48914
- const result = fn();
48915
- engine._deadline = void 0;
48916
- return result;
48914
+ try {
48915
+ return fn();
48916
+ } finally {
48917
+ engine._deadline = void 0;
48918
+ }
48917
48919
  }
48918
48920
  return fn();
48919
48921
  };
@@ -48922,9 +48924,11 @@ function withDeadlineAsync(engine, fn) {
48922
48924
  return async () => {
48923
48925
  if (engine._deadline === void 0) {
48924
48926
  engine._deadline = Date.now() + engine.timeLimit;
48925
- const result = await fn();
48926
- engine._deadline = void 0;
48927
- return result;
48927
+ try {
48928
+ return await fn();
48929
+ } finally {
48930
+ engine._deadline = void 0;
48931
+ }
48928
48932
  }
48929
48933
  return fn();
48930
48934
  };
@@ -50422,6 +50426,13 @@ var BaseCompiler = class _BaseCompiler {
50422
50426
  }
50423
50427
  }
50424
50428
  if (h === "Function") {
50429
+ const fnFn = target.functions?.(h);
50430
+ if (typeof fnFn === "function")
50431
+ return fnFn(
50432
+ args,
50433
+ (expr) => _BaseCompiler.compile(expr, target),
50434
+ target
50435
+ );
50425
50436
  const params = args.slice(1).map((x) => isSymbol2(x) ? x.symbol : "_");
50426
50437
  return `((${params.join(", ")}) => ${_BaseCompiler.compile(
50427
50438
  args[0].canonical,
@@ -50431,15 +50442,26 @@ var BaseCompiler = class _BaseCompiler {
50431
50442
  }
50432
50443
  )})`;
50433
50444
  }
50434
- if (h === "Declare")
50435
- return `let ${isSymbol2(args[0]) ? args[0].symbol : "_"}`;
50445
+ if (h === "Declare") {
50446
+ const name = isSymbol2(args[0]) ? args[0].symbol : "_";
50447
+ return target.declare ? target.declare(name) : `let ${name}`;
50448
+ }
50436
50449
  if (h === "Assign")
50437
50450
  return `${isSymbol2(args[0]) ? args[0].symbol : "_"} = ${_BaseCompiler.compile(args[1], target)}`;
50438
50451
  if (h === "Return")
50439
50452
  return `return ${_BaseCompiler.compile(args[0], target)}`;
50440
50453
  if (h === "Break") return "break";
50441
50454
  if (h === "Continue") return "continue";
50442
- if (h === "Loop") return _BaseCompiler.compileForLoop(args, target);
50455
+ if (h === "Loop") {
50456
+ const loopFn = target.functions?.(h);
50457
+ if (typeof loopFn === "function")
50458
+ return loopFn(
50459
+ args,
50460
+ (expr) => _BaseCompiler.compile(expr, target),
50461
+ target
50462
+ );
50463
+ return _BaseCompiler.compileForLoop(args, target);
50464
+ }
50443
50465
  if (h === "If") {
50444
50466
  if (args.length !== 3) throw new Error("If: wrong number of arguments");
50445
50467
  const fn2 = target.functions?.(h);
@@ -50516,16 +50538,35 @@ var BaseCompiler = class _BaseCompiler {
50516
50538
  if (args.length === 1 && locals.length === 0) {
50517
50539
  return _BaseCompiler.compile(args[0], target);
50518
50540
  }
50519
- const result = args.filter((a) => !isSymbol2(a, "Nothing")).map(
50520
- (arg) => _BaseCompiler.compile(arg, {
50521
- ...target,
50522
- var: (id) => {
50523
- if (locals.includes(id)) return id;
50524
- return target.var(id);
50541
+ const typeHints = {};
50542
+ if (target.declare && target.language) {
50543
+ const isWGSL = target.language === "wgsl";
50544
+ for (const local of locals) {
50545
+ for (const arg of args) {
50546
+ if (isFunction2(arg, "Assign") && isSymbol2(arg.ops[0], local)) {
50547
+ if (_BaseCompiler.isComplexValued(arg.ops[1])) {
50548
+ typeHints[local] = isWGSL ? "vec2f" : "vec2";
50549
+ }
50550
+ break;
50551
+ }
50525
50552
  }
50526
- })
50527
- ).filter((s) => s !== "");
50553
+ }
50554
+ }
50555
+ const localTarget = {
50556
+ ...target,
50557
+ var: (id) => {
50558
+ if (locals.includes(id)) return id;
50559
+ return target.var(id);
50560
+ }
50561
+ };
50562
+ const result = args.filter((a) => !isSymbol2(a, "Nothing")).map((arg) => {
50563
+ if (isFunction2(arg, "Declare") && isSymbol2(arg.ops[0]) && target.declare) {
50564
+ return target.declare(arg.ops[0].symbol, typeHints[arg.ops[0].symbol]);
50565
+ }
50566
+ return _BaseCompiler.compile(arg, localTarget);
50567
+ }).filter((s) => s !== "");
50528
50568
  if (result.length === 0) return "";
50569
+ if (target.block) return target.block(result);
50529
50570
  result[result.length - 1] = `return ${result[result.length - 1]}`;
50530
50571
  return `(() => {${target.ws("\n")}${result.join(
50531
50572
  `;${target.ws("\n")}`
@@ -57291,6 +57332,62 @@ var GPU_OPERATORS = {
57291
57332
  function gpuVec2(target) {
57292
57333
  return target?.language === "wgsl" ? "vec2f" : "vec2";
57293
57334
  }
57335
+ var GPU_UNROLL_LIMIT = 100;
57336
+ function compileGPUSumProduct(kind, args, _compile2, target) {
57337
+ if (!args[0]) throw new Error(`${kind}: no body`);
57338
+ if (!args[1]) throw new Error(`${kind}: no indexing set`);
57339
+ if (BaseCompiler.isComplexValued(args[0]))
57340
+ throw new Error(
57341
+ `${kind}: complex-valued body not supported in GPU targets`
57342
+ );
57343
+ const limitsExpr = args[1];
57344
+ if (!isFunction2(limitsExpr, "Limits"))
57345
+ throw new Error(`${kind}: expected Limits indexing set`);
57346
+ const limitsOps = limitsExpr.ops;
57347
+ const index = isSymbol2(limitsOps[0]) ? limitsOps[0].symbol : "_";
57348
+ const lowerRe = limitsOps[1].re;
57349
+ const upperRe = limitsOps[2].re;
57350
+ const lowerNum = !isNaN(lowerRe) && Number.isFinite(lowerRe) ? Math.floor(lowerRe) : void 0;
57351
+ const upperNum = !isNaN(upperRe) && Number.isFinite(upperRe) ? Math.floor(upperRe) : void 0;
57352
+ const isSum = kind === "Sum";
57353
+ const op = isSum ? "+" : "*";
57354
+ const identity = isSum ? "0.0" : "1.0";
57355
+ const isWGSL = target.language === "wgsl";
57356
+ const bothConstant = lowerNum !== void 0 && upperNum !== void 0;
57357
+ if (bothConstant && lowerNum > upperNum) return identity;
57358
+ if (bothConstant && upperNum - lowerNum + 1 <= GPU_UNROLL_LIMIT) {
57359
+ const terms = [];
57360
+ for (let k = lowerNum; k <= upperNum; k++) {
57361
+ const kStr = formatGPUNumber(k);
57362
+ const innerTarget = {
57363
+ ...target,
57364
+ var: (id) => id === index ? kStr : target.var(id)
57365
+ };
57366
+ terms.push(`(${BaseCompiler.compile(args[0], innerTarget)})`);
57367
+ }
57368
+ return `(${terms.join(` ${op} `)})`;
57369
+ }
57370
+ const acc = BaseCompiler.tempVar();
57371
+ const floatType = isWGSL ? "f32" : "float";
57372
+ const intType = isWGSL ? "i32" : "int";
57373
+ const bodyTarget = {
57374
+ ...target,
57375
+ var: (id) => id === index ? isWGSL ? `f32(${index})` : `float(${index})` : target.var(id)
57376
+ };
57377
+ const body = BaseCompiler.compile(args[0], bodyTarget);
57378
+ const lowerStr = lowerNum !== void 0 ? String(lowerNum) : BaseCompiler.compile(limitsOps[1], target);
57379
+ const upperStr = upperNum !== void 0 ? String(upperNum) : BaseCompiler.compile(limitsOps[2], target);
57380
+ const accDecl = isWGSL ? `var ${acc}: ${floatType}` : `${floatType} ${acc}`;
57381
+ const indexDecl = isWGSL ? `var ${index}: ${intType}` : `${intType} ${index}`;
57382
+ const lines = [
57383
+ `${accDecl} = ${identity};`,
57384
+ `for (${indexDecl} = ${lowerStr}; ${index} <= ${upperStr}; ${index}++) {`,
57385
+ ` ${acc} ${op}= ${body};`,
57386
+ `}`,
57387
+ `return ${acc}`
57388
+ ];
57389
+ return lines.join("\n");
57390
+ }
57294
57391
  var GPU_FUNCTIONS = {
57295
57392
  // Variadic arithmetic (for function-call form, e.g., with vectors)
57296
57393
  Add: (args, compile3, target) => {
@@ -57640,6 +57737,27 @@ var GPU_FUNCTIONS = {
57640
57737
  if (x === null) throw new Error("ErfInv: no argument");
57641
57738
  return `_gpu_erfinv(${compile3(x)})`;
57642
57739
  },
57740
+ Heaviside: ([x], compile3) => {
57741
+ if (x === null) throw new Error("Heaviside: no argument");
57742
+ return `_gpu_heaviside(${compile3(x)})`;
57743
+ },
57744
+ Sinc: ([x], compile3) => {
57745
+ if (x === null) throw new Error("Sinc: no argument");
57746
+ return `_gpu_sinc(${compile3(x)})`;
57747
+ },
57748
+ FresnelC: ([x], compile3) => {
57749
+ if (x === null) throw new Error("FresnelC: no argument");
57750
+ return `_gpu_fresnelC(${compile3(x)})`;
57751
+ },
57752
+ FresnelS: ([x], compile3) => {
57753
+ if (x === null) throw new Error("FresnelS: no argument");
57754
+ return `_gpu_fresnelS(${compile3(x)})`;
57755
+ },
57756
+ BesselJ: ([n, x], compile3, target) => {
57757
+ if (n === null || x === null) throw new Error("BesselJ: need two arguments");
57758
+ const intCast = target?.language === "wgsl" ? "i32" : "int";
57759
+ return `_gpu_besselJ(${intCast}(${compile3(n)}), ${compile3(x)})`;
57760
+ },
57643
57761
  // Additional math functions
57644
57762
  Lb: "log2",
57645
57763
  Log: (args, compile3) => {
@@ -57725,7 +57843,45 @@ var GPU_FUNCTIONS = {
57725
57843
  Length: "length",
57726
57844
  Normalize: "normalize",
57727
57845
  Reflect: "reflect",
57728
- Refract: "refract"
57846
+ Refract: "refract",
57847
+ // Sum/Product — unrolled or for-loop
57848
+ Sum: (args, compile3, target) => compileGPUSumProduct("Sum", args, compile3, target),
57849
+ Product: (args, compile3, target) => compileGPUSumProduct("Product", args, compile3, target),
57850
+ // Loop — GPU for-loop (no IIFE, no let)
57851
+ Loop: (args, _compile2, target) => {
57852
+ if (!args[0]) throw new Error("Loop: no body");
57853
+ if (!args[1]) throw new Error("Loop: no indexing set");
57854
+ const indexing = args[1];
57855
+ if (!isFunction2(indexing, "Element"))
57856
+ throw new Error("Loop: expected Element(index, Range(lo, hi))");
57857
+ const indexExpr = indexing.ops[0];
57858
+ const rangeExpr = indexing.ops[1];
57859
+ if (!isSymbol2(indexExpr))
57860
+ throw new Error("Loop: index must be a symbol");
57861
+ if (!isFunction2(rangeExpr, "Range"))
57862
+ throw new Error("Loop: expected Range(lo, hi)");
57863
+ const index = indexExpr.symbol;
57864
+ const lower = Math.floor(rangeExpr.ops[0].re);
57865
+ const upper = Math.floor(rangeExpr.ops[1].re);
57866
+ if (!Number.isFinite(lower) || !Number.isFinite(upper))
57867
+ throw new Error("Loop: bounds must be finite numbers");
57868
+ const isWGSL = target.language === "wgsl";
57869
+ const intType = isWGSL ? "i32" : "int";
57870
+ const bodyCode = BaseCompiler.compile(args[0], {
57871
+ ...target,
57872
+ var: (id) => id === index ? index : target.var(id)
57873
+ });
57874
+ const indexDecl = isWGSL ? `var ${index}: ${intType}` : `${intType} ${index}`;
57875
+ return `for (${indexDecl} = ${lower}; ${index} <= ${upper}; ${index}++) {
57876
+ ${bodyCode};
57877
+ }`;
57878
+ },
57879
+ // Function (lambda) — not supported in GPU
57880
+ Function: () => {
57881
+ throw new Error(
57882
+ "Anonymous functions (Function) are not supported in GPU targets"
57883
+ );
57884
+ }
57729
57885
  };
57730
57886
  function compileGPUMatrix(args, compile3, vecFn, matFn, arrayFn) {
57731
57887
  const body = args[0];
@@ -57806,6 +57962,476 @@ float _gpu_erfinv(float x) {
57806
57962
  return sqrt(pi) * 0.5 * (x + (pi / 12.0) * x3 + (7.0 * pi * pi / 480.0) * x5 + (127.0 * pi * pi * pi / 40320.0) * x7 + (4369.0 * pi * pi * pi * pi / 5806080.0) * x9);
57807
57963
  }
57808
57964
  `;
57965
+ var GPU_HEAVISIDE_PREAMBLE_GLSL = `
57966
+ float _gpu_heaviside(float x) {
57967
+ if (x < 0.0) return 0.0;
57968
+ if (x > 0.0) return 1.0;
57969
+ return 0.5;
57970
+ }
57971
+ `;
57972
+ var GPU_HEAVISIDE_PREAMBLE_WGSL = `
57973
+ fn _gpu_heaviside(x: f32) -> f32 {
57974
+ if (x < 0.0) { return 0.0; }
57975
+ if (x > 0.0) { return 1.0; }
57976
+ return 0.5;
57977
+ }
57978
+ `;
57979
+ var GPU_SINC_PREAMBLE_GLSL = `
57980
+ float _gpu_sinc(float x) {
57981
+ if (abs(x) < 1e-10) return 1.0;
57982
+ return sin(x) / x;
57983
+ }
57984
+ `;
57985
+ var GPU_SINC_PREAMBLE_WGSL = `
57986
+ fn _gpu_sinc(x: f32) -> f32 {
57987
+ if (abs(x) < 1e-10) { return 1.0; }
57988
+ return sin(x) / x;
57989
+ }
57990
+ `;
57991
+ var GPU_POLEVL_PREAMBLE_GLSL = `
57992
+ float _gpu_polevl(float x, float c[12], int n) {
57993
+ float ans = c[0];
57994
+ for (int i = 1; i < n; i++) ans = ans * x + c[i];
57995
+ return ans;
57996
+ }
57997
+ `;
57998
+ var GPU_POLEVL_PREAMBLE_WGSL = `
57999
+ fn _gpu_polevl(x: f32, c: array<f32, 12>, n: i32) -> f32 {
58000
+ var ans = c[0];
58001
+ for (var i: i32 = 1; i < n; i++) { ans = ans * x + c[i]; }
58002
+ return ans;
58003
+ }
58004
+ `;
58005
+ var GPU_FRESNELC_PREAMBLE_GLSL = `
58006
+ float _gpu_fresnelC(float x_in) {
58007
+ float sgn = x_in < 0.0 ? -1.0 : 1.0;
58008
+ float x = abs(x_in);
58009
+
58010
+ if (x < 1.6) {
58011
+ float x2 = x * x;
58012
+ float t = x2 * x2;
58013
+ float cn[6] = float[6](
58014
+ -4.98843114573573548651e-8, 9.50428062829859605134e-6,
58015
+ -6.45191435683965050962e-4, 1.88843319396703850064e-2,
58016
+ -2.05525900955013891793e-1, 9.99999999999999998822e-1
58017
+ );
58018
+ float cd[7] = float[7](
58019
+ 3.99982968972495980367e-12, 9.15439215774657478799e-10,
58020
+ 1.25001862479598821474e-7, 1.22262789024179030997e-5,
58021
+ 8.68029542941784300606e-4, 4.12142090722199792936e-2, 1.0
58022
+ );
58023
+ return sgn * x * _gpu_polevl(t, cn, 6) / _gpu_polevl(t, cd, 7);
58024
+ }
58025
+
58026
+ if (x < 36.0) {
58027
+ float x2 = x * x;
58028
+ float t = 3.14159265358979 * x2;
58029
+ float u = 1.0 / (t * t);
58030
+ float fn[10] = float[10](
58031
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58032
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58033
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58034
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58035
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20
58036
+ );
58037
+ float fd[11] = float[11](
58038
+ 1.0, 7.51586398353378947175e-1,
58039
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58040
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58041
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58042
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58043
+ 1.25443237090011264384e-20
58044
+ );
58045
+ float gn[11] = float[11](
58046
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58047
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58048
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58049
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58050
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58051
+ 1.86958710162783235106e-22
58052
+ );
58053
+ float gd[12] = float[12](
58054
+ 1.0, 1.47495759925128324529,
58055
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58056
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58057
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58058
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58059
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58060
+ );
58061
+ float f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58062
+ float g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58063
+ float z = 1.5707963267948966 * x2;
58064
+ float c = cos(z);
58065
+ float s = sin(z);
58066
+ return sgn * (0.5 + (f * s - g * c) / (3.14159265358979 * x));
58067
+ }
58068
+
58069
+ return sgn * 0.5;
58070
+ }
58071
+ `;
58072
+ var GPU_FRESNELC_PREAMBLE_WGSL = `
58073
+ fn _gpu_fresnelC(x_in: f32) -> f32 {
58074
+ let sgn: f32 = select(1.0, -1.0, x_in < 0.0);
58075
+ let x = abs(x_in);
58076
+
58077
+ if (x < 1.6) {
58078
+ let x2 = x * x;
58079
+ let t = x2 * x2;
58080
+ var cn = array<f32, 12>(
58081
+ -4.98843114573573548651e-8, 9.50428062829859605134e-6,
58082
+ -6.45191435683965050962e-4, 1.88843319396703850064e-2,
58083
+ -2.05525900955013891793e-1, 9.99999999999999998822e-1,
58084
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
58085
+ );
58086
+ var cd = array<f32, 12>(
58087
+ 3.99982968972495980367e-12, 9.15439215774657478799e-10,
58088
+ 1.25001862479598821474e-7, 1.22262789024179030997e-5,
58089
+ 8.68029542941784300606e-4, 4.12142090722199792936e-2, 1.0,
58090
+ 0.0, 0.0, 0.0, 0.0, 0.0
58091
+ );
58092
+ return sgn * x * _gpu_polevl(t, cn, 6) / _gpu_polevl(t, cd, 7);
58093
+ }
58094
+
58095
+ if (x < 36.0) {
58096
+ let x2 = x * x;
58097
+ let t = 3.14159265358979 * x2;
58098
+ let u = 1.0 / (t * t);
58099
+ var fn = array<f32, 12>(
58100
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58101
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58102
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58103
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58104
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20,
58105
+ 0.0, 0.0
58106
+ );
58107
+ var fd = array<f32, 12>(
58108
+ 1.0, 7.51586398353378947175e-1,
58109
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58110
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58111
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58112
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58113
+ 1.25443237090011264384e-20, 0.0
58114
+ );
58115
+ var gn = array<f32, 12>(
58116
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58117
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58118
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58119
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58120
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58121
+ 1.86958710162783235106e-22, 0.0
58122
+ );
58123
+ var gd = array<f32, 12>(
58124
+ 1.0, 1.47495759925128324529,
58125
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58126
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58127
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58128
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58129
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58130
+ );
58131
+ let f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58132
+ let g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58133
+ let z = 1.5707963267948966 * x2;
58134
+ let c = cos(z);
58135
+ let s = sin(z);
58136
+ return sgn * (0.5 + (f * s - g * c) / (3.14159265358979 * x));
58137
+ }
58138
+
58139
+ return sgn * 0.5;
58140
+ }
58141
+ `;
58142
+ var GPU_FRESNELS_PREAMBLE_GLSL = `
58143
+ float _gpu_fresnelS(float x_in) {
58144
+ float sgn = x_in < 0.0 ? -1.0 : 1.0;
58145
+ float x = abs(x_in);
58146
+
58147
+ if (x < 1.6) {
58148
+ float x2 = x * x;
58149
+ float t = x2 * x2;
58150
+ float sn[6] = float[6](
58151
+ -2.99181919401019853726e3, 7.08840045257738576863e5,
58152
+ -6.29741486205862506537e7, 2.54890880573376359104e9,
58153
+ -4.42979518059697779103e10, 3.18016297876567817986e11
58154
+ );
58155
+ float sd[7] = float[7](
58156
+ 1.0, 2.81376268889994315696e2, 4.55847810806532581675e4,
58157
+ 5.1734388877009640073e6, 4.19320245898111231129e8, 2.2441179564534092094e10,
58158
+ 6.07366389490084914091e11
58159
+ );
58160
+ return sgn * x * x2 * _gpu_polevl(t, sn, 6) / _gpu_polevl(t, sd, 7);
58161
+ }
58162
+
58163
+ if (x < 36.0) {
58164
+ float x2 = x * x;
58165
+ float t = 3.14159265358979 * x2;
58166
+ float u = 1.0 / (t * t);
58167
+ float fn[10] = float[10](
58168
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58169
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58170
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58171
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58172
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20
58173
+ );
58174
+ float fd[11] = float[11](
58175
+ 1.0, 7.51586398353378947175e-1,
58176
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58177
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58178
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58179
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58180
+ 1.25443237090011264384e-20
58181
+ );
58182
+ float gn[11] = float[11](
58183
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58184
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58185
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58186
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58187
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58188
+ 1.86958710162783235106e-22
58189
+ );
58190
+ float gd[12] = float[12](
58191
+ 1.0, 1.47495759925128324529,
58192
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58193
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58194
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58195
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58196
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58197
+ );
58198
+ float f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58199
+ float g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58200
+ float z = 1.5707963267948966 * x2;
58201
+ float c = cos(z);
58202
+ float s = sin(z);
58203
+ return sgn * (0.5 - (f * c + g * s) / (3.14159265358979 * x));
58204
+ }
58205
+
58206
+ return sgn * 0.5;
58207
+ }
58208
+ `;
58209
+ var GPU_FRESNELS_PREAMBLE_WGSL = `
58210
+ fn _gpu_fresnelS(x_in: f32) -> f32 {
58211
+ let sgn: f32 = select(1.0, -1.0, x_in < 0.0);
58212
+ let x = abs(x_in);
58213
+
58214
+ if (x < 1.6) {
58215
+ let x2 = x * x;
58216
+ let t = x2 * x2;
58217
+ var sn = array<f32, 12>(
58218
+ -2.99181919401019853726e3, 7.08840045257738576863e5,
58219
+ -6.29741486205862506537e7, 2.54890880573376359104e9,
58220
+ -4.42979518059697779103e10, 3.18016297876567817986e11,
58221
+ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
58222
+ );
58223
+ var sd = array<f32, 12>(
58224
+ 1.0, 2.81376268889994315696e2, 4.55847810806532581675e4,
58225
+ 5.1734388877009640073e6, 4.19320245898111231129e8, 2.2441179564534092094e10,
58226
+ 6.07366389490084914091e11,
58227
+ 0.0, 0.0, 0.0, 0.0, 0.0
58228
+ );
58229
+ return sgn * x * x2 * _gpu_polevl(t, sn, 6) / _gpu_polevl(t, sd, 7);
58230
+ }
58231
+
58232
+ if (x < 36.0) {
58233
+ let x2 = x * x;
58234
+ let t = 3.14159265358979 * x2;
58235
+ let u = 1.0 / (t * t);
58236
+ var fn = array<f32, 12>(
58237
+ 4.21543555043677546506e-1, 1.43407919780758885261e-1,
58238
+ 1.15220955073585758835e-2, 3.450179397825740279e-4,
58239
+ 4.63613749287867322088e-6, 3.05568983790257605827e-8,
58240
+ 1.02304514164907233465e-10, 1.72010743268161828879e-13,
58241
+ 1.34283276233062758925e-16, 3.76329711269987889006e-20,
58242
+ 0.0, 0.0
58243
+ );
58244
+ var fd = array<f32, 12>(
58245
+ 1.0, 7.51586398353378947175e-1,
58246
+ 1.16888925859191382142e-1, 6.44051526508858611005e-3,
58247
+ 1.55934409164153020873e-4, 1.8462756734893054587e-6,
58248
+ 1.12699224763999035261e-8, 3.60140029589371370404e-11,
58249
+ 5.8875453362157841001e-14, 4.52001434074129701496e-17,
58250
+ 1.25443237090011264384e-20, 0.0
58251
+ );
58252
+ var gn = array<f32, 12>(
58253
+ 5.04442073643383265887e-1, 1.97102833525523411709e-1,
58254
+ 1.87648584092575249293e-2, 6.84079380915393090172e-4,
58255
+ 1.15138826111884280931e-5, 9.82852443688422223854e-8,
58256
+ 4.45344415861750144738e-10, 1.08268041139020870318e-12,
58257
+ 1.37555460633261799868e-15, 8.36354435630677421531e-19,
58258
+ 1.86958710162783235106e-22, 0.0
58259
+ );
58260
+ var gd = array<f32, 12>(
58261
+ 1.0, 1.47495759925128324529,
58262
+ 3.37748989120019970451e-1, 2.53603741420338795122e-2,
58263
+ 8.14679107184306179049e-4, 1.27545075667729118702e-5,
58264
+ 1.04314589657571990585e-7, 4.60680728515232032307e-10,
58265
+ 1.10273215066240270757e-12, 1.38796531259578871258e-15,
58266
+ 8.39158816283118707363e-19, 1.86958710162783236342e-22
58267
+ );
58268
+ let f = 1.0 - u * _gpu_polevl(u, fn, 10) / _gpu_polevl(u, fd, 11);
58269
+ let g = (1.0 / t) * _gpu_polevl(u, gn, 11) / _gpu_polevl(u, gd, 12);
58270
+ let z = 1.5707963267948966 * x2;
58271
+ let c = cos(z);
58272
+ let s = sin(z);
58273
+ return sgn * (0.5 - (f * c + g * s) / (3.14159265358979 * x));
58274
+ }
58275
+
58276
+ return sgn * 0.5;
58277
+ }
58278
+ `;
58279
+ var GPU_BESSELJ_PREAMBLE_GLSL = `
58280
+ float _gpu_factorial(int n) {
58281
+ float f = 1.0;
58282
+ for (int i = 2; i <= n; i++) f *= float(i);
58283
+ return f;
58284
+ }
58285
+
58286
+ float _gpu_besselJ_series(int n, float x) {
58287
+ float halfX = x / 2.0;
58288
+ float negQ = -(x * x) / 4.0;
58289
+ float term = 1.0;
58290
+ for (int i = 1; i <= n; i++) term /= float(i);
58291
+ float s = term;
58292
+ for (int k = 1; k <= 60; k++) {
58293
+ term *= negQ / (float(k) * float(n + k));
58294
+ s += term;
58295
+ if (abs(term) < abs(s) * 1e-7) break;
58296
+ }
58297
+ return s * pow(halfX, float(n));
58298
+ }
58299
+
58300
+ float _gpu_besselJ_asymptotic(int n, float x) {
58301
+ float mu = 4.0 * float(n) * float(n);
58302
+ float P = 1.0;
58303
+ float Q = 0.0;
58304
+ float ak = 1.0;
58305
+ float e8x = 8.0 * x;
58306
+ for (int k = 1; k <= 12; k++) {
58307
+ float twokm1 = float(2 * k - 1);
58308
+ ak *= mu - twokm1 * twokm1;
58309
+ float denom = _gpu_factorial(k) * pow(e8x, float(k));
58310
+ float contrib = ak / denom;
58311
+ if (k == 1 || k == 3 || k == 5 || k == 7 || k == 9 || k == 11) {
58312
+ // odd k: contributes to Q
58313
+ if (((k - 1) / 2) % 2 == 0) Q += contrib;
58314
+ else Q -= contrib;
58315
+ } else {
58316
+ // even k: contributes to P
58317
+ if ((k / 2) % 2 == 1) P -= contrib;
58318
+ else P += contrib;
58319
+ }
58320
+ if (abs(contrib) < 1e-7) break;
58321
+ }
58322
+ float chi = x - (float(n) / 2.0 + 0.25) * 3.14159265358979;
58323
+ return sqrt(2.0 / (3.14159265358979 * x)) * (P * cos(chi) - Q * sin(chi));
58324
+ }
58325
+
58326
+ float _gpu_besselJ(int n, float x) {
58327
+ if (x == 0.0) return n == 0 ? 1.0 : 0.0;
58328
+ float sgn = 1.0;
58329
+ if (n < 0) {
58330
+ n = -n;
58331
+ if (n % 2 != 0) sgn = -1.0;
58332
+ }
58333
+ if (x < 0.0) {
58334
+ x = -x;
58335
+ if (n % 2 != 0) sgn *= -1.0;
58336
+ }
58337
+ if (x > 25.0 + float(n * n) / 2.0) return sgn * _gpu_besselJ_asymptotic(n, x);
58338
+ if (x < 5.0 + float(n)) return sgn * _gpu_besselJ_series(n, x);
58339
+ // Miller's backward recurrence
58340
+ int M = max(n + 20, int(ceil(x)) + 30);
58341
+ if (M > 200) return sgn * _gpu_besselJ_series(n, x);
58342
+ float vals[201];
58343
+ float jp1 = 0.0;
58344
+ float jk = 1.0;
58345
+ vals[M] = jk;
58346
+ for (int k = M; k >= 1; k--) {
58347
+ float jm1 = (2.0 * float(k) / x) * jk - jp1;
58348
+ jp1 = jk;
58349
+ jk = jm1;
58350
+ vals[k - 1] = jk;
58351
+ }
58352
+ float norm = vals[0];
58353
+ for (int k = 2; k <= M; k += 2) norm += 2.0 * vals[k];
58354
+ return sgn * vals[n] / norm;
58355
+ }
58356
+ `;
58357
+ var GPU_BESSELJ_PREAMBLE_WGSL = `
58358
+ fn _gpu_factorial(n: i32) -> f32 {
58359
+ var f: f32 = 1.0;
58360
+ for (var i: i32 = 2; i <= n; i++) { f *= f32(i); }
58361
+ return f;
58362
+ }
58363
+
58364
+ fn _gpu_besselJ_series(n_in: i32, x: f32) -> f32 {
58365
+ let halfX = x / 2.0;
58366
+ let negQ = -(x * x) / 4.0;
58367
+ var term: f32 = 1.0;
58368
+ for (var i: i32 = 1; i <= n_in; i++) { term /= f32(i); }
58369
+ var s = term;
58370
+ for (var k: i32 = 1; k <= 60; k++) {
58371
+ term *= negQ / (f32(k) * f32(n_in + k));
58372
+ s += term;
58373
+ if (abs(term) < abs(s) * 1e-7) { break; }
58374
+ }
58375
+ return s * pow(halfX, f32(n_in));
58376
+ }
58377
+
58378
+ fn _gpu_besselJ_asymptotic(n_in: i32, x: f32) -> f32 {
58379
+ let mu = 4.0 * f32(n_in) * f32(n_in);
58380
+ var P: f32 = 1.0;
58381
+ var Q: f32 = 0.0;
58382
+ var ak: f32 = 1.0;
58383
+ let e8x = 8.0 * x;
58384
+ for (var k: i32 = 1; k <= 12; k++) {
58385
+ let twokm1 = f32(2 * k - 1);
58386
+ ak *= mu - twokm1 * twokm1;
58387
+ let denom = _gpu_factorial(k) * pow(e8x, f32(k));
58388
+ let contrib = ak / denom;
58389
+ if (k == 1 || k == 3 || k == 5 || k == 7 || k == 9 || k == 11) {
58390
+ if (((k - 1) / 2) % 2 == 0) { Q += contrib; }
58391
+ else { Q -= contrib; }
58392
+ } else {
58393
+ if ((k / 2) % 2 == 1) { P -= contrib; }
58394
+ else { P += contrib; }
58395
+ }
58396
+ if (abs(contrib) < 1e-7) { break; }
58397
+ }
58398
+ let chi = x - (f32(n_in) / 2.0 + 0.25) * 3.14159265358979;
58399
+ return sqrt(2.0 / (3.14159265358979 * x)) * (P * cos(chi) - Q * sin(chi));
58400
+ }
58401
+
58402
+ fn _gpu_besselJ(n_in: i32, x_in: f32) -> f32 {
58403
+ var n = n_in;
58404
+ var x = x_in;
58405
+ if (x == 0.0) { return select(0.0, 1.0, n == 0); }
58406
+ var sgn: f32 = 1.0;
58407
+ if (n < 0) {
58408
+ n = -n;
58409
+ if (n % 2 != 0) { sgn = -1.0; }
58410
+ }
58411
+ if (x < 0.0) {
58412
+ x = -x;
58413
+ if (n % 2 != 0) { sgn *= -1.0; }
58414
+ }
58415
+ if (x > 25.0 + f32(n * n) / 2.0) { return sgn * _gpu_besselJ_asymptotic(n, x); }
58416
+ if (x < 5.0 + f32(n)) { return sgn * _gpu_besselJ_series(n, x); }
58417
+ // Miller's backward recurrence
58418
+ var M = max(n + 20, i32(ceil(x)) + 30);
58419
+ if (M > 200) { return sgn * _gpu_besselJ_series(n, x); }
58420
+ var vals: array<f32, 201>;
58421
+ var jp1: f32 = 0.0;
58422
+ var jk: f32 = 1.0;
58423
+ vals[M] = jk;
58424
+ for (var k: i32 = M; k >= 1; k--) {
58425
+ let jm1 = (2.0 * f32(k) / x) * jk - jp1;
58426
+ jp1 = jk;
58427
+ jk = jm1;
58428
+ vals[k - 1] = jk;
58429
+ }
58430
+ var norm = vals[0];
58431
+ for (var k2: i32 = 2; k2 <= M; k2 += 2) { norm += 2.0 * vals[k2]; }
58432
+ return sgn * vals[n] / norm;
58433
+ }
58434
+ `;
57809
58435
  var GPU_FRACTAL_PREAMBLE_GLSL = `
57810
58436
  float _fractal_mandelbrot(vec2 c, int maxIter) {
57811
58437
  vec2 z = vec2(0.0, 0.0);
@@ -58268,6 +58894,16 @@ var GPUShaderTarget = class {
58268
58894
  indent: 0,
58269
58895
  ws: (s) => s ?? "",
58270
58896
  preamble: "",
58897
+ declare: (name, typeHint) => {
58898
+ const type2 = typeHint ?? (this.languageId === "wgsl" ? "f32" : "float");
58899
+ return this.languageId === "wgsl" ? `var ${name}: ${type2}` : `${type2} ${name}`;
58900
+ },
58901
+ block: (stmts) => {
58902
+ if (stmts.length === 0) return "";
58903
+ const last = stmts.length - 1;
58904
+ stmts[last] = `return ${stmts[last]}`;
58905
+ return stmts.join(";\n");
58906
+ },
58271
58907
  ...options
58272
58908
  };
58273
58909
  }
@@ -58302,6 +58938,18 @@ var GPUShaderTarget = class {
58302
58938
  preamble += buildComplexPreamble(code, this.languageId);
58303
58939
  if (code.includes("_gpu_gamma")) preamble += GPU_GAMMA_PREAMBLE;
58304
58940
  if (code.includes("_gpu_erf")) preamble += GPU_ERF_PREAMBLE;
58941
+ if (code.includes("_gpu_heaviside"))
58942
+ preamble += this.languageId === "wgsl" ? GPU_HEAVISIDE_PREAMBLE_WGSL : GPU_HEAVISIDE_PREAMBLE_GLSL;
58943
+ if (code.includes("_gpu_sinc"))
58944
+ preamble += this.languageId === "wgsl" ? GPU_SINC_PREAMBLE_WGSL : GPU_SINC_PREAMBLE_GLSL;
58945
+ if (code.includes("_gpu_fresnel"))
58946
+ preamble += this.languageId === "wgsl" ? GPU_POLEVL_PREAMBLE_WGSL : GPU_POLEVL_PREAMBLE_GLSL;
58947
+ if (code.includes("_gpu_fresnelC"))
58948
+ preamble += this.languageId === "wgsl" ? GPU_FRESNELC_PREAMBLE_WGSL : GPU_FRESNELC_PREAMBLE_GLSL;
58949
+ if (code.includes("_gpu_fresnelS"))
58950
+ preamble += this.languageId === "wgsl" ? GPU_FRESNELS_PREAMBLE_WGSL : GPU_FRESNELS_PREAMBLE_GLSL;
58951
+ if (code.includes("_gpu_besselJ"))
58952
+ preamble += this.languageId === "wgsl" ? GPU_BESSELJ_PREAMBLE_WGSL : GPU_BESSELJ_PREAMBLE_GLSL;
58305
58953
  if (code.includes("_fractal_")) {
58306
58954
  preamble += this.languageId === "wgsl" ? GPU_FRACTAL_PREAMBLE_WGSL : GPU_FRACTAL_PREAMBLE_GLSL;
58307
58955
  }
@@ -58350,6 +58998,12 @@ var GLSLTarget = class extends GPUShaderTarget {
58350
58998
  const target = this.createTarget();
58351
58999
  const body = BaseCompiler.compile(expr, target);
58352
59000
  const params = parameters.map(([name, type2]) => `${type2} ${name}`).join(", ");
59001
+ if (body.includes("\n")) {
59002
+ const indented = body.split("\n").map((l) => ` ${l}`).join("\n");
59003
+ return `${returnType} ${functionName}(${params}) {
59004
+ ${indented};
59005
+ }`;
59006
+ }
58353
59007
  return `${returnType} ${functionName}(${params}) {
58354
59008
  return ${body};
58355
59009
  }`;
@@ -58453,6 +59107,12 @@ var WGSLTarget = class extends GPUShaderTarget {
58453
59107
  const target = this.createTarget();
58454
59108
  const body = BaseCompiler.compile(expr, target);
58455
59109
  const params = parameters.map(([name, type2]) => `${name}: ${toWGSLType(type2)}`).join(", ");
59110
+ if (body.includes("\n")) {
59111
+ const indented = body.split("\n").map((l) => ` ${l}`).join("\n");
59112
+ return `fn ${functionName}(${params}) -> ${toWGSLType(returnType)} {
59113
+ ${indented};
59114
+ }`;
59115
+ }
58456
59116
  return `fn ${functionName}(${params}) -> ${toWGSLType(returnType)} {
58457
59117
  return ${body};
58458
59118
  }`;
@@ -67320,10 +67980,10 @@ var ComputeEngine = class _ComputeEngine {
67320
67980
  _setComputeEngineClass(ComputeEngine);
67321
67981
 
67322
67982
  // src/compute-engine.ts
67323
- var version = "0.53.0";
67983
+ var version = "0.53.1";
67324
67984
  globalThis[/* @__PURE__ */ Symbol.for("io.cortexjs.compute-engine")] = {
67325
67985
  ComputeEngine: ComputeEngine.prototype.constructor,
67326
- version: "0.53.0"
67986
+ version: "0.53.1"
67327
67987
  };
67328
67988
  export {
67329
67989
  BaseCompiler,