From 0ab9d8b40a39c83a2f8ed473ac45306f22775ddd Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 16 Jul 2021 08:08:39 +0100 Subject: [PATCH 1/2] improved leftover to_namedtuple_expr, fixing a bug when used with Zygote --- src/utils.jl | 37 +++++-------------------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index e77a4ecdd..db7faabbd 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -44,39 +44,12 @@ function getargs_tilde(expr::Expr) end end -############################################ -# Julia 1.2 temporary fix - Julia PR 33303 # -############################################ function to_namedtuple_expr(syms, vals=syms) - if length(syms) == 0 - nt = :(NamedTuple()) - else - nt_type = Expr( - :curly, - :NamedTuple, - Expr(:tuple, QuoteNode.(syms)...), - Expr(:curly, :Tuple, [:(Core.Typeof($x)) for x in vals]...), - ) - nt = Expr(:call, :($(DynamicPPL.namedtuple)), nt_type, Expr(:tuple, vals...)) - end - return nt -end - -if VERSION == v"1.2" - @eval function namedtuple( - ::Type{NamedTuple{names,T}}, args::Tuple - ) where {names,T<:Tuple} - if length(args) != length(names) - throw(ArgumentError("Wrong number of arguments to named tuple constructor.")) - end - # Note T(args) might not return something of type T; e.g. - # Tuple{Type{Float64}}((Float64,)) returns a Tuple{DataType} - return $(Expr(:splatnew, :(NamedTuple{names,T}), :(T(args)))) - end -else - function namedtuple(::Type{NamedTuple{names,T}}, args::Tuple) where {names,T<:Tuple} - return NamedTuple{names,T}(args) - end + length(syms) == 0 && return :(NamedTuple()) + + names_expr = Expr(:tuple, QuoteNode.(syms)...) + vals_expr = Expr(:tuple, vals...) + return :(NamedTuple{$names_expr}($vals_expr)) end ##################################################### From 42ad5524d3a29f650e405079c1d8921d4845b536 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Fri, 16 Jul 2021 08:09:22 +0100 Subject: [PATCH 2/2] bumped patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e17343312..e2c1dd29e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DynamicPPL" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.12.2" +version = "0.12.3" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"