[Haskell-cafe] trying to go from FFT type to Vector.Storable

briand at aracnet.com briand at aracnet.com
Thu May 14 04:51:21 UTC 2015


On Tue, 12 May 2015 11:19:48 -0400
Leza Morais Lutonda <leza.ml at fecrd.cujae.edu.cu> wrote:

> On 05/11/2015 11:50 PM, briand at aracnet.com wrote:
> > FFTWReal maps to RealFloat which i found, but i haven't found anything that will take a RealFloat and give me a Double.
> Double` is `RealFloat`, so it is `Fractional`. Every FFTWReal is a 
> `Real` too, so you can use realToFrac to map from FFTWReal to Double:
> 
> fftwRealToDouble :: FFTWReal r => r -> Double
> fftwRealToDouble = realToFrac
> 
> Regards.
> 

Well what I was _really_ trying to do was to get to a Vector of (Complex Double).

Interestingly, the following, where ys is type Vector.Storable (Complex Double),


  ys_array = listArray (0, V.length ys -1) (V.toList ys)
  y = V.fromList $ map (\z -> realPart z :+ imagPart z) (elems (dft ys_array))

worked just fine, but it's not obvious to me that it should have.  Seems like the realPart/imagPart should have failed to work because the argument is not Complex Double it's Complex FFTWReal, so I should have ended up with (Complex FFTWReal) when I really wanted (Complex Double) and fail.

BTW, it seems to me that it would be awfully nice if FFT delivered results as Vectors instead of the Array thingy.  It looked to me like V.Storable is something which is supposed to ease the marshalling to and from the C world.

Would it be a whole lot of work to change the interface to Vector.Storable ?

Among other advantages, it makes interfacing to HMatrix easier.

Thanks,

Brian


More information about the Haskell-Cafe mailing list