A fugacious python class for PyTorch-ComplexTensor
Project description
pytorch_complex
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file torch_complex-0.1.2.tar.gz
.
File metadata
- Download URL: torch_complex-0.1.2.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b61aec291444945367d3ec2fe9729c1dc6c45607fcf743887046b9810ac4d7f |
|
MD5 | 44b4678136dbeb1a78173e0846c2f1d0 |
|
BLAKE2b-256 | fdd0f480348474df966ad5f8cebeddf4fc40c7bd94e624076e7682a423eb02d3 |
File details
Details for the file torch_complex-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: torch_complex-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce070627fca13d1ae360aaf9f82a32fb354b710c904cd05fda996d788df495e5 |
|
MD5 | 3d5040080dabee253e99e3619b0b16c8 |
|
BLAKE2b-256 | 8f48dd35ecafd2cf3d69533f4eb42aad602f74dde0e004a3409c56c1cbebfab1 |