-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Data Parallel Haskell segmented arrays. (abstract interface) -- -- Empty implementation of flat parallel arrays. This package exists only -- so that dph-prim-par and dph-prim-seq can provide the same interface. @package dph-prim-interface @version 0.7.0.1 -- | WARNING: This is an abstract interface. All the functions will just -- error if called. -- -- This module provides an API for the segmented array primitives used by -- DPH. None of the functions here have implementations. -- -- Client programs should use either the dph-prim-seq or -- dph-prim-par packages, as these provide the same API and -- contain real code. module Data.Array.Parallel.Unlifted class Elt a type Array a = [a] -- | O(1). Construct an array with no elements. empty :: Elt a => Array a -- | Generate a new array given its length and a function to compute each -- element. generate :: Elt a => Int -> (Int -> a) -> Array a -- | O(length result). Construct a new array by replicating a single -- element the given number of times. replicate :: Elt a => Int -> a -> Array a -- | O(length result). Segmented replicate. -- -- Elements of the array are replicated according to the lengths of the -- segments defined by the Segd. replicate_s :: Elt a => Segd -> Array a -> Array a -- | O(length result). Regular segmented replicate. -- -- Like replicate_s, but all segments are assumed to have the -- given length. replicate_rs :: Elt a => Int -> Array a -> Array a -- | O(length result). Construct an array by copying a portion of another -- array. repeat :: Elt a => Int -> Int -> Array a -> Array a -- | O(length result). Tag each element of an array with its index. -- --
-- indexed [42, 93, 13] = [(0, 42), (1, 93), (2, 13)] --indexed :: Elt a => Array a -> Array (Int, a) -- | O(length result). Append two arrays. (+:+) :: Elt a => Array a -> Array a -> Array a -- | O(length result). Segmented append. append_s :: Elt a => Segd -> Segd -> Array a -> Segd -> Array a -> Array a append_vs :: (Elt a, Elts a) => Segd -> VSegd -> Arrays a -> VSegd -> Arrays a -> Array a -- | O(length result). Segmented indices. -- -- Construct an array containing containing the segments defined by the -- given Segd. -- -- Each segment will contain the elements [0..len-1] where -- len is the length of that segment. indices_s :: Segd -> Array Int enumFromTo :: Int -> Int -> Array Int enumFromThenTo :: Int -> Int -> Int -> Array Int enumFromStepLen :: Int -> Int -> Int -> Array Int enumFromStepLenEach :: Int -> Array Int -> Array Int -> Array Int -> Array Int -- | O(1). Yield the number of elements in an array. length :: Elt a => Array a -> Int -- | O(1). Retrieve a numbered element from an array. -- -- The first argument gives a source-code location for out-of-bounds -- errors. index :: Elt a => String -> Array a -> Int -> a -- | O(length result). Scattered indexing from a single Array. -- -- This is an alias for bpermute. indexs :: Elt a => Array a -> Array Int -> Array a -- | O(length result). Scattered indexing through a VSegd. -- -- The index array contains pairs of segment id and the index within that -- segment. -- -- We use the VSegd to map the pairs to 2D indices within the -- Arrays, and return an array of the resulting elements. indexs_avs :: (Elt a, Elts a) => Arrays a -> VSegd -> Array (Int, Int) -> Array a -- | O(length result). Extract a subrange of elements from an array. -- --
-- extract [23, 42, 93, 50, 27] 1 3 = [42, 93, 50] --extract :: Elt a => Array a -> Int -> Int -> Array a -- | O(length result). Extract segments defined by a SSegd from a -- vector of arrays. -- -- NOTE: This is a transitory interface, and will be removed in future -- versions. Use extracts_ass instead. extracts_nss :: Elt a => SSegd -> Vector (Array a) -> Array a -- | O(length result). Extract segments defined by a SSegd. -- -- Extract all the segments defined by the SSegd from the -- Arrays, returning them concatenated in a fresh Array. extracts_ass :: (Elt a, Elts a) => SSegd -> Arrays a -> Array a -- | O(length result). Extract segments defined by a VSegd. -- -- Extract all the segments defined by the VSegd from the -- Arrays, returning them concatenated in a fresh Array. extracts_avs :: (Elt a, Elts a) => VSegd -> Arrays a -> Array a -- | O(length result). Drop elements from the front of an array, returning -- the latter portion. drop :: Elt a => Int -> Array a -> Array a -- | O(length result). Copy the source array while replacing some elements -- by new ones in the result. update :: Elt a => Array a -> Array (Int, a) -> Array a -- | O(length result). Forwards permutation of array elements. permute :: Elt a => Array a -> Array Int -> Array a -- | O(length result). Backwards permutation of array elements. -- --
-- bpermute [50, 60, 20, 30] [0, 3, 2] = [50, 30, 20] --bpermute :: Elt a => Array a -> Array Int -> Array a -- | Combination of map and bpermute. -- -- The advantage of using this combined version is that we don't need to -- apply the parameter function to source elements that don't appear in -- the result. mbpermute :: (Elt a, Elt b) => (a -> b) -> Array a -> Array Int -> Array b -- | Default backwards permutation. -- -- The values of the index-value pairs are written into the position in -- the result array that is indicated by the corresponding index. -- -- All positions not covered by the index-value pairs will have the value -- determined by the initialiser function for that index position. bpermuteDft :: Elt e => Int -> (Int -> e) -> Array (Int, e) -> Array e -- | O(1). Zip two arrays into an array of pairs. If one array is short, -- excess elements of the longer array are discarded. zip :: (Elt a, Elt b) => Array a -> Array b -> Array (a, b) -- | O(1). Zip three arrays into an array of triples. If one array is -- short, excess elements of the longer arrays are discarded. zip3 :: (Elt a, Elt b, Elt c) => Array a -> Array b -> Array c -> Array (a, b, c) -- | O(1). Unzip an array of pairs into a pair of arrays. unzip :: (Elt a, Elt b) => Array (a, b) -> (Array a, Array b) -- | O(1). Unzip an array of triples into a triple of arrays. unzip3 :: (Elt a, Elt b, Elt c) => Array (a, b, c) -> (Array a, Array b, Array c) -- | O(1). Take the first elements of an array of pairs. fsts :: (Elt a, Elt b) => Array (a, b) -> Array a -- | O(1). Take the second elements of an array of pairs. snds :: (Elt a, Elt b) => Array (a, b) -> Array b -- | Apply a worker function to each element of an array, yielding a new -- array. map :: (Elt a, Elt b) => (a -> b) -> Array a -> Array b -- | Apply a worker function to correponding elements of two arrays. zipWith :: (Elt a, Elt b, Elt c) => (a -> b -> c) -> Array a -> Array b -> Array c -- | Apply a worker function to corresponding elements of three arrays. zipWith3 :: (Elt a, Elt b, Elt c, Elt d) => (a -> b -> c -> d) -> Array a -> Array b -> Array c -> Array d -- | Apply a worker function to corresponding elements of four arrays. zipWith4 :: (Elt a, Elt b, Elt c, Elt d, Elt e) => (a -> b -> c -> d -> e) -> Array a -> Array b -> Array c -> Array d -> Array e -- | Apply a worker function to corresponding elements of five arrays. zipWith5 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f) => (a -> b -> c -> d -> e -> f) -> Array a -> Array b -> Array c -> Array d -> Array e -> Array f -- | Apply a worker function to corresponding elements of six arrays. zipWith6 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g) => (a -> b -> c -> d -> e -> f -> g) -> Array a -> Array b -> Array c -> Array d -> Array e -> Array f -> Array g -- | Apply a worker function to corresponding elements of seven arrays. zipWith7 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h) => (a -> b -> c -> d -> e -> f -> g -> h) -> Array a -> Array b -> Array c -> Array d -> Array e -> Array f -> Array g -> Array h -- | Apply a worker function to corresponding elements of six arrays. zipWith8 :: (Elt a, Elt b, Elt c, Elt d, Elt e, Elt f, Elt g, Elt h, Elt i) => (a -> b -> c -> d -> e -> f -> g -> h -> i) -> Array a -> Array b -> Array c -> Array d -> Array e -> Array f -> Array g -> Array h -> Array i -- | Similar to foldl but return an array of the intermediate -- states, including the final state that is computed by foldl. scan :: Elt a => (a -> a -> a) -> a -> Array a -> Array a -- | Undirected fold over an array. -- --
-- packByTag [12, 24, 42, 93] [1, 0, 0, 1] 0 = [24, 42] --packByTag :: Elt a => Array a -> Array Tag -> Tag -> Array a -- | Extract the elements from an array that match the given predicate. filter :: Elt a => (a -> Bool) -> Array a -> Array a -- | Compute an array of flags indicating which elements match a given -- value. -- --
-- pick [4, 5, 3, 6, 5, 2, 5] 5 = [F, T, F, F, T, F, T] --pick :: (Elt a, Eq a) => Array a -> a -> Array Bool -- | Combine two arrays, using a flags array to tell us where to get each -- element from. -- --
-- combine [T, F, F, T, T, F] [1, 2, 3] [4, 5, 6] = [1, 4, 5, 2, 3, 6] --combine :: Elt a => Array Bool -> Array a -> Array a -> Array a -- | Like combine, but use a precomputed selector to speed up the -- process. -- -- See the description of mkSel2 for how this works. combine2 :: Elt a => Array Tag -> SelRep2 -> Array a -> Array a -> Array a -- | Interleave the elements of two arrays. -- --
-- interleave [1, 2, 3] [4, 5, 6] = [1, 4, 2, 5, 3, 6] --interleave :: Elt a => Array a -> Array a -> Array a data Sel2 -- | O(1). Construct a selector. -- -- A selector is a description of how to perform a combine -- operation. -- -- Suppose we are evaluating the following expression: -- --
-- combine [F,F,T,F,T,T] [1,2,3] [4,5,6] = [4,5,1,6,2,3] ---- -- This is difficult to parallelise. For each element in the result, the -- source array we get this element from depends on the tag values -- associated with all previous elements. -- -- However, if we going to apply combine several times with the -- same flags array, we can precompute a selector that tells us where to -- get each element. The selector contains the original flags, as well as -- the source index telling us where to get each element for the result -- array. -- -- For example: -- --
-- tagsToIndices2 [F,F,T,F,T,T] -- tags -- = [0,1,0,2,1,2] -- indices ---- -- This says get the first element from index 0 in the second array, then -- from index 1 in the second array, then index 0 in the first array ... -- -- The selector then consists of both the tag and -- indices arrays. mkSel2 :: Array Tag -> Array Int -> Int -> Int -> SelRep2 -> Sel2 -- | O(1). Yield the tags array of a selector. tagsSel2 :: Sel2 -> Array Tag -- | O(1). Yield the indices array of a selector. indicesSel2 :: Sel2 -> Array Int -- | O(1). Yield the number of elements that will be taken from the first -- array. elementsSel2_0 :: Sel2 -> Int -- | O(1). Yield the number of elements that will be taken from the second -- array. elementsSel2_1 :: Sel2 -> Int -- | O(1). Yield the parallel representation of a selector. repSel2 :: Sel2 -> SelRep2 -- | O(n). Compute a selector from a tags array. tagsToSel2 :: Array Tag -> Sel2 type SelRep2 = () -- | O(n). Construct a parallel selector representation. -- -- A SelRep2 describes how to distribute the two data vectors -- corresponding to a Sel2 across several PEs. -- -- Suppose we want to perform the following combine operation: -- --
-- combine [F,F,T,T,F,T,F,F,T] [A0,A1,A2,A3,A4] [B0,B1,B2,B3] -- = [A0,A1,B0,B1,A2,B2,A3,A4,B3] ---- -- The first array is the flags array, that says which of the data arrays -- to get each successive element from. As combine is difficult to -- compute in parallel, if we are going to perform several combines with -- the same flags array, we can precompute a selector that tells us where -- to get each element. The selector contains the original flags, as well -- as the source index telling us where to get each element for the -- result array. -- --
-- flags: [F,F,T,T,F,T,F,F,T] -- indices: [0,1,0,1,2,2,3,4,3] ---- -- Suppose we want to distribute the combine operation across 3 PEs. It's -- easy to split the selector like so: -- --
-- PE0 PE1 PE2 -- flags: [F,F,T] [T,F,T] [F,F,T] -- indices: [0,1,0] [1,2,2] [3,4,3] ---- -- We now need to split the two data arrays. Each PE needs slices of the -- data arrays that correspond to the parts of the selector that were -- given to it. For the current example we get: -- --
-- PE0 PE1 PE2 -- data_A: [A0,A1] [A2] [A3,A4] -- data_B: [B0] [B1,B2] [B3] ---- -- The SelRep2 contains the starting index and length of each of -- of these slices: -- --
-- PE0 PE1 PE2 -- ((0, 0), (2, 1)) ((2, 1), (1, 2)) ((3, 3), (2, 1)) -- indices lens indices lens indices lens --mkSelRep2 :: Array Tag -> SelRep2 -- | O(1). Take the indices field from a SelRep2. indicesSelRep2 :: Array Tag -> SelRep2 -> Array Int -- | O(1). Yield the number of elements to take from the first array. elementsSelRep2_0 :: Array Tag -> SelRep2 -> Int -- | O(1). Yield the number of elements to take from the second array. elementsSelRep2_1 :: Array Tag -> SelRep2 -> Int data Segd -- | O(max(segs, threads) . log segs). Construct a segment descriptor. -- -- A segment desciptor defines an irregular 2D array based on a flat, 1D -- array of elements. The defined array is a nested array of segments, -- where every segment covers some of the elements from the flat array. -- --
-- flat array data: [1 2 3 4 5 6 7 8] -- (segmentation) --- ----- - --- -- segd lengths: [2, 3, 1, 2] -- indices: [0, 2, 5, 6] -- elements: 8 --mkSegd :: Array Int -> Array Int -> Int -> Segd -- | Check whether a Segd is well formed. validSegd :: Segd -> Bool -- | O(1). Construct an empty Segd. emptySegd :: Segd -- | O(1). Construct a Segd containing a single segment of the given -- length. singletonSegd :: Int -> Segd -- | O(max(segs, threads) . log segs). Construct a Segd from an -- array of segment lengths. lengthsToSegd :: Array Int -> Segd -- | O(1). Yield the length of a Segd. lengthSegd :: Segd -> Int -- | O(1). Yield the segment lengths of a Segd. lengthsSegd :: Segd -> Array Int -- | O(1). Yield the segment starting indices of a Segd. indicesSegd :: Segd -> Array Int -- | O(1). Yield the total number of elements defined by a Segd. elementsSegd :: Segd -> Int -- | O(max(segs, threads) . log segs). Add the lengths of corresponding -- segments in two descriptors. -- --
-- plusSegd [lens: 2 3 1] [lens: 3 1 1] = [lens: 5 4 2] --plusSegd :: Segd -> Segd -> Segd data SSegd -- | Construct a Scattered Segment Descriptor. -- -- A SSegd is an extension of a Segd that that allows the -- segments to be scattered through multiple flat arrays. -- -- Each segment is associated with a source id that indicates what flat -- array it is in, along with the starting index in that flat array. -- --