radius_graph(x: Tensor, r: float, batch: = None, loop: bool = False, max_num_neighbors: int = 32, flow: str = 'source_to_target', num_workers: int = 1, batch_size: = None) [source]

Computes graph edges to all points within a given distance.

import torch

x = torch.Tensor([[-1, -1], [-1, 1], [1, -1], [1, 1]])
batch = torch.tensor([0, 0, 0, 0])
edge_index = radius_graph(x, r=1.5, batch=batch, loop=False)

Parameters
• x (torch.Tensor) – Node feature matrix $$\mathbf{X} \in \mathbb{R}^{N \times F}$$.

• r (float) – The radius.

• batch (torch.Tensor, optional) – Batch vector $$\mathbf{b} \in {\{ 0, \ldots, B-1\}}^N$$, which assigns each node to a specific example. (default: None)

• loop (bool, optional) – If True, the graph will contain self-loops. (default: False)

• max_num_neighbors (int, optional) – The maximum number of neighbors to return for each element in y. (default: 32)

• flow (str, optional) – The flow direction when using in combination with message passing ("source_to_target" or "target_to_source"). (default: "source_to_target")

• num_workers (int, optional) – Number of workers to use for computation. Has no effect in case batch is not None, or the input lies on the GPU. (default: 1)

• batch_size (int, optional) – The number of examples $$B$$. Automatically calculated if not given. (default: None)

Return type

torch.Tensor