From facee57b8d0f8343cb9b7d7db3ad5e454bc80915 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 30 Apr 2009 12:09:45 +0000 Subject: [PATCH] add auto transposition for vectors --- Eigen/src/Sparse/SparseVector.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Eigen/src/Sparse/SparseVector.h b/Eigen/src/Sparse/SparseVector.h index 8e5a6efed..7321fd966 100644 --- a/Eigen/src/Sparse/SparseVector.h +++ b/Eigen/src/Sparse/SparseVector.h @@ -69,7 +69,7 @@ class SparseVector CompressedStorage m_data; int m_size; - + CompressedStorage& _data() { return m_data; } CompressedStorage& _data() const { return m_data; } @@ -103,7 +103,7 @@ class SparseVector /** \returns a reference to the coefficient value at given index \a i * This operation involes a log(rho*size) binary search. If the coefficient does not * exist yet, then a sorted insertion into a sequential buffer is performed. - * + * * This insertion might be very costly if the number of nonzeros above \a i is large. */ inline Scalar& coeffRef(int i) @@ -123,7 +123,7 @@ class SparseVector /** */ inline void reserve(int reserveSize) { m_data.reserve(reserveSize); } - + inline void startFill(int reserve) { setZero(); @@ -137,13 +137,13 @@ class SparseVector ei_assert(r==0 || c==0); return fill(IsColVector ? r : c); } - + inline Scalar& fill(int i) { m_data.append(0, i); return m_data.value(m_data.size()-1); } - + inline Scalar& fillrand(int r, int c) { ei_assert(r==0 || c==0); @@ -168,14 +168,14 @@ class SparseVector m_data.value(id+1) = 0; return m_data.value(id+1); } - + inline void endFill() {} - + void prune(Scalar reference, RealScalar epsilon = precision()) { m_data.prune(reference,epsilon); } - + void resize(int rows, int cols) { ei_assert(rows==1 || cols==1); @@ -193,7 +193,7 @@ class SparseVector inline SparseVector() : m_size(0) { resize(0); } inline SparseVector(int size) : m_size(0) { resize(size); } - + inline SparseVector(int rows, int cols) : m_size(0) { resize(rows,cols); } template @@ -202,7 +202,7 @@ class SparseVector { *this = other.derived(); } - + template inline SparseVector(const SparseMatrixBase& other) : m_size(0) @@ -239,9 +239,12 @@ class SparseVector template inline SparseVector& operator=(const SparseMatrixBase& other) { - return Base::operator=(other); + if (int(RowsAtCompileTime)!=int(OtherDerived::RowsAtCompileTime)) + return Base::operator=(other.transpose()); + else + return Base::operator=(other); } - + // const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); // if (needToTranspose) // { @@ -335,7 +338,7 @@ class SparseVector::InnerIterator { ei_assert(outer==0); } - + InnerIterator(const CompressedStorage& data) : m_data(data), m_id(0), m_end(m_data.size()) {}