extend sparse unit test and more bugfix, major todo: finilize the SparseSetter

This commit is contained in:
Gael Guennebaud
2008-08-21 18:40:56 +00:00
parent 60804c306d
commit 58061f5ffc
3 changed files with 98 additions and 50 deletions

View File

@@ -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: