[eigen] Aliasing bug with Transpose, possibly a ReturnByValue problem

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Dear all,

while browsing through Eigen's code, I found the following aliasing problem:

#include <Eigen/Eigen>
#include <iostream>

using namespace Eigen;

int main()
{
  VectorXd v = VectorXd::LinSpaced(15, 1, 15);
  MatrixXd M = Map<MatrixXd>(v.data(), 5, 3);

  Transpositions<Dynamic> T(3);
  T[0] = 2; T[1] = 0; T[2] = 0;
 
  MatrixXd M2 = T*M.topLeftCorner(3, 3);
  std::cout << M2 << std::endl << std::endl;
  M.bottomRightCorner(3, 3) = T*M.topLeftCorner(3, 3);
  std::cout << M.bottomRightCorner(3, 3) << std::endl << std::endl;
}

In the first case, we get
 1  6 11
 3  8 13
 2  7 12
which is correct

In the second case
 1  6 11
 1  6 11
 2  7 12
which is not.

I know that tracking all aliasing problems is difficult and this might just be a silly example. However, with my limited understanding of Eigen's internal, it looks to me more like a problem with the ReturnByValue class. In particular, it looks like, by using evalTo, the implementation of MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other) in assign.h is ignoring the possibility of aliasing. That would mean that expressions with aliasing nested in ReturnByValue would always be an issue.

Adrien Escande


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/