SciML / SciML/ComponentArrays.jl
Consistency in types when indexing ComponentVector with empty tuple
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 375
- Forks
- 42
- Avg merge
- 7h 25m
- Merged PRs (30d)
- 17
Description
When extracting a Sub-ComponentVector by indexing with a set of symbols, I sometimes encounter the case that the set of indices (computed somewhere else) is empty. For consistency, I expect the indexing to return the same type, i.e. an empty ComponentVector. But currently it returns a plain vector.
using ComponentArrays
using Test
cv = ComponentVector(k1 = 1.0, k2 = 2.0)
@test cv[(:k1, :k2)] == cv
@test cv[(:k1, )] == ComponentVector(k1 = 1.0)
@test cv[NTuple{0,Symbol}()] == ComponentVector{eltype(cv)}() # fails, should return ComponentVector
@test cv[()] == ComponentVector{eltype(cv)}() # discuss meaning
What are the arguments for returning a plain vector instead of an empty ComponentVector?
Extending the KeepIndex to the empty tuple does not work for me, because I need a method to extract Sub-ComponentVectors that work consistently with a NTuple{N, Symbol} for any N.
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 running the Julia reproducer in the issue, especially the NTuple{0,Symbol}() and () indexing cases. Inspect the ComponentVector indexing entry points and existing tests for tuple-based indexing; done means the intended empty-tuple behavior is defined and covered consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100