import torch


def reparameterize(mu, logvar):
    """Sample from N(mu, var)

    Parameters
    ----------
    mu : :obj:`torch.Tensor`
        vector of mean parameters
    logvar : :obj:`torch.Tensor`
        vector of log variances; only mean field approximation is currently implemented

    Returns
    -------
    :obj:`torch.Tensor`
        sampled vector of shape (n_frames, n_latents)

    """
    std = torch.exp(logvar)
    eps = torch.randn_like(std)
    return eps.mul(std).add_(mu)