Skip to content

Commit

Permalink
parameterise gradient test for PD bijector properly instead of using
Browse files Browse the repository at this point in the history
ForwardDiff as per suggestion of @devmotion
  • Loading branch information
torfjelde committed Aug 7, 2023
1 parent 951028e commit 4fe6085
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/ad/pd.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
_topd(x) = x * x' + I

@testset "AD for PD bijector" begin
d = 4
dist = Wishart(4, Matrix{Float64}(Distributions.I, d, d))
x = rand(dist)
b = bijector(dist)
binv = inverse(b)

z = randn(d, d)
x = _topd(z)
y = b(x)

test_ad(vec(x); use_forwarddiff_as_truth=true) do x
sum(transform(b, reshape(x, d, d)))
test_ad(vec(z)) do x
sum(transform(b, _topd(reshape(x, d, d))))
end

test_ad(y; use_forwarddiff_as_truth=true) do y
test_ad(y) do y
sum(transform(binv, y))
end
end

0 comments on commit 4fe6085

Please sign in to comment.