[SciPy-user] Sparse int and float performance
Thu Nov 20 15:29:16 CST 2008
On Thu, Nov 20, 2008 at 2:19 PM, Dinesh B Vadhia
> 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 firstname.lastname@example.org
More information about the SciPy-user