* Returns -1 if the array is monotonic decreasing, * +1 if the array is monotonic increasing, * and 0 if the array is not monotonic. */
| 30 | * and 0 if the array is not monotonic. |
| 31 | */ |
| 32 | static int |
| 33 | check_array_monotonic(const double *a, npy_intp lena) |
| 34 | { |
| 35 | npy_intp i; |
| 36 | double next; |
| 37 | double last; |
| 38 | |
| 39 | if (lena == 0) { |
| 40 | /* all bin edges hold the same value */ |
| 41 | return 1; |
| 42 | } |
| 43 | last = a[0]; |
| 44 | |
| 45 | /* Skip repeated values at the beginning of the array */ |
| 46 | for (i = 1; (i < lena) && (a[i] == last); i++); |
| 47 | |
| 48 | if (i == lena) { |
| 49 | /* all bin edges hold the same value */ |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | next = a[i]; |
| 54 | if (last < next) { |
| 55 | /* Possibly monotonic increasing */ |
| 56 | for (i += 1; i < lena; i++) { |
| 57 | last = next; |
| 58 | next = a[i]; |
| 59 | if (last > next) { |
| 60 | return 0; |
| 61 | } |
| 62 | } |
| 63 | return 1; |
| 64 | } |
| 65 | else { |
| 66 | /* last > next, possibly monotonic decreasing */ |
| 67 | for (i += 1; i < lena; i++) { |
| 68 | last = next; |
| 69 | next = a[i]; |
| 70 | if (last < next) { |
| 71 | return 0; |
| 72 | } |
| 73 | } |
| 74 | return -1; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /* Find the minimum and maximum of an integer array */ |
| 79 | static void |