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

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)

Short-hand for non-nested parallel vector

Construction/conversion

indexed :: Data Length -> (Data Index -> a) -> Vector a

segments :: Vector a -> [Vector a]

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

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

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

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

Converts a non-nested vector to a core vector.

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

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

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

Variant of unfreezeVector with additional static size information.

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

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

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

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

Operations

(++) :: Vector a -> Vector a -> Vector a

splitAt :: Data Index -> Vector a -> (Vector a, Vector a)

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

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

tail :: Vector a -> Vector a

init :: Vector a -> Vector a

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

Permute a single-segment vector

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

Permute a vector

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

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

Zipping a single-segment vector

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

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

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

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

Corresponds to the standard foldl.

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

Corresponds to the standard foldl1.

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

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

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

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

Scalar product of two vectors

Wrapping for vectors