scikit-learn-intelex 2025.4.0__py313-none-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scikit-learn-intelex might be problematic. Click here for more details.
- daal4py/__init__.py +73 -0
- daal4py/__main__.py +58 -0
- daal4py/_daal4py.cpython-313-x86_64-linux-gnu.so +0 -0
- daal4py/doc/third-party-programs.txt +424 -0
- daal4py/mb/__init__.py +19 -0
- daal4py/mb/model_builders.py +377 -0
- daal4py/mpi_transceiver.cpython-313-x86_64-linux-gnu.so +0 -0
- daal4py/sklearn/__init__.py +40 -0
- daal4py/sklearn/_n_jobs_support.py +248 -0
- daal4py/sklearn/_utils.py +245 -0
- daal4py/sklearn/cluster/__init__.py +20 -0
- daal4py/sklearn/cluster/dbscan.py +165 -0
- daal4py/sklearn/cluster/k_means.py +597 -0
- daal4py/sklearn/cluster/tests/test_dbscan.py +109 -0
- daal4py/sklearn/decomposition/__init__.py +19 -0
- daal4py/sklearn/decomposition/_pca.py +524 -0
- daal4py/sklearn/ensemble/AdaBoostClassifier.py +196 -0
- daal4py/sklearn/ensemble/GBTDAAL.py +337 -0
- daal4py/sklearn/ensemble/__init__.py +27 -0
- daal4py/sklearn/ensemble/_forest.py +1397 -0
- daal4py/sklearn/ensemble/tests/test_decision_forest.py +206 -0
- daal4py/sklearn/linear_model/__init__.py +29 -0
- daal4py/sklearn/linear_model/_coordinate_descent.py +848 -0
- daal4py/sklearn/linear_model/_linear.py +272 -0
- daal4py/sklearn/linear_model/_ridge.py +325 -0
- daal4py/sklearn/linear_model/coordinate_descent.py +17 -0
- daal4py/sklearn/linear_model/linear.py +17 -0
- daal4py/sklearn/linear_model/logistic_loss.py +195 -0
- daal4py/sklearn/linear_model/logistic_path.py +1026 -0
- daal4py/sklearn/linear_model/ridge.py +17 -0
- daal4py/sklearn/linear_model/tests/test_linear.py +208 -0
- daal4py/sklearn/linear_model/tests/test_ridge.py +69 -0
- daal4py/sklearn/manifold/__init__.py +19 -0
- daal4py/sklearn/manifold/_t_sne.py +405 -0
- daal4py/sklearn/metrics/__init__.py +20 -0
- daal4py/sklearn/metrics/_pairwise.py +236 -0
- daal4py/sklearn/metrics/_ranking.py +210 -0
- daal4py/sklearn/model_selection/__init__.py +19 -0
- daal4py/sklearn/model_selection/_split.py +309 -0
- daal4py/sklearn/model_selection/tests/test_split.py +56 -0
- daal4py/sklearn/monkeypatch/__init__.py +0 -0
- daal4py/sklearn/monkeypatch/dispatcher.py +232 -0
- daal4py/sklearn/monkeypatch/tests/_models_info.py +161 -0
- daal4py/sklearn/monkeypatch/tests/test_monkeypatch.py +71 -0
- daal4py/sklearn/monkeypatch/tests/test_patching.py +90 -0
- daal4py/sklearn/monkeypatch/tests/utils/_launch_algorithms.py +117 -0
- daal4py/sklearn/neighbors/__init__.py +21 -0
- daal4py/sklearn/neighbors/_base.py +503 -0
- daal4py/sklearn/neighbors/_classification.py +139 -0
- daal4py/sklearn/neighbors/_regression.py +74 -0
- daal4py/sklearn/neighbors/_unsupervised.py +55 -0
- daal4py/sklearn/neighbors/tests/test_kneighbors.py +113 -0
- daal4py/sklearn/svm/__init__.py +19 -0
- daal4py/sklearn/svm/svm.py +734 -0
- daal4py/sklearn/utils/__init__.py +21 -0
- daal4py/sklearn/utils/base.py +75 -0
- daal4py/sklearn/utils/tests/test_utils.py +51 -0
- daal4py/sklearn/utils/validation.py +696 -0
- onedal/__init__.py +83 -0
- onedal/_config.py +54 -0
- onedal/_device_offload.py +204 -0
- onedal/_onedal_py_dpc.cpython-313-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_host.cpython-313-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_spmd_dpc.cpython-313-x86_64-linux-gnu.so +0 -0
- onedal/basic_statistics/__init__.py +20 -0
- onedal/basic_statistics/basic_statistics.py +107 -0
- onedal/basic_statistics/incremental_basic_statistics.py +175 -0
- onedal/basic_statistics/tests/test_basic_statistics.py +242 -0
- onedal/basic_statistics/tests/test_incremental_basic_statistics.py +279 -0
- onedal/basic_statistics/tests/utils.py +50 -0
- onedal/cluster/__init__.py +27 -0
- onedal/cluster/dbscan.py +105 -0
- onedal/cluster/kmeans.py +557 -0
- onedal/cluster/kmeans_init.py +112 -0
- onedal/cluster/tests/test_dbscan.py +125 -0
- onedal/cluster/tests/test_kmeans.py +88 -0
- onedal/cluster/tests/test_kmeans_init.py +93 -0
- onedal/common/_base.py +38 -0
- onedal/common/_estimator_checks.py +47 -0
- onedal/common/_mixin.py +62 -0
- onedal/common/_policy.py +55 -0
- onedal/common/_spmd_policy.py +30 -0
- onedal/common/hyperparameters.py +125 -0
- onedal/common/tests/test_policy.py +76 -0
- onedal/common/tests/test_sycl.py +128 -0
- onedal/covariance/__init__.py +20 -0
- onedal/covariance/covariance.py +122 -0
- onedal/covariance/incremental_covariance.py +161 -0
- onedal/covariance/tests/test_covariance.py +50 -0
- onedal/covariance/tests/test_incremental_covariance.py +190 -0
- onedal/datatypes/__init__.py +19 -0
- onedal/datatypes/_data_conversion.py +121 -0
- onedal/datatypes/tests/common.py +126 -0
- onedal/datatypes/tests/test_data.py +475 -0
- onedal/decomposition/__init__.py +20 -0
- onedal/decomposition/incremental_pca.py +214 -0
- onedal/decomposition/pca.py +186 -0
- onedal/decomposition/tests/test_incremental_pca.py +285 -0
- onedal/ensemble/__init__.py +29 -0
- onedal/ensemble/forest.py +736 -0
- onedal/ensemble/tests/test_random_forest.py +97 -0
- onedal/linear_model/__init__.py +27 -0
- onedal/linear_model/incremental_linear_model.py +292 -0
- onedal/linear_model/linear_model.py +325 -0
- onedal/linear_model/logistic_regression.py +247 -0
- onedal/linear_model/tests/test_incremental_linear_regression.py +213 -0
- onedal/linear_model/tests/test_incremental_ridge_regression.py +171 -0
- onedal/linear_model/tests/test_linear_regression.py +259 -0
- onedal/linear_model/tests/test_logistic_regression.py +95 -0
- onedal/linear_model/tests/test_ridge.py +95 -0
- onedal/neighbors/__init__.py +19 -0
- onedal/neighbors/neighbors.py +763 -0
- onedal/neighbors/tests/test_knn_classification.py +49 -0
- onedal/primitives/__init__.py +27 -0
- onedal/primitives/get_tree.py +25 -0
- onedal/primitives/kernel_functions.py +152 -0
- onedal/primitives/tests/test_kernel_functions.py +159 -0
- onedal/spmd/__init__.py +25 -0
- onedal/spmd/_base.py +30 -0
- onedal/spmd/basic_statistics/__init__.py +20 -0
- onedal/spmd/basic_statistics/basic_statistics.py +30 -0
- onedal/spmd/basic_statistics/incremental_basic_statistics.py +71 -0
- onedal/spmd/cluster/__init__.py +28 -0
- onedal/spmd/cluster/dbscan.py +23 -0
- onedal/spmd/cluster/kmeans.py +56 -0
- onedal/spmd/covariance/__init__.py +20 -0
- onedal/spmd/covariance/covariance.py +26 -0
- onedal/spmd/covariance/incremental_covariance.py +83 -0
- onedal/spmd/decomposition/__init__.py +20 -0
- onedal/spmd/decomposition/incremental_pca.py +124 -0
- onedal/spmd/decomposition/pca.py +26 -0
- onedal/spmd/ensemble/__init__.py +19 -0
- onedal/spmd/ensemble/forest.py +28 -0
- onedal/spmd/linear_model/__init__.py +21 -0
- onedal/spmd/linear_model/incremental_linear_model.py +101 -0
- onedal/spmd/linear_model/linear_model.py +30 -0
- onedal/spmd/linear_model/logistic_regression.py +38 -0
- onedal/spmd/neighbors/__init__.py +19 -0
- onedal/spmd/neighbors/neighbors.py +75 -0
- onedal/svm/__init__.py +19 -0
- onedal/svm/svm.py +556 -0
- onedal/svm/tests/test_csr_svm.py +351 -0
- onedal/svm/tests/test_nusvc.py +204 -0
- onedal/svm/tests/test_nusvr.py +210 -0
- onedal/svm/tests/test_svc.py +176 -0
- onedal/svm/tests/test_svr.py +243 -0
- onedal/tests/test_common.py +57 -0
- onedal/tests/utils/_dataframes_support.py +162 -0
- onedal/tests/utils/_device_selection.py +102 -0
- onedal/utils/__init__.py +49 -0
- onedal/utils/_array_api.py +81 -0
- onedal/utils/_dpep_helpers.py +56 -0
- onedal/utils/tests/test_validation.py +142 -0
- onedal/utils/validation.py +464 -0
- scikit_learn_intelex-2025.4.0.dist-info/LICENSE.txt +202 -0
- scikit_learn_intelex-2025.4.0.dist-info/METADATA +190 -0
- scikit_learn_intelex-2025.4.0.dist-info/RECORD +282 -0
- scikit_learn_intelex-2025.4.0.dist-info/WHEEL +5 -0
- scikit_learn_intelex-2025.4.0.dist-info/top_level.txt +3 -0
- sklearnex/__init__.py +66 -0
- sklearnex/__main__.py +58 -0
- sklearnex/_config.py +116 -0
- sklearnex/_device_offload.py +126 -0
- sklearnex/_utils.py +177 -0
- sklearnex/basic_statistics/__init__.py +20 -0
- sklearnex/basic_statistics/basic_statistics.py +261 -0
- sklearnex/basic_statistics/incremental_basic_statistics.py +352 -0
- sklearnex/basic_statistics/tests/test_basic_statistics.py +405 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +455 -0
- sklearnex/cluster/__init__.py +20 -0
- sklearnex/cluster/dbscan.py +197 -0
- sklearnex/cluster/k_means.py +397 -0
- sklearnex/cluster/tests/test_dbscan.py +38 -0
- sklearnex/cluster/tests/test_kmeans.py +157 -0
- sklearnex/conftest.py +82 -0
- sklearnex/covariance/__init__.py +19 -0
- sklearnex/covariance/incremental_covariance.py +405 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +287 -0
- sklearnex/decomposition/__init__.py +19 -0
- sklearnex/decomposition/pca.py +427 -0
- sklearnex/decomposition/tests/test_pca.py +58 -0
- sklearnex/dispatcher.py +534 -0
- sklearnex/doc/third-party-programs.txt +424 -0
- sklearnex/ensemble/__init__.py +29 -0
- sklearnex/ensemble/_forest.py +2029 -0
- sklearnex/ensemble/tests/test_forest.py +140 -0
- sklearnex/glob/__main__.py +72 -0
- sklearnex/glob/dispatcher.py +101 -0
- sklearnex/linear_model/__init__.py +32 -0
- sklearnex/linear_model/coordinate_descent.py +30 -0
- sklearnex/linear_model/incremental_linear.py +495 -0
- sklearnex/linear_model/incremental_ridge.py +432 -0
- sklearnex/linear_model/linear.py +346 -0
- sklearnex/linear_model/logistic_regression.py +415 -0
- sklearnex/linear_model/ridge.py +390 -0
- sklearnex/linear_model/tests/test_incremental_linear.py +267 -0
- sklearnex/linear_model/tests/test_incremental_ridge.py +214 -0
- sklearnex/linear_model/tests/test_linear.py +142 -0
- sklearnex/linear_model/tests/test_logreg.py +134 -0
- sklearnex/linear_model/tests/test_ridge.py +256 -0
- sklearnex/manifold/__init__.py +19 -0
- sklearnex/manifold/t_sne.py +26 -0
- sklearnex/manifold/tests/test_tsne.py +250 -0
- sklearnex/metrics/__init__.py +23 -0
- sklearnex/metrics/pairwise.py +22 -0
- sklearnex/metrics/ranking.py +20 -0
- sklearnex/metrics/tests/test_metrics.py +39 -0
- sklearnex/model_selection/__init__.py +21 -0
- sklearnex/model_selection/split.py +22 -0
- sklearnex/model_selection/tests/test_model_selection.py +34 -0
- sklearnex/neighbors/__init__.py +27 -0
- sklearnex/neighbors/_lof.py +236 -0
- sklearnex/neighbors/common.py +310 -0
- sklearnex/neighbors/knn_classification.py +231 -0
- sklearnex/neighbors/knn_regression.py +207 -0
- sklearnex/neighbors/knn_unsupervised.py +178 -0
- sklearnex/neighbors/tests/test_neighbors.py +82 -0
- sklearnex/preview/__init__.py +17 -0
- sklearnex/preview/covariance/__init__.py +19 -0
- sklearnex/preview/covariance/covariance.py +142 -0
- sklearnex/preview/covariance/tests/test_covariance.py +66 -0
- sklearnex/preview/decomposition/__init__.py +19 -0
- sklearnex/preview/decomposition/incremental_pca.py +244 -0
- sklearnex/preview/decomposition/tests/test_incremental_pca.py +336 -0
- sklearnex/spmd/__init__.py +25 -0
- sklearnex/spmd/basic_statistics/__init__.py +20 -0
- sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
- sklearnex/spmd/basic_statistics/incremental_basic_statistics.py +30 -0
- sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
- sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py +306 -0
- sklearnex/spmd/cluster/__init__.py +30 -0
- sklearnex/spmd/cluster/dbscan.py +50 -0
- sklearnex/spmd/cluster/kmeans.py +21 -0
- sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
- sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +173 -0
- sklearnex/spmd/covariance/__init__.py +20 -0
- sklearnex/spmd/covariance/covariance.py +21 -0
- sklearnex/spmd/covariance/incremental_covariance.py +37 -0
- sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
- sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py +184 -0
- sklearnex/spmd/decomposition/__init__.py +20 -0
- sklearnex/spmd/decomposition/incremental_pca.py +30 -0
- sklearnex/spmd/decomposition/pca.py +21 -0
- sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py +269 -0
- sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
- sklearnex/spmd/ensemble/__init__.py +19 -0
- sklearnex/spmd/ensemble/forest.py +71 -0
- sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
- sklearnex/spmd/linear_model/__init__.py +21 -0
- sklearnex/spmd/linear_model/incremental_linear_model.py +35 -0
- sklearnex/spmd/linear_model/linear_model.py +21 -0
- sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py +331 -0
- sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
- sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +162 -0
- sklearnex/spmd/neighbors/__init__.py +19 -0
- sklearnex/spmd/neighbors/neighbors.py +25 -0
- sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
- sklearnex/svm/__init__.py +29 -0
- sklearnex/svm/_common.py +339 -0
- sklearnex/svm/nusvc.py +371 -0
- sklearnex/svm/nusvr.py +170 -0
- sklearnex/svm/svc.py +399 -0
- sklearnex/svm/svr.py +167 -0
- sklearnex/svm/tests/test_svm.py +93 -0
- sklearnex/tests/test_common.py +491 -0
- sklearnex/tests/test_config.py +123 -0
- sklearnex/tests/test_hyperparameters.py +43 -0
- sklearnex/tests/test_memory_usage.py +347 -0
- sklearnex/tests/test_monkeypatch.py +269 -0
- sklearnex/tests/test_n_jobs_support.py +108 -0
- sklearnex/tests/test_parallel.py +48 -0
- sklearnex/tests/test_patching.py +377 -0
- sklearnex/tests/test_run_to_run_stability.py +326 -0
- sklearnex/tests/utils/__init__.py +48 -0
- sklearnex/tests/utils/base.py +436 -0
- sklearnex/tests/utils/spmd.py +198 -0
- sklearnex/utils/__init__.py +19 -0
- sklearnex/utils/_array_api.py +82 -0
- sklearnex/utils/parallel.py +59 -0
- sklearnex/utils/tests/test_validation.py +238 -0
- sklearnex/utils/validation.py +208 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2024 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
"""Tools to support array_api."""
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
22
|
+
from onedal.utils._array_api import _get_sycl_namespace
|
|
23
|
+
|
|
24
|
+
if sklearn_check_version("1.2"):
|
|
25
|
+
from sklearn.utils._array_api import get_namespace as sklearn_get_namespace
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_namespace(*arrays):
|
|
29
|
+
"""Get namespace of arrays.
|
|
30
|
+
|
|
31
|
+
Introspect `arrays` arguments and return their common Array API
|
|
32
|
+
compatible namespace object, if any. NumPy 1.22 and later can
|
|
33
|
+
construct such containers using the `numpy.array_api` namespace
|
|
34
|
+
for instance.
|
|
35
|
+
|
|
36
|
+
This function will return the namespace of SYCL-related arrays
|
|
37
|
+
which define the __sycl_usm_array_interface__ attribute
|
|
38
|
+
regardless of array_api support, the configuration of
|
|
39
|
+
array_api_dispatch, or scikit-learn version.
|
|
40
|
+
|
|
41
|
+
See: https://numpy.org/neps/nep-0047-array-api-standard.html
|
|
42
|
+
|
|
43
|
+
If `arrays` are regular numpy arrays, an instance of the
|
|
44
|
+
`_NumPyApiWrapper` compatibility wrapper is returned instead.
|
|
45
|
+
|
|
46
|
+
Namespace support is not enabled by default. To enabled it
|
|
47
|
+
call:
|
|
48
|
+
|
|
49
|
+
sklearn.set_config(array_api_dispatch=True)
|
|
50
|
+
|
|
51
|
+
or:
|
|
52
|
+
|
|
53
|
+
with sklearn.config_context(array_api_dispatch=True):
|
|
54
|
+
# your code here
|
|
55
|
+
|
|
56
|
+
Otherwise an instance of the `_NumPyApiWrapper`
|
|
57
|
+
compatibility wrapper is always returned irrespective of
|
|
58
|
+
the fact that arrays implement the `__array_namespace__`
|
|
59
|
+
protocol or not.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
*arrays : array objects
|
|
64
|
+
Array objects.
|
|
65
|
+
|
|
66
|
+
Returns
|
|
67
|
+
-------
|
|
68
|
+
namespace : module
|
|
69
|
+
Namespace shared by array objects.
|
|
70
|
+
|
|
71
|
+
is_array_api : bool
|
|
72
|
+
True of the arrays are containers that implement the Array API spec.
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
sycl_type, xp, is_array_api_compliant = _get_sycl_namespace(*arrays)
|
|
76
|
+
|
|
77
|
+
if sycl_type:
|
|
78
|
+
return xp, is_array_api_compliant
|
|
79
|
+
elif sklearn_check_version("1.2"):
|
|
80
|
+
return sklearn_get_namespace(*arrays)
|
|
81
|
+
else:
|
|
82
|
+
return np, False
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# ===============================================================================
|
|
2
|
+
# Copyright 2023 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ===============================================================================
|
|
16
|
+
|
|
17
|
+
import warnings
|
|
18
|
+
from functools import update_wrapper
|
|
19
|
+
|
|
20
|
+
from .._config import config_context, get_config
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class _FuncWrapper:
|
|
24
|
+
"""Load the global configuration before calling the function."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, function):
|
|
27
|
+
self.function = function
|
|
28
|
+
update_wrapper(self, self.function)
|
|
29
|
+
|
|
30
|
+
def with_config(self, config):
|
|
31
|
+
self.config = config
|
|
32
|
+
return self
|
|
33
|
+
|
|
34
|
+
def __call__(self, *args, **kwargs):
|
|
35
|
+
config = getattr(self, "config", None)
|
|
36
|
+
if config is None:
|
|
37
|
+
warnings.warn(
|
|
38
|
+
"`sklearn.utils.parallel.delayed` should be used with "
|
|
39
|
+
"`sklearn.utils.parallel.Parallel` to make it possible to propagate "
|
|
40
|
+
"the scikit-learn configuration of the current thread to the "
|
|
41
|
+
"joblib workers.",
|
|
42
|
+
UserWarning,
|
|
43
|
+
)
|
|
44
|
+
config = {}
|
|
45
|
+
with config_context(**config):
|
|
46
|
+
return self.function(*args, **kwargs)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class _FuncWrapperOld:
|
|
50
|
+
"""Load the global configuration before calling the function."""
|
|
51
|
+
|
|
52
|
+
def __init__(self, function):
|
|
53
|
+
self.function = function
|
|
54
|
+
self.config = get_config()
|
|
55
|
+
update_wrapper(self, self.function)
|
|
56
|
+
|
|
57
|
+
def __call__(self, *args, **kwargs):
|
|
58
|
+
with config_context(**self.config):
|
|
59
|
+
return self.function(*args, **kwargs)
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright contributors to the oneDAL project
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
import numpy.random as rand
|
|
19
|
+
import pytest
|
|
20
|
+
|
|
21
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
22
|
+
from onedal.tests.utils._dataframes_support import (
|
|
23
|
+
_convert_to_dataframe,
|
|
24
|
+
get_dataframes_and_queues,
|
|
25
|
+
)
|
|
26
|
+
from sklearnex import config_context
|
|
27
|
+
from sklearnex.tests.utils import DummyEstimator, gen_dataset
|
|
28
|
+
from sklearnex.utils.validation import _check_sample_weight, validate_data
|
|
29
|
+
|
|
30
|
+
# array_api support starts in sklearn 1.2, and array_api_strict conformance starts in sklearn 1.3
|
|
31
|
+
_dataframes_supported = (
|
|
32
|
+
"numpy,pandas"
|
|
33
|
+
+ (",dpctl" if sklearn_check_version("1.2") else "")
|
|
34
|
+
+ (",array_api" if sklearn_check_version("1.3") else "")
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
39
|
+
@pytest.mark.parametrize(
|
|
40
|
+
"shape",
|
|
41
|
+
[
|
|
42
|
+
[16, 2048],
|
|
43
|
+
[2**16 + 3],
|
|
44
|
+
[1000, 1000],
|
|
45
|
+
],
|
|
46
|
+
)
|
|
47
|
+
@pytest.mark.parametrize("ensure_all_finite", ["allow-nan", True])
|
|
48
|
+
def test_sum_infinite_actually_finite(dtype, shape, ensure_all_finite):
|
|
49
|
+
est = DummyEstimator()
|
|
50
|
+
X = np.empty(shape, dtype=dtype)
|
|
51
|
+
X.fill(np.finfo(dtype).max)
|
|
52
|
+
X = np.atleast_2d(X)
|
|
53
|
+
X_array = validate_data(est, X, ensure_all_finite=ensure_all_finite)
|
|
54
|
+
assert type(X_array) == type(X)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
58
|
+
@pytest.mark.parametrize(
|
|
59
|
+
"shape",
|
|
60
|
+
[
|
|
61
|
+
[16, 2048],
|
|
62
|
+
[2**16 + 3],
|
|
63
|
+
[1000, 1000],
|
|
64
|
+
],
|
|
65
|
+
)
|
|
66
|
+
@pytest.mark.parametrize("ensure_all_finite", ["allow-nan", True])
|
|
67
|
+
@pytest.mark.parametrize("check", ["inf", "NaN", None])
|
|
68
|
+
@pytest.mark.parametrize("seed", [0, 123456])
|
|
69
|
+
@pytest.mark.parametrize(
|
|
70
|
+
"dataframe, queue",
|
|
71
|
+
get_dataframes_and_queues(_dataframes_supported),
|
|
72
|
+
)
|
|
73
|
+
def test_validate_data_random_location(
|
|
74
|
+
dataframe, queue, dtype, shape, ensure_all_finite, check, seed
|
|
75
|
+
):
|
|
76
|
+
est = DummyEstimator()
|
|
77
|
+
rand.seed(seed)
|
|
78
|
+
X = rand.uniform(high=np.finfo(dtype).max, size=shape).astype(dtype)
|
|
79
|
+
|
|
80
|
+
if check:
|
|
81
|
+
loc = rand.randint(0, X.size - 1)
|
|
82
|
+
X.reshape((-1,))[loc] = float(check)
|
|
83
|
+
|
|
84
|
+
# column heavy pandas inputs are very slow in sklearn's check_array even without
|
|
85
|
+
# the finite check, just transpose inputs to guarantee fast processing in tests
|
|
86
|
+
X = _convert_to_dataframe(
|
|
87
|
+
np.atleast_2d(X).T,
|
|
88
|
+
target_df=dataframe,
|
|
89
|
+
sycl_queue=queue,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
dispatch = {}
|
|
93
|
+
if sklearn_check_version("1.2") and dataframe != "pandas":
|
|
94
|
+
dispatch["array_api_dispatch"] = True
|
|
95
|
+
|
|
96
|
+
with config_context(**dispatch):
|
|
97
|
+
|
|
98
|
+
allow_nan = ensure_all_finite == "allow-nan"
|
|
99
|
+
if check is None or (allow_nan and check == "NaN"):
|
|
100
|
+
validate_data(est, X, ensure_all_finite=ensure_all_finite)
|
|
101
|
+
else:
|
|
102
|
+
type_err = "infinity" if allow_nan else "[NaN|infinity]"
|
|
103
|
+
msg_err = f"Input X contains {type_err}"
|
|
104
|
+
with pytest.raises(ValueError, match=msg_err):
|
|
105
|
+
validate_data(est, X, ensure_all_finite=ensure_all_finite)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
109
|
+
@pytest.mark.parametrize("ensure_all_finite", ["allow-nan", True])
|
|
110
|
+
@pytest.mark.parametrize("check", ["inf", "NaN", None])
|
|
111
|
+
@pytest.mark.parametrize("seed", [0, 123456])
|
|
112
|
+
@pytest.mark.parametrize(
|
|
113
|
+
"dataframe, queue",
|
|
114
|
+
get_dataframes_and_queues(_dataframes_supported),
|
|
115
|
+
)
|
|
116
|
+
def test_validate_data_random_shape_and_location(
|
|
117
|
+
dataframe, queue, dtype, ensure_all_finite, check, seed
|
|
118
|
+
):
|
|
119
|
+
est = DummyEstimator()
|
|
120
|
+
lb, ub = 32768, 1048576 # lb is a patching condition, ub 2^20
|
|
121
|
+
rand.seed(seed)
|
|
122
|
+
X = rand.uniform(high=np.finfo(dtype).max, size=rand.randint(lb, ub)).astype(dtype)
|
|
123
|
+
|
|
124
|
+
if check:
|
|
125
|
+
loc = rand.randint(0, X.size - 1)
|
|
126
|
+
X[loc] = float(check)
|
|
127
|
+
|
|
128
|
+
X = _convert_to_dataframe(
|
|
129
|
+
np.atleast_2d(X).T,
|
|
130
|
+
target_df=dataframe,
|
|
131
|
+
sycl_queue=queue,
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
dispatch = {}
|
|
135
|
+
if sklearn_check_version("1.2") and dataframe != "pandas":
|
|
136
|
+
dispatch["array_api_dispatch"] = True
|
|
137
|
+
|
|
138
|
+
with config_context(**dispatch):
|
|
139
|
+
|
|
140
|
+
allow_nan = ensure_all_finite == "allow-nan"
|
|
141
|
+
if check is None or (allow_nan and check == "NaN"):
|
|
142
|
+
validate_data(est, X, ensure_all_finite=ensure_all_finite)
|
|
143
|
+
else:
|
|
144
|
+
type_err = "infinity" if allow_nan else "[NaN|infinity]"
|
|
145
|
+
msg_err = f"Input X contains {type_err}."
|
|
146
|
+
with pytest.raises(ValueError, match=msg_err):
|
|
147
|
+
validate_data(est, X, ensure_all_finite=ensure_all_finite)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
151
|
+
@pytest.mark.parametrize("check", ["inf", "NaN", None])
|
|
152
|
+
@pytest.mark.parametrize("seed", [0, 123456])
|
|
153
|
+
@pytest.mark.parametrize(
|
|
154
|
+
"dataframe, queue",
|
|
155
|
+
get_dataframes_and_queues(_dataframes_supported),
|
|
156
|
+
)
|
|
157
|
+
def test__check_sample_weight_random_shape_and_location(
|
|
158
|
+
dataframe, queue, dtype, check, seed
|
|
159
|
+
):
|
|
160
|
+
# This testing assumes that array api inputs to validate_data will only occur
|
|
161
|
+
# with sklearn array_api support which began in sklearn 1.2. This would assume
|
|
162
|
+
# that somewhere upstream of the validate_data call, a data conversion of dpnp,
|
|
163
|
+
# dpctl, or array_api inputs to numpy inputs would have occurred.
|
|
164
|
+
|
|
165
|
+
lb, ub = 32768, 1048576 # lb is a patching condition, ub 2^20
|
|
166
|
+
rand.seed(seed)
|
|
167
|
+
shape = (rand.randint(lb, ub), 2)
|
|
168
|
+
X = rand.uniform(high=np.finfo(dtype).max, size=shape).astype(dtype)
|
|
169
|
+
sample_weight = rand.uniform(high=np.finfo(dtype).max, size=shape[0]).astype(dtype)
|
|
170
|
+
|
|
171
|
+
if check:
|
|
172
|
+
loc = rand.randint(0, shape[0] - 1)
|
|
173
|
+
sample_weight[loc] = float(check)
|
|
174
|
+
|
|
175
|
+
X = _convert_to_dataframe(
|
|
176
|
+
X,
|
|
177
|
+
target_df=dataframe,
|
|
178
|
+
sycl_queue=queue,
|
|
179
|
+
)
|
|
180
|
+
sample_weight = _convert_to_dataframe(
|
|
181
|
+
sample_weight,
|
|
182
|
+
target_df=dataframe,
|
|
183
|
+
sycl_queue=queue,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
dispatch = {}
|
|
187
|
+
if sklearn_check_version("1.2") and dataframe != "pandas":
|
|
188
|
+
dispatch["array_api_dispatch"] = True
|
|
189
|
+
|
|
190
|
+
with config_context(**dispatch):
|
|
191
|
+
|
|
192
|
+
if check is None:
|
|
193
|
+
X_out = _check_sample_weight(sample_weight, X)
|
|
194
|
+
if dispatch:
|
|
195
|
+
assert type(X_out) == type(X)
|
|
196
|
+
else:
|
|
197
|
+
assert isinstance(X_out, np.ndarray)
|
|
198
|
+
else:
|
|
199
|
+
msg_err = "Input sample_weight contains [NaN|infinity]"
|
|
200
|
+
with pytest.raises(ValueError, match=msg_err):
|
|
201
|
+
X_out = _check_sample_weight(sample_weight, X)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
|
|
205
|
+
@pytest.mark.parametrize(
|
|
206
|
+
"dataframe, queue",
|
|
207
|
+
get_dataframes_and_queues(_dataframes_supported),
|
|
208
|
+
)
|
|
209
|
+
def test_validate_data_output(dtype, dataframe, queue):
|
|
210
|
+
# This testing assumes that array api inputs to validate_data will only occur
|
|
211
|
+
# with sklearn array_api support which began in sklearn 1.2. This would assume
|
|
212
|
+
# that somewhere upstream of the validate_data call, a data conversion of dpnp,
|
|
213
|
+
# dpctl, or array_api inputs to numpy inputs would have occurred.
|
|
214
|
+
est = DummyEstimator()
|
|
215
|
+
X, y = gen_dataset(est, queue=queue, target_df=dataframe, dtype=dtype)[0]
|
|
216
|
+
|
|
217
|
+
dispatch = {}
|
|
218
|
+
if sklearn_check_version("1.2") and dataframe != "pandas":
|
|
219
|
+
dispatch["array_api_dispatch"] = True
|
|
220
|
+
|
|
221
|
+
with config_context(**dispatch):
|
|
222
|
+
X_out, y_out = validate_data(est, X, y)
|
|
223
|
+
# check sklearn validate_data operations work underneath
|
|
224
|
+
X_array = validate_data(est, X, reset=False)
|
|
225
|
+
|
|
226
|
+
for orig, first, second in ((X, X_out, X_array), (y, y_out, None)):
|
|
227
|
+
if dispatch:
|
|
228
|
+
assert type(orig) == type(
|
|
229
|
+
first
|
|
230
|
+
), f"validate_data converted {type(orig)} to {type(first)}"
|
|
231
|
+
if second is not None:
|
|
232
|
+
assert type(orig) == type(
|
|
233
|
+
second
|
|
234
|
+
), f"from_array converted {type(orig)} to {type(second)}"
|
|
235
|
+
else:
|
|
236
|
+
# array_api_strict from sklearn < 1.2 and pandas will convert to numpy arrays
|
|
237
|
+
assert isinstance(first, np.ndarray)
|
|
238
|
+
assert second is None or isinstance(second, np.ndarray)
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# ===============================================================================
|
|
2
|
+
# Copyright 2022 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ===============================================================================
|
|
16
|
+
|
|
17
|
+
import numbers
|
|
18
|
+
|
|
19
|
+
import scipy.sparse as sp
|
|
20
|
+
from sklearn.utils.validation import _assert_all_finite as _sklearn_assert_all_finite
|
|
21
|
+
from sklearn.utils.validation import _num_samples, check_array, check_non_negative
|
|
22
|
+
|
|
23
|
+
from daal4py.sklearn._utils import daal_check_version, sklearn_check_version
|
|
24
|
+
|
|
25
|
+
from ._array_api import get_namespace
|
|
26
|
+
|
|
27
|
+
if sklearn_check_version("1.6"):
|
|
28
|
+
from sklearn.utils.validation import validate_data as _sklearn_validate_data
|
|
29
|
+
|
|
30
|
+
_finite_keyword = "ensure_all_finite"
|
|
31
|
+
|
|
32
|
+
else:
|
|
33
|
+
from sklearn.base import BaseEstimator
|
|
34
|
+
|
|
35
|
+
_sklearn_validate_data = BaseEstimator._validate_data
|
|
36
|
+
_finite_keyword = "force_all_finite"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if daal_check_version((2024, "P", 700)):
|
|
40
|
+
from onedal.utils.validation import _assert_all_finite as _onedal_assert_all_finite
|
|
41
|
+
|
|
42
|
+
def _onedal_supported_format(X, xp):
|
|
43
|
+
# array_api does not have a `strides` or `flags` attribute for testing memory
|
|
44
|
+
# order. When dlpack support is brought in for oneDAL, general support for
|
|
45
|
+
# array_api can be enabled and the hasattr check can be removed.
|
|
46
|
+
# _onedal_supported_format is therefore conservative in verifying attributes and
|
|
47
|
+
# does not support array_api. This will block onedal_assert_all_finite from being
|
|
48
|
+
# used for array_api inputs but will allow dpnp ndarrays and dpctl tensors.
|
|
49
|
+
# only check contiguous arrays to prevent unnecessary copying of data, even if
|
|
50
|
+
# non-contiguous arrays can now be converted to oneDAL tables.
|
|
51
|
+
return (
|
|
52
|
+
X.dtype in [xp.float32, xp.float64]
|
|
53
|
+
and hasattr(X, "flags")
|
|
54
|
+
and (X.flags["C_CONTIGUOUS"] or X.flags["F_CONTIGUOUS"])
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
else:
|
|
58
|
+
from daal4py.utils.validation import _assert_all_finite as _onedal_assert_all_finite
|
|
59
|
+
from onedal.utils._array_api import _is_numpy_namespace
|
|
60
|
+
|
|
61
|
+
def _onedal_supported_format(X, xp):
|
|
62
|
+
# daal4py _assert_all_finite only supports numpy namespaces, use internally-
|
|
63
|
+
# defined check to validate inputs, otherwise offload to sklearn
|
|
64
|
+
return X.dtype in [xp.float32, xp.float64] and _is_numpy_namespace(xp)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _sklearnex_assert_all_finite(
|
|
68
|
+
X,
|
|
69
|
+
*,
|
|
70
|
+
allow_nan=False,
|
|
71
|
+
input_name="",
|
|
72
|
+
):
|
|
73
|
+
# size check is an initial match to daal4py for performance reasons, can be
|
|
74
|
+
# optimized later
|
|
75
|
+
xp, _ = get_namespace(X)
|
|
76
|
+
if X.size < 32768 or not _onedal_supported_format(X, xp):
|
|
77
|
+
if sklearn_check_version("1.1"):
|
|
78
|
+
_sklearn_assert_all_finite(X, allow_nan=allow_nan, input_name=input_name)
|
|
79
|
+
else:
|
|
80
|
+
_sklearn_assert_all_finite(X, allow_nan=allow_nan)
|
|
81
|
+
else:
|
|
82
|
+
_onedal_assert_all_finite(X, allow_nan=allow_nan, input_name=input_name)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def assert_all_finite(
|
|
86
|
+
X,
|
|
87
|
+
*,
|
|
88
|
+
allow_nan=False,
|
|
89
|
+
input_name="",
|
|
90
|
+
):
|
|
91
|
+
_sklearnex_assert_all_finite(
|
|
92
|
+
X.data if sp.issparse(X) else X,
|
|
93
|
+
allow_nan=allow_nan,
|
|
94
|
+
input_name=input_name,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def validate_data(
|
|
99
|
+
_estimator,
|
|
100
|
+
/,
|
|
101
|
+
X="no_validation",
|
|
102
|
+
y="no_validation",
|
|
103
|
+
**kwargs,
|
|
104
|
+
):
|
|
105
|
+
# force finite check to not occur in sklearn, default is True
|
|
106
|
+
# `ensure_all_finite` is the most up-to-date keyword name in sklearn
|
|
107
|
+
# _finite_keyword provides backward compatability for `force_all_finite`
|
|
108
|
+
ensure_all_finite = kwargs.pop("ensure_all_finite", True)
|
|
109
|
+
kwargs[_finite_keyword] = False
|
|
110
|
+
|
|
111
|
+
out = _sklearn_validate_data(
|
|
112
|
+
_estimator,
|
|
113
|
+
X=X,
|
|
114
|
+
y=y,
|
|
115
|
+
**kwargs,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
check_x = not isinstance(X, str) or X != "no_validation"
|
|
119
|
+
check_y = not (y is None or isinstance(y, str) and y == "no_validation")
|
|
120
|
+
|
|
121
|
+
if ensure_all_finite:
|
|
122
|
+
# run local finite check
|
|
123
|
+
allow_nan = ensure_all_finite == "allow-nan"
|
|
124
|
+
# the return object from validate_data can be a single
|
|
125
|
+
|
|
126
|
+
# element (either x or y) or both (as a tuple). An iterator along with
|
|
127
|
+
# check_x and check_y can go through the output properly without
|
|
128
|
+
# stacking layers of if statements to make sure the proper input_name
|
|
129
|
+
# is used
|
|
130
|
+
arg = iter(out if isinstance(out, tuple) else (out,))
|
|
131
|
+
if check_x:
|
|
132
|
+
assert_all_finite(next(arg), allow_nan=allow_nan, input_name="X")
|
|
133
|
+
if check_y:
|
|
134
|
+
assert_all_finite(next(arg), allow_nan=allow_nan, input_name="y")
|
|
135
|
+
|
|
136
|
+
if check_y and "dtype" in kwargs:
|
|
137
|
+
# validate_data does not do full dtype conversions, as it uses check_X_y
|
|
138
|
+
# oneDAL can make tables from [int32, float32, float64], requiring
|
|
139
|
+
# a dtype check and conversion. This will query the array_namespace and
|
|
140
|
+
# convert y as necessary. This is important especially for regressors.
|
|
141
|
+
dtype = kwargs["dtype"]
|
|
142
|
+
if not isinstance(dtype, (tuple, list)):
|
|
143
|
+
dtype = tuple(dtype)
|
|
144
|
+
|
|
145
|
+
outx, outy = out if check_x else (None, out)
|
|
146
|
+
if outy.dtype not in dtype:
|
|
147
|
+
yp, _ = get_namespace(outy)
|
|
148
|
+
# use asarray rather than astype because of numpy support
|
|
149
|
+
outy = yp.asarray(outy, dtype=dtype[0])
|
|
150
|
+
out = (outx, outy) if check_x else outy
|
|
151
|
+
|
|
152
|
+
return out
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _check_sample_weight(
|
|
156
|
+
sample_weight, X, dtype=None, copy=False, ensure_non_negative=False
|
|
157
|
+
):
|
|
158
|
+
|
|
159
|
+
n_samples = _num_samples(X)
|
|
160
|
+
xp, _ = get_namespace(X)
|
|
161
|
+
|
|
162
|
+
if dtype is not None and dtype not in [xp.float32, xp.float64]:
|
|
163
|
+
dtype = xp.float64
|
|
164
|
+
|
|
165
|
+
if sample_weight is None:
|
|
166
|
+
if hasattr(X, "device"):
|
|
167
|
+
sample_weight = xp.ones(n_samples, dtype=dtype, device=X.device)
|
|
168
|
+
else:
|
|
169
|
+
sample_weight = xp.ones(n_samples, dtype=dtype)
|
|
170
|
+
elif isinstance(sample_weight, numbers.Number):
|
|
171
|
+
if hasattr(X, "device"):
|
|
172
|
+
sample_weight = xp.full(
|
|
173
|
+
n_samples, sample_weight, dtype=dtype, device=X.device
|
|
174
|
+
)
|
|
175
|
+
else:
|
|
176
|
+
sample_weight = xp.full(n_samples, sample_weight, dtype=dtype)
|
|
177
|
+
else:
|
|
178
|
+
if dtype is None:
|
|
179
|
+
dtype = [xp.float64, xp.float32]
|
|
180
|
+
|
|
181
|
+
params = {
|
|
182
|
+
"accept_sparse": False,
|
|
183
|
+
"ensure_2d": False,
|
|
184
|
+
"dtype": dtype,
|
|
185
|
+
"order": "C",
|
|
186
|
+
"copy": copy,
|
|
187
|
+
_finite_keyword: False,
|
|
188
|
+
}
|
|
189
|
+
if sklearn_check_version("1.1"):
|
|
190
|
+
params["input_name"] = "sample_weight"
|
|
191
|
+
|
|
192
|
+
sample_weight = check_array(sample_weight, **params)
|
|
193
|
+
assert_all_finite(sample_weight, input_name="sample_weight")
|
|
194
|
+
|
|
195
|
+
if sample_weight.ndim != 1:
|
|
196
|
+
raise ValueError("Sample weights must be 1D array or scalar")
|
|
197
|
+
|
|
198
|
+
if sample_weight.shape != (n_samples,):
|
|
199
|
+
raise ValueError(
|
|
200
|
+
"sample_weight.shape == {}, expected {}!".format(
|
|
201
|
+
sample_weight.shape, (n_samples,)
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if ensure_non_negative:
|
|
206
|
+
check_non_negative(sample_weight, "`sample_weight`")
|
|
207
|
+
|
|
208
|
+
return sample_weight
|