2e51001ef29255f434b689866257cd8cb142c993
1 {-# LANGUAGE CPP #-}
2 #include "fusion-phases.h"
4 module Data.Array.Parallel.Unlifted.Sequential.Locked
5 ( lockedZip, lockedZipWith
6 , lockedZip3, lockedZipWith3
7 , lockedZip4, lockedZipWith4
8 , lockedZip5, lockedZipWith5
9 , lockedZip6, lockedZipWith6
10 , lockedZip7, lockedZipWith7
11 , lockedZip8, lockedZipWith8)
12 where
13 import Data.Array.Parallel.Unlifted.Stream.Locked
14 import Data.Vector.Generic as G
17 -- Locked Zips ----------------------------------------------------------------
18 -- | Zip two vectors of the same length.
19 -- If they do not have the same length then the result is undefined.
20 lockedZip
21 :: ( Vector v a, Vector v b
22 , Vector v (a, b))
23 => v a -> v b
24 -> v (a, b)
26 lockedZip aa bb
27 = unstream \$ stream2 aa bb
28 {-# INLINE_U lockedZip #-}
31 -- | Zip three vectors of the same length.
32 lockedZip3
33 :: ( Vector v a, Vector v b, Vector v c
34 , Vector v (a, b, c))
35 => v a -> v b -> v c
36 -> v (a, b, c)
38 lockedZip3 aa bb cc
39 = unstream \$ stream3 aa bb cc
40 {-# INLINE_U lockedZip3 #-}
43 -- | Zip four vectors of the same length.
44 lockedZip4
45 :: ( Vector v a, Vector v b, Vector v c, Vector v d
46 , Vector v (a, b, c, d))
47 => v a -> v b -> v c -> v d
48 -> v (a, b, c, d)
50 lockedZip4 aa bb cc dd
51 = unstream \$ stream4 aa bb cc dd
52 {-# INLINE_U lockedZip4 #-}
55 -- | Zip five vectors of the same length.
56 lockedZip5
57 :: ( Vector v a, Vector v b, Vector v c, Vector v d
58 , Vector v e
59 , Vector v (a, b, c, d, e))
60 => v a -> v b -> v c -> v d -> v e
61 -> v (a, b, c, d, e)
63 lockedZip5 aa bb cc dd ee
64 = unstream \$ stream5 aa bb cc dd ee
65 {-# INLINE_U lockedZip5 #-}
68 -- | Zip six vectors of the same length.
69 lockedZip6
70 :: ( Vector v a, Vector v b, Vector v c, Vector v d
71 , Vector v e, Vector v f
72 , Vector v (a, b, c, d, e, f))
73 => v a -> v b -> v c -> v d -> v e -> v f
74 -> v (a, b, c, d, e, f)
76 lockedZip6 aa bb cc dd ee ff
77 = unstream \$ stream6 aa bb cc dd ee ff
78 {-# INLINE_U lockedZip6 #-}
81 -- | Zip seven vectors of the same length.
82 lockedZip7
83 :: ( Vector v a, Vector v b, Vector v c, Vector v d
84 , Vector v e, Vector v f, Vector v g
85 , Vector v (a, b, c, d, e, f, g))
86 => v a -> v b -> v c -> v d -> v e -> v f -> v g
87 -> v (a, b, c, d, e, f, g)
89 lockedZip7 aa bb cc dd ee ff gg
90 = unstream \$ stream7 aa bb cc dd ee ff gg
91 {-# INLINE_U lockedZip7 #-}
94 -- | Zip eight vectors of the same length.
95 lockedZip8
96 :: ( Vector v a, Vector v b, Vector v c, Vector v d
97 , Vector v e, Vector v f, Vector v g, Vector v h
98 , Vector v (a, b, c, d, e, f, g, h))
99 => v a -> v b -> v c -> v d -> v e -> v f -> v g -> v h
100 -> v (a, b, c, d, e, f, g, h)
102 lockedZip8 aa bb cc dd ee ff gg hh
103 = unstream \$ stream8 aa bb cc dd ee ff gg hh
104 {-# INLINE_U lockedZip8 #-}
107 -- Locked ZipWiths ------------------------------------------------------------
108 lockedZipWith
109 :: ( Vector v a, Vector v b, Vector v c
110 , Vector v (a, b))
111 => (a -> b -> c)
112 -> v a -> v b -> v c
114 lockedZipWith f aa bb
115 = G.map (\(a, b) -> f a b)
116 \$ lockedZip aa bb
117 {-# INLINE lockedZipWith #-}
120 lockedZipWith3
121 :: ( Vector v a, Vector v b, Vector v c, Vector v d
122 , Vector v (a, b, c))
123 => (a -> b -> c -> d)
124 -> v a -> v b -> v c -> v d
126 lockedZipWith3 f aa bb cc
127 = G.map (\(a, b, c) -> f a b c)
128 \$ lockedZip3 aa bb cc
129 {-# INLINE lockedZipWith3 #-}
132 lockedZipWith4
133 :: ( Vector v a, Vector v b, Vector v c, Vector v d
134 , Vector v e
135 , Vector v (a, b, c, d))
136 => (a -> b -> c -> d -> e)
137 -> v a -> v b -> v c -> v d -> v e
139 lockedZipWith4 f aa bb cc dd
140 = G.map (\(a, b, c, d) -> f a b c d)
141 \$ lockedZip4 aa bb cc dd
142 {-# INLINE lockedZipWith4 #-}
145 lockedZipWith5
146 :: ( Vector v a, Vector v b, Vector v c, Vector v d
147 , Vector v e, Vector v f
148 , Vector v (a, b, c, d, e))
149 => (a -> b -> c -> d -> e -> f)
150 -> v a -> v b -> v c -> v d -> v e -> v f
152 lockedZipWith5 f aa bb cc dd ee
153 = G.map (\(a, b, c, d, e) -> f a b c d e)
154 \$ lockedZip5 aa bb cc dd ee
155 {-# INLINE lockedZipWith5 #-}
158 lockedZipWith6
159 :: ( Vector v a, Vector v b, Vector v c, Vector v d
160 , Vector v e, Vector v f, Vector v g
161 , Vector v (a, b, c, d, e, f))
162 => (a -> b -> c -> d -> e -> f -> g)
163 -> v a -> v b -> v c -> v d -> v e -> v f -> v g
165 lockedZipWith6 fn aa bb cc dd ee ff
166 = G.map (\(a, b, c, d, e, f) -> fn a b c d e f)
167 \$ lockedZip6 aa bb cc dd ee ff
168 {-# INLINE lockedZipWith6 #-}
171 lockedZipWith7
172 :: ( Vector v a, Vector v b, Vector v c, Vector v d
173 , Vector v e, Vector v f, Vector v g, Vector v h
174 , Vector v (a, b, c, d, e, f, g))
175 => (a -> b -> c -> d -> e -> f -> g -> h)
176 -> v a -> v b -> v c -> v d -> v e -> v f -> v g -> v h
178 lockedZipWith7 fn aa bb cc dd ee ff gg
179 = G.map (\(a, b, c, d, e, f, g) -> fn a b c d e f g)
180 \$ lockedZip7 aa bb cc dd ee ff gg
181 {-# INLINE lockedZipWith7 #-}
184 lockedZipWith8
185 :: ( Vector v a, Vector v b, Vector v c, Vector v d
186 , Vector v e, Vector v f, Vector v g, Vector v h
187 , Vector v i
188 , Vector v (a, b, c, d, e, f, g, h))
189 => (a -> b -> c -> d -> e -> f -> g -> h -> i)
190 -> v a -> v b -> v c -> v d -> v e -> v f -> v g -> v h -> v i
192 lockedZipWith8 fn aa bb cc dd ee ff gg hh
193 = G.map (\(a, b, c, d, e, f, g, h) -> fn a b c d e f g h)
194 \$ lockedZip8 aa bb cc dd ee ff gg hh
195 {-# INLINE lockedZipWith8 #-}