irlba
A C++ library for IRLBA
Loading...
Searching...
No Matches
compute.hpp File Reference

Compute an approximate SVD with IRLBA. More...

#include <cmath>
#include <cstdint>
#include <random>
#include <stdexcept>
#include <type_traits>
#include "utils.hpp"
#include "lanczos.hpp"
#include "Matrix/simple.hpp"
#include "sanisizer/sanisizer.hpp"
#include "Eigen/Dense"
Include dependency graph for compute.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  irlba::Results< EigenMatrix_, EigenVector_ >
 Results of the IRLBA-based SVD by compute(). More...
 

Functions

template<class Matrix_ , class EigenMatrix_ , class EigenVector_ >
std::pair< bool, int > irlba::compute (const Matrix_ &matrix, const Eigen::Index number, EigenMatrix_ &outU, EigenMatrix_ &outV, EigenVector_ &outD, const Options< EigenVector_ > &options)
 
template<class InputEigenMatrix_ , class OutputEigenMatrix_ , class EigenVector_ >
std::pair< bool, int > irlba::compute_simple (const InputEigenMatrix_ &matrix, Eigen::Index number, OutputEigenMatrix_ &outU, OutputEigenMatrix_ &outV, EigenVector_ &outD, const Options< EigenVector_ > &options)
 
template<class EigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class Matrix_ >
Results< EigenMatrix_, EigenVector_ > irlba::compute (const Matrix_ &matrix, Eigen::Index number, const Options< EigenVector_ > &options)
 
template<class OutputEigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class InputEigenMatrix_ >
Results< OutputEigenMatrix_, EigenVector_ > irlba::compute_simple (const InputEigenMatrix_ &matrix, Eigen::Index number, const Options< EigenVector_ > &options)
 

Detailed Description

Compute an approximate SVD with IRLBA.

Function Documentation

◆ compute() [1/2]

template<class Matrix_ , class EigenMatrix_ , class EigenVector_ >
std::pair< bool, int > irlba::compute ( const Matrix_ & matrix,
const Eigen::Index number,
EigenMatrix_ & outU,
EigenMatrix_ & outV,
EigenVector_ & outD,
const Options< EigenVector_ > & options )

Implements the Implicitly Restarted Lanczos Bidiagonalization Algorithm (IRLBA) for fast truncated singular value decomposition. This is heavily derived from the C code in the irlba package, with refactoring into C++ to use Eigen instead of LAPACK for much of the matrix algebra.

Template Parameters
Matrix_Class satisfying the Matrix<EigenVector_, EigenMatrix_> interface.
EigenMatrix_A dense floating-point Eigen::Matrix class to store the output.
EigenVector_A floating-point Eigen::Vector class to store the output, typically of the same scalar type as EigenMatrix_.
Parameters
[in]matrixInput matrix.
numberNumber of singular triplets to obtain. The returned number of triplets may be lower, see Options::cap_number for details.
[out]outUOutput matrix containing the left singular vectors corresponding to the largest singular values. Each column corresponds to a left singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of rows in mat.
[out]outVOutput matrix containing the right singular vectors corresponding to the largest singular values. Each column corresponds to a right singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of columns in mat.
[out]outDOutput vector containing the largest singular values, ordered by decreasing size. This has length equal to number (or lower, depending on Options::cap_number).
optionsFurther options.
Returns
A pair where the first entry indicates whether the algorithm converged, and the second entry indicates the number of restart iterations performed.

◆ compute() [2/2]

template<class EigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class Matrix_ >
Results< EigenMatrix_, EigenVector_ > irlba::compute ( const Matrix_ & matrix,
Eigen::Index number,
const Options< EigenVector_ > & options )

Convenient overload of compute() that allocates memory for the output matrices of the SVD.

Template Parameters
EigenMatrix_A dense floating-point Eigen::Matrix class to store the output.
EigenVector_A floating-point Eigen::Vector class for the output, typically of the same scalar type as EigenMatrix_.
Matrix_Class satisfying the Matrix<EigenVector_, EigenMatrix_> interface.
Parameters
[in]matrixInput matrix.
numberNumber of singular triplets to obtain.
optionsFurther options.
Returns
A Results object containing the singular vectors and values, as well as some statistics on convergence.

◆ compute_simple() [1/2]

template<class OutputEigenMatrix_ = Eigen::MatrixXd, class EigenVector_ = Eigen::VectorXd, class InputEigenMatrix_ >
Results< OutputEigenMatrix_, EigenVector_ > irlba::compute_simple ( const InputEigenMatrix_ & matrix,
Eigen::Index number,
const Options< EigenVector_ > & options )

Convenient overload of compute() that accepts an Eigen matrix directly.

Template Parameters
InputEigenMatrix_An Eigen matrix class containing the input data.
OutputEigenMatrix_A dense floating-point Eigen::Matrix class for the output.
EigenVector_A floating-point Eigen::Vector class for the output, typically of the same scalar type as OutputEigenMatrix_.
Matrix_Class satisfying the Matrix<EigenVector_, EigenMatrix_> interface.
Parameters
[in]matrixInput matrix.
numberNumber of singular triplets to obtain.
optionsFurther options.
Returns
A Results object containing the singular vectors and values, as well as some statistics on convergence.

◆ compute_simple() [2/2]

template<class InputEigenMatrix_ , class OutputEigenMatrix_ , class EigenVector_ >
std::pair< bool, int > irlba::compute_simple ( const InputEigenMatrix_ & matrix,
Eigen::Index number,
OutputEigenMatrix_ & outU,
OutputEigenMatrix_ & outV,
EigenVector_ & outD,
const Options< EigenVector_ > & options )

Convenient overload of compute() that accepts an Eigen matrix directly.

Template Parameters
InputEigenMatrix_An Eigen matrix class containing the input data.
OutputEigenMatrix_A dense floating-point Eigen::Matrix class to store the output.
EigenVector_A floating-point Eigen::Vector class to store the output, typically of the same scalar type as EigenMatrix_.
Parameters
[in]matrixInput matrix.
numberNumber of singular triplets to obtain. The returned number of triplets may be lower, see Options::cap_number for details.
[out]outUOutput matrix containing the left singular vectors corresponding to the largest singular values. Each column corresponds to a left singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of rows in mat.
[out]outVOutput matrix containing the right singular vectors corresponding to the largest singular values. Each column corresponds to a right singular vector, of which there are number (or less, depending on Options::cap_number). The number of rows is equal to the number of columns in mat.
[out]outDOutput vector containing the largest singular values, ordered by decreasing size. This has length equal to number (or lower, depending on Options::cap_number).
optionsFurther options.
Returns
A pair where the first entry indicates whether the algorithm converged, and the second entry indicates the number of restart iterations performed.