StaticArrays.jl
StaticArrays.jl copied to clipboard
Indexing with extra dimensions errors
The indexing behavior is different from static vector and a normal vector when adding extra dimensions
julia> a = @SVector randn(2)
2-element SVector{2, Float64} with indices SOneTo(2):
1.1055415819376984
-1.376116084168465
julia> a[:, 1]
ERROR: BoundsError: attempt to access Tuple{} at index [1]
Stacktrace:
[1] getindex(t::Tuple, i::Int64)
@ Base ./tuple.jl:29
[3] index_sizes
@ ~/.julia/packages/StaticArrays/pwe3X/src/indexing.jl:81 [inlined]
[4] getindex(::SVector{2, Float64}, ::Colon, ::Int64)
@ StaticArrays ~/.julia/packages/StaticArrays/pwe3X/src/indexing.jl:226
julia> b = randn(2)
2-element Vector{Float64}:
0.34780756537216645
-1.63328724070066
julia> b[:, 1]
2-element Vector{Float64}:
0.34780756537216645
-1.63328724070066
Similarly when indexing the first dimension:
julia> A = [1.0, 2.0];
julia> A[1,:]
1-element Vector{Float64}:
1.0
julia> A = SVector(1.0, 2.0);
julia> A[1,:]
ERROR: BoundsError: attempt to access Tuple{} at index [1]
Stacktrace:
[1] getindex(t::Tuple, i::Int64)
@ Base ./tuple.jl:29
[2] map(f::typeof(StaticArrays.index_size), t::Tuple{}, s::Tuple{Colon}) (repeats 2 times)
@ Base ./tuple.jl:250
[3] index_sizes
@ ~/.julia/packages/StaticArrays/76ecm/src/indexing.jl:81 [inlined]
[4] getindex(::SVector{2, Float64}, ::Int64, ::Colon)
@ StaticArrays ~/.julia/packages/StaticArrays/76ecm/src/indexing.jl:226
[5] top-level scope