import torch


def reparametrize(mu, log_var, device):
    """
    Reparametrize based on input mean and log variance

    Parameters
    ----------
    mu : torch.tensor
        The mean.
    log_var : torch.tensor
        The log variance.
    device : str
        The device on which to put the data.

    Returns
    -------
    z : torch.tensor
        The reparametrized value.
    """
    sigma = torch.exp(0.5*log_var)
    epsilon = torch.rand_like(sigma)
    z = mu + epsilon*sigma
    return z.to(device)