import torch


def sym_normalize(A):
    """
    Symmetrical normalization: computes D^-1/2 * A * D^-1/2.

    Parameters
    ----------
    A: torch.Tensor
        The matrix to normalize.

    Returns
    -------
    A_norm: torch.FloatTensor
        The normalized adjacency matrix.
    """
    degs = A.sum(dim=1)
    norm = torch.pow(degs, -0.5)
    norm[torch.isinf(norm)] = 1
    return A * norm[:, None] * norm[None, :]