diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2011-06-14 13:26:09 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-06-16 20:17:43 -0600 |
commit | d1155a365d755c5b28c383bd2cd45203a8fa060f (patch) | |
tree | 5735c8fb289aae99718ad22e48d95499db3f8b55 /numpy | |
parent | 527bedde2858173ef8eff3b4d572dd5090ec9070 (diff) | |
download | numpy-d1155a365d755c5b28c383bd2cd45203a8fa060f.tar.gz |
ENH: Move sorting functions into a library.
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/include/numpy/npy_sort.h | 83 | ||||
-rw-r--r-- | numpy/core/npysort.ini.in | 18 | ||||
-rw-r--r-- | numpy/core/setup.py | 47 | ||||
-rw-r--r-- | numpy/core/src/dummymodule.c | 46 | ||||
-rw-r--r-- | numpy/core/src/npysort/npy_sort_common.h | 32 | ||||
-rw-r--r-- | numpy/core/src/npysort/sort.c.src | 59 | ||||
-rw-r--r-- | numpy/core/src/npysort/sortmodule.c.src (renamed from numpy/core/src/npysort/sortmodule.c) | 33 |
7 files changed, 230 insertions, 88 deletions
diff --git a/numpy/core/include/numpy/npy_sort.h b/numpy/core/include/numpy/npy_sort.h index c844e9fdf..60f2b047a 100644 --- a/numpy/core/include/numpy/npy_sort.h +++ b/numpy/core/include/numpy/npy_sort.h @@ -3,126 +3,167 @@ /* Python include is for future object sorts */ #include <Python.h> -#include <numpy/ndarrayobject.h> +#include <numpy/npy_common.h> +#include <numpy/ndarraytypes.h> +int BOOL_quicksort(npy_bool *start, npy_intp num, void *NOT_USED); +int BOOL_heapsort(npy_bool *start, npy_intp n, void *NOT_USED); +int BOOL_mergesort(npy_bool *start, npy_intp num, void *NOT_USED); int BOOL_aquicksort(npy_bool *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int BOOL_aheapsort(npy_bool *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void BOOL_amergesort0(npy_intp *pl, npy_intp *pr, npy_bool *v, npy_intp *pw); int BOOL_amergesort(npy_bool *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int BYTE_quicksort(npy_byte *start, npy_intp num, void *NOT_USED); +int BYTE_heapsort(npy_byte *start, npy_intp n, void *NOT_USED); +int BYTE_mergesort(npy_byte *start, npy_intp num, void *NOT_USED); int BYTE_aquicksort(npy_byte *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int BYTE_aheapsort(npy_byte *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void BYTE_amergesort0(npy_intp *pl, npy_intp *pr, npy_byte *v, npy_intp *pw); int BYTE_amergesort(npy_byte *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int UBYTE_quicksort(npy_ubyte *start, npy_intp num, void *NOT_USED); +int UBYTE_heapsort(npy_ubyte *start, npy_intp n, void *NOT_USED); +int UBYTE_mergesort(npy_ubyte *start, npy_intp num, void *NOT_USED); int UBYTE_aquicksort(npy_ubyte *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int UBYTE_aheapsort(npy_ubyte *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void UBYTE_amergesort0(npy_intp *pl, npy_intp *pr, npy_ubyte *v, npy_intp *pw); int UBYTE_amergesort(npy_ubyte *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int SHORT_quicksort(npy_short *start, npy_intp num, void *NOT_USED); +int SHORT_heapsort(npy_short *start, npy_intp n, void *NOT_USED); +int SHORT_mergesort(npy_short *start, npy_intp num, void *NOT_USED); int SHORT_aquicksort(npy_short *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int SHORT_aheapsort(npy_short *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void SHORT_amergesort0(npy_intp *pl, npy_intp *pr, npy_short *v, npy_intp *pw); int SHORT_amergesort(npy_short *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int USHORT_quicksort(npy_ushort *start, npy_intp num, void *NOT_USED); +int USHORT_heapsort(npy_ushort *start, npy_intp n, void *NOT_USED); +int USHORT_mergesort(npy_ushort *start, npy_intp num, void *NOT_USED); int USHORT_aquicksort(npy_ushort *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int USHORT_aheapsort(npy_ushort *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void USHORT_amergesort0(npy_intp *pl, npy_intp *pr, npy_ushort *v, npy_intp *pw); int USHORT_amergesort(npy_ushort *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int INT_quicksort(npy_int *start, npy_intp num, void *NOT_USED); +int INT_heapsort(npy_int *start, npy_intp n, void *NOT_USED); +int INT_mergesort(npy_int *start, npy_intp num, void *NOT_USED); int INT_aquicksort(npy_int *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int INT_aheapsort(npy_int *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void INT_amergesort0(npy_intp *pl, npy_intp *pr, npy_int *v, npy_intp *pw); int INT_amergesort(npy_int *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int UINT_quicksort(npy_uint *start, npy_intp num, void *NOT_USED); +int UINT_heapsort(npy_uint *start, npy_intp n, void *NOT_USED); +int UINT_mergesort(npy_uint *start, npy_intp num, void *NOT_USED); int UINT_aquicksort(npy_uint *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int UINT_aheapsort(npy_uint *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void UINT_amergesort0(npy_intp *pl, npy_intp *pr, npy_uint *v, npy_intp *pw); int UINT_amergesort(npy_uint *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int LONG_quicksort(npy_long *start, npy_intp num, void *NOT_USED); +int LONG_heapsort(npy_long *start, npy_intp n, void *NOT_USED); +int LONG_mergesort(npy_long *start, npy_intp num, void *NOT_USED); int LONG_aquicksort(npy_long *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int LONG_aheapsort(npy_long *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void LONG_amergesort0(npy_intp *pl, npy_intp *pr, npy_long *v, npy_intp *pw); int LONG_amergesort(npy_long *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int ULONG_quicksort(npy_ulong *start, npy_intp num, void *NOT_USED); +int ULONG_heapsort(npy_ulong *start, npy_intp n, void *NOT_USED); +int ULONG_mergesort(npy_ulong *start, npy_intp num, void *NOT_USED); int ULONG_aquicksort(npy_ulong *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int ULONG_aheapsort(npy_ulong *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void ULONG_amergesort0(npy_intp *pl, npy_intp *pr, npy_ulong *v, npy_intp *pw); int ULONG_amergesort(npy_ulong *v, npy_intp *tosort, npy_intp num, void *NOT_USED); int LONGLONG_aquicksort(npy_longlong *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int LONGLONG_aheapsort(npy_longlong *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void LONGLONG_amergesort0(npy_intp *pl, npy_intp *pr, npy_longlong *v, npy_intp *pw); int LONGLONG_amergesort(npy_longlong *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int LONGLONG_quicksort(npy_longlong *start, npy_intp num, void *NOT_USED); +int LONGLONG_heapsort(npy_longlong *start, npy_intp n, void *NOT_USED); +int LONGLONG_mergesort(npy_longlong *start, npy_intp num, void *NOT_USED); +int ULONGLONG_quicksort(npy_ulonglong *start, npy_intp num, void *NOT_USED); +int ULONGLONG_heapsort(npy_ulonglong *start, npy_intp n, void *NOT_USED); +int ULONGLONG_mergesort(npy_ulonglong *start, npy_intp num, void *NOT_USED); int ULONGLONG_aquicksort(npy_ulonglong *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int ULONGLONG_aheapsort(npy_ulonglong *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void ULONGLONG_amergesort0(npy_intp *pl, npy_intp *pr, npy_ulonglong *v, npy_intp *pw); int ULONGLONG_amergesort(npy_ulonglong *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int HALF_quicksort(npy_ushort *start, npy_intp num, void *NOT_USED); +int HALF_heapsort(npy_ushort *start, npy_intp n, void *NOT_USED); +int HALF_mergesort(npy_ushort *start, npy_intp num, void *NOT_USED); int HALF_aquicksort(npy_ushort *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int HALF_aheapsort(npy_ushort *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void HALF_amergesort0(npy_intp *pl, npy_intp *pr, npy_ushort *v, npy_intp *pw); int HALF_amergesort(npy_ushort *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int FLOAT_quicksort(npy_float *start, npy_intp num, void *NOT_USED); +int FLOAT_heapsort(npy_float *start, npy_intp n, void *NOT_USED); +int FLOAT_mergesort(npy_float *start, npy_intp num, void *NOT_USED); int FLOAT_aquicksort(npy_float *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int FLOAT_aheapsort(npy_float *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void FLOAT_amergesort0(npy_intp *pl, npy_intp *pr, npy_float *v, npy_intp *pw); int FLOAT_amergesort(npy_float *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int DOUBLE_quicksort(npy_double *start, npy_intp num, void *NOT_USED); +int DOUBLE_heapsort(npy_double *start, npy_intp n, void *NOT_USED); +int DOUBLE_mergesort(npy_double *start, npy_intp num, void *NOT_USED); int DOUBLE_aquicksort(npy_double *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int DOUBLE_aheapsort(npy_double *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void DOUBLE_amergesort0(npy_intp *pl, npy_intp *pr, npy_double *v, npy_intp *pw); int DOUBLE_amergesort(npy_double *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int LONGDOUBLE_quicksort(npy_longdouble *start, npy_intp num, void *NOT_USED); +int LONGDOUBLE_heapsort(npy_longdouble *start, npy_intp n, void *NOT_USED); +int LONGDOUBLE_mergesort(npy_longdouble *start, npy_intp num, void *NOT_USED); int LONGDOUBLE_aquicksort(npy_longdouble *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int LONGDOUBLE_aheapsort(npy_longdouble *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void LONGDOUBLE_amergesort0(npy_intp *pl, npy_intp *pr, npy_longdouble *v, npy_intp *pw); int LONGDOUBLE_amergesort(npy_longdouble *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int CFLOAT_quicksort(npy_cfloat *start, npy_intp num, void *NOT_USED); +int CFLOAT_heapsort(npy_cfloat *start, npy_intp n, void *NOT_USED); +int CFLOAT_mergesort(npy_cfloat *start, npy_intp num, void *NOT_USED); int CFLOAT_aquicksort(npy_cfloat *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int CFLOAT_aheapsort(npy_cfloat *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void CFLOAT_amergesort0(npy_intp *pl, npy_intp *pr, npy_cfloat *v, npy_intp *pw); int CFLOAT_amergesort(npy_cfloat *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int CDOUBLE_quicksort(npy_cdouble *start, npy_intp num, void *NOT_USED); +int CDOUBLE_heapsort(npy_cdouble *start, npy_intp n, void *NOT_USED); +int CDOUBLE_mergesort(npy_cdouble *start, npy_intp num, void *NOT_USED); int CDOUBLE_aquicksort(npy_cdouble *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int CDOUBLE_aheapsort(npy_cdouble *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void CDOUBLE_amergesort0(npy_intp *pl, npy_intp *pr, npy_cdouble *v, npy_intp *pw); int CDOUBLE_amergesort(npy_cdouble *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int CLONGDOUBLE_quicksort(npy_clongdouble *start, npy_intp num, void *NOT_USED); +int CLONGDOUBLE_heapsort(npy_clongdouble *start, npy_intp n, void *NOT_USED); +int CLONGDOUBLE_mergesort(npy_clongdouble *start, npy_intp num, void *NOT_USED); int CLONGDOUBLE_aquicksort(npy_clongdouble *v, npy_intp* tosort, npy_intp num, void *NOT_USED); int CLONGDOUBLE_aheapsort(npy_clongdouble *v, npy_intp *tosort, npy_intp n, void *NOT_USED); -void CLONGDOUBLE_amergesort0(npy_intp *pl, npy_intp *pr, npy_clongdouble *v, npy_intp *pw); int CLONGDOUBLE_amergesort(npy_clongdouble *v, npy_intp *tosort, npy_intp num, void *NOT_USED); +int STRING_mergesort(char *start, npy_intp num, PyArrayObject *arr); +int STRING_quicksort(char *start, npy_intp num, PyArrayObject *arr); +int STRING_heapsort(char *start, npy_intp n, PyArrayObject *arr); int STRING_aheapsort(char *v, npy_intp *tosort, npy_intp n, PyArrayObject *arr); int STRING_aquicksort(char *v, npy_intp* tosort, npy_intp num, PyArrayObject *arr); -void STRING_amergesort0(npy_intp *pl, npy_intp *pr, char *v, npy_intp *pw, int len); int STRING_amergesort(char *v, npy_intp *tosort, npy_intp num, PyArrayObject *arr); +int UNICODE_mergesort(npy_ucs4 *start, npy_intp num, PyArrayObject *arr); +int UNICODE_quicksort(npy_ucs4 *start, npy_intp num, PyArrayObject *arr); +int UNICODE_heapsort(npy_ucs4 *start, npy_intp n, PyArrayObject *arr); int UNICODE_aheapsort(npy_ucs4 *v, npy_intp *tosort, npy_intp n, PyArrayObject *arr); int UNICODE_aquicksort(npy_ucs4 *v, npy_intp* tosort, npy_intp num, PyArrayObject *arr); -void UNICODE_amergesort0(npy_intp *pl, npy_intp *pr, npy_ucs4 *v, npy_intp *pw, int len); int UNICODE_amergesort(npy_ucs4 *v, npy_intp *tosort, npy_intp num, PyArrayObject *arr); #endif diff --git a/numpy/core/npysort.ini.in b/numpy/core/npysort.ini.in new file mode 100644 index 000000000..66e08ccfa --- /dev/null +++ b/numpy/core/npysort.ini.in @@ -0,0 +1,18 @@ +[meta] +Name = npysort +Description = Core sort library for Numpy +Version = 0.1 + +[variables] +pkgname = @pkgname@ +prefix = ${pkgdir} +libdir = ${prefix}@sep@lib +includedir = ${prefix}@sep@include + +[default] +Libs = -L${libdir} -lnpysort +Cflags = -I${includedir} + +[msvc] +Libs = /LIBPATH:${libdir} npysort.lib +Cflags = /INCLUDE:${includedir} diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 63aca2847..0cc04b4a8 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -613,7 +613,7 @@ def configuration(parent_package='',top_path=None): config.add_data_dir('include/numpy/fenv') ####################################################################### - # npymath library # + # dummy module # ####################################################################### # npymath needs the config.h and numpyconfig.h files to be generated, but @@ -622,6 +622,17 @@ def configuration(parent_package='',top_path=None): # explicitly add an extension which has generate_config_h and # generate_numpyconfig_h as sources *before* adding npymath. + config.add_extension('_dummy', + sources = [join('src','dummymodule.c'), + generate_config_h, + generate_numpyconfig_h, + generate_numpy_api] + ) + + ####################################################################### + # npymath library # + ####################################################################### + subst_dict = dict([("sep", os.path.sep), ("pkgname", "numpy.core")]) def get_mathlib_info(*args): # Another ugly hack: the mathlib info is known once build_src is run, @@ -658,6 +669,7 @@ def configuration(parent_package='',top_path=None): # sort library # ####################################################################### + #subst_dict = dict([("sep", os.path.sep), ("pkgname", "numpy.core")]) config.add_installed_library('npysort', sources = [join('src', 'npysort', 'sort.c.src')], install_dir = 'lib') @@ -671,27 +683,26 @@ def configuration(parent_package='',top_path=None): # _sort version: this function is needed to build foo.c from foo.c.src # when foo.c is included in another file and as such not in the src # argument of build_ext command -# def generate_sort_templated_sources(ext, build_dir): -# from numpy.distutils.misc_util import get_cmd -# -# subpath = join('src', 'npysort') -# sources = [join(local_dir, subpath, 'sort.c.src')] -# -# # numpy.distutils generate .c from .c.src in weird directories, we have -# # to add them there as they depend on the build_dir -# config.add_include_dirs(join(build_dir, subpath)) -# cmd = get_cmd('build_src') -# cmd.ensure_finalized() -# cmd.template_sources(sources, ext) + def generate_sort_templated_sources(ext, build_dir): + from numpy.distutils.misc_util import get_cmd + + subpath = join('src', 'npysort') + sources = [join(local_dir, subpath, 'sortmodule.c.src')] + + # numpy.distutils generate .c from .c.src in weird directories, we have + # to add them there as they depend on the build_dir + config.add_include_dirs(join(build_dir, subpath)) + cmd = get_cmd('build_src') + cmd.ensure_finalized() + cmd.template_sources(sources, ext) sort_deps = [ join('src', 'npysort', 'npy_sort_common.h'), - join('src', 'npysort', 'sort.c.src'), - join('src', 'npysort', 'sortmodule.c')] + join('src', 'npysort', 'sort.c.src')] sort_src = [ - join('src', 'npysort', 'sortmodule.c'), -# generate_sort_templated_sources, + join('src', 'npysort', 'sortmodule.c.src'), + generate_sort_templated_sources, generate_config_h, generate_numpyconfig_h, generate_numpy_api] @@ -699,7 +710,7 @@ def configuration(parent_package='',top_path=None): config.add_extension('_sort', sources = sort_src, depends = deps + sort_deps, - libraries = ['npymath', 'npysort']) + libraries = ['npysort']) ####################################################################### # multiarray module # diff --git a/numpy/core/src/dummymodule.c b/numpy/core/src/dummymodule.c new file mode 100644 index 000000000..b4eb735d4 --- /dev/null +++ b/numpy/core/src/dummymodule.c @@ -0,0 +1,46 @@ + +/* -*- c -*- */ + +/* + * This is a dummy module whose purpose is to get distutils to generate the + * configuration files before the libraries are made. + */ + +#include <Python.h> +#include <numpy/npy_3kcompat.h> + +static struct PyMethodDef methods[] = { + {NULL, NULL, 0, NULL} +}; + + +#if defined(NPY_PY3K) +static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, + "dummy", + NULL, + -1, + methods, + NULL, + NULL, + NULL, + NULL +}; +#endif + +/* Initialization function for the module */ +#if defined(NPY_PY3K) +PyObject *PyInit__dummy(void) { + PyObject *m; + m = PyModule_Create(&moduledef); + if (!m) { + return NULL; + } + return m; +} +#else +PyMODINIT_FUNC +init_sort(void) { + Py_InitModule("_dummy", methods); +} +#endif diff --git a/numpy/core/src/npysort/npy_sort_common.h b/numpy/core/src/npysort/npy_sort_common.h index d4b3a0b3e..c785b5e71 100644 --- a/numpy/core/src/npysort/npy_sort_common.h +++ b/numpy/core/src/npysort/npy_sort_common.h @@ -1,12 +1,13 @@ #ifndef __NPY_SORT_COMMON_H__ #define __NPY_SORT_COMMON_H__ - +/* #include "Python.h" #include "numpy/npy_common.h" #include "numpy/npy_math.h" -#include "numpy/halffloat.h" #include "npy_config.h" +*/ +#include <numpy/ndarraytypes.h> /* @@ -140,6 +141,33 @@ LONGDOUBLE_LT(npy_longdouble a, npy_longdouble b) NPY_INLINE static int +npy_half_isnan(npy_half h) +{ + return ((h&0x7c00u) == 0x7c00u) && ((h&0x03ffu) != 0x0000u); +} + + +NPY_INLINE static int +npy_half_lt_nonan(npy_half h1, npy_half h2) +{ + if (h1&0x8000u) { + if (h2&0x8000u) { + return (h1&0x7fffu) > (h2&0x7fffu); + } else { + /* Signed zeros are equal, have to check for it */ + return (h1 != 0x8000u) || (h2 != 0x0000u); + } + } else { + if (h2&0x8000u) { + return 0; + } else { + return (h1&0x7fffu) < (h2&0x7fffu); + } + } +} + + +NPY_INLINE static int HALF_LT(npy_half a, npy_half b) { int ret; diff --git a/numpy/core/src/npysort/sort.c.src b/numpy/core/src/npysort/sort.c.src index 551f73510..90a44a3cd 100644 --- a/numpy/core/src/npysort/sort.c.src +++ b/numpy/core/src/npysort/sort.c.src @@ -26,6 +26,8 @@ * The heap sort is included for completeness. */ +#include <stdlib.h> +#include <numpy/npy_sort.h> #include "npy_sort_common.h" #define NOT_USED NPY_UNUSED(unused) @@ -54,7 +56,7 @@ */ -static int +int @TYPE@_quicksort(@type@ *start, npy_intp num, void *NOT_USED) { @type@ *pl = start; @@ -116,7 +118,7 @@ static int return 0; } -static int +int @TYPE@_aquicksort(@type@ *v, npy_intp* tosort, npy_intp num, void *NOT_USED) { @type@ vp; @@ -182,7 +184,7 @@ static int } -static int +int @TYPE@_heapsort(@type@ *start, npy_intp n, void *NOT_USED) { @type@ tmp, *a; @@ -232,7 +234,7 @@ static int return 0; } -static int +int @TYPE@_aheapsort(@type@ *v, npy_intp *tosort, npy_intp n, void *NOT_USED) { npy_intp *a, i,j,l, tmp; @@ -322,7 +324,7 @@ static void } } -static int +int @TYPE@_mergesort(@type@ *start, npy_intp num, void *NOT_USED) { @type@ *pl, *pr, *pw; @@ -381,7 +383,7 @@ static void } } -static int +int @TYPE@_amergesort(@type@ *v, npy_intp *tosort, npy_intp num, void *NOT_USED) { npy_intp *pl, *pr, *pw; @@ -459,7 +461,7 @@ static void } } -static int +int @TYPE@_mergesort(@type@ *start, npy_intp num, PyArrayObject *arr) { const size_t elsize = arr->descr->elsize; @@ -490,7 +492,7 @@ fail_0: return err; } -static int +int @TYPE@_quicksort(@type@ *start, npy_intp num, PyArrayObject *arr) { const size_t len = arr->descr->elsize/sizeof(@type@); @@ -557,7 +559,7 @@ static int } -static int +int @TYPE@_heapsort(@type@ *start, npy_intp n, PyArrayObject *arr) { size_t len = arr->descr->elsize/sizeof(@type@); @@ -606,7 +608,7 @@ static int } -static int +int @TYPE@_aheapsort(@type@ *v, npy_intp *tosort, npy_intp n, PyArrayObject *arr) { size_t len = arr->descr->elsize/sizeof(@type@); @@ -655,7 +657,7 @@ static int } -static int +int @TYPE@_aquicksort(@type@ *v, npy_intp* tosort, npy_intp num, PyArrayObject *arr) { size_t len = arr->descr->elsize/sizeof(@type@); @@ -765,7 +767,7 @@ static void } -static int +int @TYPE@_amergesort(@type@ *v, npy_intp *tosort, npy_intp num, PyArrayObject *arr) { const size_t elsize = arr->descr->elsize; @@ -785,36 +787,3 @@ static int return 0; } /**end repeat**/ - -/* just for the module bit */ -#include "numpy/noprefix.h" - -static void -add_sortfuncs(void) -{ - PyArray_Descr *descr; - - /**begin repeat - * - * #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, - * LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, - * CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE# - */ - descr = PyArray_DescrFromType(PyArray_@TYPE@); - descr->f->sort[PyArray_QUICKSORT] = - (PyArray_SortFunc *)@TYPE@_quicksort; - descr->f->argsort[PyArray_QUICKSORT] = - (PyArray_ArgSortFunc *)@TYPE@_aquicksort; - descr->f->sort[PyArray_HEAPSORT] = - (PyArray_SortFunc *)@TYPE@_heapsort; - descr->f->argsort[PyArray_HEAPSORT] = - (PyArray_ArgSortFunc *)@TYPE@_aheapsort; - descr->f->sort[PyArray_MERGESORT] = - (PyArray_SortFunc *)@TYPE@_mergesort; - descr->f->argsort[PyArray_MERGESORT] = - (PyArray_ArgSortFunc *)@TYPE@_amergesort; - /**end repeat**/ - -} - - diff --git a/numpy/core/src/npysort/sortmodule.c b/numpy/core/src/npysort/sortmodule.c.src index f6c90cbe9..9aabc1100 100644 --- a/numpy/core/src/npysort/sortmodule.c +++ b/numpy/core/src/npysort/sortmodule.c.src @@ -26,8 +26,37 @@ * The heap sort is included for completeness. */ -/*#include "sort.c"*/ -#include "numpy/npy_sort.h" +#include <numpy/npy_sort.h> +#include <numpy/npy_3kcompat.h> +#include <numpy/ndarrayobject.h> + +static void +add_sortfuncs(void) +{ + PyArray_Descr *descr; + + /**begin repeat + * + * #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, + * LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE, + * CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE# + */ + descr = PyArray_DescrFromType(PyArray_@TYPE@); + descr->f->sort[PyArray_QUICKSORT] = + (PyArray_SortFunc *)@TYPE@_quicksort; + descr->f->argsort[PyArray_QUICKSORT] = + (PyArray_ArgSortFunc *)@TYPE@_aquicksort; + descr->f->sort[PyArray_HEAPSORT] = + (PyArray_SortFunc *)@TYPE@_heapsort; + descr->f->argsort[PyArray_HEAPSORT] = + (PyArray_ArgSortFunc *)@TYPE@_aheapsort; + descr->f->sort[PyArray_MERGESORT] = + (PyArray_SortFunc *)@TYPE@_mergesort; + descr->f->argsort[PyArray_MERGESORT] = + (PyArray_ArgSortFunc *)@TYPE@_amergesort; + /**end repeat**/ + +} static struct PyMethodDef methods[] = { {NULL, NULL, 0, NULL} |