Skip to content

Commit

Permalink
test from discourse, random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Apr 23, 2022
1 parent 950bf01 commit c3203bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 7 additions & 1 deletion test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ end
@test ForwardDiff.gradient(f, [0.2,25.0]) == [7875.0, 0.0]
end

# Issue 197
@testset "det with branches" begin
# Issue 197
det2(A) = return (
A[1,1]*(A[2,2]*A[3,3]-A[2,3]*A[3,2]) -
A[1,2]*(A[2,1]*A[3,3]-A[2,3]*A[3,1]) +
Expand All @@ -193,6 +193,12 @@ end

# And issue 407
@test ForwardDiff.hessian(det, A) ForwardDiff.hessian(det2, A)

# https://discourse.julialang.org/t/forwarddiff-and-zygote-return-wrong-jacobian-for-log-det-l/77961
S = [1.0 0.8; 0.8 1.0]
L = cholesky(S).L
@test ForwardDiff.gradient(L -> log(det(L)), Matrix(L)) [1.0 -1.3333333333333337; 0.0 1.666666666666667]
@test ForwardDiff.gradient(L -> logdet(L), Matrix(L)) [1.0 -1.3333333333333337; 0.0 1.666666666666667]
end

@testset "branches in mul!" begin
Expand Down
4 changes: 4 additions & 0 deletions test/JacobianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ for T in (StaticArrays.SArray, StaticArrays.MArray)
@test DiffResults.jacobian(sresult3) == DiffResults.jacobian(result)
end

#########
# misc. #
#########

@testset "dimension errors for jacobian" begin
@test_throws DimensionMismatch ForwardDiff.jacobian(identity, 2pi) # input
@test_throws DimensionMismatch ForwardDiff.jacobian(sum, fill(2pi, 2)) # vector_mode_jacobian
Expand Down
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using ForwardDiff, Test
using ForwardDiff, Test, Random

SEED = trunc(Int, time())
println("Testing with Random.seed!($SEED)")
Random.seed!(SEED)

@testset "ForwardDiff.jl" begin
t0 = time()
Expand Down

0 comments on commit c3203bf

Please sign in to comment.