[SciPy-user] amd64 specific error in fitpack spline interpolation

Angus McMorland a.mcmorland at auckland.ac.nz
Wed Aug 30 05:00:26 CDT 2006


Hi all, 

I posted about this problem a few months ago, but we didn't get very
far, but the annoyance level of the problem is enough now for me to have
another go.

I'm trying to run the spline example from the cookbook (my exact code,
called spl.py, is inlined below). On an ix86 computer this works fine,
and returns the expected graphs, but on an amd64 machine I get the error
below. Both computers are running debian etch, with recent svn numpy and
scipy.

TypeError: array cannot be safely cast to required type
> /usr/lib/python2.4/site-packages/scipy/interpolate/fitpack.py(217)splprep()
    216
t,c,o=_fitpack._parcur(ravel(transpose(x)),w,u,ub,ue,k,task,ipar,s,t,
--> 217                              nest,wrk,iwrk,per)
    218     _parcur_cache['u']=o['u']

I believe the error is generated by the _parcur call -> once in pdb,
calling it again re-raises the same error.

ipdb>_fitpack._parcur(ravel(transpose(x)),w,u,ub,ue,k,task,ipar,s,t,
nest,wrk,iwrk,per)
*** TypeError: array cannot be safely cast to required type

I've checked the values of all the inputs to the call

ravel(transpose(x)) | shape=(300,) <type 'numpy.float64'>
w    | shape=(100,) <type 'numpy.float64'>
u    | shape=(100,) <type 'numpy.float64'>
ub   | 0   <type 'int'>
ue   | 1   <type 'int'> 
k    | 2   <type 'int'>
task | 0   <type 'int'>
ipar | F   <type 'bool'>
s    | 3.0 <type 'float'>
t    | []  <type 'numpy.ndarray'>
nest | 103 <type 'int'>
wrk  | []  <type 'numpy.ndarray'>
iwrk | []  <type 'numpy.ndarray'>
per  | 0   <type 'int'>

and they are all the same on both machines, suggesting to me that
something is happening wrong in the internals of the function call,
rather than with one of the parameters.

Any suggestions what could be going on, or how I could debug this
further? Can anyone at least verify that the problem exists on other
amd64 platforms.

Thanks,

Angus.



spl.py:
--------------------------------
from numpy import arange, cos, linspace, pi, sin
from scipy.interpolate import splprep, splev
from numpy.random import randn

# make ascending spiral in 3-space
t=linspace(0,1.75*2*pi,100)

x = sin(t)
y = cos(t)
z = t

# add noise 
x+= 0.1*randn(*x.shape)
y+= 0.1*randn(*y.shape)
z+= 0.1*randn(*z.shape)

# spline parameters
s=3.0 # smoothness parameter
k=2 # spline order
nest=-1 # estimate of number of knots needed (-1 = maximal)

# find the knot points
tckp,u = splprep([x,y,z],s=s,k=k,nest=-1)

# evaluate spline, including interpolated points
xnew,ynew,znew = splev(linspace(0,1,400),tckp)

import pylab
pylab.subplot(2,2,1)
data,=pylab.plot(x,y,'bo-',label='data')
fit,=pylab.plot(xnew,ynew,'r-',label='fit')
pylab.legend()
pylab.xlabel('x')
pylab.ylabel('y')

pylab.subplot(2,2,2)
data,=pylab.plot(x,z,'bo-',label='data')
fit,=pylab.plot(xnew,znew,'r-',label='fit')
pylab.legend()
pylab.xlabel('x')
pylab.ylabel('z')

pylab.subplot(2,2,3)
data,=pylab.plot(y,z,'bo-',label='data')
fit,=pylab.plot(ynew,znew,'r-',label='fit')
pylab.legend()
pylab.xlabel('y')
pylab.ylabel('z')

-- 
Angus McMorland
email a.mcmorland at auckland.ac.nz
mobile +64-21-155-4906

PhD Student, Neurophysiology / Multiphoton & Confocal Imaging
Physiology, University of Auckland
phone +64-9-3737-599 x89707

Armourer, Auckland University Fencing
Secretary, Fencing North Inc.


More information about the SciPy-user mailing list