Thread Subject: Basic Memory Calculation with Sparse Matrix

Subject: Basic Memory Calculation with Sparse Matrix

From: ade77

Date: 1 Jun, 2011 15:40:08

Message: 1 of 2

reading the MATLAB help shows that the advantage of using a sparse matrix when the matrix density is low is that it does not use memory storage for zero elements.

In one of the examples:
A = [ 0 0 0 5
      0 2 0 0
      1 3 0 0
      0 0 4 0];

S = sparse(A),

if you type whos, it shows A uses 128 bytes, and S uses 80 bytes.

Assume 8 bytes for each element, which means for matrix A, (8 * 16 elements = 128 bytes), however for S, (8*5 elements = 40), how do you account for the other 40, maybe overhead, or each nnz for sparse is now 16 bytes each., anyone can shed light on this issue.

Subject: Basic Memory Calculation with Sparse Matrix

From: Matt J

Date: 1 Jun, 2011 16:41:04

Message: 2 of 2

"ade77 " <ade100a@gmail.com> wrote in message <is5mgo$6cq$1@newscl01ah.mathworks.com>...
> reading the MATLAB help shows that the advantage of using a sparse matrix when the matrix density is low is that it does not use memory storage for zero elements.
==================

The full story about how sparse matrices allocate memory is here

http://www.mathworks.com/matlabcentral/newsreader/view_thread/235374#598253

Crudely speaking there is some overhead roughly in proportion to the number of columns. That's why the following 2 sparse matrices, even though they contain ONLY zeros, consume very different amounts of memory

A=sparse(zeros(1,1e6));
At=A.';
 
>> whos A At
  Name Size Bytes Class Attributes

  A 1x1000000 4000016 double sparse
  At 1000000x1 20 double sparse

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sparse memory Matt J 1 Jun, 2011 12:44:05
rssFeed for this Thread

Contact us at files@mathworks.com