diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-01-20 17:21:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-20 17:21:00 -0700 |
commit | b78bbef27101c17601eb73104a79665bf1a46558 (patch) | |
tree | ec7901c59d4cd404933cdf58a599f47a1392a94b | |
parent | a6ee59abd47085dbcf0e4ac90cfbfa3eb0f068ba (diff) | |
parent | c1ffb3cfa07c0e7b27e6a2c278c97d8f1c8b6206 (diff) | |
download | numpy-b78bbef27101c17601eb73104a79665bf1a46558.tar.gz |
Merge pull request #10415 from charris/fix-sign-compare-binsearch-partition
MAINT: Fix sign-compare warnings in npy_binsearch, npy_partition.
-rw-r--r-- | numpy/core/src/private/npy_binsearch.h.src | 26 | ||||
-rw-r--r-- | numpy/core/src/private/npy_partition.h.src | 15 |
2 files changed, 26 insertions, 15 deletions
diff --git a/numpy/core/src/private/npy_binsearch.h.src b/numpy/core/src/private/npy_binsearch.h.src index 3b2c59487..ce3b34b0e 100644 --- a/numpy/core/src/private/npy_binsearch.h.src +++ b/numpy/core/src/private/npy_binsearch.h.src @@ -5,6 +5,8 @@ #include <numpy/npy_common.h> #include <numpy/ndarraytypes.h> +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) + typedef void (PyArray_BinSearchFunc)(const char*, const char*, char*, npy_intp, npy_intp, npy_intp, npy_intp, npy_intp, @@ -16,15 +18,15 @@ typedef int (PyArray_ArgBinSearchFunc)(const char*, const char*, npy_intp, npy_intp, npy_intp, PyArrayObject*); -struct binsearch_map { - enum NPY_TYPES typenum; +typedef struct { + int typenum; PyArray_BinSearchFunc *binsearch[NPY_NSEARCHSIDES]; -}; +} binsearch_map; -struct argbinsearch_map { - enum NPY_TYPES typenum; +typedef struct { + int typenum; PyArray_ArgBinSearchFunc *argbinsearch[NPY_NSEARCHSIDES]; -}; +} argbinsearch_map; /**begin repeat * @@ -72,7 +74,7 @@ npy_argbinsearch_@side@(const char *arr, const char *key, * #Arg = , Arg# */ -static struct @arg@binsearch_map _@arg@binsearch_map[] = { +static @arg@binsearch_map _@arg@binsearch_map[] = { /* If adding new types, make sure to keep them ordered by type num */ /**begin repeat1 * @@ -100,10 +102,9 @@ static PyArray_@Arg@BinSearchFunc *gen@arg@binsearch_map[] = { static NPY_INLINE PyArray_@Arg@BinSearchFunc* get_@arg@binsearch_func(PyArray_Descr *dtype, NPY_SEARCHSIDE side) { - static npy_intp num_funcs = sizeof(_@arg@binsearch_map) / - sizeof(_@arg@binsearch_map[0]); + npy_intp nfuncs = ARRAY_SIZE(_@arg@binsearch_map); npy_intp min_idx = 0; - npy_intp max_idx = num_funcs; + npy_intp max_idx = nfuncs; int type = dtype->type_num; if (side >= NPY_NSEARCHSIDES) { @@ -125,7 +126,8 @@ get_@arg@binsearch_func(PyArray_Descr *dtype, NPY_SEARCHSIDE side) } } - if (min_idx < num_funcs && _@arg@binsearch_map[min_idx].typenum == type) { + if (min_idx < nfuncs && + _@arg@binsearch_map[min_idx].typenum == type) { return _@arg@binsearch_map[min_idx].@arg@binsearch[side]; } @@ -137,4 +139,6 @@ get_@arg@binsearch_func(PyArray_Descr *dtype, NPY_SEARCHSIDE side) } /**end repeat**/ +#undef ARRAY_SIZE + #endif diff --git a/numpy/core/src/private/npy_partition.h.src b/numpy/core/src/private/npy_partition.h.src index 07aecd4f8..a22cf911c 100644 --- a/numpy/core/src/private/npy_partition.h.src +++ b/numpy/core/src/private/npy_partition.h.src @@ -24,8 +24,9 @@ #include <numpy/npy_common.h> #include <numpy/ndarraytypes.h> -#define NPY_MAX_PIVOT_STACK 50 +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) +#define NPY_MAX_PIVOT_STACK 50 /**begin repeat * @@ -56,7 +57,7 @@ NPY_VISIBILITY_HIDDEN int aintroselect_@suff@(@type@ *v, npy_intp* tosort, npy_i /**end repeat**/ typedef struct { - enum NPY_TYPES typenum; + int typenum; PyArray_PartitionFunc * part[NPY_NSELECTS]; PyArray_ArgPartitionFunc * argpart[NPY_NSELECTS]; } part_map; @@ -92,10 +93,12 @@ static NPY_INLINE PyArray_PartitionFunc * get_partition_func(int type, NPY_SELECTKIND which) { npy_intp i; + npy_intp ntypes = ARRAY_SIZE(_part_map); + if (which >= NPY_NSELECTS) { return NULL; } - for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) { + for (i = 0; i < ntypes; i++) { if (type == _part_map[i].typenum) { return _part_map[i].part[which]; } @@ -108,10 +111,12 @@ static NPY_INLINE PyArray_ArgPartitionFunc * get_argpartition_func(int type, NPY_SELECTKIND which) { npy_intp i; + npy_intp ntypes = ARRAY_SIZE(_part_map); + if (which >= NPY_NSELECTS) { return NULL; } - for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) { + for (i = 0; i < ntypes; i++) { if (type == _part_map[i].typenum) { return _part_map[i].argpart[which]; } @@ -119,4 +124,6 @@ get_argpartition_func(int type, NPY_SELECTKIND which) return NULL; } +#undef ARRAY_SIZE + #endif |