Add EnzymeGammaExt with analytic derivative rule for Gamma.gamma#3298
Open
oschulz wants to merge 1 commit into
Open
Add EnzymeGammaExt with analytic derivative rule for Gamma.gamma#3298oschulz wants to merge 1 commit into
oschulz wants to merge 1 commit into
Conversation
Created by generative AI.
Contributor
Author
|
Should I reduce/remove the AI code comments? |
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.
Claude Opus (max effort) says:
HypergeometricFunctions v0.3.29 switched its
gammaimport fromSpecialFunctions to the Gamma package. Unlike SpecialFunctions.gamma
(a ccall to tgamma), Gamma.gamma is a pure-Julia Cephes implementation
with internal
whileloops. When it is inlined into a larger reverse-modegradient -- e.g. logpdf(truncated(Beta(a,b),lo,hi), x) differentiated
w.r.t. the shape parameters, which routes through the Beta CDF and the
2F1 hypergeometric function -- Enzyme cannot rematerialize the loop and
fails in libEnzyme with an internal "ficticious phi" recompute error.
This is what breaks the "truncated Beta" case of the Distributions
integration test on Julia 1.10.
Add a Gamma package extension supplying the analytic derivative
d/dx gamma(x) = gamma(x) * digamma(x), so Enzyme differentiates the
closed form instead of descending into the loops. This mirrors the
existing special-function rules (e.g. _logabsgamma, beta_inc).
Add test/ext/gamma.jl covering the scalar derivative across every branch
of the implementation and the previously-failing in-context 2F1 case.