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

Copy of a block of a matrix to the same matrix

Tags: None
(comma "," separated)
constantinlevine
Registered Member
Posts
1
Karma
0
Hi all !

I am new to Eigen and I don't know if this problem is due to an improper use of Eigen or an internal bug.
I want to copy a matrix block to the same matrix like this :

MatrixXd m(10, 10);
m = m.block(5, 5, 2, 2);

Problem is that the copy operator doesn't seem to take into account that m.block(5, 5, 2, 2) is part of m, and it resizes m before doing the copy, which leads to the copy operator reading in a freed memory area.

here is a sample test code and the valgrind output showing the issue :

Code: Select all
#include "Eigen/Dense"
using Eigen::MatrixXd;
int main()
{
  MatrixXd m(10, 10);
  m = m.block(5, 5, 2, 2);
}


valgrind ouput : http://pastebin.com/Fa97Fw6m
jitseniesen
Registered Member
Posts
204
Karma
2
This is the aliasing issue, see http://eigen.tuxfamily.org/dox/group__T ... asing.html . In short: For efficiency reasons, Eigen relies on the programmer to indicate that the block is part of m, by writing "m = m.block(5,5,2,2).eval()"


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]