LogExpFunctions.jl icon indicating copy to clipboard operation
LogExpFunctions.jl copied to clipboard

logaddexp introduces NaNs for non-finite values

Open tpapp opened this issue 3 years ago • 1 comments

julia> using ForwardDiff, LogExpFunctions

julia> x = ForwardDiff.Dual(-Inf, 0.0)
Dual{Nothing}(-Inf,0.0)

julia> logaddexp(x, x)
Dual{Nothing}(-Inf,NaN)

I think this is related to JuliaDiff/ForwardDiff.jl#481.

It is the a == b in logaddexp, but I am not yet sure how to elegantly special-case this.

tpapp avatar Nov 23 '22 13:11 tpapp

Conceptually, I would be OK with logaddexp(a, b) === b whenever a <= -Inf, after suitable promotion, and similarly of course for the arguments exchanged. This is the only one I would care to special-case, the rest can (and should) just propagate Inf and NaN.

tpapp avatar Nov 23 '22 15:11 tpapp