Vector (or List) to CArray?

Hello, I'm trying to use the fftw binding, and its functions operate on CArrays of Complex. My data is coming from hsndfile, so it starts out as a Vector of Double. How do I convert this data to CArray? The API functions in the CArray module don't seem to indicate how. Thanks.

On 19.01.2012 22:15, Dominic Espinosa wrote:
Hello,
I'm trying to use the fftw binding, and its functions operate on CArrays of Complex. My data is coming from hsndfile, so it starts out as a Vector of Double. How do I convert this data to CArray? The API functions in the CArray module don't seem to indicate how.
I think only way is to go though lists. CArray and vector package use different primitives.
listArray (0, V.length v) $ V.toList v

On Thu, Jan 19, 2012 at 1:15 PM, Dominic Espinosa
Hello,
I'm trying to use the fftw binding, and its functions operate on CArrays of Complex. My data is coming from hsndfile, so it starts out as a Vector of Double. How do I convert this data to CArray? The API functions in the CArray module don't seem to indicate how.
Thanks.
I've not tried this, but I would expect to be able to use http://hackage.haskell.org/package/hsndfile-vector-0.4.0, and then use the ForeignPtr that lives inside the Vector the to build a CArray. Anthony

On Thu, Jan 19, 2012 at 10:15 AM, Dominic Espinosa
Hello,
I'm trying to use the fftw binding, and its functions operate on CArrays of Complex. My data is coming from hsndfile, so it starts out as a Vector of Double. How do I convert this data to CArray? The API functions in the CArray module don't seem to indicate how.
My first recommendation would be to use the vector-fftw package, which uses Vectors instead of CArrays. But as the author of that package I may be a bit biased. Alternately, converting between CArrays and Vectors isn't too hard if you want to do it directly. For example, you can convert from Vector to CArray by using Data.Vector.Storable.unsafeToForeignPtr and Data.Array.CArray.Base.unsafeForeignPtrToIOCArray. Other functions in those modules will let you go in the other direction. Best, -Judah
participants (4)
-
Aleksey Khudyakov
-
Anthony Cowley
-
Dominic Espinosa
-
Judah Jacobson