#20679: matrix vector product for generic sparse matrices
------------------------------+-----------------------------------
   Reporter:  orkolorko       |            Owner:
       Type:  enhancement     |           Status:  new
   Priority:  major           |        Milestone:  sage-7.3
  Component:  linear algebra  |         Keywords:  sparse, product
  Merged in:                  |          Authors:
  Reviewers:                  |  Report Upstream:  N/A
Work issues:                  |           Branch:
     Commit:                  |     Dependencies:
   Stopgaps:                  |
------------------------------+-----------------------------------
 It seems like this simple cython code is faster 30% faster than the
 implemented matrix vector product for generic sparse matrices.
 I run some tests with matrices with RIF coefficients and all seem to point
 in this direction.

 %cython file
 import cython

 from sage.matrix.matrix_generic_sparse cimport *
 from sage.modules.free_module_element cimport *

 # this is a generic sparse_mat_vec, hoping to get some speedup from the
 fact that it is compiled
 def cython_sparse_matvec(Matrix_generic_sparse P,
 FreeModuleElement_generic_dense v, FreeModuleElement_generic_dense w):

   for (ij, val) in P.dict().iteritems():
     w[ij[0]] += val*v[ij[1]]

 def cython_sparse_vecmat(Matrix_generic_sparse P,
 FreeModuleElement_generic_dense v, FreeModuleElement_generic_dense w):

   for (ij, val) in P.dict().iteritems():
     w[ij[1]] += val*v[ij[0]]

 %python module
 def sparse_matvec(P,v):

   """Compute Sage sparse matrix * vector product.

   Apparently, M*v fills the matrix in Sage, so this should be quicker"""

   w = VectorSpace(P.base_ring(),P.nrows())(0)
   cython_sparse_matvec(P,v,w)
   return w


 def sparse_vecmat(v,P):

   """Compute Sage sparse vector * matrix product.

   Apparently, v*M fills the matrix in Sage, so this should be quicker"""
   w = VectorSpace(P.base_ring(),P.ncols())(0)
   cython_sparse_vecmat(P,v,w)
   return w

--
Ticket URL: <http://trac.sagemath.org/ticket/20679>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to