summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL
diff options
context:
space:
mode:
authorVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-09-05 02:05:17 +0000
committerVivian McPhail <haskell.vivian.mcphail@gmail.com>2010-09-05 02:05:17 +0000
commitb59a56c22f7e4aa518046c41e049e5bf1cdf8204 (patch)
treecb31cb60b39a3376ab4bcc0a746c4f19817e674b /lib/Numeric/GSL
parentbadf588ae2940df6f4ce144f31e90e8973f144a4 (diff)
add vector Product to Vectors
Diffstat (limited to 'lib/Numeric/GSL')
-rw-r--r--lib/Numeric/GSL/Vector.hs34
-rw-r--r--lib/Numeric/GSL/gsl-aux.c50
2 files changed, 84 insertions, 0 deletions
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs
index 14ba0ff..e8df27c 100644
--- a/lib/Numeric/GSL/Vector.hs
+++ b/lib/Numeric/GSL/Vector.hs
@@ -15,6 +15,7 @@
15 15
16module Numeric.GSL.Vector ( 16module Numeric.GSL.Vector (
17 sumF, sumR, sumQ, sumC, 17 sumF, sumR, sumQ, sumC,
18 prodF, prodR, prodQ, prodC,
18 dotF, dotR, dotQ, dotC, 19 dotF, dotR, dotQ, dotC,
19 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, 20 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ,
20 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ, 21 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ,
@@ -111,6 +112,39 @@ foreign import ccall safe "gsl-aux.h sumR" c_sumR :: TVV
111foreign import ccall safe "gsl-aux.h sumQ" c_sumQ :: TQVQV 112foreign import ccall safe "gsl-aux.h sumQ" c_sumQ :: TQVQV
112foreign import ccall safe "gsl-aux.h sumC" c_sumC :: TCVCV 113foreign import ccall safe "gsl-aux.h sumC" c_sumC :: TCVCV
113 114
115-- | product of elements
116prodF :: Vector Float -> Float
117prodF x = unsafePerformIO $ do
118 r <- createVector 1
119 app2 c_prodF vec x vec r "prodF"
120 return $ r @> 0
121
122-- | product of elements
123prodR :: Vector Double -> Double
124prodR x = unsafePerformIO $ do
125 r <- createVector 1
126 app2 c_prodR vec x vec r "prodR"
127 return $ r @> 0
128
129-- | product of elements
130prodQ :: Vector (Complex Float) -> Complex Float
131prodQ x = unsafePerformIO $ do
132 r <- createVector 1
133 app2 c_prodQ vec x vec r "prodQ"
134 return $ r @> 0
135
136-- | product of elements
137prodC :: Vector (Complex Double) -> Complex Double
138prodC x = unsafePerformIO $ do
139 r <- createVector 1
140 app2 c_prodC vec x vec r "prodC"
141 return $ r @> 0
142
143foreign import ccall safe "gsl-aux.h prodF" c_prodF :: TFF
144foreign import ccall safe "gsl-aux.h prodR" c_prodR :: TVV
145foreign import ccall safe "gsl-aux.h prodQ" c_prodQ :: TQVQV
146foreign import ccall safe "gsl-aux.h prodC" c_prodC :: TCVCV
147
114-- | dot product 148-- | dot product
115dotF :: Vector Float -> Vector Float -> Float 149dotF :: Vector Float -> Vector Float -> Float
116dotF x y = unsafePerformIO $ do 150dotF x y = unsafePerformIO $ do
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c
index 689989d..3e9e2cb 100644
--- a/lib/Numeric/GSL/gsl-aux.c
+++ b/lib/Numeric/GSL/gsl-aux.c
@@ -153,6 +153,56 @@ int sumC(KCVEC(x),CVEC(r)) {
153 OK 153 OK
154} 154}
155 155
156int prodF(KFVEC(x),FVEC(r)) {
157 DEBUGMSG("prodF");
158 REQUIRES(rn==1,BAD_SIZE);
159 int i;
160 float res = 0;
161 for (i = 0; i < xn; i++) res *= xp[i];
162 rp[0] = res;
163 OK
164}
165
166int prodR(KRVEC(x),RVEC(r)) {
167 DEBUGMSG("prodR");
168 REQUIRES(rn==1,BAD_SIZE);
169 int i;
170 double res = 0;
171 for (i = 0; i < xn; i++) res *= xp[i];
172 rp[0] = res;
173 OK
174}
175
176int prodQ(KQVEC(x),QVEC(r)) {
177 DEBUGMSG("prodQ");
178 REQUIRES(rn==1,BAD_SIZE);
179 int i;
180 gsl_complex_float res;
181 res.dat[0] = 0;
182 res.dat[1] = 0;
183 for (i = 0; i < xn; i++) {
184 res.dat[0] = res.dat[0] * xp[i].dat[0] - res.dat[1] * xp[i].dat[1];
185 res.dat[1] = res.dat[0] * xp[i].dat[1] + res.dat[1] * xp[i].dat[0];
186 }
187 rp[0] = res;
188 OK
189}
190
191int prodC(KCVEC(x),CVEC(r)) {
192 DEBUGMSG("prodC");
193 REQUIRES(rn==1,BAD_SIZE);
194 int i;
195 gsl_complex res;
196 res.dat[0] = 0;
197 res.dat[1] = 0;
198 for (i = 0; i < xn; i++) {
199 res.dat[0] = res.dat[0] * xp[i].dat[0] - res.dat[1] * xp[i].dat[1];
200 res.dat[1] = res.dat[0] * xp[i].dat[1] + res.dat[1] * xp[i].dat[0];
201 }
202 rp[0] = res;
203 OK
204}
205
156int dotF(KFVEC(x), KFVEC(y), FVEC(r)) { 206int dotF(KFVEC(x), KFVEC(y), FVEC(r)) {
157 DEBUGMSG("dotF"); 207 DEBUGMSG("dotF");
158 REQUIRES(xn==yn,BAD_SIZE); 208 REQUIRES(xn==yn,BAD_SIZE);