Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# DynamicPPL Changelog

## 0.39.2

`returned(model, parameters...)` now accepts any arguments that can be wrapped in `InitFromParams` (previously it would only accept `NamedTuple`, `AbstractDict{<:VarName}`, or a chain).

## 0.39.1

`LogDensityFunction` now allows you to call `logdensity_and_gradient(ldf, x)` with `AbstractVector`s `x` that are not plain Vectors (they will be converted internally before calculating the gradient).
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.39.1"
version = "0.39.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
16 changes: 11 additions & 5 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1153,10 +1153,16 @@ end
function predict end

"""
returned(model::Model, parameters::NamedTuple)
returned(model::Model, parameters::AbstractDict{<:VarName})
returned(model::Model, parameters...)

Execute `model` with variables `keys` set to `values` and return the values returned by the `model`.
Initialise a `model` using the given `parameters` and return the model's return value. The
parameters must be provided in a format that can be wrapped in an `InitFromParams`, i.e.,
`InitFromParams(parameters..., nothing)` must be a valid `AbstractInitStrategy` (where
`nothing` is the fallback strategy to use if parameters are not provided).

As far as DynamicPPL is concerned, `parameters` can be either a singular `NamedTuple` or an
`AbstractDict{<:VarName}`; however this method is left flexible to allow for other packages
that wish to extend `InitFromParams`.

# Example
```jldoctest
Expand All @@ -1177,7 +1183,7 @@ julia> returned(model, Dict{VarName,Float64}(@varname(m) => 2.0))
(mp1 = 3.0,)
```
"""
function returned(model::Model, parameters::Union{NamedTuple,AbstractDict{<:VarName}})
function returned(model::Model, parameters...)
# Note: we can't use `fix(model, parameters)` because
# https://github.com/TuringLang/DynamicPPL.jl/issues/1097
return first(
Expand All @@ -1186,7 +1192,7 @@ function returned(model::Model, parameters::Union{NamedTuple,AbstractDict{<:VarN
DynamicPPL.OnlyAccsVarInfo(DynamicPPL.AccumulatorTuple()),
# Use `nothing` as the fallback to ensure that any missing parameters cause an
# error
InitFromParams(parameters, nothing),
InitFromParams(parameters..., nothing),
),
)
end