add_self_loops
¶
add_self_loops(
edge_index: array,
edge_features: Optional[array] = None,
num_nodes: Optional[int] = None,
fill_value: Optional[Union[float, array]] = 1,
allow_repeated: Optional[bool] = True,
) -> Union[array, tuple[array, array]]
Adds self-loops to the given graph represented by edge_index and edge_features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge |
required |
edge_features
|
Optional[array]
|
Optional tensor representing features associated with each edge, with shape [num_edges, num_edge_features] |
None
|
num_nodes
|
Optional[int]
|
Optional number of nodes in the graph. If not provided, it is inferred from edge_index. |
None
|
fill_value
|
Optional[Union[float, array]]
|
Value used for filling the self-loop features. Default is 1. |
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. |
True
|
Returns:
| Type | Description |
|---|---|
Union[array, tuple[array, array]]
|
A tuple containing the updated edge_index and edge_features with self-loops. |
Source code in mlx_graphs/utils/transformations.py
from mlx_graphs.utils.transformations import add_self_loops · mlx_graphs/utils/transformations.py