2
/*****************************************************************************
4
* MODULE: Grass PDE Numerical Library
5
* AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2007
6
* soerengebbert <at> gmx <dot> de
8
* PURPOSE: Unit tests for les creation
10
* COPYRIGHT: (C) 2007 by the GRASS Development Team
12
* This program is free software under the GNU General Public
13
* License (>=v2). Read the file COPYING that comes with GRASS
16
*****************************************************************************/
18
#include <grass/gis.h>
19
#include <grass/glocale.h>
20
#include <grass/gmath.h>
22
#include "test_gmath_lib.h"
24
#define EPSILON 0.0000001
27
static int test_blas_level_3_double(void);
28
static int test_blas_level_3_float(void);
31
/* *************************************************************** */
32
/* Perfrome the blas level 3 unit tests ************************** */
33
/* *************************************************************** */
34
int unit_test_blas_level_3(void)
38
G_message(_("\n++ Running blas level 3 unit tests ++"));
40
sum += test_blas_level_3_double();
41
sum += test_blas_level_3_float();
44
G_warning(_("\n-- blas level 3 unit tests failure --"));
46
G_message(_("\n-- blas level 3 unit tests finished successfully --"));
51
/* *************************************************************** */
52
/* ************** D O U B L E ************************************ */
53
/* *************************************************************** */
54
int test_blas_level_3_double(void)
58
int rows = TEST_NUM_ROWS;
59
int cols = TEST_NUM_COLS;
60
double **A, **B, **C, *x, *y, a = 0.0, b = 0.0, c = 0.0, d = 0.0;
62
x = G_alloc_vector(cols);
63
y = G_alloc_vector(rows);
65
A = G_alloc_matrix(rows, cols);
66
B = G_alloc_matrix(rows, cols);
67
C = G_alloc_matrix(rows, cols);
69
fill_d_vector_scalar(x, 1, cols);
70
fill_d_vector_scalar(y, 0, rows);
72
fill_d_vector_scalar(A[0], 1, rows*cols);
73
fill_d_vector_scalar(B[0], 2, rows*cols);
75
#pragma omp parallel default(shared)
77
G_math_d_aA_B(A, B, 1.0 , C, rows , cols );
78
G_math_d_Ax(C, x, y, rows, cols);
80
G_math_d_asum_norm(y, &a, rows);
83
if(a != 3*rows*cols) {
84
G_message("Error in G_math_d_aA_B: %f != %f", a, (double)3*rows*cols);
87
#pragma omp parallel default(shared)
89
G_math_d_aA_B(A, B, -1.0 , C, rows , cols );
90
G_math_d_Ax(C, x, y, rows, cols);
92
G_math_d_asum_norm(y, &b, rows);
96
G_message("Error in G_math_d_aA_B: %f != %f", b, (double)rows*cols);
99
#pragma omp parallel default(shared)
101
G_math_d_aA_B(A, B, 2.0 , C, rows , cols );
102
G_math_d_Ax(C, x, y, rows, cols);
104
G_math_d_asum_norm(y, &c, rows);
107
if(c != 4*rows*cols) {
108
G_message("Error in G_math_d_aA_B: %f != %f", c, (double)4*rows*cols);
115
A = G_alloc_matrix(rows, cols);
116
B = G_alloc_matrix(cols, rows);
117
C = G_alloc_matrix(rows, rows);
121
x = G_alloc_vector(rows);
122
y = G_alloc_vector(rows);
124
fill_d_vector_scalar(x, 1, rows);
125
fill_d_vector_scalar(y, 0, rows);
126
fill_d_vector_scalar(A[0], 1, rows*cols);
127
fill_d_vector_scalar(B[0], 2, rows*cols);
129
#pragma omp parallel default(shared)
131
G_math_d_AB(A, B, C, rows , cols , cols );
132
G_math_d_Ax(C, x, y, rows, cols);
134
G_math_d_asum_norm(y, &d, rows);
137
if(d != 2*rows*cols*cols) {
138
G_message("Error in G_math_d_AB: %f != %f", d, (double)2*rows*cols*cols);
158
/* *************************************************************** */
159
/* ************** F L O A T ************************************** */
160
/* *************************************************************** */
161
int test_blas_level_3_float(void)
165
int rows = TEST_NUM_ROWS;
166
int cols = TEST_NUM_COLS;
167
float **A, **B, **C, *x, *y, a = 0.0, b = 0.0, c = 0.0, d = 0.0;
169
x = G_alloc_fvector(cols);
170
y = G_alloc_fvector(rows);
172
A = G_alloc_fmatrix(rows, cols);
173
B = G_alloc_fmatrix(rows, cols);
174
C = G_alloc_fmatrix(rows, cols);
176
fill_f_vector_scalar(x, 1, cols);
177
fill_f_vector_scalar(y, 0, rows);
179
fill_f_vector_scalar(A[0], 1, rows*cols);
180
fill_f_vector_scalar(B[0], 2, rows*cols);
182
#pragma omp parallel default(shared)
184
G_math_f_aA_B(A, B, 1.0 , C, rows , cols );
185
G_math_f_Ax(C, x, y, rows, cols);
187
G_math_f_asum_norm(y, &a, rows);
189
if(a != 3*rows*cols) {
190
G_message("Error in G_math_f_aA_B: %f != %f", a, (double)3*rows*cols);
193
#pragma omp parallel default(shared)
195
G_math_f_aA_B(A, B, -1.0 , C, rows , cols );
196
G_math_f_Ax(C, x, y, rows, cols);
198
G_math_f_asum_norm(y, &b, rows);
201
G_message("Error in G_math_f_aA_B: %f != %f", b, (double)rows*cols);
204
#pragma omp parallel default(shared)
206
G_math_f_aA_B(A, B, 2.0 , C, rows , cols );
207
G_math_f_Ax(C, x, y, rows, cols);
209
G_math_f_asum_norm(y, &c, rows);
211
if(c != 4*rows*cols) {
212
G_message("Error in G_math_f_aA_B: %f != %f", c, (double)4*rows*cols);
219
A = G_alloc_fmatrix(rows, cols);
220
B = G_alloc_fmatrix(cols, rows);
221
C = G_alloc_fmatrix(rows, rows);
225
x = G_alloc_fvector(rows);
226
y = G_alloc_fvector(rows);
228
fill_f_vector_scalar(x, 1, rows);
229
fill_f_vector_scalar(y, 0, rows);
230
fill_f_vector_scalar(A[0], 1, rows*cols);
231
fill_f_vector_scalar(B[0], 2, rows*cols);
233
#pragma omp parallel default(shared)
235
G_math_f_AB(A, B, C, rows , cols , cols );
236
G_math_f_Ax(C, x, y, rows, cols);
238
G_math_f_asum_norm(y, &d, rows);
241
if(d != 2*rows*cols*cols) {
242
G_message("Error in G_math_f_AB: %f != %f", d, (double)2*rows*cols*cols);