npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
lapack_interface.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_LAPACK_INTERFACE_HH_
2 #define NPSTAT_LAPACK_INTERFACE_HH_
3 
4 /*!
5 // \file lapack_interface.hh
6 //
7 // \brief Template interface to LAPACK (in its original F77 implementation)
8 //
9 // Typically, generic templates will throw an appropriate exception,
10 // while templates specialized for float, double, etc. will perform
11 // the requested calculations via corresponding LAPACK routines.
12 //
13 // This code is rather low-level. It may be more convenient to use
14 // the API provided by the Matrix class which will eventually call
15 // appropriate LAPACK interface functions from here.
16 //
17 // Author: I. Volobouev
18 //
19 // September 2010
20 */
21 
23 
24 namespace npstat {
25  /**
26  // Invert a positive definite symmetric matrix
27  // (LAPACK DPOTRF/DPOTRI routines are used for doubles)
28  */
29  template<typename Numeric>
30  void invert_posdef_sym_matrix(const Numeric* in, unsigned dim,
31  Numeric* out);
32 
33  /**
34  // Invert a symmetric matrix
35  // (LAPACK DSYTRF/DSYTRI routines are used for doubles)
36  */
37  template<typename Numeric>
38  void invert_sym_matrix(const Numeric* in, unsigned dim, Numeric* out);
39 
40  /**
41  // Invert a tridiagonal matrix
42  // (LAPACK routines DGTSV/SGTSV are used for doubles)
43  */
44  template<typename Numeric>
45  void invert_td_matrix(const Numeric* in, unsigned dim, Numeric* out);
46 
47  /**
48  // Invert a general matrix
49  // (LAPACK DGETRF/DGETRI routines are used for doubles)
50  */
51  template<typename Numeric>
52  void invert_general_matrix(const Numeric* in, unsigned dim, Numeric* out);
53 
54  /**
55  // Determine eigenvalues of a general matrix
56  // (LAPACK DGEEV routine is used for doubles)
57  */
58  template<typename Numeric>
59  void gen_matrix_eigenvalues(const Numeric* in, unsigned dim,
60  typename GeneralizedComplex<Numeric>::type
61  *eigenvalues);
62 
63  /**
64  // Determine eigenvalues of a symmetric matrix
65  // (LAPACK DSYEV routine is used for doubles)
66  */
67  template<typename Numeric>
68  void sym_matrix_eigenvalues(const Numeric* in, unsigned dim,
69  Numeric* eigenvalues);
70 
71  template<typename Numeric>
72  void td_sym_matrix_eigenvalues(const Numeric* in, unsigned dim,
73  Numeric* eigenvalues);
74 
75  /**
76  // Determine eigenvalues of a symmetric matrix using the divide
77  // and conquer LAPACK driver (DSYEVD routine is used for doubles)
78  */
79  template<typename Numeric>
80  void sym_matrix_eigenvalues_dc(const Numeric* in, unsigned dim,
81  Numeric* eigenvalues);
82 
83  template<typename Numeric>
84  void td_sym_matrix_eigenvalues_dc(const Numeric* in, unsigned dim,
85  Numeric* eigenvalues);
86 
87  /**
88  // Determine eigenvalues of a symmetric matrix using the
89  // "Relatively Robust Representations" (RRR) LAPACK driver
90  // (DSYEVR routine is used for doubles)
91  */
92  template<typename Numeric>
93  void sym_matrix_eigenvalues_rrr(const Numeric* in, unsigned dim,
94  Numeric* eigenvalues);
95 
96  /**
97  // Determine eigenvalues of a symmetric tridiagonal matrix using
98  // the "Relatively Robust Representations" (RRR) LAPACK driver
99  // (DSTEVR routine is used for doubles)
100  */
101  template<typename Numeric>
102  void td_sym_matrix_eigenvalues_rrr(const Numeric* in, unsigned dim,
103  Numeric* eigenvalues);
104 
105  /**
106  // Determine eigenvalues and eigenvectors of a general matrix
107  // (LAPACK DGEEV routine is used for doubles)
108  */
109  template<typename Numeric>
110  void gen_matrix_eigensystem(const Numeric* in, unsigned dim,
111  typename GeneralizedComplex<Numeric>::type *ev,
112  Numeric* rightEigenvectors,
113  Numeric* leftEigenvectors);
114 
115  /**
116  // Determine eigenvalues and eigenvectors of a symmetric matrix
117  // (LAPACK DSYEV routine is used for doubles)
118  */
119  template<typename Numeric>
120  void sym_matrix_eigensystem(const Numeric* in, unsigned dim,
121  Numeric* eigenvalues,
122  Numeric* eigenvectors);
123 
124  template<typename Numeric>
125  void td_sym_matrix_eigensystem(const Numeric* in, unsigned dim,
126  Numeric* eigenvalues,
127  Numeric* eigenvectors);
128 
129  /**
130  // Determine eigenvalues and eigenvectors of a symmetric matrix
131  // using the divide and conquer LAPACK driver (DSYEVD routine
132  // is used for doubles)
133  */
134  template<typename Numeric>
135  void sym_matrix_eigensystem_dc(const Numeric* in, unsigned dim,
136  Numeric* eigenvalues,
137  Numeric* eigenvectors);
138 
139  template<typename Numeric>
140  void td_sym_matrix_eigensystem_dc(const Numeric* in, unsigned dim,
141  Numeric* eigenvalues,
142  Numeric* eigenvectors);
143 
144  /**
145  // Determine eigenvalues and eigenvectors of a symmetric matrix
146  // using the "Relatively Robust Representations" (RRR) LAPACK
147  // driver (DSYEVR routine is used for doubles)
148  */
149  template<typename Numeric>
150  void sym_matrix_eigensystem_rrr(const Numeric* in, unsigned dim,
151  Numeric* eigenvalues,
152  Numeric* eigenvectors);
153 
154  template<typename Numeric>
155  void td_sym_matrix_eigensystem_rrr(const Numeric* in, unsigned dim,
156  Numeric* eigenvalues,
157  Numeric* eigenvectors);
158 
159  /**
160  // Solve a linear system (LAPACK DGETRF/DGETRS routines are used
161  // for doubles). This function returns "true" on success or "false"
162  // in case the matrix is degenerate.
163  */
164  template<typename Numeric>
165  bool solve_linear_system(const Numeric* in, unsigned dim,
166  const Numeric* rhs, Numeric* solution);
167 
168  /**
169  // Solve multiple linear systems (LAPACK DGETRF/DGETRS routines are
170  // used for doubles). This function returns "true" on success or "false"
171  // in case the matrix is degenerate.
172  */
173  template<typename Numeric>
174  bool solve_linear_systems(const Numeric* in, unsigned nrows,
175  unsigned ncols, const Numeric* rhs,
176  Numeric* solution);
177 
178  /**
179  // Solve an overdetermined linear system in the least squares sense
180  // (DGELSD is used for doubles). This function returns "true" on
181  // success or "false" on failure.
182  */
183  template<typename Numeric>
184  bool linear_least_squares(const Numeric* mat, unsigned nrows,
185  unsigned ncols, const Numeric* rhs,
186  Numeric* solution);
187 
188  /**
189  // Constrained least squares problem (DGGLSE is used for doubles).
190  // "true" is returned on success and "false" on failure.
191  */
192  template<typename Numeric>
193  bool constrained_least_squares(const Numeric* mat, unsigned nrows,
194  unsigned ncols, const Numeric* rhs,
195  const Numeric* constraintMatrix,
196  unsigned constrRows, unsigned constrCols,
197  const Numeric* constrRhs, Numeric* solution);
198 
199  /**
200  // Singular value decomposition (by DGESVD, etc) of M x N matrix.
201  // This function returns "true" on success or "false" on failure.
202  */
203  template<typename Numeric>
204  bool gen_matrix_svd(const Numeric* in, unsigned M, unsigned N,
205  Numeric* U, Numeric* singularValues, Numeric* VT);
206 
207  /**
208  // Divide and conquer SVD (by DGESDD, etc) of M x N matrix.
209  // This function returns "true" on success or "false" on failure.
210  */
211  template<typename Numeric>
212  bool gen_matrix_svd_dc(const Numeric* in, unsigned M, unsigned N,
213  Numeric* U, Numeric* singularValues, Numeric* VT);
214 
215  namespace Private {
216  int lapack_nlvl_dgelsd(int dim);
217  int lapack_nlvl_sgelsd(int dim);
218  }
219 }
220 
221 #include "npstat/nm/lapack_interface.icc"
222 
223 #endif // NPSTAT_LAPACK_INTERFACE_HH_
Typedef complex type if it makes sense (parameter is real); otherwise typedef the original type.
Definition: AbsArrayProjector.hh:14
bool linear_least_squares(const Numeric *mat, unsigned nrows, unsigned ncols, const Numeric *rhs, Numeric *solution)
bool solve_linear_system(const Numeric *in, unsigned dim, const Numeric *rhs, Numeric *solution)
void td_sym_matrix_eigenvalues_rrr(const Numeric *in, unsigned dim, Numeric *eigenvalues)
bool gen_matrix_svd_dc(const Numeric *in, unsigned M, unsigned N, Numeric *U, Numeric *singularValues, Numeric *VT)
void gen_matrix_eigensystem(const Numeric *in, unsigned dim, typename GeneralizedComplex< Numeric >::type *ev, Numeric *rightEigenvectors, Numeric *leftEigenvectors)
void sym_matrix_eigensystem(const Numeric *in, unsigned dim, Numeric *eigenvalues, Numeric *eigenvectors)
void sym_matrix_eigensystem_dc(const Numeric *in, unsigned dim, Numeric *eigenvalues, Numeric *eigenvectors)
void sym_matrix_eigensystem_rrr(const Numeric *in, unsigned dim, Numeric *eigenvalues, Numeric *eigenvectors)
bool constrained_least_squares(const Numeric *mat, unsigned nrows, unsigned ncols, const Numeric *rhs, const Numeric *constraintMatrix, unsigned constrRows, unsigned constrCols, const Numeric *constrRhs, Numeric *solution)
void invert_sym_matrix(const Numeric *in, unsigned dim, Numeric *out)
void sym_matrix_eigenvalues_rrr(const Numeric *in, unsigned dim, Numeric *eigenvalues)
void sym_matrix_eigenvalues(const Numeric *in, unsigned dim, Numeric *eigenvalues)
void invert_general_matrix(const Numeric *in, unsigned dim, Numeric *out)
void gen_matrix_eigenvalues(const Numeric *in, unsigned dim, typename GeneralizedComplex< Numeric >::type *eigenvalues)
bool gen_matrix_svd(const Numeric *in, unsigned M, unsigned N, Numeric *U, Numeric *singularValues, Numeric *VT)
bool solve_linear_systems(const Numeric *in, unsigned nrows, unsigned ncols, const Numeric *rhs, Numeric *solution)
void sym_matrix_eigenvalues_dc(const Numeric *in, unsigned dim, Numeric *eigenvalues)
void invert_posdef_sym_matrix(const Numeric *in, unsigned dim, Numeric *out)
void invert_td_matrix(const Numeric *in, unsigned dim, Numeric *out)