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