Skip to content

contains_self_loops

contains_self_loops(edge_index: array) -> bool

Returns True if the graph given by edge_index contains self-loops.

PyG-named alias of has_self_loops().

Parameters:

Name Type Description Default
edge_index array

a [2, num_edges] array representing the source and target nodes of each edge

required

Returns:

Type Description
bool

Whether the graph has at least one edge (i, i).

Example:

contains_self_loops(mx.array([[0, 1, 1], [1, 0, 1]]))
# True
Source code in mlx_graphs/utils/loop.py
@validate_edge_index
def contains_self_loops(edge_index: mx.array) -> bool:
    """
    Returns ``True`` if the graph given by ``edge_index`` contains self-loops.

    PyG-named alias of :func:`~mlx_graphs.utils.transformations.has_self_loops`.

    Args:
        edge_index: a [2, num_edges] array representing the source and target
            nodes of each edge

    Returns:
        Whether the graph has at least one edge ``(i, i)``.

    Example:

    .. code-block:: python

        contains_self_loops(mx.array([[0, 1, 1], [1, 0, 1]]))
        # True
    """
    if edge_index.shape[1] == 0:
        return False
    return has_self_loops(edge_index)

from mlx_graphs.utils import contains_self_loops · mlx_graphs/utils/loop.py