aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Eigen/src/SparseCore/SparseCompressedBase.h21
-rw-r--r--test/sparse_basic.cpp27
2 files changed, 47 insertions, 1 deletions
diff --git a/Eigen/src/SparseCore/SparseCompressedBase.h b/Eigen/src/SparseCore/SparseCompressedBase.h
index f78d7c24d..ea71b41d1 100644
--- a/Eigen/src/SparseCore/SparseCompressedBase.h
+++ b/Eigen/src/SparseCore/SparseCompressedBase.h
@@ -117,6 +117,24 @@ template<typename Derived>
class SparseCompressedBase<Derived>::InnerIterator
{
public:
+ InnerIterator()
+ : m_values(0), m_indices(0), m_outer(0), m_id(0), m_end(0)
+ {}
+
+ InnerIterator(const InnerIterator& other)
+ : m_values(other.m_values), m_indices(other.m_indices), m_outer(other.m_outer), m_id(other.m_id), m_end(other.m_end)
+ {}
+
+ InnerIterator& operator=(const InnerIterator& other)
+ {
+ m_values = other.m_values;
+ m_indices = other.m_indices;
+ const_cast<OuterType&>(m_outer).setValue(other.m_outer.value());
+ m_id = other.m_id;
+ m_end = other.m_end;
+ return *this;
+ }
+
InnerIterator(const SparseCompressedBase& mat, Index outer)
: m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer)
{
@@ -162,7 +180,8 @@ class SparseCompressedBase<Derived>::InnerIterator
protected:
const Scalar* m_values;
const StorageIndex* m_indices;
- const internal::variable_if_dynamic<Index,Derived::IsVectorAtCompileTime?0:Dynamic> m_outer;
+ typedef internal::variable_if_dynamic<Index,Derived::IsVectorAtCompileTime?0:Dynamic> OuterType;
+ const OuterType m_outer;
Index m_id;
Index m_end;
private:
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 5a5650705..0a06c828b 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -460,6 +460,33 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
refMat1.setIdentity();
VERIFY_IS_APPROX(m1, refMat1);
}
+
+ // test array/vector of InnerIterator
+ {
+ typedef typename SparseMatrixType::InnerIterator IteratorType;
+
+ DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
+ SparseMatrixType m2(rows, cols);
+ initSparse<Scalar>(density, refMat2, m2);
+ IteratorType static_array[2];
+ static_array[0] = IteratorType(m2,0);
+ static_array[1] = IteratorType(m2,m2.outerSize()-1);
+ VERIFY( static_array[0] || m2.innerVector(static_array[0].outer()).nonZeros() == 0 );
+ VERIFY( static_array[1] || m2.innerVector(static_array[1].outer()).nonZeros() == 0 );
+ if(static_array[0] && static_array[1])
+ {
+ ++(static_array[1]);
+ static_array[1] = IteratorType(m2,0);
+ VERIFY( static_array[1] );
+ VERIFY( static_array[1].index() == static_array[0].index() );
+ VERIFY( static_array[1].outer() == static_array[0].outer() );
+ VERIFY( static_array[1].value() == static_array[0].value() );
+ }
+
+ std::vector<IteratorType> iters(2);
+ iters[0] = IteratorType(m2,0);
+ iters[1] = IteratorType(m2,m2.outerSize()-1);
+ }
}