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
11 changes: 11 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 0.1.1

Added the `Draw` struct, which bundles a `VarNamedTuple` of parameter values with a `NamedTuple` of extra information, as well as the accessor functions `parameters` and `extras`.
This is intended to represent a single MCMC sample.

`Draw` is structurally the same as what used to be called `ParamsWithStats` in DynamicPPL.

# 0.1.0

Initial release.
This is a direct port of code from AbstractPPL and DynamicPPL, with one major change: `@vn` is now an alias for `@varname`, which is hopefully helpful since it gets used quite a lot.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "VarNames"
uuid = "09a315b2-63fc-4165-8d7f-d59368e770cc"
version = "0.1.0"
version = "0.1.1"
authors = ["Penelope Yong <penelopeysm@gmail.com>", "Markus Hauru <markus@mhauru.org>"]

[deps]
Expand Down
6 changes: 6 additions & 0 deletions docs/src/vnt/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ templated_setindex!!
densify!!
skeleton
```

```@docs
Draw
parameters
extras
```
5 changes: 5 additions & 0 deletions src/VarNames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export VarNamedTuple,
SkipTemplate,
@vnt

include("draw.jl")
export Draw
export parameters
export extras

using BangBang: push!!, empty!!, setindex!!
export push!!, empty!!, setindex!!

Expand Down
32 changes: 32 additions & 0 deletions src/draw.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Draw{P<:VarNamedTuple,S<:NamedTuple}

A struct that bundles a set of parameter values stored as a `VarNamedTuple`, along with a
`NamedTuple` of extra information associated with this set of values (for example, this can
be used to store log-probability values, etc.).

In VarNames.jl, this struct is not used at all; however, it is defined here so that other
packages can dispatch on it easily.
"""
struct Draw{P<:VarNamedTuple,S<:NamedTuple}
parameters::P
extras::S
end

"""
VarNames.parameters(draw::Draw)::VarNamedTuple

Returns the parameters of the draw as a `VarNamedTuple`.
"""
function parameters(draw::Draw)
return draw.parameters
end

"""
VarNames.extras(draw::Draw)::NamedTuple

Returns the extra information of the draw as a `NamedTuple`.
"""
function extras(draw::Draw)
return draw.extras
end
16 changes: 16 additions & 0 deletions test/draw.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module DrawTests

using VarNames
using Test

@testset "draw" begin
# Since it's just a bare struct, just test its API.
vnt = VarNamedTuple(x=0.5, y=randn(3))
nt = (a=:hello, logjoint=randn())
d = Draw(vnt, nt)

@test parameters(d) == vnt
@test extras(d) == nt
end

end # module DrawTests
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ using Test
include("varname/leaves.jl")
include("varname/serialize.jl")
include("varnamedtuple.jl")
include("draw.jl")
end
Loading