Skip to content

Instantly share code, notes, and snippets.

@thomasjpfan
Last active January 3, 2023 23:13
Show Gist options
  • Select an option

  • Save thomasjpfan/5680fcfcf03683829ef560fe5c5e9e3f to your computer and use it in GitHub Desktop.

Select an option

Save thomasjpfan/5680fcfcf03683829ef560fe5c5e9e3f to your computer and use it in GitHub Desktop.
patch_for_debugging scikit-learn#25172
diff --git a/sklearn/decomposition/_dict_learning.py b/sklearn/decomposition/_dict_learning.py
index b0c252fc31..e99465ada3 100644
--- a/sklearn/decomposition/_dict_learning.py
+++ b/sklearn/decomposition/_dict_learning.py
@@ -174,6 +174,8 @@ def _sparse_encode(
)
if init is not None:
+ if not init.flags["WRITEABLE"]:
+ init = np.array(init)
clf.coef_ = init
clf.fit(dictionary.T, X.T, check_input=check_input)
diff --git a/sklearn/linear_model/_cd_fast.pyx b/sklearn/linear_model/_cd_fast.pyx
index dc1c374d61..11bb7547c4 100644
--- a/sklearn/linear_model/_cd_fast.pyx
+++ b/sklearn/linear_model/_cd_fast.pyx
@@ -96,7 +96,7 @@ def enet_coordinate_descent(
cnp.ndarray[floating, ndim=1, mode='c'] w,
floating alpha,
floating beta,
- floating[::1, :] X,
+ cnp.ndarray[floating, ndim=2, mode='fortran'] X,
cnp.ndarray[floating, ndim=1, mode='c'] y,
unsigned int max_iter,
floating tol,
@@ -568,12 +568,12 @@ def sparse_enet_coordinate_descent(
def enet_coordinate_descent_gram(
# TODO: const-qualify fused typed memoryview when Cython 3 is used (#23147)
- floating[::1] w,
+ cnp.ndarray[floating, ndim=1, mode='c'] w,
floating alpha,
floating beta,
- floating[:, ::1] Q,
- floating[::1] q,
- floating[:] y,
+ cnp.ndarray[floating, ndim=2, mode='c'] Q,
+ cnp.ndarray[floating, ndim=1, mode='c'] q,
+ cnp.ndarray[floating, ndim=1] y,
unsigned int max_iter,
floating tol,
object rng,
diff --git a/sklearn/linear_model/_coordinate_descent.py b/sklearn/linear_model/_coordinate_descent.py
index 54bb9072c1..957fb50de3 100644
--- a/sklearn/linear_model/_coordinate_descent.py
+++ b/sklearn/linear_model/_coordinate_descent.py
@@ -596,7 +596,7 @@ def enet_path(
beta=l2_reg,
# TODO: remove ReadonlyArrayWrapper when const-qualify fused typed
# memoryviews are used (this necessiates Cython 3).
- X_data=ReadonlyArrayWrapper(X.data),
+ X_data=X.data,
X_indices=X.indices,
X_indptr=X.indptr,
y=y,
@@ -618,14 +618,12 @@ def enet_path(
if check_input:
precompute = check_array(precompute, dtype=X.dtype.type, order="C")
model = cd_fast.enet_coordinate_descent_gram(
- # TODO: remove ReadonlyArrayWrappers when const-qualify fused typed
- # memoryviews are used (this necessiates Cython 3).
- ReadonlyArrayWrapper(coef_),
+ coef_,
l1_reg,
l2_reg,
- ReadonlyArrayWrapper(precompute),
- ReadonlyArrayWrapper(Xy),
- ReadonlyArrayWrapper(y),
+ precompute,
+ Xy,
+ y,
max_iter,
tol,
rng,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment