34 int main(
int argc,
char** argv) {
36 fprintf(stdout,
"Usage: test_DLT_semi m bw loops\n");
40 int m = atoi(argv[1]);
41 int bw = atoi(argv[2]);
42 int loops = atoi(argv[3]);
45 double* samples = (
double*)malloc(
sizeof(
double) * n);
46 double* coeffs = (
double*)malloc(
sizeof(
double) * (bw - m));
47 double* new_coeffs = (
double*)malloc(
sizeof(
double) * (bw - m));
49 double* relerror = (
double*)malloc(
sizeof(
double) * loops);
50 double* curmax = (
double*)malloc(
sizeof(
double) * loops);
52 double* eval_args = (
double*)malloc(
sizeof(
double) * n);
53 double* sin_values = (
double*)malloc(
sizeof(
double) * n);
57 for (
int i = 0; i < n; ++i)
58 sin_values[i] = sin(eval_args[i]);
60 double* workspace = (
double*)malloc(
sizeof(
double) * 9 * bw);
61 double* weights = (
double*)malloc(
sizeof(
double) * 4 * bw);
65 fftw_plan forwardDCT = fftw_plan_r2r_1d(2 * bw, workspace, weights, FFTW_REDFT10, FFTW_ESTIMATE);
66 fftw_plan inverseDCT = fftw_plan_r2r_1d(2 * bw, workspace, weights, FFTW_REDFT01, FFTW_ESTIMATE);
70 double* cos_pml_table = (
double*)malloc(
sizeof(
double) *
TableSize(m, bw));
71 double* transpose_cos_pml_table = (
double*)malloc(
sizeof(
double) *
TableSize(m, bw));
78 double sum_error = 0.0;
79 double sum_relerror = 0.0;
81 double total_time_f = 0.0;
82 double total_time_i = 0.0;
88 for (
int k = 0; k < loops; ++k) {
90 for (
int i = 0; i < (bw - m); ++i)
91 coeffs[i] = 2.0 * (drand48() - 0.5);
95 InvDLTSemi(coeffs, bw, m, samples, transpose_cos_pml_table, sin_values, workspace, &inverseDCT);
96 total_time_i += (
csecond() - time_start);
100 DLTSemi(samples, bw, m, new_coeffs, workspace, cos_pml_table, weights, &forwardDCT);
101 total_time_f += (
csecond() - time_start);
107 for (
int j = 0; j < bw - m; ++j) {
108 double tmp_error = fabs(coeffs[j] - new_coeffs[j]);
109 double tmp_relerror = tmp_error / (fabs(coeffs[j]) + pow(10.0, -50.0));
110 curmax[k] = fmax(curmax[k], tmp_error);
111 relerror[k] = fmax(relerror[k], tmp_relerror);
114 sum_error += curmax[k];
115 sum_relerror += relerror[k];
118 double avg_error = sum_error / loops;
119 double avg_relerror = sum_relerror / loops;
120 double stddev_error = 0.0;
121 double stddev_relerror = 0.0;
122 for (
int i = 0; i < loops; ++i) {
123 stddev_error += pow(avg_error - curmax[i], 2.0);
124 stddev_relerror += pow(avg_relerror - relerror[i], 2.0);
128 stddev_error = sqrt(stddev_error / (loops - 1));
129 stddev_relerror = sqrt(stddev_relerror / (loops - 1));
132 fprintf(stdout,
"bw = %d\tm = %d\n", bw, m);
133 fprintf(stdout,
"loops = %d\n", loops);
135 fprintf(stdout,
"Average r-o error:\t\t %.4e\t", sum_error / loops);
136 fprintf(stdout,
"std dev: %.4e\n", stddev_error);
137 fprintf(stdout,
"Average (r-o)/o error:\t\t %.4e\t", sum_relerror / loops);
138 fprintf(stdout,
"std dev: %.4e\n\n", stddev_relerror);
140 fprintf(stdout,
"average forward time = %.4e\n", total_time_f / loops);
141 fprintf(stdout,
"average inverse time = %.4e\n", total_time_i / loops);
143 fftw_destroy_plan(inverseDCT);
144 fftw_destroy_plan(forwardDCT);
152 free(transpose_cos_pml_table);