172
172
i === nothing && no_dimname_error (T, dim)
173
173
return i
174
174
end
175
- to_dims (:: Type{T} , dims:: Tuple ) where {T} = map (i -> to_dims (T, i), dims)
175
+ #=
176
+ return i
177
+ i = 1
178
+ out = 0
179
+ for s in dimnames(T)
180
+ if Symbol(s) === dim
181
+ out = i
182
+ break
183
+ else
184
+ i += i
185
+ end
186
+ end
187
+ if out === 0
188
+ no_dimname_error(T, dim)
189
+ end
190
+ return out
191
+ end
192
+ =#
176
193
194
+ to_dims (:: Type{T} , dims:: Tuple ) where {T} = map (i -> to_dims (T, i), dims)
177
195
#=
178
196
order_named_inds(names, namedtuple)
179
197
order_named_inds(names, subnames, inds)
@@ -217,6 +235,49 @@ function _order_named_inds_check(inds::Tuple{Vararg{Any,N}}, nkwargs::Int) where
217
235
return nothing
218
236
end
219
237
238
+
239
+ #=
240
+ name_to_idx(name::StaticSymbol, kwargs::Tuple, inds::Tuple, )
241
+ name_to_idx(name::StaticSymbol, kwargs::Tuple, inds::Tuple) = _name_to_index(find_first_eq(), inds)
242
+ _name_to_index(::Zero, ::Tuple) = Colon()
243
+ _name_to_index(::StaticInt{N}, inds::Tuple) where {N} = getfield(inds, N)
244
+
245
+ # return permute(inds, static_find_all_in(nd, x))
246
+ _colon_or_inds(inds::Tuple, ::Zero) = :
247
+ _colon_or_inds(inds::Tuple, ::StaticInt{I}) where {I} = getfield(inds, I)
248
+
249
+ n_i -> _colon_or_inds(inds, find_first_eq(n_i, x))
250
+ # FIXME this needs to insert a colon on missing names
251
+
252
+ @inline function order_named_inds(val::Val{L}; kwargs...) where {L}
253
+ if isempty(kwargs)
254
+ return ()
255
+ else
256
+ return order_named_inds(val, kwargs.data)
257
+ end
258
+ end
259
+ @generated function order_named_inds(val::Val{L}, ni::NamedTuple{K}) where {L,K}
260
+ tuple_issubset(K, L) || throw(DimensionMismatch("Expected subset of $L, got $K"))
261
+ exs = map(L) do n
262
+ if Base.sym_in(n, K)
263
+ qn = QuoteNode(n)
264
+ :(getfield(ni, $qn))
265
+ else
266
+ :(Colon())
267
+ end
268
+ end
269
+ return Expr(:tuple, exs...)
270
+ end
271
+ =#
272
+
273
+ @generated function _perm_tuple (:: Type{T} , :: Val{P} ) where {T,P}
274
+ out = Expr (:curly , :Tuple )
275
+ for p in P
276
+ push! (out. args, T. parameters[p])
277
+ end
278
+ Expr (:block , Expr (:meta , :inline ), out)
279
+ end
280
+
220
281
"""
221
282
axes_types(::Type{T}[, d]) -> Type
222
283
@@ -232,11 +293,14 @@ function axes_types(::Type{T}) where {T}
232
293
return axes_types (parent_type (T))
233
294
end
234
295
end
235
- function axes_types (:: Type{T} ) where {T<: MatAdjTrans }
236
- return eachop_tuple (_get_tuple, axes_types (parent_type (T)), to_parent_dims (T))
296
+ function axes_types (:: Type{T} ) where {T<: Adjoint }
297
+ return _perm_tuple (axes_types (parent_type (T)), Val ((2 , 1 )))
298
+ end
299
+ function axes_types (:: Type{T} ) where {T<: Transpose }
300
+ return _perm_tuple (axes_types (parent_type (T)), Val ((2 , 1 )))
237
301
end
238
- function axes_types (:: Type{T} ) where {T<: PermutedDimsArray }
239
- return eachop_tuple (_get_tuple, axes_types (parent_type (T)), to_parent_dims (T ))
302
+ function axes_types (:: Type{T} ) where {I1, T<: PermutedDimsArray{<:Any,<:Any,I1} }
303
+ return _perm_tuple ( axes_types (parent_type (T)), Val (I1 ))
240
304
end
241
305
function axes_types (:: Type{T} ) where {T<: AbstractRange }
242
306
if known_length (T) === nothing
0 commit comments