import torch


def collate_signs(values, eos_idx=None, left_pad=False):
    """Convert a list of 2d tensors into a padded 3d tensor.

    input is a list of k_i * 1024 features.
    We need to find the max K and pad all others to have the same length.
    Return NUM_SAMPLES * K * 1024 tensor.
    """

    # v is a k x 1024 vectors.
    lens = [len(v) for v in values]
    max_len = max(lens)
    min_len = min(lens)

    assert min_len > 0

    res = torch.zeros(size=(len(values), max_len, values[0].shape[1]))

    for i, v in enumerate(values):
        if left_pad:
            res[i][max_len - len(v):] = v
        else:
            res[i][:len(v)] = v

    return res