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

Support intervals endpoints using infinity #99

Merged
merged 7 commits into from
Jun 4, 2020
Merged

Support intervals endpoints using infinity #99

merged 7 commits into from
Jun 4, 2020

Conversation

omus
Copy link
Collaborator

@omus omus commented Jun 3, 2020

Adapted from #95. Takes the, hopefully, non-controversial parts of that PR and uses the Float64 infinity to validate the changes.

@fchorney doing this allowed me to go very carefully through your tests. I've removed a few of them that are redundant with those which are in comparison.jl and some were re-worked to avoid code duplication.

@@ -136,46 +150,56 @@
for i in 0:3
interval = Interval(a, b, Inclusivity(i))
cp = copy(interval)
lesser_val = Interval(a - unit, b + unit, Inclusivity(i))
lesser_val = Interval(a - unit, b - unit, Inclusivity(i))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Change isn't required but I think it makes it clearer that this interval is always less than the original

@codecov
Copy link

codecov bot commented Jun 3, 2020

Codecov Report

Merging #99 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #99      +/-   ##
==========================================
+ Coverage   96.55%   96.60%   +0.05%     
==========================================
  Files           7        7              
  Lines         261      265       +4     
==========================================
+ Hits          252      256       +4     
  Misses          9        9              
Impacted Files Coverage Δ
src/interval.jl 97.24% <100.00%> (+0.10%) ⬆️

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 99abb65...0ba8425. Read the comment docs.

right = min(RightEndpoint(a), RightEndpoint(b))

return Interval(left, right)
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll note this implementation could probably replace the intersect(::AbstractInterval{T}, ::AbstractInterval{T}) defined above this

Copy link
Member

Choose a reason for hiding this comment

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

when you define a function with S, and T does julia enforce that it will only be called if S and T are different? or can they be the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As there is no constraint between them they can be anything including the same. Since there a more specific definition where they have to be the same then this method will only be called when the are different.

@@ -550,11 +575,11 @@
Interval(-100, -1, Inclusivity(false, false)),
Interval(-10, -1, Inclusivity(false, false)),
Interval(10, 15, Inclusivity(false, false)),
Interval(13, 20, Inclusivity(false, false))
Interval(13, 20, Inclusivity(false, false)),
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to add infinity to the union tests? or make another union test with inf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Union test for infinity are included in the comparison tests

test/interval.jl Outdated
@@ -1,10 +1,20 @@
Base.isinf(x::Char) = false
Base.isinf(x::TimeType) = false
Copy link
Contributor

Choose a reason for hiding this comment

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

piracy?

Copy link
Contributor

Choose a reason for hiding this comment

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

could there at least be a comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely, it's just for tests though so it's not a big deal

Copy link
Contributor

Choose a reason for hiding this comment

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

should we just define and use our own _isinf?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I may open a PR to get isinf(::TimeType) implemented but I very much doubt I would get a PR for isinf(::Char) accepted

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If this really bothers people I can do:

_isinf(x) = isinf(x)
_isinf(::Char) = false
_isinf(::TimeType) = false

Copy link
Contributor

Choose a reason for hiding this comment

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

i'd slightly prefer that as it make the code easier to follow (to my eyes) as it make clearly we've added some particulars for our use-case

Copy link
Collaborator Author

@omus omus Jun 4, 2020

Choose a reason for hiding this comment

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

How about another compromise?

isinf(x) = Base.isinf(x)
isinf(::Char) = false
isinf(::TimeType) = false

Avoids type piracy by declaring a new isinf

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Something similar: https://github.com/invenia/Intervals.jl/pull/104/files#r444362741. We could actually have a generic isinf implemented as:

isinf(x) = !isfinite(x) && !isnan(x)
isfinite(x) = iszero(x - x)
isnan(x) = x != x

The only issue I see with this is that the generic isnan may not always hold for all types

Copy link
Contributor

@nicoleepp nicoleepp left a comment

Choose a reason for hiding this comment

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

LGTM

@omus omus merged commit b229a69 into master Jun 4, 2020
@omus omus deleted the cv/inf-support branch June 4, 2020 19:14
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.

4 participants