scikit-learn-intelex 2025.0.0__py312-none-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scikit-learn-intelex might be problematic. Click here for more details.
- daal4py/__init__.py +73 -0
- daal4py/__main__.py +58 -0
- daal4py/_daal4py.cpython-312-x86_64-linux-gnu.so +0 -0
- daal4py/doc/third-party-programs.txt +424 -0
- daal4py/mb/__init__.py +19 -0
- daal4py/mb/model_builders.py +377 -0
- daal4py/mpi_transceiver.cpython-312-x86_64-linux-gnu.so +0 -0
- daal4py/sklearn/__init__.py +40 -0
- daal4py/sklearn/_n_jobs_support.py +242 -0
- daal4py/sklearn/_utils.py +241 -0
- daal4py/sklearn/cluster/__init__.py +20 -0
- daal4py/sklearn/cluster/dbscan.py +165 -0
- daal4py/sklearn/cluster/k_means.py +597 -0
- daal4py/sklearn/cluster/tests/test_dbscan.py +109 -0
- daal4py/sklearn/decomposition/__init__.py +19 -0
- daal4py/sklearn/decomposition/_pca.py +524 -0
- daal4py/sklearn/ensemble/AdaBoostClassifier.py +192 -0
- daal4py/sklearn/ensemble/GBTDAAL.py +318 -0
- daal4py/sklearn/ensemble/__init__.py +27 -0
- daal4py/sklearn/ensemble/_forest.py +1397 -0
- daal4py/sklearn/ensemble/tests/test_decision_forest.py +206 -0
- daal4py/sklearn/linear_model/__init__.py +29 -0
- daal4py/sklearn/linear_model/_coordinate_descent.py +848 -0
- daal4py/sklearn/linear_model/_linear.py +272 -0
- daal4py/sklearn/linear_model/_ridge.py +325 -0
- daal4py/sklearn/linear_model/coordinate_descent.py +17 -0
- daal4py/sklearn/linear_model/linear.py +17 -0
- daal4py/sklearn/linear_model/logistic_loss.py +195 -0
- daal4py/sklearn/linear_model/logistic_path.py +1026 -0
- daal4py/sklearn/linear_model/ridge.py +17 -0
- daal4py/sklearn/linear_model/tests/test_linear.py +196 -0
- daal4py/sklearn/linear_model/tests/test_ridge.py +69 -0
- daal4py/sklearn/manifold/__init__.py +19 -0
- daal4py/sklearn/manifold/_t_sne.py +405 -0
- daal4py/sklearn/metrics/__init__.py +20 -0
- daal4py/sklearn/metrics/_pairwise.py +155 -0
- daal4py/sklearn/metrics/_ranking.py +210 -0
- daal4py/sklearn/model_selection/__init__.py +19 -0
- daal4py/sklearn/model_selection/_split.py +309 -0
- daal4py/sklearn/model_selection/tests/test_split.py +56 -0
- daal4py/sklearn/monkeypatch/__init__.py +0 -0
- daal4py/sklearn/monkeypatch/dispatcher.py +232 -0
- daal4py/sklearn/monkeypatch/tests/_models_info.py +161 -0
- daal4py/sklearn/monkeypatch/tests/test_monkeypatch.py +71 -0
- daal4py/sklearn/monkeypatch/tests/test_patching.py +87 -0
- daal4py/sklearn/monkeypatch/tests/utils/_launch_algorithms.py +118 -0
- daal4py/sklearn/neighbors/__init__.py +21 -0
- daal4py/sklearn/neighbors/_base.py +503 -0
- daal4py/sklearn/neighbors/_classification.py +139 -0
- daal4py/sklearn/neighbors/_regression.py +74 -0
- daal4py/sklearn/neighbors/_unsupervised.py +55 -0
- daal4py/sklearn/neighbors/tests/test_kneighbors.py +113 -0
- daal4py/sklearn/svm/__init__.py +19 -0
- daal4py/sklearn/svm/svm.py +734 -0
- daal4py/sklearn/utils/__init__.py +21 -0
- daal4py/sklearn/utils/base.py +75 -0
- daal4py/sklearn/utils/tests/test_utils.py +51 -0
- daal4py/sklearn/utils/validation.py +693 -0
- onedal/__init__.py +83 -0
- onedal/_config.py +53 -0
- onedal/_device_offload.py +229 -0
- onedal/_onedal_py_dpc.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_host.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_spmd_dpc.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/basic_statistics/__init__.py +20 -0
- onedal/basic_statistics/basic_statistics.py +107 -0
- onedal/basic_statistics/incremental_basic_statistics.py +160 -0
- onedal/basic_statistics/tests/test_basic_statistics.py +298 -0
- onedal/basic_statistics/tests/test_incremental_basic_statistics.py +196 -0
- onedal/cluster/__init__.py +27 -0
- onedal/cluster/dbscan.py +110 -0
- onedal/cluster/kmeans.py +560 -0
- onedal/cluster/kmeans_init.py +115 -0
- onedal/cluster/tests/test_dbscan.py +125 -0
- onedal/cluster/tests/test_kmeans.py +88 -0
- onedal/cluster/tests/test_kmeans_init.py +93 -0
- onedal/common/_base.py +38 -0
- onedal/common/_estimator_checks.py +47 -0
- onedal/common/_mixin.py +62 -0
- onedal/common/_policy.py +59 -0
- onedal/common/_spmd_policy.py +30 -0
- onedal/common/hyperparameters.py +116 -0
- onedal/common/tests/test_policy.py +75 -0
- onedal/covariance/__init__.py +20 -0
- onedal/covariance/covariance.py +125 -0
- onedal/covariance/incremental_covariance.py +146 -0
- onedal/covariance/tests/test_covariance.py +50 -0
- onedal/covariance/tests/test_incremental_covariance.py +122 -0
- onedal/datatypes/__init__.py +19 -0
- onedal/datatypes/_data_conversion.py +95 -0
- onedal/datatypes/tests/test_data.py +235 -0
- onedal/decomposition/__init__.py +20 -0
- onedal/decomposition/incremental_pca.py +204 -0
- onedal/decomposition/pca.py +186 -0
- onedal/decomposition/tests/test_incremental_pca.py +198 -0
- onedal/ensemble/__init__.py +29 -0
- onedal/ensemble/forest.py +720 -0
- onedal/ensemble/tests/test_random_forest.py +97 -0
- onedal/linear_model/__init__.py +27 -0
- onedal/linear_model/incremental_linear_model.py +258 -0
- onedal/linear_model/linear_model.py +329 -0
- onedal/linear_model/logistic_regression.py +249 -0
- onedal/linear_model/tests/test_incremental_linear_regression.py +168 -0
- onedal/linear_model/tests/test_incremental_ridge_regression.py +107 -0
- onedal/linear_model/tests/test_linear_regression.py +149 -0
- onedal/linear_model/tests/test_logistic_regression.py +95 -0
- onedal/linear_model/tests/test_ridge.py +95 -0
- onedal/neighbors/__init__.py +19 -0
- onedal/neighbors/neighbors.py +778 -0
- onedal/neighbors/tests/test_knn_classification.py +49 -0
- onedal/primitives/__init__.py +27 -0
- onedal/primitives/get_tree.py +25 -0
- onedal/primitives/kernel_functions.py +153 -0
- onedal/primitives/tests/test_kernel_functions.py +159 -0
- onedal/spmd/__init__.py +25 -0
- onedal/spmd/_base.py +30 -0
- onedal/spmd/basic_statistics/__init__.py +20 -0
- onedal/spmd/basic_statistics/basic_statistics.py +30 -0
- onedal/spmd/basic_statistics/incremental_basic_statistics.py +69 -0
- onedal/spmd/cluster/__init__.py +28 -0
- onedal/spmd/cluster/dbscan.py +23 -0
- onedal/spmd/cluster/kmeans.py +56 -0
- onedal/spmd/covariance/__init__.py +20 -0
- onedal/spmd/covariance/covariance.py +26 -0
- onedal/spmd/covariance/incremental_covariance.py +82 -0
- onedal/spmd/decomposition/__init__.py +20 -0
- onedal/spmd/decomposition/incremental_pca.py +117 -0
- onedal/spmd/decomposition/pca.py +26 -0
- onedal/spmd/ensemble/__init__.py +19 -0
- onedal/spmd/ensemble/forest.py +28 -0
- onedal/spmd/linear_model/__init__.py +21 -0
- onedal/spmd/linear_model/incremental_linear_model.py +97 -0
- onedal/spmd/linear_model/linear_model.py +30 -0
- onedal/spmd/linear_model/logistic_regression.py +38 -0
- onedal/spmd/neighbors/__init__.py +19 -0
- onedal/spmd/neighbors/neighbors.py +75 -0
- onedal/svm/__init__.py +19 -0
- onedal/svm/svm.py +556 -0
- onedal/svm/tests/test_csr_svm.py +351 -0
- onedal/svm/tests/test_nusvc.py +204 -0
- onedal/svm/tests/test_nusvr.py +210 -0
- onedal/svm/tests/test_svc.py +168 -0
- onedal/svm/tests/test_svr.py +243 -0
- onedal/tests/test_common.py +41 -0
- onedal/tests/utils/_dataframes_support.py +168 -0
- onedal/tests/utils/_device_selection.py +107 -0
- onedal/utils/__init__.py +49 -0
- onedal/utils/_array_api.py +91 -0
- onedal/utils/validation.py +432 -0
- scikit_learn_intelex-2025.0.0.dist-info/LICENSE.txt +202 -0
- scikit_learn_intelex-2025.0.0.dist-info/METADATA +231 -0
- scikit_learn_intelex-2025.0.0.dist-info/RECORD +278 -0
- scikit_learn_intelex-2025.0.0.dist-info/WHEEL +5 -0
- scikit_learn_intelex-2025.0.0.dist-info/top_level.txt +3 -0
- sklearnex/__init__.py +65 -0
- sklearnex/__main__.py +58 -0
- sklearnex/_config.py +98 -0
- sklearnex/_device_offload.py +121 -0
- sklearnex/_utils.py +109 -0
- sklearnex/basic_statistics/__init__.py +20 -0
- sklearnex/basic_statistics/basic_statistics.py +140 -0
- sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
- sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +384 -0
- sklearnex/cluster/__init__.py +20 -0
- sklearnex/cluster/dbscan.py +192 -0
- sklearnex/cluster/k_means.py +383 -0
- sklearnex/cluster/tests/test_dbscan.py +38 -0
- sklearnex/cluster/tests/test_kmeans.py +153 -0
- sklearnex/conftest.py +73 -0
- sklearnex/covariance/__init__.py +19 -0
- sklearnex/covariance/incremental_covariance.py +368 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +226 -0
- sklearnex/decomposition/__init__.py +19 -0
- sklearnex/decomposition/pca.py +414 -0
- sklearnex/decomposition/tests/test_pca.py +58 -0
- sklearnex/dispatcher.py +543 -0
- sklearnex/doc/third-party-programs.txt +424 -0
- sklearnex/ensemble/__init__.py +29 -0
- sklearnex/ensemble/_forest.py +2016 -0
- sklearnex/ensemble/tests/test_forest.py +120 -0
- sklearnex/glob/__main__.py +72 -0
- sklearnex/glob/dispatcher.py +101 -0
- sklearnex/linear_model/__init__.py +32 -0
- sklearnex/linear_model/coordinate_descent.py +30 -0
- sklearnex/linear_model/incremental_linear.py +463 -0
- sklearnex/linear_model/incremental_ridge.py +418 -0
- sklearnex/linear_model/linear.py +302 -0
- sklearnex/linear_model/logistic_path.py +17 -0
- sklearnex/linear_model/logistic_regression.py +403 -0
- sklearnex/linear_model/ridge.py +24 -0
- sklearnex/linear_model/tests/test_incremental_linear.py +203 -0
- sklearnex/linear_model/tests/test_incremental_ridge.py +153 -0
- sklearnex/linear_model/tests/test_linear.py +142 -0
- sklearnex/linear_model/tests/test_logreg.py +134 -0
- sklearnex/manifold/__init__.py +19 -0
- sklearnex/manifold/t_sne.py +21 -0
- sklearnex/manifold/tests/test_tsne.py +26 -0
- sklearnex/metrics/__init__.py +23 -0
- sklearnex/metrics/pairwise.py +22 -0
- sklearnex/metrics/ranking.py +20 -0
- sklearnex/metrics/tests/test_metrics.py +39 -0
- sklearnex/model_selection/__init__.py +21 -0
- sklearnex/model_selection/split.py +22 -0
- sklearnex/model_selection/tests/test_model_selection.py +34 -0
- sklearnex/neighbors/__init__.py +27 -0
- sklearnex/neighbors/_lof.py +231 -0
- sklearnex/neighbors/common.py +310 -0
- sklearnex/neighbors/knn_classification.py +226 -0
- sklearnex/neighbors/knn_regression.py +203 -0
- sklearnex/neighbors/knn_unsupervised.py +170 -0
- sklearnex/neighbors/tests/test_neighbors.py +80 -0
- sklearnex/preview/__init__.py +17 -0
- sklearnex/preview/covariance/__init__.py +19 -0
- sklearnex/preview/covariance/covariance.py +133 -0
- sklearnex/preview/covariance/tests/test_covariance.py +66 -0
- sklearnex/preview/decomposition/__init__.py +19 -0
- sklearnex/preview/decomposition/incremental_pca.py +228 -0
- sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
- sklearnex/preview/linear_model/__init__.py +19 -0
- sklearnex/preview/linear_model/ridge.py +419 -0
- sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
- sklearnex/spmd/__init__.py +25 -0
- sklearnex/spmd/basic_statistics/__init__.py +20 -0
- sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
- sklearnex/spmd/basic_statistics/incremental_basic_statistics.py +30 -0
- sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
- sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py +307 -0
- sklearnex/spmd/cluster/__init__.py +30 -0
- sklearnex/spmd/cluster/dbscan.py +50 -0
- sklearnex/spmd/cluster/kmeans.py +21 -0
- sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
- sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
- sklearnex/spmd/covariance/__init__.py +20 -0
- sklearnex/spmd/covariance/covariance.py +21 -0
- sklearnex/spmd/covariance/incremental_covariance.py +37 -0
- sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
- sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py +184 -0
- sklearnex/spmd/decomposition/__init__.py +20 -0
- sklearnex/spmd/decomposition/incremental_pca.py +30 -0
- sklearnex/spmd/decomposition/pca.py +21 -0
- sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py +269 -0
- sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
- sklearnex/spmd/ensemble/__init__.py +19 -0
- sklearnex/spmd/ensemble/forest.py +71 -0
- sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
- sklearnex/spmd/linear_model/__init__.py +21 -0
- sklearnex/spmd/linear_model/incremental_linear_model.py +35 -0
- sklearnex/spmd/linear_model/linear_model.py +21 -0
- sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py +329 -0
- sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
- sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +166 -0
- sklearnex/spmd/neighbors/__init__.py +19 -0
- sklearnex/spmd/neighbors/neighbors.py +25 -0
- sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
- sklearnex/svm/__init__.py +29 -0
- sklearnex/svm/_common.py +328 -0
- sklearnex/svm/nusvc.py +332 -0
- sklearnex/svm/nusvr.py +148 -0
- sklearnex/svm/svc.py +360 -0
- sklearnex/svm/svr.py +149 -0
- sklearnex/svm/tests/test_svm.py +93 -0
- sklearnex/tests/_utils.py +328 -0
- sklearnex/tests/_utils_spmd.py +198 -0
- sklearnex/tests/test_common.py +54 -0
- sklearnex/tests/test_config.py +43 -0
- sklearnex/tests/test_memory_usage.py +291 -0
- sklearnex/tests/test_monkeypatch.py +276 -0
- sklearnex/tests/test_n_jobs_support.py +103 -0
- sklearnex/tests/test_parallel.py +48 -0
- sklearnex/tests/test_patching.py +385 -0
- sklearnex/tests/test_run_to_run_stability.py +296 -0
- sklearnex/utils/__init__.py +19 -0
- sklearnex/utils/_array_api.py +82 -0
- sklearnex/utils/parallel.py +59 -0
- sklearnex/utils/tests/test_finite.py +89 -0
- sklearnex/utils/validation.py +17 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2024 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
from functools import partial
|
|
18
|
+
from inspect import getattr_static, isclass, signature
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
from scipy import sparse as sp
|
|
22
|
+
from sklearn import clone
|
|
23
|
+
from sklearn.base import (
|
|
24
|
+
BaseEstimator,
|
|
25
|
+
ClassifierMixin,
|
|
26
|
+
ClusterMixin,
|
|
27
|
+
OutlierMixin,
|
|
28
|
+
RegressorMixin,
|
|
29
|
+
TransformerMixin,
|
|
30
|
+
)
|
|
31
|
+
from sklearn.datasets import load_diabetes, load_iris
|
|
32
|
+
from sklearn.neighbors._base import KNeighborsMixin
|
|
33
|
+
|
|
34
|
+
from onedal.tests.utils._dataframes_support import _convert_to_dataframe
|
|
35
|
+
from sklearnex import get_patch_map, patch_sklearn, sklearn_is_patched, unpatch_sklearn
|
|
36
|
+
from sklearnex.linear_model import LogisticRegression
|
|
37
|
+
from sklearnex.neighbors import (
|
|
38
|
+
KNeighborsClassifier,
|
|
39
|
+
KNeighborsRegressor,
|
|
40
|
+
LocalOutlierFactor,
|
|
41
|
+
NearestNeighbors,
|
|
42
|
+
)
|
|
43
|
+
from sklearnex.svm import SVC, NuSVC
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _load_all_models(with_sklearnex=True, estimator=True):
|
|
47
|
+
"""Convert sklearnex patch_map into a dictionary of estimators or functions
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
with_sklearnex: bool (default=True)
|
|
52
|
+
Discover estimators and methods with sklearnex patching enabled (True)
|
|
53
|
+
or disabled (False) from the sklearnex patch_map
|
|
54
|
+
|
|
55
|
+
estimator: bool (default=True)
|
|
56
|
+
yield estimators (True) or functions (False)
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
dict: {name:estimator}
|
|
61
|
+
estimator is a class or function from sklearn or sklearnex
|
|
62
|
+
"""
|
|
63
|
+
# insure that patch state is correct as dictated by patch_sklearn boolean
|
|
64
|
+
# and return it to the previous state no matter what occurs.
|
|
65
|
+
already_patched_map = sklearn_is_patched(return_map=True)
|
|
66
|
+
already_patched = any(already_patched_map.values())
|
|
67
|
+
try:
|
|
68
|
+
if with_sklearnex:
|
|
69
|
+
patch_sklearn()
|
|
70
|
+
elif already_patched:
|
|
71
|
+
unpatch_sklearn()
|
|
72
|
+
|
|
73
|
+
models = {}
|
|
74
|
+
for patch_infos in get_patch_map().values():
|
|
75
|
+
candidate = getattr(patch_infos[0][0][0], patch_infos[0][0][1], None)
|
|
76
|
+
if candidate is not None and isclass(candidate) == estimator:
|
|
77
|
+
if not estimator or issubclass(candidate, BaseEstimator):
|
|
78
|
+
models[patch_infos[0][0][1]] = candidate
|
|
79
|
+
finally:
|
|
80
|
+
if with_sklearnex:
|
|
81
|
+
unpatch_sklearn()
|
|
82
|
+
# both branches are now in an unpatched state, repatch as necessary
|
|
83
|
+
if already_patched:
|
|
84
|
+
patch_sklearn(name=[i for i in already_patched_map if already_patched_map[i]])
|
|
85
|
+
|
|
86
|
+
return models
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
PATCHED_MODELS = _load_all_models(with_sklearnex=True)
|
|
90
|
+
UNPATCHED_MODELS = _load_all_models(with_sklearnex=False)
|
|
91
|
+
|
|
92
|
+
PATCHED_FUNCTIONS = _load_all_models(with_sklearnex=True, estimator=False)
|
|
93
|
+
UNPATCHED_FUNCTIONS = _load_all_models(with_sklearnex=False, estimator=False)
|
|
94
|
+
|
|
95
|
+
mixin_map = [
|
|
96
|
+
[
|
|
97
|
+
ClassifierMixin,
|
|
98
|
+
["decision_function", "predict", "predict_proba", "predict_log_proba", "score"],
|
|
99
|
+
"classification",
|
|
100
|
+
],
|
|
101
|
+
[RegressorMixin, ["predict", "score"], "regression"],
|
|
102
|
+
[ClusterMixin, ["fit_predict"], "classification"],
|
|
103
|
+
[TransformerMixin, ["fit_transform", "transform", "score"], "classification"],
|
|
104
|
+
[OutlierMixin, ["fit_predict", "predict"], "classification"],
|
|
105
|
+
[KNeighborsMixin, ["kneighbors"], None],
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class _sklearn_clone_dict(dict):
|
|
110
|
+
"""Special dict type for returning state-free sklearn/sklearnex estimators
|
|
111
|
+
with the same parameters"""
|
|
112
|
+
|
|
113
|
+
def __getitem__(self, key):
|
|
114
|
+
return clone(super().__getitem__(key))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Special dictionary of sklearnex estimators which must be specifically tested, this
|
|
118
|
+
# could be because of supported non-default parameters, blocked support via sklearn's
|
|
119
|
+
# 'available_if' decorator, or not being a native sklearn estimator (i.e. those not in
|
|
120
|
+
# the default PATCHED_MODELS dictionary)
|
|
121
|
+
SPECIAL_INSTANCES = _sklearn_clone_dict(
|
|
122
|
+
{
|
|
123
|
+
str(i): i
|
|
124
|
+
for i in [
|
|
125
|
+
LocalOutlierFactor(novelty=True),
|
|
126
|
+
SVC(probability=True),
|
|
127
|
+
NuSVC(probability=True),
|
|
128
|
+
KNeighborsClassifier(algorithm="brute"),
|
|
129
|
+
KNeighborsRegressor(algorithm="brute"),
|
|
130
|
+
NearestNeighbors(algorithm="brute"),
|
|
131
|
+
LogisticRegression(solver="newton-cg"),
|
|
132
|
+
]
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def gen_models_info(algorithms, required_inputs=["X", "y"]):
|
|
138
|
+
"""Generate estimator-attribute pairs for pytest test collection.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
----------
|
|
142
|
+
algorithms : iterable (list, tuple, 1D array-like object)
|
|
143
|
+
Iterable of valid sklearnex estimators or keys from PATCHED_MODELS
|
|
144
|
+
|
|
145
|
+
required_inputs : list, tuple of strings or None
|
|
146
|
+
list of required args/kwargs for callable attribute (only non-private,
|
|
147
|
+
non-BaseEstimator attributes). Only one must be present, None
|
|
148
|
+
signifies taking all non-private attribues, callable or not.
|
|
149
|
+
|
|
150
|
+
Returns
|
|
151
|
+
-------
|
|
152
|
+
list of 2-element tuples: (estimator, string)
|
|
153
|
+
Returns a list of valid methods or attributes without "fit"
|
|
154
|
+
"""
|
|
155
|
+
output = []
|
|
156
|
+
for estimator in algorithms:
|
|
157
|
+
|
|
158
|
+
if estimator in PATCHED_MODELS:
|
|
159
|
+
est = PATCHED_MODELS[estimator]
|
|
160
|
+
elif isinstance(algorithms[estimator], BaseEstimator):
|
|
161
|
+
est = algorithms[estimator].__class__
|
|
162
|
+
else:
|
|
163
|
+
raise KeyError(f"Unrecognized sklearnex estimator: {estimator}")
|
|
164
|
+
|
|
165
|
+
# remove BaseEstimator methods (get_params, set_params)
|
|
166
|
+
candidates = set(dir(est)) - set(dir(BaseEstimator))
|
|
167
|
+
# remove private methods
|
|
168
|
+
candidates = set([attr for attr in candidates if not attr.startswith("_")])
|
|
169
|
+
# required to enable other methods
|
|
170
|
+
candidates = candidates - {"fit"}
|
|
171
|
+
|
|
172
|
+
# allow only callable methods with any of the required inputs
|
|
173
|
+
if required_inputs:
|
|
174
|
+
methods = []
|
|
175
|
+
for attr in candidates:
|
|
176
|
+
attribute = getattr_static(est, attr)
|
|
177
|
+
if callable(attribute):
|
|
178
|
+
params = signature(attribute).parameters
|
|
179
|
+
if any([inp in params for inp in required_inputs]):
|
|
180
|
+
methods += [attr]
|
|
181
|
+
else:
|
|
182
|
+
methods = candidates
|
|
183
|
+
|
|
184
|
+
output += (
|
|
185
|
+
[(estimator, method) for method in methods]
|
|
186
|
+
if methods
|
|
187
|
+
else [(estimator, None)]
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# In the case that no methods are available, set method to None.
|
|
191
|
+
# This will allow estimators without mixins to still test the fit
|
|
192
|
+
# method in various tests.
|
|
193
|
+
return output
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def call_method(estimator, method, X, y, **kwargs):
|
|
197
|
+
"""Generalized interface to call most sklearn estimator methods
|
|
198
|
+
|
|
199
|
+
Parameters
|
|
200
|
+
----------
|
|
201
|
+
estimator : sklearn or sklearnex estimator instance
|
|
202
|
+
|
|
203
|
+
method: string
|
|
204
|
+
Valid callable method to estimator
|
|
205
|
+
|
|
206
|
+
X: array-like
|
|
207
|
+
data
|
|
208
|
+
|
|
209
|
+
y: array-like (for 'score', 'partial-fit', and 'path')
|
|
210
|
+
X-dependent data
|
|
211
|
+
|
|
212
|
+
**kwargs: keyword dict
|
|
213
|
+
keyword arguments to estimator.method
|
|
214
|
+
|
|
215
|
+
Returns
|
|
216
|
+
-------
|
|
217
|
+
return value from estimator.method
|
|
218
|
+
"""
|
|
219
|
+
# useful for repository wide testing
|
|
220
|
+
if method == "inverse_transform":
|
|
221
|
+
# PCA's inverse_transform takes (n_samples, n_components)
|
|
222
|
+
data = (
|
|
223
|
+
(X[:, : estimator.n_components_],)
|
|
224
|
+
if X.shape[1] != estimator.n_components_
|
|
225
|
+
else (X,)
|
|
226
|
+
)
|
|
227
|
+
elif method not in ["score", "partial_fit", "path"]:
|
|
228
|
+
data = (X,)
|
|
229
|
+
else:
|
|
230
|
+
data = (X, y)
|
|
231
|
+
return getattr(estimator, method)(*data, **kwargs)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _gen_dataset_type(est):
|
|
235
|
+
# est should be an estimator or estimator class
|
|
236
|
+
# dataset initialized to classification, but will be swapped
|
|
237
|
+
# for other types as necessary. Private method.
|
|
238
|
+
dataset = "classification"
|
|
239
|
+
estimator = est.__class__ if isinstance(est, BaseEstimator) else est
|
|
240
|
+
|
|
241
|
+
for mixin, _, data in mixin_map:
|
|
242
|
+
if issubclass(estimator, mixin) and data is not None:
|
|
243
|
+
dataset = data
|
|
244
|
+
return dataset
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
_dataset_dict = {
|
|
248
|
+
"classification": [partial(load_iris, return_X_y=True)],
|
|
249
|
+
"regression": [partial(load_diabetes, return_X_y=True)],
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def gen_dataset(
|
|
254
|
+
est,
|
|
255
|
+
datasets=_dataset_dict,
|
|
256
|
+
sparse=False,
|
|
257
|
+
queue=None,
|
|
258
|
+
target_df=None,
|
|
259
|
+
dtype=None,
|
|
260
|
+
):
|
|
261
|
+
"""Generate dataset for pytest testing.
|
|
262
|
+
|
|
263
|
+
Parameters
|
|
264
|
+
----------
|
|
265
|
+
est : sklearn or sklearnex estimator class
|
|
266
|
+
Must inherit an sklearn Mixin or sklearn's BaseEstimator
|
|
267
|
+
|
|
268
|
+
dataset: dataset dict
|
|
269
|
+
Dictionary with keys "classification" and/or "regression"
|
|
270
|
+
Value must be a list of object which yield X, y array
|
|
271
|
+
objects when called, ideally using a lambda or
|
|
272
|
+
functools.partial.
|
|
273
|
+
|
|
274
|
+
sparse: bool (default False)
|
|
275
|
+
Convert X data to a scipy.sparse csr_matrix format.
|
|
276
|
+
|
|
277
|
+
queue: SYCL queue or None
|
|
278
|
+
Queue necessary for device offloading following the
|
|
279
|
+
SYCL 2020 standard, usually generated by dpctl.
|
|
280
|
+
|
|
281
|
+
target_df: string or None
|
|
282
|
+
dataframe type for returned dataset, as dictated by
|
|
283
|
+
onedal's _convert_to_dataframe.
|
|
284
|
+
|
|
285
|
+
dtype: numpy dtype or None
|
|
286
|
+
target datatype for returned datasets (see DTYPES).
|
|
287
|
+
|
|
288
|
+
Returns
|
|
289
|
+
-------
|
|
290
|
+
list of 2-element list X,y: (array-like, array-like)
|
|
291
|
+
list of datasets for analysis
|
|
292
|
+
"""
|
|
293
|
+
dataset_type = _gen_dataset_type(est)
|
|
294
|
+
output = []
|
|
295
|
+
# load data
|
|
296
|
+
flag = dtype is None
|
|
297
|
+
|
|
298
|
+
for func in datasets[dataset_type]:
|
|
299
|
+
X, y = func()
|
|
300
|
+
if flag:
|
|
301
|
+
dtype = X.dtype if hasattr(X, "dtype") else np.float64
|
|
302
|
+
|
|
303
|
+
if sparse:
|
|
304
|
+
X = sp.csr_matrix(X)
|
|
305
|
+
else:
|
|
306
|
+
X = _convert_to_dataframe(
|
|
307
|
+
X, sycl_queue=queue, target_df=target_df, dtype=dtype
|
|
308
|
+
)
|
|
309
|
+
y = _convert_to_dataframe(
|
|
310
|
+
y, sycl_queue=queue, target_df=target_df, dtype=dtype
|
|
311
|
+
)
|
|
312
|
+
output += [[X, y]]
|
|
313
|
+
return output
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
DTYPES = [
|
|
317
|
+
np.int8,
|
|
318
|
+
np.int16,
|
|
319
|
+
np.int32,
|
|
320
|
+
np.int64,
|
|
321
|
+
np.float16,
|
|
322
|
+
np.float32,
|
|
323
|
+
np.float64,
|
|
324
|
+
np.uint8,
|
|
325
|
+
np.uint16,
|
|
326
|
+
np.uint32,
|
|
327
|
+
np.uint64,
|
|
328
|
+
]
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2024 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
from numpy.testing import assert_allclose
|
|
19
|
+
from sklearn.datasets import make_blobs, make_classification, make_regression
|
|
20
|
+
from sklearn.model_selection import train_test_split
|
|
21
|
+
|
|
22
|
+
from onedal.tests.utils._dataframes_support import _as_numpy
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
import dpctl
|
|
26
|
+
from dpctl import SyclQueue
|
|
27
|
+
from mpi4py import MPI
|
|
28
|
+
|
|
29
|
+
mpi_libs_available = True
|
|
30
|
+
gpu_is_available = dpctl.has_gpu_devices()
|
|
31
|
+
except (ImportError, ModuleNotFoundError):
|
|
32
|
+
mpi_libs_available = False
|
|
33
|
+
|
|
34
|
+
_mpi_libs_and_gpu_available = mpi_libs_available and gpu_is_available
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _get_local_tensor(full_data):
|
|
38
|
+
"""Splits data across ranks.
|
|
39
|
+
|
|
40
|
+
Called on each rank to extract the subset of data assigned to that rank.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
full_data (numpy or dpctl array): The entire set of data
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
local_data (numpy or dpctl array): The subset of data used by the rank
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
# create sycl queue and gather communicator details
|
|
50
|
+
q = SyclQueue("gpu")
|
|
51
|
+
comm = MPI.COMM_WORLD
|
|
52
|
+
rank = comm.Get_rank()
|
|
53
|
+
size = comm.Get_size()
|
|
54
|
+
|
|
55
|
+
# divide data across ranks and move to dpt tensor
|
|
56
|
+
data_rows = full_data.shape[0]
|
|
57
|
+
local_start = rank * data_rows // size
|
|
58
|
+
local_end = (1 + rank) * data_rows // size
|
|
59
|
+
local_data = full_data[local_start:local_end]
|
|
60
|
+
|
|
61
|
+
return local_data
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _generate_regression_data(n_samples, n_features, dtype=np.float64, random_state=42):
|
|
65
|
+
# Generates regression data and divides between train and test
|
|
66
|
+
X, y = make_regression(
|
|
67
|
+
n_samples=n_samples, n_features=n_features, random_state=random_state
|
|
68
|
+
)
|
|
69
|
+
X = X.astype(dtype)
|
|
70
|
+
y = y.astype(dtype)
|
|
71
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=random_state)
|
|
72
|
+
return X_train, X_test, y_train, y_test
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _generate_classification_data(
|
|
76
|
+
n_samples, n_features, n_classes=2, dtype=np.float64, random_state=42
|
|
77
|
+
):
|
|
78
|
+
# Generates classification data and divides between train and test
|
|
79
|
+
X, y = make_classification(
|
|
80
|
+
n_samples=n_samples,
|
|
81
|
+
n_features=n_features,
|
|
82
|
+
n_classes=n_classes,
|
|
83
|
+
n_informative=int(0.5 * n_classes + 1),
|
|
84
|
+
random_state=random_state,
|
|
85
|
+
)
|
|
86
|
+
X = X.astype(dtype)
|
|
87
|
+
y = y.astype(dtype)
|
|
88
|
+
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=random_state)
|
|
89
|
+
return X_train, X_test, y_train, y_test
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _generate_statistic_data(
|
|
93
|
+
n_samples, n_features=None, dtype=np.float64, random_state=42
|
|
94
|
+
):
|
|
95
|
+
# Generates statistical data
|
|
96
|
+
gen = np.random.default_rng(random_state)
|
|
97
|
+
data = gen.uniform(
|
|
98
|
+
low=-0.3,
|
|
99
|
+
high=+0.7,
|
|
100
|
+
size=(n_samples, n_features) if n_features is not None else (n_samples,),
|
|
101
|
+
).astype(dtype)
|
|
102
|
+
return data
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _generate_clustering_data(
|
|
106
|
+
n_samples, n_features, centers=None, dtype=np.float64, random_state=42
|
|
107
|
+
):
|
|
108
|
+
# Generates clustering data and divides between train and test
|
|
109
|
+
X, _ = make_blobs(
|
|
110
|
+
n_samples=n_samples,
|
|
111
|
+
centers=centers,
|
|
112
|
+
n_features=n_features,
|
|
113
|
+
random_state=random_state,
|
|
114
|
+
)
|
|
115
|
+
X = X.astype(dtype)
|
|
116
|
+
X_train, X_test = train_test_split(X, random_state=random_state)
|
|
117
|
+
return X_train, X_test
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _spmd_assert_allclose(spmd_result, batch_result, **kwargs):
|
|
121
|
+
"""Calls assert_allclose on spmd and batch results.
|
|
122
|
+
|
|
123
|
+
Called on each rank to compare the spmd result specific to that rank and
|
|
124
|
+
subset of batch result that corresponds to that rank.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
spmd_result (numpy or dpctl array): The result for the subset of data on the rank the function is called from, computed by the spmd estimator
|
|
128
|
+
batch_result (numpy array): The result for all data, computed by the batch estimator
|
|
129
|
+
|
|
130
|
+
Raises:
|
|
131
|
+
AssertionError: If all results are not adequately close.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
# extract chunk from batch result to match with local spmd result
|
|
135
|
+
local_batch_result = _get_local_tensor(batch_result)
|
|
136
|
+
|
|
137
|
+
assert_allclose(_as_numpy(spmd_result), _as_numpy(local_batch_result), **kwargs)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _assert_unordered_allclose(spmd_result, batch_result, localize=False, **kwargs):
|
|
141
|
+
"""Checks if rows in spmd and batch results are aligned, even if not in the same order.
|
|
142
|
+
|
|
143
|
+
Called to verify correct unordered results are present. Useful to check KMeans centers
|
|
144
|
+
or KNN neighbors, where order does not matter. Sorts inputs to handle unordering. Also
|
|
145
|
+
capable of handling localization.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
spmd_result (numpy or dpctl array): Result computed by the spmd estimator
|
|
149
|
+
batch_result (numpy array): Result computed by batch estimator
|
|
150
|
+
localize (bool): Whether of not spmd result is specific to the rank, in which case batch result needs to be localized
|
|
151
|
+
|
|
152
|
+
Raises:
|
|
153
|
+
AssertionError: If results do not match.
|
|
154
|
+
"""
|
|
155
|
+
np_spmd_result = _as_numpy(spmd_result)
|
|
156
|
+
|
|
157
|
+
sorted_spmd_result = np_spmd_result[
|
|
158
|
+
np.argsort(np.linalg.norm(np_spmd_result, axis=1))
|
|
159
|
+
]
|
|
160
|
+
if localize:
|
|
161
|
+
local_batch_result = _get_local_tensor(batch_result)
|
|
162
|
+
sorted_batch_result = local_batch_result[
|
|
163
|
+
np.argsort(np.linalg.norm(local_batch_result, axis=1))
|
|
164
|
+
]
|
|
165
|
+
else:
|
|
166
|
+
sorted_batch_result = batch_result[
|
|
167
|
+
np.argsort(np.linalg.norm(batch_result, axis=1))
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
assert_allclose(sorted_spmd_result, sorted_batch_result, **kwargs)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _assert_kmeans_labels_allclose(
|
|
174
|
+
spmd_labels, batch_labels, spmd_centers, batch_centers, **kwargs
|
|
175
|
+
):
|
|
176
|
+
"""Checks if labels for spmd and batch results are aligned, even cluster indices don't match.
|
|
177
|
+
|
|
178
|
+
Called to verify labels are assigned the same way on spmd and batch. Uses raw labels (which
|
|
179
|
+
may not match) to identify cluster center and ensure results match.
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
spmd_labels (numpy or dpctl array): The labels for the subset of data on the rank the function is called from, computed by the spmd estimator
|
|
183
|
+
batch_labels (numpy array): The labels for all data, computed by the batch estimator
|
|
184
|
+
spmd_centers (numpy or dpctl array): Centers computed by the spmd estimator
|
|
185
|
+
batch_centers (numpy array): Centers computed by batch estimator
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
AssertionError: If clusters are not correctly assigned.
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
np_spmd_labels = _as_numpy(spmd_labels)
|
|
192
|
+
np_spmd_centers = _as_numpy(spmd_centers)
|
|
193
|
+
local_batch_labels = _get_local_tensor(batch_labels)
|
|
194
|
+
assert_allclose(
|
|
195
|
+
np_spmd_centers[np_spmd_labels],
|
|
196
|
+
batch_centers[local_batch_labels],
|
|
197
|
+
**kwargs,
|
|
198
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2024 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
from glob import glob
|
|
19
|
+
|
|
20
|
+
import pytest
|
|
21
|
+
|
|
22
|
+
ALLOWED_LOCATIONS = [
|
|
23
|
+
"_config.py",
|
|
24
|
+
"_device_offload.py",
|
|
25
|
+
"test",
|
|
26
|
+
"svc.py",
|
|
27
|
+
"svm" + os.sep + "_common.py",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_target_offload_ban():
|
|
32
|
+
"""This test blocks the use of target_offload in
|
|
33
|
+
in sklearnex files. Offloading computation to devices
|
|
34
|
+
via target_offload should only occur externally, and not
|
|
35
|
+
within the architecture of the sklearnex classes. This
|
|
36
|
+
is for clarity, traceability and maintainability.
|
|
37
|
+
"""
|
|
38
|
+
from sklearnex import __file__ as loc
|
|
39
|
+
|
|
40
|
+
path = loc.replace("__init__.py", "")
|
|
41
|
+
files = [y for x in os.walk(path) for y in glob(os.path.join(x[0], "*.py"))]
|
|
42
|
+
|
|
43
|
+
output = []
|
|
44
|
+
|
|
45
|
+
for f in files:
|
|
46
|
+
if open(f, "r").read().find("target_offload") != -1:
|
|
47
|
+
output += [f.replace(path, "sklearnex" + os.sep)]
|
|
48
|
+
|
|
49
|
+
# remove this file from the list
|
|
50
|
+
for allowed in ALLOWED_LOCATIONS:
|
|
51
|
+
output = [i for i in output if allowed not in i]
|
|
52
|
+
|
|
53
|
+
output = "\n".join(output)
|
|
54
|
+
assert output == "", f"sklearn versioning is occuring in: \n{output}"
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2021 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import sklearn
|
|
18
|
+
|
|
19
|
+
import onedal
|
|
20
|
+
import sklearnex
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_get_config_contains_sklearn_params():
|
|
24
|
+
skex_config = sklearnex.get_config()
|
|
25
|
+
sk_config = sklearn.get_config()
|
|
26
|
+
|
|
27
|
+
assert all(value in skex_config.keys() for value in sk_config.keys())
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_set_config_works():
|
|
31
|
+
default_config = sklearnex.get_config()
|
|
32
|
+
sklearnex.set_config(
|
|
33
|
+
assume_finite=True, target_offload="cpu:0", allow_fallback_to_host=True
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
config = sklearnex.get_config()
|
|
37
|
+
onedal_config = onedal._config._get_config()
|
|
38
|
+
assert config["target_offload"] == "cpu:0"
|
|
39
|
+
assert config["allow_fallback_to_host"]
|
|
40
|
+
assert config["assume_finite"]
|
|
41
|
+
assert onedal_config["target_offload"] == "cpu:0"
|
|
42
|
+
assert onedal_config["allow_fallback_to_host"]
|
|
43
|
+
sklearnex.set_config(**default_config)
|