from warnings import warn
import torch


def extract_mean_std(hnet_outputs, return_logvar=False):
    """Extract mean and standard deviation for a multivariate Gaussian
    distribution with diagonal covaiance matrix from a hypernetwork that outputs
    mean and log-variance.

    .. deprecated:: 1.0
        Please use a main network wrapper such as
        :class:`probabilistic.gauss_mnet_interface.GaussianBNNWrapper` or the
        function :func:`decode_diag_gauss` rather than working with
        the hypernet output directly.

    Args:
        hnet_outputs: See docstring of method :func:`sample_diag_gaus_weights`.
        return_logvar (optional): If set, a third value will be returned,
            corresponding to the log-variance.

    Returns:
        Two lists of tensors: `mean` and `std`.
    """
    warn('Please use a main network wrapper such as class' +
        '"probabilistic.gauss_mnet_interface.GaussianBNNWrapper" or the' +
        'function "decode_diag_gauss" rather than working with ' +
        'the hypernet output directly.', DeprecationWarning)

    assert(len(hnet_outputs) % 2 == 0)
    n = len(hnet_outputs) // 2

    mean = hnet_outputs[n:]
    logvar = hnet_outputs[:n]
    std = [torch.exp(0.5 * logvar[i]) for i in range(n)]

    if return_logvar:
        return mean, std, logvar
    return mean, std