Outer products assume vectors provide linear access
Submitted by Jitse Niesen
Assigned to Nobody
Link to original bugzilla bug (#822)
Version: 3.2
Description
This is prompted by a post of amackey at the forum at http://forum.kde.org/viewtopic.php?f=74&t=121501 . The following code does not compile with the dev branch (this is a slight simplification of the code posted at the forum):
Eigen::MatrixXd row(1,5);
Eigen::VectorXd col(3);
Eigen::MatrixXd prod = col * row.leftCols(3);
It hits the static assert YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT in MapBase.h:99 . Looking at the backtrace, Eigen recognizes the product as an outer product and thus wants to do col.coeff(i) * row.leftCols(3).coeff(j) but there is no coeff(Index) member function for row.leftCols(3) because this does not have linear access.
Rather confusingly, the code does work if col is a run-time vector; i.e. declared with
Eigen::MatrixXd col(3,1);
I think the solution would be for MapBase to provide a coeff(Index) member function if it is a run-time vector (i.e. either cols()=1 or rows()=1). Or would this break something somewhere?