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