Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.13.5

Implemented a generic `varname_leaves` and `varname_and_value_leaves` for other unsupported types.

## 0.13.4

Added missing methods for `subsumes(::IndexLens, ::PropertyLens)` and vice versa.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
keywords = ["probablistic programming"]
license = "MIT"
desc = "Common interfaces for probabilistic programming"
version = "0.13.4"
version = "0.13.5"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
4 changes: 4 additions & 0 deletions src/varname/leaves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function varname_leaves(vn::VarName, x::LinearAlgebra.UpperTriangular)
VarName{getsym(vn)}(Accessors.IndexLens(Tuple(I)) ∘ getoptic(vn))
end
end
# This is a default fallback for types that we don't know how to handle.
varname_leaves(vn::VarName, @nospecialize(::Any)) = [vn]

"""
varname_and_value_leaves(vn::VarName, val)
Expand Down Expand Up @@ -259,3 +261,5 @@ function varname_and_value_leaves_inner(vn::VarName, x::LinearAlgebra.UpperTrian
for I in CartesianIndices(x) if I[1] <= I[2]
)
end
# This is a default fallback for types that we don't know how to handle.
varname_and_value_leaves_inner(vn::VarName, @nospecialize(x::Any)) = [Leaf(vn, x)]
11 changes: 11 additions & 0 deletions test/varname.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,16 @@ end
(@varname(x.U[2, 2]), x.U[2, 2]),
])
end

@testset "fallback on other types, e.g. string" begin
x = "a string"
@test Set(varname_leaves(@varname(x), x)) == Set([@varname(x)])
@test Set(collect(varname_and_value_leaves(@varname(x), x))) ==
Set([(@varname(x), x)])
x = 2
@test Set(varname_leaves(@varname(x), x)) == Set([@varname(x)])
@test Set(collect(varname_and_value_leaves(@varname(x), x))) ==
Set([(@varname(x), x)])
end
end
end
Loading