@@ -25,27 +25,24 @@ struct StructArray{T, N, C<:Tup, I} <: AbstractArray{T, N}
25
25
end
26
26
end
27
27
28
- # common type used for indexing
28
+ # compute optimal type to use for indexing as a function of component types
29
29
index_type (:: Type{NamedTuple{names, types}} ) where {names, types} = index_type (types)
30
30
index_type (:: Type{Tuple{}} ) = Int
31
31
function index_type (:: Type{T} ) where {T<: Tuple }
32
32
S, U = tuple_type_head (T), tuple_type_tail (T)
33
- IndexStyle (S) isa IndexCartesian ? CartesianIndex{ ndims (S)} : index_type ( U)
33
+ return _index_type (S, U)
34
34
end
35
35
# Julia v1.7.0-beta3 doesn't seem to specialize `index_type` as defined above
36
36
# for tuple types with "many" elements (three or four, depending on the concrete
37
37
# types). However, we can help the compiler for homogeneous types by defining
38
38
# the specialization below.
39
- function index_type (:: Type{<:NTuple{N, S}} ) where {N, S}
40
- if IndexStyle (S) isa IndexCartesian
41
- return CartesianIndex{ndims (S)}
42
- else
43
- return Int
44
- end
45
- end
46
-
39
+ index_type (:: Type{NTuple{N, S}} ) where {N, S} = _index_type (S)
47
40
index_type (:: Type{StructArray{T, N, C, I}} ) where {T, N, C, I} = I
48
41
42
+ function _index_type (:: Type{S} , :: Type{U} = Tuple{}) where {S, U}
43
+ return IndexStyle (S) isa IndexCartesian ? CartesianIndex{ndims (S)} : index_type (U)
44
+ end
45
+
49
46
array_types (:: Type{StructArray{T, N, C, I}} ) where {T, N, C, I} = array_types (C)
50
47
array_types (:: Type{NamedTuple{names, types}} ) where {names, types} = types
51
48
array_types (:: Type{TT} ) where {TT<: Tuple } = TT
0 commit comments