import torch


def kl_kumaraswamy_kumaraswamy(p, q, n_samples=1, exact_entropy=True):
    """    
    KL(p||q) = -H(p) + H(q|p)
     where the entropy can be computed in closed form or estimated
     the cross entropy is always estimated
    """
    x = p.rsample(sample_shape=torch.Size([n_samples]))
    if exact_entropy:
        p_entropy = p.entropy()
    else:
        p_entropy = - p.log_prob(x).mean(0)
    cross_entropy = - q.log_prob(x).mean(0)
    return - p_entropy + cross_entropy