From 3499f6eccd5fc56f13608a3ccf900aa70f6b1697 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 26 Mar 2009 17:11:43 +0000 Subject: [PATCH] fix Taucs support (it appears Taucs does not return sorted matrices) --- Eigen/src/Sparse/SparseMatrix.h | 10 +++---- Eigen/src/Sparse/SuperLUSupport.h | 1 + Eigen/src/Sparse/TaucsSupport.h | 45 +++++++++++++++++++++---------- 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Eigen/src/Sparse/SparseMatrix.h b/Eigen/src/Sparse/SparseMatrix.h index 8ac98d074..3f09596bc 100644 --- a/Eigen/src/Sparse/SparseMatrix.h +++ b/Eigen/src/Sparse/SparseMatrix.h @@ -62,7 +62,7 @@ class SparseMatrix // FIXME: why are these operator already alvailable ??? // EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, *=) // EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, /=) - + typedef MappedSparseMatrix Map; protected: @@ -79,7 +79,7 @@ class SparseMatrix inline int rows() const { return IsRowMajor ? m_outerSize : m_innerSize; } inline int cols() const { return IsRowMajor ? m_innerSize : m_outerSize; } - + inline int innerSize() const { return m_innerSize; } inline int outerSize() const { return m_outerSize; } inline int innerNonZeros(int j) const { return m_outerIndex[j+1]-m_outerIndex[j]; } @@ -195,7 +195,7 @@ class SparseMatrix // FIXME let's make sure sizeof(long int) == sizeof(size_t) size_t id = m_outerIndex[outer+1]; ++m_outerIndex[outer+1]; - + float reallocRatio = 1; if (m_data.allocatedSize()()) { int k = 0; diff --git a/Eigen/src/Sparse/SuperLUSupport.h b/Eigen/src/Sparse/SuperLUSupport.h index e52c62c13..bbe9ef9ac 100644 --- a/Eigen/src/Sparse/SuperLUSupport.h +++ b/Eigen/src/Sparse/SuperLUSupport.h @@ -224,6 +224,7 @@ SluMatrix SparseMatrixBase::asSluMatrix() return SluMatrix::Map(derived()); } +/** View a Super LU matrix as an Eigen expression */ template MappedSparseMatrix::MappedSparseMatrix(SluMatrix& sluMat) { diff --git a/Eigen/src/Sparse/TaucsSupport.h b/Eigen/src/Sparse/TaucsSupport.h index cda26a529..4dddca7b6 100644 --- a/Eigen/src/Sparse/TaucsSupport.h +++ b/Eigen/src/Sparse/TaucsSupport.h @@ -129,7 +129,10 @@ void SparseLLT::compute(const MatrixType& a) { taucs_ccs_matrix taucsMatA = const_cast(a).asTaucsMatrix(); taucs_ccs_matrix* taucsRes = taucs_ccs_factor_llt(&taucsMatA, Base::m_precision, 0); - m_matrix = MappedSparseMatrix(*taucsRes); + // the matrix returned by Taucs is not necessarily sorted, + // so let's copy it in two steps + DynamicSparseMatrix tmp = MappedSparseMatrix(*taucsRes); + m_matrix = tmp; free(taucsRes); m_status = (m_status & ~(CompleteFactorization|MatrixLIsDirty)) | IncompleteFactorization @@ -161,7 +164,11 @@ SparseLLT::matrixL() const ei_assert(!(m_status & SupernodalFactorIsDirty)); taucs_ccs_matrix* taucsL = taucs_supernodal_factor_to_ccs(m_taucsSupernodalFactor); - const_cast(m_matrix) = MappedSparseMatrix(*taucsL); + + // the matrix returned by Taucs is not necessarily sorted, + // so let's copy it in two steps + DynamicSparseMatrix tmp = MappedSparseMatrix(*taucsL); + const_cast(m_matrix) = tmp; free(taucsL); m_status = (m_status & ~MatrixLIsDirty); } @@ -172,22 +179,32 @@ template template void SparseLLT::solveInPlace(MatrixBase &b) const { - if (m_status & MatrixLIsDirty) + bool inputIsCompatibleWithTaucs = (Derived::Flags&RowMajorBit)==0; + + if (!inputIsCompatibleWithTaucs) { - // TODO use taucs's supernodal solver, in particular check types, storage order, etc. - // VectorXb x(b.rows()); - // for (int j=0; j(m_matrix).asTaucsMatrix(); + typename ei_plain_matrix_type::type x(b.rows()); + for (int j=0; j::type x(b.rows()); + for (int j=0; j