How large can a sparse matrix be?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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?
Titus Edelhofer
2015 年 7 月 23 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
