b0c1a4c3855274a24c2f549836c045d0ecee1181
[packages/dph.git] / dph-lifted-copy / 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
9 minimumP, maximumP, minIndexP, maxIndexP,
10
11 -- Num
12 (+), (-), (*), negate, abs,
13
14 sumP, productP,
15
16 -- Fractional
17 (/), recip,
18
19 -- Floating
20 pi, exp, sqrt, log, (**), logBase,
21 sin, tan, cos, asin, atan, acos,
22 sinh, tanh, cosh, asinh, atanh, acosh,
23
24 -- RealFrac and similar
25 fromInt,
26
27 truncate, round, ceiling, floor,
28 ) where
29
30 import Data.Array.Parallel.Prim () -- dependency required by the vectoriser
31
32 import Data.Array.Parallel.Prelude.Base
33
34 import Data.Array.Parallel.PArr
35 import Data.Array.Parallel.Lifted.Scalar
36 import Data.Array.Parallel.Lifted.Closure
37
38 import qualified Prelude as P
39
40
41 infixr 8 **
42 infixl 7 *, /
43 infixl 6 +, -
44 infix 4 ==, /=, <, <=, >, >=
45
46
47 (==), (/=), (<), (<=), (>), (>=) :: Double -> Double -> Bool
48 (==) = (P.==)
49 {-# VECTORISE SCALAR (==) #-}
50 (/=) = (P./=)
51 {-# VECTORISE SCALAR (/=) #-}
52 (<=) = (P.<=)
53 {-# VECTORISE SCALAR (<=) #-}
54 (<) = (P.<)
55 {-# VECTORISE SCALAR (<) #-}
56 (>=) = (P.>=)
57 {-# VECTORISE SCALAR (>=) #-}
58 (>) = (P.>)
59 {-# VECTORISE SCALAR (>) #-}
60
61 min, max :: Double -> Double -> Double
62 min = P.min
63 {-# VECTORISE SCALAR min #-}
64 max = P.max
65 {-# VECTORISE SCALAR max #-}
66
67 minimumP, maximumP :: PArr Double -> Double
68 {-# NOINLINE minimumP #-}
69 minimumP a = a `indexPArr` 0
70 {-# VECTORISE minimumP = minimumP_v #-}
71 {-# NOINLINE maximumP #-}
72 maximumP a = a `indexPArr` 0
73 {-# VECTORISE maximumP = maximumP_v #-}
74
75 minimumP_v, maximumP_v:: PArray Double :-> Double
76 {-# INLINE minimumP_v #-}
77 minimumP_v = closure1 (scalar_fold1 P.min) (scalar_fold1s P.min)
78 {-# NOVECTORISE minimumP_v #-}
79 {-# INLINE maximumP_v #-}
80 maximumP_v = closure1 (scalar_fold1 P.max) (scalar_fold1s P.max)
81 {-# NOVECTORISE maximumP_v #-}
82
83 minIndexP :: PArr Double -> Int
84 {-# NOINLINE minIndexP #-}
85 minIndexP _ = 0 -- FIXME: add proper implementation
86 {-# VECTORISE minIndexP = minIndexPA #-}
87
88 minIndexPA :: PArray Double :-> Int
89 {-# INLINE minIndexPA #-}
90 minIndexPA = closure1 (scalar_fold1Index min') (scalar_fold1sIndex min')
91 {-# NOVECTORISE minIndexPA #-}
92
93 min' (i,x) (j,y) | x P.<= y = (i,x)
94 | P.otherwise = (j,y)
95 {-# NOVECTORISE min' #-}
96
97 maxIndexP :: PArr Double -> Int
98 {-# NOINLINE maxIndexP #-}
99 maxIndexP _ = 0 -- FIXME: add proper implementation
100 {-# VECTORISE maxIndexP = maxIndexPA #-}
101
102 maxIndexPA :: PArray Double :-> Int
103 {-# INLINE maxIndexPA #-}
104 maxIndexPA = closure1 (scalar_fold1Index max') (scalar_fold1sIndex max')
105 {-# NOVECTORISE maxIndexPA #-}
106
107 max' (i,x) (j,y) | x P.>= y = (i,x)
108 | P.otherwise = (j,y)
109 {-# NOVECTORISE max' #-}
110
111 (+), (-), (*) :: Double -> Double -> Double
112 (+) = (P.+)
113 {-# VECTORISE SCALAR (+) #-}
114 (-) = (P.-)
115 {-# VECTORISE SCALAR (-) #-}
116 (*) = (P.*)
117 {-# VECTORISE SCALAR (*) #-}
118
119 negate, abs :: Double -> Double
120 negate = P.negate
121 {-# VECTORISE SCALAR negate #-}
122 abs = P.abs
123 {-# VECTORISE SCALAR abs #-}
124
125 sumP, productP :: PArr Double -> Double
126 {-# NOINLINE sumP #-}
127 sumP a = a `indexPArr` 0
128 {-# VECTORISE sumP = sumP_v #-}
129 {-# NOINLINE productP #-}
130 productP a = a `indexPArr` 0
131 {-# VECTORISE productP = productP_v #-}
132
133 sumP_v, productP_v:: PArray Double :-> Double
134 {-# INLINE sumP_v #-}
135 sumP_v = closure1 (scalar_fold (+) 0) (scalar_folds (+) 0)
136 {-# NOVECTORISE sumP_v #-}
137 {-# INLINE productP_v #-}
138 productP_v = closure1 (scalar_fold (*) 1) (scalar_folds (*) 1)
139 {-# NOVECTORISE productP_v #-}
140
141 (/) :: Double -> Double -> Double
142 (/) = (P./)
143 {-# VECTORISE SCALAR (/) #-}
144
145 recip :: Double -> Double
146 recip = P.recip
147 {-# VECTORISE SCALAR recip #-}
148
149 pi :: Double
150 pi = P.pi
151 {-# NOVECTORISE pi #-}
152
153 exp, sqrt, log, sin, tan, cos, asin, atan, acos, sinh, tanh, cosh,
154 asinh, atanh, acosh :: Double -> Double
155 exp = P.exp
156 {-# VECTORISE SCALAR exp #-}
157 sqrt = P.sqrt
158 {-# VECTORISE SCALAR sqrt #-}
159 log = P.log
160 {-# VECTORISE SCALAR log #-}
161 sin = P.sin
162 {-# VECTORISE SCALAR sin #-}
163 tan = P.tan
164 {-# VECTORISE SCALAR tan #-}
165 cos = P.cos
166 {-# VECTORISE SCALAR cos #-}
167 asin = P.asin
168 {-# VECTORISE SCALAR asin #-}
169 atan = P.atan
170 {-# VECTORISE SCALAR atan #-}
171 acos = P.acos
172 {-# VECTORISE SCALAR acos #-}
173 sinh = P.sinh
174 {-# VECTORISE SCALAR sinh #-}
175 tanh = P.tanh
176 {-# VECTORISE SCALAR tanh #-}
177 cosh = P.cosh
178 {-# VECTORISE SCALAR cosh #-}
179 asinh = P.asinh
180 {-# VECTORISE SCALAR asinh #-}
181 atanh = P.atanh
182 {-# VECTORISE SCALAR atanh #-}
183 acosh = P.acosh
184 {-# VECTORISE SCALAR acosh #-}
185
186 (**), logBase :: Double -> Double -> Double
187 (**) = (P.**)
188 {-# VECTORISE SCALAR (**) #-}
189 logBase = P.logBase
190 {-# VECTORISE SCALAR logBase #-}
191
192 fromInt :: Int -> Double
193 fromInt = P.fromIntegral
194 {-# VECTORISE SCALAR fromInt #-}
195
196 truncate, round, ceiling, floor :: Double -> Int
197 truncate = P.truncate
198 {-# VECTORISE SCALAR truncate #-}
199 round = P.round
200 {-# VECTORISE SCALAR round #-}
201 ceiling = P.ceiling
202 {-# VECTORISE SCALAR ceiling #-}
203 floor = P.floor
204 {-# VECTORISE SCALAR floor #-}