Skip to content

invert_sqrt_degree

invert_sqrt_degree(degree: array) -> array

Computes the inverted square root of the degree array.

Parameters:

Name Type Description Default
degree array

Array of length num_nodes with the inverted square root degree of each node.

required

Returns:

Type Description
array

Array of length num_nodes with the inverted square root of the degree of

array

each node with 'inf' values zeroed out.

Source code in mlx_graphs/utils/scatter.py
def invert_sqrt_degree(degree: mx.array) -> mx.array:
    """
    Computes the inverted square root of the degree array.

    Args:
        degree: Array of length num_nodes with the inverted square root degree of
            each node.

    Returns:
        Array of length `num_nodes` with the inverted square root of the degree of
        each node with 'inf' values zeroed out.
    """
    invert_sqrt_degree = degree ** (-0.5)
    invert_sqrt_degree = mx.where(
        invert_sqrt_degree == float("inf"), 0, invert_sqrt_degree
    )
    return invert_sqrt_degree

from mlx_graphs.utils.scatter import invert_sqrt_degree · mlx_graphs/utils/scatter.py