Skip to content

Commit 8987b55

Browse files
committed
Fix getdefault
1 parent 558409b commit 8987b55

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/compiler.jl

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ function build_output(model_info)
455455
end
456456

457457
model_type = :(DynamicPPL.Model{$(QuoteNode(model_tag))})
458+
kw_form = isempty(args) ? () : (:($model_type(;$(args...)) = $model_type($(arg_syms...))),)
459+
missings = gensym(:missings)
460+
args_tuple = gensym(:args_tuple)
458461

459462
ex = quote
460463
function ($model::$model_type)(
@@ -467,17 +470,21 @@ function build_output(model_info)
467470
$main_body
468471
end
469472

470-
getdefaults(::$model_type) = $defaults_nt
471-
$model_gen($(args...)) = $model_type($args_nt)
472-
end
473+
DynamicPPL.getdefaults(::Type{$model_type}) = $defaults_nt
474+
475+
function $model_type($(args...))
476+
$args_tuple = $args_nt
477+
$missings = DynamicPPL.getmissing($args_tuple)
478+
return DynamicPPL.Model{$(QuoteNode(model_tag)),
479+
typeof($args_tuple),
480+
typeof($missings)}($args_tuple, $missings)
481+
end
482+
483+
$(kw_form...)
473484

474-
if !isempty(args)
475-
# Allows passing arguments as kwargs
476-
kwform = :($model_gen(;$(args...)) = $model_gen($(arg_syms...)))
477-
push!(ex.args, kwform)
485+
$model_gen = $model_type
478486
end
479487

480-
481488
return esc(ex)
482489
end
483490

src/model.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ struct Model{S, Targs<:NamedTuple, Tmissings<:Val} <: AbstractModel
1515
missings::Tmissings
1616
end
1717

18-
function Model{S}(args::NamedTuple) where {S}
19-
missings = getmissing(args)
20-
Model{S, typeof(args), typeof(missings)}(args, missings)
21-
end
22-
2318
(model::Model)(vi) = model(vi, SampleFromPrior())
2419
(model::Model)(vi, spl) = model(vi, spl, DefaultContext())
2520

0 commit comments

Comments
 (0)