Re: [eigen] Memory fault when using a function returning a SelfAdjointView |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Memory fault when using a function returning a SelfAdjointView
- From: Douglas Bates <bates@xxxxxxxxxxxxx>
- Date: Wed, 26 Oct 2011 14:52:52 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=w5iIQjdAfbMqhLEtAMQDeaQ/ZoubPu6K8JhTor10ZyI=; b=LTCB1XSQT0HATulUOI4bPHxoaR+Bp7tU8Lsruzg8PVejQPZKlNZDdNbyh4SOeIpNc4 xKqAqwnUlp3Co2RcunqUxoRPllDdC6h+STservu2nEGUadpbj/z0vdhtX68D/hT6nbb1 NroyZ25FM+6p9JRaU2DKa5qYbhw4aRU7HC1vg=
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.