Skip to content

Commit e87653d

Browse files
committed
TST skip SparsePCA n_jobs!=1 test on Mac OS X because it hangs
1 parent 20c45ae commit e87653d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

sklearn/decomposition/tests/test_sparse_pca.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sklearn.utils.testing import SkipTest
1212
from sklearn.utils.testing import assert_true
1313
from sklearn.utils.testing import assert_false
14+
from sklearn.utils.testing import if_not_mac_os
1415

1516
from sklearn.decomposition import SparsePCA, MiniBatchSparsePCA
1617
from sklearn.utils import check_random_state
@@ -62,18 +63,29 @@ def test_fit_transform():
6263
spca_lars = SparsePCA(n_components=3, method='lars', alpha=alpha,
6364
random_state=0)
6465
spca_lars.fit(Y)
66+
67+
# Test that CD gives similar results
68+
spca_lasso = SparsePCA(n_components=3, method='cd', random_state=0,
69+
alpha=alpha)
70+
spca_lasso.fit(Y)
71+
assert_array_almost_equal(spca_lasso.components_, spca_lars.components_)
72+
73+
74+
@if_not_mac_os()
75+
def test_fit_transform_parallel():
76+
alpha = 1
77+
rng = np.random.RandomState(0)
78+
Y, _, _ = generate_toy_data(3, 10, (8, 8), random_state=rng) # wide array
79+
spca_lars = SparsePCA(n_components=3, method='lars', alpha=alpha,
80+
random_state=0)
81+
spca_lars.fit(Y)
6582
U1 = spca_lars.transform(Y)
6683
# Test multiple CPUs
6784
spca = SparsePCA(n_components=3, n_jobs=2, method='lars', alpha=alpha,
6885
random_state=0).fit(Y)
6986
U2 = spca.transform(Y)
7087
assert_true(not np.all(spca_lars.components_ == 0))
7188
assert_array_almost_equal(U1, U2)
72-
# Test that CD gives similar results
73-
spca_lasso = SparsePCA(n_components=3, method='cd', random_state=0,
74-
alpha=alpha)
75-
spca_lasso.fit(Y)
76-
assert_array_almost_equal(spca_lasso.components_, spca_lars.components_)
7789

7890

7991
def test_transform_nan():

0 commit comments

Comments
 (0)