Registered Member
|
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. |
Registered Member
|
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! |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]