Skip to content

Commit

Permalink
Removed usage of setindex! (TuringLang#432)
Browse files Browse the repository at this point in the history
Some usages of `setindex!` were still there causing issues with `ThreadSafeVarInfo`, which does not have such an implementation.
  • Loading branch information
torfjelde authored and Alexey Stukalov committed Mar 21, 2023
1 parent e5c18f7 commit 038a4e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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.21.1"
version = "0.21.2"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
16 changes: 8 additions & 8 deletions src/context_implementations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ end

function get_and_set_val!(
rng,
vi::AbstractVarInfo,
vi::VarInfoOrThreadSafeVarInfo,
vns::AbstractVector{<:VarName},
dist::MultivariateDistribution,
spl::Union{SampleFromPrior,SampleFromUniform},
Expand All @@ -470,7 +470,7 @@ function get_and_set_val!(
r = init(rng, dist, spl, n)
for i in 1:n
vn = vns[i]
vi[vn] = vectorize(dist, maybe_link(vi, vn, dist, r[:, i]))
setindex!!(vi, vectorize(dist, maybe_link(vi, vn, dist, r[:, i])), vn)
setorder!(vi, vn, get_num_produce(vi))
end
else
Expand All @@ -494,7 +494,7 @@ end

function get_and_set_val!(
rng,
vi::AbstractVarInfo,
vi::VarInfoOrThreadSafeVarInfo,
vns::AbstractArray{<:VarName},
dists::Union{Distribution,AbstractArray{<:Distribution}},
spl::Union{SampleFromPrior,SampleFromUniform},
Expand All @@ -508,7 +508,7 @@ function get_and_set_val!(
for i in eachindex(vns)
vn = vns[i]
dist = dists isa AbstractArray ? dists[i] : dists
vi[vn] = vectorize(dist, maybe_link(vi, vn, dist, r[i]))
setindex!!(vi, vectorize(dist, maybe_link(vi, vn, dist, r[i])), vn)
setorder!(vi, vn, get_num_produce(vi))
end
else
Expand Down Expand Up @@ -538,27 +538,27 @@ function get_and_set_val!(
end

function set_val!(
vi::AbstractVarInfo,
vi::VarInfoOrThreadSafeVarInfo,
vns::AbstractVector{<:VarName},
dist::MultivariateDistribution,
val::AbstractMatrix,
)
@assert size(val, 2) == length(vns)
foreach(enumerate(vns)) do (i, vn)
vi[vn] = val[:, i]
setindex!!(vi, val[:, i], vn)
end
return val
end
function set_val!(
vi::AbstractVarInfo,
vi::VarInfoOrThreadSafeVarInfo,
vns::AbstractArray{<:VarName},
dists::Union{Distribution,AbstractArray{<:Distribution}},
val::AbstractArray,
)
@assert size(val) == size(vns)
foreach(CartesianIndices(val)) do ind
dist = dists isa AbstractArray ? dists[ind] : dists
vi[vns[ind]] = vectorize(dist, val[ind])
setindex!!(vi, vectorize(dist, val[ind]), vns[ind])
end
return val
end
Expand Down

0 comments on commit 038a4e3

Please sign in to comment.