SciML / SciML/ComponentArrays.jl

Type instability in ComponentMatrix if index for FlatAxis is not constant

Open
#306 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.