Skip to main content

A fugacious python class for PyTorch-ComplexTensor

Project description

pytorch_complex

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(...)

Why?

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

https://github.com/pytorch/pytorch/issues/755

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!

Requirements

Python>=3.6
PyTorch>=1.0

Install

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.numpy()

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

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

Functional

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

For DNN

Almost all methods that torch.Tensor has are implemented.

x.cuda()
x.cpu()
(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.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

torch_complex-0.4.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file torch_complex-0.4.0.tar.gz.

File metadata

  • Download URL: torch_complex-0.4.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for torch_complex-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a0461cff253e18af597cbb206ae53232cff6ca17416da9af42d45c3d751421e7
MD5 08b5e94cda597abd56408fc36bb6a7a8
BLAKE2b-256 25d008a62f6be679e0092431e0dfc6ba139defb5bbdd8cd6a6623a01c2896183

See more details on using hashes here.

File details

Details for the file torch_complex-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: torch_complex-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for torch_complex-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be6d433fdc650b8cad7541cd84748d2fa87f7ff12a5ab48cfc22e34a6e64e726
MD5 943348b1682bb50c151b766fb192c371
BLAKE2b-256 a802e71a9a411410deb452b8b23735ff1a1f15432c192628c2a4ed7c460c0372

See more details on using hashes here.

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