import torch


def pinverse(t):
    """
    Computes the pseudo-inverse of a matrix using SVD.

    Parameters
    ----------
    t: torch.tensor
        The matrix whose inverse is to be calculated.

    Returns
    -------
    torch.tensor: Inverse of the matrix `t`.
    """
    u, s, v = t.svd()
    t_inv = v @ torch.diag(torch.where(s != 0, 1 / s, s)) @ u.t()
    return t_inv