Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistency in types when indexing ComponentVector with empty tuple #267

Open
bgctw opened this issue Aug 13, 2024 · 0 comments
Open

Consistency in types when indexing ComponentVector with empty tuple #267

bgctw opened this issue Aug 13, 2024 · 0 comments

Comments

@bgctw
Copy link

bgctw commented Aug 13, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant