55# pool at each step.
66
77import numpy as np
8- cimport numpy as cnp
98from cython cimport floating
109
11- cnp.import_array()
1210
1311
1412def _inplace_contiguous_isotonic_regression (floating[::1] y , floating[::1] w ):
@@ -62,9 +60,9 @@ def _inplace_contiguous_isotonic_regression(floating[::1] y, floating[::1] w):
6260 i = k
6361
6462
65- def _make_unique (cnp.ndarray[ dtype = floating] X,
66- cnp.ndarray[ dtype = floating] y,
67- cnp.ndarray[ dtype = floating] sample_weights):
63+ def _make_unique (const floating[::1 ] X ,
64+ const floating[::1 ] y ,
65+ const floating[::1 ] sample_weights ):
6866 """ Average targets for duplicate X, drop duplicates.
6967
7068 Aggregates duplicate X values into a single X value where
@@ -75,10 +73,14 @@ def _make_unique(cnp.ndarray[dtype=floating] X,
7573 """
7674 unique_values = len (np.unique(X))
7775
78- cdef cnp.ndarray[dtype= floating] y_out = np.empty(unique_values,
79- dtype = X.dtype)
80- cdef cnp.ndarray[dtype= floating] x_out = np.empty_like(y_out)
81- cdef cnp.ndarray[dtype= floating] weights_out = np.empty_like(y_out)
76+ if floating is float :
77+ dtype = np.float32
78+ else :
79+ dtype = np.float64
80+
81+ cdef floating[::1 ] y_out = np.empty(unique_values, dtype = dtype)
82+ cdef floating[::1 ] x_out = np.empty_like(y_out)
83+ cdef floating[::1 ] weights_out = np.empty_like(y_out)
8284
8385 cdef floating current_x = X[0 ]
8486 cdef floating current_y = 0
@@ -88,7 +90,
9564
7 @@ def _make_unique(cnp.ndarray[dtype=floating] X,
8890 cdef int j
8991 cdef floating x
9092 cdef int n_samples = len (X)
91- cdef floating eps = np.finfo(X. dtype).resolution
93+ cdef floating eps = np.finfo(dtype).resolution
9294
9395 for j in range (n_samples):
9496 x = X[j]
@@ -108,4 +110,8 @@ def _make_unique(cnp.ndarray[dtype=floating] X,
108110 x_out[i] = current_x
109111 weights_out[i] = current_weight
110112 y_out[i] = current_y / current_weight
111- return x_out[:i+ 1 ], y_out[:i+ 1 ], weights_out[:i+ 1 ]
113+ return (
114+ np.asarray(x_out[:i+ 1 ]),
115+ np.asarray(y_out[:i+ 1 ]),
116+ np.asarray(weights_out[:i+ 1 ]),
117+ )
0 commit comments