Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for SimplexBijector on Matrix #302

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Bijectors"
uuid = "76274a88-744f-5084-9051-94815aaf08c4"
version = "0.13.8"
version = "0.13.9"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
6 changes: 6 additions & 0 deletions src/bijectors/simplex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ function logabsdetjac(b::SimplexBijector, x::AbstractVector{T}) where {T}

return -lp
end

# Needed to avoid falling back to `with_logabsdet_jacobian` for matrix inputs.
Copy link
Member

Choose a reason for hiding this comment

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

Which calls logabsdetjac again causing a stackoverflow error (had to check the code to realize this is the underlying problem).

function logabsdetjac(b::SimplexBijector, x::AbstractMatrix{<:Real})
return sum(Base.Fix1(logabsdetjac, b), eachcol(x))
end

function simplex_logabsdetjac_gradient(x::AbstractVector)
T = eltype(x)
ϵ = _eps(T)
Expand Down
1 change: 1 addition & 0 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ end
filldist(Exponential(), 2),
filldist(Exponential(), 2, 3),
filldist(filldist(Exponential(), 2), 3),
filldist(Dirichlet(ones(2)), 3),
]
x = rand(dist)
b = bijector(dist)
Expand Down
Loading