Use tolerant assertions for floating-point tests#130
Merged
ganow merged 2 commits intoMay 29, 2026
Conversation
Floating-point computation results (corrcoef, mean, detrend, normalize, SGD optimizer step) were compared with assert_array_equal / assertEqual, causing environment-dependent failures due to rounding differences. Replace with np.testing.assert_allclose (rtol=1e-12, atol=1e-12 for float64 NumPy paths; rtol=1e-6, atol=1e-8 for PyTorch tensors) and assertAlmostEqual for the scalar learning-rate check. Integer/index/mask comparisons are left as assert_array_equal. Addresses KamitaniLab#129 Co-authored-by: Claude <noreply@anthropic.com>
…rics Explicit rtol=1e-12, atol=1e-12 for float64 NumPy correlation computations, consistent with the rest of the test suite changes. Co-authored-by: Claude <noreply@anthropic.com>
ganow
approved these changes
May 29, 2026
Contributor
ganow
left a comment
There was a problem hiding this comment.
Thank you! LGTM. The CI seems to be failed but the reason of it is the permission, not the test itself
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the remaining floating-point assertion issues discussed in #129.
Some of these issues were addressed in #112, but similar strict assertions remained in other tests. This PR updates only assertions involving numerical computations to use tolerant comparisons, while keeping exact comparisons where exact matches are expected.
Changes in this PR:
atolto an existingnp.testing.assert_allclose(...)assertion that failed due to a very small numerical difference.self.assertTrue(np.allclose(...))intest_metric.pytonp.testing.assert_allclose(...), and sets stricter explicit tolerances (rtol=1e-12,atol=1e-12) instead of relying on the defaultnp.allclosetolerances (rtol=1e-05,atol=1e-08).For
test_metric.py, #112 had already updated these assertions, but I revised them again to follow the style suggested in #117.np.testing.assert_allclose(...)reports the actual numerical differences on failure, making failures easier to diagnose than a genericFalse is not true-style message.Since this PR changes test assertions, I ran the tests locally three times with multiple Python versions and confirmed that they did not fail.
Closes #129