espnet2.asr.state_spaces.pool.upsample
Less than 1 minute
espnet2.asr.state_spaces.pool.upsample
espnet2.asr.state_spaces.pool.upsample(x, stride=1, expand=1, transposed=False)
Upsample a tensor by applying stride and expansion.
This function increases the dimensions of the input tensor x by repeating its elements based on the specified stride and expand parameters. The function can also handle transposed operations.
- Parameters:
- x (torch.Tensor) – The input tensor to upsample. It should be a 3D or higher-dimensional tensor.
- stride (int , optional) – The factor by which to increase the sequence length. Default is 1.
- expand (int , optional) – The factor by which to increase the feature dimension. Default is 1.
- transposed (bool , optional) – If True, the operation will be treated as a transposed operation. Default is False.
- Returns: The upsampled tensor.
- Return type: torch.Tensor
Examples
>>> import torch
>>> x = torch.tensor([[1, 2], [3, 4]])
>>> upsample(x, stride=2, expand=2)
tensor([[1, 1, 2, 2],
[3, 3, 4, 4]])
>>> upsample(x, stride=1, expand=3)
tensor([[1, 2, 2, 2],
[3, 4, 4, 4]])
>>> upsample(x, stride=2, expand=1, transposed=True)
tensor([[1, 2],
[1, 2],
[3, 4],
[3, 4]])
- Raises:AssertionError – If the input tensor is None.