Upsurge icon indicating copy to clipboard operation
Upsurge copied to clipboard

Add ComplexMatrix class

Open jfsantos opened this issue 9 years ago • 5 comments

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?

jfsantos avatar Oct 19 '15 20:10 jfsantos

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.

alejandro-isaza avatar Oct 19 '15 21:10 alejandro-isaza

Depends on https://github.com/aleph7/Upsurge/issues/14

alejandro-isaza avatar Oct 19 '15 21:10 alejandro-isaza

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?

jfsantos avatar Oct 19 '15 22:10 jfsantos

Sounds good.

alejandro-isaza avatar Oct 19 '15 23:10 alejandro-isaza

Check out the latest changes I pushed. This should be a lot easier now.

alejandro-isaza avatar Nov 01 '15 00:11 alejandro-isaza