import torch


def CrossEnt(p_dist, q_dist, reduce=None):
    """
        xent = - \sum_i p(i) \log q(i)
    """
    ent = - torch.mul(p_dist, torch.log(q_dist))
    ent = torch.sum(ent, -1)
    ent = ent if reduce is None else reduce(ent)
    return ent