skillfed

torch-complex

A fugacious python class for PyTorch-ComplexTensor

torch-complex v0.4.4 413.7K downloads/30d#6,840 on PyPI
Permissive license DORMANT released

What it is and what it does

torch_complex is a thin wrapper that simulates PyTorch's missing ComplexTensor type by pairing real and imaginary torch.Tensor objects. It implements basic arithmetic (addition, multiplication, division, exponentiation), matrix operations (batch matmul, batch inverse, conjugate), and functional operations (cat, stack, einsum) on complex values. The package also supports GPU operations (cuda/cpu) and autograd backpropagation.

The author explicitly describes this as a temporary workaround for PyTorch's lack of native complex tensor support at the Python level, intending to deprecate it once PyTorch adds the feature. All operations are implemented by composing real-valued PyTorch operations at the Python level, so performance is not optimized. It requires Python 3.6+ and PyTorch 1.0+.

Use it for:

  • Prototyping signal processing or Fourier-domain neural networks when native PyTorch complex support is unavailable.
  • Implementing complex-valued layers in deep learning models that require complex arithmetic.
  • Performing batch matrix operations on complex-valued data (matmul, inverse, einsum).
  • Training models with complex-valued activations or loss functions using autograd.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a Python class wrapping real and imaginary PyTorch tensors to simulate complex tensor operations until native PyTorch support arrives.

No. The package is dormant and explicitly positioned as a temporary workaround. PyTorch has since added native ComplexTensor support, making this wrapper unnecessary for modern projects. Install only if you are locked into an old PyTorch version that lacks complex tensor support and cannot upgrade.

Install

torch-complex on PyPI

pip

pip install torch-complex

uv

uv add torch-complex

poetry

poetry add torch-complex

Installing torch-complex

Before you install

Low install friction with only packaging and numpy as runtime dependencies. Package is dormant (777 days since last release) but marked Production/Stable; use only if you accept no active maintenance.

License in practice

Licensed under Apache Software License (permissive), imposing no significant restrictions on use or modification.

Quickstart

pip install torch_complex

from torch_complex.tensor import ComplexTensor
import numpy as np

real = np.random.randn(3, 10, 10)
imag = np.random.randn(3, 10, 10)
x = ComplexTensor(real, imag)
result = x + x

Requires PyTorch 1.0+ and Python 3.6+; performance is poor because all operations are implemented in Python rather than at the C++ level.

Verify before relying

  • Whether PyTorch has since added native ComplexTensor support that would make this package obsolete.
  • Performance characteristics compared to native PyTorch operations or alternative complex tensor libraries.
  • Compatibility with recent PyTorch versions beyond those listed in classifiers.

Package facts

License not declared (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 2 — packaging, numpy
Maintenance dormant — 777 days since the last release
First released
Downloads 413,667/month — #6,840 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: torch_complex-0.4.4-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: Science/ResearchLicense :: OSI Approved :: Apache Software LicenseOperating System :: POSIX :: LinuxProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: Software Development :: Libraries :: Python Modules

Tags

complex tensor pytorchcomplex number deep learningpytorch complex arithmeticcomplex tensor operationscomplex matrix operations pytorchcomplex valued neural networks
complex-numbersdeprecated-workaround

More Python Modules packages