dph-lifted-base- Data Parallel Haskell common definitions used by other dph-lifted packages.

Safe HaskellSafe-Infered




Reference implementation of operators on unvectorised parallel arrays.

  • In this module we just used boxed vectors as the array representation. This won't be fast, but it means we can write the operators without needing type class dictionaries such as PA. This makes them much easier to use as reference code.
  • The operators should also all do bounds checks, sanity checks, and give nice error messages if something is wrong. The ideas is that this code can be run side-by-side production code during debugging.



type PArray a = Vector aSource

valid :: PArray a -> BoolSource

Check that an array has a valid internal representation.

nf :: PArray a -> ()Source

Force an array to normal form.


empty :: PArray aSource

O(1). An empty array.

singleton :: a -> PArray aSource

O(1). Produce an array containing a single element.

singletonl :: PArray a -> PArray (PArray a)Source

O(n). Produce an array of singleton arrays.

replicate :: Int -> a -> PArray aSource

O(n). Define an array of the given size, that maps all elements to the same value.

replicatel :: PArray Int -> PArray a -> PArray (PArray a)Source

O(sum lengths). Lifted replicate.

replicates :: Segd -> PArray a -> PArray aSource

O(sum lengths). Segmented replicate.

replicates' :: PArray Int -> PArray a -> PArray aSource

O(sum lengths). Wrapper for segmented replicate that takes replication counts and uses them to build the Segd.

append :: PArray a -> PArray a -> PArray aSource

Append two arrays.

appendl :: PArray (PArray a) -> PArray (PArray a) -> PArray (PArray a)Source

Lifted append.

concat :: PArray (PArray a) -> PArray aSource


concatl :: PArray (PArray (PArray a)) -> PArray (PArray a)Source

Lifted concatenation.

unconcat :: PArray (PArray a) -> PArray b -> PArray (PArray b)Source

Impose a nesting structure on a flat array

nestUSegd :: Segd -> PArray a -> PArray (PArray a)Source

Create a nested array from a segment descriptor and some flat data. The segment descriptor must represent as many elements as present in the flat data array, else error


length :: PArray a -> IntSource

Take the length of an array

lengthl :: PArray (PArray a) -> PArray IntSource

Take the length of some arrays.

index :: PArray a -> Int -> aSource

Lookup a single element from the source array.

indexl :: PArray (PArray a) -> PArray Int -> PArray aSource

Lookup a several elements from several source arrays.

extract :: PArray a -> Int -> Int -> PArray aSource

Extract a range of elements from an array.

extracts :: Vector (PArray a) -> SSegd -> PArray aSource

Segmented extract.



:: Vector (PArray a) 
-> PArray Int

id of source array for each segment.

-> PArray Int

starting index of each segment in its source array.

-> PArray Int

length of each segment.

-> PArray a 

Wrapper for extracts that takes arrays of sources, starts and lengths of the segments, and uses these to build the SSegd.

slice :: Int -> Int -> PArray a -> PArray aSource

Extract a range of elements from an arrary. Like extract but with the parameters in a different order.

slicel :: PArray Int -> PArray Int -> PArray (PArray a) -> PArray (PArray a)Source

Extract some slices from some arrays. The arrays of starting indices and lengths must themselves have the same length.

takeUSegd :: PArray (PArray a) -> SegdSource

Take the segment descriptor from a nested array. This can cause index space overflow if the number of elements in the result does not can not be represented by a single machine word.

Pack and Combine

pack :: PArray a -> PArray Bool -> PArray aSource

Select the elements of an array that have their tag set to True.

packl :: PArray (PArray a) -> PArray (PArray Bool) -> PArray (PArray a)Source

Lifted pack.

packByTag :: PArray a -> Array Tag -> Tag -> PArray aSource

Filter an array based on some tags.

combine2 :: Sel2 -> PArray a -> PArray a -> PArray aSource

Combine two arrays based on a selector.


enumFromTo :: Int -> Int -> PArray IntSource

Construct a range of integers

enumFromTol :: PArray Int -> PArray Int -> PArray (PArray Int)Source

Lifted enumeration


zip :: PArray a -> PArray b -> PArray (a, b)Source

O(n). Zip a pair of arrays into an array of pairs.

zipl :: PArray (PArray a) -> PArray (PArray b) -> PArray (PArray (a, b))Source

Lifted zip

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

O(n). Unzip an array of pairs into a pair of arrays.

unzipl :: PArray (PArray (a, b)) -> PArray (PArray a, PArray b)Source

Lifted unzip


fromVector :: Vector a -> PArray aSource

Convert a Vector to a PArray

toVector :: PArray a -> Vector aSource

Convert a PArray to a Vector

fromList :: [a] -> PArray aSource

Convert a list to a PArray.

toList :: PArray a -> [a]Source

Convert a PArray to a list.

fromUArray :: Elt a => Array a -> PArray aSource

Convert a Array to a PArray

toUArray :: Elt a => PArray a -> Array aSource

Convert a PArray to a Array

fromUArray2 :: (Elt a, Elt b) => Array (a, b) -> PArray (a, b)Source

Convert a Array of tuples to a PArray