
/*
 *****************************************************************************
 **       This file was autogenerated from a template  DO NOT EDIT!!!!      **
 **       Changes should be made to the original source (.src) file         **
 *****************************************************************************
 */

#line 1
/*
 *****************************************************************************
 **               IMPORTANT NOTE for npy_partition.h.src -> npy_partition.h **
 *****************************************************************************
 *  The template file loops.h.src is not automatically converted into
 *  loops.h by the build system.  If you edit this file, you must manually
 *  do the conversion using numpy/distutils/conv_template.py from the
 *  command line as follows:
 *
 *  $ cd <NumPy source root directory>
 *  $ python  numpy/distutils/conv_template.py numpy/core/src/private/npy_partition.h.src
 *  $
 */


#ifndef __NPY_PARTITION_H__
#define __NPY_PARTITION_H__


#include "npy_sort.h"

/* Python include is for future object sorts */
#include <Python.h>
#include <numpy/npy_common.h>
#include <numpy/ndarraytypes.h>

#define NPY_MAX_PIVOT_STACK 50


#line 43

int introselect_bool(npy_bool *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_bool(npy_bool *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_byte(npy_byte *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_byte(npy_byte *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_ubyte(npy_ubyte *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_ubyte(npy_ubyte *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_short(npy_short *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_short(npy_short *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_ushort(npy_ushort *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_ushort(npy_ushort *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_int(npy_int *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_int(npy_int *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_uint(npy_uint *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_uint(npy_uint *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_long(npy_long *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_long(npy_long *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_ulong(npy_ulong *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_ulong(npy_ulong *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_longlong(npy_longlong *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_longlong(npy_longlong *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_ulonglong(npy_ulonglong *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_ulonglong(npy_ulonglong *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_half(npy_ushort *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_half(npy_ushort *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_float(npy_float *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_float(npy_float *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_double(npy_double *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_double(npy_double *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_longdouble(npy_longdouble *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_longdouble(npy_longdouble *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_cfloat(npy_cfloat *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_cfloat(npy_cfloat *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_cdouble(npy_cdouble *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_cdouble(npy_cdouble *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);



#line 43

int introselect_clongdouble(npy_clongdouble *v, npy_intp num,
                       npy_intp kth,
                       npy_intp * pivots,
                       npy_intp * npiv,
                       void *NOT_USED);
int aintroselect_clongdouble(npy_clongdouble *v, npy_intp* tosort, npy_intp num,
                        npy_intp kth,
                        npy_intp * pivots,
                        npy_intp * npiv,
                        void *NOT_USED);




int introselect_string(npy_char *vec, npy_intp cnt, npy_intp kth, PyArrayObject *arr);
int aintroselect_string(npy_char *vec, npy_intp *ind, npy_intp cnt, npy_intp kth, void *null);


int introselect_unicode(npy_ucs4 *vec, npy_intp cnt, npy_intp kth, PyArrayObject *arr);
int aintroselect_unicode(npy_ucs4 *vec, npy_intp *ind, npy_intp cnt, npy_intp kth, void *null);

int npy_introselect(void *base, size_t num, size_t size, size_t kth, npy_comparator cmp);

typedef struct {
    enum NPY_TYPES typenum;
    PyArray_PartitionFunc * part[NPY_NSELECTS];
    PyArray_ArgPartitionFunc * argpart[NPY_NSELECTS];
} part_map;

static part_map _part_map[] = {
#line 87
    {
        NPY_BOOL,
        {
            (PyArray_PartitionFunc *)&introselect_bool,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_bool,
        }
    },

#line 87
    {
        NPY_BYTE,
        {
            (PyArray_PartitionFunc *)&introselect_byte,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_byte,
        }
    },

#line 87
    {
        NPY_UBYTE,
        {
            (PyArray_PartitionFunc *)&introselect_ubyte,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_ubyte,
        }
    },

#line 87
    {
        NPY_SHORT,
        {
            (PyArray_PartitionFunc *)&introselect_short,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_short,
        }
    },

#line 87
    {
        NPY_USHORT,
        {
            (PyArray_PartitionFunc *)&introselect_ushort,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_ushort,
        }
    },

#line 87
    {
        NPY_INT,
        {
            (PyArray_PartitionFunc *)&introselect_int,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_int,
        }
    },

#line 87
    {
        NPY_UINT,
        {
            (PyArray_PartitionFunc *)&introselect_uint,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_uint,
        }
    },

#line 87
    {
        NPY_LONG,
        {
            (PyArray_PartitionFunc *)&introselect_long,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_long,
        }
    },

#line 87
    {
        NPY_ULONG,
        {
            (PyArray_PartitionFunc *)&introselect_ulong,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_ulong,
        }
    },

#line 87
    {
        NPY_LONGLONG,
        {
            (PyArray_PartitionFunc *)&introselect_longlong,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_longlong,
        }
    },

#line 87
    {
        NPY_ULONGLONG,
        {
            (PyArray_PartitionFunc *)&introselect_ulonglong,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_ulonglong,
        }
    },

#line 87
    {
        NPY_HALF,
        {
            (PyArray_PartitionFunc *)&introselect_half,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_half,
        }
    },

#line 87
    {
        NPY_FLOAT,
        {
            (PyArray_PartitionFunc *)&introselect_float,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_float,
        }
    },

#line 87
    {
        NPY_DOUBLE,
        {
            (PyArray_PartitionFunc *)&introselect_double,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_double,
        }
    },

#line 87
    {
        NPY_LONGDOUBLE,
        {
            (PyArray_PartitionFunc *)&introselect_longdouble,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_longdouble,
        }
    },

#line 87
    {
        NPY_CFLOAT,
        {
            (PyArray_PartitionFunc *)&introselect_cfloat,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_cfloat,
        }
    },

#line 87
    {
        NPY_CDOUBLE,
        {
            (PyArray_PartitionFunc *)&introselect_cdouble,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_cdouble,
        }
    },

#line 87
    {
        NPY_CLONGDOUBLE,
        {
            (PyArray_PartitionFunc *)&introselect_clongdouble,
        },
        {
            (PyArray_ArgPartitionFunc *)&aintroselect_clongdouble,
        }
    },

};


static NPY_INLINE PyArray_PartitionFunc *
get_partition_func(int type, NPY_SELECTKIND which)
{
    npy_intp i;
    if (which >= NPY_NSELECTS) {
        return NULL;
    }
    for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) {
        if (type == _part_map[i].typenum) {
            return _part_map[i].part[which];
        }
    }
    return NULL;
}


static NPY_INLINE PyArray_ArgPartitionFunc *
get_argpartition_func(int type, NPY_SELECTKIND which)
{
    npy_intp i;
    if (which >= NPY_NSELECTS) {
        return NULL;
    }
    for (i = 0; i < sizeof(_part_map)/sizeof(_part_map[0]); i++) {
        if (type == _part_map[i].typenum) {
            return _part_map[i].argpart[which];
        }
    }
    return NULL;
}

#endif
