1 | #ifndef IntfLapack_H_SEEN
|
---|
2 | #define IntfLapack_H_SEEN
|
---|
3 |
|
---|
4 | #include "machdefs.h"
|
---|
5 | #include "tarray.h"
|
---|
6 | #include "tvector.h"
|
---|
7 |
|
---|
8 | namespace SOPHYA {
|
---|
9 |
|
---|
10 | template <class T>
|
---|
11 | class LapackServer {
|
---|
12 | public:
|
---|
13 | LapackServer();
|
---|
14 | virtual ~LapackServer();
|
---|
15 |
|
---|
16 | virtual int LinSolve(TArray<T>& a, TArray<T> & b);
|
---|
17 | virtual int LinSolveSym(TArray<T>& a, TArray<T> & b);
|
---|
18 | virtual int LeastSquareSolve(TArray<T>& a, TArray<T> & b);
|
---|
19 | virtual int LeastSquareSolveSVD_DC(TMatrix<T>& a,TMatrix<T>& b,TVector<r_8>& s,int_4& rank,r_8 rcond=-1.);
|
---|
20 |
|
---|
21 | virtual int SVD(TArray<T>& a, TArray<T> & s);
|
---|
22 | virtual int SVD(TArray<T>& a, TArray<T> & s, TArray<T> & u, TArray<T> & vt);
|
---|
23 | virtual int SVD_DC(TMatrix<T>& a, TVector<r_8>& s, TMatrix<T>& u, TMatrix<T>& vt);
|
---|
24 |
|
---|
25 | virtual int LapackEigenSym(TArray<T>& a, TVector<r_8>& b, bool eigenvector=true);
|
---|
26 | virtual int LapackEigen(TArray<T>& a, TVector< complex<r_8> >& eval, TMatrix<T>& evec, bool eigenvector);
|
---|
27 |
|
---|
28 | //! Set the workspace size factor for LAPACK routines
|
---|
29 | inline void SetWorkSpaceSizeFactor(int f = 2)
|
---|
30 | { wspace_size_factor = (f > 1) ? f : 1; }
|
---|
31 |
|
---|
32 | //! Returns the workspace size factor
|
---|
33 | inline int GetWorkSpaceSizeFactor()
|
---|
34 | { return wspace_size_factor; }
|
---|
35 |
|
---|
36 | private:
|
---|
37 | int SVDDriver(TArray<T>& a, TArray<T> & s,
|
---|
38 | TArray<T>* up=NULL, TArray<T> * vtp=NULL);
|
---|
39 | int_4 ilaenv_en_C(int_4 ispec,char *name,char *opts,int_4 n1,int_4 n2,int_4 n3,int_4 n4);
|
---|
40 |
|
---|
41 | int wspace_size_factor;
|
---|
42 | };
|
---|
43 |
|
---|
44 | /*! \ingroup LinAlg
|
---|
45 | \fn LapackLinSolve(TArray<T>&, TArray<T> &)
|
---|
46 | \brief Solves the linear system A*X = B using LapackServer.
|
---|
47 | */
|
---|
48 | template <class T>
|
---|
49 | inline int LapackLinSolve(TArray<T>& a, TArray<T> & b)
|
---|
50 | { LapackServer<T> lps; return( lps.LinSolve(a, b) ); }
|
---|
51 |
|
---|
52 | /*! \ingroup LinAlg
|
---|
53 | \fn LapackLinSolveSym(TArray<T>&, TArray<T> &)
|
---|
54 | \brief Solves the linear system A*X = B with A symetric using LapackServer.
|
---|
55 | */
|
---|
56 | template <class T>
|
---|
57 | inline int LapackLinSolveSym(TArray<T>& a, TArray<T> & b)
|
---|
58 | { LapackServer<T> lps; return( lps.LinSolveSym(a, b) ); }
|
---|
59 |
|
---|
60 | /*! \ingroup LinAlg
|
---|
61 | \fn LapackLeastSquareSolve(TArray<T>&, TArray<T> &)
|
---|
62 | \brief Solves the linear least squares problem A*X - B
|
---|
63 | */
|
---|
64 | template <class T>
|
---|
65 | inline int LapackLeastSquareSolve(TArray<T>& a, TArray<T> & b)
|
---|
66 | { LapackServer<T> lps; return( lps.LeastSquareSolve(a, b) ); }
|
---|
67 |
|
---|
68 | /*! \ingroup LinAlg
|
---|
69 | \fn LapackLeastSquareSolveSVD_DC
|
---|
70 | \brief Solves the linear least squares problem A*X = B by SVD
|
---|
71 | */
|
---|
72 | template <class T>
|
---|
73 | inline int LapackLeastSquareSolveSVD_DC(TMatrix<T>& a,TMatrix<T>& b,TVector<r_8>& s,int_4& rank,r_8 rcond=-1.)
|
---|
74 | { LapackServer<T> lps; return( lps.LeastSquareSolveSVD_DC(a,b,s,rank,rcond) ); }
|
---|
75 |
|
---|
76 | /*! \ingroup LinAlg
|
---|
77 | \fn LapackSVD(TArray<T>&, TArray<T> &)
|
---|
78 | \brief SVD decomposition using LapackServer.
|
---|
79 | */
|
---|
80 | template <class T>
|
---|
81 | inline int LapackSVD(TArray<T>& a, TArray<T> & s)
|
---|
82 | { LapackServer<T> lps; return( lps.SVD(a, s) ); }
|
---|
83 |
|
---|
84 |
|
---|
85 | /*! \ingroup LinAlg
|
---|
86 | \fn LapackSVD(TArray<T>&, TArray<T> &, TArray<T> &, TArray<T> &)
|
---|
87 | \brief SVD decomposition using LapackServer.
|
---|
88 | */
|
---|
89 | template <class T>
|
---|
90 | inline int LapackSVD(TArray<T>& a, TArray<T> & s, TArray<T> & u, TArray<T> & vt)
|
---|
91 | { LapackServer<T> lps; return( lps.SVD(a, s, u, vt) ); }
|
---|
92 |
|
---|
93 |
|
---|
94 | /*! \ingroup LinAlg
|
---|
95 | \fn LapackSVD_DC(TMatrix<T>&, TVector<r_8>&, TMatrix<T>&, TMatrix<T>&)
|
---|
96 | \brief SVD decomposition DC using LapackServer.
|
---|
97 | */
|
---|
98 | template <class T>
|
---|
99 | inline int LapackSVD_DC(TMatrix<T>& a, TVector<r_8>& s, TMatrix<T>& u, TMatrix<T>& vt)
|
---|
100 | { LapackServer<T> lps; return( lps.SVD_DC(a, s, u, vt) ); }
|
---|
101 |
|
---|
102 |
|
---|
103 | /*! \ingroup LinAlg
|
---|
104 | \fn LapackEigenSym(TArray<T>&, TArray<T> &)
|
---|
105 | \brief Compute the eigenvalues and eigenvectors of A (symetric or hermitian).
|
---|
106 | */
|
---|
107 | template <class T>
|
---|
108 | inline int LapackEigenSym(TArray<T>& a, TVector<r_8>& b, bool eigenvector=true)
|
---|
109 | { LapackServer<T> lps; return( lps.LapackEigenSym(a,b,eigenvector) ); }
|
---|
110 |
|
---|
111 | /*! \ingroup LinAlg
|
---|
112 | \fn LapackEigen(TArray<T>&, TArray<T> &)
|
---|
113 | \brief Compute the eigenvalues and (right) eigenvectors of A (general square matrix).
|
---|
114 | */
|
---|
115 | template <class T>
|
---|
116 | inline int LapackEigen(TArray<T>& a, TVector< complex<r_8> >& eval, TMatrix<T>& evec, bool eigenvector=true)
|
---|
117 | { LapackServer<T> lps; return( lps.LapackEigen(a,eval,evec,eigenvector) ); }
|
---|
118 |
|
---|
119 | } // Fin du namespace
|
---|
120 |
|
---|
121 | #endif
|
---|