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

Safe Haskell | None

Feldspar.Stream

Synopsis

- data Stream a
- head :: Syntax a => Stream a -> a
- tail :: Syntax a => Stream a -> Stream a
- map :: (Syntax a, Syntax b) => (a -> b) -> Stream a -> Stream b
- mapNth :: Syntax a => (a -> a) -> Data Index -> Data Index -> Stream a -> Stream a
- maps :: Syntax a => [a -> a] -> Stream a -> Stream a
- intersperse :: Syntax a => a -> Stream a -> Stream a
- interleave :: Syntax a => Stream a -> Stream a -> Stream a
- downsample :: Syntax a => Data Index -> Stream a -> Stream a
- duplicate :: Syntax a => Data Index -> Stream a -> Stream a
- scan :: Syntax a => (a -> b -> a) -> a -> Stream b -> Stream a
- scan1 :: Syntax a => (a -> a -> a) -> Stream a -> Stream a
- mapAccum :: (Syntax acc, Syntax b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream b
- iterate :: Syntax a => (a -> a) -> a -> Stream a
- repeat :: Syntax a => a -> Stream a
- unfold :: (Syntax a, Syntax c) => (c -> (a, c)) -> c -> Stream a
- drop :: Syntax a => Data Length -> Stream a -> Stream a
- zip :: Stream a -> Stream b -> Stream (a, b)
- zipWith :: (a -> b -> c) -> Stream a -> Stream b -> Stream c
- unzip :: (Syntax a, Syntax b) => Stream (a, b) -> (Stream a, Stream b)
- take :: Syntax a => Data Length -> Stream a -> Data [Internal a]
- splitAt :: Syntax a => Data Length -> Stream a -> (Data [Internal a], Stream a)
- cycle :: Syntax a => Vector a -> Stream a
- streamAsVector :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> Vector a -> Vector b
- streamAsVectorSize :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> (Data Length -> Data Length) -> Vector a -> Vector b
- recurrenceO :: Type a => Vector1 a -> (Vector1 a -> Data a) -> Stream (Data a)
- recurrenceI :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> (Vector1 a -> Data b) -> Stream (Data b)
- recurrenceIO :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> Vector1 b -> (Vector1 a -> Vector1 b -> Data b) -> Stream (Data b)
- 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)
- slidingAvg :: Data WordN -> Stream (Data WordN) -> Stream (Data WordN)
- iir :: Data Float -> Vector1 Float -> Vector1 Float -> Stream (Data Float) -> Stream (Data Float)
- fir :: Vector1 Float -> Stream (Data Float) -> Stream (Data Float)

# Documentation

data Stream a

Infinite streams.

Instances

Syntax a => Indexed (Stream a) |

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

Take the first element of a stream

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

Drop the first element of a stream

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

'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 a

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

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

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

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

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

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

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

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

'downsample n str' takes every `n`th element of the input stream

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

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

scan :: Syntax a => (a -> b -> a) -> a -> Stream b -> Stream a

'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 a

A scan but without an initial element.

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

Maps a function over a stream using an accumulator.

iterate :: Syntax a => (a -> a) -> a -> Stream a

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 a

Repeat an element indefinitely.

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

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

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

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

Drop a number of elements from the front of a stream

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

Pairs together two streams into one.

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

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

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

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

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

'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)

'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 a

Loops through a vector indefinitely to produce a stream.

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

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 b

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)

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)

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)

`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)

Similar to `recurrenceIO` but takes two input streams.

slidingAvg :: Data WordN -> Stream (Data WordN) -> Stream (Data WordN)

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

An iir filter on streams

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

A fir filter on streams