summaryrefslogtreecommitdiff
path: root/numpy/core/include
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-02-06 19:01:59 -0700
committerCharles Harris <charlesr.harris@gmail.com>2019-02-07 14:54:27 -0700
commitd3eb626ef41e1302631b5154037567b9cc02630d (patch)
tree4dd09f4f86cf1f422a45b2d7c901516a3b3dcd06 /numpy/core/include
parentde1ca61e038548c73ede1e8bd11a9c7dfa02794d (diff)
downloadnumpy-d3eb626ef41e1302631b5154037567b9cc02630d.tar.gz
BUG: Add timsort without breaking the API.
In order to maintain forward compatibility it is necessary to keep the size of PyArray_ArrFuncs struct fixed. The usual trick of adding new elements to the end of the structure is not available in this case because the struct may be instanciated by user types and we have no way to know whether the new or old struct is in play. The solution adopted here is the reuse the (a)mergesort slots for stable sorts of all kinds, with the actual kind set when the struct is initialized. The '(a)mergesort' option thus becomes an alias for 'stable', but we keep it for backwards compatibility.
Diffstat (limited to 'numpy/core/include')
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 62895049c..1221aeece 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -156,13 +156,20 @@ enum NPY_TYPECHAR {
NPY_COMPLEXLTR = 'c'
};
+/*
+ * Changing this may break Numpy API compatibility
+ * due to changing offsets in PyArray_ArrFuncs, so be
+ * careful. Here we have reused the mergesort slot for
+ * any kind of stable sort, the actual implementation will
+ * depend on the data type.
+ */
typedef enum {
NPY_QUICKSORT=0,
NPY_HEAPSORT=1,
NPY_MERGESORT=2,
- NPY_TIMSORT=3,
+ NPY_STABLESORT=2,
} NPY_SORTKIND;
-#define NPY_NSORTS (NPY_TIMSORT + 1)
+#define NPY_NSORTS (NPY_STABLESORT + 1)
typedef enum {