#include typedef double complex TCD; typedef float complex TCF; #undef complex #include "lapack-aux.h" #define V(x) x##n,x##p #include #include #include #define MACRO(B) do {B} while (0) #define ERROR(CODE) MACRO(return CODE;) #define REQUIRES(COND, CODE) MACRO(if(!(COND)) {ERROR(CODE);}) #define OK return 0; #define MIN(A,B) ((A)<(B)?(A):(B)) #define MAX(A,B) ((A)>(B)?(A):(B)) #ifdef DBG #define DEBUGMSG(M) printf("*** calling aux C function: %s\n",M); #else #define DEBUGMSG(M) #endif #define CHECK(RES,CODE) MACRO(if(RES) return CODE;) #ifdef DBG #define DEBUGMAT(MSG,X) printf(MSG" = \n"); gsl_matrix_fprintf(stdout,X,"%f"); printf("\n"); #else #define DEBUGMAT(MSG,X) #endif #ifdef DBG #define DEBUGVEC(MSG,X) printf(MSG" = \n"); gsl_vector_fprintf(stdout,X,"%f"); printf("\n"); #else #define DEBUGVEC(MSG,X) #endif #define BAD_SIZE 2000 #define BAD_CODE 2001 #define MEM 2002 #define BAD_FILE 2003 int sumF(KFVEC(x),FVEC(r)) { DEBUGMSG("sumF"); REQUIRES(rn==1,BAD_SIZE); int i; float res = 0; for (i = 0; i < xn; i++) res += xp[i]; rp[0] = res; OK } int sumR(KDVEC(x),DVEC(r)) { DEBUGMSG("sumR"); REQUIRES(rn==1,BAD_SIZE); int i; double res = 0; for (i = 0; i < xn; i++) res += xp[i]; rp[0] = res; OK } int sumQ(KQVEC(x),QVEC(r)) { DEBUGMSG("sumQ"); REQUIRES(rn==1,BAD_SIZE); int i; complex res; res.r = 0; res.i = 0; for (i = 0; i < xn; i++) { res.r += xp[i].r; res.i += xp[i].i; } rp[0] = res; OK } int sumC(KCVEC(x),CVEC(r)) { DEBUGMSG("sumC"); REQUIRES(rn==1,BAD_SIZE); int i; doublecomplex res; res.r = 0; res.i = 0; for (i = 0; i < xn; i++) { res.r += xp[i].r; res.i += xp[i].i; } rp[0] = res; OK } int prodF(KFVEC(x),FVEC(r)) { DEBUGMSG("prodF"); REQUIRES(rn==1,BAD_SIZE); int i; float res = 1; for (i = 0; i < xn; i++) res *= xp[i]; rp[0] = res; OK } int prodR(KDVEC(x),DVEC(r)) { DEBUGMSG("prodR"); REQUIRES(rn==1,BAD_SIZE); int i; double res = 1; for (i = 0; i < xn; i++) res *= xp[i]; rp[0] = res; OK } int prodQ(KQVEC(x),QVEC(r)) { DEBUGMSG("prodQ"); REQUIRES(rn==1,BAD_SIZE); int i; complex res; float temp; res.r = 1; res.i = 0; for (i = 0; i < xn; i++) { temp = res.r * xp[i].r - res.i * xp[i].i; res.i = res.r * xp[i].i + res.i * xp[i].r; res.r = temp; } rp[0] = res; OK } int prodC(KCVEC(x),CVEC(r)) { DEBUGMSG("prodC"); REQUIRES(rn==1,BAD_SIZE); int i; doublecomplex res; double temp; res.r = 1; res.i = 0; for (i = 0; i < xn; i++) { temp = res.r * xp[i].r - res.i * xp[i].i; res.i = res.r * xp[i].i + res.i * xp[i].r; res.r = temp; } rp[0] = res; OK } double dnrm2_(integer*, const double*, integer*); double dasum_(integer*, const double*, integer*); double vector_max(KDVEC(x)) { double r = xp[0]; int k; for (k = 1; kr) { r = xp[k]; } } return r; } double vector_min(KDVEC(x)) { double r = xp[0]; int k; for (k = 1; kxp[0]) { r = k; } } return r; } double vector_min_index(KDVEC(x)) { int k, r = 0; for (k = 1; kr) { r = xp[k]; } } return r; } float vector_min_f(KFVEC(x)) { float r = xp[0]; int k; for (k = 1; kxp[0]) { r = k; } } return r; } float vector_min_index_f(KFVEC(x)) { int k, r = 0; for (k = 1; k0) { return +1.0; } else if (x<0) { return -1.0; } else { return 0.0; } } inline float float_sign(float x) { if(x>0) { return +1.0; } else if (x<0) { return -1.0; } else { return 0.0; } } #define OP(C,F) case C: { for(k=0;k