Registered Member
|
[Solved] Assertion `Flags&SelfAdjointBit' failed when calculating eigenvalues
Tue Dec 30, 2008 9:31 pm
Hi,
I'm an Eigen (and C++ newbie). I'm trying to calculate the eigenvalues of a 9x9 matrix. I'm getting the error: Matrix getDiagOfVec(Matrix v). What could be wrong? Here is a code snippet - Matrix3d getHomographyMatrix(Matrix p,Matrix q) { Matrix A; for(int i = 0;i dv; cm = getCrossMatrix(p.col(i)); dv = getDiagOfVec(q.col(i)); A.block(i * 3,0) = cm * dv; } cout << (A.tranpose() * A).eigenvalues(); } Except for the 'cout' line, the rest of the code is compiling and running correctly.
Last edited by vinodkhare on Tue Dec 30, 2008 10:06 pm, edited 1 time in total.
vinodkhare, proud to be a member of KDE forums since 2008-Dec.
|
Moderator
|
Hi,
currently, the eigenvalues() shortcut method is only for selfadjoint matrices. Fortunately, this is the case for you, but you still have to tell that to Eigen using marked(). Your example should be:
Alternatively (eg, if you want both the eigenvalues and eigenvectors without performing twice the decomposition), then you can directly use the SelfAdjointEigenSolver class:
|
Registered Member
|
Thanks! That did the trick.
However, now I'm curious. Why do I need to explicitly state that the matrix is self adjoint? Is this likely to go away in future versions of Eigen? And thanks for a great library. I've been hunting around for C++ matrix libraries for ages and never found anything so useful or elegant.
vinodkhare, proud to be a member of KDE forums since 2008-Dec.
|
Moderator
|
This is simply because: 1) it is much faster to compute the eigenvalues of a selfadjoint matrix than for a standard matrix. Since we provide algorithms for both cases, the user has to specify whether the matrix is selfadjoint or not, there is no runtime detection (which would be costly anyway). 2) we forgot to make the eigenvalues() method calls the generic algorithm when the matrix is non selfadjoint, this is why it currently fails to compile if you don't specify a selfadjoint matrix. So, yes, in the future "(A.transpose() * A).eigenvalues()" will work but it won't be optimal because it will use the generic algorithm while A.transpose() * A is selfadjoint...
thanks. |
Registered Member
|
RE: [Solved] Assertion `Flags&SelfAdjointBit' failed when calculating eigenvalues
Tue Dec 30, 2008 11:03 pm
I would just like to add a little comment:
here you are passing p and q by value which is inefficient (they get copied onto the stack) and potentially problematic (potential alignment issues). You really should rewrite that as:
That's called "passing by reference".
Last edited by bjacob on Tue Dec 30, 2008 11:04 pm, edited 1 time in total.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell