Re: [eigen] bug in assigning triangularView to MatrixBase

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


2010/8/3 Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>:
> Hi,
>
> this time I found a real one. ;)

Nope :) Really not your day! :)

Here, your program hits this assertion:

[bjacob@cahouette ~]$ ./a
a: eigen/Eigen/src/Core/TriangularMatrix.h:597: void
Eigen::TriangularBase<Derived>::evalToLazy(Eigen::MatrixBase<OtherDerived>&)
const [with DenseDerived = Eigen::Matrix<double, -0x00000000000000001,
-0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>,
Derived = Eigen::TriangularView<Eigen::Matrix<double,
-0x00000000000000001, -0x00000000000000001, 0, -0x00000000000000001,
-0x00000000000000001>, 2u>]: Assertion `this->rows() == other.rows()
&& this->cols() == other.cols()' failed.
Aborted (core dumped)

Which makes sense: the LHS expression in this assignment has size 0x0,
the RHS has size 50x50, so this fails on an assertion.

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

How could it resize a MatrixBase?

Only plain Matrix/Array objects can be resized. General expressions can't.

We could try to be clever and allow resizing MatrixBase<Matrix>. But
what would be the use case? If the user knows that the MatrixBase in
question is really a Matrix, he could just let the function take a
Matrix in the first place.

Cheers
Benoit

>
> 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/