diff --git a/src/dual.jl b/src/dual.jl index 947c50b5..e9629fe1 100644 --- a/src/dual.jl +++ b/src/dual.jl @@ -20,6 +20,11 @@ struct Dual{T,V,N} <: Real end end +########## +# Traits # +########## +Base.ArithmeticStyle(::Type{<:Dual{T,V}}) where {T,V} = Base.ArithmeticStyle(V) + ############## # Exceptions # ############## diff --git a/test/GradientTest.jl b/test/GradientTest.jl index ac949944..707fcd68 100644 --- a/test/GradientTest.jl +++ b/test/GradientTest.jl @@ -162,4 +162,11 @@ end @test_throws DimensionMismatch ForwardDiff.gradient(identity, fill(2pi, 10^6)) # chunk_mode_gradient end +@testset "ArithmeticStyle" begin + function f(p) + sum(collect(0.0:p[1]:p[2])) + end + @test ForwardDiff.gradient(f, [0.2,25.0]) == [7875.0, 0.0] +end + end # module