From 763c833637d3918c32dc9c7ce5c9fcf647c7479b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 24 Jun 2015 17:54:09 +0200 Subject: Make SparseSelfAdjointView, twists, and SparseQR more evaluator friendly --- Eigen/src/SparseQR/SparseQR.h | 68 +++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 16 deletions(-) (limited to 'Eigen/src/SparseQR') diff --git a/Eigen/src/SparseQR/SparseQR.h b/Eigen/src/SparseQR/SparseQR.h index ce4a70454..548b3f9b0 100644 --- a/Eigen/src/SparseQR/SparseQR.h +++ b/Eigen/src/SparseQR/SparseQR.h @@ -23,6 +23,10 @@ namespace internal { typedef typename SparseQRType::MatrixType ReturnType; typedef typename ReturnType::StorageIndex StorageIndex; typedef typename ReturnType::StorageKind StorageKind; + enum { + RowsAtCompileTime = Dynamic, + ColsAtCompileTime = Dynamic + }; }; template struct traits > { @@ -235,8 +239,9 @@ class SparseQR : public SparseSolverBase > return m_info; } - protected: - inline void sort_matrix_Q() + + /** \internal */ + inline void _sort_matrix_Q() { if(this->m_isQSorted) return; // The matrix Q is sorted during the transposition @@ -267,7 +272,6 @@ class SparseQR : public SparseSolverBase > bool m_isEtreeOk; // whether the elimination tree match the initial input matrix template friend struct SparseQR_QProduct; - template friend struct SparseQRMatrixQReturnType; }; @@ -635,6 +639,10 @@ struct SparseQRMatrixQReturnType : public EigenBase DenseMatrix; + enum { + RowsAtCompileTime = Dynamic, + ColsAtCompileTime = Dynamic + }; explicit SparseQRMatrixQReturnType(const SparseQRType& qr) : m_qr(qr) {} template SparseQR_QProduct operator*(const MatrixBase& other) @@ -652,19 +660,6 @@ struct SparseQRMatrixQReturnType : public EigenBase(m_qr); } - template void evalTo(MatrixBase& dest) const - { - dest.derived() = m_qr.matrixQ() * Dest::Identity(m_qr.rows(), m_qr.rows()); - } - template void evalTo(SparseMatrixBase& dest) const - { - Dest idMat(m_qr.rows(), m_qr.rows()); - idMat.setIdentity(); - // Sort the sparse householder reflectors if needed - const_cast(&m_qr)->sort_matrix_Q(); - dest.derived() = SparseQR_QProduct(m_qr, idMat, false); - } - const SparseQRType& m_qr; }; @@ -680,6 +675,47 @@ struct SparseQRMatrixQTransposeReturnType const SparseQRType& m_qr; }; +namespace internal { + +template +struct evaluator_traits > +{ + typedef typename SparseQRType::MatrixType MatrixType; + typedef typename storage_kind_to_evaluator_kind::Kind Kind; + typedef SparseShape Shape; + static const int AssumeAliasing = 0; +}; + +template< typename DstXprType, typename SparseQRType> +struct Assignment, internal::assign_op, Sparse2Sparse> +{ + typedef SparseQRMatrixQReturnType SrcXprType; + typedef typename DstXprType::Scalar Scalar; + typedef typename DstXprType::StorageIndex StorageIndex; + static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &/*func*/) + { + typename DstXprType::PlainObject idMat(src.m_qr.rows(), src.m_qr.rows()); + idMat.setIdentity(); + // Sort the sparse householder reflectors if needed + const_cast(&src.m_qr)->_sort_matrix_Q(); + dst = SparseQR_QProduct(src.m_qr, idMat, false); + } +}; + +template< typename DstXprType, typename SparseQRType> +struct Assignment, internal::assign_op, Sparse2Dense> +{ + typedef SparseQRMatrixQReturnType SrcXprType; + typedef typename DstXprType::Scalar Scalar; + typedef typename DstXprType::StorageIndex StorageIndex; + static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &/*func*/) + { + dst = src.m_qr.matrixQ() * DstXprType::Identity(src.m_qr.rows(), src.m_qr.rows()); + } +}; + +} // end namespace internal + } // end namespace Eigen #endif -- cgit v1.2.3