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