Skip to content
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

Merged
merged 7 commits into from
Jun 2, 2021

Conversation

lucaferranti
Copy link
Member

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

julia> 3..1
┌ Warning: Invalid input, empty interval is returned
└ @ IntervalArithmetic C:\Users\lucaa\.julia\dev\IntervalArithmetic\src\intervals\intervals.jl:107
∅

julia> interval(Inf, Inf)
┌ Warning: Invalid input, empty interval is returned
└ @ IntervalArithmetic C:\Users\lucaa\.julia\dev\IntervalArithmetic\src\intervals\intervals.jl:107
∅

julia> interval(NaN, π)
┌ Warning: Invalid input, empty interval is returned
└ @ IntervalArithmetic C:\Users\lucaa\.julia\dev\IntervalArithmetic\src\intervals\intervals.jl:107
∅

julia> @decorated 3 1
[NaN, NaN]_ill

julia> @decorated NaN 3
[NaN, NaN]_ill

julia> @decorated Inf Inf
[NaN, NaN]_ill

julia> @decorated Inf -Inf
∅_trv
```

@codecov-commenter
Copy link

codecov-commenter commented May 15, 2021

Codecov Report

Merging #461 (73cc938) into master (65ca77f) will increase coverage by 0.03%.
The diff coverage is 91.30%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/intervals/intervals.jl 92.18% <89.47%> (+0.66%) ⬆️
src/decorations/intervals.jl 84.78% <100.00%> (ø)
src/intervals/special.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 65ca77f...73cc938. Read the comment docs.

@lucaferranti
Copy link
Member Author

is it possible to suppress warnings during tests? I guess printing all the warnings is not very nice/useful?

@lucaferranti lucaferranti changed the title Lf/invalid as empty return empty interval when an invalid input is given May 15, 2021
@lucaferranti lucaferranti linked an issue May 15, 2021 that may be closed by this pull request
src/intervals/intervals.jl Outdated Show resolved Hide resolved
@dpsanders
Copy link
Member

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 @test_logs

@dpsanders
Copy link
Member

dpsanders commented May 15, 2021 via email

@lucaferranti lucaferranti mentioned this pull request May 27, 2021
16 tasks
@lucaferranti lucaferranti linked an issue May 29, 2021 that may be closed by this pull request
@lucaferranti
Copy link
Member Author

The current implementation of .. was calling atomic before checking the validity of the input, the commit above this message fixes it.

In the file ieee1788-exceptions.itl of the ITL testsuite there is a test

b-numsToInterval +infinity -infinity = [empty] signal UndefinedOperation;

so basically interval(Inf, -Inf) should return the empty interval and flag a warning.I modified the definition of is_valid_interval to be conformant to this, but personally I think printing the warning in this case is a little redundant, since [Inf, -Inf] is the representation of the empty interval, opinions on this?

Copy link
Member

@lbenet lbenet left a 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.

src/intervals/intervals.jl Show resolved Hide resolved
src/intervals/intervals.jl Show resolved Hide resolved
src/intervals/intervals.jl Outdated Show resolved Hide resolved
src/intervals/intervals.jl Outdated Show resolved Hide resolved
src/intervals/intervals.jl Outdated Show resolved Hide resolved
Copy link
Member

@lbenet lbenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lucaferranti
Copy link
Member Author

Great! added a couple of more tests and as a far as I'm concerned, this is ready for merge now. This fixes step 6 of #465 .
I am next going to fix the constructors for decorated intervals (steps 4 and 10 of #465 ) and next investigate the parsing of strings.

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"
Copy link
Collaborator

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.

Copy link
Member Author

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}
Copy link
Collaborator

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.

Copy link
Member Author

@lucaferranti lucaferranti May 31, 2021

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

Copy link
Member Author

@lucaferranti lucaferranti Jun 1, 2021

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?

Copy link
Collaborator

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.

@Kolaru Kolaru merged commit c7602f4 into JuliaIntervals:master Jun 2, 2021
@Kolaru
Copy link
Collaborator

Kolaru commented Jun 2, 2021

Thanks a lot!

@lucaferranti lucaferranti deleted the lf/invalid_as_empty branch June 2, 2021 06:18
@lbenet lbenet mentioned this pull request Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should Interval(Inf, Inf) give the empty set? Inconsistent errors when constructing intervals with NaN bound
5 participants