to_dense_adj
¶
to_dense_adj(
edge_index: array,
batch_indices: Optional[array] = None,
edge_features: Optional[array] = None,
max_num_nodes: Optional[int] = None,
) -> array
Converts the edges of a batch of graphs to dense adjacency matrices of
shape [batch_size, max_num_nodes, max_num_nodes].
Entry [b, i, j] holds the edge from the i-th to the j-th node
of graph b. Duplicate edges are summed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge |
required |
batch_indices
|
Optional[array]
|
Array of shape |
None
|
edge_features
|
Optional[array]
|
Optional features of each edge, of shape
|
None
|
max_num_nodes
|
Optional[int]
|
Number of nodes per graph in the output. Edges of nodes
beyond that size are dropped. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The dense adjacency matrices, of shape |
array
|
|
array
|
dimensions are those of |
array
|
|
Example:
edge_index = mx.array([[0, 0, 1, 2, 3], [0, 1, 0, 3, 2]])
batch_indices = mx.array([0, 0, 1, 1])
to_dense_adj(edge_index, batch_indices)
# mx.array([[[1, 1], [1, 0]], [[0, 1], [1, 0]]])
Source code in mlx_graphs/utils/dense.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
from mlx_graphs.utils import to_dense_adj · mlx_graphs/utils/dense.py