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

Dealing with dynamic matrix with varying size in 1 dimension

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

Basically I am trying to develop some iterative algorithms that involve matrix with varying size, for instance, something like

Code: Select all
j=1; A(100,100)= known;
P= randn(100, 1);
Q= randn(100, 1);
for iter = 1:100
     Q(:, j) = A* P(:,j);
   
    // update j, P, and therefore Q

end



Here, P and Q are initially n*1 matrix, and they grow during the iteration, so the column size is dynamic, I would like to know the best practice to use Eigen for this case, it seems to me I have to use "resize" every time the column size has been increased, is there any better solution ?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
if you know a reasonable bound m for j, better allocate n*m matrices P and Q once.
Otherwise you can use conservativeResize(NoChange,alloc_size) and double alloc_size whenever alloc_size<=j. Increasing it one by one will be rather slow.


Bookmarks



Who is online

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