This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Unusual block operation compiler error

Tags: None
(comma "," separated)
amackey
Registered Member
Posts
2
Karma
0
Hello

I'm confused by the behavior of this code snippet, a block operation matrix product:
Code: Select all
  Eigen::MatrixXd D = Eigen::MatrixXd::Random(3,4);

  Eigen::MatrixXd row(1,5); row << 1,2,3,4,5;
  Eigen::MatrixXd column = D.col(1);

  // this line causes a compile time error
  //Eigen::MatrixXd prod = (D.col(1))*(row.leftCols(3));

  // this line is fine
  Eigen::MatrixXd prod = (column)*(row.leftCols(3));

  std::cout << prod << "\n";


The compiler error is "YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT" and it's coming from MapBase. This is using gcc 4.7.

Why is the temporary "column" variable necessary for the code to compile?

Thanks!
Alan
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
That's indeed a bug in Eigen. The reason it has not been detected so far is that your use case is rather unusual because it is not recommended at all (for performance reasons) to use general MatrixXd to represent vectors. "row" should be a RowVectorXd. So what happens is the following:

Eigen knows at compile time that "D.col(1)" is a column vector, so when you perform the multiplication with "row.leftCols(3)", Eigen also determines at compile time that "row.leftCols(3)" is actually a row vector. Therefore, "row.leftCols(3)" gets read through 1D indexes and the implementation of "row.leftCols(3)" complains because it still see itself as a general 2D sub-matrix.

Doing row.col(0).head(3) will also do the trick.

Let's see if this can be easily fixed...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Partial fix:

https://bitbucket.org/eigen/eigen/commits/ed3a129e7e2b/
https://bitbucket.org/eigen/eigen/commits/792917d7f245/

The following still won't compile:

Eigen::MatrixXd prod = (D.col(1))*(row.block(0,0,1,3));

but fixing this implies transforming this static assertion into a runtime one while this actually reveal a bad use of the API.
amackey
Registered Member
Posts
2
Karma
0
Thanks for the explanation and the tip, I'll switch to a row vector.


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]