import math


def downsample(data, factor, reduce):
    """This function is used to downsample data in blocks of size `factor`.

    This function downsamples blocks of size `factor` using the function specified in reduce. If
    there are insufficient points to fill a final block, this last block is discarded.

    Parameters
    ----------
    data : array_like
        Input data
    factor : int
        Factor to downsample by
    reduce : callable
        Function to use for reducing the data
    """

    def round_down(size, n):
        """Round down `size` to the nearest multiple of `n`"""
        return int(math.floor(size / n)) * n

    data = data[: round_down(data.size, factor)]
    return reduce(data.reshape(-1, factor), axis=1)