-
Notifications
You must be signed in to change notification settings - Fork 37
VNT Part 2: Solving the issue of block elements #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mhauru/vnt-for-fastldf
Are you sure you want to change the base?
Changes from 16 commits
35c3e20
4253e9b
5cb3916
a96bb44
a8014e6
cfc6041
e198fbb
b77b0af
633e920
222334a
d22face
4cb49e1
420a6b2
d2f58d7
ce9da19
4eb33e9
51b399a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,13 +206,17 @@ an unlinked value. | |
|
|
||
| $(TYPEDFIELDS) | ||
| """ | ||
| struct RangeAndLinked | ||
| struct RangeAndLinked{T<:Tuple} | ||
| # indices that the variable corresponds to in the vectorised parameter | ||
| range::UnitRange{Int} | ||
| # whether it's linked | ||
| is_linked::Bool | ||
| # original size of the variable before vectorisation | ||
| original_size::T | ||
| end | ||
|
|
||
| Base.size(ral::RangeAndLinked) = ral.original_size | ||
|
|
||
| """ | ||
| VectorWithRanges{Tlink}( | ||
| varname_ranges::VarNamedTuple, | ||
|
|
@@ -247,7 +251,12 @@ struct VectorWithRanges{Tlink,VNT<:VarNamedTuple,T<:AbstractVector{<:Real}} | |
| end | ||
|
|
||
| function _get_range_and_linked(vr::VectorWithRanges, vn::VarName) | ||
| return vr.varname_ranges[vn] | ||
| # The type assertion does nothing if VectorWithRanges has concrete element types, as is | ||
| # the case for all type stable models. However, if the model is not type stable, | ||
| # vr.varname_ranges[vn] may infer to have type `Any`. In this case it is helpful to | ||
| # assert that it is a RangeAndLinked, because even though it remains non-concrete, | ||
| # it'll allow the compiler to infer the types of `range` and `is_linked`. | ||
| return vr.varname_ranges[vn]::RangeAndLinked | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this assertion, this model: @model function demo_one_variable_multiple_constraints(
::Type{TV}=Vector{Float64}
) where {TV}
x = TV(undef, 5)
x[1] ~ Normal()
x[2] ~ InverseGamma(2, 3)
x[3] ~ truncated(Normal(), -5, 20)
x[4:5] ~ Dirichlet([1.0, 2.0])
return (x=x,)
endfails the test that checks that the return type of Now, I'm fine saying that a model that mixes Note that this problem is independent of the above comment of introducing a type parameter to |
||
| end | ||
| function init( | ||
| ::Random.AbstractRNG, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit unfortunate to have to create this field, because now you may end up with abstractly typed
RangeAndLinked, which obscures the fact that the two fields you really care about, namelyrangeandis_linked, are still concrete. The reason this is needed is that VNT needs to know how much "space" in aPartialArrayan instance ofRangeAndLinkedtakes. An alternative to this could be something like givingsetindex!!(::VarNamedTuple, ...)an extra kwarg of something likeignore_size_checks.