What's the reason for different memory consumption for sparse row and column vectors?

1 回表示 (過去 30 日間)
See below:
>> a = sparse(1e12,1);
>> b = sparse(1,1e9);
>> whos a b
Name Size Bytes Class Attributes
a 1000000000000x1 32 double sparse
b 1x1000000000 8000000024 double sparse
>> clear all
>> c = sparse(1,1e10);
Error using sparse
Requested 1x10000000000 (74.5GB) array exceeds maximum array size preference.
Creation of arrays greater than this limit may take a long time and cause
MATLAB to become unresponsive. See array size limit or preference panel for
more information.

採用された回答

Peng Liu
Peng Liu 2016 年 9 月 3 日
編集済み: Peng Liu 2016 年 9 月 3 日
% 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:
%
% max(nnz(x),1) * (4 + 8) + (size(x,2)+1)*4; % 32-bit
% max(nnz(x),1) * (8 + 8) + (size(x,2)+1)*8; % 64-bit
%
% 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.
  1 件のコメント
Walter Roberson
Walter Roberson 2016 年 9 月 3 日
Yup, so with you having requested many columns in the second version, it needs lots of memory.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 9 月 3 日

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by