## sparse vs full

### sparse vs full

Is there any general rule of thumb that dictates when to use a full
matrix over a sparse matrix?   any specific matrix density ?

Does matlab run much slower if store and operate on relatively dense
matrices as a sparse matrix?

Basically, I'm working with a matrix that is about 1/4 full.   But all
the operators are one or a few times more dense than a diagonal
matrix. So I'm guessing that I should store the operators as sparse
matrices and have them operate on a full matrix.  The matrix
dimensions are on the order of around 1000's x 1000's.

### sparse vs full

I learned in a numerical analysis class that usually a matrix is
considered sparse if approx 10% of the entries are non-zero.

I am not sure how dependable this percentage is, but it does say that
almost all the entries would be zero.

### sparse vs full

>Is there any general rule of thumb that dictates when to use a full
>matrix over a sparse matrix?   any specific matrix density ?

>Does matlab run much slower if store and operate on relatively dense
>matrices as a sparse matrix?

>Basically, I'm working with a matrix that is about 1/4 full.   But all
>the operators are one or a few times more dense than a diagonal
>matrix. So I'm guessing that I should store the operators as sparse
>matrices and have them operate on a full matrix.  The matrix
>dimensions are on the order of around 1000's x 1000's.

It depends a lot on what kind of operations you are doing.
Usually, matrices that have 1/4 of their elements nonzero are
best stored as full matrices.  Sparse matrices usually have a
tiny fraction of nonzero elements and are so large that it is
impossible to store them as full matrice3s.

-- Cleve Moler

### sparse vs full

I tried using sparse matrices for image processing but the image processing
functions I tried to use did not work.
In terms of strorage spare matrices are really useful but were not useful in
image processing.
Cheers
Sitansu

Quote:> Is there any general rule of thumb that dictates when to use a full
> matrix over a sparse matrix?   any specific matrix density ?

> Does matlab run much slower if store and operate on relatively dense
> matrices as a sparse matrix?

> Basically, I'm working with a matrix that is about 1/4 full.   But all
> the operators are one or a few times more dense than a diagonal
> matrix. So I'm guessing that I should store the operators as sparse
> matrices and have them operate on a full matrix.  The matrix
> dimensions are on the order of around 1000's x 1000's.

I have a number of sparse matrices, that I want to sum up. These are
composed in a for loop, and summing them up leeds to memory allocation
and reordering in every step of the loop. Very ugly and slow. So a
fellow came up with the idea of putting these matrices in columns of
large sparse matrix and do a

sum(M,2).

This leeds to a out of memory error. A

sum(M)

works fine. So I assume, Matlab does the summing along rows on
full(M),
wich is easier to implement, but not of that much use, as in the above
stated example, one dimension is some 10 million.
Yes, you read right, it is very sparse.

Transposing M seems to be done on full(M) as well.

I tried to do the sum on every row at a time, but even on row is too
large (otherwise the original matrices wouldn't have to be sparse ;-))

I ended up with doing the sum by hand, but a for loop over every
nonezero of the final matrix is REALLY slow.

Any good workaround?

(to Mathworks: if it isn't yet, would you copy these 'features' from my
wishlist to yours? Thanx)

Axel