nexus
nexus copied to clipboard
numpy-style indexing
Would be nice if it is possible to index tensors with other index-typed tensors.
Notes here from @kitsing :
NumPy-style advanced indexing has form A[X1, X2, ..., Xk], where
- the indexee
Ahaskdims, here in Nexus typed with axes-descriptor(A1, A2, ..., Ak) - there must be exactly
kindexersX1, ...,Xk, each must be of any of the 3 following forms:- an
Intindex: e.g.2; - a range-style object, in the style of NumPy:
:/1:,:4; - another tensor of dims
(B1, B2, ..., Bm).
- an
@kitsing pointed out that advanced indexing is valid if and only if all indexers X1, ..., Xk can be promoted/broadcasted to the same shape (or in Nexus, same axes-type):
- An
Intindex is assumed to be of type(); - A range object at the
i-th position of the indexeeAis assumed to be of type(Ai, ); - Tensor indexers is typed as they originally are.
Hence we have
def advIdx[T[_], U, Vs]
(indexee: T[U])(indexers: Vs)(implicit v: BroadcastN.Aux[Vs, V]): T[V]
// Vs is an HList of type descriptors
// e.g.
advIdx(T[(α, β, γ)])(T[(α)], T[(δ)], ?): T[(α, δ, γ)]