Skip to content

Use tolerant assertions for floating-point tests#130

Merged
ganow merged 2 commits into
KamitaniLab:devfrom
KenyaOtsuka:fix/float-tolerant-assertions
May 29, 2026
Merged

Use tolerant assertions for floating-point tests#130
ganow merged 2 commits into
KamitaniLab:devfrom
KenyaOtsuka:fix/float-tolerant-assertions

Conversation

@KenyaOtsuka
Copy link
Copy Markdown

@KenyaOtsuka KenyaOtsuka commented May 29, 2026

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:

  • Replaces strict equality checks with tolerant comparisons for floating-point computations.
  • Adds an explicit atol to an existing np.testing.assert_allclose(...) assertion that failed due to a very small numerical difference.
  • Updates self.assertTrue(np.allclose(...)) in test_metric.py to np.testing.assert_allclose(...), and sets stricter explicit tolerances (rtol=1e-12, atol=1e-12) instead of relying on the default np.allclose tolerances (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 generic False 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

KenyaOtsuka and others added 2 commits May 29, 2026 03:59
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>
@KenyaOtsuka KenyaOtsuka changed the title Fix/float tolerant assertions Use tolerant assertions for floating-point tests May 29, 2026
@KenyaOtsuka KenyaOtsuka marked this pull request as ready for review May 29, 2026 05:41
@KenyaOtsuka KenyaOtsuka requested a review from ganow May 29, 2026 05:42
Copy link
Copy Markdown
Contributor

@ganow ganow left a comment

Choose a reason for hiding this comment

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

Thank you! LGTM. The CI seems to be failed but the reason of it is the permission, not the test itself

@ganow ganow merged commit 3545d96 into KamitaniLab:dev May 29, 2026
0 of 6 checks passed
@KenyaOtsuka KenyaOtsuka deleted the fix/float-tolerant-assertions branch May 29, 2026 06:10
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.

2 participants