<div dir="ltr"><div class="gmail_extra"><div style="font-family:verdana,sans-serif" class="gmail_default">The simplest monotonicity test that I've seen is:</div><div style="font-family:verdana,sans-serif" class="gmail_default">
<br></div><div style="font-family:verdana,sans-serif" class="gmail_default">dx = np.diff(x)</div><div style="font-family:verdana,sans-serif" class="gmail_default">monotonic = np.all(dx < 0.) or np.all(dx > 0.)</div>
<div style="font-family:verdana,sans-serif" class="gmail_default"><br></div><div style="font-family:verdana,sans-serif" class="gmail_default">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.</div>
<div style="font-family:verdana,sans-serif" class="gmail_default"><br></div><div style="font-family:verdana,sans-serif" class="gmail_default">Jon</div><br><div class="gmail_quote">On Tue, Jun 4, 2013 at 9:03 PM,  <span dir="ltr"><<a href="mailto:numpy-discussion-request@scipy.org" target="_blank">numpy-discussion-request@scipy.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":pl" style="overflow:hidden">From: Eric Firing <<a href="mailto:efiring@hawaii.edu">efiring@hawaii.edu</a>><br>
To: <a href="mailto:numpy-discussion@scipy.org">numpy-discussion@scipy.org</a><br>Cc: <br>Date: Tue, 04 Jun 2013 15:08:29 -1000<br>Subject: Re: [Numpy-discussion] suggested change of behavior for interp<br>On 2013/06/04 2:05 PM, Charles R Harris wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
On Tue, Jun 4, 2013 at 12:07 PM, Slavin, Jonathan<br>
<<a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.edu</a> <mailto:<a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.<u></u>edu</a>>> wrote:<br>
<br>
    Hi,<br>
<br>
    I would like to suggest that the behavior of numpy.interp be changed<br>
    regarding treatment of situations in which the x-coordinates are not<br>
    monotonically increasing.  Specifically, it seems to me that interp<br>
    should work correctly when the x-coordinate is decreasing<br>
    monotonically.  Clearly it cannot work if the x-coordinate is not<br>
    monotonic, but in that case it should raise an exception.  Currently<br>
    if x is not increasing it simply silently fails, providing incorrect<br>
    values.  This fix could be as simple as a monotonicity test and<br>
    inversion if necessary (plus a raise statement for non-monotonic cases).<br>
<br>
<br>
Seems reasonable, although it might add a bit of execution time.<br>
</blockquote>
<br>
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.<br>

<br>
Eric</div></blockquote></div><br><br><br clear="all"><div><div dir="ltr">________________________________________________________<br>Jonathan D. Slavin                 Harvard-Smithsonian CfA<br><a href="mailto:jslavin@cfa.harvard.edu" target="_blank">jslavin@cfa.harvard.edu</a>       60 Garden Street, MS 83<br>
phone: (617) 496-7981       Cambridge, MA 02138-1516<br>fax: (617) 496-7577            USA<br>________________________________________________________<br><br></div></div>
</div></div>