From cc9197d57f6d32c1fcb83a6f9b3d1a658af46d02 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Wed, 5 Jul 2023 11:00:52 +0200 Subject: [PATCH 1/2] use base 10 [scipy-dev] --- sklearn/linear_model/_cd_fast.pyx | 4 +++- sklearn/tree/_utils.pxd | 4 +++- sklearn/utils/_random.pxd | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sklearn/linear_model/_cd_fast.pyx b/sklearn/linear_model/_cd_fast.pyx index 3b0b2251abf69..38ba169ae8015 100644 --- a/sklearn/linear_model/_cd_fast.pyx +++ b/sklearn/linear_model/_cd_fast.pyx @@ -32,7 +32,9 @@ cdef enum: # Max value for our rand_r replacement (near the bottom). # We don't use RAND_MAX because it's different across platforms and # particularly tiny on Windows/MSVC. - RAND_R_MAX = 0x7FFFFFFF + # It corresponds to the maximum representable value for + # 32-bit signed integers (i.e. 2^31 - 1). + RAND_R_MAX = 2147483647 cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) noexcept nogil: diff --git a/sklearn/tree/_utils.pxd b/sklearn/tree/_utils.pxd index 4938d3030245f..4b953af2d9b2b 100644 --- a/sklearn/tree/_utils.pxd +++ b/sklearn/tree/_utils.pxd @@ -23,7 +23,9 @@ cdef enum: # Max value for our rand_r replacement (near the bottom). # We don't use RAND_MAX because it's different across platforms and # particularly tiny on Windows/MSVC. - RAND_R_MAX = 0x7FFFFFFF + # It corresponds to the maximum representable value for + # 32-bit signed integers (i.e. 2^31 - 1). + RAND_R_MAX = 2147483647 # safe_realloc(&p, n) resizes the allocation of p to n * sizeof(*p) bytes or diff --git a/sklearn/utils/_random.pxd b/sklearn/utils/_random.pxd index 89741ea38179c..b5199fc506f4e 100644 --- a/sklearn/utils/_random.pxd +++ b/sklearn/utils/_random.pxd @@ -14,7 +14,7 @@ cdef enum: # particularly tiny on Windows/MSVC. # It corresponds to the maximum representable value for # 32-bit signed integers (i.e. 2^31 - 1). - RAND_R_MAX = 0x7FFFFFFF + RAND_R_MAX = 2147483647 cpdef sample_without_replacement(cnp.int_t n_population, cnp.int_t n_samples, From 5b23a3641de1580c32622a01debd4cb8ad3a3335 Mon Sep 17 00:00:00 2001 From: jeremie du boisberranger Date: Wed, 5 Jul 2023 11:41:22 +0200 Subject: [PATCH 2/2] fix function declaration --- sklearn/tree/_criterion.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/tree/_criterion.pyx b/sklearn/tree/_criterion.pyx index 79f6346be239d..ed8a12065554e 100644 --- a/sklearn/tree/_criterion.pyx +++ b/sklearn/tree/_criterion.pyx @@ -236,7 +236,7 @@ cdef class Criterion: double upper_bound, double value_left, double value_right, - ) nogil: + ) noexcept nogil: cdef: bint check_lower_bound = ( (value_left >= lower_bound) &