6fe67269fb7df976db1d77b272b23d5e0c5550ee
[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, Int, Double, Eq, Ord, Num)
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
39
40 {-# VECTORISE SCALAR instance Eq Double #-}
41 {-# VECTORISE SCALAR instance Ord Double #-}
42 {-# VECTORISE SCALAR instance Num Double #-}
43
44
45 infixl 7 *, /
46 infixl 6 +, -
47 infix 4 ==, /=, <, <=, >, >=
48
49 -- Ord ------------------------------------------------------------------------
50 (==), (/=), (<), (<=), (>), (>=) :: Double -> Double -> Bool
51
52 (==) = (P.==)
53 {-# VECTORISE SCALAR (==) #-}
54
55 (/=) = (P./=)
56 {-# VECTORISE SCALAR (/=) #-}
57
58 (<=) = (P.<=)
59 {-# VECTORISE SCALAR (<=) #-}
60
61 (<) = (P.<)
62 {-# VECTORISE SCALAR (<) #-}
63
64 (>=) = (P.>=)
65 {-# VECTORISE SCALAR (>=) #-}
66
67 (>) = (P.>)
68 {-# VECTORISE SCALAR (>) #-}
69
70
71 -- min/max ----------------------------
72 min, max :: Double -> Double -> Double
73
74 min = P.min
75 {-# VECTORISE SCALAR min #-}
76
77 max = P.max
78 {-# VECTORISE SCALAR max #-}
79
80
81 -- minimum/maximum --------------------
82 minimumP, maximumP :: PArr Double -> Double
83
84 minimumP arr = headPArr arr
85 {-# NOINLINE minimumP #-}
86 {-# VECTORISE minimumP = minimumPP #-}
87
88 maximumP arr = headPArr arr
89 {-# NOINLINE maximumP #-}
90 {-# VECTORISE maximumP = maximumPP #-}
91
92 minimumPP, maximumPP :: PArray Double :-> Double
93 minimumPP = L.closure1' (SC.fold1 P.min) (SC.fold1s P.min)
94 {-# INLINE minimumPP #-}
95 {-# NOVECTORISE minimumPP #-}
96
97 maximumPP = L.closure1' (SC.fold1 P.max) (SC.fold1s P.max)
98 {-# INLINE maximumPP #-}
99 {-# NOVECTORISE maximumPP #-}
100
101
102 -- minIndex/maxIndex ------------------
103 minIndexP :: PArr Double -> Int
104 minIndexP !_ = 0
105 {-# NOINLINE minIndexP #-}
106 {-# VECTORISE minIndexP = minIndexPP #-}
107
108 minIndexPP :: PArray Double :-> Int
109 minIndexPP = L.closure1' (SC.fold1Index min') (SC.fold1sIndex min')
110 {-# INLINE minIndexPP #-}
111 {-# NOVECTORISE minIndexPP #-}
112
113 min' :: P.Ord b => (a, b) -> (a, b) -> (a, b)
114 min' (i,x) (j,y) | x P.<= y = (i,x)
115 | P.otherwise = (j,y)
116 {-# NOVECTORISE min' #-}
117
118
119 maxIndexP :: PArr Double -> Int
120 maxIndexP _ = 0
121 {-# NOINLINE maxIndexP #-}
122 {-# VECTORISE maxIndexP = maxIndexPP #-}
123
124 maxIndexPP :: PArray Double :-> Int
125 maxIndexPP = L.closure1' (SC.fold1Index max') (SC.fold1sIndex max')
126 {-# INLINE maxIndexPP #-}
127 {-# NOVECTORISE maxIndexPP #-}
128
129 max' :: P.Ord b => (a, b) -> (a, b) -> (a, b)
130 max' (i,x) (j,y) | x P.>= y = (i,x)
131 | P.otherwise = (j,y)
132 {-# NOVECTORISE max' #-}
133
134
135 -- Num ---------------------------------------------------------------------
136 (+), (-), (*), (/) :: Double -> Double -> Double
137
138 (+) = (P.+)
139 {-# VECTORISE SCALAR (+) #-}
140
141 (-) = (P.-)
142 {-# VECTORISE SCALAR (-) #-}
143
144 (*) = (P.*)
145 {-# VECTORISE SCALAR (*) #-}
146
147 (/) = (P./)
148 {-# VECTORISE SCALAR (/) #-}
149
150 -- negate/abs -------------------------
151 negate, abs :: Double -> Double
152
153 negate = P.negate
154 {-# VECTORISE SCALAR negate #-}
155
156 abs = P.abs
157 {-# VECTORISE SCALAR abs #-}
158
159
160 -- sum/product ------------------------
161 sumP, productP :: PArr Double -> Double
162
163 sumP arr = headPArr arr
164 {-# NOINLINE sumP #-}
165 {-# VECTORISE sumP = sumPP #-}
166
167 productP arr = headPArr arr
168 {-# NOINLINE productP #-}
169 {-# VECTORISE productP = productPP #-}
170
171 sumPP, productPP :: PArray Double :-> Double
172 sumPP = L.closure1' (SC.fold (+) 0) (SC.folds (+) 0)
173 {-# INLINE sumPP #-}
174 {-# NOVECTORISE sumPP #-}
175
176 productPP = L.closure1' (SC.fold (*) 1) (SC.folds (*) 1)
177 {-# INLINE productPP #-}
178 {-# NOVECTORISE productPP #-}
179
180
181 -- Floating -------------------------------------------------------------------
182 pi :: Double
183 pi = P.pi
184 {-# NOVECTORISE pi #-}
185
186 sqrt, exp, log,
187 sin, tan, cos,
188 asin, atan, acos,
189 sinh, tanh, cosh,
190 asinh, atanh, acosh :: Double -> Double
191
192 exp = P.exp
193 {-# VECTORISE SCALAR exp #-}
194
195 sqrt = P.sqrt
196 {-# VECTORISE SCALAR sqrt #-}
197
198 log = P.log
199 {-# VECTORISE SCALAR log #-}
200
201 sin = P.sin
202 {-# VECTORISE SCALAR sin #-}
203
204 tan = P.tan
205 {-# VECTORISE SCALAR tan #-}
206
207 cos = P.cos
208 {-# VECTORISE SCALAR cos #-}
209
210 asin = P.asin
211 {-# VECTORISE SCALAR asin #-}
212
213 atan = P.atan
214 {-# VECTORISE SCALAR atan #-}
215
216 acos = P.acos
217 {-# VECTORISE SCALAR acos #-}
218
219 sinh = P.sinh
220 {-# VECTORISE SCALAR sinh #-}
221
222 tanh = P.tanh
223 {-# VECTORISE SCALAR tanh #-}
224
225 cosh = P.cosh
226 {-# VECTORISE SCALAR cosh #-}
227
228 asinh = P.asinh
229 {-# VECTORISE SCALAR asinh #-}
230
231 atanh = P.atanh
232 {-# VECTORISE SCALAR atanh #-}
233
234 acosh = P.acosh
235 {-# VECTORISE SCALAR acosh #-}
236
237
238 (**), logBase :: Double -> Double -> Double
239
240 (**) = (P.**)
241 {-# VECTORISE SCALAR (**) #-}
242
243 logBase = P.logBase
244 {-# VECTORISE SCALAR logBase #-}
245
246
247 -- RealFrac -------------------------------------------------------------------
248 fromInt :: Int -> Double
249 fromInt = P.fromIntegral
250 {-# VECTORISE SCALAR fromInt #-}