From 37786e5f851fb8cb36f4f392f7d0cd409ce7d431 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 29 Oct 2024 23:32:54 +0100 Subject: [PATCH 1/2] Fix method ambiguity for `Base.TwicePrecision` --- src/dual.jl | 4 ++++ test/DualTest.jl | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/dual.jl b/src/dual.jl index 3c390e43..cffbcb11 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -78,6 +78,10 @@ end @inline Dual{T,V,N}(x::Number) where {T,V,N} = convert(Dual{T,V,N}, x) @inline Dual{T,V}(x) where {T,V} = convert(Dual{T,V}, x) +# Fix method ambiguity issue by adapting the definition in Base to `Dual`s +Dual{T,V,N}(x::Base.TwicePrecision) where {T,V,N} = + (Dual{T,V,N}(x.hi) + Dual{T,V,N}(x.lo))::Dual{T,V,N} + ############################## # Utility/Accessor Functions # ############################## diff --git a/test/DualTest.jl b/test/DualTest.jl index bc67aef1..bb051b27 100644 --- a/test/DualTest.jl +++ b/test/DualTest.jl @@ -667,4 +667,8 @@ end @test ForwardDiff.derivative(float, 1)::Float64 === 1.0 end +@testset "TwicePrecision" begin + @test ForwardDiff.derivative(x -> sum(1 .+ x .* (0:0.1:1)), 1) == 5.5 +end + end # module From c5944bb9871ba88da17ffc0d6c397003c9639781 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 29 Oct 2024 23:48:34 +0100 Subject: [PATCH 2/2] Mark tests as not broken --- test/AllocationsTest.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/AllocationsTest.jl b/test/AllocationsTest.jl index 1092db80..ad1832d0 100644 --- a/test/AllocationsTest.jl +++ b/test/AllocationsTest.jl @@ -24,7 +24,7 @@ convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,F index = 1 alloc = @allocated ForwardDiff.seed!(duals, x, index, seeds) alloc = @allocated ForwardDiff.seed!(duals, x, index, seeds) - if VERSION < v"1.9" + if VERSION < v"1.9" || VERSION >= v"1.11" @test alloc == 0 else @test_broken alloc == 0 @@ -33,7 +33,7 @@ convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,F index = 1 alloc = @allocated ForwardDiff.seed!(duals, x, index, seed) alloc = @allocated ForwardDiff.seed!(duals, x, index, seed) - if VERSION < v"1.9" + if VERSION < v"1.9" || VERSION >= v"1.11" @test alloc == 0 else @test_broken alloc == 0