import torch


def adversarial_loss(prob, label):
    """Compute adversarial losses in GAN networks.

    Note:
        As a reminder, prob is either D(x) or D(G(z)), and label is
        either 0 (fake) or 1 (real). With BCELoss(), this means that

        - l(D(x), 1) = -log(D(x)): "Real" discriminator loss
        - l(D(x), 0) = -log(1 - D(x)): "Fake" discriminator loss
        - l(D(G(z)), 1) = -log(D(G(z))): Non-saturating generator loss

    Args:
        prob: Discriminator output, in interval [0, 1]
        label: Data label, with fake = 0 and real = 1
    """
    return torch.nn.BCEWithLogitsLoss()(prob, label)