summaryrefslogtreecommitdiff
path: root/lib/Data/Packed/Internal/aux.c
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-06-04 19:10:28 +0000
committerAlberto Ruiz <aruiz@um.es>2007-06-04 19:10:28 +0000
commit7430630fa0504296b796223e01cbd417b88650ef (patch)
treec338dea8b82867a4c161fcee5817ed2ca27c7258 /lib/Data/Packed/Internal/aux.c
parent0a9817cc481fb09f1962eb2c272125e56a123814 (diff)
separation of Internal
Diffstat (limited to 'lib/Data/Packed/Internal/aux.c')
-rw-r--r--lib/Data/Packed/Internal/aux.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/aux.c b/lib/Data/Packed/Internal/aux.c
new file mode 100644
index 0000000..da36035
--- /dev/null
+++ b/lib/Data/Packed/Internal/aux.c
@@ -0,0 +1,144 @@
1#include "aux.h"
2#include <gsl/gsl_blas.h>
3#include <gsl/gsl_linalg.h>
4#include <gsl/gsl_matrix.h>
5#include <gsl/gsl_math.h>
6#include <gsl/gsl_errno.h>
7#include <gsl/gsl_fft_complex.h>
8#include <gsl/gsl_eigen.h>
9#include <gsl/gsl_integration.h>
10#include <gsl/gsl_deriv.h>
11#include <gsl/gsl_poly.h>
12#include <gsl/gsl_multimin.h>
13#include <gsl/gsl_complex.h>
14#include <gsl/gsl_complex_math.h>
15#include <string.h>
16#include <stdio.h>
17
18#define MACRO(B) do {B} while (0)
19#define ERROR(CODE) MACRO(return CODE;)
20#define REQUIRES(COND, CODE) MACRO(if(!(COND)) {ERROR(CODE);})
21
22#define MIN(A,B) ((A)<(B)?(A):(B))
23#define MAX(A,B) ((A)>(B)?(A):(B))
24
25#ifdef DBG
26#define DEBUGMSG(M) printf("GSL Wrapper "M": "); size_t t0 = time(NULL);
27#define OK MACRO(printf("%ld s\n",time(0)-t0); return 0;);
28#else
29#define DEBUGMSG(M)
30#define OK return 0;
31#endif
32
33
34#define CHECK(RES,CODE) MACRO(if(RES) return CODE;)
35
36#ifdef DBG
37#define DEBUGMAT(MSG,X) printf(MSG" = \n"); gsl_matrix_fprintf(stdout,X,"%f"); printf("\n");
38#else
39#define DEBUGMAT(MSG,X)
40#endif
41
42#ifdef DBG
43#define DEBUGVEC(MSG,X) printf(MSG" = \n"); gsl_vector_fprintf(stdout,X,"%f"); printf("\n");
44#else
45#define DEBUGVEC(MSG,X)
46#endif
47
48
49#define DVVIEW(A) gsl_vector_view A = gsl_vector_view_array(A##p,A##n)
50#define DMVIEW(A) gsl_matrix_view A = gsl_matrix_view_array(A##p,A##r,A##c)
51#define CVVIEW(A) gsl_vector_complex_view A = gsl_vector_complex_view_array((double*)A##p,A##n)
52#define CMVIEW(A) gsl_matrix_complex_view A = gsl_matrix_complex_view_array((double*)A##p,A##r,A##c)
53#define KDVVIEW(A) gsl_vector_const_view A = gsl_vector_const_view_array(A##p,A##n)
54#define KDMVIEW(A) gsl_matrix_const_view A = gsl_matrix_const_view_array(A##p,A##r,A##c)
55#define KCVVIEW(A) gsl_vector_complex_const_view A = gsl_vector_complex_const_view_array((double*)A##p,A##n)
56#define KCMVIEW(A) gsl_matrix_complex_const_view A = gsl_matrix_complex_const_view_array((double*)A##p,A##r,A##c)
57
58#define V(a) (&a.vector)
59#define M(a) (&a.matrix)
60
61#define GCVEC(A) int A##n, gsl_complex*A##p
62#define KGCVEC(A) int A##n, const gsl_complex*A##p
63
64#define BAD_SIZE 1000
65#define BAD_CODE 1001
66#define MEM 1002
67#define BAD_FILE 1003
68
69
70
71int transR(KRMAT(x),RMAT(t)) {
72 REQUIRES(xr==tc && xc==tr,BAD_SIZE);
73 DEBUGMSG("transR");
74 KDMVIEW(x);
75 DMVIEW(t);
76 int res = gsl_matrix_transpose_memcpy(M(t),M(x));
77 CHECK(res,res);
78 OK
79}
80
81int transC(KCMAT(x),CMAT(t)) {
82 REQUIRES(xr==tc && xc==tr,BAD_SIZE);
83 DEBUGMSG("transC");
84 KCMVIEW(x);
85 CMVIEW(t);
86 int res = gsl_matrix_complex_transpose_memcpy(M(t),M(x));
87 CHECK(res,res);
88 OK
89}
90
91
92int constantR(double * pval, RVEC(r)) {
93 DEBUGMSG("constantR")
94 int k;
95 double val = *pval;
96 for(k=0;k<rn;k++) {
97 rp[k]=val;
98 }
99 OK
100}
101
102int constantC(gsl_complex* pval, CVEC(r)) {
103 DEBUGMSG("constantC")
104 int k;
105 gsl_complex val = *pval;
106 for(k=0;k<rn;k++) {
107 rp[k]=val;
108 }
109 OK
110}
111
112int multiplyR(int ta, KRMAT(a), int tb, KRMAT(b),RMAT(r)) {
113 //printf("%d %d %d %d %d %d\n",ar,ac,br,bc,rr,rc);
114 //REQUIRES(ac==br && ar==rr && bc==rc,BAD_SIZE);
115 DEBUGMSG("multiplyR (gsl_blas_dgemm)");
116 KDMVIEW(a);
117 KDMVIEW(b);
118 DMVIEW(r);
119 int res = gsl_blas_dgemm(
120 ta?CblasTrans:CblasNoTrans,
121 tb?CblasTrans:CblasNoTrans,
122 1.0, M(a), M(b),
123 0.0, M(r));
124 CHECK(res,res);
125 OK
126}
127
128int multiplyC(int ta, KCMAT(a), int tb, KCMAT(b),CMAT(r)) {
129 //REQUIRES(ac==br && ar==rr && bc==rc,BAD_SIZE);
130 DEBUGMSG("multiplyC (gsl_blas_zgemm)");
131 KCMVIEW(a);
132 KCMVIEW(b);
133 CMVIEW(r);
134 gsl_complex alpha, beta;
135 GSL_SET_COMPLEX(&alpha,1.,0.);
136 GSL_SET_COMPLEX(&beta,0.,0.);
137 int res = gsl_blas_zgemm(
138 ta?CblasTrans:CblasNoTrans,
139 tb?CblasTrans:CblasNoTrans,
140 alpha, M(a), M(b),
141 beta, M(r));
142 CHECK(res,res);
143 OK
144}