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

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


On Wed, Oct 26, 2011 at 2:35 PM, Christoph Hertzberg
<chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> 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).

Thanks for the response and the clarification.

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

I wasn't concerned about overhead as much as creating more readable code.

> BTW:
> MatrixXd(cols, cols).setZero() == MatrixXd::Zero(cols, cols).

I don't think so - at least in my testing it didn't.  That problem is
that MatrixXd::Zero returns a constant matrix and I want to modify it.

> Also in your XtXmat method the conversion to MatrixXd should happen
> implicitly, I assume.

It probably should.  I'll try that.



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