mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
templateLapack.cpp
Go to the documentation of this file.
1 /** \file templateLapack.cpp
2  * \brief Implementation of templatized wrappers for the Lapack library
3  * \ingroup gen_math_files
4  * \author Jared R. Males (jaredmales@gmail.com)
5  *
6  */
7 
8 //***********************************************************************//
9 // Copyright 2020 Jared R. Males (jaredmales@gmail.com)
10 //
11 // This file is part of mxlib.
12 //
13 // mxlib is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // mxlib is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25 //***********************************************************************//
26 
27 #include "math/templateLapack.hpp"
28 
29 
30 namespace mx
31 {
32 namespace math
33 {
34 
35 
36 template<>
37 float lamch<float>(char CMACH)
38 {
39  return slamch_ (&CMACH
40  #ifdef LAPACK_FORTRAN_STRLEN_END
41  , 1
42  #endif
43  );
44 }
45 
46 // Double specialization of lamch, a wrapper for Lapack DLAMCH
47 template<>
48 double lamch<double>(char CMACH)
49 {
50  return dlamch_ (&CMACH
51  #ifdef LAPACK_FORTRAN_STRLEN_END
52  , 1
53  #endif
54  );
55 }
56 
57 template<>
58 MXLAPACK_INT potrf<float> ( char UPLO, MXLAPACK_INT N, float * A, MXLAPACK_INT LDA, MXLAPACK_INT &INFO )
59 {
60  spotrf_(&UPLO, &N, A, &LDA, &INFO
61  #ifdef LAPACK_FORTRAN_STRLEN_END
62  , 1
63  #endif
64  );
65 
66  return INFO;
67 }
68 
69 template<>
70 MXLAPACK_INT potrf<double> ( char UPLO, MXLAPACK_INT N, double * A, MXLAPACK_INT LDA, MXLAPACK_INT &INFO )
71 {
72  dpotrf_(&UPLO, &N, A, &LDA, &INFO
73  #ifdef LAPACK_FORTRAN_STRLEN_END
74  , 1
75  #endif
76  );
77 
78  return INFO;
79 }
80 
81 template<>
82 MXLAPACK_INT potrf<std::complex<float>> ( char UPLO, MXLAPACK_INT N, std::complex<float> * A, MXLAPACK_INT LDA, MXLAPACK_INT &INFO )
83 {
84  cpotrf_(&UPLO, &N,
85  (float _Complex*)A,
86  &LDA, &INFO
87  #ifdef LAPACK_FORTRAN_STRLEN_END
88  , 1
89  #endif
90  );
91 
92  return INFO;
93 }
94 
95 template<>
96 MXLAPACK_INT potrf<std::complex<double>> ( char UPLO, MXLAPACK_INT N, std::complex<double> * A, MXLAPACK_INT LDA, MXLAPACK_INT &INFO )
97 {
98  zpotrf_(&UPLO, &N,
99  (double _Complex*)A,
100  &LDA, &INFO
101  #ifdef LAPACK_FORTRAN_STRLEN_END
102  , 1
103  #endif
104  );
105 
106  return INFO;
107 }
108 
109 template<>
110 MXLAPACK_INT sytrd<float>( char UPLO, MXLAPACK_INT N, float * A, MXLAPACK_INT LDA, float *D, float *E, float *TAU, float *WORK, MXLAPACK_INT LWORK, MXLAPACK_INT INFO)
111 {
112 
113  ssytrd_(&UPLO, &N, A, &LDA, D, E, TAU, WORK, &LWORK, &INFO
114  #ifdef LAPACK_FORTRAN_STRLEN_END
115  , 1
116  #endif
117  );
118 
119  return INFO;
120 }
121 
122 template<>
123 MXLAPACK_INT sytrd<double>( char UPLO, MXLAPACK_INT N, double * A, MXLAPACK_INT LDA, double *D, double *E, double *TAU, double *WORK, MXLAPACK_INT LWORK, MXLAPACK_INT INFO)
124 {
125 
126  dsytrd_(&UPLO, &N, A, &LDA, D, E, TAU, WORK, &LWORK, &INFO
127  #ifdef LAPACK_FORTRAN_STRLEN_END
128  , 1
129  #endif
130  );
131 
132  return INFO;
133 }
134 
135 // Float specialization of syevr, a wrapper for Lapack SSYEVR
136 template<>
137 MXLAPACK_INT syevr<float> ( char JOBZ, char RANGE, char UPLO, MXLAPACK_INT N, float *A, MXLAPACK_INT LDA, float VL, float VU,
138  MXLAPACK_INT IL, MXLAPACK_INT IU, float ABSTOL, MXLAPACK_INT *M, float *W, float *Z, MXLAPACK_INT LDZ, MXLAPACK_INT *ISUPPZ,
139  float *WORK, MXLAPACK_INT LWORK, MXLAPACK_INT *IWORK, MXLAPACK_INT LIWORK )
140 {
141 
142  MXLAPACK_INT INFO;
143 
144  ssyevr_ (&JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU,
145  &IL, &IU, &ABSTOL, M, W, Z, &LDZ, ISUPPZ,
146  WORK, &LWORK, IWORK, &LIWORK, &INFO
147  #ifdef LAPACK_FORTRAN_STRLEN_END
148  , 1, 1, 1
149  #endif
150  );
151 
152  return INFO;
153 }
154 
155 // Double specialization of syevr, a wrapper for Lapack DSYEVR
156 template<>
157 MXLAPACK_INT syevr<double> ( char JOBZ, char RANGE, char UPLO, MXLAPACK_INT N, double *A, MXLAPACK_INT LDA, double VL, double VU,
158  MXLAPACK_INT IL, MXLAPACK_INT IU, double ABSTOL, MXLAPACK_INT *M, double *W, double *Z, MXLAPACK_INT LDZ, MXLAPACK_INT *ISUPPZ,
159  double *WORK, MXLAPACK_INT LWORK, MXLAPACK_INT *IWORK, MXLAPACK_INT LIWORK )
160 {
161 
162  MXLAPACK_INT INFO;
163 
164  dsyevr_ (&JOBZ, &RANGE, &UPLO, &N, A, &LDA, &VL, &VU,
165  &IL, &IU, &ABSTOL, M, W, Z, &LDZ, ISUPPZ,
166  WORK, &LWORK, IWORK, &LIWORK, &INFO
167  #ifdef LAPACK_FORTRAN_STRLEN_END
168  , 1, 1, 1
169  #endif
170  );
171 
172  return INFO;
173 }
174 
175 //float specialization of gesvd
176 template<>
177 MXLAPACK_INT gesvd<float>( char JOBU, char JOBVT, MXLAPACK_INT M, MXLAPACK_INT N, float * A, MXLAPACK_INT LDA, float * S, float *U, MXLAPACK_INT LDU,
178  float * VT, MXLAPACK_INT LDVT, float * WORK, MXLAPACK_INT LWORK)
179 {
180  MXLAPACK_INT INFO;
181 
182  sgesvd_(&JOBU, &JOBVT, &M, &N, A, &LDA, S, U, &LDU,VT, &LDVT, WORK, &LWORK, &INFO
183  #ifdef LAPACK_FORTRAN_STRLEN_END
184  , 1, 1
185  #endif
186  );
187 
188  return INFO;
189 }
190 
191 //double specialization of gesvd
192 template<>
193 MXLAPACK_INT gesvd<double>( char JOBU, char JOBVT, MXLAPACK_INT M, MXLAPACK_INT N, double * A, MXLAPACK_INT LDA, double * S, double *U, MXLAPACK_INT LDU,
194  double * VT, MXLAPACK_INT LDVT, double * WORK, MXLAPACK_INT LWORK)
195 {
196  MXLAPACK_INT INFO;
197 
198  dgesvd_(&JOBU, &JOBVT, &M, &N, A, &LDA, S, U, &LDU,VT, &LDVT, WORK, &LWORK, &INFO
199  #ifdef LAPACK_FORTRAN_STRLEN_END
200  , 1, 1
201  #endif
202  );
203 
204  return INFO;
205 }
206 
207 //float specialization of gesdd
208 template<>
209 MXLAPACK_INT gesdd<float>(char JOBZ, MXLAPACK_INT M, MXLAPACK_INT N, float *A, MXLAPACK_INT LDA, float *S, float * U, MXLAPACK_INT LDU, float * VT, MXLAPACK_INT LDVT, float *WORK, MXLAPACK_INT LWORK, MXLAPACK_INT * IWORK, MXLAPACK_INT INFO)
210 {
211  sgesdd_(&JOBZ,&M,&N,A,&LDA,S,U,&LDU,VT,&LDVT,WORK,&LWORK,IWORK,&INFO
212  #ifdef LAPACK_FORTRAN_STRLEN_END
213  , 1
214  #endif
215  );
216 
217  return INFO;
218 }
219 
220 //double specialization of gesdd
221 template<>
222 MXLAPACK_INT gesdd<double>(char JOBZ, MXLAPACK_INT M, MXLAPACK_INT N, double *A, MXLAPACK_INT LDA, double *S, double * U, MXLAPACK_INT LDU, double * VT, MXLAPACK_INT LDVT, double *WORK, MXLAPACK_INT LWORK, MXLAPACK_INT * IWORK, MXLAPACK_INT INFO)
223 {
224  dgesdd_(&JOBZ,&M,&N,A,&LDA,S,U,&LDU,VT,&LDVT,WORK,&LWORK,IWORK,&INFO
225  #ifdef LAPACK_FORTRAN_STRLEN_END
226  , 1
227  #endif
228  );
229 
230  return INFO;
231 }
232 
233 } //namespace math
234 } //namespace mx
235 
236 
The mxlib c++ namespace.
Definition: mxError.hpp:107
Declares and defines templatized wrappers for the Lapack library.