Intervals.jl
Intervals.jl copied to clipboard
Define extrema behaviour
Currently when running extrema the following behaviour occurs:
julia> x = [Interval(1,3), Interval(2,6), Interval(3,5)]
3-element Array{Intervals.Interval{Int64},1}:
[1 .. 3]
[2 .. 6]
[3 .. 5]
julia> extrema(x)
(Interval{Int64}(1, 3, Inclusivity(true, true)), Interval{Int64}(3, 5, Inclusivity(true, true)))
I would have expected the answer to have the interval with the smallest left-endpoint and the interval with the largest-right endpoint.
I think the behaviour is coming from max:
julia> max(Interval(2,6), Interval(3,5)) # Expecting `Interval(2,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))
julia> max(Interval(3,6), Interval(3,5)) # Expecting `Interval(3,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))
julia> max(Interval(2,6), Interval(3,6)) # Either?
Interval{Int64}(3, 6, Inclusivity(true, true))
julia> max(Interval(2,6), Interval(3,5)) # Expecting `Interval(2,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))
Based solely on the documentation, this one definitely looks like a bug:
The standard
<and>operators (which are not explicitly defined, but are derived fromisless) simply compare the leftmost endpoint of the intervals, and are used for things likesort,min,max, etc.
(Emphasis mine.)
julia> max(Interval(3,6), Interval(3,5)) # Expecting `Interval(3,6)`
Interval{Int64}(3, 5, Inclusivity(true, true))
This one seems acceptable per the documentation though. Perhaps the documentation should be more specific, in any case.