atlas_proto.hpp

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