Repository: pytorch
Issue: Complex addition result in NaN when it shouldn't
Labels: triaged,module: complex,module: NaNs and Infs

### 🐛 Describe the bug

When adding two complex numbers where both real components (or both imaginary components) are infinities with equal sign, the imaginary (or real) component of the result will become NaN. There should be no interaction between the different components when adding two complex numbers, and in this case adding two infinities with equal sign shouldn't result in a NaN value regardless. 

As a simple workaround, one can perform addition using torch.view_as_real and then use torch.view_as_complex on the result.

Simple test to reproduce (or [see in this Colab notebook](https://colab.research.google.com/drive/1KhWPscjEtM_SZebapVVDi55H5LkGI_zS?usp=sharing)):
```python3
import torch
x_native = float('inf') + 1j * 0
x_pytorch = torch.tensor(x_native)
x_as_real = torch.view_as_real(x_pytorch)
print('dtype:', x_pytorch.dtype)
assert (x_native + x_native) == x_native, f'{x_native + x_native} != {x_native}'
assert ((x_as_real + x_as_real) == x_as_real).all().item(), f'{x_as_real + x_as_real} != {x_as_real}'
assert ((x_pytorch + x_pytorch) == x_pytorch).all().item(), f'{x_pytorch + x_pytorch} != {x_pytorch}'
```

Result of running the above:
```
dtype: torch.complex64
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
[<ipython-input-11-53bec36d73d6>](https://wgwat1jum1d-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab-20220728-060048-RC00_463807217#) in <module>()
      7 assert (x_native + x_native) == x_native, f'{x_native + x_native} != {x_native}'
      8 assert ((x_as_real + x_as_real) == x_as_real).all().item(), f'{x_as_real + x_as_real} != {x_as_real}'
----> 9 assert ((x_pytorch + x_pytorch) == x_pytorch).all().item(), f'{x_pytorch + x_pytorch} != {x_pytorch}'

AssertionError: (inf+nanj) != (inf+0j)
```

### Versions

Collecting environment information...
PyTorch version: 1.12.0+cu113
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
CMake version: version 3.22.5
Libc version: glibc-2.26

Python version: 3.7.13 (default, Apr 24 2022, 01:04:09)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.188+-x86_64-with-Ubuntu-18.04-bionic
Is CUDA available: False
CUDA runtime version: 11.1.105
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.21.6
[pip3] torch==1.12.0+cu113
[pip3] torchaudio==0.12.0+cu113
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.13.0
[pip3] torchvision==0.13.0+cu113
[conda] Could not collect

cc @ezyang @anjali411 @dylanbespalko @mruberry @Lezcano @nikitaved