diff options
Diffstat (limited to 'lib/Data/Packed/Internal/aux.c')
-rw-r--r-- | lib/Data/Packed/Internal/aux.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/lib/Data/Packed/Internal/aux.c b/lib/Data/Packed/Internal/aux.c index 01a2bb3..fe611e2 100644 --- a/lib/Data/Packed/Internal/aux.c +++ b/lib/Data/Packed/Internal/aux.c | |||
@@ -18,19 +18,17 @@ | |||
18 | #define MACRO(B) do {B} while (0) | 18 | #define MACRO(B) do {B} while (0) |
19 | #define ERROR(CODE) MACRO(return CODE;) | 19 | #define ERROR(CODE) MACRO(return CODE;) |
20 | #define REQUIRES(COND, CODE) MACRO(if(!(COND)) {ERROR(CODE);}) | 20 | #define REQUIRES(COND, CODE) MACRO(if(!(COND)) {ERROR(CODE);}) |
21 | #define OK return 0; | ||
21 | 22 | ||
22 | #define MIN(A,B) ((A)<(B)?(A):(B)) | 23 | #define MIN(A,B) ((A)<(B)?(A):(B)) |
23 | #define MAX(A,B) ((A)>(B)?(A):(B)) | 24 | #define MAX(A,B) ((A)>(B)?(A):(B)) |
24 | 25 | ||
25 | #ifdef DBG | 26 | #ifdef DBG |
26 | #define DEBUGMSG(M) printf("GSL Wrapper "M": "); size_t t0 = time(NULL); | 27 | #define DEBUGMSG(M) printf("*** calling aux C function: %s\n",M); |
27 | #define OK MACRO(printf("%ld s\n",time(0)-t0); return 0;); | ||
28 | #else | 28 | #else |
29 | #define DEBUGMSG(M) | 29 | #define DEBUGMSG(M) |
30 | #define OK return 0; | ||
31 | #endif | 30 | #endif |
32 | 31 | ||
33 | |||
34 | #define CHECK(RES,CODE) MACRO(if(RES) return CODE;) | 32 | #define CHECK(RES,CODE) MACRO(if(RES) return CODE;) |
35 | 33 | ||
36 | #ifdef DBG | 34 | #ifdef DBG |
@@ -45,7 +43,6 @@ | |||
45 | #define DEBUGVEC(MSG,X) | 43 | #define DEBUGVEC(MSG,X) |
46 | #endif | 44 | #endif |
47 | 45 | ||
48 | |||
49 | #define DVVIEW(A) gsl_vector_view A = gsl_vector_view_array(A##p,A##n) | 46 | #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) | 47 | #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) | 48 | #define CVVIEW(A) gsl_vector_complex_view A = gsl_vector_complex_view_array((double*)A##p,A##n) |
@@ -66,8 +63,6 @@ | |||
66 | #define MEM 1002 | 63 | #define MEM 1002 |
67 | #define BAD_FILE 1003 | 64 | #define BAD_FILE 1003 |
68 | 65 | ||
69 | |||
70 | |||
71 | int transR(KRMAT(x),RMAT(t)) { | 66 | int transR(KRMAT(x),RMAT(t)) { |
72 | REQUIRES(xr==tc && xc==tr,BAD_SIZE); | 67 | REQUIRES(xr==tc && xc==tr,BAD_SIZE); |
73 | DEBUGMSG("transR"); | 68 | DEBUGMSG("transR"); |
@@ -122,6 +117,7 @@ int constantC(gsl_complex* pval, CVEC(r)) { | |||
122 | OK | 117 | OK |
123 | } | 118 | } |
124 | 119 | ||
120 | |||
125 | int multiplyR(int ta, KRMAT(a), int tb, KRMAT(b),RMAT(r)) { | 121 | int multiplyR(int ta, KRMAT(a), int tb, KRMAT(b),RMAT(r)) { |
126 | //printf("%d %d %d %d %d %d\n",ar,ac,br,bc,rr,rc); | 122 | //printf("%d %d %d %d %d %d\n",ar,ac,br,bc,rr,rc); |
127 | //REQUIRES(ac==br && ar==rr && bc==rc,BAD_SIZE); | 123 | //REQUIRES(ac==br && ar==rr && bc==rc,BAD_SIZE); |
@@ -155,3 +151,30 @@ int multiplyC(int ta, KCMAT(a), int tb, KCMAT(b),CMAT(r)) { | |||
155 | CHECK(res,res); | 151 | CHECK(res,res); |
156 | OK | 152 | OK |
157 | } | 153 | } |
154 | |||
155 | |||
156 | int diagR(KRVEC(d),RMAT(r)) { | ||
157 | REQUIRES(dn==rr && rr==rc,BAD_SIZE); | ||
158 | DEBUGMSG("diagR"); | ||
159 | int i,j; | ||
160 | for (i=0;i<rr;i++) { | ||
161 | for(j=0;j<rc;j++) { | ||
162 | rp[i*rc+j] = i==j?dp[i]:0.; | ||
163 | } | ||
164 | } | ||
165 | OK | ||
166 | } | ||
167 | |||
168 | int diagC(KCVEC(d),CMAT(r)) { | ||
169 | REQUIRES(dn==rr && rr==rc,BAD_SIZE); | ||
170 | DEBUGMSG("diagC"); | ||
171 | int i,j; | ||
172 | gsl_complex zero; | ||
173 | GSL_SET_COMPLEX(&zero,0.,0.); | ||
174 | for (i=0;i<rr;i++) { | ||
175 | for(j=0;j<rc;j++) { | ||
176 | rp[i*rc+j] = i==j?dp[i]:zero; | ||
177 | } | ||
178 | } | ||
179 | OK | ||
180 | } | ||