a2978662264fc41f35588a8829a5d2cb9c0b4964
[packages/dph.git] / dph-prim-seq / Data / Array / Parallel / Unlifted / Sequential / Extracts.hs
1 {-# LANGUAGE CPP #-}
2 #include "fusion-phases.h"
3
4 -- | Standard combinators for segmented unlifted arrays.
5 module Data.Array.Parallel.Unlifted.Sequential.Extracts
6 ( -- * Scattered indexing.
7 indexsFromVectorsUVSegd
8
9 -- * Scattered extracts
10 , extractsFromNestedUSSegd
11 , extractsFromVectorsUSSegd
12 , extractsFromVectorsUVSegd)
13 where
14 import Data.Array.Parallel.Unlifted.Stream as US
15 import Data.Array.Parallel.Unlifted.Vectors as US
16 import Data.Array.Parallel.Unlifted.Sequential.Vector as U
17 import Data.Array.Parallel.Unlifted.Sequential.USSegd (USSegd)
18 import Data.Array.Parallel.Unlifted.Sequential.UVSegd (UVSegd)
19 import qualified Data.Array.Parallel.Unlifted.Sequential.UVSegd as UVSegd
20 import qualified Data.Vector as V
21
22
23 -- Indexs --------------------------------------------------------------------
24 -- | Lookup elements from some `Vectors` through a `UPVSegd`.
25 indexsFromVectorsUVSegd
26 :: (Unbox a, US.Unboxes a)
27 => Vectors a -> UVSegd -> Vector (Int, Int) -> Vector a
28
29 indexsFromVectorsUVSegd vectors uvsegd vsrcixs
30 = let -- Because we're just doing indexing here, we don't need the culled
31 -- vsegids or ussegd, and can just use the redundant version.
32 !vsegids = UVSegd.takeVSegidsRedundant uvsegd
33 !ussegd = UVSegd.takeUSSegdRedundant uvsegd
34 in U.unstream
35 $ US.streamElemsFromVectors vectors
36 $ US.streamSrcIxsThroughUSSegd ussegd
37 $ US.streamSrcIxsThroughVSegids vsegids
38 $ U.stream vsrcixs
39 {-# INLINE_U indexsFromVectorsUVSegd #-}
40
41
42 -- Extracts wrappers ---------------------------------------------------------
43 -- | Copy segments from a `Vectors`, concatenating them into a new array.
44 extractsFromNestedUSSegd
45 :: (U.Unbox a)
46 => USSegd -> V.Vector (Vector a) -> U.Vector a
47
48 extractsFromNestedUSSegd ussegd vectors
49 = U.unstream $ streamSegsFromNestedUSSegd vectors ussegd
50 {-# INLINE_U extractsFromNestedUSSegd #-}
51
52
53 -- | Copy segments from a `Vectors`, concatenating them into a new array.
54 extractsFromVectorsUSSegd
55 :: (Unboxes a, U.Unbox a)
56 => USSegd -> Vectors a -> U.Vector a
57
58 extractsFromVectorsUSSegd ussegd vectors
59 = U.unstream $ streamSegsFromVectorsUSSegd vectors ussegd
60 {-# INLINE_U extractsFromVectorsUSSegd #-}
61
62
63 -- | Copy segments from a `Vectors`, concatenating them into a new array.
64 extractsFromVectorsUVSegd
65 :: (Unbox a, US.Unboxes a)
66 => UVSegd
67 -> Vectors a
68 -> Vector a
69
70 extractsFromVectorsUVSegd uvsegd vectors
71 = U.unstream $ US.streamSegsFromVectorsUVSegd vectors uvsegd
72 {-# INLINE_U extractsFromVectorsUVSegd #-}