TemplatizedLapack.h

Go to the documentation of this file.
00001 #ifndef SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_
00002 #define SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                      SimTK Core: SimTKcommon                               *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK Core biosimulation toolkit originating from      *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
00011  *                                                                            *
00012  * Portions copyright (c) 2006-7 Stanford University and the Authors.         *
00013  * Authors: Michael Sherman                                                   *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
00017  * copy of this software and associated documentation files (the "Software"), *
00018  * to deal in the Software without restriction, including without limitation  *
00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
00020  * and/or sell copies of the Software, and to permit persons to whom the      *
00021  * Software is furnished to do so, subject to the following conditions:       *
00022  *                                                                            *
00023  * The above copyright notice and this permission notice shall be included in *
00024  * all copies or substantial portions of the Software.                        *
00025  *                                                                            *
00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
00033  * -------------------------------------------------------------------------- */
00034 
00041 #include "SimTKcommon/internal/common.h"
00042 #include "SimTKlapack.h"
00043 
00044 namespace SimTK {
00045 
00046 class Lapack {
00047 public:
00048     // MEANINGLESS IF NOT SPECIALIZED
00049 
00050         template <class P> static void
00051     gemm
00052    (char transa, char transb,
00053     int m, int n, int k,
00054     const P& alpha, const P a[], int lda,
00055     const P b[], int ldb,
00056     const P& beta, P c[], int ldc) {assert(false);}
00057 
00058         template <class P> static void
00059     getri
00060    (int          n,
00061     P            a[],
00062     int          lda,
00063     const int    ipiv[], 
00064     P            work[], 
00065     int          lwork, 
00066     int         &info ) {assert(false);}
00067 
00068         template <class P> static void
00069     getrf
00070    (int          m,
00071     int          n, 
00072     P            a[],
00073     int          lda, 
00074     int          ipiv[], 
00075     int         &info ) {assert(false);}
00076 
00077 };
00078 
00079 
00080 template <> inline void Lapack::gemm<float>
00081    (char transa, char transb,
00082     int m, int n, int k,
00083     const float& alpha, const float a[], int lda,
00084     const float b[], int ldb,
00085     const float& beta, float c[], int ldc)
00086 {
00087     sgemm_(
00088         transa, transb,
00089         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00090     );
00091 }
00092 template <> inline void Lapack::gemm<double>
00093    (char transa, char transb,
00094     int m, int n, int k,
00095     const double& alpha, const double a[], int lda,
00096     const double b[], int ldb,
00097     const double& beta, double c[], int ldc)
00098 {
00099     dgemm_(
00100         transa, transb,
00101         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00102     );
00103 }
00104 template <> inline void Lapack::gemm< std::complex<float> >
00105    (char transa, char transb,
00106     int m, int n, int k,
00107     const std::complex<float>& alpha, const std::complex<float> a[], int lda,
00108     const std::complex<float> b[], int ldb,
00109     const std::complex<float>& beta, std::complex<float> c[], int ldc)
00110 {
00111     cgemm_(
00112         transa, transb,
00113         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00114     );
00115 }
00116 template <> inline void Lapack::gemm< std::complex<double> >
00117    (char transa, char transb,
00118     int m, int n, int k,
00119     const std::complex<double>& alpha, const std::complex<double> a[], int lda,
00120     const std::complex<double> b[], int ldb,
00121     const std::complex<double>& beta, std::complex<double> c[], int ldc)
00122 {
00123     zgemm_(
00124         transa, transb,
00125         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00126     );
00127 }
00128 
00129 template <> inline void Lapack::getri<float>
00130    (int          n,
00131     float        a[],
00132     int          lda,
00133     const int    ipiv[], 
00134     float        work[], 
00135     int          lwork, 
00136     int         &info )
00137 {
00138     sgetri_(n,a,lda,ipiv,work,lwork,info);
00139 }
00140 
00141 template <> inline void Lapack::getri<double>
00142    (int          n,
00143     double       a[],
00144     int          lda,
00145     const int    ipiv[], 
00146     double       work[], 
00147     int          lwork, 
00148     int         &info )
00149 {
00150     dgetri_(n,a,lda,ipiv,work,lwork,info);
00151 }
00152 
00153 template <> inline void Lapack::getrf<float>
00154    (int          m,
00155     int          n, 
00156     float        a[],
00157     int          lda, 
00158     int          ipiv[], 
00159     int         &info )
00160 {
00161     sgetrf_(m,n,a,lda,ipiv,info);
00162 }
00163 
00164 template <> inline void Lapack::getrf<double>
00165    (int          m,
00166     int          n, 
00167     double       a[],
00168     int          lda, 
00169     int          ipiv[], 
00170     int         &info )
00171 {
00172     dgetrf_(m,n,a,lda,ipiv,info);
00173 }
00174 /*
00175 template <> inline void Lapack::gemm<float>
00176    (char transa, char transb,
00177     int m, int n, int k,
00178     const float& alpha, const float a[], int lda,
00179     const float b[], int ldb,
00180     const float& beta, float c[], int ldc)
00181 {
00182     SimTK_LAPACK(sgemm,SGEMM)(
00183         transa SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00184         transb SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00185         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00186         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00187         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00188     );
00189 }
00190 template <> inline void Lapack::gemm<double>
00191    (char transa, char transb,
00192     int m, int n, int k,
00193     const double& alpha, const double a[], int lda,
00194     const double b[], int ldb,
00195     const double& beta, double c[], int ldc)
00196 {
00197     SimTK_LAPACK(dgemm,DGEMM)(
00198         transa SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00199         transb SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00200         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00201         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00202         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00203     );
00204 }
00205 template <> inline void Lapack::gemm< std::complex<float> >
00206    (char transa, char transb,
00207     int m, int n, int k,
00208     const std::complex<float>& alpha, const std::complex<float> a[], int lda,
00209     const std::complex<float> b[], int ldb,
00210     const std::complex<float>& beta, std::complex<float> c[], int ldc)
00211 {
00212     SimTK_LAPACK(cgemm,CGEMM)(
00213         transa SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00214         transb SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00215         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00216         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00217         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00218     );
00219 }
00220 template <> inline void Lapack::gemm< std::complex<double> >
00221    (char transa, char transb,
00222     int m, int n, int k,
00223     const std::complex<double>& alpha, const std::complex<double> a[], int lda,
00224     const std::complex<double> b[], int ldb,
00225     const std::complex<double>& beta, std::complex<double> c[], int ldc)
00226 {
00227     SimTK_LAPACK(zgemm,ZGEMM)(
00228         transa SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00229         transb SimTK_LAPACK_STRLEN_FOLLOWS_CALL(1),
00230         m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
00231         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00232         SimTK_LAPACK_STRLEN_ATEND_CALL(1)
00233     );
00234 }
00235 
00236 template <> inline void Lapack::getri<float>
00237    (int          n,
00238     float        a[],
00239     int          lda,
00240     const int    ipiv[], 
00241     float        work[], 
00242     int          lwork, 
00243     int         &info )
00244 {
00245     SimTK_LAPACK(sgetri,SGETRI)(n,a,lda,ipiv,work,lwork,info);
00246 }
00247 
00248 template <> inline void Lapack::getri<double>
00249    (int          n,
00250     double       a[],
00251     int          lda,
00252     const int    ipiv[], 
00253     double       work[], 
00254     int          lwork, 
00255     int         &info )
00256 {
00257     SimTK_LAPACK(dgetri,DGETRI)(n,a,lda,ipiv,work,lwork,info);
00258 }
00259 
00260 template <> inline void Lapack::getrf<float>
00261    (int          m,
00262     int          n, 
00263     float        a[],
00264     int          lda, 
00265     int          ipiv[], 
00266     int         &info )
00267 {
00268     SimTK_LAPACK(sgetrf,SGETRF)(m,n,a,lda,ipiv,info);
00269 }
00270 
00271 template <> inline void Lapack::getrf<double>
00272    (int          m,
00273     int          n, 
00274     double       a[],
00275     int          lda, 
00276     int          ipiv[], 
00277     int         &info )
00278 {
00279     SimTK_LAPACK(dgetrf,DGETRF)(m,n,a,lda,ipiv,info);
00280 }
00281 
00282 void SimTK_STDCALL
00283 SimTK_LAPACK(dgeev,DGEEV)
00284    (const char  &jobvl SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00285     const char  &jobvr SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00286     const int   &n,
00287     double       a[],
00288     const int   &lda, 
00289     double       wr[],
00290     double       wi[],
00291     double       vl[],
00292     const int   &ldvl,
00293     double       vr[],
00294     const int   &ldvr,
00295     double       work[],
00296     const int   &lwork,
00297     int         &info  
00298     SimTK_LAPACK_STRLEN_ATEND_DECL
00299     SimTK_LAPACK_STRLEN_ATEND_DECL);
00300 
00301 void SimTK_STDCALL
00302 SimTK_LAPACK(dsyev,DSYEV)
00303    (const char  &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00304     const char  &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00305     const int   &n,
00306     double       a[],
00307     const int   &lda, 
00308     double       w[],
00309     double       work[],
00310     const int   &lwork,
00311     int         &info  
00312     SimTK_LAPACK_STRLEN_ATEND_DECL
00313     SimTK_LAPACK_STRLEN_ATEND_DECL);
00314 
00315 void SimTK_STDCALL
00316 SimTK_LAPACK(dspev,DSPEV)
00317    (const char  &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00318     const char  &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00319     const int   &n,
00320     double       a[],
00321     double       w[],
00322     double       z[],
00323     const int   &ldz,
00324     double       work[],
00325     int         &info  
00326     SimTK_LAPACK_STRLEN_ATEND_DECL
00327     SimTK_LAPACK_STRLEN_ATEND_DECL);
00328 
00329 void SimTK_STDCALL
00330 SimTK_LAPACK(dsptri,DSPTRI)
00331    (const char  &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
00332     const int   &size,
00333     double       a[],
00334     int          ipiv[],
00335     double       work[], 
00336     int         &info  
00337     SimTK_LAPACK_STRLEN_ATEND_DECL);
00338 
00339 void SimTK_STDCALL
00340 SimTK_LAPACK(dsptrf,DSPTRF)
00341    (const char  &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
00342     const int   &size,
00343     double       a[],
00344     int          ipiv[], 
00345     int         &info  
00346     SimTK_LAPACK_STRLEN_ATEND_DECL);
00347 
00348 void SimTK_STDCALL
00349 SimTK_LAPACK(dsyevx,DSYEVX)
00350    (const char      &jobz,
00351     const char      &range,
00352     const char      &uplo,
00353     const int       &n,
00354     double           a[],
00355     const int       &lda,
00356     const double    &vl,
00357     const double    &vu,
00358     const int       &il,
00359     const int       &iu,
00360     const double    &abstol,
00361     int             &m,
00362     double           w[],
00363     double           z[],
00364     const int       &ldz,
00365     double           work[],
00366     const int       &lwork,
00367     int              iwork[],
00368     int              ifail[],
00369     int             &info);
00370 
00371 void SimTK_STDCALL
00372 SimTK_LAPACK(dgelss,DGELSS)
00373    (int             &m,
00374     const int       &n,
00375     const int       &nrhs,
00376     double           a[],
00377     const int       &lda,
00378     double           b[],
00379     const int       &ldb,
00380     double           s[],
00381     const double    &rcond,
00382     int             &rank,
00383     double           work[],
00384     const int       &lwork,
00385     int             &info );
00386 
00387 void SimTK_STDCALL
00388 SimTK_LAPACK(dgesv,DGESV)
00389    (int         &n,
00390     int         &nrhs,
00391     double       a[],
00392     int         &lda,
00393     int          ipiv[],
00394     double       b[],
00395     int         &ldb,
00396     int         &info);
00397 
00398 void SimTK_STDCALL
00399 SimTK_LAPACK(dgesvd,DGESVD)
00400    (const char  &jobu  SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 
00401     const char  &jobvt SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
00402     const int   &m, 
00403     const int   &n, 
00404     double       a[],
00405     const int   &lda,
00406     double       s[],
00407     double       u[],
00408     const int   &ldu, 
00409     double       vt[], 
00410     const int   &ldvt, 
00411     double       work[],
00412     const int   &lwork, 
00413     int         &info
00414     SimTK_LAPACK_STRLEN_ATEND_DECL
00415     SimTK_LAPACK_STRLEN_ATEND_DECL);
00416 
00417 */
00418 
00419 }   // namespace SimTK
00420 
00421 #endif // SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_

Generated on Thu Feb 28 01:34:33 2008 for SimTKcommon by  doxygen 1.4.7