mlx_graphs.utils.transformations.to_sparse_adjacency_matrix

mlx_graphs.utils.transformations.to_sparse_adjacency_matrix#

mlx_graphs.utils.transformations.to_sparse_adjacency_matrix(adjacency_matrix: mlx.core.array, *, dtype: mlx.core.Dtype = mlx.core.uint32) tuple[mlx.core.array, mlx.core.array][source]#

Converts an adjacency matrix to a sparse representation as a tuple of edge index and edge features.

Parameters:
  • adjacency_matrix (array) – the input adjacency matrix

  • dtype (Dtype) – type of the output edge_index. Default to uint32.

Return type:

tuple[array, array]

Returns:

A tuple representing the edge index and edge features

Example:

matrix = mx.array(
    [
        [0, 1, 2],
        [3, 0, 0],
        [5, 1, 2],
    ]
)
edge_index, edge_features = to_sparse_adjacency_matrix(matrix)

edge_index
# mx.array([[0, 0, 1, 2, 2, 2], [1, 2, 0, 0, 1, 2]])

edge_features
# mx.array([1, 2, 3, 5, 1, 2])