Registered Member
|
Hello all,
I would like to write some generic functions returning a matrix type. I'm halfway there from the page: http://eigen.tuxfamily.org/dox/TopicFun ... Types.html As an example:
Unfortunately, this does not compile:
I'm rather lost as what to do from here. Is there a simple way to do this, or is there an entirely different method that I need to follow? -- Damien |
Moderator
|
first, in "typename Eigen::MatrixBase<DerivedReturn>", the typename does not make any sense. Second, Eigen::MatrixBase<DerivedReturn> is not a concrete type, you cannot create an object of that type. Third, your function has 3 template arguments and only two of them can be deduced by the compiler from the argument types.
I guess that your function will do some complex computations, and so you probably simply want to return a concrete matrix object. In that case , you could e.g., return a: typename DerivedA::PlainObject |
Registered Member
|
Exactly... I'm just trying to get my head around the template syntax first Whilst I can see the DerivedA::PlainObject working for the same type as the first, what about if the matrix size is expected to change? For example, the multiply below:
Of course, the multiply function fails to compile, complaining of: "YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES" -- Damien |
Moderator
|
then you should return a Matrix<typename DerivedA::Scalar, ..., ...> where you replace the dots by the appropriate sizes computed using the DerivedA::RowsAtCompileTime, DerivedA::ColsAtCompileTime, etc. You have to be careful to correctly handle the cases where RowsAtCompileTime is Eigen::Dynamic, for instance if you have to multiply two dimensions....
|
Registered Member
|
Hi Gael,
The following seems to do the trick:
Thank you very much for your patience. -- Damien |
Moderator
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]