From e8ce9461032fe62cda95ad0cdf0e323cb3259968 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:04:40 +0100 Subject: [PATCH 01/17] Add tests provided by Aqua.jl --- test/aqua.jl | 34 ++++++++++++++++++++++++++++++++++ test/runtests.jl | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 test/aqua.jl diff --git a/test/aqua.jl b/test/aqua.jl new file mode 100644 index 00000000..240ee1a4 --- /dev/null +++ b/test/aqua.jl @@ -0,0 +1,34 @@ +using Test +using IntervalArithmetic +using Aqua + +@testset "Aqua tests (performance)" begin + # This tests that we don't accidentally run into + # https://github.com/JuliaLang/julia/issues/29393 + # Aqua.test_unbound_args(IntervalArithmetic) + ua = Aqua.detect_unbound_args_recursively(IntervalArithmetic) + @test length(ua) == 0 + + # See: https://github.com/SciML/OrdinaryDiffEq.jl/issues/1750 + # Test that we're not introducing method ambiguities across deps + ambs = Aqua.detect_ambiguities(IntervalArithmetic; recursive = true) + pkg_match(pkgname, pkdir::Nothing) = false + pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir) + filter!(x -> pkg_match("IntervalArithmetic", pkgdir(last(x).module)), ambs) + for method_ambiguity in ambs + @show method_ambiguity + end + if VERSION < v"1.10.0-DEV" + @test length(ambs) == 0 + end +end + +@testset "Aqua tests (additional)" begin + Aqua.test_undefined_exports(IntervalArithmetic) + # Aqua.test_deps_compat(IntervalArithmetic) + Aqua.test_stale_deps(IntervalArithmetic) + Aqua.test_piracies(IntervalArithmetic) + Aqua.test_unbound_args(IntervalArithmetic) + Aqua.test_project_extras(IntervalArithmetic) + Aqua.test_persistent_tasks(IntervalArithmetic) +end diff --git a/test/runtests.jl b/test/runtests.jl index cebbfb63..27befbd6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -26,3 +26,6 @@ for f ∈ readdir("ITF1788_tests"; join = true) include(f) end end + +# Aqua tests +include("aqua.jl") From 003c37381b039c523f25032d116de2a2f04b36fb Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 02/17] Additions to Project.toml and test/Project.toml --- Project.toml | 5 +++-- test/Project.toml | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 273be455..c429131f 100644 --- a/Project.toml +++ b/Project.toml @@ -12,20 +12,21 @@ RoundingEmulator = "5eaf0fd0-dfba-4ccb-bf02-d820a40db705" [weakdeps] DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" -RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" +RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" [extensions] IntervalArithmeticDiffRulesExt = "DiffRules" IntervalArithmeticForwardDiffExt = "ForwardDiff" -IntervalArithmeticRecipesBaseExt = "RecipesBase" IntervalArithmeticIntervalSetsExt = "IntervalSets" +IntervalArithmeticRecipesBaseExt = "RecipesBase" [compat] CRlibm_jll = "1" DiffRules = "1" ForwardDiff = "0.10" IntervalSets = "0.7" +LinearAlgebra = "<0.0.1, 1" MacroTools = "0.5" RecipesBase = "1" RoundingEmulator = "0.2" diff --git a/test/Project.toml b/test/Project.toml index 5ddc09e4..2dd97b19 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] +Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" From 157b705e8eaed4b9fa2a010b93ae116c8e4142ba Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 03/17] Fix _interval_infsup ambiguities --- src/intervals/construction.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intervals/construction.jl b/src/intervals/construction.jl index 7f19cff2..be505b63 100644 --- a/src/intervals/construction.jl +++ b/src/intervals/construction.jl @@ -465,7 +465,7 @@ function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y::Union{B return _unsafe_interval(z, min(decoration(x), decoration(y), decoration(z), d), t) end end -function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y, d::Decoration) where {T<:NumTypes} +function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y::NumTypes, d::Decoration) where {T<:NumTypes} lo = _inf(x) hi = _sup(y) if !is_valid_interval(lo, hi) || d == ill @@ -476,7 +476,7 @@ function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y, d::Deco return _unsafe_interval(z, min(decoration(x), decoration(z), d), isguaranteed(x)) end end -function _interval_infsup(::Type{T}, x, y::Union{BareInterval,Interval}, d::Decoration) where {T<:NumTypes} +function _interval_infsup(::Type{T}, x::NumTypes, y::Union{BareInterval,Interval}, d::Decoration) where {T<:NumTypes} lo = _inf(x) hi = _sup(y) if !is_valid_interval(lo, hi) || d == ill From b49569c49a865bc8b7b598ba24b46b23012eb731 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 04/17] Add ambiguity solutions proposed by @OlivierHnt, and revert 47605eb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 47605eb solved some ambiguities, but induced (construction) errors Co-authored-by: Olivier Hénot <38465572+OlivierHnt@users.noreply.github.com> --- src/intervals/construction.jl | 10 ++++++++-- src/intervals/exact_literals.jl | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/intervals/construction.jl b/src/intervals/construction.jl index be505b63..8a5a25db 100644 --- a/src/intervals/construction.jl +++ b/src/intervals/construction.jl @@ -426,6 +426,7 @@ interval(::Type{T}, A::AbstractArray, d::AbstractArray{Decoration}; format::Symb interval(A::AbstractArray, d::AbstractArray{Decoration}; format::Symbol = :infsup) = interval.(A, d; format = format) interval(::Type{T}, A::AbstractArray, B::AbstractArray, d::AbstractArray{Decoration}; format::Symbol = :infsup) where {T} = interval.(T, A, B, d; format = format) interval(A::AbstractArray, B::AbstractArray, d::AbstractArray{Decoration}; format::Symbol = :infsup) = interval.(A, B, d; format = format) +interval(T::Type, d::Decoration; format::Symbol = :infsup) = throw(MethodError(interval, (T, d))) # standard format @@ -465,7 +466,7 @@ function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y::Union{B return _unsafe_interval(z, min(decoration(x), decoration(y), decoration(z), d), t) end end -function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y::NumTypes, d::Decoration) where {T<:NumTypes} +function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y, d::Decoration) where {T<:NumTypes} lo = _inf(x) hi = _sup(y) if !is_valid_interval(lo, hi) || d == ill @@ -476,7 +477,7 @@ function _interval_infsup(::Type{T}, x::Union{BareInterval,Interval}, y::NumType return _unsafe_interval(z, min(decoration(x), decoration(z), d), isguaranteed(x)) end end -function _interval_infsup(::Type{T}, x::NumTypes, y::Union{BareInterval,Interval}, d::Decoration) where {T<:NumTypes} +function _interval_infsup(::Type{T}, x, y::Union{BareInterval,Interval}, d::Decoration) where {T<:NumTypes} lo = _inf(x) hi = _sup(y) if !is_valid_interval(lo, hi) || d == ill @@ -488,6 +489,11 @@ function _interval_infsup(::Type{T}, x::NumTypes, y::Union{BareInterval,Interval end end +_interval_infsup(::Type{T}, a::Complex, b::Union{BareInterval,Interval}, d::Decoration = com) where {T<:NumTypes} = + complex(_interval_infsup(T, real(a), real(b), d), _interval_infsup(T, imag(a), imag(b), d)) +_interval_infsup(::Type{T}, a::Union{BareInterval,Interval}, b::Complex, d::Decoration = com) where {T<:NumTypes} = + complex(_interval_infsup(T, real(a), real(b), d), _interval_infsup(T, imag(a), imag(b), d)) + _interval_infsup(::Type{T}, a::Complex, b::Complex, d::Decoration = com) where {T<:NumTypes} = complex(_interval_infsup(T, real(a), real(b), d), _interval_infsup(T, imag(a), imag(b), d)) _interval_infsup(::Type{T}, a::Complex, b, d::Decoration = com) where {T<:NumTypes} = diff --git a/src/intervals/exact_literals.jl b/src/intervals/exact_literals.jl index 5f7d939d..25d7367a 100644 --- a/src/intervals/exact_literals.jl +++ b/src/intervals/exact_literals.jl @@ -54,6 +54,8 @@ struct ExactReal{T<:Real} <: Real ExactReal(value::T) where {T<:Real} = new{T}(value) end +ExactReal(x::ExactReal) = x + _value(x::ExactReal) = x.value # hook for interval constructor # utilities From 313f3fa4c9e1c05bf59faab88bcacc03b4de7f88 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 05/17] Solve Base.union! ambiguities --- src/intervals/real_interface.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/intervals/real_interface.jl b/src/intervals/real_interface.jl index c2d4d814..01824b6c 100644 --- a/src/intervals/real_interface.jl +++ b/src/intervals/real_interface.jl @@ -130,6 +130,11 @@ for T ∈ (:BareInterval, :Interval) throw(ArgumentError("`setdiff!` is purposely not supported for intervals. See instead `interiordiff`")) end end +Base.union!(::AbstractVector{S}, ::BareInterval, ::Interval, ::Any...) where {S} = + throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) +Base.union!(::AbstractVector{S}, ::Interval, ::BareInterval, ::Any...) where {S} = + throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) + # allow pointwise equality From bb1b014637494edf9709ec1ecaa927d1bbcddbed Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 06/17] Remove LinearAlgebra from [deps] --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index c429131f..882cc692 100644 --- a/Project.toml +++ b/Project.toml @@ -5,7 +5,6 @@ version = "0.22.19" [deps] CRlibm_jll = "4e9b3aee-d8a1-5a3d-ad8b-7d824db253f0" -LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" RoundingEmulator = "5eaf0fd0-dfba-4ccb-bf02-d820a40db705" From 9e04957ef062dcb19c80a66295ed8b4de7181404 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 07/17] Try to solve some ambiguities related to ForwardDiff --- ext/IntervalArithmeticForwardDiffExt.jl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index daf9bfbd..5954545d 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -3,7 +3,19 @@ module IntervalArithmeticForwardDiffExt using IntervalArithmetic, ForwardDiff using ForwardDiff: Dual, Partials, ≺, value, partials -# +# Needed to avoid method ambiguities: +Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{Interval{S}}) where {T, V, N, S<:Union{AbstractFloat, Rational}} = + Interval{IntervalArithmetic.promote_numtype(V, S)} + +Base.promote_rule(::Type{ExactReal{S}}, ::Type{Dual{T, V, N}}) where {S<:Real, T, V, N} = + ExactReal{IntervalArithmetic.promote_numtype(V, S)} + +Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{ExactReal{S}}) where {S<:Real, T, V, N} = + ExactReal{IntervalArithmetic.promote_numtype(V, S)} + +Base.:(==)(x::Union{BareInterval,Interval}, y::Dual) = isthin(x, y) +Base.:(==)(x::Dual, y::Union{BareInterval,Interval}) = y == x + function Base.:(^)(x::Dual{Txy,<:Interval}, y::Dual{Txy,<:Interval}) where {Txy} vx, vy = value(x), value(y) From 0f9de49da9844fda1272a523176fab95c7f9c20d Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 08/17] Return Dual's for promote_rule --- ext/IntervalArithmeticForwardDiffExt.jl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index 5954545d..f7225496 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -5,13 +5,16 @@ using ForwardDiff: Dual, Partials, ≺, value, partials # Needed to avoid method ambiguities: Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{Interval{S}}) where {T, V, N, S<:Union{AbstractFloat, Rational}} = - Interval{IntervalArithmetic.promote_numtype(V, S)} + Dual{T,Interval{IntervalArithmetic.promote_numtype(V, S)},N} + +Base.promote_rule(::Type{Interval{S}}, ::Type{ForwardDiff.Dual{T, V, N}}) where {S<:Union{AbstractFloat, Rational}, T, V, N} = + Dual{T,Interval{IntervalArithmetic.promote_numtype(V, S)},N} Base.promote_rule(::Type{ExactReal{S}}, ::Type{Dual{T, V, N}}) where {S<:Real, T, V, N} = - ExactReal{IntervalArithmetic.promote_numtype(V, S)} + Dual{T,ExactReal{IntervalArithmetic.promote_numtype(V, S)},N} Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{ExactReal{S}}) where {S<:Real, T, V, N} = - ExactReal{IntervalArithmetic.promote_numtype(V, S)} + Dual{T,ExactReal{IntervalArithmetic.promote_numtype(V, S)},N} Base.:(==)(x::Union{BareInterval,Interval}, y::Dual) = isthin(x, y) Base.:(==)(x::Dual, y::Union{BareInterval,Interval}) = y == x From 676cc47094ddcab3cb53b8378265f799d4d1d4de Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 09/17] Add convert method to ForwardDiff extension --- ext/IntervalArithmeticForwardDiffExt.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index f7225496..00a9a7b3 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -4,15 +4,15 @@ using IntervalArithmetic, ForwardDiff using ForwardDiff: Dual, Partials, ≺, value, partials # Needed to avoid method ambiguities: +ForwardDiff.can_dual(::Type{ExactReal}) = true +Base.convert(::Type{Dual{T, V, N}}, x::ExactReal) where {T, V, N} = promote_rule(Dual{T, V, N}, typeof(x))(x.value) + Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{Interval{S}}) where {T, V, N, S<:Union{AbstractFloat, Rational}} = Dual{T,Interval{IntervalArithmetic.promote_numtype(V, S)},N} - Base.promote_rule(::Type{Interval{S}}, ::Type{ForwardDiff.Dual{T, V, N}}) where {S<:Union{AbstractFloat, Rational}, T, V, N} = Dual{T,Interval{IntervalArithmetic.promote_numtype(V, S)},N} - Base.promote_rule(::Type{ExactReal{S}}, ::Type{Dual{T, V, N}}) where {S<:Real, T, V, N} = Dual{T,ExactReal{IntervalArithmetic.promote_numtype(V, S)},N} - Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{ExactReal{S}}) where {S<:Real, T, V, N} = Dual{T,ExactReal{IntervalArithmetic.promote_numtype(V, S)},N} From ef2a774cd5d894b1b4e158db4ab9b4823a76d3a1 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 10/17] Add Dual(x::ExactReal) --- ext/IntervalArithmeticForwardDiffExt.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index 00a9a7b3..ac7bf044 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -5,6 +5,7 @@ using ForwardDiff: Dual, Partials, ≺, value, partials # Needed to avoid method ambiguities: ForwardDiff.can_dual(::Type{ExactReal}) = true +Dual(x::ExactReal) = Dual{Nothing, typeof(x), 0}(x.value) Base.convert(::Type{Dual{T, V, N}}, x::ExactReal) where {T, V, N} = promote_rule(Dual{T, V, N}, typeof(x))(x.value) Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{Interval{S}}) where {T, V, N, S<:Union{AbstractFloat, Rational}} = From a624477c6d203b5a5ce1c52445ac019f528a3696 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 11/17] More methods Dual(::ExactReal) --- ext/IntervalArithmeticForwardDiffExt.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index ac7bf044..1489ce37 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -6,6 +6,10 @@ using ForwardDiff: Dual, Partials, ≺, value, partials # Needed to avoid method ambiguities: ForwardDiff.can_dual(::Type{ExactReal}) = true Dual(x::ExactReal) = Dual{Nothing, typeof(x), 0}(x.value) +Dual{T}(x::ExactReal) where {T} = Dual{T, typeof(x), 0}(x.value) +Dual{T, V}(x::ExactReal) where {T, V<:Real} = convert(Dual{T, V, 0}, x) +Dual{T, V, N}(x::ExactReal) where {T, V<:Real, N} = convert(Dual{T, V, N}, x) + Base.convert(::Type{Dual{T, V, N}}, x::ExactReal) where {T, V, N} = promote_rule(Dual{T, V, N}, typeof(x))(x.value) Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{Interval{S}}) where {T, V, N, S<:Union{AbstractFloat, Rational}} = From f5714e93dae70d121aff861c27a565599b82127a Mon Sep 17 00:00:00 2001 From: OlivierHnt <38465572+OlivierHnt@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 12/17] Fix Project.toml --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 882cc692..c7814ca8 100644 --- a/Project.toml +++ b/Project.toml @@ -25,7 +25,6 @@ CRlibm_jll = "1" DiffRules = "1" ForwardDiff = "0.10" IntervalSets = "0.7" -LinearAlgebra = "<0.0.1, 1" MacroTools = "0.5" RecipesBase = "1" RoundingEmulator = "0.2" From ebfe89891994ceaf2044175eab3523718b1ac768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 9 Dec 2024 17:06:29 +0100 Subject: [PATCH 13/17] Define similar to avoid many ambiguities --- src/matmul.jl | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/src/matmul.jl b/src/matmul.jl index 6e30a1eb..52aee401 100644 --- a/src/matmul.jl +++ b/src/matmul.jl @@ -86,39 +86,14 @@ struct MatMulMode{T} end matmul_mode() = MatMulMode{:slow}() -# - -function Base.:*(A::AbstractMatrix{<:RealOrComplexI}, B::AbstractMatrix{<:RealOrComplexI}) - T = promote_type(eltype(A), eltype(B)) - C = zeros(T, size(A, 1), size(B, 2)) - return LinearAlgebra.mul!(C, A, B, one(T), zero(T)) -end -function Base.:*(A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVector{<:RealOrComplexI}) - T = promote_type(eltype(A), eltype(B)) - C = zeros(T, size(A, 1)) - return LinearAlgebra.mul!(C, A, B, one(T), zero(T)) -end - -function Base.:*(A::AbstractMatrix{<:RealOrComplexI}, B::AbstractMatrix) - T = promote_type(eltype(A), eltype(B)) - C = zeros(T, size(A, 1), size(B, 2)) - return LinearAlgebra.mul!(C, A, B, one(T), zero(T)) -end -function Base.:*(A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVector) - T = promote_type(eltype(A), eltype(B)) - C = zeros(T, size(A, 1)) - return LinearAlgebra.mul!(C, A, B, one(T), zero(T)) -end - -function Base.:*(A::AbstractMatrix, B::AbstractMatrix{<:RealOrComplexI}) - T = promote_type(eltype(A), eltype(B)) - C = zeros(T, size(A, 1), size(B, 2)) - return LinearAlgebra.mul!(C, A, B, one(T), zero(T)) -end -function Base.:*(A::AbstractMatrix, B::AbstractVector{<:RealOrComplexI}) - T = promote_type(eltype(A), eltype(B)) - C = zeros(T, size(A, 1)) - return LinearAlgebra.mul!(C, A, B, one(T), zero(T)) +Base.similar(a::Array{T}) where {T <: RealOrComplexI} = zeros(T, size(a)) +Base.similar(a::Array{T}, S::Type) where {T <: RealOrComplexI} = zeros(S, size(a)) +Base.similar(::Array{T}, m::Int) where {T <: RealOrComplexI} = zeros(T, m) +Base.similar(::Array, ::Type{T}, dims::Dims{N}) where {N, T <: RealOrComplexI} = zeros(T, dims) +Base.similar(::Array{T}, dims::Dims{N}) where {T <: RealOrComplexI, N} = zeros(T, dims) + +function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat{<:RealOrComplexI}) + return LinearAlgebra.mul!(C, A, B, interval(true), interval(false)) end function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat{<:RealOrComplexI}, α::Number, β::Number) From d774b673b96d06a9cf7778b3fc350035d8fdcbc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 9 Dec 2024 17:25:24 +0100 Subject: [PATCH 14/17] Fix rebase issues --- Project.toml | 2 ++ ext/IntervalArithmeticForwardDiffExt.jl | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Project.toml b/Project.toml index c7814ca8..7e4c3eee 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ version = "0.22.19" [deps] CRlibm_jll = "4e9b3aee-d8a1-5a3d-ad8b-7d824db253f0" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" RoundingEmulator = "5eaf0fd0-dfba-4ccb-bf02-d820a40db705" @@ -25,6 +26,7 @@ CRlibm_jll = "1" DiffRules = "1" ForwardDiff = "0.10" IntervalSets = "0.7" +LinearAlgebra = "1.11.0" MacroTools = "0.5" RecipesBase = "1" RoundingEmulator = "0.2" diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index 1489ce37..d2b8d512 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -10,11 +10,11 @@ Dual{T}(x::ExactReal) where {T} = Dual{T, typeof(x), 0}(x.value) Dual{T, V}(x::ExactReal) where {T, V<:Real} = convert(Dual{T, V, 0}, x) Dual{T, V, N}(x::ExactReal) where {T, V<:Real, N} = convert(Dual{T, V, N}, x) -Base.convert(::Type{Dual{T, V, N}}, x::ExactReal) where {T, V, N} = promote_rule(Dual{T, V, N}, typeof(x))(x.value) +Base.convert(::Type{Dual{T,V,N}}, x::ExactReal) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V})) Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{Interval{S}}) where {T, V, N, S<:Union{AbstractFloat, Rational}} = Dual{T,Interval{IntervalArithmetic.promote_numtype(V, S)},N} -Base.promote_rule(::Type{Interval{S}}, ::Type{ForwardDiff.Dual{T, V, N}}) where {S<:Union{AbstractFloat, Rational}, T, V, N} = +Base.promote_rule(::Type{Interval{S}}, ::Type{Dual{T, V, N}}) where {S<:Union{AbstractFloat, Rational}, T, V, N} = Dual{T,Interval{IntervalArithmetic.promote_numtype(V, S)},N} Base.promote_rule(::Type{ExactReal{S}}, ::Type{Dual{T, V, N}}) where {S<:Real, T, V, N} = Dual{T,ExactReal{IntervalArithmetic.promote_numtype(V, S)},N} @@ -90,8 +90,4 @@ function Base.:(^)(x::ExactReal, y::Dual{<:Ty}) where {Ty} end end -# resolve ambiguity - -Base.convert(::Type{Dual{T,V,N}}, x::ExactReal) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V})) - end From baad9f24f88a7167f285cc9fba995f71bd6bc26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 9 Dec 2024 17:28:54 +0100 Subject: [PATCH 15/17] Fix tests --- test/aqua.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/aqua.jl b/test/aqua.jl index 240ee1a4..7c600dee 100644 --- a/test/aqua.jl +++ b/test/aqua.jl @@ -15,12 +15,7 @@ using Aqua pkg_match(pkgname, pkdir::Nothing) = false pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir) filter!(x -> pkg_match("IntervalArithmetic", pkgdir(last(x).module)), ambs) - for method_ambiguity in ambs - @show method_ambiguity - end - if VERSION < v"1.10.0-DEV" - @test length(ambs) == 0 - end + @test_broken length(ambs) == 0 end @testset "Aqua tests (additional)" begin From 3badc0ede50e1ad8f6b8914b939e0b8fe6606b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 9 Dec 2024 17:46:58 +0100 Subject: [PATCH 16/17] Fix compat --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7e4c3eee..82126ee2 100644 --- a/Project.toml +++ b/Project.toml @@ -26,7 +26,7 @@ CRlibm_jll = "1" DiffRules = "1" ForwardDiff = "0.10" IntervalSets = "0.7" -LinearAlgebra = "1.11.0" +LinearAlgebra = "1.9" MacroTools = "0.5" RecipesBase = "1" RoundingEmulator = "0.2" From 78fb4abb6685a3dcca9d98adee288d91e75d943c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Richard?= Date: Mon, 9 Dec 2024 18:10:38 +0100 Subject: [PATCH 17/17] Fix similar breaking Documenter --- src/matmul.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matmul.jl b/src/matmul.jl index 52aee401..89a5818c 100644 --- a/src/matmul.jl +++ b/src/matmul.jl @@ -89,7 +89,7 @@ matmul_mode() = MatMulMode{:slow}() Base.similar(a::Array{T}) where {T <: RealOrComplexI} = zeros(T, size(a)) Base.similar(a::Array{T}, S::Type) where {T <: RealOrComplexI} = zeros(S, size(a)) Base.similar(::Array{T}, m::Int) where {T <: RealOrComplexI} = zeros(T, m) -Base.similar(::Array, ::Type{T}, dims::Dims{N}) where {N, T <: RealOrComplexI} = zeros(T, dims) +Base.similar(::Array{T}, S::Type, dims::Dims{N}) where {N, T <: RealOrComplexI} = zeros(S, dims) Base.similar(::Array{T}, dims::Dims{N}) where {T <: RealOrComplexI, N} = zeros(T, dims) function LinearAlgebra.mul!(C::AbstractVecOrMat{<:RealOrComplexI}, A::AbstractMatrix{<:RealOrComplexI}, B::AbstractVecOrMat{<:RealOrComplexI})