def compute_rank_ref(ref, threshold):
    """
    Function for computing the rank from the Row Echelon Form of u.

    Parameters
    __________

    ref: (2D float64 numpy array)
    The input Row Echelon form of u.

    threshold: (Float)
    See documentation of the function "sort_rows_fast".


    Returns
    __________

    rank: (Integer)
    rank of u computed from its Row Echelon Form.

    """

    rows, cols = ref.shape
    j = 0
    rank = 0
    halt = False

    for i in range(rows):
        while (-threshold <= ref[i, j] <= threshold):
            if j == cols - 1:
                halt = True
                break
            j += 1

        if halt:
            break

        rank += 1

    return rank