Skip to content

Commit 6cbb1c3

Browse files
committed
Use jldoctest on with_logabsdet_jacobian example
1 parent 3abd5a2 commit 6cbb1c3

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/with_ladj.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ For `(y, ladj) = with_logabsdet_jacobian(f, x)`, the following must hold true:
1414
`with_logabsdet_jacobian` comes with support for broadcasted/mapped functions
1515
(via `Base.Fix1`) and (Julia >=v1.6 only) `ComposedFunction`.
1616
17-
Example:
17+
# Examples
1818
19-
```julia
19+
```jldoctest a
2020
foo(x) = inv(exp(-x) + 1)
2121
2222
function ChangesOfVariables.with_logabsdet_jacobian(::typeof(foo), x)
@@ -28,14 +28,29 @@ end
2828
x = 4.2
2929
y, ladj_y = with_logabsdet_jacobian(foo, x)
3030
31-
X = rand(10)
31+
# output
32+
33+
(0.9852259683067269, -4.229768509343836)
34+
```
35+
36+
```jldoctest a
37+
X = [3, 7, 5]
3238
broadcasted_foo = Base.Fix1(broadcast, foo)
3339
Y, ladj_Y = with_logabsdet_jacobian(broadcasted_foo, X)
3440
41+
# output
42+
43+
([0.9525741268224334, 0.9990889488055994, 0.9933071490757153], -15.112428333033268)
44+
```
45+
46+
```jldoctest a
3547
# Requires Julia >= v1.6:
3648
z, ladj_z = with_logabsdet_jacobian(log ∘ foo, x)
37-
z == log(foo(x))
38-
ladj_z == ladj_y + with_logabsdet_jacobian(log, y)[2]
49+
z == log(foo(x)) && ladj_z == ladj_y + with_logabsdet_jacobian(log, y)[2]
50+
51+
# output
52+
53+
true
3954
```
4055
"""
4156
function with_logabsdet_jacobian end

0 commit comments

Comments
 (0)