This forum has been archived. All content is frozen. Please use KDE Discuss instead.

In place resize and copy in one line = non-deterministic

Tags: None
(comma "," separated)
guslott
Registered Member
Posts
1
Karma
0
When I use the following line of code:

Eigen::Matrix<double,-1,-1> A;
//Fill A with some value
A = A.block(....)

I get non-deterministic results in A (what look like unallocated values with amplitudes at 1e240 or so). This also works with A.middleCols(...) and others. Is this expected behavior?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Yes, this has to be expected, this is an aliasing issue as explained there: http://eigen.tuxfamily.org/dox-devel/gr ... asing.html

Basically, in your case, A gets resized and reallocated before copying the values... Either use conservativeResize, or make a temporary A = MatrixXd(A.block(...));


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar