diff options
Diffstat (limited to 'lib/Numeric/GSL/Vector.hs')
-rw-r--r-- | lib/Numeric/GSL/Vector.hs | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs index 86d8f10..0db2f84 100644 --- a/lib/Numeric/GSL/Vector.hs +++ b/lib/Numeric/GSL/Vector.hs | |||
@@ -25,6 +25,9 @@ import Data.Packed.Internal.Vector | |||
25 | 25 | ||
26 | import Complex | 26 | import Complex |
27 | import Foreign | 27 | import Foreign |
28 | import Foreign.C.Types(CInt) | ||
29 | |||
30 | fromei = fromIntegral . fromei | ||
28 | 31 | ||
29 | data FunCodeV = Sin | 32 | data FunCodeV = Sin |
30 | | Cos | 33 | | Cos |
@@ -73,33 +76,33 @@ data FunCodeS = Norm2 | |||
73 | 76 | ||
74 | toScalarAux fun code v = unsafePerformIO $ do | 77 | toScalarAux fun code v = unsafePerformIO $ do |
75 | r <- createVector 1 | 78 | r <- createVector 1 |
76 | app2 (fun (fromEnum code)) vec v vec r "toScalarAux" | 79 | app2 (fun (fromei code)) vec v vec r "toScalarAux" |
77 | return (r `at` 0) | 80 | return (r `at` 0) |
78 | 81 | ||
79 | vectorMapAux fun code v = unsafePerformIO $ do | 82 | vectorMapAux fun code v = unsafePerformIO $ do |
80 | r <- createVector (dim v) | 83 | r <- createVector (dim v) |
81 | app2 (fun (fromEnum code)) vec v vec r "vectorMapAux" | 84 | app2 (fun (fromei code)) vec v vec r "vectorMapAux" |
82 | return r | 85 | return r |
83 | 86 | ||
84 | vectorMapValAux fun code val v = unsafePerformIO $ do | 87 | vectorMapValAux fun code val v = unsafePerformIO $ do |
85 | r <- createVector (dim v) | 88 | r <- createVector (dim v) |
86 | pval <- newArray [val] | 89 | pval <- newArray [val] |
87 | app2 (fun (fromEnum code) pval) vec v vec r "vectorMapValAux" | 90 | app2 (fun (fromei code) pval) vec v vec r "vectorMapValAux" |
88 | free pval | 91 | free pval |
89 | return r | 92 | return r |
90 | 93 | ||
91 | vectorZipAux fun code u v = unsafePerformIO $ do | 94 | vectorZipAux fun code u v = unsafePerformIO $ do |
92 | r <- createVector (dim u) | 95 | r <- createVector (dim u) |
93 | app3 (fun (fromEnum code)) vec u vec v vec r "vectorZipAux" | 96 | app3 (fun (fromei code)) vec u vec v vec r "vectorZipAux" |
94 | return r | 97 | return r |
95 | 98 | ||
96 | --------------------------------------------------------------------- | 99 | --------------------------------------------------------------------- |
97 | 100 | ||
98 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. | 101 | -- | obtains different functions of a vector: norm1, norm2, max, min, posmax, posmin, etc. |
99 | toScalarR :: FunCodeS -> Vector Double -> Double | 102 | toScalarR :: FunCodeS -> Vector Double -> Double |
100 | toScalarR oper = toScalarAux c_toScalarR (fromEnum oper) | 103 | toScalarR oper = toScalarAux c_toScalarR (fromei oper) |
101 | 104 | ||
102 | foreign import ccall safe "gsl-aux.h toScalarR" c_toScalarR :: Int -> TVV | 105 | foreign import ccall safe "gsl-aux.h toScalarR" c_toScalarR :: CInt -> TVV |
103 | 106 | ||
104 | ------------------------------------------------------------------ | 107 | ------------------------------------------------------------------ |
105 | 108 | ||
@@ -107,27 +110,27 @@ foreign import ccall safe "gsl-aux.h toScalarR" c_toScalarR :: Int -> TVV | |||
107 | vectorMapR :: FunCodeV -> Vector Double -> Vector Double | 110 | vectorMapR :: FunCodeV -> Vector Double -> Vector Double |
108 | vectorMapR = vectorMapAux c_vectorMapR | 111 | vectorMapR = vectorMapAux c_vectorMapR |
109 | 112 | ||
110 | foreign import ccall safe "gsl-aux.h mapR" c_vectorMapR :: Int -> TVV | 113 | foreign import ccall safe "gsl-aux.h mapR" c_vectorMapR :: CInt -> TVV |
111 | 114 | ||
112 | -- | map of complex vectors with given function | 115 | -- | map of complex vectors with given function |
113 | vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) | 116 | vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) |
114 | vectorMapC oper = vectorMapAux c_vectorMapC (fromEnum oper) | 117 | vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper) |
115 | 118 | ||
116 | foreign import ccall safe "gsl-aux.h mapC" c_vectorMapC :: Int -> TCVCV | 119 | foreign import ccall safe "gsl-aux.h mapC" c_vectorMapC :: CInt -> TCVCV |
117 | 120 | ||
118 | ------------------------------------------------------------------- | 121 | ------------------------------------------------------------------- |
119 | 122 | ||
120 | -- | map of real vectors with given function | 123 | -- | map of real vectors with given function |
121 | vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double | 124 | vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double |
122 | vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromEnum oper) | 125 | vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper) |
123 | 126 | ||
124 | foreign import ccall safe "gsl-aux.h mapValR" c_vectorMapValR :: Int -> Ptr Double -> TVV | 127 | foreign import ccall safe "gsl-aux.h mapValR" c_vectorMapValR :: CInt -> Ptr Double -> TVV |
125 | 128 | ||
126 | -- | map of complex vectors with given function | 129 | -- | map of complex vectors with given function |
127 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) | 130 | vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) |
128 | vectorMapValC = vectorMapValAux c_vectorMapValC | 131 | vectorMapValC = vectorMapValAux c_vectorMapValC |
129 | 132 | ||
130 | foreign import ccall safe "gsl-aux.h mapValC" c_vectorMapValC :: Int -> Ptr (Complex Double) -> TCVCV | 133 | foreign import ccall safe "gsl-aux.h mapValC" c_vectorMapValC :: CInt -> Ptr (Complex Double) -> TCVCV |
131 | 134 | ||
132 | ------------------------------------------------------------------- | 135 | ------------------------------------------------------------------- |
133 | 136 | ||
@@ -135,10 +138,10 @@ foreign import ccall safe "gsl-aux.h mapValC" c_vectorMapValC :: Int -> Ptr (Com | |||
135 | vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double | 138 | vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double |
136 | vectorZipR = vectorZipAux c_vectorZipR | 139 | vectorZipR = vectorZipAux c_vectorZipR |
137 | 140 | ||
138 | foreign import ccall safe "gsl-aux.h zipR" c_vectorZipR :: Int -> TVVV | 141 | foreign import ccall safe "gsl-aux.h zipR" c_vectorZipR :: CInt -> TVVV |
139 | 142 | ||
140 | -- | elementwise operation on complex vectors | 143 | -- | elementwise operation on complex vectors |
141 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) | 144 | vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) |
142 | vectorZipC = vectorZipAux c_vectorZipC | 145 | vectorZipC = vectorZipAux c_vectorZipC |
143 | 146 | ||
144 | foreign import ccall safe "gsl-aux.h zipC" c_vectorZipC :: Int -> TCVCVCV | 147 | foreign import ccall safe "gsl-aux.h zipC" c_vectorZipC :: CInt -> TCVCVCV |