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

diagonal of matrix product

Tags: None
(comma "," separated)
pfabio
Registered Member
Posts
2
Karma
0

diagonal of matrix product

Wed Nov 09, 2011 1:31 pm
Dear all,
I am a newcomer to Eigen, and I have the following question.
I multiply two (large) square matrices, A and B. Actually, I only need the diagonal of A*B, not all the product matrix. On judging from the time taken by Eigen to complete the operation

v = (A*B).diagonal();,

I suspect that Eigen <first> calculates A*B and <then> extracts the diagonal,
which is quite a waste of CPU.
Is this correct? If so, is there a way to calculate the diagonal, discarding the other components of A*B?

Thanks for your help
jitseniesen
Registered Member
Posts
204
Karma
2

Re: diagonal of matrix product

Wed Nov 09, 2011 2:36 pm
pfabio wrote:v = (A*B).diagonal();,

I suspect that Eigen <first> calculates A*B and <then> extracts the diagonal,
which is quite a waste of CPU.
Is this correct?

Yes, this is correct. In most case, it's best to calculate the product first, but in your case it is probably better to calculate the coefficients you need one by one. You can instruct Eigen to do this using:

v = A.lazyProduct(B).diagonal();
pfabio
Registered Member
Posts
2
Karma
0

Re: diagonal of matrix product

Wed Nov 09, 2011 4:17 pm
Thank you jitseniesen, it seems to work faster now!


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]