~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/gmath/test/test_blas3.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*****************************************************************************
 
3
*
 
4
* MODULE:       Grass PDE Numerical Library
 
5
* AUTHOR(S):    Soeren Gebbert, Berlin (GER) Dec 2007
 
6
*               soerengebbert <at> gmx <dot> de
 
7
*               
 
8
* PURPOSE:      Unit tests for les creation
 
9
*
 
10
* COPYRIGHT:    (C) 2007 by the GRASS Development Team
 
11
*
 
12
*               This program is free software under the GNU General Public
 
13
*               License (>=v2). Read the file COPYING that comes with GRASS
 
14
*               for details.
 
15
*
 
16
*****************************************************************************/
 
17
 
 
18
#include <grass/gis.h>
 
19
#include <grass/glocale.h>
 
20
#include <grass/gmath.h>
 
21
#include <math.h>
 
22
#include "test_gmath_lib.h"
 
23
 
 
24
#define EPSILON 0.0000001
 
25
 
 
26
/* prototypes */
 
27
static int test_blas_level_3_double(void);
 
28
static int test_blas_level_3_float(void);
 
29
 
 
30
 
 
31
/* *************************************************************** */
 
32
/* Perfrome the blas level 3 unit tests ************************** */
 
33
/* *************************************************************** */
 
34
int unit_test_blas_level_3(void)
 
35
{
 
36
    int sum = 0;
 
37
 
 
38
    G_message(_("\n++ Running blas level 3 unit tests ++"));
 
39
 
 
40
    sum += test_blas_level_3_double();
 
41
    sum += test_blas_level_3_float();
 
42
 
 
43
    if (sum > 0)
 
44
        G_warning(_("\n-- blas level 3 unit tests failure --"));
 
45
    else
 
46
        G_message(_("\n-- blas level 3 unit tests finished successfully --"));
 
47
 
 
48
    return sum;
 
49
}
 
50
 
 
51
/* *************************************************************** */
 
52
/* ************** D O U B L E ************************************ */
 
53
/* *************************************************************** */
 
54
int test_blas_level_3_double(void)
 
55
{
 
56
 
 
57
    int sum = 0;
 
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;
 
61
 
 
62
    x = G_alloc_vector(cols);
 
63
    y = G_alloc_vector(rows);
 
64
 
 
65
    A = G_alloc_matrix(rows, cols);
 
66
    B = G_alloc_matrix(rows, cols);
 
67
    C = G_alloc_matrix(rows, cols);
 
68
 
 
69
    fill_d_vector_scalar(x, 1, cols);
 
70
    fill_d_vector_scalar(y, 0, rows);
 
71
 
 
72
    fill_d_vector_scalar(A[0], 1, rows*cols);
 
73
    fill_d_vector_scalar(B[0], 2, rows*cols);
 
74
 
 
75
#pragma omp parallel default(shared)
 
76
{
 
77
    G_math_d_aA_B(A, B, 1.0 , C, rows , cols );
 
78
    G_math_d_Ax(C, x, y, rows, cols);
 
79
}
 
80
    G_math_d_asum_norm(y, &a, rows);
 
81
 
 
82
 
 
83
    if(a != 3*rows*cols) {
 
84
        G_message("Error in G_math_d_aA_B: %f != %f", a, (double)3*rows*cols);
 
85
        sum++;
 
86
    }
 
87
#pragma omp parallel default(shared)
 
88
{
 
89
    G_math_d_aA_B(A, B, -1.0 , C, rows , cols );
 
90
    G_math_d_Ax(C, x, y, rows, cols);
 
91
}
 
92
    G_math_d_asum_norm(y, &b, rows);
 
93
 
 
94
 
 
95
    if(b != rows*cols) {
 
96
        G_message("Error in G_math_d_aA_B: %f != %f", b, (double)rows*cols);
 
97
        sum++;
 
98
    }
 
99
#pragma omp parallel default(shared)
 
100
{
 
101
    G_math_d_aA_B(A, B, 2.0 , C, rows , cols );
 
102
    G_math_d_Ax(C, x, y, rows, cols);
 
103
}
 
104
    G_math_d_asum_norm(y, &c, rows);
 
105
 
 
106
 
 
107
    if(c != 4*rows*cols) {
 
108
        G_message("Error in G_math_d_aA_B: %f != %f", c, (double)4*rows*cols);
 
109
        sum++;
 
110
    }
 
111
 
 
112
    G_free_matrix(A);
 
113
    G_free_matrix(B);
 
114
    G_free_matrix(C);
 
115
    A = G_alloc_matrix(rows, cols);
 
116
    B = G_alloc_matrix(cols, rows);
 
117
    C = G_alloc_matrix(rows, rows);
 
118
 
 
119
    G_free_vector(x);
 
120
    G_free_vector(y);
 
121
    x = G_alloc_vector(rows);
 
122
    y = G_alloc_vector(rows);
 
123
 
 
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);
 
128
 
 
129
#pragma omp parallel default(shared)
 
130
{
 
131
    G_math_d_AB(A, B, C, rows , cols , cols );
 
132
    G_math_d_Ax(C, x, y, rows, cols);
 
133
}
 
134
    G_math_d_asum_norm(y, &d, rows);
 
135
 
 
136
 
 
137
    if(d != 2*rows*cols*cols) {
 
138
        G_message("Error in G_math_d_AB: %f != %f", d, (double)2*rows*cols*cols);
 
139
        sum++;
 
140
    }
 
141
 
 
142
    if(x)
 
143
      G_free_vector(x);
 
144
    if(y)
 
145
      G_free_vector(y);
 
146
 
 
147
    if(A)
 
148
      G_free_matrix(A);
 
149
    if(B)
 
150
      G_free_matrix(B);
 
151
    if(C)
 
152
      G_free_matrix(C);
 
153
 
 
154
    return sum;
 
155
}
 
156
 
 
157
 
 
158
/* *************************************************************** */
 
159
/* ************** F L O A T ************************************** */
 
160
/* *************************************************************** */
 
161
int test_blas_level_3_float(void)
 
162
{
 
163
 
 
164
    int sum = 0;
 
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;
 
168
 
 
169
    x = G_alloc_fvector(cols);
 
170
    y = G_alloc_fvector(rows);
 
171
 
 
172
    A = G_alloc_fmatrix(rows, cols);
 
173
    B = G_alloc_fmatrix(rows, cols);
 
174
    C = G_alloc_fmatrix(rows, cols);
 
175
 
 
176
    fill_f_vector_scalar(x, 1, cols);
 
177
    fill_f_vector_scalar(y, 0, rows);
 
178
 
 
179
    fill_f_vector_scalar(A[0], 1, rows*cols);
 
180
    fill_f_vector_scalar(B[0], 2, rows*cols);
 
181
 
 
182
#pragma omp parallel default(shared)
 
183
{
 
184
    G_math_f_aA_B(A, B, 1.0 , C, rows , cols );
 
185
    G_math_f_Ax(C, x, y, rows, cols);
 
186
}
 
187
    G_math_f_asum_norm(y, &a, rows);
 
188
 
 
189
    if(a != 3*rows*cols) {
 
190
        G_message("Error in G_math_f_aA_B: %f != %f", a, (double)3*rows*cols);
 
191
        sum++;
 
192
    }
 
193
#pragma omp parallel default(shared)
 
194
{
 
195
    G_math_f_aA_B(A, B, -1.0 , C, rows , cols );
 
196
    G_math_f_Ax(C, x, y, rows, cols);
 
197
}
 
198
    G_math_f_asum_norm(y, &b, rows);
 
199
 
 
200
    if(b != rows*cols) {
 
201
        G_message("Error in G_math_f_aA_B: %f != %f", b, (double)rows*cols);
 
202
        sum++;
 
203
    }
 
204
#pragma omp parallel default(shared)
 
205
{
 
206
    G_math_f_aA_B(A, B, 2.0 , C, rows , cols );
 
207
    G_math_f_Ax(C, x, y, rows, cols);
 
208
}
 
209
    G_math_f_asum_norm(y, &c, rows);
 
210
 
 
211
    if(c != 4*rows*cols) {
 
212
        G_message("Error in G_math_f_aA_B: %f != %f", c, (double)4*rows*cols);
 
213
        sum++;
 
214
    }
 
215
 
 
216
    G_free_fmatrix(A);
 
217
    G_free_fmatrix(B);
 
218
    G_free_fmatrix(C);
 
219
    A = G_alloc_fmatrix(rows, cols);
 
220
    B = G_alloc_fmatrix(cols, rows);
 
221
    C = G_alloc_fmatrix(rows, rows);
 
222
 
 
223
    G_free_fvector(x);
 
224
    G_free_fvector(y);
 
225
    x = G_alloc_fvector(rows);
 
226
    y = G_alloc_fvector(rows);
 
227
 
 
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);
 
232
 
 
233
#pragma omp parallel default(shared)
 
234
{
 
235
    G_math_f_AB(A, B, C, rows , cols , cols );
 
236
    G_math_f_Ax(C, x, y, rows, cols);
 
237
}
 
238
    G_math_f_asum_norm(y, &d, rows);
 
239
 
 
240
 
 
241
    if(d != 2*rows*cols*cols) {
 
242
        G_message("Error in G_math_f_AB: %f != %f", d, (double)2*rows*cols*cols);
 
243
        sum++;
 
244
    }
 
245
 
 
246
    if(x)
 
247
      G_free_fvector(x);
 
248
    if(y)
 
249
      G_free_fvector(y);
 
250
 
 
251
    if(A)
 
252
      G_free_fmatrix(A);
 
253
    if(B)
 
254
      G_free_fmatrix(B);
 
255
    if(C)
 
256
      G_free_fmatrix(C);
 
257
 
 
258
    return sum;
 
259
}