unbatch_edge_index
¶
unbatch_edge_index(
edge_index: array, batch_indices: array, batch_size: Optional[int] = None
) -> list[array]
Splits the edge_index of a batch of graphs into one edge_index per
graph, with the node ids of each graph starting at 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge of the batch, with the edges of each graph stored contiguously and in graph order. |
required |
batch_indices
|
array
|
The graph of each node, of shape |
required |
batch_size
|
Optional[int]
|
Number of graphs. Inferred from |
None
|
Returns:
| Type | Description |
|---|---|
list[array]
|
A list with the |
Example:
edge_index = mx.array([[0, 1, 1, 2, 4, 5, 5, 6], [1, 0, 2, 1, 5, 4, 6, 5]])
batch_indices = mx.array([0, 0, 0, 0, 1, 1, 1])
unbatch_edge_index(edge_index, batch_indices)
# [mx.array([[0, 1, 1, 2], [1, 0, 2, 1]]),
# mx.array([[0, 1, 1, 2], [1, 0, 2, 1]])]
Source code in mlx_graphs/utils/unbatch.py
from mlx_graphs.utils import unbatch_edge_index · mlx_graphs/utils/unbatch.py