Skip to content

For the same complex dtype and same value, comparing a PyTorch tensor with a NumPy array results in False #43579

@xuhdev

Description

@xuhdev

🐛 Bug

For the same complex dtype and same value, comparing a PyTorch tensor with a NumPy array results in False. Note [5] and [10] in the example below. The issue is gone if complex64 is replaced with float32 (i.e., both [5] and [10] output True for float32).

In [1]: import numpy as np

In [2]: import torch

In [3]: a=torch.tensor([1, 2], dtype=torch.complex64)

In [4]: c=np.array([1, 2], dtype=np.complex64)

In [5]: a[0] == c[0]
Out[5]: False

In [6]: a[0].item() == c[0]
Out[6]: True

In [7]: a[0] == c[0].item()
Out[7]: tensor(True)

In [8]: a[0].item() == c[0].item()
Out[8]: True

In [9]: a=torch.from_numpy(c)

In [10]: a[0] == c[0]
Out[10]: False

Environment

PyTorch version: 1.7.0.dev20200819+cu101
Is debug build: False
CUDA used to build PyTorch: 10.1

OS: Debian GNU/Linux 10 (buster) (x86_64)
GCC version: (Debian 8.3.0-6) 8.3.0
Clang version: 7.0.1-8 (tags/RELEASE_701/final)
CMake version: version 3.16.3

Python version: 3.7 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: 10.1.243
GPU models and configuration: GPU 0: Quadro P400
Nvidia driver version: 440.100
cuDNN version: Could not collect

Versions of relevant libraries:
[pip3] numpy==1.19.1
[pip3] torch==1.7.0.dev20200819+cu101
[conda] Could not collect

cc @ezyang @anjali411 @dylanbespalko

Metadata

Metadata

Assignees

Labels

module: complexRelated to complex number support in PyTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions