Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,8 @@ function build_output(model_info)
end
end)
end
return esc(quote
# Allows passing arguments as kwargs
$outer_function(;$(args...)) = $outer_function($(arg_syms...))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a feature of DPPL and Turing that we can pass only the second argument for example as a kwarg and the first is given its default value.

Copy link
Member Author

@devmotion devmotion Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR just checks if args is empty and does not add the duplicate definition in case it is. The function that allows to pass keyword arguments is defined below.


ex = quote
function $outer_function($(args...))
function $inner_function(
$vi::DynamicPPL.VarInfo,
Expand All @@ -605,7 +604,17 @@ function build_output(model_info)
return DynamicPPL.Model($inner_function, $args_nt, $model_gen_constructor)
end
$model_gen = $model_gen_constructor
end)
end

if !isempty(args)
ex = quote
$ex
# Allows passing arguments as kwargs
$outer_function(;$(args...)) = $outer_function($(arg_syms...))
end
end

return esc(ex)
end

# A hack for NamedTuple type specialization
Expand Down