Compute complex-valued multiplication. Supports Ndim inputs with last dim equal to 2 (real/imaginary channels) Args: x: Input tensor with 2 channels in the last dimension representing real and imaginary parts. y: Input tensor with 2 channels in the last dimension representi
(x: Tensor, y: Tensor)
| 136 | |
| 137 | |
| 138 | def complex_mul_t(x: Tensor, y: Tensor) -> Tensor: |
| 139 | """ |
| 140 | Compute complex-valued multiplication. Supports Ndim inputs with last dim equal to 2 (real/imaginary channels) |
| 141 | |
| 142 | Args: |
| 143 | x: Input tensor with 2 channels in the last dimension representing real and imaginary parts. |
| 144 | y: Input tensor with 2 channels in the last dimension representing real and imaginary parts. |
| 145 | |
| 146 | Returns: |
| 147 | Complex multiplication of x and y |
| 148 | """ |
| 149 | if x.shape[-1] != 2 or y.shape[-1] != 2: |
| 150 | raise ValueError(f"last dim must be 2, but x.shape[-1] is {x.shape[-1]} and y.shape[-1] is {y.shape[-1]}.") |
| 151 | |
| 152 | real_part = x[..., 0] * y[..., 0] - x[..., 1] * y[..., 1] |
| 153 | imag_part = x[..., 0] * y[..., 1] + x[..., 1] * y[..., 0] |
| 154 | |
| 155 | return torch.stack((real_part, imag_part), dim=-1) |
| 156 | |
| 157 | |
| 158 | def complex_mul(x: NdarrayOrTensor, y: NdarrayOrTensor) -> NdarrayOrTensor: |
no outgoing calls
no test coverage detected
searching dependent graphs…