def enumerate_discrete(x, y_dim):
    """
    Generates a 'torch.Tensor' of size batch_size x n_labels of the given label.

    :param x: tensor with batch size to mimic
    :param y_dim: number of total labels
    :return variable
    """

    def batch(batch_size, label):
        labels = (torch.ones(batch_size, 1) * label).type(torch.LongTensor)
        y = torch.zeros((batch_size, y_dim))
        y.scatter_(1, labels, 1)
        return y.type(torch.LongTensor)

    batch_size = x.size(0)
    generated = torch.cat([batch(batch_size, i) for i in range(y_dim)])

    if x.is_cuda:
        generated = generated.to(x.device)

    return Variable(generated.float())

    Generates a 'torch.Tensor' of size batch_size x n_labels of the given label.

    :param x: tensor with batch size to mimic
    :param y_dim: number of total labels
    :return variable
    
adbench/baseline/DeepSAD/src/utils/misc.py