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

typedefs and RowsAtCompileTime

Tags: None
(comma "," separated)
mpmcl
Registered Member
Posts
19
Karma
0

typedefs and RowsAtCompileTime

Thu Sep 10, 2009 1:39 pm
I declared a typedef as

typedef Matrix<double, Dynamic, 4> GMatrix;

thinking that it should be more efficient than MatrixXd.

Later, I have to resize, at runtime, e.g.,

aMatrix.resize(N, 4)

where N is now known.

One must still specify the number of columns; the code fails otherwise. Is there then any benefit to specifying the columns in advance?

BTW, I tried several variations for replacing Dynamic with RowsAtCompileTIme (in another program) but the compiler complained that RowsAtCompileTIme was not in scope. What should the syntax be? Or is there some additional #include necessary?

Thanks.
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: typedefs and RowsAtCompileTime

Thu Sep 10, 2009 3:21 pm
when you do

typedef Matrix<double, Dynamic, 4> GMatrix;

then GMatrix is a matrix type where ColsAtCompileTime=4. Eigen takes advantage of this automatically.

It's true that when you call resize in Eigen 2.0 you still must pass the number of columns, even though it's known at compile time. That doesn't meant that anything is un-optimized. The number passed is only used in an assertion and if you disable asserts (define NDEBUG) then it's not used at all.

In the development branch, you can do matrix.resize(N,NoChange).

In eigen 2.0 you can do: matrix.resize(N,GMatrix::ColsAtCompileTime), that should definitely work. No, there's no additional header to include.

Of course that only is good if you're sure that GMatrix has known-at-compile-time number of cols. Otherwise, a safer (and just as fast, thanks to the compiler optimizing) alternative is: matrix.resize(N,matrix.cols());


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]