-
Notifications
You must be signed in to change notification settings - Fork 650
Support Complex Numbers #3330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Support Complex Numbers #3330
Conversation
- Add Complex as first-class TensorKind alongside Float, Int, Bool - Add ComplexTensorPrimitive and ComplexElem to Backend trait - Add complex tensor type aliases and exports
- Add ComplexTensorPrimitive support to NdArray backend - Implement complex arithmetic and transcendental functions in NdArray backend - Add autodiff backend wrapper for complex tensors - Begin enabling support across backend ecosystem
- Add high-level Tensor<B, D, Complex> API with BasicOps and Numeric traits - Add complex-specific methods: conj(), real(), imag(), magnitude(), phase() - Add creation utilities: from_parts(), from_polar(), zeros(), ones() - Start adding test suite covering operations
- Remove non-existent testgen_complex\!() macro call that was causing compilation errors - Add ComplexTensorOps implementations for all backends (tch, candle, cubecl, fusion, router) - Fix complex tensor assertion logic in CubeCL backend to avoid Float trait requirements - Add missing transcendental functions (exp, log, sin, cos, tan, sqrt, powc) to Complex tensor API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response! Just a general comment:
I think you're on the right track given the separation for complex tensor ops. But since complex numbers are not just another dtype, as they introduce different constraints and rules, I think it would be best to not overload the core Backend
trait.
Instead, it can be implemented as a backend extension (e.g., ComplexBackend
). That way, not all backends have this additional restriction. It can live entirely outside of the core backend and tensor stuff.
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (0.26%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #3330 +/- ##
===========================================
- Coverage 82.66% 45.66% -37.00%
===========================================
Files 995 420 -575
Lines 127626 61936 -65690
===========================================
- Hits 105498 28282 -77216
- Misses 22128 33654 +11526 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Pull Request Template
Checklist
cargo run-checks
command has been executed.Related Issues/PRs
As suggested by #3265
Changes
Core
ComplexTensorOps Trait
Fully Implemented:
Partially Implemented:
Stub Implementations:
Testing
cargo test complex
should pass 62 tests