Skip to content

Commit

Permalink
convert for nested duals sharing tags (#711)
Browse files Browse the repository at this point in the history
Co-authored-by: chriselrod <[email protected]>
  • Loading branch information
devmotion and chriselrod authored Oct 30, 2024
1 parent 826d919 commit 7e9d778
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ for R in (AbstractIrrational, Real, BigFloat, Bool)
end

@inline Base.convert(::Type{Dual{T,V,N}}, d::Dual{T}) where {T,V,N} = Dual{T}(V(value(d)), convert(Partials{N,V}, partials(d)))
@inline Base.convert(::Type{Dual{T,Dual{T,V,M},N}}, d::Dual{T,V,M}) where {T,V,N,M} = Dual{T}(d, Partials{N,Dual{T,V,M}}(zero_tuple(NTuple{N,Dual{T,V,M}})))
@inline Base.convert(::Type{Dual{T,V,N}}, x) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))
@inline Base.convert(::Type{Dual{T,V,N}}, x::Number) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))
Base.convert(::Type{D}, d::D) where {D<:Dual} = d
Expand Down
2 changes: 2 additions & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ end
@test typeof(dfmax) === typeof(d1)
@test isfinite(dfmin)
@test isfinite(dfmax)

@test floatmin(Dual{Nothing, ForwardDiff.Dual{Nothing, Float64, 2}, 1}) === Dual{Nothing}(Dual{Nothing}(floatmin(Float64),0.0,0.0),Dual{Nothing}(0.0,0.0,0.0))
end

@testset "Integer" begin
Expand Down

0 comments on commit 7e9d778

Please sign in to comment.