Skip to content

TST Sets random state in test_csr_row_norms#16509

Merged
rth merged 4 commits intoscikit-learn:masterfrom
thomasjpfan:sets_random_state_in_csr_rows_norms_v2
Feb 21, 2020
Merged

TST Sets random state in test_csr_row_norms#16509
rth merged 4 commits intoscikit-learn:masterfrom
thomasjpfan:sets_random_state_in_csr_rows_norms_v2

Conversation

@thomasjpfan
Copy link
Copy Markdown
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
Copy Markdown

how does setting random state make the test more deterministic?

Copy link
Copy Markdown
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


assert norms.dtype == dtype
assert_allclose(norms, scipy_norms)
rtol = 1e-6 if dtype == np.float32 else 1e-7
Copy link
Copy Markdown
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
Copy Markdown
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