Create sparse matrices with integer rows and columns
4 次查看(过去 30 天)
显示 更早的评论
Hi,
I am creating a fairly large sparse matrix from row-column-value triplets. Row and column numbers are obviously integer, so I tried to change the types of the row and column arrays from 'double' to 'uint32', in an attempt to reduce the memory used. I get the following error message: "Undefined function 'sparse' for input arguments of type 'uint32'."
Is there a way to format the row and column arrays so that less than 8 bytes per entry are used?
Thanks!
0 个评论
采纳的回答
Thorsten
2016-7-25
5 个评论
James Tursa
2016-7-26
编辑:James Tursa
2016-7-26
See this related link (some of which I repeat below for convenience):
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
Each row value and index gets stored, plus the cumulative column index data gets stored.
For 64-bit systems using 8-byte integers for the indexing you can replace the 4's above with 8's. So, in theory on a 64-bit system, moving from 8-byte index integers to 4-byte index integers would be more like a 25% savings (the 8+8 would become 4+8) assuming the nnz part is dominating the calculation.
This is just the minimum requirements. A sparse matrix can have excess memory allocated beyond the minimum if desired.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!