ctongfei / nexus

Experimental tensor-typed deep learning
https://tongfei.me/nexus/
MIT License
257 stars 15 forks source link

numpy-style indexing #31

Open kitsing opened 5 years ago

kitsing commented 5 years ago

Would be nice if it is possible to index tensors with other index-typed tensors.

ctongfei commented 5 years ago

Notes here from @kitsing :

NumPy-style advanced indexing has form A[X1, X2, ..., Xk], where

@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):

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[(α, δ, γ)]