[Numpy-discussion] suggested change of behavior for interp

Slavin, Jonathan jslavin at cfa.harvard.edu
Wed Jun 5 10:16:12 EDT 2013


The simplest monotonicity test that I've seen is:

dx = np.diff(x)
monotonic = np.all(dx < 0.) or np.all(dx > 0.)

I expect that this is pretty fast, though I haven't tested it yet.  If we
want to make checking optional, then I think the default should be to check
with the option to skip the check.

Jon

On Tue, Jun 4, 2013 at 9:03 PM, <numpy-discussion-request at scipy.org> wrote:

> From: Eric Firing <efiring at hawaii.edu>
> To: numpy-discussion at scipy.org
> Cc:
> Date: Tue, 04 Jun 2013 15:08:29 -1000
> Subject: Re: [Numpy-discussion] suggested change of behavior for interp
> On 2013/06/04 2:05 PM, Charles R Harris wrote:
>
>>
>>
>> On Tue, Jun 4, 2013 at 12:07 PM, Slavin, Jonathan
>> <jslavin at cfa.harvard.edu <mailto:jslavin at cfa.harvard.**edu<jslavin at cfa.harvard.edu>>>
>> wrote:
>>
>>     Hi,
>>
>>     I would like to suggest that the behavior of numpy.interp be changed
>>     regarding treatment of situations in which the x-coordinates are not
>>     monotonically increasing.  Specifically, it seems to me that interp
>>     should work correctly when the x-coordinate is decreasing
>>     monotonically.  Clearly it cannot work if the x-coordinate is not
>>     monotonic, but in that case it should raise an exception.  Currently
>>     if x is not increasing it simply silently fails, providing incorrect
>>     values.  This fix could be as simple as a monotonicity test and
>>     inversion if necessary (plus a raise statement for non-monotonic
>> cases).
>>
>>
>> Seems reasonable, although it might add a bit of execution time.
>>
>
> The monotonicity test should be an option if it is available at all; when
> interpolating a small number of points from a large pair of arrays, the
> single sweep through the whole array could dominate the execution time.
>  Checking for increasing versus decreasing, in contrast, can be done fast,
> so handling the decreasing case transparently is reasonable.
>
> Eric
>



________________________________________________________
Jonathan D. Slavin                 Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu       60 Garden Street, MS 83
phone: (617) 496-7981       Cambridge, MA 02138-1516
fax: (617) 496-7577            USA
________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130605/e43100bb/attachment.html>


More information about the NumPy-Discussion mailing list