-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,13 +50,27 @@ for f ∈ (:min, :max) | |
isempty_interval(y) && return y | ||
return _unsafe_bareinterval(T, $f(inf(x), inf(y)), $f(sup(x), sup(y))) | ||
end | ||
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 | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. |
||
|
||
function Base.$f(x::Interval, y::Interval) | ||
r = $f(bareinterval(x), bareinterval(y)) | ||
d = min(decoration(x), decoration(y)) | ||
t = isguaranteed(x) & isguaranteed(y) | ||
return _unsafe_interval(r, d, t) | ||
end | ||
|
||
function Base.$f(x::Interval, y::Rational) | ||
r = $f(bareinterval(x), y) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. On the latest version of IntervalArithmetic.jl, |
||
end | ||
end | ||
|
||
Base.clamp(i::Interval, lo, hi) = min(max(i, lo), hi) |
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
andNumber
in their computations, becauseBareInterval
cannot keep track of guarantees ("NG" flag)or decorations.So my first impulse here would be not to define such function.