Skip to content

has_self_loops

has_self_loops(edge_index: array) -> bool

Function to check for self loops.

Parameters:

Name Type Description Default
edge_index array

Edge index on which to check for self loops.

required

Returns:

Type Description
bool

A boolean of whether the graph has self loops.

Example:

edge_index = mx.array([[0, 2, 0], [2, 0, 0]])
has_self_loops(edge_index)
>>> True
Source code in mlx_graphs/utils/transformations.py
@validate_edge_index
def has_self_loops(edge_index: mx.array) -> bool:
    """Function to check for self loops.

    Args:
        edge_index: Edge index on which to check for self loops.

    Returns:
        A boolean of whether the graph has self loops.

    Example:

    .. code-block:: python

        edge_index = mx.array([[0, 2, 0], [2, 0, 0]])
        has_self_loops(edge_index)
        >>> True
    """

    return ((edge_index[0] == edge_index[1]).sum() > 0).item()

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