597
597
"""
598
598
function parent (vn:: VarName )
599
599
p = parent (getoptic (vn))
600
- return p === nothing ? VarName (vn, identity) : VarName (vn, p)
600
+ return p === nothing ? VarName {getsym (vn)} ( identity) : VarName {getsym (vn)} ( p)
601
601
end
602
602
603
603
"""
@@ -712,7 +712,7 @@ ERROR: Could not find x.a[2] in x.a[1]
712
712
function remove_parent_optic (vn_parent:: VarName{sym} , vn_child:: VarName{sym} ) where {sym}
713
713
_, child, issuccess = splitoptic (getoptic (vn_child)) do optic
714
714
o = optic === nothing ? identity : optic
715
- VarName (vn_child, o) == vn_parent
715
+ o == getoptic ( vn_parent)
716
716
end
717
717
718
718
issuccess || error (" Could not find $vn_parent in $vn_child " )
@@ -907,7 +907,7 @@ function hasvalue(vals::AbstractDict, vn::VarName)
907
907
# If `issuccess` is `true`, we found such a split, and hence `vn` is present.
908
908
parent, child, issuccess = splitoptic (getoptic (vn)) do optic
909
909
o = optic === nothing ? identity : optic
910
- haskey (vals, VarName (vn, o))
910
+ haskey (vals, VarName {getsym (vn)} ( o))
911
911
end
912
912
# When combined with `VarInfo`, `nothing` is equivalent to `identity`.
913
913
keyoptic = parent === nothing ? identity : parent
@@ -916,7 +916,7 @@ function hasvalue(vals::AbstractDict, vn::VarName)
916
916
issuccess || return false
917
917
918
918
# At this point we just need to check that we `canview` the value.
919
- value = vals[VarName (vn, keyoptic)]
919
+ value = vals[VarName {getsym (vn)} ( keyoptic)]
920
920
921
921
return canview (child, value)
922
922
end
@@ -936,7 +936,7 @@ function nested_getindex(values::AbstractDict, vn::VarName)
936
936
# Split the optic into the key / `parent` and the extraction optic / `child`.
937
937
parent, child, issuccess = splitoptic (getoptic (vn)) do optic
938
938
o = optic === nothing ? identity : optic
939
- haskey (values, VarName (vn, o))
939
+ haskey (values, VarName {getsym (vn)} ( o))
940
940
end
941
941
# When combined with `VarInfo`, `nothing` is equivalent to `identity`.
942
942
keyoptic = parent === nothing ? identity : parent
@@ -949,7 +949,7 @@ function nested_getindex(values::AbstractDict, vn::VarName)
949
949
950
950
# TODO : Should we also check that we `canview` the extracted `value`
951
951
# rather than just let it fail upon `get` call?
952
- value = values[VarName (vn, keyoptic)]
952
+ value = values[VarName {getsym (vn)} ( keyoptic)]
953
953
return child (value)
954
954
end
955
955
@@ -1067,20 +1067,21 @@ x.z[2][1]
1067
1067
varname_leaves (vn:: VarName , :: Real ) = [vn]
1068
1068
function varname_leaves (vn:: VarName , val:: AbstractArray{<:Union{Real,Missing}} )
1069
1069
return (
1070
- VarName (vn, Accessors. IndexLens (Tuple (I)) ∘ getoptic (vn)) for
1070
+ VarName {getsym (vn)} ( Accessors. IndexLens (Tuple (I)) ∘ getoptic (vn)) for
1071
1071
I in CartesianIndices (val)
1072
1072
)
1073
1073
end
1074
1074
function varname_leaves (vn:: VarName , val:: AbstractArray )
1075
1075
return Iterators. flatten (
1076
- varname_leaves (VarName (vn, Accessors. IndexLens (Tuple (I)) ∘ getoptic (vn)), val[I])
1077
- for I in CartesianIndices (val)
1076
+ varname_leaves (
1077
+ VarName {getsym(vn)} (Accessors. IndexLens (Tuple (I)) ∘ getoptic (vn)), val[I]
1078
+ ) for I in CartesianIndices (val)
1078
1079
)
1079
1080
end
1080
1081
function varname_leaves (vn:: VarName , val:: NamedTuple )
1081
- iter = Iterators. map (keys (val)) do sym
1082
- optic = Accessors. PropertyLens {sym } ()
1083
- varname_leaves (VarName (vn, optic ∘ getoptic (vn)), optic (val))
1082
+ iter = Iterators. map (keys (val)) do k
1083
+ optic = Accessors. PropertyLens {k } ()
1084
+ varname_leaves (VarName {getsym (vn)} ( optic ∘ getoptic (vn)), optic (val))
1084
1085
end
1085
1086
return Iterators. flatten (iter)
1086
1087
end
@@ -1110,7 +1111,7 @@ julia> foreach(println, varname_and_value_leaves(@varname(x), x))
1110
1111
(x.z[2][1], 3.0)
1111
1112
```
1112
1113
1113
- There are also some special handling for certain types:
1114
+ There is also some special handling for certain types:
1114
1115
1115
1116
```jldoctest varname-and-value-leaves
1116
1117
julia> using LinearAlgebra
@@ -1229,7 +1230,7 @@ function varname_and_value_leaves_inner(
1229
1230
)
1230
1231
return (
1231
1232
Leaf (
1232
- VarName (vn, DynamicPPL . Accessors. IndexLens (Tuple (I)) ∘ DynamicPPL . getoptic (vn)),
1233
+ VarName {getsym (vn)} ( Accessors. IndexLens (Tuple (I)) ∘ AbstractPPL . getoptic (vn)),
1233
1234
val[I],
1234
1235
) for I in CartesianIndices (val)
1235
1236
)
@@ -1238,14 +1239,14 @@ end
1238
1239
function varname_and_value_leaves_inner (vn:: VarName , val:: AbstractArray )
1239
1240
return Iterators. flatten (
1240
1241
varname_and_value_leaves_inner (
1241
- VarName (vn, DynamicPPL . Accessors. IndexLens (Tuple (I)) ∘ DynamicPPL . getoptic (vn)),
1242
+ VarName {getsym (vn)} ( Accessors. IndexLens (Tuple (I)) ∘ AbstractPPL . getoptic (vn)),
1242
1243
val[I],
1243
1244
) for I in CartesianIndices (val)
1244
1245
)
1245
1246
end
1246
- function varname_and_value_leaves_inner (vn:: DynamicPPL. VarName , val:: NamedTuple )
1247
- iter = Iterators. map (keys (val)) do sym
1248
- optic = DynamicPPL . Accessors. PropertyLens {sym } ()
1247
+ function varname_and_value_leaves_inner (vn:: VarName , val:: NamedTuple )
1248
+ iter = Iterators. map (keys (val)) do k
1249
+ optic = Accessors. PropertyLens {k } ()
1249
1250
varname_and_value_leaves_inner (
1250
1251
VarName {getsym(vn)} (optic ∘ getoptic (vn)), optic (val)
1251
1252
)
@@ -1264,20 +1265,14 @@ function varname_and_value_leaves_inner(vn::VarName, x::Cholesky)
1264
1265
end
1265
1266
function varname_and_value_leaves_inner (vn:: VarName , x:: LinearAlgebra.LowerTriangular )
1266
1267
return (
1267
- Leaf (
1268
- VarName (vn, DynamicPPL. Accessors. IndexLens (Tuple (I)) ∘ DynamicPPL. getoptic (vn)),
1269
- x[I],
1270
- )
1268
+ Leaf (VarName {getsym(vn)} (Accessors. IndexLens (Tuple (I)) ∘ getoptic (vn)), x[I])
1271
1269
# Iteration over the lower-triangular indices.
1272
1270
for I in CartesianIndices (x) if I[1 ] >= I[2 ]
1273
1271
)
1274
1272
end
1275
1273
function varname_and_value_leaves_inner (vn:: VarName , x:: LinearAlgebra.UpperTriangular )
1276
1274
return (
1277
- Leaf (
1278
- VarName (vn, DynamicPPL. Accessors. IndexLens (Tuple (I)) ∘ DynamicPPL. getoptic (vn)),
1279
- x[I],
1280
- )
1275
+ Leaf (VarName {getsym(vn)} (Accessors. IndexLens (Tuple (I)) ∘ getoptic (vn)), x[I])
1281
1276
# Iteration over the upper-triangular indices.
1282
1277
for I in CartesianIndices (x) if I[1 ] <= I[2 ]
1283
1278
)
0 commit comments