Skip to content

Commit 71c1000

Browse files
mateuszbaranc42f
andauthored
Better handling of subtypes of StaticVector in views of SizedArray (#867)
* Better handling of subtypes of StaticVector in views of SizedArray * Update src/SizedArray.jl Co-authored-by: Chris Foster <chris42f@gmail.com> Co-authored-by: Chris Foster <chris42f@gmail.com>
1 parent 6bfce60 commit 71c1000

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/SizedArray.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,16 @@ end
200200

201201
### Code that makes views of statically sized arrays also statically sized (where possible)
202202

203+
# Note, _get_static_vector_length is used in a generated function so it's strictly internal and can't be extended
204+
_get_static_vector_length(::Type{<:StaticVector{N}}) where {N} = N
205+
203206
@generated function new_out_size(::Type{Size}, inds...) where Size
204207
os = []
205208
map(Size.parameters, inds) do s, i
206209
if i <: Integer
207210
# dimension is fixed
208211
elseif i <: StaticVector
209-
push!(os, i.parameters[1].parameters[1])
212+
push!(os, _get_static_vector_length(i))
210213
elseif i == Colon || i <: Base.Slice
211214
push!(os, s)
212215
elseif i <: SOneTo

test/SizedArray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@
206206
x5 = view(x, :)
207207
@test isa(x5, SizedArray{Tuple{24},Float64,1,1,<:SubArray{Float64,1}})
208208
@test x5 == view(x.data, :)
209+
210+
x6 = view(x, StaticArrays.SUnitRange(2, 3), :, 2)
211+
@test isa(x6, SizedArray{Tuple{2,3},Float64,2,2,<:SubArray{Float64,2}})
212+
@test x6 == view(x.data, StaticArrays.SUnitRange(2, 3), :, 2)
209213
end
210214

211215
@testset "views of MArray" begin

0 commit comments

Comments
 (0)