@@ -6,26 +6,24 @@ WARNING: DO NOT edit .pxi FILE directly, .pxi is generated from .pxi.in
66
77{{py:
88
9- # name, dtype, ttype, c_type, to_c_type
10- dtypes = [('Complex128', 'complex128', 'complex128',
11- 'khcomplex128_t', 'to_khcomplex128_t'),
12- ('Complex64', 'complex64', 'complex64',
13- 'khcomplex64_t', 'to_khcomplex64_t'),
14- ('Float64', 'float64', 'float64', 'float64_t', ''),
15- ('Float32', 'float32', 'float32', 'float32_t', ''),
16- ('UInt64', 'uint64', 'uint64', 'uint64_t', ''),
17- ('UInt32', 'uint32', 'uint32', 'uint32_t', ''),
18- ('UInt16', 'uint16', 'uint16', 'uint16_t', ''),
19- ('UInt8', 'uint8', 'uint8', 'uint8_t', ''),
20- ('Object', 'object', 'pymap', 'object', '<PyObject*>'),
21- ('Int64', 'int64', 'int64', 'int64_t', ''),
22- ('Int32', 'int32', 'int32', 'int32_t', ''),
23- ('Int16', 'int16', 'int16', 'int16_t', ''),
24- ('Int8', 'int8', 'int8', 'int8_t', '')]
9+ # name, dtype, ttype, tfunc_type, c_type, to_c_type
10+ dtypes = [('Complex128', 'complex128', 'complex128', 'complex128', 'khcomplex128_t', 'to_khcomplex128_t'),
11+ ('Complex64', 'complex64', 'complex64', 'complex64', 'khcomplex64_t', 'to_khcomplex64_t'),
12+ ('Float64', 'float64', 'float64', 'float64', 'float64_t', ''),
13+ ('Float32', 'float32', 'float32', 'float32', 'float32_t', ''),
14+ ('UInt64', 'uint64', 'uint64', 'uint64', 'uint64_t', ''),
15+ ('UInt32', 'uint32', 'uint32', 'uint32', 'uint32_t', ''),
16+ ('UInt16', 'uint16', 'uint16', 'uint16', 'uint16_t', ''),
17+ ('UInt8', 'uint8', 'uint8', 'uint8', 'uint8_t', ''),
18+ ('Object', 'object', 'pymap', 'pymap_checked', 'object', '<PyObject*>'),
19+ ('Int64', 'int64', 'int64', 'int64', 'int64_t', ''),
20+ ('Int32', 'int32', 'int32', 'int32', 'int32_t', ''),
21+ ('Int16', 'int16', 'int16', 'int16', 'int16_t', ''),
22+ ('Int8', 'int8', 'int8', 'int8', 'int8_t', '')]
2523
2624}}
2725
28- {{for name, dtype, ttype, c_type, to_c_type in dtypes}}
26+ {{for name, dtype, ttype, tfunc_type, c_type, to_c_type in dtypes}}
2927
3028
3129@cython.wraparound(False)
@@ -55,26 +53,26 @@ cdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna, const uint8
5553 # result_keys remembers the original order of keys
5654
5755 result_keys = {{name}}Vector()
58- table = kh_init_{{ttype }}()
56+ table = kh_init_{{tfunc_type }}()
5957
6058 {{if dtype == 'object'}}
6159 if uses_mask:
6260 raise NotImplementedError("uses_mask not implemented with object dtype")
6361
64- kh_resize_{{ttype }}(table, n // 10)
62+ kh_resize_{{tfunc_type }}(table, n // 10)
6563
6664 for i in range(n):
6765 val = values[i]
6866 if not dropna or not checknull(val):
69- k = kh_get_{{ttype }}(table, {{to_c_type}}val)
67+ k = kh_get_{{tfunc_type }}(table, {{to_c_type}}val)
7068 if k != table.n_buckets:
7169 table.vals[k] += 1
7270 else:
73- k = kh_put_{{ttype }}(table, {{to_c_type}}val, &ret)
71+ k = kh_put_{{tfunc_type }}(table, {{to_c_type}}val, &ret)
7472 table.vals[k] = 1
7573 result_keys.append(val)
7674 {{else}}
77- kh_resize_{{ttype }}(table, n)
75+ kh_resize_{{tfunc_type }}(table, n)
7876
7977 for i in range(n):
8078 val = {{to_c_type}}(values[i])
@@ -90,11 +88,11 @@ cdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna, const uint8
9088 if uses_mask and isna_entry:
9189 na_counter += 1
9290 else:
93- k = kh_get_{{ttype }}(table, val)
91+ k = kh_get_{{tfunc_type }}(table, val)
9492 if k != table.n_buckets:
9593 table.vals[k] += 1
9694 else:
97- k = kh_put_{{ttype }}(table, val, &ret)
95+ k = kh_put_{{tfunc_type }}(table, val, &ret)
9896 table.vals[k] = 1
9997 result_keys.append(val)
10098 {{endif}}
@@ -107,17 +105,17 @@ cdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna, const uint8
107105
108106 for i in range(table.size):
109107 {{if dtype == 'object'}}
110- k = kh_get_{{ttype }}(table, result_keys.data[i])
108+ k = kh_get_{{tfunc_type }}(table, result_keys.data[i])
111109 {{else}}
112- k = kh_get_{{ttype }}(table, result_keys.data.data[i])
110+ k = kh_get_{{tfunc_type }}(table, result_keys.data.data[i])
113111 {{endif}}
114112 result_counts[i] = table.vals[k]
115113
116114 if na_counter > 0:
117115 result_counts[table.size] = na_counter
118116 result_keys.append(val)
119117
120- kh_destroy_{{ttype }}(table)
118+ kh_destroy_{{tfunc_type }}(table)
121119
122120 return result_keys.to_array(), result_counts.base, na_counter
123121
@@ -138,12 +136,12 @@ cdef duplicated_{{dtype}}(const {{dtype}}_t[:] values, object keep='first', cons
138136 {{endif}}
139137 Py_ssize_t i, n = len(values), first_na = -1
140138 khiter_t k
141- kh_{{ttype}}_t *table = kh_init_{{ttype }}()
139+ kh_{{ttype}}_t *table = kh_init_{{tfunc_type }}()
142140 ndarray[uint8_t, ndim=1, cast=True] out = np.empty(n, dtype='bool')
143141 bint seen_na = False, uses_mask = mask is not None
144142 bint seen_multiple_na = False
145143
146- kh_resize_{{ttype }}(table, min(kh_needed_n_buckets(n), SIZE_HINT_LIMIT))
144+ kh_resize_{{tfunc_type }}(table, min(kh_needed_n_buckets(n), SIZE_HINT_LIMIT))
147145
148146 if keep not in ('last', 'first', False):
149147 raise ValueError('keep must be either "first", "last" or False')
@@ -168,7 +166,7 @@ cdef duplicated_{{dtype}}(const {{dtype}}_t[:] values, object keep='first', cons
168166 seen_na = True
169167 else:
170168 value = {{to_c_type}}(values[i])
171- kh_put_{{ttype }}(table, value, &ret)
169+ kh_put_{{tfunc_type }}(table, value, &ret)
172170 out[i] = ret == 0
173171 {{endfor}}
174172
@@ -193,16 +191,16 @@ cdef duplicated_{{dtype}}(const {{dtype}}_t[:] values, object keep='first', cons
193191
194192 else:
195193 value = {{to_c_type}}(values[i])
196- k = kh_get_{{ttype }}(table, value)
194+ k = kh_get_{{tfunc_type }}(table, value)
197195 if k != table.n_buckets:
198196 out[table.vals[k]] = 1
199197 out[i] = 1
200198 else:
201- k = kh_put_{{ttype }}(table, value, &ret)
199+ k = kh_put_{{tfunc_type }}(table, value, &ret)
202200 table.vals[k] = i
203201 out[i] = 0
204202
205- kh_destroy_{{ttype }}(table)
203+ kh_destroy_{{tfunc_type }}(table)
206204 return out
207205
208206
@@ -243,11 +241,11 @@ cdef ismember_{{dtype}}(const {{dtype}}_t[:] arr, const {{dtype}}_t[:] values):
243241 {{c_type}} val
244242 {{endif}}
245243
246- kh_{{ttype}}_t *table = kh_init_{{ttype }}()
244+ kh_{{ttype}}_t *table = kh_init_{{tfunc_type }}()
247245
248246 # construct the table
249247 n = len(values)
250- kh_resize_{{ttype }}(table, n)
248+ kh_resize_{{tfunc_type }}(table, n)
251249
252250 {{if dtype == 'object'}}
253251 if True:
@@ -256,7 +254,7 @@ cdef ismember_{{dtype}}(const {{dtype}}_t[:] arr, const {{dtype}}_t[:] values):
256254 {{endif}}
257255 for i in range(n):
258256 val = {{to_c_type}}(values[i])
259- kh_put_{{ttype }}(table, val, &ret)
257+ kh_put_{{tfunc_type }}(table, val, &ret)
260258
261259 # test membership
262260 n = len(arr)
@@ -269,10 +267,10 @@ cdef ismember_{{dtype}}(const {{dtype}}_t[:] arr, const {{dtype}}_t[:] values):
269267 {{endif}}
270268 for i in range(n):
271269 val = {{to_c_type}}(arr[i])
272- k = kh_get_{{ttype }}(table, val)
270+ k = kh_get_{{tfunc_type }}(table, val)
273271 result[i] = (k != table.n_buckets)
274272
275- kh_destroy_{{ttype }}(table)
273+ kh_destroy_{{tfunc_type }}(table)
276274 return result.view(np.bool_)
277275
278276# ----------------------------------------------------------------------
0 commit comments