11 #ifndef EIGEN_SUITESPARSEQRSUPPORT_H    12 #define EIGEN_SUITESPARSEQRSUPPORT_H    16   template<
typename MatrixType> 
class SPQR; 
    59 template<
typename _MatrixType>
    64     using Base::m_isInitialized;
    66     typedef typename _MatrixType::Scalar 
Scalar;
    77       : m_ordering(SPQR_ORDERING_DEFAULT), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (
NumTraits<Scalar>::
epsilon()), m_useDefaultThreshold(true)
    79       cholmod_l_start(&m_cc);
    82     explicit SPQR(
const _MatrixType& matrix)
    83     : m_ordering(SPQR_ORDERING_DEFAULT), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (
NumTraits<Scalar>::
epsilon()), m_useDefaultThreshold(true)
    85       cholmod_l_start(&m_cc);
    92       cholmod_l_finish(&m_cc);
    96       cholmod_l_free_sparse(&m_H, &m_cc);
    97       cholmod_l_free_sparse(&m_cR, &m_cc);
    98       cholmod_l_free_dense(&m_HTau, &m_cc);
   105       if(m_isInitialized) SPQR_free();
   107       MatrixType mat(matrix);
   113       RealScalar pivotThreshold = m_tolerance;
   114       if(m_useDefaultThreshold) 
   116         RealScalar max2Norm = 0.0;
   117         for (
int j = 0; j < mat.
cols(); j++) max2Norm = numext::maxi(max2Norm, mat.
col(j).norm());
   118         if(max2Norm==RealScalar(0))
   119           max2Norm = RealScalar(1);
   124       m_rows = matrix.rows();
   126       m_rank = SuiteSparseQR<Scalar>(m_ordering, pivotThreshold, 
col, &A, 
   127                              &m_cR, &m_E, &m_H, &m_HPinv, &m_HTau, &m_cc);
   132         m_isInitialized = 
false;
   136       m_isInitialized = 
true;
   137       m_isRUpToDate = 
false;
   149     template<
typename Rhs, 
typename Dest>
   152       eigen_assert(m_isInitialized && 
" The QR factorization should be computed first, call compute()");
   153       eigen_assert(b.cols()==1 && 
"This method is for vectors only");
   156       typename Dest::PlainObject y, y2;
   157       y = matrixQ().transpose() * b;
   160       Index rk = this->rank();
   163       y.topRows(rk) = this->matrixR().topLeftCorner(rk, rk).template triangularView<Upper>().solve(y2.topRows(rk));
   168       for(
Index i = 0; i < rk; ++i) dest.
row(m_E[i]) = y.row(i);
   169       for(
Index i = rk; i < cols(); ++i) dest.
row(m_E[i]).setZero();
   181       eigen_assert(m_isInitialized && 
" The QR factorization should be computed first, call compute()");
   183         m_R = viewAsEigen<Scalar,ColMajor, typename MatrixType::StorageIndex>(*m_cR);
   184         m_isRUpToDate = 
true;
   196       eigen_assert(m_isInitialized && 
"Decomposition is not initialized.");
   197       return PermutationType(m_E, m_cR->ncol);
   205       eigen_assert(m_isInitialized && 
"Decomposition is not initialized.");
   206       return m_cc.SPQR_istat[4];
   213       m_useDefaultThreshold = 
false;
   228       eigen_assert(m_isInitialized && 
"Decomposition is not initialized.");
   241     mutable StorageIndex *
m_E; 
   242     mutable cholmod_sparse *
m_H;  
   252 template <
typename SPQRType, 
typename Derived>
   255   typedef typename SPQRType::Scalar 
Scalar;
   258   SPQR_QProduct(
const SPQRType& spqr, 
const Derived& other, 
bool transpose) : m_spqr(spqr),m_other(other),m_transpose(transpose) {}
   260   inline Index rows()
 const { 
return m_transpose ? m_spqr.rows() : m_spqr.cols(); }
   263   template<
typename ResType>
   268     int method = m_transpose ? SPQR_QTX : SPQR_QX; 
   269     cholmod_common *cc = m_spqr.cholmodCommon();
   271     x_cd = SuiteSparseQR_qmult<Scalar>(method, m_spqr.m_H, m_spqr.m_HTau, m_spqr.m_HPinv, &y_cd, cc);
   273     cholmod_l_free_dense(&x_cd, cc);
   280 template<
typename SPQRType>
   284   template<
typename Derived>
   301 template<
typename SPQRType>
   304   template<
typename Derived>
 SPQR_QProduct< SPQRType, Derived > operator*(const MatrixBase< Derived > &other)
const MatrixType matrixR() const
SuiteSparse_long StorageIndex
SPQRMatrixQTransposeReturnType< SPQRType > transpose() const
Map< PermutationMatrix< Dynamic, Dynamic, StorageIndex > > PermutationType
A matrix or vector expression mapping an existing array of data. 
SPQR(const _MatrixType &matrix)
EIGEN_DEVICE_FUNC ColXpr col(Index i)
This is the const version of col(). */. 
A base class for sparse solvers. 
SPQRMatrixQReturnType(const SPQRType &spqr)
void evalTo(ResType &res) const
SPQR_QProduct< SPQRType, Derived > operator*(const MatrixBase< Derived > &other)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
void _solve_impl(const MatrixBase< Rhs > &b, MatrixBase< Dest > &dest) const
_MatrixType::Scalar Scalar
ComputationInfo info() const
Reports whether previous computation was successful. 
SPQRType::MatrixType ReturnType
SparseMatrix< Scalar, ColMajor, StorageIndex > MatrixType
bool m_useDefaultThreshold
void setPivotThreshold(const RealScalar &tol)
Set the tolerance tol to treat columns with 2-norm < =tol as zero. 
SPQRMatrixQTransposeReturnType< SPQRType > adjoint() const
SPQRType::MatrixType ReturnType
Derived::PlainObject ReturnType
SPQRMatrixQReturnType< SPQR > matrixQ() const
Get an expression of the matrix Q. 
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API. 
SPQR_QProduct(const SPQRType &spqr, const Derived &other, bool transpose)
void compute(const _MatrixType &matrix)
EIGEN_DEVICE_FUNC ColXpr col(Index i)
cholmod_sparse viewAsCholmod(Ref< SparseMatrix< _Scalar, _Options, _StorageIndex > > mat)
SparseSolverBase< SPQR< _MatrixType > > Base
PermutationType colsPermutation() const
Get the permutation that was applied to columns of A. 
int64_t max(int64_t a, const int b)
void setSPQROrdering(int ord)
Set the fill-reducing ordering method to be used. 
static ConstMapType Map(const Scalar *data)
SPQRMatrixQTransposeReturnType(const SPQRType &spqr)
Sparse QR factorization based on SuiteSparseQR library. 
SPQRType::StorageIndex StorageIndex
EIGEN_DEVICE_FUNC RowXpr row(Index i)
Base class for all dense matrices, vectors, and expressions. 
cholmod_common * cholmodCommon() const
_MatrixType::RealScalar RealScalar