diff options
Diffstat (limited to 'lib/Numeric/GSL/Vector.hs')
-rw-r--r-- | lib/Numeric/GSL/Vector.hs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs index d09323b..97a0f9c 100644 --- a/lib/Numeric/GSL/Vector.hs +++ b/lib/Numeric/GSL/Vector.hs | |||
@@ -14,6 +14,8 @@ | |||
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | 15 | ||
16 | module Numeric.GSL.Vector ( | 16 | module Numeric.GSL.Vector ( |
17 | sumF, sumR, sumQ, sumC, | ||
18 | dotF, dotR, dotQ, dotC, | ||
17 | FunCodeS(..), toScalarR, toScalarF, | 19 | FunCodeS(..), toScalarR, toScalarF, |
18 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, | 20 | FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, |
19 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, | 21 | FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, |
@@ -76,6 +78,74 @@ data FunCodeS = Norm2 | |||
76 | 78 | ||
77 | ------------------------------------------------------------------ | 79 | ------------------------------------------------------------------ |
78 | 80 | ||
81 | -- | sum of elements | ||
82 | sumF :: Vector Float -> Float | ||
83 | sumF x = unsafePerformIO $ do | ||
84 | r <- createVector 1 | ||
85 | app2 c_sumF vec x vec r "sumF" | ||
86 | return $ r @> 0 | ||
87 | |||
88 | -- | sum of elements | ||
89 | sumR :: Vector Double -> Double | ||
90 | sumR x = unsafePerformIO $ do | ||
91 | r <- createVector 1 | ||
92 | app2 c_sumR vec x vec r "sumR" | ||
93 | return $ r @> 0 | ||
94 | |||
95 | -- | sum of elements | ||
96 | sumQ :: Vector (Complex Float) -> Complex Float | ||
97 | sumQ x = unsafePerformIO $ do | ||
98 | r <- createVector 1 | ||
99 | app2 c_sumQ vec x vec r "sumQ" | ||
100 | return $ r @> 0 | ||
101 | |||
102 | -- | sum of elements | ||
103 | sumC :: Vector (Complex Double) -> Complex Double | ||
104 | sumC x = unsafePerformIO $ do | ||
105 | r <- createVector 1 | ||
106 | app2 c_sumC vec x vec r "sumC" | ||
107 | return $ r @> 0 | ||
108 | |||
109 | foreign import ccall safe "gsl-aux.h sumF" c_sumF :: TFF | ||
110 | foreign import ccall safe "gsl-aux.h sumR" c_sumR :: TVV | ||
111 | foreign import ccall safe "gsl-aux.h sumQ" c_sumQ :: TQVQV | ||
112 | foreign import ccall safe "gsl-aux.h sumC" c_sumC :: TCVCV | ||
113 | |||
114 | -- | dot product | ||
115 | dotF :: Vector Float -> Vector Float -> Float | ||
116 | dotF x y = unsafePerformIO $ do | ||
117 | r <- createVector 1 | ||
118 | app3 c_dotF vec x vec y vec r "dotF" | ||
119 | return $ r @> 0 | ||
120 | |||
121 | -- | dot product | ||
122 | dotR :: Vector Double -> Vector Double -> Double | ||
123 | dotR x y = unsafePerformIO $ do | ||
124 | r <- createVector 1 | ||
125 | app3 c_dotR vec x vec y vec r "dotR" | ||
126 | return $ r @> 0 | ||
127 | |||
128 | -- | dot product | ||
129 | dotQ :: Vector (Complex Float) -> Vector (Complex Float) -> Complex Float | ||
130 | dotQ x y = unsafePerformIO $ do | ||
131 | r <- createVector 1 | ||
132 | app3 c_dotQ vec x vec y vec r "dotQ" | ||
133 | return $ r @> 0 | ||
134 | |||
135 | -- | dot product | ||
136 | dotC :: Vector (Complex Double) -> Vector (Complex Double) -> Complex Double | ||
137 | dotC x y = unsafePerformIO $ do | ||
138 | r <- createVector 1 | ||
139 | app3 c_dotC vec x vec y vec r "dotC" | ||
140 | return $ r @> 0 | ||
141 | |||
142 | foreign import ccall safe "gsl-aux.h dotF" c_dotF :: TFFF | ||
143 | foreign import ccall safe "gsl-aux.h dotR" c_dotR :: TVVV | ||
144 | foreign import ccall safe "gsl-aux.h dotQ" c_dotQ :: TQVQVQV | ||
145 | foreign import ccall safe "gsl-aux.h dotC" c_dotC :: TCVCVCV | ||
146 | |||
147 | ------------------------------------------------------------------ | ||
148 | |||
79 | toScalarAux fun code v = unsafePerformIO $ do | 149 | toScalarAux fun code v = unsafePerformIO $ do |
80 | r <- createVector 1 | 150 | r <- createVector 1 |
81 | app2 (fun (fromei code)) vec v vec r "toScalarAux" | 151 | app2 (fun (fromei code)) vec v vec r "toScalarAux" |