This bugzilla service is closed. All entries have been migrated to
Bug 1272 - Comma initializer error for matrix with 0 columns
Summary: Comma initializer error for matrix with 0 columns
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: x86 - 64-bit Windows
: Normal Crash
Assignee: Nobody
: 1280 (view as bug list)
Depends on:
Reported: 2016-08-05 13:13 UTC by Michael Hüpkes
Modified: 2019-12-04 16:05 UTC (History)
5 users (show)


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:

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:

I also backported the changes to the 3.2 branch:
Comment 4 Christoph Hertzberg 2016-08-24 14:51:58 UTC
*** Bug 1280 has been marked as a duplicate of this bug. ***
Comment 5 Nobody 2019-12-04 16:05:24 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

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