cblas1_overloads.hpp

Go to the documentation of this file.
00001 /*
00002  * 
00003  * Copyright (c) Kresimir Fresl 2002 
00004  *
00005  * Distributed under the Boost Software License, Version 1.0.
00006  * (See accompanying file LICENSE_1_0.txt or copy at
00007  * http://www.boost.org/LICENSE_1_0.txt)
00008  *
00009  * Author acknowledges the support of the Faculty of Civil Engineering, 
00010  * University of Zagreb, Croatia.
00011  *
00012  */
00013 
00014 #ifndef BOOST_NUMERIC_BINDINGS_CBLAS1_OVERLOADS_HPP
00015 #define BOOST_NUMERIC_BINDINGS_CBLAS1_OVERLOADS_HPP
00016 
00017 #include <complex> 
00018 #include <boost/numeric/bindings/atlas/cblas_inc.hpp>
00019 #include <boost/numeric/bindings/traits/type.hpp>
00020 
00021 
00022 namespace boost { namespace numeric { namespace bindings { 
00023 
00024   namespace atlas { namespace detail {
00025 
00026     // dot <- x^T * y
00027     // .. real types:    calls cblas_xdot
00028     // .. complex types: calls cblas_xdotu
00029     inline 
00030     float dot (int const N, float const* X, int const incX,
00031                float const* Y, int const incY) {
00032       return cblas_sdot (N, X, incX, Y, incY); 
00033     }
00034     inline 
00035     double dot (int const N, double const* X, int const incX,
00036                 double const* Y, int const incY) {
00037       return cblas_ddot (N, X, incX, Y, incY); 
00038     }
00039     inline 
00040     traits::complex_f 
00041     dot (int const N, traits::complex_f const* X, int const incX,
00042          traits::complex_f const* Y, int const incY) {
00043       traits::complex_f val; 
00044       cblas_cdotu_sub (N, 
00045                        static_cast<void const*> (X), incX, 
00046                        static_cast<void const*> (Y), incY, 
00047                        static_cast<void*> (&val)); 
00048       return val; 
00049     }
00050     inline 
00051     traits::complex_d 
00052     dot (int const N, traits::complex_d const* X, int const incX,
00053          traits::complex_d const* Y, int const incY) {
00054       traits::complex_d val; 
00055       cblas_zdotu_sub (N, 
00056                        static_cast<void const*> (X), incX, 
00057                        static_cast<void const*> (Y), incY, 
00058                        static_cast<void*> (&val)); 
00059       return val; 
00060     }
00061 
00062     // dotu <- x^T * y  
00063     // .. complex types only
00064     inline 
00065     void dotu (int const N, traits::complex_f const* X, int const incX,
00066                traits::complex_f const* Y, int const incY,
00067                traits::complex_f* val) 
00068     {
00069       cblas_cdotu_sub (N, 
00070                        static_cast<void const*> (X), incX, 
00071                        static_cast<void const*> (Y), incY, 
00072                        static_cast<void*> (val)); 
00073     }
00074     inline 
00075     void dotu (int const N, traits::complex_d const* X, int const incX,
00076                traits::complex_d const* Y, int const incY,
00077                traits::complex_d* val) 
00078     {
00079       cblas_zdotu_sub (N, 
00080                        static_cast<void const*> (X), incX, 
00081                        static_cast<void const*> (Y), incY, 
00082                        static_cast<void*> (val)); 
00083     }
00084 
00085     // dotc <- x^H * y  
00086     // .. complex types only 
00087     inline 
00088     void dotc (int const N, traits::complex_f const* X, int const incX,
00089                traits::complex_f const* Y, int const incY,
00090                traits::complex_f* val) 
00091     {
00092       cblas_cdotc_sub (N, 
00093                        static_cast<void const*> (X), incX, 
00094                        static_cast<void const*> (Y), incY, 
00095                        static_cast<void*> (val)); 
00096     }
00097     inline 
00098     void dotc (int const N, traits::complex_d const* X, int const incX,
00099                traits::complex_d const* Y, int const incY,
00100                traits::complex_d* val) 
00101     {
00102       cblas_zdotc_sub (N, 
00103                        static_cast<void const*> (X), incX, 
00104                        static_cast<void const*> (Y), incY, 
00105                        static_cast<void*> (val)); 
00106     }
00107 
00108     // nrm2 <- ||x||_2
00109     inline 
00110     float nrm2 (int const N, float const* X, int const incX) {
00111       return cblas_snrm2 (N, X, incX);
00112     }
00113     inline 
00114     double nrm2 (int const N, double const* X, int const incX) {
00115       return cblas_dnrm2 (N, X, incX);
00116     }
00117     inline 
00118     float nrm2 (int const N, traits::complex_f const* X, int const incX) {
00119       return cblas_scnrm2 (N, static_cast<void const*> (X), incX);
00120     }
00121     inline 
00122     double nrm2 (int const N, traits::complex_d const* X, int const incX) {
00123       return cblas_dznrm2 (N, static_cast<void const*> (X), incX);
00124     }
00125 
00126     // asum <- ||re (x)|| + ||im (x)||
00127     inline 
00128     float asum (int const N, float const* X, int const incX) {
00129       return cblas_sasum (N, X, incX);
00130     }
00131     inline 
00132     double asum (int const N, double const* X, int const incX) {
00133       return cblas_dasum (N, X, incX);
00134     }
00135     inline 
00136     float asum (int const N, traits::complex_f const* X, int const incX) {
00137       return cblas_scasum (N, static_cast<void const*> (X), incX);
00138     }
00139     inline 
00140     double asum (int const N, traits::complex_d const* X, int const incX) {
00141       return cblas_dzasum (N, static_cast<void const*> (X), incX);
00142     }
00143 
00144     // iamax <- 1st i: max (|re (x_i)| + |im (x_i)|)
00145     inline 
00146     CBLAS_INDEX iamax (int const N, float const* X, int const incX) {
00147       return cblas_isamax (N, X, incX);
00148     }
00149     inline 
00150     CBLAS_INDEX iamax (int const N, double const* X, int const incX) {
00151       return cblas_idamax (N, X, incX);
00152     }
00153     inline 
00154     CBLAS_INDEX 
00155     iamax (int const N, traits::complex_f const* X, int const incX) {
00156       return cblas_icamax (N, static_cast<void const*> (X), incX);
00157     }
00158     inline 
00159     CBLAS_INDEX 
00160     iamax (int const N, traits::complex_d const* X, int const incX) {
00161       return cblas_izamax (N, static_cast<void const*> (X), incX);
00162     }
00163 
00164     // x <-> y
00165     inline 
00166     void swap (int const N, float* X, int const incX,
00167                float* Y, int const incY) {
00168       cblas_sswap (N, X, incX, Y, incY); 
00169     }
00170     inline 
00171     void swap (int const N, double* X, int const incX,
00172                double* Y, int const incY) {
00173       cblas_dswap (N, X, incX, Y, incY); 
00174     }
00175     inline 
00176     void swap (int const N, traits::complex_f* X, int const incX,
00177                traits::complex_f* Y, int const incY) {
00178       cblas_cswap (N, 
00179                    static_cast<void*> (X), incX, 
00180                    static_cast<void*> (Y), incY); 
00181     }
00182     inline 
00183     void swap (int const N, traits::complex_d* X, int const incX,
00184                traits::complex_d* Y, int const incY) {
00185       cblas_zswap (N, 
00186                    static_cast<void*> (X), incX, 
00187                    static_cast<void*> (Y), incY); 
00188     }
00189 
00190     // y <- x
00191     inline
00192     void copy (int const N, float const* X, int const incX,
00193                float* Y, int const incY) {
00194       cblas_scopy (N, X, incX, Y, incY); 
00195     }
00196     inline
00197     void copy (int const N, double const* X, int const incX,
00198                double* Y, int const incY) {
00199       cblas_dcopy (N, X, incX, Y, incY); 
00200     }
00201     inline 
00202     void copy (int const N, traits::complex_f const* X, int const incX,
00203                traits::complex_f* Y, int const incY) {
00204       cblas_ccopy (N, 
00205                    static_cast<void const*> (X), incX, 
00206                    static_cast<void*> (Y), incY); 
00207     }
00208     inline 
00209     void copy (int const N, traits::complex_d const* X, int const incX,
00210                traits::complex_d* Y, int const incY) {
00211       cblas_zcopy (N, 
00212                    static_cast<void const*> (X), incX, 
00213                    static_cast<void*> (Y), incY); 
00214     }
00215 
00216     // y <- alpha * x + y
00217     inline
00218     void axpy (int const N, 
00219                float const alpha, float const* X, int const incX, 
00220                float* Y, int const incY) 
00221     {
00222       cblas_saxpy (N, alpha, X, incX, Y, incY);
00223     }
00224     inline
00225     void axpy (int const N, 
00226                double const alpha, double const* X, int const incX, 
00227                double* Y, int const incY) 
00228     {
00229       cblas_daxpy (N, alpha, X, incX, Y, incY);
00230     }
00231     inline
00232     void axpy (int const N, 
00233                traits::complex_f const& alpha, 
00234                traits::complex_f const* X, int const incX, 
00235                traits::complex_f* Y, int const incY) 
00236     {
00237       cblas_caxpy (N, 
00238                    static_cast<void const*> (&alpha), 
00239                    static_cast<void const*> (X), incX, 
00240                    static_cast<void*> (Y), incY);
00241     }
00242     inline
00243     void axpy (int const N, 
00244                traits::complex_d const& alpha, 
00245                traits::complex_d const* X, int const incX, 
00246                traits::complex_d* Y, int const incY) 
00247     {
00248       cblas_zaxpy (N, 
00249                    static_cast<void const*> (&alpha), 
00250                    static_cast<void const*> (X), incX, 
00251                    static_cast<void*> (Y), incY);
00252     }
00253 
00254     // y <- alpha * x + beta * y
00255     inline
00256     void axpby (int const N, 
00257                 float const alpha, float const* X, int const incX, 
00258                 float const beta, float* Y, int const incY) 
00259     {
00260       catlas_saxpby (N, alpha, X, incX, beta, Y, incY);
00261     }
00262     inline
00263     void axpby (int const N, 
00264                 double const alpha, double const* X, int const incX, 
00265                 double const beta, double* Y, int const incY) 
00266     {
00267       catlas_daxpby (N, alpha, X, incX, beta, Y, incY);
00268     }
00269     inline
00270     void axpby (int const N, 
00271                 traits::complex_f const& alpha, 
00272                 traits::complex_f const* X, int const incX, 
00273                 traits::complex_f const& beta, 
00274                 traits::complex_f* Y, int const incY) 
00275     {
00276       catlas_caxpby (N, 
00277                      static_cast<void const*> (&alpha), 
00278                      static_cast<void const*> (X), incX, 
00279                      static_cast<void const*> (&beta), 
00280                      static_cast<void*> (Y), incY);
00281     }
00282     inline
00283     void axpby (int const N, 
00284                 traits::complex_d const& alpha, 
00285                 traits::complex_d const* X, int const incX, 
00286                 traits::complex_d const& beta, 
00287                 traits::complex_d* Y, int const incY) 
00288     {
00289       catlas_zaxpby (N, 
00290                      static_cast<void const*> (&alpha), 
00291                      static_cast<void const*> (X), incX, 
00292                      static_cast<void const*> (&beta), 
00293                      static_cast<void*> (Y), incY);
00294     }
00295 
00296     // x_i <- alpha for all i
00297     inline
00298     void set (int const N, float const alpha, float* X, int const incX) {
00299       catlas_sset (N, alpha, X, incX); 
00300     }
00301     inline
00302     void set (int const N, double const alpha, double* X, int const incX) {
00303       catlas_dset (N, alpha, X, incX); 
00304     }
00305     inline
00306     void set (int const N, traits::complex_f const& alpha, 
00307               traits::complex_f* X, int const incX) {
00308       catlas_cset (N, static_cast<void const*> (&alpha), 
00309                    static_cast<void*> (X), incX);
00310     }
00311     inline
00312     void set (int const N, traits::complex_d const& alpha, 
00313               traits::complex_d* X, int const incX) {
00314       catlas_zset (N, static_cast<void const*> (&alpha), 
00315                    static_cast<void*> (X), incX);
00316     }
00317 
00318     // x <- alpha * x
00319     inline
00320     void scal (int const N, float const alpha, float* X, int const incX) {
00321       cblas_sscal (N, alpha, X, incX); 
00322     }
00323     inline
00324     void scal (int const N, double const alpha, double* X, int const incX) {
00325       cblas_dscal (N, alpha, X, incX); 
00326     }
00327     inline
00328     void scal (int const N, traits::complex_f const& alpha, 
00329                traits::complex_f* X, int const incX) {
00330       cblas_cscal (N, static_cast<void const*> (&alpha), 
00331                    static_cast<void*> (X), incX);
00332     }
00333     inline
00334     void scal (int const N, float const alpha, 
00335                traits::complex_f* X, int const incX) {
00336       cblas_csscal (N, alpha, static_cast<void*> (X), incX);
00337     }
00338     inline
00339     void scal (int const N, traits::complex_d const& alpha, 
00340                traits::complex_d* X, int const incX) {
00341       cblas_zscal (N, static_cast<void const*> (&alpha), 
00342                    static_cast<void*> (X), incX);
00343     }
00344     inline
00345     void scal (int const N, double const alpha, 
00346                traits::complex_d* X, int const incX) {
00347       cblas_zdscal (N, alpha, static_cast<void*> (X), incX);
00348     }
00349 
00350   }} // namepaces detail & atlas
00351 
00352 }}} 
00353 
00354 
00355 #endif // BOOST_NUMERIC_BINDINGS_CBLAS1_OVERLOADS_HPP

Generated on Wed Nov 23 19:00:00 2011 for FreeCAD by  doxygen 1.6.1