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

Swapping eigenvectors with an empty matrix

Tags: None
(comma "," separated)
bpiwowar
Registered Member
Posts
6
Karma
0
OS
Hi,

in order to be more efficient and avoid copying matrices, I wanted to swap the eigenvectors with an empty matrix with

MatrixXd mX;
eigensolver.eigenvectors().swap(mX);

but eigenvectors() returns a const reference to the matrix. As I am not seeing any other solution, I am using a const_cast:

MatrixXd mX;
const_cast<Eigen::MatrixXd&>(eigensolver.eigenvectors()).swap(mX);

Is there any other solution? Is this way of doing (somehow) right?

Many thanks for any help
Benjamin
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
I guess your goal is to avoid a deep copy right ? However note that this copy is completely negligible compared to the cost of computing the eigenvectors.
bpiwowar
Registered Member
Posts
6
Karma
0
OS
Yes, this was the goal. I know the cost is far from the cost of computing the eigenvalues, but at least it can be easily reduced to almost nothing.

Thanks
Benjamin


Bookmarks



Who is online

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