scikit-learn-intelex 2024.3.0__py310-none-manylinux1_x86_64.whl → 2024.4.0__py310-none-manylinux1_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.

Files changed (33) hide show
  1. {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/METADATA +2 -2
  2. {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/RECORD +33 -30
  3. sklearnex/_device_offload.py +31 -4
  4. sklearnex/basic_statistics/__init__.py +2 -1
  5. sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
  6. sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +386 -0
  7. sklearnex/decomposition/pca.py +3 -6
  8. sklearnex/dispatcher.py +2 -2
  9. sklearnex/ensemble/_forest.py +68 -75
  10. sklearnex/linear_model/linear.py +275 -340
  11. sklearnex/linear_model/logistic_regression.py +50 -9
  12. sklearnex/linear_model/tests/test_linear.py +40 -5
  13. sklearnex/neighbors/_lof.py +53 -36
  14. sklearnex/neighbors/common.py +4 -1
  15. sklearnex/neighbors/knn_classification.py +37 -122
  16. sklearnex/neighbors/knn_regression.py +10 -117
  17. sklearnex/neighbors/knn_unsupervised.py +6 -78
  18. sklearnex/preview/cluster/k_means.py +5 -73
  19. sklearnex/preview/covariance/covariance.py +6 -5
  20. sklearnex/preview/covariance/tests/test_covariance.py +18 -5
  21. sklearnex/svm/_common.py +4 -7
  22. sklearnex/svm/nusvc.py +66 -50
  23. sklearnex/svm/nusvr.py +3 -49
  24. sklearnex/svm/svc.py +66 -51
  25. sklearnex/svm/svr.py +3 -49
  26. sklearnex/tests/_utils.py +14 -5
  27. sklearnex/tests/test_n_jobs_support.py +8 -2
  28. sklearnex/tests/test_patching.py +64 -54
  29. sklearnex/utils/__init__.py +2 -1
  30. sklearnex/utils/_namespace.py +97 -0
  31. {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/LICENSE.txt +0 -0
  32. {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/WHEEL +0 -0
  33. {scikit_learn_intelex-2024.3.0.dist-info → scikit_learn_intelex-2024.4.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scikit-learn-intelex
3
- Version: 2024.3.0
3
+ Version: 2024.4.0
4
4
  Summary: Intel(R) Extension for Scikit-learn is a seamless way to speed up your Scikit-learn application.
5
5
  Home-page: https://github.com/intel/scikit-learn-intelex
6
6
  Author: Intel Corporation
@@ -31,7 +31,7 @@ Classifier: Topic :: Software Development
31
31
  Requires-Python: >=3.7
32
32
  Description-Content-Type: text/markdown
33
33
  License-File: LICENSE.txt
34
- Requires-Dist: daal4py (==2024.3.0)
34
+ Requires-Dist: daal4py (==2024.4.0)
35
35
  Requires-Dist: scikit-learn (>=0.22)
36
36
 
37
37
 
@@ -1,12 +1,14 @@
1
1
  sklearnex/__init__.py,sha256=DVpGCMMQcUlrOGj_iy1jk3ZhCfa0_TFISYLqaUDRqC0,1780
2
2
  sklearnex/__main__.py,sha256=Le9BJq6aLEGSSoZwJLsOADxsV89ynBfA8BcoJHk9F24,1921
3
3
  sklearnex/_config.py,sha256=6WS3UuS4-0DxIJyGn7yQMosj-mGkLybLQrg3W7dED5o,3928
4
- sklearnex/_device_offload.py,sha256=J0tZqj6tfvIFonWR01PadtTLgloQk_QEfXeCoqEvJlk,7710
4
+ sklearnex/_device_offload.py,sha256=EX9bRBV9tFxQBRf8mS9ntBEmB7tcIfql8sYnb9Zjlto,8639
5
5
  sklearnex/_utils.py,sha256=EV4jC3plVdndsgrfPBsJZTzggrRdYWLwOpoIRWtTXt4,3812
6
6
  sklearnex/conftest.py,sha256=ZvcfQljZNBa3zlE1iITvuacHblugVtK6X80LwNXrnWI,2130
7
- sklearnex/dispatcher.py,sha256=9NPax55jPByCK0zzIvvE4wtmEJ7pCMrDh7IPeP2-vZ8,14389
8
- sklearnex/basic_statistics/__init__.py,sha256=NA5RGlwcp27UEeCgz0ngzYYd3MAIRpxlTy86uhM2-RE,821
7
+ sklearnex/dispatcher.py,sha256=Vpoy6kwOR0Y3ISfjpk0S1vEKhDZGLUKeMy-xwCBsCQs,14389
8
+ sklearnex/basic_statistics/__init__.py,sha256=-lNh54F2FO0BuHDBLjhW7zp3yBcgFZ-DrXHj2H5hLXE,920
9
9
  sklearnex/basic_statistics/basic_statistics.py,sha256=j5jBZ3DgXjoyjCBEFfYQHyl3LgLXEWWFnNHwInThdZw,796
10
+ sklearnex/basic_statistics/incremental_basic_statistics.py,sha256=NNWF9zdxBz2jT7dzt5hL6HRvjQIGosvViQE3KJMF1L4,10048
11
+ sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py,sha256=GarYPjojsyhbOat5vOXF85AofyFa_VretX4Vntc01C8,14992
10
12
  sklearnex/cluster/__init__.py,sha256=TsDzdbKzEubaP86iY8a7mSW0ZQzgjzGYuPkhc5lZmlQ,853
11
13
  sklearnex/cluster/dbscan.py,sha256=JJaNVhV4dVK0xte9xzQpCAka80xVu3M7_SzmvD3k-EY,6736
12
14
  sklearnex/cluster/k_means.py,sha256=1QKcFUQcnycu8kSD8uYSaDIuedHbxZsV_gvUfcEwVAM,806
@@ -16,21 +18,21 @@ sklearnex/covariance/__init__.py,sha256=_c86wiKDGBH50ofN-_tn7lO4M2YVEWO5AHhJIfim
16
18
  sklearnex/covariance/incremental_covariance.py,sha256=3s9gmLP48DPhlhnFcg2JB7RQ2sliSZdNroJkv8-1sIA,4526
17
19
  sklearnex/covariance/tests/test_incremental_covariance.py,sha256=JIa4p-1_RYvU2ZVLx27iz0OKp0Nwrl9sYCsT0Dlyi2I,5402
18
20
  sklearnex/decomposition/__init__.py,sha256=RJBYDWyvnn5DA-j5r4IqVdXLp6H4mdPySsSjnXhlv-U,805
19
- sklearnex/decomposition/pca.py,sha256=XLUUM-bGeXiFXc81uUxNEIYwQ6e5edmjQ94wqnLt_xg,12829
21
+ sklearnex/decomposition/pca.py,sha256=ffR22wH2n5R8SYflEmOPDPc-QpTomiAMOegV0IMbslg,12654
20
22
  sklearnex/decomposition/tests/test_pca.py,sha256=FJYMosxpQpdOo71QD0jVx47oWEhvVNdut_5EOxTyT_0,2201
21
23
  sklearnex/doc/third-party-programs.txt,sha256=qA1XbOqYkMRnp29p8VxXjfcH0kHE8NSO5s2heea83-8,21773
22
24
  sklearnex/ensemble/__init__.py,sha256=2xB2KfG7l7uJv0p3kfVhrs4KLM174SCsigZhYqwSYAA,1035
23
- sklearnex/ensemble/_forest.py,sha256=kOtLig8WVipa2VbgMgTQAkHkbSd5UHcz05uMJCtJ8AE,70553
25
+ sklearnex/ensemble/_forest.py,sha256=OHxqhYhkdjzhhEeWLlE0_IXBrWmKCUJoP_B1gQcmTQM,70002
24
26
  sklearnex/ensemble/tests/test_forest.py,sha256=r1GSPQuVVuWYoNB3ZLiGKfMSwq3lp5i6k-Rgr7InonQ,4456
25
27
  sklearnex/glob/__main__.py,sha256=--FAjkhh5E6a1TFOGu6_BM3MHe78jP8oSpl0xKiRtTI,2531
26
28
  sklearnex/glob/dispatcher.py,sha256=IEEPhAOCVzC2JDFvYtijbiPAbaUY5RrCAhFLRjMMe1w,3018
27
29
  sklearnex/linear_model/__init__.py,sha256=5XZDZh8R0SmT8D8ZtSjW7-MKRO7l1jOZ8CUnt_OzHe4,1047
28
30
  sklearnex/linear_model/coordinate_descent.py,sha256=uZOHIKfFlHoMlNXZCh2MAnZE30fRZlmtcF7UsZQ3Vq4,822
29
- sklearnex/linear_model/linear.py,sha256=ed7pNKKnRkwa-wC0haUCOGHQoPkA4AuFhKNMzmRL6Fw,13832
31
+ sklearnex/linear_model/linear.py,sha256=0A2kCTpsGZK8IVkbIhYoAXqMAxHOyY7dO5JLxbNWmLw,11159
30
32
  sklearnex/linear_model/logistic_path.py,sha256=Nq3JPXSzE4bjamnP3gGQtsMKks2v7s6bSiuYRnFqrRw,849
31
- sklearnex/linear_model/logistic_regression.py,sha256=KgQ97a7-4ywoRakCUlqPxp-0s4EMZr2XTah-NupKUUY,12990
33
+ sklearnex/linear_model/logistic_regression.py,sha256=6TRaDJ8nIHxjofIfUvmeJOP9_EwmUgVKKK1sxe9vS5A,14171
32
34
  sklearnex/linear_model/ridge.py,sha256=0oxlM5McYYvl0KxK9OIGJKM6lOADuFSPTdfx-efJNTI,810
33
- sklearnex/linear_model/tests/test_linear.py,sha256=li9LLWgap6YCwvNiHQ9yHduvUIsK1lpXfuVNR3dLwig,3200
35
+ sklearnex/linear_model/tests/test_linear.py,sha256=kLoOcP9p0iCK2PhU438tGuPGuuBekF37FkA-YBcBMpM,4319
34
36
  sklearnex/linear_model/tests/test_logreg.py,sha256=mUYDwTDUekERlzxjnVeOeCUcNv4KJAXdTIiELZNSaDc,3283
35
37
  sklearnex/manifold/__init__.py,sha256=3FU5fY1YvHAyNeSlUHsZfPnAbvlAUtZpum0Obmok2KE,809
36
38
  sklearnex/manifold/t_sne.py,sha256=U6F_dGB6taVuEJvTnVBWD-sri3x3m0Khu3HI4wXidhg,805
@@ -43,19 +45,19 @@ sklearnex/model_selection/__init__.py,sha256=64045Y-nzLDBepO6IRjt88LhL2DM3KdvpCF
43
45
  sklearnex/model_selection/split.py,sha256=qjmy8sRf_QEG8LhT0ivn_tICMCYmt7ffZZV1-rLQnko,824
44
46
  sklearnex/model_selection/tests/test_model_selection.py,sha256=3kZIq8kba8SW93DBWXupoRymNStR1_mGGYSErQRnwME,1338
45
47
  sklearnex/neighbors/__init__.py,sha256=_GMJ2L-6YechRYI2fOFwHjy0kebUncE81z4FmdXUlb8,1078
46
- sklearnex/neighbors/_lof.py,sha256=5ze0t8_0EXMwsayKux70zJ0Cl4ndDjzv3Fkr2iUXMUc,8109
47
- sklearnex/neighbors/common.py,sha256=iia-EUIRUIohDCIGpHbVx2PeDlwUvz4Mj1Tn169jidA,10781
48
- sklearnex/neighbors/knn_classification.py,sha256=eS_uUEdhlBITAUfsaUsAQRh85g01ltsDAug2Rog4gEQ,11161
49
- sklearnex/neighbors/knn_regression.py,sha256=76eLRvngIy56RyNa4e6-Hz_OqeXiulm6CEkwO7ICuUA,9977
50
- sklearnex/neighbors/knn_unsupervised.py,sha256=j9YsD5RzawcKWytr7UR3qNlNni5wkAh3vVZWRBSA7sQ,7542
48
+ sklearnex/neighbors/_lof.py,sha256=5MPkWIb6FS55Q8xWzgc22Ec_PsouuN94SPovt-vsBGE,8648
49
+ sklearnex/neighbors/common.py,sha256=8DxDoYtXtEM4RNoMCimpTVSDOOxUIJlNVOQvBXBhkd4,10875
50
+ sklearnex/neighbors/knn_classification.py,sha256=ONoBbtwb5xoVLcpg5COpRNu1ZBOQ2EDh03RzbWDy5yo,8537
51
+ sklearnex/neighbors/knn_regression.py,sha256=YBjvh6h56OaJHSZNGq8ZV8lsB-XpSWduEcVeHRuPorQ,6692
52
+ sklearnex/neighbors/knn_unsupervised.py,sha256=qkj-hSEq8QetYsWlofnik3PpFvo1iBUbIOhywo8wFWk,5362
51
53
  sklearnex/neighbors/tests/test_neighbors.py,sha256=gcJeJwDoT7wvyvk423k9TDGTGfbXUSTQETUT-VYQ74U,3409
52
54
  sklearnex/preview/__init__.py,sha256=OXC_k2kudA13rVesXb5ZlEC7_mKUS7uUra_BR-Tin30,780
53
55
  sklearnex/preview/cluster/__init__.py,sha256=FONzOuTGAb5NwdfFhLco99P_VccRk9NBkDHU3EKuAIs,794
54
56
  sklearnex/preview/cluster/_common.py,sha256=bgpzijxgyrAtdNCCHyCNsZ-N70KQYNwMuoCTNdUna6o,2718
55
- sklearnex/preview/cluster/k_means.py,sha256=jSuU8E6r4fdbbBnxBpWp4ybBa62kCnbBx7zDXyUr0Cs,13007
57
+ sklearnex/preview/cluster/k_means.py,sha256=RdF9mwgvZ1xgyeLhCQA2WaPvPsS1ndktXXcaNj6S460,10464
56
58
  sklearnex/preview/covariance/__init__.py,sha256=DPYTk8lwcVphtwU8J3CyUYH8Uz6Zr0Uz4S6nn-RY5iM,825
57
- sklearnex/preview/covariance/covariance.py,sha256=LrNrGP62FEhTSBVaO-EOYAaq-Rszc1VS2B2IqMgh4oo,4938
58
- sklearnex/preview/covariance/tests/test_covariance.py,sha256=GYI4bMIhGnjmOXpt8J7R0JQmpm9eOvDjIphugRa4kD8,2140
59
+ sklearnex/preview/covariance/covariance.py,sha256=NjRTWLie7UbpfN16wGSxJSRHRhUnvTn03cPPc8PpPd8,5131
60
+ sklearnex/preview/covariance/tests/test_covariance.py,sha256=FOgvhJxFQo9sNG4Uo-ebuw3ZXJ9tSxdk8qKm0ZJzTdc,2487
59
61
  sklearnex/spmd/__init__.py,sha256=ChQy2kEWlo4KGvs0RnbPoPEVhdgl8URV099B1rZtF5Y,889
60
62
  sklearnex/spmd/basic_statistics/__init__.py,sha256=NA5RGlwcp27UEeCgz0ngzYYd3MAIRpxlTy86uhM2-RE,821
61
63
  sklearnex/spmd/basic_statistics/basic_statistics.py,sha256=_dQ9mhVYxeuChATEpAmHpXDpgW3YvtK1qrG-kLr2MtI,886
@@ -74,25 +76,26 @@ sklearnex/spmd/linear_model/logistic_regression.py,sha256=q_HkfWcg0RgFbk2t9FeV0Z
74
76
  sklearnex/spmd/neighbors/__init__.py,sha256=S16sH8N_18LN_8AgC_wGK5EDSNyuN-F-gI6GVlaiWVE,906
75
77
  sklearnex/spmd/neighbors/neighbors.py,sha256=SiKAS_RVt34MUcGytBS5pHnI_5vFNxJn8jqt1MOhDh8,940
76
78
  sklearnex/svm/__init__.py,sha256=f3e4ZFwZfx6MsXsn94VK1xVm6mWKT5XCiHczo6zNyAQ,1057
77
- sklearnex/svm/_common.py,sha256=Dt1Iyz1g04zOW6hn9cHa9ruzM_MHAIq0ZEEIxh5s7nI,7167
78
- sklearnex/svm/nusvc.py,sha256=-KMGIanTxVwT9ovvdvGuGBGoMMFQQpAyn1uCoz4CmXA,9150
79
- sklearnex/svm/nusvr.py,sha256=bkLU8HRlpnnZGxdL6t44Uo-idw1KQOeq2shKBIXf24g,5237
80
- sklearnex/svm/svc.py,sha256=2wa6gNGMLE1b-sPapP_i89P9fiALDamo8nRIo8H6VS4,10426
81
- sklearnex/svm/svr.py,sha256=fmYi0dghOmmyFFVI59COX9-tyouQnSDfHIbs8GY8AHs,5241
79
+ sklearnex/svm/_common.py,sha256=52csEWTYWEVgUVWUm3RjX1VD_5VyyawXBvc7lBBp5qY,7010
80
+ sklearnex/svm/nusvc.py,sha256=J4F_Tm9oYC-WK1Nf_CNqSnvuYEEZZ9xa3VY-x0G_2cw,9871
81
+ sklearnex/svm/nusvr.py,sha256=ZFBnQzMgD4aRSk3BRIxwKfwErVyDJnNoR7vrIMm5WLk,3655
82
+ sklearnex/svm/svc.py,sha256=u9wQ8dsvQvO4XP_3JSfYFBNJcuDyv3HVG5NY6jZqhZk,11125
83
+ sklearnex/svm/svr.py,sha256=ldNWehrU4vgqX_0T8splmBjPsQln7w_h8L4XNpIgP6A,3655
82
84
  sklearnex/svm/tests/test_svm.py,sha256=Ru-aGNGCsRJts7SEEYbnKcVqUx-DqPyUtw-hEoMVpW8,4190
83
- sklearnex/tests/_utils.py,sha256=XYWbUlcdzFDc2DKgHCBdScFrzarsWQrs9GKsTlJsqPs,5059
85
+ sklearnex/tests/_utils.py,sha256=hc3LxZDhlncONCGxqvWajQE7iVnSnt98Q9bem-KJDGI,5386
84
86
  sklearnex/tests/test_config.py,sha256=SnSJjxAAysISDyC3bYKSJiRHStkB9X-yjLeF11LpRog,1372
85
87
  sklearnex/tests/test_memory_usage.py,sha256=LwIuUgG7CUZ2kOk1XlxyaK7O3OlyoVwx40TgljaYs5Q,7327
86
88
  sklearnex/tests/test_monkeypatch.py,sha256=_9s_4jFvbttOf8uCuBrS4rn_AzQdFlKyRlthnGacUcU,9669
87
- sklearnex/tests/test_n_jobs_support.py,sha256=ynfCSdCMnR3yEq1YEf_cilVD7zSe0sS-ZQ9jC0hHo8M,3903
89
+ sklearnex/tests/test_n_jobs_support.py,sha256=fNGlQz882qAJoJ56ymbID0hpIsO_7PHLmXxSew2JA_k,4124
88
90
  sklearnex/tests/test_parallel.py,sha256=0zzlh2VJZWcHw5W4QSUthtAygOb6K0Bg1ekNsrdGJQE,1770
89
- sklearnex/tests/test_patching.py,sha256=eZQRz4GsUkm9yMZj_LgT62hMbUNVdTJg88_UccezoJA,13187
91
+ sklearnex/tests/test_patching.py,sha256=Gc4MChHY6lVUFkm3sgPF4RDd1uOqHQFfh9ac60d4vfQ,14299
90
92
  sklearnex/tests/test_run_to_run_stability_tests.py,sha256=4HDOeJruA1EDILbyQJtsHFmEXC0D1upSHuOT-KyTlEc,14008
91
- sklearnex/utils/__init__.py,sha256=I8mbJQ3Zsm_F3sCLAhJQb7tUrG30kVsQ-wZoqA8vDdA,842
93
+ sklearnex/utils/__init__.py,sha256=FFlM8zc2qnSdPYpLjSt4Ma_9FjC8qk8wXJa-5B8hCs0,898
94
+ sklearnex/utils/_namespace.py,sha256=lWzvzcObxq350A-Ms8JyTbaQStR8rgH4DgQYhWruHL4,3166
92
95
  sklearnex/utils/parallel.py,sha256=VBcS-KUdyq7XpJUN6ygmNjyWtYLroghbvCxQ8nVU3YI,2085
93
96
  sklearnex/utils/validation.py,sha256=fjfhQiKnBQnD7LCBlacMyvsrhGnlMLRXk5Q69uoZIP4,827
94
- scikit_learn_intelex-2024.3.0.dist-info/LICENSE.txt,sha256=7micbUpzQXphq9e_2oL7PpZcvoXzPuQHIDEXyKXC81s,10797
95
- scikit_learn_intelex-2024.3.0.dist-info/METADATA,sha256=KeIxHsT7qgO6Z0kvFuwF1SIZ5_fPWgQmgM40Iq7V1BE,12449
96
- scikit_learn_intelex-2024.3.0.dist-info/WHEEL,sha256=8HLRuLcXtw8zhRBAbl72hZgSmSYmdfyBfCzEjumF0eI,108
97
- scikit_learn_intelex-2024.3.0.dist-info/top_level.txt,sha256=kzKChSWGJEYFmdj5PwE63HNuP_PVOhWfD32ytH9rL9Q,10
98
- scikit_learn_intelex-2024.3.0.dist-info/RECORD,,
97
+ scikit_learn_intelex-2024.4.0.dist-info/LICENSE.txt,sha256=7micbUpzQXphq9e_2oL7PpZcvoXzPuQHIDEXyKXC81s,10797
98
+ scikit_learn_intelex-2024.4.0.dist-info/METADATA,sha256=We3kZekomEyuXZpbrpq05hqphdjy8S5Q_geoj0Mb93c,12449
99
+ scikit_learn_intelex-2024.4.0.dist-info/WHEEL,sha256=8HLRuLcXtw8zhRBAbl72hZgSmSYmdfyBfCzEjumF0eI,108
100
+ scikit_learn_intelex-2024.4.0.dist-info/top_level.txt,sha256=kzKChSWGJEYFmdj5PwE63HNuP_PVOhWfD32ytH9rL9Q,10
101
+ scikit_learn_intelex-2024.4.0.dist-info/RECORD,,
@@ -16,6 +16,7 @@
16
16
 
17
17
  import logging
18
18
  import sys
19
+ from collections.abc import Iterable
19
20
  from functools import wraps
20
21
 
21
22
  import numpy as np
@@ -200,9 +201,35 @@ def _copy_to_usm(queue, array):
200
201
  raise RuntimeError(
201
202
  "dpctl need to be installed to work " "with __sycl_usm_array_interface__"
202
203
  )
203
- mem = MemoryUSMDevice(array.nbytes, queue=queue)
204
- mem.copy_from_host(array.tobytes())
205
- return usm_ndarray(array.shape, array.dtype, buffer=mem)
204
+
205
+ if hasattr(array, "__array__"):
206
+
207
+ try:
208
+ mem = MemoryUSMDevice(array.nbytes, queue=queue)
209
+ mem.copy_from_host(array.tobytes())
210
+ return usm_ndarray(array.shape, array.dtype, buffer=mem)
211
+ except ValueError as e:
212
+ # ValueError will raise if device does not support the dtype
213
+ # retry with float32 (needed for fp16 and fp64 support issues)
214
+ # try again as float32, if it is a float32 just raise the error.
215
+ if array.dtype == np.float32:
216
+ raise e
217
+ return _copy_to_usm(queue, array.astype(np.float32))
218
+ else:
219
+ if isinstance(array, Iterable):
220
+ array = [_copy_to_usm(queue, i) for i in array]
221
+ return array
222
+
223
+
224
+ if dpnp_available:
225
+
226
+ def _convert_to_dpnp(array):
227
+ if isinstance(array, usm_ndarray):
228
+ return dpnp.array(array, copy=False)
229
+ elif isinstance(array, Iterable):
230
+ for i in range(len(array)):
231
+ array[i] = _convert_to_dpnp(array[i])
232
+ return array
206
233
 
207
234
 
208
235
  def wrap_output_data(func):
@@ -217,7 +244,7 @@ def wrap_output_data(func):
217
244
  if usm_iface is not None:
218
245
  result = _copy_to_usm(usm_iface["syclobj"], result)
219
246
  if dpnp_available and isinstance(data[0], dpnp.ndarray):
220
- result = dpnp.array(result, copy=False)
247
+ result = _convert_to_dpnp(result)
221
248
  return result
222
249
 
223
250
  return wrapper
@@ -15,5 +15,6 @@
15
15
  # ==============================================================================
16
16
 
17
17
  from .basic_statistics import BasicStatistics
18
+ from .incremental_basic_statistics import IncrementalBasicStatistics
18
19
 
19
- __all__ = ["BasicStatistics"]
20
+ __all__ = ["BasicStatistics", "IncrementalBasicStatistics"]
@@ -0,0 +1,288 @@
1
+ # ==============================================================================
2
+ # Copyright 2024 Intel Corporation
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ==============================================================================
16
+
17
+ import numpy as np
18
+ from sklearn.base import BaseEstimator
19
+ from sklearn.utils import check_array, gen_batches
20
+ from sklearn.utils.validation import _check_sample_weight
21
+
22
+ from daal4py.sklearn._n_jobs_support import control_n_jobs
23
+ from daal4py.sklearn._utils import sklearn_check_version
24
+ from onedal.basic_statistics import (
25
+ IncrementalBasicStatistics as onedal_IncrementalBasicStatistics,
26
+ )
27
+
28
+ from .._device_offload import dispatch
29
+ from .._utils import PatchingConditionsChain
30
+
31
+ if sklearn_check_version("1.2"):
32
+ from sklearn.utils._param_validation import Interval, StrOptions
33
+
34
+ import numbers
35
+
36
+
37
+ @control_n_jobs(decorated_methods=["partial_fit", "_onedal_finalize_fit"])
38
+ class IncrementalBasicStatistics(BaseEstimator):
39
+ """
40
+ Incremental estimator for basic statistics.
41
+ Allows to compute basic statistics if data are splitted into batches.
42
+ Parameters
43
+ ----------
44
+ result_options: string or list, default='all'
45
+ List of statistics to compute
46
+
47
+ batch_size : int, default=None
48
+ The number of samples to use for each batch. Only used when calling
49
+ ``fit``. If ``batch_size`` is ``None``, then ``batch_size``
50
+ is inferred from the data and set to ``5 * n_features``, to provide a
51
+ balance between approximation accuracy and memory consumption.
52
+
53
+ Attributes (are existing only if corresponding result option exists)
54
+ ----------
55
+ min : ndarray of shape (n_features,)
56
+ Minimum of each feature over all samples.
57
+
58
+ max : ndarray of shape (n_features,)
59
+ Maximum of each feature over all samples.
60
+
61
+ sum : ndarray of shape (n_features,)
62
+ Sum of each feature over all samples.
63
+
64
+ mean : ndarray of shape (n_features,)
65
+ Mean of each feature over all samples.
66
+
67
+ variance : ndarray of shape (n_features,)
68
+ Variance of each feature over all samples.
69
+
70
+ variation : ndarray of shape (n_features,)
71
+ Variation of each feature over all samples.
72
+
73
+ sum_squares : ndarray of shape (n_features,)
74
+ Sum of squares for each feature over all samples.
75
+
76
+ standard_deviation : ndarray of shape (n_features,)
77
+ Standard deviation of each feature over all samples.
78
+
79
+ sum_squares_centered : ndarray of shape (n_features,)
80
+ Centered sum of squares for each feature over all samples.
81
+
82
+ second_order_raw_moment : ndarray of shape (n_features,)
83
+ Second order moment of each feature over all samples.
84
+ """
85
+
86
+ _onedal_incremental_basic_statistics = staticmethod(onedal_IncrementalBasicStatistics)
87
+
88
+ if sklearn_check_version("1.2"):
89
+ _parameter_constraints: dict = {
90
+ "result_options": [
91
+ StrOptions(
92
+ {
93
+ "all",
94
+ "min",
95
+ "max",
96
+ "sum",
97
+ "mean",
98
+ "variance",
99
+ "variation",
100
+ "sum_squares",
101
+ "standard_deviation",
102
+ "sum_squares_centered",
103
+ "second_order_raw_moment",
104
+ }
105
+ ),
106
+ list,
107
+ ],
108
+ "batch_size": [Interval(numbers.Integral, 1, None, closed="left"), None],
109
+ }
110
+
111
+ def __init__(self, result_options="all", batch_size=None):
112
+ if result_options == "all":
113
+ self.result_options = (
114
+ self._onedal_incremental_basic_statistics.get_all_result_options()
115
+ )
116
+ else:
117
+ self.result_options = result_options
118
+ self._need_to_finalize = False
119
+ self.batch_size = batch_size
120
+
121
+ def _onedal_supported(self, method_name, *data):
122
+ patching_status = PatchingConditionsChain(
123
+ f"sklearn.covariance.{self.__class__.__name__}.{method_name}"
124
+ )
125
+ return patching_status
126
+
127
+ _onedal_cpu_supported = _onedal_supported
128
+ _onedal_gpu_supported = _onedal_supported
129
+
130
+ def _get_onedal_result_options(self, options):
131
+ if isinstance(options, list):
132
+ onedal_options = "|".join(self.result_options)
133
+ else:
134
+ onedal_options = options
135
+ assert isinstance(onedal_options, str)
136
+ return options
137
+
138
+ def _onedal_finalize_fit(self):
139
+ assert hasattr(self, "_onedal_estimator")
140
+ self._onedal_estimator.finalize_fit()
141
+ self._need_to_finalize = False
142
+
143
+ def _onedal_partial_fit(self, X, sample_weight=None, queue=None):
144
+ first_pass = not hasattr(self, "n_samples_seen_") or self.n_samples_seen_ == 0
145
+
146
+ if sklearn_check_version("1.0"):
147
+ X = self._validate_data(
148
+ X,
149
+ dtype=[np.float64, np.float32],
150
+ reset=first_pass,
151
+ )
152
+ else:
153
+ X = check_array(
154
+ X,
155
+ dtype=[np.float64, np.float32],
156
+ )
157
+
158
+ if sample_weight is not None:
159
+ sample_weight = _check_sample_weight(sample_weight, X)
160
+
161
+ if first_pass:
162
+ self.n_samples_seen_ = X.shape[0]
163
+ self.n_features_in_ = X.shape[1]
164
+ else:
165
+ self.n_samples_seen_ += X.shape[0]
166
+
167
+ onedal_params = {
168
+ "result_options": self._get_onedal_result_options(self.result_options)
169
+ }
170
+ if not hasattr(self, "_onedal_estimator"):
171
+ self._onedal_estimator = self._onedal_incremental_basic_statistics(
172
+ **onedal_params
173
+ )
174
+ self._onedal_estimator.partial_fit(X, sample_weight, queue)
175
+ self._need_to_finalize = True
176
+
177
+ def _onedal_fit(self, X, sample_weight=None, queue=None):
178
+ if sklearn_check_version("1.0"):
179
+ X = self._validate_data(X, dtype=[np.float64, np.float32])
180
+ else:
181
+ X = check_array(X, dtype=[np.float64, np.float32])
182
+
183
+ if sample_weight is not None:
184
+ sample_weight = _check_sample_weight(sample_weight, X)
185
+
186
+ n_samples, n_features = X.shape
187
+ if self.batch_size is None:
188
+ self.batch_size_ = 5 * n_features
189
+ else:
190
+ self.batch_size_ = self.batch_size
191
+
192
+ self.n_samples_seen_ = 0
193
+ if hasattr(self, "_onedal_estimator"):
194
+ self._onedal_estimator._reset()
195
+
196
+ for batch in gen_batches(X.shape[0], self.batch_size_):
197
+ X_batch = X[batch]
198
+ weights_batch = sample_weight[batch] if sample_weight is not None else None
199
+ self._onedal_partial_fit(X_batch, weights_batch, queue=queue)
200
+
201
+ if sklearn_check_version("1.2"):
202
+ self._validate_params()
203
+
204
+ self.n_features_in_ = X.shape[1]
205
+
206
+ self._onedal_finalize_fit()
207
+
208
+ return self
209
+
210
+ def __getattr__(self, attr):
211
+ result_options = self.__dict__["result_options"]
212
+ is_statistic_attr = (
213
+ isinstance(result_options, str) and (attr == result_options)
214
+ ) or (isinstance(result_options, list) and (attr in result_options))
215
+ if is_statistic_attr:
216
+ if self._need_to_finalize:
217
+ self._onedal_finalize_fit()
218
+ return getattr(self._onedal_estimator, attr)
219
+ if attr in self.__dict__:
220
+ return self.__dict__[attr]
221
+
222
+ raise AttributeError(
223
+ f"'{self.__class__.__name__}' object has no attribute '{attr}'"
224
+ )
225
+
226
+ def partial_fit(self, X, sample_weight=None):
227
+ """Incremental fit with X. All of X is processed as a single batch.
228
+
229
+ Parameters
230
+ ----------
231
+ X : array-like of shape (n_samples, n_features)
232
+ Data for compute, where `n_samples` is the number of samples and
233
+ `n_features` is the number of features.
234
+
235
+ y : Ignored
236
+ Not used, present for API consistency by convention.
237
+
238
+ sample_weight : array-like of shape (n_samples,), default=None
239
+ Weights for compute weighted statistics, where `n_samples` is the number of samples.
240
+
241
+ Returns
242
+ -------
243
+ self : object
244
+ Returns the instance itself.
245
+ """
246
+ dispatch(
247
+ self,
248
+ "partial_fit",
249
+ {
250
+ "onedal": self.__class__._onedal_partial_fit,
251
+ "sklearn": None,
252
+ },
253
+ X,
254
+ sample_weight,
255
+ )
256
+ return self
257
+
258
+ def fit(self, X, y=None, sample_weight=None):
259
+ """Compute statistics with X, using minibatches of size batch_size.
260
+
261
+ Parameters
262
+ ----------
263
+ X : array-like of shape (n_samples, n_features)
264
+ Data for compute, where `n_samples` is the number of samples and
265
+ `n_features` is the number of features.
266
+
267
+ y : Ignored
268
+ Not used, present for API consistency by convention.
269
+
270
+ sample_weight : array-like of shape (n_samples,), default=None
271
+ Weights for compute weighted statistics, where `n_samples` is the number of samples.
272
+
273
+ Returns
274
+ -------
275
+ self : object
276
+ Returns the instance itself.
277
+ """
278
+ dispatch(
279
+ self,
280
+ "fit",
281
+ {
282
+ "onedal": self.__class__._onedal_fit,
283
+ "sklearn": None,
284
+ },
285
+ X,
286
+ sample_weight,
287
+ )
288
+ return self