[Scipy-svn] r6623 - in trunk/scipy/interpolate: . fitpack src
scipy-svn at scipy.org
scipy-svn at scipy.org
Sun Jul 18 15:21:30 EDT 2010
Author: charris
Date: 2010-07-18 14:21:30 -0500 (Sun, 18 Jul 2010)
New Revision: 6623
Modified:
trunk/scipy/interpolate/fitpack.py
trunk/scipy/interpolate/fitpack/splev.f
trunk/scipy/interpolate/src/__fitpack.h
trunk/scipy/interpolate/src/fitpack.pyf
Log:
ENH: The extrapolate keyword can now take three values, {0,1,2} to
determine the behavior for out of bounds arguments. If
0 the usual extrapolation is returned, if 1 zero is returned, and
if 2 then a ValueError is raised.
Modified: trunk/scipy/interpolate/fitpack/splev.f
===================================================================
--- trunk/scipy/interpolate/fitpack/splev.f 2010-07-18 19:21:26 UTC (rev 6622)
+++ trunk/scipy/interpolate/fitpack/splev.f 2010-07-18 19:21:30 UTC (rev 6623)
@@ -91,9 +91,17 @@
c fetch a new x-value arg.
arg = x(i)
c check if arg is in the support
- if (e .eq. 1 .or. arg .ge. tb .and. arg .le. te) go to 35
- y(i) = 0
- goto 80
+ if (arg .lt. tb .or. arg .gt. te) then
+ if (e .eq. 0) then
+ goto 35
+ else if (e .eq. 1) then
+ y(i) = 0
+ goto 80
+ else if (e .eq. 2) then
+ ier = 1
+ goto 100
+ endif
+ endif
c search for knot interval t(l) <= arg < t(l+1)
c++..
35 if (arg .ge. t(l) .or. l1 .eq. k2) go to 40
Modified: trunk/scipy/interpolate/fitpack.py
===================================================================
--- trunk/scipy/interpolate/fitpack.py 2010-07-18 19:21:26 UTC (rev 6622)
+++ trunk/scipy/interpolate/fitpack.py 2010-07-18 19:21:30 UTC (rev 6623)
@@ -431,7 +431,7 @@
#if len(l)>1: return l
#return l[0]
-def splev(x, tck, der=0, extrapolate=1):
+def splev(x, tck, der=0, extrapolate=0):
"""Evaluate a B-spline or its derivatives.
Given the knots and coefficients of a B-spline representation, evaluate
@@ -451,11 +451,15 @@
The order of derivative of the spline to compute (must be less than
or equal to k).
extrapolate : int
- If zero, points outside of the interval defined by the knot
- sequence evaluate to zero, otherwise the piecewise polynomials in
- the end spans of the knot sequence are extrapolated. The default
- value is 1.
+ Controls the value returned for elements of ``x`` not in the
+ interval defined by the knot sequence.
+ * if extrapolate=0, return the extrapolated value.
+ * if extrapolate=1, return 0
+ * if extrapolate=2, raise a ValueError
+
+ The default value is 0.
+
Returns
-------
y : ndarray or list of ndarrays
@@ -490,13 +494,15 @@
return map(lambda c, x=x, t=t, k=k, der=der : splev(x, [t,c,k], der), c)
else:
if not (0 <= der <= k):
- raise ValueError, "0<=der=%d<=k=%d must hold"%(der,k)
+ raise ValueError("0<=der=%d<=k=%d must hold"%(der,k))
x = myasarray(x)
y, ier =_fitpack._spl_(x, der, t, c, k, extrapolate)
if ier == 10:
- raise ValueError,"Invalid input data"
+ raise ValueError("Invalid input data")
+ if ier == 1:
+ raise ValueError("Argument out of bounds.")
if ier:
- raise TypeError,"An error occurred"
+ raise TypeError("An error occurred")
if len(y) > 1:
return y
return y[0]
Modified: trunk/scipy/interpolate/src/__fitpack.h
===================================================================
--- trunk/scipy/interpolate/src/__fitpack.h 2010-07-18 19:21:26 UTC (rev 6622)
+++ trunk/scipy/interpolate/src/__fitpack.h 2010-07-18 19:21:30 UTC (rev 6623)
@@ -449,7 +449,7 @@
static char doc_spl_[] = " [y,ier] = _spl_(x,nu,t,c,k,e)";
static PyObject *fitpack_spl_(PyObject *dummy, PyObject *args)
{
- int n, nu, ier, k, e=1;
+ int n, nu, ier, k, e=0;
npy_intp m;
double *x, *y, *t, *c, *wrk = NULL;
PyArrayObject *ap_x = NULL, *ap_y = NULL, *ap_t = NULL, *ap_c = NULL;
Modified: trunk/scipy/interpolate/src/fitpack.pyf
===================================================================
--- trunk/scipy/interpolate/src/fitpack.pyf 2010-07-18 19:21:26 UTC (rev 6622)
+++ trunk/scipy/interpolate/src/fitpack.pyf 2010-07-18 19:21:30 UTC (rev 6623)
@@ -84,7 +84,7 @@
real*8 dimension(m),intent(in) :: x
real*8 dimension(m),depend(m),intent(out) :: y
integer intent(hide),depend(x) :: m=len(x)
- integer :: e=1
+ integer :: e=0
integer intent(hide) :: ier
end subroutine splev
More information about the Scipy-svn
mailing list