How large can a sparse matrix be?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
1 개 추천
Hi,
I thought I could exploit the fact that a matrix is sparse to build a big matrix. I would like to build a sparse matrix of size 46 times 8153726976. The matrix itself is very big but only has approximately 60,000 non-zero entries. I have not succeeded even in creating a completely sparse matrix of the same size. Is there any solution to this problem?
Thanks,
채택된 답변
Steven Lord
2015년 7월 22일
The larger the number of columns in a sparse matrix, the more memory it consumes. Try creating a tall but thin sparse matrix instead of a short and wide matrix.
S = spalloc(8153726976, 46, 60000);
댓글 수: 7
And to illustrate:
>> a = sparse( [zeros(1, 1e6), 1] ) ; % Row -> 1e6+1 columns.
>> b = a' ; % Column -> 1 column.
>> whos
Name Size Bytes Class Attributes
a 1x1000001 8000032 double sparse
b 1000001x1 32 double sparse
James Tursa
2015년 7월 22일
편집: James Tursa
2015년 7월 22일
And Section 2.1 gives the storage formula for the data, which I have expanded a bit:
Data storage requirements for M x N sparse double matrix with memory allocated for nzmax non-zero elements:
8 * nzmax + (4 or 8) * (nzmax + N + 1) bytes of data storage
Which breaks out as follows:
8 * nzmax --> For the double element storage
(4 or 8) * nzmax --> For the row element indexes storage
(4 or 8) * (N + 1) --> For the column indexing data storage
The (4 or 8) depends on whether your MATLAB is using 32-bit or 64-bit integers for indexing. Also note that I have used nzmax rather than nnz in the formula above. Often they are the same, but they don't have to be. For a sparse logical matrix, replace the 8*nzmax with 1*nzmax ... the indexing requirements stay the same.
(The above ignores the variable header storage and memory alignment stuff, which could easily add another 60 - 120 bytes or so to the overall footprint)
Patrick Mboma
2015년 7월 22일
편집: Patrick Mboma
2015년 7월 22일
Dear all,
Thank you so much for the replies. Suppose I succeed in creating the transpose of the matrix that I want, wouldn't I have to transpose it in order to do some computations?
I would like to be able to compute A*B, where A is the large sparse matrix and B is another sparse matrix.
James Tursa
2015년 7월 22일
편집: James Tursa
2015년 7월 22일
Regarding your transpose question, you need to be more specific about what you are doing. E.g.,
A = large sparse column vector
B = large sparse column vector
AT = A'; % <-- will consume much more memory because of the N effect
C = A'*B; <-- will likely be OK because A' is not explicitly formed
The mtimes operator * is often smart enough to not form transposes explicitly. Rather, this transpose information is passed on to the actual multiply routine internally, and then a different indexing scheme is used to do the multiply without forming the transpose explicitly in memory first.
Regarding your A*B question, just type A*B and MATLAB will recognize the sparse matrices and call the appropriate routines in the background for you.
Patrick Mboma
2015년 7월 23일
The transpose came into the picture because Mr. Lord suggested to construct "a tall but thin sparse matrix instead of a short and wide matrix". The tall-and-thin sparse matrix will be the transpose of the matrix I would like to use in my computations.
The operation I need to do is rather simple: C=A*B . In this operation however, A is short, wide and sparse, whereas B is conformably tall and potentially thin.
Any suggestions?
Hi Patrick,
then the result C should be relatively small. Did you try the obvious, namely
C = A' * B;
I'm not sure, but it guess that MATLAB identifies the pattern and computes the multiplication without "computing" the transpose before ...
Titus
Patrick Mboma
2015년 7월 23일
Titus, I have checked that what you suggested works. Matlab somehow avoids transposing the matrix before doing the multiplication. Wahoo! Now the only thing I have to make sure of is that matrix B is not too wide.
To all, Thank you so much
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Sparse Matrices에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
