Multiplying large vectors and Out of memory. Type

2019-08-19 13:16发布

Actually this is what i am trying to do Ad=<100820x20164 double> and b= <100820x1 double> also Ad is sparse matrix and b is non-sparse .Below is the original Problem and i try to change the statement A=V'*V + y_0*y_0'; using the block processing technique as you told me , now the problem is on the assignment statement mentioned below.

V=Ad;     
b_1=b;
x_0=ones(size(V ,1) ,1);
y_0=V'*x_0;
A=V'*V + y_0*y_0';
b=V'*b_1 + dot(x_0,b_1)*y_0;

%%%%%%%%% Modified using block processing below %%%%%%

V=Ad;     
b_1=b;
x_0=ones(size(V ,1) ,1);
y_0=V'*x_0;

v=V'*V ;   %%% v is updated here which is left hand side of equation 

 %%% Block Processing code %% For right hand side of equation
 y_01 = y_0(1:size(y_0)/2);
 y_02 = y_0(size(y_0)/2 + 1:end);


 res =( y_01 * y_01'); % Upper left 
 Temp=v(1:size(v ,1)/2 , 1:size(v ,1)/2)  + res  ;
 v(1:size(v ,1)/2 , 1:size(v ,1)/2)  = Temp;       %%%% Problem here gets hang
 clear Temp; clear res ;


 res = y_02 * y_02'; % Bottom right
 Temp=v(size(v ,1)/2 + 1 :end , size(v ,1)/2 + 1 :end)  + res  ;  
 v(size(v ,1)/2 + 1:end , size(v ,1)/2 + 1:end)  = Temp; 
 clear Temp; clear res ;


 res = y_01 * y_02'; % Upper right
 Temp=v(1:size(v ,1)/2 , size(v ,1)/2 + 1:end)  + res  ;
 v(1:size(v ,1)/2 , size(v ,1)/2 + 1:end)  = Temp; 
 clear Temp; clear res ;


 res = y_02 * y_01'; % Bottom left   
 Temp=v(size(v ,1)/2 + 1:end, 1:size(v ,1)/2 )   + res  ;
 v(size(v ,1)/2 + 1:end, 1:size(v ,1)/2 )  = Temp; 
 clear Temp; clear res ;

1条回答
一纸荒年 Trace。
2楼-- · 2019-08-19 13:59

While V'*V is sparse, y_0*y_0' is not. Unless of course V' has many empty rows. You could calculate y_0*y_0' block-wise:

y_01 = y_0(1:10000);
y_02 = y_0(10001:end);

res = y_01 * y_01' % Upper left 
% Process...
res = y_02 * y_02' % Bottom right
% Process...
res = y_01 * y_02' % Upper right
% Process...
res = y_02 * y_01' % Bottom left  
% Process...

In the 'Process' section you can combine it with the appropriate portion of V'*V. I would also suggest re-factoring my code snippet to avoid redundancy.

查看更多
登录 后发表回答