TuringLang / TuringLang/DynamicPPL.jl
VNT: Improve use of `typejoin` in VarNamedTuple
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 286
- Forks
- 41
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 34
Description
Currently, if one sets a PartialArray to have an element of type A and another element of type ArrayLikeBlock{A} (quite a common situation) the element type of the array becomes Any. This is a bit unfortunate, because if the type was kept as a Union{A, ArrayLikeBlock{A}} then getindex could infer its return type to be A, and we would have better type stability.
The fix for this would be to define our own typejoin alternative, that special cases ArrayLikeBlock to create Union types. This would be a lot like what the (unexported) Base.promote_typejoin does (see here) for Nothing and Missing. However we can't directly copy over that implementation because our special case type is an abstract type with type parameters, and we need to think through how to do this properly.
This is purely a performance optimisation, improving type stability for cases where some variables in an array are set with ranges and others are set as individual elements, and thus not very high priority.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the VarNamedTuple and PartialArray implementations and tracing how element types are computed when values are assigned. Read Julia's linked Base.promote_typejoin implementation, then examine how getindex inference behaves for A and ArrayLikeBlock{A}. Done means preserving the intended Union type instead of Any while improving type stability for the described assignments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100