STK++ 0.9.13
STK::lapack::SymEigen< SquareArray > Class Template Reference

{ More...

#include <STK_lapack_SymEigen.h>

Inheritance diagram for STK::lapack::SymEigen< SquareArray >:
Inheritance graph

Public Types

typedef ISymEigen< SymEigen< SquareArray > > Base
 

Public Member Functions

 SymEigen ()
 Default Constructor.
 
 SymEigen (SquareArray const &data, bool ref=false)
 Constructor.
 
template<class Derived >
 SymEigen (ArrayBase< Derived > const &data)
 Constructor.
 
 SymEigen (SymEigen const &eigen)
 copy constructor
 
virtual ~SymEigen ()
 Destructor.
 
void setJobz (char jobz)
 
void setRange (char range)
 
void setUplo (char uplo)
 
void setVlAndVu (Real const &vl, Real const &vu)
 
void setIlAndIu (int il, int iu)
 
virtual SymEigenclone () const
 clone pattern
 
bool runImpl ()
 Run eigenvalues decomposition Launch SYEVR LAPACK routine to perform the eigenvalues decomposition.
 
 SymEigen (CSquareX const &data, bool ref)
 
- Public Member Functions inherited from STK::ISymEigen< SymEigen< SquareArray > >
 ~ISymEigen ()
 virtual destructor
 
ISymEigenoperator= (ISymEigen const &eigen)
 Operator = : overwrite the ISymEigen with eigen.
 
Range constrange () const
 
Type constnorm () const
 
int constrank () const
 
Type constdet () const
 
Type consttrace () const
 
CArraySquare< Type, size_ > constrotation () const
 
CArraySquare< Type, size_ > consteigenVectors () const
 
CArrayVector< Type, size_ > consteigenValues () const
 
void setData (ExprBase< OtherDerived > const &data)
 overloading of setData.
 
ArraySquareginv (ArraySquare &res) const
 Compute the generalized inverse of the symmetric matrix and put the result in res.
 
ArraySquareginvsqrt (ArraySquare &res) const
 Compute the generalized square root inverse of the symmetric matrix and put the result in res.
 
ArraySquaregsqrt (ArraySquare &res) const
 Compute the square root of the symmetric matrix and put the result in res.
 
virtual bool run ()
 Find the eigenvalues and eigenvectors of the matrix.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Private Attributes

char jobz_
 Lapack pptions.
 
char RANGE_
 
char UPLO_
 
Real VL_
 
Real VU_
 
int IL_
 
int IU_
 

Additional Inherited Members

- Protected Types inherited from STK::ISymEigen< SymEigen< SquareArray > >
enum  
 
typedef IRunnerBase Base
 
typedef hidden::AlgebraTraits< SymEigen< SquareArray > >::SquareArray SquareArray
 
typedef hidden::Traits< SquareArray >::Type Type
 
- Protected Member Functions inherited from STK::ISymEigen< SymEigen< SquareArray > >
 ISymEigen ()
 Default constructor.
 
 ISymEigen (SquareArray const &data, bool ref=false)
 Constructor The original data set can be overwritten by the eigenvectors if it is stored in a CSquareXd.
 
 ISymEigen (ExprBase< OtherDerived > const &data)
 template constructor
 
 ISymEigen (ISymEigen const &eigen)
 Copy constructor.
 
void finalizeStep ()
 finalize the computation by computing the trace, rank, trace norm and determinant of the matrix.
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 
- Protected Attributes inherited from STK::ISymEigen< SymEigen< SquareArray > >
Range range_
 range of the original data set.
 
Type trace_
 trace norm
 
Type norm_
 trace norm
 
int rank_
 rank
 
Type det_
 determinant
 
CArraySquare< Type, size_ > eigenVectors_
 Square matrix or the eigenvectors.
 
CArrayVector< Type, size_ > eigenValues_
 Array of the eigenvalues.
 
CVectorXi SupportEigenVectors_
 Array for the support of the eigenvectors.
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

template<class SquareArray>
class STK::lapack::SymEigen< SquareArray >

{

SymEigen computes the eigenvalues and optionally the eigenvectors of a symmetric real matrix using the syevr Lapack routine.

The decomposition of a symmetric matrix require

  • Input: A symmetric matrix A of size (n,n)
  • Output:
    1. P Array of size (n,n).
    2. D Vector of dimension n
    3. $ A = PDP' $ The matrix A can be copied or overwritten by the class.

The 2-norm (operator norm) of the matrix is given. if the 2-norm is less than the arithmetic precision of the type Real, the rank is not full. Thus the user can be faced with a deficient rank matrix and with a norm and a determinant very small (but not exactly 0.0).

Note
Default values for syevr lapack parameters are
See also
STK::ISymEigen, STK::SymEigen

Definition at line 97 of file STK_lapack_SymEigen.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ SymEigen() [1/5]

template<class SquareArray >
STK::lapack::SymEigen< SquareArray >::SymEigen ( )

Default Constructor.

Definition at line 182 of file STK_lapack_SymEigen.h.

182 : Base()
183 , jobz_('V'), RANGE_('A'), UPLO_('U')
184 , VL_(0.0), VU_(0.0), IL_(0), IU_(0)
185{}
ISymEigen< SymEigen< SquareArray > > Base

Referenced by STK::lapack::SymEigen< SquareArray >::clone().

◆ SymEigen() [2/5]

template<class SquareArray >
STK::lapack::SymEigen< SquareArray >::SymEigen ( SquareArray const data,
bool  ref = false 
)

Constructor.

Parameters
datareference on a symmetric square matrix
reftrue if we overwrite the data set, false otherwise
Note
data can be a reference if and only if it is a CSquareX
Default values for syevr lapack parameters are
jobz_ = 'V'; RANGE_ = 'A'; UPLO_ = 'U';
VL_ = 0.0; VU_ = 0.0; IL_ = 0; IU_ = 0;

Definition at line 191 of file STK_lapack_SymEigen.h.

192 : Base(data)
193 , jobz_('V'), RANGE_('A'), UPLO_('U')
194 , VL_(0.0), VU_(0.0), IL_(0), IU_(0)
195{}

◆ SymEigen() [3/5]

template<class SquareArray >
template<class Derived >
STK::lapack::SymEigen< SquareArray >::SymEigen ( ArrayBase< Derived > const data)

Constructor.

Parameters
datareference on a symmetric square expression

Definition at line 209 of file STK_lapack_SymEigen.h.

210 : Base(data)
211 , jobz_('V'), RANGE_('A'), UPLO_('U')
212 , VL_(0.0), VU_(0.0), IL_(0), IU_(0)
213{}

◆ SymEigen() [4/5]

template<class SquareArray >
STK::lapack::SymEigen< SquareArray >::SymEigen ( SymEigen< SquareArray > const eigen)

copy constructor

Parameters
eigenthe SymEigen to copy

Definition at line 218 of file STK_lapack_SymEigen.h.

219 : Base(eigen)
220 , jobz_(eigen.jobz_), RANGE_(eigen.RANGE_), UPLO_(eigen.UPLO_)
221 , VL_(eigen.VL_), VU_(eigen.VU_), IL_(eigen.IL_), IU_(eigen.IU_)
222 {}

◆ ~SymEigen()

Destructor.

Definition at line 131 of file STK_lapack_SymEigen.h.

131{}

◆ SymEigen() [5/5]

STK::lapack::SymEigen< CSquareX >::SymEigen ( CSquareX const data,
bool  ref 
)
inline

Definition at line 201 of file STK_lapack_SymEigen.h.

202 : Base(data, ref)
203 , jobz_('V'), RANGE_('A'), UPLO_('U')
204 , VL_(0.0), VU_(0.0), IL_(0), IU_(0)
205{}

Member Function Documentation

◆ clone()

template<class SquareArray >
virtual SymEigen * STK::lapack::SymEigen< SquareArray >::clone ( ) const
inlinevirtual

clone pattern

Definition at line 163 of file STK_lapack_SymEigen.h.

163{ return new SymEigen(*this);}
SymEigen()
Default Constructor.

References STK::lapack::SymEigen< SquareArray >::SymEigen().

◆ runImpl()

Run eigenvalues decomposition Launch SYEVR LAPACK routine to perform the eigenvalues decomposition.

Returns
true if no error occur, false otherwise

Definition at line 229 of file STK_lapack_SymEigen.h.

230{
231#ifdef STK_ALGEBRA_VERY_VERBOSE
232 stk_cout << _T("Enter in SymEigen::run\n");
233#endif
234 /* copy square matrix with the original data set. */
235 CSquareX data_ = eigenVectors_;
236 // shift data sets
237 data_.shift(0);
241 /* set default behavior */
242 Real absTol = 0.0; // let Lapack chose the correct tolerance
243 // get optimal size necessary for work
244 Real work; // work is just one place, get the optimal size for work
245 // iwork is just on place, get the optimal size for iWork
246 int iwork, lWork =-1, liwork =-1; // workspace variable
247
248 int info = 1;
249#ifdef STK_ALGEBRA_DEBUG
250 stk_cout << _T("Data dimensions: ") << data_.rows() << " " << data_.cols() << "\n";
251 stk_cout << _T("eigenValues_ dimensions: ") << eigenValues_.rows() << " " << eigenValues_.cols() << "\n";
252 stk_cout << _T("eigenVectors_ dimensions: ") << eigenVectors_.rows() << " " << eigenVectors_.cols() << "\n";
253 stk_cout << _T("Options: ") << jobz_ << " " << RANGE_ << " " << UPLO_ << "\n";
254#endif
255 info = syevr( jobz_, RANGE_, UPLO_
256 , range_.size(), data_.p_data(), range_.size()
257 , VL_, VU_, IL_, IU_
258 , absTol, &rank_, eigenValues_.p_data()
259 , eigenVectors_.p_data(), range_.size(), this->SupportEigenVectors_.p_data()
260 , &work, lWork, &iwork, liwork);
261 // check any error
262 if (info!=0)
263 {
264 if (info>0)
265 { this->msg_error_ = STKERROR_NO_ARG(SymEigen::run,internal error);
266 return false;
267 }
268 this->msg_error_= STKERROR_1ARG(SymEigen::run,-info,error parameter);
269 return false;
270 }
271#ifdef STK_ALGEBRA_DEBUG
272 stk_cout << _T("Size needed:") << (int)work << " " << iwork << " " << "\n";
273#endif
274 // get results and allocate space
275 lWork = (int)work;
276 liwork = iwork;
277 Real* p_work = new Real[lWork];
278 int* p_iwork = new int[liwork];
279
280 // Call SYEVR with the optimal block size
281 info = syevr( jobz_, RANGE_, UPLO_
282 , range_.size(), data_.p_data(), range_.size()
283 , VL_, VU_, IL_, IU_
284 , absTol, &rank_, eigenValues_.p_data()
285 , eigenVectors_.p_data(), range_.size(), this->SupportEigenVectors_.p_data()
286 , p_work, lWork, p_iwork, liwork);
287 // recover memory
288 delete[] p_work;
289 delete[] p_iwork;
290
291 // finalize
292 data_.shift(range_.begin());
296 this->finalizeStep();
297 this->hasRun_ = true;
298 // return the result of the computation
299 if (!info) return true;
300 if (info>0)
301 { this->msg_error_ = STKERROR_NO_ARG(SymEigen::run,internal error);
302 return false;
303 }
304 this->msg_error_= STKERROR_1ARG(SymEigen::run,-info,error parameter);
305 return false;
306}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define STKERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:61
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Derived & shift(int beginRows, int beginCols)
shift the Array.
Type *const & p_data() const
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
virtual bool run()=0
run the computations.
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
void finalizeStep()
finalize the computation by computing the trace, rank, trace norm and determinant of the matrix.
Range range_
range of the original data set.
CArrayVector< Type, size_ > eigenValues_
Array of the eigenvalues.
CArraySquare< Type, size_ > eigenVectors_
Square matrix or the eigenvectors.
CVectorXi SupportEigenVectors_
Array for the support of the eigenvectors.
int begin() const
get the first index of the TRange.
Definition STK_Range.h:93
int size() const
get the size of the TRange (the number of elements).
Definition STK_Range.h:303
int syevr(char jobz, char range, char uplo, int n, Real *a, int lda, Real vl, Real vu, int il, int iu, Real abstol, int *m, Real *w, Real *z, int ldz, int *isuppz, Real *work, int lWork, int *iwork, int liwork)
wrapper of the LAPACK SYEVR routine.
double Real
STK fundamental type of Real values.
CArraySquare< Real, UnknownSize, Arrays::by_col_ > CSquareX

References _T, STK::ICArray< Derived >::p_data(), STK::IRunnerBase::run(), STK::ICArray< Derived >::shift(), stk_cout, STKERROR_1ARG, STKERROR_NO_ARG, and STK::lapack::syevr().

◆ setIlAndIu()

template<class SquareArray >
void STK::lapack::SymEigen< SquareArray >::setIlAndIu ( int  il,
int  iu 
)
inline
Parameters
il,iuIf RANGE_='I', the indices (in ascending order) of the smallest and largest eigenvalues to be returned. 1 <= IL_ <= IU_ <= NL, if NL > 0; IL_ = 1 and IU_ = 0 if NL = 0. Not referenced if RANGE_ = 'A' or 'V'.

Definition at line 160 of file STK_lapack_SymEigen.h.

160{ IL_ = il; IU_ = iu;}

References STK::lapack::SymEigen< SquareArray >::IL_, and STK::lapack::SymEigen< SquareArray >::IU_.

◆ setJobz()

template<class SquareArray >
void STK::lapack::SymEigen< SquareArray >::setJobz ( char  jobz)
inline
Parameters
jobzIf jobz ='N': Compute eigenvalues only; If jobz = 'V': Compute eigenvalues and eigenvectors.

Definition at line 137 of file STK_lapack_SymEigen.h.

137{ jobz_ = jobz;}

References STK::lapack::SymEigen< SquareArray >::jobz_.

◆ setRange()

template<class SquareArray >
void STK::lapack::SymEigen< SquareArray >::setRange ( char  range)
inline
Parameters
rangerange of the eigenvalues to be found. If range = 'A': all eigenvalues will be found. If range = 'V': all eigenvalues in the half-open interval (VL_,VU_] will be found. If range = 'I': the IL_-th through IU_-th eigenvalues will be found.

Definition at line 143 of file STK_lapack_SymEigen.h.

References STK::ISymEigen< SymEigen< SquareArray > >::range(), and STK::lapack::SymEigen< SquareArray >::RANGE_.

◆ setUplo()

template<class SquareArray >
void STK::lapack::SymEigen< SquareArray >::setUplo ( char  uplo)
inline
Parameters
uplovalues to used in A. If uplo = 'U': Upper triangle of A is stored; If uplo = 'L': Lower triangle of A is stored.

Definition at line 148 of file STK_lapack_SymEigen.h.

148{ UPLO_ = uplo;}

References STK::lapack::SymEigen< SquareArray >::UPLO_.

Referenced by STK::hidden::InvertLowerSymMatrixImpl< Matrix, Size_ >::invertLowerSymMatrixXX().

◆ setVlAndVu()

template<class SquareArray >
void STK::lapack::SymEigen< SquareArray >::setVlAndVu ( Real const vl,
Real const vu 
)
inline
Parameters
[in]vl,vulower and upper bounds of the interval to be searched for eigenvalues. Not referenced if RANGE_ = 'A' or 'I'.

Definition at line 153 of file STK_lapack_SymEigen.h.

153{ VL_ = vl; VU_ = vu;}

References STK::lapack::SymEigen< SquareArray >::VL_, and STK::lapack::SymEigen< SquareArray >::VU_.

Member Data Documentation

◆ IL_

◆ IU_

◆ jobz_

template<class SquareArray >
char STK::lapack::SymEigen< SquareArray >::jobz_
private

Lapack pptions.

Definition at line 172 of file STK_lapack_SymEigen.h.

Referenced by STK::lapack::SymEigen< SquareArray >::setJobz().

◆ RANGE_

template<class SquareArray >
char STK::lapack::SymEigen< SquareArray >::RANGE_
private

◆ UPLO_

template<class SquareArray >
char STK::lapack::SymEigen< SquareArray >::UPLO_
private

◆ VL_

◆ VU_


The documentation for this class was generated from the following file: