mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-20 20:04:26 +08:00
Add missing nonZeros() overload in Block<SparseMatrixBase<>>
This commit is contained in:
parent
b93520b1a5
commit
5c2d1b4710
@ -52,15 +52,25 @@ public:
|
|||||||
|
|
||||||
inline BlockImpl(const XprType& xpr, int i)
|
inline BlockImpl(const XprType& xpr, int i)
|
||||||
: m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
|
: m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
|
||||||
{}
|
{std::cout << __LINE__ << "\n";}
|
||||||
|
|
||||||
inline BlockImpl(const XprType& xpr, int startRow, int startCol, int blockRows, int blockCols)
|
inline BlockImpl(const XprType& xpr, int startRow, int startCol, int blockRows, int blockCols)
|
||||||
: m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
|
: m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
|
||||||
{}
|
{std::cout << __LINE__ << "\n";}
|
||||||
|
|
||||||
EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
|
EIGEN_STRONG_INLINE Index rows() const { return IsRowMajor ? m_outerSize.value() : m_matrix.rows(); }
|
||||||
EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
|
EIGEN_STRONG_INLINE Index cols() const { return IsRowMajor ? m_matrix.cols() : m_outerSize.value(); }
|
||||||
|
|
||||||
|
Index nonZeros() const
|
||||||
|
{
|
||||||
|
Index nnz = 0;
|
||||||
|
Index end = m_outerStart + m_outerSize.value();
|
||||||
|
for(int j=m_outerStart; j<end; ++j)
|
||||||
|
for(typename XprType::InnerIterator it(m_matrix, j); it; ++it)
|
||||||
|
++nnz;
|
||||||
|
return nnz;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
typename XprType::Nested m_matrix;
|
typename XprType::Nested m_matrix;
|
||||||
@ -115,11 +125,11 @@ public:
|
|||||||
|
|
||||||
inline BlockImpl(const SparseMatrixType& xpr, int i)
|
inline BlockImpl(const SparseMatrixType& xpr, int i)
|
||||||
: m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
|
: m_matrix(xpr), m_outerStart(i), m_outerSize(OuterSize)
|
||||||
{}
|
{std::cout << __LINE__ << "\n";}
|
||||||
|
|
||||||
inline BlockImpl(const SparseMatrixType& xpr, int startRow, int startCol, int blockRows, int blockCols)
|
inline BlockImpl(const SparseMatrixType& xpr, int startRow, int startCol, int blockRows, int blockCols)
|
||||||
: m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
|
: m_matrix(xpr), m_outerStart(IsRowMajor ? startRow : startCol), m_outerSize(IsRowMajor ? blockRows : blockCols)
|
||||||
{}
|
{std::cout << __LINE__ << "\n";}
|
||||||
|
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other)
|
inline BlockType& operator=(const SparseMatrixBase<OtherDerived>& other)
|
||||||
@ -307,13 +317,13 @@ public:
|
|||||||
m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
|
m_startCol( (BlockRows==XprType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
|
||||||
m_blockRows(xpr.rows()),
|
m_blockRows(xpr.rows()),
|
||||||
m_blockCols(xpr.cols())
|
m_blockCols(xpr.cols())
|
||||||
{}
|
{std::cout << __LINE__ << "\n";}
|
||||||
|
|
||||||
/** Dynamic-size constructor
|
/** Dynamic-size constructor
|
||||||
*/
|
*/
|
||||||
inline BlockImpl(const XprType& xpr, int startRow, int startCol, int blockRows, int blockCols)
|
inline BlockImpl(const XprType& xpr, int startRow, int startCol, int blockRows, int blockCols)
|
||||||
: m_matrix(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(blockRows), m_blockCols(blockCols)
|
: m_matrix(xpr), m_startRow(startRow), m_startCol(startCol), m_blockRows(blockRows), m_blockCols(blockCols)
|
||||||
{}
|
{std::cout << __LINE__ << "\n";}
|
||||||
|
|
||||||
inline int rows() const { return m_blockRows.value(); }
|
inline int rows() const { return m_blockRows.value(); }
|
||||||
inline int cols() const { return m_blockCols.value(); }
|
inline int cols() const { return m_blockCols.value(); }
|
||||||
|
@ -199,6 +199,8 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
VERIFY(j==numext::real(m3.innerVector(j).lastCoeff()));
|
VERIFY(j==numext::real(m3.innerVector(j).lastCoeff()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VERIFY(m3.innerVector(j0).nonZeros() == m3.transpose().innerVector(j0).nonZeros());
|
||||||
|
|
||||||
//m2.innerVector(j0) = 2*m2.innerVector(j1);
|
//m2.innerVector(j0) = 2*m2.innerVector(j1);
|
||||||
//refMat2.col(j0) = 2*refMat2.col(j1);
|
//refMat2.col(j0) = 2*refMat2.col(j1);
|
||||||
//VERIFY_IS_APPROX(m2, refMat2);
|
//VERIFY_IS_APPROX(m2, refMat2);
|
||||||
@ -227,6 +229,8 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
|
|
||||||
VERIFY_IS_APPROX(m2, refMat2);
|
VERIFY_IS_APPROX(m2, refMat2);
|
||||||
|
|
||||||
|
VERIFY(m2.innerVectors(j0,n0).nonZeros() == m2.transpose().innerVectors(j0,n0).nonZeros());
|
||||||
|
|
||||||
m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0);
|
m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0);
|
||||||
if(SparseMatrixType::IsRowMajor)
|
if(SparseMatrixType::IsRowMajor)
|
||||||
refMat2.middleRows(j0,n0) = (refMat2.middleRows(j0,n0) + refMat2.middleRows(j1,n0)).eval();
|
refMat2.middleRows(j0,n0) = (refMat2.middleRows(j0,n0) + refMat2.middleRows(j1,n0)).eval();
|
||||||
@ -234,7 +238,6 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
refMat2.middleCols(j0,n0) = (refMat2.middleCols(j0,n0) + refMat2.middleCols(j1,n0)).eval();
|
refMat2.middleCols(j0,n0) = (refMat2.middleCols(j0,n0) + refMat2.middleCols(j1,n0)).eval();
|
||||||
|
|
||||||
VERIFY_IS_APPROX(m2, refMat2);
|
VERIFY_IS_APPROX(m2, refMat2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test basic computations
|
// test basic computations
|
||||||
|
Loading…
x
Reference in New Issue
Block a user