@@ -36,6 +36,12 @@ function is_increasing(perm::Tuple{StaticInt{X},StaticInt{Y}}) where {X, Y}
36
36
end
37
37
is_increasing (:: Tuple{StaticInt{X}} ) where {X} = True ()
38
38
39
+ """
40
+ from_parent_dims(::Type{T}) -> Tuple{Vararg{Union{Int,StaticInt}}}
41
+ from_parent_dims(::Type{T}, dim) -> Union{Int,StaticInt}
42
+
43
+ Returns the mapping from parent dimensions to child dimensions.
44
+ """
39
45
from_parent_dims (x) = from_parent_dims (typeof (x))
40
46
from_parent_dims (:: Type{T} ) where {T} = nstatic (Val (ndims (T)))
41
47
from_parent_dims (:: Type{T} ) where {T<: VecAdjTrans } = (StaticInt (2 ),)
@@ -76,7 +82,6 @@ Compat.@constprop :aggressive function from_parent_dims(::Type{T}, dim::Int)::In
76
82
throw_dim_error (T, dim)
77
83
end
78
84
end
79
-
80
85
function from_parent_dims (:: Type{T} , :: StaticInt{dim} ) where {T,dim}
81
86
if dim > ndims (T)
82
87
return static (ndims (parent_type (T)) + dim - ndims (T))
@@ -87,6 +92,12 @@ function from_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
87
92
end
88
93
end
89
94
95
+ """
96
+ to_parent_dims(::Type{T}) -> Tuple{Vararg{Union{Int,StaticInt}}}
97
+ to_parent_dims(::Type{T}, dim) -> Union{Int,StaticInt}
98
+
99
+ Returns the mapping from child dimensions to parent dimensions.
100
+ """
90
101
to_parent_dims (x) = to_parent_dims (typeof (x))
91
102
to_parent_dims (:: Type{T} ) where {T} = nstatic (Val (ndims (T)))
92
103
to_parent_dims (:: Type{T} ) where {T<: Union{Transpose,Adjoint} } = (StaticInt (2 ), One ())
@@ -135,10 +146,21 @@ function to_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
135
146
end
136
147
end
137
148
138
- @inline function has_dimnames (x)
139
- static (known_dimnames (x) != = ntuple (Compat. Returns (:_ ), Val (ndims (x))))
140
- end
149
+ """
150
+ has_dimnames(::Type{T}) -> Bool
141
151
152
+ Returns `true` if `x` has on or more named dimensions. If all dimensions correspond
153
+ to `:_`, then `false` is returned.
154
+ """
155
+ @inline has_dimnames (x) = static (known_dimnames (x) != = ntuple (Compat. Returns (:_ ), Val (ndims (x))))
156
+
157
+ """
158
+ known_dimnames(::Type{T}) -> Tuple{Vararg{Union{Symbol,Nothing}}}
159
+ known_dimnames(::Type{T}, dim::Union{Int,StaticInt}) -> Union{Symbol,Nothing}
160
+
161
+ Return the names of the dimensions for `x`. `:_` is used to indicate a dimension does not
162
+ have a name.
163
+ """
142
164
@inline known_dimnames (x, dim:: Integer ) = _known_dimname (known_dimnames (x), canonicalize (dim))
143
165
known_dimnames (x) = known_dimnames (typeof (x))
144
166
known_dimnames (:: Type{T} ) where {T} = _known_dimnames (T, parent_type (T))
155
177
end
156
178
@inline _inbounds_known_dimname (x, dim) = @inbounds (_known_dimname (x, dim))
157
179
180
+ """
181
+ dimnames(x) -> Tuple{Vararg{Union{Symbol,StaticSymbol}}}
182
+ dimnames(x, dim::Union{Int,StaticInt}) -> Union{Symbol,StaticSymbol}
183
+
184
+ Return the names of the dimensions for `x`. `:_` is used to indicate a dimension does not
185
+ have a name.
186
+ """
158
187
@inline dimnames (x, dim:: Integer ) = _dimname (dimnames (x), canonicalize (dim))
159
188
@inline dimnames (x) = _dimnames (has_parent (x), x)
160
189
@inline function _dimnames (:: True , x)
@@ -169,6 +198,11 @@ _dimnames(::False, x) = ntuple(_->static(:_), Val(ndims(x)))
169
198
end
170
199
@inline _inbounds_dimname (x, dim) = @inbounds (_dimname (x, dim))
171
200
201
+ """
202
+ to_dims(x, dim) -> Union{Int,StaticInt}
203
+
204
+ This returns the dimension(s) of `x` corresponding to `dim`.
205
+ """
172
206
to_dims (x, dim:: Colon ) = dim
173
207
to_dims (x, dim:: Integer ) = canonicalize (dim)
174
208
to_dims (x, dim:: Union{StaticSymbol,Symbol} ) = _to_dim (dimnames (x), dim)
0 commit comments