Feldspar.Vector
 Contents Types Construction/conversion Operations
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
type Ix = Int
data Vector a = Indexed {
 length :: Data Length index :: Data Ix -> a
}
type DVector a = Vector (Data a)
freezeVector :: Storable a => Vector (Data a) -> Data [a]
unfreezeVector :: Storable a => Data Length -> Data [a] -> Vector (Data a)
memorize :: Storable a => Vector (Data a) -> Vector (Data a)
indexed :: Data Length -> (Data Ix -> a) -> Vector a
vector :: Storable a => [a] -> Vector (Data a)
modifyLength :: (Data Length -> Data Length) -> Vector a -> Vector a
setLength :: Data Length -> Vector a -> Vector a
boundVector :: Int -> Vector a -> Vector a
(++) :: Computable a => Vector a -> Vector a -> Vector a
take :: Data Int -> Vector a -> Vector a
drop :: Data Int -> Vector a -> Vector a
dropWhile :: (a -> Data Bool) -> Vector a -> Vector a
splitAt :: Data Int -> Vector a -> (Vector a, Vector a)
head :: Vector a -> a
last :: Vector a -> a
tail :: Vector a -> Vector a
init :: Vector a -> Vector a
tails :: Vector a -> Vector (Vector a)
inits :: Vector a -> Vector (Vector a)
inits1 :: Vector a -> Vector (Vector a)
permute :: (Data Length -> Data Ix -> Data Ix) -> Vector a -> Vector a
reverse :: Vector a -> Vector a
replicate :: Data Int -> a -> Vector a
enumFromTo :: Data Int -> Data Int -> Vector (Data Int)
(...) :: Data Int -> Data Int -> Vector (Data Int)
zip :: Vector a -> Vector b -> Vector (a, b)
unzip :: Vector (a, b) -> (Vector a, Vector b)
map :: (a -> b) -> Vector a -> Vector b
zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c
fold :: Computable a => (a -> b -> a) -> a -> Vector b -> a
fold1 :: Computable a => (a -> a -> a) -> Vector a -> a
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
Types
 type Ix = Int Source
Vector index
 data Vector a Source
Symbolic vector
Constructors
Indexed
 length :: Data Length index :: Data Ix -> a Instances
 RandomAccess (Vector a) Storable a => Computable (Vector (Data a)) Storable a => Computable (Vector (Vector (Data 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.
 indexed :: Data Length -> (Data Ix -> a) -> Vector a Source
 vector :: Storable a => [a] -> Vector (Data a) Source
Constructs a non-nested vector. The elements are stored in a core vector.
 modifyLength :: (Data Length -> Data Length) -> Vector a -> Vector a Source
 setLength :: Data Length -> Vector a -> Vector a Source
 boundVector :: Int -> Vector a -> Vector a Source
Operations
 (++) :: Computable a => Vector a -> Vector a -> Vector a Source
Introduces an ifThenElse for each element; use with care!
 take :: Data Int -> Vector a -> Vector a Source
 drop :: Data Int -> Vector a -> Vector a Source
 dropWhile :: (a -> Data Bool) -> Vector a -> Vector a Source
 splitAt :: Data Int -> Vector a -> (Vector a, Vector a) Source
 head :: Vector a -> a Source
 last :: Vector a -> a Source
 tail :: Vector a -> Vector a Source
 init :: Vector a -> Vector a Source
 tails :: Vector a -> Vector (Vector a) Source
 inits :: Vector a -> Vector (Vector a) Source
 inits1 :: Vector a -> Vector (Vector a) Source
 permute :: (Data Length -> Data Ix -> Data Ix) -> Vector a -> Vector a Source
 reverse :: Vector a -> Vector a Source
 replicate :: Data Int -> a -> Vector a Source
 enumFromTo :: Data Int -> Data Int -> Vector (Data Int) Source
 (...) :: Data Int -> Data Int -> Vector (Data Int) Source
 zip :: Vector a -> Vector b -> Vector (a, b) Source
 unzip :: Vector (a, b) -> (Vector a, Vector b) Source
 map :: (a -> b) -> Vector a -> Vector b Source
 zipWith :: (a -> b -> c) -> Vector a -> Vector b -> Vector c Source
 fold :: Computable a => (a -> b -> a) -> a -> Vector b -> a Source
Corresponds to foldl.
 fold1 :: Computable a => (a -> a -> a) -> Vector a -> a Source
Corresponds to foldl1.
 sum :: Numeric a => Vector (Data a) -> Data a Source
 maximum :: Ord a => Vector (Data a) -> Data a Source
 minimum :: Ord a => Vector (Data a) -> Data a Source
 scalarProd :: Numeric a => Vector (Data a) -> Vector (Data a) -> Data a Source
Scalar product of two vectors