Skip to content

Commit a205592

Browse files
FIX: incremental estimators tests (#1998) (#2021)
* FIX: incremental estimators tests (cherry picked from commit 4fd4568) Co-authored-by: Samir Nasibli <[email protected]>
1 parent 84666fa commit a205592

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

sklearnex/linear_model/tests/test_incremental_linear.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ def test_sklearnex_fit_on_gold_data(dataframe, queue, fit_intercept, macro_block
4646
inclin.fit(X_df, y_df)
4747

4848
y_pred = inclin.predict(X_df)
49+
np_y_pred = _as_numpy(y_pred)
4950

50-
tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7
51+
tol = 2e-6 if dtype == np.float32 else 1e-7
5152
assert_allclose(inclin.coef_, [1], atol=tol)
5253
if fit_intercept:
5354
assert_allclose(inclin.intercept_, [0], atol=tol)
54-
assert_allclose(_as_numpy(y_pred), y, atol=tol)
55+
assert_allclose(np_y_pred, y, atol=tol)
5556

5657

5758
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
@@ -84,14 +85,15 @@ def test_sklearnex_partial_fit_on_gold_data(
8485

8586
X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
8687
y_pred = inclin.predict(X_df)
88+
np_y_pred = _as_numpy(y_pred)
8789

8890
assert inclin.n_features_in_ == 1
89-
tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7
91+
tol = 2e-6 if dtype == np.float32 else 1e-7
9092
assert_allclose(inclin.coef_, [[1]], atol=tol)
9193
if fit_intercept:
9294
assert_allclose(inclin.intercept_, 3, atol=tol)
9395

94-
assert_allclose(_as_numpy(y_pred), y, atol=tol)
96+
assert_allclose(np_y_pred, y, atol=tol)
9597

9698

9799
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())
@@ -124,14 +126,15 @@ def test_sklearnex_partial_fit_multitarget_on_gold_data(
124126

125127
X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe)
126128
y_pred = inclin.predict(X_df)
129+
np_y_pred = _as_numpy(y_pred)
127130

128131
assert inclin.n_features_in_ == 2
129-
tol = 7e-6 if y_pred.dtype == np.float32 else 1e-7
132+
tol = 7e-6 if dtype == np.float32 else 1e-7
130133
assert_allclose(inclin.coef_, [1.0, 2.0], atol=tol)
131134
if fit_intercept:
132135
assert_allclose(inclin.intercept_, 3.0, atol=tol)
133136

134-
assert_allclose(_as_numpy(y_pred), y, atol=tol)
137+
assert_allclose(np_y_pred, y, atol=tol)
135138

136139

137140
@pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues())

sklearnex/preview/decomposition/tests/test_incremental_pca.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def check_pca_on_gold_data(incpca, dtype, whiten, transformed_data):
7474
)
7575

7676
tol = 1e-7
77-
if transformed_data.dtype == np.float32:
77+
if dtype == np.float32:
7878
tol = 7e-6 if whiten else 1e-6
7979

8080
assert incpca.n_samples_seen_ == expected_n_samples_seen_
@@ -112,7 +112,7 @@ def check_pca_on_gold_data(incpca, dtype, whiten, transformed_data):
112112

113113

114114
def check_pca(incpca, dtype, whiten, data, transformed_data):
115-
tol = 3e-3 if transformed_data.dtype == np.float32 else 2e-6
115+
tol = 3e-3 if dtype == np.float32 else 2e-6
116116

117117
n_components = incpca.n_components_
118118

0 commit comments

Comments
 (0)