ToUndirected
¶
ToUndirected(reduce: str = 'add')
Bases: BaseTransform
Makes a graph undirected by adding the reverse of every edge.
Duplicate edges are merged, so that (i, j) and (j, i) are each
present exactly once, and the edges are sorted by source then destination.
Every per-edge attribute (e.g. edge_features, edge_labels) follows:
the values of merged edges are combined with reduce.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reduce
|
str
|
How the attributes of merged edges are combined: |
'add'
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1, 1], [1, 0, 2]]))
graph = ToUndirected()(graph)
graph.edge_index
# mx.array([[0, 1, 1, 2], [1, 0, 2, 1]])
Methods:
| Name | Description |
|---|---|
process |
Adds the reverse edges to |
Source code in mlx_graphs/transforms/structure.py
process
¶
Adds the reverse edges to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The undirected graph. |
Source code in mlx_graphs/transforms/structure.py
from mlx_graphs.transforms import ToUndirected · mlx_graphs/transforms/structure.py