GRASS GIS 8 Programmer's Manual 8.2.0(2022)-exported
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
30/*!
31 * \brief Compute the dot product of vector x and y
32 * using the ATLAS routine cblas_ddot
33 *
34 * If grass was not compiled with ATLAS support
35 * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
36 * grass implementatiom
37 *
38 * \param x (float *)
39 * \param y (float *)
40 * \param rows (int)
41 * \return (double)
42 *
43 * */
44double 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
57/*!
58 * \brief Compute the dot product of vector x and y
59 * using the ATLAS routine cblas_sdsdot
60 *
61 * If grass was not compiled with ATLAS support
62 * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
63 * grass implementatiom
64 *
65 * \param x (float *)
66 * \param y (float *)
67 * \param a (float)
68 * \param rows (int)
69 * \return (float)
70 *
71 * */
72float 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
84/*!
85 * \brief Compute the euclidean norm of vector x
86 * using the ATLAS routine cblas_dnrm2
87 *
88 * If grass was not compiled with ATLAS support
89 * it will call #G_math_d_euclid_norm, the OpenMP multi threaded
90 * grass implementatiom
91 *
92 * \param x (double *)
93 * \param rows (int)
94 * \return (double)
95 *
96 * */
97double 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
109/*!
110 * \brief Compute the absolute sum norm of vector x
111 * using the ATLAS routine cblas_dasum
112 *
113 * If grass was not compiled with ATLAS support
114 * it will call #G_math_d_asum_norm, the OpenMP multi threaded
115 * grass implementatiom
116 *
117 * \param x (double *)
118 * \param rows (int)
119 * \return (double)
120 *
121 * */
122double 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
134/*!
135 * \brief Compute the maximum norm of vector x
136 * using the ATLAS routine cblas_idamax
137 *
138 * If grass was not compiled with ATLAS support
139 * it will call #G_math_d_max_norm, the OpenMP multi threaded
140 * grass implementatiom
141 *
142 * \param x (double *)
143 * \param rows (int)
144 * \return (double)
145 *
146 * */
147double 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
159/*!
160 * \brief Scale vector x with scalar a
161 * using the ATLAS routine cblas_dscal
162 *
163 * If grass was not compiled with ATLAS support
164 * it will call #G_math_d_ax_by, the OpenMP multi threaded
165 * grass implementatiom
166 *
167 * \param x (double *)
168 * \param a (double)
169 * \param rows (int)
170 * \return (void)
171 *
172 * */
173void 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
184/*!
185 * \brief Copy vector x to vector y
186 *
187 * If grass was not compiled with ATLAS support
188 * it will call #G_math_d_copy
189 *
190 * \param x (double *)
191 * \param y (double *)
192 * \param rows (int)
193 * \return (void)
194 *
195 * */
196void 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
208/*!
209 * \brief Scale vector x with scalar a and add it to y
210 *
211 * \f[ {\bf z} = a{\bf x} + {\bf y} \f]
212 *
213 * If grass was not compiled with ATLAS support
214 * it will call #G_math_d_ax_by, the
215 * grass implementatiom
216
217 *
218 * \param x (double *)
219 * \param y (double *)
220 * \param a (double)
221 * \param rows (int)
222 * \return (void)
223 *
224 * */
225void 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
242/*!
243 * \brief Compute the dot product of vector x and y
244 * using the ATLAS routine cblas_sdot
245 *
246 * If grass was not compiled with ATLAS support
247 * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
248 * grass implementatiom
249 *
250 * \param x (float *)
251 * \param y (float *)
252 * \param rows (int)
253 * \return (float)
254 *
255 * */
256float 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
268/*!
269 * \brief Compute the euclidean norm of vector x
270 * using the ATLAS routine cblas_dnrm2
271 *
272 * If grass was not compiled with ATLAS support
273 * it will call #G_math_f_euclid_norm, the OpenMP multi threaded
274 * grass implementatiom
275 *
276 * \param x (float *)
277 * \param rows (int)
278 * \return (float)
279 *
280 * */
281float 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
293/*!
294 * \brief Compute the absolute sum norm of vector x
295 * using the ATLAS routine cblas_dasum
296 *
297 * If grass was not compiled with ATLAS support
298 * it will call #G_math_f_asum_norm, the OpenMP multi threaded
299 * grass implementatiom
300 *
301 * \param x (float *)
302 * \param rows (int)
303 * \return (float)
304 *
305 * */
306float 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
318/*!
319 * \brief Compute the maximum norm of vector x
320 * using the ATLAS routine cblas_idamax
321 *
322 * If grass was not compiled with ATLAS support
323 * it will call #G_math_f_max_norm, the OpenMP multi threaded
324 * grass implementatiom
325 *
326 * \param x (float *)
327 * \param rows (int)
328 * \return (float)
329 *
330 * */
331float 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
343/*!
344 * \brief Scale vector x with scalar a
345 * using the ATLAS routine cblas_dscal
346 *
347 * If grass was not compiled with ATLAS support
348 * it will call #G_math_f_ax_by, the OpenMP multi threaded
349 * grass implementatiom
350 *
351 * \param x (float *)
352 * \param a (float)
353 * \param rows (int)
354 * \return (float)
355 *
356 * */
357void 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
368/*!
369 * \brief Copy vector x to vector y
370 *
371 * If grass was not compiled with ATLAS support
372 * it will call #G_math_f_copy, the
373 * grass implementatiom
374 *
375 * \param x (float *)
376 * \param y (float *)
377 * \param rows (int)
378 * \return (void)
379 *
380 * */
381void 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
393/*!
394 * \brief Scale vector x with scalar a and add it to y
395 *
396 * \f[ {\bf z} = a{\bf x} + {\bf y} \f]
397 *
398 * If grass was not compiled with ATLAS support
399 * it will call #G_math_f_ax_by, the
400 * grass implementatiom
401
402 *
403 * \param x (float *)
404 * \param y (float *)
405 * \param a (float)
406 * \param rows (int)
407 * \return (void)
408 *
409 * */
410void 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}
double G_math_idamax(double *x, int rows)
Compute the maximum norm of vector x using the ATLAS routine cblas_idamax.
float G_math_isamax(float *x, int rows)
Compute the maximum norm of vector x using the ATLAS routine cblas_idamax.
void G_math_sscal(float *x, float a, int rows)
Scale vector x with scalar a using the ATLAS routine cblas_dscal.
void G_math_saxpy(float *x, float *y, float a, int rows)
Scale vector x with scalar a and add it to y.
float G_math_snrm2(float *x, int rows)
Compute the euclidean norm of vector x using the ATLAS routine cblas_dnrm2.
void G_math_daxpy(double *x, double *y, double a, int rows)
Scale vector x with scalar a and add it to y.
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_dcopy(double *x, double *y, int rows)
Copy vector x to vector y.
double G_math_dasum(double *x, int rows)
Compute the absolute sum norm of vector x using the ATLAS routine cblas_dasum.
double G_math_dnrm2(double *x, int rows)
Compute the euclidean norm of vector x using the ATLAS routine cblas_dnrm2.
void G_math_dscal(double *x, double a, int rows)
Scale vector x with scalar a using the ATLAS routine cblas_dscal.
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.
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_scopy(float *x, float *y, int rows)
Copy vector x to vector y.
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_asum_norm(double *x, double *value, int rows)
Compute the asum norm of vector x
Definition: blas_level_1.c:112
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
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
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_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_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
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_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_copy(double *x, double *y, int rows)
Copy the vector x to y.
Definition: blas_level_1.c:237
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
void G_math_f_copy(float *x, float *y, int rows)
Copy the vector x to y.
Definition: blas_level_1.c:455
#define x