torch-complex is a Python library that provides a custom `ComplexTensor` class and related functional operations for PyTorch. It serves as a temporal solution to enable complex-valued tensor computations in PyTorch, developed primarily because PyTorch historically lacked comprehensive native support for complex tensors. The project's stated goal is to be superseded and eventually 'thrown away' once PyTorch's native complex tensor capabilities are fully mature and performant. The current version is 0.4.4, with a focused release cadence driven by specific needs for complex tensor operations.
pip install torch-complexVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `ComplexTensor` from NumPy arrays, perform basic arithmetic and functional operations (like matrix multiplication), and move the tensor to a CUDA device if available.
Monitor PyTorch's native complex tensor development (docs.pytorch.org/docs/stable/complex_numbers.html) and refactor code to use `torch.complex`, `torch.view_as_complex`, etc., as native support matures and covers all required operations.
For performance-critical applications, benchmark `torch-complex` operations against equivalent native PyTorch complex tensor operations (if available for your use case). If native PyTorch meets your needs, prefer it for speed.
Ensure your PyTorch installation is version 1.0 or newer. `pip install torch>=1.0`.
Carefully verify that you are importing from `torch_complex.tensor` for `ComplexTensor` and `torch_complex.functional` when using this specific library. Avoid mixing imports or assuming compatibility between different complex tensor libraries.
The `ComplexTensor` is a class that needs to be instantiated, not called as a function. Remove the extra parentheses when creating an instance.
Ensure all `ComplexTensor` and `torch.Tensor` objects involved in an operation are on the same device using `.to(device)` or `.cuda()`/`.cpu()` methods. Example: `x = x.cuda()` before performing operations with other tensors on CUDA.
Check the `torch-complex` source or documentation to see if the desired method is implemented. If not, you might need to convert the `ComplexTensor` to its real and imaginary `torch.Tensor` components to use the native method, or consider if native PyTorch complex tensors now support your use case.
No resource links recorded.