[SciPy-dev] scipy.interpolate.fitpack patch

Zachary Pincus zpincus at stanford.edu
Mon Feb 5 22:20:16 EST 2007


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]
   parametric = True
except:
   parametric = False
if parametric:
   <recurse on each element of c, collate the results, and return them>
else:
   <process the 1D c parameter, returning something or raising a  
helpful exception>


Thanks,

Zach Pincus

Program in Biomedical Informatics and Department of Biochemistry
Stanford University School of Medicine

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fitpack.patch
Type: application/octet-stream
Size: 4976 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20070205/2a684700/attachment.obj>


More information about the SciPy-Dev mailing list