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 for type instability when using LKJChol #548

Merged
merged 3 commits into from
Oct 23, 2023
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 = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.23.19"
version = "0.23.20"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ reconstruct(::MatrixDistribution, val::AbstractMatrix{<:Real}) = copy(val)
reconstruct(::Inverse{Bijectors.VecCorrBijector}, ::LKJ, val::AbstractVector) = copy(val)

function reconstruct(dist::LKJCholesky, val::AbstractVector{<:Real})
return reconstruct(dist, reshape(val, size(dist)))
return reconstruct(dist, Matrix(reshape(val, size(dist))))
end
function reconstruct(dist::LKJCholesky, val::AbstractMatrix{<:Real})
return Cholesky(val, dist.uplo, 0)
Expand Down
32 changes: 32 additions & 0 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ function innermost_distribution_type(d::Distributions.Product)
return dists[1]
end

is_typed_varinfo(::DynamicPPL.AbstractVarInfo) = false
is_typed_varinfo(varinfo::DynamicPPL.TypedVarInfo) = true
is_typed_varinfo(varinfo::DynamicPPL.SimpleVarInfo{<:NamedTuple}) = true

@testset "model.jl" begin
@testset "convenience functions" begin
model = gdemo_default # defined in test/test_util.jl
Expand Down Expand Up @@ -329,4 +333,32 @@ end
@test x_true.UL == result.x.UL
end
end

@testset "Type stability of models" begin
models_to_test = [
# FIXME: Fix issues with type-stability in `DEMO_MODELS`.
# DynamicPPL.TestUtils.DEMO_MODELS...,
DynamicPPL.TestUtils.demo_lkjchol(2),
]
@testset "$(model.f)" for model in models_to_test
vns = DynamicPPL.TestUtils.varnames(model)
example_values = DynamicPPL.TestUtils.rand(model)
varinfos = filter(
is_typed_varinfo,
DynamicPPL.TestUtils.setup_varinfos(model, example_values, vns),
)
@testset "$(short_varinfo_name(varinfo))" for varinfo in varinfos
@test (@inferred(DynamicPPL.evaluate!!(model, varinfo, DefaultContext()));
true)

varinfo_linked = DynamicPPL.link(varinfo, model)
@test (
@inferred(
DynamicPPL.evaluate!!(model, varinfo_linked, DefaultContext())
);
true
)
end
end
end
end
Loading