diff options
author | Alberto Ruiz <aruiz@um.es> | 2014-05-15 18:51:03 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2014-05-15 18:51:03 +0200 |
commit | 69d1fc1588532b48a946c1501f92ed56600baf4d (patch) | |
tree | 783de9d3dc07a5d1915b044a38982952125faf2e /packages/hmatrix/src/Numeric/GSL/Vector.hs | |
parent | f34e120d08154dc97130eca2bc569d3cdd199270 (diff) |
moved complex mapVal and zip
Diffstat (limited to 'packages/hmatrix/src/Numeric/GSL/Vector.hs')
-rw-r--r-- | packages/hmatrix/src/Numeric/GSL/Vector.hs | 58 |
1 files changed, 1 insertions, 57 deletions
diff --git a/packages/hmatrix/src/Numeric/GSL/Vector.hs b/packages/hmatrix/src/Numeric/GSL/Vector.hs index 5c34f70..e133c2c 100644 --- a/packages/hmatrix/src/Numeric/GSL/Vector.hs +++ b/packages/hmatrix/src/Numeric/GSL/Vector.hs | |||
@@ -24,73 +24,17 @@ module Numeric.GSL.Vector ( | |||
24 | 24 | ||
25 | import Data.Packed | 25 | import Data.Packed |
26 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) | 26 | import Numeric.GSL.Internal hiding (TV,TM,TCV,TCM) |
27 | import Numeric.Vectorized( | 27 | import Numeric.Vectorized |
28 | sumF, sumR, sumQ, sumC, | ||
29 | prodF, prodR, prodQ, prodC, | ||
30 | FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, | ||
31 | FunCodeV(..), vectorMapR, vectorMapF, vectorMapC, vectorMapQ, | ||
32 | FunCodeSV(..), vectorMapValR, vectorMapValF, | ||
33 | FunCodeVV(..), vectorZipR, vectorZipF | ||
34 | ) | ||
35 | 28 | ||
36 | import Data.Complex | 29 | import Data.Complex |
37 | import Foreign.Marshal.Alloc(free) | 30 | import Foreign.Marshal.Alloc(free) |
38 | import Foreign.Marshal.Array(newArray) | ||
39 | import Foreign.Ptr(Ptr) | 31 | import Foreign.Ptr(Ptr) |
40 | import Foreign.C.Types | 32 | import Foreign.C.Types |
41 | import Foreign.C.String(newCString) | 33 | import Foreign.C.String(newCString) |
42 | import System.IO.Unsafe(unsafePerformIO) | 34 | import System.IO.Unsafe(unsafePerformIO) |
43 | import Control.Monad(when) | ||
44 | 35 | ||
45 | fromei x = fromIntegral (fromEnum x) :: CInt | 36 | fromei x = fromIntegral (fromEnum x) :: CInt |
46 | 37 | ||
47 | ------------------------------------------------------------------ | ||
48 | |||
49 | vectorMapAux fun code v = unsafePerformIO $ do | ||
50 | r <- createVector (dim v) | ||
51 | app2 (fun (fromei code)) vec v vec r "vectorMapAux" | ||
52 | return r | ||
53 | |||
54 | vectorMapValAux fun code val v = unsafePerformIO $ do | ||
55 | r <- createVector (dim v) | ||
56 | pval <- newArray [val] | ||
57 | app2 (fun (fromei code) pval) vec v vec r "vectorMapValAux" | ||
58 | free pval | ||
59 | return r | ||
60 | |||
61 | vectorZipAux fun code u v = unsafePerformIO $ do | ||
62 | r <- createVector (dim u) | ||
63 | when (dim u > 0) $ app3 (fun (fromei code)) vec u vec v vec r "vectorZipAux" | ||
64 | return r | ||
65 | |||
66 | --------------------------------------------------------------------- | ||
67 | |||
68 | -- | map of complex vectors with given function | ||
69 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) | ||
70 | vectorMapValC = vectorMapValAux c_vectorMapValC | ||
71 | |||
72 | foreign import ccall unsafe "gsl-aux.h mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TCVCV | ||
73 | |||
74 | -- | map of complex vectors with given function | ||
75 | vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float) | ||
76 | vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper) | ||
77 | |||
78 | foreign import ccall unsafe "gsl-aux.h mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV | ||
79 | |||
80 | ------------------------------------------------------------------- | ||
81 | |||
82 | -- | elementwise operation on complex vectors | ||
83 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) | ||
84 | vectorZipC = vectorZipAux c_vectorZipC | ||
85 | |||
86 | foreign import ccall unsafe "gsl-aux.h zipC" c_vectorZipC :: CInt -> TCVCVCV | ||
87 | |||
88 | -- | elementwise operation on complex vectors | ||
89 | vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float) | ||
90 | vectorZipQ = vectorZipAux c_vectorZipQ | ||
91 | |||
92 | foreign import ccall unsafe "gsl-aux.h zipQ" c_vectorZipQ :: CInt -> TQVQVQV | ||
93 | |||
94 | ----------------------------------------------------------------------- | 38 | ----------------------------------------------------------------------- |
95 | 39 | ||
96 | data RandDist = Uniform -- ^ uniform distribution in [0,1) | 40 | data RandDist = Uniform -- ^ uniform distribution in [0,1) |