Skip to content

Commit

Permalink
Improved varname_and_value_leaves for Cholesky (#531)
Browse files Browse the repository at this point in the history
* varname_and_value_leaves now return x.L or x.U as varnames for cholesky

* updated docstring for varname_and_value_leaves

* bumped patch version
  • Loading branch information
torfjelde authored Sep 2, 2023
1 parent ba16e3b commit 1824fad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 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.23.15"
version = "0.23.16"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
18 changes: 11 additions & 7 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -936,15 +936,15 @@ julia> # `UpperTriangular`
julia> # `Cholesky` with lower-triangular
foreach(println, varname_and_value_leaves(@varname(x), Cholesky([1.0 0.0; 0.0 1.0], 'L', 0)))
(x[1,1], 1.0)
(x[2,1], 0.0)
(x[2,2], 1.0)
(x.L[1,1], 1.0)
(x.L[2,1], 0.0)
(x.L[2,2], 1.0)
julia> # `Cholesky` with upper-triangular
foreach(println, varname_and_value_leaves(@varname(x), Cholesky([1.0 0.0; 0.0 1.0], 'U', 0)))
(x[1,1], 1.0)
(x[1,2], 0.0)
(x[2,2], 1.0)
(x.U[1,1], 1.0)
(x.U[1,2], 0.0)
(x.U[2,2], 1.0)
```
"""
function varname_and_value_leaves(vn::VarName, x)
Expand Down Expand Up @@ -1019,7 +1019,11 @@ end
# Special types.
function varname_and_value_leaves_inner(vn::VarName, x::Cholesky)
# TODO: Or do we use `PDMat` here?
return varname_and_value_leaves_inner(vn, x.UL)
return if x.uplo == 'L'
varname_and_value_leaves_inner(vn Setfield.PropertyLens{:L}(), x.L)
else
varname_and_value_leaves_inner(vn Setfield.PropertyLens{:U}(), x.U)
end
end
function varname_and_value_leaves_inner(vn::VarName, x::LinearAlgebra.LowerTriangular)
return (
Expand Down

2 comments on commit 1824fad

@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/90701

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.23.16 -m "<description of version>" 1824fade78c39561afbf33c732d20294d1158490
git push origin v0.23.16

Please sign in to comment.