Skip to content

TST use global_dtype in sklearn/cluster/tests/test_affinity_propagation.py #22667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

jjerphan
Copy link
Member

@jjerphan jjerphan commented Mar 3, 2022

Reference Issues/PRs

Partially addresses #22881
Precedes #22590

What does this implement/fix? Explain your changes.

This parametrizes tests from test_affinity_propagation.py to run on 32bit datasets.

Any other comments?

We could introduce a mechanism to be able to able to remove tests' execution on 32bit datasets if this takes too much time to complete.

@jjerphan jjerphan marked this pull request as ready for review March 3, 2022 15:01
Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar remark as for #22672 for checking the dtype of the fitted attribute affinity_matrix_ and cluster_centers_ which should be float32 with fitting on float32 input data.

@jjerphan jjerphan changed the title TST Adapt test_affinity_propagation.py to test implementations on 32bit datasets. TST use global_dtype in sklearn/cluster/tests/test_affinity_propagation.py Mar 18, 2022
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think _equal_similarities_and_preferences should be updated to use assert_allclose because it compares float arrays.

jjerphan and others added 2 commits March 24, 2022 14:36
Co-authored-by: Jérémie du Boisberranger <jeremiedbb@users.noreply.github.com>
@jjerphan
Copy link
Member Author

I think _equal_similarities_and_preferences should be updated to use assert_allclose because it compares float arrays.

I don't think it should, because this is not a testing fixture but a utility function for affinity propagation that must not raise an AssertionError in case similarities or preferences' inequality.

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeremiedbb
Copy link
Member

I don't think it should, because this is not a testing fixture but a utility function for affinity propagation that must not raise an AssertionError in case similarities or preferences' inequality.

Right. It should use np.allclose. But it would require to create a custom allclose with different rtols. Let's leave that for later

@jeremiedbb jeremiedbb added the Quick Review For PRs that are quick to review label Mar 25, 2022
@glemaitre glemaitre self-requested a review May 6, 2022 13:57
@@ -197,17 +205,17 @@ def test_affinity_propagation_non_convergence_regressiontest():
assert_array_equal(np.array([0, 0, 0]), af.labels_)


def test_equal_similarities_and_preferences():
def test_equal_similarities_and_preferences(global_dtype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous test (test_affinity_propagation_non_convergence_regressiontest) should raise the warning for the different dtypes I think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and test_affinity_propagation_poredict_non_convergence as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous test (test_affinity_propagation_non_convergence_regressiontest) should raise the warning for the different dtypes I think?

Which difference of dtypes are you referring to?

@jjerphan
Copy link
Member Author

I don't think it should, because this is not a testing fixture but a utility function for affinity propagation that must not raise an AssertionError in case similarities or preferences' inequality.

Right. It should use np.allclose. But it would require to create a custom allclose with different rtols. Let's leave that for later

I think this has been implemented in the meantime, hence I've merged main in this small dangling PR.

@cmarmo cmarmo added the Waiting for Second Reviewer First reviewer is done, need a second one! label Oct 28, 2022
@glemaitre glemaitre self-requested a review November 3, 2022 13:38
Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I just added the global_dtype to the 2 additional tests.
I am going to merge when it is green.

@glemaitre glemaitre merged commit f647868 into scikit-learn:main Nov 3, 2022
@jjerphan jjerphan deleted the tst/test_affinity_propagation-32bit branch November 3, 2022 14:46
andportnoy pushed a commit to andportnoy/scikit-learn that referenced this pull request Nov 5, 2022
…on.py (scikit-learn#22667)

Co-authored-by: Jérémie du Boisberranger <jeremiedbb@users.noreply.github.com>
Co-authored-by: Guillaume Lemaitre <g.lemaitre58@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:cluster No Changelog Needed Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants