fix: make circular ell_comps image gradients finite - #571
Merged
Conversation
This was referenced Aug 14, 2026
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.
Summary
ell_comps, avoiding the undefined polar angle derivative at(0, 0)fac <= 0.999clamp and transformed-grid compatibilityCloses #570.
Why
The profiling hazard
likelihood.imaging-sersic.ell-comps-origin-nonfinite-gradientshowed a finite off-centre Sersic image and completeFitImaginglikelihood at the circular point, but a[NaN, NaN]JAX gradient. The sampled parameters are Cartesianell_comps_0/1; converting them to axis ratio and angle introduces an avoidable polar singularity.The new radius identity remains in Cartesian coordinates:
where
f^2=e_y^2+e_x^2after the existing magnitude clamp.Validation
1.46e-15across circular, anisotropic, rotated, and near-clamped casesjit(grad)image probe atell_comps=(0, 0): finite; central differences at1e-4,1e-5, and1e-6agreeFitImaginglikelihood: value unchanged at-15.477240141252718; origin gradient now finite at[1.1569945714414, -0.5449763942867472]; all ±1e-8and ±1e-6neighbourhood gradients finiteNo public API, prior, configuration, or release change.