#12499: The density() function of a sparse matrix looks at every matrix entry
------------------------------+---------------------------------------------
   Reporter:  jason           |          Owner:  jason, was  
       Type:  defect          |         Status:  needs_review
   Priority:  major           |      Milestone:  sage-5.0    
  Component:  linear algebra  |       Keywords:              
Work_issues:                  |       Upstream:  N/A         
   Reviewer:                  |         Author:              
     Merged:                  |   Dependencies:              
------------------------------+---------------------------------------------

Comment(by dsm):

 I think we can improve this further, especially for denser matrices, by
 adding copy=False:

 {{{

 sage: A = MatrixSpace(ZZ, 5000,sparse=True).random_element(density=0.02)
 sage: A
 5000 x 5000 sparse matrix over Integer Ring (type 'print A.str()' to see
 all of the entries)
 sage: %timeit QQ(len(A.nonzero_positions()))/(QQ(A.nrows()*A.ncols()))
 25 loops, best of 3: 16.5 ms per loop
 sage: %timeit
 QQ(len(A.nonzero_positions(copy=False)))/QQ(A.nrows()*A.ncols())
 625 loops, best of 3: 14.3 µs per loop
 sage: %timeit
 QQ(len(A.nonzero_positions(copy=False)))/(A.nrows()*A.ncols())
 625 loops, best of 3: 13.3 µs per loop
 }}}

 Removing the second QQ is a micro-optimization but buys you a little..

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12499#comment:2>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to