1
- @inline function getindex (sa:: HybridArray{S} , :: Colon ) where S
2
- return HybridArray {S} (getindex (sa. data, :))
3
- end
4
-
5
1
Base. @propagate_inbounds function getindex (sa:: HybridArray{S} , inds:: Int... ) where S
6
2
return getindex (sa. data, inds... )
7
3
end
@@ -10,39 +6,52 @@ Base.@propagate_inbounds function getindex(sa::HybridArray{S}, inds::Union{Int,
10
6
_getindex (all_dynamic_fixed_val (S, inds... ), sa, inds... )
11
7
end
12
8
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} ...)
14
20
return _getindex_all_static (sa, inds... )
15
21
end
16
22
17
23
function _get_indices (i:: Tuple{} , j:: Int )
18
24
return ()
19
25
end
20
26
21
- function _get_indices (i:: Tuple , j:: Int , i1 :: Type{Int} , inds... )
27
+ function _get_indices (i:: Tuple , j:: Int , :: Type{Int} , inds... )
22
28
return (:(inds[$ j]), _get_indices (i, j+ 1 , inds... )... )
23
29
end
24
30
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
26
32
return (:(inds[$ j][$ (i[1 ])]), _get_indices (i[2 : end ], j+ 1 , inds... )... )
27
33
end
28
34
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... )
30
36
return (i[1 ], _get_indices (i[2 : end ], j+ 1 , inds... )... )
31
37
end
32
38
33
39
_totally_linear () = true
34
40
_totally_linear (inds... ) = false
35
41
_totally_linear (inds:: Type{Int} ...) = true
42
+ _totally_linear (inds:: Type{<:Base.Slice} ...) = true
36
43
_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... )
38
46
39
47
function new_out_size_nongen (:: Type{Size} , inds... ) where Size
40
48
os = []
49
+ @assert length (Size. parameters) == length (inds)
41
50
map (Size. parameters, inds) do s, i
42
51
if i == Int
43
52
elseif i <: StaticVector
44
53
push! (os, length (i))
45
- elseif i == Colon
54
+ elseif i == Colon || i <: Base.Slice
46
55
push! (os, s)
47
56
else
48
57
error (" Unknown index type: $i " )
@@ -51,6 +60,14 @@ function new_out_size_nongen(::Type{Size}, inds...) where Size
51
60
return tuple (os... )
52
61
end
53
62
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
+
54
71
"""
55
72
_get_linear_inds(S, inds...)
56
73
@@ -108,7 +125,7 @@ function _get_linear_inds(S, inds...)
108
125
end
109
126
end
110
127
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}
112
129
newsize = new_out_size_nongen (S, inds... )
113
130
exprs = Vector {Expr} (undef, length (newsize))
114
131
@@ -138,17 +155,13 @@ end
138
155
end
139
156
end
140
157
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
-
146
158
# _get_static_vector_length is used in a generated function so using a generic function
147
159
# may not be a good idea
148
160
_get_static_vector_length (:: Type{<:StaticVector{N}} ) where {N} = N
149
161
150
162
@generated function new_out_size (:: Type{Size} , inds... ) where Size
151
163
os = []
164
+ @assert length (Size. parameters) === length (inds)
152
165
map (Size. parameters, inds) do s, i
153
166
if i == Int
154
167
elseif i <: StaticVector
@@ -166,9 +179,21 @@ _get_static_vector_length(::Type{<:StaticVector{N}}) where {N} = N
166
179
return Tuple{os... }
167
180
end
168
181
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... ))
172
197
end
173
198
174
199
# setindex stuff
0 commit comments