diff --git a/sklearn/linear_model/cd_fast.pyx b/sklearn/linear_model/cd_fast.pyx index ad0fa4277f3be..fcbe46ce77711 100644 --- a/sklearn/linear_model/cd_fast.pyx +++ b/sklearn/linear_model/cd_fast.pyx @@ -24,7 +24,7 @@ from ..utils._cython_blas cimport (_axpy, _dot, _asum, _ger, _gemv, _nrm2, from ..utils._cython_blas cimport RowMajor, ColMajor, Trans, NoTrans -from ..utils cimport _random +from ..utils._random cimport our_rand_r ctypedef np.float64_t DOUBLE ctypedef np.uint32_t UINT32_t @@ -42,7 +42,7 @@ cdef enum: cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) nogil: """Generate a random integer in [0; end).""" - return _random.our_rand_r(random_state) % end + return our_rand_r(random_state) % end cdef inline floating fmax(floating x, floating y) nogil: diff --git a/sklearn/tree/_utils.pyx b/sklearn/tree/_utils.pyx index fdbd48e75f3a9..634eb3ef84cdd 100644 --- a/sklearn/tree/_utils.pyx +++ b/sklearn/tree/_utils.pyx @@ -20,7 +20,7 @@ import numpy as np cimport numpy as np np.import_array() -from ..utils cimport _random +from ..utils._random cimport our_rand_r # ============================================================================= # Helper functions @@ -64,13 +64,13 @@ cdef inline np.ndarray sizet_ptr_to_ndarray(SIZE_t* data, SIZE_t size): cdef inline SIZE_t rand_int(SIZE_t low, SIZE_t high, UINT32_t* random_state) nogil: """Generate a random integer in [low; end).""" - return low + _random.our_rand_r(random_state) % (high - low) + return low + our_rand_r(random_state) % (high - low) cdef inline double rand_uniform(double low, double high, UINT32_t* random_state) nogil: """Generate a random double in [low; high).""" - return ((high - low) * _random.our_rand_r(random_state) / + return ((high - low) * our_rand_r(random_state) / RAND_R_MAX) + low diff --git a/sklearn/utils/seq_dataset.pyx.tp b/sklearn/utils/seq_dataset.pyx.tp index f1b34c4c86bce..14f80804554db 100644 --- a/sklearn/utils/seq_dataset.pyx.tp +++ b/sklearn/utils/seq_dataset.pyx.tp @@ -45,7 +45,7 @@ import numpy as np np.import_array() -from . cimport _random +from ._random cimport our_rand_r cdef class SequentialDataset{{name}}: """Base class for datasets with sequential data access. @@ -155,7 +155,7 @@ cdef class SequentialDataset{{name}}: cdef int n = self.n_samples cdef unsigned i, j for i in range(n - 1): - j = i + _random.our_rand_r(&seed) % (n - i) + j = i + our_rand_r(&seed) % (n - i) ind[i], ind[j] = ind[j], ind[i] cdef int _get_next_index(self) nogil: @@ -169,7 +169,7 @@ cdef class SequentialDataset{{name}}: cdef int _get_random_index(self) nogil: cdef int n = self.n_samples - cdef int current_index = _random.our_rand_r(&self.seed) % n + cdef int current_index = our_rand_r(&self.seed) % n self.current_index = current_index return current_index