Skip to content

prob macro - pre-allocation syntax #3

@mohamed82008

Description

@mohamed82008

@trappmartin brought up an issue in TuringLang/Turing.jl#997 about the syntax for pre-allocating varinfo. After the PR is merged, we can do:

using Turing

@model demo(y, ::Type{T} = Float64) where {T} = begin
    x = Vector{T}(undef, 10)
    x .~ Normal()
    y .~ Normal.(x, 1.0)
end
xval = rand(10)
varinfo = Turing.VarInfo(demo(xval))
logprob"y = rand(10) | model = demo, x = xval, varinfo = varinfo" 

Pre-allocating is useful if we need to change xval or y in a loop and re-evaluate. Pre-allocating varinfo can be useful in these cases. However, as @trappmartin indicated, the syntax seems to imply we are conditioning on varinfo which we are not. One solution proposed in the PR was to use ; instead of , before varinfo. Another one that I prefer is to not expose this in the macro at all, and only allow it in the functional API under the hood.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions