import logging


def data_compare(real_out, expect_out, atol=0.001, rtol=0.001):
    """Compare the output between the real and the expect.

    :param real_out: the real output
    :type real_out: list
    :param expect_out: the expect putput, or the benchmark
    :type expect_out: list
    :param atol: the absolute error, defaults to 0.001
    :type atol: float, optional
    :param rtol: the relative error, defaults to 0.001
    :type rtol: float, optional
    :return: return the error count and the error ratio
    :rtype: [type]
    """
    error_count = 0
    if len(real_out) != len(expect_out):
        raise ValueError("The size of real_out and expect_out must be equal.")
    for n in range(len(real_out)):
        if abs(real_out[n] - expect_out[n]) > atol or abs(real_out[n] - expect_out[n]) / abs(expect_out[n]) > rtol:
                logging.warning("pos: {}, real_out: {}, expect_out: {}, diff: {} "
                                .format([n], real_out[n], expect_out[n], real_out[n] - expect_out[n]))
                error_count += 1
    return error_count, error_count / len(real_out)