微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用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 举报,一经查实,本站将立刻删除。