1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
*****************************************************************************
** 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 ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#define NPY_MAX_PIVOT_STACK 50
/**begin repeat
*
* #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,
* LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
* CFLOAT, CDOUBLE, CLONGDOUBLE#
* #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong,
* longlong, ulonglong, half, float, double, longdouble,
* cfloat, cdouble, clongdouble#
* #type = npy_bool, npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int,
* npy_uint, npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_ushort, npy_float, npy_double, npy_longdouble, npy_cfloat,
* npy_cdouble, npy_clongdouble#
*/
NPY_VISIBILITY_HIDDEN int introselect_@suff@(@type@ *v, npy_intp num,
npy_intp kth,
npy_intp * pivots,
npy_intp * npiv,
void *NOT_USED);
NPY_VISIBILITY_HIDDEN int aintroselect_@suff@(@type@ *v, npy_intp* tosort, npy_intp num,
npy_intp kth,
npy_intp * pivots,
npy_intp * npiv,
void *NOT_USED);
/**end repeat**/
typedef struct {
int typenum;
PyArray_PartitionFunc * part[NPY_NSELECTS];
PyArray_ArgPartitionFunc * argpart[NPY_NSELECTS];
} part_map;
static part_map _part_map[] = {
/**begin repeat
*
* #TYPE = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,
* LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
* CFLOAT, CDOUBLE, CLONGDOUBLE#
* #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong,
* longlong, ulonglong, half, float, double, longdouble,
* cfloat, cdouble, clongdouble#
* #type = npy_bool, npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int,
* npy_uint, npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_ushort, npy_float, npy_double, npy_longdouble, npy_cfloat,
* npy_cdouble, npy_clongdouble#
*/
{
NPY_@TYPE@,
{
(PyArray_PartitionFunc *)&introselect_@suff@,
},
{
(PyArray_ArgPartitionFunc *)&aintroselect_@suff@,
}
},
/**end repeat**/
};
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 < ntypes; 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;
npy_intp ntypes = ARRAY_SIZE(_part_map);
if (which >= NPY_NSELECTS) {
return NULL;
}
for (i = 0; i < ntypes; i++) {
if (type == _part_map[i].typenum) {
return _part_map[i].argpart[which];
}
}
return NULL;
}
#undef ARRAY_SIZE
#endif
|