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

Feldspar.Vector

Contents

Description

A high-level interface to the operations in the core language (Feldspar.Core). Many of the functions defined here are imitations of Haskell's list operations, and to a first approximation they behave accordingly.

A symbolic vector (Vector) can be thought of as a representation of a parallel core array. This view is made precise by the function freezeVector, which converts a symbolic vector to a core vector using parallel.

Vector is instantiated under the Computable class, which means that symbolic vectors can be used quite seamlessly with the interface in Feldspar.Core.

Unlike core arrays vectors don't use any physical memory. All operations on vectors are "fused" which means that intermediate vectors are removed. As an example, the following function uses only constant space despite using two intermediate vectors of length n.

 sumSq n = sum (map (^2) (1...n))

Memory is only introduced when a vector is explicitly written to memory using the function memorize or converted to a core array using freezeVector. The function vector for creating a vector also allocates memory.

Note also that most operations only introduce a small constant overhead on the vector. The exceptions are

These functions introduce overhead that is linear in the length of the vector.

Finally, note that freezeVector can be introduced implicitly by functions overloaded by the Computable class. This means that, for example, printCore f, where f :: Vector (Data Int) -> Vector (Data Int), will introduce storage for the input and output of f.

Synopsis

Types

type Ix = IntSource

Vector index

data Vector a Source

Symbolic vector

Constructors

Indexed 

Fields

length :: Data Length
 
index :: Data Ix -> a
 

type DVector a = Vector (Data a)Source

Short-hand for non-nested parallel vector

Construction/conversion

freezeVector :: Storable a => Vector (Data a) -> Data [a]Source

Converts a non-nested vector to a core vector.

unfreezeVector :: Storable a => Data Length -> Data [a] -> Vector (Data a)Source

Converts a non-nested core vector to a parallel vector.

memorize :: Storable a => Vector (Data a) -> Vector (Data a)Source

Optimizes vector lookup by computing all elements and storing them in a core array.

vector :: Storable a => [a] -> Vector (Data a)Source

Constructs a non-nested vector. The elements are stored in a core vector.

Operations

(++) :: Computable a => Vector a -> Vector a -> Vector aSource

Introduces an ifThenElse for each element; use with care!

dropWhile :: (a -> Data Bool) -> Vector a -> Vector aSource

head :: Vector a -> aSource

last :: Vector a -> aSource

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

unzip :: Vector (a, b) -> (Vector a, Vector b)Source

map :: (a -> b) -> Vector a -> Vector bSource

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

fold :: Computable a => (a -> b -> a) -> a -> Vector b -> aSource

Corresponds to foldl.

fold1 :: Computable a => (a -> a -> a) -> Vector a -> aSource

Corresponds to foldl1.

sum :: Numeric a => Vector (Data a) -> Data aSource

maximum :: Ord a => Vector (Data a) -> Data aSource

minimum :: Ord a => Vector (Data a) -> Data aSource

scalarProd :: Numeric a => Vector (Data a) -> Vector (Data a) -> Data aSource

Scalar product of two vectors