Can complex data type of NumPy be used in PyTorch?

I am a beginner in PyTorch and I’m working on training a cnn in the fourier domain completely to exploit advantages of the fourier domain, like the convolution theorem etc. Though PyTorch has an rfft function to get fourier representation of real images and weights etc., after taking the rfft, I would need to take the dot product of the complex tensor outputs of rfft. Similarly many other operations on complex tensors might be needed in the cnn’s functioning.
Given the lack of complex data type in PyTorch currently, would it be better to shift to Tensorflow which does support a complex data type? Also, what are the advantages and drawbacks of tensorflow over PyTorch?

Or can the complex data type supported by NumPy be used in PyTorch?

1 Like

Refer to this discussion on integrating complex numbers in pytorch link.

As far as TF and torch are concerned. You should prefer TF when you want to code in Swift, Go, JavaScript, Java and some others. You can also use TF when you want to make mobile applications (but pytorch provides it through onnux). Although, it is highly recommended to deploy model on cloud and make the mobile interact with the cloud.

Apart from these there is not much difference in TF and torch, except the code base. TF is lot more cluttered in the sense way too many deprecations and too complex to learn (not true for TF 2.0).
At the end I think it comes to your preference I think, fastai a very useful library is build on PyTorch. Also, you can use tensorboard on PyTorch also.

In case you want to work on cloud TPUs your only option as of now is TF (PyTorch support is coming soon).

2 Likes

@Kushaj Hi, thank you for your valuable solution. Is Tensorflow support complex computation completely? for example, complex valued convolution, deconvolution, gradient computation, etc…
It is of significant importance to me.
Hope for your reply.

Best regards,
Purespring.

Sorry man, I don’t have much knowledge about tensorflow.

I found this link. See the last example of the page, it shows creation of a network. Also, I think as tensorflow supports complex dtypes, can you try changing the dtypes to your model inputs.