@@ -8,6 +8,8 @@ import numpy as np
8
8
cimport numpy as np
9
9
10
10
from sklearn.utils.extmath import row_norms
11
+ from cython cimport floating
12
+
11
13
from libc.stdint cimport int32_t, int64_t
12
14
# instead of int and long
13
15
@@ -26,12 +28,12 @@ np.import_array()
26
28
cdef floating _euclidean_dense_dense(
27
29
floating* a, # IN
28
30
floating* b, # IN
29
- int64_t n_features) nogil:
31
+ int32_t n_features) nogil:
30
32
""" Euclidean distance between a dense and b dense"""
31
33
cdef:
32
- int64_t i
33
- int64_t n = n_features // 4
34
- int64_t rem = n_features % 4
34
+ int32_t i
35
+ int32_t n = n_features // 4
36
+ int32_t rem = n_features % 4
35
37
floating result = 0
36
38
37
39
# We manually unroll the loop for better cache optimization.
@@ -50,7 +52,7 @@ cdef floating _euclidean_dense_dense(
50
52
51
53
52
54
cpdef np.ndarray[floating] _kmeans_loss(np.ndarray[floating, ndim= 2 , mode= ' c' ] X,
53
- int64_t [:] labels):
55
+ int32_t [:] labels):
54
56
""" Compute inertia
55
57
56
58
squared distancez between each sample and its assigned center.
@@ -61,14 +63,14 @@ cpdef np.ndarray[floating] _kmeans_loss(np.ndarray[floating, ndim=2, mode='c'] X
61
63
dtype = np.double
62
64
63
65
cdef:
64
- int64_t n_samples = X.shape[0 ]
65
- int64_t n_features = X.shape[1 ]
66
- int64_t i, j
67
- int64_t n_classes = len (np.unique(labels))
66
+ int32_t n_samples = X.shape[0 ]
67
+ int32_t n_features = X.shape[1 ]
68
+ int32_t i, j
69
+ int32_t n_classes = len (np.unique(labels))
68
70
np.ndarray[floating, ndim= 2 ] centers = np.zeros([n_classes,
69
71
n_features],
70
72
dtype = dtype)
71
- np.ndarray[long ] num_in_cluster = np.zeros(n_classes, dtype = int64_t )
73
+ np.ndarray[int64_t ] num_in_cluster = np.zeros(n_classes, dtype = int32_t )
72
74
np.ndarray[floating] inertias = np.zeros(n_samples, dtype = dtype)
73
75
for i in range (n_samples):
74
76
for j in range (n_features):
0 commit comments