1j * cos( theta), error?

Hey guys!

So I am trying to create the following rather simple function:

# Make sure to use pytorch version 1.6.0 as I am using type torch.cfloat
from torch import cos, tensor
def func():
	return tensor([[1.0, - 1j*cos(tensor(1.0))],[1.0,0.0]], dtype=torch.cfloat)
print(func())

I get an error stating that: “RuntimeError: value cannot be converted to type double without overflow: (0,-0.848705)”.
I have played around with different options for a while and it seems like this error is induced by the fact that I am doing 1j*cos(tensor(1.0)). Can someone explain what is going wrong when I multiply this cosine of tensor(1.0) by this complex amplitude?
I

With a slightly newer PyTorch (self-compiled from the dev branch, you could also use a nightly):

>>> torch.__version__
'1.7.0a0+98ad5ff'

>>> torch.tensor([[1.0, - 1j*torch.cos(torch.tensor(1.0))],[1.0,0.0]], dtype=torch.cfloat)
tensor([[1.+0.0000j, 0.-0.5403j],
        [1.+0.0000j, 0.+0.0000j]])

so maybe something got fixed (complex support is rather new and there probably are rough edges).

Best regards

Thomas

Thanks for the tip! I will try this with the newer version of torch.