From 82baf63ea7ffeb4be844f156127adfb1a4fdf423 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Mon, 14 Oct 2024 13:00:32 -0600 Subject: [PATCH] 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 3ab6c7123..869d926e6 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -3,7 +3,19 @@ module IntervalArithmeticForwardDiffExt using IntervalArithmetic, ForwardDiff using ForwardDiff: Dual, ≺, 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)