Is it possible to save only half of the symmetric matrix to save memory?

There is a large matrix that is used in the type problem Ax=b. A is symmetric. Is there any algorithm that allows us to save only half of the matrix and perform the operation x=A\bon it?

+5
source share
3 answers

You will save only half the memory, but you can do this by creating a flat version of the matrix, saving it, then unscrewing it. The extra time needed probably doesn't make the savings worthwhile, mind:

% pretend this is symettric...
A = rand(10, 10);

% store it as a flat list
flatA = [];
for k = 1:size(A,1)
    flatA = [flatA; A([1:k],k)];
end

save('flatA.mat', 'flatA');

% undo
N = (-1 + (1+4*2*length(flatA))^0.5)/2;
newA = NaN(N,N); 
cur = 1;
for k = 1:N
    len = k;
    newA(1:len, k) = flatA(cur:cur+len-1);
    cur = cur + len;
end
% real A cannot have NaNs or this trick fails
newA(isnan(newA)) = newA(isnan(newA'))';
+6
source

, . , A, A = U * U '. U , MATLAB, , , . MATLAB, MATLAB, , A = U * U '

, A * x = b x = U '\ U\b. , MATLAB , , , . , (. ). , , .

+3

, . .

% Create a symmetric matrix
A = rand(1000);
A = A + A';

% Extract the upper triangular part
B = sparse(triu(A))              % This is the important line, the rest is just checking.

% Undo
BB = full(B);
C = BB + BB' - diag(diag(BB));

% Check correct
assert(all(A(:) == C(:)));

% Save matrices
save('A.mat', 'A');
save('B.mat', 'B');

% Get file sizes
infoA = dir('A.mat'); infoA.bytes
infoB = dir('B.mat'); infoB.bytes

,

. B , A. B, .

b = rand(1000);
fullTriUA = triu(A);
sparseTriUA = sparse(fullTriUA);  %same as B above
fullResult = fullTriUA\b;
sparseResult = sparseTriUA\b;
assert(all(fullResult(:) == sparseResult(:)))
+1
source

All Articles