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

Varying size matrix

Tags: None
(comma "," separated)
to_mi
Registered Member
Posts
3
Karma
0

Varying size matrix

Thu Apr 21, 2011 11:54 am
hello,

I have an iterative algorithm, which deals with matrices that change size at each iteration. To this end, I would like to allocate a large matrix at the beginning to avoid memory reallocations, but do computations only with part of it. What would be the recommended way of doing this in Eigen?

I tried using the MaxRows/ColsAtCompileTime parameters, but run straight into problems:
Code: Select all
Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 1024, 1024> xx(1, 1);
xx(0, 0) = 1.0;
xx.conservativeResize(2, 2);

This, for some reason, gives "Segmentation fault" at conservativeResize (though not if .resize() is used instead or if 1024 is set to lower value like 512).

I guess I could also just use Eigen::MatrixXd and use lots of ".block()" code, but this sounds a bit messy.

A related question: are there methods for updating Cholesky factorization of a matrix when adding a row and column to the "end" of the matrix or when deleting a row and column from the matrix? (for example, http://lapmal.epfl.ch/lhotse/index.html seems to have something like these)
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Varying size matrix

Thu Apr 21, 2011 12:14 pm
This, for some reason, gives "Segmentation fault" at conservativeResize (though not if .resize() is used instead or if 1024 is set to lower value like 512).


Please file a bug report with a full compilable version of your example.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
to_mi
Registered Member
Posts
3
Karma
0

Re: Varying size matrix

Thu Apr 21, 2011 2:18 pm
bjacob wrote:
This, for some reason, gives "Segmentation fault" at conservativeResize (though not if .resize() is used instead or if 1024 is set to lower value like 512).

Please file a bug report with a full compilable version of your example.

I filed a bug report, although maybe this is just some stack memory issue (I'm not an expert on this...)? Is the matrix allocated on stack when giving the MaxRows/ColsAtCompileTime parameters? If so, is there any way to force it on the heap (or any other way of avoiding reallocations when resizing matrices)?
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Varying size matrix

Thu Apr 21, 2011 2:30 pm
Oh, right, I missed this --- you are indeed creating this matrix on stack, which probably explains it.

To create this matrix on the heap, well, just do

MyMatrixType *m = new MyMatrixType;

Sorry for that; please close the bug if that fixed it.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
to_mi
Registered Member
Posts
3
Karma
0

Re: Varying size matrix

Thu Apr 21, 2011 3:46 pm
It doesn't... Still Segmentation fault. Here's a code that produces the behavior for me:
Code: Select all
#include <Eigen/Dense>

typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, 0, 1024, 1024> mat_t;

int main(){
  mat_t *xx = new mat_t;

  xx->conservativeResize(1, 1);

  delete xx;
  return 0;
}
User avatar
bjacob
Registered Member
Posts
658
Karma
3

Re: Varying size matrix

Thu Apr 21, 2011 3:55 pm
Interesting, please update the bug with that info.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

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