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.
- type Size = Int
- type Ix = Int
- data Par n
- data Seq n
- data n :>> a where
- type VectorP n a = Par n :>> Data a
- type VectorS n a = Seq n :>> Data a
- type family a :+ b
- type family a :* b
- class AccessPattern t where
- indexed :: Data Size -> (Data Ix -> a) -> Par n :>> a
- unfold :: Computable s => Data Size -> (s -> (a, s)) -> s -> Seq n :>> a
- freezeVector :: forall t n a. (NaturalT n, Storable a) => (t n :>> Data a) -> Data (n :> a)
- unfreezeVector :: (NaturalT n, Storable a, AccessPattern t) => Data Size -> Data (n :> a) -> t n :>> Data a
- vector :: (NaturalT n, Storable a, AccessPattern t, ListBased a ~ a) => [a] -> t n :>> Data a
- toSeq :: (t n :>> a) -> Seq n :>> a
- resize :: NaturalT n => (t m :>> a) -> t n :>> a
- toPar :: (NaturalT n, Storable a) => (t n :>> Data a) -> VectorP n a
- index :: (t :>> a) -> Data Ix -> a
- length :: (t n :>> a) -> Data Size
- (++) :: Computable a => (t m :>> a) -> (t n :>> a) -> t (m :+ n) :>> a
- take :: Data Int -> (t n :>> a) -> t n :>> a
- drop :: Data Int -> (t n :>> a) -> t n :>> a
- dropWhile :: (a -> Data Bool) -> (t n :>> a) -> t n :>> a
- splitAt :: Data Int -> (t n :>> a) -> (t n :>> a, t n :>> a)
- head :: (t n :>> a) -> a
- last :: (t n :>> a) -> a
- tail :: (t n :>> a) -> t n :>> a
- init :: (t n :>> a) -> t n :>> a
- tails :: AccessPattern u => (t n :>> a) -> u n :>> (t n :>> a)
- inits :: AccessPattern u => (t n :>> a) -> u n :>> (t n :>> a)
- permute :: (Data Size -> Data Ix -> Data Ix) -> (Par n :>> a) -> Par n :>> a
- reverse :: (Par n :>> a) -> Par n :>> a
- replicate :: AccessPattern t => Data Int -> a -> t n :>> a
- enumFromTo :: AccessPattern t => Data Int -> Data Int -> t n :>> Data Int
- zip :: (t n :>> a) -> (t n :>> b) -> t n :>> (a, b)
- unzip :: (t n :>> (a, b)) -> (t n :>> a, t n :>> b)
- map :: (a -> b) -> (t n :>> a) -> t n :>> b
- zipWith :: (a -> b -> c) -> (t n :>> a) -> (t n :>> b) -> t n :>> c
- fold :: Computable a => (a -> b -> a) -> a -> (t n :>> b) -> a
- fold1 :: Computable a => (a -> a -> a) -> (t n :>> a) -> a
- scan :: Computable a => (a -> b -> a) -> a -> (t n :>> b) -> Seq n :>> a
- scan1 :: Computable a => (a -> a -> a) -> (t n :>> a) -> Seq n :>> a
- sum :: (Num a, Computable a) => (t n :>> a) -> a
- maximum :: Storable a => (t n :>> Data a) -> Data a
- minimum :: Storable a => (t n :>> Data a) -> Data a
- scalarProd :: (Primitive a, Num a) => (t n :>> Data a) -> (t n :>> Data a) -> Data a
Types
Empty type denoting a parallel (random) access pattern for elements in a vector. The argument denotes the static size of the vector.
AccessPattern Par | |
RandomAccess (:>> (Par n) a) |
Empty type denoting a sequential access pattern for elements in a vector. The argument denotes the static size of the vector.
Symbolic vector. For example,
Seq D10 :>> Par D5 :>> Data Int
is a sequential (symbolic) vector of parallel vectors of integers. The type
numbers D10
and D5
denote the static size of the vector, i.e. the
allocated size of the array used if and when the vector gets written to
memory (e.g. by toPar
).
If it is known that the vector will never be written to memory, it is
not needed to specify a static size. In that case, it is possible to use ()
as the static size type. This way, attempting to write to memory will
result in a type error.
The Size
argument to the Indexed
and Unfold
constructors is called the
dynamic size, since it can vary freely during execution.
Indexed :: Data Size -> (Data Ix -> a) -> Par n :>> a | |
Unfold :: Computable s => Data Size -> (s -> (a, s)) -> s -> Seq n :>> a |
RandomAccess (:>> (Par n) a) | |
(NaturalT n1, NaturalT n2, Storable a, AccessPattern t1, AccessPattern t2) => Computable (:>> (t1 n1) (:>> (t2 n2) (Data a))) | |
(NaturalT n, Storable a, AccessPattern t) => Computable (:>> (t n) (Data a)) |
Construction/conversion
class AccessPattern t whereSource
A class for generalizing over parallel and sequential vectors.
indexed :: Data Size -> (Data Ix -> a) -> Par n :>> aSource
Constructs a parallel vector from an index function. The function is
assumed to be defined for the domain [0 .. n-1]
, were n
is the dynamic
size.
unfold :: Computable s => Data Size -> (s -> (a, s)) -> s -> Seq n :>> aSource
Constructs a sequential vector from a "step" function and an initial state.
freezeVector :: forall t n a. (NaturalT n, Storable a) => (t n :>> Data a) -> Data (n :> a)Source
Converts a non-nested vector to a core vector.
unfreezeVector :: (NaturalT n, Storable a, AccessPattern t) => Data Size -> Data (n :> a) -> t n :>> Data aSource
Converts a non-nested core vector to a parallel vector.
vector :: (NaturalT n, Storable a, AccessPattern t, ListBased a ~ a) => [a] -> t n :>> Data aSource
Constructs a non-nested vector.
toSeq :: (t n :>> a) -> Seq n :>> aSource
Convert any vector to a sequential one. This operation is always "cheap".
toPar :: (NaturalT n, Storable a) => (t n :>> Data a) -> VectorP n aSource
Convert any non-nested vector to a parallel one with cheap lookups. Internally, this is done by writing the vector to memory.
Operations
index :: (t :>> a) -> Data Ix -> aSource
Look up an index in a vector. This operation takes linear time for sequential vectors.
tails :: AccessPattern u => (t n :>> a) -> u n :>> (t n :>> a)Source
Like Haskell's tails
, but does not include the empty vector. This is
actually just to make the types simpler (the result is square).
inits :: AccessPattern u => (t n :>> a) -> u n :>> (t n :>> a)Source
Like Haskell's inits
, but does not include the empty vector. This is
actually just to make the types simpler (the result is square).
enumFromTo :: AccessPattern t => Data Int -> Data Int -> t n :>> Data IntSource
fold :: Computable a => (a -> b -> a) -> a -> (t n :>> b) -> aSource
Corresponds to Haskell's foldl
.
fold1 :: Computable a => (a -> a -> a) -> (t n :>> a) -> aSource
Corresponds to Haskell's foldl1
.
scan :: Computable a => (a -> b -> a) -> a -> (t n :>> b) -> Seq n :>> aSource
Corresponds to Haskell's scanl
.
scan1 :: Computable a => (a -> a -> a) -> (t n :>> a) -> Seq n :>> aSource
Corresponds to Haskell's scanl1
.
sum :: (Num a, Computable a) => (t n :>> a) -> aSource