From 3bfff53749fd467082bd6e9dcc8ed606e7f54cbd Mon Sep 17 00:00:00 2001 From: schillic Date: Mon, 9 Sep 2024 19:48:53 +0200 Subject: [PATCH] remove piracy for == --- src/init_IntervalArithmetic.jl | 4 ---- src/matrix.jl | 6 ++++++ test/Aqua.jl | 9 ++++++++- test/affine.jl | 4 ++-- test/arithmetic.jl | 7 +++++++ test/intervals.jl | 7 ------- test/runtests.jl | 6 ++++++ test/setops.jl | 10 +++++----- 8 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/init_IntervalArithmetic.jl b/src/init_IntervalArithmetic.jl index 03062ae4..8c4e3de1 100644 --- a/src/init_IntervalArithmetic.jl +++ b/src/init_IntervalArithmetic.jl @@ -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 diff --git a/src/matrix.jl b/src/matrix.jl index 9d440d18..14959804 100644 --- a/src/matrix.jl +++ b/src/matrix.jl @@ -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 diff --git a/test/Aqua.jl b/test/Aqua.jl index fb2a3a48..1bc292ce 100644 --- a/test/Aqua.jl +++ b/test/Aqua.jl @@ -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=piracies,) + 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 diff --git a/test/affine.jl b/test/affine.jl index 6cbd2d60..91d9efdd 100644 --- a/test/affine.jl +++ b/test/affine.jl @@ -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 @@ -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 diff --git a/test/arithmetic.jl b/test/arithmetic.jl index 9cfa1ec1..662ff84c 100644 --- a/test/arithmetic.jl +++ b/test/arithmetic.jl @@ -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) diff --git a/test/intervals.jl b/test/intervals.jl index 0985d628..77191631 100644 --- a/test/intervals.jl +++ b/test/intervals.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 5d6f69ca..5ce7691f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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") diff --git a/test/setops.jl b/test/setops.jl index cd813526..27691909 100644 --- a/test/setops.jl +++ b/test/setops.jl @@ -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