pytorch_cluster
pytorch_cluster copied to clipboard
Non-intuitive behavior of `radius_graph` when `max_num_neighbors` is too small.
trafficstars
Let's create 3 points in 1D space:
import torch as pt
from torch_cluster import radius_graph
x = pt.tensor([[0.], [1.], [2.]], device='cuda')
If max_num_neighbors is 2 or more, it find the expected number of neighbors (6 = 3 points x 2 neighbors):
radius_graph(x, r=2.5, max_num_neighbors=2)
tensor([[1, 2, 0, 2, 0, 1],
[0, 0, 1, 1, 2, 2]], device='cuda:0')
If max_num_neighbors is 1 (too small), it finds just 4 neighbors (it should be 3 = 3 points x 1 neighbor) and misses the rest:
radius_graph(x, r=2.5, max_num_neighbors=1)
tensor([[1, 0, 0, 1],
[0, 1, 2, 2]], device='cuda:0')
I cannot image any application, where it could be a desired behavior. So, the function should fail if max_num_neighbors is too small.