Bugzilla – Bug 1272
Comma initializer error for matrix with 0 columns
Last modified: 2016-08-24 14:51:58 UTC
const int rows = 3;
const int cols1 = 1;
const int cols2 = 0; // If changed to cols2 != 0, works fine
Eigen::MatrixXd A1(rows, cols1);
Eigen::MatrixXd A2(rows, cols2);
Eigen::MatrixXd B(rows, cols1+cols2);
B << A1, A2;
Produces the following assertion at runtime:
Assertion failed: m_row+m_currentBlockRows<=m_xpr.rows() && "Too many rows passe
d to comma initializer (operator<<)", file v:\002\source\3rdparty\eigen\eigen-3.
3-beta2\include\eigen\src/Core/CommaInitializer.h, line 94
I expected be the code to work find and B to be equal to A1. I know, that this is a nasty corner case... not introduced by me, but used in a library I want to use.
This issue may be strongly related to #1242, which had a similar problem with rows instead of columns.
I fixed it here:
The only remaining border case are things like
B << MatrixXd(2,0), MatrixXd(2,0);
Here it is not clear immediately, if the second block is part of the first two rows or shall start the next rows.
Solving more complicated variations of that would require some sort of backtracking which I think is not worth the effort.
Alternatively, we could disable the assertion in the destructor if the total size is zero.
Puh... I also think, that backtracking in such cases is not required.
Disabling the assertion for matrices with zero size sounds like a good idea to me, but you are the expert!
Anyway, thanks for the fix :)
I decided to disable the "Too few coefficients" assertion for the cols==0 case, and I moved the assertion into the "finished()" method:
I also backported the changes to the 3.2 branch:
*** Bug 1280 has been marked as a duplicate of this bug. ***