Skip to content

Commit

Permalink
Merge branch 'master' into sunxd/remove_tonamedtuple
Browse files Browse the repository at this point in the history
  • Loading branch information
yebai authored Oct 25, 2023
2 parents 324cb8e + 12e7c27 commit cea3ed9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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

0 comments on commit cea3ed9

Please sign in to comment.