使用Eigen3库使用C ++以MatrixMarket形式存储稀疏矩阵

问题描述

我有一个生成稀疏块矩阵的C ++程序。我的目标是并排连接并最终将大矩阵存储在.mtx文件中。所以这就是我的做法:

 k=0;
 int length=6;
 Eigen::SparseMatrix<double> B_dash(length,length);
 while(k<340)
 {
 for(int j=0;j<100;j++) 
    {   
        // ---- Some other codes here containing the ind_matrix1,C,length,ind1,ind2 variables------- 

        Eigen::SparseMatrix<double> B_small(length,length); 

        // Building the B_small Matrix using the get_mappingMatrix below

        get_mappingMatrix(B_small,ind_matrix1,ind2); 
        
        // Defining a new sparse matrix to store the concatenated Matrix
        Eigen::SparseMatrix<double> B_temp(B_dash.rows(),B_dash.cols()+B_small.cols());
        
        // Concatenating the Matrices with
        B_temp.leftCols(B_dash.cols())=B_dash;
        B_temp.rightCols(B_small.cols())=B_small;
        
        B_dash  =B_temp.cast<double>();
    }
    cout<<"storing B: "<<'\n';
    cout<<"B_dash: \n"<<Eigen::MatrixXd(B_dash)<<'\n';
    string filename =  to_string((k+1)/time_jump)+".mtx";
    Eigen::saveMarket(B_dash,"/home/my_Matrix/"+filename);
    k++;
  }

但是,在看到存储的矩阵时,我看到了一些差异。在第一个条目之后,我立即看到条目“ 21932 17 0”,事实是,矩阵的尺寸仅为6x2040(即,文件的第一行认可)。为什么会出现此错误?我已在.mtx文件下面附加了一个图像。我在使用Eigen :: saveMarket函数存储的大多数.mtx文件中都得到了这些杂散值。 任何帮助将不胜感激,谢谢。

one of the .mtx file

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)