Skip to content

Commit 23bfe54

Browse files
committed
introduce vector_length instead of length, since length already
refers to the dictionary-like length impl, not vector-like
1 parent 9cf72a0 commit 23bfe54

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/varinfo.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ end
203203
VarInfo(model::Model, args...) = VarInfo(Random.default_rng(), model, args...)
204204

205205

206-
Base.length(varinfo::VarInfo) = length(varinfo.metadata)
207-
Base.length(varinfo::TypedVarInfo) = sum(length, varinfo.metadata)
208-
Base.length(md::Metadata) = sum(length, md.ranges)
206+
vector_length(varinfo::VarInfo) = length(varinfo.metadata)
207+
vector_length(varinfo::TypedVarInfo) = sum(length, varinfo.metadata)
208+
vector_length(md::Metadata) = sum(length, md.ranges)
209209

210210
unflatten(vi::VarInfo, x::AbstractVector) = unflatten(vi, SampleFromPrior(), x)
211211

@@ -653,7 +653,7 @@ function getranges(varinfo::DynamicPPL.TypedVarInfo, vns::Vector{<:DynamicPPL.Va
653653
# TODO: Does it help if we _don't_ convert to a vector here?
654654
metadatas = collect(values(varinfo.metadata))
655655
# Extract the offsets.
656-
offsets = cumsum(map(length, metadatas))
656+
offsets = cumsum(map(vector_length, metadatas))
657657
# Extract the ranges from each metadata.
658658
ranges = Vector{UnitRange{Int}}(undef, length(vns))
659659
for (i, metadata) in enumerate(metadatas)

src/varnamedvector.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,8 @@ function replace_raw_storage(vnv::VarNamedVector, ::Val{space}, vals) where {spa
10361036
return replace_raw_storage(vnv, vals)
10371037
end
10381038

1039+
vector_length(vnv::VarNamedVector) = length(vnv.vals) - num_inactive(vnv)
1040+
10391041
"""
10401042
unflatten(vnv::VarNamedVector, vals::AbstractVector)
10411043

0 commit comments

Comments
 (0)