Skip to content

contains_isolated_nodes

contains_isolated_nodes(
    edge_index: array, num_nodes: Optional[int] = None
) -> bool

Returns True if the graph given by edge_index contains isolated nodes, i.e. nodes without any edge to another node (self-loops are ignored).

PyG-named alias of has_isolated_nodes(), where num_nodes is optional.

Parameters:

Name Type Description Default
edge_index array

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

required
num_nodes Optional[int]

Number of nodes in the graph. Inferred from edge_index if not given.

None

Returns:

Type Description
bool

Whether the graph has isolated nodes.

Example:

contains_isolated_nodes(mx.array([[0, 1, 2], [1, 0, 2]]))
# True (node 2 only has a self-loop)
Source code in mlx_graphs/utils/loop.py
@validate_edge_index
def contains_isolated_nodes(
    edge_index: mx.array, num_nodes: Optional[int] = None
) -> bool:
    """
    Returns ``True`` if the graph given by ``edge_index`` contains isolated
    nodes, i.e. nodes without any edge to another node (self-loops are
    ignored).

    PyG-named alias of
    :func:`~mlx_graphs.utils.transformations.has_isolated_nodes`, where
    ``num_nodes`` is optional.

    Args:
        edge_index: a [2, num_edges] array representing the source and target
            nodes of each edge
        num_nodes: Number of nodes in the graph. Inferred from ``edge_index``
            if not given.

    Returns:
        Whether the graph has isolated nodes.

    Example:

    .. code-block:: python

        contains_isolated_nodes(mx.array([[0, 1, 2], [1, 0, 2]]))
        # True (node 2 only has a self-loop)
    """
    return has_isolated_nodes(edge_index, _infer_num_nodes(edge_index, num_nodes))

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