Skip to content

DenseDataLoader

DenseDataLoader(
    dataset: Union[Dataset, Sequence[GraphData]],
    batch_size: int = 1,
    shuffle: bool = False,
    **kwargs,
)

Bases: Dataloader

Data loader stacking dense graphs along a new batch dimension.

Every array attribute must have the same shape in all graphs (e.g. graphs padded to the same number of nodes with a dense adj matrix). Each batch is a GraphData whose arrays have shape [batch_size, ...]. It takes the same arguments as Dataloader, except collate_fn and follow_batch.

Example:

graphs = [
    GraphData(
        edge_index=mx.zeros((2, 0), dtype=mx.int32),
        node_features=mx.ones((5, 3)),
        adj=mx.zeros((5, 5)),
    )
    for _ in range(8)
]
loader = DenseDataLoader(graphs, batch_size=4)
next(iter(loader)).adj.shape  # [4, 5, 5]
Source code in mlx_graphs/loaders/dataloaders.py
def __init__(
    self,
    dataset: Union[Dataset, Sequence[GraphData]],
    batch_size: int = 1,
    shuffle: bool = False,
    **kwargs,
):
    kwargs.pop("collate_fn", None)
    kwargs.pop("follow_batch", None)
    super().__init__(
        dataset,
        batch_size=batch_size,
        shuffle=shuffle,
        collate_fn=_dense_collate,
        **kwargs,
    )

from mlx_graphs.loaders import DenseDataLoader · mlx_graphs/loaders/dataloaders.py