radius_graph
¶
radius_graph(
x: array,
r: float,
batch_indices: Optional[array] = None,
loop: bool = False,
max_num_neighbors: Optional[int] = 32,
flow: Literal["source_to_target", "target_to_source"] = "source_to_target",
num_graphs: Optional[int] = None,
) -> array
Computes the graph connecting each point to the points within distance
r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Point coordinates (or features), of shape |
required |
r
|
float
|
The radius. Points at a distance strictly smaller than |
required |
batch_indices
|
Optional[array]
|
Graph of each point, of shape |
None
|
loop
|
bool
|
If |
False
|
max_num_neighbors
|
Optional[int]
|
The maximum number of neighbors of each point; the
closest ones are kept. |
32
|
flow
|
Literal['source_to_target', 'target_to_source']
|
Direction of the edges, for use with message passing. With
|
'source_to_target'
|
num_graphs
|
Optional[int]
|
Number of graphs. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The |
array
|
center point, by increasing neighbor index. |
Example:
import mlx.core as mx
from mlx_graphs.utils import radius_graph
x = mx.array([[-1.0, -1.0], [-1.0, 1.0], [1.0, -1.0], [1.0, 1.0]])
edge_index = radius_graph(x, r=2.5)
>>> edge_index
array([[1, 2, 0, 3, 0, 3, 1, 2],
[0, 0, 1, 1, 2, 2, 3, 3]], dtype=int32)
Source code in mlx_graphs/utils/spatial.py
from mlx_graphs.utils import radius_graph · mlx_graphs/utils/spatial.py