aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/SparseCore/SparseBlock.h
diff options
context:
space:
mode:
Diffstat (limited to 'Eigen/src/SparseCore/SparseBlock.h')
-rw-r--r--Eigen/src/SparseCore/SparseBlock.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/Eigen/src/SparseCore/SparseBlock.h b/Eigen/src/SparseCore/SparseBlock.h
index 3119686c4..777fd1b76 100644
--- a/Eigen/src/SparseCore/SparseBlock.h
+++ b/Eigen/src/SparseCore/SparseBlock.h
@@ -237,15 +237,23 @@ class SparseInnerVectorSet<SparseMatrix<_Scalar, _Options, _Index>, Size>
Index nonZeros() const
{
- return std::size_t(m_matrix._outerIndexPtr()[m_outerStart+m_outerSize.value()])
- - std::size_t(m_matrix._outerIndexPtr()[m_outerStart]);
+ if(m_matrix.compressed())
+ return std::size_t(m_matrix._outerIndexPtr()[m_outerStart+m_outerSize.value()])
+ - std::size_t(m_matrix._outerIndexPtr()[m_outerStart]);
+ else if(m_outerSize.value()==0)
+ return 0;
+ else
+ return Map<const Matrix<Index,Size,1> >(m_matrix._innerNonZeroPtr(), m_outerSize.value()).sum();
}
const Scalar& lastCoeff() const
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(SparseInnerVectorSet);
eigen_assert(nonZeros()>0);
- return m_matrix._valuePtr()[m_matrix._outerIndexPtr()[m_outerStart+1]-1];
+ if(m_matrix.compressed())
+ return m_matrix._valuePtr()[m_matrix._outerIndexPtr()[m_outerStart+1]-1];
+ else
+ return m_matrix._valuePtr()[m_matrix._outerIndexPtr()[m_outerStart]+m_matrix._innerNonZeroPtr()[m_outerStart]-1];
}
// template<typename Sparse>