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

#453 - Fix low/high #959

Merged
merged 2 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/lib/representations.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ dim(::Interval)
an_element(::Interval{N}) where {N<:Real}
vertices_list(::Interval{N}) where {N<:Real}
center(::Interval{N}) where {N<:Real}
low(::Interval{N}) where {N<:Real}
high(::Interval{N}) where {N<:Real}
min(::Interval{N}) where {N<:Real}
max(::Interval{N}) where {N<:Real}
radius_hyperrectangle(::Interval{N}) where {N<:Real}
radius_hyperrectangle(::Interval{N}, ::Int) where {N<:Real}
+(::Interval{N}, ::Interval{N}) where {N<:Real}
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Base.∈

export AbstractHyperrectangle,
radius_hyperrectangle,
constraints_list
constraints_list,
low, high

"""
AbstractHyperrectangle{N<:Real} <: AbstractCentrallySymmetricPolytope{N}
Expand Down
4 changes: 1 addition & 3 deletions src/Hyperrectangle.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Base.rand

export Hyperrectangle,
low,
high
export Hyperrectangle

"""
Hyperrectangle{N<:Real} <: AbstractHyperrectangle{N}
Expand Down
20 changes: 10 additions & 10 deletions src/Interval.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import IntervalArithmetic
import IntervalArithmetic: AbstractInterval
import Base: +, -, *, ∈, ⊆, rand
import Base: +, -, *, ∈, ⊆, rand, min, max

export Interval,
dim, σ, center,
low, high, vertices_list
vertices_list

"""
Interval{N<:Real, IN <: AbstractInterval{N}} <: AbstractHyperrectangle{N}
Expand Down Expand Up @@ -254,7 +254,7 @@ function ∈(v::N, x::Interval{N}) where {N<:Real}
end

"""
low(x::Interval{N})::N where {N<:Real}
min(x::Interval{N})::N where {N<:Real}

Return the lower component of an interval.

Expand All @@ -266,12 +266,12 @@ Return the lower component of an interval.

The lower (`lo`) component of the interval.
"""
function low(x::Interval{N})::N where {N<:Real}
function min(x::Interval{N})::N where {N<:Real}
return x.dat.lo
end

"""
high(x::Interval{N})::N where {N<:Real}
max(x::Interval{N})::N where {N<:Real}

Return the higher or upper component of an interval.

Expand All @@ -283,7 +283,7 @@ Return the higher or upper component of an interval.

The higher (`hi`) component of the interval.
"""
function high(x::Interval{N})::N where {N<:Real}
function max(x::Interval{N})::N where {N<:Real}
return x.dat.hi
end

Expand All @@ -298,10 +298,10 @@ Return some element of an interval.

### Output

The left border (`low(x)`) of the interval.
The left border (`min(x)`) of the interval.
"""
function an_element(x::Interval{N})::Vector{N} where {N<:Real}
return [low(x)]
return [min(x)]
end

"""
Expand Down Expand Up @@ -354,7 +354,7 @@ Return the list of vertices of this interval.
The list of vertices of the interval represented as two one-dimensional vectors.
"""
function vertices_list(x::Interval{N})::Vector{Vector{N}} where {N<:Real}
return [[low(x)], [high(x)]]
return [[min(x)], [max(x)]]
end


Expand All @@ -377,7 +377,7 @@ The box radius in the given dimension.
"""
function radius_hyperrectangle(x::Interval{N}, i::Int)::N where {N<:Real}
@assert i == 1 "an interval is one-dimensional"
return (high(x) - low(x)) / N(2)
return (max(x) - min(x)) / N(2)
end

"""
Expand Down
4 changes: 2 additions & 2 deletions src/concrete_intersection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ Otherwise the result is the interval that describes the intersection.
function intersection(x::Interval{N},
y::Interval{N}
)::Union{Interval{N}, EmptySet{N}} where {N<:Real}
if low(y) > high(x) || low(x) > high(y)
if min(y) > max(x) || min(x) > max(y)
return EmptySet{N}()
else
return Interval(max(low(x), low(y)), min(high(x), high(y)))
return Interval(max(min(x), min(y)), min(max(x), max(y)))
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Hyperrectangle{Float64}([0.5], [0.5])
```
"""
function convert(::Type{Hyperrectangle}, x::Interval)
return Hyperrectangle(low=[low(x)], high=[high(x)])
return Hyperrectangle(low=[min(x)], high=[max(x)])
end

"""
Expand Down
4 changes: 2 additions & 2 deletions src/plot_recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ julia> plot(I);
markershape --> (add_marker ? :circle : :none)
markercolor --> color

[Tuple([low(I), 0.0]); Tuple([high(I), 0.0])]
[Tuple([min(I), 0.0]); Tuple([max(I), 0.0])]
end

"""
Expand Down Expand Up @@ -519,6 +519,6 @@ julia> plot([I1, I2]);
markercolor --> color

for Ii in Xk
@series [Tuple([low(Ii), 0.0]); Tuple([high(Ii), 0.0])]
@series [Tuple([min(Ii), 0.0]); Tuple([max(Ii), 0.0])]
end
end
10 changes: 5 additions & 5 deletions test/unit_Interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ for N in [Float64, Float32, Rational{Int}]

@test dim(x) == 1
@test center(x) == N[0.5]
@test low(x) == N(0) && high(x) == N(1)
@test min(x) == N(0) && max(x) == N(1)
v = vertices_list(x)
@test N[0] in v && N[1] in v
# test interface method an_element and membership
Expand All @@ -35,7 +35,7 @@ for N in [Float64, Float32, Rational{Int}]
@test dim(m) == 1
@test σ(N[1], m) == N[1.5]
@test σ(N[-1], m) == N[-2]
@test low(m) == N(-2) && high(m) == N(1.5)
@test min(m) == N(-2) && max(m) == N(1.5)
v = vertices_list(m)
@test N[1.5] in v && N[-2] in v

Expand All @@ -44,7 +44,7 @@ for N in [Float64, Float32, Rational{Int}]
@test dim(d) == 1
@test σ(N[1], d) == N[3]
@test σ(N[-1], d) == N[-0.5]
@test low(d) == N(-0.5) && high(d) == N(3)
@test min(d) == N(-0.5) && max(d) == N(3)
v = vertices_list(d)
@test N[-0.5] in v && N[3] in v

Expand All @@ -58,7 +58,7 @@ for N in [Float64, Float32, Rational{Int}]

# test different arithmetic operations
r = (x + y) - (d + p)
@test low(r) == N(-5.5) && high(r) == N(4)
@test min(r) == N(-5.5) && max(r) == N(4)

# isempty
@test !isempty(x)
Expand All @@ -84,7 +84,7 @@ for N in [Float64, Float32, Rational{Int}]
B = Interval(N(3), N(6))
C = intersection(A, B)
@test C isa Interval
@test low(C) == N(5) && high(C) == N(6)
@test min(C) == N(5) && max(C) == N(6)
# check empty intersection
E = intersection(A, Interval(N(0), N(1)))
@test isempty(E)
Expand Down