-
Notifications
You must be signed in to change notification settings - Fork 18
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
Restrict arguments to Number in comparisons between scalars and EndPoint #143
base: master
Are you sure you want to change the base?
Conversation
I think I spoke too soon, I see that Intervals are expected, at least from the tests, to work with things like |
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.
Currently the only restriction the element type of Interval
and AnchoredInterval
is that the eltype must be comparable with isless
. We may be able to get away with using promotion to convert a scalar (x
) into a closed-interval (Interval(x, x)
) which could work around the method invalidations by not having to define some of these methods. I suspect there will be a performance hit in doing this though.
src/endpoint.jl
Outdated
Base.:(==)(a::Number, b::Endpoint) = a == b.endpoint && isclosed(b) | ||
Base.:(==)(a::Endpoint, b::Number) = b == a |
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'm pretty sure we can update this to be this safely (tests will show if that is the case):
Base.:(==)(a::Number, b::Endpoint) = a == b.endpoint && isclosed(b) | |
Base.:(==)(a::Endpoint, b::Number) = b == a | |
Base.:(==)(a::T, b::Endpoint{T}) where T = a == b.endpoint && isclosed(b) | |
Base.:(==)(a::Endpoint{T}, b::T) where T = b == a |
I'm not sure these are actually used so we may be able to just drop them.
f4c1399
to
fe0a755
Compare
Codecov Report
@@ Coverage Diff @@
## master #143 +/- ##
=======================================
Coverage 75.76% 75.76%
=======================================
Files 11 11
Lines 491 491
=======================================
Hits 372 372
Misses 119 119
Continue to review full report at Codecov.
|
From code coverage, it looks like some of the new definitions are not used in the tests and we might get away with removing them. For others, it might be better to add code tests paths. I'm not sure how does this look for someone more familiar with direct use cases of the package (I have only use it through other packages that have it as dependency). |
I'm looking into alternative approaches. I think we may be able to fix Base code such the |
That's great. I guess I will remove the arithmetic code changes. Yes, a custom scalar conversion function sounds sensible, but is probably better done in another PR. |
Looking at some packages invalidations, I found some introduced by this one. As far as I can see, much of these methods aren't supposed to work for things other than
Number
s so I think these all should be harmless.