From c14838b0777ebef7a16f6c5826d4180486eedb12 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 00:55:04 -0700 Subject: [PATCH 01/37] add test_all_estimators_covered --- sklearnex/tests/test_common.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 311c1cd285..e7228ab46c 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -15,9 +15,14 @@ # ============================================================================== import os +import pathlib +import pkgutil from glob import glob import pytest +from sklearn.utils import all_estimators + +from sklearnex.tests.utils import PATCHED_MODELS, SPECIAL_INSTANCES ALLOWED_LOCATIONS = [ "_config.py", @@ -52,3 +57,22 @@ def test_target_offload_ban(): output = "\n".join(output) assert output == "", f"sklearn versioning is occuring in: \n{output}" + + +def _sklearnex_walk(*args, **kwargs): + """this replaces checks on pkgutils to look in sklearnex + folders specifically""" + if "prefix" in kwargs and kwargs["prefix"] == "sklearn.": + kwargs["prefix"] = "sklearnex." + if "root" in kwargs: + # force root to sklearnex + root = [str(Path(__file__).parent.parent)] + return pkgutil.walk_packages(*args, **kwargs) + + +def test_all_estimators_covered(monkeypatch): + monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk) + estimators = all_estimators() + print(estimators) + for i in estimators: + assert i in PATCHED_MODELS From 2d7a988256a3871760e0f1a7f49d7c1a9ca6aea7 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 00:57:11 -0700 Subject: [PATCH 02/37] forgotten import --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index e7228ab46c..8847659555 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -66,7 +66,7 @@ def _sklearnex_walk(*args, **kwargs): kwargs["prefix"] = "sklearnex." if "root" in kwargs: # force root to sklearnex - root = [str(Path(__file__).parent.parent)] + root = [str(pathlib.Path(__file__).parent.parent)] return pkgutil.walk_packages(*args, **kwargs) From 2621aa9dad24d1639d13265fa035932b01e26416 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 01:07:05 -0700 Subject: [PATCH 03/37] forgotten underscore --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 8847659555..7a1556289f 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -22,7 +22,7 @@ import pytest from sklearn.utils import all_estimators -from sklearnex.tests.utils import PATCHED_MODELS, SPECIAL_INSTANCES +from sklearnex.tests._utils import PATCHED_MODELS, SPECIAL_INSTANCES ALLOWED_LOCATIONS = [ "_config.py", From b97a128b1b996e33bb5b4ba08ab2d9514f0374b3 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 01:27:20 -0700 Subject: [PATCH 04/37] remove recursion --- sklearnex/tests/test_common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 7a1556289f..273baf7aad 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -17,6 +17,7 @@ import os import pathlib import pkgutil +from pkgutil import walk_packages as walk_packages_orig from glob import glob import pytest @@ -67,7 +68,7 @@ def _sklearnex_walk(*args, **kwargs): if "root" in kwargs: # force root to sklearnex root = [str(pathlib.Path(__file__).parent.parent)] - return pkgutil.walk_packages(*args, **kwargs) + return walk_packages_orig(*args, **kwargs) def test_all_estimators_covered(monkeypatch): From 978b435bdebb0e3cb105e65faf3a33b4ad2df3e6 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 01:53:31 -0700 Subject: [PATCH 05/37] root -> path --- sklearnex/tests/test_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 273baf7aad..3412db52d6 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -65,9 +65,9 @@ def _sklearnex_walk(*args, **kwargs): folders specifically""" if "prefix" in kwargs and kwargs["prefix"] == "sklearn.": kwargs["prefix"] = "sklearnex." - if "root" in kwargs: + if "path" in kwargs: # force root to sklearnex - root = [str(pathlib.Path(__file__).parent.parent)] + path = [str(pathlib.Path(__file__).parent.parent)] return walk_packages_orig(*args, **kwargs) From b670841af7b2aa5b324f9903ecf83212e746d3b9 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 02:14:57 -0700 Subject: [PATCH 06/37] forgot to change kwargs --- sklearnex/tests/test_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 3412db52d6..db0dac99ae 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -17,8 +17,8 @@ import os import pathlib import pkgutil -from pkgutil import walk_packages as walk_packages_orig from glob import glob +from pkgutil import walk_packages as walk_packages_orig import pytest from sklearn.utils import all_estimators @@ -67,7 +67,7 @@ def _sklearnex_walk(*args, **kwargs): kwargs["prefix"] = "sklearnex." if "path" in kwargs: # force root to sklearnex - path = [str(pathlib.Path(__file__).parent.parent)] + kwargs["path"] = [str(pathlib.Path(__file__).parent.parent)] return walk_packages_orig(*args, **kwargs) From c01714dc3907f3478e2dbfb8838c522c78f4bfbb Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 03:15:05 -0700 Subject: [PATCH 07/37] first attempt --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index db0dac99ae..93e27fbcb1 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -76,4 +76,4 @@ def test_all_estimators_covered(monkeypatch): estimators = all_estimators() print(estimators) for i in estimators: - assert i in PATCHED_MODELS + assert i in estimators or any([issubclass(est, i) for est in PATCHED_MODELS.values()]), f"{i} not included" From d84416a66b82dc4068ecd1315652bf809256093f Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 03:34:25 -0700 Subject: [PATCH 08/37] wrong if statement --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 93e27fbcb1..d8e237d0c7 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -76,4 +76,4 @@ def test_all_estimators_covered(monkeypatch): estimators = all_estimators() print(estimators) for i in estimators: - assert i in estimators or any([issubclass(est, i) for est in PATCHED_MODELS.values()]), f"{i} not included" + assert i in PATCHED_MODELS or any([issubclass(est, i) for est in PATCHED_MODELS.values()]), f"{i} not included" From 365f53a53c47125b5c48a90b08222ce0d83f88ab Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 03:57:59 -0700 Subject: [PATCH 09/37] add underscores --- sklearnex/cluster/dbscan.py | 12 +++---- sklearnex/cluster/k_means.py | 26 +++++++------- .../covariance/incremental_covariance.py | 12 +++---- sklearnex/neighbors/knn_classification.py | 28 +++++++-------- sklearnex/neighbors/knn_regression.py | 25 +++++++------ sklearnex/neighbors/knn_unsupervised.py | 26 +++++++------- sklearnex/preview/covariance/covariance.py | 22 ++++++------ .../preview/decomposition/incremental_pca.py | 22 ++++++------ sklearnex/preview/linear_model/ridge.py | 20 +++++------ sklearnex/svm/nusvc.py | 36 +++++++++---------- sklearnex/svm/nusvr.py | 20 +++++------ sklearnex/svm/svc.py | 36 +++++++++---------- sklearnex/svm/svr.py | 20 +++++------ 13 files changed, 152 insertions(+), 153 deletions(-) diff --git a/sklearnex/cluster/dbscan.py b/sklearnex/cluster/dbscan.py index f8d080cfbe..52b0fead78 100755 --- a/sklearnex/cluster/dbscan.py +++ b/sklearnex/cluster/dbscan.py @@ -18,7 +18,7 @@ from abc import ABC from scipy import sparse as sp -from sklearn.cluster import DBSCAN as sklearn_DBSCAN +from sklearn.cluster import DBSCAN as _sklearn_DBSCAN from sklearn.utils.validation import _check_sample_weight from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -46,11 +46,11 @@ def _save_attributes(self): @control_n_jobs(decorated_methods=["fit"]) -class DBSCAN(sklearn_DBSCAN, BaseDBSCAN): - __doc__ = sklearn_DBSCAN.__doc__ +class DBSCAN(_sklearn_DBSCAN, BaseDBSCAN): + __doc__ = _sklearn_DBSCAN.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_DBSCAN._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_DBSCAN._parameter_constraints} def __init__( self, @@ -180,7 +180,7 @@ def fit(self, X, y=None, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_DBSCAN.fit, + "sklearn": _sklearn_DBSCAN.fit, }, X, y, @@ -189,4 +189,4 @@ def fit(self, X, y=None, sample_weight=None): return self - fit.__doc__ = sklearn_DBSCAN.fit.__doc__ + fit.__doc__ = _sklearn_DBSCAN.fit.__doc__ diff --git a/sklearnex/cluster/k_means.py b/sklearnex/cluster/k_means.py index c36b73dbfb..637e452efc 100644 --- a/sklearnex/cluster/k_means.py +++ b/sklearnex/cluster/k_means.py @@ -25,7 +25,7 @@ import numpy as np from scipy.sparse import issparse - from sklearn.cluster import KMeans as sklearn_KMeans + from sklearn.cluster import KMeans as _sklearn_KMeans from sklearn.utils._openmp_helpers import _openmp_effective_n_threads from sklearn.utils.validation import ( _check_sample_weight, @@ -43,11 +43,11 @@ from .._utils import PatchingConditionsChain @control_n_jobs(decorated_methods=["fit", "predict", "transform", "fit_transform"]) - class KMeans(sklearn_KMeans): - __doc__ = sklearn_KMeans.__doc__ + class KMeans(_sklearn_KMeans): + __doc__ = _sklearn_KMeans.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_KMeans._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_KMeans._parameter_constraints} def __init__( self, @@ -148,7 +148,7 @@ def fit(self, X, y=None, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_KMeans.fit, + "sklearn": _sklearn_KMeans.fit, }, X, y, @@ -233,7 +233,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_KMeans.predict, + "sklearn": _sklearn_KMeans.predict, }, X, ) @@ -254,7 +254,7 @@ def predict( "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_KMeans.predict, + "sklearn": _sklearn_KMeans.predict, }, X, sample_weight=sample_weight, @@ -317,7 +317,7 @@ def score(self, X, y=None, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_KMeans.score, + "sklearn": _sklearn_KMeans.score, }, X, y, @@ -361,11 +361,11 @@ def _save_attributes(self): self._n_init = self._onedal_estimator._n_init - fit.__doc__ = sklearn_KMeans.fit.__doc__ - predict.__doc__ = sklearn_KMeans.predict.__doc__ - transform.__doc__ = sklearn_KMeans.transform.__doc__ - fit_transform.__doc__ = sklearn_KMeans.fit_transform.__doc__ - score.__doc__ = sklearn_KMeans.score.__doc__ + fit.__doc__ = _sklearn_KMeans.fit.__doc__ + predict.__doc__ = _sklearn_KMeans.predict.__doc__ + transform.__doc__ = _sklearn_KMeans.transform.__doc__ + fit_transform.__doc__ = _sklearn_KMeans.fit_transform.__doc__ + score.__doc__ = _sklearn_KMeans.score.__doc__ else: from daal4py.sklearn.cluster import KMeans diff --git a/sklearnex/covariance/incremental_covariance.py b/sklearnex/covariance/incremental_covariance.py index 630982cb9e..00df131fcc 100644 --- a/sklearnex/covariance/incremental_covariance.py +++ b/sklearnex/covariance/incremental_covariance.py @@ -20,7 +20,7 @@ import numpy as np from scipy import linalg from sklearn.base import BaseEstimator, clone -from sklearn.covariance import EmpiricalCovariance as sklearn_EmpiricalCovariance +from sklearn.covariance import EmpiricalCovariance as _sklearn_EmpiricalCovariance from sklearn.covariance import log_likelihood from sklearn.utils import check_array, gen_batches from sklearn.utils.validation import _num_features @@ -98,8 +98,8 @@ class IncrementalEmpiricalCovariance(BaseEstimator): "copy": ["boolean"], } - get_precision = sklearn_EmpiricalCovariance.get_precision - error_norm = wrap_output_data(sklearn_EmpiricalCovariance.error_norm) + get_precision = _sklearn_EmpiricalCovariance.get_precision + error_norm = wrap_output_data(_sklearn_EmpiricalCovariance.error_norm) def __init__( self, *, store_precision=False, assume_centered=False, batch_size=None, copy=True @@ -363,6 +363,6 @@ def mahalanobis(self, X): _onedal_cpu_supported = _onedal_supported _onedal_gpu_supported = _onedal_supported - mahalanobis.__doc__ = sklearn_EmpiricalCovariance.mahalanobis.__doc__ - error_norm.__doc__ = sklearn_EmpiricalCovariance.error_norm.__doc__ - score.__doc__ = sklearn_EmpiricalCovariance.score.__doc__ + mahalanobis.__doc__ = _sklearn_EmpiricalCovariance.mahalanobis.__doc__ + error_norm.__doc__ = _sklearn_EmpiricalCovariance.error_norm.__doc__ + score.__doc__ = _sklearn_EmpiricalCovariance.score.__doc__ diff --git a/sklearnex/neighbors/knn_classification.py b/sklearnex/neighbors/knn_classification.py index 731dc0c1f9..febc191901 100755 --- a/sklearnex/neighbors/knn_classification.py +++ b/sklearnex/neighbors/knn_classification.py @@ -16,7 +16,7 @@ from sklearn.metrics import accuracy_score from sklearn.neighbors._classification import ( - KNeighborsClassifier as sklearn_KNeighborsClassifier, + KNeighborsClassifier as _sklearn_KNeighborsClassifier, ) from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted @@ -32,11 +32,11 @@ @control_n_jobs( decorated_methods=["fit", "predict", "predict_proba", "kneighbors", "score"] ) -class KNeighborsClassifier(KNeighborsDispatchingBase, sklearn_KNeighborsClassifier): - __doc__ = sklearn_KNeighborsClassifier.__doc__ +class KNeighborsClassifier(KNeighborsDispatchingBase, _sklearn_KNeighborsClassifier): + __doc__ = _sklearn_KNeighborsClassifier.__doc__ if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_KNeighborsClassifier._parameter_constraints + **_sklearn_KNeighborsClassifier._parameter_constraints } if sklearn_check_version("1.0"): @@ -98,7 +98,7 @@ def fit(self, X, y): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_KNeighborsClassifier.fit, + "sklearn": _sklearn_KNeighborsClassifier.fit, }, X, y, @@ -115,7 +115,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_KNeighborsClassifier.predict, + "sklearn": _sklearn_KNeighborsClassifier.predict, }, X, ) @@ -130,7 +130,7 @@ def predict_proba(self, X): "predict_proba", { "onedal": self.__class__._onedal_predict_proba, - "sklearn": sklearn_KNeighborsClassifier.predict_proba, + "sklearn": _sklearn_KNeighborsClassifier.predict_proba, }, X, ) @@ -145,7 +145,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_KNeighborsClassifier.score, + "sklearn": _sklearn_KNeighborsClassifier.score, }, X, y, @@ -162,7 +162,7 @@ def kneighbors(self, X=None, n_neighbors=None, return_distance=True): "kneighbors", { "onedal": self.__class__._onedal_kneighbors, - "sklearn": sklearn_KNeighborsClassifier.kneighbors, + "sklearn": _sklearn_KNeighborsClassifier.kneighbors, }, X, n_neighbors=n_neighbors, @@ -219,8 +219,8 @@ def _save_attributes(self): self.outputs_2d_ = self._onedal_estimator.outputs_2d_ self._tree = self._onedal_estimator._tree - fit.__doc__ = sklearn_KNeighborsClassifier.fit.__doc__ - predict.__doc__ = sklearn_KNeighborsClassifier.predict.__doc__ - predict_proba.__doc__ = sklearn_KNeighborsClassifier.predict_proba.__doc__ - score.__doc__ = sklearn_KNeighborsClassifier.score.__doc__ - kneighbors.__doc__ = sklearn_KNeighborsClassifier.kneighbors.__doc__ + fit.__doc__ = _sklearn_KNeighborsClassifier.fit.__doc__ + predict.__doc__ = _sklearn_KNeighborsClassifier.predict.__doc__ + predict_proba.__doc__ = _sklearn_KNeighborsClassifier.predict_proba.__doc__ + score.__doc__ = _sklearn_KNeighborsClassifier.score.__doc__ + kneighbors.__doc__ = _sklearn_KNeighborsClassifier.kneighbors.__doc__ diff --git a/sklearnex/neighbors/knn_regression.py b/sklearnex/neighbors/knn_regression.py index aa146384d2..0dab888c08 100755 --- a/sklearnex/neighbors/knn_regression.py +++ b/sklearnex/neighbors/knn_regression.py @@ -16,9 +16,8 @@ from sklearn.metrics import r2_score from sklearn.neighbors._regression import ( - KNeighborsRegressor as sklearn_KNeighborsRegressor, + KNeighborsRegressor as _sklearn_KNeighborsRegressor, ) -from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -30,11 +29,11 @@ @control_n_jobs(decorated_methods=["fit", "predict", "kneighbors"]) -class KNeighborsRegressor(KNeighborsDispatchingBase, sklearn_KNeighborsRegressor): - __doc__ = sklearn_KNeighborsRegressor.__doc__ +class KNeighborsRegressor(KNeighborsDispatchingBase, _sklearn_KNeighborsRegressor): + __doc__ = _sklearn_KNeighborsRegressor.__doc__ if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_KNeighborsRegressor._parameter_constraints + **_sklearn_KNeighborsRegressor._parameter_constraints } if sklearn_check_version("1.0"): @@ -96,7 +95,7 @@ def fit(self, X, y): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_KNeighborsRegressor.fit, + "sklearn": _sklearn_KNeighborsRegressor.fit, }, X, y, @@ -113,7 +112,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_KNeighborsRegressor.predict, + "sklearn": _sklearn_KNeighborsRegressor.predict, }, X, ) @@ -128,7 +127,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_KNeighborsRegressor.score, + "sklearn": _sklearn_KNeighborsRegressor.score, }, X, y, @@ -145,7 +144,7 @@ def kneighbors(self, X=None, n_neighbors=None, return_distance=True): "kneighbors", { "onedal": self.__class__._onedal_kneighbors, - "sklearn": sklearn_KNeighborsRegressor.kneighbors, + "sklearn": _sklearn_KNeighborsRegressor.kneighbors, }, X, n_neighbors=n_neighbors, @@ -197,7 +196,7 @@ def _save_attributes(self): self._fit_method = self._onedal_estimator._fit_method self._tree = self._onedal_estimator._tree - fit.__doc__ = sklearn_KNeighborsRegressor.__doc__ - predict.__doc__ = sklearn_KNeighborsRegressor.predict.__doc__ - kneighbors.__doc__ = sklearn_KNeighborsRegressor.kneighbors.__doc__ - score.__doc__ = sklearn_KNeighborsRegressor.score.__doc__ + fit.__doc__ = _sklearn_KNeighborsRegressor.__doc__ + predict.__doc__ = _sklearn_KNeighborsRegressor.predict.__doc__ + kneighbors.__doc__ = _sklearn_KNeighborsRegressor.kneighbors.__doc__ + score.__doc__ = _sklearn_KNeighborsRegressor.score.__doc__ diff --git a/sklearnex/neighbors/knn_unsupervised.py b/sklearnex/neighbors/knn_unsupervised.py index 6503204ea2..b314ead6f5 100755 --- a/sklearnex/neighbors/knn_unsupervised.py +++ b/sklearnex/neighbors/knn_unsupervised.py @@ -14,7 +14,7 @@ # limitations under the License. # =============================================================================== -from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors +from sklearn.neighbors._unsupervised import NearestNeighbors as _sklearn_NearestNeighbors from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -26,10 +26,10 @@ @control_n_jobs(decorated_methods=["fit", "kneighbors"]) -class NearestNeighbors(KNeighborsDispatchingBase, sklearn_NearestNeighbors): - __doc__ = sklearn_NearestNeighbors.__doc__ +class NearestNeighbors(KNeighborsDispatchingBase, _sklearn_NearestNeighbors): + __doc__ = _sklearn_NearestNeighbors.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_NearestNeighbors._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_NearestNeighbors._parameter_constraints} @_deprecate_positional_args def __init__( @@ -60,7 +60,7 @@ def fit(self, X, y=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_NearestNeighbors.fit, + "sklearn": _sklearn_NearestNeighbors.fit, }, X, None, @@ -77,7 +77,7 @@ def kneighbors(self, X=None, n_neighbors=None, return_distance=True): "kneighbors", { "onedal": self.__class__._onedal_kneighbors, - "sklearn": sklearn_NearestNeighbors.kneighbors, + "sklearn": _sklearn_NearestNeighbors.kneighbors, }, X, n_neighbors=n_neighbors, @@ -93,13 +93,13 @@ def radius_neighbors( or getattr(self, "_tree", 0) is None and self._fit_method == "kd_tree" ): - sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None)) + _sklearn_NearestNeighbors.fit(self, self._fit_X, getattr(self, "_y", None)) return dispatch( self, "radius_neighbors", { "onedal": None, - "sklearn": sklearn_NearestNeighbors.radius_neighbors, + "sklearn": _sklearn_NearestNeighbors.radius_neighbors, }, X, radius=radius, @@ -115,7 +115,7 @@ def radius_neighbors_graph( "radius_neighbors_graph", { "onedal": None, - "sklearn": sklearn_NearestNeighbors.radius_neighbors_graph, + "sklearn": _sklearn_NearestNeighbors.radius_neighbors_graph, }, X, radius=radius, @@ -162,9 +162,9 @@ def _save_attributes(self): self._fit_method = self._onedal_estimator._fit_method self._tree = self._onedal_estimator._tree - fit.__doc__ = sklearn_NearestNeighbors.__doc__ - kneighbors.__doc__ = sklearn_NearestNeighbors.kneighbors.__doc__ - radius_neighbors.__doc__ = sklearn_NearestNeighbors.radius_neighbors.__doc__ + fit.__doc__ = _sklearn_NearestNeighbors.__doc__ + kneighbors.__doc__ = _sklearn_NearestNeighbors.kneighbors.__doc__ + radius_neighbors.__doc__ = _sklearn_NearestNeighbors.radius_neighbors.__doc__ radius_neighbors_graph.__doc__ = ( - sklearn_NearestNeighbors.radius_neighbors_graph.__doc__ + _sklearn_NearestNeighbors.radius_neighbors_graph.__doc__ ) diff --git a/sklearnex/preview/covariance/covariance.py b/sklearnex/preview/covariance/covariance.py index ac75981787..4586974908 100644 --- a/sklearnex/preview/covariance/covariance.py +++ b/sklearnex/preview/covariance/covariance.py @@ -18,7 +18,7 @@ import numpy as np from scipy import sparse as sp -from sklearn.covariance import EmpiricalCovariance as sklearn_EmpiricalCovariance +from sklearn.covariance import EmpiricalCovariance as _sklearn_EmpiricalCovariance from sklearn.utils import check_array from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -34,12 +34,12 @@ @register_hyperparameters({"fit": get_hyperparameters("covariance", "compute")}) @control_n_jobs(decorated_methods=["fit", "mahalanobis"]) -class EmpiricalCovariance(sklearn_EmpiricalCovariance): - __doc__ = sklearn_EmpiricalCovariance.__doc__ +class EmpiricalCovariance(_sklearn_EmpiricalCovariance): + __doc__ = _sklearn_EmpiricalCovariance.__doc__ if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_EmpiricalCovariance._parameter_constraints, + **_sklearn_EmpiricalCovariance._parameter_constraints, } def _save_attributes(self): @@ -100,7 +100,7 @@ def fit(self, X, y=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_EmpiricalCovariance.fit, + "sklearn": _sklearn_EmpiricalCovariance.fit, }, X, ) @@ -124,10 +124,10 @@ def mahalanobis(self, X): return np.reshape(dist, (len(X),)) ** 2 - error_norm = wrap_output_data(sklearn_EmpiricalCovariance.error_norm) - score = wrap_output_data(sklearn_EmpiricalCovariance.score) + error_norm = wrap_output_data(_sklearn_EmpiricalCovariance.error_norm) + score = wrap_output_data(_sklearn_EmpiricalCovariance.score) - fit.__doc__ = sklearn_EmpiricalCovariance.fit.__doc__ - mahalanobis.__doc__ = sklearn_EmpiricalCovariance.mahalanobis - error_norm.__doc__ = sklearn_EmpiricalCovariance.error_norm.__doc__ - score.__doc__ = sklearn_EmpiricalCovariance.score.__doc__ + fit.__doc__ = _sklearn_EmpiricalCovariance.fit.__doc__ + mahalanobis.__doc__ = _sklearn_EmpiricalCovariance.mahalanobis + error_norm.__doc__ = _sklearn_EmpiricalCovariance.error_norm.__doc__ + score.__doc__ = _sklearn_EmpiricalCovariance.score.__doc__ diff --git a/sklearnex/preview/decomposition/incremental_pca.py b/sklearnex/preview/decomposition/incremental_pca.py index d3c050ff08..2de7347105 100644 --- a/sklearnex/preview/decomposition/incremental_pca.py +++ b/sklearnex/preview/decomposition/incremental_pca.py @@ -15,7 +15,7 @@ # =============================================================================== import numpy as np -from sklearn.decomposition import IncrementalPCA as sklearn_IncrementalPCA +from sklearn.decomposition import IncrementalPCA as _sklearn_IncrementalPCA from sklearn.utils import check_array, gen_batches from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -29,7 +29,7 @@ @control_n_jobs( decorated_methods=["fit", "partial_fit", "transform", "_onedal_finalize_fit"] ) -class IncrementalPCA(sklearn_IncrementalPCA): +class IncrementalPCA(_sklearn_IncrementalPCA): def __init__(self, n_components=None, *, whiten=False, copy=True, batch_size=None): super().__init__( @@ -178,7 +178,7 @@ def partial_fit(self, X, y=None, check_input=True): "partial_fit", { "onedal": self.__class__._onedal_partial_fit, - "sklearn": sklearn_IncrementalPCA.partial_fit, + "sklearn": _sklearn_IncrementalPCA.partial_fit, }, X, check_input=check_input, @@ -191,7 +191,7 @@ def fit(self, X, y=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_IncrementalPCA.fit, + "sklearn": _sklearn_IncrementalPCA.fit, }, X, ) @@ -204,7 +204,7 @@ def transform(self, X): "transform", { "onedal": self.__class__._onedal_transform, - "sklearn": sklearn_IncrementalPCA.transform, + "sklearn": _sklearn_IncrementalPCA.transform, }, X, ) @@ -216,13 +216,13 @@ def fit_transform(self, X, y=None, **fit_params): "fit_transform", { "onedal": self.__class__._onedal_fit_transform, - "sklearn": sklearn_IncrementalPCA.fit_transform, + "sklearn": _sklearn_IncrementalPCA.fit_transform, }, X, ) - __doc__ = sklearn_IncrementalPCA.__doc__ - fit.__doc__ = sklearn_IncrementalPCA.fit.__doc__ - fit_transform.__doc__ = sklearn_IncrementalPCA.fit_transform.__doc__ - transform.__doc__ = sklearn_IncrementalPCA.transform.__doc__ - partial_fit.__doc__ = sklearn_IncrementalPCA.partial_fit.__doc__ + __doc__ = _sklearn_IncrementalPCA.__doc__ + fit.__doc__ = _sklearn_IncrementalPCA.fit.__doc__ + fit_transform.__doc__ = _sklearn_IncrementalPCA.fit_transform.__doc__ + transform.__doc__ = _sklearn_IncrementalPCA.transform.__doc__ + partial_fit.__doc__ = _sklearn_IncrementalPCA.partial_fit.__doc__ diff --git a/sklearnex/preview/linear_model/ridge.py b/sklearnex/preview/linear_model/ridge.py index c83b4dc89d..8d71e94454 100644 --- a/sklearnex/preview/linear_model/ridge.py +++ b/sklearnex/preview/linear_model/ridge.py @@ -23,7 +23,7 @@ import numpy as np from scipy.sparse import issparse - from sklearn.linear_model import Ridge as sklearn_Ridge + from sklearn.linear_model import Ridge as _sklearn_Ridge from sklearn.metrics import r2_score from sklearn.utils.validation import check_is_fitted, check_X_y @@ -52,11 +52,11 @@ def _is_numeric_scalar(value): """ return isinstance(value, numbers.Real) - class Ridge(sklearn_Ridge): - __doc__ = sklearn_Ridge.__doc__ + class Ridge(_sklearn_Ridge): + __doc__ = _sklearn_Ridge.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_Ridge._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_Ridge._parameter_constraints} def __init__( self, @@ -141,7 +141,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_Ridge.fit, + "sklearn": _sklearn_Ridge.fit, }, X, y, @@ -158,7 +158,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_Ridge.predict, + "sklearn": _sklearn_Ridge.predict, }, X, ) @@ -172,7 +172,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_Ridge.score, + "sklearn": _sklearn_Ridge.score, }, X, y, @@ -402,9 +402,9 @@ def _save_attributes(self): self._coef = self._onedal_estimator.coef_ self._intercept = self._onedal_estimator.intercept_ - fit.__doc__ = sklearn_Ridge.fit.__doc__ - predict.__doc__ = sklearn_Ridge.predict.__doc__ - score.__doc__ = sklearn_Ridge.score.__doc__ + fit.__doc__ = _sklearn_Ridge.fit.__doc__ + predict.__doc__ = _sklearn_Ridge.predict.__doc__ + score.__doc__ = _sklearn_Ridge.score.__doc__ else: from daal4py.sklearn.linear_model._ridge import Ridge diff --git a/sklearnex/svm/nusvc.py b/sklearnex/svm/nusvc.py index 421546a203..584b85cc24 100644 --- a/sklearnex/svm/nusvc.py +++ b/sklearnex/svm/nusvc.py @@ -17,7 +17,7 @@ import numpy as np from sklearn.exceptions import NotFittedError from sklearn.metrics import accuracy_score -from sklearn.svm import NuSVC as sklearn_NuSVC +from sklearn.svm import NuSVC as _sklearn_NuSVC from sklearn.utils.validation import _deprecate_positional_args from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -36,11 +36,11 @@ @control_n_jobs( decorated_methods=["fit", "predict", "_predict_proba", "decision_function", "score"] ) -class NuSVC(sklearn_NuSVC, BaseSVC): - __doc__ = sklearn_NuSVC.__doc__ +class NuSVC(_sklearn_NuSVC, BaseSVC): + __doc__ = _sklearn_NuSVC.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_NuSVC._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_NuSVC._parameter_constraints} @_deprecate_positional_args def __init__( @@ -101,7 +101,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_NuSVC.fit, + "sklearn": _sklearn_NuSVC.fit, }, X, y, @@ -119,7 +119,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_NuSVC.predict, + "sklearn": _sklearn_NuSVC.predict, }, X, ) @@ -133,7 +133,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_NuSVC.score, + "sklearn": _sklearn_NuSVC.score, }, X, y, @@ -142,7 +142,7 @@ def score(self, X, y, sample_weight=None): if sklearn_check_version("1.0"): - @available_if(sklearn_NuSVC._check_proba) + @available_if(_sklearn_NuSVC._check_proba) def predict_proba(self, X): """ Compute probabilities of possible outcomes for samples in X. @@ -172,7 +172,7 @@ def predict_proba(self, X): """ return self._predict_proba(X) - @available_if(sklearn_NuSVC._check_proba) + @available_if(_sklearn_NuSVC._check_proba) def predict_log_proba(self, X): """Compute log probabilities of possible outcomes for samples in X. @@ -215,16 +215,16 @@ def _predict_log_proba(self, X): xp, _ = get_namespace(X) return xp.log(self.predict_proba(X)) - predict_proba.__doc__ = sklearn_NuSVC.predict_proba.__doc__ + predict_proba.__doc__ = _sklearn_NuSVC.predict_proba.__doc__ @wrap_output_data def _predict_proba(self, X): if sklearn_check_version("1.0"): self._check_feature_names(X, reset=False) sklearn_pred_proba = ( - sklearn_NuSVC.predict_proba + _sklearn_NuSVC.predict_proba if sklearn_check_version("1.0") - else sklearn_NuSVC._predict_proba + else _sklearn_NuSVC._predict_proba ) return dispatch( @@ -246,12 +246,12 @@ def decision_function(self, X): "decision_function", { "onedal": self.__class__._onedal_decision_function, - "sklearn": sklearn_NuSVC.decision_function, + "sklearn": _sklearn_NuSVC.decision_function, }, X, ) - decision_function.__doc__ = sklearn_NuSVC.decision_function.__doc__ + decision_function.__doc__ = _sklearn_NuSVC.decision_function.__doc__ def _get_sample_weight(self, X, y, sample_weight=None): sample_weight = super()._get_sample_weight(X, y, sample_weight) @@ -326,7 +326,7 @@ def _onedal_score(self, X, y, sample_weight=None, queue=None): y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight ) - fit.__doc__ = sklearn_NuSVC.fit.__doc__ - predict.__doc__ = sklearn_NuSVC.predict.__doc__ - decision_function.__doc__ = sklearn_NuSVC.decision_function.__doc__ - score.__doc__ = sklearn_NuSVC.score.__doc__ + fit.__doc__ = _sklearn_NuSVC.fit.__doc__ + predict.__doc__ = _sklearn_NuSVC.predict.__doc__ + decision_function.__doc__ = _sklearn_NuSVC.decision_function.__doc__ + score.__doc__ = _sklearn_NuSVC.score.__doc__ diff --git a/sklearnex/svm/nusvr.py b/sklearnex/svm/nusvr.py index 2945175398..f9bced5ec1 100644 --- a/sklearnex/svm/nusvr.py +++ b/sklearnex/svm/nusvr.py @@ -14,7 +14,7 @@ # limitations under the License. # ============================================================================== -from sklearn.svm import NuSVR as sklearn_NuSVR +from sklearn.svm import NuSVR as _sklearn_NuSVR from sklearn.utils.validation import _deprecate_positional_args from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -26,11 +26,11 @@ @control_n_jobs(decorated_methods=["fit", "predict"]) -class NuSVR(sklearn_NuSVR, BaseSVR): - __doc__ = sklearn_NuSVR.__doc__ +class NuSVR(_sklearn_NuSVR, BaseSVR): + __doc__ = _sklearn_NuSVR.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_NuSVR._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_NuSVR._parameter_constraints} @_deprecate_positional_args def __init__( @@ -83,7 +83,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_NuSVR.fit, + "sklearn": _sklearn_NuSVR.fit, }, X, y, @@ -100,7 +100,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_NuSVR.predict, + "sklearn": _sklearn_NuSVR.predict, }, X, ) @@ -114,7 +114,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_NuSVR.score, + "sklearn": _sklearn_NuSVR.score, }, X, y, @@ -143,6 +143,6 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None): def _onedal_predict(self, X, queue=None): return self._onedal_estimator.predict(X, queue=queue) - fit.__doc__ = sklearn_NuSVR.fit.__doc__ - predict.__doc__ = sklearn_NuSVR.predict.__doc__ - score.__doc__ = sklearn_NuSVR.score.__doc__ + fit.__doc__ = _sklearn_NuSVR.fit.__doc__ + predict.__doc__ = _sklearn_NuSVR.predict.__doc__ + score.__doc__ = _sklearn_NuSVR.score.__doc__ diff --git a/sklearnex/svm/svc.py b/sklearnex/svm/svc.py index 337f44ba4b..a8627ddcd9 100644 --- a/sklearnex/svm/svc.py +++ b/sklearnex/svm/svc.py @@ -18,7 +18,7 @@ from scipy import sparse as sp from sklearn.exceptions import NotFittedError from sklearn.metrics import accuracy_score -from sklearn.svm import SVC as sklearn_SVC +from sklearn.svm import SVC as _sklearn_SVC from sklearn.utils.validation import _deprecate_positional_args from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -38,11 +38,11 @@ @control_n_jobs( decorated_methods=["fit", "predict", "_predict_proba", "decision_function", "score"] ) -class SVC(sklearn_SVC, BaseSVC): - __doc__ = sklearn_SVC.__doc__ +class SVC(_sklearn_SVC, BaseSVC): + __doc__ = _sklearn_SVC.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_SVC._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_SVC._parameter_constraints} @_deprecate_positional_args def __init__( @@ -103,7 +103,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_SVC.fit, + "sklearn": _sklearn_SVC.fit, }, X, y, @@ -121,7 +121,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_SVC.predict, + "sklearn": _sklearn_SVC.predict, }, X, ) @@ -135,7 +135,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_SVC.score, + "sklearn": _sklearn_SVC.score, }, X, y, @@ -144,7 +144,7 @@ def score(self, X, y, sample_weight=None): if sklearn_check_version("1.0"): - @available_if(sklearn_SVC._check_proba) + @available_if(_sklearn_SVC._check_proba) def predict_proba(self, X): """ Compute probabilities of possible outcomes for samples in X. @@ -174,7 +174,7 @@ def predict_proba(self, X): """ return self._predict_proba(X) - @available_if(sklearn_SVC._check_proba) + @available_if(_sklearn_SVC._check_proba) def predict_log_proba(self, X): """Compute log probabilities of possible outcomes for samples in X. @@ -217,14 +217,14 @@ def _predict_log_proba(self, X): xp, _ = get_namespace(X) return xp.log(self.predict_proba(X)) - predict_proba.__doc__ = sklearn_SVC.predict_proba.__doc__ + predict_proba.__doc__ = _sklearn_SVC.predict_proba.__doc__ @wrap_output_data def _predict_proba(self, X): sklearn_pred_proba = ( - sklearn_SVC.predict_proba + _sklearn_SVC.predict_proba if sklearn_check_version("1.0") - else sklearn_SVC._predict_proba + else _sklearn_SVC._predict_proba ) return dispatch( @@ -246,12 +246,12 @@ def decision_function(self, X): "decision_function", { "onedal": self.__class__._onedal_decision_function, - "sklearn": sklearn_SVC.decision_function, + "sklearn": _sklearn_SVC.decision_function, }, X, ) - decision_function.__doc__ = sklearn_SVC.decision_function.__doc__ + decision_function.__doc__ = _sklearn_SVC.decision_function.__doc__ def _onedal_gpu_supported(self, method_name, *data): class_name = self.__class__.__name__ @@ -354,7 +354,7 @@ def _onedal_score(self, X, y, sample_weight=None, queue=None): y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight ) - fit.__doc__ = sklearn_SVC.fit.__doc__ - predict.__doc__ = sklearn_SVC.predict.__doc__ - decision_function.__doc__ = sklearn_SVC.decision_function.__doc__ - score.__doc__ = sklearn_SVC.score.__doc__ + fit.__doc__ = _sklearn_SVC.fit.__doc__ + predict.__doc__ = _sklearn_SVC.predict.__doc__ + decision_function.__doc__ = _sklearn_SVC.decision_function.__doc__ + score.__doc__ = _sklearn_SVC.score.__doc__ diff --git a/sklearnex/svm/svr.py b/sklearnex/svm/svr.py index 1b16a5aa7e..158e1ea49e 100644 --- a/sklearnex/svm/svr.py +++ b/sklearnex/svm/svr.py @@ -14,7 +14,7 @@ # limitations under the License. # ============================================================================== -from sklearn.svm import SVR as sklearn_SVR +from sklearn.svm import SVR as _sklearn_SVR from sklearn.utils.validation import _deprecate_positional_args from daal4py.sklearn._n_jobs_support import control_n_jobs @@ -26,11 +26,11 @@ @control_n_jobs(decorated_methods=["fit", "predict"]) -class SVR(sklearn_SVR, BaseSVR): - __doc__ = sklearn_SVR.__doc__ +class SVR(_sklearn_SVR, BaseSVR): + __doc__ = _sklearn_SVR.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_SVR._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_SVR._parameter_constraints} @_deprecate_positional_args def __init__( @@ -83,7 +83,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_SVR.fit, + "sklearn": _sklearn_SVR.fit, }, X, y, @@ -101,7 +101,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_SVR.predict, + "sklearn": _sklearn_SVR.predict, }, X, ) @@ -115,7 +115,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_SVR.score, + "sklearn": _sklearn_SVR.score, }, X, y, @@ -144,6 +144,6 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None): def _onedal_predict(self, X, queue=None): return self._onedal_estimator.predict(X, queue=queue) - fit.__doc__ = sklearn_SVR.fit.__doc__ - predict.__doc__ = sklearn_SVR.predict.__doc__ - score.__doc__ = sklearn_SVR.score.__doc__ + fit.__doc__ = _sklearn_SVR.fit.__doc__ + predict.__doc__ = _sklearn_SVR.predict.__doc__ + score.__doc__ = _sklearn_SVR.score.__doc__ From f95d07cb59fefc1ec810c176afb6459f4824f0ec Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:03:08 -0700 Subject: [PATCH 10/37] sklearn_ -> _sklearn_ --- sklearnex/decomposition/pca.py | 2 +- sklearnex/dispatcher.py | 2 +- sklearnex/ensemble/_forest.py | 12 ++++++------ sklearnex/linear_model/linear.py | 2 +- sklearnex/linear_model/logistic_regression.py | 2 +- sklearnex/neighbors/_lof.py | 2 +- sklearnex/neighbors/common.py | 2 +- sklearnex/neighbors/knn_classification.py | 2 +- sklearnex/utils/_namespace.py | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sklearnex/decomposition/pca.py b/sklearnex/decomposition/pca.py index a2353536ff..56abcce60e 100755 --- a/sklearnex/decomposition/pca.py +++ b/sklearnex/decomposition/pca.py @@ -40,7 +40,7 @@ if sklearn_check_version("1.2"): from sklearn.utils._param_validation import StrOptions - from sklearn.decomposition import PCA as sklearn_PCA + from sklearn.decomposition import PCA as _sklearn_PCA from onedal.decomposition import PCA as onedal_PCA diff --git a/sklearnex/dispatcher.py b/sklearnex/dispatcher.py index a4a62556f6..ac0b0942a7 100644 --- a/sklearnex/dispatcher.py +++ b/sklearnex/dispatcher.py @@ -516,7 +516,7 @@ def unpatch_sklearn(name=None, global_unpatch=False): def sklearn_is_patched(name=None, return_map=False): - from daal4py.sklearn import sklearn_is_patched as sklearn_is_patched_orig + from daal4py.sklearn import sklearn_is_patched as _sklearn_is_patched_orig if isinstance(name, list): if return_map: diff --git a/sklearnex/ensemble/_forest.py b/sklearnex/ensemble/_forest.py index 64948b6ef7..2f2afaf421 100644 --- a/sklearnex/ensemble/_forest.py +++ b/sklearnex/ensemble/_forest.py @@ -21,12 +21,12 @@ import numpy as np from scipy import sparse as sp from sklearn.base import clone -from sklearn.ensemble import ExtraTreesClassifier as sklearn_ExtraTreesClassifier -from sklearn.ensemble import ExtraTreesRegressor as sklearn_ExtraTreesRegressor -from sklearn.ensemble import RandomForestClassifier as sklearn_RandomForestClassifier -from sklearn.ensemble import RandomForestRegressor as sklearn_RandomForestRegressor -from sklearn.ensemble._forest import ForestClassifier as sklearn_ForestClassifier -from sklearn.ensemble._forest import ForestRegressor as sklearn_ForestRegressor +from sklearn.ensemble import ExtraTreesClassifier as _sklearn_ExtraTreesClassifier +from sklearn.ensemble import ExtraTreesRegressor as _sklearn_ExtraTreesRegressor +from sklearn.ensemble import RandomForestClassifier as _sklearn_RandomForestClassifier +from sklearn.ensemble import RandomForestRegressor as _sklearn_RandomForestRegressor +from sklearn.ensemble._forest import ForestClassifier as _sklearn_ForestClassifier +from sklearn.ensemble._forest import ForestRegressor as _sklearn_ForestRegressor from sklearn.ensemble._forest import _get_n_samples_bootstrap from sklearn.exceptions import DataConversionWarning from sklearn.metrics import accuracy_score, r2_score diff --git a/sklearnex/linear_model/linear.py b/sklearnex/linear_model/linear.py index aa31f105dd..abdab41d99 100644 --- a/sklearnex/linear_model/linear.py +++ b/sklearnex/linear_model/linear.py @@ -19,7 +19,7 @@ import numpy as np from sklearn.exceptions import NotFittedError -from sklearn.linear_model import LinearRegression as sklearn_LinearRegression +from sklearn.linear_model import LinearRegression as _sklearn_LinearRegression from sklearn.metrics import r2_score from daal4py.sklearn._n_jobs_support import control_n_jobs diff --git a/sklearnex/linear_model/logistic_regression.py b/sklearnex/linear_model/logistic_regression.py index 6658d8945c..b1399fdb2e 100644 --- a/sklearnex/linear_model/logistic_regression.py +++ b/sklearnex/linear_model/logistic_regression.py @@ -25,7 +25,7 @@ if daal_check_version((2024, "P", 1)): import numpy as np from scipy.sparse import issparse - from sklearn.linear_model import LogisticRegression as sklearn_LogisticRegression + from sklearn.linear_model import LogisticRegression as _sklearn_LogisticRegression from sklearn.metrics import accuracy_score from sklearn.utils.multiclass import type_of_target from sklearn.utils.validation import check_array, check_is_fitted, check_X_y diff --git a/sklearnex/neighbors/_lof.py b/sklearnex/neighbors/_lof.py index 0a9a72ee1e..deed4f5572 100644 --- a/sklearnex/neighbors/_lof.py +++ b/sklearnex/neighbors/_lof.py @@ -17,7 +17,7 @@ import warnings import numpy as np -from sklearn.neighbors import LocalOutlierFactor as sklearn_LocalOutlierFactor +from sklearn.neighbors import LocalOutlierFactor as _sklearn_LocalOutlierFactor from sklearn.utils.metaestimators import available_if from sklearn.utils.validation import check_is_fitted diff --git a/sklearnex/neighbors/common.py b/sklearnex/neighbors/common.py index 92ef00250c..63ea780ce1 100644 --- a/sklearnex/neighbors/common.py +++ b/sklearnex/neighbors/common.py @@ -20,7 +20,7 @@ from scipy import sparse as sp from sklearn.neighbors._ball_tree import BallTree from sklearn.neighbors._base import VALID_METRICS, KNeighborsMixin -from sklearn.neighbors._base import NeighborsBase as sklearn_NeighborsBase +from sklearn.neighbors._base import NeighborsBase as _sklearn_NeighborsBase from sklearn.neighbors._kd_tree import KDTree from sklearn.utils.validation import check_is_fitted diff --git a/sklearnex/neighbors/knn_classification.py b/sklearnex/neighbors/knn_classification.py index febc191901..e3c4d1f41f 100755 --- a/sklearnex/neighbors/knn_classification.py +++ b/sklearnex/neighbors/knn_classification.py @@ -18,7 +18,7 @@ from sklearn.neighbors._classification import ( KNeighborsClassifier as _sklearn_KNeighborsClassifier, ) -from sklearn.neighbors._unsupervised import NearestNeighbors as sklearn_NearestNeighbors +from sklearn.neighbors._unsupervised import NearestNeighbors as _sklearn_NearestNeighbors from sklearn.utils.validation import _deprecate_positional_args, check_is_fitted from daal4py.sklearn._n_jobs_support import control_n_jobs diff --git a/sklearnex/utils/_namespace.py b/sklearnex/utils/_namespace.py index 2f67737023..4526972b7e 100644 --- a/sklearnex/utils/_namespace.py +++ b/sklearnex/utils/_namespace.py @@ -21,7 +21,7 @@ from .._device_offload import dpnp_available if sklearn_check_version("1.2"): - from sklearn.utils._array_api import get_namespace as sklearn_get_namespace + from sklearn.utils._array_api import get_namespace as _sklearn_get_namespace if dpnp_available: import dpnp From 83ce015d7ff5f1435052d6dcef203de60f6b37d1 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:04:33 -0700 Subject: [PATCH 11/37] fix mistake --- sklearnex/dispatcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/dispatcher.py b/sklearnex/dispatcher.py index ac0b0942a7..a4a62556f6 100644 --- a/sklearnex/dispatcher.py +++ b/sklearnex/dispatcher.py @@ -516,7 +516,7 @@ def unpatch_sklearn(name=None, global_unpatch=False): def sklearn_is_patched(name=None, return_map=False): - from daal4py.sklearn import sklearn_is_patched as _sklearn_is_patched_orig + from daal4py.sklearn import sklearn_is_patched as sklearn_is_patched_orig if isinstance(name, list): if return_map: From 679c0fff0215b3c2c211e66fd1efe6b7a77df8c3 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:14:46 -0700 Subject: [PATCH 12/37] reformulate to wrapper --- sklearnex/tests/test_common.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index d8e237d0c7..fb51a436bd 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -18,7 +18,6 @@ import pathlib import pkgutil from glob import glob -from pkgutil import walk_packages as walk_packages_orig import pytest from sklearn.utils import all_estimators @@ -60,19 +59,21 @@ def test_target_offload_ban(): assert output == "", f"sklearn versioning is occuring in: \n{output}" -def _sklearnex_walk(*args, **kwargs): +def _sklearnex_walk(func): """this replaces checks on pkgutils to look in sklearnex folders specifically""" - if "prefix" in kwargs and kwargs["prefix"] == "sklearn.": - kwargs["prefix"] = "sklearnex." - if "path" in kwargs: - # force root to sklearnex - kwargs["path"] = [str(pathlib.Path(__file__).parent.parent)] - return walk_packages_orig(*args, **kwargs) + def wrap(*args, **kwargs) + if "prefix" in kwargs and kwargs["prefix"] == "sklearn.": + kwargs["prefix"] = "sklearnex." + if "path" in kwargs: + # force root to sklearnex + kwargs["path"] = [str(pathlib.Path(__file__).parent.parent)] + return func(*args, **kwargs) + return wrap def test_all_estimators_covered(monkeypatch): - monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk) + monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk(pkgutil.walk_packages)) estimators = all_estimators() print(estimators) for i in estimators: From 0828e2f1fb50102391147de0fe275befb74b0c33 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:20:53 -0700 Subject: [PATCH 13/37] swaps --- sklearnex/decomposition/pca.py | 18 +++--- sklearnex/ensemble/_forest.py | 58 +++++++++---------- sklearnex/linear_model/linear.py | 18 +++--- sklearnex/linear_model/logistic_regression.py | 26 ++++----- sklearnex/neighbors/_lof.py | 18 +++--- sklearnex/neighbors/common.py | 6 +- sklearnex/utils/_namespace.py | 2 +- 7 files changed, 73 insertions(+), 73 deletions(-) diff --git a/sklearnex/decomposition/pca.py b/sklearnex/decomposition/pca.py index 56abcce60e..5f800b35d5 100755 --- a/sklearnex/decomposition/pca.py +++ b/sklearnex/decomposition/pca.py @@ -45,11 +45,11 @@ from onedal.decomposition import PCA as onedal_PCA @control_n_jobs(decorated_methods=["fit", "transform", "fit_transform"]) - class PCA(sklearn_PCA): - __doc__ = sklearn_PCA.__doc__ + class PCA(_sklearn_PCA): + __doc__ = _sklearn_PCA.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_PCA._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_PCA._parameter_constraints} # "onedal_svd" solver uses oneDAL's PCA-SVD algorithm # and required for testing purposes to fully enable it in future. # "covariance_eigh" solver is added for ability to explicitly request @@ -127,7 +127,7 @@ def _fit(self, X): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_PCA._fit, + "sklearn": _sklearn_PCA._fit, }, X, ) @@ -169,7 +169,7 @@ def transform(self, X): "transform", { "onedal": self.__class__._onedal_transform, - "sklearn": sklearn_PCA.transform, + "sklearn": _sklearn_PCA.transform, }, X, ) @@ -401,10 +401,10 @@ def _validate_n_features_in_after_fitting(self, X): ) ) - fit.__doc__ = sklearn_PCA.fit.__doc__ - transform.__doc__ = sklearn_PCA.transform.__doc__ - fit_transform.__doc__ = sklearn_PCA.fit_transform.__doc__ - inverse_transform.__doc__ = sklearn_PCA.inverse_transform.__doc__ + fit.__doc__ = _sklearn_PCA.fit.__doc__ + transform.__doc__ = _sklearn_PCA.transform.__doc__ + fit_transform.__doc__ = _sklearn_PCA.fit_transform.__doc__ + inverse_transform.__doc__ = _sklearn_PCA.inverse_transform.__doc__ else: from daal4py.sklearn.decomposition import PCA diff --git a/sklearnex/ensemble/_forest.py b/sklearnex/ensemble/_forest.py index 2f2afaf421..26778d23f1 100644 --- a/sklearnex/ensemble/_forest.py +++ b/sklearnex/ensemble/_forest.py @@ -394,7 +394,7 @@ def base_estimator(self, estimator): self.estimator = estimator -class ForestClassifier(sklearn_ForestClassifier, BaseForest): +class ForestClassifier(_sklearn_ForestClassifier, BaseForest): # Surprisingly, even though scikit-learn warns against using # their ForestClassifier directly, it actually has a more stable # API than the user-facing objects (over time). If they change it @@ -458,7 +458,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_ForestClassifier.fit, + "sklearn": _sklearn_ForestClassifier.fit, }, X, y, @@ -597,7 +597,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_ForestClassifier.predict, + "sklearn": _sklearn_ForestClassifier.predict, }, X, ) @@ -627,7 +627,7 @@ def predict_proba(self, X): "predict_proba", { "onedal": self.__class__._onedal_predict_proba, - "sklearn": sklearn_ForestClassifier.predict_proba, + "sklearn": _sklearn_ForestClassifier.predict_proba, }, X, ) @@ -652,18 +652,18 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_ForestClassifier.score, + "sklearn": _sklearn_ForestClassifier.score, }, X, y, sample_weight=sample_weight, ) - fit.__doc__ = sklearn_ForestClassifier.fit.__doc__ - predict.__doc__ = sklearn_ForestClassifier.predict.__doc__ - predict_proba.__doc__ = sklearn_ForestClassifier.predict_proba.__doc__ - predict_log_proba.__doc__ = sklearn_ForestClassifier.predict_log_proba.__doc__ - score.__doc__ = sklearn_ForestClassifier.score.__doc__ + fit.__doc__ = _sklearn_ForestClassifier.fit.__doc__ + predict.__doc__ = _sklearn_ForestClassifier.predict.__doc__ + predict_proba.__doc__ = _sklearn_ForestClassifier.predict_proba.__doc__ + predict_log_proba.__doc__ = _sklearn_ForestClassifier.predict_log_proba.__doc__ + score.__doc__ = _sklearn_ForestClassifier.score.__doc__ def _onedal_cpu_supported(self, method_name, *data): class_name = self.__class__.__name__ @@ -842,7 +842,7 @@ def _onedal_score(self, X, y, sample_weight=None, queue=None): ) -class ForestRegressor(sklearn_ForestRegressor, BaseForest): +class ForestRegressor(_sklearn_ForestRegressor, BaseForest): _err = "out_of_bag_error_r2|out_of_bag_error_prediction" _get_tree_state = staticmethod(get_tree_state_reg) @@ -1148,7 +1148,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_ForestRegressor.fit, + "sklearn": _sklearn_ForestRegressor.fit, }, X, y, @@ -1163,7 +1163,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_ForestRegressor.predict, + "sklearn": _sklearn_ForestRegressor.predict, }, X, ) @@ -1175,26 +1175,26 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_ForestRegressor.score, + "sklearn": _sklearn_ForestRegressor.score, }, X, y, sample_weight=sample_weight, ) - fit.__doc__ = sklearn_ForestRegressor.fit.__doc__ - predict.__doc__ = sklearn_ForestRegressor.predict.__doc__ - score.__doc__ = sklearn_ForestRegressor.score.__doc__ + fit.__doc__ = _sklearn_ForestRegressor.fit.__doc__ + predict.__doc__ = _sklearn_ForestRegressor.predict.__doc__ + score.__doc__ = _sklearn_ForestRegressor.score.__doc__ @control_n_jobs(decorated_methods=["fit", "predict", "predict_proba", "score"]) class RandomForestClassifier(ForestClassifier): - __doc__ = sklearn_RandomForestClassifier.__doc__ + __doc__ = _sklearn_RandomForestClassifier.__doc__ _onedal_factory = onedal_RandomForestClassifier if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_RandomForestClassifier._parameter_constraints, + **_sklearn_RandomForestClassifier._parameter_constraints, "max_bins": [Interval(numbers.Integral, 2, None, closed="left")], "min_bin_size": [Interval(numbers.Integral, 1, None, closed="left")], } @@ -1399,12 +1399,12 @@ def __init__( @control_n_jobs(decorated_methods=["fit", "predict"]) class RandomForestRegressor(ForestRegressor): - __doc__ = sklearn_RandomForestRegressor.__doc__ + __doc__ = _sklearn_RandomForestRegressor.__doc__ _onedal_factory = onedal_RandomForestRegressor if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_RandomForestRegressor._parameter_constraints, + **_sklearn_RandomForestRegressor._parameter_constraints, "max_bins": [Interval(numbers.Integral, 2, None, closed="left")], "min_bin_size": [Interval(numbers.Integral, 1, None, closed="left")], } @@ -1600,12 +1600,12 @@ def __init__( @control_n_jobs(decorated_methods=["fit", "predict", "predict_proba", "score"]) class ExtraTreesClassifier(ForestClassifier): - __doc__ = sklearn_ExtraTreesClassifier.__doc__ + __doc__ = _sklearn_ExtraTreesClassifier.__doc__ _onedal_factory = onedal_ExtraTreesClassifier if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_ExtraTreesClassifier._parameter_constraints, + **_sklearn_ExtraTreesClassifier._parameter_constraints, "max_bins": [Interval(numbers.Integral, 2, None, closed="left")], "min_bin_size": [Interval(numbers.Integral, 1, None, closed="left")], } @@ -1810,12 +1810,12 @@ def __init__( @control_n_jobs(decorated_methods=["fit", "predict"]) class ExtraTreesRegressor(ForestRegressor): - __doc__ = sklearn_ExtraTreesRegressor.__doc__ + __doc__ = _sklearn_ExtraTreesRegressor.__doc__ _onedal_factory = onedal_ExtraTreesRegressor if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_ExtraTreesRegressor._parameter_constraints, + **_sklearn_ExtraTreesRegressor._parameter_constraints, "max_bins": [Interval(numbers.Integral, 2, None, closed="left")], "min_bin_size": [Interval(numbers.Integral, 1, None, closed="left")], } @@ -2010,7 +2010,7 @@ def __init__( # Allow for isinstance calls without inheritance changes using ABCMeta -sklearn_RandomForestClassifier.register(RandomForestClassifier) -sklearn_RandomForestRegressor.register(RandomForestRegressor) -sklearn_ExtraTreesClassifier.register(ExtraTreesClassifier) -sklearn_ExtraTreesRegressor.register(ExtraTreesRegressor) +_sklearn_RandomForestClassifier.register(RandomForestClassifier) +_sklearn_RandomForestRegressor.register(RandomForestRegressor) +_sklearn_ExtraTreesClassifier.register(ExtraTreesClassifier) +_sklearn_ExtraTreesRegressor.register(ExtraTreesRegressor) diff --git a/sklearnex/linear_model/linear.py b/sklearnex/linear_model/linear.py index abdab41d99..94f1bc2022 100644 --- a/sklearnex/linear_model/linear.py +++ b/sklearnex/linear_model/linear.py @@ -41,11 +41,11 @@ @register_hyperparameters({"fit": get_hyperparameters("linear_regression", "train")}) @control_n_jobs(decorated_methods=["fit", "predict"]) -class LinearRegression(sklearn_LinearRegression): - __doc__ = sklearn_LinearRegression.__doc__ +class LinearRegression(_sklearn_LinearRegression): + __doc__ = _sklearn_LinearRegression.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**sklearn_LinearRegression._parameter_constraints} + _parameter_constraints: dict = {**_sklearn_LinearRegression._parameter_constraints} def __init__( self, @@ -95,7 +95,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_LinearRegression.fit, + "sklearn": _sklearn_LinearRegression.fit, }, X, y, @@ -118,7 +118,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_LinearRegression.predict, + "sklearn": _sklearn_LinearRegression.predict, }, X, ) @@ -130,7 +130,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_LinearRegression.score, + "sklearn": _sklearn_LinearRegression.score, }, X, y, @@ -297,6 +297,6 @@ def _save_attributes(self): self.__dict__["coef_"] = self._onedal_estimator.coef_ self.__dict__["intercept_"] = self._onedal_estimator.intercept_ - fit.__doc__ = sklearn_LinearRegression.fit.__doc__ - predict.__doc__ = sklearn_LinearRegression.predict.__doc__ - score.__doc__ = sklearn_LinearRegression.score.__doc__ + fit.__doc__ = _sklearn_LinearRegression.fit.__doc__ + predict.__doc__ = _sklearn_LinearRegression.predict.__doc__ + score.__doc__ = _sklearn_LinearRegression.score.__doc__ diff --git a/sklearnex/linear_model/logistic_regression.py b/sklearnex/linear_model/logistic_regression.py index b1399fdb2e..32f1c2dcad 100644 --- a/sklearnex/linear_model/logistic_regression.py +++ b/sklearnex/linear_model/logistic_regression.py @@ -59,13 +59,13 @@ def _save_attributes(self): "score", ] ) - class LogisticRegression(sklearn_LogisticRegression, BaseLogisticRegression): - __doc__ = sklearn_LogisticRegression.__doc__ + class LogisticRegression(_sklearn_LogisticRegression, BaseLogisticRegression): + __doc__ = _sklearn_LogisticRegression.__doc__ intercept_, coef_, n_iter_ = None, None, None if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_LogisticRegression._parameter_constraints + **_sklearn_LogisticRegression._parameter_constraints } def __init__( @@ -115,7 +115,7 @@ def fit(self, X, y, sample_weight=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_LogisticRegression.fit, + "sklearn": _sklearn_LogisticRegression.fit, }, X, y, @@ -130,7 +130,7 @@ def predict(self, X): "predict", { "onedal": self.__class__._onedal_predict, - "sklearn": sklearn_LogisticRegression.predict, + "sklearn": _sklearn_LogisticRegression.predict, }, X, ) @@ -142,7 +142,7 @@ def predict_proba(self, X): "predict_proba", { "onedal": self.__class__._onedal_predict_proba, - "sklearn": sklearn_LogisticRegression.predict_proba, + "sklearn": _sklearn_LogisticRegression.predict_proba, }, X, ) @@ -154,7 +154,7 @@ def predict_log_proba(self, X): "predict_log_proba", { "onedal": self.__class__._onedal_predict_log_proba, - "sklearn": sklearn_LogisticRegression.predict_log_proba, + "sklearn": _sklearn_LogisticRegression.predict_log_proba, }, X, ) @@ -166,7 +166,7 @@ def score(self, X, y, sample_weight=None): "score", { "onedal": self.__class__._onedal_score, - "sklearn": sklearn_LogisticRegression.score, + "sklearn": _sklearn_LogisticRegression.score, }, X, y, @@ -388,11 +388,11 @@ def _onedal_predict_log_proba(self, X, queue=None): assert hasattr(self, "_onedal_estimator") return self._onedal_estimator.predict_log_proba(X, queue=queue) - fit.__doc__ = sklearn_LogisticRegression.fit.__doc__ - predict.__doc__ = sklearn_LogisticRegression.predict.__doc__ - predict_proba.__doc__ = sklearn_LogisticRegression.predict_proba.__doc__ - predict_log_proba.__doc__ = sklearn_LogisticRegression.predict_log_proba.__doc__ - score.__doc__ = sklearn_LogisticRegression.score.__doc__ + fit.__doc__ = _sklearn_LogisticRegression.fit.__doc__ + predict.__doc__ = _sklearn_LogisticRegression.predict.__doc__ + predict_proba.__doc__ = _sklearn_LogisticRegression.predict_proba.__doc__ + predict_log_proba.__doc__ = _sklearn_LogisticRegression.predict_log_proba.__doc__ + score.__doc__ = _sklearn_LogisticRegression.score.__doc__ else: LogisticRegression = LogisticRegression_daal4py diff --git a/sklearnex/neighbors/_lof.py b/sklearnex/neighbors/_lof.py index deed4f5572..82622a40b7 100644 --- a/sklearnex/neighbors/_lof.py +++ b/sklearnex/neighbors/_lof.py @@ -30,16 +30,16 @@ @control_n_jobs(decorated_methods=["fit", "_kneighbors"]) -class LocalOutlierFactor(KNeighborsDispatchingBase, sklearn_LocalOutlierFactor): +class LocalOutlierFactor(KNeighborsDispatchingBase, _sklearn_LocalOutlierFactor): __doc__ = ( - sklearn_LocalOutlierFactor.__doc__ + _sklearn_LocalOutlierFactor.__doc__ + "\n NOTE: When X=None, methods kneighbors, kneighbors_graph, and predict will" + "\n only output numpy arrays. In that case, the only way to offload to gpu" + "\n is to use a global queue (e.g. using config_context)" ) if sklearn_check_version("1.2"): _parameter_constraints: dict = { - **sklearn_LocalOutlierFactor._parameter_constraints + **_sklearn_LocalOutlierFactor._parameter_constraints } # Only certain methods should be taken from knn to prevent code @@ -114,7 +114,7 @@ def fit(self, X, y=None): "fit", { "onedal": self.__class__._onedal_fit, - "sklearn": sklearn_LocalOutlierFactor.fit, + "sklearn": _sklearn_LocalOutlierFactor.fit, }, X, None, @@ -139,7 +139,7 @@ def _predict(self, X=None): # argument is given and it is a dpctl tensor or dpnp array. # This would cause issues in fit_predict. Also, available_if # is hard to unwrap, and this is the most straighforward way. - @available_if(sklearn_LocalOutlierFactor._check_novelty_fit_predict) + @available_if(_sklearn_LocalOutlierFactor._check_novelty_fit_predict) @wrap_output_data def fit_predict(self, X, y=None): """Fit the model to the training set X and return the labels. @@ -173,7 +173,7 @@ def _kneighbors(self, X=None, n_neighbors=None, return_distance=True): "kneighbors", { "onedal": self.__class__._onedal_kneighbors, - "sklearn": sklearn_LocalOutlierFactor.kneighbors, + "sklearn": _sklearn_LocalOutlierFactor.kneighbors, }, X, n_neighbors=n_neighbors, @@ -182,7 +182,7 @@ def _kneighbors(self, X=None, n_neighbors=None, return_distance=True): kneighbors = wrap_output_data(_kneighbors) - @available_if(sklearn_LocalOutlierFactor._check_novelty_score_samples) + @available_if(_sklearn_LocalOutlierFactor._check_novelty_score_samples) @wrap_output_data def score_samples(self, X): """Opposite of the Local Outlier Factor of X. @@ -226,5 +226,5 @@ def score_samples(self, X): return -np.mean(lrd_ratios_array, axis=1) - fit.__doc__ = sklearn_LocalOutlierFactor.fit.__doc__ - kneighbors.__doc__ = sklearn_LocalOutlierFactor.kneighbors.__doc__ + fit.__doc__ = _sklearn_LocalOutlierFactor.fit.__doc__ + kneighbors.__doc__ = _sklearn_LocalOutlierFactor.kneighbors.__doc__ diff --git a/sklearnex/neighbors/common.py b/sklearnex/neighbors/common.py index 63ea780ce1..4cfde76dcc 100644 --- a/sklearnex/neighbors/common.py +++ b/sklearnex/neighbors/common.py @@ -64,7 +64,7 @@ def _fit_validation(self, X, y=None): elif p == np.inf: self.effective_metric_ = "chebyshev" - if not isinstance(X, (KDTree, BallTree, sklearn_NeighborsBase)): + if not isinstance(X, (KDTree, BallTree, _sklearn_NeighborsBase)): self._fit_X = _check_array( X, dtype=[np.float64, np.float32], accept_sparse=True ) @@ -97,7 +97,7 @@ def _fit_validation(self, X, y=None): delattr(self, "_onedal_estimator") # To cover test case when we pass patched # estimator as an input for other estimator - if isinstance(X, sklearn_NeighborsBase): + if isinstance(X, _sklearn_NeighborsBase): self._fit_X = X._fit_X self._tree = X._tree self._fit_method = X._fit_method @@ -155,7 +155,7 @@ def _onedal_supported(self, device, method_name, *data): return patching_status if not patching_status.and_condition( - not isinstance(data[0], (KDTree, BallTree, sklearn_NeighborsBase)), + not isinstance(data[0], (KDTree, BallTree, _sklearn_NeighborsBase)), f"Input type {type(data[0])} is not supported.", ): return patching_status diff --git a/sklearnex/utils/_namespace.py b/sklearnex/utils/_namespace.py index 4526972b7e..2f67737023 100644 --- a/sklearnex/utils/_namespace.py +++ b/sklearnex/utils/_namespace.py @@ -21,7 +21,7 @@ from .._device_offload import dpnp_available if sklearn_check_version("1.2"): - from sklearn.utils._array_api import get_namespace as _sklearn_get_namespace + from sklearn.utils._array_api import get_namespace as sklearn_get_namespace if dpnp_available: import dpnp From 18e95bce17a2c87777f1c542b55887a4c2879f9c Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:31:30 -0700 Subject: [PATCH 14/37] forgotten : --- sklearnex/tests/test_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index fb51a436bd..18a4ee2633 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -20,7 +20,7 @@ from glob import glob import pytest -from sklearn.utils import all_estimators +import sklearn.utils.discovery import all_estimators from sklearnex.tests._utils import PATCHED_MODELS, SPECIAL_INSTANCES @@ -62,7 +62,7 @@ def test_target_offload_ban(): def _sklearnex_walk(func): """this replaces checks on pkgutils to look in sklearnex folders specifically""" - def wrap(*args, **kwargs) + def wrap(*args, **kwargs): if "prefix" in kwargs and kwargs["prefix"] == "sklearn.": kwargs["prefix"] = "sklearnex." if "path" in kwargs: From e764e24d093862009462e7d8f07ba50199808632 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:38:40 -0700 Subject: [PATCH 15/37] isort fixes --- sklearnex/tests/test_common.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 18a4ee2633..7957bb597d 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -19,8 +19,10 @@ import pkgutil from glob import glob +import all_estimators +import import import pytest -import sklearn.utils.discovery import all_estimators +import sklearn.utils.discovery from sklearnex.tests._utils import PATCHED_MODELS, SPECIAL_INSTANCES From e882951058066a3d041e1b347bae578cf56adf62 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:46:10 -0700 Subject: [PATCH 16/37] remove preview from search --- sklearnex/tests/test_common.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 7957bb597d..d7ac776276 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -19,8 +19,6 @@ import pkgutil from glob import glob -import all_estimators -import import import pytest import sklearn.utils.discovery @@ -64,6 +62,7 @@ def test_target_offload_ban(): def _sklearnex_walk(func): """this replaces checks on pkgutils to look in sklearnex folders specifically""" + def wrap(*args, **kwargs): if "prefix" in kwargs and kwargs["prefix"] == "sklearn.": kwargs["prefix"] = "sklearnex." @@ -71,12 +70,21 @@ def wrap(*args, **kwargs): # force root to sklearnex kwargs["path"] = [str(pathlib.Path(__file__).parent.parent)] return func(*args, **kwargs) + return wrap def test_all_estimators_covered(monkeypatch): monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk(pkgutil.walk_packages)) - estimators = all_estimators() + # remove preview from search + monkeypatch.setattr( + sklearn.utils.discovery, + "_MODULE_TO_IGNORE", + sklearn.utils.discovery._MODULE_TO_IGNORE + ["preview"], + ) + estimators = sklearn.utils.discovery.all_estimators() print(estimators) for i in estimators: - assert i in PATCHED_MODELS or any([issubclass(est, i) for est in PATCHED_MODELS.values()]), f"{i} not included" + assert i in PATCHED_MODELS or any( + [issubclass(est, i) for est in PATCHED_MODELS.values()] + ), f"{i} not included" From 033918884a578dee5d770d7f6cf626a694ebf69e Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:48:31 -0700 Subject: [PATCH 17/37] its a set --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index d7ac776276..de63f9dbe2 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -80,7 +80,7 @@ def test_all_estimators_covered(monkeypatch): monkeypatch.setattr( sklearn.utils.discovery, "_MODULE_TO_IGNORE", - sklearn.utils.discovery._MODULE_TO_IGNORE + ["preview"], + sklearn.utils.discovery._MODULE_TO_IGNORE | {"preview"}, ) estimators = sklearn.utils.discovery.all_estimators() print(estimators) From 2c4108583ace4a7a30b7b2af0500dea52e63d813 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 04:51:17 -0700 Subject: [PATCH 18/37] formatting --- sklearnex/linear_model/linear.py | 4 +++- sklearnex/neighbors/knn_unsupervised.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sklearnex/linear_model/linear.py b/sklearnex/linear_model/linear.py index 94f1bc2022..7e605da50e 100644 --- a/sklearnex/linear_model/linear.py +++ b/sklearnex/linear_model/linear.py @@ -45,7 +45,9 @@ class LinearRegression(_sklearn_LinearRegression): __doc__ = _sklearn_LinearRegression.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**_sklearn_LinearRegression._parameter_constraints} + _parameter_constraints: dict = { + **_sklearn_LinearRegression._parameter_constraints + } def __init__( self, diff --git a/sklearnex/neighbors/knn_unsupervised.py b/sklearnex/neighbors/knn_unsupervised.py index b314ead6f5..51e2679df1 100755 --- a/sklearnex/neighbors/knn_unsupervised.py +++ b/sklearnex/neighbors/knn_unsupervised.py @@ -29,7 +29,9 @@ class NearestNeighbors(KNeighborsDispatchingBase, _sklearn_NearestNeighbors): __doc__ = _sklearn_NearestNeighbors.__doc__ if sklearn_check_version("1.2"): - _parameter_constraints: dict = {**_sklearn_NearestNeighbors._parameter_constraints} + _parameter_constraints: dict = { + **_sklearn_NearestNeighbors._parameter_constraints + } @_deprecate_positional_args def __init__( From 60693cbbe126c9355e4d0ed8d7a06eb03d8172cf Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 05:16:59 -0700 Subject: [PATCH 19/37] manually remove preview from lsit --- sklearnex/linear_model/logistic_regression.py | 4 ++-- sklearnex/tests/test_common.py | 20 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sklearnex/linear_model/logistic_regression.py b/sklearnex/linear_model/logistic_regression.py index 32f1c2dcad..988a559e9b 100644 --- a/sklearnex/linear_model/logistic_regression.py +++ b/sklearnex/linear_model/logistic_regression.py @@ -19,7 +19,7 @@ from daal4py.sklearn._utils import daal_check_version from daal4py.sklearn.linear_model.logistic_path import ( - LogisticRegression as LogisticRegression_daal4py, + LogisticRegression as _daal4py_LogisticRegression, ) if daal_check_version((2024, "P", 1)): @@ -395,7 +395,7 @@ def _onedal_predict_log_proba(self, X, queue=None): score.__doc__ = _sklearn_LogisticRegression.score.__doc__ else: - LogisticRegression = LogisticRegression_daal4py + LogisticRegression = _daal4py_LogisticRegression logging.warning( "Sklearnex LogisticRegression requires oneDAL version >= 2024.0.1 " diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index de63f9dbe2..cd262881d1 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -20,7 +20,7 @@ from glob import glob import pytest -import sklearn.utils.discovery +from sklearn.utils import all_estimators from sklearnex.tests._utils import PATCHED_MODELS, SPECIAL_INSTANCES @@ -76,15 +76,11 @@ def wrap(*args, **kwargs): def test_all_estimators_covered(monkeypatch): monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk(pkgutil.walk_packages)) - # remove preview from search - monkeypatch.setattr( - sklearn.utils.discovery, - "_MODULE_TO_IGNORE", - sklearn.utils.discovery._MODULE_TO_IGNORE | {"preview"}, - ) - estimators = sklearn.utils.discovery.all_estimators() + estimators = all_estimators() print(estimators) - for i in estimators: - assert i in PATCHED_MODELS or any( - [issubclass(est, i) for est in PATCHED_MODELS.values()] - ), f"{i} not included" + for name, obj in estimators: + # do nothing if defined in preview + if "preview" not in obj.__module__: + assert name in PATCHED_MODELS or any( + [issubclass(est, obj) for est in PATCHED_MODELS.values()] + ), f"{name} not included" From d30bc0188e0db3b9299179056940f97525e2a7f7 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 05:37:41 -0700 Subject: [PATCH 20/37] add BasicStatistics --- sklearnex/tests/_utils.py | 3 +++ sklearnex/tests/test_common.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/sklearnex/tests/_utils.py b/sklearnex/tests/_utils.py index 413747a1a9..a720010a38 100755 --- a/sklearnex/tests/_utils.py +++ b/sklearnex/tests/_utils.py @@ -33,6 +33,7 @@ from onedal.tests.utils._dataframes_support import _convert_to_dataframe from sklearnex import get_patch_map, patch_sklearn, sklearn_is_patched, unpatch_sklearn +from sklearnex.basic_statistics import BasicStatistics, IncrementalBasicStatistics from sklearnex.linear_model import LogisticRegression from sklearnex.neighbors import ( KNeighborsClassifier, @@ -129,6 +130,8 @@ def __getitem__(self, key): KNeighborsRegressor(algorithm="brute"), NearestNeighbors(algorithm="brute"), LogisticRegression(solver="newton-cg"), + BasicStatistics(), + IncrementalBasicStatistics(), ] } ) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index cd262881d1..d9f3d2d2d8 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -81,6 +81,6 @@ def test_all_estimators_covered(monkeypatch): for name, obj in estimators: # do nothing if defined in preview if "preview" not in obj.__module__: - assert name in PATCHED_MODELS or any( - [issubclass(est, obj) for est in PATCHED_MODELS.values()] + assert any([issubclass(est, obj) for est in PATCHED_MODELS.values()]) or any( + [issubclass(est, obj.__class__) in SPECIAL_INSTANCES.values()] ), f"{name} not included" From e0d7f281ebe6ed7834c81d465183cbb5010032b2 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 05:46:09 -0700 Subject: [PATCH 21/37] fix mistake --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index d9f3d2d2d8..0fcb3a289f 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -82,5 +82,5 @@ def test_all_estimators_covered(monkeypatch): # do nothing if defined in preview if "preview" not in obj.__module__: assert any([issubclass(est, obj) for est in PATCHED_MODELS.values()]) or any( - [issubclass(est, obj.__class__) in SPECIAL_INSTANCES.values()] + [issubclass(est.__class__, obj) for est in SPECIAL_INSTANCES.values()] ), f"{name} not included" From a5f530eedeec5b80a4a979fe3ade4b6814d3bbba Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Mon, 9 Sep 2024 16:49:49 +0200 Subject: [PATCH 22/37] Update basic_statistics.py --- sklearnex/basic_statistics/basic_statistics.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sklearnex/basic_statistics/basic_statistics.py b/sklearnex/basic_statistics/basic_statistics.py index 546d52b5b3..d8ef651810 100644 --- a/sklearnex/basic_statistics/basic_statistics.py +++ b/sklearnex/basic_statistics/basic_statistics.py @@ -62,17 +62,17 @@ class BasicStatistics(BaseEstimator): """ def __init__(self, result_options="all"): - self.options = result_options + self.result_options = result_options _onedal_basic_statistics = staticmethod(onedal_BasicStatistics) def _save_attributes(self): assert hasattr(self, "_onedal_estimator") - if self.options == "all": + if self.result_options == "all": result_options = onedal_BasicStatistics.get_all_result_options() else: - result_options = self.options + result_options = self.result_options if isinstance(result_options, str): setattr(self, result_options, getattr(self._onedal_estimator, result_options)) @@ -99,7 +99,7 @@ def _onedal_fit(self, X, sample_weight=None, queue=None): sample_weight = _check_sample_weight(sample_weight, X) onedal_params = { - "result_options": self.options, + "result_options": self.result_options, } if not hasattr(self, "_onedal_estimator"): From b82b4c328f2f28db35e802b0bc38181eb8fb5681 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Mon, 9 Sep 2024 19:28:32 +0200 Subject: [PATCH 23/37] Delete sklearnex/linear_model/logistic_path.py --- sklearnex/linear_model/logistic_path.py | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 sklearnex/linear_model/logistic_path.py diff --git a/sklearnex/linear_model/logistic_path.py b/sklearnex/linear_model/logistic_path.py deleted file mode 100644 index ea25abfd80..0000000000 --- a/sklearnex/linear_model/logistic_path.py +++ /dev/null @@ -1,17 +0,0 @@ -# =============================================================================== -# Copyright 2021 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# =============================================================================== - -from daal4py.sklearn.linear_model import LogisticRegression, logistic_regression_path From eeadc04153dcd46ae14ffcb84e3cce840b779a3c Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Tue, 10 Sep 2024 00:29:08 +0200 Subject: [PATCH 24/37] Update test_common.py --- sklearnex/tests/test_common.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 0fcb3a289f..3e45bf05ce 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -69,7 +69,10 @@ def wrap(*args, **kwargs): if "path" in kwargs: # force root to sklearnex kwargs["path"] = [str(pathlib.Path(__file__).parent.parent)] - return func(*args, **kwargs) + for walk in func(*args, **kwargs): + # Do not allow spmd to be checked + if "spmd" not in walk[1]: + yield walk return wrap From 18374646ca207770f65bf940f9a162eea52b8757 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Tue, 10 Sep 2024 06:49:12 +0200 Subject: [PATCH 25/37] Update test_common.py --- sklearnex/tests/test_common.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 3e45bf05ce..182ba44a62 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -60,7 +60,7 @@ def test_target_offload_ban(): def _sklearnex_walk(func): - """this replaces checks on pkgutils to look in sklearnex + """this replaces checks on pkgutils to look through sklearnex folders specifically""" def wrap(*args, **kwargs): @@ -69,11 +69,10 @@ def wrap(*args, **kwargs): if "path" in kwargs: # force root to sklearnex kwargs["path"] = [str(pathlib.Path(__file__).parent.parent)] - for walk in func(*args, **kwargs): - # Do not allow spmd to be checked - if "spmd" not in walk[1]: - yield walk - + for pkginfo in func(*args, **kwargs): + # Do not allow spmd to be yielded + if "spmd" not in pkginfo.name.split("."): + yield pkginfo return wrap From 744d260480bcc45302cbc8097a04c02bdb2421f4 Mon Sep 17 00:00:00 2001 From: icfaust Date: Mon, 9 Sep 2024 23:57:47 -0700 Subject: [PATCH 26/37] formatting --- sklearnex/tests/test_common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 182ba44a62..a0282946ae 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -73,6 +73,7 @@ def wrap(*args, **kwargs): # Do not allow spmd to be yielded if "spmd" not in pkginfo.name.split("."): yield pkginfo + return wrap From 93143600607e62a337b404d5a49d2f6e069ea962 Mon Sep 17 00:00:00 2001 From: icfaust Date: Tue, 10 Sep 2024 00:04:54 -0700 Subject: [PATCH 27/37] add docstrings --- sklearnex/tests/test_common.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index a0282946ae..dbf459fbf6 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -78,6 +78,11 @@ def wrap(*args, **kwargs): def test_all_estimators_covered(monkeypatch): + """check that all estimators defined in sklearnex are available in either the + patch map or covered in special testing via SPECIAL_INSTANCES. The estimator + must inherit sklearn's BaseEstimator and must not have a leading underscore. + The sklearnex.spmd and sklearnex.preview packages are not tested. + """ monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk(pkgutil.walk_packages)) estimators = all_estimators() print(estimators) From f2da21d8b099461c00617a9e8c661553c7b5b886 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Tue, 10 Sep 2024 09:51:14 +0200 Subject: [PATCH 28/37] Update sklearnex/tests/test_common.py Co-authored-by: Samir Nasibli --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index dbf459fbf6..9e7bda071f 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -78,7 +78,7 @@ def wrap(*args, **kwargs): def test_all_estimators_covered(monkeypatch): - """check that all estimators defined in sklearnex are available in either the + """Check that all estimators defined in sklearnex are available in either the patch map or covered in special testing via SPECIAL_INSTANCES. The estimator must inherit sklearn's BaseEstimator and must not have a leading underscore. The sklearnex.spmd and sklearnex.preview packages are not tested. From 6e1e81525bcb0d62b68afa38a004cbc5cf28eea7 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Wed, 18 Sep 2024 12:45:39 +0200 Subject: [PATCH 29/37] Update test_common.py --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 9e7bda071f..2c0d775c92 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -22,7 +22,7 @@ import pytest from sklearn.utils import all_estimators -from sklearnex.tests._utils import PATCHED_MODELS, SPECIAL_INSTANCES +from sklearnex.tests.utils import PATCHED_MODELS, SPECIAL_INSTANCES ALLOWED_LOCATIONS = [ "_config.py", From 0a6eb24f622b37e755fb28bf5f4c7a3e52ff1988 Mon Sep 17 00:00:00 2001 From: icfaust Date: Tue, 24 Sep 2024 23:45:56 -0700 Subject: [PATCH 30/37] collect all uncovered estimators for assert --- sklearnex/tests/test_common.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 2c0d775c92..ea1336cc24 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -84,11 +84,16 @@ def test_all_estimators_covered(monkeypatch): The sklearnex.spmd and sklearnex.preview packages are not tested. """ monkeypatch.setattr(pkgutil, "walk_packages", _sklearnex_walk(pkgutil.walk_packages)) - estimators = all_estimators() - print(estimators) + estimators = all_estimators() # list of tuples + uncovered_estimators = [] for name, obj in estimators: # do nothing if defined in preview - if "preview" not in obj.__module__: - assert any([issubclass(est, obj) for est in PATCHED_MODELS.values()]) or any( - [issubclass(est.__class__, obj) for est in SPECIAL_INSTANCES.values()] - ), f"{name} not included" + if "preview" not in obj.__module__ and not ( + any([issubclass(est, obj) for est in PATCHED_MODELS.values()]) + or any([issubclass(est.__class__, obj) for est in SPECIAL_INSTANCES.values()]) + ): + uncovered_estimators += [".".join([obj.__module__, name])] + + assert ( + uncovered_estimators == [] + ), f"{uncovered_estimators} are currently not included" From da232e9c9ac3fb3c6548fd6406e8708cfe8cf0ac Mon Sep 17 00:00:00 2001 From: icfaust Date: Tue, 24 Sep 2024 23:52:28 -0700 Subject: [PATCH 31/37] isort fixes --- sklearnex/tests/test_common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_common.py b/sklearnex/tests/test_common.py index 3af79e79f1..741db14841 100644 --- a/sklearnex/tests/test_common.py +++ b/sklearnex/tests/test_common.py @@ -26,8 +26,8 @@ import numpy as np import pytest import scipy -from sklearn.utils import all_estimators import sklearn.utils.validation +from sklearn.utils import all_estimators from daal4py.sklearn._utils import sklearn_check_version from sklearnex.tests.utils import ( From a722b4fcf823588ff8ad9843cb1d60b06ffb6809 Mon Sep 17 00:00:00 2001 From: icfaust Date: Wed, 25 Sep 2024 00:31:03 -0700 Subject: [PATCH 32/37] add underscores --- sklearnex/cluster/dbscan.py | 2 +- sklearnex/cluster/k_means.py | 2 +- sklearnex/decomposition/pca.py | 2 +- sklearnex/linear_model/linear.py | 2 +- sklearnex/linear_model/logistic_regression.py | 2 +- sklearnex/neighbors/_lof.py | 2 +- sklearnex/neighbors/knn_classification.py | 2 +- sklearnex/neighbors/knn_regression.py | 2 +- sklearnex/neighbors/knn_unsupervised.py | 2 +- sklearnex/preview/covariance/covariance.py | 2 +- sklearnex/preview/decomposition/incremental_pca.py | 2 +- sklearnex/preview/linear_model/ridge.py | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sklearnex/cluster/dbscan.py b/sklearnex/cluster/dbscan.py index 65b92cab31..ef5f6b78d9 100755 --- a/sklearnex/cluster/dbscan.py +++ b/sklearnex/cluster/dbscan.py @@ -34,7 +34,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_DBSCAN._validate_data + validate_data = _sklearn_DBSCAN._validate_data class BaseDBSCAN(ABC): diff --git a/sklearnex/cluster/k_means.py b/sklearnex/cluster/k_means.py index 67e436a1a0..d97878db67 100644 --- a/sklearnex/cluster/k_means.py +++ b/sklearnex/cluster/k_means.py @@ -44,7 +44,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_KMeans._validate_data + validate_data = _sklearn_KMeans._validate_data @control_n_jobs(decorated_methods=["fit", "predict", "transform", "fit_transform"]) class KMeans(_sklearn_KMeans): diff --git a/sklearnex/decomposition/pca.py b/sklearnex/decomposition/pca.py index fb9a3ae01c..18ad6da13f 100755 --- a/sklearnex/decomposition/pca.py +++ b/sklearnex/decomposition/pca.py @@ -47,7 +47,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_PCA._validate_data + validate_data = _sklearn_PCA._validate_data @control_n_jobs(decorated_methods=["fit", "transform", "fit_transform"]) class PCA(_sklearn_PCA): diff --git a/sklearnex/linear_model/linear.py b/sklearnex/linear_model/linear.py index 4327aea2a4..ecff318025 100644 --- a/sklearnex/linear_model/linear.py +++ b/sklearnex/linear_model/linear.py @@ -42,7 +42,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_LinearRegression._validate_data + validate_data = _sklearn_LinearRegression._validate_data @register_hyperparameters({"fit": get_hyperparameters("linear_regression", "train")}) diff --git a/sklearnex/linear_model/logistic_regression.py b/sklearnex/linear_model/logistic_regression.py index b083676e27..f0ce1c3913 100644 --- a/sklearnex/linear_model/logistic_regression.py +++ b/sklearnex/linear_model/logistic_regression.py @@ -42,7 +42,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_LogisticRegression._validate_data + validate_data = _sklearn_LogisticRegression._validate_data _sparsity_enabled = daal_check_version((2024, "P", 700)) diff --git a/sklearnex/neighbors/_lof.py b/sklearnex/neighbors/_lof.py index 412cca84f9..39c163fa14 100644 --- a/sklearnex/neighbors/_lof.py +++ b/sklearnex/neighbors/_lof.py @@ -32,7 +32,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_LocalOutlierFactor._validate_data + validate_data = _sklearn_LocalOutlierFactor._validate_data @control_n_jobs(decorated_methods=["fit", "_kneighbors"]) diff --git a/sklearnex/neighbors/knn_classification.py b/sklearnex/neighbors/knn_classification.py index df7f80bd89..3b9871b4cf 100755 --- a/sklearnex/neighbors/knn_classification.py +++ b/sklearnex/neighbors/knn_classification.py @@ -31,7 +31,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_KNeighborsClassifier._validate_data + validate_data = _sklearn_KNeighborsClassifier._validate_data @control_n_jobs( diff --git a/sklearnex/neighbors/knn_regression.py b/sklearnex/neighbors/knn_regression.py index c8d4f54273..83bfad846f 100755 --- a/sklearnex/neighbors/knn_regression.py +++ b/sklearnex/neighbors/knn_regression.py @@ -30,7 +30,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_KNeighborsRegressor._validate_data + validate_data = _sklearn_KNeighborsRegressor._validate_data @control_n_jobs(decorated_methods=["fit", "predict", "kneighbors"]) diff --git a/sklearnex/neighbors/knn_unsupervised.py b/sklearnex/neighbors/knn_unsupervised.py index d822fb5af1..b5691f9039 100755 --- a/sklearnex/neighbors/knn_unsupervised.py +++ b/sklearnex/neighbors/knn_unsupervised.py @@ -27,7 +27,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_NearestNeighbors._validate_data + validate_data = _sklearn_NearestNeighbors._validate_data @control_n_jobs(decorated_methods=["fit", "kneighbors"]) diff --git a/sklearnex/preview/covariance/covariance.py b/sklearnex/preview/covariance/covariance.py index 5448c404c7..04bdc0be8d 100644 --- a/sklearnex/preview/covariance/covariance.py +++ b/sklearnex/preview/covariance/covariance.py @@ -34,7 +34,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_EmpiricalCovariance._validate_data + validate_data = _sklearn_EmpiricalCovariance._validate_data @register_hyperparameters({"fit": get_hyperparameters("covariance", "compute")}) diff --git a/sklearnex/preview/decomposition/incremental_pca.py b/sklearnex/preview/decomposition/incremental_pca.py index 8afc86a55a..aa8d7e78f1 100644 --- a/sklearnex/preview/decomposition/incremental_pca.py +++ b/sklearnex/preview/decomposition/incremental_pca.py @@ -28,7 +28,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_IncrementalPCA._validate_data + validate_data = _sklearn_IncrementalPCA._validate_data @control_n_jobs( diff --git a/sklearnex/preview/linear_model/ridge.py b/sklearnex/preview/linear_model/ridge.py index 8d5259aa11..b367c1ed72 100644 --- a/sklearnex/preview/linear_model/ridge.py +++ b/sklearnex/preview/linear_model/ridge.py @@ -43,7 +43,7 @@ if sklearn_check_version("1.6"): from sklearn.utils.validation import validate_data else: - validate_data = sklearn_Ridge._validate_data + validate_data = _sklearn_Ridge._validate_data def _is_numeric_scalar(value): """ From 986cebaf1b6b5ac3b2340239f6c10ea23e50f7b3 Mon Sep 17 00:00:00 2001 From: icfaust Date: Wed, 25 Sep 2024 00:55:35 -0700 Subject: [PATCH 33/37] fix validate_data checks for IncBS --- .../incremental_basic_statistics.py | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/sklearnex/basic_statistics/incremental_basic_statistics.py b/sklearnex/basic_statistics/incremental_basic_statistics.py index a7906951fc..a9bb01637b 100644 --- a/sklearnex/basic_statistics/incremental_basic_statistics.py +++ b/sklearnex/basic_statistics/incremental_basic_statistics.py @@ -146,21 +146,22 @@ def _onedal_finalize_fit(self, queue=None): self._onedal_estimator.finalize_fit(queue=queue) self._need_to_finalize = False - def _onedal_partial_fit(self, X, sample_weight=None, queue=None): + def _onedal_partial_fit(self, X, sample_weight=None, queue=None, check_input=True): first_pass = not hasattr(self, "n_samples_seen_") or self.n_samples_seen_ == 0 - if sklearn_check_version("1.0"): - X = validate_data( - self, - X, - dtype=[np.float64, np.float32], - reset=first_pass, - ) - else: - X = check_array( - X, - dtype=[np.float64, np.float32], - ) + if check_input: + if sklearn_check_version("1.0"): + X = validate_data( + self, + X, + dtype=[np.float64, np.float32], + reset=first_pass, + ) + else: + X = check_array( + X, + dtype=[np.float64, np.float32], + ) if sample_weight is not None: sample_weight = _check_sample_weight(sample_weight, X) @@ -206,7 +207,9 @@ def _onedal_fit(self, X, sample_weight=None, queue=None): for batch in gen_batches(X.shape[0], self.batch_size_): X_batch = X[batch] weights_batch = sample_weight[batch] if sample_weight is not None else None - self._onedal_partial_fit(X_batch, weights_batch, queue=queue) + self._onedal_partial_fit( + X_batch, weights_batch, queue=queue, check_input=False + ) self.n_features_in_ = X.shape[1] @@ -235,7 +238,7 @@ def __getattr__(self, attr): f"'{self.__class__.__name__}' object has no attribute '{attr}'" ) - def partial_fit(self, X, sample_weight=None): + def partial_fit(self, X, sample_weight=None, check_input=True): """Incremental fit with X. All of X is processed as a single batch. Parameters @@ -250,6 +253,9 @@ def partial_fit(self, X, sample_weight=None): sample_weight : array-like of shape (n_samples,), default=None Weights for compute weighted statistics, where `n_samples` is the number of samples. + check_input : bool, default=True + Run check_array on X. + Returns ------- self : object @@ -264,6 +270,7 @@ def partial_fit(self, X, sample_weight=None): }, X, sample_weight, + check_input=check_input, ) return self From 1f4154fd1bd51ed03f489b3c20521ee8db4efe6f Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Wed, 25 Sep 2024 15:42:05 +0200 Subject: [PATCH 34/37] Update k_means.py --- sklearnex/cluster/k_means.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sklearnex/cluster/k_means.py b/sklearnex/cluster/k_means.py index 33df5c8406..0ef7282003 100644 --- a/sklearnex/cluster/k_means.py +++ b/sklearnex/cluster/k_means.py @@ -47,8 +47,8 @@ validate_data = _sklearn_KMeans._validate_data @control_n_jobs(decorated_methods=["fit", "fit_transform", "predict", "score"]) - class KMeans(sklearn_KMeans): - __doc__ = sklearn_KMeans.__doc__ + class KMeans(_sklearn_KMeans): + __doc__ = _sklearn_KMeans.__doc__ if sklearn_check_version("1.2"): _parameter_constraints: dict = {**_sklearn_KMeans._parameter_constraints} From 8a7bb36d01deec99bd9fb251ce73fb724011468d Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Mon, 7 Oct 2024 08:57:22 +0200 Subject: [PATCH 35/37] Update test_run_to_run_stability.py --- sklearnex/tests/test_run_to_run_stability.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sklearnex/tests/test_run_to_run_stability.py b/sklearnex/tests/test_run_to_run_stability.py index bae2d27a83..411ff68a2e 100755 --- a/sklearnex/tests/test_run_to_run_stability.py +++ b/sklearnex/tests/test_run_to_run_stability.py @@ -193,6 +193,8 @@ def test_special_estimator_stability(estimator, method, dataframe, queue): pytest.skip(f"stability not guaranteed for {estimator}") if "KMeans" in estimator and method == "score" and queue == None: pytest.skip(f"variation observed in KMeans.score") + if estimator == "BasicStatistics" and queue == None: + pytest.skip(f"BasicStatistics not deterministic") if "NearestNeighbors" in estimator and "radius" in method: pytest.skip(f"RadiusNeighbors estimator not implemented in sklearnex") _skip_neighbors(estimator, method) From 1a69981e358e971be1e4c4bd10c50884760305f0 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Mon, 7 Oct 2024 09:06:16 +0200 Subject: [PATCH 36/37] Update basic_statistics.py --- sklearnex/basic_statistics/basic_statistics.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sklearnex/basic_statistics/basic_statistics.py b/sklearnex/basic_statistics/basic_statistics.py index 8b1dc3d02a..277934dd98 100644 --- a/sklearnex/basic_statistics/basic_statistics.py +++ b/sklearnex/basic_statistics/basic_statistics.py @@ -42,6 +42,9 @@ class BasicStatistics(BaseEstimator): """ Estimator for basic statistics. Allows to compute basic statistics for provided data. + Note, some results can exhibit small variations due to + floating point error accumulation and multithreading. + Parameters ---------- result_options: string or list, default='all' From 87e37f42183fc7358973a7bea3f80c405df17688 Mon Sep 17 00:00:00 2001 From: Ian Faust Date: Mon, 7 Oct 2024 11:37:20 +0200 Subject: [PATCH 37/37] Update test_run_to_run_stability.py --- sklearnex/tests/test_run_to_run_stability.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearnex/tests/test_run_to_run_stability.py b/sklearnex/tests/test_run_to_run_stability.py index 411ff68a2e..efd8cf8acc 100755 --- a/sklearnex/tests/test_run_to_run_stability.py +++ b/sklearnex/tests/test_run_to_run_stability.py @@ -193,7 +193,7 @@ def test_special_estimator_stability(estimator, method, dataframe, queue): pytest.skip(f"stability not guaranteed for {estimator}") if "KMeans" in estimator and method == "score" and queue == None: pytest.skip(f"variation observed in KMeans.score") - if estimator == "BasicStatistics" and queue == None: + if estimator == "BasicStatistics()" and queue == None: pytest.skip(f"BasicStatistics not deterministic") if "NearestNeighbors" in estimator and "radius" in method: pytest.skip(f"RadiusNeighbors estimator not implemented in sklearnex")