[SciPy-user] bug in diagsvd
Carlo Mattoni
carlo at jsbach.harvard.edu
Tue Jun 1 09:34:34 CDT 2004
I'm not sure if this is the best place to report a bug, but I have
found one in the function diagsvd in decomp.py.
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> scipy.linalg.diagsvd( scipy.array( [ 1, 0, 0 ] ), 3, 3 )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/scipy/linalg/decomp.py",
line 297, in diagsvd
part = diag(s)
NameError: global name 'diag' is not defined
It appears that the problem is that the definition of diagsvd does not
properly prepend scipy function calls with scip_base as all of the other
functions in decomp.py do.
I believe the diagsvd function (starting on line 295) should be changed
from:
def diagsvd(s,M,N):
"""Return sigma from singular values and original size M,N."""
part = diag(s)
typ = part.typecode()
MorN = len(s)
if MorN == M:
return c_[part,zeros((M,N-M),typ)]
elif MorN == N:
return r_[part,zeros((M-N,N),typ)]
else:
raise ValueError, "Length of s must be M or N."
to:
def diagsvd(s,M,N):
"""Return sigma from singular values and original size M,N."""
part = scipy_base.diag(s)
typ = part.typecode()
MorN = len(s)
if MorN == M:
return c_[part,scipy_base.zeros((M,N-M),typ)]
elif MorN == N:
return r_[part,scipy_base.zeros((M-N,N),typ)]
else:
raise ValueError, "Length of s must be M or N."
Once this change is made, the original test works as expected:
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>> scipy.linalg.diagsvd( scipy.array( [ 1, 0, 0 ] ), 3, 3 )
array([[ 1., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
More information about the SciPy-user
mailing list