Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operating on boolean torch tensor and numpy array casts to unit8 #77962

Open
befelix opened this issue May 20, 2022 · 1 comment
Open

Operating on boolean torch tensor and numpy array casts to unit8 #77962

befelix opened this issue May 20, 2022 · 1 comment
Labels
module: boolean tensor module: numpy Related to numpy support, and also numpy compatibility of our operators module: type promotion Related to semantics of type promotion triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@befelix
Copy link

befelix commented May 20, 2022

馃悰 Describe the bug

Sometimes one accidentally mixes torch and numpy arrays in the code. When this happens, numpy generally raises TypeError, while torch usually handles these situations gracefully. However, for boolean operations torch recasts to uint8, which leads to unexpected error messages down the road

import numpy as np
import torch

x = torch.tensor(True) | np.array(True)
print(x)

outputs tensor(1, dtype=torch.uint8) with dtype unit8. Expected output would be tensor(True) with boolean dtype.

Versions

PyTorch version: 1.11.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.4 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.8.12 (default, Oct 12 2021, 13:49:34) [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.13.0-41-generic-x86_64-with-glibc2.17
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
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy==0.941
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.22.3
[pip3] torch==1.11.0
[conda] numpy 1.22.3 pypi_0 pypi
[conda] torch 1.11.0 pypi_0 pypi

cc @mruberry @rgommers @nairbv

@gchanan
Copy link
Contributor

gchanan commented May 20, 2022

I was able to reproduce

@mrshenli mrshenli added module: type promotion Related to semantics of type promotion module: boolean tensor module: numpy Related to numpy support, and also numpy compatibility of our operators triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels May 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: boolean tensor module: numpy Related to numpy support, and also numpy compatibility of our operators module: type promotion Related to semantics of type promotion triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants