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

Passing Block as argument to <<

Tags: None
(comma "," separated)
MrFrankly
Registered Member
Posts
4
Karma
0

Passing Block as argument to <<

Sat Oct 09, 2010 9:30 am
I'm trying to use the elements of a column as the new elements of a matrix as follows:

Code: Select all
Matrix<T, 3, 3> H;
Eigen::SVD<Matrix<T, Eigen::Dynamic, 9> > svd(A);
H << svd.matrixV().col(8);


Essentially I want H to be made up of the 9 elements in the col(8) return value. The same as doing H << 1, 2, 3, ... 9.

But when I do this I get an assertion failed because the col(8) return value has a larger number of cols. Sounds fair, so how do I reshape the col(8) return value to fit in H?

(Of course I could do it with a small loop or writing out the arguments but an elegant library as Eigen must have a nicer way of doing this).

I'm using Eigen 2.0.15 btw.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Normally I'd say use Map to reshape the underlying plain array as a 3x3 matrix, but in your case that is relying on matrixV being stored in column-major order, which doesn't seem to be worth it. Why don't you slice it in 3 parts?

H << svd.matrixV().col(8).start(3),
svd.matrixV().col(8).segment(3,3),
svd.matrixV().col(8).end(3);


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

Re: Passing Block as argument to <<

Sun Oct 10, 2010 5:36 pm
That's indeed quite a good solution - I never thought about using segment().

Thanks very much for your help.


Bookmarks



Who is online

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