import torch


def one_hot(
        labels: torch.Tensor,
        n_outputs: int,
    ) -> torch.Tensor:
    """
    Returns a +1/-1 one-hot encoding, needed for adversary.

    Inputs:
        labels: torch.Tensor
            Tensor of labels.

        n_outputs: int
            Number of outputs to consider.

    Outputs:
        one_hot: torch.Tensor
            One-hot encoding of labels.
    """

    batch_size = list(labels.shape)[0]

    one_hot_vector = -torch.ones((batch_size, n_outputs))
    for i, label in enumerate(labels):
        one_hot_vector[i, label] = 1.

    return one_hot_vector