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
-
dropWhile
-
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 Computable
class. This means that, for example,
, where printCore
ff :: Vector (Data Int) -> Vector (Data Int)
, will
introduce storage for the input and output of f
.
- type Ix = Int
- data Vector a = Indexed {}
- 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
Symbolic vector
RandomAccess (Vector a) | |
Storable a => Computable (Vector (Data a)) | |
Storable a => Computable (Vector (Vector (Data a))) |
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.
boundVector :: Int -> Vector a -> Vector aSource
Operations
(++) :: Computable a => Vector a -> Vector a -> Vector aSource
Introduces an ifThenElse
for each element; use with care!
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
.