Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94f8dec

Browse files
committed
MNT: Use GEMV in enet_coordinate_descent
Make use of the BLAS GEMV operation in `enet_coordinate_descent` instead of using DOT in a `for`-loop. Go ahead and use GEMV with both non-transposed and transposed arrays. Previously we have had issues with the vendored BLAS and GEMV on transposed arrays, but this attempts to use GEMV on transposed arrays anyways. Hopefully we can make them work as well. As GEMV and DOT in a `for`-loop are both semantically equivalent, this is a reasonable change to make. Though GEMV likely uses a multithreaded approach unlike our application of DOT in a serial loop here. In BLAS implementations that do use threads for DOT, we can expect that GEMV will make better usage of those threads and avoid unnecessary setup and teardown costs that DOT in a `for`-loop is likely to incur (possibly in each iteration of the `for`-loop).
1 parent 9c6de2f commit 94f8dec

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

sklearn/linear_model/cd_fast.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,11 @@ def enet_coordinate_descent(floating[::1] w,
211211
# stopping criterion
212212

213213
# XtA = np.dot(X.T, R) - beta * w
214-
for i in range(n_features):
215-
XtA[i] = (_dot(n_samples, &X[0, i], 1, &R[0], 1)
216-
- beta * w[i])
214+
_copy(n_features, &w[0], 1, &XtA[0], 1)
215+
_gemv(CblasColMajor, CblasTrans,
216+
n_samples, n_features, 1.0, &X[0, 0], n_samples,
217+
&R[0], 1,
218+
-beta, &XtA[0], 1)
217219

218220
if positive:
219221
dual_norm_XtA = max(n_features, &XtA[0])

0 commit comments

Comments
 (0)