Re: [eigen] Memory fault when using a function returning a SelfAdjointView

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


On 26.10.2011 20:20, Douglas Bates wrote:
I can do this inline but if I try to calculate the value in a function
returning the SelfAdjointView, rather than a MatrixXd, I encounter a
bad_alloc error under Ubuntu 11.10 (64-bit).  I enclose an example
program.

The problem is that SelfAdjointView only holds a reference to the MatrixXd and the MatrixXd is just a temporary within your method, i.e. it gets deallocated when the method exits. It is basically the same problem as returning MatrixXd& (but the compiler has more problems warning about that).

The reason that I want to return the SelfAdjointView is because I want
to create different types of decompositions, such as LLT, LDLT and
SelfAdjointEigenSolver from the result.  If I return the value as a
matrix I think I need to apply the selfadjointView method before
creating the decomposition, which seems redundant.

It certainly requires redundant code, but even with basic code optimizations there should be no overhead due to that.


BTW:
MatrixXd(cols, cols).setZero() == MatrixXd::Zero(cols, cols).
Also in your XtXmat method the conversion to MatrixXd should happen implicitly, I assume.


Christoph


--
----------------------------------------------
Dipl.-Inf. Christoph Hertzberg
Cartesium 0.051
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: (+49) 421-218-64252
----------------------------------------------



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