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

Add "in" for IntervalBox #244

Merged
merged 8 commits into from
Dec 8, 2018
Merged
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
2 changes: 1 addition & 1 deletion src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ import Base:
union, intersect, isempty,
convert, promote_rule, eltype, size,
BigFloat, float, widen, big,
∩, ∪, ⊆, ⊇, eps,
∩, ∪, ⊆, ⊇, ∈, eps,
floor, ceil, trunc, sign, round,
expm1, log1p,
precision,
3 changes: 3 additions & 0 deletions src/intervals/complex.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

⊆(x::Complex{Interval{T}}, y::Complex{Interval{T}}) where T = real(x) ⊆ real(y) && imag(x) ⊆ imag(y)

function ^(x::Complex{Interval{T}}, n::Integer) where {T}
if n < 0
return inv(x)^n
2 changes: 2 additions & 0 deletions src/intervals/set_operations.jl
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ function in(x::T, a::Interval) where T<:Real
a.lo <= x <= a.hi
end

in(x::Interval, y::Interval) = throw(ArgumentError("$x ∈ $y is not defined"))

in(x::T, a::Complex{<:Interval}) where T<:Real = x ∈ real(a) && 0 ∈ imag(a)
in(x::Complex{T}, a::Complex{<:Interval}) where T<:Real = real(x) ∈ real(a) && imag(x) ∈ imag(a)

4 changes: 4 additions & 0 deletions src/multidim/intervalbox.jl
Original file line number Diff line number Diff line change
@@ -67,6 +67,10 @@ big(X::IntervalBox) = big.(X)
∪(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) where {N,T} =
IntervalBox(X.v .∪ Y.v)

∈(X::AbstractVector, Y::IntervalBox{N,T}) where {N,T} = all(X .∈ Y)
∈(X, Y::IntervalBox{N,T}) where {N,T} = throw(ArgumentError("$X ∈ $Y is not defined"))


#=
On Julia 0.6 can now write
∩{N,T}(X::IntervalBox{N,T}, Y::IntervalBox{N,T}) = IntervalBox(NTuple{N, Interval{Float64}}( (X[i] ∩ Y[i]) for i in 1:N))
2 changes: 2 additions & 0 deletions test/interval_tests/consistency.jl
Original file line number Diff line number Diff line change
@@ -83,6 +83,8 @@ setprecision(Interval, Float64)
@test 0.1 in @interval(0.1)
@test !(-Inf ∈ entireinterval())
@test !(Inf ∈ entireinterval())

@test_throws ArgumentError (3..4) ∈ (3..4)
end

@testset "Inclusion tests" begin
14 changes: 14 additions & 0 deletions test/multidim_tests/multidim.jl
Original file line number Diff line number Diff line change
@@ -218,4 +218,18 @@ end
@test diam.(X) == SVector(diam(X[1]), diam(X[2]))
end

@testset "∈" begin
X = IntervalBox(3..4, 5..6)
@test mid(X) ∈ X
@test mid(X, 0.75) ∈ X

@test (zero(mid(X)) ∈ X) == false
@test zero(mid(X)) ∉ X

@test_throws ArgumentError (3..4) ∈ X

@test_throws ArgumentError [3..4, 5..6] ∈ X

end

end