Repository: pytorch
Issue: [JIT] bitwise NOT does not handle tensor shapes correctly under JIT
Labels: oncall: jit,triaged

## 🐛 Bug

It seems that `~` operator does not generalize to different tensor shapes under JIT. Refer to https://github.com/pyro-ppl/pyro/issues/1784. 

## To Reproduce
```python
>>> def f(x): return ~x

>>> jit_fn = torch.jit.trace(f, (torch.tensor([0], dtype=torch.uint8),))
>>> jit_fn(torch.tensor([0], dtype=torch.uint8))
tensor([1], dtype=torch.uint8)

>>> jit_fn(torch.tensor([0, 0], dtype=torch.uint8))
RuntimeError:
output with shape [1] doesn't match the broadcast shape [2] (compute_shape at /Users/soumith/mc3build/conda-bld/pytorch_1549593514549/work/aten/src/ATen/native/TensorIterator.cpp:534)
frame #0: c10::Error::Error(c10::SourceLocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 64 (0x11341bff0 in libc10.dylib)
frame #1: at::TensorIterator::compute_shape() + 1568 (0x11c1078f0 in libcaffe2.dylib)
frame #2: at::TensorIterator::Builder::build() + 39 (0x11c106907 in libcaffe2.dylib)
frame #3: at::TensorIterator::binary_op(at::Tensor&, at::Tensor const&, at::Tensor const&) + 434 (0x11c1064b2 in libcaffe2.dylib)
frame #4: at::native::sub_out(at::Tensor&, at::Tensor const&, at::Tensor const&, c10::Scalar) + 718 (0x11bfad4ae in libcaffe2.dylib)
frame #5: at::native::sub_(at::Tensor&, at::Tensor const&, c10::Scalar) + 35 (0x11bfadc73 in libcaffe2.dylib)
frame #6: at::TypeDefault::sub_(at::Tensor&, at::Tensor const&, c10::Scalar) const + 232 (0x11c3878e8 in libcaffe2.dylib)
frame #7: torch::autograd::VariableType::sub_(at::Tensor&, at::Tensor const&, c10::Scalar) const + 1254 (0x11f4d44d6 in libtorch.1.dylib)
frame #8: std::__1::__function::__func<torch::jit::(anonymous namespace)::$_492, std::__1::allocator<torch::jit::(anonymous namespace)::$_492>, int (std::__1::vector<c10::IValue, std::__1::allocator<c10::IValue> >&)>::operator()(std::__1::vector<c10::IValue, std::__1::allocator<c10::IValue> >&) + 163 (0x11fa89423 in libtorch.1.dylib)
frame #9: torch::jit::InterpreterStateImpl::runImpl(std::__1::vector<c10::IValue, std::__1::allocator<c10::IValue> >&) + 455 (0x11faf86f7 in libtorch.1.dylib)
...
```
## Expected behavior

Function gives correct results with tensors of arbitrary shape.

## Environment

```
  $ python collect_env.py
Collecting environment information...
PyTorch version: 1.0.1.post2
Is debug build: No
CUDA used to build PyTorch: None

OS: Mac OSX 10.14.3
GCC version: Could not collect
CMake version: Could not collect

Python version: 3.6
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip3] numpy==1.15.4
[pip3] torch==1.0.1.post2
[pip3] torchfile==0.1.0
[pip3] torchvision==0.2.1
[conda] blas                      1.0                         mkl
[conda] mkl                       2019.1                      144
[conda] mkl_fft                   1.0.10           py36h5e564d8_0
[conda] mkl_random                1.0.2            py36h27c97d8_0
[conda] pytorch                   1.0.1                   py3.6_2    pytorch
[conda] torchfile                 0.1.0                     <pip>
[conda] torchvision               0.2.1                      py_2    pytorch
```

cc. @apaszke 

cc @suo