trying to minimize the memory of a matrix with sparse

the meaning of the sparse function is to reduce memory usage by ignoring the zero elements inside a matrix, for some reason when i use this function the memory increase what am i doing wrong?
>> whos('hologram_r1_r2')
Name Size Bytes Class Attributes
hologram_r1_r2 376x376 2262016 double complex
>> hologram_r1_r2(abs(hologram_r1_r2)<min(min(abs(hologram_r1_r2))))=0;
>> whos('hologram_r1_r2')
Name Size Bytes Class Attributes
hologram_r1_r2 376x376 2262016 double complex
>> hologram_r1_r2=sparse(hologram_r1_r2);
>> whos('hologram_r1_r2')
Name Size Bytes Class Attributes
hologram_r1_r2 376x376 3396040 double sparse, complex

답변 (2개)

Iain
Iain 2014년 2월 13일
편집: Iain 2014년 2월 13일

0 개 추천

Sparse only saves memory if your array is dominated by 0. That is exactly zero, and not small numbers.
The memory used by sparse is: 4/8/16 bytes for the value of each nonzero element, plus some overhead to store the location of each nonzero element, so a full "sparse" array can take many times the memory of a genuine double array.
Matt J
Matt J 2014년 2월 13일
편집: Matt J 2014년 2월 13일

0 개 추천

If the number of zero elements isn't at least 2/3 of the matrix (or 1/2 for a complex matrix), you won't benefit in terms of memory. Each non-zero element consumes 3 times as much memory as an ordinary matrix due to the need to store (i,j) coordinate data as well.

댓글 수: 1

Matt J
Matt J 2014년 2월 13일
편집: Matt J 2014년 2월 13일
Wide sparse matrices also tend to consume more than tall ones. Here's my favorite example of an all-zero sparse matrix, which nevertheless, consumes 80 MB of memory
>> At=sparse(1,1e7); >> At=sparse(1,1e7); whos At
Name Size Bytes Class Attributes
At 1x10000000 80000024 double sparse

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

제품

질문:

2014년 2월 13일

편집:

2014년 2월 13일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by