getkeops / keops

KErnel OPerationS, on CPUs and GPUs, with autodiff and without memory overflows
https://www.kernel-operations.io
MIT License
1.03k stars 65 forks source link

Slice LazyTensor of shape (M,N) but with ndim=1 #292

Open tiangexiang opened 1 year ago

tiangexiang commented 1 year ago

Hi, I am trying to slice a lazy tensor in this way:

N, M, C = 5000, 2000, 10  
a = LazyTensor(torch.randn(1, N, C))  
b =  LazyTensor(torch.randn(M, 1, C))
c = (a-b).norm2() 
print(c.shape) # this gives [M, N]
d = c[10:20]
print(d.shape) # this gives an error, but I hope to get the shape [M, 10]

However, I encountered an error saying "Starting index is out of bounds" with ndim is actually 1. How can I correctly slice the tensor as the way I expect?

Thank you!

JonasDeSchouwer commented 3 days ago

Just as a comment to this question, ndim currently doesn't work properly in PyKeops (see https://github.com/getkeops/keops/issues/376). So you should assume c.shape is correct.

JonasDeSchouwer commented 3 days ago

To actually solve your question (pbb a lot too late), can you try: d = c[:, 10:20]