Skip to content

Commit 06ab810

Browse files
authored
Implement returned(model, xs...) (#1171)
* Reapply "Implement `returned(model, xs...)`" This reverts commit e3fbd2d. * Fix syntax
1 parent e3fbd2d commit 06ab810

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# DynamicPPL Changelog
22

3+
## 0.39.2
4+
5+
`returned(model, parameters...)` now accepts any arguments that can be wrapped in `InitFromParams` (previously it would only accept `NamedTuple`, `AbstractDict{<:VarName}`, or a chain).
6+
37
## 0.39.1
48

59
`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).

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.39.1"
3+
version = "0.39.2"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/model.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,10 +1153,16 @@ end
11531153
function predict end
11541154

11551155
"""
1156-
returned(model::Model, parameters::NamedTuple)
1157-
returned(model::Model, parameters::AbstractDict{<:VarName})
1156+
returned(model::Model, parameters...)
11581157
1159-
Execute `model` with variables `keys` set to `values` and return the values returned by the `model`.
1158+
Initialise a `model` using the given `parameters` and return the model's return value. The
1159+
parameters must be provided in a format that can be wrapped in an `InitFromParams`, i.e.,
1160+
`InitFromParams(parameters..., nothing)` must be a valid `AbstractInitStrategy` (where
1161+
`nothing` is the fallback strategy to use if parameters are not provided).
1162+
1163+
As far as DynamicPPL is concerned, `parameters` can be either a singular `NamedTuple` or an
1164+
`AbstractDict{<:VarName}`; however this method is left flexible to allow for other packages
1165+
that wish to extend `InitFromParams`.
11601166
11611167
# Example
11621168
```jldoctest
@@ -1177,7 +1183,7 @@ julia> returned(model, Dict{VarName,Float64}(@varname(m) => 2.0))
11771183
(mp1 = 3.0,)
11781184
```
11791185
"""
1180-
function returned(model::Model, parameters::Union{NamedTuple,AbstractDict{<:VarName}})
1186+
function returned(model::Model, parameters...)
11811187
# Note: we can't use `fix(model, parameters)` because
11821188
# https://github.com/TuringLang/DynamicPPL.jl/issues/1097
11831189
return first(
@@ -1186,7 +1192,7 @@ function returned(model::Model, parameters::Union{NamedTuple,AbstractDict{<:VarN
11861192
DynamicPPL.OnlyAccsVarInfo(DynamicPPL.AccumulatorTuple()),
11871193
# Use `nothing` as the fallback to ensure that any missing parameters cause an
11881194
# error
1189-
InitFromParams(parameters, nothing),
1195+
InitFromParams(parameters..., nothing),
11901196
),
11911197
)
11921198
end

0 commit comments

Comments
 (0)