8000 make sparse encoder map copy on write arrays as gram omp modifies in … · scikit-learn/scikit-learn@562dffe · GitHub
[go: up one dir, main page]

Skip to content

Commit 562dffe

Browse files
make sparse encoder map copy on write arrays as gram omp modifies in place
1 parent 34ebbd3 commit 562dffe

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sklearn/decomposition/dict_learning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def sparse_encode(X, dictionary, gram=None, cov=None, algorithm='lasso_lars',
288288
code = np.empty((n_samples, n_components))
289289
slices = list(gen_even_slices(n_samples, _get_n_jobs(n_jobs)))
290290

291-
code_views = Parallel(n_jobs=n_jobs, verbose=verbose)(
291+
code_views = Parallel(n_jobs=n_jobs, verbose=verbose, mmap_mode='c')(
292292
delayed(_sparse_encode)(
293293
X[this_slice], dictionary, gram,
294294
cov[:, this_slice] if cov is not None else None,

sklearn/decomposition/tests/test_dict_learning.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,13 @@ def test_sparse_coder_estimator():
238238
transform_alpha=0.001).transform(X)
239239
assert_true(not np.all(code == 0))
240240
assert_less(np.sqrt(np.sum((np.dot(code, V) - X) ** 2)), 0.1)
241+
242+
243+
def test_sparse_coder_mmap():
244+
# Test that SparseCoder does not error by passing reading only
245+
# arrays to child processes
246+
247+
init_dict = np.random.rand(500, 64)
248+
data = np.random.rand(8096, 64)
249+
sc = SparseCoder(init_dict, transform_algorithm='omp', n_jobs=2)
250+
sc.fit_transform(data)

0 commit comments

Comments
 (0)
0