ankane / torch.rb

Deep learning for Ruby, powered by LibTorch
Other
704 stars 30 forks source link

Tensor ellipsis indexing and step slicing #37

Open orlando-labs opened 1 year ago

orlando-labs commented 1 year ago

Hi, @ankane!

Working recently on some Fairseq models porting, I met the following line:

residual = residual[..., :: r_tsz // tsz][..., :tsz]

What can we do with such ellipsis indexing and step slicing while keeping Ruby clarity?

UPD: according to docs

It’s also important to note that index types such as None / Ellipsis / Slice live in the torch::indexing namespace
ankane commented 1 year ago

Hi @orlando-labs, there could probably be Torch::Ellipsis and Torch::Slice classes for this (similar to the C++ API). I'm not sure it would be especially Ruby-like, but would make it easier to port code.

orlando-labs commented 1 year ago

Looks like the only way to go.