import torch


def one_hot(input, shape):
    """One hot encoding; torch does not have it as the current version

    Args:
        input (torch.LongTensor): The tensor to encode. The values should be
            "normalized" to 0 : num_labels

    Returns:
        result (torch.FloatTensor): The encoded tensor

    """
    result = torch.FloatTensor(shape).zero_()
    if input.is_cuda:
        result = result.cuda(device=input.device)
    result.scatter_(1, input, 1)
    return result