123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- /*****************************************************************************
- *
- * MODULE: Grass numerical math interface
- * AUTHOR(S): Soeren Gebbert, Berlin (GER) Dec 2006
- * soerengebbert <at> googlemail <dot> com
- *
- * PURPOSE: grass blas implementation
- * part of the gmath library
- *
- * COPYRIGHT: (C) 2010 by the GRASS Development Team
- *
- * This program is free software under the GNU General Public
- * License (>=v2). Read the file COPYING that comes with GRASS
- * for details.
- *
- *****************************************************************************/
- #include <math.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <string.h>
- #include <grass/gmath.h>
- #if defined(HAVE_ATLAS)
- #include <cblas.h>
- #endif
- /*!
- * \brief Compute the dot product of vector x and y
- * using the ATLAS routine cblas_ddot
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param y (float *)
- * \param rows (int)
- * \return (double)
- *
- * */
- double G_math_ddot(double *x, double *y, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_ddot(rows, x, 1, y, 1);
- #else
- double val;
- G_math_d_x_dot_y(x, y, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Compute the dot product of vector x and y
- * using the ATLAS routine cblas_sdsdot
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param y (float *)
- * \param a (float)
- * \param rows (int)
- * \return (float)
- *
- * */
- float G_math_sdsdot(float *x, float *y, float a, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_sdsdot(rows, a, x, 1, y, 1);
- #else
- float val;
- G_math_f_x_dot_y(x, y, &val, rows);
- return a + val;
- #endif
- }
- /*!
- * \brief Compute the euclidean norm of vector x
- * using the ATLAS routine cblas_dnrm2
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_d_euclid_norm, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (double *)
- * \param rows (int)
- * \return (double)
- *
- * */
- double G_math_dnrm2(double *x, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_dnrm2(rows, x, 1);
- #else
- double val;
- G_math_d_euclid_norm(x, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Compute the absolute sum norm of vector x
- * using the ATLAS routine cblas_dasum
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_d_asum_norm, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (double *)
- * \param rows (int)
- * \return (double)
- *
- * */
- double G_math_dasum(double *x, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_dasum(rows, x, 1);
- #else
- double val;
- G_math_d_asum_norm(x, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Compute the maximum norm of vector x
- * using the ATLAS routine cblas_idamax
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_d_max_norm, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (double *)
- * \param rows (int)
- * \return (double)
- *
- * */
- double G_math_idamax(double *x, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_idamax(rows, x, 1);
- #else
- double val;
- G_math_d_max_norm(x, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Scale vector x with scalar a
- * using the ATLAS routine cblas_dscal
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_d_ax_by, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (double *)
- * \param a (double)
- * \param rows (int)
- * \return (void)
- *
- * */
- void G_math_dscal(double *x, double a, int rows)
- {
- #if defined(HAVE_ATLAS)
- cblas_dscal(rows, a, x, 1);
- #else
- G_math_d_ax_by(x, x, x, a, 0.0, rows);
- #endif
- return;
- }
- /*!
- * \brief Copy vector x to vector y
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_d_copy
- *
- * \param x (double *)
- * \param y (double *)
- * \param rows (int)
- * \return (void)
- *
- * */
- void G_math_dcopy(double *x, double *y, int rows)
- {
- #if defined(HAVE_ATLAS)
- cblas_dcopy(rows, x, 1, y, 1);
- #else
- G_math_d_copy(x, y, rows);
- #endif
- return;
- }
- /*!
- * \brief Scale vector x with scalar a and add it to y
- *
- * \f[ {\bf z} = a{\bf x} + {\bf y} \f]
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_d_ax_by, the
- * grass implementatiom
- *
- * \param x (double *)
- * \param y (double *)
- * \param a (double)
- * \param rows (int)
- * \return (void)
- *
- * */
- void G_math_daxpy(double *x, double *y, double a, int rows)
- {
- #if defined(HAVE_ATLAS)
- cblas_daxpy(rows, a, x, 1, y, 1);
- #else
- G_math_d_ax_by(x, y, y, a, 1.0, rows);
- #endif
- return;
- }
- /****************************************************************** */
- /********* F L O A T / S I N G L E P E P R E C I S I O N ******** */
- /****************************************************************** */
- /*!
- * \brief Compute the dot product of vector x and y
- * using the ATLAS routine cblas_sdot
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_x_dot_y, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param y (float *)
- * \param rows (int)
- * \return (float)
- *
- * */
- float G_math_sdot(float *x, float *y, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_sdot(rows, x, 1, y, 1);
- #else
- float val;
- G_math_f_x_dot_y(x, y, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Compute the euclidean norm of vector x
- * using the ATLAS routine cblas_dnrm2
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_euclid_norm, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param rows (int)
- * \return (float)
- *
- * */
- float G_math_snrm2(float *x, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_snrm2(rows, x, 1);
- #else
- float val;
- G_math_f_euclid_norm(x, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Compute the absolute sum norm of vector x
- * using the ATLAS routine cblas_dasum
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_asum_norm, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param rows (int)
- * \return (float)
- *
- * */
- float G_math_sasum(float *x, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_sasum(rows, x, 1);
- #else
- float val;
- G_math_f_asum_norm(x, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Compute the maximum norm of vector x
- * using the ATLAS routine cblas_idamax
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_max_norm, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param rows (int)
- * \return (float)
- *
- * */
- float G_math_isamax(float *x, int rows)
- {
- #if defined(HAVE_ATLAS)
- return cblas_isamax(rows, x, 1);
- #else
- float val;
- G_math_f_max_norm(x, &val, rows);
- return val;
- #endif
- }
- /*!
- * \brief Scale vector x with scalar a
- * using the ATLAS routine cblas_dscal
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_ax_by, the OpenMP multi threaded
- * grass implementatiom
- *
- * \param x (float *)
- * \param a (float)
- * \param rows (int)
- * \return (float)
- *
- * */
- void G_math_sscal(float *x, float a, int rows)
- {
- #if defined(HAVE_ATLAS)
- cblas_sscal(rows, a, x, 1);
- #else
- G_math_f_ax_by(x, x, x, a, 0.0, rows);
- #endif
- return;
- }
- /*!
- * \brief Copy vector x to vector y
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_copy, the
- * grass implementatiom
- *
- * \param x (float *)
- * \param y (float *)
- * \param rows (int)
- * \return (void)
- *
- * */
- void G_math_scopy(float *x, float *y, int rows)
- {
- #if defined(HAVE_ATLAS)
- cblas_scopy(rows, x, 1, y, 1);
- #else
- G_math_f_copy(x, y, rows);
- #endif
- return;
- }
- /*!
- * \brief Scale vector x with scalar a and add it to y
- *
- * \f[ {\bf z} = a{\bf x} + {\bf y} \f]
- *
- * If grass was not compiled with ATLAS support
- * it will call #G_math_f_ax_by, the
- * grass implementatiom
- *
- * \param x (float *)
- * \param y (float *)
- * \param a (float)
- * \param rows (int)
- * \return (void)
- *
- * */
- void G_math_saxpy(float *x, float *y, float a, int rows)
- {
- #if defined(HAVE_ATLAS)
- cblas_saxpy(rows, a, x, 1, y, 1);
- #else
- G_math_f_ax_by(x, y, y, a, 1.0, rows);
- #endif
- return;
- }
|