import torch


def nullspace(A, tol=1e-12):
    """Compute the nullspace of a certain matrix.

    Args:
        A (torch.Tensor): A matrix.
        tol (float): The tolerance level for determining what the nullspace is.

    Returns:
        (torch.Tensor): A matrix with vectors in the nullspace.
    """
    U, S, V = torch.svd(A, some=False)
    if S.min() >= tol:
        null_start = len(S)
    else:
        null_start = int(len(S) - torch.sum(S<tol))
    V_null = V[:, null_start:]

    return V_null