连续修剪的产品崩溃EIGEN

Successive pruned product crashing EIGEN

本文关键字:崩溃 EIGEN 修剪 连续      更新时间:2023-10-16

我有一个错误,我在使用Eigen和SparseMatrix以及Visual Studio Pro 2013时无法理解

连续修剪的产品在 DEBUG 模式下完美运行,但它们很长。我想切换到 RELEASE,而不更改代码中的任何内容,但程序在这种模式下崩溃。

我遇到了访问冲突错误c0000005(法语VS,对此感到抱歉(:

Message de résultat  :  Code de l'exception : C0000005
StackTrace de résultat  :   
à Eigen::internal::sparse_sparse_product_with_pruning_impl<Eigen::SparseMatrix<short,0,int>,Eigen::SparseMatrix<short,0,int>,Eigen::SparseMatrix<short,0,int> >() dans [..]eigensrcsparsecoresparsesparseproductwithpruning.h:ligne 61
    à Eigen::internal::sparse_sparse_product_with_pruning_selector<Eigen::SparseMatrix<short,1,int>,Eigen::SparseMatrix<short,1,int>,Eigen::SparseMatrix<short,0,int>,1,1,0>::run() dans [..]eigensrcsparsecoresparsesparseproductwithpruning.h:ligne 143
    à Eigen::internal::unary_evaluator<Eigen::SparseView<Eigen::Product<Eigen::SparseMatrix<short,1,int>,Eigen::SparseMatrix<short,1,int>,2> >,Eigen::internal::IteratorBased,short>::unary_evaluator<Eigen::SparseView<Eigen::Product<Eigen::SparseMatrix<short,1,int>,Eigen::SparseMatrix<short,1,int>,2> >,Eigen::internal::IteratorBased,short>() dans [..]eigensrcsparsecoresparseproduct.h:ligne 158
    à Eigen::SparseMatrix<short,1,int>::operator=<Eigen::SparseView<Eigen::Product<Eigen::SparseMatrix<short,1,int>,Eigen::SparseMatrix<short,1,int>,2> > >() dans [..]eigensrcsparsecoresparsematrix.h:ligne 1080
    à IncMethod_Tester::EigenMatrix_Tests::NullMultiplication() dans [...]integrity_tests.cpp:ligne 856

integrity_test测试的代码如下:

        SparseMatrix<short, RowMajor> A(0, 1);
        SparseMatrix<short, RowMajor> B(1, 5);
        SparseMatrix<short, RowMajor> C(5, 4);
        std::vector<Triplet<short>> values;
        values.push_back(Triplet<short>(0, 4, 1));
        values.push_back(Triplet<short>(0, 3, 1));
        values.push_back(Triplet<short>(0, 2, 1));
        B.setFromTriplets(values.begin(), values.end());
        std::vector<Triplet<short>> values2;
        values2.push_back(Triplet<short>(0, 0, 1));
        values2.push_back(Triplet<short>(1, 1, 1));
        values2.push_back(Triplet<short>(2, 2, -1));
        values2.push_back(Triplet<short>(2, 3, -1));
        values2.push_back(Triplet<short>(3, 2, 1));
        values2.push_back(Triplet<short>(4, 3, 1));
        C.setFromTriplets(values2.begin(), values2.end());

        std::fstream f("NULLMULTIPLICATION", std::fstream::out);
        f << "A MATRIX (" << A.rows() << "," << A.cols() << ")" <<std::endl << A << std::endl;
        f << "B MATRIX (" << B.rows() << "," << B.cols() << ")" <<std::endl<< B << std::endl;
        f << "C MATRIX (" << C.rows() << "," << C.cols() << ")" << std::endl << C << std::endl;
        B = (A*B).pruned();
        f << "AB MATRIX (" << B.rows() << "," << B.cols() << ")" << std::endl << A << std::endl;
        B = (B*C).pruned();
        f << "B MATRIX (" << B.rows() << "," << B.cols() << ")" << std::endl << B << std::endl;

NULLMULTIPLICATION文件中的输出是:

A MATRIX (0,1)
B MATRIX (1,5)
0 0 1 1 1 
C MATRIX (5,4)
1 0 0 0 
0 1 0 0 
0 0 -1 -1 
0 0 1 0 
0 0 0 1 
AB MATRIX (0,5)

这意味着程序运行到:

B = (A*B).pruned();
B = (B*C).pruned();

我在这里做错了什么吗?我尝试创建临时变量,但它仍然崩溃:

SparseMatrix<short, RowMajor> D = (A*B).pruned();
SparseMatrix<short, RowMajor> E = (D*C).pruned();

对此产品有什么建议吗?我可能在多个稀疏产品的语法上是错误的?

提前谢谢。

好的,

我找到了导致错误的原因。这是由于修剪产品中的维度为 0,我只是通过在产品之前测试所涉及的任何矩阵是否具有空维度来解决它,如果是这样,只需在不修剪的情况下做一个普通产品。