diff --git a/test/GradientTest.jl b/test/GradientTest.jl index 18885087..bfb1e8f4 100644 --- a/test/GradientTest.jl +++ b/test/GradientTest.jl @@ -181,6 +181,21 @@ end @test ForwardDiff.hessian(det, A) ≈ ForwardDiff.hessian(det2, A) end +@testset "branches in mul!" begin + a, b = rand(3,3), rand(3,3) + + # Issue 536, version with 3-arg *, Julia 1.7: + @test ForwardDiff.derivative(x -> sum(x*a*b), 0.0) ≈ sum(a * b) + + # version with just mul! + dx = ForwardDiff.derivative(0.0) do x + c = similar(a, typeof(x)) + mul!(c, a, b, x, false) + sum(c) + end + @test dx ≈ sum(a * b) +end + @testset "dimension errors for gradient" begin @test_throws DimensionMismatch ForwardDiff.gradient(identity, 2pi) # input @test_throws DimensionMismatch ForwardDiff.gradient(identity, fill(2pi, 2)) # vector_mode_gradient