@cortex-js/compute-engine 0.60.0 → 0.61.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.
- package/dist/compile.esm.js +1270 -25
- package/dist/compile.min.esm.js +324 -78
- package/dist/compile.min.umd.cjs +324 -78
- package/dist/compile.umd.cjs +1270 -25
- package/dist/compute-engine.esm.js +867 -26
- package/dist/compute-engine.min.esm.js +329 -83
- package/dist/compute-engine.min.umd.cjs +329 -83
- package/dist/compute-engine.umd.cjs +867 -26
- package/dist/core.esm.js +855 -24
- package/dist/core.min.esm.js +330 -84
- package/dist/core.min.umd.cjs +330 -84
- package/dist/core.umd.cjs +855 -24
- package/dist/identities.esm.js +2 -2
- package/dist/identities.min.esm.js +2 -2
- package/dist/identities.min.umd.cjs +2 -2
- package/dist/identities.umd.cjs +2 -2
- package/dist/integration-rules.esm.js +2 -2
- package/dist/integration-rules.min.esm.js +2 -2
- package/dist/integration-rules.min.umd.cjs +2 -2
- package/dist/integration-rules.umd.cjs +2 -2
- package/dist/interval.esm.js +2 -2
- package/dist/interval.min.esm.js +2 -2
- package/dist/interval.min.umd.cjs +2 -2
- package/dist/interval.umd.cjs +2 -2
- package/dist/latex-syntax.esm.js +2 -2
- package/dist/latex-syntax.min.esm.js +2 -2
- package/dist/latex-syntax.min.umd.cjs +2 -2
- package/dist/latex-syntax.umd.cjs +2 -2
- package/dist/math-json.esm.js +2 -2
- package/dist/math-json.min.esm.js +2 -2
- package/dist/math-json.min.umd.cjs +2 -2
- package/dist/math-json.umd.cjs +2 -2
- package/dist/numerics.esm.js +2 -2
- package/dist/numerics.min.esm.js +2 -2
- package/dist/numerics.min.umd.cjs +2 -2
- package/dist/numerics.umd.cjs +2 -2
- package/dist/types/big-decimal/big-decimal.d.ts +1 -1
- package/dist/types/big-decimal/index.d.ts +1 -1
- package/dist/types/big-decimal/transcendentals.d.ts +1 -1
- package/dist/types/big-decimal/utils.d.ts +1 -1
- package/dist/types/common/ansi-codes.d.ts +1 -1
- package/dist/types/common/configuration-change.d.ts +1 -1
- package/dist/types/common/fuzzy-string-match.d.ts +1 -1
- package/dist/types/common/grapheme-splitter.d.ts +1 -1
- package/dist/types/common/interruptible.d.ts +1 -1
- package/dist/types/common/one-of.d.ts +1 -1
- package/dist/types/common/signals.d.ts +1 -1
- package/dist/types/common/type/ast-nodes.d.ts +1 -1
- package/dist/types/common/type/boxed-type.d.ts +1 -1
- package/dist/types/common/type/lexer.d.ts +1 -1
- package/dist/types/common/type/parse.d.ts +1 -1
- package/dist/types/common/type/parser.d.ts +1 -1
- package/dist/types/common/type/primitive.d.ts +1 -1
- package/dist/types/common/type/reduce.d.ts +1 -1
- package/dist/types/common/type/serialize.d.ts +1 -1
- package/dist/types/common/type/subtype.d.ts +1 -1
- package/dist/types/common/type/type-builder.d.ts +1 -1
- package/dist/types/common/type/types.d.ts +1 -1
- package/dist/types/common/type/utils.d.ts +1 -1
- package/dist/types/common/utils.d.ts +1 -1
- package/dist/types/compile.d.ts +2 -1
- package/dist/types/compute-engine/assume.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/abstract-boxed-expression.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/apply.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-add.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-mul-div.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/arithmetic-power.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/ascii-math.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/box.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-function.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-number.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-operator-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-patterns.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-string.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-symbol.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-tensor.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/boxed-value-definition.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/cache.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/canonical.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/compare.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/constants.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/constraint-subject.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/exp-to-trig.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expand.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/expression-map.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/factor.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/flatten.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/hold.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/inequality-bounds.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/init-lazy-refs.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/invisible-operator.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/match.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/multivariate-gcd.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/multivariate-poly.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/negate.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/numerics.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/order.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/pattern-utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomial-degree.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/predicates.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rule-index.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/rules.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/serialize.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/sgn.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/simplify.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve-linear-system.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/solve.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/stochastic-equal.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/type-guards.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/utils.d.ts +1 -1
- package/dist/types/compute-engine/boxed-expression/validate.d.ts +1 -1
- package/dist/types/compute-engine/collection-utils.d.ts +1 -1
- package/dist/types/compute-engine/compilation/base-compiler.d.ts +79 -1
- package/dist/types/compute-engine/compilation/compile-expression.d.ts +1 -1
- package/dist/types/compute-engine/compilation/constant-folding.d.ts +1 -1
- package/dist/types/compute-engine/compilation/glsl-target.d.ts +2 -2
- package/dist/types/compute-engine/compilation/gpu-target.d.ts +7 -1
- package/dist/types/compute-engine/compilation/interval-glsl-target.d.ts +49 -0
- package/dist/types/compute-engine/compilation/interval-javascript-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/javascript-target.d.ts +30 -2
- package/dist/types/compute-engine/compilation/python-target.d.ts +1 -1
- package/dist/types/compute-engine/compilation/types.d.ts +54 -2
- package/dist/types/compute-engine/compilation/wgsl-target.d.ts +1 -1
- package/dist/types/compute-engine/cost-function.d.ts +1 -1
- package/dist/types/compute-engine/engine-assumptions.d.ts +1 -1
- package/dist/types/compute-engine/engine-cache.d.ts +1 -1
- package/dist/types/compute-engine/engine-common-symbols.d.ts +1 -1
- package/dist/types/compute-engine/engine-compilation-targets.d.ts +1 -1
- package/dist/types/compute-engine/engine-configuration-lifecycle.d.ts +1 -1
- package/dist/types/compute-engine/engine-declarations.d.ts +1 -1
- package/dist/types/compute-engine/engine-expression-entrypoints.d.ts +1 -1
- package/dist/types/compute-engine/engine-extension-contracts.d.ts +1 -1
- package/dist/types/compute-engine/engine-library-bootstrap.d.ts +1 -1
- package/dist/types/compute-engine/engine-numeric-configuration.d.ts +1 -1
- package/dist/types/compute-engine/engine-runtime-state.d.ts +1 -1
- package/dist/types/compute-engine/engine-scope.d.ts +1 -1
- package/dist/types/compute-engine/engine-sequences.d.ts +1 -1
- package/dist/types/compute-engine/engine-simplification-rules.d.ts +1 -1
- package/dist/types/compute-engine/engine-startup-coordinator.d.ts +1 -1
- package/dist/types/compute-engine/engine-type-resolver.d.ts +1 -1
- package/dist/types/compute-engine/engine-validation-entrypoints.d.ts +1 -1
- package/dist/types/compute-engine/free-functions.d.ts +1 -1
- package/dist/types/compute-engine/function-properties/index.d.ts +1 -1
- package/dist/types/compute-engine/function-utils.d.ts +1 -1
- package/dist/types/compute-engine/fungrim/loader.d.ts +1 -1
- package/dist/types/compute-engine/fungrim/types.d.ts +1 -1
- package/dist/types/compute-engine/global-types.d.ts +1 -1
- package/dist/types/compute-engine/index.d.ts +10 -1
- package/dist/types/compute-engine/interval/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/interval/comparison.d.ts +1 -1
- package/dist/types/compute-engine/interval/elementary.d.ts +1 -1
- package/dist/types/compute-engine/interval/index.d.ts +1 -1
- package/dist/types/compute-engine/interval/trigonometric.d.ts +1 -1
- package/dist/types/compute-engine/interval/types.d.ts +1 -1
- package/dist/types/compute-engine/interval/util.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/default-dictionary.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-calculus.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-colors.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-complex.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-core.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-logic.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-other.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-relational-operators.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-sets.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-statistics.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-symbols.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions-units.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/definitions.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/dictionary/indexed-types.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/latex-syntax.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse-symbol.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/parse.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-dms.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serialize-number.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer-style.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/serializer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/tokenizer.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/types.d.ts +1 -1
- package/dist/types/compute-engine/latex-syntax/utils.d.ts +1 -1
- package/dist/types/compute-engine/library/arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/calculus.d.ts +1 -1
- package/dist/types/compute-engine/library/collections.d.ts +1 -1
- package/dist/types/compute-engine/library/colors.d.ts +1 -1
- package/dist/types/compute-engine/library/combinatorics.d.ts +1 -1
- package/dist/types/compute-engine/library/complex.d.ts +1 -1
- package/dist/types/compute-engine/library/control-structures.d.ts +1 -1
- package/dist/types/compute-engine/library/core.d.ts +1 -1
- package/dist/types/compute-engine/library/fractals.d.ts +1 -1
- package/dist/types/compute-engine/library/library.d.ts +1 -1
- package/dist/types/compute-engine/library/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/library/logic-analysis.d.ts +1 -1
- package/dist/types/compute-engine/library/logic.d.ts +1 -1
- package/dist/types/compute-engine/library/number-theory.d.ts +1 -1
- package/dist/types/compute-engine/library/polynomials.d.ts +1 -1
- package/dist/types/compute-engine/library/quantity-arithmetic.d.ts +1 -1
- package/dist/types/compute-engine/library/random-expression.d.ts +1 -1
- package/dist/types/compute-engine/library/relational-operator.d.ts +1 -1
- package/dist/types/compute-engine/library/sets.d.ts +1 -1
- package/dist/types/compute-engine/library/special-functions.d.ts +1 -1
- package/dist/types/compute-engine/library/statistics.d.ts +1 -1
- package/dist/types/compute-engine/library/trigonometry.d.ts +1 -1
- package/dist/types/compute-engine/library/type-handlers.d.ts +1 -1
- package/dist/types/compute-engine/library/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/library/units.d.ts +1 -1
- package/dist/types/compute-engine/library/utils.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/big-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/exact-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/machine-numeric-value.d.ts +1 -1
- package/dist/types/compute-engine/numeric-value/types.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bernoulli.d.ts +1 -1
- package/dist/types/compute-engine/numerics/bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/complex-esm-augment.d.ts +1 -1
- package/dist/types/compute-engine/numerics/expression.d.ts +1 -1
- package/dist/types/compute-engine/numerics/interval.d.ts +1 -1
- package/dist/types/compute-engine/numerics/linear-algebra.d.ts +1 -1
- package/dist/types/compute-engine/numerics/monte-carlo.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bigint.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-bignum.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric-complex.d.ts +1 -1
- package/dist/types/compute-engine/numerics/numeric.d.ts +1 -1
- package/dist/types/compute-engine/numerics/oscillatory-quadrature.d.ts +1 -1
- package/dist/types/compute-engine/numerics/polynomial-roots.d.ts +1 -1
- package/dist/types/compute-engine/numerics/primes.d.ts +1 -1
- package/dist/types/compute-engine/numerics/random.d.ts +1 -1
- package/dist/types/compute-engine/numerics/rationals.d.ts +1 -1
- package/dist/types/compute-engine/numerics/richardson.d.ts +1 -1
- package/dist/types/compute-engine/numerics/special-functions.d.ts +1 -1
- package/dist/types/compute-engine/numerics/statistics.d.ts +1 -1
- package/dist/types/compute-engine/numerics/strings.d.ts +1 -1
- package/dist/types/compute-engine/numerics/types.d.ts +1 -1
- package/dist/types/compute-engine/numerics/unit-data.d.ts +1 -1
- package/dist/types/compute-engine/oeis.d.ts +1 -1
- package/dist/types/compute-engine/rubi/compile.d.ts +1 -1
- package/dist/types/compute-engine/rubi/driver.d.ts +1 -1
- package/dist/types/compute-engine/rubi/loader.d.ts +1 -1
- package/dist/types/compute-engine/rubi/match.d.ts +1 -1
- package/dist/types/compute-engine/rubi/normal-form.d.ts +1 -1
- package/dist/types/compute-engine/rubi/rubi-utils.d.ts +1 -1
- package/dist/types/compute-engine/rubi/types.d.ts +1 -1
- package/dist/types/compute-engine/sequence.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/antiderivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/derivative.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/distribute.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-cost.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu-transforms.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/fu.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/limit.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/logic-utils.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/residue.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-abs.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-divide.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-factorial.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-hyperbolic.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-infinity.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-log.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-logic.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-power.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-product.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-rules.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-sum.d.ts +1 -1
- package/dist/types/compute-engine/symbolic/simplify-trig.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensor-fields.d.ts +1 -1
- package/dist/types/compute-engine/tensor/tensors.d.ts +1 -1
- package/dist/types/compute-engine/types-definitions.d.ts +1 -1
- package/dist/types/compute-engine/types-engine.d.ts +11 -1
- package/dist/types/compute-engine/types-evaluation.d.ts +1 -1
- package/dist/types/compute-engine/types-expression.d.ts +1 -1
- package/dist/types/compute-engine/types-kernel-evaluation.d.ts +1 -1
- package/dist/types/compute-engine/types-kernel-serialization.d.ts +1 -1
- package/dist/types/compute-engine/types-serialization.d.ts +1 -1
- package/dist/types/compute-engine/types.d.ts +1 -1
- package/dist/types/compute-engine.d.ts +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/identities.d.ts +1 -1
- package/dist/types/integration-rules.d.ts +1 -1
- package/dist/types/interval.d.ts +1 -1
- package/dist/types/latex-syntax.d.ts +2 -2
- package/dist/types/math-json/symbols.d.ts +1 -1
- package/dist/types/math-json/types.d.ts +1 -1
- package/dist/types/math-json/utils.d.ts +1 -1
- package/dist/types/math-json.d.ts +2 -2
- package/dist/types/numerics.d.ts +1 -1
- package/package.json +1 -1
package/dist/core.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ComputeEngineCore 0.
|
|
1
|
+
/** ComputeEngineCore 0.61.0 */
|
|
2
2
|
(function(global,factory){typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'],factory):(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ComputeEngineCore = {}));})(this, (function (exports) { 'use strict';
|
|
3
3
|
"use strict";
|
|
4
4
|
var ComputeEngineCore = (() => {
|
|
@@ -7470,10 +7470,18 @@ var ComputeEngineCore = (() => {
|
|
|
7470
7470
|
}
|
|
7471
7471
|
function canonicalFunctionLiteralArguments(ce, ops) {
|
|
7472
7472
|
if (ops.length === 0) return void 0;
|
|
7473
|
-
const block = ops[0].operator === "Block" ? ops[0].canonical : ce.function("Block", [ops[0]]);
|
|
7474
7473
|
const params = ops.slice(1).map(
|
|
7475
7474
|
(x) => isSymbol2(x) ? x : ce.error("expected-a-symbol", x.toString())
|
|
7476
7475
|
);
|
|
7476
|
+
ce._pushShadowedParameters(
|
|
7477
|
+
params.filter((p) => isSymbol2(p)).map((p) => p.symbol)
|
|
7478
|
+
);
|
|
7479
|
+
let block;
|
|
7480
|
+
try {
|
|
7481
|
+
block = ops[0].operator === "Block" ? ops[0].canonical : ce.function("Block", [ops[0]]);
|
|
7482
|
+
} finally {
|
|
7483
|
+
ce._popShadowedParameters();
|
|
7484
|
+
}
|
|
7477
7485
|
console.assert(block.isScoped);
|
|
7478
7486
|
for (const param of params) {
|
|
7479
7487
|
if (isSymbol2(param) && !block.localScope.bindings.has(param.symbol)) {
|
|
@@ -66962,6 +66970,13 @@ Error in definition of "${name}"`,
|
|
|
66962
66970
|
|
|
66963
66971
|
// src/compute-engine/compilation/base-compiler.ts
|
|
66964
66972
|
var BaseCompiler = class _BaseCompiler {
|
|
66973
|
+
/**
|
|
66974
|
+
* Precedence used when compiling a folded symbol value. Higher than any
|
|
66975
|
+
* target's infix operator precedence, so a compound value parenthesizes
|
|
66976
|
+
* itself when spliced into a surrounding expression. See
|
|
66977
|
+
* `tryFoldKnownSymbol`.
|
|
66978
|
+
*/
|
|
66979
|
+
static FOLD_OPERAND_PREC = 1e3;
|
|
66965
66980
|
/**
|
|
66966
66981
|
* Compile an expression to target language source code
|
|
66967
66982
|
*/
|
|
@@ -66978,7 +66993,9 @@ Error in definition of "${name}"`,
|
|
|
66978
66993
|
if (op !== void 0) {
|
|
66979
66994
|
return `(a,b) => a ${op[0]} b`;
|
|
66980
66995
|
}
|
|
66981
|
-
|
|
66996
|
+
const resolved = target.var?.(s);
|
|
66997
|
+
if (resolved !== void 0) return resolved;
|
|
66998
|
+
return _BaseCompiler.tryFoldKnownSymbol(expr2.engine, s, target) ?? s;
|
|
66982
66999
|
}
|
|
66983
67000
|
if (isNumber(expr2)) {
|
|
66984
67001
|
if (expr2.im !== 0) {
|
|
@@ -67304,10 +67321,10 @@ Error in definition of "${name}"`,
|
|
|
67304
67321
|
)
|
|
67305
67322
|
);
|
|
67306
67323
|
const needsWrap2 = target.number(0) !== "0";
|
|
67307
|
-
const bodyTarget2 =
|
|
67324
|
+
const bodyTarget2 = {
|
|
67308
67325
|
...target,
|
|
67309
|
-
var: (id) => loopVarSet.has(id) ? target.number(0).replace("0", id) : target.var(id)
|
|
67310
|
-
}
|
|
67326
|
+
var: (id) => loopVarSet.has(id) ? needsWrap2 ? target.number(0).replace("0", id) : id : target.var(id)
|
|
67327
|
+
};
|
|
67311
67328
|
const bodyCode = _BaseCompiler.compile(body, bodyTarget2);
|
|
67312
67329
|
let inner = `result.push(${bodyCode});`;
|
|
67313
67330
|
for (let i = narrowedElements.length - 1; i >= 0; i--) {
|
|
@@ -67605,6 +67622,167 @@ Error in definition of "${name}"`,
|
|
|
67605
67622
|
if (isNumber(expr2)) return expr2.im === 0 && expr2.re >= 0;
|
|
67606
67623
|
return expr2.isNonNegative === true;
|
|
67607
67624
|
}
|
|
67625
|
+
/**
|
|
67626
|
+
* If `id` names a symbol that is *known* to the engine — it has an assigned
|
|
67627
|
+
* value (`ce.assign("a", 1.5)`) or is a declared constant — return the
|
|
67628
|
+
* compiled target code for that value, i.e. **fold** the value into the
|
|
67629
|
+
* generated code the way `evaluate()` does. Returns `undefined` for a
|
|
67630
|
+
* genuinely free symbol (no value), so the caller falls back to its
|
|
67631
|
+
* free-symbol plumbing (a `vars` mapping, a `_.id` argument lookup, or a
|
|
67632
|
+
* declarable identifier).
|
|
67633
|
+
*
|
|
67634
|
+
* This keeps the compiled output consistent with `expr.unknowns` and
|
|
67635
|
+
* `evaluate()`: a symbol they treat as known (folded / dropped) is also
|
|
67636
|
+
* folded by `compile()`, instead of being emitted as a bare, dangling
|
|
67637
|
+
* reference (an undeclared GLSL identifier, or a bare JS global that throws
|
|
67638
|
+
* `ReferenceError` at run time).
|
|
67639
|
+
*
|
|
67640
|
+
* Callers MUST resolve any `vars` mapping for `id` **before** calling this,
|
|
67641
|
+
* so an explicitly `vars`-mapped symbol is never folded — the GPU/JS live
|
|
67642
|
+
* path relies on a mapped symbol staying a per-frame uniform / argument.
|
|
67643
|
+
*
|
|
67644
|
+
* `target` is the in-flight target: nested symbols inside the value resolve
|
|
67645
|
+
* through the same `vars`/constant/fold rules as the top-level expression.
|
|
67646
|
+
*
|
|
67647
|
+
* The value is compiled at a high precedence so a compound (operator) value
|
|
67648
|
+
* self-parenthesizes: folding `b = c + 1` into `b * x` must yield
|
|
67649
|
+
* `(c + 1) * x`, not `c + 1 * x`, and must stay safe when a handler splices
|
|
67650
|
+
* the folded string into its own expression (e.g. `Power`'s `(code * code)`).
|
|
67651
|
+
* An atomic value (number, symbol, function call) ignores the precedence, so
|
|
67652
|
+
* no redundant parentheses are added in the common assigned-number case.
|
|
67653
|
+
*/
|
|
67654
|
+
static tryFoldKnownSymbol(engine, id, target) {
|
|
67655
|
+
const value = engine._getSymbolValue(id);
|
|
67656
|
+
if (value === void 0) return void 0;
|
|
67657
|
+
return _BaseCompiler.compile(value, target, _BaseCompiler.FOLD_OPERAND_PREC);
|
|
67658
|
+
}
|
|
67659
|
+
/**
|
|
67660
|
+
* Operator heads the compiler lowers directly in `compileExpr`, independent
|
|
67661
|
+
* of any target operator/function mapping (control-flow, binding, and
|
|
67662
|
+
* indexing-set forms). `analyzeReferences` never reports these as
|
|
67663
|
+
* "unsupported".
|
|
67664
|
+
*/
|
|
67665
|
+
static STRUCTURAL_HEADS = /* @__PURE__ */ new Set([
|
|
67666
|
+
"Sequence",
|
|
67667
|
+
"Sum",
|
|
67668
|
+
"Product",
|
|
67669
|
+
"Function",
|
|
67670
|
+
"Declare",
|
|
67671
|
+
"Assign",
|
|
67672
|
+
"Return",
|
|
67673
|
+
"Break",
|
|
67674
|
+
"Continue",
|
|
67675
|
+
"Loop",
|
|
67676
|
+
"If",
|
|
67677
|
+
"Which",
|
|
67678
|
+
"When",
|
|
67679
|
+
"Block",
|
|
67680
|
+
// Indexing-set wrappers consumed by Sum/Product/Loop — never compiled
|
|
67681
|
+
// standalone.
|
|
67682
|
+
"Limits",
|
|
67683
|
+
"Element"
|
|
67684
|
+
]);
|
|
67685
|
+
/**
|
|
67686
|
+
* Analyze — without compiling, and never throwing — which external references
|
|
67687
|
+
* the generated code for `expr` would have on `target`:
|
|
67688
|
+
*
|
|
67689
|
+
* - `freeSymbols`: identifiers the caller must supply at run time. These are
|
|
67690
|
+
* the free symbols *as codegen sees them*: symbols with no value in the
|
|
67691
|
+
* engine, after descending into the values of folded (assigned / constant)
|
|
67692
|
+
* symbols — so `a = b + 1` surfaces `b`, which `expr.unknowns` misses — and
|
|
67693
|
+
* after excluding bound variables (lambda parameters, indices of
|
|
67694
|
+
* `Sum`/`Product`/`Integrate`/`Loop`, `Block` locals). A `vars`-mapped
|
|
67695
|
+
* symbol is always included: the mapping makes it an external input even
|
|
67696
|
+
* when it also has an assigned value.
|
|
67697
|
+
*
|
|
67698
|
+
* - `unsupported`: operator heads with no operator/function mapping in the
|
|
67699
|
+
* target and not one of the structural forms above.
|
|
67700
|
+
*
|
|
67701
|
+
* Lets a caller validate that a compiled result is self-contained
|
|
67702
|
+
* (`freeSymbols` covered by its inputs, `unsupported` empty) declaratively,
|
|
67703
|
+
* instead of executing or GPU-compiling the code to discover a dangling
|
|
67704
|
+
* reference or an unlowerable operator.
|
|
67705
|
+
*/
|
|
67706
|
+
static analyzeReferences(expr2, target, varsKeys) {
|
|
67707
|
+
const engine = expr2.engine;
|
|
67708
|
+
const free = /* @__PURE__ */ new Set();
|
|
67709
|
+
const unsupported = /* @__PURE__ */ new Set();
|
|
67710
|
+
const foldedSeen = /* @__PURE__ */ new Set();
|
|
67711
|
+
const union2 = (a, more) => {
|
|
67712
|
+
const s = new Set(a);
|
|
67713
|
+
for (const m of more) s.add(m);
|
|
67714
|
+
return s;
|
|
67715
|
+
};
|
|
67716
|
+
const visit = (e, bound) => {
|
|
67717
|
+
if (isSymbol2(e)) {
|
|
67718
|
+
const s = e.symbol;
|
|
67719
|
+
if (bound.has(s)) return;
|
|
67720
|
+
if (target.operators?.(s) !== void 0) return;
|
|
67721
|
+
if (varsKeys?.has(s)) {
|
|
67722
|
+
free.add(s);
|
|
67723
|
+
return;
|
|
67724
|
+
}
|
|
67725
|
+
const value = engine._getSymbolValue(s);
|
|
67726
|
+
if (value !== void 0) {
|
|
67727
|
+
if (!foldedSeen.has(s)) {
|
|
67728
|
+
foldedSeen.add(s);
|
|
67729
|
+
visit(value, bound);
|
|
67730
|
+
}
|
|
67731
|
+
return;
|
|
67732
|
+
}
|
|
67733
|
+
free.add(s);
|
|
67734
|
+
return;
|
|
67735
|
+
}
|
|
67736
|
+
if (!isFunction2(e)) return;
|
|
67737
|
+
const h = e.operator;
|
|
67738
|
+
const ops = e.ops;
|
|
67739
|
+
if (h !== "Error" && !_BaseCompiler.STRUCTURAL_HEADS.has(h) && target.functions?.(h) === void 0 && target.operators?.(h) === void 0)
|
|
67740
|
+
unsupported.add(h);
|
|
67741
|
+
if (h === "Function") {
|
|
67742
|
+
const params = ops.slice(1).filter((p) => isSymbol2(p)).map((p) => p.symbol);
|
|
67743
|
+
visit(ops[0], params.length ? union2(bound, params) : bound);
|
|
67744
|
+
return;
|
|
67745
|
+
}
|
|
67746
|
+
if (h === "Sum" || h === "Product" || h === "Integrate" || h === "Loop") {
|
|
67747
|
+
const indices = [];
|
|
67748
|
+
const limitExprs = [];
|
|
67749
|
+
for (const clause of ops.slice(1)) {
|
|
67750
|
+
if (isFunction2(clause)) {
|
|
67751
|
+
if (isSymbol2(clause.ops[0])) indices.push(clause.ops[0].symbol);
|
|
67752
|
+
for (const sub2 of clause.ops.slice(1)) limitExprs.push(sub2);
|
|
67753
|
+
} else {
|
|
67754
|
+
limitExprs.push(clause);
|
|
67755
|
+
}
|
|
67756
|
+
}
|
|
67757
|
+
visit(ops[0], indices.length ? union2(bound, indices) : bound);
|
|
67758
|
+
for (const le of limitExprs) visit(le, bound);
|
|
67759
|
+
return;
|
|
67760
|
+
}
|
|
67761
|
+
if (h === "Block") {
|
|
67762
|
+
const locals = [];
|
|
67763
|
+
for (const stmt of ops)
|
|
67764
|
+
if (isFunction2(stmt, "Declare") && isSymbol2(stmt.ops[0]))
|
|
67765
|
+
locals.push(stmt.ops[0].symbol);
|
|
67766
|
+
const inner = locals.length ? union2(bound, locals) : bound;
|
|
67767
|
+
for (const op of ops) visit(op, inner);
|
|
67768
|
+
return;
|
|
67769
|
+
}
|
|
67770
|
+
for (const op of ops) visit(op, bound);
|
|
67771
|
+
};
|
|
67772
|
+
visit(expr2, /* @__PURE__ */ new Set());
|
|
67773
|
+
return { freeSymbols: [...free], unsupported: [...unsupported] };
|
|
67774
|
+
}
|
|
67775
|
+
/**
|
|
67776
|
+
* Attach `freeSymbols` / `unsupported` (from `analyzeReferences`) to a
|
|
67777
|
+
* compilation result, returning the same object. Used by the built-in
|
|
67778
|
+
* targets to make every result carry its declarative reference analysis.
|
|
67779
|
+
*/
|
|
67780
|
+
static withReferences(result, expr2, target, varsKeys) {
|
|
67781
|
+
return Object.assign(
|
|
67782
|
+
result,
|
|
67783
|
+
_BaseCompiler.analyzeReferences(expr2, target, varsKeys)
|
|
67784
|
+
);
|
|
67785
|
+
}
|
|
67608
67786
|
/**
|
|
67609
67787
|
* Generate a temporary variable name
|
|
67610
67788
|
*/
|
|
@@ -67834,11 +68012,16 @@ Error in definition of "${name}"`,
|
|
|
67834
68012
|
try {
|
|
67835
68013
|
if (options?.target) {
|
|
67836
68014
|
const code = BaseCompiler.compile(expr2, options.target);
|
|
67837
|
-
return
|
|
67838
|
-
|
|
67839
|
-
|
|
67840
|
-
|
|
67841
|
-
|
|
68015
|
+
return BaseCompiler.withReferences(
|
|
68016
|
+
{
|
|
68017
|
+
target: options.target.language ?? "custom",
|
|
68018
|
+
success: true,
|
|
68019
|
+
code
|
|
68020
|
+
},
|
|
68021
|
+
expr2,
|
|
68022
|
+
options.target,
|
|
68023
|
+
options.vars ? new Set(Object.keys(options.vars)) : void 0
|
|
68024
|
+
);
|
|
67842
68025
|
}
|
|
67843
68026
|
const targetName = options?.to ?? "javascript";
|
|
67844
68027
|
const languageTarget = expr2.engine.getCompilationTarget(targetName);
|
|
@@ -67857,11 +68040,26 @@ Error in definition of "${name}"`,
|
|
|
67857
68040
|
});
|
|
67858
68041
|
} catch (e) {
|
|
67859
68042
|
if (options?.fallback ?? true) {
|
|
68043
|
+
const error = e.message;
|
|
67860
68044
|
console.warn(
|
|
67861
|
-
`Compilation fallback for "${expr2.operator}" (target: ${options?.to ?? "javascript"}): ${
|
|
68045
|
+
`Compilation fallback for "${expr2.operator}" (target: ${options?.to ?? "javascript"}): ${error}`
|
|
67862
68046
|
);
|
|
67863
68047
|
const ce = expr2.engine;
|
|
67864
68048
|
const target = options?.to ?? "javascript";
|
|
68049
|
+
let refs = {
|
|
68050
|
+
freeSymbols: [],
|
|
68051
|
+
unsupported: []
|
|
68052
|
+
};
|
|
68053
|
+
try {
|
|
68054
|
+
const compileTarget = options?.target ?? expr2.engine.getCompilationTarget(target)?.createTarget();
|
|
68055
|
+
if (compileTarget)
|
|
68056
|
+
refs = BaseCompiler.analyzeReferences(
|
|
68057
|
+
expr2,
|
|
68058
|
+
compileTarget,
|
|
68059
|
+
options?.vars ? new Set(Object.keys(options.vars)) : void 0
|
|
68060
|
+
);
|
|
68061
|
+
} catch {
|
|
68062
|
+
}
|
|
67865
68063
|
if (isFunction2(expr2, "Function")) {
|
|
67866
68064
|
const lambdaRun = ((...args) => ce.function("Apply", [expr2, ...args.map((a) => ce.expr(a))]).evaluate().re);
|
|
67867
68065
|
return {
|
|
@@ -67869,7 +68067,9 @@ Error in definition of "${name}"`,
|
|
|
67869
68067
|
success: false,
|
|
67870
68068
|
code: "",
|
|
67871
68069
|
calling: "lambda",
|
|
67872
|
-
run: lambdaRun
|
|
68070
|
+
run: lambdaRun,
|
|
68071
|
+
error,
|
|
68072
|
+
...refs
|
|
67873
68073
|
};
|
|
67874
68074
|
}
|
|
67875
68075
|
const fallbackRun = ((vars) => {
|
|
@@ -67888,7 +68088,9 @@ Error in definition of "${name}"`,
|
|
|
67888
68088
|
success: false,
|
|
67889
68089
|
code: "",
|
|
67890
68090
|
calling: "expression",
|
|
67891
|
-
run: fallbackRun
|
|
68091
|
+
run: fallbackRun,
|
|
68092
|
+
error,
|
|
68093
|
+
...refs
|
|
67892
68094
|
};
|
|
67893
68095
|
}
|
|
67894
68096
|
throw e;
|
|
@@ -73414,6 +73616,10 @@ Error in definition of "${name}"`,
|
|
|
73414
73616
|
|
|
73415
73617
|
// src/compute-engine/compilation/constant-folding.ts
|
|
73416
73618
|
function formatFloat(n) {
|
|
73619
|
+
if (!Number.isFinite(n))
|
|
73620
|
+
throw new Error(
|
|
73621
|
+
`Cannot compile the non-finite value \`${n}\` to a GPU shader: GLSL/WGSL have no infinity or NaN literals.`
|
|
73622
|
+
);
|
|
73417
73623
|
const str = n.toString();
|
|
73418
73624
|
if (!str.includes(".") && !str.includes("e") && !str.includes("E")) {
|
|
73419
73625
|
return `${str}.0`;
|
|
@@ -74009,6 +74215,7 @@ Error in definition of "${name}"`,
|
|
|
74009
74215
|
Erf: "_SYS.erf",
|
|
74010
74216
|
Erfc: "_SYS.erfc",
|
|
74011
74217
|
ErfInv: "_SYS.erfInv",
|
|
74218
|
+
Erfi: "_SYS.erfi",
|
|
74012
74219
|
// Special functions
|
|
74013
74220
|
Beta: "_SYS.beta",
|
|
74014
74221
|
Digamma: "_SYS.digamma",
|
|
@@ -74024,6 +74231,30 @@ Error in definition of "${name}"`,
|
|
|
74024
74231
|
// Airy functions
|
|
74025
74232
|
AiryAi: "_SYS.airyAi",
|
|
74026
74233
|
AiryBi: "_SYS.airyBi",
|
|
74234
|
+
// Exponential / trigonometric / logarithmic integrals. These are the closed
|
|
74235
|
+
// forms the antiderivative engine emits (e.g. ∫sin x/x dx = SinIntegral(x)),
|
|
74236
|
+
// so an "evaluate then compile" pipeline must be able to lower them.
|
|
74237
|
+
SinIntegral: "_SYS.sinIntegral",
|
|
74238
|
+
CosIntegral: "_SYS.cosIntegral",
|
|
74239
|
+
ExpIntegralEi: "_SYS.expIntegralEi",
|
|
74240
|
+
LogIntegral: "_SYS.logIntegral",
|
|
74241
|
+
// Arithmetic-geometric mean and elliptic integrals (parameter convention
|
|
74242
|
+
// m = k², as in the library). `AGM`, `EllipticE`, and `EllipticPi` are
|
|
74243
|
+
// arity-overloaded — the handlers mirror the library's evaluate dispatch.
|
|
74244
|
+
AGM: (args, compile3) => args.length === 1 ? `_SYS.agm(1, ${compile3(args[0])})` : `_SYS.agm(${compile3(args[0])}, ${compile3(args[1])})`,
|
|
74245
|
+
EllipticK: "_SYS.ellipticK",
|
|
74246
|
+
EllipticE: (args, compile3) => args.length === 2 ? `_SYS.ellipticEIncomplete(${compile3(args[0])}, ${compile3(args[1])})` : `_SYS.ellipticE(${compile3(args[0])})`,
|
|
74247
|
+
EllipticF: (args, compile3) => `_SYS.ellipticF(${compile3(args[0])}, ${compile3(args[1])})`,
|
|
74248
|
+
EllipticPi: (args, compile3) => args.length === 3 ? `_SYS.ellipticPiIncomplete(${compile3(args[0])}, ${compile3(
|
|
74249
|
+
args[1]
|
|
74250
|
+
)}, ${compile3(args[2])})` : `_SYS.ellipticPiComplete(${compile3(args[0])}, ${compile3(args[1])})`,
|
|
74251
|
+
// Hypergeometric functions.
|
|
74252
|
+
Hypergeometric2F1: (args, compile3) => `_SYS.hypergeometric2F1(${compile3(args[0])}, ${compile3(args[1])}, ${compile3(
|
|
74253
|
+
args[2]
|
|
74254
|
+
)}, ${compile3(args[3])})`,
|
|
74255
|
+
Hypergeometric1F1: (args, compile3) => `_SYS.hypergeometric1F1(${compile3(args[0])}, ${compile3(args[1])}, ${compile3(
|
|
74256
|
+
args[2]
|
|
74257
|
+
)})`,
|
|
74027
74258
|
// Combinatorics
|
|
74028
74259
|
Mandelbrot: ([c, maxIter], compile3) => {
|
|
74029
74260
|
if (c === null || maxIter === null)
|
|
@@ -74036,6 +74267,8 @@ Error in definition of "${name}"`,
|
|
|
74036
74267
|
return `_SYS.julia(${compile3(z)}, ${compile3(c)}, ${compile3(maxIter)})`;
|
|
74037
74268
|
},
|
|
74038
74269
|
Binomial: (args, compile3) => `_SYS.binomial(${compile3(args[0])}, ${compile3(args[1])})`,
|
|
74270
|
+
// Choose(n, k) is the binomial coefficient — same runtime helper.
|
|
74271
|
+
Choose: (args, compile3) => `_SYS.binomial(${compile3(args[0])}, ${compile3(args[1])})`,
|
|
74039
74272
|
Fibonacci: "_SYS.fibonacci",
|
|
74040
74273
|
// Complex-specific functions
|
|
74041
74274
|
Real: (args, compile3) => {
|
|
@@ -74541,6 +74774,20 @@ Error in definition of "${name}"`,
|
|
|
74541
74774
|
sinc,
|
|
74542
74775
|
fresnelS,
|
|
74543
74776
|
fresnelC,
|
|
74777
|
+
sinIntegral,
|
|
74778
|
+
cosIntegral,
|
|
74779
|
+
expIntegralEi,
|
|
74780
|
+
logIntegral,
|
|
74781
|
+
erfi,
|
|
74782
|
+
agm,
|
|
74783
|
+
ellipticK,
|
|
74784
|
+
ellipticE,
|
|
74785
|
+
ellipticEIncomplete,
|
|
74786
|
+
ellipticF,
|
|
74787
|
+
ellipticPiComplete,
|
|
74788
|
+
ellipticPiIncomplete,
|
|
74789
|
+
hypergeometric2F1,
|
|
74790
|
+
hypergeometric1F1,
|
|
74544
74791
|
mandelbrot: (c, maxIter) => {
|
|
74545
74792
|
let zx = 0, zy = 0;
|
|
74546
74793
|
const cx = typeof c === "number" ? c : c.re;
|
|
@@ -74727,7 +74974,7 @@ Error in definition of "${name}"`,
|
|
|
74727
74974
|
functions: (id) => namedFunctions?.[id] ? namedFunctions[id] : JAVASCRIPT_FUNCTIONS[id],
|
|
74728
74975
|
var: (id) => {
|
|
74729
74976
|
if (vars && id in vars) return JSON.stringify(vars[id]);
|
|
74730
|
-
const
|
|
74977
|
+
const result2 = {
|
|
74731
74978
|
Pi: "Math.PI",
|
|
74732
74979
|
ExponentialE: "Math.E",
|
|
74733
74980
|
NaN: "Number.NaN",
|
|
@@ -74738,13 +74985,20 @@ Error in definition of "${name}"`,
|
|
|
74738
74985
|
CatalanConstant: "0.91596559417721901",
|
|
74739
74986
|
EulerGamma: "0.57721566490153286"
|
|
74740
74987
|
}[id];
|
|
74741
|
-
if (
|
|
74988
|
+
if (result2 !== void 0) return result2;
|
|
74742
74989
|
if (unknowns.includes(id)) return `_.${id}`;
|
|
74743
|
-
return void 0;
|
|
74990
|
+
if (expr2.engine._getSymbolValue(id) !== void 0) return void 0;
|
|
74991
|
+
return `_.${id}`;
|
|
74744
74992
|
},
|
|
74745
74993
|
preamble: (preamble ?? "") + preambleImports
|
|
74746
74994
|
});
|
|
74747
|
-
|
|
74995
|
+
const result = compileToTarget(expr2, target, realOnly);
|
|
74996
|
+
return BaseCompiler.withReferences(
|
|
74997
|
+
result,
|
|
74998
|
+
expr2,
|
|
74999
|
+
target,
|
|
75000
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
75001
|
+
);
|
|
74748
75002
|
}
|
|
74749
75003
|
};
|
|
74750
75004
|
function wrapRealOnly(result) {
|
|
@@ -77315,6 +77569,10 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
|
|
|
77315
77569
|
EulerGamma: "0.57721566490"
|
|
77316
77570
|
};
|
|
77317
77571
|
function formatGPUNumber(n) {
|
|
77572
|
+
if (!Number.isFinite(n))
|
|
77573
|
+
throw new Error(
|
|
77574
|
+
`Cannot compile the non-finite value \`${n}\` to a GPU shader: GLSL/WGSL have no infinity or NaN literals.`
|
|
77575
|
+
);
|
|
77318
77576
|
const str = n.toString();
|
|
77319
77577
|
if (!str.includes(".") && !str.includes("e") && !str.includes("E")) {
|
|
77320
77578
|
return `${str}.0`;
|
|
@@ -77342,7 +77600,7 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
|
|
|
77342
77600
|
var: (id) => {
|
|
77343
77601
|
if (id === "ImaginaryUnit") return `${v2}(0.0, 1.0)`;
|
|
77344
77602
|
if (id in constants) return constants[id];
|
|
77345
|
-
return
|
|
77603
|
+
return void 0;
|
|
77346
77604
|
},
|
|
77347
77605
|
string: (str) => JSON.stringify(str),
|
|
77348
77606
|
number: formatGPUNumber,
|
|
@@ -77381,7 +77639,7 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
|
|
|
77381
77639
|
if (vars && id in vars) return vars[id];
|
|
77382
77640
|
if (id === "ImaginaryUnit") return `${v2}(0.0, 1.0)`;
|
|
77383
77641
|
if (id in constants) return constants[id];
|
|
77384
|
-
return
|
|
77642
|
+
return void 0;
|
|
77385
77643
|
}
|
|
77386
77644
|
});
|
|
77387
77645
|
const code = BaseCompiler.compile(expr2, target);
|
|
@@ -77421,7 +77679,12 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
|
|
|
77421
77679
|
preamble += this.languageId === "wgsl" ? GPU_COLOR_PREAMBLE_WGSL : GPU_COLOR_PREAMBLE_GLSL;
|
|
77422
77680
|
}
|
|
77423
77681
|
if (preamble) result.preamble = preamble;
|
|
77424
|
-
return
|
|
77682
|
+
return BaseCompiler.withReferences(
|
|
77683
|
+
result,
|
|
77684
|
+
expr2,
|
|
77685
|
+
target,
|
|
77686
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
77687
|
+
);
|
|
77425
77688
|
}
|
|
77426
77689
|
compileToSource(expr2, _options = {}) {
|
|
77427
77690
|
const target = this.createTarget();
|
|
@@ -77454,6 +77717,8 @@ fn _gpu_apca(lch_bg: vec3f, lch_fg: vec3f) -> f32 {
|
|
|
77454
77717
|
Tuple: compileGLSLList
|
|
77455
77718
|
};
|
|
77456
77719
|
var GLSLTarget = class extends GPUShaderTarget {
|
|
77720
|
+
// Annotated `string` (not the literal `'glsl'`) so subclasses such as
|
|
77721
|
+
// `IntervalGLSLTarget` can override it while reusing the GLSL shader assembly.
|
|
77457
77722
|
languageId = "glsl";
|
|
77458
77723
|
getLanguageSpecificFunctions() {
|
|
77459
77724
|
return GLSL_FUNCTIONS;
|
|
@@ -79415,11 +79680,18 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
|
|
|
79415
79680
|
};
|
|
79416
79681
|
if (id in constants) return constants[id];
|
|
79417
79682
|
if (unknowns.includes(id)) return `_.${id}`;
|
|
79418
|
-
return void 0;
|
|
79683
|
+
if (expr2.engine._getSymbolValue(id) !== void 0) return void 0;
|
|
79684
|
+
return `_.${id}`;
|
|
79419
79685
|
},
|
|
79420
79686
|
preamble: (preamble ?? "") + preambleImports
|
|
79421
79687
|
});
|
|
79422
|
-
|
|
79688
|
+
const result = compileToIntervalTarget(expr2, target);
|
|
79689
|
+
return BaseCompiler.withReferences(
|
|
79690
|
+
result,
|
|
79691
|
+
expr2,
|
|
79692
|
+
target,
|
|
79693
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
79694
|
+
);
|
|
79423
79695
|
}
|
|
79424
79696
|
};
|
|
79425
79697
|
function compileToIntervalTarget(expr2, target) {
|
|
@@ -79443,6 +79715,532 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
|
|
|
79443
79715
|
};
|
|
79444
79716
|
}
|
|
79445
79717
|
|
|
79718
|
+
// src/compute-engine/compilation/interval-glsl-target.ts
|
|
79719
|
+
var IV_INF = "1e18";
|
|
79720
|
+
var INTERVAL_GLSL_PREAMBLE = `
|
|
79721
|
+
const float IV_INF = ${IV_INF};
|
|
79722
|
+
const vec2 IV_ENTIRE = vec2(-IV_INF, IV_INF);
|
|
79723
|
+
const vec2 IV_EMPTY = vec2(IV_INF, -IV_INF);
|
|
79724
|
+
|
|
79725
|
+
bool _iv_is_empty(vec2 a) { return a.x > a.y; }
|
|
79726
|
+
|
|
79727
|
+
// Clamp bounds to the finite sentinel range. Preserves IV_EMPTY (its components
|
|
79728
|
+
// already sit at the sentinels) and folds any overflowed intermediate back to
|
|
79729
|
+
// the sentinel (min(inf, IV_INF) = IV_INF), so a real \`inf\` never escapes an op.
|
|
79730
|
+
vec2 _iv_clamp(vec2 a) { return clamp(a, -IV_INF, IV_INF); }
|
|
79731
|
+
|
|
79732
|
+
// Exact empty propagation: force empty if any operand is empty.
|
|
79733
|
+
vec2 _iv_guard1(vec2 r, vec2 a) { return _iv_is_empty(a) ? IV_EMPTY : r; }
|
|
79734
|
+
vec2 _iv_guard2(vec2 r, vec2 a, vec2 b) {
|
|
79735
|
+
return (_iv_is_empty(a) || _iv_is_empty(b)) ? IV_EMPTY : r;
|
|
79736
|
+
}
|
|
79737
|
+
|
|
79738
|
+
vec2 _iv_negate(vec2 a) { return _iv_guard1(_iv_clamp(vec2(-a.y, -a.x)), a); }
|
|
79739
|
+
|
|
79740
|
+
vec2 _iv_add(vec2 a, vec2 b) {
|
|
79741
|
+
return _iv_guard2(_iv_clamp(vec2(a.x + b.x, a.y + b.y)), a, b);
|
|
79742
|
+
}
|
|
79743
|
+
|
|
79744
|
+
vec2 _iv_sub(vec2 a, vec2 b) {
|
|
79745
|
+
return _iv_guard2(_iv_clamp(vec2(a.x - b.y, a.y - b.x)), a, b);
|
|
79746
|
+
}
|
|
79747
|
+
|
|
79748
|
+
vec2 _iv_mul(vec2 a, vec2 b) {
|
|
79749
|
+
float p1 = a.x * b.x, p2 = a.x * b.y, p3 = a.y * b.x, p4 = a.y * b.y;
|
|
79750
|
+
vec2 r = vec2(min(min(p1, p2), min(p3, p4)), max(max(p1, p2), max(p3, p4)));
|
|
79751
|
+
return _iv_guard2(_iv_clamp(r), a, b);
|
|
79752
|
+
}
|
|
79753
|
+
|
|
79754
|
+
vec2 _iv_div(vec2 a, vec2 b) {
|
|
79755
|
+
// Denominator spanning 0 \u2192 entire (wide, never narrow): the CPU pass turns
|
|
79756
|
+
// the pole into a proper asymptote break.
|
|
79757
|
+
bool spansZero = (b.x <= 0.0 && b.y >= 0.0);
|
|
79758
|
+
float q1 = a.x / b.x, q2 = a.x / b.y, q3 = a.y / b.x, q4 = a.y / b.y;
|
|
79759
|
+
vec2 r = vec2(min(min(q1, q2), min(q3, q4)), max(max(q1, q2), max(q3, q4)));
|
|
79760
|
+
r = spansZero ? IV_ENTIRE : r;
|
|
79761
|
+
return _iv_guard2(_iv_clamp(r), a, b);
|
|
79762
|
+
}
|
|
79763
|
+
|
|
79764
|
+
vec2 _iv_square(vec2 a) {
|
|
79765
|
+
float lo2 = a.x * a.x, hi2 = a.y * a.y;
|
|
79766
|
+
// Straddles 0 \u21D2 min is 0; otherwise the smaller endpoint\xB2 is the min.
|
|
79767
|
+
float lo = (a.x <= 0.0 && a.y >= 0.0) ? 0.0 : min(lo2, hi2);
|
|
79768
|
+
return _iv_guard1(_iv_clamp(vec2(lo, max(lo2, hi2))), a);
|
|
79769
|
+
}
|
|
79770
|
+
|
|
79771
|
+
// Scalar integer power that is correct for negative bases (GLSL \`pow\` requires
|
|
79772
|
+
// a non-negative base): keep the sign for odd exponents, drop it for even.
|
|
79773
|
+
float _iv_powi_scalar(float x, float n) {
|
|
79774
|
+
float a = pow(abs(x), n);
|
|
79775
|
+
return (mod(n, 2.0) == 1.0 && x < 0.0) ? -a : a;
|
|
79776
|
+
}
|
|
79777
|
+
|
|
79778
|
+
vec2 _iv_powi(vec2 a, float n) {
|
|
79779
|
+
float pl = _iv_powi_scalar(a.x, n);
|
|
79780
|
+
float ph = _iv_powi_scalar(a.y, n);
|
|
79781
|
+
bool even = (mod(n, 2.0) == 0.0);
|
|
79782
|
+
bool straddle = (a.x <= 0.0 && a.y >= 0.0);
|
|
79783
|
+
float lo = even ? (straddle ? 0.0 : min(pl, ph)) : pl;
|
|
79784
|
+
float hi = even ? max(pl, ph) : ph;
|
|
79785
|
+
return _iv_guard1(_iv_clamp(vec2(lo, hi)), a);
|
|
79786
|
+
}
|
|
79787
|
+
|
|
79788
|
+
// \u2500\u2500 Phase 2: elementary functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
79789
|
+
|
|
79790
|
+
vec2 _iv_abs(vec2 a) {
|
|
79791
|
+
float al = abs(a.x), ah = abs(a.y);
|
|
79792
|
+
bool straddle = (a.x <= 0.0 && a.y >= 0.0);
|
|
79793
|
+
return _iv_guard1(_iv_clamp(vec2(straddle ? 0.0 : min(al, ah), max(al, ah))), a);
|
|
79794
|
+
}
|
|
79795
|
+
|
|
79796
|
+
// Domain x \u2265 0: fully-negative box \u2192 empty; a box straddling 0 clamps lo to 0.
|
|
79797
|
+
vec2 _iv_sqrt(vec2 a) {
|
|
79798
|
+
vec2 r = vec2(sqrt(max(a.x, 0.0)), sqrt(max(a.y, 0.0)));
|
|
79799
|
+
r = (a.y < 0.0) ? IV_EMPTY : r;
|
|
79800
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79801
|
+
}
|
|
79802
|
+
|
|
79803
|
+
vec2 _iv_exp(vec2 a) {
|
|
79804
|
+
return _iv_guard1(_iv_clamp(vec2(exp(a.x), exp(a.y))), a);
|
|
79805
|
+
}
|
|
79806
|
+
|
|
79807
|
+
// Domain x > 0: fully-\u22640 box \u2192 empty; straddling box \u2192 lo clamped to \u2212IV_INF
|
|
79808
|
+
// (ln \u2192 \u2212\u221E as x \u2192 0\u207A, never a real \u2212inf).
|
|
79809
|
+
vec2 _iv_ln(vec2 a) {
|
|
79810
|
+
vec2 r = vec2(a.x > 0.0 ? log(a.x) : -IV_INF, log(a.y));
|
|
79811
|
+
r = (a.y <= 0.0) ? IV_EMPTY : r;
|
|
79812
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79813
|
+
}
|
|
79814
|
+
|
|
79815
|
+
const float _IV_INV_LN10 = 0.43429448190325176;
|
|
79816
|
+
const float _IV_INV_LN2 = 1.4426950408889634;
|
|
79817
|
+
|
|
79818
|
+
vec2 _iv_log10(vec2 a) {
|
|
79819
|
+
vec2 r = vec2(a.x > 0.0 ? log(a.x) * _IV_INV_LN10 : -IV_INF, log(a.y) * _IV_INV_LN10);
|
|
79820
|
+
r = (a.y <= 0.0) ? IV_EMPTY : r;
|
|
79821
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79822
|
+
}
|
|
79823
|
+
|
|
79824
|
+
vec2 _iv_log2(vec2 a) {
|
|
79825
|
+
vec2 r = vec2(a.x > 0.0 ? log(a.x) * _IV_INV_LN2 : -IV_INF, log(a.y) * _IV_INV_LN2);
|
|
79826
|
+
r = (a.y <= 0.0) ? IV_EMPTY : r;
|
|
79827
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79828
|
+
}
|
|
79829
|
+
|
|
79830
|
+
// Non-integer power. Real only for base \u2265 0: fully-negative box \u2192 empty; a box
|
|
79831
|
+
// straddling 0 clamps the base low end to 0. \`p\` is a compile-time constant, so
|
|
79832
|
+
// the \`p >= 0\` test is a constant branch.
|
|
79833
|
+
vec2 _iv_powf(vec2 a, float p) {
|
|
79834
|
+
float lob = max(a.x, 0.0);
|
|
79835
|
+
float e0 = pow(lob, p), e1 = pow(a.y, p);
|
|
79836
|
+
vec2 r = (p >= 0.0) ? vec2(e0, e1) : vec2(e1, e0);
|
|
79837
|
+
r = (a.y < 0.0) ? IV_EMPTY : r;
|
|
79838
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79839
|
+
}
|
|
79840
|
+
|
|
79841
|
+
// \u2500\u2500 Phase 3: trigonometric & inverse-trigonometric functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
79842
|
+
// Mirrors interval-js (interval/trigonometric.ts): exact endpoints with
|
|
79843
|
+
// extremum snapping (no outward epsilon). Per the Option-A contract, a tan pole
|
|
79844
|
+
// yields \`entire\` (interval-js returns \`singular\`; entire \u2287 singular and the
|
|
79845
|
+
// CPU classifies the asymptote).
|
|
79846
|
+
|
|
79847
|
+
const float _IV_PI = 3.141592653589793;
|
|
79848
|
+
const float _IV_TWO_PI = 6.283185307179586;
|
|
79849
|
+
const float _IV_HALF_PI = 1.5707963267948966;
|
|
79850
|
+
const float _IV_THREE_HALF_PI = 4.71238898038469;
|
|
79851
|
+
|
|
79852
|
+
// True if [a] contains an extremum of the family { ext + n\xB7period }.
|
|
79853
|
+
bool _iv_has_ext(vec2 a, float ext, float period) {
|
|
79854
|
+
float n = ceil((a.x - ext) / period);
|
|
79855
|
+
float cand = ext + n * period;
|
|
79856
|
+
return cand >= a.x - 1e-15 && cand <= a.y + 1e-15;
|
|
79857
|
+
}
|
|
79858
|
+
|
|
79859
|
+
vec2 _iv_sin(vec2 a) {
|
|
79860
|
+
vec2 r;
|
|
79861
|
+
if (a.y - a.x >= _IV_TWO_PI) r = vec2(-1.0, 1.0);
|
|
79862
|
+
else {
|
|
79863
|
+
float sl = sin(a.x), sh = sin(a.y);
|
|
79864
|
+
float lo = min(sl, sh), hi = max(sl, sh);
|
|
79865
|
+
if (_iv_has_ext(a, _IV_HALF_PI, _IV_TWO_PI)) hi = 1.0;
|
|
79866
|
+
if (_iv_has_ext(a, _IV_THREE_HALF_PI, _IV_TWO_PI)) lo = -1.0;
|
|
79867
|
+
r = vec2(lo, hi);
|
|
79868
|
+
}
|
|
79869
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79870
|
+
}
|
|
79871
|
+
|
|
79872
|
+
vec2 _iv_cos(vec2 a) {
|
|
79873
|
+
vec2 r;
|
|
79874
|
+
if (a.y - a.x >= _IV_TWO_PI) r = vec2(-1.0, 1.0);
|
|
79875
|
+
else {
|
|
79876
|
+
float cl = cos(a.x), ch = cos(a.y);
|
|
79877
|
+
float lo = min(cl, ch), hi = max(cl, ch);
|
|
79878
|
+
if (_iv_has_ext(a, 0.0, _IV_TWO_PI)) hi = 1.0;
|
|
79879
|
+
if (_iv_has_ext(a, _IV_PI, _IV_TWO_PI)) lo = -1.0;
|
|
79880
|
+
r = vec2(lo, hi);
|
|
79881
|
+
}
|
|
79882
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79883
|
+
}
|
|
79884
|
+
|
|
79885
|
+
vec2 _iv_tan(vec2 a) {
|
|
79886
|
+
// A pole in the interval \u2192 entire (cannot exclude).
|
|
79887
|
+
bool pole =
|
|
79888
|
+
(a.y - a.x >= _IV_PI) || _iv_has_ext(a, _IV_HALF_PI, _IV_PI);
|
|
79889
|
+
float tl = tan(a.x), th = tan(a.y);
|
|
79890
|
+
// Floating-point branch-cross sanity (large opposite-sign endpoints).
|
|
79891
|
+
bool crossed = (tl > 1e10 && th < -1e10) || (tl < -1e10 && th > 1e10);
|
|
79892
|
+
vec2 r = (pole || crossed) ? IV_ENTIRE : vec2(tl, th);
|
|
79893
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79894
|
+
}
|
|
79895
|
+
|
|
79896
|
+
// asin: domain [\u22121, 1]. Fully outside \u2192 empty; straddling clamps to the valid
|
|
79897
|
+
// sub-range. Monotonic increasing.
|
|
79898
|
+
vec2 _iv_asin(vec2 a) {
|
|
79899
|
+
vec2 r = vec2(asin(max(a.x, -1.0)), asin(min(a.y, 1.0)));
|
|
79900
|
+
r = (a.x > 1.0 || a.y < -1.0) ? IV_EMPTY : r;
|
|
79901
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79902
|
+
}
|
|
79903
|
+
|
|
79904
|
+
// acos: domain [\u22121, 1], monotonic decreasing (bounds swap).
|
|
79905
|
+
vec2 _iv_acos(vec2 a) {
|
|
79906
|
+
vec2 r = vec2(acos(min(a.y, 1.0)), acos(max(a.x, -1.0)));
|
|
79907
|
+
r = (a.x > 1.0 || a.y < -1.0) ? IV_EMPTY : r;
|
|
79908
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79909
|
+
}
|
|
79910
|
+
|
|
79911
|
+
vec2 _iv_atan(vec2 a) {
|
|
79912
|
+
return _iv_guard1(_iv_clamp(vec2(atan(a.x), atan(a.y))), a);
|
|
79913
|
+
}
|
|
79914
|
+
|
|
79915
|
+
// \u2500\u2500 Discontinuous / step functions \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
79916
|
+
// Bounded jump-discontinuity functions return the TIGHT value-range enclosure
|
|
79917
|
+
// (sound, and excludable when the range misses 0) rather than \`entire\` \u2014 only
|
|
79918
|
+
// genuine poles are entire. Per the Option-A division of labor, the CPU still
|
|
79919
|
+
// classifies the discontinuity on the (kept) live cells; the GPU only needs a
|
|
79920
|
+
// sound bound for the exclusion test. These functions are monotone, so the
|
|
79921
|
+
// enclosure is just [f(lo), f(hi)] unless noted.
|
|
79922
|
+
|
|
79923
|
+
vec2 _iv_floor(vec2 a) { return _iv_guard1(_iv_clamp(vec2(floor(a.x), floor(a.y))), a); }
|
|
79924
|
+
vec2 _iv_ceil(vec2 a) { return _iv_guard1(_iv_clamp(vec2(ceil(a.x), ceil(a.y))), a); }
|
|
79925
|
+
vec2 _iv_round(vec2 a) { return _iv_guard1(_iv_clamp(vec2(floor(a.x + 0.5), floor(a.y + 0.5))), a); }
|
|
79926
|
+
vec2 _iv_trunc(vec2 a) { return _iv_guard1(_iv_clamp(vec2(trunc(a.x), trunc(a.y))), a); }
|
|
79927
|
+
vec2 _iv_sign(vec2 a) { return _iv_guard1(vec2(sign(a.x), sign(a.y)), a); }
|
|
79928
|
+
|
|
79929
|
+
vec2 _iv_heaviside(vec2 a) {
|
|
79930
|
+
float hl = a.x < 0.0 ? 0.0 : (a.x > 0.0 ? 1.0 : 0.5);
|
|
79931
|
+
float hh = a.y < 0.0 ? 0.0 : (a.y > 0.0 ? 1.0 : 0.5);
|
|
79932
|
+
return _iv_guard1(vec2(hl, hh), a);
|
|
79933
|
+
}
|
|
79934
|
+
|
|
79935
|
+
// fract(x) = x \u2212 floor(x): continuous within an integer cell, sawtooth across
|
|
79936
|
+
// one (\u2192 full [0, 1] range).
|
|
79937
|
+
vec2 _iv_fract(vec2 a) {
|
|
79938
|
+
float fl = floor(a.x);
|
|
79939
|
+
vec2 r = (fl == floor(a.y)) ? vec2(a.x - fl, a.y - fl) : vec2(0.0, 1.0);
|
|
79940
|
+
return _iv_guard1(_iv_clamp(r), a);
|
|
79941
|
+
}
|
|
79942
|
+
|
|
79943
|
+
vec2 _iv_min(vec2 a, vec2 b) {
|
|
79944
|
+
return _iv_guard2(_iv_clamp(vec2(min(a.x, b.x), min(a.y, b.y))), a, b);
|
|
79945
|
+
}
|
|
79946
|
+
vec2 _iv_max(vec2 a, vec2 b) {
|
|
79947
|
+
return _iv_guard2(_iv_clamp(vec2(max(a.x, b.x), max(a.y, b.y))), a, b);
|
|
79948
|
+
}
|
|
79949
|
+
|
|
79950
|
+
// mod(x, y) = x \u2212 y\xB7floor(x/y). A modulus straddling 0 is a pole \u2192 entire. For
|
|
79951
|
+
// a constant (point) modulus the fast path is exact; otherwise compose (the
|
|
79952
|
+
// tight floor keeps it sound).
|
|
79953
|
+
vec2 _iv_mod(vec2 a, vec2 b) {
|
|
79954
|
+
if (b.x <= 0.0 && b.y >= 0.0) return _iv_guard2(IV_ENTIRE, a, b);
|
|
79955
|
+
if (b.x == b.y) {
|
|
79956
|
+
float p = abs(b.x);
|
|
79957
|
+
float flo = floor(a.x / p);
|
|
79958
|
+
vec2 r = (flo == floor(a.y / p)) ? vec2(a.x - p * flo, a.y - p * flo)
|
|
79959
|
+
: vec2(0.0, p);
|
|
79960
|
+
return _iv_guard2(_iv_clamp(r), a, b);
|
|
79961
|
+
}
|
|
79962
|
+
return _iv_sub(a, _iv_mul(b, _iv_floor(_iv_div(a, b))));
|
|
79963
|
+
}
|
|
79964
|
+
`;
|
|
79965
|
+
var INTERVAL_GLSL_FUNCTIONS = {
|
|
79966
|
+
Add: (args, compile3) => {
|
|
79967
|
+
if (args.length === 0) return "vec2(0.0, 0.0)";
|
|
79968
|
+
let r = compile3(args[0]);
|
|
79969
|
+
for (let i = 1; i < args.length; i++)
|
|
79970
|
+
r = `_iv_add(${r}, ${compile3(args[i])})`;
|
|
79971
|
+
return r;
|
|
79972
|
+
},
|
|
79973
|
+
Subtract: ([a, b], compile3) => {
|
|
79974
|
+
if (a === null || b === null) throw new Error("Subtract: missing argument");
|
|
79975
|
+
return `_iv_sub(${compile3(a)}, ${compile3(b)})`;
|
|
79976
|
+
},
|
|
79977
|
+
Multiply: (args, compile3) => {
|
|
79978
|
+
if (args.length === 0) return "vec2(1.0, 1.0)";
|
|
79979
|
+
let r = compile3(args[0]);
|
|
79980
|
+
for (let i = 1; i < args.length; i++)
|
|
79981
|
+
r = `_iv_mul(${r}, ${compile3(args[i])})`;
|
|
79982
|
+
return r;
|
|
79983
|
+
},
|
|
79984
|
+
Divide: ([a, b], compile3) => {
|
|
79985
|
+
if (a === null || b === null) throw new Error("Divide: missing argument");
|
|
79986
|
+
return `_iv_div(${compile3(a)}, ${compile3(b)})`;
|
|
79987
|
+
},
|
|
79988
|
+
Negate: ([a], compile3) => {
|
|
79989
|
+
if (a === null) throw new Error("Negate: no argument");
|
|
79990
|
+
return `_iv_negate(${compile3(a)})`;
|
|
79991
|
+
},
|
|
79992
|
+
Square: ([a], compile3) => {
|
|
79993
|
+
if (a === null) throw new Error("Square: no argument");
|
|
79994
|
+
return `_iv_square(${compile3(a)})`;
|
|
79995
|
+
},
|
|
79996
|
+
Sqrt: ([a], compile3) => {
|
|
79997
|
+
if (a === null) throw new Error("Sqrt: no argument");
|
|
79998
|
+
return `_iv_sqrt(${compile3(a)})`;
|
|
79999
|
+
},
|
|
80000
|
+
Abs: ([a], compile3) => {
|
|
80001
|
+
if (a === null) throw new Error("Abs: no argument");
|
|
80002
|
+
return `_iv_abs(${compile3(a)})`;
|
|
80003
|
+
},
|
|
80004
|
+
Exp: ([a], compile3) => {
|
|
80005
|
+
if (a === null) throw new Error("Exp: no argument");
|
|
80006
|
+
return `_iv_exp(${compile3(a)})`;
|
|
80007
|
+
},
|
|
80008
|
+
Ln: ([a], compile3) => {
|
|
80009
|
+
if (a === null) throw new Error("Ln: no argument");
|
|
80010
|
+
return `_iv_ln(${compile3(a)})`;
|
|
80011
|
+
},
|
|
80012
|
+
Log: (args, compile3) => {
|
|
80013
|
+
if (args.length === 1) return `_iv_log10(${compile3(args[0])})`;
|
|
80014
|
+
return `_iv_div(_iv_ln(${compile3(args[0])}), _iv_ln(${compile3(args[1])}))`;
|
|
80015
|
+
},
|
|
80016
|
+
Lb: ([a], compile3) => {
|
|
80017
|
+
if (a === null) throw new Error("Lb: no argument");
|
|
80018
|
+
return `_iv_log2(${compile3(a)})`;
|
|
80019
|
+
},
|
|
80020
|
+
Sin: ([a], compile3) => {
|
|
80021
|
+
if (a === null) throw new Error("Sin: no argument");
|
|
80022
|
+
return `_iv_sin(${compile3(a)})`;
|
|
80023
|
+
},
|
|
80024
|
+
Cos: ([a], compile3) => {
|
|
80025
|
+
if (a === null) throw new Error("Cos: no argument");
|
|
80026
|
+
return `_iv_cos(${compile3(a)})`;
|
|
80027
|
+
},
|
|
80028
|
+
Tan: ([a], compile3) => {
|
|
80029
|
+
if (a === null) throw new Error("Tan: no argument");
|
|
80030
|
+
return `_iv_tan(${compile3(a)})`;
|
|
80031
|
+
},
|
|
80032
|
+
Arcsin: ([a], compile3) => {
|
|
80033
|
+
if (a === null) throw new Error("Arcsin: no argument");
|
|
80034
|
+
return `_iv_asin(${compile3(a)})`;
|
|
80035
|
+
},
|
|
80036
|
+
Arccos: ([a], compile3) => {
|
|
80037
|
+
if (a === null) throw new Error("Arccos: no argument");
|
|
80038
|
+
return `_iv_acos(${compile3(a)})`;
|
|
80039
|
+
},
|
|
80040
|
+
Arctan: ([a], compile3) => {
|
|
80041
|
+
if (a === null) throw new Error("Arctan: no argument");
|
|
80042
|
+
return `_iv_atan(${compile3(a)})`;
|
|
80043
|
+
},
|
|
80044
|
+
Floor: ([a], compile3) => {
|
|
80045
|
+
if (a === null) throw new Error("Floor: no argument");
|
|
80046
|
+
return `_iv_floor(${compile3(a)})`;
|
|
80047
|
+
},
|
|
80048
|
+
Ceil: ([a], compile3) => {
|
|
80049
|
+
if (a === null) throw new Error("Ceil: no argument");
|
|
80050
|
+
return `_iv_ceil(${compile3(a)})`;
|
|
80051
|
+
},
|
|
80052
|
+
Round: ([a], compile3) => {
|
|
80053
|
+
if (a === null) throw new Error("Round: no argument");
|
|
80054
|
+
return `_iv_round(${compile3(a)})`;
|
|
80055
|
+
},
|
|
80056
|
+
Truncate: ([a], compile3) => {
|
|
80057
|
+
if (a === null) throw new Error("Truncate: no argument");
|
|
80058
|
+
return `_iv_trunc(${compile3(a)})`;
|
|
80059
|
+
},
|
|
80060
|
+
Fract: ([a], compile3) => {
|
|
80061
|
+
if (a === null) throw new Error("Fract: no argument");
|
|
80062
|
+
return `_iv_fract(${compile3(a)})`;
|
|
80063
|
+
},
|
|
80064
|
+
Sign: ([a], compile3) => {
|
|
80065
|
+
if (a === null) throw new Error("Sign: no argument");
|
|
80066
|
+
return `_iv_sign(${compile3(a)})`;
|
|
80067
|
+
},
|
|
80068
|
+
Heaviside: ([a], compile3) => {
|
|
80069
|
+
if (a === null) throw new Error("Heaviside: no argument");
|
|
80070
|
+
return `_iv_heaviside(${compile3(a)})`;
|
|
80071
|
+
},
|
|
80072
|
+
Mod: ([a, b], compile3) => {
|
|
80073
|
+
if (a === null || b === null) throw new Error("Mod: missing argument");
|
|
80074
|
+
return `_iv_mod(${compile3(a)}, ${compile3(b)})`;
|
|
80075
|
+
},
|
|
80076
|
+
Min: (args, compile3) => {
|
|
80077
|
+
if (args.length === 0) throw new Error("Min: no argument");
|
|
80078
|
+
let r = compile3(args[0]);
|
|
80079
|
+
for (let i = 1; i < args.length; i++)
|
|
80080
|
+
r = `_iv_min(${r}, ${compile3(args[i])})`;
|
|
80081
|
+
return r;
|
|
80082
|
+
},
|
|
80083
|
+
Max: (args, compile3) => {
|
|
80084
|
+
if (args.length === 0) throw new Error("Max: no argument");
|
|
80085
|
+
let r = compile3(args[0]);
|
|
80086
|
+
for (let i = 1; i < args.length; i++)
|
|
80087
|
+
r = `_iv_max(${r}, ${compile3(args[i])})`;
|
|
80088
|
+
return r;
|
|
80089
|
+
},
|
|
80090
|
+
Power: ([base, exp3], compile3) => {
|
|
80091
|
+
if (base === null || exp3 === null)
|
|
80092
|
+
throw new Error("Power: missing argument");
|
|
80093
|
+
if (isSymbol2(base, "ExponentialE")) return `_iv_exp(${compile3(exp3)})`;
|
|
80094
|
+
if (isNumber(exp3) && exp3.im === 0) {
|
|
80095
|
+
const v = exp3.re;
|
|
80096
|
+
if (v === 0.5) return `_iv_sqrt(${compile3(base)})`;
|
|
80097
|
+
if (v === 2) return `_iv_square(${compile3(base)})`;
|
|
80098
|
+
if (Number.isInteger(v) && v >= 0)
|
|
80099
|
+
return `_iv_powi(${compile3(base)}, ${formatGPUNumber(v)})`;
|
|
80100
|
+
if (!Number.isInteger(v) && v > 0)
|
|
80101
|
+
return `_iv_powf(${compile3(base)}, ${formatGPUNumber(v)})`;
|
|
80102
|
+
throw new Error(
|
|
80103
|
+
`interval-glsl: Power with exponent \`${exp3.toString()}\` is not yet supported`
|
|
80104
|
+
);
|
|
80105
|
+
}
|
|
80106
|
+
throw new Error(
|
|
80107
|
+
"interval-glsl: Power with a variable exponent is not yet supported"
|
|
80108
|
+
);
|
|
80109
|
+
}
|
|
80110
|
+
};
|
|
80111
|
+
var INTERVAL_GLSL_CONSTANTS = {
|
|
80112
|
+
Pi: "vec2(3.14159265359, 3.14159265359)",
|
|
80113
|
+
ExponentialE: "vec2(2.71828182846, 2.71828182846)",
|
|
80114
|
+
GoldenRatio: "vec2(1.61803398875, 1.61803398875)",
|
|
80115
|
+
CatalanConstant: "vec2(0.91596559417, 0.91596559417)",
|
|
80116
|
+
EulerGamma: "vec2(0.57721566490, 0.57721566490)"
|
|
80117
|
+
};
|
|
80118
|
+
var IntervalGLSLTarget = class extends GLSLTarget {
|
|
80119
|
+
languageId = "interval-glsl";
|
|
80120
|
+
getOperators() {
|
|
80121
|
+
return {};
|
|
80122
|
+
}
|
|
80123
|
+
getFunctions() {
|
|
80124
|
+
return INTERVAL_GLSL_FUNCTIONS;
|
|
80125
|
+
}
|
|
80126
|
+
getConstants() {
|
|
80127
|
+
return INTERVAL_GLSL_CONSTANTS;
|
|
80128
|
+
}
|
|
80129
|
+
createTarget(options = {}) {
|
|
80130
|
+
return super.createTarget({
|
|
80131
|
+
operators: () => void 0,
|
|
80132
|
+
functions: (id) => INTERVAL_GLSL_FUNCTIONS[id],
|
|
80133
|
+
number: (n) => `vec2(${formatGPUNumber(n)}, ${formatGPUNumber(n)})`,
|
|
80134
|
+
complex: () => {
|
|
80135
|
+
throw new Error("interval-glsl: complex values are not supported");
|
|
80136
|
+
},
|
|
80137
|
+
var: (id) => INTERVAL_GLSL_CONSTANTS[id],
|
|
80138
|
+
...options
|
|
80139
|
+
});
|
|
80140
|
+
}
|
|
80141
|
+
compile(expr2, options = {}) {
|
|
80142
|
+
const { vars } = options;
|
|
80143
|
+
const target = this.createTarget({
|
|
80144
|
+
var: (id) => {
|
|
80145
|
+
if (vars && id in vars) return vars[id];
|
|
80146
|
+
if (id in INTERVAL_GLSL_CONSTANTS) return INTERVAL_GLSL_CONSTANTS[id];
|
|
80147
|
+
return void 0;
|
|
80148
|
+
}
|
|
80149
|
+
});
|
|
80150
|
+
const code = BaseCompiler.compile(expr2, target);
|
|
80151
|
+
const result = {
|
|
80152
|
+
target: "interval-glsl",
|
|
80153
|
+
success: true,
|
|
80154
|
+
code
|
|
80155
|
+
};
|
|
80156
|
+
if (code.includes("_iv_")) result.preamble = INTERVAL_GLSL_PREAMBLE;
|
|
80157
|
+
return BaseCompiler.withReferences(
|
|
80158
|
+
result,
|
|
80159
|
+
expr2,
|
|
80160
|
+
target,
|
|
80161
|
+
vars ? new Set(Object.keys(vars)) : void 0
|
|
80162
|
+
);
|
|
80163
|
+
}
|
|
80164
|
+
/**
|
|
80165
|
+
* Emit a complete, self-contained GLSL fragment shader implementing the
|
|
80166
|
+
* **interval exclusion oracle** for the implicit curve `f = 0` (Phase 4).
|
|
80167
|
+
*
|
|
80168
|
+
* The shader is structured so the core contract — the interval evaluator —
|
|
80169
|
+
* is cleanly separable from the render harness:
|
|
80170
|
+
*
|
|
80171
|
+
* - `vec2 _implicit(<vec2 per free variable>)` evaluates the interval of `f`
|
|
80172
|
+
* over a cell box (this is the part that matters; it is identical to
|
|
80173
|
+
* `compile(expr).code` wrapped in a function).
|
|
80174
|
+
* - `main()` is a **reference harness**: it derives each fragment's cell box
|
|
80175
|
+
* from `gl_FragCoord` and the viewport uniforms, evaluates `_implicit`, and
|
|
80176
|
+
* writes the exclusion result. The renderer is free to replace `main()` /
|
|
80177
|
+
* the uniforms with its own conventions and keep `_implicit`.
|
|
80178
|
+
*
|
|
80179
|
+
* The first free variable maps to `u_domainX`, the second to `u_domainY`
|
|
80180
|
+
* (≤ 2 free variables; a 2D implicit curve). The exclusion predicate is
|
|
80181
|
+
* `f.lo > 0 || f.hi < 0` — which also excludes the `empty` (domain-undefined)
|
|
80182
|
+
* interval, since its `lo` is the `+IV_INF` sentinel.
|
|
80183
|
+
*
|
|
80184
|
+
* @throws if the expression has more than two free variables, or cannot be
|
|
80185
|
+
* lowered (an unsupported head propagates from `BaseCompiler.compile`).
|
|
80186
|
+
*/
|
|
80187
|
+
compileExclusionShader(expr2, options = {}) {
|
|
80188
|
+
const { version: version2 = "300 es", precision = "highp" } = options;
|
|
80189
|
+
const compiled = this.compile(expr2);
|
|
80190
|
+
const vars = compiled.freeSymbols ?? [];
|
|
80191
|
+
if (vars.length > 2)
|
|
80192
|
+
throw new Error(
|
|
80193
|
+
`interval-glsl exclusion shader supports at most 2 free variables (got ${vars.length}: ${vars.join(", ")})`
|
|
80194
|
+
);
|
|
80195
|
+
const params = vars.map((v) => `vec2 ${v}`).join(", ");
|
|
80196
|
+
const [axisX, axisY] = vars;
|
|
80197
|
+
const main = ["void main() {"];
|
|
80198
|
+
main.push(" vec2 _cell = gl_FragCoord.xy / u_resolution;");
|
|
80199
|
+
main.push(" vec2 _step = 1.0 / u_resolution;");
|
|
80200
|
+
const callArgs = [];
|
|
80201
|
+
if (axisX !== void 0) {
|
|
80202
|
+
main.push(" float _xlo = mix(u_domainX.x, u_domainX.y, _cell.x);");
|
|
80203
|
+
main.push(
|
|
80204
|
+
" float _xhi = mix(u_domainX.x, u_domainX.y, _cell.x + _step.x);"
|
|
80205
|
+
);
|
|
80206
|
+
callArgs.push("vec2(_xlo, _xhi)");
|
|
80207
|
+
}
|
|
80208
|
+
if (axisY !== void 0) {
|
|
80209
|
+
main.push(" float _ylo = mix(u_domainY.x, u_domainY.y, _cell.y);");
|
|
80210
|
+
main.push(
|
|
80211
|
+
" float _yhi = mix(u_domainY.x, u_domainY.y, _cell.y + _step.y);"
|
|
80212
|
+
);
|
|
80213
|
+
callArgs.push("vec2(_ylo, _yhi)");
|
|
80214
|
+
}
|
|
80215
|
+
main.push(` vec2 _f = _implicit(${callArgs.join(", ")});`);
|
|
80216
|
+
main.push(" bool _excluded = (_f.x > 0.0 || _f.y < 0.0);");
|
|
80217
|
+
main.push(
|
|
80218
|
+
" fragColor = _excluded ? vec4(0.0, 0.0, 0.0, 1.0) : vec4(1.0);"
|
|
80219
|
+
);
|
|
80220
|
+
main.push("}");
|
|
80221
|
+
return [
|
|
80222
|
+
`#version ${version2}`,
|
|
80223
|
+
`precision ${precision} float;`,
|
|
80224
|
+
"",
|
|
80225
|
+
INTERVAL_GLSL_PREAMBLE.trim(),
|
|
80226
|
+
"",
|
|
80227
|
+
"uniform vec2 u_domainX; // [min, max] for the 1st free variable",
|
|
80228
|
+
"uniform vec2 u_domainY; // [min, max] for the 2nd free variable",
|
|
80229
|
+
"uniform vec2 u_resolution; // render target size, in pixels",
|
|
80230
|
+
"",
|
|
80231
|
+
"out vec4 fragColor;",
|
|
80232
|
+
"",
|
|
80233
|
+
"// Interval evaluation of the implicit field f over a cell box.",
|
|
80234
|
+
`vec2 _implicit(${params}) {`,
|
|
80235
|
+
` return ${compiled.code};`,
|
|
80236
|
+
"}",
|
|
80237
|
+
"",
|
|
80238
|
+
main.join("\n"),
|
|
80239
|
+
""
|
|
80240
|
+
].join("\n");
|
|
80241
|
+
}
|
|
80242
|
+
};
|
|
80243
|
+
|
|
79446
80244
|
// src/compute-engine/engine-compilation-targets.ts
|
|
79447
80245
|
var CompilationTargetRegistry = class {
|
|
79448
80246
|
_targets = /* @__PURE__ */ new Map();
|
|
@@ -79465,6 +80263,7 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
|
|
|
79465
80263
|
this.register("glsl", new GLSLTarget());
|
|
79466
80264
|
this.register("wgsl", new WGSLTarget());
|
|
79467
80265
|
this.register("interval-js", new IntervalJavaScriptTarget());
|
|
80266
|
+
this.register("interval-glsl", new IntervalGLSLTarget());
|
|
79468
80267
|
}
|
|
79469
80268
|
};
|
|
79470
80269
|
|
|
@@ -79582,6 +80381,20 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
|
|
|
79582
80381
|
if (engine.strict && !isValidSymbol(name))
|
|
79583
80382
|
return engine.error(["invalid-symbol", validateSymbol(name)], name);
|
|
79584
80383
|
if (!canonical2) return new BoxedSymbol(engine, name, { metadata });
|
|
80384
|
+
if (engine._isShadowedParameter(name)) {
|
|
80385
|
+
let pdef = engine.lookupDefinition(name);
|
|
80386
|
+
if (!pdef || isValueDef(pdef) && pdef.value.isConstant) {
|
|
80387
|
+
let autoScope2 = engine.context.lexicalScope;
|
|
80388
|
+
while (autoScope2.noAutoDeclare && autoScope2.parent)
|
|
80389
|
+
autoScope2 = autoScope2.parent;
|
|
80390
|
+
pdef = engine._declareSymbolValue(
|
|
80391
|
+
name,
|
|
80392
|
+
{ type: "unknown", inferred: true },
|
|
80393
|
+
autoScope2
|
|
80394
|
+
);
|
|
80395
|
+
}
|
|
80396
|
+
return new BoxedSymbol(engine, name, { metadata, def: pdef });
|
|
80397
|
+
}
|
|
79585
80398
|
const result = commonSymbols[name];
|
|
79586
80399
|
if (result) return result;
|
|
79587
80400
|
let def = engine.lookupDefinition(name);
|
|
@@ -82267,6 +83080,24 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
|
|
|
82267
83080
|
_printStack(options) {
|
|
82268
83081
|
printStack(this, options);
|
|
82269
83082
|
}
|
|
83083
|
+
/** Stack of parameter-name sets active while canonicalizing function bodies.
|
|
83084
|
+
* @internal */
|
|
83085
|
+
_shadowedParameterStack = [];
|
|
83086
|
+
/** @internal */
|
|
83087
|
+
_pushShadowedParameters(names) {
|
|
83088
|
+
this._shadowedParameterStack.push(new Set(names));
|
|
83089
|
+
}
|
|
83090
|
+
/** @internal */
|
|
83091
|
+
_popShadowedParameters() {
|
|
83092
|
+
this._shadowedParameterStack.pop();
|
|
83093
|
+
}
|
|
83094
|
+
/** @internal */
|
|
83095
|
+
_isShadowedParameter(name) {
|
|
83096
|
+
const stack = this._shadowedParameterStack;
|
|
83097
|
+
for (let i = stack.length - 1; i >= 0; i--)
|
|
83098
|
+
if (stack[i].has(name)) return true;
|
|
83099
|
+
return false;
|
|
83100
|
+
}
|
|
82270
83101
|
/**
|
|
82271
83102
|
* Use `ce.expr(name)` instead
|
|
82272
83103
|
* @internal */
|
|
@@ -82686,7 +83517,7 @@ ${workgroupAttr}fn main(${paramStr})${returnStr} {
|
|
|
82686
83517
|
_setDefaultEngineFactory(() => new ComputeEngine());
|
|
82687
83518
|
|
|
82688
83519
|
// src/core.ts
|
|
82689
|
-
var version = "0.
|
|
83520
|
+
var version = "0.61.0";
|
|
82690
83521
|
return __toCommonJS(core_exports);
|
|
82691
83522
|
})();
|
|
82692
83523
|
/*! Bundled license information:
|