GithubHelp home page GithubHelp logo

pytorch_complex's Introduction

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.

pytorch/pytorch#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()

pytorch_complex's People

Contributors

kamo-naoyuki avatar boeddeker avatar deepsourcebot avatar emrys365 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.