A fugacious python class for PyTorch-ComplexTensor
Project Links
Meta
Author: Naoyuki Kamo
Classifiers
Programming Language
- Python
- Python :: 3
- Python :: 3.6
- Python :: 3.7
- Python :: 3.8
Development Status
- 5 - Production/Stable
Intended Audience
- Science/Research
Operating System
- POSIX :: Linux
License
- OSI Approved :: Apache Software License
Topic
- Software Development :: Libraries :: Python Modules
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()
Jun 28, 2024
0.4.4
Feb 25, 2022
0.4.3
Feb 21, 2022
0.4.0
Mar 05, 2021
0.2.1
Sep 15, 2020
0.2.0
Aug 12, 2020
0.1.2
Jul 24, 2020
0.1.1
Jul 16, 2020
0.1.0
May 02, 2020
0.0.3
May 02, 2020
0.0.2