@@ -336,24 +336,24 @@ cdef class HashTable:
336
336
337
337
{{py:
338
338
339
- # name, dtype, c_type, float_group, complex_group
340
- dtypes = [('Complex128', 'complex128', 'khcomplex128_t', True, True),
341
- ('Float64', 'float64', 'float64_t', True, False),
342
- ('UInt64', 'uint64', 'uint64_t', False, False),
343
- ('Int64', 'int64', 'int64_t', False, False),
344
- ('Complex64', 'complex64', 'khcomplex64_t', True, True),
345
- ('Float32', 'float32', 'float32_t', True, False),
346
- ('UInt32', 'uint32', 'uint32_t', False, False),
347
- ('Int32', 'int32', 'int32_t', False, False),
348
- ('UInt16', 'uint16', 'uint16_t', False, False),
349
- ('Int16', 'int16', 'int16_t', False, False),
350
- ('UInt8', 'uint8', 'uint8_t', False, False),
351
- ('Int8', 'int8', 'int8_t', False, False)]
339
+ # name, dtype, c_type, float_group, complex_group, to_c_type
340
+ dtypes = [('Complex128', 'complex128', 'khcomplex128_t', True, True, "to_khcomplex128_t" ),
341
+ ('Float64', 'float64', 'float64_t', True, False, "" ),
342
+ ('UInt64', 'uint64', 'uint64_t', False, False, "" ),
343
+ ('Int64', 'int64', 'int64_t', False, False, "" ),
344
+ ('Complex64', 'complex64', 'khcomplex64_t', True, True, "to_khcomplex64_t" ),
345
+ ('Float32', 'float32', 'float32_t', True, False, "" ),
346
+ ('UInt32', 'uint32', 'uint32_t', False, False, "" ),
347
+ ('Int32', 'int32', 'int32_t', False, False, "" ),
348
+ ('UInt16', 'uint16', 'uint16_t', False, False, "" ),
349
+ ('Int16', 'int16', 'int16_t', False, False, "" ),
350
+ ('UInt8', 'uint8', 'uint8_t', False, False, "" ),
351
+ ('Int8', 'int8', 'int8_t', False, False, "" )]
352
352
353
353
}}
354
354
355
355
356
- {{for name, dtype, c_type, float_group, complex_group in dtypes}}
356
+ {{for name, dtype, c_type, float_group, complex_group, to_c_type in dtypes}}
357
357
358
358
cdef class {{name}}HashTable(HashTable):
359
359
@@ -375,11 +375,7 @@ cdef class {{name}}HashTable(HashTable):
375
375
cdef:
376
376
khiter_t k
377
377
{{c_type}} ckey
378
- {{if complex_group}}
379
- ckey = to_{{c_type}}(key)
380
- {{else}}
381
- ckey = key
382
- {{endif}}
378
+ ckey = {{to_c_type}}(key)
383
379
k = kh_get_{{dtype}}(self.table, ckey)
384
380
return k != self.table.n_buckets
385
381
@@ -395,11 +391,7 @@ cdef class {{name}}HashTable(HashTable):
395
391
cdef:
396
392
khiter_t k
397
393
{{c_type}} cval
398
- {{if complex_group}}
399
- cval = to_{{c_type}}(val)
400
- {{else}}
401
- cval = val
402
- {{endif}}
394
+ cval = {{to_c_type}}(val)
403
395
k = kh_get_{{dtype}}(self.table, cval)
404
396
if k != self.table.n_buckets:
405
397
return self.table.vals[k]
@@ -411,11 +403,7 @@ cdef class {{name}}HashTable(HashTable):
411
403
khiter_t k
412
404
int ret = 0
413
405
{{c_type}} ckey
414
- {{if complex_group}}
415
- ckey = to_{{c_type}}(key)
416
- {{else}}
417
- ckey = key
418
- {{endif}}
406
+ ckey = {{to_c_type}}(key)
419
407
k = kh_put_{{dtype}}(self.table, ckey, &ret)
420
408
if kh_exist_{{dtype}}(self.table, k):
421
409
self.table.vals[k] = val
@@ -432,11 +420,7 @@ cdef class {{name}}HashTable(HashTable):
432
420
433
421
with nogil:
434
422
for i in range(n):
435
- {{if complex_group}}
436
- key = to_{{c_type}}(keys[i])
437
- {{else}}
438
- key = keys[i]
439
- {{endif}}
423
+ key = {{to_c_type}}(keys[i])
440
424
k = kh_put_{{dtype}}(self.table, key, &ret)
441
425
self.table.vals[k] = <Py_ssize_t>values[i]
442
426
@@ -450,11 +434,7 @@ cdef class {{name}}HashTable(HashTable):
450
434
451
435
with nogil:
452
436
for i in range(n):
453
- {{if complex_group}}
454
- val= to_{{c_type}}(values[i])
455
- {{else}}
456
- val = values[i]
457
- {{endif}}
437
+ val= {{to_c_type}}(values[i])
458
438
k = kh_put_{{dtype}}(self.table, val, &ret)
459
439
self.table.vals[k] = i
460
440
@@ -469,11 +449,7 @@ cdef class {{name}}HashTable(HashTable):
469
449
470
450
with nogil:
471
451
for i in range(n):
472
- {{if complex_group}}
473
- val = to_{{c_type}}(values[i])
474
- {{else}}
475
- val = values[i]
476
- {{endif}}
452
+ val = {{to_c_type}}(values[i])
477
453
k = kh_get_{{dtype}}(self.table, val)
478
454
if k != self.table.n_buckets:
479
455
locs[i] = self.table.vals[k]
@@ -550,25 +526,13 @@ cdef class {{name}}HashTable(HashTable):
550
526
# We use None, to make it optional, which requires `object` type
551
527
# for the parameter. To please the compiler, we use na_value2,
552
528
# which is only used if it's *specified*.
553
- {{if complex_group}}
554
- na_value2 = to_{{c_type}}(na_value)
555
- {{else}}
556
- na_value2 = na_value
557
- {{endif}}
529
+ na_value2 = {{to_c_type}}(na_value)
558
530
else:
559
- {{if complex_group}}
560
- na_value2 = to_{{c_type}}(0)
561
- {{else}}
562
- na_value2 = 0
563
- {{endif}}
531
+ na_value2 = {{to_c_type}}(0)
564
532
565
533
with nogil:
566
534
for i in range(n):
567
- {{if complex_group}}
568
- val = to_{{c_type}}(values[i])
569
- {{else}}
570
- val = values[i]
571
- {{endif}}
535
+ val = {{to_c_type}}(values[i])
572
536
573
537
if ignore_na and use_mask:
574
538
if mask_values[i]:
@@ -702,11 +666,7 @@ cdef class {{name}}HashTable(HashTable):
702
666
703
667
with nogil:
704
668
for i in range(n):
705
- {{if complex_group}}
706
- val = to_{{c_type}}(values[i])
707
- {{else}}
708
- val = values[i]
709
- {{endif}}
669
+ val = {{to_c_type}}(values[i])
710
670
711
671
# specific for groupby
712
672
{{if dtype == 'complex64' or dtype== 'complex128'}}
0 commit comments