[Scipy-tickets] [SciPy] #800: numpy's test_poly1d_nan_roots is broken if scipy.linalg is imported

SciPy scipy-tickets@scipy....
Thu Nov 27 08:45:48 CST 2008


#800: numpy's test_poly1d_nan_roots is broken if scipy.linalg is imported
--------------------------+-------------------------------------------------
 Reporter:  tzito         |       Owner:  somebody
     Type:  defect        |      Status:  new     
 Priority:  high          |   Milestone:  0.7.0   
Component:  scipy.linalg  |     Version:          
 Severity:  major         |    Keywords:          
--------------------------+-------------------------------------------------
 If you run the numpy tests after having imported scipy and scipy.linalg
 the test_poly1d_nan_roots start failing:


 {{{
 >>> import scipy, scipy.linalg, scipy.fftpack
 >>> import numpy
 >>> numpy.test()
 Running unit tests for numpy
 NumPy version 1.3.0.dev6109
 NumPy is installed in /home/tiziano/python/modules/numpy
 Python version 2.5.2 (r252:60911, Sep 29 2008, 21:15:13) [GCC 4.3.2]
 nose version 0.10.3
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 ......E.........................................................................K........................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 .........................................................................................................................
 ............................................................................
 ======================================================================
 ERROR: Ticket #396
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/home/tiziano/python/modules/numpy/core/tests/test_regression.py",
 line 598, in test_poly1d_nan_roots
     self.failUnlessRaises(np.linalg.LinAlgError,getattr,p,"r")
   File "/usr/lib/python2.5/unittest.py", line 320, in failUnlessRaises
     callableObj(*args, **kwargs)
   File "/home/tiziano/python/modules/numpy/lib/polynomial.py", line 1027,
 in __getattr__
     return roots(self.coeffs)
   File "/home/tiziano/python/modules/numpy/lib/polynomial.py", line 180,
 in roots
     roots = _eigvals(A)
   File "/home/tiziano/python/modules/numpy/lib/polynomial.py", line 38, in
 _eigvals
     return eigvals(arg)
   File "/home/tiziano/python/modules/scipy/linalg/decomp.py", line 577, in
 eigvals
     return eig(a,b=b,left=0,right=0,overwrite_a=overwrite_a)
   File "/home/tiziano/python/modules/scipy/linalg/decomp.py", line 151, in
 eig
     a1 = asarray_chkfinite(a)
   File "/home/tiziano/python/modules/numpy/lib/function_base.py", line
 706, in asarray_chkfinite
     raise ValueError, "array must not contain infs or NaNs"
 ValueError: array must not contain infs or NaNs

 ----------------------------------------------------------------------
 Ran 1770 tests in 6.461s

 FAILED (KNOWNFAIL=1, errors=1)
 <nose.result.TextTestResult run=1770 errors=1 failures=0>
 }}}

 The failing test checks that if you try get the roots of
 a polynomial with NaNs a LinAlgError is raised.

 If you don't import scipy.linalg a LinAlgError is raised indeed:
 {{{
 import numpy as np
 np.poly1d([np.nan,np.nan,1], r=0).r
 }}}
 If you first import scipy.linalg a ValueError is raised instead:
 {{{
 import scipy.linalg
 import numpy as np
 np.poly1d([np.nan,np.nan,1], r=0).r
 }}}
 The difference is due to the fact that the numpy.linalg.eig raises
 LinAlgError
 if the array contains NaNs (lines 590 and 118 in numpy/linalg/linalg.py),
 whereas
 scipy.linalg.eig raises ValueError (line 151 in scipy/linalg/decomp.py).

 I find the scipy behaviour more consistent: scipy.linalg.eig uses the
 numpy function asarray_chkfinite
 to check that the array does not contain NaNs. numpy.linalg.eig uses an
 _assertFinite
 function instead, which is defined inside numpy/linalg/linalg.py and which
 is actually not needed.

 There are three possible fixes:

 1. change numpy.linalg.eig so that it uses asarray_chkfinite instead of
 _assertFinite

 2. change scipy.linalg.eig so that it uses a to be defined _assertFinite
 function instead
    of asarray_chkfinite.

 3. drop the test and live with the fact that when scipy.linalg is imported
 numpy.linalg.eig raises ValueError instead of LinAlgError when called with
 an array containing NaNs

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


More information about the Scipy-tickets mailing list