GRASS GIS 7 Programmer's Manual  7.0.2(2015)-r00000
ATLAS_wrapper_blas_level_1.c
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * MODULE: Grass numerical math interface
5 * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
6 * soerengebbert <at> googlemail <dot> com
7 *
8 * PURPOSE: grass blas implementation
9 * part of the gmath library
10 *
11 * COPYRIGHT: (C) 2010 by the GRASS Development Team
12 *
13 * This program is free software under the GNU General Public
14 * License (>=v2). Read the file COPYING that comes with GRASS
15 * for details.
16 *
17 *****************************************************************************/
18 
19 #include <math.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <grass/gmath.h>
24 
25 #if defined(HAVE_ATLAS)
26 #include <cblas.h>
27 #endif
28 
29 
44 double G_math_ddot(double *x, double *y, int rows)
45 {
46 #if defined(HAVE_ATLAS)
47  return cblas_ddot(rows, x, 1, y, 1);
48 #else
49  double val;
50 
51  G_math_d_x_dot_y(x, y, &val, rows);
52  return val;
53 #endif
54 }
55 
56 
72 float G_math_sdsdot(float *x, float *y, float a, int rows)
73 {
74 #if defined(HAVE_ATLAS)
75  return cblas_sdsdot(rows, a, x, 1, y, 1);
76 #else
77  float val;
78 
79  G_math_f_x_dot_y(x, y, &val, rows);
80  return a + val;
81 #endif
82 }
83 
97 double G_math_dnrm2(double *x, int rows)
98 {
99 #if defined(HAVE_ATLAS)
100  return cblas_dnrm2(rows, x, 1);
101 #else
102  double val;
103 
104  G_math_d_euclid_norm(x, &val, rows);
105  return val;
106 #endif
107 }
108 
122 double G_math_dasum(double *x, int rows)
123 {
124 #if defined(HAVE_ATLAS)
125  return cblas_dasum(rows, x, 1);
126 #else
127  double val;
128 
129  G_math_d_asum_norm(x, &val, rows);
130  return val;
131 #endif
132 }
133 
147 double G_math_idamax(double *x, int rows)
148 {
149 #if defined(HAVE_ATLAS)
150  return cblas_idamax(rows, x, 1);
151 #else
152  double val;
153 
154  G_math_d_max_norm(x, &val, rows);
155  return val;
156 #endif
157 }
158 
173 void G_math_dscal(double *x, double a, int rows)
174 {
175 #if defined(HAVE_ATLAS)
176  cblas_dscal(rows, a, x, 1);
177 #else
178  G_math_d_ax_by(x, x, x, a, 0.0, rows);
179 #endif
180 
181  return;
182 }
183 
196 void G_math_dcopy(double *x, double *y, int rows)
197 {
198 #if defined(HAVE_ATLAS)
199  cblas_dcopy(rows, x, 1, y, 1);
200 #else
201  G_math_d_copy(x, y, rows);
202 #endif
203 
204  return;
205 }
206 
207 
225 void G_math_daxpy(double *x, double *y, double a, int rows)
226 {
227 #if defined(HAVE_ATLAS)
228  cblas_daxpy(rows, a, x, 1, y, 1);
229 #else
230  G_math_d_ax_by(x, y, y, a, 1.0, rows);
231 #endif
232 
233  return;
234 }
235 
236 /****************************************************************** */
237 
238 /********* F L O A T / S I N G L E P E P R E C I S I O N ******** */
239 
240 /****************************************************************** */
241 
256 float G_math_sdot(float *x, float *y, int rows)
257 {
258 #if defined(HAVE_ATLAS)
259  return cblas_sdot(rows, x, 1, y, 1);
260 #else
261  float val;
262 
263  G_math_f_x_dot_y(x, y, &val, rows);
264  return val;
265 #endif
266 }
267 
281 float G_math_snrm2(float *x, int rows)
282 {
283 #if defined(HAVE_ATLAS)
284  return cblas_snrm2(rows, x, 1);
285 #else
286  float val;
287 
288  G_math_f_euclid_norm(x, &val, rows);
289  return val;
290 #endif
291 }
292 
306 float G_math_sasum(float *x, int rows)
307 {
308 #if defined(HAVE_ATLAS)
309  return cblas_sasum(rows, x, 1);
310 #else
311  float val;
312 
313  G_math_f_asum_norm(x, &val, rows);
314  return val;
315 #endif
316 }
317 
331 float G_math_isamax(float *x, int rows)
332 {
333 #if defined(HAVE_ATLAS)
334  return cblas_isamax(rows, x, 1);
335 #else
336  float val;
337 
338  G_math_f_max_norm(x, &val, rows);
339  return val;
340 #endif
341 }
342 
357 void G_math_sscal(float *x, float a, int rows)
358 {
359 #if defined(HAVE_ATLAS)
360  cblas_sscal(rows, a, x, 1);
361 #else
362  G_math_f_ax_by(x, x, x, a, 0.0, rows);
363 #endif
364 
365  return;
366 }
367 
381 void G_math_scopy(float *x, float *y, int rows)
382 {
383 #if defined(HAVE_ATLAS)
384  cblas_scopy(rows, x, 1, y, 1);
385 #else
386  G_math_f_copy(x, y, rows);
387 #endif
388 
389  return;
390 }
391 
392 
410 void G_math_saxpy(float *x, float *y, float a, int rows)
411 {
412 #if defined(HAVE_ATLAS)
413  cblas_saxpy(rows, a, x, 1, y, 1);
414 #else
415  G_math_f_ax_by(x, y, y, a, 1.0, rows);
416 #endif
417 
418  return;
419 }
void G_math_f_x_dot_y(float *x, float *y, float *value, int rows)
Compute the dot product of vector x and y.
Definition: blas_level_1.c:264
void G_math_daxpy(double *x, double *y, double a, int rows)
Scale vector x with scalar a and add it to y.
void G_math_dcopy(double *x, double *y, int rows)
Copy vector x to vector y.
void G_math_dscal(double *x, double a, int rows)
Scale vector x with scalar a using the ATLAS routine cblas_dscal.
void G_math_f_ax_by(float *x, float *y, float *z, float a, float b, int rows)
Scales vectors x and y with the scalars a and b and adds them.
Definition: blas_level_1.c:392
void G_math_d_max_norm(double *x, double *value, int rows)
Compute the maximum norm of vector x.
Definition: blas_level_1.c:142
double G_math_dnrm2(double *x, int rows)
Compute the euclidean norm of vector x using the ATLAS routine cblas_dnrm2.
float G_math_sdsdot(float *x, float *y, float a, int rows)
Compute the dot product of vector x and y using the ATLAS routine cblas_sdsdot.
void G_math_d_x_dot_y(double *x, double *y, double *value, int rows)
Compute the dot product of vector x and y.
Definition: blas_level_1.c:48
void G_math_scopy(float *x, float *y, int rows)
Copy vector x to vector y.
double G_math_idamax(double *x, int rows)
Compute the maximum norm of vector x using the ATLAS routine cblas_idamax.
void G_math_f_copy(float *x, float *y, int rows)
Copy the vector x to y.
Definition: blas_level_1.c:455
void G_math_saxpy(float *x, float *y, float a, int rows)
Scale vector x with scalar a and add it to y.
void G_math_f_max_norm(float *x, float *value, int rows)
Compute the maximum norm of vector x.
Definition: blas_level_1.c:361
void G_math_f_asum_norm(float *x, float *value, int rows)
Compute the asum norm of vector x.
Definition: blas_level_1.c:328
float G_math_sasum(float *x, int rows)
Compute the absolute sum norm of vector x using the ATLAS routine cblas_dasum.
void G_math_d_euclid_norm(double *x, double *value, int rows)
Compute the euclid norm of vector x.
Definition: blas_level_1.c:80
double G_math_dasum(double *x, int rows)
Compute the absolute sum norm of vector x using the ATLAS routine cblas_dasum.
void G_math_d_copy(double *x, double *y, int rows)
Copy the vector x to y.
Definition: blas_level_1.c:237
void G_math_d_asum_norm(double *x, double *value, int rows)
Compute the asum norm of vector x.
Definition: blas_level_1.c:112
double G_math_ddot(double *x, double *y, int rows)
Compute the dot product of vector x and y using the ATLAS routine cblas_ddot.
void G_math_sscal(float *x, float a, int rows)
Scale vector x with scalar a using the ATLAS routine cblas_dscal.
float G_math_snrm2(float *x, int rows)
Compute the euclidean norm of vector x using the ATLAS routine cblas_dnrm2.
void G_math_f_euclid_norm(float *x, float *value, int rows)
Compute the euclid norm of vector x.
Definition: blas_level_1.c:296
void G_math_d_ax_by(double *x, double *y, double *z, double a, double b, int rows)
Scales vectors x and y with the scalars a and b and adds them.
Definition: blas_level_1.c:173
float G_math_isamax(float *x, int rows)
Compute the maximum norm of vector x using the ATLAS routine cblas_idamax.
float G_math_sdot(float *x, float *y, int rows)
Compute the dot product of vector x and y using the ATLAS routine cblas_sdot.