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
[stdlib] Enhance Handling of Infinity and NaN in assert_almost_equal
#2375
[stdlib] Enhance Handling of Infinity and NaN in assert_almost_equal
#2375
Conversation
031ccbd
to
d314a48
Compare
Hello @JoeLoser, I hope this message finds you well. I wanted to check in to see if there's anything additional you need from my side to facilitate the review process. Thank you for your time and attention. All the best, |
2c031c9
to
6c60c39
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice . Thanks for this
Sorry for the delay in reviewing this - I was on PTO/out of office last week and swamped with meetings yesterday. I just imported this internally and it'll be merged soon! Thanks so much for the contribution (and additional review from @abduld!). 🎉 |
✅🟣 This contribution has been merged 🟣✅ Hey @leandrolcampos, Thanks so much for the contribution! 🎉 We're moving to a new infrastructure for merging contributions to Mojo (we're using a tool called Copybara), and your contribution has now been merged into our internal copy of the Mojo Standard Library. I've added the "merged-internally" label on this PR. The changes in this PR will appear here in the mojo repo nightly branch when we do our next outbound synchronization at the time that the next Mojo nightly is released. That should happen within the next 24 hours. Please let me know if you have any questions or concerns. |
Note to self: this just got reverted due to an internal breakage on one test; we'll look into it today, but FYI. |
Please let me know if there is anything I can do to help. |
…lmost_equal` (#38991) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in #2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=#2375 Co-authored-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes #2375 MODULAR_ORIG_COMMIT_REV_ID: 2e8b24461dd3279bc841877cc0167acaa104f273
Will do! I didn't have time to look into this yet, but hoping to soon (got tied up into things for the MAX 24.3 release earlier today). I suspect it's an issue you're uncovering in some of our internal code, but I'll need to root cause it in order to land this for you internally. I'll keep you updated if there's anything, but I'm not expecting anything right now 😄 |
Ok. I'll resolve the conflicts in the branch 🙏 |
Signed-off-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com>
Signed-off-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com>
Signed-off-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com>
…function Signed-off-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com>
6c60c39
to
14f9a1b
Compare
Sorry for bothering you again. You may also need to update the implementation of |
Don't feel bad at all! I'm sorry I haven't been able to land this yet internally - it's on my list to get to though. :) |
✅🟣 This contribution has been merged 🟣✅ Your pull request has been merged to the internal upstream Mojo sources. It will be reflected here in the Mojo repository on the nightly branch during the next Mojo nightly release, typically within the next 24-48 hours. We use Copybara to merge external contributions, click here to learn more. |
@leandrolcampos this just merged again internally. Thanks for pushing on this and your patience! Your PR actually exposed a real bug with handling of inf in some internal code that @dukebw just fixed this morning. Appreciate it! |
…lmost_equal` (#39452) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in #2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=#2375 Co-authored-by: Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes #2375 MODULAR_ORIG_COMMIT_REV_ID: 8e0c2394d01d12015816f242e98d6f457af9cdfd
This PR enhances the
assert_almost_equal
function to correctly handle cases involving infinity and NaN.According to
test_assert_almost_equal
added to/test/testing/test_assertion.mojo
, the current implementation ofassert_almost_equal
results in errors in the following cases:This PR also:
and
andor
in the_isclose
function due to the issue outlined in [BUG] Theand
andor
operators produce incorrect results with SIMD inputs #2374._isclose
andassert_almost_equal
when the type is boolean, as these operations are not supported in this case.assert_almost_equal
in the docstring, highlighting differences from similar functions such asnumpy.testing.assert_allclose
.inf
function toutils/_numerics
along with corresponding tests intest/utils/test_numerics.mojo
.