CLA3P v0.3.1
Compact Linear Algebra Parallel Portable Package
Loading...
Searching...
No Matches
cla3p::LapackSyev< T_Matrix > Class Template Reference

Eigenvalue decomposition solver using LAPACK SYEV/HEEV routines. More...

Public Member Functions

 LapackSyev ()
 Default constructor.
 LapackSyev (bool calcEigenvectors)
 Constructor with explicit eigenvector option.
 ~LapackSyev ()
 Destructor.
void clear ()
 Clears all internal data and releases allocated memory.
void reserve (int_t n)
 Pre-allocates internal buffers for a matrix of dimension n.
void decompose (const T_Matrix &mat)
 Performs the eigenvalue decomposition of mat.
void setCalcEigenvectors (bool calcEigenvectors)
 Sets whether to compute eigenvectors.
bool getCalcEigenvectors () const
 Checks if eigenvectors will be computed.
const T_RVector & eigenvalues () const
 Returns the computed eigenvalues.
const T_Matrix & eigenvectors () const
 Returns the computed eigenvectors.

Detailed Description

template<typename T_Matrix>
class cla3p::LapackSyev< T_Matrix >

Eigenvalue decomposition solver using LAPACK SYEV/HEEV routines.

This class provides a high-level interface for computing eigenvalues and eigenvectors of symmetric (real) or Hermitian (complex) square matrices using the LAPACK HEEV implementation (real: dsyev/ssyev, complex: zheev/cheev).

The HEEV routine computes the eigenvalue decomposition of a symmetric/Hermitian matrix \( A \):

\[ A \, v_i = \lambda_i \, v_i, \qquad \lambda_i \in \mathbb{R} \]

where all eigenvalues \( \lambda_i \) are guaranteed to be real. The eigenvectors form an orthonormal basis satisfying \( V^H V = I \).

Unlike LapackGeev, eigenvalues are returned as real-valued quantities. Eigenvectors share the scalar type of the input matrix (real for real input, complex for complex input). Internal buffers are managed automatically and can be pre-allocated via reserve() to avoid repeated heap allocations when the solver is reused for multiple decompositions.

Template Parameters
T_MatrixThe dense symmetric/Hermitian matrix type to decompose.

Usage Example

cla3p::dns::RdMatrix A = ...; // Input symmetric matrix
LapackSyev<cla3p::dns::RdMatrix> syev;
syev.reserve(A.nrows()); // Optional: pre-allocate buffers
syev.decompose(A);
const T_Matrix & eigenvectors() const
Returns the computed eigenvectors.
void reserve(int_t n)
Pre-allocates internal buffers for a matrix of dimension n.
void decompose(const T_Matrix &mat)
Performs the eigenvalue decomposition of mat.
const T_RVector & eigenvalues() const
Returns the computed eigenvalues.
virtual T_Int nrows() const
Number of rows.
Definition meta2d.hpp:54
XxMatrix< real_t > RdMatrix
Double precision real matrix.
Definition dense.hpp:55
XxVector< real_t > RdVector
Double precision real vector.
Definition dense.hpp:31
Examples
ex10b_syev_decomposition.cpp.

Constructor & Destructor Documentation

◆ LapackSyev() [1/2]

template<typename T_Matrix>
cla3p::LapackSyev< T_Matrix >::LapackSyev ( )

Default constructor.

Initializes the eigenvalue solver with default settings. calcEigenvectors is set to true, so eigenvectors are computed by default.

◆ LapackSyev() [2/2]

template<typename T_Matrix>
cla3p::LapackSyev< T_Matrix >::LapackSyev ( bool calcEigenvectors)

Constructor with explicit eigenvector option.

Initializes the eigenvalue solver with the specified eigenvector computation option. Use this form when only eigenvalues are needed, which avoids the additional cost of computing the eigenvector matrix.

Parameters
[in]calcEigenvectorsIf true, eigenvectors will be computed in decompose().

◆ ~LapackSyev()

template<typename T_Matrix>
cla3p::LapackSyev< T_Matrix >::~LapackSyev ( )

Destructor.

Releases all allocated resources and clears internal state.

Member Function Documentation

◆ clear()

template<typename T_Matrix>
void cla3p::LapackSyev< T_Matrix >::clear ( )

Clears all internal data and releases allocated memory.

Resets the solver to its initial state, releasing all computed results, internal workspace buffers, and resetting options to their defaults (calcEigenvectors = true).

◆ reserve()

template<typename T_Matrix>
void cla3p::LapackSyev< T_Matrix >::reserve ( int_t n)

Pre-allocates internal buffers for a matrix of dimension n.

Allocates all real and scalar workspace buffers required for eigenvalue decomposition of an n x n matrix. Calling this before decompose() avoids repeated heap allocations when the same solver instance is reused across multiple decompositions of equal or smaller size.

Parameters
[in]nMatrix dimension.
Examples
ex10b_syev_decomposition.cpp.

◆ decompose()

template<typename T_Matrix>
void cla3p::LapackSyev< T_Matrix >::decompose ( const T_Matrix & mat)

Performs the eigenvalue decomposition of mat.

Computes the eigenvalues and, depending on the current setting, the eigenvectors of mat using the LAPACK HEEV routine. The input matrix is copied internally before factorization; the original is left unmodified.

Results are accessible via eigenvalues() and eigenvectors() after this call returns.

Parameters
[in]matSquare symmetric/Hermitian dense matrix to decompose.
Note
Eigenvalues are always real, regardless of whether the input is real or complex.
Examples
ex10b_syev_decomposition.cpp.

◆ setCalcEigenvectors()

template<typename T_Matrix>
void cla3p::LapackSyev< T_Matrix >::setCalcEigenvectors ( bool calcEigenvectors)

Sets whether to compute eigenvectors.

Takes effect on the next call to decompose(). Changing this setting after reserve() has been called will require new buffer allocations on the next decompose().

Parameters
[in]calcEigenvectorsIf true, eigenvectors will be computed.

◆ getCalcEigenvectors()

template<typename T_Matrix>
bool cla3p::LapackSyev< T_Matrix >::getCalcEigenvectors ( ) const

Checks if eigenvectors will be computed.

Returns
true if eigenvectors will be computed, false otherwise.

◆ eigenvalues()

template<typename T_Matrix>
const T_RVector & cla3p::LapackSyev< T_Matrix >::eigenvalues ( ) const

Returns the computed eigenvalues.

Each element i of the returned vector is the i-th eigenvalue \( \lambda_i \), sorted in ascending order, matching the column ordering of eigenvectors().

Returns
Const reference to a real vector of length n containing the eigenvalues.
Note
Only valid after a successful call to decompose().
Examples
ex10b_syev_decomposition.cpp.

◆ eigenvectors()

template<typename T_Matrix>
const T_Matrix & cla3p::LapackSyev< T_Matrix >::eigenvectors ( ) const

Returns the computed eigenvectors.

Column i of the returned matrix contains the orthonormal eigenvector \( v_i \) satisfying \( A v_i = \lambda_i v_i \), where \( \lambda_i \) is eigenvalues() [i]. The columns form an orthonormal basis: \( V^H V = I \).

Returns
Const reference to an n x n matrix of eigenvectors, with the same scalar type as the input matrix.
Note
Only valid after calling decompose() with getCalcEigenvectors() == true.
Examples
ex10b_syev_decomposition.cpp.