Skip to content

Commit 7e9d778

Browse files
convert for nested duals sharing tags (#711)
Co-authored-by: chriselrod <[email protected]>
1 parent 826d919 commit 7e9d778

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/dual.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ for R in (AbstractIrrational, Real, BigFloat, Bool)
467467
end
468468

469469
@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)))
470+
@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}})))
470471
@inline Base.convert(::Type{Dual{T,V,N}}, x) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))
471472
@inline Base.convert(::Type{Dual{T,V,N}}, x::Number) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))
472473
Base.convert(::Type{D}, d::D) where {D<:Dual} = d

test/DualTest.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ end
637637
@test typeof(dfmax) === typeof(d1)
638638
@test isfinite(dfmin)
639639
@test isfinite(dfmax)
640+
641+
@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))
640642
end
641643

642644
@testset "Integer" begin

0 commit comments

Comments
 (0)