[SciPy-user] Sparse matrices and memory usage

Nathan Bell wnbell at gmail.com
Wed Oct 29 13:53:40 EDT 2008


On Wed, Oct 29, 2008 at 1:42 PM, Dinesh B Vadhia
<dineshbvadhia at hotmail.com> wrote:
> This question is primarily for Nathan:
>
> We want size the amount of memory required for our application.  Assume a
> sparse matrix A that consumes N mb of memory.  During a matrix-vector
> multiplication ie. Ax, how much additional memory is used (for temporary
> arrays and vectors)?
>

For CSR and CSC matrices (and a few others), usually only the output
vector (y in y=A*x) needs to be allocated.  However, other formats
that do not provide a matrix-vector method get converted to one that
does.  Also, if the data types of the matrix and vector are not the
same, then one or both are upcast.  For instance, multiplying a
csr_matrix with dtype=int8 by a float64 vector will cause the data
array of the csr_matrix to be upcast to float64 first.

In the future (i.e. SciPy 0.8) we might support mixed types, which
would avoid the upcast.  For now, you should ensure that types match
if you're worried about memory consumption.

-- 
Nathan Bell wnbell at gmail.com
http://graphics.cs.uiuc.edu/~wnbell/



More information about the SciPy-User mailing list