@@ -22,8 +22,22 @@ function is_increasing(perm::Tuple{StaticInt{X},StaticInt{Y}}) where {X, Y}
22
22
end
23
23
is_increasing (:: Tuple{StaticInt{X}} ) where {X} = True ()
24
24
25
+ #=
26
+ ndims_index(::Type{I})::StaticInt
27
+
28
+ The number of dimensions an instance of `I` maps to when indexing an instance of `A`.
29
+ =#
30
+ ndims_index (i) = ndims_index (typeof (i))
31
+ ndims_index (:: Type{I} ) where {I} = static (1 )
32
+ ndims_index (:: Type{I} ) where {N,I<: AbstractCartesianIndex{N} } = static (N)
33
+ ndims_index (:: Type{I} ) where {I<: AbstractArray } = ndims_index (eltype (I))
34
+ ndims_index (:: Type{I} ) where {I<: AbstractArray{Bool} } = static (ndims (I))
35
+ ndims_index (:: Type{I} ) where {N,I<: LogicalIndex{<:Any,<:AbstractArray{Bool,N}} } = static (N)
36
+ _ndims_index (:: Type{I} , i:: StaticInt ) where {I} = ndims_index (_get_tuple (I, i))
37
+ ndims_index (:: Type{I} ) where {N,I<: Tuple{Vararg{Any,N}} } = eachop (_ndims_index, nstatic (Val (N)), I)
38
+
25
39
"""
26
- from_parent_dims(::Type{T}) -> Tuple
40
+ from_parent_dims(::Type{T}):: Tuple{Vararg{Union{Int,StaticInt}}}
27
41
28
42
Returns the mapping from parent dimensions to child dimensions.
29
43
"""
@@ -37,17 +51,16 @@ from_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _from_sub_dims(A
37
51
dim_i = 1
38
52
for i in 1 : ndims (A)
39
53
p = I. parameters[i]
40
- if argdims (A, p) > 0
54
+ if p <: Integer
55
+ push! (out. args, :(StaticInt (0 )))
56
+ else
41
57
push! (out. args, :(StaticInt ($ dim_i)))
42
58
dim_i += 1
43
- else
44
- push! (out. args, :(StaticInt (0 )))
45
59
end
46
60
end
47
61
out
48
62
end
49
63
from_parent_dims (:: Type{<:PermutedDimsArray{T,N,<:Any,I}} ) where {T,N,I} = static (Val (I))
50
-
51
64
function from_parent_dims (:: Type{R} ) where {T,N,S,A,R<: ReinterpretArray{T,N,S,A} }
52
65
if ! _is_reshaped (R) || sizeof (S) === sizeof (T)
53
66
return nstatic (Val (ndims (A)))
@@ -59,7 +72,7 @@ function from_parent_dims(::Type{R}) where {T,N,S,A,R<:ReinterpretArray{T,N,S,A}
59
72
end
60
73
61
74
"""
62
- from_parent_dims(::Type{T}, dim) -> Integer
75
+ from_parent_dims(::Type{T}, dim)::Union{Int,StaticInt}
63
76
64
77
Returns the mapping from child dimensions to parent dimensions.
65
78
"""
@@ -85,7 +98,7 @@ function from_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
85
98
end
86
99
87
100
"""
88
- to_parent_dims(::Type{T}) -> Tuple
101
+ to_parent_dims(::Type{T}):: Tuple{Vararg{Union{Int,StaticInt}}}
89
102
90
103
Returns the mapping from child dimensions to parent dimensions.
91
104
"""
@@ -98,7 +111,7 @@ to_parent_dims(::Type{<:SubArray{T,N,A,I}}) where {T,N,A,I} = _to_sub_dims(A, I)
98
111
out = Expr (:tuple )
99
112
n = 1
100
113
for p in I. parameters
101
- if argdims (A, p) > 0
114
+ if ! (p <: Integer )
102
115
push! (out. args, :(StaticInt ($ n)))
103
116
end
104
117
n += 1
@@ -117,7 +130,7 @@ function to_parent_dims(::Type{R}) where {T,N,S,A,R<:ReinterpretArray{T,N,S,A}}
117
130
end
118
131
119
132
"""
120
- to_parent_dims(::Type{T}, dim) -> Integer
133
+ to_parent_dims(::Type{T}, dim)::Union{Int,StaticInt}
121
134
122
135
Returns the mapping from child dimensions to parent dimensions.
123
136
"""
@@ -143,7 +156,7 @@ function to_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
143
156
end
144
157
145
158
"""
146
- has_dimnames(::Type{T}) -> Bool
159
+ has_dimnames(::Type{T}):: Bool
147
160
148
161
Returns `true` if `x` has names for each dimension.
149
162
"""
160
173
const SUnderscore = StaticSymbol (:_ )
161
174
162
175
"""
163
- dimnames(::Type{T}) -> Tuple{Vararg{StaticSymbol}}
164
- dimnames(::Type{T}, dim) -> StaticSymbol
176
+ dimnames(::Type{T}):: Tuple{Vararg{StaticSymbol}}
177
+ dimnames(::Type{T}, dim):: StaticSymbol
165
178
166
179
Return the names of the dimensions for `x`.
167
180
"""
@@ -191,7 +204,7 @@ function dimnames(::Type{T}) where {T<:SubArray}
191
204
end
192
205
193
206
"""
194
- to_dims(::Type{T}, dim) -> Integer
207
+ to_dims(::Type{T}, dim)::Union{Int,StaticInt}
195
208
196
209
This returns the dimension(s) of `x` corresponding to `d`.
197
210
"""
0 commit comments