[Numpy-svn] r4942 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Mar 26 23:38:19 EDT 2008


Author: oliphant
Date: 2008-03-26 22:38:14 -0500 (Wed, 26 Mar 2008)
New Revision: 4942

Modified:
   trunk/numpy/lib/function_base.py
Log:
Added patch from ticket #610 to allow floats in interp.

Modified: trunk/numpy/lib/function_base.py
===================================================================
--- trunk/numpy/lib/function_base.py	2008-03-25 04:49:47 UTC (rev 4941)
+++ trunk/numpy/lib/function_base.py	2008-03-27 03:38:14 UTC (rev 4942)
@@ -21,11 +21,11 @@
 from numpy.core.umath import pi, multiply, add, arctan2,  \
      frompyfunc, isnan, cos, less_equal, sqrt, sin, mod, exp, log10
 from numpy.core.fromnumeric import ravel, nonzero, choose, sort, mean
-from numpy.core.numerictypes import typecodes
+from numpy.core.numerictypes import typecodes, number
 from numpy.lib.shape_base import atleast_1d, atleast_2d
 from numpy.lib.twodim_base import diag
 from _compiled_base import _insert, add_docstring
-from _compiled_base import digitize, bincount, interp
+from _compiled_base import digitize, bincount, interp as compiled_interp
 from arraysetops import setdiff1d
 import numpy as np
 
@@ -677,25 +677,25 @@
 except RuntimeError:
     pass
 
-try:
-    add_docstring(interp,
-r"""interp(x, xp, fp, left=None, right=None)
 
-Return the value of a piecewise-linear function at each value in x.
+def interp(x, xp, fp, left=None, right=None):
+    """Return the value of a piecewise-linear function at each value in x.
 
-The piecewise-linear function, f, is defined by the known data-points fp=f(xp).
-The xp points must be sorted in increasing order but this is not checked.
+    The piecewise-linear function, f, is defined by the known data-points 
+    fp=f(xp). The xp points must be sorted in increasing order but this is 
+    not checked.
+    
+    For values of x < xp[0] return the value given by left.  If left is None, 
+    then return fp[0].
+    For values of x > xp[-1] return the value given by right. If right is 
+    None, then return fp[-1].
+    """
+    if isinstance(x, (float, int, number)):
+        return compiled_interp([x], xp, fp, left, right).item()
+    else:
+        return compiled_interp(x, xp, fp, left, right)
+    
 
-For values of x < xp[0] return the value given by left.  If left is None, then
-return fp[0].
-For values of x > xp[-1] return the value given by right. If right is None, then
-return fp[-1].
-"""
-                  )
-except RuntimeError:
-    pass
-
-
 def angle(z, deg=0):
     """Return the angle of the complex argument z.
     """




More information about the Numpy-svn mailing list