@@ -5,9 +5,6 @@ function _init_dimsmap(::IndicesInfo{N,pdims,cdims}) where {N,pdims,cdims}
5
5
ntuple (i -> static (getfield (pdims, i)), length (pdims)),
6
6
ntuple (i -> static (getfield (cdims, i)), length (pdims))
7
7
end
8
- # TODO move these
9
- Static. static (:: Colon ) = (:)
10
- Static. static (:: Nothing ) = nothing
11
8
12
9
"""
13
10
to_parent_dims(::Type{T}) -> Tuple{Vararg{Union{StaticInt,Tuple{Vararg{StaticInt}}}}}
@@ -22,17 +19,10 @@ to_parent_dims(@nospecialize x) = to_parent_dims(typeof(x))
22
19
@inline function to_parent_dims (@nospecialize T:: Type{<:SubArray} )
23
20
to_parent_dims (IndicesInfo {ndims(parent_type(T))} (fieldtype (T, :indices )))
24
21
end
25
- function to_parent_dims (:: IndicesInfo{N,pdims,cdims} ) where {N,pdims,cdims}
26
- flatten_tuples (ntuple (length (cdims)) do i
27
- cdim_i = getfield (cdims, i)
28
- if cdim_i isa Tuple
29
- pdim_i = static (getfield (pdims, i))
30
- ntuple (Compat. Returns (pdim_i), length (cdim_i))
31
- else
32
- cdim_i === 0 ? () : (static (getfield (pdims, i)),)
33
- end
34
- end )
35
- end
22
+ to_parent_dims (info:: IndicesInfo ) = flatten_tuples (map (_to_pdim, map_indices_info (info)))
23
+ _to_pdim (:: Tuple{StaticInt,Any,StaticInt{0}} ) = ()
24
+ _to_pdim (x:: Tuple{StaticInt,Any,StaticInt{cdim}} ) where {cdim} = getfield (x, 2 )
25
+ _to_pdim (x:: Tuple{StaticInt,Any,Tuple} ) = (ntuple (Compat. Returns (getfield (x, 2 )), length (getfield (x, 3 ))),)
36
26
to_parent_dims (@nospecialize T:: Type{<:MatAdjTrans} ) = (StaticInt (2 ), StaticInt (1 ))
37
27
to_parent_dims (@nospecialize T:: Type{<:PermutedDimsArray} ) = getfield (_permdims (T), 1 )
38
28
46
36
47
37
# Base will sometomes demote statically known slices in `SubArray` to `OneTo{Int}` so we
48
38
# provide the parent mapping to check for static size info
49
- sub_axes_map (@nospecialize (T:: Type{<:SubArray} )) = _sub_axes_map (T, IndicesInfo (T ))
50
- function _sub_axes_map ( @nospecialize (T :: Type{<:SubArray} ), :: IndicesInfo{N,pdims} ) where {N,pdims}
51
- ntuple ( length (pdims)) do i
52
- if fieldtype ( fieldtype (T, :indices ), i) <: Base.Slice{OneTo{Int} }
53
- sz = known_size ( parent_type (T), getfield (pdims, i))
54
- sz === nothing ? StaticInt (i) : StaticSymbol ( :parent ) => StaticInt (sz )
55
- else
56
- StaticInt (i)
57
- end
39
+ function sub_axes_map (@nospecialize (T:: Type{<:SubArray} ))
40
+ map (Base . Fix1 (_sub_axis_map, T ), map_indices_info ( IndicesInfo (T)))
41
+ end
42
+ function _sub_axis_map ( @nospecialize (T :: Type{<:SubArray} ), x :: Tuple{StaticInt{index},Any,Any} ) where {index }
43
+ if fieldtype ( fieldtype (T, :indices ), index) <: Base.Slice{OneTo{Int}}
44
+ sz = known_size ( parent_type (T), getfield (x, 2 ) )
45
+ return sz === nothing ? StaticInt (index) : StaticInt ( 1 ) : StaticInt (sz)
46
+ else
47
+ return StaticInt (index)
58
48
end
59
49
end
60
50
61
- sub_dimnames_map (@nospecialize T:: Type{<:SubArray} ) = _sub_dimnames_map (IndicesInfo (T))
62
- function _sub_dimnames_map (:: IndicesInfo{N,pdims,cdims} ) where {N,pdims,cdims}
63
- ntuple (length (pdims)) do i
64
- cdim_i = getfield (cdims, i)
65
- pdim_i = getfield (pdims, i)
66
- if cdim_i === 0
67
- StaticSymbol (:underscore ) => StaticInt (0 )
68
- elseif pdim_i isa Int && cdim_i isa Int
69
- StaticInt (pdim_i)
70
- else
71
- StaticSymbol (:underscore ) => length (cdim_i)
72
- end
51
+ function map_indices_info (:: IndicesInfo{N,pdims,cdims} ) where {N,pdims,cdims}
52
+ ntuple (i -> (static (i), static (getfield (pdims, i)), static (getfield (cdims, i))), length (pdims))
53
+ end
54
+ function sub_dimnames_map (dnames:: Tuple , imap:: Tuple )
55
+ flatten_tuples (map (Base. Fix1 (_to_dimname, dnames), imap))
56
+ end
57
+ @inline function _to_dimname (dnames:: Tuple , x:: Tuple{StaticInt,PD,CD} ) where {PD,CD}
58
+ if CD <: StaticInt{0}
59
+ return ()
60
+ elseif CD <: Tuple
61
+ return ntuple (Compat. Returns (static (:_ )), StaticInt (known_length (CD)))
62
+ elseif PD <: StaticInt{0} || PD <: Tuple
63
+ return static (:_ )
64
+ else
65
+ return getfield (dnames, known (PD))
73
66
end
74
67
end
75
68
@@ -122,11 +115,7 @@ function known_dimnames(@nospecialize T::Type{<:Union{MatAdjTrans,PermutedDimsAr
122
115
end
123
116
124
117
function known_dimnames (@nospecialize T:: Type{<:SubArray} )
125
- flatten_tuples (map (Base. Fix1 (_known_sub_dimname, known_dimnames (parent_type (T))), sub_dimnames_map (T)))
126
- end
127
- _known_sub_dimname (dn:: Tuple , :: StaticInt{dim} ) where {dim} = getfield (dn, dim)
128
- function _known_sub_dimname (:: Tuple , :: Pair{StaticSymbol{:underscore},StaticInt{N}} ) where {N}
129
- ntuple (Compat. Returns (:_ ), StaticInt (N))
118
+ dynamic (sub_dimnames_map (known_dimnames (parent_type (T)), map_indices_info (IndicesInfo (T))))
130
119
end
131
120
132
121
function known_dimnames (:: Type{<:ReinterpretArray{T,N,S,A,IsReshaped}} ) where {T,N,S,A,IsReshaped}
@@ -184,11 +173,7 @@ have a name.
184
173
end
185
174
186
175
function dimnames (x:: SubArray )
187
- flatten_tuples (map (Base. Fix1 (_sub_dimname, dimnames (parent (x))), sub_dimnames_map (typeof (x))))
188
- end
189
- _sub_dimname (dn:: Tuple , :: StaticInt{dim} ) where {dim} = getfield (dn, dim)
190
- function _sub_dimname (:: Tuple , :: Pair{StaticSymbol{:underscore},StaticInt{N}} ) where {N}
191
- ntuple (Compat. Returns (static (:_ )), StaticInt (N))
176
+ sub_dimnames_map (dimnames (parent (x)), map_indices_info (IndicesInfo (typeof (x))))
192
177
end
193
178
194
179
dimnames (x:: VecAdjTrans ) = (static (:_ ), getfield (dimnames (parent (x)), 1 ))
0 commit comments