在Eigen 3.2稀疏矩阵中有一个名为'nonZeros'的方法,它返回非零元素的计数。这种方法似乎在Eigen 3.3中消失了。如何获得3.3中的非零数?
答案 0 :(得分:1)
它还在那里。在Eigen/src/SparseCore/SparseCompressedBase.h
第56行中有一个定义(适用于SparseCompressedBase
)。
template<typename Derived>
class SparseCompressedBase
: public SparseMatrixBase<Derived>
{
...
protected:
typedef typename Base::IndexVector IndexVector;
Eigen::Map<IndexVector> innerNonZeros() { return Eigen::Map<IndexVector>(innerNonZeroPtr(), isCompressed()?0:derived().outerSize()); }
const Eigen::Map<const IndexVector> innerNonZeros() const { return Eigen::Map<const IndexVector>(innerNonZeroPtr(), isCompressed()?0:derived().outerSize()); }
public:
/** \returns the number of non zero coefficients */
inline Index nonZeros() const
{
if(Derived::IsVectorAtCompileTime && outerIndexPtr()==0)
return derived().nonZeros();
更重要的是,快速grep显示了所有定义(v3.3.0):
$ grep -rn&#34;索引nonZeros()&#34; *
src / Core / DenseBase.h:210:内联索引nonZeros()const {return size(); }
src / SparseCore / AmbiVector.h:39:索引nonZeros()const;
src / SparseCore / SparseBlock.h:42:索引nonZeros()const
src / SparseCore / SparseBlock.h:436:索引nonZeros()const {return Dynamic; }
src / SparseCore / SparseCompressedBase.h:56:内联索引nonZeros()const
src / SparseCore / SparseMap.h:87:内联索引nonZeros()const {return m_zero_nnz [1]; }
src / SparseCore / SparseTranspose.h:31:内联索引nonZeros()const {return derived()。nestedExpression()。nonZeros(); }
src / SparseCore / SparseVector.h:140:内联索引nonZeros()const {return m_data.size(); }