Skip to content

Commit 8ed76c7

Browse files
authored
MAINT cython typedefs in _cd_fast (scikit-learn#27334)
1 parent 83a8015 commit 8ed76c7

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

sklearn/linear_model/_cd_fast.pyx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ from cython cimport floating
1414
import warnings
1515
from ..exceptions import ConvergenceWarning
1616

17-
from ..utils._cython_blas cimport (_axpy, _dot, _asum, _gemv, _nrm2,
18-
_copy, _scal)
17+
from ..utils._cython_blas cimport (
18+
_axpy, _dot, _asum, _gemv, _nrm2, _copy, _scal
19+
)
1920
from ..utils._cython_blas cimport ColMajor, Trans, NoTrans
20-
21-
21+
from ..utils._typedefs cimport uint32_t
2222
from ..utils._random cimport our_rand_r
2323

24-
ctypedef cnp.float64_t DOUBLE
25-
ctypedef cnp.uint32_t UINT32_t
2624

2725
cnp.import_array()
2826

@@ -37,7 +35,7 @@ cdef enum:
3735
RAND_R_MAX = 2147483647
3836

3937

40-
cdef inline UINT32_t rand_int(UINT32_t end, UINT32_t* random_state) noexcept nogil:
38+
cdef inline uint32_t rand_int(uint32_t end, uint32_t* random_state) noexcept nogil:
4139
"""Generate a random integer in [0; end)."""
4240
return our_rand_r(random_state) % end
4341

@@ -156,8 +154,8 @@ def enet_coordinate_descent(
156154
cdef unsigned int ii
157155
cdef unsigned int n_iter = 0
158156
cdef unsigned int f_iter
159-
cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
160-
cdef UINT32_t* rand_r_state = &rand_r_state_seed
157+
cdef uint32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
158+
cdef uint32_t* rand_r_state = &rand_r_state_seed
161159

162160
if alpha == 0 and beta == 0:
163161
warnings.warn("Coordinate descent with no regularization may lead to "
@@ -370,8 +368,8 @@ def sparse_enet_coordinate_descent(
370368
cdef unsigned int jj
371369
cdef unsigned int n_iter = 0
372370
cdef unsigned int f_iter
373-
cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
374-
cdef UINT32_t* rand_r_state = &rand_r_state_seed
371+
cdef uint32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
372+
cdef uint32_t* rand_r_state = &rand_r_state_seed
375373
cdef bint center = False
376374
cdef bint no_sample_weights = sample_weight is None
377375
cdef int kk
@@ -628,8 +626,8 @@ def enet_coordinate_descent_gram(
628626
cdef unsigned int ii
629627
cdef unsigned int n_iter = 0
630628
cdef unsigned int f_iter
631-
cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
632-
cdef UINT32_t* rand_r_state = &rand_r_state_seed
629+
cdef uint32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
630+
cdef uint32_t* rand_r_state = &rand_r_state_seed
633631

634632
cdef floating y_norm2 = np.dot(y, y)
635633
cdef floating* w_ptr = &w[0]
@@ -808,8 +806,8 @@ def enet_coordinate_descent_multi_task(
808806
cdef unsigned int jj
809807
cdef unsigned int n_iter = 0
810808
cdef unsigned int f_iter
811-
cdef UINT32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
812-
cdef UINT32_t* rand_r_state = &rand_r_state_seed
809+
cdef uint32_t rand_r_state_seed = rng.randint(0, RAND_R_MAX)
810+
cdef uint32_t* rand_r_state = &rand_r_state_seed
813811

814812
cdef const floating* X_ptr = &X[0, 0]
815813
cdef const floating* Y_ptr = &Y[0, 0]

sklearn/utils/_typedefs.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# use these consistently throughout the codebase.
1616
# NOTE: Extend this list as needed when converting more cython extensions.
1717
ctypedef unsigned char uint8_t
18+
ctypedef unsigned int uint32_t
1819
ctypedef Py_ssize_t intp_t
1920
ctypedef float float32_t
2021
ctypedef double float64_t

sklearn/utils/_typedefs.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import numpy as np
88

99
ctypedef fused testing_type_t:
1010
uint8_t
11+
uint32_t
1112
intp_t
1213
float32_t
1314
float64_t

0 commit comments

Comments
 (0)