|
22 | 22 |
|
23 | 23 |
|
24 | 24 | @testset "test_with_logabsdet_jacobian" begin
|
25 |
| - x = Complex(0.2, -0.7) |
26 |
| - y, ladj_y = ChangesOfVariables._auto_with_logabsdet_jacobian(inv, x, ForwardDiff.jacobian, rv_and_back) |
27 |
| - @test y == inv(x) |
28 |
| - @test ladj_y ≈ -4 * log(abs(x)) |
29 |
| - |
30 |
| - X = Complex.(randn(3,3), randn(3,3)) |
31 |
| - Y, ladj_Y = ChangesOfVariables._auto_with_logabsdet_jacobian(inv, X, ForwardDiff.jacobian, rv_and_back) |
32 |
| - @test Y == inv(X) |
33 |
| - @test ladj_Y ≈ -4 * 3 * logabsdet(X)[1] |
| 25 | + rx = 0.5 |
| 26 | + cx = Complex(0.2, -0.7) |
| 27 | + X = rand(3, 3) |
| 28 | + CX = Complex.(randn(3,3), randn(3,3)) |
34 | 29 |
|
35 | 30 | myisapprox(a, b; kwargs...) = isapprox(a, b; kwargs...)
|
36 |
| - test_with_logabsdet_jacobian(inv, 0.5, ForwardDiff.derivative, test_inferred = true, atol = 10^-6) |
37 |
| - test_with_logabsdet_jacobian(inv, rand(2,2), ForwardDiff.jacobian, test_inferred = true, atol = 10^-6) |
38 |
| - test_with_logabsdet_jacobian(inv, X, ForwardDiff.jacobian, rv_and_back, test_inferred = true, atol = 10^-6) |
39 |
| - test_with_logabsdet_jacobian(inv, X, ForwardDiff.jacobian, rv_and_back, test_inferred = false, atol = 10^-6) |
40 |
| - test_with_logabsdet_jacobian(inv, X, ForwardDiff.jacobian, rv_and_back, compare = myisapprox, atol = 10^-6) |
| 31 | + |
| 32 | + noninferrable_inv(x) = x!=rand(size(x)...) ? inv(x) : "" |
| 33 | + ChangesOfVariables.with_logabsdet_jacobian(::typeof(noninferrable_inv), x) = noninferrable_inv(x), with_logabsdet_jacobian(inv, x)[2] |
| 34 | + @test_throws ErrorException @inferred with_logabsdet_jacobian(noninferrable_inv, rand(2, 2)) |
| 35 | + |
| 36 | + test_with_logabsdet_jacobian(inv, rx, ForwardDiff.derivative, atol = 10^-6) |
| 37 | + test_with_logabsdet_jacobian(inv, cx, ForwardDiff.jacobian, rv_and_back, atol = 10^-6) |
| 38 | + test_with_logabsdet_jacobian(inv, X, ForwardDiff.jacobian, atol = 10^-6) |
| 39 | + test_with_logabsdet_jacobian(inv, CX, ForwardDiff.jacobian, rv_and_back, atol = 10^-6) |
| 40 | + test_with_logabsdet_jacobian(inv, CX, ForwardDiff.jacobian, rv_and_back, atol = 10^-6) |
| 41 | + test_with_logabsdet_jacobian(inv, CX, ForwardDiff.jacobian, rv_and_back, compare = myisapprox, atol = 10^-6) |
| 42 | + test_with_logabsdet_jacobian(noninferrable_inv, CX, ForwardDiff.jacobian, rv_and_back, atol = 10^-6) |
41 | 43 | end
|
0 commit comments