@@ -887,29 +887,48 @@ cdef build_count_table_float64(float64_t[:] values, kh_float64_t *table, bint dr
887
887
k = kh_put_float64(table, val, & ret)
888
888
table.vals[k] = 1
889
889
890
+
890
891
@ cython.boundscheck (False )
891
- cpdef value_count_float64(float64_t [:] values, bint dropna):
892
+ cpdef value_count_scalar64(sixty_four_bit_scalar [:] values, bint dropna):
892
893
cdef:
893
894
Py_ssize_t i
894
- kh_float64_t * table
895
- float64_t[:] result_keys
895
+ kh_float64_t * ftable
896
+ kh_int64_t * itable
897
+ sixty_four_bit_scalar[:] result_keys
896
898
int64_t[:] result_counts
897
899
int k
898
900
899
- table = kh_init_float64()
900
- build_count_table_float64(values, table, dropna)
901
-
902
901
i = 0
903
- result_keys = np.empty(table.n_occupied, dtype = np.float64)
904
- result_counts = np.zeros(table.n_occupied, dtype = np.int64)
905
902
906
- with nogil:
907
- for k in range (table.n_buckets):
908
- if kh_exist_float64(table, k):
909
- result_keys[i] = table.keys[k]
910
- result_counts[i] = table.vals[k]
911
- i += 1
912
- kh_destroy_float64(table)
903
+ if sixty_four_bit_scalar is float64_t:
904
+ ftable = kh_init_float64()
905
+ build_count_table_float64(values, ftable, dropna)
906
+
907
+ result_keys = np.empty(ftable.n_occupied, dtype = np.float64)
908
+ result_counts = np.zeros(ftable.n_occupied, dtype = np.int64)
909
+
910
+ with nogil:
911
+ for k in range (ftable.n_buckets):
912
+ if kh_exist_float64(ftable, k):
913
+ result_keys[i] = ftable.keys[k]
914
+ result_counts[i] = ftable.vals[k]
915
+ i += 1
916
+ kh_destroy_float64(ftable)
917
+
918
+ elif sixty_four_bit_scalar is int64_t:
919
+ itable = kh_init_int64()
920
+ build_count_table_int64(values, itable)
921
+
922
+ result_keys = np.empty(itable.n_occupied, dtype = np.int64)
923
+ result_counts = np.zeros(itable.n_occupied, dtype = np.int64)
924
+
925
+ with nogil:
926
+ for k in range (itable.n_buckets):
927
+ if kh_exist_int64(itable, k):
928
+ result_keys[i] = itable.keys[k]
929
+ result_counts[i] = itable.vals[k]
930
+ i += 1
931
+ kh_destroy_int64(itable)
913
932
914
933
return np.asarray(result_keys), np.asarray(result_counts)
915
934
@@ -934,32 +953,6 @@ cdef build_count_table_int64(int64_t[:] values, kh_int64_t *table):
934
953
table.vals[k] = 1
935
954
936
955
937
- @ cython.boundscheck (False )
938
- cpdef value_count_int64(int64_t[:] values):
939
- cdef:
940
- Py_ssize_t i
941
- kh_int64_t * table
942
- int64_t[:] result_keys, result_counts
943
- int k
944
-
945
- table = kh_init_int64()
946
- build_count_table_int64(values, table)
947
-
948
- i = 0
949
- result_keys = np.empty(table.n_occupied, dtype = np.int64)
950
- result_counts = np.zeros(table.n_occupied, dtype = np.int64)
951
-
952
- with nogil:
953
- for k in range (table.n_buckets):
954
- if kh_exist_int64(table, k):
955
- result_keys[i] = table.keys[k]
956
- result_counts[i] = table.vals[k]
957
- i += 1
958
- kh_destroy_int64(table)
959
-
960
- return np.asarray(result_keys), np.asarray(result_counts)
961
-
962
-
963
956
cdef build_count_table_object(ndarray[object ] values,
964
957
ndarray[uint8_t, cast= True ] mask,
965
958
kh_pymap_t * table):
0 commit comments