Skip to content

Compose

Compose(transforms: Sequence[Callable[[Any], Any]])

Bases: BaseTransform

Chains several transforms together.

The transforms are applied one after the other, each on the output of the previous one. If a transform returns several graphs (e.g. RandomLinkSplit), the following transforms are applied to each of them.

Parameters:

Name Type Description Default
transforms Sequence[Callable[[Any], Any]]

The transforms (or any callables taking and returning a graph) to apply, in order.

required

Example:

from mlx_graphs.transforms.compose import Compose
from mlx_graphs.transforms.features import GCNNorm
from mlx_graphs.transforms.structure import RemoveSelfLoops, ToUndirected

transform = Compose([RemoveSelfLoops(), ToUndirected(), GCNNorm()])
graph = transform(graph)

Methods:

Name Description
process

Applies every transform in order.

Source code in mlx_graphs/transforms/compose.py
def __init__(self, transforms: Sequence[Callable[[Any], Any]]):
    self.transforms = list(transforms)

process

process(data: Any) -> Any

Applies every transform in order.

Parameters:

Name Type Description Default
data Any

A graph, or a list or tuple of graphs.

required

Returns:

Type Description
Any

The output of the last transform.

Source code in mlx_graphs/transforms/compose.py
def process(self, data: Any) -> Any:
    """Applies every transform in order.

    Args:
        data: A graph, or a list or tuple of graphs.

    Returns:
        The output of the last transform.
    """
    for transform in self.transforms:
        if isinstance(data, (list, tuple)):
            data = type(data)(transform(item) for item in data)
        else:
            data = transform(data)
    return data

from mlx_graphs.transforms import Compose · mlx_graphs/transforms/compose.py