Simbody  3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TemplatizedLapack.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_
2 #define SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2006-12 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
34 #include "SimTKlapack.h"
35 
36 #include <complex>
37 using std::complex;
38 
39 namespace SimTK {
40 
41 class Lapack {
42 public:
43  // MEANINGLESS IF NOT SPECIALIZED
44 
45  template <class P> static void
46  gemm
47  (char transa, char transb,
48  int m, int n, int k,
49  const P& alpha, const P a[], int lda,
50  const P b[], int ldb,
51  const P& beta, P c[], int ldc) {assert(false);}
52 
53  template <class P> static void
54  getri
55  (int n,
56  P a[],
57  int lda,
58  const int ipiv[],
59  P work[],
60  int lwork,
61  int &info ) {assert(false);}
62 
63  template <class P> static void
64  getrf
65  (int m,
66  int n,
67  P a[],
68  int lda,
69  int ipiv[],
70  int &info ) {assert(false);}
71 
72 };
73 
74  // xGEMM //
75 
76 template <> inline void Lapack::gemm<float>
77  (char transa, char transb,
78  int m, int n, int k,
79  const float& alpha, const float a[], int lda,
80  const float b[], int ldb,
81  const float& beta, float c[], int ldc)
82 {
83  sgemm_(
84  transa, transb,
85  m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
86  );
87 }
88 template <> inline void Lapack::gemm<double>
89  (char transa, char transb,
90  int m, int n, int k,
91  const double& alpha, const double a[], int lda,
92  const double b[], int ldb,
93  const double& beta, double c[], int ldc)
94 {
95  dgemm_(
96  transa, transb,
97  m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
98  );
99 }
100 template <> inline void Lapack::gemm< complex<float> >
101  (char transa, char transb,
102  int m, int n, int k,
103  const complex<float>& alpha, const complex<float> a[], int lda,
104  const complex<float> b[], int ldb,
105  const complex<float>& beta, complex<float> c[], int ldc)
106 {
107  cgemm_(
108  transa, transb,
109  m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
110  );
111 }
112 template <> inline void Lapack::gemm< complex<double> >
113  (char transa, char transb,
114  int m, int n, int k,
115  const complex<double>& alpha, const complex<double> a[], int lda,
116  const complex<double> b[], int ldb,
117  const complex<double>& beta, complex<double> c[], int ldc)
118 {
119  zgemm_(
120  transa, transb,
121  m,n,k,alpha,a,lda,b,ldb,beta,c,ldc
122  );
123 }
124 
125  // xGETRI //
126 
127 template <> inline void Lapack::getri<float>
128  (int n,
129  float a[],
130  int lda,
131  const int ipiv[],
132  float work[],
133  int lwork,
134  int& info )
135 {
136  sgetri_(n,a,lda,ipiv,work,lwork,info);
137 }
138 
139 template <> inline void Lapack::getri<double>
140  (int n,
141  double a[],
142  int lda,
143  const int ipiv[],
144  double work[],
145  int lwork,
146  int& info )
147 {
148  dgetri_(n,a,lda,ipiv,work,lwork,info);
149 }
150 
151 template <> inline void Lapack::getri< complex<float> >
152  (int n,
153  complex<float> a[],
154  int lda,
155  const int ipiv[],
156  complex<float> work[],
157  int lwork,
158  int& info )
159 {
160  cgetri_(n,a,lda,ipiv,work,lwork,info);
161 }
162 
163 template <> inline void Lapack::getri< complex<double> >
164  (int n,
165  complex<double> a[],
166  int lda,
167  const int ipiv[],
168  complex<double> work[],
169  int lwork,
170  int& info )
171 {
172  zgetri_(n,a,lda,ipiv,work,lwork,info);
173 }
174  // xGETRF //
175 
176 template <> inline void Lapack::getrf<float>
177  (int m,
178  int n,
179  float a[],
180  int lda,
181  int ipiv[],
182  int& info )
183 {
184  sgetrf_(m,n,a,lda,ipiv,info);
185 }
186 
187 template <> inline void Lapack::getrf<double>
188  (int m,
189  int n,
190  double a[],
191  int lda,
192  int ipiv[],
193  int& info )
194 {
195  dgetrf_(m,n,a,lda,ipiv,info);
196 }
197 
198 template <> inline void Lapack::getrf< complex<float> >
199  (int m,
200  int n,
201  complex<float> a[],
202  int lda,
203  int ipiv[],
204  int& info )
205 {
206  cgetrf_(m,n,a,lda,ipiv,info);
207 }
208 
209 template <> inline void Lapack::getrf< complex<double> >
210  (int m,
211  int n,
212  complex<double> a[],
213  int lda,
214  int ipiv[],
215  int& info )
216 {
217  zgetrf_(m,n,a,lda,ipiv,info);
218 }
219 
220 
221 /*
222 void SimTK_STDCALL
223 SimTK_LAPACK(dgeev,DGEEV)
224  (const char &jobvl SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
225  const char &jobvr SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
226  const int &n,
227  double a[],
228  const int &lda,
229  double wr[],
230  double wi[],
231  double vl[],
232  const int &ldvl,
233  double vr[],
234  const int &ldvr,
235  double work[],
236  const int &lwork,
237  int &info
238  SimTK_LAPACK_STRLEN_ATEND_DECL
239  SimTK_LAPACK_STRLEN_ATEND_DECL);
240 
241 void SimTK_STDCALL
242 SimTK_LAPACK(dsyev,DSYEV)
243  (const char &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
244  const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
245  const int &n,
246  double a[],
247  const int &lda,
248  double w[],
249  double work[],
250  const int &lwork,
251  int &info
252  SimTK_LAPACK_STRLEN_ATEND_DECL
253  SimTK_LAPACK_STRLEN_ATEND_DECL);
254 
255 void SimTK_STDCALL
256 SimTK_LAPACK(dspev,DSPEV)
257  (const char &jobz SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
258  const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
259  const int &n,
260  double a[],
261  double w[],
262  double z[],
263  const int &ldz,
264  double work[],
265  int &info
266  SimTK_LAPACK_STRLEN_ATEND_DECL
267  SimTK_LAPACK_STRLEN_ATEND_DECL);
268 
269 void SimTK_STDCALL
270 SimTK_LAPACK(dsptri,DSPTRI)
271  (const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
272  const int &size,
273  double a[],
274  int ipiv[],
275  double work[],
276  int &info
277  SimTK_LAPACK_STRLEN_ATEND_DECL);
278 
279 void SimTK_STDCALL
280 SimTK_LAPACK(dsptrf,DSPTRF)
281  (const char &uplo SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
282  const int &size,
283  double a[],
284  int ipiv[],
285  int &info
286  SimTK_LAPACK_STRLEN_ATEND_DECL);
287 
288 void SimTK_STDCALL
289 SimTK_LAPACK(dsyevx,DSYEVX)
290  (const char &jobz,
291  const char &range,
292  const char &uplo,
293  const int &n,
294  double a[],
295  const int &lda,
296  const double &vl,
297  const double &vu,
298  const int &il,
299  const int &iu,
300  const double &abstol,
301  int &m,
302  double w[],
303  double z[],
304  const int &ldz,
305  double work[],
306  const int &lwork,
307  int iwork[],
308  int ifail[],
309  int &info);
310 
311 void SimTK_STDCALL
312 SimTK_LAPACK(dgelss,DGELSS)
313  (int &m,
314  const int &n,
315  const int &nrhs,
316  double a[],
317  const int &lda,
318  double b[],
319  const int &ldb,
320  double s[],
321  const double &rcond,
322  int &rank,
323  double work[],
324  const int &lwork,
325  int &info );
326 
327 void SimTK_STDCALL
328 SimTK_LAPACK(dgesv,DGESV)
329  (int &n,
330  int &nrhs,
331  double a[],
332  int &lda,
333  int ipiv[],
334  double b[],
335  int &ldb,
336  int &info);
337 
338 void SimTK_STDCALL
339 SimTK_LAPACK(dgesvd,DGESVD)
340  (const char &jobu SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
341  const char &jobvt SimTK_LAPACK_STRLEN_FOLLOWS_DECL,
342  const int &m,
343  const int &n,
344  double a[],
345  const int &lda,
346  double s[],
347  double u[],
348  const int &ldu,
349  double vt[],
350  const int &ldvt,
351  double work[],
352  const int &lwork,
353  int &info
354  SimTK_LAPACK_STRLEN_ATEND_DECL
355  SimTK_LAPACK_STRLEN_ATEND_DECL);
356 
357 */
358 
359 } // namespace SimTK
360 
361 #endif // SimTK_SimTKCOMMON_TEMPLATIZED_LAPACK_H_
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
static void getri(int n, P a[], int lda, const int ipiv[], P work[], int lwork, int &info)
Definition: TemplatizedLapack.h:55
static void getrf(int m, int n, P a[], int lda, int ipiv[], int &info)
Definition: TemplatizedLapack.h:65
Definition: TemplatizedLapack.h:41
static void gemm(char transa, char transb, int m, int n, int k, const P &alpha, const P a[], int lda, const P b[], int ldb, const P &beta, P c[], int ldc)
Definition: TemplatizedLapack.h:47
Mandatory first inclusion for any Simbody source or header file.