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;
77 : m_analysisIsOk(false),
78 m_factorizationIsOk(false),
80 m_ordering(SPQR_ORDERING_DEFAULT),
81 m_allow_tol(SPQR_DEFAULT_TOL),
88 m_useDefaultThreshold(true)
90 cholmod_l_start(&m_cc);
94 : m_analysisIsOk(false),
95 m_factorizationIsOk(false),
97 m_ordering(SPQR_ORDERING_DEFAULT),
98 m_allow_tol(SPQR_DEFAULT_TOL),
105 m_useDefaultThreshold(true)
107 cholmod_l_start(&m_cc);
114 cholmod_l_finish(&m_cc);
118 cholmod_l_free_sparse(&m_H, &m_cc);
119 cholmod_l_free_sparse(&m_cR, &m_cc);
120 cholmod_l_free_dense(&m_HTau, &m_cc);
127 if(m_isInitialized) SPQR_free();
129 MatrixType
mat(matrix);
135 RealScalar pivotThreshold = m_tolerance;
136 if(m_useDefaultThreshold)
138 RealScalar max2Norm = 0.0;
146 m_rows = matrix.rows();
148 m_rank = SuiteSparseQR<Scalar>(m_ordering, pivotThreshold,
col, &A,
149 &m_cR, &m_E, &m_H, &m_HPinv, &m_HTau, &m_cc);
154 m_isInitialized =
false;
158 m_isInitialized =
true;
159 m_isRUpToDate =
false;
171 template<
typename Rhs,
typename Dest>
174 eigen_assert(m_isInitialized &&
" The QR factorization should be computed first, call compute()");
175 eigen_assert(b.cols()==1 &&
"This method is for vectors only");
178 typename Dest::PlainObject
y, y2;
179 y = matrixQ().transpose() *
b;
182 Index rk = this->rank();
185 y.topRows(rk) = this->matrixR().topLeftCorner(rk, rk).template triangularView<Upper>().solve(y2.topRows(rk));
190 for(
Index i = 0;
i < rk; ++
i) dest.
row(m_E[
i]) = y.row(i);
191 for(
Index i = rk; i <
cols(); ++
i) dest.
row(m_E[i]).setZero();
203 eigen_assert(m_isInitialized &&
" The QR factorization should be computed first, call compute()");
205 m_R = viewAsEigen<Scalar,ColMajor, typename MatrixType::StorageIndex>(*m_cR);
206 m_isRUpToDate =
true;
218 eigen_assert(m_isInitialized &&
"Decomposition is not initialized.");
219 return PermutationType(m_E, m_cR->ncol);
227 eigen_assert(m_isInitialized &&
"Decomposition is not initialized.");
228 return m_cc.SPQR_istat[4];
235 m_useDefaultThreshold =
false;
250 eigen_assert(m_isInitialized &&
"Decomposition is not initialized.");
263 mutable StorageIndex *
m_E;
264 mutable cholmod_sparse *
m_H;
274 template <
typename SPQRType,
typename Derived>
280 SPQR_QProduct(
const SPQRType& spqr,
const Derived&
other,
bool transpose) : m_spqr(spqr),m_other(other),m_transpose(transpose) {}
282 inline Index rows()
const {
return m_transpose ? m_spqr.rows() : m_spqr.cols(); }
285 template<
typename ResType>
290 int method = m_transpose ? SPQR_QTX : SPQR_QX;
291 cholmod_common *cc = m_spqr.cholmodCommon();
293 x_cd = SuiteSparseQR_qmult<Scalar>(method, m_spqr.m_H, m_spqr.m_HTau, m_spqr.m_HPinv, &y_cd, cc);
295 cholmod_l_free_dense(&x_cd, cc);
302 template<
typename SPQRType>
306 template<
typename Derived>
323 template<
typename SPQRType>
326 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)
A base class for sparse solvers.
SPQRMatrixQReturnType(const SPQRType &spqr)
Namespace containing all symbols from the Eigen library.
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
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
_MatrixType::Scalar Scalar
ComputationInfo info() const
Reports whether previous computation was successful.
SPQRType::MatrixType ReturnType
SparseMatrix< Scalar, ColMajor, StorageIndex > MatrixType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE ColXpr col(Index i)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
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)
NumTraits< Scalar >::Real RealScalar
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.
void setSPQROrdering(int ord)
Set the fill-reducing ordering method to be used.
static ConstMapType Map(const Scalar *data)
SPQRMatrixQTransposeReturnType(const SPQRType &spqr)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RowXpr row(Index i)
Sparse QR factorization based on SuiteSparseQR library.
SPQRType::StorageIndex StorageIndex
EIGEN_DONT_INLINE void compute(Solver &solver, const MatrixType &A)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Base class for all dense matrices, vectors, and expressions.
cholmod_common * cholmodCommon() const
_MatrixType::RealScalar RealScalar