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