mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-21 12:24:25 +08:00
Fix regression in SparseMatrix::ReverseInnerIterator
This commit is contained in:
parent
f4722aa479
commit
eedb87f4ba
@ -224,11 +224,11 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_start.value() = mat.outerIndexPtr()[outer];
|
m_start = mat.outerIndexPtr()[outer];
|
||||||
if(mat.isCompressed())
|
if(mat.isCompressed())
|
||||||
m_id = mat.outerIndexPtr()[outer+1];
|
m_id = mat.outerIndexPtr()[outer+1];
|
||||||
else
|
else
|
||||||
m_id = m_start.value() + mat.innerNonZeroPtr()[outer];
|
m_id = m_start + mat.innerNonZeroPtr()[outer];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,14 +254,15 @@ class SparseCompressedBase<Derived>::ReverseInnerIterator
|
|||||||
inline Index row() const { return IsRowMajor ? m_outer.value() : index(); }
|
inline Index row() const { return IsRowMajor ? m_outer.value() : index(); }
|
||||||
inline Index col() const { return IsRowMajor ? index() : m_outer.value(); }
|
inline Index col() const { return IsRowMajor ? index() : m_outer.value(); }
|
||||||
|
|
||||||
inline operator bool() const { return (m_id > m_start.value()); }
|
inline operator bool() const { return (m_id > m_start); }
|
||||||
|
|
||||||
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;
|
||||||
const internal::variable_if_dynamic<Index,Derived::IsVectorAtCompileTime?0:Dynamic> m_start;
|
Index m_start;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
@ -219,6 +219,36 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test reverse iterators
|
||||||
|
{
|
||||||
|
DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
|
||||||
|
SparseMatrixType m2(rows, cols);
|
||||||
|
initSparse<Scalar>(density, refMat2, m2);
|
||||||
|
std::vector<Scalar> ref_value(m2.innerSize());
|
||||||
|
std::vector<Index> ref_index(m2.innerSize());
|
||||||
|
if(internal::random<bool>())
|
||||||
|
m2.makeCompressed();
|
||||||
|
for(Index j = 0; j<m2.outerSize(); ++j)
|
||||||
|
{
|
||||||
|
Index count_forward = 0;
|
||||||
|
|
||||||
|
for(typename SparseMatrixType::InnerIterator it(m2,j); it; ++it)
|
||||||
|
{
|
||||||
|
ref_value[ref_value.size()-1-count_forward] = it.value();
|
||||||
|
ref_index[ref_index.size()-1-count_forward] = it.index();
|
||||||
|
count_forward++;
|
||||||
|
}
|
||||||
|
Index count_reverse = 0;
|
||||||
|
for(typename SparseMatrixType::ReverseInnerIterator it(m2,j); it; --it)
|
||||||
|
{
|
||||||
|
VERIFY_IS_APPROX( std::abs(ref_value[ref_value.size()-count_forward+count_reverse])+1, std::abs(it.value())+1);
|
||||||
|
VERIFY_IS_EQUAL( ref_index[ref_index.size()-count_forward+count_reverse] , it.index());
|
||||||
|
count_reverse++;
|
||||||
|
}
|
||||||
|
VERIFY_IS_EQUAL(count_forward, count_reverse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// test transpose
|
// test transpose
|
||||||
{
|
{
|
||||||
DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
|
DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user