Re: [eigen] bug in assigning triangularView to MatrixBase |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] bug in assigning triangularView to MatrixBase
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Tue, 3 Aug 2010 17:47:15 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=94HX0nb8EURTHsqVbm2mSSJXdQHYvcvVGxl8dzIun1A=; b=U8NEqUs09P1QtJqlrGLAs1mjBoDLsnU6y3JqGXvjHgjX+zXzX8OqMFzbDsTIY8M+cT b2eIn6aE+Fmc911kQIerHk68fDPajt29treL3eOzddA1Ja7IH2LVFUop9hLRFwNCXBQS uPMd0zVCYRJ60df46PbXvxcDIiD40Nw0sXVR8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=R+9vM8oUlXP1e1Ccq/ZyojQxT1jzuopWqaMr3X6/Cxl2tP700qqxxaGwYbAhhyyvDA uVKo/nUysyKQgI3aR0IVwg7yc+lFBVh4nTyrlJgUsA5MhpM8dEmgaQ9xetfig62nTce4 MPUZqq95uvRzrAkl23aCjAvqtu+r4kHQCRSRY=
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);
> }
>
>
>