Skip to content

get_unique_edge_indices

get_unique_edge_indices(edge_index_1: array, edge_index_2: array) -> array

Computes the indices of the edges in edge_index_1 that are NOT present in edge_index_2

Parameters:

Name Type Description Default
edge_index_1 array

The first edge index array.

required
edge_index_2 array

The second edge index array.

required

Returns:

Type Description
array

The indices of the edges in edge_index_1 that are not present in edge_index_2

Example:

edge_index_1 = mx.array(
    [
        [0, 1, 1, 2],
        [1, 0, 2, 1],
    ]
)
edge_index_2 = mx.array(
    [
        [1, 2, 2],
        [2, 1, 2],
    ]
)
x = get_unique_edge_indices(edge_index_1, edge_index_2)
# [0, 1]
Source code in mlx_graphs/utils/transformations.py
def get_unique_edge_indices(edge_index_1: mx.array, edge_index_2: mx.array) -> mx.array:
    """
    Computes the indices of the edges in edge_index_1 that are NOT present in
    edge_index_2

    Args:
        edge_index_1: The first edge index array.
        edge_index_2: The second edge index array.

    Returns:
        The indices of the edges in edge_index_1 that are not present in edge_index_2


    Example:

    .. code-block:: python

        edge_index_1 = mx.array(
            [
                [0, 1, 1, 2],
                [1, 0, 2, 1],
            ]
        )
        edge_index_2 = mx.array(
            [
                [1, 2, 2],
                [2, 1, 2],
            ]
        )
        x = get_unique_edge_indices(edge_index_1, edge_index_2)
        # [0, 1]
    """
    edges_1, edges_2 = _to_numpy(edge_index_1), _to_numpy(edge_index_2)
    num_nodes = int(max(edges_1.max(initial=-1), edges_2.max(initial=-1))) + 1
    present = np.isin(_edge_keys(edges_1, num_nodes), _edge_keys(edges_2, num_nodes))
    return mx.array(np.nonzero(~present)[0])

from mlx_graphs.utils.transformations import get_unique_edge_indices · mlx_graphs/utils/transformations.py