This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Generic algorithm with Eigen matrix factorizations

Tags: None
(comma "," separated)
bgreene
Registered Member
Posts
11
Karma
0
I'm trying to write a generic algorithm that will work with different Eigen
matrix factorization classes-- e.g. LLT, LDLT, LU, etc. I would like this
algorithm to be able to tell if the operation-- factorization or solve was
successful but it does not seem to be possible to do this in a generic way.
The LLT and LDLT classes have an info() method but the other factorization
classes do not. Is there an alternate way to do this? I'm using a very
recent Eigen3 build, by the way.

I've attached a simple example of what I tried.

Thanks.

Bill Greene
----------------------------------------------------------------
Code: Select all
#define NO_INFO 0

template<typename M, typename V, typename F>
bool genericSolve(M &m, V &rhs, F &solver, V &soln)
{
  solver.compute(m);
#if ! NO_INFO
  Eigen::ComputationInfo err = solver.info();
#else
  int err = 0;
#endif
  if(err)
    return false;
  soln = solver.solve(rhs);
#if ! NO_INFO
  err = solver.info();
#endif
  if(err)
    return false;
  return true;
}

void genericSolveTest()
{
  const int n = 4;
  Eigen::MatrixXd a(4,4);
  a << 5.,-4.,1.,0.,
       -4.,6.,-4.,1.,
       1.,-4.,6.,-4.,
       0.,1.,-4.,5.;

  Eigen::VectorXd b(n), x(n), xExact(n);
  xExact << 8./5., 13./5., 12./5., 7./5.;
  b << 0.,1.,0.,0.;
  //Eigen::LDLT<Eigen::MatrixXd> factA;
  //Eigen::LLT<Eigen::MatrixXd> factA;
  Eigen::FullPivLU<Eigen::MatrixXd> factA; // fails, no info() method
  //Eigen::PartialPivLU<Eigen::MatrixXd> factA; // fails, no info() method
  genericSolve(a, b, factA, x);

  std::cout << "x\n" << x << std::endl;
  std::cout << "error\n" << x-xExact << std::endl;
}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes you are right, for consistency we have to add this info() method to *LU and *QR


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora