cuLite v0.3.1
A lite CUDA C++ Interface
Loading...
Searching...
No Matches
culite::DefaultSVD< T_Matrix > Class Template Reference

Singular Value Decomposition (SVD) solver using cuSOLVER. More...

Public Member Functions

 DefaultSVD (CuSolverHandler &cusolver=globalCuSolverHandler())
 Default constructor.
 DefaultSVD (svdPolicy_t leftPolicy, svdPolicy_t rightPolicy, CuSolverHandler &cusolver=globalCuSolverHandler())
 Constructor with specified policies.
 ~DefaultSVD ()
 Destructor.
void reserve (const T_Matrix &mat)
 Reserves workspace memory for SVD decomposition.
void clear ()
 Clears all internal data and releases allocated memory.
svdPolicy_t getLeftPolicy () const
 Gets the current policy for computing left singular vectors.
svdPolicy_t getRightPolicy () const
 Gets the current policy for computing right singular vectors.
void setLeftPolicy (svdPolicy_t policy)
 Sets the policy for computing left singular vectors.
void setRightPolicy (svdPolicy_t policy)
 Sets the policy for computing right singular vectors.
void decompose (const T_Matrix &mat)
 Performs singular value decomposition on the input matrix.
const T_RVector & singularValues () const
 Gets the computed singular values.
const T_Matrix & leftSingularVectors () const
 Gets the computed left singular vectors.
const T_Matrix & rightSingularVectors () const
 Gets the computed right singular vectors.

Detailed Description

template<typename T_Matrix>
class culite::DefaultSVD< T_Matrix >

Singular Value Decomposition (SVD) solver using cuSOLVER.

This class provides a high-level interface for computing the singular value decomposition of general matrices using the cuSOLVER library.

For a given \( m \times n \) matrix A, the SVD computes the factorization:

\[ A = U \Sigma V^* \]

where:

  • \( U \) is an \( m \times m \) (or \( m \times \min(m,n) \) if Economy) unitary matrix of left singular vectors
  • \( \Sigma \) is an \( m \times n \) diagonal matrix with non-negative real singular values
  • \( V^* \) is the conjugate transpose of an \( n \times n \) (or \( \min(m,n) \times n \) if Economy) unitary matrix

The computation of singular vectors can be controlled independently via policy settings (Full, Economy, or None) to optimize performance and memory usage.

Template Parameters
T_MatrixThe matrix type (must be a dense GPU matrix type).

Usage Example

culite::dns::RdMatrix A = ...; // Input matrix
DefaultSVD<culite::dns::RdMatrix> svd;
svd.reserve(A); // Optional
svd.decompose(A);
void reserve(const T_Matrix &mat)
Reserves workspace memory for SVD decomposition.
const T_Matrix & rightSingularVectors() const
Gets the computed right singular vectors.
Definition default_svd.hpp:185
const T_Matrix & leftSingularVectors() const
Gets the computed left singular vectors.
Definition default_svd.hpp:176
const T_RVector & singularValues() const
Gets the computed singular values.
Definition default_svd.hpp:167
void decompose(const T_Matrix &mat)
Performs singular value decomposition on the input matrix.
XxMatrix< real_t > RdMatrix
Double precision real matrix.
Definition dense.hpp:55
XxVector< real_t > RdVector
Double precision real device vector.
Definition dense.hpp:31
Examples
ex08a_sv_decomposition.cpp.

Constructor & Destructor Documentation

◆ DefaultSVD() [1/2]

template<typename T_Matrix>
culite::DefaultSVD< T_Matrix >::DefaultSVD ( CuSolverHandler & cusolver = globalCuSolverHandler())

Default constructor.

Initializes the SVD solver with default settings. Both leftPolicy and rightPolicy are initialized to Economy.

Parameters
[in]cusolverReference to a cuSOLVER handler instance (defaults to global handler).

◆ DefaultSVD() [2/2]

template<typename T_Matrix>
culite::DefaultSVD< T_Matrix >::DefaultSVD ( svdPolicy_t leftPolicy,
svdPolicy_t rightPolicy,
CuSolverHandler & cusolver = globalCuSolverHandler() )

Constructor with specified policies.

Initializes the SVD solver with the specified cuSOLVER handler and singular vector computation policies.

Parameters
[in]leftPolicyPolicy for computing left singular vectors U (Economy, Full, or None).
[in]rightPolicyPolicy for computing right singular vectors V (Economy, Full, or None).
[in]cusolverReference to a cuSOLVER handler instance (defaults to global handler).

◆ ~DefaultSVD()

template<typename T_Matrix>
culite::DefaultSVD< T_Matrix >::~DefaultSVD ( )

Destructor.

Releases all allocated resources and clears internal state.

Member Function Documentation

◆ reserve()

template<typename T_Matrix>
void culite::DefaultSVD< T_Matrix >::reserve ( const T_Matrix & mat)

Reserves workspace memory for SVD decomposition.

Allocates internal buffers required for SVD computation based on the dimensions of the input matrix and current policies. Must be called before decompose.

Parameters
[in]matThe matrix for which to reserve workspace (determines dimensions).

◆ clear()

template<typename T_Matrix>
void culite::DefaultSVD< T_Matrix >::clear ( )

Clears all internal data and releases allocated memory.

Resets the solver to its initial state, releasing all computed results and internal workspace buffers.

◆ getLeftPolicy()

template<typename T_Matrix>
svdPolicy_t culite::DefaultSVD< T_Matrix >::getLeftPolicy ( ) const
inline

Gets the current policy for computing left singular vectors.

Returns
The current left singular vector computation policy.

◆ getRightPolicy()

template<typename T_Matrix>
svdPolicy_t culite::DefaultSVD< T_Matrix >::getRightPolicy ( ) const
inline

Gets the current policy for computing right singular vectors.

Returns
The current right singular vector computation policy.

◆ setLeftPolicy()

template<typename T_Matrix>
void culite::DefaultSVD< T_Matrix >::setLeftPolicy ( svdPolicy_t policy)
inline

Sets the policy for computing left singular vectors.

Changing the policy requires calling reserve again before the next decomposition.

Parameters
[in]policyThe desired left singular vector computation policy.

◆ setRightPolicy()

template<typename T_Matrix>
void culite::DefaultSVD< T_Matrix >::setRightPolicy ( svdPolicy_t policy)
inline

Sets the policy for computing right singular vectors.

Changing the policy requires calling reserve again before the next decomposition.

Parameters
[in]policyThe desired right singular vector computation policy.

◆ decompose()

template<typename T_Matrix>
void culite::DefaultSVD< T_Matrix >::decompose ( const T_Matrix & mat)

Performs singular value decomposition on the input matrix.

Computes the singular values and optionally the left and/or right singular vectors of the input matrix using cuSOLVER's SVD routine.

The input matrix is not modified. Results can be retrieved using the accessor methods: singularValues, leftSingularVectors, rightSingularVectors.

Parameters
[in]matThe matrix to decompose.
Precondition
reserve must have been called with a matrix of matching dimensions.
Note
Singular values are returned in descending order.
Examples
ex08a_sv_decomposition.cpp.

◆ singularValues()

template<typename T_Matrix>
const T_RVector & culite::DefaultSVD< T_Matrix >::singularValues ( ) const
inline

Gets the computed singular values.

Returns
Const reference to the vector containing the singular values in descending order.
Note
Only valid after calling decompose.
Singular values satisfy \( \sigma_1 \geq \sigma_2 \geq \ldots \geq \sigma_k \geq 0 \) where \( k = \min(m,n) \).
Examples
ex08a_sv_decomposition.cpp.

◆ leftSingularVectors()

template<typename T_Matrix>
const T_Matrix & culite::DefaultSVD< T_Matrix >::leftSingularVectors ( ) const
inline

Gets the computed left singular vectors.

Returns
Const reference to the matrix containing the left singular vectors (U matrix).
Note
Only valid after calling decompose.
Each column i contains the left singular vector corresponding to singular value i.
Dimensions depend on left policy: Economy gives \( m \times \min(m,n) \), Full gives \( m \times m \).
Examples
ex08a_sv_decomposition.cpp.

◆ rightSingularVectors()

template<typename T_Matrix>
const T_Matrix & culite::DefaultSVD< T_Matrix >::rightSingularVectors ( ) const
inline

Gets the computed right singular vectors.

Returns
Const reference to the matrix containing the right singular vectors (V matrix).
Note
Only valid after calling decompose.
Each column i contains the right singular vector corresponding to singular value i.
Returns V (not V^*). Dimensions depend on right policy: Economy gives \( n \times \min(m,n) \), Full gives \( n \times n \).
Examples
ex08a_sv_decomposition.cpp.