tighter test checks#4
Conversation
Summary of ChangesHello @aadityacs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the precision and reliability of the test suite by implementing tighter numerical checks. It systematically reduces the tolerance values in several key assertions within mmapy/mma_test.py, ensuring that the tested components adhere more closely to their expected mathematical properties and behaviors. This change aims to improve the overall quality and robustness of the codebase by catching more subtle deviations in calculations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request tightens the tolerances in several tests, making them more precise, which is a great improvement. I've also suggested a couple of minor refactorings to use np.testing.assert_allclose for floating-point comparisons. This is more idiomatic when using NumPy and improves the readability and robustness of the tests.
| relative_error = abs(actual_lambda - expected_lambda) / max(expected_lambda, 1e-6) | ||
|
|
||
| self.assertLess( | ||
| relative_error, | ||
| 0.2, # 20% tolerance | ||
| 0.01, # 1% tolerance | ||
| msg=f"Multiplier should scale with objective. " | ||
| f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}", | ||
| ) |
There was a problem hiding this comment.
While the manual calculation of relative error works, using np.testing.assert_allclose is more idiomatic and robust for comparing floating-point numbers in NumPy-based tests. It clearly expresses the intent of checking for approximate equality with a relative tolerance and handles edge cases around zero more gracefully.
| relative_error = abs(actual_lambda - expected_lambda) / max(expected_lambda, 1e-6) | |
| self.assertLess( | |
| relative_error, | |
| 0.2, # 20% tolerance | |
| 0.01, # 1% tolerance | |
| msg=f"Multiplier should scale with objective. " | |
| f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}", | |
| ) | |
| np.testing.assert_allclose( | |
| actual_lambda, | |
| expected_lambda, | |
| rtol=0.01, # 1% tolerance | |
| err_msg=( | |
| "Multiplier should scale with objective. " | |
| f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}" | |
| ), | |
| ) |
| relative_deviation = abs(prod - mean_product) / mean_product | ||
| self.assertLess( | ||
| relative_deviation, | ||
| 0.3, # 30% tolerance | ||
| 0.01, # 1% tolerance | ||
| msg="λ * scale should be approximately constant", | ||
| ) |
There was a problem hiding this comment.
For improved readability and to follow common testing patterns with NumPy, consider using np.testing.assert_allclose. This function is designed for comparing floating-point values and makes the intent of a relative tolerance check clearer than manually calculating the deviation.
| relative_deviation = abs(prod - mean_product) / mean_product | |
| self.assertLess( | |
| relative_deviation, | |
| 0.3, # 30% tolerance | |
| 0.01, # 1% tolerance | |
| msg="λ * scale should be approximately constant", | |
| ) | |
| np.testing.assert_allclose( | |
| prod, | |
| mean_product, | |
| rtol=0.01, # 1% tolerance | |
| err_msg="λ * scale should be approximately constant", | |
| ) |
No description provided.