espnet2.gan_codec.shared.decoder.seanet.unpad1d
Less than 1 minute
espnet2.gan_codec.shared.decoder.seanet.unpad1d
espnet2.gan_codec.shared.decoder.seanet.unpad1d(x: Tensor, paddings: Tuple[int, int])
Remove padding from a 1D tensor, handling zero padding properly.
This function is designed to remove the specified padding from a 1D tensor. It is important to ensure that the padding values are non-negative and that their sum does not exceed the length of the tensor.
- Parameters:
- x (torch.Tensor) – The input tensor from which padding will be removed.
- paddings (Tuple *[*int , int ]) – A tuple specifying the left and right padding to remove from the tensor.
- Returns: The tensor with the specified padding removed.
- Return type: torch.Tensor
- Raises:AssertionError – If padding values are negative or their sum exceeds the length of the tensor.
Examples
>>> import torch
>>> x = torch.tensor([1, 2, 3, 4, 5])
>>> unpad1d(x, (1, 1))
tensor([2, 3, 4])
>>> unpad1d(x, (0, 2))
tensor([1, 2, 3])