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