You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry for the clumpsy title, I hope the example makes the idea clearer:
ca =ComponentVector(a=1, b=2, c=3)
ca[[1,2]] # works
ca[[1,2]] .= [-1, -2] # works# Similar, it would be nice to index multiple fields with an array of symbols
ca[[:a, :b]] # doesn't work
ca[[:a, :b]] .= [-11, -22] # doesn't work# This works, but is not quite as elegant:getindex.(Ref(p1), [:a, :b])
setindex!.(Ref(ca), [-11, -22], [:a, :b])
The text was updated successfully, but these errors were encountered:
julia> ca =ComponentVector(a=3, b=[4,1], c=[20, 11])
ComponentVector{Int64}(a =3, b = [4, 1], c = [20, 11)
julia> a =getdata(ca)
5-element Vector{Int64}:3412011
julia> a[[1, 2:3]]
ERROR: MethodError: Cannot `convert` an object of type Vector{Int64} to an object of type Int64
Closest candidates are:convert(::Type{T}, ::Ptr) where T<:Integer at pointer.jl:23convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250convert(::Type{T}, ::AbstractChar) where T<:Number at char.jl:180...
julia> a[[2:3, 4:5]]
ERROR: ArgumentError: invalid index: UnitRange{Int64}[2:3, 4:5] of type Vector{UnitRange{Int64}}
Since a symbolic index can represent getting any number of types of results in a ComponentArray (including matrices), it seems that we should follow the pattern of Base here and similarly return an error. I guess it might be possible to check that all symbolic indices only return single elements and let it work for that case, but we'd have to make sure that doesn't slow indexing down in general.
Sorry for the clumpsy title, I hope the example makes the idea clearer:
The text was updated successfully, but these errors were encountered: