diff --git a/sklearn/cluster/k_means_.py b/sklearn/cluster/k_means_.py index 2f5b86e92e09a..937f68a1e24ab 100644 --- a/sklearn/cluster/k_means_.py +++ b/sklearn/cluster/k_means_.py @@ -26,6 +26,7 @@ from ..utils import atleast2d_or_csr from ..utils import as_float_array from ..utils import gen_batches +from ..utils.random import choice from ..externals.joblib import Parallel from ..externals.joblib import delayed @@ -396,28 +397,59 @@ def _kmeans_single(X, n_clusters, x_squared_norms, max_iter=300, return best_labels, best_inertia, best_centers -def _labels_inertia_precompute_dense(X, x_squared_norms, centers): +def _labels_inertia_precompute_dense(X, x_squared_norms, centers, distances): + """Compute labels and inertia using a full distance matrix. + + This will overwrite the 'distances' array in-place. + + Parameters + ---------- + X : numpy array, shape (n_sample, n_features) + Input data. + + x_squared_norms : numpy array, shape (n_samples,) + Precomputed squared norms of X. + + centers : numpy array, shape (n_clusters, n_features) + Cluster centers which data is assigned to. + + distances : numpy array, shape (n_samples,) + Pre-allocated array in which distances are stored. + + Returns + ------- + labels : numpy array, dtype=np.int, shape (n_samples,) + Indices of clusters that samples are assigned to. + + inertia : float + Sum of distances of samples to their closest cluster center. + + """ n_samples = X.shape[0] k = centers.shape[0] - distances = euclidean_distances(centers, X, x_squared_norms, - squared=True) + all_distances = euclidean_distances(centers, X, x_squared_norms, + squared=True) labels = np.empty(n_samples, dtype=np.int32) labels.fill(-1) mindist = np.empty(n_samples) mindist.fill(np.infty) for center_id in range(k): - dist = distances[center_id] + dist = all_distances[center_id] labels[dist < mindist] = center_id mindist = np.minimum(dist, mindist) + if n_samples == distances.shape[0]: + # distances will be changed in-place + distances[:] = mindist inertia = mindist.sum() return labels, inertia def _labels_inertia(X, x_squared_norms, centers, precompute_distances=True, distances=None): - """E step of the K-means EM algorithm + """E step of the K-means EM algorithm. - Compute the labels and the inertia of the given samples and centers + Compute the labels and the inertia of the given samples and centers. + This will compute the distances in-place. Parameters ---------- @@ -431,6 +463,9 @@ def _labels_inertia(X, x_squared_norms, centers, centers: float64 array, shape (k, n_features) The cluster centers. + precompute_distances : boolean, default: True + Precompute distances (faster but takes more memory). + distances: float64 array, shape (n_samples,) Pre-allocated array to be filled in with each sample's distance to the closest center. @@ -440,22 +475,23 @@ def _labels_inertia(X, x_squared_norms, centers, labels: int array of shape(n) The resulting assignment - inertia: float - The value of the inertia criterion with the assignment + inertia : float + Sum of distances of samples to their closest cluster center. """ n_samples = X.shape[0] # set the default value of centers to -1 to be able to detect any anomaly # easily - labels = - np.ones(n_samples, np.int32) + labels = -np.ones(n_samples, np.int32) if distances is None: distances = np.zeros(shape=(0,), dtype=np.float64) + # distances will be changed in-place if sp.issparse(X): inertia = _k_means._assign_labels_csr( X, x_squared_norms, centers, labels, distances=distances) else: if precompute_distances: return _labels_inertia_precompute_dense(X, x_squared_norms, - centers) + centers, distances) inertia = _k_means._assign_labels_array( X, x_squared_norms, centers, labels, distances=distances) return labels, inertia @@ -550,11 +586,11 @@ class KMeans(BaseEstimator, ClusterMixin, TransformerMixin): The number of clusters to form as well as the number of centroids to generate. - max_iter : int + max_iter : int, default: 300 Maximum number of iterations of the k-means algorithm for a single run. - n_init : int, optional, default: 10 + n_init : int, default: 10 Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of n_init consecutive runs in terms of inertia. @@ -572,15 +608,16 @@ class KMeans(BaseEstimator, ClusterMixin, TransformerMixin): If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. - precompute_distances : boolean + precompute_distances : boolean, default: True Precompute distances (faster but takes more memory). - tol : float, optional default: 1e-4 + tol : float, default: 1e-4 Relative tolerance with regards to inertia to declare convergence - n_jobs : int - The number of jobs to use for the computation. This works by computing - each of the n_init runs in parallel. + n_jobs : int, default: 1 + The number of jobs to use for the computation. This works by breaking + down the pairwise matrix into n_jobs even slices and computing them in + parallel. If -1 all CPUs are used. If 1 is given, no parallel computing code is used at all, which is useful for debugging. For n_jobs below -1, @@ -601,8 +638,7 @@ class KMeans(BaseEstimator, ClusterMixin, TransformerMixin): Labels of each point `inertia_` : float - The value of the inertia criterion associated with the chosen - partition. + Sum of distances of samples to their closest cluster center. Notes ------ @@ -716,7 +752,7 @@ def fit_transform(self, X, y=None): return self.fit(X)._transform(X) def transform(self, X, y=None): - """Transform X to a cluster-distance space + """Transform X to a cluster-distance space. In the new space, each dimension is the distance to the cluster centers. Note that even if X is sparse, the array returned by @@ -786,47 +822,55 @@ def _mini_batch_step(X, x_squared_norms, centers, counts, distances, random_reassign=False, random_state=None, reassignment_ratio=.01, verbose=False): - """Incremental update of the centers for the Minibatch K-Means algorithm + """Incremental update of the centers for the Minibatch K-Means algorithm. Parameters ---------- - X: array, shape (n_samples, n_features) + X : array, shape (n_samples, n_features) The original data array. - x_squared_norms: array, shape (n_samples,) + x_squared_norms : array, shape (n_samples,) Squared euclidean norm of each data point. - centers: array, shape (k, n_features) + centers : array, shape (k, n_features) The cluster centers. This array is MODIFIED IN PLACE - counts: array, shape (k,) + counts : array, shape (k,) The vector in which we keep track of the numbers of elements in a cluster. This array is MODIFIED IN PLACE - distances: array, dtype float64, shape (n_samples), optional + distances : array, dtype float64, shape (n_samples), optional If not None, should be a pre-allocated array that will be used to store - the distances of each sample to it's closest center. + the distances of each sample to its closest center. May not be None when random_reassign is True. - random_state: integer or numpy.RandomState, optional + random_state : integer or numpy.RandomState, optional The generator used to initialize the centers. If an integer is given, it fixes the seed. Defaults to the global numpy random number generator. - random_reassign: boolean, optional - If True, centers with very low counts are - randomly-reassigned to observations in dense areas. + random_reassign : boolean, optional + If True, centers with very low counts are randomly reassigned + to observations. - reassignment_ratio: float, optional + reassignment_ratio : float, optional Control the fraction of the maximum number of counts for a center to be reassigned. A higher value means that low count - centers are more easily reassigned, which means that the + centers are more likely to be reassigned, which means that the model will take longer to converge, but should converge in a better clustering. - verbose: bool, optional - Controls the verbosity + verbose : bool, optional + Controls the verbosity. + + Returns + ------- + inertia : float + Sum of distances of samples to their closest cluster center. + + squared_diff : numpy array, shape (n_clusters,) + Squared distances between previous and updated cluster centers. """ # Perform label assignment to nearest centers @@ -836,30 +880,29 @@ def _mini_batch_step(X, x_squared_norms, centers, counts, if random_reassign and reassignment_ratio > 0: random_state = check_random_state(random_state) # Reassign clusters that have very low counts - to_reassign = np.logical_or( - (counts <= 1), counts <= reassignment_ratio * counts.max()) - number_of_reassignments = to_reassign.sum() - if number_of_reassignments: - # Pick new clusters amongst observations with probability - # proportional to their closeness to their center. - # Flip the ordering of the distances. - distances -= distances.max() - distances *= -1 - rand_vals = random_state.rand(number_of_reassignments) - rand_vals *= distances.sum() - new_centers = np.searchsorted(distances.cumsum(), - rand_vals) + to_reassign = counts < reassignment_ratio * counts.max() + # pick at most .5 * batch_size samples as new centers + if to_reassign.sum() > .5 * X.shape[0]: + indices_dont_reassign = np.argsort(counts)[int(.5 * X.shape[0]):] + to_reassign[indices_dont_reassign] = False + n_reassigns = to_reassign.sum() + if n_reassigns: + # Pick new clusters amongst observations with uniform probability + new_centers = choice(X.shape[0], replace=False, size=n_reassigns, + random_state=random_state) if verbose: - n_reassigns = to_reassign.sum() - if n_reassigns: - print("[MiniBatchKMeans] Reassigning %i cluster centers." - % n_reassigns) + print("[MiniBatchKMeans] Reassigning %i cluster centers." + % n_reassigns) if sp.issparse(X) and not sp.issparse(centers): assign_rows_csr(X, new_centers, np.where(to_reassign)[0], centers) else: centers[to_reassign] = X[new_centers] + # reset counts of reassigned centers, but don't reset them too small + # to avoid instant reassignment. This is a pretty dirty hack as it + # also modifies the learning rates. + counts[to_reassign] = np.min(counts[~to_reassign]) # implementation for the sparse CSR representation completely written in # cython @@ -980,14 +1023,14 @@ class MiniBatchKMeans(KMeans): Maximum number of iterations over the complete dataset before stopping independently of any early stopping criterion heuristics. - max_no_improvement : int, optional + max_no_improvement : int, default: 10 Control early stopping based on the consecutive number of mini batches that does not yield an improvement on the smoothed inertia. To disable convergence detection based on inertia, set max_no_improvement to None. - tol : float, optional + tol : float, default: 0.0 Control early stopping based on the relative center changes as measured by a smoothed, variance-normalized of the mean center squared position changes. This early stopping heuristics is @@ -1007,7 +1050,7 @@ class MiniBatchKMeans(KMeans): only algorithm is initialized by running a batch KMeans on a random subset of the data. This needs to be larger than k. - init : {'k-means++', 'random' or an ndarray} + init : {'k-means++', 'random' or an ndarray}, default: 'k-means++' Method for initialization, defaults to 'k-means++': 'k-means++' : selects initial cluster centers for k-mean @@ -1017,7 +1060,6 @@ class MiniBatchKMeans(KMeans): 'random': choose k observations (rows) at random from data for the initial centroids. - If an ndarray is passed, it should be of shape (n_clusters, n_features) and gives the initial centers. @@ -1026,7 +1068,7 @@ class MiniBatchKMeans(KMeans): In contrast to KMeans, the algorithm is only run once, using the best of the ``n_init`` initializations as measured by inertia. - compute_labels : boolean + compute_labels : boolean, default=True Compute label assignment and inertia for the complete dataset once the minibatch optimization has converged in fit. @@ -1035,7 +1077,7 @@ class MiniBatchKMeans(KMeans): given, it fixes the seed. Defaults to the global numpy random number generator. - reassignment_ratio : float, optional + reassignment_ratio : float, default: 0.01 Control the fraction of the maximum number of counts for a center to be reassigned. A higher value means that low count centers are more easily reassigned, which means that the @@ -1159,7 +1201,7 @@ def fit(self, X, y=None): batch_inertia, centers_squared_diff = _mini_batch_step( X_valid, x_squared_norms[validation_indices], cluster_centers, counts, old_center_buffer, False, - distances=distances, verbose=self.verbose) + distances=None, verbose=self.verbose) # Keep only the best cluster centers across independent inits on # the common validation set @@ -1257,7 +1299,8 @@ def partial_fit(self, X, y=None): return self x_squared_norms = row_norms(X, squared=True) - self.random_state_ = check_random_state(self.random_state) + self.random_state_ = getattr(self, "random_state_", + check_random_state(self.random_state)) if (not hasattr(self, 'counts_') or not hasattr(self, 'cluster_centers_')): # this is the first call partial_fit on this object: @@ -1276,7 +1319,7 @@ def partial_fit(self, X, y=None): # reassignment too often, to allow for building up counts random_reassign = self.random_state_.randint( 10 * (1 + self.counts_.min())) == 0 - distances = np.zeros(self.n_clusters, dtype=np.float64) + distances = np.zeros(X.shape[0], dtype=np.float64) _mini_batch_step(X, x_squared_norms, self.cluster_centers_, self.counts_, np.zeros(0, np.double), 0, diff --git a/sklearn/cluster/tests/test_k_means.py b/sklearn/cluster/tests/test_k_means.py index 25d19e04a0037..66b3a42f00ee0 100644 --- a/sklearn/cluster/tests/test_k_means.py +++ b/sklearn/cluster/tests/test_k_means.py @@ -312,15 +312,49 @@ def test_minibatch_k_means_perfect_init_sparse_csr(): _check_fitted_model(mb_k_means) +def test_minibatch_sensible_reassign_fit(): + # check if identical initial clusters are reassigned + # also a regression test for when there are more desired reassignments than + # samples. + zeroed_X, true_labels = make_blobs(n_samples=100, centers=5, + cluster_std=1., random_state=42) + zeroed_X[::2, :] = 0 + mb_k_means = MiniBatchKMeans(n_clusters=20, batch_size=10, random_state=42, + verbose=10, init="random") + mb_k_means.fit(zeroed_X) + # there should not be too many exact zero cluster centers + assert_greater(mb_k_means.cluster_centers_.any(axis=1).sum(), 10) + + # do the same with batch-size > X.shape[0] (regression test) + mb_k_means = MiniBatchKMeans(n_clusters=20, batch_size=201, + random_state=42, verbose=10, init="random") + mb_k_means.fit(zeroed_X) + # there should not be too many exact zero cluster centers + assert_greater(mb_k_means.cluster_centers_.any(axis=1).sum(), 10) + + +def test_minibatch_sensible_reassign_partial_fit(): + zeroed_X, true_labels = make_blobs(n_samples=n_samples, centers=5, + cluster_std=1., random_state=42) + zeroed_X[::2, :] = 0 + mb_k_means = MiniBatchKMeans(n_clusters=20, random_state=42, verbose=10, + init="random") + for i in range(100): + mb_k_means.partial_fit(zeroed_X) + # there should not be too many exact zero cluster centers + assert_greater(mb_k_means.cluster_centers_.any(axis=1).sum(), 10) + + def test_minibatch_reassign(): # Give a perfect initialization, but a large reassignment_ratio, # as a result all the centers should be reassigned and the model # should not longer be good for this_X in (X, X_csr): - mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, batch_size=1, + mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, batch_size=100, random_state=42) mb_k_means.fit(this_X) - centers_before = mb_k_means.cluster_centers_.copy() + + score_before = mb_k_means.score(this_X) try: old_stdout = sys.stdout sys.stdout = StringIO() @@ -329,32 +363,30 @@ def test_minibatch_reassign(): mb_k_means.cluster_centers_, mb_k_means.counts_, np.zeros(X.shape[1], np.double), - False, distances=np.zeros(n_clusters), + False, distances=np.zeros(X.shape[0]), random_reassign=True, random_state=42, reassignment_ratio=1, verbose=True) finally: sys.stdout = old_stdout - centers_after = mb_k_means.cluster_centers_.copy() - # Check that all the centers have moved - assert_greater(((centers_before - centers_after) ** 2) - .sum(axis=1).min(), .2) + assert_greater(score_before, mb_k_means.score(this_X)) # Give a perfect initialization, with a small reassignment_ratio, # no center should be reassigned for this_X in (X, X_csr): - mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, batch_size=1, + mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, batch_size=100, init=centers.copy(), random_state=42, n_init=1) mb_k_means.fit(this_X) - centers_before = mb_k_means.cluster_centers_.copy() + clusters_before = mb_k_means.cluster_centers_ # Turn on verbosity to smoke test the display code _mini_batch_step(this_X, (X ** 2).sum(axis=1), mb_k_means.cluster_centers_, mb_k_means.counts_, np.zeros(X.shape[1], np.double), - False, distances=np.zeros(n_clusters), + False, distances=np.zeros(X.shape[0]), random_reassign=True, random_state=42, reassignment_ratio=1e-15) + assert_array_almost_equal(clusters_before, mb_k_means.cluster_centers_) def test_minibatch_with_many_reassignments(): diff --git a/sklearn/utils/random.c b/sklearn/utils/_random.c similarity index 89% rename from sklearn/utils/random.c rename to sklearn/utils/_random.c index 58f4ad04cdd35..ddfb88e924473 100644 --- a/sklearn/utils/random.c +++ b/sklearn/utils/_random.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.19.1 on Mon Jul 22 16:27:22 2013 */ +/* Generated by Cython 0.19.1 on Sun Dec 8 01:42:22 2013 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -306,8 +306,8 @@ static CYTHON_INLINE float __PYX_NAN() { #define _USE_MATH_DEFINES #endif #include -#define __PYX_HAVE__sklearn__utils__random -#define __PYX_HAVE_API__sklearn__utils__random +#define __PYX_HAVE__sklearn__utils___random +#define __PYX_HAVE_API__sklearn__utils___random #include "string.h" #include "stdio.h" #include "stdlib.h" @@ -506,7 +506,7 @@ static const char *__pyx_filename; static const char *__pyx_f[] = { - "random.pyx", + "_random.pyx", "numpy.pxd", "type.pxd", }; @@ -792,56 +792,56 @@ typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t; * cdef inline object PyArray_MultiIterNew1(a): */ typedef npy_cdouble __pyx_t_5numpy_complex_t; -struct __pyx_opt_args_7sklearn_5utils_6random_sample_without_replacement; -struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection; -struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_pool; -struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling; +struct __pyx_opt_args_7sklearn_5utils_7_random_sample_without_replacement; +struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection; +struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_pool; +struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling; -/* "sklearn/utils/random.pxd":10 +/* "sklearn/utils/_random.pxd":10 * * * cpdef sample_without_replacement(np.int_t n_population, # <<<<<<<<<<<<<< * np.int_t n_samples, * method=*, */ -struct __pyx_opt_args_7sklearn_5utils_6random_sample_without_replacement { +struct __pyx_opt_args_7sklearn_5utils_7_random_sample_without_replacement { int __pyx_n; PyObject *method; PyObject *random_state; }; -/* "sklearn/utils/random.pyx":43 +/* "sklearn/utils/_random.pyx":42 * * cpdef _sample_without_replacement_with_tracking_selection( * np.int_t n_population, # <<<<<<<<<<<<<< * np.int_t n_samples, * random_state=None): */ -struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection { +struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection { int __pyx_n; PyObject *random_state; }; -/* "sklearn/utils/random.pyx":108 +/* "sklearn/utils/_random.pyx":107 * * * cpdef _sample_without_replacement_with_pool(np.int_t n_population, # <<<<<<<<<<<<<< * np.int_t n_samples, * random_state=None): */ -struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_pool { +struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_pool { int __pyx_n; PyObject *random_state; }; -/* "sklearn/utils/random.pyx":169 +/* "sklearn/utils/_random.pyx":168 * * cpdef _sample_without_replacement_with_reservoir_sampling( * np.int_t n_population, # <<<<<<<<<<<<<< * np.int_t n_samples, * random_state=None): */ -struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling { +struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling { int __pyx_n; PyObject *random_state; }; @@ -1215,26 +1215,26 @@ static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, cha /* Module declarations from 'cython' */ -/* Module declarations from 'sklearn.utils.random' */ -static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random_sample_without_replacement *__pyx_optional_args); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection *__pyx_optional_args); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_pool(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_pool *__pyx_optional_args); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling *__pyx_optional_args); /*proto*/ +/* Module declarations from 'sklearn.utils._random' */ +static PyObject *__pyx_f_7sklearn_5utils_7_random_sample_without_replacement(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random_sample_without_replacement *__pyx_optional_args); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection *__pyx_optional_args); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_pool(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_pool *__pyx_optional_args); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling *__pyx_optional_args); /*proto*/ static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_int_t = { "int_t", NULL, sizeof(__pyx_t_5numpy_int_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_int_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_int_t), 0 }; -#define __Pyx_MODULE_NAME "sklearn.utils.random" -int __pyx_module_is_main_sklearn__utils__random = 0; +#define __Pyx_MODULE_NAME "sklearn.utils._random" +int __pyx_module_is_main_sklearn__utils___random = 0; -/* Implementation of 'sklearn.utils.random' */ +/* Implementation of 'sklearn.utils._random' */ static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_xrange; static PyObject *__pyx_builtin_RuntimeError; -static PyObject *__pyx_pf_7sklearn_5utils_6random__sample_without_replacement_check_input(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples); /* proto */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_with_tracking_selection(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state); /* proto */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_with_pool(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state); /* proto */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_with_reservoir_sampling(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state); /* proto */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_8sample_without_replacement(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_method, PyObject *__pyx_v_random_state); /* proto */ +static PyObject *__pyx_pf_7sklearn_5utils_7_random__sample_without_replacement_check_input(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples); /* proto */ +static PyObject *__pyx_pf_7sklearn_5utils_7_random_2_sample_without_replacement_with_tracking_selection(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state); /* proto */ +static PyObject *__pyx_pf_7sklearn_5utils_7_random_4_sample_without_replacement_with_pool(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state); /* proto */ +static PyObject *__pyx_pf_7sklearn_5utils_7_random_6_sample_without_replacement_with_reservoir_sampling(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state); /* proto */ +static PyObject *__pyx_pf_7sklearn_5utils_7_random_8sample_without_replacement(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_method, PyObject *__pyx_v_random_state); /* proto */ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ static char __pyx_k_1[] = "n_population should be greater than 0, got %s."; @@ -1333,7 +1333,7 @@ static PyObject *__pyx_k_tuple_13; static PyObject *__pyx_k_tuple_14; static PyObject *__pyx_k_tuple_16; -/* "sklearn/utils/random.pyx":29 +/* "sklearn/utils/_random.pyx":28 * * * cpdef _sample_without_replacement_check_input(np.int_t n_population, # <<<<<<<<<<<<<< @@ -1341,8 +1341,8 @@ static PyObject *__pyx_k_tuple_16; * """ Check that input are consistent for sample_without_replacement""" */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_check_input(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_1_sample_without_replacement_check_input(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -1354,7 +1354,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_che int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_sample_without_replacement_check_input", 0); - /* "sklearn/utils/random.pyx":32 + /* "sklearn/utils/_random.pyx":31 * np.int_t n_samples): * """ Check that input are consistent for sample_without_replacement""" * if n_population < 0: # <<<<<<<<<<<<<< @@ -1364,34 +1364,34 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_che __pyx_t_1 = ((__pyx_v_n_population < 0) != 0); if (__pyx_t_1) { - /* "sklearn/utils/random.pyx":34 + /* "sklearn/utils/_random.pyx":33 * if n_population < 0: * raise ValueError('n_population should be greater than 0, got %s.' * % n_population) # <<<<<<<<<<<<<< * * if n_samples > n_population: */ - __pyx_t_2 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L3; } __pyx_L3:; - /* "sklearn/utils/random.pyx":36 + /* "sklearn/utils/_random.pyx":35 * % n_population) * * if n_samples > n_population: # <<<<<<<<<<<<<< @@ -1401,18 +1401,18 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_che __pyx_t_1 = ((__pyx_v_n_samples > __pyx_v_n_population) != 0); if (__pyx_t_1) { - /* "sklearn/utils/random.pyx":39 + /* "sklearn/utils/_random.pyx":38 * raise ValueError('n_population should be greater or equal than ' * 'n_samples, got n_samples > n_population (%s > %s)' * % (n_samples, n_population)) # <<<<<<<<<<<<<< * * */ - __pyx_t_3 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __pyx_t_2 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); @@ -1420,20 +1420,20 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_che __Pyx_GIVEREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_2), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L4; } __pyx_L4:; @@ -1444,7 +1444,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_che __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_check_input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_check_input", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -1453,9 +1453,9 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_che } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_check_input(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_5utils_6random__sample_without_replacement_check_input[] = " Check that input are consistent for sample_without_replacement"; -static PyObject *__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_check_input(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_1_sample_without_replacement_check_input(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_5utils_7_random__sample_without_replacement_check_input[] = " Check that input are consistent for sample_without_replacement"; +static PyObject *__pyx_pw_7sklearn_5utils_7_random_1_sample_without_replacement_check_input(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_5numpy_int_t __pyx_v_n_population; __pyx_t_5numpy_int_t __pyx_v_n_samples; int __pyx_lineno = 0; @@ -1484,11 +1484,11 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_c case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_samples)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_check_input", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_check_input", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_check_input") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_check_input") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -1496,23 +1496,23 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_c values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } - __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_check_input", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_check_input", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_check_input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_check_input", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples); + __pyx_r = __pyx_pf_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "sklearn/utils/random.pyx":29 +/* "sklearn/utils/_random.pyx":28 * * * cpdef _sample_without_replacement_check_input(np.int_t n_population, # <<<<<<<<<<<<<< @@ -1520,7 +1520,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_c * """ Check that input are consistent for sample_without_replacement""" */ -static PyObject *__pyx_pf_7sklearn_5utils_6random__sample_without_replacement_check_input(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples) { +static PyObject *__pyx_pf_7sklearn_5utils_7_random__sample_without_replacement_check_input(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -1529,7 +1529,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random__sample_without_replacement_ch int __pyx_clineno = 0; __Pyx_RefNannySetupContext("_sample_without_replacement_check_input", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1539,7 +1539,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random__sample_without_replacement_ch goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_check_input", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_check_input", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -1547,7 +1547,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random__sample_without_replacement_ch return __pyx_r; } -/* "sklearn/utils/random.pyx":42 +/* "sklearn/utils/_random.pyx":41 * * * cpdef _sample_without_replacement_with_tracking_selection( # <<<<<<<<<<<<<< @@ -1555,10 +1555,10 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random__sample_without_replacement_ch * np.int_t n_samples, */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_with_tracking_selection(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection *__pyx_optional_args) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_3_sample_without_replacement_with_tracking_selection(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection *__pyx_optional_args) { - /* "sklearn/utils/random.pyx":45 + /* "sklearn/utils/_random.pyx":44 * np.int_t n_population, * np.int_t n_samples, * random_state=None): # <<<<<<<<<<<<<< @@ -1602,70 +1602,70 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_pybuffernd_out.data = NULL; __pyx_pybuffernd_out.rcbuffer = &__pyx_pybuffer_out; - /* "sklearn/utils/random.pyx":84 + /* "sklearn/utils/_random.pyx":83 * The sampled subsets of integer. * """ * _sample_without_replacement_check_input(n_population, n_samples) # <<<<<<<<<<<<<< * * cdef np.int_t i */ - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":88 + /* "sklearn/utils/_random.pyx":87 * cdef np.int_t i * cdef np.int_t j * cdef np.ndarray[np.int_t, ndim=1] out = np.empty((n_samples, ), # <<<<<<<<<<<<<< * dtype=np.int) * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - /* "sklearn/utils/random.pyx":89 + /* "sklearn/utils/_random.pyx":88 * cdef np.int_t j * cdef np.ndarray[np.int_t, ndim=1] out = np.empty((n_samples, ), * dtype=np.int) # <<<<<<<<<<<<<< * * rng = check_random_state(random_state) */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__int); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__int); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_out.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_out.diminfo[0].strides = __pyx_pybuffernd_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_out.diminfo[0].shape = __pyx_pybuffernd_out.rcbuffer->pybuffer.shape[0]; } } @@ -1673,52 +1673,52 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0; - /* "sklearn/utils/random.pyx":91 + /* "sklearn/utils/_random.pyx":90 * dtype=np.int) * * rng = check_random_state(random_state) # <<<<<<<<<<<<<< * rng_randint = rng.randint * */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__check_random_state); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__check_random_state); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_random_state); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_random_state); __Pyx_GIVEREF(__pyx_v_random_state); - __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_rng = __pyx_t_1; __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":92 + /* "sklearn/utils/_random.pyx":91 * * rng = check_random_state(random_state) * rng_randint = rng.randint # <<<<<<<<<<<<<< * * # The following line of code are heavily inspired from python core, */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s__randint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s__randint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_rng_randint = __pyx_t_1; __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":96 + /* "sklearn/utils/_random.pyx":95 * # The following line of code are heavily inspired from python core, * # more precisely of random.sample. * cdef set selected = set() # <<<<<<<<<<<<<< * * for i in range(n_samples): */ - __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_v_selected = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":98 + /* "sklearn/utils/_random.pyx":97 * cdef set selected = set() * * for i in range(n_samples): # <<<<<<<<<<<<<< @@ -1729,28 +1729,28 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_i = __pyx_t_8; - /* "sklearn/utils/random.pyx":99 + /* "sklearn/utils/_random.pyx":98 * * for i in range(n_samples): * j = rng_randint(n_population) # <<<<<<<<<<<<<< * while j in selected: * j = rng_randint(n_population) */ - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_9 = __Pyx_PyInt_from_py_npy_long(__pyx_t_1); if (unlikely((__pyx_t_9 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = __Pyx_PyInt_from_py_npy_long(__pyx_t_1); if (unlikely((__pyx_t_9 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_j = __pyx_t_9; - /* "sklearn/utils/random.pyx":100 + /* "sklearn/utils/_random.pyx":99 * for i in range(n_samples): * j = rng_randint(n_population) * while j in selected: # <<<<<<<<<<<<<< @@ -1758,48 +1758,48 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit * selected.add(j) */ while (1) { - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_j); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_j); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = (__Pyx_PySequence_Contains(__pyx_t_1, ((PyObject *)__pyx_v_selected), Py_EQ)); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_10 = (__Pyx_PySequence_Contains(__pyx_t_1, ((PyObject *)__pyx_v_selected), Py_EQ)); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = (__pyx_t_10 != 0); if (!__pyx_t_11) break; - /* "sklearn/utils/random.pyx":101 + /* "sklearn/utils/_random.pyx":100 * j = rng_randint(n_population) * while j in selected: * j = rng_randint(n_population) # <<<<<<<<<<<<<< * selected.add(j) * out[i] = j */ - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_9 = __Pyx_PyInt_from_py_npy_long(__pyx_t_1); if (unlikely((__pyx_t_9 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = __Pyx_PyInt_from_py_npy_long(__pyx_t_1); if (unlikely((__pyx_t_9 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_j = __pyx_t_9; } - /* "sklearn/utils/random.pyx":102 + /* "sklearn/utils/_random.pyx":101 * while j in selected: * j = rng_randint(n_population) * selected.add(j) # <<<<<<<<<<<<<< * out[i] = j * */ - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_j); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_j); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PySet_Add(__pyx_v_selected, __pyx_t_1); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_12 = PySet_Add(__pyx_v_selected, __pyx_t_1); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":103 + /* "sklearn/utils/_random.pyx":102 * j = rng_randint(n_population) * selected.add(j) * out[i] = j # <<<<<<<<<<<<<< @@ -1810,7 +1810,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_out.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_out.diminfo[0].strides) = __pyx_v_j; } - /* "sklearn/utils/random.pyx":105 + /* "sklearn/utils/_random.pyx":104 * out[i] = j * * return out # <<<<<<<<<<<<<< @@ -1834,7 +1834,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_out.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_tracking_selection", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_tracking_selection", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; @@ -1850,9 +1850,9 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_with_tracking_selection(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_5utils_6random_2_sample_without_replacement_with_tracking_selection[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n Time complexity:\n - Worst-case: unbounded\n - Average-case:\n O(O(np.random.randint) * \\sum_{i=1}^n_samples 1 /\n (1 - i / n_population)))\n <= O(O(np.random.randint) *\n n_population * ln((n_population - 2)\n /(n_population - 1 - n_samples)))\n <= O(O(np.random.randint) *\n n_population * 1 / (1 - n_samples / n_population))\n\n Space complexity of O(n_samples) in a python set.\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer.\n "; -static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_with_tracking_selection(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_3_sample_without_replacement_with_tracking_selection(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_5utils_7_random_2_sample_without_replacement_with_tracking_selection[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n Time complexity:\n - Worst-case: unbounded\n - Average-case:\n O(O(np.random.randint) * \\sum_{i=1}^n_samples 1 /\n (1 - i / n_population)))\n <= O(O(np.random.randint) *\n n_population * ln((n_population - 2)\n /(n_population - 1 - n_samples)))\n <= O(O(np.random.randint) *\n n_population * 1 / (1 - n_samples / n_population))\n\n Space complexity of O(n_samples) in a python set.\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer.\n "; +static PyObject *__pyx_pw_7sklearn_5utils_7_random_3_sample_without_replacement_with_tracking_selection(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_5numpy_int_t __pyx_v_n_population; __pyx_t_5numpy_int_t __pyx_v_n_samples; PyObject *__pyx_v_random_state = 0; @@ -1866,7 +1866,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_w static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__n_population,&__pyx_n_s__n_samples,&__pyx_n_s__random_state,0}; PyObject* values[3] = {0,0,0}; - /* "sklearn/utils/random.pyx":45 + /* "sklearn/utils/_random.pyx":44 * np.int_t n_population, * np.int_t n_samples, * random_state=None): # <<<<<<<<<<<<<< @@ -1892,7 +1892,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_w case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_samples)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_tracking_selection", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_tracking_selection", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { @@ -1901,7 +1901,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_w } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_with_tracking_selection") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_with_tracking_selection") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1912,24 +1912,24 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_w default: goto __pyx_L5_argtuple_error; } } - __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_random_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_tracking_selection", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_tracking_selection", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_tracking_selection", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_tracking_selection", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_with_tracking_selection(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_random_state); + __pyx_r = __pyx_pf_7sklearn_5utils_7_random_2_sample_without_replacement_with_tracking_selection(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_random_state); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "sklearn/utils/random.pyx":42 +/* "sklearn/utils/_random.pyx":41 * * * cpdef _sample_without_replacement_with_tracking_selection( # <<<<<<<<<<<<<< @@ -1937,11 +1937,11 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_w * np.int_t n_samples, */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_with_tracking_selection(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state) { +static PyObject *__pyx_pf_7sklearn_5utils_7_random_2_sample_without_replacement_with_tracking_selection(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection __pyx_t_2; + struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -1949,7 +1949,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_w __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -1959,7 +1959,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_w goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_tracking_selection", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_tracking_selection", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -1967,7 +1967,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_w return __pyx_r; } -/* "sklearn/utils/random.pyx":108 +/* "sklearn/utils/_random.pyx":107 * * * cpdef _sample_without_replacement_with_pool(np.int_t n_population, # <<<<<<<<<<<<<< @@ -1975,10 +1975,10 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_2_sample_without_replacement_w * random_state=None): */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_with_pool(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_pool(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_pool *__pyx_optional_args) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_5_sample_without_replacement_with_pool(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_pool(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_pool *__pyx_optional_args) { - /* "sklearn/utils/random.pyx":110 + /* "sklearn/utils/_random.pyx":109 * cpdef _sample_without_replacement_with_pool(np.int_t n_population, * np.int_t n_samples, * random_state=None): # <<<<<<<<<<<<<< @@ -2030,70 +2030,70 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_pybuffernd_pool.data = NULL; __pyx_pybuffernd_pool.rcbuffer = &__pyx_pybuffer_pool; - /* "sklearn/utils/random.pyx":140 + /* "sklearn/utils/_random.pyx":139 * The sampled subsets of integer. * """ * _sample_without_replacement_check_input(n_population, n_samples) # <<<<<<<<<<<<<< * * cdef np.int_t i */ - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":144 + /* "sklearn/utils/_random.pyx":143 * cdef np.int_t i * cdef np.int_t j * cdef np.ndarray[np.int_t, ndim=1] out = np.empty((n_samples, ), # <<<<<<<<<<<<<< * dtype=np.int) * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - /* "sklearn/utils/random.pyx":145 + /* "sklearn/utils/_random.pyx":144 * cdef np.int_t j * cdef np.ndarray[np.int_t, ndim=1] out = np.empty((n_samples, ), * dtype=np.int) # <<<<<<<<<<<<<< * * cdef np.ndarray[np.int_t, ndim=1] pool = np.empty((n_population, ), */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__int); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__int); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_out.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 143; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_out.diminfo[0].strides = __pyx_pybuffernd_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_out.diminfo[0].shape = __pyx_pybuffernd_out.rcbuffer->pybuffer.shape[0]; } } @@ -2101,59 +2101,59 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0; - /* "sklearn/utils/random.pyx":147 + /* "sklearn/utils/_random.pyx":146 * dtype=np.int) * * cdef np.ndarray[np.int_t, ndim=1] pool = np.empty((n_population, ), # <<<<<<<<<<<<<< * dtype=np.int) * */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s__empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_population); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - /* "sklearn/utils/random.pyx":148 + /* "sklearn/utils/_random.pyx":147 * * cdef np.ndarray[np.int_t, ndim=1] pool = np.empty((n_population, ), * dtype=np.int) # <<<<<<<<<<<<<< * * rng = check_random_state(random_state) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__int); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s__int); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_5), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_7 = ((PyArrayObject *)__pyx_t_4); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_pool.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_pool = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_pool.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 147; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 146; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_pool.diminfo[0].strides = __pyx_pybuffernd_pool.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_pool.diminfo[0].shape = __pyx_pybuffernd_pool.rcbuffer->pybuffer.shape[0]; } } @@ -2161,40 +2161,40 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_v_pool = ((PyArrayObject *)__pyx_t_4); __pyx_t_4 = 0; - /* "sklearn/utils/random.pyx":150 + /* "sklearn/utils/_random.pyx":149 * dtype=np.int) * * rng = check_random_state(random_state) # <<<<<<<<<<<<<< * rng_randint = rng.randint * */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__check_random_state); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__check_random_state); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_random_state); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_random_state); __Pyx_GIVEREF(__pyx_v_random_state); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_v_rng = __pyx_t_5; __pyx_t_5 = 0; - /* "sklearn/utils/random.pyx":151 + /* "sklearn/utils/_random.pyx":150 * * rng = check_random_state(random_state) * rng_randint = rng.randint # <<<<<<<<<<<<<< * * # Initialize the pool */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s__randint); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s__randint); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_v_rng_randint = __pyx_t_5; __pyx_t_5 = 0; - /* "sklearn/utils/random.pyx":154 + /* "sklearn/utils/_random.pyx":153 * * # Initialize the pool * for i in xrange(n_population): # <<<<<<<<<<<<<< @@ -2205,7 +2205,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_i = __pyx_t_9; - /* "sklearn/utils/random.pyx":155 + /* "sklearn/utils/_random.pyx":154 * # Initialize the pool * for i in xrange(n_population): * pool[i] = i # <<<<<<<<<<<<<< @@ -2216,7 +2216,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_pool.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_pool.diminfo[0].strides) = __pyx_v_i; } - /* "sklearn/utils/random.pyx":159 + /* "sklearn/utils/_random.pyx":158 * # The following line of code are heavily inspired from python core, * # more precisely of random.sample. * for i in xrange(n_samples): # <<<<<<<<<<<<<< @@ -2227,28 +2227,28 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_i = __pyx_t_9; - /* "sklearn/utils/random.pyx":160 + /* "sklearn/utils/_random.pyx":159 * # more precisely of random.sample. * for i in xrange(n_samples): * j = rng_randint(n_population - i) # invariant: non-selected at [0,n-i) # <<<<<<<<<<<<<< * out[i] = pool[j] * pool[j] = pool[n_population - i - 1] # move non-selected item into */ - __pyx_t_5 = __Pyx_PyInt_to_py_npy_long((__pyx_v_n_population - __pyx_v_i)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyInt_to_py_npy_long((__pyx_v_n_population - __pyx_v_i)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_11 = __Pyx_PyInt_from_py_npy_long(__pyx_t_5); if (unlikely((__pyx_t_11 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_11 = __Pyx_PyInt_from_py_npy_long(__pyx_t_5); if (unlikely((__pyx_t_11 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_j = __pyx_t_11; - /* "sklearn/utils/random.pyx":161 + /* "sklearn/utils/_random.pyx":160 * for i in xrange(n_samples): * j = rng_randint(n_population - i) # invariant: non-selected at [0,n-i) * out[i] = pool[j] # <<<<<<<<<<<<<< @@ -2259,7 +2259,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_t_12 = __pyx_v_i; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_out.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_out.diminfo[0].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_pool.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_pool.diminfo[0].strides)); - /* "sklearn/utils/random.pyx":162 + /* "sklearn/utils/_random.pyx":161 * j = rng_randint(n_population - i) # invariant: non-selected at [0,n-i) * out[i] = pool[j] * pool[j] = pool[n_population - i - 1] # move non-selected item into # <<<<<<<<<<<<<< @@ -2271,7 +2271,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_pool.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_pool.diminfo[0].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_pool.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_pool.diminfo[0].strides)); } - /* "sklearn/utils/random.pyx":165 + /* "sklearn/utils/_random.pyx":164 * # vacancy * * return out # <<<<<<<<<<<<<< @@ -2296,7 +2296,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_out.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_pool.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_pool", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_pool", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; @@ -2313,9 +2313,9 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_with_pool(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_5utils_6random_4_sample_without_replacement_with_pool[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n Time complexity: O(n_population + O(np.random.randint) * n_samples)\n\n Space complexity of O(n_population + n_samples).\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer.\n "; -static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_with_pool(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_5_sample_without_replacement_with_pool(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_5utils_7_random_4_sample_without_replacement_with_pool[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n Time complexity: O(n_population + O(np.random.randint) * n_samples)\n\n Space complexity of O(n_population + n_samples).\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer.\n "; +static PyObject *__pyx_pw_7sklearn_5utils_7_random_5_sample_without_replacement_with_pool(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_5numpy_int_t __pyx_v_n_population; __pyx_t_5numpy_int_t __pyx_v_n_samples; PyObject *__pyx_v_random_state = 0; @@ -2329,7 +2329,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_w static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__n_population,&__pyx_n_s__n_samples,&__pyx_n_s__random_state,0}; PyObject* values[3] = {0,0,0}; - /* "sklearn/utils/random.pyx":110 + /* "sklearn/utils/_random.pyx":109 * cpdef _sample_without_replacement_with_pool(np.int_t n_population, * np.int_t n_samples, * random_state=None): # <<<<<<<<<<<<<< @@ -2355,7 +2355,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_w case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_samples)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_pool", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_pool", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { @@ -2364,7 +2364,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_w } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_with_pool") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_with_pool") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2375,24 +2375,24 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_w default: goto __pyx_L5_argtuple_error; } } - __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_random_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_pool", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_pool", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_pool", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_pool", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_with_pool(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_random_state); + __pyx_r = __pyx_pf_7sklearn_5utils_7_random_4_sample_without_replacement_with_pool(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_random_state); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "sklearn/utils/random.pyx":108 +/* "sklearn/utils/_random.pyx":107 * * * cpdef _sample_without_replacement_with_pool(np.int_t n_population, # <<<<<<<<<<<<<< @@ -2400,11 +2400,11 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_w * random_state=None): */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_with_pool(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state) { +static PyObject *__pyx_pf_7sklearn_5utils_7_random_4_sample_without_replacement_with_pool(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_pool __pyx_t_2; + struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_pool __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -2412,7 +2412,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_w __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_pool(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_pool(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2422,7 +2422,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_w goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_pool", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_pool", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -2430,7 +2430,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_w return __pyx_r; } -/* "sklearn/utils/random.pyx":168 +/* "sklearn/utils/_random.pyx":167 * * * cpdef _sample_without_replacement_with_reservoir_sampling( # <<<<<<<<<<<<<< @@ -2438,10 +2438,10 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_4_sample_without_replacement_w * np.int_t n_samples, */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_with_reservoir_sampling(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling *__pyx_optional_args) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_7_sample_without_replacement_with_reservoir_sampling(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling *__pyx_optional_args) { - /* "sklearn/utils/random.pyx":171 + /* "sklearn/utils/_random.pyx":170 * np.int_t n_population, * np.int_t n_samples, * random_state=None): # <<<<<<<<<<<<<< @@ -2482,70 +2482,70 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_pybuffernd_out.data = NULL; __pyx_pybuffernd_out.rcbuffer = &__pyx_pybuffer_out; - /* "sklearn/utils/random.pyx":203 + /* "sklearn/utils/_random.pyx":202 * of the items has to be randomized. * """ * _sample_without_replacement_check_input(n_population, n_samples) # <<<<<<<<<<<<<< * * cdef np.int_t i */ - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 202; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":207 + /* "sklearn/utils/_random.pyx":206 * cdef np.int_t i * cdef np.int_t j * cdef np.ndarray[np.int_t, ndim=1] out = np.empty((n_samples, ), # <<<<<<<<<<<<<< * dtype=np.int) * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s__empty); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_to_py_npy_long(__pyx_v_n_samples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - /* "sklearn/utils/random.pyx":208 + /* "sklearn/utils/_random.pyx":207 * cdef np.int_t j * cdef np.ndarray[np.int_t, ndim=1] out = np.empty((n_samples, ), * dtype=np.int) # <<<<<<<<<<<<<< * * rng = check_random_state(random_state) */ - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__int); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s__int); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dtype), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_out.rcbuffer->pybuffer.buf = NULL; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_pybuffernd_out.diminfo[0].strides = __pyx_pybuffernd_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_out.diminfo[0].shape = __pyx_pybuffernd_out.rcbuffer->pybuffer.shape[0]; } } @@ -2553,40 +2553,40 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_v_out = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0; - /* "sklearn/utils/random.pyx":210 + /* "sklearn/utils/_random.pyx":209 * dtype=np.int) * * rng = check_random_state(random_state) # <<<<<<<<<<<<<< * rng_randint = rng.randint * */ - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__check_random_state); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s__check_random_state); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_random_state); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_random_state); __Pyx_GIVEREF(__pyx_v_random_state); - __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 209; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_v_rng = __pyx_t_1; __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":211 + /* "sklearn/utils/_random.pyx":210 * * rng = check_random_state(random_state) * rng_randint = rng.randint # <<<<<<<<<<<<<< * * # This cython implementation is based on the one of Robert Kern: */ - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s__randint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rng, __pyx_n_s__randint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_rng_randint = __pyx_t_1; __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":217 + /* "sklearn/utils/_random.pyx":216 * # 054289.html * # * for i in range(n_samples): # <<<<<<<<<<<<<< @@ -2597,7 +2597,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_i = __pyx_t_8; - /* "sklearn/utils/random.pyx":218 + /* "sklearn/utils/_random.pyx":217 * # * for i in range(n_samples): * out[i] = i # <<<<<<<<<<<<<< @@ -2608,7 +2608,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int_t *, __pyx_pybuffernd_out.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_out.diminfo[0].strides) = __pyx_v_i; } - /* "sklearn/utils/random.pyx":220 + /* "sklearn/utils/_random.pyx":219 * out[i] = i * * for i from n_samples <= i < n_population: # <<<<<<<<<<<<<< @@ -2618,16 +2618,16 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_t_7 = __pyx_v_n_population; for (__pyx_v_i = __pyx_v_n_samples; __pyx_v_i < __pyx_t_7; __pyx_v_i++) { - /* "sklearn/utils/random.pyx":221 + /* "sklearn/utils/_random.pyx":220 * * for i from n_samples <= i < n_population: * j = rng_randint(0, i + 1) # <<<<<<<<<<<<<< * if j < n_samples: * out[j] = i */ - __pyx_t_1 = PyInt_FromLong((__pyx_v_i + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyInt_FromLong((__pyx_v_i + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_0); @@ -2635,14 +2635,14 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_v_rng_randint, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_8 = __Pyx_PyInt_from_py_npy_long(__pyx_t_1); if (unlikely((__pyx_t_8 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 221; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = __Pyx_PyInt_from_py_npy_long(__pyx_t_1); if (unlikely((__pyx_t_8 == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_j = __pyx_t_8; - /* "sklearn/utils/random.pyx":222 + /* "sklearn/utils/_random.pyx":221 * for i from n_samples <= i < n_population: * j = rng_randint(0, i + 1) * if j < n_samples: # <<<<<<<<<<<<<< @@ -2652,7 +2652,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_t_10 = ((__pyx_v_j < __pyx_v_n_samples) != 0); if (__pyx_t_10) { - /* "sklearn/utils/random.pyx":223 + /* "sklearn/utils/_random.pyx":222 * j = rng_randint(0, i + 1) * if j < n_samples: * out[j] = i # <<<<<<<<<<<<<< @@ -2666,7 +2666,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __pyx_L7:; } - /* "sklearn/utils/random.pyx":225 + /* "sklearn/utils/_random.pyx":224 * out[j] = i * * return out # <<<<<<<<<<<<<< @@ -2690,7 +2690,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_out.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_reservoir_sampling", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_reservoir_sampling", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; @@ -2705,9 +2705,9 @@ static PyObject *__pyx_f_7sklearn_5utils_6random__sample_without_replacement_wit } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_with_reservoir_sampling(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_5utils_6random_6_sample_without_replacement_with_reservoir_sampling[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n Time complexity of\n O((n_population - n_samples) * O(np.random.randint) + n_samples)\n Space complexity of O(n_samples)\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer. The order of the items is not\n necessarily random. Use a random permutation of the array if the order\n of the items has to be randomized.\n "; -static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_with_reservoir_sampling(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_7_sample_without_replacement_with_reservoir_sampling(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_5utils_7_random_6_sample_without_replacement_with_reservoir_sampling[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n Time complexity of\n O((n_population - n_samples) * O(np.random.randint) + n_samples)\n Space complexity of O(n_samples)\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer. The order of the items is not\n necessarily random. Use a random permutation of the array if the order\n of the items has to be randomized.\n "; +static PyObject *__pyx_pw_7sklearn_5utils_7_random_7_sample_without_replacement_with_reservoir_sampling(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_5numpy_int_t __pyx_v_n_population; __pyx_t_5numpy_int_t __pyx_v_n_samples; PyObject *__pyx_v_random_state = 0; @@ -2721,7 +2721,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_w static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__n_population,&__pyx_n_s__n_samples,&__pyx_n_s__random_state,0}; PyObject* values[3] = {0,0,0}; - /* "sklearn/utils/random.pyx":171 + /* "sklearn/utils/_random.pyx":170 * np.int_t n_population, * np.int_t n_samples, * random_state=None): # <<<<<<<<<<<<<< @@ -2747,7 +2747,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_w case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_samples)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_reservoir_sampling", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_reservoir_sampling", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { @@ -2756,7 +2756,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_w } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_with_reservoir_sampling") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_sample_without_replacement_with_reservoir_sampling") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -2767,24 +2767,24 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_w default: goto __pyx_L5_argtuple_error; } } - __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_random_state = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_reservoir_sampling", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("_sample_without_replacement_with_reservoir_sampling", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_reservoir_sampling", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_reservoir_sampling", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_with_reservoir_sampling(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_random_state); + __pyx_r = __pyx_pf_7sklearn_5utils_7_random_6_sample_without_replacement_with_reservoir_sampling(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_random_state); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "sklearn/utils/random.pyx":168 +/* "sklearn/utils/_random.pyx":167 * * * cpdef _sample_without_replacement_with_reservoir_sampling( # <<<<<<<<<<<<<< @@ -2792,11 +2792,11 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_w * np.int_t n_samples, */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_with_reservoir_sampling(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state) { +static PyObject *__pyx_pf_7sklearn_5utils_7_random_6_sample_without_replacement_with_reservoir_sampling(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_random_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling __pyx_t_2; + struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -2804,7 +2804,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_w __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 1; __pyx_t_2.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2814,7 +2814,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_w goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("sklearn.utils.random._sample_without_replacement_with_reservoir_sampling", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random._sample_without_replacement_with_reservoir_sampling", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -2822,7 +2822,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_w return __pyx_r; } -/* "sklearn/utils/random.pyx":228 +/* "sklearn/utils/_random.pyx":227 * * * cpdef sample_without_replacement(np.int_t n_population, # <<<<<<<<<<<<<< @@ -2830,11 +2830,11 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_6_sample_without_replacement_w * method="auto", */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random_sample_without_replacement *__pyx_optional_args) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_9sample_without_replacement(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_7sklearn_5utils_7_random_sample_without_replacement(__pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random_sample_without_replacement *__pyx_optional_args) { PyObject *__pyx_v_method = ((PyObject *)__pyx_n_s__auto); - /* "sklearn/utils/random.pyx":231 + /* "sklearn/utils/_random.pyx":230 * np.int_t n_samples, * method="auto", * random_state=None): # <<<<<<<<<<<<<< @@ -2851,9 +2851,9 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py int __pyx_t_3; int __pyx_t_4; double __pyx_t_5; - struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection __pyx_t_6; - struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling __pyx_t_7; - struct __pyx_opt_args_7sklearn_5utils_6random__sample_without_replacement_with_pool __pyx_t_8; + struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection __pyx_t_6; + struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling __pyx_t_7; + struct __pyx_opt_args_7sklearn_5utils_7_random__sample_without_replacement_with_pool __pyx_t_8; PyObject *__pyx_t_9 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; @@ -2868,18 +2868,18 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py } } - /* "sklearn/utils/random.pyx":275 + /* "sklearn/utils/_random.pyx":274 * not be randomized, see the method argument. * """ * _sample_without_replacement_check_input(n_population, n_samples) # <<<<<<<<<<<<<< * * all_methods = ("auto", "tracking_selection", "reservoir_sampling", "pool") */ - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_check_input(__pyx_v_n_population, __pyx_v_n_samples, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 274; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":277 + /* "sklearn/utils/_random.pyx":276 * _sample_without_replacement_check_input(n_population, n_samples) * * all_methods = ("auto", "tracking_selection", "reservoir_sampling", "pool") # <<<<<<<<<<<<<< @@ -2889,19 +2889,19 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py __Pyx_INCREF(((PyObject *)__pyx_k_tuple_3)); __pyx_v_all_methods = __pyx_k_tuple_3; - /* "sklearn/utils/random.pyx":279 + /* "sklearn/utils/_random.pyx":278 * all_methods = ("auto", "tracking_selection", "reservoir_sampling", "pool") * * if method == "auto" or method == "tracking_selection": # <<<<<<<<<<<<<< * # TODO the pool based method can also be used. * # however, it requires special benchmark to take into account */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__auto), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__auto), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (!__pyx_t_2) { - __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__tracking_selection), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 279; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__tracking_selection), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __pyx_t_3; } else { @@ -2909,7 +2909,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py } if (__pyx_t_4) { - /* "sklearn/utils/random.pyx":283 + /* "sklearn/utils/_random.pyx":282 * # however, it requires special benchmark to take into account * # the memory requirement of the array vs the set. * ratio = n_samples / n_population if n_population != 0.0 else 1.0 # <<<<<<<<<<<<<< @@ -2923,7 +2923,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py } __pyx_v_ratio = __pyx_t_5; - /* "sklearn/utils/random.pyx":286 + /* "sklearn/utils/_random.pyx":285 * * # The value 0.2 has been determined through benchmarking. * if ratio < 0.2: # <<<<<<<<<<<<<< @@ -2933,7 +2933,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py __pyx_t_4 = ((__pyx_v_ratio < 0.2) != 0); if (__pyx_t_4) { - /* "sklearn/utils/random.pyx":287 + /* "sklearn/utils/_random.pyx":286 * # The value 0.2 has been determined through benchmarking. * if ratio < 0.2: * return _sample_without_replacement_with_tracking_selection( # <<<<<<<<<<<<<< @@ -2942,7 +2942,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __Pyx_XDECREF(__pyx_r); - /* "sklearn/utils/random.pyx":288 + /* "sklearn/utils/_random.pyx":287 * if ratio < 0.2: * return _sample_without_replacement_with_tracking_selection( * n_population, n_samples, random_state) # <<<<<<<<<<<<<< @@ -2951,7 +2951,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __pyx_t_6.__pyx_n = 1; __pyx_t_6.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_tracking_selection(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_tracking_selection(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2960,7 +2960,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py } /*else*/ { - /* "sklearn/utils/random.pyx":290 + /* "sklearn/utils/_random.pyx":289 * n_population, n_samples, random_state) * else: * return _sample_without_replacement_with_reservoir_sampling( # <<<<<<<<<<<<<< @@ -2969,7 +2969,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __Pyx_XDECREF(__pyx_r); - /* "sklearn/utils/random.pyx":291 + /* "sklearn/utils/_random.pyx":290 * else: * return _sample_without_replacement_with_reservoir_sampling( * n_population, n_samples, random_state) # <<<<<<<<<<<<<< @@ -2978,7 +2978,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __pyx_t_7.__pyx_n = 1; __pyx_t_7.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 289; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2988,19 +2988,19 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py goto __pyx_L3; } - /* "sklearn/utils/random.pyx":293 + /* "sklearn/utils/_random.pyx":292 * n_population, n_samples, random_state) * * elif method == "reservoir_sampling": # <<<<<<<<<<<<<< * return _sample_without_replacement_with_reservoir_sampling( * n_population, n_samples, random_state) */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__reservoir_sampling), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__reservoir_sampling), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_4) { - /* "sklearn/utils/random.pyx":294 + /* "sklearn/utils/_random.pyx":293 * * elif method == "reservoir_sampling": * return _sample_without_replacement_with_reservoir_sampling( # <<<<<<<<<<<<<< @@ -3009,7 +3009,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __Pyx_XDECREF(__pyx_r); - /* "sklearn/utils/random.pyx":295 + /* "sklearn/utils/_random.pyx":294 * elif method == "reservoir_sampling": * return _sample_without_replacement_with_reservoir_sampling( * n_population, n_samples, random_state) # <<<<<<<<<<<<<< @@ -3018,7 +3018,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __pyx_t_7.__pyx_n = 1; __pyx_t_7.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_reservoir_sampling(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 294; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_reservoir_sampling(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 293; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3026,19 +3026,19 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py goto __pyx_L3; } - /* "sklearn/utils/random.pyx":297 + /* "sklearn/utils/_random.pyx":296 * n_population, n_samples, random_state) * * elif method == "pool": # <<<<<<<<<<<<<< * return _sample_without_replacement_with_pool(n_population, n_samples, * random_state) */ - __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__pool), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, ((PyObject *)__pyx_n_s__pool), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_4) { - /* "sklearn/utils/random.pyx":298 + /* "sklearn/utils/_random.pyx":297 * * elif method == "pool": * return _sample_without_replacement_with_pool(n_population, n_samples, # <<<<<<<<<<<<<< @@ -3047,7 +3047,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __Pyx_XDECREF(__pyx_r); - /* "sklearn/utils/random.pyx":299 + /* "sklearn/utils/_random.pyx":298 * elif method == "pool": * return _sample_without_replacement_with_pool(n_population, n_samples, * random_state) # <<<<<<<<<<<<<< @@ -3056,7 +3056,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py */ __pyx_t_8.__pyx_n = 1; __pyx_t_8.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random__sample_without_replacement_with_pool(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random__sample_without_replacement_with_pool(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3065,12 +3065,12 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py } /*else*/ { - /* "sklearn/utils/random.pyx":302 + /* "sklearn/utils/_random.pyx":301 * else: * raise ValueError('Expected a method name in %s, got %s. ' * % (all_methods, method)) # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_all_methods)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_all_methods)); @@ -3078,20 +3078,20 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py __Pyx_INCREF(__pyx_v_method); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_method); __Pyx_GIVEREF(__pyx_v_method); - __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_4), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 302; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_4), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_9)); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_9)); __Pyx_GIVEREF(((PyObject *)__pyx_t_9)); __pyx_t_9 = 0; - __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_9 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_9, 0, 0, 0); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 301; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -3100,7 +3100,7 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_9); - __Pyx_AddTraceback("sklearn.utils.random.sample_without_replacement", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random.sample_without_replacement", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_all_methods); @@ -3110,9 +3110,9 @@ static PyObject *__pyx_f_7sklearn_5utils_6random_sample_without_replacement(__py } /* Python wrapper */ -static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static char __pyx_doc_7sklearn_5utils_6random_8sample_without_replacement[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n method : \"auto\", \"tracking_selection\" or \"reservoir_sampling\"\n If method == \"auto\", an algorithm is automatically selected.\n The subset of selected integer is not randomized.\n\n If method ==\"tracking_selection\", a set based implementation is used\n which is suitable for `n_samples` <<< `n_population`.\n\n If method == \"reservoir_sampling\", a reservoir sampling algorithm is\n used which is suitable for high memory constraint or when\n O(`n_samples`) ~ O(`n_population`).\n The subset of selected integer is not randomized.\n\n If method == \"pool\", a pool based algorithm is particularly fast, even\n faster than the tracking selection method. Hovewer, a vector containing\n the entire population has to be initialized.\n If n_samples ~ n_population, the reservoir sampling method is faster.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer. The subset of selected integer might\n not be randomized, see the method argument.\n "; -static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_7sklearn_5utils_7_random_9sample_without_replacement(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_7sklearn_5utils_7_random_8sample_without_replacement[] = "Sample integers without replacement.\n\n Select n_samples integers from the set [0, n_population) without\n replacement.\n\n\n Parameters\n ----------\n n_population : int,\n The size of the set to sample from.\n\n n_samples : int,\n The number of integer to sample.\n\n random_state : int, RandomState instance or None, optional (default=None)\n If int, random_state is the seed used by the random number generator;\n If RandomState instance, random_state is the random number generator;\n If None, the random number generator is the RandomState instance used\n by `np.random`.\n\n method : \"auto\", \"tracking_selection\" or \"reservoir_sampling\"\n If method == \"auto\", an algorithm is automatically selected.\n The subset of selected integer is not randomized.\n\n If method ==\"tracking_selection\", a set based implementation is used\n which is suitable for `n_samples` <<< `n_population`.\n\n If method == \"reservoir_sampling\", a reservoir sampling algorithm is\n used which is suitable for high memory constraint or when\n O(`n_samples`) ~ O(`n_population`).\n The subset of selected integer is not randomized.\n\n If method == \"pool\", a pool based algorithm is particularly fast, even\n faster than the tracking selection method. Hovewer, a vector containing\n the entire population has to be initialized.\n If n_samples ~ n_population, the reservoir sampling method is faster.\n\n Returns\n -------\n out : array of size (n_samples, )\n The sampled subsets of integer. The subset of selected integer might\n not be randomized, see the method argument.\n "; +static PyObject *__pyx_pw_7sklearn_5utils_7_random_9sample_without_replacement(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __pyx_t_5numpy_int_t __pyx_v_n_population; __pyx_t_5numpy_int_t __pyx_v_n_samples; PyObject *__pyx_v_method = 0; @@ -3128,7 +3128,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(Py PyObject* values[4] = {0,0,0,0}; values[2] = ((PyObject *)__pyx_n_s__auto); - /* "sklearn/utils/random.pyx":231 + /* "sklearn/utils/_random.pyx":230 * np.int_t n_samples, * method="auto", * random_state=None): # <<<<<<<<<<<<<< @@ -3155,7 +3155,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(Py case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__n_samples)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("sample_without_replacement", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sample_without_replacement", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { @@ -3169,7 +3169,7 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sample_without_replacement") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sample_without_replacement") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3181,25 +3181,25 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(Py default: goto __pyx_L5_argtuple_error; } } - __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_population = __Pyx_PyInt_from_py_npy_long(values[0]); if (unlikely((__pyx_v_n_population == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n_samples = __Pyx_PyInt_from_py_npy_long(values[1]); if (unlikely((__pyx_v_n_samples == (npy_long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_v_method = values[2]; __pyx_v_random_state = values[3]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("sample_without_replacement", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("sample_without_replacement", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("sklearn.utils.random.sample_without_replacement", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random.sample_without_replacement", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7sklearn_5utils_6random_8sample_without_replacement(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_method, __pyx_v_random_state); + __pyx_r = __pyx_pf_7sklearn_5utils_7_random_8sample_without_replacement(__pyx_self, __pyx_v_n_population, __pyx_v_n_samples, __pyx_v_method, __pyx_v_random_state); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "sklearn/utils/random.pyx":228 +/* "sklearn/utils/_random.pyx":227 * * * cpdef sample_without_replacement(np.int_t n_population, # <<<<<<<<<<<<<< @@ -3207,11 +3207,11 @@ static PyObject *__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement(Py * method="auto", */ -static PyObject *__pyx_pf_7sklearn_5utils_6random_8sample_without_replacement(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_method, PyObject *__pyx_v_random_state) { +static PyObject *__pyx_pf_7sklearn_5utils_7_random_8sample_without_replacement(CYTHON_UNUSED PyObject *__pyx_self, __pyx_t_5numpy_int_t __pyx_v_n_population, __pyx_t_5numpy_int_t __pyx_v_n_samples, PyObject *__pyx_v_method, PyObject *__pyx_v_random_state) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - struct __pyx_opt_args_7sklearn_5utils_6random_sample_without_replacement __pyx_t_2; + struct __pyx_opt_args_7sklearn_5utils_7_random_sample_without_replacement __pyx_t_2; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -3220,7 +3220,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_8sample_without_replacement(CY __pyx_t_2.__pyx_n = 2; __pyx_t_2.method = __pyx_v_method; __pyx_t_2.random_state = __pyx_v_random_state; - __pyx_t_1 = __pyx_f_7sklearn_5utils_6random_sample_without_replacement(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_f_7sklearn_5utils_7_random_sample_without_replacement(__pyx_v_n_population, __pyx_v_n_samples, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 227; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3230,7 +3230,7 @@ static PyObject *__pyx_pf_7sklearn_5utils_6random_8sample_without_replacement(CY goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("sklearn.utils.random.sample_without_replacement", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("sklearn.utils._random.sample_without_replacement", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); @@ -5192,11 +5192,11 @@ static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__py } static PyMethodDef __pyx_methods[] = { - {__Pyx_NAMESTR("_sample_without_replacement_check_input"), (PyCFunction)__pyx_pw_7sklearn_5utils_6random_1_sample_without_replacement_check_input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_6random__sample_without_replacement_check_input)}, - {__Pyx_NAMESTR("_sample_without_replacement_with_tracking_selection"), (PyCFunction)__pyx_pw_7sklearn_5utils_6random_3_sample_without_replacement_with_tracking_selection, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_6random_2_sample_without_replacement_with_tracking_selection)}, - {__Pyx_NAMESTR("_sample_without_replacement_with_pool"), (PyCFunction)__pyx_pw_7sklearn_5utils_6random_5_sample_without_replacement_with_pool, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_6random_4_sample_without_replacement_with_pool)}, - {__Pyx_NAMESTR("_sample_without_replacement_with_reservoir_sampling"), (PyCFunction)__pyx_pw_7sklearn_5utils_6random_7_sample_without_replacement_with_reservoir_sampling, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_6random_6_sample_without_replacement_with_reservoir_sampling)}, - {__Pyx_NAMESTR("sample_without_replacement"), (PyCFunction)__pyx_pw_7sklearn_5utils_6random_9sample_without_replacement, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_6random_8sample_without_replacement)}, + {__Pyx_NAMESTR("_sample_without_replacement_check_input"), (PyCFunction)__pyx_pw_7sklearn_5utils_7_random_1_sample_without_replacement_check_input, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_7_random__sample_without_replacement_check_input)}, + {__Pyx_NAMESTR("_sample_without_replacement_with_tracking_selection"), (PyCFunction)__pyx_pw_7sklearn_5utils_7_random_3_sample_without_replacement_with_tracking_selection, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_7_random_2_sample_without_replacement_with_tracking_selection)}, + {__Pyx_NAMESTR("_sample_without_replacement_with_pool"), (PyCFunction)__pyx_pw_7sklearn_5utils_7_random_5_sample_without_replacement_with_pool, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_7_random_4_sample_without_replacement_with_pool)}, + {__Pyx_NAMESTR("_sample_without_replacement_with_reservoir_sampling"), (PyCFunction)__pyx_pw_7sklearn_5utils_7_random_7_sample_without_replacement_with_reservoir_sampling, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_7_random_6_sample_without_replacement_with_reservoir_sampling)}, + {__Pyx_NAMESTR("sample_without_replacement"), (PyCFunction)__pyx_pw_7sklearn_5utils_7_random_9sample_without_replacement, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_7sklearn_5utils_7_random_8sample_without_replacement)}, {0, 0, 0, 0} }; @@ -5207,7 +5207,7 @@ static struct PyModuleDef __pyx_moduledef = { #else PyModuleDef_HEAD_INIT, #endif - __Pyx_NAMESTR("random"), + __Pyx_NAMESTR("_random"), __Pyx_DOCSTR(__pyx_k_17), /* m_doc */ -1, /* m_size */ __pyx_methods /* m_methods */, @@ -5256,12 +5256,12 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if PY_MAJOR_VERSION >= 3 - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 154; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s__xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 153; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; @@ -5273,14 +5273,14 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "sklearn/utils/random.pyx":277 + /* "sklearn/utils/_random.pyx":276 * _sample_without_replacement_check_input(n_population, n_samples) * * all_methods = ("auto", "tracking_selection", "reservoir_sampling", "pool") # <<<<<<<<<<<<<< * * if method == "auto" or method == "tracking_selection": */ - __pyx_k_tuple_3 = PyTuple_Pack(4, ((PyObject *)__pyx_n_s__auto), ((PyObject *)__pyx_n_s__tracking_selection), ((PyObject *)__pyx_n_s__reservoir_sampling), ((PyObject *)__pyx_n_s__pool)); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 277; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_3 = PyTuple_Pack(4, ((PyObject *)__pyx_n_s__auto), ((PyObject *)__pyx_n_s__tracking_selection), ((PyObject *)__pyx_n_s__reservoir_sampling), ((PyObject *)__pyx_n_s__pool)); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_3); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_3)); @@ -5366,11 +5366,11 @@ static int __Pyx_InitGlobals(void) { } #if PY_MAJOR_VERSION < 3 -PyMODINIT_FUNC initrandom(void); /*proto*/ -PyMODINIT_FUNC initrandom(void) +PyMODINIT_FUNC init_random(void); /*proto*/ +PyMODINIT_FUNC init_random(void) #else -PyMODINIT_FUNC PyInit_random(void); /*proto*/ -PyMODINIT_FUNC PyInit_random(void) +PyMODINIT_FUNC PyInit__random(void); /*proto*/ +PyMODINIT_FUNC PyInit__random(void) #endif { PyObject *__pyx_t_1 = NULL; @@ -5388,7 +5388,7 @@ PyMODINIT_FUNC PyInit_random(void) Py_FatalError("failed to import 'refnanny' module"); } #endif - __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_random(void)", 0); + __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit__random(void)", 0); if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -5410,7 +5410,7 @@ PyMODINIT_FUNC PyInit_random(void) #endif /*--- Module creation code ---*/ #if PY_MAJOR_VERSION < 3 - __pyx_m = Py_InitModule4(__Pyx_NAMESTR("random"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_17), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + __pyx_m = Py_InitModule4(__Pyx_NAMESTR("_random"), __pyx_methods, __Pyx_DOCSTR(__pyx_k_17), 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); #else __pyx_m = PyModule_Create(&__pyx_moduledef); #endif @@ -5420,8 +5420,8 @@ PyMODINIT_FUNC PyInit_random(void) #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (!PyDict_GetItemString(modules, "sklearn.utils.random")) { - if (unlikely(PyDict_SetItemString(modules, "sklearn.utils.random", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!PyDict_GetItemString(modules, "sklearn.utils._random")) { + if (unlikely(PyDict_SetItemString(modules, "sklearn.utils._random", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } } #endif @@ -5435,7 +5435,7 @@ PyMODINIT_FUNC PyInit_random(void) #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif - if (__pyx_module_is_main_sklearn__utils__random) { + if (__pyx_module_is_main_sklearn__utils___random) { if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; } /*--- Builtin init code ---*/ @@ -5445,7 +5445,7 @@ PyMODINIT_FUNC PyInit_random(void) /*--- Global init code ---*/ /*--- Variable export code ---*/ /*--- Function export code ---*/ - if (__Pyx_ExportFunction("sample_without_replacement", (void (*)(void))__pyx_f_7sklearn_5utils_6random_sample_without_replacement, "PyObject *(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_6random_sample_without_replacement *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_ExportFunction("sample_without_replacement", (void (*)(void))__pyx_f_7sklearn_5utils_7_random_sample_without_replacement, "PyObject *(__pyx_t_5numpy_int_t, __pyx_t_5numpy_int_t, int __pyx_skip_dispatch, struct __pyx_opt_args_7sklearn_5utils_7_random_sample_without_replacement *__pyx_optional_args)") < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /*--- Type init code ---*/ /*--- Type import code ---*/ __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", @@ -5464,19 +5464,19 @@ PyMODINIT_FUNC PyInit_random(void) /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "sklearn/utils/random.pyx":22 + /* "sklearn/utils/_random.pyx":21 * cimport cython * * import numpy as np # <<<<<<<<<<<<<< * cimport numpy as np * np.import_array() */ - __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s__np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "sklearn/utils/random.pyx":24 + /* "sklearn/utils/_random.pyx":23 * import numpy as np * cimport numpy as np * np.import_array() # <<<<<<<<<<<<<< @@ -5485,31 +5485,31 @@ PyMODINIT_FUNC PyInit_random(void) */ import_array(); - /* "sklearn/utils/random.pyx":26 + /* "sklearn/utils/_random.pyx":25 * np.import_array() * * from sklearn.utils import check_random_state # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_n_s__check_random_state)); PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__check_random_state)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__check_random_state)); - __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_18), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s_18), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s__check_random_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s__check_random_state); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s__check_random_state, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s__check_random_state, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "sklearn/utils/random.pyx":1 - * # encoding: utf-8 # <<<<<<<<<<<<<< - * # cython: cdivision=True + /* "sklearn/utils/_random.pyx":1 + * # cython: cdivision=True # <<<<<<<<<<<<<< * # cython: boundscheck=False + * # cython: wraparound=False */ __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); @@ -5528,10 +5528,10 @@ PyMODINIT_FUNC PyInit_random(void) __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { - __Pyx_AddTraceback("init sklearn.utils.random", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("init sklearn.utils._random", __pyx_clineno, __pyx_lineno, __pyx_filename); Py_DECREF(__pyx_m); __pyx_m = 0; } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init sklearn.utils.random"); + PyErr_SetString(PyExc_ImportError, "init sklearn.utils._random"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); diff --git a/sklearn/utils/random.pxd b/sklearn/utils/_random.pxd similarity index 100% rename from sklearn/utils/random.pxd rename to sklearn/utils/_random.pxd diff --git a/sklearn/utils/random.pyx b/sklearn/utils/_random.pyx similarity index 100% rename from sklearn/utils/random.pyx rename to sklearn/utils/_random.pyx diff --git a/sklearn/utils/random.py b/sklearn/utils/random.py new file mode 100644 index 0000000000000..7912f45b48d52 --- /dev/null +++ b/sklearn/utils/random.py @@ -0,0 +1,197 @@ +# This file contains a backport of np.random.choice from numpy 1.7 +# The function can be removed when we bump the requirements to >=1.7 + +import numpy as np +import operator + +from sklearn.utils import check_random_state + +from ._random import sample_without_replacement + +__all__ = ['sample_without_replacement', 'choice'] + + +def choice(a, size=None, replace=True, p=None, random_state=None): + """ + choice(a, size=None, replace=True, p=None) + + Generates a random sample from a given 1-D array + + .. versionadded:: 1.7.0 + + Parameters + ----------- + a : 1-D array-like or int + If an ndarray, a random sample is generated from its elements. + If an int, the random sample is generated as if a was np.arange(n) + + size : int or tuple of ints, optional + Output shape. Default is None, in which case a single value is + returned. + + replace : boolean, optional + Whether the sample is with or without replacement. + + p : 1-D array-like, optional + The probabilities associated with each entry in a. + If not given the sample assumes a uniform distribtion over all + entries in a. + + random_state : int, RandomState instance or None, optional (default=None) + If int, random_state is the seed used by the random number generator; + If RandomState instance, random_state is the random number generator; + If None, the random number generator is the RandomState instance used + by `np.random`. + + + Returns + -------- + samples : 1-D ndarray, shape (size,) + The generated random samples + + Raises + ------- + ValueError + If a is an int and less than zero, if a or p are not 1-dimensional, + if a is an array-like of size 0, if p is not a vector of + probabilities, if a and p have different lengths, or if + replace=False and the sample size is greater than the population + size + + See Also + --------- + randint, shuffle, permutation + + Examples + --------- + Generate a uniform random sample from np.arange(5) of size 3: + + >>> np.random.choice(5, 3) # doctest: +SKIP + array([0, 3, 4]) + >>> #This is equivalent to np.random.randint(0,5,3) + + Generate a non-uniform random sample from np.arange(5) of size 3: + + >>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0]) # doctest: +SKIP + array([3, 3, 0]) + + Generate a uniform random sample from np.arange(5) of size 3 without + replacement: + + >>> np.random.choice(5, 3, replace=False) # doctest: +SKIP + array([3,1,0]) + >>> #This is equivalent to np.random.shuffle(np.arange(5))[:3] + + Generate a non-uniform random sample from np.arange(5) of size + 3 without replacement: + + >>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0]) + ... # doctest: +SKIP + array([2, 3, 0]) + + Any of the above can be repeated with an arbitrary array-like + instead of just integers. For instance: + + >>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher'] + >>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3]) + ... # doctest: +SKIP + array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], + dtype='|S11') + + """ + random_state = check_random_state(random_state) + + # Format and Verify input + a = np.array(a, copy=False) + if a.ndim == 0: + try: + # __index__ must return an integer by python rules. + pop_size = operator.index(a.item()) + except TypeError: + raise ValueError("a must be 1-dimensional or an integer") + if pop_size <= 0: + raise ValueError("a must be greater than 0") + elif a.ndim != 1: + raise ValueError("a must be 1-dimensional") + else: + pop_size = a.shape[0] + if pop_size is 0: + raise ValueError("a must be non-empty") + + if None != p: + p = np.array(p, dtype=np.double, ndmin=1, copy=False) + if p.ndim != 1: + raise ValueError("p must be 1-dimensional") + if p.size != pop_size: + raise ValueError("a and p must have same size") + if np.any(p < 0): + raise ValueError("probabilities are not non-negative") + if not np.allclose(p.sum(), 1): + raise ValueError("probabilities do not sum to 1") + + shape = size + if shape is not None: + size = np.prod(shape, dtype=np.intp) + else: + size = 1 + + # Actual sampling + if replace: + if None != p: + cdf = p.cumsum() + cdf /= cdf[-1] + uniform_samples = random_state.random_sample(shape) + idx = cdf.searchsorted(uniform_samples, side='right') + # searchsorted returns a scalar + idx = np.array(idx, copy=False) + else: + idx = random_state.randint(0, pop_size, size=shape) + else: + if size > pop_size: + raise ValueError("Cannot take a larger sample than " + "population when 'replace=False'") + + if None != p: + if np.sum(p > 0) < size: + raise ValueError("Fewer non-zero entries in p than size") + n_uniq = 0 + p = p.copy() + found = np.zeros(shape, dtype=np.int) + flat_found = found.ravel() + while n_uniq < size: + x = random_state.rand(size - n_uniq) + if n_uniq > 0: + p[flat_found[0:n_uniq]] = 0 + cdf = np.cumsum(p) + cdf /= cdf[-1] + new = cdf.searchsorted(x, side='right') + _, unique_indices = np.unique(new, return_index=True) + unique_indices.sort() + new = new.take(unique_indices) + flat_found[n_uniq:n_uniq + new.size] = new + n_uniq += new.size + idx = found + else: + idx = random_state.permutation(pop_size)[:size] + if shape is not None: + idx.shape = shape + + if shape is None and isinstance(idx, np.ndarray): + # In most cases a scalar will have been made an array + idx = idx.item(0) + + #Use samples as indices for a if a is array-like + if a.ndim == 0: + return idx + + if shape is not None and idx.ndim == 0: + # If size == () then the user requested a 0-d array as opposed to + # a scalar object when size is None. However a[idx] is always a + # scalar and not an array. So this makes sure the result is an + # array, taking into account that np.array(item) may not work + # for object arrays. + res = np.empty((), dtype=a.dtype) + res[()] = a[idx] + return res + + return a[idx] diff --git a/sklearn/utils/setup.py b/sklearn/utils/setup.py index 2e271c8b2673f..ac321e7d7aa5d 100644 --- a/sklearn/utils/setup.py +++ b/sklearn/utils/setup.py @@ -64,8 +64,8 @@ def configuration(parent_package='', top_path=None): libraries=cblas_libs, **blas_info) - config.add_extension("random", - sources=["random.c"], + config.add_extension("_random", + sources=["_random.c"], include_dirs=[numpy.get_include()], libraries=libraries) diff --git a/sklearn/utils/tests/test_extmath.py b/sklearn/utils/tests/test_extmath.py index cd59f7f7b0170..8676f1ceaa23a 100644 --- a/sklearn/utils/tests/test_extmath.py +++ b/sklearn/utils/tests/test_extmath.py @@ -72,8 +72,8 @@ def test_random_weights(): mode, score = weighted_mode(x, w, axis=1) - np.testing.assert_array_equal(mode, mode_result) - np.testing.assert_array_almost_equal(score.ravel(), w[:, :5].sum(1)) + assert_array_equal(mode, mode_result) + assert_array_almost_equal(score.ravel(), w[:, :5].sum(1)) def test_logsumexp():