Skip to content

Commit cabe46d

Browse files
committed
Stabilize doctests
1 parent 69e26e8 commit cabe46d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
4+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
35
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
46

57
[compat]

src/with_ladj.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ For `(y, ladj) = with_logabsdet_jacobian(f, x)`, the following must hold true:
1717
# Examples
1818
1919
```jldoctest a
20+
using ChangesOfVariables
21+
2022
foo(x) = inv(exp(-x) + 1)
2123
2224
function ChangesOfVariables.with_logabsdet_jacobian(::typeof(foo), x)
@@ -28,25 +30,30 @@ end
2830
x = 4.2
2931
y, ladj_y = with_logabsdet_jacobian(foo, x)
3032
33+
using LinearAlgebra, ForwardDiff
34+
y == foo(x) && ladj_y ≈ log(abs(ForwardDiff.derivative(foo, x)))
35+
3136
# output
3237
33-
(0.9852259683067269, -4.229768509343836)
38+
true
3439
```
3540
3641
```jldoctest a
37-
X = [3, 7, 5]
42+
X = rand(10)
3843
broadcasted_foo = Base.Fix1(broadcast, foo)
3944
Y, ladj_Y = with_logabsdet_jacobian(broadcasted_foo, X)
45+
Y == broadcasted_foo(X) && ladj_Y ≈ logabsdet(ForwardDiff.jacobian(broadcasted_foo, X))[1]
4046
4147
# output
4248
43-
([0.9525741268224334, 0.9990889488055994, 0.9933071490757153], -15.112428333033268)
49+
true
4450
```
4551
4652
```jldoctest a
47-
# Requires Julia >= v1.6:
48-
z, ladj_z = with_logabsdet_jacobian(log ∘ foo, x)
49-
z == log(foo(x)) && ladj_z == ladj_y + with_logabsdet_jacobian(log, y)[2]
53+
VERSION < v"1.6" || begin # Support for ∘ requires Julia >= v1.6
54+
z, ladj_z = with_logabsdet_jacobian(log ∘ foo, x)
55+
z == log(foo(x)) && ladj_z == ladj_y + with_logabsdet_jacobian(log, y)[2]
56+
end
5057
5158
# output
5259

0 commit comments

Comments
 (0)