import torch


def pad_1d(seq, pad_l):
    """
    The seq is a sequence having shape [T, ..]. Note: The seq contains only one instance. This is not batched.

    :param seq:  Input sequence with shape [T, ...]
    :param pad_l: The required pad_length.
    :return:  Output sequence will have shape [Pad_L, ...]
    """
    time = seq.size(0)
    if time >= pad_l:
        return seq[:pad_l, ]  # Truncate the length if the length is bigger than required padded_length.
    else:
        pad_seq = seq.new(pad_l - time, *seq.size()[1:]).zero_()  # Requires_grad is False
        return torch.cat([seq, pad_seq], dim=0)