atlas_proto.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2010 NICTA and the authors listed below
00002 // http://nicta.com.au
00003 // 
00004 // Authors:
00005 // - Conrad Sanderson (conradsand at ieee dot org)
00006 // 
00007 // This file is part of the Armadillo C++ library.
00008 // It is provided without any warranty of fitness
00009 // for any purpose. You can redistribute this file
00010 // and/or modify it under the terms of the GNU
00011 // Lesser General Public License (LGPL) as published
00012 // by the Free Software Foundation, either version 3
00013 // of the License or (at your option) any later version.
00014 // (see http://www.opensource.org/licenses for more info)
00015 
00016 
00017 #ifdef ARMA_USE_ATLAS
00018 
00019 //! \namespace atlas namespace for ATLAS functions (imported from the global namespace)
00020 namespace atlas
00021   {
00022   
00023   using ::CblasColMajor;
00024   using ::CblasNoTrans;
00025   using ::CblasTrans;
00026   
00027   using ::cblas_sdot;
00028   using ::cblas_ddot;
00029   using ::cblas_cdotu_sub;
00030   using ::cblas_zdotu_sub;
00031   
00032   using ::cblas_sgemv;
00033   using ::cblas_dgemv;
00034   using ::cblas_cgemv;
00035   using ::cblas_zgemv;
00036   
00037   using ::cblas_sgemm;
00038   using ::cblas_dgemm;
00039   using ::cblas_cgemm;
00040   using ::cblas_zgemm;
00041   
00042   using ::clapack_sgetrf;
00043   using ::clapack_dgetrf;
00044   using ::clapack_cgetrf;
00045   using ::clapack_zgetrf;
00046   
00047   using ::clapack_sgetri;
00048   using ::clapack_dgetri;
00049   using ::clapack_cgetri;
00050   using ::clapack_zgetri;
00051   
00052   
00053   template<typename eT>
00054   inline static const eT& tmp_real(const eT& X)              { return X; }
00055   
00056   template<typename T>
00057   inline static const T&  tmp_real(const std::complex<T>& X) { return X.real(); }
00058   
00059   
00060   
00061   template<typename eT>
00062   arma_inline
00063   eT
00064   cblas_dot(const int N, const eT* X, const eT* Y)
00065     {
00066     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00067     
00068     if(is_float<eT>::value == true)
00069       {
00070       typedef float T;
00071       return eT( cblas_sdot(N, (const T*)X, 1, (const T*)Y, 1) );
00072       }
00073     else
00074     if(is_double<eT>::value == true)
00075       {
00076       typedef double T;
00077       return eT( cblas_ddot(N, (const T*)X, 1, (const T*)Y, 1) );
00078       }
00079     else
00080       {
00081       return eT(0);
00082       }
00083     }
00084   
00085   
00086   
00087   template<typename eT>
00088   arma_inline
00089   eT
00090   cx_cblas_dot(const int N, const eT* X, const eT* Y)
00091     {
00092     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00093     
00094     if(is_supported_complex_float<eT>::value == true)
00095       {
00096       typedef typename std::complex<float> T;
00097       
00098       T out;    
00099       cblas_cdotu_sub(N, (const T*)X, 1, (const T*)Y, 1, &out);
00100       
00101       return eT(out);
00102       }
00103     else
00104     if(is_supported_complex_double<eT>::value == true)
00105       {
00106       typedef typename std::complex<double> T;
00107       
00108       T out;
00109       cblas_zdotu_sub(N, (const T*)X, 1, (const T*)Y, 1, &out);
00110       
00111       return eT(out);
00112       }
00113     else
00114       {
00115       return eT(0);
00116       }
00117     }
00118   
00119   
00120   
00121   template<typename eT>
00122   inline
00123   void
00124   cblas_gemv
00125     (
00126     const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
00127     const int M, const int N,
00128     const eT alpha,
00129     const eT *A, const int lda,
00130     const eT *X, const int incX,
00131     const eT beta,
00132     eT *Y, const int incY
00133     )
00134     {
00135     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00136     
00137     if(is_float<eT>::value == true)
00138       {
00139       typedef float T;
00140       cblas_sgemv(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY);
00141       }
00142     else
00143     if(is_double<eT>::value == true)
00144       {
00145       typedef double T;
00146       cblas_dgemv(Order, TransA, M, N, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)X, incX, (const T)tmp_real(beta), (T*)Y, incY);
00147       }
00148     else
00149     if(is_supported_complex_float<eT>::value == true)
00150       {
00151       typedef std::complex<float> T;
00152       cblas_cgemv(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY);
00153       }
00154     else
00155     if(is_supported_complex_double<eT>::value == true)
00156       {
00157       typedef std::complex<double> T;
00158       cblas_zgemv(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY);
00159       }
00160     }
00161   
00162   
00163   
00164   template<typename eT>
00165   inline
00166   void
00167   cblas_gemm
00168     (
00169     const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
00170     const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
00171     const int K, const eT alpha, const eT *A,
00172     const int lda, const eT *B, const int ldb,
00173     const eT beta, eT *C, const int ldc
00174     )
00175     {
00176     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00177     
00178     if(is_float<eT>::value == true)
00179       {
00180       typedef float T;
00181       cblas_sgemm(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc);
00182       }
00183     else
00184     if(is_double<eT>::value == true)
00185       {
00186       typedef double T;
00187       cblas_dgemm(Order, TransA, TransB, M, N, K, (const T)tmp_real(alpha), (const T*)A, lda, (const T*)B, ldb, (const T)tmp_real(beta), (T*)C, ldc);
00188       }
00189     else
00190     if(is_supported_complex_float<eT>::value == true)
00191       {
00192       typedef std::complex<float> T;
00193       cblas_cgemm(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc);
00194       }
00195     else
00196     if(is_supported_complex_double<eT>::value == true)
00197       {
00198       typedef std::complex<double> T;
00199       cblas_zgemm(Order, TransA, TransB, M, N, K, (const T*)&alpha, (const T*)A, lda, (const T*)B, ldb, (const T*)&beta, (T*)C, ldc);
00200       }
00201     }
00202   
00203   
00204   
00205   template<typename eT>
00206   inline
00207   int
00208   clapack_getrf
00209     (
00210     const enum CBLAS_ORDER Order, const int M, const int N,
00211     eT *A, const int lda, int *ipiv
00212     )
00213     {
00214     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00215     
00216     if(is_float<eT>::value == true)
00217       {
00218       typedef float T;
00219       return clapack_sgetrf(Order, M, N, (T*)A, lda, ipiv);
00220       }
00221     else
00222     if(is_double<eT>::value == true)
00223       {
00224       typedef double T;
00225       return clapack_dgetrf(Order, M, N, (T*)A, lda, ipiv);
00226       }
00227     else
00228     if(is_supported_complex_float<eT>::value == true)
00229       {
00230       typedef std::complex<float> T;
00231       return clapack_cgetrf(Order, M, N, (T*)A, lda, ipiv);
00232       }
00233     else
00234     if(is_supported_complex_double<eT>::value == true)
00235       {
00236       typedef std::complex<double> T;
00237       return clapack_zgetrf(Order, M, N, (T*)A, lda, ipiv);
00238       }
00239     else
00240       {
00241       return -1;
00242       }
00243     }
00244   
00245   
00246   
00247   template<typename eT>
00248   inline
00249   int
00250   clapack_getri
00251     (
00252     const enum CBLAS_ORDER Order, const int N, eT *A,
00253     const int lda, const int *ipiv
00254     )
00255     {
00256     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00257     
00258     if(is_float<eT>::value == true)
00259       {
00260       typedef float T;
00261       return clapack_sgetri(Order, N, (T*)A, lda, ipiv);
00262       }
00263     else
00264     if(is_double<eT>::value == true)
00265       {
00266       typedef double T;
00267       return clapack_dgetri(Order, N, (T*)A, lda, ipiv);
00268       }
00269     else
00270     if(is_supported_complex_float<eT>::value == true)
00271       {
00272       typedef std::complex<float> T;
00273       return clapack_cgetri(Order, N, (T*)A, lda, ipiv);
00274       }
00275     else
00276     if(is_supported_complex_double<eT>::value == true)
00277       {
00278       typedef std::complex<double> T;
00279       return clapack_zgetri(Order, N, (T*)A, lda, ipiv);
00280       }
00281     else
00282       {
00283       return -1;
00284       }
00285     }
00286   
00287   
00288   
00289   }
00290 
00291 #endif