Skip to content

Commit 2c0fa4c

Browse files
Michael Abbottmcabbott
authored andcommitted
add a test of issue 197
1 parent 5094b90 commit 2c0fa4c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/GradientTest.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module GradientTest
33
import Calculus
44

55
using Test
6+
using LinearAlgebra
67
using ForwardDiff
78
using ForwardDiff: Dual, Tag
89
using StaticArrays
@@ -148,6 +149,10 @@ end
148149
@test isequal(ForwardDiff.gradient(t -> t[1]^t[2], [0.0, 1.5]), [0.0, 0.0])
149150
end
150151

152+
#############
153+
# bug fixes #
154+
#############
155+
151156
# Issue 399
152157
@testset "chunk size zero" begin
153158
f_const(x) = 1.0
@@ -162,4 +167,21 @@ end
162167
@test_throws DimensionMismatch ForwardDiff.gradient(identity, fill(2pi, 10^6)) # chunk_mode_gradient
163168
end
164169

170+
# Issue 197
171+
@testset "det with branches" begin
172+
det2(A) = return (
173+
A[1,1]*(A[2,2]*A[3,3]-A[2,3]*A[3,2]) -
174+
A[1,2]*(A[2,1]*A[3,3]-A[2,3]*A[3,1]) +
175+
A[1,3]*(A[2,1]*A[3,2]-A[2,2]*A[3,1])
176+
)
177+
178+
A = [1 0 0; 0 2 0; 0 pi 3]
179+
@test det2(A) == det(A) == 6
180+
@test istril(A)
181+
182+
∇A = [6 0 0; 0 3 -pi; 0 0 2]
183+
@test ForwardDiff.gradient(det2, A) ∇A
184+
@test ForwardDiff.gradient(det, A) ∇A
185+
end
186+
165187
end # module

0 commit comments

Comments
 (0)