summaryrefslogtreecommitdiff
path: root/lib/Numeric/GSL
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Numeric/GSL')
-rw-r--r--lib/Numeric/GSL/Vector.hs24
-rw-r--r--lib/Numeric/GSL/gsl-aux.c126
2 files changed, 147 insertions, 3 deletions
diff --git a/lib/Numeric/GSL/Vector.hs b/lib/Numeric/GSL/Vector.hs
index 0148c4f..14ba0ff 100644
--- a/lib/Numeric/GSL/Vector.hs
+++ b/lib/Numeric/GSL/Vector.hs
@@ -17,9 +17,9 @@ module Numeric.GSL.Vector (
17 sumF, sumR, sumQ, sumC, 17 sumF, sumR, sumQ, sumC,
18 dotF, dotR, dotQ, dotC, 18 dotF, dotR, dotQ, dotC,
19 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ, 19 FunCodeS(..), toScalarR, toScalarF, toScalarC, toScalarQ,
20 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, 20 FunCodeV(..), vectorMapR, vectorMapC, vectorMapF, vectorMapQ,
21 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, 21 FunCodeSV(..), vectorMapValR, vectorMapValC, vectorMapValF, vectorMapValQ,
22 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, 22 FunCodeVV(..), vectorZipR, vectorZipC, vectorZipF, vectorZipQ,
23 RandDist(..), randomVector 23 RandDist(..), randomVector
24) where 24) where
25 25
@@ -214,6 +214,12 @@ vectorMapF = vectorMapAux c_vectorMapF
214 214
215foreign import ccall safe "gsl-aux.h mapF" c_vectorMapF :: CInt -> TFF 215foreign import ccall safe "gsl-aux.h mapF" c_vectorMapF :: CInt -> TFF
216 216
217-- | map of real vectors with given function
218vectorMapQ :: FunCodeV -> Vector (Complex Float) -> Vector (Complex Float)
219vectorMapQ = vectorMapAux c_vectorMapQ
220
221foreign import ccall safe "gsl-aux.h mapQ" c_vectorMapQ :: CInt -> TQVQV
222
217------------------------------------------------------------------- 223-------------------------------------------------------------------
218 224
219-- | map of real vectors with given function 225-- | map of real vectors with given function
@@ -234,6 +240,12 @@ vectorMapValF oper = vectorMapValAux c_vectorMapValF (fromei oper)
234 240
235foreign import ccall safe "gsl-aux.h mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TFF 241foreign import ccall safe "gsl-aux.h mapValF" c_vectorMapValF :: CInt -> Ptr Float -> TFF
236 242
243-- | map of complex vectors with given function
244vectorMapValQ :: FunCodeSV -> Complex Float -> Vector (Complex Float) -> Vector (Complex Float)
245vectorMapValQ oper = vectorMapValAux c_vectorMapValQ (fromei oper)
246
247foreign import ccall safe "gsl-aux.h mapValQ" c_vectorMapValQ :: CInt -> Ptr (Complex Float) -> TQVQV
248
237------------------------------------------------------------------- 249-------------------------------------------------------------------
238 250
239-- | elementwise operation on real vectors 251-- | elementwise operation on real vectors
@@ -254,6 +266,12 @@ vectorZipF = vectorZipAux c_vectorZipF
254 266
255foreign import ccall safe "gsl-aux.h zipF" c_vectorZipF :: CInt -> TFFF 267foreign import ccall safe "gsl-aux.h zipF" c_vectorZipF :: CInt -> TFFF
256 268
269-- | elementwise operation on complex vectors
270vectorZipQ :: FunCodeVV -> Vector (Complex Float) -> Vector (Complex Float) -> Vector (Complex Float)
271vectorZipQ = vectorZipAux c_vectorZipQ
272
273foreign import ccall safe "gsl-aux.h zipQ" c_vectorZipQ :: CInt -> TQVQVQV
274
257----------------------------------------------------------------------- 275-----------------------------------------------------------------------
258 276
259data RandDist = Uniform -- ^ uniform distribution in [0,1) 277data RandDist = Uniform -- ^ uniform distribution in [0,1)
diff --git a/lib/Numeric/GSL/gsl-aux.c b/lib/Numeric/GSL/gsl-aux.c
index 3f9eeba..689989d 100644
--- a/lib/Numeric/GSL/gsl-aux.c
+++ b/lib/Numeric/GSL/gsl-aux.c
@@ -393,6 +393,83 @@ int mapC(int code, KCVEC(x), CVEC(r)) {
393} 393}
394 394
395 395
396gsl_complex_float complex_float_math_fun(gsl_complex (*cf)(gsl_complex), gsl_complex_float a)
397{
398 gsl_complex c;
399 gsl_complex r;
400
401 gsl_complex_float float_r;
402
403 c.dat[0] = a.dat[0];
404 c.dat[1] = a.dat[1];
405
406 r = (*cf)(c);
407
408 float_r.dat[0] = r.dat[0];
409 float_r.dat[1] = r.dat[1];
410
411 return float_r;
412}
413
414gsl_complex_float complex_float_math_op(gsl_complex (*cf)(gsl_complex,gsl_complex),
415 gsl_complex_float a,gsl_complex_float b)
416{
417 gsl_complex c1;
418 gsl_complex c2;
419 gsl_complex r;
420
421 gsl_complex_float float_r;
422
423 c1.dat[0] = a.dat[0];
424 c1.dat[1] = a.dat[1];
425
426 c2.dat[0] = b.dat[0];
427 c2.dat[1] = b.dat[1];
428
429 r = (*cf)(c1,c2);
430
431 float_r.dat[0] = r.dat[0];
432 float_r.dat[1] = r.dat[1];
433
434 return float_r;
435}
436
437#define OPC(C,F) case C: { for(k=0;k<xn;k++) rp[k] = complex_float_math_fun(&F,xp[k]); OK }
438#define OPCA(C,F,A,B) case C: { for(k=0;k<xn;k++) rp[k] = complex_float_math_op(&F,A,B); OK }
439int mapQAux(int code, KGQVEC(x), GQVEC(r)) {
440 int k;
441 REQUIRES(xn == rn,BAD_SIZE);
442 DEBUGMSG("mapQ");
443 switch (code) {
444 OPC(0,gsl_complex_sin)
445 OPC(1,gsl_complex_cos)
446 OPC(2,gsl_complex_tan)
447 OPC(3,complex_abs)
448 OPC(4,gsl_complex_arcsin)
449 OPC(5,gsl_complex_arccos)
450 OPC(6,gsl_complex_arctan)
451 OPC(7,gsl_complex_sinh)
452 OPC(8,gsl_complex_cosh)
453 OPC(9,gsl_complex_tanh)
454 OPC(10,gsl_complex_arcsinh)
455 OPC(11,gsl_complex_arccosh)
456 OPC(12,gsl_complex_arctanh)
457 OPC(13,gsl_complex_exp)
458 OPC(14,gsl_complex_log)
459 OPC(15,complex_signum)
460 OPC(16,gsl_complex_sqrt)
461
462 // gsl_complex_arg
463 // gsl_complex_abs
464 default: ERROR(BAD_CODE);
465 }
466}
467
468int mapQ(int code, KQVEC(x), QVEC(r)) {
469 return mapQAux(code, xn, (gsl_complex_float*)xp, rn, (gsl_complex_float*)rp);
470}
471
472
396int mapValR(int code, double* pval, KRVEC(x), RVEC(r)) { 473int mapValR(int code, double* pval, KRVEC(x), RVEC(r)) {
397 int k; 474 int k;
398 double val = *pval; 475 double val = *pval;
@@ -446,6 +523,27 @@ int mapValC(int code, gsl_complex* val, KCVEC(x), CVEC(r)) {
446} 523}
447 524
448 525
526int mapValQAux(int code, gsl_complex_float* pval, KQVEC(x), GQVEC(r)) {
527 int k;
528 gsl_complex_float val = *pval;
529 REQUIRES(xn == rn,BAD_SIZE);
530 DEBUGMSG("mapValQ");
531 switch (code) {
532 OPCA(0,gsl_complex_mul,val,xp[k])
533 OPCA(1,gsl_complex_div,val,xp[k])
534 OPCA(2,gsl_complex_add,val,xp[k])
535 OPCA(3,gsl_complex_sub,val,xp[k])
536 OPCA(4,gsl_complex_pow,val,xp[k])
537 OPCA(5,gsl_complex_pow,xp[k],val)
538 default: ERROR(BAD_CODE);
539 }
540}
541
542int mapValQ(int code, gsl_complex_float* val, KQVEC(x), QVEC(r)) {
543 return mapValQAux(code, val, xn, (gsl_complex_float*)xp, rn, (gsl_complex_float*)rp);
544}
545
546
449#define OPZE(C,msg,E) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) rp[k] = E(ap[k],bp[k]); OK } 547#define OPZE(C,msg,E) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) rp[k] = E(ap[k],bp[k]); OK }
450#define OPZV(C,msg,E) case C: {DEBUGMSG(msg) res = E(V(r),V(b)); CHECK(res,res); OK } 548#define OPZV(C,msg,E) case C: {DEBUGMSG(msg) res = E(V(r),V(b)); CHECK(res,res); OK }
451int zipR(int code, KRVEC(a), KRVEC(b), RVEC(r)) { 549int zipR(int code, KRVEC(a), KRVEC(b), RVEC(r)) {
@@ -519,6 +617,34 @@ int zipC(int code, KCVEC(a), KCVEC(b), CVEC(r)) {
519} 617}
520 618
521 619
620#define OPCZE(C,msg,E) case C: {DEBUGMSG(msg) for(k=0;k<an;k++) rp[k] = complex_float_math_op(&E,ap[k],bp[k]); OK }
621int zipQAux(int code, KGQVEC(a), KGQVEC(b), GQVEC(r)) {
622 REQUIRES(an == bn && an == rn, BAD_SIZE);
623 int k;
624 switch(code) {
625 OPCZE(0,"zipQ Add",gsl_complex_add)
626 OPCZE(1,"zipQ Sub",gsl_complex_sub)
627 OPCZE(2,"zipQ Mul",gsl_complex_mul)
628 OPCZE(3,"zipQ Div",gsl_complex_div)
629 OPCZE(4,"zipQ Pow",gsl_complex_pow)
630 //OPZE(5,"zipR ATan2",atan2)
631 }
632 //KCVVIEW(a);
633 //KCVVIEW(b);
634 //CVVIEW(r);
635 //gsl_vector_memcpy(V(r),V(a));
636 //int res;
637 switch(code) {
638 default: ERROR(BAD_CODE);
639 }
640}
641
642
643int zipQ(int code, KQVEC(a), KQVEC(b), QVEC(r)) {
644 return zipQAux(code, an, (gsl_complex_float*)ap, bn, (gsl_complex_float*)bp, rn, (gsl_complex_float*)rp);
645}
646
647
522 648
523int fft(int code, KCVEC(X), CVEC(R)) { 649int fft(int code, KCVEC(X), CVEC(R)) {
524 REQUIRES(Xn == Rn,BAD_SIZE); 650 REQUIRES(Xn == Rn,BAD_SIZE);