Skip to content

Commit 29332b1

Browse files
authored
Avoid recursion heuristic (#574)
1 parent 9c2be97 commit 29332b1

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ForwardDiff"
22
uuid = "f6369f11-7733-5829-9624-2563aa707210"
3-
version = "0.10.24"
3+
version = "0.10.25"
44

55
[deps]
66
CommonSubexpressions = "bbf7d656-a473-5ed7-a52c-81e309532950"

src/dual.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ for R in (Irrational, Real, BigFloat, Bool)
380380
end
381381
end
382382

383-
Base.convert(::Type{Dual{T,V,N}}, d::Dual{T}) where {T,V,N} = Dual{T}(convert(V, value(d)), convert(Partials{N,V}, partials(d)))
384-
Base.convert(::Type{Dual{T,V,N}}, x) where {T,V,N} = Dual{T}(convert(V, x), zero(Partials{N,V}))
385-
Base.convert(::Type{Dual{T,V,N}}, x::Number) where {T,V,N} = Dual{T}(convert(V, x), zero(Partials{N,V}))
383+
@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)))
384+
@inline Base.convert(::Type{Dual{T,V,N}}, x) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))
385+
@inline Base.convert(::Type{Dual{T,V,N}}, x::Number) where {T,V,N} = Dual{T}(V(x), zero(Partials{N,V}))
386386
Base.convert(::Type{D}, d::D) where {D<:Dual} = d
387387

388388
Base.float(::Type{Dual{T,V,N}}) where {T,V,N} = Dual{T,float(V),N}

test/AllocationsTest.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ using ForwardDiff
44

55
include(joinpath(dirname(@__FILE__), "utils.jl"))
66

7+
convert_test_574() = convert(ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,ForwardDiff.Dual{Nothing,Float64,8},4},2}, 1.3)
8+
79
@testset "Test seed! allocations" begin
810
x = rand(1000)
911
cfg = ForwardDiff.GradientConfig(nothing, x)
@@ -28,6 +30,11 @@ include(joinpath(dirname(@__FILE__), "utils.jl"))
2830
alloc = @allocated ForwardDiff.seed!(duals, x, index, seed)
2931
alloc = @allocated ForwardDiff.seed!(duals, x, index, seed)
3032
@test alloc == 0
33+
34+
alloc = @allocated convert_test_574()
35+
alloc = @allocated convert_test_574()
36+
@test alloc == 0
37+
3138
end
3239

33-
end
40+
end

0 commit comments

Comments
 (0)