Adapted to simplified VECTORISE pragmas
[packages/dph.git] / dph-lifted-vseg / Data / Array / Parallel / Prelude / Double.hs
1 {-# OPTIONS_GHC -fvectorise #-}
2
3 module Data.Array.Parallel.Prelude.Double
4 ( Double
5
6 -- * Ord
7 , (==), (/=), (<), (<=), (>), (>=), min, max
8 , maximumP, minimumP
9 , maxIndexP, minIndexP
10
11 -- * Num
12 , (+), (-), (*), (/)
13 , negate, abs
14 , sumP, productP
15
16 -- * Floating
17 , pi
18 , sqrt
19 , exp, (**)
20 , log, logBase
21 , sin, tan, cos
22 , asin, atan, acos
23 , sinh, tanh, cosh
24 , asinh, atanh, acosh
25
26 -- * RealFrac
27 , fromInt)
28 where
29 -- Primitives needed by the vectoriser.
30 import Data.Array.Parallel.Prim ()
31 import Data.Array.Parallel.Prelude.Base (Bool)
32 import Data.Array.Parallel.PArr
33 import Data.Array.Parallel.PArray
34 import Data.Array.Parallel.Lifted ((:->)(..))
35 import qualified Data.Array.Parallel.Lifted as L
36 import qualified Data.Array.Parallel.PArray.Scalar as SC
37 import qualified Prelude as P
38 import Prelude (Int, Double)
39
40
41 infixl 7 *, /
42 infixl 6 +, -
43 infix 4 ==, /=, <, <=, >, >=
44
45 -- Ord ------------------------------------------------------------------------
46 (==), (/=), (<), (<=), (>), (>=) :: Double -> Double -> Bool
47 (==) = (P.==)
48 (/=) = (P./=)
49 (<=) = (P.<=)
50 (<) = (P.<)
51 (>=) = (P.>=)
52 (>) = (P.>)
53
54 -- min/max ----------------------------
55 min, max :: Double -> Double -> Double
56 min = P.min
57 max = P.max
58
59 -- minimum/maximum --------------------
60 minimumP, maximumP :: PArr Double -> Double
61
62 minimumP arr = headPArr arr
63 {-# NOINLINE minimumP #-}
64 {-# VECTORISE minimumP = minimumPP #-}
65
66 maximumP arr = headPArr arr
67 {-# NOINLINE maximumP #-}
68 {-# VECTORISE maximumP = maximumPP #-}
69
70 minimumPP, maximumPP :: PArray Double :-> Double
71 minimumPP = L.closure1' (SC.fold1 P.min) (SC.fold1s P.min)
72 {-# INLINE minimumPP #-}
73 {-# NOVECTORISE minimumPP #-}
74
75 maximumPP = L.closure1' (SC.fold1 P.max) (SC.fold1s P.max)
76 {-# INLINE maximumPP #-}
77 {-# NOVECTORISE maximumPP #-}
78
79
80 -- minIndex/maxIndex ------------------
81 minIndexP :: PArr Double -> Int
82 minIndexP !_ = 0
83 {-# NOINLINE minIndexP #-}
84 {-# VECTORISE minIndexP = minIndexPP #-}
85
86 minIndexPP :: PArray Double :-> Int
87 minIndexPP = L.closure1' (SC.fold1Index min') (SC.fold1sIndex min')
88 {-# INLINE minIndexPP #-}
89 {-# NOVECTORISE minIndexPP #-}
90
91 min' :: P.Ord b => (a, b) -> (a, b) -> (a, b)
92 min' (i,x) (j,y) | x P.<= y = (i,x)
93 | P.otherwise = (j,y)
94 {-# NOVECTORISE min' #-}
95
96
97 maxIndexP :: PArr Double -> Int
98 maxIndexP _ = 0
99 {-# NOINLINE maxIndexP #-}
100 {-# VECTORISE maxIndexP = maxIndexPP #-}
101
102 maxIndexPP :: PArray Double :-> Int
103 maxIndexPP = L.closure1' (SC.fold1Index max') (SC.fold1sIndex max')
104 {-# INLINE maxIndexPP #-}
105 {-# NOVECTORISE maxIndexPP #-}
106
107 max' :: P.Ord b => (a, b) -> (a, b) -> (a, b)
108 max' (i,x) (j,y) | x P.>= y = (i,x)
109 | P.otherwise = (j,y)
110 {-# NOVECTORISE max' #-}
111
112
113 -- Num ---------------------------------------------------------------------
114 (+), (-), (*), (/) :: Double -> Double -> Double
115 (+) = (P.+)
116 (-) = (P.-)
117 (*) = (P.*)
118 (/) = (P./)
119
120 -- negate/abs -------------------------
121 negate, abs :: Double -> Double
122 negate = P.negate
123 abs = P.abs
124
125 -- sum/product ------------------------
126 sumP, productP :: PArr Double -> Double
127
128 sumP arr = headPArr arr
129 {-# NOINLINE sumP #-}
130 {-# VECTORISE sumP = sumPP #-}
131
132 productP arr = headPArr arr
133 {-# NOINLINE productP #-}
134 {-# VECTORISE productP = productPP #-}
135
136 sumPP, productPP :: PArray Double :-> Double
137 sumPP = L.closure1' (SC.fold (+) 0) (SC.folds (+) 0)
138 {-# INLINE sumPP #-}
139 {-# NOVECTORISE sumPP #-}
140
141 productPP = L.closure1' (SC.fold (*) 1) (SC.folds (*) 1)
142 {-# INLINE productPP #-}
143 {-# NOVECTORISE productPP #-}
144
145
146 -- Floating -------------------------------------------------------------------
147 pi :: Double
148 pi = P.pi
149 {-# NOVECTORISE pi #-}
150
151 sqrt, exp, log,
152 sin, tan, cos,
153 asin, atan, acos,
154 sinh, tanh, cosh,
155 asinh, atanh, acosh :: Double -> Double
156
157 exp = P.exp
158 sqrt = P.sqrt
159 log = P.log
160 sin = P.sin
161 tan = P.tan
162 cos = P.cos
163 asin = P.asin
164 atan = P.atan
165 acos = P.acos
166 sinh = P.sinh
167 tanh = P.tanh
168 cosh = P.cosh
169 asinh = P.asinh
170 atanh = P.atanh
171 acosh = P.acosh
172
173 (**), logBase :: Double -> Double -> Double
174 (**) = (P.**)
175 logBase = P.logBase
176
177 -- RealFrac -------------------------------------------------------------------
178 fromInt :: Int -> Double
179 fromInt = P.fromIntegral