Skip to content

Commit 826d919

Browse files
authored
Fix method ambiguity for Base.TwicePrecision (#715)
* Fix method ambiguity for `Base.TwicePrecision` * Mark tests as not broken
1 parent ec74fbc commit 826d919

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/dual.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ end
7878
@inline Dual{T,V,N}(x::Number) where {T,V,N} = convert(Dual{T,V,N}, x)
7979
@inline Dual{T,V}(x) where {T,V} = convert(Dual{T,V}, x)
8080

81+
# Fix method ambiguity issue by adapting the definition in Base to `Dual`s
82+
Dual{T,V,N}(x::Base.TwicePrecision) where {T,V,N} =
83+
(Dual{T,V,N}(x.hi) + Dual{T,V,N}(x.lo))::Dual{T,V,N}
84+
8185
##############################
8286
# Utility/Accessor Functions #
8387
##############################

test/AllocationsTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,F
2424
index = 1
2525
alloc = @allocated ForwardDiff.seed!(duals, x, index, seeds)
2626
alloc = @allocated ForwardDiff.seed!(duals, x, index, seeds)
27-
if VERSION < v"1.9"
27+
if VERSION < v"1.9" || VERSION >= v"1.11"
2828
@test alloc == 0
2929
else
3030
@test_broken alloc == 0
@@ -33,7 +33,7 @@ convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,F
3333
index = 1
3434
alloc = @allocated ForwardDiff.seed!(duals, x, index, seed)
3535
alloc = @allocated ForwardDiff.seed!(duals, x, index, seed)
36-
if VERSION < v"1.9"
36+
if VERSION < v"1.9" || VERSION >= v"1.11"
3737
@test alloc == 0
3838
else
3939
@test_broken alloc == 0

test/DualTest.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,4 +667,8 @@ end
667667
@test ForwardDiff.derivative(float, 1)::Float64 === 1.0
668668
end
669669

670+
@testset "TwicePrecision" begin
671+
@test ForwardDiff.derivative(x -> sum(1 .+ x .* (0:0.1:1)), 1) == 5.5
672+
end
673+
670674
end # module

0 commit comments

Comments
 (0)