@@ -90,13 +90,12 @@ cdef floating diff_abs_max(int n, floating* a, floating* b) noexcept nogil:
90
90
m = d
91
91
return m
92
92
93
- # TODO: use const fused typed memoryview where possible when Cython 0.29.33 is used.
94
93
def enet_coordinate_descent (
95
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] w,
94
+ floating[::1 ] w ,
96
95
floating alpha ,
97
96
floating beta ,
98
- cnp.ndarray[ floating , ndim = 2 , mode = ' fortran ' ] X,
99
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] y,
97
+ const floating[::1, : ] X ,
98
+ const floating[::1 ] y ,
100
99
unsigned int max_iter ,
101
100
floating tol ,
102
101
object rng ,
@@ -273,17 +272,16 @@ def enet_coordinate_descent(
273
272
return np.asarray(w), gap, tol, n_iter + 1
274
273
275
274
276
- # TODO: use const fused typed memoryview where possible when Cython 0.29.33 is used.
277
275
def sparse_enet_coordinate_descent (
278
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] w,
276
+ floating[::1 ] w ,
279
277
floating alpha ,
280
278
floating beta ,
281
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] X_data,
279
+ const floating[::1 ] X_data ,
282
280
const int[::1] X_indices ,
283
281
const int[::1] X_indptr ,
284
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] y,
285
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] sample_weight,
286
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] X_mean,
282
+ const floating[::1 ] y ,
283
+ const floating[::1 ] sample_weight ,
284
+ const floating[::1 ] X_mean ,
287
285
unsigned int max_iter ,
288
286
floating tol ,
289
287
object rng ,
@@ -340,7 +338,7 @@ def sparse_enet_coordinate_descent(
340
338
# R = y - Zw, weighted version R = sample_weight * (y - Zw)
341
339
cdef floating[::1 ] R
342
340
cdef floating[::1 ] XtA
343
- cdef floating[::1 ] yw
341
+ cdef const floating[::1 ] yw
344
342
345
343
if floating is float :
346
344
dtype = np.float32
@@ -565,14 +563,13 @@ def sparse_enet_coordinate_descent(
565
563
return np.asarray(w), gap, tol, n_iter + 1
566
564
567
565
568
- # TODO: use const fused typed memoryview where possible when Cython 0.29.33 is used.
569
566
def enet_coordinate_descent_gram (
570
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] w,
567
+ floating[::1 ] w ,
571
568
floating alpha ,
572
569
floating beta ,
573
- cnp.ndarray[ floating , ndim = 2 , mode = ' c ' ] Q,
574
- cnp.ndarray[ floating , ndim = 1 , mode = ' c ' ] q,
575
- cnp.ndarray[ floating , ndim = 1 ] y,
570
+ const floating[:, ::1 ] Q ,
571
+ const floating[::1 ] q ,
572
+ const floating[: ] y ,
576
573
unsigned int max_iter ,
577
574
floating tol ,
578
575
object rng ,
@@ -633,8 +630,8 @@ def enet_coordinate_descent_gram(
633
630
634
631
cdef floating y_norm2 = np.dot(y, y)
635
632
cdef floating* w_ptr = & w[0 ]
636
- cdef floating* Q_ptr = & Q[0 , 0 ]
637
- cdef floating* q_ptr = & q[0 ]
633
+ cdef const floating* Q_ptr = & Q[0 , 0 ]
634
+ cdef const floating* q_ptr = & q[0 ]
638
635
cdef floating* H_ptr = & H[0 ]
639
636
cdef floating* XtA_ptr = & XtA[0 ]
640
637
tol = tol * y_norm2
@@ -736,14 +733,12 @@ def enet_coordinate_descent_gram(
736
733
737
734
return np.asarray(w), gap, tol, n_iter + 1
738
735
739
- # TODO: use const fused typed memoryview where possible when Cython 0.29.33 is used.
740
736
def enet_coordinate_descent_multi_task (
741
- cnp.ndarray[ floating , ndim = 2 , mode = ' fortran ' ] W,
737
+ const floating[::1, : ] W ,
742
738
floating l1_reg ,
743
739
floating l2_reg ,
744
- # TODO: use const qualified fused-typed memoryview when Cython 3.0 is used.
745
- cnp.ndarray[floating , ndim = 2 , mode = ' fortran' ] X,
746
- cnp.ndarray[floating , ndim = 2 , mode = ' fortran' ] Y,
740
+ const floating[::1, :] X ,
741
+ const floating[::1, :] Y ,
747
742
unsigned int max_iter ,
748
743
floating tol ,
749
744
object rng ,
@@ -807,8 +802,8 @@ def enet_coordinate_descent_multi_task(
807
802
cdef UINT32_t rand_r_state_seed = rng.randint(0 , RAND_R_MAX)
808
803
cdef UINT32_t* rand_r_state = & rand_r_state_seed
809
804
810
- cdef floating* X_ptr = & X[0 , 0 ]
811
- cdef floating* Y_ptr = & Y[0 , 0 ]
805
+ cdef const floating* X_ptr = & X[0 , 0 ]
806
+ cdef const floating* Y_ptr = & Y[0 , 0 ]
812
807
813
808
if l1_reg == 0 :
814
809
warnings.warn(" Coordinate descent with l1_reg=0 may lead to unexpected"
0 commit comments