Skip to content

PyTorch complex support has NumPy incompatible functions #35494

@colesbury

Description

@colesbury

🐛 Bug

The new complex number support introduces APIs that are incompatible with NumPy. Some of these functions existed in PyTorch 1.4, but they were practically useless and undocumented.

I'm concerned that this is going to make our life difficult going forward as we try to balance backwards compatibility with NumPy support. In general, we shouldn't be releasing new APIs that are incompatible with NumPy without good reasons.

Here are some examples I found with a few minutes of testing:

Tensor.real() is a function but ndarray.real is a property

>>> torch.randn(10, dtype=torch.complex64).real
<function Tensor.real>
>>> torch.randn(10, dtype=torch.complex64).numpy().real
array([ 0.1262403 , -0.40131333,  0.52708787, -0.10931669,  1.5780342 ,
       -0.17833038,  0.4660201 , -0.35434407,  0.73025763,  0.44405413],
      dtype=float32)

torch.real() (and Tensor.real()) returns a complex-type Tensor, but np.real (and ndarray.real) return floating-point type arrays:

>>> x = torch.randn(10, dtype=torch.complex64)
>>> torch.real(x).dtype
torch.complex64
>>> np.real(x.numpy()).dtype
dtype('float32')

cc @ezyang @gchanan @zou3519 @anjali411 @dylanbespalko

Metadata

Metadata

Labels

high prioritymodule: complexRelated to complex number support in PyTorchmodule: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis 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