[Types] Add complex64 support
Open
@Nucs is already working on this.
Since Feb 18, 2026.
core
documentation-needed
enhancement
missing feature/s
- Dominant language
- C#
- Stars
- 1.5k
- Forks
- 205
- Avg merge
- 7d 7h
- Merged PRs (30d)
- 2
Description
Overview
Add support for complex64 (two float32 components) to NumSharp. Currently NumSharp only supports complex128 (two float64 components).
Problem
NumSharp has Complex (complex128) but not complex64:
>>> import numpy as np
>>> np.array([1+2j, 3+4j], dtype=np.complex64)
array([1.+2.j, 3.+4.j], dtype=complex64)
>>> np.dtype(np.complex64).itemsize
8 # 2 x 4 bytes (float32)
>>> np.dtype(np.complex128).itemsize
16 # 2 x 8 bytes (float64)
Use cases:
- FFT/Signal processing — Many FFT implementations use complex64
- Memory efficiency — 50% savings vs complex128
- Scientific computing — Matches hardware complex types
- NumPy file interop — Some
.npyfiles use complex64
Proposal
Task List
- Create
Complex64struct inUtilities/Complex64.cs:[StructLayout(LayoutKind.Sequential)] public readonly struct Complex64 : IEquatable<Complex64> { public readonly float Real; public readonly float Imaginary; // Arithmetic operators, math functions } - Add
NPTypeCode.Complex64 = 64toNPTypeCode.cs - Add
np.complex64type alias - Update
NPTypeCodeExtensions.GetTypeCode()for Complex64 - Update
InfoOf<T>for Complex64 - Update
UnmanagedStoragetype switches - Update
ArraySliceallocation - Update type promotion tables
- Implement arithmetic operations (+, -, *, /)
- Implement math functions (abs, sqrt, exp, etc.)
- Add tests
C# Type Implementation
[StructLayout(LayoutKind.Sequential)]
public readonly struct Complex64
{
public readonly float Real;
public readonly float Imaginary;
public Complex64(float real, float imaginary) => (Real, Imaginary) = (real, imaginary);
public static Complex64 operator +(Complex64 a, Complex64 b)
=> new(a.Real + b.Real, a.Imaginary + b.Imaginary);
public float Magnitude => MathF.Sqrt(Real * Real + Imaginary * Imaginary);
// ... etc
}
| NumPy | C# | Size | Components |
|---|---|---|---|
| complex64 | Complex64 (custom) | 8 bytes | 2 x float32 |
| complex128 | System.Numerics.Complex | 16 bytes | 2 x float64 |
Implementation Effort
MEDIUM — Requires custom struct with arithmetic and math operations.
Estimated: ~200-300 lines for the struct + type switch updates.
Related
- Part of NumPy 2.x alignment: #529
- Will benefit from DynamicMethod IL emission: #544
- Will benefit from SIMD optimization: #545
References
- NumPy complex64 docs: https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.complex64
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.