Separate length from data in array representation
[packages/dph.git] / dph-common / Data / Array / Parallel / Lifted / Repr.hs
1 {-# LANGUAGE EmptyDataDecls #-}
2 {-# LANGUAGE CPP #-}
3
4 #include "fusion-phases.h"
5
6 module Data.Array.Parallel.Lifted.Repr (
7 PData(..),
8 Void, void, pvoid, dPA_Void, dPR_Void,
9 {-
10 Wrap(..),
11 Sum2(..), Sum3(..),
12 -}
13
14 punit, dPR_Unit,
15 Wrap(..), dPR_Wrap,
16
17 dPR_2, dPR_3, dPR_4, dPR_5, zipPA#, unzipPA#, zip3PA#,
18 Sum2(..), {-Sum3(..),-} dPR_Sum2, {-dPR_Sum3,-}
19
20 dPR_PArray, segdPA#, concatPA#, segmentPA#, copySegdPA#
21 ) where
22
23 import Data.Array.Parallel.Lifted.PArray
24 import Data.Array.Parallel.Lifted.Selector
25 import Data.Array.Parallel.Lifted.Unboxed ( elementsSegd# )
26
27 import qualified Data.Array.Parallel.Unlifted as U
28 import Data.Array.Parallel.Base ((:*:)(..), fromBool)
29
30 import qualified Data.List as L
31 import GHC.Exts (Int#, Int(..), (+#), (-#), (*#))
32 import Debug.Trace
33
34
35 data Void
36
37 traceFn = flip const -- trace
38 traceArgs = flip const -- trace
39
40 void :: Void
41 void = error "Data.Array.Parallel.void"
42
43 data instance PData Void
44
45 pvoid :: PData Void
46 pvoid = error "Data.Array.Parallel.PData Void"
47
48 dPR_Void :: PR Void
49 {-# INLINE dPR_Void #-}
50 dPR_Void = PR {
51 emptyPR = emptyPR_Void
52 , replicatePR = replicatePR_Void
53 , replicatelPR = replicatelPR_Void
54 , repeatPR = repeatPR_Void
55 , repeatcPR = repeatcPR_Void
56 , indexPR = indexPR_Void
57 , extractPR = extractPR_Void
58 , bpermutePR = bpermutePR_Void
59 , appPR = appPR_Void
60 , applPR = applPR_Void
61 , packPR = packPR_Void
62 , combine2PR = combine2PR_Void
63 , fromListPR = fromListPR_Void
64 , nfPR = nfPR_Void
65 }
66
67 emptyPR_Void :: T_emptyPR Void
68 {-# INLINE emptyPR_Void #-}
69 emptyPR_Void = traceFn "emptyPR_Void" $ pvoid
70
71 replicatePR_Void :: T_replicatePR Void
72 {-# INLINE replicatePR_Void #-}
73 replicatePR_Void _ _ = traceFn "replicatePR_Void" $ pvoid
74
75 replicatelPR_Void :: T_replicatelPR Void
76 {-# INLINE replicatelPR_Void #-}
77 replicatelPR_Void segd _ = traceFn "replicatelPR_Void" $ pvoid
78
79 repeatPR_Void :: T_repeatPR Void
80 {-# INLINE repeatPR_Void #-}
81 repeatPR_Void _ _ _ = traceFn "repeatPR_Void" $ pvoid
82
83 repeatcPR_Void :: T_repeatcPR Void
84 {-# INLINE repeatcPR_Void #-}
85 repeatcPR_Void _ _ _ _ = traceFn "repeatcPR_Void" $ pvoid
86
87 indexPR_Void :: T_indexPR Void
88 {-# INLINE indexPR_Void #-}
89 indexPR_Void _ _ = traceFn "indexPR_Void" $ void
90
91 extractPR_Void :: T_extractPR Void
92 {-# INLINE extractPR_Void #-}
93 extractPR_Void _ _ _ = traceFn "extractPR_Void" $ pvoid
94
95 bpermutePR_Void :: T_bpermutePR Void
96 {-# INLINE bpermutePR_Void #-}
97 bpermutePR_Void _ _ _ = traceFn "bpermutePR_Void" $ pvoid
98
99 appPR_Void :: T_appPR Void
100 {-# INLINE appPR_Void #-}
101 appPR_Void _ _ = traceFn "appPR_Void" $ pvoid
102
103 applPR_Void :: T_applPR Void
104 {-# INLINE applPR_Void #-}
105 applPR_Void _ _ _ _ = traceFn "applPR_Void" $ pvoid
106
107 packPR_Void :: T_packPR Void
108 {-# INLINE packPR_Void #-}
109 packPR_Void _ _ _ = traceFn "packPR_Void" $ pvoid
110
111 combine2PR_Void :: T_combine2PR Void
112 {-# INLINE combine2PR_Void #-}
113 combine2PR_Void _ _ _ _ = traceFn "combine2PR_Void" $ pvoid
114
115 fromListPR_Void :: T_fromListPR Void
116 {-# INLINE fromListPR_Void #-}
117 fromListPR_Void _ _ = pvoid
118
119 nfPR_Void :: T_nfPR Void
120 {-# INLINE nfPR_Void #-}
121 nfPR_Void _ = ()
122
123 type instance PRepr Void = Void
124
125 dPA_Void :: PA Void
126 {-# INLINE_PA dPA_Void #-}
127 dPA_Void = PA {
128 toPRepr = id
129 , fromPRepr = id
130 , toArrPRepr = id
131 , fromArrPRepr = id
132 , dictPRepr = dPR_Void
133 }
134
135
136
137 data instance PData () = PUnit
138
139 punit :: PData ()
140 punit = PUnit
141
142 dPR_Unit :: PR ()
143 {-# INLINE dPR_Unit #-}
144 dPR_Unit = PR {
145 emptyPR = emptyPR_Unit
146 , replicatePR = replicatePR_Unit
147 , replicatelPR = replicatelPR_Unit
148 , repeatPR = repeatPR_Unit
149 , repeatcPR = repeatcPR_Unit
150 , indexPR = indexPR_Unit
151 , extractPR = extractPR_Unit
152 , bpermutePR = bpermutePR_Unit
153 , appPR = appPR_Unit
154 , applPR = applPR_Unit
155 , packPR = packPR_Unit
156 , combine2PR = combine2PR_Unit
157 , fromListPR = fromListPR_Unit
158 , nfPR = nfPR_Unit
159 }
160
161 emptyPR_Unit :: T_emptyPR ()
162 {-# INLINE emptyPR_Unit #-}
163 emptyPR_Unit = traceFn "emptyPR_Unit" $ PUnit
164
165 replicatePR_Unit :: T_replicatePR ()
166 {-# INLINE replicatePR_Unit #-}
167 replicatePR_Unit n# () =
168 traceFn "replicatePR_Unit" $
169 traceArgs ("replicatePR_Unit len = " ++ show (I# n#)) $
170 PUnit
171
172 replicatelPR_Unit :: T_replicatelPR ()
173 {-# INLINE replicatelPR_Unit #-}
174 replicatelPR_Unit segd u =
175 traceFn "replicatelPR_Unit"
176 traceArgs ("replicatelPR_Unit args len = " ++ (show (U.elementsSegd segd))) $
177 u
178
179 repeatPR_Unit :: T_repeatPR ()
180 {-# INLINE repeatPR_Unit #-}
181 repeatPR_Unit _ _ u = traceFn "repeatPR_Unit" $ u
182
183 repeatcPR_Unit :: T_repeatcPR ()
184 {-# INLINE repeatcPR_Unit #-}
185 repeatcPR_Unit _ _ _ u = traceFn "repeatcPR_Unit" $ u
186
187 indexPR_Unit :: T_indexPR ()
188 {-# INLINE indexPR_Unit #-}
189 indexPR_Unit PUnit _ = traceFn "indexPR_Unit" $ ()
190
191 extractPR_Unit :: T_extractPR ()
192 {-# INLINE extractPR_Unit #-}
193 extractPR_Unit u _ _ = traceFn "extractPR_Unit" $ u
194
195 bpermutePR_Unit :: T_bpermutePR ()
196 {-# INLINE bpermutePR_Unit #-}
197 bpermutePR_Unit u _ _ = traceFn "bpermutePR_Unit" $ u
198
199 appPR_Unit :: T_appPR ()
200 {-# INLINE appPR_Unit #-}
201 appPR_Unit u v = traceFn "appPR_Unit" (u `seq` v)
202
203 applPR_Unit :: T_applPR ()
204 {-# INLINE applPR_Unit #-}
205 applPR_Unit _ u _ v = traceFn "applPR_Unit" (u `seq` v)
206
207 packPR_Unit :: T_packPR ()
208 {-# INLINE packPR_Unit #-}
209 packPR_Unit u _ _ = traceFn "packPR_Unit" $ u
210
211 combine2PR_Unit :: T_combine2PR ()
212 {-# INLINE combine2PR_Unit #-}
213 combine2PR_Unit _ _ u v = traceFn "combine2PR_Unit" (u `seq` v)
214
215 fromListPR_Unit :: T_fromListPR ()
216 {-# INLINE fromListPR_Unit #-}
217 fromListPR_Unit _ xs = foldr seq PUnit xs
218
219 {-# INLINE nfPR_Unit #-}
220 nfPR_Unit PUnit = ()
221
222 data Wrap a = Wrap a
223
224 data instance PData (Wrap a) = PWrap (PData a)
225
226 dPR_Wrap :: PR a -> PR (Wrap a)
227 {-# INLINE dPR_Wrap #-}
228 dPR_Wrap pr = PR {
229 emptyPR = emptyPR_Wrap pr
230 , replicatePR = replicatePR_Wrap pr
231 , replicatelPR = replicatelPR_Wrap pr
232 , repeatPR = repeatPR_Wrap pr
233 , repeatcPR = repeatcPR_Wrap pr
234 , indexPR = indexPR_Wrap pr
235 , extractPR = extractPR_Wrap pr
236 , bpermutePR = bpermutePR_Wrap pr
237 , appPR = appPR_Wrap pr
238 , applPR = applPR_Wrap pr
239 , packPR = packPR_Wrap pr
240 }
241
242 {-# INLINE emptyPR_Wrap #-}
243 emptyPR_Wrap pr = traceFn "emptyPR_Wrap" $ PWrap (emptyPR pr)
244
245 {-# INLINE replicatePR_Wrap #-}
246 replicatePR_Wrap pr n# (Wrap x) = traceFn "replicatePR_Wrap" $
247 PWrap (replicatePR pr n# x)
248
249 {-# INLINE replicatelPR_Wrap #-}
250 replicatelPR_Wrap pr segd (PWrap xs) = traceFn "replicatelPR_Wrap" $
251 PWrap (replicatelPR pr segd xs)
252
253 {-# INLINE repeatPR_Wrap #-}
254 repeatPR_Wrap pr n# len# (PWrap xs) = traceFn "repeatPR_Wrap" $
255 PWrap (repeatPR pr n# len# xs)
256
257 {-# INLINE repeatcPR_Wrap #-}
258 repeatcPR_Wrap pr n# is segd (PWrap xs) = traceFn "repeatcPR_Wrap" $
259 PWrap (repeatcPR pr n# is segd xs)
260
261 {-# INLINE indexPR_Wrap #-}
262 indexPR_Wrap pr (PWrap xs) i# = traceFn "indexPR_Wrap" $
263 Wrap (indexPR pr xs i#)
264
265 {-# INLINE extractPR_Wrap #-}
266 extractPR_Wrap pr (PWrap xs) i# n# = traceFn "extractPR_Wrap" $
267 PWrap (extractPR pr xs i# n#)
268
269 {-# INLINE bpermutePR_Wrap #-}
270 bpermutePR_Wrap pr (PWrap xs) n# is = traceFn "bpermutePR_Wrap" $
271 PWrap (bpermutePR pr xs n# is)
272
273 {-# INLINE appPR_Wrap #-}
274 appPR_Wrap pr (PWrap xs) (PWrap ys) = traceFn "appPR_Wrap" $
275 PWrap (appPR pr xs ys)
276
277 {-# INLINE applPR_Wrap #-}
278 applPR_Wrap pr is (PWrap xs) js (PWrap ys) = traceFn "applPR_Wrap" $
279 PWrap (applPR pr is xs js ys)
280
281 {-# INLINE packPR_Wrap #-}
282 packPR_Wrap pr (PWrap xs) n# sel# = traceFn "packPR_Wrap" $
283 PWrap (packPR pr xs n# sel#)
284
285
286 data instance PData (a,b)
287 = P_2 (PData a)
288 (PData b)
289
290 data instance PData (a,b,c)
291 = P_3 (PData a)
292 (PData b)
293 (PData c)
294
295 data instance PData (a,b,c,d)
296 = P_4 (PData a)
297 (PData b)
298 (PData c)
299 (PData d)
300
301 data instance PData (a,b,c,d,e)
302 = P_5 (PData a)
303 (PData b)
304 (PData c)
305 (PData d)
306 (PData e)
307
308 dPR_2 :: PR a -> PR b -> PR (a,b)
309 {-# INLINE dPR_2 #-}
310 dPR_2 pra prb
311 = PR {
312 emptyPR = emptyPR_2 pra prb
313 , replicatePR = replicatePR_2 pra prb
314 , replicatelPR = replicatelPR_2 pra prb
315 , repeatPR = repeatPR_2 pra prb
316 , repeatcPR = repeatcPR_2 pra prb
317 , indexPR = indexPR_2 pra prb
318 , extractPR = extractPR_2 pra prb
319 , bpermutePR = bpermutePR_2 pra prb
320 , appPR = appPR_2 pra prb
321 , applPR = applPR_2 pra prb
322 , packPR = packPR_2 pra prb
323 , combine2PR = combine2PR_2 pra prb
324 , fromListPR = fromListPR_2 pra prb
325 , nfPR = nfPR_2 pra prb
326 }
327
328 {-# INLINE emptyPR_2 #-}
329 emptyPR_2 pra prb = traceFn "emptyPR_2" $
330 P_2 (emptyPR pra) (emptyPR prb)
331
332 {-# INLINE replicatePR_2 #-}
333 replicatePR_2 pra prb n# (a,b) =
334 traceFn "replicatePR_2" $
335 traceArgs ("replicatePR_2 args len = " ++ (show (I# n#))) $
336 P_2 (replicatePR pra n# a)
337 (replicatePR prb n# b)
338
339 {-# INLINE replicatelPR_2 #-}
340 replicatelPR_2 pra prb segd (P_2 as bs)
341 = traceFn "replicatelPR_2" $
342 P_2 (replicatelPR pra segd as)
343 (replicatelPR prb segd bs)
344
345 {-# INLINE repeatPR_2 #-}
346 repeatPR_2 pra prb n# len# (P_2 as bs)
347 = traceFn "repeatPR_2" $
348 P_2 (repeatPR pra n# len# as)
349 (repeatPR prb n# len# bs)
350
351 {-# INLINE repeatcPR_2 #-}
352 repeatcPR_2 pra prb n# ns segd (P_2 as bs)
353 = traceFn "repeatcPR_2" $
354 P_2 (repeatcPR pra n# ns segd as)
355 (repeatcPR prb n# ns segd bs)
356
357 {-# INLINE indexPR_2 #-}
358 indexPR_2 pra prb (P_2 as bs) i# = traceFn "indexPR_2" $
359 (indexPR pra as i#, indexPR prb bs i#)
360
361 {-# INLINE extractPR_2 #-}
362 extractPR_2 pra prb (P_2 as bs) i# n# = traceFn "extractPR_2" $
363 P_2 (extractPR pra as i# n#)
364 (extractPR prb bs i# n#)
365
366 {-# INLINE bpermutePR_2 #-}
367 bpermutePR_2 pra prb (P_2 as bs) n# is
368 = traceFn "bpermutePR_2" $
369 P_2 (bpermutePR pra as n# is) (bpermutePR prb bs n# is)
370
371 {-# INLINE appPR_2 #-}
372 appPR_2 pra prb (P_2 as1 bs1) (P_2 as2 bs2)
373 = P_2 (appPR pra as1 as2) (appPR prb bs1 bs2)
374
375 {-# INLINE applPR_2 #-}
376 applPR_2 pra prb is (P_2 as1 bs1) js (P_2 as2 bs2)
377 = traceFn "applPR_2" $
378 P_2 (applPR pra is as1 js as2)
379 (applPR prb is bs1 js bs2)
380
381 {-# INLINE packPR_2 #-}
382 packPR_2 pra prb (P_2 as bs) n# sel# = traceFn "packPR_2" $
383 P_2 (packPR pra as n# sel#)
384 (packPR prb bs n# sel#)
385
386 {-# INLINE combine2PR_2 #-}
387 combine2PR_2 pra prb n# sel (P_2 as1 bs1) (P_2 as2 bs2)
388 = traceFn "combine2PR_2" $
389 P_2 (combine2PR pra n# sel as1 as2)
390 (combine2PR prb n# sel bs1 bs2)
391
392 {-# INLINE fromListPR_2 #-}
393 fromListPR_2 pra prb n# xs
394 = P_2 (fromListPR pra n# as)
395 (fromListPR prb n# bs)
396 where
397 (as,bs) = unzip xs
398
399 {-# INLINE nfPR_2 #-}
400 nfPR_2 pra prb (P_2 as bs)
401 = nfPR pra as `seq` nfPR prb bs
402
403 zipPA# :: PArray a -> PArray b -> PArray (a,b)
404 {-# INLINE_PA zipPA# #-}
405 zipPA# (PArray n# xs) (PArray _ ys) = PArray n# (P_2 xs ys)
406
407 unzipPA# :: PArray (a,b) -> (PArray a, PArray b)
408 {-# INLINE_PA unzipPA# #-}
409 unzipPA# (PArray n# (P_2 xs ys)) = (PArray n# xs, PArray n# ys)
410
411 dPR_3 :: PR a -> PR b -> PR c -> PR (a,b,c)
412 {-# INLINE dPR_3 #-}
413 dPR_3 pra prb prc
414 = PR {
415 emptyPR = emptyPR_3 pra prb prc
416 , replicatePR = replicatePR_3 pra prb prc
417 , replicatelPR = replicatelPR_3 pra prb prc
418 , repeatPR = repeatPR_3 pra prb prc
419 , repeatcPR = repeatcPR_3 pra prb prc
420 , indexPR = indexPR_3 pra prb prc
421 , extractPR = extractPR_3 pra prb prc
422 , bpermutePR = bpermutePR_3 pra prb prc
423 , appPR = appPR_3 pra prb prc
424 , applPR = applPR_3 pra prb prc
425 , packPR = packPR_3 pra prb prc
426 , combine2PR = combine2PR_3 pra prb prc
427 , fromListPR = fromListPR_3 pra prb prc
428 , nfPR = nfPR_3 pra prb prc
429 }
430
431 {-# INLINE emptyPR_3 #-}
432 emptyPR_3 pra prb prc = traceFn "emptyPR_3" $
433 P_3 (emptyPR pra) (emptyPR prb) (emptyPR prc)
434
435 {-# INLINE replicatePR_3 #-}
436 replicatePR_3 pra prb prc n# (a,b,c)
437 = traceFn "replicatePR_3" $
438 P_3 (replicatePR pra n# a)
439 (replicatePR prb n# b)
440 (replicatePR prc n# c)
441
442 {-# INLINE replicatelPR_3 #-}
443 replicatelPR_3 pra prb prc segd (P_3 as bs cs)
444 = traceFn "replicatelPR_3" $
445 P_3 (replicatelPR pra segd as)
446 (replicatelPR prb segd bs)
447 (replicatelPR prc segd cs)
448
449 {-# INLINE repeatPR_3 #-}
450 repeatPR_3 pra prb prc n# len# (P_3 as bs cs)
451 = traceFn "repeatPR_3" $
452 P_3 (repeatPR pra n# len# as)
453 (repeatPR prb n# len# bs)
454 (repeatPR prc n# len# cs)
455
456 {-# INLINE repeatcPR_3 #-}
457 repeatcPR_3 pra prb prc n# ns segd (P_3 as bs cs)
458 = traceFn "repeatcPR_3" $
459 P_3 (repeatcPR pra n# ns segd as)
460 (repeatcPR prb n# ns segd bs)
461 (repeatcPR prc n# ns segd cs)
462
463 {-# INLINE indexPR_3 #-}
464 indexPR_3 pra prb prc (P_3 as bs cs) i#
465 = traceFn "indexPR_3" $
466 (indexPR pra as i#, indexPR prb bs i#, indexPR prc cs i#)
467
468 {-# INLINE extractPR_3 #-}
469 extractPR_3 pra prb prc (P_3 as bs cs) i# n# = traceFn "extractPR_3" $
470 P_3 (extractPR pra as i# n#)
471 (extractPR prb bs i# n#)
472 (extractPR prc cs i# n#)
473
474 {-# INLINE bpermutePR_3 #-}
475 bpermutePR_3 pra prb prc (P_3 as bs cs) n# is
476 = traceFn "bpermutePR_3" $
477 P_3 (bpermutePR pra as n# is)
478 (bpermutePR prb bs n# is)
479 (bpermutePR prc cs n# is)
480
481 {-# INLINE appPR_3 #-}
482 appPR_3 pra prb prc (P_3 as1 bs1 cs1) (P_3 as2 bs2 cs2)
483 = traceFn "appPR_3" $
484 P_3 (appPR pra as1 as2)
485 (appPR prb bs1 bs2)
486 (appPR prc cs1 cs2)
487
488 {-# INLINE applPR_3 #-}
489 applPR_3 pra prb prc is (P_3 as1 bs1 cs1) js (P_3 as2 bs2 cs2)
490 = traceFn "applPR_3" $
491 P_3 (applPR pra is as1 js as2)
492 (applPR prb is bs1 js bs2)
493 (applPR prc is cs1 js cs2)
494
495 {-# INLINE packPR_3 #-}
496 packPR_3 pra prb prc (P_3 as bs cs) n# sel#
497 = traceFn "packPR_3" $
498 P_3 (packPR pra as n# sel#)
499 (packPR prb bs n# sel#)
500 (packPR prc cs n# sel#)
501
502 {-# INLINE combine2PR_3 #-}
503 combine2PR_3 pra prb prc n# sel (P_3 as1 bs1 cs1)
504 (P_3 as2 bs2 cs2)
505 = traceFn "combine2PR_3" $
506 P_3 (combine2PR pra n# sel as1 as2)
507 (combine2PR prb n# sel bs1 bs2)
508 (combine2PR prc n# sel cs1 cs2)
509
510 {-# INLINE fromListPR_3 #-}
511 fromListPR_3 pra prb prc n# xs
512 = P_3 (fromListPR pra n# as)
513 (fromListPR prb n# bs)
514 (fromListPR prc n# cs)
515 where
516 (as,bs,cs) = unzip3 xs
517
518 {-# INLINE nfPR_3 #-}
519 nfPR_3 pra prb prc (P_3 as bs cs)
520 = nfPR pra as
521 `seq` nfPR prb bs
522 `seq` nfPR prc cs
523
524 zip3PA# :: PArray a -> PArray b -> PArray c -> PArray (a,b,c)
525 {-# INLINE_PA zip3PA# #-}
526 zip3PA# (PArray n# xs) (PArray _ ys) (PArray _ zs) = PArray n# (P_3 xs ys zs)
527
528 dPR_4 :: PR a -> PR b -> PR c -> PR d -> PR (a,b,c,d)
529 {-# INLINE dPR_4 #-}
530 dPR_4 pra prb prc prd
531 = PR {
532 emptyPR = emptyPR_4 pra prb prc prd
533 , replicatePR = replicatePR_4 pra prb prc prd
534 , replicatelPR = replicatelPR_4 pra prb prc prd
535 , repeatPR = repeatPR_4 pra prb prc prd
536 , repeatcPR = repeatcPR_4 pra prb prc prd
537 , indexPR = indexPR_4 pra prb prc prd
538 , extractPR = extractPR_4 pra prb prc prd
539 , bpermutePR = bpermutePR_4 pra prb prc prd
540 , appPR = appPR_4 pra prb prc prd
541 , applPR = applPR_4 pra prb prc prd
542 , packPR = packPR_4 pra prb prc prd
543 , combine2PR = combine2PR_4 pra prb prc prd
544 , fromListPR = fromListPR_4 pra prb prc prd
545 , nfPR = nfPR_4 pra prb prc prd
546 }
547
548 {-# INLINE emptyPR_4 #-}
549 emptyPR_4 pra prb prc prd = traceFn "emptyPR_4" $
550 P_4 (emptyPR pra)
551 (emptyPR prb)
552 (emptyPR prc)
553 (emptyPR prd)
554
555 {-# INLINE replicatePR_4 #-}
556 replicatePR_4 pra prb prc prd n# (a,b,c,d)
557 = traceFn "replicatePR_4" $
558 P_4 (replicatePR pra n# a)
559 (replicatePR prb n# b)
560 (replicatePR prc n# c)
561 (replicatePR prd n# d)
562
563 {-# INLINE replicatelPR_4 #-}
564 replicatelPR_4 pra prb prc prd segd (P_4 as bs cs ds)
565 = traceFn "replicatelPR_4" $
566 P_4 (replicatelPR pra segd as)
567 (replicatelPR prb segd bs)
568 (replicatelPR prc segd cs)
569 (replicatelPR prd segd ds)
570
571 {-# INLINE repeatPR_4 #-}
572 repeatPR_4 pra prb prc prd n# len# (P_4 as bs cs ds)
573 = traceFn "repeatPR_4" $
574 P_4 (repeatPR pra n# len# as)
575 (repeatPR prb n# len# bs)
576 (repeatPR prc n# len# cs)
577 (repeatPR prd n# len# ds)
578
579 {-# INLINE repeatcPR_4 #-}
580 repeatcPR_4 pra prb prc prd n# ns segd (P_4 as bs cs ds)
581 = traceFn "repeatcPR_4" $
582 P_4 (repeatcPR pra n# ns segd as)
583 (repeatcPR prb n# ns segd bs)
584 (repeatcPR prc n# ns segd cs)
585 (repeatcPR prd n# ns segd ds)
586
587 {-# INLINE indexPR_4 #-}
588 indexPR_4 pra prb prc prd (P_4 as bs cs ds) i#
589 = traceFn "indexPR_4" $
590 (indexPR pra as i#,
591 indexPR prb bs i#,
592 indexPR prc cs i#,
593 indexPR prd ds i#)
594
595 {-# INLINE extractPR_4 #-}
596 extractPR_4 pra prb prc prd (P_4 as bs cs ds) i# n#
597 = traceFn "extractPR_4" $
598 P_4 (extractPR pra as i# n#)
599 (extractPR prb bs i# n#)
600 (extractPR prc cs i# n#)
601 (extractPR prd ds i# n#)
602
603 {-# INLINE bpermutePR_4 #-}
604 bpermutePR_4 pra prb prc prd (P_4 as bs cs ds) n# is
605 = traceFn "bpermutePR_4" $
606 P_4 (bpermutePR pra as n# is)
607 (bpermutePR prb bs n# is)
608 (bpermutePR prc cs n# is)
609 (bpermutePR prd ds n# is)
610
611 {-# INLINE appPR_4 #-}
612 appPR_4 pra prb prc prd (P_4 as1 bs1 cs1 ds1) (P_4 as2 bs2 cs2 ds2)
613 = traceFn "appPR_4" $
614 P_4 (appPR pra as1 as2)
615 (appPR prb bs1 bs2)
616 (appPR prc cs1 cs2)
617 (appPR prd ds1 ds2)
618
619 {-# INLINE applPR_4 #-}
620 applPR_4 pra prb prc prd is (P_4 as1 bs1 cs1 ds1) js (P_4 as2 bs2 cs2 ds2)
621 = traceFn "applPR_4" $
622 P_4 (applPR pra is as1 js as2)
623 (applPR prb is bs1 js bs2)
624 (applPR prc is cs1 js cs2)
625 (applPR prd is ds1 js ds2)
626
627 {-# INLINE packPR_4 #-}
628 packPR_4 pra prb prc prd (P_4 as bs cs ds) n# sel#
629 = traceFn "packPR_4" $
630 P_4 (packPR pra as n# sel#)
631 (packPR prb bs n# sel#)
632 (packPR prc cs n# sel#)
633 (packPR prd ds n# sel#)
634
635 {-# INLINE combine2PR_4 #-}
636 combine2PR_4 pra prb prc prd n# sel (P_4 as1 bs1 cs1 ds1)
637 (P_4 as2 bs2 cs2 ds2)
638 = traceFn "combine2PR_4" $
639 P_4 (combine2PR pra n# sel as1 as2)
640 (combine2PR prb n# sel bs1 bs2)
641 (combine2PR prc n# sel cs1 cs2)
642 (combine2PR prd n# sel ds1 ds2)
643
644 {-# INLINE fromListPR_4 #-}
645 fromListPR_4 pra prb prc prd n# xs
646 = P_4 (fromListPR pra n# as)
647 (fromListPR prb n# bs)
648 (fromListPR prc n# cs)
649 (fromListPR prd n# ds)
650 where
651 (as,bs,cs,ds) = L.unzip4 xs
652
653 {-# INLINE nfPR_4 #-}
654 nfPR_4 pra prb prc prd (P_4 as bs cs ds)
655 = nfPR pra as
656 `seq` nfPR prb bs
657 `seq` nfPR prc cs
658 `seq` nfPR prd ds
659
660 dPR_5 :: PR a -> PR b -> PR c -> PR d -> PR e -> PR (a,b,c,d,e)
661 {-# INLINE dPR_5 #-}
662 dPR_5 pra prb prc prd pre
663 = PR {
664 emptyPR = emptyPR_5 pra prb prc prd pre
665 , replicatePR = replicatePR_5 pra prb prc prd pre
666 , replicatelPR = replicatelPR_5 pra prb prc prd pre
667 , repeatPR = repeatPR_5 pra prb prc prd pre
668 , repeatcPR = repeatcPR_5 pra prb prc prd pre
669 , indexPR = indexPR_5 pra prb prc prd pre
670 , extractPR = extractPR_5 pra prb prc prd pre
671 , bpermutePR = bpermutePR_5 pra prb prc prd pre
672 , appPR = appPR_5 pra prb prc prd pre
673 , applPR = applPR_5 pra prb prc prd pre
674 , packPR = packPR_5 pra prb prc prd pre
675 , combine2PR = combine2PR_5 pra prb prc prd pre
676 , fromListPR = fromListPR_5 pra prb prc prd pre
677 , nfPR = nfPR_5 pra prb prc prd pre
678 }
679
680 {-# INLINE emptyPR_5 #-}
681 emptyPR_5 pra prb prc prd pre
682 = traceFn "emptyPR_5" $
683 P_5 (emptyPR pra)
684 (emptyPR prb)
685 (emptyPR prc)
686 (emptyPR prd)
687 (emptyPR pre)
688
689 {-# INLINE replicatePR_5 #-}
690 replicatePR_5 pra prb prc prd pre n# (a,b,c,d,e)
691 = traceFn "replicatePR_5" $
692 P_5 (replicatePR pra n# a)
693 (replicatePR prb n# b)
694 (replicatePR prc n# c)
695 (replicatePR prd n# d)
696 (replicatePR pre n# e)
697
698 {-# INLINE replicatelPR_5 #-}
699 replicatelPR_5 pra prb prc prd pre segd (P_5 as bs cs ds es)
700 = traceFn "replicatelPR_5" $
701 P_5 (replicatelPR pra segd as)
702 (replicatelPR prb segd bs)
703 (replicatelPR prc segd cs)
704 (replicatelPR prd segd ds)
705 (replicatelPR pre segd es)
706
707 {-# INLINE repeatPR_5 #-}
708 repeatPR_5 pra prb prc prd pre n# len# (P_5 as bs cs ds es)
709 = traceFn "repeatPR_5" $
710 P_5 (repeatPR pra n# len# as)
711 (repeatPR prb n# len# bs)
712 (repeatPR prc n# len# cs)
713 (repeatPR prd n# len# ds)
714 (repeatPR pre n# len# es)
715
716 {-# INLINE repeatcPR_5 #-}
717 repeatcPR_5 pra prb prc prd pre n# ns segd (P_5 as bs cs ds es)
718 = traceFn "repeatcPR_5" $
719 P_5 (repeatcPR pra n# ns segd as)
720 (repeatcPR prb n# ns segd bs)
721 (repeatcPR prc n# ns segd cs)
722 (repeatcPR prd n# ns segd ds)
723 (repeatcPR pre n# ns segd es)
724
725 {-# INLINE indexPR_5 #-}
726 indexPR_5 pra prb prc prd pre (P_5 as bs cs ds es) i#
727 = traceFn "indexPR_5" $
728 (indexPR pra as i#,
729 indexPR prb bs i#,
730 indexPR prc cs i#,
731 indexPR prd ds i#,
732 indexPR pre es i#)
733
734 {-# INLINE extractPR_5 #-}
735 extractPR_5 pra prb prc prd pre (P_5 as bs cs ds es) i# n#
736 = traceFn "extractPR_5" $
737 P_5 (extractPR pra as i# n#)
738 (extractPR prb bs i# n#)
739 (extractPR prc cs i# n#)
740 (extractPR prd ds i# n#)
741 (extractPR pre es i# n#)
742
743 {-# INLINE bpermutePR_5 #-}
744 bpermutePR_5 pra prb prc prd pre (P_5 as bs cs ds es) n# is
745 = traceFn "bpermutePR_5" $
746 P_5 (bpermutePR pra as n# is)
747 (bpermutePR prb bs n# is)
748 (bpermutePR prc cs n# is)
749 (bpermutePR prd ds n# is)
750 (bpermutePR pre es n# is)
751
752 {-# INLINE appPR_5 #-}
753 appPR_5 pra prb prc prd pre (P_5 as1 bs1 cs1 ds1 es1)
754 (P_5 as2 bs2 cs2 ds2 es2)
755 = traceFn "appPR_5" $
756 P_5 (appPR pra as1 as2)
757 (appPR prb bs1 bs2)
758 (appPR prc cs1 cs2)
759 (appPR prd ds1 ds2)
760 (appPR pre es1 es2)
761
762 {-# INLINE applPR_5 #-}
763 applPR_5 pra prb prc prd pre is (P_5 as1 bs1 cs1 ds1 es1)
764 js (P_5 as2 bs2 cs2 ds2 es2)
765 = traceFn "applPR_5" $
766 P_5 (applPR pra is as1 js as2)
767 (applPR prb is bs1 js bs2)
768 (applPR prc is cs1 js cs2)
769 (applPR prd is ds1 js ds2)
770 (applPR pre is es1 js es2)
771
772 {-# INLINE packPR_5 #-}
773 packPR_5 pra prb prc prd pre (P_5 as bs cs ds es) n# sel#
774 = traceFn "packPR_5" $
775 P_5 (packPR pra as n# sel#)
776 (packPR prb bs n# sel#)
777 (packPR prc cs n# sel#)
778 (packPR prd ds n# sel#)
779 (packPR pre es n# sel#)
780
781 {-# INLINE combine2PR_5 #-}
782 combine2PR_5 pra prb prc prd pre n# sel (P_5 as1 bs1 cs1 ds1 es1)
783 (P_5 as2 bs2 cs2 ds2 es2)
784 = traceFn "combine2PR_5" $
785 P_5 (combine2PR pra n# sel as1 as2)
786 (combine2PR prb n# sel bs1 bs2)
787 (combine2PR prc n# sel cs1 cs2)
788 (combine2PR prd n# sel ds1 ds2)
789 (combine2PR pre n# sel es1 es2)
790
791 {-# INLINE fromListPR_5 #-}
792 fromListPR_5 pra prb prc prd pre n# xs
793 = P_5 (fromListPR pra n# as)
794 (fromListPR prb n# bs)
795 (fromListPR prc n# cs)
796 (fromListPR prd n# ds)
797 (fromListPR pre n# es)
798 where
799 (as,bs,cs,ds,es) = L.unzip5 xs
800
801 {-# INLINE nfPR_5 #-}
802 nfPR_5 pra prb prc prd pre (P_5 as bs cs ds es)
803 = nfPR pra as
804 `seq` nfPR prb bs
805 `seq` nfPR prc cs
806 `seq` nfPR prd ds
807 `seq` nfPR pre es
808
809 data Sum2 a b = Alt2_1 a | Alt2_2 b
810 data Sum3 a b c = Alt3_1 a | Alt3_2 b | Alt3_3 c
811
812 data instance PData (Sum2 a b)
813 = PSum2 Sel2 (PData a) (PData b)
814
815 dPR_Sum2 :: PR a -> PR b -> PR (Sum2 a b)
816 {-# INLINE dPR_Sum2 #-}
817 dPR_Sum2 pra prb = PR {
818 emptyPR = emptyPR_Sum2 pra prb
819 , replicatePR = replicatePR_Sum2 pra prb
820 , replicatelPR = replicatelPR_Sum2 pra prb
821 , repeatPR = repeatPR_Sum2 pra prb
822 , indexPR = indexPR_Sum2 pra prb
823 , appPR = appPR_Sum2 pra prb
824 , packPR = packPR_Sum2 pra prb
825 , combine2PR = combine2PR_Sum2 pra prb
826 }
827
828 {-# INLINE emptyPR_Sum2 #-}
829 emptyPR_Sum2 pra prb
830 = traceFn "emptyPR_Sum2" $
831 PSum2 (mkSel2 U.empty U.empty 0 0) (emptyPR pra) (emptyPR prb)
832
833 {-# INLINE replicatePR_Sum2 #-}
834 replicatePR_Sum2 pra prb n# (Alt2_1 x)
835 = traceFn "replicatePR_Sum2" $
836 PSum2 (mkSel2 (U.replicate (I# n#) 0)
837 (U.enumFromStepLen 0 1 (I# n#))
838 (I# n#) 0)
839 (replicatePR pra n# x)
840 (emptyPR prb)
841 replicatePR_Sum2 pra prb n# (Alt2_2 x)
842 = traceFn "replicatePR_Sum2" $
843 PSum2 (mkSel2 (U.replicate (I# n#) 1)
844 (U.enumFromStepLen 0 1 (I# n#))
845 0 (I# n#))
846 (emptyPR pra)
847 (replicatePR prb n# x)
848
849 {-# INLINE replicatelPR_Sum2 #-}
850 replicatelPR_Sum2 pra prb segd (PSum2 sel as bs)
851 = traceFn "replicatelPR_Sum2" $
852 PSum2 sel' as' bs'
853 where
854 tags = tagsSel2 sel
855 tags' = U.replicate_s segd tags
856 sel' = tagsToSel2 tags'
857
858 lens = U.lengthsSegd segd
859
860 asegd = U.lengthsToSegd
861 . U.pack lens
862 $ U.pick tags 0
863 bsegd = U.lengthsToSegd
864 . U.pack lens
865 $ U.pick tags 1
866
867 as' = replicatelPR pra asegd as
868 bs' = replicatelPR prb bsegd bs
869
870 {-# INLINE repeatPR_Sum2 #-}
871 repeatPR_Sum2 pra prb m# n# (PSum2 sel as bs)
872 = traceFn "repeatPR_Sum2" $
873 PSum2 sel' as' bs'
874 where
875 sel' = tagsToSel2
876 . U.repeat (I# m#) (I# n#)
877 $ tagsSel2 sel
878
879 as' = repeatPR pra m# (elementsSel2_0# sel) as
880 bs' = repeatPR prb n# (elementsSel2_1# sel) bs
881
882 {-# INLINE indexPR_Sum2 #-}
883 indexPR_Sum2 pra prb (PSum2 sel as bs) i#
884 = traceFn "indexPR_Sum2" $
885 case indicesSel2 sel U.!: I# i# of
886 I# k# -> case tagsSel2 sel U.!: I# i# of
887 0 -> Alt2_1 (indexPR pra as k#)
888 _ -> Alt2_2 (indexPR prb bs k#)
889
890 {-# INLINE appPR_Sum2 #-}
891 appPR_Sum2 pra prb (PSum2 sel1 as1 bs1)
892 (PSum2 sel2 as2 bs2)
893 = traceFn "appPR_Sum2" $
894 PSum2 sel (appPR pra as1 as2)
895 (appPR prb bs1 bs2)
896 where
897 sel = tagsToSel2
898 $ tagsSel2 sel1 U.+:+ tagsSel2 sel2
899
900 {-# INLINE packPR_Sum2 #-}
901 packPR_Sum2 pra prb (PSum2 sel as bs) m# flags
902 = traceFn "packPR_Sum2" $
903 PSum2 sel' as' bs'
904 where
905 tags = tagsSel2 sel
906 tags' = U.pack tags flags
907 sel' = tagsToSel2 tags'
908
909 aFlags = U.pack flags (U.pick tags 0)
910 bFlags = U.pack flags (U.pick tags 1)
911
912 as' = packPR pra as (elementsSel2_0# sel') aFlags
913 bs' = packPR prb bs (elementsSel2_1# sel') bFlags
914
915 _dummy :: Int#
916 _dummy = m#
917
918 combine2PR_Sum2 :: PR a -> PR b -> T_combine2PR (Sum2 a b)
919 {-# INLINE combine2PR_Sum2 #-}
920 combine2PR_Sum2 pra prb n# sel (PSum2 sel1 as1 bs1)
921 (PSum2 sel2 as2 bs2)
922 = traceFn "combine2PR_Sum2" $
923 PSum2 sel' as bs
924 where
925 tags = tagsSel2 sel
926 tags' = U.combine (U.pick tags 0) (tagsSel2 sel1) (tagsSel2 sel2)
927 sel' = tagsToSel2 tags'
928
929 asel = tagsToSel2 (U.pack tags (U.pick tags' 0))
930 bsel = tagsToSel2 (U.pack tags (U.pick tags' 1))
931
932 as = combine2PR pra (elementsSel2_0# sel') asel as1 as2
933 bs = combine2PR prb (elementsSel2_1# sel') bsel bs1 bs2
934
935 {-
936 data instance PData (Sum2 a b)
937 = PSum2 (U.Array Int) (U.Array Int) Int# (PData a)
938 Int# (PData b)
939
940 data instance PData (Sum3 a b c)
941 = PSum3 (U.Array Int) (U.Array Int) Int# (PData a)
942 Int# (PData b)
943 Int# (PData c)
944
945 dPR_Sum2 :: PR a -> PR b -> PR (Sum2 a b)
946 {-# INLINE dPR_Sum2 #-}
947 dPR_Sum2 pra prb = PR {
948 emptyPR = emptyPR_Sum2 pra prb
949 , replicatePR = replicatePR_Sum2 pra prb
950 , replicatelPR = replicatelPR_Sum2 pra prb
951 , repeatPR = repeatPR_Sum2 pra prb
952 , indexPR = indexPR_Sum2 pra prb
953 , appPR = appPR_Sum2 pra prb
954 , packPR = packPR_Sum2 pra prb
955 , combine2PR = combine2PR_Sum2 pra prb
956 }
957
958 {-# INLINE emptyPR_Sum2 #-}
959 emptyPR_Sum2 pra prb
960 = traceFn "emptyPR_Sum2" $
961 PSum2 U.empty U.empty 0# (emptyPR pra)
962 0# (emptyPR prb)
963
964 {-# INLINE replicatePR_Sum2 #-}
965 replicatePR_Sum2 pra prb n# (Alt2_1 x)
966 = traceFn "replicatePR_Sum2" $
967 PSum2 (U.replicate (I# n#) 0)
968 (U.enumFromStepLen 0 1 (I# n#))
969 n# (replicatePR pra n# x)
970 0# (emptyPR prb)
971 replicatePR_Sum2 pra prb n# (Alt2_2 x)
972 = traceFn "replicatePR_Sum2" $
973 PSum2 (U.replicate (I# n#) 1)
974 (U.enumFromStepLen 0 1 (I# n#))
975 0# (emptyPR pra)
976 n# (replicatePR prb n# x)
977
978 {-# INLINE replicatelPR_Sum2 #-}
979 replicatelPR_Sum2 pra prb segd (PSum2 sel is _ as _ bs)
980 = traceFn "replicatelPR_Sum2" $
981 PSum2 sel' is' (elementsSegd# asegd) as'
982 (elementsSegd# bsegd) bs'
983 where
984 sel' = U.replicate_s segd sel
985 is' = U.selectorToIndices2 sel'
986
987 lens = U.lengthsSegd segd
988
989 asegd = U.lengthsToSegd
990 . U.pack lens
991 $ U.pick sel 0
992 bsegd = U.lengthsToSegd
993 . U.pack lens
994 $ U.pick sel 1
995
996 as' = replicatelPR pra asegd as
997 bs' = replicatelPR prb bsegd bs
998
999 {-# INLINE repeatPR_Sum2 #-}
1000 repeatPR_Sum2 pra prb m# n# (PSum2 sel is an# as bn# bs)
1001 = traceFn "repeatPR_Sum2" $
1002 PSum2 sel' is' (m# *# an#) as'
1003 (m# *# bn#) bs'
1004 where
1005 sel' = U.repeat (I# m#) (I# n#) sel
1006 is' = U.selectorToIndices2 sel'
1007
1008 !an'# = m# *# an#
1009 !bn'# = m# *# bn#
1010
1011 as' = repeatPR pra m# an# as
1012 bs' = repeatPR prb n# bn# bs
1013
1014 {-# INLINE indexPR_Sum2 #-}
1015 indexPR_Sum2 pra prb (PSum2 sel is _ as _ bs) i#
1016 = traceFn "indexPR_Sum2" $
1017 case is U.!: I# i# of
1018 I# k# -> case sel U.!: I# i# of
1019 0 -> Alt2_1 (indexPR pra as k#)
1020 _ -> Alt2_2 (indexPR prb bs k#)
1021
1022 {-# INLINE appPR_Sum2 #-}
1023 appPR_Sum2 pra prb (PSum2 sel1 _ an1# as1 bn1# bs1)
1024 (PSum2 sel2 _ an2# as2 bn2# bs2)
1025 = traceFn "appPR_Sum2" $
1026 PSum2 sel is (an1# +# an2#) (appPR pra as1 as2)
1027 (bn1# +# bn2#) (appPR prb bs1 bs2)
1028 where
1029 sel = sel1 U.+:+ sel2
1030 is = U.selectorToIndices2 sel
1031
1032 {-# INLINE packPR_Sum2 #-}
1033 packPR_Sum2 pra prb (PSum2 sel _ an# as bn# bs) m# flags
1034 = traceFn "packPR_Sum2" $
1035 PSum2 sel' is' an'# as' bn'# bs'
1036 where
1037 sel' = U.pack sel flags
1038 is' = U.selectorToIndices2 sel'
1039
1040 aFlags = U.pack flags (U.pick sel 0)
1041 bFlags = U.pack flags (U.pick sel 1)
1042
1043 !bn'# = case U.count bFlags True of I# n# -> n#
1044 !an'# = m# -# bn'#
1045
1046 as' = packPR pra as an'# aFlags
1047 bs' = packPR prb bs bn'# bFlags
1048
1049 combine2PR_Sum2 :: PR a -> PR b -> T_combine2PR (Sum2 a b)
1050 {-# INLINE combine2PR_Sum2 #-}
1051 combine2PR_Sum2 pra prb n# sel is (PSum2 sel1 _ an1# as1 bn1# bs1)
1052 (PSum2 sel2 _ an2# as2 bn2# bs2)
1053 = traceFn "combine2PR_Sum2" $
1054 PSum2 sel' is' an# as bn# bs
1055 where
1056 sel' = U.combine (U.pick sel 0) sel1 sel2
1057 is' = U.selectorToIndices2 sel'
1058
1059 !an# = an1# +# an2#
1060 !bn# = bn1# +# bn2#
1061
1062 asel = U.pack sel (U.pick sel' 0)
1063 bsel = U.pack sel (U.pick sel' 1)
1064
1065 as = combine2PR pra an# asel (U.selectorToIndices2 asel) as1 as2
1066 bs = combine2PR prb bn# bsel (U.selectorToIndices2 bsel) bs1 bs2
1067
1068 {-
1069 = traceFn "combine2PR_Sum2" $
1070 case (sel'Bool, nsel'Bool) of
1071 (s1#, s2#) -> traceArgs ("combinePR_Sum\nn = " ++ show (I# n#) ++ "\n" ++
1072 "m1 = " ++ show (I# m1#) ++ "\n" ++
1073 "m2 = " ++ show (I# m2#) ++ "\n" ++
1074 "as# = " ++ show (I# (lengthPR pra as1)) ++ " " ++ show (I# (lengthPR pra as2)) ++ "\n" ++
1075 "bs# = " ++ show (I# (lengthPR prb bs1)) ++ " " ++ show (I# (lengthPR prb bs2)) ++ "\n" ++
1076 "sel = " ++ show sel# ++ "\n" ++
1077 "sel1 = " ++ show sel1# ++ "\n" ++
1078 "sel2 = " ++ show sel2# ++ "\n" ++
1079 "s1# = " ++ show s1# ++ "\n" ++
1080 "s2# = " ++ show s2# ++ "\n" ++
1081 "selB = " ++ show sel'Bool ++ "\n" ++
1082 "nselB = " ++ show nsel'Bool ++ "\n" ++
1083 "sel' = " ++ show sel' ++ "\n"
1084 )
1085 $
1086 PSum2 n# sel' (error "combine2PR_Sum2 index nyi") as' bs'
1087 where
1088 !as# = lengthPR pra as1 +# lengthPR pra as2
1089 !bs# = lengthPR prb bs1 +# lengthPR prb bs2
1090 asel = packPA_Int# sel# as# s1#
1091 bsel = packPA_Int# sel# bs# s2#
1092 as' = trace ("cb1: " ++ show asel) $ combine2PR pra as# asel is# as1 as2
1093 bs' = trace ("cb2: " ++ show bsel) $ combine2PR prb bs# bsel is# bs1 bs2
1094 where
1095 sel' = combine2PA_Int# n# sel# is# sel1# sel2#
1096 sel'Bool = selectPA_Int# sel' 0#
1097 nsel'Bool = selectPA_Int# sel' 1#
1098 -}
1099
1100 dPR_Sum3 :: PR a -> PR b -> PR c -> PR (Sum3 a b c)
1101 {-# INLINE dPR_Sum3 #-}
1102 dPR_Sum3 pra prb prc
1103 = PR {
1104 emptyPR = emptyPR_Sum3 pra prb prc
1105 , replicatePR = replicatePR_Sum3 pra prb prc
1106 , indexPR = indexPR_Sum3 pra prb prc
1107 }
1108
1109 {-# INLINE emptyPR_Sum3 #-}
1110 emptyPR_Sum3 pra prb prc
1111 = traceFn "emptyPR_Sum3\n" $
1112 PSum3 U.empty U.empty 0# (emptyPR pra)
1113 0# (emptyPR prb)
1114 0# (emptyPR prc)
1115
1116 {-# INLINE replicatePR_Sum3 #-}
1117 replicatePR_Sum3 pra prb prc n# (Alt3_1 x)
1118 = traceFn "replicatePR_Sum3\n" $
1119 PSum3 (U.replicate (I# n#) 0)
1120 (U.enumFromStepLen 0 1 (I# n#))
1121 n# (replicatePR pra n# x)
1122 0# (emptyPR prb)
1123 0# (emptyPR prc)
1124 replicatePR_Sum3 pra prb prc n# (Alt3_2 x)
1125 = traceFn "replicatePR_Sum3\n" $
1126 PSum3 (U.replicate (I# n#) 1)
1127 (U.enumFromStepLen 0 1 (I# n#))
1128 0# (emptyPR pra)
1129 n# (replicatePR prb n# x)
1130 0# (emptyPR prc)
1131 replicatePR_Sum3 pra prb prc n# (Alt3_3 x)
1132 = traceFn "replicatePR_Sum3\n" $
1133 PSum3 (U.replicate (I# n#) 2)
1134 (U.enumFromStepLen 0 1 (I# n#))
1135 0# (emptyPR pra)
1136 0# (emptyPR prb)
1137 n# (replicatePR prc n# x)
1138
1139 {-# INLINE indexPR_Sum3 #-}
1140 indexPR_Sum3 pra prb prc (PSum3 sel is _ as _ bs _ cs) i#
1141 = traceFn "indexPR_Sum3\n" $
1142 case is U.!: I# i# of
1143 I# k# -> case sel U.!: I# i# of
1144 0 -> Alt3_1 (indexPR pra as k#)
1145 1 -> Alt3_2 (indexPR prb bs k#)
1146 _ -> Alt3_3 (indexPR prc cs k#)
1147 -}
1148
1149 data instance PData (PArray a) = PNested U.Segd (PData a)
1150
1151 dPR_PArray :: PR a -> PR (PArray a)
1152 {-# INLINE dPR_PArray #-}
1153 dPR_PArray pr = PR {
1154 emptyPR = emptyPR_PArray pr
1155 , replicatePR = replicatePR_PArray pr
1156 , replicatelPR = replicatelPR_PArray pr
1157 , repeatPR = repeatPR_PArray pr
1158 , indexPR = indexPR_PArray pr
1159 , extractPR = extractPR_PArray pr
1160 , bpermutePR = bpermutePR_PArray pr
1161 , appPR = appPR_PArray pr
1162 , applPR = applPR_PArray pr
1163 , packPR = packPR_PArray pr
1164 , combine2PR = combine2PR_PArray pr
1165 }
1166
1167 {-
1168 {-# INLINE nested_lengthPA #-}
1169 nested_lengthPA xss = traceFn "nested_lengthPA\n" $
1170 I# (lengthPR_PArray xss)
1171 -}
1172
1173
1174 {-# INLINE emptyPR_PArray #-}
1175 emptyPR_PArray pr = traceFn "emptyPR_PArray\n" $
1176 PNested (U.mkSegd U.empty U.empty 0) (emptyPR pr)
1177
1178 {-# INLINE replicatePR_PArray #-}
1179 replicatePR_PArray pr n# (PArray m# xs)
1180 = traceFn "replicatePR_PArray\n" $
1181 PNested (U.mkSegd (U.replicate (I# n#) (I# m#))
1182 (U.enumFromStepLen 0 (I# m#) (I# n#))
1183 (I# n# * I# m#))
1184 (repeatPR pr n# m# xs)
1185
1186 {-# INLINE indexPR_PArray #-}
1187 indexPR_PArray pr (PNested segd xs) i#
1188 = case U.lengthsSegd segd U.!: I# i# of { I# n# ->
1189 case U.indicesSegd segd U.!: I# i# of { I# k# ->
1190 PArray n# (extractPR pr xs k# n#) }}
1191
1192 {-# INLINE extractPR_PArray #-}
1193 extractPR_PArray pr (PNested segd xs) i# n#
1194 = case U.indicesSegd segd U.!: I# i# of
1195 I# k# -> PNested segd' (extractPR pr xs k# (elementsSegd# segd'))
1196 where
1197 segd' = U.lengthsToSegd
1198 $ U.extract (U.lengthsSegd segd) (I# i#) (I# n#)
1199
1200 bpermutePR_PArray :: PR a -> T_bpermutePR (PArray a)
1201 {-# INLINE bpermutePR_PArray #-}
1202 bpermutePR_PArray pr (PNested segd xs) n# is
1203 = traceFn "bpermutePR_PArray\n" $
1204 PNested segd' (bpermutePR pr xs (elementsSegd# segd') flat_is)
1205 where
1206 segd' = U.lengthsToSegd
1207 $ U.bpermute (U.lengthsSegd segd) is
1208
1209 starts = U.indicesSegd segd'
1210 lens = U.lengthsSegd segd'
1211 ends = U.zipWith (\x y -> x + y - 1) starts lens
1212 flat_is = U.enumFromToEach (U.elementsSegd segd') (U.zip starts ends)
1213
1214 {-# INLINE appPR_PArray #-}
1215 appPR_PArray pr (PNested xsegd xs) (PNested ysegd ys)
1216 = traceFn "appPR_PArray\n" $
1217 PNested (U.lengthsToSegd (U.lengthsSegd xsegd U.+:+ U.lengthsSegd ysegd))
1218 (appPR pr xs ys)
1219
1220 {-# INLINE applPR_PArray #-}
1221 applPR_PArray pr segd1 (PNested xsegd xs) segd2 (PNested ysegd ys)
1222 = PNested segd (applPR pr xsegd' xs ysegd' ys)
1223 where
1224 segd = U.lengthsToSegd
1225 $ U.append_s segd1 (U.lengthsSegd xsegd) segd2 (U.lengthsSegd ysegd)
1226
1227 xsegd' = U.lengthsToSegd
1228 $ U.sum_s segd1 (U.lengthsSegd xsegd)
1229 ysegd' = U.lengthsToSegd
1230 $ U.sum_s segd2 (U.lengthsSegd ysegd)
1231
1232 {-# INLINE repeatPR_PArray #-}
1233 repeatPR_PArray pr n# len# (PNested segd xs)
1234 = traceFn "repeatPR_PArray\n" $
1235 PNested segd' (repeatPR pr n# (elementsSegd# segd) xs)
1236 where
1237 segd' = U.lengthsToSegd (U.repeat (I# n#) (I# len#) (U.lengthsSegd segd))
1238
1239 {-# INLINE replicatelPR_PArray #-}
1240 replicatelPR_PArray pr segd (PNested xsegd xs)
1241 = traceFn "replicatelPR_PArray\n" $
1242 PNested xsegd' xs'
1243 where
1244 xsegd' = U.lengthsToSegd
1245 $ U.replicate_s segd (U.lengthsSegd xsegd)
1246
1247 xs' = repeatcPR pr (elementsSegd# xsegd')
1248 (U.lengthsSegd segd)
1249 xsegd xs
1250
1251 packPR_PArray :: PR a -> T_packPR (PArray a)
1252 {-# INLINE packPR_PArray #-}
1253 packPR_PArray pr (PNested segd xs) n# flags
1254 = traceFn "packPR_PArray\n" $
1255 PNested segd' xs'
1256 where
1257 segd' = U.lengthsToSegd
1258 $ U.pack (U.lengthsSegd segd) flags
1259
1260 xs' = packPR pr xs (elementsSegd# segd') (U.replicate_s segd flags)
1261
1262 combine2PR_PArray :: PR a -> T_combine2PR (PArray a)
1263 {-# INLINE combine2PR_PArray #-}
1264 combine2PR_PArray pr n# sel (PNested xsegd xs) (PNested ysegd ys)
1265 = traceFn "combine2PR_PArray\n" $
1266 PNested segd xys
1267 where
1268 tags = tagsSel2 sel
1269
1270 segd = U.lengthsToSegd
1271 $ U.combine (U.pick tags 0) (U.lengthsSegd xsegd) (U.lengthsSegd ysegd)
1272
1273 sel' = tagsToSel2
1274 $ U.replicate_s segd tags
1275
1276 xys = combine2PR pr (elementsSegd# segd) sel' xs ys
1277
1278 segdPA# :: PArray (PArray a) -> U.Segd
1279 {-# INLINE_PA segdPA# #-}
1280 segdPA# (PArray _ (PNested segd _)) = segd
1281
1282 concatPA# :: PArray (PArray a) -> PArray a
1283 {-# INLINE_PA concatPA# #-}
1284 concatPA# (PArray _ (PNested segd xs)) = PArray (elementsSegd# segd) xs
1285
1286 segmentPA# :: Int# -> U.Segd -> PArray a -> PArray (PArray a)
1287 {-# INLINE_PA segmentPA# #-}
1288 segmentPA# n# segd (PArray _ xs) = PArray n# (PNested segd xs)
1289
1290 copySegdPA# :: PArray (PArray a) -> PArray b -> PArray (PArray b)
1291 {-# INLINE copySegdPA# #-}
1292 copySegdPA# (PArray n# (PNested segd _)) (PArray _ xs)
1293 = PArray n# (PNested segd xs)
1294