espnet2.enh.layers.dcunet.torch_complex_from_reim
Less than 1 minute
espnet2.enh.layers.dcunet.torch_complex_from_reim
espnet2.enh.layers.dcunet.torch_complex_from_reim(re, im)
Create a complex tensor from real and imaginary parts.
This function takes two tensors representing the real and imaginary components of a complex number and combines them into a single complex tensor using PyTorch’s built-in complex number support.
- Parameters:
- re (Tensor) – A tensor representing the real part of the complex number.
- im (Tensor) – A tensor representing the imaginary part of the complex number.
- Returns: A complex tensor formed by combining the real and imaginary parts.
- Return type: Tensor
Examples
>>> re = torch.tensor([1.0, 2.0])
>>> im = torch.tensor([3.0, 4.0])
>>> complex_tensor = torch_complex_from_reim(re, im)
>>> print(complex_tensor)
tensor([1. + 3.j, 2. + 4.j])
NOTE
The input tensors must have the same shape. If they do not, a runtime error will occur.
- Raises:ValueError – If the input tensors do not have the same shape.