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