jonniedie / ComponentArrays.jl

Arrays with arbitrarily nested named components.
MIT License
286 stars 34 forks source link

Can't index component array with shaped components with subset of keys #256

Closed marius311 closed 2 months ago

marius311 commented 3 months ago

Would be convenient if this worked and returned a new ComponentArray with just the x and y components, ComponentArrays 0.15.11:

julia> using ComponentArrays

julia> c = ComponentVector(x=rand(2,2), y=rand(3), z=4)
ComponentVector{Float64}(x = [0.08932677188438709 0.2039248385682888; 0.7932786495449815 0.9448910346464564], y = [0.8857236834484066, 0.3657104827001233, 0.7234530317203763], z = 4.0)

julia> c[[:x,:y]]
ERROR: MethodError: no method matching _maybe_view_axis(::UnitRange{Int64}, ::ShapedAxis{(2, 2)})

Fwiw this works with scalar components eg if c = ComponentVector(x=2, y=3, z=4)

jonniedie commented 2 months ago

It looks like this is specifically only broken with matrices and higher-dimensional array components because of a missing method for _maybe_view_axis(::Any, ::ShapedAxis). Let me see if it's a pretty straightforward fix...

jonniedie commented 2 months ago

Fix ended up being pretty simple. We were doing ::Axis for that method when it really needed to be ::AbstractAxis.