diff options
author | Gael Guennebaud <g.gael@free.fr> | 2011-11-30 19:24:43 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2011-11-30 19:24:43 +0100 |
commit | d1b54ecfa3cd9c57569ab245566a4f66cc4f363a (patch) | |
tree | f9ae278b47464206c5f87cf0fb1de10cca75c27f /Eigen/src/SparseCore | |
parent | cda397b11775000a7b6da375728ebb851ebec232 (diff) |
add more support for uncompressed mode
Diffstat (limited to 'Eigen/src/SparseCore')
-rw-r--r-- | Eigen/src/SparseCore/SparseBlock.h | 14 | ||||
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrix.h | 65 |
2 files changed, 60 insertions, 19 deletions
diff --git a/Eigen/src/SparseCore/SparseBlock.h b/Eigen/src/SparseCore/SparseBlock.h index 3119686c4..777fd1b76 100644 --- a/Eigen/src/SparseCore/SparseBlock.h +++ b/Eigen/src/SparseCore/SparseBlock.h @@ -237,15 +237,23 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options, _Index>, Size> Index nonZeros() const { - return std::size_t(m_matrix._outerIndexPtr()[m_outerStart+m_outerSize.value()]) - - std::size_t(m_matrix._outerIndexPtr()[m_outerStart]); + if(m_matrix.compressed()) + return std::size_t(m_matrix._outerIndexPtr()[m_outerStart+m_outerSize.value()]) + - std::size_t(m_matrix._outerIndexPtr()[m_outerStart]); + else if(m_outerSize.value()==0) + return 0; + else + return Map<const Matrix<Index,Size,1> >(m_matrix._innerNonZeroPtr(), m_outerSize.value()).sum(); } const Scalar& lastCoeff() const { EIGEN_STATIC_ASSERT_VECTOR_ONLY(SparseInnerVectorSet); eigen_assert(nonZeros()>0); - return m_matrix._valuePtr()[m_matrix._outerIndexPtr()[m_outerStart+1]-1]; + if(m_matrix.compressed()) + return m_matrix._valuePtr()[m_matrix._outerIndexPtr()[m_outerStart+1]-1]; + else + return m_matrix._valuePtr()[m_matrix._outerIndexPtr()[m_outerStart]+m_matrix._innerNonZeroPtr()[m_outerStart]-1]; } // template<typename Sparse> diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 21a671ca5..87a7066b3 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -138,6 +138,15 @@ class SparseMatrix * \returns a non-const pointer to the array of the starting positions of the inner vectors */ inline Index* _outerIndexPtr() { return m_outerIndex; } + /** \internal + * \returns a const pointer to the array of the number of non zeros of the inner vectors + * \warning it returns 0 in compressed mode */ + inline const Index* _innerNonZeroPtr() const { return m_innerNonZeros; } + /** \internal + * \returns a non-const pointer to the array of the number of non zeros of the inner vectors + * \warning it returns 0 in compressed mode */ + inline Index* _innerNonZeroPtr() { return m_innerNonZeros; } + inline Storage& data() { return m_data; } inline const Storage& data() const { return m_data; } @@ -357,7 +366,10 @@ class SparseMatrix return insertUncompressed(row,col); } - + EIGEN_DONT_INLINE Scalar& insertByOuterInner(Index j, Index i) + { + return insert(IsRowMajor ? j : i, IsRowMajor ? i : j); + } /** Must be called after inserting a set of non zero entries. @@ -527,12 +539,7 @@ class SparseMatrix } else { - resize(other.rows(), other.cols()); - if(m_innerNonZeros) - { - delete[] m_innerNonZeros; - m_innerNonZeros = 0; - } + initAssignment(other); if(other.compressed()) { memcpy(m_outerIndex, other.m_outerIndex, (m_outerSize+1)*sizeof(Index)); @@ -549,20 +556,30 @@ class SparseMatrix #ifndef EIGEN_PARSED_BY_DOXYGEN template<typename Lhs, typename Rhs> inline SparseMatrix& operator=(const SparseSparseProduct<Lhs,Rhs>& product) - { return Base::operator=(product); } + { + initAssignment(product); + return Base::operator=(product); + } template<typename OtherDerived> inline SparseMatrix& operator=(const ReturnByValue<OtherDerived>& other) - { return Base::operator=(other.derived()); } + { + initAssignment(other.derived()); + return Base::operator=(other.derived()); + } template<typename OtherDerived> inline SparseMatrix& operator=(const EigenBase<OtherDerived>& other) - { return Base::operator=(other.derived()); } + { + initAssignment(other.derived()); + return Base::operator=(other.derived()); + } #endif template<typename OtherDerived> EIGEN_DONT_INLINE SparseMatrix& operator=(const SparseMatrixBase<OtherDerived>& other) { + initAssignment(other.derived()); const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); if (needToTranspose) { @@ -574,7 +591,6 @@ class SparseMatrix typedef typename internal::remove_all<OtherCopy>::type _OtherCopy; OtherCopy otherCopy(other.derived()); - resize(other.rows(), other.cols()); Eigen::Map<Matrix<Index, Dynamic, 1> > (m_outerIndex,outerSize()).setZero(); // pass 1 // FIXME the above copy could be merged with that pass @@ -610,7 +626,7 @@ class SparseMatrix else { // there is no special optimization - return SparseMatrixBase<SparseMatrix>::operator=(other.derived()); + return Base::operator=(other.derived()); } } @@ -640,6 +656,7 @@ class SparseMatrix inline ~SparseMatrix() { delete[] m_outerIndex; + delete[] m_innerNonZeros; } /** Overloaded for performance */ @@ -650,6 +667,18 @@ class SparseMatrix # endif protected: + + template<typename Other> + void initAssignment(const Other& other) + { + resize(other.rows(), other.cols()); + if(m_innerNonZeros) + { + delete[] m_innerNonZeros; + m_innerNonZeros = 0; + } + } + /** \internal * \sa insert(Index,Index) */ EIGEN_DONT_INLINE Scalar& insertCompressed(Index row, Index col) @@ -820,9 +849,13 @@ class SparseMatrix<Scalar,_Options,_Index>::InnerIterator { public: InnerIterator(const SparseMatrix& mat, Index outer) - : m_values(mat._valuePtr()), m_indices(mat._innerIndexPtr()), m_outer(outer), m_id(mat.m_outerIndex[outer]), - m_end(mat.m_outerIndex[outer+1]) - {} + : m_values(mat._valuePtr()), m_indices(mat._innerIndexPtr()), m_outer(outer), m_id(mat.m_outerIndex[outer]) + { + if(mat.compressed()) + m_end = mat.m_outerIndex[outer+1]; + else + m_end = m_id + mat.m_innerNonZeros[outer]; + } inline InnerIterator& operator++() { m_id++; return *this; } @@ -841,7 +874,7 @@ class SparseMatrix<Scalar,_Options,_Index>::InnerIterator const Index* m_indices; const Index m_outer; Index m_id; - const Index m_end; + Index m_end; }; #endif // EIGEN_SPARSEMATRIX_H |