0

i am using Eigen::SPQR to solve a sparse matrix system Here is the minimal example which would give run time error

# include <Eigen/Core>
# include <Eigen/Sparse>
# include <Eigen/SparseLU>
# include <Eigen/SparseQR>
///  test eigen SPQR
    Eigen::SparseMatrix < double > A(500, 400);
    Eigen::VectorXd b(500);
    std::vector < Eigen::Triplet < double > > triplet;
    for( int i = 0; i < 500; i++ )
    {
        int r = rand() % 500;
        int c = rand() % 400;
        triplet.push_back( Eigen::Triplet < double > ( r, c, static_cast<double>(rand())/(RAND_MAX+1.0) ) );

        b(i) = static_cast<double>(rand())/(RAND_MAX+1.0);
    }
    A.setFromTriplets(triplet.begin(), triplet.end());
    Eigen::SPQR< Eigen::SparseMatrix < double > > spqrsolver(A);

    std::cout << A.rows() << " " << A.cols() << " "
              << b.rows() << " " << b.cols() << " "
              << spqrsolver.rows() << " " << spqrsolver.cols() << std::endl;
    Eigen::VectorXd X = spqrsolver.solve(b);

Output is 500 400 500 1 400 400. and error msg is "Assertion `this->rows()==B.rows() && "SPQR::solve(): invalid number of rows of the right hand side matrix B"' failed."

timrau
  • 22,578
  • 4
  • 51
  • 64
P. Preet
  • 15
  • 6
  • Can you add the initialization of `A` and `b`? – Avi Ginsburg Sep 17 '15 at 07:34
  • hi Avi. Initialization is complicated and application specific. its like 400 lines and lots of dependencies on other files. I believe initialization is correct. can i attach the file somewhere? – P. Preet Sep 17 '15 at 08:00
  • You are missing the output of `b.size()` which is what SPQR is complaining about. – ggael Sep 17 '15 at 19:41
  • hi ggael. here is output of A.rows() A.cols() b.rows() b.cols() spqrsolver.rows() spqrsolver.cols() 1108228 277057 1108228 1 277057 277057 – P. Preet Sep 19 '15 at 10:03
  • i dropped the idea of using Eigen and used SuiteSparse api directly. it worked. might be helpful to someone – P. Preet Sep 23 '15 at 04:48

0 Answers0