Don't widen the primal when differentiating x^y with a real base#824
Open
antoine-levitt wants to merge 1 commit into
Open
Don't widen the primal when differentiating x^y with a real base#824antoine-levitt wants to merge 1 commit into
x^y with a real base#824antoine-levitt wants to merge 1 commit into
Conversation
`2^x` is `Float32` for a `Float32` `x`, but `2^Dual{T,Float32,N}` came back
`Dual{T,Float64,N}`: `expv = x^v` honours Base's promotion, while `log(x)` was
evaluated from `x` alone, so an integer base gave a Float64 partial and the
`Dual` constructor unified value and partials upward. Differentiating should
not change the primal's type.
Take the log in `expv`'s type instead, which is the promotion `^` already chose
for this base/exponent pair. Float64 results are bit-identical; only bases
narrower than the exponent's own promotion (e.g. `Integer`) change, and only in
type. `NaNMath.pow` shares the definition and is fixed too.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017an8Gie5b1ULeSjhep3Sjb
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #824 +/- ##
=======================================
Coverage 90.74% 90.74%
=======================================
Files 11 11
Lines 1070 1070
=======================================
Hits 971 971
Misses 99 99 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
2^xisFloat32for aFloat32x, but2^Dual{T,Float32,N}came backDual{T,Float64,N}. Came up on JuliaMolSim/DftFunctionals.jl#33