GraphStore
¶
Bases: ABC
Abstract store of the edges of a graph, following PyG's
GraphStore.
Subclasses implement _put_edge_index(), _get_edge_index(),
_remove_edge_index() and get_all_edge_attrs(); edges are
exchanged as pairs of np.ndarray (mx.array is accepted when
putting).
Example:
from mlx_graphs.data import InMemoryGraphStore
graph_store = InMemoryGraphStore()
graph_store.put_edge_index(
data.edge_index, layout="coo", size=(data.num_nodes, data.num_nodes)
)
colptr, row, perm = graph_store.csc()
Methods:
| Name | Description |
|---|---|
get_all_edge_attrs |
The attributes of all the stored edges. |
put_edge_index |
Adds edges, as a |
get_edge_index |
The edges of |
remove_edge_index |
Removes the edges of |
num_nodes |
|
num_edges |
Number of edges of |
coo |
|
csc |
|
csr |
|
Source code in mlx_graphs/data/graph_store.py
get_all_edge_attrs
abstractmethod
¶
put_edge_index
¶
put_edge_index(
edge_index: Union[array, ndarray, tuple],
edge_type: Any = None,
layout: EdgeLayout = "coo",
size: Optional[tuple[int, int]] = None,
is_sorted: bool = False,
) -> bool
Adds edges, as a [2, num_edges] array or a pair of arrays
((row, col) for COO, (row, colptr) for CSC, (rowptr, col)
for CSR).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
Union[array, ndarray, tuple]
|
The edges. |
required |
edge_type
|
Any
|
Their type ( |
None
|
layout
|
EdgeLayout
|
|
'coo'
|
size
|
Optional[tuple[int, int]]
|
|
None
|
is_sorted
|
bool
|
Whether COO edges are sorted by destination. |
False
|
Source code in mlx_graphs/data/graph_store.py
get_edge_index
¶
get_edge_index(
edge_type: Any = None, layout: Optional[EdgeLayout] = None
) -> tuple[ndarray, ndarray]
The edges of edge_type as stored (layout=None) or
converted to layout.
Source code in mlx_graphs/data/graph_store.py
remove_edge_index
¶
Removes the edges of edge_type.
Source code in mlx_graphs/data/graph_store.py
num_nodes
¶
(num_src_nodes, num_dst_nodes) of edge_type.
num_edges
¶
Number of edges of edge_type.
Source code in mlx_graphs/data/graph_store.py
coo
¶
(row, col) of edge_type, in the original edge order for
edges stored as COO.
Source code in mlx_graphs/data/graph_store.py
csc
¶
(colptr, row, perm) of edge_type: the in-edges of every
node, and the position in the stored COO edges of every CSC entry
(None if the stored edges need no permutation). Cached.
Source code in mlx_graphs/data/graph_store.py
csr
¶
(rowptr, col, perm) of edge_type (out-edges of every
node).
Source code in mlx_graphs/data/graph_store.py
from mlx_graphs.data import GraphStore · mlx_graphs/data/graph_store.py