Skip to content

Commit

Permalink
FIX Update randomized SVD benchmark (scikit-learn#23373)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentzbao committed May 19, 2022
1 parent 0f1c0e7 commit e966f96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion benchmarks/bench_plot_randomized_svd.py
Expand Up @@ -153,7 +153,7 @@ def get_data(dataset_name):
elif dataset_name == "rcv1":
X = fetch_rcv1().data
elif dataset_name == "CIFAR":
if handle_missing_dataset(CIFAR_FOLDER) == "skip":
if handle_missing_dataset(CIFAR_FOLDER) == 0:
return
X1 = [unpickle("%sdata_batch_%d" % (CIFAR_FOLDER, i + 1)) for i in range(5)]
X = np.vstack(X1)
Expand Down
8 changes: 5 additions & 3 deletions sklearn/utils/extmath.py
Expand Up @@ -216,9 +216,6 @@ def randomized_range_finder(

# Generating normal random vectors with shape: (A.shape[1], size)
Q = random_state.normal(size=(A.shape[1], size))
if A.dtype.kind == "f":
# Ensure f32 is preserved as f32
Q = Q.astype(A.dtype, copy=False)

# Deal with "auto" mode
if power_iteration_normalizer == "auto":
Expand All @@ -243,6 +240,11 @@ def randomized_range_finder(
# Sample the range of A using by linear projection of Q
# Extract an orthonormal basis
Q, _ = linalg.qr(safe_sparse_dot(A, Q), mode="economic")

if hasattr(A, "dtype") and A.dtype.kind == "f":
# Ensure f32 is preserved as f32
Q = Q.astype(A.dtype, copy=False)

return Q


Expand Down

0 comments on commit e966f96

Please sign in to comment.