from typing import List
import torch


def encode_ordinal(labels: List[int], num_labels: int) -> torch.Tensor:
    """
    Given a list of class labels, transforms them into an ordinal tensor.

    :param labels: list of class labels to transform.
    :param num_labels: number of class labels. It is not inferred directly from parameter `labels` because this function
    could be called in batches.
    :return: an ordinal tensor from the labels passed.
    """
    return torch.tensor(
        [
            ([1] * label + [0] * (num_labels - label - 1))
            for label in labels
        ]
    ).float()