feldspar-language-0.3.1: A functional embedded language for DSP and parallelismSource codeContentsIndex
Feldspar.Stream
Synopsis
data Stream a
head :: Computable a => Stream a -> a
tail :: Computable a => Stream a -> Stream a
map :: (Computable a, Computable b) => (a -> b) -> Stream a -> Stream b
intersperse :: a -> Stream a -> Stream a
interleave :: Stream a -> Stream a -> Stream a
scan :: Computable a => (a -> b -> a) -> a -> Stream b -> Stream a
mapAccum :: (Computable acc, Computable b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream b
iterate :: Computable a => (a -> a) -> a -> Stream a
repeat :: Computable a => a -> Stream a
unfold :: (Computable a, Computable c) => (c -> (a, c)) -> c -> Stream a
drop :: Data Unsigned32 -> Stream a -> Stream a
dropWhile :: (t -> Data Bool) -> Stream t -> Stream t
filter :: (a -> Data Bool) -> Stream a -> Stream a
partition :: (a -> Data Bool) -> Stream a -> (Stream a, Stream a)
zip :: Stream a -> Stream b -> Stream (a, b)
zipWith :: Computable c => (a -> b -> c) -> Stream a -> Stream b -> Stream c
unzip :: (Computable a, Computable b) => Stream (a, b) -> (Stream a, Stream b)
take :: Storable a => Data Int -> Stream (Data a) -> Data [a]
splitAt :: Storable a => Data Int -> Stream (Data a) -> (Data [a], Stream (Data a))
cycle :: Computable a => Vector a -> Stream a
recurrence :: Storable a => DVector a -> ((Int -> Data a) -> Data a) -> Stream (Data a)
recurrenceI :: (Storable a, Storable b) => DVector a -> Stream (Data a) -> DVector b -> ((Data Int -> Data a) -> (Data Int -> Data b) -> Data b) -> Stream (Data b)
iir :: Data Float -> DVector Float -> DVector Float -> Stream (Data Float) -> Stream (Data Float)
fir :: DVector Float -> Stream (Data Float) -> Stream (Data Float)
Documentation
data Stream a Source
Infinite streams.
show/hide Instances
head :: Computable a => Stream a -> aSource
Take the first element of a stream
tail :: Computable a => Stream a -> Stream aSource
Drop the first element of a stream
map :: (Computable a, Computable b) => (a -> b) -> Stream a -> Stream bSource
'map f str' transforms every element of the stream str using the function f
intersperse :: a -> Stream a -> Stream aSource
'intersperse a str' inserts an a between each element of the stream str.
interleave :: Stream a -> Stream a -> Stream aSource
Create a new stream by alternating between the elements from the two input streams
scan :: Computable a => (a -> b -> a) -> a -> Stream b -> Stream aSource
'scan f a str' produces a stream by successively applying f to each element of the input stream str and the previous element of the output stream.
mapAccum :: (Computable acc, Computable b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream bSource
Maps a function over a stream using an accumulator.
iterate :: Computable a => (a -> a) -> a -> Stream aSource

Iteratively applies a function to a starting element. All the successive results are used to create a stream.

iterate f a == [a, f a, f (f a), f (f (f a)) ...]
repeat :: Computable a => a -> Stream aSource

Repeat an element indefinitely.

repeat a = [a, a, a, ...]
unfold :: (Computable a, Computable c) => (c -> (a, c)) -> c -> Stream aSource
unfold f acc creates a new stream by successively applying f to to the accumulator acc.
drop :: Data Unsigned32 -> Stream a -> Stream aSource
Drop a number of elements from the front of a stream
dropWhile :: (t -> Data Bool) -> Stream t -> Stream tSource
filter :: (a -> Data Bool) -> Stream a -> Stream aSource

dropWhile p str drops element from the stream str as long as the elements fulfill the predicate p.

'filter p str' removes elements from the stream str if they are false according to the predicate p

partition :: (a -> Data Bool) -> Stream a -> (Stream a, Stream a)Source
Splits a stream in two according to the predicate function. All elements which return true go in the first stream, the rest go in the second.
zip :: Stream a -> Stream b -> Stream (a, b)Source
Pairs together two streams into one.
zipWith :: Computable c => (a -> b -> c) -> Stream a -> Stream b -> Stream cSource
Pairs together two streams using a function to combine the corresponding elements.
unzip :: (Computable a, Computable b) => Stream (a, b) -> (Stream a, Stream b)Source
Given a stream of pairs, split it into two stream.
take :: Storable a => Data Int -> Stream (Data a) -> Data [a]Source
'take n str' allocates n elements from the stream str into a core array.
splitAt :: Storable a => Data Int -> Stream (Data a) -> (Data [a], Stream (Data a))Source
'splitAt n str' allocates n elements from the stream str into a core array and returns the rest of the stream continuing from element 'n+1'.
cycle :: Computable a => Vector a -> Stream aSource
Loops through a vector indefinitely to produce a stream.
recurrence :: Storable a => DVector a -> ((Int -> Data a) -> Data a) -> Stream (Data a)Source

A combinator for descibing recurrence equations, or feedback loops. It uses memory proportional to the input vector

For exaple one can define the fibonacci sequence as follows:

 fib = recurrence (vector [0,1]) (\fib -> fib 1 + fib 2)

The expressions fib 1 and fib 2 refer to previous elements in the stream defined one step back and two steps back respectively.

recurrenceI :: (Storable a, Storable b) => DVector a -> Stream (Data a) -> DVector b -> ((Data Int -> Data a) -> (Data Int -> Data b) -> Data b) -> Stream (Data b)Source

A recurrence combinator with input

The sliding average of a stream can easily be implemented using recurrenceI.

 slidingAvg :: Data Int -> Stream (Data Int) -> Stream (Data Int)
 slidingAvg n str = recurrenceI (replicate n 0) str (vector [])
                    (\input _ -> sum (indexed n input) `quot` n)
iir :: Data Float -> DVector Float -> DVector Float -> Stream (Data Float) -> Stream (Data Float)Source
An iir filter on streams
fir :: DVector Float -> Stream (Data Float) -> Stream (Data Float)Source
A fir filter on streams
Produced by Haddock version 2.6.1