#include "pfapack.h" #ifdef __cplusplus #include #include #include using std::printf; using std::rand; using std::malloc; using std::free; using std::memset; using std::memcpy; static const floatcmplx floatcmplx_one = std::complex(1); static const doublecmplx doublecmplx_one = std::complex(1); static const floatcmplx floatcmplx_zero = std::complex(0); static const doublecmplx doublecmplx_zero = std::complex(0); #else #include #include #include "string.h" #if __STDC_VERSION__ >= 199901L static const floatcmplx floatcmplx_one = 1; static const doublecmplx doublecmplx_one = 1; static const floatcmplx floatcmplx_zero = 0; static const doublecmplx doublecmplx_zero = 0; #else static const floatcmplx floatcmplx_one = { 1, 0 }; static const doublecmplx doublecmplx_one = { 1, 0 }; static const floatcmplx floatcmplx_zero = { 0, 0 }; static const doublecmplx doublecmplx_zero = { 0, 0 }; #endif #endif void make_skew_mat_s(int N, float *A, double prob) { int i, j; memset(A, 0, sizeof(float)*N*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if( rand()/(double)RAND_MAX < prob) { A[dense_fortran(i, j, N)] = rand()*2.0/RAND_MAX-1.0; A[dense_fortran(j, i, N)] = -A[dense_fortran(i, j, N)]; } } } } void make_skew_mat_d(int N, double *A, double prob) { int i, j; memset(A, 0, sizeof(double)*N*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if( rand()/(double)RAND_MAX < prob) { A[dense_fortran(i, j, N)] = rand()*2.0/RAND_MAX-1.0; A[dense_fortran(j, i, N)] = -A[dense_fortran(i, j, N)]; } } } } void make_skew_mat_c(int N, floatcmplx *A, double prob) { int i, j; memset(A, 0, sizeof(floatcmplx)*N*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if( rand()/(double)RAND_MAX < prob) { #ifdef __cplusplus A[dense_fortran(i, j, N)] = floatcmplx(rand()*2.0/RAND_MAX-1.0, rand()*2.0/RAND_MAX-1.0); A[dense_fortran(j, i, N)] = -A[dense_fortran(i, j, N)]; #elif __STDC_VERSION__ >= 199901L A[dense_fortran(i, j, N)] = (rand()*2.0/RAND_MAX-1.0) + I*(rand()*2.0/RAND_MAX-1.0); A[dense_fortran(j, i, N)] = -A[dense_fortran(i, j, N)]; #else A[dense_fortran(i, j, N)].re = rand()*2.0/RAND_MAX-1.0; A[dense_fortran(i, j, N)].im = rand()*2.0/RAND_MAX-1.0; A[dense_fortran(j, i, N)].re = -A[dense_fortran(i, j, N)].re; A[dense_fortran(j, i, N)].im = -A[dense_fortran(i, j, N)].im; #endif } } } } void make_skew_mat_z(int N, doublecmplx *A, double prob) { int i, j; memset(A, 0, sizeof(doublecmplx)*N*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if( rand()/(double)RAND_MAX < prob) { #ifdef __cplusplus A[dense_fortran(i, j, N)] = doublecmplx(rand()*2.0/RAND_MAX-1.0, rand()*2.0/RAND_MAX-1.0); A[dense_fortran(j, i, N)] = -A[dense_fortran(i, j, N)]; #elif __STDC_VERSION__ >= 199901L A[dense_fortran(i, j, N)] = (rand()*2.0/RAND_MAX-1.0) + I*(rand()*2.0/RAND_MAX-1.0); A[dense_fortran(j, i, N)] = -A[dense_fortran(i, j, N)]; #else A[dense_fortran(i, j, N)].re = rand()*2.0/RAND_MAX-1.0; A[dense_fortran(i, j, N)].im = rand()*2.0/RAND_MAX-1.0; A[dense_fortran(j, i, N)].re = -A[dense_fortran(i, j, N)].re; A[dense_fortran(j, i, N)].im = -A[dense_fortran(i, j, N)].im; #endif } } } } /*make random baned matrices*/ void make_skew_mat_banded_s(int N, int KD, float *Au, float *Ad, double prob) { int i,j; if(Au) memset(Au, 0, sizeof(float)*(KD+1)*N); if(Ad) memset(Ad, 0, sizeof(float)*(KD+1)*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if(i-j < KD) { if( rand()/(double)RAND_MAX < prob) { float tmp = rand()*2.0/RAND_MAX-1.0; if(Au) Au[bandupper_fortran(j, i, N, KD)] = tmp; if(Ad) Ad[bandlower_fortran(i, j, N, KD)] = -tmp; } } } } } void make_skew_mat_banded_d(int N, int KD, double *Au, double *Ad, double prob) { int i,j; if(Au) memset(Au, 0, sizeof(double)*(KD+1)*N); if(Ad) memset(Ad, 0, sizeof(double)*(KD+1)*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if(i-j < KD) { if( rand()/(double)RAND_MAX < prob) { double tmp = rand()*2.0/RAND_MAX-1.0; if(Au) Au[bandupper_fortran(j, i, N, KD)] = tmp; if(Ad) Ad[bandlower_fortran(i, j, N, KD)] = -tmp; } } } } } void make_skew_mat_banded_c(int N, int KD, floatcmplx *Au, floatcmplx *Ad, double prob) { int i,j; if(Au) memset(Au, 0, sizeof(floatcmplx)*(KD+1)*N); if(Ad) memset(Ad, 0, sizeof(floatcmplx)*(KD+1)*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if(i-j < KD) { if( rand()/(double)RAND_MAX < prob) { float tmpre = rand()*2.0/RAND_MAX-1.0; float tmpim = rand()*2.0/RAND_MAX-1.0; if(Au) { #ifdef __cplusplus Au[bandupper_fortran(j, i, N, KD)] = floatcmplx(tmpre, tmpim); #elif __STDC_VERSION__ >= 199901L Au[bandupper_fortran(j, i, N, KD)] = tmpre + I*tmpim; #else Au[bandupper_fortran(j, i, N, KD)].re = tmpre; Au[bandupper_fortran(j, i, N, KD)].im = tmpim; #endif } if(Ad) { #ifdef __cplusplus Ad[bandlower_fortran(i, j, N, KD)] = -floatcmplx(tmpre, tmpim); #elif __STDC_VERSION__ >= 199901L Ad[bandlower_fortran(i, j, N, KD)] = -tmpre - I*tmpim; #else Ad[bandlower_fortran(i, j, N, KD)].re = -tmpre; Ad[bandlower_fortran(i, j, N, KD)].im = -tmpim; #endif } } } } } } void make_skew_mat_banded_z(int N, int KD, doublecmplx *Au, doublecmplx *Ad, double prob) { int i,j; if(Au) memset(Au, 0, sizeof(doublecmplx)*(KD+1)*N); if(Ad) memset(Ad, 0, sizeof(doublecmplx)*(KD+1)*N); for(i=1; i<=N; i++) { for(j=1; j<=i-1; j++) { if(i-j < KD) { if( rand()/(double)RAND_MAX < prob) { double tmpre = rand()*2.0/RAND_MAX-1.0; double tmpim = rand()*2.0/RAND_MAX-1.0; if(Au) { #ifdef __cplusplus Au[bandupper_fortran(j, i, N, KD)] = doublecmplx(tmpre, tmpim); #elif __STDC_VERSION__ >= 199901L Au[bandupper_fortran(j, i, N, KD)] = tmpre + I*tmpim; #else Au[bandupper_fortran(j, i, N, KD)].re = tmpre; Au[bandupper_fortran(j, i, N, KD)].im = tmpim; #endif } if(Ad) { #ifdef __cplusplus Ad[bandlower_fortran(i, j, N, KD)] = -doublecmplx(tmpre, tmpim); #elif __STDC_VERSION__ >= 199901L Ad[bandlower_fortran(i, j, N, KD)] = -tmpre - I*tmpim; #else Ad[bandlower_fortran(i, j, N, KD)].re = -tmpre; Ad[bandlower_fortran(i, j, N, KD)].im = -tmpim; #endif } } } } } } #include "check.h" #define MAX_SIZE 20 void check_pfaff_s() { int N, KD, idens; double densities[] = {0.1, 0.25, 0.5, 1.0}; for(idens=0; idens<4; idens++) { /*dense matrices first*/ for(N=1; N<=MAX_SIZE; N++) { float *A, *Acpy; float pfaff, pfaff10[2]; A = (float*)malloc(sizeof(float)*N*N); if(!A) { printf("Failed to allocate memory!\n"); exit(10); } Acpy = (float*)malloc(sizeof(float)*N*N); if(!Acpy) { printf("Failed to allocate memory!\n"); free(A); exit(10); } /*check skpfa_x for various parameters*/ make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa_s(N, A, &pfaff, "U", "P"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "U", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa_s(N, A, &pfaff, "L", "P"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "L", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa_s(N, A, &pfaff, "U", "H"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "U", "H"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa_s(N, A, &pfaff, "L", "H"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "L", "H"); #ifdef __cplusplus make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa(N, A, &pfaff, "U", "P"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "U", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa(N, A, &pfaff, "L", "P"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "L", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa(N, A, &pfaff, "U", "H"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "U", "H"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpfa(N, A, &pfaff, "L", "H"); F95_check_skpfa_s(&N, Acpy, A, &pfaff, "L", "H"); #endif /*check skpf10_x for various parameters*/ make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10_s(N, A, pfaff10, "U", "P"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "U", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10_s(N, A, pfaff10, "L", "P"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "L", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10_s(N, A, pfaff10, "U", "H"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "U", "H"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10_s(N, A, pfaff10, "L", "H"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "L", "H"); #ifdef __cplusplus make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10(N, A, pfaff10, "U", "P"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "U", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10(N, A, pfaff10, "L", "P"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "L", "P"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10(N, A, pfaff10, "U", "H"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "U", "H"); make_skew_mat_s(N, A, densities[idens]); memcpy(Acpy, A, sizeof(float)*N*N); skpf10(N, A, pfaff10, "L", "H"); F95_check_skpf10_s(&N, Acpy, A, pfaff10, "L", "H"); #endif free(Acpy); free(A); } /*then banded matrices*/ for(N=1; N<=MAX_SIZE; N++) { for(KD=0; KD