Skip to content
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.35.1"
version = "0.35.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
6 changes: 5 additions & 1 deletion src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ function unflatten(vi::VarInfo, x::AbstractVector)
md = unflatten_metadata(vi.metadata, x)
# Note that use of RefValue{eltype(x)} rather than Ref is necessary to deal with cases
# where e.g. x is a type gradient of some AD backend.
return VarInfo(md, Base.RefValue{eltype(x)}(getlogp(vi)), Ref(get_num_produce(vi)))
return VarInfo(
md,
Base.RefValue{float_type_with_fallback(eltype(x))}(getlogp(vi)),
Ref(get_num_produce(vi)),
)
end

# We would call this `unflatten` if not for `unflatten` having a method for NamedTuples in
Expand Down
11 changes: 11 additions & 0 deletions test/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1017,4 +1017,15 @@ end
@test vi.metadata.b.orders == [2]
@test DynamicPPL.get_num_produce(vi) == 3
end

@testset "issue #842" begin
model = DynamicPPL.TestUtils.DEMO_MODELS[1]
varinfo = VarInfo(model)

n = length(varinfo[:])
# `Bool`.
@test getlogp(DynamicPPL.unflatten(varinfo, fill(true, n))) isa typeof(float(1))
# `Int`.
@test getlogp(DynamicPPL.unflatten(varinfo, fill(1, n))) isa typeof(float(1))
end
end
Loading