[SciPy-Dev] Schur decomposition test failure under Python 2.5
Ralf Gommers
ralf.gommers@googlemail....
Tue Nov 8 15:04:13 CST 2011
On Tue, Nov 8, 2011 at 4:55 PM, Bruce Southey <bsouthey@gmail.com> wrote:
> **
> On 11/07/2011 04:52 PM, Ralf Gommers wrote:
>
>
>
> On Mon, Nov 7, 2011 at 10:22 PM, Ralf Gommers <ralf.gommers@googlemail.com
> > wrote:
>
>>
>>
>> On Mon, Nov 7, 2011 at 3:47 AM, Bruce Southey <bsouthey@gmail.com>wrote:
>>
>>> On Sun, Nov 6, 2011 at 2:22 AM, Ralf Gommers
>>> <ralf.gommers@googlemail.com> wrote:
>>> >
>>> >
>>> > On Sun, Nov 6, 2011 at 3:26 AM, Bruce Southey <bsouthey@gmail.com>
>>> wrote:
>>>
>>>>
>>>> ======================================================================
>>>> 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
>>>>
>>>> These are odd. 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.
>>>
>>
> 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.
>
> Ralf
>
>
> Also I don't understand why it doesn't fail for other Python versions.
>> Are numpy arrays somehow aware of sparse matrix details?
>>
>> If anyone with more knowledge of how this sparse matrix arithmetic is
>> supposed to work can explain or have a look, that would be great.
>>
>> Ralf
>>
>>
>
> _______________________________________________
> SciPy-Dev mailing listSciPy-Dev@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-dev
>
> Actually this Python 2.4 error has been here since 0.7.0 when the dok
> format was introduced. But means there are no or very few Python2.4 scipy
> users or they have some way around this (calling todense() ) and other
> issues.
>
> I am totally ignorant here and probably why I gave up assuming I looked at
> this before (as I usually try to find the cause of the failure). Python 2.4
> appears to call __getitem__ and but not __radd__ whereas Python2.5 does not
> call __getitem__ but calls __radd__. So all I can understand is that I can
> reproduce the error under 0.7.0 as follows.
>
> Perhaps a bug should be filed and perhaps set to won't fix if Python2.4
> support will be dropped 'soon' because this apparently has not been
> previously been reported.
>
Since the problem can be worked around and has been present for a long
time, I'm okay with marking it knownfail for 2.4.
Not sure about "soon" though, every time it comes up someone claims to need
support for several more years.
Ralf
> Bruce
>
>
> $ python2.4
> Python 2.4.6 (#1, Sep 13 2010, 15:54:12)
> [GCC 4.4.4 20100630 (Red Hat 4.4.4-10)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy as np
> >>> import scipy as sp
> >>> import scipy.sparse as sparse
> >>> print 'Numpy version=',np.__version__
> Numpy version= 2.0.0.dev-93236a2
> >>> print 'Scipy version=',sp.__version__
> Scipy version= 0.7.0
> >>> dmat= np.matrix([[1,0,0,2],[3,0,1,0],[0,2,0,0]],'d')
> >>> print 'dense matrix\n', dmat
> dense matrix
> [[ 1. 0. 0. 2.]
> [ 3. 0. 1. 0.]
> [ 0. 2. 0. 0.]]
> >>> smat=sparse.dok_matrix(dmat)
> >>> print 'Sparse dok matrix\n', smat
> Sparse dok matrix
> (1, 2) 1.0
> (0, 3) 2.0
> (0, 0) 1.0
> (1, 0) 3.0
> (2, 1) 2.0
> >>> sumd=dmat+smat.todense() # work around
> >>> print 'use todense\n', sumd
> use todense
> [[ 2. 0. 0. 4.]
> [ 6. 0. 2. 0.]
> [ 0. 4. 0. 0.]]
> >>> sum1=dmat+smat
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.4/site-packages/scipy/sparse/dok.py", line
> 119, in __getitem__
>
> raise TypeError('index must be a pair of integers or slices')
> TypeError: index must be a pair of integers or slices
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20111108/d7a25510/attachment.html
More information about the SciPy-Dev
mailing list