Repository: pytorch
Issue: `torch.nanmedian` return a negative value when input is empty 
Labels: module: error checking,triaged

### 🐛 Describe the bug


In pytorch1.12.0, 1.13.0, 1.13.1, and some earlier versions, `torch.nanmedian` will return a negative number as output for empty input, which obviously does not meet the description of this API in the [docs](https://pytorch.org/docs/stable/generated/torch.nanmedian.html):

```
Returns the median of the values in input, ignoring NaN values.
```

In addition, when using `dtype=torch.int32`, it will return `-2147483648`, which seems to be the smallest negative number under int32.
When dtype is int64, it will return `-9223372036854775808`, which is also the smallest negative number under int64.
The above behaviors also happen on `torch.median`.
I'm not sure if that means some kind of overflow happened in the calculation.

I think the root cause of this issue should be related to [#71636](https://github.com/pytorch/pytorch/issues/71636).

### To Reproduce
```python
import torch

torch.manual_seed(0)
input = torch.randint(-1,1,[0], dtype=torch.int32)
# input = torch.randint(-1,1,[0], dtype=torch.int64)

def test():
    tmp_result=torch.nanmedian(input).detach().numpy()
    # tmp_result=torch.median(input).detach().numpy()
    return tmp_result
result=test()

print(result)#-2147483648 #-9223372036854775808
print(input.detach().numpy())#[]
```

### Expected behavior

Both `median` and `nanomedian` API calculate the median of the input. When the input is empty, an empty tensor should be returned instead of a negative number.
Will this unexpected output be moved in PT2.0?


### Versions


<details>
  <summary>pytorch 1.12.0</summary>
  <pre><code>
  [pip3] numpy==1.21.5
  [pip3] torch==1.12.0
  [pip3] torchelastic==0.2.0
  [pip3] torchtext==0.13.0
  [pip3] torchvision==0.13.0
  [conda] blas                      1.0                         mkl  
  [conda] cudatoolkit               11.3.1               ha36c431_9    nvidia
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.4.0           h06a4308_640  
  [conda] mkl-service               2.4.0            py37h7f8727e_0  
  [conda] mkl_fft                   1.3.1            py37hd3c417c_0  
  [conda] mkl_random                1.2.2            py37h51133e4_0  
  [conda] numpy                     1.21.5           py37he7a7128_2  
  [conda] numpy-base                1.21.5           py37hf524024_2  
  [conda] pytorch                   1.12.0          py3.7_cuda11.3_cudnn8.3.2_0    pytorch
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torchelastic              0.2.0                    pypi_0    pypi
  [conda] torchtext                 0.13.0                     py37    pytorch
  [conda] torchvision               0.13.0               py37_cu113    pytorch</code></pre>
</details>

<details>
  <summary>pytorch 1.13.0</summary>
  <pre><code>
  [pip3] numpy==1.22.3
  [pip3] torch==1.13.0
  [pip3] torchtext==0.14.0
  [pip3] torchvision==0.14.0
  [conda] blas                      1.0                         mkl  
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.4.0           h06a4308_640  
  [conda] mkl-service               2.4.0            py39h7f8727e_0  
  [conda] mkl_fft                   1.3.1            py39hd3c417c_0  
  [conda] mkl_random                1.2.2            py39h51133e4_0  
  [conda] numpy                     1.22.3           py39he7a7128_0  
  [conda] numpy-base                1.22.3           py39hf524024_0  
  [conda] pytorch                   1.13.0          py3.9_cuda11.6_cudnn8.3.2_0    pytorch
  [conda] pytorch-cuda              11.6                 h867d48c_0    pytorch
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torchtext                 0.14.0                     py39    pytorch
  [conda] torchvision               0.14.0               py39_cu116    pytorch</code></pre>
</details>

<details>
  <summary>pytorch 1.13.1</summary>
  <pre><code>
  [pip3] numpy==1.22.3
  [pip3] torch==1.13.1
  [pip3] torchelastic==0.2.2
  [pip3] torchtext==0.14.1
  [pip3] torchvision==0.14.1
  [conda] blas                      1.0                         mkl  
  [conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
  [conda] mkl                       2021.4.0           h06a4308_640  
  [conda] mkl-service               2.4.0           py310h7f8727e_0  
  [conda] mkl_fft                   1.3.1           py310hd6ae3a3_0  
  [conda] mkl_random                1.2.2           py310h00e6091_0  
  [conda] numpy                     1.22.3          py310hfa59a62_0  
  [conda] numpy-base                1.22.3          py310h9585f30_0  
  [conda] pytorch                   1.13.1          py3.10_cuda11.6_cudnn8.3.2_0    pytorch
  [conda] pytorch-cuda              11.6                 h867d48c_1    pytorch
  [conda] pytorch-mutex             1.0                        cuda    pytorch
  [conda] torchelastic              0.2.2                    pypi_0    pypi
  [conda] torchtext                 0.14.1                    py310    pytorch
  [conda] torchvision               0.14.1              py310_cu116    pytorch</code></pre>
</details>


cc @malfet