Skip to content

Commit 5f9ad3f

Browse files
Michael Abbottmcabbott
authored andcommitted
add a test of issue 197
1 parent dcb307e commit 5f9ad3f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/GradientTest.jl

Lines changed: 23 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,11 +167,29 @@ end
162167
@test_throws DimensionMismatch ForwardDiff.gradient(identity, fill(2pi, 10^6)) # chunk_mode_gradient
163168
end
164169

170+
# Issue 548
165171
@testset "ArithmeticStyle" begin
166172
function f(p)
167173
sum(collect(0.0:p[1]:p[2]))
168174
end
169175
@test ForwardDiff.gradient(f, [0.2,25.0]) == [7875.0, 0.0]
170176
end
171177

178+
# Issue 197
179+
@testset "det with branches" begin
180+
det2(A) = return (
181+
A[1,1]*(A[2,2]*A[3,3]-A[2,3]*A[3,2]) -
182+
A[1,2]*(A[2,1]*A[3,3]-A[2,3]*A[3,1]) +
183+
A[1,3]*(A[2,1]*A[3,2]-A[2,2]*A[3,1])
184+
)
185+
186+
A = [1 0 0; 0 2 0; 0 pi 3]
187+
@test det2(A) == det(A) == 6
188+
@test istril(A)
189+
190+
∇A = [6 0 0; 0 3 -pi; 0 0 2]
191+
@test ForwardDiff.gradient(det2, A) ∇A
192+
@test ForwardDiff.gradient(det, A) ∇A
193+
end
194+
172195
end # module

0 commit comments

Comments
 (0)