Skip to content

Commit

Permalink
Return Dual's for promote_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
lbenet committed Oct 14, 2024
1 parent 82baf63 commit f8fd2a7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ext/IntervalArithmeticForwardDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ 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)}
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
Expand Down

0 comments on commit f8fd2a7

Please sign in to comment.