Upsurge
Upsurge copied to clipboard
Add ComplexMatrix class
I know it's not totally straightforward, but it would be great to have support to matrices of complex numbers. Operations mixing complex and real matrices would be more complicated, but since this is not currently done for Double vs. Float, it is not necessary to implement it.
I also do not know if DSPDoubleComplex
(which was used to implement the Complex
type here) is compatible with the complex number representation in BLAS. If that is the case, this will make things much simpler.
I just started playing with Swift and do not know the best way to implement this, but if you give me some pointers I might be able to come up with something. Would it be better to add them to Matrix.swift
and MatrixArithmetic.swift
or create new files?
I'm planning to replace the current Matrix<Double>
with RealMatrix
, after it should be straight forward to add a ComplexArray
and a ComplexMatrix
. You could start by implementing ComplexArray
if you want to give me a hand. The internal representation should the split (first all reals then all imaginaries) because this is the representation that vDSP_z*
functions require.
Depends on https://github.com/aleph7/Upsurge/issues/14
Sure, I'm working on that already! There's one issue with using vDSP
as opposed to cblas
for complex matrices: vDSP
does not support complex matrices, so we will have to use functions from cblas
in order to make RealMatrix
and ComplexMatrix
have the same functionalities. However, cblas
requires complex numbers stored as a contiguous array, so anytime a matrix operation is called we would have to perform a conversion (which is expensive, since it needs two copies to go from split to contiguous and back again).
My suggestion would be to keep everything BLAS-compatible and only perform the conversion when calling fft
and other functions that are only available in vDSP
. That would make calls to fft
slower, though. What do you think?
Sounds good.
Check out the latest changes I pushed. This should be a lot easier now.