[Haskell-cafe] uvector and the stream interface

Don Stewart dons at galois.com
Mon Jul 14 12:27:16 EDT 2008

> currently i'm working on stuff that looks something like this:
> 1 read soundfile from disk in blocks of N samples (IOCArray, hsndfile  
> package)
> 2 convert to CArray with unsafeFreeze (simple O(1) cast, carray package)
> 3 perform FFT (CArray, fftw package)
> 4 convert to UArr (uvector package)
> 5 do some stuff with vectors
> i'd like to minimize copying, and since the FFT returns a new array  
> anyway, the only copying conversion is the one between CArray and  
> UArr in step 4. the approach i've been following is defining a  
> `stream' conversion for CArray, hoping that subsequent carray  
> accesses will be fused with uvector operations without the need for  
> allocating a vector in between. does that make sense? could this be a  
> general strategy for avoiding copying at the boundary between the  
> various array libraries?

If you can write a function from CArray a -> Stream a, then yep, it'll
fuse, and that's a good way to avoid copying.

Another way is to dive into the internals and coerce the CArray type to
a MUArr.

It would be helpful to see the programs people are writing with uvector,
so I can polish up the API some more :)

-- Don

More information about the Haskell-Cafe mailing list