mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-19 11:24:26 +08:00
bug #557: make InnerIterator of sparse storage types more versatile by adding default-ctor, copy-ctor/assignment
This commit is contained in:
parent
6e0a86194c
commit
ec469700dc
@ -117,6 +117,24 @@ template<typename Derived>
|
|||||||
class SparseCompressedBase<Derived>::InnerIterator
|
class SparseCompressedBase<Derived>::InnerIterator
|
||||||
{
|
{
|
||||||
public:
|
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)
|
InnerIterator(const SparseCompressedBase& mat, Index outer)
|
||||||
: m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer)
|
: m_values(mat.valuePtr()), m_indices(mat.innerIndexPtr()), m_outer(outer)
|
||||||
{
|
{
|
||||||
@ -162,7 +180,8 @@ class SparseCompressedBase<Derived>::InnerIterator
|
|||||||
protected:
|
protected:
|
||||||
const Scalar* m_values;
|
const Scalar* m_values;
|
||||||
const StorageIndex* m_indices;
|
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_id;
|
||||||
Index m_end;
|
Index m_end;
|
||||||
private:
|
private:
|
||||||
|
@ -460,6 +460,33 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
refMat1.setIdentity();
|
refMat1.setIdentity();
|
||||||
VERIFY_IS_APPROX(m1, refMat1);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user