Skip to content

sort_edge_index_and_features

sort_edge_index_and_features(
    edge_index: array, edge_features: array
) -> tuple[array, array]

Sorts the given edge_index and their corresponding features.

Parameters:

Name Type Description Default
edge_index array

A [2, num_edges] array representing edge indices, where the first row contains source indices and the second row contains target indices.

required
edge_features array

An array representing edge features, where each row corresponds to an edge.

required

Returns:

Type Description
array

A tuple containing the sorted edge index and the

array

corresponding sorted edge features.

Source code in mlx_graphs/utils/sorting.py
@validate_edge_index_and_features
def sort_edge_index_and_features(
    edge_index: mx.array, edge_features: mx.array
) -> tuple[mx.array, mx.array]:
    """Sorts the given edge_index and their corresponding features.

    Args:
        edge_index: A [2, num_edges] array representing edge indices,
            where the first row contains source indices and the second row contains
            target indices.
        edge_features: An array representing edge features, where each row
            corresponds to an edge.

    Returns:
        A tuple containing the sorted edge index and the
        corresponding sorted edge features.
    """
    sorted_edge_index, sorting_indices = sort_edge_index(edge_index)
    sorted_edge_features = edge_features[sorting_indices]
    return sorted_edge_index, sorted_edge_features

from mlx_graphs.utils.sorting import sort_edge_index_and_features · mlx_graphs/utils/sorting.py