diff options
author | Gael Guennebaud <g.gael@free.fr> | 2011-11-30 21:55:54 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2011-11-30 21:55:54 +0100 |
commit | 49d652c600bcaa98d089a03f58db7124084d4d26 (patch) | |
tree | 6f6ecb84b1443e0ddce35fb0456918634bf1b646 /Eigen/src/SparseCore/SparseMatrixBase.h | |
parent | 6b8d6887acb22f8c4d2c1a74de5c162e17bb9ae2 (diff) |
fix assigment from uncompressed
Diffstat (limited to 'Eigen/src/SparseCore/SparseMatrixBase.h')
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrixBase.h | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index 0dd56c5ec..849e00593 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -180,16 +180,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> Derived& markAsRValue() { m_isRValue = true; return derived(); } SparseMatrixBase() : m_isRValue(false) { /* TODO check flags */ } - -// inline Derived& operator=(const Derived& other) -// { -// // std::cout << "Derived& operator=(const Derived& other)\n"; -// // if (other.isRValue()) -// // derived().swap(other.const_cast_derived()); -// // else -// this->operator=<Derived>(other); -// return derived(); -// } + template<typename OtherDerived> Derived& operator=(const ReturnByValue<OtherDerived>& other) @@ -200,39 +191,23 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> template<typename OtherDerived> - inline void assignGeneric(const OtherDerived& other) + inline Derived& operator=(const SparseMatrixBase<OtherDerived>& other) { - //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); - eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) || - (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) && - "the transpose operation is supposed to be handled in SparseMatrix::operator="); - - enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) }; - - const Index outerSize = other.outerSize(); - //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType; - // thanks to shallow copies, we always eval to a tempary - Derived temp(other.rows(), other.cols()); - - temp.reserve((std::max)(this->rows(),this->cols())*2); - for (Index j=0; j<outerSize; ++j) - { - temp.startVec(j); - for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) - { - Scalar v = it.value(); - if (v!=Scalar(0)) - temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v; - } - } - temp.finalize(); + return assign(other.derived()); + } - derived() = temp.markAsRValue(); + inline Derived& operator=(const Derived& other) + { +// if (other.isRValue()) +// derived().swap(other.const_cast_derived()); +// else + return assign(other.derived()); } + protected: template<typename OtherDerived> - inline Derived& operator=(const SparseMatrixBase<OtherDerived>& other) + inline Derived& assign(const OtherDerived& other) { const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); const Index outerSize = (int(OtherDerived::Flags) & RowMajorBit) ? other.rows() : other.cols(); @@ -245,7 +220,7 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> for (Index j=0; j<outerSize; ++j) { derived().startVec(j); - for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) + for (typename OtherDerived::InnerIterator it(other, j); it; ++it) { Scalar v = it.value(); if (v!=Scalar(0)) @@ -256,11 +231,44 @@ template<typename Derived> class SparseMatrixBase : public EigenBase<Derived> } else { - assignGeneric(other.derived()); + assignGeneric(other); } return derived(); } + template<typename OtherDerived> + inline void assignGeneric(const OtherDerived& other) + { + //const bool transpose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); + eigen_assert(( ((internal::traits<Derived>::SupportedAccessPatterns&OuterRandomAccessPattern)==OuterRandomAccessPattern) || + (!((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)))) && + "the transpose operation is supposed to be handled in SparseMatrix::operator="); + + enum { Flip = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit) }; + + const Index outerSize = other.outerSize(); + //typedef typename internal::conditional<transpose, LinkedVectorMatrix<Scalar,Flags&RowMajorBit>, Derived>::type TempType; + // thanks to shallow copies, we always eval to a tempary + Derived temp(other.rows(), other.cols()); + + temp.reserve((std::max)(this->rows(),this->cols())*2); + for (Index j=0; j<outerSize; ++j) + { + temp.startVec(j); + for (typename OtherDerived::InnerIterator it(other.derived(), j); it; ++it) + { + Scalar v = it.value(); + if (v!=Scalar(0)) + temp.insertBackByOuterInner(Flip?it.index():j,Flip?j:it.index()) = v; + } + } + temp.finalize(); + + derived() = temp.markAsRValue(); + } + + public: + template<typename Lhs, typename Rhs> inline Derived& operator=(const SparseSparseProduct<Lhs,Rhs>& product); |