summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL/Vector.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/GSL/Vector.hs')
-rw-r--r--lib/Numeric/GSL/Vector.hs31
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
26import Complex 26import Complex
27import Foreign 27import Foreign
28import Foreign.C.Types(CInt)
29
30fromei = fromIntegral . fromei
28 31
29data FunCodeV = Sin 32data FunCodeV = Sin
30 | Cos 33 | Cos
@@ -73,33 +76,33 @@ data FunCodeS = Norm2
73 76
74toScalarAux fun code v = unsafePerformIO $ do 77toScalarAux 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
79vectorMapAux fun code v = unsafePerformIO $ do 82vectorMapAux 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
84vectorMapValAux fun code val v = unsafePerformIO $ do 87vectorMapValAux 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
91vectorZipAux fun code u v = unsafePerformIO $ do 94vectorZipAux 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.
99toScalarR :: FunCodeS -> Vector Double -> Double 102toScalarR :: FunCodeS -> Vector Double -> Double
100toScalarR oper = toScalarAux c_toScalarR (fromEnum oper) 103toScalarR oper = toScalarAux c_toScalarR (fromei oper)
101 104
102foreign import ccall safe "gsl-aux.h toScalarR" c_toScalarR :: Int -> TVV 105foreign 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
107vectorMapR :: FunCodeV -> Vector Double -> Vector Double 110vectorMapR :: FunCodeV -> Vector Double -> Vector Double
108vectorMapR = vectorMapAux c_vectorMapR 111vectorMapR = vectorMapAux c_vectorMapR
109 112
110foreign import ccall safe "gsl-aux.h mapR" c_vectorMapR :: Int -> TVV 113foreign 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
113vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double) 116vectorMapC :: FunCodeV -> Vector (Complex Double) -> Vector (Complex Double)
114vectorMapC oper = vectorMapAux c_vectorMapC (fromEnum oper) 117vectorMapC oper = vectorMapAux c_vectorMapC (fromei oper)
115 118
116foreign import ccall safe "gsl-aux.h mapC" c_vectorMapC :: Int -> TCVCV 119foreign 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
121vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double 124vectorMapValR :: FunCodeSV -> Double -> Vector Double -> Vector Double
122vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromEnum oper) 125vectorMapValR oper = vectorMapValAux c_vectorMapValR (fromei oper)
123 126
124foreign import ccall safe "gsl-aux.h mapValR" c_vectorMapValR :: Int -> Ptr Double -> TVV 127foreign 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
127vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double) 130vectorMapValC :: FunCodeSV -> Complex Double -> Vector (Complex Double) -> Vector (Complex Double)
128vectorMapValC = vectorMapValAux c_vectorMapValC 131vectorMapValC = vectorMapValAux c_vectorMapValC
129 132
130foreign import ccall safe "gsl-aux.h mapValC" c_vectorMapValC :: Int -> Ptr (Complex Double) -> TCVCV 133foreign 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
135vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double 138vectorZipR :: FunCodeVV -> Vector Double -> Vector Double -> Vector Double
136vectorZipR = vectorZipAux c_vectorZipR 139vectorZipR = vectorZipAux c_vectorZipR
137 140
138foreign import ccall safe "gsl-aux.h zipR" c_vectorZipR :: Int -> TVVV 141foreign 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
141vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double) 144vectorZipC :: FunCodeVV -> Vector (Complex Double) -> Vector (Complex Double) -> Vector (Complex Double)
142vectorZipC = vectorZipAux c_vectorZipC 145vectorZipC = vectorZipAux c_vectorZipC
143 146
144foreign import ccall safe "gsl-aux.h zipC" c_vectorZipC :: Int -> TCVCVCV 147foreign import ccall safe "gsl-aux.h zipC" c_vectorZipC :: CInt -> TCVCVCV