Skip to content

Commit b6e5801

Browse files
committed
add test from 536
1 parent ea7cfbe commit b6e5801

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/GradientTest.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ end
181181
@test ForwardDiff.hessian(det, A) ForwardDiff.hessian(det2, A)
182182
end
183183

184+
@testset "branches in mul!" begin
185+
a, b = rand(3,3), rand(3,3)
186+
187+
# Issue 536, version with 3-arg *, Julia 1.7:
188+
@test ForwardDiff.derivative(x -> sum(x*a*b), 0.0) sum(a * b)
189+
190+
# version with just mul!
191+
dx = ForwardDiff.derivative(0.0) do x
192+
c = similar(a, typeof(x))
193+
mul!(c, a, b, x, false)
194+
sum(c)
195+
end
196+
@test dx sum(a * b)
197+
end
198+
184199
@testset "dimension errors for gradient" begin
185200
@test_throws DimensionMismatch ForwardDiff.gradient(identity, 2pi) # input
186201
@test_throws DimensionMismatch ForwardDiff.gradient(identity, fill(2pi, 2)) # vector_mode_gradient

0 commit comments

Comments
 (0)