[SciPy-user] Sparse int and float performance

Dinesh B Vadhia dineshbvadhia@hotmail....
Fri Nov 21 07:53:19 CST 2008


Like I said, I haven't looked at the sparse solver code to know how it works 
but if x is a dense float vector, A a binary matrix with

data = numpy.ones(nnz, dtype='intc')

Then, if there were a mixed matrix-vector multiplication version of the 
sparse solver that didn't upcast it to float would there be a performance 
improvement in the calculation of y = Ax?

Dinesh


...................................................................
Date: Thu, 20 Nov 2008 16:29:16 -0500
From: "Nathan Bell" <wnbell@gmail.com>
Subject: Re: [SciPy-user] Sparse int and float performance
To: "SciPy Users List" <scipy-user@scipy.org>
Message-ID:
<d05265cb0811201329g23704871o9c0cf016ce3d8cfe@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Thu, Nov 20, 2008 at 2:19 PM, Dinesh B Vadhia
<dineshbvadhia@hotmail.com> wrote:
> A question for Nathan Bell:
>
> I use Scipy Sparse to solve y = Ax, where A is a MxN "binary" sparse 
> matrix
> and x is a dense floating point vector, with M and N each >100,000
>
> I use the following to create the CSR matrix:
>
> row = numpy.empty(nnz, dtype='intc')
> column = numpy.empty(nnz, dtype='intc')
> <read i,j into row and column>
> data = numpy.ones(nnz, dtype='intc')
> A = sparse.csr_matrix((data, (row, column)), shape=(I,J))
>
> Now, suppose that we change data to the float datatype ie.
>
> data = numpy.ones(nnz, dtype=float)
>
> I know I can test this but from the perspective of the scipy code, how 
> would
> this impact the performance of the calculation of y = Ax ie.
>
> - Same as data with dtype='intc'
> - Slower than data with dtype = 'intc'
> - Faster than data with dtype = 'intc'
>

The sparse solvers use floating point values, so I assume that
dtype='intc' will get promoted to double precision.  You should use
'float32' or 'float64' for the data array.

The fastest would be:
data = numpy.ones(nnz, dtype='float32')


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


 



More information about the SciPy-user mailing list