Registered Member
|
Hi,
I have a function that gets a VectorXf as an argument:
Now, when I pass a row of a matrix to this function by:
It doesn't work. But when I use:
My question is why doesn't the first option work, and what's the best way to pass a row of a matrix to a function. Thanks in advance, Yoav |
Moderator
|
because .row() or .col() does not return a VectorXf but a lightweight Block<> object. See this page to write generic functions:
http://eigen.tuxfamily.org/dox/TopicFun ... Types.html |
Registered Member
|
Thanks a lot! This was very helpful.
Now, assuming that I want to write a template function that is limited to get only vectors, or BlockVectors. 1. Is there a common abstract class for all vectors (/segments)? 2. How can I write a function that deduces the size of the vector as a constant in compile time? Thanks in advance, Yoav |
Moderator
|
There is no common base class for that, but you can use a static assert or boost::enable_if. e.g.:
foo(const MatrixBase<Derived>& vec) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived); } The underlying compile time test is: Derived::IsVectorAtCompileTime You can use this with enable_if. Useful compile-time information: Derived::SizeAtCompileTime Derived::RowsAtCompileTime Derived::ColsAtCompileTime Note that they might be equal to Dynamic if the size is not known at compile time! |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]