From a205592d9749b42a003f3d85bb1d3aba8b314d53 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:19:31 +0200 Subject: [PATCH] FIX: incremental estimators tests (#1998) (#2021) * FIX: incremental estimators tests (cherry picked from commit 4fd45689a9fc998c2f3228d4b066bf0e1aa04bf0) Co-authored-by: Samir Nasibli --- .../linear_model/tests/test_incremental_linear.py | 15 +++++++++------ .../decomposition/tests/test_incremental_pca.py | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sklearnex/linear_model/tests/test_incremental_linear.py b/sklearnex/linear_model/tests/test_incremental_linear.py index 54c33239ee..296c714ead 100644 --- a/sklearnex/linear_model/tests/test_incremental_linear.py +++ b/sklearnex/linear_model/tests/test_incremental_linear.py @@ -46,12 +46,13 @@ def test_sklearnex_fit_on_gold_data(dataframe, queue, fit_intercept, macro_block inclin.fit(X_df, y_df) y_pred = inclin.predict(X_df) + np_y_pred = _as_numpy(y_pred) - tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7 + tol = 2e-6 if dtype == np.float32 else 1e-7 assert_allclose(inclin.coef_, [1], atol=tol) if fit_intercept: assert_allclose(inclin.intercept_, [0], atol=tol) - assert_allclose(_as_numpy(y_pred), y, atol=tol) + assert_allclose(np_y_pred, y, atol=tol) @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues()) @@ -84,14 +85,15 @@ def test_sklearnex_partial_fit_on_gold_data( X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe) y_pred = inclin.predict(X_df) + np_y_pred = _as_numpy(y_pred) assert inclin.n_features_in_ == 1 - tol = 2e-6 if y_pred.dtype == np.float32 else 1e-7 + tol = 2e-6 if dtype == np.float32 else 1e-7 assert_allclose(inclin.coef_, [[1]], atol=tol) if fit_intercept: assert_allclose(inclin.intercept_, 3, atol=tol) - assert_allclose(_as_numpy(y_pred), y, atol=tol) + assert_allclose(np_y_pred, y, atol=tol) @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues()) @@ -124,14 +126,15 @@ def test_sklearnex_partial_fit_multitarget_on_gold_data( X_df = _convert_to_dataframe(X, sycl_queue=queue, target_df=dataframe) y_pred = inclin.predict(X_df) + np_y_pred = _as_numpy(y_pred) assert inclin.n_features_in_ == 2 - tol = 7e-6 if y_pred.dtype == np.float32 else 1e-7 + tol = 7e-6 if dtype == np.float32 else 1e-7 assert_allclose(inclin.coef_, [1.0, 2.0], atol=tol) if fit_intercept: assert_allclose(inclin.intercept_, 3.0, atol=tol) - assert_allclose(_as_numpy(y_pred), y, atol=tol) + assert_allclose(np_y_pred, y, atol=tol) @pytest.mark.parametrize("dataframe,queue", get_dataframes_and_queues()) diff --git a/sklearnex/preview/decomposition/tests/test_incremental_pca.py b/sklearnex/preview/decomposition/tests/test_incremental_pca.py index 786ae4fef0..67929bfac8 100644 --- a/sklearnex/preview/decomposition/tests/test_incremental_pca.py +++ b/sklearnex/preview/decomposition/tests/test_incremental_pca.py @@ -74,7 +74,7 @@ def check_pca_on_gold_data(incpca, dtype, whiten, transformed_data): ) tol = 1e-7 - if transformed_data.dtype == np.float32: + if dtype == np.float32: tol = 7e-6 if whiten else 1e-6 assert incpca.n_samples_seen_ == expected_n_samples_seen_ @@ -112,7 +112,7 @@ def check_pca_on_gold_data(incpca, dtype, whiten, transformed_data): def check_pca(incpca, dtype, whiten, data, transformed_data): - tol = 3e-3 if transformed_data.dtype == np.float32 else 2e-6 + tol = 3e-3 if dtype == np.float32 else 2e-6 n_components = incpca.n_components_