This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 654

Summary: Simultaneous row/column-vector and Matrix/Array conversion
Product: Eigen Reporter: nevion
Component: Core - generalAssignee: Nobody <eigen.nobody>
Status: RESOLVED FIXED    
Severity: Unknown CC: chtz, gael.guennebaud, jacob.benoit.1
Priority: Normal    
Version: 3.2   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 558    
Attachments:
Description Flags
failure case
none
fix none

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
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
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
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]
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.
Comment 6 Gael Guennebaud 2013-09-07 00:02:44 UTC
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)
Comment 7 Nobody 2019-12-04 12:36:29 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com'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: https://gitlab.com/libeigen/eigen/issues/654.