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

[Solved] Assertion `Flags&SelfAdjointBit' failed when calculating eigenvalues

Tags: None
(comma "," separated)
User avatar
vinodkhare
Registered Member
Posts
7
Karma
0
OS
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.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
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:

Code: Select all
cout ().eigenvalues();


Alternatively (eg, if you want both the eigenvalues and eigenvectors without performing twice the decomposition), then you can directly use the SelfAdjointEigenSolver class:

Code: Select all
SelfAdjointEigenSolver > eig(A.tranpose() * A);
eig.eigenvalues();
eig.eigenvectors();
User avatar
vinodkhare
Registered Member
Posts
7
Karma
0
OS
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.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
vinodkhare wrote: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?


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...

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.


thanks.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
I would just like to add a little comment:

vinodkhare wrote:Matrix3d getHomographyMatrix(Matrix p,Matrix q)


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:

Code: Select all
Matrix3d getHomographyMatrix(const Matrix & p, const Matrix & q)


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!


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell