[Scipy-tickets] [SciPy] #1559: ndarray + dok sparse array doesn't work on Python 2.4

SciPy Trac scipy-tickets@scipy....
Sun Nov 13 04:40:17 CST 2011


#1559: ndarray + dok sparse array doesn't work on Python 2.4
--------------------------+-------------------------------------------------
 Reporter:  rgommers      |       Owner:  wnbell     
     Type:  defect        |      Status:  new        
 Priority:  normal        |   Milestone:  Unscheduled
Component:  scipy.sparse  |     Version:  devel      
 Keywords:                |  
--------------------------+-------------------------------------------------
 See
 http://thread.gmane.org/gmane.comp.python.scientific.devel/15662/focus=15673

 A dok_matrix can't be indexed with a single integer, which causes errors
 when we do ``obj + dokmatrix`` when obj is an ndarray or matrix. It looks
 to me like indexing with single integers should trigger a conversion to a
 dense array or something like that. Also I don't understand why it doesn't
 fail for other Python versions. Are numpy arrays somehow aware of sparse
 matrix details?

 {{{dok_matrix.__radd__}}} (which has the todense() call) is called for
 Python >= 2.5, but not for 2.4. I can't find anything related to this in
 the "what's new in python 2.5" doc.

 {{{
 ======================================================================
 ERROR: adding a dense matrix to a sparse matrix
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python2.4/site-
 packages/scipy/sparse/tests/test_base.py",
 line 519, in test_add_dense
     sum1 = self.dat + self.datsp
   File "/usr/local/lib/python2.4/site-packages/scipy/sparse/dok.py",
 line 133, in __getitem__
     raise TypeError('index must be a pair of integers or slices')
 TypeError: index must be a pair of integers or slices

 ======================================================================
 ERROR: test_matmat_sparse (test_base.TestDOK)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python2.4/site-
 packages/scipy/sparse/tests/test_base.py",
 line 417, in test_matmat_sparse
     assert_array_almost_equal( a2*bsp, a*b)
   File "/usr/local/lib/python2.4/site-packages/scipy/sparse/dok.py",
 line 133, in __getitem__
     raise TypeError('index must be a pair of integers or slices')
 TypeError: index must be a pair of integers or slices

 ======================================================================
 ERROR: test_radd (test_base.TestDOK)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python2.4/site-
 packages/scipy/sparse/tests/test_base.py",
 line 279, in test_radd
     c = a + b
   File "/usr/local/lib/python2.4/site-packages/scipy/sparse/dok.py",
 line 133, in __getitem__
     raise TypeError('index must be a pair of integers or slices')
 TypeError: index must be a pair of integers or slices

 ======================================================================
 ERROR: test_rsub (test_base.TestDOK)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python2.4/site-
 packages/scipy/sparse/tests/test_base.py",
 line 290, in test_rsub
     assert_array_equal((self.dat -
 self.datsp),[[0,0,0,0],[0,0,0,0],[0,0,0,0]])
   File "/usr/local/lib/python2.4/site-packages/scipy/sparse/dok.py",
 line 133, in __getitem__
     raise TypeError('index must be a pair of integers or slices')
 TypeError: index must be a pair of integers or slices

 ======================================================================
 ERROR: subtracting a dense matrix to/from a sparse matrix
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/usr/local/lib/python2.4/site-
 packages/scipy/sparse/tests/test_base.py",
 line 527, in test_sub_dense
     sum1 = 3*self.dat - self.datsp
   File "/usr/local/lib/python2.4/site-packages/scipy/sparse/dok.py",
 line 133, in __getitem__
     raise TypeError('index must be a pair of integers or slices')
 TypeError: index must be a pair of integers or slices
 }}}

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


More information about the Scipy-tickets mailing list