-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for clamp and min, max, clamp with ForwardDiff #642
base: master
Are you sure you want to change the base?
Conversation
function Base.$f(x::BareInterval{T}, y::Rational) where {T<:NumTypes} | ||
isempty_interval(x) && return x | ||
return _unsafe_bareinterval(T, $f(inf(x), y), $f(sup(x), y)) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We purposely do not allow functions mixing BareInterval
and Number
in their computations, because BareInterval
cannot keep track of guarantees ("NG" flag)or decorations.
So my first impulse here would be not to define such function.
Base.$f(x::BareInterval, y::BareInterval) = $f(promote(x, y)...) | ||
Base.$f(x::BareInterval, y::Rational) = $f(promote(x), y) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
d = decoration(x) | ||
return _unsafe_interval(r, d, false) | ||
end | ||
Base.$f(x::Rational, y::Interval) = $f(y, x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the latest version of IntervalArithmetic.jl, min
and max
already do this ; so defining these functions is maybe superfluous here ? Or am I missing something ?
Thx for opening the PR! I have to think a bit more about the decoration requirement. This may be a little more subtle. @Kolaru don't you think we will run into the same issue as we did with the derivative of |
In term of decorations, for consistency we must have:
|
Based on the discussion in #640, we (@mossr, @ancorso, @mykelk) have implemented the following:
min
andmax
when one input is an interval and the other is a floatclamp
min
,max
, andclamp
when computing first and second derivatives with ForwardDiff