# [SciPy-User] am I using interpolate.PiecewisePolynomial correctly?

Evgeni Burovski evgeny.burovskiy@gmail....
Wed Feb 27 09:54:44 CST 2013

```Dear All,

I'm trying to use the interpolate.PiecewisePolynomial for the first time,
and I'm wondering if the timings I see are not due to some simple
misunderstanding of mine. Specifically, given a simple example,

\$ cat pp.py
import numpy as np
from scipy.interpolate import interp1d, PiecewisePolynomial

def f(x):
return np.tan(x)
def fprime(x):
return 1./np.cos(x)**2

Npts = 50
grid = np.array([(np.pi/2.-0.1)*j/Npts for j in xrange(Npts+1)])

interp = interp1d(grid, f(grid), kind='cubic')
piecewise = PiecewisePolynomial(grid, np.array([np.r_[f(x), fprime(x)] for
x in grid]), orders=3)

it looks like evaluation of a PiecewisePolynomial takes ages:

\$ python -mtimeit -s"from numpy import random, pi; import pp; x_new =
random.rand(1000)*pi/3." "pp.piecewise(x_new)"
100 loops, best of 3: 3.2 msec per loop
\$
\$ python -mtimeit -s"from numpy import random, pi; import pp; x_new =
random.rand(1000)*pi/3." "pp.interp(x_new)"
10000 loops, best of 3: 143 usec per loop

(I understand the difference in functionality between the two).

I'm wondering if this sort of timings is an artifact of the generality of
PiecewisePolynomials, or am I just not using them properly?

Best,

Evgeni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130227/8d508cfa/attachment.html
```