summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2016-07-21 21:32:13 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2016-07-21 23:07:48 +0200
commitf3c994a3510ff96fbc519b5dc28c27d2fd6ace76 (patch)
tree59c80c35087579201c9f4ccd5efb7a25f691f63f
parent93240e0d8ea23644a5b7874037e658c54966ff54 (diff)
downloadnumpy-f3c994a3510ff96fbc519b5dc28c27d2fd6ace76.tar.gz
MAINT: move integer msb into a sort util function
-rw-r--r--numpy/core/src/npysort/selection.c.src12
-rw-r--r--numpy/core/src/private/npy_sort.h8
2 files changed, 10 insertions, 10 deletions
diff --git a/numpy/core/src/npysort/selection.c.src b/numpy/core/src/npysort/selection.c.src
index bae10e85e..1e0934558 100644
--- a/numpy/core/src/npysort/selection.c.src
+++ b/numpy/core/src/npysort/selection.c.src
@@ -292,7 +292,7 @@ int
{
npy_intp low = 0;
npy_intp high = num - 1;
- npy_intp depth_limit;
+ int depth_limit;
if (npiv == NULL)
pivots = NULL;
@@ -338,15 +338,7 @@ int
return 0;
}
- /* dumb integer msb, float npy_log2 too slow for small parititions */
- {
- npy_uintp unum = num;
- depth_limit = 0;
- while (unum >>= 1) {
- depth_limit++;
- }
- depth_limit *= 2;
- }
+ depth_limit = npy_get_msb(num) * 2;
/* guarantee three elements */
for (;low + 1 < high;) {
diff --git a/numpy/core/src/private/npy_sort.h b/numpy/core/src/private/npy_sort.h
index 511d71b01..8c6f05623 100644
--- a/numpy/core/src/private/npy_sort.h
+++ b/numpy/core/src/private/npy_sort.h
@@ -9,6 +9,14 @@
#define NPY_ENOMEM 1
#define NPY_ECOMP 2
+static NPY_INLINE int npy_get_msb(npy_uintp unum)
+{
+ int depth_limit = 0;
+ while (unum >>= 1) {
+ depth_limit++;
+ }
+ return depth_limit;
+}
int quicksort_bool(void *vec, npy_intp cnt, void *null);
int heapsort_bool(void *vec, npy_intp cnt, void *null);