Simbody
3.4 (development)
|
00001 #ifndef SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_ 00002 #define SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_ 00003 00004 /* -------------------------------------------------------------------------- * 00005 * Simbody(tm): SimTKcommon * 00006 * -------------------------------------------------------------------------- * 00007 * This is part of the SimTK 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/home/simbody. * 00011 * * 00012 * Portions copyright (c) 2006-12 Stanford University and the Authors. * 00013 * Authors: Michael Sherman * 00014 * Contributors: * 00015 * * 00016 * Licensed under the Apache License, Version 2.0 (the "License"); you may * 00017 * not use this file except in compliance with the License. You may obtain a * 00018 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. * 00019 * * 00020 * Unless required by applicable law or agreed to in writing, software * 00021 * distributed under the License is distributed on an "AS IS" BASIS, * 00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00023 * See the License for the specific language governing permissions and * 00024 * limitations under the License. * 00025 * -------------------------------------------------------------------------- */ 00026 00033 #include "SimTKcommon/internal/common.h" 00034 #include "SimTKlapack.h" 00035 00036 #include <complex> 00037 using std::complex; 00038 00039 namespace SimTK { 00040 00041 class Lapack { 00042 public: 00043 // MEANINGLESS IF NOT SPECIALIZED 00044 00045 template <class P> static void 00046 gemm 00047 (char transa, char transb, 00048 int m, int n, int k, 00049 const P& alpha, const P a[], int lda, 00050 const P b[], int ldb, 00051 const P& beta, P c[], int ldc) {assert(false);} 00052 00053 template <class P> static void 00054 getri 00055 (int n, 00056 P a[], 00057 int lda, 00058 const int ipiv[], 00059 P work[], 00060 int lwork, 00061 int &info ) {assert(false);} 00062 00063 template <class P> static void 00064 getrf 00065 (int m, 00066 int n, 00067 P a[], 00068 int lda, 00069 int ipiv[], 00070 int &info ) {assert(false);} 00071 00072 }; 00073 00074 // xGEMM // 00075 00076 template <> inline void Lapack::gemm<float> 00077 (char transa, char transb, 00078 int m, int n, int k, 00079 const float& alpha, const float a[], int lda, 00080 const float b[], int ldb, 00081 const float& beta, float c[], int ldc) 00082 { 00083 sgemm_( 00084 transa, transb, 00085 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00086 ); 00087 } 00088 template <> inline void Lapack::gemm<double> 00089 (char transa, char transb, 00090 int m, int n, int k, 00091 const double& alpha, const double a[], int lda, 00092 const double b[], int ldb, 00093 const double& beta, double c[], int ldc) 00094 { 00095 dgemm_( 00096 transa, transb, 00097 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00098 ); 00099 } 00100 template <> inline void Lapack::gemm< complex<float> > 00101 (char transa, char transb, 00102 int m, int n, int k, 00103 const complex<float>& alpha, const complex<float> a[], int lda, 00104 const complex<float> b[], int ldb, 00105 const complex<float>& beta, complex<float> c[], int ldc) 00106 { 00107 cgemm_( 00108 transa, transb, 00109 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00110 ); 00111 } 00112 template <> inline void Lapack::gemm< complex<double> > 00113 (char transa, char transb, 00114 int m, int n, int k, 00115 const complex<double>& alpha, const complex<double> a[], int lda, 00116 const complex<double> b[], int ldb, 00117 const complex<double>& beta, complex<double> c[], int ldc) 00118 { 00119 zgemm_( 00120 transa, transb, 00121 m,n,k,alpha,a,lda,b,ldb,beta,c,ldc 00122 ); 00123 } 00124 00125 // xGETRI // 00126 00127 template <> inline void Lapack::getri<float> 00128 (int n, 00129 float a[], 00130 int lda, 00131 const int ipiv[], 00132 float work[], 00133 int lwork, 00134 int& info ) 00135 { 00136 sgetri_(n,a,lda,ipiv,work,lwork,info); 00137 } 00138 00139 template <> inline void Lapack::getri<double> 00140 (int n, 00141 double a[], 00142 int lda, 00143 const int ipiv[], 00144 double work[], 00145 int lwork, 00146 int& info ) 00147 { 00148 dgetri_(n,a,lda,ipiv,work,lwork,info); 00149 } 00150 00151 template <> inline void Lapack::getri< complex<float> > 00152 (int n, 00153 complex<float> a[], 00154 int lda, 00155 const int ipiv[], 00156 complex<float> work[], 00157 int lwork, 00158 int& info ) 00159 { 00160 cgetri_(n,a,lda,ipiv,work,lwork,info); 00161 } 00162 00163 template <> inline void Lapack::getri< complex<double> > 00164 (int n, 00165 complex<double> a[], 00166 int lda, 00167 const int ipiv[], 00168 complex<double> work[], 00169 int lwork, 00170 int& info ) 00171 { 00172 zgetri_(n,a,lda,ipiv,work,lwork,info); 00173 } 00174 // xGETRF // 00175 00176 template <> inline void Lapack::getrf<float> 00177 (int m, 00178 int n, 00179 float a[], 00180 int lda, 00181 int ipiv[], 00182 int& info ) 00183 { 00184 sgetrf_(m,n,a,lda,ipiv,info); 00185 } 00186 00187 template <> inline void Lapack::getrf<double> 00188 (int m, 00189 int n, 00190 double a[], 00191 int lda, 00192 int ipiv[], 00193 int& info ) 00194 { 00195 dgetrf_(m,n,a,lda,ipiv,info); 00196 } 00197 00198 template <> inline void Lapack::getrf< complex<float> > 00199 (int m, 00200 int n, 00201 complex<float> a[], 00202 int lda, 00203 int ipiv[], 00204 int& info ) 00205 { 00206 cgetrf_(m,n,a,lda,ipiv,info); 00207 } 00208 00209 template <> inline void Lapack::getrf< complex<double> > 00210 (int m, 00211 int n, 00212 complex<double> a[], 00213 int lda, 00214 int ipiv[], 00215 int& info ) 00216 { 00217 zgetrf_(m,n,a,lda,ipiv,info); 00218 } 00219 00220 00221 /* 00222 void SimTK_STDCALL 00223 SimTK_LAPACK(dgeev,DGEEV) 00224 (const char &jobvl SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00225 const char &jobvr SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00226 const int &n, 00227 double a[], 00228 const int &lda, 00229 double wr[], 00230 double wi[], 00231 double vl[], 00232 const int &ldvl, 00233 double vr[], 00234 const int &ldvr, 00235 double work[], 00236 const int &lwork, 00237 int &info 00238 SimTK_LAPACK_STRLEN_ATEND_DECL 00239 SimTK_LAPACK_STRLEN_ATEND_DECL); 00240 00241 void SimTK_STDCALL 00242 SimTK_LAPACK(dsyev,DSYEV) 00243 (const char &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00244 const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00245 const int &n, 00246 double a[], 00247 const int &lda, 00248 double w[], 00249 double work[], 00250 const int &lwork, 00251 int &info 00252 SimTK_LAPACK_STRLEN_ATEND_DECL 00253 SimTK_LAPACK_STRLEN_ATEND_DECL); 00254 00255 void SimTK_STDCALL 00256 SimTK_LAPACK(dspev,DSPEV) 00257 (const char &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00258 const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00259 const int &n, 00260 double a[], 00261 double w[], 00262 double z[], 00263 const int &ldz, 00264 double work[], 00265 int &info 00266 SimTK_LAPACK_STRLEN_ATEND_DECL 00267 SimTK_LAPACK_STRLEN_ATEND_DECL); 00268 00269 void SimTK_STDCALL 00270 SimTK_LAPACK(dsptri,DSPTRI) 00271 (const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00272 const int &size, 00273 double a[], 00274 int ipiv[], 00275 double work[], 00276 int &info 00277 SimTK_LAPACK_STRLEN_ATEND_DECL); 00278 00279 void SimTK_STDCALL 00280 SimTK_LAPACK(dsptrf,DSPTRF) 00281 (const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00282 const int &size, 00283 double a[], 00284 int ipiv[], 00285 int &info 00286 SimTK_LAPACK_STRLEN_ATEND_DECL); 00287 00288 void SimTK_STDCALL 00289 SimTK_LAPACK(dsyevx,DSYEVX) 00290 (const char &jobz, 00291 const char &range, 00292 const char &uplo, 00293 const int &n, 00294 double a[], 00295 const int &lda, 00296 const double &vl, 00297 const double &vu, 00298 const int &il, 00299 const int &iu, 00300 const double &abstol, 00301 int &m, 00302 double w[], 00303 double z[], 00304 const int &ldz, 00305 double work[], 00306 const int &lwork, 00307 int iwork[], 00308 int ifail[], 00309 int &info); 00310 00311 void SimTK_STDCALL 00312 SimTK_LAPACK(dgelss,DGELSS) 00313 (int &m, 00314 const int &n, 00315 const int &nrhs, 00316 double a[], 00317 const int &lda, 00318 double b[], 00319 const int &ldb, 00320 double s[], 00321 const double &rcond, 00322 int &rank, 00323 double work[], 00324 const int &lwork, 00325 int &info ); 00326 00327 void SimTK_STDCALL 00328 SimTK_LAPACK(dgesv,DGESV) 00329 (int &n, 00330 int &nrhs, 00331 double a[], 00332 int &lda, 00333 int ipiv[], 00334 double b[], 00335 int &ldb, 00336 int &info); 00337 00338 void SimTK_STDCALL 00339 SimTK_LAPACK(dgesvd,DGESVD) 00340 (const char &jobu SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00341 const char &jobvt SimTK_LAPACK_STRLEN_FOLLOWS_DECL, 00342 const int &m, 00343 const int &n, 00344 double a[], 00345 const int &lda, 00346 double s[], 00347 double u[], 00348 const int &ldu, 00349 double vt[], 00350 const int &ldvt, 00351 double work[], 00352 const int &lwork, 00353 int &info 00354 SimTK_LAPACK_STRLEN_ATEND_DECL 00355 SimTK_LAPACK_STRLEN_ATEND_DECL); 00356 00357 */ 00358 00359 } // namespace SimTK 00360 00361 #endif // SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_