[SciPy-dev] Subtle fitpack2 bug: resize (but only in doctest)
Michael McNeil Forbes
mforbes at physics.ubc.ca
Sat Mar 1 09:53:09 EST 2008
Hi,
I have been running into a very strange and hard to track down bug
with fitpack2.py. When I run certain tests as doctests, then I get
the following error:
File "/data/apps/Python-2.5.1/Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/site-packages/scipy/
interpolate/fitpack2.py", line 91, in __init__
data = self._reset_nest(data)
File "/data/apps/Python-2.5.1/Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/site-packages/scipy/
interpolate/fitpack2.py", line 128, in _reset_nest
t.resize(nest)
ValueError: cannot resize an array that has been referenced or
is referencing
another array in this way. Use the resize function
I am doing a simple 1d interpolation, but the tricky part is that
this only occurs when I am running under the doctest module: if I
import the file at an interpreter prompt and then run the doctests,
there is no problem.
The problem is at line 128 in fitpack2.py which occurs in this context:
128 t,c,fpint,nrdata = data[8].copy(),data[9].copy(),\
129 data[11].copy(),data[12].copy()
130 t.resize(nest)
131 c.resize(nest)
132 fpint.resize(nest)
133 nrdata.resize(nest)
...
Thus, t should be a fresh copy and should be resizable, but somehow,
when running the code under a doctest, there is a reference created
that messes up the call to resize.
I have no idea what is causing this problem - it also seems to be
very fickle: I can cause the problem on my macbook pro (Core Duo)
with the following program:
err.py:
"""
>>> x = [-1.,-0.65016502,-0.58856235,-0.26903553,-0.17370892,
... -0.10011001,0.,0.10011001,0.17370892,0.26903553,0.58856235,
... 0.65016502,1.]
>>> y = [ 1.,0.62928599,0.5797223, 0.39965815,0.36322694,0.3508061,
... 0.35214793,0.3508061, 0.36322694,0.39965815,0.5797223,
... 0.62928599,1.]
>>> w = [1.00000000e+12, 6.88875973e+02, 4.89314737e+02, 4.26864807e
+02,
... 6.07746770e+02, 4.51341444e+02, 3.17480210e+02, 4.51341444e+02,
... 6.07746770e+02, 4.26864807e+02, 4.89314737e+02, 6.88875973e+02,
... 1.00000000e+12]
>>> from scipy.interpolate import UnivariateSpline
>>> sp = UnivariateSpline(x=x,y=y,w=w,s=None)
"""
import doctest
doctest.testmod()
But when I run it on my linux box (64 bit), it runs fine.
In any case, there is an easy patch. Just replace the lines above with
128 t,c,fpint,nrdata = [resize(data[n],nest) for n in
129 [8,9,11,12]]
and add resize to the numpy imports
21 from numpy import ... resize
The bug is so strange, though, that I though it should be
investigated a bit more. Any ideas what could be causing this?
Michael.
More information about the SciPy-Dev
mailing list