getkeops / keops

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

LazyTensor.ndim not giving correct value #376

Open JonasDeSchouwer opened 3 months ago

JonasDeSchouwer commented 3 months ago

The title says it all.

Minimal example:

import torch
from pykeops.torch import LazyTensor

x = LazyTensor(torch.rand((5,1,8)))

print(x.shape)  # (5,1,8)   -> correct
print(x.ndim)   # 8         -> incorrect: always x.shape[-1]

As you can see, the last print should have '3' as output, but instead has '8'. Some experimenting showed that the returned value seems to always be x.shape[-1].

My environment:

huguesva commented 3 months ago

As a remark, I noticed the same thing and resorted to using len(x.shape).

JonasDeSchouwer commented 3 months ago

Yes, I did the same. But it would of course be nicer (and not lead to weird errors for developers expecting the normal behaviour)