1- @inline function getindex (sa:: HybridArray{S} , :: Colon ) where S
2- return HybridArray {S} (getindex (sa. data, :))
3- end
4-
51Base. @propagate_inbounds function getindex (sa:: HybridArray{S} , inds:: Int... ) where S
62 return getindex (sa. data, inds... )
73end
@@ -10,39 +6,52 @@ Base.@propagate_inbounds function getindex(sa::HybridArray{S}, inds::Union{Int,
106 _getindex (all_dynamic_fixed_val (S, inds... ), sa, inds... )
117end
128
13- Base. @propagate_inbounds function _getindex (:: Val{:dynamic_fixed_true} , sa:: HybridArray , inds:: Union{Int, StaticArray{<:Tuple, Int}, Colon} ...)
9+ # This plugs into a deeper level of indexing in base to catch custom
10+ # indexing schemes based on `to_indices`.
11+ # A minor version Julia release could potentially break this (though it seems unlikely).
12+ Base. @propagate_inbounds function Base. _getindex (l:: IndexLinear , sa:: HybridArray{S} , inds:: Int... ) where S
13+ return Base. _getindex (l, sa. data, inds... )
14+ end
15+ Base. @propagate_inbounds function Base. _getindex (:: IndexLinear , sa:: HybridArray{S} , inds:: Union{Int, StaticVector, Colon, Base.Slice} ...) where S
16+ _getindex (all_dynamic_fixed_val (S, inds... ), sa, inds... )
17+ end
18+
19+ Base. @propagate_inbounds function _getindex (:: Val{:dynamic_fixed_true} , sa:: HybridArray , inds:: Union{Int, StaticVector, Colon, Base.Slice} ...)
1420 return _getindex_all_static (sa, inds... )
1521end
1622
1723function _get_indices (i:: Tuple{} , j:: Int )
1824 return ()
1925end
2026
21- function _get_indices (i:: Tuple , j:: Int , i1 :: Type{Int} , inds... )
27+ function _get_indices (i:: Tuple , j:: Int , :: Type{Int} , inds... )
2228 return (:(inds[$ j]), _get_indices (i, j+ 1 , inds... )... )
2329end
2430
25- function _get_indices (i:: Tuple , j:: Int , i1 :: Type{T} , inds... ) where T<: StaticArray{<:Tuple, Int}
31+ function _get_indices (i:: Tuple , j:: Int , :: Type{T} , inds... ) where T<: StaticVector
2632 return (:(inds[$ j][$ (i[1 ])]), _get_indices (i[2 : end ], j+ 1 , inds... )... )
2733end
2834
29- function _get_indices (i:: Tuple , j:: Int , i1 :: Type{Colon} , inds... )
35+ function _get_indices (i:: Tuple , j:: Int , :: Type{<:Union{ Colon, Base.Slice} } , inds... )
3036 return (i[1 ], _get_indices (i[2 : end ], j+ 1 , inds... )... )
3137end
3238
3339_totally_linear () = true
3440_totally_linear (inds... ) = false
3541_totally_linear (inds:: Type{Int} ...) = true
42+ _totally_linear (inds:: Type{<:Base.Slice} ...) = true
3643_totally_linear (inds:: Type{Colon} ...) = true
37- _totally_linear (i1:: Type{Colon} , inds... ) = _totally_linear (inds... )
44+ _totally_linear (:: Type{<:Base.Slice} , inds... ) = _totally_linear (inds... )
45+ _totally_linear (:: Type{Colon} , inds... ) = _totally_linear (inds... )
3846
3947function new_out_size_nongen (:: Type{Size} , inds... ) where Size
4048 os = []
49+ @assert length (Size. parameters) == length (inds)
4150 map (Size. parameters, inds) do s, i
4251 if i == Int
4352 elseif i <: StaticVector
4453 push! (os, length (i))
45- elseif i == Colon
54+ elseif i == Colon || i <: Base.Slice
4655 push! (os, s)
4756 else
4857 error (" Unknown index type: $i " )
@@ -51,6 +60,14 @@ function new_out_size_nongen(::Type{Size}, inds...) where Size
5160 return tuple (os... )
5261end
5362
63+ function new_out_size_nongen (:: Type{Size} , i:: Type{<:Union{Colon, Base.Slice}} ) where Size
64+ if has_dynamic (Size)
65+ return (Dynamic (),)
66+ else
67+ return (tuple_nodynamic_prod (Size),)
68+ end
69+ end
70+
5471"""
5572 _get_linear_inds(S, inds...)
5673
@@ -108,7 +125,7 @@ function _get_linear_inds(S, inds...)
108125 end
109126end
110127
111- @generated function _getindex_all_static (sa:: HybridArray{S,T} , inds:: Union{Int, StaticArray{<:Tuple, Int} , Colon} ...) where {S,T}
128+ @generated function _getindex_all_static (sa:: HybridArray{S,T} , inds:: Union{Int, StaticIndexing, Base.Slice , Colon, StaticArray } ...) where {S,T}
112129 newsize = new_out_size_nongen (S, inds... )
113130 exprs = Vector {Expr} (undef, length (newsize))
114131
@@ -138,17 +155,13 @@ end
138155 end
139156end
140157
141- function new_out_size (S:: Type{Size} , inds:: StaticArrays.StaticIndexing... ) where Size
142- return new_out_size (S, map (StaticArrays. unwrap, inds)... )
143- end
144-
145-
146158# _get_static_vector_length is used in a generated function so using a generic function
147159# may not be a good idea
148160_get_static_vector_length (:: Type{<:StaticVector{N}} ) where {N} = N
149161
150162@generated function new_out_size (:: Type{Size} , inds... ) where Size
151163 os = []
164+ @assert length (Size. parameters) === length (inds)
152165 map (Size. parameters, inds) do s, i
153166 if i == Int
154167 elseif i <: StaticVector
@@ -166,9 +179,21 @@ _get_static_vector_length(::Type{<:StaticVector{N}}) where {N} = N
166179 return Tuple{os... }
167180end
168181
169- @inline function _getindex (:: Val{:dynamic_fixed_false} , sa:: HybridArray{S} , inds:: Union{Int, StaticArray{<:Tuple, Int}, Colon} ...) where S
170- newsize = new_out_size (S, inds... )
171- return HybridArray {newsize} (getindex (sa. data, inds... ))
182+ @generated function new_out_size (:: Type{Size} , :: Union{Colon, Base.Slice} ) where Size
183+ if has_dynamic (Size)
184+ return Tuple{Dynamic ()}
185+ else
186+ return Tuple{tuple_nodynamic_prod (Size)}
187+ end
188+ end
189+
190+ maybe_unwrap (i) = i
191+ maybe_unwrap (i:: StaticIndexing ) = i. ind
192+
193+ @inline function _getindex (:: Val{:dynamic_fixed_false} , sa:: HybridArray{S} , inds:: Union{Int, StaticIndexing, StaticVector, Base.Slice, Colon} ...) where S
194+ uinds = map (maybe_unwrap, inds)
195+ newsize = new_out_size (S, uinds... )
196+ return HybridArray {newsize} (getindex (sa. data, uinds... ))
172197end
173198
174199# setindex stuff
0 commit comments