espnet2.enh.layers.complex_utils.to_float
Less than 1 minute
espnet2.enh.layers.complex_utils.to_float
espnet2.enh.layers.complex_utils.to_float(c)
Convert a tensor to a float tensor.
This function converts a complex tensor or a native complex PyTorch tensor to a float tensor. If the input is already a float tensor or does not meet the conditions for conversion, it returns the input unchanged.
- Parameters:
- c (Union *[*torch.Tensor , ComplexTensor ]) – The input tensor which can be
- tensor. (either a ComplexTensor or a PyTorch)
- Returns: A float tensor if the input is a complex tensor, otherwise returns the input tensor unchanged.
- Return type: Union[torch.Tensor, ComplexTensor]
Examples
>>> c_complex = torch.tensor([1+2j, 3+4j], dtype=torch.complex64)
>>> to_float(c_complex)
tensor([1., 2., 3., 4.])
>>> c_float = torch.tensor([1.0, 2.0, 3.0])
>>> to_float(c_float)
tensor([1.0, 2.0, 3.0])