source: Sophya/trunk/SophyaExt/LinAlg/intflapack.h@ 2572

Last change on this file since 2572 was 2572, checked in by cmv, 21 years ago

implementation calcul lwork avec lwork=-1 cmv 28/07/04

File size: 4.1 KB
RevLine 
[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]8namespace SOPHYA {
[775]9
[814]10template <class T>
11class LapackServer {
12public:
[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
36private:
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);
[2572]40 int_4 type2i4(void *val,int nbytes);
[1342]41
42 int wspace_size_factor;
[814]43};
44
[1424]45/*! \ingroup LinAlg
46 \fn LapackLinSolve(TArray<T>&, TArray<T> &)
47 \brief Solves the linear system A*X = B using LapackServer.
48*/
[814]49template <class T>
[1042]50inline int LapackLinSolve(TArray<T>& a, TArray<T> & b)
[1342]51{ LapackServer<T> lps; return( lps.LinSolve(a, b) ); }
[814]52
[1566]53/*! \ingroup LinAlg
[2554]54 \fn LapackLinSolveSym(TArray<T>&, TArray<T> &)
55 \brief Solves the linear system A*X = B with A symetric using LapackServer.
56*/
57template <class T>
58inline int LapackLinSolveSym(TArray<T>& a, TArray<T> & b)
59{ LapackServer<T> lps; return( lps.LinSolveSym(a, b) ); }
60
61/*! \ingroup LinAlg
[1566]62 \fn LapackLeastSquareSolve(TArray<T>&, TArray<T> &)
63 \brief Solves the linear least squares problem A*X - B
64*/
[1494]65template <class T>
66inline int LapackLeastSquareSolve(TArray<T>& a, TArray<T> & b)
67{ LapackServer<T> lps; return( lps.LeastSquareSolve(a, b) ); }
68
[1424]69/*! \ingroup LinAlg
[2567]70 \fn LapackLeastSquareSolveSVD_DC
71 \brief Solves the linear least squares problem A*X = B by SVD
72*/
73template <class T>
74inline int LapackLeastSquareSolveSVD_DC(TMatrix<T>& a,TMatrix<T>& b,TVector<r_8>& s,int_4& rank,r_8 rcond=-1.)
75{ LapackServer<T> lps; return( lps.LeastSquareSolveSVD_DC(a,b,s,rank,rcond) ); }
76
77/*! \ingroup LinAlg
[1424]78 \fn LapackSVD(TArray<T>&, TArray<T> &)
79 \brief SVD decomposition using LapackServer.
80*/
[1342]81template <class T>
82inline int LapackSVD(TArray<T>& a, TArray<T> & s)
83{ LapackServer<T> lps; return( lps.SVD(a, s) ); }
[814]84
[1424]85
86/*! \ingroup LinAlg
87 \fn LapackSVD(TArray<T>&, TArray<T> &, TArray<T> &, TArray<T> &)
88 \brief SVD decomposition using LapackServer.
89*/
[1342]90template <class T>
91inline int LapackSVD(TArray<T>& a, TArray<T> & s, TArray<T> & u, TArray<T> & vt)
92{ LapackServer<T> lps; return( lps.SVD(a, s, u, vt) ); }
93
94
[2556]95/*! \ingroup LinAlg
[2563]96 \fn LapackSVD_DC(TMatrix<T>&, TVector<r_8>&, TMatrix<T>&, TMatrix<T>&)
[2561]97 \brief SVD decomposition DC using LapackServer.
98*/
99template <class T>
[2563]100inline int LapackSVD_DC(TMatrix<T>& a, TVector<r_8>& s, TMatrix<T>& u, TMatrix<T>& vt)
[2561]101{ LapackServer<T> lps; return( lps.SVD_DC(a, s, u, vt) ); }
102
103
104/*! \ingroup LinAlg
[2556]105 \fn LapackEigenSym(TArray<T>&, TArray<T> &)
106 \brief Compute the eigenvalues and eigenvectors of A (symetric or hermitian).
107*/
108template <class T>
109inline int LapackEigenSym(TArray<T>& a, TVector<r_8>& b, bool eigenvector=true)
110{ LapackServer<T> lps; return( lps.LapackEigenSym(a,b,eigenvector) ); }
111
112/*! \ingroup LinAlg
113 \fn LapackEigen(TArray<T>&, TArray<T> &)
114 \brief Compute the eigenvalues and (right) eigenvectors of A (general square matrix).
115*/
116template <class T>
117inline int LapackEigen(TArray<T>& a, TVector< complex<r_8> >& eval, TMatrix<T>& evec, bool eigenvector=true)
118{ LapackServer<T> lps; return( lps.LapackEigen(a,eval,evec,eigenvector) ); }
119
[814]120} // Fin du namespace
121
[775]122#endif
Note: See TracBrowser for help on using the repository browser.