ARPACK-Armadillo
LapackWrapperExtra.h
1 // Copyright (C) 2015 Yixuan Qiu
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef LAPACK_WRAPPER_EXTRA_H
8 #define LAPACK_WRAPPER_EXTRA_H
9 
10 namespace arma
11 {
12  #ifdef ARMA_USE_LAPACK
13 
14  #if !defined(ARMA_BLAS_CAPITALS)
15 
16  // Solving linear equations using LDL decomposition
17  #define arma_ssytrs ssytrs
18  #define arma_dsytrs dsytrs
19  #define arma_csytrs csytrs
20  #define arma_zsytrs zsytrs
21 
22  // Solving linear equations using LU decomposition
23  #define arma_sgetrs sgetrs
24  #define arma_dgetrs dgetrs
25  #define arma_cgetrs cgetrs
26  #define arma_zgetrs zgetrs
27 
28  // Calculating eigenvalues of an upper Hessenberg matrix
29  #define arma_slahqr slahqr
30  #define arma_dlahqr dlahqr
31 
32  // Calculating eigenvalues of a symmetric tridiagonal matrix
33  #define arma_sstedc sstedc
34  #define arma_dstedc dstedc
35 
36  // Calculating eigenvectors of a Schur form matrix
37  #define arma_strevc strevc
38  #define arma_dtrevc dtrevc
39 
40  #else
41 
42  #define arma_ssytrs SSYTRS
43  #define arma_dsytrs DSYTRS
44  #define arma_csytrs CSYTRS
45  #define arma_zsytrs ZSYTRS
46 
47  #define arma_sgetrs SGETRS
48  #define arma_dgetrs DGETRS
49  #define arma_cgetrs CGETRS
50  #define arma_zgetrs ZGETRS
51 
52  #define arma_slahqr SLAHQR
53  #define arma_dlahqr DLAHQR
54 
55  #define arma_sstedc SSTEDC
56  #define arma_dstedc DSTEDC
57 
58  #define arma_strevc STREVC
59  #define arma_dtrevc DTREVC
60 
61  #endif
62 
63 
64 
65  extern "C"
66  {
67  void arma_fortran(arma_ssytrs)(char* uplo, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, blas_int* ipiv, float* b, blas_int* ldb, blas_int* info);
68  void arma_fortran(arma_dsytrs)(char* uplo, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, blas_int* ipiv, double* b, blas_int* ldb, blas_int* info);
69  void arma_fortran(arma_csytrs)(char* uplo, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info);
70  void arma_fortran(arma_zsytrs)(char* uplo, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info);
71 
72  void arma_fortran(arma_sgetrs)(char* trans, blas_int* n, blas_int* nrhs, float* a, blas_int* lda, blas_int* ipiv, float* b, blas_int* ldb, blas_int* info);
73  void arma_fortran(arma_dgetrs)(char* trans, blas_int* n, blas_int* nrhs, double* a, blas_int* lda, blas_int* ipiv, double* b, blas_int* ldb, blas_int* info);
74  void arma_fortran(arma_cgetrs)(char* trans, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info);
75  void arma_fortran(arma_zgetrs)(char* trans, blas_int* n, blas_int* nrhs, void* a, blas_int* lda, blas_int* ipiv, void* b, blas_int* ldb, blas_int* info);
76 
77  void arma_fortran(arma_slahqr)(blas_int* wantt, blas_int* wantz, blas_int* n, blas_int* ilo, blas_int* ihi, float* h, blas_int* ldh, float* wr, float* wi, blas_int* iloz, blas_int* ihiz, float* z, blas_int* ldz, blas_int* info);
78  void arma_fortran(arma_dlahqr)(blas_int* wantt, blas_int* wantz, blas_int* n, blas_int* ilo, blas_int* ihi, double* h, blas_int* ldh, double* wr, double* wi, blas_int* iloz, blas_int* ihiz, double* z, blas_int* ldz, blas_int* info);
79 
80  void arma_fortran(arma_sstedc)(char* compz, blas_int* n, float* d, float* e, float* z, blas_int* ldz, float* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info);
81  void arma_fortran(arma_dstedc)(char* compz, blas_int* n, double* d, double* e, double* z, blas_int* ldz, double* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info);
82 
83  void arma_fortran(arma_strevc)(char* side, char* howmny, blas_int* select, blas_int* n, float* t, blas_int* ldt, float* vl, blas_int* ldvl, float* vr, blas_int* ldvr, blas_int* mm, blas_int* m, float* work, blas_int* info);
84  void arma_fortran(arma_dtrevc)(char* side, char* howmny, blas_int* select, blas_int* n, double* t, blas_int* ldt, double* vl, blas_int* ldvl, double* vr, blas_int* ldvr, blas_int* mm, blas_int* m, double* work, blas_int* info);
85  }
86 
87 
88 
89  namespace lapack
90  {
91  template<typename eT>
92  inline
93  void
94  sytrs(char* uplo, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, blas_int* ipiv, eT* b, blas_int* ldb, blas_int* info)
95  {
96  arma_type_check(( is_supported_blas_type<eT>::value == false ));
97  if(is_float<eT>::value == true)
98  {
99  typedef float T;
100  arma_fortran(arma_ssytrs)(uplo, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
101  }
102  else
103  if(is_double<eT>::value == true)
104  {
105  typedef double T;
106  arma_fortran(arma_dsytrs)(uplo, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
107  }
108  else
109  if(is_supported_complex_float<eT>::value == true)
110  {
111  typedef std::complex<float> T;
112  arma_fortran(arma_csytrs)(uplo, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
113  }
114  else
115  if(is_supported_complex_double<eT>::value == true)
116  {
117  typedef std::complex<double> T;
118  arma_fortran(arma_zsytrs)(uplo, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
119  }
120  }
121 
122  template<typename eT>
123  inline
124  void
125  getrs(char* trans, blas_int* n, blas_int* nrhs, eT* a, blas_int* lda, blas_int* ipiv, eT* b, blas_int* ldb, blas_int* info)
126  {
127  arma_type_check(( is_supported_blas_type<eT>::value == false ));
128  if(is_float<eT>::value == true)
129  {
130  typedef float T;
131  arma_fortran(arma_sgetrs)(trans, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
132  }
133  else
134  if(is_double<eT>::value == true)
135  {
136  typedef double T;
137  arma_fortran(arma_dgetrs)(trans, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
138  }
139  else
140  if(is_supported_complex_float<eT>::value == true)
141  {
142  typedef std::complex<float> T;
143  arma_fortran(arma_cgetrs)(trans, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
144  }
145  else
146  if(is_supported_complex_double<eT>::value == true)
147  {
148  typedef std::complex<double> T;
149  arma_fortran(arma_zgetrs)(trans, n, nrhs, (T*)a, lda, ipiv, (T*)b, ldb, info);
150  }
151  }
152 
153  template<typename eT>
154  inline
155  void
156  lahqr(blas_int* wantt, blas_int* wantz, blas_int* n, blas_int* ilo, blas_int* ihi, eT* h, blas_int* ldh, eT* wr, eT* wi, blas_int* iloz, blas_int* ihiz, eT* z, blas_int* ldz, blas_int* info)
157  {
158  arma_type_check(( is_supported_blas_type<eT>::value == false ));
159  if(is_float<eT>::value == true)
160  {
161  typedef float T;
162  arma_fortran(arma_slahqr)(wantt, wantz, n, ilo, ihi, (T*)h, ldh, (T*)wr, (T*)wi, iloz, ihiz, (T*)z, ldz, info);
163  }
164  else
165  if(is_double<eT>::value == true)
166  {
167  typedef double T;
168  arma_fortran(arma_dlahqr)(wantt, wantz, n, ilo, ihi, (T*)h, ldh, (T*)wr, (T*)wi, iloz, ihiz, (T*)z, ldz, info);
169  }
170  }
171 
172  template<typename eT>
173  inline
174  void
175  stedc(char* compz, blas_int* n, eT* d, eT* e, eT* z, blas_int* ldz, eT* work, blas_int* lwork, blas_int* iwork, blas_int* liwork, blas_int* info)
176  {
177  arma_type_check(( is_supported_blas_type<eT>::value == false ));
178  if(is_float<eT>::value == true)
179  {
180  typedef float T;
181  arma_fortran(arma_sstedc)(compz, n, (T*)d, (T*)e, (T*)z, ldz, (T*)work, lwork, iwork, liwork, info);
182  }
183  else
184  if(is_double<eT>::value == true)
185  {
186  typedef double T;
187  arma_fortran(arma_dstedc)(compz, n, (T*)d, (T*)e, (T*)z, ldz, (T*)work, lwork, iwork, liwork, info);
188  }
189  }
190 
191  template<typename eT>
192  inline
193  void
194  trevc(char* side, char* howmny, blas_int* select, blas_int* n, eT* t, blas_int* ldt, eT* vl, blas_int* ldvl, eT* vr, blas_int* ldvr, blas_int* mm, blas_int* m, eT* work, blas_int* info)
195  {
196  arma_type_check(( is_supported_blas_type<eT>::value == false ));
197  if(is_float<eT>::value == true)
198  {
199  typedef float T;
200  arma_fortran(arma_strevc)(side, howmny, select, n, (T*)t, ldt, (T*)vl, ldvl, (T*)vr, ldvr, mm, m, (T*)work, info);
201  }
202  else
203  if(is_double<eT>::value == true)
204  {
205  typedef double T;
206  arma_fortran(arma_dtrevc)(side, howmny, select, n, (T*)t, ldt, (T*)vl, ldvl, (T*)vr, ldvr, mm, m, (T*)work, info);
207  }
208  }
209  }
210 
211 
212 
213  #endif // ARMA_USE_LAPACK
214 }
215 
216 
217 
218 #endif // LAPACK_WRAPPER_EXTRA_H