From 084ce899aa8c5ada67665aa3a6cf5732a12b05c5 Mon Sep 17 00:00:00 2001 From: Philipp Gabler Date: Sun, 28 Nov 2021 19:50:40 +0100 Subject: [PATCH 1/2] Depend on DensityInterface.jl and corresponding APPL version --- Project.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 20985b109..e07712d20 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ AbstractPPL = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf" BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66" Bijectors = "76274a88-744f-5084-9051-94815aaf08c4" ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" +DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" @@ -18,10 +19,11 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [compat] AbstractMCMC = "2, 3.0" -AbstractPPL = "0.3" +AbstractPPL = "0.4" BangBang = "0.3" Bijectors = "0.5.2, 0.6, 0.7, 0.8, 0.9" ChainRulesCore = "0.9.7, 0.10, 1" +DensityInterface = "0.4" Distributions = "0.23.8, 0.24, 0.25" MacroTools = "0.5.6" Setfield = "0.7.1, 0.8" From d5f79ac4b86d55436a98e19574cd92ed77991d33 Mon Sep 17 00:00:00 2001 From: Philipp Gabler Date: Sun, 28 Nov 2021 19:53:20 +0100 Subject: [PATCH 2/2] First code changes --- src/DynamicPPL.jl | 1 + src/compiler.jl | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/DynamicPPL.jl b/src/DynamicPPL.jl index 1e04d1439..28de67110 100644 --- a/src/DynamicPPL.jl +++ b/src/DynamicPPL.jl @@ -7,6 +7,7 @@ using Bijectors using AbstractMCMC: AbstractMCMC using ChainRulesCore: ChainRulesCore +using DensityInterface: DensityInterface using MacroTools: MacroTools using ZygoteRules: ZygoteRules using BangBang: BangBang diff --git a/src/compiler.jl b/src/compiler.jl index 4cd4cc899..42a61e342 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -101,15 +101,18 @@ isliteral(e::Expr) = !isempty(e.args) && all(isliteral, e.args) Check if the right-hand side `x` of a `~` is a `Distribution` or an array of `Distributions`, then return `x`. """ -function check_tilde_rhs(@nospecialize(x)) +check_tilde_rhs(x) = check_tilde_rhs(x, DensityInterface.DensityKind(x)) +check_tilde_rhs(x::Distribution) = x +check_tilde_rhs(x::AbstractArray{<:Distribution}) = x +# check_tilde_rhs(x::AbstractArray{T}) where {T} = check_tilde_rhs(x, DensityInterface.DensityKind(T)) +check_tilde_rhs(x, ::DensityInterface.IsOrHasDensity) = x +function check_tilde_rhs(@nospecialize(x), ::DensityInterface.NoDensity) return throw( ArgumentError( "the right-hand side of a `~` must be a `Distribution` or an array of `Distribution`s", ), ) end -check_tilde_rhs(x::Distribution) = x -check_tilde_rhs(x::AbstractArray{<:Distribution}) = x """ unwrap_right_vn(right, vn)