JuliaDiff / JuliaDiff/ForwardDiff.jl
Dual for max when values agree?
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
The partial derivative of max currently uses the Julia Base implementation:
max(x,y) = ifelse(y < x, x, y)
Unfortunately, this may cause incorrect results when the Dual values agree but the partials do not:
max(Dual(3,1), Dual(3,-1))
Here, the values are both 3 but the partials have opposite signs. I think the partial here may be undefined.
Maybe something like:
function Base.max(a::Dual, b::Dual)
if value(a) > value(b)
return a
elseif value(a) < value(b)
return b
else # value(a) == value(b)
return ifelse(epsilon(a) == epsilon(b), a, Dual(value(a), NaN))
end
end
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing max(Dual(3,1), Dual(3,-1)) and reading Julia Base's max behavior described in the issue. Determine the intended result when values agree but partials differ, then add coverage for the agreed behavior and verify the existing Dual max cases still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100