Registered Member
|
I have a function that returns the rows and columns of a matrix selected by indicator arrays. It works and is happy as long as the input matrix has dynamic size, however I can't figure out how to make it work with fixed size matrices.
The problem is, that regardless of what gets passed in, the function needs to return either the corresponding Matrix/Array expression with the same scalar type, but a dynamic size. As a result, the return type of "typename DerivedData::PlainObject" is incorrect, but I can't figure out what it should be changed to. Returning "Eigen::Matrix<typename DerivedData::Scalar, Eigen::Dynamic, Eigen::Dynamic>" works, but forces the return type to always be a matrix instead of an array... thanks! -=Abe |
Moderator
|
There is no easy solution for that, here is one option:
Define two overloads for ArrayBase and MatrixBase (instead of DenseBase), and to keep the code factored, these overload will simply call a helper function. For instance the MatrixBase overload would looks like this: Matrix<...> ret; selectBlockByIndices_helper(m, rinds, cinds, ret); return ret; Another option would be to use meta programming: typename internal::conditional<internal::is_same<internal::traits<DerivedData>::XprKind,ArrayXpr>, Array<....>, Matrix<....> >::type that gives you either Array<...> or Matrix<....> depending on the expression kind of DerivedData. |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]