def ksum(p, K=2):
    """From

    T. Ogita, S.M. Rump, and S. Oishi.
    Accurate Sum and Dot Product,
    SIAM J. Sci. Comput., 26(6), 1955–1988 (34 pages).
    <https://doi.org/10.1137/030601818>.

    Algorithm 4.8. Summation as in K-fold precision by (K−1)-fold error-free
    vector transformation.
    """
    # Don't override the input data.
    q = p.copy()
    distill(q, K - 1)
    return numpy.sum(q[:-1], axis=0) + q[-1]