TuringLang / TuringLang/DynamicPPL.jl

Creating empty templated VNTs

Open
#1,283 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

data-structures enhancement
Dominant language
Julia
Stars
286
Forks
41
Avg merge
1d 11h
Merged PRs (30d)
34

Description

Transferring this from a discussion on the weekly meeting Google Docs: we should split up templated_setindex!! to do two different actions, one to create an empty template in a VNT, and one to set the value of one or more elements. That is, we could have something like this:

vnt = VarNamedTuple()
vnt = DynamicPPL.settemplate!!(vnt, zeros(3, 3), @varname(x))
vnt = BangBang.setindex!!(vnt, 10.0, @varname(x[1,1]))

templated_setindex!! I think would still exist, but it would be a composition of the last two lines. The main benefit of doing so is so that we would be able to create preallocated, empty, VNTs prior to the model evaluation, instead of the current workflow where templates are detected at model runtime.

I think this should not be very difficult to do; the main concerns would be type stability, for example in

vnt = DynamicPPL.settemplate!!(vnt, zeros(3, 3), @varname(x))
# string instead of float
vnt = BangBang.setindex!!(vnt, "a", @varname(x[1,1]))

the latter call would be type unstable since it would need to broaden the eltype of the array. This is in fact the user's fault for supplying the wrong template, but I guess we would need to make it clear. The reason why templated_setindex!! avoids this type stability issue is because when calling

templated_setindex!!(vnt, "a", @varname(x[1, 1]), zeros(3, 3))

it in fact infers the eltype of the array from the value "a" rather than the eltype of the template Float64.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating templated_setindex!!, DynamicPPL.settemplate!!, and BangBang.setindex!!, then trace how VarNamedTuple templates and element types are represented. Define the separate empty-template and value-setting behavior, preserve templated_setindex!! as their composition, and verify the documented type-stability behavior for mismatched values.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.