Adapted to simplified VECTORISE pragmas
[packages/dph.git] / dph-lifted-copy / Data / Array / Parallel / Prelude / Float.hs
1 {-# OPTIONS_GHC -fvectorise #-}
2
3 module Data.Array.Parallel.Prelude.Float (
4 Float,
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 import Prelude (Int, Float)
40
41
42 infixr 8 **
43 infixl 7 *, /
44 infixl 6 +, -
45 infix 4 ==, /=, <, <=, >, >=
46
47
48 (==), (/=), (<), (<=), (>), (>=) :: Float -> Float -> Bool
49 (==) = (P.==)
50 (/=) = (P./=)
51 (<=) = (P.<=)
52 (<) = (P.<)
53 (>=) = (P.>=)
54 (>) = (P.>)
55
56 min, max :: Float -> Float -> Float
57 min = P.min
58 max = P.max
59
60 minimumP, maximumP :: PArr Float -> Float
61 {-# NOINLINE minimumP #-}
62 minimumP a = a `indexPArr` 0
63 {-# VECTORISE minimumP = minimumP_v #-}
64 {-# NOINLINE maximumP #-}
65 maximumP a = a `indexPArr` 0
66 {-# VECTORISE maximumP = maximumP_v #-}
67
68 minimumP_v, maximumP_v:: PArray Float :-> Float
69 {-# INLINE minimumP_v #-}
70 minimumP_v = closure1 (scalar_fold1 P.min) (scalar_fold1s P.min)
71 {-# NOVECTORISE minimumP_v #-}
72 {-# INLINE maximumP_v #-}
73 maximumP_v = closure1 (scalar_fold1 P.max) (scalar_fold1s P.max)
74 {-# NOVECTORISE maximumP_v #-}
75
76 minIndexP :: PArr Float -> Int
77 {-# NOINLINE minIndexP #-}
78 minIndexP _ = 0 -- FIXME: add proper implementation
79 {-# VECTORISE minIndexP = minIndexPA #-}
80
81 minIndexPA :: PArray Float :-> Int
82 {-# INLINE minIndexPA #-}
83 minIndexPA = closure1 (scalar_fold1Index min') (scalar_fold1sIndex min')
84 {-# NOVECTORISE minIndexPA #-}
85
86 min' (i,x) (j,y) | x P.<= y = (i,x)
87 | P.otherwise = (j,y)
88 {-# NOVECTORISE min' #-}
89
90 maxIndexP :: PArr Float -> Int
91 {-# NOINLINE maxIndexP #-}
92 maxIndexP _ = 0 -- FIXME: add proper implementation
93 {-# VECTORISE maxIndexP = maxIndexPA #-}
94
95 maxIndexPA :: PArray Float :-> Int
96 {-# INLINE maxIndexPA #-}
97 maxIndexPA = closure1 (scalar_fold1Index max') (scalar_fold1sIndex max')
98 {-# NOVECTORISE maxIndexPA #-}
99
100 max' (i,x) (j,y) | x P.>= y = (i,x)
101 | P.otherwise = (j,y)
102 {-# NOVECTORISE max' #-}
103
104 (+), (-), (*) :: Float -> Float -> Float
105 (+) = (P.+)
106 (-) = (P.-)
107 (*) = (P.*)
108
109 negate, abs :: Float -> Float
110 negate = P.negate
111 abs = P.abs
112
113 sumP, productP :: PArr Float -> Float
114 {-# NOINLINE sumP #-}
115 sumP a = a `indexPArr` 0
116 {-# VECTORISE sumP = sumP_v #-}
117 {-# NOINLINE productP #-}
118 productP a = a `indexPArr` 0
119 {-# VECTORISE productP = productP_v #-}
120
121 sumP_v, productP_v:: PArray Float :-> Float
122 {-# INLINE sumP_v #-}
123 sumP_v = closure1 (scalar_fold (+) 0) (scalar_folds (+) 0)
124 {-# NOVECTORISE sumP_v #-}
125 {-# INLINE productP_v #-}
126 productP_v = closure1 (scalar_fold (*) 1) (scalar_folds (*) 1)
127 {-# NOVECTORISE productP_v #-}
128
129 (/) :: Float -> Float -> Float
130 (/) = (P./)
131
132 recip :: Float -> Float
133 recip = P.recip
134
135 pi :: Float
136 pi = P.pi
137 {-# NOVECTORISE pi #-}
138
139 exp, sqrt, log, sin, tan, cos, asin, atan, acos, sinh, tanh, cosh,
140 asinh, atanh, acosh :: Float -> Float
141 exp = P.exp
142 sqrt = P.sqrt
143 log = P.log
144 sin = P.sin
145 tan = P.tan
146 cos = P.cos
147 asin = P.asin
148 atan = P.atan
149 acos = P.acos
150 sinh = P.sinh
151 tanh = P.tanh
152 cosh = P.cosh
153 asinh = P.asinh
154 atanh = P.atanh
155 acosh = P.acosh
156
157 (**), logBase :: Float -> Float -> Float
158 (**) = (P.**)
159 logBase = P.logBase
160
161 fromInt :: Int -> Float
162 fromInt = P.fromIntegral
163
164 truncate, round, ceiling, floor :: Float -> Int
165 truncate = P.truncate
166 round = P.round
167 ceiling = P.ceiling
168 floor = P.floor