mlx_graphs.utils.transformations.add_self_loops#
- mlx_graphs.utils.transformations.add_self_loops(edge_index: mlx.core.array, edge_features: mlx.core.array | None = None, num_nodes: int | None = None, fill_value: float | mlx.core.array | None = 1, allow_repeated: bool | None = True) mlx.core.array | tuple[mlx.core.array, mlx.core.array] [source]#
Adds self-loops to the given graph represented by edge_index and edge_features.
- Parameters:
edge_index (
array
) – a [2, num_edges] array representing the source and target nodes of each edgeedge_features (
Optional
[array
]) – Optional tensor representing features associated with each edge, with shape [num_edges, num_edge_features]num_nodes (
Optional
[int
]) – Optional number of nodes in the graph. If not provided, it is inferred from edge_index.fill_value (
Union
[float
,array
,None
]) – Value used for filling the self-loop features. Default is 1.allow_repeated (
Optional
[bool
]) – Specify whether to add self-loops for all nodes, even if they are already in the edge_index. Defaults to True.
- Return type:
- Returns:
A tuple containing the updated edge_index and edge_features with self-loops.