Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there infinite lists with unboxed vector performance?

I'm thinking specifically for signal processing. Let's say I wanted to do something like double the magnitude of an incoming signal. I would want it to be very fast, so I would want the signal to be held in contiguous memory (e.g. unboxed vectors). But this signal could go on indefinitely, so I would want it to be treated as an infinite list; I'd rather call map (*2) signal once instead of calling it for every signal chunk.

Is there a data structure in Haskell that would buffer these data chunks so that I could get contiguous memory performance, but treat the data as an infinite stream?

like image 721
awelkie Avatar asked Jun 28 '14 15:06

awelkie


1 Answers

This is just a long shot, but what about using streams of large enough chunks of unboxed vectors? This would have the advantage of vectors' performance, and at the same time, fusion thanks to streams.

Update: The idea is to define a newtype such as:

import Data.Array.Unboxed
import Data.Stream
import Data.Word

newtype Word8Stream = Word8Stream (Stream (UArray Int Word8))

and then define the generic functions you need such as

smap :: (Word8 -> Word8) -> Word8Stream -> Word8Stream
smap f (Word8Stream s) = Word8Stream $ fmap (amap f) s
like image 69
Petr Avatar answered Oct 21 '22 06:10

Petr