[eigen] On lazy evaluation and temporary matrices |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] On lazy evaluation and temporary matrices
- From: Jose Luis Blanco <joseluisblancoc@xxxxxxxxx>
- Date: Thu, 25 Nov 2010 02:01:48 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=nPo2T+4RVa5q3VOwweXvE9YzgSjPLzox6RrfLlzkl68=; b=CbaZwv/Artdw3YUX00Tnq43ySwhdF9eA7RyKBrbjRnUJZIp2C23inWVm/psuccyxeO y8iazCOt+o5HsFfQUFzROCPhSwkEUkOs4grK+pZzaaDDDMA7vMjGYejjZnMFWBqeHRqt a1mkSPflRpcxzzZKHidwVuqxJTqlBwtQrTKGA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=llOoJVkYnmYp/r4Vtnsv83VWSdwdt5bOlGYloS/oQ0trN0mzG/1W8Gwqbzq+4wxW6M CqKEnME9n/yWCkjmoIBOdLbN8vmBxD/KL4swmIA91qcikIWj961LP3fp5Nj1HB47N/FO 7HoYjnKMV0fd7RF2/I8GEIB/2iSB7wur30dEs=
Hi guys,
I need the help of someone knowing the inner workings of Eigen. I've
spent a few days stuck debugging an error in some silly computations
with Eigen matrices, and want to rule out potential errors...
Consider this code:
======================
void func( Matrix<...> &m_out )
{
Matrix<...> I = ....
const double numbers[] = { 1.0, x(), -y()*x() , whatever, .... };
m_out = I * Matrix<...>(numbers);
}
int main()
{
Matrix<...> M;
func(M);
cout << M << endl;
}
======================
Is it a problem for the temporary object "Matrix<...>(numbers)" to be
created with a pointer to memory on the stack, while the evaluation of
the object for the matrix product is actually evaluated *out* of that
function (where obviously that pointer is invalid)??
I ask because I'm having a very erratic behavior in code like above
(on GCC doesn't work, it does on MSVC; adding a "cout << ..." for an
unrelated matrix changes the result, etc...).
Is it necessary to use instead:
( I * Matrix<...>(numbers) ).eval();
or not even with this .eval() is my code correct?
I'm still having random wrong matrix elements with and without eval(),
so I wanted to be sure on this part before keep on debugging...
Thanks for your time!
JL