coalesce
¶
coalesce(
edge_index: array,
edge_features: Optional[array] = None,
num_nodes: Optional[int] = None,
reduce: str = "add",
) -> Union[array, tuple[array, array]]
Sorts edge_index by source then destination and merges duplicate edges.
The features of merged edges are combined with reduce.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Edges to coalesce. |
required |
edge_features
|
Optional[array]
|
Optional features of each edge, of shape
|
None
|
num_nodes
|
Optional[int]
|
Number of nodes. Inferred from |
None
|
reduce
|
str
|
How the features of duplicate edges are combined: |
'add'
|
Returns:
| Type | Description |
|---|---|
Union[array, tuple[array, array]]
|
The sorted edges without duplicates, and their features if |
Union[array, tuple[array, array]]
|
|
Example:
edge_index = mx.array([[1, 0, 1, 0], [0, 1, 0, 2]])
edge_features = mx.array([1.0, 2.0, 3.0, 4.0])
coalesce(edge_index)
# mx.array([[0, 0, 1], [1, 2, 0]])
coalesce(edge_index, edge_features)
# (mx.array([[0, 0, 1], [1, 2, 0]]), mx.array([2.0, 4.0, 4.0]))
Source code in mlx_graphs/utils/transformations.py
from mlx_graphs.utils.transformations import coalesce · mlx_graphs/utils/transformations.py