Skip to content

Commit

Permalink
Add convert method to ForwardDiff extension
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenet committed Oct 14, 2024
1 parent f8fd2a7 commit a56fa01
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ext/IntervalArithmeticForwardDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ using IntervalArithmetic, ForwardDiff
using ForwardDiff: Dual, , 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}

Expand Down

0 comments on commit a56fa01

Please sign in to comment.