torch_geometric.nn.pool.approx_knn
- approx_knn(x: Tensor, y: Tensor, k: int, batch_x: Optional[Tensor] = None, batch_y: Optional[Tensor] = None) Tensor [source]
Finds for each element in
y
thek
approximated nearest points inx
.Note
Approximated \(k\)-nearest neighbor search is performed via the pynndescent library.
- Parameters:
x (torch.Tensor) – Node feature matrix \(\mathbf{X} \in \mathbb{R}^{N \times F}\).
y (torch.Tensor) – Node feature matrix \(\mathbf{X} \in \mathbb{R}^{M \times F}\).
k (int) – The number of neighbors.
batch_x (torch.Tensor, optional) – Batch vector \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N\), which assigns each node to a specific example. (default:
None
)batch_y (torch.Tensor, optional) – Batch vector \(\mathbf{b} \in {\{ 0, \ldots, B-1\}}^M\), which assigns each node to a specific example. (default:
None
)
- Return type:
torch.Tensor