scipy.interpolate.fitpack patch
Zachary Pincus <zpincus <at> stanford.edu>
2007-02-06 03:20:16 GMT
Hello folks,
I found a minor bug in some of the routines in
scipy.interpolate.fitpack that deal with parametric splines.
In the case of a parametric spline, the spline coefficients c (in the
'tck' tuple) are not simply a 1D array of coefficients as they are
for nonparametric splines. Instead, 'c' is a list of n different 1D
arrays, where n is the dimension of the space in which the spline
lives. To evaluate a parametric spline (or integrate it, or insert
points into it, or whatnot), one simply performs the operation n
times on the n different arrays that comprise c.
The general method for dealing with this in fitpack.py is:
try:
c[0][0]
<recurse on each element of c, collate the results, and return them>
except: pass
<process the 1D c parameter, returning something or raising a helpful
exception>
From this it should be clear what the problem is: if the spline is
parametric, and if one of the elements of the 'c' list causes an
exception to be raised, it will be silently swallowed by the 'except:
pass', and then the function will try to process c as a 1D array
(which it is not!), causing a very uninformative exception to be raised.
Attached is a patch that makes the functions look like this instead:
try:
c[0][0]
(Continue reading)