From a87a4821b65f07e6fd9681c26e71b3190e0e4c8b Mon Sep 17 00:00:00 2001 From: chriselrod Date: Tue, 8 Aug 2023 21:34:00 -0400 Subject: [PATCH] convert for nested duals sharing tags --- Project.toml | 2 +- src/dual.jl | 1 + test/DualTest.jl | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ee450fc6..f7c66517 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ForwardDiff" uuid = "f6369f11-7733-5829-9624-2563aa707210" -version = "0.10.35" +version = "0.10.36" [deps] CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950" diff --git a/src/dual.jl b/src/dual.jl index c0fb4744..5afb2144 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -431,6 +431,7 @@ for R in (Irrational, 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 diff --git a/test/DualTest.jl b/test/DualTest.jl index be3ea25a..8d87f90b 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -603,6 +603,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