Skip to content

Commit

Permalink
Removed usage of setindex! (#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 committed Nov 8, 2022
1 parent 6977dc0 commit b2ad13c
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

2 comments on commit b2ad13c

@torfjelde
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71895

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.21.2 -m "<description of version>" b2ad13ca24cb4934c2fc212afefdeb296c2d119f
git push origin v0.21.2

Please sign in to comment.