unbatch
¶
Functions:
| Name | Description |
|---|---|
unbatch |
Splits |
unbatch_edge_index |
Splits the |
unbatch
¶
unbatch(
src: array,
batch_indices: array,
axis: int = 0,
batch_size: Optional[int] = None,
) -> list[array]
Splits src into one array per graph, according to batch_indices.
This is the array-level counterpart of
mlx_graphs.data.batch.unbatch(), which splits a whole
GraphDataBatch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
array
|
The array to split, e.g. node features of shape
|
required |
batch_indices
|
array
|
The graph of each entry of |
required |
axis
|
int
|
The axis along which to split. Default: |
0
|
batch_size
|
Optional[int]
|
Number of graphs. Inferred from |
None
|
Returns:
| Type | Description |
|---|---|
list[array]
|
A list with one array per graph. |
Example:
src = mx.arange(7)
batch_indices = mx.array([0, 0, 0, 1, 1, 2, 2])
unbatch(src, batch_indices)
# [mx.array([0, 1, 2]), mx.array([3, 4]), mx.array([5, 6])]
Source code in mlx_graphs/utils/unbatch.py
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 · mlx_graphs/utils/unbatch.py