Skip to content

Consistency in types when indexing ComponentVector with empty tuple #267

Open
@bgctw

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions