-
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
return empty interval when an invalid input is given #461
return empty interval when an invalid input is given #461
Conversation
Codecov Report
@@ Coverage Diff @@
## master #461 +/- ##
==========================================
+ Coverage 91.53% 91.56% +0.03%
==========================================
Files 25 25
Lines 1748 1755 +7
==========================================
+ Hits 1600 1607 +7
Misses 148 148
Continue to review full report at Codecov.
|
is it possible to suppress warnings during tests? I guess printing all the warnings is not very nice/useful? |
Looks like you can test the warning using |
Apparently the standard requires an empty interval to be returned when
constructing incorrect intervals. There could maybe be a flag passed to
`interval` yo specify the behaviour, but we would need to benchmark that.
…On Sat, 15 May 2021, 14:57 Luis Benet, ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/intervals/intervals.jl
<#461 (comment)>
:
> +function interval(a::T, b::S) where {T<:Real, S<:Real}
if !is_valid_interval(a, b)
- throw(ArgumentError("`[$a, $b]` is not a valid interval. Need `a ≤ b` to construct `interval(a, b)`."))
+ @warn "Invalid input, empty interval is returned"
+ return emptyinterval(promote_type(T, S, Float64))
That's precisely my point: I think using interval should throw an error,
instead of a warning, as it is proposed. This behavior could be changed for
a specific "flavor".
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#461 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABO2TUDZFT3DB2BLPABKRTTN2727ANCNFSM446CTKQA>
.
|
The current implementation of In the file
so basically |
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.
I've added few comments, some may be related to a possible type instability, which should be easy to check.
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.
LGTM!
Great! added a couple of more tests and as a far as I'm concerned, this is ready for merge now. This Should we already bump the version and release or wait a few days for the upcoming PRs? |
@@ -25,7 +25,8 @@ struct Interval{T<:Real} <: AbstractInterval{T} | |||
new(a, b) | |||
|
|||
else | |||
throw(ArgumentError("Interval of form [$a, $b] not allowed. Must have a ≤ b to construct interval(a, b).")) | |||
@warn "Invalid input, empty interval is returned" |
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.
Would it be reasonnable to never check the validity here, get rid of the validity_check
setting and document that to get IEEE compliant and thouroughly validated interval once should use either interval
or DecoratedInterval
?
Related but not directly in the scope of this PR, I wonder if it wouldn't be clearer for users to have Interval
as the default IEEE compliant one and use some trick to get an unsafe_interval
function for internal operations.
If you thing it is too tangential to the issue tackled here, I can add a separate issue.
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.
validity_check
is indeed set by default to false
and since you have functions like ..
and interval
I think it could be removed without too much harm.
The Interval
vs interval
might be an interesting discussion. One thing that puzzles me is the asymmetry of bare and decorated intervals, in the sense that for bare the constructors Interval
doesn't do any checks and you should use interval
or ..
, but for decorated intervals the constructors DecoratedIntervals
does checks (well a few issues there, next PR on the way for that :D ). I think it might be important to have a mechanism to construct "unsafe intervals" which merely puts the given inputs as lower and upper bound, at least for testing purposes. Maybe this can be addressed in a separate issue?
@@ -106,9 +97,10 @@ end | |||
|
|||
`interval(a, b)` checks whether [a, b] is a valid `Interval`, which is the case if `-∞ <= a <= b <= ∞`, using the (non-exported) `is_valid_interval` function. If so, then an `Interval(a, b)` object is returned; if not, then an error is thrown. | |||
""" | |||
function interval(a::Real, b::Real) | |||
function interval(a::T, b::S) where {T<:Real, S<:Real} |
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.
This docstring is no longer correct, it never throws an error.
Also precising that this is the way of creating IEEE compliant interval would be great.
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.
right! I had a separated PR (#460 ) for the docstrings which I had opened before this. The idea was to rebase that once this is merged and fix the docstrings there but indeed... it makes no sense! I'll close that PR and take care of the docstrings here :D
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.
updated the docstring. II think the note about IEEE compliance may be more appropriate after the package is actually IEEE compliant? what do you think?
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.
I think it is fine like that. This will be discussed in #468 where will have to sort out what we want each constructor to do anyway.
Even if the full package is not yet compliant, I think it will be good to declare our intent on which constructor corresponds to the IEEE constructors.
Thanks a lot! |
It seems that the standard requires invalid inputs to return an empty interval (see discussion in #457 ), this is also the octave behavior.
Now the package returns an empty interval but also prints a warning (like octave does), a few examples