-
Notifications
You must be signed in to change notification settings - Fork 28
Add open and mixed open/closed intervals #26
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
Conversation
@timholy This is ready for review. |
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.
Seems okay to me other than the couple of things I noted.
src/IntervalSets.jl
Outdated
@@ -4,29 +4,73 @@ module IntervalSets | |||
|
|||
using Base: @pure | |||
import Base: eltype, convert, show, in, length, isempty, isequal, issubset, ==, hash, | |||
union, intersect, minimum, maximum, extrema, range, ⊇ | |||
union, intersect, minimum, maximum, extrema, range, ⊇, mean, median |
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.
In Julia 0.7, mean
and median
are in the Statistics stdlib package. So instead of adding them here, you could add
import Compat.Statistics: mean, median
Just make sure that REQUIRE has an appropriate lower bound for Compat in that case.
src/IntervalSets.jl
Outdated
end | ||
|
||
mean(d::AbstractInterval) = one(eltype(d))/2 * (leftendpoint(d) + rightendpoint(d)) | ||
median(d::AbstractInterval) = mean(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.
I'm not sure about this definition. Typically (not always, granted) the median of some set is an element of the set, but that isn't guaranteed when using a mean. Maybe this is fine, I dunno.
src/IntervalSets.jl
Outdated
b | ||
end | ||
|
||
mean(d::AbstractInterval) = one(eltype(d))/2 * (leftendpoint(d) + rightendpoint(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.
Is the one
part needed here? Couldn't you just write this as
(leftendpoint(d) + rightendpoint(d)) / 2
?
…ically for this • AbstractInfiniteSet -> Domain • deprecate length in favour of duration
@ararslan I've addressed your comments, and just removed
|
Looks good to me, but I'm not a primary maintainer of this package, so it'd be good to hear from someone else as well before merging. |
We can always chat next week about it... |
Is |
Personally I prefer the clarity of |
@timholy I mentioned this PR at JuliaCon. Do you have time to review it now? (Still no rush on my part but a revamp of domains in ApproxFun.jl is waiting on this.) |
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.
Sorry I forgot about this. It looks fantastic! Tiny comments, neither of which is necessary.
In other words, merge at will. If you are (justifiably) annoyed by the delay, I can help fix those merge conflicts. Just let me know. |
That's OK, I've resolved the conflicts, though you might have comments on the changes I made:
UnitRange{T}(i::TypedEndpointsInterval{:closed,:closed,I}) where {T<:Integer,I<:Integer} = UnitRange{T}(minimum(i), maximum(i))
UnitRange(i::TypedEndpointsInterval{:closed,:closed,I}) where {I<:Integer} = UnitRange{I}(i)
|
On my phone. See my recent PR to Base re issubset. Can't really check rest
now, you are authorized to decide😀
…On Sat, Sep 1, 2018, 8:39 AM Sheehan Olver ***@***.***> wrote:
That's OK, I've resolved the conflicts, though you might have comments on
the changes I made:
1. I removed the general AbstractUnitRange conversion because it
seemed to broad, in favour of specific ones:
UnitRange{T}(i::TypedEndpointsInterval{:closed,:closed,I}) where {T<:Integer,I<:Integer} = UnitRange{T}(minimum(i), maximum(i))UnitRange(i::TypedEndpointsInterval{:closed,:closed,I}) where {I<:Integer} = UnitRange{I}(i)
1. I added convert(AbstractInterval, x::Number) and variants
2. I overrode issubset, as the existing definition called the now
deprecated length.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABdG6e1ZaYls6XNKD2UV4ZIUspZDGOLvks5uWo3_gaJpZM4SwYH_>
.
|
Having looked again I think your taste in these matters was exquisite. I really like the distinction you made in the comments between conversion and construction, I'm going to be more deliberate about that in the future. The override for |
# convert numbers to intervals | ||
convert(::Type{AbstractInterval}, x::Number) = x..x | ||
convert(::Type{AbstractInterval{T}}, x::Number) where T = | ||
convert(AbstractInterval{T}, convert(AbstractInterval, x)) | ||
convert(::Type{TypedEndpointsInterval{:closed,:closed}}, x::Number) = x..x | ||
convert(::Type{TypedEndpointsInterval{:closed,:closed,T}}, x::Number) where T = | ||
convert(AbstractInterval{T}, convert(AbstractInterval, x)) | ||
convert(::Type{ClosedInterval}, x::Number) = x..x | ||
convert(::Type{ClosedInterval{T}}, x::Number) where T = | ||
convert(AbstractInterval{T}, convert(AbstractInterval, x)) |
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.
Do we need these conversion methods? x-ref:#97
This PR adds support for general closed/open endpoints.
It also makes the following changes which I believe are necessary:
union(a .. b, nextfloat(b) .. c)
now throws an error (fora < b < c
): this is consistent with the fact thatunion(0 .. 1, 2..3)
should not be0 .. 3
, and becausePreviously
x in union(a .. b, nextfloat(b) .. c)
returned true, which is inconsistent with the above!2.
convert(UnitRange, 0..1)
is now deprecated in favour ofUnitRange(0..1)
, asconvert
should throw an error (e.g.convert(Int, 1+Im)
throws an error).