GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
ATLAS_wrapper_blas_level_1.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * MODULE: Grass numerical math interface
4 * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
5 * soerengebbert <at> googlemail <dot> com
6 *
7 * PURPOSE: grass blas implementation
8 * part of the gmath library
9 *
10 * COPYRIGHT: (C) 2010 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 <math.h>
19#include <unistd.h>
20#include <stdio.h>
21#include <string.h>
22#include <grass/gmath.h>
23
24#if defined(HAVE_ATLAS)
25#include <cblas.h>
26#endif
27
28/*!
29 * \brief Compute the dot product of vector x and y
30 * using the ATLAS routine cblas_ddot
31 *
32 * If grass was not compiled with ATLAS support
33 * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
34 * grass implementatiom
35 *
36 * \param x (float *)
37 * \param y (float *)
38 * \param rows (int)
39 * \return (double)
40 *
41 * */
42double G_math_ddot(double *x, double *y, int rows)
43{
44#if defined(HAVE_ATLAS)
45 return cblas_ddot(rows, x, 1, y, 1);
46#else
47 double val;
48
49 G_math_d_x_dot_y(x, y, &val, rows);
50 return val;
51#endif
52}
53
54/*!
55 * \brief Compute the dot product of vector x and y
56 * using the ATLAS routine cblas_sdsdot
57 *
58 * If grass was not compiled with ATLAS support
59 * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
60 * grass implementatiom
61 *
62 * \param x (float *)
63 * \param y (float *)
64 * \param a (float)
65 * \param rows (int)
66 * \return (float)
67 *
68 * */
69float G_math_sdsdot(float *x, float *y, float a, int rows)
70{
71#if defined(HAVE_ATLAS)
72 return cblas_sdsdot(rows, a, x, 1, y, 1);
73#else
74 float val;
75
76 G_math_f_x_dot_y(x, y, &val, rows);
77 return a + val;
78#endif
79}
80
81/*!
82 * \brief Compute the euclidean norm of vector x
83 * using the ATLAS routine cblas_dnrm2
84 *
85 * If grass was not compiled with ATLAS support
86 * it will call #G_math_d_euclid_norm, the OpenMP multi threaded
87 * grass implementatiom
88 *
89 * \param x (double *)
90 * \param rows (int)
91 * \return (double)
92 *
93 * */
94double G_math_dnrm2(double *x, int rows)
95{
96#if defined(HAVE_ATLAS)
97 return cblas_dnrm2(rows, x, 1);
98#else
99 double val;
100
101 G_math_d_euclid_norm(x, &val, rows);
102 return val;
103#endif
104}
105
106/*!
107 * \brief Compute the absolute sum norm of vector x
108 * using the ATLAS routine cblas_dasum
109 *
110 * If grass was not compiled with ATLAS support
111 * it will call #G_math_d_asum_norm, the OpenMP multi threaded
112 * grass implementatiom
113 *
114 * \param x (double *)
115 * \param rows (int)
116 * \return (double)
117 *
118 * */
119double G_math_dasum(double *x, int rows)
120{
121#if defined(HAVE_ATLAS)
122 return cblas_dasum(rows, x, 1);
123#else
124 double val;
125
126 G_math_d_asum_norm(x, &val, rows);
127 return val;
128#endif
129}
130
131/*!
132 * \brief Compute the maximum norm of vector x
133 * using the ATLAS routine cblas_idamax
134 *
135 * If grass was not compiled with ATLAS support
136 * it will call #G_math_d_max_norm, the OpenMP multi threaded
137 * grass implementatiom
138 *
139 * \param x (double *)
140 * \param rows (int)
141 * \return (double)
142 *
143 * */
144double G_math_idamax(double *x, int rows)
145{
146#if defined(HAVE_ATLAS)
147 return cblas_idamax(rows, x, 1);
148#else
149 double val;
150
151 G_math_d_max_norm(x, &val, rows);
152 return val;
153#endif
154}
155
156/*!
157 * \brief Scale vector x with scalar a
158 * using the ATLAS routine cblas_dscal
159 *
160 * If grass was not compiled with ATLAS support
161 * it will call #G_math_d_ax_by, the OpenMP multi threaded
162 * grass implementatiom
163 *
164 * \param x (double *)
165 * \param a (double)
166 * \param rows (int)
167 * \return (void)
168 *
169 * */
170void G_math_dscal(double *x, double a, int rows)
171{
172#if defined(HAVE_ATLAS)
173 cblas_dscal(rows, a, x, 1);
174#else
175 G_math_d_ax_by(x, x, x, a, 0.0, rows);
176#endif
177
178 return;
179}
180
181/*!
182 * \brief Copy vector x to vector y
183 *
184 * If grass was not compiled with ATLAS support
185 * it will call #G_math_d_copy
186 *
187 * \param x (double *)
188 * \param y (double *)
189 * \param rows (int)
190 * \return (void)
191 *
192 * */
193void G_math_dcopy(double *x, double *y, int rows)
194{
195#if defined(HAVE_ATLAS)
196 cblas_dcopy(rows, x, 1, y, 1);
197#else
198 G_math_d_copy(x, y, rows);
199#endif
200
201 return;
202}
203
204/*!
205 * \brief Scale vector x with scalar a and add it to y
206 *
207 * \f[ {\bf z} = a{\bf x} + {\bf y} \f]
208 *
209 * If grass was not compiled with ATLAS support
210 * it will call #G_math_d_ax_by, the
211 * grass implementatiom
212
213 *
214 * \param x (double *)
215 * \param y (double *)
216 * \param a (double)
217 * \param rows (int)
218 * \return (void)
219 *
220 * */
221void G_math_daxpy(double *x, double *y, double a, int rows)
222{
223#if defined(HAVE_ATLAS)
224 cblas_daxpy(rows, a, x, 1, y, 1);
225#else
226 G_math_d_ax_by(x, y, y, a, 1.0, rows);
227#endif
228
229 return;
230}
231
232/****************************************************************** */
233
234/********* F L O A T / S I N G L E P E P R E C I S I O N ******** */
235
236/****************************************************************** */
237
238/*!
239 * \brief Compute the dot product of vector x and y
240 * using the ATLAS routine cblas_sdot
241 *
242 * If grass was not compiled with ATLAS support
243 * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
244 * grass implementatiom
245 *
246 * \param x (float *)
247 * \param y (float *)
248 * \param rows (int)
249 * \return (float)
250 *
251 * */
252float G_math_sdot(float *x, float *y, int rows)
253{
254#if defined(HAVE_ATLAS)
255 return cblas_sdot(rows, x, 1, y, 1);
256#else
257 float val;
258
259 G_math_f_x_dot_y(x, y, &val, rows);
260 return val;
261#endif
262}
263
264/*!
265 * \brief Compute the euclidean norm of vector x
266 * using the ATLAS routine cblas_dnrm2
267 *
268 * If grass was not compiled with ATLAS support
269 * it will call #G_math_f_euclid_norm, the OpenMP multi threaded
270 * grass implementatiom
271 *
272 * \param x (float *)
273 * \param rows (int)
274 * \return (float)
275 *
276 * */
277float G_math_snrm2(float *x, int rows)
278{
279#if defined(HAVE_ATLAS)
280 return cblas_snrm2(rows, x, 1);
281#else
282 float val;
283
284 G_math_f_euclid_norm(x, &val, rows);
285 return val;
286#endif
287}
288
289/*!
290 * \brief Compute the absolute sum norm of vector x
291 * using the ATLAS routine cblas_dasum
292 *
293 * If grass was not compiled with ATLAS support
294 * it will call #G_math_f_asum_norm, the OpenMP multi threaded
295 * grass implementatiom
296 *
297 * \param x (float *)
298 * \param rows (int)
299 * \return (float)
300 *
301 * */
302float G_math_sasum(float *x, int rows)
303{
304#if defined(HAVE_ATLAS)
305 return cblas_sasum(rows, x, 1);
306#else
307 float val;
308
309 G_math_f_asum_norm(x, &val, rows);
310 return val;
311#endif
312}
313
314/*!
315 * \brief Compute the maximum norm of vector x
316 * using the ATLAS routine cblas_idamax
317 *
318 * If grass was not compiled with ATLAS support
319 * it will call #G_math_f_max_norm, the OpenMP multi threaded
320 * grass implementatiom
321 *
322 * \param x (float *)
323 * \param rows (int)
324 * \return (float)
325 *
326 * */
327float G_math_isamax(float *x, int rows)
328{
329#if defined(HAVE_ATLAS)
330 return cblas_isamax(rows, x, 1);
331#else
332 float val;
333
334 G_math_f_max_norm(x, &val, rows);
335 return val;
336#endif
337}
338
339/*!
340 * \brief Scale vector x with scalar a
341 * using the ATLAS routine cblas_dscal
342 *
343 * If grass was not compiled with ATLAS support
344 * it will call #G_math_f_ax_by, the OpenMP multi threaded
345 * grass implementatiom
346 *
347 * \param x (float *)
348 * \param a (float)
349 * \param rows (int)
350 * \return (float)
351 *
352 * */
353void G_math_sscal(float *x, float a, int rows)
354{
355#if defined(HAVE_ATLAS)
356 cblas_sscal(rows, a, x, 1);
357#else
358 G_math_f_ax_by(x, x, x, a, 0.0, rows);
359#endif
360
361 return;
362}
363
364/*!
365 * \brief Copy vector x to vector y
366 *
367 * If grass was not compiled with ATLAS support
368 * it will call #G_math_f_copy, the
369 * grass implementatiom
370 *
371 * \param x (float *)
372 * \param y (float *)
373 * \param rows (int)
374 * \return (void)
375 *
376 * */
377void G_math_scopy(float *x, float *y, int rows)
378{
379#if defined(HAVE_ATLAS)
380 cblas_scopy(rows, x, 1, y, 1);
381#else
382 G_math_f_copy(x, y, rows);
383#endif
384
385 return;
386}
387
388/*!
389 * \brief Scale vector x with scalar a and add it to y
390 *
391 * \f[ {\bf z} = a{\bf x} + {\bf y} \f]
392 *
393 * If grass was not compiled with ATLAS support
394 * it will call #G_math_f_ax_by, the
395 * grass implementatiom
396
397 *
398 * \param x (float *)
399 * \param y (float *)
400 * \param a (float)
401 * \param rows (int)
402 * \return (void)
403 *
404 * */
405void G_math_saxpy(float *x, float *y, float a, int rows)
406{
407#if defined(HAVE_ATLAS)
408 cblas_saxpy(rows, a, x, 1, y, 1);
409#else
410 G_math_f_ax_by(x, y, y, a, 1.0, rows);
411#endif
412
413 return;
414}
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.
void G_math_f_asum_norm(float *x, float *value, int rows)
Compute the asum norm of vector x.
void G_math_d_max_norm(double *x, double *value, int rows)
Compute the maximum norm of vector x.
void G_math_f_max_norm(float *x, float *value, int rows)
Compute the maximum norm of vector x.
void G_math_d_x_dot_y(double *x, double *y, double *value, int rows)
Compute the dot product of vector x and y.
void G_math_f_euclid_norm(float *x, float *value, int rows)
Compute the euclid norm of vector x.
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.
void G_math_f_x_dot_y(float *x, float *y, float *value, int rows)
Compute the dot product of vector x and y.
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.
void G_math_d_copy(double *x, double *y, int rows)
Copy the vector x to y.
void G_math_d_euclid_norm(double *x, double *value, int rows)
Compute the euclid norm of vector x.
void G_math_f_copy(float *x, float *y, int rows)
Copy the vector x to y.
#define x