diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Internal/Vectorized.hs (renamed from packages/base/src/Numeric/Vectorized.hs) | 220 |
1 files changed, 145 insertions, 75 deletions
diff --git a/packages/base/src/Numeric/Vectorized.hs b/packages/base/src/Internal/Vectorized.hs index 589cb49..ddb14c9 100644 --- a/packages/base/src/Numeric/Vectorized.hs +++ b/packages/base/src/Internal/Vectorized.hs | |||
@@ -1,3 +1,5 @@ | |||
1 | {-# LANGUAGE TypeOperators #-} | ||
2 | |||
1 | ----------------------------------------------------------------------------- | 3 | ----------------------------------------------------------------------------- |
2 | -- | | 4 | -- | |
3 | -- Module : Numeric.Vectorized | 5 | -- Module : Numeric.Vectorized |
@@ -10,37 +12,23 @@ | |||
10 | -- | 12 | -- |
11 | ----------------------------------------------------------------------------- | 13 | ----------------------------------------------------------------------------- |
12 | 14 | ||
13 | module Numeric.Vectorized ( | 15 | module Internal.Vectorized where |
14 | sumF, sumR, sumQ, sumC, sumI, | 16 | |
15 | prodF, prodR, prodQ, prodC, prodI, | 17 | import Internal.Tools |
16 | FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, toScalarI, | 18 | import Internal.Vector |
17 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, vectorMapI, | 19 | import Internal.Devel |
18 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ, vectorMapValI, | ||
19 | FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ, vectorZipI, | ||
20 | vectorScan, saveMatrix, | ||
21 | Seed, RandDist(..), randomVector, | ||
22 | roundVector, | ||
23 | range, | ||
24 | -- compareD, compareF, compareI, | ||
25 | -- chooseD, chooseF, chooseI | ||
26 | ) where | ||
27 | |||
28 | import Data.Packed.Internal.Common | ||
29 | import Data.Packed.Internal.Signatures | ||
30 | import Data.Packed.Internal.Vector | ||
31 | import Data.Packed.Internal.Matrix | ||
32 | 20 | ||
33 | import Data.Complex | 21 | import Data.Complex |
34 | import Foreign.Marshal.Alloc(free,malloc) | 22 | import Foreign.Marshal.Alloc(free,malloc) |
35 | import Foreign.Marshal.Array(newArray,copyArray) | 23 | import Foreign.Marshal.Array(newArray,copyArray) |
36 | import Foreign.Ptr(Ptr) | 24 | import Foreign.Ptr(Ptr) |
37 | import Foreign.Storable(peek) | 25 | import Foreign.Storable(peek,Storable) |
38 | import Foreign.C.Types | 26 | import Foreign.C.Types |
39 | import Foreign.C.String | 27 | import Foreign.C.String |
40 | import System.IO.Unsafe(unsafePerformIO) | 28 | import System.IO.Unsafe(unsafePerformIO) |
41 | 29 | ||
42 | import Control.Monad(when) | 30 | import Control.Monad(when) |
43 | 31 | import Data.Vector.Storable ( unsafeWith ) | |
44 | 32 | ||
45 | 33 | ||
46 | fromei x = fromIntegral (fromEnum x) :: CInt | 34 | fromei x = fromIntegral (fromEnum x) :: CInt |
@@ -118,11 +106,13 @@ sumg f x = unsafePerformIO $ do | |||
118 | app2 f vec x vec r "sum" | 106 | app2 f vec x vec r "sum" |
119 | return $ r @> 0 | 107 | return $ r @> 0 |
120 | 108 | ||
121 | foreign import ccall unsafe "sumF" c_sumF :: TFF | 109 | type TVV t = t :> t :> Ok |
122 | foreign import ccall unsafe "sumR" c_sumR :: TVV | 110 | |
123 | foreign import ccall unsafe "sumQ" c_sumQ :: TQVQV | 111 | foreign import ccall unsafe "sumF" c_sumF :: TVV Float |
124 | foreign import ccall unsafe "sumC" c_sumC :: TCVCV | 112 | foreign import ccall unsafe "sumR" c_sumR :: TVV Double |
125 | foreign import ccall unsafe "sumC" c_sumI :: CV CInt (CV CInt (IO CInt)) | 113 | foreign import ccall unsafe "sumQ" c_sumQ :: TVV (Complex Float) |
114 | foreign import ccall unsafe "sumC" c_sumC :: TVV (Complex Double) | ||
115 | foreign import ccall unsafe "sumI" c_sumI :: TVV CInt | ||
126 | 116 | ||
127 | -- | product of elements | 117 | -- | product of elements |
128 | prodF :: Vector Float -> Float | 118 | prodF :: Vector Float -> Float |
@@ -151,18 +141,18 @@ prodg f x = unsafePerformIO $ do | |||
151 | return $ r @> 0 | 141 | return $ r @> 0 |
152 | 142 | ||
153 | 143 | ||
154 | foreign import ccall unsafe "prodF" c_prodF :: TFF | 144 | foreign import ccall unsafe "prodF" c_prodF :: TVV Float |
155 | foreign import ccall unsafe "prodR" c_prodR :: TVV | 145 | foreign import ccall unsafe "prodR" c_prodR :: TVV Double |
156 | foreign import ccall unsafe "prodQ" c_prodQ :: TQVQV | 146 | foreign import ccall unsafe "prodQ" c_prodQ :: TVV (Complex Float) |
157 | foreign import ccall unsafe "prodC" c_prodC :: TCVCV | 147 | foreign import ccall unsafe "prodC" c_prodC :: TVV (Complex Double) |
158 | foreign import ccall unsafe "prodI" c_prodI :: CV CInt (CV CInt (IO CInt)) | 148 | foreign import ccall unsafe "prodI" c_prodI :: TVV (CInt) |
159 | 149 | ||
160 | ------------------------------------------------------------------ | 150 | ------------------------------------------------------------------ |
161 | 151 | ||
162 | toScalarAux fun code v = unsafePerformIO $ do | 152 | toScalarAux fun code v = unsafePerformIO $ do |
163 | r <- createVector 1 | 153 | r <- createVector 1 |
164 | app2 (fun (fromei code)) vec v vec r "toScalarAux" | 154 | app2 (fun (fromei code)) vec v vec r "toScalarAux" |
165 | return (r `at` 0) | 155 | return (r @> 0) |
166 | 156 | ||
167 | vectorMapAux fun code v = unsafePerformIO $ do | 157 | vectorMapAux fun code v = unsafePerformIO $ do |
168 | r <- createVector (dim v) | 158 | r <- createVector (dim v) |
@@ -187,31 +177,31 @@ vectorZipAux fun code u v = unsafePerformIO $ do | |||
187 | toScalarR :: FunCodeS -> Vector Double -> Double | 177 | toScalarR :: FunCodeS -> Vector Double -> Double |
188 | toScalarR oper = toScalarAux c_toScalarR (fromei oper) | 178 | toScalarR oper = toScalarAux c_toScalarR (fromei oper) |
189 | 179 | ||
190 | foreign import ccall unsafe "toScalarR" c_toScalarR :: CInt -> TVV | 180 | foreign import ccall unsafe "toScalarR" c_toScalarR :: CInt -> TVV Double |
191 | 181 | ||
192 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | 182 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. |
193 | toScalarF :: FunCodeS -> Vector Float -> Float | 183 | toScalarF :: FunCodeS -> Vector Float -> Float |
194 | toScalarF oper = toScalarAux c_toScalarF (fromei oper) | 184 | toScalarF oper = toScalarAux c_toScalarF (fromei oper) |
195 | 185 | ||
196 | foreign import ccall unsafe "toScalarF" c_toScalarF :: CInt -> TFF | 186 | foreign import ccall unsafe "toScalarF" c_toScalarF :: CInt -> TVV Float |
197 | 187 | ||
198 | -- | obtains different functions of a vector: only norm1, norm2 | 188 | -- | obtains different functions of a vector: only norm1, norm2 |
199 | toScalarC :: FunCodeS -> Vector (Complex Double) -> Double | 189 | toScalarC :: FunCodeS -> Vector (Complex Double) -> Double |
200 | toScalarC oper = toScalarAux c_toScalarC (fromei oper) | 190 | toScalarC oper = toScalarAux c_toScalarC (fromei oper) |
201 | 191 | ||
202 | foreign import ccall unsafe "toScalarC" c_toScalarC :: CInt -> TCVV | 192 | foreign import ccall unsafe "toScalarC" c_toScalarC :: CInt -> Complex Double :> Double :> Ok |
203 | 193 | ||
204 | -- | obtains different functions of a vector: only norm1, norm2 | 194 | -- | obtains different functions of a vector: only norm1, norm2 |
205 | toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float | 195 | toScalarQ :: FunCodeS -> Vector (Complex Float) -> Float |
206 | toScalarQ oper = toScalarAux c_toScalarQ (fromei oper) | 196 | toScalarQ oper = toScalarAux c_toScalarQ (fromei oper) |
207 | 197 | ||
208 | foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> TQVF | 198 | foreign import ccall unsafe "toScalarQ" c_toScalarQ :: CInt -> Complex Float :> Float :> Ok |
209 | 199 | ||
210 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | 200 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. |
211 | toScalarI :: FunCodeS -> Vector CInt -> CInt | 201 | toScalarI :: FunCodeS -> Vector CInt -> CInt |
212 | toScalarI oper = toScalarAux c_toScalarI (fromei oper) | 202 | toScalarI oper = toScalarAux c_toScalarI (fromei oper) |
213 | 203 | ||
214 | foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> CV CInt (CV CInt (IO CInt)) | 204 | foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> TVV CInt |
215 | 205 | ||
216 | ------------------------------------------------------------------ | 206 | ------------------------------------------------------------------ |
217 | 207 | ||
@@ -219,31 +209,31 @@ foreign import ccall unsafe "toScalarI" c_toScalarI :: CInt -> CV CInt (CV CInt | |||
219 | vectorMapR :: FunCodeV -> Vector Double -> Vector Double | 209 | vectorMapR :: FunCodeV -> Vector Double -> Vector Double |
220 | vectorMapR = vectorMapAux c_vectorMapR | 210 | vectorMapR = vectorMapAux c_vectorMapR |
221 | 211 | ||
222 | foreign import ccall unsafe "mapR" c_vectorMapR :: CInt -> TVV | 212 | foreign import ccall unsafe "mapR" c_vectorMapR :: CInt -> TVV Double |
223 | 213 | ||
224 | -- | map of complex vectors with given function | 214 | -- | map of complex vectors with given function |
225 | vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) | 215 | vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) |
226 | vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper) | 216 | vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper) |
227 | 217 | ||
228 | foreign import ccall unsafe "mapC" c_vectorMapC :: CInt -> TCVCV | 218 | foreign import ccall unsafe "mapC" c_vectorMapC :: CInt -> TVV (Complex Double) |
229 | 219 | ||
230 | -- | map of real vectors with given function | 220 | -- | map of real vectors with given function |
231 | vectorMapF :: FunCodeV -> Vector Float -> Vector Float | 221 | vectorMapF :: FunCodeV -> Vector Float -> Vector Float |
232 | vectorMapF = vectorMapAux c_vectorMapF | 222 | vectorMapF = vectorMapAux c_vectorMapF |
233 | 223 | ||
234 | foreign import ccall unsafe "mapF" c_vectorMapF :: CInt -> TFF | 224 | foreign import ccall unsafe "mapF" c_vectorMapF :: CInt -> TVV Float |
235 | 225 | ||
236 | -- | map of real vectors with given function | 226 | -- | map of real vectors with given function |
237 | vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float) | 227 | vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float) |
238 | vectorMapQ = vectorMapAux c_vectorMapQ | 228 | vectorMapQ = vectorMapAux c_vectorMapQ |
239 | 229 | ||
240 | foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TQVQV | 230 | foreign import ccall unsafe "mapQ" c_vectorMapQ :: CInt -> TVV (Complex Float) |
241 | 231 | ||
242 | -- | map of real vectors with given function | 232 | -- | map of real vectors with given function |
243 | vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt | 233 | vectorMapI :: FunCodeV -> Vector CInt -> Vector CInt |
244 | vectorMapI = vectorMapAux c_vectorMapI | 234 | vectorMapI = vectorMapAux c_vectorMapI |
245 | 235 | ||
246 | foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> CV CInt (CV CInt (IO CInt)) | 236 | foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> TVV CInt |
247 | 237 | ||
248 | ------------------------------------------------------------------- | 238 | ------------------------------------------------------------------- |
249 | 239 | ||
@@ -251,64 +241,66 @@ foreign import ccall unsafe "mapI" c_vectorMapI :: CInt -> CV CInt (CV CInt (IO | |||
251 | vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double | 241 | vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double |
252 | vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper) | 242 | vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper) |
253 | 243 | ||
254 | foreign import ccall unsafe "mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV | 244 | foreign import ccall unsafe "mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV Double |
255 | 245 | ||
256 | -- | map of complex vectors with given function | 246 | -- | map of complex vectors with given function |
257 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) | 247 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) |
258 | vectorMapValC = vectorMapValAux c_vectorMapValC | 248 | vectorMapValC = vectorMapValAux c_vectorMapValC |
259 | 249 | ||
260 | foreign import ccall unsafe "mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TCVCV | 250 | foreign import ccall unsafe "mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TVV (Complex Double) |
261 | 251 | ||
262 | -- | map of real vectors with given function | 252 | -- | map of real vectors with given function |
263 | vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float | 253 | vectorMapValF :: FunCodeSV -> Float -> Vector Float -> Vector Float |
264 | vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper) | 254 | vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper) |
265 | 255 | ||
266 | foreign import ccall unsafe "mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TFF | 256 | foreign import ccall unsafe "mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TVV Float |
267 | 257 | ||
268 | -- | map of complex vectors with given function | 258 | -- | map of complex vectors with given function |
269 | vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) | 259 | vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) |
270 | vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) | 260 | vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) |
271 | 261 | ||
272 | foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV | 262 | foreign import ccall unsafe "mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TVV (Complex Float) |
273 | 263 | ||
274 | -- | map of real vectors with given function | 264 | -- | map of real vectors with given function |
275 | vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt | 265 | vectorMapValI :: FunCodeSV -> CInt -> Vector CInt -> Vector CInt |
276 | vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper) | 266 | vectorMapValI oper = vectorMapValAux c_vectorMapValI (fromei oper) |
277 | 267 | ||
278 | foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> CV CInt (CV CInt (IO CInt)) | 268 | foreign import ccall unsafe "mapValI" c_vectorMapValI :: CInt -> Ptr CInt -> TVV CInt |
279 | 269 | ||
280 | 270 | ||
281 | ------------------------------------------------------------------- | 271 | ------------------------------------------------------------------- |
282 | 272 | ||
273 | type TVVV t = t :> t :> t :> Ok | ||
274 | |||
283 | -- | elementwise operation on real vectors | 275 | -- | elementwise operation on real vectors |
284 | vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double | 276 | vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double |
285 | vectorZipR = vectorZipAux c_vectorZipR | 277 | vectorZipR = vectorZipAux c_vectorZipR |
286 | 278 | ||
287 | foreign import ccall unsafe "zipR" c_vectorZipR :: CInt -> TVVV | 279 | foreign import ccall unsafe "zipR" c_vectorZipR :: CInt -> TVVV Double |
288 | 280 | ||
289 | -- | elementwise operation on complex vectors | 281 | -- | elementwise operation on complex vectors |
290 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) | 282 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) |
291 | vectorZipC = vectorZipAux c_vectorZipC | 283 | vectorZipC = vectorZipAux c_vectorZipC |
292 | 284 | ||
293 | foreign import ccall unsafe "zipC" c_vectorZipC :: CInt -> TCVCVCV | 285 | foreign import ccall unsafe "zipC" c_vectorZipC :: CInt -> TVVV (Complex Double) |
294 | 286 | ||
295 | -- | elementwise operation on real vectors | 287 | -- | elementwise operation on real vectors |
296 | vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float | 288 | vectorZipF :: FunCodeVV -> Vector Float -> Vector Float -> Vector Float |
297 | vectorZipF = vectorZipAux c_vectorZipF | 289 | vectorZipF = vectorZipAux c_vectorZipF |
298 | 290 | ||
299 | foreign import ccall unsafe "zipF" c_vectorZipF :: CInt -> TFFF | 291 | foreign import ccall unsafe "zipF" c_vectorZipF :: CInt -> TVVV Float |
300 | 292 | ||
301 | -- | elementwise operation on complex vectors | 293 | -- | elementwise operation on complex vectors |
302 | vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) | 294 | vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) |
303 | vectorZipQ = vectorZipAux c_vectorZipQ | 295 | vectorZipQ = vectorZipAux c_vectorZipQ |
304 | 296 | ||
305 | foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TQVQVQV | 297 | foreign import ccall unsafe "zipQ" c_vectorZipQ :: CInt -> TVVV (Complex Float) |
306 | 298 | ||
307 | -- | elementwise operation on CInt vectors | 299 | -- | elementwise operation on CInt vectors |
308 | vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt | 300 | vectorZipI :: FunCodeVV -> Vector CInt -> Vector CInt -> Vector CInt |
309 | vectorZipI = vectorZipAux c_vectorZipI | 301 | vectorZipI = vectorZipAux c_vectorZipI |
310 | 302 | ||
311 | foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> CV CInt (CV CInt (CV CInt (IO CInt))) | 303 | foreign import ccall unsafe "zipI" c_vectorZipI :: CInt -> TVVV CInt |
312 | 304 | ||
313 | 305 | ||
314 | -------------------------------------------------------------------------------- | 306 | -------------------------------------------------------------------------------- |
@@ -336,26 +328,6 @@ vectorScan s = do | |||
336 | 328 | ||
337 | -------------------------------------------------------------------------------- | 329 | -------------------------------------------------------------------------------- |
338 | 330 | ||
339 | foreign import ccall unsafe "saveMatrix" c_saveMatrix | ||
340 | :: CString -> CString -> TM | ||
341 | |||
342 | {- | save a matrix as a 2D ASCII table | ||
343 | -} | ||
344 | saveMatrix | ||
345 | :: FilePath | ||
346 | -> String -- ^ \"printf\" format (e.g. \"%.2f\", \"%g\", etc.) | ||
347 | -> Matrix Double | ||
348 | -> IO () | ||
349 | saveMatrix name format m = do | ||
350 | cname <- newCString name | ||
351 | cformat <- newCString format | ||
352 | app1 (c_saveMatrix cname cformat) mat m "saveMatrix" | ||
353 | free cname | ||
354 | free cformat | ||
355 | return () | ||
356 | |||
357 | -------------------------------------------------------------------------------- | ||
358 | |||
359 | type Seed = Int | 331 | type Seed = Int |
360 | 332 | ||
361 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | 333 | data RandDist = Uniform -- ^ uniform distribution in [0,1) |
@@ -372,7 +344,7 @@ randomVector seed dist n = unsafePerformIO $ do | |||
372 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" | 344 | app1 (c_random_vector (fi seed) ((fi.fromEnum) dist)) vec r "randomVector" |
373 | return r | 345 | return r |
374 | 346 | ||
375 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> TV | 347 | foreign import ccall unsafe "random_vector" c_random_vector :: CInt -> CInt -> Double :> Ok |
376 | 348 | ||
377 | -------------------------------------------------------------------------------- | 349 | -------------------------------------------------------------------------------- |
378 | 350 | ||
@@ -381,7 +353,7 @@ roundVector v = unsafePerformIO $ do | |||
381 | app2 c_round_vector vec v vec r "roundVector" | 353 | app2 c_round_vector vec v vec r "roundVector" |
382 | return r | 354 | return r |
383 | 355 | ||
384 | foreign import ccall unsafe "round_vector" c_round_vector :: TVV | 356 | foreign import ccall unsafe "round_vector" c_round_vector :: TVV Double |
385 | 357 | ||
386 | -------------------------------------------------------------------------------- | 358 | -------------------------------------------------------------------------------- |
387 | 359 | ||
@@ -395,5 +367,103 @@ range n = unsafePerformIO $ do | |||
395 | app1 c_range_vector vec r "range" | 367 | app1 c_range_vector vec r "range" |
396 | return r | 368 | return r |
397 | 369 | ||
398 | foreign import ccall unsafe "range_vector" c_range_vector :: CV CInt (IO CInt) | 370 | foreign import ccall unsafe "range_vector" c_range_vector :: CInt :> Ok |
371 | |||
372 | |||
373 | float2DoubleV :: Vector Float -> Vector Double | ||
374 | float2DoubleV = tog c_float2double | ||
375 | |||
376 | double2FloatV :: Vector Double -> Vector Float | ||
377 | double2FloatV = tog c_double2float | ||
378 | |||
379 | double2IntV :: Vector Double -> Vector CInt | ||
380 | double2IntV = tog c_double2int | ||
381 | |||
382 | int2DoubleV :: Vector CInt -> Vector Double | ||
383 | int2DoubleV = tog c_int2double | ||
384 | |||
385 | float2IntV :: Vector Float -> Vector CInt | ||
386 | float2IntV = tog c_float2int | ||
387 | |||
388 | int2floatV :: Vector CInt -> Vector Float | ||
389 | int2floatV = tog c_int2float | ||
390 | |||
391 | |||
392 | tog f v = unsafePerformIO $ do | ||
393 | r <- createVector (dim v) | ||
394 | app2 f vec v vec r "tog" | ||
395 | return r | ||
396 | |||
397 | foreign import ccall unsafe "float2double" c_float2double :: Float :> Double :> Ok | ||
398 | foreign import ccall unsafe "double2float" c_double2float :: Double :> Float :> Ok | ||
399 | foreign import ccall unsafe "int2double" c_int2double :: CInt :> Double :> Ok | ||
400 | foreign import ccall unsafe "double2int" c_double2int :: Double :> CInt :> Ok | ||
401 | foreign import ccall unsafe "int2float" c_int2float :: CInt :> Float :> Ok | ||
402 | foreign import ccall unsafe "float2int" c_float2int :: Float :> CInt :> Ok | ||
403 | |||
404 | |||
405 | --------------------------------------------------------------- | ||
406 | |||
407 | stepg f v = unsafePerformIO $ do | ||
408 | r <- createVector (dim v) | ||
409 | app2 f vec v vec r "step" | ||
410 | return r | ||
411 | |||
412 | stepD :: Vector Double -> Vector Double | ||
413 | stepD = stepg c_stepD | ||
414 | |||
415 | stepF :: Vector Float -> Vector Float | ||
416 | stepF = stepg c_stepF | ||
417 | |||
418 | stepI :: Vector CInt -> Vector CInt | ||
419 | stepI = stepg c_stepI | ||
420 | |||
421 | foreign import ccall unsafe "stepF" c_stepF :: TVV Float | ||
422 | foreign import ccall unsafe "stepD" c_stepD :: TVV Double | ||
423 | foreign import ccall unsafe "stepI" c_stepI :: TVV CInt | ||
424 | |||
425 | |||
426 | -------------------------------------------------------------------------------- | ||
427 | |||
428 | conjugateAux fun x = unsafePerformIO $ do | ||
429 | v <- createVector (dim x) | ||
430 | app2 fun vec x vec v "conjugateAux" | ||
431 | return v | ||
432 | |||
433 | conjugateQ :: Vector (Complex Float) -> Vector (Complex Float) | ||
434 | conjugateQ = conjugateAux c_conjugateQ | ||
435 | foreign import ccall unsafe "conjugateQ" c_conjugateQ :: TVV (Complex Float) | ||
436 | |||
437 | conjugateC :: Vector (Complex Double) -> Vector (Complex Double) | ||
438 | conjugateC = conjugateAux c_conjugateC | ||
439 | foreign import ccall unsafe "conjugateC" c_conjugateC :: TVV (Complex Double) | ||
440 | |||
441 | -------------------------------------------------------------------------------- | ||
442 | |||
443 | cloneVector :: Storable t => Vector t -> IO (Vector t) | ||
444 | cloneVector v = do | ||
445 | let n = dim v | ||
446 | r <- createVector n | ||
447 | let f _ s _ d = copyArray d s n >> return 0 | ||
448 | app2 f vec v vec r "cloneVector" | ||
449 | return r | ||
450 | |||
451 | -------------------------------------------------------------------------------- | ||
452 | |||
453 | constantAux fun x n = unsafePerformIO $ do | ||
454 | v <- createVector n | ||
455 | px <- newArray [x] | ||
456 | app1 (fun px) vec v "constantAux" | ||
457 | free px | ||
458 | return v | ||
459 | |||
460 | type TConst t = Ptr t -> t :> Ok | ||
461 | |||
462 | foreign import ccall unsafe "constantF" cconstantF :: TConst Float | ||
463 | foreign import ccall unsafe "constantR" cconstantR :: TConst Double | ||
464 | foreign import ccall unsafe "constantQ" cconstantQ :: TConst (Complex Float) | ||
465 | foreign import ccall unsafe "constantC" cconstantC :: TConst (Complex Double) | ||
466 | foreign import ccall unsafe "constantI" cconstantI :: TConst CInt | ||
467 | |||
468 | ---------------------------------------------------------------------- | ||
399 | 469 | ||