aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-08-21 18:40:56 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-08-21 18:40:56 +0000
commit58061f5ffc4d8ad178f6b640a3fd38e4ca341051 (patch)
treeac374a8b5a3ed4fe60e1eccce55ab2a4f764374c /Eigen
parent60804c306dd9ad42e82402f25d31587cf749f3bb (diff)
extend sparse unit test and more bugfix, major todo: finilize the SparseSetter
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Sparse/SparseMatrix.h31
-rw-r--r--Eigen/src/Sparse/SparseMatrixBase.h2
2 files changed, 18 insertions, 15 deletions
diff --git a/Eigen/src/Sparse/SparseMatrix.h b/Eigen/src/Sparse/SparseMatrix.h
index 2504d9fd8..b34ed8fd2 100644
--- a/Eigen/src/Sparse/SparseMatrix.h
+++ b/Eigen/src/Sparse/SparseMatrix.h
@@ -84,16 +84,18 @@ class SparseMatrix : public SparseMatrixBase<SparseMatrix<_Scalar, _Flags> >
const int outer = RowMajor ? row : col;
const int inner = RowMajor ? col : row;
- int id = m_outerIndex[outer];
+ int start = m_outerIndex[outer];
int end = m_outerIndex[outer+1];
- // optimization: let's first check if it is the last coefficient
- // (very common in high level algorithms)
- if (end>0 && inner==m_data.index(end-1))
- return m_data.value(end-1);
- else if (id==end)
+ if (start==end)
return Scalar(0);
- const int* r = std::lower_bound(&m_data.index(id),&m_data.index(end),inner);
- return (*r==inner) ? m_data.value(r-&m_data.index(0)) : Scalar(0);
+ else if (end>0 && inner==m_data.index(end-1))
+ return m_data.value(end-1);
+ // ^^ optimization: let's first check if it is the last coefficient
+ // (very common in high level algorithms)
+
+ const int* r = std::lower_bound(&m_data.index(start),&m_data.index(end),inner);
+ const int id = r-&m_data.index(0);
+ return ((*r==inner) && (id<end)) ? m_data.value(id) : Scalar(0);
}
inline Scalar& coeffRef(int row, int col)
@@ -101,13 +103,14 @@ class SparseMatrix : public SparseMatrixBase<SparseMatrix<_Scalar, _Flags> >
const int outer = RowMajor ? row : col;
const int inner = RowMajor ? col : row;
- int id = m_outerIndex[outer];
+ int start = m_outerIndex[outer];
int end = m_outerIndex[outer+1];
- ei_assert(end>=id && "you probably called coeffRef on a non finalized matrix");
- ei_assert(end>id && "coeffRef cannot be called on a zero coefficient");
- int* r = std::lower_bound(&m_data.index(id),&m_data.index(end),inner);
- ei_assert(*r==inner && "coeffRef cannot be called on a zero coefficient");
- return m_data.value(r-&m_data.index(0));
+ ei_assert(end>=start && "you probably called coeffRef on a non finalized matrix");
+ ei_assert(end>start && "coeffRef cannot be called on a zero coefficient");
+ int* r = std::lower_bound(&m_data.index(start),&m_data.index(end),inner);
+ const int id = r-&m_data.index(0);
+ ei_assert((*r==inner) && (id<end) && "coeffRef cannot be called on a zero coefficient");
+ return m_data.value(id);
}
public:
diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h
index e36e7e760..508972cbb 100644
--- a/Eigen/src/Sparse/SparseMatrixBase.h
+++ b/Eigen/src/Sparse/SparseMatrixBase.h
@@ -125,7 +125,7 @@ class SparseMatrixBase : public MatrixBase<Derived>
{
for ( ; col<it.index(); ++col)
s << "0 ";
- std::cout << it.value() << " ";
+ s << it.value() << " ";
++col;
}
for ( ; col<m.cols(); ++col)