Parallel Arrays.
Parallel arrays use a fixed generic representation. All data stored in them is converted to the generic representation, and we have a small number of operators that work on arrays of these generic types.
Representation types include Ints, Floats, Tuples and Sums, so arrays of these types can be stored directly. However, user defined algebraic data needs to be converted as we don't have operators that work directly on arrays of these types.
The top-level PArray type is built up from several type families and clases:
PArray - This is the top level type. It holds an array length, and array data in the generic representation (PData).
PRepr - Family of types that can be converted to the generic representation. We supply instances for basic types like Ints Floats etc, but the vectoriser needs to make the instances for user-defined data types itself. PA class - Contains methods to convert to and from the generic representation (PData).
PData - Family of types that can be stored directly in parallel arrays. We supply all the PData instances we need here in the library. PR class - Contains methods that work directly on parallel arrays. Most of these are just wrappers for the corresponding U.Array operators.
Scalar class - Contains methods to convert between the generic representation (PData) and plain U.Arrays.
Note that the PRepr family and PA class are related. so are the PData family and PR class.
For motivational material see: An Approach to Fast Arrays in Haskell, Chakravarty and Keller, 2003
For discussion of how the mapping to generic types works see: Instant Generics: Fast and Easy, Chakravarty, Ditu and Keller, 2009
- data PArray a
- class PR (PRepr a) => PA a
- class Random a where
- length :: PA a => PArray a -> Int
- empty :: PA a => PArray a
- replicate :: PA a => Int -> a -> PArray a
- singleton :: PA a => a -> PArray a
- (!:) :: PA a => PArray a -> Int -> a
- zip :: (PA a, PA b) => PArray a -> PArray b -> PArray (a, b)
- unzip :: (PA a, PA b) => PArray (a, b) -> (PArray a, PArray b)
- pack :: PA a => PArray a -> PArray Bool -> PArray a
- concat :: PA a => PArray (PArray a) -> PArray a
- (+:+) :: PA a => PArray a -> PArray a -> PArray a
- indexed :: PA a => PArray a -> PArray (Int, a)
- slice :: PA a => Int -> Int -> PArray a -> PArray a
- update :: PA a => PArray a -> PArray (Int, a) -> PArray a
- bpermute :: PA a => PArray a -> PArray Int -> PArray a
- enumFromTo :: Int -> Int -> PArray Int
- fromList :: PA a => [a] -> PArray a
- toList :: PA a => PArray a -> [a]
- fromUArrPA' :: Scalar a => Array a -> PArray a
- nf :: PA a => PArray a -> ()
Documentation
Lifted/bulk parallel arrays This contains the array length, along with the element data.
class PR (PRepr a) => PA a Source
A PA dictionary contains the functions that we use to convert a representable type to and from its generic representation. The conversion methods should all be O(1).
Array operators.
replicate :: PA a => Int -> a -> PArray aSource
O(n). Produce an array containing copies of a given element.
zip :: (PA a, PA b) => PArray a -> PArray b -> PArray (a, b)Source
O(1). Takes two arrays and returns an array of corresponding pairs. If one array is short, excess elements of the longer array are discarded.
unzip :: (PA a, PA b) => PArray (a, b) -> (PArray a, PArray b)Source
O(1). Transform an array into an array of the first components, and an array of the second components.
pack :: PA a => PArray a -> PArray Bool -> PArray aSource
Select the elements of an array that have their tag set as True.
packPA [12, 24, 42, 93] [True, False, False, True] = [24, 42]
concat :: PA a => PArray (PArray a) -> PArray aSource
Concatenate an array of arrays into a single array.
indexed :: PA a => PArray a -> PArray (Int, a)Source
O(n). Tag each element of an array with its index.
indexed [42, 93, 13] = [(0, 42), (1, 93), (2, 13)]
slice :: PA a => Int -> Int -> PArray a -> PArray aSource
Extract a subrange of elements from an array. The first argument is the starting index, while the second is the length of the slice.
update :: PA a => PArray a -> PArray (Int, a) -> PArray aSource
Copy the source array in the destination, using new values for the given indices.
bpermute :: PA a => PArray a -> PArray Int -> PArray aSource
O(n). Backwards permutation of array elements.
bpermute [50, 60, 20, 30] [0, 3, 2] = [50, 30, 20]
Conversion
fromUArrPA' :: Scalar a => Array a -> PArray aSource
Create a PArray out of a scalar U.Array, reading the length directly from the U.Array.