diff options
Diffstat (limited to 'packages/base/src/Internal/Vectorized.hs')
-rw-r--r-- | packages/base/src/Internal/Vectorized.hs | 133 |
1 files changed, 71 insertions, 62 deletions
diff --git a/packages/base/src/Internal/Vectorized.hs b/packages/base/src/Internal/Vectorized.hs index 32430c6..ede3826 100644 --- a/packages/base/src/Internal/Vectorized.hs +++ b/packages/base/src/Internal/Vectorized.hs | |||
@@ -18,10 +18,12 @@ module Internal.Vectorized where | |||
18 | import Internal.Vector | 18 | import Internal.Vector |
19 | import Internal.Devel | 19 | import Internal.Devel |
20 | import Data.Complex | 20 | import Data.Complex |
21 | import Data.Function | ||
22 | import Data.Int | ||
21 | import Foreign.Marshal.Alloc(free,malloc) | 23 | import Foreign.Marshal.Alloc(free,malloc) |
22 | import Foreign.Marshal.Array(newArray,copyArray) | 24 | import Foreign.Marshal.Array(newArray,copyArray) |
23 | import Foreign.Ptr(Ptr) | 25 | import Foreign.Ptr(Ptr) |
24 | import Foreign.Storable(peek,Storable) | 26 | import Foreign.Storable(peek,pokeElemOff,Storable) |
25 | import Foreign.C.Types | 27 | import Foreign.C.Types |
26 | import Foreign.C.String | 28 | import Foreign.C.String |
27 | import System.IO.Unsafe(unsafePerformIO) | 29 | import System.IO.Unsafe(unsafePerformIO) |
@@ -36,8 +38,8 @@ a # b = applyRaw a b | |||
36 | a #! b = a # b # id | 38 | a #! b = a # b # id |
37 | {-# INLINE (#!) #-} | 39 | {-# INLINE (#!) #-} |
38 | 40 | ||
39 | fromei :: Enum a => a -> CInt | 41 | fromei :: Enum a => a -> Int32 |
40 | fromei x = fromIntegral (fromEnum x) :: CInt | 42 | fromei x = fromIntegral (fromEnum x) :: Int32 |
41 | 43 | ||
42 | data FunCodeV = Sin | 44 | data FunCodeV = Sin |
43 | | Cos | 45 | | Cos |
@@ -103,20 +105,20 @@ sumQ = sumg c_sumQ | |||
103 | sumC :: Vector (Complex Double) -> Complex Double | 105 | sumC :: Vector (Complex Double) -> Complex Double |
104 | sumC = sumg c_sumC | 106 | sumC = sumg c_sumC |
105 | 107 | ||
106 | sumI :: ( TransRaw c (CInt -> Ptr a -> IO CInt) ~ (CInt -> Ptr I -> I :> Ok) | 108 | sumI :: ( TransRaw c (Int32 -> Ptr a -> IO Int32) ~ (Int32 -> Ptr I -> I :> Ok) |
107 | , TransArray c | 109 | , TransArray c |
108 | , Storable a | 110 | , Storable a |
109 | ) | 111 | ) |
110 | => I -> c -> a | 112 | => I -> c -> a |
111 | sumI m = sumg (c_sumI m) | 113 | sumI m = sumg (c_sumI m) |
112 | 114 | ||
113 | sumL :: ( TransRaw c (CInt -> Ptr a -> IO CInt) ~ (CInt -> Ptr Z -> Z :> Ok) | 115 | sumL :: ( TransRaw c (Int32 -> Ptr a -> IO Int32) ~ (Int32 -> Ptr Z -> Z :> Ok) |
114 | , TransArray c | 116 | , TransArray c |
115 | , Storable a | 117 | , Storable a |
116 | ) => Z -> c -> a | 118 | ) => Z -> c -> a |
117 | sumL m = sumg (c_sumL m) | 119 | sumL m = sumg (c_sumL m) |
118 | 120 | ||
119 | sumg :: (TransArray c, Storable a) => TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a | 121 | sumg :: (TransArray c, Storable a) => TransRaw c (Int32 -> Ptr a -> IO Int32) -> c -> a |
120 | sumg f x = unsafePerformIO $ do | 122 | sumg f x = unsafePerformIO $ do |
121 | r <- createVector 1 | 123 | r <- createVector 1 |
122 | (x #! r) f #| "sum" | 124 | (x #! r) f #| "sum" |
@@ -154,7 +156,7 @@ prodL :: Z-> Vector Z -> Z | |||
154 | prodL = prodg . c_prodL | 156 | prodL = prodg . c_prodL |
155 | 157 | ||
156 | prodg :: (TransArray c, Storable a) | 158 | prodg :: (TransArray c, Storable a) |
157 | => TransRaw c (CInt -> Ptr a -> IO CInt) -> c -> a | 159 | => TransRaw c (Int32 -> Ptr a -> IO Int32) -> c -> a |
158 | prodg f x = unsafePerformIO $ do | 160 | prodg f x = unsafePerformIO $ do |
159 | r <- createVector 1 | 161 | r <- createVector 1 |
160 | (x #! r) f #| "prod" | 162 | (x #! r) f #| "prod" |
@@ -171,7 +173,7 @@ foreign import ccall unsafe "prodL" c_prodL :: Z -> TVV Z | |||
171 | ------------------------------------------------------------------ | 173 | ------------------------------------------------------------------ |
172 | 174 | ||
173 | toScalarAux :: (Enum a, TransArray c, Storable a1) | 175 | toScalarAux :: (Enum a, TransArray c, Storable a1) |
174 | => (CInt -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) -> a -> c -> a1 | 176 | => (Int32 -> TransRaw c (Int32 -> Ptr a1 -> IO Int32)) -> a -> c -> a1 |
175 | toScalarAux fun code v = unsafePerformIO $ do | 177 | toScalarAux fun code v = unsafePerformIO $ do |
176 | r <- createVector 1 | 178 | r <- createVector 1 |
177 | (v #! r) (fun (fromei code)) #|"toScalarAux" | 179 | (v #! r) (fun (fromei code)) #|"toScalarAux" |
@@ -179,7 +181,7 @@ toScalarAux fun code v = unsafePerformIO $ do | |||
179 | 181 | ||
180 | 182 | ||
181 | vectorMapAux :: (Enum a, Storable t, Storable a1) | 183 | vectorMapAux :: (Enum a, Storable t, Storable a1) |
182 | => (CInt -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt) | 184 | => (Int32 -> Int32 -> Ptr t -> Int32 -> Ptr a1 -> IO Int32) |
183 | -> a -> Vector t -> Vector a1 | 185 | -> a -> Vector t -> Vector a1 |
184 | vectorMapAux fun code v = unsafePerformIO $ do | 186 | vectorMapAux fun code v = unsafePerformIO $ do |
185 | r <- createVector (dim v) | 187 | r <- createVector (dim v) |
@@ -187,7 +189,7 @@ vectorMapAux fun code v = unsafePerformIO $ do | |||
187 | return r | 189 | return r |
188 | 190 | ||
189 | vectorMapValAux :: (Enum a, Storable a2, Storable t, Storable a1) | 191 | vectorMapValAux :: (Enum a, Storable a2, Storable t, Storable a1) |
190 | => (CInt -> Ptr a2 -> CInt -> Ptr t -> CInt -> Ptr a1 -> IO CInt) | 192 | => (Int32 -> Ptr a2 -> Int32 -> Ptr t -> Int32 -> Ptr a1 -> IO Int32) |
191 | -> a -> a2 -> Vector t -> Vector a1 | 193 | -> a -> a2 -> Vector t -> Vector a1 |
192 | vectorMapValAux fun code val v = unsafePerformIO $ do | 194 | vectorMapValAux fun code val v = unsafePerformIO $ do |
193 | r <- createVector (dim v) | 195 | r <- createVector (dim v) |
@@ -197,7 +199,7 @@ vectorMapValAux fun code val v = unsafePerformIO $ do | |||
197 | return r | 199 | return r |
198 | 200 | ||
199 | vectorZipAux :: (Enum a, TransArray c, Storable t, Storable a1) | 201 | vectorZipAux :: (Enum a, TransArray c, Storable t, Storable a1) |
200 | => (CInt -> CInt -> Ptr t -> TransRaw c (CInt -> Ptr a1 -> IO CInt)) | 202 | => (Int32 -> Int32 -> Ptr t -> TransRaw c (Int32 -> Ptr a1 -> IO Int32)) |
201 | -> a -> Vector t -> c -> Vector a1 | 203 | -> a -> Vector t -> c -> Vector a1 |
202 | vectorZipAux fun code u v = unsafePerformIO $ do | 204 | vectorZipAux fun code u v = unsafePerformIO $ do |
203 | r <- createVector (dim u) | 205 | r <- createVector (dim u) |
@@ -210,37 +212,37 @@ vectorZipAux fun code u v = unsafePerformIO $ do | |||
210 | toScalarR :: FunCodeS -> Vector Double -> Double | 212 | toScalarR :: FunCodeS -> Vector Double -> Double |
211 | toScalarR oper = toScalarAux c_toScalarR (fromei oper) | 213 | toScalarR oper = toScalarAux c_toScalarR (fromei oper) |
212 | 214 | ||
213 | foreign import ccall unsafe "toScalarR" c_toScalarR :: CInt -> TVV Double | 215 | foreign import ccall unsafe "toScalarR" c_toScalarR :: Int32 -> TVV Double |
214 | 216 | ||
215 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | 217 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. |
216 | toScalarF :: FunCodeS -> Vector Float -> Float | 218 | toScalarF :: FunCodeS -> Vector Float -> Float |
217 | toScalarF oper = toScalarAux c_toScalarF (fromei oper) | 219 | toScalarF oper = toScalarAux c_toScalarF (fromei oper) |
218 | 220 | ||
219 | foreign import ccall unsafe "toScalarF" c_toScalarF :: CInt -> TVV Float | 221 | foreign import ccall unsafe "toScalarF" c_toScalarF :: Int32 -> TVV Float |
220 | 222 | ||
221 | -- | obtains different functions of a vector: only norm1, norm2 | 223 | -- | obtains different functions of a vector: only norm1, norm2 |
222 | toScalarC :: FunCodeS -> Vector (Complex Double) -> Double | 224 | toScalarC :: FunCodeS -> Vector (Complex Double) -> Double |
223 | toScalarC oper = toScalarAux c_toScalarC (fromei oper) | 225 | toScalarC oper = toScalarAux c_toScalarC (fromei oper) |
224 | 226 | ||
225 | foreign import ccall unsafe "toScalarC" c_toScalarC :: CInt -> Complex Double :> Double :> Ok | 227 | foreign import ccall unsafe "toScalarC" c_toScalarC :: Int32 -> Complex Double :> Double :> Ok |
226 | 228 | ||
227 | -- | obtains different functions of a vector: only norm1, norm2 | 229 | -- | obtains different functions of a vector: only norm1, norm2 |
228 | toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float | 230 | toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float |
229 | toScalarQ oper = toScalarAux c_toScalarQ (fromei oper) | 231 | toScalarQ oper = toScalarAux c_toScalarQ (fromei oper) |
230 | 232 | ||
231 | foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> Complex Float :> Float :> Ok | 233 | foreign import ccall unsafe "toScalarQ" c_toScalarQ :: Int32 -> Complex Float :> Float :> Ok |
232 | 234 | ||
233 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | 235 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. |
234 | toScalarI :: FunCodeS -> Vector CInt -> CInt | 236 | toScalarI :: FunCodeS -> Vector Int32 -> Int32 |
235 | toScalarI oper = toScalarAux c_toScalarI (fromei oper) | 237 | toScalarI oper = toScalarAux c_toScalarI (fromei oper) |
236 | 238 | ||
237 | foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> TVV CInt | 239 | foreign import ccall unsafe "toScalarI" c_toScalarI :: Int32 -> TVV Int32 |
238 | 240 | ||
239 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | 241 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. |
240 | toScalarL :: FunCodeS -> Vector Z -> Z | 242 | toScalarL :: FunCodeS -> Vector Z -> Z |
241 | toScalarL oper = toScalarAux c_toScalarL (fromei oper) | 243 | toScalarL oper = toScalarAux c_toScalarL (fromei oper) |
242 | 244 | ||
243 | foreign import ccall unsafe "toScalarL" c_toScalarL :: CInt -> TVV Z | 245 | foreign import ccall unsafe "toScalarL" c_toScalarL :: Int32 -> TVV Z |
244 | 246 | ||
245 | 247 | ||
246 | ------------------------------------------------------------------ | 248 | ------------------------------------------------------------------ |
@@ -249,37 +251,37 @@ foreign import ccall unsafe "toScalarL" c_toScalarL :: CInt -> TVV Z | |||
249 | vectorMapR :: FunCodeV -> Vector Double -> Vector Double | 251 | vectorMapR :: FunCodeV -> Vector Double -> Vector Double |
250 | vectorMapR = vectorMapAux c_vectorMapR | 252 | vectorMapR = vectorMapAux c_vectorMapR |
251 | 253 | ||
252 | foreign import ccall unsafe "mapR" c_vectorMapR :: CInt -> TVV Double | 254 | foreign import ccall unsafe "mapR" c_vectorMapR :: Int32 -> TVV Double |
253 | 255 | ||
254 | -- | map of complex vectors with given function | 256 | -- | map of complex vectors with given function |
255 | vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) | 257 | vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) |
256 | vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper) | 258 | vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper) |
257 | 259 | ||
258 | foreign import ccall unsafe "mapC" c_vectorMapC :: CInt -> TVV (Complex Double) | 260 | foreign import ccall unsafe "mapC" c_vectorMapC :: Int32 -> TVV (Complex Double) |
259 | 261 | ||
260 | -- | map of real vectors with given function | 262 | -- | map of real vectors with given function |
261 | vectorMapF :: FunCodeV -> Vector Float -> Vector Float | 263 | vectorMapF :: FunCodeV -> Vector Float -> Vector Float |
262 | vectorMapF = vectorMapAux c_vectorMapF | 264 | vectorMapF = vectorMapAux c_vectorMapF |
263 | 265 | ||
264 | foreign import ccall unsafe "mapF" c_vectorMapF :: CInt -> TVV Float | 266 | foreign import ccall unsafe "mapF" c_vectorMapF :: Int32 -> TVV Float |
265 | 267 | ||
266 | -- | map of real vectors with given function | 268 | -- | map of real vectors with given function |
267 | vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float) | 269 | vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float) |
268 | vectorMapQ = vectorMapAux c_vectorMapQ | 270 | vectorMapQ = vectorMapAux c_vectorMapQ |
269 | 271 | ||
270 | foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TVV (Complex Float) | 272 | foreign import ccall unsafe "mapQ" c_vectorMapQ :: Int32 -> TVV (Complex Float) |
271 | 273 | ||
272 | -- | map of real vectors with given function | 274 | -- | map of real vectors with given function |
273 | vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt | 275 | vectorMapI :: FunCodeV -> Vector Int32 -> Vector Int32 |
274 | vectorMapI = vectorMapAux c_vectorMapI | 276 | vectorMapI = vectorMapAux c_vectorMapI |
275 | 277 | ||
276 | foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> TVV CInt | 278 | foreign import ccall unsafe "mapI" c_vectorMapI :: Int32 -> TVV Int32 |
277 | 279 | ||
278 | -- | map of real vectors with given function | 280 | -- | map of real vectors with given function |
279 | vectorMapL :: FunCodeV -> Vector Z -> Vector Z | 281 | vectorMapL :: FunCodeV -> Vector Z -> Vector Z |
280 | vectorMapL = vectorMapAux c_vectorMapL | 282 | vectorMapL = vectorMapAux c_vectorMapL |
281 | 283 | ||
282 | foreign import ccall unsafe "mapL" c_vectorMapL :: CInt -> TVV Z | 284 | foreign import ccall unsafe "mapL" c_vectorMapL :: Int32 -> TVV Z |
283 | 285 | ||
284 | ------------------------------------------------------------------- | 286 | ------------------------------------------------------------------- |
285 | 287 | ||
@@ -287,37 +289,37 @@ foreign import ccall unsafe "mapL" c_vectorMapL :: CInt -> TVV Z | |||
287 | vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double | 289 | vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double |
288 | vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper) | 290 | vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper) |
289 | 291 | ||
290 | foreign import ccall unsafe "mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV Double | 292 | foreign import ccall unsafe "mapValR" c_vectorMapValR :: Int32 -> Ptr Double -> TVV Double |
291 | 293 | ||
292 | -- | map of complex vectors with given function | 294 | -- | map of complex vectors with given function |
293 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) | 295 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) |
294 | vectorMapValC = vectorMapValAux c_vectorMapValC | 296 | vectorMapValC = vectorMapValAux c_vectorMapValC |
295 | 297 | ||
296 | foreign import ccall unsafe "mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TVV (Complex Double) | 298 | foreign import ccall unsafe "mapValC" c_vectorMapValC :: Int32 -> Ptr (Complex Double) -> TVV (Complex Double) |
297 | 299 | ||
298 | -- | map of real vectors with given function | 300 | -- | map of real vectors with given function |
299 | vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float | 301 | vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float |
300 | vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper) | 302 | vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper) |
301 | 303 | ||
302 | foreign import ccall unsafe "mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TVV Float | 304 | foreign import ccall unsafe "mapValF" c_vectorMapValF :: Int32 -> Ptr Float -> TVV Float |
303 | 305 | ||
304 | -- | map of complex vectors with given function | 306 | -- | map of complex vectors with given function |
305 | vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) | 307 | vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) |
306 | vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) | 308 | vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) |
307 | 309 | ||
308 | foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TVV (Complex Float) | 310 | foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: Int32 -> Ptr (Complex Float) -> TVV (Complex Float) |
309 | 311 | ||
310 | -- | map of real vectors with given function | 312 | -- | map of real vectors with given function |
311 | vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt | 313 | vectorMapValI :: FunCodeSV -> Int32 -> Vector Int32 -> Vector Int32 |
312 | vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper) | 314 | vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper) |
313 | 315 | ||
314 | foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> TVV CInt | 316 | foreign import ccall unsafe "mapValI" c_vectorMapValI :: Int32 -> Ptr Int32 -> TVV Int32 |
315 | 317 | ||
316 | -- | map of real vectors with given function | 318 | -- | map of real vectors with given function |
317 | vectorMapValL :: FunCodeSV -> Z -> Vector Z -> Vector Z | 319 | vectorMapValL :: FunCodeSV -> Z -> Vector Z -> Vector Z |
318 | vectorMapValL oper = vectorMapValAux c_vectorMapValL (fromei oper) | 320 | vectorMapValL oper = vectorMapValAux c_vectorMapValL (fromei oper) |
319 | 321 | ||
320 | foreign import ccall unsafe "mapValL" c_vectorMapValL :: CInt -> Ptr Z -> TVV Z | 322 | foreign import ccall unsafe "mapValL" c_vectorMapValL :: Int32 -> Ptr Z -> TVV Z |
321 | 323 | ||
322 | 324 | ||
323 | ------------------------------------------------------------------- | 325 | ------------------------------------------------------------------- |
@@ -328,42 +330,42 @@ type TVVV t = t :> t :> t :> Ok | |||
328 | vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double | 330 | vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double |
329 | vectorZipR = vectorZipAux c_vectorZipR | 331 | vectorZipR = vectorZipAux c_vectorZipR |
330 | 332 | ||
331 | foreign import ccall unsafe "zipR" c_vectorZipR :: CInt -> TVVV Double | 333 | foreign import ccall unsafe "zipR" c_vectorZipR :: Int32 -> TVVV Double |
332 | 334 | ||
333 | -- | elementwise operation on complex vectors | 335 | -- | elementwise operation on complex vectors |
334 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) | 336 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) |
335 | vectorZipC = vectorZipAux c_vectorZipC | 337 | vectorZipC = vectorZipAux c_vectorZipC |
336 | 338 | ||
337 | foreign import ccall unsafe "zipC" c_vectorZipC :: CInt -> TVVV (Complex Double) | 339 | foreign import ccall unsafe "zipC" c_vectorZipC :: Int32 -> TVVV (Complex Double) |
338 | 340 | ||
339 | -- | elementwise operation on real vectors | 341 | -- | elementwise operation on real vectors |
340 | vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float | 342 | vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float |
341 | vectorZipF = vectorZipAux c_vectorZipF | 343 | vectorZipF = vectorZipAux c_vectorZipF |
342 | 344 | ||
343 | foreign import ccall unsafe "zipF" c_vectorZipF :: CInt -> TVVV Float | 345 | foreign import ccall unsafe "zipF" c_vectorZipF :: Int32 -> TVVV Float |
344 | 346 | ||
345 | -- | elementwise operation on complex vectors | 347 | -- | elementwise operation on complex vectors |
346 | vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) | 348 | vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) |
347 | vectorZipQ = vectorZipAux c_vectorZipQ | 349 | vectorZipQ = vectorZipAux c_vectorZipQ |
348 | 350 | ||
349 | foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TVVV (Complex Float) | 351 | foreign import ccall unsafe "zipQ" c_vectorZipQ :: Int32 -> TVVV (Complex Float) |
350 | 352 | ||
351 | -- | elementwise operation on CInt vectors | 353 | -- | elementwise operation on Int32 vectors |
352 | vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt | 354 | vectorZipI :: FunCodeVV -> Vector Int32 -> Vector Int32 -> Vector Int32 |
353 | vectorZipI = vectorZipAux c_vectorZipI | 355 | vectorZipI = vectorZipAux c_vectorZipI |
354 | 356 | ||
355 | foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> TVVV CInt | 357 | foreign import ccall unsafe "zipI" c_vectorZipI :: Int32 -> TVVV Int32 |
356 | 358 | ||
357 | -- | elementwise operation on CInt vectors | 359 | -- | elementwise operation on Int32 vectors |
358 | vectorZipL :: FunCodeVV -> Vector Z -> Vector Z -> Vector Z | 360 | vectorZipL :: FunCodeVV -> Vector Z -> Vector Z -> Vector Z |
359 | vectorZipL = vectorZipAux c_vectorZipL | 361 | vectorZipL = vectorZipAux c_vectorZipL |
360 | 362 | ||
361 | foreign import ccall unsafe "zipL" c_vectorZipL :: CInt -> TVVV Z | 363 | foreign import ccall unsafe "zipL" c_vectorZipL :: Int32 -> TVVV Z |
362 | 364 | ||
363 | -------------------------------------------------------------------------------- | 365 | -------------------------------------------------------------------------------- |
364 | 366 | ||
365 | foreign import ccall unsafe "vectorScan" c_vectorScan | 367 | foreign import ccall unsafe "vectorScan" c_vectorScan |
366 | :: CString -> Ptr CInt -> Ptr (Ptr Double) -> IO CInt | 368 | :: CString -> Ptr Int32 -> Ptr (Ptr Double) -> IO Int32 |
367 | 369 | ||
368 | vectorScan :: FilePath -> IO (Vector Double) | 370 | vectorScan :: FilePath -> IO (Vector Double) |
369 | vectorScan s = do | 371 | vectorScan s = do |
@@ -401,7 +403,7 @@ randomVector seed dist n = unsafePerformIO $ do | |||
401 | (r # id) (c_random_vector (fi seed) ((fi.fromEnum) dist)) #|"randomVector" | 403 | (r # id) (c_random_vector (fi seed) ((fi.fromEnum) dist)) #|"randomVector" |
402 | return r | 404 | return r |
403 | 405 | ||
404 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> Double :> Ok | 406 | foreign import ccall unsafe "random_vector" c_random_vector :: Int32 -> Int32 -> Double :> Ok |
405 | 407 | ||
406 | -------------------------------------------------------------------------------- | 408 | -------------------------------------------------------------------------------- |
407 | 409 | ||
@@ -426,7 +428,7 @@ range n = unsafePerformIO $ do | |||
426 | (r # id) c_range_vector #|"range" | 428 | (r # id) c_range_vector #|"range" |
427 | return r | 429 | return r |
428 | 430 | ||
429 | foreign import ccall unsafe "range_vector" c_range_vector :: CInt :> Ok | 431 | foreign import ccall unsafe "range_vector" c_range_vector :: Int32 :> Ok |
430 | 432 | ||
431 | 433 | ||
432 | float2DoubleV :: Vector Float -> Vector Double | 434 | float2DoubleV :: Vector Float -> Vector Double |
@@ -435,10 +437,10 @@ float2DoubleV = tog c_float2double | |||
435 | double2FloatV :: Vector Double -> Vector Float | 437 | double2FloatV :: Vector Double -> Vector Float |
436 | double2FloatV = tog c_double2float | 438 | double2FloatV = tog c_double2float |
437 | 439 | ||
438 | double2IntV :: Vector Double -> Vector CInt | 440 | double2IntV :: Vector Double -> Vector Int32 |
439 | double2IntV = tog c_double2int | 441 | double2IntV = tog c_double2int |
440 | 442 | ||
441 | int2DoubleV :: Vector CInt -> Vector Double | 443 | int2DoubleV :: Vector Int32 -> Vector Double |
442 | int2DoubleV = tog c_int2double | 444 | int2DoubleV = tog c_int2double |
443 | 445 | ||
444 | double2longV :: Vector Double -> Vector Z | 446 | double2longV :: Vector Double -> Vector Z |
@@ -448,10 +450,10 @@ long2DoubleV :: Vector Z -> Vector Double | |||
448 | long2DoubleV = tog c_long2double | 450 | long2DoubleV = tog c_long2double |
449 | 451 | ||
450 | 452 | ||
451 | float2IntV :: Vector Float -> Vector CInt | 453 | float2IntV :: Vector Float -> Vector Int32 |
452 | float2IntV = tog c_float2int | 454 | float2IntV = tog c_float2int |
453 | 455 | ||
454 | int2floatV :: Vector CInt -> Vector Float | 456 | int2floatV :: Vector Int32 -> Vector Float |
455 | int2floatV = tog c_int2float | 457 | int2floatV = tog c_int2float |
456 | 458 | ||
457 | int2longV :: Vector I -> Vector Z | 459 | int2longV :: Vector I -> Vector Z |
@@ -462,7 +464,7 @@ long2intV = tog c_long2int | |||
462 | 464 | ||
463 | 465 | ||
464 | tog :: (Storable t, Storable a) | 466 | tog :: (Storable t, Storable a) |
465 | => (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a | 467 | => (Int32 -> Ptr t -> Int32 -> Ptr a -> IO Int32) -> Vector t -> Vector a |
466 | tog f v = unsafePerformIO $ do | 468 | tog f v = unsafePerformIO $ do |
467 | r <- createVector (dim v) | 469 | r <- createVector (dim v) |
468 | (v #! r) f #|"tog" | 470 | (v #! r) f #|"tog" |
@@ -470,12 +472,12 @@ tog f v = unsafePerformIO $ do | |||
470 | 472 | ||
471 | foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :> Ok | 473 | foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :> Ok |
472 | foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok | 474 | foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok |
473 | foreign import ccall unsafe "int2double" c_int2double :: CInt :> Double :> Ok | 475 | foreign import ccall unsafe "int2double" c_int2double :: Int32 :> Double :> Ok |
474 | foreign import ccall unsafe "double2int" c_double2int :: Double :> CInt :> Ok | 476 | foreign import ccall unsafe "double2int" c_double2int :: Double :> Int32 :> Ok |
475 | foreign import ccall unsafe "long2double" c_long2double :: Z :> Double :> Ok | 477 | foreign import ccall unsafe "long2double" c_long2double :: Z :> Double :> Ok |
476 | foreign import ccall unsafe "double2long" c_double2long :: Double :> Z :> Ok | 478 | foreign import ccall unsafe "double2long" c_double2long :: Double :> Z :> Ok |
477 | foreign import ccall unsafe "int2float" c_int2float :: CInt :> Float :> Ok | 479 | foreign import ccall unsafe "int2float" c_int2float :: Int32 :> Float :> Ok |
478 | foreign import ccall unsafe "float2int" c_float2int :: Float :> CInt :> Ok | 480 | foreign import ccall unsafe "float2int" c_float2int :: Float :> Int32 :> Ok |
479 | foreign import ccall unsafe "int2long" c_int2long :: I :> Z :> Ok | 481 | foreign import ccall unsafe "int2long" c_int2long :: I :> Z :> Ok |
480 | foreign import ccall unsafe "long2int" c_long2int :: Z :> I :> Ok | 482 | foreign import ccall unsafe "long2int" c_long2int :: Z :> I :> Ok |
481 | 483 | ||
@@ -483,7 +485,7 @@ foreign import ccall unsafe "long2int" c_long2int :: Z :> I :> Ok | |||
483 | --------------------------------------------------------------- | 485 | --------------------------------------------------------------- |
484 | 486 | ||
485 | stepg :: (Storable t, Storable a) | 487 | stepg :: (Storable t, Storable a) |
486 | => (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a | 488 | => (Int32 -> Ptr t -> Int32 -> Ptr a -> IO Int32) -> Vector t -> Vector a |
487 | stepg f v = unsafePerformIO $ do | 489 | stepg f v = unsafePerformIO $ do |
488 | r <- createVector (dim v) | 490 | r <- createVector (dim v) |
489 | (v #! r) f #|"step" | 491 | (v #! r) f #|"step" |
@@ -495,7 +497,7 @@ stepD = stepg c_stepD | |||
495 | stepF :: Vector Float -> Vector Float | 497 | stepF :: Vector Float -> Vector Float |
496 | stepF = stepg c_stepF | 498 | stepF = stepg c_stepF |
497 | 499 | ||
498 | stepI :: Vector CInt -> Vector CInt | 500 | stepI :: Vector Int32 -> Vector Int32 |
499 | stepI = stepg c_stepI | 501 | stepI = stepg c_stepI |
500 | 502 | ||
501 | stepL :: Vector Z -> Vector Z | 503 | stepL :: Vector Z -> Vector Z |
@@ -504,13 +506,13 @@ stepL = stepg c_stepL | |||
504 | 506 | ||
505 | foreign import ccall unsafe "stepF" c_stepF :: TVV Float | 507 | foreign import ccall unsafe "stepF" c_stepF :: TVV Float |
506 | foreign import ccall unsafe "stepD" c_stepD :: TVV Double | 508 | foreign import ccall unsafe "stepD" c_stepD :: TVV Double |
507 | foreign import ccall unsafe "stepI" c_stepI :: TVV CInt | 509 | foreign import ccall unsafe "stepI" c_stepI :: TVV Int32 |
508 | foreign import ccall unsafe "stepL" c_stepL :: TVV Z | 510 | foreign import ccall unsafe "stepL" c_stepL :: TVV Z |
509 | 511 | ||
510 | -------------------------------------------------------------------------------- | 512 | -------------------------------------------------------------------------------- |
511 | 513 | ||
512 | conjugateAux :: (Storable t, Storable a) | 514 | conjugateAux :: (Storable t, Storable a) |
513 | => (CInt -> Ptr t -> CInt -> Ptr a -> IO CInt) -> Vector t -> Vector a | 515 | => (Int32 -> Ptr t -> Int32 -> Ptr a -> IO Int32) -> Vector t -> Vector a |
514 | conjugateAux fun x = unsafePerformIO $ do | 516 | conjugateAux fun x = unsafePerformIO $ do |
515 | v <- createVector (dim x) | 517 | v <- createVector (dim x) |
516 | (x #! v) fun #|"conjugateAux" | 518 | (x #! v) fun #|"conjugateAux" |
@@ -536,22 +538,29 @@ cloneVector v = do | |||
536 | 538 | ||
537 | -------------------------------------------------------------------------------- | 539 | -------------------------------------------------------------------------------- |
538 | 540 | ||
539 | constantAux :: (Storable a1, Storable a) | 541 | constantAux :: Storable a => a -> Int -> Vector a |
540 | => (Ptr a1 -> CInt -> Ptr a -> IO CInt) -> a1 -> Int -> Vector a | 542 | constantAux x n = unsafePerformIO $ do |
541 | constantAux fun x n = unsafePerformIO $ do | ||
542 | v <- createVector n | 543 | v <- createVector n |
543 | px <- newArray [x] | 544 | px <- newArray [x] |
544 | (v # id) (fun px) #|"constantAux" | 545 | (v # id) (constantStorable px) #|"constantAux" |
545 | free px | 546 | free px |
546 | return v | 547 | return v |
547 | 548 | ||
549 | constantStorable :: Storable a => Ptr a -> Int32 -> Ptr a -> IO Int32 | ||
550 | constantStorable pval n p = do | ||
551 | val <- peek pval | ||
552 | ($ 0) $ fix $ \iloop i -> when (i<n) $ do | ||
553 | pokeElemOff p (fromIntegral i) val | ||
554 | iloop $! succ i | ||
555 | return 0 | ||
556 | |||
548 | type TConst t = Ptr t -> t :> Ok | 557 | type TConst t = Ptr t -> t :> Ok |
549 | 558 | ||
550 | foreign import ccall unsafe "constantF" cconstantF :: TConst Float | 559 | foreign import ccall unsafe "constantF" cconstantF :: TConst Float |
551 | foreign import ccall unsafe "constantR" cconstantR :: TConst Double | 560 | foreign import ccall unsafe "constantR" cconstantR :: TConst Double |
552 | foreign import ccall unsafe "constantQ" cconstantQ :: TConst (Complex Float) | 561 | foreign import ccall unsafe "constantQ" cconstantQ :: TConst (Complex Float) |
553 | foreign import ccall unsafe "constantC" cconstantC :: TConst (Complex Double) | 562 | foreign import ccall unsafe "constantC" cconstantC :: TConst (Complex Double) |
554 | foreign import ccall unsafe "constantI" cconstantI :: TConst CInt | 563 | foreign import ccall unsafe "constantI" cconstantI :: TConst Int32 |
555 | foreign import ccall unsafe "constantL" cconstantL :: TConst Z | 564 | foreign import ccall unsafe "constantL" cconstantL :: TConst Z |
556 | 565 | ||
557 | ---------------------------------------------------------------------- | 566 | ---------------------------------------------------------------------- |