【发布时间】:2019-06-11 14:02:39
【问题描述】:
我想比较两个Eigen::SparseMatrix
存在 res.isApprox(ans) 方法,但不幸的是,据我所知,在不同的稀疏模式的情况下,它会因断言而失败
AffineInvariantDeformerTest01: Eigen/src/SparseCore/SparseMatrix.h:934: void Eigen::internal::set_from_triplets(const InputIterator&, const InputIterator&, SparseMatrixType&, DupFunctor) [with InputIterator = __gnu_cxx::__normal_iterator<Eigen::Triplet<double, int>*, std::vector<Eigen::Triplet<double, int>, std::allocator<Eigen::Triplet<double, int> > > >; SparseMatrixType = Eigen::SparseMatrix<double, 0, int>; DupFunctor = Eigen::internal::scalar_sum_op<double, double>]: Assertion `it->row()>=0 && it->row()<mat.rows() && it->col()>=0 && it->col()<mat.cols()' failed.
我希望它用于单元测试,所以如果它不会那么快也没关系。可能我可以将稀疏矩阵转换为密集矩阵,但我希望存在更优雅的解决方案
编辑: 只是一种可以比较两个矩阵的稀疏模式的方法对我来说也可以
【问题讨论】:
-
如果稀疏模式不同,它应该返回
false,还是应该仍然是true,如果结构上不同的条目恰好/接近于零? -
@chtz 感谢您的评论!对于我的问题,不同的模式意味着不同的矩阵。
标签: c++ sparse-matrix eigen eigen3