1
/*
2
 *****************************************************************************
3
 **               IMPORTANT NOTE for npy_partition.h.src -> npy_partition.h **
4
 *****************************************************************************
5
 *  The template file loops.h.src is not automatically converted into
6
 *  loops.h by the build system.  If you edit this file, you must manually
7
 *  do the conversion using numpy/distutils/conv_template.py from the
8
 *  command line as follows:
9
 *
10
 *  $ cd <NumPy source root directory>
11
 *  $ python  numpy/distutils/conv_template.py numpy/core/src/private/npy_partition.h.src
12
 *  $
13
 */
14

15

16
#ifndef __NPY_PARTITION_H__
17
#define __NPY_PARTITION_H__
18

19

20
#include "npy_sort.h"
21

22
/* Python include is for future object sorts */
23
#include <Python.h>
24
#include <numpy/npy_common.h>
25
#include <numpy/ndarraytypes.h>
26

27
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
28

29
#define NPY_MAX_PIVOT_STACK 50
30

31
/**begin repeat
32
 *
33
 * #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,
34
 *         LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
35
 *         CFLOAT, CDOUBLE, CLONGDOUBLE#
36
 * #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong,
37
 *         longlong, ulonglong, half, float, double, longdouble,
38
 *         cfloat, cdouble, clongdouble#
39
 * #type = npy_bool, npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int,
40
 *         npy_uint, npy_long, npy_ulong, npy_longlong, npy_ulonglong,
41
 *         npy_ushort, npy_float, npy_double, npy_longdouble, npy_cfloat,
42
 *         npy_cdouble, npy_clongdouble#
43
 */
44

45
NPY_NO_EXPORT int introselect_@suff@(@type@ *v, npy_intp num,
46
                                             npy_intp kth,
47
                                             npy_intp * pivots,
48
                                             npy_intp * npiv,
49
                                             void *NOT_USED);
50
NPY_NO_EXPORT int aintroselect_@suff@(@type@ *v, npy_intp* tosort, npy_intp num,
51
                                              npy_intp kth,
52
                                              npy_intp * pivots,
53
                                              npy_intp * npiv,
54
                                              void *NOT_USED);
55

56

57
/**end repeat**/
58

59
typedef struct {
60
    int typenum;
61
    PyArray_PartitionFunc * part[NPY_NSELECTS];
62
    PyArray_ArgPartitionFunc * argpart[NPY_NSELECTS];
63
} part_map;
64

65
static part_map _part_map[] = {
66
/**begin repeat
67
 *
68
 * #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,
69
 *         LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
70
 *         CFLOAT, CDOUBLE, CLONGDOUBLE#
71
 * #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong,
72
 *         longlong, ulonglong, half, float, double, longdouble,
73
 *         cfloat, cdouble, clongdouble#
74
 * #type = npy_bool, npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int,
75
 *         npy_uint, npy_long, npy_ulong, npy_longlong, npy_ulonglong,
76
 *         npy_ushort, npy_float, npy_double, npy_longdouble, npy_cfloat,
77
 *         npy_cdouble, npy_clongdouble#
78
 */
79
    {
80
        NPY_@TYPE@,
81
        {
82
            (PyArray_PartitionFunc *)&introselect_@suff@,
83
        },
84
        {
85
            (PyArray_ArgPartitionFunc *)&aintroselect_@suff@,
86
        }
87
    },
88
/**end repeat**/
89
};
90

91

92
static NPY_INLINE PyArray_PartitionFunc *
93
get_partition_func(int type, NPY_SELECTKIND which)
94
{
95
    npy_intp i;
96 1
    npy_intp ntypes = ARRAY_SIZE(_part_map);
97

98
    if (which >= NPY_NSELECTS) {
99
        return NULL;
100
    }
101 1
    for (i = 0; i < ntypes; i++) {
102 1
        if (type == _part_map[i].typenum) {
103 1
            return _part_map[i].part[which];
104
        }
105
    }
106
    return NULL;
107
}
108

109

110
static NPY_INLINE PyArray_ArgPartitionFunc *
111
get_argpartition_func(int type, NPY_SELECTKIND which)
112
{
113
    npy_intp i;
114
    npy_intp ntypes = ARRAY_SIZE(_part_map);
115

116 1
    for (i = 0; i < ntypes; i++) {
117 1
        if (type == _part_map[i].typenum) {
118 1
            return _part_map[i].argpart[which];
119
        }
120
    }
121
    return NULL;
122
}
123

124
#undef ARRAY_SIZE
125

126
#endif

Read our documentation on viewing source code .

Loading