Repository: pytorch
Issue: Problems implementing complex support for acosh, asinh, tanh
Labels: triaged,module: complex

## 🐛 Bug

There is an unexpected behavior (on Windows and MacOS) while trying to implement complex support for `acosh, asinh, atanh` Unary Ops. (Please see: https://github.com/pytorch/pytorch/pull/38388)

For Windows VS2019, CUDA 10.1:

```
Input Tensor:  tensor([(0.0000+0.0000j),  (1.2300+infj), (-0.0600+nanj),  (inf+2.9800j),
            (inf+infj),     (inf+nanj),  (nan+0.0000j),  (nan-0.0600j),
            (nan+infj),     (nan+nanj)])
asinh output:  tensor([(0.0000+0.0000j),  (inf+1.5708j),     (nan+nanj),  (inf+0.0000j),
         (inf+0.7854j),     (nan+nanj),     (nan+nanj),     (nan+nanj),
            (nan+nanj),     (nan+nanj)])
```

For Windows VS2019 CPU:

```
Input Tensor:  tensor([(0.0000+0.0000j),  (1.2300+infj), (-0.0600+nanj),  (inf+2.9800j),
            (inf+infj),     (inf+nanj),  (nan+0.0000j),  (nan-0.0600j),
            (nan+infj),     (nan+nanj)])
asinh output:  tensor([(0.0000+0.0000j),  (inf+1.5708j),     (nan+nanj),  (inf+0.0000j),
         (inf+0.7854j),     (nan+nanj),     (nan+nanj),     (nan+nanj),
            (nan+nanj),     (nan+nanj)])
```

While on MacOS, the call `torch.asinh()` throws a `RuntimeError`:

```
May 27 11:55:42   test_asinh_domain_complex_cpu_complex64 (__main__.TestTorchDeviceTypeCPU) ... Sample:  tensor([(0.0000+0.0000j),  (1.2300+infj), (-0.0600+nanj),  (inf+2.9800j),
May 27 11:55:42             (inf+infj),     (inf+nanj),  (nan+0.0000j),  (nan-0.0600j),
May 27 11:55:42             (nan+infj),     (nan+nanj)])
May 27 11:55:42 Traceback (most recent call last):
May 27 11:55:42   File "test/run_test.py", line 689, in <module>
May 27 11:55:42     main()
May 27 11:55:42   File "test/run_test.py", line 682, in main
May 27 11:55:42     raise RuntimeError(message)
May 27 11:55:42 RuntimeError: test_torch failed! Received signal: SIGILL
```

These logs are from the test cases that were written to test domains for these trigonometric functions. Please see the removed tests here which were used: https://github.com/pytorch/pytorch/pull/38388/commits/ccfe7c14423a5bede6c976aea520ac10833a67e7.

## To Reproduce

Steps to reproduce the behavior:

1. Use the following git commands:
```
git remote add test https://github.com/krshrimali/pytorch.git
git fetch test
git checkout test/complex-support-acosh-like
```
2. Build PyTorch using the branch `test/complex-support-acosh-like`.
3. Run tests: `python test/test_torch.py`. Please note that the tests fail on VS2019 (CPU and CUDA-10.1) and throw `RuntimeError` on MacOS.

**Note:** the stack traces/logs have been provided in the bug description.

## Expected behavior

Here is how Linux systems return output for `asinh` on the input tensors mentioned in the bug description.

```
tensor([(0.0000+0.0000j),  (inf+1.5708j),     (nan+nanj),  (inf+0.0000j),
         (inf+0.7854j),     (inf+nanj),  (nan+0.0000j),     (nan+nanj),
            (inf+nanj),     (nan+nanj)])
```

Here is a concise table on how the behavior diverges:

```
Input       |  Windows (CPU & CUDA) |   Linux (CPU & CUDA) and NumPy (Linux & Windows)
(inf, nan)  | (nan, nan)            |   (inf, nan)          
(nan, 0.)   | (nan, nan)            |   (nan, 0.)           
(nan, inf)  | (nan, nan)            |   (inf, nan)          
```

**Note:** Windows diverges similarly on CPU and CUDA-10.1.

## Additional context

If you are keen on how the results are compared, please see: https://github.com/pytorch/pytorch/pull/38388#issuecomment-630158866.

cc: @mruberry, @anjali411 

cc @ezyang @anjali411 @dylanbespalko