This bugzilla service is closed. All entries have been migrated to
Bug 654 - Simultaneous row/column-vector and Matrix/Array conversion
Summary: Simultaneous row/column-vector and Matrix/Array conversion
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.2
Hardware: All All
: Normal Unknown
Assignee: Nobody
Depends on:
Blocks: 3.3
  Show dependency treegraph
Reported: 2013-09-05 11:37 UTC by nevion
Modified: 2019-12-04 12:36 UTC (History)
3 users (show)

failure case (265 bytes, text/x-c++src)
2013-09-05 11:37 UTC, nevion
no flags Details
fix (37.53 KB, patch)
2013-09-06 23:37 UTC, Gael Guennebaud
no flags Details | Diff

Description nevion 2013-09-05 11:37:30 UTC
Created attachment 378 [details]
failure case

This is at the very least not expected behavior - when using a mixed compile time and dynamic matrix (ie a list of 2d points) I get an assertion failure:

c++ -O0 -ggdb -DDEBUG -I/usr/include/eigen3 eigenfail.cpp -o /tmp/blah
blah: /usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:238: void Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 1, 0, -1, 1> >::resize(Index, Index) [Derived = Eigen::Matrix<float, -1, 1, 0, -1, 1>]: Assertion `(!(RowsAtCompileTime!=Dynamic) || (nbRows==RowsAtCompileTime)) && (!(ColsAtCompileTime!=Dynamic) || (nbCols==ColsAtCompileTime)) && (!(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic) || (nbRows<=MaxRowsAtCompileTime)) && (!(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic) || (nbCols<=MaxColsAtCompileTime)) && nbRows>=0 && nbCols>=0 && "Invalid sizes when resizing a matrix or array."' failed.

Example program attached.

Interestingly, explicitly calling .matrix at the end of the expression has no error detected.  This wasn't an issue in eigen 3.1.3 as far as I can tell.
Comment 1 Christoph Hertzberg 2013-09-05 12:30:25 UTC
I'm not sure if this is intended, but the actual problem is that you assign a row vector to a column vector. The following leads to the same result:

  Eigen::VectorXd a = Eigen::Array<double, 1, Eigen::Dynamic>(3);

but all of the following work:

  Eigen::VectorXd b = Eigen::Matrix<double, 1, Eigen::Dynamic>(3);
  Eigen::VectorXd c = Eigen::Array<double, 1, Eigen::Dynamic>(3).matrix();
  Eigen::VectorXd d = Eigen::Array<double, 1, Eigen::Dynamic>(3).transpose();

This behavior is analogue when interchanging Matrix and Vector and VectorXd to ArrayXd.
So apparently the feature of assigning a row vector to a column vector currently only works if both sides are matrices or both are arrays.
Comment 2 Christoph Hertzberg 2013-09-05 12:46:01 UTC
Exactly the same happens if all dimensions are fixed (or some are fixed and some dynamic):
  Eigen::Vector3d a = Eigen::Array<double, 1, 3>();  // fails
  Eigen::Vector3d b = Eigen::Matrix<double, 1, 3>(); // works
  Eigen::Vector3d c = Eigen::Array<double, 1, 3>().matrix();    // works
  Eigen::Vector3d d = Eigen::Array<double, 1, 3>().transpose(); // works
Comment 3 nevion 2013-09-06 04:42:33 UTC
Ah, sometimes I forget about column vs row vectors when working with Eigen::Vector... I'd figure for convenience with vectors as long as the elements are all accounted for there's no issues but that got me in trouble here.  I tend to think that this is a bug though if that feature exists.

So the question I have is will the feature be extended to handle the row/column mixing with array/matrix mixing?
Comment 4 Christoph Hertzberg 2013-09-06 10:00:34 UTC
Apparently, that feature existed in 3.1.* and unless it was removed on purpose, we should re-enable it (and write some unit-tests for it).
Comment 5 Gael Guennebaud 2013-09-06 23:37:05 UTC
Created attachment 379 [details]

The changset that introduced that regression was a regression fix ;)

The attached should fix the issue. Need to add unit tests before committing.

Also note that doing:

  RowVectorXd v(3);
  ArrayXf a;
  a = v;

works. The issue is only in the respective constructors.
Comment 6 Gael Guennebaud 2013-09-07 00:02:44 UTC
Changeset:   918ef70eaf49
User:        ggael
Date:        2013-09-07 00:01:04
Summary:     Fix bug 654: allow implicit transposition in Array to Matrix and Matrix to Array constructors
Changeset:   3a6f18c868f9
Branch:      3.2
User:        ggael
Date:        2013-09-07 00:01:04
Summary:     Fix bug 654: allow implicit transposition in Array to Matrix and Matrix to Array constructors
(grafted from 918ef70eaf498215d471597c04c33b4c5939991b)
Comment 7 Nobody 2019-12-04 12:36:29 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.