Simbody
|
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-9 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 #include <complex> 00045 using std::complex; 00046 00047 namespace SimTK { 00048 00049 class Lapack { 00050 public: 00051 // MEANINGLESS IF NOT SPECIALIZED 00052 00053 template <class P> static void 00054 gemm 00055 (char transa, char transb, 00056 int m, int n, int k, 00057 const P& alpha, const P a[], int lda, 00058 const P b[], int ldb, 00059 const P& beta, P c[], int ldc) {assert(false);} 00060 00061 template <class P> static void 00062 getri 00063 (int n, 00064 P a[], 00065 int lda, 00066 const int ipiv[], 00067 P work[], 00068 int lwork, 00069 int &info ) {assert(false);} 00070 00071 template <class P> static void 00072 getrf 00073 (int m, 00074 int n, 00075 P a[], 00076 int lda, 00077 int ipiv[], 00078 int &info ) {assert(false);} 00079 00080 }; 00081 00082 // xGEMM // 00083 00084 template <> inline void Lapack::gemm<float> 00085 (char transa, char transb, 00086 int m, int n, int k, 00087 const float& alpha, const float a[], int lda, 00088 const float b[], int ldb, 00089 const float& beta, float c[], int ldc) 00090 { 00091 sgemm_( 00092 transa, transb, 00093 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00094 ); 00095 } 00096 template <> inline void Lapack::gemm<double> 00097 (char transa, char transb, 00098 int m, int n, int k, 00099 const double& alpha, const double a[], int lda, 00100 const double b[], int ldb, 00101 const double& beta, double c[], int ldc) 00102 { 00103 dgemm_( 00104 transa, transb, 00105 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00106 ); 00107 } 00108 template <> inline void Lapack::gemm< complex<float> > 00109 (char transa, char transb, 00110 int m, int n, int k, 00111 const complex<float>& alpha, const complex<float> a[], int lda, 00112 const complex<float> b[], int ldb, 00113 const complex<float>& beta, complex<float> c[], int ldc) 00114 { 00115 cgemm_( 00116 transa, transb, 00117 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00118 ); 00119 } 00120 template <> inline void Lapack::gemm< complex<double> > 00121 (char transa, char transb, 00122 int m, int n, int k, 00123 const complex<double>& alpha, const complex<double> a[], int lda, 00124 const complex<double> b[], int ldb, 00125 const complex<double>& beta, complex<double> c[], int ldc) 00126 { 00127 zgemm_( 00128 transa, transb, 00129 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00130 ); 00131 } 00132 00133 // xGETRI // 00134 00135 template <> inline void Lapack::getri<float> 00136 (int n, 00137 float a[], 00138 int lda, 00139 const int ipiv[], 00140 float work[], 00141 int lwork, 00142 int& info ) 00143 { 00144 sgetri_(n,a,lda,ipiv,work,lwork,info); 00145 } 00146 00147 template <> inline void Lapack::getri<double> 00148 (int n, 00149 double a[], 00150 int lda, 00151 const int ipiv[], 00152 double work[], 00153 int lwork, 00154 int& info ) 00155 { 00156 dgetri_(n,a,lda,ipiv,work,lwork,info); 00157 } 00158 00159 template <> inline void Lapack::getri< complex<float> > 00160 (int n, 00161 complex<float> a[], 00162 int lda, 00163 const int ipiv[], 00164 complex<float> work[], 00165 int lwork, 00166 int& info ) 00167 { 00168 cgetri_(n,a,lda,ipiv,work,lwork,info); 00169 } 00170 00171 template <> inline void Lapack::getri< complex<double> > 00172 (int n, 00173 complex<double> a[], 00174 int lda, 00175 const int ipiv[], 00176 complex<double> work[], 00177 int lwork, 00178 int& info ) 00179 { 00180 zgetri_(n,a,lda,ipiv,work,lwork,info); 00181 } 00182 // xGETRF // 00183 00184 template <> inline void Lapack::getrf<float> 00185 (int m, 00186 int n, 00187 float a[], 00188 int lda, 00189 int ipiv[], 00190 int& info ) 00191 { 00192 sgetrf_(m,n,a,lda,ipiv,info); 00193 } 00194 00195 template <> inline void Lapack::getrf<double> 00196 (int m, 00197 int n, 00198 double a[], 00199 int lda, 00200 int ipiv[], 00201 int& info ) 00202 { 00203 dgetrf_(m,n,a,lda,ipiv,info); 00204 } 00205 00206 template <> inline void Lapack::getrf< complex<float> > 00207 (int m, 00208 int n, 00209 complex<float> a[], 00210 int lda, 00211 int ipiv[], 00212 int& info ) 00213 { 00214 cgetrf_(m,n,a,lda,ipiv,info); 00215 } 00216 00217 template <> inline void Lapack::getrf< complex<double> > 00218 (int m, 00219 int n, 00220 complex<double> a[], 00221 int lda, 00222 int ipiv[], 00223 int& info ) 00224 { 00225 zgetrf_(m,n,a,lda,ipiv,info); 00226 } 00227 00228 00229 /* 00230 void SimTK_STDCALL 00231 SimTK_LAPACK(dgeev,DGEEV) 00232 (const char &jobvl SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00233 const char &jobvr SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00234 const int &n, 00235 double a[], 00236 const int &lda, 00237 double wr[], 00238 double wi[], 00239 double vl[], 00240 const int &ldvl, 00241 double vr[], 00242 const int &ldvr, 00243 double work[], 00244 const int &lwork, 00245 int &info 00246 SimTK_LAPACK_STRLEN_ATEND_DECL 00247 SimTK_LAPACK_STRLEN_ATEND_DECL); 00248 00249 void SimTK_STDCALL 00250 SimTK_LAPACK(dsyev,DSYEV) 00251 (const char &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00252 const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00253 const int &n, 00254 double a[], 00255 const int &lda, 00256 double w[], 00257 double work[], 00258 const int &lwork, 00259 int &info 00260 SimTK_LAPACK_STRLEN_ATEND_DECL 00261 SimTK_LAPACK_STRLEN_ATEND_DECL); 00262 00263 void SimTK_STDCALL 00264 SimTK_LAPACK(dspev,DSPEV) 00265 (const char &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00266 const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00267 const int &n, 00268 double a[], 00269 double w[], 00270 double z[], 00271 const int &ldz, 00272 double work[], 00273 int &info 00274 SimTK_LAPACK_STRLEN_ATEND_DECL 00275 SimTK_LAPACK_STRLEN_ATEND_DECL); 00276 00277 void SimTK_STDCALL 00278 SimTK_LAPACK(dsptri,DSPTRI) 00279 (const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00280 const int &size, 00281 double a[], 00282 int ipiv[], 00283 double work[], 00284 int &info 00285 SimTK_LAPACK_STRLEN_ATEND_DECL); 00286 00287 void SimTK_STDCALL 00288 SimTK_LAPACK(dsptrf,DSPTRF) 00289 (const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00290 const int &size, 00291 double a[], 00292 int ipiv[], 00293 int &info 00294 SimTK_LAPACK_STRLEN_ATEND_DECL); 00295 00296 void SimTK_STDCALL 00297 SimTK_LAPACK(dsyevx,DSYEVX) 00298 (const char &jobz, 00299 const char &range, 00300 const char &uplo, 00301 const int &n, 00302 double a[], 00303 const int &lda, 00304 const double &vl, 00305 const double &vu, 00306 const int &il, 00307 const int &iu, 00308 const double &abstol, 00309 int &m, 00310 double w[], 00311 double z[], 00312 const int &ldz, 00313 double work[], 00314 const int &lwork, 00315 int iwork[], 00316 int ifail[], 00317 int &info); 00318 00319 void SimTK_STDCALL 00320 SimTK_LAPACK(dgelss,DGELSS) 00321 (int &m, 00322 const int &n, 00323 const int &nrhs, 00324 double a[], 00325 const int &lda, 00326 double b[], 00327 const int &ldb, 00328 double s[], 00329 const double &rcond, 00330 int &rank, 00331 double work[], 00332 const int &lwork, 00333 int &info ); 00334 00335 void SimTK_STDCALL 00336 SimTK_LAPACK(dgesv,DGESV) 00337 (int &n, 00338 int &nrhs, 00339 double a[], 00340 int &lda, 00341 int ipiv[], 00342 double b[], 00343 int &ldb, 00344 int &info); 00345 00346 void SimTK_STDCALL 00347 SimTK_LAPACK(dgesvd,DGESVD) 00348 (const char &jobu SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00349 const char &jobvt SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00350 const int &m, 00351 const int &n, 00352 double a[], 00353 const int &lda, 00354 double s[], 00355 double u[], 00356 const int &ldu, 00357 double vt[], 00358 const int &ldvt, 00359 double work[], 00360 const int &lwork, 00361 int &info 00362 SimTK_LAPACK_STRLEN_ATEND_DECL 00363 SimTK_LAPACK_STRLEN_ATEND_DECL); 00364 00365 */ 00366 00367 } // namespace SimTK 00368 00369 #endif // SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_