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

Remove piracy for == #254

Merged
merged 1 commit into from
Sep 9, 2024
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: 0 additions & 4 deletions src/init_IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ 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
Expand Down
6 changes: 6 additions & 0 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,9 @@ end
if VERSION >= v"1.3"
LinearAlgebra.UpperHessenberg(A::IntervalMatrix) = IntervalMatrix(UpperHessenberg(A.mat))
end

@static if vIA >= v"0.22"
function Base.:(==)(A::IntervalMatrix, B::IntervalMatrix)
return size(A) == size(B) && all(map((a, b) -> isequal_interval(a, b), A, B))
end
end
9 changes: 8 additions & 1 deletion test/Aqua.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ import PkgVersion, Aqua
undefined_exports = false
end

# old versions of IntervalArithmetic did not define `interval` for `Complex` inputs
@static if PkgVersion.Version(IntervalMatrices.IntervalArithmetic) >= v"0.21"
piracies = true
else
piracies = (broken=true,)
end

Aqua.test_all(IntervalMatrices; stale_deps=stale_deps, undefined_exports=undefined_exports,
# the ambiguities should be resolved in the future
ambiguities=(broken=true,),
# the piracies should be resolved in the future
piracies=(broken=true,))
piracies=piracies)
end
4 changes: 2 additions & 2 deletions test/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@test P[1, 1] ⩵ interval(2)

Q = copy(P)
@test Q == P && Q isa AffineIntervalMatrix1
@test Q P && Q isa AffineIntervalMatrix1

# complex interval
λc = λ + im * λ / 2
Expand All @@ -34,7 +34,7 @@ end
@test P[1, 1] ⩵ interval(5)

Q = copy(P)
@test Q == P && Q isa AffineIntervalMatrix
@test Q P && Q isa AffineIntervalMatrix

# complex interval
λ1c = λ1 + im * λ1 / 2
Expand Down
7 changes: 7 additions & 0 deletions test/arithmetic.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
@testset "Equality for interval matrix" begin
M = IntervalMatrix([interval(1) interval(2); interval(3) interval(4)])
@test M == IntervalMatrix([1 2; 3 4])
M = IntervalMatrix([interval(1, 2) interval(2, 3); interval(3, 4) interval(4, 5)])
@test M == M
end

@testset "Interval arithmetic" begin
a = interval(-2, -1)
b = interval(-1, 1)
Expand Down
7 changes: 0 additions & 7 deletions test/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ end
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
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@ using IntervalMatrices: _truncated_exponential_series,
# IntervalArithmetic removed interval comparison in v0.22
@static if PkgVersion.Version(IntervalMatrices.IntervalArithmetic) >= v"0.22"
⩵(x::Interval, y::Interval) = isequal_interval(x, y)

function ⩵(A::AbstractMatrix{<:Interval}, B::AbstractMatrix{<:Interval})
return size(A) == size(B) && all(map((a, b) -> ⩵(a, b), A, B))
end
else
⩵(x::Interval, y::Interval) = ==(x, y)
using IntervalMatrices: issubset_interval

⩵(A::AbstractMatrix{<:Interval}, B::AbstractMatrix{<:Interval}) = ==(A, B)
end

include("models.jl")
Expand Down
10 changes: 5 additions & 5 deletions test/setops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@
d = diam(m)
rad = radius(m)
m2 = copy(m)
@test m2 isa IntervalMatrix && m.mat == m2.mat
@test m2 isa IntervalMatrix && m.mat m2.mat
@test l == inf.(m) && r == sup.(m) && c == mid.(m)
@test d ≈ r - l
@test rad ≈ d / 2

sm = scale(m, 2.0)
@test sm == 2.0 .* m
@test sm 2.0 .* m
@test sm ≠ m
scale!(m, 2.0) # in-place
@test sm == m
@test sm m

m3 = IntervalMatrix([interval(-2, 2) interval(-2, 0); interval(0, 2) interval(-1, 1)])
m4 = IntervalMatrix([interval(-1, 1) interval(-1, 1); interval(-1, 1) interval(-2, 2)])
@test m3 ∩ m4 ==
@test m3 ∩ m4
IntervalMatrix([interval(-1, 1) interval(-1, 0); interval(0, 1) interval(-1, 1)])
@test m3 ∪ m4 ==
@test m3 ∪ m4
IntervalMatrix([interval(-2, 2) interval(-2, 1); interval(-1, 2) interval(-2, 2)])
@test diam_norm(m3) ≈ 6.0 # default diameter p-norm is Inf
@test diam_norm(m3, 1) ≈ 6.0
Expand Down
Loading