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

Fix infinite recursion in CorrBijector/VecCorrBijector #355

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

penelopeysm
Copy link
Member

Closes #320

With this PR:

julia> using Bijectors: CorrBijector, VecCorrBijector, inverse

julia> v = [1.0]; m = [[1.0]]
1-element Vector{Vector{Float64}}:
 [1.0]

julia> CorrBijector()(v)
ERROR: MethodError: no method matching cholesky_upper(::Vector{Float64})

julia> inverse(CorrBijector())(m)
ERROR: MethodError: no method matching AbstractFloat(::Type{Vector{Float64}})

julia> inverse(VecCorrBijector())(m)
ERROR: MethodError: no method matching AbstractFloat(::Type{Vector{Float64}})

Previously, all of these would fail with StackOverflowError due to infinite recursion between

function transform(t::Transform, x)
res = with_logabsdet_jacobian(t, x)

and

function with_logabsdet_jacobian(ib::Inverse{<:Transform}, y)
x = transform(ib, y)
return x, -logabsdetjac(inverse(ib), x)
end

or in the case of CorrBijector

with_logabsdet_jacobian(b::CorrBijector, x) = transform(b, x), logabsdetjac(b, x)

Copy link
Member

@torfjelde torfjelde left a comment

Choose a reason for hiding this comment

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

Lovely stuff @penelopeysm :)

@penelopeysm penelopeysm merged commit f52a9c5 into master Nov 30, 2024
33 checks passed
@penelopeysm penelopeysm deleted the py/fix-recursion branch November 30, 2024 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StackOverflow on calling inverse VecCorrBijector with a multidimensional array
2 participants