SciML / SciML/ComponentArrays.jl
Type instability in ComponentMatrix if index for FlatAxis is not constant
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 375
- Forks
- 42
- Avg merge
- 7h 25m
- Merged PRs (30d)
- 17
Description
Hi,
I'm trying to get a view of a part of a ComponentMatrix, but it seems this sometimes is not type-stable. In particular, if one of the indices is a non-constant integer I get a type-unstable view:
using ComponentArrays
small_comp_array = ComponentArray(a=[0.1, 0.2], b=0.3)
comp_matrix = ComponentMatrix(randn(3, 5), getaxes(small_comp_array)[1], FlatAxis())
get_a1(x) = view(x, Val(:a), 1)
get_a(x, i) = view(x, Val(:a), i)
@code_warntype get_a1(comp_matrix) #Type-stable
@code_warntype get_a(comp_matrix, 1) #Not type-stable
I'm using Julia 1.11.5.
Is this a special case of #9? I'm surprised that the Val around the symbol doesn't fix the const propagation.
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
Reproduce the type-instability with the Julia snippet using ComponentMatrix, FlatAxis, view, and the get_a/get_a1 methods. Start by tracing the view dispatch and index handling for a non-constant integer; done means the variable-indexed view is type-stable without changing the constant-index behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100