getkeops / keops

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

Question about LazyTensor.step and distance calculation #345

Closed YAndrewL closed 8 months ago

YAndrewL commented 8 months ago

Dear Team, Thanks for the brilliant work and I encountered some questions about the distance calculation another library used pykeops, and I will try to demonstrate as a minial implementation.

x = LazyTensor(x)  # here x with [N, 1, 3]
y = LazyTensor(y)  # here y with [1, M, 3]
dists = ((x - y) ** 2).sum(-1).sqrt()
dists = (1.0 - dist).step()

In this part, we want to calculate the Euclidean distance between two tensors in 3-dimensional space. Yet in the next step, some labels are defined as:

labels = (dists.sum(1) > 1.0).float().view(-1)

However, the Euclidean distance should be greater than 1, and dists should all be less than 1 after 1-dists in the second part. Thus after a step function, all the elements should be 0. Thus dists.sum(1) > 1.0 should be all False, but this part return step True values.

I'm wondering why this happened? Thanks very much for your help!