Skip to content

Commit

Permalink
fix logabsdetjac for Stacked{<:Any, 1} (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
vandenman committed Sep 14, 2020
1 parent dfca913 commit 05d50bd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
@@ -1,6 +1,6 @@
name = "Bijectors"
uuid = "76274a88-744f-5084-9051-94815aaf08c4"
version = "0.8.3"
version = "0.8.4"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
4 changes: 4 additions & 0 deletions src/bijectors/stacked.jl
Expand Up @@ -104,6 +104,10 @@ function logabsdetjac(
end
end

function logabsdetjac(b::Stacked{<:Any, 1}, x::AbstractVector{<:Real})
return sum(logabsdetjac(b.bs[1], x[b.ranges[1]]))
end

function logabsdetjac(b::Stacked, x::AbstractMatrix{<:Real})
return map(eachcol(x)) do c
logabsdetjac(b, c)
Expand Down
8 changes: 8 additions & 0 deletions test/interface.jl
Expand Up @@ -708,6 +708,14 @@ end
# AD verification
@test log(abs(det(ForwardDiff.jacobian(sb, x)))) logabsdetjac(sb, x)
@test log(abs(det(ForwardDiff.jacobian(isb, y)))) logabsdetjac(isb, y)

# Ensure `Stacked` works for a single bijector
d = (MvNormal(2, 1.0),)
sb = Stacked(bijector.(d), [1:2])
x = [.5, 1.]
@test sb(x) == x
@test logabsdetjac(sb, x) == 0
@test forward(sb, x) == (rv = x, logabsdetjac = zero(eltype(x)))
end
end

Expand Down

2 comments on commit 05d50bd

@devmotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/21368

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.8.4 -m "<description of version>" 05d50bd26be6c8a473fcdabfaa00c2beb060046b
git push origin v0.8.4

Please sign in to comment.