espnet2.enh.layers.adapt_layers.into_tuple
Less than 1 minute
espnet2.enh.layers.adapt_layers.into_tuple
espnet2.enh.layers.adapt_layers.into_tuple(x)
Transforms a tensor, list, or tuple into a tuple.
This function checks the type of the input x and converts it into a tuple. If x is a list, it will be converted to a tuple containing the same elements. If x is a tensor, it will be wrapped in a tuple. If x is already a tuple, it will be returned as is. If x is of an unsupported type, a ValueError will be raised.
- Parameters:x – A tensor, list, or tuple to be converted into a tuple.
- Returns: A tuple representation of the input x.
- Return type: tuple
- Raises:ValueError – If x is neither a tensor, list, nor tuple.
Examples
>>> into_tuple([1, 2, 3])
(1, 2, 3)
>>> into_tuple(torch.tensor([1, 2, 3]))
(tensor([1, 2, 3]),)
>>> into_tuple((1, 2, 3))
(1, 2, 3)
>>> into_tuple(5)
ValueError: x should be tensor, list of tuple