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 //   template<typename eT>
00061 //   inline
00062 //   void
00063 //   cblas_dot(const int N, const eT *X, const int incX, const eT *Y, const int incY, eT& out)
00064 //     {
00065 //     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00066 //     
00067 //     if(is_float<eT>::value == true)
00068 //       {
00069 //       typedef float T;
00070 //       out = eT( cblas_sdot(N, (const T*)X, incX, (const T*)Y, incY) );
00071 //       }
00072 //     else
00073 //     if(is_double<eT>::value == true)
00074 //       {
00075 //       typedef double T;
00076 //       out = eT( cblas_ddot(N, (const T*)X, incX, (const T*)Y, incY) );
00077 //       }
00078 //     else
00079 //     if(is_supported_complex_float<eT>::value == true)
00080 //       {
00081 //       typedef std::complex<float> T;
00082 //       cblas_cdotu_sub(N, (const T*)X, incX, (const T*)Y, incY, (T*)&out);
00083 //       }
00084 //     else
00085 //     if(is_supported_complex_double<eT>::value == true)
00086 //       {
00087 //       typedef std::complex<double> T;
00088 //       cblas_zdotu_sub(N, (const T*)X, incX, (const T*)Y, incY, (T*)&out);
00089 //       }
00090 //     }
00091   
00092   
00093   
00094   template<typename eT>
00095   inline
00096   void
00097   cblas_gemv
00098     (
00099     const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
00100     const int M, const int N,
00101     const eT alpha,
00102     const eT *A, const int lda,
00103     const eT *X, const int incX,
00104     const eT beta,
00105     eT *Y, const int incY
00106     )
00107     {
00108     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00109     
00110     if(is_float<eT>::value == true)
00111       {
00112       typedef float T;
00113       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);
00114       }
00115     else
00116     if(is_double<eT>::value == true)
00117       {
00118       typedef double T;
00119       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);
00120       }
00121     else
00122     if(is_supported_complex_float<eT>::value == true)
00123       {
00124       typedef std::complex<float> T;
00125       cblas_cgemv(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY);
00126       }
00127     else
00128     if(is_supported_complex_double<eT>::value == true)
00129       {
00130       typedef std::complex<double> T;
00131       cblas_zgemv(Order, TransA, M, N, (const T*)&alpha, (const T*)A, lda, (const T*)X, incX, (const T*)&beta, (T*)Y, incY);
00132       }
00133     }
00134   
00135   
00136   
00137   template<typename eT>
00138   inline
00139   void
00140   cblas_gemm
00141     (
00142     const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
00143     const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
00144     const int K, const eT alpha, const eT *A,
00145     const int lda, const eT *B, const int ldb,
00146     const eT beta, eT *C, const int ldc
00147     )
00148     {
00149     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00150     
00151     if(is_float<eT>::value == true)
00152       {
00153       typedef float T;
00154       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);
00155       }
00156     else
00157     if(is_double<eT>::value == true)
00158       {
00159       typedef double T;
00160       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);
00161       }
00162     else
00163     if(is_supported_complex_float<eT>::value == true)
00164       {
00165       typedef std::complex<float> T;
00166       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);
00167       }
00168     else
00169     if(is_supported_complex_double<eT>::value == true)
00170       {
00171       typedef std::complex<double> T;
00172       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);
00173       }
00174     }
00175   
00176   
00177   
00178   template<typename eT>
00179   inline
00180   int
00181   clapack_getrf
00182     (
00183     const enum CBLAS_ORDER Order, const int M, const int N,
00184     eT *A, const int lda, int *ipiv
00185     )
00186     {
00187     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00188     
00189     if(is_float<eT>::value == true)
00190       {
00191       typedef float T;
00192       return clapack_sgetrf(Order, M, N, (T*)A, lda, ipiv);
00193       }
00194     else
00195     if(is_double<eT>::value == true)
00196       {
00197       typedef double T;
00198       return clapack_dgetrf(Order, M, N, (T*)A, lda, ipiv);
00199       }
00200     else
00201     if(is_supported_complex_float<eT>::value == true)
00202       {
00203       typedef std::complex<float> T;
00204       return clapack_cgetrf(Order, M, N, (T*)A, lda, ipiv);
00205       }
00206     else
00207     if(is_supported_complex_double<eT>::value == true)
00208       {
00209       typedef std::complex<double> T;
00210       return clapack_zgetrf(Order, M, N, (T*)A, lda, ipiv);
00211       }
00212     else
00213       {
00214       return -1;
00215       }
00216     }
00217   
00218   
00219   
00220   template<typename eT>
00221   inline
00222   int
00223   clapack_getri
00224     (
00225     const enum CBLAS_ORDER Order, const int N, eT *A,
00226     const int lda, const int *ipiv
00227     )
00228     {
00229     arma_type_check<is_supported_blas_type<eT>::value == false>::apply();
00230     
00231     if(is_float<eT>::value == true)
00232       {
00233       typedef float T;
00234       return clapack_sgetri(Order, N, (T*)A, lda, ipiv);
00235       }
00236     else
00237     if(is_double<eT>::value == true)
00238       {
00239       typedef double T;
00240       return clapack_dgetri(Order, N, (T*)A, lda, ipiv);
00241       }
00242     else
00243     if(is_supported_complex_float<eT>::value == true)
00244       {
00245       typedef std::complex<float> T;
00246       return clapack_cgetri(Order, N, (T*)A, lda, ipiv);
00247       }
00248     else
00249     if(is_supported_complex_double<eT>::value == true)
00250       {
00251       typedef std::complex<double> T;
00252       return clapack_zgetri(Order, N, (T*)A, lda, ipiv);
00253       }
00254     else
00255       {
00256       return -1;
00257       }
00258     }
00259   
00260   
00261   
00262   }
00263 
00264 #endif