remove_isolated_nodes
¶
remove_isolated_nodes(
edge_index: array,
edge_features: Optional[array] = None,
num_nodes: Optional[int] = None,
) -> tuple[array, Optional[array], array]
Removes the isolated nodes of a graph and relabels the remaining ones to
[0, num_remaining_nodes) in their original order.
A node is isolated if it has no edge to another node: a node whose only edges are self-loops is isolated, and its self-loops are removed. Each remaining node keeps at most one self-loop (the last one), placed after the other edges, in node order.
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 features of each edge, of shape
|
None
|
num_nodes
|
Optional[int]
|
Number of nodes in the graph. Inferred from |
None
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple |
Optional[array]
|
edges, their features ( |
array
|
shape |
Example:
edge_index = mx.array([[0, 1, 2], [1, 0, 2]])
remove_isolated_nodes(edge_index, num_nodes=4)
# (mx.array([[0, 1], [1, 0]]), None,
# mx.array([True, True, False, False]))
Source code in mlx_graphs/utils/loop.py
from mlx_graphs.utils import remove_isolated_nodes · mlx_graphs/utils/loop.py