From 2ad56a0a9de732cea3d9719cdfc8da04f8678f94 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 12:38:43 +0100 Subject: [PATCH 1/7] fix for unwrap_right_left_vns --- src/compiler.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler.jl b/src/compiler.jl index c70bbff1e..83a10e769 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -103,7 +103,7 @@ function unwrap_right_left_vns( # for `i = size(left, 2)`. Hence the symbol should be `x[:, i]`, # and we therefore add the `Colon()` below. vns = map(axes(left, 2)) do i - return VarName(vn, (vn.indexing..., Colon(), Tuple(i))) + return VarName(vn, (vn.indexing..., (Colon(), i))) end return unwrap_right_left_vns(right, left, vns) end From 895d28045bfcdbbcfa05625ac1c46419d6c3c310 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 12:43:31 +0100 Subject: [PATCH 2/7] added tests covering previous bugs --- src/compiler.jl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/compiler.jl b/src/compiler.jl index 83a10e769..cba051781 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -90,6 +90,35 @@ left-hand side of a `.~` expression such as `x .~ Normal()`. This is used mainly to unwrap `NamedDist` distributions and adjust the indices of the variables. + +# Example +```jldoctest; setup=:(using Distributions) +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(MvNormal(1, 1.0), randn(1, 2), @varname(x)); vns +2-element Vector{VarName{:x, Tuple{Tuple{Colon, Int64}}}}: + x[:,1] + x[:,2] + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2), @varname(x[:])); vns +1×2 Matrix{VarName{:x, Tuple{Tuple{Colon}, Tuple{Int64, Int64}}}}: + x[:][1,1] x[:][1,2] + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(3), @varname(x[1])); vns +3-element Vector{VarName{:x, Tuple{Tuple{Int64}, Tuple{Int64}}}}: + x[1][1] + x[1][2] + x[1][3] + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2, 3), @varname(x)); vns +1×2×3 Array{VarName{:x, Tuple{Tuple{Int64, Int64, Int64}}}, 3}: +[:, :, 1] = + x[1,1,1] x[1,2,1] + +[:, :, 2] = + x[1,1,2] x[1,2,2] + +[:, :, 3] = + x[1,1,3] x[1,2,3] +``` """ unwrap_right_left_vns(right, left, vns) = right, left, vns function unwrap_right_left_vns(right::NamedDist, left, vns) From 0f4aa158936f403584a4e36caae49f7d78e1e274 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 12:45:07 +0100 Subject: [PATCH 3/7] bump patch version and allow old AbstractPPL so we can simply downgrade in deps if need be --- Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 5678c050a..49d2c0cea 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DynamicPPL" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.13.0" +version = "0.13.1" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" @@ -14,7 +14,7 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [compat] AbstractMCMC = "2, 3.0" -AbstractPPL = "0.2" +AbstractPPL = "0.1.4, 0.2" Bijectors = "0.5.2, 0.6, 0.7, 0.8, 0.9" ChainRulesCore = "0.9.7, 0.10" Distributions = "0.23.8, 0.24, 0.25" From 33b404a6bb2367bde7310483f211d27e6bbc1f7b Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 12:46:31 +0100 Subject: [PATCH 4/7] test only the most recent version of APPL --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index 9ca62c79e..c523f6092 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -20,7 +20,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] AbstractMCMC = "2.1, 3.0" -AbstractPPL = "0.1.4, 0.2" +AbstractPPL = "0.2" Bijectors = "0.9.5" Distributions = "< 0.25.11" DistributionsAD = "0.6.3" From 0f82e02f027fdb3fd3c5ba5802d8ec48410f0c1c Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 12:47:34 +0100 Subject: [PATCH 5/7] nvm only allow most recent version of APPL --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 49d2c0cea..0b92e07d2 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [compat] AbstractMCMC = "2, 3.0" -AbstractPPL = "0.1.4, 0.2" +AbstractPPL = "0.2" Bijectors = "0.5.2, 0.6, 0.7, 0.8, 0.9" ChainRulesCore = "0.9.7, 0.10" Distributions = "0.23.8, 0.24, 0.25" From 6f7e3024b8d61552f62a1f80b90dba8ee5bc758a Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 16:07:46 +0100 Subject: [PATCH 6/7] fixed doctests --- src/compiler.jl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/compiler.jl b/src/compiler.jl index cba051781..d5ad1c040 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -93,31 +93,31 @@ variables. # Example ```jldoctest; setup=:(using Distributions) -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(MvNormal(1, 1.0), randn(1, 2), @varname(x)); vns -2-element Vector{VarName{:x, Tuple{Tuple{Colon, Int64}}}}: - x[:,1] - x[:,2] - -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2), @varname(x[:])); vns -1×2 Matrix{VarName{:x, Tuple{Tuple{Colon}, Tuple{Int64, Int64}}}}: - x[:][1,1] x[:][1,2] - -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(3), @varname(x[1])); vns -3-element Vector{VarName{:x, Tuple{Tuple{Int64}, Tuple{Int64}}}}: - x[1][1] - x[1][2] - x[1][3] - -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2, 3), @varname(x)); vns -1×2×3 Array{VarName{:x, Tuple{Tuple{Int64, Int64, Int64}}}, 3}: +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(MvNormal(1, 1.0), randn(1, 2), @varname(x)); map(string, vns) +2-element Vector{String}: + "x[:,1]" + "x[:,2]" + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2), @varname(x[:])); map(string, vns) +1×2 Matrix{String}: + "x[:][1,1]" "x[:][1,2]" + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(3), @varname(x[1])); map(string, vns) +3-element Vector{String}: + "x[1][1]" + "x[1][2]" + "x[1][3]" + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2, 3), @varname(x)); map(string, vns) +1×2×3 Array{String, 3}: [:, :, 1] = - x[1,1,1] x[1,2,1] + "x[1,1,1]" "x[1,2,1]" [:, :, 2] = - x[1,1,2] x[1,2,2] + "x[1,1,2]" "x[1,2,2]" [:, :, 3] = - x[1,1,3] x[1,2,3] + "x[1,1,3]" "x[1,2,3]" ``` """ unwrap_right_left_vns(right, left, vns) = right, left, vns From 7a07a31588764f5833453da28e99aa392381a22e Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 30 Jul 2021 16:33:59 +0100 Subject: [PATCH 7/7] finally fixed doctests --- src/compiler.jl | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/compiler.jl b/src/compiler.jl index d5ad1c040..6de2f0945 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -93,31 +93,17 @@ variables. # Example ```jldoctest; setup=:(using Distributions) -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(MvNormal(1, 1.0), randn(1, 2), @varname(x)); map(string, vns) -2-element Vector{String}: - "x[:,1]" - "x[:,2]" - -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2), @varname(x[:])); map(string, vns) -1×2 Matrix{String}: - "x[:][1,1]" "x[:][1,2]" - -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(3), @varname(x[1])); map(string, vns) -3-element Vector{String}: - "x[1][1]" - "x[1][2]" - "x[1][3]" - -julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2, 3), @varname(x)); map(string, vns) -1×2×3 Array{String, 3}: -[:, :, 1] = - "x[1,1,1]" "x[1,2,1]" - -[:, :, 2] = - "x[1,1,2]" "x[1,2,2]" - -[:, :, 3] = - "x[1,1,3]" "x[1,2,3]" +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(MvNormal(1, 1.0), randn(1, 2), @varname(x)); string(vns[end]) +"x[:,2]" + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2), @varname(x[:])); string(vns[end]) +"x[:][1,2]" + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(3), @varname(x[1])); string(vns[end]) +"x[1][3]" + +julia> _, _, vns = DynamicPPL.unwrap_right_left_vns(Normal(), randn(1, 2, 3), @varname(x)); string(vns[end]) +"x[1,2,3]" ``` """ unwrap_right_left_vns(right, left, vns) = right, left, vns