@@ -146,37 +146,39 @@ function to_parent_dims(::Type{T}, ::StaticInt{dim}) where {T,dim}
146
146
throw_dim_error (T, dim)
147
147
end
148
148
end
149
-
150
- _nunderscore (:: Val{N} ) where {N} = ntuple (Compat . Returns (:_ ), Val (N))
149
+ struct Returns{T}; x :: T ; end ; @inline (r :: Returns )(_ :: Vararg{Any,K} ) where {K} = r . x
150
+ _nunderscore (:: Val{N} ) where {N} = ntuple (Returns (nothing ), Val (N))
151
151
152
152
"""
153
153
has_dimnames(::Type{T}) -> StaticBool
154
154
155
155
Returns `static(true)` if `x` has on or more named dimensions. If all dimensions correspond
156
- to `static(:_) `, then `static(false)` is returned.
156
+ to `nothing `, then `static(false)` is returned.
157
157
"""
158
158
Compat. @constprop :aggressive has_dimnames (x) = static (_is_named (known_dimnames (x)))
159
- _is_named (x:: NTuple{N,Symbol} ) where {N} = x != = _nunderscore (Val (N))
160
- _is_named (:: Any ) = true
159
+ _is_named (x:: Tuple{Nothing,Vararg} ) = _is_named (Base. tail (x))
160
+ _is_named (x:: Tuple{Nothing} ) = false
161
+ _is_named (x:: Tuple{Symbol,Vararg} ) = true
162
+ _is_named (x:: Tuple{} ) = true
161
163
162
164
"""
163
165
known_dimnames(::Type{T}) -> Tuple{Vararg{Union{Symbol,Nothing}}}
164
166
known_dimnames(::Type{T}, dim::Union{Int,StaticInt}) -> Union{Symbol,Nothing}
165
167
166
- Return the names of the dimensions for `x`. `:_ ` is used to indicate a dimension does not
168
+ Return the names of the dimensions for `x`. `nothing ` is used to indicate a dimension does not
167
169
have a name.
168
170
"""
169
171
@inline known_dimnames (x, dim:: Integer ) = _known_dimname (known_dimnames (x), canonicalize (dim))
170
172
known_dimnames (x) = known_dimnames (typeof (x))
171
173
known_dimnames (:: Type{T} ) where {T} = _known_dimnames (T, parent_type (T))
172
174
_known_dimnames (:: Type{T} , :: Type{T} ) where {T} = _unknown_dimnames (Base. IteratorSize (T))
173
175
_unknown_dimnames (:: Base.HasShape{N} ) where {N} = _nunderscore (Val (N))
174
- _unknown_dimnames (:: Any ) = (:_ ,)
176
+ _unknown_dimnames (:: Any ) = (nothing ,)
175
177
function _known_dimnames (:: Type{C} , :: Type{P} ) where {C,P}
176
178
eachop (_inbounds_known_dimname, to_parent_dims (C), known_dimnames (P))
177
179
end
178
180
@inline function _known_dimname (x:: Tuple{Vararg{Any,N}} , dim:: CanonicalInt ) where {N}
179
- @boundscheck (dim > N || dim < 1 ) && return :_
181
+ (dim > N || dim < 1 ) && return nothing
180
182
return @inbounds (x[dim])
181
183
end
182
184
@inline _inbounds_known_dimname (x, dim) = @inbounds (_known_dimname (x, dim))
@@ -185,17 +187,17 @@ end
185
187
dimnames(x) -> Tuple{Vararg{Union{Symbol,StaticSymbol}}}
186
188
dimnames(x, dim::Union{Int,StaticInt}) -> Union{Symbol,StaticSymbol}
187
189
188
- Return the names of the dimensions for `x`. `:_ ` is used to indicate a dimension does not
190
+ Return the names of the dimensions for `x`. `nothing ` is used to indicate a dimension does not
189
191
have a name.
190
192
"""
191
193
@inline dimnames (x, dim:: Integer ) = _dimname (dimnames (x), canonicalize (dim))
192
194
@inline dimnames (x) = _dimnames (has_parent (x), x)
193
195
@inline function _dimnames (:: True , x)
194
196
eachop (_inbounds_dimname, to_parent_dims (x), dimnames (parent (x)))
195
197
end
196
- _dimnames (:: False , x) = ntuple (_-> static ( :_ ) , Val (ndims (x)))
198
+ _dimnames (:: False , x) = ntuple (_-> nothing , Val (ndims (x)))
197
199
@inline function _dimname (x:: Tuple{Vararg{Any,N}} , dim:: CanonicalInt ) where {N}
198
- @boundscheck (dim > N || dim < 1 ) && return static ( :_ )
200
+ @boundscheck (dim > N || dim < 1 ) && return nothing
199
201
return @inbounds (x[dim])
200
202
end
201
203
@inline _inbounds_dimname (x, dim) = @inbounds (_dimname (x, dim))
0 commit comments