Skip to content

Commit 3bf4879

Browse files
Merge pull request #923 from SciML/returns_forwarddif
Specialize forwarddiff dual detection for Returns
2 parents 7f15b4e + 1c099a6 commit 3bf4879

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/forwarddiff.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ anyeltypedual(x::Union{ForwardDiff.AbstractConfig, Module}, counter = 0) = Any
114114
anyeltypedual(x::Type{T}, counter = 0) where {T <: ForwardDiff.AbstractConfig} = Any
115115
anyeltypedual(x::SciMLBase.RecipesBase.AbstractPlot, counter = 0) = Any
116116

117+
if VERSION >= v"1.7"
118+
anyeltypedual(x::Returns, counter = 0) = anyeltypedual(x.value, counter)
119+
end
120+
117121
if isdefined(PreallocationTools, :FixedSizeDiffCache)
118122
anyeltypedual(x::PreallocationTools.FixedSizeDiffCache, counter = 0) = Any
119123
end

test/forwarddiff_dual_detection.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ p_possibilities17 = [
8585
(Mod, ForwardDiff.Dual(2.0)), (() -> 2.0, ForwardDiff.Dual(2.0)),
8686
(Base.pointer([2.0]), ForwardDiff.Dual(2.0)),
8787
]
88-
VERSION >= v"1.7" && VERSION < v"1.9" &&
89-
push!(p_possibilities17, Returns((a = 2, b = 1.3, c = ForwardDiff.Dual(2.0f0))))
88+
VERSION >= v"1.7" && push!(p_possibilities17, Returns((a = 2, b = 1.3, c = ForwardDiff.Dual(2.0f0))))
9089

9190
for p in p_possibilities17
9291
@show p
@@ -128,9 +127,6 @@ p_possibilities_uninferrred = [
128127
(; x = Vector{Float64}(undef, 2), y = [[MyStruct3(ForwardDiff.Dual(2.0))]]),
129128
(; x = Matrix{Any}(undef, 2, 2), y = [[MyStruct3(ForwardDiff.Dual(2.0))]]),
130129
]
131-
VERSION >= v"1.9" &&
132-
push!(p_possibilities_uninferrred,
133-
Returns((a = 2, b = 1.3, c = ForwardDiff.Dual(2.0f0))))
134130

135131
for p in p_possibilities_uninferrred
136132
@show p

0 commit comments

Comments
 (0)