import math
import torch


def log_normal(x, mean, logvar):
    """Log-pdf for factorized Normal distributions."""
    return -0.5 * ((math.log(2 * math.pi) + logvar).sum(1) + ((x - mean).pow(2) / torch.exp(logvar)).sum(1))