Skip to main content

A fugacious python class for PyTorch-ComplexTensor

Project description


PyPI version Python Versions Downloads Build Status codecov

A temporal python class for PyTorch-ComplexTensor

What is this?

A Python class to perform as ComplexTensor in PyTorch: Nothing except for the following,

class ComplexTensor: 
    def __init__(self, ...):
        self.real = torch.Tensor(...)
        self.imag = torch.Tensor(...)


PyTorch is great DNN Python library, except that it doesn't support ComplexTensor in Python level.

I'm looking forward to the completion, but I need ComplexTensor for now. I created this cheap module for the temporal replacement of it. Thus, I'll throw away this project as soon as ComplexTensor is completely supported!




pip install torch_complex

How to use

Basic mathematical operation

import numpy as np
from torch_complex.tensor import ComplexTensor

real = np.random.randn(3, 10, 10)
imag = np.random.randn(3, 10, 10)

x = ComplexTensor(real, imag)

x + x
x * x
x - x
x / x
x ** 1.5
x @ x  # Batch-matmul
x.inverse() # Batch-inverse

All are implemented with combinations of computation of RealTensor in python level, thus the speed is not good enough.


import torch_complex.functional as F[x, x])
F.stack([x, x])
F.matmul(x, x)  # Same as x @ x
F.einsum('bij,bjk,bkl->bil', [x, x, x])


Almost all methods that torch.Tensor has are implemented.

(x + x).sum().backward()

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_complex-0.4.3.tar.gz (10.0 kB view hashes)

Uploaded Source

Built Distribution

torch_complex-0.4.3-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page