JuliaArrays / StaticArrays.jl

Statically sized arrays for Julia
Other
763 stars 148 forks source link

Slicing an `SArray` with a `CartesianIndices(::StaticArray)` may return an `SArray` #1059

Open jishnub opened 2 years ago

jishnub commented 2 years ago

Currently,

julia> m4 = SMatrix{4,4,Int,16}(1:16)
4×4 SMatrix{4, 4, Int64, 16} with indices SOneTo(4)×SOneTo(4):
 1  5   9  13
 2  6  10  14
 3  7  11  15
 4  8  12  16

julia> m3 = SMatrix{3,3,Int,9}(1:9)
3×3 SMatrix{3, 3, Int64, 9} with indices SOneTo(3)×SOneTo(3):
 1  4  7
 2  5  8
 3  6  9

julia> m4[axes(m3)...]
3×3 SMatrix{3, 3, Int64, 9} with indices SOneTo(3)×SOneTo(3):
 1  5   9
 2  6  10
 3  7  11

julia> m4[CartesianIndices(m3)]
3×3 MMatrix{3, 3, Int64, 9} with indices SOneTo(3)×SOneTo(3):
 1  5   9
 2  6  10
 3  7  11

I think this may return an SMatrix as well

mateuszbaran commented 2 years ago

Sure, returning SMatrix there is reasonable.