Translate std::pow and std::max in emitted observables - #36
Merged
Conversation
The PDAC rules use both: 16 of 105 are Hill functions and two clamp with std::max. The emitter refused them, so the readouts a fit composes could not be generated at all. Both translate without an import, which is what lets one generated module serve floats, numpy and JAX tracers alike: pow becomes **, and max becomes (a + b + abs(a - b)) / 2. Arguments split on the top-level comma rather than by regex, since a Hill exponent is routinely itself a pow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PDAC assignment rules use both: 16 of 105 are Hill functions and two clamp with
std::max. The emitter refused any non-arithmetic operator, so the Python readouts an inference run composes could not be generated at all._rewrite_callsnormalises them once when rules are read, so the dependency walk, translation and emit all continue to see plain infix arithmetic:std::pow(a, b)->((a) ** (b))std::max(a, b)->_maximum(a, b), emitted as(a + b + abs(a - b)) / 2Neither form needs an import, preserving the property that one generated module works on floats, numpy arrays and JAX tracers. Arguments split on the top-level comma rather than by regex, since a Hill exponent is routinely itself a
std::pow.Genuinely untranslatable operators (comparisons, logical operators) are still refused; the existing test now covers one of those instead of
std::max.