[775] | 1 | #ifndef IntfLapack_H_SEEN
|
---|
| 2 | #define IntfLapack_H_SEEN
|
---|
| 3 |
|
---|
| 4 | #include "machdefs.h"
|
---|
| 5 | #include "tarray.h"
|
---|
[2556] | 6 | #include "tvector.h"
|
---|
[775] | 7 |
|
---|
[814] | 8 | namespace SOPHYA {
|
---|
[775] | 9 |
|
---|
[814] | 10 | template <class T>
|
---|
| 11 | class LapackServer {
|
---|
| 12 | public:
|
---|
[1342] | 13 | LapackServer();
|
---|
| 14 | virtual ~LapackServer();
|
---|
| 15 |
|
---|
| 16 | virtual int LinSolve(TArray<T>& a, TArray<T> & b);
|
---|
[2554] | 17 | virtual int LinSolveSym(TArray<T>& a, TArray<T> & b);
|
---|
[1494] | 18 | virtual int LeastSquareSolve(TArray<T>& a, TArray<T> & b);
|
---|
[2567] | 19 | virtual int LeastSquareSolveSVD_DC(TMatrix<T>& a,TMatrix<T>& b,TVector<r_8>& s,int_4& rank,r_8 rcond=-1.);
|
---|
[1494] | 20 |
|
---|
[1342] | 21 | virtual int SVD(TArray<T>& a, TArray<T> & s);
|
---|
[2556] | 22 | virtual int SVD(TArray<T>& a, TArray<T> & s, TArray<T> & u, TArray<T> & vt);
|
---|
[2563] | 23 | virtual int SVD_DC(TMatrix<T>& a, TVector<r_8>& s, TMatrix<T>& u, TMatrix<T>& vt);
|
---|
[2556] | 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);
|
---|
[1342] | 27 |
|
---|
[1424] | 28 | //! Set the workspace size factor for LAPACK routines
|
---|
[1342] | 29 | inline void SetWorkSpaceSizeFactor(int f = 2)
|
---|
| 30 | { wspace_size_factor = (f > 1) ? f : 1; }
|
---|
[1424] | 31 |
|
---|
| 32 | //! Returns the workspace size factor
|
---|
[1342] | 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);
|
---|
[2554] | 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);
|
---|
[1342] | 40 |
|
---|
| 41 | int wspace_size_factor;
|
---|
[814] | 42 | };
|
---|
| 43 |
|
---|
[1424] | 44 | /*! \ingroup LinAlg
|
---|
| 45 | \fn LapackLinSolve(TArray<T>&, TArray<T> &)
|
---|
| 46 | \brief Solves the linear system A*X = B using LapackServer.
|
---|
| 47 | */
|
---|
[814] | 48 | template <class T>
|
---|
[1042] | 49 | inline int LapackLinSolve(TArray<T>& a, TArray<T> & b)
|
---|
[1342] | 50 | { LapackServer<T> lps; return( lps.LinSolve(a, b) ); }
|
---|
[814] | 51 |
|
---|
[1566] | 52 | /*! \ingroup LinAlg
|
---|
[2554] | 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
|
---|
[1566] | 61 | \fn LapackLeastSquareSolve(TArray<T>&, TArray<T> &)
|
---|
| 62 | \brief Solves the linear least squares problem A*X - B
|
---|
| 63 | */
|
---|
[1494] | 64 | template <class T>
|
---|
| 65 | inline int LapackLeastSquareSolve(TArray<T>& a, TArray<T> & b)
|
---|
| 66 | { LapackServer<T> lps; return( lps.LeastSquareSolve(a, b) ); }
|
---|
| 67 |
|
---|
[1424] | 68 | /*! \ingroup LinAlg
|
---|
[2567] | 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
|
---|
[1424] | 77 | \fn LapackSVD(TArray<T>&, TArray<T> &)
|
---|
| 78 | \brief SVD decomposition using LapackServer.
|
---|
| 79 | */
|
---|
[1342] | 80 | template <class T>
|
---|
| 81 | inline int LapackSVD(TArray<T>& a, TArray<T> & s)
|
---|
| 82 | { LapackServer<T> lps; return( lps.SVD(a, s) ); }
|
---|
[814] | 83 |
|
---|
[1424] | 84 |
|
---|
| 85 | /*! \ingroup LinAlg
|
---|
| 86 | \fn LapackSVD(TArray<T>&, TArray<T> &, TArray<T> &, TArray<T> &)
|
---|
| 87 | \brief SVD decomposition using LapackServer.
|
---|
| 88 | */
|
---|
[1342] | 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 |
|
---|
[2556] | 94 | /*! \ingroup LinAlg
|
---|
[2563] | 95 | \fn LapackSVD_DC(TMatrix<T>&, TVector<r_8>&, TMatrix<T>&, TMatrix<T>&)
|
---|
[2561] | 96 | \brief SVD decomposition DC using LapackServer.
|
---|
| 97 | */
|
---|
| 98 | template <class T>
|
---|
[2563] | 99 | inline int LapackSVD_DC(TMatrix<T>& a, TVector<r_8>& s, TMatrix<T>& u, TMatrix<T>& vt)
|
---|
[2561] | 100 | { LapackServer<T> lps; return( lps.SVD_DC(a, s, u, vt) ); }
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | /*! \ingroup LinAlg
|
---|
[2556] | 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 |
|
---|
[814] | 119 | } // Fin du namespace
|
---|
| 120 |
|
---|
[775] | 121 | #endif
|
---|