-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #237 from JuliaReach/schillic/tests
Outsource init code and add tests for IntervalArithmetic; unsupport :fast multiplication
- Loading branch information
Showing
7 changed files
with
179 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@reexport using IntervalArithmetic | ||
import IntervalArithmetic: inf, sup, mid, diam, radius, hull | ||
|
||
@static if VERSION >= v"1.9" | ||
vIA = pkgversion(IntervalArithmetic) | ||
else | ||
import PkgVersion | ||
vIA = PkgVersion.Version(IntervalArithmetic) | ||
end | ||
|
||
@static if vIA >= v"0.22" | ||
import Base: intersect | ||
export ±, midpoint_radius # not exported by IntervalArithmetic anymore | ||
|
||
function Base.:(==)(A::AbstractMatrix{<:Interval}, B::AbstractMatrix{<:Interval}) | ||
return size(A) == size(B) && all(map((a, b) -> isequal_interval(a, b), A, B)) | ||
end | ||
else # vIA < v"0.22" | ||
# COV_EXCL_START | ||
import IntervalArithmetic: ±, midpoint_radius | ||
|
||
issubset_interval(x::Interval, y::Interval) = issubset(x, y) | ||
|
||
in_interval(x::Number, y::Interval) = inf(y) <= x <= sup(y) | ||
|
||
intersect_interval(a::Interval, b::Interval) = intersect(a, b) | ||
|
||
if vIA >= v"0.21" | ||
# `convert` was temporarily removed in IntervalArithmetic v0.21 until v0.22 | ||
Base.convert(::Type{Interval{T}}, x::Number) where {T} = interval(T(x)) | ||
Base.convert(::Type{Interval{T}}, x::Interval{T}) where {T} = x | ||
function Base.convert(::Type{Interval{T1}}, x::Interval{T2}) where {T1,T2} | ||
return interval(T1(inf(x)), T1(sup(x))) | ||
end | ||
else # vIA < v"0.21" | ||
# IntervalArithmetic v0.21 requires `interval`, but prior versions did not | ||
# offer this method for `Complex` inputs | ||
IntervalArithmetic.interval(a::Complex) = complex(interval(real(a)), interval(imag(a))) | ||
end | ||
# COV_EXCL_STOP | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# =============================================== | ||
# helper methods for IntervalArithmetic interface | ||
# =============================================== | ||
using IntervalMatrices: intersect_interval, in_interval, issubset_interval | ||
|
||
@testset "Interval conversion" begin | ||
x = convert(Interval{Float64}, 1.0) | ||
|
||
y = convert(Interval{Float64}, x) | ||
# `===` is not applicable here because it just checks value equivalence | ||
# for (immutable) `Interval`s | ||
@test y ⩵ x && y isa Interval{Float64} | ||
|
||
y = convert(Interval{Float32}, x) | ||
@test y ⩵ x && y isa Interval{Float32} | ||
end | ||
|
||
@testset "Interval operation `intersect_interval`" begin | ||
x = interval(1, 3) | ||
for y in (interval(2, 4), interval(2f0, 4f0)) | ||
@test intersect_interval(x, y) ⩵ interval(2, 3) | ||
end | ||
@test intersect_interval(x, x) ⩵ x | ||
for y in (interval(4, 5), interval(4f0, 5f0)) | ||
@test intersect_interval(x, y) ⩵ emptyinterval(Float64) | ||
end | ||
end | ||
|
||
@testset "Interval operation `in_interval`" begin | ||
x = interval(1, 3) | ||
for e in (1, 2.0, 3) | ||
@test in_interval(e, x) | ||
end | ||
for e in (0, 0.999, 3.001, 4) | ||
@test !in_interval(e, x) | ||
end | ||
end | ||
|
||
@testset "Interval operation `issubset_interval`" begin | ||
x = interval(1, 3) | ||
for y in (interval(0, 4), x) | ||
@test issubset_interval(x, y) | ||
end | ||
for y in (interval(2, 4), interval(0, 2), interval(2)) | ||
@test !issubset_interval(x, y) | ||
end | ||
end | ||
|
||
@testset "Equality for `Interval` matrix" begin | ||
M = [interval(1) interval(2); interval(3) interval(4)] | ||
@test M == [1 2; 3 4] | ||
M = [interval(1, 2) interval(2, 3); interval(3, 4) interval(4, 5)] | ||
@test M == M | ||
end | ||
|
||
@testset "Interval from a complex number" begin | ||
@test interval(1+2im) isa Complex{Interval{Float64}} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters