def stop(M, i):
    """
    Check if the algorithm converged.
    :param M: input matrix
    :param i: iteration steo
    :return: boolean: True if converged
    """
    # this saves time, so we dont have to do multiplication in the first 7 iterations
    if i > 6:
        M_temp = M ** 2 - M
        m = M_temp.max() - M_temp.min()
        if abs(m) < 1e-8:
            return True

    return False