Skip to content

has_isolated_nodes

has_isolated_nodes(edge_index: array, num_nodes: int) -> bool

Function to check for isolated nodes. (i.e. nodes that don't have a link to any other nodes )

Parameters:

Name Type Description Default
edge_index array

Edge index on which to check for isolated nodes.

required
num_nodes int

Number of nodes of the graph.

required

Returns:

Type Description
bool

A boolean of whether the graph has isolated nodes.

Example:

edge_index = mx.array([[0, 2, 0], [2, 0, 0]])
has_isolated_nodes(edge_index, 3)
>>> True
Source code in mlx_graphs/utils/transformations.py
@validate_edge_index
def has_isolated_nodes(edge_index: mx.array, num_nodes: int) -> bool:
    """Function to check for isolated nodes.
    (i.e. nodes that don't have a link to any other nodes )

    Args:
        edge_index: Edge index on which to check for isolated nodes.
        num_nodes: Number of nodes of the graph.

    Returns:
        A boolean of whether the graph has isolated nodes.

    Example:

    .. code-block:: python

        edge_index = mx.array([[0, 2, 0], [2, 0, 0]])
        has_isolated_nodes(edge_index, 3)
        >>> True

    """
    return bool(_connected_nodes(edge_index, num_nodes).sum() < num_nodes)

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