summaryrefslogtreecommitdiff
path: root/testsuite/tests/dph/nbody/Types.hs
blob: 5ebd849a62e9e4a7b1c46a8e6e34fed97f297bab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{-# LANGUAGE ParallelArrays #-}
{-# OPTIONS -fvectorise #-}

module Types 
        ( Point
        , Line
        , makePoints, makePointsPA
        , xsOf, xsOfPA
        , ysOf, ysOfPA)
where
import Data.Array.Parallel
import Data.Array.Parallel.Prelude.Double
import qualified Data.Array.Parallel.Prelude.Double as D
import qualified Prelude as P

type Point = (Double, Double)
type Line  = (Point, Point)

-- | Make some points from their components.
makePoints :: [:Double:] -> [:Double:] -> [:Point:]
makePoints = zipP


-- | Make some points from their components, as a `PArray`.
makePointsPA :: PArray Double -> PArray Double -> PArray Point
{-# NOINLINE makePointsPA #-}
makePointsPA xs ys
        = toPArrayP (makePoints (fromPArrayP xs) (fromPArrayP ys))


-- | Take the x values of some points.
xsOf :: [:Point:] -> [:Double:]
xsOf ps = [: x | (x, _) <- ps :]


-- | Take the x values of some points as a `PArray`.
xsOfPA :: PArray Point -> PArray Double
{-# NOINLINE xsOfPA #-}
xsOfPA ps = toPArrayP (xsOf (fromPArrayP ps))


-- | Take the y values of some points.
ysOf :: [:Point:] -> [:Double:]
ysOf ps = [: y | (_, y) <- ps :]


-- | Take the y values of some points as a `PArray`.
ysOfPA :: PArray Point -> PArray Double
{-# NOINLINE ysOfPA #-}
ysOfPA ps = toPArrayP (ysOf (fromPArrayP ps))