def svd_search(S, eps, size):
    """
    Determines the rank of a matrix via the singular values.
    (Counts how many are larger than eps.)
    """
    rank = size-1
    if S[rank] < eps:
        rank -= 1
        while rank > 0:
            if S[rank] >= eps: break
            rank -= 1
    rank += 1
    return rank