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

Feldspar.Vector

Contents

Description

A module for virtual vectors. Many of the functions defined here are imitations of Haskell's list operations, and to a first approximation they behave accordingly.

A virtual vector normally doesn't use any physical memory. Memory is only introduced explicitly using the function force 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

  • fold
  • fold1
  • Functions that introduce storage (see above)
  • "Folding" functions: sum, maximum, etc.

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 Syntactic class.

Synopsis

Types

data Vector a Source

Symbolic vector

Instances

(Role a ~ (), Info a ~ EdgeSize () (Internal a), Syntactic a) => EdgeInfo (Vector a) 
(Role a ~ (), Info a ~ EdgeSize () (Internal a), Syntactic a) => Syntactic (Vector a) 
Syntactic a => RandomAccess (Vector a) 
(ElemWise a, Syntactic (Vector a)) => ElemWise (Vector a) 
(Role a ~ (), Info a ~ EdgeSize () (Internal a), Syntactic a) => MultiEdge (Vector a) Feldspar EdgeSize 
Type a => Wrap (Vector (Data a)) (Data [a]) 
Type a => Wrap (Matrix a) (Data [[a]]) 
Numeric a => Mul (Data a) (Matrix a) 
Numeric a => Mul (Data a) (DVector a) 
Numeric a => Mul (DVector a) (Matrix a) 
Numeric a => Mul (DVector a) (DVector a) 
Numeric a => Mul (DVector a) (Data a) 
Numeric a => Mul (Matrix a) (Matrix a) 
Numeric a => Mul (Matrix a) (DVector a) 
Numeric a => Mul (Matrix a) (Data a) 
(Wrap t u, Type a, Nat s) => Wrap (DVector a -> t) (Data' s [a] -> u) 
(Wrap t u, Type a, Nat row, Nat col) => Wrap (Matrix a -> t) (Data' (row, col) [[a]] -> u) 

type DVector a = Vector (Data a)Source

Short-hand for non-nested parallel vector

Construction/conversion

segments :: Vector a -> [Vector a]Source

Breaks up a segmented vector into a list of single-segment vectors.

mergeSegments :: Syntactic a => Vector a -> Vector aSource

Converts a segmented vector to a vector with a single segment.

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

Converts a non-nested vector to a core vector.

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

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

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

Variant of unfreezeVector with additional static size information.

memorize :: Syntactic (Vector a) => Vector a -> Vector aSource

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

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

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

Operations

head :: Syntactic a => Vector a -> aSource

last :: Syntactic a => Vector a -> aSource

permute' :: (Data Length -> Data Index -> Data Index) -> Vector a -> Vector aSource

Permute a single-segment vector

permute :: Syntactic a => (Data Length -> Data Index -> Data Index) -> Vector a -> Vector aSource

Permute a vector

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

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

Zipping a single-segment vector

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

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

zipWith :: (Syntactic a, Syntactic b) => (a -> b -> c) -> Vector a -> Vector b -> Vector cSource

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

Corresponds to the standard foldl.

fold1 :: Type a => (Data a -> Data a -> Data a) -> Vector (Data a) -> Data aSource

Corresponds to the standard 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

Wrapping for vectors