[SciPy-dev] bug(?) in scipy.sparse

Andrew Straw strawman at astraw.com
Mon Dec 5 11:01:37 CST 2005


This stops my test from failing -- I'm not completely sure it stops the
bug because I'm not sure what the col_ptr vector of a CSC matrix expects
after the last real data. I assume here it is the number of non-zero
elements.

Index: Lib/sparse/sparse.py
===================================================================
--- Lib/sparse/sparse.py        (revision 1471)
+++ Lib/sparse/sparse.py        (working copy)
@@ -1610,8 +1610,8 @@
         nzmax = max(nnz, nzmax)
         data = [0]*nzmax
         rowind = [0]*nzmax
-        col_ptr = [0]*(self.shape[1]+1)
-        current_col = 0
+        col_ptr = [nnz]*(self.shape[1]+1)
+        current_col = -1
         k = 0
         for key in keys:
             ikey0 = int(key[0])
@@ -1623,7 +1623,6 @@
             data[k] = self[key]
             rowind[k] = ikey0
             k += 1
-        col_ptr[-1] = nnz
         data = array(data)
         rowind = array(rowind)
         col_ptr = array(col_pt

Ed Schofield wrote:

>On 04/12/2005, at 10:21 AM, Andrew Straw wrote:
>
>  
>
>>I've written a test which fails with current scipy. Although I'm no
>>sparse matrix expert, I think this is a valid bug. Please feel free to
>>include this test in test_sparse.py under the scipy license.
>>    
>>
>
>Yes, you're right ... there's something very fishy about the CSC  
>matrix conversion.  It seems that it doesn't handle columns of zeros  
>correctly.  I'll look into it further and get back you.
>
>Thanks for the catch, and the test!
>-- Ed 
>
>_______________________________________________
>Scipy-dev mailing list
>Scipy-dev at scipy.net
>http://www.scipy.net/mailman/listinfo/scipy-dev
>  
>




More information about the Scipy-dev mailing list