ToDense
¶
Bases: BaseTransform
Converts the edges of a graph to a dense adjacency matrix, as PyG's
ToDense.
The adjacency matrix is stored in adj, with shape [num_nodes,
num_nodes, *]: entry adj[i, j] holds the edge_features of the
edge \((i, j)\) (summed over duplicate edges), or 1 if the graph has
no edge features. edge_index and edge_features are then set to
None.
If num_nodes is given, the graph is padded to that many nodes:
node_features, pos and node_labels get rows of zeros, and a
boolean mask attribute tells which nodes are real. The number of nodes
is stored explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
Optional[int]
|
Number of nodes to pad the graph to. Defaults to the number of nodes of the graph. |
None
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1], [1, 2]]))
graph = ToDense(num_nodes=4)(graph)
graph.adj
# mx.array([[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0]])
graph.mask
# mx.array([True, True, True, False])
Methods:
| Name | Description |
|---|---|
process |
Converts the edges of |
Source code in mlx_graphs/transforms/topology.py
process
¶
Converts the edges of data to a dense adjacency matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with |
Source code in mlx_graphs/transforms/topology.py
from mlx_graphs.transforms import ToDense · mlx_graphs/transforms/topology.py