[Scipy-tickets] [SciPy] #463: csr_matrix.matmat(csr_matrix) causes resize1d to be called with negative shape

SciPy scipy-tickets@scipy....
Sat Jul 14 17:45:36 CDT 2007


#463: csr_matrix.matmat(csr_matrix) causes resize1d to be called with negative
shape
--------------------------+-------------------------------------------------
 Reporter:  oscart        |       Owner:  somebody          
     Type:  defect        |      Status:  new               
 Priority:  lowest        |   Milestone:                    
Component:  scipy.sparse  |     Version:  0.5.2             
 Severity:  normal        |    Keywords:  sparse, csr_matrix
--------------------------+-------------------------------------------------
 (I don't know if this has been fixed in 0.5.3)

 In sparse.py:1437, the following line causes resize1d() to be called with
 a negative shape component, when both self and other are csr_matrices:
 percent_to_go = 1- (1.0*kcol) / N

 This is fixed by:
 if isinstance(other, csr_matrix):
     percent_to_go = 1- (1.0*irow) / N
 else:
     percent_to_go = 1- (1.0*kcol) / N

 ---
 Reproducing code:
 from numpy.random import randint, seed
 from scipy.sparse import csr_matrix

 seed(123)
 a=csr_matrix(randint(0,10, size=(1000,100))/9)
 b=csr_matrix(randint(0,10, size=(100,100))/9)
 a.matmat(b)

 ---
 Backtrace:
 /usr/lib/python2.5/site-packages/scipy/sparse/sparse.py in matmat(self,
 other)
    1437                 percent_to_go = 1- (1.0*kcol) / N
    1438                 newnnzc = int(ceil((1+percent_to_go)*nnzc))
 -> 1439                 c = resize1d(c, newnnzc)
    1440                 rowc = resize1d(rowc, newnnzc)
    1441                 nnzc = newnnzc

 /usr/lib/python2.5/site-packages/scipy/sparse/sparse.py in resize1d(arr,
 newlen)
      16 def resize1d(arr, newlen):
      17     old = len(arr)
 ---> 18     new = zeros((newlen,), arr.dtype)
      19     new[:old] = arr
      20     return new

-- 
Ticket URL: <http://projects.scipy.org/scipy/scipy/ticket/463>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list