GraphDataBatch
¶
Bases: GraphData
Concatenates multiple GraphData into a single unified GraphDataBatch
for efficient computation and parallelization over multiple graphs.
All graphs remain disconnected in the batch, meaning that any pairs of graphs
have no nodes or edges in common.
GraphDataBatch can be especially used to speed up graph classification tasks,
where multiple graphs can easily fit into memory and be processed in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graphs
|
list[GraphData]
|
List of |
required |
Example:
from mlx_graphs.data.batch import GraphDataBatch
graphs = [
GraphData(
edge_index=mx.array([[0, 0, 0], [1, 1, 1]]),
node_features=mx.zeros((3, 1)),
),
GraphData(
edge_index=mx.array([[1, 1, 1], [2, 2, 2]]),
node_features=mx.ones((3, 1)),
),
GraphData(
edge_index=mx.array([[3, 3, 3], [4, 4, 4]]),
node_features=mx.ones((3, 1)) * 2,
)
]
batch = GraphDataBatch(graphs)
>>> GraphDataBatch(
edge_index(shape=[2, 9], int32)
node_features(shape=[9, 1], float32))
batch.num_graphs
>>> 3
batch[1]
>>> GraphData(
edge_index(shape=[2, 3], int32)
node_features(shape=[3, 1], float32))
batch[1:]
>>> [
GraphData(
edge_index(shape=[2, 3], int32)
node_features(shape=[3, 1], float32)),
GraphData(
edge_index(shape=[2, 3], int32)
node_features(shape=[3, 1], float32))
]
Methods:
| Name | Description |
|---|---|
batch_indices |
Mask indicating for each node its corresponding batch index. |
batch |
PyG-style alias of |
ptr |
Offsets of the nodes of each graph in the batch, as in PyG: the nodes |
Attributes:
| Name | Type | Description |
|---|---|---|
num_graphs |
int
|
Number of graphs in the batch. |
Source code in mlx_graphs/data/batch.py
batch_indices
¶
Mask indicating for each node its corresponding batch index.
Graphs that carry their own batch_indices (e.g. the outputs of
ShaDowKHopSampler, one subgraph per seed)
keep it, offset per graph so that ids stay distinct, as PyG does with
batch.
Source code in mlx_graphs/data/batch.py
batch
¶
ptr
¶
Offsets of the nodes of each graph in the batch, as in PyG: the nodes
of graph i are ptr[i] to ptr[i + 1] - 1. Has
num_graphs + 1 entries (int32).
Source code in mlx_graphs/data/batch.py
from mlx_graphs.data.batch import GraphDataBatch · mlx_graphs/data/batch.py