[eigen] bug in assigning triangularView to MatrixBase

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


Hi,

this time I found a real one. ;)

The code below crashes because
MatrixBase<Derived>::operator=(EigenBase) is directly calling evalTo
without resizing.

I tried to template just a MatrixType and the the code is working
because Matrix<Derived>::operator=(EigenBase) calls
DenseStorageBase::operator=(EigenBase) which does the resizing before
calling MatrixBase<Derived>::operator=(EigenBase).

The question is where do we put the resizing code in order to be sure
we don't run into any trouble again?

I was wondering about putting the resize close to evalTo and did a
quick grep. ReturnByValue will cause the same troubles when it is used
in functions taking MatrixBase<Derived>.

- Hauke

-----

template <typename Derived>
void crash(const MatrixBase<Derived>& M, MatrixBase<Derived>& N)
{
  HouseholderQR<Derived> qr(M);
  N = qr.matrixQR().triangularView<Upper>();
}

void main()
{
  const int size = 50;
  typedef MatrixXd MatrixType;
  MatrixType N,M = MatrixType::Random(size,size);

  crash(M,N);
}



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