|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 00002 /***************************************************************************** 00003 * 00004 * MODULE: Grass PDE Numerical Library 00005 * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006 00006 * soerengebbert <at> gmx <dot> de 00007 * 00008 * PURPOSE: blas level 1 like functions 00009 * part of the gpde library 00010 * 00011 * COPYRIGHT: (C) 2000 by the GRASS Development Team 00012 * 00013 * This program is free software under the GNU General Public 00014 * License (>=v2). Read the file COPYING that comes with GRASS 00015 * for details. 00016 * 00017 *****************************************************************************/ 00018 00019 #include <math.h> 00020 #include <unistd.h> 00021 #include <stdio.h> 00022 #include <string.h> 00023 #include <grass/gmath.h> 00024 00025 #if defined(HAVE_ATLAS) 00026 #include <cblas.h> 00027 #endif 00028 00029 00044 double G_math_ddot(double *x, double *y, int rows) 00045 { 00046 #if defined(HAVE_ATLAS) 00047 return cblas_ddot(rows, x, 1, y, 1); 00048 #else 00049 double val; 00050 00051 G_math_d_x_dot_y(x, y, &val, rows); 00052 return val; 00053 #endif 00054 } 00055 00056 00072 float G_math_sdsdot(float *x, float *y, float a, int rows) 00073 { 00074 #if defined(HAVE_ATLAS) 00075 return cblas_sdsdot(rows, a, x, 1, y, 1); 00076 #else 00077 float val; 00078 00079 G_math_f_x_dot_y(x, y, &val, rows); 00080 return a + val; 00081 #endif 00082 } 00083 00097 double G_math_dnrm2(double *x, int rows) 00098 { 00099 #if defined(HAVE_ATLAS) 00100 return cblas_dnrm2(rows, x, 1); 00101 #else 00102 double val; 00103 00104 G_math_d_euclid_norm(x, &val, rows); 00105 return val; 00106 #endif 00107 } 00108 00122 double G_math_dasum(double *x, int rows) 00123 { 00124 #if defined(HAVE_ATLAS) 00125 return cblas_dasum(rows, x, 1); 00126 #else 00127 double val; 00128 00129 G_math_d_asum_norm(x, &val, rows); 00130 return val; 00131 #endif 00132 } 00133 00147 double G_math_idamax(double *x, int rows) 00148 { 00149 #if defined(HAVE_ATLAS) 00150 return cblas_idamax(rows, x, 1); 00151 #else 00152 double val; 00153 00154 G_math_d_max_norm(x, &val, rows); 00155 return val; 00156 #endif 00157 } 00158 00172 void G_math_dscal(double *x, double a, int rows) 00173 { 00174 #if defined(HAVE_ATLAS) 00175 cblas_dscal(rows, a, x, 1); 00176 #else 00177 G_math_d_ax_by(x, x, x, a, 0.0, rows); 00178 #endif 00179 00180 return; 00181 } 00182 00195 void G_math_dcopy(double *x, double *y, int rows) 00196 { 00197 #if defined(HAVE_ATLAS) 00198 cblas_dcopy(rows, x, 1, y, 1); 00199 #else 00200 G_math_d_copy(x, y, rows); 00201 #endif 00202 00203 return; 00204 } 00205 00206 00224 void G_math_daxpy(double *x, double *y, double a, int rows) 00225 { 00226 #if defined(HAVE_ATLAS) 00227 cblas_daxpy(rows, a, x, 1, y, 1); 00228 #else 00229 G_math_d_ax_by(x, y, y, a, 1.0, rows); 00230 #endif 00231 00232 return; 00233 } 00234 00235 /****************************************************************** */ 00236 00237 /********* F L O A T / S I N G L E P E P R E C I S I O N ******** */ 00238 00239 /****************************************************************** */ 00240 00255 float G_math_sdot(float *x, float *y, int rows) 00256 { 00257 #if defined(HAVE_ATLAS) 00258 return cblas_sdot(rows, x, 1, y, 1); 00259 #else 00260 float val; 00261 00262 G_math_f_x_dot_y(x, y, &val, rows); 00263 return val; 00264 #endif 00265 } 00266 00280 float G_math_snrm2(float *x, int rows) 00281 { 00282 #if defined(HAVE_ATLAS) 00283 return cblas_snrm2(rows, x, 1); 00284 #else 00285 float val; 00286 00287 G_math_f_euclid_norm(x, &val, rows); 00288 return val; 00289 #endif 00290 } 00291 00305 float G_math_sasum(float *x, int rows) 00306 { 00307 #if defined(HAVE_ATLAS) 00308 return cblas_sasum(rows, x, 1); 00309 #else 00310 float val; 00311 00312 G_math_f_asum_norm(x, &val, rows); 00313 return val; 00314 #endif 00315 } 00316 00330 float G_math_isamax(float *x, int rows) 00331 { 00332 #if defined(HAVE_ATLAS) 00333 return cblas_isamax(rows, x, 1); 00334 #else 00335 float val; 00336 00337 G_math_f_max_norm(x, &val, rows); 00338 return val; 00339 #endif 00340 } 00341 00355 void G_math_sscal(float *x, float a, int rows) 00356 { 00357 #if defined(HAVE_ATLAS) 00358 cblas_sscal(rows, a, x, 1); 00359 #else 00360 G_math_f_ax_by(x, x, x, a, 0.0, rows); 00361 #endif 00362 00363 return; 00364 } 00365 00379 void G_math_scopy(float *x, float *y, int rows) 00380 { 00381 #if defined(HAVE_ATLAS) 00382 cblas_scopy(rows, x, 1, y, 1); 00383 #else 00384 G_math_f_copy(x, y, rows); 00385 #endif 00386 00387 return; 00388 } 00389 00390 00408 void G_math_saxpy(float *x, float *y, float a, int rows) 00409 { 00410 #if defined(HAVE_ATLAS) 00411 cblas_saxpy(rows, a, x, 1, y, 1); 00412 #else 00413 G_math_f_ax_by(x, y, y, a, 1.0, rows); 00414 #endif 00415 00416 return; 00417 }