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

Andrew Straw strawman at astraw.com
Sun Dec 4 05:21:07 EST 2005


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.

import scipy.base
from scipy.base import zeros, allclose

from scipy.sparse import dok_matrix

# build sparse matrix from dictionary of keys
a=dok_matrix()
shape=5,7

# set shape (by tickling dok_matrix's innards)
a[shape[0]-1,shape[1]-1]=1.0
a[shape[0]-1,shape[1]-1]=0.0

# set a few elements, but none in the last column
a[2,1]=1
a[0,2]=2
a[3,1]=3
a[1,5]=4
a[4,3]=5
a[4,2]=6

# assert that the last column is all zeros
assert allclose( a.todense()[:,6], zeros((shape[0],) ) )

# make sure it still works for CSC format
csc=a.tocsc()
assert allclose( csc.todense()[:,6], zeros((shape[0],) ) ) # fails




More information about the SciPy-Dev mailing list