def distill(p, K):
    """Algorithm 4.3. Error-free vector transformation for summation.

    The vector p is transformed without changing the sum, and p_n is replaced
    by float(sum(p)). Kahan [21] calls this a 'distillation algorithm.'
    """
    q = p.reshape(p.shape[0], -1)
    for _ in range(K):
        _accupy.distill(q)
    return q.reshape(p.shape)