2018-10-19 19:16:18 +00:00
|
|
|
def test_joblib_numpy_pickle(selenium, request):
|
2020-06-28 18:24:40 +00:00
|
|
|
selenium.load_package(["numpy", "joblib"])
|
|
|
|
selenium.run(
|
|
|
|
"""
|
2018-10-05 15:00:47 +00:00
|
|
|
import joblib
|
|
|
|
import numpy as np
|
|
|
|
from numpy.testing import assert_array_equal
|
|
|
|
|
|
|
|
X = np.ones(10)
|
|
|
|
|
|
|
|
file_path = "./X.pkl"
|
|
|
|
|
|
|
|
joblib.dump(X, file_path)
|
|
|
|
|
|
|
|
X2 = joblib.load(file_path)
|
|
|
|
|
2020-06-28 18:24:40 +00:00
|
|
|
assert_array_equal(X, X2)"""
|
|
|
|
)
|
2018-10-05 15:00:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_joblib_parallel(selenium):
|
2020-06-28 18:24:40 +00:00
|
|
|
selenium.load_package(["numpy", "joblib"])
|
2018-10-05 15:00:47 +00:00
|
|
|
selenium.clean_logs()
|
2020-06-28 18:24:40 +00:00
|
|
|
selenium.run(
|
|
|
|
"""
|
2018-10-05 15:00:47 +00:00
|
|
|
from math import sqrt
|
|
|
|
from joblib import Parallel, delayed
|
|
|
|
|
|
|
|
# check that the default multiprocessing backend
|
|
|
|
# gracefully reduces to n_jobs=1
|
|
|
|
res = Parallel(n_jobs=2)(delayed(sqrt)(i ** 2)
|
|
|
|
for i in range(10))
|
|
|
|
assert res == [sqrt(i ** 2) for i in range(10)]
|
|
|
|
|
|
|
|
# check threading backend
|
|
|
|
Parallel(n_jobs=2, backend='threading')(
|
|
|
|
delayed(sqrt)(i ** 2) for i in range(10))
|
2020-06-28 18:24:40 +00:00
|
|
|
"""
|
|
|
|
)
|