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
Line 
1#ifndef IntfLapack_H_SEEN
2#define IntfLapack_H_SEEN
3
4#include "machdefs.h"
5#include "tarray.h"
6#include "tvector.h"
7
8namespace SOPHYA {
9
10template <class T>
11class LapackServer {
12public:
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
36private:
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 int_4 type2i4(void *val,int nbytes);
41
42 int wspace_size_factor;
43};
44
45/*! \ingroup LinAlg
46 \fn LapackLinSolve(TArray<T>&, TArray<T> &)
47 \brief Solves the linear system A*X = B using LapackServer.
48*/
49template <class T>
50inline int LapackLinSolve(TArray<T>& a, TArray<T> & b)
51{ LapackServer<T> lps; return( lps.LinSolve(a, b) ); }
52
53/*! \ingroup LinAlg
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
62 \fn LapackLeastSquareSolve(TArray<T>&, TArray<T> &)
63 \brief Solves the linear least squares problem A*X - B
64*/
65template <class T>
66inline int LapackLeastSquareSolve(TArray<T>& a, TArray<T> & b)
67{ LapackServer<T> lps; return( lps.LeastSquareSolve(a, b) ); }
68
69/*! \ingroup LinAlg
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
78 \fn LapackSVD(TArray<T>&, TArray<T> &)
79 \brief SVD decomposition using LapackServer.
80*/
81template <class T>
82inline int LapackSVD(TArray<T>& a, TArray<T> & s)
83{ LapackServer<T> lps; return( lps.SVD(a, s) ); }
84
85
86/*! \ingroup LinAlg
87 \fn LapackSVD(TArray<T>&, TArray<T> &, TArray<T> &, TArray<T> &)
88 \brief SVD decomposition using LapackServer.
89*/
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
95/*! \ingroup LinAlg
96 \fn LapackSVD_DC(TMatrix<T>&, TVector<r_8>&, TMatrix<T>&, TMatrix<T>&)
97 \brief SVD decomposition DC using LapackServer.
98*/
99template <class T>
100inline int LapackSVD_DC(TMatrix<T>& a, TVector<r_8>& s, TMatrix<T>& u, TMatrix<T>& vt)
101{ LapackServer<T> lps; return( lps.SVD_DC(a, s, u, vt) ); }
102
103
104/*! \ingroup LinAlg
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
120} // Fin du namespace
121
122#endif
Note: See TracBrowser for help on using the repository browser.