feldspar-language-0.6.0.2: A functional embedded language for DSP and parallelism

Safe HaskellNone

Feldspar.Stream

Synopsis

Documentation

data Stream a Source

Infinite streams.

Instances

Syntax a => Indexed (Stream a) 

head :: Syntax a => Stream a -> aSource

Take the first element of a stream

tail :: Syntax a => Stream a -> Stream aSource

Drop the first element of a stream

map :: (Syntax a, Syntax b) => (a -> b) -> Stream a -> Stream bSource

'map f str' transforms every element of the stream str using the function f

mapNth :: Syntax a => (a -> a) -> Data Index -> Data Index -> Stream a -> Stream aSource

'mapNth f n k str' transforms every nth element with offset k of the stream str using the function f

maps :: Syntax a => [a -> a] -> Stream a -> Stream aSource

'maps fs str' uses one of the functions from fs successively to modify the elements of str

intersperse :: Syntax a => a -> Stream a -> Stream aSource

'intersperse a str' inserts an a between each element of the stream str.

interleave :: Syntax a => Stream a -> Stream a -> Stream aSource

Create a new stream by alternating between the elements from the two input streams

downsample :: Syntax a => Data Index -> Stream a -> Stream aSource

'downsample n str' takes every nth element of the input stream

duplicate :: Syntax a => Data Index -> Stream a -> Stream aSource

'duplicate n str' stretches the stream by duplicating the elements n times

scan :: Syntax 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.

scan1 :: Syntax a => (a -> a -> a) -> Stream a -> Stream aSource

A scan but without an initial element.

mapAccum :: (Syntax acc, Syntax b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream bSource

Maps a function over a stream using an accumulator.

iterate :: Syntax 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 :: Syntax a => a -> Stream aSource

Repeat an element indefinitely.

repeat a = [a, a, a, ...]

unfold :: (Syntax a, Syntax c) => (c -> (a, c)) -> c -> Stream aSource

unfold f acc creates a new stream by successively applying f to to the accumulator acc.

drop :: Syntax a => Data Length -> Stream a -> Stream aSource

Drop a number of elements from the front of a stream

zip :: Stream a -> Stream b -> Stream (a, b)Source

Pairs together two streams into one.

zipWith :: (a -> b -> c) -> Stream a -> Stream b -> Stream cSource

Pairs together two streams using a function to combine the corresponding elements.

unzip :: (Syntax a, Syntax b) => Stream (a, b) -> (Stream a, Stream b)Source

Given a stream of pairs, split it into two stream.

take :: Syntax a => Data Length -> Stream a -> Data [Internal a]Source

'take n str' allocates n elements from the stream str into a core array.

splitAt :: Syntax a => Data Length -> Stream a -> (Data [Internal a], Stream 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 :: Syntax a => Vector a -> Stream aSource

Loops through a vector indefinitely to produce a stream.

streamAsVector :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> Vector a -> Vector bSource

A convenience function for translating an algorithm on streams to an algorithm on vectors. The result vector will have the same length as the input vector. It is important that the stream function doesn't drop any elements of the input stream.

This function allocates memory for the output vector.

streamAsVectorSize :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> (Data Length -> Data Length) -> Vector a -> Vector bSource

Similar to streamAsVector except the size of the output array is computed by the second argument which is given the size of the input vector as a result.

recurrenceO :: Type a => Vector1 a -> (Vector1 a -> Data a) -> Stream (Data a)Source

A combinator for descibing recurrence equations, or feedback loops. The recurrence equation may refer to previous outputs of the stream, but only as many as the length of the input stream It uses memory proportional to the input vector.

For exaple one can define the fibonacci sequence as follows:

 fib = recurrenceO (vector [0,1]) (\fib -> fib!0 + fib!1)

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

recurrenceI :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> (Vector1 a -> Data b) -> Stream (Data b)Source

A recurrence combinator with input. The function recurrenceI is similar to recurrenceO. The difference is that that it has an input stream, and that the recurrence equation may only refer to previous inputs, it may not refer to previous outputs.

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

 slidingAvg :: Data WordN -> Stream (Data WordN) -> Stream (Data WordN)
 slidingAvg n str = recurrenceI (replicate n 0) str
                    (\input -> sum input `quot` n)

recurrenceIO :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> Vector1 b -> (Vector1 a -> Vector1 b -> Data b) -> Stream (Data b)Source

recurrenceIO is a combination of recurrenceO and recurrenceI. It has an input stream and the recurrence equation may refer both to previous inputs and outputs.

recurrenceIO is used when defining the iir filter.

recurrenceIIO :: (Type a, Type b, Type c) => Vector1 a -> Stream (Data a) -> Vector1 b -> Stream (Data b) -> Vector1 c -> (Vector1 a -> Vector1 b -> Vector1 c -> Data c) -> Stream (Data c)Source

Similar to recurrenceIO but takes two input streams.

iir :: Data Float -> Vector1 Float -> Vector1 Float -> Stream (Data Float) -> Stream (Data Float)Source

An iir filter on streams

fir :: Vector1 Float -> Stream (Data Float) -> Stream (Data Float)Source

A fir filter on streams