Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
torfjelde committed Aug 31, 2023
1 parent d3b3473 commit 0f4914d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ function varname_leaves(vn::VarName, val::NamedTuple)
return Iterators.flatten(iter)
end


"""
varname_and_value_leaves(vn::VarName, val)
Expand Down Expand Up @@ -918,10 +917,7 @@ julia> # `UpperTriangular`
```
"""
function varname_and_value_leaves(vn::VarName, x)
return Iterators.map(
value,
Iterators.flatten(varname_and_value_leaves_inner(vn, x))
)
return Iterators.map(value, Iterators.flatten(varname_and_value_leaves_inner(vn, x)))
end

# Simple struct used to represent a varname-value pair even if we use
Expand All @@ -947,18 +943,17 @@ function varname_and_value_leaves_inner(
return (
Leaf(
VarName(vn, DynamicPPL.getlens(vn) DynamicPPL.Setfield.IndexLens(Tuple(I))),
val[I]
)
for I in CartesianIndices(val)
val[I],
) for I in CartesianIndices(val)
)
end
# Containers.
function varname_and_value_leaves_inner(vn::VarName, val::AbstractArray)
return Iterators.flatten(
varname_and_value_leaves_inner(
VarName(vn, DynamicPPL.getlens(vn) DynamicPPL.Setfield.IndexLens(Tuple(I))), val[I]
) for
I in CartesianIndices(val)
VarName(vn, DynamicPPL.getlens(vn) DynamicPPL.Setfield.IndexLens(Tuple(I))),
val[I],
) for I in CartesianIndices(val)
)
end
function varname_and_value_leaves_inner(vn::DynamicPPL.VarName, val::NamedTuple)
Expand All @@ -978,7 +973,7 @@ function varname_and_value_leaves_inner(vn::VarName, x::LinearAlgebra.LowerTrian
return (
Leaf(
VarName(vn, DynamicPPL.getlens(vn) DynamicPPL.Setfield.IndexLens(Tuple(I))),
x[I]
x[I],
)
# Iteration over the lower-triangular indices.
for I in CartesianIndices(x) if I[1] >= I[2]
Expand All @@ -988,7 +983,7 @@ function varname_and_value_leaves_inner(vn::VarName, x::LinearAlgebra.UpperTrian
return (
Leaf(
VarName(vn, DynamicPPL.getlens(vn) DynamicPPL.Setfield.IndexLens(Tuple(I))),
x[I]
x[I],
)
# Iteration over the upper-triangular indices.
for I in CartesianIndices(x) if I[1] <= I[2]
Expand Down

0 comments on commit 0f4914d

Please sign in to comment.