def mse(pred, target, weights=1.0, reduce=True):
    """
    Computes the MSE between pred and target.

    Args:
        pred(np.ndarray): array of predicted data.
        target(np.ndarray): array of target data.
        weights(list[float], float): weights for each value.
        reduce(bool): if reduction method should be applied.

    Returns:
        (np.ndarray): mse between pred and target

    """
    dist = weights * ((pred - target) ** 2).mean(axis=-1)
    return dist.mean() if reduce else dist