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

Optimization?

Tags: None
(comma "," separated)
sbalian
Registered Member
Posts
1
Karma
0

Optimization?

Wed Sep 30, 2015 3:23 am
Hi,

This is not a problem/bug, just wondering if anyone can help with optimizing the following expression if possible.

Code: Select all
 
return A*(a.asDiagonal())*(A.adjoint());


A is MatrixXcd, a is VectorXcd and the result is MatrixXcd.

Thanks!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Optimization?

Thu Oct 01, 2015 7:53 am
You can exploit that the result is self-adjoint this way:
Code: Select all
MatrixXcd B = a.asDiagonal()*A;
MatrixXcd res(a.size(),a.size());
res.triangularView<Lower>() = A*B.adjoint();
res.triangularView<Upper>() = res.adjoint(); // if you need the full matrix only

If your matrices are large enough (>200x200), then you should get an almost x2 speedup.


Bookmarks



Who is online

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