Feldspar.Vector.Push

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

Safe Haskell | None

Feldspar.Vector.Push

Synopsis

- data PushVector a where
  - Push :: ((Data Index -> a -> M ()) -> M ()) -> Data Length -> PushVector a
- freezePush :: Syntax a => PushVector a -> Data [Internal a]
- freezeToVector :: Syntax a => PushVector a -> Vector a
- thawPush :: Syntax a => Data [Internal a] -> PushVector a
- class Pushy arr where
  - toPush :: Syntax a => arr a -> PushVector a
- (++) :: (Pushy arr, Syntax a) => arr a -> arr a -> PushVector a
- unpair :: (Pushy arr, Syntax a) => arr (a, a) -> PushVector a
- everyOther :: (Data Index -> a -> M b) -> Data Index -> (a, a) -> M b
- zipUnpair :: Syntax a => Vector a -> Vector a -> PushVector a
- class Ixmap arr where
  - ixmap :: Syntax a => (Data Index -> Data Index) -> arr a -> arr a
- reverse :: (Ixmap arr, Len arr, Syntax a) => arr a -> arr a
- halve :: Syntax a => Vector a -> (Vector a, Vector a)
- riffle :: Syntax a => Vector a -> PushVector a
- class Len arr where
  - length :: arr a -> Data Length
- chunk :: (Pushy arr1, Pushy arr2, Syntax b) => Data Length -> (Vector a -> arr1 b) -> (Vector a -> arr2 b) -> Vector a -> PushVector b
- empty :: PushVector a
- flatten :: Syntax a => Vector (PushVector a) -> PushVector a

# Documentation

data PushVector a where

Constructors

Push :: ((Data Index -> a -> M ()) -> M ()) -> Data Length -> PushVector a |

Instances

Functor PushVector |
Len PushVector |
Ixmap PushVector |
Pushy PushVector |
Syntax a => Syntactic (PushVector a) |
Syntax a => Syntax (PushVector a) |

freezePush :: Syntax a => PushVector a -> Data [Internal a]

Store push vectors in memory.

freezeToVector :: Syntax a => PushVector a -> Vector a

Store a push vector to memory and return it as an ordinary vector.

thawPush :: Syntax a => Data [Internal a] -> PushVector a

Create a push vector from an array stored in memory.

class Pushy arr where

Any kind of vector, push or pull, can cheaply be converted to a push vector

Methods

toPush :: Syntax a => arr a -> PushVector a

Instances

Pushy Vector |
Pushy PushVector |

(++) :: (Pushy arr, Syntax a) => arr a -> arr a -> PushVector a

Concatenating two arrays.

unpair :: (Pushy arr, Syntax a) => arr (a, a) -> PushVector a

Given an array of pairs, flatten the array so that the elements of the pairs end up next to each other in the resulting vector.

everyOther :: (Data Index -> a -> M b) -> Data Index -> (a, a) -> M b

zipUnpair :: Syntax a => Vector a -> Vector a -> PushVector a

Interleaves the elements of two vectors.

class Ixmap arr where

An overloaded function for reordering elements of a vector.

Methods

ixmap :: Syntax a => (Data Index -> Data Index) -> arr a -> arr a

Instances

Ixmap Vector |
Ixmap PushVector |

reverse :: (Ixmap arr, Len arr, Syntax a) => arr a -> arr a

Reverse a vector. Works for both push and pull vectors.

halve :: Syntax a => Vector a -> (Vector a, Vector a)

Split a pull vector in half.

If the input vector has an odd length the second result vector will be one element longer than the first.

riffle :: Syntax a => Vector a -> PushVector a

Split a vector in half and interleave the two two halves.

class Len arr where

A class for overloading `length` for both pull and push vectors

Methods

length :: arr a -> Data Length

Instances

Len Vector |
Len PushVector |

chunk

Arguments

:: (Pushy arr1, Pushy arr2, Syntax b) |
=> Data Length | Size of the chunks
-> (Vector a -> arr1 b) | Applied to every chunk
-> (Vector a -> arr2 b) | Applied to the rest of the vector
-> Vector a |
-> PushVector b |

This function can distribute array computations on chunks of a large pull vector. A call `chunk l f g v` will split the vector `v` into chunks of size `l` and apply `f` to these chunks. In case the length of `v` is not a multiple of `l` then the rest of `v` will be processed by `g`.

empty :: PushVector a

The empty push vector.

flatten :: Syntax a => Vector (PushVector a) -> PushVector a

Flattens a pull vector containing push vectors into an unnested push vector

Note that there are no restrictions on the lengths of the push vectors inside the pull vector.