Repository: pytorch
Issue: boolean mask + ellipsis lead to incorrect indexing
Labels: triaged,module: numpy,module: advanced indexing,Stale

### 🐛 Describe the bug

Indexing pytorch tensors behaves not the same as indexing numpy arrays.
MWE that raises an IndexError:
```python
print('numpy arrays:')
import numpy
t = numpy.arange(2).reshape(1,1,2)
mask = numpy.array([[True]])
print(t[mask][...,0])
print(t[mask,...,0])
print('pytorch tensors:')
import torch
t = torch.arange(2).view(1,1,2)
mask = torch.BoolTensor([[True]])
print(t[mask][...,0])
print(t[mask,...,0]) # throws IndexError
```
outputs
```
numpy arrays:
[0]
[0]
pytorch tensors:
tensor([0])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-19-96582348cb03> in <module>
     10 mask = torch.BoolTensor([[True]])
     11 print(t[mask][...,0])
---> 12 print(t[mask,...,0]) # throws IndexError

IndexError: The shape of the mask [1, 1] at index 1 does not match the shape of the indexed tensor [1, 2] at index 1
```
Another example that fails silently:
```python
print('pytorch tensors:')
import torch
t = torch.arange(4).view(1,2,2)
mask = torch.BoolTensor([[True, True]])
print(t[mask][...,0], t[mask,...,0])
print('numpy arrays:')
import numpy
t = numpy.arange(4).reshape(1,2,2)
mask = numpy.array([[True, True]])
print(t[mask][...,0], t[mask,...,0])
```
outputs
```
pytorch tensors:
tensor([0, 2]) tensor([0, 1])
numpy arrays:
[0 2] [0 2]
```

### Versions

Collecting environment information...
PyTorch version: 1.10.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.3 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.16.3
Libc version: glibc-2.31

Python version: 3.9.7 (default, Sep 16 2021, 13:09:58)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.11.0-43-generic-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.2
[pip3] torch==1.10.1
[pip3] torchaudio==0.10.1
[pip3] torchvision==0.11.2
[conda] blas                      1.0                         mkl  
[conda] cpuonly                   2.0                           0    pytorch
[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.21.2           py39h20f2e39_0  
[conda] numpy-base                1.21.2           py39h79a1101_0  
[conda] pytorch                   1.10.1              py3.9_cpu_0    pytorch
[conda] pytorch-mutex             1.0                         cpu    pytorch
[conda] torchaudio                0.10.1                 py39_cpu  [cpuonly]  pytorch
[conda] torchvision               0.11.2                 py39_cpu  [cpuonly]  pytorch

cc @mruberry @rgommers