Skip to content

Commit 65b2de4

Browse files
committed
added handling of duplicated values
1 parent cd78d24 commit 65b2de4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/varinfo.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,11 @@ function vector_getranges(varinfo::TypedVarInfo, vns::Vector{<:VarName})
683683
for vn in vns_metadata
684684
r_vn = getrange(metadata, vn)
685685
# Get the index, so we return in the same order as `vns`.
686-
idx = findfirst(==(vn), vns)
687-
ranges[idx] = r_vn .+ offset
686+
# NOTE: There might be duplicates in `vns`, so we need to handle that.
687+
indices = findall(==(vn), vns)
688+
for idx in indices
689+
ranges[idx] = r_vn .+ offset
690+
end
688691
end
689692
end
690693
# Raise key error if any of the variables were not found.

test/varinfo.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,9 @@ DynamicPPL.getspace(::DynamicPPL.Sampler{MySAlg}) = (:s,)
849849
@test_throws KeyError DynamicPPL.vector_getranges(
850850
varinfo, [VarName{gensym("vn")}(), VarName{gensym("vn")}()]
851851
)
852+
# Duplicate variables.
853+
ranges_duplicated = DynamicPPL.vector_getranges(varinfo, repeat(vns, 2))
854+
@test x[reduce(vcat, ranges_duplicated)] == repeat(x, 2)
852855
end
853856
end
854857
end

0 commit comments

Comments
 (0)