import torch


def kl(q, p):
    """
    Compute the KL divergence between two Bernoulli distribution
    (with parameters q and p)

    Parameters
    ----------
    q: Tensor
        Parameter of the first Bernoulli distribution
    p: Tensor
        Parameter of the second Bernoulli distribution

    Return
    ------
    Tensor
    Value of the KL divergence
    """
    return q * torch.log(q/p) + (1-q) * torch.log((1-q)/(1-p))