Skip to content
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
af912ff
fix onedal side
icfaust Dec 3, 2024
f97206c
add SPMD interface
icfaust Dec 3, 2024
6579bbd
add new assert_all_finite
icfaust Dec 3, 2024
580e697
change incremental algo
icfaust Dec 3, 2024
8961208
remove old code
icfaust Dec 3, 2024
41c319b
readd deletion
icfaust Dec 3, 2024
5fc159e
missing?
icfaust Dec 3, 2024
6ed0419
Update test_covariance.py
icfaust Dec 3, 2024
8a84ce7
fix error in spmd interface
icfaust Dec 4, 2024
53fe3b2
Merge branch 'main' into new_cov
icfaust Jul 11, 2025
83294fb
fixes
icfaust Jul 11, 2025
0e99ee3
remove changes
icfaust Jul 11, 2025
101144b
fix
icfaust Jul 11, 2025
9ed20eb
fix preview
icfaust Jul 11, 2025
203b025
fixes
icfaust Jul 11, 2025
17f3e12
forgotten import
icfaust Jul 11, 2025
b4df020
remove import
icfaust Jul 11, 2025
c5d0e6a
fix squeeze
icfaust Jul 11, 2025
9c572e7
Update test_covariance.py
icfaust Jul 11, 2025
bf6603b
Update covariance.py
icfaust Jul 11, 2025
e13e8b9
Update incremental_covariance.py
icfaust Jul 11, 2025
c643bbf
Update incremental_covariance.py
icfaust Jul 11, 2025
8dcefec
try to fix issues
icfaust Jul 11, 2025
cb17cd4
updates to try and solve score
icfaust Jul 11, 2025
e3a3789
fixes for mahalanobis
icfaust Jul 11, 2025
653039d
Update incremental_covariance.py
icfaust Jul 12, 2025
d75f31e
Update incremental_covariance.py
icfaust Jul 12, 2025
4e09f7d
Update incremental_covariance.py
icfaust Jul 12, 2025
7490cc5
Update incremental_covariance.py
icfaust Jul 12, 2025
f541884
Update incremental_covariance.py
icfaust Jul 12, 2025
bd4de95
Update incremental_covariance.py
icfaust Jul 13, 2025
720f816
expand array API support in sklearnex
icfaust Jul 13, 2025
f7c5d4f
fix spelling mistake
icfaust Jul 13, 2025
6717b54
remove print statement
icfaust Jul 13, 2025
b65bc7d
fix issues with respect to dpctl dpnp
icfaust Jul 13, 2025
1828901
Update covariance.py
icfaust Jul 14, 2025
70ac66b
fix error_norm and score
icfaust Jul 14, 2025
daa1250
try to fix mahal
icfaust Jul 14, 2025
853b0b3
fixes
icfaust Jul 14, 2025
07a6689
fixes
icfaust Jul 14, 2025
3c0964a
fixes again
icfaust Jul 14, 2025
f22dfe7
try again
icfaust Jul 14, 2025
2927572
fixes for test case failures
icfaust Jul 14, 2025
019af95
try again
icfaust Jul 14, 2025
2670249
try to remove regression
icfaust Jul 14, 2025
df8e0ad
fix mistakes
icfaust Jul 14, 2025
6f72849
updates
icfaust Jul 14, 2025
bb13126
fix covariance
icfaust Jul 14, 2025
02b78a9
standardize validate_params
icfaust Jul 15, 2025
0c9dc1c
Merge branch 'uxlfoundation:main' into new_cov
icfaust Jul 15, 2025
671bbaa
Update covariance.py
icfaust Jul 15, 2025
095f9dc
Update covariance.py
icfaust Jul 15, 2025
fa1deae
Merge branch 'uxlfoundation:main' into new_cov
icfaust Jul 15, 2025
5929c8d
Merge branch 'main' into new_cov
icfaust Jul 16, 2025
34006ec
fix issues with double import
icfaust Jul 16, 2025
90f050d
Merge branch 'main' into new_cov
icfaust Jul 27, 2025
f0b6b45
Update covariance.py
icfaust Jul 29, 2025
c8c9b71
Update covariance.py
icfaust Jul 29, 2025
a59e11b
Update _array_api.py
icfaust Jul 30, 2025
0617a1d
Update _array_api.py
icfaust Jul 30, 2025
71cf164
Update _array_api.py
icfaust Jul 30, 2025
a40658d
Update _array_api.py
icfaust Jul 30, 2025
c6780bb
Merge branch 'uxlfoundation:main' into new_cov
icfaust Jul 30, 2025
a5c6509
Update incremental_covariance.py
icfaust Aug 5, 2025
77688ab
Update incremental_covariance.py
icfaust Aug 5, 2025
92fc141
Update covariance.py
icfaust Aug 5, 2025
d5576da
Update incremental_covariance.py
icfaust Aug 5, 2025
942c347
Update covariance.py
icfaust Aug 5, 2025
52b603e
Update covariance.py
icfaust Aug 6, 2025
8907ab0
Update incremental_covariance.py
icfaust Aug 6, 2025
fd3ea63
Merge branch 'main' into new_cov
icfaust Aug 7, 2025
d26317f
Merge branch 'uxlfoundation:main' into new_cov
icfaust Aug 8, 2025
77faccf
Update incremental_covariance.py
icfaust Aug 8, 2025
b7a6d1c
Update incremental_covariance.py
icfaust Aug 8, 2025
46845a6
Update incremental_covariance.py
icfaust Aug 8, 2025
285d1ac
Update covariance.py
icfaust Aug 8, 2025
6dc7f1b
Update _array_api.py
icfaust Aug 8, 2025
e0f15d5
Update covariance.py
icfaust Aug 8, 2025
5a7751a
Update incremental_covariance.py
icfaust Aug 8, 2025
2ea312d
Update test_incremental_covariance_spmd.py
icfaust Aug 10, 2025
f55112f
Update covariance.py
icfaust Aug 10, 2025
edd38ab
Update test_incremental_covariance_spmd.py
icfaust Aug 10, 2025
eafa3a9
Update covariance.py
icfaust Aug 11, 2025
3296e24
Update incremental_covariance.py
icfaust Aug 11, 2025
346aea8
Update covariance.py
icfaust Aug 11, 2025
93b0418
Update test_covariance_spmd.py
icfaust Aug 11, 2025
2022a4f
Update test_covariance_spmd.py
icfaust Aug 11, 2025
4bc7abd
Update test_covariance_spmd.py
icfaust Aug 11, 2025
7736c4f
Update test_covariance_spmd.py
icfaust Aug 11, 2025
4d35143
Update test_covariance_spmd.py
icfaust Aug 11, 2025
140a8b6
many requisite changes
icfaust Aug 12, 2025
3f15f94
Update test_covariance.py
icfaust Aug 12, 2025
20f8626
force output to a 0d
icfaust Aug 12, 2025
f3e4af6
try to fix test'
icfaust Aug 12, 2025
945b9b8
updates
icfaust Aug 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions onedal/covariance/covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from daal4py.sklearn._utils import daal_check_version
from onedal._device_offload import supports_queue
from onedal.common._backend import bind_default_backend
from onedal.utils.validation import _check_array

from .._config import _get_config
from ..common.hyperparameters import get_hyperparameters
Expand Down Expand Up @@ -101,13 +100,7 @@ def fit(self, X, y=None, queue=None):
self : object
Returns the instance itself.
"""
use_raw_input = _get_config()["use_raw_input"] is True
sua_iface, xp, _ = _get_sycl_namespace(X)
if use_raw_input and sua_iface:
queue = X.sycl_queue

if not use_raw_input:
X = _check_array(X, dtype=[np.float64, np.float32])
X_table = to_table(X, queue=queue)

params = self._get_onedal_params(X_table.dtype)
Expand All @@ -123,6 +116,6 @@ def fit(self, X, y=None, queue=None):
from_table(result.cov_matrix, like=X) * (X.shape[0] - 1) / X.shape[0]
)

self.location_ = xp.squeeze(from_table(result.means, like=X))
self.location_ = from_table(result.means, like=X)

return self
31 changes: 13 additions & 18 deletions onedal/covariance/incremental_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import numpy as np

from daal4py.sklearn._utils import daal_check_version
from onedal._device_offload import supports_queue
from onedal.common._backend import bind_default_backend
from onedal.utils import _sycl_queue_manager as QM

from .._config import _get_config
from ..datatypes import from_table, to_table
from .._device_offload import supports_queue
from ..common._backend import bind_default_backend
from ..datatypes import from_table, return_type_constructor, to_table
from ..utils import _sycl_queue_manager as QM
from ..utils._array_api import _get_sycl_namespace
from ..utils.validation import _check_array
from .covariance import BaseEmpiricalCovariance
Expand Down Expand Up @@ -74,6 +74,7 @@ def finalize_compute(self, params, partial_result): ...
def _reset(self):
self._need_to_finalize = False
self._queue = None
self._outtype = None
self._partial_result = self.partial_compute_result()

def __getstate__(self):
Expand Down Expand Up @@ -108,15 +109,10 @@ def partial_fit(self, X, y=None, queue=None):
self : object
Returns the instance itself.
"""
use_raw_input = _get_config()["use_raw_input"] is True
sua_iface, _, _ = _get_sycl_namespace(X)

if use_raw_input and sua_iface:
queue = X.sycl_queue
if not use_raw_input:
X = _check_array(X, dtype=[np.float64, np.float32], ensure_2d=True)

self._queue = queue
if not self._outtype:
self._outtype = return_type_constructor(X)
X_table = to_table(X, queue=queue)

if not hasattr(self, "_dtype"):
Expand All @@ -125,8 +121,6 @@ def partial_fit(self, X, y=None, queue=None):
params = self._get_onedal_params(self._dtype)
self._partial_result = self.partial_compute(params, self._partial_result, X_table)
self._need_to_finalize = True
# store the queue for when we finalize
self._queue = queue

def finalize_fit(self):
"""Finalize covariance matrix from the current `_partial_result`.
Expand All @@ -143,13 +137,14 @@ def finalize_fit(self):
with QM.manage_global_queue(self._queue):
result = self.finalize_compute(params, self._partial_result)

if daal_check_version((2024, "P", 1)) or (not self.bias):
self.covariance_ = from_table(result.cov_matrix)
else:
self.covariance_ = from_table(result.cov_matrix, like=self._outtype)

if self.bias and not daal_check_version((2024, "P", 1)):
n_rows = self._partial_result.partial_n_rows
self.covariance_ = from_table(result.cov_matrix) * (n_rows - 1) / n_rows
self.covariance_ = self.covariance_ * (n_rows - 1) / n_rows

self.location_ = from_table(result.means).ravel()
self.location_ = from_table(result.means, like=self._outtype)[0, ...]
self._outtype = None

self._need_to_finalize = False

Expand Down
12 changes: 6 additions & 6 deletions onedal/covariance/tests/test_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
def test_onedal_import_covariance(queue):
from onedal.covariance import EmpiricalCovariance

X = np.array([[0, 1], [0, 1]])
X = np.array([[0, 1], [0, 1]], dtype=np.float64)
result = EmpiricalCovariance().fit(X, queue=queue)
expected_covariance = np.array([[0, 0], [0, 0]])
expected_means = np.array([0, 1])

assert_allclose(expected_covariance, result.covariance_)
assert_allclose(expected_means, result.location_)
assert_allclose(expected_means, result.location_[0])

X = np.array([[1, 2], [3, 6]])
X = np.array([[1, 2], [3, 6]], dtype=np.float64)
result = EmpiricalCovariance().fit(X, queue=queue)
expected_covariance = np.array([[2, 4], [4, 8]])
expected_means = np.array([2, 4])

assert_allclose(expected_covariance, result.covariance_)
assert_allclose(expected_means, result.location_)
assert_allclose(expected_means, result.location_[0])

X = np.array([[1, 2], [3, 6]])
X = np.array([[1, 2], [3, 6]], dtype=np.float64)
result = EmpiricalCovariance(bias=True).fit(X, queue=queue)
expected_covariance = np.array([[1, 2], [2, 4]])
expected_means = np.array([2, 4])

assert_allclose(expected_covariance, result.covariance_)
assert_allclose(expected_means, result.location_)
assert_allclose(expected_means, result.location_[0])
Loading
Loading