Module 'torch' has no attribute 'view_as_complex'


I’m using Pytorch 1.5.1.

I’m having a problem using some functions that exist is the documentation, but I got the error 'torch' has no attribute.
For example, the code provided in this pytorch link doesn’t work:

>>> import torch
>>> x=torch.randn(4, 2)
>>> torch.view_as_complex(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'torch' has no attribute 'view_as_complex'

How can I solve this problem?

Thank you in advance!

It appears that this function is only available in torch 1.6. Is there a way to use in an anterior version of Pytorch?


I am afraid this is not something that can easily be backported to older versions of pytorch as they don’t have complex support.
You will have to use 1.6+ I’m afraid

Ok, thanks for your response!