This is such a basic question that I almost feel bad asking it, but it would be nice to get some clarification and examples of how others are using StaticArrays.jl. I’ve found this thread, but I think my question is slightly more general.
using StaticArrays
x = SVector{5}([1.1, 1.2, 1.3, 1.4, 1.5])
julia> x[[2,5]]
2-element Vector{Float64}:
1.2
1.5
julia> x[2:3]
2-element Vector{Float64}:
1.2
1.3
First, it seems very strange to me that the return type is not SVector. I’m wondering what the intended baseline use case is where you’d want the type to change when indexing. Or maybe there’s not a way to make it work with multiple dispatch with StaticArrays.
After a bit of digging, I’ve found that I can do either of the following:
julia> x[SVector{2}([2,5])]
2-element SVector{2, Float64} with indices SOneTo(2):
1.2
1.5
julia> x[StaticArrays.SUnitRange(2,3)]
2-element SVector{2, Float64} with indices SOneTo(2):
1.2
1.3
Given that SUnitRange isn’t even exported, I’m guessing that I’m looking in the wrong place. This also seems to involve writing a lot of custom code when you want to use StaticArrays.
Ultimately, I think my questions are:
What is the “right” way to index StaticArrays?
How should we write general code that is dispatched to return a specified subset of an AbstractArray with the correct return type?