Skip to content

Commit

Permalink
add test from 536
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Jul 28, 2021
1 parent ea7cfbe commit b6e5801
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b6e5801

Please sign in to comment.