[eigen] MappedSparseMatrix.coeff() uses RowMajor but shouldn't it be IsRowMajor |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
Hi,
in MappedSparseMatrix there is a bug when accessing the coefficients.
RowMajor is used to determine the storage order but RowMajor is
constant. I think using IsRowMajor was intended.
I'm attaching a small program that will fail and a diff against the
current trunk.
Regards,
Jens
#include <Eigen/Sparse>
int main() {
typedef Eigen::SparseMatrix<int, Eigen::ColMajor> Matrix;
typedef Eigen::MappedSparseMatrix<int, Eigen::ColMajor> MatrixMapped;
Matrix foo(10,10);
foo.setZero();
foo.insert(1, 5) = 2;
foo.finalize();
for (int col = 0; col < foo.cols(); col++)
for (Matrix::InnerIterator it(foo, col); it; ++it) {
assert(foo.coeff(it.row(), it.col()) == it.value());
}
MatrixMapped foo_mapped(foo.rows(),
foo.cols(),
foo.nonZeros(),
foo._outerIndexPtr(),
foo._innerIndexPtr(),
foo._valuePtr());
// this will fail
// due to MappedSparseMatrix.coeff uses RowMajor
// but it should IsRowMajor
for (int col = 0; col < foo_mapped.cols(); col++)
for (MatrixMapped::InnerIterator it(foo_mapped, col); it; ++it) {
assert(foo_mapped.coeff(it.row(), it.col()) == it.value());
}
}
Index: Eigen/src/Sparse/MappedSparseMatrix.h
===================================================================
--- Eigen/src/Sparse/MappedSparseMatrix.h (revision 966527)
+++ Eigen/src/Sparse/MappedSparseMatrix.h (working copy)
@@ -77,8 +77,8 @@
inline Scalar coeff(int row, int col) const
{
- const int outer = RowMajor ? row : col;
- const int inner = RowMajor ? col : row;
+ const int outer = IsRowMajor ? row : col;
+ const int inner = IsRowMajor ? col : row;
int start = m_outerIndex[outer];
int end = m_outerIndex[outer+1];
@@ -96,8 +96,8 @@
inline Scalar& coeffRef(int row, int col)
{
- const int outer = RowMajor ? row : col;
- const int inner = RowMajor ? col : row;
+ const int outer = IsRowMajor ? row : col;
+ const int inner = IsRowMajor ? col : row;
int start = m_outerIndex[outer];
int end = m_outerIndex[outer+1];