memory requirement for a complex sparse matrix
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi all,
I have been browsing matlab answers about my question, but could not come up with a satisfactory answer.
So, I have a (square) sparse matrix of size n with k nonzero complex elements. I have found here that, if the elements were real instead of complex, the matrix would take (n+1)*8+k*16 bytes.
It seems to me that my matrix takes (n+1)*8+k*24 bytes, which I do not entirely understand.
I would have guessed that a complex number takes twice as much as a real one, but, individually, a (double) number seems to take 16 bytes irrespective of real or complex.
The memory requirement must have to do with the way matlab stores numbers internally, and the 16 does not refer to the size of a double number in matlab.
I have found a document about this , which says that a sparse real matrix requires (n+1+k) integers and k doubles. This would agree with the above formulas if both real and integer numbers took 8 bytes:
(n+1+k)*8 + k*8 = (n+1)*8 +k *16 size of a real matrix (n+1+k)*8 + k*8 + k*8 = (n+1)*8 +k *24 size of a complex matrix
Is that it?
I'm asking all this because I'm wondering whether it would be convenient for me to switch to C, in terms of memory requirements and computational efficiency. My code performs a very large number of matrix multiplications involving the above matrix and some other (much smaller) sparse matrices.
Thanks a lot for any thought F
댓글 수: 0
답변 (1개)
James Tursa
2017년 2월 14일
편집: James Tursa
2017년 2월 14일
You can see this link:
https://www.mathworks.com/matlabcentral/answers/126295-memory-usage-in-sparse-matrix
Repeated for convenience with complex info:
The minimum data storage requirement formula for a double m x n sparse matrix with nnz non-zero elements, including the index data, is as follows on a 32-bit system:
bytes = max(nnz,1) * (4 + 8) + (n+1)*4
Which breaks down as follows:
nnz * 4 = Storing the row index of the non-zero elements
nnz * 8 = Storing the non-zero double element values themselves
(n+1)*4 = Storing the cumulative number of non-zero elements thru column
For 64-bit systems using 8-byte integers for the indexing you can replace the 4's above with 8's.
This is just the minimum requirements. A sparse matrix can have excess memory allocated beyond the minimum if desired.
If the variable is complex double, then replace the 8 in the above formula by 16.
If the variable is logical, then replace the 8 in the above formula by 1.
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!