Skip to content

Commit c3203bf

Browse files
committed
test from discourse, random seed
1 parent 950bf01 commit c3203bf

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

test/GradientTest.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ end
175175
@test ForwardDiff.gradient(f, [0.2,25.0]) == [7875.0, 0.0]
176176
end
177177

178-
# Issue 197
179178
@testset "det with branches" begin
179+
# Issue 197
180180
det2(A) = return (
181181
A[1,1]*(A[2,2]*A[3,3]-A[2,3]*A[3,2]) -
182182
A[1,2]*(A[2,1]*A[3,3]-A[2,3]*A[3,1]) +
@@ -193,6 +193,12 @@ end
193193

194194
# And issue 407
195195
@test ForwardDiff.hessian(det, A) ForwardDiff.hessian(det2, A)
196+
197+
# https://discourse.julialang.org/t/forwarddiff-and-zygote-return-wrong-jacobian-for-log-det-l/77961
198+
S = [1.0 0.8; 0.8 1.0]
199+
L = cholesky(S).L
200+
@test ForwardDiff.gradient(L -> log(det(L)), Matrix(L)) [1.0 -1.3333333333333337; 0.0 1.666666666666667]
201+
@test ForwardDiff.gradient(L -> logdet(L), Matrix(L)) [1.0 -1.3333333333333337; 0.0 1.666666666666667]
196202
end
197203

198204
@testset "branches in mul!" begin

test/JacobianTest.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ for T in (StaticArrays.SArray, StaticArrays.MArray)
226226
@test DiffResults.jacobian(sresult3) == DiffResults.jacobian(result)
227227
end
228228

229+
#########
230+
# misc. #
231+
#########
232+
229233
@testset "dimension errors for jacobian" begin
230234
@test_throws DimensionMismatch ForwardDiff.jacobian(identity, 2pi) # input
231235
@test_throws DimensionMismatch ForwardDiff.jacobian(sum, fill(2pi, 2)) # vector_mode_jacobian

test/runtests.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using ForwardDiff, Test
1+
using ForwardDiff, Test, Random
2+
3+
SEED = trunc(Int, time())
4+
println("Testing with Random.seed!($SEED)")
5+
Random.seed!(SEED)
26

37
@testset "ForwardDiff.jl" begin
48
t0 = time()

0 commit comments

Comments
 (0)