New user self-registration is currently disabled. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Bug 1272 - Comma initializer error for matrix with 0 columns
Comma initializer error for matrix with 0 columns
Status: RESOLVED FIXED
Product: Eigen
Classification: Unclassified
Component: Core - general
3.3 (current stable)
x86 - 64-bit Windows
: Normal Crash
Assigned To: Nobody
:
: 1280 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-08-05 13:13 UTC by Michael Hüpkes
Modified: 2016-08-24 14:51 UTC (History)
5 users (show)



Attachments

Description Michael Hüpkes 2016-08-05 13:13:07 UTC
Example code:

```
#include <Eigen/Dense>

void test()
{
	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.
Comment 1 Christoph Hertzberg 2016-08-08 15:40:14 UTC
I fixed it here:

https://bitbucket.org/eigen/eigen/commits/4df84dee97d2f3eaeb

The only remaining border case are things like
  MatrixXd B(4,0);
  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.
Comment 2 Michael Hüpkes 2016-08-09 07:54:01 UTC
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 :)
Comment 3 Christoph Hertzberg 2016-08-12 13:32:27 UTC
I decided to disable the "Too few coefficients" assertion for the cols==0 case, and I moved the assertion into the "finished()" method:
https://bitbucket.org/eigen/eigen/commits/be75b8ad7d1e9

I also backported the changes to the 3.2 branch:
https://bitbucket.org/eigen/eigen/commits/435ba1a184931
https://bitbucket.org/eigen/eigen/commits/10f2cc514f6ca
Comment 4 Christoph Hertzberg 2016-08-24 14:51:58 UTC
*** Bug 1280 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.