Skip to content

TST Sets random state in test_csr_row_norms #16509

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

thomasjpfan
Copy link
Member

Reference Issues/PRs

Fixes #16506

What does this implement/fix? Explain your changes.

Makes test deterministic by setting random state in test_csr_row_norms.

The alternative is to lower the tolerance for float32.

@swchoi727
Copy link

how does setting random state make the test more deterministic?

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.

Setting the random_state to make the test pass is not enough. We need to fix the thing that makes the test fail. Here it's because a rtol of 1e-7 is not suitable for float32 because machine precision is ~1.2e-7.

I suggest to use rtol=1e-6 for float32


scipy_norms = sp.linalg.norm(X, axis=1)**2
norms = csr_row_norms(X)

assert norms.dtype == dtype
assert_allclose(norms, scipy_norms)
rtol = 1e-6 if dtype == np.float32 else 1e-7
Copy link
Member

Choose a reason for hiding this comment

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

don't remove the other assert 😄

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. Thanks @thomasjpfan ! feel free to merge when green

@rth rth merged commit c1696ed into scikit-learn:master Feb 21, 2020
thomasjpfan added a commit to thomasjpfan/scikit-learn that referenced this pull request Feb 22, 2020
panpiort8 pushed a commit to panpiort8/scikit-learn that referenced this pull request Mar 3, 2020
gio8tisu pushed a commit to gio8tisu/scikit-learn that referenced this pull request May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_csr_row_norms is failing to often on master
4 participants