Bugzilla – Bug 654

Simultaneous row/column-vector and Matrix/Array conversion

Last modified: 2013-09-07 00:02:44 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 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.

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.

Addendum: 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

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?

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).

Created attachment 379 [details] fix The changset that introduced that regression was a regression fix ;) https://bitbucket.org/eigen/eigen/commits/46124a1d2c6cafdee13dfe1c916e2c1e185d3c66 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.

https://bitbucket.org/eigen/eigen/commits/918ef70eaf49/ 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 https://bitbucket.org/eigen/eigen/commits/3a6f18c868f9/ 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)