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

Fast way to permute the columns of a matrix?

Tags: None
(comma "," separated)
baoilleach
Registered Member
Posts
2
Karma
0
Is there an efficient (i.e. fast) way to permute the columns of an Eigen::MatrixXd?

I currently have a loop that fills in the columns of a new Matrix by copying from the old one with:
newmatrix.col(newindex) = oldmatrix.col(oldindex);

This seems to take a bit of time (more than I would expect), so I was wondering whether there is a better method. This is a 3 row x N column matrix where N would be in the range of 20 to 80 typically.

Thanks,
Noel
User avatar
bjacob
Registered Member
Posts
658
Karma
3
If your permutation is just a transposition (aka 'swap two columns') then you should use swap(), it is faster.

If you have a more general kind of permutation, there's no very easy answer as making your permutation efficient means have better memory locality, which is very hard with a general permutation.

If you're using Eigen 3, the best you could do, though, is use Eigen's high-level API for permutations, so if we ever make that faster, you'll benefit automatically. This requires your permutation indices to be stored in a PermutationMatrix object, and then you can simply use operator* to apply it. But for now, it won't be faster than your trivial code.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
baoilleach
Registered Member
Posts
2
Karma
0
Thanks Benoit.


Bookmarks



Who is online

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