Skip to content

Commit a04c39e

Browse files
committed
Fix varinfo[:] for empty varinfo
1 parent 3acd0a2 commit a04c39e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/varinfo.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,9 @@ getindex_internal(vi::VarInfo, ::Colon) = getindex_internal(vi.metadata, Colon()
854854
function getindex_internal(vi::NTVarInfo, ::Colon)
855855
return reduce(vcat, map(Base.Fix2(getindex_internal, Colon()), vi.metadata))
856856
end
857+
function getindex_internal(vi::VarInfo{NamedTuple{(),Tuple{}}}, ::Colon)
858+
return float(Real)[]
859+
end
857860
function getindex_internal(md::Metadata, ::Colon)
858861
return mapreduce(
859862
Base.Fix1(getindex_internal, md), vcat, md.vns; init=similar(md.vals, 0)

test/varinfo.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ end
7979
@test hash(vn2) == hash(vn1)
8080

8181
function test_base!!(vi_original)
82-
vi = empty!!(vi_original)
82+
vi = empty!!(deepcopy(vi_original))
8383
@test getlogp(vi) == 0
8484
@test isempty(vi[:])
8585

@@ -97,8 +97,10 @@ end
9797

9898
@test length(vi[vn]) == 1
9999
@test vi[vn] == r
100+
@test vi[:] == [r]
100101
vi = DynamicPPL.setindex!!(vi, 2 * r, vn)
101102
@test vi[vn] == 2 * r
103+
@test vi[:] == [2 * r]
102104

103105
# TODO(mhauru) Implement these functions for other VarInfo types too.
104106
if vi isa DynamicPPL.UntypedVectorVarInfo

0 commit comments

Comments
 (0)