1 {-# LANGUAGE CPP #-}
2 #include "fusion-phases.h"
4 module Data.Array.Parallel.Unlifted.Sequential.Locked
5 ( lockedZipSU, lockedZipWithSU
6 , lockedZip3SU, lockedZipWith3SU
7 , lockedZip4SU, lockedZipWith4SU
8 , lockedZip5SU, lockedZipWith5SU
9 , lockedZip6SU, lockedZipWith6SU
10 , lockedZip7SU, lockedZipWith7SU
11 , lockedZip8SU, lockedZipWith8SU)
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 lockedZipSU
21 :: ( Vector v a, Vector v b
22 , Vector v (a, b))
23 => v a -> v b
24 -> v (a, b)
26 lockedZipSU aa bb
27 = unstream \$ stream2 aa bb
28 {-# INLINE_U lockedZipSU #-}
31 -- | Zip three vectors of the same length.
32 lockedZip3SU
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 lockedZip3SU aa bb cc
39 = unstream \$ stream3 aa bb cc
40 {-# INLINE_U lockedZip3SU #-}
43 -- | Zip four vectors of the same length.
44 lockedZip4SU
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 lockedZip4SU aa bb cc dd
51 = unstream \$ stream4 aa bb cc dd
52 {-# INLINE_U lockedZip4SU #-}
55 -- | Zip five vectors of the same length.
56 lockedZip5SU
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 lockedZip5SU aa bb cc dd ee
64 = unstream \$ stream5 aa bb cc dd ee
65 {-# INLINE_U lockedZip5SU #-}
68 -- | Zip six vectors of the same length.
69 lockedZip6SU
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 lockedZip6SU aa bb cc dd ee ff
77 = unstream \$ stream6 aa bb cc dd ee ff
78 {-# INLINE_U lockedZip6SU #-}
81 -- | Zip seven vectors of the same length.
82 lockedZip7SU
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 lockedZip7SU aa bb cc dd ee ff gg
90 = unstream \$ stream7 aa bb cc dd ee ff gg
91 {-# INLINE_U lockedZip7SU #-}
94 -- | Zip eight vectors of the same length.
95 lockedZip8SU
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 lockedZip8SU aa bb cc dd ee ff gg hh
103 = unstream \$ stream8 aa bb cc dd ee ff gg hh
104 {-# INLINE_U lockedZip8SU #-}
107 -- Locked ZipWiths ------------------------------------------------------------
108 lockedZipWithSU
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 lockedZipWithSU f aa bb
115 = G.map (\(a, b) -> f a b)
116 \$ lockedZipSU aa bb
117 {-# INLINE lockedZipWithSU #-}
120 lockedZipWith3SU
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 lockedZipWith3SU f aa bb cc
127 = G.map (\(a, b, c) -> f a b c)
128 \$ lockedZip3SU aa bb cc
129 {-# INLINE lockedZipWith3SU #-}
132 lockedZipWith4SU
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 lockedZipWith4SU f aa bb cc dd
140 = G.map (\(a, b, c, d) -> f a b c d)
141 \$ lockedZip4SU aa bb cc dd
142 {-# INLINE lockedZipWith4SU #-}
145 lockedZipWith5SU
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 lockedZipWith5SU f aa bb cc dd ee
153 = G.map (\(a, b, c, d, e) -> f a b c d e)
154 \$ lockedZip5SU aa bb cc dd ee
155 {-# INLINE lockedZipWith5SU #-}
158 lockedZipWith6SU
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 lockedZipWith6SU fn aa bb cc dd ee ff
166 = G.map (\(a, b, c, d, e, f) -> fn a b c d e f)
167 \$ lockedZip6SU aa bb cc dd ee ff
168 {-# INLINE lockedZipWith6SU #-}
171 lockedZipWith7SU
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 lockedZipWith7SU 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 \$ unstream \$ stream7 aa bb cc dd ee ff gg
181 {-# INLINE lockedZipWith7SU #-}
184 lockedZipWith8SU
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 lockedZipWith8SU 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 \$ lockedZip8SU aa bb cc dd ee ff gg hh
195 {-# INLINE lockedZipWith8SU #-}